@elliemae/ds-treeview 2.2.0 → 2.3.0-alpha.3

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 (214) hide show
  1. package/cjs/TreeView.js +47 -31
  2. package/cjs/TreeView.js.map +7 -0
  3. package/cjs/TreeViewContext.js +55 -43
  4. package/cjs/TreeViewContext.js.map +7 -0
  5. package/cjs/config/cssClassesConstants.js +41 -13
  6. package/cjs/config/cssClassesConstants.js.map +7 -0
  7. package/cjs/config/useTreeview.js +102 -88
  8. package/cjs/config/useTreeview.js.map +7 -0
  9. package/cjs/hoc/DnDTreeContext.js +45 -0
  10. package/cjs/hoc/DnDTreeContext.js.map +7 -0
  11. package/cjs/hoc/SortableItemContext.js +46 -0
  12. package/cjs/hoc/SortableItemContext.js.map +7 -0
  13. package/cjs/hoc/WithConditionalDnDContext.js +128 -0
  14. package/cjs/hoc/WithConditionalDnDContext.js.map +7 -0
  15. package/cjs/hoc/WithDnDSortableItemContext.js +69 -0
  16. package/cjs/hoc/WithDnDSortableItemContext.js.map +7 -0
  17. package/cjs/index.js +37 -27
  18. package/cjs/index.js.map +7 -0
  19. package/cjs/parts/CheckboxSelectable.js +70 -59
  20. package/cjs/parts/CheckboxSelectable.js.map +7 -0
  21. package/cjs/parts/ChildrenCountDisplayer.js +45 -28
  22. package/cjs/parts/ChildrenCountDisplayer.js.map +7 -0
  23. package/cjs/parts/DnDHandle.js +57 -0
  24. package/cjs/parts/DnDHandle.js.map +7 -0
  25. package/cjs/parts/DropIndicator.js +80 -0
  26. package/cjs/parts/DropIndicator.js.map +7 -0
  27. package/cjs/parts/ExpandCaret.js +85 -83
  28. package/cjs/parts/ExpandCaret.js.map +7 -0
  29. package/cjs/parts/Icon.js +46 -31
  30. package/cjs/parts/Icon.js.map +7 -0
  31. package/cjs/parts/NestingSpace.js +43 -35
  32. package/cjs/parts/NestingSpace.js.map +7 -0
  33. package/cjs/parts/RadioSelectable.js +52 -37
  34. package/cjs/parts/RadioSelectable.js.map +7 -0
  35. package/cjs/parts/TreeItem.js +121 -165
  36. package/cjs/parts/TreeItem.js.map +7 -0
  37. package/cjs/parts/TreeItemText.js +88 -95
  38. package/cjs/parts/TreeItemText.js.map +7 -0
  39. package/cjs/parts/TreeList.js +114 -132
  40. package/cjs/parts/TreeList.js.map +7 -0
  41. package/cjs/plugins/dnd/TreeDndPlugin.js +34 -43
  42. package/cjs/plugins/dnd/TreeDndPlugin.js.map +7 -0
  43. package/cjs/plugins/dnd/index.js +28 -10
  44. package/cjs/plugins/dnd/index.js.map +7 -0
  45. package/cjs/plugins/index.js +34 -22
  46. package/cjs/plugins/index.js.map +7 -0
  47. package/cjs/plugins/roving/TreeRovingPlugin.js +35 -7
  48. package/cjs/plugins/roving/TreeRovingPlugin.js.map +7 -0
  49. package/cjs/plugins/roving/index.js +28 -9
  50. package/cjs/plugins/roving/index.js.map +7 -0
  51. package/cjs/plugins/searchable/SearchableTreePlugin.js +35 -7
  52. package/cjs/plugins/searchable/SearchableTreePlugin.js.map +7 -0
  53. package/cjs/plugins/searchable/index.js +28 -9
  54. package/cjs/plugins/searchable/index.js.map +7 -0
  55. package/cjs/plugins/selectable/SelectablePluginTree.js +35 -7
  56. package/cjs/plugins/selectable/SelectablePluginTree.js.map +7 -0
  57. package/cjs/plugins/selectable/index.js +28 -9
  58. package/cjs/plugins/selectable/index.js.map +7 -0
  59. package/cjs/plugins/toolbar/TreeToolbarPlugin.js +35 -7
  60. package/cjs/plugins/toolbar/TreeToolbarPlugin.js.map +7 -0
  61. package/cjs/plugins/toolbar/index.js +28 -9
  62. package/cjs/plugins/toolbar/index.js.map +7 -0
  63. package/cjs/plugins/tree/TreeDataPlugin.js +35 -7
  64. package/cjs/plugins/tree/TreeDataPlugin.js.map +7 -0
  65. package/cjs/plugins/tree/index.js +28 -9
  66. package/cjs/plugins/tree/index.js.map +7 -0
  67. package/cjs/plugins/virtualization/TreeVirtualizationPlugin.js +35 -7
  68. package/cjs/plugins/virtualization/TreeVirtualizationPlugin.js.map +7 -0
  69. package/cjs/plugins/virtualization/index.js +28 -9
  70. package/cjs/plugins/virtualization/index.js.map +7 -0
  71. package/cjs/react-desc-prop-types.js +83 -53
  72. package/cjs/react-desc-prop-types.js.map +7 -0
  73. package/cjs/related-components/TreeViewSearchBar.js +42 -40
  74. package/cjs/related-components/TreeViewSearchBar.js.map +7 -0
  75. package/cjs/sharedTypes.js +27 -2
  76. package/cjs/sharedTypes.js.map +7 -0
  77. package/cjs/utils/array-helpers.js +35 -11
  78. package/cjs/utils/array-helpers.js.map +7 -0
  79. package/cjs/utils/group-expands-helpers.js +86 -59
  80. package/cjs/utils/group-expands-helpers.js.map +7 -0
  81. package/cjs/utils/keyboard-helpers.js +86 -90
  82. package/cjs/utils/keyboard-helpers.js.map +7 -0
  83. package/cjs/utils/object-helpers.js +43 -36
  84. package/cjs/utils/object-helpers.js.map +7 -0
  85. package/cjs/utils/refs-helpers.js +43 -22
  86. package/cjs/utils/refs-helpers.js.map +7 -0
  87. package/cjs/utils/selectable-helper.js +61 -53
  88. package/cjs/utils/selectable-helper.js.map +7 -0
  89. package/cjs/utils/string-helpers.js +35 -7
  90. package/cjs/utils/string-helpers.js.map +7 -0
  91. package/cjs/utils/tree-helpers.js +125 -135
  92. package/cjs/utils/tree-helpers.js.map +7 -0
  93. package/cjs/utils/useInstanceRefActions.js +54 -43
  94. package/cjs/utils/useInstanceRefActions.js.map +7 -0
  95. package/cjs/utils/useTree.js +78 -78
  96. package/cjs/utils/useTree.js.map +7 -0
  97. package/esm/TreeView.js +16 -20
  98. package/esm/TreeView.js.map +7 -0
  99. package/esm/TreeViewContext.js +26 -37
  100. package/esm/TreeViewContext.js.map +7 -0
  101. package/esm/config/cssClassesConstants.js +12 -6
  102. package/esm/config/cssClassesConstants.js.map +7 -0
  103. package/esm/config/useTreeview.js +59 -66
  104. package/esm/config/useTreeview.js.map +7 -0
  105. package/esm/hoc/DnDTreeContext.js +16 -0
  106. package/esm/hoc/DnDTreeContext.js.map +7 -0
  107. package/esm/hoc/SortableItemContext.js +17 -0
  108. package/esm/hoc/SortableItemContext.js.map +7 -0
  109. package/esm/hoc/WithConditionalDnDContext.js +99 -0
  110. package/esm/hoc/WithConditionalDnDContext.js.map +7 -0
  111. package/esm/hoc/WithDnDSortableItemContext.js +40 -0
  112. package/esm/hoc/WithDnDSortableItemContext.js.map +7 -0
  113. package/esm/index.js +8 -9
  114. package/esm/index.js.map +7 -0
  115. package/esm/parts/CheckboxSelectable.js +36 -46
  116. package/esm/parts/CheckboxSelectable.js.map +7 -0
  117. package/esm/parts/ChildrenCountDisplayer.js +16 -20
  118. package/esm/parts/ChildrenCountDisplayer.js.map +7 -0
  119. package/esm/parts/DnDHandle.js +28 -0
  120. package/esm/parts/DnDHandle.js.map +7 -0
  121. package/esm/parts/DropIndicator.js +51 -0
  122. package/esm/parts/DropIndicator.js.map +7 -0
  123. package/esm/parts/ExpandCaret.js +54 -72
  124. package/esm/parts/ExpandCaret.js.map +7 -0
  125. package/esm/parts/Icon.js +16 -22
  126. package/esm/parts/Icon.js.map +7 -0
  127. package/esm/parts/NestingSpace.js +14 -27
  128. package/esm/parts/NestingSpace.js.map +7 -0
  129. package/esm/parts/RadioSelectable.js +20 -28
  130. package/esm/parts/RadioSelectable.js.map +7 -0
  131. package/esm/parts/TreeItem.js +89 -150
  132. package/esm/parts/TreeItem.js.map +7 -0
  133. package/esm/parts/TreeItemText.js +58 -85
  134. package/esm/parts/TreeItemText.js.map +7 -0
  135. package/esm/parts/TreeList.js +86 -120
  136. package/esm/parts/TreeList.js.map +7 -0
  137. package/esm/plugins/dnd/TreeDndPlugin.js +5 -34
  138. package/esm/plugins/dnd/TreeDndPlugin.js.map +7 -0
  139. package/esm/plugins/dnd/index.js +3 -1
  140. package/esm/plugins/dnd/index.js.map +7 -0
  141. package/esm/plugins/index.js +9 -7
  142. package/esm/plugins/index.js.map +7 -0
  143. package/esm/plugins/roving/TreeRovingPlugin.js +6 -3
  144. package/esm/plugins/roving/TreeRovingPlugin.js.map +7 -0
  145. package/esm/plugins/roving/index.js +3 -1
  146. package/esm/plugins/roving/index.js.map +7 -0
  147. package/esm/plugins/searchable/SearchableTreePlugin.js +6 -3
  148. package/esm/plugins/searchable/SearchableTreePlugin.js.map +7 -0
  149. package/esm/plugins/searchable/index.js +3 -1
  150. package/esm/plugins/searchable/index.js.map +7 -0
  151. package/esm/plugins/selectable/SelectablePluginTree.js +6 -3
  152. package/esm/plugins/selectable/SelectablePluginTree.js.map +7 -0
  153. package/esm/plugins/selectable/index.js +3 -1
  154. package/esm/plugins/selectable/index.js.map +7 -0
  155. package/esm/plugins/toolbar/TreeToolbarPlugin.js +6 -3
  156. package/esm/plugins/toolbar/TreeToolbarPlugin.js.map +7 -0
  157. package/esm/plugins/toolbar/index.js +3 -1
  158. package/esm/plugins/toolbar/index.js.map +7 -0
  159. package/esm/plugins/tree/TreeDataPlugin.js +6 -3
  160. package/esm/plugins/tree/TreeDataPlugin.js.map +7 -0
  161. package/esm/plugins/tree/index.js +3 -1
  162. package/esm/plugins/tree/index.js.map +7 -0
  163. package/esm/plugins/virtualization/TreeVirtualizationPlugin.js +6 -3
  164. package/esm/plugins/virtualization/TreeVirtualizationPlugin.js.map +7 -0
  165. package/esm/plugins/virtualization/index.js +3 -1
  166. package/esm/plugins/virtualization/index.js.map +7 -0
  167. package/esm/react-desc-prop-types.js +48 -43
  168. package/esm/react-desc-prop-types.js.map +7 -0
  169. package/esm/related-components/TreeViewSearchBar.js +13 -32
  170. package/esm/related-components/TreeViewSearchBar.js.map +7 -0
  171. package/esm/sharedTypes.js +2 -1
  172. package/esm/sharedTypes.js.map +7 -0
  173. package/esm/utils/array-helpers.js +6 -6
  174. package/esm/utils/array-helpers.js.map +7 -0
  175. package/esm/utils/group-expands-helpers.js +56 -46
  176. package/esm/utils/group-expands-helpers.js.map +7 -0
  177. package/esm/utils/keyboard-helpers.js +47 -74
  178. package/esm/utils/keyboard-helpers.js.map +7 -0
  179. package/esm/utils/object-helpers.js +14 -31
  180. package/esm/utils/object-helpers.js.map +7 -0
  181. package/esm/utils/refs-helpers.js +15 -19
  182. package/esm/utils/refs-helpers.js.map +7 -0
  183. package/esm/utils/selectable-helper.js +32 -43
  184. package/esm/utils/selectable-helper.js.map +7 -0
  185. package/esm/utils/string-helpers.js +6 -3
  186. package/esm/utils/string-helpers.js.map +7 -0
  187. package/esm/utils/tree-helpers.js +94 -119
  188. package/esm/utils/tree-helpers.js.map +7 -0
  189. package/esm/utils/useInstanceRefActions.js +21 -35
  190. package/esm/utils/useInstanceRefActions.js.map +7 -0
  191. package/esm/utils/useTree.js +37 -57
  192. package/esm/utils/useTree.js.map +7 -0
  193. package/package.json +34 -18
  194. package/types/hoc/DnDTreeContext.d.ts +14 -0
  195. package/types/hoc/SortableItemContext.d.ts +19 -0
  196. package/types/hoc/WithConditionalDnDContext.d.ts +4 -0
  197. package/types/hoc/WithDnDSortableItemContext.d.ts +4 -0
  198. package/types/parts/DnDHandle.d.ts +6 -0
  199. package/types/parts/DropIndicator.d.ts +10 -0
  200. package/types/parts/TreeItem.d.ts +4 -11
  201. package/types/parts/TreeList.d.ts +0 -4
  202. package/types/plugins/dnd/TreeDndPlugin.d.ts +0 -2
  203. package/types/react-desc-prop-types.d.ts +17 -3
  204. package/types/sharedTypes.d.ts +1 -8
  205. package/types/utils/keyboard-helpers.d.ts +2 -1
  206. package/types/utils/refs-helpers.d.ts +1 -1
  207. package/types/utils/tree-helpers.d.ts +4 -1
  208. package/types/utils/useTree.d.ts +1 -0
  209. package/cjs/utils/dnd-helpers.js +0 -140
  210. package/cjs/utils/useDnDHelpers.js +0 -220
  211. package/esm/utils/dnd-helpers.js +0 -132
  212. package/esm/utils/useDnDHelpers.js +0 -216
  213. package/types/utils/dnd-helpers.d.ts +0 -39
  214. package/types/utils/useDnDHelpers.d.ts +0 -26
@@ -1,34 +1,28 @@
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, defaultRelativeMouseCoord } 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 => {
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 { 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) => {
24
14
  const propsWithDefault = useMemoMergePropsWithDefault(props, defaultProps);
25
15
  useValidateTypescriptPropTypes(propsWithDefault, TreeViewPropTypes);
26
16
  const defaultActions = {
27
17
  actions: {
28
- toggleExpandAll: () => {},
29
- scrollTo: () => {},
30
- setSelectedItemByVirtualIndex: () => {},
31
- setFocusedItemByVirtualIndex: () => {}
18
+ toggleExpandAll: () => {
19
+ },
20
+ scrollTo: () => {
21
+ },
22
+ setSelectedItemByVirtualIndex: () => {
23
+ },
24
+ setFocusedItemByVirtualIndex: () => {
25
+ }
32
26
  }
33
27
  };
34
28
  const treeRef = useRef(defaultActions);
@@ -42,54 +36,37 @@ const useTreeview = props => {
42
36
  selection,
43
37
  onInstanceRefInitialized
44
38
  } = propsWithDefault;
45
- const [isDragging, setIsDragging] = useState(false);
46
- const [isKeyboardDragging, setIsKeyboardDragging] = useState(false);
47
- const [relativeMouseCord, setRelativeMouseCord] = useState(defaultRelativeMouseCoord);
48
- const [uniqueTreeViewUUID] = useState(v4());
49
- const [draggedItem, setDraggedItem] = useState(null);
39
+ const [uniqueTreeViewUUID] = useState(uuidv4());
50
40
  const [hoverItem, setHoverItem] = useState(null);
51
41
  const [latestToggledItem, setLatestToggledItem] = useState(null);
52
42
  const [selectedItem, setSelectedItem] = useState(null);
53
43
  const [focusedItem, setFocusedItem] = useState(null);
54
- const [selectedCheckboxes, setSelectedCheckboxes] = useState(_objectSpread({}, selection));
44
+ const [selectedCheckboxes, setSelectedCheckboxes] = useState({
45
+ ...selection
46
+ });
55
47
  const [expandedGroups, setExpandedGroups] = useState({});
56
- const {
57
- visibleItems,
58
- tree,
59
- treeRoot,
60
- triggerTreeRerender,
61
- updateUserExpandedState
62
- } = useTree(data, propsWithDefault, {
48
+ const { visibleItems, flattenedItems, tree, treeRoot, triggerTreeRerender, updateUserExpandedState } = useTree(data, propsWithDefault, {
63
49
  setExpandedGroups
64
50
  });
65
- const virtualListRef = useRef(); // estimateSize should not be really required given what was stated on
66
- // https://github.com/tannerlinsley/react-virtual/issues/23
67
-
51
+ const virtualListRef = useRef();
68
52
  const virtualListHelpers = useVirtual({
69
53
  size: visibleItems.length,
70
54
  parentRef: virtualListRef,
71
55
  overscan: 15
72
56
  });
73
- const withDragAndDrop = !!(plugins !== null && plugins !== void 0 && plugins.includes(TreeDndPlugin) && onOrderChange);
57
+ const withDragAndDrop = !!(plugins?.includes(TreeDndPlugin) && onOrderChange);
74
58
  const withRadioChecks = isSingleSelect && !isMultiSelect;
75
59
  const withCheckboxChecks = !isSingleSelect && isMultiSelect;
76
60
  const handleExpandGroup = useCallback(toggleItemExpand, []);
77
61
  const ctx = useMemo(() => ({
78
62
  props: propsWithDefault,
79
- setRelativeMouseCord,
80
- relativeMouseCord,
81
63
  virtualListHelpers,
82
64
  virtualListRef,
83
65
  tree,
84
66
  treeRoot,
85
67
  visibleItems,
68
+ flattenedItems,
86
69
  triggerTreeRerender,
87
- isDragging,
88
- setIsDragging,
89
- isKeyboardDragging,
90
- setIsKeyboardDragging,
91
- draggedItem,
92
- setDraggedItem,
93
70
  withRadioChecks,
94
71
  withCheckboxChecks,
95
72
  withDragAndDrop,
@@ -108,22 +85,38 @@ const useTreeview = props => {
108
85
  setHoverItem,
109
86
  handleExpandGroup,
110
87
  updateUserExpandedState
111
- }), [draggedItem, expandedGroups, focusedItem, handleExpandGroup, hoverItem, isDragging, isKeyboardDragging, latestToggledItem, propsWithDefault, relativeMouseCord, selectedCheckboxes, selectedItem, tree, treeRoot, triggerTreeRerender, uniqueTreeViewUUID, virtualListHelpers, visibleItems, withCheckboxChecks, withDragAndDrop, withRadioChecks, updateUserExpandedState]); // this hooks can't use the context because the context provider doesn't wrap this
112
- // as such we manually pass the second parameter as fit
113
-
114
- if (instanceRef) instanceRef.current = treeRef.current;
88
+ }), [
89
+ propsWithDefault,
90
+ virtualListHelpers,
91
+ tree,
92
+ treeRoot,
93
+ visibleItems,
94
+ flattenedItems,
95
+ triggerTreeRerender,
96
+ withRadioChecks,
97
+ withCheckboxChecks,
98
+ withDragAndDrop,
99
+ uniqueTreeViewUUID,
100
+ selectedCheckboxes,
101
+ selectedItem,
102
+ expandedGroups,
103
+ latestToggledItem,
104
+ focusedItem,
105
+ hoverItem,
106
+ handleExpandGroup,
107
+ updateUserExpandedState
108
+ ]);
109
+ if (instanceRef)
110
+ instanceRef.current = treeRef.current;
115
111
  useInstanceRefActions(treeRef.current, ctx);
116
112
  useGlobalToggleAllExpandShortcut(treeRoot, triggerTreeRerender, setLatestToggledItem, updateUserExpandedState);
117
- useNotifyExpandedChange(propsWithDefault, ctx); // this is an horrible hack.
118
- // this is required because there is no "on rendered" react-way to check if every children has finished rendering
119
- // this should be working for now, in the future we may want to review this for a better solution
120
-
113
+ useNotifyExpandedChange(propsWithDefault, ctx);
121
114
  useEffect(() => {
122
- setTimeout(() => onInstanceRefInitialized(treeRef), 100); // eslint-disable-next-line react-hooks/exhaustive-deps
115
+ setTimeout(() => onInstanceRefInitialized(treeRef), 100);
123
116
  }, []);
124
- return useMemo(() => ({
125
- ctx
126
- }), [ctx]);
117
+ return useMemo(() => ({ ctx }), [ctx]);
118
+ };
119
+ export {
120
+ useTreeview
127
121
  };
128
-
129
- export { useTreeview };
122
+ //# sourceMappingURL=useTreeview.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/config/useTreeview.tsx"],
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable max-lines */\n/* eslint-disable max-statements */\nimport { useState, useRef, useEffect, useMemo, useCallback } from 'react';\nimport { useVirtual } from 'react-virtual';\nimport { useMemoMergePropsWithDefault, useValidateTypescriptPropTypes } from '@elliemae/ds-props-helpers';\nimport { v4 as uuidv4 } from 'uuid';\n\nimport { TreeViewPropTypes } from '../react-desc-prop-types';\nimport { defaultProps } from '../TreeViewContext';\nimport { TreeDndPlugin } from '../plugins/dnd';\nimport { useTree } from '../utils/useTree';\nimport { useNotifyExpandedChange, toggleItemExpand } from '../utils/group-expands-helpers';\nimport { useInstanceRefActions } from '../utils/useInstanceRefActions';\nimport { useGlobalToggleAllExpandShortcut } from '../utils/keyboard-helpers';\nimport type { DSTreeviewT } from '../react-desc-prop-types';\nimport type { DSTreeviewInternalsT } from '../sharedTypes';\n\ntype UseTreeviewT = (props: DSTreeviewT.Props) => { ctx: DSTreeviewInternalsT.CTX };\n\nexport const useTreeview: UseTreeviewT = (props) => {\n const propsWithDefault = useMemoMergePropsWithDefault<DSTreeviewT.Props>(props, defaultProps);\n useValidateTypescriptPropTypes<DSTreeviewT.Props>(propsWithDefault, TreeViewPropTypes);\n const defaultActions = {\n actions: {\n toggleExpandAll: () => {},\n scrollTo: () => {},\n setSelectedItemByVirtualIndex: () => {},\n setFocusedItemByVirtualIndex: () => {},\n },\n } as unknown as DSTreeviewT.InstanceRef;\n const treeRef = useRef(defaultActions);\n const {\n data,\n plugins,\n onOrderChange,\n isMultiSelect,\n isSingleSelect,\n instanceRef,\n selection,\n onInstanceRefInitialized,\n } = propsWithDefault;\n const [uniqueTreeViewUUID] = useState(uuidv4());\n const [hoverItem, setHoverItem] = useState<DSTreeviewT.Item | null>(null);\n const [latestToggledItem, setLatestToggledItem] = useState<DSTreeviewT.Item | null>(null);\n const [selectedItem, setSelectedItem] = useState<DSTreeviewT.Item | null>(null);\n const [focusedItem, setFocusedItem] = useState<DSTreeviewT.Item | null>(null);\n const [selectedCheckboxes, setSelectedCheckboxes] = useState({\n ...selection,\n });\n const [expandedGroups, setExpandedGroups] = useState<DSTreeviewT.ExpandedItems>({});\n const { visibleItems, flattenedItems, tree, treeRoot, triggerTreeRerender, updateUserExpandedState } = useTree(\n data,\n propsWithDefault,\n {\n setExpandedGroups,\n },\n );\n\n const virtualListRef = useRef<HTMLUListElement>();\n // estimateSize should not be really required given what was stated on\n // https://github.com/tannerlinsley/react-virtual/issues/23\n\n const virtualListHelpers = useVirtual({\n size: visibleItems.length,\n parentRef: virtualListRef,\n overscan: 15,\n });\n\n const withDragAndDrop = !!(plugins?.includes(TreeDndPlugin) && onOrderChange);\n const withRadioChecks = isSingleSelect && !isMultiSelect;\n const withCheckboxChecks = !isSingleSelect && isMultiSelect;\n\n const handleExpandGroup = useCallback(toggleItemExpand, []);\n\n const ctx: DSTreeviewInternalsT.CTX = useMemo(\n () => ({\n props: propsWithDefault,\n virtualListHelpers,\n virtualListRef,\n tree,\n treeRoot,\n visibleItems,\n flattenedItems,\n triggerTreeRerender,\n withRadioChecks,\n withCheckboxChecks,\n withDragAndDrop,\n uniqueTreeViewUUID,\n selectedCheckboxes,\n setSelectedCheckboxes,\n selectedItem,\n setSelectedItem,\n expandedGroups,\n setExpandedGroups,\n latestToggledItem,\n setLatestToggledItem,\n focusedItem,\n setFocusedItem,\n hoverItem,\n setHoverItem,\n handleExpandGroup,\n updateUserExpandedState,\n }),\n [\n propsWithDefault,\n virtualListHelpers,\n tree,\n treeRoot,\n visibleItems,\n flattenedItems,\n triggerTreeRerender,\n withRadioChecks,\n withCheckboxChecks,\n withDragAndDrop,\n uniqueTreeViewUUID,\n selectedCheckboxes,\n selectedItem,\n expandedGroups,\n latestToggledItem,\n focusedItem,\n hoverItem,\n handleExpandGroup,\n updateUserExpandedState,\n ],\n );\n // this hooks can't use the context because the context provider doesn't wrap this\n // as such we manually pass the second parameter as fit\n if (instanceRef) instanceRef.current = treeRef.current;\n useInstanceRefActions(treeRef.current, ctx);\n useGlobalToggleAllExpandShortcut(treeRoot, triggerTreeRerender, setLatestToggledItem, updateUserExpandedState);\n useNotifyExpandedChange(propsWithDefault, ctx);\n\n // this is an horrible hack.\n // this is required because there is no \"on rendered\" react-way to check if every children has finished rendering\n // this should be working for now, in the future we may want to review this for a better solution\n useEffect(() => {\n setTimeout(() => onInstanceRefInitialized(treeRef), 100);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, []);\n\n return useMemo(() => ({ ctx }), [ctx]);\n};\n"],
5
+ "mappings": "AAAA;ACEA;AACA;AACA;AACA;AAEA;AACA;AACA;AACA;AACA;AACA;AACA;AAMO,MAAM,cAA4B,CAAC,UAAU;AAClD,QAAM,mBAAmB,6BAAgD,OAAO;AAChF,iCAAkD,kBAAkB;AACpE,QAAM,iBAAiB;AAAA,IACrB,SAAS;AAAA,MACP,iBAAiB,MAAM;AAAA;AAAA,MACvB,UAAU,MAAM;AAAA;AAAA,MAChB,+BAA+B,MAAM;AAAA;AAAA,MACrC,8BAA8B,MAAM;AAAA;AAAA;AAAA;AAGxC,QAAM,UAAU,OAAO;AACvB,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,MACE;AACJ,QAAM,CAAC,sBAAsB,SAAS;AACtC,QAAM,CAAC,WAAW,gBAAgB,SAAkC;AACpE,QAAM,CAAC,mBAAmB,wBAAwB,SAAkC;AACpF,QAAM,CAAC,cAAc,mBAAmB,SAAkC;AAC1E,QAAM,CAAC,aAAa,kBAAkB,SAAkC;AACxE,QAAM,CAAC,oBAAoB,yBAAyB,SAAS;AAAA,OACxD;AAAA;AAEL,QAAM,CAAC,gBAAgB,qBAAqB,SAAoC;AAChF,QAAM,EAAE,cAAc,gBAAgB,MAAM,UAAU,qBAAqB,4BAA4B,QACrG,MACA,kBACA;AAAA,IACE;AAAA;AAIJ,QAAM,iBAAiB;AAIvB,QAAM,qBAAqB,WAAW;AAAA,IACpC,MAAM,aAAa;AAAA,IACnB,WAAW;AAAA,IACX,UAAU;AAAA;AAGZ,QAAM,kBAAkB,CAAC,CAAE,UAAS,SAAS,kBAAkB;AAC/D,QAAM,kBAAkB,kBAAkB,CAAC;AAC3C,QAAM,qBAAqB,CAAC,kBAAkB;AAE9C,QAAM,oBAAoB,YAAY,kBAAkB;AAExD,QAAM,MAAgC,QACpC,MAAO;AAAA,IACL,OAAO;AAAA,IACP;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,MAEF;AAAA,IACE;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA;AAKJ,MAAI;AAAa,gBAAY,UAAU,QAAQ;AAC/C,wBAAsB,QAAQ,SAAS;AACvC,mCAAiC,UAAU,qBAAqB,sBAAsB;AACtF,0BAAwB,kBAAkB;AAK1C,YAAU,MAAM;AACd,eAAW,MAAM,yBAAyB,UAAU;AAAA,KAEnD;AAEH,SAAO,QAAQ,MAAO,GAAE,QAAQ,CAAC;AAAA;",
6
+ "names": []
7
+ }
@@ -0,0 +1,16 @@
1
+ import * as React from "react";
2
+ import { createContext } from "react";
3
+ import { DropIndicatorPosition } from "./SortableItemContext";
4
+ const DnDTreeContext = createContext({
5
+ depth: void 0,
6
+ activeIndex: void 0,
7
+ visibleItems: void 0,
8
+ dropIndicatorPosition: DropIndicatorPosition.None,
9
+ lastActiveId: void 0,
10
+ setLastActiveId: void 0,
11
+ isDropValid: false
12
+ });
13
+ export {
14
+ DnDTreeContext
15
+ };
16
+ //# sourceMappingURL=DnDTreeContext.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/hoc/DnDTreeContext.tsx"],
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { createContext } from 'react';\nimport { DSTreeviewT } from '../react-desc-prop-types';\nimport { DropIndicatorPosition } from './SortableItemContext';\n\ntype DnDTreeContextType = {\n depth: number | undefined;\n activeIndex: number | undefined;\n visibleItems: DSTreeviewT.Item[] | undefined;\n dropIndicatorPosition: DropIndicatorPosition;\n lastActiveId: string | undefined;\n setLastActiveId: React.Dispatch<React.SetStateAction<string>> | undefined;\n isDropValid: boolean;\n};\n\nexport const DnDTreeContext = createContext<DnDTreeContextType>({\n depth: undefined,\n activeIndex: undefined,\n visibleItems: undefined,\n dropIndicatorPosition: DropIndicatorPosition.None,\n lastActiveId: undefined,\n setLastActiveId: undefined,\n isDropValid: false,\n});\n"],
5
+ "mappings": "AAAA;ACAA;AAEA;AAYO,MAAM,iBAAiB,cAAkC;AAAA,EAC9D,OAAO;AAAA,EACP,aAAa;AAAA,EACb,cAAc;AAAA,EACd,uBAAuB,sBAAsB;AAAA,EAC7C,cAAc;AAAA,EACd,iBAAiB;AAAA,EACjB,aAAa;AAAA;",
6
+ "names": []
7
+ }
@@ -0,0 +1,17 @@
1
+ import * as React from "react";
2
+ import { createContext } from "react";
3
+ var DropIndicatorPosition = /* @__PURE__ */ ((DropIndicatorPosition2) => {
4
+ DropIndicatorPosition2[DropIndicatorPosition2["None"] = 0] = "None";
5
+ DropIndicatorPosition2[DropIndicatorPosition2["Before"] = 1] = "Before";
6
+ DropIndicatorPosition2[DropIndicatorPosition2["After"] = 2] = "After";
7
+ DropIndicatorPosition2[DropIndicatorPosition2["Inside"] = 3] = "Inside";
8
+ return DropIndicatorPosition2;
9
+ })(DropIndicatorPosition || {});
10
+ const SortableItemContext = createContext({
11
+ draggableProps: false
12
+ });
13
+ export {
14
+ DropIndicatorPosition,
15
+ SortableItemContext
16
+ };
17
+ //# sourceMappingURL=SortableItemContext.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/hoc/SortableItemContext.tsx"],
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { useSortable } from '@dnd-kit/sortable';\nimport { createContext } from 'react';\n\nexport enum DropIndicatorPosition {\n None = 0,\n Before = 1,\n After = 2,\n Inside = 3,\n}\n\nexport type SortableItemContextType = {\n draggableProps:\n | false\n | (ReturnType<typeof useSortable> & {\n dropIndicatorPosition: DropIndicatorPosition;\n shouldShowDropIndicatorPosition: boolean;\n lastActiveId?: string;\n setLastActiveId?: React.Dispatch<React.SetStateAction<string>>;\n isDropValid: boolean;\n });\n};\n\n/** Context for cross component communication */\nexport const SortableItemContext = createContext<SortableItemContextType>({\n draggableProps: false,\n});\n"],
5
+ "mappings": "AAAA;ACCA;AAEO,IAAK,wBAAL,kBAAK,2BAAL;AACL,0DAAO,KAAP;AACA,4DAAS,KAAT;AACA,2DAAQ,KAAR;AACA,4DAAS,KAAT;AAJU;AAAA;AAoBL,MAAM,sBAAsB,cAAuC;AAAA,EACxE,gBAAgB;AAAA;",
6
+ "names": []
7
+ }
@@ -0,0 +1,99 @@
1
+ import * as React from "react";
2
+ import React2, { useCallback, useContext, useMemo } from "react";
3
+ import { DndContext, DragOverlay } from "@dnd-kit/core";
4
+ import { SortableContext } from "@dnd-kit/sortable";
5
+ import { useTreeDndkitConfig } from "@elliemae/ds-drag-and-drop";
6
+ import TreeViewContext from "../TreeViewContext";
7
+ import { TreeItem } from "../parts/TreeItem";
8
+ import { DnDTreeContext } from "./DnDTreeContext";
9
+ const ensure = (argument, message = "This should never happen") => {
10
+ if (argument === void 0 || argument === null) {
11
+ throw new TypeError(message);
12
+ }
13
+ return argument;
14
+ };
15
+ const withConditionalDnDRowContext = (Component) => (props) => {
16
+ const [lastActiveId, setLastActiveId] = React2.useState("");
17
+ const {
18
+ props: { data, onOrderChange, getIsDropValid },
19
+ flattenedItems,
20
+ visibleItems: flattenedVisibleTree,
21
+ withDragAndDrop
22
+ } = useContext(TreeViewContext);
23
+ const flattenedVisibleTreeForDnD = useMemo(() => flattenedVisibleTree.map((item, index) => ({
24
+ uid: item.id.toString(),
25
+ depth: (item.treeDepth ?? 1) - 1,
26
+ realIndex: index,
27
+ childrenCount: item.children?.length ?? 0,
28
+ parentId: item.node.parent?.model?.id?.toString() ?? null,
29
+ original: item
30
+ })), [flattenedVisibleTree]);
31
+ const onReorder = useCallback((tree, indexes) => {
32
+ const nodes = {};
33
+ tree.forEach((item) => {
34
+ const originalItem = item.original;
35
+ originalItem.children = [];
36
+ nodes[item.uid] = item.original;
37
+ });
38
+ const newUserTree = [];
39
+ tree.forEach((item) => {
40
+ if (item.parentId !== null && item.parentId !== void 0 && item.parentId !== "__ds_tree_root") {
41
+ const parentNode = nodes[item.parentId];
42
+ parentNode.children?.push(item.original);
43
+ } else if (item.uid !== "__ds_tree_root")
44
+ newUserTree.push(item.original);
45
+ });
46
+ onOrderChange(newUserTree, data, flattenedItems[indexes.fromIndex]);
47
+ }, [onOrderChange, data, flattenedItems]);
48
+ const {
49
+ dndContextProps,
50
+ sortableContextProps,
51
+ activeId,
52
+ activeIndex,
53
+ depth,
54
+ dropIndicatorPosition,
55
+ visibleItems,
56
+ isDropValid
57
+ } = useTreeDndkitConfig({
58
+ flattenedItems,
59
+ visibleItems: flattenedVisibleTreeForDnD,
60
+ isHorizontalDnD: false,
61
+ isExpandable: true,
62
+ onReorder,
63
+ getIsDropValid,
64
+ maxDragAndDropLevel: Infinity
65
+ });
66
+ if (lastActiveId !== activeId && activeId)
67
+ setLastActiveId(activeId);
68
+ if (withDragAndDrop)
69
+ return /* @__PURE__ */ React2.createElement(DndContext, {
70
+ ...dndContextProps
71
+ }, /* @__PURE__ */ React2.createElement(SortableContext, {
72
+ ...sortableContextProps
73
+ }, /* @__PURE__ */ React2.createElement(DnDTreeContext.Provider, {
74
+ value: {
75
+ activeIndex,
76
+ depth,
77
+ visibleItems: visibleItems.map((item) => item.original),
78
+ dropIndicatorPosition,
79
+ lastActiveId,
80
+ setLastActiveId,
81
+ isDropValid
82
+ }
83
+ }, /* @__PURE__ */ React2.createElement(Component, {
84
+ ...props
85
+ }))), /* @__PURE__ */ React2.createElement(DragOverlay, {
86
+ style: { width: "auto" }
87
+ }, activeId ? /* @__PURE__ */ React2.createElement(TreeItem, {
88
+ itemIndex: activeIndex,
89
+ item: ensure(flattenedVisibleTree.find((item) => item.id.toString() === activeId)),
90
+ isDragOverlay: true
91
+ }) : null));
92
+ return /* @__PURE__ */ React2.createElement(Component, {
93
+ ...props
94
+ });
95
+ };
96
+ export {
97
+ withConditionalDnDRowContext
98
+ };
99
+ //# sourceMappingURL=WithConditionalDnDContext.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/hoc/WithConditionalDnDContext.tsx"],
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React, { useCallback, useContext, useMemo } from 'react';\nimport { DndContext, DragOverlay } from '@dnd-kit/core';\nimport { SortableContext } from '@dnd-kit/sortable';\nimport { useTreeDndkitConfig } from '@elliemae/ds-drag-and-drop';\nimport { DSTreeviewT } from '../react-desc-prop-types';\nimport TreeViewContext from '../TreeViewContext';\nimport { TreeItem } from '../parts/TreeItem';\nimport { DnDTreeContext } from './DnDTreeContext';\n\ntype FunctionalHOC = <T = unknown>(Component: React.ComponentType<T>, ...other: unknown[]) => (props: T) => JSX.Element;\n\nconst ensure = <T,>(argument: T | undefined | null, message = 'This should never happen'): T => {\n if (argument === undefined || argument === null) {\n throw new TypeError(message);\n }\n\n return argument;\n};\n\n// only wraps in \"DnDContext\" and \"DnDTreeContext\" if any Drag and Drop functionality is requested\nexport const withConditionalDnDRowContext: FunctionalHOC = (Component) => (props) => {\n const [lastActiveId, setLastActiveId] = React.useState('');\n\n const {\n props: { data, onOrderChange, getIsDropValid },\n flattenedItems,\n visibleItems: flattenedVisibleTree,\n withDragAndDrop,\n } = useContext(TreeViewContext);\n\n const flattenedVisibleTreeForDnD = useMemo(\n () =>\n flattenedVisibleTree.map((item, index) => ({\n uid: item.id.toString(),\n depth: (item.treeDepth ?? 1) - 1,\n realIndex: index,\n childrenCount: item.children?.length ?? 0,\n parentId: item.node.parent?.model?.id?.toString() ?? null,\n original: item,\n })),\n [flattenedVisibleTree],\n );\n\n const onReorder = useCallback(\n (tree: DSTreeviewT.DndItem[], indexes: { targetIndex: number; fromIndex: number }) => {\n // Pull the row's original data into an object\n const nodes: Record<DSTreeviewT.StringOrNum, DSTreeviewT.SimpleItem> = {};\n tree.forEach((item) => {\n const originalItem = item.original;\n originalItem.children = [];\n nodes[item.uid] = item.original;\n });\n\n const newUserTree: DSTreeviewT.SimpleItem[] = [];\n tree.forEach((item) => {\n // If row has parent, insert it to it's subrows\n // otherwise append it to the new user data\n if (item.parentId !== null && item.parentId !== undefined && item.parentId !== '__ds_tree_root') {\n const parentNode = nodes[item.parentId];\n parentNode.children?.push(item.original);\n } else if (item.uid !== '__ds_tree_root') newUserTree.push(item.original);\n });\n // Tell the user that the order has change, he can chose to commit it or not\n onOrderChange(newUserTree, data, flattenedItems[indexes.fromIndex]);\n },\n [onOrderChange, data, flattenedItems],\n );\n\n const {\n dndContextProps,\n sortableContextProps,\n activeId,\n activeIndex,\n depth,\n dropIndicatorPosition,\n visibleItems,\n isDropValid,\n } = useTreeDndkitConfig({\n flattenedItems,\n visibleItems: flattenedVisibleTreeForDnD,\n isHorizontalDnD: false,\n isExpandable: true,\n onReorder,\n getIsDropValid,\n maxDragAndDropLevel: Infinity,\n });\n\n if (lastActiveId !== activeId && activeId) setLastActiveId(activeId);\n\n if (withDragAndDrop)\n return (\n <DndContext {...dndContextProps}>\n <SortableContext {...sortableContextProps}>\n <DnDTreeContext.Provider\n value={{\n activeIndex,\n depth,\n visibleItems: visibleItems.map((item) => item.original) as DSTreeviewT.Item[],\n dropIndicatorPosition,\n lastActiveId,\n setLastActiveId,\n isDropValid,\n }}\n >\n <Component {...props} />\n </DnDTreeContext.Provider>\n </SortableContext>\n <DragOverlay style={{ width: 'auto' }}>\n {activeId ? (\n <TreeItem\n itemIndex={activeIndex}\n item={ensure(flattenedVisibleTree.find((item) => item.id.toString() === activeId))}\n isDragOverlay\n />\n ) : null}\n </DragOverlay>\n </DndContext>\n );\n return <Component {...props} />;\n};\n"],
5
+ "mappings": "AAAA;ACAA;AACA;AACA;AACA;AAEA;AACA;AACA;AAIA,MAAM,SAAS,CAAK,UAAgC,UAAU,+BAAkC;AAC9F,MAAI,aAAa,UAAa,aAAa,MAAM;AAC/C,UAAM,IAAI,UAAU;AAAA;AAGtB,SAAO;AAAA;AAIF,MAAM,+BAA8C,CAAC,cAAc,CAAC,UAAU;AACnF,QAAM,CAAC,cAAc,mBAAmB,OAAM,SAAS;AAEvD,QAAM;AAAA,IACJ,OAAO,EAAE,MAAM,eAAe;AAAA,IAC9B;AAAA,IACA,cAAc;AAAA,IACd;AAAA,MACE,WAAW;AAEf,QAAM,6BAA6B,QACjC,MACE,qBAAqB,IAAI,CAAC,MAAM,UAAW;AAAA,IACzC,KAAK,KAAK,GAAG;AAAA,IACb,OAAQ,MAAK,aAAa,KAAK;AAAA,IAC/B,WAAW;AAAA,IACX,eAAe,KAAK,UAAU,UAAU;AAAA,IACxC,UAAU,KAAK,KAAK,QAAQ,OAAO,IAAI,cAAc;AAAA,IACrD,UAAU;AAAA,OAEd,CAAC;AAGH,QAAM,YAAY,YAChB,CAAC,MAA6B,YAAwD;AAEpF,UAAM,QAAiE;AACvE,SAAK,QAAQ,CAAC,SAAS;AACrB,YAAM,eAAe,KAAK;AAC1B,mBAAa,WAAW;AACxB,YAAM,KAAK,OAAO,KAAK;AAAA;AAGzB,UAAM,cAAwC;AAC9C,SAAK,QAAQ,CAAC,SAAS;AAGrB,UAAI,KAAK,aAAa,QAAQ,KAAK,aAAa,UAAa,KAAK,aAAa,kBAAkB;AAC/F,cAAM,aAAa,MAAM,KAAK;AAC9B,mBAAW,UAAU,KAAK,KAAK;AAAA,iBACtB,KAAK,QAAQ;AAAkB,oBAAY,KAAK,KAAK;AAAA;AAGlE,kBAAc,aAAa,MAAM,eAAe,QAAQ;AAAA,KAE1D,CAAC,eAAe,MAAM;AAGxB,QAAM;AAAA,IACJ;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,MACE,oBAAoB;AAAA,IACtB;AAAA,IACA,cAAc;AAAA,IACd,iBAAiB;AAAA,IACjB,cAAc;AAAA,IACd;AAAA,IACA;AAAA,IACA,qBAAqB;AAAA;AAGvB,MAAI,iBAAiB,YAAY;AAAU,oBAAgB;AAE3D,MAAI;AACF,WACE,qCAAC,YAAD;AAAA,SAAgB;AAAA,OACd,qCAAC,iBAAD;AAAA,SAAqB;AAAA,OACnB,qCAAC,eAAe,UAAhB;AAAA,MACE,OAAO;AAAA,QACL;AAAA,QACA;AAAA,QACA,cAAc,aAAa,IAAI,CAAC,SAAS,KAAK;AAAA,QAC9C;AAAA,QACA;AAAA,QACA;AAAA,QACA;AAAA;AAAA,OAGF,qCAAC,WAAD;AAAA,SAAe;AAAA,UAGnB,qCAAC,aAAD;AAAA,MAAa,OAAO,EAAE,OAAO;AAAA,OAC1B,WACC,qCAAC,UAAD;AAAA,MACE,WAAW;AAAA,MACX,MAAM,OAAO,qBAAqB,KAAK,CAAC,SAAS,KAAK,GAAG,eAAe;AAAA,MACxE,eAAa;AAAA,SAEb;AAIZ,SAAO,qCAAC,WAAD;AAAA,OAAe;AAAA;AAAA;",
6
+ "names": []
7
+ }
@@ -0,0 +1,40 @@
1
+ import * as React from "react";
2
+ import React2, { useContext, useMemo } from "react";
3
+ import { useSortable } from "@dnd-kit/sortable";
4
+ import { SortableItemContext } from "./SortableItemContext";
5
+ import TreeViewContext from "../TreeViewContext";
6
+ import { DnDTreeContext } from "./DnDTreeContext";
7
+ const withDnDSortableItemContext = (Component) => (props) => {
8
+ const { withDragAndDrop } = useContext(TreeViewContext);
9
+ const { dropIndicatorPosition, lastActiveId, setLastActiveId, isDropValid } = useContext(DnDTreeContext);
10
+ const id = props.item.id.toString();
11
+ const draggableOptions = useMemo(() => ({
12
+ id
13
+ }), [id]);
14
+ const useSortableHelpers = useSortable(draggableOptions);
15
+ const draggableProps = useMemo(() => {
16
+ if (!withDragAndDrop)
17
+ return false;
18
+ const { index, overIndex } = useSortableHelpers;
19
+ return {
20
+ ...useSortableHelpers,
21
+ shouldShowDropIndicatorPosition: overIndex === index,
22
+ dropIndicatorPosition,
23
+ lastActiveId,
24
+ setLastActiveId,
25
+ isDropValid
26
+ };
27
+ }, [withDragAndDrop, useSortableHelpers, dropIndicatorPosition, lastActiveId, setLastActiveId, isDropValid]);
28
+ const ctx = useMemo(() => ({
29
+ draggableProps
30
+ }), [draggableProps]);
31
+ return /* @__PURE__ */ React2.createElement(SortableItemContext.Provider, {
32
+ value: ctx
33
+ }, /* @__PURE__ */ React2.createElement(Component, {
34
+ ...props
35
+ }));
36
+ };
37
+ export {
38
+ withDnDSortableItemContext
39
+ };
40
+ //# sourceMappingURL=WithDnDSortableItemContext.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/hoc/WithDnDSortableItemContext.tsx"],
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable @typescript-eslint/no-unsafe-call */\n/* eslint-disable @typescript-eslint/no-unsafe-member-access */\n/* eslint-disable @typescript-eslint/no-unsafe-assignment */\nimport React, { useContext, useMemo } from 'react';\nimport { useSortable } from '@dnd-kit/sortable';\nimport { SortableItemContext, SortableItemContextType } from './SortableItemContext';\nimport TreeViewContext from '../TreeViewContext';\nimport { DnDTreeContext } from './DnDTreeContext';\nimport { DSTreeviewT } from '../react-desc-prop-types';\n\ntype FunctionalHOC = <T = unknown>(Component: React.ComponentType<T>, ...other: unknown[]) => (props: T) => JSX.Element;\n\nexport const withDnDSortableItemContext: FunctionalHOC = (Component) => (props: any) => {\n const { withDragAndDrop } = useContext(TreeViewContext);\n const { dropIndicatorPosition, lastActiveId, setLastActiveId, isDropValid } = useContext(DnDTreeContext);\n\n const id = (props as { item: DSTreeviewT.Item }).item.id.toString();\n\n // onMount generate unique options, so everyting is only ran once\n const draggableOptions = useMemo(\n () => ({\n id,\n }),\n [id],\n );\n\n const useSortableHelpers = useSortable(draggableOptions);\n\n // calculate all the \"useSortable\" values as per required\n const draggableProps = useMemo(() => {\n if (!withDragAndDrop) return false;\n\n const { index, overIndex } = useSortableHelpers;\n\n return {\n ...useSortableHelpers,\n shouldShowDropIndicatorPosition: overIndex === index,\n dropIndicatorPosition,\n lastActiveId,\n setLastActiveId,\n isDropValid,\n };\n }, [withDragAndDrop, useSortableHelpers, dropIndicatorPosition, lastActiveId, setLastActiveId, isDropValid]);\n\n // we use a context so we can easly access information wherever without bubbling down\n // this context is all Memoized so as long as component is not re-mounted,\n // the context won't trigger un-required renders per-se...\n const ctx: SortableItemContextType = useMemo(\n () => ({\n draggableProps,\n }),\n [draggableProps],\n );\n // we always add the context, if draggableProps===false we don't have the DnD enabled.\n return (\n <SortableItemContext.Provider value={ctx}>\n <Component {...props} />\n </SortableItemContext.Provider>\n );\n};\n"],
5
+ "mappings": "AAAA;ACGA;AACA;AACA;AACA;AACA;AAKO,MAAM,6BAA4C,CAAC,cAAc,CAAC,UAAe;AACtF,QAAM,EAAE,oBAAoB,WAAW;AACvC,QAAM,EAAE,uBAAuB,cAAc,iBAAiB,gBAAgB,WAAW;AAEzF,QAAM,KAAM,MAAqC,KAAK,GAAG;AAGzD,QAAM,mBAAmB,QACvB,MAAO;AAAA,IACL;AAAA,MAEF,CAAC;AAGH,QAAM,qBAAqB,YAAY;AAGvC,QAAM,iBAAiB,QAAQ,MAAM;AACnC,QAAI,CAAC;AAAiB,aAAO;AAE7B,UAAM,EAAE,OAAO,cAAc;AAE7B,WAAO;AAAA,SACF;AAAA,MACH,iCAAiC,cAAc;AAAA,MAC/C;AAAA,MACA;AAAA,MACA;AAAA,MACA;AAAA;AAAA,KAED,CAAC,iBAAiB,oBAAoB,uBAAuB,cAAc,iBAAiB;AAK/F,QAAM,MAA+B,QACnC,MAAO;AAAA,IACL;AAAA,MAEF,CAAC;AAGH,SACE,qCAAC,oBAAoB,UAArB;AAAA,IAA8B,OAAO;AAAA,KACnC,qCAAC,WAAD;AAAA,OAAe;AAAA;AAAA;",
6
+ "names": []
7
+ }
package/esm/index.js CHANGED
@@ -1,9 +1,8 @@
1
- export { TreeView, TreeViewWithSchema } from './TreeView.js';
2
- export { TreeDnD, 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
+ 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
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../scripts/build/transpile/react-shim.js", "../../src/index.tsx"],
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "export * from './TreeView';\nexport * from './plugins';\n\nexport { TreeViewSearchBar } from './related-components/TreeViewSearchBar';\n"],
5
+ "mappings": "AAAA;ACAA;AACA;AAEA;",
6
+ "names": []
7
+ }
@@ -1,71 +1,58 @@
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
-
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
+ `;
22
11
  function CheckboxSelectable(props) {
23
- const {
24
- item,
25
- itemIndex
26
- } = props;
27
- const {
28
- id
29
- } = item;
12
+ const { item, itemIndex } = props;
13
+ const { id } = item;
30
14
  const ctx = useContext(TreeViewContext);
31
15
  const {
32
- props: {
33
- onSelectionChange,
34
- isItemDisabled
35
- },
36
- virtualListHelpers: {
37
- scrollToIndex
38
- },
16
+ props: { onSelectionChange, isItemDisabled },
17
+ virtualListHelpers: { scrollToIndex },
39
18
  triggerTreeRerender,
40
19
  selectedCheckboxes,
41
20
  setSelectedCheckboxes
42
21
  } = ctx;
43
22
  const onCheckboxChange = useCallback(() => {
44
23
  const newSelections = toggleCheckboxItem(item);
45
- const newSelectionHasmap = filterObject(_objectSpread(_objectSpread({}, selectedCheckboxes), newSelections), value => value !== false);
24
+ const newSelectionHasmap = filterObject({ ...selectedCheckboxes, ...newSelections }, (value) => value !== false);
46
25
  setSelectedCheckboxes(newSelectionHasmap);
47
26
  triggerTreeRerender();
48
27
  const indexAndScrollTo = {
49
28
  scrollToItem: () => {
50
- if (typeof item.virtualIndex === 'number') scrollToIndex(item.virtualIndex);
29
+ if (typeof item.virtualIndex === "number")
30
+ scrollToIndex(item.virtualIndex);
51
31
  },
52
32
  itemIndex
53
33
  };
54
- if (onSelectionChange) onSelectionChange(newSelectionHasmap, item, indexAndScrollTo);
55
- }, [item, triggerTreeRerender, onSelectionChange, itemIndex, scrollToIndex, selectedCheckboxes, setSelectedCheckboxes]);
34
+ if (onSelectionChange)
35
+ onSelectionChange(newSelectionHasmap, item, indexAndScrollTo);
36
+ }, [
37
+ item,
38
+ triggerTreeRerender,
39
+ onSelectionChange,
40
+ itemIndex,
41
+ scrollToIndex,
42
+ selectedCheckboxes,
43
+ setSelectedCheckboxes
44
+ ]);
56
45
  const isChecked = useMemo(() => {
57
- if (selectedCheckboxes[id] === 'mixed') {
58
- return 'mixed';
46
+ if (selectedCheckboxes[id] === "mixed") {
47
+ return "mixed";
59
48
  }
60
-
61
49
  if (selectedCheckboxes[id] === true) {
62
50
  return true;
63
51
  }
64
-
65
52
  return false;
66
53
  }, [selectedCheckboxes, id]);
67
54
  const isDisabled = useMemo(() => isItemDisabled(item), [item, isItemDisabled]);
68
- return /*#__PURE__*/_jsx(StyledCheckboxWrapper, {}, void 0, /*#__PURE__*/_jsx(DSCheckbox, {
55
+ return /* @__PURE__ */ React2.createElement(StyledCheckboxWrapper, null, /* @__PURE__ */ React2.createElement(DSCheckbox, {
69
56
  checked: isChecked,
70
57
  disabled: isDisabled,
71
58
  className: "em-ds-tree-item-checkbox",
@@ -74,5 +61,8 @@ function CheckboxSelectable(props) {
74
61
  tabIndex: "0"
75
62
  }));
76
63
  }
77
-
78
- export { CheckboxSelectable as default };
64
+ var CheckboxSelectable_default = CheckboxSelectable;
65
+ export {
66
+ CheckboxSelectable_default as default
67
+ };
68
+ //# sourceMappingURL=CheckboxSelectable.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/parts/CheckboxSelectable.tsx"],
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React, { useContext, useCallback, useMemo } from 'react';\nimport { DSCheckbox } from '@elliemae/ds-form';\nimport styled from 'styled-components';\nimport TreeViewContext from '../TreeViewContext';\nimport { toggleCheckboxItem } from '../utils/selectable-helper';\nimport { filterObject } from '../utils/object-helpers';\nimport type { DSTreeviewT } from '../react-desc-prop-types';\nconst StyledCheckboxWrapper = styled.span`\n padding-top: 3px;\n`;\ninterface PropsT {\n item: DSTreeviewT.Item;\n itemIndex: number;\n}\nfunction CheckboxSelectable(props: PropsT): JSX.Element | null {\n const { item, itemIndex } = props;\n const { id } = item;\n\n const ctx = useContext(TreeViewContext);\n const {\n props: { onSelectionChange, isItemDisabled },\n virtualListHelpers: { scrollToIndex },\n triggerTreeRerender,\n selectedCheckboxes,\n setSelectedCheckboxes,\n } = ctx;\n\n const onCheckboxChange = useCallback(() => {\n const newSelections = toggleCheckboxItem(item);\n const newSelectionHasmap = filterObject<DSTreeviewT.SelectionState>(\n { ...selectedCheckboxes, ...newSelections },\n (value) => value !== false,\n );\n setSelectedCheckboxes(newSelectionHasmap);\n triggerTreeRerender();\n\n const indexAndScrollTo = {\n scrollToItem: () => {\n if (typeof item.virtualIndex === 'number') scrollToIndex(item.virtualIndex);\n },\n itemIndex,\n };\n if (onSelectionChange) onSelectionChange(newSelectionHasmap, item, indexAndScrollTo);\n }, [\n item,\n triggerTreeRerender,\n onSelectionChange,\n itemIndex,\n scrollToIndex,\n selectedCheckboxes,\n setSelectedCheckboxes,\n ]);\n const isChecked = useMemo(() => {\n if (selectedCheckboxes[id] === 'mixed') {\n return 'mixed' as const;\n }\n if (selectedCheckboxes[id] === true) {\n return true;\n }\n return false;\n }, [selectedCheckboxes, id]);\n\n const isDisabled = useMemo(() => isItemDisabled(item), [item, isItemDisabled]);\n\n return (\n <StyledCheckboxWrapper>\n <DSCheckbox\n checked={isChecked}\n disabled={isDisabled}\n className=\"em-ds-tree-item-checkbox\"\n data-testid=\"tree-item-checkbox\"\n onChange={onCheckboxChange}\n tabIndex=\"0\"\n />\n </StyledCheckboxWrapper>\n );\n}\n\nexport default CheckboxSelectable;\n"],
5
+ "mappings": "AAAA;ACAA;AACA;AACA;AACA;AACA;AACA;AAEA,MAAM,wBAAwB,OAAO;AAAA;AAAA;AAOrC,4BAA4B,OAAmC;AAC7D,QAAM,EAAE,MAAM,cAAc;AAC5B,QAAM,EAAE,OAAO;AAEf,QAAM,MAAM,WAAW;AACvB,QAAM;AAAA,IACJ,OAAO,EAAE,mBAAmB;AAAA,IAC5B,oBAAoB,EAAE;AAAA,IACtB;AAAA,IACA;AAAA,IACA;AAAA,MACE;AAEJ,QAAM,mBAAmB,YAAY,MAAM;AACzC,UAAM,gBAAgB,mBAAmB;AACzC,UAAM,qBAAqB,aACzB,KAAK,uBAAuB,iBAC5B,CAAC,UAAU,UAAU;AAEvB,0BAAsB;AACtB;AAEA,UAAM,mBAAmB;AAAA,MACvB,cAAc,MAAM;AAClB,YAAI,OAAO,KAAK,iBAAiB;AAAU,wBAAc,KAAK;AAAA;AAAA,MAEhE;AAAA;AAEF,QAAI;AAAmB,wBAAkB,oBAAoB,MAAM;AAAA,KAClE;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA;AAEF,QAAM,YAAY,QAAQ,MAAM;AAC9B,QAAI,mBAAmB,QAAQ,SAAS;AACtC,aAAO;AAAA;AAET,QAAI,mBAAmB,QAAQ,MAAM;AACnC,aAAO;AAAA;AAET,WAAO;AAAA,KACN,CAAC,oBAAoB;AAExB,QAAM,aAAa,QAAQ,MAAM,eAAe,OAAO,CAAC,MAAM;AAE9D,SACE,qCAAC,uBAAD,MACE,qCAAC,YAAD;AAAA,IACE,SAAS;AAAA,IACT,UAAU;AAAA,IACV,WAAU;AAAA,IACV,eAAY;AAAA,IACZ,UAAU;AAAA,IACV,UAAS;AAAA;AAAA;AAMjB,IAAO,6BAAQ;",
6
+ "names": []
7
+ }
@@ -1,22 +1,18 @@
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", {
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", {
17
11
  "data-testid": "tree-item-children-count-displayer",
18
- className: className
19
- }, void 0, " | ".concat(children.length, " Items"));
12
+ className
13
+ }, ` | ${children.length} Items`);
20
14
  };
21
-
22
- export { ChildrenCountDisplayer };
15
+ export {
16
+ ChildrenCountDisplayer
17
+ };
18
+ //# sourceMappingURL=ChildrenCountDisplayer.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/parts/ChildrenCountDisplayer.tsx"],
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import React from 'react';\nimport { DSTreeViewPrefix, treeItemBlockName } from '../config/cssClassesConstants';\nimport type { DSTreeviewT } from '../react-desc-prop-types';\n\nconst className = `${DSTreeViewPrefix}-${treeItemBlockName}-children-count-displayer`;\n\ninterface PropsT {\n item: DSTreeviewT.Item;\n}\n\nexport const ChildrenCountDisplayer = (props: PropsT): JSX.Element | null => {\n const { item } = props;\n const { isGroup, children } = item;\n\n if (!isGroup) return null;\n // return ` | ${children.length} Items`;\n return (\n <span data-testid=\"tree-item-children-count-displayer\" className={className}>{` | ${children.length} Items`}</span>\n );\n};\n"],
5
+ "mappings": "AAAA;ACAA;AACA;AAGA,MAAM,YAAY,GAAG,oBAAoB;AAMlC,MAAM,yBAAyB,CAAC,UAAsC;AAC3E,QAAM,EAAE,SAAS;AACjB,QAAM,EAAE,SAAS,aAAa;AAE9B,MAAI,CAAC;AAAS,WAAO;AAErB,SACE,qCAAC,QAAD;AAAA,IAAM,eAAY;AAAA,IAAqC;AAAA,KAAuB,MAAM,SAAS;AAAA;",
6
+ "names": []
7
+ }