@fuf-stack/megapixels 0.13.5 → 0.14.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.
Files changed (50) hide show
  1. package/dist/DataTable/index.cjs +8 -0
  2. package/dist/DataTable/index.d.cts +2 -0
  3. package/dist/DataTable/index.d.ts +2 -0
  4. package/dist/DataTable/index.js +2 -0
  5. package/dist/DataTable-CF0oifeL.cjs +1166 -0
  6. package/dist/DataTable-CF0oifeL.cjs.map +1 -0
  7. package/dist/DataTable-Da6WZFKm.js +1145 -0
  8. package/dist/DataTable-Da6WZFKm.js.map +1 -0
  9. package/dist/Filter/index.cjs +1 -1
  10. package/dist/Filter/index.d.cts +1 -1
  11. package/dist/Filter/index.d.ts +1 -1
  12. package/dist/Filter/index.js +1 -1
  13. package/dist/{Filter-faDLPGFC.cjs → Filter-CbApjj6y.cjs} +41 -50
  14. package/dist/Filter-CbApjj6y.cjs.map +1 -0
  15. package/dist/{Filter-BKfVjFPo.js → Filter-DNj4lzj5.js} +35 -23
  16. package/dist/Filter-DNj4lzj5.js.map +1 -0
  17. package/dist/VirtualList/index.cjs +8 -0
  18. package/dist/VirtualList/index.d.cts +2 -0
  19. package/dist/VirtualList/index.d.ts +2 -0
  20. package/dist/VirtualList/index.js +2 -0
  21. package/dist/VirtualList-BALnlyjy.cjs +172 -0
  22. package/dist/VirtualList-BALnlyjy.cjs.map +1 -0
  23. package/dist/VirtualList-DQ4uR-wR.js +153 -0
  24. package/dist/VirtualList-DQ4uR-wR.js.map +1 -0
  25. package/dist/index-BGYzDspd.d.cts +5192 -0
  26. package/dist/index-BGYzDspd.d.cts.map +1 -0
  27. package/dist/index-Crb5hCFD.d.ts +5192 -0
  28. package/dist/index-Crb5hCFD.d.ts.map +1 -0
  29. package/dist/index-D7ZLM0zx.d.cts +1141 -0
  30. package/dist/index-D7ZLM0zx.d.cts.map +1 -0
  31. package/dist/{index-CgoXcO8f.d.cts → index-DCiYTnRL.d.ts} +22 -12
  32. package/dist/{index-E2k5kJ14.d.ts.map → index-DCiYTnRL.d.ts.map} +1 -1
  33. package/dist/{index-E2k5kJ14.d.ts → index-FDKfDW98.d.cts} +21 -11
  34. package/dist/{index-CgoXcO8f.d.cts.map → index-FDKfDW98.d.cts.map} +1 -1
  35. package/dist/index-jFySXsl9.d.ts +1141 -0
  36. package/dist/index-jFySXsl9.d.ts.map +1 -0
  37. package/dist/index.cjs +7 -1
  38. package/dist/index.cjs.map +1 -1
  39. package/dist/index.d.cts +4 -2
  40. package/dist/index.d.ts +4 -2
  41. package/dist/index.js +4 -2
  42. package/dist/index.js.map +1 -1
  43. package/dist/rolldown-runtime-D6vf50IK.cjs +28 -0
  44. package/dist/useInfiniteVirtualizer-BK0VroW4.cjs +175 -0
  45. package/dist/useInfiniteVirtualizer-BK0VroW4.cjs.map +1 -0
  46. package/dist/useInfiniteVirtualizer-BSCDrdRi.js +170 -0
  47. package/dist/useInfiniteVirtualizer-BSCDrdRi.js.map +1 -0
  48. package/package.json +15 -4
  49. package/dist/Filter-BKfVjFPo.js.map +0 -1
  50. package/dist/Filter-faDLPGFC.cjs.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index-jFySXsl9.d.ts","names":[],"sources":["../src/VirtualList/VirtualList.tsx"],"mappings":";;;;;cAYa,mBAAA,IAAmB,KAAA;EAAA;;;gbAmB9B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;gbAnB8B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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,IAAA,EAAM,KAAA;;EAEN,cAAA,GAAiB,8BAAA;;EAEjB,kBAAA,GAAqB,SAAA;;EAErB,YAAA,GAAe,SAAA;;EAEf,UAAA,GAAa,IAAA,EAAM,KAAA,EAAO,KAAA,aAAkB,SAAA;;EAE5C,MAAA;;EAEA,cAAA,EAAgB,8BAAA;AAAA;;;;;;;;;;cAYZ,WAAA;EAAuB,SAAA;EAAA,IAAA;EAAA,cAAA;EAAA,kBAAA;EAAA,UAAA;EAAA,YAAA;EAAA,MAAA;EAAA;AAAA,GAS1B,gBAAA,CAAiB,KAAA,sBAAM,GAAA,CAAA,OAAA"}
package/dist/index.cjs CHANGED
@@ -1,13 +1,19 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_Filter = require("./Filter-faDLPGFC.cjs");
2
+ const require_DataTable = require("./DataTable-CF0oifeL.cjs");
3
+ const require_Filter = require("./Filter-CbApjj6y.cjs");
3
4
  const require_Notification = require("./Notification-Bg3_1P1x.cjs");
5
+ const require_VirtualList = require("./VirtualList-BALnlyjy.cjs");
4
6
  //#region src/index.ts
5
7
  /* v8 ignore stop */
6
8
  //#endregion
9
+ exports.DataTable = require_DataTable.DataTable;
7
10
  exports.NotificationHost = require_Notification.NotificationHost;
11
+ exports.VirtualList = require_VirtualList.VirtualList;
8
12
  exports.createFilter = require_Filter.createFilter;
13
+ exports.dataTableVariants = require_DataTable.dataTableVariants;
9
14
  exports.filterVariants = require_Filter.filterVariants;
10
15
  exports.filters = require_Filter.filters;
11
16
  exports.notification = require_Notification.notification;
17
+ exports.virtualListVariants = require_VirtualList.virtualListVariants;
12
18
 
13
19
  //# sourceMappingURL=index.cjs.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.cjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["/* v8 ignore start */\n\n// components\nexport * from './Filter';\nexport * from './Notification';\n\n/* v8 ignore stop */\n"],"mappings":""}
1
+ {"version":3,"file":"index.cjs","names":[],"sources":["../src/index.ts"],"sourcesContent":["/* v8 ignore start */\n\n// components\nexport * from './DataTable';\nexport * from './Filter';\nexport * from './Notification';\nexport * from './VirtualList';\n\n/* v8 ignore stop */\n"],"mappings":""}
package/dist/index.d.cts CHANGED
@@ -1,3 +1,5 @@
1
- import { a as FilterProps, c as FilterDefinition, d as FilterFormProps, f as FilterInstance, i as FilterChildRenderFn, l as FilterDisplayProps, n as createFilter, o as FilterValues, p as FiltersConfiguration, s as filterVariants, t as filters, u as FilterFactory } from "./index-CgoXcO8f.cjs";
1
+ import { a as DataTableInfiniteScrollFeature, c as DataTableSearchField, d as dataTableVariants, i as DataTableIcons, l as DataTableVirtualizationFeature, n as DataTableExpandableRowsFeature, o as DataTablePaginationFeature, r as DataTableFeatures, s as DataTableProps, t as DataTable, u as InfiniteScrollPageInfo } from "./index-BGYzDspd.cjs";
2
+ import { a as FilterProps, c as FilterDefinition, d as FilterFormProps, f as FilterInstance, i as FilterChildRenderFn, l as FilterDisplayProps, n as createFilter, o as FilterValues, p as FiltersConfiguration, s as filterVariants, t as filters, u as FilterFactory } from "./index-FDKfDW98.cjs";
2
3
  import { a as notification, i as NotificationRenderProps, n as NotificationHostProps, r as NotificationOptions, t as NotificationHost } from "./index-oeUH2qWd.cjs";
3
- export { FilterChildRenderFn, type FilterDefinition, type FilterDisplayProps, type FilterFactory, type FilterFormProps, type FilterInstance, FilterProps, FilterValues, type FiltersConfiguration, NotificationHost, type NotificationHostProps, type NotificationOptions, type NotificationRenderProps, createFilter, filterVariants, filters, notification };
4
+ import { n as VirtualListProps, r as virtualListVariants, t as VirtualList } from "./index-D7ZLM0zx.cjs";
5
+ export { DataTable, type DataTableExpandableRowsFeature, type DataTableFeatures, type DataTableIcons, type DataTableInfiniteScrollFeature, type DataTablePaginationFeature, type DataTableProps, type DataTableSearchField, type DataTableVirtualizationFeature, FilterChildRenderFn, type FilterDefinition, type FilterDisplayProps, type FilterFactory, type FilterFormProps, type FilterInstance, FilterProps, FilterValues, type FiltersConfiguration, type InfiniteScrollPageInfo, NotificationHost, type NotificationHostProps, type NotificationOptions, type NotificationRenderProps, VirtualList, type VirtualListProps, createFilter, dataTableVariants, filterVariants, filters, notification, virtualListVariants };
package/dist/index.d.ts CHANGED
@@ -1,3 +1,5 @@
1
- import { a as FilterProps, c as FilterDefinition, d as FilterFormProps, f as FilterInstance, i as FilterChildRenderFn, l as FilterDisplayProps, n as createFilter, o as FilterValues, p as FiltersConfiguration, s as filterVariants, t as filters, u as FilterFactory } from "./index-E2k5kJ14.js";
1
+ import { a as DataTableInfiniteScrollFeature, c as DataTableSearchField, d as dataTableVariants, i as DataTableIcons, l as DataTableVirtualizationFeature, n as DataTableExpandableRowsFeature, o as DataTablePaginationFeature, r as DataTableFeatures, s as DataTableProps, t as DataTable, u as InfiniteScrollPageInfo } from "./index-Crb5hCFD.js";
2
+ import { a as FilterProps, c as FilterDefinition, d as FilterFormProps, f as FilterInstance, i as FilterChildRenderFn, l as FilterDisplayProps, n as createFilter, o as FilterValues, p as FiltersConfiguration, s as filterVariants, t as filters, u as FilterFactory } from "./index-DCiYTnRL.js";
2
3
  import { a as notification, i as NotificationRenderProps, n as NotificationHostProps, r as NotificationOptions, t as NotificationHost } from "./index-oeUH2qWd.js";
3
- export { FilterChildRenderFn, type FilterDefinition, type FilterDisplayProps, type FilterFactory, type FilterFormProps, type FilterInstance, FilterProps, FilterValues, type FiltersConfiguration, NotificationHost, type NotificationHostProps, type NotificationOptions, type NotificationRenderProps, createFilter, filterVariants, filters, notification };
4
+ import { n as VirtualListProps, r as virtualListVariants, t as VirtualList } from "./index-jFySXsl9.js";
5
+ export { DataTable, type DataTableExpandableRowsFeature, type DataTableFeatures, type DataTableIcons, type DataTableInfiniteScrollFeature, type DataTablePaginationFeature, type DataTableProps, type DataTableSearchField, type DataTableVirtualizationFeature, FilterChildRenderFn, type FilterDefinition, type FilterDisplayProps, type FilterFactory, type FilterFormProps, type FilterInstance, FilterProps, FilterValues, type FiltersConfiguration, type InfiniteScrollPageInfo, NotificationHost, type NotificationHostProps, type NotificationOptions, type NotificationRenderProps, VirtualList, type VirtualListProps, createFilter, dataTableVariants, filterVariants, filters, notification, virtualListVariants };
package/dist/index.js CHANGED
@@ -1,8 +1,10 @@
1
- import { i as filterVariants, n as filters, r as createFilter } from "./Filter-BKfVjFPo.js";
1
+ import { n as DataTable, r as dataTableVariants } from "./DataTable-Da6WZFKm.js";
2
+ import { i as filterVariants, n as filters, r as createFilter } from "./Filter-DNj4lzj5.js";
2
3
  import { n as NotificationHost, r as notification } from "./Notification-Bgw2MtBQ.js";
4
+ import { n as VirtualList, r as virtualListVariants } from "./VirtualList-DQ4uR-wR.js";
3
5
  //#region src/index.ts
4
6
  /* v8 ignore stop */
5
7
  //#endregion
6
- export { NotificationHost, createFilter, filterVariants, filters, notification };
8
+ export { DataTable, NotificationHost, VirtualList, createFilter, dataTableVariants, filterVariants, filters, notification, virtualListVariants };
7
9
 
8
10
  //# sourceMappingURL=index.js.map
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["/* v8 ignore start */\n\n// components\nexport * from './Filter';\nexport * from './Notification';\n\n/* v8 ignore stop */\n"],"mappings":""}
1
+ {"version":3,"file":"index.js","names":[],"sources":["../src/index.ts"],"sourcesContent":["/* v8 ignore start */\n\n// components\nexport * from './DataTable';\nexport * from './Filter';\nexport * from './Notification';\nexport * from './VirtualList';\n\n/* v8 ignore stop */\n"],"mappings":""}
@@ -0,0 +1,28 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __copyProps = (to, from, except, desc) => {
9
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
10
+ key = keys[i];
11
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
12
+ get: ((k) => from[k]).bind(null, key),
13
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
14
+ });
15
+ }
16
+ return to;
17
+ };
18
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
19
+ value: mod,
20
+ enumerable: true
21
+ }) : target, mod));
22
+ //#endregion
23
+ Object.defineProperty(exports, "__toESM", {
24
+ enumerable: true,
25
+ get: function() {
26
+ return __toESM;
27
+ }
28
+ });
@@ -0,0 +1,175 @@
1
+ let react = require("react");
2
+ let _tanstack_react_virtual = require("@tanstack/react-virtual");
3
+ //#region src/hooks/useInfiniteVirtualizer.ts
4
+ const DEFAULT_ESTIMATE_SIZE = 45;
5
+ const DEFAULT_LOAD_MORE_THRESHOLD = 5;
6
+ const DEFAULT_OVERSCAN = 5;
7
+ const DEFAULT_VIEWPORT_HEIGHT = 600;
8
+ /**
9
+ * Shared virtualizer hook used by DataTable/VirtualList for infinite scrolling.
10
+ *
11
+ * What it handles:
12
+ * - configures TanStack Virtual with optional dynamic row measurement
13
+ * - triggers cursor/page loading when the visible range approaches the tail
14
+ * - deduplicates repeated load-more triggers for the same loaded state/range
15
+ * - provides fallback virtual items when `getVirtualItems()` is temporarily
16
+ * empty (common in test/JSDOM or before first measurements)
17
+ * - exposes imperative helpers (`retry`, `scrollToTop`, `scrollToIndex`)
18
+ *
19
+ * Notes:
20
+ * - `count` is the total virtual item count (can include placeholders/sentinel)
21
+ * - `loadedCount` should represent only currently loaded items to let the
22
+ * dedup guard allow the next request after new data arrives
23
+ * - `shouldLoadMore` can override default tail-threshold triggering logic
24
+ */
25
+ const useInfiniteVirtualizer = ({ count, dynamicRowHeight = false, enabled = true, estimateSize, hasNextPage = false, isFetchingNextPage = false, loadedCount = void 0, loadMoreError = false, loadMoreThreshold = DEFAULT_LOAD_MORE_THRESHOLD, onLoadMore = void 0, overscan = DEFAULT_OVERSCAN, scrollElementRef: externalScrollElementRef = void 0, shouldLoadMore = void 0 }) => {
26
+ const localScrollElementRef = (0, react.useRef)(null);
27
+ const scrollElementRef = externalScrollElementRef ?? localScrollElementRef;
28
+ const lastTriggerKeyRef = (0, react.useRef)(null);
29
+ const resolvedLoadedCount = loadedCount ?? count;
30
+ const [fallbackRange, setFallbackRange] = (0, react.useState)({
31
+ scrollTop: 0,
32
+ viewportHeight: DEFAULT_VIEWPORT_HEIGHT
33
+ });
34
+ const resolvedEstimateSize = (0, react.useMemo)(() => {
35
+ return estimateSize ?? (() => {
36
+ return DEFAULT_ESTIMATE_SIZE;
37
+ });
38
+ }, [estimateSize]);
39
+ const isFirefox = typeof window !== "undefined" && window.navigator.userAgent.includes("Firefox");
40
+ const maybeLoadMore = (0, react.useCallback)((virtualItems) => {
41
+ if (!enabled || !hasNextPage || isFetchingNextPage || loadMoreError || !onLoadMore) return;
42
+ if (!(shouldLoadMore ? shouldLoadMore({
43
+ loadMoreThreshold,
44
+ virtualItems
45
+ }) : virtualItems.some((item) => {
46
+ return item.index >= Math.max(count - loadMoreThreshold - 1, 0);
47
+ }))) return;
48
+ const triggerKey = `${resolvedLoadedCount}:${virtualItems[virtualItems.length - 1]?.index ?? -1}`;
49
+ if (lastTriggerKeyRef.current === triggerKey) return;
50
+ lastTriggerKeyRef.current = triggerKey;
51
+ onLoadMore();
52
+ }, [
53
+ count,
54
+ enabled,
55
+ hasNextPage,
56
+ isFetchingNextPage,
57
+ loadMoreError,
58
+ loadMoreThreshold,
59
+ onLoadMore,
60
+ resolvedLoadedCount,
61
+ shouldLoadMore
62
+ ]);
63
+ const virtualizer = (0, _tanstack_react_virtual.useVirtualizer)({
64
+ count,
65
+ enabled,
66
+ estimateSize: resolvedEstimateSize,
67
+ getScrollElement: () => {
68
+ return scrollElementRef.current;
69
+ },
70
+ initialRect: {
71
+ height: DEFAULT_VIEWPORT_HEIGHT,
72
+ width: 1024
73
+ },
74
+ measureElement: dynamicRowHeight && !isFirefox ? (element) => {
75
+ return element.getBoundingClientRect().height;
76
+ } : void 0,
77
+ onChange: (instance) => {
78
+ maybeLoadMore(instance.getVirtualItems());
79
+ },
80
+ overscan
81
+ });
82
+ const estimatedItemSize = Math.max(resolvedEstimateSize(0), 1);
83
+ const getFallbackVirtualItems = (0, react.useCallback)((scrollTop, viewportHeight) => {
84
+ const fallbackStartIndex = Math.max(Math.floor(scrollTop / estimatedItemSize) - overscan, 0);
85
+ const fallbackEndIndex = Math.min(Math.ceil((scrollTop + viewportHeight) / estimatedItemSize) + overscan, count);
86
+ return Array.from({ length: Math.max(fallbackEndIndex - fallbackStartIndex, 0) }, (_, offset) => {
87
+ const index = fallbackStartIndex + offset;
88
+ const size = resolvedEstimateSize(index);
89
+ return {
90
+ end: (index + 1) * estimatedItemSize,
91
+ index,
92
+ key: index,
93
+ lane: 0,
94
+ size,
95
+ start: index * estimatedItemSize
96
+ };
97
+ });
98
+ }, [
99
+ count,
100
+ estimatedItemSize,
101
+ overscan,
102
+ resolvedEstimateSize
103
+ ]);
104
+ (0, react.useEffect)(() => {
105
+ const scrollElement = scrollElementRef.current;
106
+ if (!scrollElement) return;
107
+ const syncFallbackRange = () => {
108
+ const nextRange = {
109
+ scrollTop: scrollElement.scrollTop,
110
+ viewportHeight: scrollElement.clientHeight > 0 ? scrollElement.clientHeight : DEFAULT_VIEWPORT_HEIGHT
111
+ };
112
+ setFallbackRange((previousRange) => {
113
+ if (previousRange.scrollTop === nextRange.scrollTop && previousRange.viewportHeight === nextRange.viewportHeight) return previousRange;
114
+ return nextRange;
115
+ });
116
+ };
117
+ syncFallbackRange();
118
+ scrollElement.addEventListener("scroll", syncFallbackRange, { passive: true });
119
+ window.addEventListener("resize", syncFallbackRange);
120
+ return () => {
121
+ scrollElement.removeEventListener("scroll", syncFallbackRange);
122
+ window.removeEventListener("resize", syncFallbackRange);
123
+ };
124
+ }, [scrollElementRef]);
125
+ const virtualItems = virtualizer.getVirtualItems();
126
+ const fallbackVirtualItems = virtualItems.length === 0 && count > 0 ? getFallbackVirtualItems(fallbackRange.scrollTop, fallbackRange.viewportHeight) : [];
127
+ const activeVirtualItems = virtualItems.length > 0 ? virtualItems : fallbackVirtualItems;
128
+ const totalSize = Math.max(virtualizer.getTotalSize(), count * estimatedItemSize);
129
+ (0, react.useEffect)(() => {
130
+ maybeLoadMore(activeVirtualItems);
131
+ });
132
+ const measureElement = (0, react.useMemo)(() => {
133
+ if (!dynamicRowHeight || isFirefox) return;
134
+ return (node) => {
135
+ if (!node) return;
136
+ virtualizer.measureElement(node);
137
+ };
138
+ }, [
139
+ dynamicRowHeight,
140
+ isFirefox,
141
+ virtualizer
142
+ ]);
143
+ const retry = (0, react.useCallback)(() => {
144
+ if (!onLoadMore || isFetchingNextPage || !hasNextPage) return;
145
+ onLoadMore();
146
+ }, [
147
+ hasNextPage,
148
+ isFetchingNextPage,
149
+ onLoadMore
150
+ ]);
151
+ const scrollToTop = (0, react.useCallback)(() => {
152
+ virtualizer.scrollToOffset(0);
153
+ }, [virtualizer]);
154
+ return {
155
+ measureElement,
156
+ retry,
157
+ scrollElementRef,
158
+ scrollToIndex: (0, react.useCallback)((index) => {
159
+ virtualizer.scrollToIndex(index);
160
+ }, [virtualizer]),
161
+ scrollToTop,
162
+ totalSize,
163
+ virtualItems: activeVirtualItems,
164
+ virtualizer
165
+ };
166
+ };
167
+ //#endregion
168
+ Object.defineProperty(exports, "useInfiniteVirtualizer", {
169
+ enumerable: true,
170
+ get: function() {
171
+ return useInfiniteVirtualizer;
172
+ }
173
+ });
174
+
175
+ //# sourceMappingURL=useInfiniteVirtualizer-BK0VroW4.cjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useInfiniteVirtualizer-BK0VroW4.cjs","names":[],"sources":["../src/hooks/useInfiniteVirtualizer.ts"],"sourcesContent":["import type { VirtualItem } from '@tanstack/react-virtual';\nimport type { RefObject } from 'react';\n\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react';\n\nimport { useVirtualizer } from '@tanstack/react-virtual';\n\n/**\n * Configuration for the shared infinite virtualizer hook.\n */\nexport interface UseInfiniteVirtualizerParams {\n /** Total number of virtual items (loaded + placeholders/sentinels). */\n count: number;\n /** Enables dynamic measurement of row heights after render. */\n dynamicRowHeight?: boolean;\n /** Master switch for virtualization and load-more effects. */\n enabled?: boolean;\n /** Estimated item size used before real measurements are available. */\n estimateSize?: (index: number) => number;\n /** Whether another page exists beyond the currently loaded data. */\n hasNextPage?: boolean;\n /** True while the parent is currently fetching the next page. */\n isFetchingNextPage?: boolean;\n /**\n * Number of currently loaded items. Used to deduplicate load-more calls:\n * a new call is only made after the loaded count has changed (i.e. the\n * previous page arrived). Defaults to `count`.\n */\n loadedCount?: number;\n /** True when the latest load-more request failed. */\n loadMoreError?: boolean;\n /** Number of items before the tail where prefetch should trigger. */\n loadMoreThreshold?: number;\n /** Callback used to request the next page of data. */\n onLoadMore?: () => void;\n /** Number of extra items rendered above/below the viewport. */\n overscan?: number;\n /** Optional external scroll container ref consumed by the virtualizer. */\n scrollElementRef?: RefObject<HTMLDivElement | null>;\n /** Custom load-more trigger predicate for advanced item models. */\n shouldLoadMore?: (params: {\n /** Resolved threshold value passed to the predicate. */\n loadMoreThreshold: number;\n /** Current visible virtual items from the active virtualizer range. */\n virtualItems: VirtualItem[];\n }) => boolean;\n}\n\nconst DEFAULT_ESTIMATE_SIZE = 45;\nconst DEFAULT_LOAD_MORE_THRESHOLD = 5;\nconst DEFAULT_OVERSCAN = 5;\nconst DEFAULT_VIEWPORT_HEIGHT = 600;\n\n/**\n * Shared virtualizer hook used by DataTable/VirtualList for infinite scrolling.\n *\n * What it handles:\n * - configures TanStack Virtual with optional dynamic row measurement\n * - triggers cursor/page loading when the visible range approaches the tail\n * - deduplicates repeated load-more triggers for the same loaded state/range\n * - provides fallback virtual items when `getVirtualItems()` is temporarily\n * empty (common in test/JSDOM or before first measurements)\n * - exposes imperative helpers (`retry`, `scrollToTop`, `scrollToIndex`)\n *\n * Notes:\n * - `count` is the total virtual item count (can include placeholders/sentinel)\n * - `loadedCount` should represent only currently loaded items to let the\n * dedup guard allow the next request after new data arrives\n * - `shouldLoadMore` can override default tail-threshold triggering logic\n */\nexport const useInfiniteVirtualizer = ({\n count,\n dynamicRowHeight = false,\n enabled = true,\n estimateSize,\n hasNextPage = false,\n isFetchingNextPage = false,\n loadedCount = undefined,\n loadMoreError = false,\n loadMoreThreshold = DEFAULT_LOAD_MORE_THRESHOLD,\n onLoadMore = undefined,\n overscan = DEFAULT_OVERSCAN,\n scrollElementRef: externalScrollElementRef = undefined,\n shouldLoadMore = undefined,\n}: UseInfiniteVirtualizerParams) => {\n const localScrollElementRef = useRef<HTMLDivElement | null>(null);\n const scrollElementRef = externalScrollElementRef ?? localScrollElementRef;\n const lastTriggerKeyRef = useRef<string | null>(null);\n const resolvedLoadedCount = loadedCount ?? count;\n const [fallbackRange, setFallbackRange] = useState({\n scrollTop: 0,\n viewportHeight: DEFAULT_VIEWPORT_HEIGHT,\n });\n const resolvedEstimateSize = useMemo(() => {\n return (\n estimateSize ??\n (() => {\n return DEFAULT_ESTIMATE_SIZE;\n })\n );\n }, [estimateSize]);\n\n const isFirefox =\n typeof window !== 'undefined' &&\n // eslint-disable-next-line n/no-unsupported-features/node-builtins\n window.navigator.userAgent.includes('Firefox');\n\n const maybeLoadMore = useCallback(\n (virtualItems: VirtualItem[]) => {\n if (\n !enabled ||\n !hasNextPage ||\n isFetchingNextPage ||\n loadMoreError ||\n !onLoadMore\n ) {\n return;\n }\n\n const shouldTrigger = shouldLoadMore\n ? shouldLoadMore({\n loadMoreThreshold,\n virtualItems,\n })\n : virtualItems.some((item) => {\n return item.index >= Math.max(count - loadMoreThreshold - 1, 0);\n });\n\n if (!shouldTrigger) {\n return;\n }\n\n const lastVisibleIndex =\n virtualItems[virtualItems.length - 1]?.index ?? -1;\n const triggerKey = `${resolvedLoadedCount}:${lastVisibleIndex}`;\n\n // Avoid duplicate requests for the same loaded state and visible range,\n // while still allowing a later, deeper scroll to request the next page.\n if (lastTriggerKeyRef.current === triggerKey) {\n return;\n }\n\n lastTriggerKeyRef.current = triggerKey;\n onLoadMore();\n },\n [\n count,\n enabled,\n hasNextPage,\n isFetchingNextPage,\n loadMoreError,\n loadMoreThreshold,\n onLoadMore,\n resolvedLoadedCount,\n shouldLoadMore,\n ],\n );\n\n const virtualizer = useVirtualizer<HTMLDivElement, HTMLElement>({\n count,\n enabled,\n estimateSize: resolvedEstimateSize,\n getScrollElement: () => {\n return scrollElementRef.current;\n },\n initialRect: {\n height: DEFAULT_VIEWPORT_HEIGHT,\n width: 1024,\n },\n measureElement:\n dynamicRowHeight && !isFirefox\n ? (element) => {\n return element.getBoundingClientRect().height;\n }\n : undefined,\n onChange: (instance) => {\n maybeLoadMore(instance.getVirtualItems());\n },\n overscan,\n });\n\n const estimatedItemSize = Math.max(resolvedEstimateSize(0), 1);\n\n const getFallbackVirtualItems = useCallback(\n (scrollTop: number, viewportHeight: number): VirtualItem[] => {\n const fallbackStartIndex = Math.max(\n Math.floor(scrollTop / estimatedItemSize) - overscan,\n 0,\n );\n const fallbackEndIndex = Math.min(\n Math.ceil((scrollTop + viewportHeight) / estimatedItemSize) + overscan,\n count,\n );\n\n return Array.from(\n { length: Math.max(fallbackEndIndex - fallbackStartIndex, 0) },\n (_, offset) => {\n const index = fallbackStartIndex + offset;\n const size = resolvedEstimateSize(index);\n return {\n end: (index + 1) * estimatedItemSize,\n index,\n key: index,\n lane: 0,\n size,\n start: index * estimatedItemSize,\n };\n },\n );\n },\n [count, estimatedItemSize, overscan, resolvedEstimateSize],\n );\n\n useEffect(() => {\n const scrollElement = scrollElementRef.current;\n if (!scrollElement) {\n return undefined;\n }\n\n const syncFallbackRange = () => {\n const nextRange = {\n scrollTop: scrollElement.scrollTop,\n viewportHeight:\n scrollElement.clientHeight > 0\n ? scrollElement.clientHeight\n : DEFAULT_VIEWPORT_HEIGHT,\n };\n setFallbackRange((previousRange) => {\n if (\n previousRange.scrollTop === nextRange.scrollTop &&\n previousRange.viewportHeight === nextRange.viewportHeight\n ) {\n return previousRange;\n }\n return nextRange;\n });\n };\n\n syncFallbackRange();\n scrollElement.addEventListener('scroll', syncFallbackRange, {\n passive: true,\n });\n window.addEventListener('resize', syncFallbackRange);\n\n return () => {\n scrollElement.removeEventListener('scroll', syncFallbackRange);\n window.removeEventListener('resize', syncFallbackRange);\n };\n }, [scrollElementRef]);\n\n const virtualItems = virtualizer.getVirtualItems();\n const fallbackVirtualItems: VirtualItem[] =\n virtualItems.length === 0 && count > 0\n ? getFallbackVirtualItems(\n fallbackRange.scrollTop,\n fallbackRange.viewportHeight,\n )\n : [];\n const activeVirtualItems =\n virtualItems.length > 0 ? virtualItems : fallbackVirtualItems;\n const totalSize = Math.max(\n virtualizer.getTotalSize(),\n count * estimatedItemSize,\n );\n\n // Scroll events alone are not enough to drive loading: the first page may\n // not fill the container (no scroll possible) and appended pages can leave\n // the viewport still at the end. Re-check on every relevant state change.\n useEffect(() => {\n maybeLoadMore(activeVirtualItems);\n });\n\n const measureElement = useMemo(() => {\n if (!dynamicRowHeight || isFirefox) {\n return undefined;\n }\n return (node: HTMLElement | null) => {\n if (!node) {\n return;\n }\n virtualizer.measureElement(node);\n };\n }, [dynamicRowHeight, isFirefox, virtualizer]);\n\n const retry = useCallback(() => {\n if (!onLoadMore || isFetchingNextPage || !hasNextPage) {\n return;\n }\n onLoadMore();\n }, [hasNextPage, isFetchingNextPage, onLoadMore]);\n\n const scrollToTop = useCallback(() => {\n virtualizer.scrollToOffset(0);\n }, [virtualizer]);\n\n const scrollToIndex = useCallback(\n (index: number) => {\n virtualizer.scrollToIndex(index);\n },\n [virtualizer],\n );\n\n return {\n measureElement,\n retry,\n scrollElementRef,\n scrollToIndex,\n scrollToTop,\n totalSize,\n virtualItems: activeVirtualItems,\n virtualizer,\n };\n};\n\nexport default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AAkB;EAClB,cAAc,iBAAiB,UAAU,mBAAmB,EAC1D,SAAS,KACX,CAAC;EACD,OAAO,iBAAiB,UAAU,iBAAiB;EAEnD,aAAa;GACX,cAAc,oBAAoB,UAAU,iBAAiB;GAC7D,OAAO,oBAAoB,UAAU,iBAAiB;EACxD;CACF,GAAG,CAAC,gBAAgB,CAAC;CAErB,MAAM,eAAe,YAAY,gBAAgB;CACjD,MAAM,uBACJ,aAAa,WAAW,KAAK,QAAQ,IACjC,wBACE,cAAc,WACd,cAAc,cAChB,IACA,CAAC;CACP,MAAM,qBACJ,aAAa,SAAS,IAAI,eAAe;CAC3C,MAAM,YAAY,KAAK,IACrB,YAAY,aAAa,GACzB,QAAQ,iBACV;CAKA,CAAA,GAAA,MAAA,UAAA,OAAgB;EACd,cAAc,kBAAkB;CAClC,CAAC;CAED,MAAM,kBAAA,GAAA,MAAA,QAAA,OAA+B;EACnC,IAAI,CAAC,oBAAoB,WACvB;EAEF,QAAQ,SAA6B;GACnC,IAAI,CAAC,MACH;GAEF,YAAY,eAAe,IAAI;EACjC;CACF,GAAG;EAAC;EAAkB;EAAW;CAAW,CAAC;CAE7C,MAAM,SAAA,GAAA,MAAA,YAAA,OAA0B;EAC9B,IAAI,CAAC,cAAc,sBAAsB,CAAC,aACxC;EAEF,WAAW;CACb,GAAG;EAAC;EAAa;EAAoB;CAAU,CAAC;CAEhD,MAAM,eAAA,GAAA,MAAA,YAAA,OAAgC;EACpC,YAAY,eAAe,CAAC;CAC9B,GAAG,CAAC,WAAW,CAAC;CAShB,OAAO;EACL;EACA;EACA;EACA,gBAAA,GAAA,MAAA,YAAA,EAVC,UAAkB;GACjB,YAAY,cAAc,KAAK;EACjC,GACA,CAAC,WAAW,CAOA;EACZ;EACA;EACA,cAAc;EACd;CACF;AACF"}
@@ -0,0 +1,170 @@
1
+ import { useCallback, useEffect, useMemo, useRef, useState } from "react";
2
+ import { useVirtualizer } from "@tanstack/react-virtual";
3
+ //#region src/hooks/useInfiniteVirtualizer.ts
4
+ const DEFAULT_ESTIMATE_SIZE = 45;
5
+ const DEFAULT_LOAD_MORE_THRESHOLD = 5;
6
+ const DEFAULT_OVERSCAN = 5;
7
+ const DEFAULT_VIEWPORT_HEIGHT = 600;
8
+ /**
9
+ * Shared virtualizer hook used by DataTable/VirtualList for infinite scrolling.
10
+ *
11
+ * What it handles:
12
+ * - configures TanStack Virtual with optional dynamic row measurement
13
+ * - triggers cursor/page loading when the visible range approaches the tail
14
+ * - deduplicates repeated load-more triggers for the same loaded state/range
15
+ * - provides fallback virtual items when `getVirtualItems()` is temporarily
16
+ * empty (common in test/JSDOM or before first measurements)
17
+ * - exposes imperative helpers (`retry`, `scrollToTop`, `scrollToIndex`)
18
+ *
19
+ * Notes:
20
+ * - `count` is the total virtual item count (can include placeholders/sentinel)
21
+ * - `loadedCount` should represent only currently loaded items to let the
22
+ * dedup guard allow the next request after new data arrives
23
+ * - `shouldLoadMore` can override default tail-threshold triggering logic
24
+ */
25
+ const useInfiniteVirtualizer = ({ count, dynamicRowHeight = false, enabled = true, estimateSize, hasNextPage = false, isFetchingNextPage = false, loadedCount = void 0, loadMoreError = false, loadMoreThreshold = DEFAULT_LOAD_MORE_THRESHOLD, onLoadMore = void 0, overscan = DEFAULT_OVERSCAN, scrollElementRef: externalScrollElementRef = void 0, shouldLoadMore = void 0 }) => {
26
+ const localScrollElementRef = useRef(null);
27
+ const scrollElementRef = externalScrollElementRef ?? localScrollElementRef;
28
+ const lastTriggerKeyRef = useRef(null);
29
+ const resolvedLoadedCount = loadedCount ?? count;
30
+ const [fallbackRange, setFallbackRange] = useState({
31
+ scrollTop: 0,
32
+ viewportHeight: DEFAULT_VIEWPORT_HEIGHT
33
+ });
34
+ const resolvedEstimateSize = useMemo(() => {
35
+ return estimateSize ?? (() => {
36
+ return DEFAULT_ESTIMATE_SIZE;
37
+ });
38
+ }, [estimateSize]);
39
+ const isFirefox = typeof window !== "undefined" && window.navigator.userAgent.includes("Firefox");
40
+ const maybeLoadMore = useCallback((virtualItems) => {
41
+ if (!enabled || !hasNextPage || isFetchingNextPage || loadMoreError || !onLoadMore) return;
42
+ if (!(shouldLoadMore ? shouldLoadMore({
43
+ loadMoreThreshold,
44
+ virtualItems
45
+ }) : virtualItems.some((item) => {
46
+ return item.index >= Math.max(count - loadMoreThreshold - 1, 0);
47
+ }))) return;
48
+ const triggerKey = `${resolvedLoadedCount}:${virtualItems[virtualItems.length - 1]?.index ?? -1}`;
49
+ if (lastTriggerKeyRef.current === triggerKey) return;
50
+ lastTriggerKeyRef.current = triggerKey;
51
+ onLoadMore();
52
+ }, [
53
+ count,
54
+ enabled,
55
+ hasNextPage,
56
+ isFetchingNextPage,
57
+ loadMoreError,
58
+ loadMoreThreshold,
59
+ onLoadMore,
60
+ resolvedLoadedCount,
61
+ shouldLoadMore
62
+ ]);
63
+ const virtualizer = useVirtualizer({
64
+ count,
65
+ enabled,
66
+ estimateSize: resolvedEstimateSize,
67
+ getScrollElement: () => {
68
+ return scrollElementRef.current;
69
+ },
70
+ initialRect: {
71
+ height: DEFAULT_VIEWPORT_HEIGHT,
72
+ width: 1024
73
+ },
74
+ measureElement: dynamicRowHeight && !isFirefox ? (element) => {
75
+ return element.getBoundingClientRect().height;
76
+ } : void 0,
77
+ onChange: (instance) => {
78
+ maybeLoadMore(instance.getVirtualItems());
79
+ },
80
+ overscan
81
+ });
82
+ const estimatedItemSize = Math.max(resolvedEstimateSize(0), 1);
83
+ const getFallbackVirtualItems = useCallback((scrollTop, viewportHeight) => {
84
+ const fallbackStartIndex = Math.max(Math.floor(scrollTop / estimatedItemSize) - overscan, 0);
85
+ const fallbackEndIndex = Math.min(Math.ceil((scrollTop + viewportHeight) / estimatedItemSize) + overscan, count);
86
+ return Array.from({ length: Math.max(fallbackEndIndex - fallbackStartIndex, 0) }, (_, offset) => {
87
+ const index = fallbackStartIndex + offset;
88
+ const size = resolvedEstimateSize(index);
89
+ return {
90
+ end: (index + 1) * estimatedItemSize,
91
+ index,
92
+ key: index,
93
+ lane: 0,
94
+ size,
95
+ start: index * estimatedItemSize
96
+ };
97
+ });
98
+ }, [
99
+ count,
100
+ estimatedItemSize,
101
+ overscan,
102
+ resolvedEstimateSize
103
+ ]);
104
+ useEffect(() => {
105
+ const scrollElement = scrollElementRef.current;
106
+ if (!scrollElement) return;
107
+ const syncFallbackRange = () => {
108
+ const nextRange = {
109
+ scrollTop: scrollElement.scrollTop,
110
+ viewportHeight: scrollElement.clientHeight > 0 ? scrollElement.clientHeight : DEFAULT_VIEWPORT_HEIGHT
111
+ };
112
+ setFallbackRange((previousRange) => {
113
+ if (previousRange.scrollTop === nextRange.scrollTop && previousRange.viewportHeight === nextRange.viewportHeight) return previousRange;
114
+ return nextRange;
115
+ });
116
+ };
117
+ syncFallbackRange();
118
+ scrollElement.addEventListener("scroll", syncFallbackRange, { passive: true });
119
+ window.addEventListener("resize", syncFallbackRange);
120
+ return () => {
121
+ scrollElement.removeEventListener("scroll", syncFallbackRange);
122
+ window.removeEventListener("resize", syncFallbackRange);
123
+ };
124
+ }, [scrollElementRef]);
125
+ const virtualItems = virtualizer.getVirtualItems();
126
+ const fallbackVirtualItems = virtualItems.length === 0 && count > 0 ? getFallbackVirtualItems(fallbackRange.scrollTop, fallbackRange.viewportHeight) : [];
127
+ const activeVirtualItems = virtualItems.length > 0 ? virtualItems : fallbackVirtualItems;
128
+ const totalSize = Math.max(virtualizer.getTotalSize(), count * estimatedItemSize);
129
+ useEffect(() => {
130
+ maybeLoadMore(activeVirtualItems);
131
+ });
132
+ const measureElement = useMemo(() => {
133
+ if (!dynamicRowHeight || isFirefox) return;
134
+ return (node) => {
135
+ if (!node) return;
136
+ virtualizer.measureElement(node);
137
+ };
138
+ }, [
139
+ dynamicRowHeight,
140
+ isFirefox,
141
+ virtualizer
142
+ ]);
143
+ const retry = useCallback(() => {
144
+ if (!onLoadMore || isFetchingNextPage || !hasNextPage) return;
145
+ onLoadMore();
146
+ }, [
147
+ hasNextPage,
148
+ isFetchingNextPage,
149
+ onLoadMore
150
+ ]);
151
+ const scrollToTop = useCallback(() => {
152
+ virtualizer.scrollToOffset(0);
153
+ }, [virtualizer]);
154
+ return {
155
+ measureElement,
156
+ retry,
157
+ scrollElementRef,
158
+ scrollToIndex: useCallback((index) => {
159
+ virtualizer.scrollToIndex(index);
160
+ }, [virtualizer]),
161
+ scrollToTop,
162
+ totalSize,
163
+ virtualItems: activeVirtualItems,
164
+ virtualizer
165
+ };
166
+ };
167
+ //#endregion
168
+ export { useInfiniteVirtualizer as t };
169
+
170
+ //# sourceMappingURL=useInfiniteVirtualizer-BSCDrdRi.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useInfiniteVirtualizer-BSCDrdRi.js","names":[],"sources":["../src/hooks/useInfiniteVirtualizer.ts"],"sourcesContent":["import type { VirtualItem } from '@tanstack/react-virtual';\nimport type { RefObject } from 'react';\n\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react';\n\nimport { useVirtualizer } from '@tanstack/react-virtual';\n\n/**\n * Configuration for the shared infinite virtualizer hook.\n */\nexport interface UseInfiniteVirtualizerParams {\n /** Total number of virtual items (loaded + placeholders/sentinels). */\n count: number;\n /** Enables dynamic measurement of row heights after render. */\n dynamicRowHeight?: boolean;\n /** Master switch for virtualization and load-more effects. */\n enabled?: boolean;\n /** Estimated item size used before real measurements are available. */\n estimateSize?: (index: number) => number;\n /** Whether another page exists beyond the currently loaded data. */\n hasNextPage?: boolean;\n /** True while the parent is currently fetching the next page. */\n isFetchingNextPage?: boolean;\n /**\n * Number of currently loaded items. Used to deduplicate load-more calls:\n * a new call is only made after the loaded count has changed (i.e. the\n * previous page arrived). Defaults to `count`.\n */\n loadedCount?: number;\n /** True when the latest load-more request failed. */\n loadMoreError?: boolean;\n /** Number of items before the tail where prefetch should trigger. */\n loadMoreThreshold?: number;\n /** Callback used to request the next page of data. */\n onLoadMore?: () => void;\n /** Number of extra items rendered above/below the viewport. */\n overscan?: number;\n /** Optional external scroll container ref consumed by the virtualizer. */\n scrollElementRef?: RefObject<HTMLDivElement | null>;\n /** Custom load-more trigger predicate for advanced item models. */\n shouldLoadMore?: (params: {\n /** Resolved threshold value passed to the predicate. */\n loadMoreThreshold: number;\n /** Current visible virtual items from the active virtualizer range. */\n virtualItems: VirtualItem[];\n }) => boolean;\n}\n\nconst DEFAULT_ESTIMATE_SIZE = 45;\nconst DEFAULT_LOAD_MORE_THRESHOLD = 5;\nconst DEFAULT_OVERSCAN = 5;\nconst DEFAULT_VIEWPORT_HEIGHT = 600;\n\n/**\n * Shared virtualizer hook used by DataTable/VirtualList for infinite scrolling.\n *\n * What it handles:\n * - configures TanStack Virtual with optional dynamic row measurement\n * - triggers cursor/page loading when the visible range approaches the tail\n * - deduplicates repeated load-more triggers for the same loaded state/range\n * - provides fallback virtual items when `getVirtualItems()` is temporarily\n * empty (common in test/JSDOM or before first measurements)\n * - exposes imperative helpers (`retry`, `scrollToTop`, `scrollToIndex`)\n *\n * Notes:\n * - `count` is the total virtual item count (can include placeholders/sentinel)\n * - `loadedCount` should represent only currently loaded items to let the\n * dedup guard allow the next request after new data arrives\n * - `shouldLoadMore` can override default tail-threshold triggering logic\n */\nexport const useInfiniteVirtualizer = ({\n count,\n dynamicRowHeight = false,\n enabled = true,\n estimateSize,\n hasNextPage = false,\n isFetchingNextPage = false,\n loadedCount = undefined,\n loadMoreError = false,\n loadMoreThreshold = DEFAULT_LOAD_MORE_THRESHOLD,\n onLoadMore = undefined,\n overscan = DEFAULT_OVERSCAN,\n scrollElementRef: externalScrollElementRef = undefined,\n shouldLoadMore = undefined,\n}: UseInfiniteVirtualizerParams) => {\n const localScrollElementRef = useRef<HTMLDivElement | null>(null);\n const scrollElementRef = externalScrollElementRef ?? localScrollElementRef;\n const lastTriggerKeyRef = useRef<string | null>(null);\n const resolvedLoadedCount = loadedCount ?? count;\n const [fallbackRange, setFallbackRange] = useState({\n scrollTop: 0,\n viewportHeight: DEFAULT_VIEWPORT_HEIGHT,\n });\n const resolvedEstimateSize = useMemo(() => {\n return (\n estimateSize ??\n (() => {\n return DEFAULT_ESTIMATE_SIZE;\n })\n );\n }, [estimateSize]);\n\n const isFirefox =\n typeof window !== 'undefined' &&\n // eslint-disable-next-line n/no-unsupported-features/node-builtins\n window.navigator.userAgent.includes('Firefox');\n\n const maybeLoadMore = useCallback(\n (virtualItems: VirtualItem[]) => {\n if (\n !enabled ||\n !hasNextPage ||\n isFetchingNextPage ||\n loadMoreError ||\n !onLoadMore\n ) {\n return;\n }\n\n const shouldTrigger = shouldLoadMore\n ? shouldLoadMore({\n loadMoreThreshold,\n virtualItems,\n })\n : virtualItems.some((item) => {\n return item.index >= Math.max(count - loadMoreThreshold - 1, 0);\n });\n\n if (!shouldTrigger) {\n return;\n }\n\n const lastVisibleIndex =\n virtualItems[virtualItems.length - 1]?.index ?? -1;\n const triggerKey = `${resolvedLoadedCount}:${lastVisibleIndex}`;\n\n // Avoid duplicate requests for the same loaded state and visible range,\n // while still allowing a later, deeper scroll to request the next page.\n if (lastTriggerKeyRef.current === triggerKey) {\n return;\n }\n\n lastTriggerKeyRef.current = triggerKey;\n onLoadMore();\n },\n [\n count,\n enabled,\n hasNextPage,\n isFetchingNextPage,\n loadMoreError,\n loadMoreThreshold,\n onLoadMore,\n resolvedLoadedCount,\n shouldLoadMore,\n ],\n );\n\n const virtualizer = useVirtualizer<HTMLDivElement, HTMLElement>({\n count,\n enabled,\n estimateSize: resolvedEstimateSize,\n getScrollElement: () => {\n return scrollElementRef.current;\n },\n initialRect: {\n height: DEFAULT_VIEWPORT_HEIGHT,\n width: 1024,\n },\n measureElement:\n dynamicRowHeight && !isFirefox\n ? (element) => {\n return element.getBoundingClientRect().height;\n }\n : undefined,\n onChange: (instance) => {\n maybeLoadMore(instance.getVirtualItems());\n },\n overscan,\n });\n\n const estimatedItemSize = Math.max(resolvedEstimateSize(0), 1);\n\n const getFallbackVirtualItems = useCallback(\n (scrollTop: number, viewportHeight: number): VirtualItem[] => {\n const fallbackStartIndex = Math.max(\n Math.floor(scrollTop / estimatedItemSize) - overscan,\n 0,\n );\n const fallbackEndIndex = Math.min(\n Math.ceil((scrollTop + viewportHeight) / estimatedItemSize) + overscan,\n count,\n );\n\n return Array.from(\n { length: Math.max(fallbackEndIndex - fallbackStartIndex, 0) },\n (_, offset) => {\n const index = fallbackStartIndex + offset;\n const size = resolvedEstimateSize(index);\n return {\n end: (index + 1) * estimatedItemSize,\n index,\n key: index,\n lane: 0,\n size,\n start: index * estimatedItemSize,\n };\n },\n );\n },\n [count, estimatedItemSize, overscan, resolvedEstimateSize],\n );\n\n useEffect(() => {\n const scrollElement = scrollElementRef.current;\n if (!scrollElement) {\n return undefined;\n }\n\n const syncFallbackRange = () => {\n const nextRange = {\n scrollTop: scrollElement.scrollTop,\n viewportHeight:\n scrollElement.clientHeight > 0\n ? scrollElement.clientHeight\n : DEFAULT_VIEWPORT_HEIGHT,\n };\n setFallbackRange((previousRange) => {\n if (\n previousRange.scrollTop === nextRange.scrollTop &&\n previousRange.viewportHeight === nextRange.viewportHeight\n ) {\n return previousRange;\n }\n return nextRange;\n });\n };\n\n syncFallbackRange();\n scrollElement.addEventListener('scroll', syncFallbackRange, {\n passive: true,\n });\n window.addEventListener('resize', syncFallbackRange);\n\n return () => {\n scrollElement.removeEventListener('scroll', syncFallbackRange);\n window.removeEventListener('resize', syncFallbackRange);\n };\n }, [scrollElementRef]);\n\n const virtualItems = virtualizer.getVirtualItems();\n const fallbackVirtualItems: VirtualItem[] =\n virtualItems.length === 0 && count > 0\n ? getFallbackVirtualItems(\n fallbackRange.scrollTop,\n fallbackRange.viewportHeight,\n )\n : [];\n const activeVirtualItems =\n virtualItems.length > 0 ? virtualItems : fallbackVirtualItems;\n const totalSize = Math.max(\n virtualizer.getTotalSize(),\n count * estimatedItemSize,\n );\n\n // Scroll events alone are not enough to drive loading: the first page may\n // not fill the container (no scroll possible) and appended pages can leave\n // the viewport still at the end. Re-check on every relevant state change.\n useEffect(() => {\n maybeLoadMore(activeVirtualItems);\n });\n\n const measureElement = useMemo(() => {\n if (!dynamicRowHeight || isFirefox) {\n return undefined;\n }\n return (node: HTMLElement | null) => {\n if (!node) {\n return;\n }\n virtualizer.measureElement(node);\n };\n }, [dynamicRowHeight, isFirefox, virtualizer]);\n\n const retry = useCallback(() => {\n if (!onLoadMore || isFetchingNextPage || !hasNextPage) {\n return;\n }\n onLoadMore();\n }, [hasNextPage, isFetchingNextPage, onLoadMore]);\n\n const scrollToTop = useCallback(() => {\n virtualizer.scrollToOffset(0);\n }, [virtualizer]);\n\n const scrollToIndex = useCallback(\n (index: number) => {\n virtualizer.scrollToIndex(index);\n },\n [virtualizer],\n );\n\n return {\n measureElement,\n retry,\n scrollElementRef,\n scrollToIndex,\n scrollToTop,\n totalSize,\n virtualItems: activeVirtualItems,\n virtualizer,\n };\n};\n\nexport default useInfiniteVirtualizer;\n"],"mappings":";;;AAgDA,MAAM,wBAAwB;AAC9B,MAAM,8BAA8B;AACpC,MAAM,mBAAmB;AACzB,MAAM,0BAA0B;;;;;;;;;;;;;;;;;;AAmBhC,MAAa,0BAA0B,EACrC,OACA,mBAAmB,OACnB,UAAU,MACV,cACA,cAAc,OACd,qBAAqB,OACrB,cAAc,KAAA,GACd,gBAAgB,OAChB,oBAAoB,6BACpB,aAAa,KAAA,GACb,WAAW,kBACX,kBAAkB,2BAA2B,KAAA,GAC7C,iBAAiB,KAAA,QACiB;CAClC,MAAM,wBAAwB,OAA8B,IAAI;CAChE,MAAM,mBAAmB,4BAA4B;CACrD,MAAM,oBAAoB,OAAsB,IAAI;CACpD,MAAM,sBAAsB,eAAe;CAC3C,MAAM,CAAC,eAAe,oBAAoB,SAAS;EACjD,WAAW;EACX,gBAAgB;CAClB,CAAC;CACD,MAAM,uBAAuB,cAAc;EACzC,OACE,uBACO;GACL,OAAO;EACT;CAEJ,GAAG,CAAC,YAAY,CAAC;CAEjB,MAAM,YACJ,OAAO,WAAW,eAElB,OAAO,UAAU,UAAU,SAAS,SAAS;CAE/C,MAAM,gBAAgB,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,CAAC;CAShB,OAAO;EACL;EACA;EACA;EACA,eAXoB,aACnB,UAAkB;GACjB,YAAY,cAAc,KAAK;EACjC,GACA,CAAC,WAAW,CAOA;EACZ;EACA;EACA,cAAc;EACd;CACF;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fuf-stack/megapixels",
3
- "version": "0.13.5",
3
+ "version": "0.14.0",
4
4
  "description": "fuf react advanced components library",
5
5
  "author": "Fröhlich ∧ Frei",
6
6
  "homepage": "https://github.com/fuf-stack/megapixels#readme",
@@ -15,6 +15,10 @@
15
15
  "import": "./dist/index.js",
16
16
  "require": "./dist/index.cjs"
17
17
  },
18
+ "./DataTable": {
19
+ "import": "./dist/DataTable/index.js",
20
+ "require": "./dist/DataTable/index.cjs"
21
+ },
18
22
  "./Filter": {
19
23
  "import": "./dist/Filter/index.js",
20
24
  "require": "./dist/Filter/index.cjs"
@@ -23,6 +27,10 @@
23
27
  "import": "./dist/Notification/index.js",
24
28
  "require": "./dist/Notification/index.cjs"
25
29
  },
30
+ "./VirtualList": {
31
+ "import": "./dist/VirtualList/index.js",
32
+ "require": "./dist/VirtualList/index.cjs"
33
+ },
26
34
  "./package.json": "./package.json"
27
35
  },
28
36
  "files": [
@@ -49,11 +57,14 @@
49
57
  "react-dom": ">=18"
50
58
  },
51
59
  "dependencies": {
60
+ "@base-ui/react": "1.6.0",
52
61
  "@fuf-stack/pixel-motion": "1.2.2",
53
62
  "@fuf-stack/pixel-utils": "1.3.2",
54
- "@fuf-stack/pixels": "1.11.8",
55
- "@fuf-stack/uniform": "1.24.8",
63
+ "@fuf-stack/pixels": "1.12.0",
64
+ "@fuf-stack/uniform": "1.24.9",
56
65
  "@fuf-stack/veto": "1.7.4",
66
+ "@tanstack/react-table": "8.21.3",
67
+ "@tanstack/react-virtual": "3.13.12",
57
68
  "debug": "4.4.3",
58
69
  "react-icons": "5.6.0"
59
70
  },
@@ -64,5 +75,5 @@
64
75
  "react": "19.2.7",
65
76
  "react-dom": "19.2.7"
66
77
  },
67
- "gitHead": "98307ad6973b2b81e98303c4d836de79b8523318"
78
+ "gitHead": "d2666b45323b5aee10cb98fefd6a0df7b2e8214e"
68
79
  }