@os-design/drag-sort 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (135) hide show
  1. package/LICENCE.md +1 -0
  2. package/README.md +15 -0
  3. package/dist/cjs/DragAndDrop.js +197 -0
  4. package/dist/cjs/DragAndDrop.js.map +1 -0
  5. package/dist/cjs/Draggable.js +97 -0
  6. package/dist/cjs/Draggable.js.map +1 -0
  7. package/dist/cjs/Droppable.js +112 -0
  8. package/dist/cjs/Droppable.js.map +1 -0
  9. package/dist/cjs/index.js +77 -0
  10. package/dist/cjs/index.js.map +1 -0
  11. package/dist/cjs/utils/ListStore.js +68 -0
  12. package/dist/cjs/utils/ListStore.js.map +1 -0
  13. package/dist/cjs/utils/NodeList.js +266 -0
  14. package/dist/cjs/utils/NodeList.js.map +1 -0
  15. package/dist/cjs/utils/getElementOffset.js +27 -0
  16. package/dist/cjs/utils/getElementOffset.js.map +1 -0
  17. package/dist/cjs/utils/getElementScroll.js +27 -0
  18. package/dist/cjs/utils/getElementScroll.js.map +1 -0
  19. package/dist/cjs/utils/getNodeRect.js +48 -0
  20. package/dist/cjs/utils/getNodeRect.js.map +1 -0
  21. package/dist/cjs/utils/useAppendClassName.js +27 -0
  22. package/dist/cjs/utils/useAppendClassName.js.map +1 -0
  23. package/dist/cjs/utils/useBlankNode.js +103 -0
  24. package/dist/cjs/utils/useBlankNode.js.map +1 -0
  25. package/dist/cjs/utils/useDragAndDrop.js +32 -0
  26. package/dist/cjs/utils/useDragAndDrop.js.map +1 -0
  27. package/dist/cjs/utils/useDragEffect.js +509 -0
  28. package/dist/cjs/utils/useDragEffect.js.map +1 -0
  29. package/dist/cjs/utils/useDroppable.js +35 -0
  30. package/dist/cjs/utils/useDroppable.js.map +1 -0
  31. package/dist/cjs/utils/useGeneratedId.js +22 -0
  32. package/dist/cjs/utils/useGeneratedId.js.map +1 -0
  33. package/dist/cjs/utils/useGetNodeStyle.js +28 -0
  34. package/dist/cjs/utils/useGetNodeStyle.js.map +1 -0
  35. package/dist/cjs/utils/useInitRect.js +25 -0
  36. package/dist/cjs/utils/useInitRect.js.map +1 -0
  37. package/dist/cjs/utils/useInitScrollOffset.js +27 -0
  38. package/dist/cjs/utils/useInitScrollOffset.js.map +1 -0
  39. package/dist/cjs/utils/useMoveNode.js +110 -0
  40. package/dist/cjs/utils/useMoveNode.js.map +1 -0
  41. package/dist/cjs/utils/useScrollEventByPoint.js +66 -0
  42. package/dist/cjs/utils/useScrollEventByPoint.js.map +1 -0
  43. package/dist/cjs/utils/useTargetList.js +58 -0
  44. package/dist/cjs/utils/useTargetList.js.map +1 -0
  45. package/dist/cjs/utils/useTransitionStyle.js +30 -0
  46. package/dist/cjs/utils/useTransitionStyle.js.map +1 -0
  47. package/dist/esm/DragAndDrop.js +139 -0
  48. package/dist/esm/DragAndDrop.js.map +1 -0
  49. package/dist/esm/Draggable.js +62 -0
  50. package/dist/esm/Draggable.js.map +1 -0
  51. package/dist/esm/Droppable.js +84 -0
  52. package/dist/esm/Droppable.js.map +1 -0
  53. package/dist/esm/index.js +7 -0
  54. package/dist/esm/index.js.map +1 -0
  55. package/dist/esm/utils/ListStore.js +46 -0
  56. package/dist/esm/utils/ListStore.js.map +1 -0
  57. package/dist/esm/utils/NodeList.js +207 -0
  58. package/dist/esm/utils/NodeList.js.map +1 -0
  59. package/dist/esm/utils/getElementOffset.js +19 -0
  60. package/dist/esm/utils/getElementOffset.js.map +1 -0
  61. package/dist/esm/utils/getElementScroll.js +19 -0
  62. package/dist/esm/utils/getElementScroll.js.map +1 -0
  63. package/dist/esm/utils/getNodeRect.js +36 -0
  64. package/dist/esm/utils/getNodeRect.js.map +1 -0
  65. package/dist/esm/utils/useAppendClassName.js +19 -0
  66. package/dist/esm/utils/useAppendClassName.js.map +1 -0
  67. package/dist/esm/utils/useBlankNode.js +81 -0
  68. package/dist/esm/utils/useBlankNode.js.map +1 -0
  69. package/dist/esm/utils/useDragAndDrop.js +13 -0
  70. package/dist/esm/utils/useDragAndDrop.js.map +1 -0
  71. package/dist/esm/utils/useDragEffect.js +417 -0
  72. package/dist/esm/utils/useDragEffect.js.map +1 -0
  73. package/dist/esm/utils/useDroppable.js +14 -0
  74. package/dist/esm/utils/useDroppable.js.map +1 -0
  75. package/dist/esm/utils/useGeneratedId.js +7 -0
  76. package/dist/esm/utils/useGeneratedId.js.map +1 -0
  77. package/dist/esm/utils/useGetNodeStyle.js +20 -0
  78. package/dist/esm/utils/useGetNodeStyle.js.map +1 -0
  79. package/dist/esm/utils/useInitRect.js +15 -0
  80. package/dist/esm/utils/useInitRect.js.map +1 -0
  81. package/dist/esm/utils/useInitScrollOffset.js +14 -0
  82. package/dist/esm/utils/useInitScrollOffset.js.map +1 -0
  83. package/dist/esm/utils/useMoveNode.js +62 -0
  84. package/dist/esm/utils/useMoveNode.js.map +1 -0
  85. package/dist/esm/utils/useScrollEventByPoint.js +53 -0
  86. package/dist/esm/utils/useScrollEventByPoint.js.map +1 -0
  87. package/dist/esm/utils/useTargetList.js +27 -0
  88. package/dist/esm/utils/useTargetList.js.map +1 -0
  89. package/dist/esm/utils/useTransitionStyle.js +24 -0
  90. package/dist/esm/utils/useTransitionStyle.js.map +1 -0
  91. package/dist/types/DragAndDrop.d.ts +16 -0
  92. package/dist/types/DragAndDrop.d.ts.map +1 -0
  93. package/dist/types/Draggable.d.ts +17 -0
  94. package/dist/types/Draggable.d.ts.map +1 -0
  95. package/dist/types/Droppable.d.ts +15 -0
  96. package/dist/types/Droppable.d.ts.map +1 -0
  97. package/dist/types/index.d.ts +7 -0
  98. package/dist/types/index.d.ts.map +1 -0
  99. package/dist/types/utils/ListStore.d.ts +10 -0
  100. package/dist/types/utils/ListStore.d.ts.map +1 -0
  101. package/dist/types/utils/NodeList.d.ts +42 -0
  102. package/dist/types/utils/NodeList.d.ts.map +1 -0
  103. package/dist/types/utils/getElementOffset.d.ts +6 -0
  104. package/dist/types/utils/getElementOffset.d.ts.map +1 -0
  105. package/dist/types/utils/getElementScroll.d.ts +6 -0
  106. package/dist/types/utils/getElementScroll.d.ts.map +1 -0
  107. package/dist/types/utils/getNodeRect.d.ts +9 -0
  108. package/dist/types/utils/getNodeRect.d.ts.map +1 -0
  109. package/dist/types/utils/useAppendClassName.d.ts +4 -0
  110. package/dist/types/utils/useAppendClassName.d.ts.map +1 -0
  111. package/dist/types/utils/useBlankNode.d.ts +14 -0
  112. package/dist/types/utils/useBlankNode.d.ts.map +1 -0
  113. package/dist/types/utils/useDragAndDrop.d.ts +20 -0
  114. package/dist/types/utils/useDragAndDrop.d.ts.map +1 -0
  115. package/dist/types/utils/useDragEffect.d.ts +23 -0
  116. package/dist/types/utils/useDragEffect.d.ts.map +1 -0
  117. package/dist/types/utils/useDroppable.d.ts +12 -0
  118. package/dist/types/utils/useDroppable.d.ts.map +1 -0
  119. package/dist/types/utils/useGeneratedId.d.ts +3 -0
  120. package/dist/types/utils/useGeneratedId.d.ts.map +1 -0
  121. package/dist/types/utils/useGetNodeStyle.d.ts +9 -0
  122. package/dist/types/utils/useGetNodeStyle.d.ts.map +1 -0
  123. package/dist/types/utils/useInitRect.d.ts +9 -0
  124. package/dist/types/utils/useInitRect.d.ts.map +1 -0
  125. package/dist/types/utils/useInitScrollOffset.d.ts +7 -0
  126. package/dist/types/utils/useInitScrollOffset.d.ts.map +1 -0
  127. package/dist/types/utils/useMoveNode.d.ts +15 -0
  128. package/dist/types/utils/useMoveNode.d.ts.map +1 -0
  129. package/dist/types/utils/useScrollEventByPoint.d.ts +7 -0
  130. package/dist/types/utils/useScrollEventByPoint.d.ts.map +1 -0
  131. package/dist/types/utils/useTargetList.d.ts +6 -0
  132. package/dist/types/utils/useTargetList.d.ts.map +1 -0
  133. package/dist/types/utils/useTransitionStyle.d.ts +8 -0
  134. package/dist/types/utils/useTransitionStyle.d.ts.map +1 -0
  135. package/package.json +49 -0
package/LICENCE.md ADDED
@@ -0,0 +1 @@
1
+ Copyright (c) 2019-present, Ilya Ordin, all rights reserved
package/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # @os-design/drag-sort [![NPM version](https://img.shields.io/npm/v/@os-design/drag-sort)](https://yarnpkg.com/package/@os-design/drag-sort) [![BundlePhobia](https://img.shields.io/bundlephobia/minzip/@os-design/drag-sort)](https://bundlephobia.com/result?p=@os-design/drag-sort)
2
+
3
+ Drag and drop for lists. Support dragging items between different lists.
4
+
5
+ ## Installation
6
+
7
+ Install the package using the following command:
8
+
9
+ ```
10
+ yarn add @os-design/drag-sort
11
+ ```
12
+
13
+ ---
14
+
15
+ See all the features in the [Storybook](https://os-team.gitlab.io/libs/os-design/).
@@ -0,0 +1,197 @@
1
+ "use strict";
2
+
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports["default"] = void 0;
9
+
10
+ var _react = _interopRequireWildcard(require("react"));
11
+
12
+ var _usePreventDefaultEvent = _interopRequireDefault(require("@os-design/use-prevent-default-event"));
13
+
14
+ var _useMemoObject = _interopRequireDefault(require("@os-design/use-memo-object"));
15
+
16
+ var _useDrag2 = _interopRequireDefault(require("@os-design/use-drag"));
17
+
18
+ var _portal = _interopRequireDefault(require("@os-design/portal"));
19
+
20
+ var _useAutoScroll = _interopRequireDefault(require("@os-design/use-auto-scroll"));
21
+
22
+ var _useDragAndDrop = require("./utils/useDragAndDrop");
23
+
24
+ var _ListStore = _interopRequireDefault(require("./utils/ListStore"));
25
+
26
+ var _useDragEffect = _interopRequireDefault(require("./utils/useDragEffect"));
27
+
28
+ var _useGeneratedId = _interopRequireDefault(require("./utils/useGeneratedId"));
29
+
30
+ var _useTransitionStyle = _interopRequireDefault(require("./utils/useTransitionStyle"));
31
+
32
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
33
+
34
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
35
+
36
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
37
+
38
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
39
+
40
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
41
+
42
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
43
+
44
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
45
+
46
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
47
+
48
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
49
+
50
+ /**
51
+ * The container containing one or more lists with draggable nodes.
52
+ */
53
+ var DragAndDrop = function DragAndDrop(_ref) {
54
+ var draggedNodeContainer = _ref.draggedNodeContainer,
55
+ _ref$minMouseDistPx = _ref.minMouseDistPx,
56
+ minMouseDistPx = _ref$minMouseDistPx === void 0 ? 10 : _ref$minMouseDistPx,
57
+ _ref$longPressMs = _ref.longPressMs,
58
+ longPressMs = _ref$longPressMs === void 0 ? 500 : _ref$longPressMs,
59
+ _ref$autoScrollDistPe = _ref.autoScrollDistPercent,
60
+ autoScrollDistPercent = _ref$autoScrollDistPe === void 0 ? 20 : _ref$autoScrollDistPe,
61
+ _ref$autoScrollMaxSpe = _ref.autoScrollMaxSpeedPx,
62
+ autoScrollMaxSpeedPx = _ref$autoScrollMaxSpe === void 0 ? 100 : _ref$autoScrollMaxSpe,
63
+ _ref$transitionDelayM = _ref.transitionDelayMs,
64
+ transitionDelayMs = _ref$transitionDelayM === void 0 ? 250 : _ref$transitionDelayM,
65
+ _ref$onDragEnd = _ref.onDragEnd,
66
+ onDragEnd = _ref$onDragEnd === void 0 ? function () {} : _ref$onDragEnd,
67
+ children = _ref.children;
68
+ // The user can drag a node between the lists (the Droppable components).
69
+ // To determine which list a node should be dropped in, we need to store refs to all the lists.
70
+ var listStoreRef = (0, _react.useRef)(new _ListStore["default"]()); // The class name for a node used to set the transition style
71
+
72
+ var generatedId = (0, _useGeneratedId["default"])(4);
73
+ var nodeClassName = (0, _react.useMemo)(function () {
74
+ return "n".concat(generatedId);
75
+ }, [generatedId]); // The node that is currently being dragged
76
+
77
+ var _useState = (0, _react.useState)(null),
78
+ _useState2 = _slicedToArray(_useState, 2),
79
+ draggedNode = _useState2[0],
80
+ setDraggedNode = _useState2[1];
81
+
82
+ var startNodeRef = (0, _react.useRef)(null);
83
+
84
+ var _useState3 = (0, _react.useState)({
85
+ x: 0,
86
+ y: 0
87
+ }),
88
+ _useState4 = _slicedToArray(_useState3, 2),
89
+ cursorPosition = _useState4[0],
90
+ setCursorPosition = _useState4[1]; // Add a new list to the store
91
+
92
+
93
+ var registerList = (0, _react.useCallback)(function (list) {
94
+ listStoreRef.current.add(list);
95
+ }, []); // Remove the existing list from the store
96
+
97
+ var deregisterList = (0, _react.useCallback)(function (id) {
98
+ listStoreRef.current.remove(id);
99
+ }, []); // Set the style to delay transitions when the node is dragging
100
+
101
+ (0, _useTransitionStyle["default"])({
102
+ className: nodeClassName,
103
+ ms: transitionDelayMs,
104
+ enabled: !!draggedNode
105
+ });
106
+ var onDragStart = (0, _react.useCallback)(function (pos, startPos) {
107
+ var startNode = startNodeRef.current;
108
+ if (!startNode) return;
109
+
110
+ var _startNode$node = _slicedToArray(startNode.node, 3),
111
+ nodeRef = _startNode$node[2];
112
+
113
+ if (!nodeRef.current) return;
114
+ var rect = nodeRef.current.getBoundingClientRect();
115
+ setCursorPosition(pos);
116
+ setDraggedNode({
117
+ list: startNode.list,
118
+ node: startNode.node,
119
+ position: {
120
+ x: startPos.x - rect.x,
121
+ y: startPos.y - rect.y
122
+ }
123
+ });
124
+ startNodeRef.current = null;
125
+ }, []);
126
+ var onDragMove = (0, _react.useCallback)(function (pos) {
127
+ setCursorPosition(pos);
128
+ }, []);
129
+ var dragEndHandler = (0, _react.useCallback)(function () {
130
+ setDraggedNode(null);
131
+ }, []);
132
+
133
+ var _useDrag = (0, _useDrag2["default"])({
134
+ onDragStart: onDragStart,
135
+ onDragMove: onDragMove,
136
+ onDragEnd: dragEndHandler,
137
+ minMouseDistPx: minMouseDistPx,
138
+ longPressMs: longPressMs
139
+ }),
140
+ onMouseDown = _useDrag.onMouseDown,
141
+ onTouchStart = _useDrag.onTouchStart; // Handlers that determine whether a user clicks on the node
142
+
143
+
144
+ var mouseDownHandler = (0, _react.useCallback)(function (e, list, node) {
145
+ startNodeRef.current = {
146
+ list: list,
147
+ node: node
148
+ };
149
+ onMouseDown(e);
150
+ }, [onMouseDown]);
151
+ var touchStartHandler = (0, _react.useCallback)(function (e, list, node) {
152
+ startNodeRef.current = {
153
+ list: list,
154
+ node: node
155
+ };
156
+ onTouchStart(e);
157
+ }, [onTouchStart]); // Prevent body scrolling when the node is dragging.
158
+ // It's important to attach the event to the body (not to the document). Otherwise, it won't work in mobile chrome.
159
+
160
+ (0, _usePreventDefaultEvent["default"])(document.body, 'touchmove', !!draggedNode); // Implement the drag animation
161
+
162
+ (0, _useDragEffect["default"])({
163
+ draggedNode: draggedNode,
164
+ cursorPosition: cursorPosition,
165
+ listStoreRef: listStoreRef,
166
+ onDragEnd: onDragEnd
167
+ }); // Auto scroll if the cursor position is located near the border
168
+
169
+ (0, _useAutoScroll["default"])({
170
+ enabled: !!draggedNode,
171
+ distPercent: autoScrollDistPercent,
172
+ maxSpeedPx: autoScrollMaxSpeedPx
173
+ });
174
+ var dragAndDropContext = (0, _useMemoObject["default"])({
175
+ registerList: registerList,
176
+ deregisterList: deregisterList,
177
+ onMouseDown: mouseDownHandler,
178
+ onTouchStart: touchStartHandler,
179
+ nodeClassName: nodeClassName
180
+ });
181
+ return /*#__PURE__*/_react["default"].createElement(_useDragAndDrop.DragAndDropContext.Provider, {
182
+ value: dragAndDropContext
183
+ }, children, draggedNode && /*#__PURE__*/_react["default"].createElement(_portal["default"], {
184
+ container: draggedNodeContainer
185
+ }, draggedNode.list.renderDraggedNode({
186
+ index: draggedNode.node[4],
187
+ style: {
188
+ position: 'fixed',
189
+ left: cursorPosition.x - draggedNode.position.x,
190
+ top: cursorPosition.y - draggedNode.position.y
191
+ }
192
+ })));
193
+ };
194
+
195
+ var _default = DragAndDrop;
196
+ exports["default"] = _default;
197
+ //# sourceMappingURL=DragAndDrop.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/DragAndDrop.tsx"],"names":["DragAndDrop","draggedNodeContainer","minMouseDistPx","longPressMs","autoScrollDistPercent","autoScrollMaxSpeedPx","transitionDelayMs","onDragEnd","children","listStoreRef","ListStore","generatedId","nodeClassName","draggedNode","setDraggedNode","startNodeRef","x","y","cursorPosition","setCursorPosition","registerList","list","current","add","deregisterList","id","remove","className","ms","enabled","onDragStart","pos","startPos","startNode","node","nodeRef","rect","getBoundingClientRect","position","onDragMove","dragEndHandler","onMouseDown","onTouchStart","mouseDownHandler","e","touchStartHandler","document","body","distPercent","maxSpeedPx","dragAndDropContext","renderDraggedNode","index","style","left","top"],"mappings":";;;;;;;;;AAAA;;AAQA;;AACA;;AACA;;AAMA;;AACA;;AACA;;AACA;;AAEA;;AAIA;;AACA;;;;;;;;;;;;;;;;;;;;AA6CA;AACA;AACA;AACA,IAAMA,WAAuC,GAAG,SAA1CA,WAA0C,OAS1C;AAAA,MARJC,oBAQI,QARJA,oBAQI;AAAA,iCAPJC,cAOI;AAAA,MAPJA,cAOI,oCAPa,EAOb;AAAA,8BANJC,WAMI;AAAA,MANJA,WAMI,iCANU,GAMV;AAAA,mCALJC,qBAKI;AAAA,MALJA,qBAKI,sCALoB,EAKpB;AAAA,mCAJJC,oBAII;AAAA,MAJJA,oBAII,sCAJmB,GAInB;AAAA,mCAHJC,iBAGI;AAAA,MAHJA,iBAGI,sCAHgB,GAGhB;AAAA,4BAFJC,SAEI;AAAA,MAFJA,SAEI,+BAFQ,YAAM,CAAE,CAEhB;AAAA,MADJC,QACI,QADJA,QACI;AACJ;AACA;AACA,MAAMC,YAAY,GAAG,mBAAkB,IAAIC,qBAAJ,EAAlB,CAArB,CAHI,CAKJ;;AAC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AAiB,CAAjB,CAD2B;AAElCmB,IAAAA,KAAK,EAAE;AACLf,MAAAA,QAAQ,EAAE,OADL;AAELgB,MAAAA,IAAI,EAAEpC,cAAc,CAACF,CAAf,GAAmBH,WAAW,CAACyB,QAAZ,CAAqBtB,CAFzC;AAGLuC,MAAAA,GAAG,EAAErC,cAAc,CAACD,CAAf,GAAmBJ,WAAW,CAACyB,QAAZ,CAAqBrB;AAHxC;AAF2B,GAAnC,CADH,CAJJ,CADF;AAkBD,CA7ID;;eAiJejB,W","sourcesContent":["import React, {\n useCallback,\n useMemo,\n useRef,\n useState,\n MouseEvent,\n TouchEvent,\n} from 'react';\nimport usePreventDefaultEvent from '@os-design/use-prevent-default-event';\nimport useMemoObject from '@os-design/use-memo-object';\nimport useDrag, {\n Position,\n OnDragEnd,\n OnDragMove,\n OnDragStart,\n} from '@os-design/use-drag';\nimport Portal, { PortalProps } from '@os-design/portal';\nimport useAutoScroll from '@os-design/use-auto-scroll';\nimport { DragAndDropContext } from './utils/useDragAndDrop';\nimport ListStore from './utils/ListStore';\nimport NodeList, { ExistingNode } from './utils/NodeList';\nimport useDragEffect, {\n DragEndHandler,\n DraggedNode,\n} from './utils/useDragEffect';\nimport useGeneratedId from './utils/useGeneratedId';\nimport useTransitionStyle from './utils/useTransitionStyle';\n\nexport interface DragAndDropProps {\n /**\n * The container in which the dragged node will be rendered.\n * @default document.body\n */\n draggedNodeContainer?: PortalProps['container'];\n /**\n * The min distance required to start dragging a node (in px).\n * @default 10\n */\n minMouseDistPx?: number;\n /**\n * The delay of the long press event required to start dragging a node on the touch device (in ms).\n * @default 500\n */\n longPressMs?: number;\n /**\n * The distance to the bound at which the list starts to scroll automatically (in percent).\n * @default 20\n */\n autoScrollDistPercent?: number;\n /**\n * The max auto scroll speed (in px).\n * @default 100\n */\n autoScrollMaxSpeedPx?: number;\n /**\n * The animation duration (in ms).\n * @default 250\n */\n transitionDelayMs?: number;\n /**\n * The callback that is called when the drag is completed.\n * @default undefined\n */\n onDragEnd?: DragEndHandler;\n}\n\ninterface StartNode {\n list: NodeList;\n node: ExistingNode;\n}\n\n/**\n * The container containing one or more lists with draggable nodes.\n */\nconst DragAndDrop: React.FC<DragAndDropProps> = ({\n draggedNodeContainer,\n minMouseDistPx = 10,\n longPressMs = 500,\n autoScrollDistPercent = 20,\n autoScrollMaxSpeedPx = 100,\n transitionDelayMs = 250,\n onDragEnd = () => {},\n children,\n}) => {\n // The user can drag a node between the lists (the Droppable components).\n // To determine which list a node should be dropped in, we need to store refs to all the lists.\n const listStoreRef = useRef<ListStore>(new ListStore());\n\n // The class name for a node used to set the transition style\n const generatedId = useGeneratedId(4);\n const nodeClassName = useMemo(() => `n${generatedId}`, [generatedId]);\n\n // The node that is currently being dragged\n const [draggedNode, setDraggedNode] = useState<DraggedNode | null>(null);\n const startNodeRef = useRef<StartNode | null>(null);\n const [cursorPosition, setCursorPosition] = useState<Position>({\n x: 0,\n y: 0,\n });\n\n // Add a new list to the store\n const registerList = useCallback((list: NodeList) => {\n listStoreRef.current.add(list);\n }, []);\n\n // Remove the existing list from the store\n const deregisterList = useCallback((id: string) => {\n listStoreRef.current.remove(id);\n }, []);\n\n // Set the style to delay transitions when the node is dragging\n useTransitionStyle({\n className: nodeClassName,\n ms: transitionDelayMs,\n enabled: !!draggedNode,\n });\n\n const onDragStart = useCallback<OnDragStart>(\n (pos: Position, startPos: Position) => {\n const startNode = startNodeRef.current;\n if (!startNode) return;\n const [, , nodeRef] = startNode.node;\n if (!nodeRef.current) return;\n const rect = nodeRef.current.getBoundingClientRect();\n setCursorPosition(pos);\n setDraggedNode({\n list: startNode.list,\n node: startNode.node,\n position: {\n x: startPos.x - rect.x,\n y: startPos.y - rect.y,\n },\n });\n startNodeRef.current = null;\n },\n []\n );\n\n const onDragMove = useCallback<OnDragMove>((pos: Position) => {\n setCursorPosition(pos);\n }, []);\n\n const dragEndHandler = useCallback<OnDragEnd>(() => {\n setDraggedNode(null);\n }, []);\n\n const { onMouseDown, onTouchStart } = useDrag({\n onDragStart,\n onDragMove,\n onDragEnd: dragEndHandler,\n minMouseDistPx,\n longPressMs,\n });\n\n // Handlers that determine whether a user clicks on the node\n const mouseDownHandler = useCallback(\n (e: MouseEvent, list: NodeList, node: ExistingNode) => {\n startNodeRef.current = { list, node };\n onMouseDown(e);\n },\n [onMouseDown]\n );\n const touchStartHandler = useCallback(\n (e: TouchEvent, list: NodeList, node: ExistingNode) => {\n startNodeRef.current = { list, node };\n onTouchStart(e);\n },\n [onTouchStart]\n );\n\n // Prevent body scrolling when the node is dragging.\n // It's important to attach the event to the body (not to the document). Otherwise, it won't work in mobile chrome.\n usePreventDefaultEvent(document.body, 'touchmove', !!draggedNode);\n\n // Implement the drag animation\n useDragEffect({\n draggedNode,\n cursorPosition,\n listStoreRef,\n onDragEnd,\n });\n\n // Auto scroll if the cursor position is located near the border\n useAutoScroll({\n enabled: !!draggedNode,\n distPercent: autoScrollDistPercent,\n maxSpeedPx: autoScrollMaxSpeedPx,\n });\n\n const dragAndDropContext = useMemoObject({\n registerList,\n deregisterList,\n onMouseDown: mouseDownHandler,\n onTouchStart: touchStartHandler,\n nodeClassName,\n });\n\n return (\n <DragAndDropContext.Provider value={dragAndDropContext}>\n {children}\n\n {draggedNode && (\n <Portal container={draggedNodeContainer}>\n {draggedNode.list.renderDraggedNode({\n index: draggedNode.node[4],\n style: {\n position: 'fixed',\n left: cursorPosition.x - draggedNode.position.x,\n top: cursorPosition.y - draggedNode.position.y,\n },\n })}\n </Portal>\n )}\n </DragAndDropContext.Provider>\n );\n};\n\nexport type { DragEndHandler } from './utils/useDragEffect';\n\nexport default DragAndDrop;\n"],"file":"DragAndDrop.js"}
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports["default"] = void 0;
9
+
10
+ var _react = _interopRequireWildcard(require("react"));
11
+
12
+ var _useMemoObject = _interopRequireDefault(require("@os-design/use-memo-object"));
13
+
14
+ var _useDroppable2 = _interopRequireDefault(require("./utils/useDroppable"));
15
+
16
+ var _useDragAndDrop2 = _interopRequireDefault(require("./utils/useDragAndDrop"));
17
+
18
+ var _useAppendClassName = _interopRequireDefault(require("./utils/useAppendClassName"));
19
+
20
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
21
+
22
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
23
+
24
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
25
+
26
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
27
+
28
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
29
+
30
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
31
+
32
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
33
+
34
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
35
+
36
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
37
+
38
+ var Draggable = function Draggable(_ref) {
39
+ var index = _ref.index,
40
+ children = _ref.children;
41
+ // The reference to the list item
42
+ var ref = (0, _react.useRef)(null); // The reference to the node containing the refs to the prev and next nodes
43
+
44
+ var nodeRef = (0, _react.useRef)(null); // Additional styles for moving the list item
45
+
46
+ var _useState = (0, _react.useState)({}),
47
+ _useState2 = _slicedToArray(_useState, 2),
48
+ style = _useState2[0],
49
+ setStyle = _useState2[1];
50
+
51
+ var _useDragAndDrop = (0, _useDragAndDrop2["default"])(),
52
+ nodeClassName = _useDragAndDrop.nodeClassName;
53
+
54
+ var _useDroppable = (0, _useDroppable2["default"])(),
55
+ registerNode = _useDroppable.registerNode,
56
+ deregisterNode = _useDroppable.deregisterNode,
57
+ onMouseDown = _useDroppable.onMouseDown,
58
+ onTouchStart = _useDroppable.onTouchStart; // Register the node in the list
59
+
60
+
61
+ (0, _react.useEffect)(function () {
62
+ nodeRef.current = registerNode({
63
+ ref: ref,
64
+ setStyle: setStyle,
65
+ index: index
66
+ });
67
+ return function () {
68
+ if (!nodeRef.current) return;
69
+ deregisterNode(nodeRef.current);
70
+ nodeRef.current = null;
71
+ };
72
+ }, [deregisterNode, index, registerNode]); // Set the class name for the node to apply the transition style (see the DragAndDrop container)
73
+
74
+ (0, _useAppendClassName["default"])(ref, nodeClassName); // Handlers that determine whether a user clicks on the node
75
+
76
+ var mouseDownHandler = (0, _react.useCallback)(function (e) {
77
+ if (!nodeRef.current) return;
78
+ onMouseDown(e, nodeRef.current);
79
+ }, [onMouseDown]);
80
+ var touchStartHandler = (0, _react.useCallback)(function (e) {
81
+ if (!nodeRef.current) return;
82
+ onTouchStart(e, nodeRef.current);
83
+ }, [onTouchStart]);
84
+ var handlers = (0, _useMemoObject["default"])({
85
+ onMouseDown: mouseDownHandler,
86
+ onTouchStart: touchStartHandler
87
+ });
88
+ return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, null, children({
89
+ ref: ref,
90
+ style: style,
91
+ handlers: handlers
92
+ }));
93
+ };
94
+
95
+ var _default = Draggable;
96
+ exports["default"] = _default;
97
+ //# sourceMappingURL=Draggable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/Draggable.tsx"],"names":["Draggable","index","children","ref","nodeRef","style","setStyle","nodeClassName","registerNode","deregisterNode","onMouseDown","onTouchStart","current","mouseDownHandler","e","touchStartHandler","handlers"],"mappings":";;;;;;;;;AAAA;;AAUA;;AAEA;;AACA;;AACA;;;;;;;;;;;;;;;;;;;;AAuCA,IAAMA,SAAmC,GAAG,SAAtCA,SAAsC,OAAyB;AAAA,MAAtBC,KAAsB,QAAtBA,KAAsB;AAAA,MAAfC,QAAe,QAAfA,QAAe;AACnE;AACA,MAAMC,GAAG,GAAG,mBAA8B,IAA9B,CAAZ,CAFmE,CAGnE;;AACA,MAAMC,OAA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AZ;AACD,GAJuB,EAKxB,CAACD,YAAD,CALwB,CAA1B;AAQA,MAAMK,QAAQ,GAAG,+BAAc;AAC7BN,IAAAA,WAAW,EAAEG,gBADgB;AAE7BF,IAAAA,YAAY,EAAEI;AAFe,GAAd,CAAjB;AAKA,sBAAO,kEAAGb,QAAQ,CAAC;AAAEC,IAAAA,GAAG,EAAHA,GAAF;AAAOE,IAAAA,KAAK,EAALA,KAAP;AAAcW,IAAAA,QAAQ,EAARA;AAAd,GAAD,CAAX,CAAP;AACD,CA/CD;;eAiDehB,S","sourcesContent":["import React, {\n CSSProperties,\n RefObject,\n useCallback,\n useEffect,\n useRef,\n useState,\n MouseEvent,\n TouchEvent,\n} from 'react';\nimport useMemoObject from '@os-design/use-memo-object';\nimport { Node } from './utils/NodeList';\nimport useDroppable from './utils/useDroppable';\nimport useDragAndDrop from './utils/useDragAndDrop';\nimport useAppendClassName from './utils/useAppendClassName';\n\nexport interface DraggableHandlers {\n /**\n * The handler that should be called when the mouse down event occurs.\n */\n onMouseDown: (e: MouseEvent) => void;\n /**\n * The handler that should be called when the touch start event occurs.\n */\n onTouchStart: (e: TouchEvent) => void;\n}\n\nexport interface DraggableChildrenProps {\n /**\n * The reference to the draggable list item.\n */\n ref: RefObject<HTMLDivElement>;\n /**\n * Additional styles for moving the list item.\n */\n style: CSSProperties;\n /**\n * The handlers to catch events when the user starts dragging the list item.\n */\n handlers: DraggableHandlers;\n}\n\nexport interface DraggableProps {\n /**\n * The index of the draggable node.\n */\n index: number;\n /**\n * The function that renders the draggable node.\n */\n children: (props: DraggableChildrenProps) => React.ReactNode;\n}\n\nconst Draggable: React.FC<DraggableProps> = ({ index, children }) => {\n // The reference to the list item\n const ref = useRef<HTMLDivElement | null>(null);\n // The reference to the node containing the refs to the prev and next nodes\n const nodeRef = useRef<Node>(null);\n // Additional styles for moving the list item\n const [style, setStyle] = useState<CSSProperties>({});\n\n const { nodeClassName } = useDragAndDrop();\n const { registerNode, deregisterNode, onMouseDown, onTouchStart } =\n useDroppable();\n\n // Register the node in the list\n useEffect(() => {\n nodeRef.current = registerNode({ ref, setStyle, index });\n return () => {\n if (!nodeRef.current) return;\n deregisterNode(nodeRef.current);\n nodeRef.current = null;\n };\n }, [deregisterNode, index, registerNode]);\n\n // Set the class name for the node to apply the transition style (see the DragAndDrop container)\n useAppendClassName(ref, nodeClassName);\n\n // Handlers that determine whether a user clicks on the node\n const mouseDownHandler = useCallback(\n (e: MouseEvent) => {\n if (!nodeRef.current) return;\n onMouseDown(e, nodeRef.current);\n },\n [onMouseDown]\n );\n const touchStartHandler = useCallback(\n (e: TouchEvent) => {\n if (!nodeRef.current) return;\n onTouchStart(e, nodeRef.current);\n },\n [onTouchStart]\n );\n\n const handlers = useMemoObject({\n onMouseDown: mouseDownHandler,\n onTouchStart: touchStartHandler,\n });\n\n return <>{children({ ref, style, handlers })}</>;\n};\n\nexport default Draggable;\n"],"file":"Draggable.js"}
@@ -0,0 +1,112 @@
1
+ "use strict";
2
+
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports["default"] = void 0;
9
+
10
+ var _react = _interopRequireWildcard(require("react"));
11
+
12
+ var _useMemoObject = _interopRequireDefault(require("@os-design/use-memo-object"));
13
+
14
+ var _NodeList = _interopRequireDefault(require("./utils/NodeList"));
15
+
16
+ var _useDragAndDrop2 = _interopRequireDefault(require("./utils/useDragAndDrop"));
17
+
18
+ var _useDroppable = require("./utils/useDroppable");
19
+
20
+ var _useGeneratedId = _interopRequireDefault(require("./utils/useGeneratedId"));
21
+
22
+ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
23
+
24
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
25
+
26
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
27
+
28
+ var Droppable = function Droppable(_ref) {
29
+ var renderDraggedNode = _ref.renderDraggedNode,
30
+ id = _ref.id,
31
+ _ref$horizontal = _ref.horizontal,
32
+ horizontal = _ref$horizontal === void 0 ? false : _ref$horizontal,
33
+ children = _ref.children;
34
+ // The reference to the list
35
+ var ref = (0, _react.useRef)(null); // The reference to the container inside the virtual list
36
+
37
+ var innerRef = (0, _react.useRef)(null); // The unique ID of the list. If no ID was specified, the generated one is used.
38
+
39
+ var generatedId = (0, _useGeneratedId["default"])(10);
40
+ var droppableId = (0, _react.useMemo)(function () {
41
+ return id || generatedId;
42
+ }, [generatedId, id]); // The reference to the list of nodes
43
+
44
+ var listRef = (0, _react.useRef)(new _NodeList["default"]({
45
+ id: droppableId,
46
+ ref: ref,
47
+ innerRef: innerRef,
48
+ horizontal: horizontal,
49
+ renderDraggedNode: renderDraggedNode
50
+ })); // Update the ID of the list if it changes
51
+
52
+ (0, _react.useEffect)(function () {
53
+ listRef.current.id = droppableId;
54
+ }, [droppableId]); // Update the list orientation if it changes.
55
+ // There is no need to check the order of the nodes in the list because it will be the same.
56
+
57
+ (0, _react.useEffect)(function () {
58
+ listRef.current.horizontal = horizontal;
59
+ }, [horizontal]); // Update the callback that renders the dragged node if it changes
60
+
61
+ (0, _react.useEffect)(function () {
62
+ listRef.current.renderDraggedNode = renderDraggedNode;
63
+ }, [renderDraggedNode]);
64
+
65
+ var _useDragAndDrop = (0, _useDragAndDrop2["default"])(),
66
+ registerList = _useDragAndDrop.registerList,
67
+ deregisterList = _useDragAndDrop.deregisterList,
68
+ onMouseDown = _useDragAndDrop.onMouseDown,
69
+ onTouchStart = _useDragAndDrop.onTouchStart; // Register the list in the store
70
+
71
+
72
+ (0, _react.useEffect)(function () {
73
+ registerList(listRef.current);
74
+ var listId = listRef.current.id;
75
+ return function () {
76
+ return deregisterList(listId);
77
+ };
78
+ }, [deregisterList, registerList]);
79
+ var registerNode = (0, _react.useCallback)(function (props) {
80
+ return listRef.current.add(props);
81
+ }, []);
82
+ var deregisterNode = (0, _react.useCallback)(function (node) {
83
+ listRef.current.remove(node);
84
+ }, []); // Handlers that determine whether a user clicks on the node
85
+
86
+ var mouseDownHandler = (0, _react.useCallback)(function (e, node) {
87
+ onMouseDown(e, listRef.current, node);
88
+ }, [onMouseDown]);
89
+ var touchStartHandler = (0, _react.useCallback)(function (e, node) {
90
+ onTouchStart(e, listRef.current, node);
91
+ }, [onTouchStart]);
92
+ var droppableContext = (0, _useMemoObject["default"])({
93
+ registerNode: registerNode,
94
+ deregisterNode: deregisterNode,
95
+ onMouseDown: mouseDownHandler,
96
+ onTouchStart: touchStartHandler
97
+ });
98
+ var renderChildren = (0, _react.useCallback)(function () {
99
+ if (typeof children !== 'function') return children;
100
+ return children({
101
+ ref: ref,
102
+ innerRef: innerRef
103
+ });
104
+ }, [children]);
105
+ return /*#__PURE__*/_react["default"].createElement(_useDroppable.DroppableContext.Provider, {
106
+ value: droppableContext
107
+ }, renderChildren());
108
+ };
109
+
110
+ var _default = Droppable;
111
+ exports["default"] = _default;
112
+ //# sourceMappingURL=Droppable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/Droppable.tsx"],"names":["Droppable","renderDraggedNode","id","horizontal","children","ref","innerRef","generatedId","droppableId","listRef","NodeList","current","registerList","deregisterList","onMouseDown","onTouchStart","listId","registerNode","props","add","deregisterNode","node","remove","mouseDownHandler","e","touchStartHandler","droppableContext","renderChildren"],"mappings":";;;;;;;;;AAAA;;AASA;;AACA;;AAKA;;AACA;;AACA;;;;;;;;AAuCA,IAAMA,SAAmC,GAAG,SAAtCA,SAAsC,OAKtC;AAAA,MAJJC,iBAII,QAJJA,iBAII;AAAA,MAHJC,EAGI,QAHJA,EAGI;AAAA,6BAFJC,UAEI;AAAA,MAFJA,UAEI,gCAFS,KAET;AAAA,MADJC,QACI,QADJA,QACI;AACJ;AACA,MAAMC,GAAG,GAAG,mBAAuB,IAAvB,CAAZ,CAFI,CAGJ;;AACA,MAAMC,QAAQ,GAAG,mBAAuB,IAAvB,CAAjB,CAJI,CAKJ;;AACA,MAAMC,WAAW,GAAG,gCAAe,EAAf,CAApB;AACA,MAAMC,WAAW,GAAG,oBAAQ;AAAA,WAAMN,EAAE,IAAIK,WAAZ;AAAA,GAAR,EAAiC,CAACA,WAAD,EAAcL,EAAd,CAAjC,CAApB,CAPI,CAQJ;;AACA,MAAMO,OAAO,GAAG,mBACd,IAAIC,oBAAJ,CAAa;AACXR,IAAAA,EAAE,EAAEM,WADO;AAEXH,IAAAA,GAAG,EAAHA,GAFW;AAGXC,IAAAA,QAAQ,EAARA,QAHW;AAIXH,IAAAA,UAAU,EAAVA,UAJW;AAKXF,IAAAA,iBAAiB,EAAjBA;AALW,GAAb,CADc,CAAhB,CATI,CAmBJ;;AACA,wBAAU,YAAM;AACdQ,IAAAA,OAAO,CAACE,OAAR,CAAgBT,EAAhB,GAAqBM,WAArB;AACD,GAFD,EAEG,CAACA,WAAD,CAFH,EApBI,CAwBJ;AACA;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AgBH,IAAhB,EAAuC;AACrCN,IAAAA,YAAY,CAACS,CAAD,EAAIf,OAAO,CAACE,OAAZ,EAAqBU,IAArB,CAAZ;AACD,GAHuB,EAIxB,CAACN,YAAD,CAJwB,CAA1B;AAOA,MAAMW,gBAAgB,GAAG,+BAAc;AACrCT,IAAAA,YAAY,EAAZA,YADqC;AAErCG,IAAAA,cAAc,EAAdA,cAFqC;AAGrCN,IAAAA,WAAW,EAAES,gBAHwB;AAIrCR,IAAAA,YAAY,EAAEU;AAJuB,GAAd,CAAzB;AAOA,MAAME,cAAc,GAAG,wBAAmC,YAAM;AAC9D,QAAI,OAAOvB,QAAP,KAAoB,UAAxB,EAAoC,OAAOA,QAAP;AACpC,WAAQA,QAAD,CAAuB;AAAEC,MAAAA,GAAG,EAAHA,GAAF;AAAOC,MAAAA,QAAQ,EAARA;AAAP,KAAvB,CAAP;AACD,GAHsB,EAGpB,CAACF,QAAD,CAHoB,CAAvB;AAKA,sBACE,gCAAC,8BAAD,CAAkB,QAAlB;AAA2B,IAAA,KAAK,EAAEsB;AAAlC,KACGC,cAAc,EADjB,CADF;AAKD,CAzFD;;eA2Fe3B,S","sourcesContent":["import React, {\n RefObject,\n useCallback,\n useEffect,\n useMemo,\n useRef,\n MouseEvent,\n TouchEvent,\n} from 'react';\nimport useMemoObject from '@os-design/use-memo-object';\nimport NodeList, {\n ExistingNode,\n NodeProps,\n RenderDraggedNode,\n} from './utils/NodeList';\nimport useDragAndDrop from './utils/useDragAndDrop';\nimport { DroppableContext } from './utils/useDroppable';\nimport useGeneratedId from './utils/useGeneratedId';\n\nexport interface DroppableChildrenProps {\n /**\n * The reference to the list.\n * If a virtual list is used, pass it to the outerRef prop.\n */\n ref: RefObject<HTMLDivElement>;\n /**\n * The reference to the container inside the virtual list.\n * Pass it to the innerRef prop.\n */\n innerRef: RefObject<HTMLDivElement>;\n}\n\nexport interface DroppableProps {\n /**\n * The function that renders the dragged node.\n */\n renderDraggedNode: RenderDraggedNode;\n /**\n * The ID of the list with draggable nodes.\n * Used to determine in which list the dragged node was dropped.\n * @default undefined\n */\n id?: string;\n /**\n * Whether the list is horizontal.\n * @default false\n */\n horizontal?: boolean;\n /**\n * The function that renders the list with draggable nodes.\n */\n children:\n | React.ReactNode\n | ((props: DroppableChildrenProps) => React.ReactNode);\n}\n\nconst Droppable: React.FC<DroppableProps> = ({\n renderDraggedNode,\n id,\n horizontal = false,\n children,\n}) => {\n // The reference to the list\n const ref = useRef<HTMLDivElement>(null);\n // The reference to the container inside the virtual list\n const innerRef = useRef<HTMLDivElement>(null);\n // The unique ID of the list. If no ID was specified, the generated one is used.\n const generatedId = useGeneratedId(10);\n const droppableId = useMemo(() => id || generatedId, [generatedId, id]);\n // The reference to the list of nodes\n const listRef = useRef(\n new NodeList({\n id: droppableId,\n ref,\n innerRef,\n horizontal,\n renderDraggedNode,\n })\n );\n\n // Update the ID of the list if it changes\n useEffect(() => {\n listRef.current.id = droppableId;\n }, [droppableId]);\n\n // Update the list orientation if it changes.\n // There is no need to check the order of the nodes in the list because it will be the same.\n useEffect(() => {\n listRef.current.horizontal = horizontal;\n }, [horizontal]);\n\n // Update the callback that renders the dragged node if it changes\n useEffect(() => {\n listRef.current.renderDraggedNode = renderDraggedNode;\n }, [renderDraggedNode]);\n\n const { registerList, deregisterList, onMouseDown, onTouchStart } =\n useDragAndDrop();\n\n // Register the list in the store\n useEffect(() => {\n registerList(listRef.current);\n const listId = listRef.current.id;\n return () => deregisterList(listId);\n }, [deregisterList, registerList]);\n\n const registerNode = useCallback(\n (props: NodeProps) => listRef.current.add(props),\n []\n );\n const deregisterNode = useCallback((node: ExistingNode) => {\n listRef.current.remove(node);\n }, []);\n\n // Handlers that determine whether a user clicks on the node\n const mouseDownHandler = useCallback(\n (e: MouseEvent, node: ExistingNode) => {\n onMouseDown(e, listRef.current, node);\n },\n [onMouseDown]\n );\n const touchStartHandler = useCallback(\n (e: TouchEvent, node: ExistingNode) => {\n onTouchStart(e, listRef.current, node);\n },\n [onTouchStart]\n );\n\n const droppableContext = useMemoObject({\n registerNode,\n deregisterNode,\n onMouseDown: mouseDownHandler,\n onTouchStart: touchStartHandler,\n });\n\n const renderChildren = useCallback<() => React.ReactNode>(() => {\n if (typeof children !== 'function') return children;\n return (children as Function)({ ref, innerRef });\n }, [children]);\n\n return (\n <DroppableContext.Provider value={droppableContext}>\n {renderChildren()}\n </DroppableContext.Provider>\n );\n};\n\nexport default Droppable;\n"],"file":"Droppable.js"}
@@ -0,0 +1,77 @@
1
+ "use strict";
2
+
3
+ function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ var _exportNames = {
9
+ DragAndDrop: true,
10
+ Droppable: true,
11
+ Draggable: true
12
+ };
13
+ Object.defineProperty(exports, "DragAndDrop", {
14
+ enumerable: true,
15
+ get: function get() {
16
+ return _DragAndDrop["default"];
17
+ }
18
+ });
19
+ Object.defineProperty(exports, "Draggable", {
20
+ enumerable: true,
21
+ get: function get() {
22
+ return _Draggable["default"];
23
+ }
24
+ });
25
+ Object.defineProperty(exports, "Droppable", {
26
+ enumerable: true,
27
+ get: function get() {
28
+ return _Droppable["default"];
29
+ }
30
+ });
31
+
32
+ var _DragAndDrop = _interopRequireWildcard(require("./DragAndDrop"));
33
+
34
+ Object.keys(_DragAndDrop).forEach(function (key) {
35
+ if (key === "default" || key === "__esModule") return;
36
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
37
+ if (key in exports && exports[key] === _DragAndDrop[key]) return;
38
+ Object.defineProperty(exports, key, {
39
+ enumerable: true,
40
+ get: function get() {
41
+ return _DragAndDrop[key];
42
+ }
43
+ });
44
+ });
45
+
46
+ var _Droppable = _interopRequireWildcard(require("./Droppable"));
47
+
48
+ Object.keys(_Droppable).forEach(function (key) {
49
+ if (key === "default" || key === "__esModule") return;
50
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
51
+ if (key in exports && exports[key] === _Droppable[key]) return;
52
+ Object.defineProperty(exports, key, {
53
+ enumerable: true,
54
+ get: function get() {
55
+ return _Droppable[key];
56
+ }
57
+ });
58
+ });
59
+
60
+ var _Draggable = _interopRequireWildcard(require("./Draggable"));
61
+
62
+ Object.keys(_Draggable).forEach(function (key) {
63
+ if (key === "default" || key === "__esModule") return;
64
+ if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return;
65
+ if (key in exports && exports[key] === _Draggable[key]) return;
66
+ Object.defineProperty(exports, key, {
67
+ enumerable: true,
68
+ get: function get() {
69
+ return _Draggable[key];
70
+ }
71
+ });
72
+ });
73
+
74
+ function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
75
+
76
+ function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
77
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;;AAIA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAHA;;AAIA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;AAHA;;AAIA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA","sourcesContent":["export { default as DragAndDrop } from './DragAndDrop';\nexport { default as Droppable } from './Droppable';\nexport { default as Draggable } from './Draggable';\n\nexport * from './DragAndDrop';\nexport * from './Droppable';\nexport * from './Draggable';\n"],"file":"index.js"}
@@ -0,0 +1,68 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports["default"] = void 0;
7
+
8
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
9
+
10
+ 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); } }
11
+
12
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
13
+
14
+ /**
15
+ * Stores all the lists where the draggable items is located.
16
+ */
17
+ var ListStore = /*#__PURE__*/function () {
18
+ function ListStore() {
19
+ _classCallCheck(this, ListStore);
20
+
21
+ this.lists = void 0;
22
+ this.lists = [];
23
+ }
24
+ /**
25
+ * Adds a new list to the store.
26
+ */
27
+
28
+
29
+ _createClass(ListStore, [{
30
+ key: "add",
31
+ value: function add(list) {
32
+ this.lists.push(list);
33
+ }
34
+ /**
35
+ * Removes the list from the store.
36
+ */
37
+
38
+ }, {
39
+ key: "remove",
40
+ value: function remove(id) {
41
+ var index = this.lists.findIndex(function (item) {
42
+ return item.id === id;
43
+ });
44
+ if (index === -1) return;
45
+ this.lists.splice(index, 1);
46
+ }
47
+ /**
48
+ * Returns the list in which the position is located.
49
+ */
50
+
51
+ }, {
52
+ key: "findByPosition",
53
+ value: function findByPosition(x, y) {
54
+ return this.lists.find(function (list) {
55
+ var current = list.ref.current;
56
+ if (!current) return true;
57
+ var rect = current.getBoundingClientRect();
58
+ return x >= rect.x && x <= rect.x + rect.width && y >= rect.y && y <= rect.y + rect.height;
59
+ });
60
+ }
61
+ }]);
62
+
63
+ return ListStore;
64
+ }();
65
+
66
+ var _default = ListStore;
67
+ exports["default"] = _default;
68
+ //# sourceMappingURL=ListStore.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../src/utils/ListStore.ts"],"names":["ListStore","lists","list","push","id","index","findIndex","item","splice","x","y","find","current","ref","rect","getBoundingClientRect","width","height"],"mappings":";;;;;;;;;;;;;AAEA;AACA;AACA;IACMA,S;AAGJ,uBAAqB;AAAA;;AAAA,SAFbC,KAEa;AACnB,SAAKA,KAAL,GAAa,EAAb;AACD;AAED;AACF;AACA;;;;;WACE,aAAWC,IAAX,EAA2B;AACzB,WAAKD,KAAL,CAAWE,IAAX,CAAgBD,IAAhB;AACD;AAED;AACF;AACA;;;;WACE,gBAAcE,EAAd,EAA0B;AACxB,UAAMC,KAAK,GAAG,KAAKJ,KAAL,CAAWK,SAAX,CAAqB,UAACC,IAAD;AAAA,eAAUA,IAAI,CAACH,EAAL,KAAYA,EAAtB;AAAA,OAArB,CAAd;AACA,UAAIC,KAAK,KAAK,CAAC,CAAf,EAAkB;AAClB,WAAKJ,KAAL,CAAWO,MAAX,CAAkBH,KAAlB,EAAyB,CAAzB;AACD;AAED;AACF;AACA;;;;WACE,wBAAsBI,CAAtB,EAAiCC,CAAjC,EAA4C;AAC1C,aAAO,KAAKT,KAAL,CAAWU,IAAX,CAAgB,UAACT,IAAD,EAAU;AAC/B,YAAQU,OAAR,GAAoBV,IAAI,CAACW,GAAzB,CAAQD,OAAR;AACA,YAAI,CAACA,OAAL,EAAc,OAAO,IAAP;AACd,YAAME,IAAI,GAAGF,OAAO,CAACG,qBAAR,EAAb;AACA,eACEN,CAAC,IAAIK,IAAI,CAACL,CAAV,IACAA,CAAC,IAAIK,IAAI,CAACL,CAAL,GAASK,IAAI,CAACE,KADnB,IAEAN,CAAC,IAAII,IAAI,CAACJ,CAFV,IAGAA,CAAC,IAAII,IAAI,CAACJ,CAAL,GAASI,IAAI,CAACG,MAJrB;AAMD,OAVM,CAAP;AAWD;;;;;;eAGYjB,S","sourcesContent":["import NodeList from './NodeList';\n\n/**\n * Stores all the lists where the draggable items is located.\n */\nclass ListStore {\n private lists: NodeList[];\n\n public constructor() {\n this.lists = [];\n }\n\n /**\n * Adds a new list to the store.\n */\n public add(list: NodeList) {\n this.lists.push(list);\n }\n\n /**\n * Removes the list from the store.\n */\n public remove(id: string) {\n const index = this.lists.findIndex((item) => item.id === id);\n if (index === -1) return;\n this.lists.splice(index, 1);\n }\n\n /**\n * Returns the list in which the position is located.\n */\n public findByPosition(x: number, y: number) {\n return this.lists.find((list) => {\n const { current } = list.ref;\n if (!current) return true;\n const rect = current.getBoundingClientRect();\n return (\n x >= rect.x &&\n x <= rect.x + rect.width &&\n y >= rect.y &&\n y <= rect.y + rect.height\n );\n });\n }\n}\n\nexport default ListStore;\n"],"file":"ListStore.js"}