import { nodeTypeFactory } from "../../../../utils/schema.js";
export var BreakNodeName;
(function (BreakNodeName) {
    BreakNodeName["HardBreak"] = "hard_break";
    BreakNodeName["SoftBreak"] = "soft_break";
})(BreakNodeName || (BreakNodeName = {}));
export const hbType = nodeTypeFactory(BreakNodeName.HardBreak);
export const sbType = nodeTypeFactory(BreakNodeName.SoftBreak);
export const BreaksSpecs = (builder, opts) => {
    const { preferredBreak = 'hard' } = opts;
    const parseDOM = [{ tag: 'br' }];
    builder.addNode(BreakNodeName.HardBreak, () => ({
        spec: {
            inline: true,
            group: 'inline break',
            marks: '',
            isBreak: true,
            selectable: false,
            parseDOM: preferredBreak === 'hard' ? parseDOM : undefined,
            toDOM() {
                return ['br'];
            },
        },
        fromMd: { tokenName: 'hardbreak', tokenSpec: { name: BreakNodeName.HardBreak, type: 'node' } },
        toMd: (state, node, parent, index) => {
            for (let i = index + 1; i < parent.childCount; i++) {
                if (parent.child(i).type !== node.type) {
                    state.write('\\\n');
                    return;
                }
            }
        },
    }));
    // TODO: should we handle softbreak differently at different md.options.breaks setting?
    // we can safely convert softbreak into hardbreak,
    // but in this case non-edited markup will always be changed – a backspash will be added
    builder.addNode(BreakNodeName.SoftBreak, () => ({
        spec: {
            inline: true,
            group: 'inline break',
            marks: '',
            isBreak: true,
            selectable: false,
            parseDOM: preferredBreak === 'soft' ? parseDOM : undefined,
            toDOM() {
                return ['br'];
            },
        },
        fromMd: { tokenName: 'softbreak', tokenSpec: { name: BreakNodeName.SoftBreak, type: 'node' } },
        toMd: (state, node, parent, index) => {
            for (let i = index + 1; i < parent.childCount; i++) {
                if (parent.child(i).type !== node.type) {
                    state.write('\n');
                    return;
                }
            }
        },
    }));
};
//# sourceMappingURL=index.js.map
