BpmnDistributeElements.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import inherits from 'inherits-browser';
  2. import RuleProvider from 'diagram-js/lib/features/rules/RuleProvider';
  3. import { getParents } from 'diagram-js/lib/util/Elements';
  4. import {
  5. filter
  6. } from 'min-dash';
  7. import {
  8. isAny
  9. } from '../modeling/util/ModelingUtil';
  10. /**
  11. * @typedef {import('diagram-js/lib/core/EventBus').default} EventBus
  12. */
  13. /**
  14. * Registers element exclude filters for elements that currently do not support
  15. * distribution.
  16. *
  17. * @param {EventBus} eventBus
  18. */
  19. export default function BpmnDistributeElements(eventBus) {
  20. RuleProvider.call(this, eventBus);
  21. }
  22. BpmnDistributeElements.$inject = [ 'eventBus' ];
  23. inherits(BpmnDistributeElements, RuleProvider);
  24. BpmnDistributeElements.prototype.init = function() {
  25. this.addRule('elements.distribute', function(context) {
  26. var elements = context.elements;
  27. elements = filter(elements, function(element) {
  28. var cannotDistribute = isAny(element, [
  29. 'bpmn:Association',
  30. 'bpmn:BoundaryEvent',
  31. 'bpmn:DataInputAssociation',
  32. 'bpmn:DataOutputAssociation',
  33. 'bpmn:Lane',
  34. 'bpmn:MessageFlow',
  35. 'bpmn:SequenceFlow',
  36. 'bpmn:TextAnnotation'
  37. ]);
  38. return !(element.labelTarget || cannotDistribute);
  39. });
  40. // filter out elements which are children of any of the selected elements
  41. elements = getParents(elements);
  42. if (elements.length < 3) {
  43. return false;
  44. }
  45. return elements;
  46. });
  47. };