2022-08-24 19:59:08 +00:00
|
|
|
// https://stackoverflow.com/a/5767357/6090676
|
2022-08-24 16:38:47 +00:00
|
|
|
export function removeFirstInstanceOfItemFromArrayInPlace(arr, value) {
|
|
|
|
const index = arr.indexOf(value);
|
|
|
|
if (index > -1) {
|
|
|
|
arr.splice(index, 1);
|
|
|
|
}
|
|
|
|
return arr;
|
|
|
|
}
|
2022-09-27 21:40:12 +00:00
|
|
|
|
|
|
|
export function removeExtensionElementsIfEmpty(moddleElement) {
|
|
|
|
if (moddleElement.extensionElements.values.length < 1) {
|
|
|
|
moddleElement.extensionElements = null;
|
|
|
|
}
|
|
|
|
}
|
2023-06-28 16:48:44 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* loops up until it can find the root.
|
|
|
|
* @param element
|
|
|
|
*/
|
|
|
|
export function getRoot(businessObject, moddle) {
|
|
|
|
// HACK: get the root element. need a more formal way to do this
|
|
|
|
if (moddle) {
|
|
|
|
for (const elementId in moddle.ids._seed.hats) {
|
|
|
|
if (elementId.startsWith('Definitions_')) {
|
|
|
|
return moddle.ids._seed.hats[elementId];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
// todo: Do we want businessObject to be a shape or moddle object?
|
|
|
|
if (businessObject.$type === 'bpmn:Definitions') {
|
|
|
|
return businessObject;
|
|
|
|
}
|
|
|
|
if (typeof businessObject.$parent !== 'undefined') {
|
|
|
|
return getRoot(businessObject.$parent);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return businessObject;
|
|
|
|
}
|