mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-01-14 06:43:25 +08:00
chore(split): classDiagram
This commit is contained in:
parent
5dec9eb2f5
commit
4492c5ed4e
@ -1,9 +1,24 @@
|
|||||||
import type { DiagramDetector } from '../../diagram-api/types';
|
import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-api/types';
|
||||||
|
|
||||||
export const classDetectorV2: DiagramDetector = (txt, config) => {
|
const id = 'classDiagram';
|
||||||
|
|
||||||
|
const detector: DiagramDetector = (txt, config) => {
|
||||||
// If we have confgured to use dagre-wrapper then we should return true in this function for classDiagram code thus making it use the new class diagram
|
// If we have confgured to use dagre-wrapper then we should return true in this function for classDiagram code thus making it use the new class diagram
|
||||||
if (txt.match(/^\s*classDiagram/) !== null && config?.class?.defaultRenderer === 'dagre-wrapper')
|
if (txt.match(/^\s*classDiagram/) !== null && config?.class?.defaultRenderer === 'dagre-wrapper')
|
||||||
return true;
|
return true;
|
||||||
// We have not opted to use the new renderer so we should return true if we detect a class diagram
|
// We have not opted to use the new renderer so we should return true if we detect a class diagram
|
||||||
return txt.match(/^\s*classDiagram-v2/) !== null;
|
return txt.match(/^\s*classDiagram-v2/) !== null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const loader = async () => {
|
||||||
|
const { diagram } = await import('./classDiagram-v2');
|
||||||
|
return { id, diagram };
|
||||||
|
};
|
||||||
|
|
||||||
|
const plugin: ExternalDiagramDefinition = {
|
||||||
|
id,
|
||||||
|
detector,
|
||||||
|
loader,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default plugin;
|
||||||
|
@ -1,8 +1,23 @@
|
|||||||
import type { DiagramDetector } from '../../diagram-api/types';
|
import type { DiagramDetector, ExternalDiagramDefinition } from '../../diagram-api/types';
|
||||||
|
|
||||||
export const classDetector: DiagramDetector = (txt, config) => {
|
const id = 'class';
|
||||||
|
|
||||||
|
const detector: DiagramDetector = (txt, config) => {
|
||||||
// If we have confgured to use dagre-wrapper then we should never return true in this function
|
// If we have confgured to use dagre-wrapper then we should never return true in this function
|
||||||
if (config?.class?.defaultRenderer === 'dagre-wrapper') return false;
|
if (config?.class?.defaultRenderer === 'dagre-wrapper') return false;
|
||||||
// We have not opted to use the new renderer so we should return true if we detect a class diagram
|
// We have not opted to use the new renderer so we should return true if we detect a class diagram
|
||||||
return txt.match(/^\s*classDiagram/) !== null;
|
return txt.match(/^\s*classDiagram/) !== null;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const loader = async () => {
|
||||||
|
const { diagram } = await import('./classDiagram');
|
||||||
|
return { id, diagram };
|
||||||
|
};
|
||||||
|
|
||||||
|
const plugin: ExternalDiagramDefinition = {
|
||||||
|
id,
|
||||||
|
detector,
|
||||||
|
loader,
|
||||||
|
};
|
||||||
|
|
||||||
|
export default plugin;
|
||||||
|
20
packages/mermaid/src/diagrams/class/classDiagram-v2.ts
Normal file
20
packages/mermaid/src/diagrams/class/classDiagram-v2.ts
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import { DiagramDefinition } from '../../diagram-api/types';
|
||||||
|
// @ts-ignore: TODO Fix ts errors
|
||||||
|
import parser from './parser/classDiagram';
|
||||||
|
import db from './classDb';
|
||||||
|
import styles from './styles';
|
||||||
|
import renderer from './classRenderer-v2';
|
||||||
|
|
||||||
|
export const diagram: DiagramDefinition = {
|
||||||
|
parser,
|
||||||
|
db,
|
||||||
|
renderer,
|
||||||
|
styles,
|
||||||
|
init: (cnf) => {
|
||||||
|
if (!cnf.class) {
|
||||||
|
cnf.class = {};
|
||||||
|
}
|
||||||
|
cnf.class.arrowMarkerAbsolute = cnf.arrowMarkerAbsolute;
|
||||||
|
db.clear();
|
||||||
|
},
|
||||||
|
};
|
20
packages/mermaid/src/diagrams/class/classDiagram.ts
Normal file
20
packages/mermaid/src/diagrams/class/classDiagram.ts
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
import { DiagramDefinition } from '../../diagram-api/types';
|
||||||
|
// @ts-ignore: TODO Fix ts errors
|
||||||
|
import parser from './parser/classDiagram';
|
||||||
|
import db from './classDb';
|
||||||
|
import styles from './styles';
|
||||||
|
import renderer from './classRenderer';
|
||||||
|
|
||||||
|
export const diagram: DiagramDefinition = {
|
||||||
|
parser,
|
||||||
|
db,
|
||||||
|
renderer,
|
||||||
|
styles,
|
||||||
|
init: (cnf) => {
|
||||||
|
if (!cnf.class) {
|
||||||
|
cnf.class = {};
|
||||||
|
}
|
||||||
|
cnf.class.arrowMarkerAbsolute = cnf.arrowMarkerAbsolute;
|
||||||
|
db.clear();
|
||||||
|
},
|
||||||
|
};
|
Loading…
x
Reference in New Issue
Block a user