@toolbox-web/grid 2.3.0 → 2.4.1
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/all.d.ts +1 -0
- 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 +2 -1
- package/lib/core/internal/aria.d.ts +13 -0
- package/lib/core/internal/diagnostics.d.ts +5 -1
- package/lib/core/internal/dom-builder.d.ts +0 -25
- package/lib/core/internal/drag-drop-registry.d.ts +66 -0
- package/lib/core/internal/render-scheduler.d.ts +9 -8
- package/lib/core/plugin/base-plugin.d.ts +23 -0
- package/lib/core/plugin/plugin-manager.d.ts +9 -0
- package/lib/core/types.d.ts +67 -46
- package/lib/features/registry.js.map +1 -1
- package/lib/features/reorder-rows.d.ts +3 -3
- package/lib/features/reorder-rows.js +1 -1
- package/lib/features/reorder-rows.js.map +1 -1
- package/lib/features/row-drag-drop.d.ts +9 -0
- package/lib/features/row-drag-drop.js +2 -0
- package/lib/features/row-drag-drop.js.map +1 -0
- package/lib/features/server-side.js.map +1 -1
- package/lib/plugins/clipboard/index.js +1 -1
- package/lib/plugins/clipboard/index.js.map +1 -1
- package/lib/plugins/column-virtualization/index.js +1 -1
- package/lib/plugins/column-virtualization/index.js.map +1 -1
- package/lib/plugins/context-menu/index.js +1 -1
- package/lib/plugins/context-menu/index.js.map +1 -1
- package/lib/plugins/editing/index.js +1 -1
- package/lib/plugins/editing/index.js.map +1 -1
- package/lib/plugins/export/ExportPlugin.d.ts +89 -0
- package/lib/plugins/export/index.d.ts +3 -2
- package/lib/plugins/export/index.js +1 -1
- package/lib/plugins/export/index.js.map +1 -1
- package/lib/plugins/export/types.d.ts +30 -0
- package/lib/plugins/filtering/FilteringPlugin.d.ts +15 -0
- package/lib/plugins/filtering/index.js +1 -1
- package/lib/plugins/filtering/index.js.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 +2 -2
- package/lib/plugins/grouping-rows/index.js.map +1 -1
- package/lib/plugins/master-detail/index.js +1 -1
- package/lib/plugins/master-detail/index.js.map +1 -1
- package/lib/plugins/multi-sort/index.js +1 -1
- package/lib/plugins/multi-sort/index.js.map +1 -1
- package/lib/plugins/pinned-columns/index.js +1 -1
- package/lib/plugins/pinned-columns/index.js.map +1 -1
- package/lib/plugins/pinned-rows/index.js +1 -1
- package/lib/plugins/pinned-rows/index.js.map +1 -1
- package/lib/plugins/pivot/index.js +1 -1
- package/lib/plugins/pivot/index.js.map +1 -1
- package/lib/plugins/print/index.js +1 -1
- package/lib/plugins/print/index.js.map +1 -1
- package/lib/plugins/reorder-columns/index.js +1 -1
- package/lib/plugins/reorder-columns/index.js.map +1 -1
- package/lib/plugins/reorder-rows/RowReorderPlugin.d.ts +14 -156
- package/lib/plugins/reorder-rows/index.d.ts +10 -4
- package/lib/plugins/reorder-rows/index.js +1 -1
- package/lib/plugins/reorder-rows/index.js.map +1 -1
- package/lib/plugins/reorder-rows/types.d.ts +9 -86
- package/lib/plugins/responsive/index.js +1 -1
- package/lib/plugins/responsive/index.js.map +1 -1
- package/lib/plugins/row-drag-drop/RowDragDropPlugin.d.ts +146 -0
- package/lib/plugins/row-drag-drop/index.d.ts +9 -0
- package/lib/plugins/row-drag-drop/index.js +2 -0
- package/lib/plugins/row-drag-drop/index.js.map +1 -0
- package/lib/plugins/row-drag-drop/types.d.ts +276 -0
- package/lib/plugins/selection/index.js +1 -1
- package/lib/plugins/selection/index.js.map +1 -1
- package/lib/plugins/server-side/ServerSidePlugin.d.ts +13 -0
- package/lib/plugins/server-side/datasource-types.d.ts +54 -7
- package/lib/plugins/server-side/datasource.d.ts +10 -2
- package/lib/plugins/server-side/index.d.ts +1 -1
- package/lib/plugins/server-side/index.js +1 -1
- package/lib/plugins/server-side/index.js.map +1 -1
- package/lib/plugins/server-side/types.d.ts +1 -1
- package/lib/plugins/shared/drag-drop-protocol.d.ts +98 -0
- package/lib/plugins/tooltip/index.js +1 -1
- package/lib/plugins/tooltip/index.js.map +1 -1
- package/lib/plugins/tree/TreePlugin.d.ts +19 -6
- package/lib/plugins/tree/index.js +1 -1
- package/lib/plugins/tree/index.js.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/visibility/index.js +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/export.umd.js +1 -1
- package/umd/plugins/export.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/reorder-rows.umd.js +1 -1
- package/umd/plugins/reorder-rows.umd.js.map +1 -1
- package/umd/plugins/row-drag-drop.umd.js +2 -0
- package/umd/plugins/row-drag-drop.umd.js.map +1 -0
- package/umd/plugins/selection.umd.js +1 -1
- package/umd/plugins/selection.umd.js.map +1 -1
- package/umd/plugins/server-side.umd.js +1 -1
- package/umd/plugins/server-side.umd.js.map +1 -1
- package/umd/plugins/tree.umd.js +1 -1
- package/umd/plugins/tree.umd.js.map +1 -1
|
@@ -0,0 +1,276 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Row Drag-Drop Plugin Types
|
|
3
|
+
*
|
|
4
|
+
* Public types for {@link RowDragDropPlugin} — drag rows within a single grid
|
|
5
|
+
* (parity with the deprecated `RowReorderPlugin`) **and** between grids that
|
|
6
|
+
* share a `dropZone` identifier.
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* Configuration for {@link RowDragDropPlugin}.
|
|
10
|
+
*
|
|
11
|
+
* All keys not annotated as "cross-grid" are identical in name and default to
|
|
12
|
+
* `RowReorderConfig`, so migration is `new RowReorderPlugin(cfg)` →
|
|
13
|
+
* `new RowDragDropPlugin(cfg)` with zero changes.
|
|
14
|
+
*/
|
|
15
|
+
export interface RowDragDropConfig<T = unknown> {
|
|
16
|
+
/**
|
|
17
|
+
* Enable keyboard shortcuts (`Ctrl + ↑` / `Ctrl + ↓`) for moving rows.
|
|
18
|
+
* Keyboard moves are intra-grid only.
|
|
19
|
+
* @default true
|
|
20
|
+
*/
|
|
21
|
+
enableKeyboard?: boolean;
|
|
22
|
+
/**
|
|
23
|
+
* Show a drag handle column.
|
|
24
|
+
*
|
|
25
|
+
* Defaults to `true` when {@link RowDragDropConfig.dragFrom dragFrom} is
|
|
26
|
+
* `'handle'` (the default) or `'both'`, and to `false` when `dragFrom` is
|
|
27
|
+
* `'row'` — when the entire row is the drag handle, the dedicated grip
|
|
28
|
+
* column adds no value. Set explicitly to override.
|
|
29
|
+
* @default true (or false when `dragFrom: 'row'`)
|
|
30
|
+
*/
|
|
31
|
+
showDragHandle?: boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Where on a row a drag can be initiated.
|
|
34
|
+
*
|
|
35
|
+
* - `'handle'` (default): only the grip column starts a drag. Backwards
|
|
36
|
+
* compatible with `RowReorderPlugin`.
|
|
37
|
+
* - `'row'`: any cell starts a drag, and the grip column is hidden by
|
|
38
|
+
* default. Recommended for transfer-list / kanban-style UIs where a
|
|
39
|
+
* dedicated handle adds visual noise.
|
|
40
|
+
* - `'both'`: either the grip OR any cell starts a drag.
|
|
41
|
+
*
|
|
42
|
+
* Drags initiated on interactive descendants (inputs, buttons, anchors,
|
|
43
|
+
* contenteditable, open cell editors, selection checkboxes) are always
|
|
44
|
+
* suppressed regardless of this setting so native interactions keep working.
|
|
45
|
+
* @default 'handle'
|
|
46
|
+
*/
|
|
47
|
+
dragFrom?: 'handle' | 'row' | 'both';
|
|
48
|
+
/**
|
|
49
|
+
* Position of the drag handle column.
|
|
50
|
+
* @default 'left'
|
|
51
|
+
*/
|
|
52
|
+
dragHandlePosition?: 'left' | 'right';
|
|
53
|
+
/**
|
|
54
|
+
* Width of the drag handle column in pixels.
|
|
55
|
+
* @default 40
|
|
56
|
+
*/
|
|
57
|
+
dragHandleWidth?: number;
|
|
58
|
+
/**
|
|
59
|
+
* Debounce time in milliseconds for rapid keyboard moves.
|
|
60
|
+
* Events are batched and emitted after this delay.
|
|
61
|
+
* @default 150
|
|
62
|
+
*/
|
|
63
|
+
debounceMs?: number;
|
|
64
|
+
/**
|
|
65
|
+
* Animation type for row movement.
|
|
66
|
+
* - `false`: instant reorder
|
|
67
|
+
* - `'flip'`: FLIP animation (slides rows smoothly)
|
|
68
|
+
* @default 'flip'
|
|
69
|
+
*/
|
|
70
|
+
animation?: false | 'flip';
|
|
71
|
+
/**
|
|
72
|
+
* Validation callback invoked once at `dragstart` (and on intra-grid
|
|
73
|
+
* keyboard moves) to decide whether a row can be picked up.
|
|
74
|
+
* Replaces `RowReorderConfig.canMove` for the dragstart side.
|
|
75
|
+
*
|
|
76
|
+
* @param row The row about to be dragged.
|
|
77
|
+
* @param index The row's current index in the source grid's `_rows`.
|
|
78
|
+
* @returns `false` to block the drag.
|
|
79
|
+
*/
|
|
80
|
+
canDrag?: (row: T, index: number) => boolean;
|
|
81
|
+
/**
|
|
82
|
+
* @deprecated Use {@link RowDragDropConfig.canDrag canDrag} for the
|
|
83
|
+
* dragstart-side veto and {@link RowDragDropConfig.canDrop canDrop} for
|
|
84
|
+
* the drop-side veto. `canMove` is accepted as a back-compat alias and
|
|
85
|
+
* mapped internally — it is invoked for intra-grid moves with the same
|
|
86
|
+
* `(row, fromIndex, toIndex, direction)` signature as `RowReorderConfig`.
|
|
87
|
+
*/
|
|
88
|
+
canMove?: (row: T, fromIndex: number, toIndex: number, direction: 'up' | 'down') => boolean;
|
|
89
|
+
/**
|
|
90
|
+
* Shared zone identifier. Two grids that opt into the same zone may
|
|
91
|
+
* exchange rows. Omit to behave exactly like the legacy `RowReorderPlugin`
|
|
92
|
+
* — intra-grid only, no cross-grid affordances.
|
|
93
|
+
*/
|
|
94
|
+
dropZone?: string;
|
|
95
|
+
/**
|
|
96
|
+
* Cross-grid drop semantics.
|
|
97
|
+
* - `'move'` (default): the row is removed from the source grid's `_rows`
|
|
98
|
+
* and inserted into the target.
|
|
99
|
+
* - `'copy'`: the source `_rows` is unchanged; the target inserts a copy.
|
|
100
|
+
*
|
|
101
|
+
* The user's input `sourceRows` array is never mutated on either side —
|
|
102
|
+
* persistence is consumer-driven via the `row-transfer` event.
|
|
103
|
+
*
|
|
104
|
+
* @default 'move'
|
|
105
|
+
*/
|
|
106
|
+
operation?: 'copy' | 'move';
|
|
107
|
+
/**
|
|
108
|
+
* Validation callback invoked during `dragover` (same-window) and at drop
|
|
109
|
+
* time to decide whether a drop should be accepted at `targetIndex`.
|
|
110
|
+
*
|
|
111
|
+
* For intra-grid drops, `payload.sourceGridId` equals this grid's id.
|
|
112
|
+
*
|
|
113
|
+
* @returns `false` to reject the drop.
|
|
114
|
+
*/
|
|
115
|
+
canDrop?: (payload: RowDragPayload<T>, targetIndex: number) => boolean;
|
|
116
|
+
/**
|
|
117
|
+
* Optional row transformer applied when a row leaves this grid in a
|
|
118
|
+
* cross-window / cross-iframe drag (i.e. when the WeakRef live-reference
|
|
119
|
+
* path cannot be used). Use to strip internal IDs or rename fields before
|
|
120
|
+
* the row crosses a security boundary.
|
|
121
|
+
*
|
|
122
|
+
* Same-window drops use live references and bypass this hook entirely.
|
|
123
|
+
*/
|
|
124
|
+
serializeRow?: (row: T) => unknown;
|
|
125
|
+
/**
|
|
126
|
+
* Optional row transformer applied when a row lands in this grid via a
|
|
127
|
+
* cross-window / cross-iframe drag. Use to assign new IDs or remap fields.
|
|
128
|
+
*
|
|
129
|
+
* Same-window drops use live references and bypass this hook entirely.
|
|
130
|
+
*/
|
|
131
|
+
deserializeRow?: (raw: unknown) => T;
|
|
132
|
+
/**
|
|
133
|
+
* Auto-scroll the target grid when the cursor approaches its viewport top
|
|
134
|
+
* or bottom edge during drag.
|
|
135
|
+
*
|
|
136
|
+
* - `true` (default): enable with the default tuning
|
|
137
|
+
* (`edgeSize: 60`, `speed: 8`, `maxSpeed: 24`).
|
|
138
|
+
* - `false`: disabled.
|
|
139
|
+
* - object: overrides any of the tuning fields.
|
|
140
|
+
*
|
|
141
|
+
* @default true
|
|
142
|
+
*/
|
|
143
|
+
autoScroll?: boolean | {
|
|
144
|
+
edgeSize?: number;
|
|
145
|
+
speed?: number;
|
|
146
|
+
maxSpeed?: number;
|
|
147
|
+
};
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Cross-grid drag payload, carried on `dataTransfer` and (for same-window
|
|
151
|
+
* recovery) keyed in the WeakRef registry by `sessionId`.
|
|
152
|
+
*/
|
|
153
|
+
export interface RowDragPayload<T = unknown> {
|
|
154
|
+
/** Drag session id (matches the WeakRef registry key). */
|
|
155
|
+
sessionId: string;
|
|
156
|
+
/** Source grid id (`grid.id` or auto-generated UUID). */
|
|
157
|
+
sourceGridId: string;
|
|
158
|
+
/** Drop zone the source grid is participating in. */
|
|
159
|
+
dropZone: string;
|
|
160
|
+
/** Serialized row payload (JSON-safe). For same-window drops, recovered live via the registry. */
|
|
161
|
+
rows: T[];
|
|
162
|
+
/** Original indices in the source grid's `_rows` array. */
|
|
163
|
+
rowIndices: number[];
|
|
164
|
+
/** Move (default) removes from source; copy leaves source intact. */
|
|
165
|
+
operation: 'move' | 'copy';
|
|
166
|
+
}
|
|
167
|
+
/**
|
|
168
|
+
* Event detail emitted when a row is moved within a single grid.
|
|
169
|
+
*
|
|
170
|
+
* For backward compatibility this type matches `RowReorderPlugin`'s
|
|
171
|
+
* `RowMoveDetail` exactly; the `row-move` event continues to fire only for
|
|
172
|
+
* intra-grid moves. Cross-grid moves emit `row-transfer` instead.
|
|
173
|
+
*/
|
|
174
|
+
export interface RowMoveDetail<T = unknown> {
|
|
175
|
+
/** The row that was moved. */
|
|
176
|
+
row: T;
|
|
177
|
+
/** The original index of the row. */
|
|
178
|
+
fromIndex: number;
|
|
179
|
+
/** The new index of the row. */
|
|
180
|
+
toIndex: number;
|
|
181
|
+
/** The full rows array in new order. */
|
|
182
|
+
rows: T[];
|
|
183
|
+
/** How the move was initiated. */
|
|
184
|
+
source: 'keyboard' | 'drag';
|
|
185
|
+
}
|
|
186
|
+
/** Detail for the `row-drag-start` event (source grid). */
|
|
187
|
+
export interface RowDragStartDetail<T = unknown> {
|
|
188
|
+
/** Rows being dragged (single row, or whole selection if dragged row is selected). */
|
|
189
|
+
rows: T[];
|
|
190
|
+
/** Indices of those rows in the source grid's `_rows`. */
|
|
191
|
+
indices: number[];
|
|
192
|
+
/** Operation requested by the source grid's config. */
|
|
193
|
+
operation: 'move' | 'copy';
|
|
194
|
+
/** Drop zone (empty string when the source grid is intra-grid only). */
|
|
195
|
+
dropZone: string;
|
|
196
|
+
}
|
|
197
|
+
/** Detail for the `row-drag-end` event (source grid). */
|
|
198
|
+
export interface RowDragEndDetail<T = unknown> {
|
|
199
|
+
/** Rows that were being dragged. */
|
|
200
|
+
rows: T[];
|
|
201
|
+
/** Their indices at dragstart. */
|
|
202
|
+
indices: number[];
|
|
203
|
+
/** True when a target grid accepted the drop (cross-grid drops only). */
|
|
204
|
+
accepted: boolean;
|
|
205
|
+
}
|
|
206
|
+
/** Detail for the `row-drop` event (target grid, cancelable). */
|
|
207
|
+
export interface RowDropDetail<T = unknown> {
|
|
208
|
+
/** Decoded payload from the source grid. */
|
|
209
|
+
payload: RowDragPayload<T>;
|
|
210
|
+
/** Convenience accessor — same as `payload.sourceGridId`. */
|
|
211
|
+
sourceGridId: string;
|
|
212
|
+
/** Final insertion index in the target grid's `_rows`. */
|
|
213
|
+
targetIndex: number;
|
|
214
|
+
/** Operation requested by the source grid (`'move'` | `'copy'`). */
|
|
215
|
+
operation: 'move' | 'copy';
|
|
216
|
+
}
|
|
217
|
+
/** Detail for the `row-transfer` event (fired on BOTH grids after success). */
|
|
218
|
+
export interface RowTransferDetail<T = unknown> {
|
|
219
|
+
/** Rows that were transferred. */
|
|
220
|
+
rows: T[];
|
|
221
|
+
/** Source grid id. */
|
|
222
|
+
fromGridId: string;
|
|
223
|
+
/** Target grid id. */
|
|
224
|
+
toGridId: string;
|
|
225
|
+
/** Indices the rows occupied in the source grid's `_rows`. */
|
|
226
|
+
fromIndices: number[];
|
|
227
|
+
/** Insertion index in the target grid's `_rows`. */
|
|
228
|
+
toIndex: number;
|
|
229
|
+
/** Operation that was applied. */
|
|
230
|
+
operation: 'move' | 'copy';
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* Internal state for pending keyboard moves (debouncing).
|
|
234
|
+
* @internal
|
|
235
|
+
*/
|
|
236
|
+
export interface PendingMove {
|
|
237
|
+
/** Original index when debounce started. */
|
|
238
|
+
originalIndex: number;
|
|
239
|
+
/** Current pending index. */
|
|
240
|
+
currentIndex: number;
|
|
241
|
+
/** The row being moved. */
|
|
242
|
+
row: unknown;
|
|
243
|
+
}
|
|
244
|
+
declare module '../../core/types' {
|
|
245
|
+
interface DataGridEventMap<TRow = unknown> {
|
|
246
|
+
/**
|
|
247
|
+
* Fired on the **source** grid when a row drag begins.
|
|
248
|
+
* Cancelable — call `preventDefault()` to abort the drag.
|
|
249
|
+
* @group Row Drag-Drop Events
|
|
250
|
+
*/
|
|
251
|
+
'row-drag-start': RowDragStartDetail<TRow>;
|
|
252
|
+
/**
|
|
253
|
+
* Fired on the **source** grid when a row drag ends, regardless of outcome.
|
|
254
|
+
* `detail.accepted` is `true` only for cross-grid drops that landed.
|
|
255
|
+
* @group Row Drag-Drop Events
|
|
256
|
+
*/
|
|
257
|
+
'row-drag-end': RowDragEndDetail<TRow>;
|
|
258
|
+
/**
|
|
259
|
+
* Fired on the **target** grid when a cross-grid drop is about to be
|
|
260
|
+
* applied. Cancelable — call `preventDefault()` to reject the drop.
|
|
261
|
+
* Not fired for intra-grid moves (those still emit `row-move`).
|
|
262
|
+
* @group Row Drag-Drop Events
|
|
263
|
+
*/
|
|
264
|
+
'row-drop': RowDropDetail<TRow>;
|
|
265
|
+
/**
|
|
266
|
+
* Fired on **both** the source and target grid after a successful
|
|
267
|
+
* cross-grid drop. Use this to persist changes in your data store.
|
|
268
|
+
* @group Row Drag-Drop Events
|
|
269
|
+
*/
|
|
270
|
+
'row-transfer': RowTransferDetail<TRow>;
|
|
271
|
+
}
|
|
272
|
+
interface PluginNameMap {
|
|
273
|
+
/** Primary name for the row drag-drop plugin. */
|
|
274
|
+
rowDragDrop: import('./RowDragDropPlugin').RowDragDropPlugin;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
const e="selected",t={sortApplied:(e,t)=>`Sorted by ${e}, ${t}`,sortCleared:()=>"Sort cleared",filterApplied:e=>`Filter applied on ${e}`,filterCleared:e=>`Filter cleared from ${e}`,allFiltersCleared:()=>"All filters cleared",groupExpanded:(e,t)=>`Group ${e} expanded, ${t} rows`,groupCollapsed:e=>`Group ${e} collapsed`,selectionChanged:e=>`${e} rows selected`,editingStarted:e=>`Editing row ${e+1}`,editingCommitted:e=>`Row ${e+1} saved`,dataLoaded:e=>`${e} rows loaded`},s='<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:s,filterActive:s,print:"🖨️"};function r(e){if(!e)return-1;const t=e.getAttribute("data-row");if(t)return parseInt(t,10);const s=e.closest(".data-grid-row");if(!s)return-1;const i=s.parentElement;if(!i)return-1;const r=i.querySelectorAll(":scope > .data-grid-row");for(let o=0;o<r.length;o++)if(r[o]===s)return o;return-1}function o(e){e&&e.querySelectorAll(".cell-focus").forEach(e=>e.classList.remove("cell-focus"))}function n(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function l(e,t,s,i){return`${n(s,i)} ${e}: ${t}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}const c="__otorp__|__retteGenifed__|__retteSenifed__|rotcurtsnoc|wodniw|sihTlabolg|labolg|ssecorp|noitcnuF|tropmi|lave|tcelfeR|yxorP|rorrE|stnemugra|tnemucod|noitacol|eikooc|egarotSlacol|egarotSnoisses|BDdexedni|hctef|tseuqeRpttHLMX|tekcoSbeW|rekroW|rekroWderahS|rekroWecivreS|renepo|tnerap|pot|semarf|fles".split("|").map(e=>e.split("").reverse().join(""));new RegExp(`__(proto|defineGetter|defineSetter)|${c.slice(3).join("|")}|this\\b`);const a=new Set("script|iframe|object|embed|form|input|button|textarea|select|link|meta|base|style|template|slot|portal|frame|frameset|applet|noscript|noembed|plaintext|xmp|listing".split("|")),d=/^on\w+$/i,h=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),u=/^\s*(javascript|vbscript|data|blob):/i;function g(e){if(!e||"string"!=typeof e)return"";if(-1===e.indexOf("<"))return e;const t=document.createElement("template");return t.innerHTML=e,function(e){const t=[],s=e.querySelectorAll("*");for(const i of s){const e=i.tagName.toLowerCase();if(a.has(e)){t.push(i);continue}if("svg"===e||"http://www.w3.org/2000/svg"===i.namespaceURI){if(Array.from(i.attributes).some(e=>d.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(i);continue}}const s=[];for(const t of i.attributes){const e=t.name.toLowerCase();d.test(e)?s.push(t.name):(h.has(e)&&u.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&s.push(t.name)}s.forEach(e=>i.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content),t.innerHTML}class f{static dependencies;static manifest;aliases;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 s=new CustomEvent(e,{detail:t,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(s),s.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)}broadcast(e,t){this.emitPluginEvent(e,t),this.emit(e,t)}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}requestVirtualRefresh(){this.grid?.requestVirtualRefresh?.()}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?._hostElement}get disconnectSignal(){return this.#e?.signal??this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...i,...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(),s=parseInt(t,10);if(!isNaN(s))return s}return 200}setIcon(e,t,s){e.dataset.icon=t.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===t?e.dataset.expanded="":"expand"===t&&delete e.dataset.expanded;const i=this.#t(t,s);void 0!==i?"string"==typeof i?e.innerHTML=g(i):i instanceof HTMLElement&&(e.innerHTML="",e.appendChild(i.cloneNode(!0))):e.innerHTML=""}#t(e,t){return void 0!==t?t:this.grid?.gridConfig?.icons?.[e]}updateSortIndicator(e,t){e.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const s=document.createElement("span");s.setAttribute("part","sort-indicator"),s.className="sort-indicator",t?(e.setAttribute("aria-sort","asc"===t?"ascending":"descending"),e.setAttribute("data-sort",t),this.setIcon(s,"asc"===t?"sortAsc":"sortDesc")):(e.setAttribute("aria-sort","none"),e.removeAttribute("data-sort"),this.setIcon(s,"sortNone"));const i=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return i?e.insertBefore(s,i):e.appendChild(s),s}warn(e,t){void 0!==t?console.warn(l(e,t,this.gridElement.id,this.name)):console.warn(`${n(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(l(e,t,this.gridElement.id,this.name))}}function w(e){return"__tbw_expander"===e.field}function b(e){return!0===e.utility}function m(e){return{startRow:Math.min(e.startRow,e.endRow),startCol:Math.min(e.startCol,e.endCol),endRow:Math.max(e.startRow,e.endRow),endCol:Math.max(e.startCol,e.endCol)}}function p(e){const t=m(e);return{from:{row:t.startRow,col:t.startCol},to:{row:t.endRow,col:t.endCol}}}function S(e){return e.map(p)}function v(e,t,s){return s.some(s=>function(e,t,s){const i=m(s);return e>=i.startRow&&e<=i.endRow&&t>=i.startCol&&t<=i.endCol}(e,t,s))}function C(e){const t=[],s=m(e);for(let i=s.startRow;i<=s.endRow;i++)for(let e=s.startCol;e<=s.endCol;e++)t.push({row:i,col:e});return t}function R(e,t){return{startRow:e.row,startCol:e.col,endRow:t.row,endCol:t.col}}function y(e,t){const s=m(e),i=m(t);return s.startRow===i.startRow&&s.startCol===i.startCol&&s.endRow===i.endRow&&s.endCol===i.endCol}const A="__tbw_checkbox";class x extends f{static manifest={queries:[{type:"getSelection",description:"Get the current selection state"},{type:"selectRows",description:"Select specific rows by index (row mode only)"},{type:"getSelectedRowIndices",description:"Get sorted array of selected row indices"},{type:"getSelectedRows",description:"Get actual row objects for the current selection (works in all modes)"}],configRules:[{id:"selection/range-dblclick",severity:"warn",message:'"triggerOn: \'dblclick\'" has no effect when mode is "range".\n → Range selection uses drag interaction (mousedown → mousemove), not click events.\n → The "triggerOn" option only affects "cell" and "row" selection modes.',check:e=>"range"===e.mode&&"dblclick"===e.triggerOn}]};name="selection";styles='@layer tbw-plugins{tbw-grid.selecting .data-grid-row>.cell{-webkit-user-select:none;user-select:none}tbw-grid:has(.selection){-webkit-user-select:none;user-select:none}tbw-grid:has(.selection)[data-selection-mode=row] .cell-focus,tbw-grid:has(.selection)[data-selection-mode=row] .row-focus,tbw-grid:has(.selection)[data-selection-mode=range] .cell-focus{outline:none}tbw-grid .data-grid-row.row-focus{background-color:var(--tbw-focus-background, rgba(from var(--tbw-color-accent) r g b / 12%));outline:none;position:relative}tbw-grid .data-grid-row.row-focus:after{content:"";position:absolute;inset:0;pointer-events:none;border-width:0;border-style:var(--tbw-selection-border-style, var(--tbw-border-style));border-color:var(--tbw-range-border-color, var(--tbw-color-accent));border-top-width:var(--tbw-selection-border-width, var(--tbw-border-width));border-bottom-width:var(--tbw-selection-border-width, var(--tbw-border-width));z-index:1}tbw-grid .data-grid-row.row-focus+.data-grid-row.row-focus:after{border-top-width:0}tbw-grid .data-grid-row.row-focus:has(+.data-grid-row.row-focus):after{border-bottom-width:0}tbw-grid .data-grid-row>.cell.selected{background-color:var(--tbw-range-selection-bg);position:relative}tbw-grid .data-grid-row>.cell.selected:after{content:"";position:absolute;inset:0;pointer-events:none;border:0 var(--tbw-selection-border-style, var(--tbw-border-style)) var(--tbw-range-border-color);z-index:1}tbw-grid .data-grid-row>.cell.selected.top:after{border-top-width:var(--tbw-selection-border-width, var(--tbw-border-width))}tbw-grid .data-grid-row>.cell.selected.bottom:after{border-bottom-width:var(--tbw-selection-border-width, var(--tbw-border-width))}tbw-grid .data-grid-row>.cell.selected.first:after{border-left-width:var(--tbw-selection-border-width, var(--tbw-border-width))}tbw-grid .data-grid-row>.cell.selected.last:after{border-right-width:var(--tbw-selection-border-width, var(--tbw-border-width))}tbw-grid .data-grid-row[data-selectable=false]{cursor:not-allowed;opacity:.6}tbw-grid .data-grid-row[data-selectable=false].row-focus{background-color:var(--tbw-color-row-alt)}tbw-grid .data-grid-row>.cell[data-selectable=false]{cursor:not-allowed;opacity:.6}tbw-grid .data-grid-row>.cell[data-selectable=false].selected{background-color:var(--tbw-selection-warning-bg, rgba(from var(--tbw-color-error) r g b / 50%))}tbw-grid .tbw-selection-summary{font-size:var(--tbw-font-size-sm, .8125rem);color:var(--tbw-color-fg-muted);white-space:nowrap}tbw-grid .data-grid-row>.cell[data-field=__tbw_checkbox],tbw-grid .header-row>.cell[data-field=__tbw_checkbox]{text-align:center;cursor:pointer;padding:0;display:flex;align-items:center;justify-content:center}tbw-grid .tbw-select-row-checkbox{pointer-events:none;margin:0;cursor:pointer}tbw-grid .tbw-checkbox-header{display:flex;justify-content:center;align-items:center;height:100%}tbw-grid .tbw-select-all-checkbox{margin:0;cursor:pointer}}';get defaultConfig(){return{mode:"cell",triggerOn:"click",enabled:!0,multiSelect:!0}}selected=/* @__PURE__ */new Set;lastSelected=null;anchor=null;ranges=[];activeRange=null;cellAnchor=null;isDragging=!1;pendingKeyboardUpdate=null;pendingRowKeyUpdate=null;selectedCell=null;lastSyncedFocusRow=-1;lastSyncedFocusCol=-1;announceTimer=null;explicitSelection=!1;isSelectionEnabled(){return!1!==this.config.enabled&&!1!==this.grid.effectiveConfig?.selectable}checkSelectable(e,t){const{isSelectable:s}=this.config;if(!s)return!0;const i=this.rows[e];if(!i)return!1;return s(i,e,void 0!==t?this.visibleColumns[t]:void 0,t)}isRowSelectable(e){return this.checkSelectable(e)}isCellSelectable(e,t){return this.checkSelectable(e,t)}attach(e){super.attach(e),this.on("filter-change",()=>this.clearSelectionSilent()),this.on("group-toggle",()=>this.clearSelectionSilent()),this.on("tree-expand",()=>this.clearSelectionSilent()),this.on("sort-change",()=>this.clearSelectionSilent())}handleQuery(e){return"getSelection"===e.type?this.getSelection():"getSelectedRowIndices"===e.type?this.getSelectedRowIndices():"getSelectedRows"===e.type?this.getSelectedRows():"selectRows"===e.type?(this.selectRows(e.context),!0):void 0}detach(){this.selected.clear(),this.ranges=[],this.activeRange=null,this.cellAnchor=null,this.isDragging=!1,this.selectedCell=null,this.pendingKeyboardUpdate=null,this.pendingRowKeyUpdate=null,this.lastSyncedFocusRow=-1,this.lastSyncedFocusCol=-1}clearSelectionSilent(){this.selected.clear(),this.ranges=[],this.activeRange=null,this.cellAnchor=null,this.selectedCell=null,this.lastSelected=null,this.anchor=null,this.lastSyncedFocusRow=-1,this.lastSyncedFocusCol=-1,this.requestAfterRender()}onCellClick(e){if(!this.isSelectionEnabled())return!1;const{rowIndex:t,colIndex:s,originalEvent:i}=e,{mode:r,triggerOn:o="click"}=this.config;if(i.type!==o)return!1;const n=e.column,l=n&&b(n);if("cell"===r){if(l)return!1;if(!this.isCellSelectable(t,s))return!1;const e=this.selectedCell;return e&&e.row===t&&e.col===s||(this.selectedCell={row:t,col:s},this.emit("selection-change",this.#s()),this.requestAfterRender()),!1}if("row"===r){if(!this.isRowSelectable(t))return!1;const e=!1!==this.config.multiSelect,s=i.shiftKey&&e,r=(i.ctrlKey||i.metaKey)&&e,o=!0===n?.checkboxColumn;if(s&&null!==this.anchor){const e=Math.min(this.anchor,t),s=Math.max(this.anchor,t);r||this.selected.clear();for(let t=e;t<=s;t++)this.isRowSelectable(t)&&this.selected.add(t)}else if(r||o&&e)this.selected.has(t)?this.selected.delete(t):this.selected.add(t),this.anchor=t;else{if(1===this.selected.size&&this.selected.has(t))return!1;this.selected.clear(),this.selected.add(t),this.anchor=t}return this.lastSelected=t,this.explicitSelection=!0,this.emit("selection-change",this.#s()),this.requestAfterRender(),!1}if("range"===r){if(l)return!1;if(!this.isCellSelectable(t,s))return!1;const e=i.shiftKey,r=(i.ctrlKey||i.metaKey)&&!1!==this.config.multiSelect;if(e&&this.cellAnchor){const e=R(this.cellAnchor,{row:t,col:s}),i=this.ranges.length>0?this.ranges[this.ranges.length-1]:null;if(i&&y(i,e))return!1;r?this.ranges.length>0?this.ranges[this.ranges.length-1]=e:this.ranges.push(e):this.ranges=[e],this.activeRange=e}else if(r){const e={startRow:t,startCol:s,endRow:t,endCol:s};this.ranges.push(e),this.activeRange=e,this.cellAnchor={row:t,col:s}}else{const e={startRow:t,startCol:s,endRow:t,endCol:s};if(1===this.ranges.length&&y(this.ranges[0],e))return!1;this.ranges=[e],this.activeRange=e,this.cellAnchor={row:t,col:s}}return this.emit("selection-change",this.#s()),this.requestAfterRender(),!1}return!1}onKeyDown(e){if(!this.isSelectionEnabled())return!1;const{mode:t}=this.config,s=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Tab","Home","End","PageUp","PageDown"].includes(e.key);if("Escape"===e.key){return!this.grid.query("isEditing").some(Boolean)&&("cell"===t?this.selectedCell=null:"row"===t?(this.selected.clear(),this.anchor=null):"range"===t&&(this.ranges=[],this.activeRange=null,this.cellAnchor=null),this.emit("selection-change",this.#s()),this.requestAfterRender(),!0)}if("cell"===t&&s)return queueMicrotask(()=>{const e=this.grid._focusRow,t=this.grid._focusCol;this.isCellSelectable(e,t)?this.selectedCell={row:e,col:t}:this.selectedCell=null,this.emit("selection-change",this.#s()),this.requestAfterRender()}),!1;if("row"===t){const t=!1!==this.config.multiSelect;if("ArrowUp"===e.key||"ArrowDown"===e.key||"PageUp"===e.key||"PageDown"===e.key||(e.ctrlKey||e.metaKey)&&("Home"===e.key||"End"===e.key)){const s=e.shiftKey&&t;return s&&null===this.anchor&&(this.anchor=this.grid._focusRow),this.explicitSelection=!0,this.pendingRowKeyUpdate={shiftKey:s},queueMicrotask(()=>this.requestAfterRender()),!1}if(t&&"a"===e.key&&(e.ctrlKey||e.metaKey)){return!this.grid.query("isEditing").some(Boolean)&&(e.preventDefault(),e.stopPropagation(),this.selectAll(),!0)}}if("range"===t&&s){const t="Tab"===e.key,s=e.shiftKey&&!t;return s&&!this.cellAnchor&&(this.cellAnchor={row:this.grid._focusRow,col:this.grid._focusCol}),this.pendingKeyboardUpdate={shiftKey:s},queueMicrotask(()=>this.requestAfterRender()),!1}if("range"===t&&!1!==this.config.multiSelect&&"a"===e.key&&(e.ctrlKey||e.metaKey)){return!this.grid.query("isEditing").some(Boolean)&&(e.preventDefault(),e.stopPropagation(),this.selectAll(),!0)}return!1}onCellMouseDown(e){if(!this.isSelectionEnabled())return;if("range"!==this.config.mode)return;if(void 0===e.rowIndex||void 0===e.colIndex)return;if(e.rowIndex<0)return;if(e.column&&b(e.column))return;if(!this.isCellSelectable(e.rowIndex,e.colIndex))return;if(e.originalEvent.shiftKey&&this.cellAnchor)return;this.isDragging=!0;const t=e.rowIndex,s=e.colIndex,i=(e.originalEvent.ctrlKey||e.originalEvent.metaKey)&&!1!==this.config.multiSelect,r={startRow:t,startCol:s,endRow:t,endCol:s};return!i&&1===this.ranges.length&&y(this.ranges[0],r)?(this.cellAnchor={row:t,col:s},!0):(this.cellAnchor={row:t,col:s},i||(this.ranges=[]),this.ranges.push(r),this.activeRange=r,this.emit("selection-change",this.#s()),this.requestAfterRender(),!0)}onCellMouseMove(e){if(!this.isSelectionEnabled())return;if("range"!==this.config.mode)return;if(!this.isDragging||!this.cellAnchor)return;if(void 0===e.rowIndex||void 0===e.colIndex)return;if(e.rowIndex<0)return;let t=e.colIndex;const s=this.visibleColumns[t];if(s&&b(s)){const e=this.visibleColumns.findIndex(e=>!b(e));e>=0&&(t=e)}const i=R(this.cellAnchor,{row:e.rowIndex,col:t}),r=this.ranges.length>0?this.ranges[this.ranges.length-1]:null;return r&&y(r,i)||(this.ranges.length>0?this.ranges[this.ranges.length-1]=i:this.ranges.push(i),this.activeRange=i,this.emit("selection-change",this.#s()),this.requestAfterRender()),!0}onCellMouseUp(e){if(this.isSelectionEnabled()&&"range"===this.config.mode)return this.isDragging?(this.isDragging=!1,!0):void 0}processColumns(e){if(this.config.checkbox&&"row"===this.config.mode){if(e.some(e=>e.field===A))return e;const t=this.#i(),s=e.findIndex(w),i=s>=0?s+1:0;return[...e.slice(0,i),t,...e.slice(i)]}return e}#i(){return{field:A,header:"",width:32,resizable:!1,sortable:!1,lockPosition:!0,utility:!0,checkboxColumn:!0,headerRenderer:()=>{const e=document.createElement("div");if(e.className="tbw-checkbox-header",!1===this.config.multiSelect)return e;const t=document.createElement("input");return t.type="checkbox",t.className="tbw-select-all-checkbox",t.addEventListener("click",e=>{e.stopPropagation(),e.target.checked?this.selectAll():this.clearSelection()}),e.appendChild(t),e},renderer:e=>{const t=document.createElement("input");t.type="checkbox",t.className="tbw-select-row-checkbox";const s=e.cellEl;if(s){const e=parseInt(s.getAttribute("data-row")??"-1",10);e>=0&&(t.checked=this.selected.has(e))}return t}}}#r(e){e.querySelectorAll(".tbw-select-row-checkbox").forEach(e=>{const t=e.closest(".cell"),s=t?r(t):-1;s>=0&&(e.checked=this.selected.has(s))});const t=e.querySelector(".tbw-select-all-checkbox");if(t){const e=this.rows.length;let s=0;if(this.config.isSelectable)for(let t=0;t<e;t++)this.isRowSelectable(t)&&s++;else s=e;const i=s>0&&this.selected.size>=s,r=this.selected.size>0;t.checked=i,t.indeterminate=r&&!i}}#o(e){const t=this.grid._focusRow,s=this.grid._focusCol;if("row"===e){if(this.explicitSelection)return this.explicitSelection=!1,void(this.lastSyncedFocusRow=t);t!==this.lastSyncedFocusRow&&(this.lastSyncedFocusRow=t,this.isRowSelectable(t)&&(this.selected.has(t)&&1===this.selected.size||(this.selected.clear(),this.selected.add(t),this.lastSelected=t,this.anchor=t,this.emit("selection-change",this.#s()))))}if("cell"===e){if(this.explicitSelection)return this.explicitSelection=!1,this.lastSyncedFocusRow=t,void(this.lastSyncedFocusCol=s);if((t!==this.lastSyncedFocusRow||s!==this.lastSyncedFocusCol)&&(this.lastSyncedFocusRow=t,this.lastSyncedFocusCol=s,this.isCellSelectable(t,s))){const e=this.selectedCell;e&&e.row===t&&e.col===s||(this.selectedCell={row:t,col:s},this.emit("selection-change",this.#s()))}}}#n(){const t=this.gridElement;if(!t)return;const{mode:s}=this.config,i=!!this.config.isSelectable;t.querySelectorAll(".cell").forEach(t=>{t.classList.remove(e,"top","bottom","first","last"),i&&t.removeAttribute("data-selectable")});const n=t.querySelectorAll(".data-grid-row");if(n.forEach(t=>{t.classList.remove(e,"row-focus"),t.setAttribute("aria-selected","false"),i&&t.removeAttribute("data-selectable")}),"row"===s&&(o(t),n.forEach(t=>{const s=r(t.querySelector(".cell[data-row]"));s>=0&&(i&&!this.isRowSelectable(s)&&t.setAttribute("data-selectable","false"),this.selected.has(s)&&(t.classList.add(e,"row-focus"),t.setAttribute("aria-selected","true")))}),this.config.checkbox&&this.#r(t)),("cell"===s||"range"===s)&&i){t.querySelectorAll(".cell[data-row][data-col]").forEach(e=>{const t=parseInt(e.getAttribute("data-row")??"-1",10),s=parseInt(e.getAttribute("data-col")??"-1",10);t>=0&&s>=0&&(this.isCellSelectable(t,s)||e.setAttribute("data-selectable","false"))})}if("range"===s&&this.ranges.length>0){o(t);const s=this.ranges.map(m),i=(e,t)=>{for(const i of s)if(e>=i.startRow&&e<=i.endRow&&t>=i.startCol&&t<=i.endCol)return!0;return!1};t.querySelectorAll(".cell[data-row][data-col]").forEach(t=>{const s=parseInt(t.getAttribute("data-row")??"-1",10),r=parseInt(t.getAttribute("data-col")??"-1",10);if(s>=0&&r>=0){const o=this.visibleColumns[r];if(o&&b(o))return;i(s,r)&&(t.classList.add(e),t.setAttribute("aria-selected","true"),i(s-1,r)||t.classList.add("top"),i(s+1,r)||t.classList.add("bottom"),i(s,r-1)||t.classList.add("first"),i(s,r+1)||t.classList.add("last"))}})}}afterRender(){if(!this.isSelectionEnabled())return;const e=this.gridElement;if(!e)return;const t=e.querySelector(".tbw-grid-root"),{mode:s}=this.config;if(this.pendingRowKeyUpdate&&"row"===s){const{shiftKey:e}=this.pendingRowKeyUpdate;this.pendingRowKeyUpdate=null;const t=this.grid._focusRow;if(e&&null!==this.anchor){this.selected.clear();const e=Math.min(this.anchor,t),s=Math.max(this.anchor,t);for(let t=e;t<=s;t++)this.isRowSelectable(t)&&this.selected.add(t)}else this.isRowSelectable(t)?(this.selected.clear(),this.selected.add(t),this.anchor=t):this.selected.clear();this.lastSelected=t,this.emit("selection-change",this.#s())}if(this.pendingKeyboardUpdate&&"range"===s){const{shiftKey:e}=this.pendingKeyboardUpdate;this.pendingKeyboardUpdate=null;const t=this.grid._focusRow,s=this.grid._focusCol;if(e&&this.cellAnchor){const e=R(this.cellAnchor,{row:t,col:s});this.ranges=[e],this.activeRange=e}else e||(this.ranges=[],this.activeRange=null,this.cellAnchor={row:t,col:s});this.emit("selection-change",this.#s())}this.#o(s),this.gridElement.setAttribute("data-selection-mode",s),t&&t.classList.toggle("selecting",this.isDragging),this.#n()}onScrollRender(){this.isSelectionEnabled()&&this.#n()}getSelection(){return{mode:this.config.mode,ranges:this.#s().ranges,anchor:this.cellAnchor}}getSelectedCells(){return function(e){const t=/* @__PURE__ */new Map;for(const s of e)for(const e of C(s))t.set(`${e.row},${e.col}`,e);return[...t.values()]}(this.ranges)}isCellSelected(e,t){return v(e,t,this.ranges)}selectAll(){const{mode:e,multiSelect:t}=this.config;if(!1!==t)if("row"===e){this.selected.clear();for(let e=0;e<this.rows.length;e++)this.isRowSelectable(e)&&this.selected.add(e);this.explicitSelection=!0,this.emit("selection-change",this.#s()),this.requestAfterRender()}else if("range"===e){const e=this.rows.length,t=this.columns.length;if(e>0&&t>0){const s={startRow:0,startCol:0,endRow:e-1,endCol:t-1};this.ranges=[s],this.activeRange=s,this.emit("selection-change",this.#s()),this.requestAfterRender()}}}selectRows(e){if("row"!==this.config.mode)return;const t=!1===this.config.multiSelect&&e.length>1?[e[e.length-1]]:e;this.selected.clear();for(const s of t)s>=0&&s<this.rows.length&&this.isRowSelectable(s)&&this.selected.add(s);this.anchor=t.length>0?t[t.length-1]:null,this.explicitSelection=!0,this.emit("selection-change",this.#s()),this.requestAfterRender()}getSelectedRowIndices(){return[...this.selected].sort((e,t)=>e-t)}getSelectedRows(){const{mode:e}=this.config,t=this.rows;if("row"===e)return this.getSelectedRowIndices().filter(e=>e>=0&&e<t.length).map(e=>t[e]);if("cell"===e&&this.selectedCell){const{row:e}=this.selectedCell;return e>=0&&e<t.length?[t[e]]:[]}if("range"===e&&this.ranges.length>0){const e=/* @__PURE__ */new Set;for(const s of this.ranges){const i=Math.max(0,Math.min(s.startRow,s.endRow)),r=Math.min(t.length-1,Math.max(s.startRow,s.endRow));for(let t=i;t<=r;t++)e.add(t)}return[...e].sort((e,t)=>e-t).map(e=>t[e])}return[]}clearSelection(){this.selectedCell=null,this.selected.clear(),this.anchor=null,this.ranges=[],this.activeRange=null,this.cellAnchor=null,this.emit("selection-change",{mode:this.config.mode,ranges:[]}),this.requestAfterRender()}setRanges(e){this.ranges=e.map(e=>({startRow:e.from.row,startCol:e.from.col,endRow:e.to.row,endCol:e.to.col})),this.activeRange=this.ranges.length>0?this.ranges[this.ranges.length-1]:null,this.emit("selection-change",{mode:this.config.mode,ranges:S(this.ranges)}),this.requestAfterRender()}#s(){const e=function(e,t,s){if("cell"===e&&t.selectedCell)return{mode:e,ranges:[{from:{row:t.selectedCell.row,col:t.selectedCell.col},to:{row:t.selectedCell.row,col:t.selectedCell.col}}]};if("row"===e&&t.selected.size>0){const i=[...t.selected].sort((e,t)=>e-t),r=[];let o=i[0],n=o;for(let e=1;e<i.length;e++)i[e]===n+1?n=i[e]:(r.push({from:{row:o,col:0},to:{row:n,col:s-1}}),o=i[e],n=o);return r.push({from:{row:o,col:0},to:{row:n,col:s-1}}),{mode:e,ranges:r}}return"range"===e&&t.ranges.length>0?{mode:e,ranges:S(t.ranges)}:{mode:e,ranges:[]}}(this.config.mode,{selectedCell:this.selectedCell,selected:this.selected,ranges:this.ranges},this.columns.length);return this.announceTimer&&clearTimeout(this.announceTimer),this.announceTimer=setTimeout(()=>{const s="row"===e.mode?this.selected.size:e.ranges.length;s>0&&function(e,t){if(!e)return;const s="effectiveConfig"in e?e.effectiveConfig:void 0;if(!1===s?.a11y?.announcements)return;const i=e.querySelector?.(".tbw-sr-only");i&&(i.textContent="",requestAnimationFrame(()=>{i.textContent=t}))}(this.gridElement,function(e,s,...i){const r=e&&"effectiveConfig"in e?e.effectiveConfig:void 0,o=r?.a11y?.messages?.[s];return o?o(...i):t[s](...i)}(this.gridElement,"selectionChanged",s))},150),e}}export{x as SelectionPlugin};
|
|
1
|
+
const e="selected",t={sortApplied:(e,t)=>`Sorted by ${e}, ${t}`,sortCleared:()=>"Sort cleared",filterApplied:e=>`Filter applied on ${e}`,filterCleared:e=>`Filter cleared from ${e}`,allFiltersCleared:()=>"All filters cleared",groupExpanded:(e,t)=>`Group ${e} expanded, ${t} rows`,groupCollapsed:e=>`Group ${e} collapsed`,selectionChanged:e=>`${e} rows selected`,editingStarted:e=>`Editing row ${e+1}`,editingCommitted:e=>`Row ${e+1} saved`,dataLoaded:e=>`${e} rows loaded`},r={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:"",filterActive:"",print:"🖨️"};function s(e){if(!e)return-1;const t=e.getAttribute("data-row");if(t)return parseInt(t,10);const r=e.closest(".data-grid-row");if(!r)return-1;const s=r.parentElement;if(!s)return-1;const i=s.querySelectorAll(":scope > .data-grid-row");for(let o=0;o<i.length;o++)if(i[o]===r)return o;return-1}function i(e){e&&e.querySelectorAll(".cell-focus").forEach(e=>e.classList.remove("cell-focus"))}function o(e,t){return`[tbw-grid${e?`#${e}`:""}${t?`:${t}`:""}]`}function n(e,t,r,s){return`${o(r,s)} ${e}: ${t}\n\n → More info: ${function(e){return`https://toolboxjs.com/grid/errors#${e.toLowerCase()}`}(e)}`}const l="__otorp__|__retteGenifed__|__retteSenifed__|rotcurtsnoc|wodniw|sihTlabolg|labolg|ssecorp|noitcnuF|tropmi|lave|tcelfeR|yxorP|rorrE|stnemugra|tnemucod|noitacol|eikooc|egarotSlacol|egarotSnoisses|BDdexedni|hctef|tseuqeRpttHLMX|tekcoSbeW|rekroW|rekroWderahS|rekroWecivreS|renepo|tnerap|pot|semarf|fles".split("|").map(e=>e.split("").reverse().join(""));new RegExp(`__(proto|defineGetter|defineSetter)|${l.slice(3).join("|")}|this\\b`);const c=new Set("script|iframe|object|embed|form|input|button|textarea|select|link|meta|base|style|template|slot|portal|frame|frameset|applet|noscript|noembed|plaintext|xmp|listing".split("|")),a=/^on\w+$/i,d=new Set("href|src|action|formaction|data|srcdoc|xlink:href|poster|srcset".split("|")),h=/^\s*(javascript|vbscript|data|blob):/i;function u(e){if(!e||"string"!=typeof e)return"";if(-1===e.indexOf("<"))return e;const t=document.createElement("template");return t.innerHTML=e,function(e){const t=[],r=e.querySelectorAll("*");for(const s of r){const e=s.tagName.toLowerCase();if(c.has(e)){t.push(s);continue}if("svg"===e||"http://www.w3.org/2000/svg"===s.namespaceURI){if(Array.from(s.attributes).some(e=>a.test(e.name)||"href"===e.name||"xlink:href"===e.name)){t.push(s);continue}}const r=[];for(const t of s.attributes){const e=t.name.toLowerCase();a.test(e)?r.push(t.name):(d.has(e)&&h.test(t.value)||"style"===e&&/expression\s*\(|javascript:|behavior\s*:/i.test(t.value))&&r.push(t.name)}r.forEach(e=>s.removeAttribute(e))}t.forEach(e=>e.remove())}(t.content),t.innerHTML}class g{static dependencies;static manifest;aliases;version="undefined"!=typeof __GRID_VERSION__?__GRID_VERSION__:"dev";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#e;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}mergeConfigsFrom(e){if(0===e.length)return;const t={...this.userConfig},r={};for(const s of Object.keys(t))r[s]=this;for(const s of e){const e=s.userConfig;for(const[i,o]of Object.entries(e)){if(void 0===o)continue;if(!(i in t)){t[i]=o,r[i]=s;continue}if(t[i]===o)continue;const e=r[i]?.constructor.name??this.constructor.name,l=s.constructor.name,c=n("TBW025",`Cannot merge plugin configs for "${this.name}": conflicting value for "${i}" supplied by both ${e} and ${l}. Pass the option on a single instance, or remove the duplicate.`,void 0,this.name);throw new Error(c)}}Object.assign(this.userConfig,t)}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 r=new CustomEvent(e,{detail:t,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(r),r.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)}broadcast(e,t){this.emitPluginEvent(e,t),this.emit(e,t)}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}requestVirtualRefresh(){this.grid?.requestVirtualRefresh?.()}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?._hostElement}get disconnectSignal(){return this.#e?.signal??this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...r,...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(),r=parseInt(t,10);if(!isNaN(r))return r}return 200}setIcon(e,t,r){e.dataset.icon=t.replace(/([A-Z])/g,"-$1").toLowerCase(),"collapse"===t?e.dataset.expanded="":"expand"===t&&delete e.dataset.expanded;const s=this.#t(t,r);void 0!==s?"string"==typeof s?e.innerHTML=u(s):s instanceof HTMLElement&&(e.innerHTML="",e.appendChild(s.cloneNode(!0))):e.innerHTML=""}#t(e,t){return void 0!==t?t:this.grid?.gridConfig?.icons?.[e]}updateSortIndicator(e,t){e.querySelector('[part~="sort-indicator"], .sort-indicator')?.remove();const r=document.createElement("span");r.setAttribute("part","sort-indicator"),r.className="sort-indicator",t?(e.setAttribute("aria-sort","asc"===t?"ascending":"descending"),e.setAttribute("data-sort",t),this.setIcon(r,"asc"===t?"sortAsc":"sortDesc")):(e.setAttribute("aria-sort","none"),e.removeAttribute("data-sort"),this.setIcon(r,"sortNone"));const s=e.querySelector(".tbw-filter-btn")??e.querySelector(".resize-handle");return s?e.insertBefore(r,s):e.appendChild(r),r}warn(e,t){void 0!==t?console.warn(n(e,t,this.gridElement.id,this.name)):console.warn(`${o(this.gridElement.id,this.name)} ${e}`)}throwDiagnostic(e,t){throw new Error(n(e,t,this.gridElement.id,this.name))}}function f(e){return"__tbw_expander"===e.field}function w(e){return!0===e.utility}function b(e){return{startRow:Math.min(e.startRow,e.endRow),startCol:Math.min(e.startCol,e.endCol),endRow:Math.max(e.startRow,e.endRow),endCol:Math.max(e.startCol,e.endCol)}}function m(e){const t=b(e);return{from:{row:t.startRow,col:t.startCol},to:{row:t.endRow,col:t.endCol}}}function p(e){return e.map(m)}function v(e,t,r){return r.some(r=>function(e,t,r){const s=b(r);return e>=s.startRow&&e<=s.endRow&&t>=s.startCol&&t<=s.endCol}(e,t,r))}function S(e){const t=[],r=b(e);for(let s=r.startRow;s<=r.endRow;s++)for(let e=r.startCol;e<=r.endCol;e++)t.push({row:s,col:e});return t}function y(e,t){return{startRow:e.row,startCol:e.col,endRow:t.row,endCol:t.col}}function C(e,t){const r=b(e),s=b(t);return r.startRow===s.startRow&&r.startCol===s.startCol&&r.endRow===s.endRow&&r.endCol===s.endCol}const R="__tbw_checkbox";class A extends g{static manifest={queries:[{type:"getSelection",description:"Get the current selection state"},{type:"selectRows",description:"Select specific rows by index (row mode only)"},{type:"getSelectedRowIndices",description:"Get sorted array of selected row indices"},{type:"getSelectedRows",description:"Get actual row objects for the current selection (works in all modes)"}],configRules:[{id:"selection/range-dblclick",severity:"warn",message:'"triggerOn: \'dblclick\'" has no effect when mode is "range".\n → Range selection uses drag interaction (mousedown → mousemove), not click events.\n → The "triggerOn" option only affects "cell" and "row" selection modes.',check:e=>"range"===e.mode&&"dblclick"===e.triggerOn}]};name="selection";styles='@layer tbw-plugins{tbw-grid.selecting .data-grid-row>.cell{-webkit-user-select:none;user-select:none}tbw-grid:has(.selection){-webkit-user-select:none;user-select:none}tbw-grid:has(.selection)[data-selection-mode=row] .cell-focus,tbw-grid:has(.selection)[data-selection-mode=row] .row-focus,tbw-grid:has(.selection)[data-selection-mode=range] .cell-focus{outline:none}tbw-grid .data-grid-row.row-focus{background-color:var(--tbw-focus-background, rgba(from var(--tbw-color-accent) r g b / 12%));outline:none;position:relative}tbw-grid .data-grid-row.row-focus:after{content:"";position:absolute;inset:0;pointer-events:none;border-width:0;border-style:var(--tbw-selection-border-style, var(--tbw-border-style));border-color:var(--tbw-range-border-color, var(--tbw-color-accent));border-top-width:var(--tbw-selection-border-width, var(--tbw-border-width));border-bottom-width:var(--tbw-selection-border-width, var(--tbw-border-width));z-index:26}tbw-grid .data-grid-row.row-focus+.data-grid-row.row-focus:after{border-top-width:0}tbw-grid .data-grid-row.row-focus:has(+.data-grid-row.row-focus):after{border-bottom-width:0}tbw-grid .data-grid-row.row-focus>.cell.sticky-left,tbw-grid .data-grid-row.row-focus>.cell.sticky-right{background:linear-gradient(var(--tbw-focus-background, rgba(from var(--tbw-color-accent) r g b / 12%)) 0 0),var(--tbw-color-panel-bg)}tbw-grid .data-grid-row.row-focus[data-selectable=false]>.cell.sticky-left,tbw-grid .data-grid-row.row-focus[data-selectable=false]>.cell.sticky-right{background:var(--tbw-color-row-alt)}tbw-grid .data-grid-row>.cell.selected{background-color:var(--tbw-range-selection-bg);position:relative}tbw-grid .data-grid-row>.cell.selected:after{content:"";position:absolute;inset:0;pointer-events:none;border:0 var(--tbw-selection-border-style, var(--tbw-border-style)) var(--tbw-range-border-color);z-index:1}tbw-grid .data-grid-row>.cell.selected.top:after{border-top-width:var(--tbw-selection-border-width, var(--tbw-border-width))}tbw-grid .data-grid-row>.cell.selected.bottom:after{border-bottom-width:var(--tbw-selection-border-width, var(--tbw-border-width))}tbw-grid .data-grid-row>.cell.selected.first:after{border-left-width:var(--tbw-selection-border-width, var(--tbw-border-width))}tbw-grid .data-grid-row>.cell.selected.last:after{border-right-width:var(--tbw-selection-border-width, var(--tbw-border-width))}tbw-grid .data-grid-row[data-selectable=false]{cursor:not-allowed;opacity:.6}tbw-grid .data-grid-row[data-selectable=false].row-focus{background-color:var(--tbw-color-row-alt)}tbw-grid .data-grid-row>.cell[data-selectable=false]{cursor:not-allowed;opacity:.6}tbw-grid .data-grid-row>.cell[data-selectable=false].selected{background-color:var(--tbw-selection-warning-bg, rgba(from var(--tbw-color-error) r g b / 50%))}tbw-grid .tbw-selection-summary{font-size:var(--tbw-font-size-sm, .8125rem);color:var(--tbw-color-fg-muted);white-space:nowrap}tbw-grid .data-grid-row>.cell[data-field=__tbw_checkbox],tbw-grid .header-row>.cell[data-field=__tbw_checkbox]{text-align:center;cursor:pointer;padding:0;display:flex;align-items:center;justify-content:center}tbw-grid .tbw-select-row-checkbox{pointer-events:none;margin:0;cursor:pointer}tbw-grid .tbw-checkbox-header{display:flex;justify-content:center;align-items:center;height:100%}tbw-grid .tbw-select-all-checkbox{margin:0;cursor:pointer}}';get defaultConfig(){return{mode:"cell",triggerOn:"click",enabled:!0,multiSelect:!0}}selected=/* @__PURE__ */new Set;lastSelected=null;anchor=null;ranges=[];activeRange=null;cellAnchor=null;isDragging=!1;pendingKeyboardUpdate=null;pendingRowKeyUpdate=null;selectedCell=null;lastSyncedFocusRow=-1;lastSyncedFocusCol=-1;announceTimer=null;explicitSelection=!1;isSelectionEnabled(){return!1!==this.config.enabled&&!1!==this.grid.effectiveConfig?.selectable}checkSelectable(e,t){const{isSelectable:r}=this.config;if(!r)return!0;const s=this.rows[e];if(!s)return!1;return r(s,e,void 0!==t?this.visibleColumns[t]:void 0,t)}isRowSelectable(e){return this.checkSelectable(e)}isCellSelectable(e,t){return this.checkSelectable(e,t)}attach(e){super.attach(e),this.on("filter-change",()=>this.clearSelectionSilent()),this.on("group-toggle",()=>this.clearSelectionSilent()),this.on("tree-expand",()=>this.clearSelectionSilent()),this.on("sort-change",()=>this.clearSelectionSilent())}handleQuery(e){return"getSelection"===e.type?this.getSelection():"getSelectedRowIndices"===e.type?this.getSelectedRowIndices():"getSelectedRows"===e.type?this.getSelectedRows():"selectRows"===e.type?(this.selectRows(e.context),!0):void 0}detach(){const e=this.gridElement?.querySelector(".rows-body");e?.removeAttribute("aria-multiselectable"),this.selected.clear(),this.ranges=[],this.activeRange=null,this.cellAnchor=null,this.isDragging=!1,this.selectedCell=null,this.pendingKeyboardUpdate=null,this.pendingRowKeyUpdate=null,this.lastSyncedFocusRow=-1,this.lastSyncedFocusCol=-1}clearSelectionSilent(){this.selected.clear(),this.ranges=[],this.activeRange=null,this.cellAnchor=null,this.selectedCell=null,this.lastSelected=null,this.anchor=null,this.lastSyncedFocusRow=-1,this.lastSyncedFocusCol=-1,this.requestAfterRender()}onCellClick(e){if(!this.isSelectionEnabled())return!1;const{rowIndex:t,colIndex:r,originalEvent:s}=e,{mode:i,triggerOn:o="click"}=this.config;if(s.type!==o)return!1;const n=e.column,l=n&&w(n);if("cell"===i){if(l)return!1;if(!this.isCellSelectable(t,r))return!1;const e=this.selectedCell;return e&&e.row===t&&e.col===r||(this.selectedCell={row:t,col:r},this.emit("selection-change",this.#r()),this.requestAfterRender()),!1}if("row"===i){if(!this.isRowSelectable(t))return!1;const e=!1!==this.config.multiSelect,r=s.shiftKey&&e,i=(s.ctrlKey||s.metaKey)&&e,o=!0===n?.checkboxColumn;if(r&&null!==this.anchor){const e=Math.min(this.anchor,t),r=Math.max(this.anchor,t);i||this.selected.clear();for(let t=e;t<=r;t++)this.isRowSelectable(t)&&this.selected.add(t)}else if(i||o&&e)this.selected.has(t)?this.selected.delete(t):this.selected.add(t),this.anchor=t;else{if(1===this.selected.size&&this.selected.has(t))return!1;this.selected.clear(),this.selected.add(t),this.anchor=t}return this.lastSelected=t,this.explicitSelection=!0,this.emit("selection-change",this.#r()),this.requestAfterRender(),!1}if("range"===i){if(l)return!1;if(!this.isCellSelectable(t,r))return!1;const e=s.shiftKey,i=(s.ctrlKey||s.metaKey)&&!1!==this.config.multiSelect;if(e&&this.cellAnchor){const e=y(this.cellAnchor,{row:t,col:r}),s=this.ranges.length>0?this.ranges[this.ranges.length-1]:null;if(s&&C(s,e))return!1;i?this.ranges.length>0?this.ranges[this.ranges.length-1]=e:this.ranges.push(e):this.ranges=[e],this.activeRange=e}else if(i){const e={startRow:t,startCol:r,endRow:t,endCol:r};this.ranges.push(e),this.activeRange=e,this.cellAnchor={row:t,col:r}}else{const e={startRow:t,startCol:r,endRow:t,endCol:r};if(1===this.ranges.length&&C(this.ranges[0],e))return!1;this.ranges=[e],this.activeRange=e,this.cellAnchor={row:t,col:r}}return this.emit("selection-change",this.#r()),this.requestAfterRender(),!1}return!1}onKeyDown(e){if(!this.isSelectionEnabled())return!1;const{mode:t}=this.config,r=["ArrowUp","ArrowDown","ArrowLeft","ArrowRight","Tab","Home","End","PageUp","PageDown"].includes(e.key);if("Escape"===e.key){return!this.grid.query("isEditing").some(Boolean)&&("cell"===t?this.selectedCell=null:"row"===t?(this.selected.clear(),this.anchor=null):"range"===t&&(this.ranges=[],this.activeRange=null,this.cellAnchor=null),this.emit("selection-change",this.#r()),this.requestAfterRender(),!0)}if("cell"===t&&r)return queueMicrotask(()=>{const e=this.grid._focusRow,t=this.grid._focusCol;this.isCellSelectable(e,t)?this.selectedCell={row:e,col:t}:this.selectedCell=null,this.emit("selection-change",this.#r()),this.requestAfterRender()}),!1;if("row"===t){const t=!1!==this.config.multiSelect;if("ArrowUp"===e.key||"ArrowDown"===e.key||"PageUp"===e.key||"PageDown"===e.key||(e.ctrlKey||e.metaKey)&&("Home"===e.key||"End"===e.key)){const r=e.shiftKey&&t;return r&&null===this.anchor&&(this.anchor=this.grid._focusRow),this.explicitSelection=!0,this.pendingRowKeyUpdate={shiftKey:r},queueMicrotask(()=>this.requestAfterRender()),!1}if(t&&"a"===e.key&&(e.ctrlKey||e.metaKey)){return!this.grid.query("isEditing").some(Boolean)&&(e.preventDefault(),e.stopPropagation(),this.selectAll(),!0)}}if("range"===t&&r){const t="Tab"===e.key,r=e.shiftKey&&!t;return r&&!this.cellAnchor&&(this.cellAnchor={row:this.grid._focusRow,col:this.grid._focusCol}),this.pendingKeyboardUpdate={shiftKey:r},queueMicrotask(()=>this.requestAfterRender()),!1}if("range"===t&&!1!==this.config.multiSelect&&"a"===e.key&&(e.ctrlKey||e.metaKey)){return!this.grid.query("isEditing").some(Boolean)&&(e.preventDefault(),e.stopPropagation(),this.selectAll(),!0)}return!1}onCellMouseDown(e){if(!this.isSelectionEnabled())return;if("range"!==this.config.mode)return;if(void 0===e.rowIndex||void 0===e.colIndex)return;if(e.rowIndex<0)return;if(e.column&&w(e.column))return;if(!this.isCellSelectable(e.rowIndex,e.colIndex))return;if(e.originalEvent.shiftKey&&this.cellAnchor)return;this.isDragging=!0;const t=e.rowIndex,r=e.colIndex,s=(e.originalEvent.ctrlKey||e.originalEvent.metaKey)&&!1!==this.config.multiSelect,i={startRow:t,startCol:r,endRow:t,endCol:r};return!s&&1===this.ranges.length&&C(this.ranges[0],i)?(this.cellAnchor={row:t,col:r},!0):(this.cellAnchor={row:t,col:r},s||(this.ranges=[]),this.ranges.push(i),this.activeRange=i,this.emit("selection-change",this.#r()),this.requestAfterRender(),!0)}onCellMouseMove(e){if(!this.isSelectionEnabled())return;if("range"!==this.config.mode)return;if(!this.isDragging||!this.cellAnchor)return;if(void 0===e.rowIndex||void 0===e.colIndex)return;if(e.rowIndex<0)return;let t=e.colIndex;const r=this.visibleColumns[t];if(r&&w(r)){const e=this.visibleColumns.findIndex(e=>!w(e));e>=0&&(t=e)}const s=y(this.cellAnchor,{row:e.rowIndex,col:t}),i=this.ranges.length>0?this.ranges[this.ranges.length-1]:null;return i&&C(i,s)||(this.ranges.length>0?this.ranges[this.ranges.length-1]=s:this.ranges.push(s),this.activeRange=s,this.emit("selection-change",this.#r()),this.requestAfterRender()),!0}onCellMouseUp(e){if(this.isSelectionEnabled()&&"range"===this.config.mode)return this.isDragging?(this.isDragging=!1,!0):void 0}processColumns(e){if(this.config.checkbox&&"row"===this.config.mode){if(e.some(e=>e.field===R))return e;const t=this.#s(),r=e.findIndex(f),s=r>=0?r+1:0;return[...e.slice(0,s),t,...e.slice(s)]}return e}#s(){return{field:R,header:"",width:32,resizable:!1,sortable:!1,lockPosition:!0,utility:!0,checkboxColumn:!0,headerRenderer:()=>{const e=document.createElement("div");if(e.className="tbw-checkbox-header",!1===this.config.multiSelect)return e;const t=document.createElement("input");return t.type="checkbox",t.className="tbw-select-all-checkbox",t.addEventListener("click",e=>{e.stopPropagation(),e.target.checked?this.selectAll():this.clearSelection()}),e.appendChild(t),e},renderer:e=>{const t=document.createElement("input");t.type="checkbox",t.className="tbw-select-row-checkbox";const r=e.cellEl;if(r){const e=parseInt(r.getAttribute("data-row")??"-1",10);e>=0&&(t.checked=this.selected.has(e))}return t}}}#i(e){e.querySelectorAll(".tbw-select-row-checkbox").forEach(e=>{const t=e.closest(".cell"),r=t?s(t):-1;r>=0&&(e.checked=this.selected.has(r))});const t=e.querySelector(".tbw-select-all-checkbox");if(t){const e=this.rows.length;let r=0;if(this.config.isSelectable)for(let t=0;t<e;t++)this.isRowSelectable(t)&&r++;else r=e;const s=r>0&&this.selected.size>=r,i=this.selected.size>0;t.checked=s,t.indeterminate=i&&!s}}#o(e){const t=this.grid._focusRow,r=this.grid._focusCol;if("row"===e){if(this.explicitSelection)return this.explicitSelection=!1,void(this.lastSyncedFocusRow=t);t!==this.lastSyncedFocusRow&&(this.lastSyncedFocusRow=t,this.isRowSelectable(t)&&(this.selected.has(t)&&1===this.selected.size||(this.selected.clear(),this.selected.add(t),this.lastSelected=t,this.anchor=t,this.emit("selection-change",this.#r()))))}if("cell"===e){if(this.explicitSelection)return this.explicitSelection=!1,this.lastSyncedFocusRow=t,void(this.lastSyncedFocusCol=r);if((t!==this.lastSyncedFocusRow||r!==this.lastSyncedFocusCol)&&(this.lastSyncedFocusRow=t,this.lastSyncedFocusCol=r,this.isCellSelectable(t,r))){const e=this.selectedCell;e&&e.row===t&&e.col===r||(this.selectedCell={row:t,col:r},this.emit("selection-change",this.#r()))}}}#n(){const t=this.gridElement;if(!t)return;const{mode:r}=this.config,o=!!this.config.isSelectable,n=t.querySelector(".rows-body");if(n){const e=!1!==this.config.multiSelect;n.setAttribute("aria-multiselectable",e?"true":"false")}t.querySelectorAll(".cell").forEach(t=>{t.classList.remove(e,"top","bottom","first","last"),o&&t.removeAttribute("data-selectable")});const l=t.querySelectorAll(".data-grid-row");if(l.forEach(t=>{t.classList.remove(e,"row-focus"),t.setAttribute("aria-selected","false"),o&&t.removeAttribute("data-selectable")}),"row"===r&&(i(t),l.forEach(t=>{const r=s(t.querySelector(".cell[data-row]"));r>=0&&(o&&!this.isRowSelectable(r)&&t.setAttribute("data-selectable","false"),this.selected.has(r)&&(t.classList.add(e,"row-focus"),t.setAttribute("aria-selected","true")))}),this.config.checkbox&&this.#i(t)),("cell"===r||"range"===r)&&o){t.querySelectorAll(".cell[data-row][data-col]").forEach(e=>{const t=parseInt(e.getAttribute("data-row")??"-1",10),r=parseInt(e.getAttribute("data-col")??"-1",10);t>=0&&r>=0&&(this.isCellSelectable(t,r)||e.setAttribute("data-selectable","false"))})}if("range"===r&&this.ranges.length>0){i(t);const r=this.ranges.map(b),s=(e,t)=>{for(const s of r)if(e>=s.startRow&&e<=s.endRow&&t>=s.startCol&&t<=s.endCol)return!0;return!1};t.querySelectorAll(".cell[data-row][data-col]").forEach(t=>{const r=parseInt(t.getAttribute("data-row")??"-1",10),i=parseInt(t.getAttribute("data-col")??"-1",10);if(r>=0&&i>=0){const o=this.visibleColumns[i];if(o&&w(o))return;s(r,i)&&(t.classList.add(e),t.setAttribute("aria-selected","true"),s(r-1,i)||t.classList.add("top"),s(r+1,i)||t.classList.add("bottom"),s(r,i-1)||t.classList.add("first"),s(r,i+1)||t.classList.add("last"))}})}}afterRender(){if(!this.isSelectionEnabled())return;const e=this.gridElement;if(!e)return;const t=e.querySelector(".tbw-grid-root"),{mode:r}=this.config;if(this.pendingRowKeyUpdate&&"row"===r){const{shiftKey:e}=this.pendingRowKeyUpdate;this.pendingRowKeyUpdate=null;const t=this.grid._focusRow;if(e&&null!==this.anchor){this.selected.clear();const e=Math.min(this.anchor,t),r=Math.max(this.anchor,t);for(let t=e;t<=r;t++)this.isRowSelectable(t)&&this.selected.add(t)}else this.isRowSelectable(t)?(this.selected.clear(),this.selected.add(t),this.anchor=t):this.selected.clear();this.lastSelected=t,this.emit("selection-change",this.#r())}if(this.pendingKeyboardUpdate&&"range"===r){const{shiftKey:e}=this.pendingKeyboardUpdate;this.pendingKeyboardUpdate=null;const t=this.grid._focusRow,r=this.grid._focusCol;if(e&&this.cellAnchor){const e=y(this.cellAnchor,{row:t,col:r});this.ranges=[e],this.activeRange=e}else e||(this.ranges=[],this.activeRange=null,this.cellAnchor={row:t,col:r});this.emit("selection-change",this.#r())}this.#o(r),this.gridElement.setAttribute("data-selection-mode",r),t&&t.classList.toggle("selecting",this.isDragging),this.#n()}onScrollRender(){this.isSelectionEnabled()&&this.#n()}getSelection(){return{mode:this.config.mode,ranges:this.#r().ranges,anchor:this.cellAnchor}}getSelectedCells(){return function(e){const t=/* @__PURE__ */new Map;for(const r of e)for(const e of S(r))t.set(`${e.row},${e.col}`,e);return[...t.values()]}(this.ranges)}isCellSelected(e,t){return v(e,t,this.ranges)}selectAll(){const{mode:e,multiSelect:t}=this.config;if(!1!==t)if("row"===e){this.selected.clear();for(let e=0;e<this.rows.length;e++)this.isRowSelectable(e)&&this.selected.add(e);this.explicitSelection=!0,this.emit("selection-change",this.#r()),this.requestAfterRender()}else if("range"===e){const e=this.rows.length,t=this.columns.length;if(e>0&&t>0){const r={startRow:0,startCol:0,endRow:e-1,endCol:t-1};this.ranges=[r],this.activeRange=r,this.emit("selection-change",this.#r()),this.requestAfterRender()}}}selectRows(e){if("row"!==this.config.mode)return;const t=!1===this.config.multiSelect&&e.length>1?[e[e.length-1]]:e;this.selected.clear();for(const r of t)r>=0&&r<this.rows.length&&this.isRowSelectable(r)&&this.selected.add(r);this.anchor=t.length>0?t[t.length-1]:null,this.explicitSelection=!0,this.emit("selection-change",this.#r()),this.requestAfterRender()}getSelectedRowIndices(){return[...this.selected].sort((e,t)=>e-t)}getSelectedRows(){const{mode:e}=this.config,t=this.rows;if("row"===e)return this.getSelectedRowIndices().filter(e=>e>=0&&e<t.length).map(e=>t[e]);if("cell"===e&&this.selectedCell){const{row:e}=this.selectedCell;return e>=0&&e<t.length?[t[e]]:[]}if("range"===e&&this.ranges.length>0){const e=/* @__PURE__ */new Set;for(const r of this.ranges){const s=Math.max(0,Math.min(r.startRow,r.endRow)),i=Math.min(t.length-1,Math.max(r.startRow,r.endRow));for(let t=s;t<=i;t++)e.add(t)}return[...e].sort((e,t)=>e-t).map(e=>t[e])}return[]}clearSelection(){this.selectedCell=null,this.selected.clear(),this.anchor=null,this.ranges=[],this.activeRange=null,this.cellAnchor=null,this.emit("selection-change",{mode:this.config.mode,ranges:[]}),this.requestAfterRender()}setRanges(e){this.ranges=e.map(e=>({startRow:e.from.row,startCol:e.from.col,endRow:e.to.row,endCol:e.to.col})),this.activeRange=this.ranges.length>0?this.ranges[this.ranges.length-1]:null,this.emit("selection-change",{mode:this.config.mode,ranges:p(this.ranges)}),this.requestAfterRender()}#r(){const e=function(e,t,r){if("cell"===e&&t.selectedCell)return{mode:e,ranges:[{from:{row:t.selectedCell.row,col:t.selectedCell.col},to:{row:t.selectedCell.row,col:t.selectedCell.col}}]};if("row"===e&&t.selected.size>0){const s=[...t.selected].sort((e,t)=>e-t),i=[];let o=s[0],n=o;for(let e=1;e<s.length;e++)s[e]===n+1?n=s[e]:(i.push({from:{row:o,col:0},to:{row:n,col:r-1}}),o=s[e],n=o);return i.push({from:{row:o,col:0},to:{row:n,col:r-1}}),{mode:e,ranges:i}}return"range"===e&&t.ranges.length>0?{mode:e,ranges:p(t.ranges)}:{mode:e,ranges:[]}}(this.config.mode,{selectedCell:this.selectedCell,selected:this.selected,ranges:this.ranges},this.columns.length);return this.announceTimer&&clearTimeout(this.announceTimer),this.announceTimer=setTimeout(()=>{const r="row"===e.mode?this.selected.size:e.ranges.length;r>0&&function(e,t){if(!e)return;const r="effectiveConfig"in e?e.effectiveConfig:void 0;if(!1===r?.a11y?.announcements)return;const s=e.querySelector?.(".tbw-sr-only");s&&(s.textContent="",requestAnimationFrame(()=>{s.textContent=t}))}(this.gridElement,function(e,r,...s){const i=e&&"effectiveConfig"in e?e.effectiveConfig:void 0,o=i?.a11y?.messages?.[r];return o?o(...s):t[r](...s)}(this.gridElement,"selectionChanged",r))},150),e}}export{A as SelectionPlugin};
|
|
2
2
|
//# sourceMappingURL=index.js.map
|