@toolbox-web/grid 0.0.1
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/all.d.ts +3518 -0
- package/all.js +3762 -0
- package/all.js.map +1 -0
- package/index.d.ts +2367 -0
- package/index.js +3105 -0
- package/index.js.map +1 -0
- package/lib/plugins/clipboard/index.js +365 -0
- package/lib/plugins/clipboard/index.js.map +1 -0
- package/lib/plugins/column-virtualization/index.js +255 -0
- package/lib/plugins/column-virtualization/index.js.map +1 -0
- package/lib/plugins/context-menu/index.js +341 -0
- package/lib/plugins/context-menu/index.js.map +1 -0
- package/lib/plugins/export/index.js +305 -0
- package/lib/plugins/export/index.js.map +1 -0
- package/lib/plugins/filtering/index.js +759 -0
- package/lib/plugins/filtering/index.js.map +1 -0
- package/lib/plugins/grouping-columns/index.js +283 -0
- package/lib/plugins/grouping-columns/index.js.map +1 -0
- package/lib/plugins/grouping-rows/index.js +494 -0
- package/lib/plugins/grouping-rows/index.js.map +1 -0
- package/lib/plugins/master-detail/index.js +303 -0
- package/lib/plugins/master-detail/index.js.map +1 -0
- package/lib/plugins/multi-sort/index.js +270 -0
- package/lib/plugins/multi-sort/index.js.map +1 -0
- package/lib/plugins/pinned-columns/index.js +221 -0
- package/lib/plugins/pinned-columns/index.js.map +1 -0
- package/lib/plugins/pinned-rows/index.js +459 -0
- package/lib/plugins/pinned-rows/index.js.map +1 -0
- package/lib/plugins/pivot/index.js +326 -0
- package/lib/plugins/pivot/index.js.map +1 -0
- package/lib/plugins/reorder/index.js +260 -0
- package/lib/plugins/reorder/index.js.map +1 -0
- package/lib/plugins/selection/index.js +426 -0
- package/lib/plugins/selection/index.js.map +1 -0
- package/lib/plugins/server-side/index.js +241 -0
- package/lib/plugins/server-side/index.js.map +1 -0
- package/lib/plugins/tree/index.js +383 -0
- package/lib/plugins/tree/index.js.map +1 -0
- package/lib/plugins/undo-redo/index.js +289 -0
- package/lib/plugins/undo-redo/index.js.map +1 -0
- package/lib/plugins/visibility/index.js +430 -0
- package/lib/plugins/visibility/index.js.map +1 -0
- package/package.json +53 -0
- package/themes/dg-theme-contrast.css +43 -0
- package/themes/dg-theme-large.css +54 -0
- package/themes/dg-theme-standard.css +19 -0
- package/themes/dg-theme-vibrant.css +16 -0
- package/umd/grid.all.umd.js +660 -0
- package/umd/grid.all.umd.js.map +1 -0
- package/umd/grid.umd.js +105 -0
- package/umd/grid.umd.js.map +1 -0
- package/umd/plugins/clipboard.umd.js +9 -0
- package/umd/plugins/clipboard.umd.js.map +1 -0
- package/umd/plugins/column-virtualization.umd.js +2 -0
- package/umd/plugins/column-virtualization.umd.js.map +1 -0
- package/umd/plugins/context-menu.umd.js +53 -0
- package/umd/plugins/context-menu.umd.js.map +1 -0
- package/umd/plugins/export.umd.js +14 -0
- package/umd/plugins/export.umd.js.map +1 -0
- package/umd/plugins/filtering.umd.js +175 -0
- package/umd/plugins/filtering.umd.js.map +1 -0
- package/umd/plugins/grouping-columns.umd.js +29 -0
- package/umd/plugins/grouping-columns.umd.js.map +1 -0
- package/umd/plugins/grouping-rows.umd.js +40 -0
- package/umd/plugins/grouping-rows.umd.js.map +1 -0
- package/umd/plugins/master-detail.umd.js +27 -0
- package/umd/plugins/master-detail.umd.js.map +1 -0
- package/umd/plugins/multi-sort.umd.js +26 -0
- package/umd/plugins/multi-sort.umd.js.map +1 -0
- package/umd/plugins/pinned-columns.umd.js +2 -0
- package/umd/plugins/pinned-columns.umd.js.map +1 -0
- package/umd/plugins/pinned-rows.umd.js +73 -0
- package/umd/plugins/pinned-rows.umd.js.map +1 -0
- package/umd/plugins/pivot.umd.js +8 -0
- package/umd/plugins/pivot.umd.js.map +1 -0
- package/umd/plugins/reorder.umd.js +31 -0
- package/umd/plugins/reorder.umd.js.map +1 -0
- package/umd/plugins/selection.umd.js +34 -0
- package/umd/plugins/selection.umd.js.map +1 -0
- package/umd/plugins/server-side.umd.js +2 -0
- package/umd/plugins/server-side.umd.js.map +1 -0
- package/umd/plugins/tree.umd.js +11 -0
- package/umd/plugins/tree.umd.js.map +1 -0
- package/umd/plugins/undo-redo.umd.js +2 -0
- package/umd/plugins/undo-redo.umd.js.map +1 -0
- package/umd/plugins/visibility.umd.js +94 -0
- package/umd/plugins/visibility.umd.js.map +1 -0
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
class m {
|
|
2
|
+
/** Plugin version - override in subclass if needed */
|
|
3
|
+
version = "1.0.0";
|
|
4
|
+
/** CSS styles to inject into the grid's shadow DOM */
|
|
5
|
+
styles;
|
|
6
|
+
/** Custom cell renderers keyed by type name */
|
|
7
|
+
cellRenderers;
|
|
8
|
+
/** Custom header renderers keyed by type name */
|
|
9
|
+
headerRenderers;
|
|
10
|
+
/** Custom cell editors keyed by type name */
|
|
11
|
+
cellEditors;
|
|
12
|
+
/** The grid instance this plugin is attached to */
|
|
13
|
+
grid;
|
|
14
|
+
/** Plugin configuration - merged with defaults in attach() */
|
|
15
|
+
config;
|
|
16
|
+
/** User-provided configuration from constructor */
|
|
17
|
+
userConfig;
|
|
18
|
+
/**
|
|
19
|
+
* Default configuration - subclasses should override this getter.
|
|
20
|
+
* Note: This must be a getter (not property initializer) for proper inheritance
|
|
21
|
+
* since property initializers run after parent constructor.
|
|
22
|
+
*/
|
|
23
|
+
get defaultConfig() {
|
|
24
|
+
return {};
|
|
25
|
+
}
|
|
26
|
+
constructor(t = {}) {
|
|
27
|
+
this.userConfig = t;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Called when the plugin is attached to a grid.
|
|
31
|
+
* Override to set up event listeners, initialize state, etc.
|
|
32
|
+
*/
|
|
33
|
+
attach(t) {
|
|
34
|
+
this.grid = t, this.config = { ...this.defaultConfig, ...this.userConfig };
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Called when the plugin is detached from a grid.
|
|
38
|
+
* Override to clean up event listeners, timers, etc.
|
|
39
|
+
*/
|
|
40
|
+
detach() {
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Get another plugin instance from the same grid.
|
|
44
|
+
* Use for inter-plugin communication.
|
|
45
|
+
*/
|
|
46
|
+
getPlugin(t) {
|
|
47
|
+
return this.grid?.getPlugin(t);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Emit a custom event from the grid.
|
|
51
|
+
*/
|
|
52
|
+
emit(t, e) {
|
|
53
|
+
this.grid?.dispatchEvent?.(new CustomEvent(t, { detail: e, bubbles: !0 }));
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Request a re-render of the grid.
|
|
57
|
+
*/
|
|
58
|
+
requestRender() {
|
|
59
|
+
this.grid?.requestRender?.();
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Request a lightweight style update without rebuilding DOM.
|
|
63
|
+
* Use this instead of requestRender() when only CSS classes need updating.
|
|
64
|
+
*/
|
|
65
|
+
requestAfterRender() {
|
|
66
|
+
this.grid?.requestAfterRender?.();
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get the current rows from the grid.
|
|
70
|
+
*/
|
|
71
|
+
get rows() {
|
|
72
|
+
return this.grid?.rows ?? [];
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Get the original unfiltered/unprocessed rows from the grid.
|
|
76
|
+
* Use this when you need all source data regardless of active filters.
|
|
77
|
+
*/
|
|
78
|
+
get sourceRows() {
|
|
79
|
+
return this.grid?.sourceRows ?? [];
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Get the current columns from the grid.
|
|
83
|
+
*/
|
|
84
|
+
get columns() {
|
|
85
|
+
return this.grid?.columns ?? [];
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Get only visible columns from the grid (excludes hidden).
|
|
89
|
+
* Use this for rendering that needs to match the grid template.
|
|
90
|
+
*/
|
|
91
|
+
get visibleColumns() {
|
|
92
|
+
return this.grid?.visibleColumns ?? [];
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Get the shadow root of the grid.
|
|
96
|
+
*/
|
|
97
|
+
get shadowRoot() {
|
|
98
|
+
return this.grid?.shadowRoot ?? null;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Log a warning message.
|
|
102
|
+
*/
|
|
103
|
+
warn(t) {
|
|
104
|
+
console.warn(`[tbw-grid:${this.name}] ${t}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
const d = 100;
|
|
108
|
+
function u(s) {
|
|
109
|
+
if (s == null)
|
|
110
|
+
return d;
|
|
111
|
+
if (typeof s == "number")
|
|
112
|
+
return s;
|
|
113
|
+
const t = parseFloat(s);
|
|
114
|
+
return isNaN(t) ? d : t;
|
|
115
|
+
}
|
|
116
|
+
function c(s) {
|
|
117
|
+
return s.map((t) => u(t.width));
|
|
118
|
+
}
|
|
119
|
+
function f(s) {
|
|
120
|
+
const t = [];
|
|
121
|
+
let e = 0;
|
|
122
|
+
for (const i of s)
|
|
123
|
+
t.push(e), e += u(i.width);
|
|
124
|
+
return t;
|
|
125
|
+
}
|
|
126
|
+
function g(s) {
|
|
127
|
+
return s.reduce((t, e) => t + u(e.width), 0);
|
|
128
|
+
}
|
|
129
|
+
function w(s, t, e, i, o) {
|
|
130
|
+
const r = e.length;
|
|
131
|
+
if (r === 0)
|
|
132
|
+
return { startCol: 0, endCol: 0, visibleColumns: [] };
|
|
133
|
+
let n = b(s, e, i);
|
|
134
|
+
n = Math.max(0, n - o);
|
|
135
|
+
const C = s + t;
|
|
136
|
+
let h = n;
|
|
137
|
+
for (let l = n; l < r; l++) {
|
|
138
|
+
if (e[l] >= C) {
|
|
139
|
+
h = l - 1;
|
|
140
|
+
break;
|
|
141
|
+
}
|
|
142
|
+
h = l;
|
|
143
|
+
}
|
|
144
|
+
h = Math.min(r - 1, h + o);
|
|
145
|
+
const a = [];
|
|
146
|
+
for (let l = n; l <= h; l++)
|
|
147
|
+
a.push(l);
|
|
148
|
+
return { startCol: n, endCol: h, visibleColumns: a };
|
|
149
|
+
}
|
|
150
|
+
function b(s, t, e) {
|
|
151
|
+
let i = 0, o = t.length - 1;
|
|
152
|
+
for (; i < o; ) {
|
|
153
|
+
const r = Math.floor((i + o) / 2);
|
|
154
|
+
t[r] + e[r] <= s ? i = r + 1 : o = r;
|
|
155
|
+
}
|
|
156
|
+
return i;
|
|
157
|
+
}
|
|
158
|
+
function p(s, t, e) {
|
|
159
|
+
return e ? s > t : !1;
|
|
160
|
+
}
|
|
161
|
+
class R extends m {
|
|
162
|
+
name = "columnVirtualization";
|
|
163
|
+
version = "1.0.0";
|
|
164
|
+
get defaultConfig() {
|
|
165
|
+
return {
|
|
166
|
+
enabled: !0,
|
|
167
|
+
autoEnable: !0,
|
|
168
|
+
threshold: 30,
|
|
169
|
+
overscan: 3
|
|
170
|
+
};
|
|
171
|
+
}
|
|
172
|
+
// ===== Internal State =====
|
|
173
|
+
isVirtualized = !1;
|
|
174
|
+
startCol = 0;
|
|
175
|
+
endCol = 0;
|
|
176
|
+
scrollLeft = 0;
|
|
177
|
+
totalWidth = 0;
|
|
178
|
+
columnWidths = [];
|
|
179
|
+
columnOffsets = [];
|
|
180
|
+
// ===== Lifecycle =====
|
|
181
|
+
attach(t) {
|
|
182
|
+
super.attach(t);
|
|
183
|
+
const e = this.columns;
|
|
184
|
+
this.columnWidths = c(e), this.columnOffsets = f(e), this.totalWidth = g(e), this.endCol = e.length - 1;
|
|
185
|
+
}
|
|
186
|
+
detach() {
|
|
187
|
+
this.columnWidths = [], this.columnOffsets = [], this.isVirtualized = !1, this.startCol = 0, this.endCol = 0, this.scrollLeft = 0, this.totalWidth = 0;
|
|
188
|
+
}
|
|
189
|
+
// ===== Hooks =====
|
|
190
|
+
processColumns(t) {
|
|
191
|
+
const e = this.config.enabled && p(t.length, this.config.threshold ?? 30, this.config.autoEnable ?? !0);
|
|
192
|
+
if (this.isVirtualized = e ?? !1, this.columnWidths = c(t), this.columnOffsets = f(t), this.totalWidth = g(t), !e)
|
|
193
|
+
return this.startCol = 0, this.endCol = t.length - 1, [...t];
|
|
194
|
+
const i = this.grid.clientWidth || 800, o = w(
|
|
195
|
+
this.scrollLeft,
|
|
196
|
+
i,
|
|
197
|
+
this.columnOffsets,
|
|
198
|
+
this.columnWidths,
|
|
199
|
+
this.config.overscan ?? 3
|
|
200
|
+
);
|
|
201
|
+
return this.startCol = o.startCol, this.endCol = o.endCol, o.visibleColumns.map((r) => t[r]);
|
|
202
|
+
}
|
|
203
|
+
afterRender() {
|
|
204
|
+
if (!this.isVirtualized) return;
|
|
205
|
+
const t = this.shadowRoot;
|
|
206
|
+
if (!t) return;
|
|
207
|
+
const e = this.columnOffsets[this.startCol] ?? 0, i = t.querySelector(".header-row"), o = t.querySelectorAll(".data-grid-row");
|
|
208
|
+
i && (i.style.paddingLeft = `${e}px`), o.forEach((n) => {
|
|
209
|
+
n.style.paddingLeft = `${e}px`;
|
|
210
|
+
});
|
|
211
|
+
const r = t.querySelector(".rows-viewport .rows");
|
|
212
|
+
r && (r.style.width = `${this.totalWidth}px`);
|
|
213
|
+
}
|
|
214
|
+
onScroll(t) {
|
|
215
|
+
!this.isVirtualized || Math.abs(t.scrollLeft - this.scrollLeft) < 1 || (this.scrollLeft = t.scrollLeft, this.requestRender());
|
|
216
|
+
}
|
|
217
|
+
// ===== Public API =====
|
|
218
|
+
/**
|
|
219
|
+
* Check if column virtualization is currently active.
|
|
220
|
+
*/
|
|
221
|
+
getIsVirtualized() {
|
|
222
|
+
return this.isVirtualized;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Get the current visible column range.
|
|
226
|
+
*/
|
|
227
|
+
getVisibleColumnRange() {
|
|
228
|
+
return { start: this.startCol, end: this.endCol };
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Scroll the grid to bring a specific column into view.
|
|
232
|
+
* @param columnIndex - Index of the column to scroll to
|
|
233
|
+
*/
|
|
234
|
+
scrollToColumn(t) {
|
|
235
|
+
const e = this.columnOffsets[t] ?? 0, i = this.grid;
|
|
236
|
+
i.scrollLeft = e;
|
|
237
|
+
}
|
|
238
|
+
/**
|
|
239
|
+
* Get the left offset for a specific column.
|
|
240
|
+
* @param columnIndex - Index of the column
|
|
241
|
+
*/
|
|
242
|
+
getColumnOffset(t) {
|
|
243
|
+
return this.columnOffsets[t] ?? 0;
|
|
244
|
+
}
|
|
245
|
+
/**
|
|
246
|
+
* Get the total width of all columns.
|
|
247
|
+
*/
|
|
248
|
+
getTotalWidth() {
|
|
249
|
+
return this.totalWidth;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
export {
|
|
253
|
+
R as ColumnVirtualizationPlugin
|
|
254
|
+
};
|
|
255
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sources":["../../../../../../libs/grid/src/lib/core/plugin/base-plugin.ts","../../../../../../libs/grid/src/lib/plugins/column-virtualization/column-virtualization.ts","../../../../../../libs/grid/src/lib/plugins/column-virtualization/ColumnVirtualizationPlugin.ts"],"sourcesContent":["/**\r\n * Base Grid Plugin Class\r\n *\r\n * All plugins extend this abstract class.\r\n * Plugins are instantiated per-grid and manage their own state.\r\n */\r\n\r\nimport type { ColumnConfig, ColumnState, HeaderContentDefinition, ToolPanelDefinition } from '../types';\r\n\r\n// Forward declare to avoid circular imports\r\nexport interface GridElement {\r\n shadowRoot: ShadowRoot | null;\r\n rows: any[];\r\n columns: ColumnConfig[];\r\n gridConfig: any;\r\n requestRender(): void;\r\n requestAfterRender(): void;\r\n forceLayout(): Promise<void>;\r\n getPlugin<T extends BaseGridPlugin>(PluginClass: new (...args: any[]) => T): T | undefined;\r\n getPluginByName(name: string): BaseGridPlugin | undefined;\r\n dispatchEvent(event: Event): boolean;\r\n}\r\n\r\n/**\r\n * Keyboard modifier flags\r\n */\r\nexport interface KeyboardModifiers {\r\n ctrl?: boolean;\r\n shift?: boolean;\r\n alt?: boolean;\r\n meta?: boolean;\r\n}\r\n\r\n/**\r\n * Cell coordinates\r\n */\r\nexport interface CellCoords {\r\n row: number;\r\n col: number;\r\n}\r\n\r\n/**\r\n * Cell click event\r\n */\r\nexport interface CellClickEvent {\r\n rowIndex: number;\r\n colIndex: number;\r\n field: string;\r\n value: any;\r\n row: any;\r\n cellEl: HTMLElement;\r\n originalEvent: MouseEvent;\r\n}\r\n\r\n/**\r\n * Row click event\r\n */\r\nexport interface RowClickEvent {\r\n rowIndex: number;\r\n row: any;\r\n rowEl: HTMLElement;\r\n originalEvent: MouseEvent;\r\n}\r\n\r\n/**\r\n * Header click event\r\n */\r\nexport interface HeaderClickEvent {\r\n colIndex: number;\r\n field: string;\r\n column: ColumnConfig;\r\n headerEl: HTMLElement;\r\n originalEvent: MouseEvent;\r\n}\r\n\r\n/**\r\n * Scroll event\r\n */\r\nexport interface ScrollEvent {\r\n scrollTop: number;\r\n scrollLeft: number;\r\n scrollHeight: number;\r\n scrollWidth: number;\r\n clientHeight: number;\r\n clientWidth: number;\r\n originalEvent?: Event;\r\n}\r\n\r\n/**\r\n * Cell mouse event (for drag operations, selection, etc.)\r\n */\r\nexport interface CellMouseEvent {\r\n /** Event type: mousedown, mousemove, or mouseup */\r\n type: 'mousedown' | 'mousemove' | 'mouseup';\r\n /** Row index, undefined if not over a data cell */\r\n rowIndex?: number;\r\n /** Column index, undefined if not over a cell */\r\n colIndex?: number;\r\n /** Field name, undefined if not over a cell */\r\n field?: string;\r\n /** Cell value, undefined if not over a data cell */\r\n value?: unknown;\r\n /** Row data object, undefined if not over a data row */\r\n row?: unknown;\r\n /** Column configuration, undefined if not over a column */\r\n column?: ColumnConfig;\r\n /** The cell element, undefined if not over a cell */\r\n cellElement?: HTMLElement;\r\n /** The row element, undefined if not over a row */\r\n rowElement?: HTMLElement;\r\n /** Whether the event is over a header cell */\r\n isHeader: boolean;\r\n /** Cell coordinates if over a valid data cell */\r\n cell?: CellCoords;\r\n /** The original mouse event */\r\n originalEvent: MouseEvent;\r\n}\r\n\r\n/**\r\n * Context menu parameters\r\n */\r\nexport interface ContextMenuParams {\r\n x: number;\r\n y: number;\r\n rowIndex?: number;\r\n colIndex?: number;\r\n field?: string;\r\n value?: any;\r\n row?: any;\r\n column?: ColumnConfig;\r\n isHeader?: boolean;\r\n}\r\n\r\n/**\r\n * Context menu item\r\n */\r\nexport interface ContextMenuItem {\r\n id: string;\r\n label: string;\r\n icon?: string;\r\n disabled?: boolean;\r\n separator?: boolean;\r\n children?: ContextMenuItem[];\r\n action?: (params: ContextMenuParams) => void;\r\n}\r\n\r\n/**\r\n * Cell render context for plugin cell renderers.\r\n * Provides full context including position and editing state.\r\n *\r\n * Note: This differs from the core `CellRenderContext` in types.ts which is\r\n * simpler and used for column view renderers. This version provides additional\r\n * context needed by plugins that register custom cell renderers.\r\n */\r\nexport interface PluginCellRenderContext {\r\n /** The cell value */\r\n value: any;\r\n /** The field/column key */\r\n field: string;\r\n /** The row data object */\r\n row: any;\r\n /** Row index in the data array */\r\n rowIndex: number;\r\n /** Column index */\r\n colIndex: number;\r\n /** Column configuration */\r\n column: ColumnConfig;\r\n /** Whether the cell is currently in edit mode */\r\n isEditing: boolean;\r\n}\r\n\r\n/**\r\n * Header render context for plugin header renderers.\r\n */\r\nexport interface PluginHeaderRenderContext {\r\n /** Column configuration */\r\n column: ColumnConfig;\r\n /** Column index */\r\n colIndex: number;\r\n}\r\n\r\n/**\r\n * Cell renderer function type for plugins.\r\n */\r\nexport type CellRenderer = (ctx: PluginCellRenderContext) => string | HTMLElement;\r\n\r\n/**\r\n * Header renderer function type for plugins.\r\n */\r\nexport type HeaderRenderer = (ctx: PluginHeaderRenderContext) => string | HTMLElement;\r\n\r\n/**\r\n * Cell editor interface for plugins.\r\n */\r\nexport interface CellEditor {\r\n create(ctx: PluginCellRenderContext, commitFn: (value: any) => void, cancelFn: () => void): HTMLElement;\r\n getValue?(element: HTMLElement): any;\r\n focus?(element: HTMLElement): void;\r\n}\r\n\r\n/**\r\n * Abstract base class for all grid plugins.\r\n *\r\n * @template TConfig - Configuration type for the plugin\r\n */\r\nexport abstract class BaseGridPlugin<TConfig = unknown> {\r\n /** Unique plugin identifier (derived from class name by default) */\r\n abstract readonly name: string;\r\n\r\n /** Plugin version - override in subclass if needed */\r\n readonly version: string = '1.0.0';\r\n\r\n /** CSS styles to inject into the grid's shadow DOM */\r\n readonly styles?: string;\r\n\r\n /** Custom cell renderers keyed by type name */\r\n readonly cellRenderers?: Record<string, CellRenderer>;\r\n\r\n /** Custom header renderers keyed by type name */\r\n readonly headerRenderers?: Record<string, HeaderRenderer>;\r\n\r\n /** Custom cell editors keyed by type name */\r\n readonly cellEditors?: Record<string, CellEditor>;\r\n\r\n /** The grid instance this plugin is attached to */\r\n protected grid!: GridElement;\r\n\r\n /** Plugin configuration - merged with defaults in attach() */\r\n protected config!: TConfig;\r\n\r\n /** User-provided configuration from constructor */\r\n private readonly userConfig: Partial<TConfig>;\r\n\r\n /**\r\n * Default configuration - subclasses should override this getter.\r\n * Note: This must be a getter (not property initializer) for proper inheritance\r\n * since property initializers run after parent constructor.\r\n */\r\n protected get defaultConfig(): Partial<TConfig> {\r\n return {};\r\n }\r\n\r\n constructor(config: Partial<TConfig> = {}) {\r\n this.userConfig = config;\r\n }\r\n\r\n /**\r\n * Called when the plugin is attached to a grid.\r\n * Override to set up event listeners, initialize state, etc.\r\n */\r\n attach(grid: GridElement): void {\r\n this.grid = grid;\r\n // Merge config here (after subclass construction is complete)\r\n this.config = { ...this.defaultConfig, ...this.userConfig } as TConfig;\r\n }\r\n\r\n /**\r\n * Called when the plugin is detached from a grid.\r\n * Override to clean up event listeners, timers, etc.\r\n */\r\n detach(): void {\r\n // Override in subclass\r\n }\r\n\r\n /**\r\n * Get another plugin instance from the same grid.\r\n * Use for inter-plugin communication.\r\n */\r\n protected getPlugin<T extends BaseGridPlugin>(PluginClass: new (...args: any[]) => T): T | undefined {\r\n return this.grid?.getPlugin(PluginClass);\r\n }\r\n\r\n /**\r\n * Emit a custom event from the grid.\r\n */\r\n protected emit<T>(eventName: string, detail: T): void {\r\n this.grid?.dispatchEvent?.(new CustomEvent(eventName, { detail, bubbles: true }));\r\n }\r\n\r\n /**\r\n * Request a re-render of the grid.\r\n */\r\n protected requestRender(): void {\r\n this.grid?.requestRender?.();\r\n }\r\n\r\n /**\r\n * Request a lightweight style update without rebuilding DOM.\r\n * Use this instead of requestRender() when only CSS classes need updating.\r\n */\r\n protected requestAfterRender(): void {\r\n this.grid?.requestAfterRender?.();\r\n }\r\n\r\n /**\r\n * Get the current rows from the grid.\r\n */\r\n protected get rows(): any[] {\r\n return this.grid?.rows ?? [];\r\n }\r\n\r\n /**\r\n * Get the original unfiltered/unprocessed rows from the grid.\r\n * Use this when you need all source data regardless of active filters.\r\n */\r\n protected get sourceRows(): any[] {\r\n return (this.grid as any)?.sourceRows ?? [];\r\n }\r\n\r\n /**\r\n * Get the current columns from the grid.\r\n */\r\n protected get columns(): ColumnConfig[] {\r\n return this.grid?.columns ?? [];\r\n }\r\n\r\n /**\r\n * Get only visible columns from the grid (excludes hidden).\r\n * Use this for rendering that needs to match the grid template.\r\n */\r\n protected get visibleColumns(): ColumnConfig[] {\r\n return (this.grid as any)?.visibleColumns ?? [];\r\n }\r\n\r\n /**\r\n * Get the shadow root of the grid.\r\n */\r\n protected get shadowRoot(): ShadowRoot | null {\r\n return this.grid?.shadowRoot ?? null;\r\n }\r\n\r\n /**\r\n * Log a warning message.\r\n */\r\n protected warn(message: string): void {\r\n console.warn(`[tbw-grid:${this.name}] ${message}`);\r\n }\r\n\r\n // ===== Lifecycle Hooks (override as needed) =====\r\n\r\n /**\r\n * Transform rows before rendering.\r\n * Called during each render cycle before rows are rendered to the DOM.\r\n * Use this to filter, sort, or add computed properties to rows.\r\n *\r\n * @param rows - The current rows array (readonly to encourage returning a new array)\r\n * @returns The modified rows array to render\r\n *\r\n * @example\r\n * ```ts\r\n * processRows(rows: readonly any[]): any[] {\r\n * // Filter out hidden rows\r\n * return rows.filter(row => !row._hidden);\r\n * }\r\n * ```\r\n *\r\n * @example\r\n * ```ts\r\n * processRows(rows: readonly any[]): any[] {\r\n * // Add computed properties\r\n * return rows.map(row => ({\r\n * ...row,\r\n * _fullName: `${row.firstName} ${row.lastName}`\r\n * }));\r\n * }\r\n * ```\r\n */\r\n processRows?(rows: readonly any[]): any[];\r\n\r\n /**\r\n * Transform columns before rendering.\r\n * Called during each render cycle before column headers and cells are rendered.\r\n * Use this to add, remove, or modify column definitions.\r\n *\r\n * @param columns - The current columns array (readonly to encourage returning a new array)\r\n * @returns The modified columns array to render\r\n *\r\n * @example\r\n * ```ts\r\n * processColumns(columns: readonly ColumnConfig[]): ColumnConfig[] {\r\n * // Add a selection checkbox column\r\n * return [\r\n * { field: '_select', header: '', width: 40 },\r\n * ...columns\r\n * ];\r\n * }\r\n * ```\r\n */\r\n processColumns?(columns: readonly ColumnConfig[]): ColumnConfig[];\r\n\r\n /**\r\n * Called before each render cycle begins.\r\n * Use this to prepare state or cache values needed during rendering.\r\n *\r\n * @example\r\n * ```ts\r\n * beforeRender(): void {\r\n * this.visibleRowCount = this.calculateVisibleRows();\r\n * }\r\n * ```\r\n */\r\n beforeRender?(): void;\r\n\r\n /**\r\n * Called after each render cycle completes.\r\n * Use this for DOM manipulation, adding event listeners to rendered elements,\r\n * or applying visual effects like selection highlights.\r\n *\r\n * @example\r\n * ```ts\r\n * afterRender(): void {\r\n * // Apply selection styling to rendered rows\r\n * const rows = this.shadowRoot?.querySelectorAll('.data-row');\r\n * rows?.forEach((row, i) => {\r\n * row.classList.toggle('selected', this.selectedRows.has(i));\r\n * });\r\n * }\r\n * ```\r\n */\r\n afterRender?(): void;\r\n\r\n /**\r\n * Render a custom row, bypassing the default row rendering.\r\n * Use this for special row types like group headers, detail rows, or footers.\r\n *\r\n * @param row - The row data object\r\n * @param rowEl - The row DOM element to render into\r\n * @param rowIndex - The index of the row in the data array\r\n * @returns `true` if the plugin handled rendering (prevents default), `false`/`void` for default rendering\r\n *\r\n * @example\r\n * ```ts\r\n * renderRow(row: any, rowEl: HTMLElement, rowIndex: number): boolean | void {\r\n * if (row._isGroupHeader) {\r\n * rowEl.innerHTML = `<div class=\"group-header\">${row._groupLabel}</div>`;\r\n * return true; // Handled - skip default rendering\r\n * }\r\n * // Return void to let default rendering proceed\r\n * }\r\n * ```\r\n */\r\n renderRow?(row: any, rowEl: HTMLElement, rowIndex: number): boolean | void;\r\n\r\n // ===== Interaction Hooks (override as needed) =====\r\n\r\n /**\r\n * Handle keyboard events on the grid.\r\n * Called when a key is pressed while the grid or a cell has focus.\r\n *\r\n * @param event - The native KeyboardEvent\r\n * @returns `true` to prevent default behavior and stop propagation, `false`/`void` to allow default\r\n *\r\n * @example\r\n * ```ts\r\n * onKeyDown(event: KeyboardEvent): boolean | void {\r\n * // Handle Ctrl+A for select all\r\n * if (event.ctrlKey && event.key === 'a') {\r\n * this.selectAllRows();\r\n * return true; // Prevent default browser select-all\r\n * }\r\n * }\r\n * ```\r\n */\r\n onKeyDown?(event: KeyboardEvent): boolean | void;\r\n\r\n /**\r\n * Handle cell click events.\r\n * Called when a data cell is clicked (not headers).\r\n *\r\n * @param event - Cell click event with row/column context\r\n * @returns `true` to prevent default behavior and stop propagation, `false`/`void` to allow default\r\n *\r\n * @example\r\n * ```ts\r\n * onCellClick(event: CellClickEvent): boolean | void {\r\n * if (event.field === '_select') {\r\n * this.toggleRowSelection(event.rowIndex);\r\n * return true; // Handled\r\n * }\r\n * }\r\n * ```\r\n */\r\n onCellClick?(event: CellClickEvent): boolean | void;\r\n\r\n /**\r\n * Handle row click events.\r\n * Called when any part of a data row is clicked.\r\n * Note: This is called in addition to onCellClick, not instead of.\r\n *\r\n * @param event - Row click event with row context\r\n * @returns `true` to prevent default behavior and stop propagation, `false`/`void` to allow default\r\n *\r\n * @example\r\n * ```ts\r\n * onRowClick(event: RowClickEvent): boolean | void {\r\n * if (this.config.mode === 'row') {\r\n * this.selectRow(event.rowIndex, event.originalEvent);\r\n * return true;\r\n * }\r\n * }\r\n * ```\r\n */\r\n onRowClick?(event: RowClickEvent): boolean | void;\r\n\r\n /**\r\n * Handle header click events.\r\n * Called when a column header is clicked. Commonly used for sorting.\r\n *\r\n * @param event - Header click event with column context\r\n * @returns `true` to prevent default behavior and stop propagation, `false`/`void` to allow default\r\n *\r\n * @example\r\n * ```ts\r\n * onHeaderClick(event: HeaderClickEvent): boolean | void {\r\n * if (event.column.sortable !== false) {\r\n * this.toggleSort(event.field);\r\n * return true;\r\n * }\r\n * }\r\n * ```\r\n */\r\n onHeaderClick?(event: HeaderClickEvent): boolean | void;\r\n\r\n /**\r\n * Handle scroll events on the grid viewport.\r\n * Called during scrolling. Note: This may be called frequently; debounce if needed.\r\n *\r\n * @param event - Scroll event with scroll position and viewport dimensions\r\n *\r\n * @example\r\n * ```ts\r\n * onScroll(event: ScrollEvent): void {\r\n * // Update sticky column positions\r\n * this.updateStickyPositions(event.scrollLeft);\r\n * }\r\n * ```\r\n */\r\n onScroll?(event: ScrollEvent): void;\r\n\r\n /**\r\n * Handle cell mousedown events.\r\n * Used for initiating drag operations like range selection or column resize.\r\n *\r\n * @param event - Mouse event with cell context\r\n * @returns `true` to indicate drag started (prevents text selection), `false`/`void` otherwise\r\n *\r\n * @example\r\n * ```ts\r\n * onCellMouseDown(event: CellMouseEvent): boolean | void {\r\n * if (event.rowIndex !== undefined && this.config.mode === 'range') {\r\n * this.startDragSelection(event.rowIndex, event.colIndex);\r\n * return true; // Prevent text selection\r\n * }\r\n * }\r\n * ```\r\n */\r\n onCellMouseDown?(event: CellMouseEvent): boolean | void;\r\n\r\n /**\r\n * Handle cell mousemove events during drag operations.\r\n * Only called when a drag is in progress (after mousedown returned true).\r\n *\r\n * @param event - Mouse event with current cell context\r\n * @returns `true` to continue handling the drag, `false`/`void` otherwise\r\n *\r\n * @example\r\n * ```ts\r\n * onCellMouseMove(event: CellMouseEvent): boolean | void {\r\n * if (this.isDragging && event.rowIndex !== undefined) {\r\n * this.extendSelection(event.rowIndex, event.colIndex);\r\n * return true;\r\n * }\r\n * }\r\n * ```\r\n */\r\n onCellMouseMove?(event: CellMouseEvent): boolean | void;\r\n\r\n /**\r\n * Handle cell mouseup events to end drag operations.\r\n *\r\n * @param event - Mouse event with final cell context\r\n * @returns `true` if drag was finalized, `false`/`void` otherwise\r\n *\r\n * @example\r\n * ```ts\r\n * onCellMouseUp(event: CellMouseEvent): boolean | void {\r\n * if (this.isDragging) {\r\n * this.finalizeDragSelection();\r\n * this.isDragging = false;\r\n * return true;\r\n * }\r\n * }\r\n * ```\r\n */\r\n onCellMouseUp?(event: CellMouseEvent): boolean | void;\r\n\r\n /**\r\n * Provide context menu items when right-clicking on the grid.\r\n * Multiple plugins can contribute items; they are merged into a single menu.\r\n *\r\n * @param params - Context about where the menu was triggered (row, column, etc.)\r\n * @returns Array of menu items to display\r\n *\r\n * @example\r\n * ```ts\r\n * getContextMenuItems(params: ContextMenuParams): ContextMenuItem[] {\r\n * if (params.isHeader) {\r\n * return [\r\n * { id: 'sort-asc', label: 'Sort Ascending', action: () => this.sortAsc(params.field) },\r\n * { id: 'sort-desc', label: 'Sort Descending', action: () => this.sortDesc(params.field) },\r\n * ];\r\n * }\r\n * return [\r\n * { id: 'copy', label: 'Copy Cell', action: () => this.copyCell(params) },\r\n * ];\r\n * }\r\n * ```\r\n */\r\n getContextMenuItems?(params: ContextMenuParams): ContextMenuItem[];\r\n\r\n // ===== Column State Hooks (override as needed) =====\r\n\r\n /**\r\n * Contribute plugin-specific state for a column.\r\n * Called by the grid when collecting column state for serialization.\r\n * Plugins can add their own properties to the column state.\r\n *\r\n * @param field - The field name of the column\r\n * @returns Partial column state with plugin-specific properties, or undefined if no state to contribute\r\n *\r\n * @example\r\n * ```ts\r\n * getColumnState(field: string): Partial<ColumnState> | undefined {\r\n * const filterModel = this.filterModels.get(field);\r\n * if (filterModel) {\r\n * // Uses module augmentation to add filter property to ColumnState\r\n * return { filter: filterModel } as Partial<ColumnState>;\r\n * }\r\n * return undefined;\r\n * }\r\n * ```\r\n */\r\n getColumnState?(field: string): Partial<ColumnState> | undefined;\r\n\r\n /**\r\n * Apply plugin-specific state to a column.\r\n * Called by the grid when restoring column state from serialized data.\r\n * Plugins should restore their internal state based on the provided state.\r\n *\r\n * @param field - The field name of the column\r\n * @param state - The column state to apply (may contain plugin-specific properties)\r\n *\r\n * @example\r\n * ```ts\r\n * applyColumnState(field: string, state: ColumnState): void {\r\n * // Check for filter property added via module augmentation\r\n * const filter = (state as any).filter;\r\n * if (filter) {\r\n * this.filterModels.set(field, filter);\r\n * this.applyFilter();\r\n * }\r\n * }\r\n * ```\r\n */\r\n applyColumnState?(field: string, state: ColumnState): void;\r\n\r\n // ===== Shell Integration Hooks (override as needed) =====\r\n\r\n /**\r\n * Register a tool panel for this plugin.\r\n * Return undefined if plugin has no tool panel.\r\n * The shell will create a toolbar toggle button and render the panel content\r\n * when the user opens the panel.\r\n *\r\n * @returns Tool panel definition, or undefined if plugin has no panel\r\n *\r\n * @example\r\n * ```ts\r\n * getToolPanel(): ToolPanelDefinition | undefined {\r\n * return {\r\n * id: 'columns',\r\n * title: 'Columns',\r\n * icon: '☰',\r\n * tooltip: 'Show/hide columns',\r\n * order: 10,\r\n * render: (container) => {\r\n * this.renderColumnList(container);\r\n * return () => this.cleanup();\r\n * },\r\n * };\r\n * }\r\n * ```\r\n */\r\n getToolPanel?(): ToolPanelDefinition | undefined;\r\n\r\n /**\r\n * Register content for the shell header center section.\r\n * Return undefined if plugin has no header content.\r\n * Examples: search input, selection summary, status indicators.\r\n *\r\n * @returns Header content definition, or undefined if plugin has no header content\r\n *\r\n * @example\r\n * ```ts\r\n * getHeaderContent(): HeaderContentDefinition | undefined {\r\n * return {\r\n * id: 'quick-filter',\r\n * order: 10,\r\n * render: (container) => {\r\n * const input = document.createElement('input');\r\n * input.type = 'text';\r\n * input.placeholder = 'Search...';\r\n * input.addEventListener('input', this.handleInput);\r\n * container.appendChild(input);\r\n * return () => input.removeEventListener('input', this.handleInput);\r\n * },\r\n * };\r\n * }\r\n * ```\r\n */\r\n getHeaderContent?(): HeaderContentDefinition | undefined;\r\n}\r\n","/**\n * Column Virtualization Core Logic\n *\n * Pure functions for horizontal column virtualization operations.\n */\n\nimport type { ColumnConfig } from '../../core/types';\nimport type { ColumnVirtualizationViewport } from './types';\n\n/** Default column width when not specified */\nconst DEFAULT_COLUMN_WIDTH = 100;\n\n/**\n * Parse a column width value to pixels.\n * Handles number (px) and string formats.\n *\n * @param width - The width value from column config\n * @returns Width in pixels\n */\nexport function parseColumnWidth(width: string | number | undefined): number {\n if (width === undefined || width === null) {\n return DEFAULT_COLUMN_WIDTH;\n }\n\n if (typeof width === 'number') {\n return width;\n }\n\n // Handle string values - extract numeric part\n const numeric = parseFloat(width);\n if (!isNaN(numeric)) {\n return numeric;\n }\n\n return DEFAULT_COLUMN_WIDTH;\n}\n\n/**\n * Get array of column widths in pixels.\n *\n * @param columns - Column configurations\n * @returns Array of widths in pixels\n */\nexport function getColumnWidths(columns: readonly ColumnConfig[]): number[] {\n return columns.map((col) => parseColumnWidth(col.width));\n}\n\n/**\n * Compute cumulative left offsets for each column.\n *\n * @param columns - Column configurations\n * @returns Array of left offsets in pixels\n */\nexport function computeColumnOffsets(columns: readonly ColumnConfig[]): number[] {\n const offsets: number[] = [];\n let offset = 0;\n\n for (const col of columns) {\n offsets.push(offset);\n offset += parseColumnWidth(col.width);\n }\n\n return offsets;\n}\n\n/**\n * Compute total width of all columns.\n *\n * @param columns - Column configurations\n * @returns Total width in pixels\n */\nexport function computeTotalWidth(columns: readonly ColumnConfig[]): number {\n return columns.reduce((sum, col) => sum + parseColumnWidth(col.width), 0);\n}\n\n/**\n * Find the visible column range based on scroll position.\n * Uses binary search for efficient lookup in large column sets.\n *\n * @param scrollLeft - Current horizontal scroll position\n * @param viewportWidth - Width of the visible viewport\n * @param columnOffsets - Array of column left offsets\n * @param columnWidths - Array of column widths\n * @param overscan - Number of extra columns to render on each side\n * @returns Viewport information with visible column indices\n */\nexport function getVisibleColumnRange(\n scrollLeft: number,\n viewportWidth: number,\n columnOffsets: number[],\n columnWidths: number[],\n overscan: number\n): ColumnVirtualizationViewport {\n const columnCount = columnOffsets.length;\n\n if (columnCount === 0) {\n return { startCol: 0, endCol: 0, visibleColumns: [] };\n }\n\n // Binary search for first visible column\n let startCol = binarySearchFirstVisible(scrollLeft, columnOffsets, columnWidths);\n startCol = Math.max(0, startCol - overscan);\n\n // Find last visible column (without overscan first)\n const rightEdge = scrollLeft + viewportWidth;\n let endCol = startCol;\n\n for (let i = startCol; i < columnCount; i++) {\n if (columnOffsets[i] >= rightEdge) {\n endCol = i - 1;\n break;\n }\n endCol = i;\n }\n\n // Apply overscan to end (only once)\n endCol = Math.min(columnCount - 1, endCol + overscan);\n\n // Build array of visible column indices\n const visibleColumns: number[] = [];\n for (let i = startCol; i <= endCol; i++) {\n visibleColumns.push(i);\n }\n\n return { startCol, endCol, visibleColumns };\n}\n\n/**\n * Binary search to find the first column that is visible.\n *\n * @param scrollLeft - Current scroll position\n * @param columnOffsets - Array of column offsets\n * @param columnWidths - Array of column widths\n * @returns Index of first visible column\n */\nfunction binarySearchFirstVisible(scrollLeft: number, columnOffsets: number[], columnWidths: number[]): number {\n let low = 0;\n let high = columnOffsets.length - 1;\n\n while (low < high) {\n const mid = Math.floor((low + high) / 2);\n const colRight = columnOffsets[mid] + columnWidths[mid];\n\n if (colRight <= scrollLeft) {\n low = mid + 1;\n } else {\n high = mid;\n }\n }\n\n return low;\n}\n\n/**\n * Determine if column virtualization should be active.\n *\n * @param columnCount - Number of columns\n * @param threshold - Column count threshold\n * @param autoEnable - Whether auto-enable is configured\n * @returns True if virtualization should be active\n */\nexport function shouldVirtualize(columnCount: number, threshold: number, autoEnable: boolean): boolean {\n if (!autoEnable) return false;\n return columnCount > threshold;\n}\n","/**\n * Column Virtualization Plugin (Class-based)\n *\n * Provides horizontal column virtualization for grids with many columns.\n * Significantly improves rendering performance when dealing with >30 columns.\n */\n\nimport { BaseGridPlugin, ScrollEvent } from '../../core/plugin/base-plugin';\nimport type { ColumnConfig } from '../../core/types';\nimport {\n computeColumnOffsets,\n computeTotalWidth,\n getColumnWidths,\n getVisibleColumnRange,\n shouldVirtualize,\n} from './column-virtualization';\nimport type { ColumnVirtualizationConfig } from './types';\n\n/**\n * Column Virtualization Plugin for tbw-grid\n *\n * @example\n * ```ts\n * new ColumnVirtualizationPlugin({ threshold: 30, overscan: 3 })\n * ```\n */\nexport class ColumnVirtualizationPlugin extends BaseGridPlugin<ColumnVirtualizationConfig> {\n readonly name = 'columnVirtualization';\n override readonly version = '1.0.0';\n\n protected override get defaultConfig(): Partial<ColumnVirtualizationConfig> {\n return {\n enabled: true,\n autoEnable: true,\n threshold: 30,\n overscan: 3,\n };\n }\n\n // ===== Internal State =====\n private isVirtualized = false;\n private startCol = 0;\n private endCol = 0;\n private scrollLeft = 0;\n private totalWidth = 0;\n private columnWidths: number[] = [];\n private columnOffsets: number[] = [];\n\n // ===== Lifecycle =====\n\n override attach(grid: import('../../core/plugin/base-plugin').GridElement): void {\n super.attach(grid);\n\n // Initialize state from current columns\n const columns = this.columns;\n this.columnWidths = getColumnWidths(columns);\n this.columnOffsets = computeColumnOffsets(columns);\n this.totalWidth = computeTotalWidth(columns);\n this.endCol = columns.length - 1;\n }\n\n override detach(): void {\n this.columnWidths = [];\n this.columnOffsets = [];\n this.isVirtualized = false;\n this.startCol = 0;\n this.endCol = 0;\n this.scrollLeft = 0;\n this.totalWidth = 0;\n }\n\n // ===== Hooks =====\n\n override processColumns(columns: readonly ColumnConfig[]): ColumnConfig[] {\n const isVirtualized =\n this.config.enabled &&\n shouldVirtualize(columns.length, this.config.threshold ?? 30, this.config.autoEnable ?? true);\n\n // Update state with current column metrics\n this.isVirtualized = isVirtualized ?? false;\n this.columnWidths = getColumnWidths(columns);\n this.columnOffsets = computeColumnOffsets(columns);\n this.totalWidth = computeTotalWidth(columns);\n\n if (!isVirtualized) {\n this.startCol = 0;\n this.endCol = columns.length - 1;\n return [...columns];\n }\n\n // Get viewport width from grid element\n const viewportWidth = (this.grid as unknown as HTMLElement).clientWidth || 800;\n const viewport = getVisibleColumnRange(\n this.scrollLeft,\n viewportWidth,\n this.columnOffsets,\n this.columnWidths,\n this.config.overscan ?? 3\n );\n\n this.startCol = viewport.startCol;\n this.endCol = viewport.endCol;\n\n // Return only visible columns\n return viewport.visibleColumns.map((i) => columns[i]);\n }\n\n override afterRender(): void {\n if (!this.isVirtualized) return;\n\n const shadowRoot = this.shadowRoot;\n if (!shadowRoot) return;\n\n // Apply left padding to offset scrolled-out columns\n const leftPadding = this.columnOffsets[this.startCol] ?? 0;\n\n const headerRow = shadowRoot.querySelector('.header-row');\n const bodyRows = shadowRoot.querySelectorAll('.data-grid-row');\n\n if (headerRow) {\n (headerRow as HTMLElement).style.paddingLeft = `${leftPadding}px`;\n }\n\n bodyRows.forEach((row) => {\n (row as HTMLElement).style.paddingLeft = `${leftPadding}px`;\n });\n\n // Set total width for horizontal scrolling on the rows container\n const rowsContainer = shadowRoot.querySelector('.rows-viewport .rows');\n if (rowsContainer) {\n (rowsContainer as HTMLElement).style.width = `${this.totalWidth}px`;\n }\n }\n\n override onScroll(event: ScrollEvent): void {\n if (!this.isVirtualized) return;\n\n // Check if horizontal scroll position changed significantly\n const scrollDelta = Math.abs(event.scrollLeft - this.scrollLeft);\n if (scrollDelta < 1) return;\n\n // Update scroll position\n this.scrollLeft = event.scrollLeft;\n\n // Recalculate visible columns and request re-render\n this.requestRender();\n }\n\n // ===== Public API =====\n\n /**\n * Check if column virtualization is currently active.\n */\n getIsVirtualized(): boolean {\n return this.isVirtualized;\n }\n\n /**\n * Get the current visible column range.\n */\n getVisibleColumnRange(): { start: number; end: number } {\n return { start: this.startCol, end: this.endCol };\n }\n\n /**\n * Scroll the grid to bring a specific column into view.\n * @param columnIndex - Index of the column to scroll to\n */\n scrollToColumn(columnIndex: number): void {\n const offset = this.columnOffsets[columnIndex] ?? 0;\n const gridEl = this.grid as unknown as HTMLElement;\n // Scroll the grid element itself (it's the scroll container)\n gridEl.scrollLeft = offset;\n }\n\n /**\n * Get the left offset for a specific column.\n * @param columnIndex - Index of the column\n */\n getColumnOffset(columnIndex: number): number {\n return this.columnOffsets[columnIndex] ?? 0;\n }\n\n /**\n * Get the total width of all columns.\n */\n getTotalWidth(): number {\n return this.totalWidth;\n }\n}\n"],"names":["BaseGridPlugin","config","grid","PluginClass","eventName","detail","message","DEFAULT_COLUMN_WIDTH","parseColumnWidth","width","numeric","getColumnWidths","columns","col","computeColumnOffsets","offsets","offset","computeTotalWidth","sum","getVisibleColumnRange","scrollLeft","viewportWidth","columnOffsets","columnWidths","overscan","columnCount","startCol","binarySearchFirstVisible","rightEdge","endCol","i","visibleColumns","low","high","mid","shouldVirtualize","threshold","autoEnable","ColumnVirtualizationPlugin","isVirtualized","viewport","shadowRoot","leftPadding","headerRow","bodyRows","row","rowsContainer","event","columnIndex","gridEl"],"mappings":"AA6MO,MAAeA,EAAkC;AAAA;AAAA,EAK7C,UAAkB;AAAA;AAAA,EAGlB;AAAA;AAAA,EAGA;AAAA;AAAA,EAGA;AAAA;AAAA,EAGA;AAAA;AAAA,EAGC;AAAA;AAAA,EAGA;AAAA;AAAA,EAGO;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,EAOjB,IAAc,gBAAkC;AAC9C,WAAO,CAAA;AAAA,EACT;AAAA,EAEA,YAAYC,IAA2B,IAAI;AACzC,SAAK,aAAaA;AAAA,EACpB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,OAAOC,GAAyB;AAC9B,SAAK,OAAOA,GAEZ,KAAK,SAAS,EAAE,GAAG,KAAK,eAAe,GAAG,KAAK,WAAA;AAAA,EACjD;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,SAAe;AAAA,EAEf;AAAA;AAAA;AAAA;AAAA;AAAA,EAMU,UAAoCC,GAAuD;AACnG,WAAO,KAAK,MAAM,UAAUA,CAAW;AAAA,EACzC;AAAA;AAAA;AAAA;AAAA,EAKU,KAAQC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EpB,IAAAA,EAAO,aAAajC;AAAA,EACtB;AAAA;AAAA;AAAA;AAAA;AAAA,EAMA,gBAAgBgC,GAA6B;AAC3C,WAAO,KAAK,cAAcA,CAAW,KAAK;AAAA,EAC5C;AAAA;AAAA;AAAA;AAAA,EAKA,gBAAwB;AACtB,WAAO,KAAK;AAAA,EACd;AACF;"}
|
|
@@ -0,0 +1,341 @@
|
|
|
1
|
+
class v {
|
|
2
|
+
/** Plugin version - override in subclass if needed */
|
|
3
|
+
version = "1.0.0";
|
|
4
|
+
/** CSS styles to inject into the grid's shadow DOM */
|
|
5
|
+
styles;
|
|
6
|
+
/** Custom cell renderers keyed by type name */
|
|
7
|
+
cellRenderers;
|
|
8
|
+
/** Custom header renderers keyed by type name */
|
|
9
|
+
headerRenderers;
|
|
10
|
+
/** Custom cell editors keyed by type name */
|
|
11
|
+
cellEditors;
|
|
12
|
+
/** The grid instance this plugin is attached to */
|
|
13
|
+
grid;
|
|
14
|
+
/** Plugin configuration - merged with defaults in attach() */
|
|
15
|
+
config;
|
|
16
|
+
/** User-provided configuration from constructor */
|
|
17
|
+
userConfig;
|
|
18
|
+
/**
|
|
19
|
+
* Default configuration - subclasses should override this getter.
|
|
20
|
+
* Note: This must be a getter (not property initializer) for proper inheritance
|
|
21
|
+
* since property initializers run after parent constructor.
|
|
22
|
+
*/
|
|
23
|
+
get defaultConfig() {
|
|
24
|
+
return {};
|
|
25
|
+
}
|
|
26
|
+
constructor(e = {}) {
|
|
27
|
+
this.userConfig = e;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Called when the plugin is attached to a grid.
|
|
31
|
+
* Override to set up event listeners, initialize state, etc.
|
|
32
|
+
*/
|
|
33
|
+
attach(e) {
|
|
34
|
+
this.grid = e, this.config = { ...this.defaultConfig, ...this.userConfig };
|
|
35
|
+
}
|
|
36
|
+
/**
|
|
37
|
+
* Called when the plugin is detached from a grid.
|
|
38
|
+
* Override to clean up event listeners, timers, etc.
|
|
39
|
+
*/
|
|
40
|
+
detach() {
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* Get another plugin instance from the same grid.
|
|
44
|
+
* Use for inter-plugin communication.
|
|
45
|
+
*/
|
|
46
|
+
getPlugin(e) {
|
|
47
|
+
return this.grid?.getPlugin(e);
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Emit a custom event from the grid.
|
|
51
|
+
*/
|
|
52
|
+
emit(e, l) {
|
|
53
|
+
this.grid?.dispatchEvent?.(new CustomEvent(e, { detail: l, bubbles: !0 }));
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Request a re-render of the grid.
|
|
57
|
+
*/
|
|
58
|
+
requestRender() {
|
|
59
|
+
this.grid?.requestRender?.();
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Request a lightweight style update without rebuilding DOM.
|
|
63
|
+
* Use this instead of requestRender() when only CSS classes need updating.
|
|
64
|
+
*/
|
|
65
|
+
requestAfterRender() {
|
|
66
|
+
this.grid?.requestAfterRender?.();
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Get the current rows from the grid.
|
|
70
|
+
*/
|
|
71
|
+
get rows() {
|
|
72
|
+
return this.grid?.rows ?? [];
|
|
73
|
+
}
|
|
74
|
+
/**
|
|
75
|
+
* Get the original unfiltered/unprocessed rows from the grid.
|
|
76
|
+
* Use this when you need all source data regardless of active filters.
|
|
77
|
+
*/
|
|
78
|
+
get sourceRows() {
|
|
79
|
+
return this.grid?.sourceRows ?? [];
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* Get the current columns from the grid.
|
|
83
|
+
*/
|
|
84
|
+
get columns() {
|
|
85
|
+
return this.grid?.columns ?? [];
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Get only visible columns from the grid (excludes hidden).
|
|
89
|
+
* Use this for rendering that needs to match the grid template.
|
|
90
|
+
*/
|
|
91
|
+
get visibleColumns() {
|
|
92
|
+
return this.grid?.visibleColumns ?? [];
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Get the shadow root of the grid.
|
|
96
|
+
*/
|
|
97
|
+
get shadowRoot() {
|
|
98
|
+
return this.grid?.shadowRoot ?? null;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Log a warning message.
|
|
102
|
+
*/
|
|
103
|
+
warn(e) {
|
|
104
|
+
console.warn(`[tbw-grid:${this.name}] ${e}`);
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
function g(i, e) {
|
|
108
|
+
return (typeof i == "function" ? i(e) : i).filter((n) => !(n.hidden === !0 || typeof n.hidden == "function" && n.hidden(e)));
|
|
109
|
+
}
|
|
110
|
+
function y(i, e) {
|
|
111
|
+
return i.disabled === !0 ? !0 : typeof i.disabled == "function" ? i.disabled(e) : !1;
|
|
112
|
+
}
|
|
113
|
+
function x(i, e, l) {
|
|
114
|
+
const n = document.createElement("div");
|
|
115
|
+
n.className = "tbw-context-menu", n.setAttribute("role", "menu");
|
|
116
|
+
for (const t of i) {
|
|
117
|
+
if (t.separator) {
|
|
118
|
+
const o = document.createElement("div");
|
|
119
|
+
o.className = "tbw-context-menu-separator", o.setAttribute("role", "separator"), n.appendChild(o);
|
|
120
|
+
continue;
|
|
121
|
+
}
|
|
122
|
+
const s = document.createElement("div");
|
|
123
|
+
s.className = "tbw-context-menu-item", t.cssClass && s.classList.add(t.cssClass), s.setAttribute("role", "menuitem"), s.setAttribute("data-id", t.id);
|
|
124
|
+
const r = y(t, e);
|
|
125
|
+
if (r && (s.classList.add("disabled"), s.setAttribute("aria-disabled", "true")), t.icon) {
|
|
126
|
+
const o = document.createElement("span");
|
|
127
|
+
o.className = "tbw-context-menu-icon", o.innerHTML = t.icon, s.appendChild(o);
|
|
128
|
+
}
|
|
129
|
+
const u = document.createElement("span");
|
|
130
|
+
if (u.className = "tbw-context-menu-label", u.textContent = t.name, s.appendChild(u), t.shortcut) {
|
|
131
|
+
const o = document.createElement("span");
|
|
132
|
+
o.className = "tbw-context-menu-shortcut", o.textContent = t.shortcut, s.appendChild(o);
|
|
133
|
+
}
|
|
134
|
+
if (t.subMenu?.length) {
|
|
135
|
+
const o = document.createElement("span");
|
|
136
|
+
o.className = "tbw-context-menu-arrow", o.textContent = "▶", s.appendChild(o), s.addEventListener("mouseenter", () => {
|
|
137
|
+
if (s.querySelector(".tbw-context-menu") || !t.subMenu) return;
|
|
138
|
+
const a = g(t.subMenu, e), d = x(a, e, l);
|
|
139
|
+
d.classList.add("tbw-context-submenu"), d.style.position = "absolute", d.style.left = "100%", d.style.top = "0", s.style.position = "relative", s.appendChild(d);
|
|
140
|
+
}), s.addEventListener("mouseleave", () => {
|
|
141
|
+
const c = s.querySelector(".tbw-context-menu");
|
|
142
|
+
c && c.remove();
|
|
143
|
+
});
|
|
144
|
+
}
|
|
145
|
+
!r && t.action && !t.subMenu && s.addEventListener("click", (o) => {
|
|
146
|
+
o.stopPropagation(), l(t);
|
|
147
|
+
}), n.appendChild(s);
|
|
148
|
+
}
|
|
149
|
+
return n;
|
|
150
|
+
}
|
|
151
|
+
function E(i, e, l) {
|
|
152
|
+
i.style.position = "fixed", i.style.left = `${e}px`, i.style.top = `${l}px`, i.style.visibility = "hidden", i.style.zIndex = "10000";
|
|
153
|
+
const n = i.getBoundingClientRect(), t = window.innerWidth, s = window.innerHeight;
|
|
154
|
+
let r = e, u = l;
|
|
155
|
+
e + n.width > t && (r = e - n.width), l + n.height > s && (u = l - n.height), r = Math.max(0, r), u = Math.max(0, u), i.style.left = `${r}px`, i.style.top = `${u}px`, i.style.visibility = "visible";
|
|
156
|
+
}
|
|
157
|
+
let f = null, p = null, m = null;
|
|
158
|
+
const C = `
|
|
159
|
+
.tbw-context-menu {
|
|
160
|
+
position: fixed;
|
|
161
|
+
background: light-dark(#f5f5f5, #2a2a2a);
|
|
162
|
+
color: light-dark(#222, #eee);
|
|
163
|
+
border: 1px solid light-dark(#d0d0d4, #454545);
|
|
164
|
+
border-radius: 4px;
|
|
165
|
+
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.15);
|
|
166
|
+
min-width: 160px;
|
|
167
|
+
padding: 4px 0;
|
|
168
|
+
z-index: 10000;
|
|
169
|
+
font-size: 13px;
|
|
170
|
+
font-family: system-ui, sans-serif;
|
|
171
|
+
}
|
|
172
|
+
.tbw-context-menu-item {
|
|
173
|
+
display: flex;
|
|
174
|
+
align-items: center;
|
|
175
|
+
padding: 6px 12px;
|
|
176
|
+
cursor: pointer;
|
|
177
|
+
gap: 8px;
|
|
178
|
+
}
|
|
179
|
+
.tbw-context-menu-item:hover:not(.disabled) {
|
|
180
|
+
background: light-dark(#e8e8e8, #3a3a3a);
|
|
181
|
+
}
|
|
182
|
+
.tbw-context-menu-item.disabled {
|
|
183
|
+
opacity: 0.5;
|
|
184
|
+
cursor: default;
|
|
185
|
+
}
|
|
186
|
+
.tbw-context-menu-item.danger {
|
|
187
|
+
color: light-dark(#c00, #f66);
|
|
188
|
+
}
|
|
189
|
+
.tbw-context-menu-icon {
|
|
190
|
+
width: 16px;
|
|
191
|
+
text-align: center;
|
|
192
|
+
}
|
|
193
|
+
.tbw-context-menu-label {
|
|
194
|
+
flex: 1;
|
|
195
|
+
}
|
|
196
|
+
.tbw-context-menu-shortcut {
|
|
197
|
+
color: light-dark(#888, #888);
|
|
198
|
+
font-size: 11px;
|
|
199
|
+
}
|
|
200
|
+
.tbw-context-menu-arrow {
|
|
201
|
+
font-size: 10px;
|
|
202
|
+
color: light-dark(#888, #888);
|
|
203
|
+
}
|
|
204
|
+
.tbw-context-menu-separator {
|
|
205
|
+
height: 1px;
|
|
206
|
+
background: light-dark(#d0d0d4, #454545);
|
|
207
|
+
margin: 4px 0;
|
|
208
|
+
}
|
|
209
|
+
`, b = [
|
|
210
|
+
{
|
|
211
|
+
id: "copy",
|
|
212
|
+
name: "Copy",
|
|
213
|
+
shortcut: "Ctrl+C",
|
|
214
|
+
action: (i) => {
|
|
215
|
+
i.grid?.plugins?.clipboard?.copy?.();
|
|
216
|
+
}
|
|
217
|
+
},
|
|
218
|
+
{ separator: !0, id: "sep1", name: "" },
|
|
219
|
+
{
|
|
220
|
+
id: "export-csv",
|
|
221
|
+
name: "Export CSV",
|
|
222
|
+
action: (i) => {
|
|
223
|
+
i.grid?.plugins?.export?.exportCsv?.();
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
];
|
|
227
|
+
class M extends v {
|
|
228
|
+
name = "contextMenu";
|
|
229
|
+
version = "1.0.0";
|
|
230
|
+
get defaultConfig() {
|
|
231
|
+
return {
|
|
232
|
+
enabled: !0,
|
|
233
|
+
items: b
|
|
234
|
+
};
|
|
235
|
+
}
|
|
236
|
+
// ===== Internal State =====
|
|
237
|
+
isOpen = !1;
|
|
238
|
+
position = { x: 0, y: 0 };
|
|
239
|
+
params = null;
|
|
240
|
+
menuElement = null;
|
|
241
|
+
// ===== Lifecycle =====
|
|
242
|
+
attach(e) {
|
|
243
|
+
super.attach(e), this.installGlobalHandlers();
|
|
244
|
+
}
|
|
245
|
+
detach() {
|
|
246
|
+
this.menuElement && (this.menuElement.remove(), this.menuElement = null), this.isOpen = !1, this.params = null;
|
|
247
|
+
}
|
|
248
|
+
// ===== Private Methods =====
|
|
249
|
+
installGlobalHandlers() {
|
|
250
|
+
!m && typeof document < "u" && (m = document.createElement("style"), m.id = "tbw-context-menu-styles", m.textContent = C, document.head.appendChild(m)), f || (f = () => {
|
|
251
|
+
document.querySelectorAll(".tbw-context-menu").forEach((l) => l.remove());
|
|
252
|
+
}, document.addEventListener("click", f)), p || (p = (e) => {
|
|
253
|
+
e.key === "Escape" && document.querySelectorAll(".tbw-context-menu").forEach((n) => n.remove());
|
|
254
|
+
}, document.addEventListener("keydown", p));
|
|
255
|
+
}
|
|
256
|
+
// ===== Hooks =====
|
|
257
|
+
afterRender() {
|
|
258
|
+
if (!this.config.enabled) return;
|
|
259
|
+
const e = this.shadowRoot;
|
|
260
|
+
if (!e) return;
|
|
261
|
+
const l = e.children[0];
|
|
262
|
+
l && l.getAttribute("data-context-menu-bound") !== "true" && (l.setAttribute("data-context-menu-bound", "true"), l.addEventListener("contextmenu", (n) => {
|
|
263
|
+
if (!this.config.enabled) return;
|
|
264
|
+
const t = n;
|
|
265
|
+
t.preventDefault();
|
|
266
|
+
const s = t.target, r = s.closest("[data-row][data-col]"), u = s.closest(".header-cell");
|
|
267
|
+
let o;
|
|
268
|
+
if (r) {
|
|
269
|
+
const a = parseInt(r.getAttribute("data-row") ?? "-1", 10), d = parseInt(r.getAttribute("data-col") ?? "-1", 10), h = this.columns[d], w = this.rows[a];
|
|
270
|
+
o = {
|
|
271
|
+
row: w,
|
|
272
|
+
rowIndex: a,
|
|
273
|
+
column: h,
|
|
274
|
+
columnIndex: d,
|
|
275
|
+
field: h?.field ?? "",
|
|
276
|
+
value: w?.[h?.field] ?? null,
|
|
277
|
+
isHeader: !1,
|
|
278
|
+
event: t
|
|
279
|
+
};
|
|
280
|
+
} else if (u) {
|
|
281
|
+
const a = parseInt(u.getAttribute("data-col") ?? "-1", 10), d = this.columns[a];
|
|
282
|
+
o = {
|
|
283
|
+
row: null,
|
|
284
|
+
rowIndex: -1,
|
|
285
|
+
column: d,
|
|
286
|
+
columnIndex: a,
|
|
287
|
+
field: d?.field ?? "",
|
|
288
|
+
value: null,
|
|
289
|
+
isHeader: !0,
|
|
290
|
+
event: t
|
|
291
|
+
};
|
|
292
|
+
} else
|
|
293
|
+
return;
|
|
294
|
+
this.params = o, this.position = { x: t.clientX, y: t.clientY };
|
|
295
|
+
const c = g(this.config.items ?? b, o);
|
|
296
|
+
c.length && (this.menuElement && this.menuElement.remove(), this.menuElement = x(c, o, (a) => {
|
|
297
|
+
a.action && a.action(o), this.menuElement?.remove(), this.menuElement = null, this.isOpen = !1;
|
|
298
|
+
}), document.body.appendChild(this.menuElement), E(this.menuElement, t.clientX, t.clientY), this.isOpen = !0, this.emit("context-menu-open", { params: o, items: c }));
|
|
299
|
+
}));
|
|
300
|
+
}
|
|
301
|
+
// ===== Public API =====
|
|
302
|
+
/**
|
|
303
|
+
* Programmatically show the context menu at the specified position.
|
|
304
|
+
* @param x - X coordinate
|
|
305
|
+
* @param y - Y coordinate
|
|
306
|
+
* @param params - Partial context menu parameters
|
|
307
|
+
*/
|
|
308
|
+
showMenu(e, l, n) {
|
|
309
|
+
const t = {
|
|
310
|
+
row: n.row ?? null,
|
|
311
|
+
rowIndex: n.rowIndex ?? -1,
|
|
312
|
+
column: n.column ?? null,
|
|
313
|
+
columnIndex: n.columnIndex ?? -1,
|
|
314
|
+
field: n.field ?? "",
|
|
315
|
+
value: n.value ?? null,
|
|
316
|
+
isHeader: n.isHeader ?? !1,
|
|
317
|
+
event: n.event ?? new MouseEvent("contextmenu")
|
|
318
|
+
}, s = g(this.config.items ?? b, t);
|
|
319
|
+
this.menuElement && this.menuElement.remove(), this.menuElement = x(s, t, (r) => {
|
|
320
|
+
r.action && r.action(t), this.menuElement?.remove(), this.menuElement = null, this.isOpen = !1;
|
|
321
|
+
}), document.body.appendChild(this.menuElement), E(this.menuElement, e, l), this.isOpen = !0;
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Hide the context menu.
|
|
325
|
+
*/
|
|
326
|
+
hideMenu() {
|
|
327
|
+
this.menuElement && (this.menuElement.remove(), this.menuElement = null, this.isOpen = !1);
|
|
328
|
+
}
|
|
329
|
+
/**
|
|
330
|
+
* Check if the context menu is currently open.
|
|
331
|
+
* @returns Whether the menu is open
|
|
332
|
+
*/
|
|
333
|
+
isMenuOpen() {
|
|
334
|
+
return this.isOpen;
|
|
335
|
+
}
|
|
336
|
+
// Styles are injected globally via installGlobalHandlers() since menu renders in document.body
|
|
337
|
+
}
|
|
338
|
+
export {
|
|
339
|
+
M as ContextMenuPlugin
|
|
340
|
+
};
|
|
341
|
+
//# sourceMappingURL=index.js.map
|