@ornery/ui-grid-vanilla 0.1.7-hotfix
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/demo/index.html +79 -0
- package/demo/main.ts +68 -0
- package/dist/index.d.mts +206 -0
- package/dist/index.d.ts +206 -0
- package/dist/index.js +1456 -0
- package/dist/index.mjs +1495 -0
- package/package.json +33 -0
- package/src/grid-controller.ts +906 -0
- package/src/index.integration.test.ts +245 -0
- package/src/index.test.ts +52 -0
- package/src/index.ts +60 -0
- package/src/ui-grid-standalone.element.ts +972 -0
- package/tsconfig.json +13 -0
- package/vite.config.ts +23 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,1456 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var index_exports = {};
|
|
22
|
+
__export(index_exports, {
|
|
23
|
+
UiGridStandaloneElement: () => UiGridStandaloneElement,
|
|
24
|
+
createVanillaGridController: () => createVanillaGridController,
|
|
25
|
+
defineStandaloneUiGridElement: () => defineStandaloneUiGridElement,
|
|
26
|
+
defineUiGridElement: () => defineStandaloneUiGridElement,
|
|
27
|
+
mountVanillaUiGrid: () => mountVanillaUiGrid,
|
|
28
|
+
registerVanillaUiGridRustModule: () => registerVanillaUiGridRustModule
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(index_exports);
|
|
31
|
+
var import_ui_grid_core3 = require("@ornery/ui-grid-core");
|
|
32
|
+
|
|
33
|
+
// src/ui-grid-standalone.element.ts
|
|
34
|
+
var import_ui_grid_core2 = require("@ornery/ui-grid-core");
|
|
35
|
+
|
|
36
|
+
// src/grid-controller.ts
|
|
37
|
+
var import_ui_grid_core = require("@ornery/ui-grid-core");
|
|
38
|
+
function orderVisibleColumns(columns, order) {
|
|
39
|
+
return [...columns].filter((column) => column.visible !== false).sort((left, right) => order.indexOf(left.name) - order.indexOf(right.name));
|
|
40
|
+
}
|
|
41
|
+
function buildGridTemplateColumns(columns) {
|
|
42
|
+
return columns.map((column) => (0, import_ui_grid_core.gridColumnWidth)(column)).join(" ");
|
|
43
|
+
}
|
|
44
|
+
var VanillaGridController = class {
|
|
45
|
+
options;
|
|
46
|
+
activeFilters = {};
|
|
47
|
+
sortState = {
|
|
48
|
+
columnName: null,
|
|
49
|
+
direction: import_ui_grid_core.SORT_DIRECTIONS.none
|
|
50
|
+
};
|
|
51
|
+
groupByColumns = [];
|
|
52
|
+
collapsedGroups = {};
|
|
53
|
+
hiddenRowReasons = {};
|
|
54
|
+
expandedRows = {};
|
|
55
|
+
expandedTreeRows = {};
|
|
56
|
+
pinnedColumns = {};
|
|
57
|
+
columnOrder = [];
|
|
58
|
+
currentPage = 1;
|
|
59
|
+
pageSize = 0;
|
|
60
|
+
editingCell = null;
|
|
61
|
+
editingValue = "";
|
|
62
|
+
pipeline;
|
|
63
|
+
labels;
|
|
64
|
+
visibleColumns = [];
|
|
65
|
+
apiRegistered = false;
|
|
66
|
+
subscribers = /* @__PURE__ */ new Set();
|
|
67
|
+
gridApi;
|
|
68
|
+
constructor(options) {
|
|
69
|
+
this.options = options;
|
|
70
|
+
this.labels = (0, import_ui_grid_core.resolveGridLabels)(options.labels);
|
|
71
|
+
this.columnOrder = options.columnDefs.map((column) => column.name);
|
|
72
|
+
this.pipeline = {
|
|
73
|
+
visibleRows: [],
|
|
74
|
+
displayItems: [],
|
|
75
|
+
virtualizationEnabled: false,
|
|
76
|
+
pipelineMs: 0,
|
|
77
|
+
totalItems: 0
|
|
78
|
+
};
|
|
79
|
+
this.gridApi = (0, import_ui_grid_core.createGridApi)({
|
|
80
|
+
refresh: () => this.refresh(),
|
|
81
|
+
getVisibleRows: () => this.pipeline.visibleRows,
|
|
82
|
+
setRowInvisible: (row, reason) => this.setRowInvisible(row, reason),
|
|
83
|
+
clearRowInvisible: (row, reason) => this.clearRowInvisible(row, reason),
|
|
84
|
+
setFilter: (columnName, value) => this.setFilter(columnName, value),
|
|
85
|
+
clearAllFilters: () => this.clearAllFilters(),
|
|
86
|
+
sortColumn: (columnName, direction) => this.sortColumn(columnName, direction),
|
|
87
|
+
moveColumn: (fromIndex, toIndex) => {
|
|
88
|
+
const visibleNames = this.visibleColumns.map((column) => column.name);
|
|
89
|
+
const source = visibleNames[fromIndex];
|
|
90
|
+
const target = visibleNames[toIndex];
|
|
91
|
+
if (source && target) {
|
|
92
|
+
this.moveVisibleColumn(source, target);
|
|
93
|
+
}
|
|
94
|
+
},
|
|
95
|
+
pinColumn: (columnName, direction) => this.pinColumn(columnName, direction),
|
|
96
|
+
toggleGrouping: (columnName) => this.toggleGrouping(columnName),
|
|
97
|
+
clearGrouping: () => this.clearGrouping(),
|
|
98
|
+
benchmark: (iterations) => this.benchmark(iterations),
|
|
99
|
+
exportCsv: () => {
|
|
100
|
+
},
|
|
101
|
+
paginationGetPage: () => this.getCurrentPage(),
|
|
102
|
+
paginationGetTotalPages: () => this.getTotalPages(),
|
|
103
|
+
paginationGetFirstRowIndex: () => this.getFirstRowIndex(),
|
|
104
|
+
paginationGetLastRowIndex: () => this.getLastRowIndex(),
|
|
105
|
+
paginationNextPage: () => this.seekPage(this.currentPage + 1),
|
|
106
|
+
paginationPreviousPage: () => this.seekPage(this.currentPage - 1),
|
|
107
|
+
paginationSeek: (page) => this.seekPage(page),
|
|
108
|
+
paginationSetPageSize: (pageSize) => this.setPageSize(pageSize),
|
|
109
|
+
toggleRowExpansion: (row) => this.toggleRowExpansion(row),
|
|
110
|
+
expandAllRows: () => this.expandAllRows(),
|
|
111
|
+
collapseAllRows: () => this.collapseAllRows(),
|
|
112
|
+
toggleAllRows: () => {
|
|
113
|
+
if (Object.keys(this.expandedRows).length > 0) {
|
|
114
|
+
this.collapseAllRows();
|
|
115
|
+
return;
|
|
116
|
+
}
|
|
117
|
+
this.expandAllRows();
|
|
118
|
+
},
|
|
119
|
+
treeToggleRow: (row) => this.toggleTreeRow(row),
|
|
120
|
+
treeExpandAllRows: () => this.expandAllTreeRows(),
|
|
121
|
+
treeCollapseAllRows: () => this.collapseAllTreeRows(),
|
|
122
|
+
treeExpandRow: (row) => this.setTreeRowExpanded(row, true),
|
|
123
|
+
treeCollapseRow: (row) => this.setTreeRowExpanded(row, false),
|
|
124
|
+
treeGetRowChildren: (row) => {
|
|
125
|
+
const rowId = this.resolveRowId(row);
|
|
126
|
+
return this.pipeline.visibleRows.filter((candidate) => candidate.parentId === rowId);
|
|
127
|
+
},
|
|
128
|
+
treeGetState: () => ({ ...this.expandedTreeRows }),
|
|
129
|
+
treeSetState: (state) => {
|
|
130
|
+
this.expandedTreeRows = { ...state };
|
|
131
|
+
this.refresh();
|
|
132
|
+
},
|
|
133
|
+
beginCellEdit: (row, columnName, triggerEvent) => this.beginCellEdit(row, columnName, triggerEvent),
|
|
134
|
+
endCellEdit: () => {
|
|
135
|
+
this.commitCellEdit();
|
|
136
|
+
},
|
|
137
|
+
cancelCellEdit: () => {
|
|
138
|
+
this.cancelCellEdit();
|
|
139
|
+
},
|
|
140
|
+
getEditingCell: () => this.editingCell
|
|
141
|
+
});
|
|
142
|
+
this.refresh();
|
|
143
|
+
}
|
|
144
|
+
setOptions(options) {
|
|
145
|
+
this.options = options;
|
|
146
|
+
this.labels = (0, import_ui_grid_core.resolveGridLabels)(options.labels);
|
|
147
|
+
if (this.columnOrder.length === 0) {
|
|
148
|
+
this.columnOrder = options.columnDefs.map((column) => column.name);
|
|
149
|
+
} else {
|
|
150
|
+
const names = new Set(options.columnDefs.map((column) => column.name));
|
|
151
|
+
this.columnOrder = this.columnOrder.filter((name) => names.has(name));
|
|
152
|
+
for (const column of options.columnDefs) {
|
|
153
|
+
if (!this.columnOrder.includes(column.name)) {
|
|
154
|
+
this.columnOrder.push(column.name);
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
this.apiRegistered = false;
|
|
159
|
+
this.refresh();
|
|
160
|
+
}
|
|
161
|
+
subscribe(subscriber) {
|
|
162
|
+
this.subscribers.add(subscriber);
|
|
163
|
+
subscriber(this.getSnapshot());
|
|
164
|
+
return () => {
|
|
165
|
+
this.subscribers.delete(subscriber);
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
getSnapshot() {
|
|
169
|
+
const totalPages = this.getTotalPages();
|
|
170
|
+
return {
|
|
171
|
+
options: this.options,
|
|
172
|
+
labels: this.labels,
|
|
173
|
+
rowSize: this.getRowSize(),
|
|
174
|
+
visibleColumns: this.visibleColumns,
|
|
175
|
+
gridTemplateColumns: buildGridTemplateColumns(this.visibleColumns),
|
|
176
|
+
pipeline: this.pipeline,
|
|
177
|
+
activeFilters: this.activeFilters,
|
|
178
|
+
sortState: this.sortState,
|
|
179
|
+
groupByColumns: this.groupByColumns,
|
|
180
|
+
pinnedColumns: this.pinnedColumns,
|
|
181
|
+
currentPage: this.getCurrentPage(),
|
|
182
|
+
totalPages,
|
|
183
|
+
firstRowIndex: this.getFirstRowIndex(),
|
|
184
|
+
lastRowIndex: this.getLastRowIndex(),
|
|
185
|
+
pageSize: this.getEffectivePageSize(),
|
|
186
|
+
editingCell: this.editingCell,
|
|
187
|
+
editingValue: this.editingValue
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
getDisplayItems() {
|
|
191
|
+
return this.pipeline.displayItems;
|
|
192
|
+
}
|
|
193
|
+
setCollapsedGroup(groupId, collapsed) {
|
|
194
|
+
this.collapsedGroups = {
|
|
195
|
+
...this.collapsedGroups,
|
|
196
|
+
[groupId]: collapsed
|
|
197
|
+
};
|
|
198
|
+
this.refresh();
|
|
199
|
+
}
|
|
200
|
+
toggleSort(columnName) {
|
|
201
|
+
const current = this.sortState.columnName === columnName ? this.sortState.direction : import_ui_grid_core.SORT_DIRECTIONS.none;
|
|
202
|
+
if (current === import_ui_grid_core.SORT_DIRECTIONS.none) {
|
|
203
|
+
this.sortColumn(columnName, import_ui_grid_core.SORT_DIRECTIONS.asc);
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
if (current === import_ui_grid_core.SORT_DIRECTIONS.asc) {
|
|
207
|
+
this.sortColumn(columnName, import_ui_grid_core.SORT_DIRECTIONS.desc);
|
|
208
|
+
return;
|
|
209
|
+
}
|
|
210
|
+
this.sortColumn(columnName, import_ui_grid_core.SORT_DIRECTIONS.none);
|
|
211
|
+
}
|
|
212
|
+
sortColumn(columnName, direction = import_ui_grid_core.SORT_DIRECTIONS.none) {
|
|
213
|
+
(0, import_ui_grid_core.sortGridColumnCommand)(
|
|
214
|
+
this.gridApi,
|
|
215
|
+
(next) => {
|
|
216
|
+
this.sortState = next;
|
|
217
|
+
},
|
|
218
|
+
columnName,
|
|
219
|
+
direction
|
|
220
|
+
);
|
|
221
|
+
this.refresh();
|
|
222
|
+
}
|
|
223
|
+
setFilter(columnName, value) {
|
|
224
|
+
(0, import_ui_grid_core.updateGridFilterCommand)(
|
|
225
|
+
this.gridApi,
|
|
226
|
+
(updater) => {
|
|
227
|
+
this.activeFilters = updater(this.activeFilters);
|
|
228
|
+
},
|
|
229
|
+
() => this.activeFilters,
|
|
230
|
+
columnName,
|
|
231
|
+
value
|
|
232
|
+
);
|
|
233
|
+
this.currentPage = 1;
|
|
234
|
+
this.refresh();
|
|
235
|
+
}
|
|
236
|
+
clearAllFilters() {
|
|
237
|
+
(0, import_ui_grid_core.clearGridFiltersCommand)(this.gridApi, (next) => {
|
|
238
|
+
this.activeFilters = next;
|
|
239
|
+
});
|
|
240
|
+
this.currentPage = 1;
|
|
241
|
+
this.refresh();
|
|
242
|
+
}
|
|
243
|
+
toggleGrouping(columnName) {
|
|
244
|
+
(0, import_ui_grid_core.toggleGridGroupingCommand)(
|
|
245
|
+
this.gridApi,
|
|
246
|
+
(0, import_ui_grid_core.isGridGroupingEnabled)(this.options),
|
|
247
|
+
(updater) => {
|
|
248
|
+
this.groupByColumns = updater(this.groupByColumns);
|
|
249
|
+
},
|
|
250
|
+
() => this.groupByColumns,
|
|
251
|
+
columnName
|
|
252
|
+
);
|
|
253
|
+
this.refresh();
|
|
254
|
+
}
|
|
255
|
+
clearGrouping() {
|
|
256
|
+
(0, import_ui_grid_core.clearGridGroupingCommand)(this.gridApi, (next) => {
|
|
257
|
+
this.groupByColumns = next;
|
|
258
|
+
});
|
|
259
|
+
this.refresh();
|
|
260
|
+
}
|
|
261
|
+
seekPage(page) {
|
|
262
|
+
(0, import_ui_grid_core.seekGridPaginationCommand)(
|
|
263
|
+
this.gridApi,
|
|
264
|
+
(next) => {
|
|
265
|
+
this.currentPage = next;
|
|
266
|
+
},
|
|
267
|
+
() => this.getTotalPages(),
|
|
268
|
+
() => this.getEffectivePageSize(),
|
|
269
|
+
page
|
|
270
|
+
);
|
|
271
|
+
this.refresh();
|
|
272
|
+
}
|
|
273
|
+
setPageSize(pageSize) {
|
|
274
|
+
(0, import_ui_grid_core.setGridPaginationPageSizeCommand)(
|
|
275
|
+
this.gridApi,
|
|
276
|
+
(next) => {
|
|
277
|
+
this.pageSize = next;
|
|
278
|
+
},
|
|
279
|
+
(next) => {
|
|
280
|
+
this.currentPage = next;
|
|
281
|
+
},
|
|
282
|
+
pageSize
|
|
283
|
+
);
|
|
284
|
+
this.refresh();
|
|
285
|
+
}
|
|
286
|
+
pinColumn(columnName, direction) {
|
|
287
|
+
(0, import_ui_grid_core.pinGridColumnCommand)(
|
|
288
|
+
this.gridApi,
|
|
289
|
+
(0, import_ui_grid_core.isPinningEnabled)(this.options),
|
|
290
|
+
(next) => {
|
|
291
|
+
this.pinnedColumns = next;
|
|
292
|
+
},
|
|
293
|
+
() => this.pinnedColumns,
|
|
294
|
+
columnName,
|
|
295
|
+
direction
|
|
296
|
+
);
|
|
297
|
+
this.refresh();
|
|
298
|
+
}
|
|
299
|
+
moveVisibleColumn(columnName, targetColumnName) {
|
|
300
|
+
(0, import_ui_grid_core.moveGridVisibleColumnCommand)(
|
|
301
|
+
this.gridApi,
|
|
302
|
+
(0, import_ui_grid_core.canGridMoveColumns)(this.options),
|
|
303
|
+
this.columnOrder,
|
|
304
|
+
this.visibleColumns.map((column) => column.name),
|
|
305
|
+
columnName,
|
|
306
|
+
targetColumnName,
|
|
307
|
+
(next) => {
|
|
308
|
+
this.columnOrder = next;
|
|
309
|
+
}
|
|
310
|
+
);
|
|
311
|
+
this.refresh();
|
|
312
|
+
}
|
|
313
|
+
toggleRowExpansion(row) {
|
|
314
|
+
const rowId = this.resolveRowId(row);
|
|
315
|
+
(0, import_ui_grid_core.toggleGridRowExpansionCommand)(
|
|
316
|
+
this.gridApi,
|
|
317
|
+
(0, import_ui_grid_core.canGridExpandRows)(this.options),
|
|
318
|
+
this.expandedRows,
|
|
319
|
+
rowId,
|
|
320
|
+
(next) => {
|
|
321
|
+
this.expandedRows = next;
|
|
322
|
+
},
|
|
323
|
+
(candidateRowId) => this.findRowById(candidateRowId)
|
|
324
|
+
);
|
|
325
|
+
this.refresh();
|
|
326
|
+
}
|
|
327
|
+
expandAllRows() {
|
|
328
|
+
(0, import_ui_grid_core.expandAllGridRowsCommand)(
|
|
329
|
+
(data) => this.buildRowsFromData(data),
|
|
330
|
+
this.options.data,
|
|
331
|
+
(next) => {
|
|
332
|
+
this.expandedRows = next;
|
|
333
|
+
}
|
|
334
|
+
);
|
|
335
|
+
this.refresh();
|
|
336
|
+
}
|
|
337
|
+
collapseAllRows() {
|
|
338
|
+
this.expandedRows = {};
|
|
339
|
+
this.refresh();
|
|
340
|
+
}
|
|
341
|
+
toggleTreeRow(row) {
|
|
342
|
+
const rowId = this.resolveRowId(row);
|
|
343
|
+
(0, import_ui_grid_core.toggleGridTreeRowCommand)(
|
|
344
|
+
this.gridApi,
|
|
345
|
+
this.expandedTreeRows,
|
|
346
|
+
rowId,
|
|
347
|
+
(next) => {
|
|
348
|
+
this.expandedTreeRows = next;
|
|
349
|
+
},
|
|
350
|
+
(candidateRowId) => this.findRowById(candidateRowId)
|
|
351
|
+
);
|
|
352
|
+
this.refresh();
|
|
353
|
+
}
|
|
354
|
+
expandAllTreeRows() {
|
|
355
|
+
(0, import_ui_grid_core.expandAllGridTreeRowsCommand)(
|
|
356
|
+
(data) => this.buildRowsFromData(data),
|
|
357
|
+
this.options.data,
|
|
358
|
+
(next) => {
|
|
359
|
+
this.expandedTreeRows = next;
|
|
360
|
+
}
|
|
361
|
+
);
|
|
362
|
+
this.refresh();
|
|
363
|
+
}
|
|
364
|
+
collapseAllTreeRows() {
|
|
365
|
+
this.expandedTreeRows = {};
|
|
366
|
+
this.refresh();
|
|
367
|
+
}
|
|
368
|
+
setTreeRowExpanded(row, expanded) {
|
|
369
|
+
const rowId = this.resolveRowId(row);
|
|
370
|
+
if (expanded) {
|
|
371
|
+
this.expandedTreeRows = {
|
|
372
|
+
...this.expandedTreeRows,
|
|
373
|
+
[rowId]: true
|
|
374
|
+
};
|
|
375
|
+
} else {
|
|
376
|
+
const nextState = { ...this.expandedTreeRows };
|
|
377
|
+
delete nextState[rowId];
|
|
378
|
+
this.expandedTreeRows = nextState;
|
|
379
|
+
}
|
|
380
|
+
this.refresh();
|
|
381
|
+
}
|
|
382
|
+
beginCellEdit(row, columnName, triggerEvent) {
|
|
383
|
+
const rowId = this.resolveRowId(row);
|
|
384
|
+
const gridRow = this.findRowById(rowId);
|
|
385
|
+
const column = this.findColumnByName(columnName);
|
|
386
|
+
if (!gridRow || !column) {
|
|
387
|
+
return;
|
|
388
|
+
}
|
|
389
|
+
(0, import_ui_grid_core.beginGridCellEditCommand)(
|
|
390
|
+
this.gridApi,
|
|
391
|
+
{
|
|
392
|
+
setFocusedCell: () => {
|
|
393
|
+
},
|
|
394
|
+
setEditingCell: (next) => {
|
|
395
|
+
this.editingCell = next;
|
|
396
|
+
},
|
|
397
|
+
setEditingValue: (next) => {
|
|
398
|
+
this.editingValue = next;
|
|
399
|
+
}
|
|
400
|
+
},
|
|
401
|
+
gridRow,
|
|
402
|
+
column,
|
|
403
|
+
(0, import_ui_grid_core.getCellValue)(gridRow.entity, column),
|
|
404
|
+
triggerEvent
|
|
405
|
+
);
|
|
406
|
+
this.refresh();
|
|
407
|
+
}
|
|
408
|
+
updateEditingValue(value) {
|
|
409
|
+
this.editingValue = value;
|
|
410
|
+
this.emit();
|
|
411
|
+
}
|
|
412
|
+
commitCellEdit() {
|
|
413
|
+
(0, import_ui_grid_core.commitGridCellEditCommand)(this.gridApi, {
|
|
414
|
+
getEditingCell: () => this.editingCell,
|
|
415
|
+
getEditingValue: () => this.editingValue,
|
|
416
|
+
setEditingCell: (next) => {
|
|
417
|
+
this.editingCell = next;
|
|
418
|
+
},
|
|
419
|
+
setEditingValue: (next) => {
|
|
420
|
+
this.editingValue = next;
|
|
421
|
+
},
|
|
422
|
+
findRowById: (rowId) => this.findRowById(rowId),
|
|
423
|
+
findColumnByName: (columnName) => this.findColumnByName(columnName),
|
|
424
|
+
parseEditedValue: (column, value, oldValue) => (0, import_ui_grid_core.parseGridEditedValue)(column, value, oldValue),
|
|
425
|
+
setCellValue: (rowEntity, column, value) => (0, import_ui_grid_core.setPathValue)(rowEntity, column.field ?? column.name, value)
|
|
426
|
+
});
|
|
427
|
+
this.refresh();
|
|
428
|
+
}
|
|
429
|
+
cancelCellEdit() {
|
|
430
|
+
(0, import_ui_grid_core.cancelGridCellEditCommand)(this.gridApi, {
|
|
431
|
+
getEditingCell: () => this.editingCell,
|
|
432
|
+
setEditingCell: (next) => {
|
|
433
|
+
this.editingCell = next;
|
|
434
|
+
},
|
|
435
|
+
setEditingValue: (next) => {
|
|
436
|
+
this.editingValue = next;
|
|
437
|
+
},
|
|
438
|
+
findRowById: (rowId) => this.findRowById(rowId),
|
|
439
|
+
findColumnByName: (columnName) => this.findColumnByName(columnName)
|
|
440
|
+
});
|
|
441
|
+
this.refresh();
|
|
442
|
+
}
|
|
443
|
+
isGroupingEnabled() {
|
|
444
|
+
return (0, import_ui_grid_core.isGridGroupingEnabled)(this.options);
|
|
445
|
+
}
|
|
446
|
+
isSortingEnabled() {
|
|
447
|
+
return (0, import_ui_grid_core.isGridSortingEnabled)(this.options);
|
|
448
|
+
}
|
|
449
|
+
isFilteringEnabled() {
|
|
450
|
+
return (0, import_ui_grid_core.isGridFilteringEnabled)(this.options);
|
|
451
|
+
}
|
|
452
|
+
isPaginationEnabled() {
|
|
453
|
+
return (0, import_ui_grid_core.isGridPaginationEnabled)(this.options);
|
|
454
|
+
}
|
|
455
|
+
shouldShowPaginationControls() {
|
|
456
|
+
return (0, import_ui_grid_core.shouldShowGridPaginationControls)(this.options);
|
|
457
|
+
}
|
|
458
|
+
isTreeEnabled() {
|
|
459
|
+
return (0, import_ui_grid_core.isGridTreeEnabled)(this.options);
|
|
460
|
+
}
|
|
461
|
+
isExpandableEnabled() {
|
|
462
|
+
return (0, import_ui_grid_core.canGridExpandRows)(this.options);
|
|
463
|
+
}
|
|
464
|
+
isColumnSortable(column) {
|
|
465
|
+
return (0, import_ui_grid_core.isGridColumnSortable)(this.options, column);
|
|
466
|
+
}
|
|
467
|
+
isColumnFilterable(column) {
|
|
468
|
+
return (0, import_ui_grid_core.isGridColumnFilterable)(this.options, column);
|
|
469
|
+
}
|
|
470
|
+
isColumnGrouped(column) {
|
|
471
|
+
return (0, import_ui_grid_core.isGridColumnGrouped)(this.groupByColumns, column);
|
|
472
|
+
}
|
|
473
|
+
sortButtonLabel(column) {
|
|
474
|
+
return (0, import_ui_grid_core.gridSortButtonLabel)(this.getSortDirection(column), this.labels);
|
|
475
|
+
}
|
|
476
|
+
groupingButtonLabel(column) {
|
|
477
|
+
return (0, import_ui_grid_core.gridGroupingButtonLabel)(this.isColumnGrouped(column), this.labels);
|
|
478
|
+
}
|
|
479
|
+
filterPlaceholder(column) {
|
|
480
|
+
return (0, import_ui_grid_core.gridFilterPlaceholder)(this.isColumnFilterable(column), this.labels);
|
|
481
|
+
}
|
|
482
|
+
getSortDirection(column) {
|
|
483
|
+
return this.sortState.columnName === column.name ? this.sortState.direction : import_ui_grid_core.SORT_DIRECTIONS.none;
|
|
484
|
+
}
|
|
485
|
+
isPinningEnabled() {
|
|
486
|
+
return (0, import_ui_grid_core.isPinningEnabled)(this.options);
|
|
487
|
+
}
|
|
488
|
+
isColumnPinnable(column) {
|
|
489
|
+
return (0, import_ui_grid_core.isColumnPinnable)(this.options, column);
|
|
490
|
+
}
|
|
491
|
+
isPinned(column) {
|
|
492
|
+
return this.pinnedColumns[column.name] !== void 0;
|
|
493
|
+
}
|
|
494
|
+
isPinnedLeftLast(column) {
|
|
495
|
+
const leftPinned = this.visibleColumns.filter((c) => this.pinnedColumns[c.name] === "left");
|
|
496
|
+
return leftPinned.length > 0 && leftPinned[leftPinned.length - 1].name === column.name;
|
|
497
|
+
}
|
|
498
|
+
isPinnedRightFirst(column) {
|
|
499
|
+
const rightPinned = this.visibleColumns.filter((c) => this.pinnedColumns[c.name] === "right");
|
|
500
|
+
return rightPinned.length > 0 && rightPinned[0].name === column.name;
|
|
501
|
+
}
|
|
502
|
+
groupDisclosureLabel(group) {
|
|
503
|
+
return (0, import_ui_grid_core.gridGroupDisclosureLabel)(group.collapsed, this.labels);
|
|
504
|
+
}
|
|
505
|
+
pinnedOffset(column) {
|
|
506
|
+
return (0, import_ui_grid_core.computePinnedOffset)(this.visibleColumns, this.pinnedColumns, column);
|
|
507
|
+
}
|
|
508
|
+
displayValue(row, column) {
|
|
509
|
+
return (0, import_ui_grid_core.formatGridCellDisplayValue)((0, import_ui_grid_core.buildGridCellContext)(row, column));
|
|
510
|
+
}
|
|
511
|
+
headerLabel(column) {
|
|
512
|
+
return (0, import_ui_grid_core.headerLabel)(column);
|
|
513
|
+
}
|
|
514
|
+
cellIndent(row, column) {
|
|
515
|
+
return (0, import_ui_grid_core.gridCellIndent)(this.options, this.visibleColumns, row, column);
|
|
516
|
+
}
|
|
517
|
+
showTreeToggle(row, column) {
|
|
518
|
+
return (0, import_ui_grid_core.shouldShowGridTreeToggle)(this.options, this.visibleColumns, row, column);
|
|
519
|
+
}
|
|
520
|
+
showExpandToggle(_row, column) {
|
|
521
|
+
return (0, import_ui_grid_core.shouldShowGridExpandToggle)(this.options, this.visibleColumns, column);
|
|
522
|
+
}
|
|
523
|
+
isTreeRowExpanded(row) {
|
|
524
|
+
return (0, import_ui_grid_core.isGridTreeRowExpanded)(this.expandedTreeRows, row);
|
|
525
|
+
}
|
|
526
|
+
treeToggleLabel(row) {
|
|
527
|
+
return (0, import_ui_grid_core.gridTreeToggleLabelForRow)(this.expandedTreeRows, row, this.labels);
|
|
528
|
+
}
|
|
529
|
+
expandToggleLabel(row) {
|
|
530
|
+
return (0, import_ui_grid_core.gridExpandToggleLabelForRow)(row, this.labels);
|
|
531
|
+
}
|
|
532
|
+
editorInputType(column) {
|
|
533
|
+
return (0, import_ui_grid_core.gridEditorInputType)(column);
|
|
534
|
+
}
|
|
535
|
+
isEditingCell(rowId, columnName) {
|
|
536
|
+
return this.editingCell?.rowId === rowId && this.editingCell?.columnName === columnName;
|
|
537
|
+
}
|
|
538
|
+
getState() {
|
|
539
|
+
return {
|
|
540
|
+
sortState: { ...this.sortState },
|
|
541
|
+
activeFilters: { ...this.activeFilters },
|
|
542
|
+
groupByColumns: [...this.groupByColumns],
|
|
543
|
+
pinnedColumns: { ...this.pinnedColumns },
|
|
544
|
+
columnOrder: [...this.columnOrder],
|
|
545
|
+
currentPage: this.currentPage,
|
|
546
|
+
pageSize: this.pageSize
|
|
547
|
+
};
|
|
548
|
+
}
|
|
549
|
+
setState(state) {
|
|
550
|
+
if (state.sortState !== void 0) this.sortState = { ...state.sortState };
|
|
551
|
+
if (state.activeFilters !== void 0) this.activeFilters = { ...state.activeFilters };
|
|
552
|
+
if (state.groupByColumns !== void 0) this.groupByColumns = [...state.groupByColumns];
|
|
553
|
+
if (state.pinnedColumns !== void 0) this.pinnedColumns = { ...state.pinnedColumns };
|
|
554
|
+
if (state.columnOrder !== void 0) this.columnOrder = [...state.columnOrder];
|
|
555
|
+
if (state.currentPage !== void 0) this.currentPage = state.currentPage;
|
|
556
|
+
if (state.pageSize !== void 0) this.pageSize = state.pageSize;
|
|
557
|
+
this.refresh();
|
|
558
|
+
}
|
|
559
|
+
refresh() {
|
|
560
|
+
const orderedColumns = orderVisibleColumns(this.options.columnDefs, this.columnOrder);
|
|
561
|
+
const pinnedEntries = Object.entries(this.pinnedColumns);
|
|
562
|
+
if (pinnedEntries.length === 0) {
|
|
563
|
+
this.visibleColumns = orderedColumns;
|
|
564
|
+
} else {
|
|
565
|
+
const byName = new Map(orderedColumns.map((column) => [column.name, column]));
|
|
566
|
+
const pinnedLeft = pinnedEntries.filter((entry) => entry[1] === "left").map((entry) => byName.get(entry[0])).filter((column) => column !== void 0);
|
|
567
|
+
const pinnedRight = pinnedEntries.filter((entry) => entry[1] === "right").map((entry) => byName.get(entry[0])).filter((column) => column !== void 0);
|
|
568
|
+
const middleColumns = orderedColumns.filter(
|
|
569
|
+
(column) => this.pinnedColumns[column.name] === void 0
|
|
570
|
+
);
|
|
571
|
+
this.visibleColumns = [...pinnedLeft, ...middleColumns, ...pinnedRight];
|
|
572
|
+
}
|
|
573
|
+
this.pipeline = import_ui_grid_core.defaultGridEngine.buildPipeline({
|
|
574
|
+
options: this.options,
|
|
575
|
+
columns: this.visibleColumns,
|
|
576
|
+
activeFilters: this.activeFilters,
|
|
577
|
+
sortState: this.sortState,
|
|
578
|
+
groupByColumns: this.groupByColumns,
|
|
579
|
+
collapsedGroups: this.collapsedGroups,
|
|
580
|
+
hiddenRowReasons: this.hiddenRowReasons,
|
|
581
|
+
expandedRows: this.expandedRows,
|
|
582
|
+
expandedTreeRows: this.expandedTreeRows,
|
|
583
|
+
currentPage: this.currentPage,
|
|
584
|
+
pageSize: this.pageSize,
|
|
585
|
+
rowSize: this.getRowSize()
|
|
586
|
+
});
|
|
587
|
+
if (!this.apiRegistered) {
|
|
588
|
+
this.options.onRegisterApi?.(this.gridApi);
|
|
589
|
+
this.apiRegistered = true;
|
|
590
|
+
}
|
|
591
|
+
this.emit();
|
|
592
|
+
}
|
|
593
|
+
emit() {
|
|
594
|
+
const snapshot = this.getSnapshot();
|
|
595
|
+
for (const subscriber of this.subscribers) {
|
|
596
|
+
subscriber(snapshot);
|
|
597
|
+
}
|
|
598
|
+
}
|
|
599
|
+
findRowById(rowId) {
|
|
600
|
+
return (0, import_ui_grid_core.findGridRowById)(this.buildRowsFromData(this.options.data), rowId);
|
|
601
|
+
}
|
|
602
|
+
buildRowsFromData(data) {
|
|
603
|
+
return (0, import_ui_grid_core.buildGridRows)(
|
|
604
|
+
{ ...this.options, data },
|
|
605
|
+
this.getRowSize(),
|
|
606
|
+
this.hiddenRowReasons,
|
|
607
|
+
this.expandedRows
|
|
608
|
+
);
|
|
609
|
+
}
|
|
610
|
+
findColumnByName(columnName) {
|
|
611
|
+
return this.visibleColumns.find((column) => column.name === columnName);
|
|
612
|
+
}
|
|
613
|
+
resolveRowId(row) {
|
|
614
|
+
return (0, import_ui_grid_core.resolveGridRowId)(this.options, row);
|
|
615
|
+
}
|
|
616
|
+
getRowSize() {
|
|
617
|
+
return this.options.rowHeight ?? 44;
|
|
618
|
+
}
|
|
619
|
+
getTotalPages() {
|
|
620
|
+
return (0, import_ui_grid_core.getTotalPagesValue)(this.options, this.pipeline.totalItems, this.pageSize);
|
|
621
|
+
}
|
|
622
|
+
getEffectivePageSize() {
|
|
623
|
+
return (0, import_ui_grid_core.getEffectivePageSize)(this.options, this.pageSize, this.pipeline.totalItems);
|
|
624
|
+
}
|
|
625
|
+
getCurrentPage() {
|
|
626
|
+
return (0, import_ui_grid_core.getCurrentPageValue)(
|
|
627
|
+
this.options,
|
|
628
|
+
this.currentPage,
|
|
629
|
+
this.pipeline.totalItems,
|
|
630
|
+
this.pageSize
|
|
631
|
+
);
|
|
632
|
+
}
|
|
633
|
+
getFirstRowIndex() {
|
|
634
|
+
return (0, import_ui_grid_core.getFirstRowIndexValue)(
|
|
635
|
+
this.options,
|
|
636
|
+
this.currentPage,
|
|
637
|
+
this.pipeline.totalItems,
|
|
638
|
+
this.pageSize
|
|
639
|
+
);
|
|
640
|
+
}
|
|
641
|
+
getLastRowIndex() {
|
|
642
|
+
return (0, import_ui_grid_core.getLastRowIndexValue)(
|
|
643
|
+
this.options,
|
|
644
|
+
this.currentPage,
|
|
645
|
+
this.pipeline.totalItems,
|
|
646
|
+
this.pageSize
|
|
647
|
+
);
|
|
648
|
+
}
|
|
649
|
+
setRowInvisible(row, reason) {
|
|
650
|
+
const rowId = this.resolveRowId(row);
|
|
651
|
+
const next = { ...this.hiddenRowReasons };
|
|
652
|
+
const reasonValue = reason ?? "api";
|
|
653
|
+
next[rowId] = [...next[rowId] ?? [], reasonValue];
|
|
654
|
+
this.hiddenRowReasons = next;
|
|
655
|
+
this.refresh();
|
|
656
|
+
}
|
|
657
|
+
clearRowInvisible(row, reason) {
|
|
658
|
+
const rowId = this.resolveRowId(row);
|
|
659
|
+
const existing = this.hiddenRowReasons[rowId] ?? [];
|
|
660
|
+
if (existing.length === 0) {
|
|
661
|
+
return;
|
|
662
|
+
}
|
|
663
|
+
if (!reason) {
|
|
664
|
+
const next2 = { ...this.hiddenRowReasons };
|
|
665
|
+
delete next2[rowId];
|
|
666
|
+
this.hiddenRowReasons = next2;
|
|
667
|
+
this.refresh();
|
|
668
|
+
return;
|
|
669
|
+
}
|
|
670
|
+
const filtered = existing.filter((entry) => entry !== reason);
|
|
671
|
+
const next = { ...this.hiddenRowReasons };
|
|
672
|
+
if (filtered.length > 0) {
|
|
673
|
+
next[rowId] = filtered;
|
|
674
|
+
} else {
|
|
675
|
+
delete next[rowId];
|
|
676
|
+
}
|
|
677
|
+
this.hiddenRowReasons = next;
|
|
678
|
+
this.refresh();
|
|
679
|
+
}
|
|
680
|
+
benchmark(iterations) {
|
|
681
|
+
const now = () => typeof performance === "undefined" ? Date.now() : performance.now();
|
|
682
|
+
const loops = Math.max(1, iterations ?? this.options.benchmark?.iterations ?? 25);
|
|
683
|
+
const started = now();
|
|
684
|
+
let lastResult = this.pipeline;
|
|
685
|
+
for (let index = 0; index < loops; index += 1) {
|
|
686
|
+
lastResult = import_ui_grid_core.defaultGridEngine.buildPipeline({
|
|
687
|
+
options: this.options,
|
|
688
|
+
columns: this.visibleColumns,
|
|
689
|
+
activeFilters: this.activeFilters,
|
|
690
|
+
sortState: this.sortState,
|
|
691
|
+
groupByColumns: this.groupByColumns,
|
|
692
|
+
collapsedGroups: this.collapsedGroups,
|
|
693
|
+
hiddenRowReasons: this.hiddenRowReasons,
|
|
694
|
+
expandedRows: this.expandedRows,
|
|
695
|
+
expandedTreeRows: this.expandedTreeRows,
|
|
696
|
+
currentPage: this.currentPage,
|
|
697
|
+
pageSize: this.pageSize,
|
|
698
|
+
rowSize: this.getRowSize()
|
|
699
|
+
});
|
|
700
|
+
}
|
|
701
|
+
const elapsedMs = now() - started;
|
|
702
|
+
const result = {
|
|
703
|
+
iterations: loops,
|
|
704
|
+
totalMs: elapsedMs,
|
|
705
|
+
averageMs: elapsedMs / loops,
|
|
706
|
+
visibleRows: lastResult.visibleRows.length,
|
|
707
|
+
renderedItems: lastResult.displayItems.length
|
|
708
|
+
};
|
|
709
|
+
this.gridApi.core.raise.benchmarkComplete(result);
|
|
710
|
+
return result;
|
|
711
|
+
}
|
|
712
|
+
};
|
|
713
|
+
function createVanillaGridController(options) {
|
|
714
|
+
return new VanillaGridController(options);
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
// src/ui-grid-standalone.element.ts
|
|
718
|
+
function escapeHtml(value) {
|
|
719
|
+
const text = String(value ?? "");
|
|
720
|
+
return text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">").replace(/"/g, """).replace(/'/g, "'");
|
|
721
|
+
}
|
|
722
|
+
function asGroupItem(item) {
|
|
723
|
+
return item;
|
|
724
|
+
}
|
|
725
|
+
function isRowItem(item) {
|
|
726
|
+
return item.kind === "row";
|
|
727
|
+
}
|
|
728
|
+
var DEFAULT_ICONS = {
|
|
729
|
+
sortNone: { path: "M7 6h10v2H7V6Zm0 5h7v2H7v-2Zm0 5h4v2H7v-2Z" },
|
|
730
|
+
sortAsc: { path: "M12 5l-6 6h4v8h4v-8h4z" },
|
|
731
|
+
sortDesc: { path: "M12 19l6-6h-4V5h-4v8H6z" },
|
|
732
|
+
group: { path: "M4 6h8v4H4V6Zm0 8h8v4H4v-4Zm10-8h6v4h-6V6Zm0 8h6v4h-6v-4Z" },
|
|
733
|
+
groupExpanded: { path: "M7 10l5 5 5-5z" },
|
|
734
|
+
groupCollapsed: { path: "M10 7l5 5-5 5z" },
|
|
735
|
+
treeExpanded: { path: "M7 10l5 5 5-5z" },
|
|
736
|
+
treeCollapsed: { path: "M10 7l5 5-5 5z" },
|
|
737
|
+
expandExpanded: { path: "M7 10l5 5 5-5z" },
|
|
738
|
+
expandCollapsed: { path: "M10 7l5 5-5 5z" },
|
|
739
|
+
pin: { path: "M16 12V4h1V2H7v2h1v8l-2 2v2h5v6l1 1 1-1v-6h5v-2l-2-2z" },
|
|
740
|
+
pinLeft: { path: "M10 6 4 12l6 6v-4h10v-4H10V6z" },
|
|
741
|
+
pinRight: { path: "M14 6v4H4v4h10v4l6-6-6-6z" },
|
|
742
|
+
paginationPrev: { path: "M15.41 7.41 14 6l-6 6 6 6 1.41-1.41L10.83 12z" },
|
|
743
|
+
paginationNext: { path: "M8.59 16.59 10 18l6-6-6-6-1.41 1.41L13.17 12z" }
|
|
744
|
+
};
|
|
745
|
+
var UiGridStandaloneElement = class extends HTMLElement {
|
|
746
|
+
controller = null;
|
|
747
|
+
snapshot = null;
|
|
748
|
+
unsubscribe = null;
|
|
749
|
+
activeOptions = null;
|
|
750
|
+
iconOverrides = {};
|
|
751
|
+
templateObserver = null;
|
|
752
|
+
openPinMenuColumn = null;
|
|
753
|
+
focusedCell = null;
|
|
754
|
+
draggedColumnName = null;
|
|
755
|
+
dropTargetColumnName = null;
|
|
756
|
+
scrollPosition = 0;
|
|
757
|
+
scrollFrame = null;
|
|
758
|
+
suppressScrollEvent = false;
|
|
759
|
+
lastVirtualStartIndex = -1;
|
|
760
|
+
measuredHeaderStickyHeight = 0;
|
|
761
|
+
measuredFilterStickyHeight = 0;
|
|
762
|
+
stickyHeightRelayoutQueued = false;
|
|
763
|
+
benchmarkAverage = "\u2014";
|
|
764
|
+
get options() {
|
|
765
|
+
return this.activeOptions ?? {
|
|
766
|
+
id: "__ui-grid-pending__",
|
|
767
|
+
data: [],
|
|
768
|
+
columnDefs: []
|
|
769
|
+
};
|
|
770
|
+
}
|
|
771
|
+
set options(value) {
|
|
772
|
+
this.activeOptions = value;
|
|
773
|
+
this.iconOverrides = this.activeOptions.iconOverrides ?? {};
|
|
774
|
+
this.ensureController(this.buildEffectiveOptions(this.activeOptions));
|
|
775
|
+
}
|
|
776
|
+
get controlIcons() {
|
|
777
|
+
return this.iconOverrides;
|
|
778
|
+
}
|
|
779
|
+
set controlIcons(value) {
|
|
780
|
+
this.iconOverrides = { ...value };
|
|
781
|
+
this.render();
|
|
782
|
+
}
|
|
783
|
+
getState() {
|
|
784
|
+
return this.controller?.getState() ?? null;
|
|
785
|
+
}
|
|
786
|
+
setState(state) {
|
|
787
|
+
this.controller?.setState(state);
|
|
788
|
+
}
|
|
789
|
+
connectedCallback() {
|
|
790
|
+
this.ensureShadowRoot();
|
|
791
|
+
this.bindEvents();
|
|
792
|
+
this.observeTemplateSlots();
|
|
793
|
+
if (this.activeOptions) {
|
|
794
|
+
this.ensureController(this.buildEffectiveOptions(this.activeOptions));
|
|
795
|
+
} else {
|
|
796
|
+
this.render();
|
|
797
|
+
}
|
|
798
|
+
}
|
|
799
|
+
disconnectedCallback() {
|
|
800
|
+
this.unsubscribe?.();
|
|
801
|
+
this.unsubscribe = null;
|
|
802
|
+
this.templateObserver?.disconnect();
|
|
803
|
+
this.templateObserver = null;
|
|
804
|
+
if (this.scrollFrame !== null) {
|
|
805
|
+
cancelAnimationFrame(this.scrollFrame);
|
|
806
|
+
this.scrollFrame = null;
|
|
807
|
+
}
|
|
808
|
+
}
|
|
809
|
+
ensureShadowRoot() {
|
|
810
|
+
if (!this.shadowRoot) {
|
|
811
|
+
this.attachShadow({ mode: "open" });
|
|
812
|
+
}
|
|
813
|
+
return this.shadowRoot;
|
|
814
|
+
}
|
|
815
|
+
ensureController(options) {
|
|
816
|
+
if (this.controller) {
|
|
817
|
+
this.controller.setOptions(options);
|
|
818
|
+
return;
|
|
819
|
+
}
|
|
820
|
+
this.controller = createVanillaGridController(options);
|
|
821
|
+
this.unsubscribe = this.controller.subscribe((snapshot) => {
|
|
822
|
+
this.snapshot = snapshot;
|
|
823
|
+
this.render();
|
|
824
|
+
});
|
|
825
|
+
}
|
|
826
|
+
observeTemplateSlots() {
|
|
827
|
+
if (this.templateObserver) {
|
|
828
|
+
return;
|
|
829
|
+
}
|
|
830
|
+
this.templateObserver = new MutationObserver(() => {
|
|
831
|
+
if (this.activeOptions) {
|
|
832
|
+
this.ensureController(this.buildEffectiveOptions(this.activeOptions));
|
|
833
|
+
} else {
|
|
834
|
+
this.render();
|
|
835
|
+
}
|
|
836
|
+
});
|
|
837
|
+
this.templateObserver.observe(this, {
|
|
838
|
+
childList: true,
|
|
839
|
+
subtree: true,
|
|
840
|
+
attributes: true,
|
|
841
|
+
attributeFilter: ["slot"]
|
|
842
|
+
});
|
|
843
|
+
}
|
|
844
|
+
buildEffectiveOptions(options) {
|
|
845
|
+
const hasExpandableSlot = this.getTemplateMarkup("expandable-row") !== null;
|
|
846
|
+
if (options.enableExpandable && hasExpandableSlot && !options.expandableRowTemplate) {
|
|
847
|
+
return {
|
|
848
|
+
...options,
|
|
849
|
+
expandableRowTemplate: {
|
|
850
|
+
createEmbeddedView: () => void 0
|
|
851
|
+
}
|
|
852
|
+
};
|
|
853
|
+
}
|
|
854
|
+
return options;
|
|
855
|
+
}
|
|
856
|
+
bindEvents() {
|
|
857
|
+
const root = this.ensureShadowRoot();
|
|
858
|
+
if (root.__uiGridBound) {
|
|
859
|
+
return;
|
|
860
|
+
}
|
|
861
|
+
root.addEventListener("click", (event) => {
|
|
862
|
+
const target = event.target;
|
|
863
|
+
if (!target || !this.controller || !this.snapshot) {
|
|
864
|
+
return;
|
|
865
|
+
}
|
|
866
|
+
const actionNode = target.closest("[data-action]");
|
|
867
|
+
if (!actionNode) {
|
|
868
|
+
return;
|
|
869
|
+
}
|
|
870
|
+
const action = actionNode.dataset["action"];
|
|
871
|
+
if (!action) {
|
|
872
|
+
return;
|
|
873
|
+
}
|
|
874
|
+
if (this.openPinMenuColumn && !target.closest(".pin-control")) {
|
|
875
|
+
this.openPinMenuColumn = null;
|
|
876
|
+
this.render();
|
|
877
|
+
return;
|
|
878
|
+
}
|
|
879
|
+
if (action === "sort") {
|
|
880
|
+
const columnName = actionNode.dataset["column"];
|
|
881
|
+
if (columnName) {
|
|
882
|
+
this.controller.toggleSort(columnName);
|
|
883
|
+
}
|
|
884
|
+
return;
|
|
885
|
+
}
|
|
886
|
+
if (action === "group") {
|
|
887
|
+
const columnName = actionNode.dataset["column"];
|
|
888
|
+
if (columnName) {
|
|
889
|
+
this.controller.toggleGrouping(columnName);
|
|
890
|
+
}
|
|
891
|
+
return;
|
|
892
|
+
}
|
|
893
|
+
if (action === "toggle-group") {
|
|
894
|
+
const groupId = actionNode.dataset["group"];
|
|
895
|
+
if (groupId) {
|
|
896
|
+
const collapsed = actionNode.dataset["collapsed"] !== "true";
|
|
897
|
+
this.controller.setCollapsedGroup(groupId, collapsed);
|
|
898
|
+
}
|
|
899
|
+
return;
|
|
900
|
+
}
|
|
901
|
+
if (action === "pin-trigger") {
|
|
902
|
+
const columnName = actionNode.dataset["column"];
|
|
903
|
+
const column = columnName ? this.snapshot.visibleColumns.find((candidate) => candidate.name === columnName) : void 0;
|
|
904
|
+
if (columnName && column) {
|
|
905
|
+
if (this.controller.isPinned(column)) {
|
|
906
|
+
this.openPinMenuColumn = null;
|
|
907
|
+
this.controller.pinColumn(columnName, "none");
|
|
908
|
+
return;
|
|
909
|
+
}
|
|
910
|
+
this.openPinMenuColumn = this.openPinMenuColumn === columnName ? null : columnName;
|
|
911
|
+
this.render();
|
|
912
|
+
}
|
|
913
|
+
return;
|
|
914
|
+
}
|
|
915
|
+
if (action === "pin-left" || action === "pin-right") {
|
|
916
|
+
const columnName = actionNode.dataset["column"];
|
|
917
|
+
if (columnName) {
|
|
918
|
+
this.openPinMenuColumn = null;
|
|
919
|
+
this.controller.pinColumn(columnName, action === "pin-left" ? "left" : "right");
|
|
920
|
+
}
|
|
921
|
+
return;
|
|
922
|
+
}
|
|
923
|
+
if (action === "toggle-tree") {
|
|
924
|
+
const rowId = actionNode.dataset["row"];
|
|
925
|
+
if (rowId) {
|
|
926
|
+
this.controller.toggleTreeRow(rowId);
|
|
927
|
+
}
|
|
928
|
+
return;
|
|
929
|
+
}
|
|
930
|
+
if (action === "toggle-expand") {
|
|
931
|
+
const rowId = actionNode.dataset["row"];
|
|
932
|
+
if (rowId) {
|
|
933
|
+
this.controller.toggleRowExpansion(rowId);
|
|
934
|
+
}
|
|
935
|
+
return;
|
|
936
|
+
}
|
|
937
|
+
if (action === "page-prev") {
|
|
938
|
+
this.controller.seekPage(this.snapshot.currentPage - 1);
|
|
939
|
+
return;
|
|
940
|
+
}
|
|
941
|
+
if (action === "page-next") {
|
|
942
|
+
this.controller.seekPage(this.snapshot.currentPage + 1);
|
|
943
|
+
return;
|
|
944
|
+
}
|
|
945
|
+
if (action === "benchmark") {
|
|
946
|
+
const result = this.controller.gridApi.core.benchmark();
|
|
947
|
+
this.benchmarkAverage = result.averageMs.toFixed(2);
|
|
948
|
+
this.render();
|
|
949
|
+
return;
|
|
950
|
+
}
|
|
951
|
+
if (action === "export-csv") {
|
|
952
|
+
this.downloadCsv();
|
|
953
|
+
}
|
|
954
|
+
});
|
|
955
|
+
root.addEventListener("focusin", (event) => {
|
|
956
|
+
const target = event.target;
|
|
957
|
+
if (!target) {
|
|
958
|
+
return;
|
|
959
|
+
}
|
|
960
|
+
const cell = target.closest(".body-cell[data-row][data-column]");
|
|
961
|
+
const rowId = cell?.dataset["row"];
|
|
962
|
+
const columnName = cell?.dataset["column"];
|
|
963
|
+
if (rowId && columnName) {
|
|
964
|
+
this.focusedCell = { rowId, columnName };
|
|
965
|
+
}
|
|
966
|
+
});
|
|
967
|
+
root.addEventListener("focusout", (event) => {
|
|
968
|
+
const relatedTarget = event.relatedTarget;
|
|
969
|
+
if (!relatedTarget?.closest(".body-cell[data-row][data-column]")) {
|
|
970
|
+
this.focusedCell = null;
|
|
971
|
+
}
|
|
972
|
+
});
|
|
973
|
+
root.addEventListener("input", (event) => {
|
|
974
|
+
const target = event.target;
|
|
975
|
+
if (!target || !this.controller) {
|
|
976
|
+
return;
|
|
977
|
+
}
|
|
978
|
+
if (target instanceof HTMLInputElement && target.dataset["role"] === "filter") {
|
|
979
|
+
const columnName = target.dataset["column"];
|
|
980
|
+
if (columnName) {
|
|
981
|
+
this.controller.setFilter(columnName, target.value);
|
|
982
|
+
}
|
|
983
|
+
}
|
|
984
|
+
if (target instanceof HTMLInputElement && target.dataset["role"] === "editor") {
|
|
985
|
+
this.controller.updateEditingValue(target.value);
|
|
986
|
+
}
|
|
987
|
+
});
|
|
988
|
+
root.addEventListener("change", (event) => {
|
|
989
|
+
const target = event.target;
|
|
990
|
+
if (!target || !this.controller) {
|
|
991
|
+
return;
|
|
992
|
+
}
|
|
993
|
+
if (target instanceof HTMLSelectElement && target.dataset["role"] === "page-size") {
|
|
994
|
+
const value = Number.parseInt(target.value, 10);
|
|
995
|
+
this.controller.setPageSize(value);
|
|
996
|
+
}
|
|
997
|
+
});
|
|
998
|
+
root.addEventListener("dblclick", (event) => {
|
|
999
|
+
const target = event.target;
|
|
1000
|
+
if (!target || !this.controller) {
|
|
1001
|
+
return;
|
|
1002
|
+
}
|
|
1003
|
+
const cell = target.closest(".body-cell");
|
|
1004
|
+
if (!cell) {
|
|
1005
|
+
return;
|
|
1006
|
+
}
|
|
1007
|
+
const rowId = cell.dataset["row"];
|
|
1008
|
+
const columnName = cell.dataset["column"];
|
|
1009
|
+
if (rowId && columnName) {
|
|
1010
|
+
this.controller.beginCellEdit(rowId, columnName, event);
|
|
1011
|
+
}
|
|
1012
|
+
});
|
|
1013
|
+
root.addEventListener("keydown", (event) => {
|
|
1014
|
+
const keyboardEvent = event;
|
|
1015
|
+
const target = event.target;
|
|
1016
|
+
if (!target || !this.controller) {
|
|
1017
|
+
return;
|
|
1018
|
+
}
|
|
1019
|
+
if (target instanceof HTMLInputElement && target.dataset["role"] === "editor") {
|
|
1020
|
+
if (keyboardEvent.key === "Enter") {
|
|
1021
|
+
event.preventDefault();
|
|
1022
|
+
this.controller.commitCellEdit();
|
|
1023
|
+
return;
|
|
1024
|
+
}
|
|
1025
|
+
if (keyboardEvent.key === "Escape") {
|
|
1026
|
+
event.preventDefault();
|
|
1027
|
+
this.controller.cancelCellEdit();
|
|
1028
|
+
}
|
|
1029
|
+
return;
|
|
1030
|
+
}
|
|
1031
|
+
const cell = target.closest(".body-cell");
|
|
1032
|
+
if (!cell) {
|
|
1033
|
+
return;
|
|
1034
|
+
}
|
|
1035
|
+
const rowId = cell.dataset["row"];
|
|
1036
|
+
const columnName = cell.dataset["column"];
|
|
1037
|
+
if (!rowId || !columnName) {
|
|
1038
|
+
return;
|
|
1039
|
+
}
|
|
1040
|
+
if (keyboardEvent.key === "Enter" || keyboardEvent.key === "F2") {
|
|
1041
|
+
event.preventDefault();
|
|
1042
|
+
this.controller.beginCellEdit(rowId, columnName, event);
|
|
1043
|
+
return;
|
|
1044
|
+
}
|
|
1045
|
+
if (keyboardEvent.key.length === 1 && !keyboardEvent.ctrlKey && !keyboardEvent.metaKey && !keyboardEvent.altKey) {
|
|
1046
|
+
event.preventDefault();
|
|
1047
|
+
this.controller.beginCellEdit(rowId, columnName, event);
|
|
1048
|
+
this.controller.updateEditingValue(keyboardEvent.key);
|
|
1049
|
+
}
|
|
1050
|
+
});
|
|
1051
|
+
root.addEventListener(
|
|
1052
|
+
"blur",
|
|
1053
|
+
(event) => {
|
|
1054
|
+
const target = event.target;
|
|
1055
|
+
if (!target || !this.controller) {
|
|
1056
|
+
return;
|
|
1057
|
+
}
|
|
1058
|
+
if (target instanceof HTMLInputElement && target.dataset["role"] === "editor") {
|
|
1059
|
+
this.controller.commitCellEdit();
|
|
1060
|
+
}
|
|
1061
|
+
},
|
|
1062
|
+
true
|
|
1063
|
+
);
|
|
1064
|
+
root.addEventListener("dragstart", (event) => {
|
|
1065
|
+
const dragEvent = event;
|
|
1066
|
+
const target = event.target;
|
|
1067
|
+
const headerCell = target?.closest(".header-cell[data-column]");
|
|
1068
|
+
if (!headerCell || !this.snapshot || !(0, import_ui_grid_core2.canGridMoveColumns)(this.snapshot.options)) {
|
|
1069
|
+
event.preventDefault();
|
|
1070
|
+
return;
|
|
1071
|
+
}
|
|
1072
|
+
const columnName = headerCell.dataset["column"];
|
|
1073
|
+
if (!columnName || !dragEvent.dataTransfer) {
|
|
1074
|
+
event.preventDefault();
|
|
1075
|
+
return;
|
|
1076
|
+
}
|
|
1077
|
+
this.draggedColumnName = columnName;
|
|
1078
|
+
this.dropTargetColumnName = null;
|
|
1079
|
+
dragEvent.dataTransfer.effectAllowed = "move";
|
|
1080
|
+
dragEvent.dataTransfer.setData("text/plain", columnName);
|
|
1081
|
+
headerCell.classList.add("is-dragging");
|
|
1082
|
+
});
|
|
1083
|
+
root.addEventListener("dragover", (event) => {
|
|
1084
|
+
const dragEvent = event;
|
|
1085
|
+
const target = event.target;
|
|
1086
|
+
const headerCell = target?.closest(".header-cell[data-column]");
|
|
1087
|
+
if (!headerCell || !this.draggedColumnName || !dragEvent.dataTransfer) {
|
|
1088
|
+
return;
|
|
1089
|
+
}
|
|
1090
|
+
const columnName = headerCell.dataset["column"];
|
|
1091
|
+
if (!columnName || columnName === this.draggedColumnName) {
|
|
1092
|
+
return;
|
|
1093
|
+
}
|
|
1094
|
+
event.preventDefault();
|
|
1095
|
+
dragEvent.dataTransfer.dropEffect = "move";
|
|
1096
|
+
if (this.dropTargetColumnName !== columnName) {
|
|
1097
|
+
root.querySelectorAll(".header-cell.is-drag-target").forEach((element) => element.classList.remove("is-drag-target"));
|
|
1098
|
+
this.dropTargetColumnName = columnName;
|
|
1099
|
+
headerCell.classList.add("is-drag-target");
|
|
1100
|
+
}
|
|
1101
|
+
});
|
|
1102
|
+
root.addEventListener("dragleave", (event) => {
|
|
1103
|
+
const target = event.target;
|
|
1104
|
+
const headerCell = target?.closest(".header-cell[data-column]");
|
|
1105
|
+
if (headerCell && headerCell.dataset["column"] === this.dropTargetColumnName) {
|
|
1106
|
+
headerCell.classList.remove("is-drag-target");
|
|
1107
|
+
}
|
|
1108
|
+
});
|
|
1109
|
+
root.addEventListener("drop", (event) => {
|
|
1110
|
+
event.preventDefault();
|
|
1111
|
+
const dragEvent = event;
|
|
1112
|
+
const target = event.target;
|
|
1113
|
+
const headerCell = target?.closest(".header-cell[data-column]");
|
|
1114
|
+
const targetColumn = headerCell?.dataset["column"];
|
|
1115
|
+
const sourceColumn = this.draggedColumnName ?? dragEvent.dataTransfer?.getData("text/plain") ?? null;
|
|
1116
|
+
this.draggedColumnName = null;
|
|
1117
|
+
this.dropTargetColumnName = null;
|
|
1118
|
+
root.querySelectorAll(".header-cell.is-dragging, .header-cell.is-drag-target").forEach((element) => element.classList.remove("is-dragging", "is-drag-target"));
|
|
1119
|
+
if (!sourceColumn || !targetColumn || sourceColumn === targetColumn || !this.controller) {
|
|
1120
|
+
return;
|
|
1121
|
+
}
|
|
1122
|
+
this.controller.moveVisibleColumn(sourceColumn, targetColumn);
|
|
1123
|
+
});
|
|
1124
|
+
root.addEventListener("dragend", () => {
|
|
1125
|
+
this.draggedColumnName = null;
|
|
1126
|
+
this.dropTargetColumnName = null;
|
|
1127
|
+
root.querySelectorAll(".header-cell.is-dragging, .header-cell.is-drag-target").forEach((element) => element.classList.remove("is-dragging", "is-drag-target"));
|
|
1128
|
+
});
|
|
1129
|
+
root.addEventListener(
|
|
1130
|
+
"scroll",
|
|
1131
|
+
(event) => {
|
|
1132
|
+
const target = event.target;
|
|
1133
|
+
if (!target?.classList.contains("grid-table") || this.suppressScrollEvent) {
|
|
1134
|
+
return;
|
|
1135
|
+
}
|
|
1136
|
+
this.scrollPosition = target.scrollTop;
|
|
1137
|
+
if (!this.snapshot?.pipeline.virtualizationEnabled) {
|
|
1138
|
+
return;
|
|
1139
|
+
}
|
|
1140
|
+
const stickyChromeHeight = this.measuredHeaderStickyHeight + this.measuredFilterStickyHeight;
|
|
1141
|
+
const bodyScrollTop = Math.max(0, this.scrollPosition - stickyChromeHeight);
|
|
1142
|
+
const overscan = 4;
|
|
1143
|
+
const nextStartIndex = Math.max(
|
|
1144
|
+
0,
|
|
1145
|
+
Math.floor(bodyScrollTop / this.snapshot.rowSize) - overscan
|
|
1146
|
+
);
|
|
1147
|
+
if (nextStartIndex === this.lastVirtualStartIndex) {
|
|
1148
|
+
return;
|
|
1149
|
+
}
|
|
1150
|
+
if (this.scrollFrame !== null) {
|
|
1151
|
+
cancelAnimationFrame(this.scrollFrame);
|
|
1152
|
+
}
|
|
1153
|
+
this.scrollFrame = requestAnimationFrame(() => {
|
|
1154
|
+
this.scrollFrame = null;
|
|
1155
|
+
this.render();
|
|
1156
|
+
});
|
|
1157
|
+
},
|
|
1158
|
+
true
|
|
1159
|
+
);
|
|
1160
|
+
root.__uiGridBound = true;
|
|
1161
|
+
}
|
|
1162
|
+
render() {
|
|
1163
|
+
const root = this.ensureShadowRoot();
|
|
1164
|
+
const snapshot = this.snapshot;
|
|
1165
|
+
const previousGridTable = root.querySelector(".grid-table");
|
|
1166
|
+
if (previousGridTable && !this.suppressScrollEvent) {
|
|
1167
|
+
this.scrollPosition = previousGridTable.scrollTop;
|
|
1168
|
+
}
|
|
1169
|
+
if (!snapshot) {
|
|
1170
|
+
root.innerHTML = `<style>${import_ui_grid_core2.GRID_CORE_CSS}</style><section class="grid-shell ui-grid-shell"><div class="empty-state ui-grid-no-row-overlay"><strong>No grid options provided.</strong></div></section>`;
|
|
1171
|
+
return;
|
|
1172
|
+
}
|
|
1173
|
+
const controller = this.controller;
|
|
1174
|
+
const options = snapshot.options;
|
|
1175
|
+
const labels = snapshot.labels;
|
|
1176
|
+
const templateColumns = snapshot.gridTemplateColumns;
|
|
1177
|
+
const sortEnabled = controller.isSortingEnabled();
|
|
1178
|
+
const filterEnabled = controller.isFilteringEnabled();
|
|
1179
|
+
const groupingEnabled = controller.isGroupingEnabled();
|
|
1180
|
+
const pinningEnabled = controller.isPinningEnabled();
|
|
1181
|
+
const paginationEnabled = controller.isPaginationEnabled();
|
|
1182
|
+
const showPagination = controller.shouldShowPaginationControls();
|
|
1183
|
+
const virtualizationEnabled = snapshot.pipeline.virtualizationEnabled;
|
|
1184
|
+
const viewportHeight = options.viewportHeight ?? 560;
|
|
1185
|
+
const headerStickyTop = this.measuredHeaderStickyHeight || options.headerRowHeight || 50;
|
|
1186
|
+
const stickyChromeHeight = this.measuredHeaderStickyHeight + this.measuredFilterStickyHeight;
|
|
1187
|
+
const bodyViewportHeight = Math.max(snapshot.rowSize, viewportHeight - stickyChromeHeight);
|
|
1188
|
+
const visibleRowCount = snapshot.pipeline.visibleRows.length;
|
|
1189
|
+
const totalRows = options.data.length;
|
|
1190
|
+
const pinnedCount = Object.keys(snapshot.pinnedColumns).length;
|
|
1191
|
+
let startIndex = 0;
|
|
1192
|
+
let itemsToRender = snapshot.pipeline.displayItems;
|
|
1193
|
+
let virtualOffset = 0;
|
|
1194
|
+
const totalVirtualHeight = snapshot.pipeline.displayItems.length * snapshot.rowSize;
|
|
1195
|
+
if (virtualizationEnabled) {
|
|
1196
|
+
const bodyScrollTop = Math.max(0, this.scrollPosition - stickyChromeHeight);
|
|
1197
|
+
const overscan = 4;
|
|
1198
|
+
startIndex = Math.max(0, Math.floor(bodyScrollTop / snapshot.rowSize) - overscan);
|
|
1199
|
+
this.lastVirtualStartIndex = startIndex;
|
|
1200
|
+
const visibleCount = Math.ceil(bodyViewportHeight / snapshot.rowSize) + overscan * 2;
|
|
1201
|
+
itemsToRender = snapshot.pipeline.displayItems.slice(
|
|
1202
|
+
startIndex,
|
|
1203
|
+
Math.min(snapshot.pipeline.displayItems.length, startIndex + visibleCount)
|
|
1204
|
+
);
|
|
1205
|
+
virtualOffset = startIndex * snapshot.rowSize;
|
|
1206
|
+
} else {
|
|
1207
|
+
this.lastVirtualStartIndex = -1;
|
|
1208
|
+
}
|
|
1209
|
+
const slotRegistry = this.renderSlotRegistry(snapshot.visibleColumns);
|
|
1210
|
+
const header = snapshot.visibleColumns.map(
|
|
1211
|
+
(column) => this.renderHeaderCell(column, sortEnabled, groupingEnabled, pinningEnabled, options)
|
|
1212
|
+
).join("");
|
|
1213
|
+
const filterRow = filterEnabled ? `<div class="filter-grid ui-grid-header" style="grid-template-columns:${templateColumns}">${snapshot.visibleColumns.map((column) => this.renderFilterCell(column)).join("")}</div>` : "";
|
|
1214
|
+
const bodyContent = itemsToRender.map((item, index) => this.renderDisplayItem(item, startIndex + index)).join("");
|
|
1215
|
+
const body = snapshot.pipeline.displayItems.length > 0 ? virtualizationEnabled ? `<div class="grid-virtual-spacer" style="height:${totalVirtualHeight}px"><div class="body-grid ui-grid-canvas grid-virtual-body" style="grid-template-columns:${templateColumns};top:${virtualOffset}px">${bodyContent}</div></div>` : `<div class="body-grid ui-grid-canvas" style="grid-template-columns:${templateColumns}">${bodyContent}</div>` : `<div class="empty-state ui-grid-no-row-overlay"><strong>${escapeHtml(options.emptyMessage ?? labels.emptyHeading)}</strong><p>${escapeHtml(labels.emptyDescription)}</p></div>`;
|
|
1216
|
+
const pagination = paginationEnabled && showPagination ? this.renderPagination(snapshot) : "";
|
|
1217
|
+
const hero = `<header class="grid-hero"><div><p class="eyebrow">Vanilla web component</p><h1>${escapeHtml(options.title ?? "UI Grid")}</h1><p class="deck">Framework-neutral custom element with Shadow DOM styling, slot templates, pinning, virtualization, editing, tree view, grouping, and state restore.</p></div><div class="hero-actions"><button type="button" class="action action-secondary" data-action="benchmark">Benchmark</button><button type="button" class="action action-secondary" data-action="export-csv">Export CSV</button><div class="stats-card"><span>${visibleRowCount}</span><small>${escapeHtml(labels.statsVisibleRows)}</small></div></div></header>`;
|
|
1218
|
+
const metrics = `<section class="metrics-strip" aria-label="Grid metrics"><article><strong>${snapshot.pipeline.pipelineMs.toFixed(2)} ms</strong><span>pipeline</span></article><article><strong>${virtualizationEnabled ? "On" : "Off"}</strong><span>virtualization</span></article><article><strong>${pinnedCount}</strong><span>pinned columns</span></article><article><strong>${escapeHtml(this.benchmarkAverage)}</strong><span>benchmark avg</span></article></section>`;
|
|
1219
|
+
const toolbar = `<div class="grid-toolbar"><div><strong>${visibleRowCount}</strong><span>${escapeHtml(labels.toolbarOf)} ${totalRows} ${escapeHtml(labels.toolbarRows)}</span></div><p>${escapeHtml(options.id)}</p></div>`;
|
|
1220
|
+
const gridTableStyle = `${virtualizationEnabled ? `height:${viewportHeight}px;overflow-y:auto;` : ""}--ui-grid-header-sticky-top:${headerStickyTop}px;`;
|
|
1221
|
+
root.innerHTML = `<style>${import_ui_grid_core2.GRID_CORE_CSS}</style><section class="grid-shell ui-grid-shell">${slotRegistry}${hero}${metrics}<section class="grid-frame ui-grid" role="grid" aria-label="${escapeHtml(options.title ?? "Data grid")}">${toolbar}<div class="grid-table ui-grid-contents-wrapper" style="${gridTableStyle}"><div class="header-grid ui-grid-header ui-grid-header-canvas" style="grid-template-columns:${templateColumns}">${header}</div>${filterRow}${body}</div>${pagination}</section></section>`;
|
|
1222
|
+
const gridTable = root.querySelector(".grid-table");
|
|
1223
|
+
if (gridTable && this.scrollPosition > 0 && virtualizationEnabled) {
|
|
1224
|
+
this.suppressScrollEvent = true;
|
|
1225
|
+
gridTable.scrollTop = this.scrollPosition;
|
|
1226
|
+
requestAnimationFrame(() => {
|
|
1227
|
+
this.suppressScrollEvent = false;
|
|
1228
|
+
});
|
|
1229
|
+
}
|
|
1230
|
+
const headerGrid = root.querySelector(".header-grid");
|
|
1231
|
+
const filterGrid = root.querySelector(".filter-grid");
|
|
1232
|
+
const nextHeaderStickyHeight = headerGrid?.offsetHeight ?? 0;
|
|
1233
|
+
const nextFilterStickyHeight = filterGrid?.offsetHeight ?? 0;
|
|
1234
|
+
const stickyHeightsChanged = nextHeaderStickyHeight !== this.measuredHeaderStickyHeight || nextFilterStickyHeight !== this.measuredFilterStickyHeight;
|
|
1235
|
+
this.measuredHeaderStickyHeight = nextHeaderStickyHeight;
|
|
1236
|
+
this.measuredFilterStickyHeight = nextFilterStickyHeight;
|
|
1237
|
+
if (stickyHeightsChanged && !this.stickyHeightRelayoutQueued) {
|
|
1238
|
+
this.stickyHeightRelayoutQueued = true;
|
|
1239
|
+
requestAnimationFrame(() => {
|
|
1240
|
+
this.stickyHeightRelayoutQueued = false;
|
|
1241
|
+
if (!this.snapshot) {
|
|
1242
|
+
return;
|
|
1243
|
+
}
|
|
1244
|
+
this.render();
|
|
1245
|
+
});
|
|
1246
|
+
}
|
|
1247
|
+
}
|
|
1248
|
+
renderHeaderCell(column, sortEnabled, groupingEnabled, pinningEnabled, options) {
|
|
1249
|
+
const controller = this.controller;
|
|
1250
|
+
const sortDirection = controller.getSortDirection(column);
|
|
1251
|
+
const sortLabel = controller.sortButtonLabel(column);
|
|
1252
|
+
const groupingLabel = controller.groupingButtonLabel(column);
|
|
1253
|
+
const canSort = sortEnabled && controller.isColumnSortable(column);
|
|
1254
|
+
const canGroup = groupingEnabled && column.enableGrouping !== false;
|
|
1255
|
+
const canPin = pinningEnabled && controller.isColumnPinnable(column);
|
|
1256
|
+
const isPinned = controller.isPinned(column);
|
|
1257
|
+
const pinOffset = isPinned ? controller.pinnedOffset(column) : null;
|
|
1258
|
+
const isPinnedLeftLast = controller.isPinnedLeftLast(column);
|
|
1259
|
+
const isPinnedRightFirst = controller.isPinnedRightFirst(column);
|
|
1260
|
+
const isDragTarget = this.dropTargetColumnName === column.name;
|
|
1261
|
+
const isDragging = this.draggedColumnName === column.name;
|
|
1262
|
+
const classes = [
|
|
1263
|
+
"header-cell",
|
|
1264
|
+
sortDirection !== import_ui_grid_core2.SORT_DIRECTIONS.none ? "is-active" : "",
|
|
1265
|
+
isPinned ? "is-pinned" : "",
|
|
1266
|
+
isPinnedLeftLast ? "is-pinned-left-last" : "",
|
|
1267
|
+
isPinnedRightFirst ? "is-pinned-right-first" : "",
|
|
1268
|
+
this.openPinMenuColumn === column.name ? "is-pin-menu-open" : "",
|
|
1269
|
+
isDragTarget ? "is-drag-target" : "",
|
|
1270
|
+
isDragging ? "is-dragging" : ""
|
|
1271
|
+
].filter(Boolean).join(" ");
|
|
1272
|
+
const stickyStyle = pinOffset ? `${pinOffset.side}:${pinOffset.offset};` : "";
|
|
1273
|
+
const sortIconKey = sortDirection === import_ui_grid_core2.SORT_DIRECTIONS.asc ? "sortAsc" : sortDirection === import_ui_grid_core2.SORT_DIRECTIONS.desc ? "sortDesc" : "sortNone";
|
|
1274
|
+
const draggable = (0, import_ui_grid_core2.canGridMoveColumns)(options) ? 'draggable="true"' : "";
|
|
1275
|
+
const pinLabel = isPinned ? this.snapshot?.labels.unpin ?? "Unpin" : this.snapshot?.labels.pinColumn ?? "Pin";
|
|
1276
|
+
return `<div class="${classes}" data-column="${escapeHtml(column.name)}" ${draggable} style="${stickyStyle}"><span class="header-label">${escapeHtml(controller.headerLabel(column))}</span><span class="header-actions">${sortEnabled ? `<button type="button" class="header-action" data-action="sort" data-column="${escapeHtml(column.name)}" aria-label="${escapeHtml(sortLabel)}" ${canSort ? "" : "disabled"}>${this.renderControlIcon(sortIconKey)}<span class="sr-only">${escapeHtml(sortLabel)}</span></button>` : ""}${groupingEnabled ? `<button type="button" class="chip-action${controller.isColumnGrouped(column) ? " chip-action-active" : ""}" data-action="group" data-column="${escapeHtml(column.name)}" aria-label="${escapeHtml(groupingLabel)}" ${canGroup ? "" : "disabled"}>${this.renderControlIcon("group")}<span class="sr-only">${escapeHtml(groupingLabel)}</span></button>` : ""}${canPin ? `<div class="pin-control${this.openPinMenuColumn === column.name ? " pin-control-open" : ""}"><button type="button" class="chip-action pin-trigger${isPinned ? " chip-action-active" : ""}" data-action="pin-trigger" data-column="${escapeHtml(column.name)}" aria-label="${escapeHtml(pinLabel)}">${this.renderControlIcon("pin")}<span class="sr-only">${escapeHtml(pinLabel)}</span></button><div class="pin-menu" role="menu" aria-label="${escapeHtml(pinLabel)}"><button type="button" class="pin-menu-action" data-action="pin-left" data-column="${escapeHtml(column.name)}" aria-label="${escapeHtml(this.snapshot?.labels.pinLeft ?? "Pin left")}">${this.renderIconWithClass("control-icon", "pinLeft")}<span class="sr-only">${escapeHtml(this.snapshot?.labels.pinLeft ?? "Pin left")}</span></button><button type="button" class="pin-menu-action" data-action="pin-right" data-column="${escapeHtml(column.name)}" aria-label="${escapeHtml(this.snapshot?.labels.pinRight ?? "Pin right")}">${this.renderIconWithClass("control-icon", "pinRight")}<span class="sr-only">${escapeHtml(this.snapshot?.labels.pinRight ?? "Pin right")}</span></button></div></div>` : ""}</span></div>`;
|
|
1277
|
+
}
|
|
1278
|
+
renderFilterCell(column) {
|
|
1279
|
+
const value = this.snapshot?.activeFilters[column.name] ?? "";
|
|
1280
|
+
const controller = this.controller;
|
|
1281
|
+
const canFilter = controller.isColumnFilterable(column);
|
|
1282
|
+
const pinOffset = controller.isPinned(column) ? controller.pinnedOffset(column) : null;
|
|
1283
|
+
const classes = [
|
|
1284
|
+
"filter-cell",
|
|
1285
|
+
controller.isPinned(column) ? "is-pinned" : "",
|
|
1286
|
+
controller.isPinnedLeftLast(column) ? "is-pinned-left-last" : "",
|
|
1287
|
+
controller.isPinnedRightFirst(column) ? "is-pinned-right-first" : ""
|
|
1288
|
+
].filter(Boolean).join(" ");
|
|
1289
|
+
const stickyStyle = pinOffset ? `${pinOffset.side}:${pinOffset.offset};` : "";
|
|
1290
|
+
return `<label class="${classes}" style="${stickyStyle}"><input class="ui-grid-filter-input" data-role="filter" data-column="${escapeHtml(column.name)}" placeholder="${escapeHtml(controller.filterPlaceholder(column))}" value="${escapeHtml(value)}" ${canFilter ? "" : "disabled"}></label>`;
|
|
1291
|
+
}
|
|
1292
|
+
renderDisplayItem(item, displayIndex) {
|
|
1293
|
+
if (!this.snapshot || !this.controller) {
|
|
1294
|
+
return "";
|
|
1295
|
+
}
|
|
1296
|
+
if (item.kind === "group") {
|
|
1297
|
+
const group = asGroupItem(item);
|
|
1298
|
+
const iconKey = group.collapsed ? "groupCollapsed" : "groupExpanded";
|
|
1299
|
+
const disclosureLabel = this.controller.groupDisclosureLabel(group);
|
|
1300
|
+
return `<button type="button" class="group-row ui-grid-row ui-grid-group-row" data-action="toggle-group" data-group="${escapeHtml(group.id)}" data-collapsed="${group.collapsed ? "true" : "false"}" style="grid-column: 1 / -1; padding-inline-start:${group.depth * 20 + 10}px">${this.renderIconWithClass("toggle-icon group-disclosure-icon", iconKey)}<span class="sr-only">${escapeHtml(disclosureLabel)}</span><strong>${escapeHtml(group.field)}: ${escapeHtml(group.label)}</strong><span>${group.count} ${escapeHtml(this.snapshot.labels.groupRowsSuffix)}</span></button>`;
|
|
1301
|
+
}
|
|
1302
|
+
if (item.kind === "expandable") {
|
|
1303
|
+
const row = item.row;
|
|
1304
|
+
return `<div class="expandable-row ui-grid-row ui-grid-expandable-row" style="grid-column:1 / -1">${this.renderExpandableTemplate(row)}</div>`;
|
|
1305
|
+
}
|
|
1306
|
+
if (!isRowItem(item)) {
|
|
1307
|
+
return "";
|
|
1308
|
+
}
|
|
1309
|
+
return this.snapshot.visibleColumns.map((column) => this.renderBodyCell(item.row, column, displayIndex)).join("");
|
|
1310
|
+
}
|
|
1311
|
+
renderBodyCell(row, column, displayIndex) {
|
|
1312
|
+
if (!this.snapshot || !this.controller) {
|
|
1313
|
+
return "";
|
|
1314
|
+
}
|
|
1315
|
+
const controller = this.controller;
|
|
1316
|
+
const rowId = row.id;
|
|
1317
|
+
const columnName = column.name;
|
|
1318
|
+
const editing = controller.isEditingCell(rowId, columnName);
|
|
1319
|
+
const pinOffset = controller.isPinned(column) ? controller.pinnedOffset(column) : null;
|
|
1320
|
+
const treeToggle = controller.showTreeToggle(row, column) ? `<button type="button" class="row-toggle" data-action="toggle-tree" data-row="${escapeHtml(rowId)}" aria-label="${escapeHtml(controller.treeToggleLabel(row))}">${this.renderIconWithClass("toggle-icon", controller.isTreeRowExpanded(row) ? "treeExpanded" : "treeCollapsed")}<span class="sr-only">${escapeHtml(controller.treeToggleLabel(row))}</span></button>` : "";
|
|
1321
|
+
const expandToggle = controller.showExpandToggle(row, column) ? `<button type="button" class="row-toggle row-toggle-expand" data-action="toggle-expand" data-row="${escapeHtml(rowId)}" aria-label="${escapeHtml(controller.expandToggleLabel(row))}">${this.renderIconWithClass("toggle-icon", row.expanded ? "expandExpanded" : "expandCollapsed")}<span class="sr-only">${escapeHtml(controller.expandToggleLabel(row))}</span></button>` : "";
|
|
1322
|
+
const content = editing ? `<input class="cell-editor" data-role="editor" data-row="${escapeHtml(rowId)}" data-column="${escapeHtml(columnName)}" type="${escapeHtml(controller.editorInputType(column))}" value="${escapeHtml(this.snapshot.editingValue)}">` : this.renderCellTemplate(row, column, displayIndex);
|
|
1323
|
+
const classes = [
|
|
1324
|
+
"body-cell",
|
|
1325
|
+
"ui-grid-cell",
|
|
1326
|
+
displayIndex % 2 !== 0 ? "body-cell-odd" : "",
|
|
1327
|
+
column.align === "center" ? "align-center" : "",
|
|
1328
|
+
column.align === "end" ? "align-end" : "",
|
|
1329
|
+
controller.isPinned(column) ? "is-pinned" : "",
|
|
1330
|
+
controller.isPinnedLeftLast(column) ? "is-pinned-left-last" : "",
|
|
1331
|
+
controller.isPinnedRightFirst(column) ? "is-pinned-right-first" : "",
|
|
1332
|
+
this.focusedCell?.rowId === rowId && this.focusedCell.columnName === columnName ? "cell-focused" : "",
|
|
1333
|
+
editing ? "cell-editing" : ""
|
|
1334
|
+
].filter(Boolean).join(" ");
|
|
1335
|
+
const stickyStyle = pinOffset ? `${pinOffset.side}:${pinOffset.offset};` : "";
|
|
1336
|
+
return `<div class="${classes}" tabindex="0" data-row="${escapeHtml(rowId)}" data-column="${escapeHtml(columnName)}" style="${stickyStyle}"><div class="cell-shell" style="padding-inline-start:${escapeHtml(controller.cellIndent(row, column))}">${treeToggle}${expandToggle}${content}</div></div>`;
|
|
1337
|
+
}
|
|
1338
|
+
renderPagination(snapshot) {
|
|
1339
|
+
const pageSizes = snapshot.options.paginationPageSizes ?? [10, 25, 50, 100];
|
|
1340
|
+
return `<footer class="pagination-bar ui-grid-pagination"><p>${snapshot.firstRowIndex + 1}-${snapshot.lastRowIndex + 1} of ${snapshot.pipeline.totalItems}</p><div class="pagination-controls"><button type="button" class="action action-secondary pagination-button" data-action="page-prev" aria-label="${escapeHtml(snapshot.labels.paginationPrevious)}" ${snapshot.currentPage <= 1 ? "disabled" : ""}>${this.renderIconWithClass("pagination-icon", "paginationPrev")}<span class="sr-only">${escapeHtml(snapshot.labels.paginationPrevious)}</span></button><span>${escapeHtml(snapshot.labels.paginationPage)} ${snapshot.currentPage} ${escapeHtml(snapshot.labels.paginationOf)} ${snapshot.totalPages}</span><button type="button" class="action action-secondary pagination-button" data-action="page-next" aria-label="${escapeHtml(snapshot.labels.paginationNext)}" ${snapshot.currentPage >= snapshot.totalPages ? "disabled" : ""}>${this.renderIconWithClass("pagination-icon", "paginationNext")}<span class="sr-only">${escapeHtml(snapshot.labels.paginationNext)}</span></button><label class="pagination-size"><span class="sr-only">${escapeHtml(snapshot.labels.paginationRows)}</span><select class="page-size" data-role="page-size">${pageSizes.map(
|
|
1341
|
+
(size) => `<option value="${size}" ${size === snapshot.pageSize ? "selected" : ""}>${size}</option>`
|
|
1342
|
+
).join("")}</select></label></div></footer>`;
|
|
1343
|
+
}
|
|
1344
|
+
renderSlotRegistry(columns) {
|
|
1345
|
+
const cellSlots = columns.map((column) => `<slot name="${escapeHtml(this.cellSlotName(column))}"></slot>`).join("");
|
|
1346
|
+
return `<div hidden class="slot-registry">${cellSlots}<slot name="expandable-row"></slot></div>`;
|
|
1347
|
+
}
|
|
1348
|
+
renderCellTemplate(row, column, displayIndex) {
|
|
1349
|
+
const templateMarkup = this.getTemplateMarkup(this.cellSlotName(column));
|
|
1350
|
+
if (!templateMarkup) {
|
|
1351
|
+
return `<span class="cell-value">${escapeHtml(this.controller?.displayValue(row, column) ?? "")}</span>`;
|
|
1352
|
+
}
|
|
1353
|
+
const rawRow = row.entity;
|
|
1354
|
+
const rawValue = (0, import_ui_grid_core2.getCellValue)(rawRow, column);
|
|
1355
|
+
const valueText = rawValue == null ? "" : String(rawValue);
|
|
1356
|
+
return this.interpolateTemplate(templateMarkup, {
|
|
1357
|
+
$implicit: rawValue,
|
|
1358
|
+
value: rawValue,
|
|
1359
|
+
valueText,
|
|
1360
|
+
valueLower: valueText.toLowerCase(),
|
|
1361
|
+
row: rawRow,
|
|
1362
|
+
column,
|
|
1363
|
+
rowIndex: this.rowIndexFor(row, displayIndex)
|
|
1364
|
+
});
|
|
1365
|
+
}
|
|
1366
|
+
renderExpandableTemplate(row) {
|
|
1367
|
+
const templateMarkup = this.getTemplateMarkup("expandable-row");
|
|
1368
|
+
if (!templateMarkup) {
|
|
1369
|
+
return `<p>${escapeHtml(String(row.entity["name"] ?? row.id))}</p>`;
|
|
1370
|
+
}
|
|
1371
|
+
return this.interpolateTemplate(templateMarkup, {
|
|
1372
|
+
$implicit: row.entity,
|
|
1373
|
+
row: row.entity,
|
|
1374
|
+
expanded: row.expanded,
|
|
1375
|
+
rowIndex: this.rowIndexFor(row)
|
|
1376
|
+
});
|
|
1377
|
+
}
|
|
1378
|
+
getTemplateMarkup(slotName) {
|
|
1379
|
+
const template = this.querySelector(`template[slot="${slotName}"]`);
|
|
1380
|
+
return template?.innerHTML ?? null;
|
|
1381
|
+
}
|
|
1382
|
+
interpolateTemplate(templateMarkup, context) {
|
|
1383
|
+
return templateMarkup.replace(/{{\s*([^}]+?)\s*}}/g, (_match, expression) => {
|
|
1384
|
+
const value = this.resolveTemplateValue(context, String(expression).trim());
|
|
1385
|
+
return escapeHtml(value);
|
|
1386
|
+
});
|
|
1387
|
+
}
|
|
1388
|
+
resolveTemplateValue(context, expression) {
|
|
1389
|
+
const segments = expression.split(".").filter(Boolean);
|
|
1390
|
+
let current = context;
|
|
1391
|
+
for (const segment of segments) {
|
|
1392
|
+
if (current == null || typeof current !== "object") {
|
|
1393
|
+
return "";
|
|
1394
|
+
}
|
|
1395
|
+
current = current[segment];
|
|
1396
|
+
}
|
|
1397
|
+
return current ?? "";
|
|
1398
|
+
}
|
|
1399
|
+
rowIndexFor(row, fallback = 0) {
|
|
1400
|
+
return this.snapshot?.pipeline.visibleRows.findIndex((candidate) => candidate.id === row.id) ?? fallback;
|
|
1401
|
+
}
|
|
1402
|
+
cellSlotName(column) {
|
|
1403
|
+
return `cell-${column.name}`;
|
|
1404
|
+
}
|
|
1405
|
+
downloadCsv() {
|
|
1406
|
+
if (!this.snapshot) {
|
|
1407
|
+
return;
|
|
1408
|
+
}
|
|
1409
|
+
const csv = (0, import_ui_grid_core2.exportCsvRows)(this.snapshot.visibleColumns, this.snapshot.pipeline.visibleRows);
|
|
1410
|
+
const filename = (0, import_ui_grid_core2.sanitizeDownloadFilename)(`${this.snapshot.options.id}.csv`);
|
|
1411
|
+
(0, import_ui_grid_core2.downloadGridCsvFile)(csv, filename);
|
|
1412
|
+
}
|
|
1413
|
+
renderControlIcon(key) {
|
|
1414
|
+
return this.renderIconWithClass("control-icon", key);
|
|
1415
|
+
}
|
|
1416
|
+
renderIconWithClass(svgClass, key) {
|
|
1417
|
+
const icon = this.iconOverrides[key] ?? DEFAULT_ICONS[key];
|
|
1418
|
+
const viewBox = escapeHtml(icon.viewBox ?? "0 0 24 24");
|
|
1419
|
+
const path = escapeHtml(icon.path);
|
|
1420
|
+
return `<svg class="${svgClass}" viewBox="${viewBox}" aria-hidden="true" focusable="false"><path d="${path}"></path></svg>`;
|
|
1421
|
+
}
|
|
1422
|
+
};
|
|
1423
|
+
async function defineStandaloneUiGridElement(tagName = "ui-grid-element") {
|
|
1424
|
+
if (!customElements.get(tagName)) {
|
|
1425
|
+
customElements.define(tagName, UiGridStandaloneElement);
|
|
1426
|
+
}
|
|
1427
|
+
}
|
|
1428
|
+
|
|
1429
|
+
// src/index.ts
|
|
1430
|
+
async function registerVanillaUiGridRustModule(module2, input) {
|
|
1431
|
+
await module2.default(input);
|
|
1432
|
+
(0, import_ui_grid_core3.registerRustWasmGridEngine)({
|
|
1433
|
+
buildPipeline(context) {
|
|
1434
|
+
return module2.build_pipeline_js(context);
|
|
1435
|
+
}
|
|
1436
|
+
});
|
|
1437
|
+
}
|
|
1438
|
+
async function mountVanillaUiGrid(target, options, rustModule, tagName = "ui-grid-element") {
|
|
1439
|
+
if (rustModule) {
|
|
1440
|
+
await registerVanillaUiGridRustModule(rustModule);
|
|
1441
|
+
}
|
|
1442
|
+
await defineStandaloneUiGridElement(tagName);
|
|
1443
|
+
const grid = document.createElement(tagName);
|
|
1444
|
+
grid.options = options;
|
|
1445
|
+
target.replaceChildren(grid);
|
|
1446
|
+
return grid;
|
|
1447
|
+
}
|
|
1448
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
1449
|
+
0 && (module.exports = {
|
|
1450
|
+
UiGridStandaloneElement,
|
|
1451
|
+
createVanillaGridController,
|
|
1452
|
+
defineStandaloneUiGridElement,
|
|
1453
|
+
defineUiGridElement,
|
|
1454
|
+
mountVanillaUiGrid,
|
|
1455
|
+
registerVanillaUiGridRustModule
|
|
1456
|
+
});
|