Mind-elixir

Framework agnostic library to build mind maps

README

mindelixir logo

version license code quality dependency-count dependency-count



Mind elixir is a free open source mind map core.

- High performance
- Lightweight
- Framework agnostic
- Pluginable
- Build-in drag and drop / node edit plugin

Doc


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

Try now


mindelixir

https://mind-elixir.com/#/

Playground


https://codepen.io/ssshooter/pen/GVQRYK

with React https://codesandbox.io/s/mind-elixir-react-9sisb

with Vue https://codesandbox.io/s/mind-elixir-vue-nqjjl

Usage


Install


NPM


  1. ```bash
  2. npm i mind-elixir -S
  3. ```

  1. ```javascript
  2. import MindElixir, { E } from 'mind-elixir'
  3. ```

Script tag


  1. ```html
  2. <script src="https://cdn.jsdelivr.net/npm/mind-elixir/dist/MindElixir.js"></script>
  3. ```

HTML structure


  1. ```html
  2. <div id="map"></div>
  3. <style>
  4.   #map {
  5.     height: 500px;
  6.     width: 100%;
  7.   }
  8. </style>
  9. ```

Init


Breaking Change since 1.0.0, data should be passed to init(), not options.

  1. ```javascript
  2. import MindElixir, { E } from 'mind-elixir'
  3. import example from '../dist/example1'

  4. let options = {
  5.   el: '#map', // or HTMLDivElement
  6.   direction: MindElixir.LEFT,
  7.   draggable: true, // default true
  8.   contextMenu: true, // default true
  9.   toolBar: true, // default true
  10.   nodeMenu: true, // default true
  11.   keypress: true, // default true
  12.   locale: 'en', // [zh_CN,zh_TW,en,ja,pt] waiting for PRs
  13.   overflowHidden: false, // default false
  14.   primaryLinkStyle: 2, // [1,2] default 1
  15.   primaryNodeVerticalGap: 15, // default 25
  16.   primaryNodeHorizontalGap: 15, // default 65
  17.   contextMenuOption: {
  18.     focus: true,
  19.     link: true,
  20.     extend: [
  21.       {
  22.         name: 'Node edit',
  23.         onclick: () => {
  24.           alert('extend menu')
  25.         },
  26.       },
  27.     ],
  28.   },
  29.   allowUndo: false,
  30.   before: {
  31.     insertSibling(el, obj) {
  32.       return true
  33.     },
  34.     async addChild(el, obj) {
  35.       await sleep()
  36.       return true
  37.     },
  38.   },
  39. }

  40. let mind = new MindElixir(options)

  41. mind.install(plugin) // install your plugin

  42. // create new map data
  43. const data = MindElixir.new('new topic')
  44. // or `example`
  45. // or the data return from `.getAllData()`
  46. mind.init(data)

  47. // get a node
  48. E('node-id')
  49. ```

Data Structure


  1. ```javascript
  2. // whole node data structure up to now
  3. nodeData = {
  4.   topic: 'node topic',
  5.   id: 'bd1c24420cd2c2f5',
  6.   style: { fontSize: '32', color: '#3298db', background: '#ecf0f1' },
  7.   parent: null,
  8.   tags: ['Tag'],
  9.   icons: ['😀'],
  10.   hyperLink: 'https://github.com/ssshooter/mind-elixir-core',
  11.   children: [
  12.     {
  13.       topic: 'child',
  14.       id: 'xxxx',
  15.       // ...
  16.     },
  17.   ],
  18. }
  19. ```

Event Handling


  1. ```javascript
  2. mind.bus.addListener('operation', operation => {
  3.   console.log(operation)
  4.   // return {
  5.   //   name: action name,
  6.   //   obj: target object
  7.   // }

  8.   // name: [insertSibling|addChild|removeNode|beginEdit|finishEdit]
  9.   // obj: target

  10.   // name: moveNode
  11.   // obj: {from:target1,to:target2}
  12. })

  13. mind.bus.addListener('selectNode', node => {
  14.   console.log(node)
  15. })

  16. mind.bus.addListener('expandNode', node => {
  17.   console.log('expandNode: ', node)
  18. })
  19. ```

Data Export


  1. ```javascript
  2. mind.getAllData() // javascript object, see src/example.js
  3. mind.getAllDataString() // stringify object
  4. mind.getAllDataMd() // markdown
  5. ```

Operation Guards


  1. ```javascript
  2. let mind = new MindElixir({
  3.   // ...
  4.   before: {
  5.     insertSibling(el, obj) {
  6.       console.log(el, obj)
  7.       if (this.currentNode.nodeObj.parent.root) {
  8.         return false
  9.       }
  10.       return true
  11.     },
  12.     async addChild(el, obj) {
  13.       await sleep()
  14.       if (this.currentNode.nodeObj.parent.root) {
  15.         return false
  16.       }
  17.       return true
  18.     },
  19.   },
  20. })
  21. ```

Not only core