all files / Github/bpmn-js/lib/features/label-editing/ LabelUtil.js

100% Statements 23/23
96.3% Branches 26/27
100% Functions 4/4
100% Lines 23/23
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67      17410×                 16291×     1119× 16×     1103× 1095×         1082×   1082× 110×       972×       17276× 17276×   17276×   17268×   1082×     16186×           134× 134×   134×   134× 13×   121×         134×  
import { is } from '../../util/ModelUtil';
 
function getLabelAttr(semantic) {
  if (
    is(semantic, 'bpmn:FlowElement') ||
    is(semantic, 'bpmn:Participant') ||
    is(semantic, 'bpmn:Lane') ||
    is(semantic, 'bpmn:SequenceFlow') ||
    is(semantic, 'bpmn:MessageFlow') ||
    is(semantic, 'bpmn:DataInput') ||
    is(semantic, 'bpmn:DataOutput')
  ) {
    return 'name';
  }
 
  if (is(semantic, 'bpmn:TextAnnotation')) {
    return 'text';
  }
 
  if (is(semantic, 'bpmn:Group')) {
    return 'categoryValueRef';
  }
}
 
function getCategoryValue(semantic) {
  var categoryValueRef = semantic['categoryValueRef'];
 
  if (!categoryValueRef) {
    return '';
  }
 
 
  return categoryValueRef.value || '';
}
 
export function getLabel(element) {
  var semantic = element.businessObject,
      attr = getLabelAttr(semantic);
 
  if (attr) {
 
    if (attr === 'categoryValueRef') {
 
      return getCategoryValue(semantic);
    }
 
    return semantic[attr] || '';
  }
}
 
 
export function setLabel(element, text, isExternal) {
  var semantic = element.businessObject,
      attr = getLabelAttr(semantic);
 
  Eif (attr) {
 
    if (attr === 'categoryValueRef') {
      semantic['categoryValueRef'].value = text;
    } else {
      semantic[attr] = text;
    }
 
  }
 
  return element;
}