@jielga/tmdatagrid 2.0.0-beta.2 → 2.0.0-beta.3

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.
@@ -111,10 +111,15 @@ export type TMDataGridLabels = {
111
111
  cancelRowEdit: string;
112
112
  /** Save tooltip when field errors block the row, with no row message. */
113
113
  editRowErrors: string;
114
- /** `EditActions`' Save, with the dirty-row count. */
114
+ /** `EditActions`' Save, with the count of rows in the draft store. */
115
115
  saveAllEdits: (rows: number) => string;
116
116
  /** `EditActions`' Discard. */
117
117
  discardAllEdits: string;
118
+ /**
119
+ * `EditActions`' note about rows still open - edited but not committed, so
120
+ * not part of the save. Shown only while there are any.
121
+ */
122
+ editRowsStillOpen: (rows: number) => string;
118
123
  /** The entry row's ✓ - commit the add. */
119
124
  confirmNewRow: string;
120
125
  /** The entry row's ✕ - drop the entry. */
@@ -243,6 +248,8 @@ export const TMDATAGRID_LABELS_EN: TMDataGridLabels = {
243
248
  editRowErrors: "Fix the marked cells",
244
249
  saveAllEdits: (rows) => (rows === 1 ? "Save 1 row" : `Save ${rows} rows`),
245
250
  discardAllEdits: "Discard",
251
+ editRowsStillOpen: (rows) =>
252
+ rows === 1 ? "1 row still being edited" : `${rows} rows still being edited`,
246
253
  confirmNewRow: "Add row",
247
254
  discardNewRow: "Discard new row",
248
255
  deleteRow: "Delete row",
@@ -103,6 +103,8 @@ export const TMDATAGRID_LABELS_SV: TMDataGridLabels = {
103
103
  editRowErrors: "Åtgärda de markerade cellerna",
104
104
  saveAllEdits: (rows) => (rows === 1 ? "Spara 1 rad" : `Spara ${rows} rader`),
105
105
  discardAllEdits: "Förkasta",
106
+ editRowsStillOpen: (rows) =>
107
+ rows === 1 ? "1 rad redigeras fortfarande" : `${rows} rader redigeras fortfarande`,
106
108
  confirmNewRow: "Lägg till rad",
107
109
  discardNewRow: "Släng ny rad",
108
110
  deleteRow: "Ta bort rad",
@@ -82,7 +82,10 @@ export {
82
82
  type TMDataGridEditApi,
83
83
  type TMDataGridEditChange,
84
84
  type TMDataGridEditCommitArgs,
85
+ type TMDataGridSaveDraftsArgs,
85
86
  type TMDataGridEditCommitDraftsArgs,
87
+ type TMDataGridAddRowsOptions,
88
+ type TMDataGridAddRowsResult,
86
89
  type TMDataGridEditField,
87
90
  type TMDataGridEditMode,
88
91
  type TMDataGridEditorArgs,
@@ -51,7 +51,7 @@ import {
51
51
  createEditEngine,
52
52
  type TMDataGridEditApi,
53
53
  type TMDataGridEditCommitArgs,
54
- type TMDataGridEditCommitDraftsArgs,
54
+ type TMDataGridSaveDraftsArgs,
55
55
  type TMDataGridEditEngineContext,
56
56
  type TMDataGridColumnEditOptions,
57
57
  type TMDataGridEditMode,
@@ -390,7 +390,7 @@ export type TMDataGridApi<TData extends RowData> = {
390
390
  * out the same TanStack Form the inline editors write through, so a drawer
391
391
  * or detail panel can share a row's draft. Inert until `editing` is set.
392
392
  */
393
- edit: TMDataGridEditApi;
393
+ edit: TMDataGridEditApi<TData>;
394
394
  /** Table-level feature switches, re-read from options on every render. */
395
395
  features: TMDataGridFeatureFlags;
396
396
  /** Every string the chrome renders, `labels` merged over the English defaults. */
@@ -471,6 +471,7 @@ type TMDataGridEditingCallbacks<TData extends RowData> = {
471
471
  /**
472
472
  * Seed values for `edit.addRow()` - the entry row's starting point. A
473
473
  * function is called per added row (fresh timestamps, empty arrays).
474
+ * `edit.addRow(values)` overrides this key by key for that one row.
474
475
  */
475
476
  newRowDefaults?: TData | (() => TData);
476
477
  /**
@@ -498,12 +499,12 @@ type TMDataGridEditingCallbacks<TData extends RowData> = {
498
499
  * | `"cell"` | Enter, Tab, blur - Sheets | Escape |
499
500
  * | `"cellConfirm"` | ✓ or Enter only; blur keeps the draft | ✕ or Escape |
500
501
  * | `"row"` | Save in the edit lane, or Ctrl+Enter | Cancel, or Escape |
501
- * | `"draft"` | `edit.submitAll()` | `edit.cancelAll()` |
502
+ * | `"draft"` | `edit.commit(rowId)` into the draft store, `edit.saveDrafts()` out | `edit.cancelAll()` |
502
503
  *
503
504
  * Setting `editing` makes `getRowId` required - drafts are keyed by row id,
504
505
  * and the index fallback would name a different record after any sort - and
505
- * `onCommitDrafts` exists only under `mode: "draft"`, the one mode whose
506
- * `submitAll` calls it.
506
+ * `onSaveDrafts` exists only under `mode: "draft"`, the one mode with a draft
507
+ * store to save.
507
508
  *
508
509
  * The object may be written inline: the callbacks are read through a ref
509
510
  * every render, so its identity does not matter.
@@ -520,28 +521,42 @@ export type TMDataGridEditingOptions<TData extends RowData> =
520
521
  | {
521
522
  mode: "draft";
522
523
  /**
523
- * Draft mode's save, called once by `edit.submitAll()` with every
524
- * valid dirty row. Without it, `submitAll` falls back to the per-row
525
- * {@link TMDataGridEditingCallbacks.onCommit} loop. Rows failing
526
- * validation stay open either way; a rejection keeps every draft.
524
+ * Draft mode's save: called once by `edit.saveDrafts()` with the
525
+ * whole draft store - committed edits, added rows and deletion
526
+ * marks - so a server can apply it as one transaction. Without it,
527
+ * `saveDrafts` falls back to the per-row
528
+ * {@link TMDataGridEditingCallbacks.onCommit} loop.
529
+ *
530
+ * Rows still open are not in the payload and stay open; a rejection
531
+ * keeps every draft.
532
+ */
533
+ onSaveDrafts?: (
534
+ args: TMDataGridSaveDraftsArgs<TData>,
535
+ ) => void | Promise<void>;
536
+ /**
537
+ * @deprecated Renamed to {@link onSaveDrafts} - it fires when the
538
+ * draft store is saved, not when a row commits into it. Still
539
+ * honoured; removed in a later beta.
527
540
  */
528
541
  onCommitDrafts?: (
529
- args: TMDataGridEditCommitDraftsArgs<TData>,
542
+ args: TMDataGridSaveDraftsArgs<TData>,
530
543
  ) => void | Promise<void>;
531
544
  /**
532
- * Keep confirmed entry rows pinned in the sticky entry block until
533
- * Save all. Off by default: a confirmed row joins the scrolling
534
- * flow above the body rows instead - the block a row is *typed*
535
- * into is always sticky, but entered rows scroll, so entering many
536
- * cannot fill the viewport with sticky chrome.
545
+ * Keep committed entry rows pinned in the sticky entry block until
546
+ * the draft store is saved. Off by default: a committed row joins
547
+ * the scrolling flow above the body rows instead - the block a row
548
+ * is *typed* into is always sticky, but committed rows scroll, so
549
+ * committing many cannot fill the viewport with sticky chrome.
537
550
  */
538
551
  newRowsSticky?: boolean;
539
552
  }
540
553
  | {
541
554
  mode: Exclude<TMDataGridEditMode, "draft">;
542
- /** Only `"draft"`'s `submitAll` ever calls it - see the other branch. */
555
+ /** Only `"draft"` has a draft store to save - see the other branch. */
556
+ onSaveDrafts?: never;
557
+ /** @deprecated See {@link onSaveDrafts}. */
543
558
  onCommitDrafts?: never;
544
- /** Confirmed entry rows exist only under `"draft"` - see there. */
559
+ /** Committed entry rows exist only under `"draft"` - see there. */
545
560
  newRowsSticky?: never;
546
561
  }
547
562
  );
@@ -1109,16 +1124,22 @@ export function useTMDataGrid<TData extends RowData>({
1109
1124
  editing?.isRowEditable as TMDataGridEditEngineContext["isRowEditable"],
1110
1125
  onEditCommit:
1111
1126
  editing?.onCommit as TMDataGridEditEngineContext["onEditCommit"],
1112
- onEditCommitDrafts:
1113
- editing?.onCommitDrafts as TMDataGridEditEngineContext["onEditCommitDrafts"],
1127
+ // The deprecated name still works; the new one wins if both are set.
1128
+ onSaveDrafts: (editing?.onSaveDrafts ??
1129
+ editing?.onCommitDrafts) as TMDataGridEditEngineContext["onSaveDrafts"],
1114
1130
  newRowDefaults:
1115
1131
  editing?.newRowDefaults as TMDataGridEditEngineContext["newRowDefaults"],
1116
1132
  onRowAdd: editing?.onRowAdd as TMDataGridEditEngineContext["onRowAdd"],
1117
1133
  onRowDelete:
1118
1134
  editing?.onRowDelete as TMDataGridEditEngineContext["onRowDelete"],
1119
1135
  };
1120
- const [edit] = useState(() =>
1121
- createEditEngine(() => editContextRef.current),
1136
+ // The engine is erased; the row type comes back on the way out, which is
1137
+ // what makes `edit.addRow(values)` check against `TData`.
1138
+ const [edit] = useState(
1139
+ () =>
1140
+ createEditEngine(
1141
+ () => editContextRef.current,
1142
+ ) as unknown as TMDataGridEditApi<TData>,
1122
1143
  );
1123
1144
 
1124
1145
  // Switching modes mid-flight drops every draft: the policies disagree about