@getlupa/vue 0.17.1 → 0.17.3

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.
@@ -20007,6 +20007,9 @@ const _sfc_main$15 = /* @__PURE__ */ vue.defineComponent({
20007
20007
  }
20008
20008
  emit("product-click");
20009
20009
  handleRoutingEvent(link, event, boxRoutingBehavior.value === "event");
20010
+ if (props.panelOptions.programmaticNavigation) {
20011
+ window.location.assign(link);
20012
+ }
20010
20013
  };
20011
20014
  return (_ctx, _cache) => {
20012
20015
  return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$Z, [
@@ -20627,6 +20630,7 @@ const _sfc_main$10 = /* @__PURE__ */ vue.defineComponent({
20627
20630
  const suggestedValue = vue.ref(defaultSuggestedValue);
20628
20631
  const opened = vue.ref(props.isSearchContainer);
20629
20632
  const focused = vue.ref(false);
20633
+ const openedAt = vue.ref(null);
20630
20634
  const searchBoxInput = vue.ref(null);
20631
20635
  const { highlightedDocument } = storeToRefs(searchBoxStore);
20632
20636
  const searchValue = vue.computed(() => {
@@ -20663,7 +20667,7 @@ const _sfc_main$10 = /* @__PURE__ */ vue.defineComponent({
20663
20667
  });
20664
20668
  const goToResultsDebounced = debounce$1(paramsStore.goToResults, (_a = props.options.debounce) != null ? _a : 300);
20665
20669
  vue.onMounted(() => {
20666
- var _a2;
20670
+ var _a2, _b, _c;
20667
20671
  window.addEventListener("keydown", handleKeyDown);
20668
20672
  window.addEventListener("click", handleMouseClick);
20669
20673
  paramsStore.setSearchResultsLink(props.options.links.searchResults);
@@ -20674,6 +20678,9 @@ const _sfc_main$10 = /* @__PURE__ */ vue.defineComponent({
20674
20678
  if (props.isSearchContainer && searchBoxInput.value) {
20675
20679
  (_a2 = searchBoxInput.value) == null ? void 0 : _a2.focus();
20676
20680
  }
20681
+ if ((_b = props.options.callbacks) == null ? void 0 : _b.onMounted) {
20682
+ (_c = props.options.callbacks) == null ? void 0 : _c.onMounted();
20683
+ }
20677
20684
  });
20678
20685
  vue.onBeforeUnmount(() => {
20679
20686
  window.removeEventListener("keydown", handleKeyDown);
@@ -20681,11 +20688,14 @@ const _sfc_main$10 = /* @__PURE__ */ vue.defineComponent({
20681
20688
  unbindSearchTriggers(searchTriggers.value, handleCurrentValueSearch);
20682
20689
  });
20683
20690
  const handleMouseClick = (e2) => {
20684
- var _a2, _b;
20691
+ var _a2, _b, _c, _d;
20685
20692
  const el = document.getElementById("lupa-search-box");
20686
20693
  const elementClass = (_b = (_a2 = e2.target) == null ? void 0 : _a2.className) != null ? _b : "";
20687
20694
  const hasLupaClass = typeof elementClass.includes == "function" && elementClass.includes("lupa-search-box");
20688
20695
  const isOutsideElement = el && !el.contains(e2.target) && !hasLupaClass;
20696
+ if (openedAt.value && Date.now() - (openedAt == null ? void 0 : openedAt.value) < 500) {
20697
+ return;
20698
+ }
20689
20699
  if (isOutsideElement && props.options.keepOpen) {
20690
20700
  focused.value = false;
20691
20701
  }
@@ -20694,11 +20704,18 @@ const _sfc_main$10 = /* @__PURE__ */ vue.defineComponent({
20694
20704
  }
20695
20705
  opened.value = false;
20696
20706
  suggestedValue.value = defaultSuggestedValue;
20707
+ if ((_c = props.options.callbacks) == null ? void 0 : _c.onClosed) {
20708
+ (_d = props.options.callbacks) == null ? void 0 : _d.onClosed();
20709
+ }
20697
20710
  };
20698
20711
  const close = () => {
20712
+ var _a2, _b;
20699
20713
  opened.value = false;
20700
20714
  focused.value = false;
20701
20715
  suggestedValue.value = defaultSuggestedValue;
20716
+ if ((_a2 = props.options.callbacks) == null ? void 0 : _a2.onClosed) {
20717
+ (_b = props.options.callbacks) == null ? void 0 : _b.onClosed();
20718
+ }
20702
20719
  };
20703
20720
  const handleKeyDown = (e2) => {
20704
20721
  var _a2, _b;
@@ -20717,15 +20734,22 @@ const _sfc_main$10 = /* @__PURE__ */ vue.defineComponent({
20717
20734
  handleSearch();
20718
20735
  resetValues();
20719
20736
  break;
20737
+ case "Escape":
20738
+ opened.value = false;
20739
+ focused.value = false;
20740
+ break;
20720
20741
  }
20721
20742
  };
20722
20743
  const handleInput = (value) => {
20723
- var _a2;
20744
+ var _a2, _b;
20724
20745
  opened.value = true;
20725
20746
  focused.value = true;
20726
20747
  inputValue.value = (_a2 = value == null ? void 0 : value.replace(/\s+$/, "")) != null ? _a2 : "";
20727
20748
  suggestedValue.value = defaultSuggestedValue;
20728
20749
  searchBoxStore.resetHighlightIndex();
20750
+ if ((_b = props.options.callbacks) == null ? void 0 : _b.onSearchBoxInput) {
20751
+ props.options.callbacks.onSearchBoxInput(value);
20752
+ }
20729
20753
  trackSearchQuery(value);
20730
20754
  if (props.isSearchContainer) {
20731
20755
  goToResultsDebounced({
@@ -20858,6 +20882,13 @@ const _sfc_main$10 = /* @__PURE__ */ vue.defineComponent({
20858
20882
  });
20859
20883
  };
20860
20884
  vue.watch(() => props.options.debounce, handleCurrentValueSearch);
20885
+ vue.watch(opened, () => {
20886
+ if (opened.value) {
20887
+ openedAt.value = Date.now();
20888
+ } else {
20889
+ openedAt.value = null;
20890
+ }
20891
+ });
20861
20892
  const resetValues = () => {
20862
20893
  inputValue.value = "";
20863
20894
  suggestedValue.value = defaultSuggestedValue;
@@ -20869,6 +20900,20 @@ const _sfc_main$10 = /* @__PURE__ */ vue.defineComponent({
20869
20900
  const slotProps = (props2) => {
20870
20901
  return __spreadValues({}, props2);
20871
20902
  };
20903
+ const onFocus = () => {
20904
+ var _a2, _b;
20905
+ opened.value = true;
20906
+ if ((_a2 = props.options.callbacks) == null ? void 0 : _a2.onFocused) {
20907
+ (_b = props.options.callbacks) == null ? void 0 : _b.onFocused();
20908
+ }
20909
+ };
20910
+ const onBlur = () => {
20911
+ var _a2, _b;
20912
+ focused.value = false;
20913
+ if ((_a2 = props.options.callbacks) == null ? void 0 : _a2.onBlurred) {
20914
+ (_b = props.options.callbacks) == null ? void 0 : _b.onBlurred();
20915
+ }
20916
+ };
20872
20917
  return (_ctx, _cache) => {
20873
20918
  var _a2;
20874
20919
  return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$W, [
@@ -20881,10 +20926,10 @@ const _sfc_main$10 = /* @__PURE__ */ vue.defineComponent({
20881
20926
  ref_key: "searchBoxInput",
20882
20927
  ref: searchBoxInput,
20883
20928
  onInput: handleInput,
20884
- onBlur: _cache[0] || (_cache[0] = ($event) => focused.value = false),
20885
- onFocus: _cache[1] || (_cache[1] = ($event) => opened.value = true),
20929
+ onBlur,
20930
+ onFocus,
20886
20931
  onSearch: handleSearch,
20887
- onClose: _cache[2] || (_cache[2] = ($event) => _ctx.$emit("close"))
20932
+ onClose: _cache[0] || (_cache[0] = ($event) => _ctx.$emit("close"))
20888
20933
  }, null, 8, ["options", "suggestedValue", "can-close", "emit-input-on-focus"]),
20889
20934
  opened.value || _ctx.isSearchContainer ? (vue.openBlock(), vue.createBlock(_sfc_main$11, {
20890
20935
  key: 0,
@@ -20005,6 +20005,9 @@ const _sfc_main$15 = /* @__PURE__ */ defineComponent({
20005
20005
  }
20006
20006
  emit("product-click");
20007
20007
  handleRoutingEvent(link, event, boxRoutingBehavior.value === "event");
20008
+ if (props.panelOptions.programmaticNavigation) {
20009
+ window.location.assign(link);
20010
+ }
20008
20011
  };
20009
20012
  return (_ctx, _cache) => {
20010
20013
  return openBlock(), createElementBlock("div", _hoisted_1$Z, [
@@ -20625,6 +20628,7 @@ const _sfc_main$10 = /* @__PURE__ */ defineComponent({
20625
20628
  const suggestedValue = ref(defaultSuggestedValue);
20626
20629
  const opened = ref(props.isSearchContainer);
20627
20630
  const focused = ref(false);
20631
+ const openedAt = ref(null);
20628
20632
  const searchBoxInput = ref(null);
20629
20633
  const { highlightedDocument } = storeToRefs(searchBoxStore);
20630
20634
  const searchValue = computed(() => {
@@ -20661,7 +20665,7 @@ const _sfc_main$10 = /* @__PURE__ */ defineComponent({
20661
20665
  });
20662
20666
  const goToResultsDebounced = debounce$1(paramsStore.goToResults, (_a = props.options.debounce) != null ? _a : 300);
20663
20667
  onMounted(() => {
20664
- var _a2;
20668
+ var _a2, _b, _c;
20665
20669
  window.addEventListener("keydown", handleKeyDown);
20666
20670
  window.addEventListener("click", handleMouseClick);
20667
20671
  paramsStore.setSearchResultsLink(props.options.links.searchResults);
@@ -20672,6 +20676,9 @@ const _sfc_main$10 = /* @__PURE__ */ defineComponent({
20672
20676
  if (props.isSearchContainer && searchBoxInput.value) {
20673
20677
  (_a2 = searchBoxInput.value) == null ? void 0 : _a2.focus();
20674
20678
  }
20679
+ if ((_b = props.options.callbacks) == null ? void 0 : _b.onMounted) {
20680
+ (_c = props.options.callbacks) == null ? void 0 : _c.onMounted();
20681
+ }
20675
20682
  });
20676
20683
  onBeforeUnmount(() => {
20677
20684
  window.removeEventListener("keydown", handleKeyDown);
@@ -20679,11 +20686,14 @@ const _sfc_main$10 = /* @__PURE__ */ defineComponent({
20679
20686
  unbindSearchTriggers(searchTriggers.value, handleCurrentValueSearch);
20680
20687
  });
20681
20688
  const handleMouseClick = (e2) => {
20682
- var _a2, _b;
20689
+ var _a2, _b, _c, _d;
20683
20690
  const el = document.getElementById("lupa-search-box");
20684
20691
  const elementClass = (_b = (_a2 = e2.target) == null ? void 0 : _a2.className) != null ? _b : "";
20685
20692
  const hasLupaClass = typeof elementClass.includes == "function" && elementClass.includes("lupa-search-box");
20686
20693
  const isOutsideElement = el && !el.contains(e2.target) && !hasLupaClass;
20694
+ if (openedAt.value && Date.now() - (openedAt == null ? void 0 : openedAt.value) < 500) {
20695
+ return;
20696
+ }
20687
20697
  if (isOutsideElement && props.options.keepOpen) {
20688
20698
  focused.value = false;
20689
20699
  }
@@ -20692,11 +20702,18 @@ const _sfc_main$10 = /* @__PURE__ */ defineComponent({
20692
20702
  }
20693
20703
  opened.value = false;
20694
20704
  suggestedValue.value = defaultSuggestedValue;
20705
+ if ((_c = props.options.callbacks) == null ? void 0 : _c.onClosed) {
20706
+ (_d = props.options.callbacks) == null ? void 0 : _d.onClosed();
20707
+ }
20695
20708
  };
20696
20709
  const close = () => {
20710
+ var _a2, _b;
20697
20711
  opened.value = false;
20698
20712
  focused.value = false;
20699
20713
  suggestedValue.value = defaultSuggestedValue;
20714
+ if ((_a2 = props.options.callbacks) == null ? void 0 : _a2.onClosed) {
20715
+ (_b = props.options.callbacks) == null ? void 0 : _b.onClosed();
20716
+ }
20700
20717
  };
20701
20718
  const handleKeyDown = (e2) => {
20702
20719
  var _a2, _b;
@@ -20715,15 +20732,22 @@ const _sfc_main$10 = /* @__PURE__ */ defineComponent({
20715
20732
  handleSearch();
20716
20733
  resetValues();
20717
20734
  break;
20735
+ case "Escape":
20736
+ opened.value = false;
20737
+ focused.value = false;
20738
+ break;
20718
20739
  }
20719
20740
  };
20720
20741
  const handleInput = (value) => {
20721
- var _a2;
20742
+ var _a2, _b;
20722
20743
  opened.value = true;
20723
20744
  focused.value = true;
20724
20745
  inputValue.value = (_a2 = value == null ? void 0 : value.replace(/\s+$/, "")) != null ? _a2 : "";
20725
20746
  suggestedValue.value = defaultSuggestedValue;
20726
20747
  searchBoxStore.resetHighlightIndex();
20748
+ if ((_b = props.options.callbacks) == null ? void 0 : _b.onSearchBoxInput) {
20749
+ props.options.callbacks.onSearchBoxInput(value);
20750
+ }
20727
20751
  trackSearchQuery(value);
20728
20752
  if (props.isSearchContainer) {
20729
20753
  goToResultsDebounced({
@@ -20856,6 +20880,13 @@ const _sfc_main$10 = /* @__PURE__ */ defineComponent({
20856
20880
  });
20857
20881
  };
20858
20882
  watch(() => props.options.debounce, handleCurrentValueSearch);
20883
+ watch(opened, () => {
20884
+ if (opened.value) {
20885
+ openedAt.value = Date.now();
20886
+ } else {
20887
+ openedAt.value = null;
20888
+ }
20889
+ });
20859
20890
  const resetValues = () => {
20860
20891
  inputValue.value = "";
20861
20892
  suggestedValue.value = defaultSuggestedValue;
@@ -20867,6 +20898,20 @@ const _sfc_main$10 = /* @__PURE__ */ defineComponent({
20867
20898
  const slotProps = (props2) => {
20868
20899
  return __spreadValues({}, props2);
20869
20900
  };
20901
+ const onFocus = () => {
20902
+ var _a2, _b;
20903
+ opened.value = true;
20904
+ if ((_a2 = props.options.callbacks) == null ? void 0 : _a2.onFocused) {
20905
+ (_b = props.options.callbacks) == null ? void 0 : _b.onFocused();
20906
+ }
20907
+ };
20908
+ const onBlur = () => {
20909
+ var _a2, _b;
20910
+ focused.value = false;
20911
+ if ((_a2 = props.options.callbacks) == null ? void 0 : _a2.onBlurred) {
20912
+ (_b = props.options.callbacks) == null ? void 0 : _b.onBlurred();
20913
+ }
20914
+ };
20870
20915
  return (_ctx, _cache) => {
20871
20916
  var _a2;
20872
20917
  return openBlock(), createElementBlock("div", _hoisted_1$W, [
@@ -20879,10 +20924,10 @@ const _sfc_main$10 = /* @__PURE__ */ defineComponent({
20879
20924
  ref_key: "searchBoxInput",
20880
20925
  ref: searchBoxInput,
20881
20926
  onInput: handleInput,
20882
- onBlur: _cache[0] || (_cache[0] = ($event) => focused.value = false),
20883
- onFocus: _cache[1] || (_cache[1] = ($event) => opened.value = true),
20927
+ onBlur,
20928
+ onFocus,
20884
20929
  onSearch: handleSearch,
20885
- onClose: _cache[2] || (_cache[2] = ($event) => _ctx.$emit("close"))
20930
+ onClose: _cache[0] || (_cache[0] = ($event) => _ctx.$emit("close"))
20886
20931
  }, null, 8, ["options", "suggestedValue", "can-close", "emit-input-on-focus"]),
20887
20932
  opened.value || _ctx.isSearchContainer ? (openBlock(), createBlock(_sfc_main$11, {
20888
20933
  key: 0,
@@ -57,6 +57,11 @@ export type SearchBoxResultsNavigateContext = {
57
57
  };
58
58
  };
59
59
  export type SearchBoxEventCallbacks = {
60
+ onMounted: () => unknown;
61
+ onFocused: () => unknown;
62
+ onBlurred: () => unknown;
63
+ onClosed: () => unknown;
64
+ onSearchBoxInput?: (input: string) => unknown;
60
65
  onSearchBoxResults?: (context: SearchBoxResultCallbackContext) => unknown;
61
66
  onSearchResultsNavigate?: (context: SearchBoxResultsNavigateContext) => unknown;
62
67
  };
@@ -38,6 +38,7 @@ export type DocumentSearchBoxPanel = SearchBoxPanelBase & {
38
38
  badges?: SearchBoxBadgeOptions;
39
39
  showGoToResults?: boolean;
40
40
  isInStock?: DisplayCondition | ((doc: Document) => boolean);
41
+ programmaticNavigation?: boolean;
41
42
  customDocumentHtmlAttributes?: CustomDocumentHtmlAttributes;
42
43
  };
43
44
  export type RelatedSourcePanel = Omit<DocumentSearchBoxPanel, 'type'> & {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getlupa/vue",
3
- "version": "0.17.1",
3
+ "version": "0.17.3",
4
4
  "main": "dist/lupaSearch.mjs",
5
5
  "module": "dist/lupaSearch.mjs",
6
6
  "types": "dist/src/index.d.ts",