import { setBlockType } from 'prosemirror-commands';
import { withLogAction } from "../../../utils/keymap.js";
import { HeadingSpecs, headingType } from "./HeadingSpecs/index.js";
import { headingAction } from "./actions.js";
import { resetHeading } from "./commands.js";
import { HeadingAction, headingLevelAttr } from "./const.js";
import { headingRule } from "./utils.js";
export { headingNodeName, headingType } from "./HeadingSpecs/index.js";
export { HeadingAction } from "./const.js";
export const Heading = (builder, opts) => {
    builder.use(HeadingSpecs, opts);
    builder
        .addKeymap(({ schema }) => {
        const { h1Key, h2Key, h3Key, h4Key, h5Key, h6Key } = opts ?? {};
        const cmd4lvl = (level) => setBlockType(headingType(schema), { [headingLevelAttr]: level });
        const bindings = { Backspace: resetHeading };
        if (h1Key)
            bindings[h1Key] = withLogAction('heading1', cmd4lvl(1));
        if (h2Key)
            bindings[h2Key] = withLogAction('heading2', cmd4lvl(2));
        if (h3Key)
            bindings[h3Key] = withLogAction('heading3', cmd4lvl(3));
        if (h4Key)
            bindings[h4Key] = withLogAction('heading4', cmd4lvl(4));
        if (h5Key)
            bindings[h5Key] = withLogAction('heading5', cmd4lvl(5));
        if (h6Key)
            bindings[h6Key] = withLogAction('heading6', cmd4lvl(6));
        return bindings;
    })
        .addInputRules(({ schema }) => ({ rules: [headingRule(headingType(schema), 6)] }));
    builder
        .addAction(HeadingAction.ToH1, ({ schema }) => headingAction(headingType(schema), 1))
        .addAction(HeadingAction.ToH2, ({ schema }) => headingAction(headingType(schema), 2))
        .addAction(HeadingAction.ToH3, ({ schema }) => headingAction(headingType(schema), 3))
        .addAction(HeadingAction.ToH4, ({ schema }) => headingAction(headingType(schema), 4))
        .addAction(HeadingAction.ToH5, ({ schema }) => headingAction(headingType(schema), 5))
        .addAction(HeadingAction.ToH6, ({ schema }) => headingAction(headingType(schema), 6));
};
//# sourceMappingURL=index.js.map
