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: Align pinned document drag interactions https://github.com/siyuan-note/siyuan/issues/19401
Danielff97ed05c851
diff --git a/app/src/layout/dock/PinnedDocs.test.ts b/app/src/layout/dock/PinnedDocs.test.tsindex dcae980310..1d06831ea5 100644--- a/app/src/layout/dock/PinnedDocs.test.ts+++ b/app/src/layout/dock/PinnedDocs.test.ts@@ -45,7 +45,10 @@ const loadPanel = (fetchCode = 0) => {const config = {readonly: false, fileTree: {docIconClickExpand: false, parentDocClickExpand: false}};const calls: {kind: string, args: unknown[]}[] = [];const timers: (() => void)[] = [];- const runtime = {config, notebooks: [] as unknown[], languages: {}, touchDragActive: false, touchDragGhost: undefined as unknown};+ const runtime = {config, notebooks: [] as unknown[], languages: {pinDoc: "Pin", dragTipMoveChild: "Into ${x}",+ dragTipMoveBefore: "Before ${x}", dragTipMoveAfter: "After ${x}"}, dragElement: undefined as {innerText: string},+ dragTitle: "Document", touchDragActive: false, touchDragGhost: undefined as unknown};+ const tips: unknown[][] = [];const record = (kind: string) => async (...args: unknown[]) => {calls.push({kind, args});return {code: kind === "http" ? fetchCode : 0, data: args[0] === "/api/filetree/listDocsByPath" ? childData : docs};@@ -67,7 +70,8 @@ const loadPanel = (fetchCode = 0) => {remove() { calls.push({kind: "removeGhost", args: [this]}); },})},require: (name: string) => {- if (name.endsWith("/dragTip")) { return {setDragTipGhost: record("dragTipGhost")}; }+ if (name.endsWith("/dragTip")) { return {setDragTipGhost: record("dragTipGhost"),+ showDragTip: (...args: unknown[]) => tips.push(args), hideDragTip: () => tips.push([])}; }if (name.endsWith("/fileTreeAnimation")) { return {setFileTreeVisibility: (element: HTMLElement, visible: boolean) => element.classList.toggle("fn__none", !visible)}; }if (name.endsWith("/pinnedDocsDrop")) { return {getPinnedDropPosition}; }if (name.endsWith("/dragover")) { return {dragOverScroll: () => {}}; }@@ -92,7 +96,7 @@ const loadPanel = (fetchCode = 0) => {panel.scheduleRefresh = () => {};panel.list = {querySelectorAll: (): unknown[] => []};panel.sourceTree = {querySelectorAll: (): unknown[] => []};- return {panel, calls, config, docs, storage, childData, hitTest, runtime, timers};+ return {panel, calls, config, docs, storage, childData, hitTest, runtime, timers, tips};};test("collapse clears descendant expansion and persists the closed section", async () => {@@ -231,6 +235,7 @@ test("dropping on a notebook resolves its outer list ID with or without root docconst {panel, calls, hitTest} = loadPanel();const highlights: string[] = [];const row = {dataset: {type: "navigation-root", nodeId: ""},+ querySelector: () => ({textContent: "Notebook"}),closest: (selector: string) => selector === "ul[data-url]" ? {dataset: {url: "notebook"}} : null,getBoundingClientRect: () => ({top: 0, height: 30}), classList: {add: (name: string) => highlights.push(name)}};hitTest.target = {closest: () => row};@@ -263,6 +268,7 @@ test("pinned heading highlights the whole row while root reorder keeps insertionpanel.previewDrop(10, 20);assert.deepEqual(highlights, ["dragover", "dragover"]);const row = {dataset: {pinRoot: "true", nodeId: "document"},+ querySelector: () => ({textContent: "Document"}),getBoundingClientRect: () => ({top: 0, height: 30}), classList: {add: (name: string) => highlights.push(name)}};hitTest.target = {closest: () => row};panel.previewDrop(10, 1);@@ -293,6 +299,38 @@ test("desktop pinned drags create an unclipped ghost and preserve synthetic touc}});+test("pin drop tips describe pinning and source moves, and self targets clear feedback", () => {+ const {panel, hitTest, runtime, tips} = loadPanel();+ const highlights: string[] = [];+ let source = false;+ const row = {dataset: {pinRoot: "true", nodeId: "target"}, querySelector: () => ({textContent: "Target"}),+ getBoundingClientRect: () => ({top: 0, height: 30}), classList: {add: (name: string) => highlights.push(name)},+ closest: (): Element | null => null};+ hitTest.target = {closest: () => row};+ panel.sourceTree = {contains: () => source, getBoundingClientRect: () => ({})};+ panel.element = {contains: () => !source};+ panel.list = {getBoundingClientRect: () => ({})};+ runtime.dragElement = {innerText: "source"};+ panel.previewDrop(10, 1);+ assert.deepEqual(tips.at(-1), ["Document", "Pin", 10, 1]);+ source = true;+ row.dataset.pinRoot = "false";+ panel.previewDrop(10, 15, true);+ assert.deepEqual(tips.at(-1), ["Document", "Into Target", 10, 15]);+ panel.previewDrop(10, 1, true);+ assert.deepEqual(tips.at(-1), ["Document", "Before Target", 10, 1]);+ panel.previewDrop(10, 29, true);+ assert.deepEqual(tips.at(-1), ["Document", "After Target", 10, 29]);+ for (source of [true, false]) {+ runtime.dragElement.innerText = "target";+ const count = highlights.length;+ assert.equal(panel.previewDrop(10, 15, true), false);+ assert.equal(panel.dropTarget, undefined);+ assert.equal(highlights.length, count);+ assert.deepEqual(tips.at(-1), []);+ }+});+test("invalid drop targets and self moves do not mutate source documents", async () => {const {panel, calls} = loadPanel();panel.previewDrop = () => { panel.dropTarget = undefined; };diff --git a/app/src/layout/dock/PinnedDocs.ts b/app/src/layout/dock/PinnedDocs.tsindex 9432d66677..302dd02655 100644--- a/app/src/layout/dock/PinnedDocs.ts+++ b/app/src/layout/dock/PinnedDocs.ts@@ -15,7 +15,7 @@ import {newFileInTree} from "../../util/newFile";import {isOnlyMeta} from "../../protyle/util/compatibility";import {FILE_TREE_CHILDREN_SORT_MODE, FILE_TREE_EFFECTIVE_SORT_MODE} from "../../util/fileTreeSort";import {setFileTreeVisibility} from "./fileTreeAnimation";-import {setDragTipGhost} from "../../protyle/util/dragTip";+import {hideDragTip, setDragTipGhost, showDragTip} from "../../protyle/util/dragTip";interface IPinnedDoc {id: string;@@ -41,6 +41,7 @@ export class PinnedDocs {private touch: {id: string, x: number, y: number, timer: number, dragging: boolean, ghost?: HTMLElement};private suppressClick = false;private dragging = false;+ private draggedRow: HTMLElement;private sourceEvents = new AbortController();private names = new Map<string, string>();private rootSnapshot: string;@@ -108,7 +109,17 @@ export class PinnedDocs {event.dataTransfer.setData(Constants.SIYUAN_DROP_DOCUMENTS, JSON.stringify({ids: [row.dataset.nodeId]}));event.dataTransfer.setData(Constants.SIYUAN_DROP_FILE, row.dataset.nodeId);event.dataTransfer.effectAllowed = "copyMove";+ if (!row.classList.contains("b3-list-item--focus")) {+ this.clearSelection();+ row.classList.add("b3-list-item--focus");+ }this.setDragImage(row, event.dataTransfer);+ this.draggedRow = row;+ row.style.opacity = "0.38";+ this.element.closest(".sy__file")?.classList.add("sy__file--disablehover");+ window.siyuan.dragTitle = row.querySelector(".b3-list-item__text")?.textContent?.trim() || "";+ window.siyuan.dragElement = document.createElement("div");+ window.siyuan.dragElement.innerText = row.dataset.nodeId;});this.element.addEventListener("dragover", event => {if (window.siyuan.config.readonly || ![Constants.SIYUAN_DROP_DOCUMENTS, Constants.SIYUAN_DROP_FILE,@@ -118,7 +129,7 @@ export class PinnedDocs {event.preventDefault();event.stopPropagation();this.previewDrop(event.clientX, event.clientY);- event.dataTransfer.dropEffect = this.dropTarget?.position.startsWith("pin") ? "copy" : "move";+ event.dataTransfer.dropEffect = !this.dropTarget ? "none" : this.dropTarget.position.startsWith("pin") ? "copy" : "move";});this.element.addEventListener("drop", async event => {event.preventDefault();@@ -138,6 +149,11 @@ export class PinnedDocs {this.element.addEventListener("dragend", () => {this.clearDrop();this.dragging = false;+ if (this.draggedRow) { this.draggedRow.style.opacity = ""; }+ this.draggedRow = undefined;+ this.element.closest(".sy__file")?.classList.remove("sy__file--disablehover");+ window.siyuan.dragElement = undefined;+ window.siyuan.dragTitle = "";this.scheduleRefresh();});sourceTree.addEventListener("dragover", event => {@@ -145,6 +161,7 @@ export class PinnedDocs {event.preventDefault();event.stopImmediatePropagation();this.previewDrop(event.clientX, event.clientY, true);+ event.dataTransfer.dropEffect = this.dropTarget ? "move" : "none";}, {capture: true, signal: this.sourceEvents.signal});sourceTree.addEventListener("drop", event => {const id = event.dataTransfer.getData("application/siyuan-pinned-document");@@ -452,7 +469,7 @@ export class PinnedDocs {private setDragImage(row: HTMLElement, dataTransfer: DataTransfer) {const ghost = document.createElement("ul");ghost.className = "b3-list b3-list--background";- ghost.style.cssText = "width:219px;position:fixed;top:-30px;pointer-events:none";+ ghost.style.cssText = "width:219px;position:fixed;top:-30px";ghost.append(row.cloneNode(true));document.body.append(ghost);setDragTipGhost(ghost, 16, 16);@@ -465,33 +482,44 @@ export class PinnedDocs {}public previewDrop(x: number, y: number, allowSource = false) {- this.clearDrop();+ this.clearDrop(false);+ const rejectDrop = () => { hideDragTip(); return false; };const target = document.elementFromPoint(x, y);- if (!target || window.siyuan.config.readonly) { return false; }+ if (!target || window.siyuan.config.readonly) { return rejectDrop(); }const source = allowSource && this.sourceTree.contains(target);- if (!this.element.contains(target) && !source) { return false; }+ if (!this.element.contains(target) && !source) { return rejectDrop(); }const row = target.closest<HTMLElement>(source ? "li[data-type]" : "[data-pin-row]");- if (source && (!row || row.closest("[data-encrypted=true]"))) { return false; }+ if (source && (!row || row.closest("[data-encrypted=true]"))) { return rejectDrop(); }if (!row) {this.dropTarget = {id: "", position: "pin-before"};this.heading.classList.add("dragover");} else {- if (row.dataset.unavailable === "true") { return false; }+ if (row.dataset.unavailable === "true") { return rejectDrop(); }const rect = row.getBoundingClientRect();const position = source && row.dataset.type === "navigation-root" ? "inside" :getPinnedDropPosition(row.dataset.pinRoot === "true", (y - rect.top) / rect.height);const id = source && row.dataset.type === "navigation-root" ?row.closest<HTMLElement>("ul[data-url]")?.dataset.url : row.dataset.nodeId;- if (!id) { return false; }+ const draggedIDs = this.touch ? [this.touch.id] :+ (window.siyuan.dragElement?.innerText || this.draggedRow?.dataset.nodeId || "").split(",");+ if (!id || draggedIDs.includes(id)) { return rejectDrop(); }this.dropTarget = {id, position};row.classList.add(position === "inside" ? "dragover" : position.endsWith("before") ? "dragover__top" : "dragover__bottom");}+ const name = row?.querySelector(".b3-list-item__text")?.textContent || "";+ const position = this.dropTarget.position;+ const action = position.startsWith("pin") ? window.siyuan.languages.pinDoc :+ (position === "inside" ? window.siyuan.languages.dragTipMoveChild :+ position === "before" ? window.siyuan.languages.dragTipMoveBefore : window.siyuan.languages.dragTipMoveAfter)+ .replace("${x}", name);+ showDragTip(window.siyuan.dragTitle || "", action, x, y);const scrollElement = source ? this.sourceTree : this.list;dragOverScroll({clientY: y} as MouseEvent, scrollElement.getBoundingClientRect(), scrollElement);return true;}- public clearDrop() {+ public clearDrop(hideTip = true) {+ if (hideTip) { hideDragTip(); }this.dropTarget = undefined;this.element.querySelectorAll(".dragover, .dragover__top, .dragover__bottom").forEach(row =>row.classList.remove("dragover", "dragover__top", "dragover__bottom"));