"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.defineActions = defineActions;
exports.createToggleMarkAction = createToggleMarkAction;
exports.createMarkdownInlineMarkAction = createMarkdownInlineMarkAction;
const prosemirror_commands_1 = require("prosemirror-commands");
const marks_1 = require("./marks.js");
function defineActions(actions) {
    return actions;
}
function createToggleMarkAction(markType) {
    const command = (0, prosemirror_commands_1.toggleMark)(markType);
    return {
        isActive: (state) => Boolean((0, marks_1.isMarkActive)(state, markType)),
        isEnable: command,
        run: command,
    };
}
/**
 * Like createToggleMarkAction, but blocks applying the mark when the selection
 * boundaries would produce markdown that cannot round-trip (e.g. `word**,**`).
 * Removing the mark (toggling off) is always allowed.
 */
function createMarkdownInlineMarkAction(markType) {
    const base = createToggleMarkAction(markType);
    return {
        isActive: base.isActive,
        isEnable: (state, dispatch, view, attrs) => {
            const isBlocked = !(0, marks_1.isMarkActive)(state, markType) && !(0, marks_1.canApplyInlineMarkInMarkdown)(state);
            if (isBlocked)
                return false;
            return base.isEnable(state, dispatch, view, attrs);
        },
        run: (state, dispatch, view, attrs) => {
            const isBlocked = !(0, marks_1.isMarkActive)(state, markType) && !(0, marks_1.canApplyInlineMarkInMarkdown)(state);
            if (isBlocked)
                return;
            base.run(state, dispatch, view, attrs);
        },
    };
}
//# sourceMappingURL=actions.js.map
