2024-04-03 16:04:13 +08:00
|
|
|
|
import {hasClosestByAttribute, hasClosestByClassName, hasTopClosestByClassName,} from "../../protyle/util/hasClosest";
|
2023-12-19 23:18:45 +08:00
|
|
|
|
import {closeModel, closePanel} from "./closePanel";
|
2023-03-30 18:12:09 +08:00
|
|
|
|
import {popMenu} from "../menu";
|
2025-04-18 16:58:56 +08:00
|
|
|
|
import {activeBlur} from "./keyboardToolbar";
|
2025-06-03 16:08:12 +08:00
|
|
|
|
import {isIPhone} from "../../protyle/util/compatibility";
|
2023-09-06 17:19:11 +08:00
|
|
|
|
import {App} from "../../index";
|
2023-11-17 22:35:16 +08:00
|
|
|
|
import {globalTouchEnd, globalTouchStart} from "../../boot/globalEvent/touch";
|
2022-05-26 15:18:53 +08:00
|
|
|
|
|
|
|
|
|
|
let clientX: number;
|
|
|
|
|
|
let clientY: number;
|
|
|
|
|
|
let xDiff: number;
|
|
|
|
|
|
let yDiff: number;
|
2023-03-30 18:12:09 +08:00
|
|
|
|
let time: number;
|
2023-03-31 10:46:40 +08:00
|
|
|
|
let firstDirection: "toLeft" | "toRight";
|
2024-04-02 15:10:40 +08:00
|
|
|
|
let firstXY: "x" | "y";
|
2023-03-31 10:46:40 +08:00
|
|
|
|
let lastClientX: number; // 和起始方向不一致时,记录最后一次的 clientX
|
2024-02-04 12:00:41 +08:00
|
|
|
|
let scrollBlock: boolean;
|
2024-04-18 10:44:46 +08:00
|
|
|
|
let isFirstMove = true;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
|
2023-03-31 16:41:09 +08:00
|
|
|
|
const popSide = (render = true) => {
|
|
|
|
|
|
if (render) {
|
|
|
|
|
|
document.getElementById("toolbarFile").dispatchEvent(new CustomEvent("click"));
|
|
|
|
|
|
} else {
|
|
|
|
|
|
activeBlur();
|
2023-04-07 09:06:30 +08:00
|
|
|
|
document.getElementById("sidebar").style.transform = "translateX(0px)";
|
2023-03-31 16:41:09 +08:00
|
|
|
|
}
|
2023-04-02 10:42:42 +08:00
|
|
|
|
};
|
2023-03-31 16:41:09 +08:00
|
|
|
|
|
2023-09-06 17:19:11 +08:00
|
|
|
|
export const handleTouchEnd = (event: TouchEvent, app: App) => {
|
2026-02-03 11:42:35 +08:00
|
|
|
|
const target = event.target as HTMLElement;
|
|
|
|
|
|
const wysisygElement = hasClosestByClassName(target, "protyle-wysiwyg", true);
|
2026-02-03 20:32:03 +08:00
|
|
|
|
if (!yDiff || Math.abs(yDiff) < 10) {
|
2026-02-03 21:25:34 +08:00
|
|
|
|
let editElement: HTMLElement;
|
2026-02-03 21:06:46 +08:00
|
|
|
|
if (["INPUT", "TEXTAREA"].includes(target.tagName) && target.getAttribute("readonly") !== "true") {
|
|
|
|
|
|
editElement = target;
|
|
|
|
|
|
} else if (wysisygElement && wysisygElement.getAttribute("data-readonly") === "false") {
|
|
|
|
|
|
editElement = hasClosestByAttribute(target, "contenteditable", "true") as HTMLElement;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (editElement) {
|
|
|
|
|
|
if (editElement.getAttribute("virtualkeyboardpolicy") !== "manual") {
|
|
|
|
|
|
editElement.setAttribute("virtualkeyboardpolicy", "manual");
|
|
|
|
|
|
setTimeout(() => {
|
2026-02-03 21:25:34 +08:00
|
|
|
|
editElement.focus();
|
2026-02-03 21:06:46 +08:00
|
|
|
|
window.JSAndroid?.showKeyboard();
|
|
|
|
|
|
}, 100);
|
2026-02-03 20:32:03 +08:00
|
|
|
|
} else {
|
2026-02-03 21:25:34 +08:00
|
|
|
|
editElement.focus();
|
2026-02-03 21:06:46 +08:00
|
|
|
|
window.JSAndroid?.showKeyboard();
|
2026-02-03 20:32:03 +08:00
|
|
|
|
}
|
2026-02-03 11:49:57 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
window.JSAndroid?.hideKeyboard();
|
|
|
|
|
|
}
|
2026-02-03 11:42:35 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-09-07 09:58:07 +08:00
|
|
|
|
if (isIPhone() && globalTouchEnd(event, yDiff, time, app)) {
|
|
|
|
|
|
event.stopImmediatePropagation();
|
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
|
return;
|
2023-04-21 17:07:00 +08:00
|
|
|
|
}
|
2024-04-18 10:44:46 +08:00
|
|
|
|
isFirstMove = true;
|
2024-03-29 23:53:00 +08:00
|
|
|
|
if (!clientY || typeof yDiff === "undefined" ||
|
2023-04-06 16:02:06 +08:00
|
|
|
|
target.tagName === "AUDIO" ||
|
2023-04-12 10:56:46 +08:00
|
|
|
|
hasClosestByClassName(target, "b3-dialog", true) ||
|
2023-04-10 11:25:25 +08:00
|
|
|
|
(window.siyuan.mobile.editor && !window.siyuan.mobile.editor.protyle.toolbar.subElement.classList.contains("fn__none")) ||
|
2023-04-09 23:04:30 +08:00
|
|
|
|
hasClosestByClassName(target, "viewer-container") ||
|
2023-03-31 16:41:09 +08:00
|
|
|
|
hasClosestByClassName(target, "keyboard") ||
|
2023-12-19 23:18:45 +08:00
|
|
|
|
hasClosestByAttribute(target, "id", "commonMenu")
|
2023-03-31 10:46:40 +08:00
|
|
|
|
) {
|
2022-08-01 10:20:35 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-04-12 18:22:54 +08:00
|
|
|
|
if (window.siyuan.mobile.editor) {
|
|
|
|
|
|
window.siyuan.mobile.editor.protyle.contentElement.style.overflow = "";
|
|
|
|
|
|
}
|
2023-04-06 19:14:23 +08:00
|
|
|
|
|
2023-03-31 10:46:40 +08:00
|
|
|
|
// 有些事件不经过 touchstart 和 touchmove,因此需设置为 null 不再继续执行
|
|
|
|
|
|
clientX = null;
|
|
|
|
|
|
// 有些事件不经过 touchmove
|
|
|
|
|
|
|
2024-02-04 12:00:41 +08:00
|
|
|
|
if (scrollBlock) {
|
2024-04-11 18:10:05 +08:00
|
|
|
|
closePanel();
|
2024-02-04 12:00:41 +08:00
|
|
|
|
return;
|
2023-03-30 18:12:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2023-03-31 10:46:40 +08:00
|
|
|
|
let scrollEnable = false;
|
2023-03-30 18:12:09 +08:00
|
|
|
|
if (new Date().getTime() - time < 1000) {
|
2023-03-31 10:46:40 +08:00
|
|
|
|
scrollEnable = true;
|
2023-03-30 18:12:09 +08:00
|
|
|
|
} else if (Math.abs(xDiff) > window.innerWidth / 3) {
|
2023-03-31 10:46:40 +08:00
|
|
|
|
scrollEnable = true;
|
2023-03-30 18:12:09 +08:00
|
|
|
|
}
|
2023-03-31 10:46:40 +08:00
|
|
|
|
|
2023-03-31 10:48:16 +08:00
|
|
|
|
const isXScroll = Math.abs(xDiff) > Math.abs(yDiff);
|
2024-12-05 09:56:49 +08:00
|
|
|
|
const modelElement = hasClosestByAttribute(target, "id", "model", true);
|
2023-12-19 23:18:45 +08:00
|
|
|
|
if (modelElement) {
|
2026-02-03 11:42:35 +08:00
|
|
|
|
if (isXScroll && firstDirection === "toRight" && !lastClientX && !wysisygElement) {
|
2023-12-19 23:18:45 +08:00
|
|
|
|
closeModel();
|
|
|
|
|
|
}
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-03-30 18:15:20 +08:00
|
|
|
|
const menuElement = hasClosestByAttribute(target, "id", "menu");
|
2023-03-31 10:46:40 +08:00
|
|
|
|
if (menuElement) {
|
|
|
|
|
|
if (isXScroll) {
|
2023-03-31 16:41:09 +08:00
|
|
|
|
if (firstDirection === "toRight") {
|
|
|
|
|
|
if (lastClientX) {
|
|
|
|
|
|
popMenu();
|
|
|
|
|
|
} else {
|
2023-03-31 10:46:40 +08:00
|
|
|
|
closePanel();
|
|
|
|
|
|
}
|
2023-03-31 16:41:09 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
if (lastClientX) {
|
|
|
|
|
|
closePanel();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
popMenu();
|
|
|
|
|
|
}
|
2023-03-31 10:46:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2023-03-31 16:41:09 +08:00
|
|
|
|
popMenu();
|
2023-03-31 10:46:40 +08:00
|
|
|
|
}
|
2023-03-30 18:12:09 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-03-30 18:15:20 +08:00
|
|
|
|
const sideElement = hasClosestByAttribute(target, "id", "sidebar");
|
2023-03-31 10:46:40 +08:00
|
|
|
|
if (sideElement) {
|
|
|
|
|
|
if (isXScroll) {
|
2023-03-31 16:41:09 +08:00
|
|
|
|
if (firstDirection === "toLeft") {
|
|
|
|
|
|
if (lastClientX) {
|
|
|
|
|
|
popSide(false);
|
|
|
|
|
|
} else {
|
2023-03-31 10:46:40 +08:00
|
|
|
|
closePanel();
|
|
|
|
|
|
}
|
2023-03-31 16:41:09 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
if (lastClientX) {
|
|
|
|
|
|
closePanel();
|
|
|
|
|
|
} else {
|
|
|
|
|
|
popSide(false);
|
|
|
|
|
|
}
|
2023-03-31 10:46:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
2023-03-31 16:41:09 +08:00
|
|
|
|
popSide(false);
|
2023-03-31 10:46:40 +08:00
|
|
|
|
}
|
2023-03-30 18:12:09 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-03-31 10:46:40 +08:00
|
|
|
|
if (!scrollEnable || !isXScroll) {
|
2023-03-30 18:12:09 +08:00
|
|
|
|
closePanel();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-03-31 10:46:40 +08:00
|
|
|
|
|
|
|
|
|
|
if (xDiff > 0) {
|
|
|
|
|
|
if (lastClientX) {
|
|
|
|
|
|
closePanel();
|
|
|
|
|
|
} else {
|
2023-03-30 18:12:09 +08:00
|
|
|
|
popMenu();
|
2023-03-31 10:46:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
} else {
|
|
|
|
|
|
if (lastClientX) {
|
|
|
|
|
|
closePanel();
|
2022-05-26 15:18:53 +08:00
|
|
|
|
} else {
|
2023-03-31 16:41:09 +08:00
|
|
|
|
popSide();
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
export const handleTouchStart = (event: TouchEvent) => {
|
2025-04-19 20:23:31 +08:00
|
|
|
|
if (0 < event.touches.length && ((event.touches[0].target as HTMLElement).tagName === "VIDEO" || (event.touches[0].target as HTMLElement).tagName === "AUDIO")) {
|
|
|
|
|
|
// https://github.com/siyuan-note/siyuan/issues/14569
|
|
|
|
|
|
activeBlur();
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-11-17 22:35:16 +08:00
|
|
|
|
if (globalTouchStart(event)) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-03-31 10:48:16 +08:00
|
|
|
|
firstDirection = null;
|
|
|
|
|
|
xDiff = undefined;
|
|
|
|
|
|
yDiff = undefined;
|
|
|
|
|
|
lastClientX = undefined;
|
2024-04-02 15:10:40 +08:00
|
|
|
|
firstXY = undefined;
|
2023-09-06 17:19:11 +08:00
|
|
|
|
if (isIPhone() ||
|
2023-03-30 18:12:09 +08:00
|
|
|
|
(event.touches[0].clientX > 8 && event.touches[0].clientX < window.innerWidth - 8)) {
|
|
|
|
|
|
clientX = event.touches[0].clientX;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
clientY = event.touches[0].clientY;
|
2023-03-30 18:12:09 +08:00
|
|
|
|
time = new Date().getTime();
|
2022-05-26 15:18:53 +08:00
|
|
|
|
} else {
|
|
|
|
|
|
clientX = null;
|
|
|
|
|
|
clientY = null;
|
2023-03-30 18:12:09 +08:00
|
|
|
|
time = 0;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
event.stopImmediatePropagation();
|
|
|
|
|
|
}
|
2024-04-18 10:44:46 +08:00
|
|
|
|
isFirstMove = true;
|
2024-02-06 09:16:01 +08:00
|
|
|
|
scrollBlock = false;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
};
|
|
|
|
|
|
|
2023-03-31 10:46:40 +08:00
|
|
|
|
let previousClientX: number;
|
2024-04-03 16:04:13 +08:00
|
|
|
|
const sideMaskElement = document.querySelector(".side-mask") as HTMLElement;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
export const handleTouchMove = (event: TouchEvent) => {
|
2023-03-31 10:46:40 +08:00
|
|
|
|
const target = event.target as HTMLElement;
|
|
|
|
|
|
if (!clientX || !clientY ||
|
2023-04-06 16:02:06 +08:00
|
|
|
|
target.tagName === "AUDIO" ||
|
2023-04-12 10:56:46 +08:00
|
|
|
|
hasClosestByClassName(target, "b3-dialog", true) ||
|
2023-04-10 11:25:25 +08:00
|
|
|
|
(window.siyuan.mobile.editor && !window.siyuan.mobile.editor.protyle.toolbar.subElement.classList.contains("fn__none")) ||
|
2023-03-31 16:41:09 +08:00
|
|
|
|
hasClosestByClassName(target, "keyboard") ||
|
2023-04-09 23:04:30 +08:00
|
|
|
|
hasClosestByClassName(target, "viewer-container") ||
|
2024-04-02 15:10:40 +08:00
|
|
|
|
hasClosestByAttribute(target, "id", "commonMenu") || firstXY === "y"
|
2023-12-19 23:18:45 +08:00
|
|
|
|
) {
|
2023-03-30 18:12:09 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-01-04 18:13:36 +08:00
|
|
|
|
|
|
|
|
|
|
// 正在编辑时禁止滑动
|
2025-03-22 23:42:20 +08:00
|
|
|
|
if (!document.querySelector("#keyboardToolbar").classList.contains("fn__none")) {
|
2025-01-04 18:13:36 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-01-05 00:25:38 +08:00
|
|
|
|
// 只读状态下选中内容时时禁止滑动
|
2023-04-02 22:23:12 +08:00
|
|
|
|
if (getSelection().rangeCount > 0) {
|
|
|
|
|
|
// 选中后扩选的情况
|
|
|
|
|
|
const range = getSelection().getRangeAt(0);
|
|
|
|
|
|
if (range.toString() !== "" && window.siyuan.mobile.editor.protyle.wysiwyg.element.contains(range.startContainer)) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-03-31 10:46:40 +08:00
|
|
|
|
|
2022-05-26 15:18:53 +08:00
|
|
|
|
xDiff = Math.floor(clientX - event.touches[0].clientX);
|
|
|
|
|
|
yDiff = Math.floor(clientY - event.touches[0].clientY);
|
2023-03-31 10:46:40 +08:00
|
|
|
|
if (!firstDirection) {
|
|
|
|
|
|
firstDirection = xDiff > 0 ? "toLeft" : "toRight";
|
|
|
|
|
|
}
|
2024-04-02 15:10:40 +08:00
|
|
|
|
// 上下滚动防止左右滑动
|
|
|
|
|
|
if (!firstXY) {
|
|
|
|
|
|
if (Math.abs(xDiff) > Math.abs(yDiff)) {
|
2024-04-03 16:04:13 +08:00
|
|
|
|
firstXY = "x";
|
2024-04-02 15:10:40 +08:00
|
|
|
|
} else {
|
2024-04-03 16:04:13 +08:00
|
|
|
|
firstXY = "y";
|
2024-04-02 15:10:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (firstXY === "x") {
|
|
|
|
|
|
if ((hasClosestByAttribute(target, "id", "menu") && firstDirection === "toLeft") ||
|
|
|
|
|
|
(hasClosestByAttribute(target, "id", "sidebar") && firstDirection === "toRight")) {
|
2024-04-03 16:04:13 +08:00
|
|
|
|
firstXY = "y";
|
|
|
|
|
|
yDiff = undefined;
|
2024-04-02 15:10:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-03-31 10:46:40 +08:00
|
|
|
|
if (previousClientX) {
|
|
|
|
|
|
if (firstDirection === "toRight") {
|
|
|
|
|
|
if (previousClientX > event.touches[0].clientX) {
|
|
|
|
|
|
lastClientX = event.touches[0].clientX;
|
|
|
|
|
|
} else {
|
2023-03-31 10:48:16 +08:00
|
|
|
|
lastClientX = undefined;
|
2023-03-31 10:46:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
} else if (firstDirection === "toLeft") {
|
|
|
|
|
|
if (previousClientX < event.touches[0].clientX) {
|
|
|
|
|
|
lastClientX = event.touches[0].clientX;
|
|
|
|
|
|
} else {
|
2023-03-31 10:48:16 +08:00
|
|
|
|
lastClientX = undefined;
|
2023-03-31 10:46:40 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
previousClientX = event.touches[0].clientX;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
if (Math.abs(xDiff) > Math.abs(yDiff)) {
|
2023-12-19 23:18:45 +08:00
|
|
|
|
if (hasClosestByAttribute(target, "id", "model", true)) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-04-04 21:47:52 +08:00
|
|
|
|
let scrollElement = hasClosestByAttribute(target, "data-type", "NodeCodeBlock") ||
|
2023-07-30 14:42:28 +08:00
|
|
|
|
hasClosestByAttribute(target, "data-type", "NodeAttributeView") ||
|
2024-02-04 12:00:41 +08:00
|
|
|
|
hasClosestByAttribute(target, "data-type", "NodeMathBlock") ||
|
2023-05-30 23:56:46 +08:00
|
|
|
|
hasClosestByAttribute(target, "data-type", "NodeTable") ||
|
2025-03-22 23:42:20 +08:00
|
|
|
|
hasTopClosestByClassName(target, "list") ||
|
|
|
|
|
|
hasTopClosestByClassName(target, "protyle-breadcrumb__bar--nowrap");
|
2023-03-30 18:12:09 +08:00
|
|
|
|
if (scrollElement) {
|
2023-04-04 21:47:52 +08:00
|
|
|
|
if (scrollElement.classList.contains("table")) {
|
2023-04-06 22:32:33 +08:00
|
|
|
|
scrollElement = scrollElement.firstElementChild as HTMLElement;
|
2023-04-04 21:47:52 +08:00
|
|
|
|
} else if (scrollElement.classList.contains("code-block")) {
|
2023-04-06 22:32:33 +08:00
|
|
|
|
scrollElement = scrollElement.firstElementChild.nextElementSibling as HTMLElement;
|
2023-07-30 14:42:28 +08:00
|
|
|
|
} else if (scrollElement.classList.contains("av")) {
|
2025-11-23 13:50:14 +08:00
|
|
|
|
scrollElement = hasClosestByClassName(target, "layout-tab-bar") || hasClosestByClassName(target, "av__scroll") ||
|
|
|
|
|
|
hasClosestByClassName(target, "av__kanban");
|
2024-02-04 12:00:41 +08:00
|
|
|
|
} else if (scrollElement.dataset.type === "NodeMathBlock") {
|
|
|
|
|
|
scrollElement = target;
|
|
|
|
|
|
while (scrollElement && scrollElement.dataset.type !== "NodeMathBlock") {
|
2024-04-11 18:10:05 +08:00
|
|
|
|
if (scrollElement.nodeType === 1 && scrollElement.scrollLeft > 0) {
|
2024-02-04 12:00:41 +08:00
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
scrollElement = scrollElement.parentElement;
|
|
|
|
|
|
}
|
2023-04-04 21:47:52 +08:00
|
|
|
|
}
|
2025-03-22 23:42:20 +08:00
|
|
|
|
let noScroll = false;
|
|
|
|
|
|
if (scrollElement && scrollElement.scrollLeft === 0) {
|
|
|
|
|
|
scrollElement.scrollLeft = 1;
|
|
|
|
|
|
if (scrollElement.scrollLeft === 0) {
|
|
|
|
|
|
noScroll = true;
|
|
|
|
|
|
}
|
2024-02-04 12:00:41 +08:00
|
|
|
|
}
|
2025-03-22 23:42:20 +08:00
|
|
|
|
if (!noScroll) {
|
|
|
|
|
|
if (scrollElement && (
|
|
|
|
|
|
(xDiff < 0 && scrollElement.scrollLeft > 0) ||
|
|
|
|
|
|
(xDiff > 0 && scrollElement.clientWidth + scrollElement.scrollLeft < scrollElement.scrollWidth)
|
|
|
|
|
|
)) {
|
|
|
|
|
|
scrollBlock = true;
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2025-06-06 20:12:33 +08:00
|
|
|
|
}
|
|
|
|
|
|
if (scrollBlock) {
|
|
|
|
|
|
return;
|
2023-03-30 18:12:09 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-06-06 20:12:33 +08:00
|
|
|
|
|
2024-04-18 10:44:46 +08:00
|
|
|
|
if (isFirstMove) {
|
|
|
|
|
|
sideMaskElement.style.zIndex = (++window.siyuan.zIndex).toString();
|
|
|
|
|
|
document.getElementById("sidebar").style.zIndex = (++window.siyuan.zIndex).toString();
|
|
|
|
|
|
document.getElementById("menu").style.zIndex = (++window.siyuan.zIndex).toString();
|
|
|
|
|
|
isFirstMove = false;
|
|
|
|
|
|
}
|
2023-03-31 16:41:09 +08:00
|
|
|
|
const windowWidth = window.innerWidth;
|
2023-03-30 18:15:20 +08:00
|
|
|
|
const menuElement = hasClosestByAttribute(target, "id", "menu");
|
2023-03-31 10:46:40 +08:00
|
|
|
|
if (menuElement) {
|
|
|
|
|
|
if (xDiff < 0) {
|
2023-04-06 19:14:23 +08:00
|
|
|
|
menuElement.style.transform = `translateX(${-xDiff}px)`;
|
2023-03-31 16:41:09 +08:00
|
|
|
|
transformMask(-xDiff / windowWidth);
|
|
|
|
|
|
} else {
|
2023-04-07 09:06:30 +08:00
|
|
|
|
menuElement.style.transform = "translateX(0px)";
|
2023-03-31 16:41:09 +08:00
|
|
|
|
transformMask(0);
|
2023-03-31 10:46:40 +08:00
|
|
|
|
}
|
2023-03-30 18:12:09 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2023-03-30 18:15:20 +08:00
|
|
|
|
const sideElement = hasClosestByAttribute(target, "id", "sidebar");
|
2023-03-31 10:46:40 +08:00
|
|
|
|
if (sideElement) {
|
|
|
|
|
|
if (xDiff > 0) {
|
2023-04-06 19:14:23 +08:00
|
|
|
|
sideElement.style.transform = `translateX(${-xDiff}px)`;
|
2023-03-31 16:41:09 +08:00
|
|
|
|
transformMask(xDiff / windowWidth);
|
|
|
|
|
|
} else {
|
2023-04-07 09:06:30 +08:00
|
|
|
|
sideElement.style.transform = "translateX(0px)";
|
2023-03-31 16:41:09 +08:00
|
|
|
|
transformMask(0);
|
2023-03-31 10:46:40 +08:00
|
|
|
|
}
|
2023-03-30 18:12:09 +08:00
|
|
|
|
return;
|
|
|
|
|
|
}
|
2024-04-02 14:16:43 +08:00
|
|
|
|
|
2023-03-31 10:46:40 +08:00
|
|
|
|
if (firstDirection === "toRight") {
|
2024-04-02 14:16:43 +08:00
|
|
|
|
document.getElementById("sidebar").style.transform = `translateX(${Math.min(-xDiff - windowWidth, 0)}px)`;
|
2023-03-31 16:41:09 +08:00
|
|
|
|
transformMask((windowWidth + xDiff) / windowWidth);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
} else {
|
2024-04-02 14:16:43 +08:00
|
|
|
|
document.getElementById("menu").style.transform = `translateX(${Math.max(windowWidth - xDiff, 0)}px)`;
|
2023-03-31 16:41:09 +08:00
|
|
|
|
transformMask((windowWidth - xDiff) / windowWidth);
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
2023-04-06 11:02:20 +08:00
|
|
|
|
activeBlur();
|
2023-04-12 18:22:54 +08:00
|
|
|
|
if (window.siyuan.mobile.editor) {
|
|
|
|
|
|
window.siyuan.mobile.editor.protyle.contentElement.style.overflow = "hidden";
|
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
}
|
|
|
|
|
|
};
|
2023-03-31 16:41:09 +08:00
|
|
|
|
|
|
|
|
|
|
const transformMask = (opacity: number) => {
|
2024-04-02 14:16:43 +08:00
|
|
|
|
sideMaskElement.classList.remove("fn__none");
|
|
|
|
|
|
sideMaskElement.style.opacity = Math.min((1 - opacity), 0.68).toString();
|
2023-04-02 10:42:42 +08:00
|
|
|
|
};
|