@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.
- package/README.md +10 -13
- package/all.js +1124 -1047
- package/all.js.map +1 -1
- package/index.js +688 -515
- 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/internal/validate-config.d.ts +14 -0
- package/lib/core/internal/validate-config.d.ts.map +1 -1
- package/lib/core/plugin/base-plugin.d.ts +105 -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/index.d.ts +1 -0
- package/lib/core/plugin/index.d.ts.map +1 -1
- package/lib/core/plugin/plugin-manager.d.ts +1 -1
- package/lib/core/plugin/plugin-manager.d.ts.map +1 -1
- 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 +9 -2
- 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 +303 -185
- 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 +116 -24
- 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 +164 -72
- 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 +213 -133
- 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 +195 -103
- 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 +145 -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 +162 -68
- 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 +246 -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 +281 -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 +121 -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 +144 -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 +178 -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 +414 -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 +304 -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 +292 -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 +95 -3
- 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 +213 -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 +7 -2
- package/lib/plugins/undo-redo/UndoRedoPlugin.d.ts.map +1 -1
- package/lib/plugins/undo-redo/index.js +112 -12
- package/lib/plugins/undo-redo/index.js.map +1 -1
- package/lib/plugins/visibility/VisibilityPlugin.d.ts +14 -5
- package/lib/plugins/visibility/VisibilityPlugin.d.ts.map +1 -1
- package/lib/plugins/visibility/index.js +168 -65
- package/lib/plugins/visibility/index.js.map +1 -1
- package/package.json +1 -1
- package/umd/grid.all.umd.js +21 -17
- package/umd/grid.all.umd.js.map +1 -1
- package/umd/grid.umd.js +14 -8
- 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
|
@@ -9,8 +9,27 @@ const C = {
|
|
|
9
9
|
toolPanel: "☰"
|
|
10
10
|
};
|
|
11
11
|
class I {
|
|
12
|
-
/**
|
|
13
|
-
|
|
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,
|
|
98
|
-
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;
|
|
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,
|
|
182
|
-
return
|
|
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,
|
|
192
|
-
typeof
|
|
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((
|
|
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,
|
|
210
|
-
const
|
|
211
|
-
|
|
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
|
|
215
|
-
|
|
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
|
|
219
|
-
|
|
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 && (
|
|
222
|
-
const
|
|
223
|
-
|
|
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,
|
|
227
|
-
const
|
|
228
|
-
|
|
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
|
|
232
|
-
|
|
233
|
-
if (
|
|
234
|
-
const h = w(o.subMenu, e), c = v(h, e,
|
|
235
|
-
c.classList.add("tbw-context-submenu"), c.style.position = "absolute", c.style.left = "100%", c.style.top = "0",
|
|
236
|
-
}),
|
|
237
|
-
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");
|
|
238
331
|
u && u.remove();
|
|
239
332
|
});
|
|
240
333
|
}
|
|
241
|
-
!a && o.action && !o.subMenu &&
|
|
242
|
-
|
|
243
|
-
}),
|
|
334
|
+
!a && o.action && !o.subMenu && i.addEventListener("click", (r) => {
|
|
335
|
+
r.stopPropagation(), t(o);
|
|
336
|
+
}), l.appendChild(i);
|
|
244
337
|
}
|
|
245
|
-
return
|
|
338
|
+
return l;
|
|
246
339
|
}
|
|
247
|
-
function y(s, e,
|
|
248
|
-
s.style.position = "fixed", s.style.left = `${e}px`, s.style.top = `${
|
|
249
|
-
const
|
|
250
|
-
let
|
|
251
|
-
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";
|
|
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
|
|
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((
|
|
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((
|
|
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
|
|
315
|
-
|
|
316
|
-
const
|
|
317
|
-
|
|
318
|
-
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");
|
|
319
411
|
let d;
|
|
320
|
-
if (
|
|
321
|
-
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];
|
|
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:
|
|
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:
|
|
434
|
+
event: l
|
|
343
435
|
};
|
|
344
436
|
} else
|
|
345
437
|
return;
|
|
346
|
-
this.params = d, this.position = { x:
|
|
347
|
-
const
|
|
348
|
-
|
|
349
|
-
|
|
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,
|
|
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,
|
|
367
|
-
const
|
|
368
|
-
row:
|
|
369
|
-
rowIndex:
|
|
370
|
-
column:
|
|
371
|
-
columnIndex:
|
|
372
|
-
field:
|
|
373
|
-
value:
|
|
374
|
-
isHeader:
|
|
375
|
-
event:
|
|
376
|
-
}, 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);
|
|
377
469
|
this.menuElement && this.menuElement.remove(), this.menuElement = v(
|
|
378
470
|
o,
|
|
379
|
-
|
|
380
|
-
(
|
|
381
|
-
|
|
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,
|
|
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
|
-
|
|
495
|
+
R as ContextMenuPlugin
|
|
404
496
|
};
|
|
405
497
|
//# sourceMappingURL=index.js.map
|