Skip to content

Commit

Permalink
refactor: Move setWrap to individual diagrams as necessary.
Browse files Browse the repository at this point in the history
  • Loading branch information
sidharthv96 committed Aug 26, 2023
1 parent 04ce5d6 commit 066e096
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 15 deletions.
5 changes: 1 addition & 4 deletions packages/mermaid/src/Diagram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,10 @@ export class Diagram {
this.db.clear?.();
const config = configApi.getConfig();
this.init?.(config);
// These 2 blocks were added for legacy compatibility. Do not add more such blocks. Use frontmatter instead.
// This block was added for legacy compatibility. Use frontmatter instead of adding more special cases.
if (this.metadata.title) {
this.db.setDiagramTitle?.(this.metadata.title);
}
if (config.wrap) {
this.db.setWrap?.(config.wrap);
}
this.parser.parse(this.text);
}

Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagram-api/types.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import type { Diagram } from '../Diagram.js';
import type { BaseDiagramConfig, MermaidConfig } from '../config.type.js';
import type * as d3 from 'd3';
Expand Down Expand Up @@ -29,7 +30,6 @@ export interface DiagramDB {
getAccDescription?: () => string;

setDisplayMode?: (title: string) => void;
setWrap?: (wrap: boolean) => void;
bindFunctions?: (element: Element) => void;
}

Expand Down
21 changes: 11 additions & 10 deletions packages/mermaid/src/diagrams/c4/c4Diagram.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
// @ts-ignore: JISON doesn't support types
import c4Parser from './parser/c4Diagram.jison';
import c4Db from './c4Db.js';
import c4Renderer from './c4Renderer.js';
import c4Styles from './styles.js';
import parser from './parser/c4Diagram.jison';
import db from './c4Db.js';
import renderer from './c4Renderer.js';
import styles from './styles.js';
import type { MermaidConfig } from '../../config.type.js';
import type { DiagramDefinition } from '../../diagram-api/types.js';

export const diagram: DiagramDefinition = {
parser: c4Parser,
db: c4Db,
renderer: c4Renderer,
styles: c4Styles,
init: (cnf: MermaidConfig) => {
c4Renderer.setConf(cnf.c4);
parser,
db,
renderer,
styles,
init: ({ c4, wrap }: MermaidConfig) => {
renderer.setConf(c4);
db.setWrap(wrap);
},
};
3 changes: 3 additions & 0 deletions packages/mermaid/src/diagrams/sequence/sequenceDiagram.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ export const diagram: DiagramDefinition = {
db,
renderer,
styles,
init: ({ wrap }) => {
db.setWrap(wrap);
},
};

0 comments on commit 066e096

Please sign in to comment.