@gridkitjs/core 0.0.0-dev-20261109125954 → 0.0.0-dev-20261109131620
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 +63 -28
- package/dist/index.js +318 -231
- 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;
|
|
319
332
|
}
|
|
320
|
-
function collapseAllGroups(
|
|
321
|
-
return
|
|
322
|
-
|
|
323
|
-
|
|
333
|
+
function collapseAllGroups(expansion) {
|
|
334
|
+
return isWithoutExceptions(expansion, "allCollapsed") ? expansion : ALL_COLLAPSED;
|
|
335
|
+
}
|
|
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
|
|
@@ -2196,7 +2270,7 @@ function createGridController(initial) {
|
|
|
2196
2270
|
);
|
|
2197
2271
|
},
|
|
2198
2272
|
setGroupExpansion(expansion) {
|
|
2199
|
-
if (!
|
|
2273
|
+
if (!sameGroupExpansion(state.groupExpansion, expansion)) {
|
|
2200
2274
|
commitGroupExpansion(expansion, null);
|
|
2201
2275
|
}
|
|
2202
2276
|
},
|
|
@@ -2210,7 +2284,7 @@ function createGridController(initial) {
|
|
|
2210
2284
|
commitGroupExpansion(expandAllGroups(state.groupExpansion), null);
|
|
2211
2285
|
},
|
|
2212
2286
|
collapseAllGroups() {
|
|
2213
|
-
commitGroupExpansion(collapseAllGroups(
|
|
2287
|
+
commitGroupExpansion(collapseAllGroups(state.groupExpansion), null);
|
|
2214
2288
|
},
|
|
2215
2289
|
setPagination: commitPagination,
|
|
2216
2290
|
goToPage,
|
|
@@ -2248,7 +2322,7 @@ function createGridController(initial) {
|
|
|
2248
2322
|
controller.setGroupBy(saved.groupBy);
|
|
2249
2323
|
}
|
|
2250
2324
|
if (saved.groupExpansion !== void 0) {
|
|
2251
|
-
controller.setGroupExpansion(saved.groupExpansion);
|
|
2325
|
+
controller.setGroupExpansion(reviveGroupExpansion(saved.groupExpansion));
|
|
2252
2326
|
}
|
|
2253
2327
|
if (saved.pagination !== void 0) {
|
|
2254
2328
|
controller.setPagination(saved.pagination);
|
|
@@ -2592,7 +2666,12 @@ function buildExportTable(source, options = {}) {
|
|
|
2592
2666
|
messages: source.messages
|
|
2593
2667
|
};
|
|
2594
2668
|
const rows = scopedRows(source, options.scope ?? "all");
|
|
2595
|
-
const grouped = groupRows(
|
|
2669
|
+
const grouped = groupRows(
|
|
2670
|
+
rows,
|
|
2671
|
+
state.groupBy,
|
|
2672
|
+
ALL_EXPANDED,
|
|
2673
|
+
view.dataColumns
|
|
2674
|
+
);
|
|
2596
2675
|
const displayRows = options.includeGroups ?? true ? withGroupAggregates(
|
|
2597
2676
|
grouped,
|
|
2598
2677
|
rows,
|
|
@@ -3350,10 +3429,10 @@ function resolveMessages(messages, locale) {
|
|
|
3350
3429
|
|
|
3351
3430
|
// src/util/filterEditor.ts
|
|
3352
3431
|
function touchesColumn(entry, columnId) {
|
|
3353
|
-
return "
|
|
3432
|
+
return entry.kind === "group" ? entry.entries.some((nested) => touchesColumn(nested, columnId)) : entry.columnId === columnId;
|
|
3354
3433
|
}
|
|
3355
3434
|
function isOperatorOn(entry, columnId) {
|
|
3356
|
-
return "operator"
|
|
3435
|
+
return entry.kind === "operator" && entry.columnId === columnId;
|
|
3357
3436
|
}
|
|
3358
3437
|
function isConditionOn(entry, columnId) {
|
|
3359
3438
|
return isOperatorOn(entry, columnId) && entry.operator !== "in";
|
|
@@ -3365,7 +3444,7 @@ function valuesShape(entry, columnId) {
|
|
|
3365
3444
|
if (alone !== void 0) {
|
|
3366
3445
|
return { kind: "values", values: alone, includeBlanks: false };
|
|
3367
3446
|
}
|
|
3368
|
-
if (
|
|
3447
|
+
if (entry.kind !== "group" || entry.combinator !== "or" || entry.entries.length !== 2) {
|
|
3369
3448
|
return void 0;
|
|
3370
3449
|
}
|
|
3371
3450
|
const [first, second] = entry.entries;
|
|
@@ -3374,7 +3453,7 @@ function valuesShape(entry, columnId) {
|
|
|
3374
3453
|
}
|
|
3375
3454
|
function conditionsShape(touching, columnId) {
|
|
3376
3455
|
const [only] = touching;
|
|
3377
|
-
const grouped = touching.length === 1 && only !== void 0 && "
|
|
3456
|
+
const grouped = touching.length === 1 && only !== void 0 && only.kind === "group";
|
|
3378
3457
|
const entries = grouped ? only.entries : touching;
|
|
3379
3458
|
const combinator = grouped ? only.combinator : "and";
|
|
3380
3459
|
if (entries.length === 0 || entries.length > 2) {
|
|
@@ -3569,20 +3648,25 @@ function draftEntries(draft, columnId) {
|
|
|
3569
3648
|
...condition,
|
|
3570
3649
|
columnId
|
|
3571
3650
|
}));
|
|
3572
|
-
return conditions.length > 1 ? [{ combinator: draft.combinator, entries: conditions }] : conditions;
|
|
3651
|
+
return conditions.length > 1 ? [{ kind: "group", combinator: draft.combinator, entries: conditions }] : conditions;
|
|
3573
3652
|
}
|
|
3574
3653
|
if (checksEverything(draft)) {
|
|
3575
3654
|
return [];
|
|
3576
3655
|
}
|
|
3577
3656
|
const picked = {
|
|
3657
|
+
kind: "operator",
|
|
3578
3658
|
columnId,
|
|
3579
3659
|
operator: "in",
|
|
3580
3660
|
value: [...draft.checked.values()]
|
|
3581
3661
|
};
|
|
3582
3662
|
return draft.includeBlanks ? [
|
|
3583
3663
|
{
|
|
3664
|
+
kind: "group",
|
|
3584
3665
|
combinator: "or",
|
|
3585
|
-
entries: [
|
|
3666
|
+
entries: [
|
|
3667
|
+
picked,
|
|
3668
|
+
{ kind: "operator", columnId, operator: "isEmpty" }
|
|
3669
|
+
]
|
|
3586
3670
|
}
|
|
3587
3671
|
] : [picked];
|
|
3588
3672
|
}
|
|
@@ -4636,15 +4720,15 @@ function conditionOf(row, columnId, type) {
|
|
|
4636
4720
|
const { operator } = row;
|
|
4637
4721
|
switch (filterOperandArity(operator)) {
|
|
4638
4722
|
case 0:
|
|
4639
|
-
return { columnId, operator };
|
|
4723
|
+
return { kind: "operator", columnId, operator };
|
|
4640
4724
|
case 1: {
|
|
4641
4725
|
const value = parseFilterOperand(row.text, type);
|
|
4642
|
-
return value === void 0 ? void 0 : { columnId, operator, value };
|
|
4726
|
+
return value === void 0 ? void 0 : { kind: "operator", columnId, operator, value };
|
|
4643
4727
|
}
|
|
4644
4728
|
case 2: {
|
|
4645
4729
|
const low = parseFilterOperand(row.text, type);
|
|
4646
4730
|
const high = parseFilterOperand(row.textTo, type);
|
|
4647
|
-
return low === void 0 || high === void 0 ? void 0 : { columnId, operator, value: [low, high] };
|
|
4731
|
+
return low === void 0 || high === void 0 ? void 0 : { kind: "operator", columnId, operator, value: [low, high] };
|
|
4648
4732
|
}
|
|
4649
4733
|
}
|
|
4650
4734
|
}
|
|
@@ -4774,6 +4858,8 @@ var excelFilter = {
|
|
|
4774
4858
|
filterMenu: { ui: "excel", showCounts: true }
|
|
4775
4859
|
};
|
|
4776
4860
|
export {
|
|
4861
|
+
ALL_COLLAPSED,
|
|
4862
|
+
ALL_EXPANDED,
|
|
4777
4863
|
DEFAULT_COLUMN_SIZES,
|
|
4778
4864
|
DEFAULT_FILTER_VALUE_LIMIT,
|
|
4779
4865
|
HEADER_ROW,
|
|
@@ -4840,6 +4926,7 @@ export {
|
|
|
4840
4926
|
intentOf,
|
|
4841
4927
|
isColumnFiltered,
|
|
4842
4928
|
isColumnVisible,
|
|
4929
|
+
isGroupExpanded,
|
|
4843
4930
|
isPinnedToolbarItem,
|
|
4844
4931
|
isSameCell,
|
|
4845
4932
|
jsonWriter,
|