Skip to content

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

2.1 KB
Raw Blame
import {Constants} from "../../constants";

// 精简模式保留首个容器的独立块标,完整模式也允许从列表标记定位首个内容块。
export const getListItemGutterContainer = (element: Element, full = false) => {
    const item = element.closest('[data-type="NodeListItem"]');
    const first = item?.querySelector(":scope > [data-node-id]");
    const type = first?.getAttribute("data-type");
    if (first && (full || ["NodeTable", "NodeBlockquote", "NodeCallout", "NodeSuperBlock", "NodeTabs",
        "NodeMindmap", "NodeAttributeView", "NodeCodeBlock", "NodeIFrame"].includes(type) ||
        type === "NodeList" && first.getAttribute(Constants.CUSTOM_SY_LIST_MINDMAP) === "1") &&
        (element === item || first.contains(element) ||
            element.parentElement === item && element.classList.contains("protyle-action"))) {
        return first;
    }
};

// 鼠标经过祖先容器留白移向子块块标时,保留当前块标及其选区。
export const isContainerGutterBridge = (gutter: HTMLElement, container: HTMLElement, target: HTMLElement,
                                       x: number, y: number, getBlock: (button: HTMLElement) => Element) => {
    if (gutter.classList.contains("fn__none") ||
        !["NodeBlockquote", "NodeCallout", "NodeSuperBlock", "NodeBlockQueryEmbed", "NodeList", "NodeListItem"]
            .includes(container.dataset.type) ||
        target.closest(".callout-info")) {
        return false;
    }
    const gutterRect = gutter.getBoundingClientRect();
    return Array.from(gutter.querySelectorAll<HTMLElement>("button[data-node-id]")).some(button => {
        if (button.dataset.type === "fold" || button.dataset.rowId) {
            return false;
        }
        const block = getBlock(button);
        if (!block || block === container || !container.contains(block)) {
            return false;
        }
        const blockRect = block.getBoundingClientRect();
        return x >= gutterRect.left && x <= blockRect.left &&
            y >= Math.min(blockRect.top, gutterRect.top) && y <= Math.max(blockRect.bottom, gutterRect.bottom);
    });
};