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’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pre-release #5845

Merged
merged 41 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
59d6f04
make rendering-util/types a real ts file
bollwyvl Aug 30, 2024
e519686
Merge remote-tracking branch 'upstream/master'
bollwyvl Aug 30, 2024
a176d64
fix import
bollwyvl Aug 30, 2024
a45588c
Merge remote-tracking branch 'upstream/develop' into gh-5747-renderin…
bollwyvl Aug 30, 2024
3e922c8
pass linter
bollwyvl Aug 30, 2024
6a97f80
add another maybe-undefined operator elk
bollwyvl Aug 30, 2024
73f8d70
rebuild docs
bollwyvl Aug 30, 2024
1b7433b
replace with mermaid/dist
bollwyvl Aug 31, 2024
0b672e2
add test for out-of-tree tsc project
bollwyvl Sep 1, 2024
426d311
Merge branch 'develop' into gh-5747-rendering-util-types
bollwyvl Sep 2, 2024
7156cf4
merge upstream
bollwyvl Sep 2, 2024
b56fe79
more , linting
bollwyvl Sep 2, 2024
cd67fdf
docs: Fix SMW link
sidharthv96 Sep 3, 2024
bfc4abe
Merge branch 'master' into develop
sidharthv96 Sep 3, 2024
c078840
Merge branch 'develop' into gh-5747-rendering-util-types
bollwyvl Sep 4, 2024
826faad
Merge branch 'develop' into gh-5747-no-dollar-root
bollwyvl Sep 4, 2024
64abf29
feat: Return parsed config from `mermaid.parse`
sidharthv96 Sep 6, 2024
57d2d90
feat: Preview release
sidharthv96 Sep 6, 2024
ab25e9e
Merge pull request #5832 from mermaid-js/sidv/previewRelease
sidharthv96 Sep 6, 2024
58524ac
chore: Fix check
sidharthv96 Sep 6, 2024
f7be983
Merge branch 'develop' into sidv/returnConfig
sidharthv96 Sep 6, 2024
2879f37
chore: add git command and set safe dir
kairi003 Sep 7, 2024
ba95f39
Merge branch 'develop' into gh-5747-no-dollar-root
bollwyvl Sep 8, 2024
35c0898
Merge branch 'develop' into gh-5747-rendering-util-types
bollwyvl Sep 8, 2024
bf98420
Merge branch 'master' into develop
sidharthv96 Sep 8, 2024
c95a0c7
Merge pull request #5834 from kairi003/bug/5833_add_git_for_changeset
sidharthv96 Sep 8, 2024
e5aebf3
Merge pull request #5798 from bollwyvl/gh-5747-rendering-util-types
sidharthv96 Sep 8, 2024
6a3f1d1
Merge branch 'develop' into gh-5747-no-dollar-root
bollwyvl Sep 8, 2024
571dfda
replace mermaid/dist with relative paths
bollwyvl Sep 8, 2024
94deacb
linting
bollwyvl Sep 8, 2024
fd3c3fc
remove tsconfig compiler option paths
bollwyvl Sep 8, 2024
b830e61
chore(deps): update dependency eslint-plugin-jsdoc to v50
renovate[bot] Sep 9, 2024
5e75320
Create red-beans-cross.md
sidharthv96 Sep 9, 2024
cc61629
Merge pull request #5842 from mermaid-js/renovate/major-eslint
sidharthv96 Sep 9, 2024
1951a0c
[autofix.ci] apply automated fixes
autofix-ci[bot] Sep 9, 2024
750f58d
Merge pull request #5838 from bollwyvl/gh-5747-relative-paths
sidharthv96 Sep 9, 2024
303f1f4
Merge branch 'develop' into sidv/returnConfig
sidharthv96 Sep 9, 2024
c018710
fix: Return type, make config non optional
sidharthv96 Sep 9, 2024
acc1e50
Merge branch 'develop' into sidv/returnConfig
sidharthv96 Sep 9, 2024
d053284
[autofix.ci] apply automated fixes
autofix-ci[bot] Sep 9, 2024
ddb51cd
Merge pull request #5831 from mermaid-js/sidv/returnConfig
sidharthv96 Sep 9, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/giant-steaks-argue.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'mermaid': minor
---

feat: Return parsed config from mermaid.parse
5 changes: 5 additions & 0 deletions .changeset/red-beans-cross.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'mermaid': patch
---

fix: Replace $root with relative paths
42 changes: 42 additions & 0 deletions .github/workflows/release-preview.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: Preview release

on:
pull_request:
branches: [develop]

concurrency:
group: ${{ github.workflow }}-${{ github.event.number }}
cancel-in-progress: true

permissions:
contents: read
actions: write

jobs:
preview:
if: ${{ github.repository_owner == 'mermaid-js' }}
runs-on: ubuntu-latest
permissions:
contents: read
id-token: write
issues: write
pull-requests: write
name: Publish preview release
timeout-minutes: 5
steps:
- name: Checkout Repo
uses: actions/checkout@f43a0e5ff2bd294095638e18286ca9a3d1956744 # v3.6.0

- uses: pnpm/action-setup@fe02b34f77f8bc703788d5817da081398fad5dd2 # v4.0.0

- name: Setup Node.js
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
with:
cache: pnpm
node-version-file: '.node-version'

- name: Install Packages
run: pnpm install --frozen-lockfile

- name: Publish packages
run: pnpx pkg-pr-new publish --pnpm './packages/*'
4 changes: 4 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ jobs:
run: |
pnpm exec vitest run ./packages/mermaid/src/diagrams/gantt/ganttDb.spec.ts --coverage

- name: Verify out-of-tree build with TypeScript
run: |
pnpm test:check:tsc

- name: Upload Coverage to Codecov
uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4.5.0
# Run step only pushes to develop and pull_requests
Expand Down
3 changes: 3 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ USER 0:0
RUN corepack enable \
&& corepack enable pnpm

RUN apk add --no-cache git~=2.43.4 \
&& git config --add --system safe.directory /mermaid

ENV NODE_OPTIONS="--max_old_space_size=8192"

EXPOSE 9000 3333
8 changes: 4 additions & 4 deletions docs/config/setup/interfaces/mermaid.LayoutData.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

### config

• **config**: `MermaidConfig`
• **config**: [`MermaidConfig`](mermaid.MermaidConfig.md)

#### Defined in

[packages/mermaid/src/rendering-util/types.d.ts:118](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/types.d.ts#L118)
[packages/mermaid/src/rendering-util/types.ts:117](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/types.ts#L117)

---

Expand All @@ -30,7 +30,7 @@

#### Defined in

[packages/mermaid/src/rendering-util/types.d.ts:117](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/types.d.ts#L117)
[packages/mermaid/src/rendering-util/types.ts:116](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/types.ts#L116)

---

Expand All @@ -40,4 +40,4 @@

#### Defined in

[packages/mermaid/src/rendering-util/types.d.ts:116](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/types.d.ts#L116)
[packages/mermaid/src/rendering-util/types.ts:115](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/rendering-util/types.ts#L115)
2 changes: 1 addition & 1 deletion docs/config/setup/interfaces/mermaid.ParseOptions.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ The `parseError` function will not be called.

#### Defined in

[packages/mermaid/src/types.ts:43](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L43)
[packages/mermaid/src/types.ts:45](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L45)
14 changes: 13 additions & 1 deletion docs/config/setup/interfaces/mermaid.ParseResult.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,18 @@

## Properties

### config

• **config**: [`MermaidConfig`](mermaid.MermaidConfig.md)

The config passed as YAML frontmatter or directives

#### Defined in

[packages/mermaid/src/types.ts:56](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L56)

---

### diagramType

• **diagramType**: `string`
Expand All @@ -18,4 +30,4 @@ The diagram type, e.g. 'flowchart', 'sequence', etc.

#### Defined in

[packages/mermaid/src/types.ts:50](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L50)
[packages/mermaid/src/types.ts:52](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L52)
6 changes: 3 additions & 3 deletions docs/config/setup/interfaces/mermaid.RenderResult.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ bindFunctions?.(div); // To call bindFunctions only if it's present.

#### Defined in

[packages/mermaid/src/types.ts:73](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L73)
[packages/mermaid/src/types.ts:79](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L79)

---

Expand All @@ -51,7 +51,7 @@ The diagram type, e.g. 'flowchart', 'sequence', etc.

#### Defined in

[packages/mermaid/src/types.ts:63](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L63)
[packages/mermaid/src/types.ts:69](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L69)

---

Expand All @@ -63,4 +63,4 @@ The svg code for the rendered graph.

#### Defined in

[packages/mermaid/src/types.ts:59](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L59)
[packages/mermaid/src/types.ts:65](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/types.ts#L65)
2 changes: 1 addition & 1 deletion docs/ecosystem/integrations-community.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ Communication tools and platforms
- [Mermaid Extension](https://www.mediawiki.org/wiki/Extension:Mermaid)
- [PmWiki](https://www.pmwiki.org)
- [MermaidJs Cookbook recipe](https://www.pmwiki.org/wiki/Cookbook/MermaidJs)
- [Semantic Media Wiki](https://semantic-mediawiki.org)
- [Semantic Media Wiki](https://www.semantic-mediawiki.org)
- [Mermaid Plugin](https://github.com/SemanticMediaWiki/Mermaid)
- [TiddlyWiki](https://tiddlywiki.com/)
- [mermaid-tw5: wrapper for Mermaid Live](https://github.com/efurlanm/mermaid-tw5)
Expand Down
1 change: 1 addition & 0 deletions eslint.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export default tseslint.config(
'**/generated/',
'**/coverage/',
'packages/mermaid/src/config.type.ts',
'packages/mermaid/src/docs/.vitepress/components.d.ts',
],
},
{
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
"test": "pnpm lint && vitest run",
"test:watch": "vitest --watch",
"test:coverage": "vitest --coverage",
"test:check:tsc": "tsx scripts/tsc-check.ts",
"prepare": "husky && pnpm build",
"pre-commit": "lint-staged"
},
Expand Down Expand Up @@ -96,7 +97,7 @@
"eslint-plugin-cypress": "^3.3.0",
"eslint-plugin-html": "^8.1.1",
"eslint-plugin-jest": "^28.6.0",
"eslint-plugin-jsdoc": "^48.2.9",
"eslint-plugin-jsdoc": "^50.0.0",
"eslint-plugin-json": "^4.0.0",
"eslint-plugin-lodash": "^8.0.0",
"eslint-plugin-markdown": "^5.0.0",
Expand Down
12 changes: 6 additions & 6 deletions packages/mermaid-layout-elk/src/render.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
}: InternalHelpers,
{ algorithm }: RenderOptions
) => {
const nodeDb: Record<string, any> = {};

Check warning on line 24 in packages/mermaid-layout-elk/src/render.ts

View workflow job for this annotation

GitHub Actions / autofix

Unexpected any. Specify a different type
const clusterDb: Record<string, any> = {};

Check warning on line 25 in packages/mermaid-layout-elk/src/render.ts

View workflow job for this annotation

GitHub Actions / autofix

Unexpected any. Specify a different type

const addVertex = async (nodeEl: any, graph: { children: any[] }, nodeArr: any, node: any) => {

Check warning on line 27 in packages/mermaid-layout-elk/src/render.ts

View workflow job for this annotation

GitHub Actions / autofix

Unexpected any. Specify a different type

Check warning on line 27 in packages/mermaid-layout-elk/src/render.ts

View workflow job for this annotation

GitHub Actions / autofix

Unexpected any. Specify a different type

Check warning on line 27 in packages/mermaid-layout-elk/src/render.ts

View workflow job for this annotation

GitHub Actions / autofix

Unexpected any. Specify a different type

Check warning on line 27 in packages/mermaid-layout-elk/src/render.ts

View workflow job for this annotation

GitHub Actions / autofix

Unexpected any. Specify a different type
const labelData: any = { width: 0, height: 0 };

Check warning on line 28 in packages/mermaid-layout-elk/src/render.ts

View workflow job for this annotation

GitHub Actions / autofix

Unexpected any. Specify a different type

let boundingBox;
const child = {
Expand Down Expand Up @@ -67,8 +67,8 @@
};

const addVertices = async function (
nodeEl: any,

Check warning on line 70 in packages/mermaid-layout-elk/src/render.ts

View workflow job for this annotation

GitHub Actions / autofix

Unexpected any. Specify a different type
nodeArr: any[],

Check warning on line 71 in packages/mermaid-layout-elk/src/render.ts

View workflow job for this annotation

GitHub Actions / autofix

Unexpected any. Specify a different type
graph: {
id: string;
layoutOptions: {
Expand Down Expand Up @@ -224,7 +224,7 @@
* Add edges to graph based on parsed graph definition
*/
const addEdges = async function (
dataForLayout: { edges: any; direction: string },
dataForLayout: { edges: any; direction?: string },
graph: {
id?: string;
layoutOptions?: {
Expand Down Expand Up @@ -749,12 +749,12 @@
layoutOptions: {
'elk.hierarchyHandling': 'INCLUDE_CHILDREN',
'elk.algorithm': algorithm,
'nodePlacement.strategy': data4Layout.config.elk.nodePlacementStrategy,
'elk.layered.mergeEdges': data4Layout.config.elk.mergeEdges,
'nodePlacement.strategy': data4Layout.config.elk?.nodePlacementStrategy,
'elk.layered.mergeEdges': data4Layout.config.elk?.mergeEdges,
'elk.direction': 'DOWN',
'spacing.baseValue': 35,
'elk.layered.unnecessaryBendpoints': true,
'elk.layered.cycleBreaking.strategy': data4Layout.config.elk.cycleBreakingStrategy,
'elk.layered.cycleBreaking.strategy': data4Layout.config.elk?.cycleBreakingStrategy,
// 'spacing.nodeNode': 20,
// 'spacing.nodeNodeBetweenLayers': 25,
// 'spacing.edgeNode': 20,
Expand Down Expand Up @@ -837,8 +837,8 @@
...node.layoutOptions,
'elk.algorithm': algorithm,
'elk.direction': dir2ElkDirection(node.dir),
'nodePlacement.strategy': data4Layout.config['elk.nodePlacement.strategy'],
'elk.layered.mergeEdges': data4Layout.config['elk.mergeEdges'],
'nodePlacement.strategy': data4Layout.config.elk?.nodePlacementStrategy,
'elk.layered.mergeEdges': data4Layout.config.elk?.mergeEdges,
'elk.hierarchyHandling': 'SEPARATE_CHILDREN',
};
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { unknownIcon } from '$root/rendering-util/icons.js';
import { unknownIcon } from '../../rendering-util/icons.js';
import type { IconifyJSON } from '@iconify/types';

const wrapIcon = (icon: string) => {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { registerIconPacks } from '$root/rendering-util/icons.js';
import { registerIconPacks } from '../../rendering-util/icons.js';
import type { Position } from 'cytoscape';
import cytoscape from 'cytoscape';
import type { FcoseLayoutOptions } from 'cytoscape-fcose';
Expand Down
6 changes: 3 additions & 3 deletions packages/mermaid/src/diagrams/architecture/svgDraw.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getIconSVG } from '$root/rendering-util/icons.js';
import { getIconSVG } from '../../rendering-util/icons.js';
import type cytoscape from 'cytoscape';
import { getConfig } from '../../diagram-api/diagramAPI.js';
import { createText } from '../../rendering-util/createText.js';
Expand Down Expand Up @@ -170,8 +170,8 @@ export const drawEdges = async function (edgesEl: D3Element, cy: cytoscape.Core)
textElem.attr(
'transform',
`
translate(${midX}, ${midY - bboxOrig.height / 2})
translate(${(x * bboxNew.width) / 2}, ${(y * bboxNew.height) / 2})
translate(${midX}, ${midY - bboxOrig.height / 2})
translate(${(x * bboxNew.width) / 2}, ${(y * bboxNew.height) / 2})
rotate(${-1 * x * y * 45}, 0, ${bboxOrig.height / 2})
`
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ Communication tools and platforms
- [Mermaid Extension](https://www.mediawiki.org/wiki/Extension:Mermaid)
- [PmWiki](https://www.pmwiki.org)
- [MermaidJs Cookbook recipe](https://www.pmwiki.org/wiki/Cookbook/MermaidJs)
- [Semantic Media Wiki](https://semantic-mediawiki.org)
- [Semantic Media Wiki](https://www.semantic-mediawiki.org)
- [Mermaid Plugin](https://github.com/SemanticMediaWiki/Mermaid)
- [TiddlyWiki](https://tiddlywiki.com/)
- [mermaid-tw5: wrapper for Mermaid Live](https://github.com/efurlanm/mermaid-tw5)
Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/mermaid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Web page integration module for the mermaid framework. It uses the mermaidAPI for mermaid
* functionality and to render the diagrams to svg code!
*/
import { registerIconPacks } from '$root/rendering-util/icons.js';
import { registerIconPacks } from './rendering-util/icons.js';
import { dedent } from 'ts-dedent';
import type { MermaidConfig } from './config.type.js';
import { detectType, registerLazyLoadedDiagrams } from './diagram-api/detectType.js';
Expand Down
73 changes: 67 additions & 6 deletions packages/mermaid/src/mermaidAPI.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { vi, it, expect, describe, beforeEach } from 'vitest';
import { beforeEach, describe, expect, it, vi } from 'vitest';

// -------------------------------------
// Mocks and mocking
Expand Down Expand Up @@ -66,8 +66,8 @@ vi.mock('stylis', () => {
});

import { compile, serialize } from 'stylis';
import { decodeEntities, encodeEntities } from './utils.js';
import { Diagram } from './Diagram.js';
import { decodeEntities, encodeEntities } from './utils.js';
import { toBase64 } from './utils/base64.js';

/**
Expand Down Expand Up @@ -693,18 +693,79 @@ describe('mermaidAPI', () => {
await expect(mermaidAPI.parse('graph TD;A--x|text including URL space|B;')).resolves
.toMatchInlineSnapshot(`
{
"config": {},
"diagramType": "flowchart-v2",
}
`);
});
it('returns config when defined in frontmatter', async () => {
await expect(
mermaidAPI.parse(`---
config:
theme: base
flowchart:
htmlLabels: true
---
graph TD;A--x|text including URL space|B;`)
).resolves.toMatchInlineSnapshot(`
{
"config": {
"flowchart": {
"htmlLabels": true,
},
"theme": "base",
},
"diagramType": "flowchart-v2",
}
`);
});

it('returns config when defined in directive', async () => {
await expect(
mermaidAPI.parse(`%%{init: { 'theme': 'base' } }%%
graph TD;A--x|text including URL space|B;`)
).resolves.toMatchInlineSnapshot(`
{
"config": {
"theme": "base",
},
"diagramType": "flowchart-v2",
}
`);
});

it('returns merged config when defined in frontmatter and directive', async () => {
await expect(
mermaidAPI.parse(`---
config:
theme: forest
flowchart:
htmlLabels: true
---
%%{init: { 'theme': 'base' } }%%
graph TD;A--x|text including URL space|B;`)
).resolves.toMatchInlineSnapshot(`
{
"config": {
"flowchart": {
"htmlLabels": true,
},
"theme": "base",
},
"diagramType": "flowchart-v2",
}
`);
});

it('returns true for valid definition with silent option', async () => {
await expect(
mermaidAPI.parse('graph TD;A--x|text including URL space|B;', { suppressErrors: true })
).resolves.toMatchInlineSnapshot(`
{
"diagramType": "flowchart-v2",
}
`);
{
"config": {},
"diagramType": "flowchart-v2",
}
`);
});
});

Expand Down
4 changes: 2 additions & 2 deletions packages/mermaid/src/mermaidAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,9 +73,9 @@ async function parse(text: string, parseOptions?: ParseOptions): Promise<ParseRe
async function parse(text: string, parseOptions?: ParseOptions): Promise<ParseResult | false> {
addDiagrams();
try {
const { code } = processAndSetConfigs(text);
const { code, config } = processAndSetConfigs(text);
const diagram = await getDiagramFromText(code);
return { diagramType: diagram.type };
return { diagramType: diagram.type, config };
} catch (error) {
if (parseOptions?.suppressErrors) {
return false;
Expand Down
Loading
Loading