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: Align top bar dragging with dock behavior https://github.com/siyuan-note/siyuan/issues/18285
Daniel2f19b37b2d13
diff --git a/app/src/assets/scss/util/_reset.scss b/app/src/assets/scss/util/_reset.scssindex 0fc7f7c91c..384eb4b98f 100644--- a/app/src/assets/scss/util/_reset.scss+++ b/app/src/assets/scss/util/_reset.scss@@ -179,6 +179,11 @@ body {right: 0;width: var(--b3-toolbar-drag-right);}++ &[data-topbar-reordering="true"]::before,+ &[data-topbar-reordering="true"]::after {+ -webkit-app-region: no-drag;+ }}.fullscreen > .protyle-breadcrumb,diff --git a/app/src/layout/topBarDrag.test.ts b/app/src/layout/topBarDrag.test.tsindex ddf9c1e9d0..13599105c4 100644--- a/app/src/layout/topBarDrag.test.ts+++ b/app/src/layout/topBarDrag.test.ts@@ -76,6 +76,19 @@ class TestEventTarget {class TestElement extends TestEventTarget {public children: TestElement[] = [];public className = "";+ public classList = {+ add: (...tokens: string[]) => {+ const names = new Set(this.className.split(/\s+/).filter(Boolean));+ tokens.forEach((token) => names.add(token));+ this.className = Array.from(names).join(" ");+ },+ contains: (token: string) => this.className.split(/\s+/).includes(token),+ remove: (...tokens: string[]) => {+ const removed = new Set(tokens);+ this.className = this.className.split(/\s+/).filter((token) => token && !removed.has(token)).join(" ");+ },+ };+ public innerHTML = "";public parentElement: TestElement | null = null;public style: Record<string, string> = {opacity: ""};private attributes = new Map<string, string>();@@ -210,6 +223,9 @@ const createToolbar = () => {return {controls, documentSelf, drag, left, more, right, toolbar, workspace};};+const getPlaceholder = (toolbar: TestElement) => toolbar.children.find((item) =>+ item.hasAttribute("data-topbar-drag-placeholder"));+describe("top bar drag", () => {it("reads only direct configurable entries and the fixed drag key", () => {const toolbar = {@@ -252,7 +268,7 @@ describe("top bar drag", () => {});it("moves an entry across drag, cleans up, and suppresses the generated click", () => {- const {documentSelf, drag, left, toolbar} = createToolbar();+ const {controls, documentSelf, drag, left, toolbar} = createToolbar();const orders: string[][] = [];const unbind = topBarDrag.bindTopBarDrag(toolbar as unknown as HTMLElement,@@ -264,7 +280,20 @@ describe("top bar drag", () => {documentSelf.dispatch("mousemove", new TestEvent(drag, 120, 12));assert.equal(documentSelf.body.children.length, 1);assert.equal(left.style.opacity, "0.38");- documentSelf.dispatch("mouseup", new TestEvent(drag, 120, 12));+ assert.deepEqual(topBarDrag.getTopBarOrder(toolbar as unknown as HTMLElement), ["back", "drag", "search"]);+ assert.equal(getPlaceholder(toolbar), undefined);+ const ghost = documentSelf.body.children[0];+ assert.equal(ghost.style.backgroundColor, "var(--b3-theme-background-light)");+ assert.equal(ghost.style.left, "108px");+ assert.equal(ghost.style.top, "0px");+ assert.equal(ghost.style.transition, "none");+ documentSelf.dispatch("mousemove", new TestEvent(drag, 120, 12));+ const placeholder = getPlaceholder(toolbar);+ assert.ok(placeholder);+ assert.equal(placeholder.classList.contains("fn__none"), false);+ documentSelf.dispatch("mousemove", new TestEvent(controls, 250, 12));+ assert.equal(getPlaceholder(toolbar), placeholder);+ documentSelf.dispatch("mouseup", new TestEvent(controls, 250, 12));assert.deepEqual(topBarDrag.getTopBarOrder(toolbar as unknown as HTMLElement), ["drag", "back", "search"]);assert.deepEqual(orders, [["drag", "back", "search"]]);@@ -288,6 +317,36 @@ describe("top bar drag", () => {assert.equal(toolbar.listenerCount("click"), 0);});+ it("stabilizes target changes and hides the candidate after returning to the source", () => {+ const {documentSelf, drag, left, right, toolbar} = createToolbar();+ const orders: string[][] = [];+ const unbind = topBarDrag.bindTopBarDrag(+ toolbar as unknown as HTMLElement,+ (order) => orders.push(order),+ );++ toolbar.dispatch("mousedown", new TestEvent(left, 30, 12));+ documentSelf.dispatch("mousemove", new TestEvent(drag, 120, 12));+ documentSelf.dispatch("mousemove", new TestEvent(drag, 120, 12));+ const placeholder = getPlaceholder(toolbar);+ assert.ok(placeholder);+ assert.equal(toolbar.children.indexOf(placeholder), toolbar.children.indexOf(drag) + 1);++ documentSelf.dispatch("mousemove", new TestEvent(right, 165, 12));+ assert.equal(toolbar.children.indexOf(placeholder), toolbar.children.indexOf(drag) + 1);+ documentSelf.dispatch("mousemove", new TestEvent(right, 165, 12));+ assert.equal(toolbar.children.indexOf(placeholder), toolbar.children.indexOf(right) + 1);++ documentSelf.dispatch("mousemove", new TestEvent(left, 30, 12));+ assert.equal(placeholder.classList.contains("fn__none"), true);+ documentSelf.dispatch("mouseup", new TestEvent(left, 30, 12));++ assert.deepEqual(orders, []);+ assert.deepEqual(topBarDrag.getTopBarOrder(toolbar as unknown as HTMLElement), ["back", "drag", "search"]);+ assert.equal(documentSelf.body.children.length, 0);+ unbind();+ });+it("ignores non-primary, readonly, and below-threshold mouse movement", () => {const {documentSelf, drag, left, toolbar} = createToolbar();let changeCount = 0;diff --git a/app/src/layout/topBarDrag.ts b/app/src/layout/topBarDrag.tsindex 5c9ce4e7ad..846e6182d1 100644--- a/app/src/layout/topBarDrag.ts+++ b/app/src/layout/topBarDrag.ts@@ -126,12 +126,11 @@ export const bindTopBarDrag = (const startX = event.clientX;const startY = event.clientY;const sourceRect = sourceElement.getBoundingClientRect();- const offsetX = startX - sourceRect.left;- const offsetY = startY - sourceRect.top;const sourceOpacity = sourceElement.style.opacity;let dragging = false;let ghostElement: HTMLElement | undefined;let placeholderElement: HTMLElement | undefined;+ let selectedElement: HTMLElement | undefined;const preventNativeDrag = (dragEvent: DragEvent) => {dragEvent.preventDefault();@@ -160,17 +159,19 @@ export const bindTopBarDrag = (ghostElement.removeAttribute("aria-label");ghostElement.setAttribute("aria-hidden", "true");ghostElement.setAttribute("data-topbar-drag-ghost", "true");+ ghostElement.style.backgroundColor = "var(--b3-theme-background-light)";ghostElement.style.boxSizing = "border-box";ghostElement.style.height = `${sourceRect.height}px`;ghostElement.style.margin = "0";ghostElement.style.pointerEvents = "none";ghostElement.style.position = "fixed";+ ghostElement.style.transition = "none";ghostElement.style.width = `${sourceRect.width}px`;ghostElement.style.zIndex = "999997";documentSelf.body.appendChild(ghostElement);placeholderElement = documentSelf.createElement("span");- placeholderElement.className = "toolbar__item";+ placeholderElement.className = "toolbar__item fn__none";placeholderElement.setAttribute("aria-hidden", "true");placeholderElement.setAttribute("data-topbar-drag-placeholder", "true");placeholderElement.style.background = "var(--b3-theme-primary-light)";@@ -178,6 +179,7 @@ export const bindTopBarDrag = (placeholderElement.style.height = `${sourceRect.height}px`;placeholderElement.style.pointerEvents = "none";placeholderElement.style.width = `${sourceRect.width}px`;+ placeholderElement.innerHTML = "<svg></svg>";};const onMouseMove = (moveEvent: MouseEvent) => {@@ -192,40 +194,49 @@ export const bindTopBarDrag = (moveEvent.preventDefault();moveEvent.stopPropagation();- ghostElement.style.left = `${moveEvent.clientX - offsetX}px`;- ghostElement.style.top = `${moveEvent.clientY - offsetY}px`;+ ghostElement.style.left = `${moveEvent.clientX - sourceRect.width / 2}px`;+ ghostElement.style.top = `${moveEvent.clientY - sourceRect.height / 2}px`;- placeholderElement.remove();const targetElement = getDirectChild(toolbarElement, moveEvent.target);- if (!isDropTarget(targetElement) || targetElement === sourceElement) {- return;- }- const side = resolveTopBarDropSide(- targetElement.id,- moveEvent.clientX,- targetElement.getBoundingClientRect(),- );- if (!side) {+ if (targetElement && selectedElement && targetElement === selectedElement) {+ const side = resolveTopBarDropSide(+ selectedElement.id,+ moveEvent.clientX,+ selectedElement.getBoundingClientRect(),+ );+ if (!side) {+ return;+ }+ const children = Array.from(toolbarElement.children).filter((item) => item !== placeholderElement);+ if (isTopBarDropNoop(+ children.indexOf(sourceElement),+ children.indexOf(selectedElement),+ side,+ )) {+ placeholderElement.classList.add("fn__none");+ } else {+ placeholderElement.classList.remove("fn__none");+ if (side === "before") {+ selectedElement.before(placeholderElement);+ } else {+ selectedElement.after(placeholderElement);+ }+ }return;}- const children = Array.from(toolbarElement.children);- if (isTopBarDropNoop(- children.indexOf(sourceElement),- children.indexOf(targetElement),- side,- )) {+ if (!isDropTarget(targetElement) || targetElement === sourceElement) {+ if (targetElement === sourceElement) {+ placeholderElement.classList.add("fn__none");+ }return;}- if (side === "before") {- targetElement.before(placeholderElement);- } else {- targetElement.after(placeholderElement);- }+ selectedElement = targetElement;};const onMouseUp = () => {let changedOrder: string[] | undefined;- if (dragging && placeholderElement.parentElement === toolbarElement &&+ if (dragging && !view.siyuan.config.readonly && !placeholderElement.classList.contains("fn__none") &&+ placeholderElement.parentElement === toolbarElement &&sourceElement.parentElement === toolbarElement) {const previousOrder = getTopBarOrder(toolbarElement);placeholderElement.replaceWith(sourceElement);