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