all files / lib/features/editor-actions/ BpmnEditorActions.js

61.54% Statements 24/39
41.67% Branches 5/12
68.75% Functions 11/16
61.54% Lines 24/39
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 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128                                              58×   58×         35×                                                                                                           28×                                              
import inherits from 'inherits';
 
import EditorActions from 'diagram-js/lib/features/editor-actions/EditorActions';
 
import { filter } from 'min-dash';
 
import { is } from '../../util/ModelUtil';
 
import {
  getBBox
} from 'diagram-js/lib/util/Elements';
 
 
/**
 * Registers and executes BPMN specific editor actions.
 */
export default function BpmnEditorActions(
    injector, canvas, elementRegistry,
    selection, spaceTool, lassoTool,
    handTool, globalConnect, distributeElements,
    alignElements, directEditing, searchPad,
    modeling) {
 
  injector.invoke(EditorActions, this);
 
  this.register({
    selectElements: function() {
      // select all elements except for the invisible
      // root element
      var rootElement = canvas.getRootElement();
 
      var elements = elementRegistry.filter(function(element) {
        return element !== rootElement;
      });
 
      selection.select(elements);
 
      return elements;
    },
    spaceTool: function() {
      spaceTool.toggle();
    },
    lassoTool: function() {
      lassoTool.toggle();
    },
    handTool: function() {
      handTool.toggle();
    },
    globalConnectTool: function() {
      globalConnect.toggle();
    },
    distributeElements: function(opts) {
      var currentSelection = selection.get(),
          type = opts.type;
 
      if (currentSelection.length) {
        distributeElements.trigger(currentSelection, type);
      }
    },
    alignElements: function(opts) {
      var currentSelection = selection.get(),
          aligneableElements = [],
          type = opts.type;
 
      if (currentSelection.length) {
        aligneableElements = filter(currentSelection, function(element) {
          return !is(element, 'bpmn:Lane');
        });
 
        alignElements.trigger(aligneableElements, type);
      }
    },
    setColor: function(opts) {
      var currentSelection = selection.get();
 
      if (currentSelection.length) {
        modeling.setColor(currentSelection, opts);
      }
    },
    directEditing: function() {
      var currentSelection = selection.get();
 
      Eif (currentSelection.length) {
        directEditing.activate(currentSelection[0]);
      }
    },
    find: function() {
      searchPad.toggle();
    },
    moveToOrigin: function() {
      var rootElement = canvas.getRootElement(),
          boundingBox,
          elements;
 
      if (is(rootElement, 'bpmn:Collaboration')) {
        elements = elementRegistry.filter(function(element) {
          return is(element.parent, 'bpmn:Collaboration');
        });
      } else {
        elements = elementRegistry.filter(function(element) {
          return element !== rootElement && !is(element.parent, 'bpmn:SubProcess');
        });
      }
 
      boundingBox = getBBox(elements);
 
      modeling.moveElements(elements, { x: -boundingBox.x, y: -boundingBox.y }, rootElement);
    }
  });
}
 
inherits(BpmnEditorActions, EditorActions);
 
BpmnEditorActions.$inject = [
  'injector',
  'canvas',
  'elementRegistry',
  'selection',
  'spaceTool',
  'lassoTool',
  'handTool',
  'globalConnect',
  'distributeElements',
  'alignElements',
  'directEditing',
  'searchPad',
  'modeling'
];