AppendBehavior.js 1001 B

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. import inherits from 'inherits-browser';
  2. import { is } from '../../../util/ModelUtil';
  3. import CommandInterceptor from 'diagram-js/lib/command/CommandInterceptor';
  4. /**
  5. * @typedef {import('diagram-js/lib/core/EventBus').default} EventBus
  6. */
  7. export default function AppendBehavior(eventBus) {
  8. CommandInterceptor.call(this, eventBus);
  9. // assign correct shape position unless already set
  10. this.preExecute('shape.append', function(context) {
  11. var source = context.source,
  12. shape = context.shape;
  13. if (!context.position) {
  14. if (is(shape, 'bpmn:TextAnnotation')) {
  15. context.position = {
  16. x: source.x + source.width / 2 + 75,
  17. y: source.y - 50 - shape.height / 2
  18. };
  19. } else {
  20. context.position = {
  21. x: source.x + source.width + 80 + shape.width / 2,
  22. y: source.y + source.height / 2
  23. };
  24. }
  25. }
  26. }, true);
  27. }
  28. inherits(AppendBehavior, CommandInterceptor);
  29. AppendBehavior.$inject = [
  30. 'eventBus'
  31. ];