@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/cjs/index.js
CHANGED
|
@@ -426,6 +426,26 @@ var getClauseOperator = (node, state) => {
|
|
|
426
426
|
return void 0;
|
|
427
427
|
}
|
|
428
428
|
};
|
|
429
|
+
var getFilterName = (node, state) => {
|
|
430
|
+
if (node.name === "FilterName") {
|
|
431
|
+
return (0, import_vuu_codemirror5.getValue)(node, state);
|
|
432
|
+
} else {
|
|
433
|
+
let maybeTargetNode = node.prevSibling || node.parent || node.lastChild;
|
|
434
|
+
while (maybeTargetNode && maybeTargetNode.name !== "FilterName")
|
|
435
|
+
maybeTargetNode = maybeTargetNode.prevSibling;
|
|
436
|
+
if (maybeTargetNode && maybeTargetNode.name === "FilterName") {
|
|
437
|
+
return (0, import_vuu_codemirror5.getValue)(node, state);
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
};
|
|
441
|
+
var getColumnName = (node, state) => {
|
|
442
|
+
const prevNode = node.prevSibling;
|
|
443
|
+
if ((prevNode == null ? void 0 : prevNode.name) === "Column") {
|
|
444
|
+
return (0, import_vuu_codemirror5.getValue)(prevNode, state);
|
|
445
|
+
} else if ((prevNode == null ? void 0 : prevNode.name) === "Operator") {
|
|
446
|
+
return getColumnName(prevNode, state);
|
|
447
|
+
}
|
|
448
|
+
};
|
|
429
449
|
var getSetValues = (node, state) => {
|
|
430
450
|
let maybeTargetNode = node.lastChild;
|
|
431
451
|
const values = [];
|
|
@@ -440,57 +460,14 @@ var getSetValues = (node, state) => {
|
|
|
440
460
|
}
|
|
441
461
|
return values;
|
|
442
462
|
};
|
|
443
|
-
var promptForFilterName = (context) => ({
|
|
444
|
-
from: context.pos,
|
|
445
|
-
options: [
|
|
446
|
-
{
|
|
447
|
-
label: "enter name for this filter",
|
|
448
|
-
boost: 5
|
|
449
|
-
}
|
|
450
|
-
]
|
|
451
|
-
});
|
|
452
|
-
var makeSaveOrExtendSuggestions = (onSubmit, existingFilter, withJoinSuggestions = true) => {
|
|
453
|
-
const result = existingFilter ? [
|
|
454
|
-
{
|
|
455
|
-
label: "REPLACE existing filter",
|
|
456
|
-
apply: () => onSubmit("replace"),
|
|
457
|
-
boost: 8
|
|
458
|
-
},
|
|
459
|
-
{
|
|
460
|
-
label: "AND existing filter",
|
|
461
|
-
apply: () => onSubmit("and"),
|
|
462
|
-
boost: 7
|
|
463
|
-
},
|
|
464
|
-
{
|
|
465
|
-
label: "OR existing filter",
|
|
466
|
-
apply: () => onSubmit("or"),
|
|
467
|
-
boost: 7
|
|
468
|
-
}
|
|
469
|
-
] : [
|
|
470
|
-
{
|
|
471
|
-
label: "Press ENTER to submit",
|
|
472
|
-
apply: () => onSubmit(),
|
|
473
|
-
boost: 6
|
|
474
|
-
}
|
|
475
|
-
];
|
|
476
|
-
return withJoinSuggestions ? result.concat(import_vuu_codemirror5.booleanJoinSuggestions).concat(import_vuu_codemirror5.asNameSuggestion) : result;
|
|
477
|
-
};
|
|
478
|
-
var promptToSaveOrExtend = (context, onSubmit, existingFilter) => ({
|
|
479
|
-
from: context.pos,
|
|
480
|
-
options: makeSaveOrExtendSuggestions(onSubmit, existingFilter)
|
|
481
|
-
});
|
|
482
|
-
var promptToSave = (context, onSubmit, existingFilter) => ({
|
|
483
|
-
from: context.pos,
|
|
484
|
-
options: makeSaveOrExtendSuggestions(onSubmit, existingFilter, false)
|
|
485
|
-
});
|
|
486
463
|
var useAutoComplete = (suggestionProvider, onSubmit, existingFilter) => {
|
|
487
464
|
const makeSuggestions = (0, import_react.useCallback)(
|
|
488
465
|
async (context, suggestionType, optionalArgs = {}) => {
|
|
466
|
+
const { startsWith = "" } = optionalArgs;
|
|
489
467
|
const options = await suggestionProvider.getSuggestions(
|
|
490
468
|
suggestionType,
|
|
491
469
|
optionalArgs
|
|
492
470
|
);
|
|
493
|
-
const { startsWith = "" } = optionalArgs;
|
|
494
471
|
return { from: context.pos - startsWith.length, options };
|
|
495
472
|
},
|
|
496
473
|
[suggestionProvider]
|
|
@@ -514,19 +491,45 @@ var useAutoComplete = (suggestionProvider, onSubmit, existingFilter) => {
|
|
|
514
491
|
} else {
|
|
515
492
|
const clauseOperator = getClauseOperator(nodeBefore, state);
|
|
516
493
|
if (clauseOperator === "as") {
|
|
517
|
-
return
|
|
494
|
+
return makeSuggestions(context, "name");
|
|
495
|
+
} else {
|
|
496
|
+
const filterName = getFilterName(nodeBefore, state);
|
|
497
|
+
return makeSuggestions(context, "save", {
|
|
498
|
+
onSubmit: onSubmit.current,
|
|
499
|
+
existingFilter,
|
|
500
|
+
filterName
|
|
501
|
+
});
|
|
502
|
+
}
|
|
503
|
+
}
|
|
504
|
+
case "String":
|
|
505
|
+
{
|
|
506
|
+
const operator = getOperator(nodeBefore, state);
|
|
507
|
+
const columnName = getColumnName(nodeBefore, state);
|
|
508
|
+
const { from, to } = nodeBefore;
|
|
509
|
+
if (to - from === 2 && context.pos === from + 1) {
|
|
510
|
+
if (columnName && operator) {
|
|
511
|
+
return makeSuggestions(context, "columnValue", {
|
|
512
|
+
columnName,
|
|
513
|
+
operator,
|
|
514
|
+
quoted: true,
|
|
515
|
+
startsWith: word.text
|
|
516
|
+
});
|
|
517
|
+
}
|
|
518
518
|
} else {
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
onSubmit.current,
|
|
522
|
-
existingFilter
|
|
519
|
+
console.log(
|
|
520
|
+
`we have a string, column is ${columnName} ${from} ${to}`
|
|
523
521
|
);
|
|
524
522
|
}
|
|
525
523
|
}
|
|
524
|
+
break;
|
|
526
525
|
case "As":
|
|
527
|
-
return
|
|
526
|
+
return makeSuggestions(context, "name");
|
|
528
527
|
case "FilterName":
|
|
529
|
-
return
|
|
528
|
+
return makeSuggestions(context, "save", {
|
|
529
|
+
onSubmit: onSubmit.current,
|
|
530
|
+
existingFilter,
|
|
531
|
+
filterName: getFilterName(nodeBefore, state)
|
|
532
|
+
});
|
|
530
533
|
case "Column": {
|
|
531
534
|
const columnName = (0, import_vuu_codemirror5.getValue)(nodeBefore, state);
|
|
532
535
|
const isPartialMatch = await suggestionProvider.isPartialMatch(
|
|
@@ -802,6 +805,55 @@ var filterInfo = (filterName, filterQuery) => {
|
|
|
802
805
|
// src/filter-input/useFilterSuggestionProvider.ts
|
|
803
806
|
var NO_NAMED_FILTERS = [];
|
|
804
807
|
var NONE = {};
|
|
808
|
+
var saveAsTab = (onSubmit) => [
|
|
809
|
+
{
|
|
810
|
+
label: "Press ENTER to create TAB",
|
|
811
|
+
apply: () => onSubmit("tab"),
|
|
812
|
+
boost: 6
|
|
813
|
+
}
|
|
814
|
+
];
|
|
815
|
+
var makeSaveOrExtendSuggestions = (onSubmit, existingFilter, withJoinSuggestions = true) => {
|
|
816
|
+
const result = existingFilter ? [
|
|
817
|
+
{
|
|
818
|
+
label: "REPLACE existing filter",
|
|
819
|
+
apply: () => onSubmit("replace"),
|
|
820
|
+
boost: 8
|
|
821
|
+
},
|
|
822
|
+
{
|
|
823
|
+
label: "AND existing filter",
|
|
824
|
+
apply: () => onSubmit("and"),
|
|
825
|
+
boost: 7
|
|
826
|
+
},
|
|
827
|
+
{
|
|
828
|
+
label: "OR existing filter",
|
|
829
|
+
apply: () => onSubmit("or"),
|
|
830
|
+
boost: 7
|
|
831
|
+
}
|
|
832
|
+
] : [
|
|
833
|
+
{
|
|
834
|
+
label: "Press ENTER to submit",
|
|
835
|
+
apply: () => onSubmit(),
|
|
836
|
+
boost: 6
|
|
837
|
+
}
|
|
838
|
+
];
|
|
839
|
+
return withJoinSuggestions ? result.concat(import_vuu_codemirror7.booleanJoinSuggestions).concat(import_vuu_codemirror7.asNameSuggestion) : result;
|
|
840
|
+
};
|
|
841
|
+
var promptToSaveOrExtend = (onSubmit, existingFilter) => makeSaveOrExtendSuggestions(onSubmit, existingFilter, true);
|
|
842
|
+
var promptToSave = (onSubmit) => makeSaveOrExtendSuggestions(onSubmit, void 0);
|
|
843
|
+
var getSaveSuggestions = ({
|
|
844
|
+
existingFilter,
|
|
845
|
+
filterName,
|
|
846
|
+
onSubmit,
|
|
847
|
+
saveOptions
|
|
848
|
+
}) => {
|
|
849
|
+
const includeTabSuggestion = filterName && saveOptions.allowSaveAsTab;
|
|
850
|
+
const result = existingFilter ? promptToSaveOrExtend(onSubmit, existingFilter) : promptToSave(onSubmit);
|
|
851
|
+
if (includeTabSuggestion) {
|
|
852
|
+
return result.concat(saveAsTab(onSubmit));
|
|
853
|
+
} else {
|
|
854
|
+
return result;
|
|
855
|
+
}
|
|
856
|
+
};
|
|
805
857
|
var suggestColumns = (columns) => columns.map((column) => ({
|
|
806
858
|
boost: 5,
|
|
807
859
|
label: column.name
|
|
@@ -821,57 +873,101 @@ var withApplySpace = (suggestions, startsWith = "") => suggestions.filter((sugg)
|
|
|
821
873
|
...suggestion,
|
|
822
874
|
apply: suggestion.label + " "
|
|
823
875
|
}));
|
|
876
|
+
var defaultSaveOptions = {
|
|
877
|
+
allowReplace: true
|
|
878
|
+
};
|
|
824
879
|
var useFilterSuggestionProvider = ({
|
|
825
880
|
columns,
|
|
826
881
|
namedFilters,
|
|
882
|
+
saveOptions = defaultSaveOptions,
|
|
827
883
|
table
|
|
828
884
|
}) => {
|
|
829
885
|
const latestSuggestionsRef = (0, import_react3.useRef)();
|
|
830
886
|
const getTypeaheadSuggestions = (0, import_vuu_data.useTypeaheadSuggestions)();
|
|
831
887
|
const getSuggestions = (0, import_react3.useCallback)(
|
|
832
888
|
async (suggestionType, options = NONE) => {
|
|
833
|
-
const {
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
889
|
+
const {
|
|
890
|
+
columnName,
|
|
891
|
+
existingFilter,
|
|
892
|
+
filterName,
|
|
893
|
+
operator,
|
|
894
|
+
quoted: autoQuoted,
|
|
895
|
+
onSubmit,
|
|
896
|
+
startsWith,
|
|
897
|
+
selection
|
|
898
|
+
} = options;
|
|
899
|
+
switch (suggestionType) {
|
|
900
|
+
case "operator":
|
|
901
|
+
{
|
|
902
|
+
const column = columns.find((col) => col.name === columnName);
|
|
903
|
+
if (column) {
|
|
904
|
+
switch (column.serverDataType) {
|
|
905
|
+
case "string":
|
|
906
|
+
case "char":
|
|
907
|
+
return withApplySpace(import_vuu_codemirror7.stringOperators, startsWith);
|
|
908
|
+
case "int":
|
|
909
|
+
case "long":
|
|
910
|
+
case "double":
|
|
911
|
+
return withApplySpace(import_vuu_codemirror7.numericOperators);
|
|
912
|
+
}
|
|
913
|
+
} else {
|
|
914
|
+
console.warn(`'${columnName}' does not match any column name`);
|
|
915
|
+
}
|
|
845
916
|
}
|
|
846
|
-
|
|
847
|
-
|
|
917
|
+
break;
|
|
918
|
+
case "column": {
|
|
919
|
+
const columnSuggestions = await suggestColumns(columns);
|
|
920
|
+
const filterSuggestions = await suggestNamedFilters(namedFilters);
|
|
921
|
+
return (latestSuggestionsRef.current = withApplySpace(columnSuggestions)).concat(
|
|
922
|
+
withApplySpace(filterSuggestions)
|
|
923
|
+
);
|
|
848
924
|
}
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
868
|
-
|
|
925
|
+
case "columnValue":
|
|
926
|
+
{
|
|
927
|
+
if (columnName) {
|
|
928
|
+
const column = columns.find((col) => col.name === columnName);
|
|
929
|
+
const prefix = Array.isArray(selection) ? selection.length === 0 ? "[" : "," : "";
|
|
930
|
+
const params = (0, import_vuu_data.getTypeaheadParams)(
|
|
931
|
+
table,
|
|
932
|
+
columnName,
|
|
933
|
+
startsWith
|
|
934
|
+
);
|
|
935
|
+
const suggestions = await getTypeaheadSuggestions(params);
|
|
936
|
+
const isIllustration = operator === "starts";
|
|
937
|
+
latestSuggestionsRef.current = (0, import_vuu_codemirror7.toSuggestions)(suggestions, {
|
|
938
|
+
moveCursorToEnd: autoQuoted,
|
|
939
|
+
quoted: (column == null ? void 0 : column.serverDataType) === "string" && !autoQuoted,
|
|
940
|
+
suffix: autoQuoted ? "" : " ",
|
|
941
|
+
prefix: isIllustration ? startsWith : prefix,
|
|
942
|
+
isIllustration
|
|
943
|
+
});
|
|
944
|
+
if (Array.isArray(selection) && (selection == null ? void 0 : selection.length) > 1) {
|
|
945
|
+
return [doneCommand, ...latestSuggestionsRef.current];
|
|
946
|
+
}
|
|
947
|
+
return latestSuggestionsRef.current;
|
|
948
|
+
}
|
|
949
|
+
}
|
|
950
|
+
break;
|
|
951
|
+
case "save": {
|
|
952
|
+
if (typeof onSubmit !== "function") {
|
|
953
|
+
throw Error(
|
|
954
|
+
"useFilterSuggestionProvider, onSubmit must be supplied for 'save' suggestions"
|
|
955
|
+
);
|
|
956
|
+
}
|
|
957
|
+
return await getSaveSuggestions({
|
|
958
|
+
existingFilter,
|
|
959
|
+
filterName,
|
|
960
|
+
onSubmit,
|
|
961
|
+
saveOptions
|
|
962
|
+
});
|
|
869
963
|
}
|
|
870
|
-
|
|
964
|
+
case "name":
|
|
965
|
+
return await (0, import_vuu_codemirror7.getNamePrompt)("filter");
|
|
966
|
+
default:
|
|
871
967
|
}
|
|
872
968
|
return [];
|
|
873
969
|
},
|
|
874
|
-
[columns, getTypeaheadSuggestions, namedFilters, table]
|
|
970
|
+
[columns, getTypeaheadSuggestions, namedFilters, saveOptions, table]
|
|
875
971
|
);
|
|
876
972
|
const isPartialMatch = (0, import_react3.useCallback)(
|
|
877
973
|
async (valueType, columnName, pattern) => {
|