@sledge-app/react-instant-search 2.0.23 → 2.0.25

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.
@@ -6114,6 +6114,36 @@ const SearchIconWidgetPopup = () => {
6114
6114
  ] })
6115
6115
  ] }) });
6116
6116
  };
6117
+ const hasDuplicateValue = (array, targetValue) => {
6118
+ let foundCount = 0;
6119
+ if (!(array == null ? void 0 : array.length))
6120
+ return false;
6121
+ for (let i = 0; i < array.length; i++) {
6122
+ if (array[i].value === targetValue) {
6123
+ foundCount++;
6124
+ if (foundCount > 1)
6125
+ return true;
6126
+ }
6127
+ }
6128
+ return false;
6129
+ };
6130
+ const filterCustomGrouping = (arr) => {
6131
+ if (!(arr == null ? void 0 : arr.length))
6132
+ return [];
6133
+ const groupMap = /* @__PURE__ */ new Map();
6134
+ arr.forEach((arrItem) => {
6135
+ const key = `${arrItem.index}-${arrItem.query_filter}`;
6136
+ if (!groupMap.has(key)) {
6137
+ groupMap.set(key, {
6138
+ query_filter: arrItem.query_filter,
6139
+ index: arrItem.index,
6140
+ items: []
6141
+ });
6142
+ }
6143
+ groupMap.get(key).items.push(arrItem.item);
6144
+ });
6145
+ return Array.from(groupMap.values());
6146
+ };
6117
6147
  const sortFacets = ({ facets, sortingOrder }) => {
6118
6148
  if (!(facets == null ? void 0 : facets.length) || !(sortingOrder == null ? void 0 : sortingOrder.length))
6119
6149
  return facets;
@@ -6214,7 +6244,7 @@ const createQueryFilter = ({
6214
6244
  hierarchicalFacetAliases,
6215
6245
  defaultFilterItems
6216
6246
  }) => {
6217
- var _a, _b, _c, _d, _e, _f, _g, _h;
6247
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
6218
6248
  let filters = additional == null ? void 0 : additional.filter((item) => item);
6219
6249
  let detectClickedFacets = detectQueryStringFilter({
6220
6250
  facets,
@@ -6228,6 +6258,7 @@ const createQueryFilter = ({
6228
6258
  hierarchicalFacetAliases
6229
6259
  });
6230
6260
  const facetEntries = Object.entries(detectClickedFacets) || [];
6261
+ let filterCustomByObject = [];
6231
6262
  for (const facetEntry of facetEntries) {
6232
6263
  const detectClickedFacet = facetEntry;
6233
6264
  if (!((detectClickedFacet == null ? void 0 : detectClickedFacet.length) && detectClickedFacet[1].length))
@@ -6235,7 +6266,26 @@ const createQueryFilter = ({
6235
6266
  let isCustom = ["variants.inventory_quantity"].includes(detectClickedFacet[0]);
6236
6267
  let isRange = allowedFilterSlider == null ? void 0 : allowedFilterSlider.includes(detectClickedFacet[0]);
6237
6268
  let isHierarchical = hierarchicalFacetAliases == null ? void 0 : hierarchicalFacetAliases.includes(detectClickedFacet[0]);
6238
- let filterSettings = (_a = defaultFilterItems == null ? void 0 : defaultFilterItems.find(({ value }) => value === detectClickedFacet[0])) == null ? void 0 : _a.settings;
6269
+ let isHasDuplicate = hasDuplicateValue(defaultFilterItems, detectClickedFacet[0]);
6270
+ if (isHasDuplicate && !isHierarchical) {
6271
+ let filterCustom = [];
6272
+ (_a = detectClickedFacet == null ? void 0 : detectClickedFacet[1]) == null ? void 0 : _a.map((item) => {
6273
+ const defaultFilterItemsObject = defaultFilterItems == null ? void 0 : defaultFilterItems.find(({ items }) => items == null ? void 0 : items.includes(item));
6274
+ const { index: defaultFilterItemsIndex, settings: defaultFilterItemsSettings } = defaultFilterItemsObject || {};
6275
+ const { query_filter: query_filter2 } = defaultFilterItemsSettings || {};
6276
+ filterCustom.push({
6277
+ query_filter: query_filter2,
6278
+ index: defaultFilterItemsIndex,
6279
+ item
6280
+ });
6281
+ });
6282
+ filterCustomByObject.push({
6283
+ value: detectClickedFacet[0],
6284
+ filters: filterCustomGrouping(filterCustom)
6285
+ });
6286
+ continue;
6287
+ }
6288
+ let filterSettings = (_b = defaultFilterItems == null ? void 0 : defaultFilterItems.find(({ value }) => value === detectClickedFacet[0])) == null ? void 0 : _b.settings;
6239
6289
  const { query_filter } = filterSettings || {};
6240
6290
  if (isHierarchical) {
6241
6291
  let arrItemHierarchicals = [];
@@ -6256,15 +6306,15 @@ const createQueryFilter = ({
6256
6306
  } else {
6257
6307
  let filterItem = "";
6258
6308
  if (query_filter === "AND") {
6259
- filterItem = ((_b = detectClickedFacet == null ? void 0 : detectClickedFacet[1]) == null ? void 0 : _b.length) ? (_f = (_e = (_d = (_c = detectClickedFacet == null ? void 0 : detectClickedFacet[1]) == null ? void 0 : _c.map) == null ? void 0 : _d.call(_c, (item) => `'${detectClickedFacet[0]}' = ${JSON.stringify(item)}`)) == null ? void 0 : _e.join) == null ? void 0 : _f.call(_e, " AND ") : "";
6309
+ filterItem = ((_c = detectClickedFacet == null ? void 0 : detectClickedFacet[1]) == null ? void 0 : _c.length) ? (_g = (_f = (_e = (_d = detectClickedFacet == null ? void 0 : detectClickedFacet[1]) == null ? void 0 : _d.map) == null ? void 0 : _e.call(_d, (item) => `'${detectClickedFacet[0]}' = ${JSON.stringify(item)}`)) == null ? void 0 : _f.join) == null ? void 0 : _g.call(_f, " AND ") : "";
6260
6310
  } else {
6261
6311
  filterItem = `'${detectClickedFacet[0]}' IN ${JSON.stringify(detectClickedFacet[1])}`;
6262
6312
  }
6263
6313
  if (isRange)
6264
6314
  filterItem = `'${detectClickedFacet[0]}' >= ${detectClickedFacet[1][0]} AND '${detectClickedFacet[0]}' <= ${detectClickedFacet[1][1]}`;
6265
6315
  if (isCustom) {
6266
- if (Array.isArray(detectClickedFacet[1]) && ((_g = detectClickedFacet[1]) == null ? void 0 : _g.length) > 1) {
6267
- filterItem = `(${(_h = detectClickedFacet[1]) == null ? void 0 : _h.map((item) => {
6316
+ if (Array.isArray(detectClickedFacet[1]) && ((_h = detectClickedFacet[1]) == null ? void 0 : _h.length) > 1) {
6317
+ filterItem = `(${(_i = detectClickedFacet[1]) == null ? void 0 : _i.map((item) => {
6268
6318
  return `'${detectClickedFacet[0]}' ${item}`;
6269
6319
  }).join(" OR ")})`;
6270
6320
  } else {
@@ -6274,7 +6324,25 @@ const createQueryFilter = ({
6274
6324
  filters.push(filterItem);
6275
6325
  }
6276
6326
  }
6277
- return [...new Set(filters.concat(DEFAULT_QUERY_PRODUCT_MEILISEARCH))].join(" AND ");
6327
+ let filterCustomByObjectString = (_l = (_k = (_j = filterCustomByObject == null ? void 0 : filterCustomByObject.map) == null ? void 0 : _j.call(filterCustomByObject, ({ value, filters: filters2 }) => {
6328
+ var _a2, _b2;
6329
+ let filterCustomString = [];
6330
+ (_a2 = filters2 == null ? void 0 : filters2.map) == null ? void 0 : _a2.call(filters2, ({ query_filter, items }) => {
6331
+ var _a3, _b3;
6332
+ if (!(items == null ? void 0 : items.length))
6333
+ return;
6334
+ if (query_filter === "AND") {
6335
+ filterCustomString.push((_b3 = (_a3 = items.map((item) => `'${value}' = ${JSON.stringify(item)}`)) == null ? void 0 : _a3.join) == null ? void 0 : _b3.call(_a3, " AND "));
6336
+ } else {
6337
+ filterCustomString.push(`'${value}' IN ${JSON.stringify(items)}`);
6338
+ }
6339
+ });
6340
+ return (_b2 = filterCustomString == null ? void 0 : filterCustomString.join) == null ? void 0 : _b2.call(filterCustomString, " AND ");
6341
+ })) == null ? void 0 : _k.filter) == null ? void 0 : _l.call(_k, (item) => item);
6342
+ let filtersConcat = filters.concat(DEFAULT_QUERY_PRODUCT_MEILISEARCH);
6343
+ if (filterCustomByObjectString == null ? void 0 : filterCustomByObjectString.length)
6344
+ filtersConcat = filtersConcat.concat(DEFAULT_QUERY_PRODUCT_MEILISEARCH, filterCustomByObjectString);
6345
+ return [...new Set(filtersConcat)].join(" AND ");
6278
6346
  };
6279
6347
  const createHierarchicalFacet = ({
6280
6348
  indexValue,
@@ -6812,11 +6880,13 @@ const FacetBlockSelected = React__default.memo(
6812
6880
  isSalePercent = true;
6813
6881
  }
6814
6882
  if (defaultFilterItems == null ? void 0 : defaultFilterItems.length) {
6883
+ let isSetValue = false;
6815
6884
  defaultFilterItems.map((defaultFilterItem) => {
6816
6885
  const { label: defaultFilterItemLabel, items, settings: defaultFilterItemSettings } = defaultFilterItem;
6817
- if (items == null ? void 0 : items.includes(value)) {
6886
+ if ((items == null ? void 0 : items.includes(value)) && !isSetValue) {
6818
6887
  getLabel = defaultFilterItemLabel;
6819
6888
  getSettings = defaultFilterItemSettings;
6889
+ isSetValue = true;
6820
6890
  }
6821
6891
  });
6822
6892
  }
@@ -8628,7 +8698,7 @@ const DesktopLayout = (props) => {
8628
8698
  );
8629
8699
  };
8630
8700
  const FilterFlyoutLayout = (props) => {
8631
- var _a, _b, _c;
8701
+ var _a, _b, _c, _d;
8632
8702
  const {
8633
8703
  displaySettings,
8634
8704
  languageSettings,
@@ -8686,17 +8756,17 @@ const FilterFlyoutLayout = (props) => {
8686
8756
  selectOptionSkeletonComponent
8687
8757
  ] }) : /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
8688
8758
  /* @__PURE__ */ jsxRuntimeExports.jsx(SummaryTextHorizontal, { children: summaryText }),
8689
- /* @__PURE__ */ jsxRuntimeExports.jsx(ColumnGridSelectorWrapper, { children: columnGridSelector }),
8759
+ ((_b = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _b.show_switch_view_option) ? /* @__PURE__ */ jsxRuntimeExports.jsx(ColumnGridSelectorWrapper, { children: columnGridSelector }) : null,
8690
8760
  /* @__PURE__ */ jsxRuntimeExports.jsx(FilterHorizontalBlockMobile, { children: /* @__PURE__ */ jsxRuntimeExports.jsxs(ResultSearchFieldFlex, { children: [
8691
8761
  /* @__PURE__ */ jsxRuntimeExports.jsxs(Button, { type: "button", className: "sledge-instant-search__trigger-filter-flyout", onClick: () => setOpenFilterFlyout == null ? void 0 : setOpenFilterFlyout(true), children: [
8692
8762
  /* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: language_filter || "Filter" }),
8693
8763
  /* @__PURE__ */ jsxRuntimeExports.jsx(FilterIcon, { width: 18, height: 18, color: "#393d4e" })
8694
8764
  ] }),
8695
- ((_b = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _b.hide_search_bar) ? null : searchField
8765
+ ((_c = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _c.hide_search_bar) ? null : searchField
8696
8766
  ] }) }),
8697
8767
  /* @__PURE__ */ jsxRuntimeExports.jsxs(SelectFieldWrapper, { children: [
8698
8768
  /* @__PURE__ */ jsxRuntimeExports.jsx(SelectFieldItem, { children: sort }),
8699
- ((_c = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _c.hide_limit_options) ? null : /* @__PURE__ */ jsxRuntimeExports.jsx(SelectFieldItem, { children: limit })
8769
+ ((_d = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _d.hide_limit_options) ? null : /* @__PURE__ */ jsxRuntimeExports.jsx(SelectFieldItem, { children: limit })
8700
8770
  ] })
8701
8771
  ] }) }),
8702
8772
  isLoading ? /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: productGridSkeleton }) : /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: (searchResult == null ? void 0 : searchResult.length) ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
@@ -8707,7 +8777,7 @@ const FilterFlyoutLayout = (props) => {
8707
8777
  ] });
8708
8778
  };
8709
8779
  const FilterStandardLayout = (props) => {
8710
- var _a, _b, _c;
8780
+ var _a, _b, _c, _d;
8711
8781
  const { displaySettings, languageSettings, allowedFilter, isFirstLoading, isLoading, isLoadingProduct, isLoadingSetting, searchResult = [], components, skeleton } = props;
8712
8782
  const {
8713
8783
  filterHorizontal = null,
@@ -8737,14 +8807,14 @@ const FilterStandardLayout = (props) => {
8737
8807
  selectOptionSkeletonComponent
8738
8808
  ] }) : /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
8739
8809
  /* @__PURE__ */ jsxRuntimeExports.jsx(SummaryTextHorizontal, { children: summaryText }),
8740
- /* @__PURE__ */ jsxRuntimeExports.jsx(ColumnGridSelectorWrapper, { children: columnGridSelector }),
8810
+ ((_b = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _b.show_switch_view_option) ? /* @__PURE__ */ jsxRuntimeExports.jsx(ColumnGridSelectorWrapper, { children: columnGridSelector }) : null,
8741
8811
  /* @__PURE__ */ jsxRuntimeExports.jsxs(FilterHorizontalBlockMobile, { children: [
8742
- ((_b = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _b.hide_search_bar) ? null : searchField,
8812
+ ((_c = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _c.hide_search_bar) ? null : searchField,
8743
8813
  filterHorizontal == null ? void 0 : filterHorizontal({ deviceType: "mobile" })
8744
8814
  ] }),
8745
8815
  /* @__PURE__ */ jsxRuntimeExports.jsxs(SelectFieldWrapper, { children: [
8746
8816
  /* @__PURE__ */ jsxRuntimeExports.jsx(SelectFieldItem, { children: sort }),
8747
- ((_c = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _c.hide_limit_options) ? null : /* @__PURE__ */ jsxRuntimeExports.jsx(SelectFieldItem, { children: limit })
8817
+ ((_d = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _d.hide_limit_options) ? null : /* @__PURE__ */ jsxRuntimeExports.jsx(SelectFieldItem, { children: limit })
8748
8818
  ] })
8749
8819
  ] }) }),
8750
8820
  isLoading ? /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: productGridSkeleton }) : /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: (searchResult == null ? void 0 : searchResult.length) ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
@@ -8754,7 +8824,7 @@ const FilterStandardLayout = (props) => {
8754
8824
  ] }) }) });
8755
8825
  };
8756
8826
  const StickyFilterButtonLayout = (props) => {
8757
- var _a, _b, _c;
8827
+ var _a, _b, _c, _d;
8758
8828
  const {
8759
8829
  displaySettings,
8760
8830
  languageSettings,
@@ -8816,11 +8886,11 @@ const StickyFilterButtonLayout = (props) => {
8816
8886
  selectOptionSkeletonComponent
8817
8887
  ] }) : /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
8818
8888
  /* @__PURE__ */ jsxRuntimeExports.jsx(SummaryTextHorizontal, { children: summaryText }),
8819
- /* @__PURE__ */ jsxRuntimeExports.jsx(ColumnGridSelectorWrapper, { children: columnGridSelector }),
8820
- ((_b = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _b.hide_search_bar) ? null : /* @__PURE__ */ jsxRuntimeExports.jsx(FilterHorizontalBlockMobile, { children: searchField }),
8889
+ ((_b = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _b.show_switch_view_option) ? /* @__PURE__ */ jsxRuntimeExports.jsx(ColumnGridSelectorWrapper, { children: columnGridSelector }) : null,
8890
+ ((_c = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _c.hide_search_bar) ? null : /* @__PURE__ */ jsxRuntimeExports.jsx(FilterHorizontalBlockMobile, { children: searchField }),
8821
8891
  /* @__PURE__ */ jsxRuntimeExports.jsxs(SelectFieldWrapper, { children: [
8822
8892
  /* @__PURE__ */ jsxRuntimeExports.jsx(SelectFieldItem, { children: sort }),
8823
- ((_c = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _c.hide_limit_options) ? null : /* @__PURE__ */ jsxRuntimeExports.jsx(SelectFieldItem, { children: limit })
8893
+ ((_d = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _d.hide_limit_options) ? null : /* @__PURE__ */ jsxRuntimeExports.jsx(SelectFieldItem, { children: limit })
8824
8894
  ] })
8825
8895
  ] }) }),
8826
8896
  isLoading ? /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: productGridSkeleton }) : /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: (searchResult == null ? void 0 : searchResult.length) ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
@@ -9032,7 +9102,7 @@ const SearchResultWidget = (props) => {
9032
9102
  }
9033
9103
  }
9034
9104
  if (valueAllowedFilter == null ? void 0 : valueAllowedFilter.length) {
9035
- valueDefaultFilterItems = valueAllowedFilter.map((filter) => {
9105
+ valueDefaultFilterItems = valueAllowedFilter.map((filter, index) => {
9036
9106
  var _a3;
9037
9107
  const { value, label, display, settings: settings2 } = filter;
9038
9108
  const { prefix, filter_list, selected_filter } = settings2 || {};
@@ -9051,6 +9121,7 @@ const SearchResultWidget = (props) => {
9051
9121
  value,
9052
9122
  label,
9053
9123
  settings: settings2,
9124
+ index,
9054
9125
  items: (_a3 = items == null ? void 0 : items.map((item) => {
9055
9126
  const isManualFilter = item && filter_list === "manual" && !(selected_filter == null ? void 0 : selected_filter.includes(item == null ? void 0 : item.value));
9056
9127
  const isPrefixFilter = item && filter_list === "prefix" && !(prefix == null ? void 0 : prefix.find((prefixItem) => {