@bmsuisse/datagrid 0.27.0 → 0.28.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 CHANGED
@@ -1,4 +1,4 @@
1
- import { ReactNode, ReactElement, ComponentType } from 'react';
1
+ import { ReactNode, ReactElement, ComponentType, RefObject } from 'react';
2
2
  import { ColumnSizingState, RowData } from '@tanstack/react-table';
3
3
  export { ColumnSizingState } from '@tanstack/react-table';
4
4
 
@@ -1226,6 +1226,54 @@ interface DebouncedCallback<TArgs extends unknown[]> {
1226
1226
  */
1227
1227
  declare function useDebouncedCallback<TArgs extends unknown[]>(callback: (...args: TArgs) => void, delayMs: number): DebouncedCallback<TArgs>;
1228
1228
 
1229
+ interface GroupExpansionController {
1230
+ /** The resolved (controlled-or-internal) expand state, keyed by group key. */
1231
+ expandedGroups: Record<string, boolean>;
1232
+ /** A key absent from `expandedGroups` (a group never toggled since it was first seen) falls back to `defaultGroupsExpanded`, not `false`. */
1233
+ isGroupExpanded: (key: string) => boolean;
1234
+ toggleGroupExpanded: (key: string) => void;
1235
+ }
1236
+ /**
1237
+ * Same controlled/uncontrolled pattern as `<DataGrid>`'s/`<TreeDataGrid>`'s
1238
+ * own `selectedIds`/`columnSizing`: both `controlledExpandedGroups` and
1239
+ * `onExpandedGroupsChange` must be supplied together to actually control
1240
+ * this state — omit both to let this hook own it internally. Shared between
1241
+ * the two grids' `groupBy` support so a fix to the fallback/toggle logic
1242
+ * never has to be made twice.
1243
+ *
1244
+ * `isGroupExpanded`/`toggleGroupExpanded` are stable (`useCallback`-wrapped)
1245
+ * across renders as long as `expandedGroups`/`defaultGroupsExpanded`/
1246
+ * `onExpandedGroupsChange` don't change — callers can safely list them in a
1247
+ * `useMemo`/`useEffect` dependency array without defeating memoization.
1248
+ */
1249
+ declare function useGroupExpansion(defaultGroupsExpanded: boolean, controlledExpandedGroups: Record<string, boolean> | undefined, onExpandedGroupsChange: ((expanded: Record<string, boolean>) => void) | undefined): GroupExpansionController;
1250
+
1251
+ interface StickyGroupHeaderTop {
1252
+ /** Attach to the grid's own `<thead>`. */
1253
+ theadRef: RefObject<HTMLTableSectionElement>;
1254
+ /** The measured `<thead>` height in pixels — `0` until first measured, or whenever `enabled` is false. */
1255
+ groupHeaderTop: number;
1256
+ }
1257
+ /**
1258
+ * Measures the real header height so a sticky group-header row can sit
1259
+ * exactly below it (its own `top` style) while member rows scroll past
1260
+ * underneath. `ResizeObserver` rather than a one-off measurement since
1261
+ * header height can change after mount (e.g. a column's header content
1262
+ * wrapping to a second line, or a resizable column changing the header
1263
+ * row's layout). Shared between `<DataGrid>` and `<TreeDataGrid>`'s own
1264
+ * `groupBy` support.
1265
+ */
1266
+ declare function useStickyGroupHeaderTop(enabled: boolean): StickyGroupHeaderTop;
1267
+
1268
+ /**
1269
+ * Single source of truth for "which columns actually render" — filters
1270
+ * `columns` down to whatever `columnVisibility` marks visible, or returns
1271
+ * `columns` unchanged when `columnVisibility` is omitted. Shared between
1272
+ * `<DataGrid>` and `<TreeDataGrid>` so both read `columnVisibility` (e.g.
1273
+ * driven by a `<ColumnSelector>`) the same way.
1274
+ */
1275
+ declare function useVisibleColumns<TRow>(columns: ColumnDef<TRow>[], columnVisibility: ColumnVisibility | undefined): ColumnDef<TRow>[];
1276
+
1229
1277
  /**
1230
1278
  * Accessor-based node shape, matching `<DataGrid>`'s `getRowId` convention
1231
1279
  * rather than requiring `TRow` to carry specific field names.
@@ -1258,6 +1306,16 @@ interface TreeDataGridProps<TRow> extends TreeAccessors<TRow> {
1258
1306
  * chevron prepended. Defaults to the first column in `columns`.
1259
1307
  */
1260
1308
  treeColumnId?: string;
1309
+ /**
1310
+ * Controlled column visibility, e.g. driven by a `<ColumnSelector>` next
1311
+ * to the grid — same convention as `<DataGrid>`'s own `columnVisibility`.
1312
+ * `<TreeDataGrid>` never owns this state itself; omit to render every
1313
+ * column in `columns`. Note that hiding `treeColumnId` itself (or the
1314
+ * first column, when `treeColumnId` is omitted) hides the indentation/
1315
+ * expand-collapse chevron along with it, since those are only ever
1316
+ * attached to that one column's cell.
1317
+ */
1318
+ columnVisibility?: ColumnVisibility;
1261
1319
  /**
1262
1320
  * Fetches a node's children on demand. Omit this entirely for a fully
1263
1321
  * eager tree (all children already present via `getChildren`) — a node
@@ -1389,6 +1447,35 @@ interface TreeDataGridProps<TRow> extends TreeAccessors<TRow> {
1389
1447
  } | undefined;
1390
1448
  /** Disables just the checkbox for a specific row. Defaults to `() => false`. */
1391
1449
  isRowSelectionDisabled?: (row: TRow) => boolean;
1450
+ /**
1451
+ * Buckets the *root-level* rows in `data` into groups, rendering one
1452
+ * full-width `colSpan`'d group-header row before each bucket's own
1453
+ * (recursively flattened, depth-first) rows — same convention as
1454
+ * `<DataGrid>`'s own `groupBy`. Single level only, and only ever applied
1455
+ * to roots: a node's children are never split across groups from their
1456
+ * parent, since grouping an already-hierarchical tree by anything other
1457
+ * than "which root it belongs to" wouldn't have a sensible rendering.
1458
+ * Groups appear in first-seen bucket order — roots are never re-sorted to
1459
+ * cluster a group together. Omit entirely to disable — no grouping, no
1460
+ * header rows, unchanged default rendering.
1461
+ *
1462
+ * Not supported together with virtualization — when both are set,
1463
+ * virtualization is silently disabled and the tree renders as a plain,
1464
+ * fully-rendered (but still grouped) `<table>` instead, same limitation
1465
+ * `<DataGrid>` has.
1466
+ */
1467
+ groupBy?: (row: TRow) => string;
1468
+ /** Customizes a group-header row's content. Defaults to `` `${key} (${rootCount})` `` — `rootCount` counts only that group's root rows, not their descendants. */
1469
+ renderGroupHeader?: (key: string, roots: TRow[], expanded: boolean) => ReactNode;
1470
+ /** Whether a newly-seen group starts expanded. Defaults to true. */
1471
+ defaultGroupsExpanded?: boolean;
1472
+ /**
1473
+ * Controlled per-group expand/collapse state, keyed by the `groupBy` key.
1474
+ * Both must be supplied together to control it — omit both for
1475
+ * `<TreeDataGrid>` to own this state internally.
1476
+ */
1477
+ expandedGroups?: Record<string, boolean>;
1478
+ onExpandedGroupsChange?: (expanded: Record<string, boolean>) => void;
1392
1479
  /** Alternates body row backgrounds for readability on wide/dense tables. Defaults to true. */
1393
1480
  zebra?: boolean;
1394
1481
  /**
@@ -1419,7 +1506,7 @@ interface TreeDataGridProps<TRow> extends TreeAccessors<TRow> {
1419
1506
  * column's cell matches `treeColumnId` (defaults to `columns[0]`); every
1420
1507
  * other column renders exactly like it would in `<DataGrid>`.
1421
1508
  */
1422
- 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, editing, }: TreeDataGridProps<TRow>): ReactElement;
1509
+ declare function TreeDataGrid<TRow>({ columns, data, treeColumnId, columnVisibility, getRowId, getChildren, hasChildren, onLoadChildren, initialExpandedLevel, expanded: controlledExpanded, onExpandedChange, childrenMap: controlledChildrenMap, onChildrenMapChange, indentSize, getRowProps, getRowTestId, rowActions, virtualizeThreshold, estimatedRowHeight, maxBodyHeight, selectedIds: controlledSelectedIds, onSelectedIdsChange, getRowSelectionState, isRowSelectionDisabled, groupBy, renderGroupHeader, defaultGroupsExpanded, expandedGroups: controlledExpandedGroups, onExpandedGroupsChange, zebra, editing, }: TreeDataGridProps<TRow>): ReactElement;
1423
1510
 
1424
1511
  interface FlatTreeRow<TRow> {
1425
1512
  row: TRow;
@@ -1475,4 +1562,4 @@ interface UseTreeStateOptions<TRow> extends TreeAccessors<TRow> {
1475
1562
  */
1476
1563
  declare function useTreeState<TRow>({ data, getRowId, getChildren, hasChildren, onLoadChildren, expanded: controlledExpanded, onExpandedChange, childrenMap: controlledChildrenMap, onChildrenMapChange, }: UseTreeStateOptions<TRow>): TreeStateController<TRow>;
1477
1564
 
1478
- export { ActionsMenu, type BaseColumn, type BooleanColumn, BooleanEditor, BooleanFilter, type ClientProcessingResult, type ColumnAlign, type ColumnDef, type ColumnGroup, ColumnSelector, type ColumnSelectorProps, type ColumnVisibility, type CompositeFilterDescriptor, DataGrid, type DataGridProps, type DataSource, type DateColumn, DateEditor, DateRangeFilter, type DebouncedCallback, EditFieldError, type EditWidgetProps, type EditedRow, EditingBar, type EditingBarProps, type EditingCellContext, type EditingOptions, type EditingState, type EnumColumn, EnumEditor, EnumFilter, type EnumOption, type FilterDescriptor, type FilterOperator, type FilterWidgetProps, type FlatTreeRow, type GridState, type GridStateController, type MenuItem, type MenuItemContext, type NumberColumn, NumberComparisonFilter, NumberEditor, NumberHistogramFilter, type NumberHistogramFilterProps, NumberRangeFilter, type PendingRowEdit, type ResolvedMenuItem, type SortDescriptor, type StringColumn, StringEditor, StringFilter, type TreeAccessors, TreeDataGrid, type TreeDataGridProps, type TreeStateController, UNARY_OPERATORS, type UseTreeStateOptions, alignClassName, canHideColumn, canHideGroup, countVisible, defaultAlign, defaultFormat, editErrorId, evaluateFilter, facetedNumberValues, fieldKey, flattenTree, getColumnValue, groupColumns, isColumnVisible, isCompositeFilterDescriptor, isEditable, isFilterDescriptor, isFilterable, isSortable, processClientData, renderDefaultEditWidget, renderDefaultFilterWidget, renderEditableCell, resolveMenuItems, storageKeyFor, toDate, useDebouncedCallback, useEditingState, useGridState, useTreeState };
1565
+ export { ActionsMenu, type BaseColumn, type BooleanColumn, BooleanEditor, BooleanFilter, type ClientProcessingResult, type ColumnAlign, type ColumnDef, type ColumnGroup, ColumnSelector, type ColumnSelectorProps, type ColumnVisibility, type CompositeFilterDescriptor, DataGrid, type DataGridProps, type DataSource, type DateColumn, DateEditor, DateRangeFilter, type DebouncedCallback, EditFieldError, type EditWidgetProps, type EditedRow, EditingBar, type EditingBarProps, type EditingCellContext, type EditingOptions, type EditingState, type EnumColumn, EnumEditor, EnumFilter, type EnumOption, type FilterDescriptor, type FilterOperator, type FilterWidgetProps, type FlatTreeRow, type GridState, type GridStateController, type GroupExpansionController, type MenuItem, type MenuItemContext, type NumberColumn, NumberComparisonFilter, NumberEditor, NumberHistogramFilter, type NumberHistogramFilterProps, NumberRangeFilter, type PendingRowEdit, type ResolvedMenuItem, type SortDescriptor, type StickyGroupHeaderTop, type StringColumn, StringEditor, StringFilter, type TreeAccessors, TreeDataGrid, type TreeDataGridProps, type TreeStateController, UNARY_OPERATORS, type UseTreeStateOptions, alignClassName, canHideColumn, canHideGroup, countVisible, defaultAlign, defaultFormat, editErrorId, evaluateFilter, facetedNumberValues, fieldKey, flattenTree, getColumnValue, groupColumns, isColumnVisible, isCompositeFilterDescriptor, isEditable, isFilterDescriptor, isFilterable, isSortable, processClientData, renderDefaultEditWidget, renderDefaultFilterWidget, renderEditableCell, resolveMenuItems, storageKeyFor, toDate, useDebouncedCallback, useEditingState, useGridState, useGroupExpansion, useStickyGroupHeaderTop, useTreeState, useVisibleColumns };