@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.
Files changed (109) hide show
  1. package/all.js +2 -6850
  2. package/all.js.map +1 -1
  3. package/index.js +1 -4352
  4. package/index.js.map +1 -1
  5. package/lib/core/grid.d.ts +22 -6
  6. package/lib/core/grid.d.ts.map +1 -1
  7. package/lib/core/styles/index.d.ts.map +1 -1
  8. package/lib/plugins/clipboard/index.js +1 -733
  9. package/lib/plugins/clipboard/index.js.map +1 -1
  10. package/lib/plugins/column-virtualization/index.js +1 -560
  11. package/lib/plugins/column-virtualization/index.js.map +1 -1
  12. package/lib/plugins/context-menu/index.js +1 -754
  13. package/lib/plugins/context-menu/index.js.map +1 -1
  14. package/lib/plugins/editing/EditingPlugin.d.ts.map +1 -1
  15. package/lib/plugins/editing/index.d.ts +1 -1
  16. package/lib/plugins/editing/index.d.ts.map +1 -1
  17. package/lib/plugins/editing/index.js +1 -1539
  18. package/lib/plugins/editing/index.js.map +1 -1
  19. package/lib/plugins/editing/types.d.ts +23 -0
  20. package/lib/plugins/editing/types.d.ts.map +1 -1
  21. package/lib/plugins/export/index.js +1 -589
  22. package/lib/plugins/export/index.js.map +1 -1
  23. package/lib/plugins/filtering/FilteringPlugin.d.ts.map +1 -1
  24. package/lib/plugins/filtering/filter-model.d.ts.map +1 -1
  25. package/lib/plugins/filtering/index.js +1 -1283
  26. package/lib/plugins/filtering/index.js.map +1 -1
  27. package/lib/plugins/filtering/types.d.ts +4 -2
  28. package/lib/plugins/filtering/types.d.ts.map +1 -1
  29. package/lib/plugins/grouping-columns/index.js +1 -726
  30. package/lib/plugins/grouping-columns/index.js.map +1 -1
  31. package/lib/plugins/grouping-rows/index.js +2 -905
  32. package/lib/plugins/grouping-rows/index.js.map +1 -1
  33. package/lib/plugins/master-detail/index.js +1 -950
  34. package/lib/plugins/master-detail/index.js.map +1 -1
  35. package/lib/plugins/multi-sort/index.js +1 -553
  36. package/lib/plugins/multi-sort/index.js.map +1 -1
  37. package/lib/plugins/pinned-columns/index.js +1 -688
  38. package/lib/plugins/pinned-columns/index.js.map +1 -1
  39. package/lib/plugins/pinned-rows/index.js +1 -704
  40. package/lib/plugins/pinned-rows/index.js.map +1 -1
  41. package/lib/plugins/pivot/index.js +1 -1191
  42. package/lib/plugins/pivot/index.js.map +1 -1
  43. package/lib/plugins/print/index.js +1 -691
  44. package/lib/plugins/print/index.js.map +1 -1
  45. package/lib/plugins/reorder/index.js +1 -703
  46. package/lib/plugins/reorder/index.js.map +1 -1
  47. package/lib/plugins/responsive/index.js +1 -971
  48. package/lib/plugins/responsive/index.js.map +1 -1
  49. package/lib/plugins/row-reorder/index.js +1 -728
  50. package/lib/plugins/row-reorder/index.js.map +1 -1
  51. package/lib/plugins/selection/index.js +1 -1071
  52. package/lib/plugins/selection/index.js.map +1 -1
  53. package/lib/plugins/server-side/index.js +1 -521
  54. package/lib/plugins/server-side/index.js.map +1 -1
  55. package/lib/plugins/tree/index.js +1 -686
  56. package/lib/plugins/tree/index.js.map +1 -1
  57. package/lib/plugins/undo-redo/index.js +1 -584
  58. package/lib/plugins/undo-redo/index.js.map +1 -1
  59. package/lib/plugins/visibility/index.js +1 -792
  60. package/lib/plugins/visibility/index.js.map +1 -1
  61. package/package.json +4 -5
  62. package/umd/grid.all.umd.js +1 -186
  63. package/umd/grid.all.umd.js.map +1 -1
  64. package/umd/grid.umd.js +1 -90
  65. package/umd/grid.umd.js.map +1 -1
  66. package/umd/plugins/clipboard.umd.js +1 -6
  67. package/umd/plugins/clipboard.umd.js.map +1 -1
  68. package/umd/plugins/column-virtualization.umd.js +1 -1
  69. package/umd/plugins/column-virtualization.umd.js.map +1 -1
  70. package/umd/plugins/context-menu.umd.js +1 -1
  71. package/umd/plugins/context-menu.umd.js.map +1 -1
  72. package/umd/plugins/editing.umd.js +1 -1
  73. package/umd/plugins/editing.umd.js.map +1 -1
  74. package/umd/plugins/export.umd.js +1 -13
  75. package/umd/plugins/export.umd.js.map +1 -1
  76. package/umd/plugins/filtering.umd.js +1 -1
  77. package/umd/plugins/filtering.umd.js.map +1 -1
  78. package/umd/plugins/grouping-columns.umd.js +1 -1
  79. package/umd/plugins/grouping-columns.umd.js.map +1 -1
  80. package/umd/plugins/grouping-rows.umd.js +1 -4
  81. package/umd/plugins/grouping-rows.umd.js.map +1 -1
  82. package/umd/plugins/master-detail.umd.js +1 -1
  83. package/umd/plugins/master-detail.umd.js.map +1 -1
  84. package/umd/plugins/multi-sort.umd.js +1 -1
  85. package/umd/plugins/multi-sort.umd.js.map +1 -1
  86. package/umd/plugins/pinned-columns.umd.js +1 -1
  87. package/umd/plugins/pinned-columns.umd.js.map +1 -1
  88. package/umd/plugins/pinned-rows.umd.js +1 -1
  89. package/umd/plugins/pinned-rows.umd.js.map +1 -1
  90. package/umd/plugins/pivot.umd.js +1 -1
  91. package/umd/plugins/pivot.umd.js.map +1 -1
  92. package/umd/plugins/print.umd.js +1 -75
  93. package/umd/plugins/print.umd.js.map +1 -1
  94. package/umd/plugins/reorder.umd.js +1 -1
  95. package/umd/plugins/reorder.umd.js.map +1 -1
  96. package/umd/plugins/responsive.umd.js +1 -1
  97. package/umd/plugins/responsive.umd.js.map +1 -1
  98. package/umd/plugins/row-reorder.umd.js +1 -1
  99. package/umd/plugins/row-reorder.umd.js.map +1 -1
  100. package/umd/plugins/selection.umd.js +1 -3
  101. package/umd/plugins/selection.umd.js.map +1 -1
  102. package/umd/plugins/server-side.umd.js +1 -1
  103. package/umd/plugins/server-side.umd.js.map +1 -1
  104. package/umd/plugins/tree.umd.js +1 -1
  105. package/umd/plugins/tree.umd.js.map +1 -1
  106. package/umd/plugins/undo-redo.umd.js +1 -1
  107. package/umd/plugins/undo-redo.umd.js.map +1 -1
  108. package/umd/plugins/visibility.umd.js +1 -1
  109. package/umd/plugins/visibility.umd.js.map +1 -1
@@ -1,561 +1,2 @@
1
- const c = '<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: c,
11
- filterActive: c,
12
- print: "🖨️"
13
- };
14
- class b {
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
- #t;
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(t = {}) {
87
- this.userConfig = t;
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(t) {
105
- this.#t?.abort(), this.#t = new AbortController(), this.grid = t, 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.#t?.abort(), this.#t = 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(t) {
136
- return this.grid?.getPlugin(t);
137
- }
138
- /**
139
- * Emit a custom event from the grid.
140
- */
141
- emit(t, e) {
142
- this.grid?.dispatchEvent?.(new CustomEvent(t, { detail: e, 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(t, e) {
149
- const i = new CustomEvent(t, { detail: e, 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(t, e) {
172
- this.grid?._pluginManager?.subscribe(this, t, e);
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(t) {
186
- this.grid?._pluginManager?.unsubscribe(this, t);
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(t, e) {
207
- this.grid?._pluginManager?.emitPluginEvent(t, e);
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.#t?.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 t = this.grid?.gridConfig?.icons ?? {};
304
- return { ...p, ...t };
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 t = this.grid?.effectiveConfig?.animation?.mode ?? "reduced-motion";
325
- if (t === !1 || t === "off") return !1;
326
- if (t === !0 || t === "on") return !0;
327
- const e = this.gridElement;
328
- return e ? getComputedStyle(e).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 t = this.gridElement;
344
- if (t) {
345
- const e = getComputedStyle(t).getPropertyValue("--tbw-animation-duration").trim(), i = parseInt(e, 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(t, e) {
360
- return e !== void 0 ? e : this.gridIcons[t];
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(t, e) {
370
- typeof e == "string" ? t.innerHTML = e : e instanceof HTMLElement && (t.innerHTML = "", t.appendChild(e.cloneNode(!0)));
371
- }
372
- /**
373
- * Log a warning message.
374
- */
375
- warn(t) {
376
- console.warn(`[tbw-grid:${this.name}] ${t}`);
377
- }
378
- // #endregion
379
- }
380
- const g = 100;
381
- function h(s) {
382
- if (s == null)
383
- return g;
384
- if (typeof s == "number")
385
- return s;
386
- const t = parseFloat(s);
387
- return isNaN(t) ? g : t;
388
- }
389
- function f(s) {
390
- return s.map((t) => h(t.width));
391
- }
392
- function m(s) {
393
- const t = [];
394
- let e = 0;
395
- for (const i of s)
396
- t.push(e), e += h(i.width);
397
- return t;
398
- }
399
- function C(s) {
400
- return s.reduce((t, e) => t + h(e.width), 0);
401
- }
402
- function w(s, t, e, i, o) {
403
- const r = e.length;
404
- if (r === 0)
405
- return { startCol: 0, endCol: 0, visibleColumns: [] };
406
- let n = y(s, e, i);
407
- n = Math.max(0, n - o);
408
- const a = s + t;
409
- let u = n;
410
- for (let l = n; l < r; l++) {
411
- if (e[l] >= a) {
412
- u = l - 1;
413
- break;
414
- }
415
- u = l;
416
- }
417
- u = Math.min(r - 1, u + o);
418
- const d = [];
419
- for (let l = n; l <= u; l++)
420
- d.push(l);
421
- return { startCol: n, endCol: u, visibleColumns: d };
422
- }
423
- function y(s, t, e) {
424
- let i = 0, o = t.length - 1;
425
- for (; i < o; ) {
426
- const r = Math.floor((i + o) / 2);
427
- t[r] + e[r] <= s ? i = r + 1 : o = r;
428
- }
429
- return i;
430
- }
431
- function R(s, t, e) {
432
- return e ? s > t : !1;
433
- }
434
- class E extends b {
435
- /** @internal */
436
- name = "columnVirtualization";
437
- /** @internal */
438
- get defaultConfig() {
439
- return {
440
- autoEnable: !0,
441
- threshold: 30,
442
- overscan: 3
443
- };
444
- }
445
- // #region Internal State
446
- isVirtualized = !1;
447
- startCol = 0;
448
- endCol = 0;
449
- scrollLeft = 0;
450
- totalWidth = 0;
451
- columnWidths = [];
452
- columnOffsets = [];
453
- /** Store the original full column set for virtualization calculations */
454
- originalColumns = [];
455
- // #endregion
456
- // #region Lifecycle
457
- /** @internal */
458
- attach(t) {
459
- super.attach(t);
460
- const e = this.columns;
461
- this.columnWidths = f(e), this.columnOffsets = m(e), this.totalWidth = C(e), this.endCol = e.length - 1;
462
- }
463
- /** @internal */
464
- detach() {
465
- this.#t(), this.columnWidths = [], this.columnOffsets = [], this.originalColumns = [], this.isVirtualized = !1, this.startCol = 0, this.endCol = 0, this.scrollLeft = 0, this.totalWidth = 0;
466
- }
467
- /**
468
- * Remove inline styles set by this plugin for proper cleanup.
469
- */
470
- #t() {
471
- const t = this.gridElement;
472
- if (!t) return;
473
- const e = t.querySelector(".header-row");
474
- e && (e.style.paddingLeft = "", e.style.minWidth = ""), t.querySelectorAll(".data-grid-row").forEach((n) => {
475
- n.style.paddingLeft = "";
476
- });
477
- const o = t.querySelector(".rows-viewport .rows");
478
- o && (o.style.width = "");
479
- const r = t.querySelector(".rows-body");
480
- r && (r.style.minWidth = "");
481
- }
482
- // #endregion
483
- // #region Hooks
484
- /** @internal */
485
- processColumns(t) {
486
- (this.originalColumns.length === 0 || t.length >= this.originalColumns.length) && (this.originalColumns = t, this.columnWidths = f(t), this.columnOffsets = m(t), this.totalWidth = C(t));
487
- const i = this.originalColumns, o = R(
488
- i.length,
489
- this.config.threshold ?? 30,
490
- this.config.autoEnable ?? !0
491
- );
492
- if (this.isVirtualized = o ?? !1, !o)
493
- return this.startCol = 0, this.endCol = i.length - 1, [...i];
494
- const r = this.grid.clientWidth || 800, n = w(
495
- this.scrollLeft,
496
- r,
497
- this.columnOffsets,
498
- this.columnWidths,
499
- this.config.overscan ?? 3
500
- );
501
- return this.startCol = n.startCol, this.endCol = n.endCol, n.visibleColumns.map((a) => i[a]);
502
- }
503
- /** @internal */
504
- afterRender() {
505
- if (!this.isVirtualized) return;
506
- const t = this.gridElement;
507
- if (!t) return;
508
- const e = this.columnOffsets[this.startCol] ?? 0, i = t.querySelector(".header-row"), o = t.querySelectorAll(".data-grid-row");
509
- i && (i.style.paddingLeft = `${e}px`, i.style.minWidth = `${this.totalWidth}px`), o.forEach((a) => {
510
- a.style.paddingLeft = `${e}px`;
511
- });
512
- const r = t.querySelector(".rows-viewport .rows");
513
- r && (r.style.width = `${this.totalWidth}px`);
514
- const n = t.querySelector(".rows-body");
515
- n && (n.style.minWidth = `${this.totalWidth}px`);
516
- }
517
- /** @internal */
518
- onScroll(t) {
519
- !this.isVirtualized || Math.abs(t.scrollLeft - this.scrollLeft) < 1 || (this.scrollLeft = t.scrollLeft, this.requestColumnsRender());
520
- }
521
- // #endregion
522
- // #region Public API
523
- /**
524
- * Check if column virtualization is currently active.
525
- */
526
- getIsVirtualized() {
527
- return this.isVirtualized;
528
- }
529
- /**
530
- * Get the current visible column range.
531
- */
532
- getVisibleColumnRange() {
533
- return { start: this.startCol, end: this.endCol };
534
- }
535
- /**
536
- * Scroll the grid to bring a specific column into view.
537
- * @param columnIndex - Index of the column to scroll to
538
- */
539
- scrollToColumn(t) {
540
- const e = this.columnOffsets[t] ?? 0, i = this.grid;
541
- i.scrollLeft = e;
542
- }
543
- /**
544
- * Get the left offset for a specific column.
545
- * @param columnIndex - Index of the column
546
- */
547
- getColumnOffset(t) {
548
- return this.columnOffsets[t] ?? 0;
549
- }
550
- /**
551
- * Get the total width of all columns.
552
- */
553
- getTotalWidth() {
554
- return this.totalWidth;
555
- }
556
- // #endregion
557
- }
558
- export {
559
- E as ColumnVirtualizationPlugin
560
- };
1
+ const t='<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>',e={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:t,filterActive:t,print:"🖨️"};class i{static dependencies;static manifest;version="undefined"!=typeof __GRID_VERSION__?__GRID_VERSION__:"dev";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#t;get defaultConfig(){return{}}constructor(t={}){this.userConfig=t}attach(t){this.#t?.abort(),this.#t=new AbortController,this.grid=t,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#t?.abort(),this.#t=void 0}getPlugin(t){return this.grid?.getPlugin(t)}emit(t,e){this.grid?.dispatchEvent?.(new CustomEvent(t,{detail:e,bubbles:!0}))}emitCancelable(t,e){const i=new CustomEvent(t,{detail:e,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(i),i.defaultPrevented}on(t,e){this.grid?._pluginManager?.subscribe(this,t,e)}off(t){this.grid?._pluginManager?.unsubscribe(this,t)}emitPluginEvent(t,e){this.grid?._pluginManager?.emitPluginEvent(t,e)}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get gridElement(){return this.grid}get disconnectSignal(){return this.#t?.signal??this.grid?.disconnectSignal}get gridIcons(){const t=this.grid?.gridConfig?.icons??{};return{...e,...t}}get isAnimationEnabled(){const t=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===t||"off"===t)return!1;if(!0===t||"on"===t)return!0;const e=this.gridElement;if(e){return"0"!==getComputedStyle(e).getPropertyValue("--tbw-animation-enabled").trim()}return!0}get animationDuration(){const t=this.gridElement;if(t){const e=getComputedStyle(t).getPropertyValue("--tbw-animation-duration").trim(),i=parseInt(e,10);if(!isNaN(i))return i}return 200}resolveIcon(t,e){return void 0!==e?e:this.gridIcons[t]}setIcon(t,e){"string"==typeof e?t.innerHTML=e:e instanceof HTMLElement&&(t.innerHTML="",t.appendChild(e.cloneNode(!0)))}warn(t){console.warn(`[tbw-grid:${this.name}] ${t}`)}}function r(t){if(null==t)return 100;if("number"==typeof t)return t;const e=parseFloat(t);return isNaN(e)?100:e}function s(t){return t.map(t=>r(t.width))}function n(t){const e=[];let i=0;for(const s of t)e.push(i),i+=r(s.width);return e}function o(t){return t.reduce((t,e)=>t+r(e.width),0)}function l(t,e,i,r,s){const n=i.length;if(0===n)return{startCol:0,endCol:0,visibleColumns:[]};let o=function(t,e,i){let r=0,s=e.length-1;for(;r<s;){const n=Math.floor((r+s)/2);e[n]+i[n]<=t?r=n+1:s=n}return r}(t,i,r);o=Math.max(0,o-s);const l=t+e;let h=o;for(let u=o;u<n;u++){if(i[u]>=l){h=u-1;break}h=u}h=Math.min(n-1,h+s);const a=[];for(let u=o;u<=h;u++)a.push(u);return{startCol:o,endCol:h,visibleColumns:a}}class h extends i{name="columnVirtualization";get defaultConfig(){return{autoEnable:!0,threshold:30,overscan:3}}isVirtualized=!1;startCol=0;endCol=0;scrollLeft=0;totalWidth=0;columnWidths=[];columnOffsets=[];originalColumns=[];attach(t){super.attach(t);const e=this.columns;this.columnWidths=s(e),this.columnOffsets=n(e),this.totalWidth=o(e),this.endCol=e.length-1}detach(){this.#e(),this.columnWidths=[],this.columnOffsets=[],this.originalColumns=[],this.isVirtualized=!1,this.startCol=0,this.endCol=0,this.scrollLeft=0,this.totalWidth=0}#e(){const t=this.gridElement;if(!t)return;const e=t.querySelector(".header-row");e&&(e.style.paddingLeft="",e.style.minWidth="");t.querySelectorAll(".data-grid-row").forEach(t=>{t.style.paddingLeft=""});const i=t.querySelector(".rows-viewport .rows");i&&(i.style.width="");const r=t.querySelector(".rows-body");r&&(r.style.minWidth="")}processColumns(t){(0===this.originalColumns.length||t.length>=this.originalColumns.length)&&(this.originalColumns=t,this.columnWidths=s(t),this.columnOffsets=n(t),this.totalWidth=o(t));const e=this.originalColumns,i=(r=e.length,h=this.config.threshold??30,!!(this.config.autoEnable??!0)&&r>h);var r,h;if(this.isVirtualized=i??!1,!i)return this.startCol=0,this.endCol=e.length-1,[...e];const a=this.grid.clientWidth||800,u=l(this.scrollLeft,a,this.columnOffsets,this.columnWidths,this.config.overscan??3);return this.startCol=u.startCol,this.endCol=u.endCol,u.visibleColumns.map(t=>e[t])}afterRender(){if(!this.isVirtualized)return;const t=this.gridElement;if(!t)return;const e=this.columnOffsets[this.startCol]??0,i=t.querySelector(".header-row"),r=t.querySelectorAll(".data-grid-row");i&&(i.style.paddingLeft=`${e}px`,i.style.minWidth=`${this.totalWidth}px`),r.forEach(t=>{t.style.paddingLeft=`${e}px`});const s=t.querySelector(".rows-viewport .rows");s&&(s.style.width=`${this.totalWidth}px`);const n=t.querySelector(".rows-body");n&&(n.style.minWidth=`${this.totalWidth}px`)}onScroll(t){if(!this.isVirtualized)return;Math.abs(t.scrollLeft-this.scrollLeft)<1||(this.scrollLeft=t.scrollLeft,this.requestColumnsRender())}getIsVirtualized(){return this.isVirtualized}getVisibleColumnRange(){return{start:this.startCol,end:this.endCol}}scrollToColumn(t){const e=this.columnOffsets[t]??0;this.grid.scrollLeft=e}getColumnOffset(t){return this.columnOffsets[t]??0}getTotalWidth(){return this.totalWidth}}export{h as ColumnVirtualizationPlugin};
561
2
  //# sourceMappingURL=index.js.map