Skip to content

Commit c0535ff

Browse files
committed
♻️ #9032
1 parent 2349b08 commit c0535ff

File tree

10 files changed

+1754
-1712
lines changed

10 files changed

+1754
-1712
lines changed

app/src/boot/globalEvent/click.ts

+74
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import {getAllModels} from "../../layout/getAll";
2+
import {hasClosestByAttribute, hasClosestByClassName, hasTopClosestByClassName} from "../../protyle/util/hasClosest";
3+
import {hideAllElements} from "../../protyle/ui/hideElements";
4+
import {isWindow} from "../../util/functions";
5+
import {writeText} from "../../protyle/util/compatibility";
6+
import {showMessage} from "../../dialog/message";
7+
8+
export const globalClick = (event: MouseEvent & { target: HTMLElement }) => {
9+
if (!window.siyuan.menus.menu.element.contains(event.target) && !hasClosestByAttribute(event.target, "data-menu", "true")) {
10+
if (getSelection().rangeCount > 0 && window.siyuan.menus.menu.element.contains(getSelection().getRangeAt(0).startContainer) &&
11+
window.siyuan.menus.menu.element.contains(document.activeElement)) {
12+
// https://ld246.com/article/1654567749834/comment/1654589171218#comments
13+
} else {
14+
window.siyuan.menus.menu.remove();
15+
}
16+
}
17+
// protyle.toolbar 点击空白处时进行隐藏
18+
if (!hasClosestByClassName(event.target, "protyle-toolbar")) {
19+
hideAllElements(["toolbar"]);
20+
}
21+
if (!hasClosestByClassName(event.target, "pdf__outer")) {
22+
hideAllElements(["pdfutil"]);
23+
}
24+
// dock float 时,点击空白处,隐藏 dock
25+
const floatDockLayoutElement = hasClosestByClassName(event.target, "layout--float", true);
26+
if (floatDockLayoutElement && window.siyuan.layout.leftDock) {
27+
if (!floatDockLayoutElement.isSameNode(window.siyuan.layout.bottomDock.layout.element)) {
28+
window.siyuan.layout.bottomDock.hideDock();
29+
}
30+
if (!floatDockLayoutElement.isSameNode(window.siyuan.layout.leftDock.layout.element)) {
31+
window.siyuan.layout.leftDock.hideDock();
32+
}
33+
if (!floatDockLayoutElement.isSameNode(window.siyuan.layout.rightDock.layout.element)) {
34+
window.siyuan.layout.rightDock.hideDock();
35+
}
36+
} else if (!hasClosestByClassName(event.target, "dock") && !isWindow() && window.siyuan.layout.leftDock) {
37+
window.siyuan.layout.bottomDock.hideDock();
38+
window.siyuan.layout.leftDock.hideDock();
39+
window.siyuan.layout.rightDock.hideDock();
40+
}
41+
const copyElement = hasTopClosestByClassName(event.target, "protyle-action__copy");
42+
if (copyElement) {
43+
writeText(copyElement.parentElement.nextElementSibling.textContent.trimEnd());
44+
showMessage(window.siyuan.languages.copied, 2000);
45+
event.preventDefault();
46+
}
47+
48+
// 点击空白,pdf 搜索、更多消失
49+
if (hasClosestByAttribute(event.target, "id", "secondaryToolbarToggle") ||
50+
hasClosestByAttribute(event.target, "id", "viewFind") ||
51+
hasClosestByAttribute(event.target, "id", "findbar")) {
52+
return;
53+
}
54+
let currentPDFViewerObject: any;
55+
getAllModels().asset.find(item => {
56+
if (item.pdfObject &&
57+
!item.pdfObject.appConfig.appContainer.classList.contains("fn__none")) {
58+
currentPDFViewerObject = item.pdfObject;
59+
return true;
60+
}
61+
});
62+
if (!currentPDFViewerObject) {
63+
return;
64+
}
65+
if (currentPDFViewerObject.secondaryToolbar.isOpen) {
66+
currentPDFViewerObject.secondaryToolbar.close();
67+
}
68+
if (
69+
!currentPDFViewerObject.supportsIntegratedFind &&
70+
currentPDFViewerObject.findBar.opened
71+
) {
72+
currentPDFViewerObject.findBar.close();
73+
}
74+
}

app/src/boot/globalEvent/event.ts

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
import {App} from "../../index";
2+
import {windowMouseMove} from "./mousemove";
3+
import {Dialog} from "../../dialog";
4+
import {windowKeyUp} from "./keyup";
5+
import {windowKeyDown} from "./keydown";
6+
import {globalClick} from "./click";
7+
import {goBack, goForward} from "../../util/backForward";
8+
9+
export const initWindowEvent = (app: App) => {
10+
document.body.addEventListener("mouseleave", () => {
11+
if (window.siyuan.layout.leftDock) {
12+
window.siyuan.layout.leftDock.hideDock();
13+
window.siyuan.layout.rightDock.hideDock();
14+
window.siyuan.layout.bottomDock.hideDock();
15+
}
16+
});
17+
18+
window.addEventListener("mousemove", (event: MouseEvent & { target: HTMLElement }) => {
19+
windowMouseMove(event);
20+
});
21+
22+
window.addEventListener("mouseup", (event) => {
23+
if (event.button === 3) {
24+
event.preventDefault();
25+
goBack(app);
26+
} else if (event.button === 4) {
27+
event.preventDefault();
28+
goForward(app);
29+
}
30+
});
31+
32+
let switchDialog: Dialog;
33+
34+
window.addEventListener("keyup", (event) => {
35+
windowKeyUp(app, event, switchDialog);
36+
});
37+
38+
window.addEventListener("keydown", (event) => {
39+
windowKeyDown(app, event, switchDialog);
40+
});
41+
42+
window.addEventListener("blur", () => {
43+
window.siyuan.ctrlIsPressed = false;
44+
window.siyuan.shiftIsPressed = false;
45+
window.siyuan.altIsPressed = false;
46+
});
47+
48+
window.addEventListener("click", (event: MouseEvent & { target: HTMLElement }) => {
49+
globalClick(event);
50+
});
51+
};

0 commit comments

Comments
 (0)