@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,689 +1,2 @@
1
- function a(i) {
2
- try {
3
- if (getComputedStyle(i).direction === "rtl") return "rtl";
4
- } catch {
5
- }
6
- try {
7
- if (i.closest?.("[dir]")?.getAttribute("dir") === "rtl") return "rtl";
8
- } catch {
9
- }
10
- return "ltr";
11
- }
12
- function P(i, t) {
13
- return i === "left" || i === "right" ? i : t === "rtl" ? i === "start" ? "right" : "left" : i === "start" ? "left" : "right";
14
- }
15
- 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>', A = {
16
- expand: "▶",
17
- collapse: "▼",
18
- sortAsc: "▲",
19
- sortDesc: "▼",
20
- sortNone: "⇅",
21
- submenuArrow: "▶",
22
- dragHandle: "⋮⋮",
23
- toolPanel: "☰",
24
- filter: m,
25
- filterActive: m,
26
- print: "🖨️"
27
- };
28
- class R {
29
- /**
30
- * Plugin dependencies - declare other plugins this one requires.
31
- *
32
- * Dependencies are validated when the plugin is attached.
33
- * Required dependencies throw an error if missing.
34
- * Optional dependencies log an info message if missing.
35
- *
36
- * @example
37
- * ```typescript
38
- * static readonly dependencies: PluginDependency[] = [
39
- * { name: 'editing', required: true, reason: 'Tracks cell edits for undo/redo' },
40
- * { name: 'selection', required: false, reason: 'Enables selection-based undo' },
41
- * ];
42
- * ```
43
- */
44
- static dependencies;
45
- /**
46
- * Plugin manifest - declares owned properties, config rules, and hook priorities.
47
- *
48
- * This is read by the configuration validator to:
49
- * - Validate that required plugins are loaded when their properties are used
50
- * - Execute configRules to detect invalid/conflicting settings
51
- * - Order hook execution based on priority
52
- *
53
- * @example
54
- * ```typescript
55
- * static override readonly manifest: PluginManifest<MyConfig> = {
56
- * ownedProperties: [
57
- * { property: 'myProp', level: 'column', description: 'the "myProp" column property' },
58
- * ],
59
- * configRules: [
60
- * { id: 'myPlugin/conflict', severity: 'warn', message: '...', check: (c) => c.a && c.b },
61
- * ],
62
- * };
63
- * ```
64
- */
65
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
66
- static manifest;
67
- /**
68
- * Plugin version - defaults to grid version for built-in plugins.
69
- * Third-party plugins can override with their own semver.
70
- */
71
- version = typeof __GRID_VERSION__ < "u" ? __GRID_VERSION__ : "dev";
72
- /** CSS styles to inject into the grid's shadow DOM */
73
- styles;
74
- /** Custom cell renderers keyed by type name */
75
- cellRenderers;
76
- /** Custom header renderers keyed by type name */
77
- headerRenderers;
78
- /** Custom cell editors keyed by type name */
79
- cellEditors;
80
- /** The grid instance this plugin is attached to */
81
- grid;
82
- /** Plugin configuration - merged with defaults in attach() */
83
- config;
84
- /** User-provided configuration from constructor */
85
- userConfig;
86
- /**
87
- * Plugin-level AbortController for event listener cleanup.
88
- * Created fresh in attach(), aborted in detach().
89
- * This ensures event listeners are properly cleaned up when plugins are re-attached.
90
- */
91
- #t;
92
- /**
93
- * Default configuration - subclasses should override this getter.
94
- * Note: This must be a getter (not property initializer) for proper inheritance
95
- * since property initializers run after parent constructor.
96
- */
97
- get defaultConfig() {
98
- return {};
99
- }
100
- constructor(t = {}) {
101
- this.userConfig = t;
102
- }
103
- /**
104
- * Called when the plugin is attached to a grid.
105
- * Override to set up event listeners, initialize state, etc.
106
- *
107
- * @example
108
- * ```ts
109
- * attach(grid: GridElement): void {
110
- * super.attach(grid);
111
- * // Set up document-level listeners with auto-cleanup
112
- * document.addEventListener('keydown', this.handleEscape, {
113
- * signal: this.disconnectSignal
114
- * });
115
- * }
116
- * ```
117
- */
118
- attach(t) {
119
- this.#t?.abort(), this.#t = new AbortController(), this.grid = t, this.config = { ...this.defaultConfig, ...this.userConfig };
120
- }
121
- /**
122
- * Called when the plugin is detached from a grid.
123
- * Override to clean up event listeners, timers, etc.
124
- *
125
- * @example
126
- * ```ts
127
- * detach(): void {
128
- * // Clean up any state not handled by disconnectSignal
129
- * this.selectedRows.clear();
130
- * this.cache = null;
131
- * }
132
- * ```
133
- */
134
- detach() {
135
- this.#t?.abort(), this.#t = void 0;
136
- }
137
- /**
138
- * Get another plugin instance from the same grid.
139
- * Use for inter-plugin communication.
140
- *
141
- * @example
142
- * ```ts
143
- * const selection = this.getPlugin(SelectionPlugin);
144
- * if (selection) {
145
- * const selectedRows = selection.getSelectedRows();
146
- * }
147
- * ```
148
- */
149
- getPlugin(t) {
150
- return this.grid?.getPlugin(t);
151
- }
152
- /**
153
- * Emit a custom event from the grid.
154
- */
155
- emit(t, e) {
156
- this.grid?.dispatchEvent?.(new CustomEvent(t, { detail: e, bubbles: !0 }));
157
- }
158
- /**
159
- * Emit a cancelable custom event from the grid.
160
- * @returns `true` if the event was cancelled (preventDefault called), `false` otherwise
161
- */
162
- emitCancelable(t, e) {
163
- const n = new CustomEvent(t, { detail: e, bubbles: !0, cancelable: !0 });
164
- return this.grid?.dispatchEvent?.(n), n.defaultPrevented;
165
- }
166
- // =========================================================================
167
- // Event Bus - Plugin-to-Plugin Communication
168
- // =========================================================================
169
- /**
170
- * Subscribe to an event from another plugin.
171
- * The subscription is automatically cleaned up when this plugin is detached.
172
- *
173
- * @category Plugin Development
174
- * @param eventType - The event type to listen for (e.g., 'filter-change')
175
- * @param callback - The callback to invoke when the event is emitted
176
- *
177
- * @example
178
- * ```typescript
179
- * // In attach() or other initialization
180
- * this.on('filter-change', (detail) => {
181
- * console.log('Filter changed:', detail);
182
- * });
183
- * ```
184
- */
185
- on(t, e) {
186
- this.grid?._pluginManager?.subscribe(this, t, e);
187
- }
188
- /**
189
- * Unsubscribe from a plugin event.
190
- *
191
- * @category Plugin Development
192
- * @param eventType - The event type to stop listening for
193
- *
194
- * @example
195
- * ```typescript
196
- * this.off('filter-change');
197
- * ```
198
- */
199
- off(t) {
200
- this.grid?._pluginManager?.unsubscribe(this, t);
201
- }
202
- /**
203
- * Emit an event to other plugins via the Event Bus.
204
- * This is for inter-plugin communication only; it does NOT dispatch DOM events.
205
- * Use `emit()` to dispatch DOM events that external consumers can listen to.
206
- *
207
- * @category Plugin Development
208
- * @param eventType - The event type to emit (should be declared in manifest.events)
209
- * @param detail - The event payload
210
- *
211
- * @example
212
- * ```typescript
213
- * // Emit to other plugins (not DOM)
214
- * this.emitPluginEvent('filter-change', { field: 'name', value: 'Alice' });
215
- *
216
- * // For DOM events that consumers can addEventListener to:
217
- * this.emit('filter-change', { field: 'name', value: 'Alice' });
218
- * ```
219
- */
220
- emitPluginEvent(t, e) {
221
- this.grid?._pluginManager?.emitPluginEvent(t, e);
222
- }
223
- /**
224
- * Request a re-render of the grid.
225
- * Uses ROWS phase - does NOT trigger processColumns hooks.
226
- */
227
- requestRender() {
228
- this.grid?.requestRender?.();
229
- }
230
- /**
231
- * Request a columns re-render of the grid.
232
- * Uses COLUMNS phase - triggers processColumns hooks.
233
- * Use this when your plugin needs to reprocess column configuration.
234
- */
235
- requestColumnsRender() {
236
- this.grid?.requestColumnsRender?.();
237
- }
238
- /**
239
- * Request a re-render and restore focus styling afterward.
240
- * Use this when a plugin action (like expand/collapse) triggers a render
241
- * but needs to maintain keyboard navigation focus.
242
- */
243
- requestRenderWithFocus() {
244
- this.grid?.requestRenderWithFocus?.();
245
- }
246
- /**
247
- * Request a lightweight style update without rebuilding DOM.
248
- * Use this instead of requestRender() when only CSS classes need updating.
249
- */
250
- requestAfterRender() {
251
- this.grid?.requestAfterRender?.();
252
- }
253
- /**
254
- * Get the current rows from the grid.
255
- */
256
- get rows() {
257
- return this.grid?.rows ?? [];
258
- }
259
- /**
260
- * Get the original unfiltered/unprocessed rows from the grid.
261
- * Use this when you need all source data regardless of active filters.
262
- */
263
- get sourceRows() {
264
- return this.grid?.sourceRows ?? [];
265
- }
266
- /**
267
- * Get the current columns from the grid.
268
- */
269
- get columns() {
270
- return this.grid?.columns ?? [];
271
- }
272
- /**
273
- * Get only visible columns from the grid (excludes hidden).
274
- * Use this for rendering that needs to match the grid template.
275
- */
276
- get visibleColumns() {
277
- return this.grid?._visibleColumns ?? [];
278
- }
279
- /**
280
- * Get the grid as an HTMLElement for direct DOM operations.
281
- * Use sparingly - prefer the typed GridElementRef API when possible.
282
- *
283
- * @example
284
- * ```ts
285
- * const width = this.gridElement.clientWidth;
286
- * this.gridElement.classList.add('my-plugin-active');
287
- * ```
288
- */
289
- get gridElement() {
290
- return this.grid;
291
- }
292
- /**
293
- * Get the disconnect signal for event listener cleanup.
294
- * This signal is aborted when the grid disconnects from the DOM.
295
- * Use this when adding event listeners that should be cleaned up automatically.
296
- *
297
- * Best for:
298
- * - Document/window-level listeners added in attach()
299
- * - Listeners on the grid element itself
300
- * - Any listener that should persist across renders
301
- *
302
- * Not needed for:
303
- * - Listeners on elements created in afterRender() (removed with element)
304
- *
305
- * @example
306
- * element.addEventListener('click', handler, { signal: this.disconnectSignal });
307
- * document.addEventListener('keydown', handler, { signal: this.disconnectSignal });
308
- */
309
- get disconnectSignal() {
310
- return this.#t?.signal ?? this.grid?.disconnectSignal;
311
- }
312
- /**
313
- * Get the grid-level icons configuration.
314
- * Returns merged icons (user config + defaults).
315
- */
316
- get gridIcons() {
317
- const t = this.grid?.gridConfig?.icons ?? {};
318
- return { ...A, ...t };
319
- }
320
- // #region Animation Helpers
321
- /**
322
- * Check if animations are enabled at the grid level.
323
- * Respects gridConfig.animation.mode and the CSS variable set by the grid.
324
- *
325
- * Plugins should use this to skip animations when:
326
- * - Animation mode is 'off' or `false`
327
- * - User prefers reduced motion and mode is 'reduced-motion' (default)
328
- *
329
- * @example
330
- * ```ts
331
- * private get animationStyle(): 'slide' | 'fade' | false {
332
- * if (!this.isAnimationEnabled) return false;
333
- * return this.config.animation ?? 'slide';
334
- * }
335
- * ```
336
- */
337
- get isAnimationEnabled() {
338
- const t = this.grid?.effectiveConfig?.animation?.mode ?? "reduced-motion";
339
- if (t === !1 || t === "off") return !1;
340
- if (t === !0 || t === "on") return !0;
341
- const e = this.gridElement;
342
- return e ? getComputedStyle(e).getPropertyValue("--tbw-animation-enabled").trim() !== "0" : !0;
343
- }
344
- /**
345
- * Get the animation duration in milliseconds from CSS variable.
346
- * Falls back to 200ms if not set.
347
- *
348
- * Plugins can use this for their animation timing to stay consistent
349
- * with the grid-level animation.duration setting.
350
- *
351
- * @example
352
- * ```ts
353
- * element.animate(keyframes, { duration: this.animationDuration });
354
- * ```
355
- */
356
- get animationDuration() {
357
- const t = this.gridElement;
358
- if (t) {
359
- const e = getComputedStyle(t).getPropertyValue("--tbw-animation-duration").trim(), n = parseInt(e, 10);
360
- if (!isNaN(n)) return n;
361
- }
362
- return 200;
363
- }
364
- // #endregion
365
- /**
366
- * Resolve an icon value to string or HTMLElement.
367
- * Checks plugin config first, then grid-level icons, then defaults.
368
- *
369
- * @param iconKey - The icon key in GridIcons (e.g., 'expand', 'collapse')
370
- * @param pluginOverride - Optional plugin-level override
371
- * @returns The resolved icon value
372
- */
373
- resolveIcon(t, e) {
374
- return e !== void 0 ? e : this.gridIcons[t];
375
- }
376
- /**
377
- * Set an icon value on an element.
378
- * Handles both string (text/HTML) and HTMLElement values.
379
- *
380
- * @param element - The element to set the icon on
381
- * @param icon - The icon value (string or HTMLElement)
382
- */
383
- setIcon(t, e) {
384
- typeof e == "string" ? t.innerHTML = e : e instanceof HTMLElement && (t.innerHTML = "", t.appendChild(e.cloneNode(!0)));
385
- }
386
- /**
387
- * Log a warning message.
388
- */
389
- warn(t) {
390
- console.warn(`[tbw-grid:${this.name}] ${t}`);
391
- }
392
- // #endregion
393
- }
394
- function d(i) {
395
- return i.pinned ?? i.sticky ?? i.meta?.pinned ?? i.meta?.sticky;
396
- }
397
- function g(i, t) {
398
- return P(i, t);
399
- }
400
- function b(i, t) {
401
- const e = d(i);
402
- return e ? g(e, t) === "left" : !1;
403
- }
404
- function v(i, t) {
405
- const e = d(i);
406
- return e ? g(e, t) === "right" : !1;
407
- }
408
- function S(i, t = "ltr") {
409
- return i.filter((e) => b(e, t));
410
- }
411
- function E(i, t = "ltr") {
412
- return i.filter((e) => v(e, t));
413
- }
414
- function h(i) {
415
- return i.some((t) => d(t) != null);
416
- }
417
- function y(i, t) {
418
- const e = Array.from(i.querySelectorAll(".header-row .cell"));
419
- if (!e.length) return;
420
- const n = a(i);
421
- let l = 0;
422
- for (const o of t)
423
- if (b(o, n)) {
424
- const r = e.find((s) => s.getAttribute("data-field") === o.field);
425
- r && (r.classList.add("sticky-left"), r.style.position = "sticky", r.style.left = l + "px", i.querySelectorAll(`.data-grid-row .cell[data-field="${o.field}"]`).forEach((s) => {
426
- s.classList.add("sticky-left"), s.style.position = "sticky", s.style.left = l + "px";
427
- }), l += r.offsetWidth);
428
- }
429
- let c = 0;
430
- for (const o of [...t].reverse())
431
- if (v(o, n)) {
432
- const r = e.find((s) => s.getAttribute("data-field") === o.field);
433
- r && (r.classList.add("sticky-right"), r.style.position = "sticky", r.style.right = c + "px", i.querySelectorAll(`.data-grid-row .cell[data-field="${o.field}"]`).forEach((s) => {
434
- s.classList.add("sticky-right"), s.style.position = "sticky", s.style.right = c + "px";
435
- }), c += r.offsetWidth);
436
- }
437
- }
438
- function O(i, t = "ltr") {
439
- const e = [], n = [], l = [];
440
- for (const c of i) {
441
- const o = d(c);
442
- o ? g(o, t) === "left" ? e.push(c) : l.push(c) : n.push(c);
443
- }
444
- return [...e, ...n, ...l];
445
- }
446
- function C(i) {
447
- i.querySelectorAll(".sticky-left, .sticky-right").forEach((e) => {
448
- e.classList.remove("sticky-left", "sticky-right"), e.style.position = "", e.style.left = "", e.style.right = "";
449
- });
450
- }
451
- const k = "canMoveColumn";
452
- class I extends R {
453
- /**
454
- * Plugin manifest - declares owned properties and handled queries.
455
- * @internal
456
- */
457
- static manifest = {
458
- ownedProperties: [
459
- {
460
- property: "pinned",
461
- level: "column",
462
- description: 'the "pinned" column property',
463
- isUsed: (t) => t === "left" || t === "right" || t === "start" || t === "end"
464
- },
465
- {
466
- property: "sticky",
467
- level: "column",
468
- description: 'the "sticky" column property (deprecated, use "pinned")',
469
- isUsed: (t) => t === "left" || t === "right" || t === "start" || t === "end"
470
- }
471
- ],
472
- incompatibleWith: [
473
- {
474
- name: "groupingColumns",
475
- reason: "Pinning reorders columns to the grid edges, but moving a column out of its column group is not supported. The group header layout cannot accommodate members at different positions."
476
- }
477
- ],
478
- queries: [
479
- {
480
- type: k,
481
- description: "Prevents pinned (sticky) columns from being moved/reordered"
482
- },
483
- {
484
- type: "getStickyOffsets",
485
- description: "Returns the sticky offsets for left/right pinned columns"
486
- },
487
- {
488
- type: "getContextMenuItems",
489
- description: "Contributes pin/unpin items to the header context menu"
490
- }
491
- ]
492
- };
493
- /** @internal */
494
- name = "pinnedColumns";
495
- /** @internal */
496
- get defaultConfig() {
497
- return {};
498
- }
499
- // #region Internal State
500
- isApplied = !1;
501
- leftOffsets = /* @__PURE__ */ new Map();
502
- rightOffsets = /* @__PURE__ */ new Map();
503
- /**
504
- * Snapshot of the column field order before the first context-menu pin.
505
- * Used to restore original positions when unpinning.
506
- */
507
- #t = [];
508
- // #endregion
509
- // #region Lifecycle
510
- /** @internal */
511
- detach() {
512
- this.leftOffsets.clear(), this.rightOffsets.clear(), this.isApplied = !1, this.#t = [];
513
- }
514
- // #endregion
515
- // #region Detection
516
- /**
517
- * Auto-detect sticky columns from column configuration.
518
- */
519
- static detect(t, e) {
520
- const n = e?.columns;
521
- return Array.isArray(n) ? h(n) : !1;
522
- }
523
- // #endregion
524
- // #region Hooks
525
- /** @internal */
526
- processColumns(t) {
527
- const e = [...t];
528
- if (this.isApplied = h(e), !this.isApplied) return e;
529
- const n = this.gridElement, l = n ? a(n) : "ltr";
530
- return O(e, l);
531
- }
532
- /** @internal */
533
- afterRender() {
534
- if (!this.isApplied)
535
- return;
536
- const t = this.grid, e = [...this.columns];
537
- if (!h(e)) {
538
- C(t), this.isApplied = !1;
539
- return;
540
- }
541
- queueMicrotask(() => {
542
- y(t, e);
543
- });
544
- }
545
- /**
546
- * Handle inter-plugin queries.
547
- * @internal
548
- */
549
- handleQuery(t) {
550
- switch (t.type) {
551
- case k: {
552
- const e = t.context;
553
- return d(e) != null ? !1 : void 0;
554
- }
555
- case "getStickyOffsets":
556
- return {
557
- left: Object.fromEntries(this.leftOffsets),
558
- right: Object.fromEntries(this.rightOffsets)
559
- };
560
- case "getContextMenuItems": {
561
- const e = t.context;
562
- if (!e.isHeader) return;
563
- const n = e.column;
564
- if (!n?.field || n.meta?.lockPinning || this.grid?.getPluginByName("groupingColumns")?.isGroupingActive()) return;
565
- const o = d(n) != null, r = [];
566
- return o ? r.push({
567
- id: "pinned/unpin",
568
- label: "Unpin Column",
569
- icon: "📌",
570
- order: 40,
571
- action: () => this.setPinPosition(n.field, void 0)
572
- }) : (r.push({
573
- id: "pinned/pin-left",
574
- label: "Pin Left",
575
- icon: "⬅",
576
- order: 40,
577
- action: () => this.setPinPosition(n.field, "left")
578
- }), r.push({
579
- id: "pinned/pin-right",
580
- label: "Pin Right",
581
- icon: "➡",
582
- order: 41,
583
- action: () => this.setPinPosition(n.field, "right")
584
- })), r;
585
- }
586
- default:
587
- return;
588
- }
589
- }
590
- // #endregion
591
- // #region Public API
592
- /**
593
- * Set the pin position for a column.
594
- * Updates the column's `pinned` property and triggers a full re-render.
595
- *
596
- * @param field - The field name of the column to pin/unpin
597
- * @param position - The pin position (`'left'`, `'right'`, `'start'`, `'end'`), or `undefined` to unpin
598
- */
599
- setPinPosition(t, e) {
600
- const n = this.columns;
601
- if (!n?.length) return;
602
- const l = n.findIndex((o) => o.field === t);
603
- if (l === -1) return;
604
- const c = this.grid;
605
- if (e) {
606
- this.#t.length === 0 && (this.#t = n.map((r) => r.field));
607
- const o = n.map((r) => {
608
- if (r.field !== t) return r;
609
- const s = { ...r };
610
- return s.pinned = e, delete s.sticky, s;
611
- });
612
- c.columns = o;
613
- } else {
614
- const r = { ...n[l] };
615
- delete r.pinned, delete r.sticky;
616
- const s = [...n];
617
- s.splice(l, 1);
618
- const p = this.#t.indexOf(t);
619
- if (p >= 0) {
620
- let f = s.length;
621
- for (let u = 0; u < s.length; u++) {
622
- if (d(s[u])) continue;
623
- if (this.#t.indexOf(s[u].field) > p) {
624
- f = u;
625
- break;
626
- }
627
- }
628
- s.splice(f, 0, r);
629
- } else
630
- s.splice(Math.min(l, s.length), 0, r);
631
- s.some((f) => d(f) != null) || (this.#t = []), c.columns = s;
632
- }
633
- }
634
- /**
635
- * Re-apply sticky offsets (e.g., after column resize).
636
- */
637
- refreshStickyOffsets() {
638
- const t = [...this.columns];
639
- y(this.grid, t);
640
- }
641
- /**
642
- * Get columns pinned to the left (after resolving logical positions for current direction).
643
- */
644
- getLeftPinnedColumns() {
645
- const t = [...this.columns], e = a(this.grid);
646
- return S(t, e);
647
- }
648
- /**
649
- * Get columns pinned to the right (after resolving logical positions for current direction).
650
- */
651
- getRightPinnedColumns() {
652
- const t = [...this.columns], e = a(this.grid);
653
- return E(t, e);
654
- }
655
- /**
656
- * Clear all sticky positioning.
657
- */
658
- clearStickyPositions() {
659
- C(this.grid);
660
- }
661
- /**
662
- * Report horizontal scroll boundary offsets for pinned columns.
663
- * Used by keyboard navigation to ensure focused cells aren't hidden behind sticky columns.
664
- * @internal
665
- */
666
- getHorizontalScrollOffsets(t, e) {
667
- if (!this.isApplied)
668
- return;
669
- let n = 0, l = 0;
670
- if (t) {
671
- const o = t.querySelectorAll(".sticky-left"), r = t.querySelectorAll(".sticky-right");
672
- o.forEach((s) => {
673
- n += s.offsetWidth;
674
- }), r.forEach((s) => {
675
- l += s.offsetWidth;
676
- });
677
- } else
678
- this.grid.querySelectorAll(".header-row .cell").forEach((s) => {
679
- s.classList.contains("sticky-left") ? n += s.offsetWidth : s.classList.contains("sticky-right") && (l += s.offsetWidth);
680
- });
681
- const c = e?.classList.contains("sticky-left") || e?.classList.contains("sticky-right");
682
- return { left: n, right: l, skipScroll: c };
683
- }
684
- // #endregion
685
- }
686
- export {
687
- I as PinnedColumnsPlugin
688
- };
1
+ function t(t){try{if("rtl"===getComputedStyle(t).direction)return"rtl"}catch{}try{const e=t.closest?.("[dir]")?.getAttribute("dir");if("rtl"===e)return"rtl"}catch{}return"ltr"}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>',i={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:e,filterActive:e,print:"🖨️"};class n{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{...i,...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){return t.pinned??t.sticky??t.meta?.pinned??t.meta?.sticky}function s(t,e){return function(t,e){return"left"===t||"right"===t?t:"rtl"===e?"start"===t?"right":"left":"start"===t?"left":"right"}(t,e)}function o(t,e){const i=r(t);return!!i&&"left"===s(i,e)}function l(t,e){const i=r(t);return!!i&&"right"===s(i,e)}function c(t){return t.some(t=>null!=r(t))}function d(e,i){const n=Array.from(e.querySelectorAll(".header-row .cell"));if(!n.length)return;const r=t(e);let s=0;for(const t of i)if(o(t,r)){const i=n.find(e=>e.getAttribute("data-field")===t.field);i&&(i.classList.add("sticky-left"),i.style.position="sticky",i.style.left=s+"px",e.querySelectorAll(`.data-grid-row .cell[data-field="${t.field}"]`).forEach(t=>{t.classList.add("sticky-left"),t.style.position="sticky",t.style.left=s+"px"}),s+=i.offsetWidth)}let c=0;for(const t of[...i].reverse())if(l(t,r)){const i=n.find(e=>e.getAttribute("data-field")===t.field);i&&(i.classList.add("sticky-right"),i.style.position="sticky",i.style.right=c+"px",e.querySelectorAll(`.data-grid-row .cell[data-field="${t.field}"]`).forEach(t=>{t.classList.add("sticky-right"),t.style.position="sticky",t.style.right=c+"px"}),c+=i.offsetWidth)}}function u(t){t.querySelectorAll(".sticky-left, .sticky-right").forEach(t=>{t.classList.remove("sticky-left","sticky-right"),t.style.position="",t.style.left="",t.style.right=""})}const f="canMoveColumn";class a extends n{static manifest={ownedProperties:[{property:"pinned",level:"column",description:'the "pinned" column property',isUsed:t=>"left"===t||"right"===t||"start"===t||"end"===t},{property:"sticky",level:"column",description:'the "sticky" column property (deprecated, use "pinned")',isUsed:t=>"left"===t||"right"===t||"start"===t||"end"===t}],incompatibleWith:[{name:"groupingColumns",reason:"Pinning reorders columns to the grid edges, but moving a column out of its column group is not supported. The group header layout cannot accommodate members at different positions."}],queries:[{type:f,description:"Prevents pinned (sticky) columns from being moved/reordered"},{type:"getStickyOffsets",description:"Returns the sticky offsets for left/right pinned columns"},{type:"getContextMenuItems",description:"Contributes pin/unpin items to the header context menu"}]};name="pinnedColumns";get defaultConfig(){return{}}isApplied=!1;leftOffsets=/* @__PURE__ */new Map;rightOffsets=/* @__PURE__ */new Map;#e=[];detach(){this.leftOffsets.clear(),this.rightOffsets.clear(),this.isApplied=!1,this.#e=[]}static detect(t,e){const i=e?.columns;return!!Array.isArray(i)&&c(i)}processColumns(e){const i=[...e];if(this.isApplied=c(i),!this.isApplied)return i;const n=this.gridElement;return function(t,e="ltr"){const i=[],n=[],o=[];for(const l of t){const t=r(l);t?"left"===s(t,e)?i.push(l):o.push(l):n.push(l)}return[...i,...n,...o]}(i,n?t(n):"ltr")}afterRender(){if(!this.isApplied)return;const t=this.grid,e=[...this.columns];if(!c(e))return u(t),void(this.isApplied=!1);queueMicrotask(()=>{d(t,e)})}handleQuery(t){switch(t.type){case f:return null==r(t.context)&&void 0;case"getStickyOffsets":return{left:Object.fromEntries(this.leftOffsets),right:Object.fromEntries(this.rightOffsets)};case"getContextMenuItems":{const e=t.context;if(!e.isHeader)return;const i=e.column;if(!i?.field)return;if(i.meta?.lockPinning)return;const n=this.grid?.getPluginByName("groupingColumns");if(n?.isGroupingActive())return;const s=[];return null!=r(i)?s.push({id:"pinned/unpin",label:"Unpin Column",icon:"📌",order:40,action:()=>this.setPinPosition(i.field,void 0)}):(s.push({id:"pinned/pin-left",label:"Pin Left",icon:"⬅",order:40,action:()=>this.setPinPosition(i.field,"left")}),s.push({id:"pinned/pin-right",label:"Pin Right",icon:"➡",order:41,action:()=>this.setPinPosition(i.field,"right")})),s}default:return}}setPinPosition(t,e){const i=this.columns;if(!i?.length)return;const n=i.findIndex(e=>e.field===t);if(-1===n)return;const s=this.grid;if(e){0===this.#e.length&&(this.#e=i.map(t=>t.field));const n=i.map(i=>{if(i.field!==t)return i;const n={...i};return n.pinned=e,delete n.sticky,n});s.columns=n}else{const e={...i[n]};delete e.pinned,delete e.sticky;const o=[...i];o.splice(n,1);const l=this.#e.indexOf(t);if(l>=0){let t=o.length;for(let e=0;e<o.length;e++){if(r(o[e]))continue;if(this.#e.indexOf(o[e].field)>l){t=e;break}}o.splice(t,0,e)}else o.splice(Math.min(n,o.length),0,e);o.some(t=>null!=r(t))||(this.#e=[]),s.columns=o}}refreshStickyOffsets(){const t=[...this.columns];d(this.grid,t)}getLeftPinnedColumns(){return function(t,e="ltr"){return t.filter(t=>o(t,e))}([...this.columns],t(this.grid))}getRightPinnedColumns(){return function(t,e="ltr"){return t.filter(t=>l(t,e))}([...this.columns],t(this.grid))}clearStickyPositions(){u(this.grid)}getHorizontalScrollOffsets(t,e){if(!this.isApplied)return;let i=0,n=0;if(t){const e=t.querySelectorAll(".sticky-left"),r=t.querySelectorAll(".sticky-right");e.forEach(t=>{i+=t.offsetWidth}),r.forEach(t=>{n+=t.offsetWidth})}else{this.grid.querySelectorAll(".header-row .cell").forEach(t=>{t.classList.contains("sticky-left")?i+=t.offsetWidth:t.classList.contains("sticky-right")&&(n+=t.offsetWidth)})}const r=e?.classList.contains("sticky-left")||e?.classList.contains("sticky-right");return{left:i,right:n,skipScroll:r}}}export{a as PinnedColumnsPlugin};
689
2
  //# sourceMappingURL=index.js.map