@toolbox-web/grid 1.22.1 → 1.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +20 -10
- 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/grid.d.ts +88 -1
- package/lib/core/grid.d.ts.map +1 -1
- package/lib/core/types.d.ts +61 -0
- package/lib/core/types.d.ts.map +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 +132 -1
- package/lib/plugins/editing/EditingPlugin.d.ts.map +1 -1
- package/lib/plugins/editing/editors.d.ts.map +1 -1
- package/lib/plugins/editing/index.d.ts +1 -0
- 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/dirty-tracking.d.ts +90 -0
- package/lib/plugins/editing/internal/dirty-tracking.d.ts.map +1 -0
- package/lib/plugins/editing/types.d.ts +82 -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 +17 -4
- package/lib/plugins/filtering/FilteringPlugin.d.ts.map +1 -1
- package/lib/plugins/filtering/index.js +1 -1
- package/lib/plugins/filtering/index.js.map +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.map +1 -1
- package/lib/plugins/responsive/index.js.map +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/UndoRedoPlugin.d.ts +52 -7
- package/lib/plugins/undo-redo/UndoRedoPlugin.d.ts.map +1 -1
- package/lib/plugins/undo-redo/history.d.ts +11 -4
- package/lib/plugins/undo-redo/history.d.ts.map +1 -1
- package/lib/plugins/undo-redo/index.d.ts +1 -1
- package/lib/plugins/undo-redo/index.d.ts.map +1 -1
- package/lib/plugins/undo-redo/index.js +1 -1
- package/lib/plugins/undo-redo/index.js.map +1 -1
- package/lib/plugins/undo-redo/types.d.ts +20 -3
- package/lib/plugins/undo-redo/types.d.ts.map +1 -1
- package/lib/plugins/visibility/index.js.map +1 -1
- package/package.json +1 -1
- package/public.d.ts +1 -1
- package/public.d.ts.map +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/undo-redo.umd.js +1 -1
- package/umd/plugins/undo-redo.umd.js.map +1 -1
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { AfterCellRenderContext, PluginManifest, PluginQuery, BaseGridPlugin, CellClickEvent, GridElement } from '../../core/plugin/base-plugin';
|
|
1
|
+
import { AfterCellRenderContext, AfterRowRenderContext, PluginManifest, PluginQuery, BaseGridPlugin, CellClickEvent, GridElement } from '../../core/plugin/base-plugin';
|
|
2
2
|
import { ColumnConfig, RowElementInternal } from '../../core/types';
|
|
3
|
+
import { DirtyRowEntry } from './internal/dirty-tracking';
|
|
3
4
|
import { EditingConfig } from './types';
|
|
4
5
|
/**
|
|
5
6
|
* Check if a row element has any cells in editing mode.
|
|
@@ -130,6 +131,23 @@ export declare class EditingPlugin<T = unknown> extends BaseGridPlugin<EditingCo
|
|
|
130
131
|
* @internal
|
|
131
132
|
*/
|
|
132
133
|
processColumns(columns: ColumnConfig<T>[]): ColumnConfig<T>[];
|
|
134
|
+
/**
|
|
135
|
+
* Stabilize the actively edited row across `rows` array replacements and
|
|
136
|
+
* capture dirty tracking baselines.
|
|
137
|
+
*
|
|
138
|
+
* **Editing stability:** When the consumer reassigns `grid.rows` while
|
|
139
|
+
* editing, the full pipeline (sort, filter, group) runs on the new data.
|
|
140
|
+
* This hook finds the edited row in the new array by ID and swaps in the
|
|
141
|
+
* in-progress row reference (`#activeEditRowRef`) so editors survive.
|
|
142
|
+
*
|
|
143
|
+
* **Dirty tracking baselines:** When `dirtyTracking` is enabled, captures
|
|
144
|
+
* a `structuredClone` snapshot of each row on first appearance
|
|
145
|
+
* (first-write-wins). This prevents Angular's feedback loop from
|
|
146
|
+
* overwriting baselines.
|
|
147
|
+
*
|
|
148
|
+
* @internal Plugin API — part of the render pipeline
|
|
149
|
+
*/
|
|
150
|
+
processRows(rows: readonly T[]): T[];
|
|
133
151
|
/**
|
|
134
152
|
* After render, reapply editors to cells in edit mode.
|
|
135
153
|
* This handles virtualization - when a row scrolls back into view,
|
|
@@ -143,6 +161,20 @@ export declare class EditingPlugin<T = unknown> extends BaseGridPlugin<EditingCo
|
|
|
143
161
|
* @internal
|
|
144
162
|
*/
|
|
145
163
|
afterCellRender(context: AfterCellRenderContext): void;
|
|
164
|
+
/**
|
|
165
|
+
* Apply dirty-tracking CSS classes to each rendered row.
|
|
166
|
+
*
|
|
167
|
+
* - `tbw-cell-dirty` on individual cells whose value differs from baseline
|
|
168
|
+
* (applied on cell-commit, visible during editing)
|
|
169
|
+
* - `tbw-row-dirty` on the row element only after the row edit session is
|
|
170
|
+
* committed (edit-close without cancel)
|
|
171
|
+
* - `tbw-row-new` when a row was inserted via `insertRow()` with no baseline
|
|
172
|
+
*
|
|
173
|
+
* Only active when `dirtyTracking: true`.
|
|
174
|
+
*
|
|
175
|
+
* @internal Plugin API
|
|
176
|
+
*/
|
|
177
|
+
afterRowRender(context: AfterRowRenderContext): void;
|
|
146
178
|
/**
|
|
147
179
|
* On scroll render, reapply editors to recycled cells.
|
|
148
180
|
* @internal
|
|
@@ -183,6 +215,105 @@ export declare class EditingPlugin<T = unknown> extends BaseGridPlugin<EditingCo
|
|
|
183
215
|
* @param rowId - Row ID to check
|
|
184
216
|
*/
|
|
185
217
|
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
|
+
*/
|
|
225
|
+
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
|
+
*/
|
|
232
|
+
isPristine(rowId: string): boolean;
|
|
233
|
+
/**
|
|
234
|
+
* Whether any row in the grid is dirty.
|
|
235
|
+
* Requires `dirtyTracking: true` in plugin config.
|
|
236
|
+
*/
|
|
237
|
+
get dirty(): boolean;
|
|
238
|
+
/**
|
|
239
|
+
* Whether all rows in the grid are pristine (not dirty).
|
|
240
|
+
* Requires `dirtyTracking: true` in plugin config.
|
|
241
|
+
*/
|
|
242
|
+
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
|
+
*/
|
|
249
|
+
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
|
+
*/
|
|
262
|
+
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
|
+
*/
|
|
269
|
+
markAsDirty(rowId: string): void;
|
|
270
|
+
/**
|
|
271
|
+
* Mark all tracked rows as pristine. Call after a successful batch save.
|
|
272
|
+
*/
|
|
273
|
+
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
|
+
*/
|
|
286
|
+
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
|
+
*/
|
|
297
|
+
hasBaseline(rowId: string): boolean;
|
|
298
|
+
/**
|
|
299
|
+
* Get all dirty rows with their original and current data.
|
|
300
|
+
*/
|
|
301
|
+
getDirtyRows(): DirtyRowEntry<T>[];
|
|
302
|
+
/**
|
|
303
|
+
* Get IDs of all dirty rows.
|
|
304
|
+
*/
|
|
305
|
+
get dirtyRowIds(): string[];
|
|
306
|
+
/**
|
|
307
|
+
* Revert a row to its baseline values (mutates the current row in-place).
|
|
308
|
+
* Triggers a re-render.
|
|
309
|
+
*
|
|
310
|
+
* @param rowId - Row ID (from `getRowId`)
|
|
311
|
+
*/
|
|
312
|
+
revertRow(rowId: string): void;
|
|
313
|
+
/**
|
|
314
|
+
* Revert all dirty rows to their baseline values and re-render.
|
|
315
|
+
*/
|
|
316
|
+
revertAll(): void;
|
|
186
317
|
/**
|
|
187
318
|
* Mark a cell as invalid with an optional validation message.
|
|
188
319
|
* Invalid cells are marked with a `data-invalid` attribute for styling.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditingPlugin.d.ts","sourceRoot":"","sources":["../../../../../../libs/grid/src/lib/plugins/editing/EditingPlugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"EditingPlugin.d.ts","sourceRoot":"","sources":["../../../../../../libs/grid/src/lib/plugins/editing/EditingPlugin.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAIH,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,EACV,YAAY,EAIZ,kBAAkB,EACnB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EASL,KAAK,aAAa,EACnB,MAAM,2BAA2B,CAAC;AACnC,OAAO,KAAK,EAKV,aAAa,EAId,MAAM,SAAS,CAAC;AAwDjB;;GAEG;AACH,wBAAgB,eAAe,CAAC,KAAK,EAAE,kBAAkB,GAAG,OAAO,CAElE;AAWD;;GAEG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,kBAAkB,GAAG,IAAI,CAGjE;AA6GD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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;IAqGD,gBAAgB;IACP,MAAM,CAAC,IAAI,EAAE,WAAW,GAAG,IAAI;IAkQxC,gBAAgB;IACP,MAAM,IAAI,IAAI;IAqBvB;;;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;IA4OxD;;;;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;IA8D7C;;;;;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;IA2C7D;;;OAGG;IACM,cAAc,IAAI,IAAI;IAQ/B;;;OAGG;IACH,IAAI,WAAW,IAAI,CAAC,EAAE,CAOrB;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;;;;;;OAMG;IACH,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAQ/B;;;;;OAKG;IACH,UAAU,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAIlC;;;OAGG;IACH,IAAI,KAAK,IAAI,OAAO,CASnB;IAED;;;OAGG;IACH,IAAI,QAAQ,IAAI,OAAO,CAEtB;IAED;;;;;OAKG;IACH,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAgBnC;;;;;;;;;;;OAWG;IACH,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAa9B;;;;;OAKG;IACH,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAchC;;OAEG;IACH,eAAe,IAAI,IAAI;IAcvB;;;;;;;;;;;OAWG;IACH,cAAc,CAAC,KAAK,EAAE,MAAM,GAAG,CAAC,GAAG,SAAS;IAK5C;;;;;;;;;OASG;IACH,WAAW,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAKnC;;OAEG;IACH,YAAY,IAAI,aAAa,CAAC,CAAC,CAAC,EAAE;IA4BlC;;OAEG;IACH,IAAI,WAAW,IAAI,MAAM,EAAE,CAc1B;IAED;;;;;OAKG;IACH,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IAkB9B;;OAEG;IACH,SAAS,IAAI,IAAI;IAkBjB;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,OAAO,SAAK,GAAG,IAAI;IAU5D;;;;;OAKG;IACH,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,IAAI;IAWhD;;;;OAIG;IACH,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI;IASpC;;OAEG;IACH,eAAe,IAAI,IAAI;IAQvB;;;;;;OAMG;IACH,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO;IAIpD;;;;;;OAMG;IACH,iBAAiB,CAAC,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS;IAInE;;;;;OAKG;IACH,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAKvC;;;;;OAKG;IACH,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,CAAC,MAAM,EAAE,MAAM,CAAC;IAyCpD;;;;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;CA04B5B"}
|
|
@@ -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;
|
|
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;;GAEG;AACH,wBAAgB,aAAa,CAC3B,KAAK,EAAE,gBAAgB,GAAG,mBAAmB,GAAG,iBAAiB,EACjE,GAAG,EAAE,SAAS,GACb,OAAO,CAwBT"}
|
|
@@ -6,5 +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';
|
|
9
10
|
export type { BeforeEditCloseDetail, CellCommitDetail, ChangedRowsResetDetail, DateEditorParams, EditCloseDetail, EditOpenDetail, EditingConfig, EditorContext, EditorParams, NumberEditorParams, RowCommitDetail, SelectEditorParams, TextEditorParams, } from './types';
|
|
10
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,EAEV,qBAAqB,EACrB,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
|
+
{"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;AAClF,YAAY,EAEV,qBAAqB,EACrB,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){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=()=>t.commit(""===n.value?null: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 function(e){return t=>{const i=e.editorParams,n=document.createElement("input");return 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),n.addEventListener("change",()=>{"string"==typeof t.value?t.commit(n.value):t.commit(n.valueAsDate)}),n.addEventListener("keydown",e=>{"Escape"===e.key&&t.cancel()}),n}}(e);case"select":return function(e){return t=>{const i=e.editorParams,n=document.createElement("select");if(e.multi&&(n.multiple=!0),i?.includeEmpty){const e=document.createElement("option");e.value="",e.textContent=i.emptyLabel??"",n.appendChild(e)}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 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 e=n.value;(null!==t.value&&void 0!==t.value||""!==e)&&("string"==typeof t.value&&e===t.value.replace(/[\n\r]/g,"")||("number"==typeof t.value&&""!==e?t.commit(Number(e)):t.commit(e)))};return n.addEventListener("blur",o),n.addEventListener("keydown",e=>{"Enter"===e.key&&o(),"Escape"===e.key&&t.cancel()}),n}}(e)}}function s(e){return"string"==typeof e&&("__proto__"!==e&&"constructor"!==e&&"prototype"!==e)}function d(e,t,i){return e instanceof HTMLInputElement?"checkbox"===e.type?e.checked:"number"===e.type?""===e.value?null:Number(e.value):"date"===e.type?"string"==typeof i?e.value:e.valueAsDate:"number"==typeof i?""===e.value?null:Number(e.value):null==i&&""===e.value||"string"==typeof i&&e.value===i.replace(/[\n\r]/g,"")?i:e.value:"number"===t?.type&&""!==e.value||"number"==typeof i&&""!==e.value?Number(e.value):null==i&&""===e.value?i:e.value}function l(e){}class c 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'}],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;attach(t){super.attach(t);const i=this.disconnectSignal,n=t;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.#v(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.#v(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.#p()})},{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.#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.#l.clear(),this.#c.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.#v(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.#v(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.#v(this.#i,!1),!0;const t=!e.shiftKey;return this.#m(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(s(i)){const n=!r[i];return this.#E(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.#p(),!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}afterRender(){const e=this.grid;if(this.#a&&(this.#a=!1,this.#b(e)),-1!==this.#u){const t=this.#u;this.#u=-1,e.animateRow?.(t,"change")}if(!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.#R(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.#R(t,i,n,o,r,!0))}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)}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.#y(e,t,!0)}clearInvalid(e,t){const i=this.#h.get(e);i&&(i.delete(t),0===i.size&&this.#h.delete(e)),this.#y(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.#y(e,t,!1))}}clearAllInvalid(){const e=Array.from(this.#h.entries());this.#h.clear(),e.forEach(([e,t])=>{t.forEach((t,i)=>this.#y(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)??[])}#y(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.#C(),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.#_(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.#I(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(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.#v(this.#i,!1)}cancelActiveRowEdit(){-1!==this.#i&&this.#v(this.#i,!0)}#_(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.#I(e,o),this.#r=t,this.#R(o,e,r,t,i,!1)))}#p(){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())}}#m(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.#v(r,!1),n._focusRow=l,n._focusCol=i?s[0]:s[s.length-1],this.beginBulkEdit(l),t(n,{forceHorizontalScroll:!0})))}#C(){const e=this.grid;e._activeEditRows=this.#i,e._rowEditSnapshots=this.#s}#I(e,t){if(this.#i!==e){-1!==this.#i&&this.#v(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.#C(),this.#t||this.emit("edit-open",{rowIndex:e,rowId:this.#n??"",row:t})}}#v(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,l=s?.row??this.#o??i._rows[e];if(!r&&l)try{r=i.getRowId?.(l)}catch{}if(!t&&o&&l){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=l[t],n=d(r,o,i);i!==n&&this.#E(e,o,n,l)}})}if(t||this.#t||!l||this.emit("before-edit-close",{rowIndex:e,rowId:r??"",row:l}),t&&n&&l)Object.keys(n).forEach(e=>{l[e]=n[e]}),r&&(this.#d.delete(r),this.clearRowInvalid(r));else if(!t&&l){const t=this.#k(n,l),i=r?this.#d.has(r):t,o=this.emitCancelable("row-commit",{rowIndex:e,rowId:r??"",row:l,oldValue:n,newValue:l,changed:i,changedRows:this.changedRows,changedRowIds:this.changedRowIds});o&&n?(Object.keys(n).forEach(e=>{l[e]=n[e]}),r&&(this.#d.delete(r),this.clearRowInvalid(r))):!o&&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.#C();for(const d of this.#l)d.startsWith(`${e}:`)&&this.#l.delete(d);for(const d of this.#c.keys())d.startsWith(`${e}:`)&&this.#c.delete(d);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.#b(i),this.#a=!1),!this.#t&&l&&this.emit("edit-close",{rowIndex:e,rowId:r??"",row:l,reverted:t})}#E(e,t,i,n){const o=t.field;if(!s(o))return;const r=n[o];if(r===i)return;const d=this.grid;let c;try{c=this.grid.getRowId(n)}catch{}const a=!c||!this.#d.has(c),u=c?e=>this.grid.updateRow(c,e,"cascade"):l;let h=!1;const f=c?e=>{h=!0,this.setInvalid(c,o,e??"")}:()=>{};if(this.emitCancelable("cell-commit",{row:n,rowId:c??"",field:o,oldValue:r,value:i,rowIndex:e,changedRows:this.changedRows,changedRowIds:this.changedRowIds,firstTimeForRow:a,updateRow:u,setInvalid:f}))return;c&&!h&&this.isCellInvalid(c,o)&&this.clearInvalid(c,o),n[o]=i,c&&this.#d.add(c),this.#C(),this.emitPluginEvent("cell-edit-committed",{rowIndex:e,field:o,oldValue:r,newValue:i});const g=d.findRenderedRowElement?.(e);g&&g.classList.add("changed")}#R(t,i,n,o,c,a){if(!n.editable)return;if(c.classList.contains("editing"))return;let u;try{u=this.grid.getRowId(t)}catch{}const h=u?e=>this.grid.updateRow(u,e,"cascade"):l,f=s(n.field)?t[n.field]:void 0;c.classList.add("editing"),this.#l.add(`${i}:${o}`);const g=c.parentElement;g&&function(e){const t=(e.__editingCellCount??0)+1;e.__editingCellCount=t,e.setAttribute("data-has-editing","")}(g);let w=!1;const v=e=>{if(w||!this.#t&&-1===this.#i)return;const o=this.grid,r=u?o._getRowEntry(u):void 0,s=r?.row??t,d=r?.index??i;this.#E(d,n,e,s)},p=()=>{if(w=!0,s(n.field)){const e=this.grid,i=u?e._getRowEntry(u):void 0;(i?.row??t)[n.field]=f}},m=document.createElement("div");m.className="tbw-editor-host",c.innerHTML="",c.appendChild(m),m.addEventListener("keydown",e=>{if("Enter"===e.key){if(this.#t){e.stopPropagation(),e.preventDefault();const t=m.querySelector("input,textarea,select");return void(t&&v(d(t,n,f)))}if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(e))return}e.stopPropagation(),e.preventDefault(),w=!0,this.#v(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(),p(),this.#v(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)??r(n),y=f,C=`${i}:${n.field}`,_=[];this.#c.set(C,e=>{for(const t of _)t(e)});const I=e=>{_.push(e)};if("template"===R&&b)this.#S(m,E,t,f,v,p,a,i),I(e=>{const t=m.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",()=>v(t.value)),I(e=>{t.value=e}),m.appendChild(t),a||queueMicrotask(()=>{const t=m.querySelector(e);t?.focus({preventScroll:!0})})}else if("function"==typeof R){const i=R({row:t,rowId:u??"",value:y,field:n.field,column:n,commit:v,cancel:p,updateRow:h,onValueChange:I});if("string"==typeof i)m.innerHTML=i,function(e,t,i,n){const o=e.querySelector("input,textarea,select");o&&(o.addEventListener("blur",()=>{i(d(o,t,n))}),o instanceof HTMLInputElement&&"checkbox"===o.type?o.addEventListener("change",()=>i(o.checked)):o instanceof HTMLSelectElement&&o.addEventListener("change",()=>i(d(o,t,n))))}(m,n,v,f),I(e=>{const t=m.querySelector("input,textarea,select");t&&(t instanceof HTMLInputElement&&"checkbox"===t.type?t.checked=!!e:t.value=String(e??""))});else if(i instanceof Node){m.appendChild(i);i instanceof HTMLInputElement||i instanceof HTMLSelectElement||i instanceof HTMLTextAreaElement?I(e=>{i instanceof HTMLInputElement&&"checkbox"===i.type?i.checked=!!e:i.value=String(e??"")}):c.setAttribute("data-editor-managed","")}a||queueMicrotask(()=>{const t=m.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),m.appendChild(e),c.setAttribute("data-editor-managed","");const i={row:t,rowId:u??"",value:y,field:n.field,column:n,commit:v,cancel:p,updateRow:h,onValueChange:I};if(R.mount)try{R.mount({placeholder:e,context:i,spec:R})}catch(k){console.warn(`[tbw-grid] External editor mount error for column '${n.field}':`,k)}else this.grid.dispatchEvent(new CustomEvent("mount-external-editor",{detail:{placeholder:e,spec:R,context:i}}))}}#S(e,t,i,n,o,r,l,c){const a=t.__editorTemplate;if(!a)return;const u=a.cloneNode(!0),h=t.__compiledEditor;h?u.innerHTML=h({row:i,value:n,field:t.field,column:t,commit:o,cancel:r}):u.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(!s(t))return"";const n=i[t];return null==n?"":String(n)})||"")});const f=u.querySelector("input,textarea,select");if(f){f instanceof HTMLInputElement&&"checkbox"===f.type?f.checked=!!n:f.value=String(n??"");let e=!1;f.addEventListener("blur",()=>{e||o(d(f,t,n))}),f.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(d(f,t,n)),this.#v(c,!1)}if("Escape"===s.key){if(this.config.onBeforeEditClose){if(!1===this.config.onBeforeEditClose(s))return}s.stopPropagation(),s.preventDefault(),r(),this.#v(c,!0)}}),f instanceof HTMLInputElement&&"checkbox"===f.type&&f.addEventListener("change",()=>o(f.checked)),l||setTimeout(()=>f.focus({preventScroll:!0}),0)}e.appendChild(u)}#k(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}#b(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{c as EditingPlugin,r as defaultEditorFor};
|
|
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};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|