lkd-web-kit 0.8.0 → 0.8.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 (136) hide show
  1. package/dist/_virtual/_rolldown/runtime.cjs +23 -0
  2. package/dist/components/EmptyState/index.cjs +38 -52
  3. package/dist/components/EmptyState/index.js +37 -48
  4. package/dist/components/Icon.cjs +46 -50
  5. package/dist/components/Icon.js +44 -46
  6. package/dist/components/InfinityLoadMoreButton/index.cjs +30 -42
  7. package/dist/components/InfinityLoadMoreButton/index.js +28 -38
  8. package/dist/components/InfinitySelect/index.cjs +126 -168
  9. package/dist/components/InfinitySelect/index.js +125 -164
  10. package/dist/components/MyCheckboxGroup/index.cjs +14 -22
  11. package/dist/components/MyCheckboxGroup/index.js +13 -18
  12. package/dist/components/MyDateInput/index.cjs +12 -18
  13. package/dist/components/MyDateInput/index.js +11 -14
  14. package/dist/components/MyDatePickerInput/CalendarIcon.cjs +45 -64
  15. package/dist/components/MyDatePickerInput/CalendarIcon.js +43 -61
  16. package/dist/components/MyDatePickerInput/index.cjs +12 -18
  17. package/dist/components/MyDatePickerInput/index.js +11 -14
  18. package/dist/components/MyDateTimePicker/index.cjs +12 -18
  19. package/dist/components/MyDateTimePicker/index.js +11 -14
  20. package/dist/components/MyMonthPickerInput/index.cjs +12 -18
  21. package/dist/components/MyMonthPickerInput/index.js +11 -14
  22. package/dist/components/MyMultiSelect/index.cjs +9 -9
  23. package/dist/components/MyMultiSelect/index.js +8 -5
  24. package/dist/components/MyNotifications/index.cjs +11 -17
  25. package/dist/components/MyNotifications/index.js +10 -13
  26. package/dist/components/MyNumberInput/index.cjs +9 -15
  27. package/dist/components/MyNumberInput/index.js +8 -11
  28. package/dist/components/MyRadioGroup/index.cjs +14 -22
  29. package/dist/components/MyRadioGroup/index.js +13 -18
  30. package/dist/components/MySelect/index.cjs +9 -15
  31. package/dist/components/MySelect/index.js +8 -11
  32. package/dist/components/MyTextInput/index.cjs +9 -15
  33. package/dist/components/MyTextInput/index.js +8 -11
  34. package/dist/components/MyTextarea/index.cjs +9 -15
  35. package/dist/components/MyTextarea/index.js +8 -11
  36. package/dist/components/MyTimeInput/index.cjs +9 -15
  37. package/dist/components/MyTimeInput/index.js +8 -11
  38. package/dist/components/NavItems.cjs +28 -38
  39. package/dist/components/NavItems.js +26 -34
  40. package/dist/consts/http-status.cjs +66 -69
  41. package/dist/consts/http-status.js +66 -65
  42. package/dist/consts/revalidate.cjs +10 -13
  43. package/dist/consts/revalidate.js +10 -9
  44. package/dist/contexts/NavigationHistoryContext/hook.cjs +41 -42
  45. package/dist/contexts/NavigationHistoryContext/hook.js +40 -38
  46. package/dist/contexts/NavigationHistoryContext/index.cjs +31 -28
  47. package/dist/contexts/NavigationHistoryContext/index.js +30 -24
  48. package/dist/contexts/PageDataContext/index.cjs +15 -18
  49. package/dist/contexts/PageDataContext/index.js +14 -14
  50. package/dist/form/Form.cjs +19 -28
  51. package/dist/form/Form.js +18 -24
  52. package/dist/form/FormSubmitButton.cjs +15 -27
  53. package/dist/form/FormSubmitButton.js +14 -23
  54. package/dist/form/base/FormCheckbox.cjs +15 -23
  55. package/dist/form/base/FormCheckbox.js +14 -19
  56. package/dist/form/base/FormCheckboxGroup.cjs +10 -16
  57. package/dist/form/base/FormCheckboxGroup.js +9 -12
  58. package/dist/form/base/FormDateInput.cjs +10 -16
  59. package/dist/form/base/FormDateInput.js +9 -12
  60. package/dist/form/base/FormDatePickerInput.cjs +10 -16
  61. package/dist/form/base/FormDatePickerInput.js +9 -12
  62. package/dist/form/base/FormDateTimePicker.cjs +10 -16
  63. package/dist/form/base/FormDateTimePicker.js +9 -12
  64. package/dist/form/base/FormMonthPickerInput.cjs +10 -16
  65. package/dist/form/base/FormMonthPickerInput.js +9 -12
  66. package/dist/form/base/FormMultiSelect.cjs +10 -10
  67. package/dist/form/base/FormMultiSelect.js +9 -6
  68. package/dist/form/base/FormNumberInput.cjs +12 -12
  69. package/dist/form/base/FormNumberInput.js +10 -8
  70. package/dist/form/base/FormRadioGroup.cjs +10 -16
  71. package/dist/form/base/FormRadioGroup.js +9 -12
  72. package/dist/form/base/FormSelect.cjs +10 -16
  73. package/dist/form/base/FormSelect.js +9 -12
  74. package/dist/form/base/FormSelectInfinity.cjs +15 -21
  75. package/dist/form/base/FormSelectInfinity.js +14 -17
  76. package/dist/form/base/FormTextInput.cjs +10 -16
  77. package/dist/form/base/FormTextInput.js +9 -12
  78. package/dist/form/base/FormTextarea.cjs +10 -10
  79. package/dist/form/base/FormTextarea.js +9 -6
  80. package/dist/form/base/FormTimeInput.cjs +18 -24
  81. package/dist/form/base/FormTimeInput.js +17 -20
  82. package/dist/form/utils/nullable-but-required.cjs +14 -17
  83. package/dist/form/utils/nullable-but-required.js +13 -13
  84. package/dist/form/utils/optional-but-required.cjs +14 -17
  85. package/dist/form/utils/optional-but-required.js +13 -13
  86. package/dist/form/utils/zodValidator.cjs +9 -13
  87. package/dist/form/utils/zodValidator.js +9 -9
  88. package/dist/hocs/withController.cjs +43 -54
  89. package/dist/hocs/withController.js +42 -50
  90. package/dist/hocs/withModalManager.cjs +29 -35
  91. package/dist/hocs/withModalManager.js +28 -31
  92. package/dist/hooks/useBreakpoint.cjs +8 -12
  93. package/dist/hooks/useBreakpoint.js +7 -8
  94. package/dist/hooks/useFetchNextPageOnScroll.cjs +13 -21
  95. package/dist/hooks/useFetchNextPageOnScroll.js +13 -17
  96. package/dist/hooks/useOnScrollProgress.cjs +33 -37
  97. package/dist/hooks/useOnScrollProgress.js +32 -33
  98. package/dist/hooks/useUpdateSearchParams.cjs +22 -22
  99. package/dist/hooks/useUpdateSearchParams.js +21 -18
  100. package/dist/hooks/useZodConfig.cjs +14 -19
  101. package/dist/hooks/useZodConfig.js +12 -15
  102. package/dist/index.cjs +130 -136
  103. package/dist/index.d.ts +13 -13
  104. package/dist/index.js +62 -61
  105. package/dist/mantine/breakpoints-with-px.cjs +9 -12
  106. package/dist/mantine/breakpoints-with-px.js +9 -8
  107. package/dist/mantine/my-default-theme.cjs +23 -42
  108. package/dist/mantine/my-default-theme.js +22 -38
  109. package/dist/mantine/to-tailwind-colors.cjs +9 -18
  110. package/dist/mantine/to-tailwind-colors.js +9 -14
  111. package/dist/utils/array/groupBy.cjs +30 -40
  112. package/dist/utils/array/groupBy.js +30 -36
  113. package/dist/utils/array/shuffleArray.cjs +11 -17
  114. package/dist/utils/array/shuffleArray.js +11 -13
  115. package/dist/utils/formatBytes.cjs +12 -11
  116. package/dist/utils/formatBytes.js +12 -7
  117. package/dist/utils/isInfinityEmpty.cjs +3 -6
  118. package/dist/utils/isInfinityEmpty.js +3 -2
  119. package/dist/utils/ky/addBodyJsonHook.cjs +9 -14
  120. package/dist/utils/ky/addBodyJsonHook.js +8 -10
  121. package/dist/utils/ky/parseJson.cjs +6 -9
  122. package/dist/utils/ky/parseJson.js +6 -5
  123. package/dist/utils/new-route.cjs +30 -39
  124. package/dist/utils/new-route.js +30 -35
  125. package/dist/utils/query-stringify.cjs +5 -8
  126. package/dist/utils/query-stringify.js +5 -4
  127. package/dist/utils/virtual-styles.cjs +21 -26
  128. package/dist/utils/virtual-styles.js +21 -22
  129. package/package.json +20 -19
  130. package/dist/node_modules/@mantine/notifications/styles.css +0 -42
  131. package/dist/node_modules/@tanstack/react-virtual/dist/esm/index.cjs +0 -74
  132. package/dist/node_modules/@tanstack/react-virtual/dist/esm/index.js +0 -45
  133. package/dist/node_modules/@tanstack/virtual-core/dist/esm/index.cjs +0 -886
  134. package/dist/node_modules/@tanstack/virtual-core/dist/esm/index.js +0 -872
  135. package/dist/node_modules/@tanstack/virtual-core/dist/esm/utils.cjs +0 -75
  136. package/dist/node_modules/@tanstack/virtual-core/dist/esm/utils.js +0 -68
@@ -1,886 +0,0 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
4
-
5
- const utils = require('./utils.cjs');
6
-
7
- const getRect = (element) => {
8
- const { offsetWidth, offsetHeight } = element;
9
- return { width: offsetWidth, height: offsetHeight };
10
- };
11
- const defaultKeyExtractor = (index) => index;
12
- const defaultRangeExtractor = (range) => {
13
- const start = Math.max(range.startIndex - range.overscan, 0);
14
- const end = Math.min(range.endIndex + range.overscan, range.count - 1);
15
- const arr = [];
16
- for (let i = start; i <= end; i++) {
17
- arr.push(i);
18
- }
19
- return arr;
20
- };
21
- const observeElementRect = (instance, cb) => {
22
- const element = instance.scrollElement;
23
- if (!element) {
24
- return;
25
- }
26
- const targetWindow = instance.targetWindow;
27
- if (!targetWindow) {
28
- return;
29
- }
30
- const handler = (rect) => {
31
- const { width, height } = rect;
32
- cb({ width: Math.round(width), height: Math.round(height) });
33
- };
34
- handler(getRect(element));
35
- if (!targetWindow.ResizeObserver) {
36
- return () => {
37
- };
38
- }
39
- const observer = new targetWindow.ResizeObserver((entries) => {
40
- const run = () => {
41
- const entry = entries[0];
42
- if (entry == null ? void 0 : entry.borderBoxSize) {
43
- const box = entry.borderBoxSize[0];
44
- if (box) {
45
- handler({ width: box.inlineSize, height: box.blockSize });
46
- return;
47
- }
48
- }
49
- handler(getRect(element));
50
- };
51
- instance.options.useAnimationFrameWithResizeObserver ? requestAnimationFrame(run) : run();
52
- });
53
- observer.observe(element, { box: "border-box" });
54
- return () => {
55
- observer.unobserve(element);
56
- };
57
- };
58
- const addEventListenerOptions = {
59
- passive: true
60
- };
61
- const supportsScrollend = typeof window == "undefined" ? true : "onscrollend" in window;
62
- const observeElementOffset = (instance, cb) => {
63
- const element = instance.scrollElement;
64
- if (!element) {
65
- return;
66
- }
67
- const targetWindow = instance.targetWindow;
68
- if (!targetWindow) {
69
- return;
70
- }
71
- let offset = 0;
72
- const fallback = instance.options.useScrollendEvent && supportsScrollend ? () => void 0 : utils.debounce(
73
- targetWindow,
74
- () => {
75
- cb(offset, false);
76
- },
77
- instance.options.isScrollingResetDelay
78
- );
79
- const createHandler = (isScrolling) => () => {
80
- const { horizontal, isRtl } = instance.options;
81
- offset = horizontal ? element["scrollLeft"] * (isRtl && -1 || 1) : element["scrollTop"];
82
- fallback();
83
- cb(offset, isScrolling);
84
- };
85
- const handler = createHandler(true);
86
- const endHandler = createHandler(false);
87
- element.addEventListener("scroll", handler, addEventListenerOptions);
88
- const registerScrollendEvent = instance.options.useScrollendEvent && supportsScrollend;
89
- if (registerScrollendEvent) {
90
- element.addEventListener("scrollend", endHandler, addEventListenerOptions);
91
- }
92
- return () => {
93
- element.removeEventListener("scroll", handler);
94
- if (registerScrollendEvent) {
95
- element.removeEventListener("scrollend", endHandler);
96
- }
97
- };
98
- };
99
- const measureElement = (element, entry, instance) => {
100
- if (entry == null ? void 0 : entry.borderBoxSize) {
101
- const box = entry.borderBoxSize[0];
102
- if (box) {
103
- const size = Math.round(
104
- box[instance.options.horizontal ? "inlineSize" : "blockSize"]
105
- );
106
- return size;
107
- }
108
- }
109
- return element[instance.options.horizontal ? "offsetWidth" : "offsetHeight"];
110
- };
111
- const elementScroll = (offset, {
112
- adjustments = 0,
113
- behavior
114
- }, instance) => {
115
- var _a, _b;
116
- const toOffset = offset + adjustments;
117
- (_b = (_a = instance.scrollElement) == null ? void 0 : _a.scrollTo) == null ? void 0 : _b.call(_a, {
118
- [instance.options.horizontal ? "left" : "top"]: toOffset,
119
- behavior
120
- });
121
- };
122
- class Virtualizer {
123
- constructor(opts) {
124
- this.unsubs = [];
125
- this.scrollElement = null;
126
- this.targetWindow = null;
127
- this.isScrolling = false;
128
- this.scrollState = null;
129
- this.measurementsCache = [];
130
- this.itemSizeCache = /* @__PURE__ */ new Map();
131
- this.laneAssignments = /* @__PURE__ */ new Map();
132
- this.pendingMeasuredCacheIndexes = [];
133
- this.prevLanes = void 0;
134
- this.lanesChangedFlag = false;
135
- this.lanesSettling = false;
136
- this.scrollRect = null;
137
- this.scrollOffset = null;
138
- this.scrollDirection = null;
139
- this.scrollAdjustments = 0;
140
- this.elementsCache = /* @__PURE__ */ new Map();
141
- this.now = () => {
142
- var _a, _b, _c;
143
- return ((_c = (_b = (_a = this.targetWindow) == null ? void 0 : _a.performance) == null ? void 0 : _b.now) == null ? void 0 : _c.call(_b)) ?? Date.now();
144
- };
145
- this.observer = /* @__PURE__ */ (() => {
146
- let _ro = null;
147
- const get = () => {
148
- if (_ro) {
149
- return _ro;
150
- }
151
- if (!this.targetWindow || !this.targetWindow.ResizeObserver) {
152
- return null;
153
- }
154
- return _ro = new this.targetWindow.ResizeObserver((entries) => {
155
- entries.forEach((entry) => {
156
- const run = () => {
157
- const node = entry.target;
158
- const index = this.indexFromElement(node);
159
- if (!node.isConnected) {
160
- this.observer.unobserve(node);
161
- return;
162
- }
163
- if (this.shouldMeasureDuringScroll(index)) {
164
- this.resizeItem(
165
- index,
166
- this.options.measureElement(node, entry, this)
167
- );
168
- }
169
- };
170
- this.options.useAnimationFrameWithResizeObserver ? requestAnimationFrame(run) : run();
171
- });
172
- });
173
- };
174
- return {
175
- disconnect: () => {
176
- var _a;
177
- (_a = get()) == null ? void 0 : _a.disconnect();
178
- _ro = null;
179
- },
180
- observe: (target) => {
181
- var _a;
182
- return (_a = get()) == null ? void 0 : _a.observe(target, { box: "border-box" });
183
- },
184
- unobserve: (target) => {
185
- var _a;
186
- return (_a = get()) == null ? void 0 : _a.unobserve(target);
187
- }
188
- };
189
- })();
190
- this.range = null;
191
- this.setOptions = (opts2) => {
192
- Object.entries(opts2).forEach(([key, value]) => {
193
- if (typeof value === "undefined") delete opts2[key];
194
- });
195
- this.options = {
196
- debug: false,
197
- initialOffset: 0,
198
- overscan: 1,
199
- paddingStart: 0,
200
- paddingEnd: 0,
201
- scrollPaddingStart: 0,
202
- scrollPaddingEnd: 0,
203
- horizontal: false,
204
- getItemKey: defaultKeyExtractor,
205
- rangeExtractor: defaultRangeExtractor,
206
- onChange: () => {
207
- },
208
- measureElement,
209
- initialRect: { width: 0, height: 0 },
210
- scrollMargin: 0,
211
- gap: 0,
212
- indexAttribute: "data-index",
213
- initialMeasurementsCache: [],
214
- lanes: 1,
215
- isScrollingResetDelay: 150,
216
- enabled: true,
217
- isRtl: false,
218
- useScrollendEvent: false,
219
- useAnimationFrameWithResizeObserver: false,
220
- laneAssignmentMode: "estimate",
221
- ...opts2
222
- };
223
- };
224
- this.notify = (sync) => {
225
- var _a, _b;
226
- (_b = (_a = this.options).onChange) == null ? void 0 : _b.call(_a, this, sync);
227
- };
228
- this.maybeNotify = utils.memo(
229
- () => {
230
- this.calculateRange();
231
- return [
232
- this.isScrolling,
233
- this.range ? this.range.startIndex : null,
234
- this.range ? this.range.endIndex : null
235
- ];
236
- },
237
- (isScrolling) => {
238
- this.notify(isScrolling);
239
- },
240
- {
241
- key: process.env.NODE_ENV !== "production" && "maybeNotify",
242
- debug: () => this.options.debug,
243
- initialDeps: [
244
- this.isScrolling,
245
- this.range ? this.range.startIndex : null,
246
- this.range ? this.range.endIndex : null
247
- ]
248
- }
249
- );
250
- this.cleanup = () => {
251
- this.unsubs.filter(Boolean).forEach((d) => d());
252
- this.unsubs = [];
253
- this.observer.disconnect();
254
- if (this.rafId != null && this.targetWindow) {
255
- this.targetWindow.cancelAnimationFrame(this.rafId);
256
- this.rafId = null;
257
- }
258
- this.scrollState = null;
259
- this.scrollElement = null;
260
- this.targetWindow = null;
261
- };
262
- this._didMount = () => {
263
- return () => {
264
- this.cleanup();
265
- };
266
- };
267
- this._willUpdate = () => {
268
- var _a;
269
- const scrollElement = this.options.enabled ? this.options.getScrollElement() : null;
270
- if (this.scrollElement !== scrollElement) {
271
- this.cleanup();
272
- if (!scrollElement) {
273
- this.maybeNotify();
274
- return;
275
- }
276
- this.scrollElement = scrollElement;
277
- if (this.scrollElement && "ownerDocument" in this.scrollElement) {
278
- this.targetWindow = this.scrollElement.ownerDocument.defaultView;
279
- } else {
280
- this.targetWindow = ((_a = this.scrollElement) == null ? void 0 : _a.window) ?? null;
281
- }
282
- this.elementsCache.forEach((cached) => {
283
- this.observer.observe(cached);
284
- });
285
- this.unsubs.push(
286
- this.options.observeElementRect(this, (rect) => {
287
- this.scrollRect = rect;
288
- this.maybeNotify();
289
- })
290
- );
291
- this.unsubs.push(
292
- this.options.observeElementOffset(this, (offset, isScrolling) => {
293
- this.scrollAdjustments = 0;
294
- this.scrollDirection = isScrolling ? this.getScrollOffset() < offset ? "forward" : "backward" : null;
295
- this.scrollOffset = offset;
296
- this.isScrolling = isScrolling;
297
- if (this.scrollState) {
298
- this.scheduleScrollReconcile();
299
- }
300
- this.maybeNotify();
301
- })
302
- );
303
- this._scrollToOffset(this.getScrollOffset(), {
304
- adjustments: void 0,
305
- behavior: void 0
306
- });
307
- }
308
- };
309
- this.rafId = null;
310
- this.getSize = () => {
311
- if (!this.options.enabled) {
312
- this.scrollRect = null;
313
- return 0;
314
- }
315
- this.scrollRect = this.scrollRect ?? this.options.initialRect;
316
- return this.scrollRect[this.options.horizontal ? "width" : "height"];
317
- };
318
- this.getScrollOffset = () => {
319
- if (!this.options.enabled) {
320
- this.scrollOffset = null;
321
- return 0;
322
- }
323
- this.scrollOffset = this.scrollOffset ?? (typeof this.options.initialOffset === "function" ? this.options.initialOffset() : this.options.initialOffset);
324
- return this.scrollOffset;
325
- };
326
- this.getFurthestMeasurement = (measurements, index) => {
327
- const furthestMeasurementsFound = /* @__PURE__ */ new Map();
328
- const furthestMeasurements = /* @__PURE__ */ new Map();
329
- for (let m = index - 1; m >= 0; m--) {
330
- const measurement = measurements[m];
331
- if (furthestMeasurementsFound.has(measurement.lane)) {
332
- continue;
333
- }
334
- const previousFurthestMeasurement = furthestMeasurements.get(
335
- measurement.lane
336
- );
337
- if (previousFurthestMeasurement == null || measurement.end > previousFurthestMeasurement.end) {
338
- furthestMeasurements.set(measurement.lane, measurement);
339
- } else if (measurement.end < previousFurthestMeasurement.end) {
340
- furthestMeasurementsFound.set(measurement.lane, true);
341
- }
342
- if (furthestMeasurementsFound.size === this.options.lanes) {
343
- break;
344
- }
345
- }
346
- return furthestMeasurements.size === this.options.lanes ? Array.from(furthestMeasurements.values()).sort((a, b) => {
347
- if (a.end === b.end) {
348
- return a.index - b.index;
349
- }
350
- return a.end - b.end;
351
- })[0] : void 0;
352
- };
353
- this.getMeasurementOptions = utils.memo(
354
- () => [
355
- this.options.count,
356
- this.options.paddingStart,
357
- this.options.scrollMargin,
358
- this.options.getItemKey,
359
- this.options.enabled,
360
- this.options.lanes,
361
- this.options.laneAssignmentMode
362
- ],
363
- (count, paddingStart, scrollMargin, getItemKey, enabled, lanes, laneAssignmentMode) => {
364
- const lanesChanged = this.prevLanes !== void 0 && this.prevLanes !== lanes;
365
- if (lanesChanged) {
366
- this.lanesChangedFlag = true;
367
- }
368
- this.prevLanes = lanes;
369
- this.pendingMeasuredCacheIndexes = [];
370
- return {
371
- count,
372
- paddingStart,
373
- scrollMargin,
374
- getItemKey,
375
- enabled,
376
- lanes,
377
- laneAssignmentMode
378
- };
379
- },
380
- {
381
- key: false
382
- }
383
- );
384
- this.getMeasurements = utils.memo(
385
- () => [this.getMeasurementOptions(), this.itemSizeCache],
386
- ({
387
- count,
388
- paddingStart,
389
- scrollMargin,
390
- getItemKey,
391
- enabled,
392
- lanes,
393
- laneAssignmentMode
394
- }, itemSizeCache) => {
395
- if (!enabled) {
396
- this.measurementsCache = [];
397
- this.itemSizeCache.clear();
398
- this.laneAssignments.clear();
399
- return [];
400
- }
401
- if (this.laneAssignments.size > count) {
402
- for (const index of this.laneAssignments.keys()) {
403
- if (index >= count) {
404
- this.laneAssignments.delete(index);
405
- }
406
- }
407
- }
408
- if (this.lanesChangedFlag) {
409
- this.lanesChangedFlag = false;
410
- this.lanesSettling = true;
411
- this.measurementsCache = [];
412
- this.itemSizeCache.clear();
413
- this.laneAssignments.clear();
414
- this.pendingMeasuredCacheIndexes = [];
415
- }
416
- if (this.measurementsCache.length === 0 && !this.lanesSettling) {
417
- this.measurementsCache = this.options.initialMeasurementsCache;
418
- this.measurementsCache.forEach((item) => {
419
- this.itemSizeCache.set(item.key, item.size);
420
- });
421
- }
422
- const min = this.lanesSettling ? 0 : this.pendingMeasuredCacheIndexes.length > 0 ? Math.min(...this.pendingMeasuredCacheIndexes) : 0;
423
- this.pendingMeasuredCacheIndexes = [];
424
- if (this.lanesSettling && this.measurementsCache.length === count) {
425
- this.lanesSettling = false;
426
- }
427
- const measurements = this.measurementsCache.slice(0, min);
428
- const laneLastIndex = new Array(lanes).fill(
429
- void 0
430
- );
431
- for (let m = 0; m < min; m++) {
432
- const item = measurements[m];
433
- if (item) {
434
- laneLastIndex[item.lane] = m;
435
- }
436
- }
437
- for (let i = min; i < count; i++) {
438
- const key = getItemKey(i);
439
- const cachedLane = this.laneAssignments.get(i);
440
- let lane;
441
- let start;
442
- const shouldCacheLane = laneAssignmentMode === "estimate" || itemSizeCache.has(key);
443
- if (cachedLane !== void 0 && this.options.lanes > 1) {
444
- lane = cachedLane;
445
- const prevIndex = laneLastIndex[lane];
446
- const prevInLane = prevIndex !== void 0 ? measurements[prevIndex] : void 0;
447
- start = prevInLane ? prevInLane.end + this.options.gap : paddingStart + scrollMargin;
448
- } else {
449
- const furthestMeasurement = this.options.lanes === 1 ? measurements[i - 1] : this.getFurthestMeasurement(measurements, i);
450
- start = furthestMeasurement ? furthestMeasurement.end + this.options.gap : paddingStart + scrollMargin;
451
- lane = furthestMeasurement ? furthestMeasurement.lane : i % this.options.lanes;
452
- if (this.options.lanes > 1 && shouldCacheLane) {
453
- this.laneAssignments.set(i, lane);
454
- }
455
- }
456
- const measuredSize = itemSizeCache.get(key);
457
- const size = typeof measuredSize === "number" ? measuredSize : this.options.estimateSize(i);
458
- const end = start + size;
459
- measurements[i] = {
460
- index: i,
461
- start,
462
- size,
463
- end,
464
- key,
465
- lane
466
- };
467
- laneLastIndex[lane] = i;
468
- }
469
- this.measurementsCache = measurements;
470
- return measurements;
471
- },
472
- {
473
- key: process.env.NODE_ENV !== "production" && "getMeasurements",
474
- debug: () => this.options.debug
475
- }
476
- );
477
- this.calculateRange = utils.memo(
478
- () => [
479
- this.getMeasurements(),
480
- this.getSize(),
481
- this.getScrollOffset(),
482
- this.options.lanes
483
- ],
484
- (measurements, outerSize, scrollOffset, lanes) => {
485
- return this.range = measurements.length > 0 && outerSize > 0 ? calculateRange({
486
- measurements,
487
- outerSize,
488
- scrollOffset,
489
- lanes
490
- }) : null;
491
- },
492
- {
493
- key: process.env.NODE_ENV !== "production" && "calculateRange",
494
- debug: () => this.options.debug
495
- }
496
- );
497
- this.getVirtualIndexes = utils.memo(
498
- () => {
499
- let startIndex = null;
500
- let endIndex = null;
501
- const range = this.calculateRange();
502
- if (range) {
503
- startIndex = range.startIndex;
504
- endIndex = range.endIndex;
505
- }
506
- this.maybeNotify.updateDeps([this.isScrolling, startIndex, endIndex]);
507
- return [
508
- this.options.rangeExtractor,
509
- this.options.overscan,
510
- this.options.count,
511
- startIndex,
512
- endIndex
513
- ];
514
- },
515
- (rangeExtractor, overscan, count, startIndex, endIndex) => {
516
- return startIndex === null || endIndex === null ? [] : rangeExtractor({
517
- startIndex,
518
- endIndex,
519
- overscan,
520
- count
521
- });
522
- },
523
- {
524
- key: process.env.NODE_ENV !== "production" && "getVirtualIndexes",
525
- debug: () => this.options.debug
526
- }
527
- );
528
- this.indexFromElement = (node) => {
529
- const attributeName = this.options.indexAttribute;
530
- const indexStr = node.getAttribute(attributeName);
531
- if (!indexStr) {
532
- console.warn(
533
- `Missing attribute name '${attributeName}={index}' on measured element.`
534
- );
535
- return -1;
536
- }
537
- return parseInt(indexStr, 10);
538
- };
539
- this.shouldMeasureDuringScroll = (index) => {
540
- var _a;
541
- if (!this.scrollState || this.scrollState.behavior !== "smooth") {
542
- return true;
543
- }
544
- const scrollIndex = this.scrollState.index ?? ((_a = this.getVirtualItemForOffset(this.scrollState.lastTargetOffset)) == null ? void 0 : _a.index);
545
- if (scrollIndex !== void 0 && this.range) {
546
- const bufferSize = Math.max(
547
- this.options.overscan,
548
- Math.ceil((this.range.endIndex - this.range.startIndex) / 2)
549
- );
550
- const minIndex = Math.max(0, scrollIndex - bufferSize);
551
- const maxIndex = Math.min(
552
- this.options.count - 1,
553
- scrollIndex + bufferSize
554
- );
555
- return index >= minIndex && index <= maxIndex;
556
- }
557
- return true;
558
- };
559
- this.measureElement = (node) => {
560
- if (!node) {
561
- this.elementsCache.forEach((cached, key2) => {
562
- if (!cached.isConnected) {
563
- this.observer.unobserve(cached);
564
- this.elementsCache.delete(key2);
565
- }
566
- });
567
- return;
568
- }
569
- const index = this.indexFromElement(node);
570
- const key = this.options.getItemKey(index);
571
- const prevNode = this.elementsCache.get(key);
572
- if (prevNode !== node) {
573
- if (prevNode) {
574
- this.observer.unobserve(prevNode);
575
- }
576
- this.observer.observe(node);
577
- this.elementsCache.set(key, node);
578
- }
579
- if ((!this.isScrolling || this.scrollState) && this.shouldMeasureDuringScroll(index)) {
580
- this.resizeItem(index, this.options.measureElement(node, void 0, this));
581
- }
582
- };
583
- this.resizeItem = (index, size) => {
584
- var _a;
585
- const item = this.measurementsCache[index];
586
- if (!item) return;
587
- const itemSize = this.itemSizeCache.get(item.key) ?? item.size;
588
- const delta = size - itemSize;
589
- if (delta !== 0) {
590
- if (((_a = this.scrollState) == null ? void 0 : _a.behavior) !== "smooth" && (this.shouldAdjustScrollPositionOnItemSizeChange !== void 0 ? this.shouldAdjustScrollPositionOnItemSizeChange(item, delta, this) : item.start < this.getScrollOffset() + this.scrollAdjustments)) {
591
- if (process.env.NODE_ENV !== "production" && this.options.debug) {
592
- console.info("correction", delta);
593
- }
594
- this._scrollToOffset(this.getScrollOffset(), {
595
- adjustments: this.scrollAdjustments += delta,
596
- behavior: void 0
597
- });
598
- }
599
- this.pendingMeasuredCacheIndexes.push(item.index);
600
- this.itemSizeCache = new Map(this.itemSizeCache.set(item.key, size));
601
- this.notify(false);
602
- }
603
- };
604
- this.getVirtualItems = utils.memo(
605
- () => [this.getVirtualIndexes(), this.getMeasurements()],
606
- (indexes, measurements) => {
607
- const virtualItems = [];
608
- for (let k = 0, len = indexes.length; k < len; k++) {
609
- const i = indexes[k];
610
- const measurement = measurements[i];
611
- virtualItems.push(measurement);
612
- }
613
- return virtualItems;
614
- },
615
- {
616
- key: process.env.NODE_ENV !== "production" && "getVirtualItems",
617
- debug: () => this.options.debug
618
- }
619
- );
620
- this.getVirtualItemForOffset = (offset) => {
621
- const measurements = this.getMeasurements();
622
- if (measurements.length === 0) {
623
- return void 0;
624
- }
625
- return utils.notUndefined(
626
- measurements[findNearestBinarySearch(
627
- 0,
628
- measurements.length - 1,
629
- (index) => utils.notUndefined(measurements[index]).start,
630
- offset
631
- )]
632
- );
633
- };
634
- this.getMaxScrollOffset = () => {
635
- if (!this.scrollElement) return 0;
636
- if ("scrollHeight" in this.scrollElement) {
637
- return this.options.horizontal ? this.scrollElement.scrollWidth - this.scrollElement.clientWidth : this.scrollElement.scrollHeight - this.scrollElement.clientHeight;
638
- } else {
639
- const doc = this.scrollElement.document.documentElement;
640
- return this.options.horizontal ? doc.scrollWidth - this.scrollElement.innerWidth : doc.scrollHeight - this.scrollElement.innerHeight;
641
- }
642
- };
643
- this.getOffsetForAlignment = (toOffset, align, itemSize = 0) => {
644
- if (!this.scrollElement) return 0;
645
- const size = this.getSize();
646
- const scrollOffset = this.getScrollOffset();
647
- if (align === "auto") {
648
- align = toOffset >= scrollOffset + size ? "end" : "start";
649
- }
650
- if (align === "center") {
651
- toOffset += (itemSize - size) / 2;
652
- } else if (align === "end") {
653
- toOffset -= size;
654
- }
655
- const maxOffset = this.getMaxScrollOffset();
656
- return Math.max(Math.min(maxOffset, toOffset), 0);
657
- };
658
- this.getOffsetForIndex = (index, align = "auto") => {
659
- index = Math.max(0, Math.min(index, this.options.count - 1));
660
- const size = this.getSize();
661
- const scrollOffset = this.getScrollOffset();
662
- const item = this.measurementsCache[index];
663
- if (!item) return;
664
- if (align === "auto") {
665
- if (item.end >= scrollOffset + size - this.options.scrollPaddingEnd) {
666
- align = "end";
667
- } else if (item.start <= scrollOffset + this.options.scrollPaddingStart) {
668
- align = "start";
669
- } else {
670
- return [scrollOffset, align];
671
- }
672
- }
673
- if (align === "end" && index === this.options.count - 1) {
674
- return [this.getMaxScrollOffset(), align];
675
- }
676
- const toOffset = align === "end" ? item.end + this.options.scrollPaddingEnd : item.start - this.options.scrollPaddingStart;
677
- return [
678
- this.getOffsetForAlignment(toOffset, align, item.size),
679
- align
680
- ];
681
- };
682
- this.scrollToOffset = (toOffset, { align = "start", behavior = "auto" } = {}) => {
683
- const offset = this.getOffsetForAlignment(toOffset, align);
684
- const now = this.now();
685
- this.scrollState = {
686
- index: null,
687
- align,
688
- behavior,
689
- startedAt: now,
690
- lastTargetOffset: offset,
691
- stableFrames: 0
692
- };
693
- this._scrollToOffset(offset, { adjustments: void 0, behavior });
694
- this.scheduleScrollReconcile();
695
- };
696
- this.scrollToIndex = (index, {
697
- align: initialAlign = "auto",
698
- behavior = "auto"
699
- } = {}) => {
700
- index = Math.max(0, Math.min(index, this.options.count - 1));
701
- const offsetInfo = this.getOffsetForIndex(index, initialAlign);
702
- if (!offsetInfo) {
703
- return;
704
- }
705
- const [offset, align] = offsetInfo;
706
- const now = this.now();
707
- this.scrollState = {
708
- index,
709
- align,
710
- behavior,
711
- startedAt: now,
712
- lastTargetOffset: offset,
713
- stableFrames: 0
714
- };
715
- this._scrollToOffset(offset, { adjustments: void 0, behavior });
716
- this.scheduleScrollReconcile();
717
- };
718
- this.scrollBy = (delta, { behavior = "auto" } = {}) => {
719
- const offset = this.getScrollOffset() + delta;
720
- const now = this.now();
721
- this.scrollState = {
722
- index: null,
723
- align: "start",
724
- behavior,
725
- startedAt: now,
726
- lastTargetOffset: offset,
727
- stableFrames: 0
728
- };
729
- this._scrollToOffset(offset, { adjustments: void 0, behavior });
730
- this.scheduleScrollReconcile();
731
- };
732
- this.getTotalSize = () => {
733
- var _a;
734
- const measurements = this.getMeasurements();
735
- let end;
736
- if (measurements.length === 0) {
737
- end = this.options.paddingStart;
738
- } else if (this.options.lanes === 1) {
739
- end = ((_a = measurements[measurements.length - 1]) == null ? void 0 : _a.end) ?? 0;
740
- } else {
741
- const endByLane = Array(this.options.lanes).fill(null);
742
- let endIndex = measurements.length - 1;
743
- while (endIndex >= 0 && endByLane.some((val) => val === null)) {
744
- const item = measurements[endIndex];
745
- if (endByLane[item.lane] === null) {
746
- endByLane[item.lane] = item.end;
747
- }
748
- endIndex--;
749
- }
750
- end = Math.max(...endByLane.filter((val) => val !== null));
751
- }
752
- return Math.max(
753
- end - this.options.scrollMargin + this.options.paddingEnd,
754
- 0
755
- );
756
- };
757
- this._scrollToOffset = (offset, {
758
- adjustments,
759
- behavior
760
- }) => {
761
- this.options.scrollToFn(offset, { behavior, adjustments }, this);
762
- };
763
- this.measure = () => {
764
- this.itemSizeCache = /* @__PURE__ */ new Map();
765
- this.laneAssignments = /* @__PURE__ */ new Map();
766
- this.notify(false);
767
- };
768
- this.setOptions(opts);
769
- }
770
- scheduleScrollReconcile() {
771
- if (!this.targetWindow) {
772
- this.scrollState = null;
773
- return;
774
- }
775
- if (this.rafId != null) return;
776
- this.rafId = this.targetWindow.requestAnimationFrame(() => {
777
- this.rafId = null;
778
- this.reconcileScroll();
779
- });
780
- }
781
- reconcileScroll() {
782
- if (!this.scrollState) return;
783
- const el = this.scrollElement;
784
- if (!el) return;
785
- const MAX_RECONCILE_MS = 5e3;
786
- if (this.now() - this.scrollState.startedAt > MAX_RECONCILE_MS) {
787
- this.scrollState = null;
788
- return;
789
- }
790
- const offsetInfo = this.scrollState.index != null ? this.getOffsetForIndex(this.scrollState.index, this.scrollState.align) : void 0;
791
- const targetOffset = offsetInfo ? offsetInfo[0] : this.scrollState.lastTargetOffset;
792
- const STABLE_FRAMES = 1;
793
- const targetChanged = targetOffset !== this.scrollState.lastTargetOffset;
794
- if (!targetChanged && utils.approxEqual(targetOffset, this.getScrollOffset())) {
795
- this.scrollState.stableFrames++;
796
- if (this.scrollState.stableFrames >= STABLE_FRAMES) {
797
- this.scrollState = null;
798
- return;
799
- }
800
- } else {
801
- this.scrollState.stableFrames = 0;
802
- if (targetChanged) {
803
- this.scrollState.lastTargetOffset = targetOffset;
804
- this.scrollState.behavior = "auto";
805
- this._scrollToOffset(targetOffset, {
806
- adjustments: void 0,
807
- behavior: "auto"
808
- });
809
- }
810
- }
811
- this.scheduleScrollReconcile();
812
- }
813
- }
814
- const findNearestBinarySearch = (low, high, getCurrentValue, value) => {
815
- while (low <= high) {
816
- const middle = (low + high) / 2 | 0;
817
- const currentValue = getCurrentValue(middle);
818
- if (currentValue < value) {
819
- low = middle + 1;
820
- } else if (currentValue > value) {
821
- high = middle - 1;
822
- } else {
823
- return middle;
824
- }
825
- }
826
- if (low > 0) {
827
- return low - 1;
828
- } else {
829
- return 0;
830
- }
831
- };
832
- function calculateRange({
833
- measurements,
834
- outerSize,
835
- scrollOffset,
836
- lanes
837
- }) {
838
- const lastIndex = measurements.length - 1;
839
- const getOffset = (index) => measurements[index].start;
840
- if (measurements.length <= lanes) {
841
- return {
842
- startIndex: 0,
843
- endIndex: lastIndex
844
- };
845
- }
846
- let startIndex = findNearestBinarySearch(
847
- 0,
848
- lastIndex,
849
- getOffset,
850
- scrollOffset
851
- );
852
- let endIndex = startIndex;
853
- if (lanes === 1) {
854
- while (endIndex < lastIndex && measurements[endIndex].end < scrollOffset + outerSize) {
855
- endIndex++;
856
- }
857
- } else if (lanes > 1) {
858
- const endPerLane = Array(lanes).fill(0);
859
- while (endIndex < lastIndex && endPerLane.some((pos) => pos < scrollOffset + outerSize)) {
860
- const item = measurements[endIndex];
861
- endPerLane[item.lane] = item.end;
862
- endIndex++;
863
- }
864
- const startPerLane = Array(lanes).fill(scrollOffset + outerSize);
865
- while (startIndex >= 0 && startPerLane.some((pos) => pos >= scrollOffset)) {
866
- const item = measurements[startIndex];
867
- startPerLane[item.lane] = item.start;
868
- startIndex--;
869
- }
870
- startIndex = Math.max(0, startIndex - startIndex % lanes);
871
- endIndex = Math.min(lastIndex, endIndex + (lanes - 1 - endIndex % lanes));
872
- }
873
- return { startIndex, endIndex };
874
- }
875
-
876
- exports.approxEqual = utils.approxEqual;
877
- exports.debounce = utils.debounce;
878
- exports.memo = utils.memo;
879
- exports.notUndefined = utils.notUndefined;
880
- exports.Virtualizer = Virtualizer;
881
- exports.defaultKeyExtractor = defaultKeyExtractor;
882
- exports.defaultRangeExtractor = defaultRangeExtractor;
883
- exports.elementScroll = elementScroll;
884
- exports.measureElement = measureElement;
885
- exports.observeElementOffset = observeElementOffset;
886
- exports.observeElementRect = observeElementRect;