@elliemae/ds-treeview 2.2.0-alpha.5 → 2.2.0-beta.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 (178) hide show
  1. package/cjs/TreeView.js +31 -49
  2. package/cjs/TreeViewContext.js +35 -53
  3. package/cjs/config/cssClassesConstants.js +13 -41
  4. package/cjs/config/useTreeview.js +80 -108
  5. package/cjs/index.js +27 -37
  6. package/cjs/parts/CheckboxSelectable.js +59 -70
  7. package/cjs/parts/ChildrenCountDisplayer.js +28 -45
  8. package/cjs/parts/ExpandCaret.js +83 -85
  9. package/cjs/parts/Icon.js +31 -46
  10. package/cjs/parts/NestingSpace.js +35 -43
  11. package/cjs/parts/RadioSelectable.js +37 -52
  12. package/cjs/parts/TreeItem.js +147 -128
  13. package/cjs/parts/TreeItemText.js +95 -88
  14. package/cjs/parts/TreeList.js +130 -117
  15. package/cjs/plugins/dnd/TreeDndPlugin.js +36 -51
  16. package/cjs/plugins/dnd/index.js +10 -28
  17. package/cjs/plugins/index.js +22 -34
  18. package/cjs/plugins/roving/TreeRovingPlugin.js +7 -35
  19. package/cjs/plugins/roving/index.js +9 -28
  20. package/cjs/plugins/searchable/SearchableTreePlugin.js +7 -35
  21. package/cjs/plugins/searchable/index.js +9 -28
  22. package/cjs/plugins/selectable/SelectablePluginTree.js +7 -35
  23. package/cjs/plugins/selectable/index.js +9 -28
  24. package/cjs/plugins/toolbar/TreeToolbarPlugin.js +7 -35
  25. package/cjs/plugins/toolbar/index.js +9 -28
  26. package/cjs/plugins/tree/TreeDataPlugin.js +7 -35
  27. package/cjs/plugins/tree/index.js +9 -28
  28. package/cjs/plugins/virtualization/TreeVirtualizationPlugin.js +7 -35
  29. package/cjs/plugins/virtualization/index.js +9 -28
  30. package/cjs/react-desc-prop-types.js +53 -82
  31. package/cjs/related-components/TreeViewSearchBar.js +40 -42
  32. package/cjs/sharedTypes.js +2 -27
  33. package/cjs/utils/array-helpers.js +11 -35
  34. package/cjs/utils/dnd-helpers.js +84 -90
  35. package/cjs/utils/group-expands-helpers.js +59 -86
  36. package/cjs/utils/keyboard-helpers.js +88 -84
  37. package/cjs/utils/object-helpers.js +36 -43
  38. package/cjs/utils/refs-helpers.js +22 -43
  39. package/cjs/utils/selectable-helper.js +53 -61
  40. package/cjs/utils/string-helpers.js +7 -35
  41. package/cjs/utils/tree-helpers.js +135 -105
  42. package/cjs/utils/useDnDHelpers.js +118 -97
  43. package/cjs/utils/useInstanceRefActions.js +43 -54
  44. package/cjs/utils/useTree.js +78 -76
  45. package/esm/TreeView.js +20 -18
  46. package/esm/TreeViewContext.js +29 -24
  47. package/esm/config/cssClassesConstants.js +6 -12
  48. package/esm/config/useTreeview.js +54 -61
  49. package/esm/index.js +9 -8
  50. package/esm/parts/CheckboxSelectable.js +46 -36
  51. package/esm/parts/ChildrenCountDisplayer.js +20 -16
  52. package/esm/parts/ExpandCaret.js +72 -54
  53. package/esm/parts/Icon.js +22 -16
  54. package/esm/parts/NestingSpace.js +27 -14
  55. package/esm/parts/RadioSelectable.js +28 -20
  56. package/esm/parts/TreeItem.js +127 -91
  57. package/esm/parts/TreeItemText.js +85 -58
  58. package/esm/parts/TreeList.js +117 -88
  59. package/esm/plugins/dnd/TreeDndPlugin.js +26 -21
  60. package/esm/plugins/dnd/index.js +1 -3
  61. package/esm/plugins/index.js +7 -9
  62. package/esm/plugins/roving/TreeRovingPlugin.js +3 -6
  63. package/esm/plugins/roving/index.js +1 -3
  64. package/esm/plugins/searchable/SearchableTreePlugin.js +3 -6
  65. package/esm/plugins/searchable/index.js +1 -3
  66. package/esm/plugins/selectable/SelectablePluginTree.js +3 -6
  67. package/esm/plugins/selectable/index.js +1 -3
  68. package/esm/plugins/toolbar/TreeToolbarPlugin.js +3 -6
  69. package/esm/plugins/toolbar/index.js +1 -3
  70. package/esm/plugins/tree/TreeDataPlugin.js +3 -6
  71. package/esm/plugins/tree/index.js +1 -3
  72. package/esm/plugins/virtualization/TreeVirtualizationPlugin.js +3 -6
  73. package/esm/plugins/virtualization/index.js +1 -3
  74. package/esm/react-desc-prop-types.js +43 -47
  75. package/esm/related-components/TreeViewSearchBar.js +32 -13
  76. package/esm/sharedTypes.js +1 -2
  77. package/esm/utils/array-helpers.js +6 -6
  78. package/esm/utils/dnd-helpers.js +73 -58
  79. package/esm/utils/group-expands-helpers.js +46 -56
  80. package/esm/utils/keyboard-helpers.js +72 -45
  81. package/esm/utils/object-helpers.js +31 -14
  82. package/esm/utils/refs-helpers.js +19 -15
  83. package/esm/utils/selectable-helper.js +43 -32
  84. package/esm/utils/string-helpers.js +3 -6
  85. package/esm/utils/tree-helpers.js +119 -74
  86. package/esm/utils/useDnDHelpers.js +106 -60
  87. package/esm/utils/useInstanceRefActions.js +35 -21
  88. package/esm/utils/useTree.js +57 -35
  89. package/package.json +10 -10
  90. package/types/TreeView.d.ts +1 -1
  91. package/cjs/TreeView.js.map +0 -7
  92. package/cjs/TreeViewContext.js.map +0 -7
  93. package/cjs/config/cssClassesConstants.js.map +0 -7
  94. package/cjs/config/useTreeview.js.map +0 -7
  95. package/cjs/index.js.map +0 -7
  96. package/cjs/parts/CheckboxSelectable.js.map +0 -7
  97. package/cjs/parts/ChildrenCountDisplayer.js.map +0 -7
  98. package/cjs/parts/ExpandCaret.js.map +0 -7
  99. package/cjs/parts/Icon.js.map +0 -7
  100. package/cjs/parts/NestingSpace.js.map +0 -7
  101. package/cjs/parts/RadioSelectable.js.map +0 -7
  102. package/cjs/parts/TreeItem.js.map +0 -7
  103. package/cjs/parts/TreeItemText.js.map +0 -7
  104. package/cjs/parts/TreeList.js.map +0 -7
  105. package/cjs/plugins/dnd/TreeDndPlugin.js.map +0 -7
  106. package/cjs/plugins/dnd/index.js.map +0 -7
  107. package/cjs/plugins/index.js.map +0 -7
  108. package/cjs/plugins/roving/TreeRovingPlugin.js.map +0 -7
  109. package/cjs/plugins/roving/index.js.map +0 -7
  110. package/cjs/plugins/searchable/SearchableTreePlugin.js.map +0 -7
  111. package/cjs/plugins/searchable/index.js.map +0 -7
  112. package/cjs/plugins/selectable/SelectablePluginTree.js.map +0 -7
  113. package/cjs/plugins/selectable/index.js.map +0 -7
  114. package/cjs/plugins/toolbar/TreeToolbarPlugin.js.map +0 -7
  115. package/cjs/plugins/toolbar/index.js.map +0 -7
  116. package/cjs/plugins/tree/TreeDataPlugin.js.map +0 -7
  117. package/cjs/plugins/tree/index.js.map +0 -7
  118. package/cjs/plugins/virtualization/TreeVirtualizationPlugin.js.map +0 -7
  119. package/cjs/plugins/virtualization/index.js.map +0 -7
  120. package/cjs/react-desc-prop-types.js.map +0 -7
  121. package/cjs/related-components/TreeViewSearchBar.js.map +0 -7
  122. package/cjs/sharedTypes.js.map +0 -7
  123. package/cjs/utils/array-helpers.js.map +0 -7
  124. package/cjs/utils/dnd-helpers.js.map +0 -7
  125. package/cjs/utils/group-expands-helpers.js.map +0 -7
  126. package/cjs/utils/keyboard-helpers.js.map +0 -7
  127. package/cjs/utils/object-helpers.js.map +0 -7
  128. package/cjs/utils/refs-helpers.js.map +0 -7
  129. package/cjs/utils/selectable-helper.js.map +0 -7
  130. package/cjs/utils/string-helpers.js.map +0 -7
  131. package/cjs/utils/tree-helpers.js.map +0 -7
  132. package/cjs/utils/useDnDHelpers.js.map +0 -7
  133. package/cjs/utils/useInstanceRefActions.js.map +0 -7
  134. package/cjs/utils/useTree.js.map +0 -7
  135. package/esm/TreeView.js.map +0 -7
  136. package/esm/TreeViewContext.js.map +0 -7
  137. package/esm/config/cssClassesConstants.js.map +0 -7
  138. package/esm/config/useTreeview.js.map +0 -7
  139. package/esm/index.js.map +0 -7
  140. package/esm/parts/CheckboxSelectable.js.map +0 -7
  141. package/esm/parts/ChildrenCountDisplayer.js.map +0 -7
  142. package/esm/parts/ExpandCaret.js.map +0 -7
  143. package/esm/parts/Icon.js.map +0 -7
  144. package/esm/parts/NestingSpace.js.map +0 -7
  145. package/esm/parts/RadioSelectable.js.map +0 -7
  146. package/esm/parts/TreeItem.js.map +0 -7
  147. package/esm/parts/TreeItemText.js.map +0 -7
  148. package/esm/parts/TreeList.js.map +0 -7
  149. package/esm/plugins/dnd/TreeDndPlugin.js.map +0 -7
  150. package/esm/plugins/dnd/index.js.map +0 -7
  151. package/esm/plugins/index.js.map +0 -7
  152. package/esm/plugins/roving/TreeRovingPlugin.js.map +0 -7
  153. package/esm/plugins/roving/index.js.map +0 -7
  154. package/esm/plugins/searchable/SearchableTreePlugin.js.map +0 -7
  155. package/esm/plugins/searchable/index.js.map +0 -7
  156. package/esm/plugins/selectable/SelectablePluginTree.js.map +0 -7
  157. package/esm/plugins/selectable/index.js.map +0 -7
  158. package/esm/plugins/toolbar/TreeToolbarPlugin.js.map +0 -7
  159. package/esm/plugins/toolbar/index.js.map +0 -7
  160. package/esm/plugins/tree/TreeDataPlugin.js.map +0 -7
  161. package/esm/plugins/tree/index.js.map +0 -7
  162. package/esm/plugins/virtualization/TreeVirtualizationPlugin.js.map +0 -7
  163. package/esm/plugins/virtualization/index.js.map +0 -7
  164. package/esm/react-desc-prop-types.js.map +0 -7
  165. package/esm/related-components/TreeViewSearchBar.js.map +0 -7
  166. package/esm/sharedTypes.js.map +0 -7
  167. package/esm/utils/array-helpers.js.map +0 -7
  168. package/esm/utils/dnd-helpers.js.map +0 -7
  169. package/esm/utils/group-expands-helpers.js.map +0 -7
  170. package/esm/utils/keyboard-helpers.js.map +0 -7
  171. package/esm/utils/object-helpers.js.map +0 -7
  172. package/esm/utils/refs-helpers.js.map +0 -7
  173. package/esm/utils/selectable-helper.js.map +0 -7
  174. package/esm/utils/string-helpers.js.map +0 -7
  175. package/esm/utils/tree-helpers.js.map +0 -7
  176. package/esm/utils/useDnDHelpers.js.map +0 -7
  177. package/esm/utils/useInstanceRefActions.js.map +0 -7
  178. package/esm/utils/useTree.js.map +0 -7
@@ -1,5 +1,6 @@
1
- import * as React from "react";
2
- import { getItemsParentNode, itemsShareSameParent } from "./tree-helpers";
1
+ import { getItemsParentNode, itemsShareSameParent } from './tree-helpers.js';
2
+
3
+ /* eslint-disable max-lines */
3
4
  const keyCodes = {
4
5
  lift: [32, 13],
5
6
  drop: [32, 13],
@@ -7,49 +8,58 @@ const keyCodes = {
7
8
  up: [38, 37],
8
9
  down: [40, 39]
9
10
  };
10
- const sameParentAsHoverItemDrop = ({
11
- isBefore,
12
- isAfter,
13
- draggedItem,
14
- overItem,
15
- movementDirection
16
- }) => {
11
+ const sameParentAsHoverItemDrop = _ref => {
12
+ let {
13
+ isBefore,
14
+ isAfter,
15
+ draggedItem,
16
+ overItem,
17
+ movementDirection
18
+ } = _ref;
17
19
  const hoveredItemNodeNestedIndex = overItem.node.getIndex();
18
20
  let newParentNode = getItemsParentNode([overItem], true);
19
- const { treeDepth: draggedItemTreeDepth } = draggedItem;
20
- const { treeDepth: overItemTreeDepth } = overItem;
21
- const directionOffset = draggedItemTreeDepth <= overItemTreeDepth && movementDirection === "topToBottom" ? -1 : 0;
21
+ const {
22
+ treeDepth: draggedItemTreeDepth
23
+ } = draggedItem;
24
+ const {
25
+ treeDepth: overItemTreeDepth
26
+ } = overItem;
27
+ const directionOffset = // we don't apply the offset for direction
28
+ // if moving from less nested to more nested
29
+ // or moving bottom to top
30
+ // the offset is required when moving elemnts down in their nest level
31
+ draggedItemTreeDepth <= overItemTreeDepth && movementDirection === 'topToBottom' ? -1 : 0;
22
32
  let newNestedIndex;
23
- if (isBefore)
24
- newNestedIndex = hoveredItemNodeNestedIndex + directionOffset;
25
- else if (isAfter)
26
- newNestedIndex = hoveredItemNodeNestedIndex + 1 + directionOffset;
27
- else {
28
- newNestedIndex = overItem.children.length;
33
+ if (isBefore) newNestedIndex = hoveredItemNodeNestedIndex + directionOffset;else if (isAfter) newNestedIndex = hoveredItemNodeNestedIndex + 1 + directionOffset;else {
34
+ newNestedIndex = overItem.children.length; // append as last child of the group
35
+
29
36
  newParentNode = overItem.node;
30
37
  }
31
- if (newNestedIndex < 0)
32
- newNestedIndex = 0;
38
+ if (newNestedIndex < 0) newNestedIndex = 0;
33
39
  return {
34
40
  newNestedIndex,
35
41
  newParentNode
36
42
  };
37
43
  };
38
- const inferHoverItemKinshipDrop = ({
39
- isBefore,
40
- isAfter,
41
- draggedItem,
42
- overItem,
43
- movementDirection
44
- }) => {
44
+ const inferHoverItemKinshipDrop = _ref2 => {
45
+ let {
46
+ isBefore,
47
+ isAfter,
48
+ draggedItem,
49
+ overItem,
50
+ movementDirection
51
+ } = _ref2;
45
52
  const hoverItemModel = overItem.node.model;
46
53
  const isGroupAndIsExpanded = hoverItemModel.isExpanded && hoverItemModel.children.length > 0;
54
+
47
55
  if (isAfter && isGroupAndIsExpanded) {
48
56
  return {
49
57
  newNestedIndex: 0,
58
+ // append after the group, so basically as first child
50
59
  newParentNode: overItem.node
51
60
  };
52
61
  }
62
+
53
63
  if (isBefore || isAfter && !isGroupAndIsExpanded) {
54
64
  return sameParentAsHoverItemDrop({
55
65
  isBefore,
@@ -58,46 +68,56 @@ const inferHoverItemKinshipDrop = ({
58
68
  overItem,
59
69
  movementDirection
60
70
  });
61
- }
71
+ } // drop inside
72
+
73
+
62
74
  return {
63
75
  newNestedIndex: overItem.children.length,
76
+ // append as last child of the group
64
77
  newParentNode: overItem.node
65
78
  };
66
79
  };
67
- const isDropValid = ({
68
- isBefore,
69
- isAfter,
70
- draggedItem,
71
- overItem,
72
- restrictDragAndDrop
73
- }) => {
74
- const { id: movedId } = draggedItem;
75
- const { id: hoverId } = overItem;
80
+ const isDropValid = _ref3 => {
81
+ let {
82
+ isBefore,
83
+ isAfter,
84
+ draggedItem,
85
+ overItem,
86
+ restrictDragAndDrop
87
+ } = _ref3;
88
+ const {
89
+ id: movedId
90
+ } = draggedItem;
91
+ const {
92
+ id: hoverId
93
+ } = overItem;
76
94
  const isInside = !isBefore && !isAfter;
77
- if (movedId === hoverId)
78
- return false;
95
+ if (movedId === hoverId) return false;
96
+
79
97
  if (isInside && !overItem.isGroup) {
80
- return false;
98
+ return false; // we can't drop inside an item that isn't a group
81
99
  }
100
+
82
101
  if (restrictDragAndDrop) {
83
- if (isInside)
84
- return false;
102
+ if (isInside) return false; // in this mode we can't drop inside another element
103
+
85
104
  const sameParent = itemsShareSameParent([draggedItem, overItem]);
86
- if (overItem.node.model.isExpanded && isAfter)
87
- return false;
88
- if (!sameParent)
89
- return false;
105
+ if (overItem.node.model.isExpanded && isAfter) return false;
106
+ if (!sameParent) return false;
90
107
  }
108
+
91
109
  return true;
92
110
  };
93
- const inferKeyboardKinshipDrop = ({
94
- items,
95
- newIndex
96
- }) => {
111
+ const inferKeyboardKinshipDrop = _ref4 => {
112
+ let {
113
+ items,
114
+ newIndex
115
+ } = _ref4;
97
116
  const kinship = {};
98
117
  const itemBefore = items[newIndex];
99
118
  const itemBeforeModel = itemBefore.node.model;
100
119
  const isGroupAndIsExpanded = itemBeforeModel.isExpanded && itemBeforeModel.children.length > 0;
120
+
101
121
  if (isGroupAndIsExpanded) {
102
122
  kinship.newParentNode = itemBefore.node;
103
123
  kinship.newNestedIndex = 0;
@@ -105,13 +125,8 @@ const inferKeyboardKinshipDrop = ({
105
125
  kinship.newParentNode = getItemsParentNode([itemBefore], true);
106
126
  kinship.newNestedIndex = itemBefore.node.getIndex();
107
127
  }
128
+
108
129
  return kinship;
109
130
  };
110
- export {
111
- inferHoverItemKinshipDrop,
112
- inferKeyboardKinshipDrop,
113
- isDropValid,
114
- keyCodes,
115
- sameParentAsHoverItemDrop
116
- };
117
- //# sourceMappingURL=dnd-helpers.js.map
131
+
132
+ export { inferHoverItemKinshipDrop, inferKeyboardKinshipDrop, isDropValid, keyCodes, sameParentAsHoverItemDrop };
@@ -1,109 +1,99 @@
1
- import * as React from "react";
2
- import { useCallback, useEffect } from "react";
1
+ import { useCallback, useEffect } from 'react';
2
+
3
+ /* eslint-disable max-params */
3
4
  const updateExpandedState = (treeRoot, onExpandChange) => {
4
5
  const shouldContinueWalking = true;
5
- const newExpandedHashMap = { __ds_tree_root: true };
6
- treeRoot.walk((node) => {
6
+ const newExpandedHashMap = {
7
+ __ds_tree_root: true
8
+ };
9
+ treeRoot.walk(node => {
7
10
  if (!node.isRoot() && node.model.isGroup && node.model.isExpanded) {
8
11
  newExpandedHashMap[node.model.id] = true;
9
12
  }
13
+
10
14
  return shouldContinueWalking;
11
15
  });
12
- if (onExpandChange)
13
- onExpandChange(newExpandedHashMap, null);
16
+ if (onExpandChange) onExpandChange(newExpandedHashMap, null);
14
17
  };
15
- const toggleItemExpand = (itemToToggle, triggerTreeRerender, updateUserExpandedState, scrollTo = () => {
16
- }) => {
18
+ const toggleItemExpand = function (itemToToggle, triggerTreeRerender, updateUserExpandedState) {
19
+ let scrollTo = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : () => {};
17
20
  const {
18
21
  node: {
19
- model: { isExpanded }
22
+ model: {
23
+ isExpanded
24
+ }
20
25
  },
21
26
  virtualIndex
22
27
  } = itemToToggle;
28
+
23
29
  if (itemToToggle.node.model.isGroup) {
24
30
  itemToToggle.node.model.isExpanded = !isExpanded;
25
31
  triggerTreeRerender();
26
32
  updateUserExpandedState();
27
33
  setTimeout(() => {
28
- if (typeof virtualIndex === "number")
29
- scrollTo(virtualIndex, { align: "start" });
34
+ if (typeof virtualIndex === 'number') scrollTo(virtualIndex, {
35
+ align: 'start'
36
+ });
30
37
  });
31
38
  }
32
39
  };
33
- const expandItemModel = (modelToExpand) => {
34
- if (modelToExpand.isGroup)
35
- modelToExpand.isExpanded = true;
40
+ const expandItemModel = modelToExpand => {
41
+ if (modelToExpand.isGroup) modelToExpand.isExpanded = true;
36
42
  };
37
- const collapseItemModel = (modelToCollapse) => {
38
- if (modelToCollapse.isGroup)
39
- modelToCollapse.isExpanded = false;
43
+ const collapseItemModel = modelToCollapse => {
44
+ if (modelToCollapse.isGroup) modelToCollapse.isExpanded = false;
40
45
  };
41
46
  const expandAll = (treeRoot, triggerTreeRerender) => {
42
47
  const shouldContinueWalking = true;
43
- treeRoot.walk((node) => {
44
- if (!node.isRoot())
45
- expandItemModel(node.model);
48
+ treeRoot.walk(node => {
49
+ if (!node.isRoot()) expandItemModel(node.model);
46
50
  return shouldContinueWalking;
47
51
  });
48
52
  triggerTreeRerender();
49
53
  };
50
54
  const collapseAll = (treeRoot, triggerTreeRerender) => {
51
- const shouldContinueWalking = true;
52
- treeRoot.walk((node) => {
53
- if (!node.isRoot())
54
- collapseItemModel(node.model);
55
+ const shouldContinueWalking = true; // tree-model ask we return true if we want to continue walking
56
+
57
+ treeRoot.walk(node => {
58
+ if (!node.isRoot()) collapseItemModel(node.model);
55
59
  return shouldContinueWalking;
56
60
  });
57
61
  triggerTreeRerender();
58
62
  };
59
- const getToggleExpandShouldExpand = (treeRoot) => {
63
+ const getToggleExpandShouldExpand = treeRoot => {
60
64
  let shouldExpand = false;
61
- const shouldContinueWalking = true;
62
- treeRoot.walk((node) => {
65
+ const shouldContinueWalking = true; // tree-model ask we return true if we want to continue walking
66
+
67
+ treeRoot.walk(node => {
63
68
  if (!node.isRoot()) {
64
69
  if (!node.model.isExpanded && node.model.isGroup) {
65
- shouldExpand = true;
70
+ shouldExpand = true; // eslint-disable-next-line no-useless-return
71
+
66
72
  return shouldContinueWalking;
67
73
  }
68
74
  }
75
+
69
76
  return shouldContinueWalking;
70
77
  });
71
78
  return shouldExpand;
72
79
  };
73
80
  const toggleExpandAllHelper = (isExpand, treeRoot, triggerTreeRerender, setLatestToggledItem, updateUserExpandedState) => {
74
- if (isExpand === true)
75
- expandAll(treeRoot, triggerTreeRerender);
76
- else if (isExpand === false)
77
- collapseAll(treeRoot, triggerTreeRerender);
78
- else {
81
+ if (isExpand === true) expandAll(treeRoot, triggerTreeRerender);else if (isExpand === false) collapseAll(treeRoot, triggerTreeRerender);else {
79
82
  const shouldExpand = getToggleExpandShouldExpand(treeRoot);
80
- if (shouldExpand === true)
81
- expandAll(treeRoot, triggerTreeRerender);
82
- else
83
- collapseAll(treeRoot, triggerTreeRerender);
83
+ if (shouldExpand === true) expandAll(treeRoot, triggerTreeRerender);else collapseAll(treeRoot, triggerTreeRerender);
84
84
  }
85
85
  setLatestToggledItem(null);
86
86
  updateUserExpandedState();
87
87
  };
88
- const useNotifyExpandedChange = (propsWithDefaults, {
89
- latestToggledItem,
90
- expandedGroups
91
- }) => {
92
- const notifyExpandedChange = useCallback((expandedGroupHashmap) => propsWithDefaults?.onExpandChange(expandedGroupHashmap || {}, latestToggledItem), [propsWithDefaults, latestToggledItem]);
88
+ const useNotifyExpandedChange = (propsWithDefaults, _ref) => {
89
+ let {
90
+ latestToggledItem,
91
+ expandedGroups
92
+ } = _ref;
93
+ const notifyExpandedChange = useCallback(expandedGroupHashmap => propsWithDefaults === null || propsWithDefaults === void 0 ? void 0 : propsWithDefaults.onExpandChange(expandedGroupHashmap || {}, latestToggledItem), [propsWithDefaults, latestToggledItem]);
93
94
  useEffect(() => {
94
- if (!propsWithDefaults.expanded)
95
- notifyExpandedChange(expandedGroups);
95
+ if (!propsWithDefaults.expanded) notifyExpandedChange(expandedGroups);
96
96
  }, [expandedGroups, notifyExpandedChange, propsWithDefaults.expanded]);
97
97
  };
98
- export {
99
- collapseAll,
100
- collapseItemModel,
101
- expandAll,
102
- expandItemModel,
103
- getToggleExpandShouldExpand,
104
- toggleExpandAllHelper,
105
- toggleItemExpand,
106
- updateExpandedState,
107
- useNotifyExpandedChange
108
- };
109
- //# sourceMappingURL=group-expands-helpers.js.map
98
+
99
+ export { collapseAll, collapseItemModel, expandAll, expandItemModel, getToggleExpandShouldExpand, toggleExpandAllHelper, toggleItemExpand, updateExpandedState, useNotifyExpandedChange };
@@ -1,12 +1,26 @@
1
- import * as React from "react";
2
- import { useCallback, useContext, useEffect } from "react";
3
- import TreeViewContext from "../TreeViewContext";
4
- import { focusItem } from "./tree-helpers";
5
- import { toggleExpandAllHelper, toggleItemExpand } from "./group-expands-helpers";
6
- const useOnItemKeyDown = (item) => {
1
+ import { useContext, useCallback, useEffect } from 'react';
2
+ import TreeViewContext from '../TreeViewContext.js';
3
+ import { focusItem } from './tree-helpers.js';
4
+ import { toggleItemExpand, toggleExpandAllHelper } from './group-expands-helpers.js';
5
+
6
+ /* eslint-disable max-params */
7
+ // 9 tab
8
+ // 13 enter
9
+ // 32 space
10
+ // 37 left arrow
11
+ // 38 up arrow
12
+ // 39 right arrow
13
+ // 40 down arrow
14
+ // 35 end
15
+ // 36 home
16
+ // 56 number 8
17
+ // 106 (NumPad) *
18
+ const useOnItemKeyDown = item => {
7
19
  const ctx = useContext(TreeViewContext);
8
20
  const {
9
- props: { onItemFocus },
21
+ props: {
22
+ onItemFocus
23
+ },
10
24
  triggerTreeRerender,
11
25
  isDragging,
12
26
  visibleItems,
@@ -14,42 +28,63 @@ const useOnItemKeyDown = (item) => {
14
28
  setSelectedItem,
15
29
  setLatestToggledItem,
16
30
  updateUserExpandedState,
17
- virtualListHelpers: { scrollToIndex }
31
+ virtualListHelpers: {
32
+ scrollToIndex
33
+ }
18
34
  } = ctx;
19
- const { isGroup, isExpanded } = item;
20
- const onItemFocusCurry = useCallback((newFocusItem) => onItemFocus({
35
+ const {
36
+ isGroup,
37
+ isExpanded
38
+ } = item;
39
+ const onItemFocusCurry = useCallback(newFocusItem => onItemFocus({
21
40
  itemIndex: newFocusItem.virtualIndex,
22
- scrollToItem: (opts = { align: "start" }) => scrollToIndex(newFocusItem.virtualIndex, opts),
41
+ scrollToItem: function () {
42
+ let opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
43
+ align: 'start'
44
+ };
45
+ return scrollToIndex(newFocusItem.virtualIndex, opts);
46
+ },
23
47
  item: newFocusItem
24
48
  }), [onItemFocus, scrollToIndex]);
25
- const onItemKeyDown = useCallback((e) => {
26
- const { keyCode } = e;
49
+ const onItemKeyDown = useCallback(e => {
50
+ const {
51
+ keyCode
52
+ } = e;
53
+
27
54
  if (!isDragging) {
28
- if (keyCode !== 9)
29
- e.preventDefault();
30
- if (keyCode === 13 || keyCode === 32)
31
- setSelectedItem(item);
55
+ if (keyCode !== 9) e.preventDefault(); // allow tab/shift+tab
56
+
57
+ if (keyCode === 13 || keyCode === 32) setSelectedItem(item);
58
+
32
59
  if (keyCode === 37) {
33
60
  if (isGroup && isExpanded) {
34
61
  toggleItemExpand(item, triggerTreeRerender, updateUserExpandedState, scrollToIndex);
35
62
  setLatestToggledItem(item);
36
63
  }
37
64
  }
65
+
38
66
  if (keyCode === 39) {
39
67
  if (isGroup && !isExpanded) {
40
68
  toggleItemExpand(item, triggerTreeRerender, updateUserExpandedState, scrollToIndex);
41
69
  setLatestToggledItem(item);
42
70
  }
43
71
  }
44
- const { virtualIndex } = item;
45
- if (typeof virtualIndex === "number") {
72
+
73
+ const {
74
+ virtualIndex
75
+ } = item;
76
+
77
+ if (typeof virtualIndex === 'number') {
46
78
  const lastItemIndex = visibleItems.length - 1;
79
+
47
80
  if (keyCode === 38) {
48
81
  const isLoopedFocus = virtualIndex === 0;
49
82
  const newFocusIndex = isLoopedFocus ? lastItemIndex : virtualIndex - 1;
50
83
  const newFocusItem = visibleItems[newFocusIndex];
51
84
  scrollToIndex(newFocusIndex);
85
+
52
86
  if (isLoopedFocus) {
87
+ // when looping the list from start to end we need to wait a bit before focusing
53
88
  setTimeout(() => {
54
89
  setFocusedItem(newFocusItem);
55
90
  focusItem(newFocusItem);
@@ -61,12 +96,15 @@ const useOnItemKeyDown = (item) => {
61
96
  focusItem(newFocusItem);
62
97
  }
63
98
  }
99
+
64
100
  if (keyCode === 40) {
65
101
  const isLoopedFocus = virtualIndex === lastItemIndex;
66
102
  const newFocusIndex = isLoopedFocus ? 0 : virtualIndex + 1;
67
103
  const newFocusItem = visibleItems[newFocusIndex];
68
104
  scrollToIndex(newFocusIndex);
105
+
69
106
  if (isLoopedFocus) {
107
+ // when looping the list from start to end we need to wait a bit before focusing
70
108
  setTimeout(() => {
71
109
  setFocusedItem(newFocusItem);
72
110
  onItemFocusCurry(newFocusItem);
@@ -78,6 +116,7 @@ const useOnItemKeyDown = (item) => {
78
116
  focusItem(newFocusItem);
79
117
  }
80
118
  }
119
+
81
120
  if (keyCode === 35) {
82
121
  if (virtualIndex !== lastItemIndex) {
83
122
  const newFocusItem = visibleItems[lastItemIndex];
@@ -89,6 +128,7 @@ const useOnItemKeyDown = (item) => {
89
128
  }, 300);
90
129
  }
91
130
  }
131
+
92
132
  if (keyCode === 36) {
93
133
  if (virtualIndex !== 0) {
94
134
  const newFocusItem = visibleItems[0];
@@ -102,40 +142,27 @@ const useOnItemKeyDown = (item) => {
102
142
  }
103
143
  }
104
144
  }
105
- }, [
106
- isDragging,
107
- setSelectedItem,
108
- item,
109
- isGroup,
110
- isExpanded,
111
- triggerTreeRerender,
112
- scrollToIndex,
113
- setLatestToggledItem,
114
- visibleItems,
115
- setFocusedItem,
116
- onItemFocusCurry,
117
- updateUserExpandedState
118
- ]);
145
+ }, [isDragging, setSelectedItem, item, isGroup, isExpanded, triggerTreeRerender, scrollToIndex, setLatestToggledItem, visibleItems, setFocusedItem, onItemFocusCurry, updateUserExpandedState]);
119
146
  return onItemKeyDown;
120
147
  };
121
- const useGlobalKeyboardListener = (func) => {
148
+ const useGlobalKeyboardListener = func => {
122
149
  useEffect(() => {
123
- document.addEventListener("keydown", func);
124
- return () => document.removeEventListener("keydown", func);
150
+ document.addEventListener('keydown', func);
151
+ return () => document.removeEventListener('keydown', func);
125
152
  }, [func]);
126
153
  };
127
154
  const useGlobalToggleAllExpandShortcut = (treeRoot, triggerTreeRerender, setLatestToggledItem, updateUserExpandedState) => {
128
- const memoizedToggleAllKeyboardShortcut = useCallback((e) => {
129
- const { shiftKey, keyCode } = e;
155
+ const memoizedToggleAllKeyboardShortcut = useCallback(e => {
156
+ const {
157
+ shiftKey,
158
+ keyCode
159
+ } = e;
160
+
130
161
  if (shiftKey && keyCode === 56) {
131
- toggleExpandAllHelper("toggle", treeRoot, triggerTreeRerender, setLatestToggledItem, updateUserExpandedState);
162
+ toggleExpandAllHelper('toggle', treeRoot, triggerTreeRerender, setLatestToggledItem, updateUserExpandedState);
132
163
  }
133
164
  }, [setLatestToggledItem, treeRoot, triggerTreeRerender, updateUserExpandedState]);
134
165
  return useGlobalKeyboardListener(memoizedToggleAllKeyboardShortcut);
135
166
  };
136
- export {
137
- useGlobalKeyboardListener,
138
- useGlobalToggleAllExpandShortcut,
139
- useOnItemKeyDown
140
- };
141
- //# sourceMappingURL=keyboard-helpers.js.map
167
+
168
+ export { useGlobalKeyboardListener, useGlobalToggleAllExpandShortcut, useOnItemKeyDown };
@@ -1,47 +1,64 @@
1
- import * as React from "react";
1
+ import 'core-js/modules/esnext.async-iterator.for-each.js';
2
+ import 'core-js/modules/esnext.iterator.constructor.js';
3
+ import 'core-js/modules/esnext.iterator.for-each.js';
4
+ import 'core-js/modules/esnext.async-iterator.reduce.js';
5
+ import 'core-js/modules/esnext.iterator.reduce.js';
6
+
7
+ /* eslint-disable no-sequences */
8
+
9
+ /* eslint-disable no-return-assign */
10
+
11
+ /* eslint-disable no-restricted-syntax */
12
+
13
+ /* eslint-disable guard-for-in */
2
14
  function isObjectADate(o) {
3
- return o?.constructor?.name === "Date";
15
+ var _o$constructor;
16
+
17
+ return (o === null || o === void 0 ? void 0 : (_o$constructor = o.constructor) === null || _o$constructor === void 0 ? void 0 : _o$constructor.name) === 'Date';
4
18
  }
19
+
5
20
  function isObjectAnArray(o) {
6
21
  return Array.isArray(o);
7
22
  }
23
+
8
24
  function isObjectAString(o) {
9
- return typeof o === "object";
25
+ return typeof o === 'object';
10
26
  }
11
- const unfreeze = (o) => {
27
+
28
+ const unfreeze = o => {
12
29
  let oo;
30
+
13
31
  if (o === null) {
14
32
  oo = null;
15
- } else if (o === void 0) {
16
- oo = void 0;
33
+ } else if (o === undefined) {
34
+ oo = undefined;
17
35
  } else if (isObjectADate(o)) {
18
36
  oo = new Date(o);
19
37
  } else if (isObjectAnArray(o)) {
20
38
  oo = [];
21
- o.forEach((v) => {
39
+ o.forEach(v => {
22
40
  oo.push(v);
23
41
  });
24
42
  } else if (isObjectAString(o)) {
25
43
  oo = String(o);
26
44
  } else if (isObjectAString(o)) {
27
45
  oo = {};
46
+
28
47
  for (const property in o) {
29
48
  oo[property] = o[property];
30
49
  }
31
50
  } else {
32
51
  oo = o;
33
52
  }
53
+
34
54
  return oo;
35
55
  };
56
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
36
57
  function filterObject(obj, predicate) {
37
58
  return Object.keys(obj).reduce((res, key) => {
38
- if (predicate(obj[key]))
39
- res[key] = obj[key];
59
+ if (predicate(obj[key])) res[key] = obj[key];
40
60
  return res;
41
61
  }, {});
42
62
  }
43
- export {
44
- filterObject,
45
- unfreeze
46
- };
47
- //# sourceMappingURL=object-helpers.js.map
63
+
64
+ export { filterObject, unfreeze };
@@ -1,15 +1,21 @@
1
- import * as React from "react";
2
- const setMultipleRefs = (...refs) => {
1
+ import 'core-js/modules/esnext.async-iterator.filter.js';
2
+ import 'core-js/modules/esnext.iterator.constructor.js';
3
+ import 'core-js/modules/esnext.iterator.filter.js';
4
+ import 'core-js/modules/esnext.async-iterator.for-each.js';
5
+ import 'core-js/modules/esnext.iterator.for-each.js';
6
+
7
+ // allow multiple refs to be set to point to the same DOM element
8
+ const setMultipleRefs = function () {
9
+ for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
10
+ refs[_key] = arguments[_key];
11
+ }
12
+
3
13
  const filteredRefs = refs.filter(Boolean);
4
- if (!filteredRefs.length)
5
- return () => {
6
- };
7
- if (filteredRefs.length === 0)
8
- return () => {
9
- };
10
- return (newRef) => {
11
- filteredRefs.forEach((refToBeUpdated) => {
12
- if (typeof refToBeUpdated === "function") {
14
+ if (!filteredRefs.length) return () => {};
15
+ if (filteredRefs.length === 0) return () => {};
16
+ return newRef => {
17
+ filteredRefs.forEach(refToBeUpdated => {
18
+ if (typeof refToBeUpdated === 'function') {
13
19
  refToBeUpdated(newRef);
14
20
  } else if (refToBeUpdated) {
15
21
  refToBeUpdated.current = newRef;
@@ -17,7 +23,5 @@ const setMultipleRefs = (...refs) => {
17
23
  });
18
24
  };
19
25
  };
20
- export {
21
- setMultipleRefs
22
- };
23
- //# sourceMappingURL=refs-helpers.js.map
26
+
27
+ export { setMultipleRefs };