@gridkitjs/core 0.18.0 → 0.19.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
@@ -7,6 +7,7 @@ import {
7
7
  accessDotted,
8
8
  alignmentForType,
9
9
  applyColumnOrder,
10
+ applyColumnPinning,
10
11
  applyColumnVisibility,
11
12
  applySelectionIntent,
12
13
  bodyFocus,
@@ -49,11 +50,13 @@ import {
49
50
  jsonWriter,
50
51
  matchesQuery,
51
52
  moveColumnBefore,
53
+ moveColumnInPinGroup,
52
54
  moveGroupByBefore,
53
55
  reportError,
54
56
  resolveCell,
55
57
  resolveColumnHeaderText,
56
58
  resolveColumnLabel,
59
+ resolveColumnPin,
57
60
  resolveColumnWidths,
58
61
  resolveColumns,
59
62
  resolveCommands,
@@ -72,6 +75,7 @@ import {
72
75
  selectOnly,
73
76
  selectRange,
74
77
  setColumnFilter,
78
+ setColumnPin,
75
79
  setColumnVisibility,
76
80
  sortDirectionFor,
77
81
  sortPriorityFor,
@@ -88,7 +92,7 @@ import {
88
92
  unknownDisplayRow,
89
93
  unknownFilterEntry,
90
94
  withGroupAggregates
91
- } from "./chunk-QGKPKQIO.js";
95
+ } from "./chunk-WLM4AZXN.js";
92
96
 
93
97
  // src/util/memoize.ts
94
98
  function memoizeLast(compute) {
@@ -352,6 +356,7 @@ var STARTING_VIEW_STATE = {
352
356
  columnSizing: {},
353
357
  columnOrder: [],
354
358
  columnVisibility: {},
359
+ columnPinning: {},
355
360
  columnSort: [],
356
361
  filter: [],
357
362
  groupBy: [],
@@ -363,6 +368,7 @@ function fillViewState(state) {
363
368
  columnSizing: state.columnSizing ?? STARTING_VIEW_STATE.columnSizing,
364
369
  columnOrder: state.columnOrder ?? STARTING_VIEW_STATE.columnOrder,
365
370
  columnVisibility: state.columnVisibility ?? STARTING_VIEW_STATE.columnVisibility,
371
+ columnPinning: state.columnPinning ?? STARTING_VIEW_STATE.columnPinning,
366
372
  columnSort: state.columnSort ?? STARTING_VIEW_STATE.columnSort,
367
373
  filter: state.filter ?? STARTING_VIEW_STATE.filter,
368
374
  groupBy: state.groupBy ?? STARTING_VIEW_STATE.groupBy,
@@ -379,11 +385,11 @@ function identifyRows(rows, getRowId) {
379
385
  datasetIndex: rowIndex
380
386
  }));
381
387
  }
382
- function sizeColumns(visibleColumns, sizing, sizes, resizable, reorderable, groupByDraggable, resizeMode, viewportWidth) {
388
+ function sizeColumns(visibleColumns, sizing, pinning, sizes, resizable, reorderable, groupByDraggable, resizeMode, viewportWidth) {
383
389
  const widths = resolveColumnWidths(
384
390
  visibleColumns.map((entry) => entry.column),
385
391
  sizing,
386
- { sizes, resizable, reorderable, groupByDraggable }
392
+ { sizes, resizable, reorderable, groupByDraggable, pinning }
387
393
  );
388
394
  return resizeMode === "fit" && viewportWidth !== null ? fitColumnsToWidth(widths, viewportWidth, sizes) : widths;
389
395
  }
@@ -406,6 +412,7 @@ function createGridViewResolver() {
406
412
  const identify = memoizeLast(identifyRows);
407
413
  const orderColumns = memoizeLast(resolveDataColumns);
408
414
  const showColumns = memoizeLast(applyColumnVisibility);
415
+ const pinColumns = memoizeLast(applyColumnPinning);
409
416
  const size = memoizeLast(sizeColumns);
410
417
  const filterAndSort = memoizeLast(resolveShownRows);
411
418
  const group = memoizeLast(groupRows);
@@ -438,8 +445,12 @@ function createGridViewResolver() {
438
445
  const aggregates = options.aggregates ?? NO_AGGREGATES;
439
446
  const dataColumns = orderColumns(definitions, state.columnOrder);
440
447
  const columns = size(
441
- showColumns(dataColumns, state.columnVisibility),
448
+ pinColumns(
449
+ showColumns(dataColumns, state.columnVisibility),
450
+ state.columnPinning
451
+ ),
442
452
  state.columnSizing,
453
+ state.columnPinning,
443
454
  options.columnSizeDefaults,
444
455
  options.resizableColumns,
445
456
  options.reorderableColumns,
@@ -793,6 +804,7 @@ var SLICE_KEYS = [
793
804
  "columnSizing",
794
805
  "columnOrder",
795
806
  "columnVisibility",
807
+ "columnPinning",
796
808
  "columnSort",
797
809
  "filter",
798
810
  "groupBy",
@@ -806,6 +818,7 @@ var DEFAULT_OPTION = {
806
818
  columnSizing: "defaultColumnSizing",
807
819
  columnOrder: "defaultColumnOrder",
808
820
  columnVisibility: "defaultColumnVisibility",
821
+ columnPinning: "defaultColumnPinning",
809
822
  columnSort: "defaultColumnSort",
810
823
  filter: "defaultFilter",
811
824
  groupBy: "defaultGroupBy",
@@ -820,6 +833,7 @@ function startingState(options) {
820
833
  columnSizing: options.defaultColumnSizing ?? STARTING_VIEW_STATE.columnSizing,
821
834
  columnOrder: options.defaultColumnOrder ?? STARTING_VIEW_STATE.columnOrder,
822
835
  columnVisibility: options.defaultColumnVisibility ?? STARTING_VIEW_STATE.columnVisibility,
836
+ columnPinning: options.defaultColumnPinning ?? STARTING_VIEW_STATE.columnPinning,
823
837
  columnSort: options.defaultColumnSort ?? STARTING_VIEW_STATE.columnSort,
824
838
  filter: options.defaultFilter ?? STARTING_VIEW_STATE.filter,
825
839
  groupBy: options.defaultGroupBy ?? STARTING_VIEW_STATE.groupBy,
@@ -878,6 +892,7 @@ function createGridController(initial) {
878
892
  columnSizing: resolveSlice("columnSizing"),
879
893
  columnOrder: resolveSlice("columnOrder"),
880
894
  columnVisibility: resolveSlice("columnVisibility"),
895
+ columnPinning: resolveSlice("columnPinning"),
881
896
  columnSort: resolveSlice("columnSort"),
882
897
  filter: resolveSlice("filter"),
883
898
  groupBy: resolveSlice("groupBy"),
@@ -1017,13 +1032,16 @@ function createGridController(initial) {
1017
1032
  );
1018
1033
  return resolved?.width ?? 0;
1019
1034
  }
1035
+ function changedColumnIds(previous, next) {
1036
+ const changed = new Set(changedKeys(previous, next));
1037
+ const known = getView().dataColumns.map((entry) => entry.id).filter((id) => changed.delete(id));
1038
+ return [...known, ...changed];
1039
+ }
1020
1040
  function commitColumnVisibility(next) {
1021
1041
  const previous = state.columnVisibility;
1022
1042
  commit("columnVisibility", next, () => {
1023
- const changed = new Set(changedKeys(previous, next));
1024
- const shown = getView().dataColumns.map((entry) => entry.id).filter((id) => changed.delete(id));
1025
1043
  options.onColumnVisibilityChange?.({
1026
- columnIds: [...shown, ...changed],
1044
+ columnIds: changedColumnIds(previous, next),
1027
1045
  visibility: next
1028
1046
  });
1029
1047
  });
@@ -1038,6 +1056,15 @@ function createGridController(initial) {
1038
1056
  )
1039
1057
  );
1040
1058
  }
1059
+ function commitColumnPinning(next) {
1060
+ const previous = state.columnPinning;
1061
+ commit("columnPinning", next, () => {
1062
+ options.onColumnPinningChange?.({
1063
+ columnIds: changedColumnIds(previous, next),
1064
+ pinning: next
1065
+ });
1066
+ });
1067
+ }
1041
1068
  function commitGroupBy(next, columnId) {
1042
1069
  commit("groupBy", next, () => {
1043
1070
  options.onGroupByChange?.({ columnId, groupBy: next });
@@ -1145,13 +1172,25 @@ function createGridController(initial) {
1145
1172
  });
1146
1173
  },
1147
1174
  /**
1148
- * Applied to every id in display order rather than to the stored order,
1175
+ * Applied to every id in column order rather than to the stored order,
1149
1176
  * which starts empty and may name only some columns, so would have
1150
1177
  * nothing to rearrange.
1151
1178
  */
1152
1179
  moveColumn(columnId, beforeId) {
1153
- const orderedIds = getView().dataColumns.map((entry) => entry.id);
1154
- const next = moveColumnBefore(orderedIds, columnId, beforeId);
1180
+ const { dataColumns } = getView();
1181
+ const orderedIds = dataColumns.map((entry) => entry.id);
1182
+ const pins = new Map(
1183
+ dataColumns.map((entry) => [
1184
+ entry.id,
1185
+ resolveColumnPin(entry.column, state.columnPinning)
1186
+ ])
1187
+ );
1188
+ const next = moveColumnInPinGroup(
1189
+ orderedIds,
1190
+ (id) => pins.get(id) ?? "none",
1191
+ columnId,
1192
+ beforeId
1193
+ );
1155
1194
  if (next === orderedIds) {
1156
1195
  return;
1157
1196
  }
@@ -1170,6 +1209,16 @@ function createGridController(initial) {
1170
1209
  hideColumns(columnIds) {
1171
1210
  changeColumnVisibility(columnIds, false);
1172
1211
  },
1212
+ setColumnPinning(pinning) {
1213
+ if (changedKeys(state.columnPinning, pinning).length > 0) {
1214
+ commitColumnPinning(pinning);
1215
+ }
1216
+ },
1217
+ pinColumn(columnId, pin) {
1218
+ commitColumnPinning(
1219
+ setColumnPin(getView().dataColumns, state.columnPinning, columnId, pin)
1220
+ );
1221
+ },
1173
1222
  setFilter(filter) {
1174
1223
  if (sameFilter(state.filter, filter)) {
1175
1224
  return;
@@ -1268,6 +1317,9 @@ function createGridController(initial) {
1268
1317
  if (saved.columnVisibility !== void 0) {
1269
1318
  controller.setColumnVisibility(saved.columnVisibility);
1270
1319
  }
1320
+ if (saved.columnPinning !== void 0) {
1321
+ controller.setColumnPinning(saved.columnPinning);
1322
+ }
1271
1323
  if (saved.columnSort !== void 0) {
1272
1324
  controller.setColumnSort(saved.columnSort);
1273
1325
  }
@@ -1415,6 +1467,7 @@ export {
1415
1467
  accessDotted,
1416
1468
  alignmentForType,
1417
1469
  applyColumnOrder,
1470
+ applyColumnPinning,
1418
1471
  applyColumnVisibility,
1419
1472
  applySelectionIntent,
1420
1473
  bodyFocus,
@@ -1461,6 +1514,7 @@ export {
1461
1514
  resolveCell,
1462
1515
  resolveColumnHeaderText,
1463
1516
  resolveColumnLabel,
1517
+ resolveColumnPin,
1464
1518
  resolveColumnWidths,
1465
1519
  resolveColumns,
1466
1520
  resolveCommands,
@@ -1480,6 +1534,7 @@ export {
1480
1534
  selectRange,
1481
1535
  serializeGridState,
1482
1536
  setColumnFilter,
1537
+ setColumnPin,
1483
1538
  setColumnVisibility,
1484
1539
  sortDirectionFor,
1485
1540
  sortPriorityFor,