mind-tree-editor
Advanced tools
Comparing version 0.2.1 to 0.2.2
@@ -100,3 +100,3 @@ import Menu from 'antd/es/menu'; | ||
{ | ||
name: '新增条件', | ||
name: '新增子条件', | ||
key: 'add-node', | ||
@@ -106,2 +106,7 @@ handler: editor.addNode.bind(editor) | ||
{ | ||
name: '新增条件', | ||
key: 'add-sibling', | ||
handler: editor.addSibling.bind(editor) | ||
}, | ||
{ | ||
name: '删除节点', | ||
@@ -1454,5 +1459,9 @@ key: 'delete-node', | ||
shortcuts: [{ | ||
keyCode: 13, | ||
handler: 'addSibling' | ||
}, // enter | ||
{ | ||
keyCode: [45, 9], | ||
handler: 'addNode' | ||
}, // insert tab | ||
}, // tab insert tab | ||
{ | ||
@@ -1581,2 +1590,31 @@ keyCode: 46, | ||
}, { | ||
key: "addSibling", | ||
value: function addSibling() { | ||
var _this3 = this; | ||
var shape = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'expand-node'; | ||
if (this.currentId) { | ||
var currentData = this.findDataById(this.currentId); | ||
var parent = currentData.parent; | ||
if (!parent) { | ||
this.addNode(shape); | ||
return; | ||
} | ||
var data = getNodeModule(shape).create({ | ||
parent: parent | ||
}); | ||
var siblings = this.findDataById(parent).children; | ||
var index = siblings.findIndex(function (v) { | ||
return v.id === _this3.currentId; | ||
}); | ||
siblings.splice(index + 1, 0, data); | ||
this.changeData(); | ||
this.setCurrent(data.id); | ||
this.editNode(); | ||
} | ||
} | ||
}, { | ||
key: "addNode", | ||
@@ -1694,3 +1732,3 @@ value: function addNode() { | ||
value: function _cloneNode(node, parent) { | ||
var _this3 = this; | ||
var _this4 = this; | ||
@@ -1704,3 +1742,3 @@ var result = _objectSpread({}, node, { | ||
result.children = result.children.map(function (v) { | ||
return _this3._cloneNode(v, result.id); | ||
return _this4._cloneNode(v, result.id); | ||
}); | ||
@@ -1714,3 +1752,3 @@ } | ||
value: function _bindForceEvent() { | ||
var _this4 = this; | ||
var _this5 = this; | ||
@@ -1725,3 +1763,3 @@ var timer; | ||
timer = setTimeout(function () { | ||
_this4.forceFit(); | ||
_this5.forceFit(); | ||
}, 200); | ||
@@ -1728,0 +1766,0 @@ }; |
@@ -108,3 +108,3 @@ 'use strict'; | ||
{ | ||
name: '新增条件', | ||
name: '新增子条件', | ||
key: 'add-node', | ||
@@ -114,2 +114,7 @@ handler: editor.addNode.bind(editor) | ||
{ | ||
name: '新增条件', | ||
key: 'add-sibling', | ||
handler: editor.addSibling.bind(editor) | ||
}, | ||
{ | ||
name: '删除节点', | ||
@@ -1462,5 +1467,9 @@ key: 'delete-node', | ||
shortcuts: [{ | ||
keyCode: 13, | ||
handler: 'addSibling' | ||
}, // enter | ||
{ | ||
keyCode: [45, 9], | ||
handler: 'addNode' | ||
}, // insert tab | ||
}, // tab insert tab | ||
{ | ||
@@ -1589,2 +1598,31 @@ keyCode: 46, | ||
}, { | ||
key: "addSibling", | ||
value: function addSibling() { | ||
var _this3 = this; | ||
var shape = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 'expand-node'; | ||
if (this.currentId) { | ||
var currentData = this.findDataById(this.currentId); | ||
var parent = currentData.parent; | ||
if (!parent) { | ||
this.addNode(shape); | ||
return; | ||
} | ||
var data = getNodeModule(shape).create({ | ||
parent: parent | ||
}); | ||
var siblings = this.findDataById(parent).children; | ||
var index = siblings.findIndex(function (v) { | ||
return v.id === _this3.currentId; | ||
}); | ||
siblings.splice(index + 1, 0, data); | ||
this.changeData(); | ||
this.setCurrent(data.id); | ||
this.editNode(); | ||
} | ||
} | ||
}, { | ||
key: "addNode", | ||
@@ -1702,3 +1740,3 @@ value: function addNode() { | ||
value: function _cloneNode(node, parent) { | ||
var _this3 = this; | ||
var _this4 = this; | ||
@@ -1712,3 +1750,3 @@ var result = _objectSpread({}, node, { | ||
result.children = result.children.map(function (v) { | ||
return _this3._cloneNode(v, result.id); | ||
return _this4._cloneNode(v, result.id); | ||
}); | ||
@@ -1722,3 +1760,3 @@ } | ||
value: function _bindForceEvent() { | ||
var _this4 = this; | ||
var _this5 = this; | ||
@@ -1733,3 +1771,3 @@ var timer; | ||
timer = setTimeout(function () { | ||
_this4.forceFit(); | ||
_this5.forceFit(); | ||
}, 200); | ||
@@ -1736,0 +1774,0 @@ }; |
{ | ||
"name": "mind-tree-editor", | ||
"version": "0.2.1", | ||
"version": "0.2.2", | ||
"description": "mind editor", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -27,3 +27,3 @@ import { OverlayMenuItem } from './components/OverlayMenu'; | ||
{ | ||
name: '新增条件', | ||
name: '新增子条件', | ||
key: 'add-node', | ||
@@ -33,2 +33,7 @@ handler: editor.addNode.bind(editor) | ||
{ | ||
name: '新增条件', | ||
key: 'add-sibling', | ||
handler: editor.addSibling.bind(editor) | ||
}, | ||
{ | ||
name: '删除节点', | ||
@@ -35,0 +40,0 @@ key: 'delete-node', |
@@ -70,3 +70,4 @@ /* eslint-disable class-methods-use-this */ | ||
shortcuts: [ | ||
{ keyCode: [45, 9], handler: 'addNode' }, // insert tab | ||
{ keyCode: 13, handler: 'addSibling' }, // enter | ||
{ keyCode: [45, 9], handler: 'addNode' }, // tab insert tab | ||
{ keyCode: 46, handler: 'deleteNode' }, // delete | ||
@@ -163,2 +164,20 @@ // { | ||
addSibling(shape = 'expand-node') { | ||
if (this.currentId) { | ||
const currentData = this.findDataById(this.currentId); | ||
const parent = currentData.parent; | ||
if (!parent) { | ||
this.addNode(shape); | ||
return; | ||
} | ||
const data = getNodeModule(shape).create({ parent }); | ||
const siblings = this.findDataById(parent).children; | ||
const index = siblings.findIndex(v => v.id === this.currentId); | ||
siblings.splice(index + 1, 0, data); | ||
this.changeData(); | ||
this.setCurrent(data.id); | ||
this.editNode(); | ||
} | ||
} | ||
addNode(shape = 'expand-node') { | ||
@@ -165,0 +184,0 @@ if (this.currentId) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
326060
4932