"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.Heading = exports.HeadingAction = exports.headingType = exports.headingNodeName = void 0;
const prosemirror_commands_1 = require("prosemirror-commands");
const keymap_1 = require("../../../utils/keymap.js");
const HeadingSpecs_1 = require("./HeadingSpecs/index.js");
const actions_1 = require("./actions.js");
const commands_1 = require("./commands.js");
const const_1 = require("./const.js");
const utils_1 = require("./utils.js");
var HeadingSpecs_2 = require("./HeadingSpecs/index.js");
Object.defineProperty(exports, "headingNodeName", { enumerable: true, get: function () { return HeadingSpecs_2.headingNodeName; } });
Object.defineProperty(exports, "headingType", { enumerable: true, get: function () { return HeadingSpecs_2.headingType; } });
var const_2 = require("./const.js");
Object.defineProperty(exports, "HeadingAction", { enumerable: true, get: function () { return const_2.HeadingAction; } });
const Heading = (builder, opts) => {
    builder.use(HeadingSpecs_1.HeadingSpecs, opts);
    builder
        .addKeymap(({ schema }) => {
        const { h1Key, h2Key, h3Key, h4Key, h5Key, h6Key } = opts ?? {};
        const cmd4lvl = (level) => (0, prosemirror_commands_1.setBlockType)((0, HeadingSpecs_1.headingType)(schema), { [const_1.headingLevelAttr]: level });
        const bindings = { Backspace: commands_1.resetHeading };
        if (h1Key)
            bindings[h1Key] = (0, keymap_1.withLogAction)('heading1', cmd4lvl(1));
        if (h2Key)
            bindings[h2Key] = (0, keymap_1.withLogAction)('heading2', cmd4lvl(2));
        if (h3Key)
            bindings[h3Key] = (0, keymap_1.withLogAction)('heading3', cmd4lvl(3));
        if (h4Key)
            bindings[h4Key] = (0, keymap_1.withLogAction)('heading4', cmd4lvl(4));
        if (h5Key)
            bindings[h5Key] = (0, keymap_1.withLogAction)('heading5', cmd4lvl(5));
        if (h6Key)
            bindings[h6Key] = (0, keymap_1.withLogAction)('heading6', cmd4lvl(6));
        return bindings;
    })
        .addInputRules(({ schema }) => ({ rules: [(0, utils_1.headingRule)((0, HeadingSpecs_1.headingType)(schema), 6)] }));
    builder
        .addAction(const_1.HeadingAction.ToH1, ({ schema }) => (0, actions_1.headingAction)((0, HeadingSpecs_1.headingType)(schema), 1))
        .addAction(const_1.HeadingAction.ToH2, ({ schema }) => (0, actions_1.headingAction)((0, HeadingSpecs_1.headingType)(schema), 2))
        .addAction(const_1.HeadingAction.ToH3, ({ schema }) => (0, actions_1.headingAction)((0, HeadingSpecs_1.headingType)(schema), 3))
        .addAction(const_1.HeadingAction.ToH4, ({ schema }) => (0, actions_1.headingAction)((0, HeadingSpecs_1.headingType)(schema), 4))
        .addAction(const_1.HeadingAction.ToH5, ({ schema }) => (0, actions_1.headingAction)((0, HeadingSpecs_1.headingType)(schema), 5))
        .addAction(const_1.HeadingAction.ToH6, ({ schema }) => (0, actions_1.headingAction)((0, HeadingSpecs_1.headingType)(schema), 6));
};
exports.Heading = Heading;
//# sourceMappingURL=index.js.map
