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: Allow dropping blocks into empty tab items https://github.com/siyuan-note/siyuan/issues/19807
Daniel0a55e8f7f0bc
diff --git a/app/src/assets/scss/protyle/_tabs.scss b/app/src/assets/scss/protyle/_tabs.scssindex 6f5ec4d964..f540c8d257 100644--- a/app/src/assets/scss/protyle/_tabs.scss+++ b/app/src/assets/scss/protyle/_tabs.scss@@ -185,7 +185,14 @@.tab-item-content {min-width: 0;+ min-height: 1.5em;outline: none;++ &.dragover__bottom {+ outline: 2px solid var(--b3-theme-primary-lighter);+ outline-offset: -2px;+ border-radius: var(--b3-border-radius);+ }}.tabs-tab--editing > .tabs-tab-label {diff --git a/app/src/protyle/util/dragDocument.test.ts b/app/src/protyle/util/dragDocument.test.tsindex cc885f5237..ccc92e029e 100644--- a/app/src/protyle/util/dragDocument.test.ts+++ b/app/src/protyle/util/dragDocument.test.ts@@ -136,12 +136,13 @@ describe("getTabsContentDropTarget", () => {assert.equal(getTabsContentDropTarget(tabs, bodyHit), tabs);});- it("rejects a tab body without a persisted block target", () => {+ it("uses an empty tab body as the drop target", () => {+ const emptyContent = {querySelectorAll: (): HTMLElement[] => []} as unknown as HTMLElement;const emptyItem = {getAttribute: item.getAttribute.bind(item),- querySelector: () => ({querySelectorAll: (): HTMLElement[] => []}),+ querySelector: () => emptyContent,} as unknown as HTMLElement;- assert.equal(getTabsContentDropTarget(emptyItem, bodyHit), null);+ assert.equal(getTabsContentDropTarget(emptyItem, bodyHit), emptyContent);});});diff --git a/app/src/protyle/util/dragDocument.ts b/app/src/protyle/util/dragDocument.tsindex 1b0874c197..4e391b738f 100644--- a/app/src/protyle/util/dragDocument.ts+++ b/app/src/protyle/util/dragDocument.ts@@ -136,9 +136,9 @@ export const getTabsContentDropTarget = (target: HTMLElement, hit: HTMLElement):} 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;+ const content = item?.querySelector<HTMLElement>(":scope > .tab-item-content");+ const blocks = content?.querySelectorAll<HTMLElement>(":scope > [data-node-id]");+ return blocks?.[target === item ? blocks.length - 1 : 0] || content || null;};export const isSameSiblingMove = <T>(siblings: T[], sources: T[], target: T, isBottom: boolean) => {diff --git a/app/src/protyle/util/editorCommonEvent.ts b/app/src/protyle/util/editorCommonEvent.tsindex b79d63e14a..94151a5a79 100644--- a/app/src/protyle/util/editorCommonEvent.ts+++ b/app/src/protyle/util/editorCommonEvent.ts@@ -283,7 +283,8 @@ const moveTo = async (protyle: IProtyle, sourceElements: Element[], targetElemenconst copyFoldHeadingIds: { newId: string, oldId: string }[] = [];const removedSourceIDs = new Set(sourceElements.map(item => item.getAttribute("data-node-id")).filter((id): id is string => !!id));- const targetId = targetElement.getAttribute("data-node-id");+ const targetId = targetElement.classList.contains("tab-item-content") ?+ targetElement.parentElement.getAttribute("data-node-id") : targetElement.getAttribute("data-node-id");const newSourceElements: Element[] = [];let tempTargetElement = targetElement;let isSameLi = true;@@ -298,7 +299,14 @@ const moveTo = async (protyle: IProtyle, sourceElements: Element[], targetElemenlet tabsPlaceholderID: string;const orderListElements: { [key: string]: { element: Element, start?: number } } = {};const sourceTabs = new Map<HTMLElement, {ids: string[], active: string}>();+ const sourceTabItems = new Set<HTMLElement>();if (!isCopy) {+ sourceElements.forEach(item => {+ const tabItem = item.closest<HTMLElement>(".tab-item");+ if (tabItem?.parentElement?.getAttribute("data-type") === "NodeTabs") {+ sourceTabItems.add(tabItem);+ }+ });sourceElements.filter(item => item.getAttribute("data-type") === "NodeTabItem").forEach(item => {const tabs = item.parentElement;if (tabs.getAttribute("data-type") !== "NodeTabs") {@@ -657,6 +665,17 @@ const moveTo = async (protyle: IProtyle, sourceElements: Element[], targetElementempTargetElement = isCopy ? copyElement : item;}}+ sourceTabItems.forEach(tabItem => {+ const content = tabItem.querySelector<HTMLElement>(":scope > .tab-item-content");+ if (!content || content.querySelector(":scope > [data-node-id]")) {+ return;+ }+ const paragraph = genEmptyElement(false, false);+ content.appendChild(paragraph);+ doOperations.push({action: "insert", id: paragraph.dataset.nodeId,+ parentID: tabItem.dataset.nodeId, data: paragraph.outerHTML});+ undoOperations.push({action: "delete", id: paragraph.dataset.nodeId});+ });sourceTabs.forEach(({ids, active}, tabs) => {if (!tabs.isConnected) {return;@@ -902,7 +921,8 @@ const dragSame = async (protyle: IProtyle, sourceElements: Element[], targetElemif (!isCopy && isDragTargetInSource(sourceElements, targetElement)) {return;}- const siblingElements = Array.from(targetElement.parentElement.children)+ const intoEmptyTab = targetElement.classList.contains("tab-item-content");+ const siblingElements = Array.from((intoEmptyTab ? targetElement : targetElement.parentElement).children).filter(item => item.hasAttribute("data-node-id"));if (!isCopy && isSameSiblingMove(siblingElements, sourceElements, targetElement, isBottom)) {return;@@ -921,7 +941,7 @@ const dragSame = async (protyle: IProtyle, sourceElements: Element[], targetElem});const sourceHasFoldHeading = sourceElements.some(isFoldedHeading);- const targetParentElement = targetElement.parentElement;+ const targetParentElement = intoEmptyTab ? targetElement : targetElement.parentElement;const isColumnDrop = targetParentElement.classList.contains("sb") &&targetParentElement.getAttribute("data-sb-layout") === "col";const wrapUndoOperations: IOperation[] = [];@@ -963,7 +983,7 @@ const dragSame = async (protyle: IProtyle, sourceElements: Element[], targetElemconst targetListStart = targetElement.getAttribute("data-type") === "NodeListItem" &&targetElement.getAttribute("data-subtype") === "o" ? getOrderedListStart(targetElement.parentElement) : undefined;const moveToResult = await moveTo(protyle, sourceElements, sourceRowElement || targetElement, isSameEditor,- sourceRowElement ? "afterbegin" : (isBottom ? "afterend" : "beforebegin"), isCopy, sourcePositions);+ sourceRowElement || intoEmptyTab ? "afterbegin" : (isBottom ? "afterend" : "beforebegin"), isCopy, sourcePositions);if (sourceRowElement && isCopy) {clearCopiedColumnWidth(sourceRowElement, moveToResult.doOperations);}@@ -1871,6 +1891,11 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {}}} else if (sourceElements.length > 0) {+ if (targetElement.classList.contains("tab-item-content")) {+ await dragSame(protyle, sourceElements, targetElement, false, isCopyDrag);+ dragoverElement = undefined;+ return;+ }const isChild = targetClass.some((c: string) => c.indexOf("--child") > -1);const isBottom = targetClass.some((c: string) => c.indexOf("dragover__bottom") === 0);@@ -2697,6 +2722,21 @@ export const dropEvent = (protyle: IProtyle, editorElement: HTMLElement) => {hideDragTip();return;}+ if (targetElement.classList.contains("tab-item-content")) {+ const isSelf = !event.ctrlKey && !event.shiftKey && !event.altKey && gutterTypes[2]?.split(",").some(id =>+ id && hasClosestByAttribute(targetElement as HTMLElement, "data-node-id", id));+ if (isSelf) {+ clearBlockDragoverTarget();+ hideDragTip();+ return;+ }+ if (dragoverElement !== targetElement || !targetElement.classList.contains("dragover__bottom")) {+ clearBlockDragoverTarget();+ targetElement.classList.add("dragover__bottom");+ dragoverElement = targetElement;+ }+ return;+ }const isNotAvItem = !targetElement.classList.contains("av__row") &&!targetElement.classList.contains("av__row--util") &&!targetElement.classList.contains("av__gallery-item") &&