Skip to content

An open-source, privacy-first, self-hosted knowledge workspace where humans and AI agents work together 开源、隐私优先、自托管的知识工作空间,让人与智能体在此协作

:art: https://github.com/siyuan-note/siyuan/issues/18347

Vanessac7b3cb162235
diff --git a/app/src/constants.ts b/app/src/constants.ts
index cb7ee70b7b..2c7c2a770e 100644
--- a/app/src/constants.ts
+++ b/app/src/constants.ts
@@ -312,7 +312,8 @@ export abstract class Constants {
public static readonly TIMEOUT_RESIZE = 200;
public static readonly TIMEOUT_INPUT = 256;
public static readonly TIMEOUT_LOAD = 300;
- public static readonly TIMEOUT_LONGPRESS = 400;
+ public static readonly TIMEOUT_LONGPRESS = 460;
+ public static readonly TIMEOUT_VIBRATION_DURATION = 20;
// 鼠标拖拽启动的短暂时间下限:平板鼠标合成 touch 拖拽文件树/画廊/列表操作等元素时,按下后需经过该时间才进拖拽,避免点击 + 号/箭头时抖动误触发 dragstart
public static readonly TIMEOUT_MOUSE_DRAG_DELAY = 150;
public static readonly TIMEOUT_MULTIPLE_SELECT = 1500;
diff --git a/app/src/mobile/dock/MobileFiles.ts b/app/src/mobile/dock/MobileFiles.ts
index 6f7aee8517..69fe5ad41c 100644
--- a/app/src/mobile/dock/MobileFiles.ts
+++ b/app/src/mobile/dock/MobileFiles.ts
@@ -266,7 +266,21 @@ export class MobileFiles extends Model {
ghostElement: null,
startTime: Date.now() - (isMousePointerTouchEvent(event) ? Constants.TIMEOUT_LONGPRESS : 0),
};
+ if (!isMousePointerTouchEvent(event)) {
+ const state = this.touchDragState;
+ window.setTimeout(() => {
+ if (this.touchDragState !== state) {
+ return;
+ }
+ this.startTouchDrag(state, state.startX, state.startY, true);
+ }, Constants.TIMEOUT_LONGPRESS);
+ }
}, {passive: false});
+ this.element.addEventListener("scroll", () => {
+ if (this.touchDragState && !this.touchDragState.isDragging) {
+ this.touchDragState = null;
+ }
+ }, {passive: true});
filesElement.addEventListener("touchmove", (event: TouchEvent) => {
const state = this.touchDragState;
@@ -280,17 +294,7 @@ export class MobileFiles extends Model {
}
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;
-
- const ghostElement = document.createElement("ul");
- ghostElement.id = "dragGhost";
- ghostElement.append(state.selectedElement.cloneNode(true));
- ghostElement.setAttribute("style", `background-color: var(--b3-theme-surface);width: 100%;touch-action: none;margin-left: -50%;margin-top:20px;z-index:${window.siyuan.zIndex};position: fixed;top:${touch.clientX}px;left:${touch.clientY}px`);
- ghostElement.setAttribute("class", "b3-list b3-list--background");
- document.body.append(ghostElement);
-
- state.ghostElement = ghostElement;
- state.selectedElement.style.opacity = "0.38";
+ this.startTouchDrag(state, touch.clientX, touch.clientY, !isMousePointerTouchEvent(event));
event.preventDefault();
event.stopPropagation();
}
@@ -348,15 +352,16 @@ export class MobileFiles extends Model {
stopScrollAnimation();
state.selectedElement.style.opacity = "";
if (state.isDragging) {
- if (state.ghostElement) {
- state.ghostElement.remove();
- }
+ state.ghostElement?.remove();
const newElement = this.element.querySelector(".dragover, .dragover__bottom, .dragover__top");
if (!newElement) {
+ this.touchDragState = null;
return;
}
const newUlElement = hasTopClosestByTag(newElement, "UL");
if (!newUlElement) {
+ this.clearDragIndicators();
+ this.touchDragState = null;
return;
}
const oldScrollTop = this.element.scrollTop;
@@ -483,17 +488,18 @@ export class MobileFiles extends Model {
this.touchDragState = null;
});
- filesElement.addEventListener("touchcancel", () => {
+ const cancelTouchDrag = () => {
stopScrollAnimation();
- if (this.touchDragState?.ghostElement) {
- this.touchDragState.ghostElement.remove();
- }
+ this.touchDragState?.ghostElement?.remove();
if (this.touchDragState?.selectedElement) {
this.touchDragState.selectedElement.style.opacity = "";
}
this.clearDragIndicators();
this.touchDragState = null;
- });
+ };
+ filesElement.addEventListener("touchcancel", cancelTouchDrag);
+ filesElement.addEventListener("pointercancel", cancelTouchDrag);
+ window.addEventListener("blur", cancelTouchDrag);
bindMousePointerTouchBridge(filesElement);
this.init();
}
@@ -588,6 +594,28 @@ export class MobileFiles extends Model {
}
}
+ private startTouchDrag(state: MobileFiles["touchDragState"], clientX: number, clientY: number, vibrate = false) {
+ if (state.isDragging) {
+ return;
+ }
+ state.isDragging = true;
+ const ghostElement = document.createElement("ul");
+ ghostElement.id = "dragGhost";
+ ghostElement.append(state.selectedElement.cloneNode(true));
+ ghostElement.setAttribute("style", `background-color: var(--b3-theme-surface);width: 100%;touch-action: none;margin-left: -50%;margin-top:20px;z-index:${window.siyuan.zIndex};position: fixed;top:${clientX}px;left:${clientY}px`);
+ ghostElement.setAttribute("class", "b3-list b3-list--background");
+ document.body.append(ghostElement);
+ state.ghostElement = ghostElement;
+ state.selectedElement.style.opacity = "0.38";
+ if (vibrate) {
+ if (window.webkit?.messageHandlers.vibrate) {
+ window.webkit.messageHandlers.vibrate.postMessage("");
+ } else if (navigator.vibrate) {
+ navigator.vibrate(Constants.TIMEOUT_VIBRATION_DURATION);
+ }
+ }
+ }
+
private clearDragIndicators = () => {
if (!this.touchDragState) return;
this.element.querySelectorAll(".dragover__top, .dragover__bottom, .dragover").forEach(el => {
diff --git a/app/src/mobile/dock/MobileOutline.ts b/app/src/mobile/dock/MobileOutline.ts
index fc0ac0b79e..17a3b2d7fb 100644
--- a/app/src/mobile/dock/MobileOutline.ts
+++ b/app/src/mobile/dock/MobileOutline.ts
@@ -231,6 +231,15 @@ export class MobileOutline extends Model {
startTime: Date.now() - (isMousePointerTouchEvent(event) ? Constants.TIMEOUT_LONGPRESS : 0),
selectItem: null,
};
+ if (!isMousePointerTouchEvent(event)) {
+ const state = this.touchDragState;
+ window.setTimeout(() => {
+ if (this.touchDragState !== state) {
+ return;
+ }
+ this.startTouchDrag(state, state.startX, state.startY, true);
+ }, Constants.TIMEOUT_LONGPRESS);
+ }
}, {passive: false});
this.element.addEventListener("touchmove", (event: TouchEvent) => {
@@ -248,16 +257,7 @@ export class MobileOutline extends Model {
}
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);pointer-events:none;position: fixed; top: ${touch.clientY}px; left: ${touch.clientX}px; z-index:999997;`);
- document.body.append(ghostElement);
- state.ghostElement = ghostElement;
+ this.startTouchDrag(state, touch.clientX, touch.clientY, !isMousePointerTouchEvent(event));
}
// 进入拖拽后阻止原生滚动,避免列表伴随手指滚动
@@ -382,6 +382,27 @@ export class MobileOutline extends Model {
bindMousePointerTouchBridge(this.element);
}
+ private startTouchDrag(state: MobileOutline["touchDragState"], clientX: number, clientY: number, vibrate = false) {
+ if (state.isDragging) {
+ return;
+ }
+ state.isDragging = true;
+ 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);pointer-events:none;position: fixed; top: ${clientY}px; left: ${clientX}px; z-index:999997;`);
+ document.body.append(ghostElement);
+ state.ghostElement = ghostElement;
+ if (vibrate) {
+ if (window.webkit?.messageHandlers.vibrate) {
+ window.webkit.messageHandlers.vibrate.postMessage("");
+ } else if (navigator.vibrate) {
+ navigator.vibrate(Constants.TIMEOUT_VIBRATION_DURATION);
+ }
+ }
+ }
+
// 清理拖拽指示线
private clearDragIndicators = () => {
this.element.querySelectorAll(".dragover__top, .dragover__bottom, .dragover, .dragover__current").forEach(item => {
diff --git a/app/src/types/index.d.ts b/app/src/types/index.d.ts
index 8d2cb25da9..2d443596d0 100644
--- a/app/src/types/index.d.ts
+++ b/app/src/types/index.d.ts
@@ -271,6 +271,7 @@ interface Window {
}) => number
}
cancelNotification: { postMessage: (id: number) => void }
+ vibrate?: { postMessage: (text: string) => void }
}
};
htmlToImage: {