@@ -14,7 +14,7 @@ import {
1414 moveNodeBeforeObj ,
1515 moveNodeAfterObj ,
1616} from './utils/objectManipulation'
17- import { addChildDom , judgeDirection } from './utils/domManipulation'
17+ import { addChildDom , judgeDirection , removeNodeDom } from './utils/domManipulation'
1818
1919const mainToSub = function ( tpc : Topic ) {
2020 const mainNode = tpc . parentElement . parentElement
@@ -256,9 +256,9 @@ export const copyNode = function (this: MindElixirInstance, node: Topic, to: Top
256256export const moveUpNode = function ( this : MindElixirInstance , el ?: Topic ) {
257257 const nodeEle = el || this . currentNode
258258 if ( ! nodeEle ) return
259- const grp = nodeEle . parentNode . parentNode
260259 const obj = nodeEle . nodeObj
261260 moveUpObj ( obj )
261+ const grp = nodeEle . parentNode . parentNode
262262 grp . parentNode . insertBefore ( grp , grp . previousSibling )
263263 this . linkDiv ( )
264264 this . bus . fire ( 'operation' , {
@@ -280,9 +280,9 @@ export const moveUpNode = function (this: MindElixirInstance, el?: Topic) {
280280export const moveDownNode = function ( this : MindElixirInstance , el ?: Topic ) {
281281 const nodeEle = el || this . currentNode
282282 if ( ! nodeEle ) return
283- const grp = nodeEle . parentNode . parentNode
284283 const obj = nodeEle . nodeObj
285284 moveDownObj ( obj )
285+ const grp = nodeEle . parentNode . parentNode
286286 if ( grp . nextSibling ) {
287287 grp . nextSibling . insertAdjacentElement ( 'afterend' , grp )
288288 } else {
@@ -306,25 +306,17 @@ export const moveDownNode = function (this: MindElixirInstance, el?: Topic) {
306306 * removeNode(E('bd4313fbac40284b'))
307307 */
308308export const removeNode = function ( this : MindElixirInstance , el ?: Topic ) {
309- const nodeEle = el || this . currentNode
310- if ( ! nodeEle ) return
311- const nodeObj = nodeEle . nodeObj
309+ const tpc = el || this . currentNode
310+ if ( ! tpc ) return
311+ const nodeObj = tpc . nodeObj
312312 if ( nodeObj . root === true ) {
313313 throw new Error ( 'Can not remove root node' )
314314 }
315315 const siblings = nodeObj . parent ! . children !
316316 const i = siblings . findIndex ( node => node === nodeObj )
317317 const siblingLength = removeNodeObj ( nodeObj )
318+ removeNodeDom ( tpc , siblingLength )
318319
319- const t = nodeEle . parentNode
320- if ( siblingLength === 0 ) {
321- // remove epd when children length === 0
322- const c = t . parentNode . parentNode
323- // root doesn't have epd
324- if ( c . tagName !== 'ME-MAIN' ) {
325- c . previousSibling . children [ 1 ] . remove ( )
326- }
327- }
328320 // automatically select sibling or parent
329321 if ( siblings . length !== 0 ) {
330322 const sibling = siblings [ i ] || siblings [ i - 1 ]
@@ -333,7 +325,6 @@ export const removeNode = function (this: MindElixirInstance, el?: Topic) {
333325 this . selectNode ( findEle ( nodeObj . parent ! . id ) )
334326 }
335327
336- t . parentNode . remove ( )
337328 this . linkDiv ( )
338329 this . bus . fire ( 'operation' , {
339330 name : 'removeNode' ,
@@ -343,6 +334,21 @@ export const removeNode = function (this: MindElixirInstance, el?: Topic) {
343334 } )
344335}
345336
337+ export const removeNodes = function ( this : MindElixirInstance , tpcs : Topic [ ] ) {
338+ for ( const tpc of tpcs ) {
339+ const nodeObj = tpc . nodeObj
340+ if ( nodeObj . root === true ) {
341+ continue
342+ }
343+ const siblingLength = removeNodeObj ( nodeObj )
344+ removeNodeDom ( tpc , siblingLength )
345+ }
346+ this . linkDiv ( )
347+ this . bus . fire ( 'operation' , {
348+ name : 'removeNodes' ,
349+ objs : tpcs . map ( tpc => tpc . nodeObj ) ,
350+ } )
351+ }
346352/**
347353 * @function
348354 * @instance
0 commit comments