2023-08-30 16:32:54 +08:00
|
|
|
import {App} from "../../index";
|
|
|
|
|
import {windowMouseMove} from "./mousemove";
|
|
|
|
|
import {windowKeyUp} from "./keyup";
|
|
|
|
|
import {windowKeyDown} from "./keydown";
|
|
|
|
|
import {globalClick} from "./click";
|
|
|
|
|
import {goBack, goForward} from "../../util/backForward";
|
2023-09-01 21:23:58 +08:00
|
|
|
import {Constants} from "../../constants";
|
2023-09-07 10:52:35 +08:00
|
|
|
import {isIPad} from "../../protyle/util/compatibility";
|
2023-11-17 22:35:16 +08:00
|
|
|
import {globalTouchEnd, globalTouchStart} from "./touch";
|
2023-09-07 10:52:35 +08:00
|
|
|
import {initDockMenu} from "../../menus/dock";
|
2024-02-25 22:27:59 +08:00
|
|
|
import {hasClosestByAttribute, hasClosestByClassName, hasTopClosestByAttribute} from "../../protyle/util/hasClosest";
|
2023-09-07 10:52:35 +08:00
|
|
|
import {initTabMenu} from "../../menus/tab";
|
|
|
|
|
import {getInstanceById} from "../../layout/util";
|
|
|
|
|
import {Tab} from "../../layout/Tab";
|
|
|
|
|
import {hideTooltip} from "../../dialog/tooltip";
|
2023-12-12 12:09:31 +08:00
|
|
|
import {openFileById} from "../../editor/util";
|
|
|
|
|
import {checkFold} from "../../util/noRelyPCFunction";
|
2023-08-30 16:32:54 +08:00
|
|
|
|
|
|
|
|
export const initWindowEvent = (app: App) => {
|
|
|
|
|
document.body.addEventListener("mouseleave", () => {
|
|
|
|
|
if (window.siyuan.layout.leftDock) {
|
|
|
|
|
window.siyuan.layout.leftDock.hideDock();
|
|
|
|
|
window.siyuan.layout.rightDock.hideDock();
|
|
|
|
|
window.siyuan.layout.bottomDock.hideDock();
|
|
|
|
|
}
|
2023-09-30 11:21:46 +08:00
|
|
|
hideTooltip();
|
2023-08-30 16:32:54 +08:00
|
|
|
});
|
2023-09-01 21:23:58 +08:00
|
|
|
let mouseIsEnter = false;
|
|
|
|
|
document.body.addEventListener("mouseenter", () => {
|
|
|
|
|
if (window.siyuan.layout.leftDock) {
|
|
|
|
|
mouseIsEnter = true;
|
|
|
|
|
setTimeout(() => {
|
|
|
|
|
mouseIsEnter = false;
|
|
|
|
|
}, Constants.TIMEOUT_TRANSITION);
|
|
|
|
|
}
|
|
|
|
|
});
|
2023-08-30 16:32:54 +08:00
|
|
|
|
|
|
|
|
window.addEventListener("mousemove", (event: MouseEvent & { target: HTMLElement }) => {
|
2023-09-01 21:23:58 +08:00
|
|
|
windowMouseMove(event, mouseIsEnter);
|
2023-08-30 16:32:54 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
window.addEventListener("mouseup", (event) => {
|
|
|
|
|
if (event.button === 3) {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
goBack(app);
|
|
|
|
|
} else if (event.button === 4) {
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
goForward(app);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
window.addEventListener("keyup", (event) => {
|
2023-09-07 17:14:31 +08:00
|
|
|
windowKeyUp(app, event);
|
2023-08-30 16:32:54 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
window.addEventListener("keydown", (event) => {
|
2023-09-07 17:14:31 +08:00
|
|
|
windowKeyDown(app, event);
|
2023-08-30 16:32:54 +08:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
window.addEventListener("blur", () => {
|
|
|
|
|
window.siyuan.ctrlIsPressed = false;
|
|
|
|
|
window.siyuan.shiftIsPressed = false;
|
|
|
|
|
window.siyuan.altIsPressed = false;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
window.addEventListener("click", (event: MouseEvent & { target: HTMLElement }) => {
|
2023-09-01 21:23:58 +08:00
|
|
|
globalClick(event);
|
2023-08-30 16:32:54 +08:00
|
|
|
});
|
2023-09-07 10:52:35 +08:00
|
|
|
|
2023-11-17 21:57:08 +08:00
|
|
|
let time = 0;
|
|
|
|
|
document.addEventListener("touchstart", (event) => {
|
|
|
|
|
time = new Date().getTime();
|
|
|
|
|
// https://github.com/siyuan-note/siyuan/issues/6328
|
|
|
|
|
const target = event.target as HTMLElement;
|
|
|
|
|
if (hasClosestByClassName(target, "protyle-icons") ||
|
|
|
|
|
hasClosestByClassName(target, "item") ||
|
|
|
|
|
target.classList.contains("protyle-background__icon")) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
// 触摸屏背景和嵌入块按钮显示
|
2023-11-20 12:28:20 +08:00
|
|
|
const backgroundElement = hasClosestByClassName(target, "protyle-background");
|
2023-11-17 21:57:08 +08:00
|
|
|
if (backgroundElement) {
|
2023-11-17 22:35:16 +08:00
|
|
|
if (!globalTouchStart(event)) {
|
2023-11-17 21:57:08 +08:00
|
|
|
backgroundElement.classList.toggle("protyle-background--mobileshow");
|
|
|
|
|
}
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-02-25 22:27:59 +08:00
|
|
|
const embedBlockElement = hasTopClosestByAttribute(target, "data-type", "NodeBlockQueryEmbed");
|
2023-11-17 21:57:08 +08:00
|
|
|
if (embedBlockElement) {
|
|
|
|
|
embedBlockElement.firstElementChild.classList.toggle("protyle-icons--show");
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}, false);
|
|
|
|
|
document.addEventListener("touchend", (event) => {
|
|
|
|
|
if (isIPad()) {
|
|
|
|
|
// https://github.com/siyuan-note/siyuan/issues/9113
|
2023-09-07 10:52:35 +08:00
|
|
|
if (globalTouchEnd(event, undefined, time, app)) {
|
|
|
|
|
event.stopImmediatePropagation();
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
if (new Date().getTime() - time <= 900) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
const target = event.target as HTMLElement;
|
|
|
|
|
// dock right menu
|
|
|
|
|
const dockElement = hasClosestByClassName(target, "dock__item");
|
|
|
|
|
if (dockElement && dockElement.getAttribute("data-type")) {
|
2023-09-08 09:39:54 +08:00
|
|
|
const dockRect = dockElement.getBoundingClientRect();
|
2023-09-07 11:29:08 +08:00
|
|
|
initDockMenu(dockElement).popup({x: dockRect.right, y: dockRect.top});
|
2023-09-07 10:52:35 +08:00
|
|
|
event.stopImmediatePropagation();
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// tab right menu
|
|
|
|
|
const tabElement = hasClosestByAttribute(target, "data-type", "tab-header");
|
|
|
|
|
if (tabElement) {
|
2023-09-08 09:39:54 +08:00
|
|
|
const tabRect = tabElement.getBoundingClientRect();
|
2023-09-07 10:52:35 +08:00
|
|
|
initTabMenu(app, (getInstanceById(tabElement.getAttribute("data-id")) as Tab)).popup({
|
2023-09-07 11:29:08 +08:00
|
|
|
x: tabRect.left,
|
|
|
|
|
y: tabRect.bottom
|
2023-09-07 10:52:35 +08:00
|
|
|
});
|
2023-09-08 09:39:54 +08:00
|
|
|
hideTooltip();
|
2023-09-07 10:52:35 +08:00
|
|
|
event.stopImmediatePropagation();
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-11-17 22:03:59 +08:00
|
|
|
|
|
|
|
|
const backlinkBreadcrumbItemElement = hasClosestByClassName(target, "protyle-breadcrumb__item");
|
|
|
|
|
if (backlinkBreadcrumbItemElement) {
|
2023-11-17 22:35:16 +08:00
|
|
|
const breadcrumbId = backlinkBreadcrumbItemElement.getAttribute("data-id") || backlinkBreadcrumbItemElement.getAttribute("data-node-id");
|
2023-11-17 22:03:59 +08:00
|
|
|
if (breadcrumbId) {
|
2023-12-09 23:32:33 +08:00
|
|
|
checkFold(breadcrumbId, (zoomIn) => {
|
2023-11-17 22:03:59 +08:00
|
|
|
openFileById({
|
|
|
|
|
app,
|
|
|
|
|
id: breadcrumbId,
|
2023-12-09 23:32:33 +08:00
|
|
|
action: zoomIn ? [Constants.CB_GET_FOCUS, Constants.CB_GET_ALL] : [Constants.CB_GET_FOCUS, Constants.CB_GET_CONTEXT],
|
|
|
|
|
zoomIn,
|
2023-11-17 22:03:59 +08:00
|
|
|
});
|
|
|
|
|
window.siyuan.menus.menu.remove();
|
2023-12-09 23:33:06 +08:00
|
|
|
});
|
2023-11-17 22:03:59 +08:00
|
|
|
}
|
|
|
|
|
event.stopImmediatePropagation();
|
|
|
|
|
event.preventDefault();
|
|
|
|
|
return;
|
|
|
|
|
}
|
2023-11-17 21:57:08 +08:00
|
|
|
}
|
|
|
|
|
}, false);
|
2023-08-30 16:32:54 +08:00
|
|
|
};
|