import { DeflistNode, TableNode } from "../../markdown/index.js";
import { CheckboxNode, CutNode, TabsNode, YfmNoteNode } from "../../yfm/index.js";
import { logger } from "../../../logger.js";
import { Autocomplete } from "../Autocomplete/index.js";
import { DecoClassName } from "./const.js";
import { CommandHandler } from "./handler.js";
const getCommandMenuAutocompleteItem = (opts) => ({ actions }) => ({
    trigger: {
        name: 'command',
        trigger: /(?:^|\s)(\/)$/,
        allArrowKeys: false,
        cancelOnFirstSpace: true,
        decorationAttrs: { class: DecoClassName },
    },
    handler: new CommandHandler({
        storage: actions,
        actions: opts.actions,
        // TODO: add commandMenu=false flag to specs:
        nodesIgnoreList: (opts.nodesIgnoreList ?? []).concat([
            DeflistNode.Term,
            TableNode.HeaderCell,
            TableNode.DataCell,
            CheckboxNode.Label,
            YfmNoteNode.NoteTitle,
            CutNode.CutTitle,
            TabsNode.Tab,
        ]),
    }),
});
export const CommandMenu = (builder, opts) => {
    if (!Array.isArray(opts.actions) || opts.actions.length === 0) {
        logger.info("[CommandMenu extension]: Skip because 'actions' is not an array or is empty");
        return;
    }
    if (!builder.context.has('autocomplete')) {
        builder.use(Autocomplete);
    }
    builder.context.get('autocomplete').add(getCommandMenuAutocompleteItem(opts));
};
//# sourceMappingURL=index.js.map
