Skip to content

Commit

Permalink
Merge pull request #1 from ssshooter/v1.1.0
Browse files Browse the repository at this point in the history
feat: add data2Xmind function, code optimization
  • Loading branch information
SSShooter authored Nov 22, 2022
2 parents 74fe5e1 + ca36b21 commit 93bec56
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 24 deletions.
43 changes: 24 additions & 19 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,30 +42,35 @@ function convert(data) {
}
}

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 zip = new JSZip()
const data = me.getAllData()
const id = generateUUID()

metadata.creator.version = me.version
metadata.activeSheetId = id
const c0 = content[0]
c0.id = id
c0.title = data.nodeData.topic
const clone = JSON.parse(JSON.stringify(data.nodeData))
convert(clone)
c0.rootTopic = clone
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' })
return data2Xmind(data, me.version)
}
me.exportXmindFile = async function (fileName) {
const data = me.getAllData()
this.exportXmind().then(function (content) {
saveAs(content, (fileName || data.nodeData.topic) + '.xmind')
})
const file = await data2Xmind(data, me.version)
// `topic` had renamed to `title`
saveAs(file, (fileName || data.nodeData.title) + '.xmind')
}
}
3 changes: 2 additions & 1 deletion main.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import MindElixir, { E } from 'mind-elixir'
import { exportSvg, exportPng } from 'mind-elixir/dist/painter'
import example from 'mind-elixir/dist/example1'

import exportXmind from './index'
import exportXmind, { data2Xmind } from './index'
// import exportXmind from '@mind-elixir/export-xmind'

const app = document.querySelector('#app')
Expand Down Expand Up @@ -90,3 +90,4 @@ window.M = MindElixir
window.E = MindElixir.E
window.exportSvg = exportSvg
window.exportPng = exportPng
window.data2Xmind = data2Xmind
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@mind-elixir/export-xmind",
"version": "1.0.0",
"version": "1.1.0",
"type": "module",
"files": [
"dist"
Expand Down
12 changes: 11 additions & 1 deletion readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ npm i @mind-elixir/export-xmind jszip file-saver

## How To Use

### Use As A Plugin

```javascript
import MindElixir from 'mind-elixir'
import exportXmind from '@mind-elixir/export-xmind'
Expand All @@ -20,5 +22,13 @@ mind.init(data)

const blob = await mind.exportXmind() // get blob

mind.exportXmindFile() // download file
mind.exportXmindFile(fileName) // download file
```

### MindElixir Data To Xmind

```javascript
import { data2Xmind } from '@mind-elixir/export-xmind'
// use this way to avoid creating instance
const blob = await data2Xmind(data) // data returned by getAllData()
```
4 changes: 2 additions & 2 deletions xmind/metadata.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export default {
creator: {
name: 'Mind-Elixir',
version: '12.0.3.202206241736',
version: '1.0.0',
},
activeSheetId: '17b972f40eea83577fe8ab16e5',
activeSheetId: '',
}

0 comments on commit 93bec56

Please sign in to comment.