NonInterruptingBehavior.js 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
  2. import inherits from 'inherits-browser';
  3. import { canBeNonInterrupting, getInterruptingProperty } from './util/NonInterruptingUtil';
  4. import { getBusinessObject } from '../../../util/ModelUtil';
  5. export default function NonInterruptingBehavior(injector, modeling) {
  6. injector.invoke(CommandInterceptor, this);
  7. this.postExecuted('shape.replace', function(event) {
  8. const oldShape = event.context.oldShape;
  9. const newShape = event.context.newShape;
  10. const hints = event.context.hints;
  11. if (!canBeNonInterrupting(newShape)) {
  12. return;
  13. }
  14. const property = getInterruptingProperty(newShape);
  15. const isExplicitChange = hints.targetElement && hints.targetElement[property] !== undefined;
  16. if (isExplicitChange) {
  17. return;
  18. }
  19. const isOldInterrupting = getBusinessObject(oldShape).get(property);
  20. const isNewInterruptingDefault = getBusinessObject(newShape).get(property);
  21. if (isOldInterrupting === isNewInterruptingDefault) {
  22. return;
  23. }
  24. modeling.updateProperties(newShape, {
  25. [property]: isOldInterrupting
  26. });
  27. });
  28. }
  29. NonInterruptingBehavior.$inject = [ 'injector', 'modeling' ];
  30. inherits(NonInterruptingBehavior, CommandInterceptor);