@sledge-app/react-instant-search 0.0.111 → 0.0.113
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/ProductFilterWidgetInitSelector.d.ts.map +1 -1
- package/dist/components/SearchIconWidget/SearchIconWidgetInitSelector.d.ts.map +1 -1
- package/dist/components/SearchIconWidget/SearchIconWidgetPopup.d.ts.map +1 -1
- package/dist/components/SearchResultWidget/SearchResultWidgetInitSelector.d.ts.map +1 -1
- package/dist/components/SearchWidget/SearchWidgetInitSelector.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 +121 -25
- package/dist/sledge-react-instant-search.js.map +1 -1
- package/dist/style.css +1 -1
- package/package.json +1 -1
|
@@ -166,7 +166,8 @@ const sanitizeDataId = (id) => {
|
|
|
166
166
|
return getId;
|
|
167
167
|
}
|
|
168
168
|
};
|
|
169
|
-
const detectInitSelector = (
|
|
169
|
+
const detectInitSelector = (params) => {
|
|
170
|
+
const { element, init, reRender = false } = params;
|
|
170
171
|
let hasRunning = false;
|
|
171
172
|
if (!reRender) {
|
|
172
173
|
document.body.addEventListener("DOMNodeInserted", () => {
|
|
@@ -181,7 +182,8 @@ const detectInitSelector = (element, init, reRender) => {
|
|
|
181
182
|
}
|
|
182
183
|
};
|
|
183
184
|
const isFunction = (data) => typeof data === "function";
|
|
184
|
-
const scrollToElement = (
|
|
185
|
+
const scrollToElement = (params) => {
|
|
186
|
+
const { element, headerOffset } = params;
|
|
185
187
|
if (!element)
|
|
186
188
|
return;
|
|
187
189
|
var elementPosition = element == null ? void 0 : element.getBoundingClientRect().top;
|
|
@@ -191,7 +193,8 @@ const scrollToElement = (element, headerOffset) => {
|
|
|
191
193
|
behavior: "smooth"
|
|
192
194
|
});
|
|
193
195
|
};
|
|
194
|
-
const fetchApi = async (
|
|
196
|
+
const fetchApi = async (params) => {
|
|
197
|
+
const { url, method, authorization = "", payload = {}, headers = {}, isSimpleRequest = true, isUploadFile = false } = params;
|
|
195
198
|
var myHeaders = new Headers();
|
|
196
199
|
if (!isSimpleRequest) {
|
|
197
200
|
if (authorization)
|
|
@@ -757,7 +760,13 @@ const addToCart = async (data) => {
|
|
|
757
760
|
let payload = {
|
|
758
761
|
items
|
|
759
762
|
};
|
|
760
|
-
return await fetchApi(
|
|
763
|
+
return await fetchApi({
|
|
764
|
+
url,
|
|
765
|
+
method: "POST",
|
|
766
|
+
payload,
|
|
767
|
+
headers,
|
|
768
|
+
isSimpleRequest: false
|
|
769
|
+
}).then((result) => {
|
|
761
770
|
return result;
|
|
762
771
|
}).catch(() => {
|
|
763
772
|
return;
|
|
@@ -888,7 +897,12 @@ const addWishlist = async (data) => {
|
|
|
888
897
|
price: productPrice
|
|
889
898
|
})
|
|
890
899
|
};
|
|
891
|
-
return await fetchApi(
|
|
900
|
+
return await fetchApi({
|
|
901
|
+
url,
|
|
902
|
+
method: "POST",
|
|
903
|
+
authorization: sledgeAuthApp,
|
|
904
|
+
payload
|
|
905
|
+
}).then((result) => {
|
|
892
906
|
return result;
|
|
893
907
|
}).catch(() => {
|
|
894
908
|
return;
|
|
@@ -916,7 +930,14 @@ const bulkAddWishlist = async (data) => {
|
|
|
916
930
|
let payload = {
|
|
917
931
|
products
|
|
918
932
|
};
|
|
919
|
-
return await fetchApi(
|
|
933
|
+
return await fetchApi({
|
|
934
|
+
url,
|
|
935
|
+
method: "POST",
|
|
936
|
+
authorization: sledgeAuthApp,
|
|
937
|
+
payload,
|
|
938
|
+
headers,
|
|
939
|
+
isSimpleRequest: false
|
|
940
|
+
}).then((result) => {
|
|
920
941
|
return result;
|
|
921
942
|
}).catch(() => {
|
|
922
943
|
return;
|
|
@@ -925,7 +946,11 @@ const bulkAddWishlist = async (data) => {
|
|
|
925
946
|
const getWishlistInfo = async (token) => {
|
|
926
947
|
let sledgeAuthApp = token ? token : typeof localStorage !== "undefined" ? localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP) || "" : "";
|
|
927
948
|
let url = `${API_URL}/wishlist/info`;
|
|
928
|
-
return await fetchApi(
|
|
949
|
+
return await fetchApi({
|
|
950
|
+
url,
|
|
951
|
+
method: "GET",
|
|
952
|
+
authorization: sledgeAuthApp
|
|
953
|
+
}).then((result) => {
|
|
929
954
|
return result;
|
|
930
955
|
}).catch(() => {
|
|
931
956
|
return;
|
|
@@ -939,7 +964,11 @@ const checkWishlist = async (id, variantId) => {
|
|
|
939
964
|
variant_id: convertVariantId
|
|
940
965
|
}).toString();
|
|
941
966
|
let url = `${API_URL}/wishlist/check/${convertId}${queryParams}`;
|
|
942
|
-
return await fetchApi(
|
|
967
|
+
return await fetchApi({
|
|
968
|
+
url,
|
|
969
|
+
method: "GET",
|
|
970
|
+
authorization: sledgeAuthApp
|
|
971
|
+
}).then((result) => {
|
|
943
972
|
return Boolean(result.data);
|
|
944
973
|
}).catch(() => {
|
|
945
974
|
return;
|
|
@@ -949,10 +978,16 @@ const addToCartTrigger$1 = async (data) => {
|
|
|
949
978
|
const { productId } = data;
|
|
950
979
|
let sledgeAuthApp = typeof localStorage !== "undefined" ? localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP) || "" : "";
|
|
951
980
|
let url = `${API_URL}/wishlist/cart`;
|
|
952
|
-
|
|
981
|
+
let payload = {
|
|
953
982
|
product: JSON.stringify({
|
|
954
983
|
id: sanitizeDataId(productId)
|
|
955
984
|
})
|
|
985
|
+
};
|
|
986
|
+
return await fetchApi({
|
|
987
|
+
url,
|
|
988
|
+
method: "POST",
|
|
989
|
+
authorization: sledgeAuthApp,
|
|
990
|
+
payload
|
|
956
991
|
}).then((result) => {
|
|
957
992
|
return result;
|
|
958
993
|
}).catch(() => {
|
|
@@ -1078,9 +1113,9 @@ const BadgeInitSelector = (reRender = false) => {
|
|
|
1078
1113
|
}
|
|
1079
1114
|
} else {
|
|
1080
1115
|
let element = Array.from(document.querySelectorAll(SELECTOR.WISHLIST.ELEMENT_BADGE));
|
|
1081
|
-
detectInitSelector(
|
|
1116
|
+
detectInitSelector({
|
|
1082
1117
|
element,
|
|
1083
|
-
() => {
|
|
1118
|
+
init: () => {
|
|
1084
1119
|
if (element.length) {
|
|
1085
1120
|
element.map((item) => {
|
|
1086
1121
|
if (item) {
|
|
@@ -1112,7 +1147,7 @@ const BadgeInitSelector = (reRender = false) => {
|
|
|
1112
1147
|
}
|
|
1113
1148
|
},
|
|
1114
1149
|
reRender
|
|
1115
|
-
);
|
|
1150
|
+
});
|
|
1116
1151
|
}
|
|
1117
1152
|
};
|
|
1118
1153
|
const Trigger = (props) => {
|
|
@@ -1647,7 +1682,12 @@ const getReviewInfo = async (id) => {
|
|
|
1647
1682
|
let convertId = sanitizeDataId(id);
|
|
1648
1683
|
let sledgeAuthApp = typeof localStorage !== "undefined" ? localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP) || "" : "";
|
|
1649
1684
|
let url = `${API_URL}/review/info/${convertId}?${PAYLOAD_API_ALIASES.Authorization}=${sledgeAuthApp}`;
|
|
1650
|
-
return await fetchApi(
|
|
1685
|
+
return await fetchApi({
|
|
1686
|
+
url,
|
|
1687
|
+
method: "GET",
|
|
1688
|
+
authorization: sledgeAuthApp,
|
|
1689
|
+
isSimpleRequest: false
|
|
1690
|
+
}).then((result) => {
|
|
1651
1691
|
return result;
|
|
1652
1692
|
}).catch(() => {
|
|
1653
1693
|
return;
|
|
@@ -1657,7 +1697,12 @@ const getProductsReviewInfo = async (ids, token) => {
|
|
|
1657
1697
|
let convertIds = ids.map((v) => sanitizeDataId(v));
|
|
1658
1698
|
let sledgeAuthApp = token ? token : typeof localStorage !== "undefined" ? (localStorage == null ? void 0 : localStorage.getItem(LOCAL_STORAGE_KEY.AUTH_APP)) || "" : "";
|
|
1659
1699
|
let url = `${API_URL}/review/info/ids/${convertIds.join(",")}?${PAYLOAD_API_ALIASES.Authorization}=${sledgeAuthApp}`;
|
|
1660
|
-
return await fetchApi(
|
|
1700
|
+
return await fetchApi({
|
|
1701
|
+
url,
|
|
1702
|
+
method: "GET",
|
|
1703
|
+
authorization: sledgeAuthApp,
|
|
1704
|
+
isSimpleRequest: false
|
|
1705
|
+
}).then((result) => {
|
|
1661
1706
|
return result;
|
|
1662
1707
|
}).catch(() => {
|
|
1663
1708
|
return;
|
|
@@ -1737,7 +1782,10 @@ const Rating = (props) => {
|
|
|
1737
1782
|
if (!isScrollToElementWidget)
|
|
1738
1783
|
return;
|
|
1739
1784
|
setTimeout(() => {
|
|
1740
|
-
scrollToElement(
|
|
1785
|
+
scrollToElement({
|
|
1786
|
+
element: document.getElementById(ELEMENT_ID.PRODUCT_REVIEW.ELEMENT_WIDGET),
|
|
1787
|
+
headerOffset: 50
|
|
1788
|
+
});
|
|
1741
1789
|
}, 200);
|
|
1742
1790
|
};
|
|
1743
1791
|
React__default.useEffect(() => {
|
|
@@ -2093,7 +2141,14 @@ const search = async (index, payload) => {
|
|
|
2093
2141
|
let headers = {
|
|
2094
2142
|
"Content-Type": "application/json"
|
|
2095
2143
|
};
|
|
2096
|
-
return await fetchApi(
|
|
2144
|
+
return await fetchApi({
|
|
2145
|
+
url,
|
|
2146
|
+
method: "POST",
|
|
2147
|
+
authorization: sledgeInstantSearchAuthApp,
|
|
2148
|
+
payload,
|
|
2149
|
+
headers,
|
|
2150
|
+
isSimpleRequest: false
|
|
2151
|
+
}).then((result) => result).catch(() => {
|
|
2097
2152
|
return;
|
|
2098
2153
|
});
|
|
2099
2154
|
};
|
|
@@ -2103,7 +2158,14 @@ const multiSearch = async (payload, token) => {
|
|
|
2103
2158
|
let headers = {
|
|
2104
2159
|
"Content-Type": "application/json"
|
|
2105
2160
|
};
|
|
2106
|
-
return await fetchApi(
|
|
2161
|
+
return await fetchApi({
|
|
2162
|
+
url,
|
|
2163
|
+
method: "POST",
|
|
2164
|
+
authorization: sledgeInstantSearchAuthApp,
|
|
2165
|
+
payload,
|
|
2166
|
+
headers,
|
|
2167
|
+
isSimpleRequest: false
|
|
2168
|
+
}).then((result) => result).catch(() => {
|
|
2107
2169
|
return;
|
|
2108
2170
|
});
|
|
2109
2171
|
};
|
|
@@ -2118,7 +2180,14 @@ const searchTrigger = async (data) => {
|
|
|
2118
2180
|
keyword,
|
|
2119
2181
|
result_count: resultCount
|
|
2120
2182
|
};
|
|
2121
|
-
return await fetchApi(
|
|
2183
|
+
return await fetchApi({
|
|
2184
|
+
url,
|
|
2185
|
+
method: "POST",
|
|
2186
|
+
authorization: sledgeAuthApp,
|
|
2187
|
+
payload,
|
|
2188
|
+
headers,
|
|
2189
|
+
isSimpleRequest: false
|
|
2190
|
+
}).then((result) => {
|
|
2122
2191
|
return result;
|
|
2123
2192
|
}).catch(() => {
|
|
2124
2193
|
return;
|
|
@@ -2136,7 +2205,14 @@ const productClickTrigger = async (data) => {
|
|
|
2136
2205
|
id: sanitizeDataId(productId)
|
|
2137
2206
|
}
|
|
2138
2207
|
};
|
|
2139
|
-
return await fetchApi(
|
|
2208
|
+
return await fetchApi({
|
|
2209
|
+
url,
|
|
2210
|
+
method: "POST",
|
|
2211
|
+
authorization: sledgeAuthApp,
|
|
2212
|
+
payload,
|
|
2213
|
+
headers,
|
|
2214
|
+
isSimpleRequest: false
|
|
2215
|
+
}).then((result) => {
|
|
2140
2216
|
return result;
|
|
2141
2217
|
}).catch(() => {
|
|
2142
2218
|
return;
|
|
@@ -2154,7 +2230,14 @@ const addToCartTrigger = async (data) => {
|
|
|
2154
2230
|
id: sanitizeDataId(productId)
|
|
2155
2231
|
}
|
|
2156
2232
|
};
|
|
2157
|
-
return await fetchApi(
|
|
2233
|
+
return await fetchApi({
|
|
2234
|
+
url,
|
|
2235
|
+
method: "POST",
|
|
2236
|
+
authorization: sledgeAuthApp,
|
|
2237
|
+
payload,
|
|
2238
|
+
headers,
|
|
2239
|
+
isSimpleRequest: false
|
|
2240
|
+
}).then((result) => {
|
|
2158
2241
|
return result;
|
|
2159
2242
|
}).catch(() => {
|
|
2160
2243
|
return;
|
|
@@ -2857,8 +2940,9 @@ const SearchIconWidgetPopup = () => {
|
|
|
2857
2940
|
});
|
|
2858
2941
|
const searchFieldRef = React__default.useRef(null);
|
|
2859
2942
|
const previousState = usePrevious({ keyword });
|
|
2860
|
-
const handleMultiSearch = async (
|
|
2943
|
+
const handleMultiSearch = async (params) => {
|
|
2861
2944
|
var _a2, _b2, _c2, _d2, _e2, _f2, _g2, _h2, _i2, _j2, _k2, _l2;
|
|
2945
|
+
const { data, onSearch = false, withFetchReviewInfo = false } = params;
|
|
2862
2946
|
setIsLoading(true);
|
|
2863
2947
|
const { tabs, suffix_index_product, hidden_tags, display, show_out_of_stock } = data;
|
|
2864
2948
|
const suggestion = ((_a2 = display == null ? void 0 : display.search) == null ? void 0 : _a2.suggestion) || {};
|
|
@@ -2929,7 +3013,10 @@ const SearchIconWidgetPopup = () => {
|
|
|
2929
3013
|
const { display } = response;
|
|
2930
3014
|
setDisplaySettings(display);
|
|
2931
3015
|
setSuggestionSettings((_a2 = display == null ? void 0 : display.search) == null ? void 0 : _a2.suggestion);
|
|
2932
|
-
await handleMultiSearch(
|
|
3016
|
+
await handleMultiSearch({
|
|
3017
|
+
data: response,
|
|
3018
|
+
withFetchReviewInfo: true
|
|
3019
|
+
});
|
|
2933
3020
|
};
|
|
2934
3021
|
React__default.useEffect(() => {
|
|
2935
3022
|
if (!isRenderAppInstantSearch)
|
|
@@ -2978,7 +3065,10 @@ const SearchIconWidgetPopup = () => {
|
|
|
2978
3065
|
const INSTANT_SEARCH_SETTING = JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || "");
|
|
2979
3066
|
const delayDebounceFn = setTimeout(() => {
|
|
2980
3067
|
if (INSTANT_SEARCH_SETTING)
|
|
2981
|
-
handleMultiSearch(
|
|
3068
|
+
handleMultiSearch({
|
|
3069
|
+
data: INSTANT_SEARCH_SETTING,
|
|
3070
|
+
onSearch: true
|
|
3071
|
+
});
|
|
2982
3072
|
}, 500);
|
|
2983
3073
|
return () => clearTimeout(delayDebounceFn);
|
|
2984
3074
|
}
|
|
@@ -3984,7 +4074,10 @@ const ResultProduct = (props) => {
|
|
|
3984
4074
|
const handlePageChange = (page) => {
|
|
3985
4075
|
setCurrentPage(page);
|
|
3986
4076
|
setTimeout(() => {
|
|
3987
|
-
scrollToElement(
|
|
4077
|
+
scrollToElement({
|
|
4078
|
+
element: searchResultContainerRef.current,
|
|
4079
|
+
headerOffset: 50
|
|
4080
|
+
});
|
|
3988
4081
|
}, 200);
|
|
3989
4082
|
};
|
|
3990
4083
|
const handleChangeKeyword = (value) => {
|
|
@@ -4419,7 +4512,10 @@ const ResultCategory = (props) => {
|
|
|
4419
4512
|
const handlePageChange = (page) => {
|
|
4420
4513
|
setCurrentPage(page);
|
|
4421
4514
|
setTimeout(() => {
|
|
4422
|
-
scrollToElement(
|
|
4515
|
+
scrollToElement({
|
|
4516
|
+
element: searchResultContainerRef.current,
|
|
4517
|
+
headerOffset: 50
|
|
4518
|
+
});
|
|
4423
4519
|
}, 200);
|
|
4424
4520
|
};
|
|
4425
4521
|
React__default.useEffect(() => {
|