@elliemae/ds-treeview 2.2.0-alpha.4 → 3.0.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 (206) hide show
  1. package/cjs/TreeView.js +27 -49
  2. package/cjs/TreeViewContext.js +37 -61
  3. package/cjs/config/cssClassesConstants.js +13 -41
  4. package/cjs/config/useTreeview.js +78 -116
  5. package/cjs/hoc/DnDTreeContext.js +18 -0
  6. package/cjs/hoc/SortableItemContext.js +21 -0
  7. package/cjs/hoc/WithConditionalDnDContext.js +138 -0
  8. package/cjs/hoc/WithDnDSortableItemContext.js +70 -0
  9. package/cjs/index.js +26 -37
  10. package/cjs/parts/CheckboxSelectable.js +59 -70
  11. package/cjs/parts/ChildrenCountDisplayer.js +28 -45
  12. package/cjs/parts/DnDHandle.js +46 -0
  13. package/cjs/parts/DropIndicator.js +75 -0
  14. package/cjs/parts/ExpandCaret.js +83 -85
  15. package/cjs/parts/Icon.js +31 -46
  16. package/cjs/parts/NestingSpace.js +35 -43
  17. package/cjs/parts/RadioSelectable.js +37 -52
  18. package/cjs/parts/TreeItem.js +141 -147
  19. package/cjs/parts/TreeItemText.js +95 -88
  20. package/cjs/parts/TreeList.js +130 -119
  21. package/cjs/plugins/dnd/TreeDndPlugin.js +7 -59
  22. package/cjs/plugins/dnd/index.js +9 -28
  23. package/cjs/plugins/index.js +21 -34
  24. package/cjs/plugins/roving/TreeRovingPlugin.js +7 -35
  25. package/cjs/plugins/roving/index.js +9 -28
  26. package/cjs/plugins/searchable/SearchableTreePlugin.js +7 -35
  27. package/cjs/plugins/searchable/index.js +9 -28
  28. package/cjs/plugins/selectable/SelectablePluginTree.js +7 -35
  29. package/cjs/plugins/selectable/index.js +9 -28
  30. package/cjs/plugins/toolbar/TreeToolbarPlugin.js +7 -35
  31. package/cjs/plugins/toolbar/index.js +9 -28
  32. package/cjs/plugins/tree/TreeDataPlugin.js +7 -35
  33. package/cjs/plugins/tree/index.js +9 -28
  34. package/cjs/plugins/virtualization/TreeVirtualizationPlugin.js +7 -35
  35. package/cjs/plugins/virtualization/index.js +9 -28
  36. package/cjs/react-desc-prop-types.js +54 -82
  37. package/cjs/related-components/TreeViewSearchBar.js +40 -42
  38. package/cjs/sharedTypes.js +2 -27
  39. package/cjs/utils/array-helpers.js +11 -35
  40. package/cjs/utils/group-expands-helpers.js +59 -86
  41. package/cjs/utils/keyboard-helpers.js +90 -85
  42. package/cjs/utils/object-helpers.js +36 -43
  43. package/cjs/utils/refs-helpers.js +22 -43
  44. package/cjs/utils/selectable-helper.js +53 -61
  45. package/cjs/utils/string-helpers.js +7 -35
  46. package/cjs/utils/tree-helpers.js +161 -105
  47. package/cjs/utils/useInstanceRefActions.js +43 -54
  48. package/cjs/utils/useTree.js +80 -76
  49. package/esm/TreeView.js +16 -18
  50. package/esm/TreeViewContext.js +31 -32
  51. package/esm/config/cssClassesConstants.js +6 -12
  52. package/esm/config/useTreeview.js +56 -73
  53. package/esm/hoc/DnDTreeContext.js +14 -0
  54. package/esm/hoc/SortableItemContext.js +17 -0
  55. package/esm/hoc/WithConditionalDnDContext.js +128 -0
  56. package/esm/hoc/WithDnDSortableItemContext.js +61 -0
  57. package/esm/index.js +9 -8
  58. package/esm/parts/CheckboxSelectable.js +46 -36
  59. package/esm/parts/ChildrenCountDisplayer.js +20 -16
  60. package/esm/parts/DnDHandle.js +38 -0
  61. package/esm/parts/DropIndicator.js +68 -0
  62. package/esm/parts/ExpandCaret.js +72 -54
  63. package/esm/parts/Icon.js +22 -16
  64. package/esm/parts/NestingSpace.js +27 -14
  65. package/esm/parts/RadioSelectable.js +28 -20
  66. package/esm/parts/TreeItem.js +125 -114
  67. package/esm/parts/TreeItemText.js +85 -58
  68. package/esm/parts/TreeList.js +119 -91
  69. package/esm/plugins/dnd/TreeDndPlugin.js +3 -30
  70. package/esm/plugins/dnd/index.js +1 -3
  71. package/esm/plugins/index.js +7 -9
  72. package/esm/plugins/roving/TreeRovingPlugin.js +3 -6
  73. package/esm/plugins/roving/index.js +1 -3
  74. package/esm/plugins/searchable/SearchableTreePlugin.js +3 -6
  75. package/esm/plugins/searchable/index.js +1 -3
  76. package/esm/plugins/selectable/SelectablePluginTree.js +3 -6
  77. package/esm/plugins/selectable/index.js +1 -3
  78. package/esm/plugins/toolbar/TreeToolbarPlugin.js +3 -6
  79. package/esm/plugins/toolbar/index.js +1 -3
  80. package/esm/plugins/tree/TreeDataPlugin.js +3 -6
  81. package/esm/plugins/tree/index.js +1 -3
  82. package/esm/plugins/virtualization/TreeVirtualizationPlugin.js +3 -6
  83. package/esm/plugins/virtualization/index.js +1 -3
  84. package/esm/react-desc-prop-types.js +44 -47
  85. package/esm/related-components/TreeViewSearchBar.js +32 -13
  86. package/esm/sharedTypes.js +1 -2
  87. package/esm/utils/array-helpers.js +6 -6
  88. package/esm/utils/group-expands-helpers.js +46 -56
  89. package/esm/utils/keyboard-helpers.js +74 -46
  90. package/esm/utils/object-helpers.js +31 -14
  91. package/esm/utils/refs-helpers.js +19 -15
  92. package/esm/utils/selectable-helper.js +43 -32
  93. package/esm/utils/string-helpers.js +3 -6
  94. package/esm/utils/tree-helpers.js +143 -73
  95. package/esm/utils/useInstanceRefActions.js +35 -21
  96. package/esm/utils/useTree.js +59 -35
  97. package/package.json +35 -19
  98. package/types/hoc/DnDTreeContext.d.ts +14 -0
  99. package/types/hoc/SortableItemContext.d.ts +19 -0
  100. package/types/hoc/WithConditionalDnDContext.d.ts +4 -0
  101. package/types/hoc/WithDnDSortableItemContext.d.ts +4 -0
  102. package/types/parts/DnDHandle.d.ts +6 -0
  103. package/types/parts/DropIndicator.d.ts +10 -0
  104. package/types/parts/TreeItem.d.ts +4 -11
  105. package/types/parts/TreeList.d.ts +0 -4
  106. package/types/plugins/dnd/TreeDndPlugin.d.ts +0 -2
  107. package/types/react-desc-prop-types.d.ts +17 -3
  108. package/types/sharedTypes.d.ts +1 -8
  109. package/types/utils/keyboard-helpers.d.ts +2 -1
  110. package/types/utils/refs-helpers.d.ts +1 -1
  111. package/types/utils/tree-helpers.d.ts +4 -1
  112. package/types/utils/useTree.d.ts +1 -0
  113. package/cjs/TreeView.js.map +0 -7
  114. package/cjs/TreeViewContext.js.map +0 -7
  115. package/cjs/config/cssClassesConstants.js.map +0 -7
  116. package/cjs/config/useTreeview.js.map +0 -7
  117. package/cjs/index.js.map +0 -7
  118. package/cjs/parts/CheckboxSelectable.js.map +0 -7
  119. package/cjs/parts/ChildrenCountDisplayer.js.map +0 -7
  120. package/cjs/parts/ExpandCaret.js.map +0 -7
  121. package/cjs/parts/Icon.js.map +0 -7
  122. package/cjs/parts/NestingSpace.js.map +0 -7
  123. package/cjs/parts/RadioSelectable.js.map +0 -7
  124. package/cjs/parts/TreeItem.js.map +0 -7
  125. package/cjs/parts/TreeItemText.js.map +0 -7
  126. package/cjs/parts/TreeList.js.map +0 -7
  127. package/cjs/plugins/dnd/TreeDndPlugin.js.map +0 -7
  128. package/cjs/plugins/dnd/index.js.map +0 -7
  129. package/cjs/plugins/index.js.map +0 -7
  130. package/cjs/plugins/roving/TreeRovingPlugin.js.map +0 -7
  131. package/cjs/plugins/roving/index.js.map +0 -7
  132. package/cjs/plugins/searchable/SearchableTreePlugin.js.map +0 -7
  133. package/cjs/plugins/searchable/index.js.map +0 -7
  134. package/cjs/plugins/selectable/SelectablePluginTree.js.map +0 -7
  135. package/cjs/plugins/selectable/index.js.map +0 -7
  136. package/cjs/plugins/toolbar/TreeToolbarPlugin.js.map +0 -7
  137. package/cjs/plugins/toolbar/index.js.map +0 -7
  138. package/cjs/plugins/tree/TreeDataPlugin.js.map +0 -7
  139. package/cjs/plugins/tree/index.js.map +0 -7
  140. package/cjs/plugins/virtualization/TreeVirtualizationPlugin.js.map +0 -7
  141. package/cjs/plugins/virtualization/index.js.map +0 -7
  142. package/cjs/react-desc-prop-types.js.map +0 -7
  143. package/cjs/related-components/TreeViewSearchBar.js.map +0 -7
  144. package/cjs/sharedTypes.js.map +0 -7
  145. package/cjs/utils/array-helpers.js.map +0 -7
  146. package/cjs/utils/dnd-helpers.js +0 -146
  147. package/cjs/utils/dnd-helpers.js.map +0 -7
  148. package/cjs/utils/group-expands-helpers.js.map +0 -7
  149. package/cjs/utils/keyboard-helpers.js.map +0 -7
  150. package/cjs/utils/object-helpers.js.map +0 -7
  151. package/cjs/utils/refs-helpers.js.map +0 -7
  152. package/cjs/utils/selectable-helper.js.map +0 -7
  153. package/cjs/utils/string-helpers.js.map +0 -7
  154. package/cjs/utils/tree-helpers.js.map +0 -7
  155. package/cjs/utils/useDnDHelpers.js +0 -199
  156. package/cjs/utils/useDnDHelpers.js.map +0 -7
  157. package/cjs/utils/useInstanceRefActions.js.map +0 -7
  158. package/cjs/utils/useTree.js.map +0 -7
  159. package/esm/TreeView.js.map +0 -7
  160. package/esm/TreeViewContext.js.map +0 -7
  161. package/esm/config/cssClassesConstants.js.map +0 -7
  162. package/esm/config/useTreeview.js.map +0 -7
  163. package/esm/index.js.map +0 -7
  164. package/esm/parts/CheckboxSelectable.js.map +0 -7
  165. package/esm/parts/ChildrenCountDisplayer.js.map +0 -7
  166. package/esm/parts/ExpandCaret.js.map +0 -7
  167. package/esm/parts/Icon.js.map +0 -7
  168. package/esm/parts/NestingSpace.js.map +0 -7
  169. package/esm/parts/RadioSelectable.js.map +0 -7
  170. package/esm/parts/TreeItem.js.map +0 -7
  171. package/esm/parts/TreeItemText.js.map +0 -7
  172. package/esm/parts/TreeList.js.map +0 -7
  173. package/esm/plugins/dnd/TreeDndPlugin.js.map +0 -7
  174. package/esm/plugins/dnd/index.js.map +0 -7
  175. package/esm/plugins/index.js.map +0 -7
  176. package/esm/plugins/roving/TreeRovingPlugin.js.map +0 -7
  177. package/esm/plugins/roving/index.js.map +0 -7
  178. package/esm/plugins/searchable/SearchableTreePlugin.js.map +0 -7
  179. package/esm/plugins/searchable/index.js.map +0 -7
  180. package/esm/plugins/selectable/SelectablePluginTree.js.map +0 -7
  181. package/esm/plugins/selectable/index.js.map +0 -7
  182. package/esm/plugins/toolbar/TreeToolbarPlugin.js.map +0 -7
  183. package/esm/plugins/toolbar/index.js.map +0 -7
  184. package/esm/plugins/tree/TreeDataPlugin.js.map +0 -7
  185. package/esm/plugins/tree/index.js.map +0 -7
  186. package/esm/plugins/virtualization/TreeVirtualizationPlugin.js.map +0 -7
  187. package/esm/plugins/virtualization/index.js.map +0 -7
  188. package/esm/react-desc-prop-types.js.map +0 -7
  189. package/esm/related-components/TreeViewSearchBar.js.map +0 -7
  190. package/esm/sharedTypes.js.map +0 -7
  191. package/esm/utils/array-helpers.js.map +0 -7
  192. package/esm/utils/dnd-helpers.js +0 -117
  193. package/esm/utils/dnd-helpers.js.map +0 -7
  194. package/esm/utils/group-expands-helpers.js.map +0 -7
  195. package/esm/utils/keyboard-helpers.js.map +0 -7
  196. package/esm/utils/object-helpers.js.map +0 -7
  197. package/esm/utils/refs-helpers.js.map +0 -7
  198. package/esm/utils/selectable-helper.js.map +0 -7
  199. package/esm/utils/string-helpers.js.map +0 -7
  200. package/esm/utils/tree-helpers.js.map +0 -7
  201. package/esm/utils/useDnDHelpers.js +0 -170
  202. package/esm/utils/useDnDHelpers.js.map +0 -7
  203. package/esm/utils/useInstanceRefActions.js.map +0 -7
  204. package/esm/utils/useTree.js.map +0 -7
  205. package/types/utils/dnd-helpers.d.ts +0 -39
  206. package/types/utils/useDnDHelpers.d.ts +0 -26
@@ -1,28 +1,34 @@
1
- import * as React from "react";
2
- import { useState, useRef, useEffect, useMemo, useCallback } from "react";
3
- import { useVirtual } from "react-virtual";
4
- import { useMemoMergePropsWithDefault, useValidateTypescriptPropTypes } from "@elliemae/ds-props-helpers";
5
- import { v4 as uuidv4 } from "uuid";
6
- import { TreeViewPropTypes } from "../react-desc-prop-types";
7
- import { defaultRelativeMouseCoord, defaultProps } from "../TreeViewContext";
8
- import { TreeDndPlugin } from "../plugins/dnd";
9
- import { useTree } from "../utils/useTree";
10
- import { useNotifyExpandedChange, toggleItemExpand } from "../utils/group-expands-helpers";
11
- import { useInstanceRefActions } from "../utils/useInstanceRefActions";
12
- import { useGlobalToggleAllExpandShortcut } from "../utils/keyboard-helpers";
13
- const useTreeview = (props) => {
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
+ import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
7
+ import 'core-js/modules/web.dom-collections.iterator.js';
8
+ import { useRef, useState, useCallback, useMemo, useEffect } from 'react';
9
+ import { useVirtual } from 'react-virtual';
10
+ import { useMemoMergePropsWithDefault, useValidateTypescriptPropTypes } from '@elliemae/ds-props-helpers';
11
+ import { v4 } from 'uuid';
12
+ import { TreeViewPropTypes } from '../react-desc-prop-types.js';
13
+ import { defaultProps } from '../TreeViewContext.js';
14
+ import { TreeDndPlugin } from '../plugins/dnd/TreeDndPlugin.js';
15
+ import { useTree } from '../utils/useTree.js';
16
+ import { toggleItemExpand, useNotifyExpandedChange } from '../utils/group-expands-helpers.js';
17
+ import { useInstanceRefActions } from '../utils/useInstanceRefActions.js';
18
+ import { useGlobalToggleAllExpandShortcut } from '../utils/keyboard-helpers.js';
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(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 useTreeview = props => {
14
24
  const propsWithDefault = useMemoMergePropsWithDefault(props, defaultProps);
15
25
  useValidateTypescriptPropTypes(propsWithDefault, TreeViewPropTypes);
16
26
  const defaultActions = {
17
27
  actions: {
18
- toggleExpandAll: () => {
19
- },
20
- scrollTo: () => {
21
- },
22
- setSelectedItemByVirtualIndex: () => {
23
- },
24
- setFocusedItemByVirtualIndex: () => {
25
- }
28
+ toggleExpandAll: () => {},
29
+ scrollTo: () => {},
30
+ setSelectedItemByVirtualIndex: () => {},
31
+ setFocusedItemByVirtualIndex: () => {}
26
32
  }
27
33
  };
28
34
  const treeRef = useRef(defaultActions);
@@ -36,48 +42,44 @@ const useTreeview = (props) => {
36
42
  selection,
37
43
  onInstanceRefInitialized
38
44
  } = propsWithDefault;
39
- const [isDragging, setIsDragging] = useState(false);
40
- const [isKeyboardDragging, setIsKeyboardDragging] = useState(false);
41
- const [relativeMouseCord, setRelativeMouseCord] = useState(defaultRelativeMouseCoord);
42
- const [uniqueTreeViewUUID] = useState(uuidv4());
43
- const [draggedItem, setDraggedItem] = useState(null);
45
+ const [uniqueTreeViewUUID] = useState(v4());
44
46
  const [hoverItem, setHoverItem] = useState(null);
45
47
  const [latestToggledItem, setLatestToggledItem] = useState(null);
46
48
  const [selectedItem, setSelectedItem] = useState(null);
47
49
  const [focusedItem, setFocusedItem] = useState(null);
48
- const [selectedCheckboxes, setSelectedCheckboxes] = useState({
49
- ...selection
50
- });
50
+ const [selectedCheckboxes, setSelectedCheckboxes] = useState(_objectSpread({}, selection));
51
51
  const [expandedGroups, setExpandedGroups] = useState({});
52
- const { visibleItems, tree, treeRoot, triggerTreeRerender, updateUserExpandedState } = useTree(data, propsWithDefault, {
52
+ const {
53
+ visibleItems,
54
+ flattenedItems,
55
+ tree,
56
+ treeRoot,
57
+ triggerTreeRerender,
58
+ updateUserExpandedState
59
+ } = useTree(data, propsWithDefault, {
53
60
  setExpandedGroups
54
61
  });
55
- const virtualListRef = useRef();
62
+ const virtualListRef = useRef(); // estimateSize should not be really required given what was stated on
63
+ // https://github.com/tannerlinsley/react-virtual/issues/23
64
+
56
65
  const virtualListHelpers = useVirtual({
57
66
  size: visibleItems.length,
58
67
  parentRef: virtualListRef,
59
68
  overscan: 15
60
69
  });
61
- const withDragAndDrop = !!(plugins?.includes(TreeDndPlugin) && onOrderChange);
70
+ const withDragAndDrop = !!(plugins !== null && plugins !== void 0 && plugins.includes(TreeDndPlugin) && onOrderChange);
62
71
  const withRadioChecks = isSingleSelect && !isMultiSelect;
63
72
  const withCheckboxChecks = !isSingleSelect && isMultiSelect;
64
73
  const handleExpandGroup = useCallback(toggleItemExpand, []);
65
74
  const ctx = useMemo(() => ({
66
75
  props: propsWithDefault,
67
- setRelativeMouseCord,
68
- relativeMouseCord,
69
76
  virtualListHelpers,
70
77
  virtualListRef,
71
78
  tree,
72
79
  treeRoot,
73
80
  visibleItems,
81
+ flattenedItems,
74
82
  triggerTreeRerender,
75
- isDragging,
76
- setIsDragging,
77
- isKeyboardDragging,
78
- setIsKeyboardDragging,
79
- draggedItem,
80
- setDraggedItem,
81
83
  withRadioChecks,
82
84
  withCheckboxChecks,
83
85
  withDragAndDrop,
@@ -96,41 +98,22 @@ const useTreeview = (props) => {
96
98
  setHoverItem,
97
99
  handleExpandGroup,
98
100
  updateUserExpandedState
99
- }), [
100
- draggedItem,
101
- expandedGroups,
102
- focusedItem,
103
- handleExpandGroup,
104
- hoverItem,
105
- isDragging,
106
- isKeyboardDragging,
107
- latestToggledItem,
108
- propsWithDefault,
109
- relativeMouseCord,
110
- selectedCheckboxes,
111
- selectedItem,
112
- tree,
113
- treeRoot,
114
- triggerTreeRerender,
115
- uniqueTreeViewUUID,
116
- virtualListHelpers,
117
- visibleItems,
118
- withCheckboxChecks,
119
- withDragAndDrop,
120
- withRadioChecks,
121
- updateUserExpandedState
122
- ]);
123
- if (instanceRef)
124
- instanceRef.current = treeRef.current;
101
+ }), [propsWithDefault, virtualListHelpers, tree, treeRoot, visibleItems, flattenedItems, triggerTreeRerender, withRadioChecks, withCheckboxChecks, withDragAndDrop, uniqueTreeViewUUID, selectedCheckboxes, selectedItem, expandedGroups, latestToggledItem, focusedItem, hoverItem, handleExpandGroup, updateUserExpandedState]); // this hooks can't use the context because the context provider doesn't wrap this
102
+ // as such we manually pass the second parameter as fit
103
+
104
+ if (instanceRef) instanceRef.current = treeRef.current;
125
105
  useInstanceRefActions(treeRef.current, ctx);
126
106
  useGlobalToggleAllExpandShortcut(treeRoot, triggerTreeRerender, setLatestToggledItem, updateUserExpandedState);
127
- useNotifyExpandedChange(propsWithDefault, ctx);
107
+ useNotifyExpandedChange(propsWithDefault, ctx); // this is an horrible hack.
108
+ // this is required because there is no "on rendered" react-way to check if every children has finished rendering
109
+ // this should be working for now, in the future we may want to review this for a better solution
110
+
128
111
  useEffect(() => {
129
- setTimeout(() => onInstanceRefInitialized(treeRef), 100);
112
+ setTimeout(() => onInstanceRefInitialized(treeRef), 100); // eslint-disable-next-line react-hooks/exhaustive-deps
130
113
  }, []);
131
- return useMemo(() => ({ ctx }), [ctx]);
132
- };
133
- export {
134
- useTreeview
114
+ return useMemo(() => ({
115
+ ctx
116
+ }), [ctx]);
135
117
  };
136
- //# sourceMappingURL=useTreeview.js.map
118
+
119
+ export { useTreeview };
@@ -0,0 +1,14 @@
1
+ import { createContext } from 'react';
2
+ import { DropIndicatorPosition } from './SortableItemContext.js';
3
+
4
+ const DnDTreeContext = /*#__PURE__*/createContext({
5
+ depth: undefined,
6
+ activeIndex: undefined,
7
+ visibleItems: undefined,
8
+ dropIndicatorPosition: DropIndicatorPosition.None,
9
+ lastActiveId: undefined,
10
+ setLastActiveId: undefined,
11
+ isDropValid: false
12
+ });
13
+
14
+ export { DnDTreeContext };
@@ -0,0 +1,17 @@
1
+ import { createContext } from 'react';
2
+
3
+ let DropIndicatorPosition;
4
+
5
+ (function (DropIndicatorPosition) {
6
+ DropIndicatorPosition[DropIndicatorPosition["None"] = 0] = "None";
7
+ DropIndicatorPosition[DropIndicatorPosition["Before"] = 1] = "Before";
8
+ DropIndicatorPosition[DropIndicatorPosition["After"] = 2] = "After";
9
+ DropIndicatorPosition[DropIndicatorPosition["Inside"] = 3] = "Inside";
10
+ })(DropIndicatorPosition || (DropIndicatorPosition = {}));
11
+
12
+ /** Context for cross component communication */
13
+ const SortableItemContext = /*#__PURE__*/createContext({
14
+ draggableProps: false
15
+ });
16
+
17
+ export { DropIndicatorPosition, SortableItemContext };
@@ -0,0 +1,128 @@
1
+ import 'core-js/modules/esnext.async-iterator.filter.js';
2
+ import 'core-js/modules/esnext.iterator.filter.js';
3
+ import _jsx from '@babel/runtime/helpers/esm/jsx';
4
+ import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
5
+ import 'core-js/modules/web.dom-collections.iterator.js';
6
+ import 'core-js/modules/esnext.async-iterator.map.js';
7
+ import 'core-js/modules/esnext.iterator.map.js';
8
+ import 'core-js/modules/esnext.async-iterator.for-each.js';
9
+ import 'core-js/modules/esnext.iterator.constructor.js';
10
+ import 'core-js/modules/esnext.iterator.for-each.js';
11
+ import 'core-js/modules/esnext.async-iterator.find.js';
12
+ import 'core-js/modules/esnext.iterator.find.js';
13
+ import React, { useContext, useMemo, useCallback } from 'react';
14
+ import { DndContext, DragOverlay } from '@dnd-kit/core';
15
+ import { SortableContext } from '@dnd-kit/sortable';
16
+ import { useTreeDndkitConfig } from '@elliemae/ds-drag-and-drop';
17
+ import TreeViewContext from '../TreeViewContext.js';
18
+ import { TreeItem } from '../parts/TreeItem.js';
19
+ import { DnDTreeContext } from './DnDTreeContext.js';
20
+ import { jsxs, jsx } from 'react/jsx-runtime';
21
+
22
+ 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; }
23
+
24
+ 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(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; }
25
+
26
+ const ensure = function (argument) {
27
+ let message = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'This should never happen';
28
+
29
+ if (argument === undefined || argument === null) {
30
+ throw new TypeError(message);
31
+ }
32
+
33
+ return argument;
34
+ }; // only wraps in "DnDContext" and "DnDTreeContext" if any Drag and Drop functionality is requested
35
+
36
+
37
+ const withConditionalDnDRowContext = Component => props => {
38
+ const [lastActiveId, setLastActiveId] = React.useState('');
39
+ const {
40
+ props: {
41
+ data,
42
+ onOrderChange,
43
+ getIsDropValid
44
+ },
45
+ flattenedItems,
46
+ visibleItems: flattenedVisibleTree,
47
+ withDragAndDrop
48
+ } = useContext(TreeViewContext);
49
+ const flattenedVisibleTreeForDnD = useMemo(() => flattenedVisibleTree.map((item, index) => {
50
+ var _item$treeDepth, _item$children$length, _item$children, _item$node$parent$mod, _item$node$parent, _item$node$parent$mod2, _item$node$parent$mod3;
51
+
52
+ return {
53
+ uid: item.id.toString(),
54
+ depth: ((_item$treeDepth = item.treeDepth) !== null && _item$treeDepth !== void 0 ? _item$treeDepth : 1) - 1,
55
+ realIndex: index,
56
+ childrenCount: (_item$children$length = (_item$children = item.children) === null || _item$children === void 0 ? void 0 : _item$children.length) !== null && _item$children$length !== void 0 ? _item$children$length : 0,
57
+ parentId: (_item$node$parent$mod = (_item$node$parent = item.node.parent) === null || _item$node$parent === void 0 ? void 0 : (_item$node$parent$mod2 = _item$node$parent.model) === null || _item$node$parent$mod2 === void 0 ? void 0 : (_item$node$parent$mod3 = _item$node$parent$mod2.id) === null || _item$node$parent$mod3 === void 0 ? void 0 : _item$node$parent$mod3.toString()) !== null && _item$node$parent$mod !== void 0 ? _item$node$parent$mod : null,
58
+ original: item
59
+ };
60
+ }), [flattenedVisibleTree]);
61
+ const onReorder = useCallback((tree, indexes) => {
62
+ // Pull the row's original data into an object
63
+ const nodes = {};
64
+ tree.forEach(item => {
65
+ const originalItem = item.original;
66
+ originalItem.children = [];
67
+ nodes[item.uid] = item.original;
68
+ });
69
+ const newUserTree = [];
70
+ tree.forEach(item => {
71
+ // If row has parent, insert it to it's subrows
72
+ // otherwise append it to the new user data
73
+ if (item.parentId !== null && item.parentId !== undefined && item.parentId !== '__ds_tree_root') {
74
+ var _parentNode$children;
75
+
76
+ const parentNode = nodes[item.parentId];
77
+ (_parentNode$children = parentNode.children) === null || _parentNode$children === void 0 ? void 0 : _parentNode$children.push(item.original);
78
+ } else if (item.uid !== '__ds_tree_root') newUserTree.push(item.original);
79
+ }); // Tell the user that the order has change, he can chose to commit it or not
80
+
81
+ onOrderChange(newUserTree, data, flattenedItems[indexes.fromIndex]);
82
+ }, [onOrderChange, data, flattenedItems]);
83
+ const {
84
+ dndContextProps,
85
+ sortableContextProps,
86
+ activeId,
87
+ activeIndex,
88
+ depth,
89
+ dropIndicatorPosition,
90
+ visibleItems,
91
+ isDropValid
92
+ } = useTreeDndkitConfig({
93
+ flattenedItems,
94
+ visibleItems: flattenedVisibleTreeForDnD,
95
+ isHorizontalDnD: false,
96
+ isExpandable: true,
97
+ onReorder,
98
+ getIsDropValid,
99
+ maxDragAndDropLevel: Infinity
100
+ });
101
+ if (lastActiveId !== activeId && activeId) setLastActiveId(activeId);
102
+ if (withDragAndDrop) return /*#__PURE__*/jsxs(DndContext, _objectSpread(_objectSpread({}, dndContextProps), {}, {
103
+ children: [/*#__PURE__*/jsx(SortableContext, _objectSpread(_objectSpread({}, sortableContextProps), {}, {
104
+ children: /*#__PURE__*/_jsx(DnDTreeContext.Provider, {
105
+ value: {
106
+ activeIndex,
107
+ depth,
108
+ visibleItems: visibleItems.map(item => item.original),
109
+ dropIndicatorPosition,
110
+ lastActiveId,
111
+ setLastActiveId,
112
+ isDropValid
113
+ }
114
+ }, void 0, /*#__PURE__*/jsx(Component, _objectSpread({}, props)))
115
+ })), /*#__PURE__*/_jsx(DragOverlay, {
116
+ style: {
117
+ width: 'auto'
118
+ }
119
+ }, void 0, activeId ? /*#__PURE__*/_jsx(TreeItem, {
120
+ itemIndex: activeIndex,
121
+ item: ensure(flattenedVisibleTree.find(item => item.id.toString() === activeId)),
122
+ isDragOverlay: true
123
+ }) : null)]
124
+ }));
125
+ return /*#__PURE__*/jsx(Component, _objectSpread({}, props));
126
+ };
127
+
128
+ export { withConditionalDnDRowContext };
@@ -0,0 +1,61 @@
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
+ import _jsx from '@babel/runtime/helpers/esm/jsx';
7
+ import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
8
+ import { useContext, useMemo } from 'react';
9
+ import { useSortable } from '@dnd-kit/sortable';
10
+ import { SortableItemContext } from './SortableItemContext.js';
11
+ import TreeViewContext from '../TreeViewContext.js';
12
+ import { DnDTreeContext } from './DnDTreeContext.js';
13
+ import { jsx } from 'react/jsx-runtime';
14
+
15
+ 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; }
16
+
17
+ 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(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; }
18
+ const withDnDSortableItemContext = Component => props => {
19
+ const {
20
+ withDragAndDrop
21
+ } = useContext(TreeViewContext);
22
+ const {
23
+ dropIndicatorPosition,
24
+ lastActiveId,
25
+ setLastActiveId,
26
+ isDropValid
27
+ } = useContext(DnDTreeContext);
28
+ const id = props.item.id.toString(); // onMount generate unique options, so everyting is only ran once
29
+
30
+ const draggableOptions = useMemo(() => ({
31
+ id
32
+ }), [id]);
33
+ const useSortableHelpers = useSortable(draggableOptions); // calculate all the "useSortable" values as per required
34
+
35
+ const draggableProps = useMemo(() => {
36
+ if (!withDragAndDrop) return false;
37
+ const {
38
+ index,
39
+ overIndex
40
+ } = useSortableHelpers;
41
+ return _objectSpread(_objectSpread({}, useSortableHelpers), {}, {
42
+ shouldShowDropIndicatorPosition: overIndex === index,
43
+ dropIndicatorPosition,
44
+ lastActiveId,
45
+ setLastActiveId,
46
+ isDropValid
47
+ });
48
+ }, [withDragAndDrop, useSortableHelpers, dropIndicatorPosition, lastActiveId, setLastActiveId, isDropValid]); // we use a context so we can easly access information wherever without bubbling down
49
+ // this context is all Memoized so as long as component is not re-mounted,
50
+ // the context won't trigger un-required renders per-se...
51
+
52
+ const ctx = useMemo(() => ({
53
+ draggableProps
54
+ }), [draggableProps]); // we always add the context, if draggableProps===false we don't have the DnD enabled.
55
+
56
+ return /*#__PURE__*/_jsx(SortableItemContext.Provider, {
57
+ value: ctx
58
+ }, void 0, /*#__PURE__*/jsx(Component, _objectSpread({}, props)));
59
+ };
60
+
61
+ export { withDnDSortableItemContext };
package/esm/index.js CHANGED
@@ -1,8 +1,9 @@
1
- import * as React from "react";
2
- export * from "./TreeView";
3
- export * from "./plugins";
4
- import { TreeViewSearchBar } from "./related-components/TreeViewSearchBar";
5
- export {
6
- TreeViewSearchBar
7
- };
8
- //# sourceMappingURL=index.js.map
1
+ export { TreeView, TreeViewWithSchema } from './TreeView.js';
2
+ export { TreeDndPlugin } from './plugins/dnd/TreeDndPlugin.js';
3
+ export { TreeRovingPlugin } from './plugins/roving/TreeRovingPlugin.js';
4
+ export { SelectablePluginTree } from './plugins/selectable/SelectablePluginTree.js';
5
+ export { TreeToolbarPlugin } from './plugins/toolbar/TreeToolbarPlugin.js';
6
+ export { TreePluginList } from './plugins/tree/TreeDataPlugin.js';
7
+ export { TreeVirtualizationPlugin } from './plugins/virtualization/TreeVirtualizationPlugin.js';
8
+ export { SearchableTreePlugin } from './plugins/searchable/SearchableTreePlugin.js';
9
+ export { TreeViewSearchBar } from './related-components/TreeViewSearchBar.js';
@@ -1,58 +1,71 @@
1
- import * as React from "react";
2
- import React2, { useContext, useCallback, useMemo } from "react";
3
- import { DSCheckbox } from "@elliemae/ds-form";
4
- import styled from "styled-components";
5
- import TreeViewContext from "../TreeViewContext";
6
- import { toggleCheckboxItem } from "../utils/selectable-helper";
7
- import { filterObject } from "../utils/object-helpers";
8
- const StyledCheckboxWrapper = styled.span`
9
- padding-top: 3px;
10
- `;
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
+ import _jsx from '@babel/runtime/helpers/esm/jsx';
7
+ import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
8
+ import { useContext, useCallback, useMemo } from 'react';
9
+ import { DSCheckbox } from '@elliemae/ds-form';
10
+ import styled from 'styled-components';
11
+ import TreeViewContext from '../TreeViewContext.js';
12
+ import { toggleCheckboxItem } from '../utils/selectable-helper.js';
13
+ import { filterObject } from '../utils/object-helpers.js';
14
+
15
+ 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; }
16
+
17
+ 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(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; }
18
+ const StyledCheckboxWrapper = /*#__PURE__*/styled.span.withConfig({
19
+ componentId: "sc-1tyhs3t-0"
20
+ })(["padding-top:3px;"]);
21
+
11
22
  function CheckboxSelectable(props) {
12
- const { item, itemIndex } = props;
13
- const { id } = item;
23
+ const {
24
+ item,
25
+ itemIndex
26
+ } = props;
27
+ const {
28
+ id
29
+ } = item;
14
30
  const ctx = useContext(TreeViewContext);
15
31
  const {
16
- props: { onSelectionChange, isItemDisabled },
17
- virtualListHelpers: { scrollToIndex },
32
+ props: {
33
+ onSelectionChange,
34
+ isItemDisabled
35
+ },
36
+ virtualListHelpers: {
37
+ scrollToIndex
38
+ },
18
39
  triggerTreeRerender,
19
40
  selectedCheckboxes,
20
41
  setSelectedCheckboxes
21
42
  } = ctx;
22
43
  const onCheckboxChange = useCallback(() => {
23
44
  const newSelections = toggleCheckboxItem(item);
24
- const newSelectionHasmap = filterObject({ ...selectedCheckboxes, ...newSelections }, (value) => value !== false);
45
+ const newSelectionHasmap = filterObject(_objectSpread(_objectSpread({}, selectedCheckboxes), newSelections), value => value !== false);
25
46
  setSelectedCheckboxes(newSelectionHasmap);
26
47
  triggerTreeRerender();
27
48
  const indexAndScrollTo = {
28
49
  scrollToItem: () => {
29
- if (typeof item.virtualIndex === "number")
30
- scrollToIndex(item.virtualIndex);
50
+ if (typeof item.virtualIndex === 'number') scrollToIndex(item.virtualIndex);
31
51
  },
32
52
  itemIndex
33
53
  };
34
- if (onSelectionChange)
35
- onSelectionChange(newSelectionHasmap, item, indexAndScrollTo);
36
- }, [
37
- item,
38
- triggerTreeRerender,
39
- onSelectionChange,
40
- itemIndex,
41
- scrollToIndex,
42
- selectedCheckboxes,
43
- setSelectedCheckboxes
44
- ]);
54
+ if (onSelectionChange) onSelectionChange(newSelectionHasmap, item, indexAndScrollTo);
55
+ }, [item, triggerTreeRerender, onSelectionChange, itemIndex, scrollToIndex, selectedCheckboxes, setSelectedCheckboxes]);
45
56
  const isChecked = useMemo(() => {
46
- if (selectedCheckboxes[id] === "mixed") {
47
- return "mixed";
57
+ if (selectedCheckboxes[id] === 'mixed') {
58
+ return 'mixed';
48
59
  }
60
+
49
61
  if (selectedCheckboxes[id] === true) {
50
62
  return true;
51
63
  }
64
+
52
65
  return false;
53
66
  }, [selectedCheckboxes, id]);
54
67
  const isDisabled = useMemo(() => isItemDisabled(item), [item, isItemDisabled]);
55
- return /* @__PURE__ */ React2.createElement(StyledCheckboxWrapper, null, /* @__PURE__ */ React2.createElement(DSCheckbox, {
68
+ return /*#__PURE__*/_jsx(StyledCheckboxWrapper, {}, void 0, /*#__PURE__*/_jsx(DSCheckbox, {
56
69
  checked: isChecked,
57
70
  disabled: isDisabled,
58
71
  className: "em-ds-tree-item-checkbox",
@@ -61,8 +74,5 @@ function CheckboxSelectable(props) {
61
74
  tabIndex: "0"
62
75
  }));
63
76
  }
64
- var CheckboxSelectable_default = CheckboxSelectable;
65
- export {
66
- CheckboxSelectable_default as default
67
- };
68
- //# sourceMappingURL=CheckboxSelectable.js.map
77
+
78
+ export { CheckboxSelectable as default };
@@ -1,18 +1,22 @@
1
- import * as React from "react";
2
- import React2 from "react";
3
- import { DSTreeViewPrefix, treeItemBlockName } from "../config/cssClassesConstants";
4
- const className = `${DSTreeViewPrefix}-${treeItemBlockName}-children-count-displayer`;
5
- const ChildrenCountDisplayer = (props) => {
6
- const { item } = props;
7
- const { isGroup, children } = item;
8
- if (!isGroup)
9
- return null;
10
- return /* @__PURE__ */ React2.createElement("span", {
1
+ import _jsx from '@babel/runtime/helpers/esm/jsx';
2
+ import 'react';
3
+ import { DSTreeViewPrefix, treeItemBlockName } from '../config/cssClassesConstants.js';
4
+
5
+ const className = "".concat(DSTreeViewPrefix, "-").concat(treeItemBlockName, "-children-count-displayer");
6
+ const ChildrenCountDisplayer = props => {
7
+ const {
8
+ item
9
+ } = props;
10
+ const {
11
+ isGroup,
12
+ children
13
+ } = item;
14
+ if (!isGroup) return null; // return ` | ${children.length} Items`;
15
+
16
+ return /*#__PURE__*/_jsx("span", {
11
17
  "data-testid": "tree-item-children-count-displayer",
12
- className
13
- }, ` | ${children.length} Items`);
18
+ className: className
19
+ }, void 0, " | ".concat(children.length, " Items"));
14
20
  };
15
- export {
16
- ChildrenCountDisplayer
17
- };
18
- //# sourceMappingURL=ChildrenCountDisplayer.js.map
21
+
22
+ export { ChildrenCountDisplayer };
@@ -0,0 +1,38 @@
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
+ import _defineProperty from '@babel/runtime/helpers/esm/defineProperty';
7
+ import { useContext, createElement } from 'react';
8
+ import { GripperVertical } from '@elliemae/ds-icons';
9
+ import { SortableItemContext } from '../hoc/SortableItemContext.js';
10
+
11
+ 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; }
12
+
13
+ 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(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; }
14
+ const DnDHandle = _ref => {
15
+ let {
16
+ id,
17
+ isDragOverlay
18
+ } = _ref;
19
+ const {
20
+ draggableProps
21
+ } = useContext(SortableItemContext);
22
+ const isDragging = draggableProps && draggableProps.isDragging;
23
+ return /*#__PURE__*/createElement(GripperVertical, _objectSpread(_objectSpread({
24
+ role: "button"
25
+ }, draggableProps && _objectSpread(_objectSpread({}, draggableProps.listeners), draggableProps.attributes)), {}, {
26
+ "data-testid": "drag-handle",
27
+ "data-isactive": draggableProps && !!draggableProps.active,
28
+ "data-isdragoverlay": isDragOverlay,
29
+ id: "".concat(id, "-drag-handle"),
30
+ key: "".concat(id, "-drag-handle"),
31
+ className: "drag-handle ".concat(isDragging ? '' : 'focuseable'),
32
+ color: ['brand-primary', '800'],
33
+ size: "s",
34
+ tabIndex: 0
35
+ }));
36
+ };
37
+
38
+ export { DnDHandle };