@gridkitjs/core 0.0.0-dev-20261118115237 → 0.0.0-dev-20261118190822

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.
@@ -396,6 +396,34 @@ function moveColumnBefore(orderedIds, movedId, beforeId) {
396
396
  next.splice(target, 0, movedId);
397
397
  return next.every((id, index) => id === orderedIds[index]) ? orderedIds : next;
398
398
  }
399
+ var PIN_GROUP_RANK = {
400
+ start: 0,
401
+ none: 1,
402
+ end: 2
403
+ };
404
+ function moveColumnInPinGroup(orderedIds, pinOf, movedId, beforeId) {
405
+ if (beforeId !== null && !orderedIds.includes(beforeId)) {
406
+ return orderedIds;
407
+ }
408
+ const next = moveColumnBefore(
409
+ orderedIds,
410
+ movedId,
411
+ beforeIdInGroup(orderedIds, pinOf, pinOf(movedId), beforeId)
412
+ );
413
+ const grouped = (ids) => ids.toSorted((a, b) => PIN_GROUP_RANK[pinOf(a)] - PIN_GROUP_RANK[pinOf(b)]);
414
+ const before = grouped(orderedIds);
415
+ return grouped(next).every((id, index) => id === before[index]) ? orderedIds : next;
416
+ }
417
+ function beforeIdInGroup(orderedIds, pinOf, pin, beforeId) {
418
+ if (beforeId === null) {
419
+ return null;
420
+ }
421
+ const distance = PIN_GROUP_RANK[pinOf(beforeId)] - PIN_GROUP_RANK[pin];
422
+ if (distance === 0) {
423
+ return beforeId;
424
+ }
425
+ return distance > 0 ? null : orderedIds.find((id) => pinOf(id) === pin) ?? null;
426
+ }
399
427
  function movesColumn(orderedIds, movedId, beforeId) {
400
428
  return moveColumnBefore(orderedIds, movedId, beforeId) !== orderedIds;
401
429
  }
@@ -791,6 +819,80 @@ function resolveCell(rowsById, columns, cell) {
791
819
  };
792
820
  }
793
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
+
794
896
  // src/util/selection.ts
795
897
  var NO_CHANGE = { added: [], removed: [] };
796
898
  function sameSelection(a, b) {
@@ -915,7 +1017,8 @@ function clampColumnWidth(width, constraints) {
915
1017
  }
916
1018
  function resolveColumnWidths(columns, sizing, options) {
917
1019
  const resolved = withDefaults(options?.sizes);
918
- return columns.map((column) => {
1020
+ const pinning = options?.pinning ?? {};
1021
+ const sized = columns.map((column) => {
919
1022
  const id = getColumnId(column);
920
1023
  const stored = sizing[id];
921
1024
  return {
@@ -930,9 +1033,13 @@ function resolveColumnWidths(columns, sizing, options) {
930
1033
  resizable: column.resizable ?? options?.resizable ?? false,
931
1034
  reorderable: column.reorderable ?? options?.reorderable ?? false,
932
1035
  groupByDraggable: column.groupByDraggable ?? options?.groupByDraggable ?? false,
933
- alignment: column.alignment ?? alignmentForType(column.type ?? "string")
1036
+ alignment: column.alignment ?? alignmentForType(column.type ?? "string"),
1037
+ pinned: resolveColumnPin(column, pinning),
1038
+ pinOffset: 0,
1039
+ pinEdge: false
934
1040
  };
935
1041
  });
1042
+ return placePinnedColumns(sized);
936
1043
  }
937
1044
  function totalColumnWidth(resolved) {
938
1045
  return resolved.reduce((total, entry) => total + entry.width, 0);
@@ -1011,7 +1118,7 @@ function fitColumnsToWidth(resolved, availableWidth, defaults) {
1011
1118
  (item) => growing ? Math.floor(item.width) : Math.ceil(item.width)
1012
1119
  );
1013
1120
  let remainder = target - rounded.reduce((total2, width) => total2 + width, 0);
1014
- return entries.map((item, index) => {
1121
+ const fitted = entries.map((item, index) => {
1015
1122
  let width = rounded[index] ?? item.width;
1016
1123
  const hasRoom = growing ? width < item.bound : width > item.bound;
1017
1124
  if (remainder !== 0 && item.adjustable && hasRoom) {
@@ -1020,6 +1127,7 @@ function fitColumnsToWidth(resolved, availableWidth, defaults) {
1020
1127
  }
1021
1128
  return { ...item.entry, width };
1022
1129
  });
1130
+ return placePinnedColumns(fitted);
1023
1131
  }
1024
1132
  function sizeColumnToContent(measuredWidth, constraints, padding = 2) {
1025
1133
  return clampColumnWidth(Math.ceil(measuredWidth + padding), constraints);
@@ -2218,6 +2326,9 @@ function createDefaultMessages(locale) {
2218
2326
  expandAllGroups: "Expand all groups",
2219
2327
  collapseAllGroups: "Collapse all groups",
2220
2328
  hideColumn: "Hide column",
2329
+ pinToStart: "Pin to start",
2330
+ pinToEnd: "Pin to end",
2331
+ unpinColumn: "Unpin",
2221
2332
  autoFitColumn: "Autofit column",
2222
2333
  autoFitAllColumns: "Autofit all columns",
2223
2334
  selectAllRows: "Select all rows",
@@ -2746,6 +2857,19 @@ function copyCommand({
2746
2857
  }
2747
2858
  };
2748
2859
  }
2860
+ function pinCommand(id, pin, label) {
2861
+ return columnCommand({
2862
+ id,
2863
+ label: ({ messages }) => label(messages),
2864
+ find: (context) => {
2865
+ const column = columnOn(context, ["header"]);
2866
+ return column !== null && resolveColumnPin(column.column, context.state.columnPinning) !== pin ? column : null;
2867
+ },
2868
+ execute: (column, { actions }) => {
2869
+ actions.pinColumn(column.id, pin);
2870
+ }
2871
+ });
2872
+ }
2749
2873
  function sortCommand(direction) {
2750
2874
  return columnCommand({
2751
2875
  id: direction === "asc" ? "sort.ascending" : "sort.descending",
@@ -2838,6 +2962,9 @@ function builtInCommands() {
2838
2962
  actions.hideColumns([column.id]);
2839
2963
  }
2840
2964
  }),
2965
+ pinCommand("column.pinStart", "start", (messages) => messages.pinToStart),
2966
+ pinCommand("column.pinEnd", "end", (messages) => messages.pinToEnd),
2967
+ pinCommand("column.unpin", "none", (messages) => messages.unpinColumn),
2841
2968
  columnCommand({
2842
2969
  id: "column.autoFit",
2843
2970
  label: ({ messages }) => messages.autoFitColumn,
@@ -3140,7 +3267,11 @@ var defaultContextMenu = {
3140
3267
  "column.autoFitAll",
3141
3268
  "separator",
3142
3269
  "column.hide",
3143
- "column.choose"
3270
+ "column.choose",
3271
+ "separator",
3272
+ "column.pinStart",
3273
+ "column.pinEnd",
3274
+ "column.unpin"
3144
3275
  ],
3145
3276
  cell: [
3146
3277
  "copy.cell",
@@ -3338,6 +3469,7 @@ export {
3338
3469
  applyColumnOrder,
3339
3470
  resolveDataColumns,
3340
3471
  moveColumnBefore,
3472
+ moveColumnInPinGroup,
3341
3473
  movesColumn,
3342
3474
  resolveDropBefore,
3343
3475
  resolveKeyboardDropTarget,
@@ -3355,6 +3487,10 @@ export {
3355
3487
  resolveRows,
3356
3488
  resolveColumns,
3357
3489
  resolveCell,
3490
+ resolveColumnPin,
3491
+ applyColumnPinning,
3492
+ setColumnPin,
3493
+ pinnedWidths,
3358
3494
  reportError,
3359
3495
  toggleSelection,
3360
3496
  selectOnly,
@@ -3439,4 +3575,4 @@ export {
3439
3575
  clampFocus,
3440
3576
  nextFocusForKey
3441
3577
  };
3442
- //# sourceMappingURL=chunk-PUD53NFG.js.map
3578
+ //# sourceMappingURL=chunk-ZFWEGZX3.js.map