You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 

89 lines
2.3 KiB

  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.default = createSourceConnector;
  6. var _wrapConnectorHooks = require('./wrapConnectorHooks');
  7. var _wrapConnectorHooks2 = _interopRequireDefault(_wrapConnectorHooks);
  8. var _areOptionsEqual = require('./areOptionsEqual');
  9. var _areOptionsEqual2 = _interopRequireDefault(_areOptionsEqual);
  10. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  11. function createSourceConnector(backend) {
  12. var currentHandlerId = void 0;
  13. var currentDragSourceNode = void 0;
  14. var currentDragSourceOptions = void 0;
  15. var disconnectCurrentDragSource = void 0;
  16. var currentDragPreviewNode = void 0;
  17. var currentDragPreviewOptions = void 0;
  18. var disconnectCurrentDragPreview = void 0;
  19. function reconnectDragSource() {
  20. if (disconnectCurrentDragSource) {
  21. disconnectCurrentDragSource();
  22. disconnectCurrentDragSource = null;
  23. }
  24. if (currentHandlerId && currentDragSourceNode) {
  25. disconnectCurrentDragSource = backend.connectDragSource(currentHandlerId, currentDragSourceNode, currentDragSourceOptions);
  26. }
  27. }
  28. function reconnectDragPreview() {
  29. if (disconnectCurrentDragPreview) {
  30. disconnectCurrentDragPreview();
  31. disconnectCurrentDragPreview = null;
  32. }
  33. if (currentHandlerId && currentDragPreviewNode) {
  34. disconnectCurrentDragPreview = backend.connectDragPreview(currentHandlerId, currentDragPreviewNode, currentDragPreviewOptions);
  35. }
  36. }
  37. function receiveHandlerId(handlerId) {
  38. if (handlerId === currentHandlerId) {
  39. return;
  40. }
  41. currentHandlerId = handlerId;
  42. reconnectDragSource();
  43. reconnectDragPreview();
  44. }
  45. var hooks = (0, _wrapConnectorHooks2.default)({
  46. dragSource: function connectDragSource(node, options) {
  47. if (node === currentDragSourceNode && (0, _areOptionsEqual2.default)(options, currentDragSourceOptions)) {
  48. return;
  49. }
  50. currentDragSourceNode = node;
  51. currentDragSourceOptions = options;
  52. reconnectDragSource();
  53. },
  54. dragPreview: function connectDragPreview(node, options) {
  55. if (node === currentDragPreviewNode && (0, _areOptionsEqual2.default)(options, currentDragPreviewOptions)) {
  56. return;
  57. }
  58. currentDragPreviewNode = node;
  59. currentDragPreviewOptions = options;
  60. reconnectDragPreview();
  61. }
  62. });
  63. return {
  64. receiveHandlerId: receiveHandlerId,
  65. hooks: hooks
  66. };
  67. }