@vuu-ui/vuu-filters 0.6.21-debug → 0.6.22-debug
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/cjs/index.js +183 -87
- package/cjs/index.js.map +2 -2
- package/esm/index.js +186 -89
- package/esm/index.js.map +2 -2
- package/package.json +4 -4
- package/types/filter-input/useCodeMirrorEditor.d.ts +10 -4
- package/types/filter-input/useFilterAutoComplete.d.ts +4 -1
- package/types/filter-input/useFilterSuggestionProvider.d.ts +6 -1
package/esm/index.js
CHANGED
|
@@ -368,8 +368,6 @@ var vuuTheme = EditorView.theme(
|
|
|
368
368
|
|
|
369
369
|
// src/filter-input/useFilterAutoComplete.ts
|
|
370
370
|
import {
|
|
371
|
-
asNameSuggestion,
|
|
372
|
-
booleanJoinSuggestions,
|
|
373
371
|
getNodeByName,
|
|
374
372
|
getValue,
|
|
375
373
|
syntaxTree
|
|
@@ -409,6 +407,26 @@ var getClauseOperator = (node, state) => {
|
|
|
409
407
|
return void 0;
|
|
410
408
|
}
|
|
411
409
|
};
|
|
410
|
+
var getFilterName = (node, state) => {
|
|
411
|
+
if (node.name === "FilterName") {
|
|
412
|
+
return getValue(node, state);
|
|
413
|
+
} else {
|
|
414
|
+
let maybeTargetNode = node.prevSibling || node.parent || node.lastChild;
|
|
415
|
+
while (maybeTargetNode && maybeTargetNode.name !== "FilterName")
|
|
416
|
+
maybeTargetNode = maybeTargetNode.prevSibling;
|
|
417
|
+
if (maybeTargetNode && maybeTargetNode.name === "FilterName") {
|
|
418
|
+
return getValue(node, state);
|
|
419
|
+
}
|
|
420
|
+
}
|
|
421
|
+
};
|
|
422
|
+
var getColumnName = (node, state) => {
|
|
423
|
+
const prevNode = node.prevSibling;
|
|
424
|
+
if ((prevNode == null ? void 0 : prevNode.name) === "Column") {
|
|
425
|
+
return getValue(prevNode, state);
|
|
426
|
+
} else if ((prevNode == null ? void 0 : prevNode.name) === "Operator") {
|
|
427
|
+
return getColumnName(prevNode, state);
|
|
428
|
+
}
|
|
429
|
+
};
|
|
412
430
|
var getSetValues = (node, state) => {
|
|
413
431
|
let maybeTargetNode = node.lastChild;
|
|
414
432
|
const values = [];
|
|
@@ -423,57 +441,14 @@ var getSetValues = (node, state) => {
|
|
|
423
441
|
}
|
|
424
442
|
return values;
|
|
425
443
|
};
|
|
426
|
-
var promptForFilterName = (context) => ({
|
|
427
|
-
from: context.pos,
|
|
428
|
-
options: [
|
|
429
|
-
{
|
|
430
|
-
label: "enter name for this filter",
|
|
431
|
-
boost: 5
|
|
432
|
-
}
|
|
433
|
-
]
|
|
434
|
-
});
|
|
435
|
-
var makeSaveOrExtendSuggestions = (onSubmit, existingFilter, withJoinSuggestions = true) => {
|
|
436
|
-
const result = existingFilter ? [
|
|
437
|
-
{
|
|
438
|
-
label: "REPLACE existing filter",
|
|
439
|
-
apply: () => onSubmit("replace"),
|
|
440
|
-
boost: 8
|
|
441
|
-
},
|
|
442
|
-
{
|
|
443
|
-
label: "AND existing filter",
|
|
444
|
-
apply: () => onSubmit("and"),
|
|
445
|
-
boost: 7
|
|
446
|
-
},
|
|
447
|
-
{
|
|
448
|
-
label: "OR existing filter",
|
|
449
|
-
apply: () => onSubmit("or"),
|
|
450
|
-
boost: 7
|
|
451
|
-
}
|
|
452
|
-
] : [
|
|
453
|
-
{
|
|
454
|
-
label: "Press ENTER to submit",
|
|
455
|
-
apply: () => onSubmit(),
|
|
456
|
-
boost: 6
|
|
457
|
-
}
|
|
458
|
-
];
|
|
459
|
-
return withJoinSuggestions ? result.concat(booleanJoinSuggestions).concat(asNameSuggestion) : result;
|
|
460
|
-
};
|
|
461
|
-
var promptToSaveOrExtend = (context, onSubmit, existingFilter) => ({
|
|
462
|
-
from: context.pos,
|
|
463
|
-
options: makeSaveOrExtendSuggestions(onSubmit, existingFilter)
|
|
464
|
-
});
|
|
465
|
-
var promptToSave = (context, onSubmit, existingFilter) => ({
|
|
466
|
-
from: context.pos,
|
|
467
|
-
options: makeSaveOrExtendSuggestions(onSubmit, existingFilter, false)
|
|
468
|
-
});
|
|
469
444
|
var useAutoComplete = (suggestionProvider, onSubmit, existingFilter) => {
|
|
470
445
|
const makeSuggestions = useCallback(
|
|
471
446
|
async (context, suggestionType, optionalArgs = {}) => {
|
|
447
|
+
const { startsWith = "" } = optionalArgs;
|
|
472
448
|
const options = await suggestionProvider.getSuggestions(
|
|
473
449
|
suggestionType,
|
|
474
450
|
optionalArgs
|
|
475
451
|
);
|
|
476
|
-
const { startsWith = "" } = optionalArgs;
|
|
477
452
|
return { from: context.pos - startsWith.length, options };
|
|
478
453
|
},
|
|
479
454
|
[suggestionProvider]
|
|
@@ -497,19 +472,45 @@ var useAutoComplete = (suggestionProvider, onSubmit, existingFilter) => {
|
|
|
497
472
|
} else {
|
|
498
473
|
const clauseOperator = getClauseOperator(nodeBefore, state);
|
|
499
474
|
if (clauseOperator === "as") {
|
|
500
|
-
return
|
|
475
|
+
return makeSuggestions(context, "name");
|
|
501
476
|
} else {
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
onSubmit.current,
|
|
505
|
-
existingFilter
|
|
477
|
+
const filterName = getFilterName(nodeBefore, state);
|
|
478
|
+
return makeSuggestions(context, "save", {
|
|
479
|
+
onSubmit: onSubmit.current,
|
|
480
|
+
existingFilter,
|
|
481
|
+
filterName
|
|
482
|
+
});
|
|
483
|
+
}
|
|
484
|
+
}
|
|
485
|
+
case "String":
|
|
486
|
+
{
|
|
487
|
+
const operator = getOperator(nodeBefore, state);
|
|
488
|
+
const columnName = getColumnName(nodeBefore, state);
|
|
489
|
+
const { from, to } = nodeBefore;
|
|
490
|
+
if (to - from === 2 && context.pos === from + 1) {
|
|
491
|
+
if (columnName && operator) {
|
|
492
|
+
return makeSuggestions(context, "columnValue", {
|
|
493
|
+
columnName,
|
|
494
|
+
operator,
|
|
495
|
+
quoted: true,
|
|
496
|
+
startsWith: word.text
|
|
497
|
+
});
|
|
498
|
+
}
|
|
499
|
+
} else {
|
|
500
|
+
console.log(
|
|
501
|
+
`we have a string, column is ${columnName} ${from} ${to}`
|
|
506
502
|
);
|
|
507
503
|
}
|
|
508
504
|
}
|
|
505
|
+
break;
|
|
509
506
|
case "As":
|
|
510
|
-
return
|
|
507
|
+
return makeSuggestions(context, "name");
|
|
511
508
|
case "FilterName":
|
|
512
|
-
return
|
|
509
|
+
return makeSuggestions(context, "save", {
|
|
510
|
+
onSubmit: onSubmit.current,
|
|
511
|
+
existingFilter,
|
|
512
|
+
filterName: getFilterName(nodeBefore, state)
|
|
513
|
+
});
|
|
513
514
|
case "Column": {
|
|
514
515
|
const columnName = getValue(nodeBefore, state);
|
|
515
516
|
const isPartialMatch = await suggestionProvider.isPartialMatch(
|
|
@@ -766,6 +767,9 @@ var FilterInput = ({
|
|
|
766
767
|
|
|
767
768
|
// src/filter-input/useFilterSuggestionProvider.ts
|
|
768
769
|
import {
|
|
770
|
+
asNameSuggestion,
|
|
771
|
+
booleanJoinSuggestions,
|
|
772
|
+
getNamePrompt,
|
|
769
773
|
numericOperators,
|
|
770
774
|
stringOperators,
|
|
771
775
|
toSuggestions
|
|
@@ -789,6 +793,55 @@ var filterInfo = (filterName, filterQuery) => {
|
|
|
789
793
|
// src/filter-input/useFilterSuggestionProvider.ts
|
|
790
794
|
var NO_NAMED_FILTERS = [];
|
|
791
795
|
var NONE = {};
|
|
796
|
+
var saveAsTab = (onSubmit) => [
|
|
797
|
+
{
|
|
798
|
+
label: "Press ENTER to create TAB",
|
|
799
|
+
apply: () => onSubmit("tab"),
|
|
800
|
+
boost: 6
|
|
801
|
+
}
|
|
802
|
+
];
|
|
803
|
+
var makeSaveOrExtendSuggestions = (onSubmit, existingFilter, withJoinSuggestions = true) => {
|
|
804
|
+
const result = existingFilter ? [
|
|
805
|
+
{
|
|
806
|
+
label: "REPLACE existing filter",
|
|
807
|
+
apply: () => onSubmit("replace"),
|
|
808
|
+
boost: 8
|
|
809
|
+
},
|
|
810
|
+
{
|
|
811
|
+
label: "AND existing filter",
|
|
812
|
+
apply: () => onSubmit("and"),
|
|
813
|
+
boost: 7
|
|
814
|
+
},
|
|
815
|
+
{
|
|
816
|
+
label: "OR existing filter",
|
|
817
|
+
apply: () => onSubmit("or"),
|
|
818
|
+
boost: 7
|
|
819
|
+
}
|
|
820
|
+
] : [
|
|
821
|
+
{
|
|
822
|
+
label: "Press ENTER to submit",
|
|
823
|
+
apply: () => onSubmit(),
|
|
824
|
+
boost: 6
|
|
825
|
+
}
|
|
826
|
+
];
|
|
827
|
+
return withJoinSuggestions ? result.concat(booleanJoinSuggestions).concat(asNameSuggestion) : result;
|
|
828
|
+
};
|
|
829
|
+
var promptToSaveOrExtend = (onSubmit, existingFilter) => makeSaveOrExtendSuggestions(onSubmit, existingFilter, true);
|
|
830
|
+
var promptToSave = (onSubmit) => makeSaveOrExtendSuggestions(onSubmit, void 0);
|
|
831
|
+
var getSaveSuggestions = ({
|
|
832
|
+
existingFilter,
|
|
833
|
+
filterName,
|
|
834
|
+
onSubmit,
|
|
835
|
+
saveOptions
|
|
836
|
+
}) => {
|
|
837
|
+
const includeTabSuggestion = filterName && saveOptions.allowSaveAsTab;
|
|
838
|
+
const result = existingFilter ? promptToSaveOrExtend(onSubmit, existingFilter) : promptToSave(onSubmit);
|
|
839
|
+
if (includeTabSuggestion) {
|
|
840
|
+
return result.concat(saveAsTab(onSubmit));
|
|
841
|
+
} else {
|
|
842
|
+
return result;
|
|
843
|
+
}
|
|
844
|
+
};
|
|
792
845
|
var suggestColumns = (columns) => columns.map((column) => ({
|
|
793
846
|
boost: 5,
|
|
794
847
|
label: column.name
|
|
@@ -808,57 +861,101 @@ var withApplySpace = (suggestions, startsWith = "") => suggestions.filter((sugg)
|
|
|
808
861
|
...suggestion,
|
|
809
862
|
apply: suggestion.label + " "
|
|
810
863
|
}));
|
|
864
|
+
var defaultSaveOptions = {
|
|
865
|
+
allowReplace: true
|
|
866
|
+
};
|
|
811
867
|
var useFilterSuggestionProvider = ({
|
|
812
868
|
columns,
|
|
813
869
|
namedFilters,
|
|
870
|
+
saveOptions = defaultSaveOptions,
|
|
814
871
|
table
|
|
815
872
|
}) => {
|
|
816
873
|
const latestSuggestionsRef = useRef2();
|
|
817
874
|
const getTypeaheadSuggestions = useTypeaheadSuggestions();
|
|
818
875
|
const getSuggestions = useCallback2(
|
|
819
876
|
async (suggestionType, options = NONE) => {
|
|
820
|
-
const {
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
877
|
+
const {
|
|
878
|
+
columnName,
|
|
879
|
+
existingFilter,
|
|
880
|
+
filterName,
|
|
881
|
+
operator,
|
|
882
|
+
quoted: autoQuoted,
|
|
883
|
+
onSubmit,
|
|
884
|
+
startsWith,
|
|
885
|
+
selection
|
|
886
|
+
} = options;
|
|
887
|
+
switch (suggestionType) {
|
|
888
|
+
case "operator":
|
|
889
|
+
{
|
|
890
|
+
const column = columns.find((col) => col.name === columnName);
|
|
891
|
+
if (column) {
|
|
892
|
+
switch (column.serverDataType) {
|
|
893
|
+
case "string":
|
|
894
|
+
case "char":
|
|
895
|
+
return withApplySpace(stringOperators, startsWith);
|
|
896
|
+
case "int":
|
|
897
|
+
case "long":
|
|
898
|
+
case "double":
|
|
899
|
+
return withApplySpace(numericOperators);
|
|
900
|
+
}
|
|
901
|
+
} else {
|
|
902
|
+
console.warn(`'${columnName}' does not match any column name`);
|
|
903
|
+
}
|
|
832
904
|
}
|
|
833
|
-
|
|
834
|
-
|
|
905
|
+
break;
|
|
906
|
+
case "column": {
|
|
907
|
+
const columnSuggestions = await suggestColumns(columns);
|
|
908
|
+
const filterSuggestions = await suggestNamedFilters(namedFilters);
|
|
909
|
+
return (latestSuggestionsRef.current = withApplySpace(columnSuggestions)).concat(
|
|
910
|
+
withApplySpace(filterSuggestions)
|
|
911
|
+
);
|
|
835
912
|
}
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
913
|
+
case "columnValue":
|
|
914
|
+
{
|
|
915
|
+
if (columnName) {
|
|
916
|
+
const column = columns.find((col) => col.name === columnName);
|
|
917
|
+
const prefix = Array.isArray(selection) ? selection.length === 0 ? "[" : "," : "";
|
|
918
|
+
const params = getTypeaheadParams(
|
|
919
|
+
table,
|
|
920
|
+
columnName,
|
|
921
|
+
startsWith
|
|
922
|
+
);
|
|
923
|
+
const suggestions = await getTypeaheadSuggestions(params);
|
|
924
|
+
const isIllustration = operator === "starts";
|
|
925
|
+
latestSuggestionsRef.current = toSuggestions(suggestions, {
|
|
926
|
+
moveCursorToEnd: autoQuoted,
|
|
927
|
+
quoted: (column == null ? void 0 : column.serverDataType) === "string" && !autoQuoted,
|
|
928
|
+
suffix: autoQuoted ? "" : " ",
|
|
929
|
+
prefix: isIllustration ? startsWith : prefix,
|
|
930
|
+
isIllustration
|
|
931
|
+
});
|
|
932
|
+
if (Array.isArray(selection) && (selection == null ? void 0 : selection.length) > 1) {
|
|
933
|
+
return [doneCommand, ...latestSuggestionsRef.current];
|
|
934
|
+
}
|
|
935
|
+
return latestSuggestionsRef.current;
|
|
936
|
+
}
|
|
937
|
+
}
|
|
938
|
+
break;
|
|
939
|
+
case "save": {
|
|
940
|
+
if (typeof onSubmit !== "function") {
|
|
941
|
+
throw Error(
|
|
942
|
+
"useFilterSuggestionProvider, onSubmit must be supplied for 'save' suggestions"
|
|
943
|
+
);
|
|
944
|
+
}
|
|
945
|
+
return await getSaveSuggestions({
|
|
946
|
+
existingFilter,
|
|
947
|
+
filterName,
|
|
948
|
+
onSubmit,
|
|
949
|
+
saveOptions
|
|
950
|
+
});
|
|
856
951
|
}
|
|
857
|
-
|
|
952
|
+
case "name":
|
|
953
|
+
return await getNamePrompt("filter");
|
|
954
|
+
default:
|
|
858
955
|
}
|
|
859
956
|
return [];
|
|
860
957
|
},
|
|
861
|
-
[columns, getTypeaheadSuggestions, namedFilters, table]
|
|
958
|
+
[columns, getTypeaheadSuggestions, namedFilters, saveOptions, table]
|
|
862
959
|
);
|
|
863
960
|
const isPartialMatch = useCallback2(
|
|
864
961
|
async (valueType, columnName, pattern) => {
|