Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

making consitent config imports from diagramAPI #4889

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion packages/mermaid/src/dagre-wrapper/clusters.js
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
@@ -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
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
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
@@ -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 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 @@
};

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 @@
* @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 @@
* @public
*/
export const lookUpDomId = function (_id: string): string {
const id = common.sanitizeText(_id, configApi.getConfig());
const id = common.sanitizeText(_id, getConfig());

Check warning on line 100 in packages/mermaid/src/diagrams/class/classDb.ts

View check run for this annotation

Codecov / codecov/patch

packages/mermaid/src/diagrams/class/classDb.ts#L100

Added line #L100 was not covered by tests
if (id in classes) {
return classes[id].domId;
}
Expand Down Expand Up @@ -139,15 +139,9 @@
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 @@
* @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 @@
};

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 @@
getAccTitle,
getAccDescription,
setAccDescription,
getConfig: () => configApi.getConfig().class,
getConfig: () => getConfig().class,

Check warning on line 462 in packages/mermaid/src/diagrams/class/classDb.ts

View check run for this annotation

Codecov / codecov/patch

packages/mermaid/src/diagrams/class/classDb.ts#L462

Added line #L462 was not covered by tests
addClass,
bindFunctions,
clear,
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/class/classRenderer-v2.ts
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
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
@@ -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
@@ -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 @@
export default {
Cardinality,
Identification,
getConfig: () => configApi.getConfig().er,
getConfig: () => getConfig().er,

Check warning on line 86 in packages/mermaid/src/diagrams/er/erDb.js

View check run for this annotation

Codecov / codecov/patch

packages/mermaid/src/diagrams/er/erDb.js#L86

Added line #L86 was not covered by tests
addEntity,
addAttributes,
getEntities,
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/er/erRenderer.js
@@ -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
@@ -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 @@

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 @@
}
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 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 @@
firstGraph,
};
export default {
defaultConfig: () => configApi.defaultConfig.flowchart,
defaultConfig: () => defaultConfig.flowchart,

Check warning on line 769 in packages/mermaid/src/diagrams/flowchart/flowDb.js

View check run for this annotation

Codecov / codecov/patch

packages/mermaid/src/diagrams/flowchart/flowDb.js#L769

Added line #L769 was not covered by tests
setAccTitle,
getAccTitle,
getAccDescription,
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/flowchart/flowDiagram-v2.ts
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
@@ -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
@@ -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
@@ -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
Expand Up @@ -4,7 +4,7 @@
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 @@
*/
export const setLink = function (ids, _linkStr) {
let linkStr = _linkStr;
if (configApi.getConfig().securityLevel !== 'loose') {
if (getConfig().securityLevel !== 'loose') {

Check warning on line 606 in packages/mermaid/src/diagrams/gantt/ganttDb.js

View check run for this annotation

Codecov / codecov/patch

packages/mermaid/src/diagrams/gantt/ganttDb.js#L606

Added line #L606 was not covered by tests
linkStr = sanitizeUrl(_linkStr);
}
ids.split(',').forEach(function (id) {
Expand Down Expand Up @@ -634,7 +634,7 @@
};

const setClickFun = function (id, functionName, functionArgs) {
if (configApi.getConfig().securityLevel !== 'loose') {
if (getConfig().securityLevel !== 'loose') {

Check warning on line 637 in packages/mermaid/src/diagrams/gantt/ganttDb.js

View check run for this annotation

Codecov / codecov/patch

packages/mermaid/src/diagrams/gantt/ganttDb.js#L637

Added line #L637 was not covered by tests
return;
}
if (functionName === undefined) {
Expand Down Expand Up @@ -725,7 +725,7 @@
};

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