@searchcraft/javascript-sdk 0.2.4 → 0.2.6

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.
Files changed (77) hide show
  1. package/dist/cjs/index.cjs.js +2 -2
  2. package/dist/cjs/loader.cjs.js +1 -1
  3. package/dist/cjs/searchcraft-auto-search-form_17.cjs.entry.js +63 -43
  4. package/dist/cjs/searchcraft-auto-search-form_17.cjs.entry.js.map +1 -1
  5. package/dist/cjs/searchcraft-base-search-form.cjs.entry.js +1 -1
  6. package/dist/cjs/searchcraft-javascript-sdk.cjs.js +1 -1
  7. package/dist/cjs/{store-b0a26894.js → store-c44c58ab.js} +8 -7
  8. package/dist/cjs/{store-b0a26894.js.map → store-c44c58ab.js.map} +1 -1
  9. package/dist/cjs/{utils-15f85bca.js → utils-2dc6115c.js} +13 -1
  10. package/dist/cjs/utils-2dc6115c.js.map +1 -0
  11. package/dist/collection/components/searchcraft-base-search-result/searchcraft-base-search-result.js +24 -3
  12. package/dist/collection/components/searchcraft-base-search-result/searchcraft-base-search-result.js.map +1 -1
  13. package/dist/collection/components/searchcraft-base-search-result/searchcraft-base-search-result.module.css +0 -2
  14. package/dist/collection/components/searchcraft-base-search-results/searchcraft-base-search-results.js +20 -1
  15. package/dist/collection/components/searchcraft-base-search-results/searchcraft-base-search-results.js.map +1 -1
  16. package/dist/collection/components/searchcraft-filters-list/searchcraft-filters-list.js +54 -39
  17. package/dist/collection/components/searchcraft-filters-list/searchcraft-filters-list.js.map +1 -1
  18. package/dist/collection/provider/store.js +7 -6
  19. package/dist/collection/provider/store.js.map +1 -1
  20. package/dist/collection/utils/utils.js +11 -0
  21. package/dist/collection/utils/utils.js.map +1 -1
  22. package/dist/components/index.js +2 -2
  23. package/dist/components/{p-8c70054a.js → p-023371c8.js} +10 -6
  24. package/dist/components/p-023371c8.js.map +1 -0
  25. package/dist/components/{p-33bb5c45.js → p-157e5b1a.js} +8 -7
  26. package/dist/components/{p-33bb5c45.js.map → p-157e5b1a.js.map} +1 -1
  27. package/dist/components/{p-ff6c3650.js → p-2bda632c.js} +13 -2
  28. package/dist/components/p-2bda632c.js.map +1 -0
  29. package/dist/components/{p-1204b43a.js → p-b5f97e04.js} +2 -2
  30. package/dist/components/{p-1204b43a.js.map → p-b5f97e04.js.map} +1 -1
  31. package/dist/components/searchcraft-auto-search-form.js +3 -3
  32. package/dist/components/searchcraft-base-search-form.js +2 -2
  33. package/dist/components/searchcraft-base-search-result.js +1 -1
  34. package/dist/components/searchcraft-base-search-results.js +6 -4
  35. package/dist/components/searchcraft-base-search-results.js.map +1 -1
  36. package/dist/components/searchcraft-filters-list.js +55 -40
  37. package/dist/components/searchcraft-filters-list.js.map +1 -1
  38. package/dist/components/searchcraft-input.js +1 -1
  39. package/dist/components/searchcraft-results-info.js +1 -1
  40. package/dist/components/searchcraft-slider.js +1 -1
  41. package/dist/components/searchcraft-toggle-button.js +1 -1
  42. package/dist/esm/index.js +2 -2
  43. package/dist/esm/loader.js +1 -1
  44. package/dist/esm/searchcraft-auto-search-form_17.entry.js +63 -43
  45. package/dist/esm/searchcraft-auto-search-form_17.entry.js.map +1 -1
  46. package/dist/esm/searchcraft-base-search-form.entry.js +1 -1
  47. package/dist/esm/searchcraft-javascript-sdk.js +1 -1
  48. package/dist/esm/{store-97358312.js → store-9e0b0710.js} +8 -7
  49. package/dist/esm/{store-97358312.js.map → store-9e0b0710.js.map} +1 -1
  50. package/dist/esm/{utils-dbb6302b.js → utils-a3373179.js} +13 -2
  51. package/dist/esm/utils-a3373179.js.map +1 -0
  52. package/dist/searchcraft-javascript-sdk/index.esm.js +1 -1
  53. package/dist/searchcraft-javascript-sdk/p-2bda632c.js +2 -0
  54. package/dist/searchcraft-javascript-sdk/p-2bda632c.js.map +1 -0
  55. package/dist/searchcraft-javascript-sdk/{p-acca6173.entry.js → p-63b3b565.entry.js} +2 -2
  56. package/dist/searchcraft-javascript-sdk/{p-cd489e98.js → p-901fee50.js} +2 -2
  57. package/dist/searchcraft-javascript-sdk/p-901fee50.js.map +1 -0
  58. package/dist/searchcraft-javascript-sdk/p-c2c4f6b7.entry.js +2 -0
  59. package/dist/searchcraft-javascript-sdk/p-c2c4f6b7.entry.js.map +1 -0
  60. package/dist/searchcraft-javascript-sdk/searchcraft-javascript-sdk.esm.js +1 -1
  61. package/dist/searchcraft-javascript-sdk/searchcraft-javascript-sdk.esm.js.map +1 -1
  62. package/dist/types/components/searchcraft-base-search-result/searchcraft-base-search-result.d.ts +1 -0
  63. package/dist/types/components/searchcraft-base-search-results/searchcraft-base-search-results.d.ts +1 -0
  64. package/dist/types/components/searchcraft-filters-list/searchcraft-filters-list.d.ts +1 -5
  65. package/dist/types/components.d.ts +4 -0
  66. package/dist/types/utils/utils.d.ts +11 -0
  67. package/package.json +1 -1
  68. package/dist/cjs/utils-15f85bca.js.map +0 -1
  69. package/dist/components/p-8c70054a.js.map +0 -1
  70. package/dist/components/p-ff6c3650.js.map +0 -1
  71. package/dist/esm/utils-dbb6302b.js.map +0 -1
  72. package/dist/searchcraft-javascript-sdk/p-1a0e85ee.entry.js +0 -2
  73. package/dist/searchcraft-javascript-sdk/p-1a0e85ee.entry.js.map +0 -1
  74. package/dist/searchcraft-javascript-sdk/p-cd489e98.js.map +0 -1
  75. package/dist/searchcraft-javascript-sdk/p-ff6c3650.js +0 -2
  76. package/dist/searchcraft-javascript-sdk/p-ff6c3650.js.map +0 -1
  77. /package/dist/searchcraft-javascript-sdk/{p-acca6173.entry.js.map → p-63b3b565.entry.js.map} +0 -0
@@ -1,6 +1,6 @@
1
1
  import { r as registerInstance, c as createEvent, h, F as Fragment } from './index-0ac5bb53.js';
2
- import { u as useSearchcraftStore, g } from './store-97358312.js';
3
- import { p as parseCustomStyles, a as parseSearchKeys, s as serializeStyles, e as extractDynamicProperties, g as getFormattedTimeFromNow } from './utils-dbb6302b.js';
2
+ import { u as useSearchcraftStore, g } from './store-9e0b0710.js';
3
+ import { p as parseCustomStyles, a as parseSearchKeys, s as serializeStyles, e as extractDynamicProperties, g as getFormattedTimeFromNow, f as flattenFacets } from './utils-a3373179.js';
4
4
  import { c as classNames } from './index-72ac5051.js';
5
5
 
6
6
  const searchcraftAutoSearchFormModuleCss = ":root{--font-stack:Helvetica, Arial, sans-serif}.formLTR{font-family:var(--font-stack);text-align:left;width:100%}.formRTL{font-family:var(--font-stack);text-align:right;width:100%}";
@@ -109,7 +109,7 @@ const SearchcraftAutoSearchForm = class {
109
109
  };
110
110
  SearchcraftAutoSearchForm.style = SearchcraftAutoSearchFormStyle0;
111
111
 
112
- const searchcraftBaseSearchResultModuleCss = "@charset \"UTF-8\";:root{--font-stack:Helvetica, Arial, sans-serif}.interactiveResultContainerLight{align-items:flex-start;border-radius:16px;display:flex;flex-direction:column;gap:16px;padding:8px;position:relative;background-color:#FAFAFA}@media (min-width: 600px){.interactiveResultContainerLight{flex-direction:row}}.interactiveResultContainerDark{align-items:flex-start;border-radius:16px;display:flex;flex-direction:column;gap:16px;padding:8px;position:relative;background-color:#2E2E2E}@media (min-width: 600px){.interactiveResultContainerDark{flex-direction:row}}.resultContainer{align-items:flex-start;display:flex;flex-direction:column;gap:16px}@media (min-width: 600px){.resultContainer{flex-direction:row}}.interactiveIconLarge{display:inline-block;position:absolute;right:5px;top:8px}@media (max-width: 600px){.interactiveIconLarge{display:none}}.interactiveIconSmall{display:inline-block;position:absolute;right:5px;top:-2px}@media (min-width: 600px){.interactiveIconSmall{display:none}}.imageContainer{max-width:100%}.contentContainer{max-height:100%;max-width:100%}@media (min-width: 600px){.contentContainer{max-width:50%}}.secondaryContentContainer{display:flex}.imageLight{aspect-ratio:2/1;border-radius:8px;max-height:100%;max-width:100%;border:1px solid #D9D9D9}.imageDark{aspect-ratio:2/1;border-radius:8px;max-height:100%;max-width:100%;border:1px solid #333}.headingLight{font-family:var(--font-stack);font-size:16px;font-weight:700;line-height:20px;margin-bottom:4px;margin-top:0;position:relative;color:#292929}.headingDark{font-family:var(--font-stack);font-size:16px;font-weight:700;line-height:20px;margin-bottom:4px;margin-top:0;position:relative;color:#FFF}.subheadingLight{font-family:var(--font-stack);font-size:12px;font-weight:400;line-height:16px;margin-bottom:4px;margin-top:0px;color:#737373}.subheadingDark{font-family:var(--font-stack);font-size:12px;font-weight:400;line-height:16px;margin-bottom:4px;margin-top:0px;color:#BFBFBF}.primaryContentLight{font-family:var(--font-stack);font-size:16px;font-weight:400;line-height:20px;margin-bottom:4px;margin-top:0px;color:#404040}.primaryContentDark{font-family:var(--font-stack);font-size:16px;font-weight:400;line-height:20px;margin-bottom:4px;margin-top:0px;color:#E6E6E6}.secondaryContentLight{font-family:var(--font-stack);font-size:16px;font-weight:400;line-height:20px;margin-bottom:4px;margin-top:0px;color:#404040}.secondaryContentLight::after{content:\"•\";color:#404040;font-size:1em;margin-left:5px;margin-right:5px}.secondaryContentDark{font-family:var(--font-stack);font-size:16px;font-weight:400;line-height:20px;margin-bottom:4px;margin-top:0px;color:#E6E6E6}.tertiaryContentLight{font-family:var(--font-stack);font-size:16px;font-weight:400;line-height:20px;margin-bottom:4px;margin-top:0px;color:#404040}.tertiaryContentDark{font-family:var(--font-stack);font-size:16px;font-weight:400;line-height:20px;margin-bottom:4px;margin-top:0px;color:#E6E6E6}";
112
+ const searchcraftBaseSearchResultModuleCss = "@charset \"UTF-8\";:root{--font-stack:Helvetica, Arial, sans-serif}.interactiveResultContainerLight{align-items:flex-start;border-radius:16px;display:flex;flex-direction:column;gap:16px;padding:8px;position:relative;background-color:#FAFAFA}@media (min-width: 600px){.interactiveResultContainerLight{flex-direction:row}}.interactiveResultContainerDark{align-items:flex-start;border-radius:16px;display:flex;flex-direction:column;gap:16px;padding:8px;position:relative;background-color:#2E2E2E}@media (min-width: 600px){.interactiveResultContainerDark{flex-direction:row}}.resultContainer{align-items:flex-start;display:flex;flex-direction:column;gap:16px}@media (min-width: 600px){.resultContainer{flex-direction:row}}.interactiveIconLarge{display:inline-block;position:absolute;right:5px;top:8px}@media (max-width: 600px){.interactiveIconLarge{display:none}}.interactiveIconSmall{display:inline-block;position:absolute;right:5px;top:-2px}@media (min-width: 600px){.interactiveIconSmall{display:none}}.imageContainer{max-width:100%}.contentContainer{max-height:100%;max-width:100%}@media (min-width: 600px){.contentContainer{max-width:50%}}.secondaryContentContainer{display:flex}.imageLight{border-radius:8px;max-height:100%;max-width:100%;border:1px solid #D9D9D9}.imageDark{border-radius:8px;max-height:100%;max-width:100%;border:1px solid #333}.headingLight{font-family:var(--font-stack);font-size:16px;font-weight:700;line-height:20px;margin-bottom:4px;margin-top:0;position:relative;color:#292929}.headingDark{font-family:var(--font-stack);font-size:16px;font-weight:700;line-height:20px;margin-bottom:4px;margin-top:0;position:relative;color:#FFF}.subheadingLight{font-family:var(--font-stack);font-size:12px;font-weight:400;line-height:16px;margin-bottom:4px;margin-top:0px;color:#737373}.subheadingDark{font-family:var(--font-stack);font-size:12px;font-weight:400;line-height:16px;margin-bottom:4px;margin-top:0px;color:#BFBFBF}.primaryContentLight{font-family:var(--font-stack);font-size:16px;font-weight:400;line-height:20px;margin-bottom:4px;margin-top:0px;color:#404040}.primaryContentDark{font-family:var(--font-stack);font-size:16px;font-weight:400;line-height:20px;margin-bottom:4px;margin-top:0px;color:#E6E6E6}.secondaryContentLight{font-family:var(--font-stack);font-size:16px;font-weight:400;line-height:20px;margin-bottom:4px;margin-top:0px;color:#404040}.secondaryContentLight::after{content:\"•\";color:#404040;font-size:1em;margin-left:5px;margin-right:5px}.secondaryContentDark{font-family:var(--font-stack);font-size:16px;font-weight:400;line-height:20px;margin-bottom:4px;margin-top:0px;color:#E6E6E6}.tertiaryContentLight{font-family:var(--font-stack);font-size:16px;font-weight:400;line-height:20px;margin-bottom:4px;margin-top:0px;color:#404040}.tertiaryContentDark{font-family:var(--font-stack);font-size:16px;font-weight:400;line-height:20px;margin-bottom:4px;margin-top:0px;color:#E6E6E6}";
113
113
  const SearchcraftBaseSearchResultStyle0 = searchcraftBaseSearchResultModuleCss;
114
114
 
115
115
  const SearchcraftBaseSearchResult = class {
@@ -140,6 +140,7 @@ const SearchcraftBaseSearchResult = class {
140
140
  this.subheadingText = '';
141
141
  this.tertiaryContent = '';
142
142
  this.themeMode = 'light';
143
+ this.placeImageRight = false;
143
144
  }
144
145
  parseStyles() {
145
146
  try {
@@ -153,11 +154,13 @@ const SearchcraftBaseSearchResult = class {
153
154
  render() {
154
155
  const isLightTheme = this.themeMode === 'light';
155
156
  const styles = this.parseStyles();
156
- return (h("div", { key: '91cfc671b0b99082915df3eaafa053a9a7f77929', class: this.isInteractive
157
+ const imageContainer = this.imageSource && (h("div", { key: '1dee969549e02c262a9fdf050438630961d1954e', class: 'imageContainer' }, h("img", { key: '2a08fd81d563ad2f18e91d22449afefb772244c8', alt: this.imageDescription, class: isLightTheme ? 'imageLight' : 'imageDark', src: this.imageSource, style: styles.image || {} })));
158
+ const contentContainer = (h("div", { key: '93f350bba36c296377dc09824d86631e4f731e78', class: 'contentContainer' }, h("h2", { key: 'd630e930eba15b86c84f7e62f73d1d3539c3650d', class: isLightTheme ? 'headingLight' : 'headingDark', style: styles.heading || {} }, this.headingText), h("h3", { key: '0f8639094f2f64695d887b2de6fc1d777564cbb2', class: isLightTheme ? 'subheadingLight' : 'subheadingDark', style: styles.subheading || {} }, this.subheadingText), h("p", { key: 'e8562ca0a438f9ff0848920a5bae1e208eb3ae72', class: isLightTheme ? 'primaryContentLight' : 'primaryContentDark', style: styles.primaryContent || {} }, this.primaryContent), h("div", { key: 'dd97fb5946a1a50ccba31ae97c8b5b6e0cac91d9', class: 'secondaryContentContainer' }, h("p", { key: '9c6d705bfbd4eccb24f5afcbaad9ec92ca6fda9f', class: isLightTheme ? 'secondaryContentLight' : 'secondaryContentDark', style: styles.secondaryContent || {} }, this.secondaryContent), h("p", { key: '7147e47a9ed408066439431329cda75495567227', class: isLightTheme ? 'tertiaryContentLight' : 'tertiaryContentDark', style: styles.tertiaryContent || {} }, this.tertiaryContent)), this.buttonText && (h("button", { key: 'e620382ea1fe2f0e60645330ec087f767ff535a0', onClick: this.handleButtonClick, style: styles.button || {}, type: 'button' }, this.buttonText))));
159
+ return (h("div", { key: 'a104499c8adaa7d57743aaea20ee4af7caf6bdb9', class: this.isInteractive
157
160
  ? isLightTheme
158
161
  ? 'interactiveResultContainerLight'
159
162
  : 'interactiveResultContainerDark'
160
- : 'resultContainer', onKeyDown: this.keyDownCallback, onClick: this.handleContainerClick, style: styles.container || {}, tabindex: '0' }, h("div", { key: 'ccda236ef60aee285472155889c5490c69a86415', class: 'imageContainer' }, h("img", { key: 'e55d743952e2997d91f6486436e3a7955ffc1dcc', alt: this.imageDescription, class: isLightTheme ? 'imageLight' : 'imageDark', src: this.imageSource, style: styles.image || {} })), h("div", { key: 'b0e831c0c7bfef46b8b6da4e84536adf3ebd7158', class: 'contentContainer' }, h("h2", { key: '54137612623a39d711f4e3c888bf2015b6fb9500', class: isLightTheme ? 'headingLight' : 'headingDark', style: styles.heading || {} }, this.headingText), h("h3", { key: 'de46df990be3d0b5d2134d272e1766e911ab094a', class: isLightTheme ? 'subheadingLight' : 'subheadingDark', style: styles.subheading || {} }, this.subheadingText), h("p", { key: 'd9e7656bc739b0dd2267f86ac51b17d9ca16da6a', class: isLightTheme ? 'primaryContentLight' : 'primaryContentDark', style: styles.primaryContent || {} }, this.primaryContent), h("div", { key: 'd05813b3da29b8b21c2e370db9c0cbc7b48b9556', class: 'secondaryContentContainer' }, h("p", { key: 'e8d2ede937705a5bd88927779ee24e35ba2efbd8', class: isLightTheme ? 'secondaryContentLight' : 'secondaryContentDark', style: styles.secondaryContent || {} }, this.secondaryContent), h("p", { key: '2f9b9f603d55bcefe8347675cb31f705b1f7a0e8', class: isLightTheme ? 'tertiaryContentLight' : 'tertiaryContentDark', style: styles.tertiaryContent || {} }, this.tertiaryContent)), this.buttonText && (h("button", { key: '58724046c9704974cb3ae1c34335ebb7131b91ab', onClick: this.handleButtonClick, style: styles.button || {}, type: 'button' }, this.buttonText)))));
163
+ : 'resultContainer', onKeyDown: this.keyDownCallback, onClick: this.handleContainerClick, style: styles.container || {}, tabindex: '0' }, this.placeImageRight ? (h(Fragment, null, contentContainer, imageContainer)) : (h(Fragment, null, imageContainer, contentContainer))));
161
164
  }
162
165
  };
163
166
  SearchcraftBaseSearchResult.style = SearchcraftBaseSearchResultStyle0;
@@ -175,6 +178,7 @@ const SearchcraftBaseSearchResults = class {
175
178
  this.formatTime = true;
176
179
  this.placeAdAtEnd = false;
177
180
  this.placeAdAtStart = true;
181
+ this.placeResultImageRight = false;
178
182
  this.hasSearched = false;
179
183
  this.query = '';
180
184
  this.searchResults = null;
@@ -232,7 +236,7 @@ const SearchcraftBaseSearchResults = class {
232
236
  }
233
237
  }
234
238
  }
235
- return (h("searchcraft-base-search-result", { "button-callback": () => console.log('button callback'), "custom-styles": serializedStyles, "image-source": dynamicProperties[parsedSearchKeys[parsedSearchKeys.length - 1]], "is-interactive": true, key: `${document.document_id}-${index}`, "keydown-callback": () => console.log('keydown'), "heading-text": dynamicProperties[parsedSearchKeys[0]], "primary-content": dynamicProperties[parsedSearchKeys[2]], "result-callback": () => console.log('interactive element'), "secondary-content": dynamicProperties[parsedSearchKeys[3]], "subheading-text": dynamicProperties[parsedSearchKeys[1]], "tertiary-content": dynamicProperties[parsedSearchKeys[4]] }));
239
+ return (h("searchcraft-base-search-result", { "button-callback": () => console.log('button callback'), "custom-styles": serializedStyles, "image-source": dynamicProperties[parsedSearchKeys[parsedSearchKeys.length - 1]], "is-interactive": true, key: `${document.document_id}-${index}`, "keydown-callback": () => console.log('keydown'), "heading-text": dynamicProperties[parsedSearchKeys[0]], "place-image-right": this.placeResultImageRight, "primary-content": dynamicProperties[parsedSearchKeys[2]], "result-callback": () => console.log('interactive element'), "secondary-content": dynamicProperties[parsedSearchKeys[3]], "subheading-text": dynamicProperties[parsedSearchKeys[1]], "tertiary-content": dynamicProperties[parsedSearchKeys[4]] }));
236
240
  });
237
241
  const finalComponents = [];
238
242
  if (this.placeAdAtStart) {
@@ -334,29 +338,42 @@ const SearchcraftFiltersList = class {
334
338
  else {
335
339
  this.selectedFilters.delete(value);
336
340
  }
337
- const selectedFiltersArray = Array.from(this.selectedFilters);
338
- this.filtersUpdated.emit(selectedFiltersArray);
339
- this.searchStore.setSelectedFilters(selectedFiltersArray);
341
+ const deduplicatedFilters = this.deduplicatePaths(Array.from(this.selectedFilters));
342
+ this.filtersUpdated.emit(deduplicatedFilters);
343
+ this.searchStore.setSelectedFilters(deduplicatedFilters);
340
344
  this.searchStore.search();
341
345
  };
342
346
  this.filters = [];
343
347
  this.dynamicFilters = [];
344
- this.initialFilters = [];
345
348
  this.isRequesting = false;
346
- this.originalFilterCounts = {};
347
349
  this.query = '';
348
350
  this.resultsCount = 0;
349
351
  this.selectedFilters = new Set();
350
352
  }
351
353
  connectedCallback() {
354
+ var _a;
355
+ const state = this.searchStore; // Fetch the initial state
356
+ // Initial population of facets if available
357
+ if ((_a = state.searchResults) === null || _a === void 0 ? void 0 : _a.data.facets) {
358
+ this.populateFiltersFromFacets(state.searchResults.data.facets);
359
+ }
352
360
  this.unsubscribe = useSearchcraftStore.subscribe((state) => {
353
361
  var _a, _b, _c, _d;
354
- this.isRequesting = state.isRequesting;
362
+ if (!state.query || state.query.trim().length === 0) {
363
+ if (this.selectedFilters.size > 0) {
364
+ this.selectedFilters.clear();
365
+ this.filtersUpdated.emit([]);
366
+ if (this.searchStore.selectedFilters.length > 0) {
367
+ this.searchStore.setSelectedFilters([]);
368
+ }
369
+ }
370
+ }
355
371
  this.query = state.query || '';
372
+ this.isRequesting = state.isRequesting;
356
373
  this.resultsCount = ((_c = (_b = (_a = state.searchResults) === null || _a === void 0 ? void 0 : _a.data) === null || _b === void 0 ? void 0 : _b.hits) === null || _c === void 0 ? void 0 : _c.length) || 0;
357
- const facets = (_d = state.searchResults) === null || _d === void 0 ? void 0 : _d.data.facets;
358
- if (facets) {
359
- this.populateFiltersFromFacets(facets);
374
+ // Populate filters when facets are updated
375
+ if ((_d = state.searchResults) === null || _d === void 0 ? void 0 : _d.data.facets) {
376
+ this.populateFiltersFromFacets(state.searchResults.data.facets);
360
377
  }
361
378
  });
362
379
  }
@@ -367,24 +384,28 @@ const SearchcraftFiltersList = class {
367
384
  }
368
385
  populateFiltersFromFacets(facets) {
369
386
  var _a;
370
- const newFilters = Object.entries(((_a = facets.section) === null || _a === void 0 ? void 0 : _a.counts) || {}).map(([key, count]) => {
371
- const filterValue = key;
372
- this.originalFilterCounts[filterValue] = `${count}`;
373
- return {
374
- label: `${key.replace(/^\//, '')} (${count})`,
375
- value: filterValue,
376
- };
387
+ const newFilters = flattenFacets(((_a = facets[0]) === null || _a === void 0 ? void 0 : _a.section) || []);
388
+ const filtersMap = new Map();
389
+ newFilters.forEach((filter) => {
390
+ const key = filter.value.split('/').pop() || '';
391
+ const existingFilter = filtersMap.get(key);
392
+ if (!existingFilter ||
393
+ filter.value.length < existingFilter.value.length) {
394
+ filtersMap.set(key, filter);
395
+ }
377
396
  });
378
- // Update dynamic filters while preserving the initial filters
379
- const updatedFilters = [
380
- ...this.initialFilters,
381
- ...newFilters.filter((filter) => !this.initialFilters.some((initial) => initial.value === filter.value)),
382
- ];
383
- this.dynamicFilters = updatedFilters;
384
- // Store the initial filters only once
385
- if (this.initialFilters.length === 0) {
386
- this.initialFilters = [...updatedFilters];
387
- }
397
+ this.dynamicFilters = Array.from(filtersMap.values());
398
+ }
399
+ deduplicatePaths(filters) {
400
+ const pathMap = new Map();
401
+ filters.forEach((path) => {
402
+ const key = path.split('/').pop() || '';
403
+ const existingPath = pathMap.get(key);
404
+ if (!existingPath || path.length < existingPath.length) {
405
+ pathMap.set(key, path);
406
+ }
407
+ });
408
+ return Array.from(pathMap.values());
388
409
  }
389
410
  formatLabel(label) {
390
411
  return label
@@ -397,17 +418,16 @@ const SearchcraftFiltersList = class {
397
418
  if (!this.query || this.resultsCount === 0) {
398
419
  return null;
399
420
  }
400
- const filtersToRender = this.initialFilters.map((initialFilter) => {
401
- const isChecked = this.selectedFilters.has(initialFilter.value);
402
- const dynamicChildren = this.dynamicFilters.filter((dynamicFilter) => dynamicFilter.value.startsWith(initialFilter.value) &&
403
- dynamicFilter.value !== initialFilter.value);
404
- return Object.assign(Object.assign({}, initialFilter), { isChecked, children: dynamicChildren });
405
- });
406
- return (h("div", { class: 'filtersList' }, filtersToRender.map((filter) => (h("div", { key: filter.value }, h("label", { class: 'checkboxLabel' }, h("input", { class: 'filterCheckbox', checked: filter.isChecked, onChange: (event) => this.handleFilterChange(filter.value, event.target.checked), type: 'checkbox', value: filter.value }), this.formatLabel(filter.label)), filter.isChecked &&
407
- filter.children.map((childFilter) => {
408
- const childLabel = childFilter.label.split('/').pop();
409
- return (h("label", { class: 'childCheckboxLabel', key: childFilter.value, style: { marginLeft: '20px' } }, h("input", { class: 'childFilterCheckbox', checked: this.selectedFilters.has(childFilter.value), onChange: (event) => this.handleFilterChange(childFilter.value, event.target.checked), type: 'checkbox', value: childFilter.value }), this.formatLabel(childLabel || '')));
410
- }))))));
421
+ const filtersToRender = this.dynamicFilters.filter((filter) => !filter.value.includes('/', filter.value.indexOf('/') + 1));
422
+ return (h("div", { class: 'filtersList' }, filtersToRender.map((filter) => {
423
+ const isChecked = this.selectedFilters.has(filter.value);
424
+ const children = this.dynamicFilters.filter((child) => child.value.startsWith(`${filter.value}/`) &&
425
+ child.value !== filter.value);
426
+ return (h("div", { key: filter.value }, h("label", { class: 'checkboxLabel' }, h("input", { class: 'filterCheckbox', checked: isChecked, onChange: (event) => this.handleFilterChange(filter.value, event.target.checked), type: 'checkbox' }), this.formatLabel(filter.label)), children.map((child) => {
427
+ const isChildChecked = this.selectedFilters.has(child.value);
428
+ return (h("label", { class: 'childCheckboxLabel', key: child.value, style: { marginLeft: '20px' } }, h("input", { class: 'childFilterCheckbox', checked: isChildChecked, onChange: (event) => this.handleFilterChange(child.value, event.target.checked), type: 'checkbox' }), this.formatLabel(child.label.split('/').pop() || '')));
429
+ })));
430
+ })));
411
431
  }
412
432
  };
413
433
  SearchcraftFiltersList.style = SearchcraftFiltersListStyle0;