2023-04-28 10:30:27 +08:00
|
|
|
|
import {hideElements} from "../ui/hideElements";
|
|
|
|
|
|
import {setPadding} from "../ui/initUI";
|
|
|
|
|
|
import {hasClosestBlock} from "./hasClosest";
|
2023-05-10 20:18:40 +08:00
|
|
|
|
import {Constants} from "../../constants";
|
2023-09-13 12:05:57 +08:00
|
|
|
|
import {lineNumberRender} from "../render/highlightRender";
|
2023-12-10 12:10:25 +08:00
|
|
|
|
import {stickyRow} from "../render/av/row";
|
2023-04-28 10:30:27 +08:00
|
|
|
|
|
|
|
|
|
|
export const resize = (protyle: IProtyle) => {
|
2024-01-29 15:44:18 +08:00
|
|
|
|
hideElements(["gutterOnly"], protyle);
|
2023-09-13 12:05:57 +08:00
|
|
|
|
const abs = setPadding(protyle);
|
|
|
|
|
|
const MIN_ABS = 4;
|
2023-07-16 20:59:14 +08:00
|
|
|
|
// 不能 clearTimeout,否则 split 时左侧无法 resize
|
2023-09-13 12:05:57 +08:00
|
|
|
|
setTimeout(() => {
|
2024-05-10 23:10:57 +08:00
|
|
|
|
if (!protyle.disabled) {
|
2023-12-10 12:10:25 +08:00
|
|
|
|
const contentRect = protyle.contentElement.getBoundingClientRect();
|
|
|
|
|
|
protyle.wysiwyg.element.querySelectorAll(".av").forEach((item: HTMLElement) => {
|
|
|
|
|
|
if (item.querySelector(".av__title")) {
|
|
|
|
|
|
stickyRow(item, contentRect, "all");
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
|
|
|
|
|
}
|
2023-09-13 12:05:57 +08:00
|
|
|
|
if (abs.width > MIN_ABS || isNaN(abs.width)) {
|
2023-09-28 22:38:49 +08:00
|
|
|
|
if (typeof window.echarts !== "undefined") {
|
2023-09-13 12:05:57 +08:00
|
|
|
|
protyle.wysiwyg.element.querySelectorAll('[data-subtype="echarts"], [data-subtype="mindmap"]').forEach((chartItem: HTMLElement) => {
|
2023-09-28 22:38:49 +08:00
|
|
|
|
const chartInstance = window.echarts.getInstanceById(chartItem.firstElementChild.nextElementSibling.getAttribute("_echarts_instance_"));
|
2023-09-13 12:05:57 +08:00
|
|
|
|
if (chartInstance) {
|
|
|
|
|
|
chartInstance.resize();
|
|
|
|
|
|
}
|
|
|
|
|
|
});
|
2023-06-11 22:01:30 +08:00
|
|
|
|
}
|
2024-08-15 11:21:05 +08:00
|
|
|
|
protyle.wysiwyg.element.querySelectorAll(".code-block .protyle-linenumber__rows").forEach((item: HTMLElement) => {
|
2024-09-03 23:29:54 +08:00
|
|
|
|
if ((item.nextElementSibling as HTMLElement).style.wordBreak === "break-word") {
|
|
|
|
|
|
lineNumberRender(item.parentElement);
|
2024-05-10 23:10:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
});
|
2023-09-13 12:05:57 +08:00
|
|
|
|
// 保持光标位置不变 https://ld246.com/article/1673704873983/comment/1673765814595#comments
|
|
|
|
|
|
if (!protyle.disabled && protyle.toolbar.range) {
|
|
|
|
|
|
let rangeRect = protyle.toolbar.range.getBoundingClientRect();
|
|
|
|
|
|
if (rangeRect.height === 0) {
|
|
|
|
|
|
const blockElement = hasClosestBlock(protyle.toolbar.range.startContainer);
|
|
|
|
|
|
if (blockElement) {
|
|
|
|
|
|
rangeRect = blockElement.getBoundingClientRect();
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
if (rangeRect.height === 0) {
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
|
|
|
|
|
const protyleRect = protyle.element.getBoundingClientRect();
|
|
|
|
|
|
if (protyleRect.top + 30 > rangeRect.top || protyleRect.bottom < rangeRect.bottom) {
|
|
|
|
|
|
protyle.toolbar.range.startContainer.parentElement.scrollIntoView(protyleRect.top > rangeRect.top);
|
|
|
|
|
|
}
|
2023-04-28 10:30:27 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2023-05-10 20:18:40 +08:00
|
|
|
|
}, Constants.TIMEOUT_TRANSITION); // 等待 setPadding 动画结束
|
2023-04-28 10:30:27 +08:00
|
|
|
|
};
|