@gridkitjs/core 0.16.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.d.ts +163 -71
- package/dist/index.js +491 -366
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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 =
|
|
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
|
-
|
|
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
|
|
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
|
|
321
|
-
return
|
|
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
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
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
|
|
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
|
-
|
|
705
|
-
|
|
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
|
-
|
|
709
|
-
|
|
710
|
-
|
|
711
|
-
|
|
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
|
-
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
|
|
1412
|
-
|
|
1413
|
-
|
|
1414
|
-
|
|
1415
|
-
|
|
1416
|
-
|
|
1417
|
-
|
|
1418
|
-
|
|
1419
|
-
|
|
1420
|
-
|
|
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) => {
|
|
@@ -1791,7 +1865,7 @@ function startingState(options) {
|
|
|
1791
1865
|
columnSort: options.defaultColumnSort ?? [],
|
|
1792
1866
|
filter: options.defaultFilter ?? [],
|
|
1793
1867
|
groupBy: options.defaultGroupBy ?? [],
|
|
1794
|
-
groupExpansion: options.defaultGroupExpansion ??
|
|
1868
|
+
groupExpansion: options.defaultGroupExpansion ?? ALL_EXPANDED,
|
|
1795
1869
|
pagination: options.defaultPagination ?? {
|
|
1796
1870
|
pageIndex: 0,
|
|
1797
1871
|
pageSize: DEFAULT_PAGE_SIZE
|
|
@@ -1872,9 +1946,11 @@ function createGridController(initial) {
|
|
|
1872
1946
|
}
|
|
1873
1947
|
}
|
|
1874
1948
|
function refresh(keepPage = false) {
|
|
1949
|
+
const before = state;
|
|
1875
1950
|
const next = followPagingInputs(resolveSlices(), keepPage);
|
|
1876
1951
|
state = SLICE_KEYS.every((key) => next[key] === state[key]) ? state : next;
|
|
1877
1952
|
storeShownPage();
|
|
1953
|
+
return state !== before;
|
|
1878
1954
|
}
|
|
1879
1955
|
function followPagingInputs(next, keepPage) {
|
|
1880
1956
|
const inputs = pagingInputsOf(next, options);
|
|
@@ -1918,9 +1994,11 @@ function createGridController(initial) {
|
|
|
1918
1994
|
mode.held.push(report);
|
|
1919
1995
|
return;
|
|
1920
1996
|
}
|
|
1921
|
-
refresh();
|
|
1997
|
+
const changed = refresh();
|
|
1922
1998
|
report();
|
|
1923
|
-
|
|
1999
|
+
if (changed) {
|
|
2000
|
+
notify();
|
|
2001
|
+
}
|
|
1924
2002
|
}
|
|
1925
2003
|
function transaction(run) {
|
|
1926
2004
|
if (mode.kind === "transaction") {
|
|
@@ -1937,11 +2015,11 @@ function createGridController(initial) {
|
|
|
1937
2015
|
run();
|
|
1938
2016
|
} finally {
|
|
1939
2017
|
mode = IDLE;
|
|
1940
|
-
refresh(current.pageAsked);
|
|
2018
|
+
const changed = refresh(current.pageAsked);
|
|
1941
2019
|
for (const report of current.held) {
|
|
1942
2020
|
report();
|
|
1943
2021
|
}
|
|
1944
|
-
if (
|
|
2022
|
+
if (changed) {
|
|
1945
2023
|
notify();
|
|
1946
2024
|
}
|
|
1947
2025
|
}
|
|
@@ -2192,7 +2270,7 @@ function createGridController(initial) {
|
|
|
2192
2270
|
);
|
|
2193
2271
|
},
|
|
2194
2272
|
setGroupExpansion(expansion) {
|
|
2195
|
-
if (!
|
|
2273
|
+
if (!sameGroupExpansion(state.groupExpansion, expansion)) {
|
|
2196
2274
|
commitGroupExpansion(expansion, null);
|
|
2197
2275
|
}
|
|
2198
2276
|
},
|
|
@@ -2206,7 +2284,7 @@ function createGridController(initial) {
|
|
|
2206
2284
|
commitGroupExpansion(expandAllGroups(state.groupExpansion), null);
|
|
2207
2285
|
},
|
|
2208
2286
|
collapseAllGroups() {
|
|
2209
|
-
commitGroupExpansion(collapseAllGroups(
|
|
2287
|
+
commitGroupExpansion(collapseAllGroups(state.groupExpansion), null);
|
|
2210
2288
|
},
|
|
2211
2289
|
setPagination: commitPagination,
|
|
2212
2290
|
goToPage,
|
|
@@ -2244,7 +2322,7 @@ function createGridController(initial) {
|
|
|
2244
2322
|
controller.setGroupBy(saved.groupBy);
|
|
2245
2323
|
}
|
|
2246
2324
|
if (saved.groupExpansion !== void 0) {
|
|
2247
|
-
controller.setGroupExpansion(saved.groupExpansion);
|
|
2325
|
+
controller.setGroupExpansion(reviveGroupExpansion(saved.groupExpansion));
|
|
2248
2326
|
}
|
|
2249
2327
|
if (saved.pagination !== void 0) {
|
|
2250
2328
|
controller.setPagination(saved.pagination);
|
|
@@ -2588,7 +2666,12 @@ function buildExportTable(source, options = {}) {
|
|
|
2588
2666
|
messages: source.messages
|
|
2589
2667
|
};
|
|
2590
2668
|
const rows = scopedRows(source, options.scope ?? "all");
|
|
2591
|
-
const grouped = groupRows(
|
|
2669
|
+
const grouped = groupRows(
|
|
2670
|
+
rows,
|
|
2671
|
+
state.groupBy,
|
|
2672
|
+
ALL_EXPANDED,
|
|
2673
|
+
view.dataColumns
|
|
2674
|
+
);
|
|
2592
2675
|
const displayRows = options.includeGroups ?? true ? withGroupAggregates(
|
|
2593
2676
|
grouped,
|
|
2594
2677
|
rows,
|
|
@@ -3346,10 +3429,10 @@ function resolveMessages(messages, locale) {
|
|
|
3346
3429
|
|
|
3347
3430
|
// src/util/filterEditor.ts
|
|
3348
3431
|
function touchesColumn(entry, columnId) {
|
|
3349
|
-
return "
|
|
3432
|
+
return entry.kind === "group" ? entry.entries.some((nested) => touchesColumn(nested, columnId)) : entry.columnId === columnId;
|
|
3350
3433
|
}
|
|
3351
3434
|
function isOperatorOn(entry, columnId) {
|
|
3352
|
-
return "operator"
|
|
3435
|
+
return entry.kind === "operator" && entry.columnId === columnId;
|
|
3353
3436
|
}
|
|
3354
3437
|
function isConditionOn(entry, columnId) {
|
|
3355
3438
|
return isOperatorOn(entry, columnId) && entry.operator !== "in";
|
|
@@ -3361,7 +3444,7 @@ function valuesShape(entry, columnId) {
|
|
|
3361
3444
|
if (alone !== void 0) {
|
|
3362
3445
|
return { kind: "values", values: alone, includeBlanks: false };
|
|
3363
3446
|
}
|
|
3364
|
-
if (
|
|
3447
|
+
if (entry.kind !== "group" || entry.combinator !== "or" || entry.entries.length !== 2) {
|
|
3365
3448
|
return void 0;
|
|
3366
3449
|
}
|
|
3367
3450
|
const [first, second] = entry.entries;
|
|
@@ -3370,7 +3453,7 @@ function valuesShape(entry, columnId) {
|
|
|
3370
3453
|
}
|
|
3371
3454
|
function conditionsShape(touching, columnId) {
|
|
3372
3455
|
const [only] = touching;
|
|
3373
|
-
const grouped = touching.length === 1 && only !== void 0 && "
|
|
3456
|
+
const grouped = touching.length === 1 && only !== void 0 && only.kind === "group";
|
|
3374
3457
|
const entries = grouped ? only.entries : touching;
|
|
3375
3458
|
const combinator = grouped ? only.combinator : "and";
|
|
3376
3459
|
if (entries.length === 0 || entries.length > 2) {
|
|
@@ -3448,38 +3531,53 @@ function everyOption(draft) {
|
|
|
3448
3531
|
draft.options.map((option) => [keyOf2(draft, option.value), option.value])
|
|
3449
3532
|
);
|
|
3450
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
|
+
}
|
|
3451
3566
|
function initialFilterEditorDraft(shape, values) {
|
|
3452
|
-
const
|
|
3453
|
-
mode: "values",
|
|
3567
|
+
const base = {
|
|
3454
3568
|
options: values.options,
|
|
3455
3569
|
blanks: values.blanks,
|
|
3456
3570
|
search: "",
|
|
3457
|
-
|
|
3458
|
-
includeBlanks: values.blanks > 0,
|
|
3459
|
-
conditions: [],
|
|
3460
|
-
combinator: "and",
|
|
3571
|
+
openedShape: shape,
|
|
3461
3572
|
columnType: values.columnType
|
|
3462
3573
|
};
|
|
3463
|
-
|
|
3464
|
-
|
|
3465
|
-
|
|
3466
|
-
|
|
3467
|
-
|
|
3468
|
-
|
|
3469
|
-
|
|
3470
|
-
includeBlanks: shape.includeBlanks
|
|
3471
|
-
};
|
|
3472
|
-
case "conditions":
|
|
3473
|
-
return {
|
|
3474
|
-
...draft,
|
|
3475
|
-
mode: "conditions",
|
|
3476
|
-
conditions: shape.conditions,
|
|
3477
|
-
combinator: shape.combinator
|
|
3478
|
-
};
|
|
3479
|
-
case "none":
|
|
3480
|
-
case "custom":
|
|
3481
|
-
return draft;
|
|
3482
|
-
}
|
|
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));
|
|
3483
3581
|
}
|
|
3484
3582
|
function visibleFilterOptions(draft) {
|
|
3485
3583
|
return draft.search === "" ? draft.options : draft.options.filter(
|
|
@@ -3501,6 +3599,16 @@ function selectAllState(draft) {
|
|
|
3501
3599
|
}
|
|
3502
3600
|
return states.some(Boolean) ? "mixed" : "unchecked";
|
|
3503
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
|
+
}
|
|
3504
3612
|
function toggleAll(draft) {
|
|
3505
3613
|
const check = selectAllState(draft) !== "checked";
|
|
3506
3614
|
const checked = new Map(draft.checked);
|
|
@@ -3514,44 +3622,43 @@ function toggleAll(draft) {
|
|
|
3514
3622
|
}
|
|
3515
3623
|
return {
|
|
3516
3624
|
...draft,
|
|
3517
|
-
mode: "values",
|
|
3518
3625
|
checked,
|
|
3519
3626
|
includeBlanks: selectAllCoversBlanks(draft) ? check : draft.includeBlanks
|
|
3520
3627
|
};
|
|
3521
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
|
+
}
|
|
3522
3642
|
function filterEditorReducer(draft, action) {
|
|
3523
3643
|
switch (action.type) {
|
|
3524
3644
|
case "search":
|
|
3525
3645
|
return { ...draft, search: action.search };
|
|
3526
|
-
case "toggleValue":
|
|
3527
|
-
|
|
3528
|
-
const checked = new Map(draft.checked);
|
|
3529
|
-
if (checked.has(key)) {
|
|
3530
|
-
checked.delete(key);
|
|
3531
|
-
} else {
|
|
3532
|
-
checked.set(key, action.value);
|
|
3533
|
-
}
|
|
3534
|
-
return { ...draft, mode: "values", checked };
|
|
3535
|
-
}
|
|
3646
|
+
case "toggleValue":
|
|
3647
|
+
return toggleValue(toValuesDraft(draft), action.value);
|
|
3536
3648
|
case "toggleAll":
|
|
3537
|
-
return toggleAll(draft);
|
|
3649
|
+
return toggleAll(toValuesDraft(draft));
|
|
3538
3650
|
case "setIncludeBlanks":
|
|
3539
|
-
return { ...draft,
|
|
3540
|
-
case "setConditions":
|
|
3651
|
+
return { ...toValuesDraft(draft), includeBlanks: action.includeBlanks };
|
|
3652
|
+
case "setConditions": {
|
|
3653
|
+
const conditions = toConditionsDraft(draft);
|
|
3541
3654
|
return {
|
|
3542
|
-
...
|
|
3543
|
-
mode: "conditions",
|
|
3655
|
+
...conditions,
|
|
3544
3656
|
conditions: action.conditions,
|
|
3545
|
-
combinator: action.combinator ??
|
|
3657
|
+
combinator: action.combinator ?? conditions.combinator
|
|
3546
3658
|
};
|
|
3659
|
+
}
|
|
3547
3660
|
case "clear":
|
|
3548
|
-
return
|
|
3549
|
-
...draft,
|
|
3550
|
-
search: "",
|
|
3551
|
-
checked: everyOption(draft),
|
|
3552
|
-
includeBlanks: draft.blanks > 0,
|
|
3553
|
-
conditions: []
|
|
3554
|
-
};
|
|
3661
|
+
return cleared(draft);
|
|
3555
3662
|
}
|
|
3556
3663
|
}
|
|
3557
3664
|
function checksEverything(draft) {
|
|
@@ -3559,29 +3666,42 @@ function checksEverything(draft) {
|
|
|
3559
3666
|
(option) => draft.checked.has(keyOf2(draft, option.value))
|
|
3560
3667
|
) && (draft.includeBlanks || draft.blanks === 0);
|
|
3561
3668
|
}
|
|
3562
|
-
function
|
|
3563
|
-
if (draft.mode === "conditions") {
|
|
3564
|
-
const conditions = draft.conditions.map((condition) => ({
|
|
3565
|
-
...condition,
|
|
3566
|
-
columnId
|
|
3567
|
-
}));
|
|
3568
|
-
return conditions.length > 1 ? [{ combinator: draft.combinator, entries: conditions }] : conditions;
|
|
3569
|
-
}
|
|
3669
|
+
function valuesEntries(draft, columnId) {
|
|
3570
3670
|
if (checksEverything(draft)) {
|
|
3571
3671
|
return [];
|
|
3572
3672
|
}
|
|
3573
3673
|
const picked = {
|
|
3674
|
+
kind: "operator",
|
|
3574
3675
|
columnId,
|
|
3575
3676
|
operator: "in",
|
|
3576
3677
|
value: [...draft.checked.values()]
|
|
3577
3678
|
};
|
|
3578
3679
|
return draft.includeBlanks ? [
|
|
3579
3680
|
{
|
|
3681
|
+
kind: "group",
|
|
3580
3682
|
combinator: "or",
|
|
3581
|
-
entries: [
|
|
3683
|
+
entries: [
|
|
3684
|
+
picked,
|
|
3685
|
+
{ kind: "operator", columnId, operator: "isEmpty" }
|
|
3686
|
+
]
|
|
3582
3687
|
}
|
|
3583
3688
|
] : [picked];
|
|
3584
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
|
+
}
|
|
3585
3705
|
function draftToFilter(draft, columnId, current) {
|
|
3586
3706
|
const replacement = draftEntries(draft, columnId);
|
|
3587
3707
|
const first = current.findIndex((entry) => touchesColumn(entry, columnId));
|
|
@@ -3607,10 +3727,12 @@ function sameConditions(a, b) {
|
|
|
3607
3727
|
});
|
|
3608
3728
|
}
|
|
3609
3729
|
function filterDraftChanged(opened, draft) {
|
|
3610
|
-
|
|
3611
|
-
|
|
3730
|
+
switch (draft.kind) {
|
|
3731
|
+
case "values":
|
|
3732
|
+
return !sameValues(toValuesDraft(opened), draft);
|
|
3733
|
+
case "conditions":
|
|
3734
|
+
return opened.kind !== "conditions" || !sameConditions(opened, draft);
|
|
3612
3735
|
}
|
|
3613
|
-
return opened.mode !== "conditions" || !sameConditions(opened, draft);
|
|
3614
3736
|
}
|
|
3615
3737
|
|
|
3616
3738
|
// src/commands/builtInCommands.ts
|
|
@@ -3706,6 +3828,9 @@ function exportCommand({
|
|
|
3706
3828
|
isVisible: (context) => isOn(context, EXPORT_AREAS) && resolveExportWriters(context.options.exportWriters).has(format) && (!selection || context.state.rowSelection.length > 0),
|
|
3707
3829
|
isEnabled: (context) => (selection ? context.selectedRows() : context.view.rows).length > 0,
|
|
3708
3830
|
execute: (context) => {
|
|
3831
|
+
if (context.host.canSave?.() === false) {
|
|
3832
|
+
return false;
|
|
3833
|
+
}
|
|
3709
3834
|
const { export: defaults = {}, exportWriters } = context.options;
|
|
3710
3835
|
const file = exportFile(
|
|
3711
3836
|
context,
|
|
@@ -4407,101 +4532,95 @@ function setSearchText(filter, text) {
|
|
|
4407
4532
|
}
|
|
4408
4533
|
|
|
4409
4534
|
// src/util/navigation.ts
|
|
4410
|
-
|
|
4535
|
+
function headerFocus(columnIndex) {
|
|
4536
|
+
return { area: "header", columnIndex };
|
|
4537
|
+
}
|
|
4538
|
+
function bodyFocus(rowIndex, columnIndex) {
|
|
4539
|
+
return { area: "body", rowIndex, columnIndex };
|
|
4540
|
+
}
|
|
4411
4541
|
function clampFocus(focus, rowCount, columnCount2) {
|
|
4412
|
-
|
|
4413
|
-
|
|
4414
|
-
|
|
4415
|
-
|
|
4416
|
-
|
|
4417
|
-
|
|
4418
|
-
|
|
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
|
+
}
|
|
4419
4554
|
}
|
|
4420
4555
|
function noRowsSkippable() {
|
|
4421
4556
|
return false;
|
|
4422
4557
|
}
|
|
4423
|
-
function
|
|
4424
|
-
|
|
4425
|
-
|
|
4426
|
-
|
|
4427
|
-
|
|
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) {
|
|
4428
4572
|
return fallback;
|
|
4429
4573
|
}
|
|
4430
|
-
|
|
4574
|
+
if (stepped < 0) {
|
|
4575
|
+
return headerFocus(target.columnIndex);
|
|
4576
|
+
}
|
|
4577
|
+
rowIndex = stepped;
|
|
4431
4578
|
}
|
|
4432
|
-
return
|
|
4579
|
+
return bodyFocus(rowIndex, target.columnIndex);
|
|
4433
4580
|
}
|
|
4434
4581
|
function nextFocusForKey(key, modifiers, focus, rowCount, columnCount2, pageSize, isSkippableRow = noRowsSkippable) {
|
|
4435
4582
|
if (modifiers.altKey) {
|
|
4436
4583
|
return null;
|
|
4437
4584
|
}
|
|
4438
|
-
const {
|
|
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
|
+
}
|
|
4439
4595
|
switch (key) {
|
|
4440
4596
|
case "ArrowLeft":
|
|
4441
4597
|
if (modifiers.ctrlKey) return null;
|
|
4442
|
-
return {
|
|
4598
|
+
return { ...focus, columnIndex: columnIndex - 1 };
|
|
4443
4599
|
case "ArrowRight":
|
|
4444
4600
|
if (modifiers.ctrlKey) return null;
|
|
4445
|
-
return {
|
|
4601
|
+
return { ...focus, columnIndex: columnIndex + 1 };
|
|
4446
4602
|
case "ArrowUp":
|
|
4447
|
-
return
|
|
4448
|
-
rowIndex: skipSkippableRows(
|
|
4449
|
-
rowIndex - 1,
|
|
4450
|
-
-1,
|
|
4451
|
-
rowCount,
|
|
4452
|
-
isSkippableRow,
|
|
4453
|
-
rowIndex
|
|
4454
|
-
),
|
|
4455
|
-
columnIndex
|
|
4456
|
-
};
|
|
4603
|
+
return moveRows(-1);
|
|
4457
4604
|
case "ArrowDown":
|
|
4458
|
-
return
|
|
4459
|
-
rowIndex: skipSkippableRows(
|
|
4460
|
-
rowIndex + 1,
|
|
4461
|
-
1,
|
|
4462
|
-
rowCount,
|
|
4463
|
-
isSkippableRow,
|
|
4464
|
-
rowIndex
|
|
4465
|
-
),
|
|
4466
|
-
columnIndex
|
|
4467
|
-
};
|
|
4605
|
+
return moveRows(1);
|
|
4468
4606
|
// Ctrl takes Home and End to the grid's ends rather than the row's, which
|
|
4469
4607
|
// is the one place Ctrl is navigation rather than reorder.
|
|
4470
4608
|
case "Home":
|
|
4471
|
-
return modifiers.ctrlKey ?
|
|
4472
|
-
case "End":
|
|
4473
|
-
|
|
4474
|
-
|
|
4475
|
-
|
|
4476
|
-
|
|
4477
|
-
|
|
4478
|
-
|
|
4479
|
-
|
|
4480
|
-
|
|
4481
|
-
|
|
4482
|
-
} : { 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
|
+
}
|
|
4483
4620
|
case "PageUp":
|
|
4484
|
-
return
|
|
4485
|
-
rowIndex: skipSkippableRows(
|
|
4486
|
-
rowIndex - pageSize,
|
|
4487
|
-
-1,
|
|
4488
|
-
rowCount,
|
|
4489
|
-
isSkippableRow,
|
|
4490
|
-
rowIndex
|
|
4491
|
-
),
|
|
4492
|
-
columnIndex
|
|
4493
|
-
};
|
|
4621
|
+
return moveRows(-pageSize);
|
|
4494
4622
|
case "PageDown":
|
|
4495
|
-
return
|
|
4496
|
-
rowIndex: skipSkippableRows(
|
|
4497
|
-
rowIndex + pageSize,
|
|
4498
|
-
1,
|
|
4499
|
-
rowCount,
|
|
4500
|
-
isSkippableRow,
|
|
4501
|
-
rowIndex
|
|
4502
|
-
),
|
|
4503
|
-
columnIndex
|
|
4504
|
-
};
|
|
4623
|
+
return moveRows(pageSize);
|
|
4505
4624
|
default:
|
|
4506
4625
|
return null;
|
|
4507
4626
|
}
|
|
@@ -4629,15 +4748,15 @@ function conditionOf(row, columnId, type) {
|
|
|
4629
4748
|
const { operator } = row;
|
|
4630
4749
|
switch (filterOperandArity(operator)) {
|
|
4631
4750
|
case 0:
|
|
4632
|
-
return { columnId, operator };
|
|
4751
|
+
return { kind: "operator", columnId, operator };
|
|
4633
4752
|
case 1: {
|
|
4634
4753
|
const value = parseFilterOperand(row.text, type);
|
|
4635
|
-
return value === void 0 ? void 0 : { columnId, operator, value };
|
|
4754
|
+
return value === void 0 ? void 0 : { kind: "operator", columnId, operator, value };
|
|
4636
4755
|
}
|
|
4637
4756
|
case 2: {
|
|
4638
4757
|
const low = parseFilterOperand(row.text, type);
|
|
4639
4758
|
const high = parseFilterOperand(row.textTo, type);
|
|
4640
|
-
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] };
|
|
4641
4760
|
}
|
|
4642
4761
|
}
|
|
4643
4762
|
}
|
|
@@ -4767,9 +4886,10 @@ var excelFilter = {
|
|
|
4767
4886
|
filterMenu: { ui: "excel", showCounts: true }
|
|
4768
4887
|
};
|
|
4769
4888
|
export {
|
|
4889
|
+
ALL_COLLAPSED,
|
|
4890
|
+
ALL_EXPANDED,
|
|
4770
4891
|
DEFAULT_COLUMN_SIZES,
|
|
4771
4892
|
DEFAULT_FILTER_VALUE_LIMIT,
|
|
4772
|
-
HEADER_ROW,
|
|
4773
4893
|
KEYBOARD_STEP,
|
|
4774
4894
|
accessDotted,
|
|
4775
4895
|
alignmentForType,
|
|
@@ -4778,6 +4898,7 @@ export {
|
|
|
4778
4898
|
applyColumnVisibility,
|
|
4779
4899
|
applySelectionIntent,
|
|
4780
4900
|
beginColumnResize,
|
|
4901
|
+
bodyFocus,
|
|
4781
4902
|
buildExportTable,
|
|
4782
4903
|
buildKeyShortcuts,
|
|
4783
4904
|
buildPrintDocument,
|
|
@@ -4829,10 +4950,12 @@ export {
|
|
|
4829
4950
|
groupRowId,
|
|
4830
4951
|
groupRows,
|
|
4831
4952
|
hasContextMenu,
|
|
4953
|
+
headerFocus,
|
|
4832
4954
|
initialFilterEditorDraft,
|
|
4833
4955
|
intentOf,
|
|
4834
4956
|
isColumnFiltered,
|
|
4835
4957
|
isColumnVisible,
|
|
4958
|
+
isGroupExpanded,
|
|
4836
4959
|
isPinnedToolbarItem,
|
|
4837
4960
|
isSameCell,
|
|
4838
4961
|
jsonWriter,
|
|
@@ -4883,10 +5006,12 @@ export {
|
|
|
4883
5006
|
sortPriorityFor,
|
|
4884
5007
|
sortRows,
|
|
4885
5008
|
splitToolbarItems,
|
|
5009
|
+
toConditionsDraft,
|
|
4886
5010
|
toCsv,
|
|
4887
5011
|
toHtmlTable,
|
|
4888
5012
|
toJson,
|
|
4889
5013
|
toTsv,
|
|
5014
|
+
toValuesDraft,
|
|
4890
5015
|
toggleCellSelection,
|
|
4891
5016
|
toggleColumnSort,
|
|
4892
5017
|
toggleGroupExpansion,
|