"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.BaseSchema = exports.toParagraph = exports.pType = exports.BaseNode = void 0;
const prosemirror_commands_1 = require("prosemirror-commands");
// @ts-ignore // TODO: fix cjs build
const prosemirror_utils_1 = require("prosemirror-utils");
const keymap_1 = require("../../../utils/keymap.js");
const BaseSchemaSpecs_1 = require("./BaseSchemaSpecs/index.js");
var BaseSchemaSpecs_2 = require("./BaseSchemaSpecs/index.js");
Object.defineProperty(exports, "BaseNode", { enumerable: true, get: function () { return BaseSchemaSpecs_2.BaseNode; } });
Object.defineProperty(exports, "pType", { enumerable: true, get: function () { return BaseSchemaSpecs_2.pType; } });
const pAction = 'toParagraph';
const toParagraph = (state, dispatch) => (0, prosemirror_commands_1.setBlockType)((0, BaseSchemaSpecs_1.pType)(state.schema))(state, dispatch);
exports.toParagraph = toParagraph;
const BaseSchema = (builder, opts) => {
    builder.use(BaseSchemaSpecs_1.BaseSchemaSpecs, opts);
    const { paragraphKey } = opts;
    if (paragraphKey) {
        builder.addKeymap(({ schema }) => ({
            [paragraphKey]: (0, keymap_1.withLogAction)('paragraph', (0, prosemirror_commands_1.setBlockType)((0, BaseSchemaSpecs_1.pType)(schema))),
        }));
    }
    builder.addAction(pAction, ({ schema }) => {
        const p = (0, BaseSchemaSpecs_1.pType)(schema);
        const cmd = (0, prosemirror_commands_1.setBlockType)(p);
        const isParagraph = (state) => (0, prosemirror_utils_1.hasParentNodeOfType)(p)(state.selection);
        return {
            isActive: isParagraph,
            isEnable: (0, prosemirror_commands_1.chainCommands)(isParagraph, cmd),
            run: cmd,
        };
    });
};
exports.BaseSchema = BaseSchema;
//# sourceMappingURL=index.js.map
