@searchcraft/javascript-sdk 0.10.4 → 0.10.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 (65) hide show
  1. package/dist/components/index.d.ts +52 -20
  2. package/dist/components/index.js +4 -4
  3. package/dist/components/{p-9d2e55a7.js → p-2735dceb.js} +3 -3
  4. package/dist/components/{p-9d2e55a7.js.map → p-2735dceb.js.map} +1 -1
  5. package/dist/components/p-4dd1995c.js +193 -0
  6. package/dist/components/p-4dd1995c.js.map +1 -0
  7. package/dist/components/{p-35ee16e2.js → p-6e5ed641.js} +2 -2
  8. package/dist/components/{p-35ee16e2.js.map → p-6e5ed641.js.map} +1 -1
  9. package/dist/components/{p-4c610bc4.js → p-75134ca7.js} +2 -2
  10. package/dist/components/{p-4c610bc4.js.map → p-75134ca7.js.map} +1 -1
  11. package/dist/components/{p-eb633481.js → p-9f4c50ed.js} +3 -3
  12. package/dist/components/{p-eb633481.js.map → p-9f4c50ed.js.map} +1 -1
  13. package/dist/components/{p-6065aee1.js → p-a7d611cd.js} +17 -12
  14. package/dist/components/p-a7d611cd.js.map +1 -0
  15. package/dist/components/{p-6ed5cca1.js → p-aba24c85.js} +4 -4
  16. package/dist/components/{p-6ed5cca1.js.map → p-aba24c85.js.map} +1 -1
  17. package/dist/components/p-b194d081.js +406 -0
  18. package/dist/components/p-b194d081.js.map +1 -0
  19. package/dist/components/{p-60fd824d.js → p-b54873ff.js} +371 -348
  20. package/dist/components/p-b54873ff.js.map +1 -0
  21. package/dist/components/p-d54771ef.js +182 -0
  22. package/dist/components/p-d54771ef.js.map +1 -0
  23. package/dist/components/{p-2d975f19.js → p-f2976b33.js} +2 -2
  24. package/dist/components/{p-2d975f19.js.map → p-f2976b33.js.map} +1 -1
  25. package/dist/components/searchcraft-ad.js +1 -1
  26. package/dist/components/searchcraft-facet-list.js +1 -1
  27. package/dist/components/searchcraft-filter-panel.js +13 -18
  28. package/dist/components/searchcraft-filter-panel.js.map +1 -1
  29. package/dist/components/searchcraft-input-form.js +1 -1
  30. package/dist/components/searchcraft-pagination.js +1 -1
  31. package/dist/components/searchcraft-popover-button.js +1 -1
  32. package/dist/components/searchcraft-popover-footer.js +1 -1
  33. package/dist/components/searchcraft-popover-form.js +6 -6
  34. package/dist/components/searchcraft-popover-list-item.js +1 -1
  35. package/dist/components/searchcraft-popover-list-view.js +1 -1
  36. package/dist/components/searchcraft-results-info.js +2 -2
  37. package/dist/components/searchcraft-search-result.js +1 -1
  38. package/dist/components/searchcraft-search-results-per-page.js +1 -1
  39. package/dist/components/searchcraft-search-results.js +3 -3
  40. package/dist/components/searchcraft-slider.js +1 -1
  41. package/dist/components/searchcraft-theme.js +1 -1
  42. package/dist/components/searchcraft-theme.js.map +1 -1
  43. package/dist/components/searchcraft-toggle-button.js +1 -1
  44. package/dist/hydrate/index.js +710 -434
  45. package/dist/hydrate/index.mjs +710 -434
  46. package/dist/themes/hologram.css +1 -1
  47. package/dist/themes/hologram.css.map +1 -1
  48. package/dist/types/components/searchcraft-facet-list/searchcraft-facet-list.d.ts +33 -14
  49. package/dist/types/components/searchcraft-filter-panel/searchcraft-filter-panel.d.ts +2 -2
  50. package/dist/types/components/searchcraft-input-form/searchcraft-input-form.d.ts +6 -0
  51. package/dist/types/components/searchcraft-slider/searchcraft-slider.d.ts +10 -4
  52. package/dist/types/components.d.ts +23 -7
  53. package/dist/types/store/SearchcraftStore.types.d.ts +5 -3
  54. package/dist/types/utils/facets.d.ts +30 -3
  55. package/dist/types/utils/throttle.d.ts +14 -0
  56. package/dist/types/utils/units.d.ts +33 -0
  57. package/package.json +3 -3
  58. package/dist/components/p-163402fb.js +0 -291
  59. package/dist/components/p-163402fb.js.map +0 -1
  60. package/dist/components/p-4d37616e.js +0 -105
  61. package/dist/components/p-4d37616e.js.map +0 -1
  62. package/dist/components/p-6065aee1.js.map +0 -1
  63. package/dist/components/p-60fd824d.js.map +0 -1
  64. package/dist/components/p-7c650118.js +0 -110
  65. package/dist/components/p-7c650118.js.map +0 -1
@@ -1,6 +1,6 @@
1
1
  import { p as proxyCustomElement, H, c as createEvent, h } from './p-5365011f.js';
2
2
  import { c as classNames } from './p-5cdc6210.js';
3
- import { s as searchcraftStore } from './p-60fd824d.js';
3
+ import { s as searchcraftStore } from './p-b54873ff.js';
4
4
  import { d as defineCustomElement$3 } from './p-acf23bab.js';
5
5
  import { d as defineCustomElement$2 } from './p-f2585cdf.js';
6
6
  import { d as defineCustomElement$1 } from './p-1adf78b9.js';
@@ -33,6 +33,12 @@ const SearchcraftInputForm = /*@__PURE__*/ proxyCustomElement(class SearchcraftI
33
33
  * The input element's placeholder value.
34
34
  */
35
35
  placeholderValue = 'Enter Search';
36
+ /**
37
+ * The placeholder's render behavior.
38
+ * 'hide-on-focus' - Hide the placeholder text immediately when the input form gains focus.
39
+ * 'hide-on-text-entered' - Only hide the placeholder when the input form has text entered into it.
40
+ */
41
+ placeholderBehavior;
36
42
  /**
37
43
  * When the input becomes focused.
38
44
  */
@@ -76,22 +82,18 @@ const SearchcraftInputForm = /*@__PURE__*/ proxyCustomElement(class SearchcraftI
76
82
  handleInput = (event) => {
77
83
  const input = event.target;
78
84
  this.inputValue = input.value;
85
+ this.searchcraftStore.setSearchTerm(input.value);
79
86
  if (!this.autoSearch) {
80
87
  return;
81
88
  }
82
- this.performSearch(input.value);
89
+ this.performSearch();
83
90
  };
84
- performSearch = async (searchTerm) => {
85
- if (searchTerm === this.searchTerm) {
86
- return;
87
- }
88
- this.searchcraftStore.setSearchTerm(searchTerm.trim());
91
+ performSearch = async () => {
89
92
  this.error = false;
90
93
  try {
91
94
  await this.searchcraftStore.search();
92
95
  }
93
96
  catch (error) {
94
- console.error(`Search for ${searchTerm} failed:`, error);
95
97
  this.error = true;
96
98
  }
97
99
  };
@@ -106,7 +108,7 @@ const SearchcraftInputForm = /*@__PURE__*/ proxyCustomElement(class SearchcraftI
106
108
  };
107
109
  handleFormSubmit = async (event) => {
108
110
  event.preventDefault();
109
- await this.performSearch(this.inputValue);
111
+ await this.performSearch();
110
112
  };
111
113
  render() {
112
114
  const isShowingClearButton = this.inputValue.length > 0;
@@ -119,9 +121,11 @@ const SearchcraftInputForm = /*@__PURE__*/ proxyCustomElement(class SearchcraftI
119
121
  const inputGridStyles = {
120
122
  gap: shouldHaveVerticalGap ? '4px 8px' : '0px 8px',
121
123
  };
122
- return (h("form", { key: '6af89b2ab634e0f3e0ef575f98f33d091602f95a', class: 'searchcraft-input-form', onSubmit: this.handleFormSubmit }, h("div", { key: '93fea8e2b80468afeb6014122d5b749d74bfaf35', class: inputGridClassNames, style: inputGridStyles }, h("div", { key: '1e5a416843b99aec68c4672a9c78f607347dc9d1', class: 'searchcraft-input-form-button' }, h("searchcraft-button", { key: 'c38c1df0ce20f914ed76fbc0acad5a22b40e6fff', onButtonClick: this.handleFormSubmit, label: this.buttonLabel })), this.inputLabel && (h("div", { key: '2169a4466b0fdc8075c0dc74da442aef28a84d65', class: 'searchcraft-input-form-label' }, h("searchcraft-input-label", { key: 'a263b5aa2a4d50d297f06c1fe9e6afb64763f097', label: this.inputLabel }))), this.error && (h("div", { key: '49be2ac0f2d01916e5ea533e6406ee9d4d932178', class: 'searchcraft-input-form-error-message' }, h("searchcraft-error-message", { key: '310c9aebcf580d4abe92d288c6b70a5adf083f8e' }, "Something went wrong."))), h("div", { key: 'f4702e368815e049586e97cf59541b2dc5460fc0', class: 'searchcraft-input-form-input-wrapper' }, h("input", { key: 'a8cddd5e937eee1d30fb98eaaa3dbffe96c192ce', autoComplete: 'off', class: 'searchcraft-input-form-input', onFocus: () => this.inputFocus?.emit(), onBlur: () => this.inputBlur?.emit(), onInput: (event) => {
124
+ return (h("form", { key: 'd0654def009278279b7edeeccc6044d999c0d5b0', class: 'searchcraft-input-form', onSubmit: this.handleFormSubmit }, h("div", { key: '27978b08e46e0f8ecdf6dc95a74c962d85f5e9ff', class: inputGridClassNames, style: inputGridStyles }, h("div", { key: '1f7cecc80a84bfc46c994971cd751d2b65af6d83', class: 'searchcraft-input-form-button' }, h("searchcraft-button", { key: 'b3f2078604c380eef895be103b2bdf5cef6bca84', onButtonClick: this.handleFormSubmit, label: this.buttonLabel })), this.inputLabel && (h("div", { key: 'b33c0d3cbb3512964c3a47a2c354a610fa6faa09', class: 'searchcraft-input-form-label' }, h("searchcraft-input-label", { key: 'e620088318c82e2e70d885bd3ee2c88ef8118e7c', label: this.inputLabel }))), this.error && (h("div", { key: 'c3a20576917aaa33cc12df5ee5b479f87d628de7', class: 'searchcraft-input-form-error-message' }, h("searchcraft-error-message", { key: 'f48e54a236b7a33fa55bab7f29d3b321be0bbb77' }, "Something went wrong."))), h("div", { key: 'ebda089a3b8698892fd6cebcbaf89582a1bb21a2', class: 'searchcraft-input-form-input-wrapper' }, h("input", { key: 'd7ea7b49f7d65067924168fc281033841a71d419', autoComplete: 'off', class: classNames('searchcraft-input-form-input', {
125
+ 'searchcraft-placeholder-hide-on-focus': this.placeholderBehavior === 'hide-on-focus',
126
+ }), onFocus: () => this.inputFocus?.emit(), onBlur: () => this.inputBlur?.emit(), onInput: (event) => {
123
127
  this.handleInput(event);
124
- }, placeholder: this.placeholderValue, type: 'text', value: this.inputValue }), h("div", { key: '616b4dde1ba016cf6a2fba8594a99a3a3f584ef5', class: 'searchcraft-input-form-input-icon' }, h("svg", { key: 'daaef561677a06a76813375e429be7e053b8b122', class: 'searchcraft-input-form-input-search-icon', viewBox: '0 0 20 20', fill: 'none', xmlns: 'http://www.w3.org/2000/svg', "aria-labelledby": 'searchcraft-title' }, h("title", { key: 'e6d82ca64dd9bfc663813c239d11e5652aa0b9a1' }, "Search icon"), h("path", { key: '1df856c98c2063c1d0c80027255935f73b513939', d: 'M17.5 17.5L13.875 13.875M15.8333 9.16667C15.8333 12.8486 12.8486 15.8333 9.16667 15.8333C5.48477 15.8333 2.5 12.8486 2.5 9.16667C2.5 5.48477 5.48477 2.5 9.16667 2.5C12.8486 2.5 15.8333 5.48477 15.8333 9.16667Z', stroke: 'currentColor', "stroke-width": '1.5', "stroke-linecap": 'round', "stroke-linejoin": 'round' }))), isShowingClearButton && (h("button", { key: '8dd6dfefe0ba909657bd436b559ce35b5004f9ae', type: 'button', class: 'searchcraft-input-form-clear-button', onClick: this.handleClearInput }, h("svg", { key: 'bcdba04d5c0949cacc8e1962d2b3cd40ad995de6', class: 'searchcraft-input-form-clear-icon', viewBox: '0 0 22 22', fill: 'none', xmlns: 'http://www.w3.org/2000/svg', "aria-labelledby": 'icon-title' }, h("title", { key: 'e01e7fb9b23daf9434520c4c68c0d7539b37d1f8' }, "Clear icon"), h("path", { key: 'ce526d332b6e352cd9cf6008ee2f7497c6769782', d: 'M14 8L8 14M8 8L14 14M21 11C21 16.5228 16.5228 21 11 21C5.47715 21 1 16.5228 1 11C1 5.47715 5.47715 1 11 1C16.5228 1 21 5.47715 21 11Z', stroke: 'currentColor', "stroke-width": '1.5', "stroke-linecap": 'round', "stroke-linejoin": 'round' }))))))));
128
+ }, placeholder: this.placeholderValue, type: 'text', value: this.inputValue }), h("div", { key: '6dd4a02322072467a104938a47626592658eaa1e', class: 'searchcraft-input-form-input-icon' }, h("svg", { key: '26a4deabe9149db6db219e49fcccbbe7688e9f0a', class: 'searchcraft-input-form-input-search-icon', viewBox: '0 0 20 20', fill: 'none', xmlns: 'http://www.w3.org/2000/svg', "aria-labelledby": 'searchcraft-title' }, h("title", { key: 'eff07788d2edaead45a60d8ac20e5d1d694c5165' }, "Search icon"), h("path", { key: '9083cf32c8f749210232b51b1f5934a3c32b109f', d: 'M17.5 17.5L13.875 13.875M15.8333 9.16667C15.8333 12.8486 12.8486 15.8333 9.16667 15.8333C5.48477 15.8333 2.5 12.8486 2.5 9.16667C2.5 5.48477 5.48477 2.5 9.16667 2.5C12.8486 2.5 15.8333 5.48477 15.8333 9.16667Z', stroke: 'currentColor', "stroke-width": '1.5', "stroke-linecap": 'round', "stroke-linejoin": 'round' }))), isShowingClearButton && (h("button", { key: '0b2117ae2510fe743b11d8e638e981ee0f7e4760', type: 'button', class: 'searchcraft-input-form-clear-button', onClick: this.handleClearInput }, h("svg", { key: '3fbb57c1b6486638286e1010639751a83a75f489', class: 'searchcraft-input-form-clear-icon', viewBox: '0 0 22 22', fill: 'none', xmlns: 'http://www.w3.org/2000/svg', "aria-labelledby": 'icon-title' }, h("title", { key: '84ce771c55c072b4339babb136639469b68a1f9b' }, "Clear icon"), h("path", { key: '811f5fc9cc708f80004f1cf50ddcd85de05f3b6b', d: 'M14 8L8 14M8 8L14 14M21 11C21 16.5228 16.5228 21 11 21C5.47715 21 1 16.5228 1 11C1 5.47715 5.47715 1 11 1C16.5228 1 21 5.47715 21 11Z', stroke: 'currentColor', "stroke-width": '1.5', "stroke-linecap": 'round', "stroke-linejoin": 'round' }))))))));
125
129
  }
126
130
  static get watchers() { return {
127
131
  "core": ["onCoreChange"]
@@ -132,6 +136,7 @@ const SearchcraftInputForm = /*@__PURE__*/ proxyCustomElement(class SearchcraftI
132
136
  "buttonLabel": [1, "button-label"],
133
137
  "inputLabel": [1, "input-label"],
134
138
  "placeholderValue": [1, "placeholder-value"],
139
+ "placeholderBehavior": [1, "placeholder-behavior"],
135
140
  "core": [16],
136
141
  "inputValue": [32],
137
142
  "searchTerm": [32],
@@ -170,4 +175,4 @@ function defineCustomElement() {
170
175
 
171
176
  export { SearchcraftInputForm as S, defineCustomElement as d };
172
177
 
173
- //# sourceMappingURL=p-6065aee1.js.map
178
+ //# sourceMappingURL=p-a7d611cd.js.map
@@ -0,0 +1 @@
1
+ {"file":"p-a7d611cd.js","mappings":";;;;;;;MAgDa,oBAAoB;;;;;;;;;;;IAIvB,UAAU,GAAa,IAAI,CAAC;;;;IAI5B,eAAe,GAA+B,MAAM,CAAC;;;;IAIrD,WAAW,CAAU;;;;IAIrB,UAAU,CAAU;;;;IAIpB,gBAAgB,GAAY,cAAc,CAAC;;;;;;IAM3C,mBAAmB,CAA4C;;;;IAI9D,UAAU,CAAsB;;;;IAIhC,SAAS,CAAsB;;;;IAI/B,SAAS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qBAClB,YAAY,IAE5B,6EAAyB,EACzB,6DACE,CAAC,EAAC,uIAAuI,EACzI,MAAM,EAAC,cAAc,kBACR,KAAK,oBACH,OAAO,qBACN,OAAO,GACvB,CACE,CACC,CACV,CACG,CACF,CACD,EACP;KACH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":[],"sources":["src/components/searchcraft-input-form/searchcraft-input-form.tsx"],"sourcesContent":["import {\n Component,\n h,\n Prop,\n State,\n Event,\n type EventEmitter,\n Watch,\n} from '@stencil/core';\nimport classNames from 'classnames';\n\nimport type { SearchcraftCore } from '@searchcraft/core';\n\nimport { searchcraftStore } from '@store';\n\n/**\n * This web component provides a user-friendly interface for querying an indexed dataset, enabling users to easily search large collections of data.\n * It abstracts the complexities of index-based searching, making it accessible to users of all technical levels.\n *\n * @react-import\n * ```jsx\n * import { SearchcraftInputForm } from \"@searchcraft/react-sdk\";\n * ```\n *\n * @vue-import\n * ```jsx\n * import { SearchcraftInputForm } from \"@searchcraft/vue-sdk\";\n * ```\n *\n * @js-example\n * ```html\n * <searchcraft-input-form auto-search />\n * ```\n *\n * @react-example\n * ```jsx\n * <SearchcraftInputForm autoSearch />\n * ```\n *\n * @vue-example\n * ```jsx\n * <SearchcraftInputForm autoSearch />\n * ```\n */\n@Component({\n tag: 'searchcraft-input-form',\n shadow: false,\n})\nexport class SearchcraftInputForm {\n /**\n * Whether or not to automatically submit the search term when the input changes.\n */\n @Prop() autoSearch?: boolean = true;\n /**\n * Where to place the search button.\n */\n @Prop() buttonPlacement?: 'left' | 'right' | 'none' = 'none';\n /**\n * The label for the submit button.\n */\n @Prop() buttonLabel?: string;\n /**\n * The label rendered above the input.\n */\n @Prop() inputLabel?: string;\n /**\n * The input element's placeholder value.\n */\n @Prop() placeholderValue?: string = 'Enter Search';\n /**\n * The placeholder's render behavior.\n * 'hide-on-focus' - Hide the placeholder text immediately when the input form gains focus.\n * 'hide-on-text-entered' - Only hide the placeholder when the input form has text entered into it.\n */\n @Prop() placeholderBehavior?: 'hide-on-focus' | 'hide-on-text-entered';\n /**\n * When the input becomes focused.\n */\n @Event() inputFocus?: EventEmitter<void>;\n /**\n * When the input becomes unfocused.\n */\n @Event() inputBlur?: EventEmitter<void>;\n /**\n * Event emitted when input initializes.\n */\n @Event() inputInit?: EventEmitter<void>;\n\n @State() inputValue = '';\n @State() searchTerm = '';\n @State() error = false;\n\n @Prop() core?: SearchcraftCore;\n\n private searchcraftStore = searchcraftStore.getState();\n private unsubscribe: () => void = () => {};\n\n init() {\n if (this.core) {\n this.searchcraftStore.init(this.core);\n this.inputInit?.emit();\n }\n }\n\n @Watch('core')\n onCoreChange() {\n this.init();\n }\n\n connectedCallback() {\n this.init();\n }\n\n componentDidLoad() {\n this.unsubscribe = searchcraftStore.subscribe((state) => {\n this.searchTerm = state.searchTerm;\n this.inputValue = state.searchTerm;\n });\n }\n\n disconnectedCallback() {\n this.handleReset();\n this.unsubscribe?.();\n }\n\n handleInput = (event: Event) => {\n const input = event.target as HTMLInputElement;\n this.inputValue = input.value;\n this.searchcraftStore.setSearchTerm(input.value);\n\n if (!this.autoSearch) {\n return;\n }\n\n this.performSearch();\n };\n\n private performSearch = async () => {\n this.error = false;\n\n try {\n await this.searchcraftStore.search();\n } catch (error) {\n this.error = true;\n }\n };\n\n private handleReset = () => {\n this.searchcraftStore.setSearchResultsCount(0);\n this.searchcraftStore.setSearchTerm('');\n this.searchcraftStore.setSearchClientResponseItems([]);\n this.error = false;\n };\n\n handleClearInput = () => {\n this.handleReset();\n };\n\n handleFormSubmit = async (event: Event) => {\n event.preventDefault();\n await this.performSearch();\n };\n\n render() {\n const isShowingClearButton = this.inputValue.length > 0;\n const inputGridClassNames = classNames('searchcraft-input-form-grid', {\n 'searchcraft-input-form-grid-button-left':\n this.buttonPlacement === 'left',\n 'searchcraft-input-form-grid-button-right':\n this.buttonPlacement === 'right',\n 'searchcraft-input-form-grid-button-none':\n this.buttonPlacement === 'none',\n });\n const shouldHaveVerticalGap = this.inputLabel || this.error;\n const inputGridStyles = {\n gap: shouldHaveVerticalGap ? '4px 8px' : '0px 8px',\n };\n return (\n <form class='searchcraft-input-form' onSubmit={this.handleFormSubmit}>\n <div class={inputGridClassNames} style={inputGridStyles}>\n <div class='searchcraft-input-form-button'>\n <searchcraft-button\n onButtonClick={this.handleFormSubmit}\n label={this.buttonLabel}\n />\n </div>\n {this.inputLabel && (\n <div class='searchcraft-input-form-label'>\n <searchcraft-input-label label={this.inputLabel} />\n </div>\n )}\n {this.error && (\n <div class='searchcraft-input-form-error-message'>\n <searchcraft-error-message>\n Something went wrong.\n </searchcraft-error-message>\n </div>\n )}\n <div class='searchcraft-input-form-input-wrapper'>\n <input\n autoComplete='off'\n class={classNames('searchcraft-input-form-input', {\n 'searchcraft-placeholder-hide-on-focus':\n this.placeholderBehavior === 'hide-on-focus',\n })}\n onFocus={() => this.inputFocus?.emit()}\n onBlur={() => this.inputBlur?.emit()}\n onInput={(event) => {\n this.handleInput(event);\n }}\n placeholder={this.placeholderValue}\n type='text'\n value={this.inputValue}\n />\n <div class='searchcraft-input-form-input-icon'>\n <svg\n class='searchcraft-input-form-input-search-icon'\n viewBox='0 0 20 20'\n fill='none'\n xmlns='http://www.w3.org/2000/svg'\n aria-labelledby='searchcraft-title'\n >\n <title>Search icon</title>\n <path\n d='M17.5 17.5L13.875 13.875M15.8333 9.16667C15.8333 12.8486 12.8486 15.8333 9.16667 15.8333C5.48477 15.8333 2.5 12.8486 2.5 9.16667C2.5 5.48477 5.48477 2.5 9.16667 2.5C12.8486 2.5 15.8333 5.48477 15.8333 9.16667Z'\n stroke='currentColor'\n stroke-width='1.5'\n stroke-linecap='round'\n stroke-linejoin='round'\n />\n </svg>\n </div>\n {isShowingClearButton && (\n <button\n type='button'\n class='searchcraft-input-form-clear-button'\n onClick={this.handleClearInput}\n >\n <svg\n class='searchcraft-input-form-clear-icon'\n viewBox='0 0 22 22'\n fill='none'\n xmlns='http://www.w3.org/2000/svg'\n aria-labelledby='icon-title'\n >\n <title>Clear icon</title>\n <path\n d='M14 8L8 14M8 8L14 14M21 11C21 16.5228 16.5228 21 11 21C5.47715 21 1 16.5228 1 11C1 5.47715 5.47715 1 11 1C16.5228 1 21 5.47715 21 11Z'\n stroke='currentColor'\n stroke-width='1.5'\n stroke-linecap='round'\n stroke-linejoin='round'\n />\n </svg>\n </button>\n )}\n </div>\n </div>\n </form>\n );\n }\n}\n"],"version":3}
@@ -1,7 +1,7 @@
1
1
  import { p as proxyCustomElement, H, h } from './p-5365011f.js';
2
- import { n as nanoid, d as defineCustomElement$2 } from './p-35ee16e2.js';
3
- import { s as searchcraftStore } from './p-60fd824d.js';
4
- import { d as defineCustomElement$1 } from './p-9d2e55a7.js';
2
+ import { n as nanoid, d as defineCustomElement$2 } from './p-6e5ed641.js';
3
+ import { s as searchcraftStore } from './p-b54873ff.js';
4
+ import { d as defineCustomElement$1 } from './p-2735dceb.js';
5
5
 
6
6
  const SearchcraftPopoverListView = /*@__PURE__*/ proxyCustomElement(class SearchcraftPopoverListView extends H {
7
7
  constructor() {
@@ -131,4 +131,4 @@ function defineCustomElement() {
131
131
 
132
132
  export { SearchcraftPopoverListView as S, defineCustomElement as d };
133
133
 
134
- //# sourceMappingURL=p-6ed5cca1.js.map
134
+ //# sourceMappingURL=p-aba24c85.js.map
@@ -1 +1 @@
1
- {"file":"p-6ed5cca1.js","mappings":";;;;;MAyBa,0BAA0B;;;;;;;;;IAK7B,qBAAqB,CAAoC;;;;IAIzD,yBAAyB,CAAyC;IAClE,qBAAqB,CAAqC;IAC1D,iBAAiB,CAAU;IAC3B,oBAAoB,CAAU;IAE9B,MAAM,GAAG,gBAAgB,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC;IAE1D,gBAAgB;QACd,QACE,WAAK,KAAK,EAAC,+BAA+B,IACvC,IAAI,CAAC,qBAAqB,EAAE,GAAG,CAAC,CAAC,IAAI,MACpC,sBACE,oBAAoB,EAAE,IAAI,E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EACjB,aAAa,EAAE,MAAM,EAAE,EACvB,GAAG,EAAE,GAAG,CAAC,KAAK,GACd,CACH,CAAC;SACH;QAED,OAAO,WAAK,KAAK,EAAC,+BAA+B,IAAE,aAAa,CAAO,CAAC;KACzE;IAED,eAAe;QACb,QACE,WAAK,KAAK,EAAC,+BAA+B,IACvC,IAAI,CAAC,yBAAyB,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,MAC/C,qCACE,IAAI,EAAE,IAAI,EACV,GAAG,EAAE,IAAI,CAAC,EAAE,EACZ,qBAAqB,EAAE,IAAI,CAAC,qBAAqB,EACjD,gBAAgB,EACd,IAAI,CAAC,oBAAoB,IAAI,IAAI,CAAC,iBAAiB,GAAG,CAAC,CAAC,GAAG,KAAK,GAElE,CACH,CAAC,CACE,EACN;KACH;IAED,MAAM;QACJ,QAAQ,IAAI,CAAC,MAAM,EAAE,QAAQ,IAAI,MAAM;YACrC,KAAK,eAAe;gBAClB,OAAO,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACjC,KAAK,QAAQ;gBACX,OAAO,IAAI,CAAC,mBAAmB,EAAE,CAAC;YACpC,KAAK,QAAQ;gBACX,OAAO,IAAI,CAAC,mBAAmB,EAAE,CAAC;YACpC;gBACE,OAAO,IAAI,CAAC,eAAe,EAAE,CAAC;SACjC;KACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":[],"sources":["src/components/searchcraft-popover-list-view/searchcraft-popover-list-view.tsx"],"sourcesContent":["import type {\n AdClientResponseItem,\n SearchClientResponseItem,\n} from '@searchcraft/core';\nimport { Component, h, Prop, type JSX } from '@stencil/core';\nimport { nanoid } from 'nanoid';\n\nimport type { PopoverResultMappings } from '@searchcraft/core';\nimport { searchcraftStore } from '@store';\n\n/**\n * This web component is designed to display a list of results within a popover interface.\n * It is consumed within the `searchcraft-popover-form` component.\n *\n * @js-example\n * ```html\n * <searchcraft-popover-list-view />\n * ```\n *\n * @internal\n */\n@Component({\n tag: 'searchcraft-popover-list-view',\n shadow: false,\n})\nexport class SearchcraftPopoverListView {\n /**\n * The mappings that define how the data in the documents are mapped to the\n * list-view-item elements.\n */\n @Prop() popoverResultMappings: PopoverResultMappings | undefined;\n /**\n * The items to render in the list view.\n */\n @Prop() searchClientResponseItems: SearchClientResponseItem[] | undefined;\n @Prop() adClientResponseItems: AdClientResponseItem[] | undefined;\n @Prop() searchResultsPage!: number;\n @Prop() searchResultsPerPage!: number;\n\n private config = searchcraftStore.getState().core?.config;\n\n renderWithADMAds() {\n return (\n <div class='searchcraft-popover-list-view'>\n {this.adClientResponseItems?.map((item) => (\n <searchcraft-ad\n adClientResponseItem={item}\n adContainerId={nanoid()}\n adSource='adMarketplace'\n key={item.id}\n />\n ))}\n {this.searchClientResponseItems?.map((item, index) => (\n <searchcraft-popover-list-item\n item={item}\n key={item.id}\n popoverResultMappings={this.popoverResultMappings}\n documentPosition={\n this.searchResultsPerPage * (this.searchResultsPage - 1) + index\n }\n />\n ))}\n </div>\n );\n }\n\n renderWithCustomAds() {\n const itemsToRender: JSX.Element[] = [];\n const interstitialInterval = this.config?.customAdInterstitialInterval || 0;\n const interstitialQuantity = this.config?.customAdInterstitialQuantity || 1;\n const adStartQuantity = this.config?.customAdStartQuantity || 0;\n const adEndQuantity = this.config?.customAdEndQuantity || 0;\n const searchItems = this.searchClientResponseItems || [];\n\n // Renders ads at beginning\n for (let n = 0; n < adStartQuantity; n++) {\n itemsToRender.push(\n <searchcraft-ad\n adSource='Custom'\n adContainerId={nanoid()}\n key={`${n}-ad`}\n />,\n );\n }\n\n // Renders search results + interstitial ads\n searchItems.forEach((item, index) => {\n if (\n interstitialInterval &&\n index % interstitialInterval === 0 &&\n index + interstitialInterval < searchItems.length &&\n index >= interstitialInterval\n ) {\n for (let n = 0; n < interstitialQuantity; n++) {\n itemsToRender.push(\n <searchcraft-ad\n adSource='Custom'\n adContainerId={nanoid()}\n key={`${item.id}-ad-${n}`}\n />,\n );\n }\n }\n\n itemsToRender.push(\n <searchcraft-popover-list-item\n item={item}\n key={item.id}\n popoverResultMappings={this.popoverResultMappings}\n documentPosition={\n this.searchResultsPerPage * (this.searchResultsPage - 1) + index\n }\n />,\n );\n });\n\n // Renders ads at end\n for (let n = 0; n < adEndQuantity; n++) {\n itemsToRender.push(\n <searchcraft-ad\n adSource='Custom'\n adContainerId={nanoid()}\n key={`${n}-ad`}\n />,\n );\n }\n\n return <div class='searchcraft-popover-list-view'>{itemsToRender}</div>;\n }\n\n renderWithNativoAds() {\n const itemsToRender: JSX.Element[] = [];\n const interstitialStartIndex =\n this.config?.nativoAdInterstialStartIndex || 0;\n const interstitialInterval = this.config?.nativoAdInterstitialInterval || 0;\n const interstitialQuantity = this.config?.nativoAdInterstitialQuantity || 1;\n const adStartQuantity = this.config?.nativoAdStartQuantity || 0;\n const adEndQuantity = this.config?.nativoAdEndQuantity || 0;\n const searchItems = this.searchClientResponseItems || [];\n\n // Renders ads at beginning\n for (let n = 0; n < adStartQuantity; n++) {\n itemsToRender.push(\n <searchcraft-ad\n adSource='Nativo'\n adContainerId={nanoid()}\n key={`${n}-ad`}\n />,\n );\n }\n\n // Renders search results + interstitial ads\n searchItems.forEach((item, index) => {\n if (\n interstitialInterval &&\n (index + interstitialStartIndex) % interstitialInterval === 0 &&\n index + interstitialInterval < searchItems.length &&\n index >= interstitialInterval\n ) {\n for (let n = 0; n < interstitialQuantity; n++) {\n itemsToRender.push(\n <searchcraft-ad\n adSource='Nativo'\n adContainerId={nanoid()}\n key={`${item.id}-ad-${n}`}\n />,\n );\n }\n }\n\n itemsToRender.push(\n <searchcraft-popover-list-item\n item={item}\n key={item.id}\n popoverResultMappings={this.popoverResultMappings}\n documentPosition={\n this.searchResultsPerPage * (this.searchResultsPage - 1) + index\n }\n />,\n );\n });\n\n // Renders ads at end\n for (let n = 0; n < adEndQuantity; n++) {\n itemsToRender.push(\n <searchcraft-ad\n adSource='Nativo'\n adContainerId={nanoid()}\n key={`${n}-ad`}\n />,\n );\n }\n\n return <div class='searchcraft-popover-list-view'>{itemsToRender}</div>;\n }\n\n renderWithNoAds() {\n return (\n <div class='searchcraft-popover-list-view'>\n {this.searchClientResponseItems?.map((item, index) => (\n <searchcraft-popover-list-item\n item={item}\n key={item.id}\n popoverResultMappings={this.popoverResultMappings}\n documentPosition={\n this.searchResultsPerPage * (this.searchResultsPage - 1) + index\n }\n />\n ))}\n </div>\n );\n }\n\n render() {\n switch (this.config?.adSource || 'None') {\n case 'adMarketplace':\n return this.renderWithADMAds();\n case 'Custom':\n return this.renderWithCustomAds();\n case 'Nativo':\n return this.renderWithNativoAds();\n default:\n return this.renderWithNoAds();\n }\n }\n}\n"],"version":3}
1
+ {"file":"p-aba24c85.js","mappings":";;;;;MAyBa,0BAA0B;;;;;;;;;IAK7B,qBAAqB,CAAoC;;;;IAIzD,yBAAyB,CAAyC;IAClE,qBAAqB,CAAqC;IAC1D,iBAAiB,CAAU;IAC3B,oBAAoB,CAAU;IAE9B,MAAM,GAAG,gBAAgB,CAAC,QAAQ,EAAE,CAAC,IAAI,EAAE,MAAM,CAAC;IAE1D,gBAAgB;QACd,QACE,WAAK,KAAK,EAAC,+BAA+B,IACvC,IAAI,CAAC,qBAAqB,EAAE,GAAG,CAAC,CAAC,IAAI,MACpC,sBACE,oBAAoB,EAAE,IAAI,EAC1B,aAAa,EAAE,MAAM,EAAE,EACvB,QAAQ,EAAC,eAAe,EACxB,GAAG,EAAE,IAAI,CAAC,EAAE,GACZ,CACH,CAAC,EACD,IAAI,CAAC,yBAAyB,EAAE,GAAG,CAAC,CAAC,IAAI,EAAE,KAAK,MAC/C,qCACE,IAAI,EAAE,IAAI,EACV,GAAG,EAAE,IAAI,CAAC,EAAE,EACZ,qBAAqB,EAAE,IAAI,CAAC,qBAAqB,EACjD,gBAAgB,EACd,IAAI,CAAC,oBAAoB,IAAI,IAAI,CAAC,iBAAiB,GAAG,CAAC,CAAC,GAAG,KAAK,GAElE,CACH,CAAC,CACE,EACN;KACH;IAED,mBAAmB;QACjB,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AAC,iBAAiB,GAAG,CAAC,CAAC,GAAG,KAAK,GAElE,CACH,CAAC,CACE,EACN;KACH;IAED,MAAM;QACJ,QAAQ,IAAI,CAAC,MAAM,EAAE,QAAQ,IAAI,MAAM;YACrC,KAAK,eAAe;gBAClB,OAAO,IAAI,CAAC,gBAAgB,EAAE,CAAC;YACjC,KAAK,QAAQ;gBACX,OAAO,IAAI,CAAC,mBAAmB,EAAE,CAAC;YACpC,KAAK,QAAQ;gBACX,OAAO,IAAI,CAAC,mBAAmB,EAAE,CAAC;YACpC;gBACE,OAAO,IAAI,CAAC,eAAe,EAAE,CAAC;SACjC;KACF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;","names":[],"sources":["src/components/searchcraft-popover-list-view/searchcraft-popover-list-view.tsx"],"sourcesContent":["import type {\n AdClientResponseItem,\n SearchClientResponseItem,\n} from '@searchcraft/core';\nimport { Component, h, Prop, type JSX } from '@stencil/core';\nimport { nanoid } from 'nanoid';\n\nimport type { PopoverResultMappings } from '@searchcraft/core';\nimport { searchcraftStore } from '@store';\n\n/**\n * This web component is designed to display a list of results within a popover interface.\n * It is consumed within the `searchcraft-popover-form` component.\n *\n * @js-example\n * ```html\n * <searchcraft-popover-list-view />\n * ```\n *\n * @internal\n */\n@Component({\n tag: 'searchcraft-popover-list-view',\n shadow: false,\n})\nexport class SearchcraftPopoverListView {\n /**\n * The mappings that define how the data in the documents are mapped to the\n * list-view-item elements.\n */\n @Prop() popoverResultMappings: PopoverResultMappings | undefined;\n /**\n * The items to render in the list view.\n */\n @Prop() searchClientResponseItems: SearchClientResponseItem[] | undefined;\n @Prop() adClientResponseItems: AdClientResponseItem[] | undefined;\n @Prop() searchResultsPage!: number;\n @Prop() searchResultsPerPage!: number;\n\n private config = searchcraftStore.getState().core?.config;\n\n renderWithADMAds() {\n return (\n <div class='searchcraft-popover-list-view'>\n {this.adClientResponseItems?.map((item) => (\n <searchcraft-ad\n adClientResponseItem={item}\n adContainerId={nanoid()}\n adSource='adMarketplace'\n key={item.id}\n />\n ))}\n {this.searchClientResponseItems?.map((item, index) => (\n <searchcraft-popover-list-item\n item={item}\n key={item.id}\n popoverResultMappings={this.popoverResultMappings}\n documentPosition={\n this.searchResultsPerPage * (this.searchResultsPage - 1) + index\n }\n />\n ))}\n </div>\n );\n }\n\n renderWithCustomAds() {\n const itemsToRender: JSX.Element[] = [];\n const interstitialInterval = this.config?.customAdInterstitialInterval || 0;\n const interstitialQuantity = this.config?.customAdInterstitialQuantity || 1;\n const adStartQuantity = this.config?.customAdStartQuantity || 0;\n const adEndQuantity = this.config?.customAdEndQuantity || 0;\n const searchItems = this.searchClientResponseItems || [];\n\n // Renders ads at beginning\n for (let n = 0; n < adStartQuantity; n++) {\n itemsToRender.push(\n <searchcraft-ad\n adSource='Custom'\n adContainerId={nanoid()}\n key={`${n}-ad`}\n />,\n );\n }\n\n // Renders search results + interstitial ads\n searchItems.forEach((item, index) => {\n if (\n interstitialInterval &&\n index % interstitialInterval === 0 &&\n index + interstitialInterval < searchItems.length &&\n index >= interstitialInterval\n ) {\n for (let n = 0; n < interstitialQuantity; n++) {\n itemsToRender.push(\n <searchcraft-ad\n adSource='Custom'\n adContainerId={nanoid()}\n key={`${item.id}-ad-${n}`}\n />,\n );\n }\n }\n\n itemsToRender.push(\n <searchcraft-popover-list-item\n item={item}\n key={item.id}\n popoverResultMappings={this.popoverResultMappings}\n documentPosition={\n this.searchResultsPerPage * (this.searchResultsPage - 1) + index\n }\n />,\n );\n });\n\n // Renders ads at end\n for (let n = 0; n < adEndQuantity; n++) {\n itemsToRender.push(\n <searchcraft-ad\n adSource='Custom'\n adContainerId={nanoid()}\n key={`${n}-ad`}\n />,\n );\n }\n\n return <div class='searchcraft-popover-list-view'>{itemsToRender}</div>;\n }\n\n renderWithNativoAds() {\n const itemsToRender: JSX.Element[] = [];\n const interstitialStartIndex =\n this.config?.nativoAdInterstialStartIndex || 0;\n const interstitialInterval = this.config?.nativoAdInterstitialInterval || 0;\n const interstitialQuantity = this.config?.nativoAdInterstitialQuantity || 1;\n const adStartQuantity = this.config?.nativoAdStartQuantity || 0;\n const adEndQuantity = this.config?.nativoAdEndQuantity || 0;\n const searchItems = this.searchClientResponseItems || [];\n\n // Renders ads at beginning\n for (let n = 0; n < adStartQuantity; n++) {\n itemsToRender.push(\n <searchcraft-ad\n adSource='Nativo'\n adContainerId={nanoid()}\n key={`${n}-ad`}\n />,\n );\n }\n\n // Renders search results + interstitial ads\n searchItems.forEach((item, index) => {\n if (\n interstitialInterval &&\n (index + interstitialStartIndex) % interstitialInterval === 0 &&\n index + interstitialInterval < searchItems.length &&\n index >= interstitialInterval\n ) {\n for (let n = 0; n < interstitialQuantity; n++) {\n itemsToRender.push(\n <searchcraft-ad\n adSource='Nativo'\n adContainerId={nanoid()}\n key={`${item.id}-ad-${n}`}\n />,\n );\n }\n }\n\n itemsToRender.push(\n <searchcraft-popover-list-item\n item={item}\n key={item.id}\n popoverResultMappings={this.popoverResultMappings}\n documentPosition={\n this.searchResultsPerPage * (this.searchResultsPage - 1) + index\n }\n />,\n );\n });\n\n // Renders ads at end\n for (let n = 0; n < adEndQuantity; n++) {\n itemsToRender.push(\n <searchcraft-ad\n adSource='Nativo'\n adContainerId={nanoid()}\n key={`${n}-ad`}\n />,\n );\n }\n\n return <div class='searchcraft-popover-list-view'>{itemsToRender}</div>;\n }\n\n renderWithNoAds() {\n return (\n <div class='searchcraft-popover-list-view'>\n {this.searchClientResponseItems?.map((item, index) => (\n <searchcraft-popover-list-item\n item={item}\n key={item.id}\n popoverResultMappings={this.popoverResultMappings}\n documentPosition={\n this.searchResultsPerPage * (this.searchResultsPage - 1) + index\n }\n />\n ))}\n </div>\n );\n }\n\n render() {\n switch (this.config?.adSource || 'None') {\n case 'adMarketplace':\n return this.renderWithADMAds();\n case 'Custom':\n return this.renderWithCustomAds();\n case 'Nativo':\n return this.renderWithNativoAds();\n default:\n return this.renderWithNoAds();\n }\n }\n}\n"],"version":3}
@@ -0,0 +1,406 @@
1
+ import { p as proxyCustomElement, H, c as createEvent, h } from './p-5365011f.js';
2
+ import { s as searchcraftStore } from './p-b54873ff.js';
3
+ import './p-a64b4cba.js';
4
+
5
+ /**
6
+ * Helper function for getting a Node (FacetWithChildrenObject)
7
+ * at a given path. Traverses the node tree to get the node.
8
+ */
9
+ const getFacetTreeNodeAtPath = (tree, nodePaths) => {
10
+ let cursor = tree;
11
+ for (const nodePath of nodePaths) {
12
+ cursor = cursor?.children[nodePath];
13
+ }
14
+ return cursor;
15
+ };
16
+ /**
17
+ * Helper function to perform a deep merge.
18
+ * Used for merging two branches of a facet tree together.
19
+ */
20
+ const deepMergeWithSpread = (obj1, obj2) => {
21
+ const result = { ...obj1 };
22
+ for (const key in obj2) {
23
+ // biome-ignore lint/suspicious/noPrototypeBuiltins: <explanation>
24
+ if (obj2.hasOwnProperty(key)) {
25
+ if (obj2[key] instanceof Object && obj1[key] instanceof Object) {
26
+ result[key] = deepMergeWithSpread(obj1[key], obj2[key]);
27
+ }
28
+ else {
29
+ result[key] = obj2[key];
30
+ }
31
+ }
32
+ }
33
+ return result;
34
+ };
35
+ /**
36
+ * Given an array of facet paths, removes parent facet paths so that only the
37
+ * Leaf facets are sent with the search request.
38
+ */
39
+ function removeSubstringMatches(arr) {
40
+ return arr.filter((entry, index, array) => !array.some((otherEntry, otherIndex) => otherIndex !== index && otherEntry.includes(entry)));
41
+ }
42
+ /**
43
+ * Merges a current facet tree with an incoming facet tree.
44
+ *
45
+ * At each branch, the incoming facet tree's facets override current facet tree
46
+ *
47
+ * @param currentTree
48
+ * @param incomingTree
49
+ */
50
+ const mergeFacetTrees = (currentTree, incomingTree) => {
51
+ const mergedTree = structuredClone(currentTree);
52
+ const merge = (currentBranch, nodePath) => {
53
+ const mergedBranch = structuredClone(currentBranch);
54
+ const incomingBranch = getFacetTreeNodeAtPath(incomingTree, nodePath);
55
+ if (!incomingBranch) {
56
+ return mergedBranch;
57
+ }
58
+ for (const nodeName of Object.keys(currentBranch.children)) {
59
+ if (incomingBranch.children[nodeName]) {
60
+ mergedBranch.children[nodeName] = {
61
+ ...deepMergeWithSpread(currentBranch.children[nodeName], incomingBranch.children[nodeName]),
62
+ count: mergedBranch.children[nodeName]?.count || 0,
63
+ };
64
+ }
65
+ else if (mergedBranch.children[nodeName]) {
66
+ mergedBranch.children[nodeName] = merge(mergedBranch.children[nodeName], [...nodePath, nodeName]);
67
+ }
68
+ }
69
+ return mergedBranch;
70
+ };
71
+ return merge(mergedTree, []);
72
+ };
73
+ /**
74
+ * A function that converts a FacetWithChidrenArray to a complete FacetTree object.
75
+ *
76
+ * It uses the `path` of each Facet to build the tree.
77
+ *
78
+ * @param facetWithChildArray
79
+ */
80
+ const facetWithChildrenArrayToCompleteFacetTree = (rootArray) => {
81
+ // 1) Start with an empty tree at root "/"
82
+ const tree = {
83
+ path: '/',
84
+ count: 0,
85
+ children: {},
86
+ };
87
+ // 2) Recursively collect all nodes except the implicit "/" itself
88
+ const allFacets = [];
89
+ const collect = (node) => {
90
+ if (node.path !== '/') {
91
+ allFacets.push({ path: node.path, count: node.count });
92
+ }
93
+ if (node.children) {
94
+ for (const child of node.children) {
95
+ collect(child);
96
+ }
97
+ }
98
+ };
99
+ collect(rootArray);
100
+ // 3) Insert each flat node into our tree, creating missing ancestors
101
+ for (const { path, count } of allFacets) {
102
+ const segments = path.split('/').filter(Boolean); // "/sports/outdoors" -> ["sports","outdoors"]
103
+ let cursor = tree; // start at the root
104
+ for (const segment of segments) {
105
+ // Build the full path of this level
106
+ const prefixPath = cursor.path === '/' ? `/${segment}` : `${cursor.path}/${segment}`;
107
+ // If this segment doesn't exist yet, create it
108
+ if (!cursor.children[segment]) {
109
+ cursor.children[segment] = {
110
+ path: prefixPath,
111
+ count: count,
112
+ children: {},
113
+ };
114
+ }
115
+ // Descend to the next level deeper
116
+ cursor = cursor.children[segment];
117
+ }
118
+ // 4) now `cursor` is the node matching `path` — assign its real count
119
+ cursor.count = count;
120
+ }
121
+ return tree;
122
+ };
123
+
124
+ const SearchcraftFacetList = /*@__PURE__*/ proxyCustomElement(class SearchcraftFacetList extends H {
125
+ constructor() {
126
+ super();
127
+ this.__registerHost();
128
+ this.facetSelectionUpdated = createEvent(this, "facetSelectionUpdated", 7);
129
+ }
130
+ /**
131
+ * The name of the field where facets are applied.
132
+ */
133
+ fieldName = '';
134
+ /**
135
+ * Emitted when the facets are updated.
136
+ */
137
+ facetSelectionUpdated;
138
+ /**
139
+ * The currently selected facet paths.
140
+ */
141
+ selectedPaths = {};
142
+ /**
143
+ * A Tree representing all of the facets collected from search responses.
144
+ */
145
+ facetTreeCollectedFromSearchResponse = {
146
+ path: '/',
147
+ count: 0,
148
+ children: {},
149
+ };
150
+ /**
151
+ * A Tree representing the facet paths that are selected, but were not included
152
+ * in any search response.
153
+ */
154
+ facetTreeFromFacetPathsNotInSearchResponse = {
155
+ path: '/',
156
+ count: 0,
157
+ children: {},
158
+ };
159
+ /**
160
+ * The facet tree that ultimately gets rendered.
161
+ * This is a mergin of the facetTreeCollectedFromSearchResponse and the facetTreeFromFacetPathsNotInSearchResponse tree
162
+ */
163
+ renderedFacetTree = {
164
+ path: '/',
165
+ count: 0,
166
+ children: {},
167
+ };
168
+ // Internal vars used to track when to perform various facet actions.
169
+ lastTimeTaken;
170
+ lastSearchTerm;
171
+ lastSearchMode;
172
+ lastSortType;
173
+ lastRangeValues;
174
+ lastFacetValues;
175
+ unsubscribe;
176
+ get areAnyFacetPathsSelected() {
177
+ return Object.keys(this.selectedPaths).some((key) => this.selectedPaths[key]);
178
+ }
179
+ handleIncomingSearchResponse(state, actionType) {
180
+ // Look at the incoming facet root from the search response, and convert it to a FacetTree
181
+ const incomingFacetRoot = state.searchResponseFacetPrime?.find((facet) => this.fieldName === Object.keys(facet)[0]);
182
+ const incomingFacetsWithChildrenArray = incomingFacetRoot?.[this.fieldName];
183
+ const incomingFacetTree = facetWithChildrenArrayToCompleteFacetTree({
184
+ path: '/',
185
+ count: 0,
186
+ children: incomingFacetsWithChildrenArray || [],
187
+ });
188
+ // Determine what action to take to accumulate items into the `facetTreeCollectedFromSearchResponse`.
189
+ // This facet tree gets accumulated in different ways depending on what action type occured.
190
+ switch (actionType) {
191
+ case 'SEARCH_TERM_EMPTY':
192
+ this.facetTreeCollectedFromSearchResponse = {
193
+ path: '/',
194
+ count: 0,
195
+ children: {},
196
+ };
197
+ break;
198
+ case 'NEW_SEARCH_TERM':
199
+ this.facetTreeCollectedFromSearchResponse = incomingFacetTree;
200
+ break;
201
+ case 'NEW_SEARCH_TERM_WHILE_FACETS_ACTIVE':
202
+ case 'EXACT_MATCH_UPDATE':
203
+ case 'RANGE_VALUE_UPDATE': {
204
+ if (state.supplementalFacetPrime) {
205
+ const supplementalFacetRoot = state.supplementalFacetPrime?.find((facet) => this.fieldName === Object.keys(facet)[0]);
206
+ const supplementalFacetsWithChildrenArray = supplementalFacetRoot?.[this.fieldName];
207
+ const supplementalFacetTree = facetWithChildrenArrayToCompleteFacetTree({
208
+ path: '/',
209
+ count: 0,
210
+ children: supplementalFacetsWithChildrenArray || [],
211
+ });
212
+ this.facetTreeCollectedFromSearchResponse = mergeFacetTrees(supplementalFacetTree, incomingFacetTree);
213
+ }
214
+ else {
215
+ this.facetTreeCollectedFromSearchResponse = incomingFacetTree;
216
+ }
217
+ break;
218
+ }
219
+ case 'FACET_UPDATE':
220
+ case 'SORT_ORDER_UPDATE':
221
+ this.facetTreeCollectedFromSearchResponse = mergeFacetTrees(this.facetTreeCollectedFromSearchResponse, incomingFacetTree);
222
+ break;
223
+ default:
224
+ return;
225
+ }
226
+ // Determine if there are any selected facet paths not in the current tree.
227
+ // If there are, we add them to "facetTreeFromFacetPathsNotInSearchResponse"
228
+ this.facetTreeFromFacetPathsNotInSearchResponse = {
229
+ path: '/',
230
+ count: 0,
231
+ children: {},
232
+ };
233
+ const collectedFacetArray = {
234
+ path: '/',
235
+ count: 0,
236
+ children: [],
237
+ };
238
+ for (const pathName of Object.keys(this.selectedPaths).filter((path) => this.selectedPaths[path])) {
239
+ const nodePaths = pathName.startsWith('/')
240
+ ? pathName.substring(1).split('/')
241
+ : pathName.split('/');
242
+ const wasFoundInFacetTree = !!getFacetTreeNodeAtPath(this.facetTreeCollectedFromSearchResponse, nodePaths);
243
+ const pathKeyName = nodePaths.at(-1);
244
+ if (!wasFoundInFacetTree && pathKeyName) {
245
+ collectedFacetArray.children?.push({
246
+ children: [],
247
+ count: 0,
248
+ path: pathName,
249
+ });
250
+ }
251
+ }
252
+ this.facetTreeFromFacetPathsNotInSearchResponse =
253
+ facetWithChildrenArrayToCompleteFacetTree(collectedFacetArray);
254
+ // Merges facetTreeCollectedFromSearchResponse with selectedFacetPathsNotInCurrentFacetTree.
255
+ // This results in a single, final facet tree that gets rendered in as Checkboxes
256
+ this.renderedFacetTree = deepMergeWithSpread(this.facetTreeFromFacetPathsNotInSearchResponse, this.facetTreeCollectedFromSearchResponse);
257
+ }
258
+ handleStateUpdate(_state) {
259
+ const state = { ..._state };
260
+ // Determine what action to take based on the current State
261
+ if (state.searchTerm.trim() === '') {
262
+ this.handleIncomingSearchResponse(state, 'SEARCH_TERM_EMPTY');
263
+ this.lastSearchTerm = '';
264
+ }
265
+ else if (this.lastTimeTaken !== state.searchResponseTimeTaken &&
266
+ state.searchClientRequest &&
267
+ typeof state.searchClientRequest === 'object') {
268
+ const request = state.searchClientRequest;
269
+ let actionType = 'UNKNOWN';
270
+ if (this.lastSearchTerm !== request.searchTerm) {
271
+ if (this.areAnyFacetPathsSelected) {
272
+ actionType = 'NEW_SEARCH_TERM_WHILE_FACETS_ACTIVE';
273
+ }
274
+ else {
275
+ actionType = 'NEW_SEARCH_TERM';
276
+ }
277
+ }
278
+ else if (this.lastRangeValues !==
279
+ JSON.stringify(request.rangeValueForIndexFields)) {
280
+ actionType = 'RANGE_VALUE_UPDATE';
281
+ }
282
+ else if (this.lastFacetValues !==
283
+ JSON.stringify(request.facetPathsForIndexFields)) {
284
+ actionType = 'FACET_UPDATE';
285
+ }
286
+ else if (this.lastSortType !== request.order_by) {
287
+ actionType = 'SORT_ORDER_UPDATE';
288
+ }
289
+ else if (this.lastSearchMode !== request.mode) {
290
+ actionType = 'EXACT_MATCH_UPDATE';
291
+ }
292
+ this.lastRangeValues = JSON.stringify(request.rangeValueForIndexFields);
293
+ this.lastFacetValues = JSON.stringify(request.facetPathsForIndexFields);
294
+ this.lastSortType = request.order_by;
295
+ this.lastSearchMode = request.mode;
296
+ this.lastSearchTerm = request.searchTerm;
297
+ this.lastTimeTaken = state.searchResponseTimeTaken;
298
+ // Handle the incoming response, using the action we have determined.
299
+ this.handleIncomingSearchResponse(state, actionType);
300
+ }
301
+ }
302
+ connectedCallback() {
303
+ this.handleStateUpdate(searchcraftStore.getState());
304
+ this.unsubscribe = searchcraftStore.subscribe((state) => {
305
+ this.handleStateUpdate(state);
306
+ });
307
+ }
308
+ disconnectedCallback() {
309
+ this.unsubscribe?.();
310
+ }
311
+ handleCheckboxChange(path) {
312
+ const isCheckboxChecked = !this.selectedPaths[path];
313
+ if (isCheckboxChecked) {
314
+ /**
315
+ * Checkbox Checked: Add to the selectedPaths record
316
+ * Uses spread operator here so UI updates.
317
+ */
318
+ this.selectedPaths = {
319
+ ...this.selectedPaths,
320
+ [path]: true,
321
+ };
322
+ }
323
+ else {
324
+ /**
325
+ * Checkbox Uncheck: Remove any paths and sub-paths
326
+ */
327
+ const updatedPaths = Object.keys(this.selectedPaths).filter((testPath) => !testPath.includes(path));
328
+ this.selectedPaths = updatedPaths.reduce((acc, str) => {
329
+ acc[str] = true;
330
+ return acc;
331
+ }, {});
332
+ }
333
+ /**
334
+ * Emit the paths array, with parent paths removed.
335
+ */
336
+ const paths = Object.keys(this.selectedPaths).filter((path) => this.selectedPaths[path]);
337
+ const pathsWithParentPathsRemoved = removeSubstringMatches(paths);
338
+ this.facetSelectionUpdated?.emit({ paths: pathsWithParentPathsRemoved });
339
+ }
340
+ formatFacetName = (name) => {
341
+ const label = name.replace(/^\//, '');
342
+ return `${label.replace(/-/g, ' ').replace(/\b\w/g, (char) => char.toUpperCase())}`;
343
+ };
344
+ renderFacet(keyName, facet) {
345
+ let isChildSelected = false;
346
+ for (const path of Object.keys(this.selectedPaths)) {
347
+ if (this.selectedPaths[path] &&
348
+ path.startsWith(facet.path) &&
349
+ path.length > facet.path.length) {
350
+ isChildSelected = true;
351
+ }
352
+ }
353
+ const isSelected = Object.keys(this.selectedPaths).includes(facet.path);
354
+ const shouldRenderChildren = (Object.keys(facet.children).length > 0 &&
355
+ (isSelected || isChildSelected)) ||
356
+ keyName === '@@root';
357
+ return (h("div", { class: 'searchcraft-facet-list-item' }, keyName !== '@@root' && (h("label", { class: 'searchcraft-facet-list-checkbox-label' }, h("div", { class: 'searchcraft-facet-list-checkbox-input-wrapper' }, h("input", { class: 'searchcraft-facet-list-checkbox-input', checked: this.selectedPaths[facet.path], onChange: (_event) => {
358
+ this.handleCheckboxChange(facet.path);
359
+ }, type: 'checkbox' }), isChildSelected ? (h("div", { class: 'searchcraft-facet-list-checkbox-input-dash-icon' }, h("svg", { viewBox: '0 0 14 3', fill: 'none' }, h("title", null, "Checkbox dash"), h("line", { x1: '1.5', y1: '1.5', x2: '12.5', y2: '1.5', stroke: 'white', "stroke-width": '3', "stroke-linecap": 'round' })))) : (h("div", { class: 'searchcraft-facet-list-checkbox-input-check-icon' }, h("svg", { width: '16', height: '16', viewBox: '0 0 16 16', fill: 'none' }, h("title", null, "Checkbox check"), h("path", { d: 'M13.9999 2L5.74988 10L1.99988 6.36364', stroke: 'white', "stroke-width": '3', "stroke-linecap": 'round', "stroke-linejoin": 'round' }))))), h("span", null, this.formatFacetName(keyName), " (", facet.count, ")"))), shouldRenderChildren && (h("div", { class: 'searchcraft-facet-list', style: {
360
+ paddingLeft: keyName !== '@@root' ? '24px' : '0px',
361
+ paddingTop: keyName !== '@@root' ? '6px' : '0px',
362
+ } }, Object.keys(facet.children).map((key) => {
363
+ if (facet.children[key]) {
364
+ return this.renderFacet(key, facet.children[key]);
365
+ }
366
+ })))));
367
+ }
368
+ render() {
369
+ if (!this.fieldName) {
370
+ return;
371
+ }
372
+ if (Object.keys(this.facetTreeCollectedFromSearchResponse.children).length ===
373
+ 0 &&
374
+ (this.lastSearchTerm || '').trim().length === 0) {
375
+ return;
376
+ }
377
+ if (Object.keys(this.facetTreeCollectedFromSearchResponse.children).length ===
378
+ 0 &&
379
+ (this.lastSearchTerm || '').trim().length > 0) {
380
+ return (h("p", { class: 'searchcraft-facet-list-message' }, "No facets are available for this search query."));
381
+ }
382
+ return (h("div", { class: 'searchcraft-facet-list' }, this.renderFacet('@@root', this.renderedFacetTree)));
383
+ }
384
+ }, [0, "searchcraft-facet-list", {
385
+ "fieldName": [1, "field-name"],
386
+ "selectedPaths": [32],
387
+ "facetTreeCollectedFromSearchResponse": [32],
388
+ "renderedFacetTree": [32]
389
+ }]);
390
+ function defineCustomElement() {
391
+ if (typeof customElements === "undefined") {
392
+ return;
393
+ }
394
+ const components = ["searchcraft-facet-list"];
395
+ components.forEach(tagName => { switch (tagName) {
396
+ case "searchcraft-facet-list":
397
+ if (!customElements.get(tagName)) {
398
+ customElements.define(tagName, SearchcraftFacetList);
399
+ }
400
+ break;
401
+ } });
402
+ }
403
+
404
+ export { SearchcraftFacetList as S, defineCustomElement as d };
405
+
406
+ //# sourceMappingURL=p-b194d081.js.map