@sledge-app/react-instant-search 0.0.14 → 0.0.16
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.
- package/dist/components/ProductFilterWidget/ProductFilterWidget.d.ts +1 -0
- package/dist/components/ProductFilterWidget/ProductFilterWidget.d.ts.map +1 -1
- package/dist/components/SearchIconWidget/SearchIconWidget.d.ts +1 -0
- package/dist/components/SearchIconWidget/SearchIconWidget.d.ts.map +1 -1
- package/dist/components/SearchIconWidget/SearchIconWidgetPopup.d.ts +1 -1
- package/dist/components/SearchIconWidget/SearchIconWidgetPopup.d.ts.map +1 -1
- package/dist/components/SearchResultWidget/SearchResultWidget.d.ts +1 -0
- package/dist/components/SearchResultWidget/SearchResultWidget.d.ts.map +1 -1
- package/dist/components/SearchWidget/SearchWidget.d.ts +1 -0
- package/dist/components/SearchWidget/SearchWidget.d.ts.map +1 -1
- package/dist/sledge-react-instant-search.cjs +1 -1
- package/dist/sledge-react-instant-search.cjs.map +1 -1
- package/dist/sledge-react-instant-search.js +90 -37
- package/dist/sledge-react-instant-search.js.map +1 -1
- package/package.json +1 -1
|
@@ -16,6 +16,14 @@ const LOCAL_STORAGE_KEY = {
|
|
|
16
16
|
INSTANT_SEARCH_SETTING: "sledge-instant-search-setting"
|
|
17
17
|
};
|
|
18
18
|
const SEARCH_RESULT_URL = "/pages/search-result";
|
|
19
|
+
const SEPARATE_COMPONENT_DISPLAY_NAME = {
|
|
20
|
+
PRODUCT: {
|
|
21
|
+
CARDS: "ProductCards"
|
|
22
|
+
}
|
|
23
|
+
};
|
|
24
|
+
const SHOPIFY_GID = "gid://shopify/";
|
|
25
|
+
const SHOPIFY_GID_PRODUCT_ID = `${SHOPIFY_GID}Product/`;
|
|
26
|
+
const SHOPIFY_GID_PRODUCT_VARIANT_ID = `${SHOPIFY_GID}ProductVariant/`;
|
|
19
27
|
const sanitizeDataId = (id) => {
|
|
20
28
|
if (!id)
|
|
21
29
|
return "";
|
|
@@ -27,6 +35,7 @@ const sanitizeDataId = (id) => {
|
|
|
27
35
|
return getId;
|
|
28
36
|
}
|
|
29
37
|
};
|
|
38
|
+
const isFunction = (data) => typeof data === "function";
|
|
30
39
|
const SearchIconWidget$1 = "";
|
|
31
40
|
const root = "";
|
|
32
41
|
const Loading = "";
|
|
@@ -606,7 +615,7 @@ const ButtonDetail = "";
|
|
|
606
615
|
const Trigger$1 = "";
|
|
607
616
|
const Trigger = (props) => {
|
|
608
617
|
var _a, _b, _c;
|
|
609
|
-
const { data, forceActive, hidden, onAfterAddWishlist, onAfterRemoveWishlist } = props;
|
|
618
|
+
const { data, forceActive = false, hidden = false, onAfterAddWishlist, onAfterRemoveWishlist } = props;
|
|
610
619
|
const { productId, productVariantId } = data || {};
|
|
611
620
|
const { isRenderApp, triggerRenderMultipleComponent, sledgeAnonymId } = React__default.useContext(SledgeContext);
|
|
612
621
|
const defaultColorIcon = "#767676";
|
|
@@ -629,7 +638,7 @@ const Trigger = (props) => {
|
|
|
629
638
|
const handleCheckWishlist = async () => {
|
|
630
639
|
let response;
|
|
631
640
|
response = await checkWishlist(productId, productVariantId);
|
|
632
|
-
setIsWishlist(response);
|
|
641
|
+
setIsWishlist(forceActive ? forceActive : response);
|
|
633
642
|
};
|
|
634
643
|
const handleClick = async (e) => {
|
|
635
644
|
var _a2, _b2, _c2, _d, _e, _f;
|
|
@@ -1624,16 +1633,19 @@ const addToCartTrigger = async (data) => {
|
|
|
1624
1633
|
return;
|
|
1625
1634
|
});
|
|
1626
1635
|
};
|
|
1627
|
-
const
|
|
1636
|
+
const ProductGrid = ({
|
|
1637
|
+
type,
|
|
1638
|
+
className = "",
|
|
1628
1639
|
data,
|
|
1629
1640
|
setting,
|
|
1630
1641
|
showOptionOutOfStock = false,
|
|
1631
1642
|
triggerPropAdditional,
|
|
1632
1643
|
sourceApp = null,
|
|
1644
|
+
cards,
|
|
1633
1645
|
onAfterAddToCart,
|
|
1634
1646
|
onAfterAddWishlist,
|
|
1635
1647
|
onAfterRemoveWishlist,
|
|
1636
|
-
|
|
1648
|
+
onAfterRenderProduct
|
|
1637
1649
|
}) => {
|
|
1638
1650
|
const {
|
|
1639
1651
|
show_vendor = true,
|
|
@@ -1694,15 +1706,37 @@ const ProductCardComponent = ({
|
|
|
1694
1706
|
}, 1e3);
|
|
1695
1707
|
}
|
|
1696
1708
|
};
|
|
1697
|
-
|
|
1698
|
-
|
|
1709
|
+
React__default.useEffect(() => {
|
|
1710
|
+
onAfterRenderProduct && onAfterRenderProduct("success");
|
|
1711
|
+
}, []);
|
|
1712
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `sledge__product-grid ${className}`, "data-grid-type": type, children: data == null ? void 0 : data.map((item, index) => {
|
|
1699
1713
|
const { product, variants } = item || {};
|
|
1700
1714
|
const { id, title, image, url, vendor = "", currency } = product || {};
|
|
1701
1715
|
const { id: variant_id = "", title: variant_title = "", price = "", sku = "" } = (variants == null ? void 0 : variants.length) ? variants[0] : {};
|
|
1702
|
-
let totalStock = ((_a = variants == null ? void 0 : variants.map(({ inventory_quantity }) => inventory_quantity)) == null ? void 0 : _a.reduce((a, b) => a + b, 0)) || 0;
|
|
1703
1716
|
let isLoadingAddToCart = clickedAddToCartId == variant_id;
|
|
1704
|
-
let isOutOfStock = !
|
|
1705
|
-
return /* @__PURE__ */ jsxRuntimeExports.
|
|
1717
|
+
let isOutOfStock = (variants == null ? void 0 : variants.length) && Object.hasOwn(variants[0], "inventory_quantity") ? !variants[0].inventory_quantity && showOptionOutOfStock : false;
|
|
1718
|
+
return cards ? /* @__PURE__ */ jsxRuntimeExports.jsx(React__default.Fragment, { children: cards({
|
|
1719
|
+
product: {
|
|
1720
|
+
...{
|
|
1721
|
+
...product,
|
|
1722
|
+
...{
|
|
1723
|
+
id: `${SHOPIFY_GID_PRODUCT_ID}${id}`
|
|
1724
|
+
}
|
|
1725
|
+
},
|
|
1726
|
+
...{
|
|
1727
|
+
variants: variants.map((variant, index2) => {
|
|
1728
|
+
const { id: variant_id2, inventory_quantity, ...otherObject } = variant || {};
|
|
1729
|
+
return {
|
|
1730
|
+
...otherObject,
|
|
1731
|
+
...{
|
|
1732
|
+
id: `${SHOPIFY_GID_PRODUCT_VARIANT_ID}${variant_id2}`
|
|
1733
|
+
},
|
|
1734
|
+
is_out_of_stock: Object.hasOwn(variants[index2], "inventory_quantity") ? !inventory_quantity : false
|
|
1735
|
+
};
|
|
1736
|
+
})
|
|
1737
|
+
}
|
|
1738
|
+
}
|
|
1739
|
+
}) }, index) : /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge__product-grid-card", children: [
|
|
1706
1740
|
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge__product-grid-content", children: [
|
|
1707
1741
|
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge__product-grid-card-image", children: [
|
|
1708
1742
|
/* @__PURE__ */ jsxRuntimeExports.jsxs(
|
|
@@ -1759,10 +1793,15 @@ const ProductCardComponent = ({
|
|
|
1759
1793
|
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge__product-grid-card-text", children: [
|
|
1760
1794
|
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: variant_title }),
|
|
1761
1795
|
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1796
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: show_vendor ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
|
|
1797
|
+
"Vendor: ",
|
|
1798
|
+
vendor
|
|
1799
|
+
] }) : null }),
|
|
1800
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: " | " }),
|
|
1801
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: show_sku ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
|
|
1802
|
+
"SKU: ",
|
|
1803
|
+
sku
|
|
1804
|
+
] }) : null })
|
|
1766
1805
|
] })
|
|
1767
1806
|
] }),
|
|
1768
1807
|
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge__product-grid-card-rating", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
@@ -1806,30 +1845,13 @@ const ProductCardComponent = ({
|
|
|
1806
1845
|
fill: "#393D4E"
|
|
1807
1846
|
}
|
|
1808
1847
|
) }),
|
|
1809
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: "Add To Cart" })
|
|
1848
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: language_button_add_to_cart ? language_button_add_to_cart : "Add To Cart" })
|
|
1810
1849
|
] })
|
|
1811
1850
|
}
|
|
1812
1851
|
) }) : null
|
|
1813
1852
|
] }, index);
|
|
1814
1853
|
}) });
|
|
1815
1854
|
};
|
|
1816
|
-
const ProductCards = ({ component, ...otherProps }) => {
|
|
1817
|
-
return /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: component && React__default.isValidElement(component) ? React__default.cloneElement(component, { ...otherProps }) : /* @__PURE__ */ jsxRuntimeExports.jsx(ProductCardComponent, { ...otherProps }) });
|
|
1818
|
-
};
|
|
1819
|
-
const ProductGrid = ({ type, className = "", cards, onAfterRenderProduct, ...otherProps }) => {
|
|
1820
|
-
React__default.useEffect(() => {
|
|
1821
|
-
onAfterRenderProduct && onAfterRenderProduct("success");
|
|
1822
|
-
}, []);
|
|
1823
|
-
return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `sledge__product-grid ${className}`, "data-grid-type": type, children: /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
1824
|
-
ProductCards,
|
|
1825
|
-
{
|
|
1826
|
-
...cards ? {
|
|
1827
|
-
component: cards
|
|
1828
|
-
} : {},
|
|
1829
|
-
...otherProps
|
|
1830
|
-
}
|
|
1831
|
-
) });
|
|
1832
|
-
};
|
|
1833
1855
|
const TextAreaField = "";
|
|
1834
1856
|
const InputField = "";
|
|
1835
1857
|
const CollectionGrid$1 = "";
|
|
@@ -2172,7 +2194,14 @@ const SkeletonLoading = {
|
|
|
2172
2194
|
BlogGrid: SkeletonBlogGrid
|
|
2173
2195
|
};
|
|
2174
2196
|
const SearchIconWidget = (props) => {
|
|
2175
|
-
const { size = "sm", onAfterAddToCart, onAfterAddWishlist, onAfterRemoveWishlist, onAfterRenderProduct } = props || {};
|
|
2197
|
+
const { size = "sm", children, onAfterAddToCart, onAfterAddWishlist, onAfterRemoveWishlist, onAfterRenderProduct } = props || {};
|
|
2198
|
+
let productCardsComponent = null;
|
|
2199
|
+
React__default.Children.map(children, (child) => {
|
|
2200
|
+
if (React__default.isValidElement(child) && isFunction(child.type) && child.type.name === SEPARATE_COMPONENT_DISPLAY_NAME.PRODUCT.CARDS) {
|
|
2201
|
+
const { component } = (child == null ? void 0 : child.props) || {};
|
|
2202
|
+
productCardsComponent = component;
|
|
2203
|
+
}
|
|
2204
|
+
});
|
|
2176
2205
|
const { isRenderApp } = React__default.useContext(SledgeContext);
|
|
2177
2206
|
const [sizing, setSizing] = React__default.useState({
|
|
2178
2207
|
width: 0,
|
|
@@ -2200,7 +2229,7 @@ const SearchIconWidget = (props) => {
|
|
|
2200
2229
|
}, [isRenderApp]);
|
|
2201
2230
|
const handleShowWidget = () => {
|
|
2202
2231
|
if (typeof window !== "undefined" && window.sledgeInstantSearchIconWidgetPopup)
|
|
2203
|
-
window.sledgeInstantSearchIconWidgetPopup(onAfterAddToCart, onAfterAddWishlist, onAfterRemoveWishlist, onAfterRenderProduct);
|
|
2232
|
+
window.sledgeInstantSearchIconWidgetPopup(onAfterAddToCart, onAfterAddWishlist, onAfterRemoveWishlist, onAfterRenderProduct, productCardsComponent);
|
|
2204
2233
|
};
|
|
2205
2234
|
return /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "sledge-instant-search__icon-widget", onClick: handleShowWidget, children: /* @__PURE__ */ jsxRuntimeExports.jsx(SearchIcon, { ...sizing, color: "currentColor" }) });
|
|
2206
2235
|
};
|
|
@@ -2226,7 +2255,8 @@ const SearchIconWidgetPopup = () => {
|
|
|
2226
2255
|
onAfterRemoveWishlist: (state) => {
|
|
2227
2256
|
},
|
|
2228
2257
|
onAfterRenderProduct: (state) => {
|
|
2229
|
-
}
|
|
2258
|
+
},
|
|
2259
|
+
productCardsComponent: null
|
|
2230
2260
|
});
|
|
2231
2261
|
const searchFieldRef = React__default.useRef(null);
|
|
2232
2262
|
const previousState = usePrevious({ keyword });
|
|
@@ -2315,13 +2345,15 @@ const SearchIconWidgetPopup = () => {
|
|
|
2315
2345
|
}, onAfterAddWishlist = () => {
|
|
2316
2346
|
}, onAfterRemoveWishlist = () => {
|
|
2317
2347
|
}, onAfterRenderProduct = () => {
|
|
2348
|
+
}, productCardsComponent = () => {
|
|
2318
2349
|
}) => {
|
|
2319
2350
|
setShowInfo(true);
|
|
2320
2351
|
setHandleFunctions({
|
|
2321
2352
|
onAfterAddToCart,
|
|
2322
2353
|
onAfterAddWishlist,
|
|
2323
2354
|
onAfterRemoveWishlist,
|
|
2324
|
-
onAfterRenderProduct
|
|
2355
|
+
onAfterRenderProduct,
|
|
2356
|
+
productCardsComponent
|
|
2325
2357
|
});
|
|
2326
2358
|
setTimeout(() => {
|
|
2327
2359
|
if (searchFieldRef == null ? void 0 : searchFieldRef.current) {
|
|
@@ -2463,6 +2495,7 @@ const SearchIconWidgetPopup = () => {
|
|
|
2463
2495
|
show_price: (_i = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _i.show_price
|
|
2464
2496
|
},
|
|
2465
2497
|
showOptionOutOfStock: true,
|
|
2498
|
+
cards: handleFunctions.productCardsComponent,
|
|
2466
2499
|
onAfterAddToCart: handleFunctions.onAfterAddToCart,
|
|
2467
2500
|
onAfterAddWishlist: handleFunctions.onAfterAddWishlist,
|
|
2468
2501
|
onAfterRemoveWishlist: handleFunctions.onAfterRemoveWishlist,
|
|
@@ -2503,6 +2536,7 @@ const SearchIconWidgetPopup = () => {
|
|
|
2503
2536
|
show_price: (_q = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _q.show_price
|
|
2504
2537
|
},
|
|
2505
2538
|
showOptionOutOfStock: true,
|
|
2539
|
+
cards: handleFunctions.productCardsComponent,
|
|
2506
2540
|
onAfterAddToCart: handleFunctions.onAfterAddToCart,
|
|
2507
2541
|
onAfterAddWishlist: handleFunctions.onAfterAddWishlist,
|
|
2508
2542
|
onAfterRemoveWishlist: handleFunctions.onAfterRemoveWishlist,
|
|
@@ -2522,9 +2556,16 @@ const SearchIconWidgetPopup = () => {
|
|
|
2522
2556
|
const SearchResultWidget$1 = "";
|
|
2523
2557
|
const SearchResultWidget = (props) => {
|
|
2524
2558
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2525
|
-
const { layoutType = "default", query, data, onAfterAddToCart, onAfterAddWishlist, onAfterRemoveWishlist, onAfterRenderProduct } = props;
|
|
2559
|
+
const { layoutType = "default", query, data, children, onAfterAddToCart, onAfterAddWishlist, onAfterRemoveWishlist, onAfterRenderProduct } = props;
|
|
2526
2560
|
const { keyword: queryKeyword = "" } = query || {};
|
|
2527
2561
|
const { collectionId } = data || {};
|
|
2562
|
+
let productCardsComponent = null;
|
|
2563
|
+
React__default.Children.map(children, (child) => {
|
|
2564
|
+
if (React__default.isValidElement(child) && isFunction(child.type) && child.type.name === SEPARATE_COMPONENT_DISPLAY_NAME.PRODUCT.CARDS) {
|
|
2565
|
+
const { component } = (child == null ? void 0 : child.props) || {};
|
|
2566
|
+
productCardsComponent = component;
|
|
2567
|
+
}
|
|
2568
|
+
});
|
|
2528
2569
|
const { isRenderApp } = React__default.useContext(SledgeContext);
|
|
2529
2570
|
const [isFirstLoading, setIsFirstLoading] = React__default.useState(true);
|
|
2530
2571
|
const [isLoading, setIsLoading] = React__default.useState(true);
|
|
@@ -2990,6 +3031,7 @@ const SearchResultWidget = (props) => {
|
|
|
2990
3031
|
defaultSort,
|
|
2991
3032
|
showOutOfStock,
|
|
2992
3033
|
data,
|
|
3034
|
+
productCardsComponent,
|
|
2993
3035
|
onAfterAddToCart,
|
|
2994
3036
|
onAfterAddWishlist,
|
|
2995
3037
|
onAfterRemoveWishlist,
|
|
@@ -3019,6 +3061,7 @@ const ResultProduct = (props) => {
|
|
|
3019
3061
|
defaultSort,
|
|
3020
3062
|
showOutOfStock,
|
|
3021
3063
|
data,
|
|
3064
|
+
productCardsComponent,
|
|
3022
3065
|
setKeyword,
|
|
3023
3066
|
filterHorizontalSkeleton,
|
|
3024
3067
|
filterVerticalSkeleton,
|
|
@@ -3591,6 +3634,7 @@ const ResultProduct = (props) => {
|
|
|
3591
3634
|
show_sku: (_s = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _s.show_sku,
|
|
3592
3635
|
show_price: (_t = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _t.show_price
|
|
3593
3636
|
},
|
|
3637
|
+
cards: productCardsComponent,
|
|
3594
3638
|
showOptionOutOfStock: true,
|
|
3595
3639
|
onAfterAddToCart,
|
|
3596
3640
|
onAfterAddWishlist,
|
|
@@ -3738,7 +3782,14 @@ const ResultEmpty = (props) => {
|
|
|
3738
3782
|
const SearchWidget$1 = "";
|
|
3739
3783
|
const SearchWidget = (props) => {
|
|
3740
3784
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u;
|
|
3741
|
-
const { width = "400px", onAfterAddToCart, onAfterAddWishlist, onAfterRemoveWishlist, onAfterRenderProduct } = props;
|
|
3785
|
+
const { width = "400px", children, onAfterAddToCart, onAfterAddWishlist, onAfterRemoveWishlist, onAfterRenderProduct } = props;
|
|
3786
|
+
let productCardsComponent = null;
|
|
3787
|
+
React__default.Children.map(children, (child) => {
|
|
3788
|
+
if (React__default.isValidElement(child) && isFunction(child.type) && child.type.name === SEPARATE_COMPONENT_DISPLAY_NAME.PRODUCT.CARDS) {
|
|
3789
|
+
const { component } = (child == null ? void 0 : child.props) || {};
|
|
3790
|
+
productCardsComponent = component;
|
|
3791
|
+
}
|
|
3792
|
+
});
|
|
3742
3793
|
const { isRenderApp } = React__default.useContext(SledgeContext);
|
|
3743
3794
|
const [isLoading, setIsLoading] = React__default.useState(true);
|
|
3744
3795
|
const [keyword, setKeyword] = React__default.useState("");
|
|
@@ -3966,6 +4017,7 @@ const SearchWidget = (props) => {
|
|
|
3966
4017
|
show_price: (_h = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _h.show_price
|
|
3967
4018
|
},
|
|
3968
4019
|
showOptionOutOfStock: true,
|
|
4020
|
+
cards: productCardsComponent,
|
|
3969
4021
|
onAfterAddToCart,
|
|
3970
4022
|
onAfterAddWishlist,
|
|
3971
4023
|
onAfterRemoveWishlist,
|
|
@@ -4007,6 +4059,7 @@ const SearchWidget = (props) => {
|
|
|
4007
4059
|
show_price: (_p = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _p.show_price
|
|
4008
4060
|
},
|
|
4009
4061
|
showOptionOutOfStock: true,
|
|
4062
|
+
cards: productCardsComponent,
|
|
4010
4063
|
onAfterAddToCart,
|
|
4011
4064
|
onAfterAddWishlist,
|
|
4012
4065
|
onAfterRemoveWishlist,
|