@gridkitjs/core 0.19.0 → 0.20.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.
@@ -446,6 +446,182 @@ function resolveKeyboardDropTarget(orderedIds, columnId, direction) {
446
446
  return orderedIds[targetIndex] ?? null;
447
447
  }
448
448
 
449
+ // src/util/pinning.ts
450
+ function resolveColumnPin(column, pinning) {
451
+ return pinning[getColumnId(column)] ?? column.pinned ?? "none";
452
+ }
453
+ function partitionPinnedColumns(columns, pinning) {
454
+ const parts = {
455
+ start: [],
456
+ none: [],
457
+ end: []
458
+ };
459
+ for (const entry of columns) {
460
+ parts[resolveColumnPin(entry.column, pinning)].push(entry);
461
+ }
462
+ return { start: parts.start, unpinned: parts.none, end: parts.end };
463
+ }
464
+ function applyColumnPinning(columns, pinning) {
465
+ const { start, unpinned, end } = partitionPinnedColumns(columns, pinning);
466
+ const ordered = [...start, ...unpinned, ...end];
467
+ return ordered.every((entry, index) => entry === columns[index]) ? columns : ordered;
468
+ }
469
+ function setColumnPin(columns, pinning, columnId, pin) {
470
+ const entry = columns.find((candidate) => candidate.id === columnId);
471
+ if (entry === void 0 || resolveColumnPin(entry.column, pinning) === pin) {
472
+ return pinning;
473
+ }
474
+ return { ...pinning, [columnId]: pin };
475
+ }
476
+ function placePinnedColumns(columns) {
477
+ const lastStart = columns.findLastIndex((entry) => entry.pinned === "start");
478
+ const firstEnd = columns.findIndex((entry) => entry.pinned === "end");
479
+ const startOffsets = widthsBefore(columns, "start");
480
+ const endOffsets = widthsBefore(columns.toReversed(), "end").toReversed();
481
+ return columns.map((entry, index) => {
482
+ switch (entry.pinned) {
483
+ case "start":
484
+ return {
485
+ ...entry,
486
+ pinOffset: startOffsets[index] ?? 0,
487
+ pinEdge: index === lastStart
488
+ };
489
+ case "end":
490
+ return {
491
+ ...entry,
492
+ pinOffset: endOffsets[index] ?? 0,
493
+ pinEdge: index === firstEnd
494
+ };
495
+ case "none":
496
+ return { ...entry, pinOffset: 0, pinEdge: false };
497
+ }
498
+ });
499
+ }
500
+ function widthsBefore(columns, pin) {
501
+ let sum = 0;
502
+ return columns.map((entry) => {
503
+ const before = sum;
504
+ if (entry.pinned === pin) {
505
+ sum += entry.width;
506
+ }
507
+ return before;
508
+ });
509
+ }
510
+ function pinnedWidths(columns) {
511
+ let start = 0;
512
+ let end = 0;
513
+ for (const entry of columns) {
514
+ if (entry.pinned === "start") {
515
+ start += entry.width;
516
+ } else if (entry.pinned === "end") {
517
+ end += entry.width;
518
+ }
519
+ }
520
+ return { start, end };
521
+ }
522
+
523
+ // src/util/selection.ts
524
+ var NO_CHANGE = { added: [], removed: [] };
525
+ function sameSelection(a, b) {
526
+ return a.length === b.length && a.every((id, index) => id === b[index]);
527
+ }
528
+ function toggleSelection(selection, id, mode) {
529
+ if (mode === false) {
530
+ return selection;
531
+ }
532
+ if (selection.includes(id)) {
533
+ return selection.filter((selectedId) => selectedId !== id);
534
+ }
535
+ return mode === "single" ? [id] : [...selection, id];
536
+ }
537
+ function selectOnly(selection, id, mode) {
538
+ if (mode === false) {
539
+ return selection;
540
+ }
541
+ return selection.length === 1 && selection[0] === id ? selection : [id];
542
+ }
543
+ function selectRange(selection, orderedIds, anchorId, focusId, mode) {
544
+ if (mode !== "multiple") {
545
+ return selectOnly(selection, focusId, mode);
546
+ }
547
+ const anchor = orderedIds.indexOf(anchorId);
548
+ const focus = orderedIds.indexOf(focusId);
549
+ if (anchor === -1 || focus === -1) {
550
+ return selection;
551
+ }
552
+ const next = orderedIds.slice(
553
+ Math.min(anchor, focus),
554
+ Math.max(anchor, focus) + 1
555
+ );
556
+ return sameSelection(selection, next) ? selection : next;
557
+ }
558
+ function selectAll(selection, orderedIds, mode) {
559
+ if (mode !== "multiple") {
560
+ return selection;
561
+ }
562
+ return sameSelection(selection, orderedIds) ? selection : orderedIds;
563
+ }
564
+ function clearSelection(selection) {
565
+ return selection.length === 0 ? selection : [];
566
+ }
567
+ function diffSelection(previous, next) {
568
+ if (previous === next) {
569
+ return NO_CHANGE;
570
+ }
571
+ const before = new Set(previous);
572
+ const after = new Set(next);
573
+ return {
574
+ added: next.filter((id) => !before.has(id)),
575
+ removed: previous.filter((id) => !after.has(id))
576
+ };
577
+ }
578
+ var NO_CELL_SELECTED = { kind: "none" };
579
+ function isSameCell(a, b) {
580
+ if (a.kind === "none" || b.kind === "none") {
581
+ return a.kind === b.kind;
582
+ }
583
+ return a.rowId === b.rowId && a.columnId === b.columnId;
584
+ }
585
+ function holdsCell(selection, cell) {
586
+ return selection.kind === "cell" && selection.rowId === cell.rowId && selection.columnId === cell.columnId;
587
+ }
588
+ function selectCell(selection, cell, mode) {
589
+ if (mode === false || holdsCell(selection, cell)) {
590
+ return selection;
591
+ }
592
+ return { kind: "cell", rowId: cell.rowId, columnId: cell.columnId };
593
+ }
594
+ function toggleCellSelection(selection, cell, mode) {
595
+ if (mode === false) {
596
+ return selection;
597
+ }
598
+ return holdsCell(selection, cell) ? NO_CELL_SELECTED : { kind: "cell", rowId: cell.rowId, columnId: cell.columnId };
599
+ }
600
+ function clearCellSelection(selection) {
601
+ return selection.kind === "none" ? selection : NO_CELL_SELECTED;
602
+ }
603
+ function intentOf(event, options) {
604
+ if (event.shiftKey) {
605
+ return "range";
606
+ }
607
+ if (event.ctrlKey || event.metaKey) {
608
+ return "toggle";
609
+ }
610
+ return options?.toggleOnClick === true ? "toggle" : "replace";
611
+ }
612
+ function applySelectionIntent(selection, orderedIds, anchorId, id, intent, mode) {
613
+ switch (intent) {
614
+ case "toggle":
615
+ return toggleSelection(selection, id, mode);
616
+ // A range with no anchor yet spans from the id to itself, which is the
617
+ // plain click a first Shift-click may as well be.
618
+ case "range":
619
+ return selectRange(selection, orderedIds, anchorId ?? id, id, mode);
620
+ default:
621
+ return selectOnly(selection, id, mode);
622
+ }
623
+ }
624
+
449
625
  // src/util/filterOperators.ts
450
626
  var matchNothing = () => false;
451
627
  function kindOf(type) {
@@ -776,225 +952,6 @@ function filterRows(rows, filter, columns) {
776
952
  return renumberRows(filtered);
777
953
  }
778
954
 
779
- // src/util/rows.ts
780
- function resolveShownRows(rows, filter, sort, columns) {
781
- return sortRows(filterRows(rows, filter, columns), sort, columns);
782
- }
783
- function unknownDisplayRow(entry) {
784
- const { kind } = entry;
785
- throw new TypeError(
786
- `GridKit: \`${String(kind)}\` is not a display row kind.`
787
- );
788
- }
789
- function resolveRows(rowsById, ids) {
790
- return ids.map((id) => rowsById.get(id)).filter((row) => row !== void 0);
791
- }
792
- function resolveColumns(columns, ids) {
793
- return ids.map((id) => {
794
- const columnIndex = columns.findIndex((entry) => entry.id === id);
795
- const column = columns[columnIndex];
796
- return column === void 0 ? void 0 : { columnId: id, column, columnIndex };
797
- }).filter((column) => column !== void 0);
798
- }
799
- function resolveCell(rowsById, columns, cell) {
800
- if (cell === null) {
801
- return null;
802
- }
803
- const entry = rowsById.get(cell.rowId);
804
- const columnIndex = columns.findIndex(
805
- (candidate) => candidate.id === cell.columnId
806
- );
807
- const column = columns[columnIndex];
808
- if (entry === void 0 || column === void 0) {
809
- return null;
810
- }
811
- return {
812
- rowId: cell.rowId,
813
- columnId: cell.columnId,
814
- row: entry.row,
815
- column,
816
- rowIndex: entry.rowIndex,
817
- columnIndex,
818
- value: accessDotted(entry.row, column.column.field)
819
- };
820
- }
821
-
822
- // src/util/pinning.ts
823
- function resolveColumnPin(column, pinning) {
824
- return pinning[getColumnId(column)] ?? column.pinned ?? "none";
825
- }
826
- function partitionPinnedColumns(columns, pinning) {
827
- const parts = {
828
- start: [],
829
- none: [],
830
- end: []
831
- };
832
- for (const entry of columns) {
833
- parts[resolveColumnPin(entry.column, pinning)].push(entry);
834
- }
835
- return { start: parts.start, unpinned: parts.none, end: parts.end };
836
- }
837
- function applyColumnPinning(columns, pinning) {
838
- const { start, unpinned, end } = partitionPinnedColumns(columns, pinning);
839
- const ordered = [...start, ...unpinned, ...end];
840
- return ordered.every((entry, index) => entry === columns[index]) ? columns : ordered;
841
- }
842
- function setColumnPin(columns, pinning, columnId, pin) {
843
- const entry = columns.find((candidate) => candidate.id === columnId);
844
- if (entry === void 0 || resolveColumnPin(entry.column, pinning) === pin) {
845
- return pinning;
846
- }
847
- return { ...pinning, [columnId]: pin };
848
- }
849
- function placePinnedColumns(columns) {
850
- const lastStart = columns.findLastIndex((entry) => entry.pinned === "start");
851
- const firstEnd = columns.findIndex((entry) => entry.pinned === "end");
852
- const startOffsets = widthsBefore(columns, "start");
853
- const endOffsets = widthsBefore(columns.toReversed(), "end").toReversed();
854
- return columns.map((entry, index) => {
855
- switch (entry.pinned) {
856
- case "start":
857
- return {
858
- ...entry,
859
- pinOffset: startOffsets[index] ?? 0,
860
- pinEdge: index === lastStart
861
- };
862
- case "end":
863
- return {
864
- ...entry,
865
- pinOffset: endOffsets[index] ?? 0,
866
- pinEdge: index === firstEnd
867
- };
868
- case "none":
869
- return { ...entry, pinOffset: 0, pinEdge: false };
870
- }
871
- });
872
- }
873
- function widthsBefore(columns, pin) {
874
- let sum = 0;
875
- return columns.map((entry) => {
876
- const before = sum;
877
- if (entry.pinned === pin) {
878
- sum += entry.width;
879
- }
880
- return before;
881
- });
882
- }
883
- function pinnedWidths(columns) {
884
- let start = 0;
885
- let end = 0;
886
- for (const entry of columns) {
887
- if (entry.pinned === "start") {
888
- start += entry.width;
889
- } else if (entry.pinned === "end") {
890
- end += entry.width;
891
- }
892
- }
893
- return { start, end };
894
- }
895
-
896
- // src/util/selection.ts
897
- var NO_CHANGE = { added: [], removed: [] };
898
- function sameSelection(a, b) {
899
- return a.length === b.length && a.every((id, index) => id === b[index]);
900
- }
901
- function toggleSelection(selection, id, mode) {
902
- if (mode === false) {
903
- return selection;
904
- }
905
- if (selection.includes(id)) {
906
- return selection.filter((selectedId) => selectedId !== id);
907
- }
908
- return mode === "single" ? [id] : [...selection, id];
909
- }
910
- function selectOnly(selection, id, mode) {
911
- if (mode === false) {
912
- return selection;
913
- }
914
- return selection.length === 1 && selection[0] === id ? selection : [id];
915
- }
916
- function selectRange(selection, orderedIds, anchorId, focusId, mode) {
917
- if (mode !== "multiple") {
918
- return selectOnly(selection, focusId, mode);
919
- }
920
- const anchor = orderedIds.indexOf(anchorId);
921
- const focus = orderedIds.indexOf(focusId);
922
- if (anchor === -1 || focus === -1) {
923
- return selection;
924
- }
925
- const next = orderedIds.slice(
926
- Math.min(anchor, focus),
927
- Math.max(anchor, focus) + 1
928
- );
929
- return sameSelection(selection, next) ? selection : next;
930
- }
931
- function selectAll(selection, orderedIds, mode) {
932
- if (mode !== "multiple") {
933
- return selection;
934
- }
935
- return sameSelection(selection, orderedIds) ? selection : orderedIds;
936
- }
937
- function clearSelection(selection) {
938
- return selection.length === 0 ? selection : [];
939
- }
940
- function diffSelection(previous, next) {
941
- if (previous === next) {
942
- return NO_CHANGE;
943
- }
944
- const before = new Set(previous);
945
- const after = new Set(next);
946
- return {
947
- added: next.filter((id) => !before.has(id)),
948
- removed: previous.filter((id) => !after.has(id))
949
- };
950
- }
951
- var NO_CELL_SELECTED = { kind: "none" };
952
- function isSameCell(a, b) {
953
- if (a.kind === "none" || b.kind === "none") {
954
- return a.kind === b.kind;
955
- }
956
- return a.rowId === b.rowId && a.columnId === b.columnId;
957
- }
958
- function holdsCell(selection, cell) {
959
- return selection.kind === "cell" && selection.rowId === cell.rowId && selection.columnId === cell.columnId;
960
- }
961
- function selectCell(selection, cell, mode) {
962
- if (mode === false || holdsCell(selection, cell)) {
963
- return selection;
964
- }
965
- return { kind: "cell", rowId: cell.rowId, columnId: cell.columnId };
966
- }
967
- function toggleCellSelection(selection, cell, mode) {
968
- if (mode === false) {
969
- return selection;
970
- }
971
- return holdsCell(selection, cell) ? NO_CELL_SELECTED : { kind: "cell", rowId: cell.rowId, columnId: cell.columnId };
972
- }
973
- function clearCellSelection(selection) {
974
- return selection.kind === "none" ? selection : NO_CELL_SELECTED;
975
- }
976
- function intentOf(event, options) {
977
- if (event.shiftKey) {
978
- return "range";
979
- }
980
- if (event.ctrlKey || event.metaKey) {
981
- return "toggle";
982
- }
983
- return options?.toggleOnClick === true ? "toggle" : "replace";
984
- }
985
- function applySelectionIntent(selection, orderedIds, anchorId, id, intent, mode) {
986
- switch (intent) {
987
- case "toggle":
988
- return toggleSelection(selection, id, mode);
989
- // A range with no anchor yet spans from the id to itself, which is the
990
- // plain click a first Shift-click may as well be.
991
- case "range":
992
- return selectRange(selection, orderedIds, anchorId ?? id, id, mode);
993
- default:
994
- return selectOnly(selection, id, mode);
995
- }
996
- }
997
-
998
955
  // src/util/sizing.ts
999
956
  var DEFAULT_COLUMN_SIZES = {
1000
957
  width: 150,
@@ -1313,6 +1270,49 @@ function withGroupAggregates(displayRows, flatRows, groupBy, specs, columns, dis
1313
1270
  return renumberRows(out);
1314
1271
  }
1315
1272
 
1273
+ // src/util/rows.ts
1274
+ function resolveShownRows(rows, filter, sort, columns) {
1275
+ return sortRows(filterRows(rows, filter, columns), sort, columns);
1276
+ }
1277
+ function unknownDisplayRow(entry) {
1278
+ const { kind } = entry;
1279
+ throw new TypeError(
1280
+ `GridKit: \`${String(kind)}\` is not a display row kind.`
1281
+ );
1282
+ }
1283
+ function resolveRows(rowsById, ids) {
1284
+ return ids.map((id) => rowsById.get(id)).filter((row) => row !== void 0);
1285
+ }
1286
+ function resolveColumns(columns, ids) {
1287
+ return ids.map((id) => {
1288
+ const columnIndex = columns.findIndex((entry) => entry.id === id);
1289
+ const column = columns[columnIndex];
1290
+ return column === void 0 ? void 0 : { columnId: id, column, columnIndex };
1291
+ }).filter((column) => column !== void 0);
1292
+ }
1293
+ function resolveCell(rowsById, columns, cell) {
1294
+ if (cell === null) {
1295
+ return null;
1296
+ }
1297
+ const entry = rowsById.get(cell.rowId);
1298
+ const columnIndex = columns.findIndex(
1299
+ (candidate) => candidate.id === cell.columnId
1300
+ );
1301
+ const column = columns[columnIndex];
1302
+ if (entry === void 0 || column === void 0) {
1303
+ return null;
1304
+ }
1305
+ return {
1306
+ rowId: cell.rowId,
1307
+ columnId: cell.columnId,
1308
+ row: entry.row,
1309
+ column,
1310
+ rowIndex: entry.rowIndex,
1311
+ columnIndex,
1312
+ value: accessDotted(entry.row, column.column.field)
1313
+ };
1314
+ }
1315
+
1316
1316
  // src/util/visibility.ts
1317
1317
  function isColumnVisible(column, visibility) {
1318
1318
  return visibility[getColumnId(column)] ?? column.hidden !== true;
@@ -2286,6 +2286,9 @@ function createDefaultMessages(locale) {
2286
2286
  pageButtonLabel: (page) => `Page ${n(page)}`,
2287
2287
  pageStatus: (page, pageCount) => `Page ${n(page)} of ${n(pageCount)}`,
2288
2288
  loadingMore: "Loading more\u2026",
2289
+ loading: "Loading\u2026",
2290
+ noRows: "No rows to show",
2291
+ noMatchingRows: "No rows match the current filter",
2289
2292
  booleanTrue: "true",
2290
2293
  booleanFalse: "false",
2291
2294
  blankGroupValue: "(blank)",
@@ -3475,20 +3478,6 @@ export {
3475
3478
  movesColumn,
3476
3479
  resolveDropBefore,
3477
3480
  resolveKeyboardDropTarget,
3478
- isDateType,
3479
- toDate,
3480
- isScalarList,
3481
- unknownFilterEntry,
3482
- matchesQuery,
3483
- filterQueryFor,
3484
- setColumnFilter,
3485
- clearAllFilters,
3486
- filterRows,
3487
- resolveShownRows,
3488
- unknownDisplayRow,
3489
- resolveRows,
3490
- resolveColumns,
3491
- resolveCell,
3492
3481
  resolveColumnPin,
3493
3482
  applyColumnPinning,
3494
3483
  setColumnPin,
@@ -3507,6 +3496,15 @@ export {
3507
3496
  clearCellSelection,
3508
3497
  intentOf,
3509
3498
  applySelectionIntent,
3499
+ isDateType,
3500
+ toDate,
3501
+ isScalarList,
3502
+ unknownFilterEntry,
3503
+ matchesQuery,
3504
+ filterQueryFor,
3505
+ setColumnFilter,
3506
+ clearAllFilters,
3507
+ filterRows,
3510
3508
  DEFAULT_COLUMN_SIZES,
3511
3509
  KEYBOARD_STEP,
3512
3510
  resolveColumnConstraints,
@@ -3520,6 +3518,11 @@ export {
3520
3518
  revertColumnSize,
3521
3519
  computeAggregates,
3522
3520
  withGroupAggregates,
3521
+ resolveShownRows,
3522
+ unknownDisplayRow,
3523
+ resolveRows,
3524
+ resolveColumns,
3525
+ resolveCell,
3523
3526
  isColumnVisible,
3524
3527
  applyColumnVisibility,
3525
3528
  setColumnVisibility,
@@ -3577,4 +3580,4 @@ export {
3577
3580
  clampFocus,
3578
3581
  nextFocusForKey
3579
3582
  };
3580
- //# sourceMappingURL=chunk-WLM4AZXN.js.map
3583
+ //# sourceMappingURL=chunk-RYMILPCT.js.map