@sledge-app/react-instant-search 1.0.88 → 1.0.89

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.
@@ -150,6 +150,17 @@ const SELECTOR = {
150
150
  ELEMENT_RELATED_PRODUCTS: `[${SELECTOR_ATTRIBUTE_KEY}="product-recommendation-related-prodcuts"]`
151
151
  }
152
152
  };
153
+ const CUSTOM_EVENT_NAMES = {
154
+ AFTER_ADD_WISHLIST: "after-add-wishlist",
155
+ AFTER_REMOVE_WISHLIST: "after-remove-wishlist",
156
+ AFTER_ADD_TO_CART: "after-add-to-cart",
157
+ AFTER_ADD_REVIEW: "after-add-review",
158
+ AFTER_RENDER_PRODUCT: "after-render-product",
159
+ AFTER_RENDER_COLLECTION: "after-render-collection",
160
+ AFTER_RENDER_PAGE: "after-render-page",
161
+ AFTER_RENDER_BLOG: "after-render-blog",
162
+ AFTER_RENDER_ARTICLE: "after-render-article"
163
+ };
153
164
  const DEFAULT_LIMIT_VALUE = [12, 24, 36, 48, 120];
154
165
  const DEFAULT_MAX_WIDTH_COMPONENT = "1180px";
155
166
  const DEFAULT_SEARCH_RESULT_URL = "/apps/sledge/search";
@@ -510,6 +521,10 @@ const shopifyFormatMoney = (cents, format) => {
510
521
  }
511
522
  return formatString.replace(placeholderRegex, value);
512
523
  };
524
+ const dispatchCustomEvent = (eventName, detail) => {
525
+ const customEvent = new CustomEvent(eventName, { bubbles: true, cancelable: true, composed: false, ...detail && { detail } });
526
+ document.dispatchEvent(customEvent);
527
+ };
513
528
  const root = "";
514
529
  const Loading = "";
515
530
  const ConfirmationPopup = "";
@@ -1671,9 +1686,15 @@ const Trigger = (props) => {
1671
1686
  return;
1672
1687
  }
1673
1688
  let resAddWishlist = await addWishlist(params);
1674
- const { status, data: response_data } = resAddWishlist || {};
1689
+ const { status, data } = resAddWishlist || {};
1675
1690
  const { code } = status || {};
1676
- if (code === 200) {
1691
+ const { product } = data || {};
1692
+ let run = code === 200;
1693
+ dispatchCustomEvent(!isWishlist ? CUSTOM_EVENT_NAMES.AFTER_ADD_WISHLIST : CUSTOM_EVENT_NAMES.AFTER_REMOVE_WISHLIST, {
1694
+ state: run ? "success" : "failed",
1695
+ product
1696
+ });
1697
+ if (run) {
1677
1698
  setIsWishlist(!isWishlist);
1678
1699
  if (triggerRenderWishlistBadge)
1679
1700
  triggerRenderWishlistBadge(true);
@@ -3286,6 +3307,9 @@ const ProductGrid = (props) => {
3286
3307
  carouselSourceWidget: "productGrid"
3287
3308
  } || null;
3288
3309
  React__default.useEffect(() => {
3310
+ dispatchCustomEvent(CUSTOM_EVENT_NAMES.AFTER_RENDER_PRODUCT, {
3311
+ state: "success"
3312
+ });
3289
3313
  onAfterRenderProduct && onAfterRenderProduct("success");
3290
3314
  handleSettings();
3291
3315
  }, []);
@@ -3308,6 +3332,9 @@ const InputField = "";
3308
3332
  const CollectionGrid$1 = "";
3309
3333
  const CollectionGrid = ({ className = "", data, cards: CardsComponent, isComponentJsVersion, onAfterRenderCollection }) => {
3310
3334
  React__default.useEffect(() => {
3335
+ dispatchCustomEvent(CUSTOM_EVENT_NAMES.AFTER_RENDER_COLLECTION, {
3336
+ state: "success"
3337
+ });
3311
3338
  onAfterRenderCollection && onAfterRenderCollection("success");
3312
3339
  }, []);
3313
3340
  return /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: !(data == null ? void 0 : data.length) ? null : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `sledge__collection-grid ${className}`, children: data.map((item, index) => {
@@ -3329,6 +3356,9 @@ const CollectionGrid = ({ className = "", data, cards: CardsComponent, isCompone
3329
3356
  const PageGrid$1 = "";
3330
3357
  const PageGrid = ({ className = "", data, cards: CardsComponent, isComponentJsVersion, onAfterRenderPage }) => {
3331
3358
  React__default.useEffect(() => {
3359
+ dispatchCustomEvent(CUSTOM_EVENT_NAMES.AFTER_RENDER_PAGE, {
3360
+ state: "success"
3361
+ });
3332
3362
  onAfterRenderPage && onAfterRenderPage("success");
3333
3363
  }, []);
3334
3364
  return /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: !(data == null ? void 0 : data.length) ? null : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `sledge__page-grid ${className}`, children: data.map((item, index) => {
@@ -3350,6 +3380,9 @@ const PageGrid = ({ className = "", data, cards: CardsComponent, isComponentJsVe
3350
3380
  const BlogGrid$1 = "";
3351
3381
  const BlogGrid = ({ className = "", data, cards: CardsComponent, isComponentJsVersion, onAfterRenderBlog }) => {
3352
3382
  React__default.useEffect(() => {
3383
+ dispatchCustomEvent(CUSTOM_EVENT_NAMES.AFTER_RENDER_BLOG, {
3384
+ state: "success"
3385
+ });
3353
3386
  onAfterRenderBlog && onAfterRenderBlog("success");
3354
3387
  }, []);
3355
3388
  return /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: !(data == null ? void 0 : data.length) ? null : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `sledge__blog-grid ${className}`, children: data == null ? void 0 : data.map((item, index) => {
@@ -3377,6 +3410,9 @@ const BlogGrid = ({ className = "", data, cards: CardsComponent, isComponentJsVe
3377
3410
  const ArticleGrid$1 = "";
3378
3411
  const ArticleGrid = ({ className = "", data, cards: CardsComponent, isComponentJsVersion, onAfterRenderArticle }) => {
3379
3412
  React__default.useEffect(() => {
3413
+ dispatchCustomEvent(CUSTOM_EVENT_NAMES.AFTER_RENDER_ARTICLE, {
3414
+ state: "success"
3415
+ });
3380
3416
  onAfterRenderArticle && onAfterRenderArticle("success");
3381
3417
  }, []);
3382
3418
  return /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: !(data == null ? void 0 : data.length) ? null : /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `sledge__article-grid ${className}`, children: data == null ? void 0 : data.map((item, index) => {