next-data-kit 7.6.6 → 7.7.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/client/components/data-kit-infinity.d.ts +2 -7
- package/dist/client/components/data-kit-infinity.d.ts.map +1 -1
- package/dist/client/components/data-kit-infinity.js +18 -92
- package/dist/client/components/data-kit-infinity.js.map +1 -1
- package/dist/index.cjs +1 -228
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +3 -230
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/dist/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
2
|
import * as React2 from 'react';
|
|
3
3
|
import React2__default, { createContext, useRef, useState, useCallback, useEffect, useContext, useMemo } from 'react';
|
|
4
|
-
import { jsx, jsxs
|
|
5
|
-
import { Filter, Loader2, MoreHorizontal, ArrowUp, ArrowDown, ChevronLeft, ChevronRight,
|
|
4
|
+
import { jsx, jsxs } from 'react/jsx-runtime';
|
|
5
|
+
import { Filter, Loader2, MoreHorizontal, ArrowUp, ArrowDown, ChevronLeft, ChevronRight, ChevronDownIcon, CheckIcon, ChevronUpIcon } from 'lucide-react';
|
|
6
6
|
import * as CheckboxPrimitive from '@radix-ui/react-checkbox';
|
|
7
7
|
import * as PopoverPrimitive from '@radix-ui/react-popover';
|
|
8
8
|
import * as DropdownMenuPrimitive from '@radix-ui/react-dropdown-menu';
|
|
@@ -10,7 +10,7 @@ import * as SwitchPrimitive from '@radix-ui/react-switch';
|
|
|
10
10
|
import { Slot } from '@radix-ui/react-slot';
|
|
11
11
|
import { cva } from 'class-variance-authority';
|
|
12
12
|
import * as SelectPrimitive from '@radix-ui/react-select';
|
|
13
|
-
import
|
|
13
|
+
import 'react-intersection-observer';
|
|
14
14
|
|
|
15
15
|
// src/server/utils.ts
|
|
16
16
|
var isProvided = (value) => value !== void 0 && value !== null && value !== "";
|
|
@@ -1775,233 +1775,6 @@ var DataKitInner = (props, ref) => {
|
|
|
1775
1775
|
] });
|
|
1776
1776
|
};
|
|
1777
1777
|
var DataKit = React2__default.forwardRef(DataKitInner);
|
|
1778
|
-
var DataKitInfinityInner = (props, ref) => {
|
|
1779
|
-
const {
|
|
1780
|
-
action,
|
|
1781
|
-
query,
|
|
1782
|
-
filterConfig,
|
|
1783
|
-
filters = [],
|
|
1784
|
-
limit: limitConfig,
|
|
1785
|
-
defaultSort = [],
|
|
1786
|
-
className,
|
|
1787
|
-
autoFetch = true,
|
|
1788
|
-
debounce: debounce2 = 300,
|
|
1789
|
-
state: stateMode = "memory",
|
|
1790
|
-
inverse = false,
|
|
1791
|
-
manual = false,
|
|
1792
|
-
pullDownToRefresh,
|
|
1793
|
-
children
|
|
1794
|
-
} = props;
|
|
1795
|
-
const containerRef = useRef(null);
|
|
1796
|
-
const scrollContainerRef = useRef(null);
|
|
1797
|
-
const [allItems, setAllItems] = useState([]);
|
|
1798
|
-
const [isFilterOpen, setIsFilterOpen] = useState(false);
|
|
1799
|
-
const [isPullRefreshing, setIsPullRefreshing] = useState(false);
|
|
1800
|
-
const [pullStartY, setPullStartY] = useState(0);
|
|
1801
|
-
const [pullDistance, setPullDistance] = useState(0);
|
|
1802
|
-
const overlayContainer = containerRef.current;
|
|
1803
|
-
const pullThreshold = pullDownToRefresh?.threshold ?? 50;
|
|
1804
|
-
const dataKit = useDataKit({
|
|
1805
|
-
action,
|
|
1806
|
-
filterConfig,
|
|
1807
|
-
autoFetch: false,
|
|
1808
|
-
// We'll control fetching manually
|
|
1809
|
-
debounce: debounce2,
|
|
1810
|
-
state: stateMode,
|
|
1811
|
-
initial: {
|
|
1812
|
-
limit: limitConfig?.default ?? 10,
|
|
1813
|
-
query: query ?? {},
|
|
1814
|
-
sorts: defaultSort,
|
|
1815
|
-
filter: filters.reduce((acc, f) => {
|
|
1816
|
-
if (f.defaultValue !== void 0) acc[f.id] = f.defaultValue;
|
|
1817
|
-
return acc;
|
|
1818
|
-
}, {})
|
|
1819
|
-
}
|
|
1820
|
-
});
|
|
1821
|
-
const { ref: loadMoreBottomRef, inView: inViewBottom } = useInView({
|
|
1822
|
-
threshold: 0,
|
|
1823
|
-
rootMargin: "100px"
|
|
1824
|
-
});
|
|
1825
|
-
const { ref: loadMoreTopRef, inView: inViewTop } = useInView({
|
|
1826
|
-
threshold: 0,
|
|
1827
|
-
rootMargin: "100px"
|
|
1828
|
-
});
|
|
1829
|
-
React2__default.useImperativeHandle(ref, () => dataKit, [dataKit]);
|
|
1830
|
-
const handleResetFilters = useCallback(() => {
|
|
1831
|
-
filters.forEach((f) => {
|
|
1832
|
-
dataKit.actions.setFilter(f.id, f.defaultValue ?? (f.type === "BOOLEAN" ? false : ""));
|
|
1833
|
-
});
|
|
1834
|
-
}, [filters, dataKit.actions]);
|
|
1835
|
-
const loadMore = useCallback(async () => {
|
|
1836
|
-
if (dataKit.state.isLoading || !dataKit.state.hasNextPage) return;
|
|
1837
|
-
dataKit.actions.setPage(dataKit.page + 1);
|
|
1838
|
-
}, [dataKit]);
|
|
1839
|
-
const resetAndFetch = useCallback(async () => {
|
|
1840
|
-
setAllItems([]);
|
|
1841
|
-
dataKit.actions.setPage(1);
|
|
1842
|
-
await dataKit.actions.refresh();
|
|
1843
|
-
}, [dataKit.actions]);
|
|
1844
|
-
const handleTouchStart = useCallback((e) => {
|
|
1845
|
-
if (!pullDownToRefresh?.isActive) return;
|
|
1846
|
-
const scrollTop = scrollContainerRef.current?.scrollTop ?? 0;
|
|
1847
|
-
if (scrollTop === 0 && e.touches && e.touches[0]) {
|
|
1848
|
-
setPullStartY(e.touches[0].clientY);
|
|
1849
|
-
}
|
|
1850
|
-
}, [pullDownToRefresh?.isActive]);
|
|
1851
|
-
const handleTouchMove = useCallback((e) => {
|
|
1852
|
-
if (!pullDownToRefresh?.isActive || pullStartY === 0) return;
|
|
1853
|
-
if (!e.touches || !e.touches[0]) return;
|
|
1854
|
-
const scrollTop = scrollContainerRef.current?.scrollTop ?? 0;
|
|
1855
|
-
if (scrollTop === 0) {
|
|
1856
|
-
const distance = e.touches[0].clientY - pullStartY;
|
|
1857
|
-
if (distance > 0) {
|
|
1858
|
-
setPullDistance(Math.min(distance, pullThreshold * 2));
|
|
1859
|
-
if (distance > pullThreshold * 2) {
|
|
1860
|
-
e.preventDefault();
|
|
1861
|
-
}
|
|
1862
|
-
}
|
|
1863
|
-
}
|
|
1864
|
-
}, [pullDownToRefresh?.isActive, pullStartY, pullThreshold]);
|
|
1865
|
-
const handleTouchEnd = useCallback(async () => {
|
|
1866
|
-
if (!pullDownToRefresh?.isActive) return;
|
|
1867
|
-
if (pullDistance > pullThreshold) {
|
|
1868
|
-
setIsPullRefreshing(true);
|
|
1869
|
-
await resetAndFetch();
|
|
1870
|
-
setIsPullRefreshing(false);
|
|
1871
|
-
}
|
|
1872
|
-
setPullStartY(0);
|
|
1873
|
-
setPullDistance(0);
|
|
1874
|
-
}, [pullDownToRefresh?.isActive, pullDistance, pullThreshold, resetAndFetch]);
|
|
1875
|
-
useEffect(() => {
|
|
1876
|
-
if (!pullDownToRefresh?.isActive) return;
|
|
1877
|
-
const container = scrollContainerRef.current;
|
|
1878
|
-
if (!container) return;
|
|
1879
|
-
container.addEventListener("touchstart", handleTouchStart);
|
|
1880
|
-
container.addEventListener("touchmove", handleTouchMove, { passive: false });
|
|
1881
|
-
container.addEventListener("touchend", handleTouchEnd);
|
|
1882
|
-
return () => {
|
|
1883
|
-
container.removeEventListener("touchstart", handleTouchStart);
|
|
1884
|
-
container.removeEventListener("touchmove", handleTouchMove);
|
|
1885
|
-
container.removeEventListener("touchend", handleTouchEnd);
|
|
1886
|
-
};
|
|
1887
|
-
}, [pullDownToRefresh?.isActive, handleTouchStart, handleTouchMove, handleTouchEnd]);
|
|
1888
|
-
useEffect(() => {
|
|
1889
|
-
if (autoFetch && dataKit.page === 1 && allItems.length === 0) {
|
|
1890
|
-
dataKit.actions.refresh();
|
|
1891
|
-
}
|
|
1892
|
-
}, [autoFetch]);
|
|
1893
|
-
useEffect(() => {
|
|
1894
|
-
if (dataKit.items.length > 0) {
|
|
1895
|
-
setAllItems((prev) => {
|
|
1896
|
-
if (dataKit.page === 1) {
|
|
1897
|
-
return dataKit.items;
|
|
1898
|
-
}
|
|
1899
|
-
const newItems = dataKit.items.filter(
|
|
1900
|
-
(newItem) => !prev.some((existingItem) => existingItem.id === newItem.id)
|
|
1901
|
-
);
|
|
1902
|
-
return inverse ? [...newItems, ...prev] : [...prev, ...newItems];
|
|
1903
|
-
});
|
|
1904
|
-
}
|
|
1905
|
-
}, [dataKit.items, dataKit.page, inverse]);
|
|
1906
|
-
useEffect(() => {
|
|
1907
|
-
if (inViewBottom && !inverse) {
|
|
1908
|
-
loadMore();
|
|
1909
|
-
}
|
|
1910
|
-
}, [inViewBottom, inverse, loadMore]);
|
|
1911
|
-
useEffect(() => {
|
|
1912
|
-
if (inViewTop && inverse) {
|
|
1913
|
-
loadMore();
|
|
1914
|
-
}
|
|
1915
|
-
}, [inViewTop, inverse, loadMore]);
|
|
1916
|
-
const enhancedDataKit = {
|
|
1917
|
-
...dataKit,
|
|
1918
|
-
items: allItems
|
|
1919
|
-
};
|
|
1920
|
-
return /* @__PURE__ */ jsxs("div", { ref: containerRef, className: `flex flex-col ${className ?? ""}`, children: [
|
|
1921
|
-
/* @__PURE__ */ jsxs("div", { className: "mb-3 flex items-center justify-between gap-2", children: [
|
|
1922
|
-
/* @__PURE__ */ jsxs("div", { className: "flex items-center gap-2", children: [
|
|
1923
|
-
filters.length > 0 && /* @__PURE__ */ jsxs(Popover, { open: isFilterOpen, onOpenChange: setIsFilterOpen, children: [
|
|
1924
|
-
/* @__PURE__ */ jsx(PopoverTrigger, { asChild: true, children: /* @__PURE__ */ jsxs(Button, { variant: "outline", size: "sm", children: [
|
|
1925
|
-
/* @__PURE__ */ jsx(Filter, { className: "mr-1.5 size-4" }),
|
|
1926
|
-
"Filters"
|
|
1927
|
-
] }) }),
|
|
1928
|
-
/* @__PURE__ */ jsxs(PopoverContent, { align: "start", className: "w-80", container: overlayContainer, children: [
|
|
1929
|
-
/* @__PURE__ */ jsx("div", { className: "grid gap-3", children: filters.map((f) => /* @__PURE__ */ jsxs("div", { className: "grid gap-1.5", children: [
|
|
1930
|
-
/* @__PURE__ */ jsx("label", { className: "text-sm font-medium", children: f.label }),
|
|
1931
|
-
f.type === "TEXT" && /* @__PURE__ */ jsx(
|
|
1932
|
-
"input",
|
|
1933
|
-
{
|
|
1934
|
-
type: "text",
|
|
1935
|
-
className: "h-9 w-full rounded-md border bg-transparent px-3 text-sm outline-none focus:ring-2 focus:ring-ring",
|
|
1936
|
-
placeholder: f.placeholder,
|
|
1937
|
-
value: dataKit.filter[f.id] ?? "",
|
|
1938
|
-
onChange: (e) => dataKit.actions.setFilter(f.id, e.target.value)
|
|
1939
|
-
}
|
|
1940
|
-
),
|
|
1941
|
-
f.type === "SELECT" && /* @__PURE__ */ jsxs(
|
|
1942
|
-
Select,
|
|
1943
|
-
{
|
|
1944
|
-
value: String(dataKit.filter[f.id] || "__all__"),
|
|
1945
|
-
onValueChange: (v) => dataKit.actions.setFilter(f.id, v === "__all__" ? "" : v),
|
|
1946
|
-
children: [
|
|
1947
|
-
/* @__PURE__ */ jsx(SelectTrigger, { children: /* @__PURE__ */ jsx(SelectValue, {}) }),
|
|
1948
|
-
/* @__PURE__ */ jsxs(SelectContent, { container: overlayContainer, children: [
|
|
1949
|
-
/* @__PURE__ */ jsx(SelectItem, { value: "__all__", children: "All" }),
|
|
1950
|
-
f.dataset?.map((d) => /* @__PURE__ */ jsx(SelectItem, { value: d.id, children: d.label }, d.id))
|
|
1951
|
-
] })
|
|
1952
|
-
]
|
|
1953
|
-
}
|
|
1954
|
-
),
|
|
1955
|
-
f.type === "BOOLEAN" && /* @__PURE__ */ jsxs("div", { className: "flex items-center justify-between", children: [
|
|
1956
|
-
/* @__PURE__ */ jsx("span", { className: "text-sm text-muted-foreground", children: f.placeholder ?? "Enable" }),
|
|
1957
|
-
/* @__PURE__ */ jsx(
|
|
1958
|
-
Switch,
|
|
1959
|
-
{
|
|
1960
|
-
checked: Boolean(dataKit.filter[f.id]),
|
|
1961
|
-
onCheckedChange: (c) => dataKit.actions.setFilter(f.id, c)
|
|
1962
|
-
}
|
|
1963
|
-
)
|
|
1964
|
-
] })
|
|
1965
|
-
] }, f.id)) }),
|
|
1966
|
-
/* @__PURE__ */ jsxs("div", { className: "mt-4 flex justify-between border-t pt-3", children: [
|
|
1967
|
-
/* @__PURE__ */ jsx(Button, { variant: "outline", size: "sm", onClick: handleResetFilters, children: "Reset" }),
|
|
1968
|
-
/* @__PURE__ */ jsx(Button, { size: "sm", onClick: () => setIsFilterOpen(false), children: "Done" })
|
|
1969
|
-
] })
|
|
1970
|
-
] })
|
|
1971
|
-
] }),
|
|
1972
|
-
/* @__PURE__ */ jsxs(Button, { variant: "outline", size: "sm", onClick: resetAndFetch, disabled: dataKit.state.isLoading, children: [
|
|
1973
|
-
/* @__PURE__ */ jsx(RefreshCw, { className: `mr-1.5 size-4 ${dataKit.state.isLoading ? "animate-spin" : ""}` }),
|
|
1974
|
-
"Refresh"
|
|
1975
|
-
] })
|
|
1976
|
-
] }),
|
|
1977
|
-
/* @__PURE__ */ jsx("div", { className: "flex items-center gap-1", children: /* @__PURE__ */ jsxs("span", { className: "mr-2 text-sm text-muted-foreground", children: [
|
|
1978
|
-
allItems.length,
|
|
1979
|
-
" loaded"
|
|
1980
|
-
] }) })
|
|
1981
|
-
] }),
|
|
1982
|
-
/* @__PURE__ */ jsxs("div", { ref: scrollContainerRef, className: "relative flex-1 overflow-auto", children: [
|
|
1983
|
-
pullDownToRefresh?.isActive && pullDistance > 0 && /* @__PURE__ */ jsx(
|
|
1984
|
-
"div",
|
|
1985
|
-
{
|
|
1986
|
-
className: "absolute left-0 right-0 top-0 flex items-center justify-center bg-background/80 backdrop-blur-sm transition-all",
|
|
1987
|
-
style: { height: `${pullDistance}px` },
|
|
1988
|
-
children: pullDistance > pullThreshold ? /* @__PURE__ */ jsx(RefreshCw, { className: "size-5 text-primary" }) : /* @__PURE__ */ jsx("span", { className: "text-sm text-muted-foreground", children: "Pull to refresh" })
|
|
1989
|
-
}
|
|
1990
|
-
),
|
|
1991
|
-
!manual && isPullRefreshing && /* @__PURE__ */ jsx("div", { className: "flex items-center justify-center py-4", children: /* @__PURE__ */ jsx(Loader2, { className: "size-6 animate-spin text-muted-foreground" }) }),
|
|
1992
|
-
inverse && /* @__PURE__ */ jsx("div", { ref: loadMoreTopRef, className: manual ? "" : "flex items-center justify-center py-4", children: !manual && dataKit.state.hasNextPage && dataKit.state.isLoading && /* @__PURE__ */ jsx(Loader2, { className: "size-6 animate-spin text-muted-foreground" }) }),
|
|
1993
|
-
manual ? children(enhancedDataKit) : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1994
|
-
children(enhancedDataKit),
|
|
1995
|
-
!dataKit.state.isLoading && allItems.length === 0 && /* @__PURE__ */ jsx("div", { className: "flex h-48 items-center justify-center text-muted-foreground", children: "No results found." })
|
|
1996
|
-
] }),
|
|
1997
|
-
!inverse && /* @__PURE__ */ jsx("div", { ref: loadMoreBottomRef, className: manual ? "" : "flex items-center justify-center py-4", children: !manual && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1998
|
-
dataKit.state.isLoading && /* @__PURE__ */ jsx(Loader2, { className: "size-6 animate-spin text-muted-foreground" }),
|
|
1999
|
-
!dataKit.state.isLoading && !dataKit.state.hasNextPage && allItems.length > 0 && /* @__PURE__ */ jsx("p", { className: "text-sm text-muted-foreground", children: "You're all set" })
|
|
2000
|
-
] }) })
|
|
2001
|
-
] })
|
|
2002
|
-
] });
|
|
2003
|
-
};
|
|
2004
|
-
React2__default.forwardRef(DataKitInfinityInner);
|
|
2005
1778
|
|
|
2006
1779
|
export { DataKit, DefaultDataKitContext as DataKitContext, DefaultDataKitProvider as DataKitProvider, adapterMemory, calculatePagination, createDataKitContext, createSearchFilter, dataKitServerAction, debounce, escapeRegex, formatNumber, getColumnValue, getNextSortValue, getSortValue, keyToSortEntries, mongooseAdapter, sortEntriesToKey, throttle, useDataKit, useDefaultDataKitContext as useDataKitContext, usePagination, useSelection, useSelectionWithTotal };
|
|
2007
1780
|
//# sourceMappingURL=index.js.map
|