@sledge-app/react-instant-search 0.0.40 → 0.0.41

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.
@@ -2,9 +2,9 @@ import { j as jsxRuntimeExports, $ as $cb5cc270b50c6fcd$export$be92b6f5f03c0fe9,
2
2
  import React__default, { createElement } from "react";
3
3
  import { SledgeContext } from "@sledge-app/core";
4
4
  import "react-dom";
5
- const ProductFilterWidget = (props) => {
5
+ const ProductFilterWidget = React__default.memo((props) => {
6
6
  return /* @__PURE__ */ jsxRuntimeExports.jsx(SearchResultWidget, { layoutType: "product-filter", ...props });
7
- };
7
+ });
8
8
  const API_URL = "https://sledge-api-preprod.offstack.io";
9
9
  const INSTANT_SEARCH_ENGINE_URL = "https://instant-search-engine.offstack.io";
10
10
  const LOCAL_STORAGE_KEY = {
@@ -25,6 +25,11 @@ const SEPARATE_COMPONENT_DISPLAY_NAME = {
25
25
  SEARCH_VIEW_MORE_RESULT: "SearchViewMoreResult",
26
26
  WISHLIST_WIDGET_ALERT: "WishlistWidgetAlert"
27
27
  };
28
+ const ELEMENT_ID = {
29
+ PRODUCT_REVIEW: {
30
+ ELEMENT_WIDGET: "product-review-widget"
31
+ }
32
+ };
28
33
  const sanitizeDataId = (id) => {
29
34
  if (!id)
30
35
  return "";
@@ -38,6 +43,8 @@ const sanitizeDataId = (id) => {
38
43
  };
39
44
  const isFunction = (data) => typeof data === "function";
40
45
  const scrollToElement = (element, headerOffset) => {
46
+ if (!element)
47
+ return;
41
48
  var elementPosition = element == null ? void 0 : element.getBoundingClientRect().top;
42
49
  var offsetPosition = elementPosition + window.scrollY - headerOffset;
43
50
  window.scrollTo({
@@ -1165,7 +1172,7 @@ const getReviewInfo = async (id) => {
1165
1172
  };
1166
1173
  const Rating = (props) => {
1167
1174
  var _a;
1168
- const { value, size = "md", data, withSkeletonLoading = true } = props;
1175
+ const { value, size = "md", data, withSkeletonLoading = true, isScrollToElementWidget = true } = props;
1169
1176
  const { productId } = data || {};
1170
1177
  const { isRenderApp } = React__default.useContext(SledgeContext);
1171
1178
  const [isFirstLoading, setIsFirstLoading] = React__default.useState(true);
@@ -1220,6 +1227,13 @@ const Rating = (props) => {
1220
1227
  await handleProductRatingInfo();
1221
1228
  }
1222
1229
  };
1230
+ const handleOnClick = () => {
1231
+ if (!isScrollToElementWidget)
1232
+ return;
1233
+ setTimeout(() => {
1234
+ scrollToElement(document.getElementById(ELEMENT_ID.PRODUCT_REVIEW.ELEMENT_WIDGET), 50);
1235
+ }, 200);
1236
+ };
1223
1237
  React__default.useEffect(() => {
1224
1238
  if (!(isRenderApp == null ? void 0 : isRenderApp.productReview))
1225
1239
  return;
@@ -1244,7 +1258,7 @@ const Rating = (props) => {
1244
1258
  setIsFirstLoading(true);
1245
1259
  handleSettings(localStorage.getItem(LOCAL_STORAGE_KEY.PRODUCT_REVIEW_SETTING) || "");
1246
1260
  }, [isRenderApp, productId]);
1247
- return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-product-review__rating", children: isFirstLoading && withSkeletonLoading ? /* @__PURE__ */ jsxRuntimeExports.jsx(SkeletonLoading.Item, { width: "230px", height: "28px", color: "grey-100", rounded: "md" }) : /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
1261
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-product-review__rating", onClick: handleOnClick, children: isFirstLoading && withSkeletonLoading ? /* @__PURE__ */ jsxRuntimeExports.jsx(SkeletonLoading.Item, { width: "230px", height: "28px", color: "grey-100", rounded: "md" }) : /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
1248
1262
  /* @__PURE__ */ jsxRuntimeExports.jsxs("svg", { xmlns: "http://www.w3.org/2000/svg", style: { display: "none" }, id: "sledge-product-review-rating-icon-svg-store", children: [
1249
1263
  /* @__PURE__ */ jsxRuntimeExports.jsx("symbol", { id: "sledge-product-review-icons-rating-icon-fill", viewBox: "0 0 30 29", fill: fill_color || "#23BC45", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
1250
1264
  "path",
@@ -1469,7 +1483,7 @@ const WidgetHeaderSummary = (props) => {
1469
1483
  {
1470
1484
  trigger: isLoading ? /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, {}) : /* @__PURE__ */ jsxRuntimeExports.jsxs(motion.div, { initial: false, animate: isOpen ? "open" : "closed", className: "sledge-product-review__widget-summary-trigger", children: [
1471
1485
  /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-product-review__widget-summary-average", children: averageReview }),
1472
- /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-product-review__widget-summary-rating", children: !isRefreshRating && /* @__PURE__ */ jsxRuntimeExports.jsx(Rating, { value: String(averageReview), size: "md", withSkeletonLoading: false }) }),
1486
+ /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-product-review__widget-summary-rating", children: !isRefreshRating && /* @__PURE__ */ jsxRuntimeExports.jsx(Rating, { value: String(averageReview), size: "md", withSkeletonLoading: false, isScrollToElementWidget: false }) }),
1473
1487
  /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge-product-review__widget-summary-total", children: [
1474
1488
  totalReview,
1475
1489
  " ",
@@ -1506,7 +1520,7 @@ const WidgetHeaderSummary = (props) => {
1506
1520
  ] }, index);
1507
1521
  }) }) : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-product-review__widget-summary-dist", children: /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-product-review__widget-summary-dist-progress", children: [5, 4, 3, 2, 1].map((item, index) => {
1508
1522
  return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge-product-review__widget-summary-dist-progress-item", children: [
1509
- /* @__PURE__ */ jsxRuntimeExports.jsx(Rating, { value: item, size: "sm", withSkeletonLoading: false }),
1523
+ /* @__PURE__ */ jsxRuntimeExports.jsx(Rating, { value: item, size: "sm", withSkeletonLoading: false, isScrollToElementWidget: false }),
1510
1524
  /* @__PURE__ */ jsxRuntimeExports.jsx(
1511
1525
  Progress,
1512
1526
  {
@@ -1814,7 +1828,8 @@ const ProductGrid = ({
1814
1828
  productId: id
1815
1829
  },
1816
1830
  size: "xs",
1817
- withSkeletonLoading: false
1831
+ withSkeletonLoading: false,
1832
+ isScrollToElementWidget: false
1818
1833
  }
1819
1834
  ) })
1820
1835
  ] })
@@ -2625,7 +2640,7 @@ const SearchIconWidgetPopup = () => {
2625
2640
  ] }) });
2626
2641
  };
2627
2642
  const SearchResultWidget$1 = "";
2628
- const SearchResultWidget = (props) => {
2643
+ const SearchResultWidget = React__default.memo((props) => {
2629
2644
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2630
2645
  const { isRenderApp, isJsVersion } = React__default.useContext(SledgeContext);
2631
2646
  const { layoutType = "default", query, data, children, onAfterAddToCart, onAfterAddWishlist, onAfterRemoveWishlist, onAfterRenderProduct } = props;
@@ -3117,7 +3132,7 @@ const SearchResultWidget = (props) => {
3117
3132
  searchResultContainerRef
3118
3133
  })
3119
3134
  ] });
3120
- };
3135
+ });
3121
3136
  const ResultProduct = (props) => {
3122
3137
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t;
3123
3138
  const {
@@ -3625,7 +3640,7 @@ const ResultProduct = (props) => {
3625
3640
  });
3626
3641
  const paginationComponent = /* @__PURE__ */ jsxRuntimeExports.jsx(Pagination, { currentPage, totalPage, totalResult: totalSearchResult, onChange: (page) => handlePageChange(page) });
3627
3642
  return /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
3628
- ((_f = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _f.enable_on_search) && ((_g = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _g.layout) === "horizontal" ? /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: isFirstLoading ? filterHorizontalSkeleton : /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: isLoadingSetting ? null : filterHorizontalComponents.every((currentValue) => !currentValue) ? null : /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge-instant-search__result-filter-horizontal-wrapper", children: [
3643
+ ((_f = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _f.enable_on_search) && ((_g = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _g.layout) === "horizontal" ? /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: isFirstLoading ? filterHorizontalSkeleton : /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: isLoadingSetting ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-filter-horizontal-loading", children: filterHorizontalSkeleton }) : filterHorizontalComponents.every((currentValue) => !currentValue) ? null : /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge-instant-search__result-filter-horizontal-wrapper", children: [
3629
3644
  /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-filter-horizontal", children: filterHorizontalComponents }),
3630
3645
  Boolean((dataClickedFacets == null ? void 0 : dataClickedFacets.length) && ((_h = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _h.show_refine_by_block)) ? /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: Boolean(dataClickedFacets.every((currentValue) => !currentValue)) ? null : /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge-instant-search__result-filter-horizontal", children: [
3631
3646
  /* @__PURE__ */ jsxRuntimeExports.jsx(
@@ -3648,7 +3663,7 @@ const ResultProduct = (props) => {
3648
3663
  ] }) }) : null
3649
3664
  ] }) }) }) : null,
3650
3665
  /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-wrapper", "data-filter-layout": (_i = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _i.layout, children: /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
3651
- ((_j = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _j.enable_on_search) && ((_k = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _k.layout) === "vertical" ? isFirstLoading ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-filter", children: filterVerticalSkeleton }) : filterVerticalComponents.every((currentValue) => !currentValue) ? null : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-filter", children: isLoadingSetting ? null : /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
3666
+ ((_j = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _j.enable_on_search) && ((_k = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _k.layout) === "vertical" ? isFirstLoading ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-filter", children: filterVerticalSkeleton }) : filterVerticalComponents.every((currentValue) => !currentValue) ? null : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-filter", children: isLoadingSetting ? filterVerticalSkeleton : /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
3652
3667
  Boolean((dataClickedFacets == null ? void 0 : dataClickedFacets.length) && ((_l = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _l.show_refine_by_block)) ? Boolean(dataClickedFacets.every((currentValue) => !currentValue)) ? null : /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge-instant-search__result-filter-item", children: [
3653
3668
  /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge-instant-search__result-filter-item-title-refine", children: [
3654
3669
  /* @__PURE__ */ jsxRuntimeExports.jsx("strong", { className: "sledge-instant-search__result-filter-item-title-refine-heading", children: "Filter" }),