@gridkitjs/core 0.17.0 → 0.19.0
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/dist/chunk-WLM4AZXN.js +3580 -0
- package/dist/chunk-WLM4AZXN.js.map +1 -0
- package/dist/filterEditor-C4x0X-nh.d.ts +3886 -0
- package/dist/index.d.ts +9 -4007
- package/dist/index.js +368 -3841
- package/dist/index.js.map +1 -1
- package/dist/renderer.d.ts +344 -0
- package/dist/renderer.js +481 -0
- package/dist/renderer.js.map +1 -0
- package/package.json +6 -1
package/dist/index.js
CHANGED
|
@@ -1,360 +1,98 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
capabilities.filterable === true ? "Alt+Shift+ArrowDown" : "",
|
|
97
|
-
// The ContextMenu key needs no mention: it says what it does on its face.
|
|
98
|
-
capabilities.contextMenu === true ? "Shift+F10" : ""
|
|
99
|
-
].filter(Boolean).join(" ");
|
|
100
|
-
}
|
|
101
|
-
function accessDotted(obj, path) {
|
|
102
|
-
return path.split(".").reduce((value, key) => isNested(value) ? value[key] : void 0, obj);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
// src/util/position.ts
|
|
106
|
-
function renumberRows(entries) {
|
|
107
|
-
return entries.map(
|
|
108
|
-
(entry, index) => entry.rowIndex === index && entry.datasetIndex === index ? entry : { ...entry, rowIndex: index, datasetIndex: index }
|
|
109
|
-
);
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
// src/util/sorting.ts
|
|
113
|
-
function isEmpty(value) {
|
|
114
|
-
return value === null || value === void 0;
|
|
115
|
-
}
|
|
116
|
-
function toTime(value) {
|
|
117
|
-
return value instanceof Date ? value.getTime() : new Date(String(value)).getTime();
|
|
118
|
-
}
|
|
119
|
-
function isFiniteNumber(value) {
|
|
120
|
-
return typeof value === "number" && Number.isFinite(value);
|
|
121
|
-
}
|
|
122
|
-
function isValidDate(value) {
|
|
123
|
-
return value instanceof Date && !Number.isNaN(value.getTime());
|
|
124
|
-
}
|
|
125
|
-
function compareUntyped(a, b) {
|
|
126
|
-
if (isFiniteNumber(a) && isFiniteNumber(b)) {
|
|
127
|
-
return a - b;
|
|
128
|
-
}
|
|
129
|
-
if (isValidDate(a) && isValidDate(b)) {
|
|
130
|
-
return a.getTime() - b.getTime();
|
|
131
|
-
}
|
|
132
|
-
return String(a).localeCompare(String(b));
|
|
133
|
-
}
|
|
134
|
-
function compareValues(a, b, type) {
|
|
135
|
-
if (isEmpty(a)) {
|
|
136
|
-
return isEmpty(b) ? 0 : 1;
|
|
137
|
-
}
|
|
138
|
-
if (isEmpty(b)) {
|
|
139
|
-
return -1;
|
|
140
|
-
}
|
|
141
|
-
switch (type) {
|
|
142
|
-
case "number":
|
|
143
|
-
case "decimal":
|
|
144
|
-
case "currency":
|
|
145
|
-
case "percent":
|
|
146
|
-
return Number(a) - Number(b);
|
|
147
|
-
case "boolean":
|
|
148
|
-
return Number(Boolean(a)) - Number(Boolean(b));
|
|
149
|
-
case "date":
|
|
150
|
-
case "dateTime":
|
|
151
|
-
case "time":
|
|
152
|
-
return toTime(a) - toTime(b);
|
|
153
|
-
case void 0:
|
|
154
|
-
return compareUntyped(a, b);
|
|
155
|
-
default:
|
|
156
|
-
return String(a).localeCompare(String(b));
|
|
157
|
-
}
|
|
158
|
-
}
|
|
159
|
-
function sortDirectionFor(sort, columnId) {
|
|
160
|
-
return sort.find((entry) => entry.columnId === columnId)?.direction ?? null;
|
|
161
|
-
}
|
|
162
|
-
function sortPriorityFor(sort, columnId) {
|
|
163
|
-
const index = sort.findIndex((entry) => entry.columnId === columnId);
|
|
164
|
-
return index === -1 ? null : index + 1;
|
|
165
|
-
}
|
|
166
|
-
function toggleColumnSort(sort, columnId, options) {
|
|
167
|
-
const index = sort.findIndex((entry) => entry.columnId === columnId);
|
|
168
|
-
const isSoleEntry = sort.length === 1 && index === 0;
|
|
169
|
-
if (!options.stack && !isSoleEntry) {
|
|
170
|
-
return [{ columnId, direction: "asc" }];
|
|
171
|
-
}
|
|
172
|
-
const current = index === -1 ? void 0 : sort[index]?.direction;
|
|
173
|
-
const next = current === void 0 ? "asc" : current === "asc" ? "desc" : null;
|
|
174
|
-
if (next === null) {
|
|
175
|
-
return sort.filter((entry) => entry.columnId !== columnId);
|
|
176
|
-
}
|
|
177
|
-
if (index === -1) {
|
|
178
|
-
return [...sort, { columnId, direction: next }];
|
|
179
|
-
}
|
|
180
|
-
return sort.map(
|
|
181
|
-
(entry, i) => i === index ? { columnId, direction: next } : entry
|
|
182
|
-
);
|
|
183
|
-
}
|
|
184
|
-
function sortRows(rows, sort, columns) {
|
|
185
|
-
if (sort.length === 0) {
|
|
186
|
-
return rows;
|
|
187
|
-
}
|
|
188
|
-
const byId = new Map(columns.map((entry) => [entry.id, entry.column]));
|
|
189
|
-
const active = sort.filter((entry) => byId.has(entry.columnId));
|
|
190
|
-
if (active.length === 0) {
|
|
191
|
-
return rows;
|
|
192
|
-
}
|
|
193
|
-
const sorted = [...rows].sort((a, b) => {
|
|
194
|
-
for (const { columnId, direction } of active) {
|
|
195
|
-
const column = byId.get(columnId);
|
|
196
|
-
if (column === void 0) {
|
|
197
|
-
continue;
|
|
198
|
-
}
|
|
199
|
-
const left = accessDotted(a.row, column.field);
|
|
200
|
-
const right = accessDotted(b.row, column.field);
|
|
201
|
-
const leftEmpty = isEmpty(left);
|
|
202
|
-
const rightEmpty = isEmpty(right);
|
|
203
|
-
if (leftEmpty || rightEmpty) {
|
|
204
|
-
if (leftEmpty && rightEmpty) {
|
|
205
|
-
continue;
|
|
206
|
-
}
|
|
207
|
-
return leftEmpty ? 1 : -1;
|
|
208
|
-
}
|
|
209
|
-
const result = compareValues(left, right, column.type);
|
|
210
|
-
if (result !== 0) {
|
|
211
|
-
return direction === "asc" ? result : -result;
|
|
212
|
-
}
|
|
213
|
-
}
|
|
214
|
-
return 0;
|
|
215
|
-
});
|
|
216
|
-
return renumberRows(sorted);
|
|
217
|
-
}
|
|
218
|
-
|
|
219
|
-
// src/util/grouping.ts
|
|
220
|
-
function groupRowId(path) {
|
|
221
|
-
return JSON.stringify(path);
|
|
222
|
-
}
|
|
223
|
-
function bucketKey(value) {
|
|
224
|
-
if (value === null || value === void 0) {
|
|
225
|
-
return "\0empty";
|
|
226
|
-
}
|
|
227
|
-
if (value instanceof Date) {
|
|
228
|
-
return `\0date:${String(value.getTime())}`;
|
|
229
|
-
}
|
|
230
|
-
switch (typeof value) {
|
|
231
|
-
case "string":
|
|
232
|
-
case "number":
|
|
233
|
-
case "boolean":
|
|
234
|
-
case "bigint":
|
|
235
|
-
case "symbol":
|
|
236
|
-
return `\0${typeof value}:${String(value)}`;
|
|
237
|
-
case "function":
|
|
238
|
-
return "\0function";
|
|
239
|
-
default:
|
|
240
|
-
return `\0object:${JSON.stringify(value)}`;
|
|
241
|
-
}
|
|
242
|
-
}
|
|
243
|
-
function partitionByValue(rows, column, direction) {
|
|
244
|
-
const buckets = /* @__PURE__ */ new Map();
|
|
245
|
-
for (const row of rows) {
|
|
246
|
-
const value = accessDotted(row.row, column.field);
|
|
247
|
-
const key = bucketKey(value);
|
|
248
|
-
const bucket = buckets.get(key);
|
|
249
|
-
if (bucket === void 0) {
|
|
250
|
-
buckets.set(key, { value, rows: [row] });
|
|
251
|
-
} else {
|
|
252
|
-
bucket.rows.push(row);
|
|
253
|
-
}
|
|
254
|
-
}
|
|
255
|
-
const groups = [...buckets.values()];
|
|
256
|
-
groups.sort((a, b) => {
|
|
257
|
-
const result = compareValues(a.value, b.value, column.type);
|
|
258
|
-
return direction === "asc" ? result : -result;
|
|
259
|
-
});
|
|
260
|
-
return groups;
|
|
261
|
-
}
|
|
262
|
-
function buildLevel(rows, levels, parentPath, expansion, byId, out) {
|
|
263
|
-
const level = levels[0];
|
|
264
|
-
if (level === void 0) {
|
|
265
|
-
out.push(...rows);
|
|
266
|
-
return;
|
|
267
|
-
}
|
|
268
|
-
const column = byId.get(level.columnId);
|
|
269
|
-
if (column === void 0) {
|
|
270
|
-
out.push(...rows);
|
|
271
|
-
return;
|
|
272
|
-
}
|
|
273
|
-
const rest = levels.slice(1);
|
|
274
|
-
const groups = partitionByValue(rows, column, level.direction ?? "asc");
|
|
275
|
-
for (const group of groups) {
|
|
276
|
-
const path = [...parentPath, group.value];
|
|
277
|
-
const groupId = groupRowId(path);
|
|
278
|
-
const expanded = isGroupExpanded(expansion, groupId);
|
|
279
|
-
const header = {
|
|
280
|
-
kind: "group",
|
|
281
|
-
groupId,
|
|
282
|
-
level: parentPath.length,
|
|
283
|
-
columnId: level.columnId,
|
|
284
|
-
value: group.value,
|
|
285
|
-
path,
|
|
286
|
-
expanded,
|
|
287
|
-
count: group.rows.length,
|
|
288
|
-
// Both set by `groupRows` once it has the whole flattened array.
|
|
289
|
-
rowIndex: -1,
|
|
290
|
-
datasetIndex: -1,
|
|
291
|
-
// Set by `withGroupAggregates`, downstream of grouping — empty here
|
|
292
|
-
// since `groupRows` itself never knows about `AggregateState`.
|
|
293
|
-
aggregates: /* @__PURE__ */ new Map()
|
|
294
|
-
};
|
|
295
|
-
out.push(header);
|
|
296
|
-
if (expanded) {
|
|
297
|
-
buildLevel(group.rows, rest, path, expansion, byId, out);
|
|
298
|
-
}
|
|
299
|
-
}
|
|
300
|
-
}
|
|
301
|
-
function groupRows(rows, groupBy, expansion, columns) {
|
|
302
|
-
if (groupBy.length === 0) {
|
|
303
|
-
return rows;
|
|
304
|
-
}
|
|
305
|
-
const byId = new Map(columns.map((entry) => [entry.id, entry.column]));
|
|
306
|
-
const active = groupBy.filter((entry) => byId.has(entry.columnId));
|
|
307
|
-
if (active.length === 0) {
|
|
308
|
-
return rows;
|
|
309
|
-
}
|
|
310
|
-
const out = [];
|
|
311
|
-
buildLevel(rows, active, [], expansion, byId, out);
|
|
312
|
-
return renumberRows(out);
|
|
313
|
-
}
|
|
314
|
-
var ALL_EXPANDED = {
|
|
315
|
-
mode: "allExpanded",
|
|
316
|
-
except: []
|
|
317
|
-
};
|
|
318
|
-
var ALL_COLLAPSED = {
|
|
319
|
-
mode: "allCollapsed",
|
|
320
|
-
except: []
|
|
321
|
-
};
|
|
322
|
-
function isGroupExpanded(expansion, groupId) {
|
|
323
|
-
const excepted = expansion.except.includes(groupId);
|
|
324
|
-
return expansion.mode === "allExpanded" ? !excepted : excepted;
|
|
325
|
-
}
|
|
326
|
-
function toggleGroupExpansion(expansion, groupId) {
|
|
327
|
-
const except = expansion.except.includes(groupId) ? expansion.except.filter((id) => id !== groupId) : [...expansion.except, groupId];
|
|
328
|
-
return { mode: expansion.mode, except };
|
|
329
|
-
}
|
|
330
|
-
function expandAllGroups(expansion) {
|
|
331
|
-
return isWithoutExceptions(expansion, "allExpanded") ? expansion : ALL_EXPANDED;
|
|
332
|
-
}
|
|
333
|
-
function collapseAllGroups(expansion) {
|
|
334
|
-
return isWithoutExceptions(expansion, "allCollapsed") ? expansion : ALL_COLLAPSED;
|
|
335
|
-
}
|
|
336
|
-
function isWithoutExceptions(expansion, mode) {
|
|
337
|
-
return expansion.mode === mode && expansion.except.length === 0;
|
|
338
|
-
}
|
|
339
|
-
function moveGroupByBefore(groupBy, columnId, beforeColumnId) {
|
|
340
|
-
if (columnId === beforeColumnId) {
|
|
341
|
-
return groupBy;
|
|
342
|
-
}
|
|
343
|
-
const without = groupBy.filter((entry) => entry.columnId !== columnId);
|
|
344
|
-
const moved = groupBy.find((entry) => entry.columnId === columnId) ?? {
|
|
345
|
-
columnId
|
|
346
|
-
};
|
|
347
|
-
const target = beforeColumnId === null ? without.length : without.findIndex((entry) => entry.columnId === beforeColumnId);
|
|
348
|
-
if (target === -1) {
|
|
349
|
-
return groupBy;
|
|
350
|
-
}
|
|
351
|
-
const next = [...without];
|
|
352
|
-
next.splice(target, 0, moved);
|
|
353
|
-
return next.length === groupBy.length && next.every((entry, index) => entry === groupBy[index]) ? groupBy : next;
|
|
354
|
-
}
|
|
355
|
-
function movesGroupBy(groupBy, columnId, beforeColumnId) {
|
|
356
|
-
return moveGroupByBefore(groupBy, columnId, beforeColumnId) !== groupBy;
|
|
357
|
-
}
|
|
1
|
+
import {
|
|
2
|
+
ALL_COLLAPSED,
|
|
3
|
+
ALL_EXPANDED,
|
|
4
|
+
DEFAULT_COLUMN_SIZES,
|
|
5
|
+
DEFAULT_FILTER_VALUE_LIMIT,
|
|
6
|
+
NO_CELL_SELECTED,
|
|
7
|
+
accessDotted,
|
|
8
|
+
alignmentForType,
|
|
9
|
+
applyColumnOrder,
|
|
10
|
+
applyColumnPinning,
|
|
11
|
+
applyColumnVisibility,
|
|
12
|
+
applySelectionIntent,
|
|
13
|
+
bodyFocus,
|
|
14
|
+
buildExportTable,
|
|
15
|
+
builtInCommands,
|
|
16
|
+
clearAllFilters,
|
|
17
|
+
clearCellSelection,
|
|
18
|
+
clearSelection,
|
|
19
|
+
collapseAllGroups,
|
|
20
|
+
collapseSeparators,
|
|
21
|
+
compareValues,
|
|
22
|
+
computeAggregates,
|
|
23
|
+
contextMenuEntries,
|
|
24
|
+
createDefaultMessages,
|
|
25
|
+
csvWriter,
|
|
26
|
+
defaultContextMenu,
|
|
27
|
+
defaultFilterOperators,
|
|
28
|
+
defaultMessages,
|
|
29
|
+
defineColumnsFromRows,
|
|
30
|
+
diffSelection,
|
|
31
|
+
expandAllGroups,
|
|
32
|
+
exportFile,
|
|
33
|
+
exportPrintDocument,
|
|
34
|
+
filterQueryFor,
|
|
35
|
+
filterRows,
|
|
36
|
+
fitColumnsToWidth,
|
|
37
|
+
formatAggregateValue,
|
|
38
|
+
formatCellValue,
|
|
39
|
+
formatGroupValue,
|
|
40
|
+
getColumnId,
|
|
41
|
+
groupRowId,
|
|
42
|
+
groupRows,
|
|
43
|
+
headerFocus,
|
|
44
|
+
isColumnFiltered,
|
|
45
|
+
isColumnVisible,
|
|
46
|
+
isDateType,
|
|
47
|
+
isGroupExpanded,
|
|
48
|
+
isSameCell,
|
|
49
|
+
isScalarList,
|
|
50
|
+
jsonWriter,
|
|
51
|
+
matchesQuery,
|
|
52
|
+
moveColumnBefore,
|
|
53
|
+
moveColumnInPinGroup,
|
|
54
|
+
moveGroupByBefore,
|
|
55
|
+
reportError,
|
|
56
|
+
resolveCell,
|
|
57
|
+
resolveColumnHeaderText,
|
|
58
|
+
resolveColumnLabel,
|
|
59
|
+
resolveColumnPin,
|
|
60
|
+
resolveColumnWidths,
|
|
61
|
+
resolveColumns,
|
|
62
|
+
resolveCommands,
|
|
63
|
+
resolveDataColumns,
|
|
64
|
+
resolveExportWriters,
|
|
65
|
+
resolveMenu,
|
|
66
|
+
resolveMenuEntry,
|
|
67
|
+
resolveMessages,
|
|
68
|
+
resolveRowId,
|
|
69
|
+
resolveRows,
|
|
70
|
+
resolveShownRows,
|
|
71
|
+
revertColumnSize,
|
|
72
|
+
runCommand,
|
|
73
|
+
selectAll,
|
|
74
|
+
selectCell,
|
|
75
|
+
selectOnly,
|
|
76
|
+
selectRange,
|
|
77
|
+
setColumnFilter,
|
|
78
|
+
setColumnPin,
|
|
79
|
+
setColumnVisibility,
|
|
80
|
+
sortDirectionFor,
|
|
81
|
+
sortPriorityFor,
|
|
82
|
+
sortRows,
|
|
83
|
+
toCsv,
|
|
84
|
+
toDate,
|
|
85
|
+
toHtmlTable,
|
|
86
|
+
toJson,
|
|
87
|
+
toTsv,
|
|
88
|
+
toggleCellSelection,
|
|
89
|
+
toggleColumnSort,
|
|
90
|
+
toggleGroupExpansion,
|
|
91
|
+
toggleSelection,
|
|
92
|
+
unknownDisplayRow,
|
|
93
|
+
unknownFilterEntry,
|
|
94
|
+
withGroupAggregates
|
|
95
|
+
} from "./chunk-WLM4AZXN.js";
|
|
358
96
|
|
|
359
97
|
// src/util/memoize.ts
|
|
360
98
|
function memoizeLast(compute) {
|
|
@@ -370,60 +108,6 @@ function memoizeLast(compute) {
|
|
|
370
108
|
};
|
|
371
109
|
}
|
|
372
110
|
|
|
373
|
-
// src/util/ordering.ts
|
|
374
|
-
function applyColumnOrder(columns, order) {
|
|
375
|
-
if (order.length === 0) {
|
|
376
|
-
return columns;
|
|
377
|
-
}
|
|
378
|
-
const byId = new Map(columns.map((column) => [getColumnId(column), column]));
|
|
379
|
-
const listed = order.map((id) => byId.get(id)).filter((column) => column !== void 0);
|
|
380
|
-
const taken = new Set(listed.map((column) => getColumnId(column)));
|
|
381
|
-
return [
|
|
382
|
-
...listed,
|
|
383
|
-
...columns.filter((column) => !taken.has(getColumnId(column)))
|
|
384
|
-
];
|
|
385
|
-
}
|
|
386
|
-
function resolveDataColumns(columns, order) {
|
|
387
|
-
return applyColumnOrder(columns, order).map((column) => ({
|
|
388
|
-
id: getColumnId(column),
|
|
389
|
-
column
|
|
390
|
-
}));
|
|
391
|
-
}
|
|
392
|
-
function moveColumnBefore(orderedIds, movedId, beforeId) {
|
|
393
|
-
if (movedId === beforeId || !orderedIds.includes(movedId)) {
|
|
394
|
-
return orderedIds;
|
|
395
|
-
}
|
|
396
|
-
const without = orderedIds.filter((id) => id !== movedId);
|
|
397
|
-
const target = beforeId === null ? without.length : without.indexOf(beforeId);
|
|
398
|
-
if (target === -1) {
|
|
399
|
-
return orderedIds;
|
|
400
|
-
}
|
|
401
|
-
const next = [...without];
|
|
402
|
-
next.splice(target, 0, movedId);
|
|
403
|
-
return next.every((id, index) => id === orderedIds[index]) ? orderedIds : next;
|
|
404
|
-
}
|
|
405
|
-
function movesColumn(orderedIds, movedId, beforeId) {
|
|
406
|
-
return moveColumnBefore(orderedIds, movedId, beforeId) !== orderedIds;
|
|
407
|
-
}
|
|
408
|
-
function resolveDropBefore(orderedIds, targetId, side) {
|
|
409
|
-
if (side === "before") {
|
|
410
|
-
return targetId;
|
|
411
|
-
}
|
|
412
|
-
const index = orderedIds.indexOf(targetId);
|
|
413
|
-
return index === -1 ? null : orderedIds[index + 1] ?? null;
|
|
414
|
-
}
|
|
415
|
-
function resolveKeyboardDropTarget(orderedIds, columnId, direction) {
|
|
416
|
-
const index = orderedIds.indexOf(columnId);
|
|
417
|
-
if (index === -1) {
|
|
418
|
-
return void 0;
|
|
419
|
-
}
|
|
420
|
-
const targetIndex = direction === -1 ? index - 1 : index + 2;
|
|
421
|
-
if (targetIndex < 0) {
|
|
422
|
-
return void 0;
|
|
423
|
-
}
|
|
424
|
-
return orderedIds[targetIndex] ?? null;
|
|
425
|
-
}
|
|
426
|
-
|
|
427
111
|
// src/util/paging.ts
|
|
428
112
|
var NO_HEADERS = [];
|
|
429
113
|
function groupUnitsOf(rows) {
|
|
@@ -435,7 +119,7 @@ function groupUnitsOf(rows) {
|
|
|
435
119
|
if (entry === void 0) {
|
|
436
120
|
continue;
|
|
437
121
|
}
|
|
438
|
-
const isTopLevelHeader =
|
|
122
|
+
const isTopLevelHeader = entry.kind === "group" && entry.level === 0;
|
|
439
123
|
const isBoundary = index !== start && (isTopLevelHeader || !openedByGroup);
|
|
440
124
|
if (isBoundary) {
|
|
441
125
|
units.push({ start, end: index, headers: NO_HEADERS });
|
|
@@ -458,19 +142,27 @@ function rowUnitsOf(rows) {
|
|
|
458
142
|
if (entry === void 0) {
|
|
459
143
|
continue;
|
|
460
144
|
}
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
145
|
+
switch (entry.kind) {
|
|
146
|
+
case "data":
|
|
147
|
+
units.push({ start: index, end: index + 1, headers: open });
|
|
148
|
+
break;
|
|
149
|
+
case "group": {
|
|
150
|
+
const ancestors = open.slice(0, entry.level);
|
|
151
|
+
open = entry.expanded ? [...ancestors, entry] : ancestors;
|
|
152
|
+
if (!entry.expanded) {
|
|
153
|
+
units.push({ start: index, end: index + 1, headers: ancestors });
|
|
154
|
+
}
|
|
155
|
+
break;
|
|
468
156
|
}
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
157
|
+
case "group-summary": {
|
|
158
|
+
const last = units.at(-1);
|
|
159
|
+
if (last !== void 0) {
|
|
160
|
+
units[units.length - 1] = { ...last, end: index + 1 };
|
|
161
|
+
}
|
|
162
|
+
break;
|
|
473
163
|
}
|
|
164
|
+
default:
|
|
165
|
+
unknownDisplayRow(entry);
|
|
474
166
|
}
|
|
475
167
|
}
|
|
476
168
|
return units;
|
|
@@ -498,387 +190,92 @@ function paginateRows(rows, pagination, options = {}) {
|
|
|
498
190
|
return { rows: renumbered, pageCount, pageIndex };
|
|
499
191
|
}
|
|
500
192
|
|
|
501
|
-
// src/util/
|
|
502
|
-
function
|
|
503
|
-
|
|
504
|
-
}
|
|
505
|
-
|
|
506
|
-
// src/util/filterOperators.ts
|
|
507
|
-
var matchNothing = () => false;
|
|
508
|
-
function kindOf(type) {
|
|
509
|
-
switch (type) {
|
|
510
|
-
case "number":
|
|
511
|
-
case "decimal":
|
|
512
|
-
case "currency":
|
|
513
|
-
case "percent":
|
|
514
|
-
return "number";
|
|
515
|
-
case "boolean":
|
|
516
|
-
return "boolean";
|
|
517
|
-
case "date":
|
|
518
|
-
case "dateTime":
|
|
519
|
-
case "time":
|
|
520
|
-
return "date";
|
|
521
|
-
default:
|
|
522
|
-
return "text";
|
|
523
|
-
}
|
|
524
|
-
}
|
|
525
|
-
function isDateType(type) {
|
|
526
|
-
return kindOf(type) === "date";
|
|
527
|
-
}
|
|
528
|
-
function isEmptyCell(value) {
|
|
529
|
-
return value === null || value === void 0 || value === "";
|
|
193
|
+
// src/util/serialize.ts
|
|
194
|
+
function serializeScalar(scalar) {
|
|
195
|
+
return scalar instanceof Date ? scalar.toISOString() : scalar;
|
|
530
196
|
}
|
|
531
|
-
function
|
|
532
|
-
|
|
533
|
-
return date === void 0 || Number.isNaN(date.getTime()) ? void 0 : date;
|
|
197
|
+
function serializeOperand(operand) {
|
|
198
|
+
return isScalarList(operand) ? operand.map(serializeScalar) : serializeScalar(operand);
|
|
534
199
|
}
|
|
535
|
-
function
|
|
536
|
-
switch (kind) {
|
|
537
|
-
case "
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
case "
|
|
542
|
-
|
|
200
|
+
function serializeEntry(entry) {
|
|
201
|
+
switch (entry.kind) {
|
|
202
|
+
case "group": {
|
|
203
|
+
const entries = serializeFilter(entry.entries);
|
|
204
|
+
return entries.length === 0 && entry.entries.length > 0 ? void 0 : { kind: "group", combinator: entry.combinator, entries };
|
|
205
|
+
}
|
|
206
|
+
case "predicate":
|
|
207
|
+
reportError(
|
|
208
|
+
entry.columnId === void 0 ? "a predicate filter entry across every column cannot be serialised, so it is left out of the saved state." : `a predicate filter entry on \`${entry.columnId}\` cannot be serialised, so it is left out of the saved state.`
|
|
209
|
+
);
|
|
210
|
+
return void 0;
|
|
211
|
+
case "operator": {
|
|
212
|
+
const { value, ...rest } = entry;
|
|
213
|
+
return value === void 0 ? rest : { ...rest, value: serializeOperand(value) };
|
|
214
|
+
}
|
|
215
|
+
case "value": {
|
|
216
|
+
const { value, ...rest } = entry;
|
|
217
|
+
return {
|
|
218
|
+
...rest,
|
|
219
|
+
value: value instanceof Date ? value.toISOString() : value
|
|
220
|
+
};
|
|
221
|
+
}
|
|
543
222
|
case "text":
|
|
544
|
-
return
|
|
223
|
+
return entry;
|
|
224
|
+
default:
|
|
225
|
+
return unknownFilterEntry(entry);
|
|
545
226
|
}
|
|
546
227
|
}
|
|
547
|
-
function
|
|
548
|
-
|
|
549
|
-
return comparable(operand, kind) !== void 0;
|
|
550
|
-
}
|
|
551
|
-
return typeof operand === "string" || typeof operand === "number" || typeof operand === "boolean";
|
|
228
|
+
function serializeFilter(filter) {
|
|
229
|
+
return filter.map((entry) => serializeEntry(entry)).filter((entry) => entry !== void 0);
|
|
552
230
|
}
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
return (value) => {
|
|
560
|
-
if (isEmptyCell(value)) {
|
|
561
|
-
return void 0;
|
|
562
|
-
}
|
|
563
|
-
const cell = comparable(value, kind);
|
|
564
|
-
return cell === void 0 ? void 0 : compareValues(cell, target, type);
|
|
231
|
+
var SAVED_STATE_VERSION = 1;
|
|
232
|
+
function serializeGridState(state) {
|
|
233
|
+
return {
|
|
234
|
+
version: SAVED_STATE_VERSION,
|
|
235
|
+
...state,
|
|
236
|
+
filter: serializeFilter(state.filter)
|
|
565
237
|
};
|
|
566
238
|
}
|
|
567
|
-
function
|
|
568
|
-
|
|
569
|
-
}
|
|
570
|
-
function compileOrdering(operator, operand, type) {
|
|
571
|
-
const compare = compileComparison(operand, type);
|
|
572
|
-
if (compare === void 0) {
|
|
573
|
-
return matchNothing;
|
|
239
|
+
function untaggedCellSelection(saved) {
|
|
240
|
+
if (saved === null) {
|
|
241
|
+
return { kind: "none" };
|
|
574
242
|
}
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
return result !== void 0 && holds(result);
|
|
578
|
-
};
|
|
579
|
-
switch (operator) {
|
|
580
|
-
case "eq":
|
|
581
|
-
return where((result) => result === 0);
|
|
582
|
-
case "ne": {
|
|
583
|
-
const equals = where((result) => result === 0);
|
|
584
|
-
return (value) => !equals(value);
|
|
585
|
-
}
|
|
586
|
-
case "gt":
|
|
587
|
-
return where((result) => result > 0);
|
|
588
|
-
case "gte":
|
|
589
|
-
return where((result) => result >= 0);
|
|
590
|
-
case "lt":
|
|
591
|
-
return where((result) => result < 0);
|
|
592
|
-
case "lte":
|
|
593
|
-
return where((result) => result <= 0);
|
|
243
|
+
if (typeof saved === "object" && !("kind" in saved) && "rowId" in saved && typeof saved.rowId === "string" && "columnId" in saved && typeof saved.columnId === "string") {
|
|
244
|
+
return { kind: "cell", rowId: saved.rowId, columnId: saved.columnId };
|
|
594
245
|
}
|
|
246
|
+
return void 0;
|
|
595
247
|
}
|
|
596
|
-
function
|
|
597
|
-
|
|
598
|
-
|
|
248
|
+
function migrateUnversioned(state) {
|
|
249
|
+
let migrated = state;
|
|
250
|
+
if (isStringList(state.groupExpansion)) {
|
|
251
|
+
migrated = {
|
|
252
|
+
...migrated,
|
|
253
|
+
groupExpansion: { mode: "allExpanded", except: state.groupExpansion }
|
|
254
|
+
};
|
|
599
255
|
}
|
|
600
|
-
const
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
if (fromLow === void 0 || fromHigh === void 0) {
|
|
604
|
-
return matchNothing;
|
|
256
|
+
const cellSelection = untaggedCellSelection(state.cellSelection);
|
|
257
|
+
if (cellSelection !== void 0) {
|
|
258
|
+
migrated = { ...migrated, cellSelection };
|
|
605
259
|
}
|
|
606
|
-
return
|
|
607
|
-
const aboveLow = fromLow(value);
|
|
608
|
-
const belowHigh = fromHigh(value);
|
|
609
|
-
return aboveLow !== void 0 && belowHigh !== void 0 && aboveLow >= 0 && belowHigh <= 0;
|
|
610
|
-
};
|
|
611
|
-
}
|
|
612
|
-
function filterValueKey(value, type) {
|
|
613
|
-
return bucketKey(isDateType(type) ? toDate(value) ?? value : value);
|
|
260
|
+
return migrated;
|
|
614
261
|
}
|
|
615
|
-
function
|
|
616
|
-
|
|
617
|
-
|
|
262
|
+
function migrateSavedState(saved) {
|
|
263
|
+
const { version, ...state } = saved;
|
|
264
|
+
if (version === void 0) {
|
|
265
|
+
return migrateUnversioned(state);
|
|
618
266
|
}
|
|
619
|
-
|
|
620
|
-
|
|
267
|
+
if (version === SAVED_STATE_VERSION) {
|
|
268
|
+
return state;
|
|
269
|
+
}
|
|
270
|
+
throw new TypeError(
|
|
271
|
+
`GridKit: a saved state has \`version\` ${JSON.stringify(version)}, and this release reads saved state up to version ${String(SAVED_STATE_VERSION)}.`
|
|
621
272
|
);
|
|
622
|
-
return (value) => !isEmptyCell(value) && keys.has(filterValueKey(value, type));
|
|
623
273
|
}
|
|
624
|
-
function
|
|
625
|
-
|
|
626
|
-
return matchNothing;
|
|
627
|
-
}
|
|
628
|
-
const text = String(operand).toLowerCase();
|
|
629
|
-
const read = (value) => String(value).toLowerCase();
|
|
630
|
-
switch (operator) {
|
|
631
|
-
case "contains":
|
|
632
|
-
return (value) => !isEmptyCell(value) && read(value).includes(text);
|
|
633
|
-
case "notContains":
|
|
634
|
-
return (value) => isEmptyCell(value) || !read(value).includes(text);
|
|
635
|
-
case "startsWith":
|
|
636
|
-
return (value) => !isEmptyCell(value) && read(value).startsWith(text);
|
|
637
|
-
case "endsWith":
|
|
638
|
-
return (value) => !isEmptyCell(value) && read(value).endsWith(text);
|
|
639
|
-
}
|
|
274
|
+
function reviveScalar(scalar, type) {
|
|
275
|
+
return isDateType(type) && typeof scalar === "string" ? toDate(scalar) ?? scalar : scalar;
|
|
640
276
|
}
|
|
641
|
-
function
|
|
642
|
-
|
|
643
|
-
switch (operator) {
|
|
644
|
-
case "isEmpty":
|
|
645
|
-
return isEmptyCell;
|
|
646
|
-
case "isNotEmpty":
|
|
647
|
-
return (cell) => !isEmptyCell(cell);
|
|
648
|
-
case "contains":
|
|
649
|
-
case "notContains":
|
|
650
|
-
case "startsWith":
|
|
651
|
-
case "endsWith":
|
|
652
|
-
return compileText(operator, value);
|
|
653
|
-
case "between":
|
|
654
|
-
return compileBetween(value, type);
|
|
655
|
-
case "in":
|
|
656
|
-
return compileIn(value, type);
|
|
657
|
-
case "eq":
|
|
658
|
-
case "ne":
|
|
659
|
-
case "gt":
|
|
660
|
-
case "gte":
|
|
661
|
-
case "lt":
|
|
662
|
-
case "lte":
|
|
663
|
-
return compileOrdering(operator, value, type);
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
|
|
667
|
-
// src/util/filtering.ts
|
|
668
|
-
function parseFilterPattern(query) {
|
|
669
|
-
const start = query.startsWith("%");
|
|
670
|
-
const end = query.endsWith("%");
|
|
671
|
-
let text = query;
|
|
672
|
-
if (start) {
|
|
673
|
-
text = text.slice(1);
|
|
674
|
-
}
|
|
675
|
-
if (end) {
|
|
676
|
-
text = text.slice(0, -1);
|
|
677
|
-
}
|
|
678
|
-
text = text.toLowerCase();
|
|
679
|
-
if (start && end) {
|
|
680
|
-
return { mode: "contains", text };
|
|
681
|
-
}
|
|
682
|
-
if (start) {
|
|
683
|
-
return { mode: "endsWith", text };
|
|
684
|
-
}
|
|
685
|
-
if (end) {
|
|
686
|
-
return { mode: "startsWith", text };
|
|
687
|
-
}
|
|
688
|
-
return { mode: "exact", text };
|
|
689
|
-
}
|
|
690
|
-
function isEmptyValue(value) {
|
|
691
|
-
return value === null || value === void 0;
|
|
692
|
-
}
|
|
693
|
-
function compileFilterQuery(query) {
|
|
694
|
-
const { mode, text } = parseFilterPattern(query);
|
|
695
|
-
return (value) => {
|
|
696
|
-
const candidate = (isEmptyValue(value) ? "" : String(value)).toLowerCase();
|
|
697
|
-
switch (mode) {
|
|
698
|
-
case "exact":
|
|
699
|
-
return candidate === text;
|
|
700
|
-
case "contains":
|
|
701
|
-
return candidate.includes(text);
|
|
702
|
-
case "startsWith":
|
|
703
|
-
return candidate.startsWith(text);
|
|
704
|
-
case "endsWith":
|
|
705
|
-
return candidate.endsWith(text);
|
|
706
|
-
}
|
|
707
|
-
};
|
|
708
|
-
}
|
|
709
|
-
function matchesTypedValue(value, target, type) {
|
|
710
|
-
if (typeof target === "number") {
|
|
711
|
-
if (type !== "number" && type !== "decimal" && type !== "currency" && type !== "percent") {
|
|
712
|
-
return false;
|
|
713
|
-
}
|
|
714
|
-
return typeof value === "number" && value === target;
|
|
715
|
-
}
|
|
716
|
-
if (typeof target === "boolean") {
|
|
717
|
-
if (type !== "boolean") {
|
|
718
|
-
return false;
|
|
719
|
-
}
|
|
720
|
-
return typeof value === "boolean" && value === target;
|
|
721
|
-
}
|
|
722
|
-
if (type !== "date" && type !== "dateTime" && type !== "time") {
|
|
723
|
-
return false;
|
|
724
|
-
}
|
|
725
|
-
return value instanceof Date && value.getTime() === target.getTime();
|
|
726
|
-
}
|
|
727
|
-
function isEntryUsable(entry, byId) {
|
|
728
|
-
if (entry.kind === "group") {
|
|
729
|
-
return true;
|
|
730
|
-
}
|
|
731
|
-
return entry.columnId === void 0 || byId.has(entry.columnId);
|
|
732
|
-
}
|
|
733
|
-
function unknownFilterEntry(entry) {
|
|
734
|
-
const { kind } = entry;
|
|
735
|
-
throw new TypeError(
|
|
736
|
-
`GridKit: \`${String(kind)}\` is not a filter entry kind.`
|
|
737
|
-
);
|
|
738
|
-
}
|
|
739
|
-
function compileCellTest(columnId, byId, columns, test) {
|
|
740
|
-
if (columnId === void 0) {
|
|
741
|
-
return (row) => columns.some(
|
|
742
|
-
(entry) => test(accessDotted(row, entry.column.field), entry.column.type)
|
|
743
|
-
);
|
|
744
|
-
}
|
|
745
|
-
const column = byId.get(columnId);
|
|
746
|
-
if (column === void 0) {
|
|
747
|
-
return () => false;
|
|
748
|
-
}
|
|
749
|
-
return (row) => test(accessDotted(row, column.field), column.type);
|
|
750
|
-
}
|
|
751
|
-
function compileFilterEntry(entry, byId, columns) {
|
|
752
|
-
switch (entry.kind) {
|
|
753
|
-
case "group": {
|
|
754
|
-
const tests = entry.entries.filter((nested) => isEntryUsable(nested, byId)).map((nested) => compileFilterEntry(nested, byId, columns));
|
|
755
|
-
return entry.combinator === "and" ? (row) => tests.every((test) => test(row)) : (row) => tests.some((test) => test(row));
|
|
756
|
-
}
|
|
757
|
-
case "predicate": {
|
|
758
|
-
const { columnId, predicate } = entry;
|
|
759
|
-
const column = columnId === void 0 ? void 0 : byId.get(columnId);
|
|
760
|
-
return (row) => predicate(
|
|
761
|
-
column === void 0 ? void 0 : accessDotted(row, column.field),
|
|
762
|
-
row
|
|
763
|
-
);
|
|
764
|
-
}
|
|
765
|
-
case "operator": {
|
|
766
|
-
const column = byId.get(entry.columnId);
|
|
767
|
-
if (column === void 0) {
|
|
768
|
-
return () => false;
|
|
769
|
-
}
|
|
770
|
-
const test = compileOperatorEntry(entry, column.type);
|
|
771
|
-
return (row) => test(accessDotted(row, column.field));
|
|
772
|
-
}
|
|
773
|
-
case "value": {
|
|
774
|
-
const { value } = entry;
|
|
775
|
-
return compileCellTest(
|
|
776
|
-
entry.columnId,
|
|
777
|
-
byId,
|
|
778
|
-
columns,
|
|
779
|
-
(cell, type) => matchesTypedValue(cell, value, type)
|
|
780
|
-
);
|
|
781
|
-
}
|
|
782
|
-
case "text": {
|
|
783
|
-
const test = compileFilterQuery(entry.query);
|
|
784
|
-
return compileCellTest(entry.columnId, byId, columns, test);
|
|
785
|
-
}
|
|
786
|
-
default:
|
|
787
|
-
return unknownFilterEntry(entry);
|
|
788
|
-
}
|
|
789
|
-
}
|
|
790
|
-
function compileFilter(filter, columns) {
|
|
791
|
-
const byId = new Map(columns.map((entry) => [entry.id, entry.column]));
|
|
792
|
-
const compiled = filter.filter((entry) => isEntryUsable(entry, byId)).map((entry) => compileFilterEntry(entry, byId, columns));
|
|
793
|
-
return compiled.length === 0 ? void 0 : (row) => compiled.every((test) => test(row));
|
|
794
|
-
}
|
|
795
|
-
function matchesQuery(value, query) {
|
|
796
|
-
return compileFilterQuery(query)(value);
|
|
797
|
-
}
|
|
798
|
-
function filterQueryFor(filter, columnId) {
|
|
799
|
-
const entry = filter.find(
|
|
800
|
-
(candidate) => candidate.kind === "text" && candidate.columnId === columnId
|
|
801
|
-
);
|
|
802
|
-
return entry?.query ?? null;
|
|
803
|
-
}
|
|
804
|
-
function setColumnFilter(filter, columnId, query) {
|
|
805
|
-
const index = filter.findIndex(
|
|
806
|
-
(entry) => entry.kind !== "group" && entry.columnId === columnId
|
|
807
|
-
);
|
|
808
|
-
if (query === "") {
|
|
809
|
-
return index === -1 ? filter : filter.filter((_entry, i) => i !== index);
|
|
810
|
-
}
|
|
811
|
-
const next = columnId === void 0 ? { kind: "text", query } : { kind: "text", columnId, query };
|
|
812
|
-
if (index === -1) {
|
|
813
|
-
return [...filter, next];
|
|
814
|
-
}
|
|
815
|
-
const existing = filter[index];
|
|
816
|
-
if (existing?.kind === "text" && existing.query === query) {
|
|
817
|
-
return filter;
|
|
818
|
-
}
|
|
819
|
-
return filter.map((entry, i) => i === index ? next : entry);
|
|
820
|
-
}
|
|
821
|
-
function clearAllFilters(filter) {
|
|
822
|
-
return filter.length === 0 ? filter : [];
|
|
823
|
-
}
|
|
824
|
-
function filterRows(rows, filter, columns) {
|
|
825
|
-
if (filter.length === 0) {
|
|
826
|
-
return rows;
|
|
827
|
-
}
|
|
828
|
-
const test = compileFilter(filter, columns);
|
|
829
|
-
if (test === void 0) {
|
|
830
|
-
return rows;
|
|
831
|
-
}
|
|
832
|
-
const filtered = rows.filter((row) => test(row.row));
|
|
833
|
-
return renumberRows(filtered);
|
|
834
|
-
}
|
|
835
|
-
|
|
836
|
-
// src/util/serialize.ts
|
|
837
|
-
function serializeScalar(scalar) {
|
|
838
|
-
return scalar instanceof Date ? scalar.toISOString() : scalar;
|
|
839
|
-
}
|
|
840
|
-
function serializeOperand(operand) {
|
|
841
|
-
return isScalarList(operand) ? operand.map(serializeScalar) : serializeScalar(operand);
|
|
842
|
-
}
|
|
843
|
-
function serializeEntry(entry) {
|
|
844
|
-
switch (entry.kind) {
|
|
845
|
-
case "group": {
|
|
846
|
-
const entries = serializeFilter(entry.entries);
|
|
847
|
-
return entries.length === 0 && entry.entries.length > 0 ? void 0 : { kind: "group", combinator: entry.combinator, entries };
|
|
848
|
-
}
|
|
849
|
-
case "predicate":
|
|
850
|
-
reportError(
|
|
851
|
-
entry.columnId === void 0 ? "a predicate filter entry across every column cannot be serialised, so it is left out of the saved state." : `a predicate filter entry on \`${entry.columnId}\` cannot be serialised, so it is left out of the saved state.`
|
|
852
|
-
);
|
|
853
|
-
return void 0;
|
|
854
|
-
case "operator": {
|
|
855
|
-
const { value, ...rest } = entry;
|
|
856
|
-
return value === void 0 ? rest : { ...rest, value: serializeOperand(value) };
|
|
857
|
-
}
|
|
858
|
-
case "value": {
|
|
859
|
-
const { value, ...rest } = entry;
|
|
860
|
-
return {
|
|
861
|
-
...rest,
|
|
862
|
-
value: value instanceof Date ? value.toISOString() : value
|
|
863
|
-
};
|
|
864
|
-
}
|
|
865
|
-
case "text":
|
|
866
|
-
return entry;
|
|
867
|
-
default:
|
|
868
|
-
return unknownFilterEntry(entry);
|
|
869
|
-
}
|
|
870
|
-
}
|
|
871
|
-
function serializeFilter(filter) {
|
|
872
|
-
return filter.map((entry) => serializeEntry(entry)).filter((entry) => entry !== void 0);
|
|
873
|
-
}
|
|
874
|
-
function serializeGridState(state) {
|
|
875
|
-
return { ...state, filter: serializeFilter(state.filter) };
|
|
876
|
-
}
|
|
877
|
-
function reviveScalar(scalar, type) {
|
|
878
|
-
return isDateType(type) && typeof scalar === "string" ? toDate(scalar) ?? scalar : scalar;
|
|
879
|
-
}
|
|
880
|
-
function reviveOperand(operand, type) {
|
|
881
|
-
return isScalarList(operand) ? operand.map((scalar) => reviveScalar(scalar, type)) : reviveScalar(operand, type);
|
|
277
|
+
function reviveOperand(operand, type) {
|
|
278
|
+
return isScalarList(operand) ? operand.map((scalar) => reviveScalar(scalar, type)) : reviveScalar(operand, type);
|
|
882
279
|
}
|
|
883
280
|
function tagged(entry) {
|
|
884
281
|
if ("kind" in entry) {
|
|
@@ -944,404 +341,55 @@ function isGroupExpansion(value) {
|
|
|
944
341
|
return typeof value === "object" && value !== null && "mode" in value && (value.mode === "allExpanded" || value.mode === "allCollapsed") && "except" in value && isStringList(value.except);
|
|
945
342
|
}
|
|
946
343
|
function reviveGroupExpansion(saved) {
|
|
947
|
-
if (isStringList(saved)) {
|
|
948
|
-
return { mode: "allExpanded", except: saved };
|
|
949
|
-
}
|
|
950
344
|
if (isGroupExpansion(saved)) {
|
|
951
345
|
return saved;
|
|
952
346
|
}
|
|
953
347
|
throw new TypeError(
|
|
954
|
-
"GridKit: a saved `groupExpansion` is
|
|
348
|
+
"GridKit: a saved `groupExpansion` is not `{ mode, except }`."
|
|
955
349
|
);
|
|
956
350
|
}
|
|
957
351
|
|
|
958
|
-
// src/util/
|
|
959
|
-
var
|
|
960
|
-
|
|
961
|
-
|
|
962
|
-
|
|
352
|
+
// src/util/view.ts
|
|
353
|
+
var NO_AGGREGATES = [];
|
|
354
|
+
var DEFAULT_PAGE_SIZE = 25;
|
|
355
|
+
var STARTING_VIEW_STATE = {
|
|
356
|
+
columnSizing: {},
|
|
357
|
+
columnOrder: [],
|
|
358
|
+
columnVisibility: {},
|
|
359
|
+
columnPinning: {},
|
|
360
|
+
columnSort: [],
|
|
361
|
+
filter: [],
|
|
362
|
+
groupBy: [],
|
|
363
|
+
groupExpansion: ALL_EXPANDED,
|
|
364
|
+
pagination: { pageIndex: 0, pageSize: DEFAULT_PAGE_SIZE }
|
|
963
365
|
};
|
|
964
|
-
|
|
965
|
-
function withDefaults(defaults) {
|
|
966
|
-
return { ...DEFAULT_COLUMN_SIZES, ...defaults };
|
|
967
|
-
}
|
|
968
|
-
function resolveColumnConstraints(column, defaults) {
|
|
969
|
-
const resolved = withDefaults(defaults);
|
|
970
|
-
return {
|
|
971
|
-
minWidth: column.minWidth ?? resolved.minWidth,
|
|
972
|
-
maxWidth: column.maxWidth ?? resolved.maxWidth
|
|
973
|
-
};
|
|
974
|
-
}
|
|
975
|
-
function clampColumnWidth(width, constraints) {
|
|
976
|
-
return Math.min(Math.max(width, constraints.minWidth), constraints.maxWidth);
|
|
977
|
-
}
|
|
978
|
-
function resolveColumnWidths(columns, sizing, options) {
|
|
979
|
-
const resolved = withDefaults(options?.sizes);
|
|
980
|
-
return columns.map((column) => {
|
|
981
|
-
const id = getColumnId(column);
|
|
982
|
-
const stored = sizing[id];
|
|
983
|
-
return {
|
|
984
|
-
column,
|
|
985
|
-
id,
|
|
986
|
-
sized: stored !== void 0,
|
|
987
|
-
width: clampColumnWidth(
|
|
988
|
-
stored ?? column.width ?? resolved.width,
|
|
989
|
-
resolveColumnConstraints(column, resolved)
|
|
990
|
-
),
|
|
991
|
-
label: resolveColumnLabel(column),
|
|
992
|
-
resizable: column.resizable ?? options?.resizable ?? false,
|
|
993
|
-
reorderable: column.reorderable ?? options?.reorderable ?? false,
|
|
994
|
-
groupByDraggable: column.groupByDraggable ?? options?.groupByDraggable ?? false,
|
|
995
|
-
alignment: column.alignment ?? alignmentForType(column.type ?? "string")
|
|
996
|
-
};
|
|
997
|
-
});
|
|
998
|
-
}
|
|
999
|
-
function totalColumnWidth(resolved) {
|
|
1000
|
-
return resolved.reduce((total, entry) => total + entry.width, 0);
|
|
1001
|
-
}
|
|
1002
|
-
function beginColumnResize(column, startWidth, startPosition, defaults) {
|
|
1003
|
-
return {
|
|
1004
|
-
columnId: getColumnId(column),
|
|
1005
|
-
startWidth,
|
|
1006
|
-
startPosition,
|
|
1007
|
-
constraints: resolveColumnConstraints(column, defaults)
|
|
1008
|
-
};
|
|
1009
|
-
}
|
|
1010
|
-
function applyColumnResize(session, position) {
|
|
1011
|
-
return clampColumnWidth(
|
|
1012
|
-
session.startWidth + (position - session.startPosition),
|
|
1013
|
-
session.constraints
|
|
1014
|
-
);
|
|
1015
|
-
}
|
|
1016
|
-
function reachedBound(width, item) {
|
|
1017
|
-
return item.bound > item.width ? width >= item.bound : width <= item.bound;
|
|
1018
|
-
}
|
|
1019
|
-
function redistribute(entries, remaining) {
|
|
1020
|
-
for (; ; ) {
|
|
1021
|
-
const movable = entries.filter(
|
|
1022
|
-
(item) => item.adjustable && !reachedBound(item.width, item)
|
|
1023
|
-
);
|
|
1024
|
-
const left = remaining(entries.reduce((t, i) => t + i.width, 0));
|
|
1025
|
-
if (left <= 0 || movable.length === 0) {
|
|
1026
|
-
break;
|
|
1027
|
-
}
|
|
1028
|
-
const base = movable.reduce((total, item) => total + item.width, 0);
|
|
1029
|
-
let clamped = false;
|
|
1030
|
-
for (const item of movable) {
|
|
1031
|
-
const share = base === 0 ? left / movable.length : left * item.width / base;
|
|
1032
|
-
const next = item.width + (item.bound > item.width ? share : -share);
|
|
1033
|
-
if (reachedBound(next, item)) {
|
|
1034
|
-
item.width = item.bound;
|
|
1035
|
-
clamped = true;
|
|
1036
|
-
} else {
|
|
1037
|
-
item.width = next;
|
|
1038
|
-
}
|
|
1039
|
-
}
|
|
1040
|
-
if (!clamped) {
|
|
1041
|
-
break;
|
|
1042
|
-
}
|
|
1043
|
-
}
|
|
1044
|
-
}
|
|
1045
|
-
function fitColumnsToWidth(resolved, availableWidth, defaults) {
|
|
1046
|
-
const target = Math.floor(availableWidth);
|
|
1047
|
-
const total = totalColumnWidth(resolved);
|
|
1048
|
-
if (resolved.length === 0 || total === target) {
|
|
1049
|
-
return resolved;
|
|
1050
|
-
}
|
|
1051
|
-
const growing = total < target;
|
|
1052
|
-
const entries = resolved.map((entry) => {
|
|
1053
|
-
const constraints = resolveColumnConstraints(entry.column, defaults);
|
|
1054
|
-
return {
|
|
1055
|
-
entry,
|
|
1056
|
-
width: entry.width,
|
|
1057
|
-
bound: growing ? constraints.maxWidth : constraints.minWidth,
|
|
1058
|
-
adjustable: !entry.sized
|
|
1059
|
-
};
|
|
1060
|
-
});
|
|
1061
|
-
if (!growing) {
|
|
1062
|
-
const floor = entries.reduce(
|
|
1063
|
-
(sum, item) => sum + (item.adjustable ? item.bound : item.width),
|
|
1064
|
-
0
|
|
1065
|
-
);
|
|
1066
|
-
if (floor > target) {
|
|
1067
|
-
return resolved;
|
|
1068
|
-
}
|
|
1069
|
-
}
|
|
1070
|
-
redistribute(entries, (sum) => growing ? target - sum : sum - target);
|
|
1071
|
-
const rounded = entries.map(
|
|
1072
|
-
(item) => growing ? Math.floor(item.width) : Math.ceil(item.width)
|
|
1073
|
-
);
|
|
1074
|
-
let remainder = target - rounded.reduce((total2, width) => total2 + width, 0);
|
|
1075
|
-
return entries.map((item, index) => {
|
|
1076
|
-
let width = rounded[index] ?? item.width;
|
|
1077
|
-
const hasRoom = growing ? width < item.bound : width > item.bound;
|
|
1078
|
-
if (remainder !== 0 && item.adjustable && hasRoom) {
|
|
1079
|
-
width += growing ? 1 : -1;
|
|
1080
|
-
remainder += growing ? -1 : 1;
|
|
1081
|
-
}
|
|
1082
|
-
return { ...item.entry, width };
|
|
1083
|
-
});
|
|
1084
|
-
}
|
|
1085
|
-
function sizeColumnToContent(measuredWidth, constraints, padding = 2) {
|
|
1086
|
-
return clampColumnWidth(Math.ceil(measuredWidth + padding), constraints);
|
|
1087
|
-
}
|
|
1088
|
-
function revertColumnSize(current, base, columnId) {
|
|
1089
|
-
const next = Object.fromEntries(
|
|
1090
|
-
Object.entries(current).filter(([id]) => id !== columnId)
|
|
1091
|
-
);
|
|
1092
|
-
if (columnId in base) {
|
|
1093
|
-
next[columnId] = base[columnId];
|
|
1094
|
-
}
|
|
1095
|
-
return next;
|
|
1096
|
-
}
|
|
1097
|
-
|
|
1098
|
-
// src/util/aggregation.ts
|
|
1099
|
-
function isEmpty2(value) {
|
|
1100
|
-
return value === null || value === void 0;
|
|
1101
|
-
}
|
|
1102
|
-
function toNumber(value) {
|
|
1103
|
-
return Number(value);
|
|
1104
|
-
}
|
|
1105
|
-
function distinctKey(value) {
|
|
1106
|
-
if (isEmpty2(value)) {
|
|
1107
|
-
return "\0empty";
|
|
1108
|
-
}
|
|
1109
|
-
if (value instanceof Date) {
|
|
1110
|
-
return `\0date:${String(value.getTime())}`;
|
|
1111
|
-
}
|
|
1112
|
-
switch (typeof value) {
|
|
1113
|
-
case "string":
|
|
1114
|
-
case "number":
|
|
1115
|
-
case "boolean":
|
|
1116
|
-
case "bigint":
|
|
1117
|
-
case "symbol":
|
|
1118
|
-
return `\0${typeof value}:${String(value)}`;
|
|
1119
|
-
case "function":
|
|
1120
|
-
return "\0function";
|
|
1121
|
-
default:
|
|
1122
|
-
return `\0object:${JSON.stringify(value)}`;
|
|
1123
|
-
}
|
|
1124
|
-
}
|
|
1125
|
-
function reduceBuiltIn(rows, fn, column) {
|
|
1126
|
-
if (fn === "count") {
|
|
1127
|
-
return rows.length;
|
|
1128
|
-
}
|
|
1129
|
-
const field = column?.column.field;
|
|
1130
|
-
const values = field === void 0 ? [] : rows.map((row) => accessDotted(row, field));
|
|
1131
|
-
switch (fn) {
|
|
1132
|
-
case "sum": {
|
|
1133
|
-
let total = 0;
|
|
1134
|
-
for (const value of values) {
|
|
1135
|
-
if (isEmpty2(value)) continue;
|
|
1136
|
-
total += toNumber(value);
|
|
1137
|
-
}
|
|
1138
|
-
return total;
|
|
1139
|
-
}
|
|
1140
|
-
case "avg": {
|
|
1141
|
-
const present = values.filter((value) => !isEmpty2(value));
|
|
1142
|
-
if (present.length === 0) return void 0;
|
|
1143
|
-
const total = present.reduce(
|
|
1144
|
-
(acc, value) => acc + toNumber(value),
|
|
1145
|
-
0
|
|
1146
|
-
);
|
|
1147
|
-
return total / present.length;
|
|
1148
|
-
}
|
|
1149
|
-
case "min":
|
|
1150
|
-
case "max": {
|
|
1151
|
-
const type = column?.column.type;
|
|
1152
|
-
let result;
|
|
1153
|
-
for (const value of values) {
|
|
1154
|
-
if (isEmpty2(value)) continue;
|
|
1155
|
-
if (result === void 0) {
|
|
1156
|
-
result = value;
|
|
1157
|
-
continue;
|
|
1158
|
-
}
|
|
1159
|
-
const comparison = compareValues(value, result, type);
|
|
1160
|
-
if (fn === "min" ? comparison < 0 : comparison > 0) {
|
|
1161
|
-
result = value;
|
|
1162
|
-
}
|
|
1163
|
-
}
|
|
1164
|
-
return result;
|
|
1165
|
-
}
|
|
1166
|
-
case "countDistinct": {
|
|
1167
|
-
const seen = /* @__PURE__ */ new Set();
|
|
1168
|
-
for (const value of values) {
|
|
1169
|
-
if (isEmpty2(value)) continue;
|
|
1170
|
-
seen.add(distinctKey(value));
|
|
1171
|
-
}
|
|
1172
|
-
return seen.size;
|
|
1173
|
-
}
|
|
1174
|
-
}
|
|
1175
|
-
}
|
|
1176
|
-
function keyOf(spec) {
|
|
1177
|
-
return spec.id ?? spec.columnId;
|
|
1178
|
-
}
|
|
1179
|
-
function computeAggregates(rows, specs, columns) {
|
|
1180
|
-
const results = /* @__PURE__ */ new Map();
|
|
1181
|
-
if (specs.length === 0) {
|
|
1182
|
-
return results;
|
|
1183
|
-
}
|
|
1184
|
-
const byId = new Map(columns.map((entry) => [entry.id, entry]));
|
|
1185
|
-
for (const spec of specs) {
|
|
1186
|
-
const value = typeof spec.fn === "function" ? spec.fn(rows) : reduceBuiltIn(rows, spec.fn, byId.get(spec.columnId));
|
|
1187
|
-
results.set(keyOf(spec), value);
|
|
1188
|
-
}
|
|
1189
|
-
return results;
|
|
1190
|
-
}
|
|
1191
|
-
function leafDescendantsOf(flatRows, path, groupBy, byId) {
|
|
1192
|
-
const keys = path.map((value) => bucketKey(value));
|
|
1193
|
-
return flatRows.filter(
|
|
1194
|
-
(row) => keys.every((key, level) => {
|
|
1195
|
-
const columnId = groupBy[level]?.columnId;
|
|
1196
|
-
const column = columnId === void 0 ? void 0 : byId.get(columnId);
|
|
1197
|
-
if (column === void 0) return false;
|
|
1198
|
-
return bucketKey(accessDotted(row.row, column.field)) === key;
|
|
1199
|
-
})
|
|
1200
|
-
).map((row) => row.row);
|
|
1201
|
-
}
|
|
1202
|
-
function appendAggregatedSpan(displayRows, start, levelFloor, flatRows, groupBy, byId, specs, columns, display, out) {
|
|
1203
|
-
let index = start;
|
|
1204
|
-
while (index < displayRows.length) {
|
|
1205
|
-
const entry = displayRows[index];
|
|
1206
|
-
if (entry === void 0) {
|
|
1207
|
-
index++;
|
|
1208
|
-
continue;
|
|
1209
|
-
}
|
|
1210
|
-
if (levelFloor !== null && "kind" in entry && entry.kind === "group" && entry.level <= levelFloor) {
|
|
1211
|
-
break;
|
|
1212
|
-
}
|
|
1213
|
-
index++;
|
|
1214
|
-
if (!("kind" in entry) || entry.kind !== "group") {
|
|
1215
|
-
out.push(entry);
|
|
1216
|
-
continue;
|
|
1217
|
-
}
|
|
1218
|
-
const leaves = leafDescendantsOf(flatRows, entry.path, groupBy, byId);
|
|
1219
|
-
const aggregates = computeAggregates(leaves, specs, columns);
|
|
1220
|
-
const withAggregates = { ...entry, aggregates };
|
|
1221
|
-
out.push(withAggregates);
|
|
1222
|
-
index = appendAggregatedSpan(
|
|
1223
|
-
displayRows,
|
|
1224
|
-
index,
|
|
1225
|
-
entry.level,
|
|
1226
|
-
flatRows,
|
|
1227
|
-
groupBy,
|
|
1228
|
-
byId,
|
|
1229
|
-
specs,
|
|
1230
|
-
columns,
|
|
1231
|
-
display,
|
|
1232
|
-
out
|
|
1233
|
-
);
|
|
1234
|
-
if (display === "row") {
|
|
1235
|
-
const summary = {
|
|
1236
|
-
kind: "group-summary",
|
|
1237
|
-
groupId: entry.groupId,
|
|
1238
|
-
level: entry.level,
|
|
1239
|
-
rowIndex: -1,
|
|
1240
|
-
datasetIndex: -1,
|
|
1241
|
-
aggregates
|
|
1242
|
-
};
|
|
1243
|
-
out.push(summary);
|
|
1244
|
-
}
|
|
1245
|
-
}
|
|
1246
|
-
return index;
|
|
1247
|
-
}
|
|
1248
|
-
function withGroupAggregates(displayRows, flatRows, groupBy, specs, columns, display = "inline") {
|
|
1249
|
-
if (specs.length === 0) {
|
|
1250
|
-
return displayRows;
|
|
1251
|
-
}
|
|
1252
|
-
const byId = new Map(columns.map((entry) => [entry.id, entry.column]));
|
|
1253
|
-
const out = [];
|
|
1254
|
-
appendAggregatedSpan(
|
|
1255
|
-
displayRows,
|
|
1256
|
-
0,
|
|
1257
|
-
null,
|
|
1258
|
-
flatRows,
|
|
1259
|
-
groupBy,
|
|
1260
|
-
byId,
|
|
1261
|
-
specs,
|
|
1262
|
-
columns,
|
|
1263
|
-
display,
|
|
1264
|
-
out
|
|
1265
|
-
);
|
|
1266
|
-
return renumberRows(out);
|
|
1267
|
-
}
|
|
1268
|
-
|
|
1269
|
-
// src/util/rows.ts
|
|
1270
|
-
function resolveShownRows(rows, filter, sort, columns) {
|
|
1271
|
-
return sortRows(filterRows(rows, filter, columns), sort, columns);
|
|
1272
|
-
}
|
|
1273
|
-
function resolveRows(rowsById, ids) {
|
|
1274
|
-
return ids.map((id) => rowsById.get(id)).filter((row) => row !== void 0);
|
|
1275
|
-
}
|
|
1276
|
-
function resolveColumns(columns, ids) {
|
|
1277
|
-
return ids.map((id) => {
|
|
1278
|
-
const columnIndex = columns.findIndex((entry) => entry.id === id);
|
|
1279
|
-
const column = columns[columnIndex];
|
|
1280
|
-
return column === void 0 ? void 0 : { columnId: id, column, columnIndex };
|
|
1281
|
-
}).filter((column) => column !== void 0);
|
|
1282
|
-
}
|
|
1283
|
-
function resolveCell(rowsById, columns, cell) {
|
|
1284
|
-
if (cell === null) {
|
|
1285
|
-
return null;
|
|
1286
|
-
}
|
|
1287
|
-
const entry = rowsById.get(cell.rowId);
|
|
1288
|
-
const columnIndex = columns.findIndex(
|
|
1289
|
-
(candidate) => candidate.id === cell.columnId
|
|
1290
|
-
);
|
|
1291
|
-
const column = columns[columnIndex];
|
|
1292
|
-
if (entry === void 0 || column === void 0) {
|
|
1293
|
-
return null;
|
|
1294
|
-
}
|
|
1295
|
-
return {
|
|
1296
|
-
rowId: cell.rowId,
|
|
1297
|
-
columnId: cell.columnId,
|
|
1298
|
-
row: entry.row,
|
|
1299
|
-
column,
|
|
1300
|
-
rowIndex: entry.rowIndex,
|
|
1301
|
-
columnIndex,
|
|
1302
|
-
value: accessDotted(entry.row, column.column.field)
|
|
1303
|
-
};
|
|
1304
|
-
}
|
|
1305
|
-
|
|
1306
|
-
// src/util/visibility.ts
|
|
1307
|
-
function isColumnVisible(column, visibility) {
|
|
1308
|
-
return visibility[getColumnId(column)] ?? column.hidden !== true;
|
|
1309
|
-
}
|
|
1310
|
-
function applyColumnVisibility(columns, visibility) {
|
|
1311
|
-
const visible = columns.filter(
|
|
1312
|
-
(entry) => isColumnVisible(entry.column, visibility)
|
|
1313
|
-
);
|
|
1314
|
-
return visible.length === columns.length ? columns : visible;
|
|
1315
|
-
}
|
|
1316
|
-
function setColumnVisibility(columns, visibility, columnIds, visible) {
|
|
1317
|
-
const requested = new Set(columnIds);
|
|
1318
|
-
const changed = columns.filter(
|
|
1319
|
-
(entry) => requested.has(entry.id) && isColumnVisible(entry.column, visibility) !== visible
|
|
1320
|
-
);
|
|
1321
|
-
if (changed.length === 0) {
|
|
1322
|
-
return visibility;
|
|
1323
|
-
}
|
|
366
|
+
function fillViewState(state) {
|
|
1324
367
|
return {
|
|
1325
|
-
|
|
1326
|
-
|
|
368
|
+
columnSizing: state.columnSizing ?? STARTING_VIEW_STATE.columnSizing,
|
|
369
|
+
columnOrder: state.columnOrder ?? STARTING_VIEW_STATE.columnOrder,
|
|
370
|
+
columnVisibility: state.columnVisibility ?? STARTING_VIEW_STATE.columnVisibility,
|
|
371
|
+
columnPinning: state.columnPinning ?? STARTING_VIEW_STATE.columnPinning,
|
|
372
|
+
columnSort: state.columnSort ?? STARTING_VIEW_STATE.columnSort,
|
|
373
|
+
filter: state.filter ?? STARTING_VIEW_STATE.filter,
|
|
374
|
+
groupBy: state.groupBy ?? STARTING_VIEW_STATE.groupBy,
|
|
375
|
+
groupExpansion: state.groupExpansion ?? STARTING_VIEW_STATE.groupExpansion,
|
|
376
|
+
pagination: state.pagination ?? STARTING_VIEW_STATE.pagination
|
|
1327
377
|
};
|
|
1328
378
|
}
|
|
1329
|
-
|
|
1330
|
-
// src/util/view.ts
|
|
1331
|
-
var NO_AGGREGATES = [];
|
|
1332
379
|
function identifyRows(rows, getRowId) {
|
|
1333
380
|
return rows.map((row, rowIndex) => ({
|
|
381
|
+
kind: "data",
|
|
1334
382
|
rowId: resolveRowId(row, rowIndex, getRowId),
|
|
1335
383
|
row,
|
|
1336
384
|
rowIndex,
|
|
1337
385
|
datasetIndex: rowIndex
|
|
1338
386
|
}));
|
|
1339
387
|
}
|
|
1340
|
-
function sizeColumns(visibleColumns, sizing, sizes, resizable, reorderable, groupByDraggable, resizeMode, viewportWidth) {
|
|
388
|
+
function sizeColumns(visibleColumns, sizing, pinning, sizes, resizable, reorderable, groupByDraggable, resizeMode, viewportWidth) {
|
|
1341
389
|
const widths = resolveColumnWidths(
|
|
1342
390
|
visibleColumns.map((entry) => entry.column),
|
|
1343
391
|
sizing,
|
|
1344
|
-
{ sizes, resizable, reorderable, groupByDraggable }
|
|
392
|
+
{ sizes, resizable, reorderable, groupByDraggable, pinning }
|
|
1345
393
|
);
|
|
1346
394
|
return resizeMode === "fit" && viewportWidth !== null ? fitColumnsToWidth(widths, viewportWidth, sizes) : widths;
|
|
1347
395
|
}
|
|
@@ -1356,12 +404,15 @@ function paginate(displayRows, paginated, pagination, unit) {
|
|
|
1356
404
|
return paginated ? paginateRows(displayRows, pagination, { unit }) : { rows: displayRows, pageCount: 1, pageIndex: 0 };
|
|
1357
405
|
}
|
|
1358
406
|
function narrowToDataRows(pageRows, rows, reshaped) {
|
|
1359
|
-
return reshaped ? pageRows.filter(
|
|
407
|
+
return reshaped ? pageRows.filter(
|
|
408
|
+
(entry) => entry.kind === "data"
|
|
409
|
+
) : rows;
|
|
1360
410
|
}
|
|
1361
411
|
function createGridViewResolver() {
|
|
1362
412
|
const identify = memoizeLast(identifyRows);
|
|
1363
413
|
const orderColumns = memoizeLast(resolveDataColumns);
|
|
1364
414
|
const showColumns = memoizeLast(applyColumnVisibility);
|
|
415
|
+
const pinColumns = memoizeLast(applyColumnPinning);
|
|
1365
416
|
const size = memoizeLast(sizeColumns);
|
|
1366
417
|
const filterAndSort = memoizeLast(resolveShownRows);
|
|
1367
418
|
const group = memoizeLast(groupRows);
|
|
@@ -1382,13 +433,24 @@ function createGridViewResolver() {
|
|
|
1382
433
|
grandTotal
|
|
1383
434
|
})
|
|
1384
435
|
);
|
|
1385
|
-
return ({
|
|
436
|
+
return ({
|
|
437
|
+
rows: data,
|
|
438
|
+
getRowId,
|
|
439
|
+
columns: definitions,
|
|
440
|
+
state: given,
|
|
441
|
+
options
|
|
442
|
+
}) => {
|
|
443
|
+
const state = fillViewState(given);
|
|
1386
444
|
const paginated = options.paginated ?? false;
|
|
1387
445
|
const aggregates = options.aggregates ?? NO_AGGREGATES;
|
|
1388
446
|
const dataColumns = orderColumns(definitions, state.columnOrder);
|
|
1389
447
|
const columns = size(
|
|
1390
|
-
|
|
448
|
+
pinColumns(
|
|
449
|
+
showColumns(dataColumns, state.columnVisibility),
|
|
450
|
+
state.columnPinning
|
|
451
|
+
),
|
|
1391
452
|
state.columnSizing,
|
|
453
|
+
state.columnPinning,
|
|
1392
454
|
options.columnSizeDefaults,
|
|
1393
455
|
options.resizableColumns,
|
|
1394
456
|
options.reorderableColumns,
|
|
@@ -1503,101 +565,6 @@ function sameFilter(previous, next) {
|
|
|
1503
565
|
});
|
|
1504
566
|
}
|
|
1505
567
|
|
|
1506
|
-
// src/util/selection.ts
|
|
1507
|
-
var NO_CHANGE = { added: [], removed: [] };
|
|
1508
|
-
function sameSelection(a, b) {
|
|
1509
|
-
return a.length === b.length && a.every((id, index) => id === b[index]);
|
|
1510
|
-
}
|
|
1511
|
-
function toggleSelection(selection, id, mode) {
|
|
1512
|
-
if (mode === false) {
|
|
1513
|
-
return selection;
|
|
1514
|
-
}
|
|
1515
|
-
if (selection.includes(id)) {
|
|
1516
|
-
return selection.filter((selectedId) => selectedId !== id);
|
|
1517
|
-
}
|
|
1518
|
-
return mode === "single" ? [id] : [...selection, id];
|
|
1519
|
-
}
|
|
1520
|
-
function selectOnly(selection, id, mode) {
|
|
1521
|
-
if (mode === false) {
|
|
1522
|
-
return selection;
|
|
1523
|
-
}
|
|
1524
|
-
return selection.length === 1 && selection[0] === id ? selection : [id];
|
|
1525
|
-
}
|
|
1526
|
-
function selectRange(selection, orderedIds, anchorId, focusId, mode) {
|
|
1527
|
-
if (mode !== "multiple") {
|
|
1528
|
-
return selectOnly(selection, focusId, mode);
|
|
1529
|
-
}
|
|
1530
|
-
const anchor = orderedIds.indexOf(anchorId);
|
|
1531
|
-
const focus = orderedIds.indexOf(focusId);
|
|
1532
|
-
if (anchor === -1 || focus === -1) {
|
|
1533
|
-
return selection;
|
|
1534
|
-
}
|
|
1535
|
-
const next = orderedIds.slice(
|
|
1536
|
-
Math.min(anchor, focus),
|
|
1537
|
-
Math.max(anchor, focus) + 1
|
|
1538
|
-
);
|
|
1539
|
-
return sameSelection(selection, next) ? selection : next;
|
|
1540
|
-
}
|
|
1541
|
-
function selectAll(selection, orderedIds, mode) {
|
|
1542
|
-
if (mode !== "multiple") {
|
|
1543
|
-
return selection;
|
|
1544
|
-
}
|
|
1545
|
-
return sameSelection(selection, orderedIds) ? selection : orderedIds;
|
|
1546
|
-
}
|
|
1547
|
-
function clearSelection(selection) {
|
|
1548
|
-
return selection.length === 0 ? selection : [];
|
|
1549
|
-
}
|
|
1550
|
-
function diffSelection(previous, next) {
|
|
1551
|
-
if (previous === next) {
|
|
1552
|
-
return NO_CHANGE;
|
|
1553
|
-
}
|
|
1554
|
-
const before = new Set(previous);
|
|
1555
|
-
const after = new Set(next);
|
|
1556
|
-
return {
|
|
1557
|
-
added: next.filter((id) => !before.has(id)),
|
|
1558
|
-
removed: previous.filter((id) => !after.has(id))
|
|
1559
|
-
};
|
|
1560
|
-
}
|
|
1561
|
-
function isSameCell(a, b) {
|
|
1562
|
-
if (a === null || b === null) {
|
|
1563
|
-
return a === b;
|
|
1564
|
-
}
|
|
1565
|
-
return a.rowId === b.rowId && a.columnId === b.columnId;
|
|
1566
|
-
}
|
|
1567
|
-
function selectCell(selection, cell, mode) {
|
|
1568
|
-
if (mode === false || isSameCell(selection, cell)) {
|
|
1569
|
-
return selection;
|
|
1570
|
-
}
|
|
1571
|
-
return cell;
|
|
1572
|
-
}
|
|
1573
|
-
function toggleCellSelection(selection, cell, mode) {
|
|
1574
|
-
if (mode === false) {
|
|
1575
|
-
return selection;
|
|
1576
|
-
}
|
|
1577
|
-
return isSameCell(selection, cell) ? null : cell;
|
|
1578
|
-
}
|
|
1579
|
-
function intentOf(event, options) {
|
|
1580
|
-
if (event.shiftKey) {
|
|
1581
|
-
return "range";
|
|
1582
|
-
}
|
|
1583
|
-
if (event.ctrlKey || event.metaKey) {
|
|
1584
|
-
return "toggle";
|
|
1585
|
-
}
|
|
1586
|
-
return options?.toggleOnClick === true ? "toggle" : "replace";
|
|
1587
|
-
}
|
|
1588
|
-
function applySelectionIntent(selection, orderedIds, anchorId, id, intent, mode) {
|
|
1589
|
-
switch (intent) {
|
|
1590
|
-
case "toggle":
|
|
1591
|
-
return toggleSelection(selection, id, mode);
|
|
1592
|
-
// A range with no anchor yet spans from the id to itself, which is the
|
|
1593
|
-
// plain click a first Shift-click may as well be.
|
|
1594
|
-
case "range":
|
|
1595
|
-
return selectRange(selection, orderedIds, anchorId ?? id, id, mode);
|
|
1596
|
-
default:
|
|
1597
|
-
return selectOnly(selection, id, mode);
|
|
1598
|
-
}
|
|
1599
|
-
}
|
|
1600
|
-
|
|
1601
568
|
// src/controller/selectionEvents.ts
|
|
1602
569
|
function reportRowSelection(previous, next, rowsById, callbacks) {
|
|
1603
570
|
const diff = diffSelection(previous, next);
|
|
@@ -1647,9 +614,12 @@ function reportColumnSelection(previous, next, columns, callbacks) {
|
|
|
1647
614
|
});
|
|
1648
615
|
return diff;
|
|
1649
616
|
}
|
|
617
|
+
function selectedCellOf(selection) {
|
|
618
|
+
return selection.kind === "cell" ? selection : null;
|
|
619
|
+
}
|
|
1650
620
|
function reportCellSelection(previous, next, rowsById, columns, callbacks) {
|
|
1651
|
-
const selected = resolveCell(rowsById, columns, next);
|
|
1652
|
-
const deselected = resolveCell(rowsById, columns, previous);
|
|
621
|
+
const selected = resolveCell(rowsById, columns, selectedCellOf(next));
|
|
622
|
+
const deselected = resolveCell(rowsById, columns, selectedCellOf(previous));
|
|
1653
623
|
if (deselected !== null) {
|
|
1654
624
|
callbacks.onCellDeselect?.({ cell: deselected, selection: next });
|
|
1655
625
|
}
|
|
@@ -1791,7 +761,7 @@ function createSelectionActions(grid) {
|
|
|
1791
761
|
grid.transaction(() => {
|
|
1792
762
|
commitRows(clearSelection(grid.getState().rowSelection));
|
|
1793
763
|
commitColumns(clearSelection(grid.getState().columnSelection));
|
|
1794
|
-
commitCell(
|
|
764
|
+
commitCell(clearCellSelection(grid.getState().cellSelection));
|
|
1795
765
|
});
|
|
1796
766
|
},
|
|
1797
767
|
setColumnSelection(selection) {
|
|
@@ -1828,13 +798,13 @@ function createSelectionActions(grid) {
|
|
|
1828
798
|
}
|
|
1829
799
|
|
|
1830
800
|
// src/controller/createGridController.ts
|
|
1831
|
-
var DEFAULT_PAGE_SIZE = 25;
|
|
1832
801
|
var NO_ROWS = [];
|
|
1833
802
|
var NO_COLUMNS = [];
|
|
1834
803
|
var SLICE_KEYS = [
|
|
1835
804
|
"columnSizing",
|
|
1836
805
|
"columnOrder",
|
|
1837
806
|
"columnVisibility",
|
|
807
|
+
"columnPinning",
|
|
1838
808
|
"columnSort",
|
|
1839
809
|
"filter",
|
|
1840
810
|
"groupBy",
|
|
@@ -1848,6 +818,7 @@ var DEFAULT_OPTION = {
|
|
|
1848
818
|
columnSizing: "defaultColumnSizing",
|
|
1849
819
|
columnOrder: "defaultColumnOrder",
|
|
1850
820
|
columnVisibility: "defaultColumnVisibility",
|
|
821
|
+
columnPinning: "defaultColumnPinning",
|
|
1851
822
|
columnSort: "defaultColumnSort",
|
|
1852
823
|
filter: "defaultFilter",
|
|
1853
824
|
groupBy: "defaultGroupBy",
|
|
@@ -1859,20 +830,18 @@ var DEFAULT_OPTION = {
|
|
|
1859
830
|
};
|
|
1860
831
|
function startingState(options) {
|
|
1861
832
|
return {
|
|
1862
|
-
columnSizing: options.defaultColumnSizing ??
|
|
1863
|
-
columnOrder: options.defaultColumnOrder ??
|
|
1864
|
-
columnVisibility: options.defaultColumnVisibility ??
|
|
1865
|
-
|
|
1866
|
-
|
|
1867
|
-
|
|
1868
|
-
|
|
1869
|
-
|
|
1870
|
-
|
|
1871
|
-
pageSize: DEFAULT_PAGE_SIZE
|
|
1872
|
-
},
|
|
833
|
+
columnSizing: options.defaultColumnSizing ?? STARTING_VIEW_STATE.columnSizing,
|
|
834
|
+
columnOrder: options.defaultColumnOrder ?? STARTING_VIEW_STATE.columnOrder,
|
|
835
|
+
columnVisibility: options.defaultColumnVisibility ?? STARTING_VIEW_STATE.columnVisibility,
|
|
836
|
+
columnPinning: options.defaultColumnPinning ?? STARTING_VIEW_STATE.columnPinning,
|
|
837
|
+
columnSort: options.defaultColumnSort ?? STARTING_VIEW_STATE.columnSort,
|
|
838
|
+
filter: options.defaultFilter ?? STARTING_VIEW_STATE.filter,
|
|
839
|
+
groupBy: options.defaultGroupBy ?? STARTING_VIEW_STATE.groupBy,
|
|
840
|
+
groupExpansion: options.defaultGroupExpansion ?? STARTING_VIEW_STATE.groupExpansion,
|
|
841
|
+
pagination: options.defaultPagination ?? STARTING_VIEW_STATE.pagination,
|
|
1873
842
|
rowSelection: options.defaultRowSelection ?? [],
|
|
1874
843
|
columnSelection: options.defaultColumnSelection ?? [],
|
|
1875
|
-
cellSelection: options.defaultCellSelection ??
|
|
844
|
+
cellSelection: options.defaultCellSelection ?? NO_CELL_SELECTED
|
|
1876
845
|
};
|
|
1877
846
|
}
|
|
1878
847
|
function definedColumns(columns, rows) {
|
|
@@ -1923,6 +892,7 @@ function createGridController(initial) {
|
|
|
1923
892
|
columnSizing: resolveSlice("columnSizing"),
|
|
1924
893
|
columnOrder: resolveSlice("columnOrder"),
|
|
1925
894
|
columnVisibility: resolveSlice("columnVisibility"),
|
|
895
|
+
columnPinning: resolveSlice("columnPinning"),
|
|
1926
896
|
columnSort: resolveSlice("columnSort"),
|
|
1927
897
|
filter: resolveSlice("filter"),
|
|
1928
898
|
groupBy: resolveSlice("groupBy"),
|
|
@@ -2046,7 +1016,7 @@ function createGridController(initial) {
|
|
|
2046
1016
|
}
|
|
2047
1017
|
function commitColumnSizing(next, columnId, width, phase) {
|
|
2048
1018
|
commit("columnSizing", next, () => {
|
|
2049
|
-
options.
|
|
1019
|
+
options.onColumnSizingChange?.({ columnId, width, sizing: next, phase });
|
|
2050
1020
|
});
|
|
2051
1021
|
}
|
|
2052
1022
|
function definedWidth(columnId) {
|
|
@@ -2062,13 +1032,16 @@ function createGridController(initial) {
|
|
|
2062
1032
|
);
|
|
2063
1033
|
return resolved?.width ?? 0;
|
|
2064
1034
|
}
|
|
1035
|
+
function changedColumnIds(previous, next) {
|
|
1036
|
+
const changed = new Set(changedKeys(previous, next));
|
|
1037
|
+
const known = getView().dataColumns.map((entry) => entry.id).filter((id) => changed.delete(id));
|
|
1038
|
+
return [...known, ...changed];
|
|
1039
|
+
}
|
|
2065
1040
|
function commitColumnVisibility(next) {
|
|
2066
1041
|
const previous = state.columnVisibility;
|
|
2067
1042
|
commit("columnVisibility", next, () => {
|
|
2068
|
-
const changed = new Set(changedKeys(previous, next));
|
|
2069
|
-
const shown = getView().dataColumns.map((entry) => entry.id).filter((id) => changed.delete(id));
|
|
2070
1043
|
options.onColumnVisibilityChange?.({
|
|
2071
|
-
columnIds:
|
|
1044
|
+
columnIds: changedColumnIds(previous, next),
|
|
2072
1045
|
visibility: next
|
|
2073
1046
|
});
|
|
2074
1047
|
});
|
|
@@ -2083,6 +1056,15 @@ function createGridController(initial) {
|
|
|
2083
1056
|
)
|
|
2084
1057
|
);
|
|
2085
1058
|
}
|
|
1059
|
+
function commitColumnPinning(next) {
|
|
1060
|
+
const previous = state.columnPinning;
|
|
1061
|
+
commit("columnPinning", next, () => {
|
|
1062
|
+
options.onColumnPinningChange?.({
|
|
1063
|
+
columnIds: changedColumnIds(previous, next),
|
|
1064
|
+
pinning: next
|
|
1065
|
+
});
|
|
1066
|
+
});
|
|
1067
|
+
}
|
|
2086
1068
|
function commitGroupBy(next, columnId) {
|
|
2087
1069
|
commit("groupBy", next, () => {
|
|
2088
1070
|
options.onGroupByChange?.({ columnId, groupBy: next });
|
|
@@ -2142,8 +1124,9 @@ function createGridController(initial) {
|
|
|
2142
1124
|
getState: () => state,
|
|
2143
1125
|
getView,
|
|
2144
1126
|
restoreState(saved) {
|
|
1127
|
+
const current = migrateSavedState(saved);
|
|
2145
1128
|
transaction(() => {
|
|
2146
|
-
restoreSlices(
|
|
1129
|
+
restoreSlices(current);
|
|
2147
1130
|
});
|
|
2148
1131
|
},
|
|
2149
1132
|
subscribe(listener) {
|
|
@@ -2189,13 +1172,25 @@ function createGridController(initial) {
|
|
|
2189
1172
|
});
|
|
2190
1173
|
},
|
|
2191
1174
|
/**
|
|
2192
|
-
* Applied to every id in
|
|
1175
|
+
* Applied to every id in column order rather than to the stored order,
|
|
2193
1176
|
* which starts empty and may name only some columns, so would have
|
|
2194
1177
|
* nothing to rearrange.
|
|
2195
1178
|
*/
|
|
2196
1179
|
moveColumn(columnId, beforeId) {
|
|
2197
|
-
const
|
|
2198
|
-
const
|
|
1180
|
+
const { dataColumns } = getView();
|
|
1181
|
+
const orderedIds = dataColumns.map((entry) => entry.id);
|
|
1182
|
+
const pins = new Map(
|
|
1183
|
+
dataColumns.map((entry) => [
|
|
1184
|
+
entry.id,
|
|
1185
|
+
resolveColumnPin(entry.column, state.columnPinning)
|
|
1186
|
+
])
|
|
1187
|
+
);
|
|
1188
|
+
const next = moveColumnInPinGroup(
|
|
1189
|
+
orderedIds,
|
|
1190
|
+
(id) => pins.get(id) ?? "none",
|
|
1191
|
+
columnId,
|
|
1192
|
+
beforeId
|
|
1193
|
+
);
|
|
2199
1194
|
if (next === orderedIds) {
|
|
2200
1195
|
return;
|
|
2201
1196
|
}
|
|
@@ -2214,6 +1209,16 @@ function createGridController(initial) {
|
|
|
2214
1209
|
hideColumns(columnIds) {
|
|
2215
1210
|
changeColumnVisibility(columnIds, false);
|
|
2216
1211
|
},
|
|
1212
|
+
setColumnPinning(pinning) {
|
|
1213
|
+
if (changedKeys(state.columnPinning, pinning).length > 0) {
|
|
1214
|
+
commitColumnPinning(pinning);
|
|
1215
|
+
}
|
|
1216
|
+
},
|
|
1217
|
+
pinColumn(columnId, pin) {
|
|
1218
|
+
commitColumnPinning(
|
|
1219
|
+
setColumnPin(getView().dataColumns, state.columnPinning, columnId, pin)
|
|
1220
|
+
);
|
|
1221
|
+
},
|
|
2217
1222
|
setFilter(filter) {
|
|
2218
1223
|
if (sameFilter(state.filter, filter)) {
|
|
2219
1224
|
return;
|
|
@@ -2283,2101 +1288,95 @@ function createGridController(initial) {
|
|
|
2283
1288
|
expandAllGroups() {
|
|
2284
1289
|
commitGroupExpansion(expandAllGroups(state.groupExpansion), null);
|
|
2285
1290
|
},
|
|
2286
|
-
collapseAllGroups() {
|
|
2287
|
-
commitGroupExpansion(collapseAllGroups(state.groupExpansion), null);
|
|
2288
|
-
},
|
|
2289
|
-
setPagination: commitPagination,
|
|
2290
|
-
goToPage,
|
|
2291
|
-
nextPage() {
|
|
2292
|
-
goToPage(shownPageIndex() + 1);
|
|
2293
|
-
},
|
|
2294
|
-
previousPage() {
|
|
2295
|
-
goToPage(shownPageIndex() - 1);
|
|
2296
|
-
},
|
|
2297
|
-
setPageSize(pageSize) {
|
|
2298
|
-
const first = { pageIndex: 0, pageSize };
|
|
2299
|
-
commitPagination({
|
|
2300
|
-
...first,
|
|
2301
|
-
pageIndex: pageOf(first).pageIndex
|
|
2302
|
-
});
|
|
2303
|
-
}
|
|
2304
|
-
};
|
|
2305
|
-
function restoreSlices(saved) {
|
|
2306
|
-
if (saved.columnSizing !== void 0) {
|
|
2307
|
-
controller.setColumnSizing(saved.columnSizing);
|
|
2308
|
-
}
|
|
2309
|
-
if (saved.columnOrder !== void 0) {
|
|
2310
|
-
controller.setColumnOrder(saved.columnOrder);
|
|
2311
|
-
}
|
|
2312
|
-
if (saved.columnVisibility !== void 0) {
|
|
2313
|
-
controller.setColumnVisibility(saved.columnVisibility);
|
|
2314
|
-
}
|
|
2315
|
-
if (saved.columnSort !== void 0) {
|
|
2316
|
-
controller.setColumnSort(saved.columnSort);
|
|
2317
|
-
}
|
|
2318
|
-
if (saved.filter !== void 0) {
|
|
2319
|
-
controller.setFilter(reviveFilter(saved.filter, getView().dataColumns));
|
|
2320
|
-
}
|
|
2321
|
-
if (saved.groupBy !== void 0) {
|
|
2322
|
-
controller.setGroupBy(saved.groupBy);
|
|
2323
|
-
}
|
|
2324
|
-
if (saved.groupExpansion !== void 0) {
|
|
2325
|
-
controller.setGroupExpansion(reviveGroupExpansion(saved.groupExpansion));
|
|
2326
|
-
}
|
|
2327
|
-
if (saved.pagination !== void 0) {
|
|
2328
|
-
controller.setPagination(saved.pagination);
|
|
2329
|
-
}
|
|
2330
|
-
if (saved.rowSelection !== void 0) {
|
|
2331
|
-
controller.setRowSelection(saved.rowSelection);
|
|
2332
|
-
}
|
|
2333
|
-
if (saved.columnSelection !== void 0) {
|
|
2334
|
-
controller.setColumnSelection(saved.columnSelection);
|
|
2335
|
-
}
|
|
2336
|
-
if (saved.cellSelection !== void 0) {
|
|
2337
|
-
controller.setCellSelection(saved.cellSelection);
|
|
2338
|
-
}
|
|
2339
|
-
}
|
|
2340
|
-
return controller;
|
|
2341
|
-
}
|
|
2342
|
-
|
|
2343
|
-
// src/commands/context.ts
|
|
2344
|
-
function selectedRowsOf(rows, selection) {
|
|
2345
|
-
if (selection.length === 0) {
|
|
2346
|
-
return [];
|
|
2347
|
-
}
|
|
2348
|
-
const selected = new Set(selection);
|
|
2349
|
-
return rows.filter((entry) => selected.has(entry.rowId));
|
|
2350
|
-
}
|
|
2351
|
-
function createCommandContext({
|
|
2352
|
-
controller,
|
|
2353
|
-
target,
|
|
2354
|
-
messages,
|
|
2355
|
-
host
|
|
2356
|
-
}) {
|
|
2357
|
-
const state = controller.getState();
|
|
2358
|
-
const view = controller.getView();
|
|
2359
|
-
let selectedRows;
|
|
2360
|
-
return {
|
|
2361
|
-
target,
|
|
2362
|
-
state,
|
|
2363
|
-
view,
|
|
2364
|
-
options: controller.getOptions(),
|
|
2365
|
-
messages,
|
|
2366
|
-
actions: controller,
|
|
2367
|
-
host,
|
|
2368
|
-
row: target.area === "cell" ? view.rows.find((entry) => entry.rowId === target.rowId) ?? null : null,
|
|
2369
|
-
column: "columnId" in target ? view.dataColumns.find((entry) => entry.id === target.columnId) ?? null : null,
|
|
2370
|
-
selectedRows: () => selectedRows ??= selectedRowsOf(view.rows, state.rowSelection)
|
|
2371
|
-
};
|
|
2372
|
-
}
|
|
2373
|
-
|
|
2374
|
-
// src/util/format.ts
|
|
2375
|
-
var DATE_FIELDS = {
|
|
2376
|
-
year: "numeric",
|
|
2377
|
-
month: "numeric",
|
|
2378
|
-
day: "numeric"
|
|
2379
|
-
};
|
|
2380
|
-
var TIME_FIELDS = {
|
|
2381
|
-
hour: "numeric",
|
|
2382
|
-
minute: "numeric",
|
|
2383
|
-
second: "numeric"
|
|
2384
|
-
};
|
|
2385
|
-
var DATE_TIME_FIELDS = {
|
|
2386
|
-
...DATE_FIELDS,
|
|
2387
|
-
...TIME_FIELDS
|
|
2388
|
-
};
|
|
2389
|
-
var CURRENCY_DIGITS = {
|
|
2390
|
-
minimumFractionDigits: 2,
|
|
2391
|
-
maximumFractionDigits: 2
|
|
2392
|
-
};
|
|
2393
|
-
var NO_FORMAT = {};
|
|
2394
|
-
var formatters = /* @__PURE__ */ new WeakMap();
|
|
2395
|
-
function cached(format, key, create) {
|
|
2396
|
-
const owner = format ?? NO_FORMAT;
|
|
2397
|
-
let byKey = formatters.get(owner);
|
|
2398
|
-
if (byKey === void 0) {
|
|
2399
|
-
byKey = /* @__PURE__ */ new Map();
|
|
2400
|
-
formatters.set(owner, byKey);
|
|
2401
|
-
}
|
|
2402
|
-
const existing = byKey.get(key);
|
|
2403
|
-
if (existing !== void 0) {
|
|
2404
|
-
return existing;
|
|
2405
|
-
}
|
|
2406
|
-
const formatter = create();
|
|
2407
|
-
byKey.set(key, formatter);
|
|
2408
|
-
return formatter;
|
|
2409
|
-
}
|
|
2410
|
-
function localeKey(locale) {
|
|
2411
|
-
return typeof locale === "string" ? locale : locale?.join(",") ?? "";
|
|
2412
|
-
}
|
|
2413
|
-
function isNumericType(type) {
|
|
2414
|
-
return type === "number" || type === "decimal" || type === "currency" || type === "percent";
|
|
2415
|
-
}
|
|
2416
|
-
function numberOptions(type, format) {
|
|
2417
|
-
switch (type) {
|
|
2418
|
-
case "currency":
|
|
2419
|
-
return format?.currency === void 0 ? { ...CURRENCY_DIGITS, ...format } : { style: "currency", ...format };
|
|
2420
|
-
case "percent":
|
|
2421
|
-
return { style: "percent", ...format };
|
|
2422
|
-
default:
|
|
2423
|
-
return format ?? {};
|
|
2424
|
-
}
|
|
2425
|
-
}
|
|
2426
|
-
function dateOptions(type, format) {
|
|
2427
|
-
if (format !== void 0) {
|
|
2428
|
-
return format;
|
|
2429
|
-
}
|
|
2430
|
-
if (type === "date") return DATE_FIELDS;
|
|
2431
|
-
if (type === "time") return TIME_FIELDS;
|
|
2432
|
-
return DATE_TIME_FIELDS;
|
|
2433
|
-
}
|
|
2434
|
-
function formatNumber(value, type, format, locale) {
|
|
2435
|
-
const formatter = cached(
|
|
2436
|
-
format,
|
|
2437
|
-
`number|${type ?? ""}|${localeKey(locale)}`,
|
|
2438
|
-
() => new Intl.NumberFormat(
|
|
2439
|
-
locale,
|
|
2440
|
-
numberOptions(type, format)
|
|
2441
|
-
)
|
|
2442
|
-
);
|
|
2443
|
-
return formatter.format(value);
|
|
2444
|
-
}
|
|
2445
|
-
function formatDate(value, type, format, locale) {
|
|
2446
|
-
if (Number.isNaN(value.getTime())) {
|
|
2447
|
-
return String(value);
|
|
2448
|
-
}
|
|
2449
|
-
const formatter = cached(
|
|
2450
|
-
format,
|
|
2451
|
-
`date|${type ?? ""}|${localeKey(locale)}`,
|
|
2452
|
-
() => new Intl.DateTimeFormat(
|
|
2453
|
-
locale,
|
|
2454
|
-
dateOptions(type, format)
|
|
2455
|
-
)
|
|
2456
|
-
);
|
|
2457
|
-
return formatter.format(value);
|
|
2458
|
-
}
|
|
2459
|
-
function formatOther(value) {
|
|
2460
|
-
if (typeof value === "function") {
|
|
2461
|
-
return "(function)";
|
|
2462
|
-
}
|
|
2463
|
-
if (typeof value === "object" && value !== null) {
|
|
2464
|
-
try {
|
|
2465
|
-
return JSON.stringify(value);
|
|
2466
|
-
} catch {
|
|
2467
|
-
return Object.prototype.toString.call(value);
|
|
2468
|
-
}
|
|
2469
|
-
}
|
|
2470
|
-
return String(value);
|
|
2471
|
-
}
|
|
2472
|
-
function formatCellValue(value, column, locale, row, messages) {
|
|
2473
|
-
if (column.valueFormatter !== void 0) {
|
|
2474
|
-
return column.valueFormatter(value, row);
|
|
2475
|
-
}
|
|
2476
|
-
if (value === null || value === void 0) {
|
|
2477
|
-
return "";
|
|
2478
|
-
}
|
|
2479
|
-
if (typeof value === "boolean" && messages !== void 0) {
|
|
2480
|
-
return value ? messages.booleanTrue : messages.booleanFalse;
|
|
2481
|
-
}
|
|
2482
|
-
const { type, format } = column;
|
|
2483
|
-
const formatted = format !== void 0 || locale !== void 0;
|
|
2484
|
-
if (value instanceof Date) {
|
|
2485
|
-
return formatted ? formatDate(value, type, format, locale) : value.toLocaleString();
|
|
2486
|
-
}
|
|
2487
|
-
if (formatted && (typeof value === "number" || typeof value === "bigint") && isNumericType(type)) {
|
|
2488
|
-
return formatNumber(value, type, format, locale);
|
|
2489
|
-
}
|
|
2490
|
-
if (typeof value === "string") {
|
|
2491
|
-
return value;
|
|
2492
|
-
}
|
|
2493
|
-
return formatOther(value);
|
|
2494
|
-
}
|
|
2495
|
-
function aggregateFormatColumn(value, spec, column) {
|
|
2496
|
-
const plain = {
|
|
2497
|
-
field: spec.columnId,
|
|
2498
|
-
type: "number"
|
|
2499
|
-
};
|
|
2500
|
-
if (column === void 0 || spec.fn === "count" || spec.fn === "countDistinct") {
|
|
2501
|
-
return plain;
|
|
2502
|
-
}
|
|
2503
|
-
const numeric = typeof value === "number" || typeof value === "bigint";
|
|
2504
|
-
return column.valueFormatter === void 0 && numeric && !isNumericType(column.type) ? plain : column;
|
|
2505
|
-
}
|
|
2506
|
-
function formatAggregateValue(value, spec, column, locale) {
|
|
2507
|
-
const target = aggregateFormatColumn(value, spec, column);
|
|
2508
|
-
if (typeof value === "number" && target.valueFormatter === void 0 && target.format === void 0 && locale === void 0) {
|
|
2509
|
-
return value.toLocaleString();
|
|
2510
|
-
}
|
|
2511
|
-
return formatCellValue(value, target, locale);
|
|
2512
|
-
}
|
|
2513
|
-
function formatGroupValue(value, column, locale, messages) {
|
|
2514
|
-
return value === null || value === void 0 ? messages.blankGroupValue : formatCellValue(value, column, locale, void 0, messages);
|
|
2515
|
-
}
|
|
2516
|
-
|
|
2517
|
-
// src/export/buildExportTable.ts
|
|
2518
|
-
var EMPTY_CELL = { value: null, text: "" };
|
|
2519
|
-
function isDataRow(entry) {
|
|
2520
|
-
return !("kind" in entry);
|
|
2521
|
-
}
|
|
2522
|
-
function pickColumns(view, selection) {
|
|
2523
|
-
let picked;
|
|
2524
|
-
if (selection === "visible") {
|
|
2525
|
-
picked = view.columns;
|
|
2526
|
-
} else if (selection === "all") {
|
|
2527
|
-
picked = view.dataColumns;
|
|
2528
|
-
} else {
|
|
2529
|
-
const byId = new Map(view.dataColumns.map((entry) => [entry.id, entry]));
|
|
2530
|
-
picked = [...new Set(selection)].flatMap((id) => byId.get(id) ?? []);
|
|
2531
|
-
}
|
|
2532
|
-
return picked.filter((entry) => entry.column.exportable !== false);
|
|
2533
|
-
}
|
|
2534
|
-
function describeColumns(picked, source) {
|
|
2535
|
-
const shown = new Map(source.view.columns.map((entry) => [entry.id, entry]));
|
|
2536
|
-
const resolved = resolveColumnWidths(
|
|
2537
|
-
picked.map((entry) => entry.column),
|
|
2538
|
-
source.state.columnSizing,
|
|
2539
|
-
{ sizes: source.options.columnSizeDefaults }
|
|
2540
|
-
);
|
|
2541
|
-
return resolved.map((entry) => {
|
|
2542
|
-
const rendered = shown.get(entry.id) ?? entry;
|
|
2543
|
-
return {
|
|
2544
|
-
id: rendered.id,
|
|
2545
|
-
header: resolveColumnHeaderText(rendered.column),
|
|
2546
|
-
type: rendered.column.type ?? "string",
|
|
2547
|
-
format: rendered.column.format,
|
|
2548
|
-
alignment: rendered.alignment,
|
|
2549
|
-
width: rendered.width
|
|
2550
|
-
};
|
|
2551
|
-
});
|
|
2552
|
-
}
|
|
2553
|
-
function scopedRows(source, scope) {
|
|
2554
|
-
const { view, state } = source;
|
|
2555
|
-
switch (scope) {
|
|
2556
|
-
case "all":
|
|
2557
|
-
return view.rows;
|
|
2558
|
-
case "page":
|
|
2559
|
-
return view.displayDataRows;
|
|
2560
|
-
case "selection": {
|
|
2561
|
-
const selected = new Set(state.rowSelection);
|
|
2562
|
-
return view.rows.filter((entry) => selected.has(entry.rowId));
|
|
2563
|
-
}
|
|
2564
|
-
}
|
|
2565
|
-
}
|
|
2566
|
-
function typedValue(value, text) {
|
|
2567
|
-
if (value === null || value === void 0) {
|
|
2568
|
-
return null;
|
|
2569
|
-
}
|
|
2570
|
-
return typeof value === "string" || typeof value === "number" || typeof value === "boolean" || value instanceof Date ? value : text;
|
|
2571
|
-
}
|
|
2572
|
-
function dataCell(row, column, context) {
|
|
2573
|
-
const raw = accessDotted(row, column.field);
|
|
2574
|
-
const text = formatCellValue(
|
|
2575
|
-
raw,
|
|
2576
|
-
column,
|
|
2577
|
-
context.locale,
|
|
2578
|
-
row,
|
|
2579
|
-
context.messages
|
|
2580
|
-
);
|
|
2581
|
-
return {
|
|
2582
|
-
value: column.exportValue === void 0 ? typedValue(raw, text) : column.exportValue(raw, row),
|
|
2583
|
-
text
|
|
2584
|
-
};
|
|
2585
|
-
}
|
|
2586
|
-
function aggregateCell(results, specs, column, locale) {
|
|
2587
|
-
const parts = specs.flatMap((spec) => {
|
|
2588
|
-
const value = results.get(spec.id ?? spec.columnId);
|
|
2589
|
-
return value === null || value === void 0 ? [] : [{ value, text: formatAggregateValue(value, spec, column, locale) }];
|
|
2590
|
-
});
|
|
2591
|
-
const [only] = parts;
|
|
2592
|
-
if (only === void 0) {
|
|
2593
|
-
return EMPTY_CELL;
|
|
2594
|
-
}
|
|
2595
|
-
if (parts.length === 1) {
|
|
2596
|
-
return { value: typedValue(only.value, only.text), text: only.text };
|
|
2597
|
-
}
|
|
2598
|
-
const text = parts.map((part) => part.text).join(", ");
|
|
2599
|
-
return { value: text, text };
|
|
2600
|
-
}
|
|
2601
|
-
function aggregateCells(results, context) {
|
|
2602
|
-
return context.columns.map((entry) => {
|
|
2603
|
-
const specs = context.specsByColumn.get(entry.id);
|
|
2604
|
-
return specs === void 0 ? EMPTY_CELL : aggregateCell(results, specs, entry.column, context.locale);
|
|
2605
|
-
});
|
|
2606
|
-
}
|
|
2607
|
-
function groupLabel(entry, source) {
|
|
2608
|
-
const column = source.view.dataColumns.find(
|
|
2609
|
-
(candidate) => candidate.id === entry.columnId
|
|
2610
|
-
)?.column ?? { field: entry.columnId };
|
|
2611
|
-
const value = formatGroupValue(
|
|
2612
|
-
entry.value,
|
|
2613
|
-
column,
|
|
2614
|
-
source.options.locale,
|
|
2615
|
-
source.messages
|
|
2616
|
-
);
|
|
2617
|
-
return `${resolveColumnHeaderText(column)}: ${value}`;
|
|
2618
|
-
}
|
|
2619
|
-
function toExportRow(entry, source, context) {
|
|
2620
|
-
if (isDataRow(entry)) {
|
|
2621
|
-
return {
|
|
2622
|
-
kind: "data",
|
|
2623
|
-
rowId: entry.rowId,
|
|
2624
|
-
cells: context.columns.map(
|
|
2625
|
-
(column) => dataCell(entry.row, column.column, context)
|
|
2626
|
-
)
|
|
2627
|
-
};
|
|
2628
|
-
}
|
|
2629
|
-
if (entry.kind === "group") {
|
|
2630
|
-
return {
|
|
2631
|
-
kind: "group",
|
|
2632
|
-
level: entry.level,
|
|
2633
|
-
groupId: entry.groupId,
|
|
2634
|
-
label: groupLabel(entry, source),
|
|
2635
|
-
count: entry.count,
|
|
2636
|
-
cells: context.display === "inline" ? aggregateCells(entry.aggregates, context) : context.columns.map(() => EMPTY_CELL)
|
|
2637
|
-
};
|
|
2638
|
-
}
|
|
2639
|
-
return {
|
|
2640
|
-
kind: "groupSummary",
|
|
2641
|
-
level: entry.level,
|
|
2642
|
-
cells: aggregateCells(entry.aggregates, context)
|
|
2643
|
-
};
|
|
2644
|
-
}
|
|
2645
|
-
function specsByColumnOf(specs) {
|
|
2646
|
-
const byColumn = /* @__PURE__ */ new Map();
|
|
2647
|
-
for (const spec of specs) {
|
|
2648
|
-
const owned = byColumn.get(spec.columnId);
|
|
2649
|
-
if (owned === void 0) {
|
|
2650
|
-
byColumn.set(spec.columnId, [spec]);
|
|
2651
|
-
} else {
|
|
2652
|
-
owned.push(spec);
|
|
2653
|
-
}
|
|
2654
|
-
}
|
|
2655
|
-
return byColumn;
|
|
2656
|
-
}
|
|
2657
|
-
function buildExportTable(source, options = {}) {
|
|
2658
|
-
const { view, state } = source;
|
|
2659
|
-
const specs = options.includeAggregates ?? true ? source.options.aggregates ?? [] : [];
|
|
2660
|
-
const columns = pickColumns(view, options.columns ?? "visible");
|
|
2661
|
-
const context = {
|
|
2662
|
-
columns,
|
|
2663
|
-
specsByColumn: specsByColumnOf(specs),
|
|
2664
|
-
display: source.options.groupAggregateDisplay ?? "inline",
|
|
2665
|
-
locale: source.options.locale,
|
|
2666
|
-
messages: source.messages
|
|
2667
|
-
};
|
|
2668
|
-
const rows = scopedRows(source, options.scope ?? "all");
|
|
2669
|
-
const grouped = groupRows(
|
|
2670
|
-
rows,
|
|
2671
|
-
state.groupBy,
|
|
2672
|
-
ALL_EXPANDED,
|
|
2673
|
-
view.dataColumns
|
|
2674
|
-
);
|
|
2675
|
-
const displayRows = options.includeGroups ?? true ? withGroupAggregates(
|
|
2676
|
-
grouped,
|
|
2677
|
-
rows,
|
|
2678
|
-
state.groupBy,
|
|
2679
|
-
specs,
|
|
2680
|
-
view.dataColumns,
|
|
2681
|
-
context.display
|
|
2682
|
-
) : grouped.filter(isDataRow);
|
|
2683
|
-
let footer = null;
|
|
2684
|
-
if (specs.length > 0) {
|
|
2685
|
-
const totals = rows === view.rows ? view.grandTotal : computeAggregates(
|
|
2686
|
-
rows.map((entry) => entry.row),
|
|
2687
|
-
specs,
|
|
2688
|
-
view.dataColumns
|
|
2689
|
-
);
|
|
2690
|
-
footer = { kind: "total", cells: aggregateCells(totals, context) };
|
|
2691
|
-
}
|
|
2692
|
-
return {
|
|
2693
|
-
columns: describeColumns(columns, source),
|
|
2694
|
-
header: options.includeHeader ?? true,
|
|
2695
|
-
rows: displayRows.map((entry) => toExportRow(entry, source, context)),
|
|
2696
|
-
footer
|
|
2697
|
-
};
|
|
2698
|
-
}
|
|
2699
|
-
|
|
2700
|
-
// src/export/htmlTable.ts
|
|
2701
|
-
var ENTITIES = {
|
|
2702
|
-
"&": "&",
|
|
2703
|
-
"<": "<",
|
|
2704
|
-
">": ">",
|
|
2705
|
-
'"': """,
|
|
2706
|
-
"'": "'"
|
|
2707
|
-
};
|
|
2708
|
-
function escapeHtml(text) {
|
|
2709
|
-
return text.replace(/[&<>"']/g, (char) => ENTITIES[char] ?? char);
|
|
2710
|
-
}
|
|
2711
|
-
function cellHtml(tag, text, column) {
|
|
2712
|
-
const alignment = column?.alignment ?? "left";
|
|
2713
|
-
const style = alignment === "left" ? "" : ` style="text-align:${alignment}"`;
|
|
2714
|
-
return `<${tag}${style}>${escapeHtml(text)}</${tag}>`;
|
|
2715
|
-
}
|
|
2716
|
-
function cellsHtml(cells, columns) {
|
|
2717
|
-
return cells.map((cell, index) => cellHtml("td", cell.text, columns[index])).join("");
|
|
2718
|
-
}
|
|
2719
|
-
function groupRowHtml(row, columns) {
|
|
2720
|
-
const firstAggregate = row.cells.findIndex((cell) => cell.text !== "");
|
|
2721
|
-
const span = Math.max(
|
|
2722
|
-
1,
|
|
2723
|
-
firstAggregate === -1 ? row.cells.length : firstAggregate
|
|
2724
|
-
);
|
|
2725
|
-
const colspan = span > 1 ? ` colspan="${String(span)}"` : "";
|
|
2726
|
-
const label = `<td${colspan}>${escapeHtml(row.label)}</td>`;
|
|
2727
|
-
const aggregates = row.cells.slice(span).map((cell, index) => cellHtml("td", cell.text, columns[span + index])).join("");
|
|
2728
|
-
return `<tr class="export-group" data-level="${String(row.level)}">${label}${aggregates}</tr>`;
|
|
2729
|
-
}
|
|
2730
|
-
function rowHtml(row, columns) {
|
|
2731
|
-
switch (row.kind) {
|
|
2732
|
-
case "data":
|
|
2733
|
-
return `<tr>${cellsHtml(row.cells, columns)}</tr>`;
|
|
2734
|
-
case "group":
|
|
2735
|
-
return groupRowHtml(row, columns);
|
|
2736
|
-
case "groupSummary":
|
|
2737
|
-
return `<tr class="export-group-summary" data-level="${String(row.level)}">${cellsHtml(row.cells, columns)}</tr>`;
|
|
2738
|
-
}
|
|
2739
|
-
}
|
|
2740
|
-
function toHtmlTable(table, options = {}) {
|
|
2741
|
-
const { columns } = table;
|
|
2742
|
-
const caption = options.caption === void 0 ? "" : `<caption>${escapeHtml(options.caption)}</caption>`;
|
|
2743
|
-
const head = table.header ? `<thead><tr>${columns.map((column) => cellHtml("th", column.header, column)).join("")}</tr></thead>` : "";
|
|
2744
|
-
const body = `<tbody>${table.rows.map((row) => rowHtml(row, columns)).join("")}</tbody>`;
|
|
2745
|
-
const foot = table.footer === null ? "" : `<tfoot><tr>${cellsHtml(table.footer.cells, columns)}</tr></tfoot>`;
|
|
2746
|
-
return `<table class="gridkit-export-table">${caption}${head}${body}${foot}</table>`;
|
|
2747
|
-
}
|
|
2748
|
-
|
|
2749
|
-
// src/export/records.ts
|
|
2750
|
-
function rawText(value) {
|
|
2751
|
-
if (value === null) {
|
|
2752
|
-
return "";
|
|
2753
|
-
}
|
|
2754
|
-
if (value instanceof Date) {
|
|
2755
|
-
return Number.isNaN(value.getTime()) ? "" : value.toISOString();
|
|
2756
|
-
}
|
|
2757
|
-
return String(value);
|
|
2758
|
-
}
|
|
2759
|
-
function cellField(cell, values) {
|
|
2760
|
-
return {
|
|
2761
|
-
text: values === "raw" ? rawText(cell.value) : cell.text,
|
|
2762
|
-
isNumber: typeof cell.value === "number"
|
|
2763
|
-
};
|
|
2764
|
-
}
|
|
2765
|
-
function textField(text) {
|
|
2766
|
-
return { text, isNumber: false };
|
|
2767
|
-
}
|
|
2768
|
-
function textRecords(table, values) {
|
|
2769
|
-
const records = [];
|
|
2770
|
-
if (table.header) {
|
|
2771
|
-
records.push(table.columns.map((column) => textField(column.header)));
|
|
2772
|
-
}
|
|
2773
|
-
for (const row of table.rows) {
|
|
2774
|
-
records.push(
|
|
2775
|
-
row.cells.map(
|
|
2776
|
-
(cell, index) => row.kind === "group" && index === 0 ? textField(row.label) : cellField(cell, values)
|
|
2777
|
-
)
|
|
2778
|
-
);
|
|
2779
|
-
}
|
|
2780
|
-
if (table.footer !== null) {
|
|
2781
|
-
records.push(table.footer.cells.map((cell) => cellField(cell, values)));
|
|
2782
|
-
}
|
|
2783
|
-
return records;
|
|
2784
|
-
}
|
|
2785
|
-
|
|
2786
|
-
// src/export/tsv.ts
|
|
2787
|
-
var SEPARATORS = /\r\n|[\t\r\n]/g;
|
|
2788
|
-
function toTsv(table, options = {}) {
|
|
2789
|
-
return textRecords(table, options.values ?? "text").map(
|
|
2790
|
-
(record) => record.map((field) => field.text.replace(SEPARATORS, " ")).join(" ")
|
|
2791
|
-
).join("\n");
|
|
2792
|
-
}
|
|
2793
|
-
|
|
2794
|
-
// src/export/copy.ts
|
|
2795
|
-
function isCopyable(column) {
|
|
2796
|
-
return column.column.exportable !== false;
|
|
2797
|
-
}
|
|
2798
|
-
function hasRow(source, rowId) {
|
|
2799
|
-
return source.view.rows.some((entry) => entry.rowId === rowId);
|
|
2800
|
-
}
|
|
2801
|
-
function hasColumn(source, columnId) {
|
|
2802
|
-
return source.view.columns.some(
|
|
2803
|
-
(entry) => entry.id === columnId && isCopyable(entry)
|
|
2804
|
-
);
|
|
2805
|
-
}
|
|
2806
|
-
function selectionCopy(source) {
|
|
2807
|
-
const { state, view } = source;
|
|
2808
|
-
const selectedRows = new Set(state.rowSelection);
|
|
2809
|
-
const count = view.rows.filter(
|
|
2810
|
-
(entry) => selectedRows.has(entry.rowId)
|
|
2811
|
-
).length;
|
|
2812
|
-
if (count > 0) {
|
|
2813
|
-
return { kind: "rows", count };
|
|
2814
|
-
}
|
|
2815
|
-
const selectedColumns = new Set(state.columnSelection);
|
|
2816
|
-
const columnIds = view.columns.filter((entry) => selectedColumns.has(entry.id) && isCopyable(entry)).map((entry) => entry.id);
|
|
2817
|
-
if (columnIds.length > 0 && view.rows.length > 0) {
|
|
2818
|
-
return { kind: "columns", columnIds };
|
|
2819
|
-
}
|
|
2820
|
-
const cell = state.cellSelection;
|
|
2821
|
-
if (cell !== null && hasRow(source, cell.rowId) && hasColumn(source, cell.columnId)) {
|
|
2822
|
-
return { kind: "cell", rowId: cell.rowId, columnId: cell.columnId };
|
|
2823
|
-
}
|
|
2824
|
-
return null;
|
|
2825
|
-
}
|
|
2826
|
-
function canCopySelection(source) {
|
|
2827
|
-
return selectionCopy(source) !== null;
|
|
2828
|
-
}
|
|
2829
|
-
function withRows(source, rowIds) {
|
|
2830
|
-
return { ...source, state: { ...source.state, rowSelection: rowIds } };
|
|
2831
|
-
}
|
|
2832
|
-
function contentOf(source, { scope, columns, header }, unit) {
|
|
2833
|
-
const table = buildExportTable(source, {
|
|
2834
|
-
scope,
|
|
2835
|
-
columns: columns ?? "visible",
|
|
2836
|
-
includeHeader: header,
|
|
2837
|
-
includeGroups: false,
|
|
2838
|
-
includeAggregates: false
|
|
2839
|
-
});
|
|
2840
|
-
if (table.columns.length === 0 || table.rows.length === 0) {
|
|
2841
|
-
return null;
|
|
2842
|
-
}
|
|
2843
|
-
return {
|
|
2844
|
-
text: toTsv(table),
|
|
2845
|
-
html: toHtmlTable(table),
|
|
2846
|
-
count: unit === "columns" ? table.columns.length : table.rows.length,
|
|
2847
|
-
unit
|
|
2848
|
-
};
|
|
2849
|
-
}
|
|
2850
|
-
function cellContent(source, rowId, columnId) {
|
|
2851
|
-
if (!hasRow(source, rowId) || !hasColumn(source, columnId)) {
|
|
2852
|
-
return null;
|
|
2853
|
-
}
|
|
2854
|
-
return contentOf(
|
|
2855
|
-
withRows(source, [rowId]),
|
|
2856
|
-
{ scope: "selection", columns: [columnId], header: false },
|
|
2857
|
-
"cells"
|
|
2858
|
-
);
|
|
2859
|
-
}
|
|
2860
|
-
function rowContent(source, rowId) {
|
|
2861
|
-
if (!hasRow(source, rowId)) {
|
|
2862
|
-
return null;
|
|
2863
|
-
}
|
|
2864
|
-
return contentOf(
|
|
2865
|
-
withRows(source, [rowId]),
|
|
2866
|
-
{ scope: "selection", header: false },
|
|
2867
|
-
"rows"
|
|
2868
|
-
);
|
|
2869
|
-
}
|
|
2870
|
-
function selectionContent(source) {
|
|
2871
|
-
const selection = selectionCopy(source);
|
|
2872
|
-
switch (selection?.kind) {
|
|
2873
|
-
case void 0:
|
|
2874
|
-
return null;
|
|
2875
|
-
case "rows":
|
|
2876
|
-
return contentOf(
|
|
2877
|
-
source,
|
|
2878
|
-
{ scope: "selection", header: selection.count > 1 },
|
|
2879
|
-
"rows"
|
|
2880
|
-
);
|
|
2881
|
-
case "columns":
|
|
2882
|
-
return contentOf(
|
|
2883
|
-
source,
|
|
2884
|
-
{ scope: "all", columns: selection.columnIds, header: true },
|
|
2885
|
-
"columns"
|
|
2886
|
-
);
|
|
2887
|
-
case "cell":
|
|
2888
|
-
return cellContent(source, selection.rowId, selection.columnId);
|
|
2889
|
-
}
|
|
2890
|
-
}
|
|
2891
|
-
function copyContent(source, request) {
|
|
2892
|
-
switch (request.kind) {
|
|
2893
|
-
case "cell":
|
|
2894
|
-
return cellContent(source, request.rowId, request.columnId);
|
|
2895
|
-
case "row":
|
|
2896
|
-
return rowContent(source, request.rowId);
|
|
2897
|
-
case "selection":
|
|
2898
|
-
return selectionContent(source);
|
|
2899
|
-
}
|
|
2900
|
-
}
|
|
2901
|
-
|
|
2902
|
-
// src/export/exportFile.ts
|
|
2903
|
-
function withExtension(fileName, extension) {
|
|
2904
|
-
const suffix = `.${extension}`;
|
|
2905
|
-
return fileName.toLowerCase().endsWith(suffix.toLowerCase()) ? fileName : fileName + suffix;
|
|
2906
|
-
}
|
|
2907
|
-
function writerFor(format, writers) {
|
|
2908
|
-
if (typeof format !== "string") {
|
|
2909
|
-
return format;
|
|
2910
|
-
}
|
|
2911
|
-
const writer = writers.get(format);
|
|
2912
|
-
if (writer === void 0) {
|
|
2913
|
-
reportError(
|
|
2914
|
-
`there is no export writer for \`${format}\` \u2014 register one through \`exportWriters\`.`
|
|
2915
|
-
);
|
|
2916
|
-
return null;
|
|
2917
|
-
}
|
|
2918
|
-
return writer;
|
|
2919
|
-
}
|
|
2920
|
-
function fileNameFor(options, writer) {
|
|
2921
|
-
const { fileName = "export" } = options;
|
|
2922
|
-
const name = typeof fileName === "function" ? fileName(writer.format) : fileName;
|
|
2923
|
-
return withExtension(name, writer.fileExtension);
|
|
2924
|
-
}
|
|
2925
|
-
function exportFile(source, format, options, writers) {
|
|
2926
|
-
const writer = writerFor(format, writers);
|
|
2927
|
-
if (writer === null) {
|
|
2928
|
-
return null;
|
|
2929
|
-
}
|
|
2930
|
-
const content = writer.write(buildExportTable(source, options), {
|
|
2931
|
-
locale: source.options.locale,
|
|
2932
|
-
messages: source.messages,
|
|
2933
|
-
options
|
|
2934
|
-
});
|
|
2935
|
-
const fileName = fileNameFor(options, writer);
|
|
2936
|
-
const { mimeType } = writer;
|
|
2937
|
-
return content instanceof Promise ? content.then((resolved) => ({ fileName, mimeType, content: resolved })) : { fileName, mimeType, content };
|
|
2938
|
-
}
|
|
2939
|
-
|
|
2940
|
-
// src/export/print.ts
|
|
2941
|
-
var PORTRAIT_COLUMN_LIMIT = 6;
|
|
2942
|
-
function resolveOrientation(table, options) {
|
|
2943
|
-
return options.orientation ?? (table.columns.length > PORTRAIT_COLUMN_LIMIT ? "landscape" : "portrait");
|
|
2944
|
-
}
|
|
2945
|
-
function timestampText(timestamp, locale) {
|
|
2946
|
-
const date = timestamp === true ? /* @__PURE__ */ new Date() : timestamp;
|
|
2947
|
-
return new Intl.DateTimeFormat(locale, {
|
|
2948
|
-
dateStyle: "medium",
|
|
2949
|
-
timeStyle: "short"
|
|
2950
|
-
}).format(date);
|
|
2951
|
-
}
|
|
2952
|
-
function line(tag, className, text) {
|
|
2953
|
-
return text === void 0 || text === "" ? "" : `<${tag} class="${className}">${escapeHtml(text)}</${tag}>`;
|
|
2954
|
-
}
|
|
2955
|
-
function headerHtml(options) {
|
|
2956
|
-
const { timestamp = false } = options;
|
|
2957
|
-
const lines = line("h1", "print-title", options.title) + line("p", "print-subtitle", options.subtitle) + (timestamp === false ? "" : line("p", "print-timestamp", timestampText(timestamp, options.locale)));
|
|
2958
|
-
return lines === "" ? "" : `<header class="gridkit-print-header">${lines}</header>`;
|
|
2959
|
-
}
|
|
2960
|
-
function buildPrintDocument(table, options = {}) {
|
|
2961
|
-
const footer = line("footer", "gridkit-print-footer", options.footer);
|
|
2962
|
-
return {
|
|
2963
|
-
title: options.title ?? "",
|
|
2964
|
-
bodyHtml: `${headerHtml(options)}${toHtmlTable(table)}${footer}`,
|
|
2965
|
-
page: {
|
|
2966
|
-
paperSize: options.paperSize ?? "A4",
|
|
2967
|
-
orientation: resolveOrientation(table, options),
|
|
2968
|
-
pageNumbers: options.pageNumbers ?? true,
|
|
2969
|
-
fitToWidth: options.fitToWidth ?? false
|
|
2970
|
-
}
|
|
2971
|
-
};
|
|
2972
|
-
}
|
|
2973
|
-
function exportPrintDocument(source, options = {}) {
|
|
2974
|
-
return buildPrintDocument(buildExportTable(source, options), {
|
|
2975
|
-
...options,
|
|
2976
|
-
title: options.title ?? source.options.label,
|
|
2977
|
-
locale: options.locale ?? source.options.locale
|
|
2978
|
-
});
|
|
2979
|
-
}
|
|
2980
|
-
|
|
2981
|
-
// src/export/csv.ts
|
|
2982
|
-
var BOM = "\uFEFF";
|
|
2983
|
-
var FORMULA_START = /^[=+\-@\t\r]/;
|
|
2984
|
-
var SIGN_START = /^[+-]/;
|
|
2985
|
-
var NEEDS_QUOTES = /["\r\n]/;
|
|
2986
|
-
function autoDelimiter(locale) {
|
|
2987
|
-
const decimal = new Intl.NumberFormat(locale).formatToParts(1.5).find((part) => part.type === "decimal")?.value;
|
|
2988
|
-
return decimal === "," ? ";" : ",";
|
|
2989
|
-
}
|
|
2990
|
-
function neutralize(field) {
|
|
2991
|
-
const { text } = field;
|
|
2992
|
-
if (!FORMULA_START.test(text) || field.isNumber && SIGN_START.test(text)) {
|
|
2993
|
-
return text;
|
|
2994
|
-
}
|
|
2995
|
-
return `'${text}`;
|
|
2996
|
-
}
|
|
2997
|
-
function quote(text, delimiter) {
|
|
2998
|
-
return text.includes(delimiter) || NEEDS_QUOTES.test(text) ? `"${text.replaceAll('"', '""')}"` : text;
|
|
2999
|
-
}
|
|
3000
|
-
function toCsv(table, options = {}) {
|
|
3001
|
-
const delimiter = options.delimiter === "auto" ? autoDelimiter(options.locale) : options.delimiter ?? ",";
|
|
3002
|
-
const guard = options.neutralizeFormulas ?? true;
|
|
3003
|
-
const lines = textRecords(table, options.values ?? "text").map(
|
|
3004
|
-
(record) => record.map((field) => quote(guard ? neutralize(field) : field.text, delimiter)).join(delimiter)
|
|
3005
|
-
);
|
|
3006
|
-
return (options.bom ?? true ? BOM : "") + lines.join(options.eol ?? "\r\n");
|
|
3007
|
-
}
|
|
3008
|
-
|
|
3009
|
-
// src/export/json.ts
|
|
3010
|
-
function uniqueNames(names) {
|
|
3011
|
-
const used = /* @__PURE__ */ new Set();
|
|
3012
|
-
return names.map((name) => {
|
|
3013
|
-
let unique = name;
|
|
3014
|
-
for (let n = 2; used.has(unique); n += 1) {
|
|
3015
|
-
unique = `${name} (${String(n)})`;
|
|
3016
|
-
}
|
|
3017
|
-
used.add(unique);
|
|
3018
|
-
return unique;
|
|
3019
|
-
});
|
|
3020
|
-
}
|
|
3021
|
-
function toJson(table, options = {}) {
|
|
3022
|
-
const keys = options.keys === "header" ? uniqueNames(table.columns.map((column) => column.header)) : table.columns.map((column) => column.id);
|
|
3023
|
-
const records = table.rows.flatMap(
|
|
3024
|
-
(row) => row.kind === "data" ? [
|
|
3025
|
-
Object.fromEntries(
|
|
3026
|
-
keys.map((key, index) => [key, row.cells[index]?.value ?? null])
|
|
3027
|
-
)
|
|
3028
|
-
] : []
|
|
3029
|
-
);
|
|
3030
|
-
return JSON.stringify(records, null, options.space);
|
|
3031
|
-
}
|
|
3032
|
-
|
|
3033
|
-
// src/export/writer.ts
|
|
3034
|
-
var csvWriter = {
|
|
3035
|
-
format: "csv",
|
|
3036
|
-
fileExtension: "csv",
|
|
3037
|
-
mimeType: "text/csv;charset=utf-8",
|
|
3038
|
-
write: (table, { locale, options }) => toCsv(table, { locale, ...options.csv })
|
|
3039
|
-
};
|
|
3040
|
-
var jsonWriter = {
|
|
3041
|
-
format: "json",
|
|
3042
|
-
fileExtension: "json",
|
|
3043
|
-
mimeType: "application/json",
|
|
3044
|
-
write: (table, { options }) => toJson(table, options.json)
|
|
3045
|
-
};
|
|
3046
|
-
function resolveExportWriters(writers) {
|
|
3047
|
-
return new Map(
|
|
3048
|
-
[csvWriter, jsonWriter, ...writers ?? []].map((writer) => [
|
|
3049
|
-
writer.format,
|
|
3050
|
-
writer
|
|
3051
|
-
])
|
|
3052
|
-
);
|
|
3053
|
-
}
|
|
3054
|
-
|
|
3055
|
-
// src/filterMenu/operators.ts
|
|
3056
|
-
function filterOperatorFamily(type) {
|
|
3057
|
-
return kindOf(type);
|
|
3058
|
-
}
|
|
3059
|
-
var familyOperators = {
|
|
3060
|
-
text: [
|
|
3061
|
-
"contains",
|
|
3062
|
-
"notContains",
|
|
3063
|
-
"eq",
|
|
3064
|
-
"ne",
|
|
3065
|
-
"startsWith",
|
|
3066
|
-
"endsWith",
|
|
3067
|
-
"isEmpty",
|
|
3068
|
-
"isNotEmpty"
|
|
3069
|
-
],
|
|
3070
|
-
number: [
|
|
3071
|
-
"eq",
|
|
3072
|
-
"ne",
|
|
3073
|
-
"gt",
|
|
3074
|
-
"gte",
|
|
3075
|
-
"lt",
|
|
3076
|
-
"lte",
|
|
3077
|
-
"between",
|
|
3078
|
-
"isEmpty",
|
|
3079
|
-
"isNotEmpty"
|
|
3080
|
-
],
|
|
3081
|
-
date: ["eq", "ne", "lt", "gt", "between", "isEmpty", "isNotEmpty"],
|
|
3082
|
-
boolean: ["eq", "isEmpty", "isNotEmpty"]
|
|
3083
|
-
};
|
|
3084
|
-
var instantOperators = [
|
|
3085
|
-
"lt",
|
|
3086
|
-
"gt",
|
|
3087
|
-
"between",
|
|
3088
|
-
"isEmpty",
|
|
3089
|
-
"isNotEmpty"
|
|
3090
|
-
];
|
|
3091
|
-
function defaultFilterOperators(type) {
|
|
3092
|
-
return type === "dateTime" || type === "time" ? instantOperators : familyOperators[filterOperatorFamily(type)];
|
|
3093
|
-
}
|
|
3094
|
-
function filterOperandArity(operator) {
|
|
3095
|
-
switch (operator) {
|
|
3096
|
-
case "isEmpty":
|
|
3097
|
-
case "isNotEmpty":
|
|
3098
|
-
return 0;
|
|
3099
|
-
case "between":
|
|
3100
|
-
return 2;
|
|
3101
|
-
case "eq":
|
|
3102
|
-
case "ne":
|
|
3103
|
-
case "contains":
|
|
3104
|
-
case "notContains":
|
|
3105
|
-
case "startsWith":
|
|
3106
|
-
case "endsWith":
|
|
3107
|
-
case "gt":
|
|
3108
|
-
case "gte":
|
|
3109
|
-
case "lt":
|
|
3110
|
-
case "lte":
|
|
3111
|
-
case "in":
|
|
3112
|
-
return 1;
|
|
3113
|
-
}
|
|
3114
|
-
}
|
|
3115
|
-
var NUMBER_INPUT = /^[+-]?(?:\d+\.?\d*|\.\d+)(?:e[+-]?\d+)?$/i;
|
|
3116
|
-
var DATE_INPUT = /^(\d{4})-(\d{2})-(\d{2})(?:T(\d{2}):(\d{2})(?::(\d{2})(?:\.(\d{1,3}))?)?)?$/;
|
|
3117
|
-
function parseNumber(text) {
|
|
3118
|
-
const value = Number(text);
|
|
3119
|
-
return NUMBER_INPUT.test(text) && Number.isFinite(value) ? value : void 0;
|
|
3120
|
-
}
|
|
3121
|
-
function parseDate(text) {
|
|
3122
|
-
const match = DATE_INPUT.exec(text);
|
|
3123
|
-
if (match === null) {
|
|
3124
|
-
return void 0;
|
|
3125
|
-
}
|
|
3126
|
-
const [
|
|
3127
|
-
,
|
|
3128
|
-
year,
|
|
3129
|
-
month,
|
|
3130
|
-
day,
|
|
3131
|
-
hours = "0",
|
|
3132
|
-
minutes = "0",
|
|
3133
|
-
seconds = "0",
|
|
3134
|
-
fraction = ""
|
|
3135
|
-
] = match;
|
|
3136
|
-
if (Number(hours) > 23 || Number(minutes) > 59 || Number(seconds) > 59) {
|
|
3137
|
-
return void 0;
|
|
3138
|
-
}
|
|
3139
|
-
const date = new Date(
|
|
3140
|
-
Number(year),
|
|
3141
|
-
Number(month) - 1,
|
|
3142
|
-
Number(day),
|
|
3143
|
-
Number(hours),
|
|
3144
|
-
Number(minutes),
|
|
3145
|
-
Number(seconds),
|
|
3146
|
-
Number(fraction.padEnd(3, "0"))
|
|
3147
|
-
);
|
|
3148
|
-
return date.getFullYear() === Number(year) && date.getMonth() === Number(month) - 1 && date.getDate() === Number(day) ? date : void 0;
|
|
3149
|
-
}
|
|
3150
|
-
function parseBoolean(text) {
|
|
3151
|
-
if (text === "true") {
|
|
3152
|
-
return true;
|
|
3153
|
-
}
|
|
3154
|
-
return text === "false" ? false : void 0;
|
|
3155
|
-
}
|
|
3156
|
-
function parseFilterOperand(text, type) {
|
|
3157
|
-
if (text === "") {
|
|
3158
|
-
return void 0;
|
|
3159
|
-
}
|
|
3160
|
-
switch (filterOperatorFamily(type)) {
|
|
3161
|
-
case "text":
|
|
3162
|
-
return text;
|
|
3163
|
-
case "number":
|
|
3164
|
-
return parseNumber(text.trim());
|
|
3165
|
-
case "date":
|
|
3166
|
-
return parseDate(text.trim());
|
|
3167
|
-
case "boolean":
|
|
3168
|
-
return parseBoolean(text.trim());
|
|
3169
|
-
}
|
|
3170
|
-
}
|
|
3171
|
-
function pad(value, width = 2) {
|
|
3172
|
-
return String(value).padStart(width, "0");
|
|
3173
|
-
}
|
|
3174
|
-
function dayInput(date) {
|
|
3175
|
-
return `${pad(date.getFullYear(), 4)}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
|
|
3176
|
-
}
|
|
3177
|
-
function momentInput(date) {
|
|
3178
|
-
const minute = `${dayInput(date)}T${pad(date.getHours())}:${pad(date.getMinutes())}`;
|
|
3179
|
-
const seconds = date.getSeconds();
|
|
3180
|
-
const milliseconds = date.getMilliseconds();
|
|
3181
|
-
if (seconds === 0 && milliseconds === 0) {
|
|
3182
|
-
return minute;
|
|
3183
|
-
}
|
|
3184
|
-
const second = `${minute}:${pad(seconds)}`;
|
|
3185
|
-
return milliseconds === 0 ? second : `${second}.${pad(milliseconds, 3)}`;
|
|
3186
|
-
}
|
|
3187
|
-
function formatFilterOperand(value, type) {
|
|
3188
|
-
if (value === null || value === void 0) {
|
|
3189
|
-
return "";
|
|
3190
|
-
}
|
|
3191
|
-
const date = filterOperatorFamily(type) === "date" ? toDate(value) : void 0;
|
|
3192
|
-
if (date === void 0) {
|
|
3193
|
-
return String(value);
|
|
3194
|
-
}
|
|
3195
|
-
return type === "date" ? dayInput(date) : momentInput(date);
|
|
3196
|
-
}
|
|
3197
|
-
|
|
3198
|
-
// src/filterMenu/options.ts
|
|
3199
|
-
var DEFAULT_FILTER_VALUE_LIMIT = 1e4;
|
|
3200
|
-
function conditionOperators(operators) {
|
|
3201
|
-
return operators.includes("in") ? operators.filter((operator) => operator !== "in") : operators;
|
|
3202
|
-
}
|
|
3203
|
-
function resolveColumnFilterMenu(options, column) {
|
|
3204
|
-
if (!(column.filterable ?? options.filterableColumns ?? false)) {
|
|
3205
|
-
return null;
|
|
3206
|
-
}
|
|
3207
|
-
const grid = options.filterMenu;
|
|
3208
|
-
const own = column.filterMenu;
|
|
3209
|
-
return {
|
|
3210
|
-
ui: own?.ui ?? grid?.ui ?? "simple",
|
|
3211
|
-
operators: conditionOperators(
|
|
3212
|
-
own?.operators ?? defaultFilterOperators(column.type)
|
|
3213
|
-
),
|
|
3214
|
-
family: filterOperatorFamily(column.type),
|
|
3215
|
-
showCounts: grid?.showCounts ?? false,
|
|
3216
|
-
valueLimit: grid?.valueLimit ?? DEFAULT_FILTER_VALUE_LIMIT
|
|
3217
|
-
};
|
|
3218
|
-
}
|
|
3219
|
-
|
|
3220
|
-
// src/messages.ts
|
|
3221
|
-
function localeKey2(locale) {
|
|
3222
|
-
return typeof locale === "string" ? locale : locale?.join(",") ?? "";
|
|
3223
|
-
}
|
|
3224
|
-
var countFormats = /* @__PURE__ */ new Map();
|
|
3225
|
-
function countFormat(locale) {
|
|
3226
|
-
const key = localeKey2(locale);
|
|
3227
|
-
let format = countFormats.get(key);
|
|
3228
|
-
if (format === void 0) {
|
|
3229
|
-
const numberFormat = new Intl.NumberFormat(locale, {
|
|
3230
|
-
maximumFractionDigits: 0
|
|
3231
|
-
});
|
|
3232
|
-
format = (count) => numberFormat.format(count);
|
|
3233
|
-
countFormats.set(key, format);
|
|
3234
|
-
}
|
|
3235
|
-
return format;
|
|
3236
|
-
}
|
|
3237
|
-
function columnCount(n, count, change) {
|
|
3238
|
-
return count === 1 ? `1 column ${change}` : `${n(count)} columns ${change}`;
|
|
3239
|
-
}
|
|
3240
|
-
function searchResults(n, count) {
|
|
3241
|
-
if (count === 0) {
|
|
3242
|
-
return "No rows found";
|
|
3243
|
-
}
|
|
3244
|
-
return count === 1 ? "1 row found" : `${n(count)} rows found`;
|
|
3245
|
-
}
|
|
3246
|
-
function selectedCount(n, count, target) {
|
|
3247
|
-
const noun = target === "rows" ? "row" : "column";
|
|
3248
|
-
if (count === 0) {
|
|
3249
|
-
return `No ${noun}s selected`;
|
|
3250
|
-
}
|
|
3251
|
-
return count === 1 ? `1 ${noun} selected` : `${n(count)} ${noun}s selected`;
|
|
3252
|
-
}
|
|
3253
|
-
var operatorLabels = {
|
|
3254
|
-
eq: "Equals",
|
|
3255
|
-
ne: "Does not equal",
|
|
3256
|
-
contains: "Contains",
|
|
3257
|
-
notContains: "Does not contain",
|
|
3258
|
-
startsWith: "Starts with",
|
|
3259
|
-
endsWith: "Ends with",
|
|
3260
|
-
gt: "Greater than",
|
|
3261
|
-
gte: "Greater than or equal to",
|
|
3262
|
-
lt: "Less than",
|
|
3263
|
-
lte: "Less than or equal to",
|
|
3264
|
-
between: "Between",
|
|
3265
|
-
in: "Is one of",
|
|
3266
|
-
isEmpty: "Is blank",
|
|
3267
|
-
isNotEmpty: "Is not blank"
|
|
3268
|
-
};
|
|
3269
|
-
var dateOperatorLabels = {
|
|
3270
|
-
lt: "Before",
|
|
3271
|
-
lte: "On or before",
|
|
3272
|
-
gt: "After",
|
|
3273
|
-
gte: "On or after"
|
|
3274
|
-
};
|
|
3275
|
-
function filterOperatorLabel(operator, family) {
|
|
3276
|
-
return (family === "date" ? dateOperatorLabels[operator] : void 0) ?? operatorLabels[operator];
|
|
3277
|
-
}
|
|
3278
|
-
function filterSearchFirst(n, total) {
|
|
3279
|
-
return total === 1 ? "Type to search 1 value" : `Type to search ${n(total)} values`;
|
|
3280
|
-
}
|
|
3281
|
-
function filterResults(n, shown, total) {
|
|
3282
|
-
return `${n(shown)} of ${n(total)} ${total === 1 ? "row" : "rows"}`;
|
|
3283
|
-
}
|
|
3284
|
-
var filterValueRequests = {
|
|
3285
|
-
text: "Enter a value",
|
|
3286
|
-
number: "Enter a number",
|
|
3287
|
-
date: "Enter a date",
|
|
3288
|
-
boolean: "Choose a value"
|
|
3289
|
-
};
|
|
3290
|
-
var filterOperatorMenus = {
|
|
3291
|
-
text: "Text filters",
|
|
3292
|
-
number: "Number filters",
|
|
3293
|
-
date: "Date filters",
|
|
3294
|
-
boolean: "Boolean filters"
|
|
3295
|
-
};
|
|
3296
|
-
function copied(n, count, unit) {
|
|
3297
|
-
return count === 1 ? `1 ${unit.slice(0, -1)} copied` : `${n(count)} ${unit} copied`;
|
|
3298
|
-
}
|
|
3299
|
-
function createDefaultMessages(locale) {
|
|
3300
|
-
const n = countFormat(locale);
|
|
3301
|
-
return {
|
|
3302
|
-
pagerLabel: "Pagination",
|
|
3303
|
-
firstPage: "First",
|
|
3304
|
-
previousPage: "Previous",
|
|
3305
|
-
nextPage: "Next",
|
|
3306
|
-
lastPage: "Last",
|
|
3307
|
-
pageSizeLabel: "Rows per page",
|
|
3308
|
-
pageButtonLabel: (page) => `Page ${n(page)}`,
|
|
3309
|
-
pageStatus: (page, pageCount) => `Page ${n(page)} of ${n(pageCount)}`,
|
|
3310
|
-
loadingMore: "Loading more\u2026",
|
|
3311
|
-
booleanTrue: "true",
|
|
3312
|
-
booleanFalse: "false",
|
|
3313
|
-
blankGroupValue: "(blank)",
|
|
3314
|
-
groupByBarLabel: "Grouped by",
|
|
3315
|
-
groupByBarPlaceholder: "Drag a column here to group by it",
|
|
3316
|
-
groupByChipLabel: (columnName2, level, levelCount) => levelCount > 1 ? `${columnName2}, level ${n(level)} of ${n(levelCount)}` : columnName2,
|
|
3317
|
-
removeGroupBy: (columnName2) => `Stop grouping by ${columnName2}`,
|
|
3318
|
-
columnResized: (columnName2, width) => `${columnName2}, ${n(width)} pixels wide`,
|
|
3319
|
-
columnMoved: (columnName2, position, columnCount2) => `${columnName2}, column ${n(position)} of ${n(columnCount2)}`,
|
|
3320
|
-
columnSorted: (columnName2, direction, key, keyCount) => {
|
|
3321
|
-
const sorted = `${columnName2} sorted ${direction === "asc" ? "ascending" : "descending"}`;
|
|
3322
|
-
return keyCount > 1 ? `${sorted}, key ${n(key)} of ${n(keyCount)}` : sorted;
|
|
3323
|
-
},
|
|
3324
|
-
sortCleared: (columnName2) => `${columnName2}, sort cleared`,
|
|
3325
|
-
groupedBy: (columnName2, level, levelCount) => levelCount > 1 ? `Grouped by ${columnName2}, level ${n(level)} of ${n(levelCount)}` : `Grouped by ${columnName2}`,
|
|
3326
|
-
groupingRemoved: (columnName2) => `${columnName2}, grouping removed`,
|
|
3327
|
-
groupExpanded: "Group expanded",
|
|
3328
|
-
groupCollapsed: "Group collapsed",
|
|
3329
|
-
allGroupsExpanded: "All groups expanded",
|
|
3330
|
-
allGroupsCollapsed: "All groups collapsed",
|
|
3331
|
-
selectedCount: (count, target) => selectedCount(n, count, target),
|
|
3332
|
-
cellSelected: (columnName2, rowNumber) => `${columnName2}, row ${n(rowNumber)}, selected`,
|
|
3333
|
-
columnHidden: (columnName2) => `${columnName2}, column hidden`,
|
|
3334
|
-
columnShown: (columnName2) => `${columnName2}, column shown`,
|
|
3335
|
-
columnsHidden: (count) => columnCount(n, count, "hidden"),
|
|
3336
|
-
columnsShown: (count) => columnCount(n, count, "shown"),
|
|
3337
|
-
columnsAutoFitted: (count) => columnCount(n, count, "autofitted"),
|
|
3338
|
-
headerMenuLabel: (columnName2) => `${columnName2} column menu`,
|
|
3339
|
-
cellMenuLabel: "Row menu",
|
|
3340
|
-
groupMenuLabel: "Group menu",
|
|
3341
|
-
bodyMenuLabel: "Grid menu",
|
|
3342
|
-
sortAscending: "Sort ascending",
|
|
3343
|
-
sortDescending: "Sort descending",
|
|
3344
|
-
clearSort: "Clear sort",
|
|
3345
|
-
clearAllSorting: "Clear all sorting",
|
|
3346
|
-
groupByColumn: (columnName2) => `Group by ${columnName2}`,
|
|
3347
|
-
ungroupAll: "Ungroup all",
|
|
3348
|
-
expandAllGroups: "Expand all groups",
|
|
3349
|
-
collapseAllGroups: "Collapse all groups",
|
|
3350
|
-
hideColumn: "Hide column",
|
|
3351
|
-
autoFitColumn: "Autofit column",
|
|
3352
|
-
autoFitAllColumns: "Autofit all columns",
|
|
3353
|
-
selectAllRows: "Select all rows",
|
|
3354
|
-
clearSelection: "Clear selection",
|
|
3355
|
-
clearFilters: "Clear filters",
|
|
3356
|
-
chooseColumns: "Choose columns",
|
|
3357
|
-
toolbarLabel: "Grid toolbar",
|
|
3358
|
-
searchLabel: "Search",
|
|
3359
|
-
searchPlaceholder: "Search\u2026",
|
|
3360
|
-
moreToolbarItems: "More",
|
|
3361
|
-
searchResults: (count) => searchResults(n, count),
|
|
3362
|
-
columnChooserLabel: "Columns",
|
|
3363
|
-
columnChooserSearchLabel: "Search columns",
|
|
3364
|
-
showAllColumns: "Show all",
|
|
3365
|
-
noMatchingColumns: "No matching columns",
|
|
3366
|
-
filterOperatorLabel,
|
|
3367
|
-
filterBlanks: "(Blanks)",
|
|
3368
|
-
filterSearchFirst: (total) => filterSearchFirst(n, total),
|
|
3369
|
-
filterMoreValues: (count) => `${n(count)} more, refine the search`,
|
|
3370
|
-
openFilter: "Filter\u2026",
|
|
3371
|
-
clearColumnFilter: "Clear filter",
|
|
3372
|
-
filterMenuLabel: (columnName2) => `${columnName2} filter`,
|
|
3373
|
-
columnFiltered: "Filtered",
|
|
3374
|
-
applyFilter: "OK",
|
|
3375
|
-
cancelFilter: "Cancel",
|
|
3376
|
-
customFilter: "Custom filter",
|
|
3377
|
-
filterResults: (shown, total) => filterResults(n, shown, total),
|
|
3378
|
-
filterConditionLabel: (position) => `Condition ${n(position)}`,
|
|
3379
|
-
filterOperatorFieldLabel: "Operator",
|
|
3380
|
-
filterValueLabel: "Value",
|
|
3381
|
-
filterFromLabel: "From",
|
|
3382
|
-
filterToLabel: "To",
|
|
3383
|
-
filterCombinatorLabel: "Combine conditions",
|
|
3384
|
-
filterAnd: "And",
|
|
3385
|
-
filterOr: "Or",
|
|
3386
|
-
filterValueInvalid: (family) => filterValueRequests[family],
|
|
3387
|
-
filterSearchLabel: "Search values",
|
|
3388
|
-
filterSelectAll: "Select all",
|
|
3389
|
-
filterValuesLabel: "Values",
|
|
3390
|
-
filterByCondition: "Filtered by condition",
|
|
3391
|
-
filterOperatorMenu: (family) => filterOperatorMenus[family],
|
|
3392
|
-
filterBackToValues: "Back to values",
|
|
3393
|
-
exportMenu: "Export",
|
|
3394
|
-
exportCsv: "Export to CSV",
|
|
3395
|
-
exportJson: "Export to JSON",
|
|
3396
|
-
exportXlsx: "Export to Excel",
|
|
3397
|
-
exportPdf: "Export to PDF",
|
|
3398
|
-
exportSelectionCsv: "Export selection to CSV",
|
|
3399
|
-
exportSelectionJson: "Export selection to JSON",
|
|
3400
|
-
exportSelectionXlsx: "Export selection to Excel",
|
|
3401
|
-
exportFailed: "Export failed",
|
|
3402
|
-
copyCell: "Copy cell",
|
|
3403
|
-
copyRow: "Copy row",
|
|
3404
|
-
copySelection: "Copy selection",
|
|
3405
|
-
copied: (count, unit) => copied(n, count, unit),
|
|
3406
|
-
copyFailed: "Copy failed",
|
|
3407
|
-
print: "Print",
|
|
3408
|
-
printFailed: "Print failed"
|
|
3409
|
-
};
|
|
3410
|
-
}
|
|
3411
|
-
var defaultMessages = createDefaultMessages();
|
|
3412
|
-
var localeDefaults = /* @__PURE__ */ new Map();
|
|
3413
|
-
function defaultsFor(locale) {
|
|
3414
|
-
if (locale === void 0) {
|
|
3415
|
-
return defaultMessages;
|
|
3416
|
-
}
|
|
3417
|
-
const key = localeKey2(locale);
|
|
3418
|
-
let defaults = localeDefaults.get(key);
|
|
3419
|
-
if (defaults === void 0) {
|
|
3420
|
-
defaults = createDefaultMessages(locale);
|
|
3421
|
-
localeDefaults.set(key, defaults);
|
|
3422
|
-
}
|
|
3423
|
-
return defaults;
|
|
3424
|
-
}
|
|
3425
|
-
function resolveMessages(messages, locale) {
|
|
3426
|
-
const defaults = defaultsFor(locale);
|
|
3427
|
-
return messages === void 0 ? defaults : { ...defaults, ...messages };
|
|
3428
|
-
}
|
|
3429
|
-
|
|
3430
|
-
// src/util/filterEditor.ts
|
|
3431
|
-
function touchesColumn(entry, columnId) {
|
|
3432
|
-
return entry.kind === "group" ? entry.entries.some((nested) => touchesColumn(nested, columnId)) : entry.columnId === columnId;
|
|
3433
|
-
}
|
|
3434
|
-
function isOperatorOn(entry, columnId) {
|
|
3435
|
-
return entry.kind === "operator" && entry.columnId === columnId;
|
|
3436
|
-
}
|
|
3437
|
-
function isConditionOn(entry, columnId) {
|
|
3438
|
-
return isOperatorOn(entry, columnId) && entry.operator !== "in";
|
|
3439
|
-
}
|
|
3440
|
-
function valuesShape(entry, columnId) {
|
|
3441
|
-
const values = (candidate) => candidate !== void 0 && isOperatorOn(candidate, columnId) && candidate.operator === "in" && isScalarList(candidate.value) ? candidate.value : void 0;
|
|
3442
|
-
const blanks = (candidate) => candidate !== void 0 && isOperatorOn(candidate, columnId) && candidate.operator === "isEmpty";
|
|
3443
|
-
const alone = values(entry);
|
|
3444
|
-
if (alone !== void 0) {
|
|
3445
|
-
return { kind: "values", values: alone, includeBlanks: false };
|
|
3446
|
-
}
|
|
3447
|
-
if (entry.kind !== "group" || entry.combinator !== "or" || entry.entries.length !== 2) {
|
|
3448
|
-
return void 0;
|
|
3449
|
-
}
|
|
3450
|
-
const [first, second] = entry.entries;
|
|
3451
|
-
const listed = blanks(first) ? values(second) : values(first);
|
|
3452
|
-
return listed !== void 0 && (blanks(first) || blanks(second)) ? { kind: "values", values: listed, includeBlanks: true } : void 0;
|
|
3453
|
-
}
|
|
3454
|
-
function conditionsShape(touching, columnId) {
|
|
3455
|
-
const [only] = touching;
|
|
3456
|
-
const grouped = touching.length === 1 && only !== void 0 && only.kind === "group";
|
|
3457
|
-
const entries = grouped ? only.entries : touching;
|
|
3458
|
-
const combinator = grouped ? only.combinator : "and";
|
|
3459
|
-
if (entries.length === 0 || entries.length > 2) {
|
|
3460
|
-
return void 0;
|
|
3461
|
-
}
|
|
3462
|
-
const conditions = entries.filter((entry) => isConditionOn(entry, columnId));
|
|
3463
|
-
return conditions.length === entries.length ? { kind: "conditions", conditions, combinator } : void 0;
|
|
3464
|
-
}
|
|
3465
|
-
function describeColumnFilter(filter, columnId) {
|
|
3466
|
-
const touching = filter.filter((entry) => touchesColumn(entry, columnId));
|
|
3467
|
-
const [only] = touching;
|
|
3468
|
-
if (only === void 0) {
|
|
3469
|
-
return { kind: "none" };
|
|
3470
|
-
}
|
|
3471
|
-
return (touching.length === 1 ? valuesShape(only, columnId) : void 0) ?? conditionsShape(touching, columnId) ?? { kind: "custom" };
|
|
3472
|
-
}
|
|
3473
|
-
function isColumnFiltered(filter, columnId) {
|
|
3474
|
-
return filter.some((entry) => touchesColumn(entry, columnId));
|
|
3475
|
-
}
|
|
3476
|
-
function isOfferable(value) {
|
|
3477
|
-
return typeof value === "string" || typeof value === "number" || typeof value === "boolean" || value instanceof Date;
|
|
3478
|
-
}
|
|
3479
|
-
function matchesSearch(label, search) {
|
|
3480
|
-
return label.toLowerCase().includes(search.toLowerCase());
|
|
3481
|
-
}
|
|
3482
|
-
function columnValueOptions(rows, dataColumns, filter, columnId, query = {}) {
|
|
3483
|
-
const column = dataColumns.find((entry) => entry.id === columnId)?.column;
|
|
3484
|
-
if (column === void 0) {
|
|
3485
|
-
return { options: [], total: 0, truncated: false, blanks: 0 };
|
|
3486
|
-
}
|
|
3487
|
-
const keep = compileFilter(
|
|
3488
|
-
filter.filter((entry) => !touchesColumn(entry, columnId)),
|
|
3489
|
-
dataColumns
|
|
3490
|
-
);
|
|
3491
|
-
const buckets = /* @__PURE__ */ new Map();
|
|
3492
|
-
let blanks = 0;
|
|
3493
|
-
for (const row of rows) {
|
|
3494
|
-
if (keep !== void 0 && !keep(row)) {
|
|
3495
|
-
continue;
|
|
3496
|
-
}
|
|
3497
|
-
const value = accessDotted(row, column.field);
|
|
3498
|
-
if (isEmptyCell(value)) {
|
|
3499
|
-
blanks++;
|
|
3500
|
-
} else if (isOfferable(value)) {
|
|
3501
|
-
const key = filterValueKey(value, column.type);
|
|
3502
|
-
const bucket = buckets.get(key);
|
|
3503
|
-
if (bucket === void 0) {
|
|
3504
|
-
buckets.set(key, { value, row, count: 1 });
|
|
3505
|
-
} else {
|
|
3506
|
-
bucket.count++;
|
|
3507
|
-
}
|
|
3508
|
-
}
|
|
3509
|
-
}
|
|
3510
|
-
const { search = "", limit, locale } = query;
|
|
3511
|
-
const messages = resolveMessages(query.messages, locale);
|
|
3512
|
-
const options = [...buckets.values()].sort((a, b) => compareValues(a.value, b.value, column.type)).map(({ value, row, count }) => ({
|
|
3513
|
-
value,
|
|
3514
|
-
label: formatCellValue(value, column, locale, row, messages),
|
|
3515
|
-
count
|
|
3516
|
-
})).filter((option) => matchesSearch(option.label, search));
|
|
3517
|
-
const shown = limit === void 0 ? options : options.slice(0, limit);
|
|
3518
|
-
return {
|
|
3519
|
-
options: shown,
|
|
3520
|
-
total: options.length,
|
|
3521
|
-
truncated: shown.length < options.length,
|
|
3522
|
-
blanks,
|
|
3523
|
-
columnType: column.type
|
|
3524
|
-
};
|
|
3525
|
-
}
|
|
3526
|
-
function keyOf2(draft, value) {
|
|
3527
|
-
return filterValueKey(value, draft.columnType);
|
|
3528
|
-
}
|
|
3529
|
-
function everyOption(draft) {
|
|
3530
|
-
return new Map(
|
|
3531
|
-
draft.options.map((option) => [keyOf2(draft, option.value), option.value])
|
|
3532
|
-
);
|
|
3533
|
-
}
|
|
3534
|
-
function baseOf(draft) {
|
|
3535
|
-
const { options, blanks, search, openedShape, columnType } = draft;
|
|
3536
|
-
return { options, blanks, search, openedShape, columnType };
|
|
3537
|
-
}
|
|
3538
|
-
function openedValues(base) {
|
|
3539
|
-
const shape = base.openedShape;
|
|
3540
|
-
if (shape.kind !== "values") {
|
|
3541
|
-
return {
|
|
3542
|
-
kind: "values",
|
|
3543
|
-
...base,
|
|
3544
|
-
checked: everyOption(base),
|
|
3545
|
-
includeBlanks: base.blanks > 0
|
|
3546
|
-
};
|
|
3547
|
-
}
|
|
3548
|
-
return {
|
|
3549
|
-
kind: "values",
|
|
3550
|
-
...base,
|
|
3551
|
-
checked: new Map(
|
|
3552
|
-
shape.values.filter((value) => !isEmptyCell(value)).map((value) => [keyOf2(base, value), value])
|
|
3553
|
-
),
|
|
3554
|
-
includeBlanks: shape.includeBlanks
|
|
3555
|
-
};
|
|
3556
|
-
}
|
|
3557
|
-
function openedConditions(base) {
|
|
3558
|
-
const shape = base.openedShape;
|
|
3559
|
-
return shape.kind === "conditions" ? {
|
|
3560
|
-
kind: "conditions",
|
|
3561
|
-
...base,
|
|
3562
|
-
conditions: shape.conditions,
|
|
3563
|
-
combinator: shape.combinator
|
|
3564
|
-
} : { kind: "conditions", ...base, conditions: [], combinator: "and" };
|
|
3565
|
-
}
|
|
3566
|
-
function initialFilterEditorDraft(shape, values) {
|
|
3567
|
-
const base = {
|
|
3568
|
-
options: values.options,
|
|
3569
|
-
blanks: values.blanks,
|
|
3570
|
-
search: "",
|
|
3571
|
-
openedShape: shape,
|
|
3572
|
-
columnType: values.columnType
|
|
3573
|
-
};
|
|
3574
|
-
return shape.kind === "conditions" ? openedConditions(base) : openedValues(base);
|
|
3575
|
-
}
|
|
3576
|
-
function toValuesDraft(draft) {
|
|
3577
|
-
return draft.kind === "values" ? draft : openedValues(baseOf(draft));
|
|
3578
|
-
}
|
|
3579
|
-
function toConditionsDraft(draft) {
|
|
3580
|
-
return draft.kind === "conditions" ? draft : openedConditions(baseOf(draft));
|
|
3581
|
-
}
|
|
3582
|
-
function visibleFilterOptions(draft) {
|
|
3583
|
-
return draft.search === "" ? draft.options : draft.options.filter(
|
|
3584
|
-
(option) => matchesSearch(option.label, draft.search)
|
|
3585
|
-
);
|
|
3586
|
-
}
|
|
3587
|
-
function selectAllCoversBlanks(draft) {
|
|
3588
|
-
return draft.search === "" && draft.blanks > 0;
|
|
3589
|
-
}
|
|
3590
|
-
function selectAllState(draft) {
|
|
3591
|
-
const states = visibleFilterOptions(draft).map(
|
|
3592
|
-
(option) => draft.checked.has(keyOf2(draft, option.value))
|
|
3593
|
-
);
|
|
3594
|
-
if (selectAllCoversBlanks(draft)) {
|
|
3595
|
-
states.push(draft.includeBlanks);
|
|
3596
|
-
}
|
|
3597
|
-
if (states.length > 0 && states.every(Boolean)) {
|
|
3598
|
-
return "checked";
|
|
3599
|
-
}
|
|
3600
|
-
return states.some(Boolean) ? "mixed" : "unchecked";
|
|
3601
|
-
}
|
|
3602
|
-
function toggleValue(draft, value) {
|
|
3603
|
-
const key = keyOf2(draft, value);
|
|
3604
|
-
const checked = new Map(draft.checked);
|
|
3605
|
-
if (checked.has(key)) {
|
|
3606
|
-
checked.delete(key);
|
|
3607
|
-
} else {
|
|
3608
|
-
checked.set(key, value);
|
|
3609
|
-
}
|
|
3610
|
-
return { ...draft, checked };
|
|
3611
|
-
}
|
|
3612
|
-
function toggleAll(draft) {
|
|
3613
|
-
const check = selectAllState(draft) !== "checked";
|
|
3614
|
-
const checked = new Map(draft.checked);
|
|
3615
|
-
for (const option of visibleFilterOptions(draft)) {
|
|
3616
|
-
const key = keyOf2(draft, option.value);
|
|
3617
|
-
if (check) {
|
|
3618
|
-
checked.set(key, option.value);
|
|
3619
|
-
} else {
|
|
3620
|
-
checked.delete(key);
|
|
3621
|
-
}
|
|
3622
|
-
}
|
|
3623
|
-
return {
|
|
3624
|
-
...draft,
|
|
3625
|
-
checked,
|
|
3626
|
-
includeBlanks: selectAllCoversBlanks(draft) ? check : draft.includeBlanks
|
|
3627
|
-
};
|
|
3628
|
-
}
|
|
3629
|
-
function cleared(draft) {
|
|
3630
|
-
switch (draft.kind) {
|
|
3631
|
-
case "values":
|
|
3632
|
-
return {
|
|
3633
|
-
...draft,
|
|
3634
|
-
search: "",
|
|
3635
|
-
checked: everyOption(draft),
|
|
3636
|
-
includeBlanks: draft.blanks > 0
|
|
3637
|
-
};
|
|
3638
|
-
case "conditions":
|
|
3639
|
-
return { ...draft, search: "", conditions: [] };
|
|
3640
|
-
}
|
|
3641
|
-
}
|
|
3642
|
-
function filterEditorReducer(draft, action) {
|
|
3643
|
-
switch (action.type) {
|
|
3644
|
-
case "search":
|
|
3645
|
-
return { ...draft, search: action.search };
|
|
3646
|
-
case "toggleValue":
|
|
3647
|
-
return toggleValue(toValuesDraft(draft), action.value);
|
|
3648
|
-
case "toggleAll":
|
|
3649
|
-
return toggleAll(toValuesDraft(draft));
|
|
3650
|
-
case "setIncludeBlanks":
|
|
3651
|
-
return { ...toValuesDraft(draft), includeBlanks: action.includeBlanks };
|
|
3652
|
-
case "setConditions": {
|
|
3653
|
-
const conditions = toConditionsDraft(draft);
|
|
3654
|
-
return {
|
|
3655
|
-
...conditions,
|
|
3656
|
-
conditions: action.conditions,
|
|
3657
|
-
combinator: action.combinator ?? conditions.combinator
|
|
3658
|
-
};
|
|
3659
|
-
}
|
|
3660
|
-
case "clear":
|
|
3661
|
-
return cleared(draft);
|
|
3662
|
-
}
|
|
3663
|
-
}
|
|
3664
|
-
function checksEverything(draft) {
|
|
3665
|
-
return draft.options.every(
|
|
3666
|
-
(option) => draft.checked.has(keyOf2(draft, option.value))
|
|
3667
|
-
) && (draft.includeBlanks || draft.blanks === 0);
|
|
3668
|
-
}
|
|
3669
|
-
function valuesEntries(draft, columnId) {
|
|
3670
|
-
if (checksEverything(draft)) {
|
|
3671
|
-
return [];
|
|
3672
|
-
}
|
|
3673
|
-
const picked = {
|
|
3674
|
-
kind: "operator",
|
|
3675
|
-
columnId,
|
|
3676
|
-
operator: "in",
|
|
3677
|
-
value: [...draft.checked.values()]
|
|
3678
|
-
};
|
|
3679
|
-
return draft.includeBlanks ? [
|
|
3680
|
-
{
|
|
3681
|
-
kind: "group",
|
|
3682
|
-
combinator: "or",
|
|
3683
|
-
entries: [
|
|
3684
|
-
picked,
|
|
3685
|
-
{ kind: "operator", columnId, operator: "isEmpty" }
|
|
3686
|
-
]
|
|
3687
|
-
}
|
|
3688
|
-
] : [picked];
|
|
3689
|
-
}
|
|
3690
|
-
function conditionsEntries(draft, columnId) {
|
|
3691
|
-
const conditions = draft.conditions.map((condition) => ({
|
|
3692
|
-
...condition,
|
|
3693
|
-
columnId
|
|
3694
|
-
}));
|
|
3695
|
-
return conditions.length > 1 ? [{ kind: "group", combinator: draft.combinator, entries: conditions }] : conditions;
|
|
3696
|
-
}
|
|
3697
|
-
function draftEntries(draft, columnId) {
|
|
3698
|
-
switch (draft.kind) {
|
|
3699
|
-
case "values":
|
|
3700
|
-
return valuesEntries(draft, columnId);
|
|
3701
|
-
case "conditions":
|
|
3702
|
-
return conditionsEntries(draft, columnId);
|
|
3703
|
-
}
|
|
3704
|
-
}
|
|
3705
|
-
function draftToFilter(draft, columnId, current) {
|
|
3706
|
-
const replacement = draftEntries(draft, columnId);
|
|
3707
|
-
const first = current.findIndex((entry) => touchesColumn(entry, columnId));
|
|
3708
|
-
if (first === -1) {
|
|
3709
|
-
return replacement.length === 0 ? current : [...current, ...replacement];
|
|
3710
|
-
}
|
|
3711
|
-
const kept = current.filter((entry) => !touchesColumn(entry, columnId));
|
|
3712
|
-
return [...kept.slice(0, first), ...replacement, ...kept.slice(first)];
|
|
3713
|
-
}
|
|
3714
|
-
function sameValues(a, b) {
|
|
3715
|
-
return a.includeBlanks === b.includeBlanks && a.checked.size === b.checked.size && [...a.checked.keys()].every((key) => b.checked.has(key));
|
|
3716
|
-
}
|
|
3717
|
-
function sameOperand2(a, b, type) {
|
|
3718
|
-
if (isScalarList(a) || isScalarList(b)) {
|
|
3719
|
-
return isScalarList(a) && isScalarList(b) && a.length === b.length && a.every((scalar, index) => sameOperand2(scalar, b[index], type));
|
|
3720
|
-
}
|
|
3721
|
-
return filterValueKey(a, type) === filterValueKey(b, type);
|
|
3722
|
-
}
|
|
3723
|
-
function sameConditions(a, b) {
|
|
3724
|
-
return a.conditions.length === b.conditions.length && (a.conditions.length < 2 || a.combinator === b.combinator) && a.conditions.every((condition, index) => {
|
|
3725
|
-
const other = b.conditions[index];
|
|
3726
|
-
return other !== void 0 && condition.operator === other.operator && sameOperand2(condition.value, other.value, a.columnType);
|
|
3727
|
-
});
|
|
3728
|
-
}
|
|
3729
|
-
function filterDraftChanged(opened, draft) {
|
|
3730
|
-
switch (draft.kind) {
|
|
3731
|
-
case "values":
|
|
3732
|
-
return !sameValues(toValuesDraft(opened), draft);
|
|
3733
|
-
case "conditions":
|
|
3734
|
-
return opened.kind !== "conditions" || !sameConditions(opened, draft);
|
|
3735
|
-
}
|
|
3736
|
-
}
|
|
3737
|
-
|
|
3738
|
-
// src/commands/builtInCommands.ts
|
|
3739
|
-
function isOn(context, areas) {
|
|
3740
|
-
return areas.includes(context.target.area);
|
|
3741
|
-
}
|
|
3742
|
-
function columnOn(context, areas) {
|
|
3743
|
-
return isOn(context, areas) ? context.column : null;
|
|
3744
|
-
}
|
|
3745
|
-
function isGroupedBy(context, columnId) {
|
|
3746
|
-
return context.state.groupBy.some((entry) => entry.columnId === columnId);
|
|
3747
|
-
}
|
|
3748
|
-
function sortableColumn(context) {
|
|
3749
|
-
const column = columnOn(context, ["header"]);
|
|
3750
|
-
return column !== null && (column.column.sortable ?? context.options.sortableColumns ?? false) ? column : null;
|
|
3751
|
-
}
|
|
3752
|
-
function groupableColumn(context) {
|
|
3753
|
-
const column = columnOn(context, ["header"]);
|
|
3754
|
-
return column !== null && (column.column.groupable ?? context.options.groupableColumns ?? false) && !isGroupedBy(context, column.id) ? column : null;
|
|
3755
|
-
}
|
|
3756
|
-
function groupedColumn(context) {
|
|
3757
|
-
const column = columnOn(context, ["header", "group"]);
|
|
3758
|
-
return column !== null && isGroupedBy(context, column.id) ? column : null;
|
|
3759
|
-
}
|
|
3760
|
-
function filterableColumn(context) {
|
|
3761
|
-
const column = columnOn(context, ["header"]);
|
|
3762
|
-
return column !== null && resolveColumnFilterMenu(context.options, column.column) !== null ? column : null;
|
|
3763
|
-
}
|
|
3764
|
-
function hideableColumn(context) {
|
|
3765
|
-
const column = columnOn(context, ["header"]);
|
|
3766
|
-
return column !== null && column.column.hideable !== false ? column : null;
|
|
3767
|
-
}
|
|
3768
|
-
function resizableColumn(context) {
|
|
3769
|
-
const column = columnOn(context, ["header"]);
|
|
3770
|
-
if (column === null) {
|
|
3771
|
-
return null;
|
|
3772
|
-
}
|
|
3773
|
-
return context.view.columns.find(
|
|
3774
|
-
(entry) => entry.id === column.id && entry.resizable
|
|
3775
|
-
) ?? null;
|
|
3776
|
-
}
|
|
3777
|
-
function resizableColumnIds(context) {
|
|
3778
|
-
return context.view.columns.filter((entry) => entry.resizable).map((entry) => entry.id);
|
|
3779
|
-
}
|
|
3780
|
-
function isAnythingSelectable(selectable) {
|
|
3781
|
-
return [selectable?.rows, selectable?.columns, selectable?.cells].some(
|
|
3782
|
-
(mode) => mode !== void 0 && mode !== false
|
|
3783
|
-
);
|
|
3784
|
-
}
|
|
3785
|
-
function columnName(context) {
|
|
3786
|
-
return context.column === null ? "" : resolveColumnHeaderText(context.column.column);
|
|
3787
|
-
}
|
|
3788
|
-
function columnCommand({
|
|
3789
|
-
id,
|
|
3790
|
-
label,
|
|
3791
|
-
icon,
|
|
3792
|
-
find,
|
|
3793
|
-
isEnabled,
|
|
3794
|
-
isChecked,
|
|
3795
|
-
execute
|
|
3796
|
-
}) {
|
|
3797
|
-
function test(predicate) {
|
|
3798
|
-
return (context) => {
|
|
3799
|
-
const column = find(context);
|
|
3800
|
-
return column !== null && predicate(column, context);
|
|
3801
|
-
};
|
|
3802
|
-
}
|
|
3803
|
-
return {
|
|
3804
|
-
id,
|
|
3805
|
-
label,
|
|
3806
|
-
icon,
|
|
3807
|
-
isVisible: (context) => find(context) !== null,
|
|
3808
|
-
isEnabled: isEnabled === void 0 ? void 0 : test(isEnabled),
|
|
3809
|
-
isChecked: isChecked === void 0 ? void 0 : test(isChecked),
|
|
3810
|
-
execute: (context) => {
|
|
3811
|
-
const column = find(context);
|
|
3812
|
-
if (column !== null) {
|
|
3813
|
-
execute(column, context);
|
|
3814
|
-
}
|
|
3815
|
-
}
|
|
3816
|
-
};
|
|
3817
|
-
}
|
|
3818
|
-
var EXPORT_AREAS = ["grid", "toolbar", "body", "cell"];
|
|
3819
|
-
function exportCommand({
|
|
3820
|
-
id,
|
|
3821
|
-
format,
|
|
3822
|
-
label,
|
|
3823
|
-
selection = false
|
|
3824
|
-
}) {
|
|
3825
|
-
return {
|
|
3826
|
-
id,
|
|
3827
|
-
label: ({ messages }) => label(messages),
|
|
3828
|
-
isVisible: (context) => isOn(context, EXPORT_AREAS) && resolveExportWriters(context.options.exportWriters).has(format) && (!selection || context.state.rowSelection.length > 0),
|
|
3829
|
-
isEnabled: (context) => (selection ? context.selectedRows() : context.view.rows).length > 0,
|
|
3830
|
-
execute: (context) => {
|
|
3831
|
-
if (context.host.canSave?.() === false) {
|
|
3832
|
-
return false;
|
|
3833
|
-
}
|
|
3834
|
-
const { export: defaults = {}, exportWriters } = context.options;
|
|
3835
|
-
const file = exportFile(
|
|
3836
|
-
context,
|
|
3837
|
-
format,
|
|
3838
|
-
selection ? { ...defaults, scope: "selection" } : defaults,
|
|
3839
|
-
resolveExportWriters(exportWriters)
|
|
3840
|
-
);
|
|
3841
|
-
if (file === null) {
|
|
3842
|
-
return;
|
|
3843
|
-
}
|
|
3844
|
-
return context.host.saveFile(file) !== false;
|
|
3845
|
-
}
|
|
3846
|
-
};
|
|
3847
|
-
}
|
|
3848
|
-
function cellRequest(context, kind) {
|
|
3849
|
-
const { target } = context;
|
|
3850
|
-
if (target.area !== "cell") {
|
|
3851
|
-
return null;
|
|
3852
|
-
}
|
|
3853
|
-
return kind === "cell" ? { kind, rowId: target.rowId, columnId: target.columnId } : { kind, rowId: target.rowId };
|
|
3854
|
-
}
|
|
3855
|
-
function copyCommand({
|
|
3856
|
-
id,
|
|
3857
|
-
label,
|
|
3858
|
-
request,
|
|
3859
|
-
isEnabled
|
|
3860
|
-
}) {
|
|
3861
|
-
function contentFor(context) {
|
|
3862
|
-
const asked = request(context);
|
|
3863
|
-
return asked === null ? null : copyContent(context, asked);
|
|
3864
|
-
}
|
|
3865
|
-
return {
|
|
3866
|
-
id,
|
|
3867
|
-
label: ({ messages }) => label(messages),
|
|
3868
|
-
icon: "copy",
|
|
3869
|
-
isVisible: (context) => request(context) !== null,
|
|
3870
|
-
isEnabled: isEnabled ?? ((context) => contentFor(context) !== null),
|
|
3871
|
-
execute: (context) => {
|
|
3872
|
-
const content = contentFor(context);
|
|
3873
|
-
if (content !== null) {
|
|
3874
|
-
context.host.writeClipboard(content);
|
|
3875
|
-
}
|
|
3876
|
-
}
|
|
3877
|
-
};
|
|
3878
|
-
}
|
|
3879
|
-
function sortCommand(direction) {
|
|
3880
|
-
return columnCommand({
|
|
3881
|
-
id: direction === "asc" ? "sort.ascending" : "sort.descending",
|
|
3882
|
-
label: ({ messages }) => direction === "asc" ? messages.sortAscending : messages.sortDescending,
|
|
3883
|
-
icon: direction === "asc" ? "sortAscending" : "sortDescending",
|
|
3884
|
-
find: sortableColumn,
|
|
3885
|
-
isChecked: (column, { state }) => sortDirectionFor(state.columnSort, column.id) === direction,
|
|
3886
|
-
execute: (column, { actions }) => {
|
|
3887
|
-
actions.setColumnSort([{ columnId: column.id, direction }]);
|
|
3888
|
-
}
|
|
3889
|
-
});
|
|
3890
|
-
}
|
|
3891
|
-
function builtInCommands() {
|
|
3892
|
-
return [
|
|
3893
|
-
sortCommand("asc"),
|
|
3894
|
-
sortCommand("desc"),
|
|
3895
|
-
// Cleared rather than set, so the change reports this column — the one
|
|
3896
|
-
// the announcement names — rather than a key that moved up past it.
|
|
3897
|
-
columnCommand({
|
|
3898
|
-
id: "sort.clear",
|
|
3899
|
-
label: ({ messages }) => messages.clearSort,
|
|
3900
|
-
find: sortableColumn,
|
|
3901
|
-
isEnabled: (column, { state }) => sortDirectionFor(state.columnSort, column.id) !== null,
|
|
3902
|
-
execute: (column, { actions }) => {
|
|
3903
|
-
actions.clearColumnSort(column.id);
|
|
3904
|
-
}
|
|
3905
|
-
}),
|
|
3906
|
-
{
|
|
3907
|
-
id: "sort.clearAll",
|
|
3908
|
-
label: ({ messages }) => messages.clearAllSorting,
|
|
3909
|
-
isVisible: (context) => isOn(context, ["grid", "toolbar", "header"]),
|
|
3910
|
-
isEnabled: ({ state }) => state.columnSort.length > 0,
|
|
3911
|
-
execute: ({ actions }) => {
|
|
3912
|
-
actions.setColumnSort([]);
|
|
3913
|
-
}
|
|
3914
|
-
},
|
|
3915
|
-
columnCommand({
|
|
3916
|
-
id: "group.add",
|
|
3917
|
-
label: (context) => context.messages.groupByColumn(columnName(context)),
|
|
3918
|
-
icon: "group",
|
|
3919
|
-
find: groupableColumn,
|
|
3920
|
-
execute: (column, { actions }) => {
|
|
3921
|
-
actions.toggleGroupBy(column.id);
|
|
3922
|
-
}
|
|
3923
|
-
}),
|
|
3924
|
-
// Toggled rather than set, so the change reports this column — the one
|
|
3925
|
-
// the announcement names — rather than the level that moved up.
|
|
3926
|
-
columnCommand({
|
|
3927
|
-
id: "group.remove",
|
|
3928
|
-
label: (context) => context.messages.removeGroupBy(columnName(context)),
|
|
3929
|
-
icon: "group",
|
|
3930
|
-
find: groupedColumn,
|
|
3931
|
-
execute: (column, { actions }) => {
|
|
3932
|
-
actions.toggleGroupBy(column.id);
|
|
3933
|
-
}
|
|
3934
|
-
}),
|
|
3935
|
-
{
|
|
3936
|
-
id: "group.clearAll",
|
|
3937
|
-
label: ({ messages }) => messages.ungroupAll,
|
|
3938
|
-
isVisible: (context) => isOn(context, ["grid", "toolbar"]) && context.state.groupBy.length > 0,
|
|
3939
|
-
execute: ({ actions }) => {
|
|
3940
|
-
actions.setGroupBy([]);
|
|
3941
|
-
}
|
|
3942
|
-
},
|
|
3943
|
-
{
|
|
3944
|
-
id: "group.expandAll",
|
|
3945
|
-
label: ({ messages }) => messages.expandAllGroups,
|
|
3946
|
-
isVisible: (context) => isOn(context, ["grid", "toolbar", "group", "cell"]) && context.state.groupBy.length > 0,
|
|
3947
|
-
execute: ({ actions }) => {
|
|
3948
|
-
actions.expandAllGroups();
|
|
3949
|
-
}
|
|
3950
|
-
},
|
|
3951
|
-
{
|
|
3952
|
-
id: "group.collapseAll",
|
|
3953
|
-
label: ({ messages }) => messages.collapseAllGroups,
|
|
3954
|
-
isVisible: (context) => isOn(context, ["grid", "toolbar", "group", "cell"]) && context.state.groupBy.length > 0,
|
|
3955
|
-
execute: ({ actions }) => {
|
|
3956
|
-
actions.collapseAllGroups();
|
|
3957
|
-
}
|
|
3958
|
-
},
|
|
3959
|
-
columnCommand({
|
|
3960
|
-
id: "column.hide",
|
|
3961
|
-
label: ({ messages }) => messages.hideColumn,
|
|
3962
|
-
icon: "hide",
|
|
3963
|
-
find: hideableColumn,
|
|
3964
|
-
// The last column shown stays: a grid with none has no header left to
|
|
3965
|
-
// bring one back from.
|
|
3966
|
-
isEnabled: (column, { view }) => view.columns.some((entry) => entry.id !== column.id),
|
|
3967
|
-
execute: (column, { actions }) => {
|
|
3968
|
-
actions.hideColumns([column.id]);
|
|
3969
|
-
}
|
|
3970
|
-
}),
|
|
3971
|
-
columnCommand({
|
|
3972
|
-
id: "column.autoFit",
|
|
3973
|
-
label: ({ messages }) => messages.autoFitColumn,
|
|
3974
|
-
icon: "autoFit",
|
|
3975
|
-
find: resizableColumn,
|
|
3976
|
-
execute: (column, { host }) => {
|
|
3977
|
-
host.autoFitColumns([column.id]);
|
|
3978
|
-
}
|
|
3979
|
-
}),
|
|
3980
|
-
{
|
|
3981
|
-
id: "column.autoFitAll",
|
|
3982
|
-
label: ({ messages }) => messages.autoFitAllColumns,
|
|
3983
|
-
icon: "autoFit",
|
|
3984
|
-
isVisible: (context) => isOn(context, ["grid", "toolbar", "header"]) && resizableColumnIds(context).length > 0,
|
|
3985
|
-
execute: (context) => {
|
|
3986
|
-
context.host.autoFitColumns(resizableColumnIds(context));
|
|
3987
|
-
}
|
|
3988
|
-
},
|
|
3989
|
-
// The target goes along, so the renderer opens the chooser where it was
|
|
3990
|
-
// asked for: beside the toolbar button, below the header, or at the
|
|
3991
|
-
// grid's corner for a call from nowhere in particular.
|
|
3992
|
-
{
|
|
3993
|
-
id: "column.choose",
|
|
3994
|
-
label: ({ messages }) => messages.chooseColumns,
|
|
3995
|
-
isVisible: (context) => isOn(context, ["grid", "toolbar", "header"]),
|
|
3996
|
-
execute: ({ host, target }) => {
|
|
3997
|
-
host.openPanel("columnChooser", target);
|
|
3998
|
-
}
|
|
3999
|
-
},
|
|
4000
|
-
// Opened below the header it was asked for, as the chooser is.
|
|
4001
|
-
columnCommand({
|
|
4002
|
-
id: "filter.open",
|
|
4003
|
-
label: ({ messages }) => messages.openFilter,
|
|
4004
|
-
find: filterableColumn,
|
|
4005
|
-
execute: (_column, { host, target }) => {
|
|
4006
|
-
host.openPanel("filter", target);
|
|
4007
|
-
}
|
|
4008
|
-
}),
|
|
4009
|
-
// Every entry about the column goes, whichever editor wrote it — or
|
|
4010
|
-
// none did, as with a predicate set in code — as applying an editor
|
|
4011
|
-
// replaces them all.
|
|
4012
|
-
columnCommand({
|
|
4013
|
-
id: "filter.clear",
|
|
4014
|
-
label: ({ messages }) => messages.clearColumnFilter,
|
|
4015
|
-
find: filterableColumn,
|
|
4016
|
-
isEnabled: (column, { state }) => isColumnFiltered(state.filter, column.id),
|
|
4017
|
-
execute: (column, { actions, state }) => {
|
|
4018
|
-
actions.setFilter(
|
|
4019
|
-
state.filter.filter((entry) => !touchesColumn(entry, column.id))
|
|
4020
|
-
);
|
|
4021
|
-
}
|
|
4022
|
-
}),
|
|
4023
|
-
{
|
|
4024
|
-
id: "selection.selectAllRows",
|
|
4025
|
-
label: ({ messages }) => messages.selectAllRows,
|
|
4026
|
-
isVisible: (context) => isOn(context, ["grid", "cell"]) && context.options.selectable?.rows === "multiple",
|
|
4027
|
-
isEnabled: ({ view }) => view.displayDataRows.length > 0,
|
|
4028
|
-
execute: ({ actions }) => {
|
|
4029
|
-
actions.selectAllRows();
|
|
4030
|
-
}
|
|
4031
|
-
},
|
|
4032
|
-
{
|
|
4033
|
-
id: "selection.clear",
|
|
4034
|
-
label: ({ messages }) => messages.clearSelection,
|
|
4035
|
-
isVisible: (context) => isOn(context, ["grid", "cell", "header"]) && isAnythingSelectable(context.options.selectable),
|
|
4036
|
-
isEnabled: ({ state }) => state.rowSelection.length > 0 || state.columnSelection.length > 0 || state.cellSelection !== null,
|
|
4037
|
-
execute: ({ actions }) => {
|
|
4038
|
-
actions.clearSelection();
|
|
4039
|
-
}
|
|
1291
|
+
collapseAllGroups() {
|
|
1292
|
+
commitGroupExpansion(collapseAllGroups(state.groupExpansion), null);
|
|
4040
1293
|
},
|
|
4041
|
-
|
|
4042
|
-
|
|
4043
|
-
|
|
4044
|
-
|
|
4045
|
-
isEnabled: ({ state }) => state.filter.length > 0,
|
|
4046
|
-
execute: ({ actions }) => {
|
|
4047
|
-
actions.setFilter([]);
|
|
4048
|
-
}
|
|
1294
|
+
setPagination: commitPagination,
|
|
1295
|
+
goToPage,
|
|
1296
|
+
nextPage() {
|
|
1297
|
+
goToPage(shownPageIndex() + 1);
|
|
4049
1298
|
},
|
|
4050
|
-
|
|
4051
|
-
|
|
4052
|
-
|
|
4053
|
-
|
|
4054
|
-
|
|
4055
|
-
|
|
4056
|
-
|
|
4057
|
-
|
|
4058
|
-
|
|
4059
|
-
}),
|
|
4060
|
-
exportCommand({
|
|
4061
|
-
id: "export.xlsx",
|
|
4062
|
-
format: "xlsx",
|
|
4063
|
-
label: ({ exportXlsx }) => exportXlsx
|
|
4064
|
-
}),
|
|
4065
|
-
exportCommand({
|
|
4066
|
-
id: "export.pdf",
|
|
4067
|
-
format: "pdf",
|
|
4068
|
-
label: ({ exportPdf }) => exportPdf
|
|
4069
|
-
}),
|
|
4070
|
-
exportCommand({
|
|
4071
|
-
id: "exportSelection.csv",
|
|
4072
|
-
format: "csv",
|
|
4073
|
-
label: ({ exportSelectionCsv }) => exportSelectionCsv,
|
|
4074
|
-
selection: true
|
|
4075
|
-
}),
|
|
4076
|
-
exportCommand({
|
|
4077
|
-
id: "exportSelection.json",
|
|
4078
|
-
format: "json",
|
|
4079
|
-
label: ({ exportSelectionJson }) => exportSelectionJson,
|
|
4080
|
-
selection: true
|
|
4081
|
-
}),
|
|
4082
|
-
exportCommand({
|
|
4083
|
-
id: "exportSelection.xlsx",
|
|
4084
|
-
format: "xlsx",
|
|
4085
|
-
label: ({ exportSelectionXlsx }) => exportSelectionXlsx,
|
|
4086
|
-
selection: true
|
|
4087
|
-
}),
|
|
4088
|
-
copyCommand({
|
|
4089
|
-
id: "copy.cell",
|
|
4090
|
-
label: ({ copyCell }) => copyCell,
|
|
4091
|
-
request: (context) => cellRequest(context, "cell")
|
|
4092
|
-
}),
|
|
4093
|
-
copyCommand({
|
|
4094
|
-
id: "copy.row",
|
|
4095
|
-
label: ({ copyRow }) => copyRow,
|
|
4096
|
-
request: (context) => cellRequest(context, "row")
|
|
4097
|
-
}),
|
|
4098
|
-
// Shown wherever the grid as a whole is asked for, as the exports are,
|
|
4099
|
-
// once anything can be selected; enabled once something is.
|
|
4100
|
-
copyCommand({
|
|
4101
|
-
id: "copy.selection",
|
|
4102
|
-
label: ({ copySelection }) => copySelection,
|
|
4103
|
-
request: (context) => isOn(context, EXPORT_AREAS) && isAnythingSelectable(context.options.selectable) ? { kind: "selection" } : null,
|
|
4104
|
-
isEnabled: canCopySelection
|
|
4105
|
-
}),
|
|
4106
|
-
// Shown where the exports are, under the grid's `print` defaults. A grid
|
|
4107
|
-
// with no rows still prints its header; one with no columns, nothing.
|
|
4108
|
-
{
|
|
4109
|
-
id: "print",
|
|
4110
|
-
label: ({ messages }) => messages.print,
|
|
4111
|
-
icon: "print",
|
|
4112
|
-
isVisible: (context) => isOn(context, EXPORT_AREAS),
|
|
4113
|
-
isEnabled: ({ view }) => view.columns.length > 0,
|
|
4114
|
-
execute: (context) => {
|
|
4115
|
-
const { print: options = {} } = context.options;
|
|
4116
|
-
context.host.print(exportPrintDocument(context, options), options);
|
|
4117
|
-
}
|
|
4118
|
-
}
|
|
4119
|
-
];
|
|
4120
|
-
}
|
|
4121
|
-
|
|
4122
|
-
// src/commands/registry.ts
|
|
4123
|
-
function isCommandVisible(command, context) {
|
|
4124
|
-
return command.isVisible?.(context) ?? true;
|
|
4125
|
-
}
|
|
4126
|
-
function isCommandEnabled(command, context) {
|
|
4127
|
-
return command.isEnabled?.(context) ?? true;
|
|
4128
|
-
}
|
|
4129
|
-
function resolveCommands(commands) {
|
|
4130
|
-
const registry = new Map(
|
|
4131
|
-
builtInCommands().map((command) => [command.id, command])
|
|
4132
|
-
);
|
|
4133
|
-
for (const command of commands ?? []) {
|
|
4134
|
-
if (command.id === "separator") {
|
|
4135
|
-
reportError(
|
|
4136
|
-
"a command cannot have the id `separator`, which a menu reads as a separator, so it is left out."
|
|
4137
|
-
);
|
|
4138
|
-
continue;
|
|
1299
|
+
previousPage() {
|
|
1300
|
+
goToPage(shownPageIndex() - 1);
|
|
1301
|
+
},
|
|
1302
|
+
setPageSize(pageSize) {
|
|
1303
|
+
const first = { pageIndex: 0, pageSize };
|
|
1304
|
+
commitPagination({
|
|
1305
|
+
...first,
|
|
1306
|
+
pageIndex: pageOf(first).pageIndex
|
|
1307
|
+
});
|
|
4139
1308
|
}
|
|
4140
|
-
registry.set(command.id, command);
|
|
4141
|
-
}
|
|
4142
|
-
return registry;
|
|
4143
|
-
}
|
|
4144
|
-
function runCommand(command, context) {
|
|
4145
|
-
if (!isCommandVisible(command, context) || !isCommandEnabled(command, context)) {
|
|
4146
|
-
return false;
|
|
4147
|
-
}
|
|
4148
|
-
return command.execute(context) !== false;
|
|
4149
|
-
}
|
|
4150
|
-
|
|
4151
|
-
// src/menu/resolveMenu.ts
|
|
4152
|
-
var reportedUnknownIds = /* @__PURE__ */ new WeakMap();
|
|
4153
|
-
function reportUnknownId(commands, id) {
|
|
4154
|
-
let reported = reportedUnknownIds.get(commands);
|
|
4155
|
-
if (reported === void 0) {
|
|
4156
|
-
reported = /* @__PURE__ */ new Set();
|
|
4157
|
-
reportedUnknownIds.set(commands, reported);
|
|
4158
|
-
}
|
|
4159
|
-
if (reported.has(id)) {
|
|
4160
|
-
return;
|
|
4161
|
-
}
|
|
4162
|
-
reported.add(id);
|
|
4163
|
-
reportError(
|
|
4164
|
-
`the menu or toolbar entry \`${id}\` names no command, so it is left out.`
|
|
4165
|
-
);
|
|
4166
|
-
}
|
|
4167
|
-
function evaluate(value, context) {
|
|
4168
|
-
return typeof value === "function" ? value(context) : value;
|
|
4169
|
-
}
|
|
4170
|
-
function commandItem(command, context) {
|
|
4171
|
-
if (!isCommandVisible(command, context)) {
|
|
4172
|
-
return null;
|
|
4173
|
-
}
|
|
4174
|
-
return {
|
|
4175
|
-
type: "item",
|
|
4176
|
-
id: command.id,
|
|
4177
|
-
label: evaluate(command.label, context),
|
|
4178
|
-
icon: command.icon,
|
|
4179
|
-
shortcut: command.shortcut,
|
|
4180
|
-
disabled: !isCommandEnabled(command, context),
|
|
4181
|
-
checked: command.isChecked?.(context),
|
|
4182
|
-
run: () => runCommand(command, context)
|
|
4183
1309
|
};
|
|
4184
|
-
|
|
4185
|
-
|
|
4186
|
-
|
|
4187
|
-
return null;
|
|
4188
|
-
}
|
|
4189
|
-
const disabled = evaluate(entry.disabled ?? false, context);
|
|
4190
|
-
return {
|
|
4191
|
-
type: "item",
|
|
4192
|
-
id: entry.id,
|
|
4193
|
-
label: evaluate(entry.label, context),
|
|
4194
|
-
icon: entry.icon,
|
|
4195
|
-
shortcut: entry.shortcut,
|
|
4196
|
-
disabled,
|
|
4197
|
-
checked: entry.checked === void 0 ? void 0 : evaluate(entry.checked, context),
|
|
4198
|
-
run: () => {
|
|
4199
|
-
if (disabled) {
|
|
4200
|
-
return false;
|
|
4201
|
-
}
|
|
4202
|
-
entry.onSelect(context);
|
|
4203
|
-
return true;
|
|
1310
|
+
function restoreSlices(saved) {
|
|
1311
|
+
if (saved.columnSizing !== void 0) {
|
|
1312
|
+
controller.setColumnSizing(saved.columnSizing);
|
|
4204
1313
|
}
|
|
4205
|
-
|
|
4206
|
-
|
|
4207
|
-
function collapseSeparators(entries, isEdge = () => false) {
|
|
4208
|
-
const collapsed = [];
|
|
4209
|
-
for (const entry of entries) {
|
|
4210
|
-
const previous = collapsed.at(-1);
|
|
4211
|
-
if (entry.type !== "separator") {
|
|
4212
|
-
if (isEdge(entry) && previous?.type === "separator") {
|
|
4213
|
-
collapsed.pop();
|
|
4214
|
-
}
|
|
4215
|
-
collapsed.push(entry);
|
|
4216
|
-
} else if (previous !== void 0 && previous.type !== "separator" && !isEdge(previous)) {
|
|
4217
|
-
collapsed.push(entry);
|
|
1314
|
+
if (saved.columnOrder !== void 0) {
|
|
1315
|
+
controller.setColumnOrder(saved.columnOrder);
|
|
4218
1316
|
}
|
|
4219
|
-
|
|
4220
|
-
|
|
4221
|
-
|
|
4222
|
-
|
|
4223
|
-
|
|
4224
|
-
}
|
|
4225
|
-
|
|
4226
|
-
|
|
4227
|
-
|
|
4228
|
-
|
|
4229
|
-
|
|
4230
|
-
|
|
4231
|
-
|
|
4232
|
-
|
|
4233
|
-
|
|
4234
|
-
|
|
1317
|
+
if (saved.columnVisibility !== void 0) {
|
|
1318
|
+
controller.setColumnVisibility(saved.columnVisibility);
|
|
1319
|
+
}
|
|
1320
|
+
if (saved.columnPinning !== void 0) {
|
|
1321
|
+
controller.setColumnPinning(saved.columnPinning);
|
|
1322
|
+
}
|
|
1323
|
+
if (saved.columnSort !== void 0) {
|
|
1324
|
+
controller.setColumnSort(saved.columnSort);
|
|
1325
|
+
}
|
|
1326
|
+
if (saved.filter !== void 0) {
|
|
1327
|
+
controller.setFilter(reviveFilter(saved.filter, getView().dataColumns));
|
|
1328
|
+
}
|
|
1329
|
+
if (saved.groupBy !== void 0) {
|
|
1330
|
+
controller.setGroupBy(saved.groupBy);
|
|
1331
|
+
}
|
|
1332
|
+
if (saved.groupExpansion !== void 0) {
|
|
1333
|
+
controller.setGroupExpansion(reviveGroupExpansion(saved.groupExpansion));
|
|
1334
|
+
}
|
|
1335
|
+
if (saved.pagination !== void 0) {
|
|
1336
|
+
controller.setPagination(saved.pagination);
|
|
1337
|
+
}
|
|
1338
|
+
if (saved.rowSelection !== void 0) {
|
|
1339
|
+
controller.setRowSelection(saved.rowSelection);
|
|
1340
|
+
}
|
|
1341
|
+
if (saved.columnSelection !== void 0) {
|
|
1342
|
+
controller.setColumnSelection(saved.columnSelection);
|
|
1343
|
+
}
|
|
1344
|
+
if (saved.cellSelection !== void 0) {
|
|
1345
|
+
controller.setCellSelection(saved.cellSelection);
|
|
4235
1346
|
}
|
|
4236
|
-
return commandItem(command, context);
|
|
4237
1347
|
}
|
|
4238
|
-
return
|
|
4239
|
-
}
|
|
4240
|
-
function resolveSubmenu(entry, options) {
|
|
4241
|
-
const items = resolveMenu(entry.items, options);
|
|
4242
|
-
return items.length === 0 ? null : {
|
|
4243
|
-
type: "submenu",
|
|
4244
|
-
id: entry.id,
|
|
4245
|
-
label: evaluate(entry.label, options.context),
|
|
4246
|
-
icon: entry.icon,
|
|
4247
|
-
items
|
|
4248
|
-
};
|
|
4249
|
-
}
|
|
4250
|
-
function resolveMenu(entries, options) {
|
|
4251
|
-
return collapseSeparators(
|
|
4252
|
-
entries.map((entry, index) => resolveMenuEntry(entry, index, options)).filter((entry) => entry !== null)
|
|
4253
|
-
);
|
|
1348
|
+
return controller;
|
|
4254
1349
|
}
|
|
4255
1350
|
|
|
4256
|
-
// src/
|
|
4257
|
-
|
|
4258
|
-
|
|
4259
|
-
"sort.ascending",
|
|
4260
|
-
"sort.descending",
|
|
4261
|
-
"sort.clear",
|
|
4262
|
-
"separator",
|
|
4263
|
-
"filter.open",
|
|
4264
|
-
"filter.clear",
|
|
4265
|
-
"separator",
|
|
4266
|
-
"group.add",
|
|
4267
|
-
"group.remove",
|
|
4268
|
-
"separator",
|
|
4269
|
-
"column.autoFit",
|
|
4270
|
-
"column.autoFitAll",
|
|
4271
|
-
"separator",
|
|
4272
|
-
"column.hide",
|
|
4273
|
-
"column.choose"
|
|
4274
|
-
],
|
|
4275
|
-
cell: [
|
|
4276
|
-
"copy.cell",
|
|
4277
|
-
"copy.row",
|
|
4278
|
-
"copy.selection",
|
|
4279
|
-
"separator",
|
|
4280
|
-
"selection.selectAllRows",
|
|
4281
|
-
"selection.clear",
|
|
4282
|
-
"separator",
|
|
4283
|
-
"group.expandAll",
|
|
4284
|
-
"group.collapseAll"
|
|
4285
|
-
],
|
|
4286
|
-
group: ["group.expandAll", "group.collapseAll", "separator", "group.remove"],
|
|
4287
|
-
body: []
|
|
4288
|
-
};
|
|
4289
|
-
function hasContextMenu(contextMenu, area) {
|
|
4290
|
-
if (contextMenu === void 0 || contextMenu === false) {
|
|
4291
|
-
return false;
|
|
4292
|
-
}
|
|
4293
|
-
const entries = (contextMenu === true ? void 0 : contextMenu[area]) ?? defaultContextMenu[area];
|
|
4294
|
-
return typeof entries === "function" || entries.length > 0;
|
|
4295
|
-
}
|
|
4296
|
-
function entriesFor(given, request) {
|
|
4297
|
-
if (given === void 0) {
|
|
4298
|
-
return request.defaults;
|
|
4299
|
-
}
|
|
4300
|
-
return typeof given === "function" ? given(request) ?? [] : given;
|
|
4301
|
-
}
|
|
4302
|
-
function contextMenuEntries(contextMenu, context) {
|
|
4303
|
-
if (contextMenu === void 0 || contextMenu === false) {
|
|
1351
|
+
// src/commands/context.ts
|
|
1352
|
+
function selectedRowsOf(rows, selection) {
|
|
1353
|
+
if (selection.length === 0) {
|
|
4304
1354
|
return [];
|
|
4305
1355
|
}
|
|
4306
|
-
const
|
|
4307
|
-
|
|
4308
|
-
switch (target.area) {
|
|
4309
|
-
case "header":
|
|
4310
|
-
return entriesFor(options.header, {
|
|
4311
|
-
target,
|
|
4312
|
-
defaults: defaultContextMenu.header,
|
|
4313
|
-
context
|
|
4314
|
-
});
|
|
4315
|
-
case "cell":
|
|
4316
|
-
return entriesFor(options.cell, {
|
|
4317
|
-
target,
|
|
4318
|
-
defaults: defaultContextMenu.cell,
|
|
4319
|
-
context
|
|
4320
|
-
});
|
|
4321
|
-
case "group":
|
|
4322
|
-
return entriesFor(options.group, {
|
|
4323
|
-
target,
|
|
4324
|
-
defaults: defaultContextMenu.group,
|
|
4325
|
-
context
|
|
4326
|
-
});
|
|
4327
|
-
case "body":
|
|
4328
|
-
return entriesFor(options.body, {
|
|
4329
|
-
target,
|
|
4330
|
-
defaults: defaultContextMenu.body,
|
|
4331
|
-
context
|
|
4332
|
-
});
|
|
4333
|
-
default:
|
|
4334
|
-
return [];
|
|
4335
|
-
}
|
|
4336
|
-
}
|
|
4337
|
-
|
|
4338
|
-
// src/menu/navigation.ts
|
|
4339
|
-
function startIndex(count, from, move) {
|
|
4340
|
-
const focused = from >= 0 && from < count;
|
|
4341
|
-
switch (move) {
|
|
4342
|
-
case "first":
|
|
4343
|
-
return 0;
|
|
4344
|
-
case "last":
|
|
4345
|
-
return count - 1;
|
|
4346
|
-
case "next":
|
|
4347
|
-
return focused ? from + 1 : 0;
|
|
4348
|
-
case "previous":
|
|
4349
|
-
return focused ? from - 1 : count - 1;
|
|
4350
|
-
}
|
|
4351
|
-
}
|
|
4352
|
-
function nextMenuIndex(entries, from, move) {
|
|
4353
|
-
const count = entries.length;
|
|
4354
|
-
const step = move === "next" || move === "first" ? 1 : -1;
|
|
4355
|
-
const start = startIndex(count, from, move);
|
|
4356
|
-
for (let offset = 0; offset < count; offset++) {
|
|
4357
|
-
const index = ((start + step * offset) % count + count) % count;
|
|
4358
|
-
if (entries[index]?.type !== "separator") {
|
|
4359
|
-
return index;
|
|
4360
|
-
}
|
|
4361
|
-
}
|
|
4362
|
-
return -1;
|
|
1356
|
+
const selected = new Set(selection);
|
|
1357
|
+
return rows.filter((entry) => selected.has(entry.rowId));
|
|
4363
1358
|
}
|
|
4364
|
-
function
|
|
4365
|
-
|
|
4366
|
-
|
|
4367
|
-
|
|
4368
|
-
|
|
4369
|
-
|
|
4370
|
-
const
|
|
4371
|
-
const
|
|
4372
|
-
|
|
4373
|
-
|
|
4374
|
-
|
|
4375
|
-
|
|
4376
|
-
|
|
4377
|
-
|
|
4378
|
-
|
|
4379
|
-
|
|
4380
|
-
|
|
1359
|
+
function createCommandContext({
|
|
1360
|
+
controller,
|
|
1361
|
+
target,
|
|
1362
|
+
messages,
|
|
1363
|
+
host
|
|
1364
|
+
}) {
|
|
1365
|
+
const state = controller.getState();
|
|
1366
|
+
const view = controller.getView();
|
|
1367
|
+
let selectedRows;
|
|
1368
|
+
return {
|
|
1369
|
+
target,
|
|
1370
|
+
state,
|
|
1371
|
+
view,
|
|
1372
|
+
options: controller.getOptions(),
|
|
1373
|
+
messages,
|
|
1374
|
+
actions: controller,
|
|
1375
|
+
host,
|
|
1376
|
+
row: target.area === "cell" ? view.rows.find((entry) => entry.rowId === target.rowId) ?? null : null,
|
|
1377
|
+
column: "columnId" in target ? view.dataColumns.find((entry) => entry.id === target.columnId) ?? null : null,
|
|
1378
|
+
selectedRows: () => selectedRows ??= selectedRowsOf(view.rows, state.rowSelection)
|
|
1379
|
+
};
|
|
4381
1380
|
}
|
|
4382
1381
|
|
|
4383
1382
|
// src/toolbar/options.ts
|
|
@@ -4455,431 +1454,6 @@ function resolveToolbar(entries, options) {
|
|
|
4455
1454
|
);
|
|
4456
1455
|
}
|
|
4457
1456
|
|
|
4458
|
-
// src/toolbar/overflow.ts
|
|
4459
|
-
function fitToolbarItems({
|
|
4460
|
-
widths,
|
|
4461
|
-
available,
|
|
4462
|
-
moreWidth,
|
|
4463
|
-
pinned
|
|
4464
|
-
}) {
|
|
4465
|
-
const total = widths.reduce((sum, width) => sum + width, 0);
|
|
4466
|
-
if (total <= available) {
|
|
4467
|
-
return widths.length;
|
|
4468
|
-
}
|
|
4469
|
-
let used = moreWidth + widths.reduce((sum, width, index) => sum + (pinned[index] ? width : 0), 0);
|
|
4470
|
-
for (const [index, width] of widths.entries()) {
|
|
4471
|
-
if (!pinned[index]) {
|
|
4472
|
-
used += width;
|
|
4473
|
-
if (used > available) {
|
|
4474
|
-
return index;
|
|
4475
|
-
}
|
|
4476
|
-
}
|
|
4477
|
-
}
|
|
4478
|
-
return widths.length;
|
|
4479
|
-
}
|
|
4480
|
-
function isPinnedToolbarItem(item) {
|
|
4481
|
-
return item.type === "search" || item.type === "custom";
|
|
4482
|
-
}
|
|
4483
|
-
function asMenuEntry(item) {
|
|
4484
|
-
switch (item.type) {
|
|
4485
|
-
case "button":
|
|
4486
|
-
return {
|
|
4487
|
-
type: "item",
|
|
4488
|
-
id: item.id,
|
|
4489
|
-
label: item.label,
|
|
4490
|
-
icon: item.icon,
|
|
4491
|
-
shortcut: item.shortcut,
|
|
4492
|
-
disabled: item.disabled,
|
|
4493
|
-
checked: item.pressed,
|
|
4494
|
-
run: item.run
|
|
4495
|
-
};
|
|
4496
|
-
case "menu":
|
|
4497
|
-
return {
|
|
4498
|
-
type: "submenu",
|
|
4499
|
-
id: item.id,
|
|
4500
|
-
label: item.label,
|
|
4501
|
-
icon: item.icon,
|
|
4502
|
-
items: item.items
|
|
4503
|
-
};
|
|
4504
|
-
case "separator":
|
|
4505
|
-
return item;
|
|
4506
|
-
default:
|
|
4507
|
-
return null;
|
|
4508
|
-
}
|
|
4509
|
-
}
|
|
4510
|
-
function splitToolbarItems(items, fit) {
|
|
4511
|
-
const fits = (item, index) => index < fit || isPinnedToolbarItem(item);
|
|
4512
|
-
return {
|
|
4513
|
-
shown: collapseSeparators(
|
|
4514
|
-
items.filter(fits),
|
|
4515
|
-
(item) => item.type === "spacer"
|
|
4516
|
-
),
|
|
4517
|
-
overflow: collapseSeparators(
|
|
4518
|
-
items.filter((item, index) => !fits(item, index)).map(asMenuEntry).filter((entry) => entry !== null)
|
|
4519
|
-
)
|
|
4520
|
-
};
|
|
4521
|
-
}
|
|
4522
|
-
|
|
4523
|
-
// src/toolbar/search.ts
|
|
4524
|
-
function searchTextOf(filter) {
|
|
4525
|
-
const query = filterQueryFor(filter) ?? "";
|
|
4526
|
-
const start = query.startsWith("%") ? 1 : 0;
|
|
4527
|
-
const end = query.endsWith("%") ? -1 : void 0;
|
|
4528
|
-
return query.slice(start, end);
|
|
4529
|
-
}
|
|
4530
|
-
function setSearchText(filter, text) {
|
|
4531
|
-
return setColumnFilter(filter, void 0, text === "" ? "" : `%${text}%`);
|
|
4532
|
-
}
|
|
4533
|
-
|
|
4534
|
-
// src/util/navigation.ts
|
|
4535
|
-
function headerFocus(columnIndex) {
|
|
4536
|
-
return { area: "header", columnIndex };
|
|
4537
|
-
}
|
|
4538
|
-
function bodyFocus(rowIndex, columnIndex) {
|
|
4539
|
-
return { area: "body", rowIndex, columnIndex };
|
|
4540
|
-
}
|
|
4541
|
-
function clampFocus(focus, rowCount, columnCount2) {
|
|
4542
|
-
const columnIndex = Math.min(
|
|
4543
|
-
Math.max(focus.columnIndex, 0),
|
|
4544
|
-
Math.max(columnCount2 - 1, 0)
|
|
4545
|
-
);
|
|
4546
|
-
switch (focus.area) {
|
|
4547
|
-
case "header":
|
|
4548
|
-
return headerFocus(columnIndex);
|
|
4549
|
-
case "body": {
|
|
4550
|
-
const rowIndex = Math.min(focus.rowIndex, rowCount - 1);
|
|
4551
|
-
return rowIndex < 0 ? headerFocus(columnIndex) : bodyFocus(rowIndex, columnIndex);
|
|
4552
|
-
}
|
|
4553
|
-
}
|
|
4554
|
-
}
|
|
4555
|
-
function noRowsSkippable() {
|
|
4556
|
-
return false;
|
|
4557
|
-
}
|
|
4558
|
-
function linePosition(focus) {
|
|
4559
|
-
return focus.area === "header" ? -1 : focus.rowIndex;
|
|
4560
|
-
}
|
|
4561
|
-
function focusAtLine(line2, columnIndex) {
|
|
4562
|
-
return line2 < 0 ? headerFocus(columnIndex) : bodyFocus(line2, columnIndex);
|
|
4563
|
-
}
|
|
4564
|
-
function skipSkippableRows(target, direction, rowCount, isSkippableRow, fallback) {
|
|
4565
|
-
if (target.area === "header") {
|
|
4566
|
-
return target;
|
|
4567
|
-
}
|
|
4568
|
-
let rowIndex = target.rowIndex;
|
|
4569
|
-
while (rowIndex < rowCount && isSkippableRow(rowIndex)) {
|
|
4570
|
-
const stepped = rowIndex + direction;
|
|
4571
|
-
if (stepped >= rowCount) {
|
|
4572
|
-
return fallback;
|
|
4573
|
-
}
|
|
4574
|
-
if (stepped < 0) {
|
|
4575
|
-
return headerFocus(target.columnIndex);
|
|
4576
|
-
}
|
|
4577
|
-
rowIndex = stepped;
|
|
4578
|
-
}
|
|
4579
|
-
return bodyFocus(rowIndex, target.columnIndex);
|
|
4580
|
-
}
|
|
4581
|
-
function nextFocusForKey(key, modifiers, focus, rowCount, columnCount2, pageSize, isSkippableRow = noRowsSkippable) {
|
|
4582
|
-
if (modifiers.altKey) {
|
|
4583
|
-
return null;
|
|
4584
|
-
}
|
|
4585
|
-
const { columnIndex } = focus;
|
|
4586
|
-
function moveRows(rows) {
|
|
4587
|
-
return skipSkippableRows(
|
|
4588
|
-
focusAtLine(linePosition(focus) + rows, columnIndex),
|
|
4589
|
-
rows < 0 ? -1 : 1,
|
|
4590
|
-
rowCount,
|
|
4591
|
-
isSkippableRow,
|
|
4592
|
-
focus
|
|
4593
|
-
);
|
|
4594
|
-
}
|
|
4595
|
-
switch (key) {
|
|
4596
|
-
case "ArrowLeft":
|
|
4597
|
-
if (modifiers.ctrlKey) return null;
|
|
4598
|
-
return { ...focus, columnIndex: columnIndex - 1 };
|
|
4599
|
-
case "ArrowRight":
|
|
4600
|
-
if (modifiers.ctrlKey) return null;
|
|
4601
|
-
return { ...focus, columnIndex: columnIndex + 1 };
|
|
4602
|
-
case "ArrowUp":
|
|
4603
|
-
return moveRows(-1);
|
|
4604
|
-
case "ArrowDown":
|
|
4605
|
-
return moveRows(1);
|
|
4606
|
-
// Ctrl takes Home and End to the grid's ends rather than the row's, which
|
|
4607
|
-
// is the one place Ctrl is navigation rather than reorder.
|
|
4608
|
-
case "Home":
|
|
4609
|
-
return modifiers.ctrlKey ? headerFocus(0) : { ...focus, columnIndex: 0 };
|
|
4610
|
-
case "End": {
|
|
4611
|
-
const rowEnd = { ...focus, columnIndex: columnCount2 - 1 };
|
|
4612
|
-
return modifiers.ctrlKey ? skipSkippableRows(
|
|
4613
|
-
focusAtLine(rowCount - 1, columnCount2 - 1),
|
|
4614
|
-
-1,
|
|
4615
|
-
rowCount,
|
|
4616
|
-
isSkippableRow,
|
|
4617
|
-
rowEnd
|
|
4618
|
-
) : rowEnd;
|
|
4619
|
-
}
|
|
4620
|
-
case "PageUp":
|
|
4621
|
-
return moveRows(-pageSize);
|
|
4622
|
-
case "PageDown":
|
|
4623
|
-
return moveRows(pageSize);
|
|
4624
|
-
default:
|
|
4625
|
-
return null;
|
|
4626
|
-
}
|
|
4627
|
-
}
|
|
4628
|
-
|
|
4629
|
-
// src/util/paginationWindow.ts
|
|
4630
|
-
function paginationWindow(currentPage, pageCount, options) {
|
|
4631
|
-
if (pageCount <= 0) {
|
|
4632
|
-
return [];
|
|
4633
|
-
}
|
|
4634
|
-
const boundaryCount = Math.max(0, Math.floor(options?.boundaryCount ?? 1));
|
|
4635
|
-
const siblingCount = Math.max(0, Math.floor(options?.siblingCount ?? 1));
|
|
4636
|
-
const slotCount = 2 * boundaryCount + 2 * siblingCount + 3;
|
|
4637
|
-
if (pageCount <= slotCount) {
|
|
4638
|
-
return Array.from({ length: pageCount }, (_, index) => index + 1);
|
|
4639
|
-
}
|
|
4640
|
-
const current = Math.min(Math.max(currentPage, 1), pageCount);
|
|
4641
|
-
const runStart = Math.min(
|
|
4642
|
-
Math.max(current - siblingCount, boundaryCount + 2),
|
|
4643
|
-
pageCount - boundaryCount - 1 - 2 * siblingCount
|
|
4644
|
-
);
|
|
4645
|
-
const runEnd = runStart + 2 * siblingCount;
|
|
4646
|
-
const entries = [];
|
|
4647
|
-
for (let page = 1; page <= boundaryCount; page++) {
|
|
4648
|
-
entries.push(page);
|
|
4649
|
-
}
|
|
4650
|
-
entries.push(runStart === boundaryCount + 2 ? boundaryCount + 1 : "ellipsis");
|
|
4651
|
-
for (let page = runStart; page <= runEnd; page++) {
|
|
4652
|
-
entries.push(page);
|
|
4653
|
-
}
|
|
4654
|
-
entries.push(
|
|
4655
|
-
runEnd === pageCount - boundaryCount - 1 ? pageCount - boundaryCount : "ellipsis"
|
|
4656
|
-
);
|
|
4657
|
-
for (let page = pageCount - boundaryCount + 1; page <= pageCount; page++) {
|
|
4658
|
-
entries.push(page);
|
|
4659
|
-
}
|
|
4660
|
-
return entries;
|
|
4661
|
-
}
|
|
4662
|
-
|
|
4663
|
-
// src/util/columnChooser.ts
|
|
4664
|
-
function isHideable(column) {
|
|
4665
|
-
return column.column.hideable !== false;
|
|
4666
|
-
}
|
|
4667
|
-
function matchesSearch2(label, search) {
|
|
4668
|
-
return label.toLowerCase().includes(search.toLowerCase());
|
|
4669
|
-
}
|
|
4670
|
-
function selectAllStateOf(states) {
|
|
4671
|
-
if (states.length > 0 && states.every(Boolean)) {
|
|
4672
|
-
return "checked";
|
|
4673
|
-
}
|
|
4674
|
-
return states.some(Boolean) ? "mixed" : "unchecked";
|
|
4675
|
-
}
|
|
4676
|
-
function resolveColumnChooser({
|
|
4677
|
-
columns,
|
|
4678
|
-
visibility,
|
|
4679
|
-
search = ""
|
|
4680
|
-
}) {
|
|
4681
|
-
const all = columns.map((column) => ({
|
|
4682
|
-
column,
|
|
4683
|
-
label: resolveColumnHeaderText(column.column),
|
|
4684
|
-
visible: isColumnVisible(column.column, visibility)
|
|
4685
|
-
}));
|
|
4686
|
-
const shownCount = all.filter(({ visible }) => visible).length;
|
|
4687
|
-
const matched = all.filter(({ label }) => matchesSearch2(label, search));
|
|
4688
|
-
const entries = matched.map(
|
|
4689
|
-
({ column, label, visible }) => ({
|
|
4690
|
-
columnId: column.id,
|
|
4691
|
-
label,
|
|
4692
|
-
visible,
|
|
4693
|
-
disabled: visible && (!isHideable(column) || shownCount === 1)
|
|
4694
|
-
})
|
|
4695
|
-
);
|
|
4696
|
-
const covered = matched.filter(({ column }) => isHideable(column));
|
|
4697
|
-
const selectAll2 = selectAllStateOf(covered.map(({ visible }) => visible));
|
|
4698
|
-
return {
|
|
4699
|
-
entries,
|
|
4700
|
-
selectAll: selectAll2,
|
|
4701
|
-
toggleAll: toggleAllOf(covered, selectAll2, shownCount)
|
|
4702
|
-
};
|
|
4703
|
-
}
|
|
4704
|
-
function toggleAllOf(covered, selectAll2, shownCount) {
|
|
4705
|
-
const show = selectAll2 !== "checked";
|
|
4706
|
-
const changing = covered.filter(({ visible }) => visible !== show).map(({ column }) => column.id);
|
|
4707
|
-
const columnIds = !show && changing.length === shownCount ? changing.slice(1) : changing;
|
|
4708
|
-
return columnIds.length === 0 ? null : { visible: show, columnIds };
|
|
4709
|
-
}
|
|
4710
|
-
|
|
4711
|
-
// src/filterMenu/conditions.ts
|
|
4712
|
-
var ROW_COUNT = 2;
|
|
4713
|
-
function rowOf(condition, type) {
|
|
4714
|
-
const { operator, value } = condition;
|
|
4715
|
-
if (isScalarList(value)) {
|
|
4716
|
-
const [low, high] = value;
|
|
4717
|
-
return {
|
|
4718
|
-
operator,
|
|
4719
|
-
text: formatFilterOperand(low, type),
|
|
4720
|
-
textTo: formatFilterOperand(high, type)
|
|
4721
|
-
};
|
|
4722
|
-
}
|
|
4723
|
-
return { operator, text: formatFilterOperand(value, type), textTo: "" };
|
|
4724
|
-
}
|
|
4725
|
-
function conditionRowsFrom(shape, operators, type) {
|
|
4726
|
-
const filled = shape.kind === "conditions" ? shape.conditions.map((condition) => rowOf(condition, type)) : [];
|
|
4727
|
-
const [first] = operators;
|
|
4728
|
-
if (first === void 0) {
|
|
4729
|
-
return filled;
|
|
4730
|
-
}
|
|
4731
|
-
const blank = { operator: first, text: "", textTo: "" };
|
|
4732
|
-
return Array.from(
|
|
4733
|
-
{ length: ROW_COUNT },
|
|
4734
|
-
(_, index) => filled[index] ?? blank
|
|
4735
|
-
);
|
|
4736
|
-
}
|
|
4737
|
-
function isEmptyRow(row) {
|
|
4738
|
-
switch (filterOperandArity(row.operator)) {
|
|
4739
|
-
case 0:
|
|
4740
|
-
return false;
|
|
4741
|
-
case 1:
|
|
4742
|
-
return row.text === "";
|
|
4743
|
-
case 2:
|
|
4744
|
-
return row.text === "" && row.textTo === "";
|
|
4745
|
-
}
|
|
4746
|
-
}
|
|
4747
|
-
function conditionOf(row, columnId, type) {
|
|
4748
|
-
const { operator } = row;
|
|
4749
|
-
switch (filterOperandArity(operator)) {
|
|
4750
|
-
case 0:
|
|
4751
|
-
return { kind: "operator", columnId, operator };
|
|
4752
|
-
case 1: {
|
|
4753
|
-
const value = parseFilterOperand(row.text, type);
|
|
4754
|
-
return value === void 0 ? void 0 : { kind: "operator", columnId, operator, value };
|
|
4755
|
-
}
|
|
4756
|
-
case 2: {
|
|
4757
|
-
const low = parseFilterOperand(row.text, type);
|
|
4758
|
-
const high = parseFilterOperand(row.textTo, type);
|
|
4759
|
-
return low === void 0 || high === void 0 ? void 0 : { kind: "operator", columnId, operator, value: [low, high] };
|
|
4760
|
-
}
|
|
4761
|
-
}
|
|
4762
|
-
}
|
|
4763
|
-
function conditionsFromRows(rows, columnId, type) {
|
|
4764
|
-
const conditions = [];
|
|
4765
|
-
const invalid = [];
|
|
4766
|
-
for (const [index, row] of rows.entries()) {
|
|
4767
|
-
if (index > 0 && isEmptyRow(row)) {
|
|
4768
|
-
continue;
|
|
4769
|
-
}
|
|
4770
|
-
const condition = conditionOf(row, columnId, type);
|
|
4771
|
-
if (condition === void 0) {
|
|
4772
|
-
invalid.push(index);
|
|
4773
|
-
} else {
|
|
4774
|
-
conditions.push(condition);
|
|
4775
|
-
}
|
|
4776
|
-
}
|
|
4777
|
-
return { conditions, invalid };
|
|
4778
|
-
}
|
|
4779
|
-
|
|
4780
|
-
// src/filterMenu/valueCache.ts
|
|
4781
|
-
function sameSource(a, b) {
|
|
4782
|
-
return a.rows === b.rows && a.dataColumns === b.dataColumns && a.locale === b.locale && a.messages === b.messages;
|
|
4783
|
-
}
|
|
4784
|
-
function sameEntries(a, b) {
|
|
4785
|
-
return a.length === b.length && a.every((entry, index) => entry === b[index]);
|
|
4786
|
-
}
|
|
4787
|
-
function createColumnValueOptionsCache() {
|
|
4788
|
-
let source;
|
|
4789
|
-
const lists = /* @__PURE__ */ new Map();
|
|
4790
|
-
return {
|
|
4791
|
-
get: (rows, dataColumns, filter, columnId, query = {}) => {
|
|
4792
|
-
const { locale, messages } = query;
|
|
4793
|
-
const current = { rows, dataColumns, locale, messages };
|
|
4794
|
-
if (source === void 0 || !sameSource(source, current)) {
|
|
4795
|
-
lists.clear();
|
|
4796
|
-
source = current;
|
|
4797
|
-
}
|
|
4798
|
-
const others = filter.filter((entry) => !touchesColumn(entry, columnId));
|
|
4799
|
-
const cached2 = lists.get(columnId);
|
|
4800
|
-
if (cached2 !== void 0 && sameEntries(cached2.others, others)) {
|
|
4801
|
-
return cached2.values;
|
|
4802
|
-
}
|
|
4803
|
-
const values = columnValueOptions(
|
|
4804
|
-
rows,
|
|
4805
|
-
dataColumns,
|
|
4806
|
-
filter,
|
|
4807
|
-
columnId,
|
|
4808
|
-
messages === void 0 ? { locale } : { locale, messages }
|
|
4809
|
-
);
|
|
4810
|
-
lists.set(columnId, { others, values });
|
|
4811
|
-
return values;
|
|
4812
|
-
}
|
|
4813
|
-
};
|
|
4814
|
-
}
|
|
4815
|
-
|
|
4816
|
-
// src/filterMenu/checklist.ts
|
|
4817
|
-
function filterChecklist(draft, { valueLimit, blanksLabel }) {
|
|
4818
|
-
const visible = visibleFilterOptions(draft);
|
|
4819
|
-
const total = visible.length;
|
|
4820
|
-
if (draft.search === "" && total > valueLimit) {
|
|
4821
|
-
return { items: [], needsSearch: true, hiddenCount: 0, total };
|
|
4822
|
-
}
|
|
4823
|
-
const items = visible.slice(0, valueLimit).map(({ value, label, count }) => {
|
|
4824
|
-
const key = keyOf2(draft, value);
|
|
4825
|
-
const checked = draft.checked.has(key);
|
|
4826
|
-
return { kind: "value", key, value, label, count, checked };
|
|
4827
|
-
});
|
|
4828
|
-
const hiddenCount = total - items.length;
|
|
4829
|
-
if (selectAllCoversBlanks(draft)) {
|
|
4830
|
-
items.push({
|
|
4831
|
-
kind: "blanks",
|
|
4832
|
-
// Blank cells' own key, which no offered value has.
|
|
4833
|
-
key: keyOf2(draft, null),
|
|
4834
|
-
label: blanksLabel,
|
|
4835
|
-
count: draft.blanks,
|
|
4836
|
-
checked: draft.includeBlanks
|
|
4837
|
-
});
|
|
4838
|
-
}
|
|
4839
|
-
return { items, needsSearch: false, hiddenCount, total };
|
|
4840
|
-
}
|
|
4841
|
-
|
|
4842
|
-
// src/util/virtualization.ts
|
|
4843
|
-
function visibleRange(heights, estimatedHeight, scrollTop, viewportHeight, overscan) {
|
|
4844
|
-
const rowCount = heights.length;
|
|
4845
|
-
if (rowCount === 0) {
|
|
4846
|
-
return { startIndex: 0, endIndex: -1, offsetBefore: 0, offsetAfter: 0 };
|
|
4847
|
-
}
|
|
4848
|
-
function heightAt(index) {
|
|
4849
|
-
return heights[index] ?? estimatedHeight;
|
|
4850
|
-
}
|
|
4851
|
-
const viewportBottom = scrollTop + viewportHeight;
|
|
4852
|
-
let start = 0;
|
|
4853
|
-
let top = 0;
|
|
4854
|
-
while (start < rowCount - 1 && top + heightAt(start) <= scrollTop) {
|
|
4855
|
-
top += heightAt(start);
|
|
4856
|
-
start += 1;
|
|
4857
|
-
}
|
|
4858
|
-
const startTop = top;
|
|
4859
|
-
let end = start;
|
|
4860
|
-
let bottom = startTop + heightAt(start);
|
|
4861
|
-
while (end < rowCount - 1 && bottom < viewportBottom) {
|
|
4862
|
-
end += 1;
|
|
4863
|
-
bottom += heightAt(end);
|
|
4864
|
-
}
|
|
4865
|
-
const overscanStart = Math.max(0, start - overscan);
|
|
4866
|
-
const overscanEnd = Math.min(rowCount - 1, end + overscan);
|
|
4867
|
-
let offsetBefore = 0;
|
|
4868
|
-
for (let index = 0; index < overscanStart; index++) {
|
|
4869
|
-
offsetBefore += heightAt(index);
|
|
4870
|
-
}
|
|
4871
|
-
let offsetAfter = 0;
|
|
4872
|
-
for (let index = overscanEnd + 1; index < rowCount; index++) {
|
|
4873
|
-
offsetAfter += heightAt(index);
|
|
4874
|
-
}
|
|
4875
|
-
return {
|
|
4876
|
-
startIndex: overscanStart,
|
|
4877
|
-
endIndex: overscanEnd,
|
|
4878
|
-
offsetBefore,
|
|
4879
|
-
offsetAfter
|
|
4880
|
-
};
|
|
4881
|
-
}
|
|
4882
|
-
|
|
4883
1457
|
// src/presets.ts
|
|
4884
1458
|
var excelFilter = {
|
|
4885
1459
|
filterableColumns: true,
|
|
@@ -4890,32 +1464,21 @@ export {
|
|
|
4890
1464
|
ALL_EXPANDED,
|
|
4891
1465
|
DEFAULT_COLUMN_SIZES,
|
|
4892
1466
|
DEFAULT_FILTER_VALUE_LIMIT,
|
|
4893
|
-
KEYBOARD_STEP,
|
|
4894
1467
|
accessDotted,
|
|
4895
1468
|
alignmentForType,
|
|
4896
1469
|
applyColumnOrder,
|
|
4897
|
-
|
|
1470
|
+
applyColumnPinning,
|
|
4898
1471
|
applyColumnVisibility,
|
|
4899
1472
|
applySelectionIntent,
|
|
4900
|
-
beginColumnResize,
|
|
4901
1473
|
bodyFocus,
|
|
4902
1474
|
buildExportTable,
|
|
4903
|
-
buildKeyShortcuts,
|
|
4904
|
-
buildPrintDocument,
|
|
4905
1475
|
builtInCommands,
|
|
4906
|
-
clampColumnWidth,
|
|
4907
|
-
clampFocus,
|
|
4908
1476
|
clearAllFilters,
|
|
4909
1477
|
clearSelection,
|
|
4910
1478
|
collapseAllGroups,
|
|
4911
|
-
columnValueOptions,
|
|
4912
1479
|
compareValues,
|
|
4913
1480
|
computeAggregates,
|
|
4914
|
-
conditionRowsFrom,
|
|
4915
|
-
conditionsFromRows,
|
|
4916
1481
|
contextMenuEntries,
|
|
4917
|
-
copyContent,
|
|
4918
|
-
createColumnValueOptionsCache,
|
|
4919
1482
|
createCommandContext,
|
|
4920
1483
|
createDefaultMessages,
|
|
4921
1484
|
createGridController,
|
|
@@ -4926,101 +1489,65 @@ export {
|
|
|
4926
1489
|
defaultMessages,
|
|
4927
1490
|
defaultToolbar,
|
|
4928
1491
|
defineColumnsFromRows,
|
|
4929
|
-
describeColumnFilter,
|
|
4930
|
-
diffSelection,
|
|
4931
|
-
draftToFilter,
|
|
4932
1492
|
excelFilter,
|
|
4933
1493
|
expandAllGroups,
|
|
4934
1494
|
exportFile,
|
|
4935
1495
|
exportPrintDocument,
|
|
4936
|
-
filterChecklist,
|
|
4937
|
-
filterDraftChanged,
|
|
4938
|
-
filterEditorReducer,
|
|
4939
|
-
filterOperandArity,
|
|
4940
|
-
filterOperatorFamily,
|
|
4941
1496
|
filterQueryFor,
|
|
4942
1497
|
filterRows,
|
|
4943
|
-
fitColumnsToWidth,
|
|
4944
|
-
fitToolbarItems,
|
|
4945
1498
|
formatAggregateValue,
|
|
4946
1499
|
formatCellValue,
|
|
4947
|
-
formatFilterOperand,
|
|
4948
1500
|
formatGroupValue,
|
|
4949
1501
|
getColumnId,
|
|
4950
1502
|
groupRowId,
|
|
4951
1503
|
groupRows,
|
|
4952
|
-
hasContextMenu,
|
|
4953
1504
|
headerFocus,
|
|
4954
|
-
initialFilterEditorDraft,
|
|
4955
|
-
intentOf,
|
|
4956
1505
|
isColumnFiltered,
|
|
4957
1506
|
isColumnVisible,
|
|
4958
1507
|
isGroupExpanded,
|
|
4959
|
-
isPinnedToolbarItem,
|
|
4960
1508
|
isSameCell,
|
|
4961
1509
|
jsonWriter,
|
|
4962
1510
|
matchesQuery,
|
|
4963
1511
|
moveColumnBefore,
|
|
4964
1512
|
moveGroupByBefore,
|
|
4965
|
-
movesColumn,
|
|
4966
|
-
movesGroupBy,
|
|
4967
|
-
nextFocusForKey,
|
|
4968
|
-
nextMenuIndex,
|
|
4969
1513
|
paginateRows,
|
|
4970
|
-
paginationWindow,
|
|
4971
|
-
parseFilterOperand,
|
|
4972
1514
|
resolveCell,
|
|
4973
|
-
resolveColumnChooser,
|
|
4974
|
-
resolveColumnConstraints,
|
|
4975
|
-
resolveColumnFilterMenu,
|
|
4976
1515
|
resolveColumnHeaderText,
|
|
4977
1516
|
resolveColumnLabel,
|
|
1517
|
+
resolveColumnPin,
|
|
4978
1518
|
resolveColumnWidths,
|
|
4979
1519
|
resolveColumns,
|
|
4980
1520
|
resolveCommands,
|
|
4981
1521
|
resolveDataColumns,
|
|
4982
|
-
resolveDropBefore,
|
|
4983
1522
|
resolveExportWriters,
|
|
4984
1523
|
resolveGridView,
|
|
4985
|
-
resolveKeyboardDropTarget,
|
|
4986
1524
|
resolveMenu,
|
|
4987
1525
|
resolveMessages,
|
|
4988
1526
|
resolveRowId,
|
|
4989
1527
|
resolveRows,
|
|
4990
1528
|
resolveShownRows,
|
|
4991
1529
|
resolveToolbar,
|
|
4992
|
-
revertColumnSize,
|
|
4993
1530
|
runCommand,
|
|
4994
|
-
searchTextOf,
|
|
4995
1531
|
selectAll,
|
|
4996
|
-
selectAllState,
|
|
4997
1532
|
selectCell,
|
|
4998
1533
|
selectOnly,
|
|
4999
1534
|
selectRange,
|
|
5000
1535
|
serializeGridState,
|
|
5001
1536
|
setColumnFilter,
|
|
1537
|
+
setColumnPin,
|
|
5002
1538
|
setColumnVisibility,
|
|
5003
|
-
setSearchText,
|
|
5004
|
-
sizeColumnToContent,
|
|
5005
1539
|
sortDirectionFor,
|
|
5006
1540
|
sortPriorityFor,
|
|
5007
1541
|
sortRows,
|
|
5008
|
-
splitToolbarItems,
|
|
5009
|
-
toConditionsDraft,
|
|
5010
1542
|
toCsv,
|
|
5011
1543
|
toHtmlTable,
|
|
5012
1544
|
toJson,
|
|
5013
1545
|
toTsv,
|
|
5014
|
-
toValuesDraft,
|
|
5015
1546
|
toggleCellSelection,
|
|
5016
1547
|
toggleColumnSort,
|
|
5017
1548
|
toggleGroupExpansion,
|
|
5018
1549
|
toggleSelection,
|
|
5019
1550
|
toolbarEntries,
|
|
5020
|
-
totalColumnWidth,
|
|
5021
|
-
typeaheadIndex,
|
|
5022
|
-
visibleFilterOptions,
|
|
5023
|
-
visibleRange,
|
|
5024
1551
|
withGroupAggregates
|
|
5025
1552
|
};
|
|
5026
1553
|
//# sourceMappingURL=index.js.map
|