@toolbox-web/grid 1.3.0 → 1.4.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 (82) hide show
  1. package/all.d.ts +1 -0
  2. package/all.d.ts.map +1 -1
  3. package/all.js +997 -710
  4. package/all.js.map +1 -1
  5. package/index.js +642 -599
  6. package/index.js.map +1 -1
  7. package/lib/core/grid.d.ts.map +1 -1
  8. package/lib/core/internal/header.d.ts +7 -0
  9. package/lib/core/internal/header.d.ts.map +1 -1
  10. package/lib/core/types.d.ts +151 -0
  11. package/lib/core/types.d.ts.map +1 -1
  12. package/lib/plugins/clipboard/index.js +19 -16
  13. package/lib/plugins/clipboard/index.js.map +1 -1
  14. package/lib/plugins/column-virtualization/index.js +42 -39
  15. package/lib/plugins/column-virtualization/index.js.map +1 -1
  16. package/lib/plugins/context-menu/index.js +25 -22
  17. package/lib/plugins/context-menu/index.js.map +1 -1
  18. package/lib/plugins/editing/EditingPlugin.d.ts.map +1 -1
  19. package/lib/plugins/editing/index.js +53 -48
  20. package/lib/plugins/editing/index.js.map +1 -1
  21. package/lib/plugins/export/index.js +23 -20
  22. package/lib/plugins/export/index.js.map +1 -1
  23. package/lib/plugins/filtering/FilteringPlugin.d.ts +11 -1
  24. package/lib/plugins/filtering/FilteringPlugin.d.ts.map +1 -1
  25. package/lib/plugins/filtering/index.js +186 -150
  26. package/lib/plugins/filtering/index.js.map +1 -1
  27. package/lib/plugins/grouping-columns/index.js +21 -18
  28. package/lib/plugins/grouping-columns/index.js.map +1 -1
  29. package/lib/plugins/grouping-rows/index.js +67 -64
  30. package/lib/plugins/grouping-rows/index.js.map +1 -1
  31. package/lib/plugins/master-detail/index.js +52 -49
  32. package/lib/plugins/master-detail/index.js.map +1 -1
  33. package/lib/plugins/multi-sort/index.js +18 -15
  34. package/lib/plugins/multi-sort/index.js.map +1 -1
  35. package/lib/plugins/pinned-columns/index.js +25 -22
  36. package/lib/plugins/pinned-columns/index.js.map +1 -1
  37. package/lib/plugins/pinned-rows/index.js +26 -23
  38. package/lib/plugins/pinned-rows/index.js.map +1 -1
  39. package/lib/plugins/pivot/index.js +50 -47
  40. package/lib/plugins/pivot/index.js.map +1 -1
  41. package/lib/plugins/print/PrintPlugin.d.ts +98 -0
  42. package/lib/plugins/print/PrintPlugin.d.ts.map +1 -0
  43. package/lib/plugins/print/index.d.ts +10 -0
  44. package/lib/plugins/print/index.d.ts.map +1 -0
  45. package/lib/plugins/print/index.js +626 -0
  46. package/lib/plugins/print/index.js.map +1 -0
  47. package/lib/plugins/print/print-isolated.d.ts +26 -0
  48. package/lib/plugins/print/print-isolated.d.ts.map +1 -0
  49. package/lib/plugins/print/types.d.ts +147 -0
  50. package/lib/plugins/print/types.d.ts.map +1 -0
  51. package/lib/plugins/reorder/index.js +25 -22
  52. package/lib/plugins/reorder/index.js.map +1 -1
  53. package/lib/plugins/responsive/index.js +20 -17
  54. package/lib/plugins/responsive/index.js.map +1 -1
  55. package/lib/plugins/row-reorder/index.js +39 -36
  56. package/lib/plugins/row-reorder/index.js.map +1 -1
  57. package/lib/plugins/selection/SelectionPlugin.d.ts.map +1 -1
  58. package/lib/plugins/selection/index.js +115 -101
  59. package/lib/plugins/selection/index.js.map +1 -1
  60. package/lib/plugins/server-side/index.js +35 -32
  61. package/lib/plugins/server-side/index.js.map +1 -1
  62. package/lib/plugins/tree/index.js +26 -23
  63. package/lib/plugins/tree/index.js.map +1 -1
  64. package/lib/plugins/undo-redo/index.js +23 -20
  65. package/lib/plugins/undo-redo/index.js.map +1 -1
  66. package/lib/plugins/visibility/index.js +22 -19
  67. package/lib/plugins/visibility/index.js.map +1 -1
  68. package/package.json +1 -1
  69. package/public.d.ts +1 -1
  70. package/public.d.ts.map +1 -1
  71. package/umd/grid.all.umd.js +98 -24
  72. package/umd/grid.all.umd.js.map +1 -1
  73. package/umd/grid.umd.js +11 -11
  74. package/umd/grid.umd.js.map +1 -1
  75. package/umd/plugins/editing.umd.js +1 -1
  76. package/umd/plugins/editing.umd.js.map +1 -1
  77. package/umd/plugins/filtering.umd.js +1 -1
  78. package/umd/plugins/filtering.umd.js.map +1 -1
  79. package/umd/plugins/print.umd.js +76 -0
  80. package/umd/plugins/print.umd.js.map +1 -0
  81. package/umd/plugins/selection.umd.js +2 -2
  82. package/umd/plugins/selection.umd.js.map +1 -1
@@ -0,0 +1,626 @@
1
+ const h = "tbw-print-isolation-style";
2
+ function p(r, t) {
3
+ const e = document.createElement("style");
4
+ return e.id = h, e.textContent = `
5
+ /* Print isolation: hide everything except the target grid */
6
+ @media print {
7
+ /* Hide all body children by default */
8
+ body > *:not(#${r}) {
9
+ display: none !important;
10
+ }
11
+
12
+ /* But show the grid and ensure it's not hidden by ancestor rules */
13
+ #${r} {
14
+ display: block !important;
15
+ position: static !important;
16
+ visibility: visible !important;
17
+ opacity: 1 !important;
18
+ overflow: visible !important;
19
+ height: auto !important;
20
+ width: 100% !important;
21
+ max-height: none !important;
22
+ margin: 0 !important;
23
+ padding: 0 !important;
24
+ transform: none !important;
25
+ }
26
+
27
+ /* If grid is nested, we need to show its ancestors too */
28
+ #${r},
29
+ #${r} * {
30
+ visibility: visible !important;
31
+ }
32
+
33
+ /* Walk up the DOM and show all ancestors of the grid */
34
+ body *:has(> #${r}),
35
+ body *:has(#${r}) {
36
+ display: block !important;
37
+ visibility: visible !important;
38
+ opacity: 1 !important;
39
+ overflow: visible !important;
40
+ height: auto !important;
41
+ position: static !important;
42
+ transform: none !important;
43
+ background: transparent !important;
44
+ border: none !important;
45
+ padding: 0 !important;
46
+ margin: 0 !important;
47
+ }
48
+
49
+ /* Hide siblings of ancestors (everything that's not in the path to the grid) */
50
+ body *:has(#${r}) > *:not(:has(#${r})):not(#${r}) {
51
+ display: none !important;
52
+ }
53
+
54
+ /* Page settings */
55
+ @page {
56
+ size: ${t};
57
+ margin: 1cm;
58
+ }
59
+
60
+ /* Ensure proper print styling */
61
+ body {
62
+ margin: 0 !important;
63
+ padding: 0 !important;
64
+ background: white !important;
65
+ color-scheme: light !important;
66
+ }
67
+ }
68
+
69
+ /* Screen: also apply isolation for print preview */
70
+ @media screen {
71
+ /* When this stylesheet is active, we're about to print */
72
+ /* No screen-specific rules needed - isolation only applies to print */
73
+ }
74
+ `, e;
75
+ }
76
+ async function u(r, t = {}) {
77
+ const { orientation: e = "landscape" } = t, i = r.id;
78
+ document.querySelectorAll(`#${CSS.escape(i)}`).length > 1 && console.warn(
79
+ `[tbw-grid:print] Multiple elements found with id="${i}". Print isolation may not work correctly. Ensure each grid has a unique ID.`
80
+ ), document.getElementById(h)?.remove();
81
+ const s = p(i, e);
82
+ return document.head.appendChild(s), new Promise((a) => {
83
+ const l = () => {
84
+ window.removeEventListener("afterprint", l), document.getElementById(h)?.remove(), a();
85
+ };
86
+ window.addEventListener("afterprint", l), window.print(), setTimeout(() => {
87
+ window.removeEventListener("afterprint", l), document.getElementById(h)?.remove(), a();
88
+ }, 5e3);
89
+ });
90
+ }
91
+ 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>', g = {
92
+ expand: "▶",
93
+ collapse: "▼",
94
+ sortAsc: "▲",
95
+ sortDesc: "▼",
96
+ sortNone: "⇅",
97
+ submenuArrow: "▶",
98
+ dragHandle: "⋮⋮",
99
+ toolPanel: "☰",
100
+ filter: m,
101
+ filterActive: m,
102
+ print: "🖨️"
103
+ };
104
+ class w {
105
+ /**
106
+ * Plugin dependencies - declare other plugins this one requires.
107
+ *
108
+ * Dependencies are validated when the plugin is attached.
109
+ * Required dependencies throw an error if missing.
110
+ * Optional dependencies log an info message if missing.
111
+ *
112
+ * @example
113
+ * ```typescript
114
+ * static readonly dependencies: PluginDependency[] = [
115
+ * { name: 'editing', required: true, reason: 'Tracks cell edits for undo/redo' },
116
+ * { name: 'selection', required: false, reason: 'Enables selection-based undo' },
117
+ * ];
118
+ * ```
119
+ */
120
+ static dependencies;
121
+ /**
122
+ * Plugin manifest - declares owned properties, config rules, and hook priorities.
123
+ *
124
+ * This is read by the configuration validator to:
125
+ * - Validate that required plugins are loaded when their properties are used
126
+ * - Execute configRules to detect invalid/conflicting settings
127
+ * - Order hook execution based on priority
128
+ *
129
+ * @example
130
+ * ```typescript
131
+ * static override readonly manifest: PluginManifest<MyConfig> = {
132
+ * ownedProperties: [
133
+ * { property: 'myProp', level: 'column', description: 'the "myProp" column property' },
134
+ * ],
135
+ * configRules: [
136
+ * { id: 'myPlugin/conflict', severity: 'warn', message: '...', check: (c) => c.a && c.b },
137
+ * ],
138
+ * };
139
+ * ```
140
+ */
141
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
142
+ static manifest;
143
+ /**
144
+ * Plugin version - defaults to grid version for built-in plugins.
145
+ * Third-party plugins can override with their own semver.
146
+ */
147
+ version = typeof __GRID_VERSION__ < "u" ? __GRID_VERSION__ : "dev";
148
+ /** CSS styles to inject into the grid's shadow DOM */
149
+ styles;
150
+ /** Custom cell renderers keyed by type name */
151
+ cellRenderers;
152
+ /** Custom header renderers keyed by type name */
153
+ headerRenderers;
154
+ /** Custom cell editors keyed by type name */
155
+ cellEditors;
156
+ /** The grid instance this plugin is attached to */
157
+ grid;
158
+ /** Plugin configuration - merged with defaults in attach() */
159
+ config;
160
+ /** User-provided configuration from constructor */
161
+ userConfig;
162
+ /**
163
+ * Plugin-level AbortController for event listener cleanup.
164
+ * Created fresh in attach(), aborted in detach().
165
+ * This ensures event listeners are properly cleaned up when plugins are re-attached.
166
+ */
167
+ #t;
168
+ /**
169
+ * Default configuration - subclasses should override this getter.
170
+ * Note: This must be a getter (not property initializer) for proper inheritance
171
+ * since property initializers run after parent constructor.
172
+ */
173
+ get defaultConfig() {
174
+ return {};
175
+ }
176
+ constructor(t = {}) {
177
+ this.userConfig = t;
178
+ }
179
+ /**
180
+ * Called when the plugin is attached to a grid.
181
+ * Override to set up event listeners, initialize state, etc.
182
+ *
183
+ * @example
184
+ * ```ts
185
+ * attach(grid: GridElement): void {
186
+ * super.attach(grid);
187
+ * // Set up document-level listeners with auto-cleanup
188
+ * document.addEventListener('keydown', this.handleEscape, {
189
+ * signal: this.disconnectSignal
190
+ * });
191
+ * }
192
+ * ```
193
+ */
194
+ attach(t) {
195
+ this.#t?.abort(), this.#t = new AbortController(), this.grid = t, this.config = { ...this.defaultConfig, ...this.userConfig };
196
+ }
197
+ /**
198
+ * Called when the plugin is detached from a grid.
199
+ * Override to clean up event listeners, timers, etc.
200
+ *
201
+ * @example
202
+ * ```ts
203
+ * detach(): void {
204
+ * // Clean up any state not handled by disconnectSignal
205
+ * this.selectedRows.clear();
206
+ * this.cache = null;
207
+ * }
208
+ * ```
209
+ */
210
+ detach() {
211
+ this.#t?.abort(), this.#t = void 0;
212
+ }
213
+ /**
214
+ * Get another plugin instance from the same grid.
215
+ * Use for inter-plugin communication.
216
+ *
217
+ * @example
218
+ * ```ts
219
+ * const selection = this.getPlugin(SelectionPlugin);
220
+ * if (selection) {
221
+ * const selectedRows = selection.getSelectedRows();
222
+ * }
223
+ * ```
224
+ */
225
+ getPlugin(t) {
226
+ return this.grid?.getPlugin(t);
227
+ }
228
+ /**
229
+ * Emit a custom event from the grid.
230
+ */
231
+ emit(t, e) {
232
+ this.grid?.dispatchEvent?.(new CustomEvent(t, { detail: e, bubbles: !0 }));
233
+ }
234
+ /**
235
+ * Emit a cancelable custom event from the grid.
236
+ * @returns `true` if the event was cancelled (preventDefault called), `false` otherwise
237
+ */
238
+ emitCancelable(t, e) {
239
+ const i = new CustomEvent(t, { detail: e, bubbles: !0, cancelable: !0 });
240
+ return this.grid?.dispatchEvent?.(i), i.defaultPrevented;
241
+ }
242
+ /**
243
+ * Request a re-render of the grid.
244
+ */
245
+ requestRender() {
246
+ this.grid?.requestRender?.();
247
+ }
248
+ /**
249
+ * Request a re-render and restore focus styling afterward.
250
+ * Use this when a plugin action (like expand/collapse) triggers a render
251
+ * but needs to maintain keyboard navigation focus.
252
+ */
253
+ requestRenderWithFocus() {
254
+ this.grid?.requestRenderWithFocus?.();
255
+ }
256
+ /**
257
+ * Request a lightweight style update without rebuilding DOM.
258
+ * Use this instead of requestRender() when only CSS classes need updating.
259
+ */
260
+ requestAfterRender() {
261
+ this.grid?.requestAfterRender?.();
262
+ }
263
+ /**
264
+ * Get the current rows from the grid.
265
+ */
266
+ get rows() {
267
+ return this.grid?.rows ?? [];
268
+ }
269
+ /**
270
+ * Get the original unfiltered/unprocessed rows from the grid.
271
+ * Use this when you need all source data regardless of active filters.
272
+ */
273
+ get sourceRows() {
274
+ return this.grid?.sourceRows ?? [];
275
+ }
276
+ /**
277
+ * Get the current columns from the grid.
278
+ */
279
+ get columns() {
280
+ return this.grid?.columns ?? [];
281
+ }
282
+ /**
283
+ * Get only visible columns from the grid (excludes hidden).
284
+ * Use this for rendering that needs to match the grid template.
285
+ */
286
+ get visibleColumns() {
287
+ return this.grid?._visibleColumns ?? [];
288
+ }
289
+ /**
290
+ * Get the grid as an HTMLElement for direct DOM operations.
291
+ * Use sparingly - prefer the typed GridElementRef API when possible.
292
+ *
293
+ * @example
294
+ * ```ts
295
+ * const width = this.gridElement.clientWidth;
296
+ * this.gridElement.classList.add('my-plugin-active');
297
+ * ```
298
+ */
299
+ get gridElement() {
300
+ return this.grid;
301
+ }
302
+ /**
303
+ * Get the disconnect signal for event listener cleanup.
304
+ * This signal is aborted when the grid disconnects from the DOM.
305
+ * Use this when adding event listeners that should be cleaned up automatically.
306
+ *
307
+ * Best for:
308
+ * - Document/window-level listeners added in attach()
309
+ * - Listeners on the grid element itself
310
+ * - Any listener that should persist across renders
311
+ *
312
+ * Not needed for:
313
+ * - Listeners on elements created in afterRender() (removed with element)
314
+ *
315
+ * @example
316
+ * element.addEventListener('click', handler, { signal: this.disconnectSignal });
317
+ * document.addEventListener('keydown', handler, { signal: this.disconnectSignal });
318
+ */
319
+ get disconnectSignal() {
320
+ return this.#t?.signal ?? this.grid?.disconnectSignal;
321
+ }
322
+ /**
323
+ * Get the grid-level icons configuration.
324
+ * Returns merged icons (user config + defaults).
325
+ */
326
+ get gridIcons() {
327
+ const t = this.grid?.gridConfig?.icons ?? {};
328
+ return { ...g, ...t };
329
+ }
330
+ // #region Animation Helpers
331
+ /**
332
+ * Check if animations are enabled at the grid level.
333
+ * Respects gridConfig.animation.mode and the CSS variable set by the grid.
334
+ *
335
+ * Plugins should use this to skip animations when:
336
+ * - Animation mode is 'off' or `false`
337
+ * - User prefers reduced motion and mode is 'reduced-motion' (default)
338
+ *
339
+ * @example
340
+ * ```ts
341
+ * private get animationStyle(): 'slide' | 'fade' | false {
342
+ * if (!this.isAnimationEnabled) return false;
343
+ * return this.config.animation ?? 'slide';
344
+ * }
345
+ * ```
346
+ */
347
+ get isAnimationEnabled() {
348
+ const t = this.grid?.effectiveConfig?.animation?.mode ?? "reduced-motion";
349
+ if (t === !1 || t === "off") return !1;
350
+ if (t === !0 || t === "on") return !0;
351
+ const e = this.gridElement;
352
+ return e ? getComputedStyle(e).getPropertyValue("--tbw-animation-enabled").trim() !== "0" : !0;
353
+ }
354
+ /**
355
+ * Get the animation duration in milliseconds from CSS variable.
356
+ * Falls back to 200ms if not set.
357
+ *
358
+ * Plugins can use this for their animation timing to stay consistent
359
+ * with the grid-level animation.duration setting.
360
+ *
361
+ * @example
362
+ * ```ts
363
+ * element.animate(keyframes, { duration: this.animationDuration });
364
+ * ```
365
+ */
366
+ get animationDuration() {
367
+ const t = this.gridElement;
368
+ if (t) {
369
+ const e = getComputedStyle(t).getPropertyValue("--tbw-animation-duration").trim(), i = parseInt(e, 10);
370
+ if (!isNaN(i)) return i;
371
+ }
372
+ return 200;
373
+ }
374
+ // #endregion
375
+ /**
376
+ * Resolve an icon value to string or HTMLElement.
377
+ * Checks plugin config first, then grid-level icons, then defaults.
378
+ *
379
+ * @param iconKey - The icon key in GridIcons (e.g., 'expand', 'collapse')
380
+ * @param pluginOverride - Optional plugin-level override
381
+ * @returns The resolved icon value
382
+ */
383
+ resolveIcon(t, e) {
384
+ return e !== void 0 ? e : this.gridIcons[t];
385
+ }
386
+ /**
387
+ * Set an icon value on an element.
388
+ * Handles both string (text/HTML) and HTMLElement values.
389
+ *
390
+ * @param element - The element to set the icon on
391
+ * @param icon - The icon value (string or HTMLElement)
392
+ */
393
+ setIcon(t, e) {
394
+ typeof e == "string" ? t.innerHTML = e : e instanceof HTMLElement && (t.innerHTML = "", t.appendChild(e.cloneNode(!0)));
395
+ }
396
+ /**
397
+ * Log a warning message.
398
+ */
399
+ warn(t) {
400
+ console.warn(`[tbw-grid:${this.name}] ${t}`);
401
+ }
402
+ // #endregion
403
+ }
404
+ const b = ".tbw-print-header,.tbw-print-footer{display:none}@media print{tbw-grid{overflow:visible!important;height:auto!important;border:none!important;border-radius:0!important;color-scheme:light only;-webkit-print-color-adjust:exact;print-color-adjust:exact}tbw-grid .tbw-grid-content{overflow:visible!important;height:auto!important;max-height:none!important}tbw-grid .tbw-scroll-area{overflow:visible!important;height:auto!important;max-height:none!important}tbw-grid .rows-body{overflow:visible!important;height:auto!important;max-height:none!important}tbw-grid .rows-container,tbw-grid .rows-viewport,tbw-grid .rows{overflow:visible!important;height:auto!important;max-height:none!important;transform:none!important}tbw-grid .rows-viewport .rows{position:static!important}tbw-grid .resize-handle,tbw-grid [part=sort-indicator],tbw-grid .tbw-filter-btn,tbw-grid .tool-panel,tbw-grid .tool-panel-content,tbw-grid .tbw-shell-header,tbw-grid .shell-toolbar,tbw-grid .tool-panel-toggle,tbw-grid [data-print-hide],tbw-grid .expander-cell,tbw-grid .tree-toggle,tbw-grid .context-menu,tbw-grid .faux-vscroll{display:none!important}tbw-grid .tbw-print-header{display:flex;justify-content:space-between;align-items:baseline;padding:.5em 0;margin-bottom:.5em;border-bottom:2px solid var(--tbw-color-border, #333);font-family:inherit}.tbw-print-header-title{font-size:1.25em;font-weight:700}.tbw-print-header-timestamp{font-size:.875em;color:var(--tbw-color-fg-muted, #666)}tbw-grid .tbw-print-footer{display:block;margin-top:.5em;padding-top:.5em;border-top:1px solid var(--tbw-color-border, #ccc);font-size:.75em;color:var(--tbw-color-fg-muted, #666);text-align:right}tbw-grid .data-grid-row{break-inside:avoid;page-break-inside:avoid}tbw-grid .cell{border:1px solid var(--tbw-color-border, #ddd)!important}tbw-grid .header-row,tbw-grid .data-grid-row{padding-right:1px}tbw-grid .data-grid-row:hover,tbw-grid .cell:hover{background:inherit!important}@page{margin:1cm}@page{tbw-grid.print-landscape{size:landscape}}@page{tbw-grid.print-portrait{size:portrait}}}", f = {
405
+ button: !1,
406
+ orientation: "landscape",
407
+ warnThreshold: 500,
408
+ maxRows: 0,
409
+ includeTitle: !0,
410
+ includeTimestamp: !0,
411
+ title: "",
412
+ isolate: !1
413
+ };
414
+ class v extends w {
415
+ /** @internal */
416
+ name = "print";
417
+ /** @internal */
418
+ version = "1.0.0";
419
+ /** CSS styles for print mode */
420
+ styles = b;
421
+ /** Current print state */
422
+ #t = !1;
423
+ /** Saved column visibility state */
424
+ #r = null;
425
+ /** Saved virtualization state */
426
+ #n = null;
427
+ /** Saved rows when maxRows limit is applied */
428
+ #o = null;
429
+ /** Print header element */
430
+ #e = null;
431
+ /** Print footer element */
432
+ #i = null;
433
+ /** Applied scale factor (legacy, used for cleanup) */
434
+ #a = null;
435
+ /**
436
+ * Get the grid typed as PrintGridRef for internal access.
437
+ */
438
+ get #s() {
439
+ return this.grid;
440
+ }
441
+ /**
442
+ * Check if print is currently in progress
443
+ */
444
+ isPrinting() {
445
+ return this.#t;
446
+ }
447
+ /**
448
+ * Trigger the browser print dialog
449
+ *
450
+ * This method:
451
+ * 1. Validates row count against maxRows limit
452
+ * 2. Disables virtualization to render all rows
453
+ * 3. Applies print-specific CSS classes
454
+ * 4. Opens the browser print dialog (or isolated window if `isolate: true`)
455
+ * 5. Restores normal state after printing
456
+ *
457
+ * @param params - Optional parameters to override config for this print
458
+ * @param params.isolate - If true, prints in an isolated window containing only the grid
459
+ * @returns Promise that resolves when print dialog closes
460
+ */
461
+ async print(t) {
462
+ if (this.#t) {
463
+ console.warn("[PrintPlugin] Print already in progress");
464
+ return;
465
+ }
466
+ const e = this.gridElement;
467
+ if (!e) {
468
+ console.warn("[PrintPlugin] Grid not available");
469
+ return;
470
+ }
471
+ const i = { ...f, ...this.config, ...t }, s = this.rows.length;
472
+ let a = s, l = !1;
473
+ if (i.warnThreshold > 0 && s > i.warnThreshold) {
474
+ const d = i.maxRows > 0 ? `
475
+
476
+ Note: Output will be limited to ${i.maxRows.toLocaleString()} rows.` : "";
477
+ if (!confirm(
478
+ `This grid has ${s.toLocaleString()} rows. Printing large datasets may cause performance issues or browser slowdowns.${d}
479
+
480
+ Click OK to continue, or Cancel to abort.`
481
+ ))
482
+ return;
483
+ }
484
+ i.maxRows > 0 && s > i.maxRows && (a = i.maxRows, l = !0), this.#t = !0;
485
+ const c = performance.now();
486
+ this.emit("print-start", {
487
+ rowCount: a,
488
+ limitApplied: l,
489
+ originalRowCount: s
490
+ });
491
+ try {
492
+ const d = this.#s;
493
+ this.#n = {
494
+ bypassThreshold: d._virtualization?.bypassThreshold ?? 24
495
+ }, this.#p(), l && (this.#o = this.sourceRows, this.grid.rows = this.sourceRows.slice(0, a), await new Promise((n) => setTimeout(n, 50))), (i.includeTitle || i.includeTimestamp) && this.#d(i), await this.#h(), await new Promise((n) => requestAnimationFrame(n)), await new Promise((n) => requestAnimationFrame(n)), e.classList.add(`print-${i.orientation}`), await new Promise((n) => requestAnimationFrame(n)), await new Promise((n) => requestAnimationFrame(n)), i.isolate ? await this.#m(i) : await this.#c(), this.emit("print-complete", {
496
+ success: !0,
497
+ rowCount: a,
498
+ duration: Math.round(performance.now() - c)
499
+ });
500
+ } catch (d) {
501
+ console.error("[PrintPlugin] Print failed:", d), this.emit("print-complete", {
502
+ success: !1,
503
+ rowCount: 0,
504
+ duration: Math.round(performance.now() - c)
505
+ });
506
+ } finally {
507
+ this.#g(), this.#t = !1;
508
+ }
509
+ }
510
+ /**
511
+ * Add print header with title and timestamp
512
+ */
513
+ #d(t) {
514
+ const e = this.gridElement;
515
+ if (e) {
516
+ if (this.#e = document.createElement("div"), this.#e.className = "tbw-print-header", t.includeTitle) {
517
+ const i = t.title || this.grid.effectiveConfig?.shell?.header?.title || "Grid Data", o = document.createElement("div");
518
+ o.className = "tbw-print-header-title", o.textContent = i, this.#e.appendChild(o);
519
+ }
520
+ if (t.includeTimestamp) {
521
+ const i = document.createElement("div");
522
+ i.className = "tbw-print-header-timestamp", i.textContent = `Printed: ${(/* @__PURE__ */ new Date()).toLocaleString()}`, this.#e.appendChild(i);
523
+ }
524
+ e.insertBefore(this.#e, e.firstChild), this.#i = document.createElement("div"), this.#i.className = "tbw-print-footer", this.#i.textContent = `Page generated from ${window.location.hostname}`, e.appendChild(this.#i);
525
+ }
526
+ }
527
+ /**
528
+ * Disable virtualization to render all rows
529
+ */
530
+ async #h() {
531
+ const t = this.#s;
532
+ if (!t._virtualization) return;
533
+ const e = this.rows.length;
534
+ t._virtualization.bypassThreshold = e + 100, t.refreshVirtualWindow(!0), await new Promise((i) => setTimeout(i, 100));
535
+ }
536
+ /**
537
+ * Trigger the browser print dialog
538
+ */
539
+ async #c() {
540
+ return new Promise((t) => {
541
+ const e = () => {
542
+ window.removeEventListener("afterprint", e), t();
543
+ };
544
+ window.addEventListener("afterprint", e), window.print(), setTimeout(() => {
545
+ window.removeEventListener("afterprint", e), t();
546
+ }, 1e3);
547
+ });
548
+ }
549
+ /**
550
+ * Print in isolation by hiding all other page content.
551
+ * This excludes navigation, sidebars, etc. while keeping the grid in place.
552
+ */
553
+ async #m(t) {
554
+ const e = this.gridElement;
555
+ e && await u(e, {
556
+ orientation: t.orientation
557
+ });
558
+ }
559
+ /**
560
+ * Hide columns marked with printHidden: true
561
+ */
562
+ #p() {
563
+ const t = this.columns;
564
+ if (t) {
565
+ this.#r = /* @__PURE__ */ new Map();
566
+ for (const e of t)
567
+ e.printHidden && e.field && (this.#r.set(e.field, !e.hidden), this.grid.setColumnVisible(e.field, !1));
568
+ }
569
+ }
570
+ /**
571
+ * Restore columns that were hidden for printing
572
+ */
573
+ #u() {
574
+ if (this.#r) {
575
+ for (const [t, e] of this.#r)
576
+ this.grid.setColumnVisible(t, e);
577
+ this.#r = null;
578
+ }
579
+ }
580
+ /**
581
+ * Cleanup after printing
582
+ */
583
+ #g() {
584
+ const t = this.gridElement;
585
+ if (!t) return;
586
+ this.#u(), t.classList.remove("print-portrait", "print-landscape"), this.#a !== null && (t.style.transform = "", t.style.transformOrigin = "", t.style.width = "", this.#a = null), this.#e && (this.#e.remove(), this.#e = null), this.#i && (this.#i.remove(), this.#i = null);
587
+ const e = this.#s;
588
+ this.#n && e._virtualization && (e._virtualization.bypassThreshold = this.#n.bypassThreshold, e.refreshVirtualWindow(!0), this.#n = null), this.#o !== null && (this.grid.rows = this.#o, this.#o = null);
589
+ }
590
+ /**
591
+ * Register toolbar button if configured
592
+ * @internal
593
+ */
594
+ afterRender() {
595
+ this.config?.button && !this.#l && (this.#w(), this.#l = !0);
596
+ }
597
+ /** Track if toolbar button is registered */
598
+ #l = !1;
599
+ /**
600
+ * Register print button in toolbar
601
+ */
602
+ #w() {
603
+ this.#s.registerToolbarContent?.({
604
+ id: "print-button",
605
+ order: 900,
606
+ // High order to appear at the end
607
+ render: (e) => {
608
+ const i = document.createElement("button");
609
+ i.className = "tbw-toolbar-btn tbw-print-btn", i.title = "Print grid", i.type = "button";
610
+ const o = this.resolveIcon("print") || "🖨️";
611
+ this.setIcon(i, o), i.addEventListener(
612
+ "click",
613
+ () => {
614
+ this.print();
615
+ },
616
+ { signal: this.disconnectSignal }
617
+ ), e.appendChild(i);
618
+ }
619
+ });
620
+ }
621
+ }
622
+ export {
623
+ v as PrintPlugin,
624
+ u as printGridIsolated
625
+ };
626
+ //# sourceMappingURL=index.js.map