@fluentui/react-table 0.0.0-nightly-20221007-1237.1

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 (319) hide show
  1. package/CHANGELOG.json +354 -0
  2. package/CHANGELOG.md +104 -0
  3. package/LICENSE +15 -0
  4. package/README.md +5 -0
  5. package/Spec.md +63 -0
  6. package/dist/index.d.ts +647 -0
  7. package/lib/Table.js +2 -0
  8. package/lib/Table.js.map +1 -0
  9. package/lib/TableBody.js +2 -0
  10. package/lib/TableBody.js.map +1 -0
  11. package/lib/TableCell.js +2 -0
  12. package/lib/TableCell.js.map +1 -0
  13. package/lib/TableCellActions.js +2 -0
  14. package/lib/TableCellActions.js.map +1 -0
  15. package/lib/TableCellLayout.js +2 -0
  16. package/lib/TableCellLayout.js.map +1 -0
  17. package/lib/TableCellPrimaryLayout.js +2 -0
  18. package/lib/TableCellPrimaryLayout.js.map +1 -0
  19. package/lib/TableHeader.js +2 -0
  20. package/lib/TableHeader.js.map +1 -0
  21. package/lib/TableHeaderCell.js +2 -0
  22. package/lib/TableHeaderCell.js.map +1 -0
  23. package/lib/TableRow.js +2 -0
  24. package/lib/TableRow.js.map +1 -0
  25. package/lib/TableSelectionCell.js +2 -0
  26. package/lib/TableSelectionCell.js.map +1 -0
  27. package/lib/components/Table/Table.js +16 -0
  28. package/lib/components/Table/Table.js.map +1 -0
  29. package/lib/components/Table/Table.types.js +2 -0
  30. package/lib/components/Table/Table.types.js.map +1 -0
  31. package/lib/components/Table/index.js +6 -0
  32. package/lib/components/Table/index.js.map +1 -0
  33. package/lib/components/Table/renderTable.js +18 -0
  34. package/lib/components/Table/renderTable.js.map +1 -0
  35. package/lib/components/Table/useTable.js +30 -0
  36. package/lib/components/Table/useTable.js.map +1 -0
  37. package/lib/components/Table/useTableContextValues.js +17 -0
  38. package/lib/components/Table/useTableContextValues.js.map +1 -0
  39. package/lib/components/Table/useTableStyles.js +53 -0
  40. package/lib/components/Table/useTableStyles.js.map +1 -0
  41. package/lib/components/TableBody/TableBody.js +15 -0
  42. package/lib/components/TableBody/TableBody.js.map +1 -0
  43. package/lib/components/TableBody/TableBody.types.js +2 -0
  44. package/lib/components/TableBody/TableBody.types.js.map +1 -0
  45. package/lib/components/TableBody/index.js +6 -0
  46. package/lib/components/TableBody/index.js.map +1 -0
  47. package/lib/components/TableBody/renderTableBody.js +16 -0
  48. package/lib/components/TableBody/renderTableBody.js.map +1 -0
  49. package/lib/components/TableBody/useTableBody.js +32 -0
  50. package/lib/components/TableBody/useTableBody.js.map +1 -0
  51. package/lib/components/TableBody/useTableBodyStyles.js +35 -0
  52. package/lib/components/TableBody/useTableBodyStyles.js.map +1 -0
  53. package/lib/components/TableCell/TableCell.js +15 -0
  54. package/lib/components/TableCell/TableCell.js.map +1 -0
  55. package/lib/components/TableCell/TableCell.types.js +2 -0
  56. package/lib/components/TableCell/TableCell.types.js.map +1 -0
  57. package/lib/components/TableCell/index.js +6 -0
  58. package/lib/components/TableCell/index.js.map +1 -0
  59. package/lib/components/TableCell/renderTableCell.js +15 -0
  60. package/lib/components/TableCell/renderTableCell.js.map +1 -0
  61. package/lib/components/TableCell/useTableCell.js +32 -0
  62. package/lib/components/TableCell/useTableCell.js.map +1 -0
  63. package/lib/components/TableCell/useTableCellStyles.js +59 -0
  64. package/lib/components/TableCell/useTableCellStyles.js.map +1 -0
  65. package/lib/components/TableCellActions/TableCellActions.js +15 -0
  66. package/lib/components/TableCellActions/TableCellActions.js.map +1 -0
  67. package/lib/components/TableCellActions/TableCellActions.types.js +2 -0
  68. package/lib/components/TableCellActions/TableCellActions.types.js.map +1 -0
  69. package/lib/components/TableCellActions/index.js +6 -0
  70. package/lib/components/TableCellActions/index.js.map +1 -0
  71. package/lib/components/TableCellActions/renderTableCellActions.js +16 -0
  72. package/lib/components/TableCellActions/renderTableCellActions.js.map +1 -0
  73. package/lib/components/TableCellActions/useTableCellActions.js +27 -0
  74. package/lib/components/TableCellActions/useTableCellActions.js.map +1 -0
  75. package/lib/components/TableCellActions/useTableCellActionsStyles.js +40 -0
  76. package/lib/components/TableCellActions/useTableCellActionsStyles.js.map +1 -0
  77. package/lib/components/TableCellLayout/TableCellLayout.js +16 -0
  78. package/lib/components/TableCellLayout/TableCellLayout.js.map +1 -0
  79. package/lib/components/TableCellLayout/TableCellLayout.types.js +2 -0
  80. package/lib/components/TableCellLayout/TableCellLayout.types.js.map +1 -0
  81. package/lib/components/TableCellLayout/index.js +6 -0
  82. package/lib/components/TableCellLayout/index.js.map +1 -0
  83. package/lib/components/TableCellLayout/renderTableCellLayout.js +22 -0
  84. package/lib/components/TableCellLayout/renderTableCellLayout.js.map +1 -0
  85. package/lib/components/TableCellLayout/useTableCellLayout.js +46 -0
  86. package/lib/components/TableCellLayout/useTableCellLayout.js.map +1 -0
  87. package/lib/components/TableCellLayout/useTableCellLayoutContextValues.js +13 -0
  88. package/lib/components/TableCellLayout/useTableCellLayoutContextValues.js.map +1 -0
  89. package/lib/components/TableCellLayout/useTableCellLayoutStyles.js +74 -0
  90. package/lib/components/TableCellLayout/useTableCellLayoutStyles.js.map +1 -0
  91. package/lib/components/TableHeader/TableHeader.js +15 -0
  92. package/lib/components/TableHeader/TableHeader.js.map +1 -0
  93. package/lib/components/TableHeader/TableHeader.types.js +2 -0
  94. package/lib/components/TableHeader/TableHeader.types.js.map +1 -0
  95. package/lib/components/TableHeader/index.js +6 -0
  96. package/lib/components/TableHeader/index.js.map +1 -0
  97. package/lib/components/TableHeader/renderTableHeader.js +15 -0
  98. package/lib/components/TableHeader/renderTableHeader.js.map +1 -0
  99. package/lib/components/TableHeader/useTableHeader.js +39 -0
  100. package/lib/components/TableHeader/useTableHeader.js.map +1 -0
  101. package/lib/components/TableHeader/useTableHeaderStyles.js +41 -0
  102. package/lib/components/TableHeader/useTableHeaderStyles.js.map +1 -0
  103. package/lib/components/TableHeaderCell/TableHeaderCell.js +15 -0
  104. package/lib/components/TableHeaderCell/TableHeaderCell.js.map +1 -0
  105. package/lib/components/TableHeaderCell/TableHeaderCell.types.js +2 -0
  106. package/lib/components/TableHeaderCell/TableHeaderCell.types.js.map +1 -0
  107. package/lib/components/TableHeaderCell/index.js +6 -0
  108. package/lib/components/TableHeaderCell/index.js.map +1 -0
  109. package/lib/components/TableHeaderCell/renderTableHeaderCell.js +17 -0
  110. package/lib/components/TableHeaderCell/renderTableHeaderCell.js.map +1 -0
  111. package/lib/components/TableHeaderCell/useTableHeaderCell.js +62 -0
  112. package/lib/components/TableHeaderCell/useTableHeaderCell.js.map +1 -0
  113. package/lib/components/TableHeaderCell/useTableHeaderCellStyles.js +106 -0
  114. package/lib/components/TableHeaderCell/useTableHeaderCellStyles.js.map +1 -0
  115. package/lib/components/TableRow/TableRow.js +15 -0
  116. package/lib/components/TableRow/TableRow.js.map +1 -0
  117. package/lib/components/TableRow/TableRow.types.js +2 -0
  118. package/lib/components/TableRow/TableRow.types.js.map +1 -0
  119. package/lib/components/TableRow/index.js +6 -0
  120. package/lib/components/TableRow/index.js.map +1 -0
  121. package/lib/components/TableRow/renderTableRow.js +16 -0
  122. package/lib/components/TableRow/renderTableRow.js.map +1 -0
  123. package/lib/components/TableRow/useTableRow.js +34 -0
  124. package/lib/components/TableRow/useTableRow.js.map +1 -0
  125. package/lib/components/TableRow/useTableRowStyles.js +88 -0
  126. package/lib/components/TableRow/useTableRowStyles.js.map +1 -0
  127. package/lib/components/TableSelectionCell/TableSelectionCell.js +15 -0
  128. package/lib/components/TableSelectionCell/TableSelectionCell.js.map +1 -0
  129. package/lib/components/TableSelectionCell/TableSelectionCell.types.js +2 -0
  130. package/lib/components/TableSelectionCell/TableSelectionCell.types.js.map +1 -0
  131. package/lib/components/TableSelectionCell/index.js +6 -0
  132. package/lib/components/TableSelectionCell/index.js.map +1 -0
  133. package/lib/components/TableSelectionCell/renderTableSelectionCell.js +17 -0
  134. package/lib/components/TableSelectionCell/renderTableSelectionCell.js.map +1 -0
  135. package/lib/components/TableSelectionCell/useTableSelectionCell.js +47 -0
  136. package/lib/components/TableSelectionCell/useTableSelectionCell.js.map +1 -0
  137. package/lib/components/TableSelectionCell/useTableSelectionCellStyles.js +81 -0
  138. package/lib/components/TableSelectionCell/useTableSelectionCellStyles.js.map +1 -0
  139. package/lib/contexts/tableContext.js +14 -0
  140. package/lib/contexts/tableContext.js.map +1 -0
  141. package/lib/hooks/index.js +5 -0
  142. package/lib/hooks/index.js.map +1 -0
  143. package/lib/hooks/selectionManager.js +89 -0
  144. package/lib/hooks/selectionManager.js.map +1 -0
  145. package/lib/hooks/types.js +2 -0
  146. package/lib/hooks/types.js.map +1 -0
  147. package/lib/hooks/useSelection.js +74 -0
  148. package/lib/hooks/useSelection.js.map +1 -0
  149. package/lib/hooks/useSort.js +94 -0
  150. package/lib/hooks/useSort.js.map +1 -0
  151. package/lib/hooks/useTable.js +32 -0
  152. package/lib/hooks/useTable.js.map +1 -0
  153. package/lib/index.js +12 -0
  154. package/lib/index.js.map +1 -0
  155. package/lib/navigationModes/cell.js +250 -0
  156. package/lib/navigationModes/cell.js.map +1 -0
  157. package/lib/navigationModes/composite.js +208 -0
  158. package/lib/navigationModes/composite.js.map +1 -0
  159. package/lib/navigationModes/index.js +3 -0
  160. package/lib/navigationModes/index.js.map +1 -0
  161. package/lib/navigationModes/useNavigationMode.js +42 -0
  162. package/lib/navigationModes/useNavigationMode.js.map +1 -0
  163. package/lib-commonjs/Table.js +10 -0
  164. package/lib-commonjs/Table.js.map +1 -0
  165. package/lib-commonjs/TableBody.js +10 -0
  166. package/lib-commonjs/TableBody.js.map +1 -0
  167. package/lib-commonjs/TableCell.js +10 -0
  168. package/lib-commonjs/TableCell.js.map +1 -0
  169. package/lib-commonjs/TableCellActions.js +10 -0
  170. package/lib-commonjs/TableCellActions.js.map +1 -0
  171. package/lib-commonjs/TableCellLayout.js +10 -0
  172. package/lib-commonjs/TableCellLayout.js.map +1 -0
  173. package/lib-commonjs/TableCellPrimaryLayout.js +10 -0
  174. package/lib-commonjs/TableCellPrimaryLayout.js.map +1 -0
  175. package/lib-commonjs/TableHeader.js +10 -0
  176. package/lib-commonjs/TableHeader.js.map +1 -0
  177. package/lib-commonjs/TableHeaderCell.js +10 -0
  178. package/lib-commonjs/TableHeaderCell.js.map +1 -0
  179. package/lib-commonjs/TableRow.js +10 -0
  180. package/lib-commonjs/TableRow.js.map +1 -0
  181. package/lib-commonjs/TableSelectionCell.js +10 -0
  182. package/lib-commonjs/TableSelectionCell.js.map +1 -0
  183. package/lib-commonjs/components/Table/Table.js +28 -0
  184. package/lib-commonjs/components/Table/Table.js.map +1 -0
  185. package/lib-commonjs/components/Table/Table.types.js +6 -0
  186. package/lib-commonjs/components/Table/Table.types.js.map +1 -0
  187. package/lib-commonjs/components/Table/index.js +18 -0
  188. package/lib-commonjs/components/Table/index.js.map +1 -0
  189. package/lib-commonjs/components/Table/renderTable.js +30 -0
  190. package/lib-commonjs/components/Table/renderTable.js.map +1 -0
  191. package/lib-commonjs/components/Table/useTable.js +40 -0
  192. package/lib-commonjs/components/Table/useTable.js.map +1 -0
  193. package/lib-commonjs/components/Table/useTableContextValues.js +27 -0
  194. package/lib-commonjs/components/Table/useTableContextValues.js.map +1 -0
  195. package/lib-commonjs/components/Table/useTableStyles.js +64 -0
  196. package/lib-commonjs/components/Table/useTableStyles.js.map +1 -0
  197. package/lib-commonjs/components/TableBody/TableBody.js +26 -0
  198. package/lib-commonjs/components/TableBody/TableBody.js.map +1 -0
  199. package/lib-commonjs/components/TableBody/TableBody.types.js +6 -0
  200. package/lib-commonjs/components/TableBody/TableBody.types.js.map +1 -0
  201. package/lib-commonjs/components/TableBody/index.js +18 -0
  202. package/lib-commonjs/components/TableBody/index.js.map +1 -0
  203. package/lib-commonjs/components/TableBody/renderTableBody.js +27 -0
  204. package/lib-commonjs/components/TableBody/renderTableBody.js.map +1 -0
  205. package/lib-commonjs/components/TableBody/useTableBody.js +43 -0
  206. package/lib-commonjs/components/TableBody/useTableBody.js.map +1 -0
  207. package/lib-commonjs/components/TableBody/useTableBodyStyles.js +44 -0
  208. package/lib-commonjs/components/TableBody/useTableBodyStyles.js.map +1 -0
  209. package/lib-commonjs/components/TableCell/TableCell.js +26 -0
  210. package/lib-commonjs/components/TableCell/TableCell.js.map +1 -0
  211. package/lib-commonjs/components/TableCell/TableCell.types.js +6 -0
  212. package/lib-commonjs/components/TableCell/TableCell.types.js.map +1 -0
  213. package/lib-commonjs/components/TableCell/index.js +18 -0
  214. package/lib-commonjs/components/TableCell/index.js.map +1 -0
  215. package/lib-commonjs/components/TableCell/renderTableCell.js +26 -0
  216. package/lib-commonjs/components/TableCell/renderTableCell.js.map +1 -0
  217. package/lib-commonjs/components/TableCell/useTableCell.js +43 -0
  218. package/lib-commonjs/components/TableCell/useTableCell.js.map +1 -0
  219. package/lib-commonjs/components/TableCell/useTableCellStyles.js +70 -0
  220. package/lib-commonjs/components/TableCell/useTableCellStyles.js.map +1 -0
  221. package/lib-commonjs/components/TableCellActions/TableCellActions.js +26 -0
  222. package/lib-commonjs/components/TableCellActions/TableCellActions.js.map +1 -0
  223. package/lib-commonjs/components/TableCellActions/TableCellActions.types.js +6 -0
  224. package/lib-commonjs/components/TableCellActions/TableCellActions.types.js.map +1 -0
  225. package/lib-commonjs/components/TableCellActions/index.js +18 -0
  226. package/lib-commonjs/components/TableCellActions/index.js.map +1 -0
  227. package/lib-commonjs/components/TableCellActions/renderTableCellActions.js +27 -0
  228. package/lib-commonjs/components/TableCellActions/renderTableCellActions.js.map +1 -0
  229. package/lib-commonjs/components/TableCellActions/useTableCellActions.js +38 -0
  230. package/lib-commonjs/components/TableCellActions/useTableCellActions.js.map +1 -0
  231. package/lib-commonjs/components/TableCellActions/useTableCellActionsStyles.js +51 -0
  232. package/lib-commonjs/components/TableCellActions/useTableCellActionsStyles.js.map +1 -0
  233. package/lib-commonjs/components/TableCellLayout/TableCellLayout.js +28 -0
  234. package/lib-commonjs/components/TableCellLayout/TableCellLayout.js.map +1 -0
  235. package/lib-commonjs/components/TableCellLayout/TableCellLayout.types.js +6 -0
  236. package/lib-commonjs/components/TableCellLayout/TableCellLayout.types.js.map +1 -0
  237. package/lib-commonjs/components/TableCellLayout/index.js +18 -0
  238. package/lib-commonjs/components/TableCellLayout/index.js.map +1 -0
  239. package/lib-commonjs/components/TableCellLayout/renderTableCellLayout.js +34 -0
  240. package/lib-commonjs/components/TableCellLayout/renderTableCellLayout.js.map +1 -0
  241. package/lib-commonjs/components/TableCellLayout/useTableCellLayout.js +57 -0
  242. package/lib-commonjs/components/TableCellLayout/useTableCellLayout.js.map +1 -0
  243. package/lib-commonjs/components/TableCellLayout/useTableCellLayoutContextValues.js +23 -0
  244. package/lib-commonjs/components/TableCellLayout/useTableCellLayoutContextValues.js.map +1 -0
  245. package/lib-commonjs/components/TableCellLayout/useTableCellLayoutStyles.js +85 -0
  246. package/lib-commonjs/components/TableCellLayout/useTableCellLayoutStyles.js.map +1 -0
  247. package/lib-commonjs/components/TableHeader/TableHeader.js +26 -0
  248. package/lib-commonjs/components/TableHeader/TableHeader.js.map +1 -0
  249. package/lib-commonjs/components/TableHeader/TableHeader.types.js +6 -0
  250. package/lib-commonjs/components/TableHeader/TableHeader.types.js.map +1 -0
  251. package/lib-commonjs/components/TableHeader/index.js +18 -0
  252. package/lib-commonjs/components/TableHeader/index.js.map +1 -0
  253. package/lib-commonjs/components/TableHeader/renderTableHeader.js +26 -0
  254. package/lib-commonjs/components/TableHeader/renderTableHeader.js.map +1 -0
  255. package/lib-commonjs/components/TableHeader/useTableHeader.js +51 -0
  256. package/lib-commonjs/components/TableHeader/useTableHeader.js.map +1 -0
  257. package/lib-commonjs/components/TableHeader/useTableHeaderStyles.js +51 -0
  258. package/lib-commonjs/components/TableHeader/useTableHeaderStyles.js.map +1 -0
  259. package/lib-commonjs/components/TableHeaderCell/TableHeaderCell.js +26 -0
  260. package/lib-commonjs/components/TableHeaderCell/TableHeaderCell.js.map +1 -0
  261. package/lib-commonjs/components/TableHeaderCell/TableHeaderCell.types.js +6 -0
  262. package/lib-commonjs/components/TableHeaderCell/TableHeaderCell.types.js.map +1 -0
  263. package/lib-commonjs/components/TableHeaderCell/index.js +18 -0
  264. package/lib-commonjs/components/TableHeaderCell/index.js.map +1 -0
  265. package/lib-commonjs/components/TableHeaderCell/renderTableHeaderCell.js +28 -0
  266. package/lib-commonjs/components/TableHeaderCell/renderTableHeaderCell.js.map +1 -0
  267. package/lib-commonjs/components/TableHeaderCell/useTableHeaderCell.js +76 -0
  268. package/lib-commonjs/components/TableHeaderCell/useTableHeaderCell.js.map +1 -0
  269. package/lib-commonjs/components/TableHeaderCell/useTableHeaderCellStyles.js +117 -0
  270. package/lib-commonjs/components/TableHeaderCell/useTableHeaderCellStyles.js.map +1 -0
  271. package/lib-commonjs/components/TableRow/TableRow.js +26 -0
  272. package/lib-commonjs/components/TableRow/TableRow.js.map +1 -0
  273. package/lib-commonjs/components/TableRow/TableRow.types.js +6 -0
  274. package/lib-commonjs/components/TableRow/TableRow.types.js.map +1 -0
  275. package/lib-commonjs/components/TableRow/index.js +18 -0
  276. package/lib-commonjs/components/TableRow/index.js.map +1 -0
  277. package/lib-commonjs/components/TableRow/renderTableRow.js +27 -0
  278. package/lib-commonjs/components/TableRow/renderTableRow.js.map +1 -0
  279. package/lib-commonjs/components/TableRow/useTableRow.js +45 -0
  280. package/lib-commonjs/components/TableRow/useTableRow.js.map +1 -0
  281. package/lib-commonjs/components/TableRow/useTableRowStyles.js +100 -0
  282. package/lib-commonjs/components/TableRow/useTableRowStyles.js.map +1 -0
  283. package/lib-commonjs/components/TableSelectionCell/TableSelectionCell.js +26 -0
  284. package/lib-commonjs/components/TableSelectionCell/TableSelectionCell.js.map +1 -0
  285. package/lib-commonjs/components/TableSelectionCell/TableSelectionCell.types.js +6 -0
  286. package/lib-commonjs/components/TableSelectionCell/TableSelectionCell.types.js.map +1 -0
  287. package/lib-commonjs/components/TableSelectionCell/index.js +18 -0
  288. package/lib-commonjs/components/TableSelectionCell/index.js.map +1 -0
  289. package/lib-commonjs/components/TableSelectionCell/renderTableSelectionCell.js +28 -0
  290. package/lib-commonjs/components/TableSelectionCell/renderTableSelectionCell.js.map +1 -0
  291. package/lib-commonjs/components/TableSelectionCell/useTableSelectionCell.js +62 -0
  292. package/lib-commonjs/components/TableSelectionCell/useTableSelectionCell.js.map +1 -0
  293. package/lib-commonjs/components/TableSelectionCell/useTableSelectionCellStyles.js +91 -0
  294. package/lib-commonjs/components/TableSelectionCell/useTableSelectionCellStyles.js.map +1 -0
  295. package/lib-commonjs/contexts/tableContext.js +25 -0
  296. package/lib-commonjs/contexts/tableContext.js.map +1 -0
  297. package/lib-commonjs/hooks/index.js +16 -0
  298. package/lib-commonjs/hooks/index.js.map +1 -0
  299. package/lib-commonjs/hooks/selectionManager.js +98 -0
  300. package/lib-commonjs/hooks/selectionManager.js.map +1 -0
  301. package/lib-commonjs/hooks/types.js +6 -0
  302. package/lib-commonjs/hooks/types.js.map +1 -0
  303. package/lib-commonjs/hooks/useSelection.js +89 -0
  304. package/lib-commonjs/hooks/useSelection.js.map +1 -0
  305. package/lib-commonjs/hooks/useSort.js +107 -0
  306. package/lib-commonjs/hooks/useSort.js.map +1 -0
  307. package/lib-commonjs/hooks/useTable.js +42 -0
  308. package/lib-commonjs/hooks/useTable.js.map +1 -0
  309. package/lib-commonjs/index.js +377 -0
  310. package/lib-commonjs/index.js.map +1 -0
  311. package/lib-commonjs/navigationModes/cell.js +259 -0
  312. package/lib-commonjs/navigationModes/cell.js.map +1 -0
  313. package/lib-commonjs/navigationModes/composite.js +217 -0
  314. package/lib-commonjs/navigationModes/composite.js.map +1 -0
  315. package/lib-commonjs/navigationModes/index.js +16 -0
  316. package/lib-commonjs/navigationModes/index.js.map +1 -0
  317. package/lib-commonjs/navigationModes/useNavigationMode.js +55 -0
  318. package/lib-commonjs/navigationModes/useNavigationMode.js.map +1 -0
  319. package/package.json +50 -0
@@ -0,0 +1,89 @@
1
+ export function createSelectionManager(mode, onSelectionChange = () => undefined) {
2
+ const managerFactory = mode === 'multiselect' ? createMultipleSelectionManager : createSingleSelectionManager;
3
+ return managerFactory(onSelectionChange);
4
+ }
5
+
6
+ function createMultipleSelectionManager(onSelectionChange) {
7
+ const toggleAllItems = (itemIds, selectedItems) => {
8
+ const allItemsSelected = itemIds.every(itemId => selectedItems.has(itemId));
9
+
10
+ if (allItemsSelected) {
11
+ selectedItems.clear();
12
+ } else {
13
+ itemIds.forEach(itemId => selectedItems.add(itemId));
14
+ }
15
+
16
+ onSelectionChange(new Set(selectedItems));
17
+ };
18
+
19
+ const toggleItem = (itemId, selectedItems) => {
20
+ if (selectedItems.has(itemId)) {
21
+ selectedItems.delete(itemId);
22
+ } else {
23
+ selectedItems.add(itemId);
24
+ }
25
+
26
+ onSelectionChange(new Set(selectedItems));
27
+ };
28
+
29
+ const selectItem = (itemId, selectedItems) => {
30
+ selectedItems.add(itemId);
31
+ onSelectionChange(new Set(selectedItems));
32
+ };
33
+
34
+ const deselectItem = (itemId, selectedItems) => {
35
+ selectedItems.delete(itemId);
36
+ onSelectionChange(new Set(selectedItems));
37
+ };
38
+
39
+ const clearItems = () => {
40
+ onSelectionChange(new Set());
41
+ };
42
+
43
+ const isSelected = (itemId, selectedItems) => {
44
+ return selectedItems.has(itemId);
45
+ };
46
+
47
+ return {
48
+ toggleItem,
49
+ selectItem,
50
+ deselectItem,
51
+ clearItems,
52
+ isSelected,
53
+ toggleAllItems
54
+ };
55
+ }
56
+
57
+ function createSingleSelectionManager(onSelectionChange) {
58
+ const toggleItem = itemId => {
59
+ onSelectionChange(new Set([itemId]));
60
+ };
61
+
62
+ const clearItems = () => {
63
+ onSelectionChange(new Set());
64
+ };
65
+
66
+ const isSelected = (itemId, selectedItems) => {
67
+ return selectedItems.has(itemId);
68
+ };
69
+
70
+ const selectItem = itemId => {
71
+ onSelectionChange(new Set([itemId]));
72
+ };
73
+
74
+ return {
75
+ deselectItem: clearItems,
76
+ selectItem,
77
+ toggleAllItems: () => {
78
+ if (process.env.NODE_ENV !== 'production') {
79
+ throw new Error('[react-table]: `toggleAllItems` should not be used in single selection mode');
80
+ }
81
+
82
+ return undefined;
83
+ },
84
+ toggleItem,
85
+ clearItems,
86
+ isSelected
87
+ };
88
+ }
89
+ //# sourceMappingURL=selectionManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../packages/react-components/react-table/src/hooks/selectionManager.ts"],"names":[],"mappings":"AAeA,OAAM,SAAU,sBAAV,CACJ,IADI,EAEJ,iBAAA,GAA+C,MAAM,SAFjD,EAE0D;EAE9D,MAAM,cAAc,GAAG,IAAI,KAAK,aAAT,GAAyB,8BAAzB,GAA0D,4BAAjF;EAEA,OAAO,cAAc,CAAC,iBAAD,CAArB;AACD;;AAED,SAAS,8BAAT,CAAwC,iBAAxC,EAAoF;EAClF,MAAM,cAAc,GAAG,CAAC,OAAD,EAA6B,aAA7B,KAAoE;IACzF,MAAM,gBAAgB,GAAG,OAAO,CAAC,KAAR,CAAc,MAAM,IAAI,aAAa,CAAC,GAAd,CAAkB,MAAlB,CAAxB,CAAzB;;IAEA,IAAI,gBAAJ,EAAsB;MACpB,aAAa,CAAC,KAAd;IACD,CAFD,MAEO;MACL,OAAO,CAAC,OAAR,CAAgB,MAAM,IAAI,aAAa,CAAC,GAAd,CAAkB,MAAlB,CAA1B;IACD;;IAED,iBAAiB,CAAC,IAAI,GAAJ,CAAQ,aAAR,CAAD,CAAjB;EACD,CAVD;;EAYA,MAAM,UAAU,GAAG,CAAC,MAAD,EAA0B,aAA1B,KAAiE;IAClF,IAAI,aAAa,CAAC,GAAd,CAAkB,MAAlB,CAAJ,EAA+B;MAC7B,aAAa,CAAC,MAAd,CAAqB,MAArB;IACD,CAFD,MAEO;MACL,aAAa,CAAC,GAAd,CAAkB,MAAlB;IACD;;IAED,iBAAiB,CAAC,IAAI,GAAJ,CAAQ,aAAR,CAAD,CAAjB;EACD,CARD;;EAUA,MAAM,UAAU,GAAG,CAAC,MAAD,EAA0B,aAA1B,KAAiE;IAClF,aAAa,CAAC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N;MACD;;MAED,OAAO,SAAP;IACD,CATI;IAUL,UAVK;IAWL,UAXK;IAYL;EAZK,CAAP;AAcD","sourcesContent":["import { SelectionMode } from './types';\n\ntype OnSelectionChangeCallback = (selectedItems: Set<SelectionItemId>) => void;\n\nexport interface SelectionManager {\n toggleItem(id: SelectionItemId, selectedItems: Set<SelectionItemId>): void;\n selectItem(id: SelectionItemId, selectedItems: Set<SelectionItemId>): void;\n deselectItem(id: SelectionItemId, selectedItems: Set<SelectionItemId>): void;\n clearItems(): void;\n isSelected(id: SelectionItemId, selectedItems: Set<SelectionItemId>): boolean;\n toggleAllItems(itemIds: SelectionItemId[], selectedItems: Set<SelectionItemId>): void;\n}\n\nexport type SelectionItemId = string | number;\n\nexport function createSelectionManager(\n mode: SelectionMode,\n onSelectionChange: OnSelectionChangeCallback = () => undefined,\n): SelectionManager {\n const managerFactory = mode === 'multiselect' ? createMultipleSelectionManager : createSingleSelectionManager;\n\n return managerFactory(onSelectionChange);\n}\n\nfunction createMultipleSelectionManager(onSelectionChange: OnSelectionChangeCallback): SelectionManager {\n const toggleAllItems = (itemIds: SelectionItemId[], selectedItems: Set<SelectionItemId>) => {\n const allItemsSelected = itemIds.every(itemId => selectedItems.has(itemId));\n\n if (allItemsSelected) {\n selectedItems.clear();\n } else {\n itemIds.forEach(itemId => selectedItems.add(itemId));\n }\n\n onSelectionChange(new Set(selectedItems));\n };\n\n const toggleItem = (itemId: SelectionItemId, selectedItems: Set<SelectionItemId>) => {\n if (selectedItems.has(itemId)) {\n selectedItems.delete(itemId);\n } else {\n selectedItems.add(itemId);\n }\n\n onSelectionChange(new Set(selectedItems));\n };\n\n const selectItem = (itemId: SelectionItemId, selectedItems: Set<SelectionItemId>) => {\n selectedItems.add(itemId);\n onSelectionChange(new Set(selectedItems));\n };\n\n const deselectItem = (itemId: SelectionItemId, selectedItems: Set<SelectionItemId>) => {\n selectedItems.delete(itemId);\n onSelectionChange(new Set(selectedItems));\n };\n\n const clearItems = () => {\n onSelectionChange(new Set());\n };\n\n const isSelected = (itemId: SelectionItemId, selectedItems: Set<SelectionItemId>) => {\n return selectedItems.has(itemId);\n };\n\n return {\n toggleItem,\n selectItem,\n deselectItem,\n clearItems,\n isSelected,\n toggleAllItems,\n };\n}\n\nfunction createSingleSelectionManager(onSelectionChange: OnSelectionChangeCallback): SelectionManager {\n const toggleItem = (itemId: SelectionItemId) => {\n onSelectionChange(new Set([itemId]));\n };\n\n const clearItems = () => {\n onSelectionChange(new Set<SelectionItemId>());\n };\n\n const isSelected = (itemId: SelectionItemId, selectedItems: Set<SelectionItemId>) => {\n return selectedItems.has(itemId);\n };\n\n const selectItem = (itemId: SelectionItemId) => {\n onSelectionChange(new Set([itemId]));\n };\n\n return {\n deselectItem: clearItems,\n selectItem,\n toggleAllItems: () => {\n if (process.env.NODE_ENV !== 'production') {\n throw new Error('[react-table]: `toggleAllItems` should not be used in single selection mode');\n }\n\n return undefined;\n },\n toggleItem,\n clearItems,\n isSelected,\n };\n}\n"],"sourceRoot":""}
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../../../../packages/react-components/react-table/src/hooks/types.ts"],"names":[],"mappings":"","sourcesContent":["import { SortDirection } from '../components/Table/Table.types';\n\nexport type RowId = string | number;\nexport type ColumnId = string | number;\nexport type SelectionMode = 'single' | 'multiselect';\n\nexport interface SortState {\n sortColumn: ColumnId | undefined;\n sortDirection: SortDirection;\n}\n\nexport interface ColumnDefinition<TItem> {\n columnId: ColumnId;\n compare?: (a: TItem, b: TItem) => number;\n}\n\nexport type RowEnhancer<TItem, TRowState extends RowState<TItem> = RowState<TItem>> = (\n row: RowState<TItem>,\n) => TRowState;\n\nexport interface TableSortState<TItem> {\n /**\n * Current sort direction\n */\n sortDirection: SortDirection;\n /**\n * Column id of the currently sorted column\n */\n sortColumn: ColumnId | undefined;\n /**\n * Set the sort direction for the specified column\n */\n setColumnSort: (columnId: ColumnId, sortDirection: SortDirection) => void;\n /**\n * Toggles the sort direction for specified column\n */\n toggleColumnSort: (columnId: ColumnId) => void;\n /**\n * Returns the sort direction if a column is sorted,\n * returns undefined if the column is not sorted\n */\n getSortDirection: (columnId: ColumnId) => SortDirection | undefined;\n\n /**\n * Sorts rows and returns a **shallow** copy of original items\n */\n sort: (rows: RowState<TItem>[]) => RowState<TItem>[];\n}\n\nexport interface TableSelectionState {\n /**\n * Clears all selected rows\n */\n clearRows: () => void;\n /**\n * Selects single row\n */\n selectRow: (rowId: RowId) => void;\n /**\n * De-selects single row\n */\n deselectRow: (rowId: RowId) => void;\n /**\n * Toggle selection of all rows\n */\n toggleAllRows: () => void;\n /**\n * Toggle selection of single row\n */\n toggleRow: (rowId: RowId) => void;\n /**\n * Collection of row ids corresponding to selected rows\n */\n selectedRows: Set<RowId>;\n /**\n * Whether all rows are selected\n */\n allRowsSelected: boolean;\n /**\n * Whether some rows are selected\n */\n someRowsSelected: boolean;\n\n /**\n * Checks if a given rowId is selected\n */\n isRowSelected: (rowId: RowId) => boolean;\n}\n\nexport interface RowState<TItem> {\n /**\n * User provided data\n */\n item: TItem;\n /**\n * The row id, defaults to index position in the collection\n */\n rowId: RowId;\n}\n\nexport interface TableState<TItem> extends Pick<UseTableOptions<TItem>, 'items' | 'getRowId'> {\n /**\n * The row data for rendering\n * @param rowEnhancer - Enhances the row with extra user data\n */\n getRows: <TRowState extends RowState<TItem> = RowState<TItem>>(\n rowEnhancer?: RowEnhancer<TItem, TRowState>,\n ) => TRowState[];\n /**\n * State and actions to manage row selection\n */\n selection: TableSelectionState;\n /**\n * State and actions to manage row sorting\n */\n sort: TableSortState<TItem>;\n /**\n * Table columns\n */\n columns: ColumnDefinition<TItem>[];\n}\n\nexport interface UseSortOptions {\n /**\n * Used to control sorting\n */\n sortState?: SortState;\n /**\n * Used in uncontrolled mode to set initial sort column and direction on mount\n */\n defaultSortState?: SortState;\n /**\n * Called when sort changes\n */\n onSortChange?: (state: SortState) => void;\n}\n\nexport interface UseSelectionOptions {\n /**\n * Can be multi or single select\n */\n selectionMode: SelectionMode;\n /**\n * Used in uncontrolled mode to set initial selected rows on mount\n */\n defaultSelectedItems?: Set<RowId>;\n /**\n * Used to control row selection\n */\n selectedItems?: Set<RowId>;\n /**\n * Called when selection changes\n */\n onSelectionChange?: (selectedItems: Set<RowId>) => void;\n}\n\nexport interface UseTableOptions<TItem> {\n columns: ColumnDefinition<TItem>[];\n items: TItem[];\n getRowId?: (item: TItem) => RowId;\n}\n\nexport type TableStatePlugin = <TItem>(tableState: TableState<TItem>) => TableState<TItem>;\n"]}
@@ -0,0 +1,74 @@
1
+ import * as React from 'react';
2
+ import { useControllableState, useEventCallback } from '@fluentui/react-utilities';
3
+ import { createSelectionManager } from './selectionManager';
4
+
5
+ const noop = () => undefined;
6
+
7
+ export const defaultTableSelectionState = {
8
+ allRowsSelected: false,
9
+ clearRows: noop,
10
+ deselectRow: noop,
11
+ isRowSelected: () => false,
12
+ selectRow: noop,
13
+ selectedRows: /*#__PURE__*/new Set(),
14
+ someRowsSelected: false,
15
+ toggleAllRows: noop,
16
+ toggleRow: noop
17
+ };
18
+ export function useSelection(options) {
19
+ // False positive, these plugin hooks are intended to be run on every render
20
+ // eslint-disable-next-line react-hooks/rules-of-hooks
21
+ return tableState => useSelectionState(tableState, options);
22
+ }
23
+ export function useSelectionState(tableState, options) {
24
+ const {
25
+ items,
26
+ getRowId
27
+ } = tableState;
28
+ const {
29
+ selectionMode,
30
+ defaultSelectedItems,
31
+ selectedItems,
32
+ onSelectionChange
33
+ } = options;
34
+ const [selected, setSelected] = useControllableState({
35
+ initialState: new Set(),
36
+ defaultState: defaultSelectedItems,
37
+ state: selectedItems
38
+ });
39
+ const selectionManager = React.useMemo(() => {
40
+ return createSelectionManager(selectionMode, newSelectedItems => {
41
+ setSelected(() => {
42
+ onSelectionChange === null || onSelectionChange === void 0 ? void 0 : onSelectionChange(newSelectedItems);
43
+ return newSelectedItems;
44
+ });
45
+ });
46
+ }, [onSelectionChange, selectionMode, setSelected]);
47
+ const toggleAllRows = useEventCallback(() => {
48
+ selectionManager.toggleAllItems(items.map((item, i) => {
49
+ var _a;
50
+
51
+ return (_a = getRowId === null || getRowId === void 0 ? void 0 : getRowId(item)) !== null && _a !== void 0 ? _a : i;
52
+ }), selected);
53
+ });
54
+ const toggleRow = useEventCallback(rowId => selectionManager.toggleItem(rowId, selected));
55
+ const deselectRow = useEventCallback(rowId => selectionManager.deselectItem(rowId, selected));
56
+ const selectRow = useEventCallback(rowId => selectionManager.selectItem(rowId, selected));
57
+
58
+ const isRowSelected = rowId => selectionManager.isSelected(rowId, selected);
59
+
60
+ return { ...tableState,
61
+ selection: {
62
+ someRowsSelected: selected.size > 0,
63
+ allRowsSelected: selectionMode === 'single' ? selected.size > 0 : selected.size === items.length,
64
+ selectedRows: selected,
65
+ toggleRow,
66
+ toggleAllRows,
67
+ clearRows: selectionManager.clearItems,
68
+ deselectRow,
69
+ selectRow,
70
+ isRowSelected
71
+ }
72
+ };
73
+ }
74
+ //# sourceMappingURL=useSelection.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../packages/react-components/react-table/src/hooks/useSelection.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAZ,MAAuB,OAAvB;AACA,SAAS,oBAAT,EAA+B,gBAA/B,QAAuD,2BAAvD;AACA,SAAS,sBAAT,QAAuC,oBAAvC;;AAGA,MAAM,IAAI,GAAG,MAAM,SAAnB;;AAEA,OAAO,MAAM,0BAA0B,GAAwB;EAC7D,eAAe,EAAE,KAD4C;EAE7D,SAAS,EAAE,IAFkD;EAG7D,WAAW,EAAE,IAHgD;EAI7D,aAAa,EAAE,MAAM,KAJwC;EAK7D,SAAS,EAAE,IALkD;EAM7D,YAAY,eAAE,IAAI,GAAJ,EAN+C;EAO7D,gBAAgB,EAAE,KAP2C;EAQ7D,aAAa,EAAE,IAR8C;EAS7D,SAAS,EAAE;AATkD,C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A5C,CADF,EAEE,QAFF;EAID,CAL2E,CAA5E;EAOA,MAAM,SAAS,GAAqC,gBAAgB,CAAE,KAAD,IACnE,gBAAgB,CAAC,UAAjB,CAA4B,KAA5B,EAAmC,QAAnC,CADkE,CAApE;EAIA,MAAM,WAAW,GAAuC,gBAAgB,CAAE,KAAD,IACvE,gBAAgB,CAAC,YAAjB,CAA8B,KAA9B,EAAqC,QAArC,CADsE,CAAxE;EAIA,MAAM,SAAS,GAAqC,gBAAgB,CAAE,KAAD,IACnE,gBAAgB,CAAC,UAAjB,CAA4B,KAA5B,EAAmC,QAAnC,CADkE,CAApE;;EAIA,MAAM,aAAa,GAA0C,KAAD,IAC1D,gBAAgB,CAAC,UAAjB,CAA4B,KAA5B,EAAmC,QAAnC,CADF;;EAGA,OAAO,EACL,GAAG,UADE;IAEL,SAAS,EAAE;MACT,gBAAgB,EAAE,QAAQ,CAAC,IAAT,GAAgB,CADzB;MAET,eAAe,EAAE,aAAa,KAAK,QAAlB,GAA6B,QAAQ,CAAC,IAAT,GAAgB,CAA7C,GAAiD,QAAQ,CAAC,IAAT,KAAkB,KAAK,CAAC,MAFjF;MAGT,YAAY,EAAE,QAHL;MAIT,SAJS;MAKT,aALS;MAMT,SAAS,EAAE,gBAAgB,CAAC,UANnB;MAOT,WAPS;MAQT,SARS;MAST;IATS;EAFN,CAAP;AAcD","sourcesContent":["import * as React from 'react';\nimport { useControllableState, useEventCallback } from '@fluentui/react-utilities';\nimport { createSelectionManager } from './selectionManager';\nimport type { RowId, TableSelectionState, TableState, UseSelectionOptions } from './types';\n\nconst noop = () => undefined;\n\nexport const defaultTableSelectionState: TableSelectionState = {\n allRowsSelected: false,\n clearRows: noop,\n deselectRow: noop,\n isRowSelected: () => false,\n selectRow: noop,\n selectedRows: new Set(),\n someRowsSelected: false,\n toggleAllRows: noop,\n toggleRow: noop,\n};\n\nexport function useSelection<TItem>(options: UseSelectionOptions) {\n // False positive, these plugin hooks are intended to be run on every render\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return (tableState: TableState<TItem>) => useSelectionState(tableState, options);\n}\n\nexport function useSelectionState<TItem>(\n tableState: TableState<TItem>,\n options: UseSelectionOptions,\n): TableState<TItem> {\n const { items, getRowId } = tableState;\n const { selectionMode, defaultSelectedItems, selectedItems, onSelectionChange } = options;\n\n const [selected, setSelected] = useControllableState({\n initialState: new Set<RowId>(),\n defaultState: defaultSelectedItems,\n state: selectedItems,\n });\n\n const selectionManager = React.useMemo(() => {\n return createSelectionManager(selectionMode, newSelectedItems => {\n setSelected(() => {\n onSelectionChange?.(newSelectedItems);\n return newSelectedItems;\n });\n });\n }, [onSelectionChange, selectionMode, setSelected]);\n\n const toggleAllRows: TableSelectionState['toggleAllRows'] = useEventCallback(() => {\n selectionManager.toggleAllItems(\n items.map((item, i) => getRowId?.(item) ?? i),\n selected,\n );\n });\n\n const toggleRow: TableSelectionState['toggleRow'] = useEventCallback((rowId: RowId) =>\n selectionManager.toggleItem(rowId, selected),\n );\n\n const deselectRow: TableSelectionState['deselectRow'] = useEventCallback((rowId: RowId) =>\n selectionManager.deselectItem(rowId, selected),\n );\n\n const selectRow: TableSelectionState['selectRow'] = useEventCallback((rowId: RowId) =>\n selectionManager.selectItem(rowId, selected),\n );\n\n const isRowSelected: TableSelectionState['isRowSelected'] = (rowId: RowId) =>\n selectionManager.isSelected(rowId, selected);\n\n return {\n ...tableState,\n selection: {\n someRowsSelected: selected.size > 0,\n allRowsSelected: selectionMode === 'single' ? selected.size > 0 : selected.size === items.length,\n selectedRows: selected,\n toggleRow,\n toggleAllRows,\n clearRows: selectionManager.clearItems,\n deselectRow,\n selectRow,\n isRowSelected,\n },\n };\n}\n"],"sourceRoot":""}
@@ -0,0 +1,94 @@
1
+ import { useControllableState } from '@fluentui/react-utilities';
2
+
3
+ const noop = () => undefined;
4
+
5
+ export const defaultTableSortState = {
6
+ getSortDirection: () => 'ascending',
7
+ setColumnSort: noop,
8
+ sort: rows => [...rows],
9
+ sortColumn: undefined,
10
+ sortDirection: 'ascending',
11
+ toggleColumnSort: noop
12
+ };
13
+ export function useSort(options) {
14
+ // False positive, these plugin hooks are intended to be run on every render
15
+ // eslint-disable-next-line react-hooks/rules-of-hooks
16
+ return tableState => useSortState(tableState, options);
17
+ }
18
+ export function useSortState(tableState, options) {
19
+ const {
20
+ columns
21
+ } = tableState;
22
+ const {
23
+ sortState,
24
+ defaultSortState,
25
+ onSortChange
26
+ } = options;
27
+ const [sorted, setSorted] = useControllableState({
28
+ initialState: {
29
+ sortDirection: 'ascending',
30
+ sortColumn: undefined
31
+ },
32
+ defaultState: defaultSortState,
33
+ state: sortState
34
+ });
35
+ const {
36
+ sortColumn,
37
+ sortDirection
38
+ } = sorted;
39
+
40
+ const toggleColumnSort = columnId => {
41
+ setSorted(s => {
42
+ const newState = { ...s,
43
+ sortColumn: columnId
44
+ };
45
+
46
+ if (s.sortColumn === columnId) {
47
+ newState.sortDirection = s.sortDirection === 'ascending' ? 'descending' : 'ascending';
48
+ } else {
49
+ newState.sortDirection = 'ascending';
50
+ }
51
+
52
+ onSortChange === null || onSortChange === void 0 ? void 0 : onSortChange(newState);
53
+ return newState;
54
+ });
55
+ };
56
+
57
+ const setColumnSort = (nextSortColumn, nextSortDirection) => {
58
+ const newState = {
59
+ sortColumn: nextSortColumn,
60
+ sortDirection: nextSortDirection
61
+ };
62
+ onSortChange === null || onSortChange === void 0 ? void 0 : onSortChange(newState);
63
+ setSorted(newState);
64
+ };
65
+
66
+ const sort = rows => {
67
+ return rows.slice().sort((a, b) => {
68
+ const sortColumnDef = columns.find(column => column.columnId === sortColumn);
69
+
70
+ if (!(sortColumnDef === null || sortColumnDef === void 0 ? void 0 : sortColumnDef.compare)) {
71
+ return 0;
72
+ }
73
+
74
+ const mod = sortDirection === 'ascending' ? 1 : -1;
75
+ return sortColumnDef.compare(a.item, b.item) * mod;
76
+ });
77
+ };
78
+
79
+ const getSortDirection = columnId => {
80
+ return sortColumn === columnId ? sortDirection : undefined;
81
+ };
82
+
83
+ return { ...tableState,
84
+ sort: {
85
+ sort,
86
+ sortColumn,
87
+ sortDirection,
88
+ setColumnSort,
89
+ toggleColumnSort,
90
+ getSortDirection
91
+ }
92
+ };
93
+ }
94
+ //# sourceMappingURL=useSort.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../packages/react-components/react-table/src/hooks/useSort.ts"],"names":[],"mappings":"AAAA,SAAS,oBAAT,QAAqC,2BAArC;;AAGA,MAAM,IAAI,GAAG,MAAM,SAAnB;;AAEA,OAAO,MAAM,qBAAqB,GAA4B;EAC5D,gBAAgB,EAAE,MAAM,WADoC;EAE5D,aAAa,EAAE,IAF6C;EAG5D,IAAI,EAAG,IAAD,IAA+B,CAAC,GAAG,IAAJ,CAHuB;EAI5D,UAAU,EAAE,SAJgD;EAK5D,aAAa,EAAE,WAL6C;EAM5D,gBAAgB,EAAE;AAN0C,CAAvD;AASP,OAAM,SAAU,OAAV,CAAyB,OAAzB,EAAgD;EACpD;EACA;EACA,OAAQ,UAAD,IAAmC,YAAY,CAAC,UAAD,EAAa,OAAb,CAAtD;AACD;AAED,OAAM,SAAU,YAAV,CAA8B,UAA9B,EAA6D,OAA7D,EAAoF;EACxF,MAAM;IAAE;EAAF,IAAc,UAApB;EACA,MAAM;IAAE,SAAF;IAAa,gBAAb;IAA+B;EAA/B,IAAgD,OAAtD;EAEA,MAAM,CAAC,MAAD,EAAS,SAAT,IAAsB,oBAAoB,CAAY;IAC1D,YAAY,EAAE;MACZ,aAAa,EAAE,WADH;MAEZ,UAAU,EAAE;IAFA,CAD4C;IAK1D,YAAY,EAAE,gBAL4C;IAM1D,KAAK,EAAE;EANmD,CAAZ,CAAhD;EASA,MAAM;IAAE,UAAF;IAAc;EAAd,IAAgC,MAAtC;;EAEA,MAAM,gBAAgB,GAAI,QAAD,IAAmC;IAC1D,SAAS,CAAC,CAAC,IAAG;MACZ,MAAM,QAAQ,GAAG,EAAE,GAAG,CAAL;QAAQ,UAAU,EAAE;MAApB,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AAM,gBAAgB,GAA+C,QAAD,IAAuB;IACzF,OAAO,UAAU,KAAK,QAAf,GAA0B,aAA1B,GAA0C,SAAjD;EACD,CAFD;;EAIA,OAAO,EACL,GAAG,UADE;IAEL,IAAI,EAAE;MACJ,IADI;MAEJ,UAFI;MAGJ,aAHI;MAIJ,aAJI;MAKJ,gBALI;MAMJ;IANI;EAFD,CAAP;AAWD","sourcesContent":["import { useControllableState } from '@fluentui/react-utilities';\nimport type { ColumnId, RowState, SortState, TableSortState, TableState, UseSortOptions } from './types';\n\nconst noop = () => undefined;\n\nexport const defaultTableSortState: TableSortState<unknown> = {\n getSortDirection: () => 'ascending',\n setColumnSort: noop,\n sort: (rows: RowState<unknown>[]) => [...rows],\n sortColumn: undefined,\n sortDirection: 'ascending',\n toggleColumnSort: noop,\n};\n\nexport function useSort<TItem>(options: UseSortOptions) {\n // False positive, these plugin hooks are intended to be run on every render\n // eslint-disable-next-line react-hooks/rules-of-hooks\n return (tableState: TableState<TItem>) => useSortState(tableState, options);\n}\n\nexport function useSortState<TItem>(tableState: TableState<TItem>, options: UseSortOptions): TableState<TItem> {\n const { columns } = tableState;\n const { sortState, defaultSortState, onSortChange } = options;\n\n const [sorted, setSorted] = useControllableState<SortState>({\n initialState: {\n sortDirection: 'ascending' as const,\n sortColumn: undefined,\n },\n defaultState: defaultSortState,\n state: sortState,\n });\n\n const { sortColumn, sortDirection } = sorted;\n\n const toggleColumnSort = (columnId: ColumnId | undefined) => {\n setSorted(s => {\n const newState = { ...s, sortColumn: columnId };\n if (s.sortColumn === columnId) {\n newState.sortDirection = s.sortDirection === 'ascending' ? 'descending' : 'ascending';\n } else {\n newState.sortDirection = 'ascending';\n }\n\n onSortChange?.(newState);\n return newState;\n });\n };\n\n const setColumnSort: TableSortState<TItem>['setColumnSort'] = (nextSortColumn, nextSortDirection) => {\n const newState = { sortColumn: nextSortColumn, sortDirection: nextSortDirection };\n onSortChange?.(newState);\n setSorted(newState);\n };\n\n const sort = (rows: RowState<TItem>[]) => {\n return rows.slice().sort((a, b) => {\n const sortColumnDef = columns.find(column => column.columnId === sortColumn);\n if (!sortColumnDef?.compare) {\n return 0;\n }\n\n const mod = sortDirection === 'ascending' ? 1 : -1;\n return sortColumnDef.compare(a.item, b.item) * mod;\n });\n };\n\n const getSortDirection: TableSortState<TItem>['getSortDirection'] = (columnId: ColumnId) => {\n return sortColumn === columnId ? sortDirection : undefined;\n };\n\n return {\n ...tableState,\n sort: {\n sort,\n sortColumn,\n sortDirection,\n setColumnSort,\n toggleColumnSort,\n getSortDirection,\n },\n };\n}\n"],"sourceRoot":""}
@@ -0,0 +1,32 @@
1
+ import { defaultTableSelectionState } from './useSelection';
2
+ import { defaultTableSortState } from './useSort';
3
+
4
+ const defaultRowEnhancer = row => row;
5
+
6
+ export function useTable(options, plugins = []) {
7
+ const {
8
+ items,
9
+ getRowId,
10
+ columns
11
+ } = options;
12
+
13
+ const getRows = (rowEnhancer = defaultRowEnhancer) => items.map((item, i) => {
14
+ var _a;
15
+
16
+ return rowEnhancer({
17
+ item,
18
+ rowId: (_a = getRowId === null || getRowId === void 0 ? void 0 : getRowId(item)) !== null && _a !== void 0 ? _a : i
19
+ });
20
+ });
21
+
22
+ const initialState = {
23
+ getRowId,
24
+ items,
25
+ columns,
26
+ getRows,
27
+ selection: defaultTableSelectionState,
28
+ sort: defaultTableSortState
29
+ };
30
+ return plugins.reduce((state, plugin) => plugin(state), initialState);
31
+ }
32
+ //# sourceMappingURL=useTable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../packages/react-components/react-table/src/hooks/useTable.ts"],"names":[],"mappings":"AACA,SAAS,0BAAT,QAA2C,gBAA3C;AACA,SAAS,qBAAT,QAAsC,WAAtC;;AAEA,MAAM,kBAAkB,GAA4C,GAAG,IAAI,GAA3E;;AAEA,OAAM,SAAU,QAAV,CAA0B,OAA1B,EAA2D,OAAA,GAA8B,EAAzF,EAA2F;EAC/F,MAAM;IAAE,KAAF;IAAS,QAAT;IAAmB;EAAnB,IAA+B,OAArC;;EAEA,MAAM,OAAO,GAAG,CACd,WAAA,GAAc,kBADA,KAEX,KAAK,CAAC,GAAN,CAAU,CAAC,IAAD,EAAO,CAAP,KAAY;IAAA,IAAA,EAAA;;IAAC,OAAA,WAAW,CAAC;MAAE,IAAF;MAAQ,KAAK,EAAE,CAAA,EAAA,GAAA,QAAQ,KAAA,IAAR,IAAA,QAAQ,KAAA,KAAA,CAAR,GAAQ,KAAA,CAAR,GAAA,QAAQ,CAAG,IAAH,CAAR,MAAgB,IAAhB,IAAgB,EAAA,KAAA,KAAA,CAAhB,GAAgB,EAAhB,GAAoB;IAAnC,CAAD,CAAX;EAAmD,CAA1E,CAFL;;EAIA,MAAM,YAAY,GAAsB;IACtC,QADsC;IAEtC,KAFsC;IAGtC,OAHsC;IAItC,OAJsC;IAKtC,SAAS,EAAE,0BAL2B;IAMtC,IAAI,EAAE;EANgC,CAAxC;EASA,OAAO,OAAO,CAAC,MAAR,CAAe,CAAC,KAAD,EAAQ,MAAR,KAAmB,MAAM,CAAC,KAAD,CAAxC,EAAiD,YAAjD,CAAP;AACD","sourcesContent":["import type { UseTableOptions, TableState, RowState, RowEnhancer, TableStatePlugin, TableSortState } from './types';\nimport { defaultTableSelectionState } from './useSelection';\nimport { defaultTableSortState } from './useSort';\n\nconst defaultRowEnhancer: RowEnhancer<unknown, RowState<unknown>> = row => row;\n\nexport function useTable<TItem>(options: UseTableOptions<TItem>, plugins: TableStatePlugin[] = []): TableState<TItem> {\n const { items, getRowId, columns } = options;\n\n const getRows = <TRowState extends RowState<TItem>>(\n rowEnhancer = defaultRowEnhancer as RowEnhancer<TItem, TRowState>,\n ) => items.map((item, i) => rowEnhancer({ item, rowId: getRowId?.(item) ?? i }));\n\n const initialState: TableState<TItem> = {\n getRowId,\n items,\n columns,\n getRows,\n selection: defaultTableSelectionState,\n sort: defaultTableSortState as TableSortState<TItem>,\n };\n\n return plugins.reduce((state, plugin) => plugin(state), initialState);\n}\n"],"sourceRoot":""}
package/lib/index.js ADDED
@@ -0,0 +1,12 @@
1
+ export { useTable, useSelection, useSort } from './hooks';
2
+ export { TableCell, tableCellClassNames, tableCellClassName, useTableCellStyles_unstable, useTableCell_unstable, renderTableCell_unstable } from './TableCell';
3
+ export { TableRow, tableRowClassNames, tableRowClassName, useTableRowStyles_unstable, useTableRow_unstable, renderTableRow_unstable } from './TableRow';
4
+ export { TableBody, tableBodyClassName, tableBodyClassNames, useTableBodyStyles_unstable, useTableBody_unstable, renderTableBody_unstable } from './TableBody';
5
+ export { Table, tableClassName, tableClassNames, useTableStyles_unstable, useTable_unstable, renderTable_unstable } from './Table';
6
+ export { TableHeader, tableHeaderClassNames, tableHeaderClassName, useTableHeaderStyles_unstable, useTableHeader_unstable, renderTableHeader_unstable } from './TableHeader';
7
+ export { TableHeaderCell, tableHeaderCellClassName, tableHeaderCellClassNames, useTableHeaderCellStyles_unstable, useTableHeaderCell_unstable, renderTableHeaderCell_unstable } from './TableHeaderCell';
8
+ export { TableContextProvider, useTableContext } from './contexts/tableContext';
9
+ export { TableSelectionCell, useTableSelectionCellStyles_unstable, useTableSelectionCell_unstable, renderTableSelectionCell_unstable, tableSelectionCellClassNames } from './TableSelectionCell';
10
+ export { TableCellActions, tableCellActionsClassNames, useTableCellActionsStyles_unstable, useTableCellActions_unstable, renderTableCellActions_unstable } from './TableCellActions';
11
+ export { TableCellLayout, tableCellLayoutClassNames, useTableCellLayoutStyles_unstable, useTableCellLayout_unstable, renderTableCellLayout_unstable } from './TableCellLayout';
12
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../packages/react-components/react-table/src/index.ts"],"names":[],"mappings":"AAAA,SAAS,QAAT,EAAmB,YAAnB,EAAiC,OAAjC,QAAgD,SAAhD;AAaA,SACE,SADF,EAEE,mBAFF,EAGE,kBAHF,EAIE,2BAJF,EAKE,qBALF,EAME,wBANF,QAOO,aAPP;AAUA,SACE,QADF,EAEE,kBAFF,EAGE,iBAHF,EAIE,0BAJF,EAKE,oBALF,EAME,uBANF,QAOO,YAPP;AAUA,SACE,SADF,EAEE,kBAFF,EAGE,mBAHF,EAIE,2BAJF,EAKE,qBALF,EAME,wBANF,QAOO,aAPP;AAUA,SACE,KADF,EAEE,cAFF,EAGE,eAHF,EAIE,uBAJF,EAKE,iBALF,EAME,oBANF,QAOO,SAPP;AAUA,SACE,WADF,EAEE,qBAFF,EAGE,oBAHF,EAIE,6BAJF,EAKE,uBALF,EAME,0BANF,QAOO,eAPP;AAUA,SACE,eADF,EAEE,wBAFF,EAGE,yBAHF,EAIE,iCAJF,EAKE,2BALF,EAME,8BANF,QAOO,mBAPP;AAUA,SAAS,oBAAT,EAA+B,eAA/B,QAAsD,yBAAtD;AACA,SACE,kBADF,EAEE,oCAFF,EAGE,8BAHF,EAIE,iCAJF,EAKE,4BALF,QAMO,sBANP;AASA,SACE,gBADF,EAEE,0BAFF,EAGE,kCAHF,EAIE,4BAJF,EAKE,+BALF,QAMO,oBANP;AASA,SACE,eADF,EAEE,yBAFF,EAGE,iCAHF,EAIE,2BAJF,EAKE,8BALF,QAMO,mBANP","sourcesContent":["export { useTable, useSelection, useSort } from './hooks';\nexport type {\n UseTableOptions,\n TableState as HeadlessTableState,\n TableSelectionState,\n TableSortState,\n TableStatePlugin,\n RowState,\n RowId,\n ColumnDefinition,\n ColumnId,\n} from './hooks';\n\nexport {\n TableCell,\n tableCellClassNames,\n tableCellClassName,\n useTableCellStyles_unstable,\n useTableCell_unstable,\n renderTableCell_unstable,\n} from './TableCell';\nexport type { TableCellProps, TableCellState, TableCellSlots } from './TableCell';\n\nexport {\n TableRow,\n tableRowClassNames,\n tableRowClassName,\n useTableRowStyles_unstable,\n useTableRow_unstable,\n renderTableRow_unstable,\n} from './TableRow';\nexport type { TableRowProps, TableRowState, TableRowSlots } from './TableRow';\n\nexport {\n TableBody,\n tableBodyClassName,\n tableBodyClassNames,\n useTableBodyStyles_unstable,\n useTableBody_unstable,\n renderTableBody_unstable,\n} from './TableBody';\nexport type { TableBodyProps, TableBodyState, TableBodySlots } from './TableBody';\n\nexport {\n Table,\n tableClassName,\n tableClassNames,\n useTableStyles_unstable,\n useTable_unstable,\n renderTable_unstable,\n} from './Table';\nexport type { TableProps, TableSlots, TableState, TableContextValue, TableContextValues, SortDirection } from './Table';\n\nexport {\n TableHeader,\n tableHeaderClassNames,\n tableHeaderClassName,\n useTableHeaderStyles_unstable,\n useTableHeader_unstable,\n renderTableHeader_unstable,\n} from './TableHeader';\nexport type { TableHeaderProps, TableHeaderSlots, TableHeaderState } from './TableHeader';\n\nexport {\n TableHeaderCell,\n tableHeaderCellClassName,\n tableHeaderCellClassNames,\n useTableHeaderCellStyles_unstable,\n useTableHeaderCell_unstable,\n renderTableHeaderCell_unstable,\n} from './TableHeaderCell';\nexport type { TableHeaderCellProps, TableHeaderCellSlots, TableHeaderCellState } from './TableHeaderCell';\n\nexport { TableContextProvider, useTableContext } from './contexts/tableContext';\nexport {\n TableSelectionCell,\n useTableSelectionCellStyles_unstable,\n useTableSelectionCell_unstable,\n renderTableSelectionCell_unstable,\n tableSelectionCellClassNames,\n} from './TableSelectionCell';\n\nexport type { TableSelectionCellProps, TableSelectionCellState, TableSelectionCellSlots } from './TableSelectionCell';\nexport {\n TableCellActions,\n tableCellActionsClassNames,\n useTableCellActionsStyles_unstable,\n useTableCellActions_unstable,\n renderTableCellActions_unstable,\n} from './TableCellActions';\n\nexport type { TableCellActionsProps, TableCellActionsSlots, TableCellActionsState } from './TableCellActions';\nexport {\n TableCellLayout,\n tableCellLayoutClassNames,\n useTableCellLayoutStyles_unstable,\n useTableCellLayout_unstable,\n renderTableCellLayout_unstable,\n} from './TableCellLayout';\nexport type { TableCellLayoutProps, TableCellLayoutSlots, TableCellLayoutState } from './TableCellLayout';\n"],"sourceRoot":""}
@@ -0,0 +1,250 @@
1
+ export function applyCellNavigation(element) {
2
+ const container = element;
3
+ let column = 0;
4
+ let mode = undefined;
5
+ let movingOut = false;
6
+ const pre = document.createElement('div');
7
+ const post = document.createElement('div');
8
+
9
+ if (!pre || !post) {
10
+ return;
11
+ }
12
+
13
+ pre.tabIndex = 0;
14
+ post.tabIndex = 0;
15
+ pre.addEventListener('focus', () => {
16
+ if (movingOut) {
17
+ movingOut = false;
18
+ return;
19
+ } else {
20
+ treeWalker.currentNode = container;
21
+ const candidate = treeWalker.nextNode();
22
+
23
+ if (isHTMLElement(candidate)) {
24
+ column = 0;
25
+ candidate.focus();
26
+ }
27
+ }
28
+ });
29
+ post.addEventListener('focus', () => {
30
+ if (movingOut) {
31
+ movingOut = false;
32
+ return;
33
+ } else {
34
+ treeWalker.currentNode = post;
35
+ const candidate = treeWalker.previousNode();
36
+
37
+ if (isHTMLElement(candidate)) {
38
+ column = findColumnCount(candidate);
39
+ candidate.focus();
40
+ }
41
+ }
42
+ });
43
+ container.before(pre);
44
+ container.after(post);
45
+
46
+ const acceptNode = node => {
47
+ if (!isHTMLElement(node)) {
48
+ return NodeFilter.FILTER_SKIP;
49
+ }
50
+
51
+ if (mode === 'column') {
52
+ return acceptCell(node);
53
+ }
54
+
55
+ if (mode === 'row') {
56
+ return acceptRow(node);
57
+ }
58
+
59
+ if (node.tabIndex >= 0) {
60
+ return NodeFilter.FILTER_ACCEPT;
61
+ }
62
+
63
+ return NodeFilter.FILTER_SKIP;
64
+ };
65
+
66
+ const acceptCell = node => {
67
+ if (isRow(node)) {
68
+ return NodeFilter.FILTER_REJECT;
69
+ }
70
+
71
+ if (node.tabIndex < 0) {
72
+ return NodeFilter.FILTER_SKIP;
73
+ }
74
+
75
+ return NodeFilter.FILTER_ACCEPT;
76
+ };
77
+
78
+ const acceptRow = node => {
79
+ if (isRow(node)) {
80
+ return NodeFilter.FILTER_ACCEPT;
81
+ }
82
+
83
+ return NodeFilter.FILTER_SKIP;
84
+ };
85
+
86
+ const treeWalker = document.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, {
87
+ acceptNode
88
+ });
89
+
90
+ const up = current => {
91
+ mode = 'row';
92
+ treeWalker.currentNode = current;
93
+ treeWalker.previousNode(); // current row
94
+
95
+ const row = treeWalker.previousNode();
96
+
97
+ if (!row) {
98
+ return null;
99
+ }
100
+
101
+ mode = 'column';
102
+ treeWalker.currentNode = row;
103
+ let curCol = 0;
104
+ let node = null;
105
+
106
+ while (curCol <= column) {
107
+ node = treeWalker.nextNode();
108
+ curCol++;
109
+ }
110
+
111
+ if (isHTMLElement(node)) {
112
+ return node;
113
+ }
114
+
115
+ return null;
116
+ };
117
+
118
+ const down = current => {
119
+ mode = 'row';
120
+ treeWalker.currentNode = current;
121
+ const row = treeWalker.nextNode();
122
+
123
+ if (!row) {
124
+ return null;
125
+ }
126
+
127
+ mode = 'column';
128
+ treeWalker.currentNode = row;
129
+ let curCol = 0;
130
+ let node = null;
131
+
132
+ while (curCol <= column) {
133
+ node = treeWalker.nextNode();
134
+ curCol++;
135
+ }
136
+
137
+ if (isHTMLElement(node)) {
138
+ return node;
139
+ }
140
+
141
+ return null;
142
+ };
143
+
144
+ const left = current => {
145
+ treeWalker.currentNode = current;
146
+ mode = 'column';
147
+ const node = treeWalker.previousNode();
148
+
149
+ if (isHTMLElement(node)) {
150
+ column--;
151
+ return node;
152
+ }
153
+
154
+ return null;
155
+ };
156
+
157
+ const right = current => {
158
+ mode = 'column';
159
+ treeWalker.currentNode = current;
160
+ const node = treeWalker.nextNode();
161
+
162
+ if (isHTMLElement(node)) {
163
+ column++;
164
+ return node;
165
+ }
166
+
167
+ return null;
168
+ };
169
+
170
+ const onKeyDown = e => {
171
+ const target = e.target;
172
+
173
+ if (!target || !isHTMLElement(target)) {
174
+ return;
175
+ }
176
+
177
+ let next = null;
178
+
179
+ switch (e.key) {
180
+ case 'ArrowDown':
181
+ next = down(target);
182
+ break;
183
+
184
+ case 'ArrowUp':
185
+ next = up(target);
186
+ break;
187
+
188
+ case 'ArrowLeft':
189
+ next = left(target);
190
+ break;
191
+
192
+ case 'ArrowRight':
193
+ next = right(target);
194
+ break;
195
+
196
+ case 'Tab':
197
+ movingOut = true;
198
+
199
+ if (e.shiftKey) {
200
+ pre.focus();
201
+ } else {
202
+ post.focus();
203
+ }
204
+
205
+ break;
206
+
207
+ default:
208
+ return;
209
+ }
210
+
211
+ if (next) {
212
+ e.preventDefault();
213
+ next.focus();
214
+ }
215
+ };
216
+
217
+ const onFocusOut = () => {
218
+ mode = undefined;
219
+ };
220
+
221
+ container.addEventListener('keydown', onKeyDown);
222
+ container.addEventListener('focusout', onFocusOut);
223
+ return () => {
224
+ container.removeEventListener('focusout', onFocusOut);
225
+ container.removeEventListener('keydown', onKeyDown);
226
+ };
227
+ }
228
+
229
+ function isHTMLElement(node) {
230
+ return node instanceof HTMLElement;
231
+ }
232
+
233
+ function isRow(element) {
234
+ if (element.getAttribute('role') === 'row' || element.tagName === 'TR') {
235
+ return true;
236
+ }
237
+
238
+ return false;
239
+ }
240
+
241
+ function findColumnCount(node) {
242
+ let cur = node;
243
+
244
+ while (cur.parentElement && !isRow(cur)) {
245
+ cur = cur.parentElement;
246
+ }
247
+
248
+ return cur.querySelectorAll('[role="cell"], [role="gridcell"], td').length - 1;
249
+ }
250
+ //# sourceMappingURL=cell.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../../../../../packages/react-components/react-table/src/navigationModes/cell.ts"],"names":[],"mappings":"AAAA,OAAM,SAAU,mBAAV,CAA8B,OAA9B,EAAkD;EACtD,MAAM,SAAS,GAAG,OAAlB;EACA,IAAI,MAAM,GAAG,CAAb;EACA,IAAI,IAAI,GAAiC,SAAzC;EACA,IAAI,SAAS,GAAG,KAAhB;EAEA,MAAM,GAAG,GAAG,QAAQ,CAAC,aAAT,CAAuB,KAAvB,CAAZ;EACA,MAAM,IAAI,GAAG,QAAQ,CAAC,aAAT,CAAuB,KAAvB,CAAb;;EAEA,IAAI,CAAC,GAAD,IAAQ,CAAC,IAAb,EAAmB;IACjB;EACD;;EAED,GAAG,CAAC,QAAJ,GAAe,CAAf;EACA,IA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QACA;;MACF,KAAK,YAAL;QACE,IAAI,GAAG,KAAK,CAAC,MAAD,CAAZ;QACA;;MACF,KAAK,KAAL;QACE,SAAS,GAAG,IAAZ;;QACA,IAAI,CAAC,CAAC,QAAN,EAAgB;UACd,GAAG,CAAC,KAAJ;QACD,CAFD,MAEO;UACL,IAAI,CAAC,KAAL;QACD;;QAED;;MACF;QACE;IAvBJ;;IA0BA,IAAI,IAAJ,EAAU;MACR,CAAC,CAAC,cAAF;MACA,IAAI,CAAC,KAAL;IACD;EACF,CAtCD;;EAwCA,MAAM,UAAU,GAAG,MAAK;IACtB,IAAI,GAAG,SAAP;EACD,CAFD;;EAIA,SAAS,CAAC,gBAAV,CAA2B,SAA3B,EAAsC,SAAtC;EACA,SAAS,CAAC,gBAAV,CAA2B,UAA3B,EAAuC,UAAvC;EACA,OAAO,MAAK;IACV,SAAS,CAAC,mBAAV,CAA8B,UAA9B,EAA0C,UAA1C;IACA,SAAS,CAAC,mBAAV,CAA8B,SAA9B,EAAyC,SAAzC;EACD,CAHD;AAID;;AAED,SAAS,aAAT,CAAuB,IAAvB,EAAoC;EAClC,OAAO,IAAI,YAAY,WAAvB;AACD;;AAED,SAAS,KAAT,CAAe,OAAf,EAAmC;EACjC,IAAI,OAAO,CAAC,YAAR,CAAqB,MAArB,MAAiC,KAAjC,IAA0C,OAAO,CAAC,OAAR,KAAoB,IAAlE,EAAwE;IACtE,OAAO,IAAP;EACD;;EAED,OAAO,KAAP;AACD;;AAED,SAAS,eAAT,CAAyB,IAAzB,EAA0C;EACxC,IAAI,GAAG,GAAG,IAAV;;EACA,OAAO,GAAG,CAAC,aAAJ,IAAqB,CAAC,KAAK,CAAC,GAAD,CAAlC,EAAyC;IACvC,GAAG,GAAG,GAAG,CAAC,aAAV;EACD;;EAED,OAAO,GAAG,CAAC,gBAAJ,CAAqB,sCAArB,EAA6D,MAA7D,GAAsE,CAA7E;AACD","sourcesContent":["export function applyCellNavigation(element: HTMLElement) {\n const container = element;\n let column = 0;\n let mode: 'row' | 'column' | undefined = undefined;\n let movingOut = false;\n\n const pre = document.createElement('div');\n const post = document.createElement('div');\n\n if (!pre || !post) {\n return;\n }\n\n pre.tabIndex = 0;\n post.tabIndex = 0;\n\n pre.addEventListener('focus', () => {\n if (movingOut) {\n movingOut = false;\n return;\n } else {\n treeWalker.currentNode = container;\n const candidate = treeWalker.nextNode();\n if (isHTMLElement(candidate)) {\n column = 0;\n candidate.focus();\n }\n }\n });\n\n post.addEventListener('focus', () => {\n if (movingOut) {\n movingOut = false;\n return;\n } else {\n treeWalker.currentNode = post;\n const candidate = treeWalker.previousNode();\n if (isHTMLElement(candidate)) {\n column = findColumnCount(candidate);\n candidate.focus();\n }\n }\n });\n\n container.before(pre);\n container.after(post);\n\n const acceptNode = (node: Node) => {\n if (!isHTMLElement(node)) {\n return NodeFilter.FILTER_SKIP;\n }\n\n if (mode === 'column') {\n return acceptCell(node);\n }\n\n if (mode === 'row') {\n return acceptRow(node);\n }\n\n if (node.tabIndex >= 0) {\n return NodeFilter.FILTER_ACCEPT;\n }\n\n return NodeFilter.FILTER_SKIP;\n };\n\n const acceptCell = (node: HTMLElement) => {\n if (isRow(node)) {\n return NodeFilter.FILTER_REJECT;\n }\n\n if (node.tabIndex < 0) {\n return NodeFilter.FILTER_SKIP;\n }\n\n return NodeFilter.FILTER_ACCEPT;\n };\n\n const acceptRow = (node: HTMLElement) => {\n if (isRow(node)) {\n return NodeFilter.FILTER_ACCEPT;\n }\n\n return NodeFilter.FILTER_SKIP;\n };\n\n const treeWalker = document.createTreeWalker(container, NodeFilter.SHOW_ELEMENT, { acceptNode });\n\n const up = (current: HTMLElement) => {\n mode = 'row';\n treeWalker.currentNode = current;\n treeWalker.previousNode(); // current row\n const row = treeWalker.previousNode();\n if (!row) {\n return null;\n }\n\n mode = 'column';\n treeWalker.currentNode = row;\n let curCol = 0;\n let node: Node | null = null;\n while (curCol <= column) {\n node = treeWalker.nextNode();\n curCol++;\n }\n if (isHTMLElement(node)) {\n return node;\n }\n return null;\n };\n\n const down = (current: HTMLElement) => {\n mode = 'row';\n treeWalker.currentNode = current;\n const row = treeWalker.nextNode();\n if (!row) {\n return null;\n }\n\n mode = 'column';\n treeWalker.currentNode = row;\n let curCol = 0;\n let node: Node | null = null;\n while (curCol <= column) {\n node = treeWalker.nextNode();\n curCol++;\n }\n if (isHTMLElement(node)) {\n return node;\n }\n return null;\n };\n\n const left = (current: HTMLElement) => {\n treeWalker.currentNode = current;\n mode = 'column';\n const node = treeWalker.previousNode();\n\n if (isHTMLElement(node)) {\n column--;\n return node;\n }\n return null;\n };\n\n const right = (current: HTMLElement) => {\n mode = 'column';\n treeWalker.currentNode = current;\n const node = treeWalker.nextNode();\n if (isHTMLElement(node)) {\n column++;\n return node;\n }\n return null;\n };\n\n const onKeyDown = (e: KeyboardEvent) => {\n const target = e.target;\n if (!target || !isHTMLElement(target)) {\n return;\n }\n\n let next: HTMLElement | null = null;\n\n switch (e.key) {\n case 'ArrowDown':\n next = down(target);\n break;\n case 'ArrowUp':\n next = up(target);\n break;\n case 'ArrowLeft':\n next = left(target);\n break;\n case 'ArrowRight':\n next = right(target);\n break;\n case 'Tab':\n movingOut = true;\n if (e.shiftKey) {\n pre.focus();\n } else {\n post.focus();\n }\n\n break;\n default:\n return;\n }\n\n if (next) {\n e.preventDefault();\n next.focus();\n }\n };\n\n const onFocusOut = () => {\n mode = undefined;\n };\n\n container.addEventListener('keydown', onKeyDown);\n container.addEventListener('focusout', onFocusOut);\n return () => {\n container.removeEventListener('focusout', onFocusOut);\n container.removeEventListener('keydown', onKeyDown);\n };\n}\n\nfunction isHTMLElement(node: unknown): node is HTMLElement {\n return node instanceof HTMLElement;\n}\n\nfunction isRow(element: HTMLElement) {\n if (element.getAttribute('role') === 'row' || element.tagName === 'TR') {\n return true;\n }\n\n return false;\n}\n\nfunction findColumnCount(node: HTMLElement) {\n let cur = node;\n while (cur.parentElement && !isRow(cur)) {\n cur = cur.parentElement;\n }\n\n return cur.querySelectorAll('[role=\"cell\"], [role=\"gridcell\"], td').length - 1;\n}\n"],"sourceRoot":""}