@elliemae/ds-treeview 2.1.0 → 2.2.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 (177) hide show
  1. package/cjs/TreeView.js +49 -31
  2. package/cjs/TreeView.js.map +7 -0
  3. package/cjs/TreeViewContext.js +53 -35
  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 +108 -80
  8. package/cjs/config/useTreeview.js.map +7 -0
  9. package/cjs/index.js +37 -27
  10. package/cjs/index.js.map +7 -0
  11. package/cjs/parts/CheckboxSelectable.js +70 -59
  12. package/cjs/parts/CheckboxSelectable.js.map +7 -0
  13. package/cjs/parts/ChildrenCountDisplayer.js +45 -28
  14. package/cjs/parts/ChildrenCountDisplayer.js.map +7 -0
  15. package/cjs/parts/ExpandCaret.js +85 -83
  16. package/cjs/parts/ExpandCaret.js.map +7 -0
  17. package/cjs/parts/Icon.js +46 -31
  18. package/cjs/parts/Icon.js.map +7 -0
  19. package/cjs/parts/NestingSpace.js +43 -35
  20. package/cjs/parts/NestingSpace.js.map +7 -0
  21. package/cjs/parts/RadioSelectable.js +52 -37
  22. package/cjs/parts/RadioSelectable.js.map +7 -0
  23. package/cjs/parts/TreeItem.js +128 -147
  24. package/cjs/parts/TreeItem.js.map +7 -0
  25. package/cjs/parts/TreeItemText.js +88 -95
  26. package/cjs/parts/TreeItemText.js.map +7 -0
  27. package/cjs/parts/TreeList.js +117 -130
  28. package/cjs/parts/TreeList.js.map +7 -0
  29. package/cjs/plugins/dnd/TreeDndPlugin.js +51 -36
  30. package/cjs/plugins/dnd/TreeDndPlugin.js.map +7 -0
  31. package/cjs/plugins/dnd/index.js +28 -10
  32. package/cjs/plugins/dnd/index.js.map +7 -0
  33. package/cjs/plugins/index.js +34 -22
  34. package/cjs/plugins/index.js.map +7 -0
  35. package/cjs/plugins/roving/TreeRovingPlugin.js +35 -7
  36. package/cjs/plugins/roving/TreeRovingPlugin.js.map +7 -0
  37. package/cjs/plugins/roving/index.js +28 -9
  38. package/cjs/plugins/roving/index.js.map +7 -0
  39. package/cjs/plugins/searchable/SearchableTreePlugin.js +35 -7
  40. package/cjs/plugins/searchable/SearchableTreePlugin.js.map +7 -0
  41. package/cjs/plugins/searchable/index.js +28 -9
  42. package/cjs/plugins/searchable/index.js.map +7 -0
  43. package/cjs/plugins/selectable/SelectablePluginTree.js +35 -7
  44. package/cjs/plugins/selectable/SelectablePluginTree.js.map +7 -0
  45. package/cjs/plugins/selectable/index.js +28 -9
  46. package/cjs/plugins/selectable/index.js.map +7 -0
  47. package/cjs/plugins/toolbar/TreeToolbarPlugin.js +35 -7
  48. package/cjs/plugins/toolbar/TreeToolbarPlugin.js.map +7 -0
  49. package/cjs/plugins/toolbar/index.js +28 -9
  50. package/cjs/plugins/toolbar/index.js.map +7 -0
  51. package/cjs/plugins/tree/TreeDataPlugin.js +35 -7
  52. package/cjs/plugins/tree/TreeDataPlugin.js.map +7 -0
  53. package/cjs/plugins/tree/index.js +28 -9
  54. package/cjs/plugins/tree/index.js.map +7 -0
  55. package/cjs/plugins/virtualization/TreeVirtualizationPlugin.js +35 -7
  56. package/cjs/plugins/virtualization/TreeVirtualizationPlugin.js.map +7 -0
  57. package/cjs/plugins/virtualization/index.js +28 -9
  58. package/cjs/plugins/virtualization/index.js.map +7 -0
  59. package/cjs/react-desc-prop-types.js +82 -53
  60. package/cjs/react-desc-prop-types.js.map +7 -0
  61. package/cjs/related-components/TreeViewSearchBar.js +42 -40
  62. package/cjs/related-components/TreeViewSearchBar.js.map +7 -0
  63. package/cjs/sharedTypes.js +27 -2
  64. package/cjs/sharedTypes.js.map +7 -0
  65. package/cjs/utils/array-helpers.js +35 -11
  66. package/cjs/utils/array-helpers.js.map +7 -0
  67. package/cjs/utils/dnd-helpers.js +90 -84
  68. package/cjs/utils/dnd-helpers.js.map +7 -0
  69. package/cjs/utils/group-expands-helpers.js +86 -59
  70. package/cjs/utils/group-expands-helpers.js.map +7 -0
  71. package/cjs/utils/keyboard-helpers.js +84 -88
  72. package/cjs/utils/keyboard-helpers.js.map +7 -0
  73. package/cjs/utils/object-helpers.js +43 -36
  74. package/cjs/utils/object-helpers.js.map +7 -0
  75. package/cjs/utils/refs-helpers.js +43 -22
  76. package/cjs/utils/refs-helpers.js.map +7 -0
  77. package/cjs/utils/selectable-helper.js +61 -53
  78. package/cjs/utils/selectable-helper.js.map +7 -0
  79. package/cjs/utils/string-helpers.js +35 -7
  80. package/cjs/utils/string-helpers.js.map +7 -0
  81. package/cjs/utils/tree-helpers.js +105 -135
  82. package/cjs/utils/tree-helpers.js.map +7 -0
  83. package/cjs/utils/useDnDHelpers.js +97 -118
  84. package/cjs/utils/useDnDHelpers.js.map +7 -0
  85. package/cjs/utils/useInstanceRefActions.js +54 -43
  86. package/cjs/utils/useInstanceRefActions.js.map +7 -0
  87. package/cjs/utils/useTree.js +76 -78
  88. package/cjs/utils/useTree.js.map +7 -0
  89. package/esm/TreeView.js +18 -20
  90. package/esm/TreeView.js.map +7 -0
  91. package/esm/TreeViewContext.js +24 -29
  92. package/esm/TreeViewContext.js.map +7 -0
  93. package/esm/config/cssClassesConstants.js +12 -6
  94. package/esm/config/cssClassesConstants.js.map +7 -0
  95. package/esm/config/useTreeview.js +61 -54
  96. package/esm/config/useTreeview.js.map +7 -0
  97. package/esm/index.js +8 -9
  98. package/esm/index.js.map +7 -0
  99. package/esm/parts/CheckboxSelectable.js +36 -46
  100. package/esm/parts/CheckboxSelectable.js.map +7 -0
  101. package/esm/parts/ChildrenCountDisplayer.js +16 -20
  102. package/esm/parts/ChildrenCountDisplayer.js.map +7 -0
  103. package/esm/parts/ExpandCaret.js +54 -72
  104. package/esm/parts/ExpandCaret.js.map +7 -0
  105. package/esm/parts/Icon.js +16 -22
  106. package/esm/parts/Icon.js.map +7 -0
  107. package/esm/parts/NestingSpace.js +14 -27
  108. package/esm/parts/NestingSpace.js.map +7 -0
  109. package/esm/parts/RadioSelectable.js +20 -28
  110. package/esm/parts/RadioSelectable.js.map +7 -0
  111. package/esm/parts/TreeItem.js +91 -127
  112. package/esm/parts/TreeItem.js.map +7 -0
  113. package/esm/parts/TreeItemText.js +58 -85
  114. package/esm/parts/TreeItemText.js.map +7 -0
  115. package/esm/parts/TreeList.js +88 -117
  116. package/esm/parts/TreeList.js.map +7 -0
  117. package/esm/plugins/dnd/TreeDndPlugin.js +21 -26
  118. package/esm/plugins/dnd/TreeDndPlugin.js.map +7 -0
  119. package/esm/plugins/dnd/index.js +3 -1
  120. package/esm/plugins/dnd/index.js.map +7 -0
  121. package/esm/plugins/index.js +9 -7
  122. package/esm/plugins/index.js.map +7 -0
  123. package/esm/plugins/roving/TreeRovingPlugin.js +6 -3
  124. package/esm/plugins/roving/TreeRovingPlugin.js.map +7 -0
  125. package/esm/plugins/roving/index.js +3 -1
  126. package/esm/plugins/roving/index.js.map +7 -0
  127. package/esm/plugins/searchable/SearchableTreePlugin.js +6 -3
  128. package/esm/plugins/searchable/SearchableTreePlugin.js.map +7 -0
  129. package/esm/plugins/searchable/index.js +3 -1
  130. package/esm/plugins/searchable/index.js.map +7 -0
  131. package/esm/plugins/selectable/SelectablePluginTree.js +6 -3
  132. package/esm/plugins/selectable/SelectablePluginTree.js.map +7 -0
  133. package/esm/plugins/selectable/index.js +3 -1
  134. package/esm/plugins/selectable/index.js.map +7 -0
  135. package/esm/plugins/toolbar/TreeToolbarPlugin.js +6 -3
  136. package/esm/plugins/toolbar/TreeToolbarPlugin.js.map +7 -0
  137. package/esm/plugins/toolbar/index.js +3 -1
  138. package/esm/plugins/toolbar/index.js.map +7 -0
  139. package/esm/plugins/tree/TreeDataPlugin.js +6 -3
  140. package/esm/plugins/tree/TreeDataPlugin.js.map +7 -0
  141. package/esm/plugins/tree/index.js +3 -1
  142. package/esm/plugins/tree/index.js.map +7 -0
  143. package/esm/plugins/virtualization/TreeVirtualizationPlugin.js +6 -3
  144. package/esm/plugins/virtualization/TreeVirtualizationPlugin.js.map +7 -0
  145. package/esm/plugins/virtualization/index.js +3 -1
  146. package/esm/plugins/virtualization/index.js.map +7 -0
  147. package/esm/react-desc-prop-types.js +47 -43
  148. package/esm/react-desc-prop-types.js.map +7 -0
  149. package/esm/related-components/TreeViewSearchBar.js +13 -32
  150. package/esm/related-components/TreeViewSearchBar.js.map +7 -0
  151. package/esm/sharedTypes.js +2 -1
  152. package/esm/sharedTypes.js.map +7 -0
  153. package/esm/utils/array-helpers.js +6 -6
  154. package/esm/utils/array-helpers.js.map +7 -0
  155. package/esm/utils/dnd-helpers.js +58 -73
  156. package/esm/utils/dnd-helpers.js.map +7 -0
  157. package/esm/utils/group-expands-helpers.js +56 -46
  158. package/esm/utils/group-expands-helpers.js.map +7 -0
  159. package/esm/utils/keyboard-helpers.js +45 -72
  160. package/esm/utils/keyboard-helpers.js.map +7 -0
  161. package/esm/utils/object-helpers.js +14 -31
  162. package/esm/utils/object-helpers.js.map +7 -0
  163. package/esm/utils/refs-helpers.js +15 -19
  164. package/esm/utils/refs-helpers.js.map +7 -0
  165. package/esm/utils/selectable-helper.js +32 -43
  166. package/esm/utils/selectable-helper.js.map +7 -0
  167. package/esm/utils/string-helpers.js +6 -3
  168. package/esm/utils/string-helpers.js.map +7 -0
  169. package/esm/utils/tree-helpers.js +74 -119
  170. package/esm/utils/tree-helpers.js.map +7 -0
  171. package/esm/utils/useDnDHelpers.js +60 -106
  172. package/esm/utils/useDnDHelpers.js.map +7 -0
  173. package/esm/utils/useInstanceRefActions.js +21 -35
  174. package/esm/utils/useInstanceRefActions.js.map +7 -0
  175. package/esm/utils/useTree.js +35 -57
  176. package/esm/utils/useTree.js.map +7 -0
  177. package/package.json +10 -10
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/utils/useInstanceRefActions.tsx"],
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { useEffect, useMemo, useState, useRef, useCallback } from 'react';\nimport { focusItem } from './tree-helpers';\nimport { toggleExpandAllHelper } from './group-expands-helpers';\nimport type { DSTreeviewT } from '../react-desc-prop-types';\nimport type { DSTreeviewInternalsT } from '../sharedTypes';\n\ninterface PromisesRefT {\n expandResolve?: null | ((value: DSTreeviewT.Item[] | PromiseLike<DSTreeviewT.Item[]>) => void);\n scrollTo?: null | ((value: DSTreeviewT.Item[] | PromiseLike<DSTreeviewT.Item[]>) => void);\n}\n\nexport const useInstanceRefActions = ({ actions }: DSTreeviewT.InstanceRef, ctx: DSTreeviewInternalsT.CTX) => {\n const {\n props: { onItemFocus },\n virtualListHelpers,\n treeRoot,\n visibleItems,\n triggerTreeRerender,\n updateUserExpandedState,\n setSelectedItem,\n setFocusedItem,\n setLatestToggledItem,\n } = ctx;\n const { current: promises } = useRef<PromisesRefT>({});\n const { scrollToIndex } = useMemo(() => virtualListHelpers, [virtualListHelpers]);\n const [expandPromise, setPromise] = useState<Promise<DSTreeviewT.Item[]> | undefined | null>();\n\n useEffect(() => {\n if (expandPromise && promises.expandResolve) {\n promises.expandResolve(visibleItems);\n promises.expandResolve = null;\n setPromise(null);\n }\n }, [visibleItems, expandPromise, promises]);\n\n actions.toggleExpandAll = useCallback(\n (isExpand) => {\n const p = new Promise<DSTreeviewT.Item[]>((resolve) => {\n promises.expandResolve = resolve;\n if (treeRoot)\n toggleExpandAllHelper(isExpand, treeRoot, triggerTreeRerender, setLatestToggledItem, updateUserExpandedState);\n });\n setPromise(p);\n return p;\n },\n [promises, treeRoot, triggerTreeRerender, setLatestToggledItem, updateUserExpandedState],\n );\n actions.scrollTo = useCallback(\n (indx, opts = { align: 'start' }) => {\n if (scrollToIndex) scrollToIndex(indx, opts);\n },\n [scrollToIndex],\n );\n\n actions.setSelectedItemByVirtualIndex = useCallback(\n (index) => {\n const itemByIndex = visibleItems[index];\n setSelectedItem(itemByIndex);\n },\n [visibleItems, setSelectedItem],\n );\n\n actions.setFocusedItemByVirtualIndex = useCallback(\n (index, opts = { align: 'start', withScroll: false }) => {\n const itemByIndex = visibleItems[index];\n const onItemFocusParams = {\n itemIndex: itemByIndex.virtualIndex as number,\n scrollToItem: () => scrollToIndex(index, opts),\n item: itemByIndex,\n };\n\n if (opts.withScroll && scrollToIndex) {\n scrollToIndex(index, opts);\n setTimeout(() => {\n setFocusedItem(itemByIndex);\n focusItem(itemByIndex);\n onItemFocus(onItemFocusParams);\n }, 300);\n } else {\n setFocusedItem(itemByIndex);\n focusItem(itemByIndex);\n onItemFocus(onItemFocusParams);\n }\n },\n [visibleItems, scrollToIndex, setFocusedItem, onItemFocus],\n );\n\n return actions;\n};\n"],
5
+ "mappings": "AAAA;ACAA;AACA;AACA;AASO,MAAM,wBAAwB,CAAC,EAAE,WAAoC,QAAkC;AAC5G,QAAM;AAAA,IACJ,OAAO,EAAE;AAAA,IACT;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,MACE;AACJ,QAAM,EAAE,SAAS,aAAa,OAAqB;AACnD,QAAM,EAAE,kBAAkB,QAAQ,MAAM,oBAAoB,CAAC;AAC7D,QAAM,CAAC,eAAe,cAAc;AAEpC,YAAU,MAAM;AACd,QAAI,iBAAiB,SAAS,eAAe;AAC3C,eAAS,cAAc;AACvB,eAAS,gBAAgB;AACzB,iBAAW;AAAA;AAAA,KAEZ,CAAC,cAAc,eAAe;AAEjC,UAAQ,kBAAkB,YACxB,CAAC,aAAa;AACZ,UAAM,IAAI,IAAI,QAA4B,CAAC,YAAY;AACrD,eAAS,gBAAgB;AACzB,UAAI;AACF,8BAAsB,UAAU,UAAU,qBAAqB,sBAAsB;AAAA;AAEzF,eAAW;AACX,WAAO;AAAA,KAET,CAAC,UAAU,UAAU,qBAAqB,sBAAsB;AAElE,UAAQ,WAAW,YACjB,CAAC,MAAM,OAAO,EAAE,OAAO,cAAc;AACnC,QAAI;AAAe,oBAAc,MAAM;AAAA,KAEzC,CAAC;AAGH,UAAQ,gCAAgC,YACtC,CAAC,UAAU;AACT,UAAM,cAAc,aAAa;AACjC,oBAAgB;AAAA,KAElB,CAAC,cAAc;AAGjB,UAAQ,+BAA+B,YACrC,CAAC,OAAO,OAAO,EAAE,OAAO,SAAS,YAAY,YAAY;AACvD,UAAM,cAAc,aAAa;AACjC,UAAM,oBAAoB;AAAA,MACxB,WAAW,YAAY;AAAA,MACvB,cAAc,MAAM,cAAc,OAAO;AAAA,MACzC,MAAM;AAAA;AAGR,QAAI,KAAK,cAAc,eAAe;AACpC,oBAAc,OAAO;AACrB,iBAAW,MAAM;AACf,uBAAe;AACf,kBAAU;AACV,oBAAY;AAAA,SACX;AAAA,WACE;AACL,qBAAe;AACf,gBAAU;AACV,kBAAY;AAAA;AAAA,KAGhB,CAAC,cAAc,eAAe,gBAAgB;AAGhD,SAAO;AAAA;",
6
+ "names": []
7
+ }
@@ -1,88 +1,64 @@
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 { useMemo, useState, useEffect, useCallback } from 'react';
9
- import TreeModel from 'tree-model';
10
- import { cloneDeep } from 'lodash';
11
- import { enrichNodeModelInPlace, walkVisibles } from './tree-helpers.js';
12
- import { updateExpandedState } from './group-expands-helpers.js';
13
-
14
- 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; }
15
-
16
- 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; }
1
+ import * as React from "react";
2
+ import { useState, useCallback, useMemo, useEffect } from "react";
3
+ import TreeModel from "tree-model";
4
+ import { cloneDeep } from "lodash";
5
+ import { walkVisibles, enrichNodeModelInPlace } from "./tree-helpers";
6
+ import { updateExpandedState } from "./group-expands-helpers";
17
7
  const useTree = (data, props, states) => {
18
- const {
19
- setExpandedGroups
20
- } = states;
21
- const unfrozenData = useMemo(() => cloneDeep(data), [data]); // convert data into a TreeModel with extra isExpanded prop
22
- // root element type is an exception, children model is based on what the dev passed on
23
- // since root is an excepcion we must typecast
24
-
8
+ const { setExpandedGroups } = states;
9
+ const unfrozenData = useMemo(() => cloneDeep(data), [data]);
25
10
  const tree = useMemo(() => new TreeModel(), []);
26
11
  const [treeData, setTreeData] = useState({
27
- id: '__ds_tree_root',
28
- name: '__root',
12
+ id: "__ds_tree_root",
13
+ name: "__root",
29
14
  isExpanded: true,
30
15
  children: unfrozenData
31
16
  });
32
17
  useEffect(() => {
33
18
  setTreeData({
34
- id: '__ds_tree_root',
35
- name: '__root',
19
+ id: "__ds_tree_root",
20
+ name: "__root",
36
21
  isExpanded: true,
37
22
  children: unfrozenData
38
23
  });
39
- }, [unfrozenData]); // expose a way to rerender the tree
40
- // used for expand functionality
41
-
24
+ }, [unfrozenData]);
42
25
  const [rerenderItems, setRerenderItems] = useState({});
43
26
  const triggerTreeRerender = useCallback(() => {
44
27
  setRerenderItems({});
45
- }, []); // when re-rendering we re-parse the list
46
-
28
+ }, []);
47
29
  const [treeRoot, setTreeRoot] = useState(tree.parse(treeData));
48
30
  useEffect(() => {
49
31
  setTreeRoot(tree.parse(treeData));
50
32
  }, [treeData, rerenderItems, tree]);
51
33
  const [visibleItems, setVisibleItems] = useState([]);
52
- const {
53
- searchQuery,
54
- highlightOnlyQuery,
55
- onVisibleItemsChange,
56
- selection,
57
- expanded,
58
- onExpandChange
59
- } = props;
34
+ const { searchQuery, highlightOnlyQuery, onVisibleItemsChange, selection, expanded, onExpandChange } = props;
60
35
  const updateUserExpandedState = useCallback(() => {
61
36
  updateExpandedState(treeRoot, onExpandChange);
62
- }, [treeRoot, onExpandChange]); // we add missing properties to the received Items
63
- // not the best of the patterns, but it works
64
- // this is where we convert "SimpleItems" to "Items"
65
- // this was done to avoid breaking changes back in v1
66
-
37
+ }, [treeRoot, onExpandChange]);
67
38
  useEffect(() => {
68
39
  const parsedVisibleItems = [];
69
40
  const newExpandedHashMap = {};
70
- treeRoot.walk(node => {
71
- const shouldContinueWalking = true; // tree-model ask we return true if we want to continue walking
72
-
41
+ treeRoot.walk((node) => {
42
+ const shouldContinueWalking = true;
73
43
  enrichNodeModelInPlace(node, searchQuery, selection, expanded);
74
- if (node.model.id && node.model.isGroup && node.model.isExpanded) newExpandedHashMap[node.model.id] = true;
44
+ if (node.model.id && node.model.isGroup && node.model.isExpanded)
45
+ newExpandedHashMap[node.model.id] = true;
75
46
  return shouldContinueWalking;
76
47
  });
77
- walkVisibles(treeRoot, node => {
78
- parsedVisibleItems.push(_objectSpread(_objectSpread({}, node.model), {}, {
79
- node
80
- }));
48
+ walkVisibles(treeRoot, (node) => {
49
+ parsedVisibleItems.push({ ...node.model, node });
81
50
  }, true, highlightOnlyQuery);
82
51
  setVisibleItems(parsedVisibleItems);
83
52
  onVisibleItemsChange(parsedVisibleItems);
84
- setExpandedGroups(newExpandedHashMap); // eslint-disable-next-line react-hooks/exhaustive-deps
85
- }, [treeRoot, rerenderItems, searchQuery, highlightOnlyQuery, selection, expanded, setExpandedGroups // onVisibleItemsChange // evaluate potential performance hit?
53
+ setExpandedGroups(newExpandedHashMap);
54
+ }, [
55
+ treeRoot,
56
+ rerenderItems,
57
+ searchQuery,
58
+ highlightOnlyQuery,
59
+ selection,
60
+ expanded,
61
+ setExpandedGroups
86
62
  ]);
87
63
  return {
88
64
  visibleItems,
@@ -93,5 +69,7 @@ const useTree = (data, props, states) => {
93
69
  updateUserExpandedState
94
70
  };
95
71
  };
96
-
97
- export { useTree };
72
+ export {
73
+ useTree
74
+ };
75
+ //# sourceMappingURL=useTree.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../../src/utils/useTree.tsx"],
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { useState, useCallback, useMemo, useEffect } from 'react';\nimport TreeModel from 'tree-model';\nimport { cloneDeep } from 'lodash';\n\nimport { walkVisibles, enrichNodeModelInPlace } from './tree-helpers';\nimport type { DSTreeviewT } from '../react-desc-prop-types';\nimport type { DSTreeviewInternalsT } from '../sharedTypes';\nimport { updateExpandedState } from './group-expands-helpers';\n\nexport const useTree = (\n data: DSTreeviewT.SimpleItem[],\n props: DSTreeviewT.Props,\n states: {\n setExpandedGroups: DSTreeviewInternalsT.StateSetter<DSTreeviewT.ExpandedItems>;\n },\n) => {\n const { setExpandedGroups } = states;\n const unfrozenData = useMemo(() => cloneDeep(data), [data]);\n\n // convert data into a TreeModel with extra isExpanded prop\n // root element type is an exception, children model is based on what the dev passed on\n // since root is an excepcion we must typecast\n const tree = useMemo(() => new TreeModel(), []);\n const [treeData, setTreeData] = useState({\n id: '__ds_tree_root',\n name: '__root',\n isExpanded: true,\n children: unfrozenData,\n } as unknown as DSTreeviewT.Item);\n\n useEffect(() => {\n setTreeData({\n id: '__ds_tree_root',\n name: '__root',\n isExpanded: true,\n children: unfrozenData,\n } as unknown as DSTreeviewT.Item);\n }, [unfrozenData]);\n\n // expose a way to rerender the tree\n // used for expand functionality\n const [rerenderItems, setRerenderItems] = useState({});\n const triggerTreeRerender = useCallback(() => {\n setRerenderItems({});\n }, []);\n\n // when re-rendering we re-parse the list\n const [treeRoot, setTreeRoot] = useState(tree.parse(treeData));\n useEffect(() => {\n setTreeRoot(tree.parse(treeData));\n }, [treeData, rerenderItems, tree]);\n\n const [visibleItems, setVisibleItems] = useState<DSTreeviewT.Item[]>([]);\n\n const { searchQuery, highlightOnlyQuery, onVisibleItemsChange, selection, expanded, onExpandChange } = props;\n\n const updateUserExpandedState = useCallback(() => {\n updateExpandedState(treeRoot, onExpandChange);\n }, [treeRoot, onExpandChange]);\n // we add missing properties to the received Items\n // not the best of the patterns, but it works\n // this is where we convert \"SimpleItems\" to \"Items\"\n // this was done to avoid breaking changes back in v1\n useEffect(() => {\n const parsedVisibleItems: DSTreeviewT.Item[] = [];\n const newExpandedHashMap: DSTreeviewT.ExpandedItems = {};\n treeRoot.walk((node) => {\n const shouldContinueWalking = true; // tree-model ask we return true if we want to continue walking\n enrichNodeModelInPlace(node, searchQuery, selection, expanded);\n if (node.model.id && node.model.isGroup && node.model.isExpanded) newExpandedHashMap[node.model.id] = true;\n return shouldContinueWalking;\n });\n\n walkVisibles(\n treeRoot,\n (node) => {\n parsedVisibleItems.push({ ...node.model, node });\n },\n true,\n highlightOnlyQuery,\n );\n setVisibleItems(parsedVisibleItems);\n onVisibleItemsChange(parsedVisibleItems);\n\n setExpandedGroups(newExpandedHashMap);\n // eslint-disable-next-line react-hooks/exhaustive-deps\n }, [\n treeRoot,\n rerenderItems,\n searchQuery,\n highlightOnlyQuery,\n selection,\n expanded,\n setExpandedGroups,\n // onVisibleItemsChange // evaluate potential performance hit?\n ]);\n\n return {\n visibleItems,\n tree,\n treeRoot,\n rerenderItems,\n triggerTreeRerender,\n updateUserExpandedState,\n };\n};\n"],
5
+ "mappings": "AAAA;ACAA;AACA;AACA;AAEA;AAGA;AAEO,MAAM,UAAU,CACrB,MACA,OACA,WAGG;AACH,QAAM,EAAE,sBAAsB;AAC9B,QAAM,eAAe,QAAQ,MAAM,UAAU,OAAO,CAAC;AAKrD,QAAM,OAAO,QAAQ,MAAM,IAAI,aAAa;AAC5C,QAAM,CAAC,UAAU,eAAe,SAAS;AAAA,IACvC,IAAI;AAAA,IACJ,MAAM;AAAA,IACN,YAAY;AAAA,IACZ,UAAU;AAAA;AAGZ,YAAU,MAAM;AACd,gBAAY;AAAA,MACV,IAAI;AAAA,MACJ,MAAM;AAAA,MACN,YAAY;AAAA,MACZ,UAAU;AAAA;AAAA,KAEX,CAAC;AAIJ,QAAM,CAAC,eAAe,oBAAoB,SAAS;AACnD,QAAM,sBAAsB,YAAY,MAAM;AAC5C,qBAAiB;AAAA,KAChB;AAGH,QAAM,CAAC,UAAU,eAAe,SAAS,KAAK,MAAM;AACpD,YAAU,MAAM;AACd,gBAAY,KAAK,MAAM;AAAA,KACtB,CAAC,UAAU,eAAe;AAE7B,QAAM,CAAC,cAAc,mBAAmB,SAA6B;AAErE,QAAM,EAAE,aAAa,oBAAoB,sBAAsB,WAAW,UAAU,mBAAmB;AAEvG,QAAM,0BAA0B,YAAY,MAAM;AAChD,wBAAoB,UAAU;AAAA,KAC7B,CAAC,UAAU;AAKd,YAAU,MAAM;AACd,UAAM,qBAAyC;AAC/C,UAAM,qBAAgD;AACtD,aAAS,KAAK,CAAC,SAAS;AACtB,YAAM,wBAAwB;AAC9B,6BAAuB,MAAM,aAAa,WAAW;AACrD,UAAI,KAAK,MAAM,MAAM,KAAK,MAAM,WAAW,KAAK,MAAM;AAAY,2BAAmB,KAAK,MAAM,MAAM;AACtG,aAAO;AAAA;AAGT,iBACE,UACA,CAAC,SAAS;AACR,yBAAmB,KAAK,KAAK,KAAK,OAAO;AAAA,OAE3C,MACA;AAEF,oBAAgB;AAChB,yBAAqB;AAErB,sBAAkB;AAAA,KAEjB;AAAA,IACD;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA;AAIF,SAAO;AAAA,IACL;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA;AAAA;",
6
+ "names": []
7
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elliemae/ds-treeview",
3
- "version": "2.1.0",
3
+ "version": "2.2.0-alpha.3",
4
4
  "license": "MIT",
5
5
  "description": "ICE MT - Dimsum - Tree View",
6
6
  "module": "./esm/index.js",
@@ -211,15 +211,15 @@
211
211
  "generateSubmodules": true
212
212
  },
213
213
  "dependencies": {
214
- "@elliemae/ds-button": "2.1.0",
215
- "@elliemae/ds-circular-progress-indicator": "2.1.0",
216
- "@elliemae/ds-classnames": "2.1.0",
217
- "@elliemae/ds-form": "2.1.0",
218
- "@elliemae/ds-icons": "2.1.0",
219
- "@elliemae/ds-props-helpers": "2.1.0",
220
- "@elliemae/ds-shared": "2.1.0",
221
- "@elliemae/ds-truncated-tooltip-text": "2.1.0",
222
- "@elliemae/ds-utilities": "2.1.0",
214
+ "@elliemae/ds-button": "2.2.0-alpha.3",
215
+ "@elliemae/ds-circular-progress-indicator": "2.2.0-alpha.3",
216
+ "@elliemae/ds-classnames": "2.2.0-alpha.3",
217
+ "@elliemae/ds-form": "2.2.0-alpha.3",
218
+ "@elliemae/ds-icons": "2.2.0-alpha.3",
219
+ "@elliemae/ds-props-helpers": "2.2.0-alpha.3",
220
+ "@elliemae/ds-shared": "2.2.0-alpha.3",
221
+ "@elliemae/ds-truncated-tooltip-text": "2.2.0-alpha.3",
222
+ "@elliemae/ds-utilities": "2.2.0-alpha.3",
223
223
  "@elliemae/react-sortable-hoc": "^1.0.0",
224
224
  "react-desc": "~4.1.3",
225
225
  "react-highlight-words": "~0.17.0",