@sledge-app/react-instant-search 2.0.44 → 2.0.46

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.
@@ -4190,7 +4190,7 @@ const addToCartTrigger = async (data) => {
4190
4190
  });
4191
4191
  };
4192
4192
  const VariantSelector = (props) => {
4193
- var _a, _b, _c;
4193
+ var _a;
4194
4194
  const {
4195
4195
  data,
4196
4196
  setSelectedVariantId,
@@ -4201,7 +4201,6 @@ const VariantSelector = (props) => {
4201
4201
  setSelectedVariantCompareAtPrice,
4202
4202
  sourceApp,
4203
4203
  instantSearchSettings,
4204
- optionSelectedValue,
4205
4204
  hasEntryImage
4206
4205
  } = props;
4207
4206
  const { product } = data || {};
@@ -4209,24 +4208,6 @@ const VariantSelector = (props) => {
4209
4208
  const { id, handle, url } = product || {};
4210
4209
  const options = (product == null ? void 0 : product.options) ? Object.entries(product.options) : [];
4211
4210
  const images = (product == null ? void 0 : product.images) ?? [];
4212
- const isSplitProducts = Boolean((_a = instantSearchSettings == null ? void 0 : instantSearchSettings.split_products) == null ? void 0 : _a.enable);
4213
- const bySplitProducts = (_b = instantSearchSettings == null ? void 0 : instantSearchSettings.split_products) == null ? void 0 : _b.by;
4214
- React__default.useEffect(() => {
4215
- if (isSplitProducts && optionSelectedValue) {
4216
- const productCardElement = document.querySelector(`.sledge__product-grid-card[data-product-id="${id}"][data-option-selected-value="${encodeURIComponent(optionSelectedValue)}"]`);
4217
- if (productCardElement) {
4218
- const variantColorSwatch = productCardElement.querySelector(`.sledge__product-variant-color-swatch[data-option-value="${encodeURIComponent(optionSelectedValue)}"]`);
4219
- if (variantColorSwatch) {
4220
- variantColorSwatch.dispatchEvent(new Event("click", { bubbles: true }));
4221
- }
4222
- const variantSelectOption = productCardElement.querySelector(`.sledge__product-variant-size-swatch-select[data-option-name="${bySplitProducts}"]`);
4223
- if (variantSelectOption) {
4224
- variantSelectOption.value = optionSelectedValue;
4225
- variantSelectOption.dispatchEvent(new Event("change", { bubbles: true }));
4226
- }
4227
- }
4228
- }
4229
- }, [hasEntryImage]);
4230
4211
  const defaultSelected = {};
4231
4212
  function setDefaultFunction() {
4232
4213
  if (!(variants == null ? void 0 : variants.length))
@@ -4274,7 +4255,7 @@ const VariantSelector = (props) => {
4274
4255
  }
4275
4256
  }
4276
4257
  function setSelectedVariant(element, value, optionIndex) {
4277
- var _a2, _b2, _c2, _d, _e, _f, _g, _h, _i, _j, _k;
4258
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
4278
4259
  const parentCard = element.target.offsetParent;
4279
4260
  const selectedInput = parentCard.querySelector(`.sledge__product-grid-card-selected-option[data-product-id='${id}']`);
4280
4261
  setElementAttribute({
@@ -4282,8 +4263,8 @@ const VariantSelector = (props) => {
4282
4263
  attributeName: `data-selected-option${optionIndex}`,
4283
4264
  value
4284
4265
  });
4285
- const option1 = `[data-option-1="${stringToSlug((_b2 = (_a2 = selectedInput == null ? void 0 : selectedInput.attributes) == null ? void 0 : _a2["data-selected-option1"]) == null ? void 0 : _b2.value)}"]`;
4286
- const option2 = `${((_c2 = selectedInput == null ? void 0 : selectedInput.attributes) == null ? void 0 : _c2["data-selected-option2"]) ? `[data-option-2="${stringToSlug((_e = (_d = selectedInput == null ? void 0 : selectedInput.attributes) == null ? void 0 : _d["data-selected-option2"]) == null ? void 0 : _e.value)}"]` : ""}`;
4266
+ const option1 = `[data-option-1="${stringToSlug((_b = (_a2 = selectedInput == null ? void 0 : selectedInput.attributes) == null ? void 0 : _a2["data-selected-option1"]) == null ? void 0 : _b.value)}"]`;
4267
+ const option2 = `${((_c = selectedInput == null ? void 0 : selectedInput.attributes) == null ? void 0 : _c["data-selected-option2"]) ? `[data-option-2="${stringToSlug((_e = (_d = selectedInput == null ? void 0 : selectedInput.attributes) == null ? void 0 : _d["data-selected-option2"]) == null ? void 0 : _e.value)}"]` : ""}`;
4287
4268
  const selectOption = parentCard.querySelector(`select option${option1}${option2}`);
4288
4269
  const variantId = selectOption.attributes["data-graphql-id"].value;
4289
4270
  const imageId = (_f = selectOption.attributes["data-image-id"]) == null ? void 0 : _f.value;
@@ -4301,11 +4282,11 @@ const VariantSelector = (props) => {
4301
4282
  }
4302
4283
  });
4303
4284
  const setOther = () => {
4304
- var _a3, _b3;
4285
+ var _a3, _b2;
4305
4286
  setElementAttribute({
4306
4287
  element: selectedInput,
4307
4288
  attributeName: "data-variant-id",
4308
- value: ((_b3 = (_a3 = selectOption == null ? void 0 : selectOption.attributes) == null ? void 0 : _a3["data-graphql-id"]) == null ? void 0 : _b3.value) || ""
4289
+ value: ((_b2 = (_a3 = selectOption == null ? void 0 : selectOption.attributes) == null ? void 0 : _a3["data-graphql-id"]) == null ? void 0 : _b2.value) || ""
4309
4290
  });
4310
4291
  setElementAttribute({
4311
4292
  element: selectedInput,
@@ -4377,7 +4358,7 @@ const VariantSelector = (props) => {
4377
4358
  return /* @__PURE__ */ jsxRuntimeExports.jsx("option", { ...optionAttributes, children: title }, id2);
4378
4359
  }) }),
4379
4360
  /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge__product-grid-card-variant-images", children: images == null ? void 0 : images.map((image) => /* @__PURE__ */ jsxRuntimeExports.jsx("input", { type: "hidden", id: image == null ? void 0 : image.id, value: image == null ? void 0 : image.src }, image == null ? void 0 : image.id)) }),
4380
- (_c = options == null ? void 0 : options.map) == null ? void 0 : _c.call(options, (option, optionParentIndex) => {
4361
+ (_a = options == null ? void 0 : options.map) == null ? void 0 : _a.call(options, (option, optionParentIndex) => {
4381
4362
  var _a2;
4382
4363
  const optionName = option[0];
4383
4364
  const optionValues = option[1];
@@ -4453,7 +4434,7 @@ ${selectedOption === item ? "sledge__product-variant-size-swatch-active" : ""} s
4453
4434
  ] });
4454
4435
  };
4455
4436
  const ProductCard = React__default.memo((props) => {
4456
- var _a, _b, _c, _d, _e, _f, _g, _h;
4437
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k;
4457
4438
  const {
4458
4439
  item,
4459
4440
  handleAddToCart,
@@ -4474,7 +4455,6 @@ const ProductCard = React__default.memo((props) => {
4474
4455
  previewSettings,
4475
4456
  isFlyout,
4476
4457
  instantSearchSettings,
4477
- optionSelectedValue,
4478
4458
  additionalCardProps,
4479
4459
  keyword
4480
4460
  } = props;
@@ -4528,6 +4508,14 @@ const ProductCard = React__default.memo((props) => {
4528
4508
  sku = ""
4529
4509
  } = (variants == null ? void 0 : variants.length) ? variants[0] : {};
4530
4510
  const productUrl = `${url}?variant=${(_a = variants == null ? void 0 : variants[0]) == null ? void 0 : _a.id}`;
4511
+ const isSplitProducts = Boolean((_b = instantSearchSettings == null ? void 0 : instantSearchSettings.split_products) == null ? void 0 : _b.enable);
4512
+ const bySplitProducts = (_c = instantSearchSettings == null ? void 0 : instantSearchSettings.split_products) == null ? void 0 : _c.by;
4513
+ let optionSelectedValue = "";
4514
+ if (isSplitProducts && bySplitProducts) {
4515
+ const optionFirst = (_d = product == null ? void 0 : product.options) == null ? void 0 : _d[bySplitProducts];
4516
+ const optionFirstValue = (optionFirst == null ? void 0 : optionFirst.length) ? optionFirst == null ? void 0 : optionFirst[0] : "";
4517
+ optionSelectedValue = optionFirstValue;
4518
+ }
4531
4519
  const defaultSelectedVariantId = variant_admin_graphql_api_id ? variant_admin_graphql_api_id : "";
4532
4520
  const defaultSelectedVariantStock = (variants == null ? void 0 : variants.length) && Object.hasOwn(variants[0], "inventory_quantity") ? variants[0].inventory_quantity : 0;
4533
4521
  const defaultSelectedVariantInventoryManagement = (variants == null ? void 0 : variants.length) && Object.hasOwn(variants[0], "inventory_management") ? variants[0].inventory_management : null;
@@ -4572,8 +4560,8 @@ const ProductCard = React__default.memo((props) => {
4572
4560
  },
4573
4561
  ...dataReviews && Object.keys(dataReviews).length ? {
4574
4562
  review: {
4575
- total: ((_b = dataReviews == null ? void 0 : dataReviews[id]) == null ? void 0 : _b.review_count) ? dataReviews == null ? void 0 : dataReviews[id].review_count : 0,
4576
- 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
4563
+ total: ((_e = dataReviews == null ? void 0 : dataReviews[id]) == null ? void 0 : _e.review_count) ? dataReviews == null ? void 0 : dataReviews[id].review_count : 0,
4564
+ average: ((_g = (_f = dataReviews == null ? void 0 : dataReviews[id]) == null ? void 0 : _f.rating) == null ? void 0 : _g.average) ? dataReviews == null ? void 0 : dataReviews[id].rating.average : 0
4577
4565
  }
4578
4566
  } : {}
4579
4567
  },
@@ -4754,7 +4742,7 @@ const ProductCard = React__default.memo((props) => {
4754
4742
  onAfterAddWishlist,
4755
4743
  onAfterRemoveWishlist,
4756
4744
  wishlistChecked: dataWishlists == null ? void 0 : dataWishlists[id],
4757
- ...objectPresent(previewSettings) && ((_f = (_e = previewSettings == null ? void 0 : previewSettings.settings) == null ? void 0 : _e.general) == null ? void 0 : _f.use_dummy_data) ? {
4745
+ ...objectPresent(previewSettings) && ((_i = (_h = previewSettings == null ? void 0 : previewSettings.settings) == null ? void 0 : _h.general) == null ? void 0 : _i.use_dummy_data) ? {
4758
4746
  previewSettings
4759
4747
  } : {}
4760
4748
  }
@@ -4790,7 +4778,7 @@ const ProductCard = React__default.memo((props) => {
4790
4778
  }
4791
4779
  )
4792
4780
  ] }),
4793
- /* @__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(
4781
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge__product-grid-card-variant-images", children: (_k = (_j = product == null ? void 0 : product.images) == null ? void 0 : _j.map) == null ? void 0 : _k.call(_j, (image2) => /* @__PURE__ */ jsxRuntimeExports.jsx(
4794
4782
  "img",
4795
4783
  {
4796
4784
  decoding: "async",
@@ -5034,9 +5022,6 @@ const ProductGrid = React__default.memo((props) => {
5034
5022
  "data-custom-card": Boolean(props == null ? void 0 : props.cards),
5035
5023
  "data-flyout": isFlyout,
5036
5024
  children: data == null ? void 0 : data.map((item, index) => {
5037
- var _a, _b, _c;
5038
- const isSplitProducts = Boolean((_a = instantSearchSettings == null ? void 0 : instantSearchSettings.split_products) == null ? void 0 : _a.enable);
5039
- const bySplitProducts = (_b = instantSearchSettings == null ? void 0 : instantSearchSettings.split_products) == null ? void 0 : _b.by;
5040
5025
  const productCardProps = {
5041
5026
  item,
5042
5027
  handleAddToCart,
@@ -5047,9 +5032,6 @@ const ProductGrid = React__default.memo((props) => {
5047
5032
  forLoopIndexWithPage: Number(currentPage) && Number(hitsPerPage) ? index + (Number(currentPage) - 1) * Number(hitsPerPage) : index
5048
5033
  },
5049
5034
  instantSearchSettings,
5050
- ...isSplitProducts && bySplitProducts ? {
5051
- optionSelectedValue: (_c = item == null ? void 0 : item.product) == null ? void 0 : _c.optionSelectedValue
5052
- } : {},
5053
5035
  ...props
5054
5036
  };
5055
5037
  return /* @__PURE__ */ jsxRuntimeExports.jsx(ProductCard, { ...productCardProps }, `sledge-product-card_${index}`);
@@ -10422,7 +10404,7 @@ const ResultProduct = React__default.memo((props) => {
10422
10404
  return dataClickedFacets2;
10423
10405
  };
10424
10406
  const handleSearchResultData = async (props2) => {
10425
- var _a2, _b2, _c2, _d2;
10407
+ var _a2, _b2;
10426
10408
  const { isLoadMore: isLoadMore2 = false, result: resultProp, onSearch } = props2;
10427
10409
  const INSTANT_SEARCH_SETTING = JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || null);
10428
10410
  const { index_product } = INSTANT_SEARCH_SETTING || {};
@@ -10432,54 +10414,18 @@ const ResultProduct = React__default.memo((props) => {
10432
10414
  const result = layoutType === "default" && isFirstTimeOrOnSearch ? (_b2 = resultData == null ? void 0 : resultData.find) == null ? void 0 : _b2.call(resultData, ({ indexUid }) => indexUid.includes(index_product)) : resultData;
10433
10415
  if (!result)
10434
10416
  return;
10435
- const { hits: hitsResult, hitsPerPage, processingTimeMs, totalHits, totalPages, facetDistribution, query: queryResult } = result;
10436
- const isSplitProducts = Boolean((_c2 = instantSearchSettings == null ? void 0 : instantSearchSettings.split_products) == null ? void 0 : _c2.enable);
10437
- const bySplitProducts = (_d2 = instantSearchSettings == null ? void 0 : instantSearchSettings.split_products) == null ? void 0 : _d2.by;
10438
- const searchParams2 = new URLSearchParams(document.location.search);
10439
- const searchParamsObject = Object.fromEntries(searchParams2);
10440
- let hits = hitsResult;
10441
- if (isSplitProducts && bySplitProducts && (hits == null ? void 0 : hits.length)) {
10442
- let newHits = [];
10443
- hits.map((item) => {
10444
- var _a3;
10445
- const optionFirst = isSplitProducts && bySplitProducts ? (_a3 = item == null ? void 0 : item.options) == null ? void 0 : _a3[bySplitProducts] : [];
10446
- const optionFirstValues = (optionFirst == null ? void 0 : optionFirst.length) ? optionFirst : [];
10447
- if (isSplitProducts && (optionFirstValues == null ? void 0 : optionFirstValues.length)) {
10448
- optionFirstValues.map((optionFirstValue, indexFirstValue) => {
10449
- newHits.push({
10450
- ...item,
10451
- optionSelectedValue: optionFirstValue
10452
- });
10453
- });
10454
- } else {
10455
- newHits.push(item);
10456
- }
10457
- });
10458
- if (newHits == null ? void 0 : newHits.length) {
10459
- hits = newHits.filter((item) => {
10460
- var _a3, _b3, _c3, _d3, _e2;
10461
- const { optionSelectedValue } = item || {};
10462
- 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)) : [];
10463
- const hasOptionsFiltered = optionsFiltered && (optionsFiltered == null ? void 0 : optionsFiltered.length) ? !((_e2 = optionsFiltered == null ? void 0 : optionsFiltered.includes) == null ? void 0 : _e2.call(optionsFiltered, optionSelectedValue)) : false;
10464
- const isOptionNotContainsKeyword = (queryResult == null ? void 0 : queryResult.length) ? !(optionSelectedValue == null ? void 0 : optionSelectedValue.length) ? true : !optionSelectedValue.toLowerCase().includes(queryResult.toLowerCase()) : false;
10465
- if (isSplitProducts && (hasOptionsFiltered || isOptionNotContainsKeyword)) {
10466
- return false;
10467
- }
10468
- return true;
10469
- });
10470
- }
10471
- }
10417
+ const { hits, hitsPerPage, processingTimeMs, totalHits, totalPages, facetDistribution, query: queryResult } = result;
10472
10418
  const updateTabs = () => {
10473
10419
  const valueAllowedTabs = objectPresent(previewSettings) ? tabs : allowedTabs;
10474
10420
  if (valueAllowedTabs == null ? void 0 : valueAllowedTabs.length) {
10475
10421
  setAllowedTabs == null ? void 0 : setAllowedTabs(
10476
10422
  valueAllowedTabs.map((tab) => {
10477
- var _a3, _b3, _c3;
10423
+ var _a3, _b3, _c2;
10478
10424
  const { index, total } = tab;
10479
10425
  let isCurrentIndex = index.includes(clickedTabIndexId);
10480
10426
  let tabTotal = isCurrentIndex ? totalHits : total;
10481
10427
  if (layoutType === "default" && ((_a3 = resultProp == null ? void 0 : resultProp.results) == null ? void 0 : _a3.length)) {
10482
- 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));
10428
+ 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));
10483
10429
  tabTotal = totalHits2 || tabTotal;
10484
10430
  }
10485
10431
  return {
@@ -11478,9 +11424,20 @@ const SearchWidget = (props) => {
11478
11424
  handleSettings(localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || null);
11479
11425
  }, [previewSettings]);
11480
11426
  React__default.useEffect(() => {
11427
+ var _a2, _b2;
11481
11428
  if (!isRenderAppInstantSearch)
11482
11429
  return;
11483
11430
  handleSettings(localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || null);
11431
+ if (typeof window !== "undefined") {
11432
+ if ((_b2 = (_a2 = window == null ? void 0 : window.sledge) == null ? void 0 : _a2.instantSearch) == null ? void 0 : _b2.searchWidget)
11433
+ window.sledge.instantSearch.searchWidget.search = (keyword2 = "") => {
11434
+ var _a3, _b3;
11435
+ if (!(keyword2 == null ? void 0 : keyword2.length))
11436
+ return;
11437
+ setKeyword(keyword2);
11438
+ (_b3 = (_a3 = searchFieldRef == null ? void 0 : searchFieldRef.current) == null ? void 0 : _a3.focus) == null ? void 0 : _b3.call(_a3);
11439
+ };
11440
+ }
11484
11441
  }, [isRenderAppInstantSearch]);
11485
11442
  useEffectOnChange(() => {
11486
11443
  const INSTANT_SEARCH_SETTING = instantSearchPreviewSettings || JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || null);