@smallwebco/tinypivot-react 1.0.12 → 1.0.14

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/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  // src/components/DataGrid.tsx
2
- import { useState as useState8, useMemo as useMemo8, useCallback as useCallback8, useEffect as useEffect3, useRef as useRef2 } from "react";
2
+ import { useState as useState8, useMemo as useMemo8, useCallback as useCallback8, useEffect as useEffect4, useRef as useRef2 } from "react";
3
3
  import { createPortal } from "react-dom";
4
4
 
5
5
  // src/hooks/useExcelGrid.ts
6
- import { useState, useMemo, useCallback } from "react";
6
+ import { useState, useMemo, useCallback, useEffect } from "react";
7
7
  import {
8
8
  useReactTable,
9
9
  getCoreRowModel,
@@ -26,13 +26,17 @@ function useExcelGrid(options) {
26
26
  const [columnVisibility, setColumnVisibility] = useState({});
27
27
  const [globalFilter, setGlobalFilter] = useState("");
28
28
  const [columnStatsCache, setColumnStatsCache] = useState({});
29
+ const dataSignature = useMemo(
30
+ () => `${Date.now()}-${Math.random().toString(36).slice(2)}`,
31
+ [data]
32
+ );
29
33
  const columnKeys = useMemo(() => {
30
34
  if (data.length === 0) return [];
31
35
  return Object.keys(data[0]);
32
36
  }, [data]);
33
37
  const getColumnStats = useCallback(
34
38
  (columnKey) => {
35
- const cacheKey = `${columnKey}-${data.length}`;
39
+ const cacheKey = `${columnKey}-${dataSignature}`;
36
40
  if (!columnStatsCache[cacheKey]) {
37
41
  const stats = getColumnUniqueValues(data, columnKey);
38
42
  setColumnStatsCache((prev) => ({ ...prev, [cacheKey]: stats }));
@@ -40,11 +44,14 @@ function useExcelGrid(options) {
40
44
  }
41
45
  return columnStatsCache[cacheKey];
42
46
  },
43
- [data, columnStatsCache]
47
+ [data, columnStatsCache, dataSignature]
44
48
  );
45
49
  const clearStatsCache = useCallback(() => {
46
50
  setColumnStatsCache({});
47
51
  }, []);
52
+ useEffect(() => {
53
+ clearStatsCache();
54
+ }, [dataSignature, clearStatsCache]);
48
55
  const columnDefs = useMemo(() => {
49
56
  return columnKeys.map((key) => {
50
57
  const stats = getColumnStats(key);
@@ -105,7 +112,6 @@ function useExcelGrid(options) {
105
112
  const column = table.getColumn(columnId);
106
113
  if (column) {
107
114
  column.setFilterValue(values.length === 0 ? void 0 : values);
108
- setColumnFilters(table.getState().columnFilters);
109
115
  }
110
116
  },
111
117
  [table]
@@ -173,7 +179,7 @@ function useExcelGrid(options) {
173
179
  }
174
180
 
175
181
  // src/hooks/usePivotTable.ts
176
- import { useState as useState3, useMemo as useMemo3, useEffect, useCallback as useCallback3 } from "react";
182
+ import { useState as useState3, useMemo as useMemo3, useEffect as useEffect2, useCallback as useCallback3 } from "react";
177
183
  import {
178
184
  computeAvailableFields,
179
185
  getUnassignedFields,
@@ -305,7 +311,7 @@ function usePivotTable(data) {
305
311
  showColumnTotals
306
312
  });
307
313
  }, [data, isConfigured, canUsePivot, rowFields, columnFields, valueFields, showRowTotals, showColumnTotals]);
308
- useEffect(() => {
314
+ useEffect2(() => {
309
315
  if (data.length === 0) return;
310
316
  const newKeys = Object.keys(data[0]);
311
317
  const storageKey = generateStorageKey(newKeys);
@@ -334,7 +340,7 @@ function usePivotTable(data) {
334
340
  }
335
341
  }
336
342
  }, [data]);
337
- useEffect(() => {
343
+ useEffect2(() => {
338
344
  if (!currentStorageKey) return;
339
345
  const config = {
340
346
  rowFields,
@@ -694,7 +700,7 @@ function useColumnResize(initialWidths, minWidth = 60, maxWidth = 600) {
694
700
  }
695
701
 
696
702
  // src/components/ColumnFilter.tsx
697
- import { useState as useState5, useEffect as useEffect2, useRef, useCallback as useCallback5, useMemo as useMemo5 } from "react";
703
+ import { useState as useState5, useEffect as useEffect3, useRef, useCallback as useCallback5, useMemo as useMemo5 } from "react";
698
704
  import { jsx, jsxs } from "react/jsx-runtime";
699
705
  function ColumnFilter({
700
706
  columnName,
@@ -769,7 +775,7 @@ function ColumnFilter({
769
775
  onFilter([]);
770
776
  onClose();
771
777
  }, [onFilter, onClose]);
772
- useEffect2(() => {
778
+ useEffect3(() => {
773
779
  const handleClickOutside = (event) => {
774
780
  if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
775
781
  onClose();
@@ -778,7 +784,7 @@ function ColumnFilter({
778
784
  document.addEventListener("mousedown", handleClickOutside);
779
785
  return () => document.removeEventListener("mousedown", handleClickOutside);
780
786
  }, [onClose]);
781
- useEffect2(() => {
787
+ useEffect3(() => {
782
788
  const handleKeydown = (event) => {
783
789
  if (event.key === "Escape") {
784
790
  onClose();
@@ -789,10 +795,10 @@ function ColumnFilter({
789
795
  document.addEventListener("keydown", handleKeydown);
790
796
  return () => document.removeEventListener("keydown", handleKeydown);
791
797
  }, [onClose, applyFilter]);
792
- useEffect2(() => {
798
+ useEffect3(() => {
793
799
  searchInputRef.current?.focus();
794
800
  }, []);
795
- useEffect2(() => {
801
+ useEffect3(() => {
796
802
  setLocalSelected(new Set(selectedValues));
797
803
  }, [selectedValues]);
798
804
  return /* @__PURE__ */ jsxs("div", { ref: dropdownRef, className: "vpg-filter-dropdown", children: [
@@ -1887,6 +1893,9 @@ function DataGrid({
1887
1893
  const end = start + pageSize;
1888
1894
  return searchFilteredData.slice(start, end);
1889
1895
  }, [enablePagination, searchFilteredData, currentPage, pageSize]);
1896
+ useEffect4(() => {
1897
+ setCurrentPage(1);
1898
+ }, [columnFilters, globalSearchTerm]);
1890
1899
  const selectionBounds = useMemo8(() => {
1891
1900
  if (!selectionStart || !selectionEnd) return null;
1892
1901
  return {
@@ -1922,7 +1931,7 @@ function DataGrid({
1922
1931
  const avg = sum / values.length;
1923
1932
  return { count, sum, avg, numericCount: values.length };
1924
1933
  }, [selectionBounds, rows, columnKeys]);
1925
- useEffect3(() => {
1934
+ useEffect4(() => {
1926
1935
  if (data.length === 0) return;
1927
1936
  const widths = {};
1928
1937
  const sampleSize = Math.min(100, data.length);
@@ -1953,7 +1962,7 @@ function DataGrid({
1953
1962
  },
1954
1963
  [enableColumnResize, columnWidths]
1955
1964
  );
1956
- useEffect3(() => {
1965
+ useEffect4(() => {
1957
1966
  if (!resizingColumnId) return;
1958
1967
  const handleResizeMove = (event) => {
1959
1968
  const diff = event.clientX - resizeStartX;
@@ -1983,7 +1992,7 @@ function DataGrid({
1983
1992
  },
1984
1993
  [enableVerticalResize, gridHeight]
1985
1994
  );
1986
- useEffect3(() => {
1995
+ useEffect4(() => {
1987
1996
  if (!isResizingVertically) return;
1988
1997
  const handleVerticalResizeMove = (event) => {
1989
1998
  const diff = event.clientY - verticalResizeStartY;
@@ -2101,12 +2110,12 @@ function DataGrid({
2101
2110
  },
2102
2111
  [isSelecting]
2103
2112
  );
2104
- useEffect3(() => {
2113
+ useEffect4(() => {
2105
2114
  const handleMouseUp = () => setIsSelecting(false);
2106
2115
  document.addEventListener("mouseup", handleMouseUp);
2107
2116
  return () => document.removeEventListener("mouseup", handleMouseUp);
2108
2117
  }, []);
2109
- useEffect3(() => {
2118
+ useEffect4(() => {
2110
2119
  const handleKeydown = (event) => {
2111
2120
  if ((event.ctrlKey || event.metaKey) && event.key === "c" && selectionBounds) {
2112
2121
  event.preventDefault();