@getlupa/client 1.15.8 → 1.15.10

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.
@@ -8124,12 +8124,15 @@ const getFacetParam = (key, value, type = FACET_PARAMS_TYPE.TERMS) => {
8124
8124
  value
8125
8125
  };
8126
8126
  };
8127
- const toggleTermFilter = (appendParams, facetAction, getQueryParamName, currentFilters) => {
8127
+ const toggleTermFilter = (appendParams, facetAction, getQueryParamName, currentFilters, paramsToRemove = []) => {
8128
8128
  const currentFilter = currentFilters == null ? void 0 : currentFilters[facetAction.key];
8129
8129
  const newParams = toggleTermParam(currentFilter, facetAction.value);
8130
8130
  appendParams({
8131
8131
  params: [getFacetParam(facetAction.key, newParams)],
8132
- paramsToRemove: [getQueryParamName ? getQueryParamName(QUERY_PARAMS$1.PAGE) : QUERY_PARAMS$1.PAGE]
8132
+ paramsToRemove: [
8133
+ ...paramsToRemove,
8134
+ ...[getQueryParamName ? getQueryParamName(QUERY_PARAMS$1.PAGE) : QUERY_PARAMS$1.PAGE]
8135
+ ]
8133
8136
  });
8134
8137
  };
8135
8138
  const replaceHierarchyParam = (params = [], param = "") => {
@@ -24680,26 +24683,104 @@ var RelatedQuerySourceType = /* @__PURE__ */ ((RelatedQuerySourceType2) => {
24680
24683
  RelatedQuerySourceType2["FACETS"] = "facets";
24681
24684
  return RelatedQuerySourceType2;
24682
24685
  })(RelatedQuerySourceType || {});
24683
- const extractFacetsRelatedSource = (source, searchResults2) => {
24686
+ const combineIdenticalValues = (results) => {
24687
+ const result2 = [];
24688
+ const keys = /* @__PURE__ */ new Set();
24689
+ for (const item of results) {
24690
+ const trimmedValue = item.value.trim().toLowerCase();
24691
+ if (!keys.has(trimmedValue)) {
24692
+ keys.add(trimmedValue);
24693
+ result2.push({ key: item.key, value: item.value.trim() });
24694
+ }
24695
+ }
24696
+ return result2;
24697
+ };
24698
+ const processFacetsRelatedSourceSuggestionQuery = (searchText, querySource, options, activeFilters) => __async2(void 0, null, function* () {
24699
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i;
24700
+ if ((_a = Object.keys(activeFilters != null ? activeFilters : {})) == null ? void 0 : _a.length) {
24701
+ return [];
24702
+ }
24703
+ const lupaQuery = {
24704
+ searchText,
24705
+ limit: 1,
24706
+ trackTerm: false
24707
+ };
24708
+ try {
24709
+ const result2 = yield LupaSearchSdk.suggestions(querySource.queryKey, lupaQuery, options);
24710
+ if (!result2.success || ((_c = (_b = result2.items) == null ? void 0 : _b[0].suggestion) == null ? void 0 : _c.toLocaleLowerCase()) !== (searchText == null ? void 0 : searchText.toLocaleLowerCase())) {
24711
+ return [];
24712
+ }
24713
+ 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) => ({
24714
+ key: querySource.facetKey,
24715
+ value: item.title
24716
+ }))) == null ? void 0 : _h.slice(0, (_g = querySource.maxCount) != null ? _g : 5)) != null ? _i : [];
24717
+ } catch (error) {
24718
+ return [];
24719
+ }
24720
+ });
24721
+ const processFacetsRelatedSourceDocumentQuery = (searchText, querySource, options, activeFilters) => __async2(void 0, null, function* () {
24722
+ const lupaQuery = {
24723
+ searchText,
24724
+ limit: 1,
24725
+ filters: activeFilters,
24726
+ trackTerm: false
24727
+ };
24728
+ try {
24729
+ const result2 = yield LupaSearchSdk.query(querySource.queryKey, lupaQuery, options);
24730
+ if (!result2.success) {
24731
+ return [];
24732
+ }
24733
+ return extractFacetsRelatedSourceFromOriginalQuery(
24734
+ {
24735
+ type: RelatedQuerySourceType.FACETS,
24736
+ key: querySource.facetKey,
24737
+ count: querySource.maxCount
24738
+ },
24739
+ result2
24740
+ );
24741
+ } catch (error) {
24742
+ return [];
24743
+ }
24744
+ });
24745
+ const processFacetsRelatedSourceQuery = (searchText, query, options, activeFilters) => __async2(void 0, null, function* () {
24746
+ switch (query.type) {
24747
+ case "document":
24748
+ return processFacetsRelatedSourceDocumentQuery(searchText, query, options, activeFilters);
24749
+ case "suggestion":
24750
+ return processFacetsRelatedSourceSuggestionQuery(searchText, query, options, activeFilters);
24751
+ }
24752
+ });
24753
+ const extractFacetsRelatedSource = (source, searchResults2, options, activeFilters) => __async2(void 0, null, function* () {
24754
+ var _a, _b;
24755
+ if (!((_a = source.queries) == null ? void 0 : _a.length)) {
24756
+ return extractFacetsRelatedSourceFromOriginalQuery(source, searchResults2);
24757
+ }
24758
+ const promises = source.queries.map(
24759
+ (query) => processFacetsRelatedSourceQuery(searchResults2.searchText, query, options, activeFilters)
24760
+ );
24761
+ const result2 = (yield Promise.all(promises)).flat();
24762
+ return (_b = combineIdenticalValues(result2)) == null ? void 0 : _b.slice(0, source.count);
24763
+ });
24764
+ const extractFacetsRelatedSourceFromOriginalQuery = (source, searchResults2) => __async2(void 0, null, function* () {
24684
24765
  var _a, _b, _c, _d, _e;
24685
24766
  const facet = (_a = searchResults2.facets) == null ? void 0 : _a.find((facet2) => facet2.key === source.key);
24686
24767
  if (!facet) {
24687
24768
  return [];
24688
24769
  }
24689
24770
  if (facet.type === "terms") {
24690
- return (_c = (_b = facet.items) == null ? void 0 : _b.slice(0, source.count)) == null ? void 0 : _c.map((item) => item.title);
24771
+ 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 }));
24691
24772
  }
24692
24773
  if (facet.type === "hierarchy") {
24693
- return (_e = (_d = facet.items) == null ? void 0 : _d.slice(0, source.count)) == null ? void 0 : _e.map((item) => item.title);
24774
+ 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 }));
24694
24775
  }
24695
24776
  return [];
24696
- };
24697
- const extractRelatedSource = (source, searchResults2) => {
24777
+ });
24778
+ const extractRelatedSource = (source, searchResults2, options, activeFilters) => __async2(void 0, null, function* () {
24698
24779
  switch (source.type) {
24699
24780
  case RelatedQuerySourceType.FACETS:
24700
- return extractFacetsRelatedSource(source, searchResults2);
24781
+ return extractFacetsRelatedSource(source, searchResults2, options, activeFilters);
24701
24782
  }
24702
- };
24783
+ });
24703
24784
  const _hoisted_1$h = { class: "lupa-related-query-item" };
24704
24785
  const _hoisted_2$e = { class: "lupa-related-query-image" };
24705
24786
  const _hoisted_3$a = { class: "lupa-related-query-label" };
@@ -24712,12 +24793,16 @@ const _sfc_main$j = /* @__PURE__ */ defineComponent({
24712
24793
  __name: "RelatedQueryPanel",
24713
24794
  props: {
24714
24795
  query: {},
24715
- options: {}
24796
+ sourceKey: {},
24797
+ options: {},
24798
+ existingItemsFromOtherQueries: {}
24716
24799
  },
24717
- setup(__props) {
24800
+ emits: ["loaded"],
24801
+ setup(__props, { emit: emit2 }) {
24718
24802
  const props = __props;
24719
24803
  const loading = ref(false);
24720
24804
  const relatedQueryResult = ref(null);
24805
+ const itemToDisplay = ref(null);
24721
24806
  const optionsStore = useOptionsStore();
24722
24807
  const searchResultStore = useSearchResultStore();
24723
24808
  const { searchResultOptions } = storeToRefs(optionsStore);
@@ -24738,10 +24823,6 @@ const _sfc_main$j = /* @__PURE__ */ defineComponent({
24738
24823
  var _a, _b;
24739
24824
  return ((_b = (_a = relatedQueryResult.value) == null ? void 0 : _a.items) == null ? void 0 : _b.length) > 0;
24740
24825
  });
24741
- const firstResultItem = computed(() => {
24742
- var _a, _b;
24743
- return (_b = (_a = relatedQueryResult.value) == null ? void 0 : _a.items) == null ? void 0 : _b[0];
24744
- });
24745
24826
  const totalItemCount = computed(() => {
24746
24827
  var _a, _b;
24747
24828
  return (_b = (_a = relatedQueryResult.value) == null ? void 0 : _a.total) != null ? _b : 0;
@@ -24751,19 +24832,19 @@ const _sfc_main$j = /* @__PURE__ */ defineComponent({
24751
24832
  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();
24752
24833
  });
24753
24834
  const relatedQueryFilters = computed(() => {
24754
- var _a, _b, _c;
24835
+ var _a;
24755
24836
  return ((_a = props.options.source) == null ? void 0 : _a.mode) === "filter" ? {
24756
- [(_c = (_b = props.options) == null ? void 0 : _b.source) == null ? void 0 : _c.key]: [props.query]
24837
+ [props.sourceKey]: [props.query]
24757
24838
  } : {};
24758
24839
  });
24759
24840
  const searchForRelatedQuery = () => __async2(this, null, function* () {
24760
- var _a, _b, _c;
24841
+ var _a, _b, _c, _d, _e, _f, _g, _h;
24761
24842
  if (!props.query) {
24762
24843
  return;
24763
24844
  }
24764
24845
  const lupaQuery = {
24765
24846
  searchText: searchText.value,
24766
- limit: 1,
24847
+ limit: 3,
24767
24848
  filters: relatedQueryFilters.value,
24768
24849
  trackTerm: false
24769
24850
  };
@@ -24777,8 +24858,13 @@ const _sfc_main$j = /* @__PURE__ */ defineComponent({
24777
24858
  if (result2.success) {
24778
24859
  relatedQueryResult.value = result2;
24779
24860
  }
24861
+ const firstItem = (_c = (_b = relatedQueryResult.value) == null ? void 0 : _b.items) == null ? void 0 : _c[0];
24862
+ itemToDisplay.value = (_f = (_e = (_d = relatedQueryResult == null ? void 0 : relatedQueryResult.value) == null ? void 0 : _d.items) == null ? void 0 : _e.find(
24863
+ (i) => !props.existingItemsFromOtherQueries[`${i.id}`]
24864
+ )) != null ? _f : firstItem;
24865
+ emit2("loaded", itemToDisplay.value);
24780
24866
  } catch (error) {
24781
- (_c = (_b = searchResultOptions.value) == null ? void 0 : _b.options) == null ? void 0 : _c.onError(error);
24867
+ (_h = (_g = searchResultOptions.value) == null ? void 0 : _g.options) == null ? void 0 : _h.onError(error);
24782
24868
  } finally {
24783
24869
  loading.value = false;
24784
24870
  }
@@ -24796,11 +24882,11 @@ const _sfc_main$j = /* @__PURE__ */ defineComponent({
24796
24882
  var _a;
24797
24883
  return openBlock(), createElementBlock("div", _hoisted_1$h, [
24798
24884
  createBaseVNode("div", _hoisted_2$e, [
24799
- firstResultItem.value && image.value ? (openBlock(), createBlock(_sfc_main$1l, {
24885
+ itemToDisplay.value && image.value ? (openBlock(), createBlock(_sfc_main$1l, {
24800
24886
  key: 0,
24801
24887
  "wrapper-class": "lupa-related-query-image-wrapper",
24802
24888
  "image-class": "lupa-related-query-image",
24803
- item: firstResultItem.value,
24889
+ item: itemToDisplay.value,
24804
24890
  options: image.value
24805
24891
  }, null, 8, ["item", "options"])) : createCommentVNode("", true)
24806
24892
  ]),
@@ -24832,47 +24918,63 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
24832
24918
  const paramsStore = useParamsStore();
24833
24919
  const optionsStore = useOptionsStore();
24834
24920
  const { searchResult } = storeToRefs(searchResultStore);
24921
+ const { searchResultOptions } = storeToRefs(optionsStore);
24922
+ const relatedQueries = ref([]);
24923
+ const allDisplayItems = ref({});
24924
+ const querySourceResultMap = ref({});
24835
24925
  const currentSearchText = computed(() => {
24836
24926
  var _a, _b;
24837
24927
  return (_b = (_a = searchResult.value) == null ? void 0 : _a.searchText) != null ? _b : "";
24838
24928
  });
24839
- const relatedQueries = computed(() => {
24840
- if (!props.options || !searchResult.value) {
24841
- return [];
24929
+ const currentFilters = computed(() => paramsStore.filters);
24930
+ const querySources = computed(() => {
24931
+ var _a, _b, _c, _d;
24932
+ 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 : [];
24933
+ });
24934
+ const currentFiltersWithoutQuerySources = computed(() => {
24935
+ const filters = {};
24936
+ if (currentFilters.value) {
24937
+ for (const key in currentFilters.value) {
24938
+ if (!querySources.value.includes(key)) {
24939
+ filters[key] = currentFilters.value[key];
24940
+ }
24941
+ }
24842
24942
  }
24843
- const queries = extractRelatedSource(props.options.source, searchResult.value);
24844
- return queries;
24943
+ return filters;
24845
24944
  });
24945
+ watch(searchResult, () => __async2(this, null, function* () {
24946
+ allDisplayItems.value = {};
24947
+ querySourceResultMap.value = {};
24948
+ if (!props.options || !searchResult.value) {
24949
+ relatedQueries.value = [];
24950
+ }
24951
+ const queries = yield extractRelatedSource(
24952
+ props.options.source,
24953
+ searchResult.value,
24954
+ searchResultOptions.value.options,
24955
+ currentFiltersWithoutQuerySources.value
24956
+ );
24957
+ relatedQueries.value = queries;
24958
+ }));
24846
24959
  const hasEnoughRelatedQueries = computed(() => {
24847
24960
  return relatedQueries.value.length > 1;
24848
24961
  });
24849
- const goToResults = ({ searchText }) => {
24850
- paramsStore.goToResults({ searchText });
24851
- };
24852
24962
  const handleRelatedQueryClick = (query) => {
24853
24963
  var _a;
24854
24964
  if (((_a = props.options.source) == null ? void 0 : _a.mode) === "filter") {
24855
24965
  handleFilter(query);
24856
24966
  } else {
24857
- goToResults({ searchText: query });
24967
+ paramsStore.goToResults({ searchText: query.value });
24858
24968
  }
24859
24969
  };
24860
24970
  const handleFilter = (query) => {
24861
- var _a, _b;
24862
- const facet = (_b = (_a = searchResult.value) == null ? void 0 : _a.facets) == null ? void 0 : _b.find(
24863
- (facet2) => {
24864
- var _a2, _b2;
24865
- return facet2.key === ((_b2 = (_a2 = props.options) == null ? void 0 : _a2.source) == null ? void 0 : _b2.key);
24866
- }
24867
- );
24868
- if (!facet || facet.type !== "terms") {
24869
- return [];
24870
- }
24971
+ var _a;
24871
24972
  toggleTermFilter(
24872
24973
  paramsStore.appendParams,
24873
- { type: "terms", key: facet.key, value: query },
24974
+ { type: "terms", key: query.key, value: query.value },
24874
24975
  optionsStore.getQueryParamName,
24875
- {}
24976
+ {},
24977
+ (_a = querySources.value) == null ? void 0 : _a.map((q) => `f.${q}`)
24876
24978
  );
24877
24979
  };
24878
24980
  const getSelectedFilterClass = (query) => {
@@ -24880,9 +24982,13 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
24880
24982
  if (((_a = props.options.source) == null ? void 0 : _a.mode) !== "filter") {
24881
24983
  return "";
24882
24984
  }
24883
- 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(
24884
- query
24885
- )) ? "lupa-selected-related-query-filter" : "";
24985
+ 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" : "";
24986
+ };
24987
+ const processLoadedItem = (query, item) => {
24988
+ if (item) {
24989
+ allDisplayItems.value[`${item.id}`] = item;
24990
+ }
24991
+ querySourceResultMap.value[query.value] = Boolean(item);
24886
24992
  };
24887
24993
  return (_ctx, _cache) => {
24888
24994
  var _a, _b, _c, _d;
@@ -24890,19 +24996,24 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
24890
24996
  ((_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),
24891
24997
  createBaseVNode("ul", null, [
24892
24998
  (openBlock(true), createElementBlock(Fragment, null, renderList(relatedQueries.value, (query) => {
24893
- return openBlock(), createElementBlock("li", {
24894
- key: query + currentSearchText.value,
24999
+ return withDirectives((openBlock(), createElementBlock("li", {
25000
+ key: query.value + query.key + currentSearchText.value,
24895
25001
  class: normalizeClass(getSelectedFilterClass(query))
24896
25002
  }, [
24897
25003
  createBaseVNode("a", {
24898
25004
  onClick: ($event) => handleRelatedQueryClick(query)
24899
25005
  }, [
24900
25006
  createVNode(_sfc_main$j, {
25007
+ "source-key": query.key,
24901
25008
  options: _ctx.options,
24902
- query
24903
- }, null, 8, ["options", "query"])
25009
+ query: query.value,
25010
+ "existing-items-from-other-queries": allDisplayItems.value,
25011
+ onLoaded: (item) => processLoadedItem(query, item)
25012
+ }, null, 8, ["source-key", "options", "query", "existing-items-from-other-queries", "onLoaded"])
24904
25013
  ], 8, _hoisted_3$9)
24905
- ], 2);
25014
+ ], 2)), [
25015
+ [vShow, querySourceResultMap.value[query.value] !== false]
25016
+ ]);
24906
25017
  }), 128))
24907
25018
  ])
24908
25019
  ])) : createCommentVNode("", true);
@@ -25210,7 +25321,10 @@ const _hoisted_2$a = {
25210
25321
  class: "lupa-category-back"
25211
25322
  };
25212
25323
  const _hoisted_3$6 = ["href"];
25213
- const _hoisted_4$3 = { class: "lupa-child-category-list" };
25324
+ const _hoisted_4$3 = {
25325
+ key: 1,
25326
+ class: "lupa-child-category-list"
25327
+ };
25214
25328
  const _sfc_main$f = /* @__PURE__ */ defineComponent({
25215
25329
  __name: "CategoryTopFilters",
25216
25330
  props: {
@@ -25224,6 +25338,10 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
25224
25338
  var _a, _b;
25225
25339
  return Boolean((_b = (_a = props.options.categories) == null ? void 0 : _a.back) == null ? void 0 : _b.title);
25226
25340
  });
25341
+ const hasRelatedCategoryChildren = computed(() => {
25342
+ var _a;
25343
+ return ((_a = relatedCategoryChildren.value) == null ? void 0 : _a.length) > 0;
25344
+ });
25227
25345
  const backTitle = computed(() => {
25228
25346
  var _a, _b;
25229
25347
  return (_b = (_a = props.options.categories) == null ? void 0 : _a.back) == null ? void 0 : _b.title;
@@ -25250,7 +25368,10 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
25250
25368
  };
25251
25369
  return (_ctx, _cache) => {
25252
25370
  return openBlock(), createElementBlock("div", {
25253
- class: normalizeClass(["lupa-category-top-mobile-filters", { "lupa-has-back-button": hasBackButton.value }])
25371
+ class: normalizeClass(["lupa-category-top-mobile-filters", {
25372
+ "lupa-has-back-button": hasBackButton.value,
25373
+ "has-related-category-children": hasRelatedCategoryChildren.value
25374
+ }])
25254
25375
  }, [
25255
25376
  createBaseVNode("div", _hoisted_1$d, [
25256
25377
  hasBackButton.value ? (openBlock(), createElementBlock("div", _hoisted_2$a, [
@@ -25260,7 +25381,7 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
25260
25381
  onClick: handleNavigationBack
25261
25382
  }, toDisplayString(backTitle.value), 9, _hoisted_3$6)
25262
25383
  ])) : createCommentVNode("", true),
25263
- createBaseVNode("div", _hoisted_4$3, [
25384
+ hasRelatedCategoryChildren.value ? (openBlock(), createElementBlock("div", _hoisted_4$3, [
25264
25385
  (openBlock(true), createElementBlock(Fragment, null, renderList(unref(relatedCategoryChildren), (child) => {
25265
25386
  return openBlock(), createBlock(_sfc_main$U, {
25266
25387
  key: getCategoryKey(child),
@@ -25268,7 +25389,7 @@ const _sfc_main$f = /* @__PURE__ */ defineComponent({
25268
25389
  options: categoryOptions.value
25269
25390
  }, null, 8, ["item", "options"]);
25270
25391
  }), 128))
25271
- ]),
25392
+ ])) : createCommentVNode("", true),
25272
25393
  createVNode(_sfc_main$B, {
25273
25394
  class: "lupa-toolbar-mobile",
25274
25395
  "pagination-location": "top",