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