CreateConnectPreview.js 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. var LOW_PRIORITY = 740;
  2. /**
  3. * Shows connection preview during create.
  4. *
  5. * @param {EventBus} eventBus
  6. * @param {ConnectionPreview} connectionPreview
  7. */
  8. export default function CreateConnectPreview(injector, eventBus) {
  9. var connectionPreview = injector.get('connectionPreview', false);
  10. eventBus.on('create.move', LOW_PRIORITY, function(event) {
  11. var context = event.context,
  12. source = context.source,
  13. shape = context.shape,
  14. canExecute = context.canExecute,
  15. canConnect = canExecute && canExecute.connect;
  16. // don't draw connection preview if not appending a shape
  17. if (!connectionPreview || !source) {
  18. return;
  19. }
  20. // place shape's center on cursor
  21. shape.x = Math.round(event.x - shape.width / 2);
  22. shape.y = Math.round(event.y - shape.height / 2);
  23. connectionPreview.drawPreview(context, canConnect, {
  24. source: source,
  25. target: shape,
  26. waypoints: [],
  27. noNoop: true
  28. });
  29. });
  30. eventBus.on('create.cleanup', function(event) {
  31. if (connectionPreview) {
  32. connectionPreview.cleanUp(event.context);
  33. }
  34. });
  35. }
  36. CreateConnectPreview.$inject = [
  37. 'injector',
  38. 'eventBus'
  39. ];