@toolbox-web/grid 1.21.1 → 1.22.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. package/README.md +6 -8
  2. package/all.js +2 -6850
  3. package/all.js.map +1 -1
  4. package/index.js +1 -4352
  5. package/index.js.map +1 -1
  6. package/lib/core/grid.d.ts +75 -8
  7. package/lib/core/grid.d.ts.map +1 -1
  8. package/lib/core/internal/rows.d.ts.map +1 -1
  9. package/lib/core/plugin/base-plugin.d.ts +8 -2
  10. package/lib/core/plugin/base-plugin.d.ts.map +1 -1
  11. package/lib/core/styles/index.d.ts.map +1 -1
  12. package/lib/core/types.d.ts +84 -2
  13. package/lib/core/types.d.ts.map +1 -1
  14. package/lib/plugins/clipboard/index.js +1 -733
  15. package/lib/plugins/clipboard/index.js.map +1 -1
  16. package/lib/plugins/clipboard/types.d.ts +5 -0
  17. package/lib/plugins/clipboard/types.d.ts.map +1 -1
  18. package/lib/plugins/column-virtualization/index.js +1 -560
  19. package/lib/plugins/column-virtualization/index.js.map +1 -1
  20. package/lib/plugins/column-virtualization/types.d.ts +5 -0
  21. package/lib/plugins/column-virtualization/types.d.ts.map +1 -1
  22. package/lib/plugins/context-menu/index.js +1 -754
  23. package/lib/plugins/context-menu/index.js.map +1 -1
  24. package/lib/plugins/context-menu/types.d.ts +5 -0
  25. package/lib/plugins/context-menu/types.d.ts.map +1 -1
  26. package/lib/plugins/editing/EditingPlugin.d.ts.map +1 -1
  27. package/lib/plugins/editing/index.d.ts +1 -1
  28. package/lib/plugins/editing/index.d.ts.map +1 -1
  29. package/lib/plugins/editing/index.js +1 -1539
  30. package/lib/plugins/editing/index.js.map +1 -1
  31. package/lib/plugins/editing/types.d.ts +49 -0
  32. package/lib/plugins/editing/types.d.ts.map +1 -1
  33. package/lib/plugins/export/index.js +1 -589
  34. package/lib/plugins/export/index.js.map +1 -1
  35. package/lib/plugins/export/types.d.ts +5 -0
  36. package/lib/plugins/export/types.d.ts.map +1 -1
  37. package/lib/plugins/filtering/FilteringPlugin.d.ts.map +1 -1
  38. package/lib/plugins/filtering/filter-model.d.ts.map +1 -1
  39. package/lib/plugins/filtering/index.js +1 -1283
  40. package/lib/plugins/filtering/index.js.map +1 -1
  41. package/lib/plugins/filtering/types.d.ts +7 -2
  42. package/lib/plugins/filtering/types.d.ts.map +1 -1
  43. package/lib/plugins/grouping-columns/index.js +1 -726
  44. package/lib/plugins/grouping-columns/index.js.map +1 -1
  45. package/lib/plugins/grouping-columns/types.d.ts +3 -0
  46. package/lib/plugins/grouping-columns/types.d.ts.map +1 -1
  47. package/lib/plugins/grouping-rows/index.js +2 -905
  48. package/lib/plugins/grouping-rows/index.js.map +1 -1
  49. package/lib/plugins/grouping-rows/types.d.ts +5 -0
  50. package/lib/plugins/grouping-rows/types.d.ts.map +1 -1
  51. package/lib/plugins/master-detail/index.js +1 -950
  52. package/lib/plugins/master-detail/index.js.map +1 -1
  53. package/lib/plugins/master-detail/types.d.ts +5 -0
  54. package/lib/plugins/master-detail/types.d.ts.map +1 -1
  55. package/lib/plugins/multi-sort/index.js +1 -553
  56. package/lib/plugins/multi-sort/index.js.map +1 -1
  57. package/lib/plugins/multi-sort/types.d.ts +5 -0
  58. package/lib/plugins/multi-sort/types.d.ts.map +1 -1
  59. package/lib/plugins/pinned-columns/index.js +1 -688
  60. package/lib/plugins/pinned-columns/index.js.map +1 -1
  61. package/lib/plugins/pinned-columns/types.d.ts +3 -0
  62. package/lib/plugins/pinned-columns/types.d.ts.map +1 -1
  63. package/lib/plugins/pinned-rows/index.js +1 -704
  64. package/lib/plugins/pinned-rows/index.js.map +1 -1
  65. package/lib/plugins/pinned-rows/types.d.ts +5 -0
  66. package/lib/plugins/pinned-rows/types.d.ts.map +1 -1
  67. package/lib/plugins/pivot/index.js +1 -1191
  68. package/lib/plugins/pivot/index.js.map +1 -1
  69. package/lib/plugins/pivot/types.d.ts +5 -0
  70. package/lib/plugins/pivot/types.d.ts.map +1 -1
  71. package/lib/plugins/print/index.js +1 -691
  72. package/lib/plugins/print/index.js.map +1 -1
  73. package/lib/plugins/print/types.d.ts +3 -0
  74. package/lib/plugins/print/types.d.ts.map +1 -1
  75. package/lib/plugins/reorder/index.js +1 -703
  76. package/lib/plugins/reorder/index.js.map +1 -1
  77. package/lib/plugins/reorder/types.d.ts +5 -0
  78. package/lib/plugins/reorder/types.d.ts.map +1 -1
  79. package/lib/plugins/responsive/index.js +1 -971
  80. package/lib/plugins/responsive/index.js.map +1 -1
  81. package/lib/plugins/responsive/types.d.ts +5 -0
  82. package/lib/plugins/responsive/types.d.ts.map +1 -1
  83. package/lib/plugins/row-reorder/index.js +1 -728
  84. package/lib/plugins/row-reorder/index.js.map +1 -1
  85. package/lib/plugins/row-reorder/types.d.ts +5 -0
  86. package/lib/plugins/row-reorder/types.d.ts.map +1 -1
  87. package/lib/plugins/selection/index.js +1 -1071
  88. package/lib/plugins/selection/index.js.map +1 -1
  89. package/lib/plugins/selection/types.d.ts +3 -0
  90. package/lib/plugins/selection/types.d.ts.map +1 -1
  91. package/lib/plugins/server-side/index.js +1 -521
  92. package/lib/plugins/server-side/index.js.map +1 -1
  93. package/lib/plugins/server-side/types.d.ts +5 -0
  94. package/lib/plugins/server-side/types.d.ts.map +1 -1
  95. package/lib/plugins/tree/index.js +1 -686
  96. package/lib/plugins/tree/index.js.map +1 -1
  97. package/lib/plugins/tree/types.d.ts +5 -0
  98. package/lib/plugins/tree/types.d.ts.map +1 -1
  99. package/lib/plugins/undo-redo/index.js +1 -584
  100. package/lib/plugins/undo-redo/index.js.map +1 -1
  101. package/lib/plugins/undo-redo/types.d.ts +5 -0
  102. package/lib/plugins/undo-redo/types.d.ts.map +1 -1
  103. package/lib/plugins/visibility/index.js +1 -792
  104. package/lib/plugins/visibility/index.js.map +1 -1
  105. package/lib/plugins/visibility/types.d.ts +5 -0
  106. package/lib/plugins/visibility/types.d.ts.map +1 -1
  107. package/package.json +1 -1
  108. package/umd/grid.all.umd.js +1 -186
  109. package/umd/grid.all.umd.js.map +1 -1
  110. package/umd/grid.umd.js +1 -90
  111. package/umd/grid.umd.js.map +1 -1
  112. package/umd/plugins/clipboard.umd.js +1 -6
  113. package/umd/plugins/clipboard.umd.js.map +1 -1
  114. package/umd/plugins/column-virtualization.umd.js +1 -1
  115. package/umd/plugins/column-virtualization.umd.js.map +1 -1
  116. package/umd/plugins/context-menu.umd.js +1 -1
  117. package/umd/plugins/context-menu.umd.js.map +1 -1
  118. package/umd/plugins/editing.umd.js +1 -1
  119. package/umd/plugins/editing.umd.js.map +1 -1
  120. package/umd/plugins/export.umd.js +1 -13
  121. package/umd/plugins/export.umd.js.map +1 -1
  122. package/umd/plugins/filtering.umd.js +1 -1
  123. package/umd/plugins/filtering.umd.js.map +1 -1
  124. package/umd/plugins/grouping-columns.umd.js +1 -1
  125. package/umd/plugins/grouping-columns.umd.js.map +1 -1
  126. package/umd/plugins/grouping-rows.umd.js +1 -4
  127. package/umd/plugins/grouping-rows.umd.js.map +1 -1
  128. package/umd/plugins/master-detail.umd.js +1 -1
  129. package/umd/plugins/master-detail.umd.js.map +1 -1
  130. package/umd/plugins/multi-sort.umd.js +1 -1
  131. package/umd/plugins/multi-sort.umd.js.map +1 -1
  132. package/umd/plugins/pinned-columns.umd.js +1 -1
  133. package/umd/plugins/pinned-columns.umd.js.map +1 -1
  134. package/umd/plugins/pinned-rows.umd.js +1 -1
  135. package/umd/plugins/pinned-rows.umd.js.map +1 -1
  136. package/umd/plugins/pivot.umd.js +1 -1
  137. package/umd/plugins/pivot.umd.js.map +1 -1
  138. package/umd/plugins/print.umd.js +1 -75
  139. package/umd/plugins/print.umd.js.map +1 -1
  140. package/umd/plugins/reorder.umd.js +1 -1
  141. package/umd/plugins/reorder.umd.js.map +1 -1
  142. package/umd/plugins/responsive.umd.js +1 -1
  143. package/umd/plugins/responsive.umd.js.map +1 -1
  144. package/umd/plugins/row-reorder.umd.js +1 -1
  145. package/umd/plugins/row-reorder.umd.js.map +1 -1
  146. package/umd/plugins/selection.umd.js +1 -3
  147. package/umd/plugins/selection.umd.js.map +1 -1
  148. package/umd/plugins/server-side.umd.js +1 -1
  149. package/umd/plugins/server-side.umd.js.map +1 -1
  150. package/umd/plugins/tree.umd.js +1 -1
  151. package/umd/plugins/tree.umd.js.map +1 -1
  152. package/umd/plugins/undo-redo.umd.js +1 -1
  153. package/umd/plugins/undo-redo.umd.js.map +1 -1
  154. package/umd/plugins/visibility.umd.js +1 -1
  155. package/umd/plugins/visibility.umd.js.map +1 -1
@@ -1,793 +1,2 @@
1
- const m = '<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>', w = {
2
- expand: "▶",
3
- collapse: "▼",
4
- sortAsc: "▲",
5
- sortDesc: "▼",
6
- sortNone: "⇅",
7
- submenuArrow: "▶",
8
- dragHandle: "⋮⋮",
9
- toolPanel: "☰",
10
- filter: m,
11
- filterActive: m,
12
- print: "🖨️"
13
- };
14
- class C {
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 i = new CustomEvent(e, { detail: t, bubbles: !0, cancelable: !0 });
150
- return this.grid?.dispatchEvent?.(i), i.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 { ...w, ...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(), i = parseInt(t, 10);
346
- if (!isNaN(i)) return i;
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
- const y = '@layer tbw-plugins{.tbw-visibility-content{display:flex;flex-direction:column;height:100%}.tbw-visibility-list{flex:1;overflow-y:auto;padding:var(--tbw-panel-padding, var(--tbw-spacing-md, .5rem))}.tbw-visibility-row{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));padding:var(--tbw-menu-item-padding, .375rem .25rem);cursor:pointer;font-size:var(--tbw-font-size-sm, .8125rem);border-radius:var(--tbw-border-radius, .25rem);position:relative}.tbw-visibility-row:hover{background:var(--tbw-visibility-hover, var(--tbw-color-row-hover))}.tbw-visibility-row input[type=checkbox]{cursor:pointer}.tbw-visibility-row.locked span{color:var(--tbw-color-fg-muted)}.tbw-visibility-handle{cursor:grab;color:var(--tbw-color-fg-muted);font-size:var(--tbw-font-size-2xs, .625rem);letter-spacing:-2px;-webkit-user-select:none;user-select:none;flex-shrink:0}.tbw-visibility-row.reorderable:hover .tbw-visibility-handle{color:var(--tbw-color-fg)}.tbw-visibility-label{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));flex:1;cursor:pointer}.tbw-visibility-row.dragging{opacity:.5;cursor:grabbing}.tbw-visibility-row.drop-before:before{content:"";position:absolute;left:0;right:0;top:0;height:2px;background:var(--tbw-visibility-indicator, var(--tbw-color-accent))}.tbw-visibility-row.drop-after:after{content:"";position:absolute;left:0;right:0;bottom:0;height:2px;background:var(--tbw-visibility-indicator, var(--tbw-color-accent))}.tbw-visibility-show-all{margin:var(--tbw-panel-padding, var(--tbw-spacing-md, .5rem));padding:var(--tbw-button-padding, .5rem .75rem);border:1px solid var(--tbw-visibility-border, var(--tbw-color-border));border-radius:var(--tbw-border-radius, .25rem);background:var(--tbw-visibility-btn-bg, var(--tbw-color-header-bg));color:var(--tbw-color-fg);cursor:pointer;font-size:var(--tbw-font-size-sm, .8125rem)}.tbw-visibility-show-all:hover{background:var(--tbw-visibility-hover, var(--tbw-color-row-hover))}.tbw-visibility-group-header{display:flex;align-items:center;padding:var(--tbw-menu-item-padding, .375rem .25rem);font-size:var(--tbw-font-size-sm, .8125rem);font-weight:600;color:var(--tbw-color-fg);border-bottom:1px solid var(--tbw-color-border);margin-top:var(--tbw-spacing-sm, .25rem);position:relative}.tbw-visibility-group-header:first-child{margin-top:0}.tbw-visibility-group-header .tbw-visibility-label{gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.tbw-visibility-group-header.reorderable{cursor:grab}.tbw-visibility-group-header.reorderable:hover{background:var(--tbw-visibility-hover, var(--tbw-color-row-hover))}.tbw-visibility-group-header .tbw-visibility-handle{cursor:grab;color:var(--tbw-color-fg-muted);font-size:var(--tbw-font-size-2xs, .625rem);letter-spacing:-2px;-webkit-user-select:none;user-select:none;flex-shrink:0}.tbw-visibility-group-header.reorderable:hover .tbw-visibility-handle{color:var(--tbw-color-fg)}.tbw-visibility-group-header.dragging{opacity:.5;cursor:grabbing}.tbw-visibility-group-header.drop-before:before{content:"";position:absolute;left:0;right:0;top:0;height:2px;background:var(--tbw-visibility-indicator, var(--tbw-color-accent))}.tbw-visibility-group-header.drop-after:after{content:"";position:absolute;left:0;right:0;bottom:0;height:2px;background:var(--tbw-visibility-indicator, var(--tbw-color-accent))}.tbw-visibility-row--grouped{padding-left:calc(var(--tbw-panel-padding, var(--tbw-spacing-md, .5rem)) + .75rem)}}';
381
- function v(f) {
382
- const e = f.meta ?? {};
383
- return e.lockPosition !== !0 && e.suppressMovable !== !0;
384
- }
385
- class b extends C {
386
- /**
387
- * Plugin dependencies - VisibilityPlugin optionally uses ReorderPlugin for drag-drop reordering.
388
- *
389
- * When ReorderPlugin is present, columns in the visibility panel become draggable.
390
- * @internal
391
- */
392
- static dependencies = [
393
- { name: "reorder", required: !1, reason: "Enables drag-to-reorder columns in visibility panel" }
394
- ];
395
- /**
396
- * Plugin manifest - declares handled queries.
397
- * @internal
398
- */
399
- static manifest = {
400
- queries: [
401
- {
402
- type: "getContextMenuItems",
403
- description: 'Contributes "Hide column" item to the header context menu'
404
- }
405
- ]
406
- };
407
- /** @internal */
408
- name = "visibility";
409
- /** Tool panel ID for shell integration */
410
- static PANEL_ID = "columns";
411
- /** @internal */
412
- styles = y;
413
- /** @internal */
414
- get defaultConfig() {
415
- return {
416
- allowHideAll: !1
417
- };
418
- }
419
- // #region Internal State
420
- columnListElement = null;
421
- // Drag state for reorder integration
422
- isDragging = !1;
423
- draggedField = null;
424
- draggedIndex = null;
425
- dropIndex = null;
426
- /** When dragging a group, holds the group ID; null for individual column drags. */
427
- draggedGroupId = null;
428
- /** Fields belonging to the group currently being dragged. */
429
- draggedGroupFields = [];
430
- /** Clear drag-related classes from all rows and group headers in a list. */
431
- clearDragClasses(e) {
432
- e.querySelectorAll(".tbw-visibility-row, .tbw-visibility-group-header").forEach((t) => {
433
- t.classList.remove("dragging", "drop-target", "drop-before", "drop-after");
434
- });
435
- }
436
- // #endregion
437
- // #region Lifecycle
438
- /** @internal */
439
- attach(e) {
440
- super.attach(e), e.addEventListener(
441
- "column-move",
442
- () => {
443
- this.columnListElement && requestAnimationFrame(() => {
444
- this.columnListElement && this.rebuildToggles(this.columnListElement);
445
- });
446
- },
447
- { signal: this.disconnectSignal }
448
- );
449
- }
450
- /** @internal */
451
- detach() {
452
- this.columnListElement = null, this.isDragging = !1, this.draggedField = null, this.draggedIndex = null, this.dropIndex = null;
453
- }
454
- // #endregion
455
- // #region Query Handlers
456
- /**
457
- * Handle inter-plugin queries.
458
- * Contributes a "Hide column" item to the header context menu.
459
- * @internal
460
- */
461
- handleQuery(e) {
462
- if (e.type === "getContextMenuItems") {
463
- const t = e.context;
464
- if (!t.isHeader) return;
465
- const i = t.column;
466
- return !i?.field || i.meta?.lockVisibility ? void 0 : [
467
- {
468
- id: "visibility/hide-column",
469
- label: "Hide Column",
470
- icon: "👁",
471
- order: 30,
472
- action: () => this.hideColumn(i.field)
473
- }
474
- ];
475
- }
476
- }
477
- // #endregion
478
- // #region Shell Integration
479
- /**
480
- * Register the column visibility tool panel with the shell.
481
- * @internal
482
- */
483
- getToolPanel() {
484
- return {
485
- id: b.PANEL_ID,
486
- title: "Columns",
487
- icon: "☰",
488
- tooltip: "Column visibility",
489
- order: 100,
490
- // High order so it appears last
491
- render: (e) => this.renderPanelContent(e)
492
- };
493
- }
494
- // #endregion
495
- // #region Public API
496
- /**
497
- * Show the visibility sidebar panel.
498
- * Opens the tool panel and ensures this section is expanded.
499
- */
500
- show() {
501
- this.grid.openToolPanel(), this.grid.expandedToolPanelSections.includes(b.PANEL_ID) || this.grid.toggleToolPanelSection(b.PANEL_ID);
502
- }
503
- /**
504
- * Hide the visibility sidebar panel.
505
- */
506
- hide() {
507
- this.grid.closeToolPanel();
508
- }
509
- /**
510
- * Toggle the visibility sidebar panel section.
511
- */
512
- toggle() {
513
- this.grid.isToolPanelOpen || this.grid.openToolPanel(), this.grid.toggleToolPanelSection(b.PANEL_ID);
514
- }
515
- /**
516
- * Check if a specific column is visible.
517
- * Delegates to grid.isColumnVisible().
518
- * @param field - The field name to check
519
- * @returns True if the column is visible
520
- */
521
- isColumnVisible(e) {
522
- return this.grid.isColumnVisible(e);
523
- }
524
- /**
525
- * Set visibility for a specific column.
526
- * Delegates to grid.setColumnVisible().
527
- * @param field - The field name of the column
528
- * @param visible - Whether the column should be visible
529
- */
530
- setColumnVisible(e, t) {
531
- this.grid.setColumnVisible(e, t);
532
- }
533
- /**
534
- * Get list of all visible column fields.
535
- * @returns Array of visible field names
536
- */
537
- getVisibleColumns() {
538
- return this.grid.getAllColumns().filter((e) => e.visible).map((e) => e.field);
539
- }
540
- /**
541
- * Get list of all hidden column fields.
542
- * @returns Array of hidden field names
543
- */
544
- getHiddenColumns() {
545
- return this.grid.getAllColumns().filter((e) => !e.visible).map((e) => e.field);
546
- }
547
- /**
548
- * Show all columns.
549
- * Delegates to grid.showAllColumns().
550
- */
551
- showAll() {
552
- this.grid.showAllColumns();
553
- }
554
- /**
555
- * Toggle visibility for a specific column.
556
- * Delegates to grid.toggleColumnVisibility().
557
- * @param field - The field name of the column
558
- */
559
- toggleColumn(e) {
560
- this.grid.toggleColumnVisibility(e);
561
- }
562
- /**
563
- * Show a specific column.
564
- * Delegates to grid.setColumnVisible().
565
- * @param field - The field name of the column to show
566
- */
567
- showColumn(e) {
568
- this.setColumnVisible(e, !0);
569
- }
570
- /**
571
- * Hide a specific column.
572
- * Delegates to grid.setColumnVisible().
573
- * @param field - The field name of the column to hide
574
- */
575
- hideColumn(e) {
576
- this.setColumnVisible(e, !1);
577
- }
578
- /**
579
- * Get all columns with their visibility status.
580
- * Useful for building visibility UI.
581
- * @returns Array of column info with visibility status
582
- */
583
- getAllColumns() {
584
- return this.grid.getAllColumns();
585
- }
586
- /**
587
- * Check if the sidebar panel is currently open.
588
- * @returns True if the panel section is expanded
589
- */
590
- isPanelVisible() {
591
- return this.grid.isToolPanelOpen && this.grid.expandedToolPanelSections.includes(b.PANEL_ID);
592
- }
593
- // #endregion
594
- // #region Private Methods
595
- /**
596
- * Render the panel content into the shell's tool panel container.
597
- * Returns a cleanup function.
598
- */
599
- renderPanelContent(e) {
600
- const t = document.createElement("div");
601
- t.className = "tbw-visibility-content";
602
- const i = document.createElement("div");
603
- i.className = "tbw-visibility-list", t.appendChild(i);
604
- const l = document.createElement("button");
605
- return l.className = "tbw-visibility-show-all", l.textContent = "Show All", l.addEventListener("click", () => {
606
- this.grid.showAllColumns(), this.rebuildToggles(i);
607
- }), t.appendChild(l), this.columnListElement = i, this.rebuildToggles(i), e.appendChild(t), () => {
608
- this.columnListElement = null, t.remove();
609
- };
610
- }
611
- /**
612
- * Check if a reorder plugin is present (by name to avoid static import).
613
- */
614
- hasReorderPlugin() {
615
- const e = this.grid?.getPluginByName?.("reorder");
616
- return !!(e && typeof e.moveColumn == "function");
617
- }
618
- /**
619
- * Build the column toggle checkboxes.
620
- * When GroupingColumnsPlugin is present, renders columns under collapsible group headers.
621
- * When a reorder plugin is present, adds drag handles for reordering.
622
- */
623
- rebuildToggles(e) {
624
- const t = this.hasReorderPlugin();
625
- e.innerHTML = "";
626
- const i = this.grid.getAllColumns().filter((o) => !o.utility), r = this.grid.query("getColumnGrouping")?.flat().filter((o) => o && o.fields.length > 0) ?? [];
627
- if (r.length === 0) {
628
- this.renderFlatColumnList(i, t, e);
629
- return;
630
- }
631
- const n = /* @__PURE__ */ new Map();
632
- for (const o of r)
633
- for (const a of o.fields) n.set(a, o);
634
- const s = /* @__PURE__ */ new Set();
635
- for (const o of i) {
636
- const a = n.get(o.field);
637
- if (a) {
638
- if (!s.has(a.id)) {
639
- s.add(a.id);
640
- const g = new Set(a.fields), u = i.filter((d) => g.has(d.field));
641
- u.length > 0 && this.renderGroupSection(a, u, t, e);
642
- }
643
- } else {
644
- const g = i.indexOf(o);
645
- e.appendChild(this.createColumnRow(o, g, t, e));
646
- }
647
- }
648
- }
649
- /**
650
- * Render a group section with header checkbox and indented column rows.
651
- */
652
- renderGroupSection(e, t, i, l) {
653
- const r = document.createElement("div");
654
- r.className = "tbw-visibility-group-header", r.setAttribute("data-group-id", e.id), i && (r.draggable = !0, r.classList.add("reorderable"), this.setupGroupDragListeners(r, e, l));
655
- const n = document.createElement("label");
656
- n.className = "tbw-visibility-label";
657
- const s = document.createElement("input");
658
- s.type = "checkbox";
659
- const o = t.filter((d) => d.visible).length, a = t.every((d) => d.lockVisible);
660
- o === t.length ? (s.checked = !0, s.indeterminate = !1) : o === 0 ? (s.checked = !1, s.indeterminate = !1) : (s.checked = !1, s.indeterminate = !0), s.disabled = a, s.addEventListener("change", () => {
661
- const d = s.checked;
662
- for (const c of t)
663
- c.lockVisible || this.grid.setColumnVisible(c.field, d);
664
- setTimeout(() => this.rebuildToggles(l), 0);
665
- });
666
- const g = document.createElement("span");
667
- if (g.textContent = e.label, n.appendChild(s), n.appendChild(g), r.appendChild(n), i) {
668
- const d = document.createElement("span");
669
- d.className = "tbw-visibility-handle", this.setIcon(d, this.resolveIcon("dragHandle")), d.title = "Drag to reorder group", r.insertBefore(d, n);
670
- }
671
- l.appendChild(r);
672
- const u = this.grid.getAllColumns().filter((d) => !d.utility);
673
- for (const d of t) {
674
- const c = u.findIndex((h) => h.field === d.field), p = this.createColumnRow(d, c, i, l);
675
- p.classList.add("tbw-visibility-row--grouped"), l.appendChild(p);
676
- }
677
- }
678
- /**
679
- * Render a flat (ungrouped) list of column rows.
680
- */
681
- renderFlatColumnList(e, t, i) {
682
- const l = this.grid.getAllColumns().filter((r) => !r.utility);
683
- for (const r of e) {
684
- const n = l.findIndex((s) => s.field === r.field);
685
- i.appendChild(this.createColumnRow(r, n, t, i));
686
- }
687
- }
688
- /**
689
- * Create a single column visibility row element.
690
- */
691
- createColumnRow(e, t, i, l) {
692
- const r = e.header || e.field, n = document.createElement("div");
693
- n.className = e.lockVisible ? "tbw-visibility-row locked" : "tbw-visibility-row", n.setAttribute("data-field", e.field), n.setAttribute("data-index", String(t)), i && v(e) && (n.draggable = !0, n.classList.add("reorderable"), this.setupDragListeners(n, e.field, t, l));
694
- const s = document.createElement("label");
695
- s.className = "tbw-visibility-label";
696
- const o = document.createElement("input");
697
- o.type = "checkbox", o.checked = e.visible, o.disabled = e.lockVisible ?? !1, o.addEventListener("change", () => {
698
- this.grid.toggleColumnVisibility(e.field), setTimeout(() => this.rebuildToggles(l), 0);
699
- });
700
- const a = document.createElement("span");
701
- if (a.textContent = r, s.appendChild(o), s.appendChild(a), i && v(e)) {
702
- const g = document.createElement("span");
703
- g.className = "tbw-visibility-handle", this.setIcon(g, this.resolveIcon("dragHandle")), g.title = "Drag to reorder", n.appendChild(g);
704
- }
705
- return n.appendChild(s), n;
706
- }
707
- /**
708
- * Set up drag-and-drop listeners for a group header row.
709
- * Dragging a group moves all its member columns as a block.
710
- */
711
- setupGroupDragListeners(e, t, i) {
712
- e.addEventListener("dragstart", (l) => {
713
- this.isDragging = !0, this.draggedGroupId = t.id, this.draggedGroupFields = [...t.fields], this.draggedField = null, this.draggedIndex = null, l.dataTransfer && (l.dataTransfer.effectAllowed = "move", l.dataTransfer.setData("text/plain", `group:${t.id}`)), e.classList.add("dragging"), i.querySelectorAll(".tbw-visibility-row--grouped").forEach((r) => {
714
- const n = r.getAttribute("data-field");
715
- n && this.draggedGroupFields.includes(n) && r.classList.add("dragging");
716
- });
717
- }), e.addEventListener("dragend", () => {
718
- this.isDragging = !1, this.draggedGroupId = null, this.draggedGroupFields = [], this.draggedField = null, this.draggedIndex = null, this.dropIndex = null, this.clearDragClasses(i);
719
- }), e.addEventListener("dragover", (l) => {
720
- if (l.preventDefault(), !this.isDragging || this.draggedGroupId === t.id || !this.draggedGroupId) return;
721
- const r = e.getBoundingClientRect(), n = r.top + r.height / 2, s = l.clientY < n;
722
- this.clearDragClasses(i), e.classList.add("drop-target"), e.classList.toggle("drop-before", s), e.classList.toggle("drop-after", !s);
723
- }), e.addEventListener("dragleave", () => {
724
- e.classList.remove("drop-target", "drop-before", "drop-after");
725
- }), e.addEventListener("drop", (l) => {
726
- if (l.preventDefault(), !this.isDragging || !this.draggedGroupId || this.draggedGroupId === t.id) return;
727
- const r = e.getBoundingClientRect(), n = l.clientY < r.top + r.height / 2;
728
- this.executeGroupDrop(this.draggedGroupFields, t.fields, n, i);
729
- });
730
- }
731
- /**
732
- * Execute a group drop — move the dragged group's fields as a block
733
- * to the position relative to the target group or column.
734
- */
735
- executeGroupDrop(e, t, i, l) {
736
- const n = this.grid.getAllColumns().map((d) => d.field), s = n.filter((d) => !e.includes(d)), o = i ? t[0] : t[t.length - 1], a = s.indexOf(o);
737
- if (a === -1) return;
738
- const g = i ? a : a + 1, u = n.filter((d) => e.includes(d));
739
- s.splice(g, 0, ...u), this.grid.setColumnOrder(s), requestAnimationFrame(() => {
740
- this.columnListElement && this.rebuildToggles(this.columnListElement);
741
- });
742
- }
743
- /**
744
- * Set up drag-and-drop event listeners for a row.
745
- * On drop, emits a 'column-reorder-request' event for other plugins to handle.
746
- */
747
- setupDragListeners(e, t, i, l) {
748
- e.addEventListener("dragstart", (r) => {
749
- this.isDragging = !0, this.draggedField = t, this.draggedIndex = i, this.draggedGroupId = null, this.draggedGroupFields = [], r.dataTransfer && (r.dataTransfer.effectAllowed = "move", r.dataTransfer.setData("text/plain", t)), e.classList.add("dragging");
750
- }), e.addEventListener("dragend", () => {
751
- this.isDragging = !1, this.draggedField = null, this.draggedIndex = null, this.dropIndex = null, this.clearDragClasses(l);
752
- }), e.addEventListener("dragover", (r) => {
753
- if (r.preventDefault(), !this.isDragging) return;
754
- if (this.draggedGroupId) {
755
- if (e.classList.contains("tbw-visibility-row--grouped")) return;
756
- } else if (this.draggedField === t)
757
- return;
758
- const n = e.getBoundingClientRect(), s = n.top + n.height / 2;
759
- this.dropIndex = r.clientY < s ? i : i + 1, this.clearDragClasses(l), this.draggedGroupId ? (l.querySelector(`.tbw-visibility-group-header[data-group-id="${this.draggedGroupId}"]`)?.classList.add("dragging"), l.querySelectorAll(".tbw-visibility-row--grouped").forEach((o) => {
760
- const a = o.getAttribute("data-field");
761
- a && this.draggedGroupFields.includes(a) && o.classList.add("dragging");
762
- })) : this.draggedField && l.querySelector(`.tbw-visibility-row[data-field="${this.draggedField}"]`)?.classList.add("dragging"), e.classList.add("drop-target"), e.classList.toggle("drop-before", r.clientY < s), e.classList.toggle("drop-after", r.clientY >= s);
763
- }), e.addEventListener("dragleave", () => {
764
- e.classList.remove("drop-target", "drop-before", "drop-after");
765
- }), e.addEventListener("drop", (r) => {
766
- if (r.preventDefault(), !this.isDragging) return;
767
- if (this.draggedGroupId && this.draggedGroupFields.length > 0) {
768
- if (e.classList.contains("tbw-visibility-row--grouped")) return;
769
- const g = e.getBoundingClientRect(), u = r.clientY < g.top + g.height / 2;
770
- this.executeGroupDrop(this.draggedGroupFields, [t], u, l);
771
- return;
772
- }
773
- const n = this.draggedField, s = this.draggedIndex, o = this.dropIndex;
774
- if (n === null || s === null || o === null)
775
- return;
776
- const a = o > s ? o - 1 : o;
777
- if (a !== s) {
778
- const g = this.grid.getAllColumns(), d = g.filter((h) => !h.utility)[a]?.field, c = d ? g.findIndex((h) => h.field === d) : g.length, p = {
779
- field: n,
780
- fromIndex: s,
781
- // Not used by ReorderPlugin, just for info
782
- toIndex: c
783
- };
784
- this.emit("column-reorder-request", p);
785
- }
786
- });
787
- }
788
- // #endregion
789
- }
790
- export {
791
- b as VisibilityPlugin
792
- };
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>',t={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:e,filterActive:e,print:"🖨️"};class i{static dependencies;static manifest;version="undefined"!=typeof __GRID_VERSION__?__GRID_VERSION__:"dev";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#e;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}attach(e){this.#e?.abort(),this.#e=new AbortController,this.grid=e,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#e?.abort(),this.#e=void 0}getPlugin(e){return this.grid?.getPlugin(e)}emit(e,t){this.grid?.dispatchEvent?.(new CustomEvent(e,{detail:t,bubbles:!0}))}emitCancelable(e,t){const i=new CustomEvent(e,{detail:t,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(i),i.defaultPrevented}on(e,t){this.grid?._pluginManager?.subscribe(this,e,t)}off(e){this.grid?._pluginManager?.unsubscribe(this,e)}emitPluginEvent(e,t){this.grid?._pluginManager?.emitPluginEvent(e,t)}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get gridElement(){return this.grid}get disconnectSignal(){return this.#e?.signal??this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...t,...e}}get isAnimationEnabled(){const e=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===e||"off"===e)return!1;if(!0===e||"on"===e)return!0;const t=this.gridElement;if(t){return"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}return!0}get animationDuration(){const e=this.gridElement;if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),i=parseInt(t,10);if(!isNaN(i))return i}return 200}resolveIcon(e,t){return void 0!==t?t:this.gridIcons[e]}setIcon(e,t){"string"==typeof t?e.innerHTML=t:t instanceof HTMLElement&&(e.innerHTML="",e.appendChild(t.cloneNode(!0)))}warn(e){console.warn(`[tbw-grid:${this.name}] ${e}`)}}function r(e){const t=e.meta??{};return!0!==t.lockPosition&&!0!==t.suppressMovable}class s extends i{static dependencies=[{name:"reorder",required:!1,reason:"Enables drag-to-reorder columns in visibility panel"}];static manifest={queries:[{type:"getContextMenuItems",description:'Contributes "Hide column" item to the header context menu'}]};name="visibility";static PANEL_ID="columns";styles='@layer tbw-plugins{.tbw-visibility-content{display:flex;flex-direction:column;height:100%}.tbw-visibility-list{flex:1;overflow-y:auto;padding:var(--tbw-panel-padding, var(--tbw-spacing-md, .5rem))}.tbw-visibility-row{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));padding:var(--tbw-menu-item-padding, .375rem .25rem);cursor:pointer;font-size:var(--tbw-font-size-sm, .8125rem);border-radius:var(--tbw-border-radius, .25rem);position:relative}.tbw-visibility-row:hover{background:var(--tbw-visibility-hover, var(--tbw-color-row-hover))}.tbw-visibility-row input[type=checkbox]{cursor:pointer}.tbw-visibility-row.locked span{color:var(--tbw-color-fg-muted)}.tbw-visibility-handle{cursor:grab;color:var(--tbw-color-fg-muted);font-size:var(--tbw-font-size-2xs, .625rem);letter-spacing:-2px;-webkit-user-select:none;user-select:none;flex-shrink:0}.tbw-visibility-row.reorderable:hover .tbw-visibility-handle{color:var(--tbw-color-fg)}.tbw-visibility-label{display:flex;align-items:center;gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem));flex:1;cursor:pointer}.tbw-visibility-row.dragging{opacity:.5;cursor:grabbing}.tbw-visibility-row.drop-before:before{content:"";position:absolute;left:0;right:0;top:0;height:2px;background:var(--tbw-visibility-indicator, var(--tbw-color-accent))}.tbw-visibility-row.drop-after:after{content:"";position:absolute;left:0;right:0;bottom:0;height:2px;background:var(--tbw-visibility-indicator, var(--tbw-color-accent))}.tbw-visibility-show-all{margin:var(--tbw-panel-padding, var(--tbw-spacing-md, .5rem));padding:var(--tbw-button-padding, .5rem .75rem);border:1px solid var(--tbw-visibility-border, var(--tbw-color-border));border-radius:var(--tbw-border-radius, .25rem);background:var(--tbw-visibility-btn-bg, var(--tbw-color-header-bg));color:var(--tbw-color-fg);cursor:pointer;font-size:var(--tbw-font-size-sm, .8125rem)}.tbw-visibility-show-all:hover{background:var(--tbw-visibility-hover, var(--tbw-color-row-hover))}.tbw-visibility-group-header{display:flex;align-items:center;padding:var(--tbw-menu-item-padding, .375rem .25rem);font-size:var(--tbw-font-size-sm, .8125rem);font-weight:600;color:var(--tbw-color-fg);border-bottom:1px solid var(--tbw-color-border);margin-top:var(--tbw-spacing-sm, .25rem);position:relative}.tbw-visibility-group-header:first-child{margin-top:0}.tbw-visibility-group-header .tbw-visibility-label{gap:var(--tbw-panel-gap, var(--tbw-spacing-md, .5rem))}.tbw-visibility-group-header.reorderable{cursor:grab}.tbw-visibility-group-header.reorderable:hover{background:var(--tbw-visibility-hover, var(--tbw-color-row-hover))}.tbw-visibility-group-header .tbw-visibility-handle{cursor:grab;color:var(--tbw-color-fg-muted);font-size:var(--tbw-font-size-2xs, .625rem);letter-spacing:-2px;-webkit-user-select:none;user-select:none;flex-shrink:0}.tbw-visibility-group-header.reorderable:hover .tbw-visibility-handle{color:var(--tbw-color-fg)}.tbw-visibility-group-header.dragging{opacity:.5;cursor:grabbing}.tbw-visibility-group-header.drop-before:before{content:"";position:absolute;left:0;right:0;top:0;height:2px;background:var(--tbw-visibility-indicator, var(--tbw-color-accent))}.tbw-visibility-group-header.drop-after:after{content:"";position:absolute;left:0;right:0;bottom:0;height:2px;background:var(--tbw-visibility-indicator, var(--tbw-color-accent))}.tbw-visibility-row--grouped{padding-left:calc(var(--tbw-panel-padding, var(--tbw-spacing-md, .5rem)) + .75rem)}}';get defaultConfig(){return{allowHideAll:!1}}columnListElement=null;isDragging=!1;draggedField=null;draggedIndex=null;dropIndex=null;draggedGroupId=null;draggedGroupFields=[];clearDragClasses(e){e.querySelectorAll(".tbw-visibility-row, .tbw-visibility-group-header").forEach(e=>{e.classList.remove("dragging","drop-target","drop-before","drop-after")})}attach(e){super.attach(e),e.addEventListener("column-move",()=>{this.columnListElement&&requestAnimationFrame(()=>{this.columnListElement&&this.rebuildToggles(this.columnListElement)})},{signal:this.disconnectSignal})}detach(){this.columnListElement=null,this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null}handleQuery(e){if("getContextMenuItems"===e.type){const t=e.context;if(!t.isHeader)return;const i=t.column;if(!i?.field)return;if(i.meta?.lockVisibility)return;return[{id:"visibility/hide-column",label:"Hide Column",icon:"👁",order:30,action:()=>this.hideColumn(i.field)}]}}getToolPanel(){return{id:s.PANEL_ID,title:"Columns",icon:"☰",tooltip:"Column visibility",order:100,render:e=>this.renderPanelContent(e)}}show(){this.grid.openToolPanel(),this.grid.expandedToolPanelSections.includes(s.PANEL_ID)||this.grid.toggleToolPanelSection(s.PANEL_ID)}hide(){this.grid.closeToolPanel()}toggle(){this.grid.isToolPanelOpen||this.grid.openToolPanel(),this.grid.toggleToolPanelSection(s.PANEL_ID)}isColumnVisible(e){return this.grid.isColumnVisible(e)}setColumnVisible(e,t){this.grid.setColumnVisible(e,t)}getVisibleColumns(){return this.grid.getAllColumns().filter(e=>e.visible).map(e=>e.field)}getHiddenColumns(){return this.grid.getAllColumns().filter(e=>!e.visible).map(e=>e.field)}showAll(){this.grid.showAllColumns()}toggleColumn(e){this.grid.toggleColumnVisibility(e)}showColumn(e){this.setColumnVisible(e,!0)}hideColumn(e){this.setColumnVisible(e,!1)}getAllColumns(){return this.grid.getAllColumns()}isPanelVisible(){return this.grid.isToolPanelOpen&&this.grid.expandedToolPanelSections.includes(s.PANEL_ID)}renderPanelContent(e){const t=document.createElement("div");t.className="tbw-visibility-content";const i=document.createElement("div");i.className="tbw-visibility-list",t.appendChild(i);const r=document.createElement("button");return r.className="tbw-visibility-show-all",r.textContent="Show All",r.addEventListener("click",()=>{this.grid.showAllColumns(),this.rebuildToggles(i)}),t.appendChild(r),this.columnListElement=i,this.rebuildToggles(i),e.appendChild(t),()=>{this.columnListElement=null,t.remove()}}hasReorderPlugin(){const e=this.grid?.getPluginByName?.("reorder");return!(!e||"function"!=typeof e.moveColumn)}rebuildToggles(e){const t=this.hasReorderPlugin();e.innerHTML="";const i=this.grid.getAllColumns().filter(e=>!e.utility),r=this.grid.query("getColumnGrouping"),s=r?.flat().filter(e=>e&&e.fields.length>0)??[];if(0===s.length)return void this.renderFlatColumnList(i,t,e);const n=/* @__PURE__ */new Map;for(const o of s)for(const e of o.fields)n.set(e,o);const l=/* @__PURE__ */new Set;for(const o of i){const r=n.get(o.field);if(r){if(!l.has(r.id)){l.add(r.id);const s=new Set(r.fields),n=i.filter(e=>s.has(e.field));n.length>0&&this.renderGroupSection(r,n,t,e)}}else{const r=i.indexOf(o);e.appendChild(this.createColumnRow(o,r,t,e))}}}renderGroupSection(e,t,i,r){const s=document.createElement("div");s.className="tbw-visibility-group-header",s.setAttribute("data-group-id",e.id),i&&(s.draggable=!0,s.classList.add("reorderable"),this.setupGroupDragListeners(s,e,r));const n=document.createElement("label");n.className="tbw-visibility-label";const l=document.createElement("input");l.type="checkbox";const o=t.filter(e=>e.visible).length,d=t.every(e=>e.lockVisible);o===t.length?(l.checked=!0,l.indeterminate=!1):0===o?(l.checked=!1,l.indeterminate=!1):(l.checked=!1,l.indeterminate=!0),l.disabled=d,l.addEventListener("change",()=>{const e=l.checked;for(const i of t)i.lockVisible||this.grid.setColumnVisible(i.field,e);setTimeout(()=>this.rebuildToggles(r),0)});const a=document.createElement("span");if(a.textContent=e.label,n.appendChild(l),n.appendChild(a),s.appendChild(n),i){const e=document.createElement("span");e.className="tbw-visibility-handle",this.setIcon(e,this.resolveIcon("dragHandle")),e.title="Drag to reorder group",s.insertBefore(e,n)}r.appendChild(s);const g=this.grid.getAllColumns().filter(e=>!e.utility);for(const c of t){const e=g.findIndex(e=>e.field===c.field),t=this.createColumnRow(c,e,i,r);t.classList.add("tbw-visibility-row--grouped"),r.appendChild(t)}}renderFlatColumnList(e,t,i){const r=this.grid.getAllColumns().filter(e=>!e.utility);for(const s of e){const e=r.findIndex(e=>e.field===s.field);i.appendChild(this.createColumnRow(s,e,t,i))}}createColumnRow(e,t,i,s){const n=e.header||e.field,l=document.createElement("div");l.className=e.lockVisible?"tbw-visibility-row locked":"tbw-visibility-row",l.setAttribute("data-field",e.field),l.setAttribute("data-index",String(t)),i&&r(e)&&(l.draggable=!0,l.classList.add("reorderable"),this.setupDragListeners(l,e.field,t,s));const o=document.createElement("label");o.className="tbw-visibility-label";const d=document.createElement("input");d.type="checkbox",d.checked=e.visible,d.disabled=e.lockVisible??!1,d.addEventListener("change",()=>{this.grid.toggleColumnVisibility(e.field),setTimeout(()=>this.rebuildToggles(s),0)});const a=document.createElement("span");if(a.textContent=n,o.appendChild(d),o.appendChild(a),i&&r(e)){const e=document.createElement("span");e.className="tbw-visibility-handle",this.setIcon(e,this.resolveIcon("dragHandle")),e.title="Drag to reorder",l.appendChild(e)}return l.appendChild(o),l}setupGroupDragListeners(e,t,i){e.addEventListener("dragstart",r=>{this.isDragging=!0,this.draggedGroupId=t.id,this.draggedGroupFields=[...t.fields],this.draggedField=null,this.draggedIndex=null,r.dataTransfer&&(r.dataTransfer.effectAllowed="move",r.dataTransfer.setData("text/plain",`group:${t.id}`)),e.classList.add("dragging"),i.querySelectorAll(".tbw-visibility-row--grouped").forEach(e=>{const t=e.getAttribute("data-field");t&&this.draggedGroupFields.includes(t)&&e.classList.add("dragging")})}),e.addEventListener("dragend",()=>{this.isDragging=!1,this.draggedGroupId=null,this.draggedGroupFields=[],this.draggedField=null,this.draggedIndex=null,this.dropIndex=null,this.clearDragClasses(i)}),e.addEventListener("dragover",r=>{if(r.preventDefault(),!this.isDragging)return;if(this.draggedGroupId===t.id)return;if(!this.draggedGroupId)return;const s=e.getBoundingClientRect(),n=s.top+s.height/2,l=r.clientY<n;this.clearDragClasses(i),e.classList.add("drop-target"),e.classList.toggle("drop-before",l),e.classList.toggle("drop-after",!l)}),e.addEventListener("dragleave",()=>{e.classList.remove("drop-target","drop-before","drop-after")}),e.addEventListener("drop",r=>{if(r.preventDefault(),!this.isDragging||!this.draggedGroupId||this.draggedGroupId===t.id)return;const s=e.getBoundingClientRect(),n=r.clientY<s.top+s.height/2;this.executeGroupDrop(this.draggedGroupFields,t.fields,n,i)})}executeGroupDrop(e,t,i,r){const s=this.grid.getAllColumns().map(e=>e.field),n=s.filter(t=>!e.includes(t)),l=i?t[0]:t[t.length-1],o=n.indexOf(l);if(-1===o)return;const d=i?o:o+1,a=s.filter(t=>e.includes(t));n.splice(d,0,...a),this.grid.setColumnOrder(n),requestAnimationFrame(()=>{this.columnListElement&&this.rebuildToggles(this.columnListElement)})}setupDragListeners(e,t,i,r){e.addEventListener("dragstart",r=>{this.isDragging=!0,this.draggedField=t,this.draggedIndex=i,this.draggedGroupId=null,this.draggedGroupFields=[],r.dataTransfer&&(r.dataTransfer.effectAllowed="move",r.dataTransfer.setData("text/plain",t)),e.classList.add("dragging")}),e.addEventListener("dragend",()=>{this.isDragging=!1,this.draggedField=null,this.draggedIndex=null,this.dropIndex=null,this.clearDragClasses(r)}),e.addEventListener("dragover",s=>{if(s.preventDefault(),!this.isDragging)return;if(this.draggedGroupId){if(e.classList.contains("tbw-visibility-row--grouped"))return}else if(this.draggedField===t)return;const n=e.getBoundingClientRect(),l=n.top+n.height/2;this.dropIndex=s.clientY<l?i:i+1,this.clearDragClasses(r),this.draggedGroupId?(r.querySelector(`.tbw-visibility-group-header[data-group-id="${this.draggedGroupId}"]`)?.classList.add("dragging"),r.querySelectorAll(".tbw-visibility-row--grouped").forEach(e=>{const t=e.getAttribute("data-field");t&&this.draggedGroupFields.includes(t)&&e.classList.add("dragging")})):this.draggedField&&r.querySelector(`.tbw-visibility-row[data-field="${this.draggedField}"]`)?.classList.add("dragging"),e.classList.add("drop-target"),e.classList.toggle("drop-before",s.clientY<l),e.classList.toggle("drop-after",s.clientY>=l)}),e.addEventListener("dragleave",()=>{e.classList.remove("drop-target","drop-before","drop-after")}),e.addEventListener("drop",i=>{if(i.preventDefault(),!this.isDragging)return;if(this.draggedGroupId&&this.draggedGroupFields.length>0){if(e.classList.contains("tbw-visibility-row--grouped"))return;const s=e.getBoundingClientRect(),n=i.clientY<s.top+s.height/2;return void this.executeGroupDrop(this.draggedGroupFields,[t],n,r)}const s=this.draggedField,n=this.draggedIndex,l=this.dropIndex;if(null===s||null===n||null===l)return;const o=l>n?l-1:l;if(o!==n){const e=this.grid.getAllColumns(),t=e.filter(e=>!e.utility),i=t[o]?.field,r={field:s,fromIndex:n,toIndex:i?e.findIndex(e=>e.field===i):e.length};this.emit("column-reorder-request",r)}})}}export{s as VisibilityPlugin};
793
2
  //# sourceMappingURL=index.js.map