An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:art: https://github.com/siyuan-note/siyuan/issues/14034
Daniel419277392bb4
diff --git a/app/src/boot/globalEvent/event.ts b/app/src/boot/globalEvent/event.tsindex a69820233f..a7639a11de 100644--- a/app/src/boot/globalEvent/event.ts+++ b/app/src/boot/globalEvent/event.ts@@ -102,6 +102,8 @@ export const initWindowEvent = (app: App) => {});window.addEventListener("dragend", () => {stopScrollAnimation();+ document.querySelector(".drag-tip")?.remove();+ window.siyuan.dragTitle = "";});window.addEventListener("dragleave", () => {stopScrollAnimation();diff --git a/app/src/layout/dock/Files.ts b/app/src/layout/dock/Files.tsindex a626821995..0f02bec0cb 100644--- a/app/src/layout/dock/Files.ts+++ b/app/src/layout/dock/Files.ts@@ -33,6 +33,85 @@ import {ipcRenderer} from "electron";import {hideTooltip, showTooltip} from "../../dialog/tooltip";import {selectOpenTab} from "./util";+// 拖拽时跟随鼠标的自定义双区提示框:上半=操作对象名称,下半=操作文案+// 通过 .drag-tip 类做全局单例,避免编辑器与文档树两处 dragover 互相残留+const dragTipState = {+ rafId: 0, title: "", action: "", x: 0, y: 0,+ element: null as HTMLElement, titleElement: null as HTMLElement, actionElement: null as HTMLElement,+ lastTitle: "", lastAction: ""+};++const renderDragTip = () => {+ dragTipState.rafId = 0;+ if (!dragTipState.element || !dragTipState.element.isConnected) {+ // 优先复用已有的 .drag-tip(跨编辑器/文档树区域时避免重复创建)+ dragTipState.element = (document.querySelector(".drag-tip") as HTMLElement) || null;+ if (!dragTipState.element) {+ dragTipState.element = document.createElement("div");+ dragTipState.element.className = "tooltip drag-tip";+ // 拖拽提示需即时显示,覆盖 .tooltip 默认的 300ms 出现动画+ dragTipState.element.style.animation = "none";+ dragTipState.element.style.pointerEvents = "none";+ dragTipState.element.style.zIndex = "1000000";+ dragTipState.element.style.fontSize = "14px";+ dragTipState.element.style.lineHeight = "20px";+ // 锚定到视口原点,再由 transform 定位(transform 走 GPU 合成,不触发 layout)+ dragTipState.element.style.top = "0";+ dragTipState.element.style.left = "0";+ dragTipState.titleElement = document.createElement("div");+ dragTipState.titleElement.className = "drag-tip__title";+ dragTipState.titleElement.style.cssText = "max-width:200px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--b3-theme-on-background);";+ dragTipState.actionElement = document.createElement("div");+ dragTipState.actionElement.className = "drag-tip__action";+ dragTipState.actionElement.style.cssText = "color:var(--b3-tooltips-second-color);font-size:12px;";+ dragTipState.element.append(dragTipState.titleElement, dragTipState.actionElement);+ document.body.append(dragTipState.element);+ } else {+ dragTipState.titleElement = dragTipState.element.querySelector(".drag-tip__title");+ dragTipState.actionElement = dragTipState.element.querySelector(".drag-tip__action");+ }+ dragTipState.lastTitle = "";+ dragTipState.lastAction = "";+ }+ // 名称/文案变化才写 textContent,减少 DOM 写入+ if (dragTipState.lastTitle !== dragTipState.title) {+ dragTipState.titleElement.textContent = dragTipState.title;+ dragTipState.lastTitle = dragTipState.title;+ // 名称为空时隐藏上半行+ dragTipState.titleElement.style.display = dragTipState.title ? "" : "none";+ }+ if (dragTipState.lastAction !== dragTipState.action) {+ dragTipState.actionElement.textContent = dragTipState.action;+ dragTipState.lastAction = dragTipState.action;+ }+ // 固定偏移到光标右下方,不读取 offsetHeight 以免触发同步布局造成卡顿+ dragTipState.element.style.transform = `translate(${dragTipState.x + 16}px, ${dragTipState.y + 16}px)`;+};++const showDragTip = (title: string, action: string, x: number, y: number) => {+ dragTipState.title = title;+ dragTipState.action = action;+ dragTipState.x = x;+ dragTipState.y = y;+ // 合并到下一帧渲染,避免高频 dragover 下逐次写 DOM 造成卡顿+ if (!dragTipState.rafId) {+ dragTipState.rafId = requestAnimationFrame(renderDragTip);+ }+};++const hideDragTip = () => {+ if (dragTipState.rafId) {+ cancelAnimationFrame(dragTipState.rafId);+ dragTipState.rafId = 0;+ }+ dragTipState.element?.remove();+ dragTipState.element = null;+ dragTipState.titleElement = null;+ dragTipState.actionElement = null;+ dragTipState.lastTitle = "";+ dragTipState.lastAction = "";+};+export class Files extends Model {public element: HTMLElement;public parent: Tab;@@ -401,18 +480,24 @@ export class Files extends Model {ghostElement.setAttribute("style", `width: 219px;position: fixed;top:-${selectElements.length * 30}px`);ghostElement.setAttribute("class", "b3-list b3-list--background");document.body.append(ghostElement);- event.dataTransfer.setDragImage(ghostElement, 16, 16);- event.dataTransfer.setData(Constants.SIYUAN_DROP_FILE, ids);- event.dataTransfer.dropEffect = "move";- window.siyuan.dragElement = document.createElement("div");- window.siyuan.dragElement.innerText = ids;if (window.siyuan.touchDragActive) {+ // 触屏保留 DOM ghost 供 touchDragBridge 跟随手指+ event.dataTransfer.setDragImage(ghostElement, 16, 16);window.siyuan.touchDragGhost = ghostElement;} else {+ // 桌面端隐藏原生 ghost,改用自定义双区跟随框+ const transparentImg = new Image();+ transparentImg.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=";+ event.dataTransfer.setDragImage(transparentImg, 0, 0);setTimeout(() => {ghostElement.remove();});}+ event.dataTransfer.setData(Constants.SIYUAN_DROP_FILE, ids);+ event.dataTransfer.dropEffect = "move";+ window.siyuan.dragTitle = (selectElements[0] as HTMLElement)?.querySelector(".b3-list-item__text")?.textContent?.trim() || "";+ window.siyuan.dragElement = document.createElement("div");+ window.siyuan.dragElement.innerText = ids;}});const dragOverLastObj: {@@ -449,6 +534,8 @@ export class Files extends Model {}});window.siyuan.dragElement = undefined;+ hideDragTip();+ window.siyuan.dragTitle = "";/// #if !BROWSERipcRenderer.send(Constants.SIYUAN_SEND_WINDOWS, {cmd: "resetTabsStyle", data: "rmDragStyle"});/// #else@@ -472,6 +559,14 @@ export class Files extends Model {gutterType = item.type;}}+ // 非标题/列表的块标(如段落)拖到文档树无需提示;标题/列表项的提示在下方 rAF 回调内根据高亮类显示+ if (gutterType) {+ const gutterTypes = gutterType.replace(Constants.SIYUAN_DROP_GUTTER, "").split(Constants.ZWSP);+ if (!["nodelistitem", "nodeheading"].includes(gutterTypes[0])) {+ hideDragTip();+ }+ }+ // 文档→文档拖拽的提示在下方 rAF 回调中根据高亮类判定(需等高亮类确定后再显示)dragOverLastObj.rafId = requestAnimationFrame(() => {dragOverLastObj.rafId = null;let liElement = event.target.closest("li");@@ -480,6 +575,7 @@ export class Files extends Model {}if (!liElement) {dragOverLastObj.element = null;+ hideDragTip();event.preventDefault();return;}@@ -495,6 +591,7 @@ export class Files extends Model {}} else if (liElement.classList.contains("b3-list-item--focus")) {// 选中的文档不能拖拽到自己上,但允许标题拖拽到文档树的选中文档上 https://github.com/siyuan-note/siyuan/issues/6552+ hideDragTip();event.preventDefault();return;}@@ -510,6 +607,7 @@ export class Files extends Model {}}if (dragOverLastObj.sourceOnlyRoot && targetType !== "navigation-root") {+ hideDragTip();event.preventDefault();return;}@@ -517,6 +615,7 @@ export class Files extends Model {if (dragOverLastObj.element && dragOverLastObj.element === liElement && dragOverLastObj.positionY !== event.clientY) {const notebookElement = hasClosestByAttribute(liElement, "data-sortmode", null);if (!notebookElement) {+ hideDragTip();event.preventDefault();return;}@@ -551,6 +650,36 @@ export class Files extends Model {dragOverLastObj.element = liElement;}dragOverLastObj.positionY = event.clientY;+ // 文档→文档拖拽:依据当前高亮类显示对应操作提示(带目标文档名)+ if (!gutterType) {+ const name = liElement.querySelector(".b3-list-item__text")?.textContent || "";+ const title = window.siyuan.dragTitle || "";+ if (liElement.classList.contains("dragover__top")) {+ showDragTip(title, window.siyuan.languages.dragTipMoveBefore.replace("${x}", name), event.clientX, event.clientY);+ } else if (liElement.classList.contains("dragover__bottom")) {+ showDragTip(title, window.siyuan.languages.dragTipMoveAfter.replace("${x}", name), event.clientX, event.clientY);+ } else if (liElement.classList.contains("dragover")) {+ showDragTip(title, window.siyuan.languages.dragTipMoveChild.replace("${x}", name), event.clientX, event.clientY);+ } else {+ hideDragTip();+ }+ } else {+ // 块标(标题/列表项)→文档树:结合“转换为文档”和位置(带目标文档名)+ const gutterTypes = gutterType.replace(Constants.SIYUAN_DROP_GUTTER, "").split(Constants.ZWSP);+ if (["nodelistitem", "nodeheading"].includes(gutterTypes[0])) {+ const name = liElement.querySelector(".b3-list-item__text")?.textContent || "";+ const title = window.siyuan.dragTitle || "";+ let action: string;+ if (liElement.classList.contains("dragover__top")) {+ action = window.siyuan.languages.dragTip2DocBefore.replace("${x}", name);+ } else if (liElement.classList.contains("dragover__bottom")) {+ action = window.siyuan.languages.dragTip2DocAfter.replace("${x}", name);+ } else {+ action = window.siyuan.languages.dragTip2DocChild.replace("${x}", name);+ }+ showDragTip(title, action, event.clientX, event.clientY);+ }+ }event.preventDefault();});event.preventDefault();@@ -570,6 +699,8 @@ export class Files extends Model {});this.element.addEventListener("drop", async (event: DragEvent & { target: HTMLElement }) => {counter = 0;+ hideDragTip();+ window.siyuan.dragTitle = "";const newElement = this.element.querySelector(".dragover, .dragover__bottom, .dragover__top");if (!newElement) {return;diff --git a/app/src/protyle/gutter/index.ts b/app/src/protyle/gutter/index.tsindex 003a59ecbb..c3cdc6d818 100644--- a/app/src/protyle/gutter/index.ts+++ b/app/src/protyle/gutter/index.ts@@ -174,13 +174,27 @@ export class Gutter {});ghostElement.setAttribute("style", `position:fixed;opacity:.1;width:${selectElements[0].clientWidth}px;padding:0;`);document.body.append(ghostElement);- event.dataTransfer.setDragImage(ghostElement, 0, 0);- if (window.siyuan.touchDragActive) {- window.siyuan.touchDragGhost = ghostElement;- } else {+ // 仅标题块拖拽时隐藏原生 ghost 并改用自定义双区跟随框;其余块类型(段落/AV 行等)保留原生 ghost+ const isHeadingDrag = buttonElement.getAttribute("data-type") === "NodeHeading";+ if (isHeadingDrag && !window.siyuan.touchDragActive) {+ const transparentImg = new Image();+ transparentImg.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=";+ event.dataTransfer.setDragImage(transparentImg, 0, 0);setTimeout(() => {ghostElement.remove();});+ } else {+ event.dataTransfer.setDragImage(ghostElement, 0, 0);+ if (window.siyuan.touchDragActive) {+ window.siyuan.touchDragGhost = ghostElement;+ } else {+ setTimeout(() => {+ ghostElement.remove();+ });+ }+ }+ if (isHeadingDrag) {+ window.siyuan.dragTitle = getContenteditableElement(selectElements[0] as HTMLElement)?.textContent?.trim() || "";}buttonElement.style.opacity = "0.38";window.siyuan.dragElement = avElement as HTMLElement || protyle.wysiwyg.element;@@ -192,6 +206,7 @@ export class Gutter {item.style.opacity = "";});window.siyuan.dragElement = undefined;+ window.siyuan.dragTitle = "";});this.element.addEventListener("click", (event: MouseEvent & { target: HTMLInputElement }) => {const buttonElement = hasClosestByTag(event.target, "BUTTON");diff --git a/app/src/protyle/util/editorCommonEvent.ts b/app/src/protyle/util/editorCommonEvent.tsindex b1e3dd7155..f84c2347ee 100644--- a/app/src/protyle/util/editorCommonEvent.ts+++ b/app/src/protyle/util/editorCommonEvent.ts@@ -1,4 +1,5 @@import {focusBlock, focusByRange, getRangeByPoint} from "./selection";+import {getContenteditableElement, getParentBlock, getSbChildBlockCount, getTopAloneElement} from "../wysiwyg/getBlock";import {hasClosestBlock,hasClosestByAttribute,@@ -11,7 +12,6 @@ import {Constants} from "../../constants";import {paste} from "./paste";import {cancelSB, genEmptyElement, genSBElement, insertEmptyBlock, refreshSbResize} from "../../block/util";import {transaction, turnsIntoOneTransaction} from "../wysiwyg/transaction";-import {getParentBlock, getSbChildBlockCount, getTopAloneElement} from "../wysiwyg/getBlock";import {updateListOrder} from "../wysiwyg/list";import {fetchPost, fetchSyncPost} from "../../util/fetch";import {onGet} from "./onGet";@@ -40,6 +40,86 @@ import {dragoverTab} from "../render/av/view";import {setFold} from "./blockFold";// position: afterbegin 为拖拽成超级块; "afterend", "beforebegin" 一般拖拽++// 拖拽时跟随鼠标的自定义双区提示框:上半=操作对象名称,下半=操作文案+// 通过 .drag-tip 类做全局单例,避免编辑器与文档树两处 dragover 互相残留+const dragTipState = {+ rafId: 0, title: "", action: "", x: 0, y: 0,+ element: null as HTMLElement, titleElement: null as HTMLElement, actionElement: null as HTMLElement,+ lastTitle: "", lastAction: ""+};++const renderDragTip = () => {+ dragTipState.rafId = 0;+ if (!dragTipState.element || !dragTipState.element.isConnected) {+ // 优先复用已有的 .drag-tip(跨编辑器/文档树区域时避免重复创建)+ dragTipState.element = (document.querySelector(".drag-tip") as HTMLElement) || null;+ if (!dragTipState.element) {+ dragTipState.element = document.createElement("div");+ dragTipState.element.className = "tooltip drag-tip";+ // 拖拽提示需即时显示,覆盖 .tooltip 默认的 300ms 出现动画+ dragTipState.element.style.animation = "none";+ dragTipState.element.style.pointerEvents = "none";+ dragTipState.element.style.zIndex = "1000000";+ dragTipState.element.style.fontSize = "14px";+ dragTipState.element.style.lineHeight = "20px";+ // 锚定到视口原点,再由 transform 定位(transform 走 GPU 合成,不触发 layout)+ dragTipState.element.style.top = "0";+ dragTipState.element.style.left = "0";+ dragTipState.titleElement = document.createElement("div");+ dragTipState.titleElement.className = "drag-tip__title";+ dragTipState.titleElement.style.cssText = "max-width:200px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap;color:var(--b3-theme-on-background);";+ dragTipState.actionElement = document.createElement("div");+ dragTipState.actionElement.className = "drag-tip__action";+ dragTipState.actionElement.style.cssText = "color:var(--b3-tooltips-second-color);font-size:12px;";+ dragTipState.element.append(dragTipState.titleElement, dragTipState.actionElement);+ document.body.append(dragTipState.element);+ } else {+ dragTipState.titleElement = dragTipState.element.querySelector(".drag-tip__title");+ dragTipState.actionElement = dragTipState.element.querySelector(".drag-tip__action");+ }+ dragTipState.lastTitle = "";+ dragTipState.lastAction = "";+ }+ // 名称/文案变化才写 textContent,减少 DOM 写入+ if (dragTipState.lastTitle !== dragTipState.title) {+ dragTipState.titleElement.textContent = dragTipState.title;+ dragTipState.lastTitle = dragTipState.title;+ // 名称为空时隐藏上半行+ dragTipState.titleElement.style.display = dragTipState.title ? "" : "none";+ }+ if (dragTipState.lastAction !== dragTipState.action) {+ dragTipState.actionElement.textContent = dragTipState.action;+ dragTipState.lastAction = dragTipState.action;+ }+ // 固定偏移到光标右下方,不读取 offsetHeight 以免触发同步布局造成卡顿+ dragTipState.element.style.transform = `translate(${dragTipState.x + 16}px, ${dragTipState.y + 16}px)`;+};++const showDragTip = (title: string, action: string, x: number, y: number) => {+ dragTipState.title = title;+ dragTipState.action = action;+ dragTipState.x = x;+ dragTipState.y = y;+ // 合并到下一帧渲染,避免高频 dragover 下逐次写 DOM 造成卡顿+ if (!dragTipState.rafId) {+ dragTipState.rafId = requestAnimationFrame(renderDragTip);+ }+};++const hideDragTip = () => {+ if (dragTipState.rafId) {+ cancelAnimationFrame(dragTipState.rafId);+ dragTipState.rafId = 0;+ }+ dragTipState.element?.remove();+ dragTipState.element = null;+ dragTipState.titleElement = null;+ dragTipState.actionElement = null;+ dragTipState.lastTitle = "";+ dragTipState.lastAction = "";+};+const moveTo = async (protyle: IProtyle, sourceElements: Element[], targetElement: Element,isSameDoc: boolean, position: InsertPosition, isCopy: boolean) => {const doOperations: IOperation[] = [];@@ -620,14 +700,20 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {ghostElement.append(cloneElement);ghostElement.setAttribute("style", `position:fixed;opacity:.1;width:${target.parentElement.clientWidth}px;padding:0;`);document.body.append(ghostElement);- event.dataTransfer.setDragImage(ghostElement, 0, 0);if (window.siyuan.touchDragActive) {+ // 触屏保留 DOM ghost 供 touchDragBridge 跟随手指+ event.dataTransfer.setDragImage(ghostElement, 0, 0);window.siyuan.touchDragGhost = ghostElement;} else {+ // 桌面端隐藏原生 ghost,改用自定义双区跟随框+ const transparentImg = new Image();+ transparentImg.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII=";+ event.dataTransfer.setDragImage(transparentImg, 0, 0);setTimeout(() => {ghostElement.remove();});}+ window.siyuan.dragTitle = getContenteditableElement(target.parentElement)?.textContent?.trim() || "";window.siyuan.dragElement = protyle.wysiwyg.element;event.dataTransfer.setData(`${Constants.SIYUAN_DROP_GUTTER}NodeListItem${Constants.ZWSP}${target.parentElement.getAttribute("data-subtype")}${Constants.ZWSP}${[target.parentElement.getAttribute("data-node-id")]}`,@@ -723,6 +809,8 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {});editorElement.addEventListener("drop", async (event: DragEvent & { target: HTMLElement }) => {counter = 0;+ hideDragTip();+ window.siyuan.dragTitle = "";if (protyle.disabled || event.dataTransfer.getData(Constants.SIYUAN_DROP_EDITOR)) {// 只读模式/编辑器内选中文字拖拽event.preventDefault();@@ -1267,6 +1355,7 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {event.preventDefault();event.stopPropagation();event.dataTransfer.dropEffect = "none";+ hideDragTip();return;}let gutterType = "";@@ -1280,6 +1369,26 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {event.preventDefault();return;}+ // 操作提示:上半=操作对象名称,下半=操作文案+ if (event.dataTransfer.types.includes(Constants.SIYUAN_DROP_FILE)) {+ // 文档面板拖拽文档到编辑器(Alt = 转换为标题,默认 = 插入引用)+ showDragTip(window.siyuan.dragTitle || "",+ event.altKey ? window.siyuan.languages.dragTip2Heading : window.siyuan.languages.dragTipRef,+ event.clientX, event.clientY);+ } else if (gutterType.startsWith(`${Constants.SIYUAN_DROP_GUTTER}NodeHeading${Constants.ZWSP}`.toLowerCase())) {+ // 标题块拖入编辑器(含编辑器内重排):Alt=插入引用,Shift=嵌入块,默认=移动+ let action: string;+ if (event.altKey) {+ action = window.siyuan.languages.dragTipRef;+ } else if (event.shiftKey) {+ action = window.siyuan.languages.blockEmbed;+ } else {+ action = window.siyuan.languages.move;+ }+ showDragTip(window.siyuan.dragTitle || "", action, event.clientX, event.clientY);+ } else {+ hideDragTip();+ }let targetElement: HTMLElement | false;// 设置了的话 drop 就无法监听 shift/control event.dataTransfer.dropEffect = "move";if (event.dataTransfer.types.includes("Files")) {@@ -1687,6 +1796,8 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {window.siyuan.dragElement = undefined;document.onmousemove = null;}+ hideDragTip();+ window.siyuan.dragTitle = "";});};diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.tsindex d81eb8f134..613de5ec2e 100644--- a/app/src/types/index.d.ts+++ b/app/src/types/index.d.ts@@ -577,6 +577,7 @@ interface ISiyuan {}[]},dragElement?: HTMLElement,+ dragTitle?: string,currentDragOverTabHeadersElement?: HTMLElementtouchDragActive?: boolean,touchDragGhost?: HTMLElement | null,