Skip to content

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

1.6 KB
Raw Blame
export interface IEmbedRenderLoadingState {
    rotateElement: Element | null;
    height?: string;
}

export const resetPastedQueryEmbedRenderState = (element: Element) => {
    const embedElements: HTMLElement[] = [];
    if (element.getAttribute("data-type") === "NodeBlockQueryEmbed") {
        embedElements.push(element as HTMLElement);
    }
    embedElements.push(...element.querySelectorAll<HTMLElement>('[data-type="NodeBlockQueryEmbed"]'));
    embedElements.forEach(item => {
        item.removeAttribute("data-render");
        item.style.height = "";
        Array.from(item.children).forEach(child => {
            if (!child.classList.contains("protyle-attr")) {
                child.remove();
            }
        });
    });
};

export const finishEmptyEmbedRender = (item: HTMLElement, onEmbedRender?: () => void) => {
    item.querySelector(":scope > .protyle-icons .protyle-action__reload .fn__rotate")?.classList.remove("fn__rotate");
    Array.from(item.children).forEach(child => {
        if (!child.classList.contains("protyle-icons") && !child.classList.contains("protyle-cursor") &&
            !child.classList.contains("protyle-attr")) {
            child.remove();
        }
    });
    item.style.height = "";
    onEmbedRender?.();
};

export const finishCustomEmbedRender = (item: HTMLElement, loadingState: IEmbedRenderLoadingState,
                                        onEmbedRender?: () => void) => {
    loadingState.rotateElement?.classList.remove("fn__rotate");
    if (loadingState.height !== undefined && item.style.height === loadingState.height) {
        item.style.height = "";
    }
    onEmbedRender?.();
};