@gridkitjs/core 0.0.0-dev-20261109134250 → 0.0.0-dev-20261112193051
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.d.ts +5 -5
- package/dist/index.js +163 -143
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.d.ts
CHANGED
|
@@ -2572,11 +2572,10 @@ interface ResolvedGroupSummaryRow {
|
|
|
2572
2572
|
readonly aggregates: AggregateResults;
|
|
2573
2573
|
}
|
|
2574
2574
|
/**
|
|
2575
|
-
* One entry of a grouped result:
|
|
2576
|
-
*
|
|
2577
|
-
*
|
|
2578
|
-
*
|
|
2579
|
-
* Discriminate with `"kind" in entry`, then `entry.kind`.
|
|
2575
|
+
* One entry of a grouped result: a data row (`kind: "data"`), a group header
|
|
2576
|
+
* (`kind: "group"`), or — only when `groupAggregateDisplay: "row"` is
|
|
2577
|
+
* active — that group's own summary row (`kind: "group-summary"`).
|
|
2578
|
+
* Discriminate with `entry.kind`.
|
|
2580
2579
|
*/
|
|
2581
2580
|
type DisplayRow<Row> = ResolvedRow<Row> | ResolvedGroupRow | ResolvedGroupSummaryRow;
|
|
2582
2581
|
/** A reducer this package computes without a custom `AggregateFn`. */
|
|
@@ -2830,6 +2829,7 @@ interface SelectionDiff {
|
|
|
2830
2829
|
* itself rather than an id it has to look up.
|
|
2831
2830
|
*/
|
|
2832
2831
|
interface ResolvedRow<Row> {
|
|
2832
|
+
readonly kind: "data";
|
|
2833
2833
|
readonly rowId: string;
|
|
2834
2834
|
readonly row: Row;
|
|
2835
2835
|
/** Position among the rows as rendered, matching `CellTemplateContext`. */
|
package/dist/index.js
CHANGED
|
@@ -424,85 +424,6 @@ function resolveKeyboardDropTarget(orderedIds, columnId, direction) {
|
|
|
424
424
|
return orderedIds[targetIndex] ?? null;
|
|
425
425
|
}
|
|
426
426
|
|
|
427
|
-
// src/util/paging.ts
|
|
428
|
-
var NO_HEADERS = [];
|
|
429
|
-
function groupUnitsOf(rows) {
|
|
430
|
-
const units = [];
|
|
431
|
-
let start = 0;
|
|
432
|
-
let openedByGroup = false;
|
|
433
|
-
for (let index = 0; index < rows.length; index++) {
|
|
434
|
-
const entry = rows[index];
|
|
435
|
-
if (entry === void 0) {
|
|
436
|
-
continue;
|
|
437
|
-
}
|
|
438
|
-
const isTopLevelHeader = "kind" in entry && entry.kind === "group" && entry.level === 0;
|
|
439
|
-
const isBoundary = index !== start && (isTopLevelHeader || !openedByGroup);
|
|
440
|
-
if (isBoundary) {
|
|
441
|
-
units.push({ start, end: index, headers: NO_HEADERS });
|
|
442
|
-
start = index;
|
|
443
|
-
openedByGroup = isTopLevelHeader;
|
|
444
|
-
} else if (index === start) {
|
|
445
|
-
openedByGroup = isTopLevelHeader;
|
|
446
|
-
}
|
|
447
|
-
}
|
|
448
|
-
if (start < rows.length) {
|
|
449
|
-
units.push({ start, end: rows.length, headers: NO_HEADERS });
|
|
450
|
-
}
|
|
451
|
-
return units;
|
|
452
|
-
}
|
|
453
|
-
function rowUnitsOf(rows) {
|
|
454
|
-
const units = [];
|
|
455
|
-
let open = NO_HEADERS;
|
|
456
|
-
for (let index = 0; index < rows.length; index++) {
|
|
457
|
-
const entry = rows[index];
|
|
458
|
-
if (entry === void 0) {
|
|
459
|
-
continue;
|
|
460
|
-
}
|
|
461
|
-
if (!("kind" in entry)) {
|
|
462
|
-
units.push({ start: index, end: index + 1, headers: open });
|
|
463
|
-
} else if (entry.kind === "group") {
|
|
464
|
-
const ancestors = open.slice(0, entry.level);
|
|
465
|
-
open = entry.expanded ? [...ancestors, entry] : ancestors;
|
|
466
|
-
if (!entry.expanded) {
|
|
467
|
-
units.push({ start: index, end: index + 1, headers: ancestors });
|
|
468
|
-
}
|
|
469
|
-
} else {
|
|
470
|
-
const last = units.at(-1);
|
|
471
|
-
if (last !== void 0) {
|
|
472
|
-
units[units.length - 1] = { ...last, end: index + 1 };
|
|
473
|
-
}
|
|
474
|
-
}
|
|
475
|
-
}
|
|
476
|
-
return units;
|
|
477
|
-
}
|
|
478
|
-
function paginateRows(rows, pagination, options = {}) {
|
|
479
|
-
const pageSize = Math.max(1, pagination.pageSize);
|
|
480
|
-
const units = options.unit === "row" ? rowUnitsOf(rows) : groupUnitsOf(rows);
|
|
481
|
-
const pageCount = Math.ceil(units.length / pageSize);
|
|
482
|
-
if (pageCount === 0) {
|
|
483
|
-
return { rows: [], pageCount: 0, pageIndex: 0 };
|
|
484
|
-
}
|
|
485
|
-
const pageIndex = Math.min(Math.max(pagination.pageIndex, 0), pageCount - 1);
|
|
486
|
-
const firstUnit = units[pageIndex * pageSize];
|
|
487
|
-
const lastUnit = units[Math.min(pageIndex * pageSize + pageSize, units.length) - 1];
|
|
488
|
-
if (firstUnit === void 0 || lastUnit === void 0) {
|
|
489
|
-
return { rows: [], pageCount, pageIndex };
|
|
490
|
-
}
|
|
491
|
-
const page = [
|
|
492
|
-
...firstUnit.headers,
|
|
493
|
-
...rows.slice(firstUnit.start, lastUnit.end)
|
|
494
|
-
];
|
|
495
|
-
const renumbered = page.map(
|
|
496
|
-
(entry, index) => entry.rowIndex === index ? entry : { ...entry, rowIndex: index }
|
|
497
|
-
);
|
|
498
|
-
return { rows: renumbered, pageCount, pageIndex };
|
|
499
|
-
}
|
|
500
|
-
|
|
501
|
-
// src/util/report.ts
|
|
502
|
-
function reportError(message) {
|
|
503
|
-
console.error(`GridKit: ${message}`);
|
|
504
|
-
}
|
|
505
|
-
|
|
506
427
|
// src/util/filterOperators.ts
|
|
507
428
|
var matchNothing = () => false;
|
|
508
429
|
function kindOf(type) {
|
|
@@ -833,6 +754,136 @@ function filterRows(rows, filter, columns) {
|
|
|
833
754
|
return renumberRows(filtered);
|
|
834
755
|
}
|
|
835
756
|
|
|
757
|
+
// src/util/rows.ts
|
|
758
|
+
function resolveShownRows(rows, filter, sort, columns) {
|
|
759
|
+
return sortRows(filterRows(rows, filter, columns), sort, columns);
|
|
760
|
+
}
|
|
761
|
+
function unknownDisplayRow(entry) {
|
|
762
|
+
const { kind } = entry;
|
|
763
|
+
throw new TypeError(
|
|
764
|
+
`GridKit: \`${String(kind)}\` is not a display row kind.`
|
|
765
|
+
);
|
|
766
|
+
}
|
|
767
|
+
function resolveRows(rowsById, ids) {
|
|
768
|
+
return ids.map((id) => rowsById.get(id)).filter((row) => row !== void 0);
|
|
769
|
+
}
|
|
770
|
+
function resolveColumns(columns, ids) {
|
|
771
|
+
return ids.map((id) => {
|
|
772
|
+
const columnIndex = columns.findIndex((entry) => entry.id === id);
|
|
773
|
+
const column = columns[columnIndex];
|
|
774
|
+
return column === void 0 ? void 0 : { columnId: id, column, columnIndex };
|
|
775
|
+
}).filter((column) => column !== void 0);
|
|
776
|
+
}
|
|
777
|
+
function resolveCell(rowsById, columns, cell) {
|
|
778
|
+
if (cell === null) {
|
|
779
|
+
return null;
|
|
780
|
+
}
|
|
781
|
+
const entry = rowsById.get(cell.rowId);
|
|
782
|
+
const columnIndex = columns.findIndex(
|
|
783
|
+
(candidate) => candidate.id === cell.columnId
|
|
784
|
+
);
|
|
785
|
+
const column = columns[columnIndex];
|
|
786
|
+
if (entry === void 0 || column === void 0) {
|
|
787
|
+
return null;
|
|
788
|
+
}
|
|
789
|
+
return {
|
|
790
|
+
rowId: cell.rowId,
|
|
791
|
+
columnId: cell.columnId,
|
|
792
|
+
row: entry.row,
|
|
793
|
+
column,
|
|
794
|
+
rowIndex: entry.rowIndex,
|
|
795
|
+
columnIndex,
|
|
796
|
+
value: accessDotted(entry.row, column.column.field)
|
|
797
|
+
};
|
|
798
|
+
}
|
|
799
|
+
|
|
800
|
+
// src/util/paging.ts
|
|
801
|
+
var NO_HEADERS = [];
|
|
802
|
+
function groupUnitsOf(rows) {
|
|
803
|
+
const units = [];
|
|
804
|
+
let start = 0;
|
|
805
|
+
let openedByGroup = false;
|
|
806
|
+
for (let index = 0; index < rows.length; index++) {
|
|
807
|
+
const entry = rows[index];
|
|
808
|
+
if (entry === void 0) {
|
|
809
|
+
continue;
|
|
810
|
+
}
|
|
811
|
+
const isTopLevelHeader = entry.kind === "group" && entry.level === 0;
|
|
812
|
+
const isBoundary = index !== start && (isTopLevelHeader || !openedByGroup);
|
|
813
|
+
if (isBoundary) {
|
|
814
|
+
units.push({ start, end: index, headers: NO_HEADERS });
|
|
815
|
+
start = index;
|
|
816
|
+
openedByGroup = isTopLevelHeader;
|
|
817
|
+
} else if (index === start) {
|
|
818
|
+
openedByGroup = isTopLevelHeader;
|
|
819
|
+
}
|
|
820
|
+
}
|
|
821
|
+
if (start < rows.length) {
|
|
822
|
+
units.push({ start, end: rows.length, headers: NO_HEADERS });
|
|
823
|
+
}
|
|
824
|
+
return units;
|
|
825
|
+
}
|
|
826
|
+
function rowUnitsOf(rows) {
|
|
827
|
+
const units = [];
|
|
828
|
+
let open = NO_HEADERS;
|
|
829
|
+
for (let index = 0; index < rows.length; index++) {
|
|
830
|
+
const entry = rows[index];
|
|
831
|
+
if (entry === void 0) {
|
|
832
|
+
continue;
|
|
833
|
+
}
|
|
834
|
+
switch (entry.kind) {
|
|
835
|
+
case "data":
|
|
836
|
+
units.push({ start: index, end: index + 1, headers: open });
|
|
837
|
+
break;
|
|
838
|
+
case "group": {
|
|
839
|
+
const ancestors = open.slice(0, entry.level);
|
|
840
|
+
open = entry.expanded ? [...ancestors, entry] : ancestors;
|
|
841
|
+
if (!entry.expanded) {
|
|
842
|
+
units.push({ start: index, end: index + 1, headers: ancestors });
|
|
843
|
+
}
|
|
844
|
+
break;
|
|
845
|
+
}
|
|
846
|
+
case "group-summary": {
|
|
847
|
+
const last = units.at(-1);
|
|
848
|
+
if (last !== void 0) {
|
|
849
|
+
units[units.length - 1] = { ...last, end: index + 1 };
|
|
850
|
+
}
|
|
851
|
+
break;
|
|
852
|
+
}
|
|
853
|
+
default:
|
|
854
|
+
unknownDisplayRow(entry);
|
|
855
|
+
}
|
|
856
|
+
}
|
|
857
|
+
return units;
|
|
858
|
+
}
|
|
859
|
+
function paginateRows(rows, pagination, options = {}) {
|
|
860
|
+
const pageSize = Math.max(1, pagination.pageSize);
|
|
861
|
+
const units = options.unit === "row" ? rowUnitsOf(rows) : groupUnitsOf(rows);
|
|
862
|
+
const pageCount = Math.ceil(units.length / pageSize);
|
|
863
|
+
if (pageCount === 0) {
|
|
864
|
+
return { rows: [], pageCount: 0, pageIndex: 0 };
|
|
865
|
+
}
|
|
866
|
+
const pageIndex = Math.min(Math.max(pagination.pageIndex, 0), pageCount - 1);
|
|
867
|
+
const firstUnit = units[pageIndex * pageSize];
|
|
868
|
+
const lastUnit = units[Math.min(pageIndex * pageSize + pageSize, units.length) - 1];
|
|
869
|
+
if (firstUnit === void 0 || lastUnit === void 0) {
|
|
870
|
+
return { rows: [], pageCount, pageIndex };
|
|
871
|
+
}
|
|
872
|
+
const page = [
|
|
873
|
+
...firstUnit.headers,
|
|
874
|
+
...rows.slice(firstUnit.start, lastUnit.end)
|
|
875
|
+
];
|
|
876
|
+
const renumbered = page.map(
|
|
877
|
+
(entry, index) => entry.rowIndex === index ? entry : { ...entry, rowIndex: index }
|
|
878
|
+
);
|
|
879
|
+
return { rows: renumbered, pageCount, pageIndex };
|
|
880
|
+
}
|
|
881
|
+
|
|
882
|
+
// src/util/report.ts
|
|
883
|
+
function reportError(message) {
|
|
884
|
+
console.error(`GridKit: ${message}`);
|
|
885
|
+
}
|
|
886
|
+
|
|
836
887
|
// src/util/serialize.ts
|
|
837
888
|
function serializeScalar(scalar) {
|
|
838
889
|
return scalar instanceof Date ? scalar.toISOString() : scalar;
|
|
@@ -1207,11 +1258,11 @@ function appendAggregatedSpan(displayRows, start, levelFloor, flatRows, groupBy,
|
|
|
1207
1258
|
index++;
|
|
1208
1259
|
continue;
|
|
1209
1260
|
}
|
|
1210
|
-
if (levelFloor !== null &&
|
|
1261
|
+
if (levelFloor !== null && entry.kind === "group" && entry.level <= levelFloor) {
|
|
1211
1262
|
break;
|
|
1212
1263
|
}
|
|
1213
1264
|
index++;
|
|
1214
|
-
if (
|
|
1265
|
+
if (entry.kind !== "group") {
|
|
1215
1266
|
out.push(entry);
|
|
1216
1267
|
continue;
|
|
1217
1268
|
}
|
|
@@ -1266,43 +1317,6 @@ function withGroupAggregates(displayRows, flatRows, groupBy, specs, columns, dis
|
|
|
1266
1317
|
return renumberRows(out);
|
|
1267
1318
|
}
|
|
1268
1319
|
|
|
1269
|
-
// src/util/rows.ts
|
|
1270
|
-
function resolveShownRows(rows, filter, sort, columns) {
|
|
1271
|
-
return sortRows(filterRows(rows, filter, columns), sort, columns);
|
|
1272
|
-
}
|
|
1273
|
-
function resolveRows(rowsById, ids) {
|
|
1274
|
-
return ids.map((id) => rowsById.get(id)).filter((row) => row !== void 0);
|
|
1275
|
-
}
|
|
1276
|
-
function resolveColumns(columns, ids) {
|
|
1277
|
-
return ids.map((id) => {
|
|
1278
|
-
const columnIndex = columns.findIndex((entry) => entry.id === id);
|
|
1279
|
-
const column = columns[columnIndex];
|
|
1280
|
-
return column === void 0 ? void 0 : { columnId: id, column, columnIndex };
|
|
1281
|
-
}).filter((column) => column !== void 0);
|
|
1282
|
-
}
|
|
1283
|
-
function resolveCell(rowsById, columns, cell) {
|
|
1284
|
-
if (cell === null) {
|
|
1285
|
-
return null;
|
|
1286
|
-
}
|
|
1287
|
-
const entry = rowsById.get(cell.rowId);
|
|
1288
|
-
const columnIndex = columns.findIndex(
|
|
1289
|
-
(candidate) => candidate.id === cell.columnId
|
|
1290
|
-
);
|
|
1291
|
-
const column = columns[columnIndex];
|
|
1292
|
-
if (entry === void 0 || column === void 0) {
|
|
1293
|
-
return null;
|
|
1294
|
-
}
|
|
1295
|
-
return {
|
|
1296
|
-
rowId: cell.rowId,
|
|
1297
|
-
columnId: cell.columnId,
|
|
1298
|
-
row: entry.row,
|
|
1299
|
-
column,
|
|
1300
|
-
rowIndex: entry.rowIndex,
|
|
1301
|
-
columnIndex,
|
|
1302
|
-
value: accessDotted(entry.row, column.column.field)
|
|
1303
|
-
};
|
|
1304
|
-
}
|
|
1305
|
-
|
|
1306
1320
|
// src/util/visibility.ts
|
|
1307
1321
|
function isColumnVisible(column, visibility) {
|
|
1308
1322
|
return visibility[getColumnId(column)] ?? column.hidden !== true;
|
|
@@ -1331,6 +1345,7 @@ function setColumnVisibility(columns, visibility, columnIds, visible) {
|
|
|
1331
1345
|
var NO_AGGREGATES = [];
|
|
1332
1346
|
function identifyRows(rows, getRowId) {
|
|
1333
1347
|
return rows.map((row, rowIndex) => ({
|
|
1348
|
+
kind: "data",
|
|
1334
1349
|
rowId: resolveRowId(row, rowIndex, getRowId),
|
|
1335
1350
|
row,
|
|
1336
1351
|
rowIndex,
|
|
@@ -1356,7 +1371,9 @@ function paginate(displayRows, paginated, pagination, unit) {
|
|
|
1356
1371
|
return paginated ? paginateRows(displayRows, pagination, { unit }) : { rows: displayRows, pageCount: 1, pageIndex: 0 };
|
|
1357
1372
|
}
|
|
1358
1373
|
function narrowToDataRows(pageRows, rows, reshaped) {
|
|
1359
|
-
return reshaped ? pageRows.filter(
|
|
1374
|
+
return reshaped ? pageRows.filter(
|
|
1375
|
+
(entry) => entry.kind === "data"
|
|
1376
|
+
) : rows;
|
|
1360
1377
|
}
|
|
1361
1378
|
function createGridViewResolver() {
|
|
1362
1379
|
const identify = memoizeLast(identifyRows);
|
|
@@ -2517,7 +2534,7 @@ function formatGroupValue(value, column, locale, messages) {
|
|
|
2517
2534
|
// src/export/buildExportTable.ts
|
|
2518
2535
|
var EMPTY_CELL = { value: null, text: "" };
|
|
2519
2536
|
function isDataRow(entry) {
|
|
2520
|
-
return
|
|
2537
|
+
return entry.kind === "data";
|
|
2521
2538
|
}
|
|
2522
2539
|
function pickColumns(view, selection) {
|
|
2523
2540
|
let picked;
|
|
@@ -2617,30 +2634,33 @@ function groupLabel(entry, source) {
|
|
|
2617
2634
|
return `${resolveColumnHeaderText(column)}: ${value}`;
|
|
2618
2635
|
}
|
|
2619
2636
|
function toExportRow(entry, source, context) {
|
|
2620
|
-
|
|
2621
|
-
|
|
2622
|
-
|
|
2623
|
-
|
|
2624
|
-
|
|
2625
|
-
|
|
2626
|
-
|
|
2627
|
-
|
|
2628
|
-
|
|
2629
|
-
|
|
2630
|
-
|
|
2631
|
-
|
|
2632
|
-
|
|
2633
|
-
|
|
2634
|
-
|
|
2635
|
-
|
|
2636
|
-
|
|
2637
|
-
|
|
2637
|
+
switch (entry.kind) {
|
|
2638
|
+
case "data":
|
|
2639
|
+
return {
|
|
2640
|
+
kind: "data",
|
|
2641
|
+
rowId: entry.rowId,
|
|
2642
|
+
cells: context.columns.map(
|
|
2643
|
+
(column) => dataCell(entry.row, column.column, context)
|
|
2644
|
+
)
|
|
2645
|
+
};
|
|
2646
|
+
case "group":
|
|
2647
|
+
return {
|
|
2648
|
+
kind: "group",
|
|
2649
|
+
level: entry.level,
|
|
2650
|
+
groupId: entry.groupId,
|
|
2651
|
+
label: groupLabel(entry, source),
|
|
2652
|
+
count: entry.count,
|
|
2653
|
+
cells: context.display === "inline" ? aggregateCells(entry.aggregates, context) : context.columns.map(() => EMPTY_CELL)
|
|
2654
|
+
};
|
|
2655
|
+
case "group-summary":
|
|
2656
|
+
return {
|
|
2657
|
+
kind: "groupSummary",
|
|
2658
|
+
level: entry.level,
|
|
2659
|
+
cells: aggregateCells(entry.aggregates, context)
|
|
2660
|
+
};
|
|
2661
|
+
default:
|
|
2662
|
+
return unknownDisplayRow(entry);
|
|
2638
2663
|
}
|
|
2639
|
-
return {
|
|
2640
|
-
kind: "groupSummary",
|
|
2641
|
-
level: entry.level,
|
|
2642
|
-
cells: aggregateCells(entry.aggregates, context)
|
|
2643
|
-
};
|
|
2644
2664
|
}
|
|
2645
2665
|
function specsByColumnOf(specs) {
|
|
2646
2666
|
const byColumn = /* @__PURE__ */ new Map();
|