Compare commits

...
Author SHA1 Message Date
Sidharth VinodandGitHub 365d8807cd Merge branch 'master' into release/10.0.1 2023-02-28 22:46:52 +05:30
Sidharth Vinod a511e7d6b5 "mermaid": "10.0.1-rc.3", 2023-02-28 22:20:17 +05:30
Sidharth Vinod 4cc7c401b5 10.0.1-rc.2 2023-02-24 19:48:54 +05:30
Sidharth Vinod d6c25b77f7 10.0.1-rc.1 2023-02-24 18:29:34 +05:30
Sidharth VinodandGitHub 1605536f13 Merge pull request #1164 from mermaid-js/develop
Release v10
2023-02-24 10:51:07 +05:30
Sidharth VinodandGitHub 7dc59f1396 Merge pull request #1160 from mermaid-js/release/10.0.0
Release/10.0.0
2023-02-24 10:50:07 +05:30
Sidharth Vinod 59168d2437 fix: re enable uncompressed URL test 2023-02-24 10:37:29 +05:30
Sidharth Vinod 5a6dccb263 fix: Comment test caret location 2023-02-24 10:36:20 +05:30
Sidharth Vinod 6c16fa76ff fix: Adjust image size 2023-02-24 10:32:10 +05:30
Sidharth Vinod ccbb45a09c fix: E2e Tests 2023-02-24 10:10:52 +05:30
Sidharth Vinod 052665ef09 Actions, default closed 2023-02-22 10:01:16 +05:30
Sidharth Vinod ee1652e9f2 v10 2023-02-21 17:46:00 +05:30
Sidharth Vinod bbd6378065 v10 changes 2023-02-19 20:09:42 +05:30
Sidharth Vinod e93641e41f Release v10 2023-02-19 19:49:50 +05:30
Sidharth Vinod 5925448ca4 Replace moment with dayjs 2023-02-19 00:14:57 +05:30
Sidharth Vinod 5e930d19e7 Merge remote-tracking branch 'origin/develop' into release/9.4
* origin/develop:
  Fix browserlist base branch
  build: update Browserslist db
  Move browserlist update to cron
  Update Browserslist
  Update snapshots
  Fix Preset
  Update Browserslist
  chore(deps): update all non-major dependencies
  chore(deps): update all non-major dependencies
  chore: Cleanup with eslint-unicorn
  Fix tests
  Fix tests
  Update loadSite.spec.ts
  Update snapshots.js
  Also changed 'graph' to 'flowchart' on state.ts
  Replacing "chart" with "flowchart"
2023-02-16 21:04:47 +05:30
Sidharth VinodandGitHub 131dd06cde Merge pull request #1158 from mermaid-js/develop
Release 9.4
2023-02-16 21:02:05 +05:30
Sidharth VinodandGitHub e96225dc69 Merge branch 'master' into develop 2023-02-16 18:02:16 +05:30
Sidharth VinodandGitHub 3a42afd102 Merge pull request #1156 from mermaid-js/browserslist-update
build: update Browserslist db
2023-02-16 17:34:26 +05:30
Sidharth Vinod 5394074ac5 Fix browserlist base branch 2023-02-16 17:33:42 +05:30
Sidharth Vinod 20358bc254 Remove mindmap 2023-02-16 15:56:30 +05:30
Sidharth Vinod 6ece0a8a94 comment out consoles 2023-02-16 15:55:07 +05:30
Sidharth Vinod 71f4097fa0 Log SVG code 2023-02-16 15:51:53 +05:30
Sidharth Vinod 308aec1580 Merge branch 'release/9.4' of https://github.com/mermaid-js/mermaid-live-editor into release/9.4
* 'release/9.4' of https://github.com/mermaid-js/mermaid-live-editor:
  Update Browserslist
2023-02-16 15:48:06 +05:30
Sidharth Vinod 8c07649b10 Remove mindmap 2023-02-16 15:48:02 +05:30
sidharthv96 3a1b8f87c3 Update Browserslist 2023-02-16 10:02:52 +00:00
Sidharth Vinod af4f60874e 9.4.0 2023-02-16 15:31:31 +05:30
GitHub Action e5f303e6e2 build: update Browserslist db 2023-02-15 02:44:06 +00:00
Sidharth VinodandGitHub e461f108f1 Merge pull request #1106 from mermaid-js/sidv/eslint-unicorn
Cleanup with eslint-unicorn
2023-02-10 19:25:54 +00:00
Sidharth VinodandGitHub 64519ba8a1 Merge pull request #1153 from mermaid-js/sidv/browserlist
Move browserlist update to cron
2023-02-10 19:09:03 +00:00
Sidharth Vinod ec5937b4fb Move browserlist update to cron 2023-02-11 00:32:39 +05:30
sidharthv96 10a11cfc32 Update Browserslist 2023-02-10 18:53:40 +00:00
Sidharth Vinod 9ebbd3b36c Merge remote-tracking branch 'origin/develop' into sidv/eslint-unicorn
* origin/develop: (51 commits)
  Update snapshots
  Fix Preset
  Update Browserslist
  chore(deps): update all non-major dependencies
  chore(deps): update all non-major dependencies
  chore(deps): update dependency eslint to v8.33.0
  chore(deps): update all non-major dependencies
  chore(deps): update all non-major dependencies
  chore(deps): update all non-major dependencies
  chore(deps): update all non-major dependencies
  chore(deps): update dependency eslint to v8.30.0
  Fix links
  chore(deps): update all non-major dependencies
  SvelteKit 1.0!
  Update sveltekit
  Skip updatebrowserslit on renovate
  v9.3.0
  mermaid 9.3.0-rc.7
  Fix vite.config.js typing
  mermaid 9.3.0-rc.6
  ...
2023-02-11 00:22:23 +05:30
Sidharth VinodandGitHub 9e25c2d2c4 Merge pull request #654 from victorp13/patch-1
Replacing "graph" with "flowchart"
2023-02-08 12:43:51 +05:30
Sidharth Vinod 9853442201 Update snapshots 2023-02-08 00:16:46 +05:30
Sidharth VinodandGitHub ebca0ebe34 Merge pull request #1151 from mermaid-js/renovate/all-minor-patch
chore(deps): update all non-major dependencies (minor)
2023-02-08 00:15:29 +05:30
Sidharth Vinod abb2405436 Merge branch 'patch-1' of https://github.com/victorp13/mermaid-live-editor into pr/victorp13/654
* 'patch-1' of https://github.com/victorp13/mermaid-live-editor:
  Update Browserslist
2023-02-08 00:09:31 +05:30
Sidharth Vinod a6b1254425 Fix Preset 2023-02-08 00:09:26 +05:30
sidharthv96 95bf41d3e6 Update Browserslist 2023-02-07 18:38:28 +00:00
Sidharth Vinod 68f81df59b Merge remote-tracking branch 'origin/develop' into pr/victorp13/654
* origin/develop: (509 commits)
  chore(deps): update all non-major dependencies
  chore(deps): update dependency eslint to v8.33.0
  chore(deps): update all non-major dependencies
  chore(deps): update all non-major dependencies
  chore(deps): update all non-major dependencies
  chore(deps): update all non-major dependencies
  chore(deps): update dependency eslint to v8.30.0
  Fix links
  chore(deps): update all non-major dependencies
  SvelteKit 1.0!
  Update sveltekit
  Skip updatebrowserslit on renovate
  v9.3.0
  mermaid 9.3.0-rc.7
  Fix vite.config.js typing
  mermaid 9.3.0-rc.6
  rc.5
  fix: Adjust image size
  Update to rc.4
  Update to rc.3
  ...
2023-02-08 00:05:14 +05:30
renovate[bot]andGitHub d3b25e5cb8 chore(deps): update all non-major dependencies 2023-02-07 18:30:45 +00:00
Sidharth VinodandGitHub 65c1ea844c Merge pull request #1145 from mermaid-js/renovate/patch-all-minor-patch
chore(deps): update all non-major dependencies (patch)
2023-02-07 23:59:00 +05:30
renovate[bot]andGitHub 864988e24a chore(deps): update all non-major dependencies 2023-02-07 09:28:56 +00:00
sidharthv96 2fc032f58a Update Browserslist 2023-01-31 16:36:15 +00:00
Sidharth Vinod 2033e9002f 9.4.0-rc.1 2023-01-31 22:04:56 +05:30
Sidharth VinodandGitHub 651a5cb7ef Merge pull request #1146 from mermaid-js/renovate/all-minor-patch
chore(deps): update dependency eslint to v8.33.0
2023-01-30 09:20:01 +05:30
renovate[bot]andGitHub a7454aa8cb chore(deps): update dependency eslint to v8.33.0 2023-01-30 02:01:16 +00:00
Sidharth VinodandGitHub 43ff34178e Merge pull request #1142 from mermaid-js/renovate/all-minor-patch
chore(deps): update all non-major dependencies (minor)
2023-01-29 01:19:45 +05:30
renovate[bot]andGitHub 703744ebf3 chore(deps): update all non-major dependencies 2023-01-27 20:34:14 +00:00
Sidharth VinodandGitHub 15eaee6e9b Merge pull request #1120 from mermaid-js/renovate/patch-all-minor-patch
chore(deps): update all non-major dependencies (patch)
2023-01-21 22:47:07 +05:30
renovate[bot]andGitHub fa9b0344f4 chore(deps): update all non-major dependencies 2023-01-21 14:29:26 +00:00
Sidharth VinodandGitHub 965b39c2f2 Merge pull request #1138 from mermaid-js/renovate/all-minor-patch
chore(deps): update all non-major dependencies (minor)
2023-01-17 21:38:40 +05:30
renovate[bot]andGitHub 26908080cb chore(deps): update all non-major dependencies 2023-01-16 18:05:56 +00:00
Sidharth VinodandGitHub 7c64a65497 Merge pull request #1128 from mermaid-js/renovate/all-minor-patch
chore(deps): update all non-major dependencies (minor)
2022-12-27 13:06:37 +05:30
renovate[bot]andGitHub be75d950bd chore(deps): update all non-major dependencies 2022-12-26 21:02:04 +00:00
Sidharth VinodandGitHub 4022d8d872 Merge pull request #1127 from mermaid-js/renovate/all-minor-patch
chore(deps): update dependency eslint to v8.30.0
2022-12-19 10:24:48 +05:30
renovate[bot]andGitHub ccb294e5df chore(deps): update dependency eslint to v8.30.0 2022-12-19 02:44:15 +00:00
Sidharth Vinod 8d1f3f08f8 Merge branch 'develop' of https://github.com/mermaid-js/mermaid-live-editor into develop
* 'develop' of https://github.com/mermaid-js/mermaid-live-editor:
  chore(deps): update all non-major dependencies
2022-12-17 00:17:50 +05:30
Sidharth Vinod a12e9a3e6d Fix links 2022-12-17 00:17:44 +05:30
Sidharth VinodandGitHub c138e1dc94 Merge pull request #1121 from mermaid-js/renovate/all-minor-patch
chore(deps): update all non-major dependencies (minor)
2022-12-17 00:15:30 +05:30
renovate[bot]andGitHub 74431cdc08 chore(deps): update all non-major dependencies 2022-12-15 15:09:41 +00:00
Sidharth VinodandGitHub 0812b84487 Merge pull request #1124 from mermaid-js/develop
Svelte Kit 1.0 🥳 🍾
2022-12-15 17:50:45 +05:30
Sidharth Vinod cfc5567980 SvelteKit 1.0! 2022-12-15 17:42:40 +05:30
Sidharth Vinod 096f005938 Merge branch 'develop' of https://github.com/mermaid-js/mermaid-live-editor into develop
* 'develop' of https://github.com/mermaid-js/mermaid-live-editor:
  v9.3.0
  mermaid 9.3.0-rc.7
  Fix vite.config.js typing
  mermaid 9.3.0-rc.6
  rc.5
  fix: Adjust image size
  Update to rc.4
  Update to rc.3
  Remove card snapshot
  Update snapshot
  Update to rc.2
  Update Browserslist
  9.3.0-rc.1
2022-12-15 17:31:41 +05:30
Sidharth VinodandGitHub 37d96f9a87 Merge pull request #1123 from mermaid-js/develop
Release 9.3.0
2022-12-15 17:31:14 +05:30
Sidharth Vinod 8c4b7d52d1 Update sveltekit 2022-12-15 17:30:58 +05:30
Sidharth VinodandGitHub cc7411fef8 Merge pull request #1119 from mermaid-js/release/9.3
9.3.0
2022-12-15 17:23:26 +05:30
Sidharth Vinod 1382504456 Skip updatebrowserslit on renovate 2022-12-15 17:20:39 +05:30
Sidharth Vinod 860039a924 v9.3.0 2022-12-15 17:18:24 +05:30
Sidharth Vinod 33a4cbbf78 mermaid 9.3.0-rc.7 2022-12-15 09:15:35 +05:30
Sidharth Vinod 7be86b5fa7 Fix vite.config.js typing 2022-12-14 10:18:21 +05:30
Sidharth Vinod b835e0448d mermaid 9.3.0-rc.6 2022-12-14 09:46:51 +05:30
Sidharth Vinod 7c5f9f1661 rc.5 2022-12-13 13:46:35 +05:30
Sidharth Vinod 0a34cbe9c7 fix: Adjust image size 2022-12-13 12:19:02 +05:30
Sidharth Vinod a2146da8e1 Update to rc.4 2022-12-13 00:40:18 +05:30
Sidharth Vinod d23de5f9e0 Update to rc.3 2022-12-13 00:24:54 +05:30
Sidharth Vinod 7d18fa6b95 Remove card snapshot 2022-12-13 00:11:03 +05:30
Sidharth Vinod 8dbb011b98 Update snapshot 2022-12-13 00:08:20 +05:30
Sidharth Vinod 4c398ed8dd Merge branch 'release/9.3' of https://github.com/mermaid-js/mermaid-live-editor into release/9.3
* 'release/9.3' of https://github.com/mermaid-js/mermaid-live-editor:
  Update Browserslist
2022-12-12 23:58:04 +05:30
Sidharth Vinod 532e7a6537 Update to rc.2 2022-12-12 23:57:59 +05:30
Sidharth Vinod 049635cf3a Update docs button title 2022-12-12 22:34:09 +05:30
sidharthv96 c06511f11f Update Browserslist 2022-12-09 07:14:05 +00:00
Sidharth Vinod e6adff074a 9.3.0-rc.1 2022-12-09 12:42:48 +05:30
Sidharth VinodandGitHub 55988eb750 Merge pull request #1115 from mermaid-js/renovate/patch-all-minor-patch
chore(deps): update all non-major dependencies (patch)
2022-12-06 23:05:09 +05:30
Sidharth VinodandGitHub e368a20b8d Merge pull request #1116 from mermaid-js/renovate/all-minor-patch
chore(deps): update all non-major dependencies (minor)
2022-12-06 23:04:45 +05:30
Sidharth VinodandGitHub 3cc56a0348 Merge pull request #1117 from aswinthaikkat/updatereadme
docs: Improve installation steps
2022-12-06 22:34:29 +05:30
aswin 36b7aba2f4 docs: Add dependency install step 2022-12-06 22:33:16 +05:30
aswin 54485ac068 docs: Improve installation steps 2022-12-06 22:22:41 +05:30
renovate[bot] fc6cf1f014 Update Browserslist 2022-12-05 01:28:05 +00:00
renovate[bot] 048f280b8e Update Browserslist 2022-12-05 01:27:32 +00:00
renovate[bot]andGitHub 19f26ce4b9 chore(deps): update all non-major dependencies 2022-12-05 01:26:57 +00:00
renovate[bot]andGitHub 6f115d4ac2 chore(deps): update all non-major dependencies 2022-12-05 01:26:30 +00:00
Sidharth VinodandGitHub 347d669c9c Merge pull request #1109 from mermaid-js/develop
Release
2022-11-30 14:25:43 +05:30
Sidharth VinodandGitHub df7da711a9 Merge branch 'master' into develop 2022-11-30 14:19:16 +05:30
Sidharth VinodandGitHub 282dfcc701 Merge pull request #1114 from lagraham337/develop
Nav: Fixed broken tutorial link
2022-11-30 14:18:24 +05:30
Lauren Graham 998c5f7fd9 Nav: Fixed broken tutorial link 2022-11-29 20:54:26 -08:00
Sidharth VinodandGitHub 6c907c48c7 Merge pull request #1113 from mermaid-js/renovate/patch-all-minor-patch
chore(deps): update all non-major dependencies (patch)
2022-11-28 10:33:29 +05:30
renovate[bot]andGitHub fe981b7646 chore(deps): update all non-major dependencies 2022-11-28 01:03:14 +00:00
Sidharth Vinod e36b1d42e4 chore: Skip uncompressed URL test 2022-11-25 16:15:01 +05:30
Sidharth Vinod a62a65ea05 Try something 2022-11-25 14:33:49 +05:30
Sidharth Vinod d9cdab3528 test: Change test order 2022-11-25 14:28:45 +05:30
Sidharth VinodandGitHub 5b3b0a499e Merge pull request #1108 from mermaid-js/develop
Release
2022-11-25 14:19:21 +05:30
Sidharth Vinod 6888765e37 Merge branch 'master' into sidv/eslint-unicorn
* master:
2022-11-25 13:06:08 +05:30
Sidharth Vinod 25e186158d chore: Cleanup with eslint-unicorn 2022-11-25 13:05:57 +05:30
Sidharth VinodandGitHub 4453a04a05 Merge pull request #1104 from mermaid-js/develop
Release
2022-11-24 22:14:04 +05:30
Sidharth Vinod bf06bdf71a Fix tests 2022-02-22 23:05:18 +05:30
Sidharth Vinod 68a0d29320 Fix tests 2022-02-22 22:28:32 +05:30
Victor PikulaandGitHub 14ac5f23a5 Update loadSite.spec.ts 2022-02-22 15:17:57 +01:00
Victor PikulaandGitHub e7676cf4a8 Update snapshots.js 2022-02-22 15:17:19 +01:00
Victor PikulaandGitHub 0f34a76ded Also changed 'graph' to 'flowchart' on state.ts 2022-02-21 15:51:32 +01:00
Victor PikulaandGitHub ee934c60b4 Replacing "chart" with "flowchart"
Since the documentation mentions "flowchart" in the example pages, it makes more sense to also show a flowchart as the first example loaded in the editor. It looks to me like "graph" was deprecated? Not 100% sure.
2022-02-16 09:36:26 +01:00
36 changed files with 1252 additions and 979 deletions
+38 -2
View File
@@ -6,9 +6,18 @@ module.exports = {
'plugin:@typescript-eslint/recommended',
// 'plugin:@typescript-eslint/recommended-requiring-type-checking',
'plugin:@typescript-eslint/strict',
'plugin:unicorn/recommended',
'prettier'
],
plugins: ['svelte3', 'tailwindcss', '@typescript-eslint', 'es', 'vitest', 'no-only-tests'],
plugins: [
'svelte3',
'tailwindcss',
'@typescript-eslint',
'es',
'vitest',
'no-only-tests',
'unicorn'
],
ignorePatterns: [
'docs/*',
'*.cjs',
@@ -59,6 +68,33 @@ module.exports = {
'@typescript-eslint/no-unsafe-assignment': 'off',
'es/no-regexp-lookbehind-assertions': 'error',
curly: ['error', 'all'],
'no-only-tests/no-only-tests': 'error'
'no-only-tests/no-only-tests': 'error',
'unicorn/no-null': 'off',
'unicorn/filename-case': [
'error',
{
case: 'camelCase'
}
],
'unicorn/prevent-abbreviations': [
'error',
{
allowList: {
ctx: true,
db: true,
doc: true,
env: true,
fn: true,
i: true,
param: true,
req: true,
res: true,
str: true,
searchParams: true,
temp: true,
ImportMetaEnv: true
}
}
]
}
};
+27 -13
View File
@@ -1,18 +1,32 @@
name: Update Browserslist
name: Update Browserslist database
on:
push:
branches-ignore:
- 'develop'
- 'master'
schedule:
- cron: '0 2 1,15 * *'
permissions:
contents: write
pull-requests: write
jobs:
build:
update-browserslist-database:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- run: npx browserslist@latest --update-db
- name: Commit changes
uses: EndBug/add-and-commit@v9
- name: Checkout repository
uses: actions/checkout@v3
with:
author_name: ${{ github.actor }}
author_email: ${{ github.actor }}@users.noreply.github.com
message: 'Update Browserslist'
fetch-depth: 0
- name: Configure git
run: |
git config --global user.email "action@github.com"
git config --global user.name "GitHub Action"
- name: Update Browserslist database and create PR if applies
uses: c2corg/browserslist-update-action@v2
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: browserslist-update
base_branch: develop
commit_message: 'build: update Browserslist db'
title: 'build: update Browserslist db'
body: Auto-generated by [browserslist-update-action](https://github.com/c2corg/browserslist-update-action/)
labels: 'chores, github action'
+15 -1
View File
@@ -1,6 +1,20 @@
{
"editor.formatOnSave": true,
"cSpell.words": ["asyncable", "KROKI", "mindmap", "pako", "Serde", "serdes", "tailwindcss"],
"cSpell.words": [
"Browserslist",
"KROKI",
"Serde",
"asyncable",
"corg",
"cssnano",
"daisyui",
"esserializer",
"localstorage",
"mindmap",
"pako",
"serdes",
"tailwindcss"
],
"vitest.commandLine": "yarn test:unit",
"vitest.enable": true,
"testing.autoRun.mode": "rerun",
+1 -1
View File
@@ -6,7 +6,7 @@
# Stop : press ctrl + c
# or
# docker stop mermaid-live-editor
FROM node:18.12.1 as mermaid-live-editor-builder
FROM node:18.14.0 as mermaid-live-editor-builder
COPY --chown=node:node . /home
WORKDIR /home
RUN yarn install
+9 -6
View File
@@ -47,17 +47,20 @@ Then open http://localhost:8000
## Setup
[Volta](https://volta.sh) is used for managing node and yarn versions.
Below link will help you making a copy of the repository in your local system.
This project is set up using [Yarn](https://classic.yarnpkg.com/en/docs/getting-started):
https://docs.github.com/en/get-started/quickstart/fork-a-repo
```
yarn install
```
## Requirements
- [volta](https://volta.sh/) to manage node versions.
- [Node.js](https://nodejs.org/en/). `volta install node`
- [yarn](https://yarnpkg.com/) package manager. `volta install yarn`
## Development
```
```sh
yarn install
yarn dev -- --open
```
+7 -6
View File
@@ -1,8 +1,9 @@
import { verifyFileSize } from './util';
import { verifyFileSizeGreaterThan } from './util';
describe('Check actions', () => {
beforeEach(() => {
cy.clearLocalStorage();
cy.visit('/edit');
cy.contains('Actions').click();
});
it('should update markdown code', () => {
@@ -18,7 +19,7 @@ describe('Check actions', () => {
});
});
it('should load gists from URL', () => {
it.skip('should load gists from URL', () => {
cy.get('#gist').type('https://gist.github.com/sidharthv96/6268a23e673a533dcb198f241fd7012a');
cy.contains('Load Gist').click();
cy.contains('Go shopping!!');
@@ -28,20 +29,20 @@ describe('Check actions', () => {
cy.clock(new Date(2022, 0, 1).getTime());
cy.get(`#downloadPNG`).click();
verifyFileSize('diagram', 'png', 21_000);
verifyFileSizeGreaterThan('diagram', 'png', 35_000);
cy.get(`#downloadSVG`).click();
verifyFileSize('diagram', 'svg', 10_000);
verifyFileSizeGreaterThan('diagram', 'svg', 10_000);
// Verify downloaded file is different for different diagrams
cy.contains('Sample Diagrams').click();
cy.contains('ER').click();
cy.get(`#downloadPNG`).click();
verifyFileSize('diagram', 'png', 46_000);
verifyFileSizeGreaterThan('diagram', 'png', 40_000);
cy.get(`#downloadSVG`).click();
verifyFileSize('diagram', 'svg', 12_000);
verifyFileSizeGreaterThan('diagram', 'svg', 11_000);
cy.clock().invoke('restore');
});
+1 -1
View File
@@ -49,7 +49,7 @@ describe('Auto sync tests', () => {
});
it('supports commenting code out/in', () => {
getEditor().type(`{uparrow}${cmd}/`);
getEditor({ bottom: true, newline: false }).type(`{uparrow}${cmd}/`);
cy.get('#view').contains('Car').should('not.exist');
getEditor().type(`{uparrow}${cmd}/`);
+3 -5
View File
@@ -6,7 +6,6 @@ describe('Save History', () => {
cy.clearLocalStorage();
cy.visit('/edit');
cy.contains('Actions').click();
cy.contains('History').click();
});
@@ -24,7 +23,6 @@ describe('Save History', () => {
'[{"state":{"code":"graph TD\\n A[New Year] -->|Get money| B(Go shopping)","mermaid":"{\\n \\"theme\\": \\"dark\\"\\n}","autoSync":true,"updateDiagram":false},"time":0,"type":"auto","id":"69ea820e-522b-4a44-86cf-fd58acde09df","name":"barking-dog"},{"state":{"code":"graph TD\\n A[Christmas] -->|Get money| B(Go shopping)","mermaid":"{\\n \\"theme\\": \\"dark\\"\\n}","autoSync":true,"updateDiagram":true},"time":0,"type":"manual","id":"x749ffc6-21dd-418a-b984-7c1ffc3146b3","name":"needy-mosquito"}]'
);
cy.reload();
cy.contains('Actions').click();
cy.contains('History').click();
cy.get('#historyList').find('li').should('have.length', 2);
cy.get('#historyList').find('No items in History').should('not.exist');
@@ -84,15 +82,15 @@ describe('Save History', () => {
// TODO: Fix #639
xit('should auto save history', () => {
getEditor().type(' C --> HistoryTest');
cy.tick(70000);
cy.tick(70_000);
cy.contains('Timeline').click();
cy.get('#historyList').find('li').should('have.length', 1);
cy.get('#editor').type('ing');
cy.tick(70000);
cy.tick(70_000);
cy.get('#historyList').find('li').should('have.length', 2);
for (let i = 0; i < 31; i++) {
cy.get('#editor').type('.');
cy.tick(70000);
cy.tick(70_000);
}
cy.get('#historyList').find('li').should('have.length', 30);
});
+11 -11
View File
@@ -94,6 +94,17 @@ describe('Site Loads', () => {
cy.contains('Please Click here to Raise an issue in github.');
});
it('should load compressed URL', () => {
cy.visit(
'/edit#pako:eNpVkM2KwkAQhF-l6dMK5gVyEDRxvYi7sF6WjIcm0zqDzg_jBJEk725Hd2G3Tw31VVFUj23QjCWeEkUD-1p5kFs2O77BN1M6QFEshg1ncMHzfYDV2ybA1YQYrT_NXvhqgqDqtxPGkI315_ElVU__h-cB6mZLMYd4-Kvsb2GAdWM_jcT_V0xicb03RyqPVLSUoJI-OEfHyZHV0rqfDAqzYccKS3k1pbNC5Ufhuqgp81rbHBJKxuXKc6Quh6-7b7HMqeNfqLYkC7gfanwAlW1ZvQ'
);
cy.contains('New Year');
cy.visit(
'/edit#pako:eNptkU1PwzAMhv9K5BOI9Q9EXBDbJA477YYqITcxndV8QD40weh_Jy1rGR0-OY_tV2_sEyivCSQogzGuGduAtnaixINji0bcf1WVWGfVXdMtx8M1faYm4B8sxR27JLClJd6nwK4VLTlN4bI4jMQd2pLe3C4KFhNNcLQ92jv9ADGLNoTdozc-zIV4ZDsNlud7RtVN7_5Sb_jYrFcN3iN_0pPbEqUZK3QbTP_Ojyv4NdR4bwTHlyMbPcOQ3WJ2CliBpWCRdbnLqFJDOpClGmRJNYauhtr1pS-_6bKMjebkA8hXNJFWgDn5_YdTIFPINDWdb3vu6r8BaWOZRQ'
);
cy.contains('Animal');
});
it('should load uncompressed URL', () => {
cy.visit(
'/edit/#eyJjb2RlIjoiZ3JhcGggVERcbiAgICBBW05ldyBZZWFyXSAtLT58R2V0IG1vbmV5fCBCKEdvIHNob3BwaW5nKVxuICAgIEIgLS0-IEN7TGV0IG1lIHRoaW5rfVxuICAgIEMgLS0-fE9uZXwgRFtMYXB0b3BdXG4gICAgQyAtLT58VHdvfCBFW2lQaG9uZV1cbiAgICBDIC0tPnxUaHJlZXwgRltmYTpmYS1jYXIgQ2FyXSIsIm1lcm1haWQiOiJ7XG4gIFwidGhlbWVcIjogXCJkZWZhdWx0XCJcbn0iLCJ1cGRhdGVFZGl0b3IiOmZhbHNlLCJhdXRvU3luYyI6dHJ1ZSwidXBkYXRlRGlhZ3JhbSI6ZmFsc2V9'
@@ -108,15 +119,4 @@ describe('Site Loads', () => {
);
cy.contains('New Year');
});
it('should load compressed URL', () => {
cy.visit(
'/edit#pako:eNpVkM2KwkAQhF-l6dMK5gVyEDRxvYi7sF6WjIcm0zqDzg_jBJEk725Hd2G3Tw31VVFUj23QjCWeEkUD-1p5kFs2O77BN1M6QFEshg1ncMHzfYDV2ybA1YQYrT_NXvhqgqDqtxPGkI315_ElVU__h-cB6mZLMYd4-Kvsb2GAdWM_jcT_V0xicb03RyqPVLSUoJI-OEfHyZHV0rqfDAqzYccKS3k1pbNC5Ufhuqgp81rbHBJKxuXKc6Quh6-7b7HMqeNfqLYkC7gfanwAlW1ZvQ'
);
cy.contains('New Year');
cy.visit(
'/edit#pako:eNptkU1PwzAMhv9K5BOI9Q9EXBDbJA477YYqITcxndV8QD40weh_Jy1rGR0-OY_tV2_sEyivCSQogzGuGduAtnaixINji0bcf1WVWGfVXdMtx8M1faYm4B8sxR27JLClJd6nwK4VLTlN4bI4jMQd2pLe3C4KFhNNcLQ92jv9ADGLNoTdozc-zIV4ZDsNlud7RtVN7_5Sb_jYrFcN3iN_0pPbEqUZK3QbTP_Ojyv4NdR4bwTHlyMbPcOQ3WJ2CliBpWCRdbnLqFJDOpClGmRJNYauhtr1pS-_6bKMjebkA8hXNJFWgDn5_YdTIFPINDWdb3vu6r8BaWOZRQ'
);
cy.contains('Animal');
});
});
+7 -4
View File
@@ -10,7 +10,7 @@ export const getEditor = ({ bottom = true, newline = false } = {}) =>
const downloadsFolder = Cypress.config('downloadsFolder');
export const verifyFileSize = (
export const verifyFileSizeGreaterThan = (
fileType: 'history' | 'diagram',
extension: string,
size: number
@@ -21,7 +21,10 @@ export const verifyFileSize = (
cy.verifyDownload(fileName);
cy.readFile(filePath, null, {
log: false
}).then((buffer) => expect((buffer as ArrayBuffer).byteLength).to.be.gt(size));
}).then((buffer: ArrayBuffer) => {
expect(buffer.byteLength).to.be.gt(size);
expect(buffer.byteLength).to.be.lt(size * 1.3);
});
cy.task('deleteFile', filePath);
};
@@ -36,8 +39,8 @@ export const verifyFileSnapshot = (
cy.verifyDownload(fileName);
cy.readFile(filePath, null, {
log: false
}).then((buffer) =>
expect(new TextDecoder('utf-8').decode(buffer as ArrayBuffer)).to.contain(content)
}).then((buffer: ArrayBuffer) =>
expect(new TextDecoder('utf8').decode(buffer)).to.contain(content)
);
cy.task('deleteFile', filePath);
};
+3 -3
View File
@@ -1,7 +1,7 @@
module.exports = {
"Site Loads": {
"Check Home page load": {
"1": "{\"code\":\"graph TD\\n A[Christmas] -->|Get money| B(Go shopping)\\n B --> C{Let me think}\\n C -->|One| D[Laptop]\\n C -->|Two| E[iPhone]\\n C -->|Three| F[fa:fa-car Car]\\n \",\"mermaid\":\"{\\n \\\"theme\\\": \\\"default\\\"\\n}\",\"autoSync\":true,\"updateDiagram\":true}"
"1": "{\"code\":\"flowchart TD\\n A[Christmas] -->|Get money| B(Go shopping)\\n B --> C{Let me think}\\n C -->|One| D[Laptop]\\n C -->|Two| E[iPhone]\\n C -->|Three| F[fa:fa-car Car]\\n \",\"mermaid\":\"{\\n \\\"theme\\\": \\\"default\\\"\\n}\",\"autoSync\":true,\"updateDiagram\":true}"
},
"Check Redirect from old URL": {
"1": "{\"code\":\"graph TD\\n A[Christmas] -->|Get money| B(Go shopping)\\n B --> C{Let me think}\\n C -->|One| D[Laptop]\\n C -->|Two| E[iPhone]\\n C -->|Three| F[fa:fa-car Car]\",\"mermaid\":\"{\\n \\\"theme\\\": \\\"default\\\"\\n}\",\"autoSync\":true,\"updateDiagram\":true}"
@@ -19,10 +19,10 @@ module.exports = {
"__version": "11.2.0",
"Auto sync tests": {
"should dim diagram when code is edited": {
"1": "{\"code\":\"graph TD\\n A[Christmas] -->|Get money| B(Go shopping)\\n B --> C{Let me think}\\n C -->|One| D[Laptop]\\n C -->|Two| E[iPhone]\\n C -->|Three| F[fa:fa-car Car]\\n C --> Test\",\"mermaid\":\"{\\n \\\"theme\\\": \\\"default\\\"\\n}\",\"autoSync\":false,\"updateDiagram\":false}"
"1": "{\"code\":\"flowchart TD\\n A[Christmas] -->|Get money| B(Go shopping)\\n B --> C{Let me think}\\n C -->|One| D[Laptop]\\n C -->|Two| E[iPhone]\\n C -->|Three| F[fa:fa-car Car]\\n C --> Test\",\"mermaid\":\"{\\n \\\"theme\\\": \\\"default\\\"\\n}\",\"autoSync\":false,\"updateDiagram\":false}"
},
"should not dim diagram when code is in sync": {
"1": "{\"code\":\"graph TD\\n A[Christmas] -->|Get money| B(Go shopping)\\n B --> C{Let me think}\\n C -->|One| D[Laptop]\\n C -->|Two| E[iPhone]\\n C -->|Three| F[fa:fa-car Car]\\n C --> Testing\",\"mermaid\":\"{\\n \\\"theme\\\": \\\"default\\\"\\n}\",\"autoSync\":true,\"updateDiagram\":false}"
"1": "{\"code\":\"flowchart TD\\n A[Christmas] -->|Get money| B(Go shopping)\\n B --> C{Let me think}\\n C -->|One| D[Laptop]\\n C -->|Two| E[iPhone]\\n C -->|Three| F[fa:fa-car Car]\\n C --> Testing\",\"mermaid\":\"{\\n \\\"theme\\\": \\\"default\\\"\\n}\",\"autoSync\":true,\"updateDiagram\":false}"
}
},
"Test themes": {
+1 -1
View File
@@ -1,7 +1,7 @@
{
"compilerOptions": {
"allowJs": true,
"types": ["cypress", "cypress-localstorage-commands", "cy-verify-downloads"]
"types": ["cypress", "cypress-localstorage-commands", "cy-verify-downloads", "node"]
},
"include": ["**/*.ts"]
}
+23 -23
View File
@@ -23,57 +23,57 @@
},
"devDependencies": {
"@cypress/snapshot": "2.1.7",
"@sveltejs/adapter-static": "1.0.0-next.48",
"@sveltejs/kit": "1.0.0-next.561",
"@sveltejs/adapter-static": "1.0.6",
"@sveltejs/kit": "1.5.0",
"@testing-library/jest-dom": "5.16.5",
"@testing-library/svelte": "3.2.2",
"@types/pako": "2.0.0",
"@types/uuid": "8.3.4",
"@typescript-eslint/eslint-plugin": "5.44.0",
"@typescript-eslint/parser": "5.44.0",
"@vitest/ui": "^0.25.3",
"@typescript-eslint/eslint-plugin": "5.51.0",
"@typescript-eslint/parser": "5.51.0",
"@vitest/ui": "^0.28.0",
"autoprefixer": "^10.4.13",
"c8": "7.12.0",
"chai": "^4.3.7",
"cssnano": "^5.1.14",
"cy-verify-downloads": "0.1.11",
"cypress": "11.2.0",
"cypress-localstorage-commands": "2.2.1",
"eslint": "8.28.0",
"eslint-config-prettier": "8.5.0",
"cypress-localstorage-commands": "2.2.2",
"eslint": "8.33.0",
"eslint-config-prettier": "8.6.0",
"eslint-plugin-cypress": "2.12.1",
"eslint-plugin-es": "4.1.0",
"eslint-plugin-no-only-tests": "^3.1.0",
"eslint-plugin-postcss-modules": "2.0.0",
"eslint-plugin-svelte3": "4.0.0",
"eslint-plugin-tailwindcss": "3.7.0",
"eslint-plugin-vitest": "^0.0.20",
"esserializer": "1.3.5",
"eslint-plugin-tailwindcss": "3.8.3",
"eslint-plugin-unicorn": "^45.0.0",
"eslint-plugin-vitest": "^0.0.32",
"esserializer": "1.3.10",
"font-awesome": "^4.7.0",
"husky": "^8.0.2",
"jsdom": "20.0.3",
"lint-staged": "13.0.3",
"lint-staged": "13.1.1",
"node-html-parser": "^6.1.4",
"postcss": "^8.4.19",
"postcss-load-config": "4.0.1",
"prettier": "2.8.0",
"prettier": "2.8.3",
"prettier-plugin-svelte": "^2.8.1",
"svelte": "3.53.1",
"svelte": "3.55.1",
"svelte-preprocess": "4.10.7",
"tailwindcss": "^3.2.4",
"tslib": "^2.4.1",
"typescript": "4.9.3",
"vite": "^3.2.4",
"vitest": "^0.25.3"
"typescript": "4.9.5",
"vite": "^4.0.1",
"vitest": "^0.28.0"
},
"dependencies": {
"@mermaid-js/mermaid-mindmap": "9.2.2",
"analytics": "0.8.1",
"analytics-plugin-plausible": "0.0.6",
"daisyui": "2.42.1",
"js-base64": "3.7.3",
"mermaid": "9.2.2",
"moment": "2.29.4",
"daisyui": "2.50.0",
"dayjs": "^1.11.7",
"js-base64": "3.7.4",
"mermaid": "10.0.1-rc.3",
"monaco-editor": "0.34.1",
"monaco-mermaid": "1.0.8",
"pako": "2.1.0",
@@ -88,7 +88,7 @@
]
},
"volta": {
"node": "18.12.1",
"node": "18.14.0",
"yarn": "1.22.19"
},
"engines": {
+3 -3
View File
@@ -6,13 +6,13 @@
import { stateStore } from '$lib/util/state';
import { logEvent } from '$lib/util/stats';
import { toBase64 } from 'js-base64';
import moment from 'moment';
import dayjs from 'dayjs';
const { krokiRendererUrl, rendererUrl } = env;
type Exporter = (context: CanvasRenderingContext2D, image: HTMLImageElement) => () => void;
const getFileName = (ext: string) =>
`mermaid-diagram-${moment().format('YYYY-MM-DD-HHmmss')}.${ext}`;
`mermaid-diagram-${dayjs().format('YYYY-MM-DD-HHmmss')}.${ext}`;
const getBase64SVG = (svg?: HTMLElement, width?: number, height?: number): string => {
height && svg?.setAttribute('height', `${height}px`);
@@ -180,7 +180,7 @@
});
</script>
<Card title="Actions" isOpen={true}>
<Card title="Actions" isOpen={false}>
<div class="flex flex-wrap gap-2 m-2">
{#if isClipboardAvailable()}
<button class="action-btn w-full" on:click={onCopyClipboard}
@@ -1,3 +0,0 @@
// Vitest Snapshot v1
exports[`card.svelte > mounts 1`] = `"<div><div class=\\"card rounded overflow-hidden m-2 flex-grow flex flex-col shadow-2xl\\"><div class=\\"bg-primary p-2 pb-0 flex-none cursor-pointer\\"><div class=\\"flex justify-between\\"><div class=\\"flex cursor-default s-lTROw8sJayZ1\\"><span class=\\"mr-2 font-semibold s-lTROw8sJayZ1\\"><i class=\\"fas fa-chevron-right icon s-lTROw8sJayZ1 isOpen\\"></i> TabTest</span> <ul class=\\"tabs s-lTROw8sJayZ1\\"><div class=\\"tab tab-lifted tab-active s-lTROw8sJayZ1\\"><i class=\\"mr-1 fab fa-git-alt s-lTROw8sJayZ1\\"></i> title1 </div><div class=\\"tab tab-lifted text-primary-content s-lTROw8sJayZ1\\"><i class=\\"mr-1 far fa-bookmark s-lTROw8sJayZ1\\"></i> title2 </div></ul></div><!--<Tabs>--> <div class=\\"flex gap-x-4 items-center -mt-2\\"></div></div></div> <div class=\\"card-body p-0 flex-grow overflow-auto text-base-content\\"></div></div><!--<Card>--></div>"`;
-1
View File
@@ -19,6 +19,5 @@ describe('card.svelte', () => {
expect(container).toHaveTextContent('title1');
expect(container).toHaveTextContent('title2');
expect(container).not.toHaveTextContent('title3');
expect(container.innerHTML).toMatchSnapshot();
});
});
+6 -6
View File
@@ -21,7 +21,7 @@
let text = '';
stateStore.subscribe(({ errorMarkers, editorMode, code, mermaid }) => {
console.log('editor store subscription', { code, mermaid });
// console.log('editor store subscription', { code, mermaid });
if (!editor || !Monaco) {
return;
}
@@ -29,7 +29,7 @@
// Update editor text if it's different
const newText = editorMode === 'code' ? code : mermaid;
if (newText !== text) {
console.log('updating editor text', newText);
// console.log('updating editor text', newText);
editor.setValue(newText);
text = newText;
}
@@ -54,7 +54,7 @@
});
const handleUpdate = (text: string, mode: EditorMode) => {
console.log('editor HandleUpdate', { text, mode });
// console.log('editor HandleUpdate', { text, mode });
if (mode === 'code') {
updateCode(text);
} else {
@@ -91,7 +91,7 @@
editor = Monaco.editor.create(divEl, editorOptions);
editor.onDidChangeModelContent(({ isFlush, changes }) => {
const newText = editor?.getValue();
console.log('editor onDidChangeModelContent', { text, newText, isFlush, changes });
// console.log('editor onDidChangeModelContent', { text, newText, isFlush, changes });
if (!newText || text === newText || isFlush) {
return;
}
@@ -120,9 +120,9 @@
if (divEl.parentElement) {
resizeObserver.observe(divEl.parentElement);
}
console.log(`editor mounted`);
// console.log(`editor mounted`);
return () => {
console.log(`editor disposed`);
// console.log(`editor disposed`);
editor?.dispose();
};
});
+6 -3
View File
@@ -13,10 +13,13 @@
import { notify, prompt } from '$lib/util/notify';
import { onMount } from 'svelte';
import { get } from 'svelte/store';
import moment from 'moment';
import dayjs from 'dayjs';
import dayjsRelativeTime from 'dayjs/plugin/relativeTime';
import type { HistoryEntry, HistoryType, State, Tab } from '$lib/types';
import { logEvent } from '$lib/util/stats';
dayjs.extend(dayjsRelativeTime);
const HISTORY_SAVE_INTERVAL = 60000;
const tabSelectHandler = (message: CustomEvent<Tab>) => {
@@ -41,7 +44,7 @@
const url = URL.createObjectURL(blob);
const a = document.createElement('a');
a.href = url;
a.download = `mermaid-history-${moment().format('YYYY-MM-DD-HHmmss')}.json`;
a.download = `mermaid-history-${dayjs().format('YYYY-MM-DD-HHmmss')}.json`;
a.click();
URL.revokeObjectURL(url);
logEvent('history', {
@@ -95,7 +98,7 @@
const relativeTime = (time: number) => {
const t = new Date(time);
return `${new Date(t).toLocaleString()} (${moment(t).fromNow()})`;
return `${new Date(t).toLocaleString()} (${dayjs(t).fromNow()})`;
};
onMount(() => {
+8 -8
View File
@@ -17,7 +17,7 @@ describe('history', () => {
addHistoryEntry({
state: defaultState,
time: 12345,
time: 12_345,
type: 'manual'
});
@@ -25,14 +25,14 @@ describe('history', () => {
window.localStorage.getItem('manualHistoryStore') ?? '[]'
) as HistoryEntry[];
expect(manualEntry.time).toBe(12345);
expect(manualEntry.time).toBe(12_345);
expect(manualEntry.type).toBe('manual');
expect(manualEntry.name).not.toBeNull();
expect(manualEntry.state).not.toBeNull();
addHistoryEntry({
state: defaultState,
time: 54321,
time: 54_321,
type: 'auto'
});
@@ -40,7 +40,7 @@ describe('history', () => {
window.localStorage.getItem('autoHistoryStore') ?? '[]'
) as HistoryEntry[];
expect(autoEntry.time).toBe(54321);
expect(autoEntry.time).toBe(54_321);
expect(autoEntry.type).toBe('auto');
expect(autoEntry.name).not.toBeNull();
expect(autoEntry.state).not.toBeNull();
@@ -56,12 +56,12 @@ describe('history', () => {
it('should clear history entries', () => {
addHistoryEntry({
state: defaultState,
time: 12345,
time: 12_345,
type: 'manual'
});
addHistoryEntry({
state: { ...defaultState, code: 'graph TD\\n A[Christmas] -->|Get money| B(Go shopping)' },
time: 123456,
time: 123_456,
type: 'manual'
});
@@ -76,12 +76,12 @@ describe('history', () => {
historyModeStore.set('auto');
addHistoryEntry({
state: defaultState,
time: 54321,
time: 54_321,
type: 'auto'
});
addHistoryEntry({
state: { ...defaultState, code: 'graph TD\\n A[Christmas] -->|Get money| B(Go shopping)' },
time: 654321,
time: 654_321,
type: 'auto'
});
expect(get(historyStore).length).toBe(2);
+29 -18
View File
@@ -26,19 +26,27 @@ const manualHistoryStore: Writable<HistoryEntry[]> = persist(
'manualHistoryStore'
);
export const loaderHistoryStore: Writable<HistoryEntry[]> = writable([] as HistoryEntry[]);
export const loaderHistoryStore: Writable<HistoryEntry[]> = writable([]);
export const historyStore: Readable<HistoryEntry[]> = derived(
[historyModeStore, autoHistoryStore, manualHistoryStore, loaderHistoryStore],
([historyMode, autoHistories, manualHistories, loadedHistories], set) => {
if (historyMode === 'auto') {
set(autoHistories);
} else if (historyMode === 'manual') {
set(manualHistories);
} else if (historyMode === 'loader') {
set(loadedHistories);
} else {
set(autoHistories);
switch (historyMode) {
case 'auto': {
set(autoHistories);
break;
}
case 'manual': {
set(manualHistories);
break;
}
case 'loader': {
set(loadedHistories);
break;
}
default: {
set(autoHistories);
}
}
}
);
@@ -90,7 +98,7 @@ export const getPreviousState = (auto: boolean): string => {
};
export const restoreHistory = (data: HistoryEntry[]) => {
const entries = data.filter(validateEntry);
const entries = data.filter((element) => validateEntry(element));
const invalidEntryCount = data.length - entries.length;
if (invalidEntryCount > 0) {
console.error(`${invalidEntryCount} invalid history entries were removed.`);
@@ -122,20 +130,23 @@ export const restoreHistory = (data: HistoryEntry[]) => {
alert('No valid entries found.');
}
};
const setIDs = (entries: HistoryEntry[]) => {
for (const entry of entries) {
if (!entry.id) {
entry.id = uuidV4();
}
}
return entries;
};
export const injectHistoryIDs = (): void => {
const setIDs = (entries: HistoryEntry[]) => {
for (const entry of entries) {
if (!entry.id) {
entry.id = uuidV4();
}
}
return entries;
};
autoHistoryStore.update(setIDs);
manualHistoryStore.update(setIDs);
};
const validateEntry = (entry: HistoryEntry): boolean => {
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-expect-error
// eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
return entry.type && entry.state && entry.time && true;
};
+2 -2
View File
@@ -17,11 +17,11 @@
const links: Link[] = [
{
title: 'Documentation',
href: 'https://mermaid-js.github.io/mermaid/#/n00b-gettingStarted'
href: 'https://mermaid-js.github.io/mermaid/intro/n00b-gettingStarted.html'
},
{
title: 'Tutorial',
href: 'https://github.com/mermaid-js/mermaid/blob/develop/docs/Tutorials.md'
href: 'https://mermaid-js.github.io/mermaid/config/Tutorials.html'
},
{
title: 'Mermaid',
+1 -1
View File
@@ -4,7 +4,7 @@
import { logEvent } from '$lib/util/stats';
const samples = {
Flow: `graph TD
Flow: `flowchart TD
A[Christmas] -->|Get money| B(Go shopping)
B --> C{Let me think}
C -->|One| D[Laptop]
+20 -20
View File
@@ -79,27 +79,27 @@
panZoomEnabled = state.panZoom;
const scroll = view.parentElement!.scrollTop;
delete container.dataset.processed;
await renderDiagram(
const { svg, bindFunctions } = await renderDiagram(
Object.assign({}, JSON.parse(state.mermaid)) as MermaidConfig,
code,
'graph-div',
(svgCode, bindFunctions) => {
if (svgCode.length > 0) {
handlePanZoom(state);
container.innerHTML = svgCode;
// console.log(container.innerHTML);
const graphDiv = document.getElementById('graph-div');
if (!graphDiv) {
throw new Error('graph-div not found');
}
graphDiv.setAttribute('height', '100%');
graphDiv.style.maxWidth = '100%';
if (bindFunctions) {
bindFunctions(graphDiv);
}
}
}
'graph-div'
);
if (svg.length > 0) {
handlePanZoom(state);
container.innerHTML = svg;
console.log({ svg });
const graphDiv = document.getElementById('graph-div');
if (!graphDiv) {
throw new Error('graph-div not found');
}
graphDiv.setAttribute('height', '100%');
graphDiv.style.maxWidth = '100%';
if (bindFunctions) {
bindFunctions(graphDiv);
}
}
view.parentElement!.scrollTop = scroll;
error = false;
} else if (manualUpdate) {
@@ -122,7 +122,7 @@
pzoom.resize();
}
});
console.log('View mounted');
// console.log('View mounted');
});
</script>
@@ -133,7 +133,7 @@
: 'text-yellow-600'} bg-base-100 bg-opacity-80 text-center"
id="errorContainer">
{#if error}
{@html $stateStore.error.toString().replace(/\n/g, '<br />')}
{@html $stateStore.error?.toString().replace(/\n/g, '<br />')}
{:else}
Diagram out of sync. <br />
Press <i class="fas fa-sync" /> (Sync button) or <kbd>{cmdKey} + Enter</kbd> to sync.
+1 -1
View File
@@ -65,7 +65,7 @@ export type HistoryEntry = { id: string; state: State; time: number; url?: strin
}
);
export type DocConfig = Record<
export type DocumentationConfig = Record<
string,
{
code: string;
+9 -8
View File
@@ -5,6 +5,7 @@
import type { State } from '$lib/types';
import { defaultState } from '$lib/util/state';
import { addHistoryEntry } from '$lib/components/History/history';
import { fetchJSON, fetchText } from '$lib/util/util';
const codeFileName = 'code.mmd';
const configFileName = 'config.json';
@@ -21,7 +22,7 @@ const isValidGist = (files: any): boolean => {
const getFileContent = async (file: GithubFile): Promise<string> => {
if (file.truncated) {
return await (await fetch(file.raw_url)).text();
return await fetchText(file.raw_url);
}
return file.content;
};
@@ -49,9 +50,9 @@ const getGistData = async (gistURL: string): Promise<GistData> => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [_, __, gistID, revisionID] = path.split('/');
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const { html_url, files, history }: GistResponse = await (
await fetch(`https://api.github.com/gists/${gistID}${revisionID ? '/' + revisionID : ''}`)
).json();
const { html_url, files, history }: GistResponse = await fetchJSON(
`https://api.github.com/gists/${gistID}${revisionID ? '/' + revisionID : ''}`
);
if (isValidGist(files)) {
const code = await getFileContent(files[codeFileName]);
let config = '{}';
@@ -96,12 +97,12 @@ export const loadGistData = async (gistURL: string): Promise<State> => {
// eslint-disable-next-line @typescript-eslint/no-unused-vars
const [_, __, gistID, revisionID] = path.split('/');
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
const { history }: GistResponse = await (
await fetch(`https://api.github.com/gists/${gistID}${revisionID ? '/' + revisionID : ''}`)
).json();
const { history }: GistResponse = await fetchJSON(
`https://api.github.com/gists/${gistID}${revisionID ? '/' + revisionID : ''}`
);
const gistHistory: GistData[] = [];
for (const entry of history) {
const data: GistData | undefined = await getGistData(entry.url).catch(() => undefined);
const data: GistData | undefined = await getGistData(entry.url).catch();
data && gistHistory.push(data);
}
if (gistHistory.length === 0) {
+20 -22
View File
@@ -1,6 +1,8 @@
import { loadGistData } from './gist';
import { updateCodeStore, defaultState } from '../state';
import { updateCodeStore, defaultState } from '$lib/util/state';
import { fetchText } from '$lib/util/util';
import type { Loader, State } from '$lib/types';
const loaders: Record<string, Loader> = {
gist: loadGistData
};
@@ -8,34 +10,18 @@ const loaders: Record<string, Loader> = {
export const loadDataFromUrl = async (): Promise<void> => {
const searchParams = new URLSearchParams(window.location.search);
let state: Partial<State> = defaultState;
let code: string | undefined = undefined;
let config: string | undefined = undefined;
let loaded = false;
const codeURL: string | undefined = searchParams.get('code') ?? undefined;
const configURL: string | undefined = searchParams.get('config') ?? undefined;
let code: string | undefined;
const config = configURL ? await fetchText(configURL) : defaultState.mermaid;
if (codeURL) {
code = await (await fetch(codeURL)).text();
code = await fetchText(codeURL);
loaded = true;
}
if (configURL) {
config = await (await fetch(configURL)).text();
} else {
config = defaultState.mermaid;
}
if (!code) {
for (const [key, value] of searchParams.entries()) {
if (key in loaders) {
try {
state = await loaders[key](value);
loaded = true;
break;
} catch (err) {
console.error(err);
}
}
}
} else {
if (code) {
if (!codeURL) {
throw new Error('Code URL is not defined');
}
@@ -50,6 +36,18 @@ export const loadDataFromUrl = async (): Promise<void> => {
}
}
};
} else {
for (const [key, value] of searchParams.entries()) {
if (key in loaders) {
try {
state = await loaders[key](value);
loaded = true;
break;
} catch (error) {
console.error(error);
}
}
}
}
loaded &&
updateCodeStore({
+7 -18
View File
@@ -1,27 +1,16 @@
import mermaid, { type MermaidConfig } from 'mermaid';
import mindmap from '@mermaid-js/mermaid-mindmap';
const initialize = mermaid.registerExternalDiagrams([mindmap]);
export const init = async () => {
await initialize;
};
import mermaid from 'mermaid';
import type { MermaidConfig, RenderResult } from 'mermaid';
export const render = async (
config: MermaidConfig,
code: string,
id: string,
callback: Parameters<typeof mermaid.render>[2]
): Promise<void> => {
id: string
): Promise<RenderResult> => {
// Should be able to call this multiple times without any issues.
mermaid.initialize(config);
// console.log('Rendering', code);
// mermaid.mermaidAPI.render(id, code, callback);
await init();
await mermaid.mermaidAPI.renderAsync(id, code, callback);
return await mermaid.render(id, code);
};
export const parse = async (code: string): Promise<boolean> => {
await init();
return await mermaid.parseAsync(code);
export const parse = async (code: string): Promise<unknown> => {
return await mermaid.parse(code);
};
+5 -7
View File
@@ -70,13 +70,13 @@ const deserialize = (value?: string | null): unknown => {
if (value !== null && value !== undefined) {
try {
return ESSerializer.deserialize(value);
} catch (e) {
} catch {
// Do nothing
// use the value "as is"
}
try {
return JSON.parse(value);
} catch (e) {
} catch {
// Do nothing
// use the value "as is"
}
@@ -179,11 +179,9 @@ function getBrowserStorage(
const listenerFunction = (event: StorageEvent) => {
const eventKey = event.key;
if (event.storageArea === browserStorage) {
listeners
.filter(({ key }) => key === eventKey)
.forEach(({ listener }) => {
listener(deserialize(event.newValue));
});
for (const { listener } of listeners.filter(({ key }) => key === eventKey)) {
listener(deserialize(event.newValue));
}
}
};
const connect = () => {
+10 -10
View File
@@ -3,29 +3,29 @@ import { serializeState, deserializeState, type SerdeType } from './serde';
import { defaultState } from './state';
import type { State } from '$lib/types';
describe('Serde tests', () => {
const verifySerde = (state: State, serde?: SerdeType): string => {
const serialized = serializeState(state, serde);
const deserialized = deserializeState(serialized);
expect(deserialized).to.deep.equal(state);
return serialized;
};
const verifySerde = (state: State, serde?: SerdeType): string => {
const serialized = serializeState(state, serde);
const deserialized = deserializeState(serialized);
expect(deserialized).to.deep.equal(state);
return serialized;
};
describe('Serde tests', () => {
it('should serialize and deserialize with default serde', () => {
expect(verifySerde(defaultState)).toMatchInlineSnapshot(
'"pako:eNpVj81qw0AMhF9F6NRC_AI-BGK7zSXQQHLz5iBsObuk-8Naphjb7551fEl1EjPfiNGEjW8Zc7xHChqulXKQ5lCXOppeLPU3yLL9fGQB6x2PMxQfRw-99iEYd__c-GKFoJxOK8Yg2rjHslnlK__jeIaqPlEQH27vzvXPz_BVm7NO5_87OnJKfdcd5R1lDUUoKb4Q3KHlaMm0qfq0KgpFs2WFeVpb7mj4FYXKLQmlQfxldA3mEgfe4RBaEq4MpaftJi5PNtJU8w"'
'"pako:eNpVjk2Lg0AMhv9KyGkL9Q94WGh1t5fCFurN6SFo7AztfDBGpKj_fcd62c0pvM_zhkzY-JYxx-7px0ZTFKhK5SDNoS50NL1Y6m-QZZ_ziQWsd_ya4fhx8tBrH4Jx993mH1cJium8agyijXssGyre_R_HM5T1mYL4cPtLqtHP8FWbi07n_xMdObW-647yjrKGIhQU3wru0XK0ZNr0_rQmCkWzZYV5WlvuaHiKQuWWpNIg_vpyDeYSB97jEFoSLg3dI9ktXH4B_cJWqw"'
);
});
it('should serialize and deserialize with base64 serde', () => {
expect(verifySerde(defaultState, 'base64')).toMatchInlineSnapshot(
'"base64:eyJjb2RlIjoiZ3JhcGggVERcbiAgICBBW0NocmlzdG1hc10gLS0-fEdldCBtb25leXwgQihHbyBzaG9wcGluZylcbiAgICBCIC0tPiBDe0xldCBtZSB0aGlua31cbiAgICBDIC0tPnxPbmV8IERbTGFwdG9wXVxuICAgIEMgLS0-fFR3b3wgRVtpUGhvbmVdXG4gICAgQyAtLT58VGhyZWV8IEZbZmE6ZmEtY2FyIENhcl1cbiAgIiwibWVybWFpZCI6IntcbiAgXCJ0aGVtZVwiOiBcImRlZmF1bHRcIlxufSIsImF1dG9TeW5jIjp0cnVlLCJ1cGRhdGVEaWFncmFtIjp0cnVlfQ"'
'"base64:eyJjb2RlIjoiZmxvd2NoYXJ0IFREXG4gICAgQVtDaHJpc3RtYXNdIC0tPnxHZXQgbW9uZXl8IEIoR28gc2hvcHBpbmcpXG4gICAgQiAtLT4gQ3tMZXQgbWUgdGhpbmt9XG4gICAgQyAtLT58T25lfCBEW0xhcHRvcF1cbiAgICBDIC0tPnxUd298IEVbaVBob25lXVxuICAgIEMgLS0-fFRocmVlfCBGW2ZhOmZhLWNhciBDYXJdXG4gICIsIm1lcm1haWQiOiJ7XG4gIFwidGhlbWVcIjogXCJkZWZhdWx0XCJcbn0iLCJhdXRvU3luYyI6dHJ1ZSwidXBkYXRlRGlhZ3JhbSI6dHJ1ZX0"'
);
});
it('should serialize and deserialize with pako serde', () => {
expect(verifySerde(defaultState, 'pako')).toMatchInlineSnapshot(
'"pako:eNpVj81qw0AMhF9F6NRC_AI-BGK7zSXQQHLz5iBsObuk-8Naphjb7551fEl1EjPfiNGEjW8Zc7xHChqulXKQ5lCXOppeLPU3yLL9fGQB6x2PMxQfRw-99iEYd__c-GKFoJxOK8Yg2rjHslnlK__jeIaqPlEQH27vzvXPz_BVm7NO5_87OnJKfdcd5R1lDUUoKb4Q3KHlaMm0qfq0KgpFs2WFeVpb7mj4FYXKLQmlQfxldA3mEgfe4RBaEq4MpaftJi5PNtJU8w"'
'"pako:eNpVjk2Lg0AMhv9KyGkL9Q94WGh1t5fCFurN6SFo7AztfDBGpKj_fcd62c0pvM_zhkzY-JYxx-7px0ZTFKhK5SDNoS50NL1Y6m-QZZ_ziQWsd_ya4fhx8tBrH4Jx993mH1cJium8agyijXssGyre_R_HM5T1mYL4cPtLqtHP8FWbi07n_xMdObW-647yjrKGIhQU3wru0XK0ZNr0_rQmCkWzZYV5WlvuaHiKQuWWpNIg_vpyDeYSB97jEFoSLg3dI9ktXH4B_cJWqw"'
);
});
+20 -24
View File
@@ -2,32 +2,28 @@ import { writable, get, type Readable, derived } from 'svelte/store';
import { persist, localStorage } from './persist';
import { saveStatistics, countLines } from './stats';
import { serializeState, deserializeState } from './serde';
import { cmdKey, errorDebug } from './util';
import { cmdKey, errorDebug, formatJSON } from './util';
import { parse } from './mermaid';
import type { ErrorHash, MarkerData, State, ValidatedState } from '$lib/types';
import type { MermaidConfig } from 'mermaid';
export const defaultState: State = {
code: `graph TD
code: `flowchart TD
A[Christmas] -->|Get money| B(Go shopping)
B --> C{Let me think}
C -->|One| D[Laptop]
C -->|Two| E[iPhone]
C -->|Three| F[fa:fa-car Car]
`,
mermaid: JSON.stringify(
{
theme: 'default'
},
null,
2
),
mermaid: formatJSON({
theme: 'default'
}),
autoSync: true,
updateDiagram: true
};
const urlParseFailedState = `graph TD
const urlParseFailedState = `flowchart TD
A[Loading URL failed. We can try to figure out why.] -->|Decode JSON| B(Please check the console to see the JSON and error details.)
B --> C{Is the JSON correct?}
C -->|Yes| D(Please Click here to Raise an issue in github.<br/>Including the broken link in the issue <br/> will speed up the fix.)
@@ -65,16 +61,16 @@ const processState = async (state: State) => {
processed.serialized = serializeState(state);
await parse(state.code);
JSON.parse(state.mermaid);
} catch (e) {
processed.error = e as Error;
} catch (error) {
processed.error = error as Error;
errorDebug();
console.error(e);
if ('hash' in e) {
console.error(error);
if ('hash' in error) {
try {
const {
loc: { first_line, last_line, first_column, last_column }
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
} = e.hash as ErrorHash;
} = error.hash as ErrorHash;
const marker: MarkerData = {
severity: 8, // Error
startLineNumber: first_line,
@@ -82,11 +78,11 @@ const processState = async (state: State) => {
endLineNumber: last_line,
endColumn: last_column + 1,
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment
message: e.str
message: error.str
};
processed.errorMarkers = [marker];
} catch (err) {
console.error('Error without line helper', err);
} catch (error) {
console.error('Error without line helper', error);
}
}
}
@@ -120,11 +116,11 @@ export const loadState = (data: string): void => {
) {
delete mermaidConfig.securityLevel; // Prevent setting overriding securityLevel when loading state to mitigate possible XSS attack
}
state.mermaid = JSON.stringify(mermaidConfig, null, 2);
} catch (e) {
state.mermaid = formatJSON(mermaidConfig);
} catch (error) {
state = get(inputStateStore);
if (data) {
console.error('Init error', e);
console.error('Init error', error);
state.code = urlParseFailedState;
state.mermaid = defaultState.mermaid;
}
@@ -146,7 +142,7 @@ export const updateCode = (
resetPanZoom = false
}: { updateDiagram?: boolean; resetPanZoom?: boolean } = {}
): void => {
console.log('updateCode', code);
// console.log('updateCode', code);
const lines = countLines(code);
saveStatistics(code);
errorDebug();
@@ -172,7 +168,7 @@ export const updateCode = (
};
export const updateConfig = (config: string): void => {
console.log('updateConfig', config);
// console.log('updateConfig', config);
inputStateStore.update((state) => {
return { ...state, mermaid: config };
});
@@ -185,7 +181,7 @@ export const toggleDarkTheme = (dark: boolean): void => {
config.theme = dark ? 'dark' : 'default';
}
return { ...state, mermaid: JSON.stringify(config, null, 2) };
return { ...state, mermaid: formatJSON(config) };
});
};
+5 -5
View File
@@ -20,8 +20,8 @@ export const initAnalytics = async (): Promise<void> => {
})
]
});
} catch (e) {
console.log(e);
} catch (error) {
console.log(error);
console.info('Analytics blocked ;)');
}
}
@@ -87,10 +87,10 @@ export const logEvent = (name: AnalyticsEvent, data?: unknown): void => {
return;
}
const key = data ? JSON.stringify({ name, data }) : name;
if (!timeouts.has(key)) {
void analytics.track(name, data);
} else {
if (timeouts.has(key)) {
clearTimeout(timeouts.get(key));
} else {
void analytics.track(name, data);
}
timeouts.set(
key,
+3 -3
View File
@@ -16,7 +16,7 @@ export const themeStore: Writable<ThemeConfig> = persist(
'themeStore'
);
const darkThemes = [
const darkThemes = new Set([
'dark',
'synthwave',
'halloween',
@@ -25,13 +25,13 @@ const darkThemes = [
'luxury',
'black',
'dracula'
];
]);
export const setTheme = (theme: string): void => {
if (theme.includes(' ')) {
theme = theme.split(' ')[1].trim();
}
const isDark = darkThemes.includes(theme);
const isDark = darkThemes.has(theme);
console.log('Setting theme', theme);
themeStore.set({ theme, isDark });
logEvent('themeChange', { theme, isDark });
+10 -2
View File
@@ -3,7 +3,6 @@ import { analytics, initAnalytics } from './stats';
import { loadDataFromUrl } from './fileLoaders/loader';
import { initLoading } from './loading';
import { applyMigrations } from './migrations';
import { init } from './mermaid';
export const loadStateFromURL = (): void => {
loadState(window.location.hash.slice(1));
@@ -17,7 +16,6 @@ export const syncDiagram = (): void => {
export const initHandler = async (): Promise<void> => {
applyMigrations();
await initLoading('Loading Mermaid...', init());
loadStateFromURL();
await initLoading('Loading Gist...', loadDataFromUrl().catch(console.error));
syncDiagram();
@@ -38,3 +36,13 @@ export const errorDebug = (limit = 100) => {
debugger;
}
};
export const formatJSON = (data: unknown): string => JSON.stringify(data, undefined, 2);
export const fetchJSON = async <T>(url: string): Promise<T> => {
const res = await fetch(url);
return res.json() as T;
};
export const fetchText = async (url: string): Promise<string> => {
const res = await fetch(url);
return res.text();
};
+7 -4
View File
@@ -9,11 +9,11 @@
import { inputStateStore, stateStore, updateCodeStore } from '$lib/util/state';
import { cmdKey, initHandler, syncDiagram } from '$lib/util/util';
import { onMount } from 'svelte';
import type { Tab, DocConfig, EditorMode, ValidatedState } from '$lib/types';
import type { Tab, DocumentationConfig, EditorMode, ValidatedState } from '$lib/types';
import { base } from '$app/paths';
const docURLBase = 'https://mermaid-js.github.io/mermaid';
const docMap: DocConfig = {
const docMap: DocumentationConfig = {
graph: {
code: '/#/flowchart',
config: '/#/flowchart?id=configuration'
@@ -54,11 +54,12 @@
};
let docURL = docURLBase;
let activeTabID = 'code';
let docKey = '';
stateStore.subscribe(({ code, editorMode }: ValidatedState) => {
activeTabID = editorMode;
const codeTypeMatch = /([\S]+)[\s\n]/.exec(code);
if (codeTypeMatch && codeTypeMatch.length > 1) {
const docKey = codeTypeMatch[1];
docKey = codeTypeMatch[1];
const docConfig = docMap[docKey] ?? { code: '' };
docURL = docURLBase + (docConfig[editorMode] ?? docConfig.code ?? '');
}
@@ -133,7 +134,9 @@
on:click={syncDiagram}><i class="fas fa-sync" /></button>
{/if}
<button class="btn btn-secondary btn-xs" title="View documentation">
<button
class="btn btn-secondary btn-xs"
title="View documentation for {docKey.replace('Diagram', '')} diagram">
<a target="_blank" rel="noreferrer" href={docURL} data-cy="docs">
<i class="fas fa-book mr-1" />Docs
</a>
+4 -4
View File
@@ -1,6 +1,7 @@
import { sveltekit } from '@sveltejs/kit/vite';
/** @type {import('vite').UserConfig} */
const config = {
import { defineConfig } from 'vitest/config';
export default defineConfig({
plugins: [sveltekit()],
envPrefix: 'MERMAID_',
optimizeDeps: { include: ['mermaid'] },
@@ -22,5 +23,4 @@ const config = {
reporter: ['text', 'json', 'html', 'lcov']
}
}
};
export default config;
});
+930 -729
View File
File diff suppressed because it is too large Load Diff