@gridkitjs/core 0.15.0 → 0.17.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
@@ -275,7 +275,7 @@ function buildLevel(rows, levels, parentPath, expansion, byId, out) {
275
275
  for (const group of groups) {
276
276
  const path = [...parentPath, group.value];
277
277
  const groupId = groupRowId(path);
278
- const expanded = !expansion.includes(groupId);
278
+ const expanded = isGroupExpanded(expansion, groupId);
279
279
  const header = {
280
280
  kind: "group",
281
281
  groupId,
@@ -311,16 +311,30 @@ function groupRows(rows, groupBy, expansion, columns) {
311
311
  buildLevel(rows, active, [], expansion, byId, out);
312
312
  return renumberRows(out);
313
313
  }
314
+ var ALL_EXPANDED = {
315
+ mode: "allExpanded",
316
+ except: []
317
+ };
318
+ var ALL_COLLAPSED = {
319
+ mode: "allCollapsed",
320
+ except: []
321
+ };
322
+ function isGroupExpanded(expansion, groupId) {
323
+ const excepted = expansion.except.includes(groupId);
324
+ return expansion.mode === "allExpanded" ? !excepted : excepted;
325
+ }
314
326
  function toggleGroupExpansion(expansion, groupId) {
315
- return expansion.includes(groupId) ? expansion.filter((id) => id !== groupId) : [...expansion, groupId];
327
+ const except = expansion.except.includes(groupId) ? expansion.except.filter((id) => id !== groupId) : [...expansion.except, groupId];
328
+ return { mode: expansion.mode, except };
316
329
  }
317
330
  function expandAllGroups(expansion) {
318
- return expansion.length === 0 ? expansion : [];
331
+ return isWithoutExceptions(expansion, "allExpanded") ? expansion : ALL_EXPANDED;
332
+ }
333
+ function collapseAllGroups(expansion) {
334
+ return isWithoutExceptions(expansion, "allCollapsed") ? expansion : ALL_COLLAPSED;
319
335
  }
320
- function collapseAllGroups(rows) {
321
- return rows.filter(
322
- (entry) => "kind" in entry && entry.kind === "group"
323
- ).map((entry) => entry.groupId);
336
+ function isWithoutExceptions(expansion, mode) {
337
+ return expansion.mode === mode && expansion.except.length === 0;
324
338
  }
325
339
  function moveGroupByBefore(groupBy, columnId, beforeColumnId) {
326
340
  if (columnId === beforeColumnId) {
@@ -650,6 +664,175 @@ function compileOperatorEntry(entry, type) {
650
664
  }
651
665
  }
652
666
 
667
+ // src/util/filtering.ts
668
+ function parseFilterPattern(query) {
669
+ const start = query.startsWith("%");
670
+ const end = query.endsWith("%");
671
+ let text = query;
672
+ if (start) {
673
+ text = text.slice(1);
674
+ }
675
+ if (end) {
676
+ text = text.slice(0, -1);
677
+ }
678
+ text = text.toLowerCase();
679
+ if (start && end) {
680
+ return { mode: "contains", text };
681
+ }
682
+ if (start) {
683
+ return { mode: "endsWith", text };
684
+ }
685
+ if (end) {
686
+ return { mode: "startsWith", text };
687
+ }
688
+ return { mode: "exact", text };
689
+ }
690
+ function isEmptyValue(value) {
691
+ return value === null || value === void 0;
692
+ }
693
+ function compileFilterQuery(query) {
694
+ const { mode, text } = parseFilterPattern(query);
695
+ return (value) => {
696
+ const candidate = (isEmptyValue(value) ? "" : String(value)).toLowerCase();
697
+ switch (mode) {
698
+ case "exact":
699
+ return candidate === text;
700
+ case "contains":
701
+ return candidate.includes(text);
702
+ case "startsWith":
703
+ return candidate.startsWith(text);
704
+ case "endsWith":
705
+ return candidate.endsWith(text);
706
+ }
707
+ };
708
+ }
709
+ function matchesTypedValue(value, target, type) {
710
+ if (typeof target === "number") {
711
+ if (type !== "number" && type !== "decimal" && type !== "currency" && type !== "percent") {
712
+ return false;
713
+ }
714
+ return typeof value === "number" && value === target;
715
+ }
716
+ if (typeof target === "boolean") {
717
+ if (type !== "boolean") {
718
+ return false;
719
+ }
720
+ return typeof value === "boolean" && value === target;
721
+ }
722
+ if (type !== "date" && type !== "dateTime" && type !== "time") {
723
+ return false;
724
+ }
725
+ return value instanceof Date && value.getTime() === target.getTime();
726
+ }
727
+ function isEntryUsable(entry, byId) {
728
+ if (entry.kind === "group") {
729
+ return true;
730
+ }
731
+ return entry.columnId === void 0 || byId.has(entry.columnId);
732
+ }
733
+ function unknownFilterEntry(entry) {
734
+ const { kind } = entry;
735
+ throw new TypeError(
736
+ `GridKit: \`${String(kind)}\` is not a filter entry kind.`
737
+ );
738
+ }
739
+ function compileCellTest(columnId, byId, columns, test) {
740
+ if (columnId === void 0) {
741
+ return (row) => columns.some(
742
+ (entry) => test(accessDotted(row, entry.column.field), entry.column.type)
743
+ );
744
+ }
745
+ const column = byId.get(columnId);
746
+ if (column === void 0) {
747
+ return () => false;
748
+ }
749
+ return (row) => test(accessDotted(row, column.field), column.type);
750
+ }
751
+ function compileFilterEntry(entry, byId, columns) {
752
+ switch (entry.kind) {
753
+ case "group": {
754
+ const tests = entry.entries.filter((nested) => isEntryUsable(nested, byId)).map((nested) => compileFilterEntry(nested, byId, columns));
755
+ return entry.combinator === "and" ? (row) => tests.every((test) => test(row)) : (row) => tests.some((test) => test(row));
756
+ }
757
+ case "predicate": {
758
+ const { columnId, predicate } = entry;
759
+ const column = columnId === void 0 ? void 0 : byId.get(columnId);
760
+ return (row) => predicate(
761
+ column === void 0 ? void 0 : accessDotted(row, column.field),
762
+ row
763
+ );
764
+ }
765
+ case "operator": {
766
+ const column = byId.get(entry.columnId);
767
+ if (column === void 0) {
768
+ return () => false;
769
+ }
770
+ const test = compileOperatorEntry(entry, column.type);
771
+ return (row) => test(accessDotted(row, column.field));
772
+ }
773
+ case "value": {
774
+ const { value } = entry;
775
+ return compileCellTest(
776
+ entry.columnId,
777
+ byId,
778
+ columns,
779
+ (cell, type) => matchesTypedValue(cell, value, type)
780
+ );
781
+ }
782
+ case "text": {
783
+ const test = compileFilterQuery(entry.query);
784
+ return compileCellTest(entry.columnId, byId, columns, test);
785
+ }
786
+ default:
787
+ return unknownFilterEntry(entry);
788
+ }
789
+ }
790
+ function compileFilter(filter, columns) {
791
+ const byId = new Map(columns.map((entry) => [entry.id, entry.column]));
792
+ const compiled = filter.filter((entry) => isEntryUsable(entry, byId)).map((entry) => compileFilterEntry(entry, byId, columns));
793
+ return compiled.length === 0 ? void 0 : (row) => compiled.every((test) => test(row));
794
+ }
795
+ function matchesQuery(value, query) {
796
+ return compileFilterQuery(query)(value);
797
+ }
798
+ function filterQueryFor(filter, columnId) {
799
+ const entry = filter.find(
800
+ (candidate) => candidate.kind === "text" && candidate.columnId === columnId
801
+ );
802
+ return entry?.query ?? null;
803
+ }
804
+ function setColumnFilter(filter, columnId, query) {
805
+ const index = filter.findIndex(
806
+ (entry) => entry.kind !== "group" && entry.columnId === columnId
807
+ );
808
+ if (query === "") {
809
+ return index === -1 ? filter : filter.filter((_entry, i) => i !== index);
810
+ }
811
+ const next = columnId === void 0 ? { kind: "text", query } : { kind: "text", columnId, query };
812
+ if (index === -1) {
813
+ return [...filter, next];
814
+ }
815
+ const existing = filter[index];
816
+ if (existing?.kind === "text" && existing.query === query) {
817
+ return filter;
818
+ }
819
+ return filter.map((entry, i) => i === index ? next : entry);
820
+ }
821
+ function clearAllFilters(filter) {
822
+ return filter.length === 0 ? filter : [];
823
+ }
824
+ function filterRows(rows, filter, columns) {
825
+ if (filter.length === 0) {
826
+ return rows;
827
+ }
828
+ const test = compileFilter(filter, columns);
829
+ if (test === void 0) {
830
+ return rows;
831
+ }
832
+ const filtered = rows.filter((row) => test(row.row));
833
+ return renumberRows(filtered);
834
+ }
835
+
653
836
  // src/util/serialize.ts
654
837
  function serializeScalar(scalar) {
655
838
  return scalar instanceof Date ? scalar.toISOString() : scalar;
@@ -658,28 +841,32 @@ function serializeOperand(operand) {
658
841
  return isScalarList(operand) ? operand.map(serializeScalar) : serializeScalar(operand);
659
842
  }
660
843
  function serializeEntry(entry) {
661
- if ("combinator" in entry) {
662
- const entries = serializeFilter(entry.entries);
663
- return entries.length === 0 && entry.entries.length > 0 ? void 0 : { combinator: entry.combinator, entries };
664
- }
665
- if ("predicate" in entry) {
666
- reportError(
667
- entry.columnId === void 0 ? "a predicate filter entry across every column cannot be serialised, so it is left out of the saved state." : `a predicate filter entry on \`${entry.columnId}\` cannot be serialised, so it is left out of the saved state.`
668
- );
669
- return void 0;
670
- }
671
- if ("operator" in entry) {
672
- const { value, ...rest } = entry;
673
- return value === void 0 ? rest : { ...rest, value: serializeOperand(value) };
674
- }
675
- if ("value" in entry) {
676
- const { value, ...rest } = entry;
677
- return {
678
- ...rest,
679
- value: value instanceof Date ? value.toISOString() : value
680
- };
844
+ switch (entry.kind) {
845
+ case "group": {
846
+ const entries = serializeFilter(entry.entries);
847
+ return entries.length === 0 && entry.entries.length > 0 ? void 0 : { kind: "group", combinator: entry.combinator, entries };
848
+ }
849
+ case "predicate":
850
+ reportError(
851
+ entry.columnId === void 0 ? "a predicate filter entry across every column cannot be serialised, so it is left out of the saved state." : `a predicate filter entry on \`${entry.columnId}\` cannot be serialised, so it is left out of the saved state.`
852
+ );
853
+ return void 0;
854
+ case "operator": {
855
+ const { value, ...rest } = entry;
856
+ return value === void 0 ? rest : { ...rest, value: serializeOperand(value) };
857
+ }
858
+ case "value": {
859
+ const { value, ...rest } = entry;
860
+ return {
861
+ ...rest,
862
+ value: value instanceof Date ? value.toISOString() : value
863
+ };
864
+ }
865
+ case "text":
866
+ return entry;
867
+ default:
868
+ return unknownFilterEntry(entry);
681
869
  }
682
- return entry;
683
870
  }
684
871
  function serializeFilter(filter) {
685
872
  return filter.map((entry) => serializeEntry(entry)).filter((entry) => entry !== void 0);
@@ -693,25 +880,55 @@ function reviveScalar(scalar, type) {
693
880
  function reviveOperand(operand, type) {
694
881
  return isScalarList(operand) ? operand.map((scalar) => reviveScalar(scalar, type)) : reviveScalar(operand, type);
695
882
  }
696
- function reviveEntry(entry, typeOf) {
883
+ function tagged(entry) {
884
+ if ("kind" in entry) {
885
+ return entry;
886
+ }
697
887
  if ("combinator" in entry) {
698
- return {
699
- combinator: entry.combinator,
700
- entries: reviveEntries(entry.entries, typeOf)
701
- };
888
+ return { ...entry, kind: "group" };
702
889
  }
703
890
  if ("operator" in entry) {
704
- const { value, ...rest } = entry;
705
- return value === void 0 ? rest : { ...rest, value: reviveOperand(value, typeOf(entry.columnId)) };
891
+ return { ...entry, kind: "operator" };
892
+ }
893
+ if ("predicate" in entry) {
894
+ return { ...entry, kind: "predicate" };
706
895
  }
707
896
  if ("value" in entry) {
708
- const { value, ...rest } = entry;
709
- return {
710
- ...rest,
711
- value: typeof value === "string" ? new Date(value) : value
712
- };
897
+ return { ...entry, kind: "value" };
898
+ }
899
+ if ("query" in entry) {
900
+ return { ...entry, kind: "text" };
901
+ }
902
+ throw new TypeError(
903
+ "GridKit: a saved filter entry has no `kind`, nor any key one could be read from."
904
+ );
905
+ }
906
+ function reviveEntry(saved, typeOf) {
907
+ const entry = tagged(saved);
908
+ switch (entry.kind) {
909
+ case "group":
910
+ return {
911
+ kind: "group",
912
+ combinator: entry.combinator,
913
+ entries: reviveEntries(entry.entries, typeOf)
914
+ };
915
+ case "operator": {
916
+ const { value, ...rest } = entry;
917
+ return value === void 0 ? rest : { ...rest, value: reviveOperand(value, typeOf(entry.columnId)) };
918
+ }
919
+ case "value": {
920
+ const { value, ...rest } = entry;
921
+ return {
922
+ ...rest,
923
+ value: typeof value === "string" ? new Date(value) : value
924
+ };
925
+ }
926
+ case "text":
927
+ case "predicate":
928
+ return entry;
929
+ default:
930
+ return unknownFilterEntry(entry);
713
931
  }
714
- return entry;
715
932
  }
716
933
  function reviveEntries(filter, typeOf) {
717
934
  return filter.map((entry) => reviveEntry(entry, typeOf));
@@ -720,6 +937,23 @@ function reviveFilter(filter, columns) {
720
937
  const types = new Map(columns.map((entry) => [entry.id, entry.column.type]));
721
938
  return reviveEntries(filter, (columnId) => types.get(columnId));
722
939
  }
940
+ function isStringList(value) {
941
+ return Array.isArray(value) && value.every((item) => typeof item === "string");
942
+ }
943
+ function isGroupExpansion(value) {
944
+ return typeof value === "object" && value !== null && "mode" in value && (value.mode === "allExpanded" || value.mode === "allCollapsed") && "except" in value && isStringList(value.except);
945
+ }
946
+ function reviveGroupExpansion(saved) {
947
+ if (isStringList(saved)) {
948
+ return { mode: "allExpanded", except: saved };
949
+ }
950
+ if (isGroupExpansion(saved)) {
951
+ return saved;
952
+ }
953
+ throw new TypeError(
954
+ "GridKit: a saved `groupExpansion` is neither `{ mode, except }` nor a list of group ids."
955
+ );
956
+ }
723
957
 
724
958
  // src/util/sizing.ts
725
959
  var DEFAULT_COLUMN_SIZES = {
@@ -1032,167 +1266,6 @@ function withGroupAggregates(displayRows, flatRows, groupBy, specs, columns, dis
1032
1266
  return renumberRows(out);
1033
1267
  }
1034
1268
 
1035
- // src/util/filtering.ts
1036
- function parseFilterPattern(query) {
1037
- const start = query.startsWith("%");
1038
- const end = query.endsWith("%");
1039
- let text = query;
1040
- if (start) {
1041
- text = text.slice(1);
1042
- }
1043
- if (end) {
1044
- text = text.slice(0, -1);
1045
- }
1046
- text = text.toLowerCase();
1047
- if (start && end) {
1048
- return { mode: "contains", text };
1049
- }
1050
- if (start) {
1051
- return { mode: "endsWith", text };
1052
- }
1053
- if (end) {
1054
- return { mode: "startsWith", text };
1055
- }
1056
- return { mode: "exact", text };
1057
- }
1058
- function isEmptyValue(value) {
1059
- return value === null || value === void 0;
1060
- }
1061
- function compileFilterQuery(query) {
1062
- const { mode, text } = parseFilterPattern(query);
1063
- return (value) => {
1064
- const candidate = (isEmptyValue(value) ? "" : String(value)).toLowerCase();
1065
- switch (mode) {
1066
- case "exact":
1067
- return candidate === text;
1068
- case "contains":
1069
- return candidate.includes(text);
1070
- case "startsWith":
1071
- return candidate.startsWith(text);
1072
- case "endsWith":
1073
- return candidate.endsWith(text);
1074
- }
1075
- };
1076
- }
1077
- function matchesTypedValue(value, target, type) {
1078
- if (typeof target === "number") {
1079
- if (type !== "number" && type !== "decimal" && type !== "currency" && type !== "percent") {
1080
- return false;
1081
- }
1082
- return typeof value === "number" && value === target;
1083
- }
1084
- if (typeof target === "boolean") {
1085
- if (type !== "boolean") {
1086
- return false;
1087
- }
1088
- return typeof value === "boolean" && value === target;
1089
- }
1090
- if (type !== "date" && type !== "dateTime" && type !== "time") {
1091
- return false;
1092
- }
1093
- return value instanceof Date && value.getTime() === target.getTime();
1094
- }
1095
- function isEntryUsable(entry, byId) {
1096
- if ("combinator" in entry) {
1097
- return true;
1098
- }
1099
- return entry.columnId === void 0 || byId.has(entry.columnId);
1100
- }
1101
- function compileFilterEntry(entry, byId, columns) {
1102
- if ("combinator" in entry) {
1103
- const tests = entry.entries.filter((nested) => isEntryUsable(nested, byId)).map((nested) => compileFilterEntry(nested, byId, columns));
1104
- return entry.combinator === "and" ? (row) => tests.every((test2) => test2(row)) : (row) => tests.some((test2) => test2(row));
1105
- }
1106
- if ("predicate" in entry) {
1107
- const { columnId: columnId2, predicate } = entry;
1108
- const column = columnId2 === void 0 ? void 0 : byId.get(columnId2);
1109
- return (row) => predicate(
1110
- column === void 0 ? void 0 : accessDotted(row, column.field),
1111
- row
1112
- );
1113
- }
1114
- if ("operator" in entry) {
1115
- const column = byId.get(entry.columnId);
1116
- if (column === void 0) {
1117
- return () => false;
1118
- }
1119
- const test2 = compileOperatorEntry(entry, column.type);
1120
- return (row) => test2(accessDotted(row, column.field));
1121
- }
1122
- if ("value" in entry) {
1123
- const { columnId: columnId2, value } = entry;
1124
- if (columnId2 !== void 0) {
1125
- const column = byId.get(columnId2);
1126
- if (column === void 0) {
1127
- return () => false;
1128
- }
1129
- return (row) => matchesTypedValue(accessDotted(row, column.field), value, column.type);
1130
- }
1131
- return (row) => columns.some(
1132
- (entry2) => matchesTypedValue(
1133
- accessDotted(row, entry2.column.field),
1134
- value,
1135
- entry2.column.type
1136
- )
1137
- );
1138
- }
1139
- const { columnId, query } = entry;
1140
- const test = compileFilterQuery(query);
1141
- if (columnId !== void 0) {
1142
- const column = byId.get(columnId);
1143
- if (column === void 0) {
1144
- return () => false;
1145
- }
1146
- return (row) => test(accessDotted(row, column.field));
1147
- }
1148
- return (row) => columns.some((entry2) => test(accessDotted(row, entry2.column.field)));
1149
- }
1150
- function compileFilter(filter, columns) {
1151
- const byId = new Map(columns.map((entry) => [entry.id, entry.column]));
1152
- const compiled = filter.filter((entry) => isEntryUsable(entry, byId)).map((entry) => compileFilterEntry(entry, byId, columns));
1153
- return compiled.length === 0 ? void 0 : (row) => compiled.every((test) => test(row));
1154
- }
1155
- function matchesQuery(value, query) {
1156
- return compileFilterQuery(query)(value);
1157
- }
1158
- function filterQueryFor(filter, columnId) {
1159
- const entry = filter.find(
1160
- (candidate) => "query" in candidate && candidate.columnId === columnId
1161
- );
1162
- return entry?.query ?? null;
1163
- }
1164
- function setColumnFilter(filter, columnId, query) {
1165
- const index = filter.findIndex(
1166
- (entry) => !("combinator" in entry) && entry.columnId === columnId
1167
- );
1168
- if (query === "") {
1169
- return index === -1 ? filter : filter.filter((_entry, i) => i !== index);
1170
- }
1171
- const next = columnId === void 0 ? { query } : { columnId, query };
1172
- if (index === -1) {
1173
- return [...filter, next];
1174
- }
1175
- const existing = filter[index];
1176
- if (existing !== void 0 && "query" in existing && existing.query === query) {
1177
- return filter;
1178
- }
1179
- return filter.map((entry, i) => i === index ? next : entry);
1180
- }
1181
- function clearAllFilters(filter) {
1182
- return filter.length === 0 ? filter : [];
1183
- }
1184
- function filterRows(rows, filter, columns) {
1185
- if (filter.length === 0) {
1186
- return rows;
1187
- }
1188
- const test = compileFilter(filter, columns);
1189
- if (test === void 0) {
1190
- return rows;
1191
- }
1192
- const filtered = rows.filter((row) => test(row.row));
1193
- return renumberRows(filtered);
1194
- }
1195
-
1196
1269
  // src/util/rows.ts
1197
1270
  function resolveShownRows(rows, filter, sort, columns) {
1198
1271
  return sortRows(filterRows(rows, filter, columns), sort, columns);
@@ -1392,6 +1465,9 @@ function changedKeys(previous, next) {
1392
1465
  function sameItems(previous, next) {
1393
1466
  return previous.length === next.length && previous.every((item, index) => item === next[index]);
1394
1467
  }
1468
+ function sameGroupExpansion(previous, next) {
1469
+ return previous.mode === next.mode && sameItems(previous.except, next.except);
1470
+ }
1395
1471
  function samePagination(previous, next) {
1396
1472
  return previous.pageIndex === next.pageIndex && previous.pageSize === next.pageSize;
1397
1473
  }
@@ -1405,22 +1481,20 @@ function sameOperand(previous, next) {
1405
1481
  return sameValue(previous, next);
1406
1482
  }
1407
1483
  function sameEntry(previous, next) {
1408
- if ("combinator" in previous || "combinator" in next) {
1409
- return "combinator" in previous && "combinator" in next && previous.combinator === next.combinator && sameFilter(previous.entries, next.entries);
1410
- }
1411
- if (previous.columnId !== next.columnId) {
1412
- return false;
1413
- }
1414
- if ("predicate" in previous || "predicate" in next) {
1415
- return "predicate" in previous && "predicate" in next && previous.predicate === next.predicate;
1416
- }
1417
- if ("operator" in previous || "operator" in next) {
1418
- return "operator" in previous && "operator" in next && previous.operator === next.operator && sameOperand(previous.value, next.value);
1419
- }
1420
- if ("value" in previous || "value" in next) {
1421
- return "value" in previous && "value" in next && sameValue(previous.value, next.value);
1484
+ switch (previous.kind) {
1485
+ case "group":
1486
+ return next.kind === "group" && previous.combinator === next.combinator && sameFilter(previous.entries, next.entries);
1487
+ case "predicate":
1488
+ return next.kind === "predicate" && previous.columnId === next.columnId && previous.predicate === next.predicate;
1489
+ case "operator":
1490
+ return next.kind === "operator" && previous.columnId === next.columnId && previous.operator === next.operator && sameOperand(previous.value, next.value);
1491
+ case "value":
1492
+ return next.kind === "value" && previous.columnId === next.columnId && sameValue(previous.value, next.value);
1493
+ case "text":
1494
+ return next.kind === "text" && previous.columnId === next.columnId && previous.query === next.query;
1495
+ default:
1496
+ return unknownFilterEntry(previous);
1422
1497
  }
1423
- return previous.query === next.query;
1424
1498
  }
1425
1499
  function sameFilter(previous, next) {
1426
1500
  return previous.length === next.length && previous.every((entry, index) => {
@@ -1596,6 +1670,21 @@ function indexRows(rows) {
1596
1670
  function distinct(ids) {
1597
1671
  return [...new Set(ids)];
1598
1672
  }
1673
+ function click(selection, orderedIds, anchor, id, intent, mode) {
1674
+ const live = anchor !== null && orderedIds.includes(anchor) ? anchor : null;
1675
+ const keepsAnchor = mode === false || intent === "range" && live !== null;
1676
+ return {
1677
+ selection: applySelectionIntent(
1678
+ selection,
1679
+ orderedIds,
1680
+ live,
1681
+ id,
1682
+ intent,
1683
+ mode
1684
+ ),
1685
+ anchor: keepsAnchor ? anchor : id
1686
+ };
1687
+ }
1599
1688
  function createSelectionActions(grid) {
1600
1689
  let rowAnchor = null;
1601
1690
  let columnAnchor = null;
@@ -1659,6 +1748,7 @@ function createSelectionActions(grid) {
1659
1748
  }
1660
1749
  return {
1661
1750
  setRowSelection(selection) {
1751
+ rowAnchor = null;
1662
1752
  if (!sameItems(grid.getState().rowSelection, selection)) {
1663
1753
  commitRows(selection);
1664
1754
  }
@@ -1679,7 +1769,7 @@ function createSelectionActions(grid) {
1679
1769
  }
1680
1770
  },
1681
1771
  selectRow(rowId, intent) {
1682
- const next = applySelectionIntent(
1772
+ const next = click(
1683
1773
  grid.getState().rowSelection,
1684
1774
  rowIds(),
1685
1775
  rowAnchor,
@@ -1687,10 +1777,8 @@ function createSelectionActions(grid) {
1687
1777
  intent,
1688
1778
  modes().rows
1689
1779
  );
1690
- if (intent !== "range") {
1691
- rowAnchor = rowId;
1692
- }
1693
- commitRows(next);
1780
+ rowAnchor = next.anchor;
1781
+ commitRows(next.selection);
1694
1782
  },
1695
1783
  selectAllRows() {
1696
1784
  commitRows(
@@ -1698,17 +1786,22 @@ function createSelectionActions(grid) {
1698
1786
  );
1699
1787
  },
1700
1788
  clearSelection() {
1701
- commitRows(clearSelection(grid.getState().rowSelection));
1702
- commitColumns(clearSelection(grid.getState().columnSelection));
1703
- commitCell(null);
1789
+ rowAnchor = null;
1790
+ columnAnchor = null;
1791
+ grid.transaction(() => {
1792
+ commitRows(clearSelection(grid.getState().rowSelection));
1793
+ commitColumns(clearSelection(grid.getState().columnSelection));
1794
+ commitCell(null);
1795
+ });
1704
1796
  },
1705
1797
  setColumnSelection(selection) {
1798
+ columnAnchor = null;
1706
1799
  if (!sameItems(grid.getState().columnSelection, selection)) {
1707
1800
  commitColumns(selection);
1708
1801
  }
1709
1802
  },
1710
1803
  selectColumn(columnId, intent) {
1711
- const next = applySelectionIntent(
1804
+ const next = click(
1712
1805
  grid.getState().columnSelection,
1713
1806
  columnIds(),
1714
1807
  columnAnchor,
@@ -1716,10 +1809,8 @@ function createSelectionActions(grid) {
1716
1809
  intent,
1717
1810
  modes().columns
1718
1811
  );
1719
- if (intent !== "range") {
1720
- columnAnchor = columnId;
1721
- }
1722
- commitColumns(next);
1812
+ columnAnchor = next.anchor;
1813
+ commitColumns(next.selection);
1723
1814
  },
1724
1815
  setCellSelection(selection) {
1725
1816
  if (!isSameCell(grid.getState().cellSelection, selection)) {
@@ -1774,7 +1865,7 @@ function startingState(options) {
1774
1865
  columnSort: options.defaultColumnSort ?? [],
1775
1866
  filter: options.defaultFilter ?? [],
1776
1867
  groupBy: options.defaultGroupBy ?? [],
1777
- groupExpansion: options.defaultGroupExpansion ?? [],
1868
+ groupExpansion: options.defaultGroupExpansion ?? ALL_EXPANDED,
1778
1869
  pagination: options.defaultPagination ?? {
1779
1870
  pageIndex: 0,
1780
1871
  pageSize: DEFAULT_PAGE_SIZE
@@ -1793,6 +1884,10 @@ function definedColumns(columns, rows) {
1793
1884
  }
1794
1885
  return NO_COLUMNS;
1795
1886
  }
1887
+ var IDLE = { kind: "idle" };
1888
+ function samePagingInputs(a, b) {
1889
+ return a.filter === b.filter && a.columnSort === b.columnSort && a.groupBy === b.groupBy && a.paginationUnit === b.paginationUnit;
1890
+ }
1796
1891
  function pagingInputsOf(state, options) {
1797
1892
  return {
1798
1893
  filter: state.filter,
@@ -1808,7 +1903,7 @@ function createGridController(initial) {
1808
1903
  const resolveColumns2 = memoizeLast(definedColumns);
1809
1904
  const listeners = /* @__PURE__ */ new Set();
1810
1905
  const reportedConflicts = /* @__PURE__ */ new Set();
1811
- let heldReports;
1906
+ let mode = IDLE;
1812
1907
  let state = resolveSlices();
1813
1908
  let pagingInputs = pagingInputsOf(state, options);
1814
1909
  reportConflicts();
@@ -1850,18 +1945,24 @@ function createGridController(initial) {
1850
1945
  );
1851
1946
  }
1852
1947
  }
1853
- function refresh() {
1854
- let next = resolveSlices();
1855
- const inputs = pagingInputsOf(next, options);
1856
- if (inputs.filter !== pagingInputs.filter || inputs.columnSort !== pagingInputs.columnSort || inputs.groupBy !== pagingInputs.groupBy || inputs.paginationUnit !== pagingInputs.paginationUnit) {
1857
- pagingInputs = inputs;
1858
- if (!isControlled("pagination") && own.pagination.pageIndex !== 0) {
1859
- own.pagination = { ...own.pagination, pageIndex: 0 };
1860
- next = { ...next, pagination: own.pagination };
1861
- }
1862
- }
1948
+ function refresh(keepPage = false) {
1949
+ const before = state;
1950
+ const next = followPagingInputs(resolveSlices(), keepPage);
1863
1951
  state = SLICE_KEYS.every((key) => next[key] === state[key]) ? state : next;
1864
1952
  storeShownPage();
1953
+ return state !== before;
1954
+ }
1955
+ function followPagingInputs(next, keepPage) {
1956
+ const inputs = pagingInputsOf(next, options);
1957
+ if (samePagingInputs(inputs, pagingInputs)) {
1958
+ return next;
1959
+ }
1960
+ pagingInputs = inputs;
1961
+ if (keepPage || isControlled("pagination") || own.pagination.pageIndex === 0) {
1962
+ return next;
1963
+ }
1964
+ own.pagination = { ...own.pagination, pageIndex: 0 };
1965
+ return { ...next, pagination: own.pagination };
1865
1966
  }
1866
1967
  function storeShownPage() {
1867
1968
  const stored = storedPagination(state.pagination);
@@ -1889,13 +1990,39 @@ function createGridController(initial) {
1889
1990
  if (!isControlled(key)) {
1890
1991
  own[key] = next;
1891
1992
  }
1892
- if (heldReports !== void 0) {
1893
- heldReports.push(report);
1993
+ if (mode.kind === "transaction") {
1994
+ mode.held.push(report);
1894
1995
  return;
1895
1996
  }
1896
- refresh();
1997
+ const changed = refresh();
1897
1998
  report();
1898
- notify();
1999
+ if (changed) {
2000
+ notify();
2001
+ }
2002
+ }
2003
+ function transaction(run) {
2004
+ if (mode.kind === "transaction") {
2005
+ run();
2006
+ return;
2007
+ }
2008
+ const current = {
2009
+ kind: "transaction",
2010
+ held: [],
2011
+ pageAsked: false
2012
+ };
2013
+ mode = current;
2014
+ try {
2015
+ run();
2016
+ } finally {
2017
+ mode = IDLE;
2018
+ const changed = refresh(current.pageAsked);
2019
+ for (const report of current.held) {
2020
+ report();
2021
+ }
2022
+ if (changed) {
2023
+ notify();
2024
+ }
2025
+ }
1899
2026
  }
1900
2027
  function getView() {
1901
2028
  return resolveView({
@@ -1967,7 +2094,12 @@ function createGridController(initial) {
1967
2094
  });
1968
2095
  }
1969
2096
  function commitPagination(asked) {
1970
- const next = heldReports === void 0 ? storedPagination(asked) : asked;
2097
+ let next = asked;
2098
+ if (mode.kind === "transaction") {
2099
+ mode.pageAsked = true;
2100
+ } else {
2101
+ next = storedPagination(asked);
2102
+ }
1971
2103
  if (samePagination(state.pagination, next)) {
1972
2104
  return;
1973
2105
  }
@@ -1996,7 +2128,8 @@ function createGridController(initial) {
1996
2128
  getState: () => state,
1997
2129
  getOptions: () => options,
1998
2130
  getView,
1999
- commit
2131
+ commit,
2132
+ transaction
2000
2133
  });
2001
2134
  const controller = {
2002
2135
  ...selection,
@@ -2009,23 +2142,9 @@ function createGridController(initial) {
2009
2142
  getState: () => state,
2010
2143
  getView,
2011
2144
  restoreState(saved) {
2012
- const reports = [];
2013
- heldReports = reports;
2014
- try {
2145
+ transaction(() => {
2015
2146
  restoreSlices(saved);
2016
- } finally {
2017
- heldReports = void 0;
2018
- }
2019
- if (saved.pagination !== void 0) {
2020
- pagingInputs = pagingInputsOf(resolveSlices(), options);
2021
- }
2022
- refresh();
2023
- for (const report of reports) {
2024
- report();
2025
- }
2026
- if (reports.length > 0) {
2027
- notify();
2028
- }
2147
+ });
2029
2148
  },
2030
2149
  subscribe(listener) {
2031
2150
  listeners.add(listener);
@@ -2151,7 +2270,7 @@ function createGridController(initial) {
2151
2270
  );
2152
2271
  },
2153
2272
  setGroupExpansion(expansion) {
2154
- if (!sameItems(state.groupExpansion, expansion)) {
2273
+ if (!sameGroupExpansion(state.groupExpansion, expansion)) {
2155
2274
  commitGroupExpansion(expansion, null);
2156
2275
  }
2157
2276
  },
@@ -2165,7 +2284,7 @@ function createGridController(initial) {
2165
2284
  commitGroupExpansion(expandAllGroups(state.groupExpansion), null);
2166
2285
  },
2167
2286
  collapseAllGroups() {
2168
- commitGroupExpansion(collapseAllGroups(getView().displayRows), null);
2287
+ commitGroupExpansion(collapseAllGroups(state.groupExpansion), null);
2169
2288
  },
2170
2289
  setPagination: commitPagination,
2171
2290
  goToPage,
@@ -2203,7 +2322,7 @@ function createGridController(initial) {
2203
2322
  controller.setGroupBy(saved.groupBy);
2204
2323
  }
2205
2324
  if (saved.groupExpansion !== void 0) {
2206
- controller.setGroupExpansion(saved.groupExpansion);
2325
+ controller.setGroupExpansion(reviveGroupExpansion(saved.groupExpansion));
2207
2326
  }
2208
2327
  if (saved.pagination !== void 0) {
2209
2328
  controller.setPagination(saved.pagination);
@@ -2547,7 +2666,12 @@ function buildExportTable(source, options = {}) {
2547
2666
  messages: source.messages
2548
2667
  };
2549
2668
  const rows = scopedRows(source, options.scope ?? "all");
2550
- const grouped = groupRows(rows, state.groupBy, [], view.dataColumns);
2669
+ const grouped = groupRows(
2670
+ rows,
2671
+ state.groupBy,
2672
+ ALL_EXPANDED,
2673
+ view.dataColumns
2674
+ );
2551
2675
  const displayRows = options.includeGroups ?? true ? withGroupAggregates(
2552
2676
  grouped,
2553
2677
  rows,
@@ -3280,7 +3404,8 @@ function createDefaultMessages(locale) {
3280
3404
  copySelection: "Copy selection",
3281
3405
  copied: (count, unit) => copied(n, count, unit),
3282
3406
  copyFailed: "Copy failed",
3283
- print: "Print"
3407
+ print: "Print",
3408
+ printFailed: "Print failed"
3284
3409
  };
3285
3410
  }
3286
3411
  var defaultMessages = createDefaultMessages();
@@ -3304,10 +3429,10 @@ function resolveMessages(messages, locale) {
3304
3429
 
3305
3430
  // src/util/filterEditor.ts
3306
3431
  function touchesColumn(entry, columnId) {
3307
- return "combinator" in entry ? entry.entries.some((nested) => touchesColumn(nested, columnId)) : entry.columnId === columnId;
3432
+ return entry.kind === "group" ? entry.entries.some((nested) => touchesColumn(nested, columnId)) : entry.columnId === columnId;
3308
3433
  }
3309
3434
  function isOperatorOn(entry, columnId) {
3310
- return "operator" in entry && entry.columnId === columnId;
3435
+ return entry.kind === "operator" && entry.columnId === columnId;
3311
3436
  }
3312
3437
  function isConditionOn(entry, columnId) {
3313
3438
  return isOperatorOn(entry, columnId) && entry.operator !== "in";
@@ -3319,7 +3444,7 @@ function valuesShape(entry, columnId) {
3319
3444
  if (alone !== void 0) {
3320
3445
  return { kind: "values", values: alone, includeBlanks: false };
3321
3446
  }
3322
- if (!("combinator" in entry) || entry.combinator !== "or" || entry.entries.length !== 2) {
3447
+ if (entry.kind !== "group" || entry.combinator !== "or" || entry.entries.length !== 2) {
3323
3448
  return void 0;
3324
3449
  }
3325
3450
  const [first, second] = entry.entries;
@@ -3328,7 +3453,7 @@ function valuesShape(entry, columnId) {
3328
3453
  }
3329
3454
  function conditionsShape(touching, columnId) {
3330
3455
  const [only] = touching;
3331
- const grouped = touching.length === 1 && only !== void 0 && "combinator" in only;
3456
+ const grouped = touching.length === 1 && only !== void 0 && only.kind === "group";
3332
3457
  const entries = grouped ? only.entries : touching;
3333
3458
  const combinator = grouped ? only.combinator : "and";
3334
3459
  if (entries.length === 0 || entries.length > 2) {
@@ -3406,38 +3531,53 @@ function everyOption(draft) {
3406
3531
  draft.options.map((option) => [keyOf2(draft, option.value), option.value])
3407
3532
  );
3408
3533
  }
3534
+ function baseOf(draft) {
3535
+ const { options, blanks, search, openedShape, columnType } = draft;
3536
+ return { options, blanks, search, openedShape, columnType };
3537
+ }
3538
+ function openedValues(base) {
3539
+ const shape = base.openedShape;
3540
+ if (shape.kind !== "values") {
3541
+ return {
3542
+ kind: "values",
3543
+ ...base,
3544
+ checked: everyOption(base),
3545
+ includeBlanks: base.blanks > 0
3546
+ };
3547
+ }
3548
+ return {
3549
+ kind: "values",
3550
+ ...base,
3551
+ checked: new Map(
3552
+ shape.values.filter((value) => !isEmptyCell(value)).map((value) => [keyOf2(base, value), value])
3553
+ ),
3554
+ includeBlanks: shape.includeBlanks
3555
+ };
3556
+ }
3557
+ function openedConditions(base) {
3558
+ const shape = base.openedShape;
3559
+ return shape.kind === "conditions" ? {
3560
+ kind: "conditions",
3561
+ ...base,
3562
+ conditions: shape.conditions,
3563
+ combinator: shape.combinator
3564
+ } : { kind: "conditions", ...base, conditions: [], combinator: "and" };
3565
+ }
3409
3566
  function initialFilterEditorDraft(shape, values) {
3410
- const draft = {
3411
- mode: "values",
3567
+ const base = {
3412
3568
  options: values.options,
3413
3569
  blanks: values.blanks,
3414
3570
  search: "",
3415
- checked: everyOption(values),
3416
- includeBlanks: values.blanks > 0,
3417
- conditions: [],
3418
- combinator: "and",
3571
+ openedShape: shape,
3419
3572
  columnType: values.columnType
3420
3573
  };
3421
- switch (shape.kind) {
3422
- case "values":
3423
- return {
3424
- ...draft,
3425
- checked: new Map(
3426
- shape.values.filter((value) => !isEmptyCell(value)).map((value) => [keyOf2(draft, value), value])
3427
- ),
3428
- includeBlanks: shape.includeBlanks
3429
- };
3430
- case "conditions":
3431
- return {
3432
- ...draft,
3433
- mode: "conditions",
3434
- conditions: shape.conditions,
3435
- combinator: shape.combinator
3436
- };
3437
- case "none":
3438
- case "custom":
3439
- return draft;
3440
- }
3574
+ return shape.kind === "conditions" ? openedConditions(base) : openedValues(base);
3575
+ }
3576
+ function toValuesDraft(draft) {
3577
+ return draft.kind === "values" ? draft : openedValues(baseOf(draft));
3578
+ }
3579
+ function toConditionsDraft(draft) {
3580
+ return draft.kind === "conditions" ? draft : openedConditions(baseOf(draft));
3441
3581
  }
3442
3582
  function visibleFilterOptions(draft) {
3443
3583
  return draft.search === "" ? draft.options : draft.options.filter(
@@ -3459,6 +3599,16 @@ function selectAllState(draft) {
3459
3599
  }
3460
3600
  return states.some(Boolean) ? "mixed" : "unchecked";
3461
3601
  }
3602
+ function toggleValue(draft, value) {
3603
+ const key = keyOf2(draft, value);
3604
+ const checked = new Map(draft.checked);
3605
+ if (checked.has(key)) {
3606
+ checked.delete(key);
3607
+ } else {
3608
+ checked.set(key, value);
3609
+ }
3610
+ return { ...draft, checked };
3611
+ }
3462
3612
  function toggleAll(draft) {
3463
3613
  const check = selectAllState(draft) !== "checked";
3464
3614
  const checked = new Map(draft.checked);
@@ -3472,44 +3622,43 @@ function toggleAll(draft) {
3472
3622
  }
3473
3623
  return {
3474
3624
  ...draft,
3475
- mode: "values",
3476
3625
  checked,
3477
3626
  includeBlanks: selectAllCoversBlanks(draft) ? check : draft.includeBlanks
3478
3627
  };
3479
3628
  }
3629
+ function cleared(draft) {
3630
+ switch (draft.kind) {
3631
+ case "values":
3632
+ return {
3633
+ ...draft,
3634
+ search: "",
3635
+ checked: everyOption(draft),
3636
+ includeBlanks: draft.blanks > 0
3637
+ };
3638
+ case "conditions":
3639
+ return { ...draft, search: "", conditions: [] };
3640
+ }
3641
+ }
3480
3642
  function filterEditorReducer(draft, action) {
3481
3643
  switch (action.type) {
3482
3644
  case "search":
3483
3645
  return { ...draft, search: action.search };
3484
- case "toggleValue": {
3485
- const key = keyOf2(draft, action.value);
3486
- const checked = new Map(draft.checked);
3487
- if (checked.has(key)) {
3488
- checked.delete(key);
3489
- } else {
3490
- checked.set(key, action.value);
3491
- }
3492
- return { ...draft, mode: "values", checked };
3493
- }
3646
+ case "toggleValue":
3647
+ return toggleValue(toValuesDraft(draft), action.value);
3494
3648
  case "toggleAll":
3495
- return toggleAll(draft);
3649
+ return toggleAll(toValuesDraft(draft));
3496
3650
  case "setIncludeBlanks":
3497
- return { ...draft, mode: "values", includeBlanks: action.includeBlanks };
3498
- case "setConditions":
3651
+ return { ...toValuesDraft(draft), includeBlanks: action.includeBlanks };
3652
+ case "setConditions": {
3653
+ const conditions = toConditionsDraft(draft);
3499
3654
  return {
3500
- ...draft,
3501
- mode: "conditions",
3655
+ ...conditions,
3502
3656
  conditions: action.conditions,
3503
- combinator: action.combinator ?? draft.combinator
3657
+ combinator: action.combinator ?? conditions.combinator
3504
3658
  };
3659
+ }
3505
3660
  case "clear":
3506
- return {
3507
- ...draft,
3508
- search: "",
3509
- checked: everyOption(draft),
3510
- includeBlanks: draft.blanks > 0,
3511
- conditions: []
3512
- };
3661
+ return cleared(draft);
3513
3662
  }
3514
3663
  }
3515
3664
  function checksEverything(draft) {
@@ -3517,29 +3666,42 @@ function checksEverything(draft) {
3517
3666
  (option) => draft.checked.has(keyOf2(draft, option.value))
3518
3667
  ) && (draft.includeBlanks || draft.blanks === 0);
3519
3668
  }
3520
- function draftEntries(draft, columnId) {
3521
- if (draft.mode === "conditions") {
3522
- const conditions = draft.conditions.map((condition) => ({
3523
- ...condition,
3524
- columnId
3525
- }));
3526
- return conditions.length > 1 ? [{ combinator: draft.combinator, entries: conditions }] : conditions;
3527
- }
3669
+ function valuesEntries(draft, columnId) {
3528
3670
  if (checksEverything(draft)) {
3529
3671
  return [];
3530
3672
  }
3531
3673
  const picked = {
3674
+ kind: "operator",
3532
3675
  columnId,
3533
3676
  operator: "in",
3534
3677
  value: [...draft.checked.values()]
3535
3678
  };
3536
3679
  return draft.includeBlanks ? [
3537
3680
  {
3681
+ kind: "group",
3538
3682
  combinator: "or",
3539
- entries: [picked, { columnId, operator: "isEmpty" }]
3683
+ entries: [
3684
+ picked,
3685
+ { kind: "operator", columnId, operator: "isEmpty" }
3686
+ ]
3540
3687
  }
3541
3688
  ] : [picked];
3542
3689
  }
3690
+ function conditionsEntries(draft, columnId) {
3691
+ const conditions = draft.conditions.map((condition) => ({
3692
+ ...condition,
3693
+ columnId
3694
+ }));
3695
+ return conditions.length > 1 ? [{ kind: "group", combinator: draft.combinator, entries: conditions }] : conditions;
3696
+ }
3697
+ function draftEntries(draft, columnId) {
3698
+ switch (draft.kind) {
3699
+ case "values":
3700
+ return valuesEntries(draft, columnId);
3701
+ case "conditions":
3702
+ return conditionsEntries(draft, columnId);
3703
+ }
3704
+ }
3543
3705
  function draftToFilter(draft, columnId, current) {
3544
3706
  const replacement = draftEntries(draft, columnId);
3545
3707
  const first = current.findIndex((entry) => touchesColumn(entry, columnId));
@@ -3549,6 +3711,29 @@ function draftToFilter(draft, columnId, current) {
3549
3711
  const kept = current.filter((entry) => !touchesColumn(entry, columnId));
3550
3712
  return [...kept.slice(0, first), ...replacement, ...kept.slice(first)];
3551
3713
  }
3714
+ function sameValues(a, b) {
3715
+ return a.includeBlanks === b.includeBlanks && a.checked.size === b.checked.size && [...a.checked.keys()].every((key) => b.checked.has(key));
3716
+ }
3717
+ function sameOperand2(a, b, type) {
3718
+ if (isScalarList(a) || isScalarList(b)) {
3719
+ return isScalarList(a) && isScalarList(b) && a.length === b.length && a.every((scalar, index) => sameOperand2(scalar, b[index], type));
3720
+ }
3721
+ return filterValueKey(a, type) === filterValueKey(b, type);
3722
+ }
3723
+ function sameConditions(a, b) {
3724
+ return a.conditions.length === b.conditions.length && (a.conditions.length < 2 || a.combinator === b.combinator) && a.conditions.every((condition, index) => {
3725
+ const other = b.conditions[index];
3726
+ return other !== void 0 && condition.operator === other.operator && sameOperand2(condition.value, other.value, a.columnType);
3727
+ });
3728
+ }
3729
+ function filterDraftChanged(opened, draft) {
3730
+ switch (draft.kind) {
3731
+ case "values":
3732
+ return !sameValues(toValuesDraft(opened), draft);
3733
+ case "conditions":
3734
+ return opened.kind !== "conditions" || !sameConditions(opened, draft);
3735
+ }
3736
+ }
3552
3737
 
3553
3738
  // src/commands/builtInCommands.ts
3554
3739
  function isOn(context, areas) {
@@ -3643,6 +3828,9 @@ function exportCommand({
3643
3828
  isVisible: (context) => isOn(context, EXPORT_AREAS) && resolveExportWriters(context.options.exportWriters).has(format) && (!selection || context.state.rowSelection.length > 0),
3644
3829
  isEnabled: (context) => (selection ? context.selectedRows() : context.view.rows).length > 0,
3645
3830
  execute: (context) => {
3831
+ if (context.host.canSave?.() === false) {
3832
+ return false;
3833
+ }
3646
3834
  const { export: defaults = {}, exportWriters } = context.options;
3647
3835
  const file = exportFile(
3648
3836
  context,
@@ -3650,9 +3838,10 @@ function exportCommand({
3650
3838
  selection ? { ...defaults, scope: "selection" } : defaults,
3651
3839
  resolveExportWriters(exportWriters)
3652
3840
  );
3653
- if (file !== null) {
3654
- context.host.saveFile(file);
3841
+ if (file === null) {
3842
+ return;
3655
3843
  }
3844
+ return context.host.saveFile(file) !== false;
3656
3845
  }
3657
3846
  };
3658
3847
  }
@@ -3956,8 +4145,7 @@ function runCommand(command, context) {
3956
4145
  if (!isCommandVisible(command, context) || !isCommandEnabled(command, context)) {
3957
4146
  return false;
3958
4147
  }
3959
- command.execute(context);
3960
- return true;
4148
+ return command.execute(context) !== false;
3961
4149
  }
3962
4150
 
3963
4151
  // src/menu/resolveMenu.ts
@@ -4344,101 +4532,95 @@ function setSearchText(filter, text) {
4344
4532
  }
4345
4533
 
4346
4534
  // src/util/navigation.ts
4347
- var HEADER_ROW = -1;
4535
+ function headerFocus(columnIndex) {
4536
+ return { area: "header", columnIndex };
4537
+ }
4538
+ function bodyFocus(rowIndex, columnIndex) {
4539
+ return { area: "body", rowIndex, columnIndex };
4540
+ }
4348
4541
  function clampFocus(focus, rowCount, columnCount2) {
4349
- return {
4350
- rowIndex: Math.min(Math.max(focus.rowIndex, HEADER_ROW), rowCount - 1),
4351
- columnIndex: Math.min(
4352
- Math.max(focus.columnIndex, 0),
4353
- Math.max(columnCount2 - 1, 0)
4354
- )
4355
- };
4542
+ const columnIndex = Math.min(
4543
+ Math.max(focus.columnIndex, 0),
4544
+ Math.max(columnCount2 - 1, 0)
4545
+ );
4546
+ switch (focus.area) {
4547
+ case "header":
4548
+ return headerFocus(columnIndex);
4549
+ case "body": {
4550
+ const rowIndex = Math.min(focus.rowIndex, rowCount - 1);
4551
+ return rowIndex < 0 ? headerFocus(columnIndex) : bodyFocus(rowIndex, columnIndex);
4552
+ }
4553
+ }
4356
4554
  }
4357
4555
  function noRowsSkippable() {
4358
4556
  return false;
4359
4557
  }
4360
- function skipSkippableRows(rowIndex, direction, rowCount, isSkippableRow, fallback) {
4361
- let next = rowIndex;
4362
- while (next >= 0 && next < rowCount && isSkippableRow(next)) {
4363
- const stepped = next + direction;
4364
- if (stepped < HEADER_ROW || stepped >= rowCount) {
4558
+ function linePosition(focus) {
4559
+ return focus.area === "header" ? -1 : focus.rowIndex;
4560
+ }
4561
+ function focusAtLine(line2, columnIndex) {
4562
+ return line2 < 0 ? headerFocus(columnIndex) : bodyFocus(line2, columnIndex);
4563
+ }
4564
+ function skipSkippableRows(target, direction, rowCount, isSkippableRow, fallback) {
4565
+ if (target.area === "header") {
4566
+ return target;
4567
+ }
4568
+ let rowIndex = target.rowIndex;
4569
+ while (rowIndex < rowCount && isSkippableRow(rowIndex)) {
4570
+ const stepped = rowIndex + direction;
4571
+ if (stepped >= rowCount) {
4365
4572
  return fallback;
4366
4573
  }
4367
- next = stepped;
4574
+ if (stepped < 0) {
4575
+ return headerFocus(target.columnIndex);
4576
+ }
4577
+ rowIndex = stepped;
4368
4578
  }
4369
- return next;
4579
+ return bodyFocus(rowIndex, target.columnIndex);
4370
4580
  }
4371
4581
  function nextFocusForKey(key, modifiers, focus, rowCount, columnCount2, pageSize, isSkippableRow = noRowsSkippable) {
4372
4582
  if (modifiers.altKey) {
4373
4583
  return null;
4374
4584
  }
4375
- const { rowIndex, columnIndex } = focus;
4585
+ const { columnIndex } = focus;
4586
+ function moveRows(rows) {
4587
+ return skipSkippableRows(
4588
+ focusAtLine(linePosition(focus) + rows, columnIndex),
4589
+ rows < 0 ? -1 : 1,
4590
+ rowCount,
4591
+ isSkippableRow,
4592
+ focus
4593
+ );
4594
+ }
4376
4595
  switch (key) {
4377
4596
  case "ArrowLeft":
4378
4597
  if (modifiers.ctrlKey) return null;
4379
- return { rowIndex, columnIndex: columnIndex - 1 };
4598
+ return { ...focus, columnIndex: columnIndex - 1 };
4380
4599
  case "ArrowRight":
4381
4600
  if (modifiers.ctrlKey) return null;
4382
- return { rowIndex, columnIndex: columnIndex + 1 };
4601
+ return { ...focus, columnIndex: columnIndex + 1 };
4383
4602
  case "ArrowUp":
4384
- return {
4385
- rowIndex: skipSkippableRows(
4386
- rowIndex - 1,
4387
- -1,
4388
- rowCount,
4389
- isSkippableRow,
4390
- rowIndex
4391
- ),
4392
- columnIndex
4393
- };
4603
+ return moveRows(-1);
4394
4604
  case "ArrowDown":
4395
- return {
4396
- rowIndex: skipSkippableRows(
4397
- rowIndex + 1,
4398
- 1,
4399
- rowCount,
4400
- isSkippableRow,
4401
- rowIndex
4402
- ),
4403
- columnIndex
4404
- };
4605
+ return moveRows(1);
4405
4606
  // Ctrl takes Home and End to the grid's ends rather than the row's, which
4406
4607
  // is the one place Ctrl is navigation rather than reorder.
4407
4608
  case "Home":
4408
- return modifiers.ctrlKey ? { rowIndex: HEADER_ROW, columnIndex: 0 } : { rowIndex, columnIndex: 0 };
4409
- case "End":
4410
- return modifiers.ctrlKey ? {
4411
- rowIndex: skipSkippableRows(
4412
- rowCount - 1,
4413
- -1,
4414
- rowCount,
4415
- isSkippableRow,
4416
- rowIndex
4417
- ),
4418
- columnIndex: columnCount2 - 1
4419
- } : { rowIndex, columnIndex: columnCount2 - 1 };
4609
+ return modifiers.ctrlKey ? headerFocus(0) : { ...focus, columnIndex: 0 };
4610
+ case "End": {
4611
+ const rowEnd = { ...focus, columnIndex: columnCount2 - 1 };
4612
+ return modifiers.ctrlKey ? skipSkippableRows(
4613
+ focusAtLine(rowCount - 1, columnCount2 - 1),
4614
+ -1,
4615
+ rowCount,
4616
+ isSkippableRow,
4617
+ rowEnd
4618
+ ) : rowEnd;
4619
+ }
4420
4620
  case "PageUp":
4421
- return {
4422
- rowIndex: skipSkippableRows(
4423
- rowIndex - pageSize,
4424
- -1,
4425
- rowCount,
4426
- isSkippableRow,
4427
- rowIndex
4428
- ),
4429
- columnIndex
4430
- };
4621
+ return moveRows(-pageSize);
4431
4622
  case "PageDown":
4432
- return {
4433
- rowIndex: skipSkippableRows(
4434
- rowIndex + pageSize,
4435
- 1,
4436
- rowCount,
4437
- isSkippableRow,
4438
- rowIndex
4439
- ),
4440
- columnIndex
4441
- };
4623
+ return moveRows(pageSize);
4442
4624
  default:
4443
4625
  return null;
4444
4626
  }
@@ -4566,15 +4748,15 @@ function conditionOf(row, columnId, type) {
4566
4748
  const { operator } = row;
4567
4749
  switch (filterOperandArity(operator)) {
4568
4750
  case 0:
4569
- return { columnId, operator };
4751
+ return { kind: "operator", columnId, operator };
4570
4752
  case 1: {
4571
4753
  const value = parseFilterOperand(row.text, type);
4572
- return value === void 0 ? void 0 : { columnId, operator, value };
4754
+ return value === void 0 ? void 0 : { kind: "operator", columnId, operator, value };
4573
4755
  }
4574
4756
  case 2: {
4575
4757
  const low = parseFilterOperand(row.text, type);
4576
4758
  const high = parseFilterOperand(row.textTo, type);
4577
- return low === void 0 || high === void 0 ? void 0 : { columnId, operator, value: [low, high] };
4759
+ return low === void 0 || high === void 0 ? void 0 : { kind: "operator", columnId, operator, value: [low, high] };
4578
4760
  }
4579
4761
  }
4580
4762
  }
@@ -4704,9 +4886,10 @@ var excelFilter = {
4704
4886
  filterMenu: { ui: "excel", showCounts: true }
4705
4887
  };
4706
4888
  export {
4889
+ ALL_COLLAPSED,
4890
+ ALL_EXPANDED,
4707
4891
  DEFAULT_COLUMN_SIZES,
4708
4892
  DEFAULT_FILTER_VALUE_LIMIT,
4709
- HEADER_ROW,
4710
4893
  KEYBOARD_STEP,
4711
4894
  accessDotted,
4712
4895
  alignmentForType,
@@ -4715,6 +4898,7 @@ export {
4715
4898
  applyColumnVisibility,
4716
4899
  applySelectionIntent,
4717
4900
  beginColumnResize,
4901
+ bodyFocus,
4718
4902
  buildExportTable,
4719
4903
  buildKeyShortcuts,
4720
4904
  buildPrintDocument,
@@ -4750,6 +4934,7 @@ export {
4750
4934
  exportFile,
4751
4935
  exportPrintDocument,
4752
4936
  filterChecklist,
4937
+ filterDraftChanged,
4753
4938
  filterEditorReducer,
4754
4939
  filterOperandArity,
4755
4940
  filterOperatorFamily,
@@ -4765,10 +4950,12 @@ export {
4765
4950
  groupRowId,
4766
4951
  groupRows,
4767
4952
  hasContextMenu,
4953
+ headerFocus,
4768
4954
  initialFilterEditorDraft,
4769
4955
  intentOf,
4770
4956
  isColumnFiltered,
4771
4957
  isColumnVisible,
4958
+ isGroupExpanded,
4772
4959
  isPinnedToolbarItem,
4773
4960
  isSameCell,
4774
4961
  jsonWriter,
@@ -4819,10 +5006,12 @@ export {
4819
5006
  sortPriorityFor,
4820
5007
  sortRows,
4821
5008
  splitToolbarItems,
5009
+ toConditionsDraft,
4822
5010
  toCsv,
4823
5011
  toHtmlTable,
4824
5012
  toJson,
4825
5013
  toTsv,
5014
+ toValuesDraft,
4826
5015
  toggleCellSelection,
4827
5016
  toggleColumnSort,
4828
5017
  toggleGroupExpansion,