@toolbox-web/grid 1.23.1 → 1.23.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.
- package/README.md +2 -2
- package/all.js +2 -2
- package/all.js.map +1 -1
- package/index.js +1 -1
- package/index.js.map +1 -1
- package/lib/core/types.d.ts +1 -1
- package/lib/plugins/clipboard/index.js.map +1 -1
- package/lib/plugins/column-virtualization/index.js.map +1 -1
- package/lib/plugins/context-menu/index.js.map +1 -1
- package/lib/plugins/editing/EditingPlugin.d.ts +19 -122
- package/lib/plugins/editing/EditingPlugin.d.ts.map +1 -1
- package/lib/plugins/editing/editors.d.ts +4 -2
- package/lib/plugins/editing/editors.d.ts.map +1 -1
- package/lib/plugins/editing/index.d.ts +2 -2
- package/lib/plugins/editing/index.d.ts.map +1 -1
- package/lib/plugins/editing/index.js +1 -1
- package/lib/plugins/editing/index.js.map +1 -1
- package/lib/plugins/editing/internal/cell-validation.d.ts +80 -0
- package/lib/plugins/editing/internal/cell-validation.d.ts.map +1 -0
- package/lib/plugins/editing/internal/dirty-tracking-manager.d.ts +77 -0
- package/lib/plugins/editing/internal/dirty-tracking-manager.d.ts.map +1 -0
- package/lib/plugins/editing/internal/editor-injection.d.ts +33 -0
- package/lib/plugins/editing/internal/editor-injection.d.ts.map +1 -0
- package/lib/plugins/editing/internal/helpers.d.ts +55 -0
- package/lib/plugins/editing/internal/helpers.d.ts.map +1 -0
- package/lib/plugins/editing/types.d.ts +20 -0
- package/lib/plugins/editing/types.d.ts.map +1 -1
- package/lib/plugins/export/index.js.map +1 -1
- package/lib/plugins/filtering/FilteringPlugin.d.ts +8 -23
- package/lib/plugins/filtering/FilteringPlugin.d.ts.map +1 -1
- package/lib/plugins/filtering/filter-panel-date.d.ts +14 -0
- package/lib/plugins/filtering/filter-panel-date.d.ts.map +1 -0
- package/lib/plugins/filtering/filter-panel-default.d.ts +23 -0
- package/lib/plugins/filtering/filter-panel-default.d.ts.map +1 -0
- package/lib/plugins/filtering/filter-panel-number.d.ts +14 -0
- package/lib/plugins/filtering/filter-panel-number.d.ts.map +1 -0
- package/lib/plugins/filtering/index.js +1 -1
- package/lib/plugins/filtering/index.js.map +1 -1
- package/lib/plugins/grouping-columns/GroupingColumnsPlugin.d.ts.map +1 -1
- package/lib/plugins/grouping-columns/grouping-columns.d.ts +7 -0
- package/lib/plugins/grouping-columns/grouping-columns.d.ts.map +1 -1
- package/lib/plugins/grouping-columns/index.js +1 -1
- package/lib/plugins/grouping-columns/index.js.map +1 -1
- package/lib/plugins/grouping-rows/index.js.map +1 -1
- package/lib/plugins/master-detail/index.js.map +1 -1
- package/lib/plugins/multi-sort/index.js.map +1 -1
- package/lib/plugins/pinned-columns/index.js.map +1 -1
- package/lib/plugins/pinned-rows/index.js.map +1 -1
- package/lib/plugins/pivot/index.js.map +1 -1
- package/lib/plugins/print/index.js.map +1 -1
- package/lib/plugins/reorder/index.js +1 -1
- package/lib/plugins/reorder/index.js.map +1 -1
- package/lib/plugins/responsive/index.js +1 -1
- package/lib/plugins/responsive/index.js.map +1 -1
- package/lib/plugins/row-reorder/index.js +1 -1
- package/lib/plugins/row-reorder/index.js.map +1 -1
- package/lib/plugins/selection/index.js.map +1 -1
- package/lib/plugins/server-side/index.js.map +1 -1
- package/lib/plugins/tree/index.js.map +1 -1
- package/lib/plugins/undo-redo/index.js.map +1 -1
- package/lib/plugins/visibility/index.js.map +1 -1
- package/package.json +1 -1
- package/umd/grid.all.umd.js +1 -1
- package/umd/grid.all.umd.js.map +1 -1
- package/umd/grid.umd.js +1 -1
- package/umd/grid.umd.js.map +1 -1
- package/umd/plugins/editing.umd.js +1 -1
- package/umd/plugins/editing.umd.js.map +1 -1
- package/umd/plugins/filtering.umd.js +1 -1
- package/umd/plugins/filtering.umd.js.map +1 -1
- package/umd/plugins/grouping-columns.umd.js +1 -1
- package/umd/plugins/grouping-columns.umd.js.map +1 -1
- package/umd/plugins/responsive.umd.js +1 -1
- package/umd/plugins/responsive.umd.js.map +1 -1
|
@@ -1,15 +1,7 @@
|
|
|
1
1
|
import { AfterCellRenderContext, AfterRowRenderContext, PluginManifest, PluginQuery, BaseGridPlugin, CellClickEvent, GridElement } from '../../core/plugin/base-plugin';
|
|
2
|
-
import { ColumnConfig
|
|
2
|
+
import { ColumnConfig } from '../../core/types';
|
|
3
3
|
import { DirtyRowEntry } from './internal/dirty-tracking';
|
|
4
4
|
import { EditingConfig } from './types';
|
|
5
|
-
/**
|
|
6
|
-
* Check if a row element has any cells in editing mode.
|
|
7
|
-
*/
|
|
8
|
-
export declare function hasEditingCells(rowEl: RowElementInternal): boolean;
|
|
9
|
-
/**
|
|
10
|
-
* Clear all editing state from a row element.
|
|
11
|
-
*/
|
|
12
|
-
export declare function clearEditingState(rowEl: RowElementInternal): void;
|
|
13
5
|
/**
|
|
14
6
|
* Editing Plugin for tbw-grid
|
|
15
7
|
*
|
|
@@ -215,89 +207,27 @@ export declare class EditingPlugin<T = unknown> extends BaseGridPlugin<EditingCo
|
|
|
215
207
|
* @param rowId - Row ID to check
|
|
216
208
|
*/
|
|
217
209
|
isRowChangedById(rowId: string): boolean;
|
|
218
|
-
/**
|
|
219
|
-
* Check if a specific row's current data differs from its baseline.
|
|
220
|
-
* Requires `dirtyTracking: true` in plugin config.
|
|
221
|
-
*
|
|
222
|
-
* @param rowId - Row ID (from `getRowId`)
|
|
223
|
-
* @returns `true` if the row has been modified or is a new row
|
|
224
|
-
*/
|
|
210
|
+
/** Check if a row differs from its baseline. Requires `dirtyTracking: true`. */
|
|
225
211
|
isDirty(rowId: string): boolean;
|
|
226
|
-
/**
|
|
227
|
-
* Check if a specific row matches its baseline (not dirty).
|
|
228
|
-
* Requires `dirtyTracking: true` in plugin config.
|
|
229
|
-
*
|
|
230
|
-
* @param rowId - Row ID (from `getRowId`)
|
|
231
|
-
*/
|
|
212
|
+
/** Inverse of `isDirty`. */
|
|
232
213
|
isPristine(rowId: string): boolean;
|
|
233
|
-
/**
|
|
234
|
-
* Whether any row in the grid is dirty.
|
|
235
|
-
* Requires `dirtyTracking: true` in plugin config.
|
|
236
|
-
*/
|
|
214
|
+
/** Whether any row in the grid is dirty. */
|
|
237
215
|
get dirty(): boolean;
|
|
238
|
-
/**
|
|
239
|
-
* Whether all rows in the grid are pristine (not dirty).
|
|
240
|
-
* Requires `dirtyTracking: true` in plugin config.
|
|
241
|
-
*/
|
|
216
|
+
/** Whether all rows are pristine. */
|
|
242
217
|
get pristine(): boolean;
|
|
243
|
-
/**
|
|
244
|
-
* Mark a row as pristine: re-snapshot baseline from current data.
|
|
245
|
-
* Call after a successful backend save to set the new "original."
|
|
246
|
-
*
|
|
247
|
-
* @param rowId - Row ID (from `getRowId`)
|
|
248
|
-
*/
|
|
218
|
+
/** Re-snapshot baseline from current data (call after a successful save). */
|
|
249
219
|
markAsPristine(rowId: string): void;
|
|
250
|
-
/**
|
|
251
|
-
* Programmatically mark a row as new (e.g. after `grid.insertRow()`).
|
|
252
|
-
*
|
|
253
|
-
* Adds the row to the new-row set so it receives the `tbw-row-new` CSS
|
|
254
|
-
* class and is included in `getDirtyRows()` / `dirtyRowIds`.
|
|
255
|
-
*
|
|
256
|
-
* Called automatically when `grid.insertRow()` emits a `row-inserted`
|
|
257
|
-
* plugin event and `dirtyTracking` is enabled — consumers typically
|
|
258
|
-
* don't need to call this directly.
|
|
259
|
-
*
|
|
260
|
-
* @param rowId - Row ID (from `getRowId`)
|
|
261
|
-
*/
|
|
220
|
+
/** Mark a row as new (auto-called by `insertRow()` when dirty tracking is on). */
|
|
262
221
|
markAsNew(rowId: string): void;
|
|
263
|
-
/**
|
|
264
|
-
* Programmatically mark a row as dirty (e.g. after an external mutation
|
|
265
|
-
* that bypassed the editing pipeline).
|
|
266
|
-
*
|
|
267
|
-
* @param rowId - Row ID (from `getRowId`)
|
|
268
|
-
*/
|
|
222
|
+
/** Mark a row as dirty after an external mutation that bypassed the editing pipeline. */
|
|
269
223
|
markAsDirty(rowId: string): void;
|
|
270
|
-
/**
|
|
271
|
-
* Mark all tracked rows as pristine. Call after a successful batch save.
|
|
272
|
-
*/
|
|
224
|
+
/** Mark all tracked rows as pristine (call after a batch save). */
|
|
273
225
|
markAllPristine(): void;
|
|
274
|
-
/**
|
|
275
|
-
* Get the original (baseline) row data before any edits.
|
|
276
|
-
*
|
|
277
|
-
* Returns a **deep clone** of the row as it was when first seen by the grid.
|
|
278
|
-
* Cache the result if calling repeatedly for the same row — each call
|
|
279
|
-
* performs a full `structuredClone`.
|
|
280
|
-
*
|
|
281
|
-
* Returns `undefined` if no baseline exists (e.g. newly inserted row via
|
|
282
|
-
* `grid.insertRow()`).
|
|
283
|
-
*
|
|
284
|
-
* @param rowId - Row ID (from `getRowId`)
|
|
285
|
-
*/
|
|
226
|
+
/** Get a deep clone of the original (baseline) row data. Returns `undefined` for new rows. */
|
|
286
227
|
getOriginalRow(rowId: string): T | undefined;
|
|
287
|
-
/**
|
|
288
|
-
* Check whether a baseline snapshot exists for a row.
|
|
289
|
-
*
|
|
290
|
-
* Lightweight alternative to `getOriginalRow()` when you only need to know
|
|
291
|
-
* if the row has been tracked — no cloning is performed.
|
|
292
|
-
*
|
|
293
|
-
* Returns `false` when `dirtyTracking` is disabled.
|
|
294
|
-
*
|
|
295
|
-
* @param rowId - Row ID (from `getRowId`)
|
|
296
|
-
*/
|
|
228
|
+
/** Lightweight check for whether a baseline exists (no cloning). */
|
|
297
229
|
hasBaseline(rowId: string): boolean;
|
|
298
|
-
/**
|
|
299
|
-
* Get all dirty rows with their original and current data.
|
|
300
|
-
*/
|
|
230
|
+
/** Get all dirty rows with their original and current data. */
|
|
301
231
|
getDirtyRows(): DirtyRowEntry<T>[];
|
|
302
232
|
/**
|
|
303
233
|
* Get IDs of all dirty rows.
|
|
@@ -336,52 +266,19 @@ export declare class EditingPlugin<T = unknown> extends BaseGridPlugin<EditingCo
|
|
|
336
266
|
* ```
|
|
337
267
|
*/
|
|
338
268
|
setInvalid(rowId: string, field: string, message?: string): void;
|
|
339
|
-
/**
|
|
340
|
-
* Clear the invalid state for a specific cell.
|
|
341
|
-
*
|
|
342
|
-
* @param rowId - The row ID (from getRowId)
|
|
343
|
-
* @param field - The field name
|
|
344
|
-
*/
|
|
269
|
+
/** Clear the invalid state for a specific cell. */
|
|
345
270
|
clearInvalid(rowId: string, field: string): void;
|
|
346
|
-
/**
|
|
347
|
-
* Clear all invalid cells for a specific row.
|
|
348
|
-
*
|
|
349
|
-
* @param rowId - The row ID (from getRowId)
|
|
350
|
-
*/
|
|
271
|
+
/** Clear all invalid cells for a specific row. */
|
|
351
272
|
clearRowInvalid(rowId: string): void;
|
|
352
|
-
/**
|
|
353
|
-
* Clear all invalid cell states across all rows.
|
|
354
|
-
*/
|
|
273
|
+
/** Clear all invalid cell states across all rows. */
|
|
355
274
|
clearAllInvalid(): void;
|
|
356
|
-
/**
|
|
357
|
-
* Check if a specific cell is marked as invalid.
|
|
358
|
-
*
|
|
359
|
-
* @param rowId - The row ID (from getRowId)
|
|
360
|
-
* @param field - The field name
|
|
361
|
-
* @returns True if the cell is marked as invalid
|
|
362
|
-
*/
|
|
275
|
+
/** Check if a specific cell is marked as invalid. */
|
|
363
276
|
isCellInvalid(rowId: string, field: string): boolean;
|
|
364
|
-
/**
|
|
365
|
-
* Get the validation message for an invalid cell.
|
|
366
|
-
*
|
|
367
|
-
* @param rowId - The row ID (from getRowId)
|
|
368
|
-
* @param field - The field name
|
|
369
|
-
* @returns The validation message, or undefined if cell is valid
|
|
370
|
-
*/
|
|
277
|
+
/** Get the validation message for an invalid cell. */
|
|
371
278
|
getInvalidMessage(rowId: string, field: string): string | undefined;
|
|
372
|
-
/**
|
|
373
|
-
* Check if a row has any invalid cells.
|
|
374
|
-
*
|
|
375
|
-
* @param rowId - The row ID (from getRowId)
|
|
376
|
-
* @returns True if the row has at least one invalid cell
|
|
377
|
-
*/
|
|
279
|
+
/** Check if a row has any invalid cells. */
|
|
378
280
|
hasInvalidCells(rowId: string): boolean;
|
|
379
|
-
/**
|
|
380
|
-
* Get all invalid fields for a row.
|
|
381
|
-
*
|
|
382
|
-
* @param rowId - The row ID (from getRowId)
|
|
383
|
-
* @returns Map of field names to validation messages
|
|
384
|
-
*/
|
|
281
|
+
/** Get all invalid fields for a row. */
|
|
385
282
|
getInvalidFields(rowId: string): Map<string, string>;
|
|
386
283
|
/**
|
|
387
284
|
* Reset all change tracking.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditingPlugin.d.ts","sourceRoot":"","sources":["../../../../../../libs/grid/src/lib/plugins/editing/EditingPlugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;
|
|
1
|
+
{"version":3,"file":"EditingPlugin.d.ts","sourceRoot":"","sources":["../../../../../../libs/grid/src/lib/plugins/editing/EditingPlugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAGH,OAAO,KAAK,EACV,sBAAsB,EACtB,qBAAqB,EACrB,cAAc,EACd,WAAW,EACZ,MAAM,+BAA+B,CAAC;AACvC,OAAO,EAAE,cAAc,EAAE,KAAK,cAAc,EAAE,KAAK,WAAW,EAAE,MAAM,+BAA+B,CAAC;AACtG,OAAO,KAAK,EAAE,YAAY,EAAoC,MAAM,kBAAkB,CAAC;AAIvF,OAAO,EAAwD,KAAK,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAWrH,OAAO,KAAK,EAMV,aAAa,EAGd,MAAM,SAAS,CAAC;AAMjB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgFG;AACH,qBAAa,aAAa,CAAC,CAAC,GAAG,OAAO,CAAE,SAAQ,cAAc,CAAC,aAAa,CAAC;;IAC3E;;;OAGG;IACH,gBAAyB,QAAQ,EAAE,cAAc,CAoC/C;IAEF,gBAAgB;IAChB,QAAQ,CAAC,IAAI,aAAa;IAC1B,gBAAgB;IAChB,SAAkB,MAAM,SAAU;IAElC,gBAAgB;IAChB,cAAuB,aAAa,IAAI,OAAO,CAAC,aAAa,CAAC,CAK7D;IA0FD,gBAAgB;IACP,MAAM,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI;IA6SxC,gBAAgB;IACP,MAAM,IAAI,IAAI;IAmBvB;;;OAGG;IACM,WAAW,CAAC,KAAK,EAAE,WAAW,GAAG,OAAO;IAYjD;;;;;OAKG;IACM,WAAW,CAAC,KAAK,EAAE,cAAc,GAAG,OAAO,GAAG,IAAI;IA8B3D;;;OAGG;IACM,SAAS,CAAC,KAAK,EAAE,aAAa,GAAG,OAAO,GAAG,IAAI;IA+NxD;;;;OAIG;IACM,cAAc,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC,CAAC,EAAE,GAAG,YAAY,CAAC,CAAC,CAAC,EAAE;IAsCtE;;;;;;;;;;;;;;;OAeG;IACM,WAAW,CAAC,IAAI,EAAE,SAAS,CAAC,EAAE,GAAG,CAAC,EAAE;IAyD7C;;;;;OAKG;IACM,WAAW,IAAI,IAAI;IAqE5B;;;;OAIG;IACM,eAAe,CAAC,OAAO,EAAE,sBAAsB,GAAG,IAAI;IAgB/D;;;;;;;;;;;;OAYG;IACM,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,IAAI;IAqC7D;;;OAGG;IACM,cAAc,IAAI,IAAI;IAQ/B;;;OAGG;IACH,IAAI,WAAW,IAAI,CAAC,EAAE,CAErB;IAED;;OAEG;IACH,IAAI,aAAa,IAAI,MAAM,EAAE,CAE5B;IAED;;OAEG;IACH,IAAI,aAAa,IAAI,MAAM,CAE1B;IAED;;OAEG;IACH,IAAI,aAAa,IAAI,MAAM,CAE1B;IAED;;OAEG;IACH,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAIvC;;OAEG;IACH,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,GAAG,OAAO;IAI1D;;;OAGG;IACH,YAAY,CAAC,QAAQ,EAAE,MAAM,GAAG,OAAO;IAYvC;;;OAGG;IACH,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAMxC,gFAAgF;IAChF,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAQ/B,4BAA4B;IAC5B,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAIlC,4CAA4C;IAC5C,IAAI,KAAK,IAAI,OAAO,CAInB;IAED,qCAAqC;IACrC,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAED,6EAA6E;IAC7E,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAanC,kFAAkF;IAClF,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAY9B,yFAAyF;IACzF,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAahC,mEAAmE;IACnE,eAAe,IAAI,IAAI;IAMvB,8FAA8F;IAC9F,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAK5C,oEAAoE;IACpE,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAKnC,+DAA+D;IAC/D,YAAY,IAAI,aAAa,CAAC,CAAC,CAAC,EAAE;IAMlC;;OAEG;IACH,IAAI,WAAW,IAAI,MAAM,EAAE,CAI1B;IAED;;;;;OAKG;IACH,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAe9B;;OAEG;IACH,SAAS,IAAI,IAAI;IAWjB;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,SAAK,GAAG,IAAI;IAI5D,mDAAmD;IACnD,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAIhD,kDAAkD;IAClD,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAIpC,qDAAqD;IACrD,eAAe,IAAI,IAAI;IAIvB,qDAAqD;IACrD,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO;IAIpD,sDAAsD;IACtD,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAInE,4CAA4C;IAC5C,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAIvC,wCAAwC;IACxC,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;IAMpD;;;;OAIG;IACH,gBAAgB,CAAC,MAAM,CAAC,EAAE,OAAO,GAAG,IAAI;IAgBxC;;;;;OAKG;IACH,aAAa,CAAC,QAAQ,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAgBpD;;;;;OAKG;IACH,aAAa,CAAC,QAAQ,EAAE,MAAM,GAAG,IAAI;IA8CrC;;;OAGG;IACH,mBAAmB,IAAI,IAAI;IAM3B;;OAEG;IACH,mBAAmB,IAAI,IAAI;CAomB5B"}
|
|
@@ -9,8 +9,10 @@ type AnyColumn = ColumnConfig<any>;
|
|
|
9
9
|
*/
|
|
10
10
|
export declare function defaultEditorFor(column: AnyColumn): (ctx: ColumnEditorContext) => HTMLElement | string;
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Get the typed value from an input element based on its type, column config, and original value.
|
|
13
|
+
* Preserves the type of the original value (e.g., numeric currency values stay as numbers,
|
|
14
|
+
* string dates stay as strings, null/undefined for empty fields).
|
|
13
15
|
*/
|
|
14
|
-
export declare function getInputValue(input: HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement,
|
|
16
|
+
export declare function getInputValue(input: HTMLInputElement | HTMLTextAreaElement | HTMLSelectElement, column?: AnyColumn, originalValue?: unknown): unknown;
|
|
15
17
|
export {};
|
|
16
18
|
//# sourceMappingURL=editors.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"editors.d.ts","sourceRoot":"","sources":["../../../../../../libs/grid/src/lib/plugins/editing/editors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAU1E,2DAA2D;AAE3D,KAAK,SAAS,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;AAyOnC;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,GAAG,CAAC,GAAG,EAAE,mBAAmB,KAAK,WAAW,GAAG,MAAM,CAatG;AAMD
|
|
1
|
+
{"version":3,"file":"editors.d.ts","sourceRoot":"","sources":["../../../../../../libs/grid/src/lib/plugins/editing/editors.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,mBAAmB,EAAE,MAAM,kBAAkB,CAAC;AAU1E,2DAA2D;AAE3D,KAAK,SAAS,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC;AAyOnC;;;;;GAKG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,SAAS,GAAG,CAAC,GAAG,EAAE,mBAAmB,KAAK,WAAW,GAAG,MAAM,CAatG;AAMD;;;;GAIG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,gBAAgB,GAAG,mBAAmB,GAAG,iBAAiB,EACjE,MAAM,CAAC,EAAE,SAAS,EAClB,aAAa,CAAC,EAAE,OAAO,GACtB,OAAO,CAwDT"}
|
|
@@ -6,6 +6,6 @@
|
|
|
6
6
|
*/
|
|
7
7
|
export { EditingPlugin } from './EditingPlugin';
|
|
8
8
|
export { defaultEditorFor } from './editors';
|
|
9
|
-
export type { DirtyChangeDetail, DirtyRowEntry } from './internal/dirty-tracking';
|
|
10
|
-
export type { BeforeEditCloseDetail, CellCommitDetail, ChangedRowsResetDetail, DateEditorParams, EditCloseDetail, EditOpenDetail, EditingConfig, EditorContext, EditorParams, NumberEditorParams, RowCommitDetail, SelectEditorParams, TextEditorParams, } from './types';
|
|
9
|
+
export type { BaselinesCapturedDetail, DirtyChangeDetail, DirtyRowEntry } from './internal/dirty-tracking';
|
|
10
|
+
export type { BeforeEditCloseDetail, CellCancelDetail, CellCommitDetail, ChangedRowsResetDetail, DateEditorParams, EditCloseDetail, EditOpenDetail, EditingConfig, EditorContext, EditorParams, NumberEditorParams, RowCommitDetail, SelectEditorParams, TextEditorParams, } from './types';
|
|
11
11
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../libs/grid/src/lib/plugins/editing/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,YAAY,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../libs/grid/src/lib/plugins/editing/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,OAAO,EAAE,aAAa,EAAE,MAAM,iBAAiB,CAAC;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,WAAW,CAAC;AAC7C,YAAY,EAAE,uBAAuB,EAAE,iBAAiB,EAAE,aAAa,EAAE,MAAM,2BAA2B,CAAC;AAC3G,YAAY,EAEV,qBAAqB,EACrB,gBAAgB,EAChB,gBAAgB,EAChB,sBAAsB,EAEtB,gBAAgB,EAChB,eAAe,EACf,cAAc,EACd,aAAa,EACb,aAAa,EACb,YAAY,EACZ,kBAAkB,EAClB,eAAe,EACf,kBAAkB,EAClB,gBAAgB,GACjB,MAAM,SAAS,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';document.createElement("template").innerHTML='<div class="cell" role="gridcell" part="cell"></div>';function t(t,i){if(t._virtualization?.enabled){const{rowHeight:e,container:i,viewportEl:n}=t._virtualization,o=i,r=n?.clientHeight??o?.clientHeight??0;if(o&&r>0){const i=t._focusRow*e;i<o.scrollTop?o.scrollTop=i:i+e>o.scrollTop+r&&(o.scrollTop=i-r+e)}}const n=void 0!==t._activeEditRows&&-1!==t._activeEditRows;var o;n||t.refreshVirtualWindow(!1),(o=t._bodyEl)&&o.querySelectorAll(".cell-focus").forEach(e=>e.classList.remove("cell-focus")),Array.from(t._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(e=>{e.setAttribute("aria-selected","false")});const r=t._focusRow,s=t._virtualization.start??0,d=t._virtualization.end??t._rows.length;if(r>=s&&r<d){const o=t._bodyEl.querySelectorAll(".data-grid-row")[r-s];let d=o?.children[t._focusCol];if(d&&d.classList?.contains("cell")||(d=o?.querySelector(`.cell[data-col="${t._focusCol}"]`)??o?.querySelector(".cell[data-col]")),d){d.classList.add("cell-focus"),d.setAttribute("aria-selected","true");const r=t.querySelector(".tbw-scroll-area");if(r&&d&&(!n||i?.forceHorizontalScroll))if(i?.forceScrollLeft)r.scrollLeft=0;else if(i?.forceScrollRight)r.scrollLeft=r.scrollWidth-r.clientWidth;else{const e=t._getHorizontalScrollOffsets?.(o??void 0,d)??{left:0,right:0};if(!e.skipScroll){const t=d.getBoundingClientRect(),i=r.getBoundingClientRect(),n=t.left-i.left+r.scrollLeft,o=n+t.width,s=r.scrollLeft+e.left,l=r.scrollLeft+r.clientWidth-e.right;n<s?r.scrollLeft=n-e.left:o>l&&(r.scrollLeft=o-r.clientWidth+e.right)}}if(n&&d.classList.contains("editing")){const t=d.querySelector(e);if(t&&document.activeElement!==t)try{t.focus({preventScroll:!0})}catch{}}else if(n&&!d.contains(document.activeElement)){d.hasAttribute("tabindex")||d.setAttribute("tabindex","-1");try{d.focus({preventScroll:!0})}catch{}}else if(!n){const e=t;document.activeElement!==e&&e.focus({preventScroll:!0})}}}}document.createElement("template").innerHTML='<div class="data-grid-row" role="row" part="row"></div>';const i='<svg viewBox="0 0 16 16" width="12" height="12"><path fill="currentColor" d="M6 10.5a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z"/></svg>',n={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:i,filterActive:i,print:"🖨️"};class o{static dependencies;static manifest;version="undefined"!=typeof __GRID_VERSION__?__GRID_VERSION__:"dev";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#e;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}attach(e){this.#e?.abort(),this.#e=new AbortController,this.grid=e,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#e?.abort(),this.#e=void 0}getPlugin(e){return this.grid?.getPlugin(e)}emit(e,t){this.grid?.dispatchEvent?.(new CustomEvent(e,{detail:t,bubbles:!0}))}emitCancelable(e,t){const i=new CustomEvent(e,{detail:t,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(i),i.defaultPrevented}on(e,t){this.grid?._pluginManager?.subscribe(this,e,t)}off(e){this.grid?._pluginManager?.unsubscribe(this,e)}emitPluginEvent(e,t){this.grid?._pluginManager?.emitPluginEvent(e,t)}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get gridElement(){return this.grid}get disconnectSignal(){return this.#e?.signal??this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...n,...e}}get isAnimationEnabled(){const e=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===e||"off"===e)return!1;if(!0===e||"on"===e)return!0;const t=this.gridElement;if(t){return"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}return!0}get animationDuration(){const e=this.gridElement;if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),i=parseInt(t,10);if(!isNaN(i))return i}return 200}resolveIcon(e,t){return void 0!==t?t:this.gridIcons[e]}setIcon(e,t){"string"==typeof t?e.innerHTML=t:t instanceof HTMLElement&&(e.innerHTML="",e.appendChild(t.cloneNode(!0)))}warn(e){console.warn(`[tbw-grid:${this.name}] ${e}`)}}function r(e){return t=>{const i=e.editorParams,n=document.createElement("input");n.type="date",t.value instanceof Date?n.valueAsDate=t.value:"string"==typeof t.value&&t.value&&(n.value=t.value.split("T")[0]),i?.min&&(n.min=i.min),i?.max&&(n.max=i.max),i?.placeholder&&(n.placeholder=i.placeholder);return n.addEventListener("change",()=>{var o;if(n.value)"string"==typeof t.value?t.commit(n.value):t.commit(n.valueAsDate);else if(e.nullable)t.commit(null);else{const e=i?.default;"string"==typeof t.value||"string"==typeof e?t.commit("string"==typeof e?e:`${(o=e??/* @__PURE__ */new Date).getFullYear()}-${String(o.getMonth()+1).padStart(2,"0")}-${String(o.getDate()).padStart(2,"0")}`):t.commit(e instanceof Date?e:/* @__PURE__ */new Date)}}),n.addEventListener("keydown",e=>{"Escape"===e.key&&t.cancel()}),n}}const s="__tbw_null__";function d(e){switch(e.type){case"number":return function(e){return t=>{const i=e.editorParams,n=document.createElement("input");n.type="number",n.value=null!=t.value?String(t.value):"",void 0!==i?.min&&(n.min=String(i.min)),void 0!==i?.max&&(n.max=String(i.max)),void 0!==i?.step&&(n.step=String(i.step)),i?.placeholder&&(n.placeholder=i.placeholder);const o=()=>{""===n.value?e.nullable?t.commit(null):t.commit(i?.min??0):t.commit(Number(n.value))};return n.addEventListener("blur",o),n.addEventListener("keydown",e=>{"Enter"===e.key&&o(),"Escape"===e.key&&t.cancel()}),n}}(e);case"boolean":return e=>{const t=document.createElement("input");return t.type="checkbox",t.checked=!!e.value,t.addEventListener("change",()=>e.commit(t.checked)),t};case"date":return r(e);case"select":return function(e){return t=>{const i=e.editorParams,n=document.createElement("select");if(e.multi&&(n.multiple=!0),e.nullable||i?.includeEmpty){const o=document.createElement("option");o.value=e.nullable?s:"",o.textContent=e.nullable?i?.emptyLabel??"(Blank)":i?.emptyLabel??"",null==t.value&&(o.selected=!0),n.appendChild(o)}const o=function(e){const t=e.options;return t?"function"==typeof t?t():t:[]}(e);o.forEach(i=>{const o=document.createElement("option");o.value=String(i.value),o.textContent=i.label,e.multi&&Array.isArray(t.value)&&t.value.includes(i.value)?o.selected=!0:e.multi||t.value!==i.value||(o.selected=!0),n.appendChild(o)});const r=()=>{if(e.multi){const e=Array.from(n.selectedOptions).map(e=>e.value);t.commit(e)}else e.nullable&&n.value===s?t.commit(null):t.commit(n.value)};return n.addEventListener("change",r),n.addEventListener("blur",r),n.addEventListener("keydown",e=>{"Escape"===e.key&&t.cancel()}),n}}(e);default:return function(e){return t=>{const i=e.editorParams,n=document.createElement("input");n.type="text",n.value=null!=t.value?String(t.value):"",void 0!==i?.maxLength&&(n.maxLength=i.maxLength),i?.pattern&&(n.pattern=i.pattern),i?.placeholder&&(n.placeholder=i.placeholder);const o=()=>{const i=n.value;""!==i?"string"==typeof t.value&&i===t.value.replace(/[\n\r]/g,"")||("number"==typeof t.value?t.commit(Number(i)):t.commit(i)):e.nullable?t.commit(null):t.commit("")};return n.addEventListener("blur",o),n.addEventListener("keydown",e=>{"Enter"===e.key&&o(),"Escape"===e.key&&t.cancel()}),n}}(e)}}function l(e,t,i){const n=e.get(t);return!!n&&!a(n,i)}function c(e,t,i,n){const o=e.get(t);if(!o)return!1;return!a(o[n],i[n])}function a(e,t){if(e===t)return!0;if(null==e||null==t)return!1;if(typeof e!=typeof t)return!1;if(e instanceof Date&&t instanceof Date)return e.getTime()===t.getTime();if(Array.isArray(e)){if(!Array.isArray(t)||e.length!==t.length)return!1;for(let i=0;i<e.length;i++)if(!a(e[i],t[i]))return!1;return!0}if("object"==typeof e){const i=e,n=t,o=Object.keys(i),r=Object.keys(n);if(o.length!==r.length)return!1;for(const e of o)if(!a(i[e],n[e]))return!1;return!0}return!1}function u(e,t,i){e.set(t,structuredClone(i))}function h(e,t){const i=e.get(t);return i?structuredClone(i):void 0}function f(e,t,i){const n=e.get(t);if(!n)return!1;const o=n,r=i;for(const s of Object.keys(o))r[s]=o[s];return!0}function g(e){return"string"==typeof e&&("__proto__"!==e&&"constructor"!==e&&"prototype"!==e)}function w(e,t,i){if(e instanceof HTMLInputElement){if("checkbox"===e.type)return e.checked;if("number"===e.type){if(""===e.value){if(t?.nullable)return null;const e=t?.editorParams;return e?.min??0}return Number(e.value)}if("date"===e.type)return e.value?"string"==typeof i?e.value:e.valueAsDate:t?.nullable?null:"string"==typeof i?i||/* @__PURE__ */(new Date).toISOString().slice(0,10):i??/* @__PURE__ */new Date;if("number"==typeof i){if(""===e.value){if(t?.nullable)return null;const e=t?.editorParams;return e?.min??0}return Number(e.value)}return""===e.value&&null==i?t?.nullable?null:"":"string"==typeof i&&e.value===i.replace(/[\n\r]/g,"")?i:e.value}return"number"===t?.type&&""!==e.value||"number"==typeof i&&""!==e.value?Number(e.value):null==i&&""===e.value?t?.nullable?null:"":e.value}function m(e){}class v extends o{static manifest={ownedProperties:[{property:"editable",level:"column",description:'the "editable" column property',isUsed:e=>!0===e},{property:"editor",level:"column",description:'the "editor" column property'},{property:"editorParams",level:"column",description:'the "editorParams" column property'},{property:"nullable",level:"column",description:'the "nullable" column property (allows null values)'}],events:[{type:"cell-edit-committed",description:"Emitted when a cell edit is committed (for plugin-to-plugin coordination)"}],queries:[{type:"isEditing",description:"Returns whether any cell is currently being edited"}]};name="editing";styles="@layer tbw-plugins{tbw-grid{--tbw-editing-bg: var(--tbw-color-selection);--tbw-editing-row-bg: var(--tbw-editing-bg);--tbw-editing-border: var(--tbw-border-input, 1px solid var(--tbw-color-border-strong));--tbw-padding-editing-input: var(--tbw-cell-padding-input, 2px 6px);--tbw-font-size-editor: inherit;--tbw-editing-row-outline-color: var(--tbw-color-accent);--tbw-editing-row-outline-width: 1px;--tbw-invalid-bg: light-dark(#fef2f2, #450a0a);--tbw-invalid-border-color: light-dark(#ef4444, #f87171)}tbw-grid:not(.tbw-grid-mode) .data-grid-row:has(.editing){background:var(--tbw-editing-row-bg);outline:var(--tbw-editing-row-outline-width) solid var(--tbw-editing-row-outline-color);outline-offset:calc(-1 * var(--tbw-editing-row-outline-width))}tbw-grid .data-grid-row>.cell.editing{overflow:hidden;padding:0;display:flex;min-height:calc(var(--tbw-row-height) + 2px);align-items:center;justify-content:center}tbw-grid .data-grid-row>.cell.editing input:not([type=checkbox]),tbw-grid .data-grid-row>.cell.editing select,tbw-grid .data-grid-row>.cell.editing textarea{width:100%;height:100%;flex:1 1 auto;min-width:0;border:var(--tbw-editing-border);padding:var(--tbw-padding-editing-input);font-size:var(--tbw-font-size-editor)}tbw-grid .tbw-editor-host{display:contents}tbw-grid .data-grid-row>.cell[data-invalid=true]{background:var(--tbw-invalid-bg);outline:1px solid var(--tbw-invalid-border-color);outline-offset:-1px}}";get defaultConfig(){return{mode:"row",editOn:"click"}}get#t(){return"grid"===this.config.mode}#i=-1;#n;#o;#r=-1;#s=/* @__PURE__ */new Map;#d=/* @__PURE__ */new Set;#l=/* @__PURE__ */new Set;#c=/* @__PURE__ */new Map;#a=!1;#u=-1;#h=/* @__PURE__ */new Map;#f=!1;#g=!1;#w=!1;#m=/* @__PURE__ */new Map;#v=!1;#p=/* @__PURE__ */new Set;#E=/* @__PURE__ */new Set;attach(t){super.attach(t);const i=this.disconnectSignal,n=t;if(n._activeEditRows=-1,n._rowEditSnapshots=/* @__PURE__ */new Map,Object.defineProperty(t,"changedRows",{get:()=>this.changedRows,configurable:!0}),Object.defineProperty(t,"changedRowIds",{get:()=>this.changedRowIds,configurable:!0}),t.resetChangedRows=e=>this.resetChangedRows(e),t.beginBulkEdit=(e,t)=>{t&&this.beginCellEdit(e,t)},document.addEventListener("keydown",e=>{if(!this.#t&&"Escape"===e.key&&-1!==this.#i){if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(e))return}this.#b(this.#i,!0)}},{capture:!0,signal:i}),document.addEventListener("mousedown",e=>{if(this.#t)return;if(-1===this.#i)return;const t=n.findRenderedRowElement?.(this.#i);if(!t)return;if((e.composedPath&&e.composedPath()||[]).includes(t))return;const i=e.target;if(!i||this.gridElement.contains(i)||!this.grid.containsFocus?.(i)){if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(e))return}queueMicrotask(()=>{-1!==this.#i&&this.#b(this.#i,!1)})}},{signal:i}),this.config.focusTrap&&this.gridElement.addEventListener("focusout",e=>{if(this.#t)return;if(-1===this.#i)return;const t=e.relatedTarget;t&&this.grid.containsFocus?.(t)||t&&this.gridElement.contains(t)||queueMicrotask(()=>{-1!==this.#i&&this.#R()})},{signal:i}),this.gridElement.addEventListener("cell-change",e=>{const t=e.detail;if("user"===t.source)return;const i=`${t.rowIndex}:${t.field}`,n=this.#c.get(i);n&&n(t.newValue)},{signal:i}),this.config.dirtyTracking){const e=e=>{const t=e.detail,i=t?.action;if(!i)return;const n=this.rows[i.rowIndex];if(!n)return;const o=this.grid.getRowId(n);if(!o)return;const r=l(this.#m,o,n);this.emit("dirty-change",{rowId:o,row:n,original:h(this.#m,o),type:r?"modified":"pristine"})};this.gridElement.addEventListener("undo",e,{signal:i}),this.gridElement.addEventListener("redo",e,{signal:i}),this.on("row-inserted",e=>{const t=this.grid.getRowId(e.row);null!=t&&this.markAsNew(String(t))})}this.#t&&(n._isGridEditMode=!0,this.gridElement.classList.add("tbw-grid-mode"),this.requestRender(),this.gridElement.addEventListener("focusin",t=>{const i=t.target;if(i.matches(e)){if(this.#g)return i.blur(),void this.gridElement.focus();this.#f=!0}},{signal:i}),this.gridElement.addEventListener("focusout",t=>{const i=t.relatedTarget;i&&(this.gridElement.contains(i)||this.grid.containsFocus?.(i))&&i.matches(e)||(this.#f=!1)},{signal:i}),this.gridElement.addEventListener("keydown",e=>{if("Escape"===e.key&&this.#f){if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(e))return}const t=document.activeElement;t&&this.gridElement.contains(t)&&(t.blur(),this.gridElement.focus()),this.#f=!1,this.#g=!0,e.preventDefault(),e.stopPropagation()}},{capture:!0,signal:i}),this.gridElement.addEventListener("mousedown",t=>{t.target.matches(e)&&(this.#g=!1)},{signal:i}))}detach(){this.gridElement._isGridEditMode=!1,this.gridElement.classList.remove("tbw-grid-mode"),this.#i=-1,this.#n=void 0,this.#o=void 0,this.#r=-1,this.#s.clear(),this.#d.clear(),this.#E.clear(),this.#l.clear(),this.#c.clear(),this.#m.clear(),this.#p.clear(),this.#f=!1,this.#g=!1,this.#w=!1,super.detach()}handleQuery(e){if("isEditing"===e.type)return this.#t||-1!==this.#i}onCellClick(e){if(this.#t)return!1;const t=this.grid,i=this.config.editOn??t.effectiveConfig?.editOn;if(!1===i||"manual"===i)return!1;if("click"!==i&&"dblclick"!==i)return!1;const n="dblclick"===e.originalEvent.type;if("click"===i&&n)return!1;if("dblclick"===i&&!n)return!1;const{rowIndex:o}=e,r=t._columns?.some(e=>e.editable);return!!r&&(e.originalEvent.stopPropagation(),this.beginBulkEdit(o),!0)}onKeyDown(e){const i=this.grid;if("Escape"===e.key){if(this.#t&&this.#f){if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(e))return!0}const t=document.activeElement;return t&&this.gridElement.contains(t)&&t.blur(),this.#f=!1,this.requestAfterRender(),!0}if(-1!==this.#i&&!this.#t){if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(e))return!0}return this.#b(this.#i,!0),!0}}if(this.#t&&!this.#f&&("ArrowUp"===e.key||"ArrowDown"===e.key||"ArrowLeft"===e.key||"ArrowRight"===e.key))return!1;if(this.#t&&this.#f&&("ArrowUp"===e.key||"ArrowDown"===e.key))return!0;if(("ArrowUp"===e.key||"ArrowDown"===e.key)&&-1!==this.#i&&!this.#t){if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(e))return!0}const n=i._rows.length-1,o=this.#i;return this.#b(o,!1),"ArrowDown"===e.key?i._focusRow=Math.min(n,i._focusRow+1):i._focusRow=Math.max(0,i._focusRow-1),e.preventDefault(),t(i),this.requestAfterRender(),!0}if("Tab"===e.key&&(-1!==this.#i||this.#t)){if(e.preventDefault(),this.#w)return this.#b(this.#i,!1),!0;const t=!e.shiftKey;return this.#y(t),!0}if(" "===e.key||"Spacebar"===e.key){if(-1!==this.#i)return!1;const t=i._focusRow,n=i._focusCol;if(t>=0&&n>=0){const o=i._visibleColumns[n],r=i._rows[t];if(o?.editable&&"boolean"===o.type&&r){const i=o.field;if(g(i)){const n=!r[i];return this.#C(t,o,n,r),e.preventDefault(),this.requestRender(),!0}}}return!1}if(!("Enter"!==e.key||e.shiftKey||e.ctrlKey||e.altKey||e.metaKey)){if(this.#t&&!this.#f)return this.#R(),!0;if(-1!==this.#i){if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(e))return!0}return!1}const t=this.config.editOn??i.effectiveConfig?.editOn;if(!1===t||"manual"===t)return!1;const n=i._focusRow,o=i._focusCol;if(n>=0){const t=i._columns?.some(e=>e.editable);if(t){const t=i._visibleColumns[o],r=i._rows[n],s=t?.field??"",d=s&&r?r[s]:void 0,l=this.gridElement.querySelector(`[data-row="${n}"][data-col="${o}"]`),c=new CustomEvent("cell-activate",{cancelable:!0,bubbles:!0,detail:{rowIndex:n,colIndex:o,field:s,value:d,row:r,cellEl:l,trigger:"keyboard",originalEvent:e}});this.gridElement.dispatchEvent(c);const a=new CustomEvent("activate-cell",{cancelable:!0,bubbles:!0,detail:{row:n,col:o}});return this.gridElement.dispatchEvent(a),c.defaultPrevented||a.defaultPrevented?(e.preventDefault(),!0):(this.beginBulkEdit(n),!0)}}return!1}if("F2"===e.key){if(-1!==this.#i||this.#t)return!1;if(!1===(this.config.editOn??i.effectiveConfig?.editOn))return!1;const t=i._focusRow,n=i._focusCol;if(t>=0&&n>=0){const o=i._visibleColumns[n];if(o?.editable&&o.field)return e.preventDefault(),this.beginCellEdit(t,o.field),!0}return!1}return!1}processColumns(e){const t=this.grid,i=t.effectiveConfig?.typeDefaults,n=t.__frameworkAdapter;return i||n?.getTypeDefault?e.map(e=>{if(!e.type)return e;let t;if(i?.[e.type]?.editorParams&&(t=i[e.type].editorParams),!t&&n?.getTypeDefault){const i=n.getTypeDefault(e.type);i?.editorParams&&(t=i.editorParams)}return t?{...e,editorParams:{...t,...e.editorParams}}:e}):e}processRows(e){const t=this.grid;if(this.config.dirtyTracking&&t.getRowId){const i=this.#m.size;!function(e,t,i){for(const n of t)try{const t=i(n);null==t||e.has(t)||e.set(t,structuredClone(n))}catch{}}(this.#m,e,e=>{try{return t.getRowId?.(e)}catch{return}}),this.#m.size>i&&(this.#v=!0)}if(-1===this.#i||this.#t)return e;const i=this.#n,n=this.#o;if(!i||!n)return e;const o=[...e];let r=-1;for(let s=0;s<o.length;s++)try{if(t.getRowId?.(o[s])===i){r=s;break}}catch{}return-1===r?(setTimeout(()=>this.cancelActiveRowEdit(),0),o):(o[r]=n,this.#i!==r&&this.#I(this.#i,r),o)}afterRender(){const e=this.grid;if(-1!==this.#i&&this.#o&&!this.#t&&e._rows[this.#i]!==this.#o){const t=e._rows.indexOf(this.#o);if(-1===t)return void setTimeout(()=>this.cancelActiveRowEdit(),0);this.#I(this.#i,t)}if(this.#a&&(this.#a=!1,this.#k(e)),-1!==this.#u){const t=this.#u;this.#u=-1,e.animateRow?.(t,"change")}if(this.#v&&(this.#v=!1,this.emit("baselines-captured",{count:this.#m.size})),!this.#t&&0!==this.#l.size)for(const t of this.#l){const[i,n]=t.split(":"),o=parseInt(i,10),r=parseInt(n,10),s=e.findRenderedRowElement?.(o);if(!s)continue;const d=s.querySelector(`.cell[data-col="${r}"]`);if(!d||d.classList.contains("editing"))continue;const l=e._rows[o],c=e._visibleColumns[r];l&&c&&this.#_(l,o,c,r,d,!0)}}afterCellRender(e){if(!this.#t)return;const{row:t,rowIndex:i,column:n,colIndex:o,cellElement:r}=e;n.editable&&(r.classList.contains("editing")||this.#_(t,i,n,o,r,!0))}afterRowRender(e){if(!this.config.dirtyTracking)return;const t=this.gridElement,i=t.getRowId?.(e.row);if(!i)return;const n=this.#p.has(i),o=!n&&this.#E.has(i)&&l(this.#m,i,e.row),r=e.rowElement;r.classList.toggle("tbw-row-dirty",o),r.classList.toggle("tbw-row-new",n);if(this.#m.has(i)){const t=r.querySelectorAll(".cell[data-field]");for(let n=0;n<t.length;n++){const o=t[n],r=o.getAttribute("data-field");r&&o.classList.toggle("tbw-cell-dirty",c(this.#m,i,e.row,r))}}else{const e=r.querySelectorAll(".tbw-cell-dirty");for(let t=0;t<e.length;t++)e[t].classList.remove("tbw-cell-dirty")}}onScrollRender(){this.afterRender()}get changedRows(){const e=[];for(const t of this.#d){const i=this.grid.getRow(t);i&&e.push(i)}return e}get changedRowIds(){return Array.from(this.#d)}get activeEditRow(){return this.#i}get activeEditCol(){return this.#r}isRowEditing(e){return this.#i===e}isCellEditing(e,t){return this.#l.has(`${e}:${t}`)}isRowChanged(e){const t=this.grid,i=t._rows[e];if(!i)return!1;try{const e=t.getRowId?.(i);return!!e&&this.#d.has(e)}catch{return!1}}isRowChangedById(e){return this.#d.has(e)}isDirty(e){if(!this.config.dirtyTracking)return!1;if(this.#p.has(e))return!0;const t=this.grid.getRow(e);return!!t&&l(this.#m,e,t)}isPristine(e){return!this.isDirty(e)}get dirty(){if(!this.config.dirtyTracking)return!1;if(this.#p.size>0)return!0;const e=this.grid;for(const[t,i]of this.#m){const i=e._getRowEntry(t)?.row;if(i&&l(this.#m,t,i))return!0}return!1}get pristine(){return!this.dirty}markAsPristine(e){if(!this.config.dirtyTracking)return;const t=this.grid.getRow(e);t&&(u(this.#m,e,t),this.#p.delete(e),this.#d.delete(e),this.#E.delete(e),this.emit("dirty-change",{rowId:e,row:t,original:t,type:"pristine"}))}markAsNew(e){if(!this.config.dirtyTracking)return;this.#p.add(e),this.#E.add(e);const t=this.grid.getRow(e);this.emit("dirty-change",{rowId:e,row:t,original:void 0,type:"new"})}markAsDirty(e){if(!this.config.dirtyTracking)return;const t=this.grid.getRow(e);t&&(this.#d.add(e),this.#E.add(e),this.emit("dirty-change",{rowId:e,row:t,original:h(this.#m,e),type:"modified"}))}markAllPristine(){if(!this.config.dirtyTracking)return;const e=this.grid;for(const[t]of this.#m){const i=e._getRowEntry(t)?.row;i&&u(this.#m,t,i)}this.#p.clear(),this.#d.clear(),this.#E.clear()}getOriginalRow(e){if(this.config.dirtyTracking)return h(this.#m,e)}hasBaseline(e){return!!this.config.dirtyTracking&&this.#m.has(e)}getDirtyRows(){if(!this.config.dirtyTracking)return[];const e=[],t=this.grid;for(const[i,n]of this.#m){const o=t._getRowEntry(i);o&&l(this.#m,i,o.row)&&e.push({id:i,original:structuredClone(n),current:o.row})}for(const i of this.#p){const n=t._getRowEntry(i);n&&e.push({id:i,original:void 0,current:n.row})}return e}get dirtyRowIds(){if(!this.config.dirtyTracking)return[];const e=[],t=this.grid;for(const[i]of this.#m){const n=t._getRowEntry(i);n&&l(this.#m,i,n.row)&&e.push(i)}for(const i of this.#p)e.push(i);return e}revertRow(e){if(!this.config.dirtyTracking)return;const t=this.grid.getRow(e);if(!t)return;f(this.#m,e,t)&&(this.#d.delete(e),this.#E.delete(e),this.emit("dirty-change",{rowId:e,row:t,original:h(this.#m,e),type:"reverted"}),this.requestRender())}revertAll(){if(!this.config.dirtyTracking)return;const e=this.grid;for(const[t]of this.#m){const i=e._getRowEntry(t);i&&f(this.#m,t,i.row)}this.#d.clear(),this.#E.clear(),this.requestRender()}setInvalid(e,t,i=""){let n=this.#h.get(e);n||(n=/* @__PURE__ */new Map,this.#h.set(e,n)),n.set(t,i),this.#S(e,t,!0)}clearInvalid(e,t){const i=this.#h.get(e);i&&(i.delete(t),0===i.size&&this.#h.delete(e)),this.#S(e,t,!1)}clearRowInvalid(e){const t=this.#h.get(e);if(t){const i=Array.from(t.keys());this.#h.delete(e),i.forEach(t=>this.#S(e,t,!1))}}clearAllInvalid(){const e=Array.from(this.#h.entries());this.#h.clear(),e.forEach(([e,t])=>{t.forEach((t,i)=>this.#S(e,i,!1))})}isCellInvalid(e,t){return this.#h.get(e)?.has(t)??!1}getInvalidMessage(e,t){return this.#h.get(e)?.get(t)}hasInvalidCells(e){const t=this.#h.get(e);return!!t&&t.size>0}getInvalidFields(e){return new Map(this.#h.get(e)??[])}#S(e,t,i){const n=this.grid,o=n._visibleColumns?.findIndex(e=>e.field===t);if(-1===o||void 0===o)return;const r=n._rows,s=r?.findIndex(t=>{try{return n.getRowId?.(t)===e}catch{return!1}});if(-1===s||void 0===s)return;const d=n.findRenderedRowElement?.(s),l=d?.querySelector(`.cell[data-col="${o}"]`);if(l)if(i){l.setAttribute("data-invalid","true");const i=this.#h.get(e)?.get(t);i&&l.setAttribute("title",i)}else l.removeAttribute("data-invalid"),l.removeAttribute("title")}resetChangedRows(e){const t=this.changedRows,i=this.changedRowIds;this.#d.clear(),this.#E.clear(),this.#x(),e||this.emit("changed-rows-reset",{rows:t,ids:i});const n=this.grid;n._rowPool?.forEach(e=>e.classList.remove("changed"))}beginCellEdit(e,t){const i=this.grid,n=i._visibleColumns.findIndex(e=>e.field===t);if(-1===n)return;const o=i._visibleColumns[n];if(!o?.editable)return;const r=i.findRenderedRowElement?.(e),s=r?.querySelector(`.cell[data-col="${n}"]`);s&&(this.#w=!0,this.#L(e,n,s))}beginBulkEdit(t){const i=this.grid;if(!1===(this.config.editOn??i.effectiveConfig?.editOn))return;const n=i._columns?.some(e=>e.editable);if(!n)return;const o=i.findRenderedRowElement?.(t);if(!o)return;this.#w=!1;const r=i._rows[t];this.#A(t,r),Array.from(o.children).forEach((e,n)=>{const o=i._visibleColumns[n];if(o?.editable){const i=e;i.classList.contains("editing")||this.#_(r,t,o,n,i,!0)}}),setTimeout(()=>{let t=o.querySelector(`.cell[data-col="${i._focusCol}"]`);if(t?.classList.contains("editing")||(t=o.querySelector(".cell.editing")),t?.classList.contains("editing")){const i=t.querySelector(e);try{i?.focus({preventScroll:!0})}catch{}}},0)}commitActiveRowEdit(){-1!==this.#i&&this.#b(this.#i,!1)}cancelActiveRowEdit(){-1!==this.#i&&this.#b(this.#i,!0)}#I(e,t){this.#i=t;const i=/* @__PURE__ */new Set,n=`${e}:`;for(const s of this.#l)s.startsWith(n)?i.add(`${t}:${s.substring(n.length)}`):i.add(s);this.#l.clear();for(const s of i)this.#l.add(s);const o=this.#s.get(e);void 0!==o&&(this.#s.delete(e),this.#s.set(t,o));const r=[];for(const[s,d]of this.#c)s.startsWith(n)&&(r.push([`${t}:${s.substring(n.length)}`,d]),this.#c.delete(s));for(const[s,d]of r)this.#c.set(s,d);this.#x()}#L(e,t,i){const n=this.grid,o=n._rows[e],r=n._visibleColumns[t];o&&r?.editable&&(i.classList.contains("editing")||(this.#i!==e&&this.#A(e,o),this.#r=t,this.#_(o,e,r,t,i,!1)))}#R(){const t=this.grid,i=t._focusRow,n=t._focusCol;if(i<0||n<0)return;const o=t.findRenderedRowElement?.(i),r=o?.querySelector(`.cell[data-col="${n}"]`);if(r?.classList.contains("editing")){const t=r.querySelector(e);t&&(this.#g=!1,t.focus(),this.#f=!0,t instanceof HTMLInputElement&&("text"===t.type||"number"===t.type)&&t.select())}}#y(i){const n=this.grid,o=n._rows,r=this.#t?n._focusRow:this.#i,s=n._visibleColumns.map((e,t)=>e.editable?t:-1).filter(e=>e>=0);if(0===s.length)return;const d=s.indexOf(n._focusCol)+(i?1:-1);if(d>=0&&d<s.length){n._focusCol=s[d];const i=n.findRenderedRowElement?.(r),o=i?.querySelector(`.cell[data-col="${s[d]}"]`);if(o?.classList.contains("editing")){const t=o.querySelector(e);t?.focus({preventScroll:!0})}return void t(n,{forceHorizontalScroll:!0})}const l=r+(i?1:-1);l>=0&&l<o.length&&(this.#t?(n._focusRow=l,n._focusCol=i?s[0]:s[s.length-1],t(n,{forceHorizontalScroll:!0}),this.requestAfterRender(),setTimeout(()=>{const t=n.findRenderedRowElement?.(l),i=t?.querySelector(`.cell[data-col="${n._focusCol}"]`);if(i?.classList.contains("editing")){const t=i.querySelector(e);t?.focus({preventScroll:!0})}},0)):(this.#b(r,!1),n._focusRow=l,n._focusCol=i?s[0]:s[s.length-1],this.beginBulkEdit(l),t(n,{forceHorizontalScroll:!0})))}#x(){const e=this.grid;e._activeEditRows=this.#i,e._rowEditSnapshots=this.#s}#A(e,t){if(this.#i!==e){-1!==this.#i&&this.#b(this.#i,!1),this.#s.set(e,{...t}),this.#i=e,this.#o=t;const i=this.grid;try{this.#n=i.getRowId?.(t)??void 0}catch{this.#n=void 0}this.#x(),this.#t||this.emit("edit-open",{rowIndex:e,rowId:this.#n??"",row:t})}}#b(e,t){if(this.#i!==e)return;const i=this.grid,n=this.#s.get(e),o=i.findRenderedRowElement?.(e);let r=this.#n;const s=r?i._getRowEntry(r):void 0,d=s?.row??this.#o??i._rows[e];if(!r&&d)try{r=i.getRowId?.(d)}catch{}if(!t&&o&&d){o.querySelectorAll(".cell.editing").forEach(t=>{const n=Number(t.getAttribute("data-col"));if(isNaN(n))return;const o=i._visibleColumns[n];if(!o)return;if(t.hasAttribute("data-editor-managed"))return;const r=t.querySelector("input,textarea,select");if(r){const t=o.field,i=d[t],n=w(r,o,i);i!==n&&this.#C(e,o,n,d)}})}if(t||this.#t||!d||this.emit("before-edit-close",{rowIndex:e,rowId:r??"",row:d}),t&&n&&d)Object.keys(n).forEach(e=>{d[e]=n[e]}),r&&(this.#d.delete(r),this.#E.delete(r),this.clearRowInvalid(r));else if(!t&&d){const t=this.#M(n,d),i=r?this.#d.has(r):t,o=this.emitCancelable("row-commit",{rowIndex:e,rowId:r??"",row:d,oldValue:n,newValue:d,changed:i,changedRows:this.changedRows,changedRowIds:this.changedRowIds});o&&n?(Object.keys(n).forEach(e=>{d[e]=n[e]}),r&&(this.#d.delete(r),this.#E.delete(r),this.clearRowInvalid(r))):o||(r&&this.config.dirtyTracking&&(l(this.#m,r,d)?this.#E.add(r):this.#E.delete(r)),t&&this.isAnimationEnabled&&(this.#u=e))}this.#s.delete(e),this.#i=-1,this.#n=void 0,this.#o=void 0,this.#r=-1,this.#w=!1,this.#x();for(const l of this.#l)l.startsWith(`${e}:`)&&this.#l.delete(l);for(const l of this.#c.keys())l.startsWith(`${e}:`)&&this.#c.delete(l);this.#a=!0,o?(o.querySelectorAll(".cell.editing").forEach(e=>{e.classList.remove("editing"),function(e){e.__editingCellCount=0,e.removeAttribute("data-has-editing")}(e.parentElement)}),i.refreshVirtualWindow(!0)):(this.#k(i),this.#a=!1),!this.#t&&d&&this.emit("edit-close",{rowIndex:e,rowId:r??"",row:d,reverted:t})}#C(e,t,i,n){const o=t.field;if(!g(o))return;const r=n[o];if(r===i)return;const s=this.grid;let d;try{d=this.grid.getRowId(n)}catch{}const c=!d||!this.#d.has(d),a=d?e=>this.grid.updateRow(d,e,"cascade"):m;let u=!1;const f=d?e=>{u=!0,this.setInvalid(d,o,e??"")}:()=>{};if(this.emitCancelable("cell-commit",{row:n,rowId:d??"",field:o,oldValue:r,value:i,rowIndex:e,changedRows:this.changedRows,changedRowIds:this.changedRowIds,firstTimeForRow:c,updateRow:a,setInvalid:f}))return;if(d&&!u&&this.isCellInvalid(d,o)&&this.clearInvalid(d,o),n[o]=i,d&&this.#d.add(d),this.#x(),this.config.dirtyTracking&&d){const e=l(this.#m,d,n);this.emit("dirty-change",{rowId:d,row:n,original:h(this.#m,d),type:e?"modified":"pristine"})}this.emitPluginEvent("cell-edit-committed",{rowIndex:e,field:o,oldValue:r,newValue:i});const w=s.findRenderedRowElement?.(e);w&&w.classList.add("changed")}#_(t,i,n,o,r,s){if(!n.editable)return;if(r.classList.contains("editing"))return;let l;try{l=this.grid.getRowId(t)}catch{}const c=l?e=>this.grid.updateRow(l,e,"cascade"):m,a=g(n.field)?t[n.field]:void 0;r.classList.add("editing"),this.#l.add(`${i}:${o}`);const u=r.parentElement;u&&function(e){const t=(e.__editingCellCount??0)+1;e.__editingCellCount=t,e.setAttribute("data-has-editing","")}(u);let h=!1;const f=e=>{if(h||!this.#t&&-1===this.#i)return;const o=this.grid,r=l?o._getRowEntry(l):void 0,s=r?.row??t,d=r?.index??i;this.#C(d,n,e,s)},v=()=>{if(h=!0,g(n.field)){const e=this.grid,i=l?e._getRowEntry(l):void 0;(i?.row??t)[n.field]=a}},p=document.createElement("div");p.className="tbw-editor-host",r.innerHTML="",r.appendChild(p),p.addEventListener("keydown",e=>{if("Enter"===e.key){if(this.#t){e.stopPropagation(),e.preventDefault();const t=p.querySelector("input,textarea,select");return void(t&&f(w(t,n,a)))}if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(e))return}e.stopPropagation(),e.preventDefault(),h=!0,this.#b(i,!1)}if("Escape"===e.key){if(this.#t)return e.stopPropagation(),void e.preventDefault();if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(e))return}e.stopPropagation(),e.preventDefault(),v(),this.#b(i,!0)}});const E=n,b=E.__editorTemplate,R=function(e,t){if(t.editor)return t.editor;if(t.__editorTemplate)return"template";if(!t.type)return;const i=e.effectiveConfig?.typeDefaults;if(i?.[t.type]?.editor)return i[t.type].editor;const n=e.__frameworkAdapter;if(n?.getTypeDefault){const e=n.getTypeDefault(t.type);if(e?.editor)return e.editor}}(this.grid,E)??d(n),y=a,C=`${i}:${n.field}`,I=[];this.#c.set(C,e=>{for(const t of I)t(e)});const k=e=>{I.push(e)};if("template"===R&&b)this.#T(p,E,t,a,f,v,s,i),k(e=>{const t=p.querySelector("input,textarea,select");t&&(t instanceof HTMLInputElement&&"checkbox"===t.type?t.checked=!!e:t.value=String(e??""))});else if("string"==typeof R){const t=document.createElement(R);t.value=y,t.addEventListener("change",()=>f(t.value)),k(e=>{t.value=e}),p.appendChild(t),s||queueMicrotask(()=>{const t=p.querySelector(e);t?.focus({preventScroll:!0})})}else if("function"==typeof R){const i=R({row:t,rowId:l??"",value:y,field:n.field,column:n,commit:f,cancel:v,updateRow:c,onValueChange:k});if("string"==typeof i)p.innerHTML=i,function(e,t,i,n){const o=e.querySelector("input,textarea,select");o&&(o.addEventListener("blur",()=>{i(w(o,t,n))}),o instanceof HTMLInputElement&&"checkbox"===o.type?o.addEventListener("change",()=>i(o.checked)):o instanceof HTMLSelectElement&&o.addEventListener("change",()=>i(w(o,t,n))))}(p,n,f,a),k(e=>{const t=p.querySelector("input,textarea,select");t&&(t instanceof HTMLInputElement&&"checkbox"===t.type?t.checked=!!e:t.value=String(e??""))});else if(i instanceof Node){p.appendChild(i);i instanceof HTMLInputElement||i instanceof HTMLSelectElement||i instanceof HTMLTextAreaElement?k(e=>{i instanceof HTMLInputElement&&"checkbox"===i.type?i.checked=!!e:i.value=String(e??"")}):r.setAttribute("data-editor-managed","")}else!i&&p.hasChildNodes()&&r.setAttribute("data-editor-managed","");s||queueMicrotask(()=>{const t=p.querySelector(e);t?.focus({preventScroll:!0})})}else if(R&&"object"==typeof R){const e=document.createElement("div");e.setAttribute("data-external-editor",""),e.setAttribute("data-field",n.field),p.appendChild(e),r.setAttribute("data-editor-managed","");const i={row:t,rowId:l??"",value:y,field:n.field,column:n,commit:f,cancel:v,updateRow:c,onValueChange:k};if(R.mount)try{R.mount({placeholder:e,context:i,spec:R})}catch(_){console.warn(`[tbw-grid] External editor mount error for column '${n.field}':`,_)}else this.grid.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:e,spec:R,context:i}}))}}#T(e,t,i,n,o,r,s,d){const l=t.__editorTemplate;if(!l)return;const c=l.cloneNode(!0),a=t.__compiledEditor;a?c.innerHTML=a({row:i,value:n,field:t.field,column:t,commit:o,cancel:r}):c.querySelectorAll("*").forEach(e=>{1===e.childNodes.length&&e.firstChild?.nodeType===Node.TEXT_NODE&&(e.textContent=e.textContent?.replace(/{{\s*value\s*}}/g,null==n?"":String(n)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g,(e,t)=>{if(!g(t))return"";const n=i[t];return null==n?"":String(n)})||"")});const u=c.querySelector("input,textarea,select");if(u){u instanceof HTMLInputElement&&"checkbox"===u.type?u.checked=!!n:u.value=String(n??"");let e=!1;u.addEventListener("blur",()=>{e||o(w(u,t,n))}),u.addEventListener("keydown",i=>{const s=i;if("Enter"===s.key){if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(s))return}s.stopPropagation(),s.preventDefault(),e=!0,o(w(u,t,n)),this.#b(d,!1)}if("Escape"===s.key){if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(s))return}s.stopPropagation(),s.preventDefault(),r(),this.#b(d,!0)}}),u instanceof HTMLInputElement&&"checkbox"===u.type&&u.addEventListener("change",()=>o(u.checked)),s||setTimeout(()=>u.focus({preventScroll:!0}),0)}e.appendChild(c)}#M(e,t){if(!e)return!1;const i=e,n=t,o=/* @__PURE__ */new Set([...Object.keys(i),...Object.keys(n)]);for(const r of o)if(i[r]!==n[r])return!0;return!1}#k(e){queueMicrotask(()=>{try{const t=e._focusRow,i=e._focusCol,n=e.findRenderedRowElement?.(t);if(n){Array.from(e._bodyEl.querySelectorAll(".cell-focus")).forEach(e=>e.classList.remove("cell-focus"));const o=n.querySelector(`.cell[data-row="${t}"][data-col="${i}"]`);o&&(o.classList.add("cell-focus"),o.setAttribute("aria-selected","true"),o.hasAttribute("tabindex")||o.setAttribute("tabindex","-1"),o.focus({preventScroll:!0}))}}catch{}})}}export{v as EditingPlugin,d as defaultEditorFor};
|
|
1
|
+
document.createElement("template").innerHTML='<div class="cell" role="gridcell" part="cell"></div>';function t(t,e){if(t._virtualization?.enabled){const{rowHeight:e,container:i,viewportEl:n}=t._virtualization,r=i,s=n?.clientHeight??r?.clientHeight??0;if(r&&s>0){const i=t._focusRow*e;i<r.scrollTop?r.scrollTop=i:i+e>r.scrollTop+s&&(r.scrollTop=i-s+e)}}const i=void 0!==t._activeEditRows&&-1!==t._activeEditRows||!!t._isGridEditMode;var n;i||t.refreshVirtualWindow(!1),(n=t._bodyEl)&&n.querySelectorAll(".cell-focus").forEach(t=>t.classList.remove("cell-focus")),Array.from(t._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(t=>{t.setAttribute("aria-selected","false")});const r=t._focusRow,s=t._virtualization.start??0,o=t._virtualization.end??t._rows.length;if(r>=s&&r<o){const n=t._bodyEl.querySelectorAll(".data-grid-row")[r-s];let o=n?.children[t._focusCol];if(o&&o.classList?.contains("cell")||(o=n?.querySelector(`.cell[data-col="${t._focusCol}"]`)??n?.querySelector(".cell[data-col]")),o){o.classList.add("cell-focus"),o.setAttribute("aria-selected","true");const r=t.querySelector(".tbw-scroll-area");if(r&&o&&(!i||e?.forceHorizontalScroll))if(e?.forceScrollLeft)r.scrollLeft=0;else if(e?.forceScrollRight)r.scrollLeft=r.scrollWidth-r.clientWidth;else{const e=t._getHorizontalScrollOffsets?.(n??void 0,o)??{left:0,right:0};if(!e.skipScroll){const t=o.getBoundingClientRect(),i=r.getBoundingClientRect(),n=t.left-i.left+r.scrollLeft,s=n+t.width,d=r.scrollLeft+e.left,l=r.scrollLeft+r.clientWidth-e.right;n<d?r.scrollLeft=n-e.left:s>l&&(r.scrollLeft=s-r.clientWidth+e.right)}}if(i&&o.classList.contains("editing")){const t=o.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');if(t&&document.activeElement!==t)try{t.focus({preventScroll:!0})}catch{}}else if(i&&!o.contains(document.activeElement)){o.hasAttribute("tabindex")||o.setAttribute("tabindex","-1");try{o.focus({preventScroll:!0})}catch{}}else if(!i){const e=t;document.activeElement!==e&&e.focus({preventScroll:!0})}}}}document.createElement("template").innerHTML='<div class="data-grid-row" role="row" part="row"></div>';const e='<svg viewBox="0 0 16 16" width="12" height="12"><path fill="currentColor" d="M6 10.5a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z"/></svg>',i={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:e,filterActive:e,print:"🖨️"};class n{static dependencies;static manifest;version="undefined"!=typeof __GRID_VERSION__?__GRID_VERSION__:"dev";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#t;get defaultConfig(){return{}}constructor(t={}){this.userConfig=t}attach(t){this.#t?.abort(),this.#t=new AbortController,this.grid=t,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#t?.abort(),this.#t=void 0}getPlugin(t){return this.grid?.getPlugin(t)}emit(t,e){this.grid?.dispatchEvent?.(new CustomEvent(t,{detail:e,bubbles:!0}))}emitCancelable(t,e){const i=new CustomEvent(t,{detail:e,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(i),i.defaultPrevented}on(t,e){this.grid?._pluginManager?.subscribe(this,t,e)}off(t){this.grid?._pluginManager?.unsubscribe(this,t)}emitPluginEvent(t,e){this.grid?._pluginManager?.emitPluginEvent(t,e)}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get gridElement(){return this.grid}get disconnectSignal(){return this.#t?.signal??this.grid?.disconnectSignal}get gridIcons(){const t=this.grid?.gridConfig?.icons??{};return{...i,...t}}get isAnimationEnabled(){const t=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===t||"off"===t)return!1;if(!0===t||"on"===t)return!0;const e=this.gridElement;if(e){return"0"!==getComputedStyle(e).getPropertyValue("--tbw-animation-enabled").trim()}return!0}get animationDuration(){const t=this.gridElement;if(t){const e=getComputedStyle(t).getPropertyValue("--tbw-animation-duration").trim(),i=parseInt(e,10);if(!isNaN(i))return i}return 200}resolveIcon(t,e){return void 0!==e?e:this.gridIcons[t]}setIcon(t,e){"string"==typeof e?t.innerHTML=e:e instanceof HTMLElement&&(t.innerHTML="",t.appendChild(e.cloneNode(!0)))}warn(t){console.warn(`[tbw-grid:${this.name}] ${t}`)}}function r(t){return e=>{const i=t.editorParams,n=document.createElement("input");n.type="date",e.value instanceof Date?n.valueAsDate=e.value:"string"==typeof e.value&&e.value&&(n.value=e.value.split("T")[0]),i?.min&&(n.min=i.min),i?.max&&(n.max=i.max),i?.placeholder&&(n.placeholder=i.placeholder);return n.addEventListener("change",()=>{var r;if(n.value)"string"==typeof e.value?e.commit(n.value):e.commit(n.valueAsDate);else if(t.nullable)e.commit(null);else{const t=i?.default;"string"==typeof e.value||"string"==typeof t?e.commit("string"==typeof t?t:`${(r=t??/* @__PURE__ */new Date).getFullYear()}-${String(r.getMonth()+1).padStart(2,"0")}-${String(r.getDate()).padStart(2,"0")}`):e.commit(t instanceof Date?t:/* @__PURE__ */new Date)}}),n.addEventListener("keydown",t=>{"Escape"===t.key&&e.cancel()}),n}}const s="__tbw_null__";function o(t){switch(t.type){case"number":return function(t){return e=>{const i=t.editorParams,n=document.createElement("input");n.type="number",n.value=null!=e.value?String(e.value):"",void 0!==i?.min&&(n.min=String(i.min)),void 0!==i?.max&&(n.max=String(i.max)),void 0!==i?.step&&(n.step=String(i.step)),i?.placeholder&&(n.placeholder=i.placeholder);const r=()=>{""===n.value?t.nullable?e.commit(null):e.commit(i?.min??0):e.commit(Number(n.value))};return n.addEventListener("blur",r),n.addEventListener("keydown",t=>{"Enter"===t.key&&r(),"Escape"===t.key&&e.cancel()}),n}}(t);case"boolean":return t=>{const e=document.createElement("input");return e.type="checkbox",e.checked=!!t.value,e.addEventListener("change",()=>t.commit(e.checked)),e};case"date":return r(t);case"select":return function(t){return e=>{const i=t.editorParams,n=document.createElement("select");if(t.multi&&(n.multiple=!0),t.nullable||i?.includeEmpty){const r=document.createElement("option");r.value=t.nullable?s:"",r.textContent=t.nullable?i?.emptyLabel??"(Blank)":i?.emptyLabel??"",null==e.value&&(r.selected=!0),n.appendChild(r)}const r=function(t){const e=t.options;return e?"function"==typeof e?e():e:[]}(t);r.forEach(i=>{const r=document.createElement("option");r.value=String(i.value),r.textContent=i.label,t.multi&&Array.isArray(e.value)&&e.value.includes(i.value)?r.selected=!0:t.multi||e.value!==i.value||(r.selected=!0),n.appendChild(r)});const o=()=>{if(t.multi){const t=Array.from(n.selectedOptions).map(t=>t.value);e.commit(t)}else t.nullable&&n.value===s?e.commit(null):e.commit(n.value)};return n.addEventListener("change",o),n.addEventListener("blur",o),n.addEventListener("keydown",t=>{"Escape"===t.key&&e.cancel()}),n}}(t);default:return function(t){return e=>{const i=t.editorParams,n=document.createElement("input");n.type="text",n.value=null!=e.value?String(e.value):"",void 0!==i?.maxLength&&(n.maxLength=i.maxLength),i?.pattern&&(n.pattern=i.pattern),i?.placeholder&&(n.placeholder=i.placeholder);const r=()=>{const i=n.value;""!==i?"string"==typeof e.value&&i===e.value.replace(/[\n\r]/g,"")||("number"==typeof e.value?e.commit(Number(i)):e.commit(i)):t.nullable?e.commit(null):e.commit("")};return n.addEventListener("blur",r),n.addEventListener("keydown",t=>{"Enter"===t.key&&r(),"Escape"===t.key&&e.cancel()}),n}}(t)}}function d(t,e,i){if(t instanceof HTMLInputElement){if("checkbox"===t.type)return t.checked;if("number"===t.type){if(""===t.value){if(e?.nullable)return null;const t=e?.editorParams;return t?.min??0}return Number(t.value)}if("date"===t.type)return t.value?"string"==typeof i?t.value:t.valueAsDate:e?.nullable?null:"string"==typeof i?i||/* @__PURE__ */(new Date).toISOString().slice(0,10):i??/* @__PURE__ */new Date;if("number"==typeof i){if(""===t.value){if(e?.nullable)return null;const t=e?.editorParams;return t?.min??0}return Number(t.value)}return""===t.value&&null==i?e?.nullable?null:"":"string"==typeof i&&t.value===i.replace(/[\n\r]/g,"")?i:t.value}return"number"===e?.type&&""!==t.value||"number"==typeof i&&""!==t.value?Number(t.value):null==i&&""===t.value?e?.nullable?null:"":t.value}class l{#e=/* @__PURE__ */new Map;#i;constructor(t){this.#i=t}setInvalid(t,e,i=""){let n=this.#e.get(t);n||(n=/* @__PURE__ */new Map,this.#e.set(t,n)),n.set(e,i),this.#i(t,e,!0)}clearInvalid(t,e){const i=this.#e.get(t);i&&(i.delete(e),0===i.size&&this.#e.delete(t)),this.#i(t,e,!1)}clearRowInvalid(t){const e=this.#e.get(t);if(e){const i=Array.from(e.keys());this.#e.delete(t),i.forEach(e=>this.#i(t,e,!1))}}clearAllInvalid(){const t=Array.from(this.#e.entries());this.#e.clear(),t.forEach(([t,e])=>{e.forEach((e,i)=>this.#i(t,i,!1))})}isCellInvalid(t,e){return this.#e.get(t)?.has(e)??!1}getInvalidMessage(t,e){return this.#e.get(t)?.get(e)}hasInvalidCells(t){const e=this.#e.get(t);return!!e&&e.size>0}getInvalidFields(t){return new Map(this.#e.get(t)??[])}}function a(t,e,i){const n=t.get(e);return!!n&&!c(n,i)}function c(t,e){if(t===e)return!0;if(null==t||null==e)return!1;if(typeof t!=typeof e)return!1;if(t instanceof Date&&e instanceof Date)return t.getTime()===e.getTime();if(Array.isArray(t)){if(!Array.isArray(e)||t.length!==e.length)return!1;for(let i=0;i<t.length;i++)if(!c(t[i],e[i]))return!1;return!0}if("object"==typeof t){const i=t,n=e,r=Object.keys(i),s=Object.keys(n);if(r.length!==s.length)return!1;for(const t of r)if(!c(i[t],n[t]))return!1;return!0}return!1}function u(t,e,i){t.set(e,structuredClone(i))}function h(t,e,i){const n=t.get(e);if(!n)return!1;const r=n,s=i;for(const o of Object.keys(r))s[o]=r[o];return!0}class g{baselines=/* @__PURE__ */new Map;baselinesWereCaptured=!1;newRowIds=/* @__PURE__ */new Set;changedRowIds=/* @__PURE__ */new Set;committedDirtyRowIds=/* @__PURE__ */new Set;clear(){this.changedRowIds.clear(),this.committedDirtyRowIds.clear(),this.baselines.clear(),this.newRowIds.clear(),this.baselinesWereCaptured=!1}capture(t,e){const i=this.baselines.size;!function(t,e,i){for(const n of e)try{const e=i(n);null==e||t.has(e)||t.set(e,structuredClone(n))}catch{}}(this.baselines,t,e),this.baselines.size>i&&(this.baselinesWereCaptured=!0)}drainCapturedFlag(){return this.baselinesWereCaptured?(this.baselinesWereCaptured=!1,this.baselines.size):null}isRowDirty(t,e){return a(this.baselines,t,e)}hasAnyDirty(t){if(this.newRowIds.size>0)return!0;for(const[e]of this.baselines){const i=t(e);if(i&&a(this.baselines,e,i))return!0}return!1}isCellDirty(t,e,i){return function(t,e,i,n){const r=t.get(e);return!!r&&!c(r[n],i[n])}(this.baselines,t,e,i)}getRowDirtyState(t,e){const i=this.newRowIds.has(t);return{isNew:i,isCommittedDirty:!i&&this.committedDirtyRowIds.has(t)&&a(this.baselines,t,e),hasBaseline:this.baselines.has(t)}}markPristine(t,e){u(this.baselines,t,e),this.newRowIds.delete(t),this.changedRowIds.delete(t),this.committedDirtyRowIds.delete(t)}markNew(t){this.newRowIds.add(t),this.committedDirtyRowIds.add(t)}markDirty(t){this.changedRowIds.add(t),this.committedDirtyRowIds.add(t)}markAllPristine(t){for(const[e]of this.baselines){const i=t(e);i&&u(this.baselines,e,i)}this.newRowIds.clear(),this.changedRowIds.clear(),this.committedDirtyRowIds.clear()}getOriginalRow(t){return function(t,e){const i=t.get(e);return i?structuredClone(i):void 0}(this.baselines,t)}hasBaseline(t){return this.baselines.has(t)}getDirtyRows(t){const e=[];for(const[i,n]of this.baselines){const r=t(i);r&&a(this.baselines,i,r)&&e.push({id:i,original:structuredClone(n),current:r})}for(const i of this.newRowIds){const n=t(i);n&&e.push({id:i,original:void 0,current:n})}return e}getDirtyRowIds(t){const e=[];for(const[i]of this.baselines){const n=t(i);n&&a(this.baselines,i,n)&&e.push(i)}for(const i of this.newRowIds)e.push(i);return e}revertRow(t,e){const i=h(this.baselines,t,e);return i&&(this.changedRowIds.delete(t),this.committedDirtyRowIds.delete(t)),i}revertAll(t){for(const[e]of this.baselines){const i=t(e);i&&h(this.baselines,e,i)}this.changedRowIds.clear(),this.committedDirtyRowIds.clear()}getChangedRows(t){const e=[];for(const i of this.changedRowIds){const n=t(i);n&&e.push(n)}return e}getChangedRowIds(){return Array.from(this.changedRowIds)}isRowChanged(t){return this.changedRowIds.has(t)}}const f='input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])';function w(t){return"string"==typeof t&&("__proto__"!==t&&"constructor"!==t&&"prototype"!==t)}function m(t){}function v(t,e){return!1===t.onBeforeEditClose?.(e)}function p(t,e,i,n,r,s,l){if(!n.editable)return;if(s.classList.contains("editing"))return;const{grid:a,isGridMode:c,config:u,editingCells:h,editorValueCallbacks:g}=t;let p;try{p=a.getRowId?.(e)}catch{}const y=p?t=>a.updateRow(p,t,"cascade"):m,E=w(n.field)?e[n.field]:void 0;s.classList.add("editing"),h.add(`${i}:${r}`);const R=s.parentElement;R&&function(t){const e=(t.__editingCellCount??0)+1;t.__editingCellCount=e,t.setAttribute("data-has-editing","")}(R);let b=!1;const C=r=>{if(b||!c&&!t.isEditSessionActive())return;const s=p?a._getRowEntry(p):void 0,o=s?.row??e,d=s?.index??i;t.commitCellValue(d,n,r,o)},I=()=>{if(b=!0,w(n.field)){const t=p?a._getRowEntry(p):void 0;(t?.row??e)[n.field]=E}},k=document.createElement("div");k.className="tbw-editor-host",s.innerHTML="",s.appendChild(k),k.addEventListener("keydown",e=>{if("Enter"===e.key){if(c){e.stopPropagation(),e.preventDefault();const t=k.querySelector("input,textarea,select");return void(t&&C(d(t,n,E)))}if(v(u,e))return;e.stopPropagation(),e.preventDefault(),b=!0,t.exitRowEdit(i,!1)}if("Escape"===e.key){if(c)return e.stopPropagation(),void e.preventDefault();if(v(u,e))return;e.stopPropagation(),e.preventDefault(),I(),t.exitRowEdit(i,!0)}});const _=n,S=_.__editorTemplate,x=function(t,e){if(e.editor)return e.editor;if(e.__editorTemplate)return"template";if(!e.type)return;const i=t.effectiveConfig?.typeDefaults;if(i?.[e.type]?.editor)return i[e.type].editor;const n=t.__frameworkAdapter;if(n?.getTypeDefault){const t=n.getTypeDefault(e.type);if(t?.editor)return t.editor}}(a,_)??o(n),M=E,A=`${i}:${n.field}`,L=[];g.set(A,t=>{for(const e of L)e(t)});const D=t=>{L.push(t)};if("template"===x&&S)!function(t,e,i,n,r,s,o,l,a){const c=i.__editorTemplate;if(!c)return;const u=c.cloneNode(!0),h=i.__compiledEditor;h?u.innerHTML=h({row:n,value:r,field:i.field,column:i,commit:s,cancel:o}):u.querySelectorAll("*").forEach(t=>{1===t.childNodes.length&&t.firstChild?.nodeType===Node.TEXT_NODE&&(t.textContent=t.textContent?.replace(/{{\s*value\s*}}/g,null==r?"":String(r)).replace(/{{\s*row\.([a-zA-Z0-9_]+)\s*}}/g,(t,e)=>{if(!w(e))return"";const i=n[e];return null==i?"":String(i)})||"")});const g=u.querySelector("input,textarea,select");if(g){g instanceof HTMLInputElement&&"checkbox"===g.type?g.checked=!!r:g.value=String(r??"");let e=!1;g.addEventListener("blur",()=>{e||s(d(g,i,r))}),g.addEventListener("keydown",n=>{const l=n;if("Enter"===l.key){if(v(t.config,l))return;l.stopPropagation(),l.preventDefault(),e=!0,s(d(g,i,r)),t.exitRowEdit(a,!1)}if("Escape"===l.key){if(v(t.config,l))return;l.stopPropagation(),l.preventDefault(),o(),t.exitRowEdit(a,!0)}}),g instanceof HTMLInputElement&&"checkbox"===g.type&&g.addEventListener("change",()=>s(g.checked)),l||setTimeout(()=>g.focus({preventScroll:!0}),0)}e.appendChild(u)}(t,k,_,e,E,C,I,l,i),D(t=>{const e=k.querySelector("input,textarea,select");e&&(e instanceof HTMLInputElement&&"checkbox"===e.type?e.checked=!!t:e.value=String(t??""))});else if("string"==typeof x){const t=document.createElement(x);t.value=M,t.addEventListener("change",()=>C(t.value)),D(e=>{t.value=e}),k.appendChild(t),l||queueMicrotask(()=>{const t=k.querySelector(f);t?.focus({preventScroll:!0})})}else if("function"==typeof x){const t=x({row:e,rowId:p??"",value:M,field:n.field,column:n,commit:C,cancel:I,updateRow:y,onValueChange:D});if("string"==typeof t)k.innerHTML=t,function(t,e,i,n){const r=t.querySelector("input,textarea,select");r&&(r.addEventListener("blur",()=>{i(d(r,e,n))}),r instanceof HTMLInputElement&&"checkbox"===r.type?r.addEventListener("change",()=>i(r.checked)):r instanceof HTMLSelectElement&&r.addEventListener("change",()=>i(d(r,e,n))))}(k,n,C,E),D(t=>{const e=k.querySelector("input,textarea,select");e&&(e instanceof HTMLInputElement&&"checkbox"===e.type?e.checked=!!t:e.value=String(t??""))});else if(t instanceof Node){k.appendChild(t);t instanceof HTMLInputElement||t instanceof HTMLSelectElement||t instanceof HTMLTextAreaElement?D(e=>{t instanceof HTMLInputElement&&"checkbox"===t.type?t.checked=!!e:t.value=String(e??"")}):s.setAttribute("data-editor-managed","")}else!t&&k.hasChildNodes()&&s.setAttribute("data-editor-managed","");l||queueMicrotask(()=>{const t=k.querySelector(f);t?.focus({preventScroll:!0})})}else if(x&&"object"==typeof x){const t=document.createElement("div");t.setAttribute("data-external-editor",""),t.setAttribute("data-field",n.field),k.appendChild(t),s.setAttribute("data-editor-managed","");const i={row:e,rowId:p??"",value:M,field:n.field,column:n,commit:C,cancel:I,updateRow:y,onValueChange:D};if(x.mount)try{x.mount({placeholder:t,context:i,spec:x})}catch(T){console.warn(`[tbw-grid] External editor mount error for column '${n.field}':`,T)}else a.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:t,spec:x,context:i}}))}}class y extends n{static manifest={ownedProperties:[{property:"editable",level:"column",description:'the "editable" column property',isUsed:t=>!0===t},{property:"editor",level:"column",description:'the "editor" column property'},{property:"editorParams",level:"column",description:'the "editorParams" column property'},{property:"nullable",level:"column",description:'the "nullable" column property (allows null values)'}],events:[{type:"cell-edit-committed",description:"Emitted when a cell edit is committed (for plugin-to-plugin coordination)"}],queries:[{type:"isEditing",description:"Returns whether any cell is currently being edited"}]};name="editing";styles="@layer tbw-plugins{tbw-grid{--tbw-editing-bg: var(--tbw-color-selection);--tbw-editing-row-bg: var(--tbw-editing-bg);--tbw-editing-border: var(--tbw-border-input, 1px solid var(--tbw-color-border-strong));--tbw-padding-editing-input: var(--tbw-cell-padding-input, 2px 6px);--tbw-font-size-editor: inherit;--tbw-editing-row-outline-color: var(--tbw-color-accent);--tbw-editing-row-outline-width: 1px;--tbw-invalid-bg: light-dark(#fef2f2, #450a0a);--tbw-invalid-border-color: light-dark(#ef4444, #f87171)}tbw-grid:not(.tbw-grid-mode) .data-grid-row:has(.editing){background:var(--tbw-editing-row-bg);outline:var(--tbw-editing-row-outline-width) solid var(--tbw-editing-row-outline-color);outline-offset:calc(-1 * var(--tbw-editing-row-outline-width))}tbw-grid .data-grid-row>.cell.editing{overflow:hidden;padding:0;display:flex;min-height:calc(var(--tbw-row-height) + 2px);align-items:center;justify-content:center}tbw-grid .data-grid-row>.cell.editing input:not([type=checkbox]),tbw-grid .data-grid-row>.cell.editing select,tbw-grid .data-grid-row>.cell.editing textarea{width:100%;height:100%;flex:1 1 auto;min-width:0;border:var(--tbw-editing-border);padding:var(--tbw-padding-editing-input);font-size:var(--tbw-font-size-editor)}tbw-grid .tbw-editor-host{display:contents}tbw-grid .data-grid-row>.cell[data-invalid=true]{background:var(--tbw-invalid-bg);outline:1px solid var(--tbw-invalid-border-color);outline-offset:-1px}}";get defaultConfig(){return{mode:"row",editOn:"click"}}get#n(){return"grid"===this.config.mode}#r=-1;#s;#o;#d=-1;#l=/* @__PURE__ */new Map;#a=/* @__PURE__ */new Set;#c=/* @__PURE__ */new Map;#u=!1;#h=-1;#g;#f=!1;#w=!1;#m=!1;#v=null;#p=new g;#y;attach(t){super.attach(t);const e=this.disconnectSignal,i=t;if(this.#g=new l((t,e,i)=>{this.#E(t,e,i)}),this.#y={grid:i,isGridMode:this.#n,config:this.config,editingCells:this.#a,editorValueCallbacks:this.#c,isEditSessionActive:()=>-1!==this.#r,commitCellValue:(t,e,i,n)=>this.#R(t,e,i,n),exitRowEdit:(t,e)=>this.#b(t,e)},i._activeEditRows=-1,i._rowEditSnapshots=/* @__PURE__ */new Map,Object.defineProperty(t,"changedRows",{get:()=>this.changedRows,configurable:!0}),Object.defineProperty(t,"changedRowIds",{get:()=>this.changedRowIds,configurable:!0}),t.resetChangedRows=t=>this.resetChangedRows(t),t.beginBulkEdit=(t,e)=>{e&&this.beginCellEdit(t,e)},document.addEventListener("keydown",t=>{if(!this.#n&&"Escape"===t.key&&-1!==this.#r){if(v(this.config,t))return;this.#b(this.#r,!0)}},{capture:!0,signal:e}),document.addEventListener("mousedown",t=>{if(this.#n)return;if(-1===this.#r)return;const e=i.findRenderedRowElement?.(this.#r);if(!e)return;if((t.composedPath&&t.composedPath()||[]).includes(e))return;const n=t.target;n&&!this.gridElement.contains(n)&&this.grid.containsFocus?.(n)||v(this.config,t)||queueMicrotask(()=>{-1!==this.#r&&this.#b(this.#r,!1)})},{signal:e}),this.config.focusTrap&&this.gridElement.addEventListener("focusout",t=>{if(this.#n)return;if(-1===this.#r)return;const e=t.relatedTarget;e&&this.grid.containsFocus?.(e)||e&&this.gridElement.contains(e)||queueMicrotask(()=>{-1!==this.#r&&this.#C()})},{signal:e}),this.gridElement.addEventListener("cell-change",t=>{const e=t.detail;if("user"===e.source)return;const i=`${e.rowIndex}:${e.field}`,n=this.#c.get(i);n&&n(e.newValue)},{signal:e}),this.config.dirtyTracking){const t=t=>{const e=t.detail,i=e?.action;if(!i)return;const n=this.rows[i.rowIndex];if(!n)return;const r=this.grid.getRowId(n);if(!r)return;const s=this.#p.isRowDirty(r,n);this.emit("dirty-change",{rowId:r,row:n,original:this.#p.getOriginalRow(r),type:s?"modified":"pristine"})};this.gridElement.addEventListener("undo",t,{signal:e}),this.gridElement.addEventListener("redo",t,{signal:e}),this.on("row-inserted",t=>{const e=this.grid.getRowId(t.row);null!=e&&this.markAsNew(String(e))})}this.#n&&(i._isGridEditMode=!0,this.gridElement.classList.add("tbw-grid-mode"),this.requestRender(),this.gridElement.addEventListener("focusin",t=>{const e=t.target;if(e!==this.gridElement&&e.matches(f)){if(this.#w)return e.blur(),void this.gridElement.focus();const t=i._focusRow,n=i._focusCol,r=this.#v;if(!r||r.rowIndex!==t||r.colIndex!==n){const e=i._visibleColumns?.[n],r=i._rows?.[t];if(e?.field&&r){const i=e.field;this.#v={rowIndex:t,colIndex:n,field:i,value:r[i]}}}this.#f=!0}},{signal:e}),this.gridElement.addEventListener("focusout",t=>{const e=t.relatedTarget;e&&(this.gridElement.contains(e)||this.grid.containsFocus?.(e))&&e.matches(f)||(this.#f=!1,this.#v=null)},{signal:e}),this.gridElement.addEventListener("keydown",t=>{if("Escape"===t.key&&this.#f){if(v(this.config,t))return void queueMicrotask(()=>{if(this.#f){this.#I();const t=document.activeElement;t&&this.gridElement.contains(t)&&(t.blur(),this.gridElement.focus()),this.#f=!1,this.#w=!0}});this.#I();const e=document.activeElement;e&&this.gridElement.contains(e)&&(e.blur(),this.gridElement.focus()),this.#f=!1,this.#w=!0,t.preventDefault(),t.stopPropagation()}},{capture:!0,signal:e}),this.gridElement.addEventListener("mousedown",t=>{t.target.matches(f)&&(this.#w=!1)},{signal:e}))}detach(){this.gridElement._isGridEditMode=!1,this.gridElement.classList.remove("tbw-grid-mode"),this.#r=-1,this.#s=void 0,this.#o=void 0,this.#d=-1,this.#l.clear(),this.#p.clear(),this.#a.clear(),this.#c.clear(),this.#f=!1,this.#w=!1,this.#v=null,this.#m=!1,super.detach()}handleQuery(t){if("isEditing"===t.type)return this.#n||-1!==this.#r}onCellClick(t){if(this.#n)return!1;const e=this.grid,i=this.config.editOn??e.effectiveConfig?.editOn;if(!1===i||"manual"===i)return!1;if("click"!==i&&"dblclick"!==i)return!1;const n="dblclick"===t.originalEvent.type;if("click"===i&&n)return!1;if("dblclick"===i&&!n)return!1;const{rowIndex:r}=t,s=e._columns?.some(t=>t.editable);return!!s&&(t.originalEvent.stopPropagation(),this.beginBulkEdit(r),!0)}onKeyDown(e){const i=this.grid;if("Escape"===e.key){if(this.#n&&this.#f){this.#I();const t=document.activeElement;return t&&this.gridElement.contains(t)&&(t.blur(),this.gridElement.focus()),this.#f=!1,this.#w=!0,this.requestAfterRender(),!0}if(-1!==this.#r&&!this.#n)return v(this.config,e)||this.#b(this.#r,!0),!0}if(this.#n&&!this.#f&&("ArrowUp"===e.key||"ArrowDown"===e.key||"ArrowLeft"===e.key||"ArrowRight"===e.key))return!1;if(this.#n&&this.#f&&("ArrowUp"===e.key||"ArrowDown"===e.key))return!0;if(("ArrowUp"===e.key||"ArrowDown"===e.key)&&-1!==this.#r&&!this.#n){if(v(this.config,e))return!0;const n=i._rows.length-1,r=this.#r;return this.#b(r,!1),"ArrowDown"===e.key?i._focusRow=Math.min(n,i._focusRow+1):i._focusRow=Math.max(0,i._focusRow-1),e.preventDefault(),t(i),this.requestAfterRender(),!0}if("Tab"===e.key&&(-1!==this.#r||this.#n)){if(e.preventDefault(),this.#m)return this.#b(this.#r,!1),!0;const t=!e.shiftKey;return this.#k(t),!0}if(" "===e.key||"Spacebar"===e.key){if(-1!==this.#r)return!1;const t=i._focusRow,n=i._focusCol;if(t>=0&&n>=0){const r=i._visibleColumns[n],s=i._rows[t];if(r?.editable&&"boolean"===r.type&&s){const i=r.field;if(w(i)){const n=!s[i];return this.#R(t,r,n,s),e.preventDefault(),this.requestRender(),!0}}}return!1}if(!("Enter"!==e.key||e.shiftKey||e.ctrlKey||e.altKey||e.metaKey)){if(this.#n&&!this.#f)return this.#C(),!0;if(-1!==this.#r)return!!v(this.config,e);const t=this.config.editOn??i.effectiveConfig?.editOn;if(!1===t||"manual"===t)return!1;const n=i._focusRow,r=i._focusCol;if(n>=0){const t=i._columns?.some(t=>t.editable);if(t){const t=i._visibleColumns[r],s=i._rows[n],o=t?.field??"",d=o&&s?s[o]:void 0,l=this.gridElement.querySelector(`[data-row="${n}"][data-col="${r}"]`),a=new CustomEvent("cell-activate",{cancelable:!0,bubbles:!0,detail:{rowIndex:n,colIndex:r,field:o,value:d,row:s,cellEl:l,trigger:"keyboard",originalEvent:e}});this.gridElement.dispatchEvent(a);const c=new CustomEvent("activate-cell",{cancelable:!0,bubbles:!0,detail:{row:n,col:r}});return this.gridElement.dispatchEvent(c),a.defaultPrevented||c.defaultPrevented?(e.preventDefault(),!0):(this.beginBulkEdit(n),!0)}}return!1}if("F2"===e.key){if(-1!==this.#r||this.#n)return!1;if(!1===(this.config.editOn??i.effectiveConfig?.editOn))return!1;const t=i._focusRow,n=i._focusCol;if(t>=0&&n>=0){const r=i._visibleColumns[n];if(r?.editable&&r.field)return e.preventDefault(),this.beginCellEdit(t,r.field),!0}return!1}return!1}processColumns(t){const e=this.grid,i=e.effectiveConfig?.typeDefaults,n=e.__frameworkAdapter;return i||n?.getTypeDefault?t.map(t=>{if(!t.type)return t;let e;if(i?.[t.type]?.editorParams&&(e=i[t.type].editorParams),!e&&n?.getTypeDefault){const i=n.getTypeDefault(t.type);i?.editorParams&&(e=i.editorParams)}return e?{...t,editorParams:{...e,...t.editorParams}}:t}):t}processRows(t){const e=this.grid;if(this.config.dirtyTracking&&e.getRowId&&this.#p.capture(t,t=>{try{return e.getRowId?.(t)}catch{return}}),-1===this.#r||this.#n)return t;const i=this.#s,n=this.#o;if(!i||!n)return t;const r=[...t];let s=-1;for(let o=0;o<r.length;o++)try{if(e.getRowId?.(r[o])===i){s=o;break}}catch{}return-1===s?(setTimeout(()=>this.cancelActiveRowEdit(),0),r):(r[s]=n,this.#r!==s&&this.#_(this.#r,s),r)}afterRender(){const t=this.grid;if(-1!==this.#r&&this.#o&&!this.#n&&t._rows[this.#r]!==this.#o){const e=t._rows.indexOf(this.#o);if(-1===e)return void setTimeout(()=>this.cancelActiveRowEdit(),0);this.#_(this.#r,e)}if(this.#u&&(this.#u=!1,this.#S(t)),-1!==this.#h){const e=this.#h;this.#h=-1,t.animateRow?.(e,"change")}const e=this.#p.drainCapturedFlag();if(null!=e&&this.emit("baselines-captured",{count:e}),!this.#n&&0!==this.#a.size)for(const i of this.#a){const[e,n]=i.split(":"),r=parseInt(e,10),s=parseInt(n,10),o=t.findRenderedRowElement?.(r);if(!o)continue;const d=o.querySelector(`.cell[data-col="${s}"]`);if(!d||d.classList.contains("editing"))continue;const l=t._rows[r],a=t._visibleColumns[s];l&&a&&this.#x(l,r,a,s,d,!0)}}afterCellRender(t){if(!this.#n)return;const{row:e,rowIndex:i,column:n,colIndex:r,cellElement:s}=t;n.editable&&(s.classList.contains("editing")||this.#x(e,i,n,r,s,!0))}afterRowRender(t){if(!this.config.dirtyTracking)return;const e=this.gridElement,i=e.getRowId?.(t.row);if(!i)return;const{isNew:n,isCommittedDirty:r,hasBaseline:s}=this.#p.getRowDirtyState(i,t.row),o=t.rowElement;if(o.classList.toggle("tbw-row-dirty",r),o.classList.toggle("tbw-row-new",n),s){const e=o.querySelectorAll(".cell[data-field]");for(let n=0;n<e.length;n++){const r=e[n],s=r.getAttribute("data-field");s&&r.classList.toggle("tbw-cell-dirty",this.#p.isCellDirty(i,t.row,s))}}else{const t=o.querySelectorAll(".tbw-cell-dirty");for(let e=0;e<t.length;e++)t[e].classList.remove("tbw-cell-dirty")}}onScrollRender(){this.afterRender()}get changedRows(){return this.#p.getChangedRows(t=>this.grid.getRow(t))}get changedRowIds(){return this.#p.getChangedRowIds()}get activeEditRow(){return this.#r}get activeEditCol(){return this.#d}isRowEditing(t){return this.#r===t}isCellEditing(t,e){return this.#a.has(`${t}:${e}`)}isRowChanged(t){const e=this.grid,i=e._rows[t];if(!i)return!1;try{const t=e.getRowId?.(i);return!!t&&this.#p.isRowChanged(t)}catch{return!1}}isRowChangedById(t){return this.#p.isRowChanged(t)}isDirty(t){if(!this.config.dirtyTracking)return!1;if(this.#p.newRowIds.has(t))return!0;const e=this.grid.getRow(t);return!!e&&this.#p.isRowDirty(t,e)}isPristine(t){return!this.isDirty(t)}get dirty(){if(!this.config.dirtyTracking)return!1;const t=this.grid;return this.#p.hasAnyDirty(e=>t._getRowEntry(e)?.row)}get pristine(){return!this.dirty}markAsPristine(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&(this.#p.markPristine(t,e),this.emit("dirty-change",{rowId:t,row:e,original:e,type:"pristine"}))}markAsNew(t){if(!this.config.dirtyTracking)return;this.#p.markNew(t);const e=this.grid.getRow(t);this.emit("dirty-change",{rowId:t,row:e,original:void 0,type:"new"})}markAsDirty(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&(this.#p.markDirty(t),this.emit("dirty-change",{rowId:t,row:e,original:this.#p.getOriginalRow(t),type:"modified"}))}markAllPristine(){if(!this.config.dirtyTracking)return;const t=this.grid;this.#p.markAllPristine(e=>t._getRowEntry(e)?.row)}getOriginalRow(t){if(this.config.dirtyTracking)return this.#p.getOriginalRow(t)}hasBaseline(t){return!!this.config.dirtyTracking&&this.#p.hasBaseline(t)}getDirtyRows(){if(!this.config.dirtyTracking)return[];const t=this.grid;return this.#p.getDirtyRows(e=>t._getRowEntry(e)?.row)}get dirtyRowIds(){if(!this.config.dirtyTracking)return[];const t=this.grid;return this.#p.getDirtyRowIds(e=>t._getRowEntry(e)?.row)}revertRow(t){if(!this.config.dirtyTracking)return;const e=this.grid.getRow(t);e&&this.#p.revertRow(t,e)&&(this.emit("dirty-change",{rowId:t,row:e,original:this.#p.getOriginalRow(t),type:"reverted"}),this.requestRender())}revertAll(){if(!this.config.dirtyTracking)return;const t=this.grid;this.#p.revertAll(e=>t._getRowEntry(e)?.row),this.requestRender()}setInvalid(t,e,i=""){this.#g.setInvalid(t,e,i)}clearInvalid(t,e){this.#g.clearInvalid(t,e)}clearRowInvalid(t){this.#g.clearRowInvalid(t)}clearAllInvalid(){this.#g.clearAllInvalid()}isCellInvalid(t,e){return this.#g.isCellInvalid(t,e)}getInvalidMessage(t,e){return this.#g.getInvalidMessage(t,e)}hasInvalidCells(t){return this.#g.hasInvalidCells(t)}getInvalidFields(t){return this.#g.getInvalidFields(t)}resetChangedRows(t){const e=this.changedRows,i=this.changedRowIds;this.#p.changedRowIds.clear(),this.#p.committedDirtyRowIds.clear(),this.#M(),t||this.emit("changed-rows-reset",{rows:e,ids:i});const n=this.grid;n._rowPool?.forEach(t=>t.classList.remove("changed"))}beginCellEdit(t,e){const i=this.grid,n=i._visibleColumns.findIndex(t=>t.field===e);if(-1===n)return;const r=i._visibleColumns[n];if(!r?.editable)return;const s=i.findRenderedRowElement?.(t),o=s?.querySelector(`.cell[data-col="${n}"]`);o&&(this.#m=!0,this.#A(t,n,o))}beginBulkEdit(t){const e=this.grid;if(!1===(this.config.editOn??e.effectiveConfig?.editOn))return;const i=e._columns?.some(t=>t.editable);if(!i)return;const n=e.findRenderedRowElement?.(t);if(!n)return;this.#m=!1;const r=e._rows[t];this.#L(t,r),Array.from(n.children).forEach((i,n)=>{const s=e._visibleColumns[n];if(s?.editable){const e=i;e.classList.contains("editing")||this.#x(r,t,s,n,e,!0)}}),setTimeout(()=>{let t=n.querySelector(`.cell[data-col="${e._focusCol}"]`);if(t?.classList.contains("editing")||(t=n.querySelector(".cell.editing")),t?.classList.contains("editing")){const e=t.querySelector(f);try{e?.focus({preventScroll:!0})}catch{}}},0)}commitActiveRowEdit(){-1!==this.#r&&this.#b(this.#r,!1)}cancelActiveRowEdit(){-1!==this.#r&&this.#b(this.#r,!0)}#E(t,e,i){const n=this.grid,r=n._visibleColumns?.findIndex(t=>t.field===e);if(-1===r||void 0===r)return;const s=n._rows,o=s?.findIndex(e=>{try{return n.getRowId?.(e)===t}catch{return!1}});if(-1===o||void 0===o)return;const d=n.findRenderedRowElement?.(o),l=d?.querySelector(`.cell[data-col="${r}"]`);if(l)if(i){l.setAttribute("data-invalid","true");const i=this.#g.getInvalidMessage(t,e);i&&l.setAttribute("title",i)}else l.removeAttribute("data-invalid"),l.removeAttribute("title")}#_(t,e){this.#r=e;const i=/* @__PURE__ */new Set,n=`${t}:`;for(const o of this.#a)o.startsWith(n)?i.add(`${e}:${o.substring(n.length)}`):i.add(o);this.#a.clear();for(const o of i)this.#a.add(o);const r=this.#l.get(t);void 0!==r&&(this.#l.delete(t),this.#l.set(e,r));const s=[];for(const[o,d]of this.#c)o.startsWith(n)&&(s.push([`${e}:${o.substring(n.length)}`,d]),this.#c.delete(o));for(const[o,d]of s)this.#c.set(o,d);this.#M()}#A(t,e,i){const n=this.grid,r=n._rows[t],s=n._visibleColumns[e];r&&s?.editable&&(i.classList.contains("editing")||(this.#r!==t&&this.#L(t,r),this.#d=e,this.#x(r,t,s,e,i,!1)))}#I(){const t=this.#v;if(!t)return;const e=this.grid,i=e._rows?.[t.rowIndex];i&&(i[t.field]=t.value);const n=`${t.rowIndex}:${t.field}`,r=this.#c.get(n);r&&r(t.value),this.emit("cell-cancel",{rowIndex:t.rowIndex,colIndex:t.colIndex,field:t.field,previousValue:t.value}),this.#v=null}#C(){const t=this.grid,e=t._focusRow,i=t._focusCol;if(e<0||i<0)return;const n=t.findRenderedRowElement?.(e),r=n?.querySelector(`.cell[data-col="${i}"]`);if(r?.classList.contains("editing")){const t=r.querySelector(f);t&&(this.#w=!1,t.focus(),this.#f=!0,t instanceof HTMLInputElement&&("text"===t.type||"number"===t.type)&&t.select())}}#k(e){const i=this.grid,n=i._rows,r=this.#n?i._focusRow:this.#r,s=i._visibleColumns.map((t,e)=>t.editable?e:-1).filter(t=>t>=0);if(0===s.length)return;const o=s.indexOf(i._focusCol)+(e?1:-1);if(o>=0&&o<s.length){i._focusCol=s[o];const e=i.findRenderedRowElement?.(r),n=e?.querySelector(`.cell[data-col="${s[o]}"]`);if(n?.classList.contains("editing")){const t=n.querySelector(f);t?.focus({preventScroll:!0})}return void t(i,{forceHorizontalScroll:!0})}const d=r+(e?1:-1);d>=0&&d<n.length&&(this.#n?(i._focusRow=d,i._focusCol=e?s[0]:s[s.length-1],t(i,{forceHorizontalScroll:!0}),this.requestAfterRender(),setTimeout(()=>{const t=i.findRenderedRowElement?.(d),e=t?.querySelector(`.cell[data-col="${i._focusCol}"]`);if(e?.classList.contains("editing")){const t=e.querySelector(f);t?.focus({preventScroll:!0})}},0)):(this.#b(r,!1),i._focusRow=d,i._focusCol=e?s[0]:s[s.length-1],this.beginBulkEdit(d),t(i,{forceHorizontalScroll:!0})))}#M(){const t=this.grid;t._activeEditRows=this.#r,t._rowEditSnapshots=this.#l}#L(t,e){if(this.#r!==t){-1!==this.#r&&this.#b(this.#r,!1),this.#l.set(t,{...e}),this.#r=t,this.#o=e;const i=this.grid;try{this.#s=i.getRowId?.(e)??void 0}catch{this.#s=void 0}this.#M(),this.#n||this.emit("edit-open",{rowIndex:t,rowId:this.#s??"",row:e})}}#b(t,e){if(this.#r!==t)return;const i=this.grid,n=this.#l.get(t),r=i.findRenderedRowElement?.(t);let s=this.#s;const o=s?i._getRowEntry(s):void 0,l=o?.row??this.#o??i._rows[t];if(!s&&l)try{s=i.getRowId?.(l)}catch{}if(!e&&r&&l){r.querySelectorAll(".cell.editing").forEach(e=>{const n=Number(e.getAttribute("data-col"));if(isNaN(n))return;const r=i._visibleColumns[n];if(!r)return;if(e.hasAttribute("data-editor-managed"))return;const s=e.querySelector("input,textarea,select");if(s){const e=r.field,i=l[e],n=d(s,r,i);i!==n&&this.#R(t,r,n,l)}})}if(e||this.#n||!l||this.emit("before-edit-close",{rowIndex:t,rowId:s??"",row:l}),e&&n&&l)Object.keys(n).forEach(t=>{l[t]=n[t]}),s&&(this.#p.changedRowIds.delete(s),this.#p.committedDirtyRowIds.delete(s),this.clearRowInvalid(s));else if(!e&&l){const e=function(t,e){if(!t)return!1;const i=t,n=e,r=/* @__PURE__ */new Set([...Object.keys(i),...Object.keys(n)]);for(const s of r)if(i[s]!==n[s])return!0;return!1}(n,l),i=s?this.#p.changedRowIds.has(s):e,r=this.emitCancelable("row-commit",{rowIndex:t,rowId:s??"",row:l,oldValue:n,newValue:l,changed:i,changedRows:this.changedRows,changedRowIds:this.changedRowIds});r&&n?(Object.keys(n).forEach(t=>{l[t]=n[t]}),s&&(this.#p.changedRowIds.delete(s),this.#p.committedDirtyRowIds.delete(s),this.clearRowInvalid(s))):r||(s&&this.config.dirtyTracking&&(this.#p.isRowDirty(s,l)?this.#p.committedDirtyRowIds.add(s):this.#p.committedDirtyRowIds.delete(s)),e&&this.isAnimationEnabled&&(this.#h=t))}this.#l.delete(t),this.#r=-1,this.#s=void 0,this.#o=void 0,this.#d=-1,this.#m=!1,this.#M();for(const d of this.#a)d.startsWith(`${t}:`)&&this.#a.delete(d);for(const d of this.#c.keys())d.startsWith(`${t}:`)&&this.#c.delete(d);this.#u=!0,r?(r.querySelectorAll(".cell.editing").forEach(t=>{t.classList.remove("editing"),function(t){t.__editingCellCount=0,t.removeAttribute("data-has-editing")}(t.parentElement)}),i.refreshVirtualWindow(!0)):(this.#S(i),this.#u=!1),!this.#n&&l&&this.emit("edit-close",{rowIndex:t,rowId:s??"",row:l,reverted:e})}#R(t,e,i,n){const r=e.field;if(!w(r))return;const s=n[r];if(s===i)return;const o=this.grid;let d;try{d=this.grid.getRowId(n)}catch{}const l=!d||!this.#p.changedRowIds.has(d),a=d?t=>this.grid.updateRow(d,t,"cascade"):m;let c=!1;const u=d?t=>{c=!0,this.setInvalid(d,r,t??"")}:()=>{};if(this.emitCancelable("cell-commit",{row:n,rowId:d??"",field:r,oldValue:s,value:i,rowIndex:t,changedRows:this.changedRows,changedRowIds:this.changedRowIds,firstTimeForRow:l,updateRow:a,setInvalid:u}))return;if(d&&!c&&this.isCellInvalid(d,r)&&this.clearInvalid(d,r),n[r]=i,d&&this.#p.changedRowIds.add(d),this.#M(),this.config.dirtyTracking&&d){const t=this.#p.isRowDirty(d,n);this.emit("dirty-change",{rowId:d,row:n,original:this.#p.getOriginalRow(d),type:t?"modified":"pristine"})}this.emitPluginEvent("cell-edit-committed",{rowIndex:t,field:r,oldValue:s,newValue:i});const h=o.findRenderedRowElement?.(t);h&&h.classList.add("changed")}#x(t,e,i,n,r,s){p(this.#y,t,e,i,n,r,s)}#S(t){queueMicrotask(()=>{try{const e=t._focusRow,i=t._focusCol,n=t.findRenderedRowElement?.(e);if(n){Array.from(t._bodyEl.querySelectorAll(".cell-focus")).forEach(t=>t.classList.remove("cell-focus"));const r=n.querySelector(`.cell[data-row="${e}"][data-col="${i}"]`);r&&(r.classList.add("cell-focus"),r.setAttribute("aria-selected","true"),r.hasAttribute("tabindex")||r.setAttribute("tabindex","-1"),r.focus({preventScroll:!0}))}}catch{}})}}export{y as EditingPlugin,o as defaultEditorFor};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|