Skip to content

Commit

Permalink
use mermaid v10.x
Browse files Browse the repository at this point in the history
  • Loading branch information
hojas committed Jul 8, 2023
1 parent 7b12fce commit df72e0f
Show file tree
Hide file tree
Showing 25 changed files with 3,166 additions and 513 deletions.
5 changes: 5 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
process.env.ESLINT_TSCONFIG = 'tsconfig.json'

module.exports = {
extends: '@antfu'
}
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@ dist-ssr

# Editor directories and files
.vscode
!.vscode/extensions.json
.idea
.DS_Store
*.suo
Expand Down
4 changes: 0 additions & 4 deletions .prettierrc

This file was deleted.

10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# vue-mermaid-render

Vue component to render diagrams with Mermaid.
Vue 3 component to render diagrams with Mermaid.

## Install

Expand All @@ -17,10 +17,10 @@ import { VueMermaidRender } from 'vue-mermaid-render'
const content = `
graph TD;
A-->B;
A-->C;
B-->D;
C-->D;
A-->B;
A-->C;
B-->D;
C-->D;
`
</script>
Expand Down
42 changes: 5 additions & 37 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,43 +1,11 @@
{
"name": "vue-mermaid-render",
"version": "0.0.3",
"packageManager": "[email protected]",
"license": "MIT",
"keywords": [
"vue",
"vue-component",
"component",
"mermaid",
"diagrams"
],
"repository": "hojas/vue-mermaid-render",
"bugs": "https://github.com/hojas/vue-mermaid-render/issues",
"type": "module",
"files": [
"dist"
],
"types": "./dist/index.d.ts",
"main": "./dist/vue-mermaid-render.umd.cjs",
"module": "./dist/vue-mermaid-render.js",
"exports": {
".": {
"import": "./dist/vue-mermaid-render.js",
"require": "./dist/vue-mermaid-render.umd.cjs"
}
},
"scripts": {
"build": "vite build && vue-tsc --declaration --emitDeclarationOnly"
},
"dependencies": {
"mermaid": "^9.4.0"
},
"version": "0.0.0",
"packageManager": "[email protected]",
"license": "MIT",
"devDependencies": {
"@types/node": "^18.14.0",
"@vitejs/plugin-vue": "^4.0.0",
"prettier": "^2.8.4",
"typescript": "^4.9.5",
"vite": "^4.1.3",
"vue": "^3.2.47",
"vue-tsc": "^1.1.5"
"@antfu/eslint-config": "^0.39.7",
"eslint": "^8.44.0"
}
}
12 changes: 12 additions & 0 deletions packages/demo/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>VueMermaidRender Demo</title>
</head>
<body>
<div id="app"></div>
<script type="module" src="/src/main.ts"></script>
</body>
</html>
19 changes: 19 additions & 0 deletions packages/demo/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
"name": "demo",
"type": "module",
"private": true,
"scripts": {
"dev": "vite"
},
"dependencies": {
"vue": "^3.3.4",
"vue-mermaid-render": "workspace:*"
},
"devDependencies": {
"@types/node": "^20.4.1",
"@vitejs/plugin-vue": "^4.2.3",
"typescript": "^5.1.6",
"vite": "^4.4.2",
"vue-tsc": "^1.8.4"
}
}
32 changes: 32 additions & 0 deletions packages/demo/src/App.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<script setup lang="ts">
import { ref } from 'vue'
import { VueMermaidRender } from 'vue-mermaid-render'
const content = ref(`
graph TD;
A-->B;
A-->C;
B-->D;
C-->D;
`)
setTimeout(() => {
content.value = `
sequenceDiagram
participant Alice
participant Bob
Alice->>John: Hello John, how are you?
loop Healthcheck
John->>John: Fight against hypochondria
end
Note right of John: Rational thoughts <br/>prevail!
John-->>Alice: Great!
John->>Bob: How about you?
Bob-->>John: Jolly good!
`
}, 2000)
</script>

<template>
<VueMermaidRender :content="content" />
</template>
4 changes: 4 additions & 0 deletions packages/demo/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { createApp } from 'vue'
import App from './App.vue'

createApp(App).mount('#app')
File renamed without changes.
25 changes: 25 additions & 0 deletions packages/demo/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"skipLibCheck": true,

/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "preserve",

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
"references": [{ "path": "./tsconfig.node.json" }]
}
3 changes: 2 additions & 1 deletion tsconfig.node.json → packages/demo/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
{
"compilerOptions": {
"composite": true,
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "Node",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true
},
"include": ["vite.config.ts"]
Expand Down
6 changes: 6 additions & 0 deletions packages/demo/vite.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

export default defineConfig({
plugins: [vue()],
})
41 changes: 41 additions & 0 deletions packages/vue-mermaid-render/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{
"name": "vue-mermaid-render",
"type": "module",
"version": "0.1.0",
"packageManager": "[email protected]",
"license": "MIT",
"repository": "hojas/vue-mermaid-render",
"bugs": "https://github.com/hojas/vue-mermaid-render/issues",
"keywords": [
"vue",
"vue-component",
"component",
"mermaid",
"diagrams"
],
"exports": {
".": {
"types": "./dist/main.d.ts",
"require": "./dist/vue-mermaid-render.umd.cjs",
"import": "./dist/vue-mermaid-render.js"
}
},
"main": "./dist/vue-mermaid-render.umd.cjs",
"module": "./dist/vue-mermaid-render.js",
"types": "./dist/main.d.ts",
"files": ["dist"],
"scripts": {
"build": "vite build && vue-tsc --declaration --emitDeclarationOnly"
},
"dependencies": {
"mermaid": "^10.2.4"
},
"devDependencies": {
"@types/node": "^20.4.1",
"@vitejs/plugin-vue": "^4.2.3",
"typescript": "^5.1.6",
"vite": "^4.4.2",
"vue": "^3.3.4",
"vue-tsc": "^1.8.4"
}
}
49 changes: 49 additions & 0 deletions packages/vue-mermaid-render/src/components/VueMermaidRender.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<script setup lang="ts">
import { onMounted, ref, watchEffect } from 'vue'
import type { MermaidConfig } from 'mermaid'
import mermaid from 'mermaid'
const props = defineProps<{ content: string; config?: MermaidConfig }>()
const mounted = ref(false)
const el = ref()
const mermaidString = ref('')
function genSvgId() {
const min = Math.ceil(1)
const max = Math.floor(100000)
return `mermaid-svg-${Math.floor(Math.random() * (max - min + 1))}${min}`
}
async function updateGraph(graphDefinition: string) {
const id = genSvgId()
const res = await mermaid.render(id, graphDefinition, el.value)
mermaidString.value = res.svg
}
watchEffect(() => {
if (!mounted.value)
return
if (props.config)
mermaid.initialize({ startOnLoad: false, ...props.config })
else
mermaid.initialize({ startOnLoad: false })
})
watchEffect(() => {
if (!mounted.value)
return
if (props.content)
updateGraph(props.content)
})
onMounted(() => {
mounted.value = true
})
</script>

<template>
<pre ref="el" class="mermaid" v-html="mermaidString" />
</template>
10 changes: 10 additions & 0 deletions packages/vue-mermaid-render/src/main.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import type { App } from 'vue'
import VueMermaidRender from './components/VueMermaidRender.vue'

export { VueMermaidRender }

export default {
install: (app: App) => {
app.component('VueMermaidRender', VueMermaidRender)
},
}
3 changes: 3 additions & 0 deletions packages/vue-mermaid-render/src/vite-env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/// <reference types="vite/client" />

declare module '*.vue'
26 changes: 26 additions & 0 deletions packages/vue-mermaid-render/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"compilerOptions": {
"target": "ES2020",
"useDefineForClassFields": true,
"module": "ESNext",
"lib": ["ES2020", "DOM", "DOM.Iterable"],
"skipLibCheck": true,
"outDir": "dist",

/* Bundler mode */
"moduleResolution": "bundler",
"allowImportingTsExtensions": true,
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": false,
"jsx": "preserve",

/* Linting */
"strict": true,
"noUnusedLocals": true,
"noUnusedParameters": true,
"noFallthroughCasesInSwitch": true
},
"include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
"references": [{ "path": "./tsconfig.node.json" }]
}
10 changes: 10 additions & 0 deletions packages/vue-mermaid-render/tsconfig.node.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"composite": true,
"skipLibCheck": true,
"module": "ESNext",
"moduleResolution": "bundler",
"allowSyntheticDefaultImports": true
},
"include": ["vite.config.ts"]
}
5 changes: 3 additions & 2 deletions vite.config.ts → packages/vue-mermaid-render/vite.config.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import { resolve } from 'path'
import { resolve } from 'node:path'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'

export default defineConfig({
build: {
lib: {
entry: resolve(__dirname, 'src/index.ts'),
entry: resolve(__dirname, 'src/main.ts'),
name: 'VueMermaidRender',
fileName: 'vue-mermaid-render',
},
Expand All @@ -14,6 +14,7 @@ export default defineConfig({
output: {
globals: {
vue: 'Vue',
mermaid: 'mermaid',
},
},
},
Expand Down
Loading

0 comments on commit df72e0f

Please sign in to comment.