Skip to content

Commit 4e10550

Browse files
committed
🎉 1.0.0 released, breaking changes included
1 parent acc7e24 commit 4e10550

File tree

8 files changed

+176
-147
lines changed

8 files changed

+176
-147
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "mind-elixir",
3-
"version": "0.19.8",
3+
"version": "1.0.0",
44
"description": "Mind elixir is a free open source mind map core.",
55
"main": "dist/MindElixir.js",
66
"scripts": {

readme.md

Lines changed: 30 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,15 @@
1616
</a>
1717
</p>
1818

19+
[中文 README](https://github.com/ssshooter/mind-elixir-core/blob/master/readme.cn.md)
20+
1921
Mind elixir is a free open source mind map core.
2022

21-
[中文](https://github.com/ssshooter/mind-elixir-core/blob/master/readme.cn.md)
23+
- High performance
24+
- Small size
25+
- Framework agnostic
26+
- Pluginable
27+
- Build-in drag and drop / node edit plugin
2228

2329
## Try now
2430

@@ -68,17 +74,16 @@ import MindElixir, { E } from 'mind-elixir'
6874

6975
### Init
7076

77+
**Breaking Change** since 1.0.0, `data` should be passed to `init()`, not `options`.
78+
7179
```javascript
7280
import MindElixir, { E } from 'mind-elixir'
7381
import { exportSvg, exportPng } from '../dist/painter'
7482
import example from '../dist/example1'
7583

7684
let options = {
77-
el: '#map',
85+
el: '#map', // or HTMLDivElement
7886
direction: MindElixir.LEFT,
79-
// create new map data
80-
data: MindElixir.new('new topic') or example,
81-
// the data return from `.getAllData()`
8287
draggable: true, // default true
8388
contextMenu: true, // default true
8489
toolBar: true, // default true
@@ -114,11 +119,17 @@ let options = {
114119
}
115120

116121
let mind = new MindElixir(options)
117-
mind.init()
122+
123+
mind.install(plugin) // install your plugin
124+
125+
// create new map data
126+
const data = MindElixir.new('new topic')
127+
// or `example`
128+
// or the data return from `.getAllData()`
129+
mind.init(data)
118130

119131
// get a node
120132
E('node-id')
121-
122133
```
123134

124135
### Data Structure
@@ -170,21 +181,11 @@ mind.getAllDataString() // stringify object
170181
mind.getAllDataMd() // markdown
171182
```
172183

173-
### Export as image
174-
175-
**WIP**
176-
177-
```javascript
178-
import painter from 'mind-elixir/dist/painter'
179-
painter.exportSvg()
180-
painter.exportPng()
181-
```
182-
183184
### Operation Guards
184185

185186
```javascript
186187
let mind = new MindElixir({
187-
...
188+
// ...
188189
before: {
189190
insertSibling(el, obj) {
190191
console.log(el, obj)
@@ -204,10 +205,20 @@ let mind = new MindElixir({
204205
})
205206
```
206207

208+
### Export as image
209+
210+
**WIP**
211+
212+
```javascript
213+
import painter from 'mind-elixir/dist/painter'
214+
painter.exportSvg()
215+
painter.exportPng()
216+
```
217+
207218
## Doc
208219

209220
https://doc.mind-elixir.com/
210221

211222
## Thanks
212223

213-
[canvg](https://github.com/canvg/canvg)
224+
[canvg](https://github.com/canvg/canvg)

src/dev.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@ const options = {
2020
newTopicName: '子节点',
2121
direction: MindElixir.SIDE,
2222
// direction: MindElixir.RIGHT,
23-
data: MindElixir.new('new topic'),
24-
// data: example,
2523
locale: 'en',
2624
draggable: true,
2725
editable: true,
@@ -62,7 +60,9 @@ const options = {
6260
}
6361

6462
const mind = new (MindElixir as any)(options)
65-
mind.init()
63+
64+
const data = MindElixir.new('new topic')
65+
mind.init(example) // or try `example`
6666
function sleep() {
6767
return new Promise<void>((res, rej) => {
6868
setTimeout(() => res(), 1000)
@@ -72,12 +72,11 @@ console.log('test E function', E('bd4313fbac40284b'))
7272
const mind2 = new (MindElixirLite as any)({
7373
el: document.querySelector('#map2'),
7474
direction: 2,
75-
data: example2,
7675
draggable: false,
7776
// overflowHidden: true,
7877
nodeMenu: true,
7978
})
80-
mind2.init()
79+
mind2.init(example2)
8180
window.currentOperation = null
8281
mind.bus.addListener('operation', operation => {
8382
console.log(operation)

src/exampleData/1.cn.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ export default {
3737
id: 'c1f1e245b0a89f9b',
3838
},
3939
{
40-
topic: 'new MindElixir({...}).init()',
40+
topic: 'new MindElixir({...}).init(data)',
4141
id: 'c1f1ebc7072c8928',
4242
},
4343
],

src/exampleData/1.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export default {
2727
topic: "import MindElixir from 'mind-elixir'",
2828
id: 'c1f1e245b0a89f9b',
2929
},
30-
{ topic: 'new MindElixir({...}).init()', id: 'c1f1ebc7072c8928' },
30+
{ topic: 'new MindElixir({...}).init(data)', id: 'c1f1ebc7072c8928' },
3131
],
3232
},
3333
{

src/index.lite.ts

Lines changed: 63 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import {
2525
initSide,
2626
setLocale,
2727
expandNode,
28+
refresh,
2829
} from './interact'
2930
import {
3031
processPrimaryNode,
@@ -43,8 +44,6 @@ import mobileMenu from './plugin/mobileMenu'
4344
import Bus from './utils/pubsub'
4445

4546
import './index.less'
46-
import './plugin/toolBar.less'
47-
import './plugin/mobileMenu.less'
4847

4948
import './iconfont/iconfont.js'
5049

@@ -109,10 +108,20 @@ export interface MindElixirInstance {
109108
primaryNodeVerticalGap: number,
110109
mobileMenu: boolean,
111110

111+
container: HTMLElement,
112+
map: HTMLElement,
113+
root: HTMLElement,
114+
box: HTMLElement,
115+
svg2nd: SVGElement,
116+
linkController:SVGElement,
117+
P2: HTMLElement,
118+
P3: HTMLElement,
119+
line1:SVGElement,
120+
line2:SVGElement,
121+
linkSvgGroup:SVGElement,
112122
}
113123
export interface Options {
114124
el: string | Element,
115-
data: MindElixirData,
116125
direction?: number,
117126
locale?: string,
118127
draggable?: boolean,
@@ -134,7 +143,6 @@ export interface Options {
134143
const $d = document
135144
function MindElixir(this: MindElixirInstance, {
136145
el,
137-
data,
138146
direction,
139147
locale,
140148
draggable,
@@ -156,8 +164,6 @@ function MindElixir(this: MindElixirInstance, {
156164
}
157165
if (!box) return new Error('MindElixir: el is not a valid element')
158166
this.mindElixirBox = box
159-
this.nodeData = data.nodeData
160-
this.linkData = data.linkData || {}
161167
this.locale = locale
162168
this.toolBar = toolBar === undefined ? true : toolBar
163169
this.keypress = keypress === undefined ? true : keypress
@@ -194,6 +200,52 @@ function MindElixir(this: MindElixirInstance, {
194200
// console.log(operation, this.history)
195201
}
196202
})
203+
204+
console.log('ME_version ' + MindElixir.version)
205+
this.mindElixirBox.className += ' mind-elixir'
206+
this.mindElixirBox.innerHTML = ''
207+
208+
this.container = $d.createElement('div') // map container
209+
this.container.className = 'map-container'
210+
211+
if (this.overflowHidden) this.container.style.overflow = 'hidden'
212+
213+
this.map = $d.createElement('div') // map-canvas Element
214+
this.map.className = 'map-canvas'
215+
this.map.setAttribute('tabindex', '0')
216+
this.container.appendChild(this.map)
217+
this.mindElixirBox.appendChild(this.container)
218+
this.root = $d.createElement('root')
219+
220+
this.box = $d.createElement('children')
221+
this.box.className = 'box'
222+
223+
// infrastructure
224+
225+
this.svg2nd = createLinkSvg('svg2nd') // main link container
226+
227+
this.linkController = createLinkSvg('linkcontroller') // bezier controller container
228+
this.P2 = $d.createElement('div') // bezier P2
229+
this.P3 = $d.createElement('div') // bezier P3
230+
this.P2.className = this.P3.className = 'circle'
231+
this.line1 = createLine(0, 0, 0, 0) // bezier auxiliary line1
232+
this.line2 = createLine(0, 0, 0, 0) // bezier auxiliary line2
233+
this.linkController.appendChild(this.line1)
234+
this.linkController.appendChild(this.line2)
235+
236+
this.linkSvgGroup = createLinkSvg('topiclinks') // storage user custom link svg
237+
238+
this.map.appendChild(this.root)
239+
this.map.appendChild(this.box)
240+
this.map.appendChild(this.svg2nd)
241+
this.map.appendChild(this.linkController)
242+
this.map.appendChild(this.linkSvgGroup)
243+
this.map.appendChild(this.P2)
244+
this.map.appendChild(this.P3)
245+
246+
if (this.overflowHidden) {
247+
this.container.style.overflow = 'hidden'
248+
} else initMouseEvent(this)
197249
}
198250

199251
MindElixir.prototype = {
@@ -226,60 +278,11 @@ MindElixir.prototype = {
226278
initSide,
227279
setLocale,
228280
expandNode,
281+
refresh,
229282

230-
init: function() {
231-
/**
232-
* @function
233-
* @global
234-
* @name E
235-
* @param {string} id Node id.
236-
* @return {TargetElement} Target element.
237-
* @example
238-
* E('bd4313fbac40284b')
239-
*/
240-
addParentLink(this.nodeData)
241-
console.log('ME_version ' + MindElixir.version)
242-
this.mindElixirBox.className += ' mind-elixir'
243-
this.mindElixirBox.innerHTML = ''
244-
245-
this.container = $d.createElement('div') // map container
246-
this.container.className = 'map-container'
247-
248-
if (this.overflowHidden) this.container.style.overflow = 'hidden'
249-
250-
this.map = $d.createElement('div') // map-canvas Element
251-
this.map.className = 'map-canvas'
252-
this.map.setAttribute('tabindex', '0')
253-
this.container.appendChild(this.map)
254-
this.mindElixirBox.appendChild(this.container)
255-
this.root = $d.createElement('root')
256-
257-
this.box = $d.createElement('children')
258-
this.box.className = 'box'
259-
260-
// infrastructure
261-
262-
this.svg2nd = createLinkSvg('svg2nd') // main link container
263-
264-
this.linkController = createLinkSvg('linkcontroller') // bezier controller container
265-
this.P2 = $d.createElement('div') // bezier P2
266-
this.P3 = $d.createElement('div') // bezier P3
267-
this.P2.className = this.P3.className = 'circle'
268-
this.line1 = createLine(0, 0, 0, 0) // bezier auxiliary line1
269-
this.line2 = createLine(0, 0, 0, 0) // bezier auxiliary line2
270-
this.linkController.appendChild(this.line1)
271-
this.linkController.appendChild(this.line2)
272-
273-
this.linkSvgGroup = createLinkSvg('topiclinks') // storage user custom link svg
274-
275-
this.map.appendChild(this.root)
276-
this.map.appendChild(this.box)
277-
this.map.appendChild(this.svg2nd)
278-
this.map.appendChild(this.linkController)
279-
this.map.appendChild(this.linkSvgGroup)
280-
this.map.appendChild(this.P2)
281-
this.map.appendChild(this.P3)
282-
283+
init: function(data:MindElixirData) {
284+
this.nodeData = data.nodeData
285+
this.linkData = data.linkData || {}
283286
// plugin
284287
this.toolBar && toolBar(this)
285288

@@ -289,10 +292,10 @@ MindElixir.prototype = {
289292
this.contextMenu && contextMenu(this, this.contextMenuOption)
290293
}
291294

295+
addParentLink(this.nodeData)
292296
this.toCenter()
293297
this.layout()
294298
this.linkDiv()
295-
if (!this.overflowHidden) initMouseEvent(this)
296299
},
297300
}
298301

0 commit comments

Comments
 (0)