@gridkitjs/core 0.0.0-dev-20261118134132 → 0.0.0-dev-20261118204728

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);
@@ -2204,6 +2312,8 @@ function createDefaultMessages(locale) {
2204
2312
  columnShown: (columnName2) => `${columnName2}, column shown`,
2205
2313
  columnsHidden: (count) => columnCount(n, count, "hidden"),
2206
2314
  columnsShown: (count) => columnCount(n, count, "shown"),
2315
+ columnPinned: (columnName2, edge) => `${columnName2}, pinned to ${edge}`,
2316
+ columnUnpinned: (columnName2) => `${columnName2}, unpinned`,
2207
2317
  columnsAutoFitted: (count) => columnCount(n, count, "autofitted"),
2208
2318
  headerMenuLabel: (columnName2) => `${columnName2} column menu`,
2209
2319
  cellMenuLabel: "Row menu",
@@ -2218,6 +2328,9 @@ function createDefaultMessages(locale) {
2218
2328
  expandAllGroups: "Expand all groups",
2219
2329
  collapseAllGroups: "Collapse all groups",
2220
2330
  hideColumn: "Hide column",
2331
+ pinToStart: "Pin to start",
2332
+ pinToEnd: "Pin to end",
2333
+ unpinColumn: "Unpin",
2221
2334
  autoFitColumn: "Autofit column",
2222
2335
  autoFitAllColumns: "Autofit all columns",
2223
2336
  selectAllRows: "Select all rows",
@@ -2746,6 +2859,19 @@ function copyCommand({
2746
2859
  }
2747
2860
  };
2748
2861
  }
2862
+ function pinCommand(id, pin, label) {
2863
+ return columnCommand({
2864
+ id,
2865
+ label: ({ messages }) => label(messages),
2866
+ find: (context) => {
2867
+ const column = columnOn(context, ["header"]);
2868
+ return column !== null && resolveColumnPin(column.column, context.state.columnPinning) !== pin ? column : null;
2869
+ },
2870
+ execute: (column, { actions }) => {
2871
+ actions.pinColumn(column.id, pin);
2872
+ }
2873
+ });
2874
+ }
2749
2875
  function sortCommand(direction) {
2750
2876
  return columnCommand({
2751
2877
  id: direction === "asc" ? "sort.ascending" : "sort.descending",
@@ -2838,6 +2964,9 @@ function builtInCommands() {
2838
2964
  actions.hideColumns([column.id]);
2839
2965
  }
2840
2966
  }),
2967
+ pinCommand("column.pinStart", "start", (messages) => messages.pinToStart),
2968
+ pinCommand("column.pinEnd", "end", (messages) => messages.pinToEnd),
2969
+ pinCommand("column.unpin", "none", (messages) => messages.unpinColumn),
2841
2970
  columnCommand({
2842
2971
  id: "column.autoFit",
2843
2972
  label: ({ messages }) => messages.autoFitColumn,
@@ -3140,7 +3269,11 @@ var defaultContextMenu = {
3140
3269
  "column.autoFitAll",
3141
3270
  "separator",
3142
3271
  "column.hide",
3143
- "column.choose"
3272
+ "column.choose",
3273
+ "separator",
3274
+ "column.pinStart",
3275
+ "column.pinEnd",
3276
+ "column.unpin"
3144
3277
  ],
3145
3278
  cell: [
3146
3279
  "copy.cell",
@@ -3338,6 +3471,7 @@ export {
3338
3471
  applyColumnOrder,
3339
3472
  resolveDataColumns,
3340
3473
  moveColumnBefore,
3474
+ moveColumnInPinGroup,
3341
3475
  movesColumn,
3342
3476
  resolveDropBefore,
3343
3477
  resolveKeyboardDropTarget,
@@ -3355,6 +3489,10 @@ export {
3355
3489
  resolveRows,
3356
3490
  resolveColumns,
3357
3491
  resolveCell,
3492
+ resolveColumnPin,
3493
+ applyColumnPinning,
3494
+ setColumnPin,
3495
+ pinnedWidths,
3358
3496
  reportError,
3359
3497
  toggleSelection,
3360
3498
  selectOnly,
@@ -3439,4 +3577,4 @@ export {
3439
3577
  clampFocus,
3440
3578
  nextFocusForKey
3441
3579
  };
3442
- //# sourceMappingURL=chunk-PUD53NFG.js.map
3580
+ //# sourceMappingURL=chunk-WLM4AZXN.js.map