Skip to content

Commit 49ac4f2

Browse files
committed
Yes we have markdown in our mindmap
http://i.imgur.com/tysJGT7.png Also fixed a layout bug in the pos calculation.
1 parent af67087 commit 49ac4f2

File tree

6 files changed

+74
-16
lines changed

6 files changed

+74
-16
lines changed

demo/mindmap/index.less

+5-1
Original file line numberDiff line numberDiff line change
@@ -85,9 +85,13 @@ body {
8585
border-color: magenta;
8686
}
8787

88+
&-editing {
89+
border-color: green;
90+
}
91+
8892
&_main {
8993
padding: 20px;
90-
width: 100px;
94+
width: 200px;
9195
}
9296

9397
&_children {

views/mindmap/actions.js

+25
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,28 @@ var movement = require('./movement')
55

66
module.exports = {
77

8+
createBefore: function (id) {
9+
id = id || this.view.active
10+
var node = this.db.nodes[id]
11+
, pos
12+
if (id === this.view.root) {
13+
pos = {
14+
pid: id,
15+
type: node.type,
16+
ix: 0
17+
}
18+
} else {
19+
pos = {
20+
pid: node.parent,
21+
type: node.type,
22+
ix: this.db.nodes[node.parent].children.indexOf(id),
23+
}
24+
}
25+
this.executeCommand('create', pos, (err, cmd) => {
26+
this.edit(cmd.id)
27+
})
28+
},
29+
830
createAfter: function (id, split, after) {
931
id = id || this.view.active
1032
var node = this.db.nodes[id]
@@ -42,6 +64,9 @@ module.exports = {
4264
}
4365
},
4466

67+
joinUp: function () {},
68+
removeEmpty: function () {},
69+
4570
moveDown: function (id) {
4671
id = id || this.view.active
4772
if (this.view.mode === 'visual') {

views/mindmap/calcpos.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11

2-
module.exports = function calcPos(root, nodes, xsep, ysep, heights) {
2+
module.exports = function calcPos(root, nodes, xsep, ysep, cellHeight, heights) {
33
var tree = crawl(root, nodes)
44

5-
var {boxes, height, width} = calcBoxes(tree, 100, xsep, 1, ysep)
5+
var {boxes, height, width} = calcBoxes(tree, cellHeight, xsep, 1, ysep)
66
var links = []
77
var rbox = boxes[root]
88
, rx = 0//rbox.x
@@ -69,8 +69,8 @@ function calcBoxes(data, cellHeight, xsep, pxscale, ysep) {
6969
var x = node.x * width
7070
, y = node.y * height
7171
boxes[node.id] = {
72-
x: y - node.width/2 * xs,
73-
y: x,
72+
x: y,
73+
y: x - node.width/2 * xs,
7474
height: node.width * xs,
7575
width: ys,
7676
}

views/mindmap/index.js

+24-9
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,30 @@ var Mindmap = React.createClass({
5858
var positions = calcPos(
5959
this.props.store.view.root,
6060
this.props.store.actions.db.nodes,
61+
20,
6162
100,
62-
100,
63+
200,
6364
this.state.heights);
6465
return positions
6566
},
6667

6768
render: function () {
6869
var positions = this.calcPositions()
70+
var bodies = {
71+
default: {editor: null, renderer: null}
72+
}
73+
if (this.props.nodePlugins) {
74+
for (var i=0; i<this.props.nodePlugins.length; i++) {
75+
if (this.props.nodePlugins[i].bodies) {
76+
bodies = extend(bodies, this.props.nodePlugins[i].bodies)
77+
}
78+
}
79+
}
6980
return <div className='Mindmap'>
7081
<Movable
7182
height={this.props.height}
7283
width={this.props.width}
84+
bodies={bodies}
7385
positions={positions}
7486
reCalc={this._reCalc}
7587
onHeight={this._onHeight}
@@ -100,7 +112,8 @@ var Movable = React.createClass({
100112
if (this.state.activeNode === state.activeNode) return
101113
var aid = state.activeNode
102114
, pos = props.positions.boxes[aid]
103-
, nx = this.state.left + pos.x
115+
if (!pos) return
116+
var nx = this.state.left + pos.x
104117
, ny = this.state.top + pos.y
105118
, margin = 100
106119
, dx = 0
@@ -111,16 +124,16 @@ var Movable = React.createClass({
111124
if (ny - margin < 0) {
112125
dy -= ny - margin
113126
}
114-
if (nx + pos.height + margin > this.props.width) {
115-
dx -= nx + pos.height + margin - this.props.width
127+
if (nx + pos.width + margin > this.props.width) {
128+
dx -= nx + pos.width + margin - this.props.width
116129
}
117-
if (ny + pos.width + margin > this.props.height) {
118-
dy -= ny + pos.width + margin - this.props.height
130+
if (ny + pos.height + margin > this.props.height) {
131+
dy -= ny + pos.height + margin - this.props.height
119132
}
120-
this.setState({
133+
return {
121134
left: this.state.left + dx,
122135
top: this.state.top + dy,
123-
})
136+
}
124137
},
125138
})
126139
],
@@ -129,7 +142,8 @@ var Movable = React.createClass({
129142
var aid = this.props.store.view.active
130143
, ppos = this.props.positions.boxes[aid]
131144
, npos = nextProps.positions.boxes[aid]
132-
, dx = ppos.x - npos.x
145+
if (!ppos || !npos) return
146+
var dx = ppos.x - npos.x
133147
, dy = ppos.y - npos.y
134148
, nx = this.state.left + dx + npos.x
135149
, ny = this.state.top + dy + npos.y
@@ -215,6 +229,7 @@ var Movable = React.createClass({
215229
onHeight={this.props.onHeight}
216230
positions={positions.boxes}
217231
plugins={this.props.nodePlugins}
232+
bodies={this.props.bodies}
218233
store={this.props.store}
219234
key={this.props.store.view.root}
220235
id={this.props.store.view.root}

views/mindmap/keys.js

+3
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,9 @@ module.exports = {
3434
'move down': {
3535
normal: 'shift+alt+down, shift+alt+j',
3636
},
37+
'create before': {
38+
normal: 'shift+o',
39+
},
3740
'create after': {
3841
normal: 'o',
3942
},

views/mindmap/node.js

+13-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
var React = require('react/addons')
22
, cx = React.addons.classSet
33
, PT = React.PropTypes
4+
, SimpleBody = require('../body/simple')
45

56
, Listener = require('../../listener')
67

@@ -86,11 +87,21 @@ var MindmapNode = React.createClass({
8687
'MindmapNode': true,
8788
'MindmapNode-hiding': this.props.hiding,
8889
'MindmapNode-active': this.state.isActive,
89-
'MindmapNode-collapsed': this.state.node.collapsed,
90+
'MindmapNode-editing': this.state.editState,
91+
'MindmapNode-collapsed': this.state.node.children && this.state.node.children.length && this.state.node.collapsed,
9092
})
93+
var body = this.props.bodies[this.state.node.type] || this.props.bodies['default']
9194
return <div style={style} className={cls}>
9295
<div onClick={this._onClick} className='MindmapNode_main'>
93-
{this.state.node.content}
96+
{SimpleBody({
97+
editor: body.editor,
98+
renderer: body.renderer,
99+
node: this.state.node,
100+
isActive: this.state.isActive,
101+
editState: this.state.editState,
102+
actions: this.props.store.actions,
103+
store: this.props.store,
104+
})}
94105
</div>
95106
{this.state.node.children.length ? <div className='MindmapNode_children'>
96107
{!this.state.lazyChildren && this.state.node.children.map((id, i) =>

0 commit comments

Comments
 (0)