2023-03-30 18:12:09 +08:00
|
|
|
import {hasClosestByAttribute} from "../../protyle/util/hasClosest";
|
|
|
|
|
import {closePanel} from "./closePanel";
|
|
|
|
|
import {popMenu} from "../menu";
|
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;
|
2022-05-26 15:18:53 +08:00
|
|
|
|
2023-03-30 18:12:09 +08:00
|
|
|
export const handleTouchEnd = (event: TouchEvent) => {
|
2023-01-19 20:31:14 +08:00
|
|
|
if (window.siyuan.mobile.editor) {
|
2022-12-24 22:04:01 +08:00
|
|
|
document.querySelectorAll(".protyle-breadcrumb__bar--hide").forEach(item => {
|
2022-12-25 10:31:01 +08:00
|
|
|
item.classList.remove("protyle-breadcrumb__bar--hide");
|
|
|
|
|
});
|
2022-12-24 22:04:01 +08:00
|
|
|
window.siyuan.hideBreadcrumb = false;
|
2022-08-01 10:20:35 +08:00
|
|
|
}
|
|
|
|
|
|
2023-03-30 18:12:09 +08:00
|
|
|
if (!clientX || !clientY || xDiff === 0) {
|
2022-08-01 10:20:35 +08:00
|
|
|
return;
|
|
|
|
|
}
|
2022-05-26 15:18:53 +08:00
|
|
|
|
2023-03-30 18:15:20 +08:00
|
|
|
const target = event.target as HTMLElement;
|
|
|
|
|
let scrollElement = hasClosestByAttribute(target, "data-type", "NodeCodeBlock") || hasClosestByAttribute(target, "data-type", "NodeTable");
|
2023-03-30 18:12:09 +08:00
|
|
|
if (scrollElement) {
|
2023-03-30 18:15:20 +08:00
|
|
|
scrollElement = scrollElement.classList.contains("table") ? (scrollElement.firstElementChild as HTMLElement) : (scrollElement.firstElementChild.nextElementSibling as HTMLElement);
|
2023-03-30 18:12:09 +08:00
|
|
|
if ((xDiff < 0 && scrollElement.scrollLeft > 0) ||
|
|
|
|
|
(xDiff > 0 && scrollElement.clientWidth + scrollElement.scrollLeft < scrollElement.scrollWidth)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-03-30 18:15:20 +08:00
|
|
|
let show = false;
|
2023-03-30 18:12:09 +08:00
|
|
|
if (new Date().getTime() - time < 1000) {
|
2023-03-30 18:15:20 +08:00
|
|
|
show = true;
|
2023-03-30 18:12:09 +08:00
|
|
|
} else if (Math.abs(xDiff) > window.innerWidth / 3) {
|
2023-03-30 18:15:20 +08:00
|
|
|
show = true;
|
2023-03-30 18:12:09 +08:00
|
|
|
}
|
2023-03-30 18:15:20 +08:00
|
|
|
const menuElement = hasClosestByAttribute(target, "id", "menu");
|
2023-03-30 18:12:09 +08:00
|
|
|
if (show && menuElement && xDiff < 0) {
|
|
|
|
|
closePanel();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-03-30 18:15:20 +08:00
|
|
|
const sideElement = hasClosestByAttribute(target, "id", "sidebar");
|
2023-03-30 18:12:09 +08:00
|
|
|
if (show && sideElement && xDiff > 0) {
|
|
|
|
|
closePanel();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (!show) {
|
|
|
|
|
closePanel();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (Math.abs(xDiff) > Math.abs(yDiff)) {
|
2022-05-26 15:18:53 +08:00
|
|
|
if (xDiff > 0) {
|
2023-03-30 18:12:09 +08:00
|
|
|
popMenu();
|
2022-05-26 15:18:53 +08:00
|
|
|
} else {
|
2023-03-30 18:15:20 +08:00
|
|
|
document.getElementById("toolbarFile").dispatchEvent(new CustomEvent("click"));
|
2022-05-26 15:18:53 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const handleTouchStart = (event: TouchEvent) => {
|
|
|
|
|
xDiff = 0;
|
|
|
|
|
yDiff = 0;
|
2023-03-30 18:12:09 +08:00
|
|
|
if (navigator.userAgent.indexOf("iPhone") > -1 ||
|
|
|
|
|
(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();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export const handleTouchMove = (event: TouchEvent) => {
|
2023-03-30 18:12:09 +08:00
|
|
|
if (!clientX || !clientY) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
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-30 18:12:09 +08:00
|
|
|
|
2022-05-26 15:18:53 +08:00
|
|
|
if (Math.abs(xDiff) > Math.abs(yDiff)) {
|
2023-03-30 18:15:20 +08:00
|
|
|
const target = event.target as HTMLElement;
|
|
|
|
|
let scrollElement = hasClosestByAttribute(target, "data-type", "NodeCodeBlock") || hasClosestByAttribute(target, "data-type", "NodeTable");
|
2023-03-30 18:12:09 +08:00
|
|
|
if (scrollElement) {
|
2023-03-30 18:15:20 +08:00
|
|
|
scrollElement = scrollElement.classList.contains("table") ? (scrollElement.firstElementChild as HTMLElement) : (scrollElement.firstElementChild.nextElementSibling as HTMLElement);
|
2023-03-30 18:12:09 +08:00
|
|
|
if ((xDiff < 0 && scrollElement.scrollLeft > 0) ||
|
|
|
|
|
(xDiff > 0 && scrollElement.clientWidth + scrollElement.scrollLeft < scrollElement.scrollWidth)) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2023-03-30 18:15:20 +08:00
|
|
|
const menuElement = hasClosestByAttribute(target, "id", "menu");
|
2023-03-30 18:12:09 +08:00
|
|
|
if (menuElement && xDiff < 0) {
|
2023-03-30 18:15:20 +08:00
|
|
|
menuElement.style.right = xDiff + "px";
|
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-30 18:12:09 +08:00
|
|
|
if (sideElement && xDiff > 0) {
|
2023-03-30 18:15:20 +08:00
|
|
|
sideElement.style.left = -xDiff + "px";
|
2023-03-30 18:12:09 +08:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
console.log(event);
|
2022-05-26 15:18:53 +08:00
|
|
|
if (xDiff < 0) {
|
2023-03-30 18:15:20 +08:00
|
|
|
document.getElementById("sidebar").style.left = -window.innerWidth - xDiff + "px";
|
2022-05-26 15:18:53 +08:00
|
|
|
} else {
|
2023-03-30 18:15:20 +08:00
|
|
|
document.getElementById("menu").style.right = -window.innerWidth + xDiff + "px";
|
2022-05-26 15:18:53 +08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|