remark-mind-elixir 0.4.0 → 0.5.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/package.json +1 -1
- package/src/client.js +6 -6
- package/src/index.js +38 -8
package/package.json
CHANGED
package/src/client.js
CHANGED
|
@@ -2,15 +2,15 @@ import { MindMap } from '@zikojs/mind-elixir/no-css'
|
|
|
2
2
|
|
|
3
3
|
document.addEventListener('DOMContentLoaded', () => {
|
|
4
4
|
document.querySelectorAll('[data-elixir-mind]').forEach((element) => {
|
|
5
|
-
const
|
|
6
|
-
|
|
5
|
+
const body = element.dataset.xmindBody
|
|
6
|
+
const config = element.dataset?.xmindConfig
|
|
7
7
|
|
|
8
|
-
if (!
|
|
8
|
+
if (!body) return
|
|
9
9
|
|
|
10
|
-
const nodeData = JSON.parse(
|
|
11
|
-
|
|
10
|
+
const nodeData = JSON.parse(body)
|
|
11
|
+
const nodeConfig = JSON.parse(config)
|
|
12
12
|
|
|
13
|
-
const map = MindMap({}, nodeData)
|
|
13
|
+
const map = MindMap({height : '400px', ...nodeConfig}, nodeData)
|
|
14
14
|
|
|
15
15
|
map.mount(element)
|
|
16
16
|
})
|
package/src/index.js
CHANGED
|
@@ -16,10 +16,10 @@ const remarkElixirMind = ({
|
|
|
16
16
|
let config = {}, body = null;
|
|
17
17
|
|
|
18
18
|
const documents = splitDocuments(node.value.trim());
|
|
19
|
-
if(documents.length === 1) body =
|
|
19
|
+
if(documents.length === 1) body = parseMindBody(documents[0])
|
|
20
20
|
else {
|
|
21
21
|
config = parse(documents[0])
|
|
22
|
-
body =
|
|
22
|
+
body = parseMindBody(documents[1])
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
// parent creates circular references, so serialize a clean copy
|
|
@@ -59,12 +59,12 @@ const remarkElixirMind = ({
|
|
|
59
59
|
import { MindMap } from 'https://esm.sh/@zikojs/mind-elixir@latest/src/mind/main.js'
|
|
60
60
|
document.addEventListener('DOMContentLoaded', () => {
|
|
61
61
|
document.querySelectorAll('[data-elixir-mind]').forEach((element) => {
|
|
62
|
-
const
|
|
63
|
-
|
|
64
|
-
if (!
|
|
65
|
-
const nodeData = JSON.parse(
|
|
66
|
-
|
|
67
|
-
const map = MindMap({}, nodeData)
|
|
62
|
+
const body = element.dataset.xmindBody
|
|
63
|
+
const config = element.dataset?.xmindConfig
|
|
64
|
+
if (!body) return
|
|
65
|
+
const nodeData = JSON.parse(body)
|
|
66
|
+
const nodeConfig = JSON.parse(config)
|
|
67
|
+
const map = MindMap({height : '400px', ...nodeConfig}, nodeData)
|
|
68
68
|
map.mount(element)
|
|
69
69
|
})
|
|
70
70
|
})
|
|
@@ -140,4 +140,34 @@ const splitDocuments = (text) => {
|
|
|
140
140
|
}
|
|
141
141
|
|
|
142
142
|
return documents
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// const parseMindBody = (text) => {
|
|
146
|
+
// try {
|
|
147
|
+
// return JSON.parse(text)
|
|
148
|
+
// } catch {
|
|
149
|
+
// return yaml2MindElixirData(text)
|
|
150
|
+
// }
|
|
151
|
+
// }
|
|
152
|
+
|
|
153
|
+
const parseMindBody = (text) => {
|
|
154
|
+
const trimmed = text.trim()
|
|
155
|
+
|
|
156
|
+
// JSON
|
|
157
|
+
try {
|
|
158
|
+
return JSON.parse(trimmed)
|
|
159
|
+
} catch {}
|
|
160
|
+
|
|
161
|
+
// JavaScript object/array
|
|
162
|
+
if (
|
|
163
|
+
trimmed.startsWith('{') ||
|
|
164
|
+
trimmed.startsWith('[')
|
|
165
|
+
) {
|
|
166
|
+
try {
|
|
167
|
+
return Function(`"use strict"; return (${trimmed})`)()
|
|
168
|
+
} catch {}
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
// YAML
|
|
172
|
+
return yaml2MindElixirData(trimmed)
|
|
143
173
|
}
|