@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,307 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import type { RefCallback } from 'react';
|
|
3
|
-
import type { Renderable } from '../types/Renderable';
|
|
4
|
-
import type { RenderItem } from './types';
|
|
5
|
-
import type { SubscriptionCallback } from '../types/SubscriptionCallback';
|
|
6
|
-
import type { RenderRange } from '../VirtualBrain';
|
|
7
|
-
|
|
8
|
-
import { dbg, Logger } from '../../utils/debug';
|
|
9
|
-
|
|
10
|
-
import { VirtualBrain } from '../VirtualBrain';
|
|
11
|
-
|
|
12
|
-
import { MappedItems } from './MappedItems';
|
|
13
|
-
import { AvoidReactDiff } from './AvoidReactDiff';
|
|
14
|
-
import { buildSubscriptionCallback } from '../utils/buildSubscriptionCallback';
|
|
15
|
-
|
|
16
|
-
const ITEM_POSITION_WITH_TRANSFORM = true;
|
|
17
|
-
|
|
18
|
-
export class ReactVirtualRenderer extends Logger {
|
|
19
|
-
private mappedItems: MappedItems;
|
|
20
|
-
// needed for hot reload and react hooks executing twice in dev
|
|
21
|
-
private destroyed: boolean = false;
|
|
22
|
-
|
|
23
|
-
private itemDOMElements: Record<number, HTMLElement | null> = {};
|
|
24
|
-
private itemDOMRefs: Record<number, RefCallback<HTMLElement>> = {};
|
|
25
|
-
private updaters: Record<number, SubscriptionCallback<Renderable>> = {};
|
|
26
|
-
|
|
27
|
-
private onRender: (items: Renderable[]) => void = () => null;
|
|
28
|
-
private brain: VirtualBrain;
|
|
29
|
-
|
|
30
|
-
private items: Renderable[] = [];
|
|
31
|
-
prevLength: number = 0;
|
|
32
|
-
|
|
33
|
-
constructor(
|
|
34
|
-
brain: VirtualBrain,
|
|
35
|
-
{
|
|
36
|
-
onRender,
|
|
37
|
-
channel,
|
|
38
|
-
}: {
|
|
39
|
-
onRender?: ReactVirtualRenderer['onRender'];
|
|
40
|
-
channel?: string;
|
|
41
|
-
},
|
|
42
|
-
) {
|
|
43
|
-
super(
|
|
44
|
-
`ReactVirtualRenderer:${brain.getOptions().mainAxis}` +
|
|
45
|
-
(channel ? `:${channel}` : ''),
|
|
46
|
-
);
|
|
47
|
-
|
|
48
|
-
if (onRender) {
|
|
49
|
-
this.onRender = onRender;
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
this.brain = brain;
|
|
53
|
-
this.mappedItems = new MappedItems(brain.getOptions().mainAxis);
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
renderRange = (
|
|
57
|
-
range: RenderRange,
|
|
58
|
-
{
|
|
59
|
-
renderItem,
|
|
60
|
-
force,
|
|
61
|
-
onRender,
|
|
62
|
-
}: {
|
|
63
|
-
renderItem: RenderItem;
|
|
64
|
-
force: boolean;
|
|
65
|
-
onRender?: (items: Renderable[]) => void;
|
|
66
|
-
},
|
|
67
|
-
): Renderable[] => {
|
|
68
|
-
// needed for hot reload and react hooks executing twice in dev
|
|
69
|
-
if (this.destroyed) {
|
|
70
|
-
// console.warn('DESTROYED');
|
|
71
|
-
return [];
|
|
72
|
-
}
|
|
73
|
-
const { mappedItems } = this;
|
|
74
|
-
const { renderStartIndex, renderEndIndex } = range;
|
|
75
|
-
|
|
76
|
-
if (__DEV__) {
|
|
77
|
-
this.debug(
|
|
78
|
-
`Render range ${renderStartIndex}-${renderEndIndex}. Force ${force}`,
|
|
79
|
-
);
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
const renderCount =
|
|
83
|
-
renderEndIndex === -1 ? 0 : renderEndIndex - renderStartIndex + 1;
|
|
84
|
-
|
|
85
|
-
if (this.itemDOMElements[renderCount]) {
|
|
86
|
-
mappedItems.discardElementsStartingWith(renderCount, (elementIndex) => {
|
|
87
|
-
delete this.itemDOMElements[elementIndex];
|
|
88
|
-
delete this.itemDOMRefs[elementIndex];
|
|
89
|
-
|
|
90
|
-
// when less items become rendered
|
|
91
|
-
// we unmount the extra items by calling destroy on the updater
|
|
92
|
-
// so we don't need to re-render the whole container
|
|
93
|
-
if (this.updaters[elementIndex]) {
|
|
94
|
-
this.updaters[elementIndex].destroy();
|
|
95
|
-
delete this.updaters[elementIndex];
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
delete this.items[elementIndex];
|
|
99
|
-
if (__DEV__) {
|
|
100
|
-
this.debug(`Discard element ${elementIndex}`);
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
}
|
|
104
|
-
if (this.items.length > renderCount) {
|
|
105
|
-
this.items.length = renderCount;
|
|
106
|
-
}
|
|
107
|
-
|
|
108
|
-
const elementsOutsideItemRange =
|
|
109
|
-
this.mappedItems.getElementsOutsideItemRange(
|
|
110
|
-
renderStartIndex,
|
|
111
|
-
renderEndIndex,
|
|
112
|
-
);
|
|
113
|
-
|
|
114
|
-
// start from the last rendered, and render additional elements, until we have renderCount
|
|
115
|
-
// this loop might not even execute the body once if all the elements are present
|
|
116
|
-
for (let i = this.items.length; i < renderCount; i++) {
|
|
117
|
-
this.renderElement(i);
|
|
118
|
-
// push at start
|
|
119
|
-
elementsOutsideItemRange.splice(0, 0, i);
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
for (let i = renderStartIndex; i <= renderEndIndex; i++) {
|
|
123
|
-
if (mappedItems.isRenderedItem(i)) {
|
|
124
|
-
if (force) {
|
|
125
|
-
this.renderItemAtElement(i, undefined, renderItem);
|
|
126
|
-
}
|
|
127
|
-
continue;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const elementIndex = elementsOutsideItemRange.pop();
|
|
131
|
-
if (elementIndex == null) {
|
|
132
|
-
if (__DEV__) {
|
|
133
|
-
this.error(`Cannot find element to render item ${i}`);
|
|
134
|
-
}
|
|
135
|
-
continue;
|
|
136
|
-
}
|
|
137
|
-
this.renderItemAtElement(i, elementIndex, renderItem);
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
// OLD we need to spread and create a new array
|
|
141
|
-
// OLD as otherwise the AvoidReactDiff component will receive the same array
|
|
142
|
-
// OLD and since it uses setState internally, it will not render/update
|
|
143
|
-
// const result = [...this.items];
|
|
144
|
-
let result = this.items;
|
|
145
|
-
|
|
146
|
-
// TODO why does this optimisation not work
|
|
147
|
-
// if (this.items.length > this.prevLength) {
|
|
148
|
-
// // only assign and do a render when
|
|
149
|
-
// // we have more items than last time
|
|
150
|
-
// // so we need to show new items
|
|
151
|
-
result = [...this.items];
|
|
152
|
-
|
|
153
|
-
if (this.onRender) {
|
|
154
|
-
this.onRender(result);
|
|
155
|
-
}
|
|
156
|
-
if (onRender) {
|
|
157
|
-
onRender(result);
|
|
158
|
-
}
|
|
159
|
-
// this.prevLength = result.length;
|
|
160
|
-
// }
|
|
161
|
-
|
|
162
|
-
return result;
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
private renderElement(elementIndex: number) {
|
|
166
|
-
const domRef = (node: HTMLElement | null) => {
|
|
167
|
-
if (node) {
|
|
168
|
-
this.itemDOMElements[elementIndex] = node;
|
|
169
|
-
this.updateElementPosition(elementIndex);
|
|
170
|
-
}
|
|
171
|
-
};
|
|
172
|
-
this.itemDOMRefs[elementIndex] = domRef;
|
|
173
|
-
this.updaters[elementIndex] = buildSubscriptionCallback<Renderable>();
|
|
174
|
-
|
|
175
|
-
const item = (
|
|
176
|
-
<AvoidReactDiff
|
|
177
|
-
key={elementIndex}
|
|
178
|
-
name={`${elementIndex}`}
|
|
179
|
-
updater={this.updaters[elementIndex]}
|
|
180
|
-
/>
|
|
181
|
-
);
|
|
182
|
-
|
|
183
|
-
// if (__DEV__) {
|
|
184
|
-
// this.debug(`Mount element ${elementIndex}`);
|
|
185
|
-
// }
|
|
186
|
-
this.items[elementIndex] = item;
|
|
187
|
-
|
|
188
|
-
return item;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
private renderItemAtElement(
|
|
192
|
-
itemIndex: number,
|
|
193
|
-
elementIndex = this.mappedItems.getElementIndexForItem(itemIndex) as number,
|
|
194
|
-
renderItem: RenderItem,
|
|
195
|
-
// swapSpanned?: boolean,
|
|
196
|
-
) {
|
|
197
|
-
// needed for hot reload and react hooks executing twice in dev
|
|
198
|
-
if (this.destroyed) {
|
|
199
|
-
return;
|
|
200
|
-
}
|
|
201
|
-
const spanParent = this.brain.getItemSpanParent(itemIndex);
|
|
202
|
-
let covered = false;
|
|
203
|
-
if (spanParent !== itemIndex) {
|
|
204
|
-
// if (swapSpanned) {
|
|
205
|
-
// debugger;
|
|
206
|
-
// itemIndex = spanParent;
|
|
207
|
-
// } else {
|
|
208
|
-
|
|
209
|
-
covered = true;
|
|
210
|
-
// }
|
|
211
|
-
}
|
|
212
|
-
const itemSize = this.brain.getItemSize(itemIndex);
|
|
213
|
-
const itemSpan = this.brain.getItemSpan(itemIndex);
|
|
214
|
-
const itemSizeWithSpan =
|
|
215
|
-
itemSpan === 1
|
|
216
|
-
? itemSize
|
|
217
|
-
: this.brain.getItemSizeWithSpan(itemIndex, itemSpan);
|
|
218
|
-
|
|
219
|
-
const renderedNode = renderItem({
|
|
220
|
-
spanParent,
|
|
221
|
-
itemIndex,
|
|
222
|
-
itemSize,
|
|
223
|
-
itemSizeWithSpan,
|
|
224
|
-
itemSpan,
|
|
225
|
-
covered,
|
|
226
|
-
domRef: this.itemDOMRefs[elementIndex],
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
const itemUpdater = this.updaters[elementIndex];
|
|
230
|
-
|
|
231
|
-
if (!itemUpdater) {
|
|
232
|
-
this.error(
|
|
233
|
-
`Cannot find item updater for item ${itemIndex} at this time... sorry.`,
|
|
234
|
-
);
|
|
235
|
-
return;
|
|
236
|
-
}
|
|
237
|
-
this.mappedItems.renderItemAtElement(itemIndex, elementIndex, renderedNode);
|
|
238
|
-
|
|
239
|
-
if (__DEV__) {
|
|
240
|
-
dbg(`ReactVirtualRenderer:${this.brain.getOptions().mainAxis}`)(
|
|
241
|
-
`Render item ${itemIndex} at element ${elementIndex}`,
|
|
242
|
-
);
|
|
243
|
-
}
|
|
244
|
-
itemUpdater(renderedNode);
|
|
245
|
-
|
|
246
|
-
this.updateElementPosition(elementIndex);
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
private updateElementPosition = (elementIndex: number) => {
|
|
250
|
-
const itemElement = this.itemDOMElements[elementIndex];
|
|
251
|
-
const itemIndex =
|
|
252
|
-
this.mappedItems.getItemRenderedAtElementIndex(elementIndex);
|
|
253
|
-
|
|
254
|
-
const options = this.brain.getOptions();
|
|
255
|
-
|
|
256
|
-
if (itemIndex == null) {
|
|
257
|
-
if (__DEV__) {
|
|
258
|
-
this.error(`Cannot find item for element ${elementIndex}`);
|
|
259
|
-
}
|
|
260
|
-
return;
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
const itemPosition = this.brain.getItemOffsetFor(itemIndex);
|
|
264
|
-
|
|
265
|
-
if (itemPosition == null) {
|
|
266
|
-
return;
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
if (itemElement) {
|
|
270
|
-
if (__DEV__) {
|
|
271
|
-
(itemElement.dataset as any).elementIndex = elementIndex;
|
|
272
|
-
(itemElement.dataset as any).itemIndex = itemIndex;
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
if (ITEM_POSITION_WITH_TRANSFORM) {
|
|
276
|
-
itemElement.style.transform =
|
|
277
|
-
options.mainAxis === 'vertical'
|
|
278
|
-
? `translateY(${itemPosition}px)`
|
|
279
|
-
: `translateX(${itemPosition}px)`;
|
|
280
|
-
itemElement.style.visibility = '';
|
|
281
|
-
} else {
|
|
282
|
-
itemElement.style.display = '';
|
|
283
|
-
itemElement.style[
|
|
284
|
-
options.mainAxis === 'vertical' ? 'top' : 'left'
|
|
285
|
-
] = `${itemPosition}px`;
|
|
286
|
-
}
|
|
287
|
-
}
|
|
288
|
-
};
|
|
289
|
-
|
|
290
|
-
destroy = () => {
|
|
291
|
-
this.destroyed = true;
|
|
292
|
-
this.reset();
|
|
293
|
-
|
|
294
|
-
(this as any).onRender = null;
|
|
295
|
-
(this as any).renderItem = null;
|
|
296
|
-
(this as any).brain = null;
|
|
297
|
-
(this as any).mappedItems = null;
|
|
298
|
-
};
|
|
299
|
-
|
|
300
|
-
reset() {
|
|
301
|
-
this.itemDOMElements = {};
|
|
302
|
-
this.itemDOMRefs = {};
|
|
303
|
-
this.updaters = {};
|
|
304
|
-
this.items = [];
|
|
305
|
-
this.mappedItems.reset();
|
|
306
|
-
}
|
|
307
|
-
}
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import { useEffect } from 'react';
|
|
3
|
-
|
|
4
|
-
import { AvoidReactDiff } from './AvoidReactDiff';
|
|
5
|
-
import { RawListProps } from './types';
|
|
6
|
-
import { useLatest } from '../hooks/useLatest';
|
|
7
|
-
import { useVirtualRenderer } from './useVirtualRenderer';
|
|
8
|
-
|
|
9
|
-
function RawListFn(props: RawListProps) {
|
|
10
|
-
const { renderItem, brain, debugChannel } = props;
|
|
11
|
-
|
|
12
|
-
const { onRenderUpdater, renderer } = useVirtualRenderer({
|
|
13
|
-
brain,
|
|
14
|
-
debugChannel,
|
|
15
|
-
});
|
|
16
|
-
const getRenderItem = useLatest(renderItem);
|
|
17
|
-
|
|
18
|
-
useEffect(() => {
|
|
19
|
-
const renderRange = brain.getRenderRange();
|
|
20
|
-
|
|
21
|
-
renderer.renderRange(renderRange, {
|
|
22
|
-
renderItem,
|
|
23
|
-
force: true,
|
|
24
|
-
onRender: onRenderUpdater,
|
|
25
|
-
});
|
|
26
|
-
}, [brain, renderItem, onRenderUpdater]);
|
|
27
|
-
|
|
28
|
-
useEffect(() => {
|
|
29
|
-
const remove = brain.onRenderRangeChange((renderRange) => {
|
|
30
|
-
renderer.renderRange(renderRange, {
|
|
31
|
-
force: false,
|
|
32
|
-
renderItem: getRenderItem(),
|
|
33
|
-
onRender: onRenderUpdater,
|
|
34
|
-
});
|
|
35
|
-
});
|
|
36
|
-
return remove;
|
|
37
|
-
}, [brain, onRenderUpdater]);
|
|
38
|
-
|
|
39
|
-
return <AvoidReactDiff updater={onRenderUpdater} />;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
export const RawList: React.FC<RawListProps> = React.memo(RawListFn);
|
|
@@ -1,23 +0,0 @@
|
|
|
1
|
-
import type { RefCallback } from 'react';
|
|
2
|
-
import type { Renderable } from '../types/Renderable';
|
|
3
|
-
import type { VirtualBrain } from '../VirtualBrain';
|
|
4
|
-
|
|
5
|
-
export type RenderItemParam = {
|
|
6
|
-
domRef: RefCallback<HTMLElement>;
|
|
7
|
-
itemIndex: number;
|
|
8
|
-
itemSize: number;
|
|
9
|
-
itemSizeWithSpan: number;
|
|
10
|
-
itemSpan: number;
|
|
11
|
-
spanParent: number;
|
|
12
|
-
covered: boolean;
|
|
13
|
-
};
|
|
14
|
-
export type RenderItem = (renderProps: RenderItemParam) => Renderable;
|
|
15
|
-
export type RawListItemSpan = (itemSpanProps: { itemIndex: number }) => number;
|
|
16
|
-
|
|
17
|
-
export type RawListProps = {
|
|
18
|
-
debugChannel?: string;
|
|
19
|
-
renderItem: RenderItem;
|
|
20
|
-
itemSpan?: RawListItemSpan;
|
|
21
|
-
brain: VirtualBrain;
|
|
22
|
-
repaintId?: string | number;
|
|
23
|
-
};
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { useMemo } from 'react';
|
|
2
|
-
|
|
3
|
-
import { Renderable } from '../types/Renderable';
|
|
4
|
-
import { SubscriptionCallback } from '../types/SubscriptionCallback';
|
|
5
|
-
import { buildSubscriptionCallback } from '../utils/buildSubscriptionCallback';
|
|
6
|
-
|
|
7
|
-
import { VirtualBrain } from '../VirtualBrain';
|
|
8
|
-
import { ReactVirtualRenderer } from './ReactVirtualRenderer';
|
|
9
|
-
|
|
10
|
-
function createRenderer(brain: VirtualBrain) {
|
|
11
|
-
const renderer = new ReactVirtualRenderer(brain, {});
|
|
12
|
-
const onRenderUpdater = buildSubscriptionCallback<Renderable>();
|
|
13
|
-
|
|
14
|
-
brain.onDestroy(() => {
|
|
15
|
-
renderer.destroy();
|
|
16
|
-
onRenderUpdater.destroy();
|
|
17
|
-
});
|
|
18
|
-
|
|
19
|
-
return {
|
|
20
|
-
renderer,
|
|
21
|
-
onRenderUpdater,
|
|
22
|
-
};
|
|
23
|
-
}
|
|
24
|
-
export function useVirtualRenderer({
|
|
25
|
-
brain,
|
|
26
|
-
}: {
|
|
27
|
-
brain: VirtualBrain;
|
|
28
|
-
debugChannel?: string;
|
|
29
|
-
}): {
|
|
30
|
-
onRenderUpdater: SubscriptionCallback<Renderable>;
|
|
31
|
-
renderer: ReactVirtualRenderer;
|
|
32
|
-
} {
|
|
33
|
-
return useMemo(() => {
|
|
34
|
-
return createRenderer(brain);
|
|
35
|
-
}, [brain]);
|
|
36
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
export type RenderHookComponentProps<RENDER_FN extends Function, PARAM_TYPE> = {
|
|
2
|
-
render: RENDER_FN;
|
|
3
|
-
renderParam: PARAM_TYPE;
|
|
4
|
-
};
|
|
5
|
-
|
|
6
|
-
export function RenderHookComponent<RENDER_FN extends Function, PARAM_TYPE>(
|
|
7
|
-
props: RenderHookComponentProps<RENDER_FN, PARAM_TYPE>,
|
|
8
|
-
) {
|
|
9
|
-
return props.render(props.renderParam) ?? null;
|
|
10
|
-
}
|
|
@@ -1,170 +0,0 @@
|
|
|
1
|
-
import * as React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
useMemo,
|
|
4
|
-
useRef,
|
|
5
|
-
useEffect,
|
|
6
|
-
useLayoutEffect,
|
|
7
|
-
useCallback,
|
|
8
|
-
} from 'react';
|
|
9
|
-
|
|
10
|
-
import { Size, OnResizeFn } from '../types/Size';
|
|
11
|
-
import { debounce } from '../utils/debounce';
|
|
12
|
-
|
|
13
|
-
interface ResizeObserverProps {
|
|
14
|
-
/**
|
|
15
|
-
* Specifies whether to call onResize after the initial render (on mount)
|
|
16
|
-
*
|
|
17
|
-
* @default true
|
|
18
|
-
*/
|
|
19
|
-
notifyOnMount?: boolean;
|
|
20
|
-
|
|
21
|
-
/**
|
|
22
|
-
* If set to true, it will be attached using useLayoutEffect. If false, will be attached using useEffect
|
|
23
|
-
* @default false
|
|
24
|
-
*/
|
|
25
|
-
earlyAttach?: boolean;
|
|
26
|
-
|
|
27
|
-
onResize: OnResizeFn;
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
export const setupResizeObserver = (
|
|
31
|
-
node: HTMLElement,
|
|
32
|
-
callback: OnResizeFn,
|
|
33
|
-
config: { debounce?: number } = { debounce: 0 },
|
|
34
|
-
): (() => void) => {
|
|
35
|
-
const debounceTime = config.debounce ?? 0;
|
|
36
|
-
const RO = (window as any).ResizeObserver;
|
|
37
|
-
|
|
38
|
-
const onResizeCallback = debounceTime
|
|
39
|
-
? debounce(callback, { wait: debounceTime })
|
|
40
|
-
: callback;
|
|
41
|
-
|
|
42
|
-
const observer = new RO((entries: any[]) => {
|
|
43
|
-
const entry = entries[0];
|
|
44
|
-
|
|
45
|
-
let { width, height } = entry.contentRect;
|
|
46
|
-
|
|
47
|
-
if (entry.borderBoxSize?.[0]) {
|
|
48
|
-
height = entry.borderBoxSize[0].blockSize;
|
|
49
|
-
width = entry.borderBoxSize[0].inlineSize;
|
|
50
|
-
} else {
|
|
51
|
-
// this is needed for Safari and other browsers that don't have borderBoxSize on the entry object
|
|
52
|
-
const rect = node.getBoundingClientRect();
|
|
53
|
-
height = rect.height;
|
|
54
|
-
width = rect.width;
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
onResizeCallback({ width, height });
|
|
58
|
-
});
|
|
59
|
-
|
|
60
|
-
observer.observe(node);
|
|
61
|
-
|
|
62
|
-
return () => {
|
|
63
|
-
observer.disconnect();
|
|
64
|
-
};
|
|
65
|
-
};
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* A hook that notifies you when a certain DOM element has changed it's size
|
|
69
|
-
*
|
|
70
|
-
* @param ref A React ref to a DOM element
|
|
71
|
-
* @param callback The function to be called when the element is resized.
|
|
72
|
-
*/
|
|
73
|
-
export const useResizeObserver = (
|
|
74
|
-
ref: React.MutableRefObject<HTMLElement | null>,
|
|
75
|
-
callback: OnResizeFn,
|
|
76
|
-
config: { earlyAttach: boolean; debounce?: number } = {
|
|
77
|
-
earlyAttach: false,
|
|
78
|
-
debounce: 0,
|
|
79
|
-
},
|
|
80
|
-
) => {
|
|
81
|
-
const sizeRef = useRef<Size>({
|
|
82
|
-
width: 0,
|
|
83
|
-
height: 0,
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
const effectFn = (callback: OnResizeFn) => {
|
|
87
|
-
let disconnect: () => void;
|
|
88
|
-
if (ref.current) {
|
|
89
|
-
disconnect = setupResizeObserver(
|
|
90
|
-
ref.current,
|
|
91
|
-
(size) => {
|
|
92
|
-
size = {
|
|
93
|
-
width: Math.round(size.width),
|
|
94
|
-
height: Math.round(size.height),
|
|
95
|
-
};
|
|
96
|
-
const prevSize = sizeRef.current;
|
|
97
|
-
if (
|
|
98
|
-
prevSize.width !== size.width ||
|
|
99
|
-
prevSize.height !== size.height
|
|
100
|
-
) {
|
|
101
|
-
sizeRef.current = size;
|
|
102
|
-
|
|
103
|
-
callback(size);
|
|
104
|
-
}
|
|
105
|
-
},
|
|
106
|
-
{ debounce: config.debounce },
|
|
107
|
-
);
|
|
108
|
-
}
|
|
109
|
-
return () => {
|
|
110
|
-
if (disconnect) {
|
|
111
|
-
disconnect();
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
useEffect(() => {
|
|
117
|
-
if (!config.earlyAttach) {
|
|
118
|
-
return effectFn(callback);
|
|
119
|
-
}
|
|
120
|
-
return () => {};
|
|
121
|
-
}, [ref.current, callback, config.earlyAttach, config.debounce]);
|
|
122
|
-
|
|
123
|
-
useLayoutEffect(() => {
|
|
124
|
-
if (config.earlyAttach) {
|
|
125
|
-
return effectFn(callback);
|
|
126
|
-
}
|
|
127
|
-
return () => {};
|
|
128
|
-
}, [ref.current, callback, config.earlyAttach]);
|
|
129
|
-
};
|
|
130
|
-
|
|
131
|
-
const ReactResizeObserver = (props: ResizeObserverProps) => {
|
|
132
|
-
const style = useMemo(
|
|
133
|
-
() => ({
|
|
134
|
-
position: 'absolute' as 'absolute',
|
|
135
|
-
top: 0,
|
|
136
|
-
left: 0,
|
|
137
|
-
width: '100%',
|
|
138
|
-
height: '100%',
|
|
139
|
-
boxSizing: 'border-box' as 'border-box',
|
|
140
|
-
}),
|
|
141
|
-
[],
|
|
142
|
-
);
|
|
143
|
-
|
|
144
|
-
const { notifyOnMount, earlyAttach } = props;
|
|
145
|
-
|
|
146
|
-
const firstTime = useRef(true);
|
|
147
|
-
const ref = useRef<HTMLDivElement>(null);
|
|
148
|
-
|
|
149
|
-
const onResize = useCallback(
|
|
150
|
-
(size: Size) => {
|
|
151
|
-
if (firstTime.current && !notifyOnMount) {
|
|
152
|
-
firstTime.current = false;
|
|
153
|
-
return;
|
|
154
|
-
}
|
|
155
|
-
props.onResize(size);
|
|
156
|
-
},
|
|
157
|
-
[props.onResize],
|
|
158
|
-
);
|
|
159
|
-
|
|
160
|
-
useResizeObserver(ref, onResize, { earlyAttach: earlyAttach || false });
|
|
161
|
-
|
|
162
|
-
return <div ref={ref} style={style}></div>;
|
|
163
|
-
};
|
|
164
|
-
|
|
165
|
-
ReactResizeObserver.defaultProps = {
|
|
166
|
-
notifyOnMount: true,
|
|
167
|
-
earlyAttach: false,
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
export default ReactResizeObserver;
|