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: Route block drops on tab headers into the active tab https://github.com/siyuan-note/siyuan/issues/19783
Daniel12338023a78c
diff --git a/app/src/protyle/util/dragDocument.test.ts b/app/src/protyle/util/dragDocument.test.tsindex 7130a67ca2..cc885f5237 100644--- a/app/src/protyle/util/dragDocument.test.ts+++ b/app/src/protyle/util/dragDocument.test.ts@@ -8,6 +8,7 @@ import {getMissingDragIds,getSameSuperBlockEdgeTarget,getSuperBlockResizeDropTarget,+ getTabsContentDropTarget,getTopListDragTarget,isAttributeViewTitleTarget,isCopyBlockDrag,@@ -107,6 +108,43 @@ const createSuperBlock = (layout = "col") => {return {blocks, superBlock};};+describe("getTabsContentDropTarget", () => {+ const first = {} as HTMLElement;+ const last = {} as HTMLElement;+ const content = {querySelectorAll: () => [first, last]} as unknown as HTMLElement;+ const item = {+ getAttribute: (name: string) => name === "data-type" ? "NodeTabItem" : null,+ querySelector: () => content,+ } as unknown as HTMLElement;+ const tabs = {+ getAttribute: (name: string) => name === "data-type" ? "NodeTabs" : null,+ querySelector: () => item,+ } as unknown as HTMLElement;+ const header = {parentElement: tabs} as HTMLElement;+ const headerHit = {closest: () => header} as unknown as HTMLElement;+ const bodyHit = {closest: (): null => null} as unknown as HTMLElement;++ it("inserts at the start of the active tab when hovering over its header", () => {+ assert.equal(getTabsContentDropTarget(tabs, headerHit), first);+ });++ it("uses the last body block when hovering over a tab item", () => {+ assert.equal(getTabsContentDropTarget(item, bodyHit), last);+ });++ it("keeps the tab container as an outer drop target outside the header", () => {+ assert.equal(getTabsContentDropTarget(tabs, bodyHit), tabs);+ });++ it("rejects a tab body without a persisted block target", () => {+ const emptyItem = {+ getAttribute: item.getAttribute.bind(item),+ querySelector: () => ({querySelectorAll: (): HTMLElement[] => []}),+ } as unknown as HTMLElement;+ assert.equal(getTabsContentDropTarget(emptyItem, bodyHit), null);+ });+});+describe("isSameDragEditor", () => {it("does not treat a nested Protyle as the target editor", () => {const sourceElement = {} as Element;diff --git a/app/src/protyle/util/dragDocument.ts b/app/src/protyle/util/dragDocument.tsindex cd1e89e2f6..1b0874c197 100644--- a/app/src/protyle/util/dragDocument.ts+++ b/app/src/protyle/util/dragDocument.ts@@ -125,6 +125,22 @@ export const getAVRowDropTarget = (targetElement: HTMLElement | false): HTMLElemreturn rowElement || targetElement;};+export const getTabsContentDropTarget = (target: HTMLElement, hit: HTMLElement): HTMLElement | null => {+ let item: HTMLElement;+ if (target.getAttribute("data-type") === "NodeTabItem") {+ item = target;+ } else if (target.getAttribute("data-type") === "NodeTabs" &&+ hit.closest(".tabs-header")?.parentElement === target) {+ item = target.querySelector<HTMLElement>(':scope > .tab-item[data-tabs-hidden="false"]') ||+ target.querySelector<HTMLElement>(":scope > .tab-item");+ } else {+ return target;+ }+ const blocks = item?.querySelector<HTMLElement>(":scope > .tab-item-content")+ ?.querySelectorAll<HTMLElement>(":scope > [data-node-id]");+ return blocks?.[target === item ? blocks.length - 1 : 0] || null;+};+export const isSameSiblingMove = <T>(siblings: T[], sources: T[], target: T, isBottom: boolean) => {if (sources.length === 0 || sources.includes(target)) {return sources.includes(target);diff --git a/app/src/protyle/util/editorCommonEvent.ts b/app/src/protyle/util/editorCommonEvent.tsindex 9fc02e7c34..b79d63e14a 100644--- a/app/src/protyle/util/editorCommonEvent.ts+++ b/app/src/protyle/util/editorCommonEvent.ts@@ -67,6 +67,7 @@ import {getMissingDragIds,getSameSuperBlockEdgeTarget,getSuperBlockResizeDropTarget,+ getTabsContentDropTarget,getTopListDragTarget,isAttributeViewTitleTarget,isCopyBlockDrag,@@ -2667,6 +2668,11 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {}}+ if (targetElement && gutterType && !isAvSubType && gutterTypes[0] !== "nodetabitem") {+ // 页签标题栏和空白正文区指向当前页签的正文块,避免把普通块移为页签项的兄弟。+ targetElement = getTabsContentDropTarget(targetElement, event.target);+ }+if (!targetElement) {clearBlockDragoverTarget();hideDragTip();