mirror of
https://github.com/sartography/bpmn-js.git
synced 2025-01-13 02:24:31 +00:00
d3449ca87c
* use ES6 import / export * UTILS: export individual utilities * TESTS: localize TestHelper includes BREAKING CHANGE: * all utilities export independent functions * library sources got ported to ES6. You must now use a ES module bundler such as Browserify + babelify or Webpack to consume this library (or parts of it).
46 lines
789 B
JavaScript
46 lines
789 B
JavaScript
'use strict';
|
|
|
|
import {
|
|
some
|
|
} from 'min-dash';
|
|
|
|
import { is } from '../../../util/ModelUtil';
|
|
|
|
|
|
/**
|
|
* Return true if element has any of the given types.
|
|
*
|
|
* @param {djs.model.Base} element
|
|
* @param {Array<String>} types
|
|
*
|
|
* @return {Boolean}
|
|
*/
|
|
export function isAny(element, types) {
|
|
return some(types, function(t) {
|
|
return is(element, t);
|
|
});
|
|
}
|
|
|
|
|
|
/**
|
|
* Return the parent of the element with any of the given types.
|
|
*
|
|
* @param {djs.model.Base} element
|
|
* @param {String|Array<String>} anyType
|
|
*
|
|
* @return {djs.model.Base}
|
|
*/
|
|
export function getParent(element, anyType) {
|
|
|
|
if (typeof anyType === 'string') {
|
|
anyType = [ anyType ];
|
|
}
|
|
|
|
while ((element = element.parent)) {
|
|
if (isAny(element, anyType)) {
|
|
return element;
|
|
}
|
|
}
|
|
|
|
return null;
|
|
} |