A privacy-first, self-hosted, fully open source personal knowledge management software, written in typescript and golang. (PERSONAL FORK)
1/// #if !MOBILE
2import {getAllModels} from "../../layout/getAll";
3/// #endif
4import {hasClosestByAttribute, hasClosestByClassName, hasTopClosestByClassName} from "../../protyle/util/hasClosest";
5import {hideAllElements} from "../../protyle/ui/hideElements";
6import {isWindow} from "../../util/functions";
7import {writeText} from "../../protyle/util/compatibility";
8import {showMessage} from "../../dialog/message";
9import {cancelDrag} from "./dragover";
10
11export const globalClickHideMenu = (element: HTMLElement) => {
12 if (!window.siyuan.menus.menu.element.contains(element) && !hasClosestByAttribute(element, "data-menu", "true")) {
13 if (getSelection().rangeCount > 0 && window.siyuan.menus.menu.element.contains(getSelection().getRangeAt(0).startContainer) &&
14 window.siyuan.menus.menu.element.contains(document.activeElement)) {
15 // https://ld246.com/article/1654567749834/comment/1654589171218#comments
16 } else {
17 window.siyuan.menus.menu.remove();
18 }
19 }
20};
21
22export const globalClick = (event: MouseEvent & { target: HTMLElement }) => {
23 cancelDrag();
24
25 globalClickHideMenu(event.target);
26
27 const protyleElement = hasClosestByClassName(event.target, "protyle", true);
28 if (protyleElement) {
29 const wysiwygElement = protyleElement.querySelector(".protyle-wysiwyg");
30 if (wysiwygElement.getAttribute("data-readonly") === "true" || !wysiwygElement.contains(event.target)) {
31 wysiwygElement.dispatchEvent(new Event("focusin"));
32 }
33 }
34
35 if (!hasTopClosestByClassName(event.target, "protyle-util") &&
36 !hasTopClosestByClassName(event.target, "protyle-toolbar")) {
37 document.querySelectorAll(".protyle-font").forEach((item: HTMLElement) => {
38 item.parentElement.classList.add("fn__none");
39 });
40 }
41
42 const copyElement = hasTopClosestByClassName(event.target, "protyle-action__copy");
43 if (copyElement) {
44 let text = copyElement.parentElement.nextElementSibling.textContent.replace(/\n$/, "");
45 text = text.replace(/\u00A0/g, " "); // Replace non-breaking spaces with normal spaces when copying https://github.com/siyuan-note/siyuan/issues/9382
46 writeText(text);
47 showMessage(window.siyuan.languages.copied, 2000);
48 event.preventDefault();
49 return;
50 }
51
52 /// #if !MOBILE
53 // dock float 时,点击空白处,隐藏 dock。场景:文档树上重命名后
54 if (!isWindow() && window.siyuan.layout.leftDock &&
55 !hasClosestByClassName(event.target, "b3-dialog--open", true) &&
56 !hasClosestByClassName(event.target, "b3-menu") &&
57 !hasClosestByClassName(event.target, "block__popover") &&
58 !hasClosestByClassName(event.target, "dock") &&
59 !hasClosestByClassName(event.target, "layout--float", true)
60 ) {
61 window.siyuan.layout.bottomDock.hideDock();
62 window.siyuan.layout.leftDock.hideDock();
63 window.siyuan.layout.rightDock.hideDock();
64 }
65
66 if (!hasClosestByClassName(event.target, "pdf__outer")) {
67 hideAllElements(["pdfutil"]);
68 }
69
70 // 点击空白,pdf 搜索、更多消失
71 if (hasClosestByAttribute(event.target, "id", "secondaryToolbarToggleButton") ||
72 hasClosestByAttribute(event.target, "id", "viewFindButton") ||
73 hasClosestByAttribute(event.target, "id", "findbar")) {
74 return;
75 }
76 let currentPDFViewerObject: any;
77 getAllModels().asset.find(item => {
78 if (item.pdfObject &&
79 !item.pdfObject.appConfig.appContainer.classList.contains("fn__none")) {
80 currentPDFViewerObject = item.pdfObject;
81 return true;
82 }
83 });
84 if (!currentPDFViewerObject) {
85 return;
86 }
87 if (currentPDFViewerObject.secondaryToolbar.isOpen) {
88 currentPDFViewerObject.secondaryToolbar.close();
89 }
90 if (
91 !currentPDFViewerObject.supportsIntegratedFind &&
92 currentPDFViewerObject.findBar.opened
93 ) {
94 currentPDFViewerObject.findBar.close();
95 }
96 /// #endif
97};