Compare commits
3
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9c74126ce5 | ||
|
|
db92134444 | ||
|
|
b03d862b53 |
+2
-38
@@ -6,18 +6,9 @@ module.exports = {
|
|||||||
'plugin:@typescript-eslint/recommended',
|
'plugin:@typescript-eslint/recommended',
|
||||||
// 'plugin:@typescript-eslint/recommended-requiring-type-checking',
|
// 'plugin:@typescript-eslint/recommended-requiring-type-checking',
|
||||||
'plugin:@typescript-eslint/strict',
|
'plugin:@typescript-eslint/strict',
|
||||||
'plugin:unicorn/recommended',
|
|
||||||
'prettier'
|
'prettier'
|
||||||
],
|
],
|
||||||
plugins: [
|
plugins: ['svelte3', 'tailwindcss', '@typescript-eslint', 'es', 'vitest', 'no-only-tests'],
|
||||||
'svelte3',
|
|
||||||
'tailwindcss',
|
|
||||||
'@typescript-eslint',
|
|
||||||
'es',
|
|
||||||
'vitest',
|
|
||||||
'no-only-tests',
|
|
||||||
'unicorn'
|
|
||||||
],
|
|
||||||
ignorePatterns: [
|
ignorePatterns: [
|
||||||
'docs/*',
|
'docs/*',
|
||||||
'*.cjs',
|
'*.cjs',
|
||||||
@@ -68,33 +59,6 @@ module.exports = {
|
|||||||
'@typescript-eslint/no-unsafe-assignment': 'off',
|
'@typescript-eslint/no-unsafe-assignment': 'off',
|
||||||
'es/no-regexp-lookbehind-assertions': 'error',
|
'es/no-regexp-lookbehind-assertions': 'error',
|
||||||
curly: ['error', 'all'],
|
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -0,0 +1,27 @@
|
|||||||
|
name: Playwright Tests
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches: [ main, master ]
|
||||||
|
pull_request:
|
||||||
|
branches: [ main, master ]
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
timeout-minutes: 60
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v2
|
||||||
|
- uses: actions/setup-node@v2
|
||||||
|
with:
|
||||||
|
node-version: '14.x'
|
||||||
|
- name: Install dependencies
|
||||||
|
run: yarn
|
||||||
|
- name: Install Playwright Browsers
|
||||||
|
run: npx playwright install --with-deps
|
||||||
|
- name: Run Playwright tests
|
||||||
|
run: yarn playwright test
|
||||||
|
- uses: actions/upload-artifact@v2
|
||||||
|
if: always()
|
||||||
|
with:
|
||||||
|
name: playwright-report
|
||||||
|
path: playwright-report/
|
||||||
|
retention-days: 30
|
||||||
@@ -1,21 +0,0 @@
|
|||||||
name: Create release pull request
|
|
||||||
on:
|
|
||||||
push:
|
|
||||||
branches:
|
|
||||||
- develop
|
|
||||||
jobs:
|
|
||||||
productionPromotion:
|
|
||||||
runs-on: ubuntu-latest
|
|
||||||
steps:
|
|
||||||
- uses: actions/checkout@v3
|
|
||||||
with:
|
|
||||||
ref: master
|
|
||||||
- name: Reset promotion branch
|
|
||||||
run: |
|
|
||||||
git fetch origin develop:develop
|
|
||||||
git reset --hard develop
|
|
||||||
- name: Create Pull Request
|
|
||||||
uses: peter-evans/create-pull-request@v5
|
|
||||||
with:
|
|
||||||
branch: release-promotion
|
|
||||||
title: Release live editor
|
|
||||||
@@ -8,7 +8,7 @@ jobs:
|
|||||||
stale:
|
stale:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/stale@v8
|
- uses: actions/stale@v6
|
||||||
with:
|
with:
|
||||||
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
repo-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
exempt-issue-labels: 'retained'
|
exempt-issue-labels: 'retained'
|
||||||
|
|||||||
@@ -1,32 +1,18 @@
|
|||||||
name: Update Browserslist database
|
name: Update Browserslist
|
||||||
|
|
||||||
on:
|
on:
|
||||||
schedule:
|
push:
|
||||||
- cron: '0 2 1,15 * *'
|
branches-ignore:
|
||||||
|
- 'develop'
|
||||||
permissions:
|
- 'master'
|
||||||
contents: write
|
|
||||||
pull-requests: write
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
update-browserslist-database:
|
build:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
steps:
|
steps:
|
||||||
- name: Checkout repository
|
- uses: actions/checkout@v3
|
||||||
uses: actions/checkout@v3
|
- run: npx browserslist@latest --update-db
|
||||||
|
- name: Commit changes
|
||||||
|
uses: EndBug/add-and-commit@v9
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
author_name: ${{ github.actor }}
|
||||||
- name: Configure git
|
author_email: ${{ github.actor }}@users.noreply.github.com
|
||||||
run: |
|
message: 'Update Browserslist'
|
||||||
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'
|
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
name: Update Monaco-editor
|
||||||
|
on:
|
||||||
|
workflow_dispatch:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- 'dependabot/npm_and_yarn/develop/monaco-editor-**'
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
build:
|
||||||
|
runs-on: ubuntu-latest
|
||||||
|
steps:
|
||||||
|
- uses: actions/checkout@v3
|
||||||
|
- uses: actions/setup-node@v3
|
||||||
|
with:
|
||||||
|
node-version: 18
|
||||||
|
- name: Update monaco version
|
||||||
|
run: |
|
||||||
|
yarn install
|
||||||
|
node ./bin/update-monaco.js
|
||||||
|
- name: Commit changes
|
||||||
|
uses: EndBug/add-and-commit@v9
|
||||||
|
with:
|
||||||
|
author_name: ${{ github.actor }}
|
||||||
|
author_email: ${{ github.actor }}@users.noreply.github.com
|
||||||
|
message: 'Update Monaco-editor'
|
||||||
@@ -12,3 +12,6 @@ yarn-error.log
|
|||||||
/cypress/downloads
|
/cypress/downloads
|
||||||
/cypress/videos
|
/cypress/videos
|
||||||
/cypress/screenshots
|
/cypress/screenshots
|
||||||
|
/test-results/
|
||||||
|
/playwright-report/
|
||||||
|
/playwright/.cache/
|
||||||
|
|||||||
Vendored
+1
-19
@@ -1,24 +1,6 @@
|
|||||||
{
|
{
|
||||||
"editor.formatOnSave": true,
|
"editor.formatOnSave": true,
|
||||||
"cSpell.blockCheckingWhenLineLengthGreaterThan": 150,
|
"cSpell.words": ["asyncable", "KROKI", "mindmap", "pako", "Serde", "serdes", "tailwindcss"],
|
||||||
"cSpell.words": [
|
|
||||||
"asyncable",
|
|
||||||
"Browserslist",
|
|
||||||
"ckppp",
|
|
||||||
"corg",
|
|
||||||
"cssnano",
|
|
||||||
"daisyui",
|
|
||||||
"esserializer",
|
|
||||||
"KROKI",
|
|
||||||
"localstorage",
|
|
||||||
"mermaidchart",
|
|
||||||
"mindmap",
|
|
||||||
"pako",
|
|
||||||
"Serde",
|
|
||||||
"serdes",
|
|
||||||
"tailwindcss",
|
|
||||||
"uparrow"
|
|
||||||
],
|
|
||||||
"vitest.commandLine": "yarn test:unit",
|
"vitest.commandLine": "yarn test:unit",
|
||||||
"vitest.enable": true,
|
"vitest.enable": true,
|
||||||
"testing.autoRun.mode": "rerun",
|
"testing.autoRun.mode": "rerun",
|
||||||
|
|||||||
+3
-3
@@ -1,17 +1,17 @@
|
|||||||
# Two-stage docker container for mermaid-js/mermaid-live-editor
|
# Two-stage docker container for mermaid-js/mermaid-live-editor
|
||||||
# Build : docker build -t mermaid-js/mermaid-live-editor .
|
# Build : docker build -t mermaid-js/mermaid-live-editor .
|
||||||
# Run : docker run --name mermaid-live-editor --publish 8080:8080 mermaid-js/mermaid-live-editor
|
# Run : docker run --name mermaid-live-editor --publish 8080:80 mermaid-js/mermaid-live-editor
|
||||||
# Start : docker start mermaid-live-editor
|
# Start : docker start mermaid-live-editor
|
||||||
# Use webbrowser : http://localhost:8080
|
# Use webbrowser : http://localhost:8080
|
||||||
# Stop : press ctrl + c
|
# Stop : press ctrl + c
|
||||||
# or
|
# or
|
||||||
# docker stop mermaid-live-editor
|
# docker stop mermaid-live-editor
|
||||||
FROM node:18.17.1 as mermaid-live-editor-builder
|
FROM node:18.12.1 as mermaid-live-editor-builder
|
||||||
COPY --chown=node:node . /home
|
COPY --chown=node:node . /home
|
||||||
WORKDIR /home
|
WORKDIR /home
|
||||||
RUN yarn install
|
RUN yarn install
|
||||||
RUN yarn build
|
RUN yarn build
|
||||||
|
|
||||||
FROM nginxinc/nginx-unprivileged:alpine as mermaid-live-editor-runner
|
FROM nginx:alpine as mermaid-live-editor-runner
|
||||||
COPY ./nginx.conf /etc/nginx/conf.d/default.conf
|
COPY ./nginx.conf /etc/nginx/conf.d/default.conf
|
||||||
COPY --from=mermaid-live-editor-builder --chown=nginx:nginx /home/docs /usr/share/nginx/html
|
COPY --from=mermaid-live-editor-builder --chown=nginx:nginx /home/docs /usr/share/nginx/html
|
||||||
|
|||||||
+2
-2
@@ -1,8 +1,8 @@
|
|||||||
FROM node:18.17.1
|
FROM node:18
|
||||||
WORKDIR /app
|
WORKDIR /app
|
||||||
COPY package.json .
|
COPY package.json .
|
||||||
COPY yarn.lock .
|
COPY yarn.lock .
|
||||||
RUN npm install
|
RUN npm install
|
||||||
COPY . .
|
COPY . .
|
||||||
RUN ls
|
RUN ls
|
||||||
CMD ["yarn", "dev"]
|
CMD ["yarn", "dev"]
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
MIT License
|
MIT License
|
||||||
|
|
||||||
Copyright (c) 2020 - 2023 Knut Sveidqvist
|
Copyright (c) 2020 - 2021 Knut Sveidqvist
|
||||||
|
|
||||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
of this software and associated documentation files (the "Software"), to deal
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ You can try out a live version [here](https://mermaid.live/).
|
|||||||
### Run published image
|
### Run published image
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker run --platform linux/amd64 --publish 8000:8080 ghcr.io/mermaid-js/mermaid-live-editor
|
docker run --publish 8000:80 ghcr.io/mermaid-js/mermaid-live-editor
|
||||||
```
|
```
|
||||||
|
|
||||||
### To configure renderer URL
|
### To configure renderer URL
|
||||||
@@ -43,24 +43,21 @@ Default is `https://kroki.io`
|
|||||||
docker compose up --build
|
docker compose up --build
|
||||||
```
|
```
|
||||||
|
|
||||||
Then open http://localhost:3000
|
Then open http://localhost:8000
|
||||||
|
|
||||||
## Setup
|
## Setup
|
||||||
|
|
||||||
Below link will help you making a copy of the repository in your local system.
|
[Volta](https://volta.sh) is used for managing node and yarn versions.
|
||||||
|
|
||||||
https://docs.github.com/en/get-started/quickstart/fork-a-repo
|
This project is set up using [Yarn](https://classic.yarnpkg.com/en/docs/getting-started):
|
||||||
|
|
||||||
## Requirements
|
```
|
||||||
|
yarn install
|
||||||
- [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
|
## Development
|
||||||
|
|
||||||
```sh
|
```
|
||||||
yarn install
|
|
||||||
yarn dev -- --open
|
yarn dev -- --open
|
||||||
```
|
```
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -6,10 +6,10 @@ export default defineConfig({
|
|||||||
viewportWidth: 1440,
|
viewportWidth: 1440,
|
||||||
viewportHeight: 768,
|
viewportHeight: 768,
|
||||||
snapshotFileName: './cypress/snapshots.js',
|
snapshotFileName: './cypress/snapshots.js',
|
||||||
defaultCommandTimeout: 5000,
|
defaultCommandTimeout: 16000,
|
||||||
requestTimeout: 5000,
|
requestTimeout: 16000,
|
||||||
retries: {
|
retries: {
|
||||||
runMode: 2,
|
runMode: 4,
|
||||||
openMode: 0
|
openMode: 0
|
||||||
},
|
},
|
||||||
e2e: {
|
e2e: {
|
||||||
|
|||||||
@@ -1,16 +1,15 @@
|
|||||||
import { typeInEditor, verifyFileSizeGreaterThan } from './util';
|
import { verifyFileSize } from './util';
|
||||||
describe('Check actions', () => {
|
describe('Check actions', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
cy.clearLocalStorage();
|
cy.clearLocalStorage();
|
||||||
cy.visit('/edit');
|
cy.visit('/edit');
|
||||||
cy.contains('Actions').click();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should update markdown code', () => {
|
it('should update markdown code', () => {
|
||||||
cy.get('#markdown')
|
cy.get('#markdown')
|
||||||
.invoke('val')
|
.invoke('val')
|
||||||
.then((oldText) => {
|
.then((oldText) => {
|
||||||
typeInEditor('C --> HistoryTest', { bottom: true, newline: true });
|
cy.get('#editor').click('bottom').type('{enter}C --> HistoryTest');
|
||||||
cy.get('#markdown')
|
cy.get('#markdown')
|
||||||
.invoke('val')
|
.invoke('val')
|
||||||
.then((newText) => {
|
.then((newText) => {
|
||||||
@@ -19,7 +18,7 @@ describe('Check actions', () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it.skip('should load gists from URL', () => {
|
it('should load gists from URL', () => {
|
||||||
cy.get('#gist').type('https://gist.github.com/sidharthv96/6268a23e673a533dcb198f241fd7012a');
|
cy.get('#gist').type('https://gist.github.com/sidharthv96/6268a23e673a533dcb198f241fd7012a');
|
||||||
cy.contains('Load Gist').click();
|
cy.contains('Load Gist').click();
|
||||||
cy.contains('Go shopping!!');
|
cy.contains('Go shopping!!');
|
||||||
@@ -29,20 +28,20 @@ describe('Check actions', () => {
|
|||||||
cy.clock(new Date(2022, 0, 1).getTime());
|
cy.clock(new Date(2022, 0, 1).getTime());
|
||||||
|
|
||||||
cy.get(`#downloadPNG`).click();
|
cy.get(`#downloadPNG`).click();
|
||||||
verifyFileSizeGreaterThan('diagram', 'png', 34_000);
|
verifyFileSize('diagram', 'png', 21_000);
|
||||||
|
|
||||||
cy.get(`#downloadSVG`).click();
|
cy.get(`#downloadSVG`).click();
|
||||||
verifyFileSizeGreaterThan('diagram', 'svg', 10_000);
|
verifyFileSize('diagram', 'svg', 10_000);
|
||||||
|
|
||||||
// Verify downloaded file is different for different diagrams
|
// Verify downloaded file is different for different diagrams
|
||||||
cy.contains('Sample Diagrams').click();
|
cy.contains('Sample Diagrams').click();
|
||||||
cy.contains('ER').click();
|
cy.contains('ER').click();
|
||||||
|
|
||||||
cy.get(`#downloadPNG`).click();
|
cy.get(`#downloadPNG`).click();
|
||||||
verifyFileSizeGreaterThan('diagram', 'png', 40_000);
|
verifyFileSize('diagram', 'png', 46_000);
|
||||||
|
|
||||||
cy.get(`#downloadSVG`).click();
|
cy.get(`#downloadSVG`).click();
|
||||||
verifyFileSizeGreaterThan('diagram', 'svg', 11_000);
|
verifyFileSize('diagram', 'svg', 12_000);
|
||||||
|
|
||||||
cy.clock().invoke('restore');
|
cy.clock().invoke('restore');
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,18 +1,16 @@
|
|||||||
import { typeInEditor, cmd } from './util';
|
import { getEditor, cmd } from './util';
|
||||||
|
|
||||||
describe('Auto sync tests', () => {
|
describe('Auto sync tests', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
cy.clearLocalStorage();
|
cy.clearLocalStorage();
|
||||||
cy.visit('/');
|
cy.visit('/');
|
||||||
cy.url().should('contain', '/edit#pako');
|
|
||||||
cy.window().should('have.property', 'editorLoaded', true);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should dim diagram when code is edited', () => {
|
it('should dim diagram when code is edited', () => {
|
||||||
cy.contains('Auto sync').click();
|
cy.contains('Auto sync').click();
|
||||||
cy.get('#view').should('not.have.class', 'outOfSync');
|
cy.get('#view').should('not.have.class', 'outOfSync');
|
||||||
cy.get('#errorContainer').should('not.exist');
|
cy.get('#errorContainer').should('not.exist');
|
||||||
typeInEditor(' C --> Test', { bottom: true });
|
getEditor({ bottom: true, newline: true }).type(' C --> Test');
|
||||||
cy.get('#view').should('have.class', 'outOfSync');
|
cy.get('#view').should('have.class', 'outOfSync');
|
||||||
cy.get('#errorContainer').should('contain.text', 'Diagram out of sync.');
|
cy.get('#errorContainer').should('contain.text', 'Diagram out of sync.');
|
||||||
cy.getLocalStorage('codeStore').snapshot();
|
cy.getLocalStorage('codeStore').snapshot();
|
||||||
@@ -21,10 +19,10 @@ describe('Auto sync tests', () => {
|
|||||||
it('should update diagram when shortcut is used', () => {
|
it('should update diagram when shortcut is used', () => {
|
||||||
cy.contains('Auto sync').click();
|
cy.contains('Auto sync').click();
|
||||||
cy.get('#view').should('not.have.class', 'outOfSync');
|
cy.get('#view').should('not.have.class', 'outOfSync');
|
||||||
typeInEditor(' C --> Test');
|
getEditor().type(' C --> Test');
|
||||||
cy.get('#view').should('have.class', 'outOfSync');
|
cy.get('#view').should('have.class', 'outOfSync');
|
||||||
cy.get('#errorContainer').should('contain.text', 'Diagram out of sync.');
|
cy.get('#errorContainer').should('contain.text', 'Diagram out of sync.');
|
||||||
typeInEditor(`${cmd}{enter}`);
|
getEditor().type(`${cmd}{enter}`);
|
||||||
cy.get('#errorContainer').should('not.exist');
|
cy.get('#errorContainer').should('not.exist');
|
||||||
cy.get('#view').should('not.have.class', 'outOfSync');
|
cy.get('#view').should('not.have.class', 'outOfSync');
|
||||||
});
|
});
|
||||||
@@ -40,22 +38,21 @@ describe('Auto sync tests', () => {
|
|||||||
it('should not dim diagram when code is in sync', () => {
|
it('should not dim diagram when code is in sync', () => {
|
||||||
cy.contains('Auto sync').click();
|
cy.contains('Auto sync').click();
|
||||||
cy.get('#view').should('not.have.class', 'outOfSync');
|
cy.get('#view').should('not.have.class', 'outOfSync');
|
||||||
typeInEditor(' C --> Test');
|
getEditor().type(' C --> Test');
|
||||||
cy.get('#view').should('have.class', 'outOfSync');
|
cy.get('#view').should('have.class', 'outOfSync');
|
||||||
cy.get('[data-cy=sync]').click();
|
cy.get('[data-cy=sync]').click();
|
||||||
cy.get('#view').should('not.have.class', 'outOfSync');
|
cy.get('#view').should('not.have.class', 'outOfSync');
|
||||||
cy.get('#autoSync').check();
|
cy.get('#autoSync').check();
|
||||||
typeInEditor('ing');
|
getEditor().type('ing');
|
||||||
cy.get('#view').should('not.have.class', 'outOfSync');
|
cy.get('#view').should('not.have.class', 'outOfSync');
|
||||||
cy.getLocalStorage('codeStore').snapshot();
|
cy.getLocalStorage('codeStore').snapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('supports commenting code out/in', () => {
|
it('supports commenting code out/in', () => {
|
||||||
cy.get('#editor').contains('Car').click();
|
getEditor().type(`{uparrow}${cmd}/`);
|
||||||
cy.get('#editor').get('textarea').type(`${cmd}/`, { force: true });
|
|
||||||
cy.get('#view').contains('Car').should('not.exist');
|
cy.get('#view').contains('Car').should('not.exist');
|
||||||
|
|
||||||
typeInEditor(`{uparrow}${cmd}/`);
|
getEditor().type(`{uparrow}${cmd}/`);
|
||||||
cy.get('#view').contains('Car').should('exist');
|
cy.get('#view').contains('Car').should('exist');
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -64,7 +61,7 @@ describe('Auto sync tests', () => {
|
|||||||
'/edit#pako:eNpljjEKwzAMRa8SNOcEnlt6gK5eVFvYJsgOqkwpIXevg9smEE1PnyfxF3DFExgISW-CczQ2D21cYU7a-SGYXRwyvTp9jUhuKlVP-eHy7zA-leQsMEmg_QOM0BLG5FujZVMsaCQmC6ahR5ks2Lw2r84ela4-aREwKpVGwKrl_s7ut3fnkjAIcg_XDzuaUhs'
|
'/edit#pako:eNpljjEKwzAMRa8SNOcEnlt6gK5eVFvYJsgOqkwpIXevg9smEE1PnyfxF3DFExgISW-CczQ2D21cYU7a-SGYXRwyvTp9jUhuKlVP-eHy7zA-leQsMEmg_QOM0BLG5FujZVMsaCQmC6ahR5ks2Lw2r84ela4-aREwKpVGwKrl_s7ut3fnkjAIcg_XDzuaUhs'
|
||||||
);
|
);
|
||||||
cy.get('#errorContainer').should('not.exist');
|
cy.get('#errorContainer').should('not.exist');
|
||||||
typeInEditor(`branch test`, { bottom: true, newline: true });
|
getEditor({ newline: true }).type(`branch test`);
|
||||||
cy.get('#editor').contains('branch test').should('exist');
|
cy.get('#editor').contains('branch test').should('exist');
|
||||||
cy.get('#errorContainer')
|
cy.get('#errorContainer')
|
||||||
.contains(
|
.contains(
|
||||||
@@ -75,9 +72,9 @@ describe('Auto sync tests', () => {
|
|||||||
|
|
||||||
it('should update diagram after entire text is removed', () => {
|
it('should update diagram after entire text is removed', () => {
|
||||||
// https://github.com/mermaid-js/mermaid-live-editor/issues/1102
|
// https://github.com/mermaid-js/mermaid-live-editor/issues/1102
|
||||||
typeInEditor(`${cmd} a {backspace}`);
|
getEditor().type(`${cmd} a {backspace}`);
|
||||||
typeInEditor('graph LR');
|
getEditor().type('graph LR');
|
||||||
typeInEditor(' {enter} A-->Car');
|
getEditor().type(' {enter} A-->Car');
|
||||||
cy.get('#view').contains('Car').should('exist');
|
cy.get('#view').contains('Car').should('exist');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -14,23 +14,23 @@ describe('Editor docs tests', () => {
|
|||||||
|
|
||||||
it('Test to see if the correct URL loads when changing from one diagram to other', () => {
|
it('Test to see if the correct URL loads when changing from one diagram to other', () => {
|
||||||
cy.contains('Flow').click();
|
cy.contains('Flow').click();
|
||||||
cy.get(`[data-cy=docs][href$="/syntax/flowchart"]`).should('exist');
|
cy.get(`[data-cy=docs][href$="/#/flowchart"]`).should('exist');
|
||||||
|
|
||||||
cy.contains('Config').click();
|
cy.contains('Config').click();
|
||||||
cy.get(`[data-cy=docs][href$="/syntax/flowchart?id=configuration"]`).should('exist');
|
cy.get(`[data-cy=docs][href$="/#/flowchart?id=configuration"]`).should('exist');
|
||||||
|
|
||||||
cy.contains('Sequence').click();
|
cy.contains('Sequence').click();
|
||||||
cy.get(`[data-cy=docs][href$="/syntax/sequenceDiagram?id=configuration"]`).should('exist');
|
cy.get(`[data-cy=docs][href$="/#/sequenceDiagram?id=configuration"]`).should('exist');
|
||||||
|
|
||||||
cy.contains('Code').click();
|
cy.contains('Code').click();
|
||||||
cy.get(`[data-cy=docs][href$="/syntax/sequenceDiagram"]`).should('exist');
|
cy.get(`[data-cy=docs][href$="/#/sequenceDiagram"]`).should('exist');
|
||||||
});
|
});
|
||||||
|
|
||||||
it("Test to check URLs for a case where config URL doesn't exist", () => {
|
it("Test to check URLs for a case where config URL doesn't exist", () => {
|
||||||
cy.contains('State').click();
|
cy.contains('State').click();
|
||||||
cy.get(`[data-cy=docs][href$="/syntax/stateDiagram"]`).should('exist');
|
cy.get(`[data-cy=docs][href$="/#/stateDiagram"]`).should('exist');
|
||||||
|
|
||||||
cy.contains('Config').click();
|
cy.contains('Config').click();
|
||||||
cy.get(`[data-cy=docs][href$="/syntax/stateDiagram"]`).should('exist');
|
cy.get(`[data-cy=docs][href$="/#/stateDiagram"]`).should('exist');
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { typeInEditor, verifyFileSnapshot } from './util';
|
import { getEditor, verifyFileSnapshot } from './util';
|
||||||
|
|
||||||
describe('Save History', () => {
|
describe('Save History', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
@@ -6,6 +6,7 @@ describe('Save History', () => {
|
|||||||
cy.clearLocalStorage();
|
cy.clearLocalStorage();
|
||||||
cy.visit('/edit');
|
cy.visit('/edit');
|
||||||
|
|
||||||
|
cy.contains('Actions').click();
|
||||||
cy.contains('History').click();
|
cy.contains('History').click();
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -23,6 +24,7 @@ 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"}]'
|
'[{"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.reload();
|
||||||
|
cy.contains('Actions').click();
|
||||||
cy.contains('History').click();
|
cy.contains('History').click();
|
||||||
cy.get('#historyList').find('li').should('have.length', 2);
|
cy.get('#historyList').find('li').should('have.length', 2);
|
||||||
cy.get('#historyList').find('No items in History').should('not.exist');
|
cy.get('#historyList').find('No items in History').should('not.exist');
|
||||||
@@ -51,14 +53,14 @@ describe('Save History', () => {
|
|||||||
expect(str).to.equal('State already saved.');
|
expect(str).to.equal('State already saved.');
|
||||||
});
|
});
|
||||||
cy.on('window:confirm', () => true);
|
cy.on('window:confirm', () => true);
|
||||||
typeInEditor(' C --> HistoryTest');
|
getEditor().type(' C --> HistoryTest');
|
||||||
cy.get('#saveHistory').click();
|
cy.get('#saveHistory').click();
|
||||||
cy.get('#historyList').find('li').should('have.length', 2);
|
cy.get('#historyList').find('li').should('have.length', 2);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should be able to restore and delete', () => {
|
it('should be able to restore and delete', () => {
|
||||||
cy.get('#saveHistory').click();
|
cy.get('#saveHistory').click();
|
||||||
typeInEditor(' C --> HistoryTest');
|
getEditor().type(' C --> HistoryTest');
|
||||||
cy.get('#historyList').find('No items in History').should('not.exist');
|
cy.get('#historyList').find('No items in History').should('not.exist');
|
||||||
cy.get('#historyList').find('li').should('have.length', 1);
|
cy.get('#historyList').find('li').should('have.length', 1);
|
||||||
cy.contains('HistoryTest');
|
cy.contains('HistoryTest');
|
||||||
@@ -68,7 +70,7 @@ describe('Save History', () => {
|
|||||||
cy.get('#historyList').find('li').should('have.length', 0);
|
cy.get('#historyList').find('li').should('have.length', 0);
|
||||||
cy.get('#historyList').contains('No items in History');
|
cy.get('#historyList').contains('No items in History');
|
||||||
cy.get('#saveHistory').click();
|
cy.get('#saveHistory').click();
|
||||||
typeInEditor(' C --> HistoryTest');
|
getEditor().type(' C --> HistoryTest');
|
||||||
cy.get('#saveHistory').click();
|
cy.get('#saveHistory').click();
|
||||||
cy.get('#editor').type('ing');
|
cy.get('#editor').type('ing');
|
||||||
cy.get('#clearHistory').click();
|
cy.get('#clearHistory').click();
|
||||||
@@ -81,16 +83,16 @@ describe('Save History', () => {
|
|||||||
|
|
||||||
// TODO: Fix #639
|
// TODO: Fix #639
|
||||||
xit('should auto save history', () => {
|
xit('should auto save history', () => {
|
||||||
typeInEditor(' C --> HistoryTest');
|
getEditor().type(' C --> HistoryTest');
|
||||||
cy.tick(70_000);
|
cy.tick(70000);
|
||||||
cy.contains('Timeline').click();
|
cy.contains('Timeline').click();
|
||||||
cy.get('#historyList').find('li').should('have.length', 1);
|
cy.get('#historyList').find('li').should('have.length', 1);
|
||||||
cy.get('#editor').type('ing');
|
cy.get('#editor').type('ing');
|
||||||
cy.tick(70_000);
|
cy.tick(70000);
|
||||||
cy.get('#historyList').find('li').should('have.length', 2);
|
cy.get('#historyList').find('li').should('have.length', 2);
|
||||||
for (let i = 0; i < 31; i++) {
|
for (let i = 0; i < 31; i++) {
|
||||||
cy.get('#editor').type('.');
|
cy.get('#editor').type('.');
|
||||||
cy.tick(70_000);
|
cy.tick(70000);
|
||||||
}
|
}
|
||||||
cy.get('#historyList').find('li').should('have.length', 30);
|
cy.get('#historyList').find('li').should('have.length', 30);
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -4,7 +4,6 @@ describe('Site Loads', () => {
|
|||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
cy.clearLocalStorage();
|
cy.clearLocalStorage();
|
||||||
cy.visit('/');
|
cy.visit('/');
|
||||||
cy.url().should('include', '/edit#pako');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it('Check Home page load', () => {
|
it('Check Home page load', () => {
|
||||||
@@ -13,12 +12,6 @@ describe('Site Loads', () => {
|
|||||||
cy.getLocalStorage('codeStore').snapshot();
|
cy.getLocalStorage('codeStore').snapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should keep code after reload', () => {
|
|
||||||
cy.get('#editor').contains('Car');
|
|
||||||
cy.reload();
|
|
||||||
cy.get('#editor').contains('Car');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('Check Redirect from old URL', () => {
|
it('Check Redirect from old URL', () => {
|
||||||
cy.visit(
|
cy.visit(
|
||||||
'/#/edit/eyJjb2RlIjoiZ3JhcGggVERcbiAgICBBW0NocmlzdG1hc10gLS0-fEdldCBtb25leXwgQihHbyBzaG9wcGluZylcbiAgICBCIC0tPiBDe0xldCBtZSB0aGlua31cbiAgICBDIC0tPnxPbmV8IERbTGFwdG9wXVxuICAgIEMgLS0-fFR3b3wgRVtpUGhvbmVdXG4gICAgQyAtLT58VGhyZWV8IEZbZmE6ZmEtY2FyIENhcl0iLCJtZXJtYWlkIjp7InRoZW1lIjoiZGVmYXVsdCJ9LCJ1cGRhdGVFZGl0b3IiOmZhbHNlfQ'
|
'/#/edit/eyJjb2RlIjoiZ3JhcGggVERcbiAgICBBW0NocmlzdG1hc10gLS0-fEdldCBtb25leXwgQihHbyBzaG9wcGluZylcbiAgICBCIC0tPiBDe0xldCBtZSB0aGlua31cbiAgICBDIC0tPnxPbmV8IERbTGFwdG9wXVxuICAgIEMgLS0-fFR3b3wgRVtpUGhvbmVdXG4gICAgQyAtLT58VGhyZWV8IEZbZmE6ZmEtY2FyIENhcl0iLCJtZXJtYWlkIjp7InRoZW1lIjoiZGVmYXVsdCJ9LCJ1cGRhdGVFZGl0b3IiOmZhbHNlfQ'
|
||||||
@@ -100,9 +93,22 @@ describe('Site Loads', () => {
|
|||||||
cy.reload(true);
|
cy.reload(true);
|
||||||
cy.contains('Please Click here to Raise an issue in github.');
|
cy.contains('Please Click here to Raise an issue in github.');
|
||||||
});
|
});
|
||||||
});
|
|
||||||
|
|
||||||
describe('Verify types of URLs', () => {
|
it('should load uncompressed URL', () => {
|
||||||
|
cy.visit(
|
||||||
|
'/edit/#eyJjb2RlIjoiZ3JhcGggVERcbiAgICBBW05ldyBZZWFyXSAtLT58R2V0IG1vbmV5fCBCKEdvIHNob3BwaW5nKVxuICAgIEIgLS0-IEN7TGV0IG1lIHRoaW5rfVxuICAgIEMgLS0-fE9uZXwgRFtMYXB0b3BdXG4gICAgQyAtLT58VHdvfCBFW2lQaG9uZV1cbiAgICBDIC0tPnxUaHJlZXwgRltmYTpmYS1jYXIgQ2FyXSIsIm1lcm1haWQiOiJ7XG4gIFwidGhlbWVcIjogXCJkZWZhdWx0XCJcbn0iLCJ1cGRhdGVFZGl0b3IiOmZhbHNlLCJhdXRvU3luYyI6dHJ1ZSwidXBkYXRlRGlhZ3JhbSI6ZmFsc2V9'
|
||||||
|
);
|
||||||
|
cy.contains('New Year');
|
||||||
|
cy.visit(
|
||||||
|
'/edit#eyJjb2RlIjoiY2xhc3NEaWFncmFtXG4gICAgQW5pbWFsIDx8LS0gRHVja1xuICAgIEFuaW1hbCA8fC0tIEZpc2hcbiAgICBBbmltYWwgPHwtLSBaZWJyYVxuICAgIEFuaW1hbCA6ICtpbnQgYWdlXG4gICAgQW5pbWFsIDogK1N0cmluZyBnZW5kZXJcbiAgICBBbmltYWw6ICtpc01hbW1hbCgpXG4gICAgQW5pbWFsOiArbWF0ZSgpXG4gICAgY2xhc3MgRHVja3tcbiAgICAgICtTdHJpbmcgYmVha0NvbG9yXG4gICAgICArc3dpbSgpXG4gICAgICArcXVhY2soKVxuICAgIH1cbiAgICBjbGFzcyBGaXNoe1xuICAgICAgLWludCBzaXplSW5GZWV0XG4gICAgICAtY2FuRWF0KClcbiAgICB9XG4gICAgY2xhc3MgWmVicmF7XG4gICAgICArYm9vbCBpc193aWxkXG4gICAgICArcnVuKClcbiAgICB9XG4gICAgICAgICAgICAiLCJtZXJtYWlkIjoie1xuICBcInRoZW1lXCI6IFwiZGFya1wiXG59IiwidXBkYXRlRWRpdG9yIjpmYWxzZSwiYXV0b1N5bmMiOnRydWUsInVwZGF0ZURpYWdyYW0iOmZhbHNlfQ'
|
||||||
|
);
|
||||||
|
cy.contains('Animal');
|
||||||
|
cy.visit(
|
||||||
|
'/edit/#base64:eyJjb2RlIjoiZ3JhcGggVERcbiAgICBBW05ldyBZZWFyXSAtLT58R2V0IG1vbmV5fCBCKEdvIHNob3BwaW5nKVxuICAgIEIgLS0-IEN7TGV0IG1lIHRoaW5rfVxuICAgIEMgLS0-fE9uZXwgRFtMYXB0b3BdXG4gICAgQyAtLT58VHdvfCBFW2lQaG9uZV1cbiAgICBDIC0tPnxUaHJlZXwgRltmYTpmYS1jYXIgQ2FyXSIsIm1lcm1haWQiOiJ7XG4gIFwidGhlbWVcIjogXCJkZWZhdWx0XCJcbn0iLCJ1cGRhdGVFZGl0b3IiOmZhbHNlLCJhdXRvU3luYyI6dHJ1ZSwidXBkYXRlRGlhZ3JhbSI6ZmFsc2V9'
|
||||||
|
);
|
||||||
|
cy.contains('New Year');
|
||||||
|
});
|
||||||
|
|
||||||
it('should load compressed URL', () => {
|
it('should load compressed URL', () => {
|
||||||
cy.visit(
|
cy.visit(
|
||||||
'/edit#pako:eNpVkM2KwkAQhF-l6dMK5gVyEDRxvYi7sF6WjIcm0zqDzg_jBJEk725Hd2G3Tw31VVFUj23QjCWeEkUD-1p5kFs2O77BN1M6QFEshg1ncMHzfYDV2ybA1YQYrT_NXvhqgqDqtxPGkI315_ElVU__h-cB6mZLMYd4-Kvsb2GAdWM_jcT_V0xicb03RyqPVLSUoJI-OEfHyZHV0rqfDAqzYccKS3k1pbNC5Ufhuqgp81rbHBJKxuXKc6Quh6-7b7HMqeNfqLYkC7gfanwAlW1ZvQ'
|
'/edit#pako:eNpVkM2KwkAQhF-l6dMK5gVyEDRxvYi7sF6WjIcm0zqDzg_jBJEk725Hd2G3Tw31VVFUj23QjCWeEkUD-1p5kFs2O77BN1M6QFEshg1ncMHzfYDV2ybA1YQYrT_NXvhqgqDqtxPGkI315_ElVU__h-cB6mZLMYd4-Kvsb2GAdWM_jcT_V0xicb03RyqPVLSUoJI-OEfHyZHV0rqfDAqzYccKS3k1pbNC5Ufhuqgp81rbHBJKxuXKc6Quh6-7b7HMqeNfqLYkC7gfanwAlW1ZvQ'
|
||||||
@@ -113,24 +119,4 @@ describe('Verify types of URLs', () => {
|
|||||||
);
|
);
|
||||||
cy.contains('Animal');
|
cy.contains('Animal');
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('Uncompressed URLs', () => {
|
|
||||||
it('should load URL without specifier', () => {
|
|
||||||
cy.visit(
|
|
||||||
'/edit/#eyJjb2RlIjoiZ3JhcGhcbiAgICBUZXN0TGFiZWwiLCJtZXJtYWlkIjoie1xuICBcInRoZW1lXCI6IFwiZGVmYXVsdFwiXG59IiwidXBkYXRlRWRpdG9yIjpmYWxzZSwiYXV0b1N5bmMiOnRydWUsInVwZGF0ZURpYWdyYW0iOmZhbHNlfQ'
|
|
||||||
);
|
|
||||||
cy.contains('TestLabel');
|
|
||||||
cy.visit(
|
|
||||||
'/edit#eyJjb2RlIjoiY2xhc3NEaWFncmFtXG4gICAgQW5pbWFsIDx8LS0gRHVja1xuICAgIEFuaW1hbCA8fC0tIEZpc2hcbiAgICBBbmltYWwgPHwtLSBaZWJyYVxuICAgIEFuaW1hbCA6ICtpbnQgYWdlXG4gICAgQW5pbWFsIDogK1N0cmluZyBnZW5kZXJcbiAgICBBbmltYWw6ICtpc01hbW1hbCgpXG4gICAgQW5pbWFsOiArbWF0ZSgpXG4gICAgY2xhc3MgRHVja3tcbiAgICAgICtTdHJpbmcgYmVha0NvbG9yXG4gICAgICArc3dpbSgpXG4gICAgICArcXVhY2soKVxuICAgIH1cbiAgICBjbGFzcyBGaXNoe1xuICAgICAgLWludCBzaXplSW5GZWV0XG4gICAgICAtY2FuRWF0KClcbiAgICB9XG4gICAgY2xhc3MgWmVicmF7XG4gICAgICArYm9vbCBpc193aWxkXG4gICAgICArcnVuKClcbiAgICB9XG4gICAgICAgICAgICAiLCJtZXJtYWlkIjoie1xuICBcInRoZW1lXCI6IFwiZGFya1wiXG59IiwidXBkYXRlRWRpdG9yIjpmYWxzZSwiYXV0b1N5bmMiOnRydWUsInVwZGF0ZURpYWdyYW0iOmZhbHNlfQ'
|
|
||||||
);
|
|
||||||
cy.contains('Animal');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should load URL with "base64" specifier', () => {
|
|
||||||
cy.visit(
|
|
||||||
'/edit/#base64:eyJjb2RlIjoiZ3JhcGhcbiAgICBUZXN0TGFiZWwiLCJtZXJtYWlkIjoie1xuICBcInRoZW1lXCI6IFwiZGVmYXVsdFwiXG59IiwidXBkYXRlRWRpdG9yIjpmYWxzZSwiYXV0b1N5bmMiOnRydWUsInVwZGF0ZURpYWdyYW0iOmZhbHNlfQ'
|
|
||||||
);
|
|
||||||
cy.contains('TestLabel');
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ describe('Test themes', () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
cy.contains('Theme').click();
|
cy.contains('Change Theme').click();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set light theme as default', () => {
|
it('should set light theme as default', () => {
|
||||||
@@ -44,7 +44,7 @@ describe('Test themes', () => {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
cy.contains('Theme').click();
|
cy.contains('Change Theme').click();
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should set dark theme as default', () => {
|
it('should set dark theme as default', () => {
|
||||||
|
|||||||
+11
-28
@@ -1,30 +1,16 @@
|
|||||||
export const cmd = `{${Cypress.platform === 'darwin' ? 'meta' : 'ctrl'}}`;
|
export const cmd = `{${Cypress.platform === 'darwin' ? 'meta' : 'ctrl'}}`;
|
||||||
|
|
||||||
interface EditorOptions {
|
export const getEditor = ({ bottom = true, newline = false } = {}) =>
|
||||||
bottom?: boolean;
|
cy
|
||||||
newline?: boolean;
|
.get('#editor textarea:first')
|
||||||
}
|
.click()
|
||||||
|
.focused()
|
||||||
export const typeInEditor = (
|
.type(`${bottom ? '{pageDown}' : cmd}`)
|
||||||
text: string,
|
.type(`${newline ? '{enter}' : cmd}`);
|
||||||
{ bottom = true, newline = false }: EditorOptions = {}
|
|
||||||
) => {
|
|
||||||
cy.window().should('have.property', 'editorLoaded', true);
|
|
||||||
cy.get('#editor').click();
|
|
||||||
cy.get('#editor').within(($editor) => {
|
|
||||||
if (bottom) {
|
|
||||||
cy.get('textarea').type('{pageDown}', { force: true });
|
|
||||||
}
|
|
||||||
if (newline) {
|
|
||||||
cy.get('textarea').type('{enter}', { force: true });
|
|
||||||
}
|
|
||||||
cy.get('textarea').type(text, { force: true });
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
const downloadsFolder = Cypress.config('downloadsFolder');
|
const downloadsFolder = Cypress.config('downloadsFolder');
|
||||||
|
|
||||||
export const verifyFileSizeGreaterThan = (
|
export const verifyFileSize = (
|
||||||
fileType: 'history' | 'diagram',
|
fileType: 'history' | 'diagram',
|
||||||
extension: string,
|
extension: string,
|
||||||
size: number
|
size: number
|
||||||
@@ -35,10 +21,7 @@ export const verifyFileSizeGreaterThan = (
|
|||||||
cy.verifyDownload(fileName);
|
cy.verifyDownload(fileName);
|
||||||
cy.readFile(filePath, null, {
|
cy.readFile(filePath, null, {
|
||||||
log: false
|
log: false
|
||||||
}).then((buffer: ArrayBuffer) => {
|
}).then((buffer) => expect((buffer as ArrayBuffer).byteLength).to.be.gt(size));
|
||||||
expect(buffer.byteLength).to.be.gt(size);
|
|
||||||
expect(buffer.byteLength).to.be.lt(size * 1.3);
|
|
||||||
});
|
|
||||||
cy.task('deleteFile', filePath);
|
cy.task('deleteFile', filePath);
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -53,8 +36,8 @@ export const verifyFileSnapshot = (
|
|||||||
cy.verifyDownload(fileName);
|
cy.verifyDownload(fileName);
|
||||||
cy.readFile(filePath, null, {
|
cy.readFile(filePath, null, {
|
||||||
log: false
|
log: false
|
||||||
}).then((buffer: ArrayBuffer) =>
|
}).then((buffer) =>
|
||||||
expect(new TextDecoder('utf8').decode(buffer)).to.contain(content)
|
expect(new TextDecoder('utf-8').decode(buffer as ArrayBuffer)).to.contain(content)
|
||||||
);
|
);
|
||||||
cy.task('deleteFile', filePath);
|
cy.task('deleteFile', filePath);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
module.exports = {
|
module.exports = {
|
||||||
"Site Loads": {
|
"Site Loads": {
|
||||||
"Check Home page load": {
|
"Check Home page load": {
|
||||||
"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}"
|
"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}"
|
||||||
},
|
},
|
||||||
"Check Redirect from old URL": {
|
"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}"
|
"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}"
|
||||||
@@ -16,13 +16,13 @@ module.exports = {
|
|||||||
"1": "{\"code\":\"graph TD\\n A[Party] -->|Get money| B(Go shopping!!)\\n \",\"mermaid\":\"{\\n \\\"theme\\\": \\\"forest\\\",\\n \\\"test\\\": \\\"hello world\\\"\\n}\",\"autoSync\":true,\"updateDiagram\":true,\"loader\":{\"type\":\"files\",\"config\":{\"codeURL\":\"https://gist.githubusercontent.com/sidharthv96/6268a23e673a533dcb198f241fd7012a/raw/4eb03887e6a41397e80bdcdbf94017c498f8f1e2/code.mmd\",\"configURL\":\"https://gist.githubusercontent.com/sidharthv96/6268a23e673a533dcb198f241fd7012a/raw/4eb03887e6a41397e80bdcdbf94017c498f8f1e2/config.json\"}}}"
|
"1": "{\"code\":\"graph TD\\n A[Party] -->|Get money| B(Go shopping!!)\\n \",\"mermaid\":\"{\\n \\\"theme\\\": \\\"forest\\\",\\n \\\"test\\\": \\\"hello world\\\"\\n}\",\"autoSync\":true,\"updateDiagram\":true,\"loader\":{\"type\":\"files\",\"config\":{\"codeURL\":\"https://gist.githubusercontent.com/sidharthv96/6268a23e673a533dcb198f241fd7012a/raw/4eb03887e6a41397e80bdcdbf94017c498f8f1e2/code.mmd\",\"configURL\":\"https://gist.githubusercontent.com/sidharthv96/6268a23e673a533dcb198f241fd7012a/raw/4eb03887e6a41397e80bdcdbf94017c498f8f1e2/config.json\"}}}"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"__version": "12.17.4",
|
"__version": "11.2.0",
|
||||||
"Auto sync tests": {
|
"Auto sync tests": {
|
||||||
"should dim diagram when code is edited": {
|
"should dim diagram when code is edited": {
|
||||||
"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}"
|
"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}"
|
||||||
},
|
},
|
||||||
"should not dim diagram when code is in sync": {
|
"should not dim diagram when code is in sync": {
|
||||||
"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}"
|
"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}"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"Test themes": {
|
"Test themes": {
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"allowJs": true,
|
"allowJs": true,
|
||||||
"types": ["cypress", "cypress-localstorage-commands", "cy-verify-downloads", "node"]
|
"types": ["cypress", "cypress-localstorage-commands", "cy-verify-downloads"]
|
||||||
},
|
},
|
||||||
"include": ["**/*.ts"]
|
"include": ["**/*.ts"]
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -7,5 +7,5 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- ./src:/app/src
|
- ./src:/app/src
|
||||||
ports:
|
ports:
|
||||||
- 3000:3000
|
- 8080:8080
|
||||||
- 24678:24678
|
- 24678:24678
|
||||||
|
|||||||
+1
-1
@@ -1,5 +1,5 @@
|
|||||||
server {
|
server {
|
||||||
listen 8080;
|
listen 80;
|
||||||
server_name mermaid;
|
server_name mermaid;
|
||||||
location / {
|
location / {
|
||||||
root /usr/share/nginx/html;
|
root /usr/share/nginx/html;
|
||||||
|
|||||||
+47
-44
@@ -19,66 +19,69 @@
|
|||||||
"test:coverage": "vitest run --coverage",
|
"test:coverage": "vitest run --coverage",
|
||||||
"test:browser": "cypress run",
|
"test:browser": "cypress run",
|
||||||
"test": "test:unit && test:browser",
|
"test": "test:unit && test:browser",
|
||||||
"cy": "cypress open"
|
"cy": "cypress open",
|
||||||
|
"pw": "npx playwright test"
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@cypress/snapshot": "2.1.7",
|
"@cypress/snapshot": "2.1.7",
|
||||||
"@sveltejs/adapter-static": "2.0.3",
|
"@playwright/test": "^1.28.1",
|
||||||
"@sveltejs/kit": "1.25.0",
|
"@sveltejs/adapter-static": "1.0.0-next.48",
|
||||||
"@testing-library/jest-dom": "5.17.0",
|
"@sveltejs/kit": "1.0.0-next.561",
|
||||||
|
"@testing-library/jest-dom": "5.16.5",
|
||||||
"@testing-library/svelte": "3.2.2",
|
"@testing-library/svelte": "3.2.2",
|
||||||
"@types/pako": "2.0.0",
|
"@types/pako": "2.0.0",
|
||||||
"@types/uuid": "9.0.4",
|
"@types/uuid": "8.3.4",
|
||||||
"@typescript-eslint/eslint-plugin": "5.62.0",
|
"@typescript-eslint/eslint-plugin": "5.44.0",
|
||||||
"@typescript-eslint/parser": "5.62.0",
|
"@typescript-eslint/parser": "5.44.0",
|
||||||
"@vitest/ui": "^0.34.0",
|
"@vitest/ui": "^0.25.3",
|
||||||
"autoprefixer": "^10.4.14",
|
"autoprefixer": "^10.4.13",
|
||||||
"c8": "7.14.0",
|
"c8": "7.12.0",
|
||||||
"chai": "^4.3.7",
|
"chai": "^4.3.7",
|
||||||
"cssnano": "^6.0.0",
|
"cssnano": "^5.1.14",
|
||||||
"cy-verify-downloads": "0.2.0",
|
"cy-verify-downloads": "0.1.11",
|
||||||
"cypress": "12.17.4",
|
"cypress": "11.2.0",
|
||||||
"cypress-localstorage-commands": "2.2.4",
|
"cypress-localstorage-commands": "2.2.1",
|
||||||
"eslint": "8.49.0",
|
"eslint": "8.28.0",
|
||||||
"eslint-config-prettier": "8.10.0",
|
"eslint-config-prettier": "8.5.0",
|
||||||
"eslint-plugin-cypress": "2.14.0",
|
"eslint-plugin-cypress": "2.12.1",
|
||||||
"eslint-plugin-es": "4.1.0",
|
"eslint-plugin-es": "4.1.0",
|
||||||
"eslint-plugin-no-only-tests": "^3.1.0",
|
"eslint-plugin-no-only-tests": "^3.1.0",
|
||||||
"eslint-plugin-postcss-modules": "2.0.0",
|
"eslint-plugin-postcss-modules": "2.0.0",
|
||||||
"eslint-plugin-svelte3": "4.0.0",
|
"eslint-plugin-svelte3": "4.0.0",
|
||||||
"eslint-plugin-tailwindcss": "3.13.0",
|
"eslint-plugin-tailwindcss": "3.7.0",
|
||||||
"eslint-plugin-unicorn": "^46.0.0",
|
"eslint-plugin-vitest": "^0.0.20",
|
||||||
"eslint-plugin-vitest": "^0.3.0",
|
"esserializer": "1.3.5",
|
||||||
"esserializer": "1.3.11",
|
|
||||||
"font-awesome": "^4.7.0",
|
"font-awesome": "^4.7.0",
|
||||||
"husky": "^8.0.3",
|
"husky": "^8.0.2",
|
||||||
"jsdom": "21.1.2",
|
"jsdom": "20.0.3",
|
||||||
"lint-staged": "13.3.0",
|
"lint-staged": "13.0.3",
|
||||||
"node-html-parser": "^6.1.5",
|
"node-html-parser": "^6.1.4",
|
||||||
"postcss": "^8.4.21",
|
"postcss": "^8.4.19",
|
||||||
"postcss-load-config": "4.0.1",
|
"postcss-load-config": "4.0.1",
|
||||||
"prettier": "2.8.8",
|
"prettier": "2.8.0",
|
||||||
"prettier-plugin-svelte": "^2.10.0",
|
"prettier-plugin-svelte": "^2.8.1",
|
||||||
"svelte": "3.59.2",
|
"svelte": "3.53.1",
|
||||||
"svelte-preprocess": "5.0.4",
|
"svelte-preprocess": "4.10.7",
|
||||||
"tailwindcss": "^3.3.1",
|
"tailwindcss": "^3.2.4",
|
||||||
"tslib": "^2.5.0",
|
"tslib": "^2.4.1",
|
||||||
"typescript": "5.2.2",
|
"typescript": "4.9.3",
|
||||||
"vite": "^4.3.9",
|
"vite": "^3.2.4",
|
||||||
"vitest": "^0.34.0"
|
"vitest": "^0.25.3"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"analytics": "0.8.9",
|
"@mermaid-js/mermaid-mindmap": "9.2.2",
|
||||||
|
"analytics": "0.8.1",
|
||||||
"analytics-plugin-plausible": "0.0.6",
|
"analytics-plugin-plausible": "0.0.6",
|
||||||
"daisyui": "2.52.0",
|
"daisyui": "2.42.1",
|
||||||
"dayjs": "^1.11.7",
|
"js-base64": "3.7.3",
|
||||||
"js-base64": "3.7.5",
|
"mermaid": "9.2.2",
|
||||||
"mermaid": "10.5.0",
|
"moment": "2.29.4",
|
||||||
"monaco-editor": "0.43.0",
|
"monaco-editor": "0.34.1",
|
||||||
|
"monaco-mermaid": "1.0.8",
|
||||||
"pako": "2.1.0",
|
"pako": "2.1.0",
|
||||||
"random-word-slugs": "0.1.7",
|
"random-word-slugs": "0.1.6",
|
||||||
"svg-pan-zoom": "3.6.1",
|
"svg-pan-zoom": "3.6.1",
|
||||||
"uuid": "9.0.1"
|
"uuid": "9.0.0"
|
||||||
},
|
},
|
||||||
"lint-staged": {
|
"lint-staged": {
|
||||||
"*.{ts,svelte,js,css,md,json}": [
|
"*.{ts,svelte,js,css,md,json}": [
|
||||||
@@ -87,7 +90,7 @@
|
|||||||
]
|
]
|
||||||
},
|
},
|
||||||
"volta": {
|
"volta": {
|
||||||
"node": "18.17.1",
|
"node": "18.12.1",
|
||||||
"yarn": "1.22.19"
|
"yarn": "1.22.19"
|
||||||
},
|
},
|
||||||
"engines": {
|
"engines": {
|
||||||
|
|||||||
@@ -0,0 +1,106 @@
|
|||||||
|
import type { PlaywrightTestConfig } from '@playwright/test';
|
||||||
|
import { devices } from '@playwright/test';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Read environment variables from file.
|
||||||
|
* https://github.com/motdotla/dotenv
|
||||||
|
*/
|
||||||
|
// require('dotenv').config();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* See https://playwright.dev/docs/test-configuration.
|
||||||
|
*/
|
||||||
|
const config: PlaywrightTestConfig = {
|
||||||
|
testDir: './tests',
|
||||||
|
/* Maximum time one test can run for. */
|
||||||
|
timeout: 30 * 1000,
|
||||||
|
expect: {
|
||||||
|
/**
|
||||||
|
* Maximum time expect() should wait for the condition to be met.
|
||||||
|
* For example in `await expect(locator).toHaveText();`
|
||||||
|
*/
|
||||||
|
timeout: 5000
|
||||||
|
},
|
||||||
|
/* Run tests in files in parallel */
|
||||||
|
fullyParallel: true,
|
||||||
|
/* Fail the build on CI if you accidentally left test.only in the source code. */
|
||||||
|
forbidOnly: !!process.env.CI,
|
||||||
|
/* Retry on CI only */
|
||||||
|
retries: process.env.CI ? 2 : 0,
|
||||||
|
/* Opt out of parallel tests on CI. */
|
||||||
|
workers: process.env.CI ? 1 : undefined,
|
||||||
|
/* Reporter to use. See https://playwright.dev/docs/test-reporters */
|
||||||
|
reporter: 'html',
|
||||||
|
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
|
||||||
|
use: {
|
||||||
|
/* Maximum time each action such as `click()` can take. Defaults to 0 (no limit). */
|
||||||
|
actionTimeout: 0,
|
||||||
|
/* Base URL to use in actions like `await page.goto('/')`. */
|
||||||
|
baseURL: 'http://localhost:3000',
|
||||||
|
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
|
||||||
|
trace: 'on-first-retry'
|
||||||
|
},
|
||||||
|
|
||||||
|
/* Configure projects for major browsers */
|
||||||
|
projects: [
|
||||||
|
{
|
||||||
|
name: 'chromium',
|
||||||
|
use: {
|
||||||
|
...devices['Desktop Chrome']
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// {
|
||||||
|
// name: 'firefox',
|
||||||
|
// use: {
|
||||||
|
// ...devices['Desktop Firefox'],
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
|
||||||
|
// {
|
||||||
|
// name: 'webkit',
|
||||||
|
// use: {
|
||||||
|
// ...devices['Desktop Safari'],
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
|
||||||
|
/* Test against mobile viewports. */
|
||||||
|
// {
|
||||||
|
// name: 'Mobile Chrome',
|
||||||
|
// use: {
|
||||||
|
// ...devices['Pixel 5'],
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// name: 'Mobile Safari',
|
||||||
|
// use: {
|
||||||
|
// ...devices['iPhone 12'],
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
|
||||||
|
/* Test against branded browsers. */
|
||||||
|
// {
|
||||||
|
// name: 'Microsoft Edge',
|
||||||
|
// use: {
|
||||||
|
// channel: 'msedge',
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
// {
|
||||||
|
// name: 'Google Chrome',
|
||||||
|
// use: {
|
||||||
|
// channel: 'chrome',
|
||||||
|
// },
|
||||||
|
// },
|
||||||
|
]
|
||||||
|
|
||||||
|
/* Folder for test artifacts such as screenshots, videos, traces, etc. */
|
||||||
|
// outputDir: 'test-results/',
|
||||||
|
|
||||||
|
/* Run your local dev server before starting the tests */
|
||||||
|
// webServer: {
|
||||||
|
// command: 'npm run start',
|
||||||
|
// port: 3000,
|
||||||
|
// },
|
||||||
|
};
|
||||||
|
|
||||||
|
export default config;
|
||||||
@@ -11,10 +11,6 @@
|
|||||||
":automergePatch"
|
":automergePatch"
|
||||||
],
|
],
|
||||||
"packageRules": [
|
"packageRules": [
|
||||||
{
|
|
||||||
"matchPackagePatterns": ["^mermaid"],
|
|
||||||
"groupName": "Mermaid packages"
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"matchUpdateTypes": ["minor", "patch", "pin", "digest"],
|
"matchUpdateTypes": ["minor", "patch", "pin", "digest"],
|
||||||
"automerge": true
|
"automerge": true
|
||||||
|
|||||||
+30
-2
@@ -17,10 +17,38 @@
|
|||||||
<link rel="manifest" href="%sveltekit.assets%/manifest.json" />
|
<link rel="manifest" href="%sveltekit.assets%/manifest.json" />
|
||||||
<link
|
<link
|
||||||
rel="stylesheet"
|
rel="stylesheet"
|
||||||
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.4.2/css/all.min.css"
|
href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.2.1/css/all.min.css"
|
||||||
integrity="sha512-z3gLpd7yknf1YoNbCzqRKc4qyor8gaKU1qmn+CShxbuBusANI9QpRohGBreCFkKxLhei6S9CQXFEbbKuqLg0DA=="
|
integrity="sha512-MV7K8+y+gLIBoVD59lQIYicR65iaqukzvf/nwasF0nqhPay5w/9lJmVM2hMDcnK1OnMGCdVK+iQrJ7lzPJQd1w=="
|
||||||
crossorigin="anonymous"
|
crossorigin="anonymous"
|
||||||
referrerpolicy="no-referrer" />
|
referrerpolicy="no-referrer" />
|
||||||
|
<link
|
||||||
|
rel="stylesheet"
|
||||||
|
href="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.34.1/min/vs/editor/editor.main.min.css"
|
||||||
|
integrity="sha512-GzcoZD7y5zvBofYtImXPZaPVhoY7xLPt+ysmbPb/vU+quSKFkcngxaSrxuwprDZL4MALUqGFmnqCxQZqMozv1Q=="
|
||||||
|
crossorigin="anonymous"
|
||||||
|
referrerpolicy="no-referrer" />
|
||||||
|
<script>
|
||||||
|
var require = {
|
||||||
|
paths: {
|
||||||
|
vs: 'https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.34.0/min/vs'
|
||||||
|
}
|
||||||
|
};
|
||||||
|
</script>
|
||||||
|
<script
|
||||||
|
src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.34.1/min/vs/loader.min.js"
|
||||||
|
integrity="sha512-6bIYsGqvLpAiEBXPdRQeFf5cueeBECtAKJjIHer3BhBZNTV3WLcLA8Tm3pDfxUwTMIS+kAZwTUvJ1IrMdX8C5w=="
|
||||||
|
crossorigin="anonymous"
|
||||||
|
referrerpolicy="no-referrer"></script>
|
||||||
|
<script
|
||||||
|
src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.34.1/min/vs/editor/editor.main.nls.min.js"
|
||||||
|
integrity="sha512-CCv+DKWw+yZhxf4Z+ExT6HC5G+3S45TeMTYcJyYbdrv4BpK2vyALJ4FoVR/KGWDIPu7w4tNCOC9MJQIkYPR5FA=="
|
||||||
|
crossorigin="anonymous"
|
||||||
|
referrerpolicy="no-referrer"></script>
|
||||||
|
<script
|
||||||
|
src="https://cdnjs.cloudflare.com/ajax/libs/monaco-editor/0.34.1/min/vs/editor/editor.main.js"
|
||||||
|
integrity="sha512-BtSZPhzoyN8kq1axY6cgOFPSgLJgFwvAZ3WxeDGxEFXeFcFuK2s7Hr+zF75npVHASUY1dxudAfIVzwmgdR89Bw=="
|
||||||
|
crossorigin="anonymous"
|
||||||
|
referrerpolicy="no-referrer"></script>
|
||||||
%sveltekit.head%
|
%sveltekit.head%
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
|
|||||||
@@ -6,13 +6,13 @@
|
|||||||
import { stateStore } from '$lib/util/state';
|
import { stateStore } from '$lib/util/state';
|
||||||
import { logEvent } from '$lib/util/stats';
|
import { logEvent } from '$lib/util/stats';
|
||||||
import { toBase64 } from 'js-base64';
|
import { toBase64 } from 'js-base64';
|
||||||
import dayjs from 'dayjs';
|
import moment from 'moment';
|
||||||
const { krokiRendererUrl, rendererUrl } = env;
|
const { krokiRendererUrl, rendererUrl } = env;
|
||||||
|
|
||||||
type Exporter = (context: CanvasRenderingContext2D, image: HTMLImageElement) => () => void;
|
type Exporter = (context: CanvasRenderingContext2D, image: HTMLImageElement) => () => void;
|
||||||
|
|
||||||
const getFileName = (ext: string) =>
|
const getFileName = (ext: string) =>
|
||||||
`mermaid-diagram-${dayjs().format('YYYY-MM-DD-HHmmss')}.${ext}`;
|
`mermaid-diagram-${moment().format('YYYY-MM-DD-HHmmss')}.${ext}`;
|
||||||
|
|
||||||
const getBase64SVG = (svg?: HTMLElement, width?: number, height?: number): string => {
|
const getBase64SVG = (svg?: HTMLElement, width?: number, height?: number): string => {
|
||||||
height && svg?.setAttribute('height', `${height}px`);
|
height && svg?.setAttribute('height', `${height}px`);
|
||||||
@@ -180,7 +180,7 @@
|
|||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<Card title="Actions" isOpen={false}>
|
<Card title="Actions" isOpen={true}>
|
||||||
<div class="flex flex-wrap gap-2 m-2">
|
<div class="flex flex-wrap gap-2 m-2">
|
||||||
{#if isClipboardAvailable()}
|
{#if isClipboardAvailable()}
|
||||||
<button class="action-btn w-full" on:click={onCopyClipboard}
|
<button class="action-btn w-full" on:click={onCopyClipboard}
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
// 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>"`;
|
||||||
@@ -19,5 +19,6 @@ describe('card.svelte', () => {
|
|||||||
expect(container).toHaveTextContent('title1');
|
expect(container).toHaveTextContent('title1');
|
||||||
expect(container).toHaveTextContent('title2');
|
expect(container).toHaveTextContent('title2');
|
||||||
expect(container).not.toHaveTextContent('title3');
|
expect(container).not.toHaveTextContent('title3');
|
||||||
|
expect(container.innerHTML).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -3,15 +3,14 @@
|
|||||||
import { stateStore, updateCode, updateConfig } from '$lib/util/state';
|
import { stateStore, updateCode, updateConfig } from '$lib/util/state';
|
||||||
import { themeStore } from '$lib/util/theme';
|
import { themeStore } from '$lib/util/theme';
|
||||||
import { errorDebug, syncDiagram } from '$lib/util/util';
|
import { errorDebug, syncDiagram } from '$lib/util/util';
|
||||||
import * as monaco from 'monaco-editor';
|
import type monaco from 'monaco-editor';
|
||||||
import monacoJsonWorker from 'monaco-editor/esm/vs/language/json/json.worker?worker';
|
|
||||||
import monacoEditorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker';
|
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import { initEditor } from '$lib/util/monacoExtra';
|
import initEditor from 'monaco-mermaid';
|
||||||
import { logEvent } from '$lib/util/stats';
|
import { logEvent } from '$lib/util/stats';
|
||||||
|
|
||||||
let divEl: HTMLDivElement | undefined = undefined;
|
let divEl: HTMLDivElement | undefined = undefined;
|
||||||
let editor: monaco.editor.IStandaloneCodeEditor | undefined;
|
let editor: monaco.editor.IStandaloneCodeEditor | undefined;
|
||||||
|
let Monaco: typeof monaco | undefined;
|
||||||
let editorOptions: monaco.editor.IStandaloneEditorConstructionOptions = {
|
let editorOptions: monaco.editor.IStandaloneEditorConstructionOptions = {
|
||||||
minimap: {
|
minimap: {
|
||||||
enabled: false
|
enabled: false
|
||||||
@@ -22,16 +21,15 @@
|
|||||||
let text = '';
|
let text = '';
|
||||||
|
|
||||||
stateStore.subscribe(({ errorMarkers, editorMode, code, mermaid }) => {
|
stateStore.subscribe(({ errorMarkers, editorMode, code, mermaid }) => {
|
||||||
// console.log('editor store subscription', { code, mermaid });
|
console.log('editor store subscription', { code, mermaid });
|
||||||
if (!editor) {
|
if (!editor || !Monaco) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update editor text if it's different
|
// Update editor text if it's different
|
||||||
const newText = editorMode === 'code' ? code : mermaid;
|
const newText = editorMode === 'code' ? code : mermaid;
|
||||||
if (newText !== text) {
|
if (newText !== text) {
|
||||||
// console.log('updating editor text', newText);
|
console.log('updating editor text', newText);
|
||||||
editor.setScrollTop(0);
|
|
||||||
editor.setValue(newText);
|
editor.setValue(newText);
|
||||||
text = newText;
|
text = newText;
|
||||||
}
|
}
|
||||||
@@ -44,19 +42,19 @@
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (model.getLanguageId() !== language) {
|
if (model.getLanguageId() !== language) {
|
||||||
monaco.editor.setModelLanguage(model, language);
|
Monaco.editor.setModelLanguage(model, language);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Display/clear errors
|
// Display/clear errors
|
||||||
monaco.editor.setModelMarkers(model, 'mermaid', errorMarkers);
|
Monaco.editor.setModelMarkers(model, 'mermaid', errorMarkers);
|
||||||
});
|
});
|
||||||
|
|
||||||
themeStore.subscribe(({ isDark }) => {
|
themeStore.subscribe(({ isDark }) => {
|
||||||
editor && monaco.editor.setTheme(isDark ? 'mermaid-dark' : 'mermaid');
|
editor && Monaco?.editor.setTheme(isDark ? 'mermaid-dark' : 'mermaid');
|
||||||
});
|
});
|
||||||
|
|
||||||
const handleUpdate = (text: string, mode: EditorMode) => {
|
const handleUpdate = (text: string, mode: EditorMode) => {
|
||||||
// console.log('editor HandleUpdate', { text, mode });
|
console.log('editor HandleUpdate', { text, mode });
|
||||||
if (mode === 'code') {
|
if (mode === 'code') {
|
||||||
updateCode(text);
|
updateCode(text);
|
||||||
} else {
|
} else {
|
||||||
@@ -64,26 +62,36 @@
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
onMount(async () => {
|
const loadMonaco = async () => {
|
||||||
self.MonacoEnvironment = {
|
console.log('Loading Monaco...');
|
||||||
getWorker(_, label) {
|
// errorDebug();
|
||||||
if (label === 'json') {
|
let i = 0;
|
||||||
return new monacoJsonWorker();
|
while (i++ < 500) {
|
||||||
}
|
// @ts-expect-error : This is a hack to handle a svelte-kit error when importing monaco.
|
||||||
return new monacoEditorWorker();
|
Monaco = window.monaco;
|
||||||
|
if (Monaco !== undefined) {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
};
|
await new Promise((r) => setTimeout(r, 100));
|
||||||
|
}
|
||||||
|
alert('Loading Monaco Editor failed. Please try refreshing the page.');
|
||||||
|
};
|
||||||
|
|
||||||
|
onMount(async () => {
|
||||||
|
await loadMonaco(); // Fix https://github.com/mermaid-js/mermaid-live-editor/issues/175
|
||||||
|
if (!Monaco) {
|
||||||
|
throw new Error('Monaco failed to load');
|
||||||
|
}
|
||||||
if (!divEl) {
|
if (!divEl) {
|
||||||
throw new Error('divEl is undefined');
|
throw new Error('divEl is undefined');
|
||||||
}
|
}
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-call
|
||||||
initEditor(monaco);
|
initEditor(Monaco);
|
||||||
errorDebug(100);
|
errorDebug(100);
|
||||||
editor = monaco.editor.create(divEl, editorOptions);
|
editor = Monaco.editor.create(divEl, editorOptions);
|
||||||
editor.onDidChangeModelContent(({ isFlush, changes }) => {
|
editor.onDidChangeModelContent(({ isFlush, changes }) => {
|
||||||
const newText = editor?.getValue();
|
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) {
|
if (!newText || text === newText || isFlush) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -93,17 +101,17 @@
|
|||||||
editor.addAction({
|
editor.addAction({
|
||||||
id: 'mermaid-render-diagram',
|
id: 'mermaid-render-diagram',
|
||||||
label: 'Render Diagram',
|
label: 'Render Diagram',
|
||||||
keybindings: [monaco.KeyMod.CtrlCmd | monaco.KeyCode.Enter],
|
keybindings: [Monaco.KeyMod.CtrlCmd | Monaco.KeyCode.Enter],
|
||||||
run: function () {
|
run: function () {
|
||||||
syncDiagram();
|
syncDiagram();
|
||||||
logEvent('renderDiagram', {
|
logEvent('renderDiagram', {
|
||||||
method: 'keyboardShortcut'
|
method: 'keyboadShortcut'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
monaco.editor.setTheme($themeStore.isDark ? 'mermaid-dark' : 'mermaid');
|
Monaco.editor.setTheme($themeStore.isDark ? 'mermaid-dark' : 'mermaid');
|
||||||
const resizeObserver = new ResizeObserver((entries) => {
|
const resizeObserver = new ResizeObserver((entries) => {
|
||||||
editor?.layout({
|
editor!.layout({
|
||||||
height: entries[0].contentRect.height,
|
height: entries[0].contentRect.height,
|
||||||
width: entries[0].contentRect.width
|
width: entries[0].contentRect.width
|
||||||
});
|
});
|
||||||
@@ -112,14 +120,9 @@
|
|||||||
if (divEl.parentElement) {
|
if (divEl.parentElement) {
|
||||||
resizeObserver.observe(divEl.parentElement);
|
resizeObserver.observe(divEl.parentElement);
|
||||||
}
|
}
|
||||||
|
console.log(`editor mounted`);
|
||||||
// @ts-ignore
|
|
||||||
if (window.Cypress) {
|
|
||||||
// @ts-ignore
|
|
||||||
window.editorLoaded = true;
|
|
||||||
}
|
|
||||||
return () => {
|
return () => {
|
||||||
// console.log(`editor disposed`);
|
console.log(`editor disposed`);
|
||||||
editor?.dispose();
|
editor?.dispose();
|
||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -13,13 +13,10 @@
|
|||||||
import { notify, prompt } from '$lib/util/notify';
|
import { notify, prompt } from '$lib/util/notify';
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
import { get } from 'svelte/store';
|
import { get } from 'svelte/store';
|
||||||
import dayjs from 'dayjs';
|
import moment from 'moment';
|
||||||
import dayjsRelativeTime from 'dayjs/plugin/relativeTime';
|
|
||||||
import type { HistoryEntry, HistoryType, State, Tab } from '$lib/types';
|
import type { HistoryEntry, HistoryType, State, Tab } from '$lib/types';
|
||||||
import { logEvent } from '$lib/util/stats';
|
import { logEvent } from '$lib/util/stats';
|
||||||
|
|
||||||
dayjs.extend(dayjsRelativeTime);
|
|
||||||
|
|
||||||
const HISTORY_SAVE_INTERVAL = 60000;
|
const HISTORY_SAVE_INTERVAL = 60000;
|
||||||
|
|
||||||
const tabSelectHandler = (message: CustomEvent<Tab>) => {
|
const tabSelectHandler = (message: CustomEvent<Tab>) => {
|
||||||
@@ -44,7 +41,7 @@
|
|||||||
const url = URL.createObjectURL(blob);
|
const url = URL.createObjectURL(blob);
|
||||||
const a = document.createElement('a');
|
const a = document.createElement('a');
|
||||||
a.href = url;
|
a.href = url;
|
||||||
a.download = `mermaid-history-${dayjs().format('YYYY-MM-DD-HHmmss')}.json`;
|
a.download = `mermaid-history-${moment().format('YYYY-MM-DD-HHmmss')}.json`;
|
||||||
a.click();
|
a.click();
|
||||||
URL.revokeObjectURL(url);
|
URL.revokeObjectURL(url);
|
||||||
logEvent('history', {
|
logEvent('history', {
|
||||||
@@ -98,7 +95,7 @@
|
|||||||
|
|
||||||
const relativeTime = (time: number) => {
|
const relativeTime = (time: number) => {
|
||||||
const t = new Date(time);
|
const t = new Date(time);
|
||||||
return `${new Date(t).toLocaleString()} (${dayjs(t).fromNow()})`;
|
return `${new Date(t).toLocaleString()} (${moment(t).fromNow()})`;
|
||||||
};
|
};
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
@@ -164,6 +161,7 @@
|
|||||||
<a
|
<a
|
||||||
href={url}
|
href={url}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
|
rel="noreferrer"
|
||||||
title="Open revision in new tab"
|
title="Open revision in new tab"
|
||||||
class="hover:underline text-blue-500">{name}</a>
|
class="hover:underline text-blue-500">{name}</a>
|
||||||
{:else}
|
{:else}
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-unnecessary-condition */
|
|
||||||
import type { HistoryEntry } from '$lib/types';
|
import type { HistoryEntry } from '$lib/types';
|
||||||
import { describe, it, expect } from 'vitest';
|
import { describe, it, expect } from 'vitest';
|
||||||
import {
|
import {
|
||||||
@@ -18,7 +17,7 @@ describe('history', () => {
|
|||||||
|
|
||||||
addHistoryEntry({
|
addHistoryEntry({
|
||||||
state: defaultState,
|
state: defaultState,
|
||||||
time: 12_345,
|
time: 12345,
|
||||||
type: 'manual'
|
type: 'manual'
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -26,14 +25,14 @@ describe('history', () => {
|
|||||||
window.localStorage.getItem('manualHistoryStore') ?? '[]'
|
window.localStorage.getItem('manualHistoryStore') ?? '[]'
|
||||||
) as HistoryEntry[];
|
) as HistoryEntry[];
|
||||||
|
|
||||||
expect(manualEntry.time).toBe(12_345);
|
expect(manualEntry.time).toBe(12345);
|
||||||
expect(manualEntry.type).toBe('manual');
|
expect(manualEntry.type).toBe('manual');
|
||||||
expect(manualEntry.name).not.toBeNull();
|
expect(manualEntry.name).not.toBeNull();
|
||||||
expect(manualEntry.state).not.toBeNull();
|
expect(manualEntry.state).not.toBeNull();
|
||||||
|
|
||||||
addHistoryEntry({
|
addHistoryEntry({
|
||||||
state: defaultState,
|
state: defaultState,
|
||||||
time: 54_321,
|
time: 54321,
|
||||||
type: 'auto'
|
type: 'auto'
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -41,7 +40,7 @@ describe('history', () => {
|
|||||||
window.localStorage.getItem('autoHistoryStore') ?? '[]'
|
window.localStorage.getItem('autoHistoryStore') ?? '[]'
|
||||||
) as HistoryEntry[];
|
) as HistoryEntry[];
|
||||||
|
|
||||||
expect(autoEntry.time).toBe(54_321);
|
expect(autoEntry.time).toBe(54321);
|
||||||
expect(autoEntry.type).toBe('auto');
|
expect(autoEntry.type).toBe('auto');
|
||||||
expect(autoEntry.name).not.toBeNull();
|
expect(autoEntry.name).not.toBeNull();
|
||||||
expect(autoEntry.state).not.toBeNull();
|
expect(autoEntry.state).not.toBeNull();
|
||||||
@@ -57,12 +56,12 @@ describe('history', () => {
|
|||||||
it('should clear history entries', () => {
|
it('should clear history entries', () => {
|
||||||
addHistoryEntry({
|
addHistoryEntry({
|
||||||
state: defaultState,
|
state: defaultState,
|
||||||
time: 12_345,
|
time: 12345,
|
||||||
type: 'manual'
|
type: 'manual'
|
||||||
});
|
});
|
||||||
addHistoryEntry({
|
addHistoryEntry({
|
||||||
state: { ...defaultState, code: 'graph TD\\n A[Christmas] -->|Get money| B(Go shopping)' },
|
state: { ...defaultState, code: 'graph TD\\n A[Christmas] -->|Get money| B(Go shopping)' },
|
||||||
time: 123_456,
|
time: 123456,
|
||||||
type: 'manual'
|
type: 'manual'
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -77,12 +76,12 @@ describe('history', () => {
|
|||||||
historyModeStore.set('auto');
|
historyModeStore.set('auto');
|
||||||
addHistoryEntry({
|
addHistoryEntry({
|
||||||
state: defaultState,
|
state: defaultState,
|
||||||
time: 54_321,
|
time: 54321,
|
||||||
type: 'auto'
|
type: 'auto'
|
||||||
});
|
});
|
||||||
addHistoryEntry({
|
addHistoryEntry({
|
||||||
state: { ...defaultState, code: 'graph TD\\n A[Christmas] -->|Get money| B(Go shopping)' },
|
state: { ...defaultState, code: 'graph TD\\n A[Christmas] -->|Get money| B(Go shopping)' },
|
||||||
time: 654_321,
|
time: 654321,
|
||||||
type: 'auto'
|
type: 'auto'
|
||||||
});
|
});
|
||||||
expect(get(historyStore).length).toBe(2);
|
expect(get(historyStore).length).toBe(2);
|
||||||
|
|||||||
@@ -26,27 +26,19 @@ const manualHistoryStore: Writable<HistoryEntry[]> = persist(
|
|||||||
'manualHistoryStore'
|
'manualHistoryStore'
|
||||||
);
|
);
|
||||||
|
|
||||||
export const loaderHistoryStore: Writable<HistoryEntry[]> = writable([]);
|
export const loaderHistoryStore: Writable<HistoryEntry[]> = writable([] as HistoryEntry[]);
|
||||||
|
|
||||||
export const historyStore: Readable<HistoryEntry[]> = derived(
|
export const historyStore: Readable<HistoryEntry[]> = derived(
|
||||||
[historyModeStore, autoHistoryStore, manualHistoryStore, loaderHistoryStore],
|
[historyModeStore, autoHistoryStore, manualHistoryStore, loaderHistoryStore],
|
||||||
([historyMode, autoHistories, manualHistories, loadedHistories], set) => {
|
([historyMode, autoHistories, manualHistories, loadedHistories], set) => {
|
||||||
switch (historyMode) {
|
if (historyMode === 'auto') {
|
||||||
case 'auto': {
|
set(autoHistories);
|
||||||
set(autoHistories);
|
} else if (historyMode === 'manual') {
|
||||||
break;
|
set(manualHistories);
|
||||||
}
|
} else if (historyMode === 'loader') {
|
||||||
case 'manual': {
|
set(loadedHistories);
|
||||||
set(manualHistories);
|
} else {
|
||||||
break;
|
set(autoHistories);
|
||||||
}
|
|
||||||
case 'loader': {
|
|
||||||
set(loadedHistories);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default: {
|
|
||||||
set(autoHistories);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@@ -73,10 +65,10 @@ export const addHistoryEntry = (entryToAdd: Optional<HistoryEntry, 'id'>): void
|
|||||||
}
|
}
|
||||||
return [entry, ...entries];
|
return [entry, ...entries];
|
||||||
});
|
});
|
||||||
|
} else if (entry.type === 'manual') {
|
||||||
|
manualHistoryStore.update((entries) => [entry, ...entries]);
|
||||||
|
logEvent('history', { action: 'save' });
|
||||||
}
|
}
|
||||||
|
|
||||||
manualHistoryStore.update((entries) => [entry, ...entries]);
|
|
||||||
logEvent('history', { action: 'save' });
|
|
||||||
};
|
};
|
||||||
|
|
||||||
export const clearHistoryData = (idToClear?: string): void => {
|
export const clearHistoryData = (idToClear?: string): void => {
|
||||||
@@ -98,7 +90,7 @@ export const getPreviousState = (auto: boolean): string => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const restoreHistory = (data: HistoryEntry[]) => {
|
export const restoreHistory = (data: HistoryEntry[]) => {
|
||||||
const entries = data.filter((element) => validateEntry(element));
|
const entries = data.filter(validateEntry);
|
||||||
const invalidEntryCount = data.length - entries.length;
|
const invalidEntryCount = data.length - entries.length;
|
||||||
if (invalidEntryCount > 0) {
|
if (invalidEntryCount > 0) {
|
||||||
console.error(`${invalidEntryCount} invalid history entries were removed.`);
|
console.error(`${invalidEntryCount} invalid history entries were removed.`);
|
||||||
@@ -130,23 +122,20 @@ export const restoreHistory = (data: HistoryEntry[]) => {
|
|||||||
alert('No valid entries found.');
|
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 => {
|
export const injectHistoryIDs = (): void => {
|
||||||
|
const setIDs = (entries: HistoryEntry[]) => {
|
||||||
|
for (const entry of entries) {
|
||||||
|
if (!entry.id) {
|
||||||
|
entry.id = uuidV4();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return entries;
|
||||||
|
};
|
||||||
autoHistoryStore.update(setIDs);
|
autoHistoryStore.update(setIDs);
|
||||||
manualHistoryStore.update(setIDs);
|
manualHistoryStore.update(setIDs);
|
||||||
};
|
};
|
||||||
|
|
||||||
const validateEntry = (entry: HistoryEntry): boolean => {
|
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;
|
return entry.type && entry.state && entry.time && true;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -10,19 +10,18 @@
|
|||||||
import Theme from './Theme.svelte';
|
import Theme from './Theme.svelte';
|
||||||
|
|
||||||
interface Link {
|
interface Link {
|
||||||
|
title: string;
|
||||||
href: string;
|
href: string;
|
||||||
title?: string;
|
|
||||||
icon?: string;
|
icon?: string;
|
||||||
img?: string;
|
|
||||||
}
|
}
|
||||||
const links: Link[] = [
|
const links: Link[] = [
|
||||||
{
|
{
|
||||||
title: 'Documentation',
|
title: 'Documentation',
|
||||||
href: 'https://mermaid.js.org/intro/n00b-gettingStarted.html'
|
href: 'https://mermaid-js.github.io/mermaid/#/n00b-gettingStarted'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'Tutorial',
|
title: 'Tutorial',
|
||||||
href: 'https://mermaid.js.org/config/Tutorials.html'
|
href: 'https://github.com/mermaid-js/mermaid/blob/develop/docs/Tutorials.md'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
title: 'Mermaid',
|
title: 'Mermaid',
|
||||||
@@ -33,12 +32,9 @@
|
|||||||
href: 'https://github.com/mermaid-js/mermaid-cli'
|
href: 'https://github.com/mermaid-js/mermaid-cli'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
|
title: '',
|
||||||
href: 'https://github.com/mermaid-js/mermaid-live-editor',
|
href: 'https://github.com/mermaid-js/mermaid-live-editor',
|
||||||
icon: 'fab fa-github fa-lg'
|
icon: 'fab fa-github fa-lg'
|
||||||
},
|
|
||||||
{
|
|
||||||
href: 'https://mermaidchart.com',
|
|
||||||
img: '/mermaidchart-logo.svg'
|
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
</script>
|
</script>
|
||||||
@@ -51,7 +47,7 @@
|
|||||||
</div>
|
</div>
|
||||||
<label for="menu-toggle" class="pointer-cursor lg:hidden block"
|
<label for="menu-toggle" class="pointer-cursor lg:hidden block"
|
||||||
><svg
|
><svg
|
||||||
class="fill-current"
|
class="fill-current "
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
width="20"
|
width="20"
|
||||||
height="20"
|
height="20"
|
||||||
@@ -63,18 +59,13 @@
|
|||||||
<Theme />
|
<Theme />
|
||||||
<div class="hidden lg:flex lg:items-center lg:w-auto w-full" id="menu">
|
<div class="hidden lg:flex lg:items-center lg:w-auto w-full" id="menu">
|
||||||
<ul class="lg:flex items-center justify-between text-base pt-4 lg:pt-0">
|
<ul class="lg:flex items-center justify-between text-base pt-4 lg:pt-0">
|
||||||
{#each links as { title, href, icon, img }}
|
{#each links as { title, href, icon }}
|
||||||
<li>
|
<li>
|
||||||
<a class="btn btn-ghost" target="_blank" {href}>
|
<a class="btn btn-ghost" target="_blank" rel="noreferrer" {href}>
|
||||||
{#if icon}
|
{#if icon}
|
||||||
<i class={icon} />
|
<i class={icon} />
|
||||||
{:else if img}
|
|
||||||
<img src={img} alt={title} />
|
|
||||||
{/if}
|
{/if}
|
||||||
{#if title}
|
{title}</a>
|
||||||
{title}
|
|
||||||
{/if}
|
|
||||||
</a>
|
|
||||||
</li>
|
</li>
|
||||||
{/each}
|
{/each}
|
||||||
</ul>
|
</ul>
|
||||||
@@ -88,9 +79,4 @@
|
|||||||
.navbar {
|
.navbar {
|
||||||
z-index: 10000;
|
z-index: 10000;
|
||||||
}
|
}
|
||||||
|
|
||||||
img {
|
|
||||||
width: 1.5rem;
|
|
||||||
height: 1.5rem;
|
|
||||||
}
|
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -4,7 +4,7 @@
|
|||||||
import { logEvent } from '$lib/util/stats';
|
import { logEvent } from '$lib/util/stats';
|
||||||
|
|
||||||
const samples = {
|
const samples = {
|
||||||
Flow: `flowchart TD
|
Flow: `graph TD
|
||||||
A[Christmas] -->|Get money| B(Go shopping)
|
A[Christmas] -->|Get money| B(Go shopping)
|
||||||
B --> C{Let me think}
|
B --> C{Let me think}
|
||||||
C -->|One| D[Laptop]
|
C -->|One| D[Laptop]
|
||||||
@@ -101,21 +101,7 @@
|
|||||||
Argument mapping
|
Argument mapping
|
||||||
Tools
|
Tools
|
||||||
Pen and paper
|
Pen and paper
|
||||||
Mermaid`,
|
Mermaid`
|
||||||
QuadrantChart: `quadrantChart
|
|
||||||
title Reach and engagement of campaigns
|
|
||||||
x-axis Low Reach --> High Reach
|
|
||||||
y-axis Low Engagement --> High Engagement
|
|
||||||
quadrant-1 We should expand
|
|
||||||
quadrant-2 Need to promote
|
|
||||||
quadrant-3 Re-evaluate
|
|
||||||
quadrant-4 May be improved
|
|
||||||
Campaign A: [0.3, 0.6]
|
|
||||||
Campaign B: [0.45, 0.23]
|
|
||||||
Campaign C: [0.57, 0.69]
|
|
||||||
Campaign D: [0.78, 0.34]
|
|
||||||
Campaign E: [0.40, 0.34]
|
|
||||||
Campaign F: [0.35, 0.78]`
|
|
||||||
};
|
};
|
||||||
|
|
||||||
type SampleTypes = keyof typeof samples;
|
type SampleTypes = keyof typeof samples;
|
||||||
@@ -128,7 +114,7 @@
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Adding in this array will add an icon to the preset menu
|
// Adding in this array will add an icon to the preset menu
|
||||||
const newDiagrams: SampleTypes[] = ['Mindmap', 'QuadrantChart'];
|
const newDiagrams: SampleTypes[] = ['Mindmap'];
|
||||||
const diagramOrder: SampleTypes[] = [
|
const diagramOrder: SampleTypes[] = [
|
||||||
'Sequence',
|
'Sequence',
|
||||||
'Flow',
|
'Flow',
|
||||||
@@ -139,8 +125,7 @@
|
|||||||
'User Journey',
|
'User Journey',
|
||||||
'Git',
|
'Git',
|
||||||
'Pie',
|
'Pie',
|
||||||
'Mindmap',
|
'Mindmap'
|
||||||
'QuadrantChart'
|
|
||||||
];
|
];
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
|||||||
@@ -28,7 +28,7 @@
|
|||||||
|
|
||||||
<div class="hidden lg:block dropdown">
|
<div class="hidden lg:block dropdown">
|
||||||
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
|
<!-- svelte-ignore a11y-no-noninteractive-tabindex -->
|
||||||
<div tabindex="0" class="btn btn-ghost">
|
<div tabindex="0" class="btn btn-ghost ">
|
||||||
<svg
|
<svg
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
fill="none"
|
fill="none"
|
||||||
@@ -39,7 +39,7 @@
|
|||||||
stroke-linejoin="round"
|
stroke-linejoin="round"
|
||||||
stroke-width="2"
|
stroke-width="2"
|
||||||
d="M7 21a4 4 0 01-4-4V5a2 2 0 012-2h4a2 2 0 012 2v12a4 4 0 01-4 4zm0 0h12a2 2 0 002-2v-4a2 2 0 00-2-2h-2.343M11 7.343l1.657-1.657a2 2 0 012.828 0l2.829 2.829a2 2 0 010 2.828l-8.486 8.485M7 17h.01" /></svg>
|
d="M7 21a4 4 0 01-4-4V5a2 2 0 012-2h4a2 2 0 012 2v12a4 4 0 01-4 4zm0 0h12a2 2 0 002-2v-4a2 2 0 00-2-2h-2.343M11 7.343l1.657-1.657a2 2 0 012.828 0l2.829 2.829a2 2 0 010 2.828l-8.486 8.485M7 17h.01" /></svg>
|
||||||
<span class="hidden md:inline">Theme</span>
|
<span class="hidden md:inline"> Change Theme </span>
|
||||||
<svg
|
<svg
|
||||||
xmlns="http://www.w3.org/2000/svg"
|
xmlns="http://www.w3.org/2000/svg"
|
||||||
viewBox="0 0 1792 1792"
|
viewBox="0 0 1792 1792"
|
||||||
|
|||||||
@@ -79,27 +79,27 @@
|
|||||||
panZoomEnabled = state.panZoom;
|
panZoomEnabled = state.panZoom;
|
||||||
const scroll = view.parentElement!.scrollTop;
|
const scroll = view.parentElement!.scrollTop;
|
||||||
delete container.dataset.processed;
|
delete container.dataset.processed;
|
||||||
const { svg, bindFunctions } = await renderDiagram(
|
await renderDiagram(
|
||||||
Object.assign({}, JSON.parse(state.mermaid)) as MermaidConfig,
|
Object.assign({}, JSON.parse(state.mermaid)) as MermaidConfig,
|
||||||
code,
|
code,
|
||||||
'graph-div'
|
'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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
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;
|
view.parentElement!.scrollTop = scroll;
|
||||||
error = false;
|
error = false;
|
||||||
} else if (manualUpdate) {
|
} else if (manualUpdate) {
|
||||||
@@ -122,6 +122,7 @@
|
|||||||
pzoom.resize();
|
pzoom.resize();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
console.log('View mounted');
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
@@ -129,10 +130,10 @@
|
|||||||
<div
|
<div
|
||||||
class="absolute w-full p-2 z-10 font-mono {error
|
class="absolute w-full p-2 z-10 font-mono {error
|
||||||
? 'text-red-600'
|
? 'text-red-600'
|
||||||
: 'text-yellow-600'} bg-base-100 bg-opacity-80 text-left"
|
: 'text-yellow-600'} bg-base-100 bg-opacity-80 text-center"
|
||||||
id="errorContainer">
|
id="errorContainer">
|
||||||
{#if error}
|
{#if error}
|
||||||
{@html $stateStore.error?.toString().replace(/\n/g, '<br />')}
|
{@html $stateStore.error.toString().replace(/\n/g, '<br />')}
|
||||||
{:else}
|
{:else}
|
||||||
Diagram out of sync. <br />
|
Diagram out of sync. <br />
|
||||||
Press <i class="fas fa-sync" /> (Sync button) or <kbd>{cmdKey} + Enter</kbd> to sync.
|
Press <i class="fas fa-sync" /> (Sync button) or <kbd>{cmdKey} + Enter</kbd> to sync.
|
||||||
|
|||||||
Vendored
+1
-1
@@ -65,7 +65,7 @@ export type HistoryEntry = { id: string; state: State; time: number; url?: strin
|
|||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
|
||||||
export type DocumentationConfig = Record<
|
export type DocConfig = Record<
|
||||||
string,
|
string,
|
||||||
{
|
{
|
||||||
code: string;
|
code: string;
|
||||||
|
|||||||
@@ -5,7 +5,6 @@
|
|||||||
import type { State } from '$lib/types';
|
import type { State } from '$lib/types';
|
||||||
import { defaultState } from '$lib/util/state';
|
import { defaultState } from '$lib/util/state';
|
||||||
import { addHistoryEntry } from '$lib/components/History/history';
|
import { addHistoryEntry } from '$lib/components/History/history';
|
||||||
import { fetchJSON, fetchText } from '$lib/util/util';
|
|
||||||
|
|
||||||
const codeFileName = 'code.mmd';
|
const codeFileName = 'code.mmd';
|
||||||
const configFileName = 'config.json';
|
const configFileName = 'config.json';
|
||||||
@@ -22,7 +21,7 @@ const isValidGist = (files: any): boolean => {
|
|||||||
|
|
||||||
const getFileContent = async (file: GithubFile): Promise<string> => {
|
const getFileContent = async (file: GithubFile): Promise<string> => {
|
||||||
if (file.truncated) {
|
if (file.truncated) {
|
||||||
return await fetchText(file.raw_url);
|
return await (await fetch(file.raw_url)).text();
|
||||||
}
|
}
|
||||||
return file.content;
|
return file.content;
|
||||||
};
|
};
|
||||||
@@ -50,9 +49,9 @@ const getGistData = async (gistURL: string): Promise<GistData> => {
|
|||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
const [_, __, gistID, revisionID] = path.split('/');
|
const [_, __, gistID, revisionID] = path.split('/');
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||||
const { html_url, files, history }: GistResponse = await fetchJSON(
|
const { html_url, files, history }: GistResponse = await (
|
||||||
`https://api.github.com/gists/${gistID}${revisionID ? '/' + revisionID : ''}`
|
await fetch(`https://api.github.com/gists/${gistID}${revisionID ? '/' + revisionID : ''}`)
|
||||||
);
|
).json();
|
||||||
if (isValidGist(files)) {
|
if (isValidGist(files)) {
|
||||||
const code = await getFileContent(files[codeFileName]);
|
const code = await getFileContent(files[codeFileName]);
|
||||||
let config = '{}';
|
let config = '{}';
|
||||||
@@ -97,12 +96,12 @@ export const loadGistData = async (gistURL: string): Promise<State> => {
|
|||||||
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
||||||
const [_, __, gistID, revisionID] = path.split('/');
|
const [_, __, gistID, revisionID] = path.split('/');
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
|
||||||
const { history }: GistResponse = await fetchJSON(
|
const { history }: GistResponse = await (
|
||||||
`https://api.github.com/gists/${gistID}${revisionID ? '/' + revisionID : ''}`
|
await fetch(`https://api.github.com/gists/${gistID}${revisionID ? '/' + revisionID : ''}`)
|
||||||
);
|
).json();
|
||||||
const gistHistory: GistData[] = [];
|
const gistHistory: GistData[] = [];
|
||||||
for (const entry of history) {
|
for (const entry of history) {
|
||||||
const data: GistData | undefined = await getGistData(entry.url).catch();
|
const data: GistData | undefined = await getGistData(entry.url).catch(() => undefined);
|
||||||
data && gistHistory.push(data);
|
data && gistHistory.push(data);
|
||||||
}
|
}
|
||||||
if (gistHistory.length === 0) {
|
if (gistHistory.length === 0) {
|
||||||
|
|||||||
@@ -1,8 +1,6 @@
|
|||||||
import { loadGistData } from './gist';
|
import { loadGistData } from './gist';
|
||||||
import { updateCodeStore, defaultState } from '$lib/util/state';
|
import { updateCodeStore, defaultState } from '../state';
|
||||||
import { fetchText } from '$lib/util/util';
|
|
||||||
import type { Loader, State } from '$lib/types';
|
import type { Loader, State } from '$lib/types';
|
||||||
|
|
||||||
const loaders: Record<string, Loader> = {
|
const loaders: Record<string, Loader> = {
|
||||||
gist: loadGistData
|
gist: loadGistData
|
||||||
};
|
};
|
||||||
@@ -10,18 +8,34 @@ const loaders: Record<string, Loader> = {
|
|||||||
export const loadDataFromUrl = async (): Promise<void> => {
|
export const loadDataFromUrl = async (): Promise<void> => {
|
||||||
const searchParams = new URLSearchParams(window.location.search);
|
const searchParams = new URLSearchParams(window.location.search);
|
||||||
let state: Partial<State> = defaultState;
|
let state: Partial<State> = defaultState;
|
||||||
|
let code: string | undefined = undefined;
|
||||||
|
let config: string | undefined = undefined;
|
||||||
let loaded = false;
|
let loaded = false;
|
||||||
const codeURL: string | undefined = searchParams.get('code') ?? undefined;
|
const codeURL: string | undefined = searchParams.get('code') ?? undefined;
|
||||||
const configURL: string | undefined = searchParams.get('config') ?? undefined;
|
const configURL: string | undefined = searchParams.get('config') ?? undefined;
|
||||||
|
|
||||||
let code: string | undefined;
|
|
||||||
const config = configURL ? await fetchText(configURL) : defaultState.mermaid;
|
|
||||||
|
|
||||||
if (codeURL) {
|
if (codeURL) {
|
||||||
code = await fetchText(codeURL);
|
code = await (await fetch(codeURL)).text();
|
||||||
loaded = true;
|
loaded = true;
|
||||||
}
|
}
|
||||||
if (code) {
|
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 (!codeURL) {
|
if (!codeURL) {
|
||||||
throw new Error('Code URL is not defined');
|
throw new Error('Code URL is not defined');
|
||||||
}
|
}
|
||||||
@@ -36,18 +50,6 @@ 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 &&
|
loaded &&
|
||||||
updateCodeStore({
|
updateCodeStore({
|
||||||
|
|||||||
+18
-7
@@ -1,16 +1,27 @@
|
|||||||
import mermaid from 'mermaid';
|
import mermaid, { type MermaidConfig } from 'mermaid';
|
||||||
import type { MermaidConfig, RenderResult } from 'mermaid';
|
import mindmap from '@mermaid-js/mermaid-mindmap';
|
||||||
|
|
||||||
|
const initialize = mermaid.registerExternalDiagrams([mindmap]);
|
||||||
|
|
||||||
|
export const init = async () => {
|
||||||
|
await initialize;
|
||||||
|
};
|
||||||
|
|
||||||
export const render = async (
|
export const render = async (
|
||||||
config: MermaidConfig,
|
config: MermaidConfig,
|
||||||
code: string,
|
code: string,
|
||||||
id: string
|
id: string,
|
||||||
): Promise<RenderResult> => {
|
callback: Parameters<typeof mermaid.render>[2]
|
||||||
|
): Promise<void> => {
|
||||||
// Should be able to call this multiple times without any issues.
|
// Should be able to call this multiple times without any issues.
|
||||||
mermaid.initialize(config);
|
mermaid.initialize(config);
|
||||||
return await mermaid.render(id, code);
|
// console.log('Rendering', code);
|
||||||
|
// mermaid.mermaidAPI.render(id, code, callback);
|
||||||
|
await init();
|
||||||
|
await mermaid.mermaidAPI.renderAsync(id, code, callback);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const parse = async (code: string): Promise<unknown> => {
|
export const parse = async (code: string): Promise<boolean> => {
|
||||||
return await mermaid.parse(code);
|
await init();
|
||||||
|
return await mermaid.parseAsync(code);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -1,621 +0,0 @@
|
|||||||
// Modified from https://github.com/Yash-Singh1/monaco-mermaid/blob/main/index.ts
|
|
||||||
|
|
||||||
import type * as Monaco from 'monaco-editor';
|
|
||||||
|
|
||||||
export const initEditor = (monacoEditor: typeof Monaco): void => {
|
|
||||||
monacoEditor.languages.register({ id: 'mermaid' });
|
|
||||||
const requirementDiagrams = [
|
|
||||||
'requirement',
|
|
||||||
'functionalRequirement',
|
|
||||||
'interfaceRequirement',
|
|
||||||
'performanceRequirement',
|
|
||||||
'physicalRequirement',
|
|
||||||
'designConstraint'
|
|
||||||
];
|
|
||||||
const keywords: Record<
|
|
||||||
string,
|
|
||||||
{
|
|
||||||
typeKeywords: string[];
|
|
||||||
blockKeywords: string[];
|
|
||||||
keywords: string[];
|
|
||||||
}
|
|
||||||
> = {
|
|
||||||
flowchart: {
|
|
||||||
typeKeywords: ['flowchart', 'flowchart-v2', 'graph'],
|
|
||||||
blockKeywords: ['subgraph', 'end'],
|
|
||||||
keywords: [
|
|
||||||
'TB',
|
|
||||||
'TD',
|
|
||||||
'BT',
|
|
||||||
'RL',
|
|
||||||
'LR',
|
|
||||||
'click',
|
|
||||||
'call',
|
|
||||||
'href',
|
|
||||||
'_self',
|
|
||||||
'_blank',
|
|
||||||
'_parent',
|
|
||||||
'_top',
|
|
||||||
'linkStyle',
|
|
||||||
'style',
|
|
||||||
'classDef',
|
|
||||||
'class',
|
|
||||||
'direction',
|
|
||||||
'interpolate'
|
|
||||||
]
|
|
||||||
},
|
|
||||||
sequenceDiagram: {
|
|
||||||
typeKeywords: ['sequenceDiagram'],
|
|
||||||
blockKeywords: ['alt', 'par', 'and', 'loop', 'else', 'end', 'rect', 'opt', 'alt', 'rect'],
|
|
||||||
keywords: [
|
|
||||||
'participant',
|
|
||||||
'as',
|
|
||||||
'Note',
|
|
||||||
'note',
|
|
||||||
'right of',
|
|
||||||
'left of',
|
|
||||||
'over',
|
|
||||||
'activate',
|
|
||||||
'deactivate',
|
|
||||||
'autonumber',
|
|
||||||
'title',
|
|
||||||
'actor',
|
|
||||||
'accDescription',
|
|
||||||
'link',
|
|
||||||
'links'
|
|
||||||
]
|
|
||||||
},
|
|
||||||
classDiagram: {
|
|
||||||
typeKeywords: ['classDiagram', 'classDiagram-v2'],
|
|
||||||
blockKeywords: ['class'],
|
|
||||||
keywords: [
|
|
||||||
'link',
|
|
||||||
'click',
|
|
||||||
'callback',
|
|
||||||
'call',
|
|
||||||
'href',
|
|
||||||
'cssClass',
|
|
||||||
'direction',
|
|
||||||
'TB',
|
|
||||||
'BT',
|
|
||||||
'RL',
|
|
||||||
'LR',
|
|
||||||
'title',
|
|
||||||
'accDescription',
|
|
||||||
'order'
|
|
||||||
]
|
|
||||||
},
|
|
||||||
stateDiagram: {
|
|
||||||
typeKeywords: ['stateDiagram', 'stateDiagram-v2'],
|
|
||||||
blockKeywords: ['state', 'note', 'end'],
|
|
||||||
keywords: ['state', 'as', 'hide empty description', 'direction', 'TB', 'BT', 'RL', 'LR']
|
|
||||||
},
|
|
||||||
erDiagram: {
|
|
||||||
typeKeywords: ['erDiagram'],
|
|
||||||
blockKeywords: [],
|
|
||||||
keywords: ['title', 'accDescription']
|
|
||||||
},
|
|
||||||
journey: {
|
|
||||||
typeKeywords: ['journey'],
|
|
||||||
blockKeywords: ['section'],
|
|
||||||
keywords: ['title']
|
|
||||||
},
|
|
||||||
info: {
|
|
||||||
typeKeywords: ['info'],
|
|
||||||
blockKeywords: [],
|
|
||||||
keywords: ['showInfo']
|
|
||||||
},
|
|
||||||
gantt: {
|
|
||||||
typeKeywords: ['gantt'],
|
|
||||||
blockKeywords: [],
|
|
||||||
keywords: [
|
|
||||||
'title',
|
|
||||||
'dateFormat',
|
|
||||||
'axisFormat',
|
|
||||||
'todayMarker',
|
|
||||||
'section',
|
|
||||||
'excludes',
|
|
||||||
'inclusiveEndDates'
|
|
||||||
]
|
|
||||||
},
|
|
||||||
requirementDiagram: {
|
|
||||||
typeKeywords: ['requirement', 'requirementDiagram'],
|
|
||||||
blockKeywords: [...requirementDiagrams, 'element'],
|
|
||||||
keywords: []
|
|
||||||
},
|
|
||||||
gitGraph: {
|
|
||||||
typeKeywords: ['gitGraph'],
|
|
||||||
blockKeywords: [],
|
|
||||||
keywords: [
|
|
||||||
'accTitle',
|
|
||||||
'accDescr',
|
|
||||||
'commit',
|
|
||||||
'cherry-pick',
|
|
||||||
'branch',
|
|
||||||
'merge',
|
|
||||||
'reset',
|
|
||||||
'checkout',
|
|
||||||
'LR',
|
|
||||||
'BT',
|
|
||||||
'id',
|
|
||||||
'msg',
|
|
||||||
'type',
|
|
||||||
'tag',
|
|
||||||
'NORMAL',
|
|
||||||
'REVERSE',
|
|
||||||
'HIGHLIGHT'
|
|
||||||
]
|
|
||||||
},
|
|
||||||
pie: {
|
|
||||||
typeKeywords: ['pie'],
|
|
||||||
blockKeywords: [],
|
|
||||||
keywords: ['showData', 'title', 'accDescr', 'accTitle']
|
|
||||||
},
|
|
||||||
c4Diagram: {
|
|
||||||
typeKeywords: ['C4Context', 'C4Container', 'C4Component', 'C4Dynamic', 'C4Deployment'],
|
|
||||||
blockKeywords: [
|
|
||||||
'Boundary',
|
|
||||||
'Enterprise_Boundary',
|
|
||||||
'System_Boundary',
|
|
||||||
'Container_Boundary',
|
|
||||||
'Node',
|
|
||||||
'Node_L',
|
|
||||||
'Node_R'
|
|
||||||
],
|
|
||||||
keywords: [
|
|
||||||
'title',
|
|
||||||
'accDescription',
|
|
||||||
'direction',
|
|
||||||
'TB',
|
|
||||||
'BT',
|
|
||||||
'RL',
|
|
||||||
'LR',
|
|
||||||
'Person_Ext',
|
|
||||||
'Person',
|
|
||||||
'SystemQueue_Ext',
|
|
||||||
'SystemDb_Ext',
|
|
||||||
'System_Ext',
|
|
||||||
'SystemQueue',
|
|
||||||
'SystemDb',
|
|
||||||
'System',
|
|
||||||
'ContainerQueue_Ext',
|
|
||||||
'ContainerDb_Ext',
|
|
||||||
'Container_Ext',
|
|
||||||
'ContainerQueue',
|
|
||||||
'ContainerDb',
|
|
||||||
'Container',
|
|
||||||
'ComponentQueue_Ext',
|
|
||||||
'ComponentDb_Ext',
|
|
||||||
'Component_Ext',
|
|
||||||
'ComponentQueue',
|
|
||||||
'ComponentDb',
|
|
||||||
'Component',
|
|
||||||
'Deployment_Node',
|
|
||||||
'Rel',
|
|
||||||
'BiRel',
|
|
||||||
'Rel_Up',
|
|
||||||
'Rel_U',
|
|
||||||
'Rel_Down',
|
|
||||||
'Rel_D',
|
|
||||||
'Rel_Left',
|
|
||||||
'Rel_L',
|
|
||||||
'Rel_Right',
|
|
||||||
'Rel_R',
|
|
||||||
'Rel_Back',
|
|
||||||
'RelIndex'
|
|
||||||
]
|
|
||||||
},
|
|
||||||
sankey: {
|
|
||||||
typeKeywords: ['sankey-beta'],
|
|
||||||
blockKeywords: [],
|
|
||||||
keywords: []
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
const configDirectiveHandler = [
|
|
||||||
/^\s*%%(?={)/,
|
|
||||||
{
|
|
||||||
token: 'string',
|
|
||||||
next: '@configDirective',
|
|
||||||
nextEmbedded: 'javascript'
|
|
||||||
}
|
|
||||||
] as Monaco.languages.IShortMonarchLanguageRule1;
|
|
||||||
|
|
||||||
// Register a tokens provider for the mermaid language
|
|
||||||
monacoEditor.languages.setMonarchTokensProvider('mermaid', {
|
|
||||||
...Object.entries(keywords)
|
|
||||||
.map((entry) =>
|
|
||||||
Object.fromEntries(
|
|
||||||
Object.entries(entry[1]).map((deepEntry) => [
|
|
||||||
entry[0] + deepEntry[0][0].toUpperCase() + deepEntry[0].slice(1),
|
|
||||||
deepEntry[1]
|
|
||||||
])
|
|
||||||
)
|
|
||||||
)
|
|
||||||
// eslint-disable-next-line unicorn/no-array-reduce
|
|
||||||
.reduce(
|
|
||||||
(overallKeywords, nextKeyword) => ({
|
|
||||||
...overallKeywords,
|
|
||||||
...nextKeyword
|
|
||||||
}),
|
|
||||||
{}
|
|
||||||
),
|
|
||||||
tokenizer: {
|
|
||||||
root: [
|
|
||||||
[/^\s*gitGraph/m, 'typeKeyword', 'gitGraph'],
|
|
||||||
[/^\s*info/m, 'typeKeyword', 'info'],
|
|
||||||
[/^\s*pie/m, 'typeKeyword', 'pie'],
|
|
||||||
[/^\s*(flowchart|flowchart-v2|graph)/m, 'typeKeyword', 'flowchart'],
|
|
||||||
[/^\s*sequenceDiagram/, 'typeKeyword', 'sequenceDiagram'],
|
|
||||||
[/^\s*classDiagram(-v2)?/, 'typeKeyword', 'classDiagram'],
|
|
||||||
[/^\s*journey/, 'typeKeyword', 'journey'],
|
|
||||||
[/^\s*gantt/, 'typeKeyword', 'gantt'],
|
|
||||||
[/^\s*stateDiagram(-v2)?/, 'typeKeyword', 'stateDiagram'],
|
|
||||||
[/^\s*er(Diagram)?/, 'typeKeyword', 'erDiagram'],
|
|
||||||
[/^\s*requirement(Diagram)?/, 'typeKeyword', 'requirementDiagram'],
|
|
||||||
[/^\s*sankey-beta/m, 'typeKeyword', 'sankey'],
|
|
||||||
[
|
|
||||||
/^\s*(C4Context|C4Container|C4Component|C4Dynamic|C4Deployment)/m,
|
|
||||||
'typeKeyword',
|
|
||||||
'c4Diagram'
|
|
||||||
],
|
|
||||||
configDirectiveHandler,
|
|
||||||
[/%%[^${].*$/, 'comment']
|
|
||||||
],
|
|
||||||
configDirective: [[/%%$/, { token: 'string', next: '@pop', nextEmbedded: '@pop' }]],
|
|
||||||
gitGraph: [
|
|
||||||
configDirectiveHandler,
|
|
||||||
[/option(?=s)/, { token: 'typeKeyword', next: 'optionsGitGraph' }],
|
|
||||||
[/(accTitle|accDescr)(\s*:)(\s*[^\n\r]+$)/, ['keyword', 'delimiter.bracket', 'string']],
|
|
||||||
[
|
|
||||||
/(^\s*branch)(.*?)(\s+order)(:\s*)(\d+\s*$)/,
|
|
||||||
['keyword', 'variable', 'keyword', 'delimiter.bracket', 'number']
|
|
||||||
],
|
|
||||||
[/".*?"/, 'string'],
|
|
||||||
[
|
|
||||||
/(^\s*)(branch|reset|merge|checkout)(\s*\S+)/m,
|
|
||||||
['delimiter.bracket', 'keyword', 'variable']
|
|
||||||
],
|
|
||||||
[
|
|
||||||
/[A-Za-z][\w$]*/,
|
|
||||||
{
|
|
||||||
cases: {
|
|
||||||
'@gitGraphBlockKeywords': 'typeKeyword',
|
|
||||||
'@gitGraphKeywords': 'keyword'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[/%%[^$]([^%]*(?!%%$)%?)*$/, 'comment'],
|
|
||||||
[/\^/, 'delimiter.bracket']
|
|
||||||
],
|
|
||||||
optionsGitGraph: [
|
|
||||||
[
|
|
||||||
/s$/,
|
|
||||||
{
|
|
||||||
token: 'typeKeyword',
|
|
||||||
nextEmbedded: 'json'
|
|
||||||
}
|
|
||||||
],
|
|
||||||
['end', { token: 'typeKeyword', next: '@pop', nextEmbedded: '@pop' }]
|
|
||||||
],
|
|
||||||
info: [
|
|
||||||
[
|
|
||||||
/[A-Za-z][\w$]*/,
|
|
||||||
{
|
|
||||||
cases: {
|
|
||||||
'@infoBlockKeywords': 'typeKeyword',
|
|
||||||
'@infoKeywords': 'keyword'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
]
|
|
||||||
],
|
|
||||||
pie: [
|
|
||||||
configDirectiveHandler,
|
|
||||||
[/(title|accDescription)(.*$)/, ['keyword', 'string']],
|
|
||||||
[
|
|
||||||
/[A-Za-z][\w$]*/,
|
|
||||||
{
|
|
||||||
cases: {
|
|
||||||
'@pieBlockKeywords': 'typeKeyword',
|
|
||||||
'@pieKeywords': 'keyword'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[/".*?"/, 'string'],
|
|
||||||
[/\s*\d+/, 'number'],
|
|
||||||
[/:/, 'delimiter.bracket'],
|
|
||||||
[/%%[^$]([^%]*(?!%%$)%?)*$/, 'comment']
|
|
||||||
],
|
|
||||||
flowchart: [
|
|
||||||
configDirectiveHandler,
|
|
||||||
[/[ox]?(--+|==+)[ox]/, 'transition'],
|
|
||||||
[
|
|
||||||
/[A-Za-z][\w$]*/,
|
|
||||||
{
|
|
||||||
cases: {
|
|
||||||
'@flowchartBlockKeywords': 'typeKeyword',
|
|
||||||
'@flowchartKeywords': 'keyword',
|
|
||||||
'@default': 'variable'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[/\|+.+?\|+/, 'string'],
|
|
||||||
[/\[+(\\.+?[/\\]|\/.+?[/\\])]+/, 'string'],
|
|
||||||
[/[>[]+[^[\]|]+?]+/, 'string'],
|
|
||||||
[/{+.+?}+/, 'string'],
|
|
||||||
[/\(+.+?\)+/, 'string'],
|
|
||||||
[/-\.+->?/, 'transition'],
|
|
||||||
[/(-[.-])([^>-][^-]+?)(-{3,}|-{2,}>|\.-+>)/, ['transition', 'string', 'transition']],
|
|
||||||
[/(==+)([^=]+?)(={3,}|={2,}>)/, ['transition', 'string', 'transition']],
|
|
||||||
[/<?(--+|==+)>|===+|---+/, 'transition'],
|
|
||||||
[/:::/, 'transition'],
|
|
||||||
[/[&;]/, 'delimiter.bracket'],
|
|
||||||
[/".*?"/, 'string'],
|
|
||||||
[/%%[^$]([^%]*(?!%%$)%?)*$/, 'comment']
|
|
||||||
],
|
|
||||||
sequenceDiagram: [
|
|
||||||
configDirectiveHandler,
|
|
||||||
[/(title:?|accDescription)([^\n\r;]*$)/, ['keyword', 'string']],
|
|
||||||
[/(autonumber)([^\S\n\r]+off[^\S\n\r]*$)/, ['keyword', 'keyword']],
|
|
||||||
[/(autonumber)((?:[^\S\n\r]+\d+){2}[^\S\n\r]*$)/, ['keyword', 'number']],
|
|
||||||
[/(autonumber)([^\S\n\r]+\d+[^\S\n\r]*$)/, ['keyword', 'number']],
|
|
||||||
[
|
|
||||||
/(link\s+)(.*?)(:)(\s*.*?)(\s*@)(\s*[^\n\r;]+)/,
|
|
||||||
['keyword', 'variable', 'delimiter.bracket', 'string', 'delimiter.bracket', 'string']
|
|
||||||
],
|
|
||||||
[
|
|
||||||
/((?:links|properties)\s+)([^\n\r:]*?)(:\s+)/,
|
|
||||||
[
|
|
||||||
{ token: 'keyword' },
|
|
||||||
{ token: 'variable' },
|
|
||||||
{
|
|
||||||
token: 'delimiter.bracket',
|
|
||||||
nextEmbedded: 'javascript',
|
|
||||||
next: '@sequenceDiagramLinksProps'
|
|
||||||
}
|
|
||||||
]
|
|
||||||
],
|
|
||||||
[
|
|
||||||
/[A-Za-z][\w$]*/,
|
|
||||||
{
|
|
||||||
cases: {
|
|
||||||
'@sequenceDiagramBlockKeywords': 'typeKeyword',
|
|
||||||
'@sequenceDiagramKeywords': 'keyword',
|
|
||||||
'@default': 'variable'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[/(--?>?>|--?[)x])[+-]?/, 'transition'],
|
|
||||||
[/(:)([^\n:]*?$)/, ['delimiter.bracket', 'string']],
|
|
||||||
[/%%[^$]([^%]*(?!%%$)%?)*$/, 'comment']
|
|
||||||
],
|
|
||||||
sequenceDiagramLinksProps: [
|
|
||||||
// [/^:/, { token: 'delimiter.bracket', nextEmbedded: 'json' }],
|
|
||||||
[/$|;/, { nextEmbedded: '@pop', next: '@pop', token: 'delimiter.bracket' }]
|
|
||||||
],
|
|
||||||
classDiagram: [
|
|
||||||
configDirectiveHandler,
|
|
||||||
[/(^\s*(?:title|accDescription))(\s+.*$)/, ['keyword', 'string']],
|
|
||||||
[
|
|
||||||
/(\*|<\|?|o|)(--|\.\.)(\*|\|?>|o|)([\t ]*[A-Za-z]+[\t ]*)(:)(.*?$)/,
|
|
||||||
['transition', 'transition', 'transition', 'variable', 'delimiter.bracket', 'string']
|
|
||||||
],
|
|
||||||
[/(?!class\s)([A-Za-z]+)(\s+[A-Za-z]+)/, ['type', 'variable']],
|
|
||||||
[/(\*|<\|?|o)?(--|\.\.)(\*|\|?>|o)?/, 'transition'],
|
|
||||||
[/^\s*class\s(?!.*{)/, 'keyword'],
|
|
||||||
[
|
|
||||||
/[A-Za-z][\w$]*/,
|
|
||||||
{
|
|
||||||
cases: {
|
|
||||||
'@classDiagramBlockKeywords': 'typeKeyword',
|
|
||||||
'@classDiagramKeywords': 'keyword',
|
|
||||||
'@default': 'variable'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[/%%[^$]([^%]*(?!%%$)%?)*$/, 'comment'],
|
|
||||||
[/(<<)(.+?)(>>)/, ['delimiter.bracket', 'annotation', 'delimiter.bracket']],
|
|
||||||
[/".*?"/, 'string'],
|
|
||||||
[/:::/, 'transition'],
|
|
||||||
[/:|\+|-|#|~|\*\s*$|\$\s*$|\(|\)|{|}/, 'delimiter.bracket']
|
|
||||||
],
|
|
||||||
journey: [
|
|
||||||
configDirectiveHandler,
|
|
||||||
[/(title)(.*)/, ['keyword', 'string']],
|
|
||||||
[/(section)(.*)/, ['typeKeyword', 'string']],
|
|
||||||
[
|
|
||||||
/[A-Za-z][\w$]*/,
|
|
||||||
{
|
|
||||||
cases: {
|
|
||||||
'@journeyBlockKeywords': 'typeKeyword',
|
|
||||||
'@journeyKeywords': 'keyword',
|
|
||||||
'@default': 'variable'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[
|
|
||||||
/(^\s*.+?)(:)(.*?)(:)(.*?)([$,])/,
|
|
||||||
[
|
|
||||||
'string',
|
|
||||||
'delimiter.bracket',
|
|
||||||
'number',
|
|
||||||
'delimiter.bracket',
|
|
||||||
'variable',
|
|
||||||
'delimiter.bracket'
|
|
||||||
]
|
|
||||||
],
|
|
||||||
[/,/, 'delimiter.bracket'],
|
|
||||||
[/(^\s*.+?)(:)([^:]*?)$/, ['string', 'delimiter.bracket', 'variable']],
|
|
||||||
[/%%[^$]([^%]*(?!%%$)%?)*$/, 'comment']
|
|
||||||
],
|
|
||||||
gantt: [
|
|
||||||
configDirectiveHandler,
|
|
||||||
[/(title)(.*)/, ['keyword', 'string']],
|
|
||||||
[/(section)(.*)/, ['typeKeyword', 'string']],
|
|
||||||
[/^\s*([^\n:]*?)(:)/, ['string', 'delimiter.bracket']],
|
|
||||||
[
|
|
||||||
/[A-Za-z][\w$]*/,
|
|
||||||
{
|
|
||||||
cases: {
|
|
||||||
'@ganttBlockKeywords': 'typeKeyword',
|
|
||||||
'@ganttKeywords': 'keyword'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[/%%[^$]([^%]*(?!%%$)%?)*$/, 'comment'],
|
|
||||||
[/:/, 'delimiter.bracket']
|
|
||||||
],
|
|
||||||
stateDiagram: [
|
|
||||||
configDirectiveHandler,
|
|
||||||
[/note[^:]*$/, { token: 'typeKeyword', next: 'stateDiagramNote' }],
|
|
||||||
['hide empty description', 'keyword'],
|
|
||||||
[/^\s*state\s(?!.*{)/, 'keyword'],
|
|
||||||
[/(<<)(fork|join|choice)(>>)/, 'annotation'],
|
|
||||||
[/(\[\[)(fork|join|choice)(]])/, ['delimiter.bracket', 'annotation', 'delimiter.bracket']],
|
|
||||||
[
|
|
||||||
/[A-Za-z][\w$]*/,
|
|
||||||
{
|
|
||||||
cases: {
|
|
||||||
'@stateDiagramBlockKeywords': 'typeKeyword',
|
|
||||||
'@stateDiagramKeywords': 'keyword',
|
|
||||||
'@default': 'variable'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[/".*?"/, 'string'],
|
|
||||||
[/(:)([^\n:]*?$)/, ['delimiter.bracket', 'string']],
|
|
||||||
[/{|}/, 'delimiter.bracket'],
|
|
||||||
[/%%[^$]([^%]*(?!%%$)%?)*$/, 'comment'],
|
|
||||||
[/-->/, 'transition'],
|
|
||||||
[/\[.*?]/, 'string']
|
|
||||||
],
|
|
||||||
stateDiagramNote: [
|
|
||||||
[/^\s*end note$/, { token: 'typeKeyword', next: '@pop' }],
|
|
||||||
[/.*/, 'string']
|
|
||||||
],
|
|
||||||
erDiagram: [
|
|
||||||
configDirectiveHandler,
|
|
||||||
[/(title|accDescription)(.*$)/, ['keyword', 'string']],
|
|
||||||
[/[|}][o|](--|\.\.)[o|][{|]/, 'transition'],
|
|
||||||
[/".*?"/, 'string'],
|
|
||||||
[/(:)(.*?$)/, ['delimiter.bracket', 'string']],
|
|
||||||
[/[:{}]/, 'delimiter.bracket'],
|
|
||||||
[/([A-Za-z]+)(\s+[A-Za-z]+)/, ['type', 'variable']],
|
|
||||||
[/%%[^$]([^%]*(?!%%$)%?)*$/, 'comment'],
|
|
||||||
[/[A-Z_a-z-][\w$]*/, 'variable']
|
|
||||||
],
|
|
||||||
requirementDiagram: [
|
|
||||||
configDirectiveHandler,
|
|
||||||
[/->|<-|-/, 'transition'],
|
|
||||||
[/(\d+\.)*\d+/, 'number'],
|
|
||||||
[
|
|
||||||
/[A-Z_a-z-][\w$]*/,
|
|
||||||
{
|
|
||||||
cases: {
|
|
||||||
'@requirementDiagramBlockKeywords': 'typeKeyword',
|
|
||||||
'@default': 'variable'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[/[/:{}]/, 'delimiter.bracket'],
|
|
||||||
[/%%[^$]([^%]*(?!%%$)%?)*$/, 'comment'],
|
|
||||||
[/".*?"/, 'string']
|
|
||||||
],
|
|
||||||
c4Diagram: [
|
|
||||||
configDirectiveHandler,
|
|
||||||
[/(title|accDescription)(.*$)/, ['keyword', 'string']],
|
|
||||||
[/\(/, { token: 'delimiter.bracket', next: 'c4DiagramParenthesis' }],
|
|
||||||
[
|
|
||||||
/[A-Z_a-z-][\w$]*/,
|
|
||||||
{
|
|
||||||
cases: {
|
|
||||||
'@c4DiagramBlockKeywords': 'typeKeyword',
|
|
||||||
'@c4DiagramKeywords': 'keyword',
|
|
||||||
'@default': 'variable'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
],
|
|
||||||
[/%%[^$]([^%]*(?!%%$)%?)*$/, 'comment']
|
|
||||||
],
|
|
||||||
c4DiagramParenthesis: [
|
|
||||||
[/,/, 'delimiter.bracket'],
|
|
||||||
[/\)/, { next: '@pop', token: 'delimiter.bracket' }],
|
|
||||||
[/[^),]/, 'string']
|
|
||||||
],
|
|
||||||
sankey: [
|
|
||||||
configDirectiveHandler,
|
|
||||||
[/(title)(.*)/, ['keyword', 'string']],
|
|
||||||
[/(accTitle|accDescr)(\s*:)(\s*[^\n\r]+$)/, ['keyword', 'delimiter.bracket', 'string']],
|
|
||||||
[/".*?"/, 'string'],
|
|
||||||
[/[A-Za-z]+/, 'string'],
|
|
||||||
[/\s*\d+/, 'number'],
|
|
||||||
[/,/, 'delimiter.bracket'],
|
|
||||||
[/%%[^$]([^%]*(?!%%$)%?)*$/, 'comment']
|
|
||||||
]
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
monacoEditor.editor.defineTheme('mermaid-dark', {
|
|
||||||
base: 'vs-dark',
|
|
||||||
inherit: true,
|
|
||||||
colors: {},
|
|
||||||
rules: [
|
|
||||||
{ token: 'typeKeyword', foreground: '9650c8', fontStyle: 'bold' },
|
|
||||||
{ token: 'transition', foreground: '008800', fontStyle: 'bold' },
|
|
||||||
{ token: 'identifier', foreground: '9cdcfe' }
|
|
||||||
]
|
|
||||||
});
|
|
||||||
|
|
||||||
monacoEditor.editor.defineTheme('mermaid', {
|
|
||||||
base: 'vs',
|
|
||||||
inherit: true,
|
|
||||||
colors: {},
|
|
||||||
rules: [
|
|
||||||
{ token: 'typeKeyword', foreground: '9650c8', fontStyle: 'bold' },
|
|
||||||
{ token: 'keyword', foreground: '649696' },
|
|
||||||
{ token: 'custom-error', foreground: 'ff0000', fontStyle: 'bold' },
|
|
||||||
{ token: 'string', foreground: 'AA8500' },
|
|
||||||
{ token: 'transition', foreground: '008800', fontStyle: 'bold' },
|
|
||||||
{ token: 'delimiter.bracket', foreground: '000000', fontStyle: 'bold' },
|
|
||||||
{ token: 'annotation', foreground: '4b4b96' },
|
|
||||||
{ token: 'number', foreground: '4b4b96' },
|
|
||||||
{ token: 'comment', foreground: '888c89' },
|
|
||||||
{ token: 'variable', foreground: 'A22889' },
|
|
||||||
{ token: 'type', foreground: '2BDEA8' },
|
|
||||||
{ token: 'identifier', foreground: '9cdcfe' }
|
|
||||||
]
|
|
||||||
});
|
|
||||||
|
|
||||||
monacoEditor.languages.registerCompletionItemProvider('mermaid', {
|
|
||||||
provideCompletionItems: () => {
|
|
||||||
return {
|
|
||||||
suggestions: []
|
|
||||||
};
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
monacoEditor.languages.setLanguageConfiguration('mermaid', {
|
|
||||||
autoClosingPairs: [
|
|
||||||
{
|
|
||||||
open: '(',
|
|
||||||
close: ')'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
open: '{',
|
|
||||||
close: '}'
|
|
||||||
},
|
|
||||||
{
|
|
||||||
open: '[',
|
|
||||||
close: ']'
|
|
||||||
}
|
|
||||||
],
|
|
||||||
brackets: [
|
|
||||||
['(', ')'],
|
|
||||||
['{', '}'],
|
|
||||||
['[', ']']
|
|
||||||
],
|
|
||||||
comments: {
|
|
||||||
lineComment: '%%'
|
|
||||||
}
|
|
||||||
});
|
|
||||||
};
|
|
||||||
@@ -70,13 +70,13 @@ const deserialize = (value?: string | null): unknown => {
|
|||||||
if (value !== null && value !== undefined) {
|
if (value !== null && value !== undefined) {
|
||||||
try {
|
try {
|
||||||
return ESSerializer.deserialize(value);
|
return ESSerializer.deserialize(value);
|
||||||
} catch {
|
} catch (e) {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
// use the value "as is"
|
// use the value "as is"
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
return JSON.parse(value);
|
return JSON.parse(value);
|
||||||
} catch {
|
} catch (e) {
|
||||||
// Do nothing
|
// Do nothing
|
||||||
// use the value "as is"
|
// use the value "as is"
|
||||||
}
|
}
|
||||||
@@ -179,9 +179,11 @@ function getBrowserStorage(
|
|||||||
const listenerFunction = (event: StorageEvent) => {
|
const listenerFunction = (event: StorageEvent) => {
|
||||||
const eventKey = event.key;
|
const eventKey = event.key;
|
||||||
if (event.storageArea === browserStorage) {
|
if (event.storageArea === browserStorage) {
|
||||||
for (const { listener } of listeners.filter(({ key }) => key === eventKey)) {
|
listeners
|
||||||
listener(deserialize(event.newValue));
|
.filter(({ key }) => key === eventKey)
|
||||||
}
|
.forEach(({ listener }) => {
|
||||||
|
listener(deserialize(event.newValue));
|
||||||
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
const connect = () => {
|
const connect = () => {
|
||||||
|
|||||||
+10
-10
@@ -3,29 +3,29 @@ import { serializeState, deserializeState, type SerdeType } from './serde';
|
|||||||
import { defaultState } from './state';
|
import { defaultState } from './state';
|
||||||
import type { State } from '$lib/types';
|
import type { State } from '$lib/types';
|
||||||
|
|
||||||
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', () => {
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
it('should serialize and deserialize with default serde', () => {
|
it('should serialize and deserialize with default serde', () => {
|
||||||
expect(verifySerde(defaultState)).toMatchInlineSnapshot(
|
expect(verifySerde(defaultState)).toMatchInlineSnapshot(
|
||||||
'"pako:eNpVjk2Lg0AMhv9KyGkL9Q94WGh1t5fCFurN6SFo7AztfDBGpKj_fcd62c0pvM_zhkzY-JYxx-7px0ZTFKhK5SDNoS50NL1Y6m-QZZ_ziQWsd_ya4fhx8tBrH4Jx993mH1cJium8agyijXssGyre_R_HM5T1mYL4cPtLqtHP8FWbi07n_xMdObW-647yjrKGIhQU3wru0XK0ZNr0_rQmCkWzZYV5WlvuaHiKQuWWpNIg_vpyDeYSB97jEFoSLg3dI9ktXH4B_cJWqw"'
|
'"pako:eNpVj81qw0AMhF9F6NRC_AI-BGK7zSXQQHLz5iBsObuk-8Naphjb7551fEl1EjPfiNGEjW8Zc7xHChqulXKQ5lCXOppeLPU3yLL9fGQB6x2PMxQfRw-99iEYd__c-GKFoJxOK8Yg2rjHslnlK__jeIaqPlEQH27vzvXPz_BVm7NO5_87OnJKfdcd5R1lDUUoKb4Q3KHlaMm0qfq0KgpFs2WFeVpb7mj4FYXKLQmlQfxldA3mEgfe4RBaEq4MpaftJi5PNtJU8w"'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should serialize and deserialize with base64 serde', () => {
|
it('should serialize and deserialize with base64 serde', () => {
|
||||||
expect(verifySerde(defaultState, 'base64')).toMatchInlineSnapshot(
|
expect(verifySerde(defaultState, 'base64')).toMatchInlineSnapshot(
|
||||||
'"base64:eyJjb2RlIjoiZmxvd2NoYXJ0IFREXG4gICAgQVtDaHJpc3RtYXNdIC0tPnxHZXQgbW9uZXl8IEIoR28gc2hvcHBpbmcpXG4gICAgQiAtLT4gQ3tMZXQgbWUgdGhpbmt9XG4gICAgQyAtLT58T25lfCBEW0xhcHRvcF1cbiAgICBDIC0tPnxUd298IEVbaVBob25lXVxuICAgIEMgLS0-fFRocmVlfCBGW2ZhOmZhLWNhciBDYXJdXG4gICIsIm1lcm1haWQiOiJ7XG4gIFwidGhlbWVcIjogXCJkZWZhdWx0XCJcbn0iLCJhdXRvU3luYyI6dHJ1ZSwidXBkYXRlRGlhZ3JhbSI6dHJ1ZX0"'
|
'"base64:eyJjb2RlIjoiZ3JhcGggVERcbiAgICBBW0NocmlzdG1hc10gLS0-fEdldCBtb25leXwgQihHbyBzaG9wcGluZylcbiAgICBCIC0tPiBDe0xldCBtZSB0aGlua31cbiAgICBDIC0tPnxPbmV8IERbTGFwdG9wXVxuICAgIEMgLS0-fFR3b3wgRVtpUGhvbmVdXG4gICAgQyAtLT58VGhyZWV8IEZbZmE6ZmEtY2FyIENhcl1cbiAgIiwibWVybWFpZCI6IntcbiAgXCJ0aGVtZVwiOiBcImRlZmF1bHRcIlxufSIsImF1dG9TeW5jIjp0cnVlLCJ1cGRhdGVEaWFncmFtIjp0cnVlfQ"'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should serialize and deserialize with pako serde', () => {
|
it('should serialize and deserialize with pako serde', () => {
|
||||||
expect(verifySerde(defaultState, 'pako')).toMatchInlineSnapshot(
|
expect(verifySerde(defaultState, 'pako')).toMatchInlineSnapshot(
|
||||||
'"pako:eNpVjk2Lg0AMhv9KyGkL9Q94WGh1t5fCFurN6SFo7AztfDBGpKj_fcd62c0pvM_zhkzY-JYxx-7px0ZTFKhK5SDNoS50NL1Y6m-QZZ_ziQWsd_ya4fhx8tBrH4Jx993mH1cJium8agyijXssGyre_R_HM5T1mYL4cPtLqtHP8FWbi07n_xMdObW-647yjrKGIhQU3wru0XK0ZNr0_rQmCkWzZYV5WlvuaHiKQuWWpNIg_vpyDeYSB97jEFoSLg3dI9ktXH4B_cJWqw"'
|
'"pako:eNpVj81qw0AMhF9F6NRC_AI-BGK7zSXQQHLz5iBsObuk-8Naphjb7551fEl1EjPfiNGEjW8Zc7xHChqulXKQ5lCXOppeLPU3yLL9fGQB6x2PMxQfRw-99iEYd__c-GKFoJxOK8Yg2rjHslnlK__jeIaqPlEQH27vzvXPz_BVm7NO5_87OnJKfdcd5R1lDUUoKb4Q3KHlaMm0qfq0KgpFs2WFeVpb7mj4FYXKLQmlQfxldA3mEgfe4RBaEq4MpaftJi5PNtJU8w"'
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
+24
-20
@@ -2,28 +2,32 @@ import { writable, get, type Readable, derived } from 'svelte/store';
|
|||||||
import { persist, localStorage } from './persist';
|
import { persist, localStorage } from './persist';
|
||||||
import { saveStatistics, countLines } from './stats';
|
import { saveStatistics, countLines } from './stats';
|
||||||
import { serializeState, deserializeState } from './serde';
|
import { serializeState, deserializeState } from './serde';
|
||||||
import { cmdKey, errorDebug, formatJSON } from './util';
|
import { cmdKey, errorDebug } from './util';
|
||||||
import { parse } from './mermaid';
|
import { parse } from './mermaid';
|
||||||
|
|
||||||
import type { ErrorHash, MarkerData, State, ValidatedState } from '$lib/types';
|
import type { ErrorHash, MarkerData, State, ValidatedState } from '$lib/types';
|
||||||
import type { MermaidConfig } from 'mermaid';
|
import type { MermaidConfig } from 'mermaid';
|
||||||
|
|
||||||
export const defaultState: State = {
|
export const defaultState: State = {
|
||||||
code: `flowchart TD
|
code: `graph TD
|
||||||
A[Christmas] -->|Get money| B(Go shopping)
|
A[Christmas] -->|Get money| B(Go shopping)
|
||||||
B --> C{Let me think}
|
B --> C{Let me think}
|
||||||
C -->|One| D[Laptop]
|
C -->|One| D[Laptop]
|
||||||
C -->|Two| E[iPhone]
|
C -->|Two| E[iPhone]
|
||||||
C -->|Three| F[fa:fa-car Car]
|
C -->|Three| F[fa:fa-car Car]
|
||||||
`,
|
`,
|
||||||
mermaid: formatJSON({
|
mermaid: JSON.stringify(
|
||||||
theme: 'default'
|
{
|
||||||
}),
|
theme: 'default'
|
||||||
|
},
|
||||||
|
null,
|
||||||
|
2
|
||||||
|
),
|
||||||
autoSync: true,
|
autoSync: true,
|
||||||
updateDiagram: true
|
updateDiagram: true
|
||||||
};
|
};
|
||||||
|
|
||||||
const urlParseFailedState = `flowchart TD
|
const urlParseFailedState = `graph 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.)
|
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?}
|
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.)
|
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.)
|
||||||
@@ -61,16 +65,16 @@ const processState = async (state: State) => {
|
|||||||
processed.serialized = serializeState(state);
|
processed.serialized = serializeState(state);
|
||||||
await parse(state.code);
|
await parse(state.code);
|
||||||
JSON.parse(state.mermaid);
|
JSON.parse(state.mermaid);
|
||||||
} catch (error) {
|
} catch (e) {
|
||||||
processed.error = error as Error;
|
processed.error = e as Error;
|
||||||
errorDebug();
|
errorDebug();
|
||||||
console.error(error);
|
console.error(e);
|
||||||
if ('hash' in error) {
|
if ('hash' in e) {
|
||||||
try {
|
try {
|
||||||
const {
|
const {
|
||||||
loc: { first_line, last_line, first_column, last_column }
|
loc: { first_line, last_line, first_column, last_column }
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access
|
||||||
} = error.hash as ErrorHash;
|
} = e.hash as ErrorHash;
|
||||||
const marker: MarkerData = {
|
const marker: MarkerData = {
|
||||||
severity: 8, // Error
|
severity: 8, // Error
|
||||||
startLineNumber: first_line,
|
startLineNumber: first_line,
|
||||||
@@ -78,11 +82,11 @@ const processState = async (state: State) => {
|
|||||||
endLineNumber: last_line,
|
endLineNumber: last_line,
|
||||||
endColumn: last_column + 1,
|
endColumn: last_column + 1,
|
||||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment
|
// eslint-disable-next-line @typescript-eslint/no-unsafe-member-access, @typescript-eslint/no-unsafe-assignment
|
||||||
message: error.str
|
message: e.str
|
||||||
};
|
};
|
||||||
processed.errorMarkers = [marker];
|
processed.errorMarkers = [marker];
|
||||||
} catch (error) {
|
} catch (err) {
|
||||||
console.error('Error without line helper', error);
|
console.error('Error without line helper', err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -116,11 +120,11 @@ export const loadState = (data: string): void => {
|
|||||||
) {
|
) {
|
||||||
delete mermaidConfig.securityLevel; // Prevent setting overriding securityLevel when loading state to mitigate possible XSS attack
|
delete mermaidConfig.securityLevel; // Prevent setting overriding securityLevel when loading state to mitigate possible XSS attack
|
||||||
}
|
}
|
||||||
state.mermaid = formatJSON(mermaidConfig);
|
state.mermaid = JSON.stringify(mermaidConfig, null, 2);
|
||||||
} catch (error) {
|
} catch (e) {
|
||||||
state = get(inputStateStore);
|
state = get(inputStateStore);
|
||||||
if (data) {
|
if (data) {
|
||||||
console.error('Init error', error);
|
console.error('Init error', e);
|
||||||
state.code = urlParseFailedState;
|
state.code = urlParseFailedState;
|
||||||
state.mermaid = defaultState.mermaid;
|
state.mermaid = defaultState.mermaid;
|
||||||
}
|
}
|
||||||
@@ -142,7 +146,7 @@ export const updateCode = (
|
|||||||
resetPanZoom = false
|
resetPanZoom = false
|
||||||
}: { updateDiagram?: boolean; resetPanZoom?: boolean } = {}
|
}: { updateDiagram?: boolean; resetPanZoom?: boolean } = {}
|
||||||
): void => {
|
): void => {
|
||||||
// console.log('updateCode', code);
|
console.log('updateCode', code);
|
||||||
const lines = countLines(code);
|
const lines = countLines(code);
|
||||||
saveStatistics(code);
|
saveStatistics(code);
|
||||||
errorDebug();
|
errorDebug();
|
||||||
@@ -168,7 +172,7 @@ export const updateCode = (
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const updateConfig = (config: string): void => {
|
export const updateConfig = (config: string): void => {
|
||||||
// console.log('updateConfig', config);
|
console.log('updateConfig', config);
|
||||||
inputStateStore.update((state) => {
|
inputStateStore.update((state) => {
|
||||||
return { ...state, mermaid: config };
|
return { ...state, mermaid: config };
|
||||||
});
|
});
|
||||||
@@ -181,7 +185,7 @@ export const toggleDarkTheme = (dark: boolean): void => {
|
|||||||
config.theme = dark ? 'dark' : 'default';
|
config.theme = dark ? 'dark' : 'default';
|
||||||
}
|
}
|
||||||
|
|
||||||
return { ...state, mermaid: formatJSON(config) };
|
return { ...state, mermaid: JSON.stringify(config, null, 2) };
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
+9
-31
@@ -15,13 +15,13 @@ export const initAnalytics = async (): Promise<void> => {
|
|||||||
plausible({
|
plausible({
|
||||||
domain: 'mermaid.live',
|
domain: 'mermaid.live',
|
||||||
hashMode: false,
|
hashMode: false,
|
||||||
// All tracked stats are public and available at https://p.mermaid.live/mermaid.live
|
trackLocalhost: false, // By default 'false'
|
||||||
apiHost: 'https://p.mermaid.live'
|
apiHost: 'https://plausible.io'
|
||||||
})
|
})
|
||||||
]
|
]
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (e) {
|
||||||
console.log(error);
|
console.log(e);
|
||||||
console.info('Analytics blocked ;)');
|
console.info('Analytics blocked ;)');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -37,9 +37,7 @@ export const detectType = (text: string): string | undefined => {
|
|||||||
'graph',
|
'graph',
|
||||||
'journey',
|
'journey',
|
||||||
'pie',
|
'pie',
|
||||||
'stateDiagram',
|
'stateDiagram'
|
||||||
'quadrantChart',
|
|
||||||
'mindmap'
|
|
||||||
];
|
];
|
||||||
const firstLine = text
|
const firstLine = text
|
||||||
.replace(/^\s*%%.*\n/g, '\n')
|
.replace(/^\s*%%.*\n/g, '\n')
|
||||||
@@ -60,27 +58,7 @@ export const saveStatistics = (graph: string): void => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const length = countLines(graph);
|
const length = countLines(graph);
|
||||||
const lengthBucket =
|
logEvent('render', { graphType, length });
|
||||||
length < 10
|
|
||||||
? '0-10'
|
|
||||||
: length < 25
|
|
||||||
? '10-25'
|
|
||||||
: length < 50
|
|
||||||
? '25-50'
|
|
||||||
: length < 100
|
|
||||||
? '50-100'
|
|
||||||
: length < 200
|
|
||||||
? '100-200'
|
|
||||||
: length < 500
|
|
||||||
? '200-500'
|
|
||||||
: length < 700
|
|
||||||
? '500-700'
|
|
||||||
: length < 1000
|
|
||||||
? '700-1000'
|
|
||||||
: length < 1500
|
|
||||||
? '1000-1500'
|
|
||||||
: '1500+';
|
|
||||||
logEvent('render', { graphType, length, lengthBucket });
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const minutesToMilliSeconds = (minutes: number): number => {
|
const minutesToMilliSeconds = (minutes: number): number => {
|
||||||
@@ -109,10 +87,10 @@ export const logEvent = (name: AnalyticsEvent, data?: unknown): void => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const key = data ? JSON.stringify({ name, data }) : name;
|
const key = data ? JSON.stringify({ name, data }) : name;
|
||||||
if (timeouts.has(key)) {
|
if (!timeouts.has(key)) {
|
||||||
clearTimeout(timeouts.get(key));
|
|
||||||
} else {
|
|
||||||
void analytics.track(name, data);
|
void analytics.track(name, data);
|
||||||
|
} else {
|
||||||
|
clearTimeout(timeouts.get(key));
|
||||||
}
|
}
|
||||||
timeouts.set(
|
timeouts.set(
|
||||||
key,
|
key,
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ export const themeStore: Writable<ThemeConfig> = persist(
|
|||||||
'themeStore'
|
'themeStore'
|
||||||
);
|
);
|
||||||
|
|
||||||
const darkThemes = new Set([
|
const darkThemes = [
|
||||||
'dark',
|
'dark',
|
||||||
'synthwave',
|
'synthwave',
|
||||||
'halloween',
|
'halloween',
|
||||||
@@ -25,13 +25,13 @@ const darkThemes = new Set([
|
|||||||
'luxury',
|
'luxury',
|
||||||
'black',
|
'black',
|
||||||
'dracula'
|
'dracula'
|
||||||
]);
|
];
|
||||||
|
|
||||||
export const setTheme = (theme: string): void => {
|
export const setTheme = (theme: string): void => {
|
||||||
if (theme.includes(' ')) {
|
if (theme.includes(' ')) {
|
||||||
theme = theme.split(' ')[1].trim();
|
theme = theme.split(' ')[1].trim();
|
||||||
}
|
}
|
||||||
const isDark = darkThemes.has(theme);
|
const isDark = darkThemes.includes(theme);
|
||||||
console.log('Setting theme', theme);
|
console.log('Setting theme', theme);
|
||||||
themeStore.set({ theme, isDark });
|
themeStore.set({ theme, isDark });
|
||||||
logEvent('themeChange', { theme, isDark });
|
logEvent('themeChange', { theme, isDark });
|
||||||
|
|||||||
+2
-10
@@ -3,6 +3,7 @@ import { analytics, initAnalytics } from './stats';
|
|||||||
import { loadDataFromUrl } from './fileLoaders/loader';
|
import { loadDataFromUrl } from './fileLoaders/loader';
|
||||||
import { initLoading } from './loading';
|
import { initLoading } from './loading';
|
||||||
import { applyMigrations } from './migrations';
|
import { applyMigrations } from './migrations';
|
||||||
|
import { init } from './mermaid';
|
||||||
|
|
||||||
export const loadStateFromURL = (): void => {
|
export const loadStateFromURL = (): void => {
|
||||||
loadState(window.location.hash.slice(1));
|
loadState(window.location.hash.slice(1));
|
||||||
@@ -16,6 +17,7 @@ export const syncDiagram = (): void => {
|
|||||||
|
|
||||||
export const initHandler = async (): Promise<void> => {
|
export const initHandler = async (): Promise<void> => {
|
||||||
applyMigrations();
|
applyMigrations();
|
||||||
|
await initLoading('Loading Mermaid...', init());
|
||||||
loadStateFromURL();
|
loadStateFromURL();
|
||||||
await initLoading('Loading Gist...', loadDataFromUrl().catch(console.error));
|
await initLoading('Loading Gist...', loadDataFromUrl().catch(console.error));
|
||||||
syncDiagram();
|
syncDiagram();
|
||||||
@@ -36,13 +38,3 @@ export const errorDebug = (limit = 100) => {
|
|||||||
debugger;
|
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();
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -9,66 +9,56 @@
|
|||||||
import { inputStateStore, stateStore, updateCodeStore } from '$lib/util/state';
|
import { inputStateStore, stateStore, updateCodeStore } from '$lib/util/state';
|
||||||
import { cmdKey, initHandler, syncDiagram } from '$lib/util/util';
|
import { cmdKey, initHandler, syncDiagram } from '$lib/util/util';
|
||||||
import { onMount } from 'svelte';
|
import { onMount } from 'svelte';
|
||||||
|
import type { Tab, DocConfig, EditorMode, ValidatedState } from '$lib/types';
|
||||||
import { base } from '$app/paths';
|
import { base } from '$app/paths';
|
||||||
import { dev } from '$app/environment';
|
|
||||||
import type { Tab, DocumentationConfig, EditorMode, ValidatedState } from '$lib/types';
|
|
||||||
|
|
||||||
const MCBaseURL = dev ? 'http://localhost:5174' : 'https://mermaidchart.com';
|
|
||||||
const docURLBase = 'https://mermaid-js.github.io/mermaid';
|
const docURLBase = 'https://mermaid-js.github.io/mermaid';
|
||||||
const docMap: DocumentationConfig = {
|
const docMap: DocConfig = {
|
||||||
classDiagram: {
|
graph: {
|
||||||
code: '/syntax/classDiagram',
|
code: '/#/flowchart',
|
||||||
config: '/syntax/classDiagram#configuration'
|
config: '/#/flowchart?id=configuration'
|
||||||
},
|
|
||||||
erDiagram: {
|
|
||||||
code: '/syntax/entityRelationshipDiagram'
|
|
||||||
},
|
},
|
||||||
flowchart: {
|
flowchart: {
|
||||||
code: '/syntax/flowchart',
|
code: '/#/flowchart',
|
||||||
config: '/syntax/flowchart#configuration'
|
config: '/#/flowchart?id=configuration'
|
||||||
},
|
|
||||||
gantt: {
|
|
||||||
code: '/syntax/gantt',
|
|
||||||
config: '/syntax/gantt#configuration'
|
|
||||||
},
|
|
||||||
gitGraph: {
|
|
||||||
code: '/syntax/gitgraph',
|
|
||||||
config: '/syntax/gitgraph#gitgraph-specific-configuration-options'
|
|
||||||
},
|
|
||||||
graph: {
|
|
||||||
code: '/syntax/flowchart',
|
|
||||||
config: '/syntax/flowchart#configuration'
|
|
||||||
},
|
|
||||||
journey: {
|
|
||||||
code: '/syntax/userJourney'
|
|
||||||
},
|
|
||||||
mindmap: {
|
|
||||||
code: '/syntax/mindmap'
|
|
||||||
},
|
|
||||||
pie: {
|
|
||||||
code: '/syntax/pie',
|
|
||||||
config: '/syntax/pie#configuration'
|
|
||||||
},
|
|
||||||
quadrantChart: {
|
|
||||||
code: '/syntax/quadrantChart',
|
|
||||||
config: '/syntax/quadrantChart#chart-configurations'
|
|
||||||
},
|
},
|
||||||
sequenceDiagram: {
|
sequenceDiagram: {
|
||||||
code: '/syntax/sequenceDiagram',
|
code: '/#/sequenceDiagram',
|
||||||
config: '/syntax/sequenceDiagram#configuration'
|
config: '/#/sequenceDiagram?id=configuration'
|
||||||
|
},
|
||||||
|
classDiagram: {
|
||||||
|
code: '/#/classDiagram',
|
||||||
|
config: '/#/classDiagram?id=configuration'
|
||||||
},
|
},
|
||||||
'stateDiagram-v2': {
|
'stateDiagram-v2': {
|
||||||
code: '/syntax/stateDiagram'
|
code: '/#/stateDiagram'
|
||||||
|
},
|
||||||
|
gantt: {
|
||||||
|
code: '/#/gantt',
|
||||||
|
config: '/#/gantt?id=configuration'
|
||||||
|
},
|
||||||
|
pie: {
|
||||||
|
code: '/#/pie'
|
||||||
|
},
|
||||||
|
erDiagram: {
|
||||||
|
code: '/#/entityRelationshipDiagram',
|
||||||
|
config: '/#/entityRelationshipDiagram?id=styling'
|
||||||
|
},
|
||||||
|
journey: {
|
||||||
|
code: '/#/user-journey'
|
||||||
|
},
|
||||||
|
gitGraph: {
|
||||||
|
code: '/#/gitgraph',
|
||||||
|
config: '/#/gitgraph?id=gitgraph-specific-configuration-options'
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
let docURL = docURLBase;
|
let docURL = docURLBase;
|
||||||
let activeTabID = 'code';
|
let activeTabID = 'code';
|
||||||
let docKey = '';
|
|
||||||
stateStore.subscribe(({ code, editorMode }: ValidatedState) => {
|
stateStore.subscribe(({ code, editorMode }: ValidatedState) => {
|
||||||
activeTabID = editorMode;
|
activeTabID = editorMode;
|
||||||
const codeTypeMatch = /([\S]+)[\s\n]/.exec(code);
|
const codeTypeMatch = /([\S]+)[\s\n]/.exec(code);
|
||||||
if (codeTypeMatch && codeTypeMatch.length > 1) {
|
if (codeTypeMatch && codeTypeMatch.length > 1) {
|
||||||
docKey = codeTypeMatch[1];
|
const docKey = codeTypeMatch[1];
|
||||||
const docConfig = docMap[docKey] ?? { code: '' };
|
const docConfig = docMap[docKey] ?? { code: '' };
|
||||||
docURL = docURLBase + (docConfig[editorMode] ?? docConfig.code ?? '');
|
docURL = docURLBase + (docConfig[editorMode] ?? docConfig.code ?? '');
|
||||||
}
|
}
|
||||||
@@ -143,10 +133,8 @@
|
|||||||
on:click={syncDiagram}><i class="fas fa-sync" /></button>
|
on:click={syncDiagram}><i class="fas fa-sync" /></button>
|
||||||
{/if}
|
{/if}
|
||||||
|
|
||||||
<button
|
<button class="btn btn-secondary btn-xs" title="View documentation">
|
||||||
class="btn btn-secondary btn-xs"
|
<a target="_blank" rel="noreferrer" href={docURL} data-cy="docs">
|
||||||
title="View documentation for {docKey.replace('Diagram', '')} diagram">
|
|
||||||
<a target="_blank" href={docURL} data-cy="docs">
|
|
||||||
<i class="fas fa-book mr-1" />Docs
|
<i class="fas fa-book mr-1" />Docs
|
||||||
</a>
|
</a>
|
||||||
</button>
|
</button>
|
||||||
@@ -164,27 +152,22 @@
|
|||||||
<div id="resizeHandler" class="hidden md:block" />
|
<div id="resizeHandler" class="hidden md:block" />
|
||||||
<div class="flex-1 flex flex-col overflow-hidden">
|
<div class="flex-1 flex flex-col overflow-hidden">
|
||||||
<Card title="Diagram" isCloseable={false}>
|
<Card title="Diagram" isCloseable={false}>
|
||||||
<div slot="actions" class="flex flex-row items-center gap-2">
|
<div slot="actions" class="flex flex-row items-center">
|
||||||
<label class="cursor-pointer label py-0" for="panZoom">
|
<label class="cursor-pointer label py-0" for="panZoom">
|
||||||
<span>Pan & Zoom</span>
|
<span>Pan & Zoom</span>
|
||||||
<input
|
<input
|
||||||
type="checkbox"
|
type="checkbox"
|
||||||
class="toggle {$stateStore.panZoom ? 'btn-secondary' : 'toggle-primary'}"
|
class="toggle {$stateStore.panZoom ? 'btn-secondary' : 'toggle-primary'} ml-1"
|
||||||
id="panZoom"
|
id="panZoom"
|
||||||
bind:checked={$inputStateStore.panZoom} />
|
bind:checked={$inputStateStore.panZoom} />
|
||||||
</label>
|
</label>
|
||||||
<a
|
<a
|
||||||
href={`${base}/view#${$stateStore.serialized}`}
|
href={`${base}/view#${$stateStore.serialized}`}
|
||||||
target="_blank"
|
target="_blank"
|
||||||
class="btn btn-secondary btn-xs gap-1"
|
rel="noreferrer"
|
||||||
title="View diagram in new page"><i class="fas fa-external-link-alt" />Full screen</a>
|
class="btn btn-secondary btn-xs"
|
||||||
<a
|
title="View diagram in new page"
|
||||||
href={`${MCBaseURL}/app/plugin/save?state=${$stateStore.serialized}`}
|
><i class="fas fa-external-link-alt mr-1" />Full screen</a>
|
||||||
target="_blank"
|
|
||||||
class="btn btn-secondary btn-xs gap-1 bg-[#FF3570]"
|
|
||||||
title="Save diagram in Mermaid Chart"
|
|
||||||
><img src="/mermaidchart-logo.svg" class="w-5 h-5" alt="Mermaid chart logo" />Save to
|
|
||||||
Mermaid Chart</a>
|
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex-1 overflow-auto">
|
<div class="flex-1 overflow-auto">
|
||||||
|
|||||||
@@ -1 +0,0 @@
|
|||||||
<svg id="Layer_1" data-name="Layer 1" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 490.16 490.16"><defs><style>.cls-1{fill:#ff3670;}.cls-2{fill:#fff;}</style></defs><rect class="cls-1" width="490.16" height="490.16" rx="84.61"/><path class="cls-2" d="M407.48,111.18A165.2,165.2,0,0,0,245.08,220,165.2,165.2,0,0,0,82.68,111.18a165.5,165.5,0,0,0,72.06,143.64,88.81,88.81,0,0,1,38.53,73.45v50.86H296.9V328.27a88.8,88.8,0,0,1,38.52-73.45,165.41,165.41,0,0,0,72.06-143.64Z"/><path class="cls-2" d="M160.63,328.27a56.09,56.09,0,0,0-24.27-46.49,198.74,198.74,0,0,1-28.54-23.66A196.87,196.87,0,0,1,82.53,227V379.13h78.1Z"/><path class="cls-2" d="M329.53,328.27a56.09,56.09,0,0,1,24.27-46.49,198.74,198.74,0,0,0,28.54-23.66A196.87,196.87,0,0,0,407.63,227V379.13h-78.1Z"/></svg>
|
|
||||||
|
Before Width: | Height: | Size: 772 B |
@@ -0,0 +1,398 @@
|
|||||||
|
import { test, expect, type Page } from '@playwright/test';
|
||||||
|
|
||||||
|
test.beforeEach(async ({ page }) => {
|
||||||
|
await page.goto('https://demo.playwright.dev/todomvc');
|
||||||
|
});
|
||||||
|
|
||||||
|
const TODO_ITEMS = [
|
||||||
|
'buy some cheese',
|
||||||
|
'feed the cat',
|
||||||
|
'book a doctors appointment'
|
||||||
|
];
|
||||||
|
|
||||||
|
test.describe('New Todo', () => {
|
||||||
|
test('should allow me to add todo items', async ({ page }) => {
|
||||||
|
// Create 1st todo.
|
||||||
|
await page.locator('.new-todo').fill(TODO_ITEMS[0]);
|
||||||
|
await page.locator('.new-todo').press('Enter');
|
||||||
|
|
||||||
|
// Make sure the list only has one todo item.
|
||||||
|
await expect(page.locator('.view label')).toHaveText([
|
||||||
|
TODO_ITEMS[0]
|
||||||
|
]);
|
||||||
|
|
||||||
|
// Create 2nd todo.
|
||||||
|
await page.locator('.new-todo').fill(TODO_ITEMS[1]);
|
||||||
|
await page.locator('.new-todo').press('Enter');
|
||||||
|
|
||||||
|
// Make sure the list now has two todo items.
|
||||||
|
await expect(page.locator('.view label')).toHaveText([
|
||||||
|
TODO_ITEMS[0],
|
||||||
|
TODO_ITEMS[1]
|
||||||
|
]);
|
||||||
|
|
||||||
|
await checkNumberOfTodosInLocalStorage(page, 2);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should clear text input field when an item is added', async ({ page }) => {
|
||||||
|
// Create one todo item.
|
||||||
|
await page.locator('.new-todo').fill(TODO_ITEMS[0]);
|
||||||
|
await page.locator('.new-todo').press('Enter');
|
||||||
|
|
||||||
|
// Check that input is empty.
|
||||||
|
await expect(page.locator('.new-todo')).toBeEmpty();
|
||||||
|
await checkNumberOfTodosInLocalStorage(page, 1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should append new items to the bottom of the list', async ({ page }) => {
|
||||||
|
// Create 3 items.
|
||||||
|
await createDefaultTodos(page);
|
||||||
|
|
||||||
|
// Check test using different methods.
|
||||||
|
await expect(page.locator('.todo-count')).toHaveText('3 items left');
|
||||||
|
await expect(page.locator('.todo-count')).toContainText('3');
|
||||||
|
await expect(page.locator('.todo-count')).toHaveText(/3/);
|
||||||
|
|
||||||
|
// Check all items in one call.
|
||||||
|
await expect(page.locator('.view label')).toHaveText(TODO_ITEMS);
|
||||||
|
await checkNumberOfTodosInLocalStorage(page, 3);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should show #main and #footer when items added', async ({ page }) => {
|
||||||
|
await page.locator('.new-todo').fill(TODO_ITEMS[0]);
|
||||||
|
await page.locator('.new-todo').press('Enter');
|
||||||
|
|
||||||
|
await expect(page.locator('.main')).toBeVisible();
|
||||||
|
await expect(page.locator('.footer')).toBeVisible();
|
||||||
|
await checkNumberOfTodosInLocalStorage(page, 1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test.describe('Mark all as completed', () => {
|
||||||
|
test.beforeEach(async ({ page }) => {
|
||||||
|
await createDefaultTodos(page);
|
||||||
|
await checkNumberOfTodosInLocalStorage(page, 3);
|
||||||
|
});
|
||||||
|
|
||||||
|
test.afterEach(async ({ page }) => {
|
||||||
|
await checkNumberOfTodosInLocalStorage(page, 3);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should allow me to mark all items as completed', async ({ page }) => {
|
||||||
|
// Complete all todos.
|
||||||
|
await page.locator('.toggle-all').check();
|
||||||
|
|
||||||
|
// Ensure all todos have 'completed' class.
|
||||||
|
await expect(page.locator('.todo-list li')).toHaveClass(['completed', 'completed', 'completed']);
|
||||||
|
await checkNumberOfCompletedTodosInLocalStorage(page, 3);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should allow me to clear the complete state of all items', async ({ page }) => {
|
||||||
|
// Check and then immediately uncheck.
|
||||||
|
await page.locator('.toggle-all').check();
|
||||||
|
await page.locator('.toggle-all').uncheck();
|
||||||
|
|
||||||
|
// Should be no completed classes.
|
||||||
|
await expect(page.locator('.todo-list li')).toHaveClass(['', '', '']);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('complete all checkbox should update state when items are completed / cleared', async ({ page }) => {
|
||||||
|
const toggleAll = page.locator('.toggle-all');
|
||||||
|
await toggleAll.check();
|
||||||
|
await expect(toggleAll).toBeChecked();
|
||||||
|
await checkNumberOfCompletedTodosInLocalStorage(page, 3);
|
||||||
|
|
||||||
|
// Uncheck first todo.
|
||||||
|
const firstTodo = page.locator('.todo-list li').nth(0);
|
||||||
|
await firstTodo.locator('.toggle').uncheck();
|
||||||
|
|
||||||
|
// Reuse toggleAll locator and make sure its not checked.
|
||||||
|
await expect(toggleAll).not.toBeChecked();
|
||||||
|
|
||||||
|
await firstTodo.locator('.toggle').check();
|
||||||
|
await checkNumberOfCompletedTodosInLocalStorage(page, 3);
|
||||||
|
|
||||||
|
// Assert the toggle all is checked again.
|
||||||
|
await expect(toggleAll).toBeChecked();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test.describe('Item', () => {
|
||||||
|
|
||||||
|
test('should allow me to mark items as complete', async ({ page }) => {
|
||||||
|
// Create two items.
|
||||||
|
for (const item of TODO_ITEMS.slice(0, 2)) {
|
||||||
|
await page.locator('.new-todo').fill(item);
|
||||||
|
await page.locator('.new-todo').press('Enter');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check first item.
|
||||||
|
const firstTodo = page.locator('.todo-list li').nth(0);
|
||||||
|
await firstTodo.locator('.toggle').check();
|
||||||
|
await expect(firstTodo).toHaveClass('completed');
|
||||||
|
|
||||||
|
// Check second item.
|
||||||
|
const secondTodo = page.locator('.todo-list li').nth(1);
|
||||||
|
await expect(secondTodo).not.toHaveClass('completed');
|
||||||
|
await secondTodo.locator('.toggle').check();
|
||||||
|
|
||||||
|
// Assert completed class.
|
||||||
|
await expect(firstTodo).toHaveClass('completed');
|
||||||
|
await expect(secondTodo).toHaveClass('completed');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should allow me to un-mark items as complete', async ({ page }) => {
|
||||||
|
// Create two items.
|
||||||
|
for (const item of TODO_ITEMS.slice(0, 2)) {
|
||||||
|
await page.locator('.new-todo').fill(item);
|
||||||
|
await page.locator('.new-todo').press('Enter');
|
||||||
|
}
|
||||||
|
|
||||||
|
const firstTodo = page.locator('.todo-list li').nth(0);
|
||||||
|
const secondTodo = page.locator('.todo-list li').nth(1);
|
||||||
|
await firstTodo.locator('.toggle').check();
|
||||||
|
await expect(firstTodo).toHaveClass('completed');
|
||||||
|
await expect(secondTodo).not.toHaveClass('completed');
|
||||||
|
await checkNumberOfCompletedTodosInLocalStorage(page, 1);
|
||||||
|
|
||||||
|
await firstTodo.locator('.toggle').uncheck();
|
||||||
|
await expect(firstTodo).not.toHaveClass('completed');
|
||||||
|
await expect(secondTodo).not.toHaveClass('completed');
|
||||||
|
await checkNumberOfCompletedTodosInLocalStorage(page, 0);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should allow me to edit an item', async ({ page }) => {
|
||||||
|
await createDefaultTodos(page);
|
||||||
|
|
||||||
|
const todoItems = page.locator('.todo-list li');
|
||||||
|
const secondTodo = todoItems.nth(1);
|
||||||
|
await secondTodo.dblclick();
|
||||||
|
await expect(secondTodo.locator('.edit')).toHaveValue(TODO_ITEMS[1]);
|
||||||
|
await secondTodo.locator('.edit').fill('buy some sausages');
|
||||||
|
await secondTodo.locator('.edit').press('Enter');
|
||||||
|
|
||||||
|
// Explicitly assert the new text value.
|
||||||
|
await expect(todoItems).toHaveText([
|
||||||
|
TODO_ITEMS[0],
|
||||||
|
'buy some sausages',
|
||||||
|
TODO_ITEMS[2]
|
||||||
|
]);
|
||||||
|
await checkTodosInLocalStorage(page, 'buy some sausages');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test.describe('Editing', () => {
|
||||||
|
test.beforeEach(async ({ page }) => {
|
||||||
|
await createDefaultTodos(page);
|
||||||
|
await checkNumberOfTodosInLocalStorage(page, 3);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should hide other controls when editing', async ({ page }) => {
|
||||||
|
const todoItem = page.locator('.todo-list li').nth(1);
|
||||||
|
await todoItem.dblclick();
|
||||||
|
await expect(todoItem.locator('.toggle')).not.toBeVisible();
|
||||||
|
await expect(todoItem.locator('label')).not.toBeVisible();
|
||||||
|
await checkNumberOfTodosInLocalStorage(page, 3);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should save edits on blur', async ({ page }) => {
|
||||||
|
const todoItems = page.locator('.todo-list li');
|
||||||
|
await todoItems.nth(1).dblclick();
|
||||||
|
await todoItems.nth(1).locator('.edit').fill('buy some sausages');
|
||||||
|
await todoItems.nth(1).locator('.edit').dispatchEvent('blur');
|
||||||
|
|
||||||
|
await expect(todoItems).toHaveText([
|
||||||
|
TODO_ITEMS[0],
|
||||||
|
'buy some sausages',
|
||||||
|
TODO_ITEMS[2],
|
||||||
|
]);
|
||||||
|
await checkTodosInLocalStorage(page, 'buy some sausages');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should trim entered text', async ({ page }) => {
|
||||||
|
const todoItems = page.locator('.todo-list li');
|
||||||
|
await todoItems.nth(1).dblclick();
|
||||||
|
await todoItems.nth(1).locator('.edit').fill(' buy some sausages ');
|
||||||
|
await todoItems.nth(1).locator('.edit').press('Enter');
|
||||||
|
|
||||||
|
await expect(todoItems).toHaveText([
|
||||||
|
TODO_ITEMS[0],
|
||||||
|
'buy some sausages',
|
||||||
|
TODO_ITEMS[2],
|
||||||
|
]);
|
||||||
|
await checkTodosInLocalStorage(page, 'buy some sausages');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should remove the item if an empty text string was entered', async ({ page }) => {
|
||||||
|
const todoItems = page.locator('.todo-list li');
|
||||||
|
await todoItems.nth(1).dblclick();
|
||||||
|
await todoItems.nth(1).locator('.edit').fill('');
|
||||||
|
await todoItems.nth(1).locator('.edit').press('Enter');
|
||||||
|
|
||||||
|
await expect(todoItems).toHaveText([
|
||||||
|
TODO_ITEMS[0],
|
||||||
|
TODO_ITEMS[2],
|
||||||
|
]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should cancel edits on escape', async ({ page }) => {
|
||||||
|
const todoItems = page.locator('.todo-list li');
|
||||||
|
await todoItems.nth(1).dblclick();
|
||||||
|
await todoItems.nth(1).locator('.edit').press('Escape');
|
||||||
|
await expect(todoItems).toHaveText(TODO_ITEMS);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test.describe('Counter', () => {
|
||||||
|
test('should display the current number of todo items', async ({ page }) => {
|
||||||
|
await page.locator('.new-todo').fill(TODO_ITEMS[0]);
|
||||||
|
await page.locator('.new-todo').press('Enter');
|
||||||
|
await expect(page.locator('.todo-count')).toContainText('1');
|
||||||
|
|
||||||
|
await page.locator('.new-todo').fill(TODO_ITEMS[1]);
|
||||||
|
await page.locator('.new-todo').press('Enter');
|
||||||
|
await expect(page.locator('.todo-count')).toContainText('2');
|
||||||
|
|
||||||
|
await checkNumberOfTodosInLocalStorage(page, 2);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test.describe('Clear completed button', () => {
|
||||||
|
test.beforeEach(async ({ page }) => {
|
||||||
|
await createDefaultTodos(page);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should display the correct text', async ({ page }) => {
|
||||||
|
await page.locator('.todo-list li .toggle').first().check();
|
||||||
|
await expect(page.locator('.clear-completed')).toHaveText('Clear completed');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should remove completed items when clicked', async ({ page }) => {
|
||||||
|
const todoItems = page.locator('.todo-list li');
|
||||||
|
await todoItems.nth(1).locator('.toggle').check();
|
||||||
|
await page.locator('.clear-completed').click();
|
||||||
|
await expect(todoItems).toHaveCount(2);
|
||||||
|
await expect(todoItems).toHaveText([TODO_ITEMS[0], TODO_ITEMS[2]]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should be hidden when there are no items that are completed', async ({ page }) => {
|
||||||
|
await page.locator('.todo-list li .toggle').first().check();
|
||||||
|
await page.locator('.clear-completed').click();
|
||||||
|
await expect(page.locator('.clear-completed')).toBeHidden();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test.describe('Persistence', () => {
|
||||||
|
test('should persist its data', async ({ page }) => {
|
||||||
|
for (const item of TODO_ITEMS.slice(0, 2)) {
|
||||||
|
await page.locator('.new-todo').fill(item);
|
||||||
|
await page.locator('.new-todo').press('Enter');
|
||||||
|
}
|
||||||
|
|
||||||
|
const todoItems = page.locator('.todo-list li');
|
||||||
|
await todoItems.nth(0).locator('.toggle').check();
|
||||||
|
await expect(todoItems).toHaveText([TODO_ITEMS[0], TODO_ITEMS[1]]);
|
||||||
|
await expect(todoItems).toHaveClass(['completed', '']);
|
||||||
|
|
||||||
|
// Ensure there is 1 completed item.
|
||||||
|
checkNumberOfCompletedTodosInLocalStorage(page, 1);
|
||||||
|
|
||||||
|
// Now reload.
|
||||||
|
await page.reload();
|
||||||
|
await expect(todoItems).toHaveText([TODO_ITEMS[0], TODO_ITEMS[1]]);
|
||||||
|
await expect(todoItems).toHaveClass(['completed', '']);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
test.describe('Routing', () => {
|
||||||
|
test.beforeEach(async ({ page }) => {
|
||||||
|
await createDefaultTodos(page);
|
||||||
|
// make sure the app had a chance to save updated todos in storage
|
||||||
|
// before navigating to a new view, otherwise the items can get lost :(
|
||||||
|
// in some frameworks like Durandal
|
||||||
|
await checkTodosInLocalStorage(page, TODO_ITEMS[0]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should allow me to display active items', async ({ page }) => {
|
||||||
|
await page.locator('.todo-list li .toggle').nth(1).check();
|
||||||
|
await checkNumberOfCompletedTodosInLocalStorage(page, 1);
|
||||||
|
await page.locator('.filters >> text=Active').click();
|
||||||
|
await expect(page.locator('.todo-list li')).toHaveCount(2);
|
||||||
|
await expect(page.locator('.todo-list li')).toHaveText([TODO_ITEMS[0], TODO_ITEMS[2]]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should respect the back button', async ({ page }) => {
|
||||||
|
await page.locator('.todo-list li .toggle').nth(1).check();
|
||||||
|
await checkNumberOfCompletedTodosInLocalStorage(page, 1);
|
||||||
|
|
||||||
|
await test.step('Showing all items', async () => {
|
||||||
|
await page.locator('.filters >> text=All').click();
|
||||||
|
await expect(page.locator('.todo-list li')).toHaveCount(3);
|
||||||
|
});
|
||||||
|
|
||||||
|
await test.step('Showing active items', async () => {
|
||||||
|
await page.locator('.filters >> text=Active').click();
|
||||||
|
});
|
||||||
|
|
||||||
|
await test.step('Showing completed items', async () => {
|
||||||
|
await page.locator('.filters >> text=Completed').click();
|
||||||
|
});
|
||||||
|
|
||||||
|
await expect(page.locator('.todo-list li')).toHaveCount(1);
|
||||||
|
await page.goBack();
|
||||||
|
await expect(page.locator('.todo-list li')).toHaveCount(2);
|
||||||
|
await page.goBack();
|
||||||
|
await expect(page.locator('.todo-list li')).toHaveCount(3);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should allow me to display completed items', async ({ page }) => {
|
||||||
|
await page.locator('.todo-list li .toggle').nth(1).check();
|
||||||
|
await checkNumberOfCompletedTodosInLocalStorage(page, 1);
|
||||||
|
await page.locator('.filters >> text=Completed').click();
|
||||||
|
await expect(page.locator('.todo-list li')).toHaveCount(1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should allow me to display all items', async ({ page }) => {
|
||||||
|
await page.locator('.todo-list li .toggle').nth(1).check();
|
||||||
|
await checkNumberOfCompletedTodosInLocalStorage(page, 1);
|
||||||
|
await page.locator('.filters >> text=Active').click();
|
||||||
|
await page.locator('.filters >> text=Completed').click();
|
||||||
|
await page.locator('.filters >> text=All').click();
|
||||||
|
await expect(page.locator('.todo-list li')).toHaveCount(3);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should highlight the currently applied filter', async ({ page }) => {
|
||||||
|
await expect(page.locator('.filters >> text=All')).toHaveClass('selected');
|
||||||
|
await page.locator('.filters >> text=Active').click();
|
||||||
|
// Page change - active items.
|
||||||
|
await expect(page.locator('.filters >> text=Active')).toHaveClass('selected');
|
||||||
|
await page.locator('.filters >> text=Completed').click();
|
||||||
|
// Page change - completed items.
|
||||||
|
await expect(page.locator('.filters >> text=Completed')).toHaveClass('selected');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
async function createDefaultTodos(page: Page) {
|
||||||
|
for (const item of TODO_ITEMS) {
|
||||||
|
await page.locator('.new-todo').fill(item);
|
||||||
|
await page.locator('.new-todo').press('Enter');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
async function checkNumberOfTodosInLocalStorage(page: Page, expected: number) {
|
||||||
|
return await page.waitForFunction(e => {
|
||||||
|
return JSON.parse(localStorage['react-todos']).length === e;
|
||||||
|
}, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function checkNumberOfCompletedTodosInLocalStorage(page: Page, expected: number) {
|
||||||
|
return await page.waitForFunction(e => {
|
||||||
|
return JSON.parse(localStorage['react-todos']).filter((todo: any) => todo.completed).length === e;
|
||||||
|
}, expected);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function checkTodosInLocalStorage(page: Page, title: string) {
|
||||||
|
return await page.waitForFunction(t => {
|
||||||
|
return JSON.parse(localStorage['react-todos']).map((todo: any) => todo.title).includes(t);
|
||||||
|
}, title);
|
||||||
|
}
|
||||||
@@ -0,0 +1,179 @@
|
|||||||
|
import { toBase64 } from 'js-base64';
|
||||||
|
|
||||||
|
// describe('Site Loads', () => {
|
||||||
|
// beforeEach(() => {
|
||||||
|
// cy.clearLocalStorage();
|
||||||
|
// cy.visit('/');
|
||||||
|
// });
|
||||||
|
|
||||||
|
// it('Check Home page load', () => {
|
||||||
|
// cy.url().should('include', '/edit');
|
||||||
|
// cy.contains('History').click();
|
||||||
|
// cy.getLocalStorage('codeStore').snapshot();
|
||||||
|
// });
|
||||||
|
|
||||||
|
// it('Check Redirect from old URL', () => {
|
||||||
|
// cy.visit(
|
||||||
|
// '/#/edit/eyJjb2RlIjoiZ3JhcGggVERcbiAgICBBW0NocmlzdG1hc10gLS0-fEdldCBtb25leXwgQihHbyBzaG9wcGluZylcbiAgICBCIC0tPiBDe0xldCBtZSB0aGlua31cbiAgICBDIC0tPnxPbmV8IERbTGFwdG9wXVxuICAgIEMgLS0-fFR3b3wgRVtpUGhvbmVdXG4gICAgQyAtLT58VGhyZWV8IEZbZmE6ZmEtY2FyIENhcl0iLCJtZXJtYWlkIjp7InRoZW1lIjoiZGVmYXVsdCJ9LCJ1cGRhdGVFZGl0b3IiOmZhbHNlfQ'
|
||||||
|
// );
|
||||||
|
// cy.url().should('include', '/edit#pako:eNp');
|
||||||
|
// });
|
||||||
|
|
||||||
|
// it('should load sample diagrams when clicked', () => {
|
||||||
|
// cy.contains('Sample Diagrams').click();
|
||||||
|
// cy.contains('Pie').click();
|
||||||
|
// cy.contains('pie title Pets adopted by volunteers');
|
||||||
|
// cy.contains('Class').click();
|
||||||
|
// cy.contains('classDiagram');
|
||||||
|
// });
|
||||||
|
|
||||||
|
// (Cypress.env('CI') === 'true' ? describe : describe.skip)('github', () => {
|
||||||
|
// it('should load diagram from gist', () => {
|
||||||
|
// cy.visit(`/edit?gist=https://gist.github.com/sidharthv96/6268a23e673a533dcb198f241fd7012a`);
|
||||||
|
// cy.contains('History').click();
|
||||||
|
// cy.contains('Go shopping!!');
|
||||||
|
// cy.contains('Revisions');
|
||||||
|
// cy.contains('sidharthv96 v8f8f1e2');
|
||||||
|
// cy.contains('sidharthv96 v7851e19');
|
||||||
|
// cy.getLocalStorage('codeStore').snapshot();
|
||||||
|
// });
|
||||||
|
|
||||||
|
// it('should load diagram from gist revision', () => {
|
||||||
|
// cy.visit(
|
||||||
|
// '/edit?gist=https://gist.github.com/sidharthv96/6268a23e673a533dcb198f241fd7012a/ec9b4ab0e41e4ff6287326cd3cb47affd7851e19'
|
||||||
|
// );
|
||||||
|
// cy.contains('History').click();
|
||||||
|
// cy.contains('Party');
|
||||||
|
// cy.contains('Revisions');
|
||||||
|
// cy.contains('sidharthv96 v7851e19');
|
||||||
|
// cy.getLocalStorage('codeStore').snapshot();
|
||||||
|
// });
|
||||||
|
|
||||||
|
// it('should load diagram from raw files', () => {
|
||||||
|
// cy.visit(
|
||||||
|
// '/edit?code=https://gist.githubusercontent.com/sidharthv96/6268a23e673a533dcb198f241fd7012a/raw/4eb03887e6a41397e80bdcdbf94017c498f8f1e2/code.mmd&config=https://gist.githubusercontent.com/sidharthv96/6268a23e673a533dcb198f241fd7012a/raw/4eb03887e6a41397e80bdcdbf94017c498f8f1e2/config.json'
|
||||||
|
// );
|
||||||
|
// cy.contains('Party');
|
||||||
|
// cy.getLocalStorage('codeStore').snapshot();
|
||||||
|
// });
|
||||||
|
// });
|
||||||
|
|
||||||
|
// // Disabled temporarily. Should be enabled after the issue is fixed in Mermaid.
|
||||||
|
// // it('should prevent setting the "securityLevel" option via URL', () => {
|
||||||
|
// // const b64State = toBase64(
|
||||||
|
// // `{"code":"graph TD\\nA[\\"<img src='https://via.placeholder.com/64' width=64 />\\"]","mermaid":"{\\"securityLevel\\": \\"loose\\", \\"theme\\": \\"forest\\"}","autoSync":true,"updateDiagram":true}`,
|
||||||
|
// // true
|
||||||
|
// // );
|
||||||
|
// // cy.on('window:confirm', () => true);
|
||||||
|
// // cy.visit(`/edit#${b64State}`);
|
||||||
|
// // cy.contains('Config').click();
|
||||||
|
// // cy.contains('forest');
|
||||||
|
// // cy.contains('securityLevel').should('not.exist');
|
||||||
|
// // cy.get('#view').find('img').should('not.exist');
|
||||||
|
// // cy.get('#view').contains('<img');
|
||||||
|
// // cy.get('#view').contains(`src='https://via.placeholder.com/64'`);
|
||||||
|
// // });
|
||||||
|
|
||||||
|
// it.skip('should allow persisting "securityLevel" using confirm dialogue', () => {
|
||||||
|
// const b64State = toBase64(
|
||||||
|
// `{"code":"graph TD\\nA[\\"<img src='https://dummyimage.com/64' width=64/>\\"]","mermaid":"{\\"securityLevel\\": \\"loose\\", \\"theme\\": \\"forest\\"}","autoSync":true,"updateDiagram":true}`,
|
||||||
|
// true
|
||||||
|
// );
|
||||||
|
// cy.on('window:confirm', () => false);
|
||||||
|
// cy.visit(`/edit#${b64State}`);
|
||||||
|
// cy.get('#editor').type(' ');
|
||||||
|
// cy.contains('Config').click();
|
||||||
|
// cy.contains('forest');
|
||||||
|
// cy.contains('securityLevel');
|
||||||
|
// cy.get('#view').find('img').should('be.visible');
|
||||||
|
// });
|
||||||
|
|
||||||
|
// it('should show troubleshooting steps if loading fails', () => {
|
||||||
|
// cy.visit('/#/edit/eyJjb2RlIjoiZ3JhcGggVERcbiAg');
|
||||||
|
// cy.reload(true);
|
||||||
|
// cy.contains('Please Click here to Raise an issue in github.');
|
||||||
|
// });
|
||||||
|
|
||||||
|
// it('should load uncompressed URL', () => {
|
||||||
|
// cy.visit(
|
||||||
|
// '/edit/#eyJjb2RlIjoiZ3JhcGggVERcbiAgICBBW05ldyBZZWFyXSAtLT58R2V0IG1vbmV5fCBCKEdvIHNob3BwaW5nKVxuICAgIEIgLS0-IEN7TGV0IG1lIHRoaW5rfVxuICAgIEMgLS0-fE9uZXwgRFtMYXB0b3BdXG4gICAgQyAtLT58VHdvfCBFW2lQaG9uZV1cbiAgICBDIC0tPnxUaHJlZXwgRltmYTpmYS1jYXIgQ2FyXSIsIm1lcm1haWQiOiJ7XG4gIFwidGhlbWVcIjogXCJkZWZhdWx0XCJcbn0iLCJ1cGRhdGVFZGl0b3IiOmZhbHNlLCJhdXRvU3luYyI6dHJ1ZSwidXBkYXRlRGlhZ3JhbSI6ZmFsc2V9'
|
||||||
|
// );
|
||||||
|
// cy.contains('New Year');
|
||||||
|
// cy.visit(
|
||||||
|
// '/edit#eyJjb2RlIjoiY2xhc3NEaWFncmFtXG4gICAgQW5pbWFsIDx8LS0gRHVja1xuICAgIEFuaW1hbCA8fC0tIEZpc2hcbiAgICBBbmltYWwgPHwtLSBaZWJyYVxuICAgIEFuaW1hbCA6ICtpbnQgYWdlXG4gICAgQW5pbWFsIDogK1N0cmluZyBnZW5kZXJcbiAgICBBbmltYWw6ICtpc01hbW1hbCgpXG4gICAgQW5pbWFsOiArbWF0ZSgpXG4gICAgY2xhc3MgRHVja3tcbiAgICAgICtTdHJpbmcgYmVha0NvbG9yXG4gICAgICArc3dpbSgpXG4gICAgICArcXVhY2soKVxuICAgIH1cbiAgICBjbGFzcyBGaXNoe1xuICAgICAgLWludCBzaXplSW5GZWV0XG4gICAgICAtY2FuRWF0KClcbiAgICB9XG4gICAgY2xhc3MgWmVicmF7XG4gICAgICArYm9vbCBpc193aWxkXG4gICAgICArcnVuKClcbiAgICB9XG4gICAgICAgICAgICAiLCJtZXJtYWlkIjoie1xuICBcInRoZW1lXCI6IFwiZGFya1wiXG59IiwidXBkYXRlRWRpdG9yIjpmYWxzZSwiYXV0b1N5bmMiOnRydWUsInVwZGF0ZURpYWdyYW0iOmZhbHNlfQ'
|
||||||
|
// );
|
||||||
|
// cy.contains('Animal');
|
||||||
|
// cy.visit(
|
||||||
|
// '/edit/#base64:eyJjb2RlIjoiZ3JhcGggVERcbiAgICBBW05ldyBZZWFyXSAtLT58R2V0IG1vbmV5fCBCKEdvIHNob3BwaW5nKVxuICAgIEIgLS0-IEN7TGV0IG1lIHRoaW5rfVxuICAgIEMgLS0-fE9uZXwgRFtMYXB0b3BdXG4gICAgQyAtLT58VHdvfCBFW2lQaG9uZV1cbiAgICBDIC0tPnxUaHJlZXwgRltmYTpmYS1jYXIgQ2FyXSIsIm1lcm1haWQiOiJ7XG4gIFwidGhlbWVcIjogXCJkZWZhdWx0XCJcbn0iLCJ1cGRhdGVFZGl0b3IiOmZhbHNlLCJhdXRvU3luYyI6dHJ1ZSwidXBkYXRlRGlhZ3JhbSI6ZmFsc2V9'
|
||||||
|
// );
|
||||||
|
// 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');
|
||||||
|
// });
|
||||||
|
// });
|
||||||
|
|
||||||
|
import { test, expect } from '@playwright/test';
|
||||||
|
|
||||||
|
test.describe('site loads', () => {
|
||||||
|
test.beforeEach(async ({ page }) => {
|
||||||
|
await page.addInitScript(() => {
|
||||||
|
window.localStorage.clear();
|
||||||
|
});
|
||||||
|
await page.goto('/', { waitUntil: 'networkidle' });
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should load home page', async ({ page }) => {
|
||||||
|
expect(page.url()).toContain('/edit');
|
||||||
|
await expect(page.locator('"History"')).toBeVisible();
|
||||||
|
// const { origins } = await context.storageState();
|
||||||
|
// console.log(JSON.stringify(origins));
|
||||||
|
// expect(JSON.stringify(origins)).toMatchSnapshot('initial-storage-state.json');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should redirect from old URL', async ({ page }) => {
|
||||||
|
// Note that Promise.all prevents a race condition
|
||||||
|
// between clicking and waiting for a navigation.
|
||||||
|
await Promise.all([
|
||||||
|
page.waitForNavigation({ url: '**/edit#pako:eNp**', timeout: 1000 }),
|
||||||
|
page.goto(
|
||||||
|
'/#/edit/eyJjb2RlIjoiZ3JhcGggVERcbiAgICBBW0NocmlzdG1hc10gLS0-fEdldCBtb25leXwgQihHbyBzaG9wcGluZylcbiAgICBCIC0tPiBDe0xldCBtZSB0aGlua31cbiAgICBDIC0tPnxPbmV8IERbTGFwdG9wXVxuICAgIEMgLS0-fFR3b3wgRVtpUGhvbmVdXG4gICAgQyAtLT58VGhyZWV8IEZbZmE6ZmEtY2FyIENhcl0iLCJtZXJtYWlkIjp7InRoZW1lIjoiZGVmYXVsdCJ9LCJ1cGRhdGVFZGl0b3IiOmZhbHNlfQ'
|
||||||
|
)
|
||||||
|
]);
|
||||||
|
expect(page.url()).toContain('/edit#pako:eNp');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('should load sample diagrams when clicked', async ({ page }) => {
|
||||||
|
await page.click('"Sample Diagrams"');
|
||||||
|
await page.click('"Pie"');
|
||||||
|
await expect(page.locator('"pie title Pets adopted by volunteers"')).toBeVisible();
|
||||||
|
await page.click('"Class"');
|
||||||
|
await expect(page.locator('"classDiagram"')).toBeVisible();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
// test('homepage has Playwright in title and get started link linking to the intro page', async ({
|
||||||
|
// page,
|
||||||
|
// context
|
||||||
|
// }) => {
|
||||||
|
// await page.goto(
|
||||||
|
// 'http://localhost:3000/edit?gist=https://gist.github.com/sidharthv96/6268a23e673a533dcb198f241fd7012a/ec9b4ab0e41e4ff6287326cd3cb47affd7851e19'
|
||||||
|
// );
|
||||||
|
|
||||||
|
// // cy.getLocalStorage('codeStore').snapshot();
|
||||||
|
// // Expect a title "to contain" a substring.
|
||||||
|
// await page.locator('"History"').click();
|
||||||
|
// await page.locator('"Party"').isVisible();
|
||||||
|
// await page.locator('"Revisions"').isVisible();
|
||||||
|
// await page.locator('"sidharthv96 v7851e19"').isVisible();
|
||||||
|
// await page.waitForTimeout(400);
|
||||||
|
// const storage = await context.storageState();
|
||||||
|
// expect(JSON.stringify(storage)).toMatchSnapshot();
|
||||||
|
// });
|
||||||
@@ -0,0 +1,17 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"origin": "http://localhost:3000",
|
||||||
|
"localStorage": [
|
||||||
|
{ "name": "__anon_id", "value": "\"87f53493-b439-425c-961c-9a2014f0ced8\"" },
|
||||||
|
{ "name": "manualHistoryStore", "value": "[]" },
|
||||||
|
{ "name": "autoHistoryMode", "value": "\"manual\"" },
|
||||||
|
{
|
||||||
|
"name": "codeStore",
|
||||||
|
"value": "{\"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}"
|
||||||
|
},
|
||||||
|
{ "name": "migrations", "value": "{\"version\":0}" },
|
||||||
|
{ "name": "themeStore", "value": "{\"theme\":\"light\",\"isDark\":false}" },
|
||||||
|
{ "name": "autoHistoryStore", "value": "[]" }
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
[{"origin":"http://localhost:3000","localStorage":[{"name":"__anon_id","value":"\"e4127e54-eced-443f-837e-0986e577b624\""},{"name":"manualHistoryStore","value":"[]"},{"name":"autoHistoryMode","value":"\"manual\""},{"name":"codeStore","value":"{\"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}"},{"name":"migrations","value":"{\"version\":0}"},{"name":"themeStore","value":"{\"theme\":\"light\",\"isDark\":false}"},{"name":"autoHistoryStore","value":"[]"}]}]
|
||||||
+5
-1
@@ -6,8 +6,12 @@
|
|||||||
"cypress/**/*.ts",
|
"cypress/**/*.ts",
|
||||||
"cypress/**/*.js",
|
"cypress/**/*.js",
|
||||||
"cypress/**/*.json",
|
"cypress/**/*.json",
|
||||||
|
"tests/**/*.ts",
|
||||||
|
"tests/**/*.js",
|
||||||
|
"tests/**/*.json",
|
||||||
"static/**/*.js",
|
"static/**/*.js",
|
||||||
"static/**/*.json"
|
"static/**/*.json",
|
||||||
|
"./playwright.config.ts"
|
||||||
],
|
],
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"resolveJsonModule": true,
|
"resolveJsonModule": true,
|
||||||
|
|||||||
+4
-4
@@ -1,7 +1,6 @@
|
|||||||
import { sveltekit } from '@sveltejs/kit/vite';
|
import { sveltekit } from '@sveltejs/kit/vite';
|
||||||
import { defineConfig } from 'vitest/config';
|
/** @type {import('vite').UserConfig} */
|
||||||
|
const config = {
|
||||||
export default defineConfig({
|
|
||||||
plugins: [sveltekit()],
|
plugins: [sveltekit()],
|
||||||
envPrefix: 'MERMAID_',
|
envPrefix: 'MERMAID_',
|
||||||
optimizeDeps: { include: ['mermaid'] },
|
optimizeDeps: { include: ['mermaid'] },
|
||||||
@@ -23,4 +22,5 @@ export default defineConfig({
|
|||||||
reporter: ['text', 'json', 'html', 'lcov']
|
reporter: ['text', 'json', 'html', 'lcov']
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
};
|
||||||
|
export default config;
|
||||||
|
|||||||
Reference in New Issue
Block a user