@toolbox-web/grid 0.4.0 → 0.4.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 (161) hide show
  1. package/README.md +10 -13
  2. package/all.js +1124 -1047
  3. package/all.js.map +1 -1
  4. package/index.js +688 -515
  5. package/index.js.map +1 -1
  6. package/lib/core/grid.d.ts +10 -0
  7. package/lib/core/grid.d.ts.map +1 -1
  8. package/lib/core/internal/config-manager.d.ts +1 -0
  9. package/lib/core/internal/config-manager.d.ts.map +1 -1
  10. package/lib/core/internal/keyboard.d.ts.map +1 -1
  11. package/lib/core/internal/utils.d.ts +1 -0
  12. package/lib/core/internal/utils.d.ts.map +1 -1
  13. package/lib/core/internal/validate-config.d.ts +14 -0
  14. package/lib/core/internal/validate-config.d.ts.map +1 -1
  15. package/lib/core/plugin/base-plugin.d.ts +105 -1
  16. package/lib/core/plugin/base-plugin.d.ts.map +1 -1
  17. package/lib/core/plugin/expander-column.d.ts +51 -0
  18. package/lib/core/plugin/expander-column.d.ts.map +1 -0
  19. package/lib/core/plugin/index.d.ts +1 -0
  20. package/lib/core/plugin/index.d.ts.map +1 -1
  21. package/lib/core/plugin/plugin-manager.d.ts +1 -1
  22. package/lib/core/plugin/plugin-manager.d.ts.map +1 -1
  23. package/lib/core/plugin/types.d.ts +117 -1
  24. package/lib/core/plugin/types.d.ts.map +1 -1
  25. package/lib/core/types.d.ts +4 -2
  26. package/lib/core/types.d.ts.map +1 -1
  27. package/lib/plugins/clipboard/ClipboardPlugin.d.ts +9 -2
  28. package/lib/plugins/clipboard/ClipboardPlugin.d.ts.map +1 -1
  29. package/lib/plugins/clipboard/index.d.ts +1 -1
  30. package/lib/plugins/clipboard/index.d.ts.map +1 -1
  31. package/lib/plugins/clipboard/index.js +303 -185
  32. package/lib/plugins/clipboard/index.js.map +1 -1
  33. package/lib/plugins/clipboard/types.d.ts +72 -2
  34. package/lib/plugins/clipboard/types.d.ts.map +1 -1
  35. package/lib/plugins/column-virtualization/ColumnVirtualizationPlugin.d.ts +0 -1
  36. package/lib/plugins/column-virtualization/ColumnVirtualizationPlugin.d.ts.map +1 -1
  37. package/lib/plugins/column-virtualization/index.js +116 -24
  38. package/lib/plugins/column-virtualization/index.js.map +1 -1
  39. package/lib/plugins/context-menu/ContextMenuPlugin.d.ts +0 -1
  40. package/lib/plugins/context-menu/ContextMenuPlugin.d.ts.map +1 -1
  41. package/lib/plugins/context-menu/index.js +164 -72
  42. package/lib/plugins/context-menu/index.js.map +1 -1
  43. package/lib/plugins/editing/EditingPlugin.d.ts +1 -7
  44. package/lib/plugins/editing/EditingPlugin.d.ts.map +1 -1
  45. package/lib/plugins/editing/index.js +213 -133
  46. package/lib/plugins/editing/index.js.map +1 -1
  47. package/lib/plugins/export/ExportPlugin.d.ts +0 -1
  48. package/lib/plugins/export/ExportPlugin.d.ts.map +1 -1
  49. package/lib/plugins/export/index.js +195 -103
  50. package/lib/plugins/export/index.js.map +1 -1
  51. package/lib/plugins/filtering/FilteringPlugin.d.ts +5 -2
  52. package/lib/plugins/filtering/FilteringPlugin.d.ts.map +1 -1
  53. package/lib/plugins/filtering/index.js +145 -43
  54. package/lib/plugins/filtering/index.js.map +1 -1
  55. package/lib/plugins/grouping-columns/GroupingColumnsPlugin.d.ts +1 -2
  56. package/lib/plugins/grouping-columns/GroupingColumnsPlugin.d.ts.map +1 -1
  57. package/lib/plugins/grouping-columns/grouping-columns.d.ts +1 -1
  58. package/lib/plugins/grouping-columns/grouping-columns.d.ts.map +1 -1
  59. package/lib/plugins/grouping-columns/index.js +162 -68
  60. package/lib/plugins/grouping-columns/index.js.map +1 -1
  61. package/lib/plugins/grouping-rows/GroupingRowsPlugin.d.ts +14 -2
  62. package/lib/plugins/grouping-rows/GroupingRowsPlugin.d.ts.map +1 -1
  63. package/lib/plugins/grouping-rows/index.js +246 -138
  64. package/lib/plugins/grouping-rows/index.js.map +1 -1
  65. package/lib/plugins/master-detail/MasterDetailPlugin.d.ts +13 -11
  66. package/lib/plugins/master-detail/MasterDetailPlugin.d.ts.map +1 -1
  67. package/lib/plugins/master-detail/index.js +281 -196
  68. package/lib/plugins/master-detail/index.js.map +1 -1
  69. package/lib/plugins/master-detail/types.d.ts +0 -10
  70. package/lib/plugins/master-detail/types.d.ts.map +1 -1
  71. package/lib/plugins/multi-sort/MultiSortPlugin.d.ts +1 -2
  72. package/lib/plugins/multi-sort/MultiSortPlugin.d.ts.map +1 -1
  73. package/lib/plugins/multi-sort/index.js +121 -31
  74. package/lib/plugins/multi-sort/index.js.map +1 -1
  75. package/lib/plugins/pinned-columns/PinnedColumnsPlugin.d.ts +0 -1
  76. package/lib/plugins/pinned-columns/PinnedColumnsPlugin.d.ts.map +1 -1
  77. package/lib/plugins/pinned-columns/index.js +144 -52
  78. package/lib/plugins/pinned-columns/index.js.map +1 -1
  79. package/lib/plugins/pinned-rows/PinnedRowsPlugin.d.ts +1 -2
  80. package/lib/plugins/pinned-rows/PinnedRowsPlugin.d.ts.map +1 -1
  81. package/lib/plugins/pinned-rows/index.js +178 -88
  82. package/lib/plugins/pinned-rows/index.js.map +1 -1
  83. package/lib/plugins/pivot/PivotPlugin.d.ts +26 -4
  84. package/lib/plugins/pivot/PivotPlugin.d.ts.map +1 -1
  85. package/lib/plugins/pivot/index.js +414 -310
  86. package/lib/plugins/pivot/index.js.map +1 -1
  87. package/lib/plugins/pivot/pivot-rows.d.ts +2 -1
  88. package/lib/plugins/pivot/pivot-rows.d.ts.map +1 -1
  89. package/lib/plugins/reorder/ReorderPlugin.d.ts +13 -10
  90. package/lib/plugins/reorder/ReorderPlugin.d.ts.map +1 -1
  91. package/lib/plugins/reorder/index.js +304 -226
  92. package/lib/plugins/reorder/index.js.map +1 -1
  93. package/lib/plugins/selection/SelectionPlugin.d.ts +21 -3
  94. package/lib/plugins/selection/SelectionPlugin.d.ts.map +1 -1
  95. package/lib/plugins/selection/index.d.ts +2 -2
  96. package/lib/plugins/selection/index.d.ts.map +1 -1
  97. package/lib/plugins/selection/index.js +292 -145
  98. package/lib/plugins/selection/index.js.map +1 -1
  99. package/lib/plugins/selection/types.d.ts +24 -0
  100. package/lib/plugins/selection/types.d.ts.map +1 -1
  101. package/lib/plugins/server-side/ServerSidePlugin.d.ts +0 -1
  102. package/lib/plugins/server-side/ServerSidePlugin.d.ts.map +1 -1
  103. package/lib/plugins/server-side/index.js +95 -3
  104. package/lib/plugins/server-side/index.js.map +1 -1
  105. package/lib/plugins/tree/TreePlugin.d.ts +5 -1
  106. package/lib/plugins/tree/TreePlugin.d.ts.map +1 -1
  107. package/lib/plugins/tree/index.js +213 -112
  108. package/lib/plugins/tree/index.js.map +1 -1
  109. package/lib/plugins/tree/types.d.ts +0 -10
  110. package/lib/plugins/tree/types.d.ts.map +1 -1
  111. package/lib/plugins/undo-redo/UndoRedoPlugin.d.ts +7 -2
  112. package/lib/plugins/undo-redo/UndoRedoPlugin.d.ts.map +1 -1
  113. package/lib/plugins/undo-redo/index.js +112 -12
  114. package/lib/plugins/undo-redo/index.js.map +1 -1
  115. package/lib/plugins/visibility/VisibilityPlugin.d.ts +14 -5
  116. package/lib/plugins/visibility/VisibilityPlugin.d.ts.map +1 -1
  117. package/lib/plugins/visibility/index.js +168 -65
  118. package/lib/plugins/visibility/index.js.map +1 -1
  119. package/package.json +1 -1
  120. package/umd/grid.all.umd.js +21 -17
  121. package/umd/grid.all.umd.js.map +1 -1
  122. package/umd/grid.umd.js +14 -8
  123. package/umd/grid.umd.js.map +1 -1
  124. package/umd/plugins/clipboard.umd.js +5 -7
  125. package/umd/plugins/clipboard.umd.js.map +1 -1
  126. package/umd/plugins/column-virtualization.umd.js +1 -1
  127. package/umd/plugins/column-virtualization.umd.js.map +1 -1
  128. package/umd/plugins/context-menu.umd.js +1 -1
  129. package/umd/plugins/context-menu.umd.js.map +1 -1
  130. package/umd/plugins/editing.umd.js +1 -1
  131. package/umd/plugins/editing.umd.js.map +1 -1
  132. package/umd/plugins/export.umd.js +1 -1
  133. package/umd/plugins/export.umd.js.map +1 -1
  134. package/umd/plugins/filtering.umd.js +1 -1
  135. package/umd/plugins/filtering.umd.js.map +1 -1
  136. package/umd/plugins/grouping-columns.umd.js +1 -1
  137. package/umd/plugins/grouping-columns.umd.js.map +1 -1
  138. package/umd/plugins/grouping-rows.umd.js +1 -1
  139. package/umd/plugins/grouping-rows.umd.js.map +1 -1
  140. package/umd/plugins/master-detail.umd.js +1 -1
  141. package/umd/plugins/master-detail.umd.js.map +1 -1
  142. package/umd/plugins/multi-sort.umd.js +1 -1
  143. package/umd/plugins/multi-sort.umd.js.map +1 -1
  144. package/umd/plugins/pinned-columns.umd.js +1 -1
  145. package/umd/plugins/pinned-columns.umd.js.map +1 -1
  146. package/umd/plugins/pinned-rows.umd.js +1 -1
  147. package/umd/plugins/pinned-rows.umd.js.map +1 -1
  148. package/umd/plugins/pivot.umd.js +1 -1
  149. package/umd/plugins/pivot.umd.js.map +1 -1
  150. package/umd/plugins/reorder.umd.js +1 -1
  151. package/umd/plugins/reorder.umd.js.map +1 -1
  152. package/umd/plugins/selection.umd.js +1 -1
  153. package/umd/plugins/selection.umd.js.map +1 -1
  154. package/umd/plugins/server-side.umd.js +1 -1
  155. package/umd/plugins/server-side.umd.js.map +1 -1
  156. package/umd/plugins/tree.umd.js +1 -1
  157. package/umd/plugins/tree.umd.js.map +1 -1
  158. package/umd/plugins/undo-redo.umd.js +1 -1
  159. package/umd/plugins/undo-redo.umd.js.map +1 -1
  160. package/umd/plugins/visibility.umd.js +1 -1
  161. package/umd/plugins/visibility.umd.js.map +1 -1
@@ -9,8 +9,27 @@ const C = {
9
9
  toolPanel: "☰"
10
10
  };
11
11
  class I {
12
- /** Plugin version - override in subclass if needed */
13
- version = "1.0.0";
12
+ /**
13
+ * Plugin dependencies - declare other plugins this one requires.
14
+ *
15
+ * Dependencies are validated when the plugin is attached.
16
+ * Required dependencies throw an error if missing.
17
+ * Optional dependencies log an info message if missing.
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * static readonly dependencies: PluginDependency[] = [
22
+ * { name: 'editing', required: true, reason: 'Tracks cell edits for undo/redo' },
23
+ * { name: 'selection', required: false, reason: 'Enables selection-based undo' },
24
+ * ];
25
+ * ```
26
+ */
27
+ static dependencies;
28
+ /**
29
+ * Plugin version - defaults to grid version for built-in plugins.
30
+ * Third-party plugins can override with their own semver.
31
+ */
32
+ version = typeof __GRID_VERSION__ < "u" ? __GRID_VERSION__ : "dev";
14
33
  /** CSS styles to inject into the grid's shadow DOM */
15
34
  styles;
16
35
  /** Custom cell renderers keyed by type name */
@@ -94,8 +113,16 @@ class I {
94
113
  /**
95
114
  * Emit a custom event from the grid.
96
115
  */
97
- emit(e, n) {
98
- this.grid?.dispatchEvent?.(new CustomEvent(e, { detail: n, bubbles: !0 }));
116
+ emit(e, t) {
117
+ this.grid?.dispatchEvent?.(new CustomEvent(e, { detail: t, bubbles: !0 }));
118
+ }
119
+ /**
120
+ * Emit a cancelable custom event from the grid.
121
+ * @returns `true` if the event was cancelled (preventDefault called), `false` otherwise
122
+ */
123
+ emitCancelable(e, t) {
124
+ const n = new CustomEvent(e, { detail: t, bubbles: !0, cancelable: !0 });
125
+ return this.grid?.dispatchEvent?.(n), n.defaultPrevented;
99
126
  }
100
127
  /**
101
128
  * Request a re-render of the grid.
@@ -103,6 +130,14 @@ class I {
103
130
  requestRender() {
104
131
  this.grid?.requestRender?.();
105
132
  }
133
+ /**
134
+ * Request a re-render and restore focus styling afterward.
135
+ * Use this when a plugin action (like expand/collapse) triggers a render
136
+ * but needs to maintain keyboard navigation focus.
137
+ */
138
+ requestRenderWithFocus() {
139
+ this.grid?.requestRenderWithFocus?.();
140
+ }
106
141
  /**
107
142
  * Request a lightweight style update without rebuilding DOM.
108
143
  * Use this instead of requestRender() when only CSS classes need updating.
@@ -136,6 +171,19 @@ class I {
136
171
  get visibleColumns() {
137
172
  return this.grid?._visibleColumns ?? [];
138
173
  }
174
+ /**
175
+ * Get the grid as an HTMLElement for direct DOM operations.
176
+ * Use sparingly - prefer the typed GridElementRef API when possible.
177
+ *
178
+ * @example
179
+ * ```ts
180
+ * const width = this.gridElement.clientWidth;
181
+ * this.gridElement.classList.add('my-plugin-active');
182
+ * ```
183
+ */
184
+ get gridElement() {
185
+ return this.grid;
186
+ }
139
187
  /**
140
188
  * Get the shadow root of the grid.
141
189
  */
@@ -170,6 +218,51 @@ class I {
170
218
  const e = this.grid?.gridConfig?.icons ?? {};
171
219
  return { ...C, ...e };
172
220
  }
221
+ // #region Animation Helpers
222
+ /**
223
+ * Check if animations are enabled at the grid level.
224
+ * Respects gridConfig.animation.mode and the CSS variable set by the grid.
225
+ *
226
+ * Plugins should use this to skip animations when:
227
+ * - Animation mode is 'off' or `false`
228
+ * - User prefers reduced motion and mode is 'reduced-motion' (default)
229
+ *
230
+ * @example
231
+ * ```ts
232
+ * private get animationStyle(): 'slide' | 'fade' | false {
233
+ * if (!this.isAnimationEnabled) return false;
234
+ * return this.config.animation ?? 'slide';
235
+ * }
236
+ * ```
237
+ */
238
+ get isAnimationEnabled() {
239
+ const e = this.grid?.effectiveConfig?.animation?.mode ?? "reduced-motion";
240
+ if (e === !1 || e === "off") return !1;
241
+ if (e === !0 || e === "on") return !0;
242
+ const t = this.shadowRoot?.host;
243
+ return t ? getComputedStyle(t).getPropertyValue("--tbw-animation-enabled").trim() !== "0" : !0;
244
+ }
245
+ /**
246
+ * Get the animation duration in milliseconds from CSS variable.
247
+ * Falls back to 200ms if not set.
248
+ *
249
+ * Plugins can use this for their animation timing to stay consistent
250
+ * with the grid-level animation.duration setting.
251
+ *
252
+ * @example
253
+ * ```ts
254
+ * element.animate(keyframes, { duration: this.animationDuration });
255
+ * ```
256
+ */
257
+ get animationDuration() {
258
+ const e = this.shadowRoot?.host;
259
+ if (e) {
260
+ const t = getComputedStyle(e).getPropertyValue("--tbw-animation-duration").trim(), n = parseInt(t, 10);
261
+ if (!isNaN(n)) return n;
262
+ }
263
+ return 200;
264
+ }
265
+ // #endregion
173
266
  /**
174
267
  * Resolve an icon value to string or HTMLElement.
175
268
  * Checks plugin config first, then grid-level icons, then defaults.
@@ -178,8 +271,8 @@ class I {
178
271
  * @param pluginOverride - Optional plugin-level override
179
272
  * @returns The resolved icon value
180
273
  */
181
- resolveIcon(e, n) {
182
- return n !== void 0 ? n : this.gridIcons[e];
274
+ resolveIcon(e, t) {
275
+ return t !== void 0 ? t : this.gridIcons[e];
183
276
  }
184
277
  /**
185
278
  * Set an icon value on an element.
@@ -188,8 +281,8 @@ class I {
188
281
  * @param element - The element to set the icon on
189
282
  * @param icon - The icon value (string or HTMLElement)
190
283
  */
191
- setIcon(e, n) {
192
- typeof n == "string" ? e.innerHTML = n : n instanceof HTMLElement && (e.innerHTML = "", e.appendChild(n.cloneNode(!0)));
284
+ setIcon(e, t) {
285
+ typeof t == "string" ? e.innerHTML = t : t instanceof HTMLElement && (e.innerHTML = "", e.appendChild(t.cloneNode(!0)));
193
286
  }
194
287
  /**
195
288
  * Log a warning message.
@@ -201,54 +294,54 @@ class I {
201
294
  }
202
295
  const g = ".tbw-context-menu{position:fixed;background:light-dark(#f5f5f5,#2a2a2a);color:light-dark(#222,#eee);border:1px solid light-dark(#d0d0d4,#454545);border-radius:4px;box-shadow:0 2px 10px #00000026;min-width:160px;padding:4px 0;z-index:10000;font-size:13px;font-family:system-ui,sans-serif}.tbw-context-menu-item{display:flex;align-items:center;padding:6px 12px;cursor:pointer;gap:8px}.tbw-context-menu-item:hover:not(.disabled){background:light-dark(#e8e8e8,#3a3a3a)}.tbw-context-menu-item.disabled{opacity:.5;cursor:default}.tbw-context-menu-item.danger{color:light-dark(#c00,#f66)}.tbw-context-menu-icon{width:16px;text-align:center}.tbw-context-menu-label{flex:1}.tbw-context-menu-shortcut{color:light-dark(#888,#888);font-size:11px}.tbw-context-menu-arrow{font-size:10px;color:light-dark(#888,#888)}.tbw-context-menu-separator{height:1px;background:light-dark(#d0d0d4,#454545);margin:4px 0}";
203
296
  function w(s, e) {
204
- return (typeof s == "function" ? s(e) : s).filter((i) => !(i.hidden === !0 || typeof i.hidden == "function" && i.hidden(e)));
297
+ return (typeof s == "function" ? s(e) : s).filter((n) => !(n.hidden === !0 || typeof n.hidden == "function" && n.hidden(e)));
205
298
  }
206
299
  function M(s, e) {
207
300
  return s.disabled === !0 ? !0 : typeof s.disabled == "function" ? s.disabled(e) : !1;
208
301
  }
209
- function v(s, e, n, i = C.submenuArrow) {
210
- const r = document.createElement("div");
211
- r.className = "tbw-context-menu", r.setAttribute("role", "menu");
302
+ function v(s, e, t, n = C.submenuArrow) {
303
+ const l = document.createElement("div");
304
+ l.className = "tbw-context-menu", l.setAttribute("role", "menu");
212
305
  for (const o of s) {
213
306
  if (o.separator) {
214
- const l = document.createElement("div");
215
- l.className = "tbw-context-menu-separator", l.setAttribute("role", "separator"), r.appendChild(l);
307
+ const r = document.createElement("div");
308
+ r.className = "tbw-context-menu-separator", r.setAttribute("role", "separator"), l.appendChild(r);
216
309
  continue;
217
310
  }
218
- const t = document.createElement("div");
219
- t.className = "tbw-context-menu-item", o.cssClass && t.classList.add(o.cssClass), t.setAttribute("role", "menuitem"), t.setAttribute("data-id", o.id);
311
+ const i = document.createElement("div");
312
+ i.className = "tbw-context-menu-item", o.cssClass && i.classList.add(o.cssClass), i.setAttribute("role", "menuitem"), i.setAttribute("data-id", o.id);
220
313
  const a = M(o, e);
221
- if (a && (t.classList.add("disabled"), t.setAttribute("aria-disabled", "true")), o.icon) {
222
- const l = document.createElement("span");
223
- l.className = "tbw-context-menu-icon", l.innerHTML = o.icon, t.appendChild(l);
314
+ if (a && (i.classList.add("disabled"), i.setAttribute("aria-disabled", "true")), o.icon) {
315
+ const r = document.createElement("span");
316
+ r.className = "tbw-context-menu-icon", r.innerHTML = o.icon, i.appendChild(r);
224
317
  }
225
318
  const d = document.createElement("span");
226
- if (d.className = "tbw-context-menu-label", d.textContent = o.name, t.appendChild(d), o.shortcut) {
227
- const l = document.createElement("span");
228
- l.className = "tbw-context-menu-shortcut", l.textContent = o.shortcut, t.appendChild(l);
319
+ if (d.className = "tbw-context-menu-label", d.textContent = o.name, i.appendChild(d), o.shortcut) {
320
+ const r = document.createElement("span");
321
+ r.className = "tbw-context-menu-shortcut", r.textContent = o.shortcut, i.appendChild(r);
229
322
  }
230
323
  if (o.subMenu?.length) {
231
- const l = document.createElement("span");
232
- l.className = "tbw-context-menu-arrow", typeof i == "string" ? l.innerHTML = i : i instanceof HTMLElement && l.appendChild(i.cloneNode(!0)), t.appendChild(l), t.addEventListener("mouseenter", () => {
233
- if (t.querySelector(".tbw-context-menu") || !o.subMenu) return;
234
- const h = w(o.subMenu, e), c = v(h, e, n, i);
235
- c.classList.add("tbw-context-submenu"), c.style.position = "absolute", c.style.left = "100%", c.style.top = "0", t.style.position = "relative", t.appendChild(c);
236
- }), t.addEventListener("mouseleave", () => {
237
- const u = t.querySelector(".tbw-context-menu");
324
+ const r = document.createElement("span");
325
+ r.className = "tbw-context-menu-arrow", typeof n == "string" ? r.innerHTML = n : n instanceof HTMLElement && r.appendChild(n.cloneNode(!0)), i.appendChild(r), i.addEventListener("mouseenter", () => {
326
+ if (i.querySelector(".tbw-context-menu") || !o.subMenu) return;
327
+ const h = w(o.subMenu, e), c = v(h, e, t, n);
328
+ c.classList.add("tbw-context-submenu"), c.style.position = "absolute", c.style.left = "100%", c.style.top = "0", i.style.position = "relative", i.appendChild(c);
329
+ }), i.addEventListener("mouseleave", () => {
330
+ const u = i.querySelector(".tbw-context-menu");
238
331
  u && u.remove();
239
332
  });
240
333
  }
241
- !a && o.action && !o.subMenu && t.addEventListener("click", (l) => {
242
- l.stopPropagation(), n(o);
243
- }), r.appendChild(t);
334
+ !a && o.action && !o.subMenu && i.addEventListener("click", (r) => {
335
+ r.stopPropagation(), t(o);
336
+ }), l.appendChild(i);
244
337
  }
245
- return r;
338
+ return l;
246
339
  }
247
- function y(s, e, n) {
248
- s.style.position = "fixed", s.style.left = `${e}px`, s.style.top = `${n}px`, s.style.visibility = "hidden", s.style.zIndex = "10000";
249
- const i = s.getBoundingClientRect(), r = window.innerWidth, o = window.innerHeight;
250
- let t = e, a = n;
251
- e + i.width > r && (t = e - i.width), n + i.height > o && (a = n - i.height), t = Math.max(0, t), a = Math.max(0, a), s.style.left = `${t}px`, s.style.top = `${a}px`, s.style.visibility = "visible";
340
+ function y(s, e, t) {
341
+ s.style.position = "fixed", s.style.left = `${e}px`, s.style.top = `${t}px`, s.style.visibility = "hidden", s.style.zIndex = "10000";
342
+ const n = s.getBoundingClientRect(), l = window.innerWidth, o = window.innerHeight;
343
+ let i = e, a = t;
344
+ e + n.width > l && (i = e - n.width), t + n.height > o && (a = t - n.height), i = Math.max(0, i), a = Math.max(0, a), s.style.left = `${i}px`, s.style.top = `${a}px`, s.style.visibility = "visible";
252
345
  }
253
346
  let f = null, p = null, m = null, b = 0;
254
347
  const x = [
@@ -269,9 +362,8 @@ const x = [
269
362
  }
270
363
  }
271
364
  ];
272
- class H extends I {
365
+ class R extends I {
273
366
  name = "contextMenu";
274
- version = "1.0.0";
275
367
  get defaultConfig() {
276
368
  return {
277
369
  items: x
@@ -294,9 +386,9 @@ class H extends I {
294
386
  // #region Private Methods
295
387
  installGlobalHandlers() {
296
388
  !m && typeof document < "u" && typeof g == "string" && g && (m = document.createElement("style"), m.id = "tbw-context-menu-styles", m.textContent = g, document.head.appendChild(m)), f || (f = () => {
297
- document.querySelectorAll(".tbw-context-menu").forEach((n) => n.remove());
389
+ document.querySelectorAll(".tbw-context-menu").forEach((t) => t.remove());
298
390
  }, document.addEventListener("click", f)), p || (p = (e) => {
299
- e.key === "Escape" && document.querySelectorAll(".tbw-context-menu").forEach((i) => i.remove());
391
+ e.key === "Escape" && document.querySelectorAll(".tbw-context-menu").forEach((n) => n.remove());
300
392
  }, document.addEventListener("keydown", p));
301
393
  }
302
394
  /**
@@ -311,14 +403,14 @@ class H extends I {
311
403
  afterRender() {
312
404
  const e = this.shadowRoot;
313
405
  if (!e) return;
314
- const n = e.children[0];
315
- n && n.getAttribute("data-context-menu-bound") !== "true" && (n.setAttribute("data-context-menu-bound", "true"), n.addEventListener("contextmenu", (i) => {
316
- const r = i;
317
- r.preventDefault();
318
- const o = r.target, t = o.closest("[data-row][data-col]"), a = o.closest(".header-cell");
406
+ const t = e.children[0];
407
+ t && t.getAttribute("data-context-menu-bound") !== "true" && (t.setAttribute("data-context-menu-bound", "true"), t.addEventListener("contextmenu", (n) => {
408
+ const l = n;
409
+ l.preventDefault();
410
+ const o = l.target, i = o.closest("[data-row][data-col]"), a = o.closest(".header-cell");
319
411
  let d;
320
- if (t) {
321
- const u = parseInt(t.getAttribute("data-row") ?? "-1", 10), h = parseInt(t.getAttribute("data-col") ?? "-1", 10), c = this.columns[h], E = this.rows[u];
412
+ if (i) {
413
+ const u = parseInt(i.getAttribute("data-row") ?? "-1", 10), h = parseInt(i.getAttribute("data-col") ?? "-1", 10), c = this.columns[h], E = this.rows[u];
322
414
  d = {
323
415
  row: E,
324
416
  rowIndex: u,
@@ -327,7 +419,7 @@ class H extends I {
327
419
  field: c?.field ?? "",
328
420
  value: E?.[c?.field] ?? null,
329
421
  isHeader: !1,
330
- event: r
422
+ event: l
331
423
  };
332
424
  } else if (a) {
333
425
  const u = parseInt(a.getAttribute("data-col") ?? "-1", 10), h = this.columns[u];
@@ -339,20 +431,20 @@ class H extends I {
339
431
  field: h?.field ?? "",
340
432
  value: null,
341
433
  isHeader: !0,
342
- event: r
434
+ event: l
343
435
  };
344
436
  } else
345
437
  return;
346
- this.params = d, this.position = { x: r.clientX, y: r.clientY };
347
- const l = w(this.config.items ?? x, d);
348
- l.length && (this.menuElement && this.menuElement.remove(), this.menuElement = v(
349
- l,
438
+ this.params = d, this.position = { x: l.clientX, y: l.clientY };
439
+ const r = w(this.config.items ?? x, d);
440
+ r.length && (this.menuElement && this.menuElement.remove(), this.menuElement = v(
441
+ r,
350
442
  d,
351
443
  (u) => {
352
444
  u.action && u.action(d), this.menuElement?.remove(), this.menuElement = null, this.isOpen = !1;
353
445
  },
354
446
  this.gridIcons.submenuArrow
355
- ), document.body.appendChild(this.menuElement), y(this.menuElement, r.clientX, r.clientY), this.isOpen = !0, this.emit("context-menu-open", { params: d, items: l }));
447
+ ), document.body.appendChild(this.menuElement), y(this.menuElement, l.clientX, l.clientY), this.isOpen = !0, this.emit("context-menu-open", { params: d, items: r }));
356
448
  }));
357
449
  }
358
450
  // #endregion
@@ -363,25 +455,25 @@ class H extends I {
363
455
  * @param y - Y coordinate
364
456
  * @param params - Partial context menu parameters
365
457
  */
366
- showMenu(e, n, i) {
367
- const r = {
368
- row: i.row ?? null,
369
- rowIndex: i.rowIndex ?? -1,
370
- column: i.column ?? null,
371
- columnIndex: i.columnIndex ?? -1,
372
- field: i.field ?? "",
373
- value: i.value ?? null,
374
- isHeader: i.isHeader ?? !1,
375
- event: i.event ?? new MouseEvent("contextmenu")
376
- }, o = w(this.config.items ?? x, r);
458
+ showMenu(e, t, n) {
459
+ const l = {
460
+ row: n.row ?? null,
461
+ rowIndex: n.rowIndex ?? -1,
462
+ column: n.column ?? null,
463
+ columnIndex: n.columnIndex ?? -1,
464
+ field: n.field ?? "",
465
+ value: n.value ?? null,
466
+ isHeader: n.isHeader ?? !1,
467
+ event: n.event ?? new MouseEvent("contextmenu")
468
+ }, o = w(this.config.items ?? x, l);
377
469
  this.menuElement && this.menuElement.remove(), this.menuElement = v(
378
470
  o,
379
- r,
380
- (t) => {
381
- t.action && t.action(r), this.menuElement?.remove(), this.menuElement = null, this.isOpen = !1;
471
+ l,
472
+ (i) => {
473
+ i.action && i.action(l), this.menuElement?.remove(), this.menuElement = null, this.isOpen = !1;
382
474
  },
383
475
  this.gridIcons.submenuArrow
384
- ), document.body.appendChild(this.menuElement), y(this.menuElement, e, n), this.isOpen = !0;
476
+ ), document.body.appendChild(this.menuElement), y(this.menuElement, e, t), this.isOpen = !0;
385
477
  }
386
478
  /**
387
479
  * Hide the context menu.
@@ -400,6 +492,6 @@ class H extends I {
400
492
  // Styles are injected globally via installGlobalHandlers() since menu renders in document.body
401
493
  }
402
494
  export {
403
- H as ContextMenuPlugin
495
+ R as ContextMenuPlugin
404
496
  };
405
497
  //# sourceMappingURL=index.js.map