@infinite-table/infinite-react 0.5.0 → 0.5.2
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/README.md +104 -0
- package/index.css +896 -0
- package/index.d.ts +2264 -0
- package/index.esm.css +896 -0
- package/index.esm.js +15404 -0
- package/index.js +15240 -0
- package/package.json +9 -94
- package/.vscode/settings.json +0 -3
- package/API.md +0 -0
- package/build/buildPackageJson.js +0 -43
- package/build/scripts/test.js +0 -37
- package/bundler.config.js +0 -25
- package/globals.d.ts +0 -7
- package/rollup.config.js +0 -15
- package/run-build-deepmap.js +0 -47
- package/run-build.js +0 -45
- package/run-dts-concat.js +0 -21
- package/src/components/CSSVariableWatch.tsx +0 -82
- package/src/components/DataSource/BooleanCollectionState.ts +0 -214
- package/src/components/DataSource/BooleanDeepCollectionState.ts +0 -208
- package/src/components/DataSource/DataSourceContext.ts +0 -20
- package/src/components/DataSource/GroupRowsState.ts +0 -74
- package/src/components/DataSource/Indexer.ts +0 -27
- package/src/components/DataSource/RowSelectionState.ts +0 -763
- package/src/components/DataSource/defaultFilterTypes.ts +0 -64
- package/src/components/DataSource/index.tsx +0 -108
- package/src/components/DataSource/privateHooks/getChangeDetect.ts +0 -7
- package/src/components/DataSource/privateHooks/useLoadData.ts +0 -783
- package/src/components/DataSource/publicHooks/useDataSource.ts +0 -19
- package/src/components/DataSource/publicHooks/useDataSourceActions.ts +0 -14
- package/src/components/DataSource/state/getInitialState.ts +0 -494
- package/src/components/DataSource/state/normalizeSortInfo.ts +0 -35
- package/src/components/DataSource/state/reducer.ts +0 -466
- package/src/components/DataSource/state/rowInfoStatus.ts +0 -27
- package/src/components/DataSource/types.ts +0 -548
- package/src/components/HeadlessTable/HeadlessTableWithPinnedContainers.tsx +0 -142
- package/src/components/HeadlessTable/MappedCells.ts +0 -251
- package/src/components/HeadlessTable/RawTable.tsx +0 -98
- package/src/components/HeadlessTable/ReactHeadlessTableRenderer.tsx +0 -1516
- package/src/components/HeadlessTable/index.tsx +0 -234
- package/src/components/InfiniteTable/InfiniteCls.css.ts +0 -164
- package/src/components/InfiniteTable/InfiniteTableContext.ts +0 -16
- package/src/components/InfiniteTable/api/getImperativeApi.ts +0 -391
- package/src/components/InfiniteTable/api/getSelectionApi.ts +0 -364
- package/src/components/InfiniteTable/api/type.ts +0 -11
- package/src/components/InfiniteTable/components/ActiveCellIndicator.css.ts +0 -51
- package/src/components/InfiniteTable/components/ActiveCellIndicator.tsx +0 -116
- package/src/components/InfiniteTable/components/ActiveRowIndicator.css.ts +0 -56
- package/src/components/InfiniteTable/components/ActiveRowIndicator.tsx +0 -94
- package/src/components/InfiniteTable/components/CheckBox.css.ts +0 -13
- package/src/components/InfiniteTable/components/CheckBox.tsx +0 -96
- package/src/components/InfiniteTable/components/FilterEditors.tsx +0 -52
- package/src/components/InfiniteTable/components/InfiniteTableBody/InfiniteTableBody.tsx +0 -27
- package/src/components/InfiniteTable/components/InfiniteTableBody/index.tsx +0 -1
- package/src/components/InfiniteTable/components/InfiniteTableFooter/InfiniteTableFooter.tsx +0 -31
- package/src/components/InfiniteTable/components/InfiniteTableFooter/index.tsx +0 -1
- package/src/components/InfiniteTable/components/InfiniteTableHeader/InfiniteTableColumnHeaderFilter.tsx +0 -102
- package/src/components/InfiniteTable/components/InfiniteTableHeader/InfiniteTableHeader.tsx +0 -163
- package/src/components/InfiniteTable/components/InfiniteTableHeader/InfiniteTableHeaderCell.tsx +0 -574
- package/src/components/InfiniteTable/components/InfiniteTableHeader/InfiniteTableHeaderGroup.tsx +0 -79
- package/src/components/InfiniteTable/components/InfiniteTableHeader/InfiniteTableHeaderTypes.tsx +0 -25
- package/src/components/InfiniteTable/components/InfiniteTableHeader/InfiniteTableHeaderWrapper.tsx +0 -185
- package/src/components/InfiniteTable/components/InfiniteTableHeader/ResizeHandle/GroupResizeHandle.tsx +0 -159
- package/src/components/InfiniteTable/components/InfiniteTableHeader/ResizeHandle/ResizeHandle.css.ts +0 -124
- package/src/components/InfiniteTable/components/InfiniteTableHeader/ResizeHandle/columnResizer.ts +0 -166
- package/src/components/InfiniteTable/components/InfiniteTableHeader/ResizeHandle/index.tsx +0 -146
- package/src/components/InfiniteTable/components/InfiniteTableHeader/buildColumnAndGroupTree.ts +0 -240
- package/src/components/InfiniteTable/components/InfiniteTableHeader/header.css.ts +0 -358
- package/src/components/InfiniteTable/components/InfiniteTableHeader/index.tsx +0 -1
- package/src/components/InfiniteTable/components/InfiniteTableHeader/useColumnGroupResizeHandle.tsx +0 -114
- package/src/components/InfiniteTable/components/InfiniteTableHeader/useColumnResizeHandle.tsx +0 -146
- package/src/components/InfiniteTable/components/InfiniteTableLicenseFooter/footer.css.ts +0 -7
- package/src/components/InfiniteTable/components/InfiniteTableLicenseFooter/index.tsx +0 -110
- package/src/components/InfiniteTable/components/InfiniteTableRow/InfiniteTableCell.tsx +0 -120
- package/src/components/InfiniteTable/components/InfiniteTableRow/InfiniteTableCellTypes.ts +0 -74
- package/src/components/InfiniteTable/components/InfiniteTableRow/InfiniteTableColumnCell.tsx +0 -457
- package/src/components/InfiniteTable/components/InfiniteTableRow/InfiniteTableRow.tsx +0 -107
- package/src/components/InfiniteTable/components/InfiniteTableRow/InfiniteTableRowClassName.ts +0 -6
- package/src/components/InfiniteTable/components/InfiniteTableRow/InfiniteTableRowTypes.ts +0 -32
- package/src/components/InfiniteTable/components/InfiniteTableRow/InfiniteTableRowUnvirtualized.tsx +0 -75
- package/src/components/InfiniteTable/components/InfiniteTableRow/columnRendering.tsx +0 -263
- package/src/components/InfiniteTable/components/InfiniteTableRow/index.tsx +0 -1
- package/src/components/InfiniteTable/components/InfiniteTableRow/row.css.ts +0 -74
- package/src/components/InfiniteTable/components/InfiniteTableRow/useRowDOMProps.ts +0 -199
- package/src/components/InfiniteTable/components/LoadMask.css.ts +0 -34
- package/src/components/InfiniteTable/components/LoadMask.tsx +0 -27
- package/src/components/InfiniteTable/components/ScrollbarPlaceholder.tsx +0 -56
- package/src/components/InfiniteTable/components/cell.css.ts +0 -192
- package/src/components/InfiniteTable/components/icons/ArrowDown.tsx +0 -14
- package/src/components/InfiniteTable/components/icons/ArrowUp.tsx +0 -14
- package/src/components/InfiniteTable/components/icons/ExpanderIcon.css.ts +0 -31
- package/src/components/InfiniteTable/components/icons/ExpanderIcon.tsx +0 -63
- package/src/components/InfiniteTable/components/icons/Icon.tsx +0 -18
- package/src/components/InfiniteTable/components/icons/InfiniteTableIconClassName.ts +0 -1
- package/src/components/InfiniteTable/components/icons/LoadingIcon.css.ts +0 -8
- package/src/components/InfiniteTable/components/icons/LoadingIcon.tsx +0 -45
- package/src/components/InfiniteTable/components/icons/MenuIcon.tsx +0 -50
- package/src/components/InfiniteTable/components/icons/SortIcon.tsx +0 -113
- package/src/components/InfiniteTable/eventHandlers/eventHandlerTypes.ts +0 -57
- package/src/components/InfiniteTable/eventHandlers/index.ts +0 -95
- package/src/components/InfiniteTable/eventHandlers/keyboardNavigation.ts +0 -232
- package/src/components/InfiniteTable/eventHandlers/keyboardSelection.ts +0 -110
- package/src/components/InfiniteTable/eventHandlers/onCellClick.ts +0 -94
- package/src/components/InfiniteTable/eventHandlers/onKeyDown.ts +0 -25
- package/src/components/InfiniteTable/hooks/adjustColumnOrderForAllColumns.ts +0 -70
- package/src/components/InfiniteTable/hooks/reorderColumnsOnDrag.ts +0 -476
- package/src/components/InfiniteTable/hooks/useAutoSizeColumns.ts +0 -206
- package/src/components/InfiniteTable/hooks/useCellClassName.ts +0 -80
- package/src/components/InfiniteTable/hooks/useCellRendering.tsx +0 -217
- package/src/components/InfiniteTable/hooks/useColumnGroups.ts +0 -71
- package/src/components/InfiniteTable/hooks/useColumnMenu.ts +0 -72
- package/src/components/InfiniteTable/hooks/useColumnPointerEvents.ts +0 -258
- package/src/components/InfiniteTable/hooks/useColumnRowspan.ts +0 -43
- package/src/components/InfiniteTable/hooks/useColumnSizeFn.ts +0 -24
- package/src/components/InfiniteTable/hooks/useColumnsWhen.ts +0 -582
- package/src/components/InfiniteTable/hooks/useComputed.ts +0 -186
- package/src/components/InfiniteTable/hooks/useComputedVisibleColumns.ts +0 -219
- package/src/components/InfiniteTable/hooks/useDOMProps.ts +0 -306
- package/src/components/InfiniteTable/hooks/useEffectWithRaf.ts +0 -47
- package/src/components/InfiniteTable/hooks/useInfiniteTable.ts +0 -10
- package/src/components/InfiniteTable/hooks/useInfiniteTableState.ts +0 -11
- package/src/components/InfiniteTable/hooks/useInternalProps.ts +0 -8
- package/src/components/InfiniteTable/hooks/useLicense/LicenseDetails.ts +0 -13
- package/src/components/InfiniteTable/hooks/useLicense/crc32.ts +0 -56
- package/src/components/InfiniteTable/hooks/useLicense/decode.ts +0 -147
- package/src/components/InfiniteTable/hooks/useLicense/useLicense.ts +0 -39
- package/src/components/InfiniteTable/hooks/useRerenderOnKeyChange.ts +0 -21
- package/src/components/InfiniteTable/hooks/useRowHover.ts +0 -18
- package/src/components/InfiniteTable/hooks/useScrollToActiveCell.ts +0 -48
- package/src/components/InfiniteTable/hooks/useScrollToActiveRow.ts +0 -44
- package/src/components/InfiniteTable/hooks/useScrollbars.ts +0 -51
- package/src/components/InfiniteTable/hooks/useToggleGroupRow.ts +0 -56
- package/src/components/InfiniteTable/hooks/useUnpinnedRendering.tsx +0 -165
- package/src/components/InfiniteTable/hooks/useYourBrain.ts +0 -55
- package/src/components/InfiniteTable/index.tsx +0 -352
- package/src/components/InfiniteTable/internalProps.ts +0 -4
- package/src/components/InfiniteTable/state/computeColumnGroupsDepths.ts +0 -29
- package/src/components/InfiniteTable/state/getColumnVisibilityForHideEmptyGroupColumns.ts +0 -127
- package/src/components/InfiniteTable/state/getInitialState.ts +0 -375
- package/src/components/InfiniteTable/theme.css.ts +0 -556
- package/src/components/InfiniteTable/types/InfiniteTableAction.ts +0 -6
- package/src/components/InfiniteTable/types/InfiniteTableActionType.ts +0 -12
- package/src/components/InfiniteTable/types/InfiniteTableColumn.ts +0 -478
- package/src/components/InfiniteTable/types/InfiniteTableComputedValues.ts +0 -43
- package/src/components/InfiniteTable/types/InfiniteTableContextValue.ts +0 -12
- package/src/components/InfiniteTable/types/InfiniteTableInternalProps.ts +0 -3
- package/src/components/InfiniteTable/types/InfiniteTableProps.ts +0 -511
- package/src/components/InfiniteTable/types/InfiniteTableState.ts +0 -195
- package/src/components/InfiniteTable/types/Utility.ts +0 -35
- package/src/components/InfiniteTable/types/index.ts +0 -96
- package/src/components/InfiniteTable/utilities.css.ts +0 -179
- package/src/components/InfiniteTable/utils/MultiRowSelector.ts +0 -111
- package/src/components/InfiniteTable/utils/RenderHookComponentForInfinite.tsx +0 -52
- package/src/components/InfiniteTable/utils/adjustColumnOrderForPinning.ts +0 -33
- package/src/components/InfiniteTable/utils/assignFiltered.ts +0 -29
- package/src/components/InfiniteTable/utils/defaultGetColumContextMenuItems.tsx +0 -108
- package/src/components/InfiniteTable/utils/getColumnComputedType.ts +0 -33
- package/src/components/InfiniteTable/utils/getColumnForGroupBy.tsx +0 -313
- package/src/components/InfiniteTable/utils/getComputedVisibleColumns.ts +0 -773
- package/src/components/InfiniteTable/utils/getContextMenuForColumn.tsx +0 -72
- package/src/components/InfiniteTable/utils/infiniteDOMUtils.ts +0 -189
- package/src/components/InfiniteTable/utils/mapToObject.ts +0 -20
- package/src/components/InfiniteTable/utils/moveXatY.ts +0 -25
- package/src/components/InfiniteTable/utils/objectValuesExcept.ts +0 -9
- package/src/components/InfiniteTable/utils/progressiveSpeedScroller.ts +0 -158
- package/src/components/InfiniteTable/utils/rafFn.ts +0 -13
- package/src/components/InfiniteTable/utils/toCSSVarName.ts +0 -1
- package/src/components/InfiniteTable/utils/toMap.ts +0 -24
- package/src/components/Menu/Menu.tsx +0 -750
- package/src/components/Menu/MenuCls.css.ts +0 -139
- package/src/components/Menu/MenuContext.ts +0 -10
- package/src/components/Menu/MenuContextValue.ts +0 -15
- package/src/components/Menu/MenuProps.ts +0 -98
- package/src/components/Menu/MenuState.ts +0 -56
- package/src/components/Menu/MenuTriangleContext.ts +0 -352
- package/src/components/Menu/childrenToRuntimeItems.tsx +0 -103
- package/src/components/Menu/getMenuState.tsx +0 -119
- package/src/components/Menu/index.tsx +0 -88
- package/src/components/Menu/propToIdentifyMenu.ts +0 -1
- package/src/components/RawList/AvoidReactDiff.tsx +0 -48
- package/src/components/RawList/MappedItems.ts +0 -143
- package/src/components/RawList/ReactVirtualRenderer.tsx +0 -307
- package/src/components/RawList/index.tsx +0 -42
- package/src/components/RawList/types.ts +0 -23
- package/src/components/RawList/useVirtualRenderer.ts +0 -36
- package/src/components/RenderHookComponent.tsx +0 -10
- package/src/components/ResizeObserver/index.tsx +0 -170
- package/src/components/VirtualBrain/MatrixBrain.ts +0 -1621
- package/src/components/VirtualBrain/ScrollListener.ts +0 -39
- package/src/components/VirtualBrain/index.ts +0 -664
- package/src/components/VirtualList/ColumnListWithExternalScrolling.tsx +0 -78
- package/src/components/VirtualList/InfiniteListRootClassName.ts +0 -1
- package/src/components/VirtualList/RowListWithExternalScrolling.tsx +0 -120
- package/src/components/VirtualList/SpacePlaceholder.tsx +0 -32
- package/src/components/VirtualList/VirtualList.css.ts +0 -29
- package/src/components/VirtualList/VirtualList.tsx +0 -141
- package/src/components/VirtualList/VirtualRowList.tsx +0 -34
- package/src/components/VirtualList/types.ts +0 -56
- package/src/components/VirtualList/useCorrectHeightForRowElements.ts +0 -14
- package/src/components/VirtualScrollContainer/VirtualScrollContainer.css.ts +0 -51
- package/src/components/VirtualScrollContainer/getScrollableClassName.ts +0 -30
- package/src/components/VirtualScrollContainer/index.tsx +0 -63
- package/src/components/flexbox/index.ts +0 -562
- package/src/components/hooks/useComponentState/index.tsx +0 -562
- package/src/components/hooks/useComponentState/types.ts +0 -32
- package/src/components/hooks/useEffectOnceWithProperUnmount.ts +0 -33
- package/src/components/hooks/useEffectWithChanges.ts +0 -56
- package/src/components/hooks/useImmutableRef.ts +0 -7
- package/src/components/hooks/useInterceptedMap.ts +0 -71
- package/src/components/hooks/useLatest.tsx +0 -8
- package/src/components/hooks/useLazyLatest.ts +0 -23
- package/src/components/hooks/useMemoShallowObjectMerge.ts +0 -16
- package/src/components/hooks/useMounted.ts +0 -18
- package/src/components/hooks/useOnMount.ts +0 -21
- package/src/components/hooks/useOnScroll.ts +0 -34
- package/src/components/hooks/useOnce.ts +0 -10
- package/src/components/hooks/useOverlay/index.tsx +0 -418
- package/src/components/hooks/usePrevious.ts +0 -8
- package/src/components/hooks/usePropertyOld.ts +0 -168
- package/src/components/hooks/useRerender.ts +0 -12
- package/src/components/hooks/xuseProperty.ts +0 -165
- package/src/components/types/CellPosition.ts +0 -4
- package/src/components/types/NonUndefined.ts +0 -1
- package/src/components/types/RemoveObject.ts +0 -22
- package/src/components/types/Renderable.ts +0 -3
- package/src/components/types/ScrollPosition.ts +0 -7
- package/src/components/types/Setter.ts +0 -2
- package/src/components/types/Size.ts +0 -6
- package/src/components/types/SubscriptionCallback.ts +0 -10
- package/src/components/types/VoidFn.ts +0 -1
- package/src/components/utils/buildSubscriptionCallback.tsx +0 -60
- package/src/components/utils/clamp.ts +0 -3
- package/src/components/utils/debounce.ts +0 -16
- package/src/components/utils/decamelize.ts +0 -11
- package/src/components/utils/discardCallsWithEqualArg.ts +0 -42
- package/src/components/utils/getRenderIndexes.ts +0 -33
- package/src/components/utils/getScrollbarWidth.ts +0 -31
- package/src/components/utils/getVirtualRenderCount.ts +0 -21
- package/src/components/utils/isControlled.ts +0 -12
- package/src/components/utils/isControlledValue.ts +0 -5
- package/src/index.tsx +0 -34
- package/src/test.tsx +0 -18
- package/src/utils/DeepMap/index.ts +0 -588
- package/src/utils/DeepMap/once.ts +0 -16
- package/src/utils/DeepMap/sortAscending.ts +0 -1
- package/src/utils/DeepMap/tsconfig.deepmap.json +0 -17
- package/src/utils/DeepMap/xpackage.json +0 -26
- package/src/utils/debug.ts +0 -40
- package/src/utils/deepClone.ts +0 -38
- package/src/utils/getGlobal.ts +0 -3
- package/src/utils/groupAndPivot/defaultToKey.ts +0 -3
- package/src/utils/groupAndPivot/getGroupKeysForDataItem.ts +0 -19
- package/src/utils/groupAndPivot/getPivotColumnsAndColumnGroups.ts +0 -361
- package/src/utils/groupAndPivot/index.ts +0 -1229
- package/src/utils/groupAndPivot/types.ts +0 -10
- package/src/utils/join.ts +0 -4
- package/src/utils/mathIntersection.ts +0 -21
- package/src/utils/minified.d.ts +0 -2
- package/src/utils/minified.js +0 -6
- package/src/utils/multisort/index.ts +0 -151
- package/src/utils/multisort/sortTypes.ts +0 -25
- package/src/utils/notes-status.md +0 -92
- package/src/utils/pageGeometry/ConvexPoly.ts +0 -34
- package/src/utils/pageGeometry/Point.ts +0 -51
- package/src/utils/pageGeometry/PolyWithPoints.ts +0 -52
- package/src/utils/pageGeometry/Rectangle.ts +0 -98
- package/src/utils/pageGeometry/Triangle.ts +0 -16
- package/src/utils/pageGeometry/alignment/index.ts +0 -221
- package/src/utils/pageGeometry/polyContainsPoint.ts +0 -182
- package/src/utils/pageGeometry/types.ts +0 -3
- package/src/utils/proxyFnCall.ts +0 -46
- package/src/utils/raf.ts +0 -13
- package/src/utils/selectParent.ts +0 -18
- package/src/utils/shallowEqualObjects.ts +0 -49
- package/src/utils/stripVar.ts +0 -3
- package/src/utils/toUpperFirst.ts +0 -5
- package/todo.md +0 -2
- package/tsconfig.build.json +0 -8
- package/tsconfig.dev.json +0 -7
- package/tsconfig.json +0 -30
- package/tsconfig.typebundler.json +0 -13
- package/typedoc.json +0 -4
|
@@ -1,1621 +0,0 @@
|
|
|
1
|
-
import binarySearch from 'binary-search';
|
|
2
|
-
|
|
3
|
-
import { Logger } from '../../utils/debug';
|
|
4
|
-
import type { OnScrollFn, ScrollPosition } from '../types/ScrollPosition';
|
|
5
|
-
import type { Size } from '../types/Size';
|
|
6
|
-
import type { VoidFn } from '../types/VoidFn';
|
|
7
|
-
|
|
8
|
-
export type FixedPosition = false | 'start' | 'end';
|
|
9
|
-
export type SpanFunction = ({
|
|
10
|
-
rowIndex,
|
|
11
|
-
colIndex,
|
|
12
|
-
}: {
|
|
13
|
-
rowIndex: number;
|
|
14
|
-
colIndex: number;
|
|
15
|
-
}) => number;
|
|
16
|
-
|
|
17
|
-
type RenderRangeType = {
|
|
18
|
-
startIndex: number;
|
|
19
|
-
endIndex: number;
|
|
20
|
-
};
|
|
21
|
-
|
|
22
|
-
type ItemSizeFunction = (index: number) => number;
|
|
23
|
-
|
|
24
|
-
export type MatrixBrainOptions = {
|
|
25
|
-
width: number;
|
|
26
|
-
height: number;
|
|
27
|
-
|
|
28
|
-
cols: number;
|
|
29
|
-
rows: number;
|
|
30
|
-
|
|
31
|
-
rowHeight: number | ItemSizeFunction;
|
|
32
|
-
colWidth: number | ItemSizeFunction;
|
|
33
|
-
|
|
34
|
-
rowspan?: SpanFunction;
|
|
35
|
-
colspan?: SpanFunction;
|
|
36
|
-
};
|
|
37
|
-
|
|
38
|
-
export type TableRenderRange = {
|
|
39
|
-
start: [number, number];
|
|
40
|
-
end: [number, number];
|
|
41
|
-
rowFixed?: FixedPosition;
|
|
42
|
-
colFixed?: FixedPosition;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
export const getRenderRangeCellCount = (range: TableRenderRange) => {
|
|
46
|
-
const { start, end } = range;
|
|
47
|
-
const [startRow, startCol] = start;
|
|
48
|
-
const [endRow, endCol] = end;
|
|
49
|
-
|
|
50
|
-
const rowCount = endRow - startRow;
|
|
51
|
-
const colCount = endCol - startCol;
|
|
52
|
-
|
|
53
|
-
return rowCount * colCount;
|
|
54
|
-
};
|
|
55
|
-
|
|
56
|
-
type WhichDirection = { horizontal?: boolean; vertical?: boolean };
|
|
57
|
-
|
|
58
|
-
const ALL_DIRECTIONS: WhichDirection = { horizontal: true, vertical: true };
|
|
59
|
-
const SORT_ASC = (a: number, b: number) => a - b;
|
|
60
|
-
|
|
61
|
-
const raf =
|
|
62
|
-
typeof window !== 'undefined'
|
|
63
|
-
? requestAnimationFrame
|
|
64
|
-
: (fn: () => void) => setTimeout(fn, 0);
|
|
65
|
-
|
|
66
|
-
export type FnOnRenderRangeChange = (range: TableRenderRange) => void;
|
|
67
|
-
export type FnOnDirectionalRenderRangeChange = (
|
|
68
|
-
range: [number, number],
|
|
69
|
-
) => void;
|
|
70
|
-
|
|
71
|
-
export type FnOnRenderCountChange = ({
|
|
72
|
-
horizontal,
|
|
73
|
-
vertical,
|
|
74
|
-
}: {
|
|
75
|
-
horizontal: number;
|
|
76
|
-
vertical: number;
|
|
77
|
-
}) => void;
|
|
78
|
-
|
|
79
|
-
export type OnAvailableSizeChange = (size: Size) => void;
|
|
80
|
-
|
|
81
|
-
export type FnOnScrollStop = (
|
|
82
|
-
scrollPosition: ScrollPosition,
|
|
83
|
-
range: TableRenderRange,
|
|
84
|
-
) => void;
|
|
85
|
-
|
|
86
|
-
export class MatrixBrain extends Logger {
|
|
87
|
-
private scrolling = false;
|
|
88
|
-
private width: MatrixBrainOptions['width'] = 0;
|
|
89
|
-
|
|
90
|
-
private height: MatrixBrainOptions['height'] = 0;
|
|
91
|
-
|
|
92
|
-
private cols: MatrixBrainOptions['cols'] = 0;
|
|
93
|
-
private rows: MatrixBrainOptions['rows'] = 0;
|
|
94
|
-
|
|
95
|
-
private rowHeight: MatrixBrainOptions['rowHeight'] = 0;
|
|
96
|
-
private colWidth: MatrixBrainOptions['colWidth'] = 0;
|
|
97
|
-
|
|
98
|
-
private rowspan: MatrixBrainOptions['rowspan'];
|
|
99
|
-
private colspan: MatrixBrainOptions['colspan'];
|
|
100
|
-
|
|
101
|
-
private rowspanParent!: Map<number, number[]>;
|
|
102
|
-
private rowspanValue!: Map<number, number[]>;
|
|
103
|
-
|
|
104
|
-
private rowHeightCache!: number[];
|
|
105
|
-
private rowOffsetCache!: number[];
|
|
106
|
-
|
|
107
|
-
private verticalTotalSize = 0;
|
|
108
|
-
|
|
109
|
-
private colspanParent!: Map<number, number[]>;
|
|
110
|
-
private colspanValue!: Map<number, number[]>;
|
|
111
|
-
|
|
112
|
-
private colWidthCache!: number[];
|
|
113
|
-
private colOffsetCache!: number[];
|
|
114
|
-
private horizontalTotalSize = 0;
|
|
115
|
-
|
|
116
|
-
private horizontalRenderCount?: number = undefined;
|
|
117
|
-
private verticalRenderCount?: number = undefined;
|
|
118
|
-
|
|
119
|
-
private horizontalRenderRange: RenderRangeType = {
|
|
120
|
-
startIndex: 0,
|
|
121
|
-
endIndex: 0,
|
|
122
|
-
};
|
|
123
|
-
|
|
124
|
-
private verticalRenderRange: RenderRangeType = { startIndex: 0, endIndex: 0 };
|
|
125
|
-
|
|
126
|
-
private extraSpanCells: [number, number][] = [];
|
|
127
|
-
|
|
128
|
-
private scrollPosition: ScrollPosition = { scrollLeft: 0, scrollTop: 0 };
|
|
129
|
-
|
|
130
|
-
private onScrollFns: OnScrollFn[] = [];
|
|
131
|
-
// private onTotalSizeChangeFns: OnSizeChangeFn[] = [];
|
|
132
|
-
private onRenderRangeChangeFns: Set<FnOnRenderRangeChange> = new Set();
|
|
133
|
-
|
|
134
|
-
private onVerticalRenderRangeChangeFns: Set<FnOnDirectionalRenderRangeChange> =
|
|
135
|
-
new Set();
|
|
136
|
-
private onHorizontalRenderRangeChangeFns: Set<FnOnDirectionalRenderRangeChange> =
|
|
137
|
-
new Set();
|
|
138
|
-
|
|
139
|
-
private onDestroyFns: VoidFn[] = [];
|
|
140
|
-
private destroyed = false;
|
|
141
|
-
private onRenderCountChangeFns: Set<FnOnRenderCountChange> = new Set();
|
|
142
|
-
private onAvailableSizeChangeFns: Set<OnAvailableSizeChange> = new Set();
|
|
143
|
-
private onScrollStartFns: VoidFunction[] = [];
|
|
144
|
-
private onScrollStopFns: FnOnScrollStop[] = [];
|
|
145
|
-
|
|
146
|
-
private scrollTimeoutId = 0;
|
|
147
|
-
private scrollStopDelay = 250;
|
|
148
|
-
|
|
149
|
-
/**
|
|
150
|
-
* Number of columns that are fixed at the start
|
|
151
|
-
*/
|
|
152
|
-
private fixedColsStart = 0;
|
|
153
|
-
/**
|
|
154
|
-
* Number of columns that are fixed at the end
|
|
155
|
-
*/
|
|
156
|
-
private fixedColsEnd = 0;
|
|
157
|
-
/**
|
|
158
|
-
* Number of rows that are fixed at the start
|
|
159
|
-
*/
|
|
160
|
-
private fixedRowsStart = 0;
|
|
161
|
-
/**
|
|
162
|
-
* Number of rows that are fixed at the end
|
|
163
|
-
*/
|
|
164
|
-
private fixedRowsEnd = 0;
|
|
165
|
-
|
|
166
|
-
constructor(name?: string) {
|
|
167
|
-
super(`MatrixBrain${name ? `:${name}` : ''}`);
|
|
168
|
-
this.reset();
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
private reset(which: WhichDirection = ALL_DIRECTIONS) {
|
|
172
|
-
if (which.vertical) {
|
|
173
|
-
this.resetVertical();
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
if (which.horizontal) {
|
|
177
|
-
this.resetHorizontal();
|
|
178
|
-
}
|
|
179
|
-
|
|
180
|
-
this.extraSpanCells = [];
|
|
181
|
-
}
|
|
182
|
-
|
|
183
|
-
private resetVertical() {
|
|
184
|
-
this.rowspanParent = new Map();
|
|
185
|
-
this.rowspanValue = new Map();
|
|
186
|
-
this.rowHeightCache = [];
|
|
187
|
-
this.rowOffsetCache = [0];
|
|
188
|
-
this.verticalRenderCount = undefined;
|
|
189
|
-
this.verticalTotalSize = 0;
|
|
190
|
-
}
|
|
191
|
-
private resetHorizontal() {
|
|
192
|
-
this.colspanParent = new Map();
|
|
193
|
-
this.colspanValue = new Map();
|
|
194
|
-
this.colWidthCache = [];
|
|
195
|
-
this.colOffsetCache = [0];
|
|
196
|
-
this.horizontalRenderCount = undefined;
|
|
197
|
-
this.horizontalTotalSize = 0;
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
public setScrollStopDelay = (scrollStopDelay: number) => {
|
|
201
|
-
this.scrollStopDelay = scrollStopDelay;
|
|
202
|
-
};
|
|
203
|
-
|
|
204
|
-
public getRowCount = () => {
|
|
205
|
-
return this.rows;
|
|
206
|
-
};
|
|
207
|
-
public getColCount = () => {
|
|
208
|
-
return this.cols;
|
|
209
|
-
};
|
|
210
|
-
|
|
211
|
-
public update = (options: Partial<MatrixBrainOptions>) => {
|
|
212
|
-
const { rows, cols, rowHeight, colWidth, width, height } = options;
|
|
213
|
-
|
|
214
|
-
const widthDefined = typeof width === 'number';
|
|
215
|
-
const heightDefined = typeof height === 'number';
|
|
216
|
-
|
|
217
|
-
const widthChanged = widthDefined && width !== this.width;
|
|
218
|
-
const heightChanged = heightDefined && height !== this.height;
|
|
219
|
-
|
|
220
|
-
this.setAvailableSize({ width, height }, { skipUpdateRenderCount: true });
|
|
221
|
-
|
|
222
|
-
const rowsDefined = typeof rows === 'number';
|
|
223
|
-
const colsDefined = typeof cols === 'number';
|
|
224
|
-
|
|
225
|
-
const rowsChanged = rowsDefined && rows !== this.rows;
|
|
226
|
-
const colsChanged = colsDefined && cols !== this.cols;
|
|
227
|
-
|
|
228
|
-
if (rowsDefined) {
|
|
229
|
-
this.rows = rows;
|
|
230
|
-
}
|
|
231
|
-
if (colsDefined) {
|
|
232
|
-
this.cols = cols;
|
|
233
|
-
}
|
|
234
|
-
|
|
235
|
-
const rowHeightDefined = rowHeight != null;
|
|
236
|
-
const colWidthDefined = colWidth != null;
|
|
237
|
-
|
|
238
|
-
const rowHeightChanged = rowHeightDefined && rowHeight !== this.rowHeight;
|
|
239
|
-
const colWidthChanged = colWidthDefined && colWidth !== this.colWidth;
|
|
240
|
-
|
|
241
|
-
if (rowHeightDefined) {
|
|
242
|
-
this.rowHeight = rowHeight;
|
|
243
|
-
}
|
|
244
|
-
if (colWidthDefined) {
|
|
245
|
-
this.colWidth = colWidth;
|
|
246
|
-
}
|
|
247
|
-
|
|
248
|
-
if (__DEV__) {
|
|
249
|
-
if (widthChanged) {
|
|
250
|
-
this.debug(
|
|
251
|
-
'New available width %d (size is %d,%d)',
|
|
252
|
-
this.width,
|
|
253
|
-
this.width,
|
|
254
|
-
this.height,
|
|
255
|
-
);
|
|
256
|
-
}
|
|
257
|
-
if (heightChanged) {
|
|
258
|
-
this.debug(
|
|
259
|
-
'New available height %d (size is %d,%d)',
|
|
260
|
-
this.height,
|
|
261
|
-
this.width,
|
|
262
|
-
this.height,
|
|
263
|
-
);
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
if (rowsChanged) {
|
|
267
|
-
this.debug('New rows count: %d', this.rows);
|
|
268
|
-
}
|
|
269
|
-
if (colsChanged) {
|
|
270
|
-
this.debug('New cols count: %d', this.cols);
|
|
271
|
-
}
|
|
272
|
-
if (rowHeightChanged) {
|
|
273
|
-
this.debug('New row size', this.rowHeight);
|
|
274
|
-
}
|
|
275
|
-
if (colWidthChanged) {
|
|
276
|
-
this.debug('New col size', this.colWidth);
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
|
|
280
|
-
const rowspanDefined = options.rowspan != null;
|
|
281
|
-
const colspanDefined = options.colspan != null;
|
|
282
|
-
|
|
283
|
-
const rowspanChanged = rowspanDefined && options.rowspan != this.rowspan;
|
|
284
|
-
const colspanChanged = colspanDefined && options.colspan != this.colspan;
|
|
285
|
-
|
|
286
|
-
if (rowspanChanged) {
|
|
287
|
-
this.rowspan = options.rowspan;
|
|
288
|
-
}
|
|
289
|
-
if (colspanChanged) {
|
|
290
|
-
this.colspan = options.colspan;
|
|
291
|
-
}
|
|
292
|
-
|
|
293
|
-
const horizontalChange =
|
|
294
|
-
colsChanged || colWidthChanged || widthChanged || colspanChanged;
|
|
295
|
-
const verticalChange =
|
|
296
|
-
rowsChanged || rowHeightChanged || heightChanged || rowspanChanged;
|
|
297
|
-
|
|
298
|
-
if (horizontalChange || verticalChange) {
|
|
299
|
-
this.updateRenderCount({
|
|
300
|
-
horizontal: horizontalChange,
|
|
301
|
-
vertical: verticalChange,
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
};
|
|
305
|
-
|
|
306
|
-
public setRowAndColumnSizes({
|
|
307
|
-
rowHeight,
|
|
308
|
-
colWidth,
|
|
309
|
-
}: {
|
|
310
|
-
rowHeight: number | ItemSizeFunction;
|
|
311
|
-
colWidth: number | ItemSizeFunction;
|
|
312
|
-
}) {
|
|
313
|
-
const horizontalSame = colWidth === this.colWidth;
|
|
314
|
-
const verticalSame = rowHeight === this.rowHeight;
|
|
315
|
-
|
|
316
|
-
this.rowHeight = rowHeight;
|
|
317
|
-
this.colWidth = colWidth;
|
|
318
|
-
|
|
319
|
-
this.updateRenderCount({
|
|
320
|
-
horizontal: !horizontalSame,
|
|
321
|
-
vertical: !verticalSame,
|
|
322
|
-
});
|
|
323
|
-
}
|
|
324
|
-
|
|
325
|
-
public setRowsAndCols = ({ rows, cols }: { rows: number; cols: number }) => {
|
|
326
|
-
const rowsSame = rows === this.rows;
|
|
327
|
-
const colsSame = cols === this.cols;
|
|
328
|
-
|
|
329
|
-
this.rows = rows;
|
|
330
|
-
this.cols = cols;
|
|
331
|
-
|
|
332
|
-
this.updateRenderCount({
|
|
333
|
-
horizontal: !colsSame,
|
|
334
|
-
vertical: !rowsSame,
|
|
335
|
-
});
|
|
336
|
-
};
|
|
337
|
-
|
|
338
|
-
public setAvailableSize(
|
|
339
|
-
size: Partial<Size>,
|
|
340
|
-
config?: { skipUpdateRenderCount?: boolean },
|
|
341
|
-
) {
|
|
342
|
-
let { width, height } = size;
|
|
343
|
-
|
|
344
|
-
width = width ?? this.width;
|
|
345
|
-
height = height ?? this.height;
|
|
346
|
-
|
|
347
|
-
const widthSame = width === this.width;
|
|
348
|
-
const heightSame = height === this.height;
|
|
349
|
-
|
|
350
|
-
if (widthSame && heightSame) {
|
|
351
|
-
return;
|
|
352
|
-
}
|
|
353
|
-
this.width = width;
|
|
354
|
-
this.height = height;
|
|
355
|
-
|
|
356
|
-
if (__DEV__) {
|
|
357
|
-
this.debug(
|
|
358
|
-
'New available size: width %d, height %d',
|
|
359
|
-
this.width,
|
|
360
|
-
this.height,
|
|
361
|
-
);
|
|
362
|
-
}
|
|
363
|
-
|
|
364
|
-
this.notifyAvailableSizeChange();
|
|
365
|
-
|
|
366
|
-
if (config && config.skipUpdateRenderCount) {
|
|
367
|
-
return;
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
this.updateRenderCount({ horizontal: !widthSame, vertical: !heightSame });
|
|
371
|
-
}
|
|
372
|
-
|
|
373
|
-
updateRenderCount = (which: WhichDirection = ALL_DIRECTIONS) => {
|
|
374
|
-
// if (this._updateRenderCountRafId) {
|
|
375
|
-
// cancelAnimationFrame(this._updateRenderCountRafId);
|
|
376
|
-
// }
|
|
377
|
-
// this._updateRenderCountRafId = requestAnimationFrame(() => {
|
|
378
|
-
this.reset(which);
|
|
379
|
-
this.doUpdateRenderCount(which);
|
|
380
|
-
|
|
381
|
-
// delete this._updateRenderCountRafId;
|
|
382
|
-
// });
|
|
383
|
-
};
|
|
384
|
-
|
|
385
|
-
private doUpdateRenderCount = (which: WhichDirection = ALL_DIRECTIONS) => {
|
|
386
|
-
if (!this.width || !this.height) {
|
|
387
|
-
this.setRenderCount({ horizontal: 0, vertical: 0 });
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
this.setRenderCount(this.computeRenderCount(which));
|
|
391
|
-
};
|
|
392
|
-
|
|
393
|
-
get scrollTopMax() {
|
|
394
|
-
const totalSize = this.getTotalSize();
|
|
395
|
-
return totalSize.height - this.height;
|
|
396
|
-
}
|
|
397
|
-
get scrollLeftMax() {
|
|
398
|
-
const totalSize = this.getTotalSize();
|
|
399
|
-
return totalSize.width - this.width;
|
|
400
|
-
}
|
|
401
|
-
|
|
402
|
-
private setScrolling = (scrolling: boolean) => {
|
|
403
|
-
const prevScrolling = this.scrolling;
|
|
404
|
-
this.scrolling = scrolling;
|
|
405
|
-
|
|
406
|
-
if (scrolling) {
|
|
407
|
-
if (this.scrollTimeoutId) {
|
|
408
|
-
clearTimeout(this.scrollTimeoutId);
|
|
409
|
-
}
|
|
410
|
-
this.scrollTimeoutId = setTimeout(() => {
|
|
411
|
-
this.setScrolling(false);
|
|
412
|
-
this.scrollTimeoutId = 0;
|
|
413
|
-
}, this.scrollStopDelay) as any as number;
|
|
414
|
-
}
|
|
415
|
-
if (scrolling !== prevScrolling) {
|
|
416
|
-
if (scrolling) {
|
|
417
|
-
this.notifyScrollStart();
|
|
418
|
-
} else {
|
|
419
|
-
this.notifyScrollStop();
|
|
420
|
-
}
|
|
421
|
-
}
|
|
422
|
-
};
|
|
423
|
-
|
|
424
|
-
private notifyScrollStart = () => {
|
|
425
|
-
if (this.destroyed) {
|
|
426
|
-
return;
|
|
427
|
-
}
|
|
428
|
-
const fns = this.onScrollStartFns;
|
|
429
|
-
for (let i = 0, len = fns.length; i < len; i++) {
|
|
430
|
-
fns[i]();
|
|
431
|
-
}
|
|
432
|
-
};
|
|
433
|
-
|
|
434
|
-
private notifyScrollStop = () => {
|
|
435
|
-
if (this.destroyed) {
|
|
436
|
-
return;
|
|
437
|
-
}
|
|
438
|
-
const fns = this.onScrollStopFns;
|
|
439
|
-
|
|
440
|
-
const scrollPos = this.scrollPosition;
|
|
441
|
-
const range = this.getRenderRange();
|
|
442
|
-
|
|
443
|
-
for (let i = 0, len = fns.length; i < len; i++) {
|
|
444
|
-
fns[i](scrollPos, range);
|
|
445
|
-
}
|
|
446
|
-
};
|
|
447
|
-
|
|
448
|
-
public setScrollPosition = (
|
|
449
|
-
scrollPosition: ScrollPosition,
|
|
450
|
-
callback?: (scrollPos: ScrollPosition) => void,
|
|
451
|
-
) => {
|
|
452
|
-
this.setScrolling(true);
|
|
453
|
-
const changeHorizontal =
|
|
454
|
-
scrollPosition.scrollLeft !== this.scrollPosition.scrollLeft;
|
|
455
|
-
const changeVertical =
|
|
456
|
-
scrollPosition.scrollTop !== this.scrollPosition.scrollTop;
|
|
457
|
-
|
|
458
|
-
this.scrollPosition = scrollPosition;
|
|
459
|
-
|
|
460
|
-
if (changeHorizontal || changeVertical) {
|
|
461
|
-
callback?.(scrollPosition);
|
|
462
|
-
this.updateRenderRange({
|
|
463
|
-
horizontal: changeHorizontal,
|
|
464
|
-
vertical: changeVertical,
|
|
465
|
-
});
|
|
466
|
-
|
|
467
|
-
this.notifyScrollChange();
|
|
468
|
-
}
|
|
469
|
-
};
|
|
470
|
-
|
|
471
|
-
private notifyAvailableSizeChange = () => {
|
|
472
|
-
if (this.destroyed) {
|
|
473
|
-
return;
|
|
474
|
-
}
|
|
475
|
-
const fns = this.onAvailableSizeChangeFns;
|
|
476
|
-
|
|
477
|
-
const range = this.getAvailableSize();
|
|
478
|
-
|
|
479
|
-
fns.forEach((fn) => {
|
|
480
|
-
raf(() => {
|
|
481
|
-
if (this.destroyed) {
|
|
482
|
-
return;
|
|
483
|
-
}
|
|
484
|
-
// #check-for-presence - we need to check the fn is still in the collection,
|
|
485
|
-
// as it might have been removed between the time of fns.forEach and the time
|
|
486
|
-
// it took the raf to trigger, so we only need to call fns that are still present in the collection
|
|
487
|
-
// this is an important detail, which can cause mis-renderings if not adressed properly (like this)
|
|
488
|
-
if (fns.has(fn)) {
|
|
489
|
-
fn(range);
|
|
490
|
-
}
|
|
491
|
-
});
|
|
492
|
-
});
|
|
493
|
-
};
|
|
494
|
-
|
|
495
|
-
private notifyRenderRangeChange = () => {
|
|
496
|
-
if (this.destroyed) {
|
|
497
|
-
return;
|
|
498
|
-
}
|
|
499
|
-
const fns = this.onRenderRangeChangeFns;
|
|
500
|
-
|
|
501
|
-
const range = this.getRenderRange();
|
|
502
|
-
|
|
503
|
-
fns.forEach((fn) => {
|
|
504
|
-
raf(() => {
|
|
505
|
-
if (this.destroyed) {
|
|
506
|
-
return;
|
|
507
|
-
}
|
|
508
|
-
// #check-for-presence - see above note
|
|
509
|
-
if (fns.has(fn)) {
|
|
510
|
-
fn(range);
|
|
511
|
-
}
|
|
512
|
-
});
|
|
513
|
-
});
|
|
514
|
-
};
|
|
515
|
-
private notifyVerticalRenderRangeChange = () => {
|
|
516
|
-
if (this.destroyed) {
|
|
517
|
-
return;
|
|
518
|
-
}
|
|
519
|
-
const fns = this.onVerticalRenderRangeChangeFns;
|
|
520
|
-
|
|
521
|
-
const range = this.verticalRenderRange;
|
|
522
|
-
|
|
523
|
-
fns.forEach((fn) => {
|
|
524
|
-
raf(() => {
|
|
525
|
-
if (this.destroyed) {
|
|
526
|
-
return;
|
|
527
|
-
}
|
|
528
|
-
// #check-for-presence - see above note
|
|
529
|
-
if (fns.has(fn)) {
|
|
530
|
-
fn([range.startIndex, range.endIndex]);
|
|
531
|
-
}
|
|
532
|
-
});
|
|
533
|
-
});
|
|
534
|
-
};
|
|
535
|
-
private notifyHorizontalRenderRangeChange = () => {
|
|
536
|
-
if (this.destroyed) {
|
|
537
|
-
return;
|
|
538
|
-
}
|
|
539
|
-
const fns = this.onHorizontalRenderRangeChangeFns;
|
|
540
|
-
|
|
541
|
-
const range = this.horizontalRenderRange;
|
|
542
|
-
|
|
543
|
-
fns.forEach((fn) => {
|
|
544
|
-
raf(() => {
|
|
545
|
-
if (this.destroyed) {
|
|
546
|
-
return;
|
|
547
|
-
}
|
|
548
|
-
// #check-for-presence - see above note
|
|
549
|
-
if (fns.has(fn)) {
|
|
550
|
-
fn([range.startIndex, range.endIndex]);
|
|
551
|
-
}
|
|
552
|
-
});
|
|
553
|
-
});
|
|
554
|
-
};
|
|
555
|
-
|
|
556
|
-
private notifyScrollChange() {
|
|
557
|
-
if (this.destroyed) {
|
|
558
|
-
return;
|
|
559
|
-
}
|
|
560
|
-
const { scrollPosition } = this;
|
|
561
|
-
|
|
562
|
-
const fns = this.onScrollFns;
|
|
563
|
-
for (let i = 0, len = fns.length; i < len; i++) {
|
|
564
|
-
fns[i](scrollPosition);
|
|
565
|
-
}
|
|
566
|
-
}
|
|
567
|
-
|
|
568
|
-
private computeDirectionalRenderCount = (
|
|
569
|
-
direction: 'horizontal' | 'vertical',
|
|
570
|
-
itemSize: number | ItemSizeFunction,
|
|
571
|
-
count: number,
|
|
572
|
-
theSize: Size,
|
|
573
|
-
) => {
|
|
574
|
-
let renderCount = 0;
|
|
575
|
-
|
|
576
|
-
let size = direction === 'horizontal' ? theSize.width : theSize.height;
|
|
577
|
-
|
|
578
|
-
size -= this.getFixedSize(direction);
|
|
579
|
-
|
|
580
|
-
if (typeof itemSize === 'function') {
|
|
581
|
-
const sizes = [];
|
|
582
|
-
for (let i = 0; i < count; i++) {
|
|
583
|
-
sizes.push(this.getItemSize(i, direction));
|
|
584
|
-
}
|
|
585
|
-
sizes.sort(SORT_ASC);
|
|
586
|
-
let sum = 0;
|
|
587
|
-
for (let i = 0; i < count; i++) {
|
|
588
|
-
sum += sizes[i];
|
|
589
|
-
|
|
590
|
-
renderCount++;
|
|
591
|
-
if (sum > size) {
|
|
592
|
-
break;
|
|
593
|
-
}
|
|
594
|
-
}
|
|
595
|
-
renderCount += 1;
|
|
596
|
-
} else {
|
|
597
|
-
renderCount = (itemSize ? Math.ceil(size / itemSize) : 0) + 1;
|
|
598
|
-
}
|
|
599
|
-
|
|
600
|
-
renderCount = Math.min(count, renderCount);
|
|
601
|
-
|
|
602
|
-
return renderCount;
|
|
603
|
-
};
|
|
604
|
-
|
|
605
|
-
getFixedSize(direction: 'horizontal' | 'vertical') {
|
|
606
|
-
return direction === 'horizontal'
|
|
607
|
-
? this.getFixedStartColsWidth() + this.getFixedEndColsWidth()
|
|
608
|
-
: this.getFixedStartRowsHeight() + this.getFixedEndRowsHeight();
|
|
609
|
-
}
|
|
610
|
-
getFixedStartSize(direction: 'horizontal' | 'vertical') {
|
|
611
|
-
return direction === 'horizontal'
|
|
612
|
-
? this.getFixedStartColsWidth()
|
|
613
|
-
: this.getFixedStartRowsHeight();
|
|
614
|
-
}
|
|
615
|
-
getFixedEndSize(direction: 'horizontal' | 'vertical') {
|
|
616
|
-
return direction === 'horizontal'
|
|
617
|
-
? this.getFixedEndColsWidth()
|
|
618
|
-
: this.getFixedEndRowsHeight();
|
|
619
|
-
}
|
|
620
|
-
|
|
621
|
-
isColFixedEnd = (colIndex: number) => {
|
|
622
|
-
if (!this.fixedColsEnd) {
|
|
623
|
-
return false;
|
|
624
|
-
}
|
|
625
|
-
|
|
626
|
-
return colIndex >= this.cols - this.fixedColsEnd;
|
|
627
|
-
};
|
|
628
|
-
isColFixedStart = (colIndex: number) => {
|
|
629
|
-
if (!this.fixedColsStart) {
|
|
630
|
-
return false;
|
|
631
|
-
}
|
|
632
|
-
|
|
633
|
-
return colIndex < this.fixedColsStart;
|
|
634
|
-
};
|
|
635
|
-
|
|
636
|
-
isRowFixedEnd = (rowIndex: number) => {
|
|
637
|
-
if (!this.fixedRowsEnd) {
|
|
638
|
-
return false;
|
|
639
|
-
}
|
|
640
|
-
|
|
641
|
-
return rowIndex >= this.rows - this.fixedRowsEnd;
|
|
642
|
-
};
|
|
643
|
-
isRowFixedStart = (rowIndex: number) => {
|
|
644
|
-
if (!this.fixedRowsStart) {
|
|
645
|
-
return false;
|
|
646
|
-
}
|
|
647
|
-
|
|
648
|
-
return rowIndex < this.fixedRowsStart;
|
|
649
|
-
};
|
|
650
|
-
|
|
651
|
-
isColFixed = (colIndex: number) => {
|
|
652
|
-
return this.isColFixedStart(colIndex) || this.isColFixedEnd(colIndex);
|
|
653
|
-
};
|
|
654
|
-
|
|
655
|
-
isRowFixed = (rowIndex: number) => {
|
|
656
|
-
return this.isRowFixedStart(rowIndex) || this.isRowFixedEnd(rowIndex);
|
|
657
|
-
};
|
|
658
|
-
|
|
659
|
-
getFixedEndColsWidth = () => {
|
|
660
|
-
if (!this.fixedColsEnd) {
|
|
661
|
-
return 0;
|
|
662
|
-
}
|
|
663
|
-
|
|
664
|
-
let sum = 0;
|
|
665
|
-
|
|
666
|
-
for (let i = this.cols - this.fixedColsEnd; i < this.cols; i++) {
|
|
667
|
-
sum += this.getColWidth(i);
|
|
668
|
-
}
|
|
669
|
-
|
|
670
|
-
return sum;
|
|
671
|
-
};
|
|
672
|
-
|
|
673
|
-
/**
|
|
674
|
-
* Returns an array of offsets for all cols fixed at the end
|
|
675
|
-
*
|
|
676
|
-
* The order in the array is from leftmost col to the rightmost col
|
|
677
|
-
* The reference for offset is the left side of the table.
|
|
678
|
-
* The offsets take into account the scroll position and return the correct position.
|
|
679
|
-
*
|
|
680
|
-
* The indexes in the returned array are the absolute indexes of the cols, so the returned array is an array with holes
|
|
681
|
-
*
|
|
682
|
-
*/
|
|
683
|
-
getFixedEndColsOffsets = (
|
|
684
|
-
{ skipScroll }: { skipScroll: boolean } = { skipScroll: false },
|
|
685
|
-
): number[] => {
|
|
686
|
-
if (!this.fixedColsEnd) {
|
|
687
|
-
return [];
|
|
688
|
-
}
|
|
689
|
-
|
|
690
|
-
const { scrollLeft } = this.scrollPosition;
|
|
691
|
-
const { width } = this.getAvailableSize();
|
|
692
|
-
const offsets = [];
|
|
693
|
-
const widths = [];
|
|
694
|
-
let sum = 0;
|
|
695
|
-
|
|
696
|
-
for (
|
|
697
|
-
let colIndex = this.cols - this.fixedColsEnd;
|
|
698
|
-
colIndex < this.cols;
|
|
699
|
-
colIndex++
|
|
700
|
-
) {
|
|
701
|
-
const colWidth = this.getColWidth(colIndex);
|
|
702
|
-
widths.push(colWidth);
|
|
703
|
-
sum += colWidth;
|
|
704
|
-
}
|
|
705
|
-
|
|
706
|
-
const baseOffset = width - sum + (skipScroll ? 0 : scrollLeft);
|
|
707
|
-
|
|
708
|
-
sum = 0;
|
|
709
|
-
|
|
710
|
-
let index = 0;
|
|
711
|
-
for (
|
|
712
|
-
let colIndex = this.cols - this.fixedColsEnd;
|
|
713
|
-
colIndex < this.cols;
|
|
714
|
-
colIndex++
|
|
715
|
-
) {
|
|
716
|
-
const offset = baseOffset + sum;
|
|
717
|
-
offsets[colIndex] = offset;
|
|
718
|
-
sum += widths[index];
|
|
719
|
-
index++;
|
|
720
|
-
}
|
|
721
|
-
return offsets;
|
|
722
|
-
};
|
|
723
|
-
|
|
724
|
-
/**
|
|
725
|
-
* Returns an array of offsets for all rows fixed at the end
|
|
726
|
-
*
|
|
727
|
-
* The order in the array is from topmost row to the bottom-most row
|
|
728
|
-
* The reference for offset is the top side of the table.
|
|
729
|
-
* The offsets take into account the scroll position and return the correct position.
|
|
730
|
-
*
|
|
731
|
-
* The indexes in the returned array are the absolute indexes of the rows, so the returned array is an array with holes
|
|
732
|
-
*
|
|
733
|
-
*/
|
|
734
|
-
getFixedEndRowsOffsets = (
|
|
735
|
-
{ skipScroll }: { skipScroll: boolean } = { skipScroll: false },
|
|
736
|
-
): number[] => {
|
|
737
|
-
if (!this.fixedRowsEnd) {
|
|
738
|
-
return [];
|
|
739
|
-
}
|
|
740
|
-
|
|
741
|
-
const { scrollTop } = this.scrollPosition;
|
|
742
|
-
const { height } = this.getAvailableSize();
|
|
743
|
-
const offsets = [];
|
|
744
|
-
const heights = [];
|
|
745
|
-
let sum = 0;
|
|
746
|
-
|
|
747
|
-
for (
|
|
748
|
-
let rowIndex = this.rows - this.fixedRowsEnd;
|
|
749
|
-
rowIndex < this.rows;
|
|
750
|
-
rowIndex++
|
|
751
|
-
) {
|
|
752
|
-
const rowHeight = this.getRowHeight(rowIndex);
|
|
753
|
-
heights.push(rowHeight);
|
|
754
|
-
sum += rowHeight;
|
|
755
|
-
}
|
|
756
|
-
|
|
757
|
-
const baseOffset = height - sum + (skipScroll ? 0 : scrollTop);
|
|
758
|
-
|
|
759
|
-
sum = 0;
|
|
760
|
-
|
|
761
|
-
let index = 0;
|
|
762
|
-
for (
|
|
763
|
-
let rowIndex = this.rows - this.fixedRowsEnd;
|
|
764
|
-
rowIndex < this.rows;
|
|
765
|
-
rowIndex++
|
|
766
|
-
) {
|
|
767
|
-
const offset = baseOffset + sum;
|
|
768
|
-
offsets[rowIndex] = offset;
|
|
769
|
-
sum += heights[index];
|
|
770
|
-
index++;
|
|
771
|
-
}
|
|
772
|
-
return offsets;
|
|
773
|
-
};
|
|
774
|
-
|
|
775
|
-
getFixedStartColsWidth = () => {
|
|
776
|
-
if (!this.fixedColsStart) {
|
|
777
|
-
return 0;
|
|
778
|
-
}
|
|
779
|
-
|
|
780
|
-
let sum = 0;
|
|
781
|
-
|
|
782
|
-
for (let i = 0; i < this.fixedColsStart; i++) {
|
|
783
|
-
sum += this.getColWidth(i);
|
|
784
|
-
}
|
|
785
|
-
|
|
786
|
-
return sum;
|
|
787
|
-
};
|
|
788
|
-
|
|
789
|
-
getFixedEndRowsHeight = () => {
|
|
790
|
-
if (!this.fixedRowsEnd) {
|
|
791
|
-
return 0;
|
|
792
|
-
}
|
|
793
|
-
|
|
794
|
-
let sum = 0;
|
|
795
|
-
|
|
796
|
-
for (let i = this.rows - this.fixedRowsEnd; i < this.rows; i++) {
|
|
797
|
-
sum += this.getRowHeight(i);
|
|
798
|
-
}
|
|
799
|
-
|
|
800
|
-
return sum;
|
|
801
|
-
};
|
|
802
|
-
|
|
803
|
-
getFixedStartRowsHeight = () => {
|
|
804
|
-
if (!this.fixedRowsStart) {
|
|
805
|
-
return 0;
|
|
806
|
-
}
|
|
807
|
-
|
|
808
|
-
let sum = 0;
|
|
809
|
-
|
|
810
|
-
for (let i = 0; i < this.fixedRowsStart; i++) {
|
|
811
|
-
sum += this.getRowHeight(i);
|
|
812
|
-
}
|
|
813
|
-
|
|
814
|
-
return sum;
|
|
815
|
-
};
|
|
816
|
-
|
|
817
|
-
computeRenderCount = (which: WhichDirection = ALL_DIRECTIONS) => {
|
|
818
|
-
const recomputeHorizontal = which.horizontal;
|
|
819
|
-
const recomputeVertical = which.vertical;
|
|
820
|
-
|
|
821
|
-
let horizontalRenderCount = this.horizontalRenderCount || 0;
|
|
822
|
-
let verticalRenderCount = this.verticalRenderCount || 0;
|
|
823
|
-
|
|
824
|
-
if (recomputeHorizontal) {
|
|
825
|
-
horizontalRenderCount = this.computeDirectionalRenderCount(
|
|
826
|
-
'horizontal',
|
|
827
|
-
this.colWidth,
|
|
828
|
-
this.cols,
|
|
829
|
-
this.getAvailableSize(),
|
|
830
|
-
);
|
|
831
|
-
}
|
|
832
|
-
if (recomputeVertical) {
|
|
833
|
-
verticalRenderCount = this.computeDirectionalRenderCount(
|
|
834
|
-
'vertical',
|
|
835
|
-
this.rowHeight,
|
|
836
|
-
this.rows,
|
|
837
|
-
this.getAvailableSize(),
|
|
838
|
-
);
|
|
839
|
-
}
|
|
840
|
-
const result = {
|
|
841
|
-
horizontal: horizontalRenderCount,
|
|
842
|
-
vertical: verticalRenderCount,
|
|
843
|
-
};
|
|
844
|
-
return result;
|
|
845
|
-
};
|
|
846
|
-
|
|
847
|
-
setRenderCount = ({
|
|
848
|
-
horizontal,
|
|
849
|
-
vertical,
|
|
850
|
-
}: {
|
|
851
|
-
horizontal: number | undefined;
|
|
852
|
-
vertical: number | undefined;
|
|
853
|
-
}) => {
|
|
854
|
-
if (horizontal === undefined) {
|
|
855
|
-
horizontal = this.horizontalRenderCount;
|
|
856
|
-
}
|
|
857
|
-
if (vertical === undefined) {
|
|
858
|
-
vertical = this.verticalRenderCount;
|
|
859
|
-
}
|
|
860
|
-
const horizontalSame = horizontal === this.horizontalRenderCount;
|
|
861
|
-
const verticalSame = vertical === this.verticalRenderCount;
|
|
862
|
-
|
|
863
|
-
if (horizontalSame && verticalSame) {
|
|
864
|
-
return;
|
|
865
|
-
}
|
|
866
|
-
|
|
867
|
-
this.horizontalRenderCount = horizontal;
|
|
868
|
-
this.verticalRenderCount = vertical;
|
|
869
|
-
|
|
870
|
-
this.updateRenderRange({
|
|
871
|
-
horizontal: !horizontalSame,
|
|
872
|
-
vertical: !verticalSame,
|
|
873
|
-
});
|
|
874
|
-
|
|
875
|
-
this.notifyRenderCountChange();
|
|
876
|
-
};
|
|
877
|
-
|
|
878
|
-
private notifyRenderCountChange() {
|
|
879
|
-
if (this.destroyed) {
|
|
880
|
-
return;
|
|
881
|
-
}
|
|
882
|
-
const { horizontalRenderCount, verticalRenderCount } = this;
|
|
883
|
-
|
|
884
|
-
const renderCount = {
|
|
885
|
-
horizontal: horizontalRenderCount!,
|
|
886
|
-
vertical: verticalRenderCount!,
|
|
887
|
-
};
|
|
888
|
-
|
|
889
|
-
const fns = this.onRenderCountChangeFns;
|
|
890
|
-
|
|
891
|
-
fns.forEach((fn) => {
|
|
892
|
-
raf(() => {
|
|
893
|
-
if (this.destroyed) {
|
|
894
|
-
return;
|
|
895
|
-
}
|
|
896
|
-
// #check-for-presence - see above note
|
|
897
|
-
if (fns.has(fn)) {
|
|
898
|
-
fn(renderCount);
|
|
899
|
-
}
|
|
900
|
-
});
|
|
901
|
-
});
|
|
902
|
-
}
|
|
903
|
-
|
|
904
|
-
public updateFixedCells = (config: {
|
|
905
|
-
fixedColsStart?: number;
|
|
906
|
-
fixedColsEnd?: number;
|
|
907
|
-
fixedRowsStart?: number;
|
|
908
|
-
fixedRowsEnd?: number;
|
|
909
|
-
}) => {
|
|
910
|
-
if (config.fixedColsStart != this.fixedColsStart) {
|
|
911
|
-
this.fixedColsStart = config.fixedColsStart || 0;
|
|
912
|
-
}
|
|
913
|
-
if (config.fixedColsEnd != this.fixedColsEnd) {
|
|
914
|
-
this.fixedColsEnd = config.fixedColsEnd || 0;
|
|
915
|
-
}
|
|
916
|
-
if (config.fixedRowsStart != this.fixedRowsStart) {
|
|
917
|
-
this.fixedRowsStart = config.fixedRowsStart || 0;
|
|
918
|
-
}
|
|
919
|
-
if (config.fixedRowsEnd != this.fixedRowsEnd) {
|
|
920
|
-
this.fixedRowsEnd = config.fixedRowsEnd || 0;
|
|
921
|
-
}
|
|
922
|
-
};
|
|
923
|
-
|
|
924
|
-
public getFixedCellInfo = () => {
|
|
925
|
-
const { fixedRowsStart, fixedColsStart, fixedRowsEnd, fixedColsEnd } = this;
|
|
926
|
-
|
|
927
|
-
return {
|
|
928
|
-
fixedRowsStart,
|
|
929
|
-
fixedColsStart,
|
|
930
|
-
fixedRowsEnd,
|
|
931
|
-
fixedColsEnd,
|
|
932
|
-
};
|
|
933
|
-
};
|
|
934
|
-
|
|
935
|
-
public updateRenderRange = (which: WhichDirection = ALL_DIRECTIONS) => {
|
|
936
|
-
this.setRenderRange(this.computeRenderRange(which));
|
|
937
|
-
};
|
|
938
|
-
|
|
939
|
-
public getExtraSpanCellsForRange = ({
|
|
940
|
-
horizontal,
|
|
941
|
-
vertical,
|
|
942
|
-
}: {
|
|
943
|
-
horizontal: RenderRangeType;
|
|
944
|
-
vertical: RenderRangeType;
|
|
945
|
-
}) => {
|
|
946
|
-
const { colspan, rowspan } = this;
|
|
947
|
-
|
|
948
|
-
const extraCells: [number, number][] = [];
|
|
949
|
-
|
|
950
|
-
if (rowspan) {
|
|
951
|
-
const rowStart = vertical.startIndex;
|
|
952
|
-
|
|
953
|
-
const colStart = horizontal.startIndex;
|
|
954
|
-
const colEnd = horizontal.endIndex;
|
|
955
|
-
|
|
956
|
-
// for each rendered column, compute span for the cells in
|
|
957
|
-
// the first row in the render range
|
|
958
|
-
for (let colIndex = colStart; colIndex < colEnd; colIndex++) {
|
|
959
|
-
this.computeItemSpanUpTo(rowStart, colIndex, 'vertical');
|
|
960
|
-
|
|
961
|
-
const rowspanParent = this.rowspanParent.get(colIndex)!;
|
|
962
|
-
|
|
963
|
-
if (rowspanParent[rowStart] != rowStart) {
|
|
964
|
-
let rowIndex = rowStart;
|
|
965
|
-
while (rowspanParent[rowIndex] != rowIndex) {
|
|
966
|
-
rowIndex--;
|
|
967
|
-
}
|
|
968
|
-
|
|
969
|
-
extraCells.push([rowIndex, colIndex]);
|
|
970
|
-
}
|
|
971
|
-
}
|
|
972
|
-
}
|
|
973
|
-
|
|
974
|
-
if (colspan) {
|
|
975
|
-
const colStart = horizontal.startIndex;
|
|
976
|
-
|
|
977
|
-
const rowStart = vertical.startIndex;
|
|
978
|
-
const rowEnd = vertical.endIndex;
|
|
979
|
-
|
|
980
|
-
// for each rendered row, compute span for the cells in
|
|
981
|
-
// the first column in the render range
|
|
982
|
-
for (let rowIndex = rowStart; rowIndex < rowEnd; rowIndex++) {
|
|
983
|
-
this.computeItemSpanUpTo(rowIndex, colStart, 'horizontal');
|
|
984
|
-
|
|
985
|
-
const colspanParent = this.colspanParent.get(rowIndex)!;
|
|
986
|
-
|
|
987
|
-
if (colspanParent[colStart] != colStart) {
|
|
988
|
-
let colIndex = colStart;
|
|
989
|
-
while (colspanParent[colIndex] != colIndex) {
|
|
990
|
-
colIndex--;
|
|
991
|
-
}
|
|
992
|
-
|
|
993
|
-
extraCells.push([rowIndex, colIndex]);
|
|
994
|
-
}
|
|
995
|
-
}
|
|
996
|
-
}
|
|
997
|
-
|
|
998
|
-
return extraCells;
|
|
999
|
-
};
|
|
1000
|
-
|
|
1001
|
-
computeRenderRange = (which: WhichDirection = ALL_DIRECTIONS) => {
|
|
1002
|
-
const horizontal = which.horizontal
|
|
1003
|
-
? this.computeDirectionalRenderRange('horizontal')
|
|
1004
|
-
: this.horizontalRenderRange;
|
|
1005
|
-
|
|
1006
|
-
const vertical = which.vertical
|
|
1007
|
-
? this.computeDirectionalRenderRange('vertical')
|
|
1008
|
-
: this.verticalRenderRange;
|
|
1009
|
-
|
|
1010
|
-
return {
|
|
1011
|
-
horizontal,
|
|
1012
|
-
vertical,
|
|
1013
|
-
extraCells: this.getExtraSpanCellsForRange({ horizontal, vertical }),
|
|
1014
|
-
};
|
|
1015
|
-
};
|
|
1016
|
-
|
|
1017
|
-
computeDirectionalRenderRange = (direction: 'horizontal' | 'vertical') => {
|
|
1018
|
-
const renderCount =
|
|
1019
|
-
direction === 'horizontal'
|
|
1020
|
-
? this.horizontalRenderCount
|
|
1021
|
-
: this.verticalRenderCount;
|
|
1022
|
-
const count = direction === 'horizontal' ? this.cols : this.rows;
|
|
1023
|
-
|
|
1024
|
-
if (!renderCount) {
|
|
1025
|
-
return {
|
|
1026
|
-
startIndex: 0,
|
|
1027
|
-
endIndex: 0,
|
|
1028
|
-
};
|
|
1029
|
-
}
|
|
1030
|
-
|
|
1031
|
-
const fixedStartIndex =
|
|
1032
|
-
(direction === 'horizontal'
|
|
1033
|
-
? this.fixedColsStart
|
|
1034
|
-
: this.fixedRowsStart) || 0;
|
|
1035
|
-
|
|
1036
|
-
let scrollPositionForDirection =
|
|
1037
|
-
direction === 'horizontal'
|
|
1038
|
-
? this.scrollPosition.scrollLeft
|
|
1039
|
-
: this.scrollPosition.scrollTop;
|
|
1040
|
-
|
|
1041
|
-
scrollPositionForDirection += this.getFixedStartSize(direction);
|
|
1042
|
-
|
|
1043
|
-
let startIndex = this.getItemAt(scrollPositionForDirection, direction);
|
|
1044
|
-
|
|
1045
|
-
let endIndex = startIndex + renderCount;
|
|
1046
|
-
|
|
1047
|
-
const theEnd = Math.max(
|
|
1048
|
-
fixedStartIndex,
|
|
1049
|
-
count -
|
|
1050
|
-
(direction === 'horizontal' ? this.fixedColsEnd : this.fixedRowsEnd),
|
|
1051
|
-
);
|
|
1052
|
-
|
|
1053
|
-
if (endIndex > theEnd) {
|
|
1054
|
-
endIndex = theEnd;
|
|
1055
|
-
startIndex = Math.max(fixedStartIndex, endIndex - renderCount);
|
|
1056
|
-
}
|
|
1057
|
-
|
|
1058
|
-
/**
|
|
1059
|
-
*
|
|
1060
|
-
//TODO continue here we can avoid doing this expand here
|
|
1061
|
-
// if the renderStartIndex row is spanned over, we only need to render the span parent instead
|
|
1062
|
-
// of the current row - so big wins
|
|
1063
|
-
if (this.options.itemSpan) {
|
|
1064
|
-
this.computeItemSpanUpTo(renderStartIndex);
|
|
1065
|
-
|
|
1066
|
-
while (this.itemSpanParent[renderStartIndex] != renderStartIndex) {
|
|
1067
|
-
renderStartIndex--;
|
|
1068
|
-
}
|
|
1069
|
-
}
|
|
1070
|
-
*/
|
|
1071
|
-
return {
|
|
1072
|
-
startIndex,
|
|
1073
|
-
endIndex,
|
|
1074
|
-
};
|
|
1075
|
-
};
|
|
1076
|
-
|
|
1077
|
-
getItemAt = (scrollPos: number, direction: 'horizontal' | 'vertical') => {
|
|
1078
|
-
const itemSize =
|
|
1079
|
-
direction === 'horizontal' ? this.colWidth : this.rowHeight;
|
|
1080
|
-
const count = direction === 'horizontal' ? this.cols : this.rows;
|
|
1081
|
-
|
|
1082
|
-
if (typeof itemSize !== 'function') {
|
|
1083
|
-
return Math.min(Math.max(0, Math.floor(scrollPos / itemSize)), count - 1);
|
|
1084
|
-
}
|
|
1085
|
-
|
|
1086
|
-
const itemOffsetCache =
|
|
1087
|
-
direction === 'horizontal' ? this.colOffsetCache : this.rowOffsetCache;
|
|
1088
|
-
const itemSizeCache =
|
|
1089
|
-
direction === 'horizontal' ? this.colWidthCache : this.rowHeightCache;
|
|
1090
|
-
|
|
1091
|
-
const lastOffsetIndex = itemOffsetCache.length - 1;
|
|
1092
|
-
let lastSizeIndex = itemSizeCache.length - 1;
|
|
1093
|
-
let lastOffset = itemOffsetCache[lastOffsetIndex];
|
|
1094
|
-
|
|
1095
|
-
let _prev: number;
|
|
1096
|
-
|
|
1097
|
-
while (lastOffset < scrollPos) {
|
|
1098
|
-
if (lastOffsetIndex >= count) {
|
|
1099
|
-
return count - 1;
|
|
1100
|
-
}
|
|
1101
|
-
lastSizeIndex += 1;
|
|
1102
|
-
this.computeCacheFor(lastSizeIndex, direction);
|
|
1103
|
-
_prev = lastOffset;
|
|
1104
|
-
lastOffset = itemOffsetCache[lastSizeIndex];
|
|
1105
|
-
if (_prev === lastOffset && _prev != 0) {
|
|
1106
|
-
return count - 1;
|
|
1107
|
-
}
|
|
1108
|
-
}
|
|
1109
|
-
|
|
1110
|
-
const searchResult = binarySearch(itemOffsetCache, scrollPos, SORT_ASC);
|
|
1111
|
-
|
|
1112
|
-
if (searchResult >= 0) {
|
|
1113
|
-
return searchResult;
|
|
1114
|
-
}
|
|
1115
|
-
|
|
1116
|
-
return ~searchResult - 1;
|
|
1117
|
-
|
|
1118
|
-
return 0;
|
|
1119
|
-
};
|
|
1120
|
-
|
|
1121
|
-
public getCellOffset = (rowIndex: number, colIndex: number) => {
|
|
1122
|
-
return {
|
|
1123
|
-
x: this.getItemOffsetFor(colIndex, 'horizontal'),
|
|
1124
|
-
y: this.getItemOffsetFor(rowIndex, 'vertical'),
|
|
1125
|
-
};
|
|
1126
|
-
};
|
|
1127
|
-
|
|
1128
|
-
public getItemOffsetFor = (
|
|
1129
|
-
itemIndex: number,
|
|
1130
|
-
direction: 'horizontal' | 'vertical',
|
|
1131
|
-
): number => {
|
|
1132
|
-
const itemSize =
|
|
1133
|
-
direction === 'horizontal' ? this.colWidth : this.rowHeight;
|
|
1134
|
-
if (typeof itemSize !== 'function') {
|
|
1135
|
-
return itemIndex * itemSize;
|
|
1136
|
-
}
|
|
1137
|
-
const itemOffsetCache =
|
|
1138
|
-
direction === 'horizontal' ? this.colOffsetCache : this.rowOffsetCache;
|
|
1139
|
-
const itemSizeCache =
|
|
1140
|
-
direction === 'horizontal' ? this.colWidthCache : this.rowHeightCache;
|
|
1141
|
-
|
|
1142
|
-
let result = itemOffsetCache[itemIndex];
|
|
1143
|
-
|
|
1144
|
-
if (result == null) {
|
|
1145
|
-
let lastSizeIndex = itemSizeCache.length - 1;
|
|
1146
|
-
|
|
1147
|
-
while (lastSizeIndex < itemIndex) {
|
|
1148
|
-
lastSizeIndex += 1;
|
|
1149
|
-
this.computeCacheFor(lastSizeIndex, direction);
|
|
1150
|
-
}
|
|
1151
|
-
|
|
1152
|
-
result = itemOffsetCache[itemIndex];
|
|
1153
|
-
}
|
|
1154
|
-
return result;
|
|
1155
|
-
};
|
|
1156
|
-
|
|
1157
|
-
private computeCacheFor = (
|
|
1158
|
-
itemIndex: number,
|
|
1159
|
-
direction: 'horizontal' | 'vertical',
|
|
1160
|
-
) => {
|
|
1161
|
-
const itemSizeValueOrFn =
|
|
1162
|
-
direction === 'horizontal' ? this.colWidth : this.rowHeight;
|
|
1163
|
-
const itemSizeCache =
|
|
1164
|
-
direction === 'horizontal' ? this.colWidthCache : this.rowHeightCache;
|
|
1165
|
-
const itemOffsetCache =
|
|
1166
|
-
direction === 'horizontal' ? this.colOffsetCache : this.rowOffsetCache;
|
|
1167
|
-
if (typeof itemSizeValueOrFn !== 'function') {
|
|
1168
|
-
return;
|
|
1169
|
-
}
|
|
1170
|
-
|
|
1171
|
-
const itemSize: number = itemSizeValueOrFn(itemIndex);
|
|
1172
|
-
itemSizeCache[itemIndex] = itemSize;
|
|
1173
|
-
|
|
1174
|
-
if (itemIndex > 0) {
|
|
1175
|
-
const prevOffset = itemOffsetCache[itemIndex - 1];
|
|
1176
|
-
const prevSize = itemSizeCache[itemIndex - 1];
|
|
1177
|
-
if (prevOffset == null) {
|
|
1178
|
-
console.error(
|
|
1179
|
-
`Offset was not available for ${
|
|
1180
|
-
direction === 'horizontal' ? 'col' : 'row'
|
|
1181
|
-
} ${itemIndex - 1}`,
|
|
1182
|
-
);
|
|
1183
|
-
}
|
|
1184
|
-
if (prevSize == null) {
|
|
1185
|
-
console.error(
|
|
1186
|
-
`Size was not available for ${
|
|
1187
|
-
direction === 'horizontal' ? 'col' : 'row'
|
|
1188
|
-
} ${itemIndex - 1}`,
|
|
1189
|
-
);
|
|
1190
|
-
}
|
|
1191
|
-
const offset = prevOffset + prevSize;
|
|
1192
|
-
itemOffsetCache[itemIndex] = offset;
|
|
1193
|
-
}
|
|
1194
|
-
};
|
|
1195
|
-
|
|
1196
|
-
private getItemSizeCacheFor(
|
|
1197
|
-
itemIndex: number,
|
|
1198
|
-
direction: 'horizontal' | 'vertical',
|
|
1199
|
-
): number {
|
|
1200
|
-
return (
|
|
1201
|
-
direction === 'horizontal' ? this.colWidthCache : this.rowHeightCache
|
|
1202
|
-
)[itemIndex];
|
|
1203
|
-
}
|
|
1204
|
-
|
|
1205
|
-
private computeItemSpanUpTo = (
|
|
1206
|
-
rowIndex: number,
|
|
1207
|
-
colIndex: number,
|
|
1208
|
-
direction: 'horizontal' | 'vertical',
|
|
1209
|
-
) => {
|
|
1210
|
-
const itemIndex = direction === 'horizontal' ? colIndex : rowIndex;
|
|
1211
|
-
const otherIndex = direction === 'horizontal' ? rowIndex : colIndex;
|
|
1212
|
-
|
|
1213
|
-
const count = direction === 'horizontal' ? this.cols : this.rows;
|
|
1214
|
-
const itemSpan = direction === 'horizontal' ? this.colspan : this.rowspan;
|
|
1215
|
-
|
|
1216
|
-
if (!itemSpan) {
|
|
1217
|
-
return;
|
|
1218
|
-
}
|
|
1219
|
-
|
|
1220
|
-
const directionCache =
|
|
1221
|
-
direction === 'horizontal' ? this.colspanParent : this.rowspanParent;
|
|
1222
|
-
if (!directionCache.has(otherIndex)) {
|
|
1223
|
-
directionCache.set(otherIndex, []);
|
|
1224
|
-
}
|
|
1225
|
-
|
|
1226
|
-
const directionSpanResult =
|
|
1227
|
-
direction === 'horizontal' ? this.colspanValue : this.rowspanValue;
|
|
1228
|
-
|
|
1229
|
-
if (!directionSpanResult.has(otherIndex)) {
|
|
1230
|
-
directionSpanResult.set(otherIndex, []);
|
|
1231
|
-
}
|
|
1232
|
-
|
|
1233
|
-
const cache = directionCache.get(otherIndex)!;
|
|
1234
|
-
const spanResultArr = directionSpanResult.get(otherIndex)!;
|
|
1235
|
-
|
|
1236
|
-
if (cache[itemIndex] === undefined) {
|
|
1237
|
-
let i = cache.length;
|
|
1238
|
-
const lastIndex = count ? Math.min(itemIndex, count - 1) : 0;
|
|
1239
|
-
|
|
1240
|
-
const cell = { rowIndex, colIndex };
|
|
1241
|
-
|
|
1242
|
-
for (; i <= lastIndex; i++) {
|
|
1243
|
-
if (cache[i] === undefined) {
|
|
1244
|
-
cell[direction === 'horizontal' ? 'colIndex' : 'rowIndex'] = i;
|
|
1245
|
-
let spanValue = itemSpan(cell);
|
|
1246
|
-
|
|
1247
|
-
if (__DEV__ && spanValue < 1) {
|
|
1248
|
-
this.debug(
|
|
1249
|
-
`${
|
|
1250
|
-
direction === 'horizontal' ? 'colspan' : 'rowspan'
|
|
1251
|
-
} cannot be less than 1 - got %d for index %d`,
|
|
1252
|
-
spanValue,
|
|
1253
|
-
i,
|
|
1254
|
-
);
|
|
1255
|
-
}
|
|
1256
|
-
// this is it's own span parent
|
|
1257
|
-
cache[i] = i;
|
|
1258
|
-
spanResultArr[i] = spanValue;
|
|
1259
|
-
|
|
1260
|
-
let spannedItemIndex: number = i;
|
|
1261
|
-
while (spanValue > 1) {
|
|
1262
|
-
spannedItemIndex += 1;
|
|
1263
|
-
cache[spannedItemIndex] = i;
|
|
1264
|
-
spanResultArr[spannedItemIndex] = 0;
|
|
1265
|
-
|
|
1266
|
-
spanValue -= 1;
|
|
1267
|
-
}
|
|
1268
|
-
}
|
|
1269
|
-
}
|
|
1270
|
-
}
|
|
1271
|
-
};
|
|
1272
|
-
|
|
1273
|
-
private getCellSpan = (
|
|
1274
|
-
rowIndex: number,
|
|
1275
|
-
colIndex: number,
|
|
1276
|
-
direction: 'horizontal' | 'vertical',
|
|
1277
|
-
) => {
|
|
1278
|
-
const itemSpan = direction === 'horizontal' ? this.colspan : this.rowspan;
|
|
1279
|
-
const itemIndex = direction === 'horizontal' ? colIndex : rowIndex;
|
|
1280
|
-
const otherIndex = direction === 'horizontal' ? rowIndex : colIndex;
|
|
1281
|
-
|
|
1282
|
-
if (!itemSpan) {
|
|
1283
|
-
return 1;
|
|
1284
|
-
}
|
|
1285
|
-
const directionSpanValue =
|
|
1286
|
-
direction === 'horizontal' ? this.colspanValue : this.rowspanValue;
|
|
1287
|
-
|
|
1288
|
-
let itemSpanValue = directionSpanValue.get(otherIndex);
|
|
1289
|
-
|
|
1290
|
-
if (!itemSpanValue || itemSpanValue[itemIndex] === undefined) {
|
|
1291
|
-
this.computeItemSpanUpTo(rowIndex, colIndex, direction);
|
|
1292
|
-
}
|
|
1293
|
-
if (!itemSpanValue) {
|
|
1294
|
-
itemSpanValue = directionSpanValue.get(otherIndex);
|
|
1295
|
-
}
|
|
1296
|
-
|
|
1297
|
-
return itemSpanValue![itemIndex] || 1;
|
|
1298
|
-
};
|
|
1299
|
-
|
|
1300
|
-
getRowspan = (rowIndex: number, colIndex: number) => {
|
|
1301
|
-
return this.getCellSpan(rowIndex, colIndex, 'vertical');
|
|
1302
|
-
};
|
|
1303
|
-
getColspan = (rowIndex: number, colIndex: number) => {
|
|
1304
|
-
return this.getCellSpan(rowIndex, colIndex, 'horizontal');
|
|
1305
|
-
};
|
|
1306
|
-
|
|
1307
|
-
getRowspanParent = (rowIndex: number, colIndex: number) => {
|
|
1308
|
-
return this.getItemSpanParent(rowIndex, colIndex, 'vertical');
|
|
1309
|
-
};
|
|
1310
|
-
getColspanParent = (rowIndex: number, colIndex: number) => {
|
|
1311
|
-
return this.getItemSpanParent(rowIndex, colIndex, 'horizontal');
|
|
1312
|
-
};
|
|
1313
|
-
|
|
1314
|
-
getItemSpanParent = (
|
|
1315
|
-
rowIndex: number,
|
|
1316
|
-
colIndex: number,
|
|
1317
|
-
direction: 'horizontal' | 'vertical',
|
|
1318
|
-
) => {
|
|
1319
|
-
const itemSpan = direction == 'horizontal' ? this.colspan : this.rowspan;
|
|
1320
|
-
const itemIndex = direction === 'horizontal' ? colIndex : rowIndex;
|
|
1321
|
-
const otherIndex = direction === 'horizontal' ? rowIndex : colIndex;
|
|
1322
|
-
if (!itemSpan) {
|
|
1323
|
-
return itemIndex;
|
|
1324
|
-
}
|
|
1325
|
-
const directionSpanParent =
|
|
1326
|
-
direction === 'horizontal' ? this.colspanParent : this.rowspanParent;
|
|
1327
|
-
let itemSpanParent = directionSpanParent.get(otherIndex);
|
|
1328
|
-
if (!itemSpanParent || itemSpanParent[itemIndex] === undefined) {
|
|
1329
|
-
this.computeItemSpanUpTo(rowIndex, colIndex, direction);
|
|
1330
|
-
}
|
|
1331
|
-
if (!itemSpanParent) {
|
|
1332
|
-
itemSpanParent = directionSpanParent.get(otherIndex);
|
|
1333
|
-
}
|
|
1334
|
-
return itemSpanParent![itemIndex];
|
|
1335
|
-
};
|
|
1336
|
-
|
|
1337
|
-
public getRowHeightWithSpan = (
|
|
1338
|
-
rowIndex: number,
|
|
1339
|
-
colIndex: number,
|
|
1340
|
-
rowspan: number,
|
|
1341
|
-
) => {
|
|
1342
|
-
return this.getItemSizeWithSpan(rowIndex, colIndex, rowspan, 'vertical');
|
|
1343
|
-
};
|
|
1344
|
-
public getColWidthWithSpan = (
|
|
1345
|
-
rowIndex: number,
|
|
1346
|
-
colIndex: number,
|
|
1347
|
-
colspan: number,
|
|
1348
|
-
) => {
|
|
1349
|
-
return this.getItemSizeWithSpan(rowIndex, colIndex, colspan, 'horizontal');
|
|
1350
|
-
};
|
|
1351
|
-
|
|
1352
|
-
private getItemSizeWithSpan = (
|
|
1353
|
-
rowIndex: number,
|
|
1354
|
-
colIndex: number,
|
|
1355
|
-
itemSpan: number,
|
|
1356
|
-
direction: 'horizontal' | 'vertical',
|
|
1357
|
-
) => {
|
|
1358
|
-
let itemIndex = direction === 'horizontal' ? colIndex : rowIndex;
|
|
1359
|
-
let itemSize = this.getItemSize(itemIndex, direction);
|
|
1360
|
-
|
|
1361
|
-
while (itemSpan > 1) {
|
|
1362
|
-
itemIndex += 1;
|
|
1363
|
-
itemSpan -= 1;
|
|
1364
|
-
itemSize += this.getItemSize(itemIndex, direction);
|
|
1365
|
-
}
|
|
1366
|
-
|
|
1367
|
-
return itemSize;
|
|
1368
|
-
};
|
|
1369
|
-
|
|
1370
|
-
getRowHeight = (rowIndex: number) => {
|
|
1371
|
-
return this.getItemSize(rowIndex, 'vertical');
|
|
1372
|
-
};
|
|
1373
|
-
|
|
1374
|
-
getColWidth = (colIndex: number) => {
|
|
1375
|
-
return this.getItemSize(colIndex, 'horizontal');
|
|
1376
|
-
};
|
|
1377
|
-
|
|
1378
|
-
/**
|
|
1379
|
-
* For now, this doesn't take into account the row/colspan, and it's okay not to
|
|
1380
|
-
* @param itemIndex
|
|
1381
|
-
* @returns the size of the specified item
|
|
1382
|
-
*/
|
|
1383
|
-
getItemSize = (
|
|
1384
|
-
itemIndex: number,
|
|
1385
|
-
direction: 'horizontal' | 'vertical',
|
|
1386
|
-
): number => {
|
|
1387
|
-
const count = direction === 'horizontal' ? this.cols : this.rows;
|
|
1388
|
-
const itemSize =
|
|
1389
|
-
direction === 'horizontal' ? this.colWidth : this.rowHeight;
|
|
1390
|
-
|
|
1391
|
-
if (typeof itemSize !== 'function') {
|
|
1392
|
-
return itemSize;
|
|
1393
|
-
}
|
|
1394
|
-
|
|
1395
|
-
// we make sure when we request the size for an item at a given index
|
|
1396
|
-
// all previous items have their size cached
|
|
1397
|
-
|
|
1398
|
-
// we could take a more optimized approach, but for now, we only have
|
|
1399
|
-
// itemMainAxisSize as a function for column virtualization
|
|
1400
|
-
// which doesn't need a more performant approach right now, as we dont expect a column count > 10k
|
|
1401
|
-
|
|
1402
|
-
let cachedSize = this.getItemSizeCacheFor(itemIndex, direction);
|
|
1403
|
-
|
|
1404
|
-
const itemSizeCache =
|
|
1405
|
-
direction === 'horizontal' ? this.colWidthCache : this.rowHeightCache;
|
|
1406
|
-
if (cachedSize === undefined) {
|
|
1407
|
-
let i = itemSizeCache.length;
|
|
1408
|
-
const lastIndex = Math.min(itemIndex, count - 1);
|
|
1409
|
-
|
|
1410
|
-
for (; i <= lastIndex; i++) {
|
|
1411
|
-
this.computeCacheFor(i, direction);
|
|
1412
|
-
}
|
|
1413
|
-
cachedSize = this.getItemSizeCacheFor(itemIndex, direction);
|
|
1414
|
-
}
|
|
1415
|
-
|
|
1416
|
-
return cachedSize;
|
|
1417
|
-
};
|
|
1418
|
-
|
|
1419
|
-
getTotalSize = () => {
|
|
1420
|
-
return {
|
|
1421
|
-
height: this.getTotalSizeFor('vertical'),
|
|
1422
|
-
width: this.getTotalSizeFor('horizontal'),
|
|
1423
|
-
};
|
|
1424
|
-
};
|
|
1425
|
-
|
|
1426
|
-
public getTotalSizeFor = (direction: 'horizontal' | 'vertical') => {
|
|
1427
|
-
const count = direction === 'horizontal' ? this.cols : this.rows;
|
|
1428
|
-
const itemSize =
|
|
1429
|
-
direction === 'horizontal' ? this.colWidth : this.rowHeight;
|
|
1430
|
-
const totalSize =
|
|
1431
|
-
direction === 'horizontal'
|
|
1432
|
-
? this.horizontalTotalSize
|
|
1433
|
-
: this.verticalTotalSize;
|
|
1434
|
-
|
|
1435
|
-
if (typeof itemSize !== 'function') {
|
|
1436
|
-
return itemSize * count;
|
|
1437
|
-
}
|
|
1438
|
-
|
|
1439
|
-
if (totalSize !== 0 && !isNaN(totalSize)) {
|
|
1440
|
-
return totalSize;
|
|
1441
|
-
}
|
|
1442
|
-
|
|
1443
|
-
const itemOffsetCache =
|
|
1444
|
-
direction === 'horizontal' ? this.colOffsetCache : this.rowOffsetCache;
|
|
1445
|
-
const lastItemSize = count ? this.getItemSize(count - 1, direction) : 0;
|
|
1446
|
-
|
|
1447
|
-
const lastItemOffset = count ? itemOffsetCache[count - 1] : 0;
|
|
1448
|
-
|
|
1449
|
-
const result = lastItemSize + lastItemOffset;
|
|
1450
|
-
|
|
1451
|
-
if (direction === 'horizontal') {
|
|
1452
|
-
this.horizontalTotalSize = result;
|
|
1453
|
-
} else {
|
|
1454
|
-
this.verticalTotalSize = result;
|
|
1455
|
-
}
|
|
1456
|
-
|
|
1457
|
-
return result;
|
|
1458
|
-
};
|
|
1459
|
-
|
|
1460
|
-
setRenderRange = ({
|
|
1461
|
-
horizontal,
|
|
1462
|
-
vertical,
|
|
1463
|
-
extraCells,
|
|
1464
|
-
}: {
|
|
1465
|
-
horizontal: RenderRangeType;
|
|
1466
|
-
vertical: RenderRangeType;
|
|
1467
|
-
extraCells?: [number, number][];
|
|
1468
|
-
}) => {
|
|
1469
|
-
let horizontalChange = false;
|
|
1470
|
-
if (
|
|
1471
|
-
horizontal.startIndex !== this.horizontalRenderRange.startIndex ||
|
|
1472
|
-
horizontal.endIndex !== this.horizontalRenderRange.endIndex
|
|
1473
|
-
) {
|
|
1474
|
-
this.horizontalRenderRange = horizontal;
|
|
1475
|
-
horizontalChange = true;
|
|
1476
|
-
}
|
|
1477
|
-
|
|
1478
|
-
let verticalChange = false;
|
|
1479
|
-
if (
|
|
1480
|
-
vertical.startIndex !== this.verticalRenderRange.startIndex ||
|
|
1481
|
-
vertical.endIndex !== this.verticalRenderRange.endIndex
|
|
1482
|
-
) {
|
|
1483
|
-
this.verticalRenderRange = vertical;
|
|
1484
|
-
verticalChange = true;
|
|
1485
|
-
}
|
|
1486
|
-
|
|
1487
|
-
this.extraSpanCells = extraCells || [];
|
|
1488
|
-
|
|
1489
|
-
if (horizontalChange || verticalChange) {
|
|
1490
|
-
this.notifyRenderRangeChange();
|
|
1491
|
-
}
|
|
1492
|
-
if (verticalChange) {
|
|
1493
|
-
this.notifyVerticalRenderRangeChange();
|
|
1494
|
-
}
|
|
1495
|
-
if (horizontalChange) {
|
|
1496
|
-
this.notifyHorizontalRenderRangeChange();
|
|
1497
|
-
}
|
|
1498
|
-
};
|
|
1499
|
-
|
|
1500
|
-
getRenderRangeCellCount = getRenderRangeCellCount;
|
|
1501
|
-
|
|
1502
|
-
getExtraCells = (): [number, number][] => {
|
|
1503
|
-
return this.extraSpanCells;
|
|
1504
|
-
};
|
|
1505
|
-
|
|
1506
|
-
getScrollPosition = () => {
|
|
1507
|
-
return this.scrollPosition;
|
|
1508
|
-
};
|
|
1509
|
-
|
|
1510
|
-
getRenderRange = () => {
|
|
1511
|
-
return {
|
|
1512
|
-
start: [
|
|
1513
|
-
this.verticalRenderRange.startIndex,
|
|
1514
|
-
this.horizontalRenderRange.startIndex,
|
|
1515
|
-
],
|
|
1516
|
-
end: [
|
|
1517
|
-
this.verticalRenderRange.endIndex,
|
|
1518
|
-
this.horizontalRenderRange.endIndex,
|
|
1519
|
-
],
|
|
1520
|
-
} as TableRenderRange;
|
|
1521
|
-
};
|
|
1522
|
-
|
|
1523
|
-
onScroll = (fn: OnScrollFn) => {
|
|
1524
|
-
this.onScrollFns.push(fn);
|
|
1525
|
-
return () => {
|
|
1526
|
-
this.onScrollFns = this.onScrollFns.filter((f) => f !== fn);
|
|
1527
|
-
};
|
|
1528
|
-
};
|
|
1529
|
-
|
|
1530
|
-
onScrollStart = (fn: VoidFunction) => {
|
|
1531
|
-
this.onScrollStartFns.push(fn);
|
|
1532
|
-
return () => {
|
|
1533
|
-
this.onScrollStartFns = this.onScrollStartFns.filter((f) => f !== fn);
|
|
1534
|
-
};
|
|
1535
|
-
};
|
|
1536
|
-
|
|
1537
|
-
onScrollStop = (fn: (scrollPos: ScrollPosition) => void) => {
|
|
1538
|
-
this.onScrollStopFns.push(fn);
|
|
1539
|
-
return () => {
|
|
1540
|
-
this.onScrollStopFns = this.onScrollStopFns.filter((f) => f !== fn);
|
|
1541
|
-
};
|
|
1542
|
-
};
|
|
1543
|
-
|
|
1544
|
-
onRenderRangeChange = (fn: FnOnRenderRangeChange) => {
|
|
1545
|
-
this.onRenderRangeChangeFns.add(fn);
|
|
1546
|
-
return () => {
|
|
1547
|
-
this.onRenderRangeChangeFns.delete(fn);
|
|
1548
|
-
};
|
|
1549
|
-
};
|
|
1550
|
-
onVerticalRenderRangeChange = (fn: FnOnDirectionalRenderRangeChange) => {
|
|
1551
|
-
this.onVerticalRenderRangeChangeFns.add(fn);
|
|
1552
|
-
return () => {
|
|
1553
|
-
this.onVerticalRenderRangeChangeFns.delete(fn);
|
|
1554
|
-
};
|
|
1555
|
-
};
|
|
1556
|
-
onHorizontalRenderRangeChange = (fn: FnOnDirectionalRenderRangeChange) => {
|
|
1557
|
-
this.onHorizontalRenderRangeChangeFns.add(fn);
|
|
1558
|
-
return () => {
|
|
1559
|
-
this.onHorizontalRenderRangeChangeFns.delete(fn);
|
|
1560
|
-
};
|
|
1561
|
-
};
|
|
1562
|
-
|
|
1563
|
-
onRenderCountChange = (fn: FnOnRenderCountChange) => {
|
|
1564
|
-
this.onRenderCountChangeFns.add(fn);
|
|
1565
|
-
|
|
1566
|
-
return () => {
|
|
1567
|
-
this.onRenderCountChangeFns.delete(fn);
|
|
1568
|
-
};
|
|
1569
|
-
};
|
|
1570
|
-
|
|
1571
|
-
onAvailableSizeChange = (fn: OnAvailableSizeChange) => {
|
|
1572
|
-
this.onAvailableSizeChangeFns.add(fn);
|
|
1573
|
-
|
|
1574
|
-
return () => {
|
|
1575
|
-
this.onAvailableSizeChangeFns.delete(fn);
|
|
1576
|
-
};
|
|
1577
|
-
};
|
|
1578
|
-
|
|
1579
|
-
public onDestroy = (fn: VoidFn) => {
|
|
1580
|
-
this.onDestroyFns.push(fn);
|
|
1581
|
-
|
|
1582
|
-
return () => {
|
|
1583
|
-
this.onDestroyFns = this.onDestroyFns.filter((f) => f !== fn);
|
|
1584
|
-
};
|
|
1585
|
-
};
|
|
1586
|
-
|
|
1587
|
-
public getAvailableSize = () => {
|
|
1588
|
-
return {
|
|
1589
|
-
width: this.width,
|
|
1590
|
-
height: this.height,
|
|
1591
|
-
};
|
|
1592
|
-
};
|
|
1593
|
-
|
|
1594
|
-
private notifyDestroy() {
|
|
1595
|
-
const fns = this.onDestroyFns;
|
|
1596
|
-
for (let i = 0, len = fns.length; i < len; i++) {
|
|
1597
|
-
fns[i]();
|
|
1598
|
-
}
|
|
1599
|
-
}
|
|
1600
|
-
|
|
1601
|
-
destroy = () => {
|
|
1602
|
-
if (this.destroyed) {
|
|
1603
|
-
return;
|
|
1604
|
-
}
|
|
1605
|
-
this.notifyDestroy();
|
|
1606
|
-
|
|
1607
|
-
this.reset();
|
|
1608
|
-
|
|
1609
|
-
this.rowspanParent.clear();
|
|
1610
|
-
this.colspanParent.clear();
|
|
1611
|
-
this.destroyed = true;
|
|
1612
|
-
this.onDestroyFns = [];
|
|
1613
|
-
this.onScrollFns = [];
|
|
1614
|
-
this.onScrollStartFns = [];
|
|
1615
|
-
this.onScrollStopFns = [];
|
|
1616
|
-
this.onRenderCountChangeFns = new Set();
|
|
1617
|
-
this.onRenderRangeChangeFns = new Set();
|
|
1618
|
-
this.onVerticalRenderRangeChangeFns = new Set();
|
|
1619
|
-
this.onHorizontalRenderRangeChangeFns = new Set();
|
|
1620
|
-
};
|
|
1621
|
-
}
|