Add MermaidConfigWithDefaults

This commit is contained in:
Sidharth Vinod
2024-01-28 16:02:28 +05:30
parent f30c26485e
commit ba0bddf417
3 changed files with 7 additions and 3 deletions

View File

@@ -2,7 +2,7 @@ import assignWithDepth from './assignWithDepth.js';
import { log } from './logger.js'; import { log } from './logger.js';
import theme from './themes/index.js'; import theme from './themes/index.js';
import config from './defaultConfig.js'; import config from './defaultConfig.js';
import type { MermaidConfig } from './config.type.js'; import type { MermaidConfig, MermaidConfigWithDefaults } from './config.type.js';
import { sanitizeDirective } from './utils/sanitizeDirective.js'; import { sanitizeDirective } from './utils/sanitizeDirective.js';
export const defaultConfig: MermaidConfig = Object.freeze(config); export const defaultConfig: MermaidConfig = Object.freeze(config);
@@ -128,7 +128,7 @@ export const setConfig = (conf: MermaidConfig): MermaidConfig => {
* *
* @returns The currentConfig * @returns The currentConfig
*/ */
export const getConfig = (): MermaidConfig => { export const getConfig = (): MermaidConfigWithDefaults => {
return assignWithDepth({}, currentConfig); return assignWithDepth({}, currentConfig);
}; };
/** /**

View File

@@ -5,6 +5,8 @@
* and run json-schema-to-typescript to regenerate this file. * and run json-schema-to-typescript to regenerate this file.
*/ */
import { RequiredDeep } from 'type-fest';
/** /**
* Configuration options to pass to the `dompurify` library. * Configuration options to pass to the `dompurify` library.
*/ */
@@ -165,6 +167,9 @@ export interface MermaidConfig {
wrap?: boolean; wrap?: boolean;
fontSize?: number; fontSize?: number;
} }
// I'd prefer this to be named MermaidConfig, so all the functions can use the shorter name.
export type MermaidConfigWithDefaults = RequiredDeep<MermaidConfig>;
/** /**
* This interface was referenced by `MermaidConfig`'s JSON-Schema * This interface was referenced by `MermaidConfig`'s JSON-Schema
* via the `definition` "BaseDiagramConfig". * via the `definition` "BaseDiagramConfig".

View File

@@ -1,6 +1,5 @@
import type { Diagram } from '../../Diagram.js'; import type { Diagram } from '../../Diagram.js';
import { getConfig, defaultConfig } from '../../diagram-api/diagramAPI.js'; import { getConfig, defaultConfig } from '../../diagram-api/diagramAPI.js';
import { import {
select as d3select, select as d3select,
scaleOrdinal as d3scaleOrdinal, scaleOrdinal as d3scaleOrdinal,