@sledge-app/react-instant-search 0.0.14 → 0.0.15
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 +77 -35
- package/dist/sledge-react-instant-search.js.map +1 -1
- package/package.json +1 -1
|
@@ -16,6 +16,11 @@ 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
|
+
};
|
|
19
24
|
const sanitizeDataId = (id) => {
|
|
20
25
|
if (!id)
|
|
21
26
|
return "";
|
|
@@ -27,6 +32,7 @@ const sanitizeDataId = (id) => {
|
|
|
27
32
|
return getId;
|
|
28
33
|
}
|
|
29
34
|
};
|
|
35
|
+
const isFunction = (data) => typeof data === "function";
|
|
30
36
|
const SearchIconWidget$1 = "";
|
|
31
37
|
const root = "";
|
|
32
38
|
const Loading = "";
|
|
@@ -1624,16 +1630,19 @@ const addToCartTrigger = async (data) => {
|
|
|
1624
1630
|
return;
|
|
1625
1631
|
});
|
|
1626
1632
|
};
|
|
1627
|
-
const
|
|
1633
|
+
const ProductGrid = ({
|
|
1634
|
+
type,
|
|
1635
|
+
className = "",
|
|
1628
1636
|
data,
|
|
1629
1637
|
setting,
|
|
1630
1638
|
showOptionOutOfStock = false,
|
|
1631
1639
|
triggerPropAdditional,
|
|
1632
1640
|
sourceApp = null,
|
|
1641
|
+
cards,
|
|
1633
1642
|
onAfterAddToCart,
|
|
1634
1643
|
onAfterAddWishlist,
|
|
1635
1644
|
onAfterRemoveWishlist,
|
|
1636
|
-
|
|
1645
|
+
onAfterRenderProduct
|
|
1637
1646
|
}) => {
|
|
1638
1647
|
const {
|
|
1639
1648
|
show_vendor = true,
|
|
@@ -1694,15 +1703,29 @@ const ProductCardComponent = ({
|
|
|
1694
1703
|
}, 1e3);
|
|
1695
1704
|
}
|
|
1696
1705
|
};
|
|
1697
|
-
|
|
1698
|
-
|
|
1706
|
+
React__default.useEffect(() => {
|
|
1707
|
+
onAfterRenderProduct && onAfterRenderProduct("success");
|
|
1708
|
+
}, []);
|
|
1709
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: `sledge__product-grid ${className}`, "data-grid-type": type, children: data == null ? void 0 : data.map((item, index) => {
|
|
1699
1710
|
const { product, variants } = item || {};
|
|
1700
1711
|
const { id, title, image, url, vendor = "", currency } = product || {};
|
|
1701
1712
|
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
1713
|
let isLoadingAddToCart = clickedAddToCartId == variant_id;
|
|
1704
|
-
let isOutOfStock = !
|
|
1705
|
-
return /* @__PURE__ */ jsxRuntimeExports.
|
|
1714
|
+
let isOutOfStock = (variants == null ? void 0 : variants.length) && Object.hasOwn(variants[0], "inventory_quantity") ? !variants[0].inventory_quantity && showOptionOutOfStock : false;
|
|
1715
|
+
return cards ? /* @__PURE__ */ jsxRuntimeExports.jsx(React__default.Fragment, { children: cards({
|
|
1716
|
+
product: {
|
|
1717
|
+
...product,
|
|
1718
|
+
...{
|
|
1719
|
+
variants: variants.map((variant, index2) => {
|
|
1720
|
+
const { inventory_quantity, ...otherObject } = variant || {};
|
|
1721
|
+
return {
|
|
1722
|
+
...otherObject,
|
|
1723
|
+
is_out_of_stock: Object.hasOwn(variants[index2], "inventory_quantity") ? !inventory_quantity : false
|
|
1724
|
+
};
|
|
1725
|
+
})
|
|
1726
|
+
}
|
|
1727
|
+
}
|
|
1728
|
+
}) }, index) : /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge__product-grid-card", children: [
|
|
1706
1729
|
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge__product-grid-content", children: [
|
|
1707
1730
|
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge__product-grid-card-image", children: [
|
|
1708
1731
|
/* @__PURE__ */ jsxRuntimeExports.jsxs(
|
|
@@ -1759,10 +1782,15 @@ const ProductCardComponent = ({
|
|
|
1759
1782
|
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge__product-grid-card-text", children: [
|
|
1760
1783
|
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { children: variant_title }),
|
|
1761
1784
|
/* @__PURE__ */ jsxRuntimeExports.jsxs("div", { children: [
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1785
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: show_vendor ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
|
|
1786
|
+
"Vendor: ",
|
|
1787
|
+
vendor
|
|
1788
|
+
] }) : null }),
|
|
1789
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: " | " }),
|
|
1790
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: show_sku ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
|
|
1791
|
+
"SKU: ",
|
|
1792
|
+
sku
|
|
1793
|
+
] }) : null })
|
|
1766
1794
|
] })
|
|
1767
1795
|
] }),
|
|
1768
1796
|
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge__product-grid-card-rating", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
@@ -1806,30 +1834,13 @@ const ProductCardComponent = ({
|
|
|
1806
1834
|
fill: "#393D4E"
|
|
1807
1835
|
}
|
|
1808
1836
|
) }),
|
|
1809
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: "Add To Cart" })
|
|
1837
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("span", { children: language_button_add_to_cart ? language_button_add_to_cart : "Add To Cart" })
|
|
1810
1838
|
] })
|
|
1811
1839
|
}
|
|
1812
1840
|
) }) : null
|
|
1813
1841
|
] }, index);
|
|
1814
1842
|
}) });
|
|
1815
1843
|
};
|
|
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
1844
|
const TextAreaField = "";
|
|
1834
1845
|
const InputField = "";
|
|
1835
1846
|
const CollectionGrid$1 = "";
|
|
@@ -2172,7 +2183,14 @@ const SkeletonLoading = {
|
|
|
2172
2183
|
BlogGrid: SkeletonBlogGrid
|
|
2173
2184
|
};
|
|
2174
2185
|
const SearchIconWidget = (props) => {
|
|
2175
|
-
const { size = "sm", onAfterAddToCart, onAfterAddWishlist, onAfterRemoveWishlist, onAfterRenderProduct } = props || {};
|
|
2186
|
+
const { size = "sm", children, onAfterAddToCart, onAfterAddWishlist, onAfterRemoveWishlist, onAfterRenderProduct } = props || {};
|
|
2187
|
+
let productCardsComponent = null;
|
|
2188
|
+
React__default.Children.map(children, (child) => {
|
|
2189
|
+
if (React__default.isValidElement(child) && isFunction(child.type) && child.type.name === SEPARATE_COMPONENT_DISPLAY_NAME.PRODUCT.CARDS) {
|
|
2190
|
+
const { component } = (child == null ? void 0 : child.props) || {};
|
|
2191
|
+
productCardsComponent = component;
|
|
2192
|
+
}
|
|
2193
|
+
});
|
|
2176
2194
|
const { isRenderApp } = React__default.useContext(SledgeContext);
|
|
2177
2195
|
const [sizing, setSizing] = React__default.useState({
|
|
2178
2196
|
width: 0,
|
|
@@ -2200,7 +2218,7 @@ const SearchIconWidget = (props) => {
|
|
|
2200
2218
|
}, [isRenderApp]);
|
|
2201
2219
|
const handleShowWidget = () => {
|
|
2202
2220
|
if (typeof window !== "undefined" && window.sledgeInstantSearchIconWidgetPopup)
|
|
2203
|
-
window.sledgeInstantSearchIconWidgetPopup(onAfterAddToCart, onAfterAddWishlist, onAfterRemoveWishlist, onAfterRenderProduct);
|
|
2221
|
+
window.sledgeInstantSearchIconWidgetPopup(onAfterAddToCart, onAfterAddWishlist, onAfterRemoveWishlist, onAfterRenderProduct, productCardsComponent);
|
|
2204
2222
|
};
|
|
2205
2223
|
return /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "sledge-instant-search__icon-widget", onClick: handleShowWidget, children: /* @__PURE__ */ jsxRuntimeExports.jsx(SearchIcon, { ...sizing, color: "currentColor" }) });
|
|
2206
2224
|
};
|
|
@@ -2226,7 +2244,8 @@ const SearchIconWidgetPopup = () => {
|
|
|
2226
2244
|
onAfterRemoveWishlist: (state) => {
|
|
2227
2245
|
},
|
|
2228
2246
|
onAfterRenderProduct: (state) => {
|
|
2229
|
-
}
|
|
2247
|
+
},
|
|
2248
|
+
productCardsComponent: null
|
|
2230
2249
|
});
|
|
2231
2250
|
const searchFieldRef = React__default.useRef(null);
|
|
2232
2251
|
const previousState = usePrevious({ keyword });
|
|
@@ -2315,13 +2334,15 @@ const SearchIconWidgetPopup = () => {
|
|
|
2315
2334
|
}, onAfterAddWishlist = () => {
|
|
2316
2335
|
}, onAfterRemoveWishlist = () => {
|
|
2317
2336
|
}, onAfterRenderProduct = () => {
|
|
2337
|
+
}, productCardsComponent = () => {
|
|
2318
2338
|
}) => {
|
|
2319
2339
|
setShowInfo(true);
|
|
2320
2340
|
setHandleFunctions({
|
|
2321
2341
|
onAfterAddToCart,
|
|
2322
2342
|
onAfterAddWishlist,
|
|
2323
2343
|
onAfterRemoveWishlist,
|
|
2324
|
-
onAfterRenderProduct
|
|
2344
|
+
onAfterRenderProduct,
|
|
2345
|
+
productCardsComponent
|
|
2325
2346
|
});
|
|
2326
2347
|
setTimeout(() => {
|
|
2327
2348
|
if (searchFieldRef == null ? void 0 : searchFieldRef.current) {
|
|
@@ -2463,6 +2484,7 @@ const SearchIconWidgetPopup = () => {
|
|
|
2463
2484
|
show_price: (_i = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _i.show_price
|
|
2464
2485
|
},
|
|
2465
2486
|
showOptionOutOfStock: true,
|
|
2487
|
+
cards: handleFunctions.productCardsComponent,
|
|
2466
2488
|
onAfterAddToCart: handleFunctions.onAfterAddToCart,
|
|
2467
2489
|
onAfterAddWishlist: handleFunctions.onAfterAddWishlist,
|
|
2468
2490
|
onAfterRemoveWishlist: handleFunctions.onAfterRemoveWishlist,
|
|
@@ -2503,6 +2525,7 @@ const SearchIconWidgetPopup = () => {
|
|
|
2503
2525
|
show_price: (_q = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _q.show_price
|
|
2504
2526
|
},
|
|
2505
2527
|
showOptionOutOfStock: true,
|
|
2528
|
+
cards: handleFunctions.productCardsComponent,
|
|
2506
2529
|
onAfterAddToCart: handleFunctions.onAfterAddToCart,
|
|
2507
2530
|
onAfterAddWishlist: handleFunctions.onAfterAddWishlist,
|
|
2508
2531
|
onAfterRemoveWishlist: handleFunctions.onAfterRemoveWishlist,
|
|
@@ -2522,9 +2545,16 @@ const SearchIconWidgetPopup = () => {
|
|
|
2522
2545
|
const SearchResultWidget$1 = "";
|
|
2523
2546
|
const SearchResultWidget = (props) => {
|
|
2524
2547
|
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
|
|
2525
|
-
const { layoutType = "default", query, data, onAfterAddToCart, onAfterAddWishlist, onAfterRemoveWishlist, onAfterRenderProduct } = props;
|
|
2548
|
+
const { layoutType = "default", query, data, children, onAfterAddToCart, onAfterAddWishlist, onAfterRemoveWishlist, onAfterRenderProduct } = props;
|
|
2526
2549
|
const { keyword: queryKeyword = "" } = query || {};
|
|
2527
2550
|
const { collectionId } = data || {};
|
|
2551
|
+
let productCardsComponent = null;
|
|
2552
|
+
React__default.Children.map(children, (child) => {
|
|
2553
|
+
if (React__default.isValidElement(child) && isFunction(child.type) && child.type.name === SEPARATE_COMPONENT_DISPLAY_NAME.PRODUCT.CARDS) {
|
|
2554
|
+
const { component } = (child == null ? void 0 : child.props) || {};
|
|
2555
|
+
productCardsComponent = component;
|
|
2556
|
+
}
|
|
2557
|
+
});
|
|
2528
2558
|
const { isRenderApp } = React__default.useContext(SledgeContext);
|
|
2529
2559
|
const [isFirstLoading, setIsFirstLoading] = React__default.useState(true);
|
|
2530
2560
|
const [isLoading, setIsLoading] = React__default.useState(true);
|
|
@@ -2990,6 +3020,7 @@ const SearchResultWidget = (props) => {
|
|
|
2990
3020
|
defaultSort,
|
|
2991
3021
|
showOutOfStock,
|
|
2992
3022
|
data,
|
|
3023
|
+
productCardsComponent,
|
|
2993
3024
|
onAfterAddToCart,
|
|
2994
3025
|
onAfterAddWishlist,
|
|
2995
3026
|
onAfterRemoveWishlist,
|
|
@@ -3019,6 +3050,7 @@ const ResultProduct = (props) => {
|
|
|
3019
3050
|
defaultSort,
|
|
3020
3051
|
showOutOfStock,
|
|
3021
3052
|
data,
|
|
3053
|
+
productCardsComponent,
|
|
3022
3054
|
setKeyword,
|
|
3023
3055
|
filterHorizontalSkeleton,
|
|
3024
3056
|
filterVerticalSkeleton,
|
|
@@ -3591,6 +3623,7 @@ const ResultProduct = (props) => {
|
|
|
3591
3623
|
show_sku: (_s = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _s.show_sku,
|
|
3592
3624
|
show_price: (_t = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _t.show_price
|
|
3593
3625
|
},
|
|
3626
|
+
cards: productCardsComponent,
|
|
3594
3627
|
showOptionOutOfStock: true,
|
|
3595
3628
|
onAfterAddToCart,
|
|
3596
3629
|
onAfterAddWishlist,
|
|
@@ -3738,7 +3771,14 @@ const ResultEmpty = (props) => {
|
|
|
3738
3771
|
const SearchWidget$1 = "";
|
|
3739
3772
|
const SearchWidget = (props) => {
|
|
3740
3773
|
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;
|
|
3774
|
+
const { width = "400px", children, onAfterAddToCart, onAfterAddWishlist, onAfterRemoveWishlist, onAfterRenderProduct } = props;
|
|
3775
|
+
let productCardsComponent = null;
|
|
3776
|
+
React__default.Children.map(children, (child) => {
|
|
3777
|
+
if (React__default.isValidElement(child) && isFunction(child.type) && child.type.name === SEPARATE_COMPONENT_DISPLAY_NAME.PRODUCT.CARDS) {
|
|
3778
|
+
const { component } = (child == null ? void 0 : child.props) || {};
|
|
3779
|
+
productCardsComponent = component;
|
|
3780
|
+
}
|
|
3781
|
+
});
|
|
3742
3782
|
const { isRenderApp } = React__default.useContext(SledgeContext);
|
|
3743
3783
|
const [isLoading, setIsLoading] = React__default.useState(true);
|
|
3744
3784
|
const [keyword, setKeyword] = React__default.useState("");
|
|
@@ -3966,6 +4006,7 @@ const SearchWidget = (props) => {
|
|
|
3966
4006
|
show_price: (_h = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _h.show_price
|
|
3967
4007
|
},
|
|
3968
4008
|
showOptionOutOfStock: true,
|
|
4009
|
+
cards: productCardsComponent,
|
|
3969
4010
|
onAfterAddToCart,
|
|
3970
4011
|
onAfterAddWishlist,
|
|
3971
4012
|
onAfterRemoveWishlist,
|
|
@@ -4007,6 +4048,7 @@ const SearchWidget = (props) => {
|
|
|
4007
4048
|
show_price: (_p = displaySettings == null ? void 0 : displaySettings.search) == null ? void 0 : _p.show_price
|
|
4008
4049
|
},
|
|
4009
4050
|
showOptionOutOfStock: true,
|
|
4051
|
+
cards: productCardsComponent,
|
|
4010
4052
|
onAfterAddToCart,
|
|
4011
4053
|
onAfterAddWishlist,
|
|
4012
4054
|
onAfterRemoveWishlist,
|