"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.YfmCut = exports.cutContentType = exports.cutTitleType = exports.cutType = exports.CutNode = void 0;
require("@diplodoc/cut-extension/runtime");
const prosemirror_commands_1 = require("prosemirror-commands");
const inputrules_1 = require("../../../utils/inputrules.js");
const keymap_1 = require("../../../utils/keymap.js");
const YfmCutSpecs_1 = require("./YfmCutSpecs/index.js");
const toYfmCut_1 = require("./actions/toYfmCut.js");
const commands_1 = require("./commands.js");
const const_1 = require("./const.js");
const yfm_cut_title_1 = require("./nodeviews/yfm-cut-title.js");
const active_1 = require("./plugins/active.js");
const auto_open_1 = require("./plugins/auto-open.js");
require("@diplodoc/cut-extension/runtime/styles.css");
require("./index.css"); // eslint-disable-line import/order
const cutAction = 'toYfmCut';
var YfmCutSpecs_2 = require("./YfmCutSpecs/index.js");
Object.defineProperty(exports, "CutNode", { enumerable: true, get: function () { return YfmCutSpecs_2.CutNode; } });
Object.defineProperty(exports, "cutType", { enumerable: true, get: function () { return YfmCutSpecs_2.cutType; } });
Object.defineProperty(exports, "cutTitleType", { enumerable: true, get: function () { return YfmCutSpecs_2.cutTitleType; } });
Object.defineProperty(exports, "cutContentType", { enumerable: true, get: function () { return YfmCutSpecs_2.cutContentType; } });
const YfmCut = (builder, opts) => {
    builder.use(YfmCutSpecs_1.YfmCutSpecs, {
        ...opts,
        // @ts-expect-error
        cutView: 
        // FIX: ignore mutation and don't rerender node when yfm.js open or close cut
        () => () => ({
            ignoreMutation(mutation) {
                return mutation instanceof MutationRecord && mutation.type === 'attributes';
            },
        }),
        cutTitleView: () => (node) => new yfm_cut_title_1.YfmCutTitleNodeView(node),
    });
    builder
        .addPlugin(active_1.cutActivePlugin)
        .addPlugin(auto_open_1.cutAutoOpenPlugin)
        .addAction(cutAction, () => toYfmCut_1.toYfmCut)
        .addKeymap(() => ({
        Backspace: (0, prosemirror_commands_1.chainCommands)(commands_1.backToCutTitle, commands_1.removeCut),
        Enter: (0, prosemirror_commands_1.chainCommands)(commands_1.exitFromCutTitle, commands_1.liftEmptyBlockFromCut),
    }))
        .addInputRules(({ schema }) => ({
        rules: [(0, inputrules_1.nodeInputRule)(/(?:^)({% cut)\s$/, (0, const_1.cutType)(schema).createAndFill(), 1)],
    }));
    if (opts?.yfmCutKey) {
        const { yfmCutKey } = opts;
        builder.addKeymap(() => ({ [yfmCutKey]: (0, keymap_1.withLogAction)('yfm_cut', toYfmCut_1.createYfmCut) }));
    }
};
exports.YfmCut = YfmCut;
//# sourceMappingURL=index.js.map
