Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

1.9 KB
Raw Blame
import {highlightRender} from "./highlightRender";
import {mathRender} from "./mathRender";
import {getTableCellRichBlockDOM, updateTableCellContentLayout} from "../util/tableCellRich";
import {TABLE_CELL_RICH_ATTRIBUTE} from "../util/tableCellRichValue";
import {renderBlockDirection} from "./blockDirection";

export const renderTableCellRichElements = (root: Element) => {
    const elements = [...root.querySelectorAll<HTMLElement>(".table__cell-rich")];
    if (root.classList.contains("table__cell-rich")) {
        elements.unshift(root as HTMLElement);
    }
    elements.forEach(element => {
        const cell = element.closest(`th[${TABLE_CELL_RICH_ATTRIBUTE}], td[${TABLE_CELL_RICH_ATTRIBUTE}]`);
        if (!cell) {
            return;
        }
        // 预览复用编辑结构,但不携带文档块身份或编辑能力。
        const template = document.createElement("template");
        template.innerHTML = getTableCellRichBlockDOM(cell);
        updateTableCellContentLayout(element, template.innerHTML);
        template.content.querySelectorAll<HTMLElement>("*").forEach(node => {
            if (node.hasAttribute("data-node-id")) {
                node.setAttribute("data-table-cell-node", "");
            }
            if (node.hasAttribute("spellcheck")) {
                node.setAttribute("data-table-cell-content", "");
            }
            ["id", "data-node-id", "data-node-index", "updated", "spellcheck", "draggable"].forEach(attribute =>
                node.removeAttribute(attribute));
            if (node.hasAttribute("contenteditable")) {
                node.contentEditable = "false";
            }
        });
        element.replaceChildren(template.content);
        renderBlockDirection(element);
        element.classList.remove("b3-typography");
        element.dataset.protyleLiteRender = "safe";
        mathRender(element);
        highlightRender(element);
    });
};