mirror of
https://github.com/mermaid-js/mermaid.git
synced 2024-08-28 21:16:07 +02:00
chore(split): Error
This commit is contained in:
parent
0b4c6f6477
commit
fa51121f29
3 changed files with 43 additions and 27 deletions
|
@ -1,4 +1,3 @@
|
|||
import { registerDiagram } from './diagramAPI';
|
||||
import c4 from '../diagrams/c4/c4Detector';
|
||||
import flowchart from '../diagrams/flowchart/flowDetector';
|
||||
import flowchartV2 from '../diagrams/flowchart/flowDetector-v2';
|
||||
|
@ -14,9 +13,7 @@ import classDiagramV2 from '../diagrams/class/classDetector-V2';
|
|||
import state from '../diagrams/state/stateDetector';
|
||||
import stateV2 from '../diagrams/state/stateDetector-V2';
|
||||
import journey from '../diagrams/user-journey/journeyDetector';
|
||||
|
||||
import errorRenderer from '../diagrams/error/errorRenderer';
|
||||
import errorStyles from '../diagrams/error/styles';
|
||||
import error from '../diagrams/error/errorDetector';
|
||||
import { addDiagram } from './detectType';
|
||||
|
||||
let hasLoadedDiagrams = false;
|
||||
|
@ -27,29 +24,7 @@ export const addDiagrams = () => {
|
|||
// This is added here to avoid race-conditions.
|
||||
// We could optimize the loading logic somehow.
|
||||
hasLoadedDiagrams = true;
|
||||
registerDiagram(
|
||||
'error',
|
||||
// Special diagram with error messages but setup as a regular diagram
|
||||
{
|
||||
db: {
|
||||
clear: () => {
|
||||
// Quite ok, clear needs to be there for error to work as a regular diagram
|
||||
},
|
||||
},
|
||||
styles: errorStyles,
|
||||
renderer: errorRenderer,
|
||||
parser: {
|
||||
parser: { yy: {} },
|
||||
parse: () => {
|
||||
// no op
|
||||
},
|
||||
},
|
||||
init: () => {
|
||||
// no op
|
||||
},
|
||||
},
|
||||
(text) => text.toLowerCase().trim() === 'error'
|
||||
);
|
||||
addDiagram(error);
|
||||
addDiagram(c4);
|
||||
addDiagram(classDiagram);
|
||||
addDiagram(classDiagramV2);
|
||||
|
|
20
packages/mermaid/src/diagrams/error/errorDetector.ts
Normal file
20
packages/mermaid/src/diagrams/error/errorDetector.ts
Normal file
|
@ -0,0 +1,20 @@
|
|||
import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-api/types';
|
||||
|
||||
const id = 'error';
|
||||
|
||||
const detector: DiagramDetector = (text) => {
|
||||
return text.toLowerCase().trim() === 'error';
|
||||
};
|
||||
|
||||
const loader = async () => {
|
||||
const { diagram } = await import('./errorDiagram');
|
||||
return { id, diagram };
|
||||
};
|
||||
|
||||
const plugin: ExternalDiagramDefinition = {
|
||||
id,
|
||||
detector,
|
||||
loader,
|
||||
};
|
||||
|
||||
export default plugin;
|
21
packages/mermaid/src/diagrams/error/errorDiagram.ts
Normal file
21
packages/mermaid/src/diagrams/error/errorDiagram.ts
Normal file
|
@ -0,0 +1,21 @@
|
|||
import { DiagramDefinition } from '../../diagram-api/types';
|
||||
import styles from './styles';
|
||||
import renderer from './errorRenderer';
|
||||
export const diagram: DiagramDefinition = {
|
||||
db: {
|
||||
clear: () => {
|
||||
// Quite ok, clear needs to be there for error to work as a regular diagram
|
||||
},
|
||||
},
|
||||
styles,
|
||||
renderer,
|
||||
parser: {
|
||||
parser: { yy: {} },
|
||||
parse: () => {
|
||||
// no op
|
||||
},
|
||||
},
|
||||
init: () => {
|
||||
// no op
|
||||
},
|
||||
};
|
Loading…
Reference in a new issue