@nanahoshi/mona-ui 0.26.2 → 0.26.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.
@@ -0,0 +1,575 @@
1
+ # Editing
2
+
3
+ > Edit cells or rows inline with Signal Forms, and add, save, cancel and remove rows.
4
+
5
+ Entry point: `@nanahoshi/mona-ui/grid`
6
+
7
+ **Selectors:** `mona-grid[monaGridEditable]`, `mona-grid-command-column`, `ng-template[monaGridEditTemplate]`, `button[monaGridAddCommand]`, `button[monaGridEditCommand]`, `button[monaGridRemoveCommand]`, `button[monaGridSaveCommand]`, `button[monaGridCancelCommand]`
8
+
9
+ `monaGridEditable` turns on inline editing, one cell or one row at a time, backed by Angular Signal Forms. A command column adds Edit and Remove buttons to each row, and an Add command opens a new row above the others. The grid never changes your data: you save, add and remove rows from its events.
10
+
11
+ ## Overview
12
+
13
+ | Mode | Starts with | Commits |
14
+ | :--- | :--- | :--- |
15
+ | `"cell"` | `Enter`, `F2` or a double click on a cell | When the editor is left or `Enter` is pressed. `cellEdit` then `save` report it. |
16
+ | `"row"` | The row's Edit button, or `Enter` or `F2` on any of its cells | With the row's Save button or `Enter`, after validation. `save` then `rowEdit` report it. |
17
+
18
+ `monaGridEditable` without a value edits cells; pass `{ mode: "row" }` to edit whole rows. Each column's `type` picks its built-in editor: a text box, numeric text box, date picker or checkbox. A `monaGridEditTemplate` replaces it with your own.
19
+
20
+ **Use something else when:**
21
+
22
+ - A row has many fields, or fields that don't fit a cell. Edit it in a [Dialog](dialog.md) or a separate form, and save from there.
23
+ - Values change in bulk. Change `data` from your own controls; the grid shows the new rows.
24
+
25
+ ## Import & Quick Start
26
+
27
+ ```typescript
28
+ import {
29
+ GridAddCommandDirective,
30
+ GridColumnComponent,
31
+ GridCommandColumnComponent,
32
+ GridComponent,
33
+ GridEditableDirective,
34
+ type GridRemoveEvent,
35
+ type GridSaveEvent,
36
+ GridToolbarTemplateDirective
37
+ } from "@nanahoshi/mona-ui/grid";
38
+ ```
39
+
40
+ ```html
41
+ <mona-grid
42
+ aria-label="Products"
43
+ rowKey="id"
44
+ [data]="products()"
45
+ [monaGridEditable]="{ mode: 'row' }"
46
+ [newRowFactory]="createProduct"
47
+ (save)="onSave($event)"
48
+ (remove)="onRemove($event)">
49
+ <mona-grid-column field="name" title="Name"></mona-grid-column>
50
+ <mona-grid-column field="price" title="Price" type="number"></mona-grid-column>
51
+ <mona-grid-command-column></mona-grid-command-column>
52
+ </mona-grid>
53
+ ```
54
+
55
+ ```typescript
56
+ protected onSave(event: GridSaveEvent): void {
57
+ const product = event.rowData as Product;
58
+ this.products.update(products =>
59
+ event.operation === "create" ? [product, ...products] : products.map(p => (p.id === product.id ? product : p))
60
+ );
61
+ }
62
+ ```
63
+
64
+ ## Anatomy
65
+
66
+ | Piece | Placed inside | What it does |
67
+ | :--- | :--- | :--- |
68
+ | `mona-grid-command-column` | `mona-grid` | A column of command buttons. Without content it shows Edit and Remove, and Save and Cancel while its row is edited. |
69
+ | `monaGridCellTemplate` | `mona-grid-command-column` | Your own command buttons. The context has `$implicit` and `rowData` (the item), `row`, `isEditing`, `isNew`, and `edit()`, `save()`, `cancel()` and `remove()`. |
70
+ | `button[monaGridEditCommand]` | A command template | Starts row editing for the row it's given, usually the context's `row`. |
71
+ | `button[monaGridRemoveCommand]` | A command template | Removes the row it's given, asking first when the column has `removeConfirmation`. |
72
+ | `button[monaGridSaveCommand]`, `button[monaGridCancelCommand]` | A command template or the toolbar | Save or cancel the edit in progress. |
73
+ | `button[monaGridAddCommand]` | `monaGridToolbarTemplate` | Opens the add row, filled from `newRowFactory`. |
74
+ | `ng-template[monaGridEditTemplate]` | `mona-grid-column` | Replaces the column's editor. The context is a `GridEditTemplateContext`. |
75
+
76
+ ## Examples
77
+
78
+ ### Row Editing with Validation
79
+
80
+ `editing-example.component.ts`
81
+
82
+ ```typescript
83
+ import { Component, signal } from "@angular/core";
84
+ import { type SchemaPathTree, validate } from "@angular/forms/signals";
85
+ import { ButtonDirective } from "@nanahoshi/mona-ui/button";
86
+ import {
87
+ GridAddCommandDirective,
88
+ GridColumnComponent,
89
+ GridCommandColumnComponent,
90
+ GridComponent,
91
+ GridEditableDirective,
92
+ type GridEditSchemaFactory,
93
+ type GridRemoveEvent,
94
+ type GridSaveEvent,
95
+ GridToolbarTemplateDirective
96
+ } from "@nanahoshi/mona-ui/grid";
97
+
98
+ interface Product {
99
+ id: number;
100
+ inStock: boolean;
101
+ name: string;
102
+ price: number;
103
+ }
104
+
105
+ /** Validates the row being edited. A failed save keeps the editor open and announces the error. */
106
+ const productSchema: GridEditSchemaFactory<Product> =
107
+ () =>
108
+ (row: SchemaPathTree<Product>): void => {
109
+ validate(row.name, ({ value }) =>
110
+ value().trim() !== "" ? undefined : { kind: "required", message: "Enter a name." }
111
+ );
112
+ validate(row.price, ({ value }) =>
113
+ value() >= 0 ? undefined : { kind: "min", message: "The price can't be negative." }
114
+ );
115
+ };
116
+
117
+ @Component({
118
+ selector: "app-grid-editing-editing-example",
119
+ imports: [
120
+ ButtonDirective,
121
+ GridAddCommandDirective,
122
+ GridColumnComponent,
123
+ GridCommandColumnComponent,
124
+ GridComponent,
125
+ GridEditableDirective,
126
+ GridToolbarTemplateDirective
127
+ ],
128
+ templateUrl: "./editing-example.component.html"
129
+ })
130
+ export class GridEditingExampleComponent {
131
+ #nextId = 4;
132
+ protected readonly productSchema = productSchema;
133
+ protected readonly products = signal<Product[]>([
134
+ { id: 1, name: "Desk lamp", price: 39, inStock: true },
135
+ { id: 2, name: "Notebook", price: 6.5, inStock: true },
136
+ { id: 3, name: "Standing desk", price: 420, inStock: false }
137
+ ]);
138
+ protected readonly createProduct = (): Product => ({
139
+ id: this.#nextId++,
140
+ name: "",
141
+ price: 0,
142
+ inStock: true
143
+ });
144
+
145
+ protected onRemove(event: GridRemoveEvent): void {
146
+ this.products.update(products => products.filter(product => product.id !== event.key));
147
+ }
148
+
149
+ /** The grid never changes `data` itself: write the saved row back. */
150
+ protected onSave(event: GridSaveEvent<Product>): void {
151
+ const saved = event.rowData;
152
+ const id = event.originalRowData?.id;
153
+ if (event.operation === "create") {
154
+ this.products.update(products => [...products, saved]);
155
+ } else {
156
+ this.products.update(products => products.map(product => (product.id === id ? saved : product)));
157
+ }
158
+ }
159
+ }
160
+ ```
161
+
162
+ `editing-example.component.html`
163
+
164
+ ```html
165
+ <mona-grid
166
+ aria-label="Products"
167
+ rowKey="id"
168
+ [data]="products()"
169
+ [monaGridEditable]="{ mode: 'row', schema: productSchema }"
170
+ [newRowFactory]="createProduct"
171
+ [pageSize]="5"
172
+ (remove)="onRemove($event)"
173
+ (save)="onSave($event)">
174
+ <ng-template let-addRowVisible="addRowVisible" monaGridToolbarTemplate>
175
+ <button monaButton monaGridAddCommand type="button" [disabled]="addRowVisible">Add product</button>
176
+ </ng-template>
177
+ <mona-grid-column field="name" title="Name" />
178
+ <mona-grid-column field="price" title="Price" type="number" />
179
+ <mona-grid-column field="inStock" title="In stock" type="boolean" />
180
+ <mona-grid-command-column [width]="120" />
181
+ </mona-grid>
182
+ ```
183
+
184
+ A `mona-grid-command-column` without content shows the built-in Edit and Remove buttons, and `monaGridAddCommand` on a toolbar button opens the add row. The `schema` validates the row; a save that fails validation keeps the editor open and announces the error.
185
+
186
+ ### Custom Editors
187
+
188
+ Custom edit templates receive a `GridEditTemplateContext` bound to the row's Signal Forms field:
189
+
190
+ ```html
191
+ <mona-grid-column field="shipName" title="Ship Name">
192
+ <ng-template monaGridEditTemplate let-context>
193
+ <mona-text-box [formField]="$any(context.field)" (keydown.escape)="context.cancel()"></mona-text-box>
194
+ </ng-template>
195
+ </mona-grid-column>
196
+ ```
197
+
198
+ The context also has `value`, `setValue()`, `commit()`, `cancel()`, and `errors`, `invalid` and `touched` for showing validation messages.
199
+
200
+ ### Custom Command Buttons
201
+
202
+ ```html
203
+ <mona-grid-command-column [width]="120">
204
+ <ng-template monaGridCellTemplate let-row="row">
205
+ <button monaButton type="button" [monaGridEditCommand]="row">Change</button>
206
+ <button monaButton type="button" [monaGridRemoveCommand]="row">Delete</button>
207
+ </ng-template>
208
+ </mona-grid-command-column>
209
+ ```
210
+
211
+ ### Saving on a Server
212
+
213
+ Prevent `save` to keep the editor open while the request runs, then call `endEdit()` on the `GridEditableDirective` (from `viewChild(GridEditableDirective)`) when it succeeds.
214
+
215
+ ```typescript
216
+ private readonly editable = viewChild.required(GridEditableDirective);
217
+
218
+ protected onSave(event: GridSaveEvent): void {
219
+ event.preventDefault();
220
+ this.api.save(event.rowData).subscribe(() => {
221
+ this.reload();
222
+ this.editable().endEdit();
223
+ });
224
+ }
225
+ ```
226
+
227
+ ## Behavior
228
+
229
+ ### Which columns are editable
230
+
231
+ Every column is editable except the one whose `field` is the `rowKey`. Set `[editable]` on a `mona-grid-column` to change that, for example `[editable]="true"` to type the key of a new row, or `[editable]="false"` for a computed column.
232
+
233
+ ### Events
234
+
235
+ `save` is the one to persist from: its `rowData` holds the edited values and `originalRowData` the row as it was. `cellEdit` comes first in cell mode, with the field's old and new value; its `rowData` is the row as it was. Neither fires when nothing changed. `edit` and `add` come before an editor opens, and preventing them keeps it closed.
236
+
237
+ `cancel` carries a `reason`: `"command"`, `"escape"`, `"switch"` (another edit or the add row started) or `"removed"` (the row left the data or the view, which can't be prevented). `remove` carries the row's `key` and its `index` in `data`.
238
+
239
+ ### Values
240
+
241
+ Each editor is named after its column title. Number text is read in the grid's locale (`1.234,5` in de-DE); a date picked in the calendar keeps the time of day the value had. A row without a value for an editable column starts that editor at `null`, and the field is left out of the saved row again if it stays empty.
242
+
243
+ ### Data that changes during an edit
244
+
245
+ When `data` is replaced during an edit, the edit moves to the new item with the same `rowKey` and keeps what was typed. If the row is gone, the edit is canceled with the reason `"removed"`. After Save, Cancel or Remove, focus moves to the row's cell, or to the nearest cell when the row is gone.
246
+
247
+ ## Forms Integration
248
+
249
+ Inline editing is built exclusively on Angular Signal Forms: the built-in editors and the `GridEditTemplateContext` passed to `monaGridEditTemplate` both operate on a `FieldTree` from `@angular/forms/signals`. No grid component implements `ControlValueAccessor`, `FormValueControl`, or `FormCheckboxControl`, so there is no `[(ngModel)]`, `[formControl]`, or `formControlName` integration at the cell-editor level.
250
+
251
+ Provide a `schema` function in `monaGridEditable`'s options to validate the row being edited. It receives a `GridEditFormContext` and returns a Signal Forms schema for the row; errors surface through `errors`, `invalid` and `touched` in custom edit templates, and on the built-in editors.
252
+
253
+ ## Accessibility
254
+
255
+ The command buttons are named after their row (`Edit row 3`); `commandAriaLabel` in the options names them after something else, such as an order number. An invalid field is linked to its editor with `aria-describedby`, and a commit that fails validation is announced through a polite live region.
256
+
257
+ ### Keyboard
258
+
259
+ | Key | Action |
260
+ | --- | --- |
261
+ | `Enter` / `F2` | Starts editing an editable cell; in row mode, edits the row from that cell's editor. |
262
+ | `Enter` | In cell mode, saves the cell. In row mode, saves the row after validation. |
263
+ | `Escape` | Cancels the edit. |
264
+ | `Tab` / `Shift+Tab` | In cell mode, saves and edits the next/previous editable cell. In row mode, moves between the row's editors and its Save and Cancel buttons. |
265
+
266
+ The add row works the same way. `Enter` and `Escape` are left to an input method while it composes text. The rest of the grid's keys are on [Grid Overview](grid.md#keyboard).
267
+
268
+ ### ARIA
269
+
270
+ | Attribute | When present | Value |
271
+ | --- | --- | --- |
272
+ | `aria-readonly` | On the tabular content region | `"true"` while editing is off |
273
+ | `aria-readonly` | On a data cell | `"true"` when editing is off for that cell or column |
274
+ | `aria-label` | On the built-in command buttons | `"Edit row 3"`, `"Remove row 3"`, `"Save row 3"`, `"Cancel editing row 3"`, or the `commandAriaLabel` option's text |
275
+ | `aria-describedby` | On an editor with a validation error | The error message |
276
+
277
+ ## API
278
+
279
+ Everything below is imported from `@nanahoshi/mona-ui/grid`.
280
+
281
+ ### `GridCommandColumnComponent`
282
+
283
+ **Selector:** `mona-grid-command-column`
284
+
285
+ #### Inputs
286
+
287
+ | Name | Type | Default | Description |
288
+ | --- | --- | --- | --- |
289
+ | `hidden` | `boolean` | `false` | Whether this command column is hidden from the rendered grid. |
290
+ | `locked` | `boolean` | `false` | Whether this command column remains fixed while the grid scrolls horizontally. |
291
+ | `lockedPosition` | `GridColumnLockedPosition` | `"left"` | The side of the grid where this locked command column is fixed. |
292
+ | `maxWidth` | `number \| null` | `null` | The maximum width of this command column in pixels. |
293
+ | `minWidth` | `number \| null` | `null` | The minimum width of this command column in pixels. |
294
+ | `removeConfirmation` | `boolean` | `false` | Whether removing a row asks for confirmation before emitting `remove`: from the built-in Remove button, or from a `monaGridRemoveCommand` button in this column's template. |
295
+ | `stateKey` | `string \| null` | `"commands"` | A stable key used to persist state for this command column. |
296
+ | `title` | `string \| null` | `null` | The title displayed in the command column header. Without one, the localized `commandColumnTitle` message ("Commands"). |
297
+ | `width` | `number \| null` | `160` | The fixed width of this command column in pixels. |
298
+
299
+ ### `GridEditableDirective`
300
+
301
+ **Selector:** `mona-grid[monaGridEditable]`
302
+ **Type parameters:** `T extends object = Record<PropertyKey, unknown>`
303
+
304
+ #### Inputs
305
+
306
+ | Name | Type | Default | Description |
307
+ | --- | --- | --- | --- |
308
+ | `monaGridEditable` | `EditableOptions<T> \| ""` | `""` | Enables inline editing. An empty string enables cell-mode editing with default settings; pass an object to choose `"cell"` or `"row"` mode and an optional validation `schema`. |
309
+ | `newRowFactory` | `() => T` | — | Creates the initial data object used by the add-row editor. |
310
+
311
+ #### Outputs
312
+
313
+ | Name | Type | Description |
314
+ | --- | --- | --- |
315
+ | `add` | `GridAddEvent` | Emitted before the grid displays the new-row editor. |
316
+ | `cancel` | `GridCancelEvent` | Emitted before an edit operation is canceled; `reason` says why. Prevent it to keep editing, except for `"removed"`, when the edited row left the data or the view. |
317
+ | `cellEdit` | `CellEditEvent` | Emitted before a changed cell is saved in cell mode; not when the value didn't change. `rowData` is the row as it was; persist from `save`, whose `rowData` holds the edited values. |
318
+ | `edit` | `GridEditEvent` | Emitted before a row enters edit mode. |
319
+ | `remove` | `GridRemoveEvent` | Emitted when a row remove command is triggered, with the row's `key` and `index`. |
320
+ | `rowEdit` | `RowEditEvent` | Emitted after a changed row is saved (row mode only). |
321
+ | `save` | `GridSaveEvent<T>` | Emitted before an edited or new row is saved; not when an edit changed nothing. `rowData` holds the edited values and `originalRowData` the row as it was. Prevent it to keep the editor open, for example while saving on the server, then call `endEdit()`. |
322
+
323
+ #### Methods
324
+
325
+ | Signature | Description |
326
+ | --- | --- |
327
+ | `endEdit(): void` | Closes the current edit without reporting it, such as after a `save` that was prevented to save on the server has finished. |
328
+
329
+ ### `GridEditCommandDirective`
330
+
331
+ **Selector:** `button[monaGridEditCommand]`
332
+
333
+ #### Inputs
334
+
335
+ | Name | Type | Default | Description |
336
+ | --- | --- | --- | --- |
337
+ | `monaGridEditCommand` | `Row \| null` | `null` | The row the button puts into row edit mode when clicked, usually the command template's `row`. Does nothing while `null` or when the grid isn't in row edit mode. |
338
+
339
+ ### `GridRemoveCommandDirective`
340
+
341
+ **Selector:** `button[monaGridRemoveCommand]`
342
+
343
+ #### Inputs
344
+
345
+ | Name | Type | Default | Description |
346
+ | --- | --- | --- | --- |
347
+ | `monaGridRemoveCommand` | `Row \| null` | `null` | The row the button removes when clicked, usually the command template's `row`. The click emits the grid's `remove` event for that row. Inside a command column with `removeConfirmation`, it asks first, as the built-in remove command does. Does nothing while `null`. |
348
+
349
+ ### `GridAddCommandDirective`
350
+
351
+ **Selector:** `button[monaGridAddCommand]`
352
+
353
+ ### `GridCancelCommandDirective`
354
+
355
+ **Selector:** `button[monaGridCancelCommand]`
356
+
357
+ ### `GridEditTemplateDirective`
358
+
359
+ **Selector:** `ng-template[monaGridEditTemplate]`
360
+
361
+ ### `GridSaveCommandDirective`
362
+
363
+ **Selector:** `button[monaGridSaveCommand]`
364
+
365
+ ### `CellEditEvent`
366
+
367
+ **Extends:** `PreventableEvent`
368
+
369
+ #### Properties
370
+
371
+ | Name | Type |
372
+ | --- | --- |
373
+ | `field` (read-only) | `string` |
374
+ | `newValue` (read-only) | `unknown` |
375
+ | `oldValue` (read-only) | `unknown` |
376
+ | `rowData` (read-only) | `Record<PropertyKey, unknown>` |
377
+ | `session` (read-only) | `GridEditSession` |
378
+
379
+ ### `GridAddEvent`
380
+
381
+ **Extends:** `PreventableEvent`
382
+
383
+ #### Properties
384
+
385
+ | Name | Type |
386
+ | --- | --- |
387
+ | `rowData` (read-only) | `Record<PropertyKey, unknown>` |
388
+ | `session` (read-only) | `GridEditSession` |
389
+
390
+ ### `GridCancelEvent`
391
+
392
+ **Extends:** `PreventableEvent`
393
+
394
+ #### Properties
395
+
396
+ | Name | Type |
397
+ | --- | --- |
398
+ | `operation` (read-only) | `GridSaveOperation` |
399
+ | `reason` (read-only) | `GridCancelReason` |
400
+ | `rowData` (read-only) | `Record<PropertyKey, unknown>` |
401
+ | `session` (read-only) | `GridEditSession` |
402
+
403
+ ### `GridEditEvent`
404
+
405
+ **Extends:** `PreventableEvent`
406
+
407
+ #### Properties
408
+
409
+ | Name | Type |
410
+ | --- | --- |
411
+ | `rowData` (read-only) | `Record<PropertyKey, unknown>` |
412
+ | `session` (read-only) | `GridEditSession` |
413
+
414
+ ### `GridRemoveEvent`
415
+
416
+ **Extends:** `PreventableEvent`
417
+
418
+ #### Properties
419
+
420
+ | Name | Type | Description |
421
+ | --- | --- | --- |
422
+ | `index` (read-only) | `number` | The row's position in the grid's `data`, or -1 when it is no longer there. |
423
+ | `key` (read-only) | `unknown` | The row's `rowKey` value, or the data item when the grid has no `rowKey`. |
424
+ | `rowData` (read-only) | `Record<PropertyKey, unknown>` | The data item of the row being removed. |
425
+
426
+ ### `GridSaveEvent`
427
+
428
+ `T` is the row type, which a typed `schema` or `newRowFactory` on `monaGridEditable` sets.
429
+
430
+ **Type parameters:** `T extends object = Record<PropertyKey, unknown>`
431
+ **Extends:** `PreventableEvent`
432
+
433
+ #### Properties
434
+
435
+ | Name | Type |
436
+ | --- | --- |
437
+ | `operation` (read-only) | `GridSaveOperation` |
438
+ | `originalRowData` (read-only) | `T \| null` |
439
+ | `rowData` (read-only) | `T` |
440
+ | `session` (read-only) | `GridEditSession` |
441
+
442
+ ### `RowEditEvent`
443
+
444
+ **Extends:** `PreventableEvent`
445
+
446
+ #### Properties
447
+
448
+ | Name | Type |
449
+ | --- | --- |
450
+ | `originalRowData` (read-only) | `Record<PropertyKey, unknown> \| null` |
451
+ | `rowData` (read-only) | `Record<PropertyKey, unknown>` |
452
+ | `session` (read-only) | `GridEditSession` |
453
+
454
+ ### Types
455
+
456
+ #### `EditableOptions`
457
+
458
+ `T` is the row type, which a typed `schema` sets.
459
+
460
+ **Type parameters:** `T extends object = Record<PropertyKey, unknown>`
461
+
462
+ | Name | Type | Description |
463
+ | --- | --- | --- |
464
+ | `commandAriaLabel?` | `( command: GridRowCommand, rowData: Record<PropertyKey, unknown>, absoluteIndex: number ) => string` | Returns the accessible name of a row's command button, such as "Edit order 10248". Without it the buttons are named by position ("Edit row 3"). `absoluteIndex` is the row's 0-based position in the filtered and sorted rows; the add row isn't passed here. |
465
+ | `enabled?` | `boolean` | Whether editing is active. On unless set to `false`; options replace earlier ones. |
466
+ | `mode` | `"cell" \| "row"` | Whether editing commits per cell or per row. |
467
+ | `schema?` | `GridEditSchemaFactory<T>` | Builds a Signal Forms validation schema for the row being edited. |
468
+
469
+ #### `GridEditFormContext`
470
+
471
+ What a schema factory is told about the edit. `T` is the row type, untyped unless you give one.
472
+
473
+ **Type parameters:** `T extends object = Record<PropertyKey, unknown>`
474
+
475
+ | Name | Type |
476
+ | --- | --- |
477
+ | `column` (read-only) | `Column \| null` |
478
+ | `field` (read-only) | `string \| null` |
479
+ | `isNew` (read-only) | `boolean` |
480
+ | `mode` (read-only) | `"cell" \| "row"` |
481
+ | `operation` (read-only) | `GridEditOperation` |
482
+ | `originalRowData` (read-only) | `T \| null` |
483
+ | `rowData` (read-only) | `T` |
484
+
485
+ #### `GridEditSession`
486
+
487
+ | Name | Type | Description |
488
+ | --- | --- | --- |
489
+ | `column` (read-only) | `Column \| null` | The column currently being edited, in cell mode. |
490
+ | `field` (read-only) | `string \| null` | The field name currently being edited, in cell mode. |
491
+ | `form` (read-only) | `FieldTree<Record<PropertyKey, unknown>>` | The Signal Forms field tree backing the row being edited. |
492
+ | `isNew` (read-only) | `boolean` | Whether this session represents a new row being added. |
493
+ | `mode` (read-only) | `"cell" \| "row"` | The active editing mode. |
494
+ | `model` (read-only) | `WritableSignal<Record<PropertyKey, unknown>>` | The signal holding the row's current edited values. |
495
+ | `operation` (read-only) | `GridEditOperation` | `"create"` or `"update"`. |
496
+ | `originalRowData` (read-only) | `Record<PropertyKey, unknown> \| null` | The row's data before editing began. |
497
+ | `row` (read-only) | `Row \| null` | The internal row wrapper being edited. |
498
+ | `rowUid` (read-only) | `string \| null` | The stable identifier of the row being edited. |
499
+
500
+ #### `GridEditTemplateContext`
501
+
502
+ | Name | Type | Description |
503
+ | --- | --- | --- |
504
+ | `cancel` (read-only) | `() => void` | Cancels the current edit. |
505
+ | `column` (read-only) | `string` | The field name of the column being edited. |
506
+ | `commit` (read-only) | `() => void` | Commits the current edit. |
507
+ | `dataField` (read-only) | `string` | Same as `column`; the field name being edited. |
508
+ | `dataItem` (read-only) | `Record<PropertyKey, unknown>` | The row's current edited values. |
509
+ | `errors` (read-only) | `readonly ValidationError.WithFieldTree[]` | Validation errors for this field. |
510
+ | `field` (read-only) | `FieldTree<unknown>` | The Signal Forms field for this column. |
511
+ | `form` (read-only) | `GridEditSession["form"]` | The row's full Signal Forms field tree. |
512
+ | `invalid` (read-only) | `boolean` | Whether this field currently fails validation. |
513
+ | `isNew` (read-only) | `boolean` | Whether this is a new row being added. |
514
+ | `session` (read-only) | `GridEditSession` | The full edit session for this row. |
515
+ | `setValue` (read-only) | `(value: unknown) => void` | Sets this field's value. |
516
+ | `touched` (read-only) | `boolean` | Whether this field has been touched. |
517
+ | `value` (read-only) | `unknown` | This field's current value. |
518
+
519
+ #### `GridCancelReason`
520
+
521
+ Why an edit is being canceled: `"command"` for the Cancel button or `cancel()` in a template, `"escape"` for
522
+ the Escape key, `"switch"` when another edit or the add row starts, `"removed"` when the edited row left the
523
+ data or the view. A `"removed"` cancel can't be prevented: the row is gone.
524
+
525
+ ```typescript
526
+ type GridCancelReason = "command" | "escape" | "removed" | "switch";
527
+ ```
528
+
529
+ #### `GridEditOperation`
530
+
531
+ ```typescript
532
+ type GridEditOperation = "create" | "update";
533
+ ```
534
+
535
+ #### `GridEditSchemaFactory`
536
+
537
+ Builds the Signal Forms schema for the row being edited. `T` is the row type, untyped unless you give one.
538
+
539
+ ```typescript
540
+ type GridEditSchemaFactory<T extends object = Record<PropertyKey, unknown>> = ( context: GridEditFormContext<T> ) => SchemaOrSchemaFn<T> | null | undefined;
541
+ ```
542
+
543
+ #### `GridRowCommand`
544
+
545
+ A row command button: Edit, Remove, Save or Cancel.
546
+
547
+ ```typescript
548
+ type GridRowCommand = "cancel" | "edit" | "remove" | "save";
549
+ ```
550
+
551
+ #### `GridSaveOperation`
552
+
553
+ ```typescript
554
+ type GridSaveOperation = GridEditOperation;
555
+ ```
556
+
557
+ #### `PreventableEvent`
558
+
559
+ From `@nanahoshi/mona-ui/common`.
560
+
561
+ **Type parameters:** `E extends Event = Event`
562
+
563
+ | Name | Type | Description |
564
+ | --- | --- | --- |
565
+ | `originalEvent` (read-only) | `E \| undefined` | The DOM event that caused this one, when there is one. |
566
+ | `type` (read-only) | `string \| undefined` | A name for the kind of event, when the component that emits it sets one. |
567
+
568
+ **Methods**
569
+
570
+ | Signature | Description |
571
+ | --- | --- |
572
+ | `isDefaultPrevented(): boolean` | Whether `preventDefault()` was called. |
573
+ | `preventDefault(): void` | Cancels what the event announces, such as opening or closing a popup, or closing a dialog. |
574
+
575
+ **Documented elsewhere:** [`Column`](grid.md), [`GridColumnLockedPosition`](grid-columns.md), [`Row`](grid.md)