import sanitize from '@diplodoc/transform/lib/sanitize.js';
import { HtmlAttr, HtmlNode } from "./const.js";
var DomAttr;
(function (DomAttr) {
    DomAttr["Html"] = "data-html";
    DomAttr["HtmlRaw"] = "data-html-raw";
})(DomAttr || (DomAttr = {}));
export const schemaSpecs = {
    [HtmlNode.Block]: {
        atom: true,
        group: 'block',
        attrs: { [HtmlAttr.Content]: {} },
        parseDOM: [
            {
                tag: `div[${DomAttr.Html}]`,
                getAttrs(dom) {
                    const dom_ = dom;
                    return {
                        [HtmlAttr.Content]: dom_.getAttribute(DomAttr.HtmlRaw) || dom_.innerHTML,
                    };
                },
            },
        ],
        toDOM(node) {
            const htmlContent = node.attrs[HtmlAttr.Content];
            const elem = document.createElement('div');
            elem.setAttribute(DomAttr.Html, '');
            elem.setAttribute(DomAttr.HtmlRaw, htmlContent);
            elem.contentEditable = 'false';
            elem.innerHTML = sanitize(htmlContent);
            return elem;
        },
    },
    [HtmlNode.Inline]: {
        atom: true,
        inline: true,
        group: 'inline',
        attrs: { [HtmlAttr.Content]: {} },
        parseDOM: [
            {
                tag: `span[${DomAttr.Html}]`,
                getAttrs(dom) {
                    return { [HtmlAttr.Content]: dom.textContent };
                },
            },
        ],
        toDOM(node) {
            const elem = document.createElement('span');
            elem.setAttribute(DomAttr.Html, '');
            elem.contentEditable = 'false';
            elem.textContent = node.attrs[HtmlAttr.Content];
            return elem;
        },
    },
};
//# sourceMappingURL=schema.js.map
