An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作
TypeScript agentic-aiai-agentknowledge-baselocal-firstmarkdownmcpmindmapnote-takingself-hostedsiyuanworkspace
:bug: Preserve dragged blocks across dynamic loading https://github.com/siyuan-note/siyuan/issues/10096
Daniel6cf35a2a21c1
diff --git a/app/src/protyle/util/dragDocument.test.ts b/app/src/protyle/util/dragDocument.test.tsindex 7ce5912907..75a5a99441 100644--- a/app/src/protyle/util/dragDocument.test.ts+++ b/app/src/protyle/util/dragDocument.test.ts@@ -5,6 +5,7 @@ import {getAVRowDropTarget,getBlockDragInsertPosition,getBlockDragoverTarget,+ getMissingDragIds,getSameSuperBlockEdgeTarget,getSuperBlockResizeDropTarget,getTopListDragTarget,@@ -214,6 +215,14 @@ describe("uniqueDragIds", () => {});});+describe("getMissingDragIds", () => {+ it("returns source IDs unloaded during dynamic loading", () => {+ assert.deepEqual(getMissingDragIds(["a", "b"], new Set()), ["a", "b"]);+ assert.deepEqual(getMissingDragIds(["a", "b", "c"], new Set(["a", "c"])), ["b"]);+ assert.deepEqual(getMissingDragIds(["a", "b"], new Set(["a", "b"])), []);+ });+});+describe("getAVRowDropTarget", () => {it("uses the preceding row for the table utility row", () => {const row = createClassElement(["av__row"], null, "row-1");diff --git a/app/src/protyle/util/dragDocument.ts b/app/src/protyle/util/dragDocument.tsindex eac18cede0..84aefb7c17 100644--- a/app/src/protyle/util/dragDocument.ts+++ b/app/src/protyle/util/dragDocument.ts@@ -102,6 +102,10 @@ export const uniqueDragIds = (ids: string[]) => {return Array.from(new Set(ids.filter(Boolean)));};+export const getMissingDragIds = (selectedIds: string[], sourceIds: ReadonlySet<string>) => {+ return selectedIds.filter(id => !sourceIds.has(id));+};+export const getAVRowDropTarget = (targetElement: HTMLElement | false): HTMLElement | false => {if (!targetElement || !targetElement.classList.contains("av__row--util")) {return targetElement;diff --git a/app/src/protyle/util/editorCommonEvent.ts b/app/src/protyle/util/editorCommonEvent.tsindex 2a22d1f3ee..013032caf4 100644--- a/app/src/protyle/util/editorCommonEvent.ts+++ b/app/src/protyle/util/editorCommonEvent.ts@@ -61,6 +61,7 @@ import {getAVRowDropTarget,getBlockDragInsertPosition,getBlockDragoverTarget,+ getMissingDragIds,getSameSuperBlockEdgeTarget,getSuperBlockResizeDropTarget,getTopListDragTarget,@@ -1531,15 +1532,19 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {window.siyuan.dragElement.querySelectorAll(queryClass.substring(0, queryClass.length - 1)).forEach(elementItem => {appendSourceElement(elementItem);});- } else if (window.siyuan.config.system.workspaceDir.toLowerCase() === gutterTypes[3]) {- // 跨窗口拖拽+ }+ const missingSourceIds = getMissingDragIds(selectedIds, sourceElementIds);+ if (missingSourceIds.length > 0 &&+ window.siyuan.config.system.workspaceDir.toLowerCase() === gutterTypes[3]) {+ // 跨窗口拖拽或动态加载卸载源块时,从拖拽快照中补齐源块// 不能跨工作区域拖拽 https://github.com/siyuan-note/siyuan/issues/13582const dragData = parseBlockDragData(event.dataTransfer.getData(gutterType));const sourceProtyleElement = document.createElement("div");sourceProtyleElement.setAttribute(DRAG_SOURCE_NOTEBOOK_ID, dragData.notebookID);sourceProtyleElement.setAttribute(DRAG_SOURCE_ROOT_ID, dragData.rootID);sourceProtyleElement.innerHTML = dragData.html;- sourceProtyleElement.querySelectorAll(queryClass.substring(0, queryClass.length - 1)).forEach(elementItem => {+ const missingSourceSelector = missingSourceIds.map(id => `[data-node-id="${id}"]`).join(",");+ sourceProtyleElement.querySelectorAll(missingSourceSelector).forEach(elementItem => {appendSourceElement(elementItem);});}