Skip to content

Commit

Permalink
Merge pull request #4889 from dreathed/bug/4345_bundle_current_config…
Browse files Browse the repository at this point in the history
…_consitently_in_one_file

making consitent config imports from diagramAPI
  • Loading branch information
aloisklink authored Oct 15, 2023
2 parents df068db + 497ffde commit d04f4c2
Show file tree
Hide file tree
Showing 46 changed files with 114 additions and 113 deletions.
2 changes: 1 addition & 1 deletion packages/mermaid/src/dagre-wrapper/clusters.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { log } from '../logger.js';
import createLabel from './createLabel.js';
import { createText } from '../rendering-util/createText.js';
import { select } from 'd3';
import { getConfig } from '../config.js';
import { getConfig } from '../diagram-api/diagramAPI.js';
import { evaluate } from '../diagrams/common/common.js';

const rect = (parent, node) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/dagre-wrapper/createLabel.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { select } from 'd3';
import { log } from '../logger.js';
import { getConfig } from '../config.js';
import { getConfig } from '../diagram-api/diagramAPI.js';
import { evaluate } from '../diagrams/common/common.js';
import { decodeEntities } from '../mermaidAPI.js';

Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/dagre-wrapper/edges.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { log } from '../logger.js';
import createLabel from './createLabel.js';
import { createText } from '../rendering-util/createText.js';
import { line, curveBasis, select } from 'd3';
import { getConfig } from '../config.js';
import { getConfig } from '../diagram-api/diagramAPI.js';
import utils from '../utils.js';
import { evaluate } from '../diagrams/common/common.js';
import { getLineFunctionsWithOffset } from '../utils/lineWithOffset.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/dagre-wrapper/nodes.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { select } from 'd3';
import { log } from '../logger.js';
import { labelHelper, updateNodeBounds, insertPolygonShape } from './shapes/util.js';
import { getConfig } from '../config.js';
import { getConfig } from '../diagram-api/diagramAPI.js';
import intersect from './intersect/index.js';
import createLabel from './createLabel.js';
import note from './shapes/note.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/dagre-wrapper/shapes/note.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { updateNodeBounds, labelHelper } from './util.js';
import { log } from '../../logger.js';
import { getConfig } from '../../config.js';
import { getConfig } from '../../diagram-api/diagramAPI.js';
import intersect from '../intersect/index.js';

const note = async (parent, node) => {
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/dagre-wrapper/shapes/util.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import createLabel from '../createLabel.js';
import { createText } from '../../rendering-util/createText.js';
import { getConfig } from '../../config.js';
import { getConfig } from '../../diagram-api/diagramAPI.js';
import { decodeEntities } from '../../mermaidAPI.js';
import { select } from 'd3';
import { evaluate, sanitizeText } from '../../diagrams/common/common.js';
Expand Down
10 changes: 9 additions & 1 deletion packages/mermaid/src/diagram-api/diagramAPI.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { addDetector } from './detectType.js';
import { log as _log, setLogLevel as _setLogLevel } from '../logger.js';
import { getConfig as _getConfig } from '../config.js';
import {
getConfig as _getConfig,
setConfig as _setConfig,
defaultConfig as _defaultConfig,
setSiteConfig as _setSiteConfig,
} from '../config.js';
import { sanitizeText as _sanitizeText } from '../diagrams/common/common.js';
import { setupGraphViewbox as _setupGraphViewbox } from '../setupGraphViewbox.js';
import { addStylesForDiagram } from '../styles.js';
Expand All @@ -15,6 +20,9 @@ import * as _commonDb from '../diagrams/common/commonDb.js';
export const log = _log;
export const setLogLevel = _setLogLevel;
export const getConfig = _getConfig;
export const setConfig = _setConfig;
export const defaultConfig = _defaultConfig;
export const setSiteConfig = _setSiteConfig;
export const sanitizeText = (text: string) => _sanitizeText(text, getConfig());
export const setupGraphViewbox = _setupGraphViewbox;
export const getCommonDb = () => {
Expand Down
8 changes: 4 additions & 4 deletions packages/mermaid/src/diagrams/c4/c4Db.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import * as configApi from '../../config.js';
import { getConfig } from '../../diagram-api/diagramAPI.js';
import { sanitizeText } from '../common/common.js';
import {
setAccTitle,
Expand Down Expand Up @@ -33,7 +33,7 @@ export const getC4Type = function () {
};

export const setC4Type = function (c4TypeParam) {
let sanitizedText = sanitizeText(c4TypeParam, configApi.getConfig());
let sanitizedText = sanitizeText(c4TypeParam, getConfig());
c4Type = sanitizedText;
};

Expand Down Expand Up @@ -783,7 +783,7 @@ export const PLACEMENT = {
};

export const setTitle = function (txt) {
let sanitizedText = sanitizeText(txt, configApi.getConfig());
let sanitizedText = sanitizeText(txt, getConfig());
title = sanitizedText;
};

Expand Down Expand Up @@ -816,7 +816,7 @@ export default {
getAccTitle,
getAccDescription,
setAccDescription,
getConfig: () => configApi.getConfig().c4,
getConfig: () => getConfig().c4,
clear,
LINETYPE,
ARROWTYPE,
Expand Down
6 changes: 3 additions & 3 deletions packages/mermaid/src/diagrams/c4/c4Renderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { log } from '../../logger.js';
import { parser } from './parser/c4Diagram.jison';
import common from '../common/common.js';
import c4Db from './c4Db.js';
import * as configApi from '../../config.js';
import { getConfig } from '../../diagram-api/diagramAPI.js';
import assignWithDepth from '../../assignWithDepth.js';
import { wrapLabel, calculateTextWidth, calculateTextHeight } from '../../utils.js';
import { configureSvgSize } from '../../setupGraphViewbox.js';
Expand Down Expand Up @@ -580,8 +580,8 @@ function drawInsideBoundary(
* @param diagObj
*/
export const draw = function (_text, id, _version, diagObj) {
conf = configApi.getConfig().c4;
const securityLevel = configApi.getConfig().securityLevel;
conf = getConfig().c4;
const securityLevel = getConfig().securityLevel;
// Handle root and Document for when rendering in sandbox mode
let sandboxElement;
if (securityLevel === 'sandbox') {
Expand Down
32 changes: 13 additions & 19 deletions packages/mermaid/src/diagrams/class/classDb.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import type { Selection } from 'd3';
import { select } from 'd3';
import { log } from '../../logger.js';
import * as configApi from '../../config.js';
import { getConfig } from '../../diagram-api/diagramAPI.js';
import common from '../common/common.js';
import utils from '../../utils.js';
import {
Expand Down Expand Up @@ -34,10 +34,10 @@ let namespaceCounter = 0;

let functions: any[] = [];

const sanitizeText = (txt: string) => common.sanitizeText(txt, configApi.getConfig());
const sanitizeText = (txt: string) => common.sanitizeText(txt, getConfig());

const splitClassNameAndType = function (_id: string) {
const id = common.sanitizeText(_id, configApi.getConfig());
const id = common.sanitizeText(_id, getConfig());
let genericType = '';
let className = id;

Expand All @@ -51,7 +51,7 @@ const splitClassNameAndType = function (_id: string) {
};

export const setClassLabel = function (_id: string, label: string) {
const id = common.sanitizeText(_id, configApi.getConfig());
const id = common.sanitizeText(_id, getConfig());
if (label) {
label = sanitizeText(label);
}
Expand All @@ -67,14 +67,14 @@ export const setClassLabel = function (_id: string, label: string) {
* @public
*/
export const addClass = function (_id: string) {
const id = common.sanitizeText(_id, configApi.getConfig());
const id = common.sanitizeText(_id, getConfig());
const { className, type } = splitClassNameAndType(id);
// Only add class if not exists
if (Object.hasOwn(classes, className)) {
return;
}
// alert('Adding class: ' + className);
const name = common.sanitizeText(className, configApi.getConfig());
const name = common.sanitizeText(className, getConfig());
// alert('Adding class after: ' + name);
classes[name] = {
id: name,
Expand All @@ -97,7 +97,7 @@ export const addClass = function (_id: string) {
* @public
*/
export const lookUpDomId = function (_id: string): string {
const id = common.sanitizeText(_id, configApi.getConfig());
const id = common.sanitizeText(_id, getConfig());
if (id in classes) {
return classes[id].domId;
}
Expand Down Expand Up @@ -139,15 +139,9 @@ export const addRelation = function (relation: ClassRelation) {
relation.id1 = splitClassNameAndType(relation.id1).className;
relation.id2 = splitClassNameAndType(relation.id2).className;

relation.relationTitle1 = common.sanitizeText(
relation.relationTitle1.trim(),
configApi.getConfig()
);
relation.relationTitle1 = common.sanitizeText(relation.relationTitle1.trim(), getConfig());

relation.relationTitle2 = common.sanitizeText(
relation.relationTitle2.trim(),
configApi.getConfig()
);
relation.relationTitle2 = common.sanitizeText(relation.relationTitle2.trim(), getConfig());

relations.push(relation);
};
Expand Down Expand Up @@ -267,7 +261,7 @@ export const getTooltip = function (id: string, namespace?: string) {
* @param target - Target of the link, _blank by default as originally defined in the svgDraw.js file
*/
export const setLink = function (ids: string, linkStr: string, target: string) {
const config = configApi.getConfig();
const config = getConfig();
ids.split(',').forEach(function (_id) {
let id = _id;
if (_id[0].match(/\d/)) {
Expand Down Expand Up @@ -303,8 +297,8 @@ export const setClickEvent = function (ids: string, functionName: string, functi
};

const setClickFunc = function (_domId: string, functionName: string, functionArgs: string) {
const domId = common.sanitizeText(_domId, configApi.getConfig());
const config = configApi.getConfig();
const domId = common.sanitizeText(_domId, getConfig());
const config = getConfig();
if (config.securityLevel !== 'loose') {
return;
}
Expand Down Expand Up @@ -465,7 +459,7 @@ export default {
getAccTitle,
getAccDescription,
setAccDescription,
getConfig: () => configApi.getConfig().class,
getConfig: () => getConfig().class,
addClass,
bindFunctions,
clear,
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/class/classRenderer-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { select, curveLinear } from 'd3';
import * as graphlib from 'dagre-d3-es/src/graphlib/index.js';
import { log } from '../../logger.js';
import { getConfig } from '../../config.js';
import { getConfig } from '../../diagram-api/diagramAPI.js';
import { render } from '../../dagre-wrapper/index.js';
import utils from '../../utils.js';
import { interpolateToCurve, getStylesFromArray } from '../../utils.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/class/classRenderer.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import * as graphlib from 'dagre-d3-es/src/graphlib/index.js';
import { log } from '../../logger.js';
import svgDraw from './svgDraw.js';
import { configureSvgSize } from '../../setupGraphViewbox.js';
import { getConfig } from '../../config.js';
import { getConfig } from '../../diagram-api/diagramAPI.js';

let idCache = {};
const padding = 20;
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/class/classTypes.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getConfig } from '../../config.js';
import { getConfig } from '../../diagram-api/diagramAPI.js';
import { parseGenericTypes, sanitizeText } from '../common/common.js';

export interface ClassNode {
Expand Down
4 changes: 2 additions & 2 deletions packages/mermaid/src/diagrams/er/erDb.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { log } from '../../logger.js';
import * as configApi from '../../config.js';
import { getConfig } from '../../diagram-api/diagramAPI.js';

import {
setAccTitle,
Expand Down Expand Up @@ -83,7 +83,7 @@ const clear = function () {
export default {
Cardinality,
Identification,
getConfig: () => configApi.getConfig().er,
getConfig: () => getConfig().er,
addEntity,
addAttributes,
getEntities,
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/er/erRenderer.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as graphlib from 'dagre-d3-es/src/graphlib/index.js';
import { line, curveBasis, select } from 'd3';
import { layout as dagreLayout } from 'dagre-d3-es/src/dagre/index.js';
import { getConfig } from '../../config.js';
import { getConfig } from '../../diagram-api/diagramAPI.js';
import { log } from '../../logger.js';
import utils from '../../utils.js';
import erMarkers from './erMarkers.js';
Expand Down
10 changes: 5 additions & 5 deletions packages/mermaid/src/diagrams/flowchart/flowDb.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { select } from 'd3';
import utils from '../../utils.js';
import * as configApi from '../../config.js';
import { getConfig, defaultConfig } from '../../diagram-api/diagramAPI.js';
import common from '../common/common.js';
import { log } from '../../logger.js';
import {
Expand All @@ -15,7 +15,7 @@ import {

const MERMAID_DOM_ID_PREFIX = 'flowchart-';
let vertexCounter = 0;
let config = configApi.getConfig();
let config = getConfig();
let vertices = {};
let edges = [];
let classes = {};
Expand Down Expand Up @@ -84,7 +84,7 @@ export const addVertex = function (_id, textObj, type, style, classes, dir, prop
}
vertexCounter++;
if (textObj !== undefined) {
config = configApi.getConfig();
config = getConfig();
txt = sanitizeText(textObj.text.trim());
vertices[id].labelType = textObj.type;
// strip quotes if string starts and ends with a quote
Expand Down Expand Up @@ -277,7 +277,7 @@ const setTooltip = function (ids, tooltip) {
const setClickFun = function (id, functionName, functionArgs) {
let domId = lookUpDomId(id);
// if (_id[0].match(/\d/)) id = MERMAID_DOM_ID_PREFIX + id;
if (configApi.getConfig().securityLevel !== 'loose') {
if (getConfig().securityLevel !== 'loose') {
return;
}
if (functionName === undefined) {
Expand Down Expand Up @@ -766,7 +766,7 @@ export const lex = {
firstGraph,
};
export default {
defaultConfig: () => configApi.defaultConfig.flowchart,
defaultConfig: () => defaultConfig.flowchart,
setAccTitle,
getAccTitle,
getAccDescription,
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/flowchart/flowDiagram-v2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import flowDb from './flowDb.js';
import flowRendererV2 from './flowRenderer-v2.js';
import flowStyles from './styles.js';
import type { MermaidConfig } from '../../config.type.js';
import { setConfig } from '../../config.js';
import { setConfig } from '../../diagram-api/diagramAPI.js';

export const diagram = {
parser: flowParser,
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/flowchart/flowRenderer-v2.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as graphlib from 'dagre-d3-es/src/graphlib/index.js';
import { select, curveLinear, selectAll } from 'd3';
import { getConfig } from '../../config.js';
import { getConfig } from '../../diagram-api/diagramAPI.js';
import utils from '../../utils.js';
import { render } from '../../dagre-wrapper/index.js';
import { addHtmlLabel } from 'dagre-d3-es/src/dagre-js/label/add-html-label.js';
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/flowchart/flowRenderer.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import * as graphlib from 'dagre-d3-es/src/graphlib/index.js';
import { select, curveLinear, selectAll } from 'd3';
import { getConfig } from '../../config.js';
import { getConfig } from '../../diagram-api/diagramAPI.js';
import { render as Render } from 'dagre-d3-es';
import { applyStyle } from 'dagre-d3-es/src/dagre-js/util.js';
import { addHtmlLabel } from 'dagre-d3-es/src/dagre-js/label/add-html-label.js';
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { addVertices, addEdges } from './flowRenderer.js';
import { setConfig } from '../../config.js';
import { setConfig } from '../../diagram-api/diagramAPI.js';

setConfig({
flowchart: {
Expand Down
8 changes: 4 additions & 4 deletions packages/mermaid/src/diagrams/gantt/ganttDb.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import dayjsIsoWeek from 'dayjs/plugin/isoWeek.js';
import dayjsCustomParseFormat from 'dayjs/plugin/customParseFormat.js';
import dayjsAdvancedFormat from 'dayjs/plugin/advancedFormat.js';
import { log } from '../../logger.js';
import * as configApi from '../../config.js';
import { getConfig } from '../../diagram-api/diagramAPI.js';
import utils from '../../utils.js';

import {
Expand Down Expand Up @@ -603,7 +603,7 @@ const compileTasks = function () {
*/
export const setLink = function (ids, _linkStr) {
let linkStr = _linkStr;
if (configApi.getConfig().securityLevel !== 'loose') {
if (getConfig().securityLevel !== 'loose') {
linkStr = sanitizeUrl(_linkStr);
}
ids.split(',').forEach(function (id) {
Expand Down Expand Up @@ -634,7 +634,7 @@ export const setClass = function (ids, className) {
};

const setClickFun = function (id, functionName, functionArgs) {
if (configApi.getConfig().securityLevel !== 'loose') {
if (getConfig().securityLevel !== 'loose') {
return;
}
if (functionName === undefined) {
Expand Down Expand Up @@ -725,7 +725,7 @@ export const bindFunctions = function (element) {
};

export default {
getConfig: () => configApi.getConfig().gantt,
getConfig: () => getConfig().gantt,
clear,
setDateFormat,
getDateFormat,
Expand Down
Loading

0 comments on commit d04f4c2

Please sign in to comment.