@sledge-app/react-instant-search 2.0.36 → 2.0.38

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.
@@ -4452,7 +4452,8 @@ const ProductCard = React__default.memo((props) => {
4452
4452
  isFlyout,
4453
4453
  instantSearchSettings,
4454
4454
  optionSelectedValue,
4455
- additionalCardProps
4455
+ additionalCardProps,
4456
+ keyword
4456
4457
  } = props;
4457
4458
  const {
4458
4459
  show_vendor = true,
@@ -4509,7 +4510,8 @@ const ProductCard = React__default.memo((props) => {
4509
4510
  const bySplitProducts = (_c = instantSearchSettings == null ? void 0 : instantSearchSettings.split_products) == null ? void 0 : _c.by;
4510
4511
  const optionsFiltered = bySplitProducts ? (_g = (_f = (_e = (_d = searchParamsObject == null ? void 0 : searchParamsObject[`options.${bySplitProducts}`]) == null ? void 0 : _d.split) == null ? void 0 : _e.call(_d, ",")) == null ? void 0 : _f.map) == null ? void 0 : _g.call(_f, (item2) => decodeURIComponent(item2)) : [];
4511
4512
  const hasOptionsFiltered = (optionsFiltered == null ? void 0 : optionsFiltered.length) ? !((_h = optionsFiltered == null ? void 0 : optionsFiltered.includes) == null ? void 0 : _h.call(optionsFiltered, optionSelectedValue)) : false;
4512
- if (isSplitProducts && hasOptionsFiltered) {
4513
+ const isOptionNotContainsKeyword = (keyword == null ? void 0 : keyword.length) ? !(optionSelectedValue == null ? void 0 : optionSelectedValue.length) ? true : !optionSelectedValue.toLowerCase().includes(keyword.toLowerCase()) : false;
4514
+ if (isSplitProducts && (hasOptionsFiltered || isOptionNotContainsKeyword)) {
4513
4515
  return /* @__PURE__ */ jsxRuntimeExports.jsx(React__default.Fragment, { children: component }, id);
4514
4516
  }
4515
4517
  if (CardsComponent) {
@@ -6344,10 +6346,10 @@ const detectQueryStringFilter = ({ facets, facetsQueryStringObject, callback })
6344
6346
  const searchParamsObject = Object.fromEntries(searchParams);
6345
6347
  for (const searchParamsKey in searchParamsObject) {
6346
6348
  let ifFacetsQueryStringObject = (facets == null ? void 0 : facets.length) && facets.includes(searchParamsKey);
6347
- if (ifFacetsQueryStringObject)
6349
+ if (ifFacetsQueryStringObject && typeof facetsQueryStringObject === "object")
6348
6350
  facetsQueryStringObject[searchParamsKey] = (_b = (_a = searchParamsObject[searchParamsKey].split(",")) == null ? void 0 : _a.map) == null ? void 0 : _b.call(_a, (item) => decodeURIComponent(item));
6349
6351
  }
6350
- if (Object.keys(facetsQueryStringObject).length)
6352
+ if (facetsQueryStringObject && Object.keys(facetsQueryStringObject).length)
6351
6353
  callback(facetsQueryStringObject);
6352
6354
  return facetsQueryStringObject;
6353
6355
  };
@@ -6364,19 +6366,21 @@ const detectArrFacetHierarchical = ({
6364
6366
  }
6365
6367
  return { ...item, [key]: defaultLevelHierarchical };
6366
6368
  }, {});
6367
- Object.entries(clickedFacetsObject).map((facet) => {
6368
- var _a, _b;
6369
- if ((facet == null ? void 0 : facet.length) && facet[1].length) {
6370
- const isCollection = (_a = String(facet[0])) == null ? void 0 : _a.includes(HIERARCHICAL_FACET_OBJECT_ALIASES.collections);
6371
- let isHierarchical = hierarchicalFacetAliases == null ? void 0 : hierarchicalFacetAliases.includes(facet[0]);
6372
- if (isHierarchical)
6373
- (_b = facet[1]) == null ? void 0 : _b.map((item) => {
6374
- const arrItem = String(item).split(isCollection ? separatorCollection : separator);
6375
- if ((arrItem == null ? void 0 : arrItem.length) && Object.hasOwn(facetHierarchical[facet[0]], `lvl${arrItem.length - 1}`))
6376
- facetHierarchical[facet[0]][`lvl${arrItem.length - 1}`].push(item);
6377
- });
6378
- }
6379
- });
6369
+ if (clickedFacetsObject && Object.keys(clickedFacetsObject).length) {
6370
+ Object.entries(clickedFacetsObject).map((facet) => {
6371
+ var _a, _b;
6372
+ if ((facet == null ? void 0 : facet.length) && facet[1].length) {
6373
+ const isCollection = (_a = String(facet[0])) == null ? void 0 : _a.includes(HIERARCHICAL_FACET_OBJECT_ALIASES.collections);
6374
+ let isHierarchical = hierarchicalFacetAliases == null ? void 0 : hierarchicalFacetAliases.includes(facet[0]);
6375
+ if (isHierarchical)
6376
+ (_b = facet[1]) == null ? void 0 : _b.map((item) => {
6377
+ const arrItem = String(item).split(isCollection ? separatorCollection : separator);
6378
+ if ((arrItem == null ? void 0 : arrItem.length) && Object.hasOwn(facetHierarchical[facet[0]], `lvl${arrItem.length - 1}`))
6379
+ facetHierarchical[facet[0]][`lvl${arrItem.length - 1}`].push(item);
6380
+ });
6381
+ }
6382
+ });
6383
+ }
6380
6384
  return facetHierarchical;
6381
6385
  };
6382
6386
  const createQueryFilter = ({
@@ -6403,7 +6407,7 @@ const createQueryFilter = ({
6403
6407
  separatorCollection,
6404
6408
  hierarchicalFacetAliases
6405
6409
  });
6406
- const facetEntries = Object.entries(detectClickedFacets) || [];
6410
+ const facetEntries = detectClickedFacets && Object.keys(detectClickedFacets).length ? Object.entries(detectClickedFacets) : [];
6407
6411
  let filterCustomByObject = [];
6408
6412
  for (const facetEntry of facetEntries) {
6409
6413
  const detectClickedFacet = facetEntry;
@@ -10356,14 +10360,14 @@ const ResultProduct = React__default.memo((props) => {
10356
10360
  });
10357
10361
  return dataClickedFacets2;
10358
10362
  };
10359
- const handleSearchResultData = (props2) => {
10363
+ const handleSearchResultData = async (props2) => {
10360
10364
  var _a2, _b2;
10361
10365
  const { isLoadMore: isLoadMore2 = false, result: resultProp, onSearch } = props2;
10362
10366
  const INSTANT_SEARCH_SETTING = JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || null);
10363
10367
  const { index_product } = INSTANT_SEARCH_SETTING || {};
10364
10368
  const isNoneFacetSelected = Boolean(!((_a2 = handleDataClickedFacets()) == null ? void 0 : _a2.length));
10365
10369
  const isFirstTimeOrOnSearch = handleSearchResultFirstTime && initStatesFirstTime || onSearch;
10366
- const resultData = layoutType === "default" && isFirstTimeOrOnSearch ? resultProp == null ? void 0 : resultProp.results : resultProp;
10370
+ let resultData = layoutType === "default" && isFirstTimeOrOnSearch ? resultProp == null ? void 0 : resultProp.results : resultProp;
10367
10371
  const result = layoutType === "default" && isFirstTimeOrOnSearch ? (_b2 = resultData == null ? void 0 : resultData.find) == null ? void 0 : _b2.call(resultData, ({ indexUid }) => indexUid.includes(index_product)) : resultData;
10368
10372
  if (!result)
10369
10373
  return;
@@ -10394,6 +10398,30 @@ const ResultProduct = React__default.memo((props) => {
10394
10398
  if (objectPresent(previewSettings))
10395
10399
  updateTabs();
10396
10400
  if (isFirstTimeOrOnSearch || isNoneFacetSelected) {
10401
+ if (handleSearchResultFirstTime && initStatesFirstTime && clickedFacets && Object.keys(clickedFacets).length) {
10402
+ const initData = await handleSearchResponse({
10403
+ layoutType,
10404
+ clickedTabIndexId,
10405
+ clickedTabIndexType,
10406
+ page: 0,
10407
+ limit: 0,
10408
+ isUseMultiSearch: handleSearchResultFirstTime && initStatesFirstTime || onSearch,
10409
+ facets,
10410
+ attributesToRetrieve,
10411
+ allowedFilterSlider,
10412
+ hierarchicalFacetAliases,
10413
+ defaultFilterItems,
10414
+ collectionId,
10415
+ hiddenTags,
10416
+ showOutOfStock,
10417
+ hierarchicalProductTypeSettings,
10418
+ hierarchicalCollectionsSettings,
10419
+ usePublishedFilter,
10420
+ tabs,
10421
+ instantSearchSettings
10422
+ });
10423
+ resultData = layoutType === "default" && isFirstTimeOrOnSearch ? initData == null ? void 0 : initData.results : initData;
10424
+ }
10397
10425
  handleSetInitStates == null ? void 0 : handleSetInitStates({
10398
10426
  results: resultData,
10399
10427
  data: INSTANT_SEARCH_SETTING,
@@ -10489,7 +10517,7 @@ const ResultProduct = React__default.memo((props) => {
10489
10517
  }
10490
10518
  setHandleSearchResultFirstTime(false);
10491
10519
  setInitStatesFirstTime == null ? void 0 : setInitStatesFirstTime(false);
10492
- handleSearchResultData({
10520
+ await handleSearchResultData({
10493
10521
  result: response,
10494
10522
  ...props2
10495
10523
  });
@@ -10855,7 +10883,8 @@ const ResultProduct = React__default.memo((props) => {
10855
10883
  previewSettings,
10856
10884
  instantSearchSettings,
10857
10885
  hitsPerPage: hitsPerPageResult,
10858
- currentPage
10886
+ currentPage,
10887
+ keyword
10859
10888
  }
10860
10889
  );
10861
10890
  const resultEmptyComponent = /* @__PURE__ */ jsxRuntimeExports.jsx(ResultEmpty, { ...props });