@getlupa/vue 0.14.16 → 0.15.0

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.
@@ -2580,7 +2580,10 @@ const getHint = (suggestion, inputValue) => {
2580
2580
  if (!inputValue) {
2581
2581
  return escapeHtml$1(suggestion);
2582
2582
  }
2583
- return (_a = suggestion == null ? void 0 : suggestion.replace(inputValue, `<strong>${escapeHtml$1(inputValue)}</strong>`)) != null ? _a : "";
2583
+ return (_a = suggestion == null ? void 0 : suggestion.replace(
2584
+ inputValue == null ? void 0 : inputValue.toLocaleLowerCase(),
2585
+ `<strong>${escapeHtml$1(inputValue == null ? void 0 : inputValue.toLocaleLowerCase())}</strong>`
2586
+ )) != null ? _a : "";
2584
2587
  };
2585
2588
  const reverseKeyValue = (obj) => {
2586
2589
  return Object.fromEntries(Object.entries(obj).map(([k, v]) => [v, k.toLowerCase()]));
@@ -2798,14 +2801,16 @@ const toggleTermFilter = (appendParams, facetAction, getQueryParamName, currentF
2798
2801
  paramsToRemove: [getQueryParamName ? getQueryParamName(QUERY_PARAMS.PAGE) : QUERY_PARAMS.PAGE]
2799
2802
  });
2800
2803
  };
2804
+ const replaceHierarchyParam = (params = [], param = "") => {
2805
+ if (params.some((p2) => p2.startsWith(param))) {
2806
+ return toggleLastPram(params, param);
2807
+ }
2808
+ return [param];
2809
+ };
2801
2810
  const toggleHierarchyFilter = (appendParams, facetAction, getQueryParamName, currentFilters, removeAllLevels = false) => {
2802
- var _a;
2811
+ var _a, _b;
2803
2812
  const currentFilter = currentFilters == null ? void 0 : currentFilters[facetAction.key];
2804
- const newParams = toggleHierarchyParam(
2805
- (_a = currentFilter == null ? void 0 : currentFilter.terms) != null ? _a : [],
2806
- facetAction.value,
2807
- removeAllLevels
2808
- );
2813
+ const newParams = facetAction.behavior === "replace" ? replaceHierarchyParam((_a = currentFilter == null ? void 0 : currentFilter.terms) != null ? _a : [], facetAction.value) : toggleHierarchyParam((_b = currentFilter == null ? void 0 : currentFilter.terms) != null ? _b : [], facetAction.value, removeAllLevels);
2809
2814
  appendParams({
2810
2815
  params: [getFacetParam(facetAction.key, newParams, FACET_PARAMS_TYPE.HIERARCHY)],
2811
2816
  paramsToRemove: [getQueryParamName ? getQueryParamName(QUERY_PARAMS.PAGE) : QUERY_PARAMS.PAGE]
@@ -3148,6 +3153,7 @@ const useSearchBoxStore = defineStore("searchBox", () => {
3148
3153
  const highlightedIndex = vue.ref(-1);
3149
3154
  const inputValue = vue.ref("");
3150
3155
  const resultInputValue = vue.ref("");
3156
+ const latestRequestIdByQueryKey = {};
3151
3157
  const historyStore = useHistoryStore();
3152
3158
  const resultsVisible = vue.computed(() => {
3153
3159
  var _a;
@@ -3214,12 +3220,17 @@ const useSearchBoxStore = defineStore("searchBox", () => {
3214
3220
  }) {
3215
3221
  var _a;
3216
3222
  try {
3223
+ const currentRequestId = Date.now();
3224
+ latestRequestIdByQueryKey[queryKey] = currentRequestId;
3217
3225
  const context = getLupaTrackingContext();
3218
3226
  const result2 = yield LupaSearchSdk.suggestions(
3219
3227
  queryKey,
3220
3228
  __spreadValues(__spreadValues({}, publicQuery), context),
3221
3229
  options2
3222
3230
  );
3231
+ if (latestRequestIdByQueryKey[queryKey] !== currentRequestId) {
3232
+ return { suggestions: void 0 };
3233
+ }
3223
3234
  if (!result2.success) {
3224
3235
  return { suggestions: void 0 };
3225
3236
  }
@@ -3260,8 +3271,13 @@ const useSearchBoxStore = defineStore("searchBox", () => {
3260
3271
  options: options2
3261
3272
  }) {
3262
3273
  try {
3274
+ const currentRequestId = Date.now();
3275
+ latestRequestIdByQueryKey[queryKey] = currentRequestId;
3263
3276
  const context = getLupaTrackingContext();
3264
3277
  const result2 = yield LupaSearchSdk.query(queryKey, __spreadValues(__spreadValues({}, publicQuery), context), options2);
3278
+ if (latestRequestIdByQueryKey[queryKey] !== currentRequestId) {
3279
+ return { suggestions: void 0 };
3280
+ }
3265
3281
  if (!result2.success) {
3266
3282
  return { queryKey, result: { items: [] } };
3267
3283
  }
@@ -16843,8 +16859,12 @@ const _sfc_main$Q = /* @__PURE__ */ vue.defineComponent({
16843
16859
  var _a;
16844
16860
  return Boolean((_a = props.options.stats) == null ? void 0 : _a.inputs);
16845
16861
  });
16862
+ const pricePrecision = vue.computed(() => {
16863
+ var _a, _b;
16864
+ return (_b = (_a = props.options.stats) == null ? void 0 : _a.pricePrecisionDigits) != null ? _b : 2;
16865
+ });
16846
16866
  const fromValue = vue.computed({
16847
- get: () => isPrice.value ? sliderRange.value[0].toFixed(2).replace(".", separator.value) : `${sliderRange.value[0]}`,
16867
+ get: () => isPrice.value ? sliderRange.value[0].toFixed(pricePrecision.value).replace(".", separator.value) : `${sliderRange.value[0]}`,
16848
16868
  set: (stringValue) => {
16849
16869
  let value = normalizeFloat(stringValue);
16850
16870
  if (value < facetMin.value) {
@@ -16858,7 +16878,7 @@ const _sfc_main$Q = /* @__PURE__ */ vue.defineComponent({
16858
16878
  }
16859
16879
  });
16860
16880
  const toValue = vue.computed({
16861
- get: () => isPrice.value ? sliderRange.value[1].toFixed(2).replace(".", separator.value) : `${sliderRange.value[1]}`,
16881
+ get: () => isPrice.value ? sliderRange.value[1].toFixed(pricePrecision.value).replace(".", separator.value) : `${sliderRange.value[1]}`,
16862
16882
  set: (stringValue) => {
16863
16883
  let value = normalizeFloat(stringValue);
16864
16884
  if (value > facetMax.value) {
@@ -17167,15 +17187,20 @@ const _sfc_main$O = /* @__PURE__ */ vue.defineComponent({
17167
17187
  return Boolean((_a = props.options.hierarchy) == null ? void 0 : _a.filterable) && allValues.value.length >= ((_c = (_b = props.options.filterable) == null ? void 0 : _b.minValues) != null ? _c : MAX_FACET_VALUES);
17168
17188
  });
17169
17189
  const handleFacetClick = ({ value }) => {
17190
+ var _a, _b;
17170
17191
  emit("select", {
17171
17192
  key: facet.value.key,
17172
17193
  value,
17173
- type: "hierarchy"
17194
+ type: "hierarchy",
17195
+ behavior: (_b = (_a = props.options.hierarchy) == null ? void 0 : _a.behavior) != null ? _b : "append"
17174
17196
  });
17175
17197
  };
17176
17198
  const handleShowAll = () => {
17177
17199
  showAll.value = true;
17178
17200
  };
17201
+ const handleCancelShowAll = () => {
17202
+ showAll.value = false;
17203
+ };
17179
17204
  return (_ctx, _cache) => {
17180
17205
  return vue.openBlock(), vue.createElementBlock("div", _hoisted_1$J, [
17181
17206
  isFilterable.value ? (vue.openBlock(), vue.createElementBlock("div", _hoisted_2$x, [
@@ -17204,7 +17229,11 @@ const _sfc_main$O = /* @__PURE__ */ vue.defineComponent({
17204
17229
  class: "lupa-facet-term lupa-show-more-facet-results",
17205
17230
  "data-cy": "lupa-facet-term",
17206
17231
  onClick: handleShowAll
17207
- }, vue.toDisplayString(_ctx.options.labels.showAll), 1)) : vue.createCommentVNode("", true)
17232
+ }, vue.toDisplayString(_ctx.options.labels.showAll), 1)) : showAll.value ? (vue.openBlock(), vue.createElementBlock("div", {
17233
+ key: 2,
17234
+ class: "lupa-facet-term lupa-show-more-facet-results",
17235
+ onClick: handleCancelShowAll
17236
+ }, vue.toDisplayString(_ctx.options.labels.showLess), 1)) : vue.createCommentVNode("", true)
17208
17237
  ]);
17209
17238
  };
17210
17239
  }
@@ -19395,7 +19424,6 @@ const _sfc_main$i = /* @__PURE__ */ vue.defineComponent({
19395
19424
  vue.watch(
19396
19425
  () => props.query,
19397
19426
  () => {
19398
- console.log("query changed", props.query);
19399
19427
  searchForRelatedQuery();
19400
19428
  }
19401
19429
  );
@@ -26604,6 +26632,7 @@ const _sfc_main$a = /* @__PURE__ */ vue.defineComponent({
26604
26632
  return;
26605
26633
  }
26606
26634
  recommendations.value = result2.recommended;
26635
+ loading.value = false;
26607
26636
  yield dynamicDataStore.enhanceSearchResultsWithDynamicData({
26608
26637
  result: { items: result2.recommended }
26609
26638
  });
@@ -2578,7 +2578,10 @@ const getHint = (suggestion, inputValue) => {
2578
2578
  if (!inputValue) {
2579
2579
  return escapeHtml$1(suggestion);
2580
2580
  }
2581
- return (_a = suggestion == null ? void 0 : suggestion.replace(inputValue, `<strong>${escapeHtml$1(inputValue)}</strong>`)) != null ? _a : "";
2581
+ return (_a = suggestion == null ? void 0 : suggestion.replace(
2582
+ inputValue == null ? void 0 : inputValue.toLocaleLowerCase(),
2583
+ `<strong>${escapeHtml$1(inputValue == null ? void 0 : inputValue.toLocaleLowerCase())}</strong>`
2584
+ )) != null ? _a : "";
2582
2585
  };
2583
2586
  const reverseKeyValue = (obj) => {
2584
2587
  return Object.fromEntries(Object.entries(obj).map(([k, v]) => [v, k.toLowerCase()]));
@@ -2796,14 +2799,16 @@ const toggleTermFilter = (appendParams, facetAction, getQueryParamName, currentF
2796
2799
  paramsToRemove: [getQueryParamName ? getQueryParamName(QUERY_PARAMS.PAGE) : QUERY_PARAMS.PAGE]
2797
2800
  });
2798
2801
  };
2802
+ const replaceHierarchyParam = (params = [], param = "") => {
2803
+ if (params.some((p2) => p2.startsWith(param))) {
2804
+ return toggleLastPram(params, param);
2805
+ }
2806
+ return [param];
2807
+ };
2799
2808
  const toggleHierarchyFilter = (appendParams, facetAction, getQueryParamName, currentFilters, removeAllLevels = false) => {
2800
- var _a;
2809
+ var _a, _b;
2801
2810
  const currentFilter = currentFilters == null ? void 0 : currentFilters[facetAction.key];
2802
- const newParams = toggleHierarchyParam(
2803
- (_a = currentFilter == null ? void 0 : currentFilter.terms) != null ? _a : [],
2804
- facetAction.value,
2805
- removeAllLevels
2806
- );
2811
+ const newParams = facetAction.behavior === "replace" ? replaceHierarchyParam((_a = currentFilter == null ? void 0 : currentFilter.terms) != null ? _a : [], facetAction.value) : toggleHierarchyParam((_b = currentFilter == null ? void 0 : currentFilter.terms) != null ? _b : [], facetAction.value, removeAllLevels);
2807
2812
  appendParams({
2808
2813
  params: [getFacetParam(facetAction.key, newParams, FACET_PARAMS_TYPE.HIERARCHY)],
2809
2814
  paramsToRemove: [getQueryParamName ? getQueryParamName(QUERY_PARAMS.PAGE) : QUERY_PARAMS.PAGE]
@@ -3146,6 +3151,7 @@ const useSearchBoxStore = defineStore("searchBox", () => {
3146
3151
  const highlightedIndex = ref(-1);
3147
3152
  const inputValue = ref("");
3148
3153
  const resultInputValue = ref("");
3154
+ const latestRequestIdByQueryKey = {};
3149
3155
  const historyStore = useHistoryStore();
3150
3156
  const resultsVisible = computed(() => {
3151
3157
  var _a;
@@ -3212,12 +3218,17 @@ const useSearchBoxStore = defineStore("searchBox", () => {
3212
3218
  }) {
3213
3219
  var _a;
3214
3220
  try {
3221
+ const currentRequestId = Date.now();
3222
+ latestRequestIdByQueryKey[queryKey] = currentRequestId;
3215
3223
  const context = getLupaTrackingContext();
3216
3224
  const result2 = yield LupaSearchSdk.suggestions(
3217
3225
  queryKey,
3218
3226
  __spreadValues(__spreadValues({}, publicQuery), context),
3219
3227
  options2
3220
3228
  );
3229
+ if (latestRequestIdByQueryKey[queryKey] !== currentRequestId) {
3230
+ return { suggestions: void 0 };
3231
+ }
3221
3232
  if (!result2.success) {
3222
3233
  return { suggestions: void 0 };
3223
3234
  }
@@ -3258,8 +3269,13 @@ const useSearchBoxStore = defineStore("searchBox", () => {
3258
3269
  options: options2
3259
3270
  }) {
3260
3271
  try {
3272
+ const currentRequestId = Date.now();
3273
+ latestRequestIdByQueryKey[queryKey] = currentRequestId;
3261
3274
  const context = getLupaTrackingContext();
3262
3275
  const result2 = yield LupaSearchSdk.query(queryKey, __spreadValues(__spreadValues({}, publicQuery), context), options2);
3276
+ if (latestRequestIdByQueryKey[queryKey] !== currentRequestId) {
3277
+ return { suggestions: void 0 };
3278
+ }
3263
3279
  if (!result2.success) {
3264
3280
  return { queryKey, result: { items: [] } };
3265
3281
  }
@@ -16841,8 +16857,12 @@ const _sfc_main$Q = /* @__PURE__ */ defineComponent({
16841
16857
  var _a;
16842
16858
  return Boolean((_a = props.options.stats) == null ? void 0 : _a.inputs);
16843
16859
  });
16860
+ const pricePrecision = computed(() => {
16861
+ var _a, _b;
16862
+ return (_b = (_a = props.options.stats) == null ? void 0 : _a.pricePrecisionDigits) != null ? _b : 2;
16863
+ });
16844
16864
  const fromValue = computed({
16845
- get: () => isPrice.value ? sliderRange.value[0].toFixed(2).replace(".", separator.value) : `${sliderRange.value[0]}`,
16865
+ get: () => isPrice.value ? sliderRange.value[0].toFixed(pricePrecision.value).replace(".", separator.value) : `${sliderRange.value[0]}`,
16846
16866
  set: (stringValue) => {
16847
16867
  let value = normalizeFloat(stringValue);
16848
16868
  if (value < facetMin.value) {
@@ -16856,7 +16876,7 @@ const _sfc_main$Q = /* @__PURE__ */ defineComponent({
16856
16876
  }
16857
16877
  });
16858
16878
  const toValue = computed({
16859
- get: () => isPrice.value ? sliderRange.value[1].toFixed(2).replace(".", separator.value) : `${sliderRange.value[1]}`,
16879
+ get: () => isPrice.value ? sliderRange.value[1].toFixed(pricePrecision.value).replace(".", separator.value) : `${sliderRange.value[1]}`,
16860
16880
  set: (stringValue) => {
16861
16881
  let value = normalizeFloat(stringValue);
16862
16882
  if (value > facetMax.value) {
@@ -17165,15 +17185,20 @@ const _sfc_main$O = /* @__PURE__ */ defineComponent({
17165
17185
  return Boolean((_a = props.options.hierarchy) == null ? void 0 : _a.filterable) && allValues.value.length >= ((_c = (_b = props.options.filterable) == null ? void 0 : _b.minValues) != null ? _c : MAX_FACET_VALUES);
17166
17186
  });
17167
17187
  const handleFacetClick = ({ value }) => {
17188
+ var _a, _b;
17168
17189
  emit("select", {
17169
17190
  key: facet.value.key,
17170
17191
  value,
17171
- type: "hierarchy"
17192
+ type: "hierarchy",
17193
+ behavior: (_b = (_a = props.options.hierarchy) == null ? void 0 : _a.behavior) != null ? _b : "append"
17172
17194
  });
17173
17195
  };
17174
17196
  const handleShowAll = () => {
17175
17197
  showAll.value = true;
17176
17198
  };
17199
+ const handleCancelShowAll = () => {
17200
+ showAll.value = false;
17201
+ };
17177
17202
  return (_ctx, _cache) => {
17178
17203
  return openBlock(), createElementBlock("div", _hoisted_1$J, [
17179
17204
  isFilterable.value ? (openBlock(), createElementBlock("div", _hoisted_2$x, [
@@ -17202,7 +17227,11 @@ const _sfc_main$O = /* @__PURE__ */ defineComponent({
17202
17227
  class: "lupa-facet-term lupa-show-more-facet-results",
17203
17228
  "data-cy": "lupa-facet-term",
17204
17229
  onClick: handleShowAll
17205
- }, toDisplayString(_ctx.options.labels.showAll), 1)) : createCommentVNode("", true)
17230
+ }, toDisplayString(_ctx.options.labels.showAll), 1)) : showAll.value ? (openBlock(), createElementBlock("div", {
17231
+ key: 2,
17232
+ class: "lupa-facet-term lupa-show-more-facet-results",
17233
+ onClick: handleCancelShowAll
17234
+ }, toDisplayString(_ctx.options.labels.showLess), 1)) : createCommentVNode("", true)
17206
17235
  ]);
17207
17236
  };
17208
17237
  }
@@ -19393,7 +19422,6 @@ const _sfc_main$i = /* @__PURE__ */ defineComponent({
19393
19422
  watch(
19394
19423
  () => props.query,
19395
19424
  () => {
19396
- console.log("query changed", props.query);
19397
19425
  searchForRelatedQuery();
19398
19426
  }
19399
19427
  );
@@ -26602,6 +26630,7 @@ const _sfc_main$a = /* @__PURE__ */ defineComponent({
26602
26630
  return;
26603
26631
  }
26604
26632
  recommendations.value = result2.recommended;
26633
+ loading.value = false;
26605
26634
  yield dynamicDataStore.enhanceSearchResultsWithDynamicData({
26606
26635
  result: { items: result2.recommended }
26607
26636
  });
@@ -53,13 +53,19 @@ export declare const useSearchBoxStore: import("pinia").StoreDefinition<"searchB
53
53
  publicQuery: PublicQuery;
54
54
  options?: SdkOptions;
55
55
  }) => Promise<{
56
+ suggestions: any;
57
+ queryKey?: undefined;
58
+ result?: undefined;
59
+ } | {
56
60
  queryKey: string;
57
61
  result: {
58
62
  items: any[];
59
63
  };
64
+ suggestions?: undefined;
60
65
  } | {
61
66
  queryKey: string;
62
67
  result: SearchQueryResult;
68
+ suggestions?: undefined;
63
69
  }>;
64
70
  highlightChange: ({ action }: {
65
71
  action: 'down' | 'up' | 'clear';
@@ -123,13 +129,19 @@ export declare const useSearchBoxStore: import("pinia").StoreDefinition<"searchB
123
129
  publicQuery: PublicQuery;
124
130
  options?: SdkOptions;
125
131
  }) => Promise<{
132
+ suggestions: any;
133
+ queryKey?: undefined;
134
+ result?: undefined;
135
+ } | {
126
136
  queryKey: string;
127
137
  result: {
128
138
  items: any[];
129
139
  };
140
+ suggestions?: undefined;
130
141
  } | {
131
142
  queryKey: string;
132
143
  result: SearchQueryResult;
144
+ suggestions?: undefined;
133
145
  }>;
134
146
  highlightChange: ({ action }: {
135
147
  action: 'down' | 'up' | 'clear';
@@ -193,13 +205,19 @@ export declare const useSearchBoxStore: import("pinia").StoreDefinition<"searchB
193
205
  publicQuery: PublicQuery;
194
206
  options?: SdkOptions;
195
207
  }) => Promise<{
208
+ suggestions: any;
209
+ queryKey?: undefined;
210
+ result?: undefined;
211
+ } | {
196
212
  queryKey: string;
197
213
  result: {
198
214
  items: any[];
199
215
  };
216
+ suggestions?: undefined;
200
217
  } | {
201
218
  queryKey: string;
202
219
  result: SearchQueryResult;
220
+ suggestions?: undefined;
203
221
  }>;
204
222
  highlightChange: ({ action }: {
205
223
  action: 'down' | 'up' | 'clear';
@@ -7,6 +7,7 @@ export type HierarchyFacetAction = {
7
7
  type: 'hierarchy';
8
8
  value: string;
9
9
  key: string;
10
+ behavior?: 'append' | 'replace';
10
11
  };
11
12
  export type RangeFacetAction = {
12
13
  type: 'range';
@@ -189,11 +189,13 @@ export type ResultFacetOptions = {
189
189
  maxInitialLevel: number;
190
190
  topLevelValueCountLimit?: number;
191
191
  filterable?: boolean;
192
+ behavior?: 'append' | 'replace';
192
193
  };
193
194
  stats?: {
194
195
  slider?: boolean;
195
196
  inputs?: boolean;
196
197
  interval?: number;
198
+ pricePrecisionDigits?: number;
197
199
  labels?: {
198
200
  from?: string;
199
201
  to?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@getlupa/vue",
3
- "version": "0.14.16",
3
+ "version": "0.15.0",
4
4
  "main": "dist/lupaSearch.mjs",
5
5
  "module": "dist/lupaSearch.mjs",
6
6
  "types": "dist/src/index.d.ts",