#1542 Setting theme options as the regular options

This commit is contained in:
Knut Sveidqvist
2020-07-16 23:39:38 +02:00
parent 8c0e022b44
commit fd4240b774
17 changed files with 477 additions and 1450 deletions

View File

@@ -1,6 +1,14 @@
import { assignWithDepth } from './utils';
import { logger } from './logger';
// import themeVariables from './theme-default';
// import themeForestVariables from './theme-forest';
// import themeNeutralVariables from './theme-neutral';
const themes = {};
for (const themeName of ['default', 'forest', 'dark', 'neutral']) {
themes[themeName] = require(`./theme-${themeName}.js`).default;
}
/**
* **Configuration methods in Mermaid version 8.6.0 have been updated, to learn more[[click here](8.6.0_docs.md)].**
*
@@ -51,6 +59,7 @@ const config = {
* </pre>
*/
theme: 'default',
themeVariables: themes.default,
themeCSS: undefined,
/* **maxTextSize** - The maximum allowed size of the users text diamgram */
maxTextSize: 50000,
@@ -836,6 +845,8 @@ const config = {
useMaxWidth: true
}
};
// debugger;
config.class.arrowMarkerAbsolute = config.arrowMarkerAbsolute;
config.git.arrowMarkerAbsolute = config.arrowMarkerAbsolute;
export const defaultConfig = Object.freeze(config);
@@ -845,24 +856,30 @@ const currentConfig = assignWithDepth({}, defaultConfig);
/**
*## setSiteConfig
*| Function | Description | Type | Values |
*| --------- | ------------------- | ------- | ------------------ |
*| setSiteConfig|Sets the siteConfig to desired values | Put Request | Any Values, except ones in secure array|
***Notes:**
*Sets the siteConfig. The siteConfig is a protected configuration for repeat use. Calls to reset() will reset
*the currentConfig to siteConfig. Calls to reset(configApi.defaultConfig) will reset siteConfig and currentConfig
*to the defaultConfig
*Note: currentConfig is set in this function
**Default value: At default, will mirror Global Config**
* @param conf - the base currentConfig to use as siteConfig
* @returns {*} - the siteConfig
*/
export const setSiteConfig = conf => {
assignWithDepth(currentConfig, conf, { clobber: true });
// Set theme variables if user has set the theme option
// if (conf.theme && themes[conf.theme]) {
// conf.themeVariables = themes[conf.theme];
// }
// debugger;
assignWithDepth(siteConfig, conf);
return getSiteConfig();
};
/**
@@ -870,7 +887,7 @@ export const setSiteConfig = conf => {
*| Function | Description | Type | Values |
*| --------- | ------------------- | ------- | ------------------ |
*| setSiteConfig|Returns the current siteConfig base configuration | Get Request | Returns Any Values in siteConfig|
***Notes**:
*Returns **any** values in siteConfig.
* @returns {*}
@@ -883,8 +900,8 @@ export const getSiteConfig = () => {
*| Function | Description | Type | Values |
*| --------- | ------------------- | ------- | ------------------ |
*| setSiteConfig|Sets the siteConfig to desired values | Put Request| Any Values, except ones in secure array|
***Notes**:
*Sets the currentConfig. The parameter conf is sanitized based on the siteConfig.secure keys. Any
*values found in conf with key found in siteConfig.secure will be replaced with the corresponding
@@ -894,6 +911,10 @@ export const getSiteConfig = () => {
*/
export const setConfig = conf => {
sanitize(conf);
// if (conf.theme && themes[conf.theme]) {
// conf.themeVariables = themes[conf.theme];
// }
assignWithDepth(currentConfig, conf);
return getConfig();
};
@@ -902,7 +923,7 @@ export const setConfig = conf => {
*| Function | Description | Type | Return Values |
*| --------- | ------------------- | ------- | ------------------ |
*| getConfig |Obtains the currentConfig | Get Request | Any Values from currentConfig|
***Notes**:
*Returns **any** the currentConfig
* @returns {*} - the currentConfig
@@ -915,7 +936,7 @@ export const getConfig = () => {
*| Function | Description | Type | Values |
*| --------- | ------------------- | ------- | ------------------ |
*| sanitize |Sets the siteConfig to desired values. | Put Request |None|
*Ensures options parameter does not attempt to override siteConfig secure keys
*Note: modifies options in-place
* @param options - the potential setConfig parameter
@@ -935,7 +956,7 @@ export const sanitize = options => {
};
/**
*## reset
*| Function | Description | Type | Required | Values |
*| --------- | ------------------- | ------- | -------- | ------------------ |
*| reset|Resets currentConfig to conf| Put Request | Required | None|
@@ -951,6 +972,12 @@ export const sanitize = options => {
export const reset = (conf = getSiteConfig()) => {
Object.keys(siteConfig).forEach(key => delete siteConfig[key]);
Object.keys(currentConfig).forEach(key => delete currentConfig[key]);
// Set theme variables if user has set the theme option
// if (conf.theme && themes[conf.theme]) {
// conf.themeVariables = themes[conf.theme];
// }
// debugger;
assignWithDepth(siteConfig, conf, { clobber: true });
assignWithDepth(currentConfig, conf, { clobber: true });
};