Skip to content

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

915 B
Raw Blame
export const getHeadingLevelUpdateOperations = (operations: IOperation[], excludedIDs = new Set<string>()) => {
    return operations.filter((operation): operation is Extract<IOperation, {action: "update"}> =>
        operation.action === "update" && !excludedIDs.has(operation.id));
};

export const applyHeadingLevelUpdates = (protyle: IProtyle, operations: IOperation[], render: (element: HTMLElement) => unknown) => {
    getHeadingLevelUpdateOperations(operations).forEach(operation => {
        protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.id}"]`).forEach((itemElement: HTMLElement) => {
            itemElement.outerHTML = operation.data;
        });
        // 使用 outer 后元素需要重新查询
        protyle.wysiwyg.element.querySelectorAll(`[data-node-id="${operation.id}"]`).forEach((itemElement: HTMLElement) => {
            render(itemElement);
        });
    });
};