"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.SchemaDynamicModifier = void 0;
/**
 * Class SchemaDynamicModifier
 *
 * Provides a mechanism for dynamic modification of schema node attributes:
 *
 *    - `allowedAttrs`: A list of additional attributes to include in the ProseMirror schema with default values.
 *      When specified, these attributes are added to the schema and preserved during processing.
 *
 * Example:
 * ```ts
 * const dynamicModifier = new SchemaDynamicModifier({
 *     paragraph: {
 *         allowedAttrs: ['data-paragraph'],
 *     },
 * });
 * ```
 */
class SchemaDynamicModifier {
    nodeSpecsProcessors;
    constructor(config) {
        this.nodeSpecsProcessors = new Map(Object.entries(config));
    }
    processNodeSpec(name, nodeSpec) {
        let updatedSpec = nodeSpec;
        this.nodeSpecsProcessors.forEach((processor, elementType) => {
            if (name === elementType &&
                processor.allowedAttrs &&
                processor.allowedAttrs.length > 0 &&
                nodeSpec) {
                updatedSpec = {
                    ...nodeSpec,
                    attrs: {
                        ...nodeSpec.attrs,
                        ...processor.allowedAttrs.reduce((acc, key) => {
                            acc[key] = { default: null };
                            return acc;
                        }, {}),
                    },
                };
            }
        });
        return updatedSpec;
    }
}
exports.SchemaDynamicModifier = SchemaDynamicModifier;
//# sourceMappingURL=SchemaDynamicModifier.js.map
