import '@diplodoc/cut-extension/runtime';
import { chainCommands } from 'prosemirror-commands';
import { nodeInputRule } from "../../../utils/inputrules.js";
import { withLogAction } from "../../../utils/keymap.js";
import { YfmCutSpecs } from "./YfmCutSpecs/index.js";
import { createYfmCut, toYfmCut } from "./actions/toYfmCut.js";
import { backToCutTitle, exitFromCutTitle, liftEmptyBlockFromCut, removeCut } from "./commands.js";
import { cutType } from "./const.js";
import { YfmCutTitleNodeView } from "./nodeviews/yfm-cut-title.js";
import { cutActivePlugin } from "./plugins/active.js";
import { cutAutoOpenPlugin } from "./plugins/auto-open.js";
import '@diplodoc/cut-extension/runtime/styles.css';
import "./index.css"; // eslint-disable-line import/order
const cutAction = 'toYfmCut';
export { CutNode, cutType, cutTitleType, cutContentType } from "./YfmCutSpecs/index.js";
export const YfmCut = (builder, opts) => {
    builder.use(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 YfmCutTitleNodeView(node),
    });
    builder
        .addPlugin(cutActivePlugin)
        .addPlugin(cutAutoOpenPlugin)
        .addAction(cutAction, () => toYfmCut)
        .addKeymap(() => ({
        Backspace: chainCommands(backToCutTitle, removeCut),
        Enter: chainCommands(exitFromCutTitle, liftEmptyBlockFromCut),
    }))
        .addInputRules(({ schema }) => ({
        rules: [nodeInputRule(/(?:^)({% cut)\s$/, cutType(schema).createAndFill(), 1)],
    }));
    if (opts?.yfmCutKey) {
        const { yfmCutKey } = opts;
        builder.addKeymap(() => ({ [yfmCutKey]: withLogAction('yfm_cut', createYfmCut) }));
    }
};
//# sourceMappingURL=index.js.map
