A privacy-first, self-hosted, fully open source personal knowledge management software, written in typescript and golang. (PERSONAL FORK)
at lambda-fork/main 90 lines 4.4 kB view raw
1import {hideElements} from "../ui/hideElements"; 2import {setPadding} from "../ui/initUI"; 3import {hasClosestBlock, hasClosestByClassName} from "./hasClosest"; 4import {Constants} from "../../constants"; 5import {lineNumberRender} from "../render/highlightRender"; 6/// #if !MOBILE 7import {getAllModels} from "../../layout/getAll"; 8/// #endif 9import {stickyRow} from "../render/av/row"; 10 11export const clearBeforeResizeTop = () => { 12 /// #if !MOBILE 13 getAllModels().editor.forEach((item) => { 14 if (item.editor && item.editor.protyle && 15 item.element.parentElement && !item.element.classList.contains("fn__none")) { 16 item.editor.protyle.wysiwyg.element.querySelector("[data-resize-top]")?.removeAttribute("data-resize-top"); 17 } 18 }); 19 /// #endif 20}; 21 22export const recordBeforeResizeTop = () => { 23 /// #if !MOBILE 24 getAllModels().editor.forEach((item) => { 25 if (item.editor && item.editor.protyle && 26 item.element.parentElement && !item.element.classList.contains("fn__none")) { 27 item.editor.protyle.wysiwyg.element.querySelector("[data-resize-top]")?.removeAttribute("data-resize-top"); 28 const contentRect = item.editor.protyle.contentElement.getBoundingClientRect(); 29 let topElement = document.elementFromPoint(contentRect.left + (contentRect.width / 2), contentRect.top); 30 if (hasClosestByClassName(topElement, "b3-menu")) { 31 window.siyuan.menus.menu.remove(); 32 topElement = document.elementFromPoint(contentRect.left + (contentRect.width / 2), contentRect.top); 33 } 34 if (!topElement) { 35 topElement = document.elementFromPoint(contentRect.left + (contentRect.width / 2), contentRect.top + 17); 36 } 37 if (!topElement) { 38 return; 39 } 40 topElement = hasClosestBlock(topElement) as HTMLElement; 41 if (!topElement) { 42 return; 43 } 44 topElement.setAttribute("data-resize-top", (contentRect.top - topElement.getBoundingClientRect().top).toString()); 45 } 46 }); 47 /// #endif 48}; 49 50export const resize = (protyle: IProtyle) => { 51 hideElements(["gutterOnly"], protyle); 52 const abs = setPadding(protyle); 53 const MIN_ABS = 4; 54 // 不能 clearTimeout,否则 split 时左侧无法 resize 55 setTimeout(() => { 56 if (protyle.scroll && protyle.scroll.element.parentElement.getAttribute("style")) { 57 protyle.scroll.element.parentElement.setAttribute("style", `--b3-dynamicscroll-width:${Math.min(protyle.contentElement.clientHeight - 49, 200)}px`); 58 } 59 if (!protyle.disabled) { 60 const contentRect = protyle.contentElement.getBoundingClientRect(); 61 protyle.wysiwyg.element.querySelectorAll(".av").forEach((item: HTMLElement) => { 62 if (item.querySelector(".av__scroll")) { 63 stickyRow(item, contentRect, "all"); 64 } 65 }); 66 } 67 if (abs.width > MIN_ABS || isNaN(abs.width)) { 68 if (typeof window.echarts !== "undefined") { 69 protyle.wysiwyg.element.querySelectorAll('[data-subtype="echarts"], [data-subtype="mindmap"]').forEach((chartItem: HTMLElement) => { 70 const chartInstance = window.echarts.getInstanceById(chartItem.firstElementChild.nextElementSibling.getAttribute("_echarts_instance_")); 71 if (chartInstance) { 72 chartInstance.resize(); 73 } 74 }); 75 } 76 } 77 // 小于 MIN_ABS 也会导致换行 https://github.com/siyuan-note/siyuan/issues/13677 78 protyle.wysiwyg.element.querySelectorAll(".code-block .protyle-linenumber__rows").forEach((item: HTMLElement) => { 79 if ((item.nextElementSibling as HTMLElement).style.wordBreak === "break-word") { 80 lineNumberRender(item.parentElement); 81 } 82 }); 83 const topElement = protyle.wysiwyg.element.querySelector("[data-resize-top]"); 84 if (topElement) { 85 topElement.scrollIntoView(); 86 protyle.contentElement.scrollTop += parseInt(topElement.getAttribute("data-resize-top")); 87 topElement.removeAttribute("data-resize-top"); 88 } 89 }, Constants.TIMEOUT_TRANSITION + 100); // 等待 setPadding 动画结束 90};