@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,729 +1,2 @@
1
- function v(l) {
2
- l && l.querySelectorAll(".cell-focus").forEach((e) => e.classList.remove("cell-focus"));
3
- }
4
- const m = 'input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])', R = document.createElement("template");
5
- R.innerHTML = '<div class="cell" role="gridcell" part="cell"></div>';
6
- const E = document.createElement("template");
7
- E.innerHTML = '<div class="data-grid-row" role="row" part="row"></div>';
8
- function b(l, e) {
9
- if (l._virtualization?.enabled) {
10
- const { rowHeight: i, container: n, viewportEl: c } = l._virtualization, a = n, u = c?.clientHeight ?? a?.clientHeight ?? 0;
11
- if (a && u > 0) {
12
- const d = l._focusRow * i;
13
- d < a.scrollTop ? a.scrollTop = d : d + i > a.scrollTop + u && (a.scrollTop = d - u + i);
14
- }
15
- }
16
- const t = l._activeEditRows !== void 0 && l._activeEditRows !== -1;
17
- t || l.refreshVirtualWindow(!1), v(l._bodyEl), Array.from(l._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach((i) => {
18
- i.setAttribute("aria-selected", "false");
19
- });
20
- const r = l._focusRow, o = l._virtualization.start ?? 0, s = l._virtualization.end ?? l._rows.length;
21
- if (r >= o && r < s) {
22
- const i = l._bodyEl.querySelectorAll(".data-grid-row")[r - o];
23
- let n = i?.children[l._focusCol];
24
- if ((!n || !n.classList?.contains("cell")) && (n = i?.querySelector(`.cell[data-col="${l._focusCol}"]`) ?? i?.querySelector(".cell[data-col]")), n) {
25
- n.classList.add("cell-focus"), n.setAttribute("aria-selected", "true");
26
- const c = l.querySelector(".tbw-scroll-area");
27
- if (c && n && (!t || e?.forceHorizontalScroll)) {
28
- const a = l._getHorizontalScrollOffsets?.(i ?? void 0, n) ?? { left: 0, right: 0 };
29
- if (!a.skipScroll) {
30
- const u = n.getBoundingClientRect(), d = c.getBoundingClientRect(), g = u.left - d.left + c.scrollLeft, h = g + u.width, w = c.scrollLeft + a.left, f = c.scrollLeft + c.clientWidth - a.right;
31
- g < w ? c.scrollLeft = g - a.left : h > f && (c.scrollLeft = h - c.clientWidth + a.right);
32
- }
33
- }
34
- if (t && n.classList.contains("editing")) {
35
- const a = n.querySelector(m);
36
- if (a && document.activeElement !== a)
37
- try {
38
- a.focus({ preventScroll: !0 });
39
- } catch {
40
- }
41
- } else if (t && !n.contains(document.activeElement)) {
42
- n.hasAttribute("tabindex") || n.setAttribute("tabindex", "-1");
43
- try {
44
- n.focus({ preventScroll: !0 });
45
- } catch {
46
- }
47
- } else if (!t) {
48
- const a = l;
49
- document.activeElement !== a && a.focus({ preventScroll: !0 });
50
- }
51
- }
52
- }
53
- }
54
- const p = '<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>', _ = {
55
- expand: "▶",
56
- collapse: "▼",
57
- sortAsc: "▲",
58
- sortDesc: "▼",
59
- sortNone: "⇅",
60
- submenuArrow: "▶",
61
- dragHandle: "⋮⋮",
62
- toolPanel: "☰",
63
- filter: p,
64
- filterActive: p,
65
- print: "🖨️"
66
- };
67
- class y {
68
- /**
69
- * Plugin dependencies - declare other plugins this one requires.
70
- *
71
- * Dependencies are validated when the plugin is attached.
72
- * Required dependencies throw an error if missing.
73
- * Optional dependencies log an info message if missing.
74
- *
75
- * @example
76
- * ```typescript
77
- * static readonly dependencies: PluginDependency[] = [
78
- * { name: 'editing', required: true, reason: 'Tracks cell edits for undo/redo' },
79
- * { name: 'selection', required: false, reason: 'Enables selection-based undo' },
80
- * ];
81
- * ```
82
- */
83
- static dependencies;
84
- /**
85
- * Plugin manifest - declares owned properties, config rules, and hook priorities.
86
- *
87
- * This is read by the configuration validator to:
88
- * - Validate that required plugins are loaded when their properties are used
89
- * - Execute configRules to detect invalid/conflicting settings
90
- * - Order hook execution based on priority
91
- *
92
- * @example
93
- * ```typescript
94
- * static override readonly manifest: PluginManifest<MyConfig> = {
95
- * ownedProperties: [
96
- * { property: 'myProp', level: 'column', description: 'the "myProp" column property' },
97
- * ],
98
- * configRules: [
99
- * { id: 'myPlugin/conflict', severity: 'warn', message: '...', check: (c) => c.a && c.b },
100
- * ],
101
- * };
102
- * ```
103
- */
104
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
105
- static manifest;
106
- /**
107
- * Plugin version - defaults to grid version for built-in plugins.
108
- * Third-party plugins can override with their own semver.
109
- */
110
- version = typeof __GRID_VERSION__ < "u" ? __GRID_VERSION__ : "dev";
111
- /** CSS styles to inject into the grid's shadow DOM */
112
- styles;
113
- /** Custom cell renderers keyed by type name */
114
- cellRenderers;
115
- /** Custom header renderers keyed by type name */
116
- headerRenderers;
117
- /** Custom cell editors keyed by type name */
118
- cellEditors;
119
- /** The grid instance this plugin is attached to */
120
- grid;
121
- /** Plugin configuration - merged with defaults in attach() */
122
- config;
123
- /** User-provided configuration from constructor */
124
- userConfig;
125
- /**
126
- * Plugin-level AbortController for event listener cleanup.
127
- * Created fresh in attach(), aborted in detach().
128
- * This ensures event listeners are properly cleaned up when plugins are re-attached.
129
- */
130
- #e;
131
- /**
132
- * Default configuration - subclasses should override this getter.
133
- * Note: This must be a getter (not property initializer) for proper inheritance
134
- * since property initializers run after parent constructor.
135
- */
136
- get defaultConfig() {
137
- return {};
138
- }
139
- constructor(e = {}) {
140
- this.userConfig = e;
141
- }
142
- /**
143
- * Called when the plugin is attached to a grid.
144
- * Override to set up event listeners, initialize state, etc.
145
- *
146
- * @example
147
- * ```ts
148
- * attach(grid: GridElement): void {
149
- * super.attach(grid);
150
- * // Set up document-level listeners with auto-cleanup
151
- * document.addEventListener('keydown', this.handleEscape, {
152
- * signal: this.disconnectSignal
153
- * });
154
- * }
155
- * ```
156
- */
157
- attach(e) {
158
- this.#e?.abort(), this.#e = new AbortController(), this.grid = e, this.config = { ...this.defaultConfig, ...this.userConfig };
159
- }
160
- /**
161
- * Called when the plugin is detached from a grid.
162
- * Override to clean up event listeners, timers, etc.
163
- *
164
- * @example
165
- * ```ts
166
- * detach(): void {
167
- * // Clean up any state not handled by disconnectSignal
168
- * this.selectedRows.clear();
169
- * this.cache = null;
170
- * }
171
- * ```
172
- */
173
- detach() {
174
- this.#e?.abort(), this.#e = void 0;
175
- }
176
- /**
177
- * Get another plugin instance from the same grid.
178
- * Use for inter-plugin communication.
179
- *
180
- * @example
181
- * ```ts
182
- * const selection = this.getPlugin(SelectionPlugin);
183
- * if (selection) {
184
- * const selectedRows = selection.getSelectedRows();
185
- * }
186
- * ```
187
- */
188
- getPlugin(e) {
189
- return this.grid?.getPlugin(e);
190
- }
191
- /**
192
- * Emit a custom event from the grid.
193
- */
194
- emit(e, t) {
195
- this.grid?.dispatchEvent?.(new CustomEvent(e, { detail: t, bubbles: !0 }));
196
- }
197
- /**
198
- * Emit a cancelable custom event from the grid.
199
- * @returns `true` if the event was cancelled (preventDefault called), `false` otherwise
200
- */
201
- emitCancelable(e, t) {
202
- const r = new CustomEvent(e, { detail: t, bubbles: !0, cancelable: !0 });
203
- return this.grid?.dispatchEvent?.(r), r.defaultPrevented;
204
- }
205
- // =========================================================================
206
- // Event Bus - Plugin-to-Plugin Communication
207
- // =========================================================================
208
- /**
209
- * Subscribe to an event from another plugin.
210
- * The subscription is automatically cleaned up when this plugin is detached.
211
- *
212
- * @category Plugin Development
213
- * @param eventType - The event type to listen for (e.g., 'filter-change')
214
- * @param callback - The callback to invoke when the event is emitted
215
- *
216
- * @example
217
- * ```typescript
218
- * // In attach() or other initialization
219
- * this.on('filter-change', (detail) => {
220
- * console.log('Filter changed:', detail);
221
- * });
222
- * ```
223
- */
224
- on(e, t) {
225
- this.grid?._pluginManager?.subscribe(this, e, t);
226
- }
227
- /**
228
- * Unsubscribe from a plugin event.
229
- *
230
- * @category Plugin Development
231
- * @param eventType - The event type to stop listening for
232
- *
233
- * @example
234
- * ```typescript
235
- * this.off('filter-change');
236
- * ```
237
- */
238
- off(e) {
239
- this.grid?._pluginManager?.unsubscribe(this, e);
240
- }
241
- /**
242
- * Emit an event to other plugins via the Event Bus.
243
- * This is for inter-plugin communication only; it does NOT dispatch DOM events.
244
- * Use `emit()` to dispatch DOM events that external consumers can listen to.
245
- *
246
- * @category Plugin Development
247
- * @param eventType - The event type to emit (should be declared in manifest.events)
248
- * @param detail - The event payload
249
- *
250
- * @example
251
- * ```typescript
252
- * // Emit to other plugins (not DOM)
253
- * this.emitPluginEvent('filter-change', { field: 'name', value: 'Alice' });
254
- *
255
- * // For DOM events that consumers can addEventListener to:
256
- * this.emit('filter-change', { field: 'name', value: 'Alice' });
257
- * ```
258
- */
259
- emitPluginEvent(e, t) {
260
- this.grid?._pluginManager?.emitPluginEvent(e, t);
261
- }
262
- /**
263
- * Request a re-render of the grid.
264
- * Uses ROWS phase - does NOT trigger processColumns hooks.
265
- */
266
- requestRender() {
267
- this.grid?.requestRender?.();
268
- }
269
- /**
270
- * Request a columns re-render of the grid.
271
- * Uses COLUMNS phase - triggers processColumns hooks.
272
- * Use this when your plugin needs to reprocess column configuration.
273
- */
274
- requestColumnsRender() {
275
- this.grid?.requestColumnsRender?.();
276
- }
277
- /**
278
- * Request a re-render and restore focus styling afterward.
279
- * Use this when a plugin action (like expand/collapse) triggers a render
280
- * but needs to maintain keyboard navigation focus.
281
- */
282
- requestRenderWithFocus() {
283
- this.grid?.requestRenderWithFocus?.();
284
- }
285
- /**
286
- * Request a lightweight style update without rebuilding DOM.
287
- * Use this instead of requestRender() when only CSS classes need updating.
288
- */
289
- requestAfterRender() {
290
- this.grid?.requestAfterRender?.();
291
- }
292
- /**
293
- * Get the current rows from the grid.
294
- */
295
- get rows() {
296
- return this.grid?.rows ?? [];
297
- }
298
- /**
299
- * Get the original unfiltered/unprocessed rows from the grid.
300
- * Use this when you need all source data regardless of active filters.
301
- */
302
- get sourceRows() {
303
- return this.grid?.sourceRows ?? [];
304
- }
305
- /**
306
- * Get the current columns from the grid.
307
- */
308
- get columns() {
309
- return this.grid?.columns ?? [];
310
- }
311
- /**
312
- * Get only visible columns from the grid (excludes hidden).
313
- * Use this for rendering that needs to match the grid template.
314
- */
315
- get visibleColumns() {
316
- return this.grid?._visibleColumns ?? [];
317
- }
318
- /**
319
- * Get the grid as an HTMLElement for direct DOM operations.
320
- * Use sparingly - prefer the typed GridElementRef API when possible.
321
- *
322
- * @example
323
- * ```ts
324
- * const width = this.gridElement.clientWidth;
325
- * this.gridElement.classList.add('my-plugin-active');
326
- * ```
327
- */
328
- get gridElement() {
329
- return this.grid;
330
- }
331
- /**
332
- * Get the disconnect signal for event listener cleanup.
333
- * This signal is aborted when the grid disconnects from the DOM.
334
- * Use this when adding event listeners that should be cleaned up automatically.
335
- *
336
- * Best for:
337
- * - Document/window-level listeners added in attach()
338
- * - Listeners on the grid element itself
339
- * - Any listener that should persist across renders
340
- *
341
- * Not needed for:
342
- * - Listeners on elements created in afterRender() (removed with element)
343
- *
344
- * @example
345
- * element.addEventListener('click', handler, { signal: this.disconnectSignal });
346
- * document.addEventListener('keydown', handler, { signal: this.disconnectSignal });
347
- */
348
- get disconnectSignal() {
349
- return this.#e?.signal ?? this.grid?.disconnectSignal;
350
- }
351
- /**
352
- * Get the grid-level icons configuration.
353
- * Returns merged icons (user config + defaults).
354
- */
355
- get gridIcons() {
356
- const e = this.grid?.gridConfig?.icons ?? {};
357
- return { ..._, ...e };
358
- }
359
- // #region Animation Helpers
360
- /**
361
- * Check if animations are enabled at the grid level.
362
- * Respects gridConfig.animation.mode and the CSS variable set by the grid.
363
- *
364
- * Plugins should use this to skip animations when:
365
- * - Animation mode is 'off' or `false`
366
- * - User prefers reduced motion and mode is 'reduced-motion' (default)
367
- *
368
- * @example
369
- * ```ts
370
- * private get animationStyle(): 'slide' | 'fade' | false {
371
- * if (!this.isAnimationEnabled) return false;
372
- * return this.config.animation ?? 'slide';
373
- * }
374
- * ```
375
- */
376
- get isAnimationEnabled() {
377
- const e = this.grid?.effectiveConfig?.animation?.mode ?? "reduced-motion";
378
- if (e === !1 || e === "off") return !1;
379
- if (e === !0 || e === "on") return !0;
380
- const t = this.gridElement;
381
- return t ? getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim() !== "0" : !0;
382
- }
383
- /**
384
- * Get the animation duration in milliseconds from CSS variable.
385
- * Falls back to 200ms if not set.
386
- *
387
- * Plugins can use this for their animation timing to stay consistent
388
- * with the grid-level animation.duration setting.
389
- *
390
- * @example
391
- * ```ts
392
- * element.animate(keyframes, { duration: this.animationDuration });
393
- * ```
394
- */
395
- get animationDuration() {
396
- const e = this.gridElement;
397
- if (e) {
398
- const t = getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(), r = parseInt(t, 10);
399
- if (!isNaN(r)) return r;
400
- }
401
- return 200;
402
- }
403
- // #endregion
404
- /**
405
- * Resolve an icon value to string or HTMLElement.
406
- * Checks plugin config first, then grid-level icons, then defaults.
407
- *
408
- * @param iconKey - The icon key in GridIcons (e.g., 'expand', 'collapse')
409
- * @param pluginOverride - Optional plugin-level override
410
- * @returns The resolved icon value
411
- */
412
- resolveIcon(e, t) {
413
- return t !== void 0 ? t : this.gridIcons[e];
414
- }
415
- /**
416
- * Set an icon value on an element.
417
- * Handles both string (text/HTML) and HTMLElement values.
418
- *
419
- * @param element - The element to set the icon on
420
- * @param icon - The icon value (string or HTMLElement)
421
- */
422
- setIcon(e, t) {
423
- typeof t == "string" ? e.innerHTML = t : t instanceof HTMLElement && (e.innerHTML = "", e.appendChild(t.cloneNode(!0)));
424
- }
425
- /**
426
- * Log a warning message.
427
- */
428
- warn(e) {
429
- console.warn(`[tbw-grid:${this.name}] ${e}`);
430
- }
431
- // #endregion
432
- }
433
- const C = '@layer tbw-plugins{[data-field=__tbw_row_drag]{display:flex;align-items:center;justify-content:center}.dg-row-drag-handle{display:flex;align-items:center;justify-content:center;min-width:1em;min-height:1em;cursor:grab;-webkit-user-select:none;user-select:none;color:var(--tbw-row-reorder-handle-color, var(--tbw-color-fg-muted));transition:color var(--tbw-transition-duration, .12s) var(--tbw-transition-ease, ease);font-size:var(--tbw-font-size, 1em);letter-spacing:-2px}.dg-row-drag-handle:hover{color:var(--tbw-row-reorder-handle-hover, var(--tbw-color-fg))}.dg-row-drag-handle:active{cursor:grabbing}.data-grid-row.dragging{opacity:.6}.data-grid-row.drop-target{position:relative}.data-grid-row.drop-target.drop-before:before{content:"";position:absolute;top:0;left:0;right:0;height:2px;background-color:var(--tbw-row-reorder-indicator, var(--tbw-color-accent));z-index:10}.data-grid-row.drop-target.drop-after:after{content:"";position:absolute;bottom:0;left:0;right:0;height:2px;background-color:var(--tbw-row-reorder-indicator, var(--tbw-color-accent));z-index:10}.data-grid-row.keyboard-moving{background-color:var(--tbw-row-reorder-moving-bg, var(--tbw-focus-background));box-shadow:0 0 0 1px var(--tbw-row-reorder-moving-border, var(--tbw-color-accent)) inset}.data-grid-row.flip-animating{transition:transform var(--tbw-animation-duration, .2s) ease-out;will-change:transform;z-index:1}}', A = "__tbw_row_drag";
434
- class L extends y {
435
- /** @internal */
436
- name = "rowReorder";
437
- /** @internal */
438
- styles = C;
439
- /** @internal */
440
- get defaultConfig() {
441
- return {
442
- enableKeyboard: !0,
443
- showDragHandle: !0,
444
- dragHandlePosition: "left",
445
- dragHandleWidth: 40,
446
- debounceMs: 150,
447
- animation: "flip"
448
- };
449
- }
450
- /**
451
- * Resolve animation type from plugin config.
452
- * Uses base class isAnimationEnabled to respect grid-level settings.
453
- */
454
- get animationType() {
455
- return this.isAnimationEnabled ? this.config.animation !== void 0 ? this.config.animation : "flip" : !1;
456
- }
457
- // #region Internal State
458
- isDragging = !1;
459
- draggedRowIndex = null;
460
- dropRowIndex = null;
461
- pendingMove = null;
462
- debounceTimer = null;
463
- /** Column index to use when flushing pending move */
464
- lastFocusCol = 0;
465
- // #endregion
466
- // #region Lifecycle
467
- /** @internal */
468
- detach() {
469
- this.clearDebounceTimer(), this.isDragging = !1, this.draggedRowIndex = null, this.dropRowIndex = null, this.pendingMove = null;
470
- }
471
- // #endregion
472
- // #region Hooks
473
- /** @internal */
474
- processColumns(e) {
475
- if (!this.config.showDragHandle)
476
- return [...e];
477
- const t = {
478
- field: A,
479
- header: "",
480
- width: this.config.dragHandleWidth ?? 40,
481
- resizable: !1,
482
- sortable: !1,
483
- filterable: !1,
484
- meta: {
485
- lockPosition: !0,
486
- suppressMovable: !0,
487
- utility: !0
488
- },
489
- viewRenderer: () => {
490
- const r = document.createElement("div");
491
- return r.className = "dg-row-drag-handle", r.setAttribute("aria-label", "Drag to reorder"), r.setAttribute("role", "button"), r.setAttribute("tabindex", "-1"), r.draggable = !0, this.setIcon(r, this.resolveIcon("dragHandle")), r;
492
- }
493
- };
494
- return this.config.dragHandlePosition === "right" ? [...e, t] : [t, ...e];
495
- }
496
- /** @internal */
497
- afterRender() {
498
- if (!this.config.showDragHandle) return;
499
- const e = this.gridElement;
500
- if (!e) return;
501
- e.querySelectorAll(".dg-row-drag-handle").forEach((o) => {
502
- const s = o;
503
- if (s.getAttribute("data-drag-bound")) return;
504
- s.setAttribute("data-drag-bound", "true");
505
- const i = s.closest(".data-grid-row");
506
- i && this.setupHandleDragListeners(s, i);
507
- }), e.querySelectorAll(".data-grid-row").forEach((o) => {
508
- const s = o;
509
- s.getAttribute("data-drop-bound") || (s.setAttribute("data-drop-bound", "true"), this.setupRowDropListeners(s));
510
- });
511
- }
512
- /**
513
- * Handle Ctrl+Arrow keyboard shortcuts for row reordering.
514
- * @internal
515
- */
516
- onKeyDown(e) {
517
- if (!this.config.enableKeyboard || !e.ctrlKey || e.key !== "ArrowUp" && e.key !== "ArrowDown")
518
- return;
519
- const t = this.grid, r = t._focusRow, o = t._rows ?? this.sourceRows;
520
- if (r < 0 || r >= o.length) return;
521
- const s = e.key === "ArrowUp" ? "up" : "down", i = s === "up" ? r - 1 : r + 1;
522
- if (i < 0 || i >= o.length) return;
523
- const n = o[r];
524
- if (!(this.config.canMove && !this.config.canMove(n, r, i, s)))
525
- return this.handleKeyboardMove(n, r, i, s, t._focusCol), e.preventDefault(), e.stopPropagation(), !0;
526
- }
527
- /**
528
- * Flush pending keyboard moves when user clicks a cell.
529
- * This commits the move immediately so focus works correctly.
530
- * @internal
531
- */
532
- onCellClick() {
533
- this.flushPendingMove();
534
- }
535
- // #endregion
536
- // #region Public API
537
- /**
538
- * Move a row to a new position programmatically.
539
- * @param fromIndex - Current index of the row
540
- * @param toIndex - Target index
541
- */
542
- moveRow(e, t) {
543
- const r = [...this.sourceRows];
544
- if (e < 0 || e >= r.length || t < 0 || t >= r.length || e === t) return;
545
- const o = t < e ? "up" : "down", s = r[e];
546
- this.config.canMove && !this.config.canMove(s, e, t, o) || this.executeMove(s, e, t, "keyboard");
547
- }
548
- /**
549
- * Check if a row can be moved to a position.
550
- * @param fromIndex - Current index of the row
551
- * @param toIndex - Target index
552
- */
553
- canMoveRow(e, t) {
554
- const r = this.sourceRows;
555
- if (e < 0 || e >= r.length || t < 0 || t >= r.length || e === t) return !1;
556
- if (!this.config.canMove) return !0;
557
- const o = t < e ? "up" : "down";
558
- return this.config.canMove(r[e], e, t, o);
559
- }
560
- // #endregion
561
- // #region Private Methods
562
- /**
563
- * Set up drag start/end listeners on the drag handle element.
564
- */
565
- setupHandleDragListeners(e, t) {
566
- e.addEventListener("dragstart", (r) => {
567
- const o = this.getRowIndex(t);
568
- o < 0 || (this.isDragging = !0, this.draggedRowIndex = o, r.dataTransfer && (r.dataTransfer.effectAllowed = "move", r.dataTransfer.setData("text/plain", String(o))), t.classList.add("dragging"));
569
- }), e.addEventListener("dragend", () => {
570
- this.isDragging = !1, this.draggedRowIndex = null, this.dropRowIndex = null, this.clearDragClasses();
571
- });
572
- }
573
- /**
574
- * Set up drop target listeners on a row element.
575
- * All rows are valid drop targets during drag operations.
576
- */
577
- setupRowDropListeners(e) {
578
- e.addEventListener("dragover", (t) => {
579
- if (t.preventDefault(), !this.isDragging || this.draggedRowIndex === null) return;
580
- const r = this.getRowIndex(e);
581
- if (r < 0 || r === this.draggedRowIndex) return;
582
- const o = e.getBoundingClientRect(), s = o.top + o.height / 2, i = t.clientY < s;
583
- this.dropRowIndex = i ? r : r + 1, e.classList.add("drop-target"), e.classList.toggle("drop-before", i), e.classList.toggle("drop-after", !i);
584
- }), e.addEventListener("dragleave", () => {
585
- e.classList.remove("drop-target", "drop-before", "drop-after");
586
- }), e.addEventListener("drop", (t) => {
587
- t.preventDefault();
588
- const r = this.draggedRowIndex;
589
- let o = this.dropRowIndex;
590
- if (!(!this.isDragging || r === null || o === null) && (o > r && o--, r !== o)) {
591
- const i = this.sourceRows[r], n = o < r ? "up" : "down";
592
- (!this.config.canMove || this.config.canMove(i, r, o, n)) && this.executeMove(i, r, o, "drag");
593
- }
594
- });
595
- }
596
- /**
597
- * Handle debounced keyboard moves.
598
- * Rows move immediately for visual feedback, but the event emission is debounced.
599
- */
600
- handleKeyboardMove(e, t, r, o, s) {
601
- this.pendingMove ? this.pendingMove.currentIndex = r : this.pendingMove = {
602
- originalIndex: t,
603
- currentIndex: r,
604
- row: e
605
- }, this.lastFocusCol = s;
606
- const i = this.grid, n = [...i._rows ?? this.sourceRows], [c] = n.splice(t, 1);
607
- n.splice(r, 0, c), i._rows = n, i._focusRow = r, i._focusCol = s, i.refreshVirtualWindow(!0), b(i), this.clearDebounceTimer(), this.debounceTimer = setTimeout(() => {
608
- this.flushPendingMove();
609
- }, this.config.debounceMs ?? 300);
610
- }
611
- /**
612
- * Flush the pending move by emitting the event.
613
- * Called when debounce timer fires or user clicks elsewhere.
614
- */
615
- flushPendingMove() {
616
- if (this.clearDebounceTimer(), !this.pendingMove) return;
617
- const { originalIndex: e, currentIndex: t, row: r } = this.pendingMove;
618
- if (this.pendingMove = null, e === t) return;
619
- const o = {
620
- row: r,
621
- fromIndex: e,
622
- toIndex: t,
623
- rows: [...this.sourceRows],
624
- source: "keyboard"
625
- };
626
- if (this.emitCancelable("row-move", o)) {
627
- const i = [...this.sourceRows], [n] = i.splice(t, 1);
628
- i.splice(e, 0, n);
629
- const c = this.grid;
630
- c._rows = i, c._focusRow = e, c._focusCol = this.lastFocusCol, c.refreshVirtualWindow(!0), b(c);
631
- }
632
- }
633
- /**
634
- * Execute a row move and emit the event.
635
- */
636
- executeMove(e, t, r, o) {
637
- const s = [...this.sourceRows], [i] = s.splice(t, 1);
638
- s.splice(r, 0, i);
639
- const n = {
640
- row: e,
641
- fromIndex: t,
642
- toIndex: r,
643
- rows: s,
644
- source: o
645
- };
646
- if (!this.emitCancelable("row-move", n))
647
- if (this.animationType === "flip" && this.gridElement) {
648
- const a = this.captureRowPositions();
649
- this.grid.rows = s, requestAnimationFrame(() => {
650
- this.gridElement.offsetHeight, this.animateFLIP(a, t, r);
651
- });
652
- } else
653
- this.grid.rows = s;
654
- }
655
- /**
656
- * Capture row positions before reorder.
657
- * Maps visual row index to its top position.
658
- */
659
- captureRowPositions() {
660
- const e = /* @__PURE__ */ new Map();
661
- return this.gridElement?.querySelectorAll(".data-grid-row").forEach((t) => {
662
- const r = this.getRowIndex(t);
663
- r >= 0 && e.set(r, t.getBoundingClientRect().top);
664
- }), e;
665
- }
666
- /**
667
- * Apply FLIP animation for row reorder.
668
- * Uses CSS transitions - JS sets initial transform and toggles class.
669
- * @param oldPositions - Row positions captured before DOM change
670
- * @param fromIndex - Original index of moved row
671
- * @param toIndex - New index of moved row
672
- */
673
- animateFLIP(e, t, r) {
674
- const o = this.gridElement;
675
- if (!o || e.size === 0) return;
676
- const s = Math.min(t, r), i = Math.max(t, r), n = [];
677
- if (o.querySelectorAll(".data-grid-row").forEach((a) => {
678
- const u = a, d = this.getRowIndex(u);
679
- if (d < 0 || d < s || d > i) return;
680
- let g;
681
- d === r ? g = t : t < r ? g = d + 1 : g = d - 1;
682
- const h = e.get(g);
683
- if (h === void 0) return;
684
- const w = u.getBoundingClientRect().top, f = h - w;
685
- Math.abs(f) > 1 && n.push({ el: u, deltaY: f });
686
- }), n.length === 0) return;
687
- n.forEach(({ el: a, deltaY: u }) => {
688
- a.style.transform = `translateY(${u}px)`;
689
- }), o.offsetHeight;
690
- const c = this.animationDuration;
691
- requestAnimationFrame(() => {
692
- n.forEach(({ el: a }) => {
693
- a.classList.add("flip-animating"), a.style.transform = "";
694
- }), setTimeout(() => {
695
- n.forEach(({ el: a }) => {
696
- a.style.transform = "", a.classList.remove("flip-animating");
697
- });
698
- }, c + 50);
699
- });
700
- }
701
- /**
702
- * Get the row index from a row element by checking data-row attribute on cells.
703
- * This is consistent with how other plugins retrieve row indices.
704
- */
705
- getRowIndex(e) {
706
- const t = e.querySelector(".cell[data-row]");
707
- return t ? parseInt(t.getAttribute("data-row") ?? "-1", 10) : -1;
708
- }
709
- /**
710
- * Clear all drag-related classes from rows.
711
- */
712
- clearDragClasses() {
713
- this.gridElement?.querySelectorAll(".data-grid-row").forEach((e) => {
714
- e.classList.remove("dragging", "drop-target", "drop-before", "drop-after");
715
- });
716
- }
717
- /**
718
- * Clear the debounce timer.
719
- */
720
- clearDebounceTimer() {
721
- this.debounceTimer && (clearTimeout(this.debounceTimer), this.debounceTimer = null);
722
- }
723
- // #endregion
724
- }
725
- export {
726
- A as ROW_DRAG_HANDLE_FIELD,
727
- L as RowReorderPlugin
728
- };
1
+ document.createElement("template").innerHTML='<div class="cell" role="gridcell" part="cell"></div>';function e(e,t){if(e._virtualization?.enabled){const{rowHeight:t,container:r,viewportEl:o}=e._virtualization,i=r,n=o?.clientHeight??i?.clientHeight??0;if(i&&n>0){const r=e._focusRow*t;r<i.scrollTop?i.scrollTop=r:r+t>i.scrollTop+n&&(i.scrollTop=r-n+t)}}const r=void 0!==e._activeEditRows&&-1!==e._activeEditRows;var o;r||e.refreshVirtualWindow(!1),(o=e._bodyEl)&&o.querySelectorAll(".cell-focus").forEach(e=>e.classList.remove("cell-focus")),Array.from(e._bodyEl.querySelectorAll('[aria-selected="true"]')).forEach(e=>{e.setAttribute("aria-selected","false")});const i=e._focusRow,n=e._virtualization.start??0,s=e._virtualization.end??e._rows.length;if(i>=n&&i<s){const o=e._bodyEl.querySelectorAll(".data-grid-row")[i-n];let s=o?.children[e._focusCol];if(s&&s.classList?.contains("cell")||(s=o?.querySelector(`.cell[data-col="${e._focusCol}"]`)??o?.querySelector(".cell[data-col]")),s){s.classList.add("cell-focus"),s.setAttribute("aria-selected","true");const i=e.querySelector(".tbw-scroll-area");if(i&&s&&(!r||t?.forceHorizontalScroll)){const t=e._getHorizontalScrollOffsets?.(o??void 0,s)??{left:0,right:0};if(!t.skipScroll){const e=s.getBoundingClientRect(),r=i.getBoundingClientRect(),o=e.left-r.left+i.scrollLeft,n=o+e.width,a=i.scrollLeft+t.left,l=i.scrollLeft+i.clientWidth-t.right;o<a?i.scrollLeft=o-t.left:n>l&&(i.scrollLeft=n-i.clientWidth+t.right)}}if(r&&s.classList.contains("editing")){const e=s.querySelector('input,select,textarea,[contenteditable="true"],[contenteditable=""],[tabindex]:not([tabindex="-1"])');if(e&&document.activeElement!==e)try{e.focus({preventScroll:!0})}catch{}}else if(r&&!s.contains(document.activeElement)){s.hasAttribute("tabindex")||s.setAttribute("tabindex","-1");try{s.focus({preventScroll:!0})}catch{}}else if(!r){const t=e;document.activeElement!==t&&t.focus({preventScroll:!0})}}}}document.createElement("template").innerHTML='<div class="data-grid-row" role="row" part="row"></div>';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>',r={expand:"▶",collapse:"▼",sortAsc:"▲",sortDesc:"▼",sortNone:"⇅",submenuArrow:"▶",dragHandle:"⋮⋮",toolPanel:"☰",filter:t,filterActive:t,print:"🖨️"};class o{static dependencies;static manifest;version="undefined"!=typeof __GRID_VERSION__?__GRID_VERSION__:"dev";styles;cellRenderers;headerRenderers;cellEditors;grid;config;userConfig;#e;get defaultConfig(){return{}}constructor(e={}){this.userConfig=e}attach(e){this.#e?.abort(),this.#e=new AbortController,this.grid=e,this.config={...this.defaultConfig,...this.userConfig}}detach(){this.#e?.abort(),this.#e=void 0}getPlugin(e){return this.grid?.getPlugin(e)}emit(e,t){this.grid?.dispatchEvent?.(new CustomEvent(e,{detail:t,bubbles:!0}))}emitCancelable(e,t){const r=new CustomEvent(e,{detail:t,bubbles:!0,cancelable:!0});return this.grid?.dispatchEvent?.(r),r.defaultPrevented}on(e,t){this.grid?._pluginManager?.subscribe(this,e,t)}off(e){this.grid?._pluginManager?.unsubscribe(this,e)}emitPluginEvent(e,t){this.grid?._pluginManager?.emitPluginEvent(e,t)}requestRender(){this.grid?.requestRender?.()}requestColumnsRender(){this.grid?.requestColumnsRender?.()}requestRenderWithFocus(){this.grid?.requestRenderWithFocus?.()}requestAfterRender(){this.grid?.requestAfterRender?.()}get rows(){return this.grid?.rows??[]}get sourceRows(){return this.grid?.sourceRows??[]}get columns(){return this.grid?.columns??[]}get visibleColumns(){return this.grid?._visibleColumns??[]}get gridElement(){return this.grid}get disconnectSignal(){return this.#e?.signal??this.grid?.disconnectSignal}get gridIcons(){const e=this.grid?.gridConfig?.icons??{};return{...r,...e}}get isAnimationEnabled(){const e=this.grid?.effectiveConfig?.animation?.mode??"reduced-motion";if(!1===e||"off"===e)return!1;if(!0===e||"on"===e)return!0;const t=this.gridElement;if(t){return"0"!==getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim()}return!0}get animationDuration(){const e=this.gridElement;if(e){const t=getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(),r=parseInt(t,10);if(!isNaN(r))return r}return 200}resolveIcon(e,t){return void 0!==t?t:this.gridIcons[e]}setIcon(e,t){"string"==typeof t?e.innerHTML=t:t instanceof HTMLElement&&(e.innerHTML="",e.appendChild(t.cloneNode(!0)))}warn(e){console.warn(`[tbw-grid:${this.name}] ${e}`)}}const i="__tbw_row_drag";class n extends o{name="rowReorder";styles='@layer tbw-plugins{[data-field=__tbw_row_drag]{display:flex;align-items:center;justify-content:center}.dg-row-drag-handle{display:flex;align-items:center;justify-content:center;min-width:1em;min-height:1em;cursor:grab;-webkit-user-select:none;user-select:none;color:var(--tbw-row-reorder-handle-color, var(--tbw-color-fg-muted));transition:color var(--tbw-transition-duration, .12s) var(--tbw-transition-ease, ease);font-size:var(--tbw-font-size, 1em);letter-spacing:-2px}.dg-row-drag-handle:hover{color:var(--tbw-row-reorder-handle-hover, var(--tbw-color-fg))}.dg-row-drag-handle:active{cursor:grabbing}.data-grid-row.dragging{opacity:.6}.data-grid-row.drop-target{position:relative}.data-grid-row.drop-target.drop-before:before{content:"";position:absolute;top:0;left:0;right:0;height:2px;background-color:var(--tbw-row-reorder-indicator, var(--tbw-color-accent));z-index:10}.data-grid-row.drop-target.drop-after:after{content:"";position:absolute;bottom:0;left:0;right:0;height:2px;background-color:var(--tbw-row-reorder-indicator, var(--tbw-color-accent));z-index:10}.data-grid-row.keyboard-moving{background-color:var(--tbw-row-reorder-moving-bg, var(--tbw-focus-background));box-shadow:0 0 0 1px var(--tbw-row-reorder-moving-border, var(--tbw-color-accent)) inset}.data-grid-row.flip-animating{transition:transform var(--tbw-animation-duration, .2s) ease-out;will-change:transform;z-index:1}}';get defaultConfig(){return{enableKeyboard:!0,showDragHandle:!0,dragHandlePosition:"left",dragHandleWidth:40,debounceMs:150,animation:"flip"}}get animationType(){return!!this.isAnimationEnabled&&(void 0!==this.config.animation?this.config.animation:"flip")}isDragging=!1;draggedRowIndex=null;dropRowIndex=null;pendingMove=null;debounceTimer=null;lastFocusCol=0;detach(){this.clearDebounceTimer(),this.isDragging=!1,this.draggedRowIndex=null,this.dropRowIndex=null,this.pendingMove=null}processColumns(e){if(!this.config.showDragHandle)return[...e];const t={field:i,header:"",width:this.config.dragHandleWidth??40,resizable:!1,sortable:!1,filterable:!1,meta:{lockPosition:!0,suppressMovable:!0,utility:!0},viewRenderer:()=>{const e=document.createElement("div");return e.className="dg-row-drag-handle",e.setAttribute("aria-label","Drag to reorder"),e.setAttribute("role","button"),e.setAttribute("tabindex","-1"),e.draggable=!0,this.setIcon(e,this.resolveIcon("dragHandle")),e}};return"right"===this.config.dragHandlePosition?[...e,t]:[t,...e]}afterRender(){if(!this.config.showDragHandle)return;const e=this.gridElement;if(!e)return;e.querySelectorAll(".dg-row-drag-handle").forEach(e=>{const t=e;if(t.getAttribute("data-drag-bound"))return;t.setAttribute("data-drag-bound","true");const r=t.closest(".data-grid-row");r&&this.setupHandleDragListeners(t,r)});e.querySelectorAll(".data-grid-row").forEach(e=>{const t=e;t.getAttribute("data-drop-bound")||(t.setAttribute("data-drop-bound","true"),this.setupRowDropListeners(t))})}onKeyDown(e){if(!this.config.enableKeyboard)return;if(!e.ctrlKey||"ArrowUp"!==e.key&&"ArrowDown"!==e.key)return;const t=this.grid,r=t._focusRow,o=t._rows??this.sourceRows;if(r<0||r>=o.length)return;const i="ArrowUp"===e.key?"up":"down",n="up"===i?r-1:r+1;if(n<0||n>=o.length)return;const s=o[r];return!this.config.canMove||this.config.canMove(s,r,n,i)?(this.handleKeyboardMove(s,r,n,i,t._focusCol),e.preventDefault(),e.stopPropagation(),!0):void 0}onCellClick(){this.flushPendingMove()}moveRow(e,t){const r=[...this.sourceRows];if(e<0||e>=r.length)return;if(t<0||t>=r.length)return;if(e===t)return;const o=t<e?"up":"down",i=r[e];this.config.canMove&&!this.config.canMove(i,e,t,o)||this.executeMove(i,e,t,"keyboard")}canMoveRow(e,t){const r=this.sourceRows;if(e<0||e>=r.length)return!1;if(t<0||t>=r.length)return!1;if(e===t)return!1;if(!this.config.canMove)return!0;const o=t<e?"up":"down";return this.config.canMove(r[e],e,t,o)}setupHandleDragListeners(e,t){e.addEventListener("dragstart",e=>{const r=this.getRowIndex(t);r<0||(this.isDragging=!0,this.draggedRowIndex=r,e.dataTransfer&&(e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",String(r))),t.classList.add("dragging"))}),e.addEventListener("dragend",()=>{this.isDragging=!1,this.draggedRowIndex=null,this.dropRowIndex=null,this.clearDragClasses()})}setupRowDropListeners(e){e.addEventListener("dragover",t=>{if(t.preventDefault(),!this.isDragging||null===this.draggedRowIndex)return;const r=this.getRowIndex(e);if(r<0||r===this.draggedRowIndex)return;const o=e.getBoundingClientRect(),i=o.top+o.height/2,n=t.clientY<i;this.dropRowIndex=n?r:r+1,e.classList.add("drop-target"),e.classList.toggle("drop-before",n),e.classList.toggle("drop-after",!n)}),e.addEventListener("dragleave",()=>{e.classList.remove("drop-target","drop-before","drop-after")}),e.addEventListener("drop",e=>{e.preventDefault();const t=this.draggedRowIndex;let r=this.dropRowIndex;if(this.isDragging&&null!==t&&null!==r&&(r>t&&r--,t!==r)){const e=this.sourceRows[t],o=r<t?"up":"down";this.config.canMove&&!this.config.canMove(e,t,r,o)||this.executeMove(e,t,r,"drag")}})}handleKeyboardMove(t,r,o,i,n){this.pendingMove?this.pendingMove.currentIndex=o:this.pendingMove={originalIndex:r,currentIndex:o,row:t},this.lastFocusCol=n;const s=this.grid,a=[...s._rows??this.sourceRows],[l]=a.splice(r,1);a.splice(o,0,l),s._rows=a,s._focusRow=o,s._focusCol=n,s.refreshVirtualWindow(!0),e(s),this.clearDebounceTimer(),this.debounceTimer=setTimeout(()=>{this.flushPendingMove()},this.config.debounceMs??300)}flushPendingMove(){if(this.clearDebounceTimer(),!this.pendingMove)return;const{originalIndex:t,currentIndex:r,row:o}=this.pendingMove;if(this.pendingMove=null,t===r)return;const i={row:o,fromIndex:t,toIndex:r,rows:[...this.sourceRows],source:"keyboard"};if(this.emitCancelable("row-move",i)){const o=[...this.sourceRows],[i]=o.splice(r,1);o.splice(t,0,i);const n=this.grid;n._rows=o,n._focusRow=t,n._focusCol=this.lastFocusCol,n.refreshVirtualWindow(!0),e(n)}}executeMove(e,t,r,o){const i=[...this.sourceRows],[n]=i.splice(t,1);i.splice(r,0,n);const s={row:e,fromIndex:t,toIndex:r,rows:i,source:o};if(!this.emitCancelable("row-move",s))if("flip"===this.animationType&&this.gridElement){const e=this.captureRowPositions();this.grid.rows=i,requestAnimationFrame(()=>{this.gridElement.offsetHeight,this.animateFLIP(e,t,r)})}else this.grid.rows=i}captureRowPositions(){const e=/* @__PURE__ */new Map;return this.gridElement?.querySelectorAll(".data-grid-row").forEach(t=>{const r=this.getRowIndex(t);r>=0&&e.set(r,t.getBoundingClientRect().top)}),e}animateFLIP(e,t,r){const o=this.gridElement;if(!o||0===e.size)return;const i=Math.min(t,r),n=Math.max(t,r),s=[];if(o.querySelectorAll(".data-grid-row").forEach(o=>{const a=o,l=this.getRowIndex(a);if(l<0||l<i||l>n)return;let d;d=l===r?t:t<r?l+1:l-1;const c=e.get(d);if(void 0===c)return;const g=c-a.getBoundingClientRect().top;Math.abs(g)>1&&s.push({el:a,deltaY:g})}),0===s.length)return;s.forEach(({el:e,deltaY:t})=>{e.style.transform=`translateY(${t}px)`}),o.offsetHeight;const a=this.animationDuration;requestAnimationFrame(()=>{s.forEach(({el:e})=>{e.classList.add("flip-animating"),e.style.transform=""}),setTimeout(()=>{s.forEach(({el:e})=>{e.style.transform="",e.classList.remove("flip-animating")})},a+50)})}getRowIndex(e){const t=e.querySelector(".cell[data-row]");return t?parseInt(t.getAttribute("data-row")??"-1",10):-1}clearDragClasses(){this.gridElement?.querySelectorAll(".data-grid-row").forEach(e=>{e.classList.remove("dragging","drop-target","drop-before","drop-after")})}clearDebounceTimer(){this.debounceTimer&&(clearTimeout(this.debounceTimer),this.debounceTimer=null)}}export{i as ROW_DRAG_HANDLE_FIELD,n as RowReorderPlugin};
729
2
  //# sourceMappingURL=index.js.map