@fuf-stack/megapixels 0.14.4 → 0.16.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 (66) hide show
  1. package/dist/DataTable/{index.d.cts → index.d.mts} +1 -1
  2. package/dist/DataTable/{index.js → index.mjs} +1 -1
  3. package/dist/{DataTable-BVFkEua6.js → DataTable-Dxha1_X9.mjs} +2 -2
  4. package/dist/DataTable-Dxha1_X9.mjs.map +1 -0
  5. package/dist/Filter/{index.d.cts → index.d.mts} +1 -1
  6. package/dist/Filter/{index.js → index.mjs} +1 -1
  7. package/dist/{Filter-DNfu6KwS.js → Filter-DASemVam.mjs} +7 -4
  8. package/dist/Filter-DASemVam.mjs.map +1 -0
  9. package/dist/Notification/{index.d.cts → index.d.mts} +1 -1
  10. package/dist/Notification/{index.js → index.mjs} +1 -1
  11. package/dist/{Notification-Bgw2MtBQ.js → Notification-Bgw2MtBQ.mjs} +1 -1
  12. package/dist/Notification-Bgw2MtBQ.mjs.map +1 -0
  13. package/dist/VirtualList/{index.d.cts → index.d.mts} +1 -1
  14. package/dist/VirtualList/{index.js → index.mjs} +1 -1
  15. package/dist/{VirtualList-C4ylipy_.js → VirtualList-BRWFBEWK.mjs} +2 -2
  16. package/dist/VirtualList-BRWFBEWK.mjs.map +1 -0
  17. package/dist/{index-oeUH2qWd.d.ts → index-C8qpzima.d.mts} +4 -6
  18. package/dist/index-C8qpzima.d.mts.map +1 -0
  19. package/dist/{index-DCiYTnRL.d.ts → index-CWO6WrN7.d.mts} +490 -493
  20. package/dist/index-CWO6WrN7.d.mts.map +1 -0
  21. package/dist/{index-CzUDgCXS.d.cts → index-CeBjB8ML.d.mts} +1363 -1366
  22. package/dist/{index-SE4suk-2.d.ts.map → index-CeBjB8ML.d.mts.map} +1 -1
  23. package/dist/{index-DTHVZwVC.d.cts → index-DsTgtkjk.d.mts} +292 -302
  24. package/dist/index-DsTgtkjk.d.mts.map +1 -0
  25. package/dist/{index.d.cts → index.d.mts} +4 -4
  26. package/dist/{index.js → index.mjs} +5 -5
  27. package/dist/{index.cjs.map → index.mjs.map} +1 -1
  28. package/dist/{useInfiniteVirtualizer-BBgVBqJa.js → useInfiniteVirtualizer-BBgVBqJa.mjs} +1 -1
  29. package/dist/{useInfiniteVirtualizer-vIWKOBNt.cjs.map → useInfiniteVirtualizer-BBgVBqJa.mjs.map} +1 -1
  30. package/package.json +17 -34
  31. package/dist/DataTable/index.cjs +0 -8
  32. package/dist/DataTable/index.d.ts +0 -2
  33. package/dist/DataTable-BVFkEua6.js.map +0 -1
  34. package/dist/DataTable-CDKQh9m0.cjs +0 -1162
  35. package/dist/DataTable-CDKQh9m0.cjs.map +0 -1
  36. package/dist/Filter/index.cjs +0 -9
  37. package/dist/Filter/index.d.ts +0 -2
  38. package/dist/Filter-DNfu6KwS.js.map +0 -1
  39. package/dist/Filter-DvKXl2aZ.cjs +0 -791
  40. package/dist/Filter-DvKXl2aZ.cjs.map +0 -1
  41. package/dist/Notification/index.cjs +0 -8
  42. package/dist/Notification/index.d.ts +0 -2
  43. package/dist/Notification-Bg3_1P1x.cjs +0 -154
  44. package/dist/Notification-Bg3_1P1x.cjs.map +0 -1
  45. package/dist/Notification-Bgw2MtBQ.js.map +0 -1
  46. package/dist/VirtualList/index.cjs +0 -8
  47. package/dist/VirtualList/index.d.ts +0 -2
  48. package/dist/VirtualList-C4ylipy_.js.map +0 -1
  49. package/dist/VirtualList-CmG2C3B2.cjs +0 -170
  50. package/dist/VirtualList-CmG2C3B2.cjs.map +0 -1
  51. package/dist/index-CzUDgCXS.d.cts.map +0 -1
  52. package/dist/index-DCiYTnRL.d.ts.map +0 -1
  53. package/dist/index-DTHVZwVC.d.cts.map +0 -1
  54. package/dist/index-Ds212A8D.d.ts +0 -1141
  55. package/dist/index-Ds212A8D.d.ts.map +0 -1
  56. package/dist/index-FDKfDW98.d.cts +0 -2070
  57. package/dist/index-FDKfDW98.d.cts.map +0 -1
  58. package/dist/index-SE4suk-2.d.ts +0 -5192
  59. package/dist/index-oeUH2qWd.d.cts +0 -103
  60. package/dist/index-oeUH2qWd.d.cts.map +0 -1
  61. package/dist/index-oeUH2qWd.d.ts.map +0 -1
  62. package/dist/index.cjs +0 -19
  63. package/dist/index.d.ts +0 -5
  64. package/dist/index.js.map +0 -1
  65. package/dist/useInfiniteVirtualizer-BBgVBqJa.js.map +0 -1
  66. package/dist/useInfiniteVirtualizer-vIWKOBNt.cjs +0 -176
@@ -1,103 +0,0 @@
1
- import { ReactNode } from "react";
2
- import { ModalStoreApi } from "@fuf-stack/pixels/Modal";
3
- import { ToastOptions } from "@fuf-stack/pixels/Toast";
4
-
5
- //#region src/Notification/notification.d.ts
6
- /**
7
- * Props passed to function-based render props on a notification (e.g.
8
- * `endContent`), exposing helpers usable while rendering.
9
- */
10
- interface NotificationRenderProps {
11
- /** Closes the notification this render function belongs to. */
12
- closeNotification: () => void;
13
- /** Imperative modal API for opening/closing a modal from a notification. */
14
- modal: ModalStoreApi;
15
- }
16
- /** Options accepted by every `notification.<variant>()` call */
17
- interface NotificationOptions extends Omit<ToastOptions, 'endContent'> {
18
- /**
19
- * The notification's end content. Either a node rendered directly, or a
20
- * render function that receives the {@link NotificationRenderProps} (incl. a
21
- * `modal` API to open a modal) and returns the node to render.
22
- */
23
- endContent?: ReactNode | ((props: NotificationRenderProps) => ReactNode);
24
- }
25
- /**
26
- * Imperative API for showing notifications: `default` / `info` / `warn` /
27
- * `success` / `error` show a notification (each returns an id), and `close`
28
- * dismisses one by id.
29
- *
30
- * Besides a plain node, `endContent` may be a render function that receives
31
- * the {@link NotificationRenderProps} — including a `modal` API and a
32
- * `closeNotification` helper that dismisses this notification — and returns
33
- * the node to render, e.g. to open a modal showing details that do not fit
34
- * into the notification itself.
35
- *
36
- * Requires a `<NotificationHost />` to be mounted in the React tree.
37
- *
38
- * @example
39
- * ```tsx
40
- * notification.error('A request failed.', {
41
- * title: 'Request failed',
42
- * endContent: ({ modal, closeNotification }) => (
43
- * <>
44
- * <Button onClick={() => modal.open({ content: details })}>More</Button>
45
- * <Button onClick={closeNotification}>Dismiss</Button>
46
- * </>
47
- * ),
48
- * });
49
- * ```
50
- */
51
- declare const notification: {
52
- /**
53
- * Show a default notification.
54
- * @returns The toast id which can be passed to `notification.close()`
55
- */
56
- default: (message: ReactNode, options?: NotificationOptions) => string | number;
57
- /**
58
- * Show an info notification.
59
- * @returns The toast id which can be passed to `notification.close()`
60
- */
61
- info: (message: ReactNode, options?: NotificationOptions) => string | number;
62
- /**
63
- * Show a warning notification.
64
- * @returns The toast id which can be passed to `notification.close()`
65
- */
66
- warn: (message: ReactNode, options?: NotificationOptions) => string | number;
67
- /**
68
- * Show a success notification.
69
- * @returns The toast id which can be passed to `notification.close()`
70
- */
71
- success: (message: ReactNode, options?: NotificationOptions) => string | number;
72
- /**
73
- * Show an error notification.
74
- * @returns The toast id which can be passed to `notification.close()`
75
- */
76
- error: (message: ReactNode, options?: NotificationOptions) => string | number; /** Close a notification by its id */
77
- close: (id: string | number) => void;
78
- };
79
- //#endregion
80
- //#region src/Notification/NotificationHost.d.ts
81
- interface NotificationHostProps {
82
- /**
83
- * Width applied to all toasts. A number is treated as pixels; a string is
84
- * used verbatim (e.g. `'600px'`, `'40rem'`). Sets Sonner's `--width` CSS
85
- * variable on the Toaster.
86
- */
87
- width?: number | string;
88
- }
89
- /**
90
- * Mounts the Toaster and ModalHost.
91
- *
92
- * Use once at the top level of your app:
93
- *
94
- * ```tsx
95
- * <NotificationHost />
96
- * ```
97
- */
98
- declare const NotificationHost: ({
99
- width
100
- }: NotificationHostProps) => import("react").JSX.Element;
101
- //#endregion
102
- export { notification as a, NotificationRenderProps as i, NotificationHostProps as n, NotificationOptions as r, NotificationHost as t };
103
- //# sourceMappingURL=index-oeUH2qWd.d.cts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index-oeUH2qWd.d.cts","names":[],"sources":["../src/Notification/notification.tsx","../src/Notification/NotificationHost.tsx"],"mappings":";;;;;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B;;;;mBAAA,SAAA,EAAS,OAAA,GAAY,mBAAA;;;;;UClJvB,qBAAA;;;;;ADMjB;ECAE,KAAK;AAAA;;;;;;ADIe;AAItB;;;cCIM,gBAAA;EAAoB;AAAA,GAAiB,qBAAqB,qBAAA,GAAA,CAAA,OAAA"}
package/dist/index.cjs DELETED
@@ -1,19 +0,0 @@
1
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_Filter = require("./Filter-DvKXl2aZ.cjs");
3
- const require_DataTable = require("./DataTable-CDKQh9m0.cjs");
4
- const require_Notification = require("./Notification-Bg3_1P1x.cjs");
5
- const require_VirtualList = require("./VirtualList-CmG2C3B2.cjs");
6
- //#region src/index.ts
7
- /* v8 ignore stop */
8
- //#endregion
9
- exports.DataTable = require_DataTable.DataTable;
10
- exports.NotificationHost = require_Notification.NotificationHost;
11
- exports.VirtualList = require_VirtualList.VirtualList;
12
- exports.createFilter = require_Filter.createFilter;
13
- exports.dataTableVariants = require_DataTable.dataTableVariants;
14
- exports.filterVariants = require_Filter.filterVariants;
15
- exports.filters = require_Filter.filters;
16
- exports.notification = require_Notification.notification;
17
- exports.virtualListVariants = require_VirtualList.virtualListVariants;
18
-
19
- //# sourceMappingURL=index.cjs.map
package/dist/index.d.ts DELETED
@@ -1,5 +0,0 @@
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-SE4suk-2.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";
3
- import { a as notification, i as NotificationRenderProps, n as NotificationHostProps, r as NotificationOptions, t as NotificationHost } from "./index-oeUH2qWd.js";
4
- import { n as VirtualListProps, r as virtualListVariants, t as VirtualList } from "./index-Ds212A8D.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.map DELETED
@@ -1 +0,0 @@
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":""}
@@ -1 +0,0 @@
1
- {"version":3,"file":"useInfiniteVirtualizer-BBgVBqJa.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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AI;EACjC;CACF,GAAG;EAAC;EAAkB;EAAW;CAAW,CAAC;CAE7C,MAAM,QAAQ,kBAAkB;EAC9B,IAAI,CAAC,cAAc,sBAAsB,CAAC,aACxC;EAEF,WAAW;CACb,GAAG;EAAC;EAAa;EAAoB;CAAU,CAAC;CAEhD,MAAM,cAAc,kBAAkB;EACpC,YAAY,eAAe,CAAC;CAC9B,GAAG,CAAC,WAAW,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"}
@@ -1,176 +0,0 @@
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 lastVisibleIndex = virtualItems[virtualItems.length - 1]?.index ?? -1;
49
- const triggerKey = `${resolvedLoadedCount}:${lastVisibleIndex}`;
50
- if (lastTriggerKeyRef.current === triggerKey) return;
51
- lastTriggerKeyRef.current = triggerKey;
52
- onLoadMore();
53
- }, [
54
- count,
55
- enabled,
56
- hasNextPage,
57
- isFetchingNextPage,
58
- loadMoreError,
59
- loadMoreThreshold,
60
- onLoadMore,
61
- resolvedLoadedCount,
62
- shouldLoadMore
63
- ]);
64
- const virtualizer = (0, _tanstack_react_virtual.useVirtualizer)({
65
- count,
66
- enabled,
67
- estimateSize: resolvedEstimateSize,
68
- getScrollElement: () => {
69
- return scrollElementRef.current;
70
- },
71
- initialRect: {
72
- height: DEFAULT_VIEWPORT_HEIGHT,
73
- width: 1024
74
- },
75
- measureElement: dynamicRowHeight && !isFirefox ? (element) => {
76
- return element.getBoundingClientRect().height;
77
- } : void 0,
78
- onChange: (instance) => {
79
- maybeLoadMore(instance.getVirtualItems());
80
- },
81
- overscan
82
- });
83
- const estimatedItemSize = Math.max(resolvedEstimateSize(0), 1);
84
- const getFallbackVirtualItems = (0, react.useCallback)((scrollTop, viewportHeight) => {
85
- const fallbackStartIndex = Math.max(Math.floor(scrollTop / estimatedItemSize) - overscan, 0);
86
- const fallbackEndIndex = Math.min(Math.ceil((scrollTop + viewportHeight) / estimatedItemSize) + overscan, count);
87
- return Array.from({ length: Math.max(fallbackEndIndex - fallbackStartIndex, 0) }, (_, offset) => {
88
- const index = fallbackStartIndex + offset;
89
- const size = resolvedEstimateSize(index);
90
- return {
91
- end: (index + 1) * estimatedItemSize,
92
- index,
93
- key: index,
94
- lane: 0,
95
- size,
96
- start: index * estimatedItemSize
97
- };
98
- });
99
- }, [
100
- count,
101
- estimatedItemSize,
102
- overscan,
103
- resolvedEstimateSize
104
- ]);
105
- (0, react.useEffect)(() => {
106
- const scrollElement = scrollElementRef.current;
107
- if (!scrollElement) return;
108
- const syncFallbackRange = () => {
109
- const nextRange = {
110
- scrollTop: scrollElement.scrollTop,
111
- viewportHeight: scrollElement.clientHeight > 0 ? scrollElement.clientHeight : DEFAULT_VIEWPORT_HEIGHT
112
- };
113
- setFallbackRange((previousRange) => {
114
- if (previousRange.scrollTop === nextRange.scrollTop && previousRange.viewportHeight === nextRange.viewportHeight) return previousRange;
115
- return nextRange;
116
- });
117
- };
118
- syncFallbackRange();
119
- scrollElement.addEventListener("scroll", syncFallbackRange, { passive: true });
120
- window.addEventListener("resize", syncFallbackRange);
121
- return () => {
122
- scrollElement.removeEventListener("scroll", syncFallbackRange);
123
- window.removeEventListener("resize", syncFallbackRange);
124
- };
125
- }, [scrollElementRef]);
126
- const virtualItems = virtualizer.getVirtualItems();
127
- const fallbackVirtualItems = virtualItems.length === 0 && count > 0 ? getFallbackVirtualItems(fallbackRange.scrollTop, fallbackRange.viewportHeight) : [];
128
- const activeVirtualItems = virtualItems.length > 0 ? virtualItems : fallbackVirtualItems;
129
- const totalSize = Math.max(virtualizer.getTotalSize(), count * estimatedItemSize);
130
- (0, react.useEffect)(() => {
131
- maybeLoadMore(activeVirtualItems);
132
- });
133
- const measureElement = (0, react.useMemo)(() => {
134
- if (!dynamicRowHeight || isFirefox) return;
135
- return (node) => {
136
- if (!node) return;
137
- virtualizer.measureElement(node);
138
- };
139
- }, [
140
- dynamicRowHeight,
141
- isFirefox,
142
- virtualizer
143
- ]);
144
- const retry = (0, react.useCallback)(() => {
145
- if (!onLoadMore || isFetchingNextPage || !hasNextPage) return;
146
- onLoadMore();
147
- }, [
148
- hasNextPage,
149
- isFetchingNextPage,
150
- onLoadMore
151
- ]);
152
- const scrollToTop = (0, react.useCallback)(() => {
153
- virtualizer.scrollToOffset(0);
154
- }, [virtualizer]);
155
- return {
156
- measureElement,
157
- retry,
158
- scrollElementRef,
159
- scrollToIndex: (0, react.useCallback)((index) => {
160
- virtualizer.scrollToIndex(index);
161
- }, [virtualizer]),
162
- scrollToTop,
163
- totalSize,
164
- virtualItems: activeVirtualItems,
165
- virtualizer
166
- };
167
- };
168
- //#endregion
169
- Object.defineProperty(exports, "useInfiniteVirtualizer", {
170
- enumerable: true,
171
- get: function() {
172
- return useInfiniteVirtualizer;
173
- }
174
- });
175
-
176
- //# sourceMappingURL=useInfiniteVirtualizer-vIWKOBNt.cjs.map