Skip to content

Commit

Permalink
Merge branch 'release/10.0.0' into sidv/esbuildV10
Browse files Browse the repository at this point in the history
* release/10.0.0:
  fix(#3406, #3394): Remove init & initThrowsErrors
  chore: Rename lazy loaded diagram definitions
  Skip flowchart-elk failing test
  • Loading branch information
sidharthv96 committed Feb 19, 2023
2 parents 1f5e676 + 4ea7294 commit f48e48d
Show file tree
Hide file tree
Showing 18 changed files with 219 additions and 130 deletions.
35 changes: 34 additions & 1 deletion V10-BreakingChanges.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

## Async

`init`, `parse`, `render` are now async.
`parse`, `render` are now async.

## Lazy loading and asynchronisity

Expand All @@ -23,3 +23,36 @@ try {
parseError(err);
}
```

## Init deprecated and InitThrowsErrors removed

The config passed to `init` was not being used eariler.
It will now be used.
The `init` function is deprecated and will be removed in the next major release.
init currently works as a wrapper to `initialize` and `run`.

```js
//< v10.0.0
mermaid.init(config, selector, cb);

//>= v10.0.0
mermaid.initialize(config);
mermaid.run({
querySelector: selector,
postRenderCallback: cb,
suppressErrors: true,
});
```

```js
//< v10.0.0
mermaid.initThrowsErrors(config, selector, cb);

//>= v10.0.0
mermaid.initialize(config);
mermaid.run({
querySelector: selector,
postRenderCallback: cb,
suppressErrors: false,
});
```
2 changes: 1 addition & 1 deletion cypress/integration/rendering/flowchart-elk.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ describe('Flowchart ELK', () => {
});
});

it('V2 elk - 16: Render Stadium shape', () => {
it.skip('V2 elk - 16: Render Stadium shape', () => {
imgSnapshotTest(
` flowchart-elk TD
A([stadium shape test])
Expand Down
2 changes: 1 addition & 1 deletion cypress/platform/external-diagrams-example-diagram.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ <h1>Should correctly load a third-party diagram using registerDiagram</h1>

await mermaid.registerExternalDiagrams([exampleDiagram]);
await mermaid.initialize({ logLevel: 0 });
await mermaid.initThrowsErrors();
await mermaid.run();
if (window.Cypress) {
window.rendered = true;
}
Expand Down
3 changes: 2 additions & 1 deletion cypress/platform/render-after-error.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@

<script type="module">
import mermaid from './mermaid.esm.mjs';
await mermaid.init({ startOnLoad: false });
await mermaid.initialize({ startOnLoad: false });
await mermaid.run();

await mermaid.mermaidAPI.initialize({ securityLevel: 'strict' });
try {
Expand Down
2 changes: 1 addition & 1 deletion cypress/platform/rerender.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

<script type="module">
import mermaid from './mermaid.esm.mjs';
mermaid.init({ startOnLoad: false });
mermaid.initialize({ startOnLoad: false });
mermaid.mermaidAPI.initialize();

async function rerender(text) {
Expand Down
19 changes: 19 additions & 0 deletions docs/config/setup/interfaces/mermaidAPI.ParseOptions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
> **Warning**
>
> ## THIS IS AN AUTOGENERATED FILE. DO NOT EDIT.
>
> ## Please edit the corresponding file in [/packages/mermaid/src/docs/config/setup/interfaces/mermaidAPI.ParseOptions.md](../../../../packages/mermaid/src/docs/config/setup/interfaces/mermaidAPI.ParseOptions.md).
# Interface: ParseOptions

[mermaidAPI](../modules/mermaidAPI.md).ParseOptions

## Properties

### suppressErrors

`Optional` **suppressErrors**: `boolean`

#### Defined in

[mermaidAPI.ts:70](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L70)
4 changes: 2 additions & 2 deletions docs/config/setup/interfaces/mermaidAPI.RenderResult.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ element will be removed when rendering is completed.

#### Defined in

[mermaidAPI.ts:385](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L385)
[mermaidAPI.ts:387](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L387)

---

Expand All @@ -75,4 +75,4 @@ element will be removed when rendering is completed.

#### Defined in

[mermaidAPI.ts:384](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L384)
[mermaidAPI.ts:386](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L386)
25 changes: 13 additions & 12 deletions docs/config/setup/modules/mermaidAPI.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

## Interfaces

- [ParseOptions](../interfaces/mermaidAPI.ParseOptions.md)
- [RenderResult](../interfaces/mermaidAPI.RenderResult.md)

## References
Expand All @@ -24,13 +25,13 @@ Renames and re-exports [mermaidAPI](mermaidAPI.md#mermaidapi)

#### Defined in

[mermaidAPI.ts:71](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L71)
[mermaidAPI.ts:75](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L75)

## Variables

### mermaidAPI

`Const` **mermaidAPI**: `Readonly`<{ `defaultConfig`: `MermaidConfig` = configApi.defaultConfig; `getConfig`: () => `MermaidConfig` = configApi.getConfig; `getSiteConfig`: () => `MermaidConfig` = configApi.getSiteConfig; `globalReset`: () => `void` ; `initialize`: (`options`: `MermaidConfig`) => `void` ; `parse`: (`text`: `string`, `parseOptions?`: { `silent?`: `boolean` }) => `Promise`<`boolean` | `void`> ; `parseDirective`: (`p`: `any`, `statement`: `string`, `context`: `string`, `type`: `string`) => `void` ; `render`: (`id`: `string`, `text`: `string`, `svgContainingElement?`: `Element`) => `Promise`<[`RenderResult`](../interfaces/mermaidAPI.RenderResult.md)> ; `reset`: () => `void` ; `setConfig`: (`conf`: `MermaidConfig`) => `MermaidConfig` = configApi.setConfig; `updateSiteConfig`: (`conf`: `MermaidConfig`) => `MermaidConfig` = configApi.updateSiteConfig }>
`Const` **mermaidAPI**: `Readonly`<{ `defaultConfig`: `MermaidConfig` = configApi.defaultConfig; `getConfig`: () => `MermaidConfig` = configApi.getConfig; `getSiteConfig`: () => `MermaidConfig` = configApi.getSiteConfig; `globalReset`: () => `void` ; `initialize`: (`options`: `MermaidConfig`) => `void` ; `parse`: (`text`: `string`, `parseOptions?`: [`ParseOptions`](../interfaces/mermaidAPI.ParseOptions.md)) => `Promise`<`boolean` | `void`> ; `parseDirective`: (`p`: `any`, `statement`: `string`, `context`: `string`, `type`: `string`) => `void` ; `render`: (`id`: `string`, `text`: `string`, `svgContainingElement?`: `Element`) => `Promise`<[`RenderResult`](../interfaces/mermaidAPI.RenderResult.md)> ; `reset`: () => `void` ; `setConfig`: (`conf`: `MermaidConfig`) => `MermaidConfig` = configApi.setConfig; `updateSiteConfig`: (`conf`: `MermaidConfig`) => `MermaidConfig` = configApi.updateSiteConfig }>

## mermaidAPI configuration defaults

Expand Down Expand Up @@ -94,7 +95,7 @@ mermaid.initialize(config);

#### Defined in

[mermaidAPI.ts:669](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L669)
[mermaidAPI.ts:671](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L671)

## Functions

Expand Down Expand Up @@ -125,7 +126,7 @@ Return the last node appended

#### Defined in

[mermaidAPI.ts:292](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L292)
[mermaidAPI.ts:294](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L294)

---

Expand All @@ -151,7 +152,7 @@ the cleaned up svgCode

#### Defined in

[mermaidAPI.ts:243](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L243)
[mermaidAPI.ts:245](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L245)

---

Expand All @@ -177,7 +178,7 @@ the string with all the user styles

#### Defined in

[mermaidAPI.ts:172](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L172)
[mermaidAPI.ts:174](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L174)

---

Expand All @@ -200,7 +201,7 @@ the string with all the user styles

#### Defined in

[mermaidAPI.ts:220](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L220)
[mermaidAPI.ts:222](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L222)

---

Expand All @@ -227,7 +228,7 @@ with an enclosing block that has each of the cssClasses followed by !important;

#### Defined in

[mermaidAPI.ts:156](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L156)
[mermaidAPI.ts:158](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L158)

---

Expand All @@ -247,7 +248,7 @@ with an enclosing block that has each of the cssClasses followed by !important;

#### Defined in

[mermaidAPI.ts:136](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L136)
[mermaidAPI.ts:138](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L138)

---

Expand All @@ -267,7 +268,7 @@ with an enclosing block that has each of the cssClasses followed by !important;

#### Defined in

[mermaidAPI.ts:107](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L107)
[mermaidAPI.ts:109](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L109)

---

Expand All @@ -293,7 +294,7 @@ Put the svgCode into an iFrame. Return the iFrame code

#### Defined in

[mermaidAPI.ts:271](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L271)
[mermaidAPI.ts:273](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L273)

---

Expand All @@ -318,4 +319,4 @@ Remove any existing elements from the given document

#### Defined in

[mermaidAPI.ts:342](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L342)
[mermaidAPI.ts:344](https://github.com/mermaid-js/mermaid/blob/master/packages/mermaid/src/mermaidAPI.ts#L344)
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/flowchart/elk/detector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ const detector: DiagramDetector = (txt: string, config?: MermaidConfig): boolean
};

const loader = async () => {
const { diagram } = await import('./diagram-definition.js');
const { diagram } = await import('./flowchart-elk-definition.js');
return { id, diagram };
};

Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/mindmap/detector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const detector = (txt: string) => {
};

const loader = async () => {
const { diagram } = await import('./diagram-definition.js');
const { diagram } = await import('./mindmap-definition.js');
return { id, diagram };
};

Expand Down
2 changes: 1 addition & 1 deletion packages/mermaid/src/diagrams/timeline/detector.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const detector = (txt: string) => {
};

const loader = async () => {
const { diagram } = await import('./diagram-definition.js');
const { diagram } = await import('./timeline-definition.js');
return { id, diagram };
};

Expand Down
28 changes: 17 additions & 11 deletions packages/mermaid/src/mermaid.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,41 +14,43 @@ describe('when using mermaid and ', () => {
it('should not start rendering with mermaid.startOnLoad set to false', async () => {
mermaid.startOnLoad = false;
document.body.innerHTML = '<div class="mermaid">graph TD;\na;</div>';
spyOn(mermaid, 'init');
spyOn(mermaid, 'run');
mermaid.contentLoaded();
expect(mermaid.init).not.toHaveBeenCalled();
expect(mermaid.run).not.toHaveBeenCalled();
});

it('should start rendering with both startOnLoad set', async () => {
mermaid.startOnLoad = true;
document.body.innerHTML = '<div class="mermaid">graph TD;\na;</div>';
spyOn(mermaid, 'init');
spyOn(mermaid, 'run');
mermaid.contentLoaded();
expect(mermaid.init).toHaveBeenCalled();
expect(mermaid.run).toHaveBeenCalled();
});

it('should start rendering with mermaid.startOnLoad', async () => {
mermaid.startOnLoad = true;
document.body.innerHTML = '<div class="mermaid">graph TD;\na;</div>';
spyOn(mermaid, 'init');
spyOn(mermaid, 'run');
mermaid.contentLoaded();
expect(mermaid.init).toHaveBeenCalled();
expect(mermaid.run).toHaveBeenCalled();
});

it('should start rendering as a default with no changes performed', async () => {
document.body.innerHTML = '<div class="mermaid">graph TD;\na;</div>';
spyOn(mermaid, 'init');
spyOn(mermaid, 'run');
mermaid.contentLoaded();
expect(mermaid.init).toHaveBeenCalled();
expect(mermaid.run).toHaveBeenCalled();
});
});

describe('when using #initThrowsErrors', () => {
describe('when using #run', () => {
it('should accept single node', async () => {
const node = document.createElement('div');
node.appendChild(document.createTextNode('graph TD;\na;'));

await mermaid.initThrowsErrors(undefined, node);
await mermaid.run({
nodes: [node],
});
// mermaidAPI.render function has been mocked, since it doesn't yet work
// in Node.JS (only works in browser)
expect(mermaidAPI.render).toHaveBeenCalled();
Expand All @@ -73,7 +75,11 @@ describe('when using mermaid and ', () => {
)
).rejects.toThrow('Failed to load 1 external diagrams');

expect(() => mermaid.initThrowsErrors(undefined, node)).not.toThrow();
await expect(
mermaid.run({
nodes: [node],
})
).resolves.not.toThrow();
// should still render, even if lazyLoadedDiagrams fails
expect(mermaidAPI.render).toHaveBeenCalled();
});
Expand Down
Loading

0 comments on commit f48e48d

Please sign in to comment.