@sledge-app/react-instant-search 1.0.11 → 1.0.13

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.
@@ -39,7 +39,6 @@ const DATASET_ATTRIBUTE_KEY = {
39
39
  WISHLIST: {
40
40
  SHARE_ID: "data-share-id",
41
41
  QUERY_SHARE_ID: "data-query-share-id",
42
- CUSTOM_ROUTE_PAGE: "data-custom-route-page",
43
42
  RENDER_WISHLIST_WIDGET_ALERT: "data-render-wishlist-widget-alert",
44
43
  USE_PROXY_URL: "data-use-proxy-url",
45
44
  LIMIT_OPTIONS: "data-limit-options"
@@ -55,6 +54,7 @@ const DATASET_ATTRIBUTE_KEY = {
55
54
  ON_AFTER_RENDER_BLOG: "data-on-after-render-blog",
56
55
  ON_AFTER_RENDER_ARTICLE: "data-on-after-render-article",
57
56
  QUERY_KEYWORD: "data-query-keyword",
57
+ URL_SEARCH_RESULT: "data-url-search-result",
58
58
  RENDER_SUGGESTION_KEYWORD_LIST: "data-render-suggestion-keyword-list",
59
59
  RENDER_OTHER_INDEX_LIST: "data-render-other-index-list",
60
60
  RENDER_SEARCH_VIEW_MORE_RESULT: "data-render-search-view-more-result",
@@ -116,7 +116,11 @@ const SELECTOR = {
116
116
  ELEMENT_PLP_WIDGET: `[${SELECTOR_ATTRIBUTE_KEY}="instant-search-product-filter-widget"]`
117
117
  }
118
118
  };
119
- const SEARCH_RESULT_URL = "/pages/search-result";
119
+ const DEFAULT_SEARCH_RESULT_URL = "/apps/sledge/search";
120
+ const DEFAULT_WISHLIST_URL = "/apps/sledge/wishlist";
121
+ const DEFAULT_QUERY_PARAM = {
122
+ KEYWORD: "q"
123
+ };
120
124
  const ELEMENT_ID = {
121
125
  PRODUCT_REVIEW: {
122
126
  ELEMENT_WIDGET: "product-review-widget"
@@ -843,7 +847,7 @@ const BadgeHeaderMenu = (props) => {
843
847
  const { sledgeAnonymId } = React__default.useContext(SledgeContext);
844
848
  const { isFirstLoading, isLoading, totalWishlist, isMaximizeTotalWishlist, proxyUrl, dataSettings, useProxyUrl } = props || {};
845
849
  const { is_required_login } = ((_a = dataSettings == null ? void 0 : dataSettings.display) == null ? void 0 : _a.global) || {};
846
- const defaultColorIcon = "#000000";
850
+ const defaultColorIcon = "currentColor";
847
851
  const [colorIcon, setColorIcon] = React__default.useState(defaultColorIcon);
848
852
  const [isRequiredLogin, setIsRequiredLogin] = React__default.useState(false);
849
853
  React__default.useEffect(() => {
@@ -1002,7 +1006,7 @@ const BadgeRoot = (props) => {
1002
1006
  const [proxyUrl, setProxyUrl] = React__default.useState((propsData == null ? void 0 : propsData.proxy_url) || "");
1003
1007
  const [dataSettings, setDataSettings] = React__default.useState({});
1004
1008
  const handleGetWishlistInfo = async () => {
1005
- var _a2, _b, _c;
1009
+ var _a2, _b;
1006
1010
  let response;
1007
1011
  let run = false;
1008
1012
  let valueTotalWishlist;
@@ -1010,7 +1014,7 @@ const BadgeRoot = (props) => {
1010
1014
  response = await getWishlistInfo();
1011
1015
  run = ((_a2 = response == null ? void 0 : response.status) == null ? void 0 : _a2.code) === 200 || false;
1012
1016
  valueTotalWishlist = !((_b = response == null ? void 0 : response.data) == null ? void 0 : _b.total_data) ? 0 : response.data.total_data;
1013
- valueProxyUrl = ((_c = response == null ? void 0 : response.data) == null ? void 0 : _c.proxy_url) || "";
1017
+ valueProxyUrl = DEFAULT_WISHLIST_URL;
1014
1018
  if (run) {
1015
1019
  setTotalWishlist(valueTotalWishlist);
1016
1020
  setIsMaximizeTotalWishlist(valueTotalWishlist > 99);
@@ -2287,9 +2291,11 @@ const ProductCard = (props) => {
2287
2291
  const { id, title, image, url, vendor = "", currency, handle } = product || {};
2288
2292
  const { id: variant_id = "", admin_graphql_api_id: variant_admin_graphql_api_id = "", title: variant_title = "", price = "", sku = "" } = (variants == null ? void 0 : variants.length) ? variants[0] : {};
2289
2293
  const defaultSelectedVariantId = variant_admin_graphql_api_id ? variant_admin_graphql_api_id : "";
2294
+ const defaultSelectedVariantStock = (variants == null ? void 0 : variants.length) && Object.hasOwn(variants[0], "inventory_quantity") ? variants[0].inventory_quantity : 0;
2290
2295
  const [selectedVariantId, setSelectedVariantId] = React__default.useState(defaultSelectedVariantId);
2296
+ const [selectedVariantStock, setSelectedVariantStock] = React__default.useState(defaultSelectedVariantStock);
2291
2297
  let isLoadingAddToCart = clickedAddToCartId == selectedVariantId;
2292
- let isOutOfStock = (variants == null ? void 0 : variants.length) && Object.hasOwn(variants[0], "inventory_quantity") ? !variants[0].inventory_quantity && showOptionOutOfStock : false;
2298
+ let isOutOfStock = (variants == null ? void 0 : variants.length) && Object.hasOwn(variants[0], "inventory_quantity") ? !Number(selectedVariantStock) && showOptionOutOfStock : false;
2293
2299
  let component = null;
2294
2300
  if (CardsComponent) {
2295
2301
  const CardsProps = {
@@ -2327,6 +2333,7 @@ const ProductCard = (props) => {
2327
2333
  defaultSelected["data-selected-option2"] = variants[0].option2;
2328
2334
  }
2329
2335
  defaultSelected["data-variant-id"] = variants[0].admin_graphql_api_id;
2336
+ defaultSelected["data-inventory-quantity"] = variants[0].inventory_quantity;
2330
2337
  }, setSelectedOption = function(element, optionName) {
2331
2338
  const optionsButton = element.target.offsetParent.querySelector(`.options-button-${optionName}`).querySelectorAll(`button`);
2332
2339
  const defaultSelectedClassChanger = () => {
@@ -2352,7 +2359,7 @@ const ProductCard = (props) => {
2352
2359
  defaultSelectedClassChanger();
2353
2360
  }
2354
2361
  }, setSelectedVariant = function(element, value, optionIndex) {
2355
- var _a2;
2362
+ var _a2, _b2;
2356
2363
  const parentCard = element.target.offsetParent;
2357
2364
  const selectedInput = parentCard.querySelector(`.sledge__product-grid-card-selected-option[data-product-id='${id}']`);
2358
2365
  const setOptionAttribute = () => {
@@ -2364,10 +2371,14 @@ const ProductCard = (props) => {
2364
2371
  const selectOption = parentCard.querySelector(`select option${option1}${option2}`);
2365
2372
  const variantId = selectOption.attributes["data-graphql-id"].value;
2366
2373
  const imageId = (_a2 = selectOption.attributes["data-image-id"]) == null ? void 0 : _a2.value;
2374
+ const inventoryQuantity = (_b2 = selectOption.attributes["data-inventory-quantity"]) == null ? void 0 : _b2.value;
2367
2375
  const setOther = () => {
2368
2376
  selectedInput.attributes[`data-variant-id`].value = selectOption.attributes["data-graphql-id"].value;
2377
+ selectedInput.attributes[`data-inventory-quantity`].value = inventoryQuantity;
2369
2378
  if (variantId)
2370
2379
  setSelectedVariantId(variantId);
2380
+ if (inventoryQuantity)
2381
+ setSelectedVariantStock(inventoryQuantity);
2371
2382
  if (imageId)
2372
2383
  parentCard.querySelector(`img.sledge__product-grid-card-image-featured-image`).src = parentCard.querySelector(
2373
2384
  `div.sledge__product-grid-card-variant-images img[id="${imageId}"]`
@@ -2394,6 +2405,7 @@ const ProductCard = (props) => {
2394
2405
  onClick: () => sourceApp === "instant-search" && productClickTrigger({
2395
2406
  productId: id
2396
2407
  }),
2408
+ className: "sledge__product-grid-card-image-link",
2397
2409
  children: [
2398
2410
  /* @__PURE__ */ jsxRuntimeExports.jsx(
2399
2411
  Trigger,
@@ -2476,10 +2488,11 @@ const ProductCard = (props) => {
2476
2488
  /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge__product-grid-card-variant-swatch", children: [
2477
2489
  /* @__PURE__ */ jsxRuntimeExports.jsx("input", { type: "hidden", ...defaultSelected, className: "sledge__product-grid-card-selected-option" }),
2478
2490
  /* @__PURE__ */ jsxRuntimeExports.jsx("select", { className: "variant-picker sledge__product-grid-card-variant-picker", children: variants == null ? void 0 : variants.map((variant) => {
2479
- const { title: title2, option1, option2, position, id: id2, admin_graphql_api_id, image_id } = variant;
2491
+ const { title: title2, option1, option2, position, id: id2, admin_graphql_api_id, image_id, inventory_quantity } = variant;
2480
2492
  let optionAttributes = {
2481
2493
  "data-option-1": option1,
2482
2494
  "data-option-2": option2,
2495
+ "data-inventory-quantity": inventory_quantity,
2483
2496
  "data-position": position,
2484
2497
  "data-id": id2,
2485
2498
  "data-graphql-id": admin_graphql_api_id,
@@ -2962,7 +2975,7 @@ const LoadingDots = () => {
2962
2975
  const SearchIconWidget = (props) => {
2963
2976
  const { isRenderApp, isJsVersion } = React__default.useContext(SledgeContext);
2964
2977
  const { instantSearch: isRenderAppInstantSearch } = isRenderApp || {};
2965
- const { size = "sm", children, onAfterAddToCart, onAfterAddWishlist, onAfterRemoveWishlist, onAfterRenderProduct } = props || {};
2978
+ const { size = "sm", children, onAfterAddToCart, onAfterAddWishlist, onAfterRemoveWishlist, onAfterRenderProduct, urlSearchResult, query } = props || {};
2966
2979
  let productCardsComponent = null;
2967
2980
  let suggestionKeywordListsComponent = null;
2968
2981
  let otherIndexListsComponent = null;
@@ -3015,7 +3028,9 @@ const SearchIconWidget = (props) => {
3015
3028
  productCardsComponent,
3016
3029
  suggestionKeywordListsComponent,
3017
3030
  otherIndexListsComponent,
3018
- searchViewMoreResultComponent
3031
+ searchViewMoreResultComponent,
3032
+ urlSearchResult,
3033
+ query
3019
3034
  });
3020
3035
  };
3021
3036
  return /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "sledge-instant-search__icon-widget", onClick: handleShowWidget, children: /* @__PURE__ */ jsxRuntimeExports.jsx(SearchIcon, { ...sizing, color: "currentColor" }) });
@@ -3069,7 +3084,7 @@ const SuggestionKeywordLists = ({
3069
3084
  return /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: /* @__PURE__ */ jsxRuntimeExports.jsxs(
3070
3085
  "a",
3071
3086
  {
3072
- href: `${SEARCH_RESULT_URL}?q=${keyword}`,
3087
+ href: `${DEFAULT_SEARCH_RESULT_URL}?q=${keyword}`,
3073
3088
  className: "sledge-instant-search__icon-widget-search-form-result-list-link sledge-instant-search__icon-widget-search-form-result-list-link-suggestion",
3074
3089
  children: [
3075
3090
  /* @__PURE__ */ jsxRuntimeExports.jsx(SearchIcon, { width: 12, height: 12, color: "#677487" }),
@@ -3087,7 +3102,9 @@ const SearchViewMoreResult = ({
3087
3102
  keyword,
3088
3103
  isComponentJsVersion = false,
3089
3104
  showPopupComponent,
3090
- setShowPopupComponent
3105
+ setShowPopupComponent,
3106
+ urlSearchResult = DEFAULT_SEARCH_RESULT_URL,
3107
+ query
3091
3108
  }) => {
3092
3109
  var _a;
3093
3110
  if (Component) {
@@ -3100,7 +3117,8 @@ const SearchViewMoreResult = ({
3100
3117
  const ComponentProps = { keyword, showPopupComponent, setShowPopupComponent, setRenderSearchResult };
3101
3118
  return /* @__PURE__ */ jsxRuntimeExports.jsx(React__default.Fragment, { children: isComponentJsVersion ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { dangerouslySetInnerHTML: { __html: Component({ ...ComponentProps }) } }) : /* @__PURE__ */ jsxRuntimeExports.jsx(Component, { ...ComponentProps }) });
3102
3119
  } else {
3103
- return /* @__PURE__ */ jsxRuntimeExports.jsx("a", { href: `${SEARCH_RESULT_URL}?q=${keyword}`, className: "sledge-instant-search__icon-widget-button-more", children: "View More Result" });
3120
+ const queryKeyword = (query == null ? void 0 : query.keyword) ? query.keyword : DEFAULT_QUERY_PARAM.KEYWORD;
3121
+ return /* @__PURE__ */ jsxRuntimeExports.jsx("a", { href: `${urlSearchResult}?${queryKeyword}=${keyword}`, className: "sledge-instant-search__icon-widget-button-more", children: "View More Result" });
3104
3122
  }
3105
3123
  };
3106
3124
  const Global = {
@@ -3121,6 +3139,7 @@ const SearchIconWidgetPopup = () => {
3121
3139
  const [displaySettings, setDisplaySettings] = React__default.useState({});
3122
3140
  const [suggestionSettings, setSuggestionSettings] = React__default.useState({});
3123
3141
  const [suggestionIndex, setSuggestionIndex] = React__default.useState("");
3142
+ const [urlSearchResult, setUrlSearchResult] = React__default.useState("");
3124
3143
  const [handleFunctions, setHandleFunctions] = React__default.useState({
3125
3144
  onAfterAddToCart: (state) => {
3126
3145
  },
@@ -3134,7 +3153,8 @@ const SearchIconWidgetPopup = () => {
3134
3153
  productCardsComponent: null,
3135
3154
  suggestionKeywordListsComponent: null,
3136
3155
  otherIndexListsComponent: null,
3137
- searchViewMoreResultComponent: null
3156
+ searchViewMoreResultComponent: null,
3157
+ query: {}
3138
3158
  });
3139
3159
  const searchFieldRef = React__default.useRef(null);
3140
3160
  const previousState = usePrevious({ keyword });
@@ -3237,7 +3257,9 @@ const SearchIconWidgetPopup = () => {
3237
3257
  otherIndexListsComponent = () => {
3238
3258
  },
3239
3259
  searchViewMoreResultComponent = () => {
3240
- }
3260
+ },
3261
+ urlSearchResult: urlSearchResult2 = "",
3262
+ query = {}
3241
3263
  }) => {
3242
3264
  setShowInfo(true);
3243
3265
  setHandleFunctions({
@@ -3249,8 +3271,10 @@ const SearchIconWidgetPopup = () => {
3249
3271
  productCardsComponent,
3250
3272
  suggestionKeywordListsComponent,
3251
3273
  otherIndexListsComponent,
3252
- searchViewMoreResultComponent
3274
+ searchViewMoreResultComponent,
3275
+ query
3253
3276
  });
3277
+ setUrlSearchResult(urlSearchResult2);
3254
3278
  };
3255
3279
  }
3256
3280
  handleSettings(localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || null);
@@ -3431,7 +3455,9 @@ const SearchIconWidgetPopup = () => {
3431
3455
  keyword,
3432
3456
  isComponentJsVersion: handleFunctions.isJsVersion,
3433
3457
  showPopupComponent: showInfo,
3434
- setShowPopupComponent: setShowInfo
3458
+ setShowPopupComponent: setShowInfo,
3459
+ urlSearchResult,
3460
+ query: handleFunctions.query
3435
3461
  }
3436
3462
  ) }) : null
3437
3463
  ] })
@@ -3457,7 +3483,7 @@ const SearchResultWidget = (props) => {
3457
3483
  data: propsData,
3458
3484
  sledgeSettings
3459
3485
  } = props;
3460
- const queryKeyword = (query == null ? void 0 : query.keyword) ? query.keyword : "q";
3486
+ const queryKeyword = (query == null ? void 0 : query.keyword) ? query.keyword : DEFAULT_QUERY_PARAM.KEYWORD;
3461
3487
  const { collectionId } = params || {};
3462
3488
  const searchParams = typeof document !== "undefined" ? new URLSearchParams((_a = document == null ? void 0 : document.location) == null ? void 0 : _a.search) : null;
3463
3489
  const [settings] = React__default.useState(typeof localStorage !== "undefined" ? JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || "{}") : {});
@@ -3995,7 +4021,7 @@ const ResultProduct = (props) => {
3995
4021
  data: propsData,
3996
4022
  settings
3997
4023
  } = props || {};
3998
- const queryKeyword = (query == null ? void 0 : query.keyword) ? query.keyword : "q";
4024
+ const queryKeyword = (query == null ? void 0 : query.keyword) ? query.keyword : DEFAULT_QUERY_PARAM.KEYWORD;
3999
4025
  const { collectionId } = params || {};
4000
4026
  const [isFirstLoading, setIsFirstLoading] = React__default.useState(!propsData);
4001
4027
  const [isLoading, setIsLoading] = React__default.useState(!propsData);
@@ -4821,7 +4847,7 @@ const SearchWidget = (props) => {
4821
4847
  var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
4822
4848
  const { isRenderApp, isJsVersion } = React__default.useContext(SledgeContext);
4823
4849
  const { instantSearch: isRenderAppInstantSearch } = isRenderApp || {};
4824
- const { width = "400px", children, onAfterAddToCart, onAfterAddWishlist, onAfterRemoveWishlist, onAfterRenderProduct } = props;
4850
+ const { width = "400px", children, onAfterAddToCart, onAfterAddWishlist, onAfterRemoveWishlist, onAfterRenderProduct, urlSearchResult, query } = props;
4825
4851
  let productCardsComponent = null;
4826
4852
  let suggestionKeywordListsComponent = null;
4827
4853
  let otherIndexListsComponent = null;
@@ -5068,7 +5094,16 @@ const SearchWidget = (props) => {
5068
5094
  ] }) : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__widget-search-form-result-product-disabled", children: "No product were found" })
5069
5095
  ] })
5070
5096
  ] }),
5071
- (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
5097
+ (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(
5098
+ Global.SearchViewMoreResult,
5099
+ {
5100
+ component: searchViewMoreResultComponent,
5101
+ keyword,
5102
+ isComponentJsVersion: isJsVersion,
5103
+ urlSearchResult,
5104
+ query
5105
+ }
5106
+ ) }) : null
5072
5107
  ] }) }) })
5073
5108
  ] });
5074
5109
  };