@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.
Files changed (132) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +0 -0
  3. package/es/auto-sizer/auto-sizer.d.ts +56 -0
  4. package/es/auto-sizer/auto-sizer.d.ts.map +1 -0
  5. package/es/auto-sizer/auto-sizer.js +157 -0
  6. package/es/auto-sizer/index.d.ts +3 -0
  7. package/es/auto-sizer/index.d.ts.map +1 -0
  8. package/es/auto-sizer/index.js +2 -0
  9. package/es/cell-measurer/cell-measurer-cache.d.ts +52 -0
  10. package/es/cell-measurer/cell-measurer-cache.d.ts.map +1 -0
  11. package/es/cell-measurer/cell-measurer-cache.js +176 -0
  12. package/es/cell-measurer/cell-measurer.d.ts +39 -0
  13. package/es/cell-measurer/cell-measurer.d.ts.map +1 -0
  14. package/es/cell-measurer/cell-measurer.js +154 -0
  15. package/es/cell-measurer/index.d.ts +5 -0
  16. package/es/cell-measurer/index.d.ts.map +1 -0
  17. package/es/cell-measurer/index.js +4 -0
  18. package/es/cell-measurer/types.d.ts +9 -0
  19. package/es/cell-measurer/types.d.ts.map +1 -0
  20. package/es/cell-measurer/types.js +0 -0
  21. package/es/grid/accessibility-overscanIndices-getter.d.ts +11 -0
  22. package/es/grid/accessibility-overscanIndices-getter.d.ts.map +1 -0
  23. package/es/grid/accessibility-overscanIndices-getter.js +33 -0
  24. package/es/grid/default-cell-range-renderer.d.ts +10 -0
  25. package/es/grid/default-cell-range-renderer.d.ts.map +1 -0
  26. package/es/grid/default-cell-range-renderer.js +135 -0
  27. package/es/grid/default-overscanIndices-getter.d.ts +11 -0
  28. package/es/grid/default-overscanIndices-getter.d.ts.map +1 -0
  29. package/es/grid/default-overscanIndices-getter.js +28 -0
  30. package/es/grid/grid.d.ts +359 -0
  31. package/es/grid/grid.d.ts.map +1 -0
  32. package/es/grid/grid.js +1287 -0
  33. package/es/grid/index.d.ts +6 -0
  34. package/es/grid/index.d.ts.map +1 -0
  35. package/es/grid/index.js +4 -0
  36. package/es/grid/types.d.ts +87 -0
  37. package/es/grid/types.d.ts.map +1 -0
  38. package/es/grid/types.js +1 -0
  39. package/es/grid/utils/calculate-size-and-position-data-and-update-scroll-offset.d.ts +17 -0
  40. package/es/grid/utils/calculate-size-and-position-data-and-update-scroll-offset.d.ts.map +1 -0
  41. package/es/grid/utils/calculate-size-and-position-data-and-update-scroll-offset.js +25 -0
  42. package/es/grid/utils/cell-size-and-position-manager-row.d.ts +97 -0
  43. package/es/grid/utils/cell-size-and-position-manager-row.d.ts.map +1 -0
  44. package/es/grid/utils/cell-size-and-position-manager-row.js +297 -0
  45. package/es/grid/utils/cell-size-and-position-manager.d.ts +85 -0
  46. package/es/grid/utils/cell-size-and-position-manager.d.ts.map +1 -0
  47. package/es/grid/utils/cell-size-and-position-manager.js +268 -0
  48. package/es/grid/utils/max-element-size.d.ts +2 -0
  49. package/es/grid/utils/max-element-size.d.ts.map +1 -0
  50. package/es/grid/utils/max-element-size.js +17 -0
  51. package/es/grid/utils/scaling-cell-size-and-position-manager-row.d.ts +78 -0
  52. package/es/grid/utils/scaling-cell-size-and-position-manager-row.d.ts.map +1 -0
  53. package/es/grid/utils/scaling-cell-size-and-position-manager-row.js +187 -0
  54. package/es/grid/utils/scaling-cell-size-and-position-manager.d.ts +70 -0
  55. package/es/grid/utils/scaling-cell-size-and-position-manager.d.ts.map +1 -0
  56. package/es/grid/utils/scaling-cell-size-and-position-manager.js +187 -0
  57. package/es/grid/utils/update-scroll-index-helper.d.ts +24 -0
  58. package/es/grid/utils/update-scroll-index-helper.d.ts.map +1 -0
  59. package/es/grid/utils/update-scroll-index-helper.js +40 -0
  60. package/es/index.d.ts +5 -0
  61. package/es/index.d.ts.map +1 -0
  62. package/es/index.js +4 -0
  63. package/es/list/index.d.ts +3 -0
  64. package/es/list/index.d.ts.map +1 -0
  65. package/es/list/index.js +1 -0
  66. package/es/list/list.d.ts +109 -0
  67. package/es/list/list.d.ts.map +1 -0
  68. package/es/list/list.js +261 -0
  69. package/es/list/types.d.ts +22 -0
  70. package/es/list/types.d.ts.map +1 -0
  71. package/es/list/types.js +1 -0
  72. package/es/utils/animation-frame.d.ts +7 -0
  73. package/es/utils/animation-frame.d.ts.map +1 -0
  74. package/es/utils/animation-frame.js +20 -0
  75. package/es/utils/create-callback-memoizer.d.ts +5 -0
  76. package/es/utils/create-callback-memoizer.d.ts.map +1 -0
  77. package/es/utils/create-callback-memoizer.js +25 -0
  78. package/es/utils/get-updated-offset-for-index.d.ts +14 -0
  79. package/es/utils/get-updated-offset-for-index.d.ts.map +1 -0
  80. package/es/utils/get-updated-offset-for-index.js +32 -0
  81. package/es/utils/init-cell-metadata.d.ts +13 -0
  82. package/es/utils/init-cell-metadata.d.ts.map +1 -0
  83. package/es/utils/init-cell-metadata.js +32 -0
  84. package/es/utils/request-animation-timeout.d.ts +12 -0
  85. package/es/utils/request-animation-timeout.d.ts.map +1 -0
  86. package/es/utils/request-animation-timeout.js +33 -0
  87. package/es/utils/test-helper.d.ts +5 -0
  88. package/es/utils/test-helper.d.ts.map +1 -0
  89. package/es/utils/test-helper.js +31 -0
  90. package/es/vendor/binary-search-bounds.d.ts +22 -0
  91. package/es/vendor/binary-search-bounds.d.ts.map +1 -0
  92. package/es/vendor/binary-search-bounds.js +198 -0
  93. package/es/vendor/detect-element-resize.d.ts +16 -0
  94. package/es/vendor/detect-element-resize.d.ts.map +1 -0
  95. package/es/vendor/detect-element-resize.js +184 -0
  96. package/es/vendor/interval-tree.d.ts +10 -0
  97. package/es/vendor/interval-tree.d.ts.map +1 -0
  98. package/es/vendor/interval-tree.js +359 -0
  99. package/package.json +59 -0
  100. package/src/auto-sizer/auto-sizer.tsx +187 -0
  101. package/src/auto-sizer/index.ts +4 -0
  102. package/src/cell-measurer/cell-measurer-cache.ts +220 -0
  103. package/src/cell-measurer/cell-measurer.ts +151 -0
  104. package/src/cell-measurer/index.ts +5 -0
  105. package/src/cell-measurer/types.ts +8 -0
  106. package/src/grid/accessibility-overscanIndices-getter.ts +38 -0
  107. package/src/grid/default-cell-range-renderer.ts +166 -0
  108. package/src/grid/default-overscanIndices-getter.ts +32 -0
  109. package/src/grid/grid.tsx +1672 -0
  110. package/src/grid/index.ts +14 -0
  111. package/src/grid/types.ts +112 -0
  112. package/src/grid/utils/calculate-size-and-position-data-and-update-scroll-offset.ts +62 -0
  113. package/src/grid/utils/cell-size-and-position-manager-row.ts +365 -0
  114. package/src/grid/utils/cell-size-and-position-manager.ts +309 -0
  115. package/src/grid/utils/max-element-size.ts +18 -0
  116. package/src/grid/utils/scaling-cell-size-and-position-manager-row.ts +206 -0
  117. package/src/grid/utils/scaling-cell-size-and-position-manager.ts +198 -0
  118. package/src/grid/utils/update-scroll-index-helper.ts +96 -0
  119. package/src/index.spec.ts +10 -0
  120. package/src/index.ts +4 -0
  121. package/src/list/index.ts +2 -0
  122. package/src/list/list.tsx +292 -0
  123. package/src/list/types.ts +25 -0
  124. package/src/utils/animation-frame.ts +38 -0
  125. package/src/utils/create-callback-memoizer.ts +32 -0
  126. package/src/utils/get-updated-offset-for-index.ts +33 -0
  127. package/src/utils/init-cell-metadata.ts +32 -0
  128. package/src/utils/request-animation-timeout.ts +44 -0
  129. package/src/utils/test-helper.ts +20 -0
  130. package/src/vendor/binary-search-bounds.ts +203 -0
  131. package/src/vendor/detect-element-resize.ts +241 -0
  132. package/src/vendor/interval-tree.ts +406 -0
@@ -0,0 +1,268 @@
1
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
2
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
3
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
4
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
5
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
6
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
7
+ /* eslint-disable no-param-reassign */
8
+ /* eslint-disable prefer-const */
9
+ /**
10
+ * Just-in-time calculates and caches size and position information for a collection of cells.
11
+ */
12
+ var CellSizeAndPositionManager = /*#__PURE__*/function () {
13
+ function CellSizeAndPositionManager(_ref) {
14
+ var cellCount = _ref.cellCount,
15
+ cellSizeGetter = _ref.cellSizeGetter,
16
+ estimatedCellSize = _ref.estimatedCellSize;
17
+ _classCallCheck(this, CellSizeAndPositionManager);
18
+ // Cache of size and position data for cells, mapped by cell index.
19
+ // Note that invalid values may exist in this map so only rely on cells up to this._lastMeasuredIndex
20
+ this._cellSizeAndPositionData = {};
21
+ // Measurements for cells up to this index can be trusted; cells afterward should be estimated.
22
+ this._lastMeasuredIndex = -1;
23
+ // Used in deferred mode to track which cells have been queued for measurement.
24
+ this._lastBatchedIndex = -1;
25
+ this._cellSizeGetter = cellSizeGetter;
26
+ this._cellCount = cellCount;
27
+ this._estimatedCellSize = estimatedCellSize;
28
+ }
29
+ _createClass(CellSizeAndPositionManager, [{
30
+ key: "areOffsetsAdjusted",
31
+ value: function areOffsetsAdjusted() {
32
+ return false;
33
+ }
34
+ }, {
35
+ key: "configure",
36
+ value: function configure(_ref2) {
37
+ var cellCount = _ref2.cellCount,
38
+ estimatedCellSize = _ref2.estimatedCellSize,
39
+ cellSizeGetter = _ref2.cellSizeGetter;
40
+ this._cellCount = cellCount;
41
+ this._estimatedCellSize = estimatedCellSize;
42
+ this._cellSizeGetter = cellSizeGetter;
43
+ }
44
+ }, {
45
+ key: "getCellCount",
46
+ value: function getCellCount() {
47
+ return this._cellCount;
48
+ }
49
+ }, {
50
+ key: "getEstimatedCellSize",
51
+ value: function getEstimatedCellSize() {
52
+ return this._estimatedCellSize;
53
+ }
54
+ }, {
55
+ key: "getLastMeasuredIndex",
56
+ value: function getLastMeasuredIndex() {
57
+ return this._lastMeasuredIndex;
58
+ }
59
+ }, {
60
+ key: "getOffsetAdjustment",
61
+ value: function getOffsetAdjustment() {
62
+ return 0;
63
+ }
64
+
65
+ /**
66
+ * This method returns the size and position for the cell at the specified index.
67
+ * It just-in-time calculates (or used cached values) for cells leading up to the index.
68
+ */
69
+ }, {
70
+ key: "getSizeAndPositionOfCell",
71
+ value: function getSizeAndPositionOfCell(index) {
72
+ if (index < 0 || index >= this._cellCount) {
73
+ throw Error("Requested index ".concat(index, " is outside of range 0..").concat(this._cellCount));
74
+ }
75
+ if (index > this._lastMeasuredIndex) {
76
+ var lastMeasuredCellSizeAndPosition = this.getSizeAndPositionOfLastMeasuredCell();
77
+ var offset = lastMeasuredCellSizeAndPosition.offset + lastMeasuredCellSizeAndPosition.size;
78
+ for (var i = this._lastMeasuredIndex + 1; i <= index; i++) {
79
+ var size = this._cellSizeGetter({
80
+ index: i
81
+ });
82
+
83
+ // undefined or NaN probably means a logic error in the size getter.
84
+ // null means we're using CellMeasurer and haven't yet measured a given index.
85
+ if (size === undefined || isNaN(size)) {
86
+ throw Error("Invalid size returned for cell ".concat(i, " of value ").concat(size));
87
+ } else if (size === null) {
88
+ this._cellSizeAndPositionData[i] = {
89
+ offset: offset,
90
+ size: 0
91
+ };
92
+ this._lastBatchedIndex = index;
93
+ } else {
94
+ this._cellSizeAndPositionData[i] = {
95
+ offset: offset,
96
+ size: size
97
+ };
98
+ offset += size;
99
+ this._lastMeasuredIndex = index;
100
+ }
101
+ }
102
+ }
103
+ return this._cellSizeAndPositionData[index];
104
+ }
105
+ }, {
106
+ key: "getSizeAndPositionOfLastMeasuredCell",
107
+ value: function getSizeAndPositionOfLastMeasuredCell() {
108
+ return this._lastMeasuredIndex >= 0 ? this._cellSizeAndPositionData[this._lastMeasuredIndex] : {
109
+ offset: 0,
110
+ size: 0
111
+ };
112
+ }
113
+
114
+ /**
115
+ * Total size of all cells being measured.
116
+ * This value will be completely estimated initially.
117
+ * As cells are measured, the estimate will be updated.
118
+ */
119
+ }, {
120
+ key: "getTotalSize",
121
+ value: function getTotalSize() {
122
+ var lastMeasuredCellSizeAndPosition = this.getSizeAndPositionOfLastMeasuredCell();
123
+ var totalSizeOfMeasuredCells = lastMeasuredCellSizeAndPosition.offset + lastMeasuredCellSizeAndPosition.size;
124
+ var numUnmeasuredCells = this._cellCount - this._lastMeasuredIndex - 1;
125
+ var totalSizeOfUnmeasuredCells = numUnmeasuredCells * this._estimatedCellSize;
126
+ return totalSizeOfMeasuredCells + totalSizeOfUnmeasuredCells;
127
+ }
128
+
129
+ /**
130
+ * Determines a new offset that ensures a certain cell is visible, given the current offset.
131
+ * If the cell is already visible then the current offset will be returned.
132
+ * If the current offset is too great or small, it will be adjusted just enough to ensure the specified index is visible.
133
+ *
134
+ * @param align Desired alignment within container; one of "auto" (default), "start", or "end"
135
+ * @param containerSize Size (width or height) of the container viewport
136
+ * @param currentOffset Container's current (x or y) offset
137
+ * @param totalSize Total size (width or height) of all cells
138
+ * @return Offset to use to ensure the specified cell is visible
139
+ */
140
+ }, {
141
+ key: "getUpdatedOffsetForIndex",
142
+ value: function getUpdatedOffsetForIndex(_ref3) {
143
+ var _ref3$align = _ref3.align,
144
+ align = _ref3$align === void 0 ? 'auto' : _ref3$align,
145
+ containerSize = _ref3.containerSize,
146
+ currentOffset = _ref3.currentOffset,
147
+ targetIndex = _ref3.targetIndex;
148
+ if (containerSize <= 0) {
149
+ return 0;
150
+ }
151
+ var datum = this.getSizeAndPositionOfCell(targetIndex);
152
+ var maxOffset = datum.offset;
153
+ var minOffset = maxOffset - containerSize + datum.size;
154
+ var idealOffset;
155
+ switch (align) {
156
+ case 'start':
157
+ idealOffset = maxOffset;
158
+ break;
159
+ case 'end':
160
+ idealOffset = minOffset;
161
+ break;
162
+ case 'center':
163
+ idealOffset = maxOffset - (containerSize - datum.size) / 2;
164
+ break;
165
+ default:
166
+ idealOffset = Math.max(minOffset, Math.min(maxOffset, currentOffset));
167
+ break;
168
+ }
169
+ var totalSize = this.getTotalSize();
170
+ return Math.max(0, Math.min(totalSize - containerSize, idealOffset));
171
+ }
172
+ }, {
173
+ key: "getVisibleCellRange",
174
+ value: function getVisibleCellRange(params) {
175
+ var containerSize = params.containerSize,
176
+ offset = params.offset;
177
+ var totalSize = this.getTotalSize();
178
+ if (totalSize === 0) {
179
+ return {};
180
+ }
181
+ var maxOffset = offset + containerSize;
182
+ var start = this._findNearestCell(offset);
183
+ var datum = this.getSizeAndPositionOfCell(start);
184
+ offset = datum.offset + datum.size;
185
+ var stop = start;
186
+ while (offset < maxOffset && stop < this._cellCount - 1) {
187
+ stop++;
188
+ offset += this.getSizeAndPositionOfCell(stop).size;
189
+ }
190
+ return {
191
+ start: start,
192
+ stop: stop
193
+ };
194
+ }
195
+
196
+ /**
197
+ * Clear all cached values for cells after the specified index.
198
+ * This method should be called for any cell that has changed its size.
199
+ * It will not immediately perform any calculations; they'll be performed the next time getSizeAndPositionOfCell() is called.
200
+ */
201
+ }, {
202
+ key: "resetCell",
203
+ value: function resetCell(index) {
204
+ this._lastMeasuredIndex = Math.min(this._lastMeasuredIndex, index - 1);
205
+ }
206
+ }, {
207
+ key: "_binarySearch",
208
+ value: function _binarySearch(high, low, offset) {
209
+ while (low <= high) {
210
+ var middle = low + Math.floor((high - low) / 2);
211
+ var currentOffset = this.getSizeAndPositionOfCell(middle).offset;
212
+ if (currentOffset === offset) {
213
+ return middle;
214
+ } else if (currentOffset < offset) {
215
+ low = middle + 1;
216
+ } else if (currentOffset > offset) {
217
+ high = middle - 1;
218
+ }
219
+ }
220
+ if (low > 0) {
221
+ return low - 1;
222
+ } else {
223
+ return 0;
224
+ }
225
+ }
226
+ }, {
227
+ key: "_exponentialSearch",
228
+ value: function _exponentialSearch(index, offset) {
229
+ var interval = 1;
230
+ while (index < this._cellCount && this.getSizeAndPositionOfCell(index).offset < offset) {
231
+ index += interval;
232
+ interval *= 2;
233
+ }
234
+ return this._binarySearch(Math.min(index, this._cellCount - 1), Math.floor(index / 2), offset);
235
+ }
236
+
237
+ /**
238
+ * Searches for the cell (index) nearest the specified offset.
239
+ *
240
+ * If no exact match is found the next lowest cell index will be returned.
241
+ * This allows partially visible cells (with offsets just before/above the fold) to be visible.
242
+ */
243
+ }, {
244
+ key: "_findNearestCell",
245
+ value: function _findNearestCell(offset) {
246
+ if (isNaN(offset)) {
247
+ throw Error("Invalid offset ".concat(offset, " specified"));
248
+ }
249
+
250
+ // Our search algorithms find the nearest match at or below the specified offset.
251
+ // So make sure the offset is at least 0 or no match will be found.
252
+ offset = Math.max(0, offset);
253
+ var lastMeasuredCellSizeAndPosition = this.getSizeAndPositionOfLastMeasuredCell();
254
+ var lastMeasuredIndex = Math.max(0, this._lastMeasuredIndex);
255
+ if (lastMeasuredCellSizeAndPosition.offset >= offset) {
256
+ // If we've already measured cells within this range just use a binary search as it's faster.
257
+ return this._binarySearch(lastMeasuredIndex, 0, offset);
258
+ } else {
259
+ // If we haven't yet measured this high, fallback to an exponential search with an inner binary search.
260
+ // The exponential search avoids pre-computing sizes for the full set of cells as a binary search would.
261
+ // The overall complexity for this approach is O(log n).
262
+ return this._exponentialSearch(lastMeasuredIndex, offset);
263
+ }
264
+ }
265
+ }]);
266
+ return CellSizeAndPositionManager;
267
+ }();
268
+ export { CellSizeAndPositionManager as default };
@@ -0,0 +1,2 @@
1
+ export declare const getMaxElementSize: () => number;
2
+ //# sourceMappingURL=max-element-size.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"max-element-size.d.ts","sourceRoot":"","sources":["../../../src/grid/utils/max-element-size.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,iBAAiB,QAAO,MAOpC,CAAC"}
@@ -0,0 +1,17 @@
1
+ var DEFAULT_MAX_ELEMENT_SIZE = 1500000;
2
+ var CHROME_MAX_ELEMENT_SIZE = 1.67771e7;
3
+ var isBrowser = function isBrowser() {
4
+ return typeof window !== 'undefined';
5
+ };
6
+ var isChrome = function isChrome() {
7
+ var userAgent = navigator.userAgent;
8
+ return userAgent.indexOf('Chrome') >= 0;
9
+ };
10
+ export var getMaxElementSize = function getMaxElementSize() {
11
+ if (isBrowser()) {
12
+ if (isChrome()) {
13
+ return CHROME_MAX_ELEMENT_SIZE;
14
+ }
15
+ }
16
+ return DEFAULT_MAX_ELEMENT_SIZE;
17
+ };
@@ -0,0 +1,78 @@
1
+ import type { Alignment, CellSizeGetter, VisibleCellRange } from '../types.js';
2
+ import RowCellSizeAndPositionManager from './cell-size-and-position-manager-row.js';
3
+ type ContainerSizeAndOffset = {
4
+ containerSize: number;
5
+ offset: number;
6
+ };
7
+ /**
8
+ * Browsers have scroll offset limitations (eg Chrome stops scrolling at ~33.5M pixels where as Edge tops out at ~1.5M pixels).
9
+ * After a certain position, the browser won't allow the user to scroll further (even via JavaScript scroll offset adjustments).
10
+ * This util picks a lower ceiling for max size and artificially adjusts positions within to make it transparent for users.
11
+ */
12
+ type Params = {
13
+ maxScrollSize?: number;
14
+ cellCount: number;
15
+ cellSizeGetter: CellSizeGetter;
16
+ estimatedCellSize: number;
17
+ cellsHeight: number[];
18
+ editorAreaHeight: number[];
19
+ totalSize: number;
20
+ editorsOffset: number[];
21
+ };
22
+ /**
23
+ * Extends CellSizeAndPositionManager and adds scaling behavior for lists that are too large to fit within a browser's native limits.
24
+ */
25
+ export default class RowScalingCellSizeAndPositionManager {
26
+ _cellSizeAndPositionManager: RowCellSizeAndPositionManager;
27
+ _maxScrollSize: number;
28
+ constructor({ maxScrollSize, ...params }: Params);
29
+ areOffsetsAdjusted(): boolean;
30
+ configure(params: {
31
+ cellCount: number;
32
+ estimatedCellSize: number;
33
+ cellSizeGetter: CellSizeGetter;
34
+ cellsHeight: number[];
35
+ editorAreaHeight: number[];
36
+ totalSize: number;
37
+ editorsOffset: number[];
38
+ }): void;
39
+ getCellCount(): number;
40
+ getEstimatedCellSize(): number;
41
+ getLastMeasuredIndex(): number;
42
+ /**
43
+ * Number of pixels a cell at the given position (offset) should be shifted in order to fit within the scaled container.
44
+ * The offset passed to this function is scaled (safe) as well.
45
+ */
46
+ getOffsetAdjustment({ containerSize, offset, }: ContainerSizeAndOffset): number;
47
+ getSizeAndPositionOfCell(index: number): {
48
+ offset: number;
49
+ size: number;
50
+ };
51
+ getSizeAndPositionOfLastMeasuredCell(): {
52
+ offset: number;
53
+ size: number;
54
+ };
55
+ /** See CellSizeAndPositionManager#getTotalSize */
56
+ getTotalSize(): number;
57
+ /** See CellSizeAndPositionManager#getUpdatedOffsetForIndex */
58
+ getUpdatedOffsetForIndex({ align, containerSize, currentOffset, // safe
59
+ targetIndex, }: {
60
+ align: Alignment;
61
+ containerSize: number;
62
+ currentOffset: number;
63
+ targetIndex: number;
64
+ }): number;
65
+ /** See CellSizeAndPositionManager#getVisibleCellRange */
66
+ getVisibleCellRange({ containerSize, offset, }: ContainerSizeAndOffset): VisibleCellRange;
67
+ resetCell(index: number): void;
68
+ _getOffsetPercentage({ containerSize, offset, // safe
69
+ totalSize, }: {
70
+ containerSize: number;
71
+ offset: number;
72
+ totalSize: number;
73
+ }): number;
74
+ _offsetToSafeOffset({ containerSize, offset, }: ContainerSizeAndOffset): number;
75
+ _safeOffsetToOffset({ containerSize, offset, }: ContainerSizeAndOffset): number;
76
+ }
77
+ export {};
78
+ //# sourceMappingURL=scaling-cell-size-and-position-manager-row.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scaling-cell-size-and-position-manager-row.d.ts","sourceRoot":"","sources":["../../../src/grid/utils/scaling-cell-size-and-position-manager-row.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/E,OAAO,6BAA6B,MAAM,yCAAyC,CAAC;AAGpF,KAAK,sBAAsB,GAAG;IAC5B,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;;;GAIG;AAEH,KAAK,MAAM,GAAG;IACZ,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,cAAc,CAAC;IAC/B,iBAAiB,EAAE,MAAM,CAAC;IAC1B,WAAW,EAAE,MAAM,EAAE,CAAC;IACtB,gBAAgB,EAAE,MAAM,EAAE,CAAC;IAC3B,SAAS,EAAE,MAAM,CAAC;IAClB,aAAa,EAAE,MAAM,EAAE,CAAC;CACzB,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,oCAAoC;IACvD,2BAA2B,EAAE,6BAA6B,CAAC;IAC3D,cAAc,EAAE,MAAM,CAAC;gBAEX,EAAE,aAAmC,EAAE,GAAG,MAAM,EAAE,EAAE,MAAM;IAMtE,kBAAkB,IAAI,OAAO;IAI7B,SAAS,CAAC,MAAM,EAAE;QAChB,SAAS,EAAE,MAAM,CAAC;QAClB,iBAAiB,EAAE,MAAM,CAAC;QAC1B,cAAc,EAAE,cAAc,CAAC;QAC/B,WAAW,EAAE,MAAM,EAAE,CAAC;QACtB,gBAAgB,EAAE,MAAM,EAAE,CAAC;QAC3B,SAAS,EAAE,MAAM,CAAC;QAClB,aAAa,EAAE,MAAM,EAAE,CAAC;KACzB;IAID,YAAY,IAAI,MAAM;IAItB,oBAAoB,IAAI,MAAM;IAI9B,oBAAoB,IAAI,MAAM;IAI9B;;;OAGG;IACH,mBAAmB,CAAC,EAClB,aAAa,EACb,MAAM,GACP,EAAE,sBAAsB,GAAG,MAAM;IAYlC,wBAAwB,CAAC,KAAK,EAAE,MAAM;;;;IAItC,oCAAoC;;;;IAIpC,kDAAkD;IAClD,YAAY,IAAI,MAAM;IAOtB,8DAA8D;IAC9D,wBAAwB,CAAC,EACvB,KAAc,EACd,aAAa,EACb,aAAa,EAAE,OAAO;IACtB,WAAW,GACZ,EAAE;QACD,KAAK,EAAE,SAAS,CAAC;QACjB,aAAa,EAAE,MAAM,CAAC;QACtB,aAAa,EAAE,MAAM,CAAC;QACtB,WAAW,EAAE,MAAM,CAAC;KACrB;IAmBD,yDAAyD;IACzD,mBAAmB,CAAC,EAClB,aAAa,EACb,MAAM,GACP,EAAE,sBAAsB,GAAG,gBAAgB;IAY5C,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAI9B,oBAAoB,CAAC,EACnB,aAAa,EACb,MAAM,EAAE,OAAO;IACf,SAAS,GACV,EAAE;QACD,aAAa,EAAE,MAAM,CAAC;QACtB,MAAM,EAAE,MAAM,CAAC;QACf,SAAS,EAAE,MAAM,CAAC;KACnB;IAID,mBAAmB,CAAC,EAClB,aAAa,EACb,MAAM,GACP,EAAE,sBAAsB,GAAG,MAAM;IAiBlC,mBAAmB,CAAC,EAClB,aAAa,EACb,MAAM,GACP,EAAE,sBAAsB,GAAG,MAAM;CAgBnC"}
@@ -0,0 +1,187 @@
1
+ var _excluded = ["maxScrollSize"];
2
+ function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
3
+ function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
4
+ function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
5
+ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6
+ function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, _toPropertyKey(descriptor.key), descriptor); } }
7
+ function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
8
+ function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
9
+ function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); }
10
+ /* eslint-disable no-param-reassign */
11
+
12
+ import RowCellSizeAndPositionManager from "./cell-size-and-position-manager-row.js";
13
+ import { getMaxElementSize } from "./max-element-size.js";
14
+
15
+ /**
16
+ * Browsers have scroll offset limitations (eg Chrome stops scrolling at ~33.5M pixels where as Edge tops out at ~1.5M pixels).
17
+ * After a certain position, the browser won't allow the user to scroll further (even via JavaScript scroll offset adjustments).
18
+ * This util picks a lower ceiling for max size and artificially adjusts positions within to make it transparent for users.
19
+ */
20
+ /**
21
+ * Extends CellSizeAndPositionManager and adds scaling behavior for lists that are too large to fit within a browser's native limits.
22
+ */
23
+ var RowScalingCellSizeAndPositionManager = /*#__PURE__*/function () {
24
+ function RowScalingCellSizeAndPositionManager(_ref) {
25
+ var _ref$maxScrollSize = _ref.maxScrollSize,
26
+ maxScrollSize = _ref$maxScrollSize === void 0 ? getMaxElementSize() : _ref$maxScrollSize,
27
+ params = _objectWithoutProperties(_ref, _excluded);
28
+ _classCallCheck(this, RowScalingCellSizeAndPositionManager);
29
+ // Favor composition over inheritance to simplify IE10 support
30
+ this._cellSizeAndPositionManager = new RowCellSizeAndPositionManager(params);
31
+ this._maxScrollSize = maxScrollSize;
32
+ }
33
+ _createClass(RowScalingCellSizeAndPositionManager, [{
34
+ key: "areOffsetsAdjusted",
35
+ value: function areOffsetsAdjusted() {
36
+ return this._cellSizeAndPositionManager.getTotalSize() > this._maxScrollSize;
37
+ }
38
+ }, {
39
+ key: "configure",
40
+ value: function configure(params) {
41
+ this._cellSizeAndPositionManager.configure(params);
42
+ }
43
+ }, {
44
+ key: "getCellCount",
45
+ value: function getCellCount() {
46
+ return this._cellSizeAndPositionManager.getCellCount();
47
+ }
48
+ }, {
49
+ key: "getEstimatedCellSize",
50
+ value: function getEstimatedCellSize() {
51
+ return this._cellSizeAndPositionManager.getEstimatedCellSize();
52
+ }
53
+ }, {
54
+ key: "getLastMeasuredIndex",
55
+ value: function getLastMeasuredIndex() {
56
+ return this._cellSizeAndPositionManager.getLastMeasuredIndex();
57
+ }
58
+
59
+ /**
60
+ * Number of pixels a cell at the given position (offset) should be shifted in order to fit within the scaled container.
61
+ * The offset passed to this function is scaled (safe) as well.
62
+ */
63
+ }, {
64
+ key: "getOffsetAdjustment",
65
+ value: function getOffsetAdjustment(_ref2) {
66
+ var containerSize = _ref2.containerSize,
67
+ offset = _ref2.offset;
68
+ var totalSize = this._cellSizeAndPositionManager.getTotalSize();
69
+ var safeTotalSize = this.getTotalSize();
70
+ var offsetPercentage = this._getOffsetPercentage({
71
+ containerSize: containerSize,
72
+ offset: offset,
73
+ totalSize: safeTotalSize
74
+ });
75
+ return Math.round(offsetPercentage * (safeTotalSize - totalSize));
76
+ }
77
+ }, {
78
+ key: "getSizeAndPositionOfCell",
79
+ value: function getSizeAndPositionOfCell(index) {
80
+ return this._cellSizeAndPositionManager.getSizeAndPositionOfCell(index);
81
+ }
82
+ }, {
83
+ key: "getSizeAndPositionOfLastMeasuredCell",
84
+ value: function getSizeAndPositionOfLastMeasuredCell() {
85
+ return this._cellSizeAndPositionManager.getSizeAndPositionOfLastMeasuredCell();
86
+ }
87
+
88
+ /** See CellSizeAndPositionManager#getTotalSize */
89
+ }, {
90
+ key: "getTotalSize",
91
+ value: function getTotalSize() {
92
+ return Math.min(this._maxScrollSize, this._cellSizeAndPositionManager.getTotalSize());
93
+ }
94
+
95
+ /** See CellSizeAndPositionManager#getUpdatedOffsetForIndex */
96
+ }, {
97
+ key: "getUpdatedOffsetForIndex",
98
+ value: function getUpdatedOffsetForIndex(_ref3) {
99
+ var _ref3$align = _ref3.align,
100
+ align = _ref3$align === void 0 ? 'auto' : _ref3$align,
101
+ containerSize = _ref3.containerSize,
102
+ currentOffset = _ref3.currentOffset,
103
+ targetIndex = _ref3.targetIndex;
104
+ currentOffset = this._safeOffsetToOffset({
105
+ containerSize: containerSize,
106
+ offset: currentOffset
107
+ });
108
+ var offset = this._cellSizeAndPositionManager.getUpdatedOffsetForIndex({
109
+ align: align,
110
+ containerSize: containerSize,
111
+ currentOffset: currentOffset,
112
+ targetIndex: targetIndex
113
+ });
114
+ return this._offsetToSafeOffset({
115
+ containerSize: containerSize,
116
+ offset: offset
117
+ });
118
+ }
119
+
120
+ /** See CellSizeAndPositionManager#getVisibleCellRange */
121
+ }, {
122
+ key: "getVisibleCellRange",
123
+ value: function getVisibleCellRange(_ref4) {
124
+ var containerSize = _ref4.containerSize,
125
+ offset = _ref4.offset;
126
+ offset = this._safeOffsetToOffset({
127
+ containerSize: containerSize,
128
+ offset: offset
129
+ });
130
+ return this._cellSizeAndPositionManager.getVisibleCellRange({
131
+ containerSize: containerSize,
132
+ offset: offset
133
+ });
134
+ }
135
+ }, {
136
+ key: "resetCell",
137
+ value: function resetCell(index) {
138
+ this._cellSizeAndPositionManager.resetCell(index);
139
+ }
140
+ }, {
141
+ key: "_getOffsetPercentage",
142
+ value: function _getOffsetPercentage(_ref5) {
143
+ var containerSize = _ref5.containerSize,
144
+ offset = _ref5.offset,
145
+ totalSize = _ref5.totalSize;
146
+ return totalSize <= containerSize ? 0 : offset / (totalSize - containerSize);
147
+ }
148
+ }, {
149
+ key: "_offsetToSafeOffset",
150
+ value: function _offsetToSafeOffset(_ref6) {
151
+ var containerSize = _ref6.containerSize,
152
+ offset = _ref6.offset;
153
+ var totalSize = this._cellSizeAndPositionManager.getTotalSize();
154
+ var safeTotalSize = this.getTotalSize();
155
+ if (totalSize === safeTotalSize) {
156
+ return offset;
157
+ } else {
158
+ var offsetPercentage = this._getOffsetPercentage({
159
+ containerSize: containerSize,
160
+ offset: offset,
161
+ totalSize: totalSize
162
+ });
163
+ return Math.round(offsetPercentage * (safeTotalSize - containerSize));
164
+ }
165
+ }
166
+ }, {
167
+ key: "_safeOffsetToOffset",
168
+ value: function _safeOffsetToOffset(_ref7) {
169
+ var containerSize = _ref7.containerSize,
170
+ offset = _ref7.offset;
171
+ var totalSize = this._cellSizeAndPositionManager.getTotalSize();
172
+ var safeTotalSize = this.getTotalSize();
173
+ if (totalSize === safeTotalSize) {
174
+ return offset;
175
+ } else {
176
+ var offsetPercentage = this._getOffsetPercentage({
177
+ containerSize: containerSize,
178
+ offset: offset,
179
+ totalSize: safeTotalSize
180
+ });
181
+ return Math.round(offsetPercentage * (totalSize - containerSize));
182
+ }
183
+ }
184
+ }]);
185
+ return RowScalingCellSizeAndPositionManager;
186
+ }();
187
+ export { RowScalingCellSizeAndPositionManager as default };
@@ -0,0 +1,70 @@
1
+ import type { Alignment, CellSizeGetter, VisibleCellRange } from '../types.js';
2
+ import CellSizeAndPositionManager from './cell-size-and-position-manager.js';
3
+ type ContainerSizeAndOffset = {
4
+ containerSize: number;
5
+ offset: number;
6
+ };
7
+ /**
8
+ * Browsers have scroll offset limitations (eg Chrome stops scrolling at ~33.5M pixels where as Edge tops out at ~1.5M pixels).
9
+ * After a certain position, the browser won't allow the user to scroll further (even via JavaScript scroll offset adjustments).
10
+ * This util picks a lower ceiling for max size and artificially adjusts positions within to make it transparent for users.
11
+ */
12
+ type Params = {
13
+ maxScrollSize?: number;
14
+ cellCount: number;
15
+ cellSizeGetter: CellSizeGetter;
16
+ estimatedCellSize: number;
17
+ };
18
+ /**
19
+ * Extends CellSizeAndPositionManager and adds scaling behavior for lists that are too large to fit within a browser's native limits.
20
+ */
21
+ export default class ScalingCellSizeAndPositionManager {
22
+ _cellSizeAndPositionManager: CellSizeAndPositionManager;
23
+ _maxScrollSize: number;
24
+ constructor({ maxScrollSize, ...params }: Params);
25
+ areOffsetsAdjusted(): boolean;
26
+ configure(params: {
27
+ cellCount: number;
28
+ estimatedCellSize: number;
29
+ cellSizeGetter: CellSizeGetter;
30
+ }): void;
31
+ getCellCount(): number;
32
+ getEstimatedCellSize(): number;
33
+ getLastMeasuredIndex(): number;
34
+ /**
35
+ * Number of pixels a cell at the given position (offset) should be shifted in order to fit within the scaled container.
36
+ * The offset passed to this function is scaled (safe) as well.
37
+ */
38
+ getOffsetAdjustment({ containerSize, offset, }: ContainerSizeAndOffset): number;
39
+ getSizeAndPositionOfCell(index: number): {
40
+ offset: number;
41
+ size: number;
42
+ };
43
+ getSizeAndPositionOfLastMeasuredCell(): {
44
+ offset: number;
45
+ size: number;
46
+ };
47
+ /** See CellSizeAndPositionManager#getTotalSize */
48
+ getTotalSize(): number;
49
+ /** See CellSizeAndPositionManager#getUpdatedOffsetForIndex */
50
+ getUpdatedOffsetForIndex({ align, containerSize, currentOffset, // safe
51
+ targetIndex, }: {
52
+ align: Alignment;
53
+ containerSize: number;
54
+ currentOffset: number;
55
+ targetIndex: number;
56
+ }): number;
57
+ /** See CellSizeAndPositionManager#getVisibleCellRange */
58
+ getVisibleCellRange({ containerSize, offset, }: ContainerSizeAndOffset): VisibleCellRange;
59
+ resetCell(index: number): void;
60
+ _getOffsetPercentage({ containerSize, offset, // safe
61
+ totalSize, }: {
62
+ containerSize: number;
63
+ offset: number;
64
+ totalSize: number;
65
+ }): number;
66
+ _offsetToSafeOffset({ containerSize, offset, }: ContainerSizeAndOffset): number;
67
+ _safeOffsetToOffset({ containerSize, offset, }: ContainerSizeAndOffset): number;
68
+ }
69
+ export {};
70
+ //# sourceMappingURL=scaling-cell-size-and-position-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scaling-cell-size-and-position-manager.d.ts","sourceRoot":"","sources":["../../../src/grid/utils/scaling-cell-size-and-position-manager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAE/E,OAAO,0BAA0B,MAAM,qCAAqC,CAAC;AAG7E,KAAK,sBAAsB,GAAG;IAC5B,aAAa,EAAE,MAAM,CAAC;IACtB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC;AAEF;;;;GAIG;AAEH,KAAK,MAAM,GAAG;IACZ,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;IAClB,cAAc,EAAE,cAAc,CAAC;IAC/B,iBAAiB,EAAE,MAAM,CAAC;CAC3B,CAAC;AAEF;;GAEG;AACH,MAAM,CAAC,OAAO,OAAO,iCAAiC;IACpD,2BAA2B,EAAE,0BAA0B,CAAC;IACxD,cAAc,EAAE,MAAM,CAAC;gBAEX,EAAE,aAAmC,EAAE,GAAG,MAAM,EAAE,EAAE,MAAM;IAMtE,kBAAkB,IAAI,OAAO;IAI7B,SAAS,CAAC,MAAM,EAAE;QAChB,SAAS,EAAE,MAAM,CAAC;QAClB,iBAAiB,EAAE,MAAM,CAAC;QAC1B,cAAc,EAAE,cAAc,CAAC;KAChC;IAID,YAAY,IAAI,MAAM;IAItB,oBAAoB,IAAI,MAAM;IAI9B,oBAAoB,IAAI,MAAM;IAI9B;;;OAGG;IACH,mBAAmB,CAAC,EAClB,aAAa,EACb,MAAM,GACP,EAAE,sBAAsB,GAAG,MAAM;IAYlC,wBAAwB,CAAC,KAAK,EAAE,MAAM;;;;IAItC,oCAAoC;;;;IAIpC,kDAAkD;IAClD,YAAY,IAAI,MAAM;IAOtB,8DAA8D;IAC9D,wBAAwB,CAAC,EACvB,KAAc,EACd,aAAa,EACb,aAAa,EAAE,OAAO;IACtB,WAAW,GACZ,EAAE;QACD,KAAK,EAAE,SAAS,CAAC;QACjB,aAAa,EAAE,MAAM,CAAC;QACtB,aAAa,EAAE,MAAM,CAAC;QACtB,WAAW,EAAE,MAAM,CAAC;KACrB;IAmBD,yDAAyD;IACzD,mBAAmB,CAAC,EAClB,aAAa,EACb,MAAM,GACP,EAAE,sBAAsB,GAAG,gBAAgB;IAY5C,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAI9B,oBAAoB,CAAC,EACnB,aAAa,EACb,MAAM,EAAE,OAAO;IACf,SAAS,GACV,EAAE;QACD,aAAa,EAAE,MAAM,CAAC;QACtB,MAAM,EAAE,MAAM,CAAC;QACf,SAAS,EAAE,MAAM,CAAC;KACnB;IAID,mBAAmB,CAAC,EAClB,aAAa,EACb,MAAM,GACP,EAAE,sBAAsB,GAAG,MAAM;IAiBlC,mBAAmB,CAAC,EAClB,aAAa,EACb,MAAM,GACP,EAAE,sBAAsB,GAAG,MAAM;CAgBnC"}