Vanessa 2024-11-22 20:32:38 +08:00
parent 7b38c9a108
commit eca2678012
4 changed files with 26 additions and 34 deletions

View file

@ -18,19 +18,11 @@ export const chartRender = (element: Element, cdn = Constants.PROTYLE_CDN) => {
if (echartsElements.length > 0) {
addScript(`${cdn}/js/echarts/echarts.min.js?v=5.3.2`, "protyleEchartsScript").then(() => {
addScript(`${cdn}/js/echarts/echarts-gl.min.js?v=2.0.9`, "protyleEchartsGLScript").then(() => {
let width: number = undefined;
if (echartsElements[0].firstElementChild.clientWidth === 0) {
const tabElement = hasClosestByClassName(echartsElements[0], "layout-tab-container", true);
if (tabElement) {
Array.from(tabElement.children).find(item => {
if (item.classList.contains("protyle") && !item.classList.contains("fn__none")) {
width = item.querySelector(".protyle-wysiwyg").firstElementChild.clientWidth;
return true;
}
});
}
}
const wysiswgElement = hasClosestByClassName(element, "protyle-wysiwyg", true);
let width: number = undefined;
if (wysiswgElement && wysiswgElement.clientWidth > 0 && echartsElements[0].firstElementChild.clientWidth === 0 && wysiswgElement.firstElementChild) {
width = wysiswgElement.firstElementChild.clientWidth;
}
echartsElements.forEach(async (e: HTMLDivElement) => {
if (e.getAttribute("data-render") === "true") {
return;

View file

@ -20,15 +20,19 @@ export const flowchartRender = (element: Element, cdn = Constants.PROTYLE_CDN) =
}
addScript(`${cdn}/js/flowchart.js/flowchart.min.js?v=0.0.0`, "protyleFlowchartScript").then(() => {
if (flowchartElements[0].firstElementChild.clientWidth === 0) {
const hideElement = hasClosestByAttribute(flowchartElements[0], "fold", "1");
if (!hideElement) {
return;
}
const observer = new MutationObserver(() => {
initFlowchart(flowchartElements);
observer.disconnect();
});
observer.observe(hideElement, {attributeFilter: ["fold"]});
const hideElement = hasClosestByAttribute(flowchartElements[0], "fold", "1");
if (hideElement) {
observer.observe(hideElement, {attributeFilter: ["fold"]});
} else {
const cardElement = hasClosestByClassName(flowchartElements[0], "card__block", true);
if (cardElement) {
observer.observe(cardElement, {attributeFilter: ["class"]});
}
}
} else {
initFlowchart(flowchartElements);
}

View file

@ -41,15 +41,19 @@ export const mermaidRender = (element: Element, cdn = Constants.PROTYLE_CDN) =>
}
window.mermaid.initialize(config);
if (mermaidElements[0].firstElementChild.clientWidth === 0) {
const hideElement = hasClosestByAttribute(mermaidElements[0], "fold", "1");
if (!hideElement) {
return;
}
const observer = new MutationObserver(() => {
initMermaid(mermaidElements);
observer.disconnect();
});
observer.observe(hideElement, {attributeFilter: ["fold"]});
const hideElement = hasClosestByAttribute(mermaidElements[0], "fold", "1");
if (hideElement) {
observer.observe(hideElement, {attributeFilter: ["fold"]});
} else {
const cardElement = hasClosestByClassName(mermaidElements[0], "card__block", true);
if (cardElement) {
observer.observe(cardElement, {attributeFilter: ["class"]});
}
}
} else {
initMermaid(mermaidElements);
}

View file

@ -15,19 +15,11 @@ export const mindmapRender = (element: Element, cdn = Constants.PROTYLE_CDN) =>
return;
}
addScript(`${cdn}/js/echarts/echarts.min.js?v=0.0.0`, "protyleEchartsScript").then(() => {
let width: number = undefined;
if (mindmapElements[0].firstElementChild.clientWidth === 0) {
const tabElement = hasClosestByClassName(mindmapElements[0], "layout-tab-container", true);
if (tabElement) {
Array.from(tabElement.children).find(item => {
if (item.classList.contains("protyle") && !item.classList.contains("fn__none") && item.querySelector(".protyle-wysiwyg").firstElementChild) {
width = item.querySelector(".protyle-wysiwyg").firstElementChild.clientWidth;
return true;
}
});
}
}
const wysiswgElement = hasClosestByClassName(element, "protyle-wysiwyg", true);
let width: number = undefined;
if (wysiswgElement && wysiswgElement.clientWidth > 0 && mindmapElements[0].firstElementChild.clientWidth === 0 && wysiswgElement.firstElementChild) {
width = wysiswgElement.firstElementChild.clientWidth;
}
mindmapElements.forEach((e: HTMLDivElement) => {
if (e.getAttribute("data-render") === "true") {
return;