@bmsuisse/datagrid 0.33.1 → 0.34.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.
- package/dist/index.d.ts +24 -4
- package/dist/index.js +73 -65
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -1395,6 +1395,22 @@ interface DataGridProps<TRow> {
|
|
|
1395
1395
|
* control back, it just stops resyncing.
|
|
1396
1396
|
*/
|
|
1397
1397
|
gridState?: GridState;
|
|
1398
|
+
/**
|
|
1399
|
+
* Fires on every sort/filter/page/pageSize change, in **both** `"client"`
|
|
1400
|
+
* and `"server"` `dataSource.mode` — unlike `dataSource.onStateChange`
|
|
1401
|
+
* (server-mode only, and required there), this is purely an observer and
|
|
1402
|
+
* works whether or not `<DataGrid>` owns its own state. The one way to
|
|
1403
|
+
* know a `"client"`-mode grid's *current* filter/sort/page from outside
|
|
1404
|
+
* (e.g. to compute a footer total over only the currently-filtered rows
|
|
1405
|
+
* with the exported `evaluateFilter`, or to build a custom paginated
|
|
1406
|
+
* footer in another locale) — `"client"` mode has no equivalent of
|
|
1407
|
+
* `dataSource.onStateChange` otherwise. Debounced ~300ms for filter
|
|
1408
|
+
* changes (typing), immediate for sort/page/pageSize, matching
|
|
1409
|
+
* `dataSource.onStateChange`'s own timing. Does not imply control: pass
|
|
1410
|
+
* `gridState` too if you also want to push state back in (e.g. resetting
|
|
1411
|
+
* filters programmatically); omit `gridState` to just observe.
|
|
1412
|
+
*/
|
|
1413
|
+
onGridStateChange?: (state: GridState) => void;
|
|
1398
1414
|
/**
|
|
1399
1415
|
* Controlled column visibility, e.g. driven by a `<ColumnSelector>` next
|
|
1400
1416
|
* to the grid. Both must be supplied together to actually hide columns —
|
|
@@ -1610,7 +1626,7 @@ interface DataGridProps<TRow> {
|
|
|
1610
1626
|
* (`"server"`). Column filter UI defaults to the type-appropriate widget
|
|
1611
1627
|
* from `src/filter` unless a column supplies its own `cell` renderer.
|
|
1612
1628
|
*/
|
|
1613
|
-
declare function DataGrid<TRow extends RowData>({ columns, dataSource, getRowId, rowActions, headerActions, enableMultiSort, initialState, columnVisibility, renderDetail, enableColumnResizing, columnResizeMode, columnSizing: controlledColumnSizing, onColumnSizingChange, virtualize, showPagination, getRowProps, getRowTestId, gridState, selectedIds: controlledSelectedIds, onSelectedIdsChange, testId, loading: loadingProp, groupBy, renderGroupHeader, defaultGroupsExpanded, expandedGroups: controlledExpandedGroups, onExpandedGroupsChange, zebra, showTotals, editing, cellEditing, }: DataGridProps<TRow>): ReactElement;
|
|
1629
|
+
declare function DataGrid<TRow extends RowData>({ columns, dataSource, getRowId, rowActions, headerActions, enableMultiSort, initialState, columnVisibility, renderDetail, enableColumnResizing, columnResizeMode, columnSizing: controlledColumnSizing, onColumnSizingChange, virtualize, showPagination, getRowProps, getRowTestId, gridState, onGridStateChange, selectedIds: controlledSelectedIds, onSelectedIdsChange, testId, loading: loadingProp, groupBy, renderGroupHeader, defaultGroupsExpanded, expandedGroups: controlledExpandedGroups, onExpandedGroupsChange, zebra, showTotals, editing, cellEditing, }: DataGridProps<TRow>): ReactElement;
|
|
1614
1630
|
|
|
1615
1631
|
interface GridStateController {
|
|
1616
1632
|
state: GridState;
|
|
@@ -1632,8 +1648,12 @@ interface GridStateController {
|
|
|
1632
1648
|
* Owns `GridState` (filter/sort/page/pageSize) for `<DataGrid>` and, in
|
|
1633
1649
|
* `"server"` mode, calls `dataSource.onStateChange` on every change —
|
|
1634
1650
|
* debounced ~300ms for filter changes (typing), immediately for sort/page
|
|
1635
|
-
* changes. In `"client"` mode `onStateChange` doesn't exist and
|
|
1636
|
-
* called; the grid re-filters/re-sorts the in-memory array itself
|
|
1651
|
+
* changes. In `"client"` mode `dataSource.onStateChange` doesn't exist and
|
|
1652
|
+
* is never called; the grid re-filters/re-sorts the in-memory array itself
|
|
1653
|
+
* instead. `onGridStateChange` (see its own doc on `DataGridProps`) gets the
|
|
1654
|
+
* same notifications regardless of mode, for callers that just want to
|
|
1655
|
+
* observe — e.g. a `"client"`-mode grid with no other way to know its
|
|
1656
|
+
* current filter/sort/page from outside.
|
|
1637
1657
|
*
|
|
1638
1658
|
* Deliberately takes no `columns` and enforces no `sortable`/`filterable`
|
|
1639
1659
|
* policy itself — `toggleSort`/`setColumnFilter` will happily act on any
|
|
@@ -1668,7 +1688,7 @@ interface GridStateController {
|
|
|
1668
1688
|
* particular page size at all. Has no effect once `externalState` is in
|
|
1669
1689
|
* play — a controlled `GridState` is always fully caller-specified.
|
|
1670
1690
|
*/
|
|
1671
|
-
declare function useGridState<TRow>(dataSource: DataSource<TRow>, initialState?: Partial<GridState>, externalState?: GridState, showPagination?: boolean): GridStateController;
|
|
1691
|
+
declare function useGridState<TRow>(dataSource: DataSource<TRow>, initialState?: Partial<GridState>, externalState?: GridState, showPagination?: boolean, onGridStateChange?: (state: GridState) => void): GridStateController;
|
|
1672
1692
|
|
|
1673
1693
|
interface ClientProcessingResult<TRow> {
|
|
1674
1694
|
rows: TRow[];
|
package/dist/index.js
CHANGED
|
@@ -1283,7 +1283,7 @@ function facetedNumberValues(data, column, filter) {
|
|
|
1283
1283
|
|
|
1284
1284
|
// src/filter/StringFilter.tsx
|
|
1285
1285
|
import { FunnelIcon as FunnelIcon6 } from "@heroicons/react/24/outline";
|
|
1286
|
-
import { useId as useId3 } from "react";
|
|
1286
|
+
import { useEffect as useEffect4, useId as useId3, useState as useState5 } from "react";
|
|
1287
1287
|
import { jsx as jsx13, jsxs as jsxs8 } from "react/jsx-runtime";
|
|
1288
1288
|
var STRING_OPERATORS = [
|
|
1289
1289
|
{ value: "contains", label: "Contains" },
|
|
@@ -1298,10 +1298,13 @@ function StringFilter({
|
|
|
1298
1298
|
onChange,
|
|
1299
1299
|
bare = false
|
|
1300
1300
|
}) {
|
|
1301
|
-
const operator = value?.operator ?? DEFAULT_OPERATOR2;
|
|
1301
|
+
const [operator, setOperator] = useState5(value?.operator ?? DEFAULT_OPERATOR2);
|
|
1302
1302
|
const text = typeof value?.value === "string" ? value.value : "";
|
|
1303
1303
|
const inputId = useId3();
|
|
1304
1304
|
const isFiltered = text !== "";
|
|
1305
|
+
useEffect4(() => {
|
|
1306
|
+
setOperator(value?.operator ?? DEFAULT_OPERATOR2);
|
|
1307
|
+
}, [value?.operator]);
|
|
1305
1308
|
function emit(nextOperator, nextText) {
|
|
1306
1309
|
if (nextText === "") {
|
|
1307
1310
|
onChange(void 0);
|
|
@@ -1316,7 +1319,9 @@ function StringFilter({
|
|
|
1316
1319
|
value: operator,
|
|
1317
1320
|
onValueChange: (next) => {
|
|
1318
1321
|
const nextOperator = STRING_OPERATORS.find((option) => option.value === next)?.value;
|
|
1319
|
-
if (nextOperator)
|
|
1322
|
+
if (!nextOperator) return;
|
|
1323
|
+
setOperator(nextOperator);
|
|
1324
|
+
emit(nextOperator, text);
|
|
1320
1325
|
},
|
|
1321
1326
|
children: [
|
|
1322
1327
|
/* @__PURE__ */ jsx13(SelectTrigger, { "aria-label": `${column.header} filter operator`, children: /* @__PURE__ */ jsx13(SelectValue, {}) }),
|
|
@@ -1579,7 +1584,7 @@ function MultilineStringEditor({
|
|
|
1579
1584
|
}
|
|
1580
1585
|
|
|
1581
1586
|
// src/edit/NumberEditor.tsx
|
|
1582
|
-
import { useEffect as
|
|
1587
|
+
import { useEffect as useEffect5, useRef as useRef5, useState as useState6 } from "react";
|
|
1583
1588
|
import { jsx as jsx21, jsxs as jsxs13 } from "react/jsx-runtime";
|
|
1584
1589
|
function textFromValue(value) {
|
|
1585
1590
|
return value === null || value === void 0 ? "" : String(value);
|
|
@@ -1593,9 +1598,9 @@ function NumberEditor({
|
|
|
1593
1598
|
autoFocus
|
|
1594
1599
|
}) {
|
|
1595
1600
|
const errorId = editErrorId(rowId, column.id);
|
|
1596
|
-
const [text, setText] =
|
|
1601
|
+
const [text, setText] = useState6(() => textFromValue(value));
|
|
1597
1602
|
const lastEmittedRef = useRef5(value);
|
|
1598
|
-
|
|
1603
|
+
useEffect5(() => {
|
|
1599
1604
|
if (value === lastEmittedRef.current) return;
|
|
1600
1605
|
lastEmittedRef.current = value;
|
|
1601
1606
|
setText(textFromValue(value));
|
|
@@ -1673,22 +1678,22 @@ function renderDefaultEditWidget(column, rowId, value, onChange, error, autoFocu
|
|
|
1673
1678
|
}
|
|
1674
1679
|
|
|
1675
1680
|
// src/edit/editingState.ts
|
|
1676
|
-
import { useEffect as
|
|
1681
|
+
import { useEffect as useEffect6, useRef as useRef6, useState as useState7 } from "react";
|
|
1677
1682
|
function editValuesEqual(a, b) {
|
|
1678
1683
|
if (a instanceof Date && b instanceof Date) return a.getTime() === b.getTime();
|
|
1679
1684
|
return a === b;
|
|
1680
1685
|
}
|
|
1681
1686
|
function useEditingState(editing, getRowId) {
|
|
1682
|
-
const [pendingEdits, setPendingEdits] =
|
|
1683
|
-
const [editErrors, setEditErrors] =
|
|
1687
|
+
const [pendingEdits, setPendingEdits] = useState7(/* @__PURE__ */ new Map());
|
|
1688
|
+
const [editErrors, setEditErrors] = useState7(/* @__PURE__ */ new Map());
|
|
1684
1689
|
const hasEditErrors = editErrors.size > 0;
|
|
1685
|
-
const [activeRowId, setActiveRowId] =
|
|
1686
|
-
const [autoFocusTarget, setAutoFocusTarget] =
|
|
1690
|
+
const [activeRowId, setActiveRowId] = useState7(null);
|
|
1691
|
+
const [autoFocusTarget, setAutoFocusTarget] = useState7(null);
|
|
1687
1692
|
function activateRow(rowId, columnId) {
|
|
1688
1693
|
setActiveRowId(rowId);
|
|
1689
1694
|
setAutoFocusTarget({ rowId, columnId });
|
|
1690
1695
|
}
|
|
1691
|
-
|
|
1696
|
+
useEffect6(() => {
|
|
1692
1697
|
if (autoFocusTarget) setAutoFocusTarget(null);
|
|
1693
1698
|
}, [autoFocusTarget]);
|
|
1694
1699
|
function commitEdit(column, row, value) {
|
|
@@ -1981,11 +1986,11 @@ function extendRangeForFillToCellRange(base, target, rowIds, columnIds, rowIndex
|
|
|
1981
1986
|
}
|
|
1982
1987
|
|
|
1983
1988
|
// src/cell-editing/useCellSelection.ts
|
|
1984
|
-
import { useCallback as useCallback2, useMemo as useMemo3, useRef as useRef7, useState as
|
|
1989
|
+
import { useCallback as useCallback2, useMemo as useMemo3, useRef as useRef7, useState as useState8 } from "react";
|
|
1985
1990
|
function useCellSelection({ rowIds, columnIds, onNavigateToRow }) {
|
|
1986
|
-
const [selection, setSelectionState] =
|
|
1987
|
-
const [isDragging, setIsDragging] =
|
|
1988
|
-
const [dragFocus, setDragFocus] =
|
|
1991
|
+
const [selection, setSelectionState] = useState8(void 0);
|
|
1992
|
+
const [isDragging, setIsDragging] = useState8(false);
|
|
1993
|
+
const [dragFocus, setDragFocus] = useState8(void 0);
|
|
1989
1994
|
const draggingRef = useRef7(false);
|
|
1990
1995
|
const dragFocusRef = useRef7(void 0);
|
|
1991
1996
|
const rowIndex = useMemo3(() => buildIndexMap(rowIds), [rowIds]);
|
|
@@ -2048,8 +2053,8 @@ function useCellSelection({ rowIds, columnIds, onNavigateToRow }) {
|
|
|
2048
2053
|
if (isDragging && dragFocus) return { anchor: selection.anchor, focus: dragFocus };
|
|
2049
2054
|
return selection;
|
|
2050
2055
|
}, [selection, isDragging, dragFocus]);
|
|
2051
|
-
const [isFillDragging, setIsFillDragging] =
|
|
2052
|
-
const [fillTarget, setFillTarget] =
|
|
2056
|
+
const [isFillDragging, setIsFillDragging] = useState8(false);
|
|
2057
|
+
const [fillTarget, setFillTarget] = useState8(void 0);
|
|
2053
2058
|
const fillDraggingRef = useRef7(false);
|
|
2054
2059
|
const fillTargetRef = useRef7(void 0);
|
|
2055
2060
|
const fillBaseRef = useRef7(void 0);
|
|
@@ -2102,17 +2107,17 @@ function useCellSelection({ rowIds, columnIds, onNavigateToRow }) {
|
|
|
2102
2107
|
}
|
|
2103
2108
|
|
|
2104
2109
|
// src/cell-editing/useCellEditingState.ts
|
|
2105
|
-
import { useRef as useRef8, useState as
|
|
2110
|
+
import { useRef as useRef8, useState as useState9 } from "react";
|
|
2106
2111
|
function cellKey(rowId, columnId) {
|
|
2107
2112
|
return `${rowId}:${columnId}`;
|
|
2108
2113
|
}
|
|
2109
2114
|
function useCellEditingState(cellEditing, getRowId) {
|
|
2110
|
-
const [editingCell, setEditingCell] =
|
|
2111
|
-
const [initialText, setInitialText] =
|
|
2112
|
-
const [hasDraft, setHasDraft] =
|
|
2113
|
-
const [draftValue, setDraftValue] =
|
|
2114
|
-
const [overrides, setOverrides] =
|
|
2115
|
-
const [errors, setErrors] =
|
|
2115
|
+
const [editingCell, setEditingCell] = useState9(void 0);
|
|
2116
|
+
const [initialText, setInitialText] = useState9(void 0);
|
|
2117
|
+
const [hasDraft, setHasDraft] = useState9(false);
|
|
2118
|
+
const [draftValue, setDraftValue] = useState9(void 0);
|
|
2119
|
+
const [overrides, setOverrides] = useState9(/* @__PURE__ */ new Map());
|
|
2120
|
+
const [errors, setErrors] = useState9(/* @__PURE__ */ new Map());
|
|
2116
2121
|
const justCommittedRef = useRef8(false);
|
|
2117
2122
|
function closeEditor() {
|
|
2118
2123
|
setEditingCell(void 0);
|
|
@@ -2272,7 +2277,7 @@ function renderCellModeCell(column, row, rawValue, ctx) {
|
|
|
2272
2277
|
}
|
|
2273
2278
|
|
|
2274
2279
|
// src/cell-editing/SelectionOverlay.tsx
|
|
2275
|
-
import { useLayoutEffect as useLayoutEffect2, useRef as useRef9, useState as
|
|
2280
|
+
import { useLayoutEffect as useLayoutEffect2, useRef as useRef9, useState as useState10 } from "react";
|
|
2276
2281
|
import { Fragment as Fragment2, jsx as jsx27, jsxs as jsxs16 } from "react/jsx-runtime";
|
|
2277
2282
|
function cellSelector(rowId, columnId) {
|
|
2278
2283
|
const escape = (value) => typeof CSS !== "undefined" && CSS.escape ? CSS.escape(value) : value.replace(/["\\]/g, "\\$&");
|
|
@@ -2303,8 +2308,8 @@ function SelectionOverlay({
|
|
|
2303
2308
|
fillPreviewRange,
|
|
2304
2309
|
onFillHandleMouseDown
|
|
2305
2310
|
}) {
|
|
2306
|
-
const [rect, setRect] =
|
|
2307
|
-
const [previewRect, setPreviewRect] =
|
|
2311
|
+
const [rect, setRect] = useState10(void 0);
|
|
2312
|
+
const [previewRect, setPreviewRect] = useState10(void 0);
|
|
2308
2313
|
const recomputeRef = useRef9(() => {
|
|
2309
2314
|
});
|
|
2310
2315
|
recomputeRef.current = () => {
|
|
@@ -2552,7 +2557,7 @@ function computeFillChanges(sourceRange, finalRange, rowIds, columnIds, columns,
|
|
|
2552
2557
|
|
|
2553
2558
|
// src/column-selector/ColumnSelector.tsx
|
|
2554
2559
|
import { Columns3 } from "lucide-react";
|
|
2555
|
-
import { useEffect as
|
|
2560
|
+
import { useEffect as useEffect7 } from "react";
|
|
2556
2561
|
|
|
2557
2562
|
// src/components/ui/dialog.tsx
|
|
2558
2563
|
import * as DialogPrimitive from "@radix-ui/react-dialog";
|
|
@@ -2676,7 +2681,7 @@ function ColumnSelector({
|
|
|
2676
2681
|
open,
|
|
2677
2682
|
onOpenChange
|
|
2678
2683
|
}) {
|
|
2679
|
-
|
|
2684
|
+
useEffect7(() => {
|
|
2680
2685
|
if (!persistKey) return;
|
|
2681
2686
|
const restored = readPersistedVisibility(persistKey);
|
|
2682
2687
|
if (restored) onVisibilityChange({ ...visibility, ...restored });
|
|
@@ -2817,23 +2822,23 @@ import { BarsArrowDownIcon, BarsArrowUpIcon, FunnelIcon as FunnelIcon7 } from "@
|
|
|
2817
2822
|
import { columnResizingFeature, columnSizingFeature, flexRender, tableFeatures, useTable } from "@tanstack/react-table";
|
|
2818
2823
|
import { useVirtualizer } from "@tanstack/react-virtual";
|
|
2819
2824
|
import { ChevronRight, Loader2 } from "lucide-react";
|
|
2820
|
-
import { Fragment as Fragment3, useEffect as
|
|
2825
|
+
import { Fragment as Fragment3, useEffect as useEffect11, useMemo as useMemo8, useRef as useRef12, useState as useState15 } from "react";
|
|
2821
2826
|
|
|
2822
2827
|
// src/cell-editing/renderAlwaysEditCell.tsx
|
|
2823
2828
|
import {
|
|
2824
|
-
useEffect as
|
|
2825
|
-
useState as
|
|
2829
|
+
useEffect as useEffect8,
|
|
2830
|
+
useState as useState11
|
|
2826
2831
|
} from "react";
|
|
2827
2832
|
import { jsx as jsx32 } from "react/jsx-runtime";
|
|
2828
2833
|
function AlwaysEditCell(props) {
|
|
2829
2834
|
const { column, row, rawValue, ctx, atomicGesture } = props;
|
|
2830
2835
|
const rowId = ctx.getRowId(row);
|
|
2831
2836
|
const resolvedValue = ctx.resolveValue(rowId, column.id, rawValue);
|
|
2832
|
-
const [draft, setDraft] =
|
|
2833
|
-
const [enumOpen, setEnumOpen] =
|
|
2837
|
+
const [draft, setDraft] = useState11(void 0);
|
|
2838
|
+
const [enumOpen, setEnumOpen] = useState11(false);
|
|
2834
2839
|
const isBuiltinEnum = column.type === "enum" && !column.renderEditCell;
|
|
2835
2840
|
const shouldOpenEnumNow = isBuiltinEnum && (atomicGesture?.shouldOpenEnum(rowId, column.id) ?? false);
|
|
2836
|
-
|
|
2841
|
+
useEffect8(() => {
|
|
2837
2842
|
if (shouldOpenEnumNow) setEnumOpen(true);
|
|
2838
2843
|
}, [shouldOpenEnumNow]);
|
|
2839
2844
|
if (!isEditable(column, row)) {
|
|
@@ -2931,9 +2936,9 @@ function AlwaysEditCell(props) {
|
|
|
2931
2936
|
}
|
|
2932
2937
|
|
|
2933
2938
|
// src/hooks/useGroupExpansion.ts
|
|
2934
|
-
import { useCallback as useCallback3, useState as
|
|
2939
|
+
import { useCallback as useCallback3, useState as useState12 } from "react";
|
|
2935
2940
|
function useGroupExpansion(defaultGroupsExpanded, controlledExpandedGroups, onExpandedGroupsChange) {
|
|
2936
|
-
const [internalExpandedGroups, setInternalExpandedGroups] =
|
|
2941
|
+
const [internalExpandedGroups, setInternalExpandedGroups] = useState12({});
|
|
2937
2942
|
const expandedGroups = controlledExpandedGroups ?? internalExpandedGroups;
|
|
2938
2943
|
const updateExpandedGroups = useCallback3(
|
|
2939
2944
|
(next) => {
|
|
@@ -2956,10 +2961,10 @@ function useGroupExpansion(defaultGroupsExpanded, controlledExpandedGroups, onEx
|
|
|
2956
2961
|
}
|
|
2957
2962
|
|
|
2958
2963
|
// src/hooks/useStickyGroupHeaderTop.ts
|
|
2959
|
-
import { useLayoutEffect as useLayoutEffect3, useRef as useRef10, useState as
|
|
2964
|
+
import { useLayoutEffect as useLayoutEffect3, useRef as useRef10, useState as useState13 } from "react";
|
|
2960
2965
|
function useStickyGroupHeaderTop(enabled) {
|
|
2961
2966
|
const theadRef = useRef10(null);
|
|
2962
|
-
const [groupHeaderTop, setGroupHeaderTop] =
|
|
2967
|
+
const [groupHeaderTop, setGroupHeaderTop] = useState13(0);
|
|
2963
2968
|
useLayoutEffect3(() => {
|
|
2964
2969
|
if (!enabled) return;
|
|
2965
2970
|
const theadEl = theadRef.current;
|
|
@@ -3023,15 +3028,15 @@ function processClientData(data, state) {
|
|
|
3023
3028
|
}
|
|
3024
3029
|
|
|
3025
3030
|
// src/grid/useGridState.ts
|
|
3026
|
-
import { useCallback as useCallback4, useEffect as
|
|
3031
|
+
import { useCallback as useCallback4, useEffect as useEffect10, useMemo as useMemo7, useState as useState14 } from "react";
|
|
3027
3032
|
|
|
3028
3033
|
// src/hooks/useDebouncedCallback.ts
|
|
3029
|
-
import { useEffect as
|
|
3034
|
+
import { useEffect as useEffect9, useMemo as useMemo6, useRef as useRef11 } from "react";
|
|
3030
3035
|
function useDebouncedCallback(callback, delayMs) {
|
|
3031
3036
|
const callbackRef = useRef11(callback);
|
|
3032
3037
|
callbackRef.current = callback;
|
|
3033
3038
|
const timeoutRef = useRef11(void 0);
|
|
3034
|
-
|
|
3039
|
+
useEffect9(() => {
|
|
3035
3040
|
return () => {
|
|
3036
3041
|
clearTimeout(timeoutRef.current);
|
|
3037
3042
|
};
|
|
@@ -3060,8 +3065,8 @@ function nextSortDir(current, descFirst) {
|
|
|
3060
3065
|
if (current === first) return second;
|
|
3061
3066
|
return void 0;
|
|
3062
3067
|
}
|
|
3063
|
-
function useGridState(dataSource, initialState, externalState, showPagination = true) {
|
|
3064
|
-
const [state, setState] =
|
|
3068
|
+
function useGridState(dataSource, initialState, externalState, showPagination = true, onGridStateChange) {
|
|
3069
|
+
const [state, setState] = useState14(() => {
|
|
3065
3070
|
if (externalState) return externalState;
|
|
3066
3071
|
const pageSize = initialState?.pageSize ?? (showPagination ? DEFAULT_STATE.pageSize : Number.MAX_SAFE_INTEGER);
|
|
3067
3072
|
return { ...DEFAULT_STATE, ...initialState, pageSize };
|
|
@@ -3069,8 +3074,9 @@ function useGridState(dataSource, initialState, externalState, showPagination =
|
|
|
3069
3074
|
const notifyRaw = useCallback4(
|
|
3070
3075
|
(next) => {
|
|
3071
3076
|
if (dataSource.mode === "server") dataSource.onStateChange(next);
|
|
3077
|
+
onGridStateChange?.(next);
|
|
3072
3078
|
},
|
|
3073
|
-
[dataSource]
|
|
3079
|
+
[dataSource, onGridStateChange]
|
|
3074
3080
|
);
|
|
3075
3081
|
const { run: notifyDebounced, cancel: cancelDebouncedNotify } = useDebouncedCallback(
|
|
3076
3082
|
notifyRaw,
|
|
@@ -3083,7 +3089,7 @@ function useGridState(dataSource, initialState, externalState, showPagination =
|
|
|
3083
3089
|
},
|
|
3084
3090
|
[notifyRaw, cancelDebouncedNotify]
|
|
3085
3091
|
);
|
|
3086
|
-
|
|
3092
|
+
useEffect10(() => {
|
|
3087
3093
|
if (!externalState) return;
|
|
3088
3094
|
cancelDebouncedNotify();
|
|
3089
3095
|
setState(externalState);
|
|
@@ -3235,6 +3241,7 @@ function DataGrid({
|
|
|
3235
3241
|
getRowProps,
|
|
3236
3242
|
getRowTestId,
|
|
3237
3243
|
gridState,
|
|
3244
|
+
onGridStateChange,
|
|
3238
3245
|
selectedIds: controlledSelectedIds,
|
|
3239
3246
|
onSelectedIdsChange,
|
|
3240
3247
|
testId,
|
|
@@ -3254,21 +3261,22 @@ function DataGrid({
|
|
|
3254
3261
|
dataSource,
|
|
3255
3262
|
initialState,
|
|
3256
3263
|
gridState,
|
|
3257
|
-
showPagination
|
|
3264
|
+
showPagination,
|
|
3265
|
+
onGridStateChange
|
|
3258
3266
|
);
|
|
3259
|
-
const [internalSelectedIds, setInternalSelectedIds] =
|
|
3267
|
+
const [internalSelectedIds, setInternalSelectedIds] = useState15(/* @__PURE__ */ new Set());
|
|
3260
3268
|
const selectedIds = controlledSelectedIds ?? internalSelectedIds;
|
|
3261
3269
|
function updateSelectedIds(next) {
|
|
3262
3270
|
setInternalSelectedIds(next);
|
|
3263
3271
|
onSelectedIdsChange?.(next);
|
|
3264
3272
|
}
|
|
3265
|
-
const [internalColumnSizing, setInternalColumnSizing] =
|
|
3273
|
+
const [internalColumnSizing, setInternalColumnSizing] = useState15({});
|
|
3266
3274
|
const columnSizing = controlledColumnSizing ?? internalColumnSizing;
|
|
3267
3275
|
function updateColumnSizing(next) {
|
|
3268
3276
|
setInternalColumnSizing(next);
|
|
3269
3277
|
onColumnSizingChange?.(next);
|
|
3270
3278
|
}
|
|
3271
|
-
const [expandedIds, setExpandedIds] =
|
|
3279
|
+
const [expandedIds, setExpandedIds] = useState15(/* @__PURE__ */ new Set());
|
|
3272
3280
|
function toggleRowExpanded(id) {
|
|
3273
3281
|
setExpandedIds((prev) => {
|
|
3274
3282
|
const next = new Set(prev);
|
|
@@ -3446,7 +3454,7 @@ function DataGrid({
|
|
|
3446
3454
|
}, [visibleColumns, enableColumnResizing, leftPinnedOffsets, rightPinnedOffsets, columnSizing]);
|
|
3447
3455
|
const tableRows = table.getRowModel().rows;
|
|
3448
3456
|
const truncationWarnedRef = useRef12(false);
|
|
3449
|
-
|
|
3457
|
+
useEffect11(() => {
|
|
3450
3458
|
if (process.env.NODE_ENV === "production") return;
|
|
3451
3459
|
if (showPagination) return;
|
|
3452
3460
|
if (truncationWarnedRef.current) return;
|
|
@@ -3489,10 +3497,10 @@ function DataGrid({
|
|
|
3489
3497
|
const paddingBottom = virtualItems.length > 0 ? virtualizer.getTotalSize() - virtualItems[virtualItems.length - 1].end : 0;
|
|
3490
3498
|
const lastVisibleIndex = virtualItems.length > 0 ? virtualItems[virtualItems.length - 1].index : -1;
|
|
3491
3499
|
const notifiedForLengthRef = useRef12(-1);
|
|
3492
|
-
|
|
3500
|
+
useEffect11(() => {
|
|
3493
3501
|
notifiedForLengthRef.current = -1;
|
|
3494
3502
|
}, [state.filter, state.sort]);
|
|
3495
|
-
|
|
3503
|
+
useEffect11(() => {
|
|
3496
3504
|
if (!virtualize?.onEndReached) return;
|
|
3497
3505
|
if (lastVisibleIndex < 0 || lastVisibleIndex < flatItems.length - 1) return;
|
|
3498
3506
|
if (virtualize.hasMore === false) return;
|
|
@@ -3520,7 +3528,7 @@ function DataGrid({
|
|
|
3520
3528
|
});
|
|
3521
3529
|
const clickCellRef = useRef12(null);
|
|
3522
3530
|
const dragMovedRef = useRef12(false);
|
|
3523
|
-
const [pendingOpenEnumCell, setPendingOpenEnumCell] =
|
|
3531
|
+
const [pendingOpenEnumCell, setPendingOpenEnumCell] = useState15(void 0);
|
|
3524
3532
|
atomicGestureRef.current = {
|
|
3525
3533
|
shouldOpenEnum: (rowId, columnId) => pendingOpenEnumCell?.rowId === rowId && pendingOpenEnumCell?.columnId === columnId,
|
|
3526
3534
|
// Mirrors exactly what `handleCellMouseDown` below does for every other
|
|
@@ -3545,7 +3553,7 @@ function DataGrid({
|
|
|
3545
3553
|
}
|
|
3546
3554
|
const pendingDragCellRef = useRef12(null);
|
|
3547
3555
|
const dragRafRef = useRef12(null);
|
|
3548
|
-
|
|
3556
|
+
useEffect11(() => {
|
|
3549
3557
|
if (!cellSelection.isDragging) return;
|
|
3550
3558
|
function handleMouseMove(event) {
|
|
3551
3559
|
const cellEl = event.target?.closest("[data-cell-row]");
|
|
@@ -3586,7 +3594,7 @@ function DataGrid({
|
|
|
3586
3594
|
}, [cellSelection.isDragging, cellSelection.updateDrag, cellSelection.endDrag]);
|
|
3587
3595
|
const pendingFillCellRef = useRef12(null);
|
|
3588
3596
|
const fillRafRef = useRef12(null);
|
|
3589
|
-
|
|
3597
|
+
useEffect11(() => {
|
|
3590
3598
|
if (!cellSelection.isFillDragging) return;
|
|
3591
3599
|
function handleMouseMove(event) {
|
|
3592
3600
|
const cellEl = event.target?.closest("[data-cell-row]");
|
|
@@ -3623,7 +3631,7 @@ function DataGrid({
|
|
|
3623
3631
|
};
|
|
3624
3632
|
}, [cellSelection.isFillDragging, cellSelection.updateFillDrag, cellSelection.endFillDrag]);
|
|
3625
3633
|
const wasEditingCellRef = useRef12(void 0);
|
|
3626
|
-
|
|
3634
|
+
useEffect11(() => {
|
|
3627
3635
|
const wasEditing = wasEditingCellRef.current !== void 0;
|
|
3628
3636
|
wasEditingCellRef.current = cellEditingCtx?.editingCell;
|
|
3629
3637
|
if (!wasEditing || cellEditingCtx?.editingCell) return;
|
|
@@ -4252,7 +4260,7 @@ function DataGrid({
|
|
|
4252
4260
|
// src/tree/TreeDataGrid.tsx
|
|
4253
4261
|
import { useVirtualizer as useVirtualizer2 } from "@tanstack/react-virtual";
|
|
4254
4262
|
import { AlertCircle, ChevronDown as ChevronDown2, ChevronRight as ChevronRight2, Loader2 as Loader22 } from "lucide-react";
|
|
4255
|
-
import { Fragment as Fragment5, useEffect as
|
|
4263
|
+
import { Fragment as Fragment5, useEffect as useEffect12, useMemo as useMemo10, useRef as useRef13 } from "react";
|
|
4256
4264
|
|
|
4257
4265
|
// src/tree/flattenTree.ts
|
|
4258
4266
|
function flattenTree(roots, accessors, expanded, childrenOverride) {
|
|
@@ -4297,7 +4305,7 @@ function computeSelectionStates(roots, accessors, childrenOverride, selectedIds)
|
|
|
4297
4305
|
}
|
|
4298
4306
|
|
|
4299
4307
|
// src/tree/useTreeState.ts
|
|
4300
|
-
import { useCallback as useCallback5, useMemo as useMemo9, useState as
|
|
4308
|
+
import { useCallback as useCallback5, useMemo as useMemo9, useState as useState16 } from "react";
|
|
4301
4309
|
function useTreeState({
|
|
4302
4310
|
data,
|
|
4303
4311
|
getRowId,
|
|
@@ -4309,7 +4317,7 @@ function useTreeState({
|
|
|
4309
4317
|
childrenMap: controlledChildrenMap,
|
|
4310
4318
|
onChildrenMapChange
|
|
4311
4319
|
}) {
|
|
4312
|
-
const [internalExpanded, setInternalExpanded] =
|
|
4320
|
+
const [internalExpanded, setInternalExpanded] = useState16({});
|
|
4313
4321
|
const expanded = controlledExpanded ?? internalExpanded;
|
|
4314
4322
|
const setExpanded = useCallback5(
|
|
4315
4323
|
(updater) => {
|
|
@@ -4321,7 +4329,7 @@ function useTreeState({
|
|
|
4321
4329
|
},
|
|
4322
4330
|
[controlledExpanded, onExpandedChange]
|
|
4323
4331
|
);
|
|
4324
|
-
const [internalChildrenMap, setInternalChildrenMap] =
|
|
4332
|
+
const [internalChildrenMap, setInternalChildrenMap] = useState16(/* @__PURE__ */ new Map());
|
|
4325
4333
|
const childrenMap = controlledChildrenMap ?? internalChildrenMap;
|
|
4326
4334
|
const setChildrenMap = useCallback5(
|
|
4327
4335
|
(updater) => {
|
|
@@ -4333,8 +4341,8 @@ function useTreeState({
|
|
|
4333
4341
|
},
|
|
4334
4342
|
[controlledChildrenMap, onChildrenMapChange]
|
|
4335
4343
|
);
|
|
4336
|
-
const [loadingIds, setLoadingIds] =
|
|
4337
|
-
const [errorIds, setErrorIds] =
|
|
4344
|
+
const [loadingIds, setLoadingIds] = useState16(/* @__PURE__ */ new Set());
|
|
4345
|
+
const [errorIds, setErrorIds] = useState16(/* @__PURE__ */ new Map());
|
|
4338
4346
|
const resolveHasChildren = useMemo9(
|
|
4339
4347
|
() => hasChildren ?? ((row) => (getChildren(row)?.length ?? 0) > 0),
|
|
4340
4348
|
[hasChildren, getChildren]
|
|
@@ -4507,7 +4515,7 @@ function TreeDataGrid({
|
|
|
4507
4515
|
onChildrenMapChange
|
|
4508
4516
|
});
|
|
4509
4517
|
const didAutoExpand = useRef13(false);
|
|
4510
|
-
|
|
4518
|
+
useEffect12(() => {
|
|
4511
4519
|
if (didAutoExpand.current) return;
|
|
4512
4520
|
didAutoExpand.current = true;
|
|
4513
4521
|
if (initialExpandedLevel > 0) void expandToLevel(initialExpandedLevel);
|