all files / diagram-js/lib/util/ CopyPasteUtil.js

95% Statements 19/20
75% Branches 6/8
100% Functions 5/5
95% Lines 19/20
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43            28× 28× 28× 28×   28× 35×   35× 29×     35× 29×     35×     28× 29× 35×           28× 29×   29× 29×       28×  
import {
  forEach
} from 'min-dash';
 
 
export function getTopLevel(elements) {
  var topLevel = {},
      parents = [],
      result = [],
      clearedParents = [];
 
  forEach(elements, function(element) {
    var parent = element.parent;
 
    if (!topLevel[parent.id]) {
      topLevel[parent.id] = [];
    }
 
    if (parents.indexOf(parent.id) === -1) {
      parents.push(parent.id);
    }
 
    topLevel[parent.id].push(element);
  });
 
  forEach(parents, function(parent) {
    forEach(topLevel[parent], function(element) {
      Iif (topLevel[element.id]) {
        clearedParents.push(element.id);
      }
    });
  });
 
  forEach(parents, function(parent) {
    var idx = clearedParents.indexOf(parent);
 
    Eif (idx === -1) {
      result = result.concat(topLevel[parent]);
    }
  });
 
  return result;
}