import handleOver from './handleOver' ; import handleDelete from './handleDelete' ; import { Layer } from '../types' ; const recombineTreeDataNew = ( data ) => { let currRecord = data [ data . length - 1 ] ; if ( data . length > 1 ) { let preLength = data . length ; for ( let i = 0 ; i < data . length - 1 ; i ++ ) { let record = data [ data . length - 2 - i ] ; if ( currRecord . parentId ) { if ( currRecord . parentId === record . id ) { if ( ! record . children ) { record . children = [ ] ; } record . children . unshift ( JSON . parse ( JSON . stringify ( currRecord ) ) ) ; data . length = data . length - 1 ; break ; } } else if ( isContain ( currRecord , record , data [ 0 ] ) ) { if ( ! record . children ) { record . children = [ ] ; } record . children . unshift ( JSON . parse ( JSON . stringify ( currRecord ) ) ) ; data . length = data . length - 1 ; break ; } } if ( preLength > data . length ) { recombineTreeDataNew ( data ) ; } } return data ; } ; const isContain = ( target , container , artboard ) => { if ( ! target || ! container ) { return false ; } if ( container . id === artboard . id ) { return true ; } if ( container . istransformContain ) { return false ; } if ( target . structure . x <= container . structure . x && target . structure . y <= container . structure . y && target . structure . x + target . structure . width >= container . structure . x + container . structure . width && target . structure . y + target . structure . height >= container . structure . y + container . structure . height && ! ( target . structure . x == container . structure . x && target . structure . y == container . structure . y && target . structure . x + target . structure . width == container . structure . x + container . structure . width && target . structure . y + target . structure . height == container . structure . y + container . structure . height ) ) { return false ; } let currTarget = JSON . parse ( JSON . stringify ( target ) ) ; let curr = handleOver ( currTarget , container ) ; let targetH = target . structure . height ; if ( artboard . structure . y + artboard . structure . height - target . structure . y < targetH ) { targetH = artboard . structure . y + artboard . structure . height - target . structure . y ; targetH = targetH < 0 ? 0 : targetH ; } if ( curr > target . structure . width * targetH * 0.3 ) { return true ; } return false ; } ; export default ( data , currIndex = { num : 0 } ) => { data = data . map ( ( item ) => { currIndex . num = currIndex . num + 1 ; item . structure . zIndex = currIndex . num ; return item ; } ) ; data = recombineTreeDataNew ( data ) ; data = handleDelete ( data ) ; return data ; } ;