import { toggleMark } from 'prosemirror-commands';
import { canApplyInlineMarkInMarkdown, isMarkActive } from "./marks.js";
export function defineActions(actions) {
    return actions;
}
export function createToggleMarkAction(markType) {
    const command = toggleMark(markType);
    return {
        isActive: (state) => Boolean(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.
 */
export function createMarkdownInlineMarkAction(markType) {
    const base = createToggleMarkAction(markType);
    return {
        isActive: base.isActive,
        isEnable: (state, dispatch, view, attrs) => {
            const isBlocked = !isMarkActive(state, markType) && !canApplyInlineMarkInMarkdown(state);
            if (isBlocked)
                return false;
            return base.isEnable(state, dispatch, view, attrs);
        },
        run: (state, dispatch, view, attrs) => {
            const isBlocked = !isMarkActive(state, markType) && !canApplyInlineMarkInMarkdown(state);
            if (isBlocked)
                return;
            base.run(state, dispatch, view, attrs);
        },
    };
}
//# sourceMappingURL=actions.js.map
