import { chainCommands } from 'prosemirror-commands';
import { nodeInputRule } from "../../../utils/inputrules.js";
import { withLogAction } from "../../../utils/keymap.js";
import { YfmNoteSpecs } from "./YfmNoteSpecs/index.js";
import { createYfmNote, toYfmNote } from "./actions/toYfmNote.js";
import { backToNoteTitle, exitFromNoteTitle, liftEmptyBlockFromNote, removeNote } from "./commands.js";
import { yfmNoteTooltipPlugin } from "./plugins/YfmNoteTooltipPlugin/index.js";
import { noteType } from "./utils.js";
import "./index.css";
const noteAction = 'toYfmNote';
export { YfmNoteNode, noteType, noteTitleType } from "./YfmNoteSpecs/index.js";
export const YfmNote = (builder, opts) => {
    builder.use(YfmNoteSpecs, opts);
    builder
        .addKeymap(() => ({
        Enter: chainCommands(exitFromNoteTitle, liftEmptyBlockFromNote),
        Backspace: chainCommands(backToNoteTitle, removeNote),
    }))
        .addAction(noteAction, () => toYfmNote)
        .addInputRules(({ schema }) => ({
        rules: [nodeInputRule(/(?:^)({% note)\s$/, noteType(schema).createAndFill(), 1)],
    }));
    if (opts?.yfmNoteKey) {
        const { yfmNoteKey } = opts;
        builder.addKeymap(() => ({ [yfmNoteKey]: withLogAction('yfm_note', createYfmNote) }));
    }
    builder.addPlugin(yfmNoteTooltipPlugin);
};
//# sourceMappingURL=index.js.map
