@elliemae/ds-drag-and-drop 2.2.0-alpha.3 → 2.2.0-next.2

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 (82) hide show
  1. package/cjs/hierarchy/customCollisionDetection.js +50 -44
  2. package/cjs/hierarchy/getHierarchyKeyboardCoordinates.js +91 -78
  3. package/cjs/hierarchy/index.js +9 -28
  4. package/cjs/hierarchy/types.js +2 -27
  5. package/cjs/hierarchy/useHierarchyActionHandlers.js +35 -53
  6. package/cjs/hierarchy/useHierarchyAnnouncements.js +26 -45
  7. package/cjs/hierarchy/useHierarchyDndkitConfig.js +83 -77
  8. package/cjs/hierarchy/useHierarchyPreviewHandlers.js +27 -48
  9. package/cjs/index.js +11 -29
  10. package/cjs/tree/constants.js +12 -41
  11. package/cjs/tree/customCollisionDetection.js +128 -93
  12. package/cjs/tree/getTreeKeyboardCoordinates.js +100 -87
  13. package/cjs/tree/index.js +9 -28
  14. package/cjs/tree/types.js +2 -27
  15. package/cjs/tree/useTreeActionHandlers.js +56 -67
  16. package/cjs/tree/useTreeAnnouncements.js +40 -53
  17. package/cjs/tree/useTreeDndkitConfig.js +108 -102
  18. package/cjs/tree/useTreePreviewHandlers.js +37 -53
  19. package/cjs/tree/utilities.js +30 -44
  20. package/esm/hierarchy/customCollisionDetection.js +46 -15
  21. package/esm/hierarchy/getHierarchyKeyboardCoordinates.js +76 -42
  22. package/esm/hierarchy/index.js +1 -3
  23. package/esm/hierarchy/types.js +1 -2
  24. package/esm/hierarchy/useHierarchyActionHandlers.js +31 -24
  25. package/esm/hierarchy/useHierarchyAnnouncements.js +20 -14
  26. package/esm/hierarchy/useHierarchyDndkitConfig.js +66 -45
  27. package/esm/hierarchy/useHierarchyPreviewHandlers.js +19 -15
  28. package/esm/index.js +2 -4
  29. package/esm/tree/constants.js +10 -12
  30. package/esm/tree/customCollisionDetection.js +124 -64
  31. package/esm/tree/getTreeKeyboardCoordinates.js +83 -49
  32. package/esm/tree/index.js +1 -3
  33. package/esm/tree/types.js +1 -2
  34. package/esm/tree/useTreeActionHandlers.js +50 -36
  35. package/esm/tree/useTreeAnnouncements.js +30 -18
  36. package/esm/tree/useTreeDndkitConfig.js +89 -68
  37. package/esm/tree/useTreePreviewHandlers.js +28 -19
  38. package/esm/tree/utilities.js +23 -13
  39. package/package.json +1 -1
  40. package/types/hierarchy/types.d.ts +1 -1
  41. package/types/tree/types.d.ts +17 -13
  42. package/types/tree/useTreeActionHandlers.d.ts +2 -2
  43. package/types/tree/useTreeDndkitConfig.d.ts +2 -2
  44. package/types/tree/useTreePreviewHandlers.d.ts +2 -2
  45. package/cjs/hierarchy/customCollisionDetection.js.map +0 -7
  46. package/cjs/hierarchy/getHierarchyKeyboardCoordinates.js.map +0 -7
  47. package/cjs/hierarchy/index.js.map +0 -7
  48. package/cjs/hierarchy/types.js.map +0 -7
  49. package/cjs/hierarchy/useHierarchyActionHandlers.js.map +0 -7
  50. package/cjs/hierarchy/useHierarchyAnnouncements.js.map +0 -7
  51. package/cjs/hierarchy/useHierarchyDndkitConfig.js.map +0 -7
  52. package/cjs/hierarchy/useHierarchyPreviewHandlers.js.map +0 -7
  53. package/cjs/index.js.map +0 -7
  54. package/cjs/tree/constants.js.map +0 -7
  55. package/cjs/tree/customCollisionDetection.js.map +0 -7
  56. package/cjs/tree/getTreeKeyboardCoordinates.js.map +0 -7
  57. package/cjs/tree/index.js.map +0 -7
  58. package/cjs/tree/types.js.map +0 -7
  59. package/cjs/tree/useTreeActionHandlers.js.map +0 -7
  60. package/cjs/tree/useTreeAnnouncements.js.map +0 -7
  61. package/cjs/tree/useTreeDndkitConfig.js.map +0 -7
  62. package/cjs/tree/useTreePreviewHandlers.js.map +0 -7
  63. package/cjs/tree/utilities.js.map +0 -7
  64. package/esm/hierarchy/customCollisionDetection.js.map +0 -7
  65. package/esm/hierarchy/getHierarchyKeyboardCoordinates.js.map +0 -7
  66. package/esm/hierarchy/index.js.map +0 -7
  67. package/esm/hierarchy/types.js.map +0 -7
  68. package/esm/hierarchy/useHierarchyActionHandlers.js.map +0 -7
  69. package/esm/hierarchy/useHierarchyAnnouncements.js.map +0 -7
  70. package/esm/hierarchy/useHierarchyDndkitConfig.js.map +0 -7
  71. package/esm/hierarchy/useHierarchyPreviewHandlers.js.map +0 -7
  72. package/esm/index.js.map +0 -7
  73. package/esm/tree/constants.js.map +0 -7
  74. package/esm/tree/customCollisionDetection.js.map +0 -7
  75. package/esm/tree/getTreeKeyboardCoordinates.js.map +0 -7
  76. package/esm/tree/index.js.map +0 -7
  77. package/esm/tree/types.js.map +0 -7
  78. package/esm/tree/useTreeActionHandlers.js.map +0 -7
  79. package/esm/tree/useTreeAnnouncements.js.map +0 -7
  80. package/esm/tree/useTreeDndkitConfig.js.map +0 -7
  81. package/esm/tree/useTreePreviewHandlers.js.map +0 -7
  82. package/esm/tree/utilities.js.map +0 -7
@@ -1,109 +1,122 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __reExport = (target, module2, copyDefault, desc) => {
13
- if (module2 && typeof module2 === "object" || typeof module2 === "function") {
14
- for (let key of __getOwnPropNames(module2))
15
- if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
16
- __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
17
- }
18
- return target;
19
- };
20
- var __toESM = (module2, isNodeMode) => {
21
- return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
22
- };
23
- var __toCommonJS = /* @__PURE__ */ ((cache) => {
24
- return (module2, temp) => {
25
- return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
26
- };
27
- })(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
28
- var getTreeKeyboardCoordinates_exports = {};
29
- __export(getTreeKeyboardCoordinates_exports, {
30
- getTreeKeyboardCoordinates: () => getTreeKeyboardCoordinates
31
- });
32
- var React = __toESM(require("react"));
33
- var import_core = __toESM(require("@dnd-kit/core"));
34
- var import_constants = __toESM(require("./constants"));
35
- const directions = [import_core.KeyboardCode.Down, import_core.KeyboardCode.Right, import_core.KeyboardCode.Up, import_core.KeyboardCode.Left];
36
- const horizontal = [import_core.KeyboardCode.Left, import_core.KeyboardCode.Right];
37
- const vertical = [import_core.KeyboardCode.Up, import_core.KeyboardCode.Down];
38
- const getVerticalKeyboardCoordinates = ({
39
- items,
40
- active,
41
- over,
42
- event,
43
- currentCoordinates,
44
- droppableContainers,
45
- collisionRect,
46
- dropIndicatorPosition,
47
- maxDragAndDropLevel
48
- }) => {
49
- if (horizontal.includes(event.code))
50
- return void 0;
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var _defineProperty = require('@babel/runtime/helpers/defineProperty');
6
+ require('core-js/modules/esnext.async-iterator.for-each.js');
7
+ require('core-js/modules/esnext.iterator.constructor.js');
8
+ require('core-js/modules/esnext.iterator.for-each.js');
9
+ require('core-js/modules/esnext.async-iterator.find.js');
10
+ require('core-js/modules/esnext.iterator.find.js');
11
+ require('core-js/modules/esnext.async-iterator.filter.js');
12
+ require('core-js/modules/esnext.iterator.filter.js');
13
+ var core = require('@dnd-kit/core');
14
+ var constants = require('./constants.js');
15
+
16
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
17
+
18
+ var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
19
+
20
+ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
21
+
22
+ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty__default["default"](target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
23
+ const directions = [core.KeyboardCode.Down, core.KeyboardCode.Right, core.KeyboardCode.Up, core.KeyboardCode.Left];
24
+ const horizontal = [core.KeyboardCode.Left, core.KeyboardCode.Right];
25
+
26
+ const getVerticalKeyboardCoordinates = _ref => {
27
+ var _droppableContainers$, _droppableContainers$2;
28
+
29
+ let {
30
+ items,
31
+ active,
32
+ over,
33
+ event,
34
+ currentCoordinates,
35
+ droppableContainers,
36
+ collisionRect,
37
+ dropIndicatorPosition,
38
+ maxDragAndDropLevel
39
+ } = _ref;
40
+ if (horizontal.includes(event.code)) return undefined;
51
41
  const overRect = over.rect;
52
- const layoutRects = [];
53
- droppableContainers.forEach((container) => {
54
- if (container?.disabled || !overRect) {
42
+ const layoutRects = []; // Get the reacheable rects depending on the arrow key pressed
43
+
44
+ droppableContainers.forEach(container => {
45
+ if (container !== null && container !== void 0 && container.disabled || !overRect) {
55
46
  return;
56
47
  }
48
+
57
49
  const rect = container.rect.current;
58
- if (rect && event.code === import_core.KeyboardCode.Down && collisionRect.top - 2 <= rect.offsetTop) {
50
+
51
+ if (rect && event.code === core.KeyboardCode.Down && collisionRect.top - 2 <= rect.offsetTop) {
59
52
  layoutRects.push(container);
60
- } else if (rect && event.code === import_core.KeyboardCode.Up && collisionRect.top >= rect.offsetTop) {
53
+ } else if (rect && event.code === core.KeyboardCode.Up && collisionRect.top >= rect.offsetTop) {
61
54
  layoutRects.push(container);
62
55
  }
63
56
  });
64
- const closestId = (0, import_core.closestCorners)({
57
+ const closestId = core.closestCorners({
65
58
  collisionRect,
66
59
  droppableContainers: layoutRects,
67
60
  active
68
61
  });
69
- const closestItem = items.find((item) => item.uid === closestId);
70
- const closestElement = droppableContainers.get(closestId)?.node?.current;
71
- if (!closestId || !closestItem || !closestElement)
72
- return void 0;
73
- const closestRect = (0, import_core.getViewRect)(closestElement);
74
- if (event.code === import_core.KeyboardCode.Up) {
75
- if (dropIndicatorPosition === import_constants.DropIndicatorPosition.Inside || closestId === active.id || closestItem.depth + 1 > maxDragAndDropLevel) {
76
- return {
77
- ...currentCoordinates,
62
+ const closestItem = items.find(item => item.uid === closestId);
63
+ const closestElement = (_droppableContainers$ = droppableContainers.get(closestId)) === null || _droppableContainers$ === void 0 ? void 0 : (_droppableContainers$2 = _droppableContainers$.node) === null || _droppableContainers$2 === void 0 ? void 0 : _droppableContainers$2.current;
64
+ if (!closestId || !closestItem || !closestElement) return undefined;
65
+ const closestRect = core.getViewRect(closestElement);
66
+
67
+ if (event.code === core.KeyboardCode.Up) {
68
+ // If the drop indicator is inside (or over ourselves)
69
+ // We are gonna go to the before position
70
+ // Else we are gonna go inside the over rect
71
+ if (dropIndicatorPosition === constants.DropIndicatorPosition.Inside || closestId === active.id || closestItem.depth + 1 > maxDragAndDropLevel) {
72
+ return _objectSpread(_objectSpread({}, currentCoordinates), {}, {
78
73
  y: closestRect.top - collisionRect.height / 2
79
- };
74
+ });
80
75
  }
81
- return {
82
- ...currentCoordinates,
76
+
77
+ return _objectSpread(_objectSpread({}, currentCoordinates), {}, {
83
78
  y: closestRect.top + Math.abs(closestRect.height - collisionRect.height) / 2
84
- };
85
- }
86
- if (dropIndicatorPosition === import_constants.DropIndicatorPosition.Inside || closestId === active.id || closestItem.depth + 1 > maxDragAndDropLevel) {
87
- return {
88
- ...currentCoordinates,
79
+ });
80
+ } // If the drop indicator is inside (or over ourselves)
81
+ // We are gonna go to the after position
82
+ // Else we are gonna go inside the over rect
83
+
84
+
85
+ if (dropIndicatorPosition === constants.DropIndicatorPosition.Inside || closestId === active.id || closestItem.depth + 1 > maxDragAndDropLevel) {
86
+ return _objectSpread(_objectSpread({}, currentCoordinates), {}, {
89
87
  y: closestRect.top + collisionRect.height / 2
90
- };
88
+ });
91
89
  }
92
- return {
93
- ...currentCoordinates,
90
+
91
+ return _objectSpread(_objectSpread({}, currentCoordinates), {}, {
94
92
  y: closestRect.top + Math.abs(closestRect.height - collisionRect.height) / 2
95
- };
93
+ });
96
94
  };
97
- const getTreeKeyboardCoordinates = (context, isHorizontalDnD, maxDragAndDropLevel) => (event, { currentCoordinates, context: { over, translatedRect, droppableContainers, active, collisionRect } }) => {
95
+
96
+ const getTreeKeyboardCoordinates = (context, isHorizontalDnD, maxDragAndDropLevel) => (event, _ref2) => {
97
+ let {
98
+ currentCoordinates,
99
+ context: {
100
+ over,
101
+ translatedRect,
102
+ droppableContainers,
103
+ active,
104
+ collisionRect
105
+ }
106
+ } = _ref2;
107
+
98
108
  if (directions.includes(event.code)) {
99
109
  if (!translatedRect) {
100
- return void 0;
110
+ return undefined;
101
111
  }
112
+
102
113
  const {
103
- current: { items, dropIndicatorPosition }
114
+ current: {
115
+ items,
116
+ dropIndicatorPosition
117
+ }
104
118
  } = context;
105
- if (!over || !active || !collisionRect)
106
- return void 0;
119
+ if (!over || !active || !collisionRect) return undefined;
107
120
  const args = {
108
121
  items,
109
122
  active,
@@ -115,11 +128,11 @@ const getTreeKeyboardCoordinates = (context, isHorizontalDnD, maxDragAndDropLeve
115
128
  dropIndicatorPosition,
116
129
  maxDragAndDropLevel
117
130
  };
118
- if (isHorizontalDnD)
119
- return void 0;
131
+ if (isHorizontalDnD) return undefined;
120
132
  return getVerticalKeyboardCoordinates(args);
121
133
  }
122
- return void 0;
134
+
135
+ return undefined;
123
136
  };
124
- module.exports = __toCommonJS(getTreeKeyboardCoordinates_exports);
125
- //# sourceMappingURL=getTreeKeyboardCoordinates.js.map
137
+
138
+ exports.getTreeKeyboardCoordinates = getTreeKeyboardCoordinates;
package/cjs/tree/index.js CHANGED
@@ -1,28 +1,9 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
8
- var __reExport = (target, module2, copyDefault, desc) => {
9
- if (module2 && typeof module2 === "object" || typeof module2 === "function") {
10
- for (let key of __getOwnPropNames(module2))
11
- if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
12
- __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
13
- }
14
- return target;
15
- };
16
- var __toESM = (module2, isNodeMode) => {
17
- return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
18
- };
19
- var __toCommonJS = /* @__PURE__ */ ((cache) => {
20
- return (module2, temp) => {
21
- return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
22
- };
23
- })(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
24
- var tree_exports = {};
25
- var React = __toESM(require("react"));
26
- __reExport(tree_exports, __toESM(require("./useTreeDndkitConfig")));
27
- module.exports = __toCommonJS(tree_exports);
28
- //# sourceMappingURL=index.js.map
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var useTreeDndkitConfig = require('./useTreeDndkitConfig.js');
6
+
7
+
8
+
9
+ exports.useTreeDndkitConfig = useTreeDndkitConfig.useTreeDndkitConfig;
package/cjs/tree/types.js CHANGED
@@ -1,27 +1,2 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
8
- var __reExport = (target, module2, copyDefault, desc) => {
9
- if (module2 && typeof module2 === "object" || typeof module2 === "function") {
10
- for (let key of __getOwnPropNames(module2))
11
- if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
12
- __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
13
- }
14
- return target;
15
- };
16
- var __toESM = (module2, isNodeMode) => {
17
- return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
18
- };
19
- var __toCommonJS = /* @__PURE__ */ ((cache) => {
20
- return (module2, temp) => {
21
- return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
22
- };
23
- })(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
24
- var types_exports = {};
25
- var React = __toESM(require("react"));
26
- module.exports = __toCommonJS(types_exports);
27
- //# sourceMappingURL=types.js.map
1
+ 'use strict';
2
+
@@ -1,85 +1,74 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __reExport = (target, module2, copyDefault, desc) => {
13
- if (module2 && typeof module2 === "object" || typeof module2 === "function") {
14
- for (let key of __getOwnPropNames(module2))
15
- if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
16
- __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
17
- }
18
- return target;
19
- };
20
- var __toESM = (module2, isNodeMode) => {
21
- return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
22
- };
23
- var __toCommonJS = /* @__PURE__ */ ((cache) => {
24
- return (module2, temp) => {
25
- return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
26
- };
27
- })(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
28
- var useTreeActionHandlers_exports = {};
29
- __export(useTreeActionHandlers_exports, {
30
- useTreeActionHandlers: () => useTreeActionHandlers
31
- });
32
- var React = __toESM(require("react"));
33
- var import_sortable = __toESM(require("@dnd-kit/sortable"));
34
- var import_lodash = __toESM(require("lodash"));
35
- var import_react = __toESM(require("react"));
36
- var import_constants = __toESM(require("./constants"));
37
- const useTreeActionHandlers = ({
38
- handlePreviewDragStart,
39
- handlePreviewDragMove,
40
- handlePreviewDragOver,
41
- handlePreviewDragEnd,
42
- handlePreviewDragCancel,
43
- onReorder,
44
- flattenedItems,
45
- projected,
46
- dropIndicatorPosition
47
- }) => {
48
- const onDragStart = (0, import_react.useCallback)((e) => {
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var sortable = require('@dnd-kit/sortable');
6
+ var lodash = require('lodash');
7
+ var react = require('react');
8
+ var constants = require('./constants.js');
9
+
10
+ const useTreeActionHandlers = _ref => {
11
+ let {
12
+ handlePreviewDragStart,
13
+ handlePreviewDragMove,
14
+ handlePreviewDragOver,
15
+ handlePreviewDragEnd,
16
+ handlePreviewDragCancel,
17
+ onReorder,
18
+ flattenedItems,
19
+ projected,
20
+ dropIndicatorPosition,
21
+ isDropValid
22
+ } = _ref;
23
+ const onDragStart = react.useCallback(e => {
49
24
  handlePreviewDragStart(e);
50
25
  }, [handlePreviewDragStart]);
51
- const onDragMove = (0, import_react.useCallback)((e) => {
26
+ const onDragMove = react.useCallback(e => {
52
27
  handlePreviewDragMove(e);
53
28
  }, [handlePreviewDragMove]);
54
- const onDragOver = (0, import_react.useCallback)((e) => {
29
+ const onDragOver = react.useCallback(e => {
55
30
  handlePreviewDragOver(e);
56
31
  }, [handlePreviewDragOver]);
57
- const onDragEnd = (0, import_react.useCallback)((e) => {
32
+ const onDragEnd = react.useCallback(e => {
58
33
  handlePreviewDragEnd(e);
59
- const { active, over } = e;
60
- if (over === null)
61
- return;
62
- const activeIndex = flattenedItems.findIndex((item) => item.uid === active.id);
34
+ const {
35
+ active,
36
+ over
37
+ } = e;
38
+ if (over === null || !isDropValid) return;
39
+ const activeIndex = flattenedItems.findIndex(item => item.uid === active.id);
63
40
  let considerExpanding = null;
64
- let overIndex = flattenedItems.findIndex((item) => item.uid === over.id);
65
- if (dropIndicatorPosition === import_constants.DropIndicatorPosition.Inside) {
41
+ let overIndex = flattenedItems.findIndex(item => item.uid === over.id); // If drop indicator is inside, then put it last,
42
+ // It will be reconstructed well later
43
+
44
+ if (dropIndicatorPosition === constants.DropIndicatorPosition.Inside) {
66
45
  considerExpanding = over.id;
67
- overIndex = flattenedItems[overIndex].realIndex + (flattenedItems[overIndex].original.subRows?.length ?? 0) + 1;
68
- }
46
+ overIndex = flattenedItems[overIndex].realIndex + flattenedItems[overIndex].childrenCount + 1;
47
+ } // If we are dropping the item in a new position, or new depth
48
+
49
+
69
50
  if (projected && (activeIndex !== overIndex || flattenedItems[activeIndex].depth !== projected.depth)) {
51
+ // Change parent and depth from projected data
70
52
  flattenedItems[activeIndex].parentId = projected.parentId;
71
- flattenedItems[activeIndex].depth = projected.depth;
72
- const newFlattenedData = activeIndex !== overIndex ? (0, import_sortable.arrayMove)(flattenedItems, activeIndex, overIndex) : (0, import_lodash.cloneDeep)(flattenedItems);
53
+ flattenedItems[activeIndex].depth = projected.depth; // If same index, don't move the array, just copy it
54
+
55
+ const newFlattenedData = activeIndex !== overIndex ? sortable.arrayMove(flattenedItems, activeIndex, overIndex) : lodash.cloneDeep(flattenedItems);
73
56
  onReorder(newFlattenedData, {
74
57
  targetIndex: overIndex,
75
58
  fromIndex: activeIndex
76
- }, considerExpanding || "");
59
+ }, considerExpanding || '');
77
60
  }
78
- }, [handlePreviewDragEnd, flattenedItems, projected, onReorder, dropIndicatorPosition]);
79
- const onDragCancel = (0, import_react.useCallback)((e) => {
61
+ }, [handlePreviewDragEnd, isDropValid, flattenedItems, dropIndicatorPosition, projected, onReorder]);
62
+ const onDragCancel = react.useCallback(e => {
80
63
  handlePreviewDragCancel(e);
81
64
  }, [handlePreviewDragCancel]);
82
- return { onDragStart, onDragMove, onDragOver, onDragEnd, onDragCancel };
65
+ return {
66
+ onDragStart,
67
+ onDragMove,
68
+ onDragOver,
69
+ onDragEnd,
70
+ onDragCancel
71
+ };
83
72
  };
84
- module.exports = __toCommonJS(useTreeActionHandlers_exports);
85
- //# sourceMappingURL=useTreeActionHandlers.js.map
73
+
74
+ exports.useTreeActionHandlers = useTreeActionHandlers;
@@ -1,68 +1,55 @@
1
- var __create = Object.create;
2
- var __defProp = Object.defineProperty;
3
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
- var __getOwnPropNames = Object.getOwnPropertyNames;
5
- var __getProtoOf = Object.getPrototypeOf;
6
- var __hasOwnProp = Object.prototype.hasOwnProperty;
7
- var __markAsModule = (target) => __defProp(target, "__esModule", { value: true });
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __reExport = (target, module2, copyDefault, desc) => {
13
- if (module2 && typeof module2 === "object" || typeof module2 === "function") {
14
- for (let key of __getOwnPropNames(module2))
15
- if (!__hasOwnProp.call(target, key) && (copyDefault || key !== "default"))
16
- __defProp(target, key, { get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable });
17
- }
18
- return target;
19
- };
20
- var __toESM = (module2, isNodeMode) => {
21
- return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", !isNodeMode && module2 && module2.__esModule ? { get: () => module2.default, enumerable: true } : { value: module2, enumerable: true })), module2);
22
- };
23
- var __toCommonJS = /* @__PURE__ */ ((cache) => {
24
- return (module2, temp) => {
25
- return cache && cache.get(module2) || (temp = __reExport(__markAsModule({}), module2, 1), cache && cache.set(module2, temp), temp);
26
- };
27
- })(typeof WeakMap !== "undefined" ? /* @__PURE__ */ new WeakMap() : 0);
28
- var useTreeAnnouncements_exports = {};
29
- __export(useTreeAnnouncements_exports, {
30
- useTreeAnnouncements: () => useTreeAnnouncements
31
- });
32
- var React = __toESM(require("react"));
33
- var import_react = __toESM(require("react"));
34
- var import_constants = __toESM(require("./constants"));
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var react = require('react');
6
+ var constants = require('./constants.js');
7
+
35
8
  const useTreeAnnouncements = (visibleItemsDictionary, dropIndicatorPosition) => {
36
- const onDragStart = (0, import_react.useCallback)((id) => `Picked up draggable item from position ${visibleItemsDictionary[id].realIndex + 1}.`, [visibleItemsDictionary]);
37
- const onDragMove = (0, import_react.useCallback)((id, overId) => {
9
+ const onDragStart = react.useCallback(id => "Picked up draggable item from position ".concat(visibleItemsDictionary[id].realIndex + 1, "."), [visibleItemsDictionary]);
10
+ const onDragMove = react.useCallback((id, overId) => {
38
11
  if (overId) {
39
12
  const overIndex = visibleItemsDictionary[overId].realIndex + 1;
40
- if (dropIndicatorPosition === import_constants.DropIndicatorPosition.Inside) {
41
- return `Draggable item was moved inside the item at position ${overIndex}.`;
13
+
14
+ if (dropIndicatorPosition === constants.DropIndicatorPosition.Inside) {
15
+ return "Draggable item was moved inside the item at position ".concat(overIndex, ".");
42
16
  }
43
- if (dropIndicatorPosition === import_constants.DropIndicatorPosition.Before) {
44
- return `Draggable item was moved to position ${overIndex - 1}.`;
17
+
18
+ if (dropIndicatorPosition === constants.DropIndicatorPosition.Before) {
19
+ return "Draggable item was moved to position ".concat(overIndex - 1, ".");
45
20
  }
46
- return `Draggable item was moved to position ${overIndex}.`;
21
+
22
+ return "Draggable item was moved to position ".concat(overIndex, ".");
47
23
  }
48
- return `Draggable item is no longer over a droppable area.`;
24
+
25
+ return "Draggable item is no longer over a droppable area.";
49
26
  }, [visibleItemsDictionary, dropIndicatorPosition]);
50
27
  const onDragOver = onDragMove;
51
- const onDragEnd = (0, import_react.useCallback)((id, overId) => {
28
+ const onDragEnd = react.useCallback((id, overId) => {
52
29
  if (overId) {
53
30
  const overIndex = visibleItemsDictionary[overId].realIndex + 1;
54
- if (dropIndicatorPosition === import_constants.DropIndicatorPosition.Inside) {
55
- return `Draggable item was dropped inside the item at position ${overIndex}.`;
31
+
32
+ if (dropIndicatorPosition === constants.DropIndicatorPosition.Inside) {
33
+ return "Draggable item was dropped inside the item at position ".concat(overIndex, ".");
56
34
  }
57
- if (dropIndicatorPosition === import_constants.DropIndicatorPosition.Before) {
58
- return `Draggable item was dropped over position ${overIndex - 1}.`;
35
+
36
+ if (dropIndicatorPosition === constants.DropIndicatorPosition.Before) {
37
+ return "Draggable item was dropped over position ".concat(overIndex - 1, ".");
59
38
  }
60
- return `Draggable item was dropped over position ${overIndex}.`;
39
+
40
+ return "Draggable item was dropped over position ".concat(overIndex, ".");
61
41
  }
62
- return `Draggable item was dropped at it's original position.`;
42
+
43
+ return "Draggable item was dropped at it's original position.";
63
44
  }, [dropIndicatorPosition, visibleItemsDictionary]);
64
- const onDragCancel = (0, import_react.useCallback)((id) => `Dragging was cancelled. Draggable item from position ${visibleItemsDictionary[id].realIndex + 1} was dropped at it's initial position.`, [visibleItemsDictionary]);
65
- return { onDragStart, onDragOver, onDragMove, onDragEnd, onDragCancel };
45
+ const onDragCancel = react.useCallback(id => "Dragging was cancelled. Draggable item from position ".concat(visibleItemsDictionary[id].realIndex + 1, " was dropped at it's initial position."), [visibleItemsDictionary]);
46
+ return {
47
+ onDragStart,
48
+ onDragOver,
49
+ onDragMove,
50
+ onDragEnd,
51
+ onDragCancel
52
+ };
66
53
  };
67
- module.exports = __toCommonJS(useTreeAnnouncements_exports);
68
- //# sourceMappingURL=useTreeAnnouncements.js.map
54
+
55
+ exports.useTreeAnnouncements = useTreeAnnouncements;