bpmn-js/lib/features/modeling/util/ModelingUtil.js

44 lines
774 B
JavaScript
Raw Normal View History

import {
some
} from 'min-dash';
import { is } from '../../../util/ModelUtil';
/**
2018-03-22 11:43:36 +00:00
* 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);
});
}
/**
2018-03-22 11:43:36 +00:00
* 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;
}