mirror of
https://github.com/mermaid-js/mermaid.git
synced 2025-11-06 13:54:09 +01:00
feat: Add config validator MVP
This commit is contained in:
@@ -40,7 +40,8 @@ export const updateCurrentConfig = (siteCfg: MermaidConfig, _directives: any[])
|
|||||||
}
|
}
|
||||||
|
|
||||||
currentConfig = cfg;
|
currentConfig = cfg;
|
||||||
return cfg;
|
checkConfig(currentConfig);
|
||||||
|
return currentConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -68,7 +69,7 @@ export const setSiteConfig = (conf: MermaidConfig): MermaidConfig => {
|
|||||||
siteConfig.themeVariables = theme[conf.theme].getThemeVariables(conf.themeVariables);
|
siteConfig.themeVariables = theme[conf.theme].getThemeVariables(conf.themeVariables);
|
||||||
}
|
}
|
||||||
|
|
||||||
currentConfig = updateCurrentConfig(siteConfig, directives);
|
updateCurrentConfig(siteConfig, directives);
|
||||||
return siteConfig;
|
return siteConfig;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -117,6 +118,7 @@ export const setConfig = (conf: MermaidConfig): MermaidConfig => {
|
|||||||
// conf[key] = manipulator ? manipulator(conf[key]) : conf[key];
|
// conf[key] = manipulator ? manipulator(conf[key]) : conf[key];
|
||||||
// });
|
// });
|
||||||
|
|
||||||
|
checkConfig(conf);
|
||||||
assignWithDepth(currentConfig, conf);
|
assignWithDepth(currentConfig, conf);
|
||||||
|
|
||||||
return getConfig();
|
return getConfig();
|
||||||
@@ -224,3 +226,25 @@ export const reset = (config = siteConfig): void => {
|
|||||||
directives = [];
|
directives = [];
|
||||||
updateCurrentConfig(config, directives);
|
updateCurrentConfig(config, directives);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum ConfigWarning {
|
||||||
|
'LAZY_LOAD_DEPRECATED' = 'The configuration options lazyLoadedDiagrams and loadExternalDiagramsAtStartup are deprecated. Please use registerExternalDiagrams instead.',
|
||||||
|
}
|
||||||
|
type ConfigWarningStrings = keyof typeof ConfigWarning;
|
||||||
|
const issuedWarnings: { [key in ConfigWarningStrings]?: boolean } = {};
|
||||||
|
const issueWarning = (warning: ConfigWarningStrings) => {
|
||||||
|
if (issuedWarnings[warning]) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
log.warn(ConfigWarning[warning]);
|
||||||
|
issuedWarnings[warning] = true;
|
||||||
|
};
|
||||||
|
|
||||||
|
const checkConfig = (config: MermaidConfig) => {
|
||||||
|
if (!config) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (config.lazyLoadedDiagrams || config.loadExternalDiagramsAtStartup) {
|
||||||
|
issueWarning('LAZY_LOAD_DEPRECATED');
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|||||||
@@ -3,6 +3,10 @@
|
|||||||
import DOMPurify from 'dompurify';
|
import DOMPurify from 'dompurify';
|
||||||
|
|
||||||
export interface MermaidConfig {
|
export interface MermaidConfig {
|
||||||
|
/** @deprecated use mermaid.registerLazyDiagrams instead */
|
||||||
|
lazyLoadedDiagrams?: string[];
|
||||||
|
/** @deprecated use mermaid.registerLazyDiagrams instead */
|
||||||
|
loadExternalDiagramsAtStartup?: boolean;
|
||||||
theme?: string;
|
theme?: string;
|
||||||
themeVariables?: any;
|
themeVariables?: any;
|
||||||
themeCSS?: string;
|
themeCSS?: string;
|
||||||
|
|||||||
Reference in New Issue
Block a user