@getlupa/client 1.4.0 → 1.4.2

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.
@@ -7536,6 +7536,10 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
7536
7536
  };
7537
7537
  })
7538
7538
  );
7539
+ const hasAnyResults = computed(() => {
7540
+ var _a;
7541
+ return (_a = panelItemCounts.value) == null ? void 0 : _a.some((p2) => p2.count > 0);
7542
+ });
7539
7543
  const totalCount = computed(
7540
7544
  () => {
7541
7545
  var _a, _b;
@@ -7588,6 +7592,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
7588
7592
  [queryKey]: flattenSuggestions(result.items, (_a = publicQuery.searchText) != null ? _a : "")
7589
7593
  });
7590
7594
  inputValue.value = publicQuery.searchText;
7595
+ emitSearchResultsCallback();
7591
7596
  return {
7592
7597
  suggestions: result.items
7593
7598
  };
@@ -7599,6 +7604,19 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
7599
7604
  return { suggestions: void 0 };
7600
7605
  }
7601
7606
  });
7607
+ const emitSearchResultsCallback = () => {
7608
+ var _a;
7609
+ if ((_a = options.value.callbacks) == null ? void 0 : _a.onSearchBoxResults) {
7610
+ options.value.callbacks.onSearchBoxResults({
7611
+ hasAnyResults: hasAnyResults.value,
7612
+ docResults: docResults.value,
7613
+ suggestionResults: suggestionResults.value,
7614
+ totalCount: totalCount.value,
7615
+ panelItemCounts: panelItemCounts.value,
7616
+ inputValue: inputValue.value
7617
+ });
7618
+ }
7619
+ };
7602
7620
  const queryDocuments = (_0) => __async(void 0, [_0], function* ({
7603
7621
  queryKey,
7604
7622
  publicQuery,
@@ -7612,6 +7630,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
7612
7630
  }
7613
7631
  highlightChange({ action: "clear" });
7614
7632
  docResults.value = __spreadProps2(__spreadValues2({}, docResults.value), { [queryKey]: result });
7633
+ emitSearchResultsCallback();
7615
7634
  return { queryKey, result };
7616
7635
  } catch (err) {
7617
7636
  console.error(err);
@@ -7648,6 +7667,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
7648
7667
  totalCount,
7649
7668
  highlightedItem,
7650
7669
  highlightedDocument,
7670
+ hasAnyResults,
7651
7671
  querySuggestions,
7652
7672
  queryDocuments,
7653
7673
  highlightChange,
@@ -7656,16 +7676,16 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
7656
7676
  resetHighlightIndex
7657
7677
  };
7658
7678
  });
7659
- const _hoisted_1$1a = { id: "lupa-search-box-input-container" };
7679
+ const _hoisted_1$1b = { id: "lupa-search-box-input-container" };
7660
7680
  const _hoisted_2$O = { class: "lupa-input-clear" };
7661
7681
  const _hoisted_3$A = { id: "lupa-search-box-input" };
7662
- const _hoisted_4$r = ["value"];
7682
+ const _hoisted_4$q = ["value"];
7663
7683
  const _hoisted_5$f = ["placeholder"];
7664
7684
  const _hoisted_6$8 = {
7665
7685
  key: 0,
7666
7686
  class: "lupa-close-label"
7667
7687
  };
7668
- const _sfc_main$1i = /* @__PURE__ */ defineComponent({
7688
+ const _sfc_main$1j = /* @__PURE__ */ defineComponent({
7669
7689
  __name: "SearchBoxInput",
7670
7690
  props: {
7671
7691
  options: {},
@@ -7742,7 +7762,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
7742
7762
  };
7743
7763
  __expose({ focus });
7744
7764
  return (_ctx, _cache) => {
7745
- return openBlock(), createElementBlock("div", _hoisted_1$1a, [
7765
+ return openBlock(), createElementBlock("div", _hoisted_1$1b, [
7746
7766
  createBaseVNode("div", _hoisted_2$O, [
7747
7767
  createBaseVNode("div", {
7748
7768
  class: normalizeClass(["lupa-input-clear-content", { "lupa-input-clear-filled": inputValue.value }]),
@@ -7754,7 +7774,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
7754
7774
  class: "lupa-hint",
7755
7775
  value: showHint.value ? suggestedValue.value.item.suggestion : "",
7756
7776
  disabled: ""
7757
- }, null, 8, _hoisted_4$r),
7777
+ }, null, 8, _hoisted_4$q),
7758
7778
  withDirectives(createBaseVNode("input", mergeProps({
7759
7779
  "onUpdate:modelValue": _cache[0] || (_cache[0] = ($event) => inputValue.value = $event)
7760
7780
  }, inputAttributes.value, {
@@ -7782,7 +7802,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
7782
7802
  };
7783
7803
  }
7784
7804
  });
7785
- const _sfc_main$1h = /* @__PURE__ */ defineComponent({
7805
+ const _sfc_main$1i = /* @__PURE__ */ defineComponent({
7786
7806
  __name: "SearchBoxMoreResults",
7787
7807
  props: {
7788
7808
  labels: {},
@@ -7814,9 +7834,9 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
7814
7834
  };
7815
7835
  }
7816
7836
  });
7817
- const _hoisted_1$19 = { class: "lupa-search-box-history-item" };
7837
+ const _hoisted_1$1a = { class: "lupa-search-box-history-item" };
7818
7838
  const _hoisted_2$N = { class: "lupa-search-box-history-item-content" };
7819
- const _sfc_main$1g = /* @__PURE__ */ defineComponent({
7839
+ const _sfc_main$1h = /* @__PURE__ */ defineComponent({
7820
7840
  __name: "SearchBoxHistoryItem",
7821
7841
  props: {
7822
7842
  item: {},
@@ -7832,7 +7852,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
7832
7852
  emit2("click", { query: props.item });
7833
7853
  };
7834
7854
  return (_ctx, _cache) => {
7835
- return openBlock(), createElementBlock("div", _hoisted_1$19, [
7855
+ return openBlock(), createElementBlock("div", _hoisted_1$1a, [
7836
7856
  createBaseVNode("div", _hoisted_2$N, [
7837
7857
  createBaseVNode("div", {
7838
7858
  class: normalizeClass(["lupa-search-box-history-item-text", { "lupa-search-box-history-item-highlighted": _ctx.highlighted }]),
@@ -7847,11 +7867,11 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
7847
7867
  };
7848
7868
  }
7849
7869
  });
7850
- const _hoisted_1$18 = {
7870
+ const _hoisted_1$19 = {
7851
7871
  key: 0,
7852
7872
  class: "lupa-search-box-history-panel"
7853
7873
  };
7854
- const _sfc_main$1f = /* @__PURE__ */ defineComponent({
7874
+ const _sfc_main$1g = /* @__PURE__ */ defineComponent({
7855
7875
  __name: "SearchBoxHistoryPanel",
7856
7876
  props: {
7857
7877
  options: {}
@@ -7892,9 +7912,9 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
7892
7912
  }
7893
7913
  };
7894
7914
  return (_ctx, _cache) => {
7895
- return hasHistory.value ? (openBlock(), createElementBlock("div", _hoisted_1$18, [
7915
+ return hasHistory.value ? (openBlock(), createElementBlock("div", _hoisted_1$19, [
7896
7916
  (openBlock(true), createElementBlock(Fragment, null, renderList(unref(history), (item, index) => {
7897
- return openBlock(), createBlock(_sfc_main$1g, {
7917
+ return openBlock(), createBlock(_sfc_main$1h, {
7898
7918
  key: item,
7899
7919
  item,
7900
7920
  highlighted: index === highlightIndex.value,
@@ -7910,6 +7930,18 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
7910
7930
  };
7911
7931
  }
7912
7932
  });
7933
+ const _hoisted_1$18 = { class: "lupa-search-box-no-results" };
7934
+ const _sfc_main$1f = /* @__PURE__ */ defineComponent({
7935
+ __name: "SearchBoxNoResults",
7936
+ props: {
7937
+ labels: {}
7938
+ },
7939
+ setup(__props) {
7940
+ return (_ctx, _cache) => {
7941
+ return openBlock(), createElementBlock("p", _hoisted_1$18, toDisplayString(_ctx.labels.noResults), 1);
7942
+ };
7943
+ }
7944
+ });
7913
7945
  const _hoisted_1$17 = ["innerHTML"];
7914
7946
  const _hoisted_2$M = {
7915
7947
  key: 1,
@@ -7921,7 +7953,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
7921
7953
  class: "lupa-suggestion-facet",
7922
7954
  "data-cy": "lupa-suggestion-facet"
7923
7955
  };
7924
- const _hoisted_4$q = {
7956
+ const _hoisted_4$p = {
7925
7957
  class: "lupa-suggestion-facet-label",
7926
7958
  "data-cy": "lupa-suggestion-facet-label"
7927
7959
  };
@@ -7967,7 +7999,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
7967
7999
  innerHTML: _ctx.suggestion.displayHighlight
7968
8000
  }, null, 8, _hoisted_1$17)) : (openBlock(), createElementBlock("div", _hoisted_2$M, toDisplayString(_ctx.suggestion.display), 1)),
7969
8001
  _ctx.suggestion.facet ? (openBlock(), createElementBlock("div", _hoisted_3$z, [
7970
- createBaseVNode("span", _hoisted_4$q, toDisplayString(facetLabel.value), 1),
8002
+ createBaseVNode("span", _hoisted_4$p, toDisplayString(facetLabel.value), 1),
7971
8003
  createBaseVNode("span", _hoisted_5$e, toDisplayString(_ctx.suggestion.facet.title), 1)
7972
8004
  ])) : createCommentVNode("", true)
7973
8005
  ]);
@@ -8369,7 +8401,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
8369
8401
  const _hoisted_1$10 = ["innerHTML"];
8370
8402
  const _hoisted_2$J = { key: 0 };
8371
8403
  const _hoisted_3$y = { key: 1 };
8372
- const _hoisted_4$p = { class: "lupa-search-box-custom-label" };
8404
+ const _hoisted_4$o = { class: "lupa-search-box-custom-label" };
8373
8405
  const _hoisted_5$d = { class: "lupa-search-box-custom-text" };
8374
8406
  const _sfc_main$15 = /* @__PURE__ */ defineComponent({
8375
8407
  __name: "SearchBoxProductCustom",
@@ -8402,7 +8434,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
8402
8434
  class: [className.value, "lupa-search-box-product-custom"]
8403
8435
  }, toHandlers(_ctx.options.action ? { click: handleClick } : {}, true)), [
8404
8436
  !label.value ? (openBlock(), createElementBlock("div", _hoisted_2$J, toDisplayString(text.value), 1)) : (openBlock(), createElementBlock("div", _hoisted_3$y, [
8405
- createBaseVNode("div", _hoisted_4$p, toDisplayString(label.value), 1),
8437
+ createBaseVNode("div", _hoisted_4$o, toDisplayString(label.value), 1),
8406
8438
  createBaseVNode("div", _hoisted_5$d, toDisplayString(text.value), 1)
8407
8439
  ]))
8408
8440
  ], 16));
@@ -8798,7 +8830,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
8798
8830
  const _hoisted_1$Z = ["href"];
8799
8831
  const _hoisted_2$H = { class: "lupa-search-box-product-image-section" };
8800
8832
  const _hoisted_3$w = { class: "lupa-search-box-product-details-section" };
8801
- const _hoisted_4$o = {
8833
+ const _hoisted_4$n = {
8802
8834
  key: 0,
8803
8835
  class: "lupa-search-box-product-add-to-cart-section"
8804
8836
  };
@@ -8919,7 +8951,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
8919
8951
  }, null, 8, ["item", "element", "labels", "link"]);
8920
8952
  }), 128))
8921
8953
  ]),
8922
- addToCartElement.value ? (openBlock(), createElementBlock("div", _hoisted_4$o, [
8954
+ addToCartElement.value ? (openBlock(), createElementBlock("div", _hoisted_4$n, [
8923
8955
  createVNode(_sfc_main$12, {
8924
8956
  class: "lupa-search-box-product-element",
8925
8957
  item: _ctx.item,
@@ -9054,12 +9086,8 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
9054
9086
  key: 0,
9055
9087
  id: "lupa-search-box-panel"
9056
9088
  };
9057
- const _hoisted_2$G = {
9058
- class: "lupa-main-panel",
9059
- "data-cy": "lupa-main-panel"
9060
- };
9061
- const _hoisted_3$v = ["data-cy"];
9062
- const _hoisted_4$n = {
9089
+ const _hoisted_2$G = ["data-cy"];
9090
+ const _hoisted_3$v = {
9063
9091
  key: 1,
9064
9092
  id: "lupa-search-box-panel"
9065
9093
  };
@@ -9096,7 +9124,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
9096
9124
  const panels = computed(() => props.options.panels);
9097
9125
  const sdkOptions = computed(() => props.options.options);
9098
9126
  const searchBoxStore = useSearchBoxStore();
9099
- const { suggestionResults } = storeToRefs(searchBoxStore);
9127
+ const { suggestionResults, hasAnyResults, panelItemCounts } = storeToRefs(searchBoxStore);
9100
9128
  const displayResults = computed(
9101
9129
  () => {
9102
9130
  var _a, _b;
@@ -9177,6 +9205,12 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
9177
9205
  `${window.innerHeight - panel.getBoundingClientRect().y - 10}px`
9178
9206
  );
9179
9207
  };
9208
+ const numberOfVisiblePanels = computed(() => {
9209
+ return panelItemCounts.value.filter((v) => v.count > 0).length;
9210
+ });
9211
+ const expandOnSinglePanel = computed(() => {
9212
+ return numberOfVisiblePanels.value === 1 && props.options.expandOnSinglePanel;
9213
+ });
9180
9214
  return (_ctx, _cache) => {
9181
9215
  var _a;
9182
9216
  return openBlock(), createElementBlock("div", {
@@ -9184,7 +9218,11 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
9184
9218
  ref: panelContainer
9185
9219
  }, [
9186
9220
  displayResults.value ? (openBlock(), createElementBlock("div", _hoisted_1$X, [
9187
- createBaseVNode("div", _hoisted_2$G, [
9221
+ createBaseVNode("div", {
9222
+ class: "lupa-main-panel",
9223
+ style: normalizeStyle(expandOnSinglePanel.value ? { display: "block" } : {}),
9224
+ "data-cy": "lupa-main-panel"
9225
+ }, [
9188
9226
  (openBlock(true), createElementBlock(Fragment, null, renderList(displayPanels.value, (panel, index) => {
9189
9227
  return openBlock(), createElementBlock("div", {
9190
9228
  key: index,
@@ -9213,16 +9251,21 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
9213
9251
  key: "0"
9214
9252
  } : void 0
9215
9253
  ]), 1064, ["panel", "options", "debounce", "inputValue", "labels"])) : createCommentVNode("", true)
9216
- ], 10, _hoisted_3$v);
9254
+ ], 10, _hoisted_2$G);
9217
9255
  }), 128))
9218
- ]),
9219
- createVNode(_sfc_main$1h, {
9256
+ ], 4),
9257
+ !unref(hasAnyResults) && _ctx.options.showNoResultsPanel ? (openBlock(), createBlock(_sfc_main$1f, {
9258
+ key: 0,
9259
+ labels: labels.value
9260
+ }, null, 8, ["labels"])) : createCommentVNode("", true),
9261
+ unref(hasAnyResults) || !_ctx.options.hideMoreResultsButtonOnNoResults ? (openBlock(), createBlock(_sfc_main$1i, {
9262
+ key: 1,
9220
9263
  labels: labels.value,
9221
9264
  showTotalCount: (_a = _ctx.options.showTotalCount) != null ? _a : false,
9222
9265
  onGoToResults: _cache[3] || (_cache[3] = ($event) => _ctx.$emit("go-to-results"))
9223
- }, null, 8, ["labels", "showTotalCount"])
9224
- ])) : displayHistory.value ? (openBlock(), createElementBlock("div", _hoisted_4$n, [
9225
- createVNode(_sfc_main$1f, {
9266
+ }, null, 8, ["labels", "showTotalCount"])) : createCommentVNode("", true)
9267
+ ])) : displayHistory.value ? (openBlock(), createElementBlock("div", _hoisted_3$v, [
9268
+ createVNode(_sfc_main$1g, {
9226
9269
  options: _ctx.options.history,
9227
9270
  history: history.value,
9228
9271
  onGoToResults: handleGoToResults,
@@ -9288,7 +9331,10 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
9288
9331
  "links",
9289
9332
  "options",
9290
9333
  "debounce",
9291
- "showTotalCount"
9334
+ "showTotalCount",
9335
+ "hideMoreResultsButtonOnNoResults",
9336
+ "showNoResultsPanel",
9337
+ "expandOnSinglePanel"
9292
9338
  ])
9293
9339
  );
9294
9340
  const searchTriggers = computed(() => {
@@ -9484,7 +9530,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
9484
9530
  var _a2;
9485
9531
  return openBlock(), createElementBlock("div", _hoisted_1$W, [
9486
9532
  createBaseVNode("div", _hoisted_2$F, [
9487
- createVNode(_sfc_main$1i, {
9533
+ createVNode(_sfc_main$1j, {
9488
9534
  options: inputOptions.value,
9489
9535
  suggestedValue: suggestedValue.value,
9490
9536
  "can-close": (_a2 = _ctx.isSearchContainer) != null ? _a2 : false,
@@ -13957,8 +14003,14 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
13957
14003
  const isTitleResultTopPosition = computed(() => {
13958
14004
  return props.options.searchTitlePosition === "search-results-top";
13959
14005
  });
14006
+ const handlePopState = () => {
14007
+ var _a;
14008
+ const searchParams = getSearchParams((_a = props.options.ssr) == null ? void 0 : _a.url);
14009
+ paramStore.add(parseParams(searchParams));
14010
+ };
13960
14011
  onMounted(() => {
13961
14012
  var _a, _b;
14013
+ window.addEventListener("popstate", handlePopState);
13962
14014
  window.addEventListener("resize", handleResize);
13963
14015
  if (props.initialData) {
13964
14016
  searchResultStore.add(__spreadValues2({}, props.initialData));
@@ -13969,6 +14021,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
13969
14021
  });
13970
14022
  onBeforeUnmount(() => {
13971
14023
  window.removeEventListener("resize", handleResize);
14024
+ window.removeEventListener("popstate", handlePopState);
13972
14025
  });
13973
14026
  const trackItemListView = (title, items = []) => {
13974
14027
  trackingStore.trackEvent({
@@ -21171,7 +21224,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
21171
21224
  class: "lupa-chat-spinner-main"
21172
21225
  };
21173
21226
  const _hoisted_5 = { class: "lupasearch-chat-input" };
21174
- const _sfc_main$1j = /* @__PURE__ */ defineComponent({
21227
+ const _sfc_main$1k = /* @__PURE__ */ defineComponent({
21175
21228
  __name: "ChatContainer",
21176
21229
  props: {
21177
21230
  options: {}
@@ -27286,7 +27339,7 @@ var __spreadProps = (a, b) => __defProps(a, __getOwnPropDescs(b));
27286
27339
  }
27287
27340
  return;
27288
27341
  }
27289
- const instance = createVue(options.displayOptions.containerSelector, _sfc_main$1j, {
27342
+ const instance = createVue(options.displayOptions.containerSelector, _sfc_main$1k, {
27290
27343
  options
27291
27344
  });
27292
27345
  if (!instance) {