AppendBehavior.js 979 B

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