@bmsuisse/datagrid 0.25.0 → 0.25.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/index.d.ts CHANGED
@@ -935,6 +935,29 @@ interface TreeDataGridProps<TRow> extends TreeAccessors<TRow> {
935
935
  /** Controlled expanded state, keyed by node id. Omit for the grid to own this itself. */
936
936
  expanded?: Record<string, boolean>;
937
937
  onExpandedChange?: (expanded: Record<string, boolean>) => void;
938
+ /**
939
+ * Controlled lazy-children cache, keyed by node id — same
940
+ * controlled/uncontrolled convention as `expanded` above. Omit for the
941
+ * grid to own this itself (the common case, and the only way earlier
942
+ * versions of this component worked).
943
+ *
944
+ * Supply this when a caller needs to force a specific node's cached batch
945
+ * to be replaced with fresher data fetched *outside* the normal
946
+ * expand/collapse flow above (`onLoadChildren` only ever runs once per
947
+ * node id per the doc on it) — e.g. after an edit made to one of that
948
+ * node's children was saved, and the caller re-fetched that batch via its
949
+ * own `onLoadChildren` function to pick up the server's new state. Setting
950
+ * `childrenMap` to a new map containing that node's id (typically via
951
+ * `onChildrenMapChange`'s own setter, called by the caller's re-fetch
952
+ * logic) makes this component's flattened rows use the fresh batch on the
953
+ * very next render — without this, a caller's own separate copy of that
954
+ * data has nowhere to feed back into what actually gets rendered, no
955
+ * matter how it's refreshed, since only this component's internal cache
956
+ * (or an eager `getChildren(row)`) is ever consulted for a lazily-loaded
957
+ * node's children.
958
+ */
959
+ childrenMap?: ReadonlyMap<string, TRow[]>;
960
+ onChildrenMapChange?: (childrenMap: ReadonlyMap<string, TRow[]>) => void;
938
961
  /** Pixels of left padding added per depth level to the tree column's cell. Defaults to 20. */
939
962
  indentSize?: number;
940
963
  /**
@@ -1047,7 +1070,7 @@ interface TreeDataGridProps<TRow> extends TreeAccessors<TRow> {
1047
1070
  * column's cell matches `treeColumnId` (defaults to `columns[0]`); every
1048
1071
  * other column renders exactly like it would in `<DataGrid>`.
1049
1072
  */
1050
- declare function TreeDataGrid<TRow>({ columns, data, treeColumnId, getRowId, getChildren, hasChildren, onLoadChildren, initialExpandedLevel, expanded: controlledExpanded, onExpandedChange, indentSize, getRowProps, getRowTestId, rowActions, virtualizeThreshold, estimatedRowHeight, maxBodyHeight, selectedIds: controlledSelectedIds, onSelectedIdsChange, getRowSelectionState, isRowSelectionDisabled, zebra, }: TreeDataGridProps<TRow>): ReactElement;
1073
+ declare function TreeDataGrid<TRow>({ columns, data, treeColumnId, getRowId, getChildren, hasChildren, onLoadChildren, initialExpandedLevel, expanded: controlledExpanded, onExpandedChange, childrenMap: controlledChildrenMap, onChildrenMapChange, indentSize, getRowProps, getRowTestId, rowActions, virtualizeThreshold, estimatedRowHeight, maxBodyHeight, selectedIds: controlledSelectedIds, onSelectedIdsChange, getRowSelectionState, isRowSelectionDisabled, zebra, }: TreeDataGridProps<TRow>): ReactElement;
1051
1074
 
1052
1075
  interface FlatTreeRow<TRow> {
1053
1076
  row: TRow;
@@ -1085,6 +1108,8 @@ interface UseTreeStateOptions<TRow> extends TreeAccessors<TRow> {
1085
1108
  onLoadChildren?: (row: TRow) => Promise<TRow[]>;
1086
1109
  expanded?: Record<string, boolean>;
1087
1110
  onExpandedChange?: (expanded: Record<string, boolean>) => void;
1111
+ childrenMap?: ReadonlyMap<string, TRow[]>;
1112
+ onChildrenMapChange?: (childrenMap: ReadonlyMap<string, TRow[]>) => void;
1088
1113
  }
1089
1114
  /**
1090
1115
  * Owns everything `<TreeDataGrid>` needs beyond plain rendering: expand
@@ -1099,6 +1124,6 @@ interface UseTreeStateOptions<TRow> extends TreeAccessors<TRow> {
1099
1124
  * reset (e.g. switching to a different root entity entirely) should remount
1100
1125
  * `<TreeDataGrid>` via a `key` prop rather than rely on implicit magic here.
1101
1126
  */
1102
- declare function useTreeState<TRow>({ data, getRowId, getChildren, hasChildren, onLoadChildren, expanded: controlledExpanded, onExpandedChange, }: UseTreeStateOptions<TRow>): TreeStateController<TRow>;
1127
+ declare function useTreeState<TRow>({ data, getRowId, getChildren, hasChildren, onLoadChildren, expanded: controlledExpanded, onExpandedChange, childrenMap: controlledChildrenMap, onChildrenMapChange, }: UseTreeStateOptions<TRow>): TreeStateController<TRow>;
1103
1128
 
1104
1129
  export { ActionsMenu, type BaseColumn, type BooleanColumn, BooleanFilter, type ClientProcessingResult, type ColumnAlign, type ColumnDef, type ColumnGroup, ColumnSelector, type ColumnSelectorProps, type ColumnVisibility, type CompositeFilterDescriptor, DataGrid, type DataGridProps, type DataSource, type DateColumn, DateRangeFilter, type DebouncedCallback, type EnumColumn, EnumFilter, type EnumOption, type FilterDescriptor, type FilterOperator, type FilterWidgetProps, type FlatTreeRow, type GridState, type GridStateController, type MenuItem, type MenuItemContext, type NumberColumn, NumberComparisonFilter, NumberHistogramFilter, type NumberHistogramFilterProps, NumberRangeFilter, type ResolvedMenuItem, type SortDescriptor, type StringColumn, StringFilter, type TreeAccessors, TreeDataGrid, type TreeDataGridProps, type TreeStateController, UNARY_OPERATORS, type UseTreeStateOptions, alignClassName, canHideColumn, canHideGroup, countVisible, defaultAlign, defaultFormat, evaluateFilter, facetedNumberValues, fieldKey, flattenTree, getColumnValue, groupColumns, isColumnVisible, isCompositeFilterDescriptor, isFilterDescriptor, isFilterable, isSortable, processClientData, renderDefaultFilterWidget, resolveMenuItems, storageKeyFor, useDebouncedCallback, useGridState, useTreeState };
package/dist/index.js CHANGED
@@ -2480,7 +2480,9 @@ function useTreeState({
2480
2480
  hasChildren,
2481
2481
  onLoadChildren,
2482
2482
  expanded: controlledExpanded,
2483
- onExpandedChange
2483
+ onExpandedChange,
2484
+ childrenMap: controlledChildrenMap,
2485
+ onChildrenMapChange
2484
2486
  }) {
2485
2487
  const [internalExpanded, setInternalExpanded] = useState7({});
2486
2488
  const expanded = controlledExpanded ?? internalExpanded;
@@ -2494,7 +2496,18 @@ function useTreeState({
2494
2496
  },
2495
2497
  [controlledExpanded, onExpandedChange]
2496
2498
  );
2497
- const [childrenMap, setChildrenMap] = useState7(/* @__PURE__ */ new Map());
2499
+ const [internalChildrenMap, setInternalChildrenMap] = useState7(/* @__PURE__ */ new Map());
2500
+ const childrenMap = controlledChildrenMap ?? internalChildrenMap;
2501
+ const setChildrenMap = useCallback3(
2502
+ (updater) => {
2503
+ if (controlledChildrenMap) {
2504
+ onChildrenMapChange?.(updater(controlledChildrenMap));
2505
+ } else {
2506
+ setInternalChildrenMap((prev) => new Map(updater(prev)));
2507
+ }
2508
+ },
2509
+ [controlledChildrenMap, onChildrenMapChange]
2510
+ );
2498
2511
  const [loadingIds, setLoadingIds] = useState7(/* @__PURE__ */ new Set());
2499
2512
  const [errorIds, setErrorIds] = useState7(/* @__PURE__ */ new Map());
2500
2513
  const resolveHasChildren = useMemo7(
@@ -2532,7 +2545,7 @@ function useTreeState({
2532
2545
  });
2533
2546
  }
2534
2547
  },
2535
- [childrenMap, getChildren, getRowId, onLoadChildren]
2548
+ [childrenMap, getChildren, getRowId, onLoadChildren, setChildrenMap]
2536
2549
  );
2537
2550
  const toggleExpand = useCallback3(
2538
2551
  (row) => {
@@ -2627,6 +2640,8 @@ function TreeDataGrid({
2627
2640
  initialExpandedLevel = 0,
2628
2641
  expanded: controlledExpanded,
2629
2642
  onExpandedChange,
2643
+ childrenMap: controlledChildrenMap,
2644
+ onChildrenMapChange,
2630
2645
  indentSize = 20,
2631
2646
  getRowProps,
2632
2647
  getRowTestId,
@@ -2651,7 +2666,9 @@ function TreeDataGrid({
2651
2666
  hasChildren,
2652
2667
  onLoadChildren,
2653
2668
  expanded: controlledExpanded,
2654
- onExpandedChange
2669
+ onExpandedChange,
2670
+ childrenMap: controlledChildrenMap,
2671
+ onChildrenMapChange
2655
2672
  });
2656
2673
  const didAutoExpand = useRef6(false);
2657
2674
  useEffect8(() => {
@@ -2720,6 +2737,7 @@ function TreeDataGrid({
2720
2737
  {
2721
2738
  ref: measureRef,
2722
2739
  ...rowProps,
2740
+ "data-index": index,
2723
2741
  "data-testid": rowTestId,
2724
2742
  className: rowProps?.className ? cn(
2725
2743
  "border-b border-border divide-x divide-border",