Skip to content

Commit a494f1a

Browse files
fix: vue 3, component is client-only now, CDN doesn't require mermaid anymore
BREAKING CHANGE: Migrated to Vue 3 BREAKING CHANGE: The component is client-only now. This means that if you use SSR, you need to make sure that the component is only instantiated on the client (e.g. use <client-only> with Nuxt). Having this flexible led to some issues.
1 parent 9a1a075 commit a494f1a

File tree

9 files changed

+2459
-4716
lines changed

9 files changed

+2459
-4716
lines changed

.baserc.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
{
22
"name": "@dword-design/component",
33
"testInContainer": true,
4-
"cdnExtraScripts": [
5-
"<script src=\"https://unpkg.com/mermaid/dist/mermaid.min.js\"></script>"
6-
],
74
"seeAlso": [
85
{ "repository": "nuxt-mermaid-string", "description": "Embed a Mermaid diagram in a Nuxt.js app by providing its diagram string." }
96
]

.devcontainer/devcontainer.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
{
2+
"features": {
3+
"ghcr.io/devcontainers/features/docker-in-docker:2": {}
4+
},
5+
"image": "mcr.microsoft.com/devcontainers/javascript-node:0-16",
6+
"updateContentCommand": "yarn --frozen-lockfile"
7+
}

.gitpod.Dockerfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ RUN git lfs install
77

88
# https://www.gitpod.io/docs/languages/javascript
99
RUN bash -c 'VERSION="16" && source $HOME/.nvm/nvm.sh && nvm install $VERSION && nvm use $VERSION && nvm alias default $VERSION'
10-
RUN echo "nvm use default &>/dev/null" >> ~/.bashrc.d/51-nvm-fix
1110

1211
RUN echo "\nexport PATH=$(yarn global bin):\$PATH" >> /home/gitpod/.bashrc
1312

.vscode/settings.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
".browserslistrc": true,
77
".commitlintrc.json": true,
88
".cz.json": true,
9+
".devcontainer": true,
910
".editorconfig": true,
1011
".eslintrc.json": true,
1112
".gitattributes": true,
@@ -17,6 +18,7 @@
1718
".nyc_output": true,
1819
".releaserc.json": true,
1920
".renovaterc.json": true,
21+
".vscode": true,
2022
"CHANGELOG.md": true,
2123
"LICENSE.md": true,
2224
"coverage": true,

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,8 +101,7 @@ Vue.use(VueMermaidString)
101101
## Install via CDN
102102

103103
```html
104-
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
105-
<script src="https://unpkg.com/mermaid/dist/mermaid.min.js"></script>
104+
<script src="https://unpkg.com/vue@3/dist/vue.global.js"></script>
106105
<script src="https://unpkg.com/vue-mermaid-string"></script>
107106
```
108107
<!-- /INSTALL -->

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
},
3131
"devDependencies": {
3232
"@dword-design/base": "^9.1.10",
33-
"@dword-design/base-config-component": "^1.1.7",
33+
"@dword-design/base-config-component": "^2.0.0",
3434
"@dword-design/functions": "^4.0.0",
3535
"@dword-design/puppeteer": "^6.0.0",
3636
"@dword-design/tester": "^2.0.0",
37-
"@dword-design/tester-plugin-component": "^2.0.0",
37+
"@dword-design/tester-plugin-component": "^3.0.0",
3838
"@dword-design/tester-plugin-puppeteer": "^2.0.0"
3939
},
4040
"engines": {

src/index.spec.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@ export default tester(
4242
async test() {
4343
await this.page.goto('http://localhost:3000')
4444
await this.page.waitForSelector('.foo')
45+
console.log('ready')
46+
await new Promise(resolve => setTimeout(resolve, 30000))
4547
await this.page.click('button')
4648
expect(
4749
await this.page.screenshot({ fullPage: true })

src/index.vue

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@
33
</template>
44

55
<script>
6+
import mermaid from 'mermaid'
67
import { nanoid } from 'nanoid'
78
89
import addClickEvent from './add-click-event.js'
910
1011
export default {
11-
beforeDestroy() {
12+
beforeUnmount() {
1213
delete window[`mermaidClick_${this.id}`]
1314
},
1415
computed: {
@@ -20,22 +21,15 @@ export default {
2021
methods: {
2122
update() {
2223
if (typeof window !== 'undefined') {
23-
const mermaid = window.mermaid || require('mermaid').default
24-
mermaid.parseError = error => this.$emit('parse-error', error)
2524
this.$el.removeAttribute('data-processed')
26-
this.$el.replaceChild(
27-
document.createTextNode(this.finalValue),
28-
this.$el.firstChild
29-
)
25+
mermaid.parseError = error => this.$emit('parse-error', error)
3026
mermaid.init(this.finalValue, this.$el)
3127
}
3228
},
3329
},
3430
mounted() {
3531
if (typeof window !== 'undefined') {
3632
window[`mermaidClick_${this.id}`] = id => this.$emit('node-click', id)
37-
38-
const mermaid = window.mermaid || require('mermaid').default
3933
mermaid.initialize({
4034
securityLevel: 'loose',
4135
startOnLoad: false,
@@ -52,8 +46,11 @@ export default {
5246
value: { required: true, type: String },
5347
},
5448
watch: {
55-
finalValue() {
56-
return this.update()
49+
finalValue: {
50+
flush: 'post',
51+
async handler() {
52+
await this.update()
53+
},
5754
},
5855
},
5956
}

yarn.lock

Lines changed: 2437 additions & 4697 deletions
Large diffs are not rendered by default.

0 commit comments

Comments
 (0)