@infinite-table/infinite-react 0.5.1 → 0.5.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (282) hide show
  1. package/README.md +104 -0
  2. package/index.css +896 -0
  3. package/index.d.ts +2264 -0
  4. package/index.esm.css +896 -0
  5. package/index.esm.js +15404 -0
  6. package/index.js +15240 -0
  7. package/package.json +3 -95
  8. package/.vscode/settings.json +0 -3
  9. package/API.md +0 -0
  10. package/build/buildPackageJson.js +0 -43
  11. package/build/scripts/test.js +0 -37
  12. package/bundler.config.js +0 -25
  13. package/globals.d.ts +0 -7
  14. package/rollup.config.js +0 -15
  15. package/run-build-deepmap.js +0 -47
  16. package/run-build.js +0 -45
  17. package/run-dts-concat.js +0 -21
  18. package/src/components/CSSVariableWatch.tsx +0 -82
  19. package/src/components/DataSource/BooleanCollectionState.ts +0 -214
  20. package/src/components/DataSource/BooleanDeepCollectionState.ts +0 -208
  21. package/src/components/DataSource/DataSourceContext.ts +0 -20
  22. package/src/components/DataSource/GroupRowsState.ts +0 -74
  23. package/src/components/DataSource/Indexer.ts +0 -27
  24. package/src/components/DataSource/RowSelectionState.ts +0 -763
  25. package/src/components/DataSource/defaultFilterTypes.ts +0 -64
  26. package/src/components/DataSource/index.tsx +0 -108
  27. package/src/components/DataSource/privateHooks/getChangeDetect.ts +0 -7
  28. package/src/components/DataSource/privateHooks/useLoadData.ts +0 -783
  29. package/src/components/DataSource/publicHooks/useDataSource.ts +0 -19
  30. package/src/components/DataSource/publicHooks/useDataSourceActions.ts +0 -14
  31. package/src/components/DataSource/state/getInitialState.ts +0 -494
  32. package/src/components/DataSource/state/normalizeSortInfo.ts +0 -35
  33. package/src/components/DataSource/state/reducer.ts +0 -466
  34. package/src/components/DataSource/state/rowInfoStatus.ts +0 -27
  35. package/src/components/DataSource/types.ts +0 -548
  36. package/src/components/HeadlessTable/HeadlessTableWithPinnedContainers.tsx +0 -142
  37. package/src/components/HeadlessTable/MappedCells.ts +0 -251
  38. package/src/components/HeadlessTable/RawTable.tsx +0 -98
  39. package/src/components/HeadlessTable/ReactHeadlessTableRenderer.tsx +0 -1516
  40. package/src/components/HeadlessTable/index.tsx +0 -234
  41. package/src/components/InfiniteTable/InfiniteCls.css.ts +0 -164
  42. package/src/components/InfiniteTable/InfiniteTableContext.ts +0 -16
  43. package/src/components/InfiniteTable/api/getImperativeApi.ts +0 -391
  44. package/src/components/InfiniteTable/api/getSelectionApi.ts +0 -364
  45. package/src/components/InfiniteTable/api/type.ts +0 -11
  46. package/src/components/InfiniteTable/components/ActiveCellIndicator.css.ts +0 -51
  47. package/src/components/InfiniteTable/components/ActiveCellIndicator.tsx +0 -116
  48. package/src/components/InfiniteTable/components/ActiveRowIndicator.css.ts +0 -56
  49. package/src/components/InfiniteTable/components/ActiveRowIndicator.tsx +0 -94
  50. package/src/components/InfiniteTable/components/CheckBox.css.ts +0 -13
  51. package/src/components/InfiniteTable/components/CheckBox.tsx +0 -96
  52. package/src/components/InfiniteTable/components/FilterEditors.tsx +0 -52
  53. package/src/components/InfiniteTable/components/InfiniteTableBody/InfiniteTableBody.tsx +0 -27
  54. package/src/components/InfiniteTable/components/InfiniteTableBody/index.tsx +0 -1
  55. package/src/components/InfiniteTable/components/InfiniteTableFooter/InfiniteTableFooter.tsx +0 -31
  56. package/src/components/InfiniteTable/components/InfiniteTableFooter/index.tsx +0 -1
  57. package/src/components/InfiniteTable/components/InfiniteTableHeader/InfiniteTableColumnHeaderFilter.tsx +0 -102
  58. package/src/components/InfiniteTable/components/InfiniteTableHeader/InfiniteTableHeader.tsx +0 -163
  59. package/src/components/InfiniteTable/components/InfiniteTableHeader/InfiniteTableHeaderCell.tsx +0 -574
  60. package/src/components/InfiniteTable/components/InfiniteTableHeader/InfiniteTableHeaderGroup.tsx +0 -79
  61. package/src/components/InfiniteTable/components/InfiniteTableHeader/InfiniteTableHeaderTypes.tsx +0 -25
  62. package/src/components/InfiniteTable/components/InfiniteTableHeader/InfiniteTableHeaderWrapper.tsx +0 -185
  63. package/src/components/InfiniteTable/components/InfiniteTableHeader/ResizeHandle/GroupResizeHandle.tsx +0 -159
  64. package/src/components/InfiniteTable/components/InfiniteTableHeader/ResizeHandle/ResizeHandle.css.ts +0 -124
  65. package/src/components/InfiniteTable/components/InfiniteTableHeader/ResizeHandle/columnResizer.ts +0 -166
  66. package/src/components/InfiniteTable/components/InfiniteTableHeader/ResizeHandle/index.tsx +0 -146
  67. package/src/components/InfiniteTable/components/InfiniteTableHeader/buildColumnAndGroupTree.ts +0 -240
  68. package/src/components/InfiniteTable/components/InfiniteTableHeader/header.css.ts +0 -358
  69. package/src/components/InfiniteTable/components/InfiniteTableHeader/index.tsx +0 -1
  70. package/src/components/InfiniteTable/components/InfiniteTableHeader/useColumnGroupResizeHandle.tsx +0 -114
  71. package/src/components/InfiniteTable/components/InfiniteTableHeader/useColumnResizeHandle.tsx +0 -146
  72. package/src/components/InfiniteTable/components/InfiniteTableLicenseFooter/footer.css.ts +0 -7
  73. package/src/components/InfiniteTable/components/InfiniteTableLicenseFooter/index.tsx +0 -110
  74. package/src/components/InfiniteTable/components/InfiniteTableRow/InfiniteTableCell.tsx +0 -120
  75. package/src/components/InfiniteTable/components/InfiniteTableRow/InfiniteTableCellTypes.ts +0 -74
  76. package/src/components/InfiniteTable/components/InfiniteTableRow/InfiniteTableColumnCell.tsx +0 -457
  77. package/src/components/InfiniteTable/components/InfiniteTableRow/InfiniteTableRow.tsx +0 -107
  78. package/src/components/InfiniteTable/components/InfiniteTableRow/InfiniteTableRowClassName.ts +0 -6
  79. package/src/components/InfiniteTable/components/InfiniteTableRow/InfiniteTableRowTypes.ts +0 -32
  80. package/src/components/InfiniteTable/components/InfiniteTableRow/InfiniteTableRowUnvirtualized.tsx +0 -75
  81. package/src/components/InfiniteTable/components/InfiniteTableRow/columnRendering.tsx +0 -263
  82. package/src/components/InfiniteTable/components/InfiniteTableRow/index.tsx +0 -1
  83. package/src/components/InfiniteTable/components/InfiniteTableRow/row.css.ts +0 -74
  84. package/src/components/InfiniteTable/components/InfiniteTableRow/useRowDOMProps.ts +0 -199
  85. package/src/components/InfiniteTable/components/LoadMask.css.ts +0 -34
  86. package/src/components/InfiniteTable/components/LoadMask.tsx +0 -27
  87. package/src/components/InfiniteTable/components/ScrollbarPlaceholder.tsx +0 -56
  88. package/src/components/InfiniteTable/components/cell.css.ts +0 -192
  89. package/src/components/InfiniteTable/components/icons/ArrowDown.tsx +0 -14
  90. package/src/components/InfiniteTable/components/icons/ArrowUp.tsx +0 -14
  91. package/src/components/InfiniteTable/components/icons/ExpanderIcon.css.ts +0 -31
  92. package/src/components/InfiniteTable/components/icons/ExpanderIcon.tsx +0 -63
  93. package/src/components/InfiniteTable/components/icons/Icon.tsx +0 -18
  94. package/src/components/InfiniteTable/components/icons/InfiniteTableIconClassName.ts +0 -1
  95. package/src/components/InfiniteTable/components/icons/LoadingIcon.css.ts +0 -8
  96. package/src/components/InfiniteTable/components/icons/LoadingIcon.tsx +0 -45
  97. package/src/components/InfiniteTable/components/icons/MenuIcon.tsx +0 -50
  98. package/src/components/InfiniteTable/components/icons/SortIcon.tsx +0 -113
  99. package/src/components/InfiniteTable/eventHandlers/eventHandlerTypes.ts +0 -57
  100. package/src/components/InfiniteTable/eventHandlers/index.ts +0 -95
  101. package/src/components/InfiniteTable/eventHandlers/keyboardNavigation.ts +0 -232
  102. package/src/components/InfiniteTable/eventHandlers/keyboardSelection.ts +0 -110
  103. package/src/components/InfiniteTable/eventHandlers/onCellClick.ts +0 -94
  104. package/src/components/InfiniteTable/eventHandlers/onKeyDown.ts +0 -25
  105. package/src/components/InfiniteTable/hooks/adjustColumnOrderForAllColumns.ts +0 -70
  106. package/src/components/InfiniteTable/hooks/reorderColumnsOnDrag.ts +0 -476
  107. package/src/components/InfiniteTable/hooks/useAutoSizeColumns.ts +0 -206
  108. package/src/components/InfiniteTable/hooks/useCellClassName.ts +0 -80
  109. package/src/components/InfiniteTable/hooks/useCellRendering.tsx +0 -217
  110. package/src/components/InfiniteTable/hooks/useColumnGroups.ts +0 -71
  111. package/src/components/InfiniteTable/hooks/useColumnMenu.ts +0 -72
  112. package/src/components/InfiniteTable/hooks/useColumnPointerEvents.ts +0 -258
  113. package/src/components/InfiniteTable/hooks/useColumnRowspan.ts +0 -43
  114. package/src/components/InfiniteTable/hooks/useColumnSizeFn.ts +0 -24
  115. package/src/components/InfiniteTable/hooks/useColumnsWhen.ts +0 -582
  116. package/src/components/InfiniteTable/hooks/useComputed.ts +0 -186
  117. package/src/components/InfiniteTable/hooks/useComputedVisibleColumns.ts +0 -219
  118. package/src/components/InfiniteTable/hooks/useDOMProps.ts +0 -306
  119. package/src/components/InfiniteTable/hooks/useEffectWithRaf.ts +0 -47
  120. package/src/components/InfiniteTable/hooks/useInfiniteTable.ts +0 -10
  121. package/src/components/InfiniteTable/hooks/useInfiniteTableState.ts +0 -11
  122. package/src/components/InfiniteTable/hooks/useInternalProps.ts +0 -8
  123. package/src/components/InfiniteTable/hooks/useLicense/LicenseDetails.ts +0 -13
  124. package/src/components/InfiniteTable/hooks/useLicense/crc32.ts +0 -56
  125. package/src/components/InfiniteTable/hooks/useLicense/decode.ts +0 -147
  126. package/src/components/InfiniteTable/hooks/useLicense/useLicense.ts +0 -39
  127. package/src/components/InfiniteTable/hooks/useRerenderOnKeyChange.ts +0 -21
  128. package/src/components/InfiniteTable/hooks/useRowHover.ts +0 -18
  129. package/src/components/InfiniteTable/hooks/useScrollToActiveCell.ts +0 -48
  130. package/src/components/InfiniteTable/hooks/useScrollToActiveRow.ts +0 -44
  131. package/src/components/InfiniteTable/hooks/useScrollbars.ts +0 -51
  132. package/src/components/InfiniteTable/hooks/useToggleGroupRow.ts +0 -56
  133. package/src/components/InfiniteTable/hooks/useUnpinnedRendering.tsx +0 -165
  134. package/src/components/InfiniteTable/hooks/useYourBrain.ts +0 -55
  135. package/src/components/InfiniteTable/index.tsx +0 -352
  136. package/src/components/InfiniteTable/internalProps.ts +0 -4
  137. package/src/components/InfiniteTable/state/computeColumnGroupsDepths.ts +0 -29
  138. package/src/components/InfiniteTable/state/getColumnVisibilityForHideEmptyGroupColumns.ts +0 -127
  139. package/src/components/InfiniteTable/state/getInitialState.ts +0 -375
  140. package/src/components/InfiniteTable/theme.css.ts +0 -556
  141. package/src/components/InfiniteTable/types/InfiniteTableAction.ts +0 -6
  142. package/src/components/InfiniteTable/types/InfiniteTableActionType.ts +0 -12
  143. package/src/components/InfiniteTable/types/InfiniteTableColumn.ts +0 -478
  144. package/src/components/InfiniteTable/types/InfiniteTableComputedValues.ts +0 -43
  145. package/src/components/InfiniteTable/types/InfiniteTableContextValue.ts +0 -12
  146. package/src/components/InfiniteTable/types/InfiniteTableInternalProps.ts +0 -3
  147. package/src/components/InfiniteTable/types/InfiniteTableProps.ts +0 -511
  148. package/src/components/InfiniteTable/types/InfiniteTableState.ts +0 -195
  149. package/src/components/InfiniteTable/types/Utility.ts +0 -35
  150. package/src/components/InfiniteTable/types/index.ts +0 -96
  151. package/src/components/InfiniteTable/utilities.css.ts +0 -179
  152. package/src/components/InfiniteTable/utils/MultiRowSelector.ts +0 -111
  153. package/src/components/InfiniteTable/utils/RenderHookComponentForInfinite.tsx +0 -52
  154. package/src/components/InfiniteTable/utils/adjustColumnOrderForPinning.ts +0 -33
  155. package/src/components/InfiniteTable/utils/assignFiltered.ts +0 -29
  156. package/src/components/InfiniteTable/utils/defaultGetColumContextMenuItems.tsx +0 -108
  157. package/src/components/InfiniteTable/utils/getColumnComputedType.ts +0 -33
  158. package/src/components/InfiniteTable/utils/getColumnForGroupBy.tsx +0 -313
  159. package/src/components/InfiniteTable/utils/getComputedVisibleColumns.ts +0 -773
  160. package/src/components/InfiniteTable/utils/getContextMenuForColumn.tsx +0 -72
  161. package/src/components/InfiniteTable/utils/infiniteDOMUtils.ts +0 -189
  162. package/src/components/InfiniteTable/utils/mapToObject.ts +0 -20
  163. package/src/components/InfiniteTable/utils/moveXatY.ts +0 -25
  164. package/src/components/InfiniteTable/utils/objectValuesExcept.ts +0 -9
  165. package/src/components/InfiniteTable/utils/progressiveSpeedScroller.ts +0 -158
  166. package/src/components/InfiniteTable/utils/rafFn.ts +0 -13
  167. package/src/components/InfiniteTable/utils/toCSSVarName.ts +0 -1
  168. package/src/components/InfiniteTable/utils/toMap.ts +0 -24
  169. package/src/components/Menu/Menu.tsx +0 -750
  170. package/src/components/Menu/MenuCls.css.ts +0 -139
  171. package/src/components/Menu/MenuContext.ts +0 -10
  172. package/src/components/Menu/MenuContextValue.ts +0 -15
  173. package/src/components/Menu/MenuProps.ts +0 -98
  174. package/src/components/Menu/MenuState.ts +0 -56
  175. package/src/components/Menu/MenuTriangleContext.ts +0 -352
  176. package/src/components/Menu/childrenToRuntimeItems.tsx +0 -103
  177. package/src/components/Menu/getMenuState.tsx +0 -119
  178. package/src/components/Menu/index.tsx +0 -88
  179. package/src/components/Menu/propToIdentifyMenu.ts +0 -1
  180. package/src/components/RawList/AvoidReactDiff.tsx +0 -48
  181. package/src/components/RawList/MappedItems.ts +0 -143
  182. package/src/components/RawList/ReactVirtualRenderer.tsx +0 -307
  183. package/src/components/RawList/index.tsx +0 -42
  184. package/src/components/RawList/types.ts +0 -23
  185. package/src/components/RawList/useVirtualRenderer.ts +0 -36
  186. package/src/components/RenderHookComponent.tsx +0 -10
  187. package/src/components/ResizeObserver/index.tsx +0 -170
  188. package/src/components/VirtualBrain/MatrixBrain.ts +0 -1621
  189. package/src/components/VirtualBrain/ScrollListener.ts +0 -39
  190. package/src/components/VirtualBrain/index.ts +0 -664
  191. package/src/components/VirtualList/ColumnListWithExternalScrolling.tsx +0 -78
  192. package/src/components/VirtualList/InfiniteListRootClassName.ts +0 -1
  193. package/src/components/VirtualList/RowListWithExternalScrolling.tsx +0 -120
  194. package/src/components/VirtualList/SpacePlaceholder.tsx +0 -32
  195. package/src/components/VirtualList/VirtualList.css.ts +0 -29
  196. package/src/components/VirtualList/VirtualList.tsx +0 -141
  197. package/src/components/VirtualList/VirtualRowList.tsx +0 -34
  198. package/src/components/VirtualList/types.ts +0 -56
  199. package/src/components/VirtualList/useCorrectHeightForRowElements.ts +0 -14
  200. package/src/components/VirtualScrollContainer/VirtualScrollContainer.css.ts +0 -51
  201. package/src/components/VirtualScrollContainer/getScrollableClassName.ts +0 -30
  202. package/src/components/VirtualScrollContainer/index.tsx +0 -63
  203. package/src/components/flexbox/index.ts +0 -562
  204. package/src/components/hooks/useComponentState/index.tsx +0 -562
  205. package/src/components/hooks/useComponentState/types.ts +0 -32
  206. package/src/components/hooks/useEffectOnceWithProperUnmount.ts +0 -33
  207. package/src/components/hooks/useEffectWithChanges.ts +0 -56
  208. package/src/components/hooks/useImmutableRef.ts +0 -7
  209. package/src/components/hooks/useInterceptedMap.ts +0 -71
  210. package/src/components/hooks/useLatest.tsx +0 -8
  211. package/src/components/hooks/useLazyLatest.ts +0 -23
  212. package/src/components/hooks/useMemoShallowObjectMerge.ts +0 -16
  213. package/src/components/hooks/useMounted.ts +0 -18
  214. package/src/components/hooks/useOnMount.ts +0 -21
  215. package/src/components/hooks/useOnScroll.ts +0 -34
  216. package/src/components/hooks/useOnce.ts +0 -10
  217. package/src/components/hooks/useOverlay/index.tsx +0 -418
  218. package/src/components/hooks/usePrevious.ts +0 -8
  219. package/src/components/hooks/usePropertyOld.ts +0 -168
  220. package/src/components/hooks/useRerender.ts +0 -12
  221. package/src/components/hooks/xuseProperty.ts +0 -165
  222. package/src/components/types/CellPosition.ts +0 -4
  223. package/src/components/types/NonUndefined.ts +0 -1
  224. package/src/components/types/RemoveObject.ts +0 -22
  225. package/src/components/types/Renderable.ts +0 -3
  226. package/src/components/types/ScrollPosition.ts +0 -7
  227. package/src/components/types/Setter.ts +0 -2
  228. package/src/components/types/Size.ts +0 -6
  229. package/src/components/types/SubscriptionCallback.ts +0 -10
  230. package/src/components/types/VoidFn.ts +0 -1
  231. package/src/components/utils/buildSubscriptionCallback.tsx +0 -60
  232. package/src/components/utils/clamp.ts +0 -3
  233. package/src/components/utils/debounce.ts +0 -16
  234. package/src/components/utils/decamelize.ts +0 -11
  235. package/src/components/utils/discardCallsWithEqualArg.ts +0 -42
  236. package/src/components/utils/getRenderIndexes.ts +0 -33
  237. package/src/components/utils/getScrollbarWidth.ts +0 -31
  238. package/src/components/utils/getVirtualRenderCount.ts +0 -21
  239. package/src/components/utils/isControlled.ts +0 -12
  240. package/src/components/utils/isControlledValue.ts +0 -5
  241. package/src/index.tsx +0 -34
  242. package/src/test.tsx +0 -18
  243. package/src/utils/DeepMap/index.ts +0 -588
  244. package/src/utils/DeepMap/once.ts +0 -16
  245. package/src/utils/DeepMap/sortAscending.ts +0 -1
  246. package/src/utils/DeepMap/tsconfig.deepmap.json +0 -17
  247. package/src/utils/DeepMap/xpackage.json +0 -26
  248. package/src/utils/debug.ts +0 -40
  249. package/src/utils/deepClone.ts +0 -38
  250. package/src/utils/getGlobal.ts +0 -3
  251. package/src/utils/groupAndPivot/defaultToKey.ts +0 -3
  252. package/src/utils/groupAndPivot/getGroupKeysForDataItem.ts +0 -19
  253. package/src/utils/groupAndPivot/getPivotColumnsAndColumnGroups.ts +0 -361
  254. package/src/utils/groupAndPivot/index.ts +0 -1229
  255. package/src/utils/groupAndPivot/types.ts +0 -10
  256. package/src/utils/join.ts +0 -4
  257. package/src/utils/mathIntersection.ts +0 -21
  258. package/src/utils/minified.d.ts +0 -2
  259. package/src/utils/minified.js +0 -6
  260. package/src/utils/multisort/index.ts +0 -151
  261. package/src/utils/multisort/sortTypes.ts +0 -25
  262. package/src/utils/notes-status.md +0 -92
  263. package/src/utils/pageGeometry/ConvexPoly.ts +0 -34
  264. package/src/utils/pageGeometry/Point.ts +0 -51
  265. package/src/utils/pageGeometry/PolyWithPoints.ts +0 -52
  266. package/src/utils/pageGeometry/Rectangle.ts +0 -98
  267. package/src/utils/pageGeometry/Triangle.ts +0 -16
  268. package/src/utils/pageGeometry/alignment/index.ts +0 -221
  269. package/src/utils/pageGeometry/polyContainsPoint.ts +0 -182
  270. package/src/utils/pageGeometry/types.ts +0 -3
  271. package/src/utils/proxyFnCall.ts +0 -46
  272. package/src/utils/raf.ts +0 -13
  273. package/src/utils/selectParent.ts +0 -18
  274. package/src/utils/shallowEqualObjects.ts +0 -49
  275. package/src/utils/stripVar.ts +0 -3
  276. package/src/utils/toUpperFirst.ts +0 -5
  277. package/todo.md +0 -2
  278. package/tsconfig.build.json +0 -8
  279. package/tsconfig.dev.json +0 -7
  280. package/tsconfig.json +0 -30
  281. package/tsconfig.typebundler.json +0 -13
  282. package/typedoc.json +0 -4
@@ -1,763 +0,0 @@
1
- import { DataSourceState } from '.';
2
- import { DeepMap } from '../../utils/DeepMap';
3
- import { getGroupKeysForDataItem } from '../../utils/groupAndPivot/getGroupKeysForDataItem';
4
-
5
- type RowSelectionStateItem = (any | any[])[];
6
-
7
- export type RowSelectionStateObject =
8
- | {
9
- selectedRows: RowSelectionStateItem;
10
- deselectedRows: RowSelectionStateItem;
11
- defaultSelection: boolean;
12
- }
13
- | {
14
- defaultSelection: true;
15
- deselectedRows: RowSelectionStateItem;
16
- selectedRows?: RowSelectionStateItem;
17
- }
18
- | {
19
- defaultSelection: false;
20
- selectedRows: RowSelectionStateItem;
21
- deselectedRows?: RowSelectionStateItem;
22
- };
23
-
24
- export type RowSelectionStateConfig<T> = {
25
- groupBy: DataSourceState<T>['groupBy'];
26
- groupDeepMap: DataSourceState<T>['groupDeepMap'];
27
- toPrimaryKey: DataSourceState<T>['toPrimaryKey'];
28
- totalCount: number;
29
- indexer: DataSourceState<T>['indexer'];
30
- lazyLoad: boolean;
31
- onlyUsePrimaryKeys: boolean;
32
- };
33
-
34
- export type GetRowSelectionStateConfig<T> = () => RowSelectionStateConfig<T>;
35
-
36
- type RowSelectionStateOverride = {
37
- getGroupKeysForPrimaryKey: RowSelectionState<any>['getGroupKeysForPrimaryKey'];
38
- getGroupByLength: RowSelectionState<any>['getGroupByLength'];
39
- getGroupCount: RowSelectionState<any>['getGroupCount'];
40
- getGroupKeysDirectlyInsideGroup: RowSelectionState<any>['getGroupKeysDirectlyInsideGroup'];
41
- getAllPrimaryKeysInsideGroup: RowSelectionState<any>['getAllPrimaryKeysInsideGroup'];
42
- };
43
-
44
- export class RowSelectionState<T = any> {
45
- selectedRows: RowSelectionStateItem | null = null;
46
- deselectedRows: RowSelectionStateItem | null = null;
47
-
48
- defaultSelection: boolean = false;
49
-
50
- selectedMap: DeepMap<any, true> = new DeepMap();
51
- deselectedMap: DeepMap<any, true> = new DeepMap();
52
-
53
- onlyUsePrimaryKeys: boolean = false;
54
-
55
- // TODO make it easy to share the cache with another instance
56
- selectionCache: DeepMap<any, boolean | null> = new DeepMap();
57
- selectionCountCache: DeepMap<
58
- any,
59
- { selectedCount: number; deselectedCount: number }
60
- > = new DeepMap();
61
-
62
- getConfig: GetRowSelectionStateConfig<T>;
63
-
64
- getGroupKeysForPrimaryKey(pk: any) {
65
- const { indexer, groupBy } = this.getConfig();
66
-
67
- const data = indexer.getDataForPrimaryKey(pk);
68
-
69
- // if (!data) {
70
- // console.error('Cannot find data object for primary key', pk);
71
- // }
72
-
73
- return data ? getGroupKeysForDataItem(data, groupBy) : [];
74
- }
75
-
76
- getGroupDeepMap() {
77
- return this.getConfig().groupDeepMap;
78
- }
79
-
80
- getGroupCount(groupKeys: any[]) {
81
- if (groupKeys.length == 0) {
82
- return this.getConfig().totalCount;
83
- }
84
- const groupDeepMap = this.getGroupDeepMap();
85
- const deepMapValue = groupDeepMap?.get(groupKeys);
86
- if (!deepMapValue) {
87
- return 0;
88
- }
89
-
90
- return deepMapValue.totalChildrenCount ?? (deepMapValue.items.length || 0);
91
- }
92
-
93
- getGroupKeysDirectlyInsideGroup(groupKeys: any[]) {
94
- const { groupDeepMap } = this.getConfig();
95
- return groupDeepMap?.getKeysStartingWith(groupKeys, true, 1) || [];
96
- }
97
-
98
- getAllPrimaryKeysInsideGroup(groupKeys: any[]): any[] {
99
- const { groupDeepMap } = this.getConfig();
100
-
101
- if (!groupKeys.length) {
102
- const topLevelKeys = groupDeepMap?.getKeysStartingWith([], true, 1) || [];
103
-
104
- return topLevelKeys
105
- .map((groupKeys) => this.getAllPrimaryKeysInsideGroup(groupKeys))
106
- .flat();
107
- }
108
-
109
- const group = groupDeepMap?.get(groupKeys);
110
- return group ? group.items.map(this.getConfig().toPrimaryKey) : [];
111
- }
112
-
113
- getGroupByLength() {
114
- return this.getConfig().groupBy.length;
115
- }
116
-
117
- static from<T>(
118
- rowSeleStateObject: RowSelectionStateObject,
119
- getConfig: GetRowSelectionStateConfig<T>,
120
- overrides?: RowSelectionStateOverride,
121
- ) {
122
- return new RowSelectionState(rowSeleStateObject, getConfig, overrides);
123
- }
124
-
125
- constructor(
126
- state: RowSelectionStateObject | RowSelectionState,
127
- getConfig: GetRowSelectionStateConfig<T>,
128
- _forTestingOnly?: RowSelectionStateOverride,
129
- ) {
130
- const stateObject =
131
- state instanceof Object.getPrototypeOf(this).constructor
132
- ? //@ts-ignore
133
- state.getState()
134
- : state;
135
-
136
- this.getConfig = getConfig;
137
-
138
- this.onlyUsePrimaryKeys = getConfig().onlyUsePrimaryKeys;
139
-
140
- if (_forTestingOnly) {
141
- Object.assign(this, _forTestingOnly);
142
- }
143
-
144
- this.update(stateObject);
145
- }
146
- mapSet = (name: 'selected' | 'deselected', key: any | any[]) => {
147
- if (!Array.isArray(key)) {
148
- if (this.onlyUsePrimaryKeys) {
149
- key = [key];
150
- } else {
151
- key = [...this.getGroupKeysForPrimaryKey(key), key];
152
- }
153
- }
154
-
155
- this.xcache();
156
- if (name === 'selected') {
157
- this.selectedMap.set(key, true);
158
- } else {
159
- this.deselectedMap.set(key, true);
160
- }
161
- };
162
- _selectedMapSet = (key: any | any[]) => {
163
- this.mapSet('selected', key);
164
- };
165
- _deselectedMapSet = (key: any | any[]) => {
166
- this.mapSet('deselected', key);
167
- };
168
-
169
- update(stateObject: RowSelectionStateObject) {
170
- this.selectedRows = stateObject.selectedRows || null;
171
- this.deselectedRows = stateObject.deselectedRows || null;
172
-
173
- this.selectedMap.clear();
174
- this.deselectedMap.clear();
175
-
176
- this.selectedRows?.forEach(this._selectedMapSet);
177
- this.deselectedRows?.forEach(this._deselectedMapSet);
178
-
179
- this.defaultSelection = stateObject.defaultSelection;
180
-
181
- this.xcache();
182
- }
183
-
184
- private xcache() {
185
- this.selectionCache.clear();
186
- this.selectionCountCache.clear();
187
-
188
- // //@ts-ignore
189
- // this.selectionCache.get = () => {};
190
- // //@ts-ignore
191
- // this.selectionCountCache.get = () => {};
192
- }
193
-
194
- public getState(): RowSelectionStateObject {
195
- // we have to do the normalization step
196
- // because when we first load the keys, all the values which are not arrays, from selectedRows or deselectedRows,
197
- // we transform them to arrays: eg: [ 45, ['TypeScript']] becomes [['JavaScript',45],['TypeScript']] (where the row with id 45 was in the JavaScript group)
198
- // we do the above in order to make it easier to work with groups and rows
199
- // so now we're doing the opposite transformation
200
- const normalize = (allKeys: any[]) => {
201
- const groupByLength = this.getGroupByLength();
202
- return allKeys.map((keys) => {
203
- if (this.onlyUsePrimaryKeys) {
204
- return keys[0];
205
- }
206
- return keys.length > groupByLength ? keys.pop() : keys;
207
- });
208
- };
209
- const selectedRows = normalize(this.selectedMap.topDownKeys());
210
- const deselectedRows = normalize(this.deselectedMap.topDownKeys());
211
-
212
- return {
213
- defaultSelection: this.defaultSelection,
214
- selectedRows,
215
- deselectedRows,
216
- };
217
- }
218
-
219
- public deselectAll() {
220
- this.update({
221
- defaultSelection: false,
222
- selectedRows: [],
223
- deselectedRows: [],
224
- });
225
- }
226
-
227
- public selectAll() {
228
- this.update({
229
- defaultSelection: true,
230
- deselectedRows: [],
231
- selectedRows: [],
232
- });
233
- }
234
-
235
- public isRowDefaultSelected() {
236
- return this.defaultSelection === true;
237
- }
238
-
239
- public isRowDefaultDeselected() {
240
- return this.defaultSelection === false;
241
- }
242
-
243
- /**
244
- *
245
- * @param key the id of the row - if a row in a grouped datasource, this is the final row id, without the group keys
246
- * @param groupKeys the keys of row parents, in order
247
- * @returns Whether the row is selected or not.
248
- */
249
- public isRowSelected(key: any, groupKeys?: any[]) {
250
- // use the empty arr to avoid lots of new empty array allocations
251
-
252
- if (this.onlyUsePrimaryKeys) {
253
- return this.defaultSelection
254
- ? !this.deselectedMap.has([key])
255
- : this.selectedMap.has([key]);
256
- }
257
-
258
- groupKeys = groupKeys || this.getGroupKeysForPrimaryKey(key);
259
- const finalKey = [...groupKeys, key];
260
-
261
- const cachedResult = this.selectionCache.get(finalKey);
262
-
263
- if (cachedResult !== undefined) {
264
- return cachedResult as boolean;
265
- }
266
-
267
- const inSelected = this.selectedMap.has(finalKey);
268
- const inDeselected = this.deselectedMap.has(finalKey);
269
-
270
- if (inSelected) {
271
- this.selectionCache.set(finalKey, true);
272
- return true;
273
- }
274
-
275
- if (inDeselected) {
276
- this.selectionCache.set(finalKey, false);
277
- return false;
278
- }
279
-
280
- // exact parent groups found in selected
281
- if (this.selectedMap.has(groupKeys)) {
282
- this.selectionCache.set(finalKey, true);
283
- return true;
284
- }
285
- // exact parent groups found in deselected
286
- if (this.deselectedMap.has(groupKeys)) {
287
- this.selectionCache.set(finalKey, false);
288
- return false;
289
- }
290
- // clone the keys so we can mutate
291
- groupKeys = [...groupKeys];
292
-
293
- while (groupKeys.length) {
294
- groupKeys.pop();
295
- const inSelected = this.selectedMap.has(groupKeys);
296
- const inDeselected = this.deselectedMap.has(groupKeys);
297
-
298
- if (inSelected) {
299
- this.selectionCache.set(finalKey, true);
300
- return true;
301
- }
302
- if (inDeselected) {
303
- this.selectionCache.set(finalKey, false);
304
- return false;
305
- }
306
- }
307
-
308
- this.selectionCache.set(finalKey, this.defaultSelection);
309
- return this.defaultSelection;
310
- }
311
-
312
- public isRowDeselected(key: any, groupKeys?: any[]) {
313
- return !this.isRowSelected(key, groupKeys);
314
- }
315
-
316
- public setRowSelected(
317
- key: string | number,
318
- selected: boolean,
319
- groupKeys?: any[],
320
- ) {
321
- if (selected) {
322
- this.setRowAsSelected(key, groupKeys);
323
- } else {
324
- this.setRowAsDeselected(key, groupKeys);
325
- }
326
- }
327
-
328
- /**
329
- * Returns if the selection state ('full','partial','none') for the current group
330
- *
331
- * The selection state will be full (true) if either of those are true:
332
- * * the group keys are specified as selected
333
- * * all the children are specified as selected
334
- *
335
- * The selection state will be partial (null) if either of those are true:
336
- * * the group keys are partially selected
337
- * * some of the children are specified as selected
338
- *
339
- *
340
- * @param groupKeys the keys of the group row
341
- * @param children leaf children that belong to the group
342
- * @returns boolean
343
- */
344
- public getGroupRowSelectionState(initialGroupKeys: any[]): boolean | null {
345
- const cachedResult = this.selectionCache.get(initialGroupKeys);
346
-
347
- if (cachedResult !== undefined) {
348
- return cachedResult as boolean;
349
- }
350
-
351
- const { selectedCount, deselectedCount } = this.getSelectionCountFor(
352
- initialGroupKeys,
353
- this.onlyUsePrimaryKeys
354
- ? // there is no need for the state from the parent group
355
- // when we are in this case, so don't do that
356
- undefined
357
- : this.getGroupRowBooleanSelectionStateFromParent(initialGroupKeys),
358
- );
359
-
360
- const result =
361
- selectedCount && deselectedCount ? null : selectedCount ? true : false;
362
-
363
- this.selectionCache.set(initialGroupKeys, result);
364
-
365
- return result;
366
- }
367
-
368
- private getGroupRowBooleanSelectionStateFromParent(
369
- initialGroupKeys: any[],
370
- ): boolean {
371
- if (!initialGroupKeys.length) {
372
- return this.defaultSelection;
373
- }
374
-
375
- // clone the keys so we can mutate
376
- const groupKeys = [...initialGroupKeys];
377
-
378
- const selfDeselected = this.deselectedMap.has(groupKeys);
379
- const selfSelected = this.selectedMap.has(groupKeys);
380
-
381
- let selectionState: undefined | boolean =
382
- selfSelected && !selfDeselected
383
- ? true
384
- : selfDeselected && !selfSelected
385
- ? false
386
- : undefined;
387
-
388
- if (selectionState === undefined) {
389
- while (groupKeys.length) {
390
- groupKeys.pop();
391
-
392
- if (this.deselectedMap.has(groupKeys)) {
393
- selectionState = false;
394
- break;
395
- }
396
-
397
- if (this.selectedMap.has(groupKeys)) {
398
- selectionState = true;
399
- break;
400
- }
401
- }
402
- }
403
- if (selectionState === undefined) {
404
- selectionState = this.defaultSelection;
405
- }
406
-
407
- return selectionState;
408
- }
409
-
410
- public isGroupRowPartlySelected(groupKeys: any[]) {
411
- return this.getGroupRowSelectionState(groupKeys) === null;
412
- }
413
-
414
- public isGroupRowSelected(groupKeys: any[]) {
415
- return this.getGroupRowSelectionState(groupKeys) === true;
416
- }
417
-
418
- public isGroupRowDeselected(groupKeys: any[]) {
419
- return this.getGroupRowSelectionState(groupKeys) === false;
420
- }
421
-
422
- public selectGroupRow(groupKeys: any[]) {
423
- if (this.onlyUsePrimaryKeys) {
424
- const keys = this.getAllPrimaryKeysInsideGroup(groupKeys);
425
-
426
- keys.forEach((key) => {
427
- if (this.defaultSelection === true) {
428
- this.deselectedMap.delete([key]);
429
- } else {
430
- this._selectedMapSet(key);
431
- }
432
- });
433
- this.xcache();
434
- return;
435
- }
436
- // retrieve any selection under this group
437
- const selectedKeys = this.selectedMap.getKeysStartingWith(groupKeys, true);
438
-
439
- // and clean it up
440
- selectedKeys.forEach((groupKeys) => {
441
- this.selectedMap.delete(groupKeys);
442
- });
443
-
444
- // finally make sure this selection is set
445
- // so set it explicitly in the selection map
446
- if (groupKeys.length === 1 && this.defaultSelection === true) {
447
- // this is top level, but default selection is the same
448
- // so we can skip putting it in the map
449
- } else {
450
- this._selectedMapSet(groupKeys);
451
- }
452
-
453
- // delete it from deselection map in case it's there
454
- const deselectedKeys = this.deselectedMap.getKeysStartingWith(groupKeys);
455
-
456
- deselectedKeys.forEach((groupKeys) => {
457
- this.deselectedMap.delete(groupKeys);
458
- });
459
- }
460
-
461
- public deselectGroupRow(groupKeys: any[]) {
462
- if (this.onlyUsePrimaryKeys) {
463
- const keys = this.getAllPrimaryKeysInsideGroup(groupKeys);
464
-
465
- keys.forEach((key) => {
466
- if (this.defaultSelection === false) {
467
- this.selectedMap.delete([key]);
468
- } else {
469
- this._deselectedMapSet(key);
470
- }
471
- });
472
- this.xcache();
473
- return;
474
- }
475
- // retrieve any deselection under this group
476
- const deselectedKeys = this.deselectedMap.getKeysStartingWith(
477
- groupKeys,
478
- true,
479
- );
480
-
481
- // and clean it up
482
- deselectedKeys.forEach((groupKeys) => {
483
- this.deselectedMap.delete(groupKeys);
484
- });
485
-
486
- // finally make sure this deselection is set
487
- // so set it explicitly in the deselection map
488
- if (groupKeys.length === 1 && this.defaultSelection === false) {
489
- } else {
490
- this._deselectedMapSet(groupKeys);
491
- }
492
-
493
- // delete it from selection map in case it's there
494
- const selectedKeys = this.selectedMap.getKeysStartingWith(groupKeys);
495
-
496
- selectedKeys.forEach((groupKeys) => {
497
- this.selectedMap.delete(groupKeys);
498
- });
499
- }
500
-
501
- public setRowAsSelected(key: string | number, groupKeys?: any[]) {
502
- if (this.onlyUsePrimaryKeys) {
503
- if (this.defaultSelection) {
504
- // all selected by default, so to make it selected
505
- // we need to remove it from deselected map
506
- this.deselectedMap.delete([key]);
507
- } else {
508
- // all deselected by default, so we have to explicitly mention it in the selection map
509
- this._selectedMapSet(key);
510
- }
511
-
512
- this.xcache();
513
- return;
514
- }
515
-
516
- groupKeys = groupKeys || this.getGroupKeysForPrimaryKey(key);
517
-
518
- const finalKey = [...groupKeys, key];
519
-
520
- // delete it from deselection map
521
-
522
- this.deselectedMap.delete(finalKey);
523
- this.xcache();
524
-
525
- // if the direct parent is not selected
526
- if (this.getGroupRowSelectionState(groupKeys) !== true) {
527
- // then set it in selection map
528
- this._selectedMapSet(finalKey);
529
- // otherwise was probably enough to just delete it from deselection map
530
-
531
- // probably all children are now selected, so worth selecting the group explicitly
532
- if (this.getGroupRowSelectionState(groupKeys) === true) {
533
- this.selectGroupRow(groupKeys);
534
- }
535
- }
536
- }
537
-
538
- public setRowAsDeselected(key: string | number, groupKeys?: any[]) {
539
- if (this.onlyUsePrimaryKeys) {
540
- if (this.defaultSelection) {
541
- // all selected by default,
542
- // so we have to explicitly mention this in the deselectedMap
543
- this._deselectedMapSet(key);
544
- } else {
545
- // all deselected by default
546
- // so remove it from selected map
547
- this.selectedMap.delete([key]);
548
- }
549
-
550
- this.xcache();
551
- return;
552
- }
553
-
554
- groupKeys = groupKeys || this.getGroupKeysForPrimaryKey(key);
555
- const finalKey = [...groupKeys, key];
556
-
557
- this.selectedMap.delete(finalKey);
558
- this.xcache();
559
-
560
- // if the group is not fully deselected, also mark this row as deselected
561
- if (this.getGroupRowSelectionState(groupKeys) !== false) {
562
- this._deselectedMapSet(finalKey);
563
-
564
- // probably all children are now deselected, so worth deselecting the group explicitly
565
- if (this.getGroupRowSelectionState(groupKeys) === false) {
566
- this.deselectGroupRow(groupKeys);
567
- }
568
- }
569
- }
570
-
571
- public deselectRow(key: any, groupKeys?: any[]) {
572
- this.setRowSelected(key, false, groupKeys);
573
- }
574
-
575
- public selectRow(key: any, groupKeys?: any[]) {
576
- this.setRowSelected(key, true, groupKeys);
577
- }
578
-
579
- public toggleGroupRowSelection(groupKeys: any[]) {
580
- const groupRowSelectionState = this.getGroupRowSelectionState(groupKeys);
581
-
582
- if (groupRowSelectionState === true) {
583
- this.deselectGroupRow(groupKeys);
584
- } else {
585
- this.selectGroupRow(groupKeys);
586
- }
587
- }
588
-
589
- public toggleRowSelection(
590
- key: string | number,
591
- groupKeys?: any[] | undefined,
592
- ) {
593
- if (this.isRowSelected(key, groupKeys)) {
594
- this.deselectRow(key, groupKeys);
595
- } else {
596
- this.selectRow(key, groupKeys);
597
- }
598
- }
599
-
600
- public getSelectedCount() {
601
- return this.getSelectionCountFor([]).selectedCount;
602
- }
603
-
604
- public getDeselectedCount() {
605
- return this.getSelectionCountFor([]).deselectedCount;
606
- }
607
-
608
- public getSelectionCountFor(groupKeys: any[] = [], parentSelected?: boolean) {
609
- const cachedResult = this.selectionCountCache.get(groupKeys);
610
-
611
- if (cachedResult != null) {
612
- return cachedResult;
613
- }
614
-
615
- const groupByLength = this.getGroupByLength();
616
- if (groupKeys.length > groupByLength) {
617
- const result = this.isRowSelected(groupKeys)
618
- ? { selectedCount: 1, deselectedCount: 0 }
619
- : {
620
- selectedCount: 0,
621
- deselectedCount: 1,
622
- };
623
-
624
- this.selectionCountCache.set(groupKeys, result);
625
- return result;
626
- }
627
-
628
- if (groupByLength && this.onlyUsePrimaryKeys) {
629
- const allKeys = this.getAllPrimaryKeysInsideGroup(groupKeys);
630
-
631
- let selectedCount = 0;
632
- let deselectedCount = 0;
633
-
634
- allKeys.forEach((key) => {
635
- if (this.defaultSelection) {
636
- // by default all are selected
637
-
638
- if (this.deselectedMap.has([key])) {
639
- // so count it as deselected if it's in the deselection map
640
- deselectedCount++;
641
- return;
642
- }
643
- selectedCount++;
644
- } else {
645
- // by default all are deselected
646
- if (this.selectedMap.has([key])) {
647
- selectedCount++;
648
- return;
649
- }
650
- deselectedCount++;
651
- }
652
- });
653
-
654
- const result = {
655
- selectedCount,
656
- deselectedCount,
657
- };
658
-
659
- this.selectionCountCache.set(groupKeys, result);
660
-
661
- return result;
662
- }
663
-
664
- parentSelected =
665
- parentSelected ??
666
- this.getGroupRowBooleanSelectionStateFromParent(groupKeys);
667
-
668
- let allKeys = this.getGroupKeysDirectlyInsideGroup(groupKeys);
669
-
670
- // if (!allKeys.length) {
671
- if (groupKeys.length === this.getGroupByLength()) {
672
- // this is the last level of grouping, with no other group keys (in the groupDeepMap) under this level
673
-
674
- // we need to compute the selection state
675
- const selectionState = this.selectedMap.has(groupKeys)
676
- ? true
677
- : this.deselectedMap.has(groupKeys)
678
- ? false
679
- : parentSelected;
680
-
681
- const totalCount = this.getGroupCount(groupKeys);
682
-
683
- //explicitly selected rows
684
- let selectedCount = this.selectedMap.getKeysStartingWith(
685
- groupKeys,
686
- true,
687
- 1,
688
- ).length;
689
-
690
- // explicitly deselected rows
691
- let deselectedCount = this.deselectedMap.getKeysStartingWith(
692
- groupKeys,
693
- true,
694
- 1,
695
- ).length;
696
-
697
- const notSpecifiedCount = totalCount - (selectedCount + deselectedCount);
698
-
699
- const result = {
700
- selectedCount: selectedCount + (selectionState ? notSpecifiedCount : 0),
701
- deselectedCount:
702
- deselectedCount + (selectionState ? 0 : notSpecifiedCount),
703
- };
704
-
705
- this.selectionCountCache.set(groupKeys, result);
706
-
707
- return result;
708
- }
709
-
710
- let selectedCount = 0;
711
- let deselectedCount = 0;
712
-
713
- if (this.getConfig().lazyLoad && !allKeys.length) {
714
- // no loaded rows under this group
715
- // so we need to somehow guess the selection
716
- const totalChildrenCount =
717
- this.getConfig().groupDeepMap?.get(groupKeys)?.totalChildrenCount || 0;
718
-
719
- if (parentSelected) {
720
- selectedCount = totalChildrenCount;
721
- // the deselection count might contain groups as well (with more than 1 row)
722
- // but here we count everything as a leaf row (so a value of 1)
723
- // which will be enough to render the selection checkbox in the correct state
724
- deselectedCount = this.deselectedMap.getAllChildrenSizeFor(groupKeys);
725
- if (deselectedCount === totalChildrenCount) {
726
- selectedCount = 0;
727
- }
728
- } else {
729
- deselectedCount = totalChildrenCount;
730
- // same as above, the selection count might contain ....
731
- selectedCount = this.selectedMap.getAllChildrenSizeFor(groupKeys);
732
- if (selectedCount === totalChildrenCount) {
733
- deselectedCount = 0;
734
- }
735
- }
736
- }
737
- allKeys.forEach((keys) => {
738
- let isSelected = this.selectedMap.get(keys);
739
- let isDeselected = this.deselectedMap.get(keys);
740
-
741
- const selected = isSelected
742
- ? true
743
- : isDeselected
744
- ? false
745
- : parentSelected;
746
-
747
- const { selectedCount: selCount, deselectedCount: deselCount } =
748
- this.getSelectionCountFor(keys, selected);
749
-
750
- selectedCount += selCount;
751
- deselectedCount += deselCount;
752
- });
753
-
754
- const result = {
755
- selectedCount,
756
- deselectedCount,
757
- };
758
-
759
- this.selectionCountCache.set(groupKeys, result);
760
-
761
- return result;
762
- }
763
- }