@sledge-app/react-instant-search 1.0.47 → 1.0.49

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.
@@ -490,11 +490,16 @@ const Popover = ({
490
490
  );
491
491
  };
492
492
  const Progress$1 = "";
493
- const Progress = ({ value, total, fillColor = "", outlineColor = "" }) => {
493
+ const Progress = ({ value, total, fillColor = "", outlineColor = "", delay = 150 }) => {
494
494
  const [progress, setProgress] = React__default.useState(0);
495
495
  React__default.useEffect(() => {
496
- const timer = setTimeout(() => setProgress(+value / total * 100), 150);
497
- return () => clearTimeout(timer);
496
+ let valueProgress = +value / total * 100;
497
+ if (delay) {
498
+ const timer = setTimeout(() => setProgress(valueProgress), delay);
499
+ return () => clearTimeout(timer);
500
+ } else {
501
+ setProgress(valueProgress);
502
+ }
498
503
  }, []);
499
504
  return /* @__PURE__ */ jsxRuntimeExports.jsx(
500
505
  $67824d98245208a0$export$be92b6f5f03c0fe9,
@@ -1315,6 +1320,12 @@ const Trigger = (props) => {
1315
1320
  });
1316
1321
  const [isRequiredLogin, setIsRequiredLogin] = React__default.useState(false);
1317
1322
  const [isFirstTime, setIsFirstTime] = React__default.useState(true);
1323
+ const [hasEntry, setHasEntry] = React__default.useState(false);
1324
+ const [rootRef, rootEntry] = useIntersectionObserver({
1325
+ threshold: 0,
1326
+ root: null,
1327
+ rootMargin: "0px"
1328
+ });
1318
1329
  const { is_required_login } = ((_b = dataSettings == null ? void 0 : dataSettings.display) == null ? void 0 : _b.global) || {};
1319
1330
  const { show: show_notification, location: location_notification } = ((_c = dataSettings == null ? void 0 : dataSettings.display) == null ? void 0 : _c.notification) || {};
1320
1331
  const { title_added_to_wishlist, text_added_to_wishlist, title_removed_to_wishlist, text_removed_to_wishlist, title_fail_add_to_wishlist, text_fail_add_to_wishlist } = ((_d = dataSettings == null ? void 0 : dataSettings.languages) == null ? void 0 : _d.notification) || {};
@@ -1397,7 +1408,11 @@ const Trigger = (props) => {
1397
1408
  setIsLoading(false);
1398
1409
  };
1399
1410
  React__default.useEffect(() => {
1400
- if (!isRenderAppWishlist)
1411
+ if (!hasEntry && (rootEntry == null ? void 0 : rootEntry.isIntersecting))
1412
+ setHasEntry(rootEntry == null ? void 0 : rootEntry.isIntersecting);
1413
+ }, [rootEntry]);
1414
+ React__default.useEffect(() => {
1415
+ if (!isRenderAppWishlist || !hasEntry)
1401
1416
  return;
1402
1417
  if (typeof window !== "undefined") {
1403
1418
  window.sledgeWishlistTriggerUpdate = () => {
@@ -1405,15 +1420,15 @@ const Trigger = (props) => {
1405
1420
  };
1406
1421
  }
1407
1422
  handleSettings(localStorage.getItem(LOCAL_STORAGE_KEY.WISHLIST_SETTING) || null);
1408
- }, [isRenderAppWishlist]);
1423
+ }, [isRenderAppWishlist, hasEntry]);
1409
1424
  React__default.useEffect(() => {
1410
1425
  setIsRequiredLogin(sledgeAnonymId && is_required_login);
1411
1426
  }, [sledgeAnonymId]);
1412
1427
  React__default.useEffect(() => {
1413
- if (!isRenderAppWishlist)
1428
+ if (!isRenderAppWishlist || !hasEntry)
1414
1429
  return;
1415
1430
  handleCheckWishlist();
1416
- }, [isRenderAppWishlist, productVariantId]);
1431
+ }, [isRenderAppWishlist, hasEntry, productVariantId]);
1417
1432
  const isActive = (isWishlist || forceActive) && !isRequiredLogin;
1418
1433
  React__default.useEffect(() => {
1419
1434
  if (isActive) {
@@ -1424,7 +1439,7 @@ const Trigger = (props) => {
1424
1439
  setTypeIcon(defaultTypeIcon);
1425
1440
  }
1426
1441
  }, [isWishlist]);
1427
- return /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: !isLoading && !hidden && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-wishlist__trigger-block", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
1442
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { ref: rootRef, children: !isLoading && !hidden && /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-wishlist__trigger-block", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
1428
1443
  "span",
1429
1444
  {
1430
1445
  className: "sledge-wishlist__trigger",
@@ -1891,7 +1906,13 @@ const Rating = (props) => {
1891
1906
  const [averageReview, setAverageReview] = React__default.useState(((_b = propsData == null ? void 0 : propsData.rating) == null ? void 0 : _b.average) || average || "0");
1892
1907
  const [dataSettings, setDataSettings] = React__default.useState((sledgeSettings == null ? void 0 : sledgeSettings.review) || {});
1893
1908
  const [isFirstTime, setIsFirstTime] = React__default.useState(true);
1909
+ const [hasEntry, setHasEntry] = React__default.useState(false);
1894
1910
  const previousState = usePrevious({ productId });
1911
+ const [rootRef, rootEntry] = useIntersectionObserver({
1912
+ threshold: 0,
1913
+ root: null,
1914
+ rootMargin: "0px"
1915
+ });
1895
1916
  const { fill_color = "#23BC45", outline_color = "#8D9196" } = ((_c = dataSettings == null ? void 0 : dataSettings.display) == null ? void 0 : _c.rating) || {};
1896
1917
  const unixTimestamp = getUnixTimestamp();
1897
1918
  const handleProductRatingInfo = async (paramsProductId, isTriggerMultiComponent = false) => {
@@ -1956,7 +1977,11 @@ const Rating = (props) => {
1956
1977
  }, 200);
1957
1978
  };
1958
1979
  React__default.useEffect(() => {
1959
- if (!isRenderAppProductReview)
1980
+ if (!hasEntry && (rootEntry == null ? void 0 : rootEntry.isIntersecting))
1981
+ setHasEntry(rootEntry == null ? void 0 : rootEntry.isIntersecting);
1982
+ }, [rootEntry]);
1983
+ React__default.useEffect(() => {
1984
+ if (!isRenderAppProductReview || !hasEntry)
1960
1985
  return;
1961
1986
  if (size === "xs") {
1962
1987
  setSizing({
@@ -1978,7 +2003,7 @@ const Rating = (props) => {
1978
2003
  if (isProductIdChanged)
1979
2004
  setIsFirstLoading(true);
1980
2005
  handleSettings(localStorage.getItem(LOCAL_STORAGE_KEY.PRODUCT_REVIEW_SETTING) || null);
1981
- }, [isRenderAppProductReview, productId]);
2006
+ }, [isRenderAppProductReview, hasEntry, productId]);
1982
2007
  React__default.useEffect(() => {
1983
2008
  if (!productId || productId && valueRenderProductReviewRating !== productId)
1984
2009
  return;
@@ -1995,6 +2020,7 @@ const Rating = (props) => {
1995
2020
  ...typeof size === "string" ? {
1996
2021
  ["data-rating-size"]: size
1997
2022
  } : {},
2023
+ ref: rootRef,
1998
2024
  children: isFirstLoading && withSkeletonLoading ? /* @__PURE__ */ jsxRuntimeExports.jsx(SkeletonLoading.Item, { width: "230px", height: "28px", color: "lighten", rounded: "md" }) : /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: !isLoading && /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
1999
2025
  [1, 2, 3, 4, 5].map((item, index) => {
2000
2026
  if (!(item <= numberOfIcons))
@@ -2504,6 +2530,16 @@ const ProductCard = (props) => {
2504
2530
  const defaultSelectedVariantStock = (variants == null ? void 0 : variants.length) && Object.hasOwn(variants[0], "inventory_quantity") ? variants[0].inventory_quantity : 0;
2505
2531
  const [selectedVariantId, setSelectedVariantId] = React__default.useState(defaultSelectedVariantId);
2506
2532
  const [selectedVariantStock, setSelectedVariantStock] = React__default.useState(defaultSelectedVariantStock);
2533
+ const [hasEntry, setHasEntry] = React__default.useState(false);
2534
+ const [rootRef, rootEntry] = useIntersectionObserver({
2535
+ threshold: 0,
2536
+ root: null,
2537
+ rootMargin: "0px"
2538
+ });
2539
+ React__default.useEffect(() => {
2540
+ if (!hasEntry && (rootEntry == null ? void 0 : rootEntry.isIntersecting))
2541
+ setHasEntry(rootEntry == null ? void 0 : rootEntry.isIntersecting);
2542
+ }, [rootEntry]);
2507
2543
  let isLoadingAddToCart = clickedAddToCartId == selectedVariantId;
2508
2544
  let isOutOfStock = (variants == null ? void 0 : variants.length) && Object.hasOwn(variants[0], "inventory_quantity") ? !Number(selectedVariantStock) && showOptionOutOfStock : false;
2509
2545
  let component = null;
@@ -2531,7 +2567,7 @@ const ProductCard = (props) => {
2531
2567
  setShowPopupComponent,
2532
2568
  sourceApp
2533
2569
  };
2534
- component = /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: isComponentJsVersion ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { dangerouslySetInnerHTML: { __html: CardsComponent({ ...CardsProps }) } }) : /* @__PURE__ */ jsxRuntimeExports.jsx(CardsComponent, { ...CardsProps }) });
2570
+ component = /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: isComponentJsVersion ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge__product-grid-entry-card", dangerouslySetInnerHTML: { __html: CardsComponent({ ...CardsProps }) } }) : /* @__PURE__ */ jsxRuntimeExports.jsx(CardsComponent, { ...CardsProps }) });
2535
2571
  } else {
2536
2572
  let setDefaultFunction = function() {
2537
2573
  if (!(variants == null ? void 0 : variants.length))
@@ -2806,7 +2842,7 @@ ${selectedOption === item2 ? "sledge__product-variant-size-swatch-active" : ""}
2806
2842
  ) }) : null
2807
2843
  ] });
2808
2844
  }
2809
- return /* @__PURE__ */ jsxRuntimeExports.jsx(React__default.Fragment, { children: component }, id);
2845
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge__product-grid-entry-card", ref: rootRef, children: hasEntry && component }, id);
2810
2846
  };
2811
2847
  const ProductGrid = (props) => {
2812
2848
  const { type, className = "", data, setting, sourceApp = null, useSlider = false, onAfterAddToCart, onAfterRenderProduct } = props;
@@ -3880,17 +3916,40 @@ const SearchIconWidgetPopup = () => {
3880
3916
  ] })
3881
3917
  ] }) });
3882
3918
  };
3883
- const ButtonLoadMore = ({ text, onClick, isInfiniteScroll, ...otherProps }) => {
3919
+ const ButtonLoadMore = ({ text, onClick, isInfiniteScroll, currentPage, totalPage, totalResult, pageInfo: pageInfoProp, isVisibleLoadMore, ...otherProps }) => {
3884
3920
  const [ref, entry] = useIntersectionObserver({
3885
3921
  threshold: 0,
3886
3922
  root: null,
3887
3923
  rootMargin: "0px"
3888
3924
  });
3925
+ const [pageInfo, setPageInfo] = React__default.useState(null);
3926
+ const handlePageInfo = () => {
3927
+ const defaultPageInfo = /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
3928
+ "Page ",
3929
+ currentPage,
3930
+ " of ",
3931
+ totalPage,
3932
+ " - total ",
3933
+ totalResult,
3934
+ " result"
3935
+ ] });
3936
+ if (pageInfoProp) {
3937
+ pageInfoProp = pageInfoProp.replaceAll(OBJECT_DATA_STRING_KEY.CURRENT_PAGE, String(currentPage));
3938
+ pageInfoProp = pageInfoProp.replaceAll(OBJECT_DATA_STRING_KEY.TOTAL_PAGE, String(totalPage));
3939
+ pageInfoProp = pageInfoProp.replaceAll(OBJECT_DATA_STRING_KEY.TOTAL_RESULT, String(totalResult));
3940
+ }
3941
+ setPageInfo(pageInfoProp ? pageInfoProp : defaultPageInfo);
3942
+ };
3889
3943
  React__default.useEffect(() => {
3890
- if (isInfiniteScroll && (entry == null ? void 0 : entry.isIntersecting))
3944
+ handlePageInfo();
3945
+ if (isInfiniteScroll && isVisibleLoadMore && (entry == null ? void 0 : entry.isIntersecting))
3891
3946
  onClick == null ? void 0 : onClick();
3892
3947
  }, [entry]);
3893
- return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge__pagination", ref, children: (entry == null ? void 0 : entry.isIntersecting) && /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { type: "button", role: "button", colorType: "light", onClick, ...otherProps, children: text }) });
3948
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge__pagination", ref, children: (entry == null ? void 0 : entry.isIntersecting) && /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge-instant-search__load-more", children: [
3949
+ /* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: pageInfo }),
3950
+ /* @__PURE__ */ jsxRuntimeExports.jsx(Progress, { value: currentPage, total: totalPage, delay: 0 }),
3951
+ isVisibleLoadMore && /* @__PURE__ */ jsxRuntimeExports.jsx(Button, { type: "button", role: "button", colorType: "light", onClick, ...otherProps, children: text })
3952
+ ] }) });
3894
3953
  };
3895
3954
  const SearchResultWidget = (props) => {
3896
3955
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
@@ -5258,7 +5317,7 @@ const ResultProduct = (props) => {
5258
5317
  }
5259
5318
  ) }, indexFilter) : null;
5260
5319
  });
5261
- const paginationComponent = isLoadMore ? isVisibleLoadMore ? /* @__PURE__ */ jsxRuntimeExports.jsx(
5320
+ const paginationComponent = isLoadMore ? /* @__PURE__ */ jsxRuntimeExports.jsx(
5262
5321
  ButtonLoadMore,
5263
5322
  {
5264
5323
  disabled: isLoadingButtonLoadMore,
@@ -5269,9 +5328,14 @@ const ResultProduct = (props) => {
5269
5328
  }
5270
5329
  },
5271
5330
  text: isLoadingButtonLoadMore ? button_loading || "Loading..." : button_load_more || "Load More",
5272
- isInfiniteScroll: ((_k = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _k.pagination_type) === "infinite_scroll"
5331
+ isInfiniteScroll: ((_k = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _k.pagination_type) === "infinite_scroll",
5332
+ currentPage,
5333
+ totalPage,
5334
+ totalResult: totalSearchResult,
5335
+ pageInfo: language_pagination_info,
5336
+ isVisibleLoadMore
5273
5337
  }
5274
- ) : null : /* @__PURE__ */ jsxRuntimeExports.jsx(Pagination, { currentPage, totalPage, totalResult: totalSearchResult, onChange: (page) => handlePageChange(page), pageInfo: language_pagination_info });
5338
+ ) : /* @__PURE__ */ jsxRuntimeExports.jsx(Pagination, { currentPage, totalPage, totalResult: totalSearchResult, onChange: (page) => handlePageChange(page), pageInfo: language_pagination_info });
5275
5339
  const filterHorizontalBlockComponent = ((_l = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _l.enable_on_search) && allowedFilter.length ? /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: isFirstLoading && !propsData ? filterHorizontalSkeleton : /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: isLoadingSetting && !propsData ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-filter-horizontal-loading", children: filterHorizontalSkeleton }) : /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge-instant-search__result-filter-horizontal-wrapper", children: [
5276
5340
  /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-filter-horizontal sledge-instant-search__result-filter-horizontal-component", children: filterHorizontalComponents }),
5277
5341
  Boolean((dataClickedFacets == null ? void 0 : dataClickedFacets.length) && ((_m = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _m.show_refine_by_block)) ? /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge-instant-search__result-filter-horizontal", children: [