@diplodoc/mermaid-extension 0.0.9 → 1.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/Readme.md CHANGED
@@ -5,7 +5,7 @@ This is extension for Diplodoc platform which adds support for Mermaid diagrams.
5
5
  Extension contains some parts:
6
6
  - [Prepared Mermaid runtime](#prepared-mermaid-runtime)
7
7
  - [MarkdownIt transform plugin](#markdownit-transform-plugin)
8
- - [React hook for smart control of Mermaid](#react-hook-for-smart-control-of-mermaid)
8
+ - [React hook_and_component for smart control of Mermaid](#react-hook-for-smart-control-of-mermaid)
9
9
 
10
10
  ## Quickstart
11
11
  Attach plugin to transformer
@@ -78,12 +78,28 @@ window.mermaidJsonp.push((mermaid) => {
78
78
  });
79
79
  ```
80
80
 
81
+ ### Custom initialize options
82
+
83
+ Exposed `mermaid.initialize` method has extra configuration options:
84
+
85
+ - `zoom` - Enable diagram *zoom and explore* feature. Can be boolean or object with inner props.<br>
86
+ (Default: false)<br>
87
+ - `showMenu` - Show navigation menu.<br>
88
+ (Default: false)
89
+ - `bindKeys` - Enable `wasd` controls.<br>
90
+ Use `w/a/s/d` to explore diagram, `e/q` to zoom in/out and `r` to reset diagram position.<br>
91
+ (Default: false)
92
+ - `maximumScale` - Maximum zoom scale.<br>
93
+ (Default: 5)
94
+ - `resetOnBlur` - Reeset diagram position on outher click.<br>
95
+ (Default: false)
96
+
81
97
  ## MarkdownIt transform plugin
82
98
 
83
99
  Plugin for [@diplodoc/transform](https://github.com/diplodoc-platform/transform) package.
84
100
 
85
101
  Configuration:
86
- - `runtime` - name on runtime script which will be exposed in results `script` section.<br>
102
+ - `runtime` - name of runtime script which will be exposed in results `script` section.<br>
87
103
  (Default: `_assets/mermaid-extension.js`)<br>
88
104
 
89
105
  - `bundle` - boolean flag to enable/disable copying of bundled runtime to target directory.<br>
@@ -93,19 +109,56 @@ Configuration:
93
109
  - `classes` - additional classes which will be added to Mermaid's diagrams.<br>
94
110
  Example: `my-own-class and-other-class`<br>
95
111
 
96
- ## React hook for smart control of Mermaid
112
+ ## React hook and component for smart control of Mermaid
97
113
 
98
114
  Simplifies Mermaid control with react
99
115
 
100
- ```ts
101
- import React, { useEffect } from 'react'
102
- import { useMermaid } from '@diplodoc/mermaid-extension/hooks'
116
+ ```tsx
117
+ import React from 'react'
118
+ import { transform } from '@diplodoc/transform'
119
+ import mermaid from '@diplodoc/mermaid-extension/plugin'
120
+ import { MermaidRuntime } from '@diplodoc/mermaid-extension/react'
121
+
122
+ const MERMAID_RUNTIME = 'extension:mermaid';
123
+
124
+ const Doc: React.FC = ({ content }) => {
125
+ const result = transform(content, {
126
+ plugins: [
127
+ // Initialize plugin for client/server rendering
128
+ mermaid.transform({
129
+ // Do not touch file system
130
+ bundle: false,
131
+ // Set custom runtime name for searching in result scripts
132
+ runtime: MERMAID_RUNTIME
133
+ })
134
+ ]
135
+ })
136
+
137
+ // Load mermaid only if one or more diagram should be rendered
138
+ if (result.script.includes(MERMAID_RUNTIME)) {
139
+ // Load oversized mermaid runtime asyncronously
140
+ import('@diplodoc/mermaid-extension/runtime')
141
+ }
142
+
143
+ return <div dangerouslySetInnerHTML={{ __html: result.html }} />
144
+ }
103
145
 
104
146
  export const App: React.FC = ({ theme }) => {
105
- const renderMermaid = useMermaid()
106
-
107
- useEffect(() => {
108
- renderMermaid({ theme })
109
- }, [ theme, renderMermaid ])
147
+ return <>
148
+ <Doc content={`
149
+ \`\`\`mermaid
150
+ graph TD
151
+ A[Christmas] -->|Get money| B(Go shopping)
152
+ B --> C{Let me think}
153
+ \`\`\`
154
+ `}/>
155
+ <MermaidRuntime
156
+ zoom={{
157
+ showMenu: true,
158
+ bindKeys: true,
159
+ resetOnBlur: true,
160
+ }}
161
+ />
162
+ </>
110
163
  }
111
164
  ```
package/package.json CHANGED
@@ -1,19 +1,19 @@
1
1
  {
2
2
  "name": "@diplodoc/mermaid-extension",
3
- "version": "0.0.9",
3
+ "version": "1.1.0",
4
4
  "description": "Mermaid plugin for Diplodoc transformer and builder",
5
5
  "main": "plugin/index.js",
6
6
  "types": "plugin/index.d.ts",
7
7
  "exports": {
8
8
  ".": "./plugin/index.js",
9
+ "./plugin": "./plugin/index.js",
9
10
  "./runtime": "./runtime/index.js",
10
- "./hooks": "./hooks/index.js"
11
+ "./react": "./react/index.js",
12
+ "./hooks": "./react/index.js"
11
13
  },
12
14
  "scripts": {
13
15
  "build": "run-p build:*",
14
- "build:plugin": "./esbuild/plugin.sh",
15
- "build:hooks": "./esbuild/hooks.sh",
16
- "build:runtime": "./esbuild/runtime.sh",
16
+ "build:js": "./esbuild/build.js",
17
17
  "build:declarations": "tsc --emitDeclarationOnly --outDir .",
18
18
  "prepublishOnly": "npm run build",
19
19
  "test": "jest"
@@ -39,10 +39,12 @@
39
39
  },
40
40
  "devDependencies": {
41
41
  "@doc-tools/transform": "^2.16.4",
42
+ "@types/d3": "^7.4.0",
42
43
  "@types/markdown-it": "^12.2.3",
43
44
  "@types/node": "^20.3.2",
44
45
  "@types/react": "^18.0.35",
45
46
  "esbuild": "^0.17.12",
47
+ "esbuild-inline-sass": "^0.4.1",
46
48
  "jest": "^29.5.0",
47
49
  "markdown-it": "^13.0.1",
48
50
  "npm-run-all": "^4.1.5",
@@ -50,6 +52,7 @@
50
52
  "typescript": "^5.0.2"
51
53
  },
52
54
  "dependencies": {
55
+ "@gravity-ui/icons": "^2.3.0",
53
56
  "mermaid": "^10.0.2",
54
57
  "ts-dedent": "^2.2.0"
55
58
  }