@smallwebco/tinypivot-react 1.0.13 → 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.cjs +9 -2
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +25 -18
- package/dist/index.js.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +2 -2
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
|
|
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}-${
|
|
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);
|
|
@@ -172,7 +179,7 @@ function useExcelGrid(options) {
|
|
|
172
179
|
}
|
|
173
180
|
|
|
174
181
|
// src/hooks/usePivotTable.ts
|
|
175
|
-
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";
|
|
176
183
|
import {
|
|
177
184
|
computeAvailableFields,
|
|
178
185
|
getUnassignedFields,
|
|
@@ -304,7 +311,7 @@ function usePivotTable(data) {
|
|
|
304
311
|
showColumnTotals
|
|
305
312
|
});
|
|
306
313
|
}, [data, isConfigured, canUsePivot, rowFields, columnFields, valueFields, showRowTotals, showColumnTotals]);
|
|
307
|
-
|
|
314
|
+
useEffect2(() => {
|
|
308
315
|
if (data.length === 0) return;
|
|
309
316
|
const newKeys = Object.keys(data[0]);
|
|
310
317
|
const storageKey = generateStorageKey(newKeys);
|
|
@@ -333,7 +340,7 @@ function usePivotTable(data) {
|
|
|
333
340
|
}
|
|
334
341
|
}
|
|
335
342
|
}, [data]);
|
|
336
|
-
|
|
343
|
+
useEffect2(() => {
|
|
337
344
|
if (!currentStorageKey) return;
|
|
338
345
|
const config = {
|
|
339
346
|
rowFields,
|
|
@@ -693,7 +700,7 @@ function useColumnResize(initialWidths, minWidth = 60, maxWidth = 600) {
|
|
|
693
700
|
}
|
|
694
701
|
|
|
695
702
|
// src/components/ColumnFilter.tsx
|
|
696
|
-
import { useState as useState5, useEffect as
|
|
703
|
+
import { useState as useState5, useEffect as useEffect3, useRef, useCallback as useCallback5, useMemo as useMemo5 } from "react";
|
|
697
704
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
698
705
|
function ColumnFilter({
|
|
699
706
|
columnName,
|
|
@@ -768,7 +775,7 @@ function ColumnFilter({
|
|
|
768
775
|
onFilter([]);
|
|
769
776
|
onClose();
|
|
770
777
|
}, [onFilter, onClose]);
|
|
771
|
-
|
|
778
|
+
useEffect3(() => {
|
|
772
779
|
const handleClickOutside = (event) => {
|
|
773
780
|
if (dropdownRef.current && !dropdownRef.current.contains(event.target)) {
|
|
774
781
|
onClose();
|
|
@@ -777,7 +784,7 @@ function ColumnFilter({
|
|
|
777
784
|
document.addEventListener("mousedown", handleClickOutside);
|
|
778
785
|
return () => document.removeEventListener("mousedown", handleClickOutside);
|
|
779
786
|
}, [onClose]);
|
|
780
|
-
|
|
787
|
+
useEffect3(() => {
|
|
781
788
|
const handleKeydown = (event) => {
|
|
782
789
|
if (event.key === "Escape") {
|
|
783
790
|
onClose();
|
|
@@ -788,10 +795,10 @@ function ColumnFilter({
|
|
|
788
795
|
document.addEventListener("keydown", handleKeydown);
|
|
789
796
|
return () => document.removeEventListener("keydown", handleKeydown);
|
|
790
797
|
}, [onClose, applyFilter]);
|
|
791
|
-
|
|
798
|
+
useEffect3(() => {
|
|
792
799
|
searchInputRef.current?.focus();
|
|
793
800
|
}, []);
|
|
794
|
-
|
|
801
|
+
useEffect3(() => {
|
|
795
802
|
setLocalSelected(new Set(selectedValues));
|
|
796
803
|
}, [selectedValues]);
|
|
797
804
|
return /* @__PURE__ */ jsxs("div", { ref: dropdownRef, className: "vpg-filter-dropdown", children: [
|
|
@@ -1886,7 +1893,7 @@ function DataGrid({
|
|
|
1886
1893
|
const end = start + pageSize;
|
|
1887
1894
|
return searchFilteredData.slice(start, end);
|
|
1888
1895
|
}, [enablePagination, searchFilteredData, currentPage, pageSize]);
|
|
1889
|
-
|
|
1896
|
+
useEffect4(() => {
|
|
1890
1897
|
setCurrentPage(1);
|
|
1891
1898
|
}, [columnFilters, globalSearchTerm]);
|
|
1892
1899
|
const selectionBounds = useMemo8(() => {
|
|
@@ -1924,7 +1931,7 @@ function DataGrid({
|
|
|
1924
1931
|
const avg = sum / values.length;
|
|
1925
1932
|
return { count, sum, avg, numericCount: values.length };
|
|
1926
1933
|
}, [selectionBounds, rows, columnKeys]);
|
|
1927
|
-
|
|
1934
|
+
useEffect4(() => {
|
|
1928
1935
|
if (data.length === 0) return;
|
|
1929
1936
|
const widths = {};
|
|
1930
1937
|
const sampleSize = Math.min(100, data.length);
|
|
@@ -1955,7 +1962,7 @@ function DataGrid({
|
|
|
1955
1962
|
},
|
|
1956
1963
|
[enableColumnResize, columnWidths]
|
|
1957
1964
|
);
|
|
1958
|
-
|
|
1965
|
+
useEffect4(() => {
|
|
1959
1966
|
if (!resizingColumnId) return;
|
|
1960
1967
|
const handleResizeMove = (event) => {
|
|
1961
1968
|
const diff = event.clientX - resizeStartX;
|
|
@@ -1985,7 +1992,7 @@ function DataGrid({
|
|
|
1985
1992
|
},
|
|
1986
1993
|
[enableVerticalResize, gridHeight]
|
|
1987
1994
|
);
|
|
1988
|
-
|
|
1995
|
+
useEffect4(() => {
|
|
1989
1996
|
if (!isResizingVertically) return;
|
|
1990
1997
|
const handleVerticalResizeMove = (event) => {
|
|
1991
1998
|
const diff = event.clientY - verticalResizeStartY;
|
|
@@ -2103,12 +2110,12 @@ function DataGrid({
|
|
|
2103
2110
|
},
|
|
2104
2111
|
[isSelecting]
|
|
2105
2112
|
);
|
|
2106
|
-
|
|
2113
|
+
useEffect4(() => {
|
|
2107
2114
|
const handleMouseUp = () => setIsSelecting(false);
|
|
2108
2115
|
document.addEventListener("mouseup", handleMouseUp);
|
|
2109
2116
|
return () => document.removeEventListener("mouseup", handleMouseUp);
|
|
2110
2117
|
}, []);
|
|
2111
|
-
|
|
2118
|
+
useEffect4(() => {
|
|
2112
2119
|
const handleKeydown = (event) => {
|
|
2113
2120
|
if ((event.ctrlKey || event.metaKey) && event.key === "c" && selectionBounds) {
|
|
2114
2121
|
event.preventDefault();
|