@difizen/libro-virtualized 0.1.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/LICENSE +21 -0
- package/README.md +0 -0
- package/es/auto-sizer/auto-sizer.d.ts +56 -0
- package/es/auto-sizer/auto-sizer.d.ts.map +1 -0
- package/es/auto-sizer/auto-sizer.js +157 -0
- package/es/auto-sizer/index.d.ts +3 -0
- package/es/auto-sizer/index.d.ts.map +1 -0
- package/es/auto-sizer/index.js +2 -0
- package/es/cell-measurer/cell-measurer-cache.d.ts +52 -0
- package/es/cell-measurer/cell-measurer-cache.d.ts.map +1 -0
- package/es/cell-measurer/cell-measurer-cache.js +176 -0
- package/es/cell-measurer/cell-measurer.d.ts +39 -0
- package/es/cell-measurer/cell-measurer.d.ts.map +1 -0
- package/es/cell-measurer/cell-measurer.js +154 -0
- package/es/cell-measurer/index.d.ts +5 -0
- package/es/cell-measurer/index.d.ts.map +1 -0
- package/es/cell-measurer/index.js +4 -0
- package/es/cell-measurer/types.d.ts +9 -0
- package/es/cell-measurer/types.d.ts.map +1 -0
- package/es/cell-measurer/types.js +0 -0
- package/es/grid/accessibility-overscanIndices-getter.d.ts +11 -0
- package/es/grid/accessibility-overscanIndices-getter.d.ts.map +1 -0
- package/es/grid/accessibility-overscanIndices-getter.js +33 -0
- package/es/grid/default-cell-range-renderer.d.ts +10 -0
- package/es/grid/default-cell-range-renderer.d.ts.map +1 -0
- package/es/grid/default-cell-range-renderer.js +135 -0
- package/es/grid/default-overscanIndices-getter.d.ts +11 -0
- package/es/grid/default-overscanIndices-getter.d.ts.map +1 -0
- package/es/grid/default-overscanIndices-getter.js +28 -0
- package/es/grid/grid.d.ts +359 -0
- package/es/grid/grid.d.ts.map +1 -0
- package/es/grid/grid.js +1287 -0
- package/es/grid/index.d.ts +6 -0
- package/es/grid/index.d.ts.map +1 -0
- package/es/grid/index.js +4 -0
- package/es/grid/types.d.ts +87 -0
- package/es/grid/types.d.ts.map +1 -0
- package/es/grid/types.js +1 -0
- package/es/grid/utils/calculate-size-and-position-data-and-update-scroll-offset.d.ts +17 -0
- package/es/grid/utils/calculate-size-and-position-data-and-update-scroll-offset.d.ts.map +1 -0
- package/es/grid/utils/calculate-size-and-position-data-and-update-scroll-offset.js +25 -0
- package/es/grid/utils/cell-size-and-position-manager-row.d.ts +97 -0
- package/es/grid/utils/cell-size-and-position-manager-row.d.ts.map +1 -0
- package/es/grid/utils/cell-size-and-position-manager-row.js +297 -0
- package/es/grid/utils/cell-size-and-position-manager.d.ts +85 -0
- package/es/grid/utils/cell-size-and-position-manager.d.ts.map +1 -0
- package/es/grid/utils/cell-size-and-position-manager.js +268 -0
- package/es/grid/utils/max-element-size.d.ts +2 -0
- package/es/grid/utils/max-element-size.d.ts.map +1 -0
- package/es/grid/utils/max-element-size.js +17 -0
- package/es/grid/utils/scaling-cell-size-and-position-manager-row.d.ts +78 -0
- package/es/grid/utils/scaling-cell-size-and-position-manager-row.d.ts.map +1 -0
- package/es/grid/utils/scaling-cell-size-and-position-manager-row.js +187 -0
- package/es/grid/utils/scaling-cell-size-and-position-manager.d.ts +70 -0
- package/es/grid/utils/scaling-cell-size-and-position-manager.d.ts.map +1 -0
- package/es/grid/utils/scaling-cell-size-and-position-manager.js +187 -0
- package/es/grid/utils/update-scroll-index-helper.d.ts +24 -0
- package/es/grid/utils/update-scroll-index-helper.d.ts.map +1 -0
- package/es/grid/utils/update-scroll-index-helper.js +40 -0
- package/es/index.d.ts +5 -0
- package/es/index.d.ts.map +1 -0
- package/es/index.js +4 -0
- package/es/list/index.d.ts +3 -0
- package/es/list/index.d.ts.map +1 -0
- package/es/list/index.js +1 -0
- package/es/list/list.d.ts +109 -0
- package/es/list/list.d.ts.map +1 -0
- package/es/list/list.js +261 -0
- package/es/list/types.d.ts +22 -0
- package/es/list/types.d.ts.map +1 -0
- package/es/list/types.js +1 -0
- package/es/utils/animation-frame.d.ts +7 -0
- package/es/utils/animation-frame.d.ts.map +1 -0
- package/es/utils/animation-frame.js +20 -0
- package/es/utils/create-callback-memoizer.d.ts +5 -0
- package/es/utils/create-callback-memoizer.d.ts.map +1 -0
- package/es/utils/create-callback-memoizer.js +25 -0
- package/es/utils/get-updated-offset-for-index.d.ts +14 -0
- package/es/utils/get-updated-offset-for-index.d.ts.map +1 -0
- package/es/utils/get-updated-offset-for-index.js +32 -0
- package/es/utils/init-cell-metadata.d.ts +13 -0
- package/es/utils/init-cell-metadata.d.ts.map +1 -0
- package/es/utils/init-cell-metadata.js +32 -0
- package/es/utils/request-animation-timeout.d.ts +12 -0
- package/es/utils/request-animation-timeout.d.ts.map +1 -0
- package/es/utils/request-animation-timeout.js +33 -0
- package/es/utils/test-helper.d.ts +5 -0
- package/es/utils/test-helper.d.ts.map +1 -0
- package/es/utils/test-helper.js +31 -0
- package/es/vendor/binary-search-bounds.d.ts +22 -0
- package/es/vendor/binary-search-bounds.d.ts.map +1 -0
- package/es/vendor/binary-search-bounds.js +198 -0
- package/es/vendor/detect-element-resize.d.ts +16 -0
- package/es/vendor/detect-element-resize.d.ts.map +1 -0
- package/es/vendor/detect-element-resize.js +184 -0
- package/es/vendor/interval-tree.d.ts +10 -0
- package/es/vendor/interval-tree.d.ts.map +1 -0
- package/es/vendor/interval-tree.js +359 -0
- package/package.json +59 -0
- package/src/auto-sizer/auto-sizer.tsx +187 -0
- package/src/auto-sizer/index.ts +4 -0
- package/src/cell-measurer/cell-measurer-cache.ts +220 -0
- package/src/cell-measurer/cell-measurer.ts +151 -0
- package/src/cell-measurer/index.ts +5 -0
- package/src/cell-measurer/types.ts +8 -0
- package/src/grid/accessibility-overscanIndices-getter.ts +38 -0
- package/src/grid/default-cell-range-renderer.ts +166 -0
- package/src/grid/default-overscanIndices-getter.ts +32 -0
- package/src/grid/grid.tsx +1672 -0
- package/src/grid/index.ts +14 -0
- package/src/grid/types.ts +112 -0
- package/src/grid/utils/calculate-size-and-position-data-and-update-scroll-offset.ts +62 -0
- package/src/grid/utils/cell-size-and-position-manager-row.ts +365 -0
- package/src/grid/utils/cell-size-and-position-manager.ts +309 -0
- package/src/grid/utils/max-element-size.ts +18 -0
- package/src/grid/utils/scaling-cell-size-and-position-manager-row.ts +206 -0
- package/src/grid/utils/scaling-cell-size-and-position-manager.ts +198 -0
- package/src/grid/utils/update-scroll-index-helper.ts +96 -0
- package/src/index.spec.ts +10 -0
- package/src/index.ts +4 -0
- package/src/list/index.ts +2 -0
- package/src/list/list.tsx +292 -0
- package/src/list/types.ts +25 -0
- package/src/utils/animation-frame.ts +38 -0
- package/src/utils/create-callback-memoizer.ts +32 -0
- package/src/utils/get-updated-offset-for-index.ts +33 -0
- package/src/utils/init-cell-metadata.ts +32 -0
- package/src/utils/request-animation-timeout.ts +44 -0
- package/src/utils/test-helper.ts +20 -0
- package/src/vendor/binary-search-bounds.ts +203 -0
- package/src/vendor/detect-element-resize.ts +241 -0
- package/src/vendor/interval-tree.ts +406 -0
|
@@ -0,0 +1,166 @@
|
|
|
1
|
+
/* eslint-disable @typescript-eslint/no-unused-vars */
|
|
2
|
+
/** @flow */
|
|
3
|
+
|
|
4
|
+
import type { CellRangeRendererParams } from './types.js';
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Default implementation of cellRangeRenderer used by Grid.
|
|
8
|
+
* This renderer supports cell-caching while the user is scrolling.
|
|
9
|
+
*/
|
|
10
|
+
|
|
11
|
+
export default function defaultCellRangeRenderer({
|
|
12
|
+
cellCache,
|
|
13
|
+
cellRenderer,
|
|
14
|
+
columnSizeAndPositionManager,
|
|
15
|
+
columnStartIndex,
|
|
16
|
+
columnStopIndex,
|
|
17
|
+
deferredMeasurementCache,
|
|
18
|
+
horizontalOffsetAdjustment,
|
|
19
|
+
isScrolling,
|
|
20
|
+
isScrollingOptOut,
|
|
21
|
+
parent, // Grid (or List or Table)
|
|
22
|
+
rowSizeAndPositionManager,
|
|
23
|
+
rowStartIndex,
|
|
24
|
+
rowStopIndex,
|
|
25
|
+
styleCache,
|
|
26
|
+
verticalOffsetAdjustment,
|
|
27
|
+
visibleColumnIndices,
|
|
28
|
+
visibleRowIndices,
|
|
29
|
+
}: CellRangeRendererParams) {
|
|
30
|
+
const renderedCells = [];
|
|
31
|
+
|
|
32
|
+
// Browsers have native size limits for elements (eg Chrome 33M pixels, IE 1.5M pixes).
|
|
33
|
+
// User cannot scroll beyond these size limitations.
|
|
34
|
+
// In order to work around this, ScalingCellSizeAndPositionManager compresses offsets.
|
|
35
|
+
// We should never cache styles for compressed offsets though as this can lead to bugs.
|
|
36
|
+
// See issue #576 for more.
|
|
37
|
+
// const areOffsetsAdjusted =
|
|
38
|
+
// columnSizeAndPositionManager.areOffsetsAdjusted() ||
|
|
39
|
+
// rowSizeAndPositionManager.areOffsetsAdjusted();
|
|
40
|
+
|
|
41
|
+
// const canCacheStyle = !isScrolling && !areOffsetsAdjusted;
|
|
42
|
+
|
|
43
|
+
for (let rowIndex = rowStartIndex; rowIndex <= rowStopIndex; rowIndex++) {
|
|
44
|
+
const rowDatum = rowSizeAndPositionManager.getSizeAndPositionOfCell(rowIndex);
|
|
45
|
+
// 计算无偏差
|
|
46
|
+
|
|
47
|
+
for (
|
|
48
|
+
let columnIndex = columnStartIndex;
|
|
49
|
+
columnIndex <= columnStopIndex;
|
|
50
|
+
columnIndex++
|
|
51
|
+
) {
|
|
52
|
+
// const columnDatum = columnSizeAndPositionManager.getSizeAndPositionOfCell(columnIndex);
|
|
53
|
+
const isVisible =
|
|
54
|
+
columnIndex >= visibleColumnIndices['start'] &&
|
|
55
|
+
columnIndex <= visibleColumnIndices['stop'] &&
|
|
56
|
+
rowIndex >= visibleRowIndices['start'] &&
|
|
57
|
+
rowIndex <= visibleRowIndices['stop'];
|
|
58
|
+
const key = `${rowIndex}-${columnIndex}`;
|
|
59
|
+
|
|
60
|
+
// Cache style objects so shallow-compare doesn't re-render unnecessarily.
|
|
61
|
+
// if (canCacheStyle && styleCache[key]) {
|
|
62
|
+
// style = styleCache[key];
|
|
63
|
+
// } else {
|
|
64
|
+
// In deferred mode, cells will be initially rendered before we know their size.
|
|
65
|
+
// Don't interfere with CellMeasurer's measurements by setting an invalid size.
|
|
66
|
+
// if (deferredMeasurementCache && !deferredMeasurementCache.has(rowIndex, columnIndex)) {
|
|
67
|
+
// // Position not-yet-measured cells at top/left 0,0,
|
|
68
|
+
// // And give them width/height of 'auto' so they can grow larger than the parent Grid if necessary.
|
|
69
|
+
// // Positioning them further to the right/bottom influences their measured size.
|
|
70
|
+
// style = {
|
|
71
|
+
// height: 'auto',
|
|
72
|
+
// left: 0,
|
|
73
|
+
// position: 'absolute',
|
|
74
|
+
// top: 0,
|
|
75
|
+
// width: 'auto',
|
|
76
|
+
// };
|
|
77
|
+
// } else {
|
|
78
|
+
const style = {
|
|
79
|
+
height: rowDatum.size,
|
|
80
|
+
left: '73px', // columnDatum.offset + horizontalOffsetAdjustment,
|
|
81
|
+
position: 'absolute',
|
|
82
|
+
top: rowDatum.offset + verticalOffsetAdjustment,
|
|
83
|
+
width: 'calc(100% - 135px)', // columnDatum.size,
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
// styleCache[key] = style;
|
|
87
|
+
// }
|
|
88
|
+
// }
|
|
89
|
+
|
|
90
|
+
const cellRendererParams = {
|
|
91
|
+
columnIndex,
|
|
92
|
+
isScrolling,
|
|
93
|
+
isVisible,
|
|
94
|
+
key,
|
|
95
|
+
parent,
|
|
96
|
+
rowIndex,
|
|
97
|
+
style,
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
let renderedCell;
|
|
101
|
+
|
|
102
|
+
// Avoid re-creating cells while scrolling.
|
|
103
|
+
// This can lead to the same cell being created many times and can cause performance issues for "heavy" cells.
|
|
104
|
+
// If a scroll is in progress- cache and reuse cells.
|
|
105
|
+
// This cache will be thrown away once scrolling completes.
|
|
106
|
+
// However if we are scaling scroll positions and sizes, we should also avoid caching.
|
|
107
|
+
// This is because the offset changes slightly as scroll position changes and caching leads to stale values.
|
|
108
|
+
// For more info refer to issue #395
|
|
109
|
+
//
|
|
110
|
+
// If isScrollingOptOut is specified, we always cache cells.
|
|
111
|
+
// For more info refer to issue #1028
|
|
112
|
+
if (
|
|
113
|
+
(isScrollingOptOut || isScrolling) &&
|
|
114
|
+
!horizontalOffsetAdjustment &&
|
|
115
|
+
!verticalOffsetAdjustment
|
|
116
|
+
) {
|
|
117
|
+
if (!cellCache[key]) {
|
|
118
|
+
cellCache[key] = cellRenderer(cellRendererParams);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
renderedCell = cellCache[key];
|
|
122
|
+
|
|
123
|
+
// If the user is no longer scrolling, don't cache cells.
|
|
124
|
+
// This makes dynamic cell content difficult for users and would also lead to a heavier memory footprint.
|
|
125
|
+
} else {
|
|
126
|
+
renderedCell = cellRenderer(cellRendererParams);
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
if (renderedCell === null || renderedCell === false) {
|
|
130
|
+
continue;
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
if (process.env['NODE_ENV'] !== 'production') {
|
|
134
|
+
warnAboutMissingStyle(parent, renderedCell);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
renderedCells.push(renderedCell);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
return renderedCells;
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
function warnAboutMissingStyle(parent: any, renderedCell: any) {
|
|
145
|
+
if (process.env['NODE_ENV'] !== 'production') {
|
|
146
|
+
if (renderedCell) {
|
|
147
|
+
// If the direct child is a CellMeasurer, then we should check its child
|
|
148
|
+
// See issue #611
|
|
149
|
+
if (renderedCell.type && renderedCell.type.__internalCellMeasurerFlag) {
|
|
150
|
+
// eslint-disable-next-line no-param-reassign
|
|
151
|
+
renderedCell = renderedCell.props.children;
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
if (
|
|
155
|
+
renderedCell &&
|
|
156
|
+
renderedCell.props &&
|
|
157
|
+
renderedCell.props.style === undefined &&
|
|
158
|
+
parent.__warnedAboutMissingStyle !== true
|
|
159
|
+
) {
|
|
160
|
+
parent.__warnedAboutMissingStyle = true;
|
|
161
|
+
|
|
162
|
+
console.warn('Rendered cell should include style property for positioning.');
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
}
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
import type { OverscanIndices, OverscanIndicesGetterParams } from './types.js';
|
|
2
|
+
|
|
3
|
+
export const SCROLL_DIRECTION_BACKWARD = -1;
|
|
4
|
+
export const SCROLL_DIRECTION_FORWARD = 1;
|
|
5
|
+
|
|
6
|
+
export const SCROLL_DIRECTION_HORIZONTAL = 'horizontal';
|
|
7
|
+
export const SCROLL_DIRECTION_VERTICAL = 'vertical';
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Calculates the number of cells to overscan before and after a specified range.
|
|
11
|
+
* This function ensures that overscanning doesn't exceed the available cells.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
export default function defaultOverscanIndicesGetter({
|
|
15
|
+
cellCount,
|
|
16
|
+
overscanCellsCount,
|
|
17
|
+
scrollDirection,
|
|
18
|
+
startIndex,
|
|
19
|
+
stopIndex,
|
|
20
|
+
}: OverscanIndicesGetterParams): OverscanIndices {
|
|
21
|
+
if (scrollDirection === SCROLL_DIRECTION_FORWARD) {
|
|
22
|
+
return {
|
|
23
|
+
overscanStartIndex: Math.max(0, startIndex),
|
|
24
|
+
overscanStopIndex: Math.min(cellCount - 1, stopIndex + overscanCellsCount),
|
|
25
|
+
};
|
|
26
|
+
} else {
|
|
27
|
+
return {
|
|
28
|
+
overscanStartIndex: Math.max(0, startIndex - overscanCellsCount),
|
|
29
|
+
overscanStopIndex: Math.min(cellCount - 1, stopIndex),
|
|
30
|
+
};
|
|
31
|
+
}
|
|
32
|
+
}
|