@elliemae/ds-treeview 2.3.0-alpha.9 → 2.3.0-next.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 (333) hide show
  1. package/cjs/TreeView.js +30 -0
  2. package/cjs/TreeViewContext.js +98 -0
  3. package/cjs/config/cssClassesConstants.js +13 -0
  4. package/cjs/config/useTreeview.js +127 -0
  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 -0
  10. package/cjs/parts/CheckboxSelectable.js +86 -0
  11. package/cjs/parts/ChildrenCountDisplayer.js +30 -0
  12. package/cjs/parts/DnDHandle.js +46 -0
  13. package/cjs/parts/DropIndicator.js +75 -0
  14. package/cjs/parts/ExpandCaret.js +94 -0
  15. package/cjs/parts/Icon.js +37 -0
  16. package/cjs/parts/NestingSpace.js +47 -0
  17. package/cjs/parts/RadioSelectable.js +59 -0
  18. package/cjs/parts/TreeItem.js +185 -0
  19. package/cjs/parts/TreeItemText.js +108 -0
  20. package/cjs/parts/TreeList.js +139 -0
  21. package/cjs/plugins/dnd/TreeDndPlugin.js +7 -0
  22. package/cjs/plugins/dnd/index.js +9 -0
  23. package/cjs/plugins/index.js +21 -0
  24. package/cjs/plugins/roving/TreeRovingPlugin.js +7 -0
  25. package/cjs/plugins/roving/index.js +9 -0
  26. package/cjs/plugins/searchable/SearchableTreePlugin.js +7 -0
  27. package/cjs/plugins/searchable/index.js +9 -0
  28. package/cjs/plugins/selectable/SelectablePluginTree.js +7 -0
  29. package/cjs/plugins/selectable/index.js +9 -0
  30. package/cjs/plugins/toolbar/TreeToolbarPlugin.js +7 -0
  31. package/cjs/plugins/toolbar/index.js +9 -0
  32. package/cjs/plugins/tree/TreeDataPlugin.js +7 -0
  33. package/cjs/plugins/tree/index.js +9 -0
  34. package/cjs/plugins/virtualization/TreeVirtualizationPlugin.js +7 -0
  35. package/cjs/plugins/virtualization/index.js +9 -0
  36. package/cjs/react-desc-prop-types.js +56 -0
  37. package/cjs/related-components/TreeViewSearchBar.js +48 -0
  38. package/cjs/sharedTypes.js +2 -0
  39. package/cjs/utils/array-helpers.js +24 -0
  40. package/cjs/utils/group-expands-helpers.js +111 -0
  41. package/cjs/utils/keyboard-helpers.js +175 -0
  42. package/cjs/utils/object-helpers.js +69 -0
  43. package/cjs/utils/refs-helpers.js +31 -0
  44. package/cjs/utils/selectable-helper.js +80 -0
  45. package/cjs/utils/string-helpers.js +7 -0
  46. package/cjs/utils/tree-helpers.js +220 -0
  47. package/cjs/utils/useInstanceRefActions.js +87 -0
  48. package/cjs/utils/useTree.js +108 -0
  49. package/esm/TreeView.js +21 -0
  50. package/{dist/esm → esm}/TreeViewContext.js +29 -24
  51. package/esm/config/cssClassesConstants.js +6 -0
  52. package/esm/config/useTreeview.js +119 -0
  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 -0
  58. package/esm/parts/CheckboxSelectable.js +78 -0
  59. package/esm/parts/ChildrenCountDisplayer.js +22 -0
  60. package/esm/parts/DnDHandle.js +38 -0
  61. package/esm/parts/DropIndicator.js +68 -0
  62. package/esm/parts/ExpandCaret.js +85 -0
  63. package/esm/parts/Icon.js +29 -0
  64. package/esm/parts/NestingSpace.js +39 -0
  65. package/esm/parts/RadioSelectable.js +53 -0
  66. package/esm/parts/TreeItem.js +173 -0
  67. package/esm/parts/TreeItemText.js +99 -0
  68. package/esm/parts/TreeList.js +127 -0
  69. package/esm/plugins/dnd/TreeDndPlugin.js +3 -0
  70. package/esm/plugins/dnd/index.js +1 -0
  71. package/esm/plugins/index.js +7 -0
  72. package/esm/plugins/roving/TreeRovingPlugin.js +3 -0
  73. package/esm/plugins/roving/index.js +1 -0
  74. package/esm/plugins/searchable/SearchableTreePlugin.js +3 -0
  75. package/esm/plugins/searchable/index.js +1 -0
  76. package/esm/plugins/selectable/SelectablePluginTree.js +3 -0
  77. package/esm/plugins/selectable/index.js +1 -0
  78. package/esm/plugins/toolbar/TreeToolbarPlugin.js +3 -0
  79. package/esm/plugins/toolbar/index.js +1 -0
  80. package/esm/plugins/tree/TreeDataPlugin.js +3 -0
  81. package/esm/plugins/tree/index.js +1 -0
  82. package/esm/plugins/virtualization/TreeVirtualizationPlugin.js +3 -0
  83. package/esm/plugins/virtualization/index.js +1 -0
  84. package/esm/react-desc-prop-types.js +52 -0
  85. package/esm/related-components/TreeViewSearchBar.js +40 -0
  86. package/esm/sharedTypes.js +1 -0
  87. package/{dist/esm → esm}/utils/array-helpers.js +6 -6
  88. package/esm/utils/group-expands-helpers.js +99 -0
  89. package/{dist/esm → esm}/utils/keyboard-helpers.js +71 -43
  90. package/esm/utils/object-helpers.js +64 -0
  91. package/esm/utils/refs-helpers.js +27 -0
  92. package/esm/utils/selectable-helper.js +70 -0
  93. package/esm/utils/string-helpers.js +3 -0
  94. package/esm/utils/tree-helpers.js +205 -0
  95. package/{dist/esm → esm}/utils/useInstanceRefActions.js +35 -21
  96. package/esm/utils/useTree.js +99 -0
  97. package/package.json +121 -124
  98. package/{dist/types → types}/TreeView.d.ts +0 -0
  99. package/{dist/types → types}/TreeViewContext.d.ts +0 -0
  100. package/{dist/types → types}/config/cssClassesConstants.d.ts +0 -0
  101. package/{dist/types → types}/config/useTreeview.d.ts +0 -0
  102. package/{dist/types → types}/hoc/DnDTreeContext.d.ts +0 -0
  103. package/{dist/types → types}/hoc/SortableItemContext.d.ts +0 -0
  104. package/{dist/types → types}/hoc/WithConditionalDnDContext.d.ts +0 -0
  105. package/{dist/types → types}/hoc/WithDnDSortableItemContext.d.ts +0 -0
  106. package/{dist/types → types}/index.d.ts +0 -0
  107. package/{dist/types → types}/parts/CheckboxSelectable.d.ts +0 -0
  108. package/{dist/types → types}/parts/ChildrenCountDisplayer.d.ts +0 -0
  109. package/{dist/types → types}/parts/DnDHandle.d.ts +0 -0
  110. package/{dist/types → types}/parts/DropIndicator.d.ts +0 -0
  111. package/{dist/types → types}/parts/ExpandCaret.d.ts +0 -0
  112. package/{dist/types → types}/parts/Icon.d.ts +0 -0
  113. package/{dist/types → types}/parts/NestingSpace.d.ts +0 -0
  114. package/{dist/types → types}/parts/RadioSelectable.d.ts +0 -0
  115. package/{dist/types → types}/parts/TreeItem.d.ts +0 -0
  116. package/{dist/types → types}/parts/TreeItemText.d.ts +0 -0
  117. package/{dist/types → types}/parts/TreeList.d.ts +0 -0
  118. package/{dist/types → types}/plugins/dnd/TreeDndPlugin.d.ts +0 -0
  119. package/{dist/types → types}/plugins/dnd/index.d.ts +0 -0
  120. package/{dist/types → types}/plugins/index.d.ts +0 -0
  121. package/{dist/types → types}/plugins/roving/TreeRovingPlugin.d.ts +0 -0
  122. package/{dist/types → types}/plugins/roving/index.d.ts +0 -0
  123. package/{dist/types → types}/plugins/searchable/SearchableTreePlugin.d.ts +0 -0
  124. package/{dist/types → types}/plugins/searchable/index.d.ts +0 -0
  125. package/{dist/types → types}/plugins/selectable/SelectablePluginTree.d.ts +0 -0
  126. package/{dist/types → types}/plugins/selectable/index.d.ts +0 -0
  127. package/{dist/types → types}/plugins/toolbar/TreeToolbarPlugin.d.ts +0 -0
  128. package/{dist/types → types}/plugins/toolbar/index.d.ts +0 -0
  129. package/{dist/types → types}/plugins/tree/TreeDataPlugin.d.ts +0 -0
  130. package/{dist/types → types}/plugins/tree/index.d.ts +0 -0
  131. package/{dist/types → types}/plugins/virtualization/TreeVirtualizationPlugin.d.ts +0 -0
  132. package/{dist/types → types}/plugins/virtualization/index.d.ts +0 -0
  133. package/{dist/types → types}/react-desc-prop-types.d.ts +0 -0
  134. package/{dist/types → types}/related-components/TreeViewSearchBar.d.ts +0 -0
  135. package/{dist/types → types}/sharedTypes.d.ts +0 -0
  136. package/{dist/types → types}/utils/array-helpers.d.ts +0 -0
  137. package/{dist/types → types}/utils/group-expands-helpers.d.ts +0 -0
  138. package/{dist/types → types}/utils/keyboard-helpers.d.ts +0 -0
  139. package/{dist/types → types}/utils/object-helpers.d.ts +0 -0
  140. package/{dist/types → types}/utils/refs-helpers.d.ts +0 -0
  141. package/{dist/types → types}/utils/selectable-helper.d.ts +0 -0
  142. package/{dist/types → types}/utils/string-helpers.d.ts +0 -0
  143. package/{dist/types → types}/utils/tree-helpers.d.ts +0 -0
  144. package/{dist/types → types}/utils/useInstanceRefActions.d.ts +0 -0
  145. package/{dist/types → types}/utils/useTree.d.ts +0 -0
  146. package/dist/cjs/TreeView.js +0 -50
  147. package/dist/cjs/TreeView.js.map +0 -7
  148. package/dist/cjs/TreeViewContext.js +0 -116
  149. package/dist/cjs/TreeViewContext.js.map +0 -7
  150. package/dist/cjs/config/cssClassesConstants.js +0 -41
  151. package/dist/cjs/config/cssClassesConstants.js.map +0 -7
  152. package/dist/cjs/config/useTreeview.js +0 -151
  153. package/dist/cjs/config/useTreeview.js.map +0 -7
  154. package/dist/cjs/hoc/DnDTreeContext.js +0 -45
  155. package/dist/cjs/hoc/DnDTreeContext.js.map +0 -7
  156. package/dist/cjs/hoc/SortableItemContext.js +0 -46
  157. package/dist/cjs/hoc/SortableItemContext.js.map +0 -7
  158. package/dist/cjs/hoc/WithConditionalDnDContext.js +0 -128
  159. package/dist/cjs/hoc/WithConditionalDnDContext.js.map +0 -7
  160. package/dist/cjs/hoc/WithDnDSortableItemContext.js +0 -69
  161. package/dist/cjs/hoc/WithDnDSortableItemContext.js.map +0 -7
  162. package/dist/cjs/index.js +0 -37
  163. package/dist/cjs/index.js.map +0 -7
  164. package/dist/cjs/parts/CheckboxSelectable.js +0 -97
  165. package/dist/cjs/parts/CheckboxSelectable.js.map +0 -7
  166. package/dist/cjs/parts/ChildrenCountDisplayer.js +0 -47
  167. package/dist/cjs/parts/ChildrenCountDisplayer.js.map +0 -7
  168. package/dist/cjs/parts/DnDHandle.js +0 -57
  169. package/dist/cjs/parts/DnDHandle.js.map +0 -7
  170. package/dist/cjs/parts/DropIndicator.js +0 -80
  171. package/dist/cjs/parts/DropIndicator.js.map +0 -7
  172. package/dist/cjs/parts/ExpandCaret.js +0 -96
  173. package/dist/cjs/parts/ExpandCaret.js.map +0 -7
  174. package/dist/cjs/parts/Icon.js +0 -52
  175. package/dist/cjs/parts/Icon.js.map +0 -7
  176. package/dist/cjs/parts/NestingSpace.js +0 -55
  177. package/dist/cjs/parts/NestingSpace.js.map +0 -7
  178. package/dist/cjs/parts/RadioSelectable.js +0 -74
  179. package/dist/cjs/parts/RadioSelectable.js.map +0 -7
  180. package/dist/cjs/parts/TreeItem.js +0 -166
  181. package/dist/cjs/parts/TreeItem.js.map +0 -7
  182. package/dist/cjs/parts/TreeItemText.js +0 -101
  183. package/dist/cjs/parts/TreeItemText.js.map +0 -7
  184. package/dist/cjs/parts/TreeList.js +0 -123
  185. package/dist/cjs/parts/TreeList.js.map +0 -7
  186. package/dist/cjs/plugins/dnd/TreeDndPlugin.js +0 -35
  187. package/dist/cjs/plugins/dnd/TreeDndPlugin.js.map +0 -7
  188. package/dist/cjs/plugins/dnd/index.js +0 -28
  189. package/dist/cjs/plugins/dnd/index.js.map +0 -7
  190. package/dist/cjs/plugins/index.js +0 -34
  191. package/dist/cjs/plugins/index.js.map +0 -7
  192. package/dist/cjs/plugins/roving/TreeRovingPlugin.js +0 -35
  193. package/dist/cjs/plugins/roving/TreeRovingPlugin.js.map +0 -7
  194. package/dist/cjs/plugins/roving/index.js +0 -28
  195. package/dist/cjs/plugins/roving/index.js.map +0 -7
  196. package/dist/cjs/plugins/searchable/SearchableTreePlugin.js +0 -35
  197. package/dist/cjs/plugins/searchable/SearchableTreePlugin.js.map +0 -7
  198. package/dist/cjs/plugins/searchable/index.js +0 -28
  199. package/dist/cjs/plugins/searchable/index.js.map +0 -7
  200. package/dist/cjs/plugins/selectable/SelectablePluginTree.js +0 -35
  201. package/dist/cjs/plugins/selectable/SelectablePluginTree.js.map +0 -7
  202. package/dist/cjs/plugins/selectable/index.js +0 -28
  203. package/dist/cjs/plugins/selectable/index.js.map +0 -7
  204. package/dist/cjs/plugins/toolbar/TreeToolbarPlugin.js +0 -35
  205. package/dist/cjs/plugins/toolbar/TreeToolbarPlugin.js.map +0 -7
  206. package/dist/cjs/plugins/toolbar/index.js +0 -28
  207. package/dist/cjs/plugins/toolbar/index.js.map +0 -7
  208. package/dist/cjs/plugins/tree/TreeDataPlugin.js +0 -35
  209. package/dist/cjs/plugins/tree/TreeDataPlugin.js.map +0 -7
  210. package/dist/cjs/plugins/tree/index.js +0 -28
  211. package/dist/cjs/plugins/tree/index.js.map +0 -7
  212. package/dist/cjs/plugins/virtualization/TreeVirtualizationPlugin.js +0 -35
  213. package/dist/cjs/plugins/virtualization/TreeVirtualizationPlugin.js.map +0 -7
  214. package/dist/cjs/plugins/virtualization/index.js +0 -28
  215. package/dist/cjs/plugins/virtualization/index.js.map +0 -7
  216. package/dist/cjs/react-desc-prop-types.js +0 -85
  217. package/dist/cjs/react-desc-prop-types.js.map +0 -7
  218. package/dist/cjs/related-components/TreeViewSearchBar.js +0 -50
  219. package/dist/cjs/related-components/TreeViewSearchBar.js.map +0 -7
  220. package/dist/cjs/sharedTypes.js +0 -27
  221. package/dist/cjs/sharedTypes.js.map +0 -7
  222. package/dist/cjs/utils/array-helpers.js +0 -48
  223. package/dist/cjs/utils/array-helpers.js.map +0 -7
  224. package/dist/cjs/utils/group-expands-helpers.js +0 -138
  225. package/dist/cjs/utils/group-expands-helpers.js.map +0 -7
  226. package/dist/cjs/utils/keyboard-helpers.js +0 -170
  227. package/dist/cjs/utils/keyboard-helpers.js.map +0 -7
  228. package/dist/cjs/utils/object-helpers.js +0 -76
  229. package/dist/cjs/utils/object-helpers.js.map +0 -7
  230. package/dist/cjs/utils/refs-helpers.js +0 -52
  231. package/dist/cjs/utils/refs-helpers.js.map +0 -7
  232. package/dist/cjs/utils/selectable-helper.js +0 -88
  233. package/dist/cjs/utils/selectable-helper.js.map +0 -7
  234. package/dist/cjs/utils/string-helpers.js +0 -35
  235. package/dist/cjs/utils/string-helpers.js.map +0 -7
  236. package/dist/cjs/utils/tree-helpers.js +0 -184
  237. package/dist/cjs/utils/tree-helpers.js.map +0 -7
  238. package/dist/cjs/utils/useInstanceRefActions.js +0 -98
  239. package/dist/cjs/utils/useInstanceRefActions.js.map +0 -7
  240. package/dist/cjs/utils/useTree.js +0 -106
  241. package/dist/cjs/utils/useTree.js.map +0 -7
  242. package/dist/esm/TreeView.js +0 -21
  243. package/dist/esm/TreeView.js.map +0 -7
  244. package/dist/esm/TreeViewContext.js.map +0 -7
  245. package/dist/esm/config/cssClassesConstants.js +0 -12
  246. package/dist/esm/config/cssClassesConstants.js.map +0 -7
  247. package/dist/esm/config/useTreeview.js +0 -122
  248. package/dist/esm/config/useTreeview.js.map +0 -7
  249. package/dist/esm/hoc/DnDTreeContext.js +0 -16
  250. package/dist/esm/hoc/DnDTreeContext.js.map +0 -7
  251. package/dist/esm/hoc/SortableItemContext.js +0 -17
  252. package/dist/esm/hoc/SortableItemContext.js.map +0 -7
  253. package/dist/esm/hoc/WithConditionalDnDContext.js +0 -99
  254. package/dist/esm/hoc/WithConditionalDnDContext.js.map +0 -7
  255. package/dist/esm/hoc/WithDnDSortableItemContext.js +0 -40
  256. package/dist/esm/hoc/WithDnDSortableItemContext.js.map +0 -7
  257. package/dist/esm/index.js +0 -8
  258. package/dist/esm/index.js.map +0 -7
  259. package/dist/esm/parts/CheckboxSelectable.js +0 -68
  260. package/dist/esm/parts/CheckboxSelectable.js.map +0 -7
  261. package/dist/esm/parts/ChildrenCountDisplayer.js +0 -18
  262. package/dist/esm/parts/ChildrenCountDisplayer.js.map +0 -7
  263. package/dist/esm/parts/DnDHandle.js +0 -28
  264. package/dist/esm/parts/DnDHandle.js.map +0 -7
  265. package/dist/esm/parts/DropIndicator.js +0 -51
  266. package/dist/esm/parts/DropIndicator.js.map +0 -7
  267. package/dist/esm/parts/ExpandCaret.js +0 -67
  268. package/dist/esm/parts/ExpandCaret.js.map +0 -7
  269. package/dist/esm/parts/Icon.js +0 -23
  270. package/dist/esm/parts/Icon.js.map +0 -7
  271. package/dist/esm/parts/NestingSpace.js +0 -26
  272. package/dist/esm/parts/NestingSpace.js.map +0 -7
  273. package/dist/esm/parts/RadioSelectable.js +0 -45
  274. package/dist/esm/parts/RadioSelectable.js.map +0 -7
  275. package/dist/esm/parts/TreeItem.js +0 -137
  276. package/dist/esm/parts/TreeItem.js.map +0 -7
  277. package/dist/esm/parts/TreeItemText.js +0 -72
  278. package/dist/esm/parts/TreeItemText.js.map +0 -7
  279. package/dist/esm/parts/TreeList.js +0 -94
  280. package/dist/esm/parts/TreeList.js.map +0 -7
  281. package/dist/esm/plugins/dnd/TreeDndPlugin.js +0 -6
  282. package/dist/esm/plugins/dnd/TreeDndPlugin.js.map +0 -7
  283. package/dist/esm/plugins/dnd/index.js +0 -3
  284. package/dist/esm/plugins/dnd/index.js.map +0 -7
  285. package/dist/esm/plugins/index.js +0 -9
  286. package/dist/esm/plugins/index.js.map +0 -7
  287. package/dist/esm/plugins/roving/TreeRovingPlugin.js +0 -6
  288. package/dist/esm/plugins/roving/TreeRovingPlugin.js.map +0 -7
  289. package/dist/esm/plugins/roving/index.js +0 -3
  290. package/dist/esm/plugins/roving/index.js.map +0 -7
  291. package/dist/esm/plugins/searchable/SearchableTreePlugin.js +0 -6
  292. package/dist/esm/plugins/searchable/SearchableTreePlugin.js.map +0 -7
  293. package/dist/esm/plugins/searchable/index.js +0 -3
  294. package/dist/esm/plugins/searchable/index.js.map +0 -7
  295. package/dist/esm/plugins/selectable/SelectablePluginTree.js +0 -6
  296. package/dist/esm/plugins/selectable/SelectablePluginTree.js.map +0 -7
  297. package/dist/esm/plugins/selectable/index.js +0 -3
  298. package/dist/esm/plugins/selectable/index.js.map +0 -7
  299. package/dist/esm/plugins/toolbar/TreeToolbarPlugin.js +0 -6
  300. package/dist/esm/plugins/toolbar/TreeToolbarPlugin.js.map +0 -7
  301. package/dist/esm/plugins/toolbar/index.js +0 -3
  302. package/dist/esm/plugins/toolbar/index.js.map +0 -7
  303. package/dist/esm/plugins/tree/TreeDataPlugin.js +0 -6
  304. package/dist/esm/plugins/tree/TreeDataPlugin.js.map +0 -7
  305. package/dist/esm/plugins/tree/index.js +0 -3
  306. package/dist/esm/plugins/tree/index.js.map +0 -7
  307. package/dist/esm/plugins/virtualization/TreeVirtualizationPlugin.js +0 -6
  308. package/dist/esm/plugins/virtualization/TreeVirtualizationPlugin.js.map +0 -7
  309. package/dist/esm/plugins/virtualization/index.js +0 -3
  310. package/dist/esm/plugins/virtualization/index.js.map +0 -7
  311. package/dist/esm/react-desc-prop-types.js +0 -56
  312. package/dist/esm/react-desc-prop-types.js.map +0 -7
  313. package/dist/esm/related-components/TreeViewSearchBar.js +0 -21
  314. package/dist/esm/related-components/TreeViewSearchBar.js.map +0 -7
  315. package/dist/esm/sharedTypes.js +0 -2
  316. package/dist/esm/sharedTypes.js.map +0 -7
  317. package/dist/esm/utils/array-helpers.js.map +0 -7
  318. package/dist/esm/utils/group-expands-helpers.js +0 -109
  319. package/dist/esm/utils/group-expands-helpers.js.map +0 -7
  320. package/dist/esm/utils/keyboard-helpers.js.map +0 -7
  321. package/dist/esm/utils/object-helpers.js +0 -47
  322. package/dist/esm/utils/object-helpers.js.map +0 -7
  323. package/dist/esm/utils/refs-helpers.js +0 -23
  324. package/dist/esm/utils/refs-helpers.js.map +0 -7
  325. package/dist/esm/utils/selectable-helper.js +0 -59
  326. package/dist/esm/utils/selectable-helper.js.map +0 -7
  327. package/dist/esm/utils/string-helpers.js +0 -6
  328. package/dist/esm/utils/string-helpers.js.map +0 -7
  329. package/dist/esm/utils/tree-helpers.js +0 -155
  330. package/dist/esm/utils/tree-helpers.js.map +0 -7
  331. package/dist/esm/utils/useInstanceRefActions.js.map +0 -7
  332. package/dist/esm/utils/useTree.js +0 -77
  333. package/dist/esm/utils/useTree.js.map +0 -7
@@ -0,0 +1,64 @@
1
+ import 'core-js/modules/esnext.async-iterator.for-each.js';
2
+ import 'core-js/modules/esnext.iterator.constructor.js';
3
+ import 'core-js/modules/esnext.iterator.for-each.js';
4
+ import 'core-js/modules/esnext.async-iterator.reduce.js';
5
+ import 'core-js/modules/esnext.iterator.reduce.js';
6
+
7
+ /* eslint-disable no-sequences */
8
+
9
+ /* eslint-disable no-return-assign */
10
+
11
+ /* eslint-disable no-restricted-syntax */
12
+
13
+ /* eslint-disable guard-for-in */
14
+ function isObjectADate(o) {
15
+ var _o$constructor;
16
+
17
+ return (o === null || o === void 0 ? void 0 : (_o$constructor = o.constructor) === null || _o$constructor === void 0 ? void 0 : _o$constructor.name) === 'Date';
18
+ }
19
+
20
+ function isObjectAnArray(o) {
21
+ return Array.isArray(o);
22
+ }
23
+
24
+ function isObjectAString(o) {
25
+ return typeof o === 'object';
26
+ }
27
+
28
+ const unfreeze = o => {
29
+ let oo;
30
+
31
+ if (o === null) {
32
+ oo = null;
33
+ } else if (o === undefined) {
34
+ oo = undefined;
35
+ } else if (isObjectADate(o)) {
36
+ oo = new Date(o);
37
+ } else if (isObjectAnArray(o)) {
38
+ oo = [];
39
+ o.forEach(v => {
40
+ oo.push(v);
41
+ });
42
+ } else if (isObjectAString(o)) {
43
+ oo = String(o);
44
+ } else if (isObjectAString(o)) {
45
+ oo = {};
46
+
47
+ for (const property in o) {
48
+ oo[property] = o[property];
49
+ }
50
+ } else {
51
+ oo = o;
52
+ }
53
+
54
+ return oo;
55
+ };
56
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
57
+ function filterObject(obj, predicate) {
58
+ return Object.keys(obj).reduce((res, key) => {
59
+ if (predicate(obj[key])) res[key] = obj[key];
60
+ return res;
61
+ }, {});
62
+ }
63
+
64
+ export { filterObject, unfreeze };
@@ -0,0 +1,27 @@
1
+ import 'core-js/modules/esnext.async-iterator.filter.js';
2
+ import 'core-js/modules/esnext.iterator.constructor.js';
3
+ import 'core-js/modules/esnext.iterator.filter.js';
4
+ import 'core-js/modules/esnext.async-iterator.for-each.js';
5
+ import 'core-js/modules/esnext.iterator.for-each.js';
6
+
7
+ // allow multiple refs to be set to point to the same DOM element
8
+ const setMultipleRefs = function () {
9
+ for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
10
+ refs[_key] = arguments[_key];
11
+ }
12
+
13
+ const filteredRefs = refs.filter(Boolean);
14
+ if (!filteredRefs.length) return () => {};
15
+ if (filteredRefs.length === 0) return () => {};
16
+ return newRef => {
17
+ filteredRefs.forEach(refToBeUpdated => {
18
+ if (typeof refToBeUpdated === 'function') {
19
+ refToBeUpdated(newRef);
20
+ } else if (refToBeUpdated) {
21
+ refToBeUpdated.current = newRef;
22
+ }
23
+ });
24
+ };
25
+ };
26
+
27
+ export { setMultipleRefs };
@@ -0,0 +1,70 @@
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 { walkAllNodeChildren, walkParents } from './tree-helpers.js';
8
+
9
+ 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; }
10
+
11
+ 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; }
12
+ const getGroupCheckState = node => {
13
+ let childAllChecked = true;
14
+ let anyChildChecked = false;
15
+ walkAllNodeChildren(node, childNode => {
16
+ const {
17
+ model: {
18
+ isChecked
19
+ }
20
+ } = childNode;
21
+ if (isChecked === 'mixed' || isChecked === true) anyChildChecked = true;else childAllChecked = false;
22
+ });
23
+ if (childAllChecked) return true;
24
+ if (anyChildChecked) return 'mixed';
25
+ return false;
26
+ };
27
+ const selectCheckboxItemModelParentsTillRoot = function (modelToCheck) {
28
+ let triggerTreeRerender = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
29
+ const newSelections = {};
30
+ const {
31
+ nodePath
32
+ } = modelToCheck;
33
+ walkParents(nodePath, parentNode => {
34
+ const nextState = getGroupCheckState(parentNode);
35
+ parentNode.model.isChecked = nextState;
36
+ newSelections[parentNode.model.id] = nextState;
37
+ });
38
+ if (triggerTreeRerender) triggerTreeRerender();
39
+ return newSelections;
40
+ };
41
+ const toggleCheckboxItem = function (itemToSelect) {
42
+ let triggerTreeRerender = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
43
+ const {
44
+ node: {
45
+ model: {
46
+ id,
47
+ isChecked,
48
+ children = []
49
+ }
50
+ }
51
+ } = itemToSelect;
52
+ const newSelections = {}; // 'mixed' -> true -> false -> true [...->false -> true]
53
+
54
+ const nextState = isChecked === 'mixed' ? true : !isChecked;
55
+ itemToSelect.node.model.isChecked = nextState;
56
+ newSelections[id] = nextState;
57
+
58
+ if (children.length > 0 && (nextState === true || nextState === false)) {
59
+ walkAllNodeChildren(itemToSelect.node, childNode => {
60
+ childNode.model.isChecked = nextState;
61
+ newSelections[childNode.model.id] = nextState;
62
+ });
63
+ }
64
+
65
+ const parentsNewSelections = selectCheckboxItemModelParentsTillRoot(itemToSelect);
66
+ if (triggerTreeRerender) triggerTreeRerender();
67
+ return _objectSpread(_objectSpread({}, parentsNewSelections), newSelections);
68
+ };
69
+
70
+ export { getGroupCheckState, selectCheckboxItemModelParentsTillRoot, toggleCheckboxItem };
@@ -0,0 +1,3 @@
1
+ const standardizeSearchQueryString = input => input.trim().toLowerCase();
2
+
3
+ export { standardizeSearchQueryString };
@@ -0,0 +1,205 @@
1
+ import 'core-js/modules/esnext.async-iterator.for-each.js';
2
+ import 'core-js/modules/esnext.iterator.constructor.js';
3
+ import 'core-js/modules/esnext.iterator.for-each.js';
4
+ import 'core-js/modules/web.dom-collections.iterator.js';
5
+ import 'core-js/modules/esnext.async-iterator.find.js';
6
+ import 'core-js/modules/esnext.iterator.find.js';
7
+ import 'core-js/modules/esnext.async-iterator.every.js';
8
+ import 'core-js/modules/esnext.iterator.every.js';
9
+ import { createRef } from 'react';
10
+ import { standardizeSearchQueryString } from './string-helpers.js';
11
+
12
+ const walkVisibles = function (node, callback) {
13
+ let skipRoot = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
14
+ let highlightOnlyQuery = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
15
+ const {
16
+ children,
17
+ model
18
+ } = node;
19
+ const {
20
+ name,
21
+ isExpanded,
22
+ childrenMatchesSearchQuery,
23
+ matchesSearchQuery
24
+ } = model;
25
+ const shouldSkipBecauseIsRoot = skipRoot && name === '__root';
26
+ const queryRestrictionsPassed = !!(highlightOnlyQuery || childrenMatchesSearchQuery || matchesSearchQuery);
27
+ if (!shouldSkipBecauseIsRoot && queryRestrictionsPassed) callback(node);
28
+ const shouldWalkChildren = !!(children.length > 0 && isExpanded && queryRestrictionsPassed);
29
+
30
+ if (shouldWalkChildren) {
31
+ children.forEach(childNode => {
32
+ walkVisibles(childNode, callback, skipRoot, highlightOnlyQuery);
33
+ });
34
+ }
35
+ };
36
+ const walkParents = function (nodePath, callback) {
37
+ let skipRoot = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
38
+ const parents = [...nodePath].reverse();
39
+ parents.shift(); // remove current node from the parents array
40
+
41
+ if (skipRoot) parents.pop(); // remove the root from the parents if skipping root
42
+
43
+ parents.forEach(callback);
44
+ };
45
+ const walkAllNodeChildren = function (node, callback) {
46
+ let isFirst = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
47
+ const {
48
+ children = []
49
+ } = node;
50
+ const shouldWalkChildren = children.length;
51
+ if (!isFirst) callback(node);
52
+
53
+ if (shouldWalkChildren) {
54
+ children.forEach(childNode => {
55
+ walkAllNodeChildren(childNode, callback, false);
56
+ });
57
+ }
58
+ };
59
+ const getNodeById = (treeRoot, id) => {
60
+ const nodes = treeRoot.all(node => node.model.id === id);
61
+ return nodes[0];
62
+ };
63
+ const cloneNode = (tree, node) => tree.parse(node.model);
64
+ const itemsShareSameParent = function () {
65
+ let items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
66
+ if (items.length === 0) throw new Error('Received empty items for comparison');
67
+ if (items.length === 1) return true; // when moving in first position we receive [undefined,...{items}]
68
+ // when moving in last position we receive [...{items}, undefined]
69
+
70
+ const firstExistingItem = items.find(item => !!item);
71
+ if (!firstExistingItem) throw new Error("Received no items, can't retrieve parent");
72
+ const firstExistingItemPath = firstExistingItem.node.getPath(); // path is like [rootParent, ...[parentsNodes], currentNode]
73
+ // length -1 is the current-node
74
+ // length -2 is the parent-node
75
+ // root node is not printed and is always present so minimum path length is 2 (root + currentNode)
76
+
77
+ const directParentNode = firstExistingItemPath[firstExistingItemPath.length - 2];
78
+ return items.every(item => {
79
+ // undefined nodes count as having the same parent
80
+ if (!item) return true;
81
+ const itemPath = item.node.getPath();
82
+ const itemDirectParent = itemPath[itemPath.length - 2];
83
+ return directParentNode === itemDirectParent;
84
+ });
85
+ };
86
+ const getItemsParentNode = function () {
87
+ let items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
88
+ let skipSameParentCheck = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
89
+ if (items.length === 0) throw new Error("Received empty items, can't retrieve parent"); // in case we already know the items compared shares the same parent
90
+
91
+ if (!skipSameParentCheck) if (!itemsShareSameParent(items)) // if we don't know (default, we don't) check if they share the parent
92
+ throw new Error("Received items don't share the same parent, can't retrieve parent"); // when moving in first position we receive [undefined,...{items}]
93
+ // when moving in last position we receive [...{items}, undefined]
94
+
95
+ const firstExistingItem = items.find(item => !!item);
96
+ if (!firstExistingItem) throw new Error("Received no items, can't retrieve parent");
97
+ const firstExistingItemPath = firstExistingItem.node.getPath(); // path is like [rootParent, ...[parentsNodes], currentNode]
98
+ // length -1 is the current-node
99
+ // length -2 is the parent-node
100
+ // root node is not printed and is always present so minimum path length is 2 (root + currentNode)
101
+
102
+ const directParentNode = firstExistingItemPath[firstExistingItemPath.length - 2];
103
+ return directParentNode;
104
+ };
105
+ const getNodeMatchesSearchQuery = function (node) {
106
+ let searchQuery = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
107
+ const standardizedName = standardizeSearchQueryString(node.model.name);
108
+ const standardizedSearchQuery = standardizeSearchQueryString(searchQuery);
109
+ return standardizedName.includes(standardizedSearchQuery);
110
+ };
111
+ const getChildrenMatchesSearchQuery = function (parentNode) {
112
+ let searchQuery = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
113
+ let anyChildMatch = false;
114
+ walkAllNodeChildren(parentNode, node => {
115
+ if (getNodeMatchesSearchQuery(node, searchQuery)) anyChildMatch = true;
116
+ });
117
+ return anyChildMatch;
118
+ };
119
+ /**
120
+ * Mutate in place a node from tree-model normalizing object properties like "isGroup" even if user didn't specify it explicitly,
121
+ * after execution the node will have "nodePath" "treeDepth" "nodeItemRef" "isGroup" "isExpanded"
122
+ * (optionally, based on the provided arguments) "matchesSearchQuery" "childrenMatchesSearchQuery" "isChecked"
123
+ *
124
+ * @param {Object} node - node (based on 'tree-model' lib) that you wish to mutate with extra props
125
+ * @param {string} [searchQuery=''] - optional string used to parse "matchesSearchQuery"/"childrenMatchesSearchQuery" properties
126
+ * @param {Object} [selection=null] - optional selection hashmap used to parse "isChecked" properties
127
+ * @param {Object} [expanded=null] - optional expanded hashmap used to parse "isExpanded" properties
128
+ */
129
+
130
+ const enrichNodeModelInPlace = function (node) {
131
+ var _node$model$children$, _node$model, _node$model$children;
132
+
133
+ let searchQuery = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
134
+ let selection = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
135
+ let expanded = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
136
+ const path = node.getPath();
137
+ const depth = path.length - 1;
138
+ node.model.nodePath = path;
139
+ node.model.treeDepth = depth;
140
+
141
+ if (!node.model.nodeItemRef) {
142
+ node.model.nodeItemRef = /*#__PURE__*/createRef();
143
+ } // if a node has children but was not marked as isGroup, force-mark as group
144
+ // this is useful to avoid having to always check both the flag and the children.length...
145
+
146
+
147
+ if (typeof node.model.isGroup !== 'boolean' && ((_node$model$children$ = (_node$model = node.model) === null || _node$model === void 0 ? void 0 : (_node$model$children = _node$model.children) === null || _node$model$children === void 0 ? void 0 : _node$model$children.length) !== null && _node$model$children$ !== void 0 ? _node$model$children$ : 0) > 0) {
148
+ node.model.isGroup = true;
149
+ }
150
+
151
+ if (node.model.isGroup && node.model.id !== '__ds_tree_root') {
152
+ if (expanded) node.model.isExpanded = !!expanded[node.model.id];else if (typeof node.model.isExpanded !== 'boolean') {
153
+ node.model.isExpanded = false;
154
+ }
155
+ }
156
+
157
+ node.model.matchesSearchQuery = true;
158
+ node.model.childrenMatchesSearchQuery = false;
159
+ const partiallyEnrichedNode = node;
160
+
161
+ if (searchQuery) {
162
+ partiallyEnrichedNode.model.matchesSearchQuery = getNodeMatchesSearchQuery(partiallyEnrichedNode, searchQuery);
163
+
164
+ if (partiallyEnrichedNode.model.isGroup === true) {
165
+ partiallyEnrichedNode.model.childrenMatchesSearchQuery = getChildrenMatchesSearchQuery(partiallyEnrichedNode, searchQuery);
166
+ if (partiallyEnrichedNode.model.childrenMatchesSearchQuery) partiallyEnrichedNode.model.isExpanded = true;
167
+ }
168
+ }
169
+
170
+ if (selection && selection[partiallyEnrichedNode.model.id]) {
171
+ partiallyEnrichedNode.model.isChecked = selection[partiallyEnrichedNode.model.id];
172
+ }
173
+ };
174
+ const focusItem = item => {
175
+ var _item$nodeItemRef, _item$nodeItemRef$cur;
176
+
177
+ item === null || item === void 0 ? void 0 : (_item$nodeItemRef = item.nodeItemRef) === null || _item$nodeItemRef === void 0 ? void 0 : (_item$nodeItemRef$cur = _item$nodeItemRef.current) === null || _item$nodeItemRef$cur === void 0 ? void 0 : _item$nodeItemRef$cur.focus();
178
+ };
179
+ const flattenTreeForDnD = function (data) {
180
+ let shouldDescend = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : () => true;
181
+ const flattenedTree = [];
182
+ let index = 0;
183
+
184
+ const doit = function (node) {
185
+ var _node$children$length, _node$children, _node$children2;
186
+
187
+ let depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
188
+ let parentId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
189
+ flattenedTree.push({
190
+ uid: node.id.toString(),
191
+ depth,
192
+ realIndex: index,
193
+ childrenCount: (_node$children$length = (_node$children = node.children) === null || _node$children === void 0 ? void 0 : _node$children.length) !== null && _node$children$length !== void 0 ? _node$children$length : 0,
194
+ parentId: parentId !== null ? parentId.toString() : null,
195
+ original: node
196
+ });
197
+ index += 1;
198
+ if (shouldDescend(node)) (_node$children2 = node.children) === null || _node$children2 === void 0 ? void 0 : _node$children2.forEach(child => doit(child, depth + 1, node.id.toString()));
199
+ };
200
+
201
+ data.forEach(datum => doit(datum));
202
+ return flattenedTree;
203
+ };
204
+
205
+ export { cloneNode, enrichNodeModelInPlace, flattenTreeForDnD, focusItem, getChildrenMatchesSearchQuery, getItemsParentNode, getNodeById, getNodeMatchesSearchQuery, itemsShareSameParent, walkAllNodeChildren, walkParents, walkVisibles };
@@ -1,10 +1,16 @@
1
- import * as React from "react";
2
- import { useEffect, useMemo, useState, useRef, useCallback } from "react";
3
- import { focusItem } from "./tree-helpers";
4
- import { toggleExpandAllHelper } from "./group-expands-helpers";
5
- const useInstanceRefActions = ({ actions }, ctx) => {
1
+ import 'core-js/modules/web.dom-collections.iterator.js';
2
+ import { useRef, useMemo, useState, useEffect, useCallback } from 'react';
3
+ import { focusItem } from './tree-helpers.js';
4
+ import { toggleExpandAllHelper } from './group-expands-helpers.js';
5
+
6
+ const useInstanceRefActions = (_ref, ctx) => {
7
+ let {
8
+ actions
9
+ } = _ref;
6
10
  const {
7
- props: { onItemFocus },
11
+ props: {
12
+ onItemFocus
13
+ },
8
14
  virtualListHelpers,
9
15
  treeRoot,
10
16
  visibleItems,
@@ -14,8 +20,12 @@ const useInstanceRefActions = ({ actions }, ctx) => {
14
20
  setFocusedItem,
15
21
  setLatestToggledItem
16
22
  } = ctx;
17
- const { current: promises } = useRef({});
18
- const { scrollToIndex } = useMemo(() => virtualListHelpers, [virtualListHelpers]);
23
+ const {
24
+ current: promises
25
+ } = useRef({});
26
+ const {
27
+ scrollToIndex
28
+ } = useMemo(() => virtualListHelpers, [virtualListHelpers]);
19
29
  const [expandPromise, setPromise] = useState();
20
30
  useEffect(() => {
21
31
  if (expandPromise && promises.expandResolve) {
@@ -24,30 +34,36 @@ const useInstanceRefActions = ({ actions }, ctx) => {
24
34
  setPromise(null);
25
35
  }
26
36
  }, [visibleItems, expandPromise, promises]);
27
- actions.toggleExpandAll = useCallback((isExpand) => {
28
- const p = new Promise((resolve) => {
37
+ actions.toggleExpandAll = useCallback(isExpand => {
38
+ const p = new Promise(resolve => {
29
39
  promises.expandResolve = resolve;
30
- if (treeRoot)
31
- toggleExpandAllHelper(isExpand, treeRoot, triggerTreeRerender, setLatestToggledItem, updateUserExpandedState);
40
+ if (treeRoot) toggleExpandAllHelper(isExpand, treeRoot, triggerTreeRerender, setLatestToggledItem, updateUserExpandedState);
32
41
  });
33
42
  setPromise(p);
34
43
  return p;
35
44
  }, [promises, treeRoot, triggerTreeRerender, setLatestToggledItem, updateUserExpandedState]);
36
- actions.scrollTo = useCallback((indx, opts = { align: "start" }) => {
37
- if (scrollToIndex)
38
- scrollToIndex(indx, opts);
45
+ actions.scrollTo = useCallback(function (indx) {
46
+ let opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
47
+ align: 'start'
48
+ };
49
+ if (scrollToIndex) scrollToIndex(indx, opts);
39
50
  }, [scrollToIndex]);
40
- actions.setSelectedItemByVirtualIndex = useCallback((index) => {
51
+ actions.setSelectedItemByVirtualIndex = useCallback(index => {
41
52
  const itemByIndex = visibleItems[index];
42
53
  setSelectedItem(itemByIndex);
43
54
  }, [visibleItems, setSelectedItem]);
44
- actions.setFocusedItemByVirtualIndex = useCallback((index, opts = { align: "start", withScroll: false }) => {
55
+ actions.setFocusedItemByVirtualIndex = useCallback(function (index) {
56
+ let opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
57
+ align: 'start',
58
+ withScroll: false
59
+ };
45
60
  const itemByIndex = visibleItems[index];
46
61
  const onItemFocusParams = {
47
62
  itemIndex: itemByIndex.virtualIndex,
48
63
  scrollToItem: () => scrollToIndex(index, opts),
49
64
  item: itemByIndex
50
65
  };
66
+
51
67
  if (opts.withScroll && scrollToIndex) {
52
68
  scrollToIndex(index, opts);
53
69
  setTimeout(() => {
@@ -63,7 +79,5 @@ const useInstanceRefActions = ({ actions }, ctx) => {
63
79
  }, [visibleItems, scrollToIndex, setFocusedItem, onItemFocus]);
64
80
  return actions;
65
81
  };
66
- export {
67
- useInstanceRefActions
68
- };
69
- //# sourceMappingURL=useInstanceRefActions.js.map
82
+
83
+ export { useInstanceRefActions };
@@ -0,0 +1,99 @@
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, flattenTreeForDnD } 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; }
17
+ 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
+
25
+ const tree = useMemo(() => new TreeModel(), []);
26
+ const [treeData, setTreeData] = useState({
27
+ id: '__ds_tree_root',
28
+ name: '__root',
29
+ isExpanded: true,
30
+ children: unfrozenData
31
+ });
32
+ useEffect(() => {
33
+ setTreeData({
34
+ id: '__ds_tree_root',
35
+ name: '__root',
36
+ isExpanded: true,
37
+ children: unfrozenData
38
+ });
39
+ }, [unfrozenData]); // expose a way to rerender the tree
40
+ // used for expand functionality
41
+
42
+ const [rerenderItems, setRerenderItems] = useState({});
43
+ const triggerTreeRerender = useCallback(() => {
44
+ setRerenderItems({});
45
+ }, []); // when re-rendering we re-parse the list
46
+
47
+ const [treeRoot, setTreeRoot] = useState(tree.parse(treeData));
48
+ useEffect(() => {
49
+ setTreeRoot(tree.parse(treeData));
50
+ }, [treeData, rerenderItems, tree]);
51
+ const [visibleItems, setVisibleItems] = useState([]);
52
+ const {
53
+ searchQuery,
54
+ highlightOnlyQuery,
55
+ onVisibleItemsChange,
56
+ selection,
57
+ expanded,
58
+ onExpandChange
59
+ } = props;
60
+ const updateUserExpandedState = useCallback(() => {
61
+ 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
+
67
+ useEffect(() => {
68
+ const parsedVisibleItems = [];
69
+ const newExpandedHashMap = {};
70
+ const shouldContinueWalking = true; // tree-model ask we return true if we want to continue walking
71
+
72
+ treeRoot.walk(node => {
73
+ enrichNodeModelInPlace(node, searchQuery, selection, expanded);
74
+ if (node.model.id && node.model.isGroup && node.model.isExpanded) newExpandedHashMap[node.model.id] = true;
75
+ return shouldContinueWalking;
76
+ });
77
+ walkVisibles(treeRoot, node => {
78
+ parsedVisibleItems.push(_objectSpread(_objectSpread({}, node.model), {}, {
79
+ node
80
+ }));
81
+ }, true, highlightOnlyQuery);
82
+ setVisibleItems(parsedVisibleItems);
83
+ 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?
86
+ ]);
87
+ const flattenedItems = useMemo(() => flattenTreeForDnD(data), [data]);
88
+ return {
89
+ visibleItems,
90
+ flattenedItems,
91
+ tree,
92
+ treeRoot,
93
+ rerenderItems,
94
+ triggerTreeRerender,
95
+ updateUserExpandedState
96
+ };
97
+ };
98
+
99
+ export { useTree };