UnclaimIdBehavior.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import inherits from 'inherits-browser';
  2. import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
  3. import { is } from '../../../util/ModelUtil';
  4. import { isExpanded } from '../../../util/DiUtil';
  5. import { isLabel } from '../../../util/LabelUtil';
  6. /**
  7. * @typedef {import('diagram-js/lib/core/Canvas').default} Canvas
  8. * @typedef {import('didi').Injector} Injector
  9. * @typedef {import('../Modeling').default} Modeling
  10. *
  11. * @typedef {import('../../../model/Types').Moddle} Moddle
  12. */
  13. /**
  14. * Unclaims model IDs on element deletion.
  15. *
  16. * @param {Canvas} canvas
  17. * @param {Injector} injector
  18. * @param {Moddle} moddle
  19. * @param {Modeling} modeling
  20. */
  21. export default function UnclaimIdBehavior(canvas, injector, moddle, modeling) {
  22. injector.invoke(CommandInterceptor, this);
  23. this.preExecute('shape.delete', function(event) {
  24. var context = event.context,
  25. shape = context.shape,
  26. shapeBo = shape.businessObject;
  27. if (isLabel(shape)) {
  28. return;
  29. }
  30. if (is(shape, 'bpmn:Participant') && isExpanded(shape)) {
  31. moddle.ids.unclaim(shapeBo.processRef.id);
  32. }
  33. modeling.unclaimId(shapeBo.id, shapeBo);
  34. });
  35. this.preExecute('connection.delete', function(event) {
  36. var context = event.context,
  37. connection = context.connection,
  38. connectionBo = connection.businessObject;
  39. modeling.unclaimId(connectionBo.id, connectionBo);
  40. });
  41. this.preExecute('canvas.updateRoot', function() {
  42. var rootElement = canvas.getRootElement(),
  43. rootElementBo = rootElement.businessObject;
  44. if (is(rootElement, 'bpmn:Collaboration')) {
  45. moddle.ids.unclaim(rootElementBo.id);
  46. }
  47. });
  48. }
  49. inherits(UnclaimIdBehavior, CommandInterceptor);
  50. UnclaimIdBehavior.$inject = [ 'canvas', 'injector', 'moddle', 'modeling' ];