|
| 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 | +} |
0 commit comments