@elliemae/ds-data-table 2.0.0-rc.1 → 2.0.0-rc.13

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 (138) hide show
  1. package/cjs/DataTableSchema.js +21 -12
  2. package/cjs/addons/Editables/TextEditableCell/TextEditableCell.js +16 -0
  3. package/cjs/addons/Filters/Components/CurrencyRangeFilter/index.js +24 -2
  4. package/cjs/addons/Filters/Components/DateRangeFilter/index.js +4 -1
  5. package/cjs/addons/Filters/Components/NumberRangeFilter/index.js +25 -3
  6. package/cjs/addons/Filters/Components/SingleDateFilter/index.js +4 -1
  7. package/cjs/addons/Filters/Components/index.js +0 -2
  8. package/cjs/addons/Filters/index.js +0 -2
  9. package/cjs/configs/usePaginationConfig.js +1 -1
  10. package/cjs/configs/useRowFlattenization.js +3 -3
  11. package/cjs/exported-related/EditableCell.js +13 -7
  12. package/cjs/exported-related/FilterPopover.js +17 -3
  13. package/cjs/exported-related/FilterTypes.js +0 -1
  14. package/cjs/exported-related/Filters/applyOutOfTheBoxFilters.js +0 -2
  15. package/cjs/exported-related/Filters/index.js +0 -2
  16. package/cjs/exported-related/index.js +0 -2
  17. package/cjs/helpers/refs-helpers.js +2 -2
  18. package/cjs/index.js +0 -2
  19. package/cjs/parts/FilterBar/FiltersBar.js +0 -2
  20. package/cjs/parts/FilterBar/components/index.js +0 -2
  21. package/cjs/parts/Filters/index.js +10 -12
  22. package/cjs/parts/Headers/HeaderCellGroup.js +4 -3
  23. package/cjs/parts/Headers/index.js +1 -1
  24. package/cjs/parts/Headers/useHeaderCellHandlers.js +4 -2
  25. package/cjs/parts/HoC/withConditionalDnDColumnContext.js +37 -16
  26. package/cjs/parts/HoC/withConditionalDnDRowContext.js +11 -12
  27. package/cjs/parts/HoC/withConditionalDnDSortableContext.js +1 -1
  28. package/cjs/parts/HoC/withDnDSortableColumnContext.js +5 -19
  29. package/cjs/parts/HoC/withDnDSortableRowContext.js +3 -17
  30. package/cjs/parts/Row.js +10 -10
  31. package/cjs/parts/Rows.js +1 -1
  32. package/cjs/parts/index.js +1 -1
  33. package/cjs/styled.js +18 -13
  34. package/esm/DataTableSchema.js +21 -12
  35. package/esm/addons/Editables/TextEditableCell/TextEditableCell.js +16 -0
  36. package/esm/addons/Filters/Components/CurrencyRangeFilter/index.js +24 -2
  37. package/esm/addons/Filters/Components/DateRangeFilter/index.js +4 -1
  38. package/esm/addons/Filters/Components/NumberRangeFilter/index.js +25 -3
  39. package/esm/addons/Filters/Components/SingleDateFilter/index.js +4 -1
  40. package/esm/addons/Filters/Components/index.js +0 -1
  41. package/esm/addons/Filters/index.js +0 -1
  42. package/esm/configs/usePaginationConfig.js +1 -1
  43. package/esm/configs/useRowFlattenization.js +3 -3
  44. package/esm/exported-related/EditableCell.js +13 -7
  45. package/esm/exported-related/FilterPopover.js +17 -3
  46. package/esm/exported-related/FilterTypes.js +0 -1
  47. package/esm/exported-related/Filters/applyOutOfTheBoxFilters.js +0 -2
  48. package/esm/exported-related/Filters/index.js +0 -1
  49. package/esm/exported-related/index.js +0 -1
  50. package/esm/helpers/refs-helpers.js +2 -2
  51. package/esm/index.js +0 -1
  52. package/esm/parts/FilterBar/FiltersBar.js +0 -2
  53. package/esm/parts/FilterBar/components/index.js +0 -1
  54. package/esm/parts/Filters/index.js +0 -2
  55. package/esm/parts/Headers/HeaderCellGroup.js +4 -4
  56. package/esm/parts/Headers/index.js +2 -2
  57. package/esm/parts/Headers/useHeaderCellHandlers.js +4 -2
  58. package/esm/parts/HoC/withConditionalDnDColumnContext.js +38 -17
  59. package/esm/parts/HoC/withConditionalDnDRowContext.js +12 -13
  60. package/esm/parts/HoC/withConditionalDnDSortableContext.js +1 -1
  61. package/esm/parts/HoC/withDnDSortableColumnContext.js +6 -20
  62. package/esm/parts/HoC/withDnDSortableRowContext.js +4 -18
  63. package/esm/parts/Row.js +7 -10
  64. package/esm/styled.js +18 -13
  65. package/package.json +26 -103
  66. package/types/DataTable.d.ts +245 -43
  67. package/types/DataTableSchema.d.ts +245 -43
  68. package/types/addons/Filters/Components/SelectFilter/components.d.ts +6 -6
  69. package/types/addons/Filters/Components/index.d.ts +0 -1
  70. package/types/exported-related/FilterTypes.d.ts +0 -1
  71. package/types/exported-related/Filters/index.d.ts +0 -1
  72. package/types/helpers/refs-helpers.d.ts +1 -1
  73. package/types/parts/FilterBar/components/index.d.ts +0 -1
  74. package/types/parts/FilterBar/styled.d.ts +165 -30
  75. package/types/parts/Headers/HeaderCellGroup.d.ts +4 -3
  76. package/types/parts/Row.d.ts +2 -1
  77. package/types/styled.d.ts +21 -19
  78. package/types/types/props.d.ts +2 -2
  79. package/cjs/addons/Filters/Components/TextInputFilter/index.js +0 -92
  80. package/cjs/exported-related/Filters/textFilterFn.js +0 -14
  81. package/cjs/helpers/dndkit/hierarchy/customCollisionDetection.js +0 -76
  82. package/cjs/helpers/dndkit/hierarchy/getHierarchyKeyboardCoordinates.js +0 -141
  83. package/cjs/helpers/dndkit/hierarchy/types.js +0 -2
  84. package/cjs/helpers/dndkit/hierarchy/useHierarchyActionHandlers.js +0 -55
  85. package/cjs/helpers/dndkit/hierarchy/useHierarchyAnnouncements.js +0 -36
  86. package/cjs/helpers/dndkit/hierarchy/useHierarchyDndkitConfig.js +0 -109
  87. package/cjs/helpers/dndkit/hierarchy/useHierarchyPreviewHandlers.js +0 -87
  88. package/cjs/helpers/dndkit/tree/customCollisionDetection.js +0 -98
  89. package/cjs/helpers/dndkit/tree/getTreeKeyboardCoordinates.js +0 -139
  90. package/cjs/helpers/dndkit/tree/types.js +0 -2
  91. package/cjs/helpers/dndkit/tree/useTreeActionHandlers.js +0 -75
  92. package/cjs/helpers/dndkit/tree/useTreeAnnouncements.js +0 -55
  93. package/cjs/helpers/dndkit/tree/useTreeDndkitConfig.js +0 -139
  94. package/cjs/helpers/dndkit/tree/useTreePreviewHandlers.js +0 -54
  95. package/cjs/helpers/dndkit/types.js +0 -2
  96. package/cjs/helpers/dndkit/utilities.js +0 -52
  97. package/cjs/parts/FilterBar/components/TextPill.js +0 -42
  98. package/cjs/parts/HoC/DragOverlayContext.js +0 -11
  99. package/esm/addons/Filters/Components/TextInputFilter/index.js +0 -84
  100. package/esm/exported-related/Filters/textFilterFn.js +0 -10
  101. package/esm/helpers/dndkit/hierarchy/customCollisionDetection.js +0 -72
  102. package/esm/helpers/dndkit/hierarchy/getHierarchyKeyboardCoordinates.js +0 -133
  103. package/esm/helpers/dndkit/hierarchy/types.js +0 -1
  104. package/esm/helpers/dndkit/hierarchy/useHierarchyActionHandlers.js +0 -51
  105. package/esm/helpers/dndkit/hierarchy/useHierarchyAnnouncements.js +0 -32
  106. package/esm/helpers/dndkit/hierarchy/useHierarchyDndkitConfig.js +0 -103
  107. package/esm/helpers/dndkit/hierarchy/useHierarchyPreviewHandlers.js +0 -83
  108. package/esm/helpers/dndkit/tree/customCollisionDetection.js +0 -94
  109. package/esm/helpers/dndkit/tree/getTreeKeyboardCoordinates.js +0 -131
  110. package/esm/helpers/dndkit/tree/types.js +0 -1
  111. package/esm/helpers/dndkit/tree/useTreeActionHandlers.js +0 -71
  112. package/esm/helpers/dndkit/tree/useTreeAnnouncements.js +0 -51
  113. package/esm/helpers/dndkit/tree/useTreeDndkitConfig.js +0 -133
  114. package/esm/helpers/dndkit/tree/useTreePreviewHandlers.js +0 -50
  115. package/esm/helpers/dndkit/types.js +0 -1
  116. package/esm/helpers/dndkit/utilities.js +0 -47
  117. package/esm/parts/FilterBar/components/TextPill.js +0 -34
  118. package/esm/parts/HoC/DragOverlayContext.js +0 -7
  119. package/types/addons/Filters/Components/TextInputFilter/index.d.ts +0 -3
  120. package/types/exported-related/Filters/textFilterFn.d.ts +0 -2
  121. package/types/helpers/dndkit/hierarchy/customCollisionDetection.d.ts +0 -3
  122. package/types/helpers/dndkit/hierarchy/getHierarchyKeyboardCoordinates.d.ts +0 -3
  123. package/types/helpers/dndkit/hierarchy/types.d.ts +0 -66
  124. package/types/helpers/dndkit/hierarchy/useHierarchyActionHandlers.d.ts +0 -2
  125. package/types/helpers/dndkit/hierarchy/useHierarchyAnnouncements.d.ts +0 -3
  126. package/types/helpers/dndkit/hierarchy/useHierarchyDndkitConfig.d.ts +0 -3
  127. package/types/helpers/dndkit/hierarchy/useHierarchyPreviewHandlers.d.ts +0 -2
  128. package/types/helpers/dndkit/tree/customCollisionDetection.d.ts +0 -4
  129. package/types/helpers/dndkit/tree/getTreeKeyboardCoordinates.d.ts +0 -3
  130. package/types/helpers/dndkit/tree/types.d.ts +0 -83
  131. package/types/helpers/dndkit/tree/useTreeActionHandlers.d.ts +0 -2
  132. package/types/helpers/dndkit/tree/useTreeAnnouncements.d.ts +0 -4
  133. package/types/helpers/dndkit/tree/useTreeDndkitConfig.d.ts +0 -3
  134. package/types/helpers/dndkit/tree/useTreePreviewHandlers.d.ts +0 -2
  135. package/types/helpers/dndkit/types.d.ts +0 -20
  136. package/types/helpers/dndkit/utilities.d.ts +0 -7
  137. package/types/parts/FilterBar/components/TextPill.d.ts +0 -2
  138. package/types/parts/HoC/DragOverlayContext.d.ts +0 -6
@@ -1,32 +0,0 @@
1
- import { useCallback } from 'react';
2
-
3
- const useHierarchyAnnouncements = visibleItemsDictionary => {
4
- const onDragStart = useCallback(id => "Picked up draggable item from position ".concat(visibleItemsDictionary[id].index + 1, "."), [visibleItemsDictionary]);
5
- const onDragMove = useCallback((id, overId) => {
6
- if (overId) {
7
- const overIndex = visibleItemsDictionary[overId].index + 1;
8
- return "Draggable item was moved to position ".concat(overIndex, ".");
9
- }
10
-
11
- return "Draggable item is no longer over a droppable area.";
12
- }, [visibleItemsDictionary]);
13
- const onDragOver = onDragMove;
14
- const onDragEnd = useCallback((id, overId) => {
15
- if (overId) {
16
- const overIndex = visibleItemsDictionary[overId].index + 1;
17
- return "Draggable item was dropped over position ".concat(overIndex, ".");
18
- }
19
-
20
- return "Draggable item was dropped at it's original position.";
21
- }, [visibleItemsDictionary]);
22
- const onDragCancel = useCallback(id => "Dragging was cancelled. Draggable item from position ".concat(visibleItemsDictionary[id].index + 1, " was dropped at it's initial position."), [visibleItemsDictionary]);
23
- return {
24
- onDragStart,
25
- onDragOver,
26
- onDragMove,
27
- onDragEnd,
28
- onDragCancel
29
- };
30
- };
31
-
32
- export { useHierarchyAnnouncements };
@@ -1,103 +0,0 @@
1
- import 'core-js/modules/esnext.async-iterator.filter.js';
2
- import 'core-js/modules/esnext.iterator.filter.js';
3
- import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
4
- import 'core-js/modules/web.dom-collections.iterator.js';
5
- import 'core-js/modules/esnext.async-iterator.map.js';
6
- import 'core-js/modules/esnext.iterator.map.js';
7
- import 'core-js/modules/esnext.async-iterator.find.js';
8
- import 'core-js/modules/esnext.iterator.constructor.js';
9
- import 'core-js/modules/esnext.iterator.find.js';
10
- import 'core-js/modules/esnext.async-iterator.for-each.js';
11
- import 'core-js/modules/esnext.iterator.for-each.js';
12
- import { useState, useMemo, useRef, useEffect } from 'react';
13
- import { LayoutMeasuringStrategy, useSensors, useSensor, PointerSensor, KeyboardSensor } from '@dnd-kit/core';
14
- import { useHierarchyActionHandlers } from './useHierarchyActionHandlers.js';
15
- import { useHierarchyPreviewHandlers } from './useHierarchyPreviewHandlers.js';
16
- import { getHierarchyKeyboardCoordinates } from './getHierarchyKeyboardCoordinates.js';
17
- import { customCollisionDetection } from './customCollisionDetection.js';
18
- import { useHierarchyAnnouncements } from './useHierarchyAnnouncements.js';
19
-
20
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (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 = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
23
- // if second parameter is true, the space will be done on the horizontal axis
24
-
25
- const adjustTranslate = function (_ref) {
26
- let {
27
- transform
28
- } = _ref;
29
- let isHorizontalDnD = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
30
-
31
- const newTransform = _objectSpread({}, transform);
32
-
33
- if (isHorizontalDnD) {
34
- newTransform.y = transform.y + 15;
35
- } else {
36
- newTransform.y = transform.y - 35;
37
- }
38
-
39
- return newTransform;
40
- };
41
-
42
- const layoutMeasuring = {
43
- strategy: LayoutMeasuringStrategy.Always
44
- };
45
-
46
- const useHierarchyDndkitConfig = _ref2 => {
47
- let {
48
- flattenedItems,
49
- isHorizontalDnD = false,
50
- onReorder
51
- } = _ref2;
52
- const [activeId, setActiveId] = useState(null);
53
- const [overId, setOverId] = useState(null);
54
- const dndItems = useMemo(() => flattenedItems.map(_ref3 => {
55
- let [item] = _ref3;
56
- return item;
57
- }), [flattenedItems]);
58
- const activeItem = useMemo(() => dndItems.find(item => item.id === activeId), [activeId, dndItems]);
59
- const itemsDictionary = useMemo(() => {
60
- const dictionary = {};
61
- dndItems.forEach(item => {
62
- dictionary[item.id] = item;
63
- });
64
- return dictionary;
65
- }, [dndItems]);
66
- const modifiers = useMemo(() => [options => adjustTranslate(options, isHorizontalDnD)], [isHorizontalDnD]);
67
- const sensorContext = useRef({
68
- items: dndItems
69
- });
70
- useEffect(() => {
71
- sensorContext.current = {
72
- items: dndItems
73
- };
74
- }, [dndItems]);
75
- const coordinateGetter = useMemo(() => getHierarchyKeyboardCoordinates(sensorContext, isHorizontalDnD), [isHorizontalDnD]);
76
- const sensors = useSensors(useSensor(PointerSensor), useSensor(KeyboardSensor, {
77
- coordinateGetter
78
- }));
79
- const dragPreviewHandlers = useHierarchyPreviewHandlers({
80
- setActiveId,
81
- setOverId
82
- });
83
- const dragActionHandlers = useHierarchyActionHandlers(_objectSpread(_objectSpread({}, dragPreviewHandlers), {}, {
84
- dndItems,
85
- onReorder
86
- }));
87
- const announcements = useHierarchyAnnouncements(itemsDictionary);
88
- const dndContextProps = useMemo(() => _objectSpread({
89
- announcements,
90
- modifiers,
91
- sensors,
92
- layoutMeasuring,
93
- collisionDetection: customCollisionDetection(activeId, activeItem === null || activeItem === void 0 ? void 0 : activeItem.parentId, dndItems)
94
- }, dragActionHandlers), [announcements, modifiers, sensors, activeId, activeItem === null || activeItem === void 0 ? void 0 : activeItem.parentId, dndItems, dragActionHandlers]);
95
- return {
96
- dndContextProps,
97
- activeId,
98
- overId,
99
- activeIndex: activeId ? activeItem.index : -1
100
- };
101
- };
102
-
103
- export { useHierarchyDndkitConfig as default };
@@ -1,83 +0,0 @@
1
- import { useCallback } from 'react';
2
- import { DATA_TESTID } from '../../../configs/constants.js';
3
- import 'core-js/modules/esnext.async-iterator.filter.js';
4
- import 'core-js/modules/esnext.iterator.constructor.js';
5
- import 'core-js/modules/esnext.iterator.filter.js';
6
- import 'core-js/modules/web.dom-collections.iterator.js';
7
- import 'core-js/modules/esnext.async-iterator.reduce.js';
8
- import 'core-js/modules/esnext.iterator.reduce.js';
9
- import 'react-virtual';
10
- import 'core-js/modules/esnext.async-iterator.for-each.js';
11
- import 'core-js/modules/esnext.iterator.for-each.js';
12
- import '../../../configs/useRowFlattenization.js';
13
- import '@babel/runtime/helpers/esm/defineProperty';
14
- import 'core-js/modules/esnext.async-iterator.map.js';
15
- import 'core-js/modules/esnext.iterator.map.js';
16
- import '@babel/runtime/helpers/esm/jsx';
17
- import '@elliemae/ds-icons';
18
- import 'styled-components';
19
- import '../../../styled.js';
20
- import 'react/jsx-runtime';
21
- import '@elliemae/ds-form';
22
- import '../../../parts/TableContent.js';
23
- import '@elliemae/ds-grid';
24
- import '@elliemae/ds-circular-progress-indicator';
25
- import '@elliemae/ds-system';
26
- import '@elliemae/ds-button';
27
- import '../../../DataTableContext.js';
28
- import '../../../parts/Row.js';
29
- import '../../../parts/Footer.js';
30
- import '../../../parts/HoC/SortableItemContext.js';
31
-
32
- const useHierarchyPreviewHandlers = _ref => {
33
- let {
34
- setOverId,
35
- setActiveId
36
- } = _ref;
37
- const resetState = useCallback(() => {
38
- setOverId(null);
39
- setActiveId(null);
40
- document.body.style.setProperty('cursor', '');
41
- const el = document.querySelector("[data-testid=\"".concat(DATA_TESTID.DATA_TABLE_SCROLLABLE_CONTAINER, "\"]"));
42
-
43
- el.onscroll = () => null;
44
- }, [setOverId, setActiveId]);
45
- const handlePreviewDragStart = useCallback(_ref2 => {
46
- let {
47
- active: {
48
- id
49
- }
50
- } = _ref2;
51
- setActiveId(id);
52
- setOverId(id);
53
- document.body.style.setProperty('cursor', 'grabbing');
54
- const el = document.querySelector("[data-testid=\"".concat(DATA_TESTID.DATA_TABLE_SCROLLABLE_CONTAINER, "\"]"));
55
- const y = el.scrollTop;
56
-
57
- el.onscroll = () => el.scrollTo(0, y);
58
- }, [setActiveId, setOverId]);
59
- const handlePreviewDragMove = useCallback(() => null, []);
60
- const handlePreviewDragOver = useCallback(_ref3 => {
61
- var _over$id;
62
-
63
- let {
64
- over
65
- } = _ref3;
66
- setOverId((_over$id = over === null || over === void 0 ? void 0 : over.id) !== null && _over$id !== void 0 ? _over$id : null);
67
- }, [setOverId]);
68
- const handlePreviewDragEnd = useCallback(() => {
69
- resetState();
70
- }, [resetState]);
71
- const handlePreviewDragCancel = useCallback(() => {
72
- resetState();
73
- }, [resetState]);
74
- return {
75
- handlePreviewDragStart,
76
- handlePreviewDragMove,
77
- handlePreviewDragOver,
78
- handlePreviewDragEnd,
79
- handlePreviewDragCancel
80
- };
81
- };
82
-
83
- export { useHierarchyPreviewHandlers };
@@ -1,94 +0,0 @@
1
- import 'core-js/modules/esnext.async-iterator.find.js';
2
- import 'core-js/modules/esnext.iterator.constructor.js';
3
- import 'core-js/modules/esnext.iterator.find.js';
4
- import 'core-js/modules/web.dom-collections.iterator.js';
5
- import 'core-js/modules/esnext.async-iterator.reduce.js';
6
- import 'core-js/modules/esnext.iterator.reduce.js';
7
- import { DropIndicatorPosition } from '../../../parts/HoC/SortableItemContext.js';
8
-
9
- const DUMMY_ID = 'DUMMY_ID_INTERNAL_USE_ONLY';
10
- const RECT_UP = {
11
- offsetTop: -Infinity,
12
- offsetLeft: 0,
13
- // Doesn't matter,
14
- width: 0,
15
- // Doesn't matter
16
- height: 0 // Doesn't matter
17
-
18
- };
19
- const RECT_DOWN = {
20
- offsetTop: Infinity,
21
- offsetLeft: 0,
22
- // Doesn't matter,
23
- width: 0,
24
- // Doesn't matter
25
- height: 0 // Doesn't matter
26
-
27
- }; // Percentage of height to take into consideration when looking for colliding rects
28
-
29
- const thresholdRatio = 0.2; // Percentage to be inside
30
-
31
- const insideThreshold = 0.7;
32
- const customCollisionDetection = (activeId, visibleItemsDictionary, setDropIndicatorPosition, maxDragAndDropLevel, lastPosition, setLastPosition) => (rects, rect) => {
33
- const originalRect = rects.find(_ref => {
34
- let [rectId] = _ref;
35
- return rectId === activeId;
36
- }); // We first check if the item was moved up or down
37
- // This modifies how to search the matching colliding rect
38
-
39
- let isUp = lastPosition === 'up';
40
-
41
- if (originalRect) {
42
- isUp = originalRect[1].offsetTop > rect.top;
43
- } // Threshold
44
-
45
-
46
- const threshold = rect.height * thresholdRatio;
47
- let collidingRect = null;
48
-
49
- if (isUp) {
50
- // Up -- We need to find the first rectangle downwards
51
- collidingRect = rects.reduce((acc, _ref2) => {
52
- let [rectID, rectData] = _ref2;
53
-
54
- if (rectData.offsetTop + threshold > rect.top && rectData.offsetTop < acc[1].offsetTop) {
55
- return [rectID, rectData];
56
- }
57
-
58
- return acc;
59
- }, [DUMMY_ID, RECT_DOWN]);
60
- } else {
61
- // Down -- We need to find the first rectangle upwards
62
- collidingRect = rects.reduce((acc, _ref3) => {
63
- let [rectID, rectData] = _ref3;
64
-
65
- if (rectData.offsetTop - threshold < rect.top && rectData.offsetTop > acc[1].offsetTop) {
66
- return [rectID, rectData];
67
- }
68
-
69
- return acc;
70
- }, [DUMMY_ID, RECT_UP]);
71
- } // If we didn't find a match, return null
72
-
73
-
74
- if (collidingRect[0] === DUMMY_ID) {
75
- return null;
76
- } // Calculate the intersection interval
77
-
78
-
79
- const [top, bottom] = [Math.max(rect.top, collidingRect[1].offsetTop), Math.min(rect.bottom, collidingRect[1].offsetTop + collidingRect[1].height)]; // Calculate the percentage of intersection
80
-
81
- const intersectionPercentage = Math.abs(bottom - top) / collidingRect[1].height;
82
-
83
- if (intersectionPercentage > insideThreshold && visibleItemsDictionary[collidingRect[0]].depth + 1 <= maxDragAndDropLevel && collidingRect[0] !== activeId) {
84
- setDropIndicatorPosition(DropIndicatorPosition.Inside);
85
- } else {
86
- setDropIndicatorPosition(isUp ? DropIndicatorPosition.Before : DropIndicatorPosition.After);
87
- }
88
-
89
- if (isUp && lastPosition !== 'up') setLastPosition('up');else if (!isUp && lastPosition !== 'down') setLastPosition('down'); // Return the id of the match rectangle
90
-
91
- return collidingRect[0];
92
- };
93
-
94
- export { customCollisionDetection };
@@ -1,131 +0,0 @@
1
- import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
2
- import 'core-js/modules/esnext.async-iterator.for-each.js';
3
- import 'core-js/modules/esnext.iterator.constructor.js';
4
- import 'core-js/modules/esnext.iterator.for-each.js';
5
- import 'core-js/modules/web.dom-collections.iterator.js';
6
- import 'core-js/modules/esnext.async-iterator.find.js';
7
- import 'core-js/modules/esnext.iterator.find.js';
8
- import 'core-js/modules/esnext.async-iterator.filter.js';
9
- import 'core-js/modules/esnext.iterator.filter.js';
10
- import { KeyboardCode, getViewRect, closestCorners } from '@dnd-kit/core';
11
- import { DropIndicatorPosition } from '../../../parts/HoC/SortableItemContext.js';
12
-
13
- function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
14
-
15
- function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
16
- const directions = [KeyboardCode.Down, KeyboardCode.Right, KeyboardCode.Up, KeyboardCode.Left];
17
- const horizontal = [KeyboardCode.Left, KeyboardCode.Right]; // const vertical: string[] = [KeyboardCode.Up, KeyboardCode.Down];
18
-
19
- const getVerticalKeyboardCoordinates = _ref => {
20
- let {
21
- items,
22
- active,
23
- over,
24
- event,
25
- currentCoordinates,
26
- droppableContainers,
27
- translatedRect,
28
- dropIndicatorPosition,
29
- maxDragAndDropLevel
30
- } = _ref;
31
- if (horizontal.includes(event.code)) return undefined;
32
- const activeRect = droppableContainers[active].rect.current;
33
- const overRect = over.rect;
34
- const layoutRects = []; // Get the reacheable rects depending on the arrow key pressed
35
-
36
- Object.entries(droppableContainers).forEach(_ref2 => {
37
- let [id, container] = _ref2;
38
-
39
- if (container !== null && container !== void 0 && container.disabled || !overRect) {
40
- return;
41
- }
42
-
43
- const node = container === null || container === void 0 ? void 0 : container.node.current;
44
-
45
- if (!node) {
46
- return;
47
- }
48
-
49
- const rect = getViewRect(node);
50
-
51
- if (event.code === KeyboardCode.Down && translatedRect.top - 2 <= rect.top) {
52
- layoutRects.push([id, rect]);
53
- } else if (event.code === KeyboardCode.Up && translatedRect.top >= rect.top) {
54
- layoutRects.push([id, rect]);
55
- }
56
- });
57
- const closestId = closestCorners(layoutRects, translatedRect);
58
- if (!closestId) return undefined;
59
- const closestItem = items.find(item => item.uid === closestId);
60
- const closestRect = getViewRect(droppableContainers[closestId].node.current);
61
-
62
- if (event.code === KeyboardCode.Up) {
63
- // If the drop indicator is inside (or over ourselves)
64
- // We are gonna go to the before position
65
- // Else we are gonna go inside the over rect
66
- if (dropIndicatorPosition === DropIndicatorPosition.Inside || closestId === active || closestItem.depth + 1 > maxDragAndDropLevel) {
67
- return _objectSpread(_objectSpread({}, currentCoordinates), {}, {
68
- y: closestRect.top - translatedRect.height / 2
69
- });
70
- }
71
-
72
- return _objectSpread(_objectSpread({}, currentCoordinates), {}, {
73
- y: closestRect.top + Math.abs(closestRect.height - activeRect.height) / 2
74
- });
75
- } // If the drop indicator is inside (or over ourselves)
76
- // We are gonna go to the after position
77
- // Else we are gonna go inside the over rect
78
-
79
-
80
- if (dropIndicatorPosition === DropIndicatorPosition.Inside || closestId === active || closestItem.depth + 1 > maxDragAndDropLevel) {
81
- return _objectSpread(_objectSpread({}, currentCoordinates), {}, {
82
- y: closestRect.top + translatedRect.height / 2
83
- });
84
- }
85
-
86
- return _objectSpread(_objectSpread({}, currentCoordinates), {}, {
87
- y: closestRect.top + Math.abs(closestRect.height - activeRect.height) / 2
88
- });
89
- };
90
-
91
- const getTreeKeyboardCoordinates = (context, isHorizontalDnD, maxDragAndDropLevel) => (event, _ref3) => {
92
- let {
93
- active,
94
- currentCoordinates,
95
- context: {
96
- over,
97
- translatedRect,
98
- droppableContainers
99
- }
100
- } = _ref3;
101
-
102
- if (directions.includes(event.code)) {
103
- if (!translatedRect) {
104
- return undefined;
105
- }
106
-
107
- const {
108
- current: {
109
- items,
110
- dropIndicatorPosition
111
- }
112
- } = context;
113
- const args = {
114
- items,
115
- active,
116
- over,
117
- event,
118
- currentCoordinates,
119
- droppableContainers,
120
- translatedRect,
121
- dropIndicatorPosition,
122
- maxDragAndDropLevel
123
- };
124
- if (isHorizontalDnD) return undefined;
125
- return getVerticalKeyboardCoordinates(args);
126
- }
127
-
128
- return undefined;
129
- };
130
-
131
- export { getTreeKeyboardCoordinates };
@@ -1 +0,0 @@
1
-
@@ -1,71 +0,0 @@
1
- import { arrayMove } from '@dnd-kit/sortable';
2
- import { cloneDeep } from 'lodash';
3
- import { useCallback } from 'react';
4
- import { DropIndicatorPosition } from '../../../parts/HoC/SortableItemContext.js';
5
-
6
- const useTreeActionHandlers = _ref => {
7
- let {
8
- handlePreviewDragStart,
9
- handlePreviewDragMove,
10
- handlePreviewDragOver,
11
- handlePreviewDragEnd,
12
- handlePreviewDragCancel,
13
- onReorder,
14
- flattenedItems,
15
- projected,
16
- dropIndicatorPosition
17
- } = _ref;
18
- const onDragStart = useCallback(e => {
19
- handlePreviewDragStart(e);
20
- }, [handlePreviewDragStart]);
21
- const onDragMove = useCallback(e => {
22
- handlePreviewDragMove(e);
23
- }, [handlePreviewDragMove]);
24
- const onDragOver = useCallback(e => {
25
- handlePreviewDragOver(e);
26
- }, [handlePreviewDragOver]);
27
- const onDragEnd = useCallback(e => {
28
- handlePreviewDragEnd(e);
29
- const {
30
- active,
31
- over
32
- } = e;
33
- if (over === null) return;
34
- const activeIndex = flattenedItems.findIndex(item => item.uid === active.id);
35
- let considerExpanding = null;
36
- let overIndex = flattenedItems.findIndex(item => item.uid === over.id); // If drop indicator is inside, then put it last,
37
- // It will be reconstructed well later
38
-
39
- if (dropIndicatorPosition === DropIndicatorPosition.Inside) {
40
- var _flattenedItems$overI, _flattenedItems$overI2;
41
-
42
- considerExpanding = over.id;
43
- overIndex = flattenedItems[overIndex].realIndex + ((_flattenedItems$overI = (_flattenedItems$overI2 = flattenedItems[overIndex].original.subRows) === null || _flattenedItems$overI2 === void 0 ? void 0 : _flattenedItems$overI2.length) !== null && _flattenedItems$overI !== void 0 ? _flattenedItems$overI : 0) + 1;
44
- } // If we are dropping the item in a new position, or new depth
45
-
46
-
47
- if (activeIndex !== overIndex || flattenedItems[activeIndex].depth !== projected.depth) {
48
- // Change parent and depth from projected data
49
- flattenedItems[activeIndex].parentId = projected.parentId;
50
- flattenedItems[activeIndex].depth = projected.depth; // If same index, don't move the array, just copy it
51
-
52
- const newFlattenedData = activeIndex !== overIndex ? arrayMove(flattenedItems, activeIndex, overIndex) : cloneDeep(flattenedItems);
53
- onReorder(newFlattenedData, {
54
- targetIndex: overIndex,
55
- fromIndex: activeIndex
56
- }, considerExpanding);
57
- }
58
- }, [handlePreviewDragEnd, flattenedItems, projected, onReorder, dropIndicatorPosition]);
59
- const onDragCancel = useCallback(e => {
60
- handlePreviewDragCancel(e);
61
- }, [handlePreviewDragCancel]);
62
- return {
63
- onDragStart,
64
- onDragMove,
65
- onDragOver,
66
- onDragEnd,
67
- onDragCancel
68
- };
69
- };
70
-
71
- export { useTreeActionHandlers };
@@ -1,51 +0,0 @@
1
- import { useCallback } from 'react';
2
- import { DropIndicatorPosition } from '../../../parts/HoC/SortableItemContext.js';
3
-
4
- const useTreeAnnouncements = (visibleItemsDictionary, dropIndicatorPosition) => {
5
- const onDragStart = useCallback(id => "Picked up draggable item from position ".concat(visibleItemsDictionary[id].realIndex + 1, "."), [visibleItemsDictionary]);
6
- const onDragMove = useCallback((id, overId) => {
7
- if (overId) {
8
- const overIndex = visibleItemsDictionary[overId].realIndex + 1;
9
-
10
- if (dropIndicatorPosition === DropIndicatorPosition.Inside) {
11
- return "Draggable item was moved inside the item at position ".concat(overIndex, ".");
12
- }
13
-
14
- if (dropIndicatorPosition === DropIndicatorPosition.Before) {
15
- return "Draggable item was moved to position ".concat(overIndex - 1, ".");
16
- }
17
-
18
- return "Draggable item was moved to position ".concat(overIndex, ".");
19
- }
20
-
21
- return "Draggable item is no longer over a droppable area.";
22
- }, [visibleItemsDictionary, dropIndicatorPosition]);
23
- const onDragOver = onDragMove;
24
- const onDragEnd = useCallback((id, overId) => {
25
- if (overId) {
26
- const overIndex = visibleItemsDictionary[overId].realIndex + 1;
27
-
28
- if (dropIndicatorPosition === DropIndicatorPosition.Inside) {
29
- return "Draggable item was dropped inside the item at position ".concat(overIndex, ".");
30
- }
31
-
32
- if (dropIndicatorPosition === DropIndicatorPosition.Before) {
33
- return "Draggable item was dropped over position ".concat(overIndex - 1, ".");
34
- }
35
-
36
- return "Draggable item was dropped over position ".concat(overIndex, ".");
37
- }
38
-
39
- return "Draggable item was dropped at it's original position.";
40
- }, [dropIndicatorPosition, visibleItemsDictionary]);
41
- const onDragCancel = useCallback(id => "Dragging was cancelled. Draggable item from position ".concat(visibleItemsDictionary[id].realIndex + 1, " was dropped at it's initial position."), [visibleItemsDictionary]);
42
- return {
43
- onDragStart,
44
- onDragOver,
45
- onDragMove,
46
- onDragEnd,
47
- onDragCancel
48
- };
49
- };
50
-
51
- export { useTreeAnnouncements };