@pk-design/react-tailwind 1.1.6 → 1.1.7

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.
@@ -4,6 +4,7 @@ var jsxRuntime = require('react/jsx-runtime');
4
4
  var tailwindMerge = require('tailwind-merge');
5
5
  var React = require('react');
6
6
  var react = require('@headlessui/react');
7
+ var reactWindow = require('react-window');
7
8
 
8
9
  function _interopNamespaceDefault(e) {
9
10
  var n = Object.create(null);
@@ -1441,604 +1442,8 @@ const ToastProvider = ({ children, placement = 'top-center' }) => {
1441
1442
  return (jsxRuntime.jsxs(ToastContext.Provider, { value: { showToast, closeToast }, children: [children, jsxRuntime.jsx("div", { className: buildClassName('fixed z-50 flex flex-col gap-3 pointer-events-none', placementClass[placement]), children: toasts.map((toast, index) => (jsxRuntime.jsx("div", { className: "pointer-events-auto", onMouseEnter: () => toast.pauseOnHover && clearTimer(toast.id), onMouseLeave: () => toast.pauseOnHover && scheduleClose(toast), children: jsxRuntime.jsx(Toast, { ...toast, isTop: placement.startsWith('top'), onClose: () => closeToast(toast.id) }) }, toast.id))) })] }));
1442
1443
  };
1443
1444
 
1444
- const q = typeof window < "u" ? React.useLayoutEffect : React.useEffect;
1445
- function oe(e) {
1446
- if (e !== void 0)
1447
- switch (typeof e) {
1448
- case "number":
1449
- return e;
1450
- case "string": {
1451
- if (e.endsWith("px"))
1452
- return parseFloat(e);
1453
- break;
1454
- }
1455
- }
1456
- }
1457
- function Ie({
1458
- box: e,
1459
- defaultHeight: t,
1460
- defaultWidth: s,
1461
- disabled: r,
1462
- element: n,
1463
- mode: o,
1464
- style: i
1465
- }) {
1466
- const { styleHeight: f, styleWidth: l } = React.useMemo(
1467
- () => ({
1468
- styleHeight: oe(i?.height),
1469
- styleWidth: oe(i?.width)
1470
- }),
1471
- [i?.height, i?.width]
1472
- ), [c, d] = React.useState({
1473
- height: t,
1474
- width: s
1475
- }), a = r || f !== void 0 || o === "only-width" || f !== void 0 && l !== void 0;
1476
- return q(() => {
1477
- if (n === null || a)
1478
- return;
1479
- const u = new ResizeObserver((I) => {
1480
- for (const m of I) {
1481
- const { contentRect: b, target: g } = m;
1482
- n === g && d((w) => w.height === b.height && w.width === b.width ? w : {
1483
- height: b.height,
1484
- width: b.width
1485
- });
1486
- }
1487
- });
1488
- return u.observe(n, { box: e }), () => {
1489
- u?.unobserve(n);
1490
- };
1491
- }, [e, a, n, f, l]), React.useMemo(
1492
- () => ({
1493
- height: f ?? c.height,
1494
- width: l ?? c.width
1495
- }),
1496
- [c, f, l]
1497
- );
1498
- }
1499
- function ae(e) {
1500
- const t = React.useRef(() => {
1501
- throw new Error("Cannot call during render.");
1502
- });
1503
- return q(() => {
1504
- t.current = e;
1505
- }, [e]), React.useCallback((s) => t.current?.(s), [t]);
1506
- }
1507
- function Z({
1508
- containerElement: e,
1509
- direction: t,
1510
- isRtl: s,
1511
- scrollOffset: r
1512
- }) {
1513
- return r;
1514
- }
1515
- function $(e, t = "Assertion error") {
1516
- if (!e)
1517
- throw console.error(t), Error(t);
1518
- }
1519
- function Y(e, t) {
1520
- if (e === t)
1521
- return true;
1522
- if (!!e != !!t || ($(e !== void 0), $(t !== void 0), Object.keys(e).length !== Object.keys(t).length))
1523
- return false;
1524
- for (const s in e)
1525
- if (!Object.is(t[s], e[s]))
1526
- return false;
1527
- return true;
1528
- }
1529
- function fe({
1530
- cachedBounds: e,
1531
- itemCount: t,
1532
- itemSize: s
1533
- }) {
1534
- if (t === 0)
1535
- return 0;
1536
- if (typeof s == "number")
1537
- return t * s;
1538
- {
1539
- const r = e.get(
1540
- e.size === 0 ? 0 : e.size - 1
1541
- );
1542
- $(r !== void 0, "Unexpected bounds cache miss");
1543
- const n = (r.scrollOffset + r.size) / e.size;
1544
- return t * n;
1545
- }
1546
- }
1547
- function we({
1548
- align: e,
1549
- cachedBounds: t,
1550
- index: s,
1551
- itemCount: r,
1552
- itemSize: n,
1553
- containerScrollOffset: o,
1554
- containerSize: i
1555
- }) {
1556
- if (s < 0 || s >= r)
1557
- throw RangeError(`Invalid index specified: ${s}`, {
1558
- cause: `Index ${s} is not within the range of 0 - ${r - 1}`
1559
- });
1560
- const f = fe({
1561
- cachedBounds: t,
1562
- itemCount: r,
1563
- itemSize: n
1564
- }), l = t.get(s), c = Math.max(
1565
- 0,
1566
- Math.min(f - i, l.scrollOffset)
1567
- ), d = Math.max(
1568
- 0,
1569
- l.scrollOffset - i + l.size
1570
- );
1571
- switch (e === "smart" && (o >= d && o <= c ? e = "auto" : e = "center"), e) {
1572
- case "start":
1573
- return c;
1574
- case "end":
1575
- return d;
1576
- case "center":
1577
- return l.scrollOffset <= i / 2 ? 0 : l.scrollOffset + l.size / 2 >= f - i / 2 ? f - i : l.scrollOffset + l.size / 2 - i / 2;
1578
- case "auto":
1579
- default:
1580
- return o >= d && o <= c ? o : o < d ? d : c;
1581
- }
1582
- }
1583
- function ie({
1584
- cachedBounds: e,
1585
- containerScrollOffset: t,
1586
- containerSize: s,
1587
- itemCount: r,
1588
- overscanCount: n
1589
- }) {
1590
- const o = r - 1;
1591
- let i = 0, f = -1, l = 0, c = -1, d = 0;
1592
- for (; d < o; ) {
1593
- const a = e.get(d);
1594
- if (a.scrollOffset + a.size > t)
1595
- break;
1596
- d++;
1597
- }
1598
- for (i = d, l = Math.max(0, i - n); d < o; ) {
1599
- const a = e.get(d);
1600
- if (a.scrollOffset + a.size >= t + s)
1601
- break;
1602
- d++;
1603
- }
1604
- return f = Math.min(o, d), c = Math.min(r - 1, f + n), i < 0 && (i = 0, f = -1, l = 0, c = -1), {
1605
- startIndexVisible: i,
1606
- stopIndexVisible: f,
1607
- startIndexOverscan: l,
1608
- stopIndexOverscan: c
1609
- };
1610
- }
1611
- function me({
1612
- itemCount: e,
1613
- itemProps: t,
1614
- itemSize: s
1615
- }) {
1616
- const r = /* @__PURE__ */ new Map();
1617
- return {
1618
- get(n) {
1619
- for ($(n < e, `Invalid index ${n}`); r.size - 1 < n; ) {
1620
- const i = r.size;
1621
- let f;
1622
- switch (typeof s) {
1623
- case "function": {
1624
- f = s(i, t);
1625
- break;
1626
- }
1627
- case "number": {
1628
- f = s;
1629
- break;
1630
- }
1631
- }
1632
- if (i === 0)
1633
- r.set(i, {
1634
- size: f,
1635
- scrollOffset: 0
1636
- });
1637
- else {
1638
- const l = r.get(i - 1);
1639
- $(
1640
- l !== void 0,
1641
- `Unexpected bounds cache miss for index ${n}`
1642
- ), r.set(i, {
1643
- scrollOffset: l.scrollOffset + l.size,
1644
- size: f
1645
- });
1646
- }
1647
- }
1648
- const o = r.get(n);
1649
- return $(
1650
- o !== void 0,
1651
- `Unexpected bounds cache miss for index ${n}`
1652
- ), o;
1653
- },
1654
- set(n, o) {
1655
- r.set(n, o);
1656
- },
1657
- get size() {
1658
- return r.size;
1659
- }
1660
- };
1661
- }
1662
- function Oe({
1663
- itemCount: e,
1664
- itemProps: t,
1665
- itemSize: s
1666
- }) {
1667
- return React.useMemo(
1668
- () => me({
1669
- itemCount: e,
1670
- itemProps: t,
1671
- itemSize: s
1672
- }),
1673
- [e, t, s]
1674
- );
1675
- }
1676
- function ye({
1677
- containerSize: e,
1678
- itemSize: t
1679
- }) {
1680
- let s;
1681
- switch (typeof t) {
1682
- case "string": {
1683
- $(
1684
- t.endsWith("%"),
1685
- `Invalid item size: "${t}"; string values must be percentages (e.g. "100%")`
1686
- ), $(
1687
- e !== void 0,
1688
- "Container size must be defined if a percentage item size is specified"
1689
- ), s = e * parseInt(t) / 100;
1690
- break;
1691
- }
1692
- default: {
1693
- s = t;
1694
- break;
1695
- }
1696
- }
1697
- return s;
1698
- }
1699
- function ee({
1700
- containerElement: e,
1701
- containerStyle: t,
1702
- defaultContainerSize: s = 0,
1703
- direction: r,
1704
- isRtl: n = false,
1705
- itemCount: o,
1706
- itemProps: i,
1707
- itemSize: f,
1708
- onResize: l,
1709
- overscanCount: c
1710
- }) {
1711
- const [d, a] = React.useState({
1712
- startIndexVisible: 0,
1713
- startIndexOverscan: 0,
1714
- stopIndexVisible: -1,
1715
- stopIndexOverscan: -1
1716
- }), {
1717
- startIndexVisible: u,
1718
- startIndexOverscan: I,
1719
- stopIndexVisible: m,
1720
- stopIndexOverscan: b
1721
- } = {
1722
- startIndexVisible: Math.min(o - 1, d.startIndexVisible),
1723
- startIndexOverscan: Math.min(o - 1, d.startIndexOverscan),
1724
- stopIndexVisible: Math.min(o - 1, d.stopIndexVisible),
1725
- stopIndexOverscan: Math.min(o - 1, d.stopIndexOverscan)
1726
- }, { height: g = s, width: w = s } = Ie({
1727
- defaultHeight: s ,
1728
- defaultWidth: void 0,
1729
- element: e,
1730
- mode: "only-height" ,
1731
- style: t
1732
- }), y = React.useRef({
1733
- height: 0,
1734
- width: 0
1735
- }), V = g , h = ye({ containerSize: V, itemSize: f });
1736
- React.useLayoutEffect(() => {
1737
- if (typeof l == "function") {
1738
- const p = y.current;
1739
- (p.height !== g || p.width !== w) && (l({ height: g, width: w }, { ...p }), p.height = g, p.width = w);
1740
- }
1741
- }, [g, l, w]);
1742
- const z = Oe({
1743
- itemCount: o,
1744
- itemProps: i,
1745
- itemSize: h
1746
- }), k = React.useCallback(
1747
- (p) => z.get(p),
1748
- [z]
1749
- ), S = React.useCallback(
1750
- () => fe({
1751
- cachedBounds: z,
1752
- itemCount: o,
1753
- itemSize: h
1754
- }),
1755
- [z, o, h]
1756
- ), W = React.useCallback(
1757
- (p) => {
1758
- const T = Z({
1759
- containerElement: e,
1760
- direction: r,
1761
- isRtl: n,
1762
- scrollOffset: p
1763
- });
1764
- return ie({
1765
- cachedBounds: z,
1766
- containerScrollOffset: T,
1767
- containerSize: V,
1768
- itemCount: o,
1769
- overscanCount: c
1770
- });
1771
- },
1772
- [
1773
- z,
1774
- e,
1775
- V,
1776
- r,
1777
- n,
1778
- o,
1779
- c
1780
- ]
1781
- );
1782
- q(() => {
1783
- const p = (e?.scrollTop ) ?? 0;
1784
- a(W(p));
1785
- }, [e, r, W]), q(() => {
1786
- if (!e)
1787
- return;
1788
- const p = () => {
1789
- a((T) => {
1790
- const { scrollLeft: R, scrollTop: v } = e, x = Z({
1791
- containerElement: e,
1792
- direction: r,
1793
- isRtl: n,
1794
- scrollOffset: v
1795
- }), A = ie({
1796
- cachedBounds: z,
1797
- containerScrollOffset: x,
1798
- containerSize: V,
1799
- itemCount: o,
1800
- overscanCount: c
1801
- });
1802
- return Y(A, T) ? T : A;
1803
- });
1804
- };
1805
- return e.addEventListener("scroll", p), () => {
1806
- e.removeEventListener("scroll", p);
1807
- };
1808
- }, [
1809
- z,
1810
- e,
1811
- V,
1812
- r,
1813
- o,
1814
- c
1815
- ]);
1816
- const O = ae(
1817
- ({
1818
- align: p = "auto",
1819
- containerScrollOffset: T,
1820
- index: R
1821
- }) => {
1822
- let v = we({
1823
- align: p,
1824
- cachedBounds: z,
1825
- containerScrollOffset: T,
1826
- containerSize: V,
1827
- index: R,
1828
- itemCount: o,
1829
- itemSize: h
1830
- });
1831
- if (e) {
1832
- if (v = Z({
1833
- containerElement: e,
1834
- direction: r,
1835
- isRtl: n,
1836
- scrollOffset: v
1837
- }), typeof e.scrollTo != "function") {
1838
- const x = W(v);
1839
- Y(d, x) || a(x);
1840
- }
1841
- return v;
1842
- }
1843
- }
1844
- );
1845
- return {
1846
- getCellBounds: k,
1847
- getEstimatedSize: S,
1848
- scrollToIndex: O,
1849
- startIndexOverscan: I,
1850
- startIndexVisible: u,
1851
- stopIndexOverscan: b,
1852
- stopIndexVisible: m
1853
- };
1854
- }
1855
- function de(e) {
1856
- return React.useMemo(() => e, Object.values(e));
1857
- }
1858
- function ue(e, t) {
1859
- const {
1860
- ariaAttributes: s,
1861
- style: r,
1862
- ...n
1863
- } = e, {
1864
- ariaAttributes: o,
1865
- style: i,
1866
- ...f
1867
- } = t;
1868
- return Y(s, o) && Y(r, i) && Y(n, f);
1869
- }
1870
- function ze(e) {
1871
- return e != null && typeof e == "object" && "getAverageRowHeight" in e && typeof e.getAverageRowHeight == "function";
1872
- }
1873
- const te = "data-react-window-index";
1874
- function Ae({
1875
- children: e,
1876
- className: t,
1877
- defaultHeight: s = 0,
1878
- listRef: r,
1879
- onResize: n,
1880
- onRowsRendered: o,
1881
- overscanCount: i = 3,
1882
- rowComponent: f,
1883
- rowCount: l,
1884
- rowHeight: c,
1885
- rowProps: d,
1886
- tagName: a = "div",
1887
- style: u,
1888
- ...I
1889
- }) {
1890
- const m = de(d), b = React.useMemo(
1891
- () => React.memo(f, ue),
1892
- [f]
1893
- ), [g, w] = React.useState(null), y = ze(c), V = React.useMemo(() => y ? (v) => c.getRowHeight(v) ?? c.getAverageRowHeight() : c, [y, c]), {
1894
- getCellBounds: h,
1895
- getEstimatedSize: z,
1896
- scrollToIndex: k,
1897
- startIndexOverscan: S,
1898
- startIndexVisible: W,
1899
- stopIndexOverscan: O,
1900
- stopIndexVisible: p
1901
- } = ee({
1902
- containerElement: g,
1903
- containerStyle: u,
1904
- defaultContainerSize: s,
1905
- direction: "vertical",
1906
- itemCount: l,
1907
- itemProps: m,
1908
- itemSize: V,
1909
- onResize: n,
1910
- overscanCount: i
1911
- });
1912
- React.useImperativeHandle(
1913
- r,
1914
- () => ({
1915
- get element() {
1916
- return g;
1917
- },
1918
- scrollToRow({
1919
- align: v = "auto",
1920
- behavior: x = "auto",
1921
- index: A
1922
- }) {
1923
- const M = k({
1924
- align: v,
1925
- containerScrollOffset: g?.scrollTop ?? 0,
1926
- index: A
1927
- });
1928
- typeof g?.scrollTo == "function" && g.scrollTo({
1929
- behavior: x,
1930
- top: M
1931
- });
1932
- }
1933
- }),
1934
- [g, k]
1935
- ), q(() => {
1936
- if (!g)
1937
- return;
1938
- const v = Array.from(g.children).filter((x, A) => {
1939
- if (x.hasAttribute("aria-hidden"))
1940
- return false;
1941
- const M = `${S + A}`;
1942
- return x.setAttribute(te, M), true;
1943
- });
1944
- if (y)
1945
- return c.observeRowElements(v);
1946
- }, [
1947
- g,
1948
- y,
1949
- c,
1950
- S,
1951
- O
1952
- ]), React.useEffect(() => {
1953
- S >= 0 && O >= 0 && o && o(
1954
- {
1955
- startIndex: W,
1956
- stopIndex: p
1957
- },
1958
- {
1959
- startIndex: S,
1960
- stopIndex: O
1961
- }
1962
- );
1963
- }, [
1964
- o,
1965
- S,
1966
- W,
1967
- O,
1968
- p
1969
- ]);
1970
- const T = React.useMemo(() => {
1971
- const v = [];
1972
- if (l > 0)
1973
- for (let x = S; x <= O; x++) {
1974
- const A = h(x);
1975
- v.push(
1976
- /* @__PURE__ */ React.createElement(
1977
- b,
1978
- {
1979
- ...m,
1980
- ariaAttributes: {
1981
- "aria-posinset": x + 1,
1982
- "aria-setsize": l,
1983
- role: "listitem"
1984
- },
1985
- key: x,
1986
- index: x,
1987
- style: {
1988
- position: "absolute",
1989
- left: 0,
1990
- transform: `translateY(${A.scrollOffset}px)`,
1991
- // In case of dynamic row heights, don't specify a height style
1992
- // otherwise a default/estimated height would mask the actual height
1993
- height: y ? void 0 : A.size,
1994
- width: "100%"
1995
- }
1996
- }
1997
- )
1998
- );
1999
- }
2000
- return v;
2001
- }, [
2002
- b,
2003
- h,
2004
- y,
2005
- l,
2006
- m,
2007
- S,
2008
- O
2009
- ]), R = /* @__PURE__ */ jsxRuntime.jsx(
2010
- "div",
2011
- {
2012
- "aria-hidden": true,
2013
- style: {
2014
- height: z(),
2015
- width: "100%",
2016
- zIndex: -1
2017
- }
2018
- }
2019
- );
2020
- return React.createElement(
2021
- a,
2022
- {
2023
- role: "list",
2024
- ...I,
2025
- className: t,
2026
- ref: w,
2027
- style: {
2028
- position: "relative",
2029
- maxHeight: "100%",
2030
- flexGrow: 1,
2031
- overflowY: "auto",
2032
- ...u
2033
- }
2034
- },
2035
- T,
2036
- e,
2037
- R
2038
- );
2039
- }
2040
-
2041
- const VirtualizedRow = ({ index, style, items, columns, gridTemplate, }) => {
1445
+ const VirtualizedRow = ({ index, style, data }) => {
1446
+ const { items, columns, gridTemplate } = data;
2042
1447
  const item = items[index];
2043
1448
  return (jsxRuntime.jsx("div", { role: "row", className: "grid border-b border-gray-200 dark:border-gray-700 bg-white dark:bg-gray-900 group", style: {
2044
1449
  ...style,
@@ -2060,14 +1465,21 @@ const VirtualizedRow = ({ index, style, items, columns, gridTemplate, }) => {
2060
1465
  const useGridTemplate = (columns) => React.useMemo(() => columns.map((col) => (col.width ? `${col.width}px` : '1fr')).join(' '), [columns]);
2061
1466
  const VirtualizedDataTable = ({ items, columns, sorting = {}, onSort, loading = false, emptyMessage = 'No data available', containerClass = '', wrapperClass = '', rowHeight = 48, maxHeight = 400, }) => {
2062
1467
  const scrollRef = React.useRef(null);
1468
+ const outerRef = React.useRef(null);
2063
1469
  const headerRef = React.useRef(null);
2064
1470
  const gridTemplate = useGridTemplate(columns);
2065
- /** Sync body → header scroll */
2066
- const handleScrollSync = (scrollOffset) => {
2067
- if (headerRef.current) {
2068
- headerRef.current.scrollLeft = scrollOffset;
2069
- }
2070
- };
1471
+ /** Sync horizontal scroll of the virtualized body → header */
1472
+ React.useEffect(() => {
1473
+ const el = outerRef.current;
1474
+ if (!el)
1475
+ return;
1476
+ const handler = () => {
1477
+ if (headerRef.current)
1478
+ headerRef.current.scrollLeft = el.scrollLeft;
1479
+ };
1480
+ el.addEventListener('scroll', handler);
1481
+ return () => el.removeEventListener('scroll', handler);
1482
+ }, []);
2071
1483
  const handleSort = React.useCallback((column) => {
2072
1484
  if (column.sortable)
2073
1485
  onSort === null || onSort === void 0 ? void 0 : onSort(column);
@@ -2099,11 +1511,7 @@ const VirtualizedDataTable = ({ items, columns, sorting = {}, onSort, loading =
2099
1511
  /* -------------------------------------------------------
2100
1512
  * MAIN (virtualized body)
2101
1513
  * ------------------------------------------------------- */
2102
- return (jsxRuntime.jsx("div", { className: buildClassName('w-full rounded-lg relative', containerClass), children: jsxRuntime.jsxs("div", { className: buildClassName('rounded-lg border border-gray-200 dark:border-gray-800 overflow-hidden', wrapperClass), children: [Header, jsxRuntime.jsx("div", { style: {
2103
- height: maxHeight,
2104
- overflowY: 'auto',
2105
- overflowX: 'auto',
2106
- }, children: jsxRuntime.jsx(Ae, { listRef: scrollRef, rowComponent: VirtualizedRow, rowCount: items.length, rowHeight: rowHeight, rowProps: { items, columns, gridTemplate }, onScroll: (e) => handleScrollSync(e.currentTarget.scrollLeft) }) })] }) }));
1514
+ return (jsxRuntime.jsx("div", { className: buildClassName('w-full rounded-lg relative', containerClass), children: jsxRuntime.jsxs("div", { className: buildClassName('rounded-lg border border-gray-200 dark:border-gray-800 overflow-hidden', wrapperClass), children: [Header, jsxRuntime.jsx(reactWindow.FixedSizeList, { ref: scrollRef, outerRef: outerRef, height: maxHeight, width: "100%", itemCount: items.length, itemSize: rowHeight, itemData: { items, columns, gridTemplate }, children: VirtualizedRow })] }) }));
2107
1515
  };
2108
1516
 
2109
1517
  const useIsMobile = () => {