ModelingUtil.js 774 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import {
  2. some
  3. } from 'min-dash';
  4. import { is } from '../../../util/ModelUtil';
  5. /**
  6. * Return true if element has any of the given types.
  7. *
  8. * @param {djs.model.Base} element
  9. * @param {Array<string>} types
  10. *
  11. * @return {boolean}
  12. */
  13. export function isAny(element, types) {
  14. return some(types, function(t) {
  15. return is(element, t);
  16. });
  17. }
  18. /**
  19. * Return the parent of the element with any of the given types.
  20. *
  21. * @param {djs.model.Base} element
  22. * @param {string|Array<string>} anyType
  23. *
  24. * @return {djs.model.Base}
  25. */
  26. export function getParent(element, anyType) {
  27. if (typeof anyType === 'string') {
  28. anyType = [ anyType ];
  29. }
  30. while ((element = element.parent)) {
  31. if (isAny(element, anyType)) {
  32. return element;
  33. }
  34. }
  35. return null;
  36. }