11![ mindelixir logo] ( https://raw.githubusercontent.com/ssshooter/mind-elixir-core/master/logo.png )
22
33<p >
4- <a href =" https://www.npmjs.com/package/mind-elixir " ><img src =" https://img.shields.io/npm/v/mind-elixir " alt =" version " ></a >
4+ <a href =" https://www.npmjs.com/package/mind-elixir " >
5+ <img src="https://img.shields.io/npm/v/mind-elixir" alt="version">
6+ </a >
57 <img src =" https://img.shields.io/npm/l/mind-elixir " alt =" license " >
8+ <a href =" https://app.codacy.com/gh/ssshooter/mind-elixir-core?utm_source=github.com&utm_medium=referral&utm_content=ssshooter/mind-elixir-core&utm_campaign=Badge_Grade_Settings " >
9+ <img src="https://api.codacy.com/project/badge/Grade/09fadec5bf094886b30cea6aabf3a88b" alt="code quality">
10+ </a >
11+ <a href =" https://bundlephobia.com/result?p=mind-elixir " >
12+ <img src="https://badgen.net/bundlephobia/dependency-count/mind-elixir" alt="dependency-count">
13+ </a >
14+ <a href =" https://packagephobia.com/result?p=mind-elixir " >
15+ <img src="https://packagephobia.com/badge?p=mind-elixir" alt="dependency-count">
16+ </a >
617</p >
718
8- Mind elixir 是一个免费开源的思维导图内核
19+ Mind elixir 是一个无框架依赖的思维导图内核
920
10- ## 立即试用
21+ [ English ] ( https://github.com/ssshooter/mind-elixir-core/blob/master/readme.md )
1122
12- ![ mindelixir] ( https://raw.githubusercontent.com/ssshooter/mind-elixir-core/master/screenshot.cn.png )
23+ ## 立即尝试
24+
25+ ![ mindelixir] ( https://raw.githubusercontent.com/ssshooter/mind-elixir-core/master/screenshot.png )
1326
1427https://mindelixir.ink/#/
1528
16- ## 在项目中使用
29+ ### Playground
30+
31+ https://codepen.io/ssshooter/pen/GVQRYK
32+
33+ with React https://codesandbox.io/s/mind-elixir-react-9sisb
34+
35+ with Vue https://codesandbox.io/s/mind-elixir-vue-nqjjl
36+
37+ ## 如何使用
1738
1839### 安装
1940
@@ -27,7 +48,7 @@ npm i mind-elixir -S
2748import MindElixir , { E } from ' mind-elixir'
2849```
2950
30- #### script 标签引入
51+ #### Script 标签
3152
3253``` html
3354<script src =" https://cdn.jsdelivr.net/npm/mind-elixir/dist/mind-elixir.js" ></script >
@@ -36,9 +57,7 @@ import MindElixir, { E } from 'mind-elixir'
3657### HTML 结构
3758
3859``` html
39- <div class =" outer" >
40- <div id =" map" ></div >
41- </div >
60+ <div id =" map" ></div >
4261<style >
4362 #map {
4463 height : 500px ;
@@ -50,50 +69,145 @@ import MindElixir, { E } from 'mind-elixir'
5069### 初始化
5170
5271``` javascript
53- let mind = new MindElixir ({
72+ import MindElixir , { E } from ' mind-elixir'
73+ import { exportSvg , exportPng } from ' ../dist/painter'
74+ import example from ' ../dist/example1'
75+
76+ let options = {
5477 el: ' #map' ,
5578 direction: MindElixir .LEFT ,
56- // 创建新数据
57- data: MindElixir .new (' new topic' ),
58- // 也使用 getDataAll 得到的数据
59- data: {... },
60- draggable: true , // 启用拖动 default true
61- contextMenu: true , // 启用右键菜单 default true
62- toolBar: true , // 启用工具栏 default true
63- nodeMenu: true , // 启用节点菜单 default true
64- keypress: true , // 启用快捷键 default true
65- })
79+ // create new map data
80+ data: MindElixir .new (' new topic' ) or example,
81+ // the data return from `.getAllData()`
82+ draggable: true , // default true
83+ contextMenu: true , // default true
84+ toolBar: true , // default true
85+ nodeMenu: true , // default true
86+ keypress: true , // default true
87+ locale: ' en' , // [zh_CN,zh_TW,en,ja,pt] waiting for PRs
88+ overflowHidden: false , // default false
89+ primaryLinkStyle: 2 , // [1,2] default 1
90+ primaryNodeVerticalGap: 15 , // default 25
91+ primaryNodeHorizontalGap: 15 , // default 65
92+ contextMenuOption: {
93+ focus: true ,
94+ link: true ,
95+ extend: [
96+ {
97+ name: ' Node edit' ,
98+ onclick : () => {
99+ alert (' extend menu' )
100+ },
101+ },
102+ ],
103+ },
104+ allowUndo: false ,
105+ before: {
106+ insertSibling (el , obj ) {
107+ return true
108+ },
109+ async addChild (el , obj ) {
110+ await sleep ()
111+ return true
112+ },
113+ },
114+ }
115+
116+ let mind = new MindElixir (options)
66117mind .init ()
67118
68119// get a node
69120E (' node-id' )
121+
70122```
71123
72- ### Data Export
124+ ### 数据结构
73125
74126``` javascript
75- mind .getAllData ()
76- // see src/example.js
127+ // whole node data structure up to now
128+ {
129+ topic: ' node topic' ,
130+ id: ' bd1c24420cd2c2f5' ,
131+ style: { fontSize: ' 32' , color: ' #3298db' , background: ' #ecf0f1' },
132+ parent: null ,
133+ tags: [' Tag' ],
134+ icons: [' 😀' ],
135+ hyperLink: ' https://github.com/ssshooter/mind-elixir-core' ,
136+ }
77137```
78138
79- ## 使用提示
139+ ### 事件处理
80140
81- ### direction 选项
141+ ``` javascript
142+ mind .bus .addListener (' operation' , operation => {
143+ console .log (operation)
144+ // return {
145+ // name: action name,
146+ // obj: target object
147+ // }
148+
149+ // name: [insertSibling|addChild|removeNode|beginEdit|finishEdit]
150+ // obj: target
151+
152+ // name: moveNode
153+ // obj: {from:target1,to:target2}
154+ })
82155
83- direction 选项可选 ` MindElixir.LEFT ` 、` MindElixir.RIGHT ` 和 ` MindElixir.SIDE ` 。
156+ mind .bus .addListener (' selectNode' , node => {
157+ console .log (node)
158+ })
84159
85- ### HTML 结构
160+ mind .bus .addListener (' expandNode' , node => {
161+ console .log (' expandNode: ' , node)
162+ })
163+ ```
86164
87- 挂载的目标需要定宽高,可以是百分百;外层元素建议设置 ` position: relative; ` ,否则菜单位置以视窗为标准分布。
165+ ### 数据导出
88166
89- ### E 函数
167+ ``` javascript
168+ mind .getAllData () // javascript object, see src/example.js
169+ mind .getAllDataString () // stringify object
170+ mind .getAllDataMd () // markdown
171+ ```
90172
91- 在使用节点操作方法时需要传入的参数可以借助 ` E ` 函数获得。
173+ ### 输出图片
174+
175+ ** WIP**
92176
93177``` javascript
94- mind .insertSibling (E (' bd4313fbac40284b' ))
178+ import painter from ' mind-elixir/dist/painter'
179+ painter .exportSvg ()
180+ painter .exportPng ()
181+ ```
182+
183+ ### 操作拦截
184+
185+ ``` javascript
186+ let mind = new MindElixir ({
187+ ...
188+ before: {
189+ insertSibling (el , obj ) {
190+ console .log (el, obj)
191+ if (this .currentNode .nodeObj .parent .root ) {
192+ return false
193+ }
194+ return true
195+ },
196+ async addChild (el , obj ) {
197+ await sleep ()
198+ if (this .currentNode .nodeObj .parent .root ) {
199+ return false
200+ }
201+ return true
202+ },
203+ },
204+ })
95205```
96206
97207## 文档
98208
99- https://inspiring-golick-3c01b9.netlify.com/
209+ https://doc.mindelixir.ink/
210+
211+ ## 感谢
212+
213+ [ canvg] ( https://github.com/canvg/canvg )
0 commit comments