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: https://github.com/siyuan-note/siyuan/issues/17916
Daniel39c070e5c216
diff --git a/app/src/protyle/render/av/asset.ts b/app/src/protyle/render/av/asset.tsindex a8d4f95e2f..322e6b9198 100644--- a/app/src/protyle/render/av/asset.ts+++ b/app/src/protyle/render/av/asset.ts@@ -184,7 +184,7 @@ export const updateAssetCell = (options: {});const cellRect = (options.cellElements[0].classList.contains("custom-attr__avvalue") ? options.cellElements[0] : options.protyle.wysiwyg.element.querySelector(`.av__cell[data-id="${options.cellElements[0].dataset.id}"]`)).getBoundingClientRect();setTimeout(() => {- setPosition(menuElement, cellRect.left, cellRect.bottom, cellRect.height);+ setPosition(menuElement, cellRect.left, cellRect.bottom, cellRect.height, 0, true);}, Constants.TIMEOUT_LOAD); // 等待图片加载}};diff --git a/app/src/protyle/render/av/col.ts b/app/src/protyle/render/av/col.tsindex 933ba158f6..c55e174d7b 100644--- a/app/src/protyle/render/av/col.ts+++ b/app/src/protyle/render/av/col.ts@@ -668,7 +668,7 @@ const addAttrViewColAnimation = (options: {});const tabRect = options.blockElement.querySelector(".av__views").getBoundingClientRect();if (tabRect) {- setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);+ setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height, 0, true);}return;}@@ -1257,7 +1257,7 @@ export const removeCol = (options: {options.menuElement.innerHTML = getPropertiesHTML(options.fields);setPosition(options.menuElement,options.tabRect.right - options.menuElement.clientWidth, options.tabRect.bottom,- options.tabRect.height);+ options.tabRect.height, 0, true);}};diff --git a/app/src/protyle/render/av/filter.ts b/app/src/protyle/render/av/filter.tsindex 88d75b582d..e50e80eab1 100644--- a/app/src/protyle/render/av/filter.ts+++ b/app/src/protyle/render/av/filter.ts@@ -188,7 +188,7 @@ export const addFilter = (options: {blockID}]);options.menuElement.innerHTML = getFiltersHTML(options.data);- setPosition(options.menuElement, options.tabRect.right - options.menuElement.clientWidth, options.tabRect.bottom, options.tabRect.height);+ setPosition(options.menuElement, options.tabRect.right - options.menuElement.clientWidth, options.tabRect.bottom, options.tabRect.height, 0, true);}});}diff --git a/app/src/protyle/render/av/groups.ts b/app/src/protyle/render/av/groups.tsindex 34c834e96d..718093b70f 100644--- a/app/src/protyle/render/av/groups.ts+++ b/app/src/protyle/render/av/groups.ts@@ -61,7 +61,7 @@ export const setGroupMethod = async (options: {data: options.data});const tabRect = options.blockElement.querySelector(".av__views").getBoundingClientRect();- setPosition(options.menuElement, tabRect.right - options.menuElement.clientWidth, tabRect.bottom, tabRect.height);+ setPosition(options.menuElement, tabRect.right - options.menuElement.clientWidth, tabRect.bottom, tabRect.height, 0, true);};export const getGroupsMethodHTML = (columns: IAVColumn[], group: IAVGroup, viewType: TAVView) => {@@ -294,7 +294,7 @@ export const bindGroupsEvent = (options: {data: options.data});const tabRect = options.blockElement.querySelector(".av__views").getBoundingClientRect();- setPosition(options.menuElement, tabRect.right - options.menuElement.clientWidth, tabRect.bottom, tabRect.height);+ setPosition(options.menuElement, tabRect.right - options.menuElement.clientWidth, tabRect.bottom, tabRect.height, 0, true);});};@@ -333,7 +333,7 @@ export const goGroupsDate = (options: {data: options.data});const tabRect = options.blockElement.querySelector(".av__views").getBoundingClientRect();- setPosition(options.menuElement, tabRect.right - options.menuElement.clientWidth, tabRect.bottom, tabRect.height);+ setPosition(options.menuElement, tabRect.right - options.menuElement.clientWidth, tabRect.bottom, tabRect.height, 0, true);}});});@@ -383,7 +383,7 @@ export const goGroupsSort = (options: {data: options.data});const tabRect = options.blockElement.querySelector(".av__views").getBoundingClientRect();- setPosition(options.menuElement, tabRect.right - options.menuElement.clientWidth, tabRect.bottom, tabRect.height);+ setPosition(options.menuElement, tabRect.right - options.menuElement.clientWidth, tabRect.bottom, tabRect.height, 0, true);}});});diff --git a/app/src/protyle/render/av/openMenuPanel.ts b/app/src/protyle/render/av/openMenuPanel.tsindex 8b5d6ed829..acfa302c18 100644--- a/app/src/protyle/render/av/openMenuPanel.ts+++ b/app/src/protyle/render/av/openMenuPanel.ts@@ -207,7 +207,7 @@ export const openMenuPanel = (options: {blockElement: options.blockElement});setTimeout(() => {- setPosition(menuElement, cellRect.left, cellRect.bottom, cellRect.height);+ setPosition(menuElement, cellRect.left, cellRect.bottom, cellRect.height, 0, true);}, Constants.TIMEOUT_LOAD); // 等待加载} else if (options.type === "relation") {bindRelationEvent({@@ -225,10 +225,10 @@ export const openMenuPanel = (options: {inputElement.select();inputElement.focus();}- setPosition(menuElement, cellRect.left, cellRect.bottom, cellRect.height);+ setPosition(menuElement, cellRect.left, cellRect.bottom, cellRect.height, 0, true);}} else {- setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);+ setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height, 0, true);if (options.type === "sorts") {bindSortsEvent(options.protyle, menuElement, data, blockID);} else if (options.type === "filters") {@@ -272,7 +272,7 @@ export const openMenuPanel = (options: {// 重渲染以同步所有只读且/或标签(index >= 2 的节点显示的是只读 span)menuElement.innerHTML = getFiltersHTML(data);bindInlineFilterEvents(avPanelElement as HTMLElement, data, options.protyle, blockID, avID);- setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);+ setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height, 0, true);event.stopPropagation();});// 多选排序@@ -372,7 +372,7 @@ export const openMenuPanel = (options: {} else if (type === "go-config") {menuElement.classList.remove("av__filter-panel");menuElement.innerHTML = getViewHTML(data);- setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);+ setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height, 0, true);bindViewEvent({protyle: options.protyle, data, menuElement, blockElement: options.blockElement});window.siyuan.menus.menu.remove();event.preventDefault();@@ -383,7 +383,7 @@ export const openMenuPanel = (options: {tabRect = options.blockElement.querySelector(".av__views").getBoundingClientRect();menuElement.classList.remove("av__filter-panel");menuElement.innerHTML = getPropertiesHTML(fields);- setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);+ setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height, 0, true);window.siyuan.menus.menu.remove();event.preventDefault();event.stopPropagation();@@ -391,7 +391,7 @@ export const openMenuPanel = (options: {} else if (type === "go-layout") {menuElement.classList.remove("av__filter-panel");menuElement.innerHTML = getLayoutHTML(data);- setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);+ setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height, 0, true);bindLayoutEvent({protyle: options.protyle, data, menuElement, blockElement: options.blockElement});window.siyuan.menus.menu.remove();event.preventDefault();@@ -401,7 +401,7 @@ export const openMenuPanel = (options: {menuElement.classList.remove("av__filter-panel");menuElement.innerHTML = getSortsHTML(fields, data.view.sorts);bindSortsEvent(options.protyle, menuElement, data, blockID);- setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);+ setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height, 0, true);window.siyuan.menus.menu.remove();event.preventDefault();event.stopPropagation();@@ -421,7 +421,7 @@ export const openMenuPanel = (options: {data.view.sorts = [];menuElement.innerHTML = getSortsHTML(fields, data.view.sorts);bindSortsEvent(options.protyle, menuElement, data, blockID);- setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);+ setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height, 0, true);event.preventDefault();event.stopPropagation();break;@@ -459,7 +459,7 @@ export const openMenuPanel = (options: {}]);menuElement.innerHTML = getSortsHTML(fields, data.view.sorts);bindSortsEvent(options.protyle, menuElement, data, blockID);- setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);+ setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height, 0, true);event.preventDefault();event.stopPropagation();break;@@ -467,7 +467,7 @@ export const openMenuPanel = (options: {menuElement.innerHTML = getFiltersHTML(data);menuElement.classList.add("av__filter-panel");bindInlineFilterEvents(avPanelElement as HTMLElement, data, options.protyle, blockID, avID);- setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);+ setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height, 0, true);window.siyuan.menus.menu.remove();event.preventDefault();event.stopPropagation();@@ -487,7 +487,7 @@ export const openMenuPanel = (options: {// 本地状态保持“顶层单个空根组”不变量(后端会同样归一化),避免后续 addFilterGroup 误把新分组当成根组data.view.filters = [{combination: "and", filters: []}];menuElement.innerHTML = getFiltersHTML(data);- setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);+ setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height, 0, true);window.siyuan.menus.menu.remove();event.preventDefault();event.stopPropagation();@@ -568,7 +568,7 @@ export const openMenuPanel = (options: {blockID}]);menuElement.innerHTML = getFiltersHTML(data);- setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);+ setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height, 0, true);}});}@@ -599,7 +599,7 @@ export const openMenuPanel = (options: {blockID}]);menuElement.innerHTML = getFiltersHTML(data);- setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);+ setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height, 0, true);}});if (!isGroup) {@@ -621,7 +621,7 @@ export const openMenuPanel = (options: {blockID}]);menuElement.innerHTML = getFiltersHTML(data);- setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);+ setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height, 0, true);}});} else if (node && node.filters && 1 === node.filters.length) {@@ -643,7 +643,7 @@ export const openMenuPanel = (options: {blockID}]);menuElement.innerHTML = getFiltersHTML(data);- setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);+ setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height, 0, true);}});}@@ -668,7 +668,7 @@ export const openMenuPanel = (options: {blockID}]);menuElement.innerHTML = getFiltersHTML(data);- setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);+ setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height, 0, true);};if (rmNode && rmNode.filters && rmNode.filters.length > 0) {confirmDialog(window.siyuan.languages.deleteOpConfirm, window.siyuan.languages.confirmDeleteFilterGroupTip, doRemove);@@ -826,7 +826,7 @@ export const openMenuPanel = (options: {if (doOperations.length > 0) {transaction(options.protyle, doOperations, undoOperations);menuElement.innerHTML = getPropertiesHTML(fields);- setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);+ setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height, 0, true);}event.preventDefault();event.stopPropagation();@@ -856,7 +856,7 @@ export const openMenuPanel = (options: {if (doOperations.length > 0) {transaction(options.protyle, doOperations, undoOperations);menuElement.innerHTML = getPropertiesHTML(fields);- setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);+ setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height, 0, true);}event.preventDefault();event.stopPropagation();@@ -869,7 +869,7 @@ export const openMenuPanel = (options: {isCustomAttr});bindEditEvent({protyle: options.protyle, data, menuElement, isCustomAttr, blockID});- setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);+ setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height, 0, true);event.preventDefault();event.stopPropagation();break;@@ -957,7 +957,7 @@ export const openMenuPanel = (options: {isCustomAttr});bindEditEvent({protyle: options.protyle, data, menuElement, isCustomAttr, blockID});- setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);+ setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height, 0, true);event.preventDefault();event.stopPropagation();break;@@ -967,7 +967,7 @@ export const openMenuPanel = (options: {editMenuElement.firstElementChild.classList.add("fn__none");editMenuElement.lastElementChild.classList.remove("fn__none");}- setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);+ setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height, 0, true);event.preventDefault();event.stopPropagation();break;@@ -1024,7 +1024,7 @@ export const openMenuPanel = (options: {editMenuElement.firstElementChild.classList.remove("fn__none");editMenuElement.lastElementChild.classList.add("fn__none");}- setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);+ setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height, 0, true);event.preventDefault();event.stopPropagation();break;@@ -1056,7 +1056,7 @@ export const openMenuPanel = (options: {} else {menuElement.innerHTML = getPropertiesHTML(fields);}- setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);+ setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height, 0, true);event.preventDefault();event.stopPropagation();break;@@ -1088,7 +1088,7 @@ export const openMenuPanel = (options: {} else {menuElement.innerHTML = getPropertiesHTML(fields);}- setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);+ setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height, 0, true);event.preventDefault();event.stopPropagation();break;@@ -1451,21 +1451,21 @@ export const openMenuPanel = (options: {} else {menuElement.innerHTML = getGroupsMethodHTML(fields, data.view.group, data.viewType);}- setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);+ setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height, 0, true);event.preventDefault();event.stopPropagation();break;} else if (type === "goGroupsMethod") {window.siyuan.menus.menu.remove();menuElement.innerHTML = getGroupsMethodHTML(fields, data.view.group, data.viewType);- setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);+ setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height, 0, true);event.preventDefault();event.stopPropagation();break;} else if (type === "getGroupsNumber") {window.siyuan.menus.menu.remove();menuElement.innerHTML = getGroupsNumberHTML(data.view.group);- setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);+ setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height, 0, true);closeCB = bindGroupsNumber({protyle: options.protyle,data,@@ -1552,7 +1552,7 @@ export const openMenuPanel = (options: {data.view.group = null;delete data.view.groups;menuElement.innerHTML = getGroupsHTML(fields, data.view);- setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height);+ setPosition(menuElement, tabRect.right - menuElement.clientWidth, tabRect.bottom, tabRect.height, 0, true);event.preventDefault();event.stopPropagation();break;diff --git a/app/src/protyle/render/av/relation.ts b/app/src/protyle/render/av/relation.tsindex 1ae2f6dd93..6544cb68c5 100644--- a/app/src/protyle/render/av/relation.ts+++ b/app/src/protyle/render/av/relation.ts@@ -2,7 +2,7 @@ import {Menu} from "../../../plugin/Menu";import {hasClosestByClassName, hasTopClosestByClassName} from "../../util/hasClosest";import {UDLRHint, upDownHint} from "../../../util/upDownHint";import {fetchPost} from "../../../util/fetch";-import {escapeLessThans, escapeHtml} from "../../../util/escape";+import {escapeHtml, escapeLessThans} from "../../../util/escape";import {transaction} from "../../wysiwyg/transaction";import {updateCellsValue} from "./cell";import {updateAttrViewCellAnimation} from "./action";@@ -380,7 +380,7 @@ draggable="true">${genSelectItemHTML({<button class="b3-menu__separator"></button>${html || genSelectItemHTML({type: "empty"})}`;const cellRect = options.cellElements[options.cellElements.length - 1].getBoundingClientRect();- setPosition(options.menuElement, cellRect.left, cellRect.bottom, cellRect.height);+ setPosition(options.menuElement, cellRect.left, cellRect.bottom, cellRect.height, 0, true);options.menuElement.querySelector(".b3-menu__items .b3-menu__item:not(.fn__none)").classList.add("b3-menu__item--current");const inputElement = options.menuElement.querySelector("input");inputElement.focus();diff --git a/app/src/protyle/render/av/sort.ts b/app/src/protyle/render/av/sort.tsindex d1484765df..6f20680328 100644--- a/app/src/protyle/render/av/sort.ts+++ b/app/src/protyle/render/av/sort.ts@@ -55,7 +55,7 @@ export const addSort = (options: {}]);options.menuElement.innerHTML = getSortsHTML(fields, options.data.view.sorts);bindSortsEvent(options.protyle, options.menuElement, options.data, options.blockID);- setPosition(options.menuElement, options.tabRect.right - options.menuElement.clientWidth, options.tabRect.bottom, options.tabRect.height);+ setPosition(options.menuElement, options.tabRect.right - options.menuElement.clientWidth, options.tabRect.bottom, options.tabRect.height, 0, true);}});}diff --git a/app/src/util/setPosition.ts b/app/src/util/setPosition.tsindex dd11d8b476..10c8f8f2f1 100644--- a/app/src/util/setPosition.ts+++ b/app/src/util/setPosition.ts@@ -1,6 +1,6 @@import {getTopBarHeight} from "../layout/getTopBarHeight";-export const setPosition = (element: HTMLElement, left: number, top: number, targetHeight = 0, targetLeft = 0) => {+export const setPosition = (element: HTMLElement, left: number, top: number, targetHeight = 0, targetLeft = 0, sticky = false) => {element.style.top = top + "px";element.style.left = left + "px";const rect = element.getBoundingClientRect();@@ -18,11 +18,47 @@ export const setPosition = (element: HTMLElement, left: number, top: number, tarelement.style.top = Math.max(topBarHeight, window.innerHeight - rect.height) + "px";}}- if (rect.right > window.innerWidth) {- // 展现在左侧- element.style.left = window.innerWidth - rect.width - targetLeft + "px";- } else if (rect.left < 0) {- // 依旧展现在左侧,只是位置右移- element.style.left = "0";++ if (sticky) {+ // 粘滞定位:同一锚点(top 不变)下,锁定底部边缘+ // 菜单内容变化导致高度增减时,底部不动、顶部上下移动(向上撑开/向下收缩),避免位置跳动和底部溢出+ const lockedBottom = element.dataset.positionBottom;+ const lockedX = element.dataset.positionX;+ const sameAnchor = element.dataset.positionTop === String(top);+ if (sameAnchor && lockedBottom !== undefined) {+ const newTop = parseFloat(lockedBottom) - rect.height;+ element.style.top = (newTop >= topBarHeight ? newTop : topBarHeight) + "px";+ }+ if (sameAnchor && lockedX !== undefined) {+ element.style.left = lockedX + "px";+ }++ // 水平溢出修正(仅在未锁定时做)+ if (!(sameAnchor && lockedX !== undefined)) {+ if (rect.right > window.innerWidth) {+ element.style.left = window.innerWidth - rect.width - targetLeft + "px";+ } else if (rect.left < 0) {+ element.style.left = "0";+ }+ }++ element.dataset.positionTop = String(top);+ const actualRect = element.getBoundingClientRect();+ element.dataset.positionBottom = String(actualRect.bottom);+ element.dataset.positionX = String(parseFloat(element.style.left));+ } else {+ if (rect.right > window.innerWidth) {+ // 展现在左侧+ element.style.left = window.innerWidth - rect.width - targetLeft + "px";+ } else if (rect.left < 0) {+ // 依旧展现在左侧,只是位置右移+ element.style.left = "0";+ }}};++export const clearPositionState = (element: HTMLElement) => {+ delete element.dataset.positionTop;+ delete element.dataset.positionBottom;+ delete element.dataset.positionX;+};