import { chainCommands, setBlockType } from 'prosemirror-commands';
// @ts-ignore // TODO: fix cjs build
import { hasParentNodeOfType } from 'prosemirror-utils';
import { withLogAction } from "../../../utils/keymap.js";
import { BaseSchemaSpecs, pType } from "./BaseSchemaSpecs/index.js";
export { BaseNode, pType } from "./BaseSchemaSpecs/index.js";
const pAction = 'toParagraph';
export const toParagraph = (state, dispatch) => setBlockType(pType(state.schema))(state, dispatch);
export const BaseSchema = (builder, opts) => {
    builder.use(BaseSchemaSpecs, opts);
    const { paragraphKey } = opts;
    if (paragraphKey) {
        builder.addKeymap(({ schema }) => ({
            [paragraphKey]: withLogAction('paragraph', setBlockType(pType(schema))),
        }));
    }
    builder.addAction(pAction, ({ schema }) => {
        const p = pType(schema);
        const cmd = setBlockType(p);
        const isParagraph = (state) => hasParentNodeOfType(p)(state.selection);
        return {
            isActive: isParagraph,
            isEnable: chainCommands(isParagraph, cmd),
            run: cmd,
        };
    });
};
//# sourceMappingURL=index.js.map
