Skip to content

Commit

Permalink
Merge pull request #4528 from Yokozuna59/bug/4527_fix-optional-style-…
Browse files Browse the repository at this point in the history
…issue

fix not rendered style when style is optional
  • Loading branch information
sidharthv96 committed Jun 27, 2023
2 parents 5baeda0 + 64a28be commit 2bec827
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
5 changes: 1 addition & 4 deletions packages/mermaid/src/diagram-api/diagramAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import { addStylesForDiagram } from '../styles.js';
import { DiagramDefinition, DiagramDetector } from './types.js';
import * as _commonDb from '../commonDb.js';
import { parseDirective as _parseDirective } from '../directiveUtils.js';
import isEmpty from 'lodash-es/isEmpty.js';

/*
Packaging and exposing resources for external diagrams so that they can import
Expand Down Expand Up @@ -51,9 +50,7 @@ export const registerDiagram = (
if (detector) {
addDetector(id, detector);
}
if (!isEmpty(diagram.styles)) {
addStylesForDiagram(id, diagram.styles);
}
addStylesForDiagram(id, diagram.styles);

if (diagram.injectUtils) {
diagram.injectUtils(
Expand Down
2 changes: 2 additions & 0 deletions packages/mermaid/src/diagram-api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,3 +82,5 @@ export type ParseDirectiveDefinition = (statement: string, context: string, type
export type HTML = d3.Selection<HTMLIFrameElement, unknown, Element, unknown>;

export type SVG = d3.Selection<SVGSVGElement, unknown, Element, unknown>;

export type DiagramStylesProvider = (options?: any) => string;
9 changes: 6 additions & 3 deletions packages/mermaid/src/styles.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import type { FlowChartStyleOptions } from './diagrams/flowchart/styles.js';
import { log } from './logger.js';
import type { DiagramStylesProvider } from './diagram-api/types.js';

const themes: Record<string, any> = {};
const themes: Record<string, DiagramStylesProvider> = {};

const getStyles = (
type: string,
Expand Down Expand Up @@ -73,8 +74,10 @@ const getStyles = (
`;
};

export const addStylesForDiagram = (type: string, diagramTheme: unknown): void => {
themes[type] = diagramTheme;
export const addStylesForDiagram = (type: string, diagramTheme?: DiagramStylesProvider): void => {
if (diagramTheme !== undefined) {
themes[type] = diagramTheme;
}
};

export default getStyles;

0 comments on commit 2bec827

Please sign in to comment.