@jielga/tmdatagrid 2.0.0 → 2.1.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.
@@ -6,7 +6,7 @@ Reference for the `rows` skill.
6
6
 
7
7
  | Name | Kind | Type | Default | What it does |
8
8
  | --- | --- | --- | --- | --- |
9
- | `selectionMode` | Option | `"checkbox" \| "row" \| "checkboxAndHighlight" \| "highlight"` | `"checkbox"` | What selecting looks like and what a row click does. |
9
+ | `selectionMode` | Option | `TMDataGridSelectionMode`: `"checkbox" \| "row" \| "checkboxAndHighlight" \| "highlight"` | `"checkbox"` | What selecting looks like and what a row click does. |
10
10
  | `enableRowSelection` | Table option | `boolean \| ((row) => boolean)` | `true` | `false` removes the checkbox column and row-click selection. |
11
11
  | `enableMultiRowSelection` | Table option | `boolean` | `true` | `false` limits the selection to one row and drops group checkboxes. |
12
12
  | `showSelectedBackground` | Option | `boolean` | Follows the mode | Whether selected rows take a background tint. |
@@ -14,7 +14,8 @@ Reference for the `rows` skill.
14
14
  | `onHighlightedRowChange` | Callback | `(rowId: string \| null) => void` | – | Fires when the highlight moves. |
15
15
  | `SELECT_COLUMN_ID` | Export | `"__select__"` | – | Id of the generated checkbox column. |
16
16
  | `getSelectableRowIds` | Export | `(table) => string[]` | – | Ids the header checkbox would select. |
17
- | `resolveRowSelectionClick` | Export | `(args) => ResolvedRowSelection` | – | The desktop-list click rules, for a custom surface. |
17
+ | `resolveRowSelectionClick` | Export | `(args: ResolveRowSelectionClickArgs) => ResolvedRowSelection` | – | The desktop-list click rules, for a custom surface. |
18
+ | `ResolveRowSelectionClickArgs` · `TMDataGridRowClickModifiers` | Types | `{ rows, rowId, anchorRowId, modifiers, selection }` · `{ toggle, extend }` | – | What `resolveRowSelectionClick` takes, and its `modifiers`. |
18
19
  | `getDisplayedRows` | Export | `(table) => Row[]` | – | The rows currently on screen, paging respected. |
19
20
  | `isPagingActive` | Export | `(table) => boolean` | – | Whether a pager is in play. |
20
21
 
@@ -31,11 +32,13 @@ All are props of `TMDataGrid.Table`, not hook options.
31
32
  | `onCellClick` | `(args) => void` | Cell click. `args` is `TMDataGridCellEventArgs`. |
32
33
  | `onCellDoubleClick` | `(args) => void` | Cell double-click. |
33
34
  | `onCellContextMenu` | `(args) => void` | Cell right-click. |
34
- | `renderRowContextMenu` | `({ table, row, cell, close, internalItems }) => ReactNode` | Contents of the row's context menu. `null` for no menu. Reading `internalItems` hands the composition over. |
35
- | `renderColumnMenuItems` | `({ column, table, internalItems }) => ReactNode[]` | Contents of a column's menu. An empty list removes the button. |
35
+ | `renderRowContextMenu` | `TMDataGridRowContextMenuRenderer`: `(args: TMDataGridRowContextMenuArgs) => ReactNode` | Contents of the row's context menu. `null` for no menu. Reading `internalItems` hands the composition over. |
36
+ | `renderColumnMenuItems` | `TMDataGridColumnMenuItemsRenderer`: `(args: TMDataGridColumnMenuItemsArgs) => ReactNode[]` | Contents of a column's menu. An empty list removes the button. |
36
37
  | `rowContextMenuProps` | `MenuProps` | Passed to the Mantine `Menu` unchanged, apart from its open state. |
37
38
 
38
- `TMDataGridCellEventArgs` is `{ cell, row, column, event }`. The context-menu
39
+ `TMDataGridCellEventArgs` is `{ cell, row, column, event }`.
40
+ `TMDataGridRowContextMenuArgs` is `{ table, row, cell, close, internalItems }`,
41
+ and `TMDataGridColumnMenuItemsArgs` is `{ column, table, internalItems }`. The context-menu
39
42
  slot's `cell` is `null` only when a custom cell renderer stopped the
40
43
  event. One `Menu` serves the whole body rather than one per row: a closed
41
44
  Mantine `Popover` still runs its hooks on every render, and the virtualized body
@@ -76,13 +79,15 @@ Row data attributes:
76
79
 
77
80
  | Name | Kind | Type | Default | What it does |
78
81
  | --- | --- | --- | --- | --- |
79
- | `renderDetails` | Option | `({ row, table }) => ReactNode` | – | Contents of the panel. Setting it adds the lane. |
82
+ | `renderDetails` | Option | `TMDataGridDetailsRenderer`: `(args: TMDataGridDetailsArgs) => ReactNode` | – | Contents of the panel. Setting it adds the lane. `TMDataGridDetailsArgs` is `{ row, table }`. |
80
83
  | `renderDetailsEstHeight` | Option | `number` | `160` | Height the virtualizer assumes for an unmeasured panel. |
84
+ | `detailsColumnPosition` | Option | `"left" \| "right"` | `"left"` | Which edge the lane is pinned to. `"right"` places it after every column, inside the edit lane. |
81
85
  | `initialState.expanded` | Table option | `ExpandedState` | `{}` | Rows open at mount. A `data` slice, so it persists. |
82
- | `autoResetExpanded` | Table option | `boolean` | `true` | `false` keeps panels open when `data` changes. |
86
+ | `autoResetExpanded` | Table option | `boolean` | `false` | `true` closes the panels when the `data` array changes. Off by default, so a draft commit keeps them open. |
83
87
  | `DETAILS_COLUMN_ID` | Export | `"__details__"` | – | Id of the generated chevron column. |
84
88
  | `resolveExpandAll` | Export | `(args) => ExpandedState` | – | Expand or collapse every group, or every panel, but not both. |
85
89
  | `areAllRowsExpanded` | Export | `(args) => boolean` | – | Whether every row of one target is open. |
90
+ | `TMDataGridExpandAllArgs` · `TMDataGridExpandTarget` | Types | `{ rows, expanded, target }` · `"groups" \| "details"` | – | What `areAllRowsExpanded` takes (`resolveExpandAll` also takes `expand`), and its `target`. |
86
91
  | `data-dg-part="details"` | Data attribute | – | – | The panel element, carrying the row's `data-row-id`. |
87
92
 
88
93
  One `expanded` state opens two unrelated things - a group row into its children,
@@ -115,4 +120,5 @@ table.setExpanded(
115
120
  | `ROW_NUMBER_COLUMN_ID` | Export | `"__rowNumber__"` | – | Id of the generated number gutter. |
116
121
 
117
122
  Lane order, left to right: row number, checkbox, tree, details, your columns,
118
- edit.
123
+ edit. Under `detailsColumnPosition: "right"`, details sits between your columns
124
+ and edit.
@@ -15,7 +15,7 @@ description: >
15
15
  metadata:
16
16
  type: core
17
17
  library: '@jielga/tmdatagrid'
18
- library_version: '2.0.0'
18
+ library_version: '2.1.0'
19
19
  sources:
20
20
  - 'Jielga/TMDataGrid:packages/tmdatagrid/docs/server-side.md'
21
21
  - 'Jielga/TMDataGrid:packages/tmdatagrid/docs/server-query.md'
@@ -13,7 +13,7 @@ description: >
13
13
  metadata:
14
14
  type: core
15
15
  library: '@jielga/tmdatagrid'
16
- library_version: '2.0.0'
16
+ library_version: '2.1.0'
17
17
  sources:
18
18
  - 'Jielga/TMDataGrid:packages/tmdatagrid/docs/testing.md'
19
19
  - 'Jielga/TMDataGrid:playwright/support/DataGrid.ts'
@@ -12,7 +12,7 @@ description: >
12
12
  metadata:
13
13
  type: core
14
14
  library: '@jielga/tmdatagrid'
15
- library_version: '2.0.0'
15
+ library_version: '2.1.0'
16
16
  sources:
17
17
  - 'Jielga/TMDataGrid:packages/tmdatagrid/docs/testing.md'
18
18
  - 'Jielga/TMDataGrid:packages/tmdatagrid/test/gallery/main.tsx'
@@ -12,7 +12,7 @@ description: >
12
12
  metadata:
13
13
  type: core
14
14
  library: '@jielga/tmdatagrid'
15
- library_version: '2.0.0'
15
+ library_version: '2.1.0'
16
16
  sources:
17
17
  - 'Jielga/TMDataGrid:packages/tmdatagrid/docs/testing.md'
18
18
  - 'Jielga/TMDataGrid:packages/tmdatagrid/docs/editing.md'
@@ -51,6 +51,11 @@
51
51
  --dg-header-height: 44px;
52
52
  --dg-font-size: var(--mantine-font-size-sm);
53
53
  --dg-padding: 10px;
54
+ /* The header's font size. Resolved on the root, so it follows whatever
55
+ `--dg-font-size` the scale or an override gives the cells, until set on
56
+ its own:
57
+ <TMDataGrid style={{ "--dg-header-font-size": "var(--mantine-font-size-md)" }} /> */
58
+ --dg-header-font-size: var(--dg-font-size);
54
59
  /* Background of a selected row, when `showSelectedBackground` is on. Override
55
60
  it on the grid:
56
61
  <TMDataGrid style={{ "--dg-row-selected-bg": "var(--mantine-color-blue-0)" }} /> */
@@ -7,7 +7,7 @@
7
7
  min-width: 0;
8
8
  min-height: var(--dg-header-height);
9
9
  font-weight: 600;
10
- font-size: var(--dg-font-size);
10
+ font-size: var(--dg-header-font-size);
11
11
  background-color: var(--mantine-color-body);
12
12
  border-bottom: 1px solid var(--mantine-color-default-border);
13
13
  user-select: none;
@@ -100,13 +100,15 @@ export function createGroupColumn<TData extends RowData>(
100
100
  }
101
101
 
102
102
  /**
103
- * The generated details lane, prepended whenever `renderDetails` is set.
103
+ * The generated details lane, added whenever `renderDetails` is set.
104
104
  *
105
105
  * Structural, like the checkbox and tree columns: fixed width, pinned to the
106
- * left after both of them, not hideable, not movable and not resizable. Moving
107
- * or hiding the toggle would leave rows with panels that cannot be opened.
106
+ * edge `detailsColumnPosition` names, not hideable, not movable and not
107
+ * resizable. Moving or hiding the toggle would leave rows with panels that
108
+ * cannot be opened.
108
109
  *
109
- * Last of the three because it acts on a single record.
110
+ * Innermost on its edge - last of the left lanes, or first of the right ones,
111
+ * inside the edit lane - because it acts on a single record.
110
112
  *
111
113
  * A second toggle elsewhere is supported: `row.toggleExpanded()` is the entire
112
114
  * interface, and this lane is only the control the grid ships.
@@ -119,7 +121,7 @@ export function createDetailsColumn<TData extends RowData>(
119
121
  meta: {
120
122
  label,
121
123
  align: "center",
122
- // Structurally the last of the generated lanes.
124
+ // Structurally the innermost of the generated lanes.
123
125
  enableOrdering: false,
124
126
  },
125
127
  // A system lane: as wide as the control it holds and no wider. Fixed at
@@ -135,7 +137,7 @@ export function createDetailsColumn<TData extends RowData>(
135
137
  // Its visibility is not the user's to set: hiding it would strand every
136
138
  // panel behind a control that is no longer there.
137
139
  enableHiding: false,
138
- // Structurally pinned to the left; users shouldn't be able to move it.
140
+ // Structurally pinned to its edge; users shouldn't be able to move it.
139
141
  enablePinning: false,
140
142
  header: ({ table }) => <DetailsHeader table={table} />,
141
143
  cell: ({ row }) => <DetailsCell row={row} />,
@@ -12,6 +12,7 @@ import {
12
12
  columnGroupingFeature,
13
13
  columnOrderingFeature,
14
14
  columnPinningFeature,
15
+ type ColumnPinningState,
15
16
  columnResizingFeature,
16
17
  columnSizingFeature,
17
18
  columnVisibilityFeature,
@@ -77,7 +78,11 @@ import {
77
78
  type TMDataGridColumnType,
78
79
  tmDataGridFilterFn,
79
80
  } from "./core/filterOperators";
80
- import { getColumnDefaultOperator, isControlColumn } from "./core/columnUtils";
81
+ import {
82
+ getColumnDefaultOperator,
83
+ isControlColumn,
84
+ isGeneratedColumn,
85
+ } from "./core/columnUtils";
81
86
  import type { TMDataGridColumnFilterOptions } from "./core/filterControls";
82
87
  import {
83
88
  resolveFilterOptions,
@@ -1050,6 +1055,16 @@ export type UseTMDataGridOptions<TData extends RowData> = Omit<
1050
1055
  * state. An approximate value is enough.
1051
1056
  */
1052
1057
  renderDetailsEstHeight?: number;
1058
+ /**
1059
+ * Which edge the details lane sits on. Defaults to `"left"`.
1060
+ *
1061
+ * `"left"` pins the chevron after the row number, checkbox and tree lanes,
1062
+ * before every column of yours. `"right"` pins it after every column of
1063
+ * yours, inside the edit lane, so the chevron closes the row the way an
1064
+ * accordion's does. On either edge it stays a structural lane: the user
1065
+ * cannot move, hide or unpin it.
1066
+ */
1067
+ detailsColumnPosition?: "left" | "right";
1053
1068
  /**
1054
1069
  * Rows the virtualizer keeps mounted above and below the viewport. Defaults
1055
1070
  * to 6.
@@ -1149,6 +1164,7 @@ export function useTMDataGrid<TData extends RowData>({
1149
1164
  editing,
1150
1165
  renderDetails,
1151
1166
  renderDetailsEstHeight = DEFAULT_DETAILS_EST_HEIGHT,
1167
+ detailsColumnPosition = "left",
1152
1168
  overscan = DEFAULT_OVERSCAN,
1153
1169
  ...options
1154
1170
  }: UseTMDataGridOptions<TData>): TMDataGridApi<TData> {
@@ -1250,6 +1266,35 @@ export function useTMDataGrid<TData extends RowData>({
1250
1266
  // rest hold two - it gets the wider track.
1251
1267
  const editWideLane = editDraft;
1252
1268
 
1269
+ // The generated lanes are structurally pinned, outermost first on each edge,
1270
+ // and re-applied on top of anything restored: a snapshot cannot unpin one,
1271
+ // and a snapshot taken before `detailsColumnPosition` changed cannot pin the
1272
+ // details lane to the edge it has since left.
1273
+ const structuralPinning = (
1274
+ restored: Partial<ColumnPinningState> | undefined,
1275
+ ): ColumnPinningState => {
1276
+ const own = (ids: string[] | undefined) =>
1277
+ (ids ?? []).filter((id) => !isGeneratedColumn(id));
1278
+ const lane = (enabled: boolean, id: string) =>
1279
+ enabled && pinningEnabled ? [id] : [];
1280
+ const detailsOn = (edge: "left" | "right") =>
1281
+ detailsColumnEnabled && detailsColumnPosition === edge;
1282
+ return {
1283
+ start: [
1284
+ ...lane(rowNumbersEnabled, ROW_NUMBER_COLUMN_ID),
1285
+ ...lane(selectColumnEnabled, SELECT_COLUMN_ID),
1286
+ ...lane(groupColumnEnabled, GROUP_COLUMN_ID),
1287
+ ...lane(detailsOn("left"), DETAILS_COLUMN_ID),
1288
+ ...own(restored?.start),
1289
+ ],
1290
+ end: [
1291
+ ...own(restored?.end),
1292
+ ...lane(detailsOn("right"), DETAILS_COLUMN_ID),
1293
+ ...lane(editColumnEnabled, EDIT_COLUMN_ID),
1294
+ ],
1295
+ };
1296
+ };
1297
+
1253
1298
  const columns = useMemo(() => {
1254
1299
  const base = withTMDataGridDefaults<TData>(
1255
1300
  options.columns as ReadonlyArray<TMDataGridColumnDef<TData>>,
@@ -1262,8 +1307,12 @@ export function useTMDataGrid<TData extends RowData>({
1262
1307
  //
1263
1308
  // The order is the order they are pinned in, and it follows what each one
1264
1309
  // is about: tick a row, find it in the tree the user grouped it into, then
1265
- // open it. The details chevron sits last because it acts on the record the
1266
- // lanes to its left have narrowed down to.
1310
+ // open it. The details chevron sits innermost on whichever edge it was
1311
+ // given - last of the left lanes, or first of the right ones - because it
1312
+ // acts on the record the lanes outside it have narrowed down to.
1313
+ const detailsColumn = detailsColumnEnabled
1314
+ ? [createDetailsColumn<TData>(detailsColumnLabel)]
1315
+ : [];
1267
1316
  return [
1268
1317
  // The gutter sits outside everything, the way a spreadsheet's does.
1269
1318
  ...(rowNumbersEnabled
@@ -1273,10 +1322,9 @@ export function useTMDataGrid<TData extends RowData>({
1273
1322
  ? [createSelectColumn<TData>(selectColumnLabel)]
1274
1323
  : []),
1275
1324
  ...(groupColumnEnabled ? [createGroupColumn<TData>(groupColumnLabel)] : []),
1276
- ...(detailsColumnEnabled
1277
- ? [createDetailsColumn<TData>(detailsColumnLabel)]
1278
- : []),
1325
+ ...(detailsColumnPosition === "left" ? detailsColumn : []),
1279
1326
  ...base,
1327
+ ...(detailsColumnPosition === "right" ? detailsColumn : []),
1280
1328
  // Last and pinned right - the row's Save belongs at the end of the row.
1281
1329
  ...(editColumnEnabled
1282
1330
  ? [createEditColumn<TData>(editColumnLabel, editWideLane)]
@@ -1287,6 +1335,7 @@ export function useTMDataGrid<TData extends RowData>({
1287
1335
  rowNumbersEnabled,
1288
1336
  selectColumnEnabled,
1289
1337
  detailsColumnEnabled,
1338
+ detailsColumnPosition,
1290
1339
  groupColumnEnabled,
1291
1340
  editColumnEnabled,
1292
1341
  editWideLane,
@@ -1619,37 +1668,14 @@ export function useTMDataGrid<TData extends RowData>({
1619
1668
  ? { [GROUP_COLUMN_ID]: initialGrouping.length > 0 }
1620
1669
  : {}),
1621
1670
  },
1622
- columnPinning: {
1623
- // The generated columns are structurally pinned, so they are re-applied
1624
- // on top of anything restored from storage.
1625
- start: [
1626
- ...(rowNumbersEnabled && pinningEnabled ? [ROW_NUMBER_COLUMN_ID] : []),
1627
- ...(selectColumnEnabled && pinningEnabled ? [SELECT_COLUMN_ID] : []),
1628
- ...(groupColumnEnabled && pinningEnabled ? [GROUP_COLUMN_ID] : []),
1629
- ...(detailsColumnEnabled && pinningEnabled ? [DETAILS_COLUMN_ID] : []),
1630
- ...(
1631
- persistedState.columnPinning?.start ??
1632
- options.initialState?.columnPinning?.start ??
1633
- []
1634
- ).filter(
1635
- (id) =>
1636
- id !== ROW_NUMBER_COLUMN_ID &&
1637
- id !== SELECT_COLUMN_ID &&
1638
- id !== DETAILS_COLUMN_ID &&
1639
- id !== GROUP_COLUMN_ID,
1640
- ),
1641
- ],
1642
- // The edit lane mirrors the generated columns on the left: structurally
1643
- // pinned, outermost, re-applied over anything restored.
1644
- end: [
1645
- ...(
1646
- persistedState.columnPinning?.end ??
1647
- options.initialState?.columnPinning?.end ??
1648
- []
1649
- ).filter((id) => id !== EDIT_COLUMN_ID),
1650
- ...(editColumnEnabled && pinningEnabled ? [EDIT_COLUMN_ID] : []),
1651
- ],
1652
- },
1671
+ columnPinning: structuralPinning({
1672
+ start:
1673
+ persistedState.columnPinning?.start ??
1674
+ options.initialState?.columnPinning?.start,
1675
+ end:
1676
+ persistedState.columnPinning?.end ??
1677
+ options.initialState?.columnPinning?.end,
1678
+ }),
1653
1679
  pagination: {
1654
1680
  pageIndex: 0,
1655
1681
  pageSize: 25,
@@ -1964,27 +1990,7 @@ export function useTMDataGrid<TData extends RowData>({
1964
1990
  });
1965
1991
  table.setColumnSizing({ ...initial?.columnSizing });
1966
1992
  table.setColumnOrder([...(initial?.columnOrder ?? [])]);
1967
- table.setColumnPinning({
1968
- start: [
1969
- ...(rowNumbersEnabled && pinningEnabled ? [ROW_NUMBER_COLUMN_ID] : []),
1970
- ...(selectColumnEnabled && pinningEnabled ? [SELECT_COLUMN_ID] : []),
1971
- ...(groupColumnEnabled && pinningEnabled ? [GROUP_COLUMN_ID] : []),
1972
- ...(detailsColumnEnabled && pinningEnabled ? [DETAILS_COLUMN_ID] : []),
1973
- ...(initial?.columnPinning?.start ?? []).filter(
1974
- (id) =>
1975
- id !== ROW_NUMBER_COLUMN_ID &&
1976
- id !== SELECT_COLUMN_ID &&
1977
- id !== DETAILS_COLUMN_ID &&
1978
- id !== GROUP_COLUMN_ID,
1979
- ),
1980
- ],
1981
- end: [
1982
- ...(initial?.columnPinning?.end ?? []).filter(
1983
- (id) => id !== EDIT_COLUMN_ID,
1984
- ),
1985
- ...(editColumnEnabled && pinningEnabled ? [EDIT_COLUMN_ID] : []),
1986
- ],
1987
- });
1993
+ table.setColumnPinning(structuralPinning(initial?.columnPinning));
1988
1994
  };
1989
1995
  const resetSettings = useCallback(() => resetSettingsRef.current(), []);
1990
1996