-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
76 lines (69 loc) · 1.9 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import { saveAs } from 'file-saver'
import JSZip from 'jszip'
import manifest from './xmind/manifest'
import metadata from './xmind/metadata'
import content from './xmind/content'
function generateUUID() {
return (
new Date().getTime().toString(16) + Math.random().toString(16).substr(2)
).substr(2, 16)
}
function convert(data) {
data.title = data.topic
delete data.topic
if (data.style) {
const style = data.style
const properties = {}
if (style.fontSize) {
properties['fo:font-size'] = style.fontSize
}
if (style.fontWeight) {
properties['fo:font-weight'] = style.fontWeight
}
if (style.color) {
properties['fo:color'] = style.color
}
if (style.background) {
properties['svg:fill'] = style.background
properties['fill-pattern'] = 'solid'
}
data.style = { properties }
}
if (data.children) {
for (let i = 0; i < data.children.length; i++) {
convert(data.children[i])
}
data.children = {
attached: data.children,
}
}
}
export function data2Xmind(data, version) {
const zip = new JSZip()
const id = generateUUID()
if (version) {
metadata.creator.version = version
}
metadata.activeSheetId = id
const c0 = content[0]
c0.id = id
c0.title = data.nodeData.topic
convert(data.nodeData)
c0.rootTopic = data.nodeData
zip.file('manifest.json', JSON.stringify(manifest))
zip.file('metadata.json', JSON.stringify(metadata))
zip.file('content.json', JSON.stringify(content))
return zip.generateAsync({ type: 'blob' })
}
export default function (me) {
me.exportXmind = function () {
const data = me.getData()
return data2Xmind(data, me.version)
}
me.exportXmindFile = async function (fileName) {
const data = me.getData()
const file = await data2Xmind(data, me.version)
// `topic` had renamed to `title`
saveAs(file, (fileName || data.nodeData.title) + '.xmind')
}
}