import { withLogAction } from "../../../utils/keymap.js";
import { YfmHeadingSpecs } from "./YfmHeadingSpecs/index.js";
import { headingRule, headingType } from "./YfmHeadingSpecs/utils.js";
import { headingAction } from "./actions.js";
import { resetHeading, toHeading } from "./commands.js";
import { HeadingAction } from "./const.js";
export { YfmHeadingAttr } from "./const.js";
/** YfmHeading extension needs markdown-it-attrs plugin */
export const YfmHeading = (builder, opts) => {
    builder.use(YfmHeadingSpecs, opts);
    builder
        .addKeymap(() => {
        const { h1Key, h2Key, h3Key, h4Key, h5Key, h6Key } = opts ?? {};
        const bindings = { Backspace: resetHeading };
        if (h1Key)
            bindings[h1Key] = withLogAction('heading1', toHeading(1));
        if (h2Key)
            bindings[h2Key] = withLogAction('heading2', toHeading(2));
        if (h3Key)
            bindings[h3Key] = withLogAction('heading3', toHeading(3));
        if (h4Key)
            bindings[h4Key] = withLogAction('heading4', toHeading(4));
        if (h5Key)
            bindings[h5Key] = withLogAction('heading5', toHeading(5));
        if (h6Key)
            bindings[h6Key] = withLogAction('heading6', toHeading(6));
        return bindings;
    })
        .addInputRules(({ schema }) => ({ rules: [headingRule(headingType(schema), 6)] }));
    builder
        .addAction(HeadingAction.ToH1, () => headingAction(1))
        .addAction(HeadingAction.ToH2, () => headingAction(2))
        .addAction(HeadingAction.ToH3, () => headingAction(3))
        .addAction(HeadingAction.ToH4, () => headingAction(4))
        .addAction(HeadingAction.ToH5, () => headingAction(5))
        .addAction(HeadingAction.ToH6, () => headingAction(6));
};
//# sourceMappingURL=index.js.map
