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