#1874 Protecting the original configuration

This commit is contained in:
Knut Sveidqvist
2021-01-27 22:23:33 +01:00
parent 2e5771b9e8
commit 177cd30854
6 changed files with 43 additions and 19 deletions

View File

@@ -8,7 +8,7 @@ import config from './defaultConfig';
export const defaultConfig = Object.freeze(config);
let siteConfig = assignWithDepth({}, defaultConfig);
let siteConfigDelta;
let configFromInitialize;
let directives = [];
let currentConfig = assignWithDepth({}, defaultConfig);
@@ -30,20 +30,14 @@ export const updateCurrentConfig = (siteCfg, _directives) => {
cfg = assignWithDepth(cfg, sumOfDirectives);
if (sumOfDirectives.theme) {
const tmpConfigFromInitialize = assignWithDepth({}, configFromInitialize);
const themeVariables = assignWithDepth(
siteConfigDelta.themeVariables || {},
tmpConfigFromInitialize.themeVariables || {},
sumOfDirectives.themeVariables
);
cfg.themeVariables = theme[cfg.theme].getThemeVariables(themeVariables);
}
// if (cfg.theme && theme[cfg.theme]) {
// let tVars = assignWithDepth({}, cfg.themeVariables);
// tVars = assignWithDepth(tVars, themeVariables);
// const variables = theme[cfg.theme].getThemeVariables(tVars);
// cfg.themeVariables = variables;
// }
currentConfig = cfg;
return cfg;
};
@@ -73,9 +67,10 @@ export const setSiteConfig = conf => {
return siteConfig;
};
export const setSiteConfigDelta = conf => {
siteConfigDelta = assignWithDepth({}, conf);
export const saveConfigFromInitilize = conf => {
configFromInitialize = assignWithDepth({}, conf);
};
export const updateSiteConfig = conf => {
siteConfig = assignWithDepth(siteConfig, conf);
updateCurrentConfig(siteConfig, directives);

View File

@@ -69,6 +69,9 @@ const getStyles = options =>
.cluster span {
color: ${options.titleColor};
}
.cluster div {
color: ${options.titleColor};
}
div.mermaidTooltip {
position: absolute;

View File

@@ -223,12 +223,6 @@ const render = function(id, _txt, cb, container) {
// console.warn('Render fetching config');
const cnf = configApi.getConfig();
// console.warn('Render with config after adding new directives', cnf.sequence);
// console.warn(
// 'Render with config after adding new directives',
// cnf.fontFamily,
// cnf.themeVariables.fontFamily
// );
// Check the maximum allowed text size
if (_txt.length > cnf.maxTextSize) {
txt = 'graph TB;a[Maximum text size in diagram exceeded];style a fill:#faa';
@@ -577,7 +571,7 @@ function initialize(options) {
}
}
// Set default options
configApi.setSiteConfigDelta(options);
configApi.saveConfigFromInitilize(options);
if (options && options.theme && theme[options.theme]) {
// Todo merge with user options

View File

@@ -65,6 +65,7 @@ const getStyles = (type, userStyles, options) => {
.marker {
fill: ${options.lineColor};
stroke: ${options.lineColor};
}
.marker.cross {
stroke: ${options.lineColor};