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.renderer = diagram.renderer;
this.parser = diagram.parser;
console.log('Setting db to !', this.db);
this.parser.parser.yy = this.db;
if (diagram.init) {
diagram.init(cnf);

View File

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

View File

@ -1795,13 +1795,14 @@ describe('when rendering a sequenceDiagram with directives', function () {
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 = `
%%{init: { "theme": "dark", "logLevel": 1 } }%%
sequenceDiagram
%%{wrap}%%
participant Alice
`;
diagram = new Diagram(str);
diagram.renderer.bounds.init();
mermaidAPI.parse(str);
@ -1819,14 +1820,14 @@ participant Alice
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 = `
%%{initialize: { "logLevel": 3 }}%%
sequenceDiagram
participant Alice
`;
mermaidAPI.parse(str);
// diagram.parse(str);
diagram.renderer.draw(str, 'tst', '1.2.3', diagram);
const { bounds, models } = diagram.renderer.bounds.getBounds();