|
5 | 5 | removeNodeObj, |
6 | 6 | insertNodeObj, |
7 | 7 | insertBeforeNodeObj, |
| 8 | + insertParentNodeObj, |
8 | 9 | checkMoveValid, |
9 | 10 | addParentLink, |
10 | 11 | moveUpObj, |
@@ -170,6 +171,46 @@ export const insertBefore = function(el, node) { |
170 | 171 | }) |
171 | 172 | } |
172 | 173 |
|
| 174 | +export const insertParent = function(el, node) { |
| 175 | + const nodeEle = el || this.currentNode |
| 176 | + if (!nodeEle) return |
| 177 | + const nodeObj = nodeEle.nodeObj |
| 178 | + if (nodeObj.root === true) { |
| 179 | + return |
| 180 | + } |
| 181 | + const newNodeObj = node || this.generateNewObj() |
| 182 | + insertParentNodeObj(nodeObj, newNodeObj) |
| 183 | + addParentLink(this.nodeData) |
| 184 | + const grp0 = nodeEle.parentElement.parentElement |
| 185 | + console.time('insertParent_DOM') |
| 186 | + const { grp, top } = this.createGroup(newNodeObj) |
| 187 | + // console.log(grp) |
| 188 | + const children = grp0.parentNode |
| 189 | + children.insertBefore(grp, grp0.nextSibling) |
| 190 | + |
| 191 | + // const c = $d.createElement('children') |
| 192 | + // c.appendChild(grp0) |
| 193 | + // top.appendChild(createExpander(true)) |
| 194 | + // top.parentElement.insertBefore(c, top.nextSibling) |
| 195 | + grp0.remove() |
| 196 | + if (children.className === 'box') { |
| 197 | + this.processPrimaryNode(grp, newNodeObj) |
| 198 | + this.linkDiv() |
| 199 | + } else { |
| 200 | + this.linkDiv(grp.offsetParent) |
| 201 | + } |
| 202 | + |
| 203 | + if (!node) { |
| 204 | + this.createInputDiv(top.children[0]) |
| 205 | + } |
| 206 | + this.selectNode(top.children[0], true) |
| 207 | + console.timeEnd('insertParent_DOM') |
| 208 | + this.bus.fire('operation', { |
| 209 | + name: 'insertParent', |
| 210 | + obj: newNodeObj, |
| 211 | + }) |
| 212 | +} |
| 213 | + |
173 | 214 | export const addChildFunction = function(nodeEle, node) { |
174 | 215 | if (!nodeEle) return |
175 | 216 | const nodeObj = nodeEle.nodeObj |
@@ -344,7 +385,9 @@ export const removeNode = function(el) { |
344 | 385 | // remove epd when children length === 0 |
345 | 386 | const parentT = t.parentNode.parentNode.previousSibling |
346 | 387 | // root doesn't have epd |
347 | | - if (parentT.tagName !== 'ROOT') { parentT.children[1].remove() } |
| 388 | + if (parentT.tagName !== 'ROOT') { |
| 389 | + parentT.children[1].remove() |
| 390 | + } |
348 | 391 | this.selectParent() |
349 | 392 | } else { |
350 | 393 | // select sibling automatically |
|
0 commit comments