@toolbox-web/grid 0.4.1 → 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.
- package/README.md +10 -13
- package/all.js +1101 -1048
- package/all.js.map +1 -1
- package/index.js +245 -137
- package/index.js.map +1 -1
- package/lib/core/grid.d.ts +10 -0
- package/lib/core/grid.d.ts.map +1 -1
- package/lib/core/internal/config-manager.d.ts +1 -0
- package/lib/core/internal/config-manager.d.ts.map +1 -1
- package/lib/core/internal/keyboard.d.ts.map +1 -1
- package/lib/core/internal/utils.d.ts +1 -0
- package/lib/core/internal/utils.d.ts.map +1 -1
- package/lib/core/plugin/base-plugin.d.ts +57 -1
- package/lib/core/plugin/base-plugin.d.ts.map +1 -1
- package/lib/core/plugin/expander-column.d.ts +51 -0
- package/lib/core/plugin/expander-column.d.ts.map +1 -0
- package/lib/core/plugin/types.d.ts +117 -1
- package/lib/core/plugin/types.d.ts.map +1 -1
- package/lib/core/types.d.ts +4 -2
- package/lib/core/types.d.ts.map +1 -1
- package/lib/plugins/clipboard/ClipboardPlugin.d.ts +5 -4
- package/lib/plugins/clipboard/ClipboardPlugin.d.ts.map +1 -1
- package/lib/plugins/clipboard/index.d.ts +1 -1
- package/lib/plugins/clipboard/index.d.ts.map +1 -1
- package/lib/plugins/clipboard/index.js +282 -188
- package/lib/plugins/clipboard/index.js.map +1 -1
- package/lib/plugins/clipboard/types.d.ts +72 -2
- package/lib/plugins/clipboard/types.d.ts.map +1 -1
- package/lib/plugins/column-virtualization/ColumnVirtualizationPlugin.d.ts +0 -1
- package/lib/plugins/column-virtualization/ColumnVirtualizationPlugin.d.ts.map +1 -1
- package/lib/plugins/column-virtualization/index.js +102 -26
- package/lib/plugins/column-virtualization/index.js.map +1 -1
- package/lib/plugins/context-menu/ContextMenuPlugin.d.ts +0 -1
- package/lib/plugins/context-menu/ContextMenuPlugin.d.ts.map +1 -1
- package/lib/plugins/context-menu/index.js +154 -78
- package/lib/plugins/context-menu/index.js.map +1 -1
- package/lib/plugins/editing/EditingPlugin.d.ts +1 -7
- package/lib/plugins/editing/EditingPlugin.d.ts.map +1 -1
- package/lib/plugins/editing/index.js +200 -136
- package/lib/plugins/editing/index.js.map +1 -1
- package/lib/plugins/export/ExportPlugin.d.ts +0 -1
- package/lib/plugins/export/ExportPlugin.d.ts.map +1 -1
- package/lib/plugins/export/index.js +175 -99
- package/lib/plugins/export/index.js.map +1 -1
- package/lib/plugins/filtering/FilteringPlugin.d.ts +5 -2
- package/lib/plugins/filtering/FilteringPlugin.d.ts.map +1 -1
- package/lib/plugins/filtering/index.js +129 -43
- package/lib/plugins/filtering/index.js.map +1 -1
- package/lib/plugins/grouping-columns/GroupingColumnsPlugin.d.ts +1 -2
- package/lib/plugins/grouping-columns/GroupingColumnsPlugin.d.ts.map +1 -1
- package/lib/plugins/grouping-columns/grouping-columns.d.ts +1 -1
- package/lib/plugins/grouping-columns/grouping-columns.d.ts.map +1 -1
- package/lib/plugins/grouping-columns/index.js +144 -66
- package/lib/plugins/grouping-columns/index.js.map +1 -1
- package/lib/plugins/grouping-rows/GroupingRowsPlugin.d.ts +14 -2
- package/lib/plugins/grouping-rows/GroupingRowsPlugin.d.ts.map +1 -1
- package/lib/plugins/grouping-rows/index.js +230 -138
- package/lib/plugins/grouping-rows/index.js.map +1 -1
- package/lib/plugins/master-detail/MasterDetailPlugin.d.ts +13 -11
- package/lib/plugins/master-detail/MasterDetailPlugin.d.ts.map +1 -1
- package/lib/plugins/master-detail/index.js +265 -196
- package/lib/plugins/master-detail/index.js.map +1 -1
- package/lib/plugins/master-detail/types.d.ts +0 -10
- package/lib/plugins/master-detail/types.d.ts.map +1 -1
- package/lib/plugins/multi-sort/MultiSortPlugin.d.ts +1 -2
- package/lib/plugins/multi-sort/MultiSortPlugin.d.ts.map +1 -1
- package/lib/plugins/multi-sort/index.js +105 -31
- package/lib/plugins/multi-sort/index.js.map +1 -1
- package/lib/plugins/pinned-columns/PinnedColumnsPlugin.d.ts +0 -1
- package/lib/plugins/pinned-columns/PinnedColumnsPlugin.d.ts.map +1 -1
- package/lib/plugins/pinned-columns/index.js +128 -52
- package/lib/plugins/pinned-columns/index.js.map +1 -1
- package/lib/plugins/pinned-rows/PinnedRowsPlugin.d.ts +1 -2
- package/lib/plugins/pinned-rows/PinnedRowsPlugin.d.ts.map +1 -1
- package/lib/plugins/pinned-rows/index.js +162 -88
- package/lib/plugins/pinned-rows/index.js.map +1 -1
- package/lib/plugins/pivot/PivotPlugin.d.ts +26 -4
- package/lib/plugins/pivot/PivotPlugin.d.ts.map +1 -1
- package/lib/plugins/pivot/index.js +398 -310
- package/lib/plugins/pivot/index.js.map +1 -1
- package/lib/plugins/pivot/pivot-rows.d.ts +2 -1
- package/lib/plugins/pivot/pivot-rows.d.ts.map +1 -1
- package/lib/plugins/reorder/ReorderPlugin.d.ts +13 -10
- package/lib/plugins/reorder/ReorderPlugin.d.ts.map +1 -1
- package/lib/plugins/reorder/index.js +288 -226
- package/lib/plugins/reorder/index.js.map +1 -1
- package/lib/plugins/selection/SelectionPlugin.d.ts +21 -3
- package/lib/plugins/selection/SelectionPlugin.d.ts.map +1 -1
- package/lib/plugins/selection/index.d.ts +2 -2
- package/lib/plugins/selection/index.d.ts.map +1 -1
- package/lib/plugins/selection/index.js +276 -145
- package/lib/plugins/selection/index.js.map +1 -1
- package/lib/plugins/selection/types.d.ts +24 -0
- package/lib/plugins/selection/types.d.ts.map +1 -1
- package/lib/plugins/server-side/ServerSidePlugin.d.ts +0 -1
- package/lib/plugins/server-side/ServerSidePlugin.d.ts.map +1 -1
- package/lib/plugins/server-side/index.js +83 -7
- package/lib/plugins/server-side/index.js.map +1 -1
- package/lib/plugins/tree/TreePlugin.d.ts +5 -1
- package/lib/plugins/tree/TreePlugin.d.ts.map +1 -1
- package/lib/plugins/tree/index.js +197 -112
- package/lib/plugins/tree/index.js.map +1 -1
- package/lib/plugins/tree/types.d.ts +0 -10
- package/lib/plugins/tree/types.d.ts.map +1 -1
- package/lib/plugins/undo-redo/UndoRedoPlugin.d.ts +0 -1
- package/lib/plugins/undo-redo/UndoRedoPlugin.d.ts.map +1 -1
- package/lib/plugins/undo-redo/index.js +93 -17
- package/lib/plugins/undo-redo/index.js.map +1 -1
- package/lib/plugins/visibility/VisibilityPlugin.d.ts +7 -4
- package/lib/plugins/visibility/VisibilityPlugin.d.ts.map +1 -1
- package/lib/plugins/visibility/index.js +144 -65
- package/lib/plugins/visibility/index.js.map +1 -1
- package/package.json +1 -1
- package/umd/grid.all.umd.js +17 -19
- package/umd/grid.all.umd.js.map +1 -1
- package/umd/grid.umd.js +7 -7
- package/umd/grid.umd.js.map +1 -1
- package/umd/plugins/clipboard.umd.js +5 -7
- package/umd/plugins/clipboard.umd.js.map +1 -1
- package/umd/plugins/column-virtualization.umd.js +1 -1
- package/umd/plugins/column-virtualization.umd.js.map +1 -1
- package/umd/plugins/context-menu.umd.js +1 -1
- package/umd/plugins/context-menu.umd.js.map +1 -1
- package/umd/plugins/editing.umd.js +1 -1
- package/umd/plugins/editing.umd.js.map +1 -1
- package/umd/plugins/export.umd.js +1 -1
- package/umd/plugins/export.umd.js.map +1 -1
- package/umd/plugins/filtering.umd.js +1 -1
- package/umd/plugins/filtering.umd.js.map +1 -1
- package/umd/plugins/grouping-columns.umd.js +1 -1
- package/umd/plugins/grouping-columns.umd.js.map +1 -1
- package/umd/plugins/grouping-rows.umd.js +1 -1
- package/umd/plugins/grouping-rows.umd.js.map +1 -1
- package/umd/plugins/master-detail.umd.js +1 -1
- package/umd/plugins/master-detail.umd.js.map +1 -1
- package/umd/plugins/multi-sort.umd.js +1 -1
- package/umd/plugins/multi-sort.umd.js.map +1 -1
- package/umd/plugins/pinned-columns.umd.js +1 -1
- package/umd/plugins/pinned-columns.umd.js.map +1 -1
- package/umd/plugins/pinned-rows.umd.js +1 -1
- package/umd/plugins/pinned-rows.umd.js.map +1 -1
- package/umd/plugins/pivot.umd.js +1 -1
- package/umd/plugins/pivot.umd.js.map +1 -1
- package/umd/plugins/reorder.umd.js +1 -1
- package/umd/plugins/reorder.umd.js.map +1 -1
- package/umd/plugins/selection.umd.js +1 -1
- package/umd/plugins/selection.umd.js.map +1 -1
- package/umd/plugins/server-side.umd.js +1 -1
- package/umd/plugins/server-side.umd.js.map +1 -1
- package/umd/plugins/tree.umd.js +1 -1
- package/umd/plugins/tree.umd.js.map +1 -1
- package/umd/plugins/undo-redo.umd.js +1 -1
- package/umd/plugins/undo-redo.umd.js.map +1 -1
- package/umd/plugins/visibility.umd.js +1 -1
- package/umd/plugins/visibility.umd.js.map +1 -1
- package/lib/core/internal/editing.d.ts +0 -76
- package/lib/core/internal/editing.d.ts.map +0 -1
|
@@ -25,8 +25,11 @@ class I {
|
|
|
25
25
|
* ```
|
|
26
26
|
*/
|
|
27
27
|
static dependencies;
|
|
28
|
-
/**
|
|
29
|
-
|
|
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";
|
|
30
33
|
/** CSS styles to inject into the grid's shadow DOM */
|
|
31
34
|
styles;
|
|
32
35
|
/** Custom cell renderers keyed by type name */
|
|
@@ -110,8 +113,16 @@ class I {
|
|
|
110
113
|
/**
|
|
111
114
|
* Emit a custom event from the grid.
|
|
112
115
|
*/
|
|
113
|
-
emit(e,
|
|
114
|
-
this.grid?.dispatchEvent?.(new CustomEvent(e, { detail:
|
|
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;
|
|
115
126
|
}
|
|
116
127
|
/**
|
|
117
128
|
* Request a re-render of the grid.
|
|
@@ -119,6 +130,14 @@ class I {
|
|
|
119
130
|
requestRender() {
|
|
120
131
|
this.grid?.requestRender?.();
|
|
121
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
|
+
}
|
|
122
141
|
/**
|
|
123
142
|
* Request a lightweight style update without rebuilding DOM.
|
|
124
143
|
* Use this instead of requestRender() when only CSS classes need updating.
|
|
@@ -152,6 +171,19 @@ class I {
|
|
|
152
171
|
get visibleColumns() {
|
|
153
172
|
return this.grid?._visibleColumns ?? [];
|
|
154
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
|
+
}
|
|
155
187
|
/**
|
|
156
188
|
* Get the shadow root of the grid.
|
|
157
189
|
*/
|
|
@@ -186,6 +218,51 @@ class I {
|
|
|
186
218
|
const e = this.grid?.gridConfig?.icons ?? {};
|
|
187
219
|
return { ...C, ...e };
|
|
188
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
|
|
189
266
|
/**
|
|
190
267
|
* Resolve an icon value to string or HTMLElement.
|
|
191
268
|
* Checks plugin config first, then grid-level icons, then defaults.
|
|
@@ -194,8 +271,8 @@ class I {
|
|
|
194
271
|
* @param pluginOverride - Optional plugin-level override
|
|
195
272
|
* @returns The resolved icon value
|
|
196
273
|
*/
|
|
197
|
-
resolveIcon(e,
|
|
198
|
-
return
|
|
274
|
+
resolveIcon(e, t) {
|
|
275
|
+
return t !== void 0 ? t : this.gridIcons[e];
|
|
199
276
|
}
|
|
200
277
|
/**
|
|
201
278
|
* Set an icon value on an element.
|
|
@@ -204,8 +281,8 @@ class I {
|
|
|
204
281
|
* @param element - The element to set the icon on
|
|
205
282
|
* @param icon - The icon value (string or HTMLElement)
|
|
206
283
|
*/
|
|
207
|
-
setIcon(e,
|
|
208
|
-
typeof
|
|
284
|
+
setIcon(e, t) {
|
|
285
|
+
typeof t == "string" ? e.innerHTML = t : t instanceof HTMLElement && (e.innerHTML = "", e.appendChild(t.cloneNode(!0)));
|
|
209
286
|
}
|
|
210
287
|
/**
|
|
211
288
|
* Log a warning message.
|
|
@@ -217,54 +294,54 @@ class I {
|
|
|
217
294
|
}
|
|
218
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}";
|
|
219
296
|
function w(s, e) {
|
|
220
|
-
return (typeof s == "function" ? s(e) : s).filter((
|
|
297
|
+
return (typeof s == "function" ? s(e) : s).filter((n) => !(n.hidden === !0 || typeof n.hidden == "function" && n.hidden(e)));
|
|
221
298
|
}
|
|
222
299
|
function M(s, e) {
|
|
223
300
|
return s.disabled === !0 ? !0 : typeof s.disabled == "function" ? s.disabled(e) : !1;
|
|
224
301
|
}
|
|
225
|
-
function v(s, e,
|
|
226
|
-
const
|
|
227
|
-
|
|
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");
|
|
228
305
|
for (const o of s) {
|
|
229
306
|
if (o.separator) {
|
|
230
|
-
const
|
|
231
|
-
|
|
307
|
+
const r = document.createElement("div");
|
|
308
|
+
r.className = "tbw-context-menu-separator", r.setAttribute("role", "separator"), l.appendChild(r);
|
|
232
309
|
continue;
|
|
233
310
|
}
|
|
234
|
-
const
|
|
235
|
-
|
|
236
|
-
const
|
|
237
|
-
if (
|
|
238
|
-
const
|
|
239
|
-
|
|
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);
|
|
313
|
+
const a = M(o, e);
|
|
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);
|
|
240
317
|
}
|
|
241
318
|
const d = document.createElement("span");
|
|
242
|
-
if (d.className = "tbw-context-menu-label", d.textContent = o.name,
|
|
243
|
-
const
|
|
244
|
-
|
|
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);
|
|
245
322
|
}
|
|
246
323
|
if (o.subMenu?.length) {
|
|
247
|
-
const
|
|
248
|
-
|
|
249
|
-
if (
|
|
250
|
-
const h = w(o.subMenu, e),
|
|
251
|
-
|
|
252
|
-
}),
|
|
253
|
-
const u =
|
|
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");
|
|
254
331
|
u && u.remove();
|
|
255
332
|
});
|
|
256
333
|
}
|
|
257
|
-
!
|
|
258
|
-
|
|
259
|
-
}),
|
|
334
|
+
!a && o.action && !o.subMenu && i.addEventListener("click", (r) => {
|
|
335
|
+
r.stopPropagation(), t(o);
|
|
336
|
+
}), l.appendChild(i);
|
|
260
337
|
}
|
|
261
|
-
return
|
|
338
|
+
return l;
|
|
262
339
|
}
|
|
263
|
-
function y(s, e,
|
|
264
|
-
s.style.position = "fixed", s.style.left = `${e}px`, s.style.top = `${
|
|
265
|
-
const
|
|
266
|
-
let
|
|
267
|
-
e +
|
|
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";
|
|
268
345
|
}
|
|
269
346
|
let f = null, p = null, m = null, b = 0;
|
|
270
347
|
const x = [
|
|
@@ -285,9 +362,8 @@ const x = [
|
|
|
285
362
|
}
|
|
286
363
|
}
|
|
287
364
|
];
|
|
288
|
-
class
|
|
365
|
+
class R extends I {
|
|
289
366
|
name = "contextMenu";
|
|
290
|
-
version = "1.0.0";
|
|
291
367
|
get defaultConfig() {
|
|
292
368
|
return {
|
|
293
369
|
items: x
|
|
@@ -310,9 +386,9 @@ class H extends I {
|
|
|
310
386
|
// #region Private Methods
|
|
311
387
|
installGlobalHandlers() {
|
|
312
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 = () => {
|
|
313
|
-
document.querySelectorAll(".tbw-context-menu").forEach((
|
|
389
|
+
document.querySelectorAll(".tbw-context-menu").forEach((t) => t.remove());
|
|
314
390
|
}, document.addEventListener("click", f)), p || (p = (e) => {
|
|
315
|
-
e.key === "Escape" && document.querySelectorAll(".tbw-context-menu").forEach((
|
|
391
|
+
e.key === "Escape" && document.querySelectorAll(".tbw-context-menu").forEach((n) => n.remove());
|
|
316
392
|
}, document.addEventListener("keydown", p));
|
|
317
393
|
}
|
|
318
394
|
/**
|
|
@@ -327,26 +403,26 @@ class H extends I {
|
|
|
327
403
|
afterRender() {
|
|
328
404
|
const e = this.shadowRoot;
|
|
329
405
|
if (!e) return;
|
|
330
|
-
const
|
|
331
|
-
|
|
332
|
-
const
|
|
333
|
-
|
|
334
|
-
const o =
|
|
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");
|
|
335
411
|
let d;
|
|
336
|
-
if (
|
|
337
|
-
const u = parseInt(
|
|
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];
|
|
338
414
|
d = {
|
|
339
415
|
row: E,
|
|
340
416
|
rowIndex: u,
|
|
341
|
-
column:
|
|
417
|
+
column: c,
|
|
342
418
|
columnIndex: h,
|
|
343
|
-
field:
|
|
344
|
-
value: E?.[
|
|
419
|
+
field: c?.field ?? "",
|
|
420
|
+
value: E?.[c?.field] ?? null,
|
|
345
421
|
isHeader: !1,
|
|
346
|
-
event:
|
|
422
|
+
event: l
|
|
347
423
|
};
|
|
348
|
-
} else if (
|
|
349
|
-
const u = parseInt(
|
|
424
|
+
} else if (a) {
|
|
425
|
+
const u = parseInt(a.getAttribute("data-col") ?? "-1", 10), h = this.columns[u];
|
|
350
426
|
d = {
|
|
351
427
|
row: null,
|
|
352
428
|
rowIndex: -1,
|
|
@@ -355,20 +431,20 @@ class H extends I {
|
|
|
355
431
|
field: h?.field ?? "",
|
|
356
432
|
value: null,
|
|
357
433
|
isHeader: !0,
|
|
358
|
-
event:
|
|
434
|
+
event: l
|
|
359
435
|
};
|
|
360
436
|
} else
|
|
361
437
|
return;
|
|
362
|
-
this.params = d, this.position = { x:
|
|
363
|
-
const
|
|
364
|
-
|
|
365
|
-
|
|
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,
|
|
366
442
|
d,
|
|
367
443
|
(u) => {
|
|
368
444
|
u.action && u.action(d), this.menuElement?.remove(), this.menuElement = null, this.isOpen = !1;
|
|
369
445
|
},
|
|
370
446
|
this.gridIcons.submenuArrow
|
|
371
|
-
), document.body.appendChild(this.menuElement), y(this.menuElement,
|
|
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 }));
|
|
372
448
|
}));
|
|
373
449
|
}
|
|
374
450
|
// #endregion
|
|
@@ -379,25 +455,25 @@ class H extends I {
|
|
|
379
455
|
* @param y - Y coordinate
|
|
380
456
|
* @param params - Partial context menu parameters
|
|
381
457
|
*/
|
|
382
|
-
showMenu(e,
|
|
383
|
-
const
|
|
384
|
-
row:
|
|
385
|
-
rowIndex:
|
|
386
|
-
column:
|
|
387
|
-
columnIndex:
|
|
388
|
-
field:
|
|
389
|
-
value:
|
|
390
|
-
isHeader:
|
|
391
|
-
event:
|
|
392
|
-
}, o = w(this.config.items ?? x,
|
|
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);
|
|
393
469
|
this.menuElement && this.menuElement.remove(), this.menuElement = v(
|
|
394
470
|
o,
|
|
395
|
-
|
|
396
|
-
(
|
|
397
|
-
|
|
471
|
+
l,
|
|
472
|
+
(i) => {
|
|
473
|
+
i.action && i.action(l), this.menuElement?.remove(), this.menuElement = null, this.isOpen = !1;
|
|
398
474
|
},
|
|
399
475
|
this.gridIcons.submenuArrow
|
|
400
|
-
), document.body.appendChild(this.menuElement), y(this.menuElement, e,
|
|
476
|
+
), document.body.appendChild(this.menuElement), y(this.menuElement, e, t), this.isOpen = !0;
|
|
401
477
|
}
|
|
402
478
|
/**
|
|
403
479
|
* Hide the context menu.
|
|
@@ -416,6 +492,6 @@ class H extends I {
|
|
|
416
492
|
// Styles are injected globally via installGlobalHandlers() since menu renders in document.body
|
|
417
493
|
}
|
|
418
494
|
export {
|
|
419
|
-
|
|
495
|
+
R as ContextMenuPlugin
|
|
420
496
|
};
|
|
421
497
|
//# sourceMappingURL=index.js.map
|