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/18145
Vanessad55d863238d1
diff --git a/app/src/boot/globalEvent/event.ts b/app/src/boot/globalEvent/event.tsindex ebb3473036..e97c21a5d0 100644--- a/app/src/boot/globalEvent/event.ts+++ b/app/src/boot/globalEvent/event.ts@@ -10,7 +10,7 @@ import {hideTooltip} from "../../dialog/tooltip";import {hideAllElements} from "../../protyle/ui/hideElements";import {dragOverScroll, stopScrollAnimation} from "./dragover";import {setWebViewFocusable} from "../../mobile/util/mobileAppUtil";-import {initTouchDragBridge} from "../../util/touchDragBridge";+import {cancelManualTouch, initTouchDragBridge} from "../../util/touchDragBridge";import {isWindow} from "../../util/functions";import {getDockByType} from "../../layout/tabUtil";@@ -218,6 +218,8 @@ export const initWindowEvent = (app: App) => {}, false);document.addEventListener("touchend", (event) => {+ // 无条件前置取消手动桥接:触发各组件(如 Outline.bindSort)注册的 mouseup 清理回调,复位 document.onmousemove 等状态+ cancelManualTouch();if (window.siyuan.touchDragActive) {return;}diff --git a/app/src/mobile/dock/MobileOutline.ts b/app/src/mobile/dock/MobileOutline.tsindex b183bd9dce..03cfc9e500 100644--- a/app/src/mobile/dock/MobileOutline.ts+++ b/app/src/mobile/dock/MobileOutline.ts@@ -15,6 +15,7 @@ import {openMobileFileById} from "../editor";import {Model} from "../../layout/Model";import {genUUID} from "../../util/genID";import {isEncryptedBox} from "../../util/pathName";+import {dragOverScroll, stopScrollAnimation} from "../../boot/globalEvent/dragover";export class MobileOutline extends Model {public tree: Tree;@@ -22,6 +23,15 @@ export class MobileOutline extends Model {public blockId: string;public isPreview: boolean;private preFilterExpandIds: string[] | null = null;+ private touchDragState: {+ selectedElement: HTMLElement;+ startX: number;+ startY: number;+ isDragging: boolean;+ ghostElement: HTMLElement;+ startTime: number;+ selectItem: HTMLElement;+ };constructor(options: {app: App,@@ -184,6 +194,8 @@ export class MobileOutline extends Model {}});+ this.bindSort();+const outlineParam: IObject = {id: this.blockId,preview: this.isPreview@@ -197,6 +209,183 @@ export class MobileOutline extends Model {});}+ // 大纲拖拽排序:原生触摸事件实现,长按门槛避免与列表滚动冲突,排序逻辑对齐桌面端 Outline.bindSort+ private bindSort() {+ const contentRect = () => this.element.getBoundingClientRect();+ this.element.addEventListener("touchstart", (event: TouchEvent) => {+ if (window.siyuan.config.readonly) return;+ if (this.element.getAttribute("data-loading") === "true") return;+ if (event.touches.length !== 1) return;+ // 仅当触摸到当前文档对应的编辑器时才允许拖拽排序+ const editor = window.siyuan.mobile.editor?.protyle;+ if (!editor || editor.disabled || editor.block.rootID !== this.blockId) return;++ const touch = event.touches[0];+ const liElement = hasClosestByClassName(touch.target as HTMLElement, "b3-list-item") as HTMLElement;+ if (!liElement || liElement.tagName !== "LI") return;++ this.touchDragState = {+ selectedElement: liElement,+ startX: touch.clientX,+ startY: touch.clientY,+ isDragging: false,+ ghostElement: null,+ startTime: Date.now(),+ selectItem: null,+ };+ }, {passive: false});++ this.element.addEventListener("touchmove", (event: TouchEvent) => {+ const state = this.touchDragState;+ if (!state) return;+ const touch = event.touches[0];++ // 长按门槛:未达到长按时间就移动则视为滚动,放弃拖拽+ if (!state.isDragging) {+ if (Date.now() - state.startTime < Constants.TIMEOUT_LONGPRESS &&+ (Math.abs(touch.clientX - state.startX) > Constants.SIZE_DRAG_THRESHOLD ||+ Math.abs(touch.clientY - state.startY) > Constants.SIZE_DRAG_THRESHOLD)) {+ this.touchDragState = null;+ return;+ }+ if (Math.abs(touch.clientX - state.startX) < Constants.SIZE_DRAG_THRESHOLD &&+ Math.abs(touch.clientY - state.startY) < Constants.SIZE_DRAG_THRESHOLD) return;+ state.isDragging = true;++ // 创建 ghost 元素,跟随手指移动+ state.selectedElement.style.opacity = "0.38";+ const ghostElement = state.selectedElement.cloneNode(true) as HTMLElement;+ ghostElement.setAttribute("id", "dragGhost");+ ghostElement.firstElementChild.setAttribute("style", "padding-left:4px");+ ghostElement.setAttribute("style", `border-radius: var(--b3-border-radius);background-color: var(--b3-list-hover);position: fixed; top: ${touch.clientY}px; left: ${touch.clientX}px; z-index:999997;`);+ document.body.append(ghostElement);+ state.ghostElement = ghostElement;+ }++ // 进入拖拽后阻止原生滚动,避免列表伴随手指滚动+ event.preventDefault();+ event.stopPropagation();+ state.ghostElement.style.top = touch.clientY + "px";+ state.ghostElement.style.left = touch.clientX + "px";+ dragOverScroll({clientY: touch.clientY} as MouseEvent, contentRect(), this.element);++ // 通过 elementFromPoint 定位手指下的目标项+ const target = document.elementFromPoint(touch.clientX, touch.clientY);+ const selectItem = target?.closest(".b3-list-item") as HTMLElement;+ if (!selectItem || selectItem.tagName !== "LI") return;++ this.clearDragIndicators();+ if (selectItem === state.selectedElement) {+ selectItem.classList.add("dragover__current");+ return;+ }+ const selectRect = selectItem.getBoundingClientRect();+ const dragHeight = selectRect.height * .2;+ if (touch.clientY > selectRect.bottom - dragHeight) {+ selectItem.classList.add("dragover__bottom");+ } else if (touch.clientY < selectRect.top + dragHeight) {+ selectItem.classList.add("dragover__top");+ } else {+ selectItem.classList.add("dragover");+ }+ state.selectItem = selectItem;+ }, {passive: false});++ this.element.addEventListener("touchend", () => {+ const state = this.touchDragState;+ if (!state) return;+ stopScrollAnimation();+ state.selectedElement.style.opacity = "";+ const item = state.selectedElement;++ if (state.isDragging) {+ state.ghostElement?.remove();+ let selectItem = state.selectItem;+ if (!selectItem) {+ selectItem = this.element.querySelector(".dragover__top, .dragover__bottom, .dragover") as HTMLElement;+ }+ const editor = window.siyuan.mobile.editor?.protyle;+ let hasChange = true;+ if (selectItem && editor &&+ (selectItem.classList.contains("dragover__top") || selectItem.classList.contains("dragover__bottom") || selectItem.classList.contains("dragover"))) {+ let previousID;+ let parentID;+ const undoPreviousID = (item.previousElementSibling && item.previousElementSibling.tagName === "UL") ? item.previousElementSibling.previousElementSibling.getAttribute("data-node-id") : item.previousElementSibling?.getAttribute("data-node-id");+ const undoParentID = item.parentElement.previousElementSibling?.getAttribute("data-node-id");+ if (selectItem.classList.contains("dragover")) {+ parentID = selectItem.getAttribute("data-node-id");+ if (selectItem.nextElementSibling && selectItem.nextElementSibling.tagName === "UL") {+ selectItem.nextElementSibling.insertAdjacentElement("afterbegin", item);+ } else {+ selectItem.insertAdjacentHTML("afterend", `<ul>${item.outerHTML}</ul>`);+ item.remove();+ }+ } else if (selectItem.classList.contains("dragover__top")) {+ parentID = selectItem.parentElement.previousElementSibling?.getAttribute("data-node-id");+ if (selectItem.previousElementSibling && selectItem.previousElementSibling.tagName === "UL") {+ previousID = selectItem.previousElementSibling.previousElementSibling.getAttribute("data-node-id");+ } else {+ previousID = selectItem.previousElementSibling?.getAttribute("data-node-id");+ }+ if (previousID === item.dataset.nodeId || parentID === item.dataset.nodeId) {+ hasChange = false;+ } else {+ selectItem.before(item);+ }+ } else if (selectItem.classList.contains("dragover__bottom")) {+ previousID = selectItem.getAttribute("data-node-id");+ if (previousID === item.previousElementSibling?.getAttribute("data-node-id")) {+ hasChange = false;+ } else {+ selectItem.after(item);+ }+ }+ if (hasChange) {+ this.element.setAttribute("data-loading", "true");++ transaction(editor, [{+ action: "moveOutlineHeading",+ id: item.dataset.nodeId,+ previousID,+ parentID,+ }], [{+ action: "moveOutlineHeading",+ id: item.dataset.nodeId,+ previousID: undoPreviousID,+ parentID: undoParentID,+ }]);++ // https://github.com/siyuan-note/siyuan/issues/10828#issuecomment-2044099675+ editor.wysiwyg.element.querySelectorAll('[data-type="NodeHeading"] [contenteditable="true"][spellcheck]').forEach(headingItem => {+ headingItem.setAttribute("contenteditable", "false");+ });+ }+ }+ this.clearDragIndicators();+ }+ this.touchDragState = null;+ });++ this.element.addEventListener("touchcancel", () => {+ stopScrollAnimation();+ if (this.touchDragState?.ghostElement) {+ this.touchDragState.ghostElement.remove();+ }+ if (this.touchDragState?.selectedElement) {+ this.touchDragState.selectedElement.style.opacity = "";+ }+ this.clearDragIndicators();+ this.touchDragState = null;+ });+ }++ // 清理拖拽指示线+ private clearDragIndicators = () => {+ this.element.querySelectorAll(".dragover__top, .dragover__bottom, .dragover, .dragover__current").forEach(item => {+ item.classList.remove("dragover__top", "dragover__bottom", "dragover", "dragover__current");+ });+ };+private handleMsgCallback(data: IWebSocketData) {if (data) {switch (data.cmd) {diff --git a/app/src/mobile/util/touch.ts b/app/src/mobile/util/touch.tsindex fe049002ea..804990ebdb 100644--- a/app/src/mobile/util/touch.ts+++ b/app/src/mobile/util/touch.ts@@ -100,7 +100,7 @@ export const handleTouchEnd = (event: TouchEvent) => {}if (typeof yDiff === "undefined" && editor?.protyle.options.render.gutter) {const nodeElement = hasClosestBlock(target);- if (nodeElement) {+ if (nodeElement && nodeElement.closest(".protyle-wysiwyg")) {if (nodeElement.classList.contains("list") || nodeElement.classList.contains("li")) {// 光标在列表下部应显示右侧的元素,而不是列表本身。放在 windowEvent 中的 mousemove 下处理return;diff --git a/app/src/util/reloadSync.ts b/app/src/util/reloadSync.tsindex cf2a3ad32e..e00da2114a 100644--- a/app/src/util/reloadSync.ts+++ b/app/src/util/reloadSync.ts@@ -46,6 +46,20 @@ export const reloadSync = (setTitle(response.data.name);window.siyuan.mobile.editor.protyle.title.setTitle(response.data.name, response.data.ial[Constants.CUSTOM_SY_TITLE_EMPTY] === "true");});+ // 同步刷新移动端大纲,避免大纲与重载后的编辑器数据不一致+ const outline = window.siyuan.mobile.docks.outline;+ if (outline) {+ const outlineParam: IObject = {+ id: window.siyuan.mobile.editor.protyle.block.rootID,+ preview: window.siyuan.mobile.editor.protyle.preview.element.classList.contains("fn__none")+ };+ if (isEncryptedBox(window.siyuan.mobile.editor.protyle.notebookId)) {+ outlineParam.notebook = window.siyuan.mobile.editor.protyle.notebookId;+ }+ fetchPost("/api/outline/getDocOutline", outlineParam, response => {+ outline.update(response);+ });+ }}}setNoteBook(() => {