@getlupa/client 1.15.8 → 1.15.9
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/lupaSearch.iife.js +162 -51
- package/dist/lupaSearch.js +162 -51
- package/dist/lupaSearch.mjs +162 -51
- package/dist/lupaSearch.umd.js +162 -51
- package/package.json +2 -2
package/dist/lupaSearch.iife.js
CHANGED
|
@@ -8126,12 +8126,15 @@ var __async = (__this, __arguments, generator) => {
|
|
|
8126
8126
|
value
|
|
8127
8127
|
};
|
|
8128
8128
|
};
|
|
8129
|
-
const toggleTermFilter = (appendParams, facetAction, getQueryParamName, currentFilters) => {
|
|
8129
|
+
const toggleTermFilter = (appendParams, facetAction, getQueryParamName, currentFilters, paramsToRemove = []) => {
|
|
8130
8130
|
const currentFilter = currentFilters == null ? void 0 : currentFilters[facetAction.key];
|
|
8131
8131
|
const newParams = toggleTermParam(currentFilter, facetAction.value);
|
|
8132
8132
|
appendParams({
|
|
8133
8133
|
params: [getFacetParam(facetAction.key, newParams)],
|
|
8134
|
-
paramsToRemove: [
|
|
8134
|
+
paramsToRemove: [
|
|
8135
|
+
...paramsToRemove,
|
|
8136
|
+
...[getQueryParamName ? getQueryParamName(QUERY_PARAMS$1.PAGE) : QUERY_PARAMS$1.PAGE]
|
|
8137
|
+
]
|
|
8135
8138
|
});
|
|
8136
8139
|
};
|
|
8137
8140
|
const replaceHierarchyParam = (params = [], param = "") => {
|
|
@@ -24682,26 +24685,104 @@ and ensure you are accounting for this risk.
|
|
|
24682
24685
|
RelatedQuerySourceType2["FACETS"] = "facets";
|
|
24683
24686
|
return RelatedQuerySourceType2;
|
|
24684
24687
|
})(RelatedQuerySourceType || {});
|
|
24685
|
-
const
|
|
24688
|
+
const combineIdenticalValues = (results) => {
|
|
24689
|
+
const result2 = [];
|
|
24690
|
+
const keys = /* @__PURE__ */ new Set();
|
|
24691
|
+
for (const item of results) {
|
|
24692
|
+
const trimmedValue = item.value.trim().toLowerCase();
|
|
24693
|
+
if (!keys.has(trimmedValue)) {
|
|
24694
|
+
keys.add(trimmedValue);
|
|
24695
|
+
result2.push({ key: item.key, value: item.value.trim() });
|
|
24696
|
+
}
|
|
24697
|
+
}
|
|
24698
|
+
return result2;
|
|
24699
|
+
};
|
|
24700
|
+
const processFacetsRelatedSourceSuggestionQuery = (searchText, querySource, options, activeFilters) => __async2(void 0, null, function* () {
|
|
24701
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i;
|
|
24702
|
+
if ((_a = Object.keys(activeFilters != null ? activeFilters : {})) == null ? void 0 : _a.length) {
|
|
24703
|
+
return [];
|
|
24704
|
+
}
|
|
24705
|
+
const lupaQuery = {
|
|
24706
|
+
searchText,
|
|
24707
|
+
limit: 1,
|
|
24708
|
+
trackTerm: false
|
|
24709
|
+
};
|
|
24710
|
+
try {
|
|
24711
|
+
const result2 = yield LupaSearchSdk.suggestions(querySource.queryKey, lupaQuery, options);
|
|
24712
|
+
if (!result2.success || ((_c = (_b = result2.items) == null ? void 0 : _b[0].suggestion) == null ? void 0 : _c.toLocaleLowerCase()) !== (searchText == null ? void 0 : searchText.toLocaleLowerCase())) {
|
|
24713
|
+
return [];
|
|
24714
|
+
}
|
|
24715
|
+
return (_i = (_h = (_f = (_e = (_d = result2.items) == null ? void 0 : _d[0].facets) == null ? void 0 : _e[querySource.facetKey]) == null ? void 0 : _f.map((item) => ({
|
|
24716
|
+
key: querySource.facetKey,
|
|
24717
|
+
value: item.title
|
|
24718
|
+
}))) == null ? void 0 : _h.slice(0, (_g = querySource.maxCount) != null ? _g : 5)) != null ? _i : [];
|
|
24719
|
+
} catch (error) {
|
|
24720
|
+
return [];
|
|
24721
|
+
}
|
|
24722
|
+
});
|
|
24723
|
+
const processFacetsRelatedSourceDocumentQuery = (searchText, querySource, options, activeFilters) => __async2(void 0, null, function* () {
|
|
24724
|
+
const lupaQuery = {
|
|
24725
|
+
searchText,
|
|
24726
|
+
limit: 1,
|
|
24727
|
+
filters: activeFilters,
|
|
24728
|
+
trackTerm: false
|
|
24729
|
+
};
|
|
24730
|
+
try {
|
|
24731
|
+
const result2 = yield LupaSearchSdk.query(querySource.queryKey, lupaQuery, options);
|
|
24732
|
+
if (!result2.success) {
|
|
24733
|
+
return [];
|
|
24734
|
+
}
|
|
24735
|
+
return extractFacetsRelatedSourceFromOriginalQuery(
|
|
24736
|
+
{
|
|
24737
|
+
type: RelatedQuerySourceType.FACETS,
|
|
24738
|
+
key: querySource.facetKey,
|
|
24739
|
+
count: querySource.maxCount
|
|
24740
|
+
},
|
|
24741
|
+
result2
|
|
24742
|
+
);
|
|
24743
|
+
} catch (error) {
|
|
24744
|
+
return [];
|
|
24745
|
+
}
|
|
24746
|
+
});
|
|
24747
|
+
const processFacetsRelatedSourceQuery = (searchText, query, options, activeFilters) => __async2(void 0, null, function* () {
|
|
24748
|
+
switch (query.type) {
|
|
24749
|
+
case "document":
|
|
24750
|
+
return processFacetsRelatedSourceDocumentQuery(searchText, query, options, activeFilters);
|
|
24751
|
+
case "suggestion":
|
|
24752
|
+
return processFacetsRelatedSourceSuggestionQuery(searchText, query, options, activeFilters);
|
|
24753
|
+
}
|
|
24754
|
+
});
|
|
24755
|
+
const extractFacetsRelatedSource = (source, searchResults2, options, activeFilters) => __async2(void 0, null, function* () {
|
|
24756
|
+
var _a, _b;
|
|
24757
|
+
if (!((_a = source.queries) == null ? void 0 : _a.length)) {
|
|
24758
|
+
return extractFacetsRelatedSourceFromOriginalQuery(source, searchResults2);
|
|
24759
|
+
}
|
|
24760
|
+
const promises = source.queries.map(
|
|
24761
|
+
(query) => processFacetsRelatedSourceQuery(searchResults2.searchText, query, options, activeFilters)
|
|
24762
|
+
);
|
|
24763
|
+
const result2 = (yield Promise.all(promises)).flat();
|
|
24764
|
+
return (_b = combineIdenticalValues(result2)) == null ? void 0 : _b.slice(0, source.count);
|
|
24765
|
+
});
|
|
24766
|
+
const extractFacetsRelatedSourceFromOriginalQuery = (source, searchResults2) => __async2(void 0, null, function* () {
|
|
24686
24767
|
var _a, _b, _c, _d, _e;
|
|
24687
24768
|
const facet = (_a = searchResults2.facets) == null ? void 0 : _a.find((facet2) => facet2.key === source.key);
|
|
24688
24769
|
if (!facet) {
|
|
24689
24770
|
return [];
|
|
24690
24771
|
}
|
|
24691
24772
|
if (facet.type === "terms") {
|
|
24692
|
-
return (_c = (_b = facet.items) == null ? void 0 : _b.slice(0, source.count)) == null ? void 0 : _c.map((item) => item.title);
|
|
24773
|
+
return (_c = (_b = facet.items) == null ? void 0 : _b.slice(0, source.count)) == null ? void 0 : _c.map((item) => ({ key: source.key, value: item.title }));
|
|
24693
24774
|
}
|
|
24694
24775
|
if (facet.type === "hierarchy") {
|
|
24695
|
-
return (_e = (_d = facet.items) == null ? void 0 : _d.slice(0, source.count)) == null ? void 0 : _e.map((item) => item.title);
|
|
24776
|
+
return (_e = (_d = facet.items) == null ? void 0 : _d.slice(0, source.count)) == null ? void 0 : _e.map((item) => ({ key: source.key, value: item.title }));
|
|
24696
24777
|
}
|
|
24697
24778
|
return [];
|
|
24698
|
-
};
|
|
24699
|
-
const extractRelatedSource = (source, searchResults2) => {
|
|
24779
|
+
});
|
|
24780
|
+
const extractRelatedSource = (source, searchResults2, options, activeFilters) => __async2(void 0, null, function* () {
|
|
24700
24781
|
switch (source.type) {
|
|
24701
24782
|
case RelatedQuerySourceType.FACETS:
|
|
24702
|
-
return extractFacetsRelatedSource(source, searchResults2);
|
|
24783
|
+
return extractFacetsRelatedSource(source, searchResults2, options, activeFilters);
|
|
24703
24784
|
}
|
|
24704
|
-
};
|
|
24785
|
+
});
|
|
24705
24786
|
const _hoisted_1$h = { class: "lupa-related-query-item" };
|
|
24706
24787
|
const _hoisted_2$e = { class: "lupa-related-query-image" };
|
|
24707
24788
|
const _hoisted_3$a = { class: "lupa-related-query-label" };
|
|
@@ -24714,12 +24795,16 @@ and ensure you are accounting for this risk.
|
|
|
24714
24795
|
__name: "RelatedQueryPanel",
|
|
24715
24796
|
props: {
|
|
24716
24797
|
query: {},
|
|
24717
|
-
|
|
24798
|
+
sourceKey: {},
|
|
24799
|
+
options: {},
|
|
24800
|
+
existingItemsFromOtherQueries: {}
|
|
24718
24801
|
},
|
|
24719
|
-
|
|
24802
|
+
emits: ["loaded"],
|
|
24803
|
+
setup(__props, { emit: emit2 }) {
|
|
24720
24804
|
const props = __props;
|
|
24721
24805
|
const loading = ref(false);
|
|
24722
24806
|
const relatedQueryResult = ref(null);
|
|
24807
|
+
const itemToDisplay = ref(null);
|
|
24723
24808
|
const optionsStore = useOptionsStore();
|
|
24724
24809
|
const searchResultStore = useSearchResultStore();
|
|
24725
24810
|
const { searchResultOptions } = storeToRefs(optionsStore);
|
|
@@ -24740,10 +24825,6 @@ and ensure you are accounting for this risk.
|
|
|
24740
24825
|
var _a, _b;
|
|
24741
24826
|
return ((_b = (_a = relatedQueryResult.value) == null ? void 0 : _a.items) == null ? void 0 : _b.length) > 0;
|
|
24742
24827
|
});
|
|
24743
|
-
const firstResultItem = computed(() => {
|
|
24744
|
-
var _a, _b;
|
|
24745
|
-
return (_b = (_a = relatedQueryResult.value) == null ? void 0 : _a.items) == null ? void 0 : _b[0];
|
|
24746
|
-
});
|
|
24747
24828
|
const totalItemCount = computed(() => {
|
|
24748
24829
|
var _a, _b;
|
|
24749
24830
|
return (_b = (_a = relatedQueryResult.value) == null ? void 0 : _a.total) != null ? _b : 0;
|
|
@@ -24753,19 +24834,19 @@ and ensure you are accounting for this risk.
|
|
|
24753
24834
|
return ((_a = props.options.source) == null ? void 0 : _a.mode) === "filter" ? (_b = searchResult.value) == null ? void 0 : _b.searchText : (_c = props.query) == null ? void 0 : _c.toLowerCase();
|
|
24754
24835
|
});
|
|
24755
24836
|
const relatedQueryFilters = computed(() => {
|
|
24756
|
-
var _a
|
|
24837
|
+
var _a;
|
|
24757
24838
|
return ((_a = props.options.source) == null ? void 0 : _a.mode) === "filter" ? {
|
|
24758
|
-
[
|
|
24839
|
+
[props.sourceKey]: [props.query]
|
|
24759
24840
|
} : {};
|
|
24760
24841
|
});
|
|
24761
24842
|
const searchForRelatedQuery = () => __async2(this, null, function* () {
|
|
24762
|
-
var _a, _b, _c;
|
|
24843
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
24763
24844
|
if (!props.query) {
|
|
24764
24845
|
return;
|
|
24765
24846
|
}
|
|
24766
24847
|
const lupaQuery = {
|
|
24767
24848
|
searchText: searchText.value,
|
|
24768
|
-
limit:
|
|
24849
|
+
limit: 3,
|
|
24769
24850
|
filters: relatedQueryFilters.value,
|
|
24770
24851
|
trackTerm: false
|
|
24771
24852
|
};
|
|
@@ -24779,8 +24860,13 @@ and ensure you are accounting for this risk.
|
|
|
24779
24860
|
if (result2.success) {
|
|
24780
24861
|
relatedQueryResult.value = result2;
|
|
24781
24862
|
}
|
|
24863
|
+
const firstItem = (_c = (_b = relatedQueryResult.value) == null ? void 0 : _b.items) == null ? void 0 : _c[0];
|
|
24864
|
+
itemToDisplay.value = (_f = (_e = (_d = relatedQueryResult == null ? void 0 : relatedQueryResult.value) == null ? void 0 : _d.items) == null ? void 0 : _e.find(
|
|
24865
|
+
(i) => !props.existingItemsFromOtherQueries[`${i.id}`]
|
|
24866
|
+
)) != null ? _f : firstItem;
|
|
24867
|
+
emit2("loaded", itemToDisplay.value);
|
|
24782
24868
|
} catch (error) {
|
|
24783
|
-
(
|
|
24869
|
+
(_h = (_g = searchResultOptions.value) == null ? void 0 : _g.options) == null ? void 0 : _h.onError(error);
|
|
24784
24870
|
} finally {
|
|
24785
24871
|
loading.value = false;
|
|
24786
24872
|
}
|
|
@@ -24798,11 +24884,11 @@ and ensure you are accounting for this risk.
|
|
|
24798
24884
|
var _a;
|
|
24799
24885
|
return openBlock(), createElementBlock("div", _hoisted_1$h, [
|
|
24800
24886
|
createBaseVNode("div", _hoisted_2$e, [
|
|
24801
|
-
|
|
24887
|
+
itemToDisplay.value && image.value ? (openBlock(), createBlock(_sfc_main$1l, {
|
|
24802
24888
|
key: 0,
|
|
24803
24889
|
"wrapper-class": "lupa-related-query-image-wrapper",
|
|
24804
24890
|
"image-class": "lupa-related-query-image",
|
|
24805
|
-
item:
|
|
24891
|
+
item: itemToDisplay.value,
|
|
24806
24892
|
options: image.value
|
|
24807
24893
|
}, null, 8, ["item", "options"])) : createCommentVNode("", true)
|
|
24808
24894
|
]),
|
|
@@ -24834,47 +24920,63 @@ and ensure you are accounting for this risk.
|
|
|
24834
24920
|
const paramsStore = useParamsStore();
|
|
24835
24921
|
const optionsStore = useOptionsStore();
|
|
24836
24922
|
const { searchResult } = storeToRefs(searchResultStore);
|
|
24923
|
+
const { searchResultOptions } = storeToRefs(optionsStore);
|
|
24924
|
+
const relatedQueries = ref([]);
|
|
24925
|
+
const allDisplayItems = ref({});
|
|
24926
|
+
const querySourceResultMap = ref({});
|
|
24837
24927
|
const currentSearchText = computed(() => {
|
|
24838
24928
|
var _a, _b;
|
|
24839
24929
|
return (_b = (_a = searchResult.value) == null ? void 0 : _a.searchText) != null ? _b : "";
|
|
24840
24930
|
});
|
|
24841
|
-
const
|
|
24842
|
-
|
|
24843
|
-
|
|
24931
|
+
const currentFilters = computed(() => paramsStore.filters);
|
|
24932
|
+
const querySources = computed(() => {
|
|
24933
|
+
var _a, _b, _c, _d;
|
|
24934
|
+
return (_d = (_c = (_b = (_a = props.options) == null ? void 0 : _a.source) == null ? void 0 : _b.queries) == null ? void 0 : _c.map((q) => q.facetKey)) != null ? _d : [];
|
|
24935
|
+
});
|
|
24936
|
+
const currentFiltersWithoutQuerySources = computed(() => {
|
|
24937
|
+
const filters = {};
|
|
24938
|
+
if (currentFilters.value) {
|
|
24939
|
+
for (const key in currentFilters.value) {
|
|
24940
|
+
if (!querySources.value.includes(key)) {
|
|
24941
|
+
filters[key] = currentFilters.value[key];
|
|
24942
|
+
}
|
|
24943
|
+
}
|
|
24844
24944
|
}
|
|
24845
|
-
|
|
24846
|
-
return queries;
|
|
24945
|
+
return filters;
|
|
24847
24946
|
});
|
|
24947
|
+
watch(searchResult, () => __async2(this, null, function* () {
|
|
24948
|
+
allDisplayItems.value = {};
|
|
24949
|
+
querySourceResultMap.value = {};
|
|
24950
|
+
if (!props.options || !searchResult.value) {
|
|
24951
|
+
relatedQueries.value = [];
|
|
24952
|
+
}
|
|
24953
|
+
const queries = yield extractRelatedSource(
|
|
24954
|
+
props.options.source,
|
|
24955
|
+
searchResult.value,
|
|
24956
|
+
searchResultOptions.value.options,
|
|
24957
|
+
currentFiltersWithoutQuerySources.value
|
|
24958
|
+
);
|
|
24959
|
+
relatedQueries.value = queries;
|
|
24960
|
+
}));
|
|
24848
24961
|
const hasEnoughRelatedQueries = computed(() => {
|
|
24849
24962
|
return relatedQueries.value.length > 1;
|
|
24850
24963
|
});
|
|
24851
|
-
const goToResults = ({ searchText }) => {
|
|
24852
|
-
paramsStore.goToResults({ searchText });
|
|
24853
|
-
};
|
|
24854
24964
|
const handleRelatedQueryClick = (query) => {
|
|
24855
24965
|
var _a;
|
|
24856
24966
|
if (((_a = props.options.source) == null ? void 0 : _a.mode) === "filter") {
|
|
24857
24967
|
handleFilter(query);
|
|
24858
24968
|
} else {
|
|
24859
|
-
goToResults({ searchText: query });
|
|
24969
|
+
paramsStore.goToResults({ searchText: query.value });
|
|
24860
24970
|
}
|
|
24861
24971
|
};
|
|
24862
24972
|
const handleFilter = (query) => {
|
|
24863
|
-
var _a
|
|
24864
|
-
const facet = (_b = (_a = searchResult.value) == null ? void 0 : _a.facets) == null ? void 0 : _b.find(
|
|
24865
|
-
(facet2) => {
|
|
24866
|
-
var _a2, _b2;
|
|
24867
|
-
return facet2.key === ((_b2 = (_a2 = props.options) == null ? void 0 : _a2.source) == null ? void 0 : _b2.key);
|
|
24868
|
-
}
|
|
24869
|
-
);
|
|
24870
|
-
if (!facet || facet.type !== "terms") {
|
|
24871
|
-
return [];
|
|
24872
|
-
}
|
|
24973
|
+
var _a;
|
|
24873
24974
|
toggleTermFilter(
|
|
24874
24975
|
paramsStore.appendParams,
|
|
24875
|
-
{ type: "terms", key:
|
|
24976
|
+
{ type: "terms", key: query.key, value: query.value },
|
|
24876
24977
|
optionsStore.getQueryParamName,
|
|
24877
|
-
{}
|
|
24978
|
+
{},
|
|
24979
|
+
(_a = querySources.value) == null ? void 0 : _a.map((q) => `f.${q}`)
|
|
24878
24980
|
);
|
|
24879
24981
|
};
|
|
24880
24982
|
const getSelectedFilterClass = (query) => {
|
|
@@ -24882,9 +24984,13 @@ and ensure you are accounting for this risk.
|
|
|
24882
24984
|
if (((_a = props.options.source) == null ? void 0 : _a.mode) !== "filter") {
|
|
24883
24985
|
return "";
|
|
24884
24986
|
}
|
|
24885
|
-
return Array.isArray((_c = (_b = searchResult.value) == null ? void 0 : _b.filters) == null ? void 0 : _c[
|
|
24886
|
-
|
|
24887
|
-
|
|
24987
|
+
return Array.isArray((_c = (_b = searchResult.value) == null ? void 0 : _b.filters) == null ? void 0 : _c[query.key]) && ((_f = (_e = (_d = searchResult.value) == null ? void 0 : _d.filters) == null ? void 0 : _e[query.key]) == null ? void 0 : _f.includes(query.value)) ? "lupa-selected-related-query-filter" : "";
|
|
24988
|
+
};
|
|
24989
|
+
const processLoadedItem = (query, item) => {
|
|
24990
|
+
if (item) {
|
|
24991
|
+
allDisplayItems.value[`${item.id}`] = item;
|
|
24992
|
+
}
|
|
24993
|
+
querySourceResultMap.value[query.value] = Boolean(item);
|
|
24888
24994
|
};
|
|
24889
24995
|
return (_ctx, _cache) => {
|
|
24890
24996
|
var _a, _b, _c, _d;
|
|
@@ -24892,19 +24998,24 @@ and ensure you are accounting for this risk.
|
|
|
24892
24998
|
((_b = (_a = _ctx.options) == null ? void 0 : _a.labels) == null ? void 0 : _b.title) ? (openBlock(), createElementBlock("h3", _hoisted_2$d, toDisplayString((_d = (_c = _ctx.options) == null ? void 0 : _c.labels) == null ? void 0 : _d.title), 1)) : createCommentVNode("", true),
|
|
24893
24999
|
createBaseVNode("ul", null, [
|
|
24894
25000
|
(openBlock(true), createElementBlock(Fragment, null, renderList(relatedQueries.value, (query) => {
|
|
24895
|
-
return openBlock(), createElementBlock("li", {
|
|
24896
|
-
key: query + currentSearchText.value,
|
|
25001
|
+
return withDirectives((openBlock(), createElementBlock("li", {
|
|
25002
|
+
key: query.value + query.key + currentSearchText.value,
|
|
24897
25003
|
class: normalizeClass(getSelectedFilterClass(query))
|
|
24898
25004
|
}, [
|
|
24899
25005
|
createBaseVNode("a", {
|
|
24900
25006
|
onClick: ($event) => handleRelatedQueryClick(query)
|
|
24901
25007
|
}, [
|
|
24902
25008
|
createVNode(_sfc_main$j, {
|
|
25009
|
+
"source-key": query.key,
|
|
24903
25010
|
options: _ctx.options,
|
|
24904
|
-
query
|
|
24905
|
-
|
|
25011
|
+
query: query.value,
|
|
25012
|
+
"existing-items-from-other-queries": allDisplayItems.value,
|
|
25013
|
+
onLoaded: (item) => processLoadedItem(query, item)
|
|
25014
|
+
}, null, 8, ["source-key", "options", "query", "existing-items-from-other-queries", "onLoaded"])
|
|
24906
25015
|
], 8, _hoisted_3$9)
|
|
24907
|
-
], 2)
|
|
25016
|
+
], 2)), [
|
|
25017
|
+
[vShow, querySourceResultMap.value[query.value] !== false]
|
|
25018
|
+
]);
|
|
24908
25019
|
}), 128))
|
|
24909
25020
|
])
|
|
24910
25021
|
])) : createCommentVNode("", true);
|