drag up & down
This commit is contained in:
1 parent
b4e08f7108
commit
99d1a4570e
2 files changed
+24
-6
No files matched your search
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "behavior3editor",
|
"name": "behavior3editor",
|
||||||
"version": "0.0.2",
|
"version": "0.0.3",
|
||||||
"description": "行为树编辑器",
|
"description": "行为树编辑器",
|
||||||
"main": "./dist/main.js",
|
"main": "./dist/main.js",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|||||||
@@ -161,19 +161,37 @@ export default class Editor extends React.Component<EditorProps, EditorState> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Utils.findFromAllChildren(srcData, dstData.id)) {
|
||||||
|
// 不能将父节点拖到自已的子孙节点
|
||||||
|
console.log("cannot move to child");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
const removeSrc = () => {
|
const removeSrc = () => {
|
||||||
srcParent.children = srcParent.children.filter(e => e.id != srcData.id);
|
srcParent.children = srcParent.children.filter(e => e.id != srcData.id);
|
||||||
}
|
}
|
||||||
if (dstNode.hasState('dragRight')) {
|
if (dstNode.hasState('dragRight')) {
|
||||||
if(Utils.findFromAllChildren(srcData, dstData.id)) {
|
|
||||||
console.log("cannot move to child");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
removeSrc();
|
removeSrc();
|
||||||
if(!dstData.children) {
|
if (!dstData.children) {
|
||||||
dstData.children = [];
|
dstData.children = [];
|
||||||
}
|
}
|
||||||
dstData.children.push(srcData);
|
dstData.children.push(srcData);
|
||||||
|
} else if (dstNode.hasState('dragUp')) {
|
||||||
|
if (!dstParent) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
removeSrc();
|
||||||
|
const idx = dstParent.children.findIndex(e => e.id == dstData.id);
|
||||||
|
dstParent.children.splice(idx, 0, srcData);
|
||||||
|
} else if (dstNode.hasState('dragDown')) {
|
||||||
|
if (!dstParent) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
removeSrc();
|
||||||
|
const idx = dstParent.children.findIndex(e => e.id == dstData.id);
|
||||||
|
dstParent.children.splice(idx + 1, 0, srcData);
|
||||||
|
} else {
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
Utils.refreshNodeId(graph.findDataById('1'));
|
Utils.refreshNodeId(graph.findDataById('1'));
|
||||||
|
|||||||
Reference in new issue
Block a user