Compare commits

...

20 Commits

Author SHA1 Message Date
Sidharth Vinod
6462f73bdb chore: resolve eslint warnings in packages/parser/src/language/common/valueConverter.ts 2025-04-19 10:21:45 +05:30
Sidharth Vinod
cfe1723c6c chore: resolve eslint warnings in packages/mermaid/src/diagrams/packet/parser.ts 2025-04-19 10:21:45 +05:30
Sidharth Vinod
6d8b936319 chore: resolve eslint warnings in packages/mermaid/src/diagrams/class/classRenderer-v2.ts 2025-04-19 10:21:45 +05:30
Sidharth Vinod
f992d95082 chore: resolve eslint warnings in packages/mermaid/src/diagrams/class/classDiagram.ts 2025-04-19 10:21:44 +05:30
Sidharth Vinod
f2276f93cd chore: resolve eslint warnings in packages/mermaid/src/diagrams/class/classDiagram-v2.ts 2025-04-19 10:21:44 +05:30
Sidharth Vinod
b52f5058c9 chore: resolve eslint warnings in packages/mermaid/src/diagrams/class/classDb.ts 2025-04-19 10:21:44 +05:30
Sidharth Vinod
5e20087252 chore: resolve eslint warnings in packages/mermaid/src/diagrams/block/renderHelpers.ts 2025-04-19 10:21:44 +05:30
Sidharth Vinod
b49036068f chore: resolve eslint warnings in packages/mermaid/src/diagrams/block/blockDB.ts 2025-04-19 10:21:43 +05:30
Sidharth Vinod
5f3d4cb913 chore: resolve eslint warnings in packages/mermaid/src/diagrams/architecture/architectureRenderer.ts 2025-04-19 10:21:43 +05:30
Sidharth Vinod
b11eb93ab2 chore: resolve eslint warnings in packages/mermaid/src/dagre-wrapper/nodes.js 2025-04-19 10:21:43 +05:30
Sidharth Vinod
e4f19480cd chore: resolve eslint warnings in packages/mermaid/src/dagre-wrapper/mermaid-graphlib.js 2025-04-19 10:21:43 +05:30
Sidharth Vinod
a331a958c0 chore: resolve eslint warnings in packages/mermaid/src/dagre-wrapper/edges.js 2025-04-19 10:21:42 +05:30
Sidharth Vinod
134fca3f1d chore: resolve eslint warnings in packages/mermaid/src/dagre-wrapper/createLabel.js 2025-04-19 10:21:42 +05:30
Sidharth Vinod
ef7c0a1936 chore: resolve eslint warnings in packages/mermaid/src/dagre-wrapper/clusters.js 2025-04-19 10:21:42 +05:30
Sidharth Vinod
2c5403c0f9 chore: resolve eslint warnings in packages/mermaid/src/config.ts 2025-04-19 10:21:41 +05:30
Sidharth Vinod
3b0cb1271e chore: resolve eslint warnings in packages/mermaid-layout-elk/src/render.ts 2025-04-19 10:21:41 +05:30
Sidharth Vinod
96c06a681d chore: resolve eslint warnings in cypress/integration/rendering/journey.spec.js 2025-04-19 10:21:41 +05:30
Sidharth Vinod
ff9d26bc70 chore: resolve eslint warnings in cypress/integration/rendering/imageShape.spec.ts 2025-04-19 10:21:41 +05:30
Sidharth Vinod
2ddc3403de chore: resolve eslint warnings in cypress/integration/rendering/iconShape.spec.ts 2025-04-19 10:21:40 +05:30
Sidharth Vinod
4535911a3a chore: resolve eslint warnings in cypress/helpers/util.ts 2025-04-19 10:21:40 +05:30
20 changed files with 40 additions and 63 deletions

View File

@@ -22,7 +22,7 @@ const batchId: string =
'mermaid-batch-' +
(Cypress.env('useAppli')
? Date.now().toString()
: Cypress.env('CYPRESS_COMMIT') || Date.now().toString());
: (Cypress.env('CYPRESS_COMMIT') ?? Date.now().toString()));
export const mermaidUrl = (
graphStr: string | string[],
@@ -61,9 +61,7 @@ export const imgSnapshotTest = (
sequence: {
...(_options.sequence ?? {}),
actorFontFamily: 'courier',
noteFontFamily: _options.sequence?.noteFontFamily
? _options.sequence.noteFontFamily
: 'courier',
noteFontFamily: _options.sequence?.noteFontFamily ?? 'courier',
messageFontFamily: 'courier',
},
};

View File

@@ -14,7 +14,7 @@ looks.forEach((look) => {
directions.forEach((direction) => {
forms.forEach((form) => {
labelPos.forEach((pos) => {
describe(`Test iconShape in ${form ? `${form} form,` : ''} ${look} look and dir ${direction} with label position ${pos ? pos : 'not defined'}`, () => {
describe(`Test iconShape in ${form ? `${form} form,` : ''} ${look} look and dir ${direction} with label position ${pos ?? 'not defined'}`, () => {
it(`without label`, () => {
let flowchartCode = `flowchart ${direction}\n`;
flowchartCode += ` nA --> nAA@{ icon: 'fa:bell'`;

View File

@@ -12,7 +12,7 @@ const labelPos = [undefined, 't', 'b'] as const;
looks.forEach((look) => {
directions.forEach((direction) => {
labelPos.forEach((pos) => {
describe(`Test imageShape in ${look} look and dir ${direction} with label position ${pos ? pos : 'not defined'}`, () => {
describe(`Test imageShape in ${look} look and dir ${direction} with label position ${pos ?? 'not defined'}`, () => {
it(`without label`, () => {
let flowchartCode = `flowchart ${direction}\n`;
flowchartCode += ` nA --> A@{ img: 'https://cdn.pixabay.com/photo/2020/02/22/18/49/paper-4871356_1280.jpg', w: '100', h: '100' }\n`;

View File

@@ -214,7 +214,7 @@ section Checkout from website
$lines.each((index, el) => {
const bbox = el.getBBox();
expect(bbox.width).to.be.lte(320);
maxLineWidth = Math.max(maxLineWidth || 0, bbox.width);
maxLineWidth = Math.max(maxLineWidth ?? 0, bbox.width);
});
/** The expected margin between the diagram and the legend is 150px, as defined by

View File

@@ -190,9 +190,7 @@ export const render = async (
const children = nodeArr.filter((node: { parentId: any }) => node.parentId === subgraph.id);
children.forEach((node: any) => {
parentLookupDb.parentById[node.id] = subgraph.id;
if (parentLookupDb.childrenById[subgraph.id] === undefined) {
parentLookupDb.childrenById[subgraph.id] = [];
}
parentLookupDb.childrenById[subgraph.id] ??= [];
parentLookupDb.childrenById[subgraph.id].push(node);
});
});
@@ -381,10 +379,10 @@ export const render = async (
}
edgeData.labelType = edge.labelType;
edgeData.label = (edge?.text || '').replace(common.lineBreakRegex, '\n');
edgeData.label = (edge?.text ?? '').replace(common.lineBreakRegex, '\n');
if (edge.style === undefined) {
edgeData.style = edgeData.style || 'stroke: #333; stroke-width: 1.5px;fill:none;';
edgeData.style = edgeData.style ?? 'stroke: #333; stroke-width: 1.5px;fill:none;';
}
edgeData.labelStyle = edgeData.labelStyle.replace('color:', 'fill:');
@@ -725,9 +723,7 @@ export const render = async (
inter = inter2;
}
}
if (!inter) {
inter = intersection(bounds, lastPointOutside, point);
}
inter ??= intersection(bounds, lastPointOutside, point);
// Check case where the intersection is the same as the last point
let pointPresent = false;
@@ -840,8 +836,8 @@ export const render = async (
node.labels = [
{
text: node.label,
width: node?.labelData?.width || 50,
height: node?.labelData?.height || 50,
width: node?.labelData?.width ?? 50,
height: node?.labelData?.height ?? 50,
},
(node.width = node.width + 2 * node.padding),
log.debug('UIO node label', node?.labelData?.width, node.padding),
@@ -917,7 +913,7 @@ export const render = async (
if (edge.sections) {
const src = edge.sections[0].startPoint;
const dest = edge.sections[0].endPoint;
const segments = edge.sections[0].bendPoints ? edge.sections[0].bendPoints : [];
const segments = edge.sections[0].bendPoints ?? [];
const segPoints = segments.map((segment: { x: any; y: any }) => {
return { x: segment.x + offset.x, y: segment.y + offset.y };

View File

@@ -30,7 +30,7 @@ export const updateCurrentConfig = (siteCfg: MermaidConfig, _directives: Mermaid
if (sumOfDirectives.theme && sumOfDirectives.theme in theme) {
const tmpConfigFromInitialize = assignWithDepth({}, configFromInitialize);
const themeVariables = assignWithDepth(
tmpConfigFromInitialize.themeVariables || {},
tmpConfigFromInitialize.themeVariables ?? {},
sumOfDirectives.themeVariables
);
if (cfg.theme && cfg.theme in theme) {

View File

@@ -238,7 +238,7 @@ let clusterElems = {};
export const insertCluster = (elem, node) => {
log.trace('Inserting cluster');
const shape = node.shape || 'rect';
const shape = node.shape ?? 'rect';
clusterElems[node.id] = shapes[shape](elem, node);
};
export const getClusterTitleWidth = (elem, node) => {

View File

@@ -45,7 +45,7 @@ function addHtmlLabel(node) {
* @deprecated svg-util/createText instead
*/
const createLabel = (_vertexText, style, isTitle, isNode) => {
let vertexText = _vertexText || '';
let vertexText = _vertexText ?? '';
if (typeof vertexText === 'object') {
vertexText = vertexText[0];
}

View File

@@ -69,9 +69,7 @@ export const insertEdgeLabel = (elem, edge) => {
fo = inner.node().appendChild(startLabelElement);
const slBox = startLabelElement.getBBox();
inner.attr('transform', 'translate(' + -slBox.width / 2 + ', ' + -slBox.height / 2 + ')');
if (!terminalLabels[edge.id]) {
terminalLabels[edge.id] = {};
}
terminalLabels[edge.id] ??= {};
terminalLabels[edge.id].startLeft = startEdgeLabelLeft;
setTerminalWidth(fo, edge.startLabelLeft);
}
@@ -85,9 +83,7 @@ export const insertEdgeLabel = (elem, edge) => {
const slBox = startLabelElement.getBBox();
inner.attr('transform', 'translate(' + -slBox.width / 2 + ', ' + -slBox.height / 2 + ')');
if (!terminalLabels[edge.id]) {
terminalLabels[edge.id] = {};
}
terminalLabels[edge.id] ??= {};
terminalLabels[edge.id].startRight = startEdgeLabelRight;
setTerminalWidth(fo, edge.startLabelRight);
}
@@ -102,9 +98,7 @@ export const insertEdgeLabel = (elem, edge) => {
endEdgeLabelLeft.node().appendChild(endLabelElement);
if (!terminalLabels[edge.id]) {
terminalLabels[edge.id] = {};
}
terminalLabels[edge.id] ??= {};
terminalLabels[edge.id].endLeft = endEdgeLabelLeft;
setTerminalWidth(fo, edge.endLabelLeft);
}
@@ -119,9 +113,7 @@ export const insertEdgeLabel = (elem, edge) => {
inner.attr('transform', 'translate(' + -slBox.width / 2 + ', ' + -slBox.height / 2 + ')');
endEdgeLabelRight.node().appendChild(endLabelElement);
if (!terminalLabels[edge.id]) {
terminalLabels[edge.id] = {};
}
terminalLabels[edge.id] ??= {};
terminalLabels[edge.id].endRight = endEdgeLabelRight;
setTerminalWidth(fo, edge.endLabelRight);
}
@@ -141,7 +133,7 @@ function setTerminalWidth(fo, value) {
export const positionEdgeLabel = (edge, paths) => {
log.debug('Moving label abc88 ', edge.id, edge.label, edgeLabels[edge.id], paths);
let path = paths.updatedPath ? paths.updatedPath : paths.originalPath;
let path = paths.updatedPath ?? paths.originalPath;
const siteConfig = getConfig();
const { subGraphTitleTotalMargin } = getSubGraphTitleMargins(siteConfig);
if (edge.label) {

View File

@@ -4,7 +4,9 @@ import * as graphlibJson from 'dagre-d3-es/src/graphlib/json.js';
import * as graphlib from 'dagre-d3-es/src/graphlib/index.js';
export let clusterDb = {};
/** @type {Record<string, string[]>} */
let descendants = {};
/** @type {Record<string, string>} */
let parents = {};
export const clear = () => {

View File

@@ -15,9 +15,7 @@ const formatClass = (str) => {
return '';
};
const getClassesFromNode = (node, otherClasses) => {
return `${otherClasses ? otherClasses : 'node default'}${formatClass(node.classes)} ${formatClass(
node.class
)}`;
return `${otherClasses ?? 'node default'}${formatClass(node.classes)} ${formatClass(node.class)}`;
};
const question = async (parent, node) => {
@@ -57,7 +55,7 @@ const choice = (parent, node) => {
const shapeSvg = parent
.insert('g')
.attr('class', 'node default')
.attr('id', node.domId || node.id);
.attr('id', node.domId ?? node.id);
const s = 28;
const points = [
@@ -566,7 +564,7 @@ const rectWithTitle = (parent, node) => {
const shapeSvg = parent
.insert('g')
.attr('class', classes)
.attr('id', node.domId || node.id);
.attr('id', node.domId ?? node.id);
// Create the title label and insert it after the rect
const rect = shapeSvg.insert('rect', ':first-child');
@@ -808,7 +806,7 @@ const start = (parent, node) => {
const shapeSvg = parent
.insert('g')
.attr('class', 'node default')
.attr('id', node.domId || node.id);
.attr('id', node.domId ?? node.id);
const circle = shapeSvg.insert('circle', ':first-child');
// center the circle around its coordinate
@@ -827,7 +825,7 @@ const forkJoin = (parent, node, dir) => {
const shapeSvg = parent
.insert('g')
.attr('class', 'node default')
.attr('id', node.domId || node.id);
.attr('id', node.domId ?? node.id);
let width = 70;
let height = 10;
@@ -859,7 +857,7 @@ const end = (parent, node) => {
const shapeSvg = parent
.insert('g')
.attr('class', 'node default')
.attr('id', node.domId || node.id);
.attr('id', node.domId ?? node.id);
const innerCircle = shapeSvg.insert('circle', ':first-child');
const circle = shapeSvg.insert('circle', ':first-child');
@@ -891,7 +889,7 @@ const class_box = (parent, node) => {
const shapeSvg = parent
.insert('g')
.attr('class', classes)
.attr('id', node.domId || node.id);
.attr('id', node.domId ?? node.id);
// Create the title label and insert it after the rect
const rect = shapeSvg.insert('rect', ':first-child');

View File

@@ -88,7 +88,7 @@ function positionNodes(db: ArchitectureDB, cy: cytoscape.Core) {
data.y = node.position().y;
const nodeElem = db.getElementById(data.id);
nodeElem.attr('transform', 'translate(' + (data.x || 0) + ',' + (data.y || 0) + ')');
nodeElem.attr('transform', 'translate(' + (data.x ?? 0) + ',' + (data.y ?? 0) + ')');
});
}

View File

@@ -82,9 +82,7 @@ export const setCssClass = function (itemIds: string, cssClassName: string) {
foundBlock = { id: trimmedId, type: 'na', children: [] } as Block;
blockDatabase.set(trimmedId, foundBlock);
}
if (!foundBlock.classes) {
foundBlock.classes = [];
}
foundBlock.classes ??= [];
foundBlock.classes.push(cssClassName);
});
};

View File

@@ -10,7 +10,7 @@ function getNodeFromBlock(block: Block, db: BlockDB, positioned = false) {
const vertex = block;
let classStr = 'default';
if ((vertex?.classes?.length || 0) > 0) {
if ((vertex?.classes?.length ?? 0) > 0) {
classStr = (vertex?.classes ?? []).join(' ');
}
classStr = classStr + ' flowchart-label';

View File

@@ -41,7 +41,7 @@ export class ClassDB implements DiagramDB {
private namespaces = new Map<string, NamespaceNode>();
private namespaceCounter = 0;
private functions: any[] = [];
private functions: ((element: Element) => void)[] = [];
constructor() {
this.functions.push(this.setupToolTips.bind(this));
@@ -477,7 +477,7 @@ export class ClassDB implements DiagramDB {
let tooltipElem: Selection<HTMLDivElement, unknown, HTMLElement, unknown> =
select('.mermaidTooltip');
// @ts-expect-error - Incorrect types
if ((tooltipElem._groups || tooltipElem)[0][0] === null) {
if ((tooltipElem._groups ?? tooltipElem)[0][0] === null) {
tooltipElem = select('body')
.append('div')
.attr('class', 'mermaidTooltip')

View File

@@ -13,9 +13,7 @@ export const diagram: DiagramDefinition = {
renderer,
styles,
init: (cnf) => {
if (!cnf.class) {
cnf.class = {};
}
cnf.class ??= {};
cnf.class.arrowMarkerAbsolute = cnf.arrowMarkerAbsolute;
},
};

View File

@@ -13,9 +13,7 @@ export const diagram: DiagramDefinition = {
renderer,
styles,
init: (cnf) => {
if (!cnf.class) {
cnf.class = {};
}
cnf.class ??= {};
cnf.class.arrowMarkerAbsolute = cnf.arrowMarkerAbsolute;
},
};

View File

@@ -117,7 +117,7 @@ export const addClasses = function (
style: styles.style,
id: vertex.id,
domId: vertex.domId,
tooltip: diagObj.db.getTooltip(vertex.id, parent) || '',
tooltip: diagObj.db.getTooltip(vertex.id, parent) ?? '',
haveCallback: vertex.haveCallback,
link: vertex.link,
width: vertex.type === 'group' ? 500 : undefined,

View File

@@ -50,9 +50,7 @@ const getNextFittingBlock = (
row: number,
bitsPerRow: number
): [Required<PacketBlock>, PacketBlock | undefined] => {
if (block.end === undefined) {
block.end = block.start;
}
block.end ??= block.start;
if (block.start > block.end) {
throw new Error(`Block start ${block.start} is greater than block end ${block.end}.`);

View File

@@ -31,9 +31,8 @@ export abstract class AbstractMermaidValueConverter extends DefaultValueConverte
): ValueType {
let value: ValueType | undefined = this.runCommonConverter(rule, input, cstNode);
if (value === undefined) {
value = this.runCustomConverter(rule, input, cstNode);
}
value ??= this.runCustomConverter(rule, input, cstNode);
if (value === undefined) {
return super.runConverter(rule, input, cstNode);
}