@digdir/designsystemet-react 0.55.1-alpha.0 → 0.56.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/components/Chip/Chip.module.css.js +1 -1
- package/dist/cjs/components/DropdownMenu/DropdownMenu.js +2 -2
- package/dist/cjs/components/Popover/Popover.js +2 -2
- package/dist/cjs/components/Popover/PopoverContent.js +2 -2
- package/dist/cjs/components/Tooltip/Tooltip.js +1 -1
- package/dist/cjs/components/form/Checkbox/Checkbox.js +2 -2
- package/dist/cjs/components/form/Combobox/Combobox.js +19 -4
- package/dist/cjs/components/form/Radio/Radio.js +2 -2
- package/dist/cjs/components/form/Search/Search.js +1 -1
- package/dist/cjs/node_modules/@floating-ui/react/dist/floating-ui.react.js +1 -1
- package/dist/cjs/node_modules/@floating-ui/{react/node_modules/@floating-ui/react-dom → react-dom}/dist/floating-ui.react-dom.js +2 -2
- package/dist/cjs/node_modules/@tanstack/react-virtual/{build/lib → dist/esm}/index.js +18 -32
- package/dist/cjs/node_modules/@tanstack/virtual-core/dist/esm/index.js +606 -0
- package/dist/cjs/node_modules/@tanstack/virtual-core/dist/esm/utils.js +60 -0
- package/dist/cjs/react-css-modules.css +76 -79
- package/dist/esm/components/Chip/Chip.module.css.js +1 -1
- package/dist/esm/components/DropdownMenu/DropdownMenu.js +2 -2
- package/dist/esm/components/Popover/Popover.js +2 -2
- package/dist/esm/components/Popover/PopoverContent.js +2 -2
- package/dist/esm/components/Tooltip/Tooltip.js +1 -1
- package/dist/esm/components/form/Checkbox/Checkbox.js +2 -2
- package/dist/esm/components/form/Combobox/Combobox.js +19 -4
- package/dist/esm/components/form/Radio/Radio.js +2 -2
- package/dist/esm/components/form/Search/Search.js +1 -1
- package/dist/esm/node_modules/@floating-ui/react/dist/floating-ui.react.js +2 -2
- package/dist/esm/node_modules/@floating-ui/{react/node_modules/@floating-ui/react-dom → react-dom}/dist/floating-ui.react-dom.js +4 -4
- package/dist/esm/node_modules/@tanstack/react-virtual/dist/esm/index.js +43 -0
- package/dist/esm/node_modules/@tanstack/virtual-core/dist/esm/index.js +595 -0
- package/dist/esm/node_modules/@tanstack/virtual-core/dist/esm/utils.js +56 -0
- package/dist/esm/react-css-modules.css +76 -79
- package/dist/types/components/DropdownMenu/DropdownMenu.d.ts +1 -6
- package/dist/types/components/DropdownMenu/DropdownMenu.d.ts.map +1 -1
- package/dist/types/components/Popover/Popover.d.ts +1 -6
- package/dist/types/components/Popover/Popover.d.ts.map +1 -1
- package/dist/types/components/form/Checkbox/Checkbox.d.ts.map +1 -1
- package/dist/types/components/form/Combobox/Combobox.d.ts.map +1 -1
- package/dist/types/components/form/Radio/Radio.d.ts.map +1 -1
- package/dist/types/components/form/Search/Search.d.ts.map +1 -1
- package/package.json +3 -3
- package/dist/cjs/node_modules/@tanstack/react-virtual/build/lib/_virtual/_rollupPluginBabelHelpers.js +0 -29
- package/dist/cjs/node_modules/@tanstack/virtual-core/build/lib/_virtual/_rollupPluginBabelHelpers.js +0 -29
- package/dist/cjs/node_modules/@tanstack/virtual-core/build/lib/index.js +0 -607
- package/dist/cjs/node_modules/@tanstack/virtual-core/build/lib/utils.js +0 -62
- package/dist/esm/node_modules/@tanstack/react-virtual/build/lib/_virtual/_rollupPluginBabelHelpers.js +0 -27
- package/dist/esm/node_modules/@tanstack/react-virtual/build/lib/index.js +0 -57
- package/dist/esm/node_modules/@tanstack/virtual-core/build/lib/_virtual/_rollupPluginBabelHelpers.js +0 -27
- package/dist/esm/node_modules/@tanstack/virtual-core/build/lib/index.js +0 -596
- package/dist/esm/node_modules/@tanstack/virtual-core/build/lib/utils.js +0 -58
|
@@ -0,0 +1,606 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
var utils = require('./utils.js');
|
|
5
|
+
|
|
6
|
+
const defaultKeyExtractor = (index) => index;
|
|
7
|
+
const defaultRangeExtractor = (range) => {
|
|
8
|
+
const start = Math.max(range.startIndex - range.overscan, 0);
|
|
9
|
+
const end = Math.min(range.endIndex + range.overscan, range.count - 1);
|
|
10
|
+
const arr = [];
|
|
11
|
+
for (let i = start; i <= end; i++) {
|
|
12
|
+
arr.push(i);
|
|
13
|
+
}
|
|
14
|
+
return arr;
|
|
15
|
+
};
|
|
16
|
+
const observeElementRect = (instance, cb) => {
|
|
17
|
+
const element = instance.scrollElement;
|
|
18
|
+
if (!element) {
|
|
19
|
+
return;
|
|
20
|
+
}
|
|
21
|
+
const handler = (rect) => {
|
|
22
|
+
const { width, height } = rect;
|
|
23
|
+
cb({ width: Math.round(width), height: Math.round(height) });
|
|
24
|
+
};
|
|
25
|
+
handler(element.getBoundingClientRect());
|
|
26
|
+
if (typeof ResizeObserver === "undefined") {
|
|
27
|
+
return () => {
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
const observer = new ResizeObserver((entries) => {
|
|
31
|
+
const entry = entries[0];
|
|
32
|
+
if (entry == null ? void 0 : entry.borderBoxSize) {
|
|
33
|
+
const box = entry.borderBoxSize[0];
|
|
34
|
+
if (box) {
|
|
35
|
+
handler({ width: box.inlineSize, height: box.blockSize });
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
handler(element.getBoundingClientRect());
|
|
40
|
+
});
|
|
41
|
+
observer.observe(element, { box: "border-box" });
|
|
42
|
+
return () => {
|
|
43
|
+
observer.unobserve(element);
|
|
44
|
+
};
|
|
45
|
+
};
|
|
46
|
+
const observeElementOffset = (instance, cb) => {
|
|
47
|
+
const element = instance.scrollElement;
|
|
48
|
+
if (!element) {
|
|
49
|
+
return;
|
|
50
|
+
}
|
|
51
|
+
const handler = () => {
|
|
52
|
+
cb(element[instance.options.horizontal ? "scrollLeft" : "scrollTop"]);
|
|
53
|
+
};
|
|
54
|
+
handler();
|
|
55
|
+
element.addEventListener("scroll", handler, {
|
|
56
|
+
passive: true
|
|
57
|
+
});
|
|
58
|
+
return () => {
|
|
59
|
+
element.removeEventListener("scroll", handler);
|
|
60
|
+
};
|
|
61
|
+
};
|
|
62
|
+
const measureElement = (element, entry, instance) => {
|
|
63
|
+
if (entry == null ? void 0 : entry.borderBoxSize) {
|
|
64
|
+
const box = entry.borderBoxSize[0];
|
|
65
|
+
if (box) {
|
|
66
|
+
const size = Math.round(
|
|
67
|
+
box[instance.options.horizontal ? "inlineSize" : "blockSize"]
|
|
68
|
+
);
|
|
69
|
+
return size;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
return Math.round(
|
|
73
|
+
element.getBoundingClientRect()[instance.options.horizontal ? "width" : "height"]
|
|
74
|
+
);
|
|
75
|
+
};
|
|
76
|
+
const elementScroll = (offset, {
|
|
77
|
+
adjustments = 0,
|
|
78
|
+
behavior
|
|
79
|
+
}, instance) => {
|
|
80
|
+
var _a, _b;
|
|
81
|
+
const toOffset = offset + adjustments;
|
|
82
|
+
(_b = (_a = instance.scrollElement) == null ? void 0 : _a.scrollTo) == null ? void 0 : _b.call(_a, {
|
|
83
|
+
[instance.options.horizontal ? "left" : "top"]: toOffset,
|
|
84
|
+
behavior
|
|
85
|
+
});
|
|
86
|
+
};
|
|
87
|
+
class Virtualizer {
|
|
88
|
+
constructor(opts) {
|
|
89
|
+
this.unsubs = [];
|
|
90
|
+
this.scrollElement = null;
|
|
91
|
+
this.isScrolling = false;
|
|
92
|
+
this.isScrollingTimeoutId = null;
|
|
93
|
+
this.scrollToIndexTimeoutId = null;
|
|
94
|
+
this.measurementsCache = [];
|
|
95
|
+
this.itemSizeCache = /* @__PURE__ */ new Map();
|
|
96
|
+
this.pendingMeasuredCacheIndexes = [];
|
|
97
|
+
this.scrollDirection = null;
|
|
98
|
+
this.scrollAdjustments = 0;
|
|
99
|
+
this.measureElementCache = /* @__PURE__ */ new Map();
|
|
100
|
+
this.observer = /* @__PURE__ */ (() => {
|
|
101
|
+
let _ro = null;
|
|
102
|
+
const get = () => {
|
|
103
|
+
if (_ro) {
|
|
104
|
+
return _ro;
|
|
105
|
+
} else if (typeof ResizeObserver !== "undefined") {
|
|
106
|
+
return _ro = new ResizeObserver((entries) => {
|
|
107
|
+
entries.forEach((entry) => {
|
|
108
|
+
this._measureElement(entry.target, entry);
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
} else {
|
|
112
|
+
return null;
|
|
113
|
+
}
|
|
114
|
+
};
|
|
115
|
+
return {
|
|
116
|
+
disconnect: () => {
|
|
117
|
+
var _a;
|
|
118
|
+
return (_a = get()) == null ? void 0 : _a.disconnect();
|
|
119
|
+
},
|
|
120
|
+
observe: (target) => {
|
|
121
|
+
var _a;
|
|
122
|
+
return (_a = get()) == null ? void 0 : _a.observe(target, { box: "border-box" });
|
|
123
|
+
},
|
|
124
|
+
unobserve: (target) => {
|
|
125
|
+
var _a;
|
|
126
|
+
return (_a = get()) == null ? void 0 : _a.unobserve(target);
|
|
127
|
+
}
|
|
128
|
+
};
|
|
129
|
+
})();
|
|
130
|
+
this.range = null;
|
|
131
|
+
this.setOptions = (opts2) => {
|
|
132
|
+
Object.entries(opts2).forEach(([key, value]) => {
|
|
133
|
+
if (typeof value === "undefined")
|
|
134
|
+
delete opts2[key];
|
|
135
|
+
});
|
|
136
|
+
this.options = {
|
|
137
|
+
debug: false,
|
|
138
|
+
initialOffset: 0,
|
|
139
|
+
overscan: 1,
|
|
140
|
+
paddingStart: 0,
|
|
141
|
+
paddingEnd: 0,
|
|
142
|
+
scrollPaddingStart: 0,
|
|
143
|
+
scrollPaddingEnd: 0,
|
|
144
|
+
horizontal: false,
|
|
145
|
+
getItemKey: defaultKeyExtractor,
|
|
146
|
+
rangeExtractor: defaultRangeExtractor,
|
|
147
|
+
onChange: () => {
|
|
148
|
+
},
|
|
149
|
+
measureElement,
|
|
150
|
+
initialRect: { width: 0, height: 0 },
|
|
151
|
+
scrollMargin: 0,
|
|
152
|
+
gap: 0,
|
|
153
|
+
scrollingDelay: 150,
|
|
154
|
+
indexAttribute: "data-index",
|
|
155
|
+
initialMeasurementsCache: [],
|
|
156
|
+
lanes: 1,
|
|
157
|
+
...opts2
|
|
158
|
+
};
|
|
159
|
+
};
|
|
160
|
+
this.notify = (sync) => {
|
|
161
|
+
var _a, _b;
|
|
162
|
+
(_b = (_a = this.options).onChange) == null ? void 0 : _b.call(_a, this, sync);
|
|
163
|
+
};
|
|
164
|
+
this.maybeNotify = utils.memo(
|
|
165
|
+
() => {
|
|
166
|
+
this.calculateRange();
|
|
167
|
+
return [
|
|
168
|
+
this.isScrolling,
|
|
169
|
+
this.range ? this.range.startIndex : null,
|
|
170
|
+
this.range ? this.range.endIndex : null
|
|
171
|
+
];
|
|
172
|
+
},
|
|
173
|
+
(isScrolling) => {
|
|
174
|
+
this.notify(isScrolling);
|
|
175
|
+
},
|
|
176
|
+
{
|
|
177
|
+
key: process.env.NODE_ENV !== "production" && "maybeNotify",
|
|
178
|
+
debug: () => this.options.debug,
|
|
179
|
+
initialDeps: [
|
|
180
|
+
this.isScrolling,
|
|
181
|
+
this.range ? this.range.startIndex : null,
|
|
182
|
+
this.range ? this.range.endIndex : null
|
|
183
|
+
]
|
|
184
|
+
}
|
|
185
|
+
);
|
|
186
|
+
this.cleanup = () => {
|
|
187
|
+
this.unsubs.filter(Boolean).forEach((d) => d());
|
|
188
|
+
this.unsubs = [];
|
|
189
|
+
this.scrollElement = null;
|
|
190
|
+
};
|
|
191
|
+
this._didMount = () => {
|
|
192
|
+
this.measureElementCache.forEach(this.observer.observe);
|
|
193
|
+
return () => {
|
|
194
|
+
this.observer.disconnect();
|
|
195
|
+
this.cleanup();
|
|
196
|
+
};
|
|
197
|
+
};
|
|
198
|
+
this._willUpdate = () => {
|
|
199
|
+
const scrollElement = this.options.getScrollElement();
|
|
200
|
+
if (this.scrollElement !== scrollElement) {
|
|
201
|
+
this.cleanup();
|
|
202
|
+
this.scrollElement = scrollElement;
|
|
203
|
+
this._scrollToOffset(this.scrollOffset, {
|
|
204
|
+
adjustments: void 0,
|
|
205
|
+
behavior: void 0
|
|
206
|
+
});
|
|
207
|
+
this.unsubs.push(
|
|
208
|
+
this.options.observeElementRect(this, (rect) => {
|
|
209
|
+
this.scrollRect = rect;
|
|
210
|
+
this.maybeNotify();
|
|
211
|
+
})
|
|
212
|
+
);
|
|
213
|
+
this.unsubs.push(
|
|
214
|
+
this.options.observeElementOffset(this, (offset) => {
|
|
215
|
+
this.scrollAdjustments = 0;
|
|
216
|
+
if (this.scrollOffset === offset) {
|
|
217
|
+
return;
|
|
218
|
+
}
|
|
219
|
+
if (this.isScrollingTimeoutId !== null) {
|
|
220
|
+
clearTimeout(this.isScrollingTimeoutId);
|
|
221
|
+
this.isScrollingTimeoutId = null;
|
|
222
|
+
}
|
|
223
|
+
this.isScrolling = true;
|
|
224
|
+
this.scrollDirection = this.scrollOffset < offset ? "forward" : "backward";
|
|
225
|
+
this.scrollOffset = offset;
|
|
226
|
+
this.maybeNotify();
|
|
227
|
+
this.isScrollingTimeoutId = setTimeout(() => {
|
|
228
|
+
this.isScrollingTimeoutId = null;
|
|
229
|
+
this.isScrolling = false;
|
|
230
|
+
this.scrollDirection = null;
|
|
231
|
+
this.maybeNotify();
|
|
232
|
+
}, this.options.scrollingDelay);
|
|
233
|
+
})
|
|
234
|
+
);
|
|
235
|
+
}
|
|
236
|
+
};
|
|
237
|
+
this.getSize = () => {
|
|
238
|
+
return this.scrollRect[this.options.horizontal ? "width" : "height"];
|
|
239
|
+
};
|
|
240
|
+
this.memoOptions = utils.memo(
|
|
241
|
+
() => [
|
|
242
|
+
this.options.count,
|
|
243
|
+
this.options.paddingStart,
|
|
244
|
+
this.options.scrollMargin,
|
|
245
|
+
this.options.getItemKey
|
|
246
|
+
],
|
|
247
|
+
(count, paddingStart, scrollMargin, getItemKey) => {
|
|
248
|
+
this.pendingMeasuredCacheIndexes = [];
|
|
249
|
+
return {
|
|
250
|
+
count,
|
|
251
|
+
paddingStart,
|
|
252
|
+
scrollMargin,
|
|
253
|
+
getItemKey
|
|
254
|
+
};
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
key: false
|
|
258
|
+
}
|
|
259
|
+
);
|
|
260
|
+
this.getFurthestMeasurement = (measurements, index) => {
|
|
261
|
+
const furthestMeasurementsFound = /* @__PURE__ */ new Map();
|
|
262
|
+
const furthestMeasurements = /* @__PURE__ */ new Map();
|
|
263
|
+
for (let m = index - 1; m >= 0; m--) {
|
|
264
|
+
const measurement = measurements[m];
|
|
265
|
+
if (furthestMeasurementsFound.has(measurement.lane)) {
|
|
266
|
+
continue;
|
|
267
|
+
}
|
|
268
|
+
const previousFurthestMeasurement = furthestMeasurements.get(
|
|
269
|
+
measurement.lane
|
|
270
|
+
);
|
|
271
|
+
if (previousFurthestMeasurement == null || measurement.end > previousFurthestMeasurement.end) {
|
|
272
|
+
furthestMeasurements.set(measurement.lane, measurement);
|
|
273
|
+
} else if (measurement.end < previousFurthestMeasurement.end) {
|
|
274
|
+
furthestMeasurementsFound.set(measurement.lane, true);
|
|
275
|
+
}
|
|
276
|
+
if (furthestMeasurementsFound.size === this.options.lanes) {
|
|
277
|
+
break;
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
return furthestMeasurements.size === this.options.lanes ? Array.from(furthestMeasurements.values()).sort((a, b) => {
|
|
281
|
+
if (a.end === b.end) {
|
|
282
|
+
return a.index - b.index;
|
|
283
|
+
}
|
|
284
|
+
return a.end - b.end;
|
|
285
|
+
})[0] : void 0;
|
|
286
|
+
};
|
|
287
|
+
this.getMeasurements = utils.memo(
|
|
288
|
+
() => [this.memoOptions(), this.itemSizeCache],
|
|
289
|
+
({ count, paddingStart, scrollMargin, getItemKey }, itemSizeCache) => {
|
|
290
|
+
const min = this.pendingMeasuredCacheIndexes.length > 0 ? Math.min(...this.pendingMeasuredCacheIndexes) : 0;
|
|
291
|
+
this.pendingMeasuredCacheIndexes = [];
|
|
292
|
+
const measurements = this.measurementsCache.slice(0, min);
|
|
293
|
+
for (let i = min; i < count; i++) {
|
|
294
|
+
const key = getItemKey(i);
|
|
295
|
+
const furthestMeasurement = this.options.lanes === 1 ? measurements[i - 1] : this.getFurthestMeasurement(measurements, i);
|
|
296
|
+
const start = furthestMeasurement ? furthestMeasurement.end + this.options.gap : paddingStart + scrollMargin;
|
|
297
|
+
const measuredSize = itemSizeCache.get(key);
|
|
298
|
+
const size = typeof measuredSize === "number" ? measuredSize : this.options.estimateSize(i);
|
|
299
|
+
const end = start + size;
|
|
300
|
+
const lane = furthestMeasurement ? furthestMeasurement.lane : i % this.options.lanes;
|
|
301
|
+
measurements[i] = {
|
|
302
|
+
index: i,
|
|
303
|
+
start,
|
|
304
|
+
size,
|
|
305
|
+
end,
|
|
306
|
+
key,
|
|
307
|
+
lane
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
this.measurementsCache = measurements;
|
|
311
|
+
return measurements;
|
|
312
|
+
},
|
|
313
|
+
{
|
|
314
|
+
key: process.env.NODE_ENV !== "production" && "getMeasurements",
|
|
315
|
+
debug: () => this.options.debug
|
|
316
|
+
}
|
|
317
|
+
);
|
|
318
|
+
this.calculateRange = utils.memo(
|
|
319
|
+
() => [this.getMeasurements(), this.getSize(), this.scrollOffset],
|
|
320
|
+
(measurements, outerSize, scrollOffset) => {
|
|
321
|
+
return this.range = measurements.length > 0 && outerSize > 0 ? calculateRange({
|
|
322
|
+
measurements,
|
|
323
|
+
outerSize,
|
|
324
|
+
scrollOffset
|
|
325
|
+
}) : null;
|
|
326
|
+
},
|
|
327
|
+
{
|
|
328
|
+
key: process.env.NODE_ENV !== "production" && "calculateRange",
|
|
329
|
+
debug: () => this.options.debug
|
|
330
|
+
}
|
|
331
|
+
);
|
|
332
|
+
this.getIndexes = utils.memo(
|
|
333
|
+
() => [
|
|
334
|
+
this.options.rangeExtractor,
|
|
335
|
+
this.calculateRange(),
|
|
336
|
+
this.options.overscan,
|
|
337
|
+
this.options.count
|
|
338
|
+
],
|
|
339
|
+
(rangeExtractor, range, overscan, count) => {
|
|
340
|
+
return range === null ? [] : rangeExtractor({
|
|
341
|
+
...range,
|
|
342
|
+
overscan,
|
|
343
|
+
count
|
|
344
|
+
});
|
|
345
|
+
},
|
|
346
|
+
{
|
|
347
|
+
key: process.env.NODE_ENV !== "production" && "getIndexes",
|
|
348
|
+
debug: () => this.options.debug
|
|
349
|
+
}
|
|
350
|
+
);
|
|
351
|
+
this.indexFromElement = (node) => {
|
|
352
|
+
const attributeName = this.options.indexAttribute;
|
|
353
|
+
const indexStr = node.getAttribute(attributeName);
|
|
354
|
+
if (!indexStr) {
|
|
355
|
+
console.warn(
|
|
356
|
+
`Missing attribute name '${attributeName}={index}' on measured element.`
|
|
357
|
+
);
|
|
358
|
+
return -1;
|
|
359
|
+
}
|
|
360
|
+
return parseInt(indexStr, 10);
|
|
361
|
+
};
|
|
362
|
+
this._measureElement = (node, entry) => {
|
|
363
|
+
const item = this.measurementsCache[this.indexFromElement(node)];
|
|
364
|
+
if (!item || !node.isConnected) {
|
|
365
|
+
this.measureElementCache.forEach((cached, key) => {
|
|
366
|
+
if (cached === node) {
|
|
367
|
+
this.observer.unobserve(node);
|
|
368
|
+
this.measureElementCache.delete(key);
|
|
369
|
+
}
|
|
370
|
+
});
|
|
371
|
+
return;
|
|
372
|
+
}
|
|
373
|
+
const prevNode = this.measureElementCache.get(item.key);
|
|
374
|
+
if (prevNode !== node) {
|
|
375
|
+
if (prevNode) {
|
|
376
|
+
this.observer.unobserve(prevNode);
|
|
377
|
+
}
|
|
378
|
+
this.observer.observe(node);
|
|
379
|
+
this.measureElementCache.set(item.key, node);
|
|
380
|
+
}
|
|
381
|
+
const measuredItemSize = this.options.measureElement(node, entry, this);
|
|
382
|
+
this.resizeItem(item, measuredItemSize);
|
|
383
|
+
};
|
|
384
|
+
this.resizeItem = (item, size) => {
|
|
385
|
+
const itemSize = this.itemSizeCache.get(item.key) ?? item.size;
|
|
386
|
+
const delta = size - itemSize;
|
|
387
|
+
if (delta !== 0) {
|
|
388
|
+
if (item.start < this.scrollOffset + this.scrollAdjustments) {
|
|
389
|
+
if (process.env.NODE_ENV !== "production" && this.options.debug) {
|
|
390
|
+
console.info("correction", delta);
|
|
391
|
+
}
|
|
392
|
+
this._scrollToOffset(this.scrollOffset, {
|
|
393
|
+
adjustments: this.scrollAdjustments += delta,
|
|
394
|
+
behavior: void 0
|
|
395
|
+
});
|
|
396
|
+
}
|
|
397
|
+
this.pendingMeasuredCacheIndexes.push(item.index);
|
|
398
|
+
this.itemSizeCache = new Map(this.itemSizeCache.set(item.key, size));
|
|
399
|
+
this.notify(false);
|
|
400
|
+
}
|
|
401
|
+
};
|
|
402
|
+
this.measureElement = (node) => {
|
|
403
|
+
if (!node) {
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
this._measureElement(node, void 0);
|
|
407
|
+
};
|
|
408
|
+
this.getVirtualItems = utils.memo(
|
|
409
|
+
() => [this.getIndexes(), this.getMeasurements()],
|
|
410
|
+
(indexes, measurements) => {
|
|
411
|
+
const virtualItems = [];
|
|
412
|
+
for (let k = 0, len = indexes.length; k < len; k++) {
|
|
413
|
+
const i = indexes[k];
|
|
414
|
+
const measurement = measurements[i];
|
|
415
|
+
virtualItems.push(measurement);
|
|
416
|
+
}
|
|
417
|
+
return virtualItems;
|
|
418
|
+
},
|
|
419
|
+
{
|
|
420
|
+
key: process.env.NODE_ENV !== "production" && "getIndexes",
|
|
421
|
+
debug: () => this.options.debug
|
|
422
|
+
}
|
|
423
|
+
);
|
|
424
|
+
this.getVirtualItemForOffset = (offset) => {
|
|
425
|
+
const measurements = this.getMeasurements();
|
|
426
|
+
return utils.notUndefined(
|
|
427
|
+
measurements[findNearestBinarySearch(
|
|
428
|
+
0,
|
|
429
|
+
measurements.length - 1,
|
|
430
|
+
(index) => utils.notUndefined(measurements[index]).start,
|
|
431
|
+
offset
|
|
432
|
+
)]
|
|
433
|
+
);
|
|
434
|
+
};
|
|
435
|
+
this.getOffsetForAlignment = (toOffset, align) => {
|
|
436
|
+
const size = this.getSize();
|
|
437
|
+
if (align === "auto") {
|
|
438
|
+
if (toOffset <= this.scrollOffset) {
|
|
439
|
+
align = "start";
|
|
440
|
+
} else if (toOffset >= this.scrollOffset + size) {
|
|
441
|
+
align = "end";
|
|
442
|
+
} else {
|
|
443
|
+
align = "start";
|
|
444
|
+
}
|
|
445
|
+
}
|
|
446
|
+
if (align === "start") {
|
|
447
|
+
toOffset = toOffset;
|
|
448
|
+
} else if (align === "end") {
|
|
449
|
+
toOffset = toOffset - size;
|
|
450
|
+
} else if (align === "center") {
|
|
451
|
+
toOffset = toOffset - size / 2;
|
|
452
|
+
}
|
|
453
|
+
const scrollSizeProp = this.options.horizontal ? "scrollWidth" : "scrollHeight";
|
|
454
|
+
const scrollSize = this.scrollElement ? "document" in this.scrollElement ? this.scrollElement.document.documentElement[scrollSizeProp] : this.scrollElement[scrollSizeProp] : 0;
|
|
455
|
+
const maxOffset = scrollSize - this.getSize();
|
|
456
|
+
return Math.max(Math.min(maxOffset, toOffset), 0);
|
|
457
|
+
};
|
|
458
|
+
this.getOffsetForIndex = (index, align = "auto") => {
|
|
459
|
+
index = Math.max(0, Math.min(index, this.options.count - 1));
|
|
460
|
+
const measurement = utils.notUndefined(this.getMeasurements()[index]);
|
|
461
|
+
if (align === "auto") {
|
|
462
|
+
if (measurement.end >= this.scrollOffset + this.getSize() - this.options.scrollPaddingEnd) {
|
|
463
|
+
align = "end";
|
|
464
|
+
} else if (measurement.start <= this.scrollOffset + this.options.scrollPaddingStart) {
|
|
465
|
+
align = "start";
|
|
466
|
+
} else {
|
|
467
|
+
return [this.scrollOffset, align];
|
|
468
|
+
}
|
|
469
|
+
}
|
|
470
|
+
const toOffset = align === "end" ? measurement.end + this.options.scrollPaddingEnd : measurement.start - this.options.scrollPaddingStart;
|
|
471
|
+
return [this.getOffsetForAlignment(toOffset, align), align];
|
|
472
|
+
};
|
|
473
|
+
this.isDynamicMode = () => this.measureElementCache.size > 0;
|
|
474
|
+
this.cancelScrollToIndex = () => {
|
|
475
|
+
if (this.scrollToIndexTimeoutId !== null) {
|
|
476
|
+
clearTimeout(this.scrollToIndexTimeoutId);
|
|
477
|
+
this.scrollToIndexTimeoutId = null;
|
|
478
|
+
}
|
|
479
|
+
};
|
|
480
|
+
this.scrollToOffset = (toOffset, { align = "start", behavior } = {}) => {
|
|
481
|
+
this.cancelScrollToIndex();
|
|
482
|
+
if (behavior === "smooth" && this.isDynamicMode()) {
|
|
483
|
+
console.warn(
|
|
484
|
+
"The `smooth` scroll behavior is not fully supported with dynamic size."
|
|
485
|
+
);
|
|
486
|
+
}
|
|
487
|
+
this._scrollToOffset(this.getOffsetForAlignment(toOffset, align), {
|
|
488
|
+
adjustments: void 0,
|
|
489
|
+
behavior
|
|
490
|
+
});
|
|
491
|
+
};
|
|
492
|
+
this.scrollToIndex = (index, { align: initialAlign = "auto", behavior } = {}) => {
|
|
493
|
+
index = Math.max(0, Math.min(index, this.options.count - 1));
|
|
494
|
+
this.cancelScrollToIndex();
|
|
495
|
+
if (behavior === "smooth" && this.isDynamicMode()) {
|
|
496
|
+
console.warn(
|
|
497
|
+
"The `smooth` scroll behavior is not fully supported with dynamic size."
|
|
498
|
+
);
|
|
499
|
+
}
|
|
500
|
+
const [toOffset, align] = this.getOffsetForIndex(index, initialAlign);
|
|
501
|
+
this._scrollToOffset(toOffset, { adjustments: void 0, behavior });
|
|
502
|
+
if (behavior !== "smooth" && this.isDynamicMode()) {
|
|
503
|
+
this.scrollToIndexTimeoutId = setTimeout(() => {
|
|
504
|
+
this.scrollToIndexTimeoutId = null;
|
|
505
|
+
const elementInDOM = this.measureElementCache.has(
|
|
506
|
+
this.options.getItemKey(index)
|
|
507
|
+
);
|
|
508
|
+
if (elementInDOM) {
|
|
509
|
+
const [toOffset2] = this.getOffsetForIndex(index, align);
|
|
510
|
+
if (!utils.approxEqual(toOffset2, this.scrollOffset)) {
|
|
511
|
+
this.scrollToIndex(index, { align, behavior });
|
|
512
|
+
}
|
|
513
|
+
} else {
|
|
514
|
+
this.scrollToIndex(index, { align, behavior });
|
|
515
|
+
}
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
this.scrollBy = (delta, { behavior } = {}) => {
|
|
520
|
+
this.cancelScrollToIndex();
|
|
521
|
+
if (behavior === "smooth" && this.isDynamicMode()) {
|
|
522
|
+
console.warn(
|
|
523
|
+
"The `smooth` scroll behavior is not fully supported with dynamic size."
|
|
524
|
+
);
|
|
525
|
+
}
|
|
526
|
+
this._scrollToOffset(this.scrollOffset + delta, {
|
|
527
|
+
adjustments: void 0,
|
|
528
|
+
behavior
|
|
529
|
+
});
|
|
530
|
+
};
|
|
531
|
+
this.getTotalSize = () => {
|
|
532
|
+
var _a;
|
|
533
|
+
const measurements = this.getMeasurements();
|
|
534
|
+
let end;
|
|
535
|
+
if (measurements.length === 0) {
|
|
536
|
+
end = this.options.paddingStart;
|
|
537
|
+
} else {
|
|
538
|
+
end = this.options.lanes === 1 ? ((_a = measurements[measurements.length - 1]) == null ? void 0 : _a.end) ?? 0 : Math.max(
|
|
539
|
+
...measurements.slice(-this.options.lanes).map((m) => m.end)
|
|
540
|
+
);
|
|
541
|
+
}
|
|
542
|
+
return end - this.options.scrollMargin + this.options.paddingEnd;
|
|
543
|
+
};
|
|
544
|
+
this._scrollToOffset = (offset, {
|
|
545
|
+
adjustments,
|
|
546
|
+
behavior
|
|
547
|
+
}) => {
|
|
548
|
+
this.options.scrollToFn(offset, { behavior, adjustments }, this);
|
|
549
|
+
};
|
|
550
|
+
this.measure = () => {
|
|
551
|
+
this.itemSizeCache = /* @__PURE__ */ new Map();
|
|
552
|
+
this.notify(false);
|
|
553
|
+
};
|
|
554
|
+
this.setOptions(opts);
|
|
555
|
+
this.scrollRect = this.options.initialRect;
|
|
556
|
+
this.scrollOffset = this.options.initialOffset;
|
|
557
|
+
this.measurementsCache = this.options.initialMeasurementsCache;
|
|
558
|
+
this.measurementsCache.forEach((item) => {
|
|
559
|
+
this.itemSizeCache.set(item.key, item.size);
|
|
560
|
+
});
|
|
561
|
+
this.maybeNotify();
|
|
562
|
+
}
|
|
563
|
+
}
|
|
564
|
+
const findNearestBinarySearch = (low, high, getCurrentValue, value) => {
|
|
565
|
+
while (low <= high) {
|
|
566
|
+
const middle = (low + high) / 2 | 0;
|
|
567
|
+
const currentValue = getCurrentValue(middle);
|
|
568
|
+
if (currentValue < value) {
|
|
569
|
+
low = middle + 1;
|
|
570
|
+
} else if (currentValue > value) {
|
|
571
|
+
high = middle - 1;
|
|
572
|
+
} else {
|
|
573
|
+
return middle;
|
|
574
|
+
}
|
|
575
|
+
}
|
|
576
|
+
if (low > 0) {
|
|
577
|
+
return low - 1;
|
|
578
|
+
} else {
|
|
579
|
+
return 0;
|
|
580
|
+
}
|
|
581
|
+
};
|
|
582
|
+
function calculateRange({
|
|
583
|
+
measurements,
|
|
584
|
+
outerSize,
|
|
585
|
+
scrollOffset
|
|
586
|
+
}) {
|
|
587
|
+
const count = measurements.length - 1;
|
|
588
|
+
const getOffset = (index) => measurements[index].start;
|
|
589
|
+
const startIndex = findNearestBinarySearch(0, count, getOffset, scrollOffset);
|
|
590
|
+
let endIndex = startIndex;
|
|
591
|
+
while (endIndex < count && measurements[endIndex].end < scrollOffset + outerSize) {
|
|
592
|
+
endIndex++;
|
|
593
|
+
}
|
|
594
|
+
return { startIndex, endIndex };
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
exports.approxEqual = utils.approxEqual;
|
|
598
|
+
exports.memo = utils.memo;
|
|
599
|
+
exports.notUndefined = utils.notUndefined;
|
|
600
|
+
exports.Virtualizer = Virtualizer;
|
|
601
|
+
exports.defaultKeyExtractor = defaultKeyExtractor;
|
|
602
|
+
exports.defaultRangeExtractor = defaultRangeExtractor;
|
|
603
|
+
exports.elementScroll = elementScroll;
|
|
604
|
+
exports.measureElement = measureElement;
|
|
605
|
+
exports.observeElementOffset = observeElementOffset;
|
|
606
|
+
exports.observeElementRect = observeElementRect;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
function memo(getDeps, fn, opts) {
|
|
5
|
+
let deps = opts.initialDeps ?? [];
|
|
6
|
+
let result;
|
|
7
|
+
return () => {
|
|
8
|
+
var _a, _b, _c, _d;
|
|
9
|
+
let depTime;
|
|
10
|
+
if (opts.key && ((_a = opts.debug) == null ? void 0 : _a.call(opts)))
|
|
11
|
+
depTime = Date.now();
|
|
12
|
+
const newDeps = getDeps();
|
|
13
|
+
const depsChanged = newDeps.length !== deps.length || newDeps.some((dep, index) => deps[index] !== dep);
|
|
14
|
+
if (!depsChanged) {
|
|
15
|
+
return result;
|
|
16
|
+
}
|
|
17
|
+
deps = newDeps;
|
|
18
|
+
let resultTime;
|
|
19
|
+
if (opts.key && ((_b = opts.debug) == null ? void 0 : _b.call(opts)))
|
|
20
|
+
resultTime = Date.now();
|
|
21
|
+
result = fn(...newDeps);
|
|
22
|
+
if (opts.key && ((_c = opts.debug) == null ? void 0 : _c.call(opts))) {
|
|
23
|
+
const depEndTime = Math.round((Date.now() - depTime) * 100) / 100;
|
|
24
|
+
const resultEndTime = Math.round((Date.now() - resultTime) * 100) / 100;
|
|
25
|
+
const resultFpsPercentage = resultEndTime / 16;
|
|
26
|
+
const pad = (str, num) => {
|
|
27
|
+
str = String(str);
|
|
28
|
+
while (str.length < num) {
|
|
29
|
+
str = " " + str;
|
|
30
|
+
}
|
|
31
|
+
return str;
|
|
32
|
+
};
|
|
33
|
+
console.info(
|
|
34
|
+
`%c⏱ ${pad(resultEndTime, 5)} /${pad(depEndTime, 5)} ms`,
|
|
35
|
+
`
|
|
36
|
+
font-size: .6rem;
|
|
37
|
+
font-weight: bold;
|
|
38
|
+
color: hsl(${Math.max(
|
|
39
|
+
0,
|
|
40
|
+
Math.min(120 - 120 * resultFpsPercentage, 120)
|
|
41
|
+
)}deg 100% 31%);`,
|
|
42
|
+
opts == null ? void 0 : opts.key
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
(_d = opts == null ? void 0 : opts.onChange) == null ? void 0 : _d.call(opts, result);
|
|
46
|
+
return result;
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
function notUndefined(value, msg) {
|
|
50
|
+
if (value === void 0) {
|
|
51
|
+
throw new Error(`Unexpected undefined${msg ? `: ${msg}` : ""}`);
|
|
52
|
+
} else {
|
|
53
|
+
return value;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
const approxEqual = (a, b) => Math.abs(a - b) < 1;
|
|
57
|
+
|
|
58
|
+
exports.approxEqual = approxEqual;
|
|
59
|
+
exports.memo = memo;
|
|
60
|
+
exports.notUndefined = notUndefined;
|