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

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.
@@ -22,7 +22,8 @@ const SEPARATE_COMPONENT_DISPLAY_NAME = {
22
22
  },
23
23
  SUGGESTION_KEYWORD_LISTS: "SuggestionKeywordLists",
24
24
  OTHER_INDEX_LISTS: "OtherIndexLists",
25
- SEARCH_VIEW_MORE_RESULT: "SearchViewMoreResult"
25
+ SEARCH_VIEW_MORE_RESULT: "SearchViewMoreResult",
26
+ WISHLIST_WIDGET_ALERT: "WishlistWidgetAlert"
26
27
  };
27
28
  const sanitizeDataId = (id) => {
28
29
  if (!id)
@@ -36,6 +37,14 @@ const sanitizeDataId = (id) => {
36
37
  }
37
38
  };
38
39
  const isFunction = (data) => typeof data === "function";
40
+ const scrollToElement = (element, headerOffset) => {
41
+ var elementPosition = element == null ? void 0 : element.getBoundingClientRect().top;
42
+ var offsetPosition = elementPosition + window.scrollY - headerOffset;
43
+ window.scrollTo({
44
+ top: offsetPosition,
45
+ behavior: "smooth"
46
+ });
47
+ };
39
48
  const SearchIconWidget$1 = "";
40
49
  const root = "";
41
50
  const Loading = "";
@@ -2188,16 +2197,15 @@ const SkeletonLoading = {
2188
2197
  BlogGrid: SkeletonBlogGrid
2189
2198
  };
2190
2199
  const SearchIconWidget = (props) => {
2200
+ const { isRenderApp, isJsVersion } = React__default.useContext(SledgeContext);
2191
2201
  const { size = "sm", children, onAfterAddToCart, onAfterAddWishlist, onAfterRemoveWishlist, onAfterRenderProduct } = props || {};
2192
2202
  let productCardsComponent = null;
2193
2203
  let suggestionKeywordListsComponent = null;
2194
2204
  let otherIndexListsComponent = null;
2195
2205
  let searchViewMoreResultComponent = null;
2196
- let separateJsVersionComponent = false;
2197
2206
  React__default.Children.map(children, (child) => {
2198
2207
  if (React__default.isValidElement(child) && isFunction(child.type)) {
2199
- const { component, isJsVersion } = (child == null ? void 0 : child.props) || {};
2200
- separateJsVersionComponent = isJsVersion;
2208
+ const { component } = (child == null ? void 0 : child.props) || {};
2201
2209
  switch (child.type.name) {
2202
2210
  case SEPARATE_COMPONENT_DISPLAY_NAME.PRODUCT.CARDS:
2203
2211
  productCardsComponent = component;
@@ -2214,7 +2222,6 @@ const SearchIconWidget = (props) => {
2214
2222
  }
2215
2223
  }
2216
2224
  });
2217
- const { isRenderApp } = React__default.useContext(SledgeContext);
2218
2225
  const [sizing, setSizing] = React__default.useState({
2219
2226
  width: 0,
2220
2227
  height: 0
@@ -2246,7 +2253,7 @@ const SearchIconWidget = (props) => {
2246
2253
  onAfterAddWishlist,
2247
2254
  onAfterRemoveWishlist,
2248
2255
  onAfterRenderProduct,
2249
- separateJsVersionComponent,
2256
+ isJsVersion,
2250
2257
  productCardsComponent,
2251
2258
  suggestionKeywordListsComponent,
2252
2259
  otherIndexListsComponent,
@@ -2321,7 +2328,7 @@ const SearchIconWidgetPopup = () => {
2321
2328
  },
2322
2329
  onAfterRenderProduct: (state) => {
2323
2330
  },
2324
- separateJsVersionComponent: null,
2331
+ isJsVersion: null,
2325
2332
  productCardsComponent: null,
2326
2333
  suggestionKeywordListsComponent: null,
2327
2334
  otherIndexListsComponent: null,
@@ -2419,7 +2426,7 @@ const SearchIconWidgetPopup = () => {
2419
2426
  },
2420
2427
  onAfterRenderProduct = () => {
2421
2428
  },
2422
- separateJsVersionComponent = null,
2429
+ isJsVersion = null,
2423
2430
  productCardsComponent = () => {
2424
2431
  },
2425
2432
  suggestionKeywordListsComponent = () => {
@@ -2435,7 +2442,7 @@ const SearchIconWidgetPopup = () => {
2435
2442
  onAfterAddWishlist,
2436
2443
  onAfterRemoveWishlist,
2437
2444
  onAfterRenderProduct,
2438
- separateJsVersionComponent,
2445
+ isJsVersion,
2439
2446
  productCardsComponent,
2440
2447
  suggestionKeywordListsComponent,
2441
2448
  otherIndexListsComponent,
@@ -2525,7 +2532,7 @@ const SearchIconWidgetPopup = () => {
2525
2532
  {
2526
2533
  listsComponent: handleFunctions.suggestionKeywordListsComponent,
2527
2534
  keywords: suggestionSettings[suggestionIndex].keywords.list,
2528
- isComponentJsVersion: handleFunctions.separateJsVersionComponent
2535
+ isComponentJsVersion: handleFunctions.isJsVersion
2529
2536
  }
2530
2537
  ) : null,
2531
2538
  searchResultOther && searchResultOther.map((item, index) => {
@@ -2536,7 +2543,7 @@ const SearchIconWidgetPopup = () => {
2536
2543
  listsComponent: handleFunctions.otherIndexListsComponent,
2537
2544
  name,
2538
2545
  items: hits,
2539
- isComponentJsVersion: handleFunctions.separateJsVersionComponent
2546
+ isComponentJsVersion: handleFunctions.isJsVersion
2540
2547
  }
2541
2548
  ) }, index);
2542
2549
  })
@@ -2560,7 +2567,7 @@ const SearchIconWidgetPopup = () => {
2560
2567
  show_price: (_i = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _i.show_price
2561
2568
  },
2562
2569
  showOptionOutOfStock: true,
2563
- isComponentJsVersion: handleFunctions.separateJsVersionComponent,
2570
+ isComponentJsVersion: handleFunctions.isJsVersion,
2564
2571
  cards: handleFunctions.productCardsComponent,
2565
2572
  onAfterAddToCart: handleFunctions.onAfterAddToCart,
2566
2573
  onAfterAddWishlist: handleFunctions.onAfterAddWishlist,
@@ -2592,7 +2599,7 @@ const SearchIconWidgetPopup = () => {
2592
2599
  show_price: (_q = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _q.show_price
2593
2600
  },
2594
2601
  showOptionOutOfStock: true,
2595
- isComponentJsVersion: handleFunctions.separateJsVersionComponent,
2602
+ isComponentJsVersion: handleFunctions.isJsVersion,
2596
2603
  cards: handleFunctions.productCardsComponent,
2597
2604
  onAfterAddToCart: handleFunctions.onAfterAddToCart,
2598
2605
  onAfterAddWishlist: handleFunctions.onAfterAddWishlist,
@@ -2609,7 +2616,7 @@ const SearchIconWidgetPopup = () => {
2609
2616
  {
2610
2617
  component: handleFunctions.searchViewMoreResultComponent,
2611
2618
  keyword,
2612
- isComponentJsVersion: handleFunctions.separateJsVersionComponent
2619
+ isComponentJsVersion: handleFunctions.isJsVersion
2613
2620
  }
2614
2621
  ) }) : null
2615
2622
  ] })
@@ -2620,19 +2627,17 @@ const SearchIconWidgetPopup = () => {
2620
2627
  const SearchResultWidget$1 = "";
2621
2628
  const SearchResultWidget = (props) => {
2622
2629
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2630
+ const { isRenderApp, isJsVersion } = React__default.useContext(SledgeContext);
2623
2631
  const { layoutType = "default", query, data, children, onAfterAddToCart, onAfterAddWishlist, onAfterRemoveWishlist, onAfterRenderProduct } = props;
2624
2632
  const { keyword: queryKeyword = "" } = query || {};
2625
2633
  const { collectionId } = data || {};
2626
2634
  let productCardsComponent = null;
2627
- let separateJsVersionComponent = false;
2628
2635
  React__default.Children.map(children, (child) => {
2629
2636
  if (React__default.isValidElement(child) && isFunction(child.type) && child.type.name === SEPARATE_COMPONENT_DISPLAY_NAME.PRODUCT.CARDS) {
2630
- const { component, isJsVersion } = (child == null ? void 0 : child.props) || {};
2637
+ const { component } = (child == null ? void 0 : child.props) || {};
2631
2638
  productCardsComponent = component;
2632
- separateJsVersionComponent = isJsVersion;
2633
2639
  }
2634
2640
  });
2635
- const { isRenderApp } = React__default.useContext(SledgeContext);
2636
2641
  const [isFirstLoading, setIsFirstLoading] = React__default.useState(true);
2637
2642
  const [isLoading, setIsLoading] = React__default.useState(true);
2638
2643
  const [keyword, setKeyword] = React__default.useState("");
@@ -2651,6 +2656,7 @@ const SearchResultWidget = (props) => {
2651
2656
  const [colorSwatches, setColorSwatches] = React__default.useState([]);
2652
2657
  const [defaultSort, setDefaultSort] = React__default.useState("");
2653
2658
  const [showOutOfStock, setShowOutOfStock] = React__default.useState(false);
2659
+ const searchResultContainerRef = React__default.useRef(null);
2654
2660
  const previousState = usePrevious({ keyword });
2655
2661
  const handleChangeTabIndex = (id, name, e) => {
2656
2662
  setClickedTabIndexId(id);
@@ -3060,7 +3066,7 @@ const SearchResultWidget = (props) => {
3060
3066
  /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-data-summary-select-field-item", children: /* @__PURE__ */ jsxRuntimeExports.jsx(SkeletonLoading.Item, { width: "150px", height: "42px", color: "grey-100", rounded: "lg" }) })
3061
3067
  ] })
3062
3068
  ] });
3063
- return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge-instant-search__result-container", children: [
3069
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge-instant-search__result-container", ref: searchResultContainerRef, children: [
3064
3070
  isFirstLoading ? null : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `${layoutType === "default" && (allowedTabs == null ? void 0 : allowedTabs.length) ? "sledge-instant-search__result-tab" : "sledge-instant-search__result-tab-no-index"}`, children: layoutType === "default" && (allowedTabs == null ? void 0 : allowedTabs.length) ? /* @__PURE__ */ jsxRuntimeExports.jsx("ul", { className: "sledge-instant-search__result-tab-list", children: allowedTabs.map((item) => {
3065
3071
  const { name, index, total } = item;
3066
3072
  let isActive = clickedTabIndexId === index;
@@ -3096,7 +3102,7 @@ const SearchResultWidget = (props) => {
3096
3102
  showOutOfStock,
3097
3103
  query,
3098
3104
  data,
3099
- separateJsVersionComponent,
3105
+ isJsVersion,
3100
3106
  productCardsComponent,
3101
3107
  onAfterAddToCart,
3102
3108
  onAfterAddWishlist,
@@ -3107,7 +3113,8 @@ const SearchResultWidget = (props) => {
3107
3113
  filterHorizontalSkeleton,
3108
3114
  filterVerticalSkeleton,
3109
3115
  productGridSkeleton,
3110
- searchAndSelectOptionSkeleton
3116
+ searchAndSelectOptionSkeleton,
3117
+ searchResultContainerRef
3111
3118
  })
3112
3119
  ] });
3113
3120
  };
@@ -3128,7 +3135,7 @@ const ResultProduct = (props) => {
3128
3135
  showOutOfStock,
3129
3136
  query,
3130
3137
  data,
3131
- separateJsVersionComponent,
3138
+ isJsVersion,
3132
3139
  productCardsComponent,
3133
3140
  setKeyword,
3134
3141
  filterHorizontalSkeleton,
@@ -3138,7 +3145,8 @@ const ResultProduct = (props) => {
3138
3145
  onAfterAddToCart,
3139
3146
  onAfterAddWishlist,
3140
3147
  onAfterRemoveWishlist,
3141
- onAfterRenderProduct
3148
+ onAfterRenderProduct,
3149
+ searchResultContainerRef
3142
3150
  } = props || {};
3143
3151
  const { keyword: queryKeyword = "" } = query || {};
3144
3152
  const { collectionId } = data || {};
@@ -3395,6 +3403,9 @@ const ResultProduct = (props) => {
3395
3403
  };
3396
3404
  const handlePageChange = (page) => {
3397
3405
  setCurrentPage(page);
3406
+ setTimeout(() => {
3407
+ scrollToElement(searchResultContainerRef.current, 50);
3408
+ }, 200);
3398
3409
  };
3399
3410
  const handleChangeKeyword = (value) => {
3400
3411
  const searchParams = new URLSearchParams(document.location.search);
@@ -3739,7 +3750,7 @@ const ResultProduct = (props) => {
3739
3750
  show_sku: (_s = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _s.show_sku,
3740
3751
  show_price: (_t = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _t.show_price
3741
3752
  },
3742
- isComponentJsVersion: separateJsVersionComponent,
3753
+ isComponentJsVersion: isJsVersion,
3743
3754
  cards: productCardsComponent,
3744
3755
  showOptionOutOfStock: true,
3745
3756
  onAfterAddToCart,
@@ -3757,7 +3768,7 @@ const ResultProduct = (props) => {
3757
3768
  };
3758
3769
  const ResultCategory = (props) => {
3759
3770
  var _a, _b, _c, _d;
3760
- const { keyword, clickedTabIndexId, clickedTabIndexName, setKeyword } = props || {};
3771
+ const { keyword, clickedTabIndexId, clickedTabIndexName, setKeyword, searchResultContainerRef } = props || {};
3761
3772
  const [isFirstLoading, setIsFirstLoading] = React__default.useState(true);
3762
3773
  const [isLoading, setIsLoading] = React__default.useState(true);
3763
3774
  const [clickedSortId, setClickedSortId] = React__default.useState("");
@@ -3810,6 +3821,9 @@ const ResultCategory = (props) => {
3810
3821
  };
3811
3822
  const handlePageChange = (page) => {
3812
3823
  setCurrentPage(page);
3824
+ setTimeout(() => {
3825
+ scrollToElement(searchResultContainerRef.current, 50);
3826
+ }, 200);
3813
3827
  };
3814
3828
  React__default.useEffect(() => {
3815
3829
  if (Boolean(previousState && (previousState == null ? void 0 : previousState.keyword) !== keyword)) {
@@ -3888,16 +3902,15 @@ const ResultEmpty = (props) => {
3888
3902
  const SearchWidget$1 = "";
3889
3903
  const SearchWidget = (props) => {
3890
3904
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
3905
+ const { isRenderApp, isJsVersion } = React__default.useContext(SledgeContext);
3891
3906
  const { width = "400px", children, onAfterAddToCart, onAfterAddWishlist, onAfterRemoveWishlist, onAfterRenderProduct } = props;
3892
3907
  let productCardsComponent = null;
3893
3908
  let suggestionKeywordListsComponent = null;
3894
3909
  let otherIndexListsComponent = null;
3895
3910
  let searchViewMoreResultComponent = null;
3896
- let separateJsVersionComponent = false;
3897
3911
  React__default.Children.map(children, (child) => {
3898
3912
  if (React__default.isValidElement(child) && isFunction(child.type)) {
3899
- const { component, isJsVersion } = (child == null ? void 0 : child.props) || {};
3900
- separateJsVersionComponent = isJsVersion;
3913
+ const { component } = (child == null ? void 0 : child.props) || {};
3901
3914
  switch (child.type.name) {
3902
3915
  case SEPARATE_COMPONENT_DISPLAY_NAME.PRODUCT.CARDS:
3903
3916
  productCardsComponent = component;
@@ -3914,7 +3927,6 @@ const SearchWidget = (props) => {
3914
3927
  }
3915
3928
  }
3916
3929
  });
3917
- const { isRenderApp } = React__default.useContext(SledgeContext);
3918
3930
  const [isLoading, setIsLoading] = React__default.useState(true);
3919
3931
  const [keyword, setKeyword] = React__default.useState("");
3920
3932
  const [suffixIndexProduct, setSuffixIndexProduct] = React__default.useState("");
@@ -4084,12 +4096,12 @@ const SearchWidget = (props) => {
4084
4096
  {
4085
4097
  listsComponent: suggestionKeywordListsComponent,
4086
4098
  keywords: suggestionSettings[suggestionIndex].keywords.list,
4087
- isComponentJsVersion: separateJsVersionComponent
4099
+ isComponentJsVersion: isJsVersion
4088
4100
  }
4089
4101
  ) : null,
4090
4102
  searchResultOther.map((item, index) => {
4091
4103
  const { hits, name } = item;
4092
- return /* @__PURE__ */ jsxRuntimeExports.jsx(React__default.Fragment, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(Global.OtherIndexLists, { listsComponent: otherIndexListsComponent, name, items: hits, isComponentJsVersion: separateJsVersionComponent }) }, index);
4104
+ return /* @__PURE__ */ jsxRuntimeExports.jsx(React__default.Fragment, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(Global.OtherIndexLists, { listsComponent: otherIndexListsComponent, name, items: hits, isComponentJsVersion: isJsVersion }) }, index);
4093
4105
  })
4094
4106
  ] }),
4095
4107
  /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge-instant-search__widget-search-form-result-flex-item-product", children: [
@@ -4112,7 +4124,7 @@ const SearchWidget = (props) => {
4112
4124
  show_price: (_h = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _h.show_price
4113
4125
  },
4114
4126
  showOptionOutOfStock: true,
4115
- isComponentJsVersion: separateJsVersionComponent,
4127
+ isComponentJsVersion: isJsVersion,
4116
4128
  cards: productCardsComponent,
4117
4129
  onAfterAddToCart,
4118
4130
  onAfterAddWishlist,
@@ -4145,7 +4157,7 @@ const SearchWidget = (props) => {
4145
4157
  show_price: (_p = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _p.show_price
4146
4158
  },
4147
4159
  showOptionOutOfStock: true,
4148
- isComponentJsVersion: separateJsVersionComponent,
4160
+ isComponentJsVersion: isJsVersion,
4149
4161
  cards: productCardsComponent,
4150
4162
  onAfterAddToCart,
4151
4163
  onAfterAddWishlist,
@@ -4156,7 +4168,7 @@ const SearchWidget = (props) => {
4156
4168
  ] }) : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__widget-search-form-result-product-disabled", children: "No product were found" })
4157
4169
  ] })
4158
4170
  ] }),
4159
- (searchResultProduct == null ? void 0 : searchResultProduct.length) || Object.keys(suggestionSettings).length && ((_r = (_q = suggestionSettings[suggestionIndex]) == null ? void 0 : _q.products) == null ? void 0 : _r.active) && ((_u = (_t = (_s = suggestionSettings[suggestionIndex]) == null ? void 0 : _s.products) == null ? void 0 : _t.list) == null ? void 0 : _u.length) ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__widget-button-more-wrapper", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Global.SearchViewMoreResult, { component: searchViewMoreResultComponent, keyword, isComponentJsVersion: separateJsVersionComponent }) }) : null
4171
+ (searchResultProduct == null ? void 0 : searchResultProduct.length) || Object.keys(suggestionSettings).length && ((_r = (_q = suggestionSettings[suggestionIndex]) == null ? void 0 : _q.products) == null ? void 0 : _r.active) && ((_u = (_t = (_s = suggestionSettings[suggestionIndex]) == null ? void 0 : _s.products) == null ? void 0 : _t.list) == null ? void 0 : _u.length) ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__widget-button-more-wrapper", children: /* @__PURE__ */ jsxRuntimeExports.jsx(Global.SearchViewMoreResult, { component: searchViewMoreResultComponent, keyword, isComponentJsVersion: isJsVersion }) }) : null
4160
4172
  ] }) }) })
4161
4173
  ] });
4162
4174
  };