"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.YfmHtmlBlockSpecs = exports.YfmHtmlBlockConsts = exports.yfmHtmlBlockNodeName = void 0;
const html_extension_1 = require("@diplodoc/html-extension");
const entity_id_1 = require("../../../../utils/entity-id.js");
const const_1 = require("./const.js");
var const_2 = require("./const.js");
Object.defineProperty(exports, "yfmHtmlBlockNodeName", { enumerable: true, get: function () { return const_2.yfmHtmlBlockNodeName; } });
Object.defineProperty(exports, "YfmHtmlBlockConsts", { enumerable: true, get: function () { return const_2.YfmHtmlBlockConsts; } });
const YfmHtmlBlockSpecsExtension = (builder, { nodeView, ...options }) => {
    builder
        .configureMd((md) => md.use((0, html_extension_1.transform)({
        bundle: false,
        embeddingMode: 'srcdoc',
        ...options,
    }), {}))
        .addNode(const_1.YfmHtmlBlockConsts.NodeName, () => ({
        fromMd: {
            tokenSpec: {
                name: const_1.YfmHtmlBlockConsts.NodeName,
                type: 'node',
                noCloseToken: true,
                getAttrs: ({ content }) => ({
                    [const_1.YfmHtmlBlockConsts.NodeAttrs.srcdoc]: content,
                    [const_1.YfmHtmlBlockConsts.NodeAttrs.EntityId]: (0, entity_id_1.generateEntityId)(const_1.YfmHtmlBlockConsts.NodeName),
                }),
            },
        },
        spec: {
            group: 'block',
            attrs: {
                [const_1.YfmHtmlBlockConsts.NodeAttrs.class]: { default: 'yfm-html' },
                [const_1.YfmHtmlBlockConsts.NodeAttrs.frameborder]: { default: '' },
                [const_1.YfmHtmlBlockConsts.NodeAttrs.srcdoc]: { default: '' },
                [const_1.YfmHtmlBlockConsts.NodeAttrs.style]: { default: null },
                [const_1.YfmHtmlBlockConsts.NodeAttrs.newCreated]: { default: null },
                [const_1.YfmHtmlBlockConsts.NodeAttrs.EntityId]: { default: const_1.defaultYfmHtmlBlockEntityId },
            },
            toDOM: (node) => ['iframe', node.attrs],
        },
        toMd: (state, node) => {
            state.write('::: html');
            state.write('\n');
            state.write(node.attrs[const_1.YfmHtmlBlockConsts.NodeAttrs.srcdoc]);
            state.ensureNewLine();
            state.write(':::');
            state.closeBlock(node);
        },
        view: nodeView,
    }));
};
exports.YfmHtmlBlockSpecs = Object.assign(YfmHtmlBlockSpecsExtension, const_1.YfmHtmlBlockConsts);
//# sourceMappingURL=index.js.map
