chore(split): classDiagram

This commit is contained in:
Sidharth Vinod 2022-11-18 16:09:36 +05:30
parent 5dec9eb2f5
commit 4492c5ed4e
No known key found for this signature in database
GPG Key ID: FB5CCD378D3907CD
4 changed files with 74 additions and 4 deletions

View File

@ -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;

View File

@ -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;

View 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();
},
};

View 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();
},
};