@elliemae/ds-treeview 2.3.0-alpha.6 → 2.3.0-next.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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/types/TreeView.d.ts +13 -0
  99. package/types/TreeViewContext.d.ts +17 -0
  100. package/types/config/cssClassesConstants.d.ts +4 -0
  101. package/types/config/useTreeview.d.ts +7 -0
  102. package/types/hoc/DnDTreeContext.d.ts +14 -0
  103. package/types/hoc/SortableItemContext.d.ts +19 -0
  104. package/types/hoc/WithConditionalDnDContext.d.ts +4 -0
  105. package/types/hoc/WithDnDSortableItemContext.d.ts +4 -0
  106. package/types/index.d.ts +3 -0
  107. package/types/parts/CheckboxSelectable.d.ts +8 -0
  108. package/types/parts/ChildrenCountDisplayer.d.ts +7 -0
  109. package/types/parts/DnDHandle.d.ts +6 -0
  110. package/types/parts/DropIndicator.d.ts +10 -0
  111. package/types/parts/ExpandCaret.d.ts +7 -0
  112. package/types/parts/Icon.d.ts +7 -0
  113. package/types/parts/NestingSpace.d.ts +8 -0
  114. package/types/parts/RadioSelectable.d.ts +8 -0
  115. package/types/parts/TreeItem.d.ts +17 -0
  116. package/types/parts/TreeItemText.d.ts +7 -0
  117. package/types/parts/TreeList.d.ts +20 -0
  118. package/types/plugins/dnd/TreeDndPlugin.d.ts +1 -0
  119. package/types/plugins/dnd/index.d.ts +1 -0
  120. package/types/plugins/index.d.ts +7 -0
  121. package/types/plugins/roving/TreeRovingPlugin.d.ts +1 -0
  122. package/types/plugins/roving/index.d.ts +1 -0
  123. package/types/plugins/searchable/SearchableTreePlugin.d.ts +1 -0
  124. package/types/plugins/searchable/index.d.ts +1 -0
  125. package/types/plugins/selectable/SelectablePluginTree.d.ts +1 -0
  126. package/types/plugins/selectable/index.d.ts +1 -0
  127. package/types/plugins/toolbar/TreeToolbarPlugin.d.ts +1 -0
  128. package/types/plugins/toolbar/index.d.ts +1 -0
  129. package/types/plugins/tree/TreeDataPlugin.d.ts +1 -0
  130. package/types/plugins/tree/index.d.ts +1 -0
  131. package/types/plugins/virtualization/TreeVirtualizationPlugin.d.ts +1 -0
  132. package/types/plugins/virtualization/index.d.ts +1 -0
  133. package/types/react-desc-prop-types.d.ts +210 -0
  134. package/types/related-components/TreeViewSearchBar.d.ts +16 -0
  135. package/types/sharedTypes.d.ts +47 -0
  136. package/types/utils/array-helpers.d.ts +2 -0
  137. package/types/utils/group-expands-helpers.d.ts +14 -0
  138. package/types/utils/keyboard-helpers.d.ts +6 -0
  139. package/types/utils/object-helpers.d.ts +6 -0
  140. package/types/utils/refs-helpers.d.ts +4 -0
  141. package/types/utils/selectable-helper.d.ts +7 -0
  142. package/types/utils/string-helpers.d.ts +1 -0
  143. package/types/utils/tree-helpers.d.ts +28 -0
  144. package/types/utils/useInstanceRefActions.d.ts +3 -0
  145. package/types/utils/useTree.d.ts +14 -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,175 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ var React = require('react');
6
+ var TreeViewContext = require('../TreeViewContext.js');
7
+ var treeHelpers = require('./tree-helpers.js');
8
+ var groupExpandsHelpers = require('./group-expands-helpers.js');
9
+
10
+ /* eslint-disable max-params */
11
+ // 9 tab
12
+ // 13 enter
13
+ // 32 space
14
+ // 37 left arrow
15
+ // 38 up arrow
16
+ // 39 right arrow
17
+ // 40 down arrow
18
+ // 35 end
19
+ // 36 home
20
+ // 56 number 8
21
+ // 106 (NumPad) *
22
+ const useOnItemKeyDown = (item, draggableProps) => {
23
+ const ctx = React.useContext(TreeViewContext["default"]);
24
+ const {
25
+ props: {
26
+ onItemFocus
27
+ },
28
+ triggerTreeRerender,
29
+ visibleItems,
30
+ setFocusedItem,
31
+ setSelectedItem,
32
+ setLatestToggledItem,
33
+ updateUserExpandedState,
34
+ virtualListHelpers: {
35
+ scrollToIndex
36
+ }
37
+ } = ctx;
38
+ const {
39
+ isGroup,
40
+ isExpanded
41
+ } = item;
42
+ const onItemFocusCurry = React.useCallback(newFocusItem => onItemFocus({
43
+ itemIndex: newFocusItem.virtualIndex,
44
+ scrollToItem: function () {
45
+ let opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {
46
+ align: 'start'
47
+ };
48
+ return scrollToIndex(newFocusItem.virtualIndex, opts);
49
+ },
50
+ item: newFocusItem
51
+ }), [onItemFocus, scrollToIndex]);
52
+ const onItemKeyDown = React.useCallback(e => {
53
+ const {
54
+ keyCode
55
+ } = e;
56
+
57
+ if (!(draggableProps && draggableProps.active)) {
58
+ if (keyCode !== 9) e.preventDefault(); // allow tab/shift+tab
59
+
60
+ if ((keyCode === 13 || keyCode === 32) && e.target.tagName === 'LI') {
61
+ setSelectedItem(item);
62
+ }
63
+
64
+ if (keyCode === 37) {
65
+ if (isGroup && isExpanded) {
66
+ groupExpandsHelpers.toggleItemExpand(item, triggerTreeRerender, updateUserExpandedState, scrollToIndex);
67
+ setLatestToggledItem(item);
68
+ }
69
+ }
70
+
71
+ if (keyCode === 39) {
72
+ if (isGroup && !isExpanded) {
73
+ groupExpandsHelpers.toggleItemExpand(item, triggerTreeRerender, updateUserExpandedState, scrollToIndex);
74
+ setLatestToggledItem(item);
75
+ }
76
+ }
77
+
78
+ const {
79
+ virtualIndex
80
+ } = item;
81
+
82
+ if (typeof virtualIndex === 'number') {
83
+ const lastItemIndex = visibleItems.length - 1;
84
+
85
+ if (keyCode === 38) {
86
+ const isLoopedFocus = virtualIndex === 0;
87
+ const newFocusIndex = isLoopedFocus ? lastItemIndex : virtualIndex - 1;
88
+ const newFocusItem = visibleItems[newFocusIndex];
89
+ scrollToIndex(newFocusIndex);
90
+
91
+ if (isLoopedFocus) {
92
+ // when looping the list from start to end we need to wait a bit before focusing
93
+ setTimeout(() => {
94
+ setFocusedItem(newFocusItem);
95
+ treeHelpers.focusItem(newFocusItem);
96
+ onItemFocusCurry(newFocusItem);
97
+ }, 300);
98
+ } else {
99
+ setFocusedItem(newFocusItem);
100
+ onItemFocusCurry(newFocusItem);
101
+ treeHelpers.focusItem(newFocusItem);
102
+ }
103
+ }
104
+
105
+ if (keyCode === 40) {
106
+ const isLoopedFocus = virtualIndex === lastItemIndex;
107
+ const newFocusIndex = isLoopedFocus ? 0 : virtualIndex + 1;
108
+ const newFocusItem = visibleItems[newFocusIndex];
109
+ scrollToIndex(newFocusIndex);
110
+
111
+ if (isLoopedFocus) {
112
+ // when looping the list from start to end we need to wait a bit before focusing
113
+ setTimeout(() => {
114
+ setFocusedItem(newFocusItem);
115
+ onItemFocusCurry(newFocusItem);
116
+ treeHelpers.focusItem(newFocusItem);
117
+ }, 300);
118
+ } else {
119
+ setFocusedItem(newFocusItem);
120
+ onItemFocusCurry(newFocusItem);
121
+ treeHelpers.focusItem(newFocusItem);
122
+ }
123
+ }
124
+
125
+ if (keyCode === 35) {
126
+ if (virtualIndex !== lastItemIndex) {
127
+ const newFocusItem = visibleItems[lastItemIndex];
128
+ scrollToIndex(lastItemIndex);
129
+ setTimeout(() => {
130
+ setFocusedItem(newFocusItem);
131
+ onItemFocusCurry(newFocusItem);
132
+ treeHelpers.focusItem(newFocusItem);
133
+ }, 300);
134
+ }
135
+ }
136
+
137
+ if (keyCode === 36) {
138
+ if (virtualIndex !== 0) {
139
+ const newFocusItem = visibleItems[0];
140
+ scrollToIndex(0);
141
+ setTimeout(() => {
142
+ setFocusedItem(newFocusItem);
143
+ onItemFocusCurry(newFocusItem);
144
+ treeHelpers.focusItem(newFocusItem);
145
+ }, 300);
146
+ }
147
+ }
148
+ }
149
+ }
150
+ }, [draggableProps, setSelectedItem, item, isGroup, isExpanded, triggerTreeRerender, updateUserExpandedState, scrollToIndex, setLatestToggledItem, visibleItems, setFocusedItem, onItemFocusCurry]);
151
+ return onItemKeyDown;
152
+ };
153
+ const useGlobalKeyboardListener = func => {
154
+ React.useEffect(() => {
155
+ document.addEventListener('keydown', func);
156
+ return () => document.removeEventListener('keydown', func);
157
+ }, [func]);
158
+ };
159
+ const useGlobalToggleAllExpandShortcut = (treeRoot, triggerTreeRerender, setLatestToggledItem, updateUserExpandedState) => {
160
+ const memoizedToggleAllKeyboardShortcut = React.useCallback(e => {
161
+ const {
162
+ shiftKey,
163
+ keyCode
164
+ } = e;
165
+
166
+ if (shiftKey && keyCode === 56) {
167
+ groupExpandsHelpers.toggleExpandAllHelper('toggle', treeRoot, triggerTreeRerender, setLatestToggledItem, updateUserExpandedState);
168
+ }
169
+ }, [setLatestToggledItem, treeRoot, triggerTreeRerender, updateUserExpandedState]);
170
+ return useGlobalKeyboardListener(memoizedToggleAllKeyboardShortcut);
171
+ };
172
+
173
+ exports.useGlobalKeyboardListener = useGlobalKeyboardListener;
174
+ exports.useGlobalToggleAllExpandShortcut = useGlobalToggleAllExpandShortcut;
175
+ exports.useOnItemKeyDown = useOnItemKeyDown;
@@ -0,0 +1,69 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ require('core-js/modules/esnext.async-iterator.for-each.js');
6
+ require('core-js/modules/esnext.iterator.constructor.js');
7
+ require('core-js/modules/esnext.iterator.for-each.js');
8
+ require('core-js/modules/esnext.async-iterator.reduce.js');
9
+ require('core-js/modules/esnext.iterator.reduce.js');
10
+
11
+ /* eslint-disable no-sequences */
12
+
13
+ /* eslint-disable no-return-assign */
14
+
15
+ /* eslint-disable no-restricted-syntax */
16
+
17
+ /* eslint-disable guard-for-in */
18
+ function isObjectADate(o) {
19
+ var _o$constructor;
20
+
21
+ return (o === null || o === void 0 ? void 0 : (_o$constructor = o.constructor) === null || _o$constructor === void 0 ? void 0 : _o$constructor.name) === 'Date';
22
+ }
23
+
24
+ function isObjectAnArray(o) {
25
+ return Array.isArray(o);
26
+ }
27
+
28
+ function isObjectAString(o) {
29
+ return typeof o === 'object';
30
+ }
31
+
32
+ const unfreeze = o => {
33
+ let oo;
34
+
35
+ if (o === null) {
36
+ oo = null;
37
+ } else if (o === undefined) {
38
+ oo = undefined;
39
+ } else if (isObjectADate(o)) {
40
+ oo = new Date(o);
41
+ } else if (isObjectAnArray(o)) {
42
+ oo = [];
43
+ o.forEach(v => {
44
+ oo.push(v);
45
+ });
46
+ } else if (isObjectAString(o)) {
47
+ oo = String(o);
48
+ } else if (isObjectAString(o)) {
49
+ oo = {};
50
+
51
+ for (const property in o) {
52
+ oo[property] = o[property];
53
+ }
54
+ } else {
55
+ oo = o;
56
+ }
57
+
58
+ return oo;
59
+ };
60
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
61
+ function filterObject(obj, predicate) {
62
+ return Object.keys(obj).reduce((res, key) => {
63
+ if (predicate(obj[key])) res[key] = obj[key];
64
+ return res;
65
+ }, {});
66
+ }
67
+
68
+ exports.filterObject = filterObject;
69
+ exports.unfreeze = unfreeze;
@@ -0,0 +1,31 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ require('core-js/modules/esnext.async-iterator.filter.js');
6
+ require('core-js/modules/esnext.iterator.constructor.js');
7
+ require('core-js/modules/esnext.iterator.filter.js');
8
+ require('core-js/modules/esnext.async-iterator.for-each.js');
9
+ require('core-js/modules/esnext.iterator.for-each.js');
10
+
11
+ // allow multiple refs to be set to point to the same DOM element
12
+ const setMultipleRefs = function () {
13
+ for (var _len = arguments.length, refs = new Array(_len), _key = 0; _key < _len; _key++) {
14
+ refs[_key] = arguments[_key];
15
+ }
16
+
17
+ const filteredRefs = refs.filter(Boolean);
18
+ if (!filteredRefs.length) return () => {};
19
+ if (filteredRefs.length === 0) return () => {};
20
+ return newRef => {
21
+ filteredRefs.forEach(refToBeUpdated => {
22
+ if (typeof refToBeUpdated === 'function') {
23
+ refToBeUpdated(newRef);
24
+ } else if (refToBeUpdated) {
25
+ refToBeUpdated.current = newRef;
26
+ }
27
+ });
28
+ };
29
+ };
30
+
31
+ exports.setMultipleRefs = setMultipleRefs;
@@ -0,0 +1,80 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ require('core-js/modules/esnext.async-iterator.filter.js');
6
+ require('core-js/modules/esnext.iterator.constructor.js');
7
+ require('core-js/modules/esnext.iterator.filter.js');
8
+ require('core-js/modules/esnext.async-iterator.for-each.js');
9
+ require('core-js/modules/esnext.iterator.for-each.js');
10
+ var _defineProperty = require('@babel/runtime/helpers/defineProperty');
11
+ var treeHelpers = require('./tree-helpers.js');
12
+
13
+ function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
14
+
15
+ var _defineProperty__default = /*#__PURE__*/_interopDefaultLegacy(_defineProperty);
16
+
17
+ 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; }
18
+
19
+ 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__default["default"](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; }
20
+ const getGroupCheckState = node => {
21
+ let childAllChecked = true;
22
+ let anyChildChecked = false;
23
+ treeHelpers.walkAllNodeChildren(node, childNode => {
24
+ const {
25
+ model: {
26
+ isChecked
27
+ }
28
+ } = childNode;
29
+ if (isChecked === 'mixed' || isChecked === true) anyChildChecked = true;else childAllChecked = false;
30
+ });
31
+ if (childAllChecked) return true;
32
+ if (anyChildChecked) return 'mixed';
33
+ return false;
34
+ };
35
+ const selectCheckboxItemModelParentsTillRoot = function (modelToCheck) {
36
+ let triggerTreeRerender = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
37
+ const newSelections = {};
38
+ const {
39
+ nodePath
40
+ } = modelToCheck;
41
+ treeHelpers.walkParents(nodePath, parentNode => {
42
+ const nextState = getGroupCheckState(parentNode);
43
+ parentNode.model.isChecked = nextState;
44
+ newSelections[parentNode.model.id] = nextState;
45
+ });
46
+ if (triggerTreeRerender) triggerTreeRerender();
47
+ return newSelections;
48
+ };
49
+ const toggleCheckboxItem = function (itemToSelect) {
50
+ let triggerTreeRerender = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : null;
51
+ const {
52
+ node: {
53
+ model: {
54
+ id,
55
+ isChecked,
56
+ children = []
57
+ }
58
+ }
59
+ } = itemToSelect;
60
+ const newSelections = {}; // 'mixed' -> true -> false -> true [...->false -> true]
61
+
62
+ const nextState = isChecked === 'mixed' ? true : !isChecked;
63
+ itemToSelect.node.model.isChecked = nextState;
64
+ newSelections[id] = nextState;
65
+
66
+ if (children.length > 0 && (nextState === true || nextState === false)) {
67
+ treeHelpers.walkAllNodeChildren(itemToSelect.node, childNode => {
68
+ childNode.model.isChecked = nextState;
69
+ newSelections[childNode.model.id] = nextState;
70
+ });
71
+ }
72
+
73
+ const parentsNewSelections = selectCheckboxItemModelParentsTillRoot(itemToSelect);
74
+ if (triggerTreeRerender) triggerTreeRerender();
75
+ return _objectSpread(_objectSpread({}, parentsNewSelections), newSelections);
76
+ };
77
+
78
+ exports.getGroupCheckState = getGroupCheckState;
79
+ exports.selectCheckboxItemModelParentsTillRoot = selectCheckboxItemModelParentsTillRoot;
80
+ exports.toggleCheckboxItem = toggleCheckboxItem;
@@ -0,0 +1,7 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ const standardizeSearchQueryString = input => input.trim().toLowerCase();
6
+
7
+ exports.standardizeSearchQueryString = standardizeSearchQueryString;
@@ -0,0 +1,220 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ require('core-js/modules/esnext.async-iterator.for-each.js');
6
+ require('core-js/modules/esnext.iterator.constructor.js');
7
+ require('core-js/modules/esnext.iterator.for-each.js');
8
+ require('core-js/modules/web.dom-collections.iterator.js');
9
+ require('core-js/modules/esnext.async-iterator.find.js');
10
+ require('core-js/modules/esnext.iterator.find.js');
11
+ require('core-js/modules/esnext.async-iterator.every.js');
12
+ require('core-js/modules/esnext.iterator.every.js');
13
+ var React = require('react');
14
+ var stringHelpers = require('./string-helpers.js');
15
+
16
+ const walkVisibles = function (node, callback) {
17
+ let skipRoot = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
18
+ let highlightOnlyQuery = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false;
19
+ const {
20
+ children,
21
+ model
22
+ } = node;
23
+ const {
24
+ name,
25
+ isExpanded,
26
+ childrenMatchesSearchQuery,
27
+ matchesSearchQuery
28
+ } = model;
29
+ const shouldSkipBecauseIsRoot = skipRoot && name === '__root';
30
+ const queryRestrictionsPassed = !!(highlightOnlyQuery || childrenMatchesSearchQuery || matchesSearchQuery);
31
+ if (!shouldSkipBecauseIsRoot && queryRestrictionsPassed) callback(node);
32
+ const shouldWalkChildren = !!(children.length > 0 && isExpanded && queryRestrictionsPassed);
33
+
34
+ if (shouldWalkChildren) {
35
+ children.forEach(childNode => {
36
+ walkVisibles(childNode, callback, skipRoot, highlightOnlyQuery);
37
+ });
38
+ }
39
+ };
40
+ const walkParents = function (nodePath, callback) {
41
+ let skipRoot = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
42
+ const parents = [...nodePath].reverse();
43
+ parents.shift(); // remove current node from the parents array
44
+
45
+ if (skipRoot) parents.pop(); // remove the root from the parents if skipping root
46
+
47
+ parents.forEach(callback);
48
+ };
49
+ const walkAllNodeChildren = function (node, callback) {
50
+ let isFirst = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : true;
51
+ const {
52
+ children = []
53
+ } = node;
54
+ const shouldWalkChildren = children.length;
55
+ if (!isFirst) callback(node);
56
+
57
+ if (shouldWalkChildren) {
58
+ children.forEach(childNode => {
59
+ walkAllNodeChildren(childNode, callback, false);
60
+ });
61
+ }
62
+ };
63
+ const getNodeById = (treeRoot, id) => {
64
+ const nodes = treeRoot.all(node => node.model.id === id);
65
+ return nodes[0];
66
+ };
67
+ const cloneNode = (tree, node) => tree.parse(node.model);
68
+ const itemsShareSameParent = function () {
69
+ let items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
70
+ if (items.length === 0) throw new Error('Received empty items for comparison');
71
+ if (items.length === 1) return true; // when moving in first position we receive [undefined,...{items}]
72
+ // when moving in last position we receive [...{items}, undefined]
73
+
74
+ const firstExistingItem = items.find(item => !!item);
75
+ if (!firstExistingItem) throw new Error("Received no items, can't retrieve parent");
76
+ const firstExistingItemPath = firstExistingItem.node.getPath(); // path is like [rootParent, ...[parentsNodes], currentNode]
77
+ // length -1 is the current-node
78
+ // length -2 is the parent-node
79
+ // root node is not printed and is always present so minimum path length is 2 (root + currentNode)
80
+
81
+ const directParentNode = firstExistingItemPath[firstExistingItemPath.length - 2];
82
+ return items.every(item => {
83
+ // undefined nodes count as having the same parent
84
+ if (!item) return true;
85
+ const itemPath = item.node.getPath();
86
+ const itemDirectParent = itemPath[itemPath.length - 2];
87
+ return directParentNode === itemDirectParent;
88
+ });
89
+ };
90
+ const getItemsParentNode = function () {
91
+ let items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
92
+ let skipSameParentCheck = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false;
93
+ 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
94
+
95
+ if (!skipSameParentCheck) if (!itemsShareSameParent(items)) // if we don't know (default, we don't) check if they share the parent
96
+ throw new Error("Received items don't share the same parent, can't retrieve parent"); // when moving in first position we receive [undefined,...{items}]
97
+ // when moving in last position we receive [...{items}, undefined]
98
+
99
+ const firstExistingItem = items.find(item => !!item);
100
+ if (!firstExistingItem) throw new Error("Received no items, can't retrieve parent");
101
+ const firstExistingItemPath = firstExistingItem.node.getPath(); // path is like [rootParent, ...[parentsNodes], currentNode]
102
+ // length -1 is the current-node
103
+ // length -2 is the parent-node
104
+ // root node is not printed and is always present so minimum path length is 2 (root + currentNode)
105
+
106
+ const directParentNode = firstExistingItemPath[firstExistingItemPath.length - 2];
107
+ return directParentNode;
108
+ };
109
+ const getNodeMatchesSearchQuery = function (node) {
110
+ let searchQuery = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
111
+ const standardizedName = stringHelpers.standardizeSearchQueryString(node.model.name);
112
+ const standardizedSearchQuery = stringHelpers.standardizeSearchQueryString(searchQuery);
113
+ return standardizedName.includes(standardizedSearchQuery);
114
+ };
115
+ const getChildrenMatchesSearchQuery = function (parentNode) {
116
+ let searchQuery = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
117
+ let anyChildMatch = false;
118
+ walkAllNodeChildren(parentNode, node => {
119
+ if (getNodeMatchesSearchQuery(node, searchQuery)) anyChildMatch = true;
120
+ });
121
+ return anyChildMatch;
122
+ };
123
+ /**
124
+ * Mutate in place a node from tree-model normalizing object properties like "isGroup" even if user didn't specify it explicitly,
125
+ * after execution the node will have "nodePath" "treeDepth" "nodeItemRef" "isGroup" "isExpanded"
126
+ * (optionally, based on the provided arguments) "matchesSearchQuery" "childrenMatchesSearchQuery" "isChecked"
127
+ *
128
+ * @param {Object} node - node (based on 'tree-model' lib) that you wish to mutate with extra props
129
+ * @param {string} [searchQuery=''] - optional string used to parse "matchesSearchQuery"/"childrenMatchesSearchQuery" properties
130
+ * @param {Object} [selection=null] - optional selection hashmap used to parse "isChecked" properties
131
+ * @param {Object} [expanded=null] - optional expanded hashmap used to parse "isExpanded" properties
132
+ */
133
+
134
+ const enrichNodeModelInPlace = function (node) {
135
+ var _node$model$children$, _node$model, _node$model$children;
136
+
137
+ let searchQuery = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
138
+ let selection = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
139
+ let expanded = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : null;
140
+ const path = node.getPath();
141
+ const depth = path.length - 1;
142
+ node.model.nodePath = path;
143
+ node.model.treeDepth = depth;
144
+
145
+ if (!node.model.nodeItemRef) {
146
+ node.model.nodeItemRef = /*#__PURE__*/React.createRef();
147
+ } // if a node has children but was not marked as isGroup, force-mark as group
148
+ // this is useful to avoid having to always check both the flag and the children.length...
149
+
150
+
151
+ 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) {
152
+ node.model.isGroup = true;
153
+ }
154
+
155
+ if (node.model.isGroup && node.model.id !== '__ds_tree_root') {
156
+ if (expanded) node.model.isExpanded = !!expanded[node.model.id];else if (typeof node.model.isExpanded !== 'boolean') {
157
+ node.model.isExpanded = false;
158
+ }
159
+ }
160
+
161
+ node.model.matchesSearchQuery = true;
162
+ node.model.childrenMatchesSearchQuery = false;
163
+ const partiallyEnrichedNode = node;
164
+
165
+ if (searchQuery) {
166
+ partiallyEnrichedNode.model.matchesSearchQuery = getNodeMatchesSearchQuery(partiallyEnrichedNode, searchQuery);
167
+
168
+ if (partiallyEnrichedNode.model.isGroup === true) {
169
+ partiallyEnrichedNode.model.childrenMatchesSearchQuery = getChildrenMatchesSearchQuery(partiallyEnrichedNode, searchQuery);
170
+ if (partiallyEnrichedNode.model.childrenMatchesSearchQuery) partiallyEnrichedNode.model.isExpanded = true;
171
+ }
172
+ }
173
+
174
+ if (selection && selection[partiallyEnrichedNode.model.id]) {
175
+ partiallyEnrichedNode.model.isChecked = selection[partiallyEnrichedNode.model.id];
176
+ }
177
+ };
178
+ const focusItem = item => {
179
+ var _item$nodeItemRef, _item$nodeItemRef$cur;
180
+
181
+ 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();
182
+ };
183
+ const flattenTreeForDnD = function (data) {
184
+ let shouldDescend = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : () => true;
185
+ const flattenedTree = [];
186
+ let index = 0;
187
+
188
+ const doit = function (node) {
189
+ var _node$children$length, _node$children, _node$children2;
190
+
191
+ let depth = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0;
192
+ let parentId = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : null;
193
+ flattenedTree.push({
194
+ uid: node.id.toString(),
195
+ depth,
196
+ realIndex: index,
197
+ 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,
198
+ parentId: parentId !== null ? parentId.toString() : null,
199
+ original: node
200
+ });
201
+ index += 1;
202
+ 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()));
203
+ };
204
+
205
+ data.forEach(datum => doit(datum));
206
+ return flattenedTree;
207
+ };
208
+
209
+ exports.cloneNode = cloneNode;
210
+ exports.enrichNodeModelInPlace = enrichNodeModelInPlace;
211
+ exports.flattenTreeForDnD = flattenTreeForDnD;
212
+ exports.focusItem = focusItem;
213
+ exports.getChildrenMatchesSearchQuery = getChildrenMatchesSearchQuery;
214
+ exports.getItemsParentNode = getItemsParentNode;
215
+ exports.getNodeById = getNodeById;
216
+ exports.getNodeMatchesSearchQuery = getNodeMatchesSearchQuery;
217
+ exports.itemsShareSameParent = itemsShareSameParent;
218
+ exports.walkAllNodeChildren = walkAllNodeChildren;
219
+ exports.walkParents = walkParents;
220
+ exports.walkVisibles = walkVisibles;
@@ -0,0 +1,87 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperty(exports, '__esModule', { value: true });
4
+
5
+ require('core-js/modules/web.dom-collections.iterator.js');
6
+ var React = require('react');
7
+ var treeHelpers = require('./tree-helpers.js');
8
+ var groupExpandsHelpers = require('./group-expands-helpers.js');
9
+
10
+ const useInstanceRefActions = (_ref, ctx) => {
11
+ let {
12
+ actions
13
+ } = _ref;
14
+ const {
15
+ props: {
16
+ onItemFocus
17
+ },
18
+ virtualListHelpers,
19
+ treeRoot,
20
+ visibleItems,
21
+ triggerTreeRerender,
22
+ updateUserExpandedState,
23
+ setSelectedItem,
24
+ setFocusedItem,
25
+ setLatestToggledItem
26
+ } = ctx;
27
+ const {
28
+ current: promises
29
+ } = React.useRef({});
30
+ const {
31
+ scrollToIndex
32
+ } = React.useMemo(() => virtualListHelpers, [virtualListHelpers]);
33
+ const [expandPromise, setPromise] = React.useState();
34
+ React.useEffect(() => {
35
+ if (expandPromise && promises.expandResolve) {
36
+ promises.expandResolve(visibleItems);
37
+ promises.expandResolve = null;
38
+ setPromise(null);
39
+ }
40
+ }, [visibleItems, expandPromise, promises]);
41
+ actions.toggleExpandAll = React.useCallback(isExpand => {
42
+ const p = new Promise(resolve => {
43
+ promises.expandResolve = resolve;
44
+ if (treeRoot) groupExpandsHelpers.toggleExpandAllHelper(isExpand, treeRoot, triggerTreeRerender, setLatestToggledItem, updateUserExpandedState);
45
+ });
46
+ setPromise(p);
47
+ return p;
48
+ }, [promises, treeRoot, triggerTreeRerender, setLatestToggledItem, updateUserExpandedState]);
49
+ actions.scrollTo = React.useCallback(function (indx) {
50
+ let opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
51
+ align: 'start'
52
+ };
53
+ if (scrollToIndex) scrollToIndex(indx, opts);
54
+ }, [scrollToIndex]);
55
+ actions.setSelectedItemByVirtualIndex = React.useCallback(index => {
56
+ const itemByIndex = visibleItems[index];
57
+ setSelectedItem(itemByIndex);
58
+ }, [visibleItems, setSelectedItem]);
59
+ actions.setFocusedItemByVirtualIndex = React.useCallback(function (index) {
60
+ let opts = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {
61
+ align: 'start',
62
+ withScroll: false
63
+ };
64
+ const itemByIndex = visibleItems[index];
65
+ const onItemFocusParams = {
66
+ itemIndex: itemByIndex.virtualIndex,
67
+ scrollToItem: () => scrollToIndex(index, opts),
68
+ item: itemByIndex
69
+ };
70
+
71
+ if (opts.withScroll && scrollToIndex) {
72
+ scrollToIndex(index, opts);
73
+ setTimeout(() => {
74
+ setFocusedItem(itemByIndex);
75
+ treeHelpers.focusItem(itemByIndex);
76
+ onItemFocus(onItemFocusParams);
77
+ }, 300);
78
+ } else {
79
+ setFocusedItem(itemByIndex);
80
+ treeHelpers.focusItem(itemByIndex);
81
+ onItemFocus(onItemFocusParams);
82
+ }
83
+ }, [visibleItems, scrollToIndex, setFocusedItem, onItemFocus]);
84
+ return actions;
85
+ };
86
+
87
+ exports.useInstanceRefActions = useInstanceRefActions;