"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MermaidSpecs = exports.mermaidNodeName = void 0;
// eslint-disable-next-line import/no-extraneous-dependencies
const mermaid_extension_1 = require("@diplodoc/mermaid-extension");
const const_1 = require("./const.js");
var const_2 = require("./const.js");
Object.defineProperty(exports, "mermaidNodeName", { enumerable: true, get: function () { return const_2.mermaidNodeName; } });
const MermaidSpecsExtension = (builder, { nodeView }) => {
    builder
        .configureMd((md) => md.use((0, mermaid_extension_1.transform)({ runtime: 'mermaid', bundle: false }), {}))
        .addNode(const_1.mermaidNodeName, () => ({
        fromMd: {
            tokenSpec: {
                name: const_1.mermaidNodeName,
                type: 'node',
                getAttrs: ({ content }) => ({ content }),
            },
        },
        spec: {
            selectable: true,
            atom: true,
            group: 'block',
            attrs: {
                [const_1.MermaidConsts.NodeAttrs.content]: { default: '' },
                [const_1.MermaidConsts.NodeAttrs.class]: { default: 'mermaid' },
                [const_1.MermaidConsts.NodeAttrs.newCreated]: { default: null },
            },
            parseDOM: [],
            toDOM(node) {
                return ['div', node.attrs];
            },
            dnd: { props: { offset: [8, 1] } },
        },
        toMd: (state, node) => {
            const content = node.attrs[const_1.MermaidConsts.NodeAttrs.content] || '';
            state.write('```mermaid');
            state.ensureNewLine();
            state.text(content.trim(), false);
            state.ensureNewLine();
            state.write('```');
            state.ensureNewLine();
        },
        view: nodeView,
    }));
};
exports.MermaidSpecs = Object.assign(MermaidSpecsExtension, const_1.MermaidConsts);
//# sourceMappingURL=index.js.map
