@sledge-app/react-instant-search 1.0.39 → 1.0.41

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.
@@ -175,6 +175,11 @@ const PAYLOAD_API_ALIASES = {
175
175
  PUT: "dEnOjbvTzULLK",
176
176
  DELETE: "pLC93Tvsu6g7H"
177
177
  };
178
+ const HIERARCHICAL_FACET_OBJECT_ALIASES = {
179
+ collections: "hierarchicalCollections",
180
+ product_type: "hierarchicalProductType"
181
+ };
182
+ const MAX_LIMIT_HIERARCHICAL = 7;
178
183
  async function swr(url, options) {
179
184
  if (typeof localStorage !== "undefined" && typeof caches !== "undefined" && options.method === "GET" && !(options == null ? void 0 : options.ignoreSWR)) {
180
185
  const data = await getData(url);
@@ -382,6 +387,7 @@ const getFillRating = ({
382
387
  const stripTags = (html) => {
383
388
  return html.replace(/(<([^>]+)>)/gi, "");
384
389
  };
390
+ const stringToSlug = (text) => text.toLowerCase().replace(/[^\w ]+/g, "").replace(/ +/g, "-");
385
391
  const root = "";
386
392
  const Loading = "";
387
393
  const ConfirmationPopup = "";
@@ -3847,7 +3853,7 @@ const SearchIconWidgetPopup = () => {
3847
3853
  ] }) });
3848
3854
  };
3849
3855
  const SearchResultWidget = (props) => {
3850
- var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w;
3856
+ var _a, _b, _c, _d, _e, _f, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v, _w, _x;
3851
3857
  const {
3852
3858
  layoutType = "default",
3853
3859
  width = DEFAULT_MAX_WIDTH_COMPONENT,
@@ -3888,6 +3894,7 @@ const SearchResultWidget = (props) => {
3888
3894
  const [defaultSort, setDefaultSort] = React__default.useState(((_h = sledgeSettings == null ? void 0 : sledgeSettings.instantsearch) == null ? void 0 : _h.default_sort) || "");
3889
3895
  const [showOutOfStock, setShowOutOfStock] = React__default.useState((_i = sledgeSettings == null ? void 0 : sledgeSettings.instantsearch) == null ? void 0 : _i.show_out_of_stock);
3890
3896
  const [languageSettings, setLanguageSettings] = React__default.useState(((_j = sledgeSettings == null ? void 0 : sledgeSettings.instantsearch) == null ? void 0 : _j.languages) || {});
3897
+ const [hierarchicalProductTypeSettings, setHierarchicalProductTypeSettings] = React__default.useState(((_k = sledgeSettings == null ? void 0 : sledgeSettings.instantsearch) == null ? void 0 : _k.hierarchical_product_type) || {});
3891
3898
  const [initStatesFirstTime, setInitStatesFirstTime] = React__default.useState(true);
3892
3899
  const [defaultFacetStats, setDefaultFacetStats] = React__default.useState({});
3893
3900
  const [hideFilterWhenOneValue, setHideFilterWhenOneValue] = React__default.useState(false);
@@ -3915,7 +3922,7 @@ const SearchResultWidget = (props) => {
3915
3922
  });
3916
3923
  const { isRenderApp, isJsVersion, triggerRenderMultipleComponent } = React__default.useContext(SledgeContext);
3917
3924
  const { instantSearch: isRenderAppInstantSearch } = isRenderApp || {};
3918
- const { value: valueRenderInstantSearchResult, trigger: triggerRenderInstantSearchResult } = ((_k = triggerRenderMultipleComponent == null ? void 0 : triggerRenderMultipleComponent.instantSearch) == null ? void 0 : _k.searchResult) || {};
3925
+ const { value: valueRenderInstantSearchResult, trigger: triggerRenderInstantSearchResult } = ((_l = triggerRenderMultipleComponent == null ? void 0 : triggerRenderMultipleComponent.instantSearch) == null ? void 0 : _l.searchResult) || {};
3919
3926
  const searchResultContainerRef = React__default.useRef(null);
3920
3927
  const previousState = usePrevious({ keyword });
3921
3928
  const handleChangeTabIndex = (params2) => {
@@ -3936,13 +3943,14 @@ const SearchResultWidget = (props) => {
3936
3943
  let isSetFilter = false;
3937
3944
  let getFacets = !isSetFilter ? filters == null ? void 0 : filters.map((filter) => {
3938
3945
  const { collections, items } = filter;
3946
+ const newItems = items == null ? void 0 : items.map(({ value, ...otherItem }) => (otherItem == null ? void 0 : otherItem.display) === "tree" ? HIERARCHICAL_FACET_OBJECT_ALIASES[value] : value);
3939
3947
  if (collectionId && (collections == null ? void 0 : collections.includes(Number(collectionId)))) {
3940
3948
  isSetFilter = true;
3941
- return items == null ? void 0 : items.map(({ value }) => value);
3949
+ return newItems;
3942
3950
  } else {
3943
3951
  if (collections == null ? void 0 : collections.includes("all")) {
3944
3952
  isSetFilter = true;
3945
- return items == null ? void 0 : items.map(({ value }) => value);
3953
+ return newItems;
3946
3954
  }
3947
3955
  }
3948
3956
  }) : [];
@@ -4028,7 +4036,7 @@ const SearchResultWidget = (props) => {
4028
4036
  response = JSON.parse(LOCAL_STORAGE_INSTANT_SEARCH_SETTING);
4029
4037
  if (!response)
4030
4038
  return;
4031
- const { allowed_sorts, default_sort, filters, index_product, tabs, hidden_tags, display, colors, show_out_of_stock, languages } = response;
4039
+ const { allowed_sorts, default_sort, filters, index_product, tabs, hidden_tags, display, colors, show_out_of_stock, languages, hierarchical_product_type } = response;
4032
4040
  setAllowedSorts((allowed_sorts == null ? void 0 : allowed_sorts.length) ? allowed_sorts : []);
4033
4041
  setAllowedFilters((filters == null ? void 0 : filters.length) ? filters : []);
4034
4042
  setIndexProduct(index_product);
@@ -4038,6 +4046,7 @@ const SearchResultWidget = (props) => {
4038
4046
  setDefaultSort(default_sort);
4039
4047
  setShowOutOfStock(show_out_of_stock);
4040
4048
  setLanguageSettings(languages);
4049
+ setHierarchicalProductTypeSettings(hierarchical_product_type);
4041
4050
  getFirstIndex = tabs.find(({ index }) => index.includes(index_product));
4042
4051
  if (Object.keys(getFirstIndex).length) {
4043
4052
  setClickedTabIndexId(getFirstIndex.index);
@@ -4074,8 +4083,8 @@ const SearchResultWidget = (props) => {
4074
4083
  }, [keyword]);
4075
4084
  const filterHorizontalSkeletonComponent = /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-filter-horizontal-skeleton", children: [1, 2, 3, 4, 5, 6, 7].map((index) => /* @__PURE__ */ jsxRuntimeExports.jsx(SkeletonLoading.Item, { width: "106px", height: "42px", rounded: "md", color: "lighten" }, index)) });
4076
4085
  const tabSkeleton = layoutType === "default" ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-tab-list sledge-instant-search__result-tab-list-skeleton", children: [1, 2, 3, 4, 5].map((index) => /* @__PURE__ */ jsxRuntimeExports.jsx(SkeletonLoading.Item, { width: "122px", height: "28px", rounded: "md", color: "lighten" }, index)) }) : null;
4077
- const filterHorizontalSkeleton = ((_l = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _l.enable_on_search) && ((_m = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _m.layout) === "horizontal" && !hideFilterWhenOneValue ? filterHorizontalSkeletonComponent : null;
4078
- const filterVerticalSkeleton = ((_n = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _n.enable_on_search) && ((_o = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _o.layout) === "vertical" && !hideFilterWhenOneValue ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
4086
+ const filterHorizontalSkeleton = ((_m = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _m.enable_on_search) && ((_n = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _n.layout) === "horizontal" && !hideFilterWhenOneValue ? filterHorizontalSkeletonComponent : null;
4087
+ const filterVerticalSkeleton = ((_o = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _o.enable_on_search) && ((_p = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _p.layout) === "vertical" && !hideFilterWhenOneValue ? /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
4079
4088
  /* @__PURE__ */ jsxRuntimeExports.jsxs(
4080
4089
  "div",
4081
4090
  {
@@ -4291,7 +4300,7 @@ const SearchResultWidget = (props) => {
4291
4300
  )
4292
4301
  ] }) : null;
4293
4302
  const productGridSkeleton = /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
4294
- ((_p = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _p.show_total_products) && ((_q = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _q.layout) === "vertical" ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge__hide-element-lg-on-mobile", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
4303
+ ((_q = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _q.show_total_products) && ((_r = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _r.layout) === "vertical" ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge__hide-element-lg-on-mobile", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
4295
4304
  SkeletonLoading.Item,
4296
4305
  {
4297
4306
  width: "117px",
@@ -4312,12 +4321,12 @@ const SearchResultWidget = (props) => {
4312
4321
  /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-data-summary-select-field-item", children: /* @__PURE__ */ jsxRuntimeExports.jsx(SkeletonLoading.Item, { width: "150px", height: "42px", color: "lighten", rounded: "lg" }) })
4313
4322
  ] });
4314
4323
  const searchAndSelectOptionSkeleton = /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge-instant-search__result-data-keyword", children: [
4315
- ((_r = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _r.show_total_products) && ((_s = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _s.layout) === "horizontal" ? summaryTextSkeleton : null,
4324
+ ((_s = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _s.show_total_products) && ((_t = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _t.layout) === "horizontal" ? summaryTextSkeleton : null,
4316
4325
  searchFieldSkeletonComponent,
4317
4326
  selectOptionSkeletonComponent
4318
4327
  ] });
4319
4328
  const mobileFilterWithSearchAndSelectOptionSkeleton = /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge__hide-element-mobile-on-lg sledge-instant-search__mobile-filter-search-skeleton", children: /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge-instant-search__result-data-keyword", children: [
4320
- ((_t = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _t.show_total_products) && ((_u = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _u.layout) === "horizontal" ? summaryTextSkeleton : null,
4329
+ ((_u = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _u.show_total_products) && ((_v = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _v.layout) === "horizontal" ? summaryTextSkeleton : null,
4321
4330
  searchFieldSkeletonComponent,
4322
4331
  filterHorizontalSkeletonComponent,
4323
4332
  selectOptionSkeletonComponent
@@ -4350,7 +4359,7 @@ const SearchResultWidget = (props) => {
4350
4359
  mobileFilterWithSearchAndSelectOptionSkeleton,
4351
4360
  /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge__hide-element-lg-on-mobile", children: filterHorizontalSkeleton }),
4352
4361
  /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge-instant-search__result-wrapper sledge-instant-search__result-wrapper-skeleton", children: [
4353
- ((_v = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _v.enable_on_search) && ((_w = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _w.layout) === "vertical" && !hideFilterWhenOneValue ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-filter sledge__hide-element-lg-on-mobile", children: filterVerticalSkeleton }) : null,
4362
+ ((_w = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _w.enable_on_search) && ((_x = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _x.layout) === "vertical" && !hideFilterWhenOneValue ? /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-filter sledge__hide-element-lg-on-mobile", children: filterVerticalSkeleton }) : null,
4354
4363
  /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge-instant-search__result-data", children: [
4355
4364
  /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge__hide-element-lg-on-mobile", children: searchAndSelectOptionSkeleton }),
4356
4365
  productGridSkeleton
@@ -4375,6 +4384,7 @@ const SearchResultWidget = (props) => {
4375
4384
  defaultSort,
4376
4385
  showOutOfStock,
4377
4386
  languageSettings,
4387
+ hierarchicalProductTypeSettings,
4378
4388
  query,
4379
4389
  params,
4380
4390
  isJsVersion,
@@ -4428,6 +4438,7 @@ const ResultProduct = (props) => {
4428
4438
  defaultSort,
4429
4439
  showOutOfStock,
4430
4440
  languageSettings,
4441
+ hierarchicalProductTypeSettings,
4431
4442
  query,
4432
4443
  params,
4433
4444
  isJsVersion,
@@ -4486,6 +4497,7 @@ const ResultProduct = (props) => {
4486
4497
  pagination_info: language_pagination_info,
4487
4498
  total_result_text: language_total_result_text
4488
4499
  } = languageSettings || {};
4500
+ const { separator: hierarchical_separator } = hierarchicalProductTypeSettings || {};
4489
4501
  const summaryTextGenerator = (totalResult) => {
4490
4502
  var _a2;
4491
4503
  const defaultSummaryText = /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
@@ -4618,7 +4630,7 @@ const ResultProduct = (props) => {
4618
4630
  handleQueryStringFilter({});
4619
4631
  setValueFilterPriceChange([]);
4620
4632
  };
4621
- const handleFilterChange = (parentId, value, force = false) => {
4633
+ const handleFilterChange = ({ parentId, value, force = false }) => {
4622
4634
  var _a2;
4623
4635
  let facets2 = [value];
4624
4636
  let isRange = ["variants.price"].includes(parentId);
@@ -4679,18 +4691,48 @@ const ResultProduct = (props) => {
4679
4691
  if (isRefreshPage)
4680
4692
  setCurrentPage(1);
4681
4693
  setIsLoading(true);
4694
+ let hierarchicalFacetAliases = Object.entries(HIERARCHICAL_FACET_OBJECT_ALIASES).map((hierarchicalFacetAlias) => hierarchicalFacetAlias[1]);
4695
+ let facetHierarchical = hierarchicalFacetAliases.reduce((item, key) => {
4696
+ let defaultLevelHierarchical = {};
4697
+ for (let iLevel = 0; iLevel < MAX_LIMIT_HIERARCHICAL; iLevel++) {
4698
+ defaultLevelHierarchical[`lvl${iLevel}`] = [];
4699
+ }
4700
+ return { ...item, [key]: defaultLevelHierarchical };
4701
+ }, {});
4682
4702
  let detectClickedFacets = detectQueryStringFilter(clickedFacets);
4683
4703
  let response;
4684
4704
  let filters = Object.entries(detectClickedFacets).map((facet) => {
4685
- var _a3, _b3;
4705
+ var _a3, _b3, _c2;
4686
4706
  if ((facet == null ? void 0 : facet.length) && facet[1].length) {
4687
- let value = `'${facet[0]}'`;
4688
4707
  let isCustom = ["variants.inventory_quantity"].includes(facet[0]);
4689
4708
  let isRange = ["variants.price"].includes(facet[0]);
4690
4709
  let isArray = ["tags"].includes(facet[0]);
4691
- let items = Array.isArray(facet[1]) && ((_a3 = facet[1]) == null ? void 0 : _a3.length) > 1 ? isRange ? `${value} >= ${facet[1][0]} AND ${value} <= ${facet[1][1]}` : isArray ? `${value} IN ${JSON.stringify(facet[1])}` : `(${(_b3 = facet[1]) == null ? void 0 : _b3.map((item) => {
4692
- return isCustom ? `${value} ${item}` : `${value} = '${item}'`;
4693
- }).join(" OR ")})` : isCustom ? `${value} ${facet[1]}` : isArray ? `${value} IN ${JSON.stringify(facet[1])}` : `${value} = '${facet[1]}'`;
4710
+ let isHierarchical = hierarchicalFacetAliases.includes(facet[0]);
4711
+ if (isHierarchical) {
4712
+ (_a3 = facet[1]) == null ? void 0 : _a3.map((item) => {
4713
+ const arrItem = String(item).split(hierarchical_separator);
4714
+ if (arrItem == null ? void 0 : arrItem.length) {
4715
+ if (Object.hasOwn(facetHierarchical[facet[0]], `lvl${arrItem.length - 1}`))
4716
+ facetHierarchical[facet[0]][`lvl${arrItem.length - 1}`].push(item);
4717
+ }
4718
+ });
4719
+ let arrItemHierarchicals = [];
4720
+ Object.entries(facetHierarchical[facet[0]]).map((itemHierarchical) => {
4721
+ var _a4;
4722
+ if ((_a4 = itemHierarchical[1]) == null ? void 0 : _a4.length)
4723
+ arrItemHierarchicals.push([`${facet[0]}.${itemHierarchical[0]}`, itemHierarchical[1]]);
4724
+ });
4725
+ let itemHierarchicals = arrItemHierarchicals == null ? void 0 : arrItemHierarchicals.map((filterHierarchical) => {
4726
+ var _a4, _b4;
4727
+ return Array.isArray(filterHierarchical[1]) && ((_a4 = filterHierarchical[1]) == null ? void 0 : _a4.length) > 1 ? `(${(_b4 = filterHierarchical[1]) == null ? void 0 : _b4.map((item) => {
4728
+ return `'${filterHierarchical[0]}' = '${item}'`;
4729
+ }).join(" OR ")})` : `'${filterHierarchical[0]}' = '${filterHierarchical[1]}'`;
4730
+ }).join(" AND ");
4731
+ return itemHierarchicals;
4732
+ }
4733
+ let items = Array.isArray(facet[1]) && ((_b3 = facet[1]) == null ? void 0 : _b3.length) > 1 ? isRange ? `'${facet[0]}' >= ${facet[1][0]} AND '${facet[0]}' <= ${facet[1][1]}` : isArray ? `'${facet[0]}' IN ${JSON.stringify(facet[1])}` : `(${(_c2 = facet[1]) == null ? void 0 : _c2.map((item) => {
4734
+ return isCustom ? `'${facet[0]}' ${item}` : `'${facet[0]}' = '${item}'`;
4735
+ }).join(" OR ")})` : isCustom ? `'${facet[0]}' ${facet[1]}` : isArray ? `'${facet[0]}' IN ${JSON.stringify(facet[1])}` : `'${facet[0]}' = '${facet[1]}'`;
4694
4736
  return items;
4695
4737
  } else
4696
4738
  return null;
@@ -4723,13 +4765,19 @@ const ResultProduct = (props) => {
4723
4765
  if (!isSetFilter)
4724
4766
  allowedFilters == null ? void 0 : allowedFilters.map((filter) => {
4725
4767
  const { collections, items } = filter;
4768
+ const newItems = items == null ? void 0 : items.map(({ value, ...otherItem }) => {
4769
+ return {
4770
+ ...otherItem,
4771
+ value: (otherItem == null ? void 0 : otherItem.display) === "tree" ? HIERARCHICAL_FACET_OBJECT_ALIASES[value] : value
4772
+ };
4773
+ });
4726
4774
  if (collectionId && (collections == null ? void 0 : collections.includes(Number(collectionId)))) {
4727
4775
  isSetFilter = true;
4728
- valueAllowedFilter = items;
4776
+ valueAllowedFilter = newItems;
4729
4777
  } else {
4730
4778
  if (collections == null ? void 0 : collections.includes("all")) {
4731
4779
  isSetFilter = true;
4732
- valueAllowedFilter = items;
4780
+ valueAllowedFilter = newItems;
4733
4781
  }
4734
4782
  }
4735
4783
  });
@@ -4819,15 +4867,25 @@ const ResultProduct = (props) => {
4819
4867
  ": ",
4820
4868
  (_a2 = String(valueText)) == null ? void 0 : _a2.replaceAll("_", " ")
4821
4869
  ] }),
4822
- /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "sledge-instant-search__result-filter-item-refine-title-clear", onClick: () => handleFilterChange(name, value), children: /* @__PURE__ */ jsxRuntimeExports.jsx("svg", { width: 12, height: 12, viewBox: "0 0 15 15", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
4823
- "path",
4870
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
4871
+ "span",
4824
4872
  {
4825
- d: "M11.7816 4.03157C12.0062 3.80702 12.0062 3.44295 11.7816 3.2184C11.5571 2.99385 11.193 2.99385 10.9685 3.2184L7.50005 6.68682L4.03164 3.2184C3.80708 2.99385 3.44301 2.99385 3.21846 3.2184C2.99391 3.44295 2.99391 3.80702 3.21846 4.03157L6.68688 7.49999L3.21846 10.9684C2.99391 11.193 2.99391 11.557 3.21846 11.7816C3.44301 12.0061 3.80708 12.0061 4.03164 11.7816L7.50005 8.31316L10.9685 11.7816C11.193 12.0061 11.5571 12.0061 11.7816 11.7816C12.0062 11.557 12.0062 11.193 11.7816 10.9684L8.31322 7.49999L11.7816 4.03157Z",
4826
- fill: "currentColor",
4827
- fillRule: "evenodd",
4828
- clipRule: "evenodd"
4873
+ className: "sledge-instant-search__result-filter-item-refine-title-clear",
4874
+ onClick: () => handleFilterChange({
4875
+ parentId: name,
4876
+ value
4877
+ }),
4878
+ children: /* @__PURE__ */ jsxRuntimeExports.jsx("svg", { width: 12, height: 12, viewBox: "0 0 15 15", fill: "none", xmlns: "http://www.w3.org/2000/svg", children: /* @__PURE__ */ jsxRuntimeExports.jsx(
4879
+ "path",
4880
+ {
4881
+ d: "M11.7816 4.03157C12.0062 3.80702 12.0062 3.44295 11.7816 3.2184C11.5571 2.99385 11.193 2.99385 10.9685 3.2184L7.50005 6.68682L4.03164 3.2184C3.80708 2.99385 3.44301 2.99385 3.21846 3.2184C2.99391 3.44295 2.99391 3.80702 3.21846 4.03157L6.68688 7.49999L3.21846 10.9684C2.99391 11.193 2.99391 11.557 3.21846 11.7816C3.44301 12.0061 3.80708 12.0061 4.03164 11.7816L7.50005 8.31316L10.9685 11.7816C11.193 12.0061 11.5571 12.0061 11.7816 11.7816C12.0062 11.557 12.0062 11.193 11.7816 10.9684L8.31322 7.49999L11.7816 4.03157Z",
4882
+ fill: "currentColor",
4883
+ fillRule: "evenodd",
4884
+ clipRule: "evenodd"
4885
+ }
4886
+ ) })
4829
4887
  }
4830
- ) }) })
4888
+ )
4831
4889
  ] }, index);
4832
4890
  };
4833
4891
  const handleConditionNotUpdateFacetDistribution = (value) => {
@@ -4840,26 +4898,74 @@ const ResultProduct = (props) => {
4840
4898
  return isNoneFacetSelected || isOnFacetSelectedOne || isPriorityFacet;
4841
4899
  };
4842
4900
  const facetComponent = (filter) => {
4843
- var _a2, _b2;
4844
- const { value, label, display } = filter;
4901
+ var _a2, _b2, _c2, _d2;
4902
+ let { value, label, display, items } = filter;
4845
4903
  if (isFirstLoading)
4846
4904
  return null;
4847
4905
  let blockComponent = null;
4848
- let items = searchResultFacets[value];
4849
4906
  let isShowNumberMatchingProduct = (_a2 = displaySettings == null ? void 0 : displaySettings.filter) == null ? void 0 : _a2.show_number_matching_product;
4850
- let itemsComponent = [];
4851
- if (["checkbox", "radio", "select"].includes(display.toLowerCase()))
4852
- itemsComponent = items == null ? void 0 : items.map((item) => {
4907
+ const handleFacetValues = (items2) => {
4908
+ return items2 == null ? void 0 : items2.map((item) => {
4909
+ const isFacetHierarchical = Object.hasOwn(item, "children");
4853
4910
  let labelName = item.name;
4911
+ let getValue = isFacetHierarchical ? `${value}.lvl${item.level}` : value;
4854
4912
  if (languageSettings && (languageSettings[item.value] || languageSettings[item.name]))
4855
4913
  labelName = languageSettings[item.value] || languageSettings[item.name];
4856
- let counter = handleConditionNotUpdateFacetDistribution(value) ? (item == null ? void 0 : item.total) || 0 : searchFacetDistribution[value] && searchFacetDistribution[value][item.value] ? searchFacetDistribution[value][item.value] : 0;
4914
+ let counter = handleConditionNotUpdateFacetDistribution(getValue) ? (item == null ? void 0 : item.total) || 0 : searchFacetDistribution[getValue] && searchFacetDistribution[getValue][item.value] ? searchFacetDistribution[getValue][item.value] : 0;
4857
4915
  return {
4858
4916
  ...item,
4859
4917
  labelName,
4860
4918
  counter
4861
4919
  };
4862
4920
  });
4921
+ };
4922
+ const handleFacetCheckbox = (facetValues) => {
4923
+ var _a3;
4924
+ return (_a3 = handleFacetValues(facetValues)) == null ? void 0 : _a3.map((facetValue, index) => {
4925
+ var _a4;
4926
+ const { labelName, value: itemValue, counter, children, level } = facetValue;
4927
+ const isFacetHierarchical = Object.hasOwn(facetValue, "children");
4928
+ const isHasChildren = isFacetHierarchical && (children == null ? void 0 : children.length);
4929
+ const isChecked = Boolean(clickedFacets && ((_a4 = clickedFacets[value]) == null ? void 0 : _a4.includes(itemValue)));
4930
+ return /* @__PURE__ */ jsxRuntimeExports.jsxs(jsxRuntimeExports.Fragment, { children: [
4931
+ /* @__PURE__ */ jsxRuntimeExports.jsxs(
4932
+ "li",
4933
+ {
4934
+ className: `sledge-instant-search__result-filter-checkbox-item ${isFacetHierarchical ? `sledge-instant-search__result-filter-checkbox-item-level sledge-instant-search__result-filter-checkbox-item-level-${level}` : ""}`,
4935
+ children: [
4936
+ /* @__PURE__ */ jsxRuntimeExports.jsx(
4937
+ Checkbox,
4938
+ {
4939
+ id: `${value}_${index}${isFacetHierarchical ? `_${stringToSlug(itemValue)}` : ""}`,
4940
+ name: value,
4941
+ value: itemValue,
4942
+ label: `${labelName}${counter !== void 0 && isShowNumberMatchingProduct ? ` (${counter})` : ""}`,
4943
+ onClick: (e) => handleFilterChange({
4944
+ parentId: value,
4945
+ value: e.currentTarget.value
4946
+ }),
4947
+ checked: isChecked,
4948
+ labelStyle: filter_option_style
4949
+ }
4950
+ ),
4951
+ isHasChildren ? /* @__PURE__ */ jsxRuntimeExports.jsx(
4952
+ motion.div,
4953
+ {
4954
+ initial: false,
4955
+ animate: isChecked ? "open" : "closed",
4956
+ variants: ROTATE_FILTER_ARROW_ANIMATION,
4957
+ className: "sledge-instant-search__result-filter-checkbox-item-level-arrow",
4958
+ children: /* @__PURE__ */ jsxRuntimeExports.jsx(ChevronArrowDownIcon, { width: 15, height: 15, color: "#000000" })
4959
+ }
4960
+ ) : null
4961
+ ]
4962
+ },
4963
+ index
4964
+ ),
4965
+ isHasChildren && isChecked ? handleFacetCheckbox(children) : null
4966
+ ] });
4967
+ });
4968
+ };
4863
4969
  if (display.toLowerCase() === "slider") {
4864
4970
  items = defaultFacetStats[value] && Object.keys(defaultFacetStats[value]).length ? defaultFacetStats[value] : {};
4865
4971
  let defaultValueMin = valueFilterPriceChange[0] || (items == null ? void 0 : items.min);
@@ -4874,7 +4980,10 @@ const ResultProduct = (props) => {
4874
4980
  },
4875
4981
  max: items == null ? void 0 : items.max,
4876
4982
  step: 1,
4877
- setValueCommit: (valueCommit) => handleFilterChange(value, valueCommit),
4983
+ setValueCommit: (valueCommit) => handleFilterChange({
4984
+ parentId: value,
4985
+ value: valueCommit
4986
+ }),
4878
4987
  setValueChange: (valueChange) => setValueFilterPriceChange(valueChange)
4879
4988
  }
4880
4989
  ),
@@ -4883,38 +4992,27 @@ const ResultProduct = (props) => {
4883
4992
  /* @__PURE__ */ jsxRuntimeExports.jsx("div", { className: "sledge-instant-search__result-filter-minmax-field", children: defaultValueMax })
4884
4993
  ] })
4885
4994
  ] });
4886
- } else if (display.toLowerCase() === "checkbox" && (items == null ? void 0 : items.length)) {
4887
- blockComponent = /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: itemsComponent == null ? void 0 : itemsComponent.map((item, index) => {
4888
- var _a3;
4889
- const { labelName, value: itemValue, counter } = item;
4890
- return /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: /* @__PURE__ */ jsxRuntimeExports.jsx(
4891
- Checkbox,
4892
- {
4893
- id: `${value}_${index}`,
4894
- name: value,
4895
- value: itemValue,
4896
- label: `${labelName}${counter !== void 0 && isShowNumberMatchingProduct ? ` (${counter})` : ""}`,
4897
- onClick: (e) => handleFilterChange(value, e.currentTarget.value),
4898
- checked: Boolean(clickedFacets && ((_a3 = clickedFacets[value]) == null ? void 0 : _a3.includes(itemValue))),
4899
- labelStyle: filter_option_style
4900
- }
4901
- ) }, index);
4902
- }) });
4995
+ } else if ((display.toLowerCase() === "checkbox" || display.toLowerCase() === "tree") && (items == null ? void 0 : items.length)) {
4996
+ blockComponent = /* @__PURE__ */ jsxRuntimeExports.jsx(jsxRuntimeExports.Fragment, { children: handleFacetCheckbox(items) });
4903
4997
  } else if (display.toLowerCase() === "radio" && (items == null ? void 0 : items.length)) {
4904
4998
  blockComponent = /* @__PURE__ */ jsxRuntimeExports.jsx("li", { children: /* @__PURE__ */ jsxRuntimeExports.jsx(
4905
4999
  RadioGroup,
4906
5000
  {
4907
5001
  id: value,
4908
5002
  name: value,
4909
- onValueChange: (getValue) => handleFilterChange(value, getValue, true),
4910
- items: items == null ? void 0 : items.map((item) => {
5003
+ onValueChange: (getValue) => handleFilterChange({
5004
+ parentId: value,
5005
+ value: getValue,
5006
+ force: true
5007
+ }),
5008
+ items: (_b2 = handleFacetValues(items)) == null ? void 0 : _b2.map((item) => {
4911
5009
  const { labelName, value: value2, counter } = item;
4912
5010
  return {
4913
5011
  label: `${labelName} ${counter !== void 0 && isShowNumberMatchingProduct ? ` (${counter})` : ""}`,
4914
5012
  value: value2
4915
5013
  };
4916
5014
  }),
4917
- defaultValue: clickedFacets && ((_b2 = clickedFacets[value]) == null ? void 0 : _b2.length) ? clickedFacets[value][0] : "",
5015
+ defaultValue: clickedFacets && ((_c2 = clickedFacets[value]) == null ? void 0 : _c2.length) ? clickedFacets[value][0] : "",
4918
5016
  labelStyle: filter_option_style
4919
5017
  }
4920
5018
  ) });
@@ -4924,8 +5022,12 @@ const ResultProduct = (props) => {
4924
5022
  {
4925
5023
  placeholder: `Select ${label}`,
4926
5024
  name: value,
4927
- onValueChange: (getValue) => handleFilterChange(value, getValue, true),
4928
- items: items == null ? void 0 : items.map((item) => {
5025
+ onValueChange: (getValue) => handleFilterChange({
5026
+ parentId: value,
5027
+ value: getValue,
5028
+ force: true
5029
+ }),
5030
+ items: (_d2 = handleFacetValues(items)) == null ? void 0 : _d2.map((item) => {
4929
5031
  const { labelName, value: value2, counter } = item;
4930
5032
  return {
4931
5033
  label: `${labelName} ${counter !== void 0 && isShowNumberMatchingProduct ? ` (${counter})` : ""}`,
@@ -4947,7 +5049,10 @@ const ResultProduct = (props) => {
4947
5049
  value: item.value,
4948
5050
  rgb: getColorSwatch == null ? void 0 : getColorSwatch.rgb,
4949
5051
  image: getColorSwatch == null ? void 0 : getColorSwatch.image,
4950
- onClick: (e) => handleFilterChange(value, e.currentTarget.value),
5052
+ onClick: (e) => handleFilterChange({
5053
+ parentId: value,
5054
+ value: e.currentTarget.value
5055
+ }),
4951
5056
  defaultChecked: Boolean(clickedFacets && ((_a3 = clickedFacets[value]) == null ? void 0 : _a3.includes(item.value)))
4952
5057
  }
4953
5058
  ) }, index);
@@ -4955,15 +5060,58 @@ const ResultProduct = (props) => {
4955
5060
  }
4956
5061
  return blockComponent;
4957
5062
  };
4958
- const filterVerticalComponents = allowedFilter.map((filter, indexFilter) => {
4959
- const { value, label, display } = filter;
4960
- let items = searchResultFacets[value];
5063
+ const handleHierarchicalFacet = (indexValue) => {
5064
+ var _a2;
5065
+ let hierarchicalFacets = [];
5066
+ for (let level = 0; level < MAX_LIMIT_HIERARCHICAL; level++) {
5067
+ const facets2 = searchResultFacets[`${indexValue}.lvl${level}`];
5068
+ let parent = hierarchicalFacets;
5069
+ for (let facet of facets2) {
5070
+ let names = facet.name.split(hierarchical_separator);
5071
+ if (level > 0) {
5072
+ parent = hierarchicalFacets;
5073
+ for (let i = 0; i < names.length - 1; i++) {
5074
+ let foundIndex = parent.findIndex((f) => f.name.trim().toLowerCase() === names[i].trim().toLowerCase());
5075
+ parent = (_a2 = parent[foundIndex]) == null ? void 0 : _a2.children;
5076
+ }
5077
+ parent.push({
5078
+ ...facet,
5079
+ name: names[names.length - 1].trim(),
5080
+ level,
5081
+ children: []
5082
+ });
5083
+ }
5084
+ if (level === 0)
5085
+ parent.push({
5086
+ ...facet,
5087
+ name: names[names.length - 1].trim(),
5088
+ level: 0,
5089
+ children: []
5090
+ });
5091
+ }
5092
+ }
5093
+ return hierarchicalFacets;
5094
+ };
5095
+ const filterSettings = (filter) => {
5096
+ const { value, display, indexFilter } = filter;
5097
+ let isActive = clickedOpenFilterId === value;
5098
+ let items = display.toLowerCase() === "tree" ? handleHierarchicalFacet(value) : searchResultFacets[value];
4961
5099
  let isRender = Boolean(display.toLowerCase() === "slider" ? items : items == null ? void 0 : items.length);
4962
5100
  let classesUlElement = ["sledge-instant-search__result-filter-item-list"];
4963
- let getFacetComponent = facetComponent(filter);
4964
- if (display.toLowerCase() === "swatch" && (items == null ? void 0 : items.length)) {
5101
+ let getFacetComponent = facetComponent({
5102
+ ...filter,
5103
+ items
5104
+ });
5105
+ if (display.toLowerCase() === "swatch" && (items == null ? void 0 : items.length))
4965
5106
  classesUlElement.push("sledge-instant-search__result-filter-item-color-swatches");
4966
- }
5107
+ if (display.toLowerCase() === "tree")
5108
+ classesUlElement.push("sledge-instant-search__result-filter-item-tree");
5109
+ let isLastIndex = allowedFilter.length - 1 === indexFilter;
5110
+ return { isActive, isRender, classesUlElement, getFacetComponent, isLastIndex };
5111
+ };
5112
+ const filterVerticalComponents = allowedFilter.map((filter, indexFilter) => {
5113
+ const { value, label } = filter;
5114
+ const { isRender, classesUlElement, getFacetComponent } = filterSettings(filter);
4967
5115
  return isRender ? /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge-instant-search__result-filter-item", children: [
4968
5116
  /* @__PURE__ */ jsxRuntimeExports.jsxs("div", { className: "sledge-instant-search__result-filter-item-title", onClick: () => handleOpenFilterVertical(value), children: [
4969
5117
  /* @__PURE__ */ jsxRuntimeExports.jsx("span", { className: "sledge-instant-search__result-filter-title", style: filter_title_style, children: label }),
@@ -4973,16 +5121,8 @@ const ResultProduct = (props) => {
4973
5121
  ] }, indexFilter) : null;
4974
5122
  });
4975
5123
  const filterHorizontalComponents = allowedFilter.map((filter, indexFilter) => {
4976
- const { value, label, display } = filter;
4977
- let isActive = clickedOpenFilterId === value;
4978
- let items = searchResultFacets[value];
4979
- let isRender = Boolean(display.toLowerCase() === "slider" ? items : items == null ? void 0 : items.length);
4980
- let classesUlElement = ["sledge-instant-search__result-filter-item-list"];
4981
- let getFacetComponent = facetComponent(filter);
4982
- if (display.toLowerCase() === "swatch" && (items == null ? void 0 : items.length)) {
4983
- classesUlElement.push("sledge-instant-search__result-filter-item-color-swatches");
4984
- }
4985
- let isLastIndex = allowedFilter.length - 1 === indexFilter;
5124
+ const { value, label } = filter;
5125
+ const { isActive, isRender, classesUlElement, getFacetComponent, isLastIndex } = filterSettings(filter);
4986
5126
  return isRender ? /* @__PURE__ */ jsxRuntimeExports.jsx(React__default.Fragment, { children: /* @__PURE__ */ jsxRuntimeExports.jsx(
4987
5127
  Popover,
4988
5128
  {