@sledge-app/react-instant-search 2.0.37 → 2.0.39
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/SearchResultWidget/utils.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 +96 -42
- package/dist/sledge-react-instant-search.js.map +1 -1
- package/package.json +1 -1
|
@@ -4430,7 +4430,7 @@ ${selectedOption === item ? "sledge__product-variant-size-swatch-active" : ""} s
|
|
|
4430
4430
|
] });
|
|
4431
4431
|
};
|
|
4432
4432
|
const ProductCard = React__default.memo((props) => {
|
|
4433
|
-
var _a, _b, _c, _d, _e, _f, _g, _h
|
|
4433
|
+
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
4434
4434
|
const {
|
|
4435
4435
|
item,
|
|
4436
4436
|
handleAddToCart,
|
|
@@ -4477,8 +4477,6 @@ const ProductCard = React__default.memo((props) => {
|
|
|
4477
4477
|
sku = ""
|
|
4478
4478
|
} = (variants == null ? void 0 : variants.length) ? variants[0] : {};
|
|
4479
4479
|
const productUrl = `${url}?variant=${(_a = variants == null ? void 0 : variants[0]) == null ? void 0 : _a.id}`;
|
|
4480
|
-
const searchParams = new URLSearchParams(document.location.search);
|
|
4481
|
-
const searchParamsObject = Object.fromEntries(searchParams);
|
|
4482
4480
|
const defaultSelectedVariantId = variant_admin_graphql_api_id ? variant_admin_graphql_api_id : "";
|
|
4483
4481
|
const defaultSelectedVariantStock = (variants == null ? void 0 : variants.length) && Object.hasOwn(variants[0], "inventory_quantity") ? variants[0].inventory_quantity : 0;
|
|
4484
4482
|
const defaultSelectedVariantInventoryManagement = (variants == null ? void 0 : variants.length) && Object.hasOwn(variants[0], "inventory_management") ? variants[0].inventory_management : null;
|
|
@@ -4506,14 +4504,6 @@ const ProductCard = React__default.memo((props) => {
|
|
|
4506
4504
|
const { money_format } = generalDataSettings || {};
|
|
4507
4505
|
const { forLoopIndex, forLoopIndexWithPage } = additionalCardProps || {};
|
|
4508
4506
|
let component = null;
|
|
4509
|
-
const isSplitProducts = Boolean((_b = instantSearchSettings == null ? void 0 : instantSearchSettings.split_products) == null ? void 0 : _b.enable);
|
|
4510
|
-
const bySplitProducts = (_c = instantSearchSettings == null ? void 0 : instantSearchSettings.split_products) == null ? void 0 : _c.by;
|
|
4511
|
-
const optionsFiltered = bySplitProducts ? (_g = (_f = (_e = (_d = searchParamsObject == null ? void 0 : searchParamsObject[`options.${bySplitProducts}`]) == null ? void 0 : _d.split) == null ? void 0 : _e.call(_d, ",")) == null ? void 0 : _f.map) == null ? void 0 : _g.call(_f, (item2) => decodeURIComponent(item2)) : [];
|
|
4512
|
-
const hasOptionsFiltered = (optionsFiltered == null ? void 0 : optionsFiltered.length) ? !((_h = optionsFiltered == null ? void 0 : optionsFiltered.includes) == null ? void 0 : _h.call(optionsFiltered, optionSelectedValue)) : false;
|
|
4513
|
-
const isOptionNotContainsKeyword = (keyword == null ? void 0 : keyword.length) ? !(optionSelectedValue == null ? void 0 : optionSelectedValue.length) ? true : !optionSelectedValue.toLowerCase().includes(keyword.toLowerCase()) : false;
|
|
4514
|
-
if (isSplitProducts && (hasOptionsFiltered || isOptionNotContainsKeyword)) {
|
|
4515
|
-
return /* @__PURE__ */ jsxRuntimeExports.jsx(React__default.Fragment, { children: component }, id);
|
|
4516
|
-
}
|
|
4517
4507
|
if (CardsComponent) {
|
|
4518
4508
|
const CardsProps = {
|
|
4519
4509
|
product: {
|
|
@@ -4531,8 +4521,8 @@ const ProductCard = React__default.memo((props) => {
|
|
|
4531
4521
|
},
|
|
4532
4522
|
...dataReviews && Object.keys(dataReviews).length ? {
|
|
4533
4523
|
review: {
|
|
4534
|
-
total: ((
|
|
4535
|
-
average: ((
|
|
4524
|
+
total: ((_b = dataReviews == null ? void 0 : dataReviews[id]) == null ? void 0 : _b.review_count) ? dataReviews == null ? void 0 : dataReviews[id].review_count : 0,
|
|
4525
|
+
average: ((_d = (_c = dataReviews == null ? void 0 : dataReviews[id]) == null ? void 0 : _c.rating) == null ? void 0 : _d.average) ? dataReviews == null ? void 0 : dataReviews[id].rating.average : 0
|
|
4536
4526
|
}
|
|
4537
4527
|
} : {}
|
|
4538
4528
|
},
|
|
@@ -4713,7 +4703,7 @@ const ProductCard = React__default.memo((props) => {
|
|
|
4713
4703
|
onAfterAddWishlist,
|
|
4714
4704
|
onAfterRemoveWishlist,
|
|
4715
4705
|
wishlistChecked: dataWishlists == null ? void 0 : dataWishlists[id],
|
|
4716
|
-
...objectPresent(previewSettings) && ((
|
|
4706
|
+
...objectPresent(previewSettings) && ((_f = (_e = previewSettings == null ? void 0 : previewSettings.settings) == null ? void 0 : _e.general) == null ? void 0 : _f.use_dummy_data) ? {
|
|
4717
4707
|
previewSettings
|
|
4718
4708
|
} : {}
|
|
4719
4709
|
}
|
|
@@ -4749,7 +4739,7 @@ const ProductCard = React__default.memo((props) => {
|
|
|
4749
4739
|
}
|
|
4750
4740
|
)
|
|
4751
4741
|
] }),
|
|
4752
|
-
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge__product-grid-card-variant-images", children: (
|
|
4742
|
+
/* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge__product-grid-card-variant-images", children: (_h = (_g = product == null ? void 0 : product.images) == null ? void 0 : _g.map) == null ? void 0 : _h.call(_g, (image2) => /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
4753
4743
|
"img",
|
|
4754
4744
|
{
|
|
4755
4745
|
decoding: "async",
|
|
@@ -4993,10 +4983,9 @@ const ProductGrid = React__default.memo((props) => {
|
|
|
4993
4983
|
"data-custom-card": Boolean(props == null ? void 0 : props.cards),
|
|
4994
4984
|
"data-flyout": isFlyout,
|
|
4995
4985
|
children: data == null ? void 0 : data.map((item, index) => {
|
|
4996
|
-
var _a, _b, _c
|
|
4986
|
+
var _a, _b, _c;
|
|
4997
4987
|
const isSplitProducts = Boolean((_a = instantSearchSettings == null ? void 0 : instantSearchSettings.split_products) == null ? void 0 : _a.enable);
|
|
4998
|
-
const
|
|
4999
|
-
const optionFirstValues = (optionFirst == null ? void 0 : optionFirst.length) ? optionFirst : [];
|
|
4988
|
+
const bySplitProducts = (_b = instantSearchSettings == null ? void 0 : instantSearchSettings.split_products) == null ? void 0 : _b.by;
|
|
5000
4989
|
const productCardProps = {
|
|
5001
4990
|
item,
|
|
5002
4991
|
handleAddToCart,
|
|
@@ -5007,9 +4996,12 @@ const ProductGrid = React__default.memo((props) => {
|
|
|
5007
4996
|
forLoopIndexWithPage: Number(currentPage) && Number(hitsPerPage) ? index + (Number(currentPage) - 1) * Number(hitsPerPage) : index
|
|
5008
4997
|
},
|
|
5009
4998
|
instantSearchSettings,
|
|
4999
|
+
...isSplitProducts && bySplitProducts ? {
|
|
5000
|
+
optionSelectedValue: (_c = item == null ? void 0 : item.product) == null ? void 0 : _c.optionSelectedValue
|
|
5001
|
+
} : {},
|
|
5010
5002
|
...props
|
|
5011
5003
|
};
|
|
5012
|
-
return /* @__PURE__ */ jsxRuntimeExports.jsx(
|
|
5004
|
+
return /* @__PURE__ */ jsxRuntimeExports.jsx(ProductCard, { ...productCardProps }, `sledge-product-card_${index}`);
|
|
5013
5005
|
})
|
|
5014
5006
|
}
|
|
5015
5007
|
);
|
|
@@ -6346,10 +6338,10 @@ const detectQueryStringFilter = ({ facets, facetsQueryStringObject, callback })
|
|
|
6346
6338
|
const searchParamsObject = Object.fromEntries(searchParams);
|
|
6347
6339
|
for (const searchParamsKey in searchParamsObject) {
|
|
6348
6340
|
let ifFacetsQueryStringObject = (facets == null ? void 0 : facets.length) && facets.includes(searchParamsKey);
|
|
6349
|
-
if (ifFacetsQueryStringObject)
|
|
6341
|
+
if (ifFacetsQueryStringObject && typeof facetsQueryStringObject === "object")
|
|
6350
6342
|
facetsQueryStringObject[searchParamsKey] = (_b = (_a = searchParamsObject[searchParamsKey].split(",")) == null ? void 0 : _a.map) == null ? void 0 : _b.call(_a, (item) => decodeURIComponent(item));
|
|
6351
6343
|
}
|
|
6352
|
-
if (Object.keys(facetsQueryStringObject).length)
|
|
6344
|
+
if (facetsQueryStringObject && Object.keys(facetsQueryStringObject).length)
|
|
6353
6345
|
callback(facetsQueryStringObject);
|
|
6354
6346
|
return facetsQueryStringObject;
|
|
6355
6347
|
};
|
|
@@ -6366,19 +6358,21 @@ const detectArrFacetHierarchical = ({
|
|
|
6366
6358
|
}
|
|
6367
6359
|
return { ...item, [key]: defaultLevelHierarchical };
|
|
6368
6360
|
}, {});
|
|
6369
|
-
Object.
|
|
6370
|
-
|
|
6371
|
-
|
|
6372
|
-
|
|
6373
|
-
|
|
6374
|
-
|
|
6375
|
-
|
|
6376
|
-
|
|
6377
|
-
|
|
6378
|
-
facetHierarchical[facet[0]]
|
|
6379
|
-
|
|
6380
|
-
|
|
6381
|
-
|
|
6361
|
+
if (clickedFacetsObject && Object.keys(clickedFacetsObject).length) {
|
|
6362
|
+
Object.entries(clickedFacetsObject).map((facet) => {
|
|
6363
|
+
var _a, _b;
|
|
6364
|
+
if ((facet == null ? void 0 : facet.length) && facet[1].length) {
|
|
6365
|
+
const isCollection = (_a = String(facet[0])) == null ? void 0 : _a.includes(HIERARCHICAL_FACET_OBJECT_ALIASES.collections);
|
|
6366
|
+
let isHierarchical = hierarchicalFacetAliases == null ? void 0 : hierarchicalFacetAliases.includes(facet[0]);
|
|
6367
|
+
if (isHierarchical)
|
|
6368
|
+
(_b = facet[1]) == null ? void 0 : _b.map((item) => {
|
|
6369
|
+
const arrItem = String(item).split(isCollection ? separatorCollection : separator);
|
|
6370
|
+
if ((arrItem == null ? void 0 : arrItem.length) && Object.hasOwn(facetHierarchical[facet[0]], `lvl${arrItem.length - 1}`))
|
|
6371
|
+
facetHierarchical[facet[0]][`lvl${arrItem.length - 1}`].push(item);
|
|
6372
|
+
});
|
|
6373
|
+
}
|
|
6374
|
+
});
|
|
6375
|
+
}
|
|
6382
6376
|
return facetHierarchical;
|
|
6383
6377
|
};
|
|
6384
6378
|
const createQueryFilter = ({
|
|
@@ -6405,7 +6399,7 @@ const createQueryFilter = ({
|
|
|
6405
6399
|
separatorCollection,
|
|
6406
6400
|
hierarchicalFacetAliases
|
|
6407
6401
|
});
|
|
6408
|
-
const facetEntries = Object.entries(detectClickedFacets)
|
|
6402
|
+
const facetEntries = detectClickedFacets && Object.keys(detectClickedFacets).length ? Object.entries(detectClickedFacets) : [];
|
|
6409
6403
|
let filterCustomByObject = [];
|
|
6410
6404
|
for (const facetEntry of facetEntries) {
|
|
6411
6405
|
const detectClickedFacet = facetEntry;
|
|
@@ -10358,29 +10352,65 @@ const ResultProduct = React__default.memo((props) => {
|
|
|
10358
10352
|
});
|
|
10359
10353
|
return dataClickedFacets2;
|
|
10360
10354
|
};
|
|
10361
|
-
const handleSearchResultData = (props2) => {
|
|
10362
|
-
var _a2, _b2;
|
|
10355
|
+
const handleSearchResultData = async (props2) => {
|
|
10356
|
+
var _a2, _b2, _c2, _d2;
|
|
10363
10357
|
const { isLoadMore: isLoadMore2 = false, result: resultProp, onSearch } = props2;
|
|
10364
10358
|
const INSTANT_SEARCH_SETTING = JSON.parse(localStorage.getItem(LOCAL_STORAGE_KEY.INSTANT_SEARCH_SETTING) || null);
|
|
10365
10359
|
const { index_product } = INSTANT_SEARCH_SETTING || {};
|
|
10366
10360
|
const isNoneFacetSelected = Boolean(!((_a2 = handleDataClickedFacets()) == null ? void 0 : _a2.length));
|
|
10367
10361
|
const isFirstTimeOrOnSearch = handleSearchResultFirstTime && initStatesFirstTime || onSearch;
|
|
10368
|
-
|
|
10362
|
+
let resultData = layoutType === "default" && isFirstTimeOrOnSearch ? resultProp == null ? void 0 : resultProp.results : resultProp;
|
|
10369
10363
|
const result = layoutType === "default" && isFirstTimeOrOnSearch ? (_b2 = resultData == null ? void 0 : resultData.find) == null ? void 0 : _b2.call(resultData, ({ indexUid }) => indexUid.includes(index_product)) : resultData;
|
|
10370
10364
|
if (!result)
|
|
10371
10365
|
return;
|
|
10372
|
-
const { hits, hitsPerPage, processingTimeMs, totalHits, totalPages, facetDistribution } = result;
|
|
10366
|
+
const { hits: hitsResult, hitsPerPage, processingTimeMs, totalHits, totalPages, facetDistribution, query: queryResult } = result;
|
|
10367
|
+
const isSplitProducts = Boolean((_c2 = instantSearchSettings == null ? void 0 : instantSearchSettings.split_products) == null ? void 0 : _c2.enable);
|
|
10368
|
+
const bySplitProducts = (_d2 = instantSearchSettings == null ? void 0 : instantSearchSettings.split_products) == null ? void 0 : _d2.by;
|
|
10369
|
+
const searchParams2 = new URLSearchParams(document.location.search);
|
|
10370
|
+
const searchParamsObject = Object.fromEntries(searchParams2);
|
|
10371
|
+
let hits = hitsResult;
|
|
10372
|
+
if (isSplitProducts && bySplitProducts && (hits == null ? void 0 : hits.length)) {
|
|
10373
|
+
let newHits = [];
|
|
10374
|
+
hits.map((item) => {
|
|
10375
|
+
var _a3;
|
|
10376
|
+
const optionFirst = isSplitProducts && bySplitProducts ? (_a3 = item == null ? void 0 : item.options) == null ? void 0 : _a3[bySplitProducts] : [];
|
|
10377
|
+
const optionFirstValues = (optionFirst == null ? void 0 : optionFirst.length) ? optionFirst : [];
|
|
10378
|
+
if (isSplitProducts && (optionFirstValues == null ? void 0 : optionFirstValues.length)) {
|
|
10379
|
+
optionFirstValues.map((optionFirstValue, indexFirstValue) => {
|
|
10380
|
+
newHits.push({
|
|
10381
|
+
...item,
|
|
10382
|
+
optionSelectedValue: optionFirstValue
|
|
10383
|
+
});
|
|
10384
|
+
});
|
|
10385
|
+
} else {
|
|
10386
|
+
newHits.push(item);
|
|
10387
|
+
}
|
|
10388
|
+
});
|
|
10389
|
+
if (newHits == null ? void 0 : newHits.length) {
|
|
10390
|
+
hits = newHits.filter((item) => {
|
|
10391
|
+
var _a3, _b3, _c3, _d3, _e2;
|
|
10392
|
+
const { optionSelectedValue } = item || {};
|
|
10393
|
+
const optionsFiltered = bySplitProducts ? (_d3 = (_c3 = (_b3 = (_a3 = searchParamsObject == null ? void 0 : searchParamsObject[`options.${bySplitProducts}`]) == null ? void 0 : _a3.split) == null ? void 0 : _b3.call(_a3, ",")) == null ? void 0 : _c3.map) == null ? void 0 : _d3.call(_c3, (item2) => decodeURIComponent(item2)) : [];
|
|
10394
|
+
const hasOptionsFiltered = optionsFiltered && (optionsFiltered == null ? void 0 : optionsFiltered.length) ? !((_e2 = optionsFiltered == null ? void 0 : optionsFiltered.includes) == null ? void 0 : _e2.call(optionsFiltered, optionSelectedValue)) : false;
|
|
10395
|
+
const isOptionNotContainsKeyword = (queryResult == null ? void 0 : queryResult.length) ? !(optionSelectedValue == null ? void 0 : optionSelectedValue.length) ? true : !optionSelectedValue.toLowerCase().includes(queryResult.toLowerCase()) : false;
|
|
10396
|
+
if (isSplitProducts && (hasOptionsFiltered || isOptionNotContainsKeyword)) {
|
|
10397
|
+
return false;
|
|
10398
|
+
}
|
|
10399
|
+
return true;
|
|
10400
|
+
});
|
|
10401
|
+
}
|
|
10402
|
+
}
|
|
10373
10403
|
const updateTabs = () => {
|
|
10374
10404
|
const valueAllowedTabs = objectPresent(previewSettings) ? tabs : allowedTabs;
|
|
10375
10405
|
if (valueAllowedTabs == null ? void 0 : valueAllowedTabs.length) {
|
|
10376
10406
|
setAllowedTabs == null ? void 0 : setAllowedTabs(
|
|
10377
10407
|
valueAllowedTabs.map((tab) => {
|
|
10378
|
-
var _a3, _b3,
|
|
10408
|
+
var _a3, _b3, _c3;
|
|
10379
10409
|
const { index, total } = tab;
|
|
10380
10410
|
let isCurrentIndex = index.includes(clickedTabIndexId);
|
|
10381
10411
|
let tabTotal = isCurrentIndex ? totalHits : total;
|
|
10382
10412
|
if (layoutType === "default" && ((_a3 = resultProp == null ? void 0 : resultProp.results) == null ? void 0 : _a3.length)) {
|
|
10383
|
-
const { totalHits: totalHits2 } = (
|
|
10413
|
+
const { totalHits: totalHits2 } = (_c3 = (_b3 = resultProp == null ? void 0 : resultProp.results) == null ? void 0 : _b3.find) == null ? void 0 : _c3.call(_b3, ({ indexUid }) => indexUid.includes(index));
|
|
10384
10414
|
tabTotal = totalHits2 || tabTotal;
|
|
10385
10415
|
}
|
|
10386
10416
|
return {
|
|
@@ -10396,6 +10426,30 @@ const ResultProduct = React__default.memo((props) => {
|
|
|
10396
10426
|
if (objectPresent(previewSettings))
|
|
10397
10427
|
updateTabs();
|
|
10398
10428
|
if (isFirstTimeOrOnSearch || isNoneFacetSelected) {
|
|
10429
|
+
if (handleSearchResultFirstTime && initStatesFirstTime && clickedFacets && Object.keys(clickedFacets).length) {
|
|
10430
|
+
const initData = await handleSearchResponse({
|
|
10431
|
+
layoutType,
|
|
10432
|
+
clickedTabIndexId,
|
|
10433
|
+
clickedTabIndexType,
|
|
10434
|
+
page: 0,
|
|
10435
|
+
limit: 0,
|
|
10436
|
+
isUseMultiSearch: handleSearchResultFirstTime && initStatesFirstTime || onSearch,
|
|
10437
|
+
facets,
|
|
10438
|
+
attributesToRetrieve,
|
|
10439
|
+
allowedFilterSlider,
|
|
10440
|
+
hierarchicalFacetAliases,
|
|
10441
|
+
defaultFilterItems,
|
|
10442
|
+
collectionId,
|
|
10443
|
+
hiddenTags,
|
|
10444
|
+
showOutOfStock,
|
|
10445
|
+
hierarchicalProductTypeSettings,
|
|
10446
|
+
hierarchicalCollectionsSettings,
|
|
10447
|
+
usePublishedFilter,
|
|
10448
|
+
tabs,
|
|
10449
|
+
instantSearchSettings
|
|
10450
|
+
});
|
|
10451
|
+
resultData = layoutType === "default" && isFirstTimeOrOnSearch ? initData == null ? void 0 : initData.results : initData;
|
|
10452
|
+
}
|
|
10399
10453
|
handleSetInitStates == null ? void 0 : handleSetInitStates({
|
|
10400
10454
|
results: resultData,
|
|
10401
10455
|
data: INSTANT_SEARCH_SETTING,
|
|
@@ -10491,7 +10545,7 @@ const ResultProduct = React__default.memo((props) => {
|
|
|
10491
10545
|
}
|
|
10492
10546
|
setHandleSearchResultFirstTime(false);
|
|
10493
10547
|
setInitStatesFirstTime == null ? void 0 : setInitStatesFirstTime(false);
|
|
10494
|
-
handleSearchResultData({
|
|
10548
|
+
await handleSearchResultData({
|
|
10495
10549
|
result: response,
|
|
10496
10550
|
...props2
|
|
10497
10551
|
});
|