@sledge-app/react-instant-search 2.0.22 → 2.0.24
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/SearchResultWidget.d.ts.map +1 -1
- package/dist/components/SearchResultWidget/components/FacetBlockSelected.d.ts.map +1 -1
- 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 -12
- package/dist/sledge-react-instant-search.js.map +1 -1
- package/package.json +1 -1
|
@@ -671,6 +671,17 @@ const setElementAttribute = ({ element, attributeName, value }) => {
|
|
|
671
671
|
element.setAttribute(attributeName, value);
|
|
672
672
|
}
|
|
673
673
|
};
|
|
674
|
+
const convertToQueryParams = (obj) => {
|
|
675
|
+
var _a;
|
|
676
|
+
if (typeof obj !== "object" || obj === null || obj && !((_a = Object.keys(obj)) == null ? void 0 : _a.length))
|
|
677
|
+
return {};
|
|
678
|
+
const queryParams = {};
|
|
679
|
+
Object.keys(obj).forEach((key) => {
|
|
680
|
+
var _a2, _b;
|
|
681
|
+
queryParams[key] = (_b = (_a2 = obj[key]) == null ? void 0 : _a2.map) == null ? void 0 : _b.call(_a2, (value) => encodeURIComponent(value));
|
|
682
|
+
});
|
|
683
|
+
return queryParams;
|
|
684
|
+
};
|
|
674
685
|
const root = "";
|
|
675
686
|
const Loading = "";
|
|
676
687
|
const ConfirmationPopup = "";
|
|
@@ -6103,6 +6114,36 @@ const SearchIconWidgetPopup = () => {
|
|
|
6103
6114
|
] })
|
|
6104
6115
|
] }) });
|
|
6105
6116
|
};
|
|
6117
|
+
const hasDuplicateValue = (array, targetValue) => {
|
|
6118
|
+
let foundCount = 0;
|
|
6119
|
+
if (!(array == null ? void 0 : array.length))
|
|
6120
|
+
return false;
|
|
6121
|
+
for (let i = 0; i < array.length; i++) {
|
|
6122
|
+
if (array[i].value === targetValue) {
|
|
6123
|
+
foundCount++;
|
|
6124
|
+
if (foundCount > 1)
|
|
6125
|
+
return true;
|
|
6126
|
+
}
|
|
6127
|
+
}
|
|
6128
|
+
return false;
|
|
6129
|
+
};
|
|
6130
|
+
const filterCustomGrouping = (arr) => {
|
|
6131
|
+
if (!(arr == null ? void 0 : arr.length))
|
|
6132
|
+
return [];
|
|
6133
|
+
const groupMap = /* @__PURE__ */ new Map();
|
|
6134
|
+
arr.forEach((arrItem) => {
|
|
6135
|
+
const key = `${arrItem.index}-${arrItem.query_filter}`;
|
|
6136
|
+
if (!groupMap.has(key)) {
|
|
6137
|
+
groupMap.set(key, {
|
|
6138
|
+
query_filter: arrItem.query_filter,
|
|
6139
|
+
index: arrItem.index,
|
|
6140
|
+
items: []
|
|
6141
|
+
});
|
|
6142
|
+
}
|
|
6143
|
+
groupMap.get(key).items.push(arrItem.item);
|
|
6144
|
+
});
|
|
6145
|
+
return Array.from(groupMap.values());
|
|
6146
|
+
};
|
|
6106
6147
|
const sortFacets = ({ facets, sortingOrder }) => {
|
|
6107
6148
|
if (!(facets == null ? void 0 : facets.length) || !(sortingOrder == null ? void 0 : sortingOrder.length))
|
|
6108
6149
|
return facets;
|
|
@@ -6152,12 +6193,13 @@ const parseFacetObject = ({ facet = "" }) => {
|
|
|
6152
6193
|
return null;
|
|
6153
6194
|
};
|
|
6154
6195
|
const detectQueryStringFilter = ({ facets, facetsQueryStringObject, callback }) => {
|
|
6196
|
+
var _a, _b;
|
|
6155
6197
|
const searchParams = new URLSearchParams(document.location.search);
|
|
6156
6198
|
const searchParamsObject = Object.fromEntries(searchParams);
|
|
6157
6199
|
for (const searchParamsKey in searchParamsObject) {
|
|
6158
6200
|
let ifFacetsQueryStringObject = (facets == null ? void 0 : facets.length) && facets.includes(searchParamsKey);
|
|
6159
6201
|
if (ifFacetsQueryStringObject)
|
|
6160
|
-
facetsQueryStringObject[searchParamsKey] = searchParamsObject[searchParamsKey].split(",");
|
|
6202
|
+
facetsQueryStringObject[searchParamsKey] = (_b = (_a = searchParamsObject[searchParamsKey].split(",")) == null ? void 0 : _a.map) == null ? void 0 : _b.call(_a, (item) => decodeURIComponent(item));
|
|
6161
6203
|
}
|
|
6162
6204
|
if (Object.keys(facetsQueryStringObject).length)
|
|
6163
6205
|
callback(facetsQueryStringObject);
|
|
@@ -6202,7 +6244,7 @@ const createQueryFilter = ({
|
|
|
6202
6244
|
hierarchicalFacetAliases,
|
|
6203
6245
|
defaultFilterItems
|
|
6204
6246
|
}) => {
|
|
6205
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
6247
|
+
var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l;
|
|
6206
6248
|
let filters = additional == null ? void 0 : additional.filter((item) => item);
|
|
6207
6249
|
let detectClickedFacets = detectQueryStringFilter({
|
|
6208
6250
|
facets,
|
|
@@ -6216,6 +6258,7 @@ const createQueryFilter = ({
|
|
|
6216
6258
|
hierarchicalFacetAliases
|
|
6217
6259
|
});
|
|
6218
6260
|
const facetEntries = Object.entries(detectClickedFacets) || [];
|
|
6261
|
+
let filterCustomByObject = [];
|
|
6219
6262
|
for (const facetEntry of facetEntries) {
|
|
6220
6263
|
const detectClickedFacet = facetEntry;
|
|
6221
6264
|
if (!((detectClickedFacet == null ? void 0 : detectClickedFacet.length) && detectClickedFacet[1].length))
|
|
@@ -6223,7 +6266,26 @@ const createQueryFilter = ({
|
|
|
6223
6266
|
let isCustom = ["variants.inventory_quantity"].includes(detectClickedFacet[0]);
|
|
6224
6267
|
let isRange = allowedFilterSlider == null ? void 0 : allowedFilterSlider.includes(detectClickedFacet[0]);
|
|
6225
6268
|
let isHierarchical = hierarchicalFacetAliases == null ? void 0 : hierarchicalFacetAliases.includes(detectClickedFacet[0]);
|
|
6226
|
-
let
|
|
6269
|
+
let isHasDuplicate = hasDuplicateValue(defaultFilterItems, detectClickedFacet[0]);
|
|
6270
|
+
if (isHasDuplicate && !isHierarchical) {
|
|
6271
|
+
let filterCustom = [];
|
|
6272
|
+
(_a = detectClickedFacet == null ? void 0 : detectClickedFacet[1]) == null ? void 0 : _a.map((item) => {
|
|
6273
|
+
const defaultFilterItemsObject = defaultFilterItems == null ? void 0 : defaultFilterItems.find(({ items }) => items == null ? void 0 : items.includes(item));
|
|
6274
|
+
const { index: defaultFilterItemsIndex, settings: defaultFilterItemsSettings } = defaultFilterItemsObject || {};
|
|
6275
|
+
const { query_filter: query_filter2 } = defaultFilterItemsSettings || {};
|
|
6276
|
+
filterCustom.push({
|
|
6277
|
+
query_filter: query_filter2,
|
|
6278
|
+
index: defaultFilterItemsIndex,
|
|
6279
|
+
item
|
|
6280
|
+
});
|
|
6281
|
+
});
|
|
6282
|
+
filterCustomByObject.push({
|
|
6283
|
+
value: detectClickedFacet[0],
|
|
6284
|
+
filters: filterCustomGrouping(filterCustom)
|
|
6285
|
+
});
|
|
6286
|
+
continue;
|
|
6287
|
+
}
|
|
6288
|
+
let filterSettings = (_b = defaultFilterItems == null ? void 0 : defaultFilterItems.find(({ value }) => value === detectClickedFacet[0])) == null ? void 0 : _b.settings;
|
|
6227
6289
|
const { query_filter } = filterSettings || {};
|
|
6228
6290
|
if (isHierarchical) {
|
|
6229
6291
|
let arrItemHierarchicals = [];
|
|
@@ -6244,15 +6306,15 @@ const createQueryFilter = ({
|
|
|
6244
6306
|
} else {
|
|
6245
6307
|
let filterItem = "";
|
|
6246
6308
|
if (query_filter === "AND") {
|
|
6247
|
-
filterItem = ((
|
|
6309
|
+
filterItem = ((_c = detectClickedFacet == null ? void 0 : detectClickedFacet[1]) == null ? void 0 : _c.length) ? (_g = (_f = (_e = (_d = detectClickedFacet == null ? void 0 : detectClickedFacet[1]) == null ? void 0 : _d.map) == null ? void 0 : _e.call(_d, (item) => `'${detectClickedFacet[0]}' = ${JSON.stringify(item)}`)) == null ? void 0 : _f.join) == null ? void 0 : _g.call(_f, " AND ") : "";
|
|
6248
6310
|
} else {
|
|
6249
6311
|
filterItem = `'${detectClickedFacet[0]}' IN ${JSON.stringify(detectClickedFacet[1])}`;
|
|
6250
6312
|
}
|
|
6251
6313
|
if (isRange)
|
|
6252
6314
|
filterItem = `'${detectClickedFacet[0]}' >= ${detectClickedFacet[1][0]} AND '${detectClickedFacet[0]}' <= ${detectClickedFacet[1][1]}`;
|
|
6253
6315
|
if (isCustom) {
|
|
6254
|
-
if (Array.isArray(detectClickedFacet[1]) && ((
|
|
6255
|
-
filterItem = `(${(
|
|
6316
|
+
if (Array.isArray(detectClickedFacet[1]) && ((_h = detectClickedFacet[1]) == null ? void 0 : _h.length) > 1) {
|
|
6317
|
+
filterItem = `(${(_i = detectClickedFacet[1]) == null ? void 0 : _i.map((item) => {
|
|
6256
6318
|
return `'${detectClickedFacet[0]}' ${item}`;
|
|
6257
6319
|
}).join(" OR ")})`;
|
|
6258
6320
|
} else {
|
|
@@ -6262,7 +6324,25 @@ const createQueryFilter = ({
|
|
|
6262
6324
|
filters.push(filterItem);
|
|
6263
6325
|
}
|
|
6264
6326
|
}
|
|
6265
|
-
|
|
6327
|
+
let filterCustomByObjectString = (_l = (_k = (_j = filterCustomByObject == null ? void 0 : filterCustomByObject.map) == null ? void 0 : _j.call(filterCustomByObject, ({ value, filters: filters2 }) => {
|
|
6328
|
+
var _a2, _b2;
|
|
6329
|
+
let filterCustomString = [];
|
|
6330
|
+
(_a2 = filters2 == null ? void 0 : filters2.map) == null ? void 0 : _a2.call(filters2, ({ query_filter, items }) => {
|
|
6331
|
+
var _a3, _b3;
|
|
6332
|
+
if (!(items == null ? void 0 : items.length))
|
|
6333
|
+
return;
|
|
6334
|
+
if (query_filter === "AND") {
|
|
6335
|
+
filterCustomString.push((_b3 = (_a3 = items.map((item) => `'${value}' = ${JSON.stringify(item)}`)) == null ? void 0 : _a3.join) == null ? void 0 : _b3.call(_a3, " AND "));
|
|
6336
|
+
} else {
|
|
6337
|
+
filterCustomString.push(`'${value}' IN ${JSON.stringify(items)}`);
|
|
6338
|
+
}
|
|
6339
|
+
});
|
|
6340
|
+
return (_b2 = filterCustomString == null ? void 0 : filterCustomString.join) == null ? void 0 : _b2.call(filterCustomString, " AND ");
|
|
6341
|
+
})) == null ? void 0 : _k.filter) == null ? void 0 : _l.call(_k, (item) => item);
|
|
6342
|
+
let filtersConcat = filters.concat(DEFAULT_QUERY_PRODUCT_MEILISEARCH);
|
|
6343
|
+
if (filterCustomByObjectString == null ? void 0 : filterCustomByObjectString.length)
|
|
6344
|
+
filtersConcat = filtersConcat.concat(DEFAULT_QUERY_PRODUCT_MEILISEARCH, filterCustomByObjectString);
|
|
6345
|
+
return [...new Set(filtersConcat)].join(" AND ");
|
|
6266
6346
|
};
|
|
6267
6347
|
const createHierarchicalFacet = ({
|
|
6268
6348
|
indexValue,
|
|
@@ -6800,11 +6880,13 @@ const FacetBlockSelected = React__default.memo(
|
|
|
6800
6880
|
isSalePercent = true;
|
|
6801
6881
|
}
|
|
6802
6882
|
if (defaultFilterItems == null ? void 0 : defaultFilterItems.length) {
|
|
6883
|
+
let isSetValue = false;
|
|
6803
6884
|
defaultFilterItems.map((defaultFilterItem) => {
|
|
6804
6885
|
const { label: defaultFilterItemLabel, items, settings: defaultFilterItemSettings } = defaultFilterItem;
|
|
6805
|
-
if (items == null ? void 0 : items.includes(value)) {
|
|
6886
|
+
if ((items == null ? void 0 : items.includes(value)) && !isSetValue) {
|
|
6806
6887
|
getLabel = defaultFilterItemLabel;
|
|
6807
6888
|
getSettings = defaultFilterItemSettings;
|
|
6889
|
+
isSetValue = true;
|
|
6808
6890
|
}
|
|
6809
6891
|
});
|
|
6810
6892
|
}
|
|
@@ -9020,7 +9102,7 @@ const SearchResultWidget = (props) => {
|
|
|
9020
9102
|
}
|
|
9021
9103
|
}
|
|
9022
9104
|
if (valueAllowedFilter == null ? void 0 : valueAllowedFilter.length) {
|
|
9023
|
-
valueDefaultFilterItems = valueAllowedFilter.map((filter) => {
|
|
9105
|
+
valueDefaultFilterItems = valueAllowedFilter.map((filter, index) => {
|
|
9024
9106
|
var _a3;
|
|
9025
9107
|
const { value, label, display, settings: settings2 } = filter;
|
|
9026
9108
|
const { prefix, filter_list, selected_filter } = settings2 || {};
|
|
@@ -9039,6 +9121,7 @@ const SearchResultWidget = (props) => {
|
|
|
9039
9121
|
value,
|
|
9040
9122
|
label,
|
|
9041
9123
|
settings: settings2,
|
|
9124
|
+
index,
|
|
9042
9125
|
items: (_a3 = items == null ? void 0 : items.map((item) => {
|
|
9043
9126
|
const isManualFilter = item && filter_list === "manual" && !(selected_filter == null ? void 0 : selected_filter.includes(item == null ? void 0 : item.value));
|
|
9044
9127
|
const isPrefixFilter = item && filter_list === "prefix" && !(prefix == null ? void 0 : prefix.find((prefixItem) => {
|
|
@@ -9957,9 +10040,10 @@ const ResultProduct = React__default.memo((props) => {
|
|
|
9957
10040
|
otherQueryStringObject[searchParamsKey] = searchParamsObject[searchParamsKey];
|
|
9958
10041
|
}
|
|
9959
10042
|
let facetQueryStringObject = {};
|
|
9960
|
-
|
|
9961
|
-
|
|
9962
|
-
|
|
10043
|
+
let convertValueClickedFacets = convertToQueryParams(valueClickedFacets);
|
|
10044
|
+
for (const valueClickedFacetsKey in convertValueClickedFacets) {
|
|
10045
|
+
if ((_a2 = convertValueClickedFacets[valueClickedFacetsKey]) == null ? void 0 : _a2.length)
|
|
10046
|
+
otherQueryStringObject[valueClickedFacetsKey] = convertValueClickedFacets[valueClickedFacetsKey];
|
|
9963
10047
|
}
|
|
9964
10048
|
const newQueryString = new URLSearchParams({
|
|
9965
10049
|
...otherQueryStringObject,
|