mirror of
				https://github.com/zadam/trilium.git
				synced 2025-10-31 02:16:05 +01:00 
			
		
		
		
	refactor(mermaid): move mermaid config to service
This commit is contained in:
		| @@ -1,7 +1,26 @@ | |||||||
|  | import type { MermaidConfig } from "mermaid"; | ||||||
| import type { Mermaid } from "mermaid"; | import type { Mermaid } from "mermaid"; | ||||||
|  |  | ||||||
| let elkLoaded = false; | let elkLoaded = false; | ||||||
|  |  | ||||||
|  | export function getMermaidConfig(): MermaidConfig { | ||||||
|  |     const documentStyle = window.getComputedStyle(document.documentElement); | ||||||
|  |     const mermaidTheme = documentStyle.getPropertyValue("--mermaid-theme") as "default"; | ||||||
|  |  | ||||||
|  |     return { | ||||||
|  |         theme: mermaidTheme.trim() as "default", | ||||||
|  |         securityLevel: "antiscript", | ||||||
|  |         flowchart: { useMaxWidth: false }, | ||||||
|  |         sequence: { useMaxWidth: false }, | ||||||
|  |         gantt: { useMaxWidth: false }, | ||||||
|  |         class: { useMaxWidth: false }, | ||||||
|  |         state: { useMaxWidth: false }, | ||||||
|  |         pie: { useMaxWidth: true }, | ||||||
|  |         journey: { useMaxWidth: false }, | ||||||
|  |         gitGraph: { useMaxWidth: false } | ||||||
|  |     }; | ||||||
|  | } | ||||||
|  |  | ||||||
| /** | /** | ||||||
|  * Determines whether the ELK extension of Mermaid.js needs to be loaded (which is a relatively large library), based on the |  * Determines whether the ELK extension of Mermaid.js needs to be loaded (which is a relatively large library), based on the | ||||||
|  * front-matter of the diagram and loads the library if needed. |  * front-matter of the diagram and loads the library if needed. | ||||||
|   | |||||||
| @@ -16,7 +16,7 @@ import toast from "../../services/toast.js"; | |||||||
| import { normalizeMimeTypeForCKEditor } from "../../services/mime_type_definitions.js"; | import { normalizeMimeTypeForCKEditor } from "../../services/mime_type_definitions.js"; | ||||||
| import { buildConfig, buildToolbarConfig } from "./ckeditor/config.js"; | import { buildConfig, buildToolbarConfig } from "./ckeditor/config.js"; | ||||||
| import type FNote from "../../entities/fnote.js"; | import type FNote from "../../entities/fnote.js"; | ||||||
| import { getMermaidConfig } from "./mermaid.js"; | import { getMermaidConfig } from "../../services/mermaid.js"; | ||||||
|  |  | ||||||
| const ENABLE_INSPECTOR = false; | const ENABLE_INSPECTOR = false; | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,5 +1,4 @@ | |||||||
| import type { MermaidConfig } from "mermaid"; | import { getMermaidConfig, loadElkIfNeeded, postprocessMermaidSvg } from "../../services/mermaid.js"; | ||||||
| import { loadElkIfNeeded, postprocessMermaidSvg } from "../../services/mermaid.js"; |  | ||||||
| import AbstractSvgSplitTypeWidget from "./abstract_svg_split_type_widget.js"; | import AbstractSvgSplitTypeWidget from "./abstract_svg_split_type_widget.js"; | ||||||
|  |  | ||||||
| let idCounter = 1; | let idCounter = 1; | ||||||
| @@ -34,22 +33,3 @@ export class MermaidTypeWidget extends AbstractSvgSplitTypeWidget { | |||||||
|     } |     } | ||||||
|  |  | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| export function getMermaidConfig(): MermaidConfig { |  | ||||||
|     const documentStyle = window.getComputedStyle(document.documentElement); |  | ||||||
|     const mermaidTheme = documentStyle.getPropertyValue("--mermaid-theme") as "default"; |  | ||||||
|  |  | ||||||
|     return { |  | ||||||
|         theme: mermaidTheme.trim() as "default", |  | ||||||
|         securityLevel: "antiscript", |  | ||||||
|         flowchart: { useMaxWidth: false }, |  | ||||||
|         sequence: { useMaxWidth: false }, |  | ||||||
|         gantt: { useMaxWidth: false }, |  | ||||||
|         class: { useMaxWidth: false }, |  | ||||||
|         state: { useMaxWidth: false }, |  | ||||||
|         pie: { useMaxWidth: true }, |  | ||||||
|         journey: { useMaxWidth: false }, |  | ||||||
|         gitGraph: { useMaxWidth: false } |  | ||||||
|     }; |  | ||||||
| } |  | ||||||
|   | |||||||
| @@ -4,7 +4,7 @@ import { applySyntaxHighlight } from "../../services/syntax_highlight.js"; | |||||||
| import type FNote from "../../entities/fnote.js"; | import type FNote from "../../entities/fnote.js"; | ||||||
| import type { EventData } from "../../components/app_context.js"; | import type { EventData } from "../../components/app_context.js"; | ||||||
| import { getLocaleById } from "../../services/i18n.js"; | import { getLocaleById } from "../../services/i18n.js"; | ||||||
| import { getMermaidConfig } from "./mermaid.js"; | import { getMermaidConfig } from "../../services/mermaid.js"; | ||||||
|  |  | ||||||
| const TPL = ` | const TPL = ` | ||||||
| <div class="note-detail-readonly-text note-detail-printable"> | <div class="note-detail-readonly-text note-detail-printable"> | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user