Deoupling, inecting mermaid utilities in external diagram

This commit is contained in:
Knut Sveidqvist 2022-09-26 08:02:12 +02:00
parent 9566f51ca8
commit 98ddc95648
3 changed files with 11 additions and 5 deletions

View File

@ -20,6 +20,7 @@ export class Diagram {
this.db.clear?.(); this.db.clear?.();
this.renderer = diagram.renderer; this.renderer = diagram.renderer;
this.parser = diagram.parser; this.parser = diagram.parser;
console.log('Setting db to !', this.db);
this.parser.parser.yy = this.db; this.parser.parser.yy = this.db;
if (diagram.init) { if (diagram.init) {
diagram.init(cnf); diagram.init(cnf);

View File

@ -1,5 +1,5 @@
import { detectType } from './detectType'; import { detectType, DiagramDetector } from './detectType';
import { getDiagram, registerDiagram } from './diagramAPI'; import { getDiagram, registerDiagram, registerDetector } from './diagramAPI';
import { addDiagrams } from './diagram-orchestration'; import { addDiagrams } from './diagram-orchestration';
addDiagrams(); addDiagrams();
@ -16,6 +16,10 @@ describe('DiagramAPI', () => {
it('should handle diagram registrations', () => { it('should handle diagram registrations', () => {
expect(() => getDiagram('loki')).toThrow(); expect(() => getDiagram('loki')).toThrow();
expect(() => detectType('loki diagram')).not.toThrow(); // TODO: #3391 expect(() => detectType('loki diagram')).not.toThrow(); // TODO: #3391
const detector: DiagramDetector = (str: string) => {
return str.match('loki') !== null;
};
registerDetector('loki', detector);
registerDiagram( registerDiagram(
'loki', 'loki',
{ {

View File

@ -1795,13 +1795,14 @@ describe('when rendering a sequenceDiagram with directives', function () {
diagram.renderer.bounds.init(); diagram.renderer.bounds.init();
}); });
it('should handle one actor, when theme is dark and logLevel is 1 DX1', function () { it('should handle one actor, when theme is dark and logLevel is 1 DX1 (dfg1)', function () {
const str = ` const str = `
%%{init: { "theme": "dark", "logLevel": 1 } }%% %%{init: { "theme": "dark", "logLevel": 1 } }%%
sequenceDiagram sequenceDiagram
%%{wrap}%% %%{wrap}%%
participant Alice participant Alice
`; `;
diagram = new Diagram(str);
diagram.renderer.bounds.init(); diagram.renderer.bounds.init();
mermaidAPI.parse(str); mermaidAPI.parse(str);
@ -1819,14 +1820,14 @@ participant Alice
models.lastActor().y + models.lastActor().height + mermaid.sequence.boxMargin models.lastActor().y + models.lastActor().height + mermaid.sequence.boxMargin
); );
}); });
it('should handle one actor, when logLevel is 3', function () { it('should handle one actor, when logLevel is 3 (dfg0)', function () {
const str = ` const str = `
%%{initialize: { "logLevel": 3 }}%% %%{initialize: { "logLevel": 3 }}%%
sequenceDiagram sequenceDiagram
participant Alice participant Alice
`; `;
mermaidAPI.parse(str); // diagram.parse(str);
diagram.renderer.draw(str, 'tst', '1.2.3', diagram); diagram.renderer.draw(str, 'tst', '1.2.3', diagram);
const { bounds, models } = diagram.renderer.bounds.getBounds(); const { bounds, models } = diagram.renderer.bounds.getBounds();