|
@@ -1,8 +1,5 @@
|
|
|
import mermaid from "mermaid";
|
|
|
|
|
|
-let is_running = false;
|
|
|
-const queue = [];
|
|
|
-
|
|
|
export default {
|
|
|
template: `<div></div>`,
|
|
|
data: () => ({
|
|
@@ -24,20 +21,18 @@ export default {
|
|
|
async update(content) {
|
|
|
if (this.last_content === content) return;
|
|
|
this.last_content = content;
|
|
|
- this.$el.innerHTML = content;
|
|
|
- this.$el.removeAttribute("data-processed");
|
|
|
- queue.push(this.$el);
|
|
|
- if (is_running) return;
|
|
|
- is_running = true;
|
|
|
- while (queue.length) {
|
|
|
- try {
|
|
|
- await mermaid.run({ nodes: [queue.shift()] });
|
|
|
- } catch (error) {
|
|
|
- console.error(error);
|
|
|
- this.$emit("error", error);
|
|
|
- }
|
|
|
+ try {
|
|
|
+ const { svg, bindFunctions } = await mermaid.render(this.$el.id + "_mermaid", content);
|
|
|
+ this.$el.innerHTML = svg;
|
|
|
+ bindFunctions?.(this.$el);
|
|
|
+ } catch (error) {
|
|
|
+ const { svg, bindFunctions } = await mermaid.render(this.$el.id + "_mermaid", "error");
|
|
|
+ this.$el.innerHTML = svg;
|
|
|
+ bindFunctions?.(this.$el);
|
|
|
+ const mermaidErrorFormat = { str: error.message, message: error.message, hash: error.name, error };
|
|
|
+ console.error(mermaidErrorFormat);
|
|
|
+ this.$emit("error", mermaidErrorFormat);
|
|
|
}
|
|
|
- is_running = false;
|
|
|
},
|
|
|
},
|
|
|
props: {
|