ModelingUtil.js 610 B

1234567891011121314151617181920212223242526272829303132
  1. import { isString } from 'min-dash';
  2. export { is, isAny } from '../../../util/ModelUtil';
  3. import { isAny } from '../../../util/ModelUtil';
  4. /**
  5. * @typedef {import('../../../model/Types').Element} Element
  6. */
  7. /**
  8. * Return the parent of the element with any of the given types.
  9. *
  10. * @param {Element} element
  11. * @param {string|string[]} anyType
  12. *
  13. * @return {Element|null}
  14. */
  15. export function getParent(element, anyType) {
  16. if (isString(anyType)) {
  17. anyType = [ anyType ];
  18. }
  19. while ((element = element.parent)) {
  20. if (isAny(element, anyType)) {
  21. return element;
  22. }
  23. }
  24. return null;
  25. }