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

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.
@@ -4430,7 +4430,7 @@ ${selectedOption === item ? "sledge__product-variant-size-swatch-active" : ""} s
4430
4430
  ] });
4431
4431
  };
4432
4432
  const ProductCard = React__default.memo((props) => {
4433
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o;
4433
+ var _a, _b, _c, _d, _e, _f, _g, _h;
4434
4434
  const {
4435
4435
  item,
4436
4436
  handleAddToCart,
@@ -4477,8 +4477,6 @@ const ProductCard = React__default.memo((props) => {
4477
4477
  sku = ""
4478
4478
  } = (variants == null ? void 0 : variants.length) ? variants[0] : {};
4479
4479
  const productUrl = `${url}?variant=${(_a = variants == null ? void 0 : variants[0]) == null ? void 0 : _a.id}`;
4480
- const searchParams = new URLSearchParams(document.location.search);
4481
- const searchParamsObject = Object.fromEntries(searchParams);
4482
4480
  const defaultSelectedVariantId = variant_admin_graphql_api_id ? variant_admin_graphql_api_id : "";
4483
4481
  const defaultSelectedVariantStock = (variants == null ? void 0 : variants.length) && Object.hasOwn(variants[0], "inventory_quantity") ? variants[0].inventory_quantity : 0;
4484
4482
  const defaultSelectedVariantInventoryManagement = (variants == null ? void 0 : variants.length) && Object.hasOwn(variants[0], "inventory_management") ? variants[0].inventory_management : null;
@@ -4506,14 +4504,6 @@ const ProductCard = React__default.memo((props) => {
4506
4504
  const { money_format } = generalDataSettings || {};
4507
4505
  const { forLoopIndex, forLoopIndexWithPage } = additionalCardProps || {};
4508
4506
  let component = null;
4509
- const isSplitProducts = Boolean((_b = instantSearchSettings == null ? void 0 : instantSearchSettings.split_products) == null ? void 0 : _b.enable);
4510
- const bySplitProducts = (_c = instantSearchSettings == null ? void 0 : instantSearchSettings.split_products) == null ? void 0 : _c.by;
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)) : [];
4512
- const hasOptionsFiltered = (optionsFiltered == null ? void 0 : optionsFiltered.length) ? !((_h = optionsFiltered == null ? void 0 : optionsFiltered.includes) == null ? void 0 : _h.call(optionsFiltered, optionSelectedValue)) : false;
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)) {
4515
- return /* @__PURE__ */ jsxRuntimeExports.jsx(React__default.Fragment, { children: component }, id);
4516
- }
4517
4507
  if (CardsComponent) {
4518
4508
  const CardsProps = {
4519
4509
  product: {
@@ -4531,8 +4521,8 @@ const ProductCard = React__default.memo((props) => {
4531
4521
  },
4532
4522
  ...dataReviews && Object.keys(dataReviews).length ? {
4533
4523
  review: {
4534
- total: ((_i = dataReviews == null ? void 0 : dataReviews[id]) == null ? void 0 : _i.review_count) ? dataReviews == null ? void 0 : dataReviews[id].review_count : 0,
4535
- average: ((_k = (_j = dataReviews == null ? void 0 : dataReviews[id]) == null ? void 0 : _j.rating) == null ? void 0 : _k.average) ? dataReviews == null ? void 0 : dataReviews[id].rating.average : 0
4524
+ total: ((_b = dataReviews == null ? void 0 : dataReviews[id]) == null ? void 0 : _b.review_count) ? dataReviews == null ? void 0 : dataReviews[id].review_count : 0,
4525
+ average: ((_d = (_c = dataReviews == null ? void 0 : dataReviews[id]) == null ? void 0 : _c.rating) == null ? void 0 : _d.average) ? dataReviews == null ? void 0 : dataReviews[id].rating.average : 0
4536
4526
  }
4537
4527
  } : {}
4538
4528
  },
@@ -4713,7 +4703,7 @@ const ProductCard = React__default.memo((props) => {
4713
4703
  onAfterAddWishlist,
4714
4704
  onAfterRemoveWishlist,
4715
4705
  wishlistChecked: dataWishlists == null ? void 0 : dataWishlists[id],
4716
- ...objectPresent(previewSettings) && ((_m = (_l = previewSettings == null ? void 0 : previewSettings.settings) == null ? void 0 : _l.general) == null ? void 0 : _m.use_dummy_data) ? {
4706
+ ...objectPresent(previewSettings) && ((_f = (_e = previewSettings == null ? void 0 : previewSettings.settings) == null ? void 0 : _e.general) == null ? void 0 : _f.use_dummy_data) ? {
4717
4707
  previewSettings
4718
4708
  } : {}
4719
4709
  }
@@ -4749,7 +4739,7 @@ const ProductCard = React__default.memo((props) => {
4749
4739
  }
4750
4740
  )
4751
4741
  ] }),
4752
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge__product-grid-card-variant-images", children: (_o = (_n = product == null ? void 0 : product.images) == null ? void 0 : _n.map) == null ? void 0 : _o.call(_n, (image2) => /* @__PURE__ */ jsxRuntimeExports.jsx(
4742
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge__product-grid-card-variant-images", children: (_h = (_g = product == null ? void 0 : product.images) == null ? void 0 : _g.map) == null ? void 0 : _h.call(_g, (image2) => /* @__PURE__ */ jsxRuntimeExports.jsx(
4753
4743
  "img",
4754
4744
  {
4755
4745
  decoding: "async",
@@ -4993,10 +4983,9 @@ const ProductGrid = React__default.memo((props) => {
4993
4983
  "data-custom-card": Boolean(props == null ? void 0 : props.cards),
4994
4984
  "data-flyout": isFlyout,
4995
4985
  children: data == null ? void 0 : data.map((item, index) => {
4996
- var _a, _b, _c, _d, _e;
4986
+ var _a, _b, _c;
4997
4987
  const isSplitProducts = Boolean((_a = instantSearchSettings == null ? void 0 : instantSearchSettings.split_products) == null ? void 0 : _a.enable);
4998
- const optionFirst = isSplitProducts && ((_b = instantSearchSettings == null ? void 0 : instantSearchSettings.split_products) == null ? void 0 : _b.by) ? (_e = (_c = item == null ? void 0 : item.product) == null ? void 0 : _c.options) == null ? void 0 : _e[(_d = instantSearchSettings == null ? void 0 : instantSearchSettings.split_products) == null ? void 0 : _d.by] : [];
4999
- const optionFirstValues = (optionFirst == null ? void 0 : optionFirst.length) ? optionFirst : [];
4988
+ const bySplitProducts = (_b = instantSearchSettings == null ? void 0 : instantSearchSettings.split_products) == null ? void 0 : _b.by;
5000
4989
  const productCardProps = {
5001
4990
  item,
5002
4991
  handleAddToCart,
@@ -5007,9 +4996,12 @@ const ProductGrid = React__default.memo((props) => {
5007
4996
  forLoopIndexWithPage: Number(currentPage) && Number(hitsPerPage) ? index + (Number(currentPage) - 1) * Number(hitsPerPage) : index
5008
4997
  },
5009
4998
  instantSearchSettings,
4999
+ ...isSplitProducts && bySplitProducts ? {
5000
+ optionSelectedValue: (_c = item == null ? void 0 : item.product) == null ? void 0 : _c.optionSelectedValue
5001
+ } : {},
5010
5002
  ...props
5011
5003
  };
5012
- return /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: isSplitProducts && (optionFirstValues == null ? void 0 : optionFirstValues.length) ? optionFirstValues.map((optionFirstValue, indexFirstValue) => /* @__PURE__ */ jsxRuntimeExports.jsx(ProductCard, { optionSelectedValue: optionFirstValue, ...productCardProps }, `sledge-product-card_${index}_${indexFirstValue}`)) : /* @__PURE__ */ jsxRuntimeExports.jsx(ProductCard, { ...productCardProps }, `sledge-product-card_${index}`) });
5004
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(ProductCard, { ...productCardProps }, `sledge-product-card_${index}`);
5013
5005
  })
5014
5006
  }
5015
5007
  );
@@ -10361,7 +10353,7 @@ const ResultProduct = React__default.memo((props) => {
10361
10353
  return dataClickedFacets2;
10362
10354
  };
10363
10355
  const handleSearchResultData = async (props2) => {
10364
- var _a2, _b2;
10356
+ var _a2, _b2, _c2, _d2;
10365
10357
  const { isLoadMore: isLoadMore2 = false, result: resultProp, onSearch } = props2;
10366
10358
  const INSTANT_SEARCH_SETTING = JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || null);
10367
10359
  const { index_product } = INSTANT_SEARCH_SETTING || {};
@@ -10371,18 +10363,54 @@ const ResultProduct = React__default.memo((props) => {
10371
10363
  const result = layoutType === "default" && isFirstTimeOrOnSearch ? (_b2 = resultData == null ? void 0 : resultData.find) == null ? void 0 : _b2.call(resultData, ({ indexUid }) => indexUid.includes(index_product)) : resultData;
10372
10364
  if (!result)
10373
10365
  return;
10374
- const { hits, hitsPerPage, processingTimeMs, totalHits, totalPages, facetDistribution } = result;
10366
+ const { hits: hitsResult, hitsPerPage, processingTimeMs, totalHits, totalPages, facetDistribution, query: queryResult } = result;
10367
+ const isSplitProducts = Boolean((_c2 = instantSearchSettings == null ? void 0 : instantSearchSettings.split_products) == null ? void 0 : _c2.enable);
10368
+ const bySplitProducts = (_d2 = instantSearchSettings == null ? void 0 : instantSearchSettings.split_products) == null ? void 0 : _d2.by;
10369
+ const searchParams2 = new URLSearchParams(document.location.search);
10370
+ const searchParamsObject = Object.fromEntries(searchParams2);
10371
+ let hits = hitsResult;
10372
+ if (isSplitProducts && bySplitProducts && (hits == null ? void 0 : hits.length)) {
10373
+ let newHits = [];
10374
+ hits.map((item) => {
10375
+ var _a3;
10376
+ const optionFirst = isSplitProducts && bySplitProducts ? (_a3 = item == null ? void 0 : item.options) == null ? void 0 : _a3[bySplitProducts] : [];
10377
+ const optionFirstValues = (optionFirst == null ? void 0 : optionFirst.length) ? optionFirst : [];
10378
+ if (isSplitProducts && (optionFirstValues == null ? void 0 : optionFirstValues.length)) {
10379
+ optionFirstValues.map((optionFirstValue, indexFirstValue) => {
10380
+ newHits.push({
10381
+ ...item,
10382
+ optionSelectedValue: optionFirstValue
10383
+ });
10384
+ });
10385
+ } else {
10386
+ newHits.push(item);
10387
+ }
10388
+ });
10389
+ if (newHits == null ? void 0 : newHits.length) {
10390
+ hits = newHits.filter((item) => {
10391
+ var _a3, _b3, _c3, _d3, _e2;
10392
+ const { optionSelectedValue } = item || {};
10393
+ const optionsFiltered = bySplitProducts ? (_d3 = (_c3 = (_b3 = (_a3 = searchParamsObject == null ? void 0 : searchParamsObject[`options.${bySplitProducts}`]) == null ? void 0 : _a3.split) == null ? void 0 : _b3.call(_a3, ",")) == null ? void 0 : _c3.map) == null ? void 0 : _d3.call(_c3, (item2) => decodeURIComponent(item2)) : [];
10394
+ const hasOptionsFiltered = optionsFiltered && (optionsFiltered == null ? void 0 : optionsFiltered.length) ? !((_e2 = optionsFiltered == null ? void 0 : optionsFiltered.includes) == null ? void 0 : _e2.call(optionsFiltered, optionSelectedValue)) : false;
10395
+ const isOptionNotContainsKeyword = (queryResult == null ? void 0 : queryResult.length) ? !(optionSelectedValue == null ? void 0 : optionSelectedValue.length) ? true : !optionSelectedValue.toLowerCase().includes(queryResult.toLowerCase()) : false;
10396
+ if (isSplitProducts && (hasOptionsFiltered || isOptionNotContainsKeyword)) {
10397
+ return false;
10398
+ }
10399
+ return true;
10400
+ });
10401
+ }
10402
+ }
10375
10403
  const updateTabs = () => {
10376
10404
  const valueAllowedTabs = objectPresent(previewSettings) ? tabs : allowedTabs;
10377
10405
  if (valueAllowedTabs == null ? void 0 : valueAllowedTabs.length) {
10378
10406
  setAllowedTabs == null ? void 0 : setAllowedTabs(
10379
10407
  valueAllowedTabs.map((tab) => {
10380
- var _a3, _b3, _c2;
10408
+ var _a3, _b3, _c3;
10381
10409
  const { index, total } = tab;
10382
10410
  let isCurrentIndex = index.includes(clickedTabIndexId);
10383
10411
  let tabTotal = isCurrentIndex ? totalHits : total;
10384
10412
  if (layoutType === "default" && ((_a3 = resultProp == null ? void 0 : resultProp.results) == null ? void 0 : _a3.length)) {
10385
- const { totalHits: totalHits2 } = (_c2 = (_b3 = resultProp == null ? void 0 : resultProp.results) == null ? void 0 : _b3.find) == null ? void 0 : _c2.call(_b3, ({ indexUid }) => indexUid.includes(index));
10413
+ const { totalHits: totalHits2 } = (_c3 = (_b3 = resultProp == null ? void 0 : resultProp.results) == null ? void 0 : _b3.find) == null ? void 0 : _c3.call(_b3, ({ indexUid }) => indexUid.includes(index));
10386
10414
  tabTotal = totalHits2 || tabTotal;
10387
10415
  }
10388
10416
  return {