2025-03-18 11:56:26 +08:00
|
|
|
|
/// #if !MOBILE
|
2023-08-30 16:32:54 +08:00
|
|
|
|
import {getAllModels} from "../../layout/getAll";
|
2025-03-18 11:56:26 +08:00
|
|
|
|
/// #endif
|
2025-01-16 10:00:30 +08:00
|
|
|
|
import {hasClosestByAttribute, hasClosestByClassName, hasTopClosestByClassName} from "../../protyle/util/hasClosest";
|
2023-08-30 16:32:54 +08:00
|
|
|
|
import {hideAllElements} from "../../protyle/ui/hideElements";
|
|
|
|
|
|
import {isWindow} from "../../util/functions";
|
|
|
|
|
|
import {writeText} from "../../protyle/util/compatibility";
|
|
|
|
|
|
import {showMessage} from "../../dialog/message";
|
2025-01-11 21:25:51 +08:00
|
|
|
|
import {cancelDrag} from "./dragover";
|
2023-08-30 16:32:54 +08:00
|
|
|
|
|
2025-01-15 11:42:08 +08:00
|
|
|
|
export const globalClickHideMenu = (element: HTMLElement) => {
|
|
|
|
|
|
if (!window.siyuan.menus.menu.element.contains(element) && !hasClosestByAttribute(element, "data-menu", "true")) {
|
2023-08-30 16:32:54 +08:00
|
|
|
|
if (getSelection().rangeCount > 0 && window.siyuan.menus.menu.element.contains(getSelection().getRangeAt(0).startContainer) &&
|
2024-01-02 17:18:11 +08:00
|
|
|
|
window.siyuan.menus.menu.element.contains(document.activeElement)) {
|
2023-08-30 16:32:54 +08:00
|
|
|
|
// https://ld246.com/article/1654567749834/comment/1654589171218#comments
|
|
|
|
|
|
} else {
|
|
|
|
|
|
window.siyuan.menus.menu.remove();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-01-16 10:00:30 +08:00
|
|
|
|
};
|
2025-01-15 11:42:08 +08:00
|
|
|
|
|
|
|
|
|
|
export const globalClick = (event: MouseEvent & { target: HTMLElement }) => {
|
|
|
|
|
|
cancelDrag();
|
|
|
|
|
|
|
|
|
|
|
|
globalClickHideMenu(event.target);
|
2025-01-10 11:17:40 +08:00
|
|
|
|
|
2024-06-01 00:08:35 +08:00
|
|
|
|
const protyleElement = hasClosestByClassName(event.target, "protyle", true);
|
2024-04-06 23:30:07 +08:00
|
|
|
|
if (protyleElement) {
|
|
|
|
|
|
const wysiwygElement = protyleElement.querySelector(".protyle-wysiwyg");
|
|
|
|
|
|
if (wysiwygElement.getAttribute("data-readonly") === "true" || !wysiwygElement.contains(event.target)) {
|
|
|
|
|
|
wysiwygElement.dispatchEvent(new Event("focusin"));
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-03-18 11:56:26 +08:00
|
|
|
|
|
2025-05-28 18:01:18 +08:00
|
|
|
|
if (!hasTopClosestByClassName(event.target, "protyle-util") &&
|
|
|
|
|
|
!hasTopClosestByClassName(event.target, "protyle-toolbar")) {
|
|
|
|
|
|
document.querySelectorAll(".protyle-font").forEach((item: HTMLElement) => {
|
|
|
|
|
|
item.parentElement.classList.add("fn__none");
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-08-30 16:32:54 +08:00
|
|
|
|
const copyElement = hasTopClosestByClassName(event.target, "protyle-action__copy");
|
|
|
|
|
|
if (copyElement) {
|
2024-11-27 11:39:40 +08:00
|
|
|
|
let text = copyElement.parentElement.nextElementSibling.textContent.replace(/\n$/, "");
|
2023-10-09 21:45:36 +08:00
|
|
|
|
text = text.replace(/\u00A0/g, " "); // Replace non-breaking spaces with normal spaces when copying https://github.com/siyuan-note/siyuan/issues/9382
|
|
|
|
|
|
writeText(text);
|
2023-08-30 16:32:54 +08:00
|
|
|
|
showMessage(window.siyuan.languages.copied, 2000);
|
|
|
|
|
|
event.preventDefault();
|
2023-09-05 09:17:03 +08:00
|
|
|
|
return;
|
2023-08-30 16:32:54 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-03-18 11:56:26 +08:00
|
|
|
|
/// #if !MOBILE
|
|
|
|
|
|
// dock float 时,点击空白处,隐藏 dock。场景:文档树上重命名后
|
|
|
|
|
|
if (!isWindow() && window.siyuan.layout.leftDock &&
|
|
|
|
|
|
!hasClosestByClassName(event.target, "b3-dialog--open", true) &&
|
|
|
|
|
|
!hasClosestByClassName(event.target, "b3-menu") &&
|
|
|
|
|
|
!hasClosestByClassName(event.target, "block__popover") &&
|
|
|
|
|
|
!hasClosestByClassName(event.target, "dock") &&
|
|
|
|
|
|
!hasClosestByClassName(event.target, "layout--float", true)
|
|
|
|
|
|
) {
|
|
|
|
|
|
window.siyuan.layout.bottomDock.hideDock();
|
|
|
|
|
|
window.siyuan.layout.leftDock.hideDock();
|
|
|
|
|
|
window.siyuan.layout.rightDock.hideDock();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
if (!hasClosestByClassName(event.target, "pdf__outer")) {
|
|
|
|
|
|
hideAllElements(["pdfutil"]);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2023-08-30 16:32:54 +08:00
|
|
|
|
// 点击空白,pdf 搜索、更多消失
|
2024-10-11 01:07:32 +08:00
|
|
|
|
if (hasClosestByAttribute(event.target, "id", "secondaryToolbarToggleButton") ||
|
|
|
|
|
|
hasClosestByAttribute(event.target, "id", "viewFindButton") ||
|
2023-08-30 16:32:54 +08:00
|
|
|
|
hasClosestByAttribute(event.target, "id", "findbar")) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
let currentPDFViewerObject: any;
|
|
|
|
|
|
getAllModels().asset.find(item => {
|
|
|
|
|
|
if (item.pdfObject &&
|
|
|
|
|
|
!item.pdfObject.appConfig.appContainer.classList.contains("fn__none")) {
|
|
|
|
|
|
currentPDFViewerObject = item.pdfObject;
|
|
|
|
|
|
return true;
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
if (!currentPDFViewerObject) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
if (currentPDFViewerObject.secondaryToolbar.isOpen) {
|
|
|
|
|
|
currentPDFViewerObject.secondaryToolbar.close();
|
|
|
|
|
|
}
|
|
|
|
|
|
if (
|
|
|
|
|
|
!currentPDFViewerObject.supportsIntegratedFind &&
|
|
|
|
|
|
currentPDFViewerObject.findBar.opened
|
|
|
|
|
|
) {
|
|
|
|
|
|
currentPDFViewerObject.findBar.close();
|
|
|
|
|
|
}
|
2025-03-18 11:56:26 +08:00
|
|
|
|
/// #endif
|
2023-09-05 09:39:57 +08:00
|
|
|
|
};
|