@infinite-table/infinite-react 0.4.12 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.vscode/settings.json +3 -0
- package/API.md +0 -0
- package/build/buildPackageJson.js +43 -0
- package/build/scripts/test.js +37 -0
- package/bundler.config.js +25 -0
- package/globals.d.ts +7 -0
- package/package.json +95 -3
- package/rollup.config.js +15 -0
- package/run-build-deepmap.js +47 -0
- package/run-build.js +45 -0
- package/run-dts-concat.js +21 -0
- package/src/components/CSSVariableWatch.tsx +82 -0
- package/src/components/DataSource/BooleanCollectionState.ts +214 -0
- package/src/components/DataSource/BooleanDeepCollectionState.ts +208 -0
- package/src/components/DataSource/DataSourceContext.ts +20 -0
- package/src/components/DataSource/GroupRowsState.ts +74 -0
- package/src/components/DataSource/Indexer.ts +27 -0
- package/src/components/DataSource/RowSelectionState.ts +763 -0
- package/src/components/DataSource/defaultFilterTypes.ts +64 -0
- package/src/components/DataSource/index.tsx +108 -0
- package/src/components/DataSource/privateHooks/getChangeDetect.ts +7 -0
- package/src/components/DataSource/privateHooks/useLoadData.ts +783 -0
- package/src/components/DataSource/publicHooks/useDataSource.ts +19 -0
- package/src/components/DataSource/publicHooks/useDataSourceActions.ts +14 -0
- package/src/components/DataSource/state/getInitialState.ts +494 -0
- package/src/components/DataSource/state/normalizeSortInfo.ts +35 -0
- package/src/components/DataSource/state/reducer.ts +466 -0
- package/src/components/DataSource/state/rowInfoStatus.ts +27 -0
- package/src/components/DataSource/types.ts +548 -0
- package/src/components/HeadlessTable/HeadlessTableWithPinnedContainers.tsx +142 -0
- package/src/components/HeadlessTable/MappedCells.ts +251 -0
- package/src/components/HeadlessTable/RawTable.tsx +98 -0
- package/src/components/HeadlessTable/ReactHeadlessTableRenderer.tsx +1516 -0
- package/src/components/HeadlessTable/index.tsx +234 -0
- package/src/components/InfiniteTable/InfiniteCls.css.ts +164 -0
- package/src/components/InfiniteTable/InfiniteTableContext.ts +16 -0
- package/src/components/InfiniteTable/api/getImperativeApi.ts +391 -0
- package/src/components/InfiniteTable/api/getSelectionApi.ts +364 -0
- package/src/components/InfiniteTable/api/type.ts +11 -0
- package/src/components/InfiniteTable/components/ActiveCellIndicator.css.ts +51 -0
- package/src/components/InfiniteTable/components/ActiveCellIndicator.tsx +116 -0
- package/src/components/InfiniteTable/components/ActiveRowIndicator.css.ts +56 -0
- package/src/components/InfiniteTable/components/ActiveRowIndicator.tsx +94 -0
- package/src/components/InfiniteTable/components/CheckBox.css.ts +13 -0
- package/src/components/InfiniteTable/components/CheckBox.tsx +96 -0
- package/src/components/InfiniteTable/components/FilterEditors.tsx +52 -0
- package/src/components/InfiniteTable/components/InfiniteTableBody/InfiniteTableBody.tsx +27 -0
- package/src/components/InfiniteTable/components/InfiniteTableBody/index.tsx +1 -0
- package/src/components/InfiniteTable/components/InfiniteTableFooter/InfiniteTableFooter.tsx +31 -0
- package/src/components/InfiniteTable/components/InfiniteTableFooter/index.tsx +1 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/InfiniteTableColumnHeaderFilter.tsx +102 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/InfiniteTableHeader.tsx +163 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/InfiniteTableHeaderCell.tsx +574 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/InfiniteTableHeaderGroup.tsx +79 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/InfiniteTableHeaderTypes.tsx +25 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/InfiniteTableHeaderWrapper.tsx +185 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/ResizeHandle/GroupResizeHandle.tsx +159 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/ResizeHandle/ResizeHandle.css.ts +124 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/ResizeHandle/columnResizer.ts +166 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/ResizeHandle/index.tsx +146 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/buildColumnAndGroupTree.ts +240 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/header.css.ts +358 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/index.tsx +1 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/useColumnGroupResizeHandle.tsx +114 -0
- package/src/components/InfiniteTable/components/InfiniteTableHeader/useColumnResizeHandle.tsx +146 -0
- package/src/components/InfiniteTable/components/InfiniteTableLicenseFooter/footer.css.ts +7 -0
- package/src/components/InfiniteTable/components/InfiniteTableLicenseFooter/index.tsx +110 -0
- package/src/components/InfiniteTable/components/InfiniteTableRow/InfiniteTableCell.tsx +120 -0
- package/src/components/InfiniteTable/components/InfiniteTableRow/InfiniteTableCellTypes.ts +74 -0
- package/src/components/InfiniteTable/components/InfiniteTableRow/InfiniteTableColumnCell.tsx +457 -0
- package/src/components/InfiniteTable/components/InfiniteTableRow/InfiniteTableRow.tsx +107 -0
- package/src/components/InfiniteTable/components/InfiniteTableRow/InfiniteTableRowClassName.ts +6 -0
- package/src/components/InfiniteTable/components/InfiniteTableRow/InfiniteTableRowTypes.ts +32 -0
- package/src/components/InfiniteTable/components/InfiniteTableRow/InfiniteTableRowUnvirtualized.tsx +75 -0
- package/src/components/InfiniteTable/components/InfiniteTableRow/columnRendering.tsx +263 -0
- package/src/components/InfiniteTable/components/InfiniteTableRow/index.tsx +1 -0
- package/src/components/InfiniteTable/components/InfiniteTableRow/row.css.ts +74 -0
- package/src/components/InfiniteTable/components/InfiniteTableRow/useRowDOMProps.ts +199 -0
- package/src/components/InfiniteTable/components/LoadMask.css.ts +34 -0
- package/src/components/InfiniteTable/components/LoadMask.tsx +27 -0
- package/src/components/InfiniteTable/components/ScrollbarPlaceholder.tsx +56 -0
- package/src/components/InfiniteTable/components/cell.css.ts +192 -0
- package/src/components/InfiniteTable/components/icons/ArrowDown.tsx +14 -0
- package/src/components/InfiniteTable/components/icons/ArrowUp.tsx +14 -0
- package/src/components/InfiniteTable/components/icons/ExpanderIcon.css.ts +31 -0
- package/src/components/InfiniteTable/components/icons/ExpanderIcon.tsx +63 -0
- package/src/components/InfiniteTable/components/icons/Icon.tsx +18 -0
- package/src/components/InfiniteTable/components/icons/InfiniteTableIconClassName.ts +1 -0
- package/src/components/InfiniteTable/components/icons/LoadingIcon.css.ts +8 -0
- package/src/components/InfiniteTable/components/icons/LoadingIcon.tsx +45 -0
- package/src/components/InfiniteTable/components/icons/MenuIcon.tsx +50 -0
- package/src/components/InfiniteTable/components/icons/SortIcon.tsx +113 -0
- package/src/components/InfiniteTable/eventHandlers/eventHandlerTypes.ts +57 -0
- package/src/components/InfiniteTable/eventHandlers/index.ts +95 -0
- package/src/components/InfiniteTable/eventHandlers/keyboardNavigation.ts +232 -0
- package/src/components/InfiniteTable/eventHandlers/keyboardSelection.ts +110 -0
- package/src/components/InfiniteTable/eventHandlers/onCellClick.ts +94 -0
- package/src/components/InfiniteTable/eventHandlers/onKeyDown.ts +25 -0
- package/src/components/InfiniteTable/hooks/adjustColumnOrderForAllColumns.ts +70 -0
- package/src/components/InfiniteTable/hooks/reorderColumnsOnDrag.ts +476 -0
- package/src/components/InfiniteTable/hooks/useAutoSizeColumns.ts +206 -0
- package/src/components/InfiniteTable/hooks/useCellClassName.ts +80 -0
- package/src/components/InfiniteTable/hooks/useCellRendering.tsx +217 -0
- package/src/components/InfiniteTable/hooks/useColumnGroups.ts +71 -0
- package/src/components/InfiniteTable/hooks/useColumnMenu.ts +72 -0
- package/src/components/InfiniteTable/hooks/useColumnPointerEvents.ts +258 -0
- package/src/components/InfiniteTable/hooks/useColumnRowspan.ts +43 -0
- package/src/components/InfiniteTable/hooks/useColumnSizeFn.ts +24 -0
- package/src/components/InfiniteTable/hooks/useColumnsWhen.ts +582 -0
- package/src/components/InfiniteTable/hooks/useComputed.ts +186 -0
- package/src/components/InfiniteTable/hooks/useComputedVisibleColumns.ts +219 -0
- package/src/components/InfiniteTable/hooks/useDOMProps.ts +306 -0
- package/src/components/InfiniteTable/hooks/useEffectWithRaf.ts +47 -0
- package/src/components/InfiniteTable/hooks/useInfiniteTable.ts +10 -0
- package/src/components/InfiniteTable/hooks/useInfiniteTableState.ts +11 -0
- package/src/components/InfiniteTable/hooks/useInternalProps.ts +8 -0
- package/src/components/InfiniteTable/hooks/useLicense/LicenseDetails.ts +13 -0
- package/src/components/InfiniteTable/hooks/useLicense/crc32.ts +56 -0
- package/src/components/InfiniteTable/hooks/useLicense/decode.ts +147 -0
- package/src/components/InfiniteTable/hooks/useLicense/useLicense.ts +39 -0
- package/src/components/InfiniteTable/hooks/useRerenderOnKeyChange.ts +21 -0
- package/src/components/InfiniteTable/hooks/useRowHover.ts +18 -0
- package/src/components/InfiniteTable/hooks/useScrollToActiveCell.ts +48 -0
- package/src/components/InfiniteTable/hooks/useScrollToActiveRow.ts +44 -0
- package/src/components/InfiniteTable/hooks/useScrollbars.ts +51 -0
- package/src/components/InfiniteTable/hooks/useToggleGroupRow.ts +56 -0
- package/src/components/InfiniteTable/hooks/useUnpinnedRendering.tsx +165 -0
- package/src/components/InfiniteTable/hooks/useYourBrain.ts +55 -0
- package/src/components/InfiniteTable/index.tsx +352 -0
- package/src/components/InfiniteTable/internalProps.ts +4 -0
- package/src/components/InfiniteTable/state/computeColumnGroupsDepths.ts +29 -0
- package/src/components/InfiniteTable/state/getColumnVisibilityForHideEmptyGroupColumns.ts +127 -0
- package/src/components/InfiniteTable/state/getInitialState.ts +375 -0
- package/src/components/InfiniteTable/theme.css.ts +556 -0
- package/src/components/InfiniteTable/types/InfiniteTableAction.ts +6 -0
- package/src/components/InfiniteTable/types/InfiniteTableActionType.ts +12 -0
- package/src/components/InfiniteTable/types/InfiniteTableColumn.ts +478 -0
- package/src/components/InfiniteTable/types/InfiniteTableComputedValues.ts +43 -0
- package/src/components/InfiniteTable/types/InfiniteTableContextValue.ts +12 -0
- package/src/components/InfiniteTable/types/InfiniteTableInternalProps.ts +3 -0
- package/src/components/InfiniteTable/types/InfiniteTableProps.ts +511 -0
- package/src/components/InfiniteTable/types/InfiniteTableState.ts +195 -0
- package/src/components/InfiniteTable/types/Utility.ts +35 -0
- package/src/components/InfiniteTable/types/index.ts +96 -0
- package/src/components/InfiniteTable/utilities.css.ts +179 -0
- package/src/components/InfiniteTable/utils/MultiRowSelector.ts +111 -0
- package/src/components/InfiniteTable/utils/RenderHookComponentForInfinite.tsx +52 -0
- package/src/components/InfiniteTable/utils/adjustColumnOrderForPinning.ts +33 -0
- package/src/components/InfiniteTable/utils/assignFiltered.ts +29 -0
- package/src/components/InfiniteTable/utils/defaultGetColumContextMenuItems.tsx +108 -0
- package/src/components/InfiniteTable/utils/getColumnComputedType.ts +33 -0
- package/src/components/InfiniteTable/utils/getColumnForGroupBy.tsx +313 -0
- package/src/components/InfiniteTable/utils/getComputedVisibleColumns.ts +773 -0
- package/src/components/InfiniteTable/utils/getContextMenuForColumn.tsx +72 -0
- package/src/components/InfiniteTable/utils/infiniteDOMUtils.ts +189 -0
- package/src/components/InfiniteTable/utils/mapToObject.ts +20 -0
- package/src/components/InfiniteTable/utils/moveXatY.ts +25 -0
- package/src/components/InfiniteTable/utils/objectValuesExcept.ts +9 -0
- package/src/components/InfiniteTable/utils/progressiveSpeedScroller.ts +158 -0
- package/src/components/InfiniteTable/utils/rafFn.ts +13 -0
- package/src/components/InfiniteTable/utils/toCSSVarName.ts +1 -0
- package/src/components/InfiniteTable/utils/toMap.ts +24 -0
- package/src/components/Menu/Menu.tsx +750 -0
- package/src/components/Menu/MenuCls.css.ts +139 -0
- package/src/components/Menu/MenuContext.ts +10 -0
- package/src/components/Menu/MenuContextValue.ts +15 -0
- package/src/components/Menu/MenuProps.ts +98 -0
- package/src/components/Menu/MenuState.ts +56 -0
- package/src/components/Menu/MenuTriangleContext.ts +352 -0
- package/src/components/Menu/childrenToRuntimeItems.tsx +103 -0
- package/src/components/Menu/getMenuState.tsx +119 -0
- package/src/components/Menu/index.tsx +88 -0
- package/src/components/Menu/propToIdentifyMenu.ts +1 -0
- package/src/components/RawList/AvoidReactDiff.tsx +48 -0
- package/src/components/RawList/MappedItems.ts +143 -0
- package/src/components/RawList/ReactVirtualRenderer.tsx +307 -0
- package/src/components/RawList/index.tsx +42 -0
- package/src/components/RawList/types.ts +23 -0
- package/src/components/RawList/useVirtualRenderer.ts +36 -0
- package/src/components/RenderHookComponent.tsx +10 -0
- package/src/components/ResizeObserver/index.tsx +170 -0
- package/src/components/VirtualBrain/MatrixBrain.ts +1621 -0
- package/src/components/VirtualBrain/ScrollListener.ts +39 -0
- package/src/components/VirtualBrain/index.ts +664 -0
- package/src/components/VirtualList/ColumnListWithExternalScrolling.tsx +78 -0
- package/src/components/VirtualList/InfiniteListRootClassName.ts +1 -0
- package/src/components/VirtualList/RowListWithExternalScrolling.tsx +120 -0
- package/src/components/VirtualList/SpacePlaceholder.tsx +32 -0
- package/src/components/VirtualList/VirtualList.css.ts +29 -0
- package/src/components/VirtualList/VirtualList.tsx +141 -0
- package/src/components/VirtualList/VirtualRowList.tsx +34 -0
- package/src/components/VirtualList/types.ts +56 -0
- package/src/components/VirtualList/useCorrectHeightForRowElements.ts +14 -0
- package/src/components/VirtualScrollContainer/VirtualScrollContainer.css.ts +51 -0
- package/src/components/VirtualScrollContainer/getScrollableClassName.ts +30 -0
- package/src/components/VirtualScrollContainer/index.tsx +63 -0
- package/src/components/flexbox/index.ts +562 -0
- package/src/components/hooks/useComponentState/index.tsx +562 -0
- package/src/components/hooks/useComponentState/types.ts +32 -0
- package/src/components/hooks/useEffectOnceWithProperUnmount.ts +33 -0
- package/src/components/hooks/useEffectWithChanges.ts +56 -0
- package/src/components/hooks/useImmutableRef.ts +7 -0
- package/src/components/hooks/useInterceptedMap.ts +71 -0
- package/src/components/hooks/useLatest.tsx +8 -0
- package/src/components/hooks/useLazyLatest.ts +23 -0
- package/src/components/hooks/useMemoShallowObjectMerge.ts +16 -0
- package/src/components/hooks/useMounted.ts +18 -0
- package/src/components/hooks/useOnMount.ts +21 -0
- package/src/components/hooks/useOnScroll.ts +34 -0
- package/src/components/hooks/useOnce.ts +10 -0
- package/src/components/hooks/useOverlay/index.tsx +418 -0
- package/src/components/hooks/usePrevious.ts +8 -0
- package/src/components/hooks/usePropertyOld.ts +168 -0
- package/src/components/hooks/useRerender.ts +12 -0
- package/src/components/hooks/xuseProperty.ts +165 -0
- package/src/components/types/CellPosition.ts +4 -0
- package/src/components/types/NonUndefined.ts +1 -0
- package/src/components/types/RemoveObject.ts +22 -0
- package/src/components/types/Renderable.ts +3 -0
- package/src/components/types/ScrollPosition.ts +7 -0
- package/src/components/types/Setter.ts +2 -0
- package/src/components/types/Size.ts +6 -0
- package/src/components/types/SubscriptionCallback.ts +10 -0
- package/src/components/types/VoidFn.ts +1 -0
- package/src/components/utils/buildSubscriptionCallback.tsx +60 -0
- package/src/components/utils/clamp.ts +3 -0
- package/src/components/utils/debounce.ts +16 -0
- package/src/components/utils/decamelize.ts +11 -0
- package/src/components/utils/discardCallsWithEqualArg.ts +42 -0
- package/src/components/utils/getRenderIndexes.ts +33 -0
- package/src/components/utils/getScrollbarWidth.ts +31 -0
- package/src/components/utils/getVirtualRenderCount.ts +21 -0
- package/src/components/utils/isControlled.ts +12 -0
- package/src/components/utils/isControlledValue.ts +5 -0
- package/src/index.tsx +34 -0
- package/src/test.tsx +18 -0
- package/src/utils/DeepMap/index.ts +588 -0
- package/src/utils/DeepMap/once.ts +16 -0
- package/src/utils/DeepMap/sortAscending.ts +1 -0
- package/src/utils/DeepMap/tsconfig.deepmap.json +17 -0
- package/src/utils/DeepMap/xpackage.json +26 -0
- package/src/utils/debug.ts +40 -0
- package/src/utils/deepClone.ts +38 -0
- package/src/utils/getGlobal.ts +3 -0
- package/src/utils/groupAndPivot/defaultToKey.ts +3 -0
- package/src/utils/groupAndPivot/getGroupKeysForDataItem.ts +19 -0
- package/src/utils/groupAndPivot/getPivotColumnsAndColumnGroups.ts +361 -0
- package/src/utils/groupAndPivot/index.ts +1229 -0
- package/src/utils/groupAndPivot/types.ts +10 -0
- package/src/utils/join.ts +4 -0
- package/src/utils/mathIntersection.ts +21 -0
- package/src/utils/minified.d.ts +2 -0
- package/src/utils/minified.js +6 -0
- package/src/utils/multisort/index.ts +151 -0
- package/src/utils/multisort/sortTypes.ts +25 -0
- package/src/utils/notes-status.md +92 -0
- package/src/utils/pageGeometry/ConvexPoly.ts +34 -0
- package/src/utils/pageGeometry/Point.ts +51 -0
- package/src/utils/pageGeometry/PolyWithPoints.ts +52 -0
- package/src/utils/pageGeometry/Rectangle.ts +98 -0
- package/src/utils/pageGeometry/Triangle.ts +16 -0
- package/src/utils/pageGeometry/alignment/index.ts +221 -0
- package/src/utils/pageGeometry/polyContainsPoint.ts +182 -0
- package/src/utils/pageGeometry/types.ts +3 -0
- package/src/utils/proxyFnCall.ts +46 -0
- package/src/utils/raf.ts +13 -0
- package/src/utils/selectParent.ts +18 -0
- package/src/utils/shallowEqualObjects.ts +49 -0
- package/src/utils/stripVar.ts +3 -0
- package/src/utils/toUpperFirst.ts +5 -0
- package/todo.md +2 -0
- package/tsconfig.build.json +8 -0
- package/tsconfig.dev.json +7 -0
- package/tsconfig.json +30 -0
- package/tsconfig.typebundler.json +13 -0
- package/typedoc.json +4 -0
- package/README.md +0 -104
- package/index.css +0 -857
- package/index.d.ts +0 -2111
- package/index.esm.css +0 -857
- package/index.esm.js +0 -13689
- package/index.js +0 -13560
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
import { DataSourceContextValue } from '../types';
|
|
4
|
+
|
|
5
|
+
import { getDataSourceContext } from '../DataSourceContext';
|
|
6
|
+
import { DataSourceState } from '..';
|
|
7
|
+
|
|
8
|
+
export function useDataSource<T>(): DataSourceState<T> {
|
|
9
|
+
const DataSourceContext = getDataSourceContext<T>();
|
|
10
|
+
const contextValue = React.useContext(DataSourceContext);
|
|
11
|
+
|
|
12
|
+
return contextValue.componentState;
|
|
13
|
+
}
|
|
14
|
+
export function useDataSourceContextValue<T>(): DataSourceContextValue<T> {
|
|
15
|
+
const DataSourceContext = getDataSourceContext<T>();
|
|
16
|
+
const contextValue = React.useContext(DataSourceContext);
|
|
17
|
+
|
|
18
|
+
return contextValue;
|
|
19
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import * as React from 'react';
|
|
2
|
+
|
|
3
|
+
import { DataSourceComponentActions } from '../types';
|
|
4
|
+
|
|
5
|
+
import { getDataSourceContext } from '../DataSourceContext';
|
|
6
|
+
|
|
7
|
+
export default function useDataSourceActions<
|
|
8
|
+
T,
|
|
9
|
+
>(): DataSourceComponentActions<T> {
|
|
10
|
+
const DataSourceContext = getDataSourceContext<T>();
|
|
11
|
+
const contextValue = React.useContext(DataSourceContext);
|
|
12
|
+
|
|
13
|
+
return contextValue.componentActions;
|
|
14
|
+
}
|
|
@@ -0,0 +1,494 @@
|
|
|
1
|
+
import {
|
|
2
|
+
DataSourceComponentActions,
|
|
3
|
+
DataSourceDataParams,
|
|
4
|
+
RowSelectionState,
|
|
5
|
+
} from '..';
|
|
6
|
+
import { dbg } from '../../../utils/debug';
|
|
7
|
+
import { DeepMap } from '../../../utils/DeepMap';
|
|
8
|
+
import defaultSortTypes from '../../../utils/multisort/sortTypes';
|
|
9
|
+
import { raf } from '../../../utils/raf';
|
|
10
|
+
import { shallowEqualObjects } from '../../../utils/shallowEqualObjects';
|
|
11
|
+
import { ForwardPropsToStateFnResult } from '../../hooks/useComponentState';
|
|
12
|
+
import { ComponentInterceptedActions } from '../../hooks/useComponentState/types';
|
|
13
|
+
import { InfiniteTableRowInfo, Scrollbars } from '../../InfiniteTable';
|
|
14
|
+
import { rowSelectionStateConfigGetter } from '../../InfiniteTable/api/getSelectionApi';
|
|
15
|
+
import { ScrollStopInfo } from '../../InfiniteTable/types/InfiniteTableProps';
|
|
16
|
+
import { buildSubscriptionCallback } from '../../utils/buildSubscriptionCallback';
|
|
17
|
+
import { discardCallsWithEqualArg } from '../../utils/discardCallsWithEqualArg';
|
|
18
|
+
import { isControlledValue } from '../../utils/isControlledValue';
|
|
19
|
+
import { RenderRange } from '../../VirtualBrain';
|
|
20
|
+
import { defaultFilterTypes } from '../defaultFilterTypes';
|
|
21
|
+
import { GroupRowsState } from '../GroupRowsState';
|
|
22
|
+
import { Indexer } from '../Indexer';
|
|
23
|
+
import { buildDataSourceDataParams } from '../privateHooks/useLoadData';
|
|
24
|
+
import { RowSelectionStateObject } from '../RowSelectionState';
|
|
25
|
+
import {
|
|
26
|
+
DataSourceMappedState,
|
|
27
|
+
DataSourceProps,
|
|
28
|
+
DataSourceDerivedState,
|
|
29
|
+
DataSourceSetupState,
|
|
30
|
+
DataSourceState,
|
|
31
|
+
LazyGroupDataDeepMap,
|
|
32
|
+
LazyRowInfoGroup,
|
|
33
|
+
DataSourceFilterOperator,
|
|
34
|
+
DataSourcePropOnRowSelectionChange_MultiRow,
|
|
35
|
+
DataSourcePropOnRowSelectionChange_SingleRow,
|
|
36
|
+
DataSourcePropSelectionMode,
|
|
37
|
+
} from '../types';
|
|
38
|
+
|
|
39
|
+
import { normalizeSortInfo } from './normalizeSortInfo';
|
|
40
|
+
|
|
41
|
+
export const defaultCursorId = Symbol('cursorId');
|
|
42
|
+
|
|
43
|
+
export function initSetupState<T>(): DataSourceSetupState<T> {
|
|
44
|
+
const now = Date.now();
|
|
45
|
+
const originalDataArray: T[] = [];
|
|
46
|
+
const dataArray: InfiniteTableRowInfo<T>[] = [];
|
|
47
|
+
|
|
48
|
+
const originalLazyGroupData: LazyGroupDataDeepMap<T> = new DeepMap<
|
|
49
|
+
string,
|
|
50
|
+
LazyRowInfoGroup<T>
|
|
51
|
+
>();
|
|
52
|
+
|
|
53
|
+
return {
|
|
54
|
+
// TODO cleanup indexer on unmount
|
|
55
|
+
indexer: new Indexer<T, any>(),
|
|
56
|
+
lazyLoadCacheOfLoadedBatches: new DeepMap<string, true>(),
|
|
57
|
+
dataParams: undefined,
|
|
58
|
+
notifyScrollbarsChange: buildSubscriptionCallback<Scrollbars>(),
|
|
59
|
+
notifyScrollStop: buildSubscriptionCallback<ScrollStopInfo>(),
|
|
60
|
+
notifyRenderRangeChange: buildSubscriptionCallback<RenderRange>(),
|
|
61
|
+
pivotTotalColumnPosition: 'end',
|
|
62
|
+
pivotGrandTotalColumnPosition: false,
|
|
63
|
+
scrollStopDelayUpdatedByTable: 100,
|
|
64
|
+
originalLazyGroupData,
|
|
65
|
+
originalLazyGroupDataChangeDetect: 0,
|
|
66
|
+
originalDataArray,
|
|
67
|
+
cursorId: defaultCursorId,
|
|
68
|
+
showSeparatePivotColumnForSingleAggregation: false,
|
|
69
|
+
|
|
70
|
+
propsCache: new Map<keyof DataSourceProps<T>, WeakMap<any, any>>([
|
|
71
|
+
['sortInfo', new WeakMap()],
|
|
72
|
+
]),
|
|
73
|
+
|
|
74
|
+
pivotMappings: undefined,
|
|
75
|
+
|
|
76
|
+
pivotColumns: undefined,
|
|
77
|
+
pivotColumnGroups: undefined,
|
|
78
|
+
dataArray,
|
|
79
|
+
unfilteredCount: dataArray.length,
|
|
80
|
+
filteredCount: dataArray.length,
|
|
81
|
+
|
|
82
|
+
updatedAt: now,
|
|
83
|
+
groupedAt: 0,
|
|
84
|
+
sortedAt: 0,
|
|
85
|
+
filteredAt: 0,
|
|
86
|
+
reducedAt: now,
|
|
87
|
+
generateGroupRows: true,
|
|
88
|
+
groupDeepMap: undefined,
|
|
89
|
+
reducerResults: undefined,
|
|
90
|
+
allRowsSelected: false,
|
|
91
|
+
someRowsSelected: false,
|
|
92
|
+
// selectedRowCount: 0,
|
|
93
|
+
postSortDataArray: undefined,
|
|
94
|
+
postGroupDataArray: undefined,
|
|
95
|
+
lastSortDataArray: undefined,
|
|
96
|
+
lastGroupDataArray: undefined,
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function getCompareObjectForDataParams<T>(
|
|
101
|
+
dataParams: DataSourceDataParams<T>,
|
|
102
|
+
): Partial<DataSourceDataParams<T>> {
|
|
103
|
+
const obj: Partial<DataSourceDataParams<T>> = {
|
|
104
|
+
...dataParams,
|
|
105
|
+
};
|
|
106
|
+
|
|
107
|
+
delete obj.originalDataArray;
|
|
108
|
+
|
|
109
|
+
return obj;
|
|
110
|
+
}
|
|
111
|
+
export const forwardProps = <T>(
|
|
112
|
+
setupState: DataSourceSetupState<T>,
|
|
113
|
+
): ForwardPropsToStateFnResult<
|
|
114
|
+
DataSourceProps<T>,
|
|
115
|
+
DataSourceMappedState<T>
|
|
116
|
+
> => {
|
|
117
|
+
return {
|
|
118
|
+
onDataParamsChange: (fn) =>
|
|
119
|
+
fn
|
|
120
|
+
? discardCallsWithEqualArg(fn, 100, getCompareObjectForDataParams)
|
|
121
|
+
: undefined,
|
|
122
|
+
lazyLoad: (lazyLoad) => !!lazyLoad,
|
|
123
|
+
data: 1,
|
|
124
|
+
pivotBy: 1,
|
|
125
|
+
primaryKey: 1,
|
|
126
|
+
livePagination: 1,
|
|
127
|
+
filterFunction: 1,
|
|
128
|
+
filterValue: 1,
|
|
129
|
+
useGroupKeysForMultiRowSelection: (useGroupKeysForMultiRowSelection) =>
|
|
130
|
+
useGroupKeysForMultiRowSelection ?? false,
|
|
131
|
+
filterDelay: (filterDelay) => filterDelay ?? 200,
|
|
132
|
+
filterTypes: (filterTypes) => {
|
|
133
|
+
return { ...defaultFilterTypes, ...filterTypes };
|
|
134
|
+
},
|
|
135
|
+
|
|
136
|
+
sortTypes: (sortTypes) => {
|
|
137
|
+
return { ...defaultSortTypes, ...sortTypes };
|
|
138
|
+
},
|
|
139
|
+
sortMode: (sortMode) => sortMode ?? 'local',
|
|
140
|
+
|
|
141
|
+
isRowSelected: 1,
|
|
142
|
+
aggregationReducers: 1,
|
|
143
|
+
collapseGroupRowsOnDataFunctionChange: (
|
|
144
|
+
collapseGroupRowsOnDataFunctionChange,
|
|
145
|
+
) => collapseGroupRowsOnDataFunctionChange ?? true,
|
|
146
|
+
|
|
147
|
+
loading: (loading) => loading ?? false,
|
|
148
|
+
sortInfo: (sortInfo) =>
|
|
149
|
+
normalizeSortInfo(sortInfo, setupState.propsCache.get('sortInfo')),
|
|
150
|
+
groupBy: (groupBy) => groupBy ?? [],
|
|
151
|
+
};
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
function getLivePaginationCursorValue<T>(
|
|
155
|
+
livePaginationCursorProp: DataSourceProps<T>['livePaginationCursor'],
|
|
156
|
+
state: DataSourceState<T>,
|
|
157
|
+
) {
|
|
158
|
+
const livePaginationCursor =
|
|
159
|
+
typeof livePaginationCursorProp === 'function'
|
|
160
|
+
? livePaginationCursorProp({
|
|
161
|
+
array: state.originalDataArray,
|
|
162
|
+
length: state.originalDataArray.length,
|
|
163
|
+
lastItem: state.originalDataArray[state.originalDataArray.length - 1],
|
|
164
|
+
})
|
|
165
|
+
: livePaginationCursorProp;
|
|
166
|
+
|
|
167
|
+
return livePaginationCursor;
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export function deriveStateFromProps<T extends any>(params: {
|
|
171
|
+
props: DataSourceProps<T>;
|
|
172
|
+
|
|
173
|
+
state: DataSourceState<T>;
|
|
174
|
+
oldState: DataSourceState<T> | null;
|
|
175
|
+
}): DataSourceDerivedState<T> {
|
|
176
|
+
const { props, state, oldState } = params;
|
|
177
|
+
|
|
178
|
+
const controlledSort = isControlledValue(props.sortInfo);
|
|
179
|
+
const controlledFilter = isControlledValue(props.filterValue);
|
|
180
|
+
|
|
181
|
+
const { filterTypes } = state;
|
|
182
|
+
|
|
183
|
+
const operatorsByFilterType = Object.keys(filterTypes).reduce((acc, key) => {
|
|
184
|
+
const operators = filterTypes[key].operators;
|
|
185
|
+
|
|
186
|
+
acc[key] = acc[key] || {};
|
|
187
|
+
const currentFilterTypeOperators = acc[key];
|
|
188
|
+
|
|
189
|
+
operators.forEach((operator) => {
|
|
190
|
+
currentFilterTypeOperators[operator.name] = operator;
|
|
191
|
+
});
|
|
192
|
+
|
|
193
|
+
return acc;
|
|
194
|
+
}, {} as Record<string, Record<string, DataSourceFilterOperator<T>>>);
|
|
195
|
+
|
|
196
|
+
let selectionMode: DataSourcePropSelectionMode | undefined =
|
|
197
|
+
props.selectionMode;
|
|
198
|
+
|
|
199
|
+
if (selectionMode === undefined) {
|
|
200
|
+
if (
|
|
201
|
+
props.cellSelection !== undefined ||
|
|
202
|
+
props.defaultCellSelection !== undefined
|
|
203
|
+
) {
|
|
204
|
+
// TODO implement single cell selection as well
|
|
205
|
+
selectionMode = 'multi-cell';
|
|
206
|
+
} else {
|
|
207
|
+
const rowSelectionProp =
|
|
208
|
+
props.rowSelection !== undefined
|
|
209
|
+
? props.rowSelection
|
|
210
|
+
: props.defaultRowSelection;
|
|
211
|
+
if (rowSelectionProp !== undefined) {
|
|
212
|
+
if (rowSelectionProp && typeof rowSelectionProp === 'object') {
|
|
213
|
+
selectionMode = 'multi-row';
|
|
214
|
+
} else {
|
|
215
|
+
selectionMode = 'single-row';
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
selectionMode = selectionMode ?? false;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
let rowSelectionState: RowSelectionState | null | number | string = null;
|
|
223
|
+
|
|
224
|
+
let currentRowSelection =
|
|
225
|
+
props.rowSelection !== undefined
|
|
226
|
+
? props.rowSelection
|
|
227
|
+
: state.rowSelection === undefined
|
|
228
|
+
? props.defaultRowSelection !== undefined
|
|
229
|
+
? props.defaultRowSelection
|
|
230
|
+
: null
|
|
231
|
+
: state.rowSelection;
|
|
232
|
+
|
|
233
|
+
if (selectionMode !== false) {
|
|
234
|
+
if (selectionMode === 'single-row' || selectionMode === 'multi-row') {
|
|
235
|
+
if (currentRowSelection === null) {
|
|
236
|
+
rowSelectionState =
|
|
237
|
+
selectionMode === 'single-row'
|
|
238
|
+
? null
|
|
239
|
+
: new RowSelectionState(
|
|
240
|
+
{
|
|
241
|
+
selectedRows: [],
|
|
242
|
+
deselectedRows: [],
|
|
243
|
+
defaultSelection: false,
|
|
244
|
+
},
|
|
245
|
+
rowSelectionStateConfigGetter(state),
|
|
246
|
+
);
|
|
247
|
+
} else {
|
|
248
|
+
rowSelectionState =
|
|
249
|
+
selectionMode === 'single-row'
|
|
250
|
+
? (currentRowSelection as string | number)
|
|
251
|
+
: currentRowSelection instanceof RowSelectionState
|
|
252
|
+
? currentRowSelection
|
|
253
|
+
: new RowSelectionState(
|
|
254
|
+
currentRowSelection as RowSelectionStateObject,
|
|
255
|
+
rowSelectionStateConfigGetter(state),
|
|
256
|
+
);
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const primaryKeyDescriptor = state.primaryKey;
|
|
262
|
+
const toPrimaryKey =
|
|
263
|
+
typeof primaryKeyDescriptor === 'function'
|
|
264
|
+
? (data: T) => primaryKeyDescriptor(data)
|
|
265
|
+
: (data: T) => data[primaryKeyDescriptor];
|
|
266
|
+
|
|
267
|
+
let groupRowsState =
|
|
268
|
+
props.groupRowsState || state.groupRowsState || props.defaultGroupRowsState;
|
|
269
|
+
|
|
270
|
+
if (groupRowsState && !(groupRowsState instanceof GroupRowsState)) {
|
|
271
|
+
groupRowsState = new GroupRowsState(groupRowsState);
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
groupRowsState =
|
|
275
|
+
groupRowsState ||
|
|
276
|
+
new GroupRowsState(
|
|
277
|
+
state.lazyLoad
|
|
278
|
+
? { expandedRows: [], collapsedRows: true }
|
|
279
|
+
: {
|
|
280
|
+
expandedRows: true,
|
|
281
|
+
collapsedRows: [],
|
|
282
|
+
},
|
|
283
|
+
);
|
|
284
|
+
|
|
285
|
+
const result: DataSourceDerivedState<T> = {
|
|
286
|
+
selectionMode,
|
|
287
|
+
groupRowsState,
|
|
288
|
+
// for whatever reason I had to do this cast to appease TS
|
|
289
|
+
rowSelection: rowSelectionState as any as null,
|
|
290
|
+
|
|
291
|
+
toPrimaryKey,
|
|
292
|
+
operatorsByFilterType,
|
|
293
|
+
controlledSort,
|
|
294
|
+
controlledFilter,
|
|
295
|
+
|
|
296
|
+
filterMode:
|
|
297
|
+
props.filterMode ?? props.filterFunction != null
|
|
298
|
+
? 'local'
|
|
299
|
+
: typeof props.data === 'function'
|
|
300
|
+
? 'remote'
|
|
301
|
+
: 'local',
|
|
302
|
+
|
|
303
|
+
multiSort: Array.isArray(
|
|
304
|
+
controlledSort ? props.sortInfo : props.defaultSortInfo,
|
|
305
|
+
),
|
|
306
|
+
lazyLoadBatchSize:
|
|
307
|
+
typeof props.lazyLoad === 'object' ? props.lazyLoad.batchSize : undefined,
|
|
308
|
+
};
|
|
309
|
+
|
|
310
|
+
if (props.livePagination) {
|
|
311
|
+
const dataArrayChanged =
|
|
312
|
+
!oldState || oldState.originalDataArray !== state.originalDataArray;
|
|
313
|
+
|
|
314
|
+
const livePaginationCursor =
|
|
315
|
+
typeof props.livePaginationCursor === 'function'
|
|
316
|
+
? dataArrayChanged
|
|
317
|
+
? getLivePaginationCursorValue(props.livePaginationCursor, state)
|
|
318
|
+
: state.livePaginationCursor
|
|
319
|
+
: props.livePaginationCursor;
|
|
320
|
+
|
|
321
|
+
result.livePaginationCursor = livePaginationCursor;
|
|
322
|
+
}
|
|
323
|
+
|
|
324
|
+
return result;
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
const debugFullLazyLoad = dbg('DataSource:fullLazyLoad');
|
|
328
|
+
|
|
329
|
+
export function onPropChange<T>(
|
|
330
|
+
params: { name: keyof T; newValue: any; oldValue: any },
|
|
331
|
+
props: DataSourceProps<T>,
|
|
332
|
+
actions: DataSourceComponentActions<T>,
|
|
333
|
+
) {
|
|
334
|
+
const { name, newValue } = params;
|
|
335
|
+
|
|
336
|
+
if (
|
|
337
|
+
name === 'data' &&
|
|
338
|
+
typeof newValue === 'function' &&
|
|
339
|
+
!props.groupRowsState
|
|
340
|
+
) {
|
|
341
|
+
if (props.lazyLoad) {
|
|
342
|
+
debugFullLazyLoad(`"data" function prop has changed`);
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
if (props.collapseGroupRowsOnDataFunctionChange !== false) {
|
|
346
|
+
actions.groupRowsState = new GroupRowsState({
|
|
347
|
+
collapsedRows: true,
|
|
348
|
+
expandedRows: [],
|
|
349
|
+
});
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
|
|
354
|
+
const debugDataParams = dbg('DataSource:dataParams');
|
|
355
|
+
|
|
356
|
+
export type DataSourceMappedCallbackParams<T> = {
|
|
357
|
+
[k in keyof DataSourceState<T>]: (
|
|
358
|
+
value: DataSourceState<T>[k],
|
|
359
|
+
state: DataSourceState<T>,
|
|
360
|
+
) => {
|
|
361
|
+
callbackName?: string;
|
|
362
|
+
callbackParams: any[];
|
|
363
|
+
};
|
|
364
|
+
};
|
|
365
|
+
|
|
366
|
+
export function getMappedCallbacks<T>() {
|
|
367
|
+
return {
|
|
368
|
+
rowSelection: (
|
|
369
|
+
rowSelection,
|
|
370
|
+
state: DataSourceState<T>,
|
|
371
|
+
): { callbackParams: any[] } => {
|
|
372
|
+
if (state.selectionMode === 'single-row') {
|
|
373
|
+
return {
|
|
374
|
+
callbackParams: [
|
|
375
|
+
rowSelection,
|
|
376
|
+
'single-row',
|
|
377
|
+
] as Parameters<DataSourcePropOnRowSelectionChange_SingleRow>,
|
|
378
|
+
};
|
|
379
|
+
}
|
|
380
|
+
return {
|
|
381
|
+
callbackParams: [
|
|
382
|
+
(rowSelection as RowSelectionState).getState(),
|
|
383
|
+
'multi-row',
|
|
384
|
+
] as Parameters<DataSourcePropOnRowSelectionChange_MultiRow>,
|
|
385
|
+
};
|
|
386
|
+
},
|
|
387
|
+
} as DataSourceMappedCallbackParams<T>;
|
|
388
|
+
}
|
|
389
|
+
|
|
390
|
+
export function getInterceptActions<T>(): ComponentInterceptedActions<
|
|
391
|
+
DataSourceState<T>
|
|
392
|
+
> {
|
|
393
|
+
return {
|
|
394
|
+
sortInfo: (sortInfo, { actions, state }) => {
|
|
395
|
+
const dataParams = buildDataSourceDataParams(state, {
|
|
396
|
+
sortInfo,
|
|
397
|
+
livePaginationCursor: null,
|
|
398
|
+
});
|
|
399
|
+
|
|
400
|
+
actions.dataParams = dataParams;
|
|
401
|
+
|
|
402
|
+
if (state.livePagination) {
|
|
403
|
+
// #wait_for_update do it on raf, since it also does actions.dataParams assignment
|
|
404
|
+
// so we allow dataParams to be updated (the call 3 lines above) in state
|
|
405
|
+
|
|
406
|
+
raf(() => {
|
|
407
|
+
actions.livePaginationCursor = null;
|
|
408
|
+
});
|
|
409
|
+
}
|
|
410
|
+
},
|
|
411
|
+
groupBy: (groupBy, { actions, state }) => {
|
|
412
|
+
const dataParams = buildDataSourceDataParams(state, {
|
|
413
|
+
groupBy,
|
|
414
|
+
livePaginationCursor: null,
|
|
415
|
+
});
|
|
416
|
+
|
|
417
|
+
actions.dataParams = dataParams;
|
|
418
|
+
|
|
419
|
+
if (state.livePagination) {
|
|
420
|
+
// see #wait_for_update above
|
|
421
|
+
|
|
422
|
+
raf(() => {
|
|
423
|
+
actions.livePaginationCursor = null;
|
|
424
|
+
});
|
|
425
|
+
}
|
|
426
|
+
},
|
|
427
|
+
pivotBy: (pivotBy, { actions, state }) => {
|
|
428
|
+
const dataParams = buildDataSourceDataParams(state, {
|
|
429
|
+
pivotBy,
|
|
430
|
+
livePaginationCursor: null,
|
|
431
|
+
});
|
|
432
|
+
|
|
433
|
+
actions.dataParams = dataParams;
|
|
434
|
+
|
|
435
|
+
if (state.livePagination) {
|
|
436
|
+
// see #wait_for_update above
|
|
437
|
+
|
|
438
|
+
raf(() => {
|
|
439
|
+
actions.livePaginationCursor = null;
|
|
440
|
+
});
|
|
441
|
+
}
|
|
442
|
+
},
|
|
443
|
+
filterValue: (filterValue, { actions, state }) => {
|
|
444
|
+
const dataParams = buildDataSourceDataParams(state, {
|
|
445
|
+
filterValue,
|
|
446
|
+
livePaginationCursor: null,
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
actions.dataParams = dataParams;
|
|
450
|
+
|
|
451
|
+
if (state.livePagination) {
|
|
452
|
+
// see #wait_for_update above
|
|
453
|
+
|
|
454
|
+
raf(() => {
|
|
455
|
+
actions.livePaginationCursor = null;
|
|
456
|
+
});
|
|
457
|
+
}
|
|
458
|
+
},
|
|
459
|
+
cursorId: (cursorId, { actions, state }) => {
|
|
460
|
+
const dataParams = buildDataSourceDataParams(state, {
|
|
461
|
+
__cursorId: cursorId,
|
|
462
|
+
});
|
|
463
|
+
actions.dataParams = dataParams;
|
|
464
|
+
},
|
|
465
|
+
livePaginationCursor: (livePaginationCursor, { actions, state }) => {
|
|
466
|
+
const dataParams = buildDataSourceDataParams(state, {
|
|
467
|
+
livePaginationCursor,
|
|
468
|
+
});
|
|
469
|
+
|
|
470
|
+
actions.dataParams = dataParams;
|
|
471
|
+
},
|
|
472
|
+
dataParams: (dataParams, { state }) => {
|
|
473
|
+
if (
|
|
474
|
+
shallowEqualObjects(
|
|
475
|
+
dataParams!,
|
|
476
|
+
state.dataParams!,
|
|
477
|
+
new Set<keyof DataSourceDataParams<T>>([
|
|
478
|
+
'changes',
|
|
479
|
+
'originalDataArray',
|
|
480
|
+
]),
|
|
481
|
+
)
|
|
482
|
+
) {
|
|
483
|
+
return false;
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
debugDataParams(
|
|
487
|
+
'onDataParamsChange triggered because the following values have changed',
|
|
488
|
+
dataParams?.changes,
|
|
489
|
+
);
|
|
490
|
+
|
|
491
|
+
return true;
|
|
492
|
+
},
|
|
493
|
+
};
|
|
494
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { DataSourceSingleSortInfo, DataSourceSortInfo } from '../types';
|
|
2
|
+
|
|
3
|
+
const EMPTY_ARRAY: DataSourceSingleSortInfo<any>[] = Object.freeze(
|
|
4
|
+
[],
|
|
5
|
+
) as any as DataSourceSingleSortInfo<any>[];
|
|
6
|
+
|
|
7
|
+
// the idea of using a weakmap was that single objects always get
|
|
8
|
+
// mapped into an array, thus become a new reference on every render
|
|
9
|
+
// which breaks React.memo and useEffect comparisons.
|
|
10
|
+
//
|
|
11
|
+
// but now, mostly just having the EMPTY_ARRAY fixes the referencial issue
|
|
12
|
+
|
|
13
|
+
export const normalizeSortInfo = <T>(
|
|
14
|
+
initialSortInfo?: DataSourceSortInfo<T>,
|
|
15
|
+
weakMap?: WeakMap<any, any>,
|
|
16
|
+
): DataSourceSingleSortInfo<T>[] => {
|
|
17
|
+
const sortInfo =
|
|
18
|
+
initialSortInfo ?? (EMPTY_ARRAY as DataSourceSingleSortInfo<T>[]);
|
|
19
|
+
|
|
20
|
+
const result = Array.isArray(sortInfo) ? sortInfo : [sortInfo];
|
|
21
|
+
|
|
22
|
+
if (weakMap && weakMap.has(sortInfo)) {
|
|
23
|
+
const prevResult = weakMap.get(sortInfo);
|
|
24
|
+
|
|
25
|
+
if (prevResult && prevResult.length === result.length) {
|
|
26
|
+
return prevResult;
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
if (weakMap && sortInfo) {
|
|
31
|
+
weakMap.set(sortInfo, result);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
return result;
|
|
35
|
+
};
|