@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/{chunk-QGKPKQIO.js → chunk-WLM4AZXN.js} +175 -16
- package/dist/chunk-WLM4AZXN.js.map +1 -0
- package/dist/{filterEditor-B7C_n89V.d.ts → filterEditor-C4x0X-nh.d.ts} +202 -19
- package/dist/index.d.ts +4 -4
- package/dist/index.js +65 -10
- package/dist/index.js.map +1 -1
- package/dist/renderer.d.ts +2 -2
- package/dist/renderer.js +7 -1
- package/dist/renderer.js.map +1 -1
- package/package.json +1 -1
- package/dist/chunk-QGKPKQIO.js.map +0 -1
|
@@ -259,10 +259,16 @@ function partitionByValue(rows, column, direction) {
|
|
|
259
259
|
});
|
|
260
260
|
return groups;
|
|
261
261
|
}
|
|
262
|
+
function withGroupPosition(rows, depth) {
|
|
263
|
+
return rows.map((row, index) => ({
|
|
264
|
+
...row,
|
|
265
|
+
groupPosition: { level: depth, position: index + 1, setSize: rows.length }
|
|
266
|
+
}));
|
|
267
|
+
}
|
|
262
268
|
function buildLevel(rows, levels, parentPath, expansion, byId, out) {
|
|
263
269
|
const level = levels[0];
|
|
264
270
|
if (level === void 0) {
|
|
265
|
-
out.push(...rows);
|
|
271
|
+
out.push(...withGroupPosition(rows, parentPath.length));
|
|
266
272
|
return;
|
|
267
273
|
}
|
|
268
274
|
const column = byId.get(level.columnId);
|
|
@@ -272,7 +278,7 @@ function buildLevel(rows, levels, parentPath, expansion, byId, out) {
|
|
|
272
278
|
}
|
|
273
279
|
const rest = levels.slice(1);
|
|
274
280
|
const groups = partitionByValue(rows, column, level.direction ?? "asc");
|
|
275
|
-
for (const group of groups) {
|
|
281
|
+
for (const [index, group] of groups.entries()) {
|
|
276
282
|
const path = [...parentPath, group.value];
|
|
277
283
|
const groupId = groupRowId(path);
|
|
278
284
|
const expanded = isGroupExpanded(expansion, groupId);
|
|
@@ -285,6 +291,8 @@ function buildLevel(rows, levels, parentPath, expansion, byId, out) {
|
|
|
285
291
|
path,
|
|
286
292
|
expanded,
|
|
287
293
|
count: group.rows.length,
|
|
294
|
+
position: index + 1,
|
|
295
|
+
setSize: groups.length,
|
|
288
296
|
// Both set by `groupRows` once it has the whole flattened array.
|
|
289
297
|
rowIndex: -1,
|
|
290
298
|
datasetIndex: -1,
|
|
@@ -388,6 +396,34 @@ function moveColumnBefore(orderedIds, movedId, beforeId) {
|
|
|
388
396
|
next.splice(target, 0, movedId);
|
|
389
397
|
return next.every((id, index) => id === orderedIds[index]) ? orderedIds : next;
|
|
390
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
|
+
}
|
|
391
427
|
function movesColumn(orderedIds, movedId, beforeId) {
|
|
392
428
|
return moveColumnBefore(orderedIds, movedId, beforeId) !== orderedIds;
|
|
393
429
|
}
|
|
@@ -783,6 +819,80 @@ function resolveCell(rowsById, columns, cell) {
|
|
|
783
819
|
};
|
|
784
820
|
}
|
|
785
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
|
+
|
|
786
896
|
// src/util/selection.ts
|
|
787
897
|
var NO_CHANGE = { added: [], removed: [] };
|
|
788
898
|
function sameSelection(a, b) {
|
|
@@ -907,7 +1017,8 @@ function clampColumnWidth(width, constraints) {
|
|
|
907
1017
|
}
|
|
908
1018
|
function resolveColumnWidths(columns, sizing, options) {
|
|
909
1019
|
const resolved = withDefaults(options?.sizes);
|
|
910
|
-
|
|
1020
|
+
const pinning = options?.pinning ?? {};
|
|
1021
|
+
const sized = columns.map((column) => {
|
|
911
1022
|
const id = getColumnId(column);
|
|
912
1023
|
const stored = sizing[id];
|
|
913
1024
|
return {
|
|
@@ -922,9 +1033,13 @@ function resolveColumnWidths(columns, sizing, options) {
|
|
|
922
1033
|
resizable: column.resizable ?? options?.resizable ?? false,
|
|
923
1034
|
reorderable: column.reorderable ?? options?.reorderable ?? false,
|
|
924
1035
|
groupByDraggable: column.groupByDraggable ?? options?.groupByDraggable ?? false,
|
|
925
|
-
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
|
|
926
1040
|
};
|
|
927
1041
|
});
|
|
1042
|
+
return placePinnedColumns(sized);
|
|
928
1043
|
}
|
|
929
1044
|
function totalColumnWidth(resolved) {
|
|
930
1045
|
return resolved.reduce((total, entry) => total + entry.width, 0);
|
|
@@ -937,9 +1052,10 @@ function beginColumnResize(column, startWidth, startPosition, defaults) {
|
|
|
937
1052
|
constraints: resolveColumnConstraints(column, defaults)
|
|
938
1053
|
};
|
|
939
1054
|
}
|
|
940
|
-
function applyColumnResize(session, position) {
|
|
1055
|
+
function applyColumnResize(session, position, direction = "ltr") {
|
|
1056
|
+
const moved = position - session.startPosition;
|
|
941
1057
|
return clampColumnWidth(
|
|
942
|
-
session.startWidth + (
|
|
1058
|
+
session.startWidth + (direction === "rtl" ? -moved : moved),
|
|
943
1059
|
session.constraints
|
|
944
1060
|
);
|
|
945
1061
|
}
|
|
@@ -1002,7 +1118,7 @@ function fitColumnsToWidth(resolved, availableWidth, defaults) {
|
|
|
1002
1118
|
(item) => growing ? Math.floor(item.width) : Math.ceil(item.width)
|
|
1003
1119
|
);
|
|
1004
1120
|
let remainder = target - rounded.reduce((total2, width) => total2 + width, 0);
|
|
1005
|
-
|
|
1121
|
+
const fitted = entries.map((item, index) => {
|
|
1006
1122
|
let width = rounded[index] ?? item.width;
|
|
1007
1123
|
const hasRoom = growing ? width < item.bound : width > item.bound;
|
|
1008
1124
|
if (remainder !== 0 && item.adjustable && hasRoom) {
|
|
@@ -1011,6 +1127,7 @@ function fitColumnsToWidth(resolved, availableWidth, defaults) {
|
|
|
1011
1127
|
}
|
|
1012
1128
|
return { ...item.entry, width };
|
|
1013
1129
|
});
|
|
1130
|
+
return placePinnedColumns(fitted);
|
|
1014
1131
|
}
|
|
1015
1132
|
function sizeColumnToContent(measuredWidth, constraints, padding = 2) {
|
|
1016
1133
|
return clampColumnWidth(Math.ceil(measuredWidth + padding), constraints);
|
|
@@ -2195,6 +2312,8 @@ function createDefaultMessages(locale) {
|
|
|
2195
2312
|
columnShown: (columnName2) => `${columnName2}, column shown`,
|
|
2196
2313
|
columnsHidden: (count) => columnCount(n, count, "hidden"),
|
|
2197
2314
|
columnsShown: (count) => columnCount(n, count, "shown"),
|
|
2315
|
+
columnPinned: (columnName2, edge) => `${columnName2}, pinned to ${edge}`,
|
|
2316
|
+
columnUnpinned: (columnName2) => `${columnName2}, unpinned`,
|
|
2198
2317
|
columnsAutoFitted: (count) => columnCount(n, count, "autofitted"),
|
|
2199
2318
|
headerMenuLabel: (columnName2) => `${columnName2} column menu`,
|
|
2200
2319
|
cellMenuLabel: "Row menu",
|
|
@@ -2209,6 +2328,9 @@ function createDefaultMessages(locale) {
|
|
|
2209
2328
|
expandAllGroups: "Expand all groups",
|
|
2210
2329
|
collapseAllGroups: "Collapse all groups",
|
|
2211
2330
|
hideColumn: "Hide column",
|
|
2331
|
+
pinToStart: "Pin to start",
|
|
2332
|
+
pinToEnd: "Pin to end",
|
|
2333
|
+
unpinColumn: "Unpin",
|
|
2212
2334
|
autoFitColumn: "Autofit column",
|
|
2213
2335
|
autoFitAllColumns: "Autofit all columns",
|
|
2214
2336
|
selectAllRows: "Select all rows",
|
|
@@ -2737,6 +2859,19 @@ function copyCommand({
|
|
|
2737
2859
|
}
|
|
2738
2860
|
};
|
|
2739
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
|
+
}
|
|
2740
2875
|
function sortCommand(direction) {
|
|
2741
2876
|
return columnCommand({
|
|
2742
2877
|
id: direction === "asc" ? "sort.ascending" : "sort.descending",
|
|
@@ -2829,6 +2964,9 @@ function builtInCommands() {
|
|
|
2829
2964
|
actions.hideColumns([column.id]);
|
|
2830
2965
|
}
|
|
2831
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),
|
|
2832
2970
|
columnCommand({
|
|
2833
2971
|
id: "column.autoFit",
|
|
2834
2972
|
label: ({ messages }) => messages.autoFitColumn,
|
|
@@ -3131,7 +3269,11 @@ var defaultContextMenu = {
|
|
|
3131
3269
|
"column.autoFitAll",
|
|
3132
3270
|
"separator",
|
|
3133
3271
|
"column.hide",
|
|
3134
|
-
"column.choose"
|
|
3272
|
+
"column.choose",
|
|
3273
|
+
"separator",
|
|
3274
|
+
"column.pinStart",
|
|
3275
|
+
"column.pinEnd",
|
|
3276
|
+
"column.unpin"
|
|
3135
3277
|
],
|
|
3136
3278
|
cell: [
|
|
3137
3279
|
"copy.cell",
|
|
@@ -3196,6 +3338,19 @@ function contextMenuEntries(contextMenu, context) {
|
|
|
3196
3338
|
}
|
|
3197
3339
|
}
|
|
3198
3340
|
|
|
3341
|
+
// src/util/direction.ts
|
|
3342
|
+
function inlineStep(key, direction = "ltr") {
|
|
3343
|
+
const forward = direction === "rtl" ? "ArrowLeft" : "ArrowRight";
|
|
3344
|
+
const backward = direction === "rtl" ? "ArrowRight" : "ArrowLeft";
|
|
3345
|
+
if (key === forward) {
|
|
3346
|
+
return 1;
|
|
3347
|
+
}
|
|
3348
|
+
if (key === backward) {
|
|
3349
|
+
return -1;
|
|
3350
|
+
}
|
|
3351
|
+
return null;
|
|
3352
|
+
}
|
|
3353
|
+
|
|
3199
3354
|
// src/util/navigation.ts
|
|
3200
3355
|
function headerFocus(columnIndex) {
|
|
3201
3356
|
return { area: "header", columnIndex };
|
|
@@ -3243,7 +3398,7 @@ function skipSkippableRows(target, direction, rowCount, isSkippableRow, fallback
|
|
|
3243
3398
|
}
|
|
3244
3399
|
return bodyFocus(rowIndex, target.columnIndex);
|
|
3245
3400
|
}
|
|
3246
|
-
function nextFocusForKey(key, modifiers, focus, rowCount, columnCount2, pageSize, isSkippableRow = noRowsSkippable) {
|
|
3401
|
+
function nextFocusForKey(key, modifiers, focus, rowCount, columnCount2, pageSize, isSkippableRow = noRowsSkippable, direction = "ltr") {
|
|
3247
3402
|
if (modifiers.altKey) {
|
|
3248
3403
|
return null;
|
|
3249
3404
|
}
|
|
@@ -3257,13 +3412,11 @@ function nextFocusForKey(key, modifiers, focus, rowCount, columnCount2, pageSize
|
|
|
3257
3412
|
focus
|
|
3258
3413
|
);
|
|
3259
3414
|
}
|
|
3415
|
+
const step = inlineStep(key, direction);
|
|
3416
|
+
if (step !== null) {
|
|
3417
|
+
return modifiers.ctrlKey ? null : { ...focus, columnIndex: columnIndex + step };
|
|
3418
|
+
}
|
|
3260
3419
|
switch (key) {
|
|
3261
|
-
case "ArrowLeft":
|
|
3262
|
-
if (modifiers.ctrlKey) return null;
|
|
3263
|
-
return { ...focus, columnIndex: columnIndex - 1 };
|
|
3264
|
-
case "ArrowRight":
|
|
3265
|
-
if (modifiers.ctrlKey) return null;
|
|
3266
|
-
return { ...focus, columnIndex: columnIndex + 1 };
|
|
3267
3420
|
case "ArrowUp":
|
|
3268
3421
|
return moveRows(-1);
|
|
3269
3422
|
case "ArrowDown":
|
|
@@ -3318,6 +3471,7 @@ export {
|
|
|
3318
3471
|
applyColumnOrder,
|
|
3319
3472
|
resolveDataColumns,
|
|
3320
3473
|
moveColumnBefore,
|
|
3474
|
+
moveColumnInPinGroup,
|
|
3321
3475
|
movesColumn,
|
|
3322
3476
|
resolveDropBefore,
|
|
3323
3477
|
resolveKeyboardDropTarget,
|
|
@@ -3335,6 +3489,10 @@ export {
|
|
|
3335
3489
|
resolveRows,
|
|
3336
3490
|
resolveColumns,
|
|
3337
3491
|
resolveCell,
|
|
3492
|
+
resolveColumnPin,
|
|
3493
|
+
applyColumnPinning,
|
|
3494
|
+
setColumnPin,
|
|
3495
|
+
pinnedWidths,
|
|
3338
3496
|
reportError,
|
|
3339
3497
|
toggleSelection,
|
|
3340
3498
|
selectOnly,
|
|
@@ -3413,9 +3571,10 @@ export {
|
|
|
3413
3571
|
defaultContextMenu,
|
|
3414
3572
|
hasContextMenu,
|
|
3415
3573
|
contextMenuEntries,
|
|
3574
|
+
inlineStep,
|
|
3416
3575
|
headerFocus,
|
|
3417
3576
|
bodyFocus,
|
|
3418
3577
|
clampFocus,
|
|
3419
3578
|
nextFocusForKey
|
|
3420
3579
|
};
|
|
3421
|
-
//# sourceMappingURL=chunk-
|
|
3580
|
+
//# sourceMappingURL=chunk-WLM4AZXN.js.map
|