@toolbox-web/grid 1.21.0 → 1.21.2
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.js +2 -6850
- package/all.js.map +1 -1
- package/index.js +1 -4352
- package/index.js.map +1 -1
- package/lib/core/grid.d.ts +22 -6
- package/lib/core/grid.d.ts.map +1 -1
- package/lib/core/styles/index.d.ts.map +1 -1
- package/lib/plugins/clipboard/index.js +1 -733
- package/lib/plugins/clipboard/index.js.map +1 -1
- package/lib/plugins/column-virtualization/index.js +1 -560
- package/lib/plugins/column-virtualization/index.js.map +1 -1
- package/lib/plugins/context-menu/index.js +1 -754
- package/lib/plugins/context-menu/index.js.map +1 -1
- package/lib/plugins/editing/EditingPlugin.d.ts.map +1 -1
- package/lib/plugins/editing/index.d.ts +1 -1
- package/lib/plugins/editing/index.d.ts.map +1 -1
- package/lib/plugins/editing/index.js +1 -1539
- package/lib/plugins/editing/index.js.map +1 -1
- package/lib/plugins/editing/types.d.ts +23 -0
- package/lib/plugins/editing/types.d.ts.map +1 -1
- package/lib/plugins/export/index.js +1 -589
- package/lib/plugins/export/index.js.map +1 -1
- package/lib/plugins/filtering/FilteringPlugin.d.ts.map +1 -1
- package/lib/plugins/filtering/filter-model.d.ts.map +1 -1
- package/lib/plugins/filtering/index.js +1 -1283
- package/lib/plugins/filtering/index.js.map +1 -1
- package/lib/plugins/filtering/types.d.ts +4 -2
- package/lib/plugins/filtering/types.d.ts.map +1 -1
- package/lib/plugins/grouping-columns/index.js +1 -726
- package/lib/plugins/grouping-columns/index.js.map +1 -1
- package/lib/plugins/grouping-rows/index.js +2 -905
- package/lib/plugins/grouping-rows/index.js.map +1 -1
- package/lib/plugins/master-detail/index.js +1 -950
- package/lib/plugins/master-detail/index.js.map +1 -1
- package/lib/plugins/multi-sort/index.js +1 -553
- package/lib/plugins/multi-sort/index.js.map +1 -1
- package/lib/plugins/pinned-columns/index.js +1 -688
- package/lib/plugins/pinned-columns/index.js.map +1 -1
- package/lib/plugins/pinned-rows/index.js +1 -704
- package/lib/plugins/pinned-rows/index.js.map +1 -1
- package/lib/plugins/pivot/index.js +1 -1191
- package/lib/plugins/pivot/index.js.map +1 -1
- package/lib/plugins/print/index.js +1 -691
- package/lib/plugins/print/index.js.map +1 -1
- package/lib/plugins/reorder/index.js +1 -703
- package/lib/plugins/reorder/index.js.map +1 -1
- package/lib/plugins/responsive/index.js +1 -971
- package/lib/plugins/responsive/index.js.map +1 -1
- package/lib/plugins/row-reorder/index.js +1 -728
- package/lib/plugins/row-reorder/index.js.map +1 -1
- package/lib/plugins/selection/index.js +1 -1071
- package/lib/plugins/selection/index.js.map +1 -1
- package/lib/plugins/server-side/index.js +1 -521
- package/lib/plugins/server-side/index.js.map +1 -1
- package/lib/plugins/tree/index.js +1 -686
- package/lib/plugins/tree/index.js.map +1 -1
- package/lib/plugins/undo-redo/index.js +1 -584
- package/lib/plugins/undo-redo/index.js.map +1 -1
- package/lib/plugins/visibility/index.js +1 -792
- package/lib/plugins/visibility/index.js.map +1 -1
- package/package.json +4 -5
- package/umd/grid.all.umd.js +1 -186
- package/umd/grid.all.umd.js.map +1 -1
- package/umd/grid.umd.js +1 -90
- package/umd/grid.umd.js.map +1 -1
- package/umd/plugins/clipboard.umd.js +1 -6
- package/umd/plugins/clipboard.umd.js.map +1 -1
- package/umd/plugins/column-virtualization.umd.js +1 -1
- package/umd/plugins/column-virtualization.umd.js.map +1 -1
- package/umd/plugins/context-menu.umd.js +1 -1
- package/umd/plugins/context-menu.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/export.umd.js +1 -13
- 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/grouping-columns.umd.js +1 -1
- package/umd/plugins/grouping-columns.umd.js.map +1 -1
- package/umd/plugins/grouping-rows.umd.js +1 -4
- package/umd/plugins/grouping-rows.umd.js.map +1 -1
- package/umd/plugins/master-detail.umd.js +1 -1
- package/umd/plugins/master-detail.umd.js.map +1 -1
- package/umd/plugins/multi-sort.umd.js +1 -1
- package/umd/plugins/multi-sort.umd.js.map +1 -1
- package/umd/plugins/pinned-columns.umd.js +1 -1
- package/umd/plugins/pinned-columns.umd.js.map +1 -1
- package/umd/plugins/pinned-rows.umd.js +1 -1
- package/umd/plugins/pinned-rows.umd.js.map +1 -1
- package/umd/plugins/pivot.umd.js +1 -1
- package/umd/plugins/pivot.umd.js.map +1 -1
- package/umd/plugins/print.umd.js +1 -75
- package/umd/plugins/print.umd.js.map +1 -1
- package/umd/plugins/reorder.umd.js +1 -1
- package/umd/plugins/reorder.umd.js.map +1 -1
- package/umd/plugins/responsive.umd.js +1 -1
- package/umd/plugins/responsive.umd.js.map +1 -1
- package/umd/plugins/row-reorder.umd.js +1 -1
- package/umd/plugins/row-reorder.umd.js.map +1 -1
- package/umd/plugins/selection.umd.js +1 -3
- 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
- package/umd/plugins/undo-redo.umd.js +1 -1
- package/umd/plugins/undo-redo.umd.js.map +1 -1
- package/umd/plugins/visibility.umd.js +1 -1
- package/umd/plugins/visibility.umd.js.map +1 -1
|
@@ -1,727 +1,2 @@
|
|
|
1
|
-
const g = '<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>', p = {
|
|
2
|
-
expand: "▶",
|
|
3
|
-
collapse: "▼",
|
|
4
|
-
sortAsc: "▲",
|
|
5
|
-
sortDesc: "▼",
|
|
6
|
-
sortNone: "⇅",
|
|
7
|
-
submenuArrow: "▶",
|
|
8
|
-
dragHandle: "⋮⋮",
|
|
9
|
-
toolPanel: "☰",
|
|
10
|
-
filter: g,
|
|
11
|
-
filterActive: g,
|
|
12
|
-
print: "🖨️"
|
|
13
|
-
};
|
|
14
|
-
class f {
|
|
15
|
-
/**
|
|
16
|
-
* Plugin dependencies - declare other plugins this one requires.
|
|
17
|
-
*
|
|
18
|
-
* Dependencies are validated when the plugin is attached.
|
|
19
|
-
* Required dependencies throw an error if missing.
|
|
20
|
-
* Optional dependencies log an info message if missing.
|
|
21
|
-
*
|
|
22
|
-
* @example
|
|
23
|
-
* ```typescript
|
|
24
|
-
* static readonly dependencies: PluginDependency[] = [
|
|
25
|
-
* { name: 'editing', required: true, reason: 'Tracks cell edits for undo/redo' },
|
|
26
|
-
* { name: 'selection', required: false, reason: 'Enables selection-based undo' },
|
|
27
|
-
* ];
|
|
28
|
-
* ```
|
|
29
|
-
*/
|
|
30
|
-
static dependencies;
|
|
31
|
-
/**
|
|
32
|
-
* Plugin manifest - declares owned properties, config rules, and hook priorities.
|
|
33
|
-
*
|
|
34
|
-
* This is read by the configuration validator to:
|
|
35
|
-
* - Validate that required plugins are loaded when their properties are used
|
|
36
|
-
* - Execute configRules to detect invalid/conflicting settings
|
|
37
|
-
* - Order hook execution based on priority
|
|
38
|
-
*
|
|
39
|
-
* @example
|
|
40
|
-
* ```typescript
|
|
41
|
-
* static override readonly manifest: PluginManifest<MyConfig> = {
|
|
42
|
-
* ownedProperties: [
|
|
43
|
-
* { property: 'myProp', level: 'column', description: 'the "myProp" column property' },
|
|
44
|
-
* ],
|
|
45
|
-
* configRules: [
|
|
46
|
-
* { id: 'myPlugin/conflict', severity: 'warn', message: '...', check: (c) => c.a && c.b },
|
|
47
|
-
* ],
|
|
48
|
-
* };
|
|
49
|
-
* ```
|
|
50
|
-
*/
|
|
51
|
-
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
52
|
-
static manifest;
|
|
53
|
-
/**
|
|
54
|
-
* Plugin version - defaults to grid version for built-in plugins.
|
|
55
|
-
* Third-party plugins can override with their own semver.
|
|
56
|
-
*/
|
|
57
|
-
version = typeof __GRID_VERSION__ < "u" ? __GRID_VERSION__ : "dev";
|
|
58
|
-
/** CSS styles to inject into the grid's shadow DOM */
|
|
59
|
-
styles;
|
|
60
|
-
/** Custom cell renderers keyed by type name */
|
|
61
|
-
cellRenderers;
|
|
62
|
-
/** Custom header renderers keyed by type name */
|
|
63
|
-
headerRenderers;
|
|
64
|
-
/** Custom cell editors keyed by type name */
|
|
65
|
-
cellEditors;
|
|
66
|
-
/** The grid instance this plugin is attached to */
|
|
67
|
-
grid;
|
|
68
|
-
/** Plugin configuration - merged with defaults in attach() */
|
|
69
|
-
config;
|
|
70
|
-
/** User-provided configuration from constructor */
|
|
71
|
-
userConfig;
|
|
72
|
-
/**
|
|
73
|
-
* Plugin-level AbortController for event listener cleanup.
|
|
74
|
-
* Created fresh in attach(), aborted in detach().
|
|
75
|
-
* This ensures event listeners are properly cleaned up when plugins are re-attached.
|
|
76
|
-
*/
|
|
77
|
-
#e;
|
|
78
|
-
/**
|
|
79
|
-
* Default configuration - subclasses should override this getter.
|
|
80
|
-
* Note: This must be a getter (not property initializer) for proper inheritance
|
|
81
|
-
* since property initializers run after parent constructor.
|
|
82
|
-
*/
|
|
83
|
-
get defaultConfig() {
|
|
84
|
-
return {};
|
|
85
|
-
}
|
|
86
|
-
constructor(e = {}) {
|
|
87
|
-
this.userConfig = e;
|
|
88
|
-
}
|
|
89
|
-
/**
|
|
90
|
-
* Called when the plugin is attached to a grid.
|
|
91
|
-
* Override to set up event listeners, initialize state, etc.
|
|
92
|
-
*
|
|
93
|
-
* @example
|
|
94
|
-
* ```ts
|
|
95
|
-
* attach(grid: GridElement): void {
|
|
96
|
-
* super.attach(grid);
|
|
97
|
-
* // Set up document-level listeners with auto-cleanup
|
|
98
|
-
* document.addEventListener('keydown', this.handleEscape, {
|
|
99
|
-
* signal: this.disconnectSignal
|
|
100
|
-
* });
|
|
101
|
-
* }
|
|
102
|
-
* ```
|
|
103
|
-
*/
|
|
104
|
-
attach(e) {
|
|
105
|
-
this.#e?.abort(), this.#e = new AbortController(), this.grid = e, this.config = { ...this.defaultConfig, ...this.userConfig };
|
|
106
|
-
}
|
|
107
|
-
/**
|
|
108
|
-
* Called when the plugin is detached from a grid.
|
|
109
|
-
* Override to clean up event listeners, timers, etc.
|
|
110
|
-
*
|
|
111
|
-
* @example
|
|
112
|
-
* ```ts
|
|
113
|
-
* detach(): void {
|
|
114
|
-
* // Clean up any state not handled by disconnectSignal
|
|
115
|
-
* this.selectedRows.clear();
|
|
116
|
-
* this.cache = null;
|
|
117
|
-
* }
|
|
118
|
-
* ```
|
|
119
|
-
*/
|
|
120
|
-
detach() {
|
|
121
|
-
this.#e?.abort(), this.#e = void 0;
|
|
122
|
-
}
|
|
123
|
-
/**
|
|
124
|
-
* Get another plugin instance from the same grid.
|
|
125
|
-
* Use for inter-plugin communication.
|
|
126
|
-
*
|
|
127
|
-
* @example
|
|
128
|
-
* ```ts
|
|
129
|
-
* const selection = this.getPlugin(SelectionPlugin);
|
|
130
|
-
* if (selection) {
|
|
131
|
-
* const selectedRows = selection.getSelectedRows();
|
|
132
|
-
* }
|
|
133
|
-
* ```
|
|
134
|
-
*/
|
|
135
|
-
getPlugin(e) {
|
|
136
|
-
return this.grid?.getPlugin(e);
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Emit a custom event from the grid.
|
|
140
|
-
*/
|
|
141
|
-
emit(e, t) {
|
|
142
|
-
this.grid?.dispatchEvent?.(new CustomEvent(e, { detail: t, bubbles: !0 }));
|
|
143
|
-
}
|
|
144
|
-
/**
|
|
145
|
-
* Emit a cancelable custom event from the grid.
|
|
146
|
-
* @returns `true` if the event was cancelled (preventDefault called), `false` otherwise
|
|
147
|
-
*/
|
|
148
|
-
emitCancelable(e, t) {
|
|
149
|
-
const s = new CustomEvent(e, { detail: t, bubbles: !0, cancelable: !0 });
|
|
150
|
-
return this.grid?.dispatchEvent?.(s), s.defaultPrevented;
|
|
151
|
-
}
|
|
152
|
-
// =========================================================================
|
|
153
|
-
// Event Bus - Plugin-to-Plugin Communication
|
|
154
|
-
// =========================================================================
|
|
155
|
-
/**
|
|
156
|
-
* Subscribe to an event from another plugin.
|
|
157
|
-
* The subscription is automatically cleaned up when this plugin is detached.
|
|
158
|
-
*
|
|
159
|
-
* @category Plugin Development
|
|
160
|
-
* @param eventType - The event type to listen for (e.g., 'filter-change')
|
|
161
|
-
* @param callback - The callback to invoke when the event is emitted
|
|
162
|
-
*
|
|
163
|
-
* @example
|
|
164
|
-
* ```typescript
|
|
165
|
-
* // In attach() or other initialization
|
|
166
|
-
* this.on('filter-change', (detail) => {
|
|
167
|
-
* console.log('Filter changed:', detail);
|
|
168
|
-
* });
|
|
169
|
-
* ```
|
|
170
|
-
*/
|
|
171
|
-
on(e, t) {
|
|
172
|
-
this.grid?._pluginManager?.subscribe(this, e, t);
|
|
173
|
-
}
|
|
174
|
-
/**
|
|
175
|
-
* Unsubscribe from a plugin event.
|
|
176
|
-
*
|
|
177
|
-
* @category Plugin Development
|
|
178
|
-
* @param eventType - The event type to stop listening for
|
|
179
|
-
*
|
|
180
|
-
* @example
|
|
181
|
-
* ```typescript
|
|
182
|
-
* this.off('filter-change');
|
|
183
|
-
* ```
|
|
184
|
-
*/
|
|
185
|
-
off(e) {
|
|
186
|
-
this.grid?._pluginManager?.unsubscribe(this, e);
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* Emit an event to other plugins via the Event Bus.
|
|
190
|
-
* This is for inter-plugin communication only; it does NOT dispatch DOM events.
|
|
191
|
-
* Use `emit()` to dispatch DOM events that external consumers can listen to.
|
|
192
|
-
*
|
|
193
|
-
* @category Plugin Development
|
|
194
|
-
* @param eventType - The event type to emit (should be declared in manifest.events)
|
|
195
|
-
* @param detail - The event payload
|
|
196
|
-
*
|
|
197
|
-
* @example
|
|
198
|
-
* ```typescript
|
|
199
|
-
* // Emit to other plugins (not DOM)
|
|
200
|
-
* this.emitPluginEvent('filter-change', { field: 'name', value: 'Alice' });
|
|
201
|
-
*
|
|
202
|
-
* // For DOM events that consumers can addEventListener to:
|
|
203
|
-
* this.emit('filter-change', { field: 'name', value: 'Alice' });
|
|
204
|
-
* ```
|
|
205
|
-
*/
|
|
206
|
-
emitPluginEvent(e, t) {
|
|
207
|
-
this.grid?._pluginManager?.emitPluginEvent(e, t);
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* Request a re-render of the grid.
|
|
211
|
-
* Uses ROWS phase - does NOT trigger processColumns hooks.
|
|
212
|
-
*/
|
|
213
|
-
requestRender() {
|
|
214
|
-
this.grid?.requestRender?.();
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Request a columns re-render of the grid.
|
|
218
|
-
* Uses COLUMNS phase - triggers processColumns hooks.
|
|
219
|
-
* Use this when your plugin needs to reprocess column configuration.
|
|
220
|
-
*/
|
|
221
|
-
requestColumnsRender() {
|
|
222
|
-
this.grid?.requestColumnsRender?.();
|
|
223
|
-
}
|
|
224
|
-
/**
|
|
225
|
-
* Request a re-render and restore focus styling afterward.
|
|
226
|
-
* Use this when a plugin action (like expand/collapse) triggers a render
|
|
227
|
-
* but needs to maintain keyboard navigation focus.
|
|
228
|
-
*/
|
|
229
|
-
requestRenderWithFocus() {
|
|
230
|
-
this.grid?.requestRenderWithFocus?.();
|
|
231
|
-
}
|
|
232
|
-
/**
|
|
233
|
-
* Request a lightweight style update without rebuilding DOM.
|
|
234
|
-
* Use this instead of requestRender() when only CSS classes need updating.
|
|
235
|
-
*/
|
|
236
|
-
requestAfterRender() {
|
|
237
|
-
this.grid?.requestAfterRender?.();
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
* Get the current rows from the grid.
|
|
241
|
-
*/
|
|
242
|
-
get rows() {
|
|
243
|
-
return this.grid?.rows ?? [];
|
|
244
|
-
}
|
|
245
|
-
/**
|
|
246
|
-
* Get the original unfiltered/unprocessed rows from the grid.
|
|
247
|
-
* Use this when you need all source data regardless of active filters.
|
|
248
|
-
*/
|
|
249
|
-
get sourceRows() {
|
|
250
|
-
return this.grid?.sourceRows ?? [];
|
|
251
|
-
}
|
|
252
|
-
/**
|
|
253
|
-
* Get the current columns from the grid.
|
|
254
|
-
*/
|
|
255
|
-
get columns() {
|
|
256
|
-
return this.grid?.columns ?? [];
|
|
257
|
-
}
|
|
258
|
-
/**
|
|
259
|
-
* Get only visible columns from the grid (excludes hidden).
|
|
260
|
-
* Use this for rendering that needs to match the grid template.
|
|
261
|
-
*/
|
|
262
|
-
get visibleColumns() {
|
|
263
|
-
return this.grid?._visibleColumns ?? [];
|
|
264
|
-
}
|
|
265
|
-
/**
|
|
266
|
-
* Get the grid as an HTMLElement for direct DOM operations.
|
|
267
|
-
* Use sparingly - prefer the typed GridElementRef API when possible.
|
|
268
|
-
*
|
|
269
|
-
* @example
|
|
270
|
-
* ```ts
|
|
271
|
-
* const width = this.gridElement.clientWidth;
|
|
272
|
-
* this.gridElement.classList.add('my-plugin-active');
|
|
273
|
-
* ```
|
|
274
|
-
*/
|
|
275
|
-
get gridElement() {
|
|
276
|
-
return this.grid;
|
|
277
|
-
}
|
|
278
|
-
/**
|
|
279
|
-
* Get the disconnect signal for event listener cleanup.
|
|
280
|
-
* This signal is aborted when the grid disconnects from the DOM.
|
|
281
|
-
* Use this when adding event listeners that should be cleaned up automatically.
|
|
282
|
-
*
|
|
283
|
-
* Best for:
|
|
284
|
-
* - Document/window-level listeners added in attach()
|
|
285
|
-
* - Listeners on the grid element itself
|
|
286
|
-
* - Any listener that should persist across renders
|
|
287
|
-
*
|
|
288
|
-
* Not needed for:
|
|
289
|
-
* - Listeners on elements created in afterRender() (removed with element)
|
|
290
|
-
*
|
|
291
|
-
* @example
|
|
292
|
-
* element.addEventListener('click', handler, { signal: this.disconnectSignal });
|
|
293
|
-
* document.addEventListener('keydown', handler, { signal: this.disconnectSignal });
|
|
294
|
-
*/
|
|
295
|
-
get disconnectSignal() {
|
|
296
|
-
return this.#e?.signal ?? this.grid?.disconnectSignal;
|
|
297
|
-
}
|
|
298
|
-
/**
|
|
299
|
-
* Get the grid-level icons configuration.
|
|
300
|
-
* Returns merged icons (user config + defaults).
|
|
301
|
-
*/
|
|
302
|
-
get gridIcons() {
|
|
303
|
-
const e = this.grid?.gridConfig?.icons ?? {};
|
|
304
|
-
return { ...p, ...e };
|
|
305
|
-
}
|
|
306
|
-
// #region Animation Helpers
|
|
307
|
-
/**
|
|
308
|
-
* Check if animations are enabled at the grid level.
|
|
309
|
-
* Respects gridConfig.animation.mode and the CSS variable set by the grid.
|
|
310
|
-
*
|
|
311
|
-
* Plugins should use this to skip animations when:
|
|
312
|
-
* - Animation mode is 'off' or `false`
|
|
313
|
-
* - User prefers reduced motion and mode is 'reduced-motion' (default)
|
|
314
|
-
*
|
|
315
|
-
* @example
|
|
316
|
-
* ```ts
|
|
317
|
-
* private get animationStyle(): 'slide' | 'fade' | false {
|
|
318
|
-
* if (!this.isAnimationEnabled) return false;
|
|
319
|
-
* return this.config.animation ?? 'slide';
|
|
320
|
-
* }
|
|
321
|
-
* ```
|
|
322
|
-
*/
|
|
323
|
-
get isAnimationEnabled() {
|
|
324
|
-
const e = this.grid?.effectiveConfig?.animation?.mode ?? "reduced-motion";
|
|
325
|
-
if (e === !1 || e === "off") return !1;
|
|
326
|
-
if (e === !0 || e === "on") return !0;
|
|
327
|
-
const t = this.gridElement;
|
|
328
|
-
return t ? getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim() !== "0" : !0;
|
|
329
|
-
}
|
|
330
|
-
/**
|
|
331
|
-
* Get the animation duration in milliseconds from CSS variable.
|
|
332
|
-
* Falls back to 200ms if not set.
|
|
333
|
-
*
|
|
334
|
-
* Plugins can use this for their animation timing to stay consistent
|
|
335
|
-
* with the grid-level animation.duration setting.
|
|
336
|
-
*
|
|
337
|
-
* @example
|
|
338
|
-
* ```ts
|
|
339
|
-
* element.animate(keyframes, { duration: this.animationDuration });
|
|
340
|
-
* ```
|
|
341
|
-
*/
|
|
342
|
-
get animationDuration() {
|
|
343
|
-
const e = this.gridElement;
|
|
344
|
-
if (e) {
|
|
345
|
-
const t = getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(), s = parseInt(t, 10);
|
|
346
|
-
if (!isNaN(s)) return s;
|
|
347
|
-
}
|
|
348
|
-
return 200;
|
|
349
|
-
}
|
|
350
|
-
// #endregion
|
|
351
|
-
/**
|
|
352
|
-
* Resolve an icon value to string or HTMLElement.
|
|
353
|
-
* Checks plugin config first, then grid-level icons, then defaults.
|
|
354
|
-
*
|
|
355
|
-
* @param iconKey - The icon key in GridIcons (e.g., 'expand', 'collapse')
|
|
356
|
-
* @param pluginOverride - Optional plugin-level override
|
|
357
|
-
* @returns The resolved icon value
|
|
358
|
-
*/
|
|
359
|
-
resolveIcon(e, t) {
|
|
360
|
-
return t !== void 0 ? t : this.gridIcons[e];
|
|
361
|
-
}
|
|
362
|
-
/**
|
|
363
|
-
* Set an icon value on an element.
|
|
364
|
-
* Handles both string (text/HTML) and HTMLElement values.
|
|
365
|
-
*
|
|
366
|
-
* @param element - The element to set the icon on
|
|
367
|
-
* @param icon - The icon value (string or HTMLElement)
|
|
368
|
-
*/
|
|
369
|
-
setIcon(e, t) {
|
|
370
|
-
typeof t == "string" ? e.innerHTML = t : t instanceof HTMLElement && (e.innerHTML = "", e.appendChild(t.cloneNode(!0)));
|
|
371
|
-
}
|
|
372
|
-
/**
|
|
373
|
-
* Log a warning message.
|
|
374
|
-
*/
|
|
375
|
-
warn(e) {
|
|
376
|
-
console.warn(`[tbw-grid:${this.name}] ${e}`);
|
|
377
|
-
}
|
|
378
|
-
// #endregion
|
|
379
|
-
}
|
|
380
|
-
function c(d) {
|
|
381
|
-
if (!d.length) return [];
|
|
382
|
-
const e = /* @__PURE__ */ new Map(), t = [], s = (o, n) => {
|
|
383
|
-
if (!n.length) return;
|
|
384
|
-
const l = t[t.length - 1];
|
|
385
|
-
if (l && l.implicit && l.firstIndex + l.columns.length === o) {
|
|
386
|
-
l.columns.push(...n);
|
|
387
|
-
return;
|
|
388
|
-
}
|
|
389
|
-
t.push({
|
|
390
|
-
id: "__implicit__" + o,
|
|
391
|
-
label: void 0,
|
|
392
|
-
columns: n,
|
|
393
|
-
firstIndex: o,
|
|
394
|
-
implicit: !0
|
|
395
|
-
});
|
|
396
|
-
};
|
|
397
|
-
let i = [], r = 0;
|
|
398
|
-
return d.forEach((o, n) => {
|
|
399
|
-
const l = o.group;
|
|
400
|
-
if (!l) {
|
|
401
|
-
i.length === 0 && (r = n), i.push(o);
|
|
402
|
-
return;
|
|
403
|
-
}
|
|
404
|
-
i.length && (s(r, i.slice()), i = []);
|
|
405
|
-
const u = typeof l == "string" ? l : l.id;
|
|
406
|
-
let a = e.get(u);
|
|
407
|
-
a || (a = {
|
|
408
|
-
id: u,
|
|
409
|
-
label: typeof l == "string" ? void 0 : l.label,
|
|
410
|
-
columns: [],
|
|
411
|
-
firstIndex: n
|
|
412
|
-
}, e.set(u, a), t.push(a)), a.columns.push(o);
|
|
413
|
-
}), i.length && s(r, i), t.length === 1 && t[0].implicit && t[0].columns.length === d.length ? [] : t;
|
|
414
|
-
}
|
|
415
|
-
function h(d, e, t) {
|
|
416
|
-
if (!e.length || !d) return;
|
|
417
|
-
const s = /* @__PURE__ */ new Map();
|
|
418
|
-
for (const r of e)
|
|
419
|
-
for (const o of r.columns)
|
|
420
|
-
o.field && s.set(o.field, r.id);
|
|
421
|
-
const i = Array.from(d.querySelectorAll(".cell[data-field]"));
|
|
422
|
-
i.forEach((r) => {
|
|
423
|
-
const o = r.getAttribute("data-field") || "", n = s.get(o);
|
|
424
|
-
n && (r.classList.add("grouped"), r.getAttribute("data-group") || r.setAttribute("data-group", n));
|
|
425
|
-
});
|
|
426
|
-
for (const r of e) {
|
|
427
|
-
const o = r.columns[r.columns.length - 1], n = i.find((l) => l.getAttribute("data-field") === o.field);
|
|
428
|
-
n && n.classList.add("group-end");
|
|
429
|
-
}
|
|
430
|
-
}
|
|
431
|
-
function m(d, e) {
|
|
432
|
-
if (d.length === 0) return null;
|
|
433
|
-
const t = document.createElement("div");
|
|
434
|
-
t.className = "header-group-row", t.setAttribute("role", "row");
|
|
435
|
-
for (const s of d) {
|
|
436
|
-
const i = s.columns[0], r = i ? e.findIndex((u) => u.field === i.field) : -1;
|
|
437
|
-
if (r === -1) continue;
|
|
438
|
-
const o = String(s.id).startsWith("__implicit__"), n = o ? "" : s.label || s.id, l = document.createElement("div");
|
|
439
|
-
l.className = "cell header-group-cell", o && l.classList.add("implicit-group"), l.setAttribute("data-group", String(s.id)), l.style.gridColumn = `${r + 1} / span ${s.columns.length}`, l.textContent = n, t.appendChild(l);
|
|
440
|
-
}
|
|
441
|
-
return t;
|
|
442
|
-
}
|
|
443
|
-
function b(d) {
|
|
444
|
-
return d.some((e) => e.group != null);
|
|
445
|
-
}
|
|
446
|
-
const w = "@layer tbw-plugins{.header-group-row{display:grid;grid-auto-flow:column;background:var(--tbw-grouping-columns-header-bg, var(--tbw-color-header-bg));border-bottom:1px solid var(--tbw-grouping-columns-border, var(--tbw-color-border))}.header-group-cell{display:flex;align-items:center;justify-content:center;padding:var(--tbw-button-padding-sm, .25rem .5rem);font-weight:600;font-size:var(--tbw-font-size-sm, .9em);text-transform:uppercase;letter-spacing:.5px;border-right:2px solid var(--tbw-grouping-columns-separator, var(--tbw-color-border-strong, var(--tbw-color-border)))}.header-group-cell:last-child{border-right:none}.header-row .cell.grouped{border-top:none}.header-row .cell.group-end{border-right:2px solid var(--tbw-grouping-columns-separator, var(--tbw-color-border-strong, var(--tbw-color-border)))}.header-row .cell.group-end:last-child{border-right:none}.rows .cell.group-end{border-right:2px solid var(--tbw-grouping-columns-separator, var(--tbw-color-border-strong, var(--tbw-color-border)))}.rows .cell.group-end:last-child{border-right:none}.header-group-row.no-borders{border-bottom:none}.header-group-row.no-borders .header-group-cell{border-right:none}.header-row.no-group-borders .cell.group-end{border-right:1px solid var(--tbw-color-border)}}";
|
|
447
|
-
class v extends f {
|
|
448
|
-
/**
|
|
449
|
-
* Plugin manifest - declares owned properties for configuration validation.
|
|
450
|
-
* @internal
|
|
451
|
-
*/
|
|
452
|
-
static manifest = {
|
|
453
|
-
ownedProperties: [
|
|
454
|
-
{
|
|
455
|
-
property: "group",
|
|
456
|
-
level: "column",
|
|
457
|
-
description: 'the "group" column property'
|
|
458
|
-
},
|
|
459
|
-
{
|
|
460
|
-
property: "columnGroups",
|
|
461
|
-
level: "config",
|
|
462
|
-
description: 'the "columnGroups" config property',
|
|
463
|
-
isUsed: (e) => Array.isArray(e) && e.length > 0
|
|
464
|
-
}
|
|
465
|
-
],
|
|
466
|
-
queries: [{ type: "getColumnGrouping", description: "Returns column group metadata for the visibility panel" }]
|
|
467
|
-
};
|
|
468
|
-
/** @internal */
|
|
469
|
-
name = "groupingColumns";
|
|
470
|
-
/** @internal */
|
|
471
|
-
styles = w;
|
|
472
|
-
/** @internal */
|
|
473
|
-
get defaultConfig() {
|
|
474
|
-
return {
|
|
475
|
-
showGroupBorders: !0,
|
|
476
|
-
lockGroupOrder: !1
|
|
477
|
-
};
|
|
478
|
-
}
|
|
479
|
-
// #region Internal State
|
|
480
|
-
groups = [];
|
|
481
|
-
isActive = !1;
|
|
482
|
-
/** Fields that are the last column in a group (for group-end border class). */
|
|
483
|
-
#e = /* @__PURE__ */ new Set();
|
|
484
|
-
// #endregion
|
|
485
|
-
// #region Lifecycle
|
|
486
|
-
/** @internal */
|
|
487
|
-
attach(e) {
|
|
488
|
-
super.attach(e), e.addEventListener("column-move", this.#r, {
|
|
489
|
-
signal: this.disconnectSignal
|
|
490
|
-
});
|
|
491
|
-
}
|
|
492
|
-
/** @internal */
|
|
493
|
-
detach() {
|
|
494
|
-
this.groups = [], this.isActive = !1, this.#e.clear();
|
|
495
|
-
}
|
|
496
|
-
// #region Column Move Guard
|
|
497
|
-
/**
|
|
498
|
-
* Handle the cancelable column-move event.
|
|
499
|
-
* - When lockGroupOrder is enabled, prevents moves that would break group contiguity.
|
|
500
|
-
* - Always refreshes #groupEndFields after a successful move so that afterCellRender
|
|
501
|
-
* applies group-end borders to the correct (reordered) last column.
|
|
502
|
-
*/
|
|
503
|
-
#r = (e) => {
|
|
504
|
-
if (!this.isActive) return;
|
|
505
|
-
const t = e, { field: s, columnOrder: i } = t.detail;
|
|
506
|
-
if (this.config.lockGroupOrder) {
|
|
507
|
-
for (const r of this.groups)
|
|
508
|
-
if (!r.id.startsWith("__implicit__") && !this.#i(r, i)) {
|
|
509
|
-
t.preventDefault(), this.#s(s);
|
|
510
|
-
return;
|
|
511
|
-
}
|
|
512
|
-
}
|
|
513
|
-
this.#t(i);
|
|
514
|
-
};
|
|
515
|
-
/**
|
|
516
|
-
* Recompute which fields are group-end based on a column order.
|
|
517
|
-
* The last field of each explicit group in the order gets the group-end class.
|
|
518
|
-
*/
|
|
519
|
-
#t(e) {
|
|
520
|
-
this.#e.clear();
|
|
521
|
-
const t = this.#o(e);
|
|
522
|
-
for (const s of this.groups) {
|
|
523
|
-
const i = new Set(s.columns.map((r) => r.field));
|
|
524
|
-
for (let r = e.length - 1; r >= 0; r--)
|
|
525
|
-
if (i.has(e[r])) {
|
|
526
|
-
const o = e[r];
|
|
527
|
-
o !== t && this.#e.add(o);
|
|
528
|
-
break;
|
|
529
|
-
}
|
|
530
|
-
}
|
|
531
|
-
}
|
|
532
|
-
/**
|
|
533
|
-
* Find the trailing field of the last group in column order (to exclude from group-end marking).
|
|
534
|
-
*/
|
|
535
|
-
#o(e) {
|
|
536
|
-
if (this.groups.length === 0) return null;
|
|
537
|
-
for (let t = e.length - 1; t >= 0; t--) {
|
|
538
|
-
const s = e[t];
|
|
539
|
-
for (const i of this.groups)
|
|
540
|
-
if (i.columns.some((r) => r.field === s)) {
|
|
541
|
-
const r = new Set(i.columns.map((o) => o.field));
|
|
542
|
-
for (let o = e.length - 1; o >= 0; o--)
|
|
543
|
-
if (r.has(e[o])) return e[o];
|
|
544
|
-
}
|
|
545
|
-
}
|
|
546
|
-
return null;
|
|
547
|
-
}
|
|
548
|
-
/**
|
|
549
|
-
* Check if all columns in a group are contiguous in the proposed column order.
|
|
550
|
-
*/
|
|
551
|
-
#i(e, t) {
|
|
552
|
-
const s = e.columns.map((i) => t.indexOf(i.field)).filter((i) => i !== -1).sort((i, r) => i - r);
|
|
553
|
-
return s.length <= 1 ? !0 : s.length === s[s.length - 1] - s[0] + 1;
|
|
554
|
-
}
|
|
555
|
-
/**
|
|
556
|
-
* Flash the header cell with an error color to indicate a blocked move.
|
|
557
|
-
*/
|
|
558
|
-
#s(e) {
|
|
559
|
-
const t = this.gridElement?.querySelector(
|
|
560
|
-
`.header-row [part~="header-cell"][data-field="${e}"]`
|
|
561
|
-
);
|
|
562
|
-
t && (t.style.setProperty("--_flash-color", "var(--tbw-color-error)"), t.animate(
|
|
563
|
-
[{ backgroundColor: "rgba(from var(--_flash-color) r g b / 30%)" }, { backgroundColor: "transparent" }],
|
|
564
|
-
{ duration: 400, easing: "ease-out" }
|
|
565
|
-
));
|
|
566
|
-
}
|
|
567
|
-
// #endregion
|
|
568
|
-
/** @internal */
|
|
569
|
-
handleQuery(e) {
|
|
570
|
-
if (e.type === "getColumnGrouping")
|
|
571
|
-
return this.#n();
|
|
572
|
-
}
|
|
573
|
-
/**
|
|
574
|
-
* Get stable column grouping info that includes ALL columns (visible and hidden).
|
|
575
|
-
* Used by the visibility panel to maintain group structure regardless of visibility state.
|
|
576
|
-
* Fields within each group are sorted by current display order.
|
|
577
|
-
*/
|
|
578
|
-
#n() {
|
|
579
|
-
let e;
|
|
580
|
-
const t = this.grid?.gridConfig?.columnGroups;
|
|
581
|
-
if (t && Array.isArray(t) && t.length > 0)
|
|
582
|
-
e = t.filter((i) => i.children.length > 0).map((i) => ({
|
|
583
|
-
id: i.id,
|
|
584
|
-
label: i.header,
|
|
585
|
-
fields: [...i.children]
|
|
586
|
-
}));
|
|
587
|
-
else if (this.isActive && this.groups.length > 0) {
|
|
588
|
-
e = this.groups.filter((r) => !r.id.startsWith("__implicit__")).map((r) => ({
|
|
589
|
-
id: r.id,
|
|
590
|
-
label: r.label ?? r.id,
|
|
591
|
-
fields: r.columns.map((o) => o.field)
|
|
592
|
-
}));
|
|
593
|
-
const i = this.columns;
|
|
594
|
-
for (const r of i)
|
|
595
|
-
if (r.hidden && r.group) {
|
|
596
|
-
const o = typeof r.group == "string" ? r.group : r.group.id, n = typeof r.group == "string" ? r.group : r.group.label ?? r.group.id, l = e.find((u) => u.id === o);
|
|
597
|
-
l ? l.fields.includes(r.field) || l.fields.push(r.field) : e.push({ id: o, label: n, fields: [r.field] });
|
|
598
|
-
}
|
|
599
|
-
} else {
|
|
600
|
-
const i = this.columns, r = /* @__PURE__ */ new Map();
|
|
601
|
-
for (const o of i) {
|
|
602
|
-
if (!o.group) continue;
|
|
603
|
-
const n = typeof o.group == "string" ? o.group : o.group.id, l = typeof o.group == "string" ? o.group : o.group.label ?? o.group.id, u = r.get(n);
|
|
604
|
-
u ? u.fields.includes(o.field) || u.fields.push(o.field) : r.set(n, { id: n, label: l, fields: [o.field] });
|
|
605
|
-
}
|
|
606
|
-
e = Array.from(r.values());
|
|
607
|
-
}
|
|
608
|
-
const s = this.grid?.getColumnOrder();
|
|
609
|
-
if (s && s.length > 0) {
|
|
610
|
-
const i = new Map(s.map((r, o) => [r, o]));
|
|
611
|
-
for (const r of e)
|
|
612
|
-
r.fields.sort((o, n) => (i.get(o) ?? 1 / 0) - (i.get(n) ?? 1 / 0));
|
|
613
|
-
}
|
|
614
|
-
return e;
|
|
615
|
-
}
|
|
616
|
-
// #endregion
|
|
617
|
-
// #region Static Detection
|
|
618
|
-
/**
|
|
619
|
-
* Auto-detect column groups from column configuration.
|
|
620
|
-
* Detects both inline `column.group` properties and declarative `columnGroups` config.
|
|
621
|
-
*/
|
|
622
|
-
static detect(e, t) {
|
|
623
|
-
if (t?.columnGroups && Array.isArray(t.columnGroups) && t.columnGroups.length > 0)
|
|
624
|
-
return !0;
|
|
625
|
-
const s = t?.columns;
|
|
626
|
-
return Array.isArray(s) ? b(s) : !1;
|
|
627
|
-
}
|
|
628
|
-
// #endregion
|
|
629
|
-
// #region Hooks
|
|
630
|
-
/** @internal */
|
|
631
|
-
processColumns(e) {
|
|
632
|
-
const t = this.grid?.gridConfig?.columnGroups;
|
|
633
|
-
let s;
|
|
634
|
-
if (t && Array.isArray(t) && t.length > 0) {
|
|
635
|
-
const r = /* @__PURE__ */ new Map();
|
|
636
|
-
for (const o of t)
|
|
637
|
-
for (const n of o.children)
|
|
638
|
-
r.set(n, { id: o.id, label: o.header });
|
|
639
|
-
s = e.map((o) => {
|
|
640
|
-
const n = r.get(o.field);
|
|
641
|
-
return n && !o.group ? { ...o, group: n } : o;
|
|
642
|
-
});
|
|
643
|
-
} else
|
|
644
|
-
s = [...e];
|
|
645
|
-
const i = c(s);
|
|
646
|
-
if (i.length === 0)
|
|
647
|
-
return this.isActive = !1, this.groups = [], s;
|
|
648
|
-
this.isActive = !0, this.groups = i, this.#e.clear();
|
|
649
|
-
for (const r of i) {
|
|
650
|
-
const o = r.columns[r.columns.length - 1];
|
|
651
|
-
o?.field && this.#e.add(o.field);
|
|
652
|
-
}
|
|
653
|
-
return s;
|
|
654
|
-
}
|
|
655
|
-
/** @internal */
|
|
656
|
-
afterRender() {
|
|
657
|
-
if (!this.isActive) {
|
|
658
|
-
const l = this.gridElement?.querySelector(".header")?.querySelector(".header-group-row");
|
|
659
|
-
l && l.remove();
|
|
660
|
-
return;
|
|
661
|
-
}
|
|
662
|
-
const e = this.gridElement?.querySelector(".header");
|
|
663
|
-
if (!e) return;
|
|
664
|
-
const t = e.querySelector(".header-group-row");
|
|
665
|
-
t && t.remove();
|
|
666
|
-
const s = this.visibleColumns, i = c(s);
|
|
667
|
-
if (i.length === 0) return;
|
|
668
|
-
this.#e.clear();
|
|
669
|
-
for (let n = 0; n < i.length; n++) {
|
|
670
|
-
const l = i[n], u = l.columns[l.columns.length - 1];
|
|
671
|
-
u?.field && n < i.length - 1 && this.#e.add(u.field);
|
|
672
|
-
}
|
|
673
|
-
const r = m(i, s);
|
|
674
|
-
if (r) {
|
|
675
|
-
r.classList.toggle("no-borders", !this.config.showGroupBorders);
|
|
676
|
-
const n = e.querySelector(".header-row");
|
|
677
|
-
n ? e.insertBefore(r, n) : e.appendChild(r);
|
|
678
|
-
}
|
|
679
|
-
const o = e.querySelector(".header-row");
|
|
680
|
-
o && (o.classList.toggle("no-group-borders", !this.config.showGroupBorders), h(o, i));
|
|
681
|
-
}
|
|
682
|
-
/**
|
|
683
|
-
* Apply group-end class to individual cells during render and scroll.
|
|
684
|
-
* This is more efficient than querySelectorAll in afterRender and ensures
|
|
685
|
-
* cells recycled during scroll also get the class applied.
|
|
686
|
-
* @internal
|
|
687
|
-
*/
|
|
688
|
-
afterCellRender(e) {
|
|
689
|
-
!this.isActive || !this.config.showGroupBorders || e.cellElement.classList.toggle("group-end", this.#e.has(e.column.field));
|
|
690
|
-
}
|
|
691
|
-
// #endregion
|
|
692
|
-
// #region Public API
|
|
693
|
-
/**
|
|
694
|
-
* Check if column groups are active.
|
|
695
|
-
* @returns Whether grouping is active
|
|
696
|
-
*/
|
|
697
|
-
isGroupingActive() {
|
|
698
|
-
return this.isActive;
|
|
699
|
-
}
|
|
700
|
-
/**
|
|
701
|
-
* Get the computed column groups.
|
|
702
|
-
* @returns Array of column groups
|
|
703
|
-
*/
|
|
704
|
-
getGroups() {
|
|
705
|
-
return this.groups;
|
|
706
|
-
}
|
|
707
|
-
/**
|
|
708
|
-
* Get columns in a specific group.
|
|
709
|
-
* @param groupId - The group ID to find
|
|
710
|
-
* @returns Array of columns in the group
|
|
711
|
-
*/
|
|
712
|
-
getGroupColumns(e) {
|
|
713
|
-
const t = this.groups.find((s) => s.id === e);
|
|
714
|
-
return t ? t.columns : [];
|
|
715
|
-
}
|
|
716
|
-
/**
|
|
717
|
-
* Refresh column groups (recompute from current columns).
|
|
718
|
-
*/
|
|
719
|
-
refresh() {
|
|
720
|
-
this.requestRender();
|
|
721
|
-
}
|
|
722
|
-
// #endregion
|
|
723
|
-
}
|
|
724
|
-
export {
|
|
725
|
-
v as GroupingColumnsPlugin
|
|
726
|
-
};
|
|
1
|
+
const e='<svg viewBox="0 0 16 16" width="12" height="12"><path fill="currentColor" d="M6 10.5a.5.5 0 0 1 .5-.5h3a.5.5 0 0 1 0 1h-3a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h7a.5.5 0 0 1 0 1h-7a.5.5 0 0 1-.5-.5zm-2-3a.5.5 0 0 1 .5-.5h11a.5.5 0 0 1 0 1h-11a.5.5 0 0 1-.5-.5z"/></svg>',r={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:e,filterActive:e,print:"🖨️"};class t{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,r){this.grid?.dispatchEvent?.(new CustomEvent(e,{detail:r,bubbles:!0}))}emitCancelable(e,r){const t=new CustomEvent(e,{detail:r,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(t),t.defaultPrevented}on(e,r){this.grid?._pluginManager?.subscribe(this,e,r)}off(e){this.grid?._pluginManager?.unsubscribe(this,e)}emitPluginEvent(e,r){this.grid?._pluginManager?.emitPluginEvent(e,r)}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{...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 r=this.gridElement;if(r){return"0"!==getComputedStyle(r).getPropertyValue("--tbw-animation-enabled").trim()}return!0}get animationDuration(){const e=this.gridElement;if(e){const r=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),t=parseInt(r,10);if(!isNaN(t))return t}return 200}resolveIcon(e,r){return void 0!==r?r:this.gridIcons[e]}setIcon(e,r){"string"==typeof r?e.innerHTML=r:r instanceof HTMLElement&&(e.innerHTML="",e.appendChild(r.cloneNode(!0)))}warn(e){console.warn(`[tbw-grid:${this.name}] ${e}`)}}function o(e){if(!e.length)return[];const r=/* @__PURE__ */new Map,t=[],o=(e,r)=>{if(!r.length)return;const o=t[t.length-1];o&&o.implicit&&o.firstIndex+o.columns.length===e?o.columns.push(...r):t.push({id:"__implicit__"+e,label:void 0,columns:r,firstIndex:e,implicit:!0})};let i=[],n=0;return e.forEach((e,s)=>{const l=e.group;if(!l)return 0===i.length&&(n=s),void i.push(e);i.length&&(o(n,i.slice()),i=[]);const d="string"==typeof l?l:l.id;let u=r.get(d);u||(u={id:d,label:"string"==typeof l?void 0:l.label,columns:[],firstIndex:s},r.set(d,u),t.push(u)),u.columns.push(e)}),i.length&&o(n,i),1===t.length&&t[0].implicit&&t[0].columns.length===e.length?[]:t}class i extends t{static manifest={ownedProperties:[{property:"group",level:"column",description:'the "group" column property'},{property:"columnGroups",level:"config",description:'the "columnGroups" config property',isUsed:e=>Array.isArray(e)&&e.length>0}],queries:[{type:"getColumnGrouping",description:"Returns column group metadata for the visibility panel"}]};name="groupingColumns";styles="@layer tbw-plugins{.header-group-row{display:grid;grid-auto-flow:column;background:var(--tbw-grouping-columns-header-bg, var(--tbw-color-header-bg));border-bottom:1px solid var(--tbw-grouping-columns-border, var(--tbw-color-border))}.header-group-cell{display:flex;align-items:center;justify-content:center;padding:var(--tbw-button-padding-sm, .25rem .5rem);font-weight:600;font-size:var(--tbw-font-size-sm, .9em);text-transform:uppercase;letter-spacing:.5px;border-right:2px solid var(--tbw-grouping-columns-separator, var(--tbw-color-border-strong, var(--tbw-color-border)))}.header-group-cell:last-child{border-right:none}.header-row .cell.grouped{border-top:none}.header-row .cell.group-end{border-right:2px solid var(--tbw-grouping-columns-separator, var(--tbw-color-border-strong, var(--tbw-color-border)))}.header-row .cell.group-end:last-child{border-right:none}.rows .cell.group-end{border-right:2px solid var(--tbw-grouping-columns-separator, var(--tbw-color-border-strong, var(--tbw-color-border)))}.rows .cell.group-end:last-child{border-right:none}.header-group-row.no-borders{border-bottom:none}.header-group-row.no-borders .header-group-cell{border-right:none}.header-row.no-group-borders .cell.group-end{border-right:1px solid var(--tbw-color-border)}}";get defaultConfig(){return{showGroupBorders:!0,lockGroupOrder:!1}}groups=[];isActive=!1;#r=/* @__PURE__ */new Set;attach(e){super.attach(e),e.addEventListener("column-move",this.#t,{signal:this.disconnectSignal})}detach(){this.groups=[],this.isActive=!1,this.#r.clear()}#t=e=>{if(!this.isActive)return;const r=e,{field:t,columnOrder:o}=r.detail;if(this.config.lockGroupOrder)for(const i of this.groups)if(!i.id.startsWith("__implicit__")&&!this.#o(i,o))return r.preventDefault(),void this.#i(t);this.#n(o)};#n(e){this.#r.clear();const r=this.#s(e);for(const t of this.groups){const o=new Set(t.columns.map(e=>e.field));for(let t=e.length-1;t>=0;t--)if(o.has(e[t])){const o=e[t];o!==r&&this.#r.add(o);break}}}#s(e){if(0===this.groups.length)return null;for(let r=e.length-1;r>=0;r--){const t=e[r];for(const r of this.groups)if(r.columns.some(e=>e.field===t)){const t=new Set(r.columns.map(e=>e.field));for(let r=e.length-1;r>=0;r--)if(t.has(e[r]))return e[r]}}return null}#o(e,r){const t=e.columns.map(e=>r.indexOf(e.field)).filter(e=>-1!==e).sort((e,r)=>e-r);return t.length<=1||t.length===t[t.length-1]-t[0]+1}#i(e){const r=this.gridElement?.querySelector(`.header-row [part~="header-cell"][data-field="${e}"]`);r&&(r.style.setProperty("--_flash-color","var(--tbw-color-error)"),r.animate([{backgroundColor:"rgba(from var(--_flash-color) r g b / 30%)"},{backgroundColor:"transparent"}],{duration:400,easing:"ease-out"}))}handleQuery(e){if("getColumnGrouping"===e.type)return this.#l()}#l(){let e;const r=this.grid?.gridConfig?.columnGroups;if(r&&Array.isArray(r)&&r.length>0)e=r.filter(e=>e.children.length>0).map(e=>({id:e.id,label:e.header,fields:[...e.children]}));else if(this.isActive&&this.groups.length>0){e=this.groups.filter(e=>!e.id.startsWith("__implicit__")).map(e=>({id:e.id,label:e.label??e.id,fields:e.columns.map(e=>e.field)}));const r=this.columns;for(const t of r)if(t.hidden&&t.group){const r="string"==typeof t.group?t.group:t.group.id,o="string"==typeof t.group?t.group:t.group.label??t.group.id,i=e.find(e=>e.id===r);i?i.fields.includes(t.field)||i.fields.push(t.field):e.push({id:r,label:o,fields:[t.field]})}}else{const r=this.columns,t=/* @__PURE__ */new Map;for(const e of r){if(!e.group)continue;const r="string"==typeof e.group?e.group:e.group.id,o="string"==typeof e.group?e.group:e.group.label??e.group.id,i=t.get(r);i?i.fields.includes(e.field)||i.fields.push(e.field):t.set(r,{id:r,label:o,fields:[e.field]})}e=Array.from(t.values())}const t=this.grid?.getColumnOrder();if(t&&t.length>0){const r=new Map(t.map((e,r)=>[e,r]));for(const t of e)t.fields.sort((e,t)=>(r.get(e)??1/0)-(r.get(t)??1/0))}return e}static detect(e,r){if(r?.columnGroups&&Array.isArray(r.columnGroups)&&r.columnGroups.length>0)return!0;const t=r?.columns;return!!Array.isArray(t)&&function(e){return e.some(e=>null!=e.group)}(t)}processColumns(e){const r=this.grid?.gridConfig?.columnGroups;let t;if(r&&Array.isArray(r)&&r.length>0){const o=/* @__PURE__ */new Map;for(const e of r)for(const r of e.children)o.set(r,{id:e.id,label:e.header});t=e.map(e=>{const r=o.get(e.field);return r&&!e.group?{...e,group:r}:e})}else t=[...e];const i=o(t);if(0===i.length)return this.isActive=!1,this.groups=[],t;this.isActive=!0,this.groups=i,this.#r.clear();for(const o of i){const e=o.columns[o.columns.length-1];e?.field&&this.#r.add(e.field)}return t}afterRender(){if(!this.isActive){const e=this.gridElement?.querySelector(".header"),r=e?.querySelector(".header-group-row");return void(r&&r.remove())}const e=this.gridElement?.querySelector(".header");if(!e)return;const r=e.querySelector(".header-group-row");r&&r.remove();const t=this.visibleColumns,i=o(t);if(0===i.length)return;this.#r.clear();for(let o=0;o<i.length;o++){const e=i[o],r=e.columns[e.columns.length-1];r?.field&&o<i.length-1&&this.#r.add(r.field)}const n=function(e,r){if(0===e.length)return null;const t=document.createElement("div");t.className="header-group-row",t.setAttribute("role","row");for(const o of e){const e=o.columns[0],i=e?r.findIndex(r=>r.field===e.field):-1;if(-1===i)continue;const n=String(o.id).startsWith("__implicit__"),s=n?"":o.label||o.id,l=document.createElement("div");l.className="cell header-group-cell",n&&l.classList.add("implicit-group"),l.setAttribute("data-group",String(o.id)),l.style.gridColumn=`${i+1} / span ${o.columns.length}`,l.textContent=s,t.appendChild(l)}return t}(i,t);if(n){n.classList.toggle("no-borders",!this.config.showGroupBorders);const r=e.querySelector(".header-row");r?e.insertBefore(n,r):e.appendChild(n)}const s=e.querySelector(".header-row");s&&(s.classList.toggle("no-group-borders",!this.config.showGroupBorders),function(e,r){if(!r.length||!e)return;const t=/* @__PURE__ */new Map;for(const i of r)for(const e of i.columns)e.field&&t.set(e.field,i.id);const o=Array.from(e.querySelectorAll(".cell[data-field]"));o.forEach(e=>{const r=e.getAttribute("data-field")||"",o=t.get(r);o&&(e.classList.add("grouped"),e.getAttribute("data-group")||e.setAttribute("data-group",o))});for(const i of r){const e=i.columns[i.columns.length-1],r=o.find(r=>r.getAttribute("data-field")===e.field);r&&r.classList.add("group-end")}}(s,i))}afterCellRender(e){this.isActive&&this.config.showGroupBorders&&e.cellElement.classList.toggle("group-end",this.#r.has(e.column.field))}isGroupingActive(){return this.isActive}getGroups(){return this.groups}getGroupColumns(e){const r=this.groups.find(r=>r.id===e);return r?r.columns:[]}refresh(){this.requestRender()}}export{i as GroupingColumnsPlugin};
|
|
727
2
|
//# sourceMappingURL=index.js.map
|