Du kannst nicht mehr als 25 Themen auswählen Themen müssen entweder mit einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

createSourceMonitor.js 3.5 KiB

vor 3 Jahren
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. 'use strict';
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
  6. exports.default = createSourceMonitor;
  7. var _invariant = require('invariant');
  8. var _invariant2 = _interopRequireDefault(_invariant);
  9. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  10. function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
  11. var isCallingCanDrag = false;
  12. var isCallingIsDragging = false;
  13. var SourceMonitor = function () {
  14. function SourceMonitor(manager) {
  15. _classCallCheck(this, SourceMonitor);
  16. this.internalMonitor = manager.getMonitor();
  17. }
  18. _createClass(SourceMonitor, [{
  19. key: 'receiveHandlerId',
  20. value: function receiveHandlerId(sourceId) {
  21. this.sourceId = sourceId;
  22. }
  23. }, {
  24. key: 'canDrag',
  25. value: function canDrag() {
  26. (0, _invariant2.default)(!isCallingCanDrag, 'You may not call monitor.canDrag() inside your canDrag() implementation. ' + 'Read more: http://react-dnd.github.io/react-dnd/docs-drag-source-monitor.html');
  27. try {
  28. isCallingCanDrag = true;
  29. return this.internalMonitor.canDragSource(this.sourceId);
  30. } finally {
  31. isCallingCanDrag = false;
  32. }
  33. }
  34. }, {
  35. key: 'isDragging',
  36. value: function isDragging() {
  37. (0, _invariant2.default)(!isCallingIsDragging, 'You may not call monitor.isDragging() inside your isDragging() implementation. ' + 'Read more: http://react-dnd.github.io/react-dnd/docs-drag-source-monitor.html');
  38. try {
  39. isCallingIsDragging = true;
  40. return this.internalMonitor.isDraggingSource(this.sourceId);
  41. } finally {
  42. isCallingIsDragging = false;
  43. }
  44. }
  45. }, {
  46. key: 'getItemType',
  47. value: function getItemType() {
  48. return this.internalMonitor.getItemType();
  49. }
  50. }, {
  51. key: 'getItem',
  52. value: function getItem() {
  53. return this.internalMonitor.getItem();
  54. }
  55. }, {
  56. key: 'getDropResult',
  57. value: function getDropResult() {
  58. return this.internalMonitor.getDropResult();
  59. }
  60. }, {
  61. key: 'didDrop',
  62. value: function didDrop() {
  63. return this.internalMonitor.didDrop();
  64. }
  65. }, {
  66. key: 'getInitialClientOffset',
  67. value: function getInitialClientOffset() {
  68. return this.internalMonitor.getInitialClientOffset();
  69. }
  70. }, {
  71. key: 'getInitialSourceClientOffset',
  72. value: function getInitialSourceClientOffset() {
  73. return this.internalMonitor.getInitialSourceClientOffset();
  74. }
  75. }, {
  76. key: 'getSourceClientOffset',
  77. value: function getSourceClientOffset() {
  78. return this.internalMonitor.getSourceClientOffset();
  79. }
  80. }, {
  81. key: 'getClientOffset',
  82. value: function getClientOffset() {
  83. return this.internalMonitor.getClientOffset();
  84. }
  85. }, {
  86. key: 'getDifferenceFromInitialOffset',
  87. value: function getDifferenceFromInitialOffset() {
  88. return this.internalMonitor.getDifferenceFromInitialOffset();
  89. }
  90. }]);
  91. return SourceMonitor;
  92. }();
  93. function createSourceMonitor(manager) {
  94. return new SourceMonitor(manager);
  95. }