@preline/select 4.2.0 → 5.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -161,6 +161,8 @@ Data options are specified in the `data-hs-select` attribute as a JSON object.
161
161
  | `:preventSearchInsideDescription` | Inside `data-hs-select` | boolean | `false` | Prevents searching inside the description when set to `true`. |
162
162
  | `:mode` | Inside `data-hs-select` | `'default'` \| `'tags'` | `'default'` | Define a select mode. `default` for single/multiple selection, `tags` for tag-based selection. |
163
163
  | `:scrollToSelected` | Inside `data-hs-select` | boolean | `false` | Scroll to the selected option when the dropdown is opened. |
164
+ | `:value` | Inside `data-hs-select` | string \| string[] | - | Defines the initial selected value. Use an array when the select is multiple. |
165
+ | `:viewport` | Inside `data-hs-select` | string | - | Defines the viewport selector used when recalculating dropdown direction and available space. |
164
166
  | `:toggleTag` | Inside `data-hs-select` | string (HTML markup) | - | Define a markup for the select toggle. Note: `data-title` is required if you are using a custom placeholder. |
165
167
  | `:toggleClasses` | Inside `data-hs-select` | string | - | Define CSS classes for the selects' toggle. CSS classes must be separated by a space. |
166
168
  | `:toggleSeparators` | Inside `data-hs-select` | object | - | Define separators for the selects' toggle. |
@@ -181,6 +183,11 @@ Data options are specified in the `data-hs-select` attribute as a JSON object.
181
183
  | `:dropdownAutoPlacement` | Inside `data-hs-select` | boolean | `false` | Automatically determine the placement of the menu based on the available space. Requires the `Floating UI` and `dropdownScope` option to be `window`. |
182
184
  | `:dropdownVerticalFixedPlacement` | Inside `data-hs-select` | `"top"` \| `"bottom"` \| null | `null` | Specifies a fixed vertical position for the menu when opened. It will not change when scrolling. |
183
185
  | `:dropdownScope` | Inside `data-hs-select` | `"window"` \| `"parent"` | `"parent"` | Determines whether the dropdown will be moved outside the parent, for correct display in elements with hidden overflow. Requires the `Floating UI` plugin. |
186
+ | `:dropdownDirectionClasses` | Inside `data-hs-select` | `{ top?: string; bottom?: string; }` | `null` | Defines classes that are applied when the dropdown is placed above or below the toggle. |
187
+ | `:dropdownSpace` | Inside `data-hs-select` | number | `10` | Defines the spacing in pixels between the toggle and dropdown. |
188
+ | `:searchTemplate` | Inside `data-hs-select` | string (HTML markup) | `"<input type=\"text\">"` | This option is only available when `hasSearch: true`. Define a custom markup for the search input. |
189
+ | `:searchWrapperTemplate` | Inside `data-hs-select` | string (HTML markup) | `"<div></div>"` | This option is only available when `hasSearch: true`. Define a custom markup for the search wrapper. |
190
+ | `:searchWrapperClasses` | Inside `data-hs-select` | string | `"bg-white p-2 sticky top-0"` | This option is only available when `hasSearch: true`. Define CSS classes for the search wrapper. |
184
191
  | `:searchId` | Inside `data-hs-select` | string | - | This option is only available when `hasSearch: true`. This option is useful if there is a need to associate a `label` outside the initialized element with the search input. |
185
192
  | `:searchLimit` | Inside `data-hs-select` | number | `Infinity` | This option is only available when `hasSearch: true`. If this option is enabled, the search will display only the first 'n' matching items. |
186
193
  | `:isSearchDirectMatch` | Inside `data-hs-select` | boolean | `true` | This option is only available when `hasSearch: true`. If the option is disabled, then in the search results you will be able to see non-direct matches by text. For example, if you entered `england` in the search field, then `Eng-land`, `Eng.land`, `Eng_land` will also be shown. |
@@ -193,7 +200,6 @@ Data options are specified in the `data-hs-select` attribute as a JSON object.
193
200
  | `:optionTemplate` | Inside `data-hs-select` | string (HTML markup) | - | Define template for the single option. It could contain: `data-icon` if target option tag has `data-hs-select-option:icon`, `data-title` the text from the target option, `data-description` if target option tag has `data-hs-select-option:description`. |
194
201
  | `:optionTag` | Inside `data-hs-select` | string (HTML markup) | - | Define a markup for the single option. |
195
202
  | `:optionClasses` | Inside `data-hs-select` | string | - | Define CSS classes for the single option. CSS classes must be separated by a space. |
196
- | `:optionGroupTemplate` | Inside `data-hs-select` | string (HTML markup) | - | Define template for the single option group. |
197
203
  | `:optgroupTag` | Inside `data-hs-select` | string (HTML markup) | - | Define a markup for the single option group. |
198
204
  | `:optgroupClasses` | Inside `data-hs-select` | string | - | Define CSS classes for the single option group. CSS classes must be separated by a space. |
199
205
  | `:extraMarkup` | Inside `data-hs-select` | string \| array (HTML markup) | - | Define a markup that could be extra added to the wrapper of the select for the decoration reasons. If it contains the `--prevent-click` class, clicking on this element will not trigger the open function. |
@@ -206,14 +212,16 @@ Data options are specified in the `data-hs-select` attribute as a JSON object.
206
212
  | `:apiOptions` | Inside `data-hs-select` | RequestInit \| null | `null` | Defines options for the fetch function. |
207
213
  | `:apiDataPart` | Inside `data-hs-select` | string \| null | `null` | If data is in some first level parameter, then it allows you to specify the name of this parameter to extract the data. |
208
214
  | `:apiSearchQueryKey` | Inside `data-hs-select` | string \| null | `null` | Defines the key for the query search parameter. |
209
- | `:apiFieldsMap` | Inside `data-hs-select` | `{ id: string; title: string; val?: string; icon?: string \| null; description?: string \| null; } \| null` | `null` | Allows you to convert fields from the API to the fields required for the plugin to work. |
215
+ | `:apiFieldsMap` | Inside `data-hs-select` | `{ id: string; title: string; val?: string; icon?: string \| null; description?: string \| null; page?: string; offset?: string; limit?: string; pageStart?: string; totalPath?: string; [key: string]: unknown; } \| null` | `null` | Allows you to convert fields from the API to the fields required for the plugin to work. `page`, `offset`, and `limit` customize pagination parameter names for remote data. |
210
216
  | `:apiLoadMore` | Inside `data-hs-select` | `boolean \| { perPage?: number; scrollThreshold?: number; }` | `false` | Defines the options for the load more feature. |
217
+ | `:apiPageStart` | Inside `data-hs-select` | number | - | Defines the first page or offset value used for remote option loading. If omitted, page-based loading starts from `1` and offset-based loading starts from `0`. |
218
+ | `:apiTotalPath` | Inside `data-hs-select` | string \| null | `null` | Defines the response path used to read the total result count for remote option loading. |
211
219
  | `:apiSelectedValues` | Inside `data-hs-select` | `string \| string[] \| null` | `null` | Allows to preselect values when loading options from an API. Can be a single value or an array of values for multiple selection. |
212
220
  | `:apiIconTag` | Inside `data-hs-select` | string \| null | `null` | Allows to define an `img` tag that will be used when rendering options and in the trigger button. |
213
221
  | `data-hs-select-option` | Option element | object | - | Allows to define the parameters for the single option. Should be added to the option. |
214
222
  | `:description` | Inside `data-hs-select-option` | string | - | Allows to define the description of the option inside the element that have `data-description` attribute. |
215
223
  | `:icon` | Inside `data-hs-select-option` | string | - | Allows to define the icon of the option inside the element that have `data-icon` attribute. |
216
- | `:additinalClasses` | Inside `data-hs-select-option` | `[string, string[]][]` | - | Allows to define additional classes. The first string is the selector of the element to apply the classes to, the second string is an array of classes to apply. If the selector is set to `null`, the classes will be applied to the option itself. |
224
+ | `:additionalClasses` | Inside `data-hs-select-option` | `[string, string[]][]` | - | Allows to define additional classes. The first string is the selector of the element to apply the classes to, the second string is an array of classes to apply. If the selector is set to `null`, the classes will be applied to the option itself. |
217
225
  | `:apiFields` | Inside `data-hs-select-option` | `{ [key: string]: unknown; }` | - | Allows to define the fields of the option from the API. |
218
226
 
219
227
  ### Tailwind Modifiers
@@ -328,6 +336,10 @@ Select instances emit events that can be listened to for selection lifecycle hoo
328
336
  | Event Name | When Fired | Callback Parameter | Description |
329
337
  | --- | --- | --- | --- |
330
338
  | `on:change` | When the selected value changes | `string | string[]` (new selected value; array in multi-select / tags mode) | Fires after the user picks an option or removes a tag. |
339
+ | `on:request` | Right before an `apiUrl` request is sent (search or `apiLoadMore` pagination) | `{ url: string }` | Useful for showing a loading indicator. |
340
+ | `on:requestCompleted` | After an `apiUrl` request settles, success or failure | `{ url: string, data?: unknown, error?: unknown }` | `data` holds the parsed response on success, `error` is set on failure. Not fired when a request is superseded/aborted (e.g. a newer search query). |
341
+
342
+ Both are also dispatched as DOM `CustomEvent`s (`request.hs.select` / `requestCompleted.hs.select`) with the same payload under `event.detail.payload`, so they can be listened to via `addEventListener` as well as `element.on(...)`.
331
343
 
332
344
  ### Event Usage Example
333
345
 
@@ -343,6 +355,18 @@ if (instance) {
343
355
  console.log('Selected value:', value);
344
356
  // value is a string for single-select, string[] for multi-select / tags mode
345
357
  });
358
+
359
+ // Listen for API request lifecycle (only relevant when `apiUrl` is set)
360
+ element.on('request', ({ url }) => {
361
+ console.log('Requesting:', url);
362
+ // e.g. show a loading spinner
363
+ });
364
+
365
+ element.on('requestCompleted', ({ data, error }) => {
366
+ if (error) console.error('Request failed:', error);
367
+ else console.log('Request completed with:', data);
368
+ // e.g. hide the loading spinner
369
+ });
346
370
  }
347
371
  ```
348
372
 
@@ -392,6 +416,6 @@ Load options from API.
392
416
 
393
417
  ## License
394
418
 
395
- Copyright (c) 2026 Preline Labs.
419
+ Copyright (c) 2024 Htmlstream.
396
420
 
397
421
  Licensed under the [MIT License](https://opensource.org/licenses/MIT).
package/index.d.ts CHANGED
@@ -95,6 +95,7 @@ export interface ISelectOptions {
95
95
  searchNoResultText?: string | null;
96
96
  searchNoResultClasses?: string | null;
97
97
  optionAllowEmptyOption?: boolean;
98
+ optionValueAsTitle?: boolean;
98
99
  optionTemplate?: string;
99
100
  optionTag?: string;
100
101
  optionClasses?: string;
@@ -188,6 +189,7 @@ declare class HSSelect extends HSBasePlugin<ISelectOptions> implements ISelect {
188
189
  private readonly searchNoResultText;
189
190
  private readonly searchNoResultClasses;
190
191
  private readonly optionAllowEmptyOption;
192
+ private readonly optionValueAsTitle;
191
193
  private readonly optionTag;
192
194
  private readonly optionTemplate;
193
195
  private readonly optionClasses;
@@ -251,6 +253,7 @@ declare class HSSelect extends HSBasePlugin<ISelectOptions> implements ISelect {
251
253
  private buildExtraMarkup;
252
254
  private buildToggle;
253
255
  private setToggleIcon;
256
+ private setToggleText;
254
257
  private setToggleTitle;
255
258
  private buildTags;
256
259
  private reassignTagsInputPlaceholder;
package/index.js CHANGED
@@ -1,24 +1,24 @@
1
- !function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var i=e();for(var s in i)("object"==typeof exports?exports:t)[s]=i[s]}}(self,()=>(()=>{"use strict";var t={8223(t,e){Object.defineProperty(e,"__esModule",{value:!0}),e.BREAKPOINTS=e.COMBO_BOX_ACCESSIBILITY_KEY_SET=e.SELECT_ACCESSIBILITY_KEY_SET=e.TABS_ACCESSIBILITY_KEY_SET=e.OVERLAY_ACCESSIBILITY_KEY_SET=e.DROPDOWN_ACCESSIBILITY_KEY_SET=e.POSITIONS=void 0,e.POSITIONS={auto:"auto","auto-start":"auto-start","auto-end":"auto-end",top:"top","top-left":"top-start","top-right":"top-end",bottom:"bottom","bottom-left":"bottom-start","bottom-right":"bottom-end",right:"right","right-start":"right-start","right-end":"right-end",left:"left","left-start":"left-start","left-end":"left-end"},e.DROPDOWN_ACCESSIBILITY_KEY_SET=["Escape","ArrowUp","ArrowDown","ArrowRight","ArrowLeft","Home","End","Enter"],e.OVERLAY_ACCESSIBILITY_KEY_SET=["Escape","Tab"],e.TABS_ACCESSIBILITY_KEY_SET=["ArrowUp","ArrowLeft","ArrowDown","ArrowRight","Home","End"],e.SELECT_ACCESSIBILITY_KEY_SET=["ArrowUp","ArrowLeft","ArrowDown","ArrowRight","Home","End","Escape","Enter","Space","Tab"],e.COMBO_BOX_ACCESSIBILITY_KEY_SET=["ArrowUp","ArrowLeft","ArrowDown","ArrowRight","Home","End","Escape","Enter"],e.BREAKPOINTS={xs:0,sm:640,md:768,lg:1024,xl:1280,"2xl":1536}},248(t,e,i){Object.defineProperty(e,"__esModule",{value:!0});const s=i(292);e.default=class{constructor(){this.components=[],this.currentlyOpenedComponents=[],this.activeComponent=null,this.allowedKeybindings=new Set(["Escape","Enter"," ","Space","ArrowDown","ArrowUp","ArrowLeft","ArrowRight","Tab","Home","End"]),this.initGlobalListeners()}initGlobalListeners(){document.addEventListener("keydown",t=>this.handleGlobalKeydown(t)),document.addEventListener("focusin",t=>this.handleGlobalFocusin(t))}isAllowedKeybinding(t){return!!this.allowedKeybindings.has(t.key)||!(1!==t.key.length||!/^[a-zA-Z]$/.test(t.key)||t.metaKey||t.ctrlKey||t.altKey||t.shiftKey)}getActiveComponent(t){if(!t)return null;const e=this.components.filter(e=>e.wrapper.contains(t)||e.context&&e.context.contains(t));if(0===e.length)return null;if(1===e.length)return e[0];let i=null,s=Number.MAX_SAFE_INTEGER;for(const o of e){let e=0,n=t;for(;n&&n!==o.wrapper&&n!==o.context;)e++,n=n.parentElement;e<s&&(s=e,i=o)}return i}getActiveComponentForKey(t,e){if(!t)return null;const i=this.components.filter(e=>e.wrapper.contains(t)||e.context&&e.context.contains(t));if(0===i.length)return null;const s=i.filter(t=>{const i=t.handlers;switch(e){case"Escape":return!!i.onEsc;case"Enter":return!!i.onEnter;case" ":case"Space":return!!i.onSpace;case"ArrowDown":case"ArrowUp":case"ArrowLeft":case"ArrowRight":return!!i.onArrow;case"Tab":return!!i.onTab||!!i.onShiftTab;case"Home":return!!i.onHome;case"End":return!!i.onEnd;default:return!!i.onFirstLetter}});if(0===s.length)return this.getActiveComponent(t);if(1===s.length)return s[0];let o=null,n=Number.MAX_SAFE_INTEGER;for(const e of s){let i=0,s=t;for(;s&&s!==e.wrapper&&s!==e.context;)i++,s=s.parentElement;i<n&&(n=i,o=e)}return o}getDistanceToComponent(t,e){let i=0,s=t;for(;s&&s!==e.wrapper&&s!==e.context;)i++,s=s.parentElement;return i}getComponentsByNesting(t){if(!t)return[];const e=this.components.filter(e=>e.wrapper.contains(t)||e.context&&e.context.contains(t));return e.length<=1?e:[...e].sort((e,i)=>this.getDistanceToComponent(t,i)-this.getDistanceToComponent(t,e))}getSequentialHandlersForKey(t,e){const i=this.getComponentsByNesting(t);return 0===i.length?[]:i.map(t=>"Enter"===e?t.handlers.onEnter:t.handlers.onSpace).filter(t=>"function"==typeof t)}executeSequentialHandlers(t,e){let i=!1,s=!1;for(const o of t){i=!0;if(!1===o(e)){s=!0;break}}return{called:i,stopped:s}}handleGlobalFocusin(t){const e=t.target;this.activeComponent=this.getActiveComponent(e)}handleGlobalKeydown(t){var e;const i=t.target;this.activeComponent=this.getActiveComponentForKey(i,t.key);const o=this.activeComponent,n="Enter"===t.key||" "===t.key||"Space"===t.key;if((o||n)&&this.isAllowedKeybinding(t))switch(t.key){case"Escape":if(!o)break;if(o.isOpened){if(o.handlers.onEsc){const e=o.handlers.onEsc();if(t.preventDefault(),t.stopPropagation(),!1===e){const t=this.findClosestOpenParent(i);(null==t?void 0:t.handlers.onEsc)&&t.handlers.onEsc()}}}else{const e=this.findClosestOpenParent(i);(null==e?void 0:e.handlers.onEsc)&&(e.handlers.onEsc(),t.preventDefault(),t.stopPropagation())}break;case"Enter":{const e=this.getSequentialHandlersForKey(i,"Enter");if(0===e.length)break;const{called:o,stopped:n}=this.executeSequentialHandlers(e,t);if(o&&!(0,s.isFormElement)(i)&&(t.stopPropagation(),t.preventDefault()),n)break;break}case" ":case"Space":{if("INPUT"===i.tagName||"TEXTAREA"===i.tagName)return;const e=this.getActiveComponent(i),s=this.getSequentialHandlersForKey(i,"Space");if(0===s.length)break;const{stopped:o}=this.executeSequentialHandlers(s);(o||(null==e?void 0:e.handlers.onSpace))&&(t.preventDefault(),t.stopPropagation());break}case"ArrowDown":case"ArrowUp":case"ArrowLeft":case"ArrowRight":if(!o)break;if(o.handlers.onArrow){if(t.metaKey||t.ctrlKey||t.altKey||t.shiftKey)return;o.handlers.onArrow(t),t.preventDefault(),t.stopPropagation()}break;case"Tab":if(!o)break;if(!o.handlers.onTab)break;const n=t.shiftKey?o.handlers.onShiftTab:o.handlers.onTab;n&&n(t);break;case"Home":if(!o)break;o.handlers.onHome&&(o.handlers.onHome(),t.preventDefault(),t.stopPropagation());break;case"End":if(!o)break;o.handlers.onEnd&&(o.handlers.onEnd(),t.preventDefault(),t.stopPropagation());break;default:if(!o)break;if(o.handlers.onFirstLetter&&1===t.key.length&&/^[a-zA-Z]$/.test(t.key)){if(o.handlers.onFirstLetter(t.key),!(null===(e=o.stopPropagation)||void 0===e?void 0:e.onFirstLetter))return;t.preventDefault(),t.stopPropagation()}}}findClosestOpenParent(t){let e=t.parentElement;for(;e;){const t=this.currentlyOpenedComponents.find(t=>t.wrapper===e&&t!==this.activeComponent);if(t)return t;e=e.parentElement}return null}registerComponent(t,e,i=!0,s="",o="",n,l){const a={wrapper:t,handlers:e,isOpened:i,name:s,selector:o,context:n,isRegistered:!0,stopPropagation:l};return this.components.push(a),a}updateComponentState(t,e){t.isOpened=e,e?this.currentlyOpenedComponents.includes(t)||this.currentlyOpenedComponents.push(t):this.currentlyOpenedComponents=this.currentlyOpenedComponents.filter(e=>e!==t)}unregisterComponent(t){this.components=this.components.filter(e=>e!==t),this.currentlyOpenedComponents=this.currentlyOpenedComponents.filter(e=>e!==t)}addAllowedKeybinding(t){this.allowedKeybindings.add(t)}removeAllowedKeybinding(t){this.allowedKeybindings.delete(t)}getAllowedKeybindings(){return Array.from(this.allowedKeybindings)}}},2961(t,e){
1
+ !function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var i=e();for(var s in i)("object"==typeof exports?exports:t)[s]=i[s]}}(self,()=>(()=>{"use strict";var t={8223(t,e){Object.defineProperty(e,"__esModule",{value:!0}),e.BREAKPOINTS=e.COMBO_BOX_ACCESSIBILITY_KEY_SET=e.SELECT_ACCESSIBILITY_KEY_SET=e.TABS_ACCESSIBILITY_KEY_SET=e.OVERLAY_ACCESSIBILITY_KEY_SET=e.DROPDOWN_ACCESSIBILITY_KEY_SET=e.POSITIONS=void 0,e.POSITIONS={auto:"auto","auto-start":"auto-start","auto-end":"auto-end",top:"top","top-left":"top-start","top-right":"top-end",bottom:"bottom","bottom-left":"bottom-start","bottom-right":"bottom-end",right:"right","right-start":"right-start","right-end":"right-end",left:"left","left-start":"left-start","left-end":"left-end"},e.DROPDOWN_ACCESSIBILITY_KEY_SET=["Escape","ArrowUp","ArrowDown","ArrowRight","ArrowLeft","Home","End","Enter"],e.OVERLAY_ACCESSIBILITY_KEY_SET=["Escape","Tab"],e.TABS_ACCESSIBILITY_KEY_SET=["ArrowUp","ArrowLeft","ArrowDown","ArrowRight","Home","End"],e.SELECT_ACCESSIBILITY_KEY_SET=["ArrowUp","ArrowLeft","ArrowDown","ArrowRight","Home","End","Escape","Enter","Space","Tab"],e.COMBO_BOX_ACCESSIBILITY_KEY_SET=["ArrowUp","ArrowLeft","ArrowDown","ArrowRight","Home","End","Escape","Enter"],e.BREAKPOINTS={xs:0,sm:640,md:768,lg:1024,xl:1280,"2xl":1536}},248(t,e,i){Object.defineProperty(e,"__esModule",{value:!0});const s=i(292);e.default=class{constructor(){this.components=[],this.currentlyOpenedComponents=[],this.activeComponent=null,this.allowedKeybindings=new Set(["Escape","Enter"," ","Space","ArrowDown","ArrowUp","ArrowLeft","ArrowRight","Tab","Home","End"]),this.initGlobalListeners()}initGlobalListeners(){document.addEventListener("keydown",t=>this.handleGlobalKeydown(t)),document.addEventListener("focusin",t=>this.handleGlobalFocusin(t))}isAllowedKeybinding(t){return!!this.allowedKeybindings.has(t.key)||!(1!==t.key.length||!/^[a-zA-Z]$/.test(t.key)||t.metaKey||t.ctrlKey||t.altKey||t.shiftKey)}getActiveComponent(t){if(!t)return null;const e=this.components.filter(e=>e.wrapper.contains(t)||e.context&&e.context.contains(t));if(0===e.length)return null;if(1===e.length)return e[0];let i=null,s=Number.MAX_SAFE_INTEGER;for(const o of e){let e=0,l=t;for(;l&&l!==o.wrapper&&l!==o.context;)e++,l=l.parentElement;e<s&&(s=e,i=o)}return i}getActiveComponentForKey(t,e){if(!t)return null;const i=this.components.filter(e=>e.wrapper.contains(t)||e.context&&e.context.contains(t));if(0===i.length)return null;const s=i.filter(t=>{const i=t.handlers;switch(e){case"Escape":return!!i.onEsc;case"Enter":return!!i.onEnter;case" ":case"Space":return!!i.onSpace;case"ArrowDown":case"ArrowUp":case"ArrowLeft":case"ArrowRight":return!!i.onArrow;case"Tab":return!!i.onTab||!!i.onShiftTab;case"Home":return!!i.onHome;case"End":return!!i.onEnd;default:return!!i.onFirstLetter}});if(0===s.length)return this.getActiveComponent(t);if(1===s.length)return s[0];let o=null,l=Number.MAX_SAFE_INTEGER;for(const e of s){let i=0,s=t;for(;s&&s!==e.wrapper&&s!==e.context;)i++,s=s.parentElement;i<l&&(l=i,o=e)}return o}getDistanceToComponent(t,e){let i=0,s=t;for(;s&&s!==e.wrapper&&s!==e.context;)i++,s=s.parentElement;return i}getComponentsByNesting(t){if(!t)return[];const e=this.components.filter(e=>e.wrapper.contains(t)||e.context&&e.context.contains(t));return e.length<=1?e:[...e].sort((e,i)=>this.getDistanceToComponent(t,i)-this.getDistanceToComponent(t,e))}getSequentialHandlersForKey(t,e){const i=this.getComponentsByNesting(t);return 0===i.length?[]:i.map(i=>"Enter"===e?i.onEnterSelfOnly&&i.wrapper!==t?void 0:i.handlers.onEnter:i.handlers.onSpace).filter(t=>"function"==typeof t)}executeSequentialHandlers(t,e){let i=!1,s=!1;for(const o of t){i=!0;if(!1===o(e)){s=!0;break}}return{called:i,stopped:s}}handleGlobalFocusin(t){const e=t.target;this.activeComponent=this.getActiveComponent(e)}handleGlobalKeydown(t){var e;const i=t.target;this.activeComponent=this.getActiveComponentForKey(i,t.key);const o=this.activeComponent,l="Enter"===t.key||" "===t.key||"Space"===t.key;if((o||l)&&this.isAllowedKeybinding(t))switch(t.key){case"Escape":if(!o)break;if(o.isOpened){if(o.handlers.onEsc){const e=o.handlers.onEsc();if(t.preventDefault(),t.stopPropagation(),!1===e){const t=this.findClosestOpenParent(i);(null==t?void 0:t.handlers.onEsc)&&t.handlers.onEsc()}}}else{const e=this.findClosestOpenParent(i);(null==e?void 0:e.handlers.onEsc)&&(e.handlers.onEsc(),t.preventDefault(),t.stopPropagation())}break;case"Enter":{const e=this.getSequentialHandlersForKey(i,"Enter");if(0===e.length)break;const{called:o,stopped:l}=this.executeSequentialHandlers(e,t);if(o&&!(0,s.isFormElement)(i)&&(t.stopPropagation(),t.preventDefault()),l)break;break}case" ":case"Space":{if("INPUT"===i.tagName||"TEXTAREA"===i.tagName)return;const e=this.getActiveComponent(i),s=this.getSequentialHandlersForKey(i,"Space");if(0===s.length)break;const{stopped:o}=this.executeSequentialHandlers(s);(o||(null==e?void 0:e.handlers.onSpace))&&(t.preventDefault(),t.stopPropagation());break}case"ArrowDown":case"ArrowUp":case"ArrowLeft":case"ArrowRight":if(!o)break;if(o.handlers.onArrow){if(t.metaKey||t.ctrlKey||t.altKey||t.shiftKey)return;o.handlers.onArrow(t),t.preventDefault(),t.stopPropagation()}break;case"Tab":if(!o)break;if(!o.handlers.onTab)break;const l=t.shiftKey?o.handlers.onShiftTab:o.handlers.onTab;l&&l(t);break;case"Home":if(!o)break;o.handlers.onHome&&(o.handlers.onHome(),t.preventDefault(),t.stopPropagation());break;case"End":if(!o)break;o.handlers.onEnd&&(o.handlers.onEnd(),t.preventDefault(),t.stopPropagation());break;default:if(!o)break;if(o.handlers.onFirstLetter&&1===t.key.length&&/^[a-zA-Z]$/.test(t.key)){if(o.handlers.onFirstLetter(t.key),!(null===(e=o.stopPropagation)||void 0===e?void 0:e.onFirstLetter))return;t.preventDefault(),t.stopPropagation()}}}findClosestOpenParent(t){let e=t.parentElement;for(;e;){const t=this.currentlyOpenedComponents.find(t=>t.wrapper===e&&t!==this.activeComponent);if(t)return t;e=e.parentElement}return null}registerComponent(t,e,i=!0,s="",o="",l,n){const a={wrapper:t,handlers:e,isOpened:i,name:s,selector:o,context:l,isRegistered:!0,stopPropagation:n};return this.components.push(a),a}updateComponentState(t,e){t.isOpened=e,e?this.currentlyOpenedComponents.includes(t)||this.currentlyOpenedComponents.push(t):this.currentlyOpenedComponents=this.currentlyOpenedComponents.filter(e=>e!==t)}unregisterComponent(t){this.components=this.components.filter(e=>e!==t),this.currentlyOpenedComponents=this.currentlyOpenedComponents.filter(e=>e!==t)}addAllowedKeybinding(t){this.allowedKeybindings.add(t)}removeAllowedKeybinding(t){this.allowedKeybindings.delete(t)}getAllowedKeybindings(){return Array.from(this.allowedKeybindings)}}},2961(t,e){
2
2
  /*
3
3
  * HSBasePlugin
4
- * @version: 4.2.0
4
+ * @version: 5.1.0
5
5
  * @author: Preline Labs Ltd.
6
6
  * @license: Licensed under MIT and Preline UI Fair Use License (https://preline.co/docs/license.html)
7
7
  * Copyright 2024 Preline Labs Ltd.
8
8
  */
9
- Object.defineProperty(e,"__esModule",{value:!0});e.default=class{constructor(t,e,i){this.el=t,this.options=e,this.events=i,this.el=t,this.options=e,this.events={}}createCollection(t,e){var i,s;let o=t;if(!Array.isArray(o)&&"undefined"!=typeof window){const t=null===(i=this.constructor)||void 0===i?void 0:i.name,e="string"==typeof t&&t.startsWith("HS")?`$hs${t.slice(2)}Collection`:null;e&&(Array.isArray(window[e])||(window[e]=[]),o=window[e])}Array.isArray(o)&&o.push({id:(null===(s=null==e?void 0:e.el)||void 0===s?void 0:s.id)||o.length+1,element:e})}fireEvent(t,e=null){if(this.events.hasOwnProperty(t))return this.events[t](e)}on(t,e){this.events[t]=e}}},4375(t,e,i){var s=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const o=s(i(591)),n=i(292);window.addEventListener("load",()=>{o.default.autoInit()});const l=(0,n.debounce)(t=>{if(!window.$hsSelectCollection)return!1;const e=window.$hsSelectCollection.find(t=>t.element.isOpened());if(!e)return!1;const i=document.activeElement,s=(null==t?void 0:t.target)||null;if(i&&e.element.containsDropdownElement(i)||s&&e.element.containsDropdownElement(s))return!1;e.element.recalculateDirection()},150);document.addEventListener("scroll",l),"undefined"!=typeof window&&(window.HSSelect=o.default)},591(t,e,i){
9
+ Object.defineProperty(e,"__esModule",{value:!0});e.default=class{constructor(t,e,i){this.el=t,this.options=e,this.events=i,this.el=t,this.options=e,this.events={}}createCollection(t,e){var i,s;let o=t;if(!Array.isArray(o)&&"undefined"!=typeof window){const t=null===(i=this.constructor)||void 0===i?void 0:i.name,e="string"==typeof t&&t.startsWith("HS")?`$hs${t.slice(2)}Collection`:null;e&&(Array.isArray(window[e])||(window[e]=[]),o=window[e])}Array.isArray(o)&&o.push({id:(null===(s=null==e?void 0:e.el)||void 0===s?void 0:s.id)||o.length+1,element:e})}fireEvent(t,e=null){if(this.events.hasOwnProperty(t))return this.events[t](e)}on(t,e){this.events[t]=e}}},4375(t,e,i){var s=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const o=s(i(591)),l=i(292);window.addEventListener("load",()=>{o.default.autoInit()});const n=(0,l.debounce)(t=>{if(!window.$hsSelectCollection)return!1;const e=window.$hsSelectCollection.find(t=>t.element.isOpened());if(!e)return!1;const i=document.activeElement,s=(null==t?void 0:t.target)||null;if(i&&e.element.containsDropdownElement(i)||s&&e.element.containsDropdownElement(s))return!1;e.element.recalculateDirection()},150);document.addEventListener("scroll",n),"undefined"!=typeof window&&(window.HSSelect=o.default)},591(t,e,i){
10
10
  /*
11
11
  * HSSelect
12
- * @version: 4.2.0
12
+ * @version: 5.1.0
13
13
  * @author: Preline Labs Ltd.
14
14
  * @license: Licensed under MIT and Preline UI Fair Use License (https://preline.co/docs/license.html)
15
15
  * Copyright 2024 Preline Labs Ltd.
16
16
  */
17
- var s=this&&this.__awaiter||function(t,e,i,s){return new(i||(i=Promise))(function(o,n){function l(t){try{r(s.next(t))}catch(t){n(t)}}function a(t){try{r(s.throw(t))}catch(t){n(t)}}function r(t){var e;t.done?o(t.value):(e=t.value,e instanceof i?e:new i(function(t){t(e)})).then(l,a)}r((s=s.apply(t,e||[])).next())})},o=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const n=i(292),l=o(i(2961)),a=o(i(248)),r=i(8223);class d extends l.default{constructor(t,e){var i,s,o,n,l;super(t,e),this.disabledObserver=null,this.remoteSearchAbortController=null,this.loadMoreAbortController=null,this.requestId=0,this.lastQuery="",this.isLoadEventFired=!1,this.optionId=0;const a=t.getAttribute("data-hs-select"),r=a?JSON.parse(a):{},d=Object.assign(Object.assign({},r),e);this.value=(null==d?void 0:d.value)||this.el.value||null,this.placeholder=(null==d?void 0:d.placeholder)||"Select...",this.hasSearch=(null==d?void 0:d.hasSearch)||!1,this.minSearchLength=null!==(i=null==d?void 0:d.minSearchLength)&&void 0!==i?i:0,this.preventSearchFocus=(null==d?void 0:d.preventSearchFocus)||!1,this.preventSearchInsideDescription=(null==d?void 0:d.preventSearchInsideDescription)||!1,this.mode=(null==d?void 0:d.mode)||"default",this.viewport=void 0!==(null==d?void 0:d.viewport)?document.querySelector(null==d?void 0:d.viewport):null,this.scrollToSelected=void 0!==(null==d?void 0:d.scrollToSelected)&&(null==d?void 0:d.scrollToSelected),this._isOpened=Boolean(null==d?void 0:d.isOpened)||!1,this.isMultiple=this.el.hasAttribute("multiple")||!1,this.isDisabled=this.el.hasAttribute("disabled")||!1,this.selectedItems=[],this.apiUrl=(null==d?void 0:d.apiUrl)||null,this.apiQuery=(null==d?void 0:d.apiQuery)||null,this.apiOptions=(null==d?void 0:d.apiOptions)||null,this.apiSearchQueryKey=(null==d?void 0:d.apiSearchQueryKey)||null,this.apiDataPart=(null==d?void 0:d.apiDataPart)||null,this.apiLoadMore=!0===(null==d?void 0:d.apiLoadMore)?{perPage:10,scrollThreshold:100}:"object"==typeof(null==d?void 0:d.apiLoadMore)&&null!==(null==d?void 0:d.apiLoadMore)&&{perPage:d.apiLoadMore.perPage||10,scrollThreshold:d.apiLoadMore.scrollThreshold||100},this.apiPageStart="number"==typeof(null==d?void 0:d.apiPageStart)?d.apiPageStart:void 0,this.apiTotalPath="string"==typeof(null==d?void 0:d.apiTotalPath)?d.apiTotalPath:null,this.apiFieldsMap=(null==d?void 0:d.apiFieldsMap)||null,this.apiIconTag=(null==d?void 0:d.apiIconTag)||null,this.apiSelectedValues=(null==d?void 0:d.apiSelectedValues)||null,this.currentPage=0,this.isLoading=!1,this.hasMore=!0,this.wrapperClasses=(null==d?void 0:d.wrapperClasses)||null,this.toggleTag=(null==d?void 0:d.toggleTag)||null,this.toggleClasses=(null==d?void 0:d.toggleClasses)||null,this.toggleCountText=void 0===typeof(null==d?void 0:d.toggleCountText)?null:d.toggleCountText,this.toggleCountTextPlacement=(null==d?void 0:d.toggleCountTextPlacement)||"postfix",this.toggleCountTextMinItems=(null==d?void 0:d.toggleCountTextMinItems)||1,this.toggleCountTextMode=(null==d?void 0:d.toggleCountTextMode)||"countAfterLimit",this.toggleSeparators={items:(null===(s=null==d?void 0:d.toggleSeparators)||void 0===s?void 0:s.items)||", ",betweenItemsAndCounter:(null===(o=null==d?void 0:d.toggleSeparators)||void 0===o?void 0:o.betweenItemsAndCounter)||"and"},this.tagsItemTemplate=(null==d?void 0:d.tagsItemTemplate)||null,this.tagsItemClasses=(null==d?void 0:d.tagsItemClasses)||null,this.tagsInputId=(null==d?void 0:d.tagsInputId)||null,this.tagsInputClasses=(null==d?void 0:d.tagsInputClasses)||null,this.dropdownTag=(null==d?void 0:d.dropdownTag)||null,this.dropdownClasses=(null==d?void 0:d.dropdownClasses)||null,this.dropdownDirectionClasses=(null==d?void 0:d.dropdownDirectionClasses)||null,this.dropdownSpace=(null==d?void 0:d.dropdownSpace)||10,this.dropdownPlacement=(null==d?void 0:d.dropdownPlacement)||null,this.dropdownVerticalFixedPlacement=(null==d?void 0:d.dropdownVerticalFixedPlacement)||null,this.dropdownScope=(null==d?void 0:d.dropdownScope)||"parent",this.dropdownAutoPlacement=(null==d?void 0:d.dropdownAutoPlacement)||!1,this.searchTemplate=(null==d?void 0:d.searchTemplate)||null,this.searchWrapperTemplate=(null==d?void 0:d.searchWrapperTemplate)||null,this.searchWrapperClasses=(null==d?void 0:d.searchWrapperClasses)||"bg-white p-2 sticky top-0",this.searchId=(null==d?void 0:d.searchId)||null,this.searchLimit=(null==d?void 0:d.searchLimit)||1/0,this.isSearchDirectMatch=void 0===(null==d?void 0:d.isSearchDirectMatch)||d.isSearchDirectMatch,this.searchMatchMode=(null==d?void 0:d.searchMatchMode)||(this.isSearchDirectMatch?"substring":"chars-sequence"),this.searchClasses=(null==d?void 0:d.searchClasses)||"block w-[calc(100%-32px)] text-sm border-gray-200 rounded-md focus:border-blue-500 focus:ring-blue-500 dark:bg-neutral-900 dark:border-neutral-700 dark:text-neutral-400 py-2 px-3 my-2 mx-4",this.searchPlaceholder=(null==d?void 0:d.searchPlaceholder)||"Search...",this.searchNoResultTemplate=(null==d?void 0:d.searchNoResultTemplate)||"<span></span>",this.searchNoResultText=(null==d?void 0:d.searchNoResultText)||"No results found",this.searchNoResultClasses=(null==d?void 0:d.searchNoResultClasses)||"px-4 text-sm text-gray-800 dark:text-neutral-200",this.optionAllowEmptyOption=void 0!==(null==d?void 0:d.optionAllowEmptyOption)&&(null==d?void 0:d.optionAllowEmptyOption),this.optionTemplate=(null==d?void 0:d.optionTemplate)||null,this.optionTag=(null==d?void 0:d.optionTag)||null,this.optionClasses=(null==d?void 0:d.optionClasses)||null,this.optgroupTag=(null==d?void 0:d.optgroupTag)||null,this.optgroupClasses=(null==d?void 0:d.optgroupClasses)||null,this.extraMarkup=(null==d?void 0:d.extraMarkup)||null,this.descriptionClasses=(null==d?void 0:d.descriptionClasses)||null,this.iconClasses=(null==d?void 0:d.iconClasses)||null,this.isAddTagOnEnter=null===(n=null==d?void 0:d.isAddTagOnEnter)||void 0===n||n,this.isSelectedOptionOnTop=null!==(l=null==d?void 0:d.isSelectedOptionOnTop)&&void 0!==l&&l,this.animationInProcess=!1,this.selectOptions=[],this.staticOptions=[],this.remoteOptions=[],this.tagsInputHelper=null,this.disabledObserver=new MutationObserver(t=>{t.some(t=>"disabled"===t.attributeName)&&this.setDisabledState(this.el.hasAttribute("disabled"))}),this.disabledObserver.observe(this.el,{attributes:!0,attributeFilter:["disabled"]}),this.init()}wrapperClick(t){t.target.closest("[data-hs-select-dropdown]")||t.target.closest("[data-tag-value]")||this.tagsInput.focus()}toggleClick(){if(this.isDisabled)return!1;this.toggleFn()}tagsInputFocus(){this._isOpened||this.open()}tagsInputInput(){this.calculateInputWidth()}tagsInputInputSecond(t){this.apiUrl||this.searchOptions(t.target.value)}tagsInputKeydown(t){if("Enter"===t.key&&this.isAddTagOnEnter){const e=t.target.value;if(this.selectOptions.find(t=>t.val===e))return!1;this.addSelectOption(e,e),this.buildOption(e,e),this.buildOriginalOption(e,e),this.dropdown.querySelector(`[data-value="${e}"]`).click(),this.resetTagsInputField()}}searchInput(t){const e=t.target.value;this.lastQuery=e,this.apiUrl?this.remoteSearch(e):this.searchOptions(e)}setValue(t){if(this.value=t,this.clearSelections(),Array.isArray(t))if("tags"===this.mode){this.unselectMultipleItems(),this.selectMultipleItems(),this.selectedItems=[];this.wrapper.querySelectorAll("[data-tag-value]").forEach(t=>t.remove()),this.setTagsItems(),this.reassignTagsInputPlaceholder(this.hasValue()?"":this.placeholder)}else this.toggleTextWrapper.innerHTML=this.hasValue()?this.stringFromValue():this.placeholder,this.unselectMultipleItems(),this.selectMultipleItems();else this.setToggleTitle(),this.toggle.querySelector("[data-icon]")&&this.setToggleIcon(),this.toggle.querySelector("[data-title]")&&this.setToggleTitle(),this.selectSingleItem()}setDisabledState(t){this.isDisabled=t;const e="tags"===this.mode?this.wrapper:this.toggle;null==e||e.classList.toggle("disabled",t),t&&this.isOpened()&&this.close()}hasValue(){return this.isMultiple?Array.isArray(this.value)&&this.value.length>0&&this.value.some(t=>null!=t&&""!==t):null!==this.value&&void 0!==this.value&&""!==this.value}init(){d.ensureGlobalHandlers(),this.createCollection(window.$hsSelectCollection,this),this.build(),"undefined"!=typeof window&&(window.HSAccessibilityObserver||(window.HSAccessibilityObserver=new a.default),this.setupAccessibility())}build(){this.el.style.display="none";if(this.el.querySelectorAll("option").length&&this.setOptions(),this.optionAllowEmptyOption&&!this.value&&(this.value=""),this.isMultiple){const t=this.el.querySelectorAll("option"),e=Array.from(t).filter(t=>t.selected),i=[];e.forEach(t=>{i.push(t.value)}),this.value=i}this.buildWrapper(),"tags"===this.mode?this.buildTags():this.buildToggle(),this.buildDropdown(),this.extraMarkup&&this.buildExtraMarkup(),this.apiUrl||this.fireLoadEvent()}fireLoadEvent(){this.isLoadEventFired||(this.isLoadEventFired=!0,setTimeout(()=>{this.fireEvent("load",this.el),(0,n.dispatch)("load.hs.select",this.el,this.el)}))}setOptions(){const t=this.el.querySelectorAll("option");Array.from(t).filter(t=>this.optionAllowEmptyOption||!this.optionAllowEmptyOption&&t.value&&""!==t.value).forEach(t=>{var e;const i=t.getAttribute("data-hs-select-option"),s={title:t.textContent,val:t.value,disabled:t.disabled,options:i&&"undefined"!==i?JSON.parse(i):null,optgroupName:"OPTGROUP"===(null===(e=t.parentElement)||void 0===e?void 0:e.tagName)?t.parentElement.label:null};this.selectOptions=[...this.selectOptions,s],this.apiUrl&&(this.staticOptions=[...this.staticOptions,s],t.setAttribute("data-static","true"))})}buildWrapper(){this.wrapper=document.createElement("div"),this.wrapper.classList.add("hs-select","relative"),this.setDisabledState(this.isDisabled),"tags"===this.mode&&(this.onWrapperClickListener=t=>this.wrapperClick(t),this.wrapper.addEventListener("click",this.onWrapperClickListener)),this.wrapperClasses&&(0,n.classToClassList)(this.wrapperClasses,this.wrapper),this.el.before(this.wrapper),this.wrapper.append(this.el)}buildExtraMarkup(){const t=t=>{const e=(0,n.htmlToElement)(t);return this.wrapper.append(e),e},e=t=>{t.classList.contains("--prevent-click")||t.addEventListener("click",t=>{t.stopPropagation(),this.isDisabled||this.toggleFn()})};if(Array.isArray(this.extraMarkup))this.extraMarkup.forEach(i=>{const s=t(i);e(s)});else{const i=t(this.extraMarkup);e(i)}}buildToggle(){var t,e;let i,s;this.toggleTextWrapper=document.createElement("span"),this.toggleTextWrapper.classList.add("truncate"),this.toggle=(0,n.htmlToElement)(this.toggleTag||"<div></div>"),i=this.toggle.querySelector("[data-icon]"),s=this.toggle.querySelector("[data-title]"),!this.isMultiple&&i&&this.setToggleIcon(),!this.isMultiple&&s&&this.setToggleTitle(),this.isMultiple?this.toggleTextWrapper.innerHTML=this.hasValue()?this.stringFromValue():this.placeholder:this.toggleTextWrapper.innerHTML=(null===(t=this.getItemByValue(this.value))||void 0===t?void 0:t.title)||this.placeholder,s||this.toggle.append(this.toggleTextWrapper),this.toggleClasses&&(0,n.classToClassList)(this.toggleClasses,this.toggle),this.isDisabled&&this.toggle.classList.add("disabled"),this.wrapper&&this.wrapper.append(this.toggle),(null===(e=this.toggle)||void 0===e?void 0:e.ariaExpanded)&&(this._isOpened?this.toggle.ariaExpanded="true":this.toggle.ariaExpanded="false"),this.onToggleClickListener=()=>this.toggleClick(),this.toggle.addEventListener("click",this.onToggleClickListener)}setToggleIcon(){var t,e,i,s;const o=this.getItemByValue(this.value),l=this.toggle.querySelector("[data-icon]");if(l){l.innerHTML="";const a=null===(e=null===(t=null==o?void 0:o.options)||void 0===t?void 0:t.apiFields)||void 0===e?void 0:e.icon,r=null==o?void 0:o[null===(i=this.apiFieldsMap)||void 0===i?void 0:i.icon],d=null===(s=null==o?void 0:o.options)||void 0===s?void 0:s.icon,h=(0,n.htmlToElement)((this.apiUrl||a)&&this.apiIconTag?this.apiIconTag||"":d||"");this.value&&(a?h.src=a:this.apiUrl&&this.apiIconTag&&r?h.src=r:d&&"string"==typeof d&&!d.trim().startsWith("<")&&(h.src=d)),l.append(h),(h instanceof HTMLImageElement?h.src:h)?l.classList.remove("hidden"):l.classList.add("hidden")}}setToggleTitle(){const t=this.toggle.querySelector("[data-title]");let e=this.placeholder;if(this.optionAllowEmptyOption&&""===this.value){const t=this.selectOptions.find(t=>""===t.val);e=(null==t?void 0:t.title)||this.placeholder}else if(this.value)if(this.apiUrl){const t=this.staticOptions.find(t=>t.val===this.value);if(t)e=t.title;else{const t=this.remoteOptions.find(t=>`${t[this.apiFieldsMap.val]}`===this.value||`${t[this.apiFieldsMap.title]}`===this.value);t&&(e=t[this.apiFieldsMap.title])}}else{const t=this.selectOptions.find(t=>t.val===this.value);t&&(e=t.title)}t?(t.innerHTML=e,t.classList.add("truncate"),this.toggle.append(t)):this.toggleTextWrapper.innerHTML=e}buildTags(){this.isDisabled&&this.wrapper.classList.add("disabled"),this.wrapper.setAttribute("tabindex","0"),this.buildTagsInput(),this.setTagsItems()}reassignTagsInputPlaceholder(t){this.tagsInput.placeholder=t,this.tagsInputHelper.innerHTML=t,this.calculateInputWidth()}buildTagsItem(t){var e,i,s,o,l,a,r,d;const h=this.getItemByValue(t);let p,c,u,g;const v=document.createElement("div");if(v.setAttribute("data-tag-value",t),this.tagsItemClasses&&(0,n.classToClassList)(this.tagsItemClasses,v),this.tagsItemTemplate&&(p=(0,n.htmlToElement)(this.tagsItemTemplate),v.append(p)),(null===(e=null==h?void 0:h.options)||void 0===e?void 0:e.icon)||this.apiIconTag){const t=(0,n.htmlToElement)(this.apiUrl&&this.apiIconTag?this.apiIconTag:null===(i=null==h?void 0:h.options)||void 0===i?void 0:i.icon);if(this.apiUrl&&this.apiIconTag){const e=h[this.apiFieldsMap.icon]||(null===(o=null===(s=null==h?void 0:h.options)||void 0===s?void 0:s.apiFields)||void 0===o?void 0:o.icon)||(null===(l=null==h?void 0:h.options)||void 0===l?void 0:l.icon)||"";e&&(t.src=e)}g=p?p.querySelector("[data-icon]"):document.createElement("span"),g.append(t),p||v.append(g)}!p||!p.querySelector("[data-icon]")||(null===(a=null==h?void 0:h.options)||void 0===a?void 0:a.icon)||this.apiUrl||this.apiIconTag||h[null===(r=this.apiFieldsMap)||void 0===r?void 0:r.icon]||p.querySelector("[data-icon]").classList.add("hidden"),c=p?p.querySelector("[data-title]"):document.createElement("span"),this.apiUrl&&(null===(d=this.apiFieldsMap)||void 0===d?void 0:d.title)&&h[this.apiFieldsMap.title]?c.textContent=h[this.apiFieldsMap.title]:c.textContent=h.title||"",p||v.append(c),p?u=p.querySelector("[data-remove]"):(u=document.createElement("span"),u.textContent="X",v.append(u)),u.addEventListener("click",()=>{this.value=this.value.filter(e=>e!==t),this.selectedItems=this.selectedItems.filter(e=>e!==t),this.hasValue()||this.reassignTagsInputPlaceholder(this.placeholder),this.unselectMultipleItems(),this.selectMultipleItems(),v.remove(),this.triggerChangeEventForNativeSelect()}),this.wrapper.append(v)}getItemByValue(t){if(this.apiUrl){const e=this.staticOptions.find(e=>e.val===t);return e||this.remoteOptions.find(e=>`${e[this.apiFieldsMap.val]}`===t||e[this.apiFieldsMap.title]===t)}return this.selectOptions.find(e=>e.val===t)}setTagsItems(){if(this.value){(Array.isArray(this.value)?this.value:null!=this.value?[this.value]:[]).forEach(t=>{this.selectedItems.includes(t)||this.buildTagsItem(t),this.selectedItems=this.selectedItems.includes(t)?this.selectedItems:[...this.selectedItems,t]})}this._isOpened&&this.floatingUIInstance&&this.floatingUIInstance.update()}buildTagsInput(){this.tagsInput=document.createElement("input"),this.tagsInputId&&(this.tagsInput.id=this.tagsInputId),this.tagsInputClasses&&(0,n.classToClassList)(this.tagsInputClasses,this.tagsInput),this.tagsInput.setAttribute("tabindex","-1"),this.onTagsInputFocusListener=()=>this.tagsInputFocus(),this.onTagsInputInputListener=()=>this.tagsInputInput(),this.onTagsInputInputSecondListener=(0,n.debounce)(t=>this.tagsInputInputSecond(t)),this.onTagsInputKeydownListener=t=>this.tagsInputKeydown(t),this.tagsInput.addEventListener("focus",this.onTagsInputFocusListener),this.tagsInput.addEventListener("input",this.onTagsInputInputListener),this.tagsInput.addEventListener("input",this.onTagsInputInputSecondListener),this.tagsInput.addEventListener("keydown",this.onTagsInputKeydownListener),this.wrapper.append(this.tagsInput),setTimeout(()=>{this.adjustInputWidth(),this.reassignTagsInputPlaceholder(this.hasValue()?"":this.placeholder)})}buildDropdown(){if(this.dropdown=(0,n.htmlToElement)(this.dropdownTag||"<div></div>"),this.dropdown.setAttribute("data-hs-select-dropdown",""),"parent"===this.dropdownScope&&(this.dropdown.classList.add("absolute"),this.dropdownVerticalFixedPlacement||this.dropdown.classList.add("top-full")),this.dropdown.role="listbox",this.dropdown.tabIndex=-1,this.dropdown.ariaOrientation="vertical",this._isOpened||this.dropdown.classList.add("hidden"),this.dropdownClasses&&(0,n.classToClassList)(this.dropdownClasses,this.dropdown),this.wrapper&&this.wrapper.append(this.dropdown),this.dropdown&&this.hasSearch&&this.buildSearch(),this.selectOptions){let t="";this.selectOptions.forEach((e,i)=>{e.optgroupName&&e.optgroupName!==t&&(this.hasOptgroup=!0,t=e.optgroupName,this.buildOptgroup(t)),this.buildOption(e.title,e.val,e.disabled,e.selected,e.options,`${i}`,void 0,!!this.apiUrl)}),t=""}this.apiUrl&&this.optionsFromRemoteData().then(()=>this.fireLoadEvent()),this.apiUrl||(this.sortElements(this.el,"option"),this.sortElements(this.dropdown,"[data-value]")),"window"===this.dropdownScope&&this.buildFloatingUI(),this.dropdown&&this.apiLoadMore&&this.setupInfiniteScroll()}buildOptgroup(t){const e=(0,n.htmlToElement)(this.optgroupTag||"<div></div>");e.textContent=t,e.setAttribute("data-optgroup",""),this.optgroupClasses&&(0,n.classToClassList)(this.optgroupClasses,e),this.dropdown.append(e)}setupInfiniteScroll(){this.dropdown.addEventListener("scroll",this.handleScroll.bind(this))}handleScroll(){return s(this,void 0,void 0,function*(){if(!this.dropdown||this.isLoading||!this.hasMore||!this.apiLoadMore)return;const{scrollTop:t,scrollHeight:e,clientHeight:i}=this.dropdown;e-t-i<("object"==typeof this.apiLoadMore?this.apiLoadMore.scrollThreshold:100)&&(yield this.loadMore())})}loadMore(){return s(this,void 0,void 0,function*(){var t,e,i,s,o,n,l,a,r,d,h,p;if(!this.apiUrl||this.isLoading||!this.hasMore||!this.apiLoadMore)return;const c=this.requestId;this.isLoading=!0;try{const u=new URL(this.apiUrl),g=(null!==(t=this.lastQuery)&&void 0!==t?t:"").trim().toLowerCase(),v=new URLSearchParams(null!==(e=this.apiQuery)&&void 0!==e?e:""),m=null!==(i=this.apiSearchQueryKey)&&void 0!==i?i:"q";""!==g&&v.set(m,g),u.search=v.toString();const f=(null===(s=this.apiFieldsMap)||void 0===s?void 0:s.page)||(null===(o=this.apiFieldsMap)||void 0===o?void 0:o.offset)||"page",w=!!(null===(n=this.apiFieldsMap)||void 0===n?void 0:n.offset),y="object"==typeof this.apiLoadMore?this.apiLoadMore.perPage:10,S=this.currentPage+1;if(w){const t=this.currentPage*y;u.searchParams.set(f,String(t))}else u.searchParams.set(f,String(S));if(u.searchParams.set((null===(l=this.apiFieldsMap)||void 0===l?void 0:l.limit)||"limit",String(y)),this.loadMoreAbortController)try{this.loadMoreAbortController.abort()}catch(t){}this.loadMoreAbortController=new AbortController;const b=Object.assign(Object.assign({},this.apiOptions||{}),{signal:this.loadMoreAbortController.signal}),I=yield fetch(u.toString(),b),T=yield I.json();if(c!==this.requestId)return void(this.isLoading=!1);const C=this.apiDataPart?null!==(r=null!==(a=T[this.apiDataPart])&&void 0!==a?a:T.results)&&void 0!==r?r:T:null!==(d=T.results)&&void 0!==d?d:T,E=(t,e)=>e.split(".").reduce((t,e)=>t?t[e]:void 0,t);let A=null;if(this.apiTotalPath){const t=E(T,this.apiTotalPath);A="number"==typeof t?t:null}else A=null!==(p=null!==(h="number"==typeof T.count?T.count:null)&&void 0!==h?h:"number"==typeof T.total?T.total:null)&&void 0!==p?p:T.info&&"number"==typeof T.info.count?T.info.count:null;if(C&&C.length>0){if(this.remoteOptions=[...this.remoteOptions||[],...C],this.buildOptionsFromRemoteData(C),"number"==typeof A){const t=S*y;this.hasMore=t<A}else this.hasMore=C.length===y;this.currentPage=S}else this.hasMore=!1}catch(t){this.hasMore=!1,console.error("Error loading more options:",t)}finally{this.isLoading=!1}})}buildFloatingUI(){if("undefined"!=typeof FloatingUIDOM&&FloatingUIDOM.computePosition){document.body.appendChild(this.dropdown);const t="tags"===this.mode?this.wrapper:this.toggle,e=[FloatingUIDOM.offset([0,5])];this.dropdownAutoPlacement&&"function"==typeof FloatingUIDOM.flip&&e.push(FloatingUIDOM.flip({fallbackPlacements:["bottom-start","bottom-end","top-start","top-end"]}));const i={placement:r.POSITIONS[this.dropdownPlacement]||"bottom",strategy:"fixed",middleware:e},s=()=>{Object.assign(this.dropdown.style,{marginLeft:"",marginTop:"",marginRight:"",marginBottom:""}),FloatingUIDOM.computePosition(t,this.dropdown,i).then(({x:t,y:e,placement:i})=>{Object.assign(this.dropdown.style,{position:"fixed",left:`${t}px`,top:`${e}px`,["margin"+(i.startsWith("bottom")||i.startsWith("top")?"Top":i.startsWith("right")?"Left":"Right")]:`${i.startsWith("top")?"-":""}${this.dropdownSpace}px`}),this.dropdown.setAttribute("data-placement",i)})};s();const o=FloatingUIDOM.autoUpdate(t,this.dropdown,s);this.floatingUIInstance={update:s,destroy:o}}else console.error("FloatingUIDOM not found! Please enable it on the page.")}updateDropdownWidth(){const t="tags"===this.mode?this.wrapper:this.toggle;this.dropdown.style.width=`${t.clientWidth}px`}buildSearch(){var t,e,i;if(!this.hasSearch)return;if("tags"===this.mode){const s=null!==(i=null!==(t=this.tagsInput)&&void 0!==t?t:null===(e=this.wrapper)||void 0===e?void 0:e.querySelector(":scope input"))&&void 0!==i?i:this.el.querySelector(":scope input");return s?(this.search=s,this.searchPlaceholder&&(this.search.placeholder=this.searchPlaceholder),this.searchId&&(this.search.id=this.searchId),this.searchClasses&&(0,n.classToClassList)(this.searchClasses,this.search),void(this.apiUrl&&(this.onSearchInputListener=(0,n.debounce)(t=>this.searchInput(t)),this.search.addEventListener("input",this.onSearchInputListener)))):void 0}let s;this.searchWrapper=(0,n.htmlToElement)(this.searchWrapperTemplate||"<div></div>"),this.searchWrapperClasses&&(0,n.classToClassList)(this.searchWrapperClasses,this.searchWrapper),s=this.searchWrapper.querySelector("[data-input]");const o=(0,n.htmlToElement)(this.searchTemplate||'<input type="text">');this.search="INPUT"===o.tagName?o:o.querySelector(":scope input"),this.search.placeholder=this.searchPlaceholder,this.searchClasses&&(0,n.classToClassList)(this.searchClasses,this.search),this.searchId&&(this.search.id=this.searchId),this.onSearchInputListener=(0,n.debounce)(t=>this.searchInput(t)),this.search.addEventListener("input",this.onSearchInputListener),s?s.append(o):this.searchWrapper.append(o),this.dropdown.append(this.searchWrapper)}buildOption(t,e,i=!1,s=!1,o,l="1",a,r=!1){var d,h,p,c,u;let g=null,v=null,m=null,f=null;const w=(0,n.htmlToElement)(this.optionTag||"<div></div>");if(w.setAttribute("data-value",e),w.setAttribute("data-title-value",t),w.setAttribute("tabIndex",l),w.classList.add("cursor-pointer"),w.setAttribute("data-id",a||`${this.optionId}`),r&&w.setAttribute("data-static","true"),a||this.optionId++,i&&w.classList.add("disabled"),s&&(this.isMultiple?this.value=[...this.value,e]:this.value=e),this.optionTemplate&&(g=(0,n.htmlToElement)(this.optionTemplate),w.append(g)),g?(v=g.querySelector("[data-title]"),v.textContent=t||""):w.textContent=t||"",o){const e=null!==(h=null===(d=o.apiFields)||void 0===d?void 0:d.icon)&&void 0!==h?h:o.icon,i=null!==(c=null===(p=o.apiFields)||void 0===p?void 0:p.description)&&void 0!==c?c:o.description;if(e){const i=(0,n.htmlToElement)(null!==(u=this.apiIconTag)&&void 0!==u?u:e);if(i.classList.add("max-w-full"),(this.apiUrl||o.apiFields)&&(i.setAttribute("alt",t),i.setAttribute("src",e)),g)m=g.querySelector("[data-icon]"),m.append(i);else{const t=(0,n.htmlToElement)("<div></div>");this.iconClasses&&(0,n.classToClassList)(this.iconClasses,t),t.append(i),w.append(t)}}if(Array.isArray(o.additionalClasses)&&o.additionalClasses.forEach(([t,e])=>{const i=t?w.querySelector(t):w;i&&e.forEach(t=>i.classList.add(t))}),i)if(w.dataset.description=i,g)f=g.querySelector("[data-description]"),f&&f.append(i);else{const t=(0,n.htmlToElement)("<div></div>");t.textContent=i,this.descriptionClasses&&(0,n.classToClassList)(this.descriptionClasses,t),w.append(t)}}g&&g.querySelector("[data-icon]")&&!o&&!(null==o?void 0:o.icon)&&g.querySelector("[data-icon]").classList.add("hidden"),this.value&&(this.isMultiple?this.value.includes(e):this.value===e)&&w.classList.add("selected"),i||w.addEventListener("click",()=>this.onSelectOption(e)),this.optionClasses&&(0,n.classToClassList)(this.optionClasses,w),this.dropdown&&this.dropdown.append(w),s&&this.setNewValue()}buildOptionFromRemoteData(t,e,i=!1,s=!1,o="1",n,l){o?this.buildOption(t,e,i,s,l,o,n):alert("ID parameter is required for generating remote options! Please check your API endpoint have it.")}buildOptionsFromRemoteData(t){t.forEach((t,e)=>{let i=null,s="",o="";const n={id:"",val:"",title:"",icon:null,description:null,rest:{}};Object.keys(t).forEach(e=>{var l;t[this.apiFieldsMap.id]&&(i=t[this.apiFieldsMap.id],n.id=`${i}`),t[this.apiFieldsMap.val]&&(o=`${t[this.apiFieldsMap.val]}`,n.val=o),t[this.apiFieldsMap.title]&&(s=t[this.apiFieldsMap.title],n.title=s,t[this.apiFieldsMap.val]||(o=s,n.val=o)),t[this.apiFieldsMap.icon]&&(n.icon=t[this.apiFieldsMap.icon]),t[null===(l=this.apiFieldsMap)||void 0===l?void 0:l.description]&&(n.description=t[this.apiFieldsMap.description]),n.rest[e]=t[e]});const l=this.staticOptions.findIndex(t=>t.val===o);if(-1!==l)return void this.mergeRemoteDataIntoStaticOption(l,o,n,e);if(!this.dropdown.querySelector(`[data-value="${o}"]`)){const t=!!this.apiSelectedValues&&(Array.isArray(this.apiSelectedValues)?this.apiSelectedValues.includes(o):this.apiSelectedValues===o);this.buildOriginalOption(s,o,i,!1,t,n),this.buildOptionFromRemoteData(s,o,!1,t,`${e}`,i,n),t&&(this.isMultiple?(this.value||(this.value=[]),Array.isArray(this.value)&&(this.value=[...this.value,o])):this.value=o,this.toggle&&(this.toggle.querySelector("[data-title]")&&this.setToggleTitle(),this.toggle.querySelector("[data-icon]")&&this.setToggleIcon()))}}),this.sortElements(this.el,"option"),this.sortElements(this.dropdown,"[data-value]")}mergeRemoteDataIntoStaticOption(t,e,i,s){const o=this.staticOptions[t];o.options||(o.options={}),o.options.apiFields||(o.options.apiFields={}),i.title&&(o.title=i.title),i.icon&&(o.options.apiFields.icon=i.icon),i.description&&(o.options.apiFields.description=i.description),Object.keys(i.rest).forEach(t=>{o.options.apiFields[t]=i.rest[t]});const l=this.dropdown.querySelector(`[data-value="${e}"][data-static]`);if(l){if(l.setAttribute("tabIndex",`${s}`),i.id&&l.setAttribute("data-id",`${i.id}`),i.title){l.setAttribute("data-title-value",i.title);const t=l.querySelector("[data-title]");t&&(t.textContent=i.title)}if(i.icon){const t=l.querySelector("[data-icon]");if(t){t.innerHTML="";const e=(0,n.htmlToElement)(this.apiIconTag||"<img />");e.classList.add("max-w-full"),e.setAttribute("alt",o.title),e.setAttribute("src",i.icon),t.append(e)}}if(i.description){l.dataset.description=i.description;const t=l.querySelector("[data-description]");t&&(t.textContent=i.description)}}const a=this.el.querySelector(`option[value="${e}"][data-static]`);if(a){i.id&&a.setAttribute("data-id",`${i.id}`),i.title&&(a.textContent=i.title);const t={id:i.id||"",val:i.val||"",title:i.title||"",icon:i.icon||null,description:i.description||null,rest:i.rest};a.setAttribute("data-hs-select-option",JSON.stringify(t))}const r=this.selectOptions.findIndex(t=>t.val===e);-1!==r&&(this.selectOptions[r]=o);(this.isMultiple?Array.isArray(this.value)&&this.value.includes(e):this.value===e)&&this.toggle&&(i.title&&(this.toggle.querySelector("[data-title]")?this.setToggleTitle():this.toggleTextWrapper&&(this.isMultiple?this.toggleTextWrapper.innerHTML=this.stringFromValue():this.toggleTextWrapper.innerHTML=i.title)),i.icon&&this.toggle.querySelector("[data-icon]")&&this.setToggleIcon())}optionsFromRemoteData(){return s(this,arguments,void 0,function*(t=""){const e=(yield this.apiRequest(t))||[];this.remoteOptions=e,e.length?this.buildOptionsFromRemoteData(this.remoteOptions):console.log("There is no data were responded!")})}apiRequest(){return s(this,arguments,void 0,function*(t="",e){var i,s,o,n,l,a,r,d,h,p;try{const c=new URL(this.apiUrl),u=new URLSearchParams(null!==(i=this.apiQuery)&&void 0!==i?i:""),g=null!==(s=this.apiOptions)&&void 0!==s?s:{},v=Object.assign({},g);e&&(v.signal=e);const m=null!==(o=this.apiSearchQueryKey)&&void 0!==o?o:"q",f=(null!=t?t:"").trim().toLowerCase();if(""!==f&&u.set(m,f),this.apiLoadMore){const t="object"==typeof this.apiLoadMore?this.apiLoadMore.perPage:10,e=null!==(r=null!==(l=null===(n=this.apiFieldsMap)||void 0===n?void 0:n.page)&&void 0!==l?l:null===(a=this.apiFieldsMap)||void 0===a?void 0:a.offset)&&void 0!==r?r:"page",i=null!==(h=null===(d=this.apiFieldsMap)||void 0===d?void 0:d.limit)&&void 0!==h?h:"limit",s=Boolean(null===(p=this.apiFieldsMap)||void 0===p?void 0:p.offset)?0:1,o="number"==typeof this.apiPageStart?this.apiPageStart:s;u.delete(e),u.delete(i),u.set(e,String(o)),u.set(i,String(t))}c.search=u.toString();const w=yield fetch(c.toString(),v),y=yield w.json();return this.apiDataPart?y[this.apiDataPart]:y}catch(t){console.error(t)}})}sortElements(t,e){if(this.hasOptgroup)return;const i=Array.from(t.querySelectorAll(e));this.isSelectedOptionOnTop&&i.sort((t,e)=>{const i=t.classList.contains("selected")||t.hasAttribute("selected"),s=e.classList.contains("selected")||e.hasAttribute("selected");return i&&!s?-1:!i&&s?1:0}),i.forEach((e,i)=>{t.appendChild(e),e.hasAttribute("tabindex")&&e.setAttribute("tabIndex",`${i}`)})}remoteSearch(t){return s(this,void 0,void 0,function*(){var e,i,s,o;if(this.requestId++,this.remoteSearchAbortController)try{this.remoteSearchAbortController.abort()}catch(t){}if(this.loadMoreAbortController)try{this.loadMoreAbortController.abort()}catch(t){}if(this.remoteSearchAbortController=new AbortController,this.currentPage=0,this.hasMore=!0,this.isLoading=!1,this.filterStaticOptions(t),t.length<=this.minSearchLength){const t=yield this.apiRequest("",null===(e=this.remoteSearchAbortController)||void 0===e?void 0:e.signal);if(!t)return!1;const s=Boolean(null===(i=this.apiFieldsMap)||void 0===i?void 0:i.offset)?0:1,o="number"==typeof this.apiPageStart?this.apiPageStart:s;this.currentPage=o;const n=Array.isArray(this.value)?this.value:this.value?[this.value]:[],l=this.remoteOptions.filter(t=>{var e;return n.includes(`${t[null===(e=this.apiFieldsMap)||void 0===e?void 0:e.val]}`)}),a=new Set(t.map(t=>{var e;return`${t[null===(e=this.apiFieldsMap)||void 0===e?void 0:e.val]}`}));return this.remoteOptions=[...t,...l.filter(t=>{var e;return!a.has(`${t[null===(e=this.apiFieldsMap)||void 0===e?void 0:e.val]}`)})],Array.from(this.dropdown.querySelectorAll("[data-value]:not([data-static])")).forEach(t=>{n.includes(t.getAttribute("data-value"))||t.remove()}),Array.from(this.el.querySelectorAll("option[value][data-hs-select-option]:not([data-static])")).forEach(t=>{n.includes(t.value)||t.remove()}),t.length?this.buildOptionsFromRemoteData(t):console.log("No data responded!"),!1}const n=yield this.apiRequest(t,null===(s=this.remoteSearchAbortController)||void 0===s?void 0:s.signal);if(!n)return;const l=Boolean(null===(o=this.apiFieldsMap)||void 0===o?void 0:o.offset)?0:1,a="number"==typeof this.apiPageStart?this.apiPageStart:l;this.currentPage=a;const r=Array.isArray(this.value)?this.value:this.value?[this.value]:[],d=this.remoteOptions.filter(t=>{var e;return r.includes(`${t[null===(e=this.apiFieldsMap)||void 0===e?void 0:e.val]}`)}),h=new Set(n.map(t=>{var e;return`${t[null===(e=this.apiFieldsMap)||void 0===e?void 0:e.val]}`}));this.remoteOptions=[...n,...d.filter(t=>{var e;return!h.has(`${t[null===(e=this.apiFieldsMap)||void 0===e?void 0:e.val]}`)})];let p=n.map(t=>`${t.id}`),c=null;const u=this.dropdown.querySelectorAll("[data-value]:not([data-static])");this.el.querySelectorAll("[data-hs-select-option]:not([data-static])").forEach(t=>{var e;const i=t.getAttribute("data-id");p.includes(i)||(null===(e=this.value)||void 0===e?void 0:e.includes(t.value))||this.destroyOriginalOption(t.value)}),u.forEach(t=>{var e;const i=t.getAttribute("data-id");p.includes(i)||(null===(e=this.value)||void 0===e?void 0:e.includes(t.getAttribute("data-value")))?p=p.filter(t=>t!==i):this.destroyOption(t.getAttribute("data-value"))}),c=n.filter(t=>p.includes(`${t.id}`)),c.length?this.buildOptionsFromRemoteData(c):console.log("No data responded!")})}filterStaticOptions(t){const e=this.dropdown.querySelectorAll("[data-value][data-static]"),i=t.trim().toLowerCase();e.forEach(t=>{var e,s;if(i.length<=this.minSearchLength)t.classList.remove("hidden");else{const o=(null===(e=t.getAttribute("data-title-value"))||void 0===e?void 0:e.toLowerCase())||"",n=(null===(s=t.dataset.description)||void 0===s?void 0:s.toLowerCase())||"";this.optionMatchesQuery(i,o,n)?t.classList.remove("hidden"):t.classList.add("hidden")}})}normalizeSearchText(t=""){return t.toLocaleLowerCase().replace(/\s+/g," ").trim()}tokenizeSearchQuery(t){return this.normalizeSearchText(t).split(" ").filter(Boolean)}charsSequenceMatch(t,e){const i=t.split("").map(t=>/\w/.test(t)?`${t}[\\W_]*`:"\\W*").join("");return new RegExp(i,"i").test(e)}optionMatchesQuery(t,e,i=""){const s=this.normalizeSearchText(t);if(!s)return!0;const o=this.normalizeSearchText(e),n=this.normalizeSearchText(i),l=this.preventSearchInsideDescription?[o]:[o,n];if("token-all"===this.searchMatchMode){const t=this.tokenizeSearchQuery(s);return l.some(e=>t.every(t=>e.includes(t)))}if("hybrid"===this.searchMatchMode){const t=this.tokenizeSearchQuery(s);return l.some(e=>{const i=t.every(t=>e.includes(t)),o=this.charsSequenceMatch(s,e);return i||o})}return"chars-sequence"===this.searchMatchMode?l.some(t=>this.charsSequenceMatch(s,t)):l.some(t=>t.includes(s))}destroyOption(t){const e=this.dropdown.querySelector(`[data-value="${t}"]`);if(!e)return!1;e.remove()}buildOriginalOption(t,e,i,s,o,l){const a=(0,n.htmlToElement)("<option></option>");a.setAttribute("value",e),s&&a.setAttribute("disabled","disabled"),o&&a.setAttribute("selected","selected"),i&&a.setAttribute("data-id",i),a.setAttribute("data-hs-select-option",JSON.stringify(l)),a.innerText=t,this.el.append(a)}destroyOriginalOption(t){const e=this.el.querySelector(`[value="${t}"]`);if(!e)return!1;e.remove()}buildTagsInputHelper(){this.tagsInputHelper=document.createElement("span"),this.tagsInputHelper.style.fontSize=window.getComputedStyle(this.tagsInput).fontSize,this.tagsInputHelper.style.fontFamily=window.getComputedStyle(this.tagsInput).fontFamily,this.tagsInputHelper.style.fontWeight=window.getComputedStyle(this.tagsInput).fontWeight,this.tagsInputHelper.style.letterSpacing=window.getComputedStyle(this.tagsInput).letterSpacing,this.tagsInputHelper.style.visibility="hidden",this.tagsInputHelper.style.whiteSpace="pre",this.tagsInputHelper.style.position="absolute",this.wrapper.appendChild(this.tagsInputHelper)}calculateInputWidth(){this.tagsInputHelper.textContent=this.tagsInput.value||this.tagsInput.placeholder;const t=parseInt(window.getComputedStyle(this.tagsInput).paddingLeft)+parseInt(window.getComputedStyle(this.tagsInput).paddingRight),e=parseInt(window.getComputedStyle(this.tagsInput).borderLeftWidth)+parseInt(window.getComputedStyle(this.tagsInput).borderRightWidth),i=this.tagsInputHelper.offsetWidth+t+e,s=this.wrapper.offsetWidth-(parseInt(window.getComputedStyle(this.wrapper).paddingLeft)+parseInt(window.getComputedStyle(this.wrapper).paddingRight));this.tagsInput.style.width=`${Math.min(i,s)+2}px`}adjustInputWidth(){this.buildTagsInputHelper(),this.calculateInputWidth()}onSelectOption(t){if(this.clearSelections(),this.isMultiple?(Array.isArray(this.value)||(this.value=[]),this.value=this.value.includes(t)?this.value.filter(e=>e!==t):[...this.value,t],this.selectMultipleItems(),this.setNewValue()):(this.value=t,this.selectSingleItem(),this.setNewValue()),this.fireEvent("change",this.value),"tags"===this.mode){const t=this.selectedItems.filter(t=>!this.value.includes(t));t.length&&t.forEach(t=>{this.selectedItems=this.selectedItems.filter(e=>e!==t),this.wrapper.querySelector(`[data-tag-value="${t}"]`).remove()}),this.resetTagsInputField()}this.isMultiple||(this.toggle.querySelector("[data-icon]")&&this.setToggleIcon(),this.toggle.querySelector("[data-title]")&&this.setToggleTitle(),this.close(!0)),this.hasValue()||"tags"!==this.mode||this.reassignTagsInputPlaceholder(this.placeholder),this._isOpened&&"tags"===this.mode&&this.tagsInput&&this.tagsInput.focus(),this.triggerChangeEventForNativeSelect()}triggerChangeEventForNativeSelect(){const t=new Event("change",{bubbles:!0});this.el.dispatchEvent(t),(0,n.dispatch)("change.hs.select",this.el,this.value)}addSelectOption(t,e,i,s,o){this.selectOptions=[...this.selectOptions,{title:t,val:e,disabled:i,selected:s,options:o}]}removeSelectOption(t,e=!1){if(!!!this.selectOptions.some(e=>e.val===t))return!1;this.selectOptions=this.selectOptions.filter(e=>e.val!==t),this.value=e?this.value.filter(e=>e!==t):t}resetTagsInputField(){this.tagsInput.value="",this.reassignTagsInputPlaceholder(""),this.searchOptions("")}clearSelections(){const t=this.el.querySelectorAll("option");Array.from(this.dropdown.children).forEach(t=>{t.classList.contains("selected")&&t.classList.remove("selected")}),Array.from(t).forEach(t=>{t.selected&&(t.selected=!1)})}setNewValue(){if("tags"===this.mode)this.setTagsItems();else if(this.optionAllowEmptyOption&&""===this.value){const t=this.selectOptions.find(t=>""===t.val);this.toggleTextWrapper.innerHTML=(null==t?void 0:t.title)||this.placeholder}else if(this.hasValue())if(this.apiUrl){const t=this.dropdown.querySelector(`[data-value="${this.value}"]`);if(t)this.toggleTextWrapper.innerHTML=t.getAttribute("data-title-value")||this.placeholder;else{const t=this.staticOptions.find(t=>t.val===this.value);if(t)this.toggleTextWrapper.innerHTML=t.title;else{const t=this.remoteOptions.find(t=>(t[this.apiFieldsMap.val]?`${t[this.apiFieldsMap.val]}`:t[this.apiFieldsMap.title])===this.value);this.toggleTextWrapper.innerHTML=t?`${t[this.apiFieldsMap.title]}`:this.stringFromValue()}}}else this.toggleTextWrapper.innerHTML=this.stringFromValue();else this.toggleTextWrapper.innerHTML=this.placeholder}stringFromValueBasic(t){var e;const i=[];let s="";if(t.forEach(t=>{this.isMultiple?Array.isArray(this.value)&&this.value.includes(t.val)&&i.push(t.title):this.value===t.val&&i.push(t.title)}),void 0!==this.toggleCountText&&null!==this.toggleCountText&&i.length>=this.toggleCountTextMinItems)if("nItemsAndCount"===this.toggleCountTextMode){const t=i.slice(0,this.toggleCountTextMinItems-1),o=[t.join(this.toggleSeparators.items)],n=""+(i.length-t.length);if((null===(e=null==this?void 0:this.toggleSeparators)||void 0===e?void 0:e.betweenItemsAndCounter)&&o.push(this.toggleSeparators.betweenItemsAndCounter),this.toggleCountText)switch(this.toggleCountTextPlacement){case"postfix-no-space":o.push(`${n}${this.toggleCountText}`);break;case"prefix-no-space":o.push(`${this.toggleCountText}${n}`);break;case"prefix":o.push(`${this.toggleCountText} ${n}`);break;default:o.push(`${n} ${this.toggleCountText}`)}s=o.join(" ")}else s=`${i.length} ${this.toggleCountText}`;else s=i.join(this.toggleSeparators.items);return s}stringFromValueRemoteData(){if(!this.dropdown)return this.stringFromValueBasic(this.selectOptions);const t=this.dropdown.querySelectorAll("[data-title-value]"),e=[];let i="";if(t.forEach(t=>{const i=t.getAttribute("data-value"),s=t.getAttribute("data-title-value");this.isMultiple?Array.isArray(this.value)&&this.value.includes(i)&&e.push(s):this.value===i&&e.push(s)}),this.toggleCountText&&""!==this.toggleCountText&&e.length>=this.toggleCountTextMinItems)if("nItemsAndCount"===this.toggleCountTextMode){const t=e.slice(0,this.toggleCountTextMinItems-1);i=`${t.join(this.toggleSeparators.items)} ${this.toggleSeparators.betweenItemsAndCounter} ${e.length-t.length} ${this.toggleCountText}`}else i=`${e.length} ${this.toggleCountText}`;else i=e.join(this.toggleSeparators.items);return i}stringFromValue(){return this.apiUrl?this.stringFromValueRemoteData():this.stringFromValueBasic(this.selectOptions)}selectSingleItem(){const t=this.el.querySelectorAll("option");Array.from(t).find(t=>this.value===t.value).selected=!0;const e=Array.from(this.dropdown.children).find(t=>this.value===t.getAttribute("data-value"));e&&e.classList.add("selected"),this.sortElements(this.el,"option"),this.sortElements(this.dropdown,"[data-value]")}selectMultipleItems(){if(!Array.isArray(this.value))return;const t=this.el.querySelectorAll("option");Array.from(this.dropdown.children).filter(t=>this.value.includes(t.getAttribute("data-value"))).forEach(t=>t.classList.add("selected")),Array.from(t).filter(t=>this.value.includes(t.value)).forEach(t=>t.selected=!0),this.sortElements(this.el,"option"),this.sortElements(this.dropdown,"[data-value]")}unselectMultipleItems(){const t=this.el.querySelectorAll("option");Array.from(this.dropdown.children).forEach(t=>t.classList.remove("selected")),Array.from(t).forEach(t=>t.selected=!1),this.sortElements(this.el,"option"),this.sortElements(this.dropdown,"[data-value]")}searchOptions(t){if(t.length<=this.minSearchLength){this.searchNoResult&&(this.searchNoResult.remove(),this.searchNoResult=null);return this.dropdown.querySelectorAll("[data-value]").forEach(t=>{t.classList.remove("hidden")}),!1}this.searchNoResult&&(this.searchNoResult.remove(),this.searchNoResult=null),this.searchNoResult=(0,n.htmlToElement)(this.searchNoResultTemplate),this.searchNoResult.innerText=this.searchNoResultText,(0,n.classToClassList)(this.searchNoResultClasses,this.searchNoResult);const e=this.dropdown.querySelectorAll("[data-value]");let i,s=!1;this.searchLimit&&(i=0),e.forEach(e=>{var o;const n=e.getAttribute("data-title-value")||"",l=(null===(o=null==e?void 0:e.dataset)||void 0===o?void 0:o.description)||"";!this.optionMatchesQuery(t,n,l)||this.searchLimit&&i>=this.searchLimit?e.classList.add("hidden"):(e.classList.remove("hidden"),s=!0,this.searchLimit&&i++)}),s||this.dropdown.append(this.searchNoResult)}eraseToggleIcon(){const t=this.toggle.querySelector("[data-icon]");t&&(t.innerHTML=null,t.classList.add("hidden"))}eraseToggleTitle(){const t=this.toggle.querySelector("[data-title]");t?t.innerHTML=this.placeholder:this.toggleTextWrapper.innerHTML=this.placeholder}toggleFn(){this._isOpened?this.close():this.open()}setupAccessibility(){this.accessibilityComponent=window.HSAccessibilityObserver.registerComponent(this.wrapper,{onEnter:()=>{if(this._isOpened){const t=this.dropdown.querySelector(".hs-select-option-highlighted");t&&(this.onSelectOption(t.getAttribute("data-value")||""),this._isOpened&&t.focus())}else this.open()},onSpace:()=>{if(this._isOpened){const t=this.dropdown.querySelector(".hs-select-option-highlighted");t&&(this.onSelectOption(t.getAttribute("data-value")||""),this._isOpened&&t.focus())}else this.open()},onEsc:()=>{this._isOpened&&this.close(!0)},onArrow:t=>{if(!t.metaKey)if(this._isOpened||"ArrowDown"!==t.key){if(this._isOpened)switch(t.key){case"ArrowDown":this.focusMenuItem("next");break;case"ArrowUp":this.focusMenuItem("prev");break;case"Home":this.onStartEnd(!0);break;case"End":this.onStartEnd(!1)}}else this.open()},onHome:()=>{this._isOpened&&this.onStartEnd(!0)},onEnd:()=>{this._isOpened&&this.onStartEnd(!1)},onTab:()=>{this._isOpened&&this.close()}},this._isOpened,"Select",".hs-select",this.dropdown)}focusMenuItem(t){const e=Array.from(this.dropdown.querySelectorAll(":scope > *:not(.hidden)")).filter(t=>!t.classList.contains("disabled")&&!t.hasAttribute("data-optgroup"));if(!e.length)return;const i=this.dropdown.querySelector(".hs-select-option-highlighted"),s=i?e.indexOf(i):-1,o="next"===t?(s+1)%e.length:(s-1+e.length)%e.length;i&&i.classList.remove("hs-select-option-highlighted"),e[o].classList.add("hs-select-option-highlighted"),e[o].focus()}onStartEnd(t=!0){if(!this.dropdown)return;const e=Array.from(this.dropdown.querySelectorAll(":scope > *:not(.hidden)")).filter(t=>!t.classList.contains("disabled"));if(!e.length)return;const i=this.dropdown.querySelector(".hs-select-option-highlighted");i&&i.classList.remove("hs-select-option-highlighted");const s=t?0:e.length-1;e[s].classList.add("hs-select-option-highlighted"),e[s].focus()}destroy(){var t;this.wrapper&&this.wrapper.removeEventListener("click",this.onWrapperClickListener),this.toggle&&this.toggle.removeEventListener("click",this.onToggleClickListener),this.tagsInput&&(this.tagsInput.removeEventListener("focus",this.onTagsInputFocusListener),this.tagsInput.removeEventListener("input",this.onTagsInputInputListener),this.tagsInput.removeEventListener("input",this.onTagsInputInputSecondListener),this.tagsInput.removeEventListener("keydown",this.onTagsInputKeydownListener)),this.search&&this.search.removeEventListener("input",this.onSearchInputListener);const e=this.el.parentElement.parentElement;this.el.classList.add("hidden"),this.el.style.display="",e.prepend(this.el),e.querySelector(".hs-select").remove(),this.wrapper=null,null===(t=this.disabledObserver)||void 0===t||t.disconnect(),this.disabledObserver=null,window.$hsSelectCollection=window.$hsSelectCollection.filter(({element:t})=>t.el!==this.el)}open(){var t;const e=(null===(t=null===window||void 0===window?void 0:window.$hsSelectCollection)||void 0===t?void 0:t.find(t=>t.element.isOpened()))||null;if(e&&e.element.close(),this.animationInProcess)return!1;this.animationInProcess=!0,"window"===this.dropdownScope&&this.dropdown.classList.add("invisible"),this.dropdown.classList.remove("hidden"),"window"!==this.dropdownScope&&this.recalculateDirection(),setTimeout(()=>{var t;if((null===(t=null==this?void 0:this.toggle)||void 0===t?void 0:t.ariaExpanded)&&(this.toggle.ariaExpanded="true"),this.wrapper.classList.add("active"),this.dropdown.classList.add("opened"),this.dropdown.classList.contains("w-full")&&"window"===this.dropdownScope&&this.updateDropdownWidth(),this.floatingUIInstance&&"window"===this.dropdownScope&&(this.floatingUIInstance.update(),this.dropdown.classList.remove("invisible")),this.hasSearch&&!this.preventSearchFocus&&this.search.focus(),this.animationInProcess=!1,this.scrollToSelected&&this.dropdown){const t=this.dropdown.querySelector(".selected");if(t){const e=this.dropdown.clientHeight,i=t.offsetTop-e/2+t.clientHeight/2;this.dropdown.scrollTop=i}}}),this._isOpened=!0,window.HSAccessibilityObserver&&this.accessibilityComponent&&window.HSAccessibilityObserver.updateComponentState(this.accessibilityComponent,this._isOpened)}close(t=!1){var e,i,s,o;if(this.animationInProcess)return!1;this.animationInProcess=!0,(null===(e=null==this?void 0:this.toggle)||void 0===e?void 0:e.ariaExpanded)&&(this.toggle.ariaExpanded="false"),this.wrapper.classList.remove("active"),this.dropdown.classList.remove("opened","bottom-full","top-full"),(null===(i=this.dropdownDirectionClasses)||void 0===i?void 0:i.bottom)&&this.dropdown.classList.remove(this.dropdownDirectionClasses.bottom),(null===(s=this.dropdownDirectionClasses)||void 0===s?void 0:s.top)&&this.dropdown.classList.remove(this.dropdownDirectionClasses.top),this.dropdown.style.marginTop="",this.dropdown.style.marginBottom="",(0,n.afterTransition)(this.dropdown,()=>{var e;this.dropdown.classList.add("hidden"),this.hasSearch&&"tags"!==this.mode&&(this.search.value="",this.apiUrl?this.filterStaticOptions(""):this.search.dispatchEvent(new Event("input",{bubbles:!0})),this.search.blur()),t&&((null===(e=this.mode)||void 0===e?void 0:e.includes("tags"))?this.wrapper.focus():this.toggle.focus()),this.animationInProcess=!1}),null===(o=this.dropdown.querySelector(".hs-select-option-highlighted"))||void 0===o||o.classList.remove("hs-select-option-highlighted"),this._isOpened=!1,window.HSAccessibilityObserver&&this.accessibilityComponent&&window.HSAccessibilityObserver.updateComponentState(this.accessibilityComponent,this._isOpened)}addOption(t){let e=`${this.selectOptions.length}`;const i=t=>{const{title:i,val:s,disabled:o,selected:n,options:l}=t;!!this.selectOptions.some(t=>t.val===s)||(this.addSelectOption(i,s,o,n,l),this.buildOption(i,s,o,n,l,e),this.buildOriginalOption(i,s,null,o,n,l),n&&!this.isMultiple&&this.onSelectOption(s))};Array.isArray(t)?t.forEach(t=>{i(t)}):i(t),this.sortElements(this.el,"option"),this.sortElements(this.dropdown,"[data-value]")}removeOption(t){const e=(t,e=!1)=>{!!this.selectOptions.some(e=>e.val===t)&&(this.removeSelectOption(t,e),this.destroyOption(t),this.destroyOriginalOption(t),this.value===t&&(this.value=null,this.eraseToggleTitle(),this.eraseToggleIcon()))};Array.isArray(t)?t.forEach(t=>{e(t,this.isMultiple)}):e(t,this.isMultiple),this.setNewValue(),this.sortElements(this.el,"option"),this.sortElements(this.dropdown,"[data-value]")}recalculateDirection(){var t,e,i,s;if((null==this?void 0:this.dropdownVerticalFixedPlacement)&&(this.dropdown.classList.contains("bottom-full")||this.dropdown.classList.contains("top-full")))return!1;"top"===(null==this?void 0:this.dropdownVerticalFixedPlacement)?(this.dropdown.classList.add("bottom-full"),this.dropdown.style.marginBottom=`${this.dropdownSpace}px`):"bottom"===(null==this?void 0:this.dropdownVerticalFixedPlacement)?(this.dropdown.classList.add("top-full"),this.dropdown.style.marginTop=`${this.dropdownSpace}px`):(0,n.isEnoughSpace)(this.dropdown,this.toggle||this.tagsInput,"bottom",this.dropdownSpace,this.viewport)?(this.dropdown.classList.remove("bottom-full"),(null===(t=this.dropdownDirectionClasses)||void 0===t?void 0:t.bottom)&&this.dropdown.classList.remove(this.dropdownDirectionClasses.bottom),this.dropdown.style.marginBottom="",this.dropdown.classList.add("top-full"),(null===(e=this.dropdownDirectionClasses)||void 0===e?void 0:e.top)&&this.dropdown.classList.add(this.dropdownDirectionClasses.top),this.dropdown.style.marginTop=`${this.dropdownSpace}px`):(this.dropdown.classList.remove("top-full"),(null===(i=this.dropdownDirectionClasses)||void 0===i?void 0:i.top)&&this.dropdown.classList.remove(this.dropdownDirectionClasses.top),this.dropdown.style.marginTop="",this.dropdown.classList.add("bottom-full"),(null===(s=this.dropdownDirectionClasses)||void 0===s?void 0:s.bottom)&&this.dropdown.classList.add(this.dropdownDirectionClasses.bottom),this.dropdown.style.marginBottom=`${this.dropdownSpace}px`)}isOpened(){return this._isOpened||!1}containsElement(t){var e;return(null===(e=this.wrapper)||void 0===e?void 0:e.contains(t))||!1}containsDropdownElement(t){var e;return(null===(e=this.dropdown)||void 0===e?void 0:e.contains(t))||!1}static findInCollection(t){return d.ensureGlobalHandlers(),window.$hsSelectCollection.find(e=>t instanceof d?e.element.el===t.el:"string"==typeof t?e.element.el===document.querySelector(t):e.element.el===t)||null}static getInstance(t,e){d.ensureGlobalHandlers();const i=window.$hsSelectCollection.find(e=>e.element.el===("string"==typeof t?document.querySelector(t):t));return i?e?i:i.element:null}static autoInit(){d.ensureGlobalHandlers(),window.$hsSelectCollection&&(window.$hsSelectCollection=window.$hsSelectCollection.filter(({element:t})=>document.contains(t.el))),document.querySelectorAll("[data-hs-select]:not(.--prevent-on-load-init)").forEach(t=>{if(!window.$hsSelectCollection.find(e=>{var i;return(null===(i=null==e?void 0:e.element)||void 0===i?void 0:i.el)===t})){const e=t.getAttribute("data-hs-select"),i=e?JSON.parse(e):{};new d(t,i)}})}static ensureGlobalHandlers(){"undefined"!=typeof window&&(window.$hsSelectCollection||(window.$hsSelectCollection=[]),d.globalListenersInitialized||(d.globalListenersInitialized=!0,window.addEventListener("click",t=>{const e=t.target;d.closeCurrentlyOpened(e)})))}static open(t){const e=d.findInCollection(t);e&&!e.element.isOpened()&&e.element.open()}static close(t){const e=d.findInCollection(t);e&&e.element.isOpened()&&e.element.close()}static closeCurrentlyOpened(t=null){if(!t.closest(".hs-select.active")&&!t.closest("[data-hs-select-dropdown].opened")){const t=window.$hsSelectCollection.filter(t=>t.element.isOpened())||null;t&&t.forEach(t=>{t.element.close()})}}}d.globalListenersInitialized=!1,e.default=d},292(t,e){
17
+ var s=this&&this.__awaiter||function(t,e,i,s){return new(i||(i=Promise))(function(o,l){function n(t){try{r(s.next(t))}catch(t){l(t)}}function a(t){try{r(s.throw(t))}catch(t){l(t)}}function r(t){var e;t.done?o(t.value):(e=t.value,e instanceof i?e:new i(function(t){t(e)})).then(n,a)}r((s=s.apply(t,e||[])).next())})},o=this&&this.__importDefault||function(t){return t&&t.__esModule?t:{default:t}};Object.defineProperty(e,"__esModule",{value:!0});const l=i(292),n=o(i(2961)),a=o(i(248)),r=i(8223);class d extends n.default{constructor(t,e){var i,s,o,l,n;super(t,e),this.disabledObserver=null,this.remoteSearchAbortController=null,this.loadMoreAbortController=null,this.requestId=0,this.lastQuery="",this.isLoadEventFired=!1,this.optionId=0;const a=t.getAttribute("data-hs-select"),r=a?JSON.parse(a):{},d=Object.assign(Object.assign({},r),e);this.value=(null==d?void 0:d.value)||this.el.value||null,this.placeholder=(null==d?void 0:d.placeholder)||"Select...",this.hasSearch=(null==d?void 0:d.hasSearch)||!1,this.minSearchLength=null!==(i=null==d?void 0:d.minSearchLength)&&void 0!==i?i:0,this.preventSearchFocus=(null==d?void 0:d.preventSearchFocus)||!1,this.preventSearchInsideDescription=(null==d?void 0:d.preventSearchInsideDescription)||!1,this.mode=(null==d?void 0:d.mode)||"default",this.viewport=void 0!==(null==d?void 0:d.viewport)?document.querySelector(null==d?void 0:d.viewport):null,this.scrollToSelected=void 0!==(null==d?void 0:d.scrollToSelected)&&(null==d?void 0:d.scrollToSelected),this._isOpened=Boolean(null==d?void 0:d.isOpened)||!1,this.isMultiple=this.el.hasAttribute("multiple")||!1,this.isDisabled=this.el.hasAttribute("disabled")||!1,this.selectedItems=[],this.apiUrl=(null==d?void 0:d.apiUrl)||null,this.apiQuery=(null==d?void 0:d.apiQuery)||null,this.apiOptions=(null==d?void 0:d.apiOptions)||null,this.apiSearchQueryKey=(null==d?void 0:d.apiSearchQueryKey)||null,this.apiDataPart=(null==d?void 0:d.apiDataPart)||null,this.apiLoadMore=!0===(null==d?void 0:d.apiLoadMore)?{perPage:10,scrollThreshold:100}:"object"==typeof(null==d?void 0:d.apiLoadMore)&&null!==(null==d?void 0:d.apiLoadMore)&&{perPage:d.apiLoadMore.perPage||10,scrollThreshold:d.apiLoadMore.scrollThreshold||100},this.apiPageStart="number"==typeof(null==d?void 0:d.apiPageStart)?d.apiPageStart:void 0,this.apiTotalPath="string"==typeof(null==d?void 0:d.apiTotalPath)?d.apiTotalPath:null,this.apiFieldsMap=(null==d?void 0:d.apiFieldsMap)||null,this.apiIconTag=(null==d?void 0:d.apiIconTag)||null,this.apiSelectedValues=(null==d?void 0:d.apiSelectedValues)||null,this.currentPage=0,this.isLoading=!1,this.hasMore=!0,this.wrapperClasses=(null==d?void 0:d.wrapperClasses)||null,this.toggleTag=(null==d?void 0:d.toggleTag)||null,this.toggleClasses=(null==d?void 0:d.toggleClasses)||null,this.toggleCountText=void 0===typeof(null==d?void 0:d.toggleCountText)?null:d.toggleCountText,this.toggleCountTextPlacement=(null==d?void 0:d.toggleCountTextPlacement)||"postfix",this.toggleCountTextMinItems=(null==d?void 0:d.toggleCountTextMinItems)||1,this.toggleCountTextMode=(null==d?void 0:d.toggleCountTextMode)||"countAfterLimit",this.toggleSeparators={items:(null===(s=null==d?void 0:d.toggleSeparators)||void 0===s?void 0:s.items)||", ",betweenItemsAndCounter:(null===(o=null==d?void 0:d.toggleSeparators)||void 0===o?void 0:o.betweenItemsAndCounter)||"and"},this.tagsItemTemplate=(null==d?void 0:d.tagsItemTemplate)||null,this.tagsItemClasses=(null==d?void 0:d.tagsItemClasses)||null,this.tagsInputId=(null==d?void 0:d.tagsInputId)||null,this.tagsInputClasses=(null==d?void 0:d.tagsInputClasses)||null,this.dropdownTag=(null==d?void 0:d.dropdownTag)||null,this.dropdownClasses=(null==d?void 0:d.dropdownClasses)||null,this.dropdownDirectionClasses=(null==d?void 0:d.dropdownDirectionClasses)||null,this.dropdownSpace=(null==d?void 0:d.dropdownSpace)||10,this.dropdownPlacement=(null==d?void 0:d.dropdownPlacement)||null,this.dropdownVerticalFixedPlacement=(null==d?void 0:d.dropdownVerticalFixedPlacement)||null,this.dropdownScope=(null==d?void 0:d.dropdownScope)||"parent",this.dropdownAutoPlacement=(null==d?void 0:d.dropdownAutoPlacement)||!1,this.searchTemplate=(null==d?void 0:d.searchTemplate)||null,this.searchWrapperTemplate=(null==d?void 0:d.searchWrapperTemplate)||null,this.searchWrapperClasses=(null==d?void 0:d.searchWrapperClasses)||"bg-white p-2 sticky top-0",this.searchId=(null==d?void 0:d.searchId)||null,this.searchLimit=(null==d?void 0:d.searchLimit)||1/0,this.isSearchDirectMatch=void 0===(null==d?void 0:d.isSearchDirectMatch)||d.isSearchDirectMatch,this.searchMatchMode=(null==d?void 0:d.searchMatchMode)||(this.isSearchDirectMatch?"substring":"chars-sequence"),this.searchClasses=(null==d?void 0:d.searchClasses)||"block w-[calc(100%-32px)] text-sm border-gray-200 rounded-md focus:border-blue-500 focus:ring-blue-500 dark:bg-neutral-900 dark:border-neutral-700 dark:text-neutral-400 py-2 px-3 my-2 mx-4",this.searchPlaceholder=(null==d?void 0:d.searchPlaceholder)||"Search...",this.searchNoResultTemplate=(null==d?void 0:d.searchNoResultTemplate)||"<span></span>",this.searchNoResultText=(null==d?void 0:d.searchNoResultText)||"No results found",this.searchNoResultClasses=(null==d?void 0:d.searchNoResultClasses)||"px-4 text-sm text-gray-800 dark:text-neutral-200",this.optionAllowEmptyOption=void 0!==(null==d?void 0:d.optionAllowEmptyOption)&&(null==d?void 0:d.optionAllowEmptyOption),this.optionValueAsTitle=void 0!==(null==d?void 0:d.optionValueAsTitle)&&(null==d?void 0:d.optionValueAsTitle),this.optionTemplate=(null==d?void 0:d.optionTemplate)||null,this.optionTag=(null==d?void 0:d.optionTag)||null,this.optionClasses=(null==d?void 0:d.optionClasses)||null,this.optgroupTag=(null==d?void 0:d.optgroupTag)||null,this.optgroupClasses=(null==d?void 0:d.optgroupClasses)||null,this.extraMarkup=(null==d?void 0:d.extraMarkup)||null,this.descriptionClasses=(null==d?void 0:d.descriptionClasses)||null,this.iconClasses=(null==d?void 0:d.iconClasses)||null,this.isAddTagOnEnter=null===(l=null==d?void 0:d.isAddTagOnEnter)||void 0===l||l,this.isSelectedOptionOnTop=null!==(n=null==d?void 0:d.isSelectedOptionOnTop)&&void 0!==n&&n,this.animationInProcess=!1,this.selectOptions=[],this.staticOptions=[],this.remoteOptions=[],this.tagsInputHelper=null,this.disabledObserver=new MutationObserver(t=>{t.some(t=>"disabled"===t.attributeName)&&this.setDisabledState(this.el.hasAttribute("disabled"))}),this.disabledObserver.observe(this.el,{attributes:!0,attributeFilter:["disabled"]}),this.init()}wrapperClick(t){t.target.closest("[data-hs-select-dropdown]")||t.target.closest("[data-tag-value]")||this.tagsInput.focus()}toggleClick(){if(this.isDisabled)return!1;this.toggleFn()}tagsInputFocus(){this._isOpened||this.open()}tagsInputInput(){this.calculateInputWidth()}tagsInputInputSecond(t){this.apiUrl||this.searchOptions(t.target.value)}tagsInputKeydown(t){if("Enter"===t.key&&this.isAddTagOnEnter){const e=t.target.value;if(this.selectOptions.find(t=>t.val===e))return!1;this.addSelectOption(e,e),this.buildOption(e,e),this.buildOriginalOption(e,e),this.dropdown.querySelector(`[data-value="${e}"]`).click(),this.resetTagsInputField()}}searchInput(t){const e=t.target.value;this.lastQuery=e,this.apiUrl?this.remoteSearch(e):this.searchOptions(e)}setValue(t){if(this.value=t,this.clearSelections(),Array.isArray(t))if("tags"===this.mode){this.unselectMultipleItems(),this.selectMultipleItems(),this.selectedItems=[];this.wrapper.querySelectorAll("[data-tag-value]").forEach(t=>t.remove()),this.setTagsItems(),this.reassignTagsInputPlaceholder(this.hasValue()?"":this.placeholder)}else this.setToggleText(this.toggleTextWrapper,this.hasValue()?this.stringFromValue():null),this.unselectMultipleItems(),this.selectMultipleItems();else this.setToggleTitle(),this.toggle.querySelector("[data-icon]")&&this.setToggleIcon(),this.toggle.querySelector("[data-title]")&&this.setToggleTitle(),this.selectSingleItem()}setDisabledState(t){this.isDisabled=t;const e="tags"===this.mode?this.wrapper:this.toggle;null==e||e.classList.toggle("disabled",t),t&&this.isOpened()&&this.close()}hasValue(){return this.isMultiple?Array.isArray(this.value)&&this.value.length>0&&this.value.some(t=>null!=t&&""!==t):null!==this.value&&void 0!==this.value&&""!==this.value}init(){d.ensureGlobalHandlers(),this.createCollection(window.$hsSelectCollection,this),this.build(),"undefined"!=typeof window&&(window.HSAccessibilityObserver||(window.HSAccessibilityObserver=new a.default),this.setupAccessibility())}build(){this.el.style.display="none";if(this.el.querySelectorAll("option").length&&this.setOptions(),this.optionAllowEmptyOption&&!this.value&&(this.value=""),this.isMultiple){const t=this.el.querySelectorAll("option"),e=Array.from(t).filter(t=>t.selected),i=[];e.forEach(t=>{i.push(t.value)}),this.value=i}this.buildWrapper(),"tags"===this.mode?this.buildTags():this.buildToggle(),this.buildDropdown(),this.extraMarkup&&this.buildExtraMarkup(),this.apiUrl||this.fireLoadEvent()}fireLoadEvent(){this.isLoadEventFired||(this.isLoadEventFired=!0,setTimeout(()=>{this.fireEvent("load",this.el),(0,l.dispatch)("load.hs.select",this.el,this.el)}))}setOptions(){const t=this.el.querySelectorAll("option");Array.from(t).filter(t=>this.optionAllowEmptyOption||!this.optionAllowEmptyOption&&t.value&&""!==t.value).forEach(t=>{var e;const i=t.getAttribute("data-hs-select-option"),s={title:t.textContent,val:t.value,disabled:t.disabled,options:i&&"undefined"!==i?JSON.parse(i):null,optgroupName:"OPTGROUP"===(null===(e=t.parentElement)||void 0===e?void 0:e.tagName)?t.parentElement.label:null};this.selectOptions=[...this.selectOptions,s],this.apiUrl&&(this.staticOptions=[...this.staticOptions,s],t.setAttribute("data-static","true"))})}buildWrapper(){this.wrapper=document.createElement("div"),this.wrapper.classList.add("hs-select","relative"),this.setDisabledState(this.isDisabled),"tags"===this.mode&&(this.onWrapperClickListener=t=>this.wrapperClick(t),this.wrapper.addEventListener("click",this.onWrapperClickListener)),this.wrapperClasses&&(0,l.classToClassList)(this.wrapperClasses,this.wrapper),this.el.before(this.wrapper),this.wrapper.append(this.el)}buildExtraMarkup(){const t=t=>{const e=(0,l.htmlToElement)(t);return this.wrapper.append(e),e},e=t=>{t.classList.contains("--prevent-click")||t.addEventListener("click",t=>{t.stopPropagation(),this.isDisabled||this.toggleFn()})};if(Array.isArray(this.extraMarkup))this.extraMarkup.forEach(i=>{const s=t(i);e(s)});else{const i=t(this.extraMarkup);e(i)}}buildToggle(){var t,e;let i,s;this.toggleTextWrapper=document.createElement("span"),this.toggleTextWrapper.classList.add("truncate"),this.toggle=(0,l.htmlToElement)(this.toggleTag||"<div></div>"),i=this.toggle.querySelector("[data-icon]"),s=this.toggle.querySelector("[data-title]"),!this.isMultiple&&i&&this.setToggleIcon(),!this.isMultiple&&s&&this.setToggleTitle(),this.isMultiple?this.setToggleText(this.toggleTextWrapper,this.hasValue()?this.stringFromValue():null):this.setToggleText(this.toggleTextWrapper,(null===(t=this.getItemByValue(this.value))||void 0===t?void 0:t.title)||null),s||this.toggle.append(this.toggleTextWrapper),this.toggleClasses&&(0,l.classToClassList)(this.toggleClasses,this.toggle),this.isDisabled&&this.toggle.classList.add("disabled"),this.wrapper&&this.wrapper.append(this.toggle),(null===(e=this.toggle)||void 0===e?void 0:e.ariaExpanded)&&(this._isOpened?this.toggle.ariaExpanded="true":this.toggle.ariaExpanded="false"),this.onToggleClickListener=()=>this.toggleClick(),this.toggle.addEventListener("click",this.onToggleClickListener)}setToggleIcon(){var t,e,i,s;const o=this.getItemByValue(this.value),n=this.toggle.querySelector("[data-icon]");if(n){n.innerHTML="";const a=null===(e=null===(t=null==o?void 0:o.options)||void 0===t?void 0:t.apiFields)||void 0===e?void 0:e.icon,r=null==o?void 0:o[null===(i=this.apiFieldsMap)||void 0===i?void 0:i.icon],d=null===(s=null==o?void 0:o.options)||void 0===s?void 0:s.icon,h=(0,l.htmlToElement)((this.apiUrl||a)&&this.apiIconTag?this.apiIconTag||"":d||"");this.value&&(a?h.src=a:this.apiUrl&&this.apiIconTag&&r?h.src=r:d&&"string"==typeof d&&!d.trim().startsWith("<")&&(h.src=d)),n.append(h),(h instanceof HTMLImageElement?h.src:h)?n.classList.remove("hidden"):n.classList.add("hidden")}}setToggleText(t,e){null===e?t.innerHTML=this.placeholder:t.textContent=e}setToggleTitle(){const t=this.toggle.querySelector("[data-title]");let e=null;if(this.optionAllowEmptyOption&&""===this.value){const t=this.selectOptions.find(t=>""===t.val);e=(null==t?void 0:t.title)||null}else if(this.value)if(this.apiUrl){const t=this.staticOptions.find(t=>t.val===this.value);if(t)e=t.title;else{const t=this.remoteOptions.find(t=>`${t[this.apiFieldsMap.val]}`===this.value||`${t[this.apiFieldsMap.title]}`===this.value);t&&(e=t[this.apiFieldsMap.title])}}else{const t=this.selectOptions.find(t=>t.val===this.value);t&&(e=t.title)}t?(this.setToggleText(t,e),t.classList.add("truncate"),this.toggle.append(t)):this.setToggleText(this.toggleTextWrapper,e)}buildTags(){this.isDisabled&&this.wrapper.classList.add("disabled"),this.wrapper.setAttribute("tabindex","0"),this.buildTagsInput(),this.setTagsItems()}reassignTagsInputPlaceholder(t){this.tagsInput.placeholder=t,this.calculateInputWidth()}buildTagsItem(t){var e,i,s,o,n,a,r,d;const h=this.getItemByValue(t);let p,c,u,g;const v=document.createElement("div");if(v.setAttribute("data-tag-value",t),this.tagsItemClasses&&(0,l.classToClassList)(this.tagsItemClasses,v),this.tagsItemTemplate&&(p=(0,l.htmlToElement)(this.tagsItemTemplate),v.append(p)),(null===(e=null==h?void 0:h.options)||void 0===e?void 0:e.icon)||this.apiIconTag){const t=(0,l.htmlToElement)(this.apiUrl&&this.apiIconTag?this.apiIconTag:null===(i=null==h?void 0:h.options)||void 0===i?void 0:i.icon);if(this.apiUrl&&this.apiIconTag){const e=h[this.apiFieldsMap.icon]||(null===(o=null===(s=null==h?void 0:h.options)||void 0===s?void 0:s.apiFields)||void 0===o?void 0:o.icon)||(null===(n=null==h?void 0:h.options)||void 0===n?void 0:n.icon)||"";e&&(t.src=e)}g=p?p.querySelector("[data-icon]"):document.createElement("span"),g.append(t),p||v.append(g)}!p||!p.querySelector("[data-icon]")||(null===(a=null==h?void 0:h.options)||void 0===a?void 0:a.icon)||this.apiUrl||this.apiIconTag||h[null===(r=this.apiFieldsMap)||void 0===r?void 0:r.icon]||p.querySelector("[data-icon]").classList.add("hidden"),c=p?p.querySelector("[data-title]"):document.createElement("span"),this.apiUrl&&(null===(d=this.apiFieldsMap)||void 0===d?void 0:d.title)&&h[this.apiFieldsMap.title]?c.textContent=h[this.apiFieldsMap.title]:c.textContent=h.title||"",p||v.append(c),p?u=p.querySelector("[data-remove]"):(u=document.createElement("span"),u.textContent="X",v.append(u)),u.addEventListener("click",()=>{this.value=this.value.filter(e=>e!==t),this.selectedItems=this.selectedItems.filter(e=>e!==t),this.hasValue()||this.reassignTagsInputPlaceholder(this.placeholder),this.unselectMultipleItems(),this.selectMultipleItems(),v.remove(),this.triggerChangeEventForNativeSelect()}),this.wrapper.append(v)}getItemByValue(t){if(this.apiUrl){const e=this.staticOptions.find(e=>e.val===t);return e||this.remoteOptions.find(e=>`${e[this.apiFieldsMap.val]}`===t||e[this.apiFieldsMap.title]===t)}return this.selectOptions.find(e=>e.val===t)}setTagsItems(){if(this.value){(Array.isArray(this.value)?this.value:null!=this.value?[this.value]:[]).forEach(t=>{this.selectedItems.includes(t)||this.buildTagsItem(t),this.selectedItems=this.selectedItems.includes(t)?this.selectedItems:[...this.selectedItems,t]})}this._isOpened&&this.floatingUIInstance&&this.floatingUIInstance.update()}buildTagsInput(){this.tagsInput=document.createElement("input"),this.tagsInputId&&(this.tagsInput.id=this.tagsInputId),this.tagsInputClasses&&(0,l.classToClassList)(this.tagsInputClasses,this.tagsInput),this.tagsInput.setAttribute("tabindex","-1"),this.onTagsInputFocusListener=()=>this.tagsInputFocus(),this.onTagsInputInputListener=()=>this.tagsInputInput(),this.onTagsInputInputSecondListener=(0,l.debounce)(t=>this.tagsInputInputSecond(t)),this.onTagsInputKeydownListener=t=>this.tagsInputKeydown(t),this.tagsInput.addEventListener("focus",this.onTagsInputFocusListener),this.tagsInput.addEventListener("input",this.onTagsInputInputListener),this.tagsInput.addEventListener("input",this.onTagsInputInputSecondListener),this.tagsInput.addEventListener("keydown",this.onTagsInputKeydownListener),this.wrapper.append(this.tagsInput),setTimeout(()=>{this.adjustInputWidth(),this.reassignTagsInputPlaceholder(this.hasValue()?"":this.placeholder)})}buildDropdown(){if(this.dropdown=(0,l.htmlToElement)(this.dropdownTag||"<div></div>"),this.dropdown.setAttribute("data-hs-select-dropdown",""),"parent"===this.dropdownScope&&(this.dropdown.classList.add("absolute"),this.dropdownVerticalFixedPlacement||this.dropdown.classList.add("top-full")),this.dropdown.role="listbox",this.dropdown.tabIndex=-1,this.dropdown.ariaOrientation="vertical",this._isOpened||this.dropdown.classList.add("hidden"),this.dropdownClasses&&(0,l.classToClassList)(this.dropdownClasses,this.dropdown),this.wrapper&&this.wrapper.append(this.dropdown),this.dropdown&&this.hasSearch&&this.buildSearch(),this.selectOptions){let t="";this.selectOptions.forEach((e,i)=>{e.optgroupName&&e.optgroupName!==t&&(this.hasOptgroup=!0,t=e.optgroupName,this.buildOptgroup(t)),this.buildOption(e.title,e.val,e.disabled,e.selected,e.options,`${i}`,void 0,!!this.apiUrl)}),t=""}this.apiUrl&&this.optionsFromRemoteData().then(()=>this.fireLoadEvent()),this.apiUrl||(this.sortElements(this.el,"option"),this.sortElements(this.dropdown,"[data-value]")),"window"===this.dropdownScope&&this.buildFloatingUI(),this.dropdown&&this.apiLoadMore&&this.setupInfiniteScroll()}buildOptgroup(t){const e=(0,l.htmlToElement)(this.optgroupTag||"<div></div>");e.textContent=t,e.setAttribute("data-optgroup",""),this.optgroupClasses&&(0,l.classToClassList)(this.optgroupClasses,e),this.dropdown.append(e)}setupInfiniteScroll(){this.dropdown.addEventListener("scroll",this.handleScroll.bind(this))}handleScroll(){return s(this,void 0,void 0,function*(){if(!this.dropdown||this.isLoading||!this.hasMore||!this.apiLoadMore)return;const{scrollTop:t,scrollHeight:e,clientHeight:i}=this.dropdown;e-t-i<("object"==typeof this.apiLoadMore?this.apiLoadMore.scrollThreshold:100)&&(yield this.loadMore())})}loadMore(){return s(this,void 0,void 0,function*(){var t,e,i,s,o,n,a,r,d,h,p,c;if(!this.apiUrl||this.isLoading||!this.hasMore||!this.apiLoadMore)return;const u=this.requestId;this.isLoading=!0;try{let g;try{g=new URL(this.apiUrl)}catch(t){g=new URL(this.apiUrl,window.location.origin)}const v=(null!==(t=this.lastQuery)&&void 0!==t?t:"").trim().toLowerCase(),m=new URLSearchParams(null!==(e=this.apiQuery)&&void 0!==e?e:""),f=null!==(i=this.apiSearchQueryKey)&&void 0!==i?i:"q";""!==v&&m.set(f,v),g.search=m.toString();const w=(null===(s=this.apiFieldsMap)||void 0===s?void 0:s.page)||(null===(o=this.apiFieldsMap)||void 0===o?void 0:o.offset)||"page",y=!!(null===(n=this.apiFieldsMap)||void 0===n?void 0:n.offset),S="object"==typeof this.apiLoadMore?this.apiLoadMore.perPage:10,b=this.currentPage+1;if(y){const t=this.currentPage*S;g.searchParams.set(w,String(t))}else g.searchParams.set(w,String(b));if(g.searchParams.set((null===(a=this.apiFieldsMap)||void 0===a?void 0:a.limit)||"limit",String(S)),this.loadMoreAbortController)try{this.loadMoreAbortController.abort()}catch(t){}this.loadMoreAbortController=new AbortController;const T=Object.assign(Object.assign({},this.apiOptions||{}),{signal:this.loadMoreAbortController.signal});this.fireEvent("request",{url:g.toString()}),(0,l.dispatch)("request.hs.select",this.el,{url:g.toString()});const I=yield fetch(g.toString(),T),C=yield I.json();if(u!==this.requestId)return void(this.isLoading=!1);const E=this.apiDataPart?null!==(d=null!==(r=C[this.apiDataPart])&&void 0!==r?r:C.results)&&void 0!==d?d:C:null!==(h=C.results)&&void 0!==h?h:C;this.fireEvent("requestCompleted",{url:g.toString(),data:E}),(0,l.dispatch)("requestCompleted.hs.select",this.el,{url:g.toString(),data:E});const A=(t,e)=>e.split(".").reduce((t,e)=>t?t[e]:void 0,t);let O=null;if(this.apiTotalPath){const t=A(C,this.apiTotalPath);O="number"==typeof t?t:null}else O=null!==(c=null!==(p="number"==typeof C.count?C.count:null)&&void 0!==p?p:"number"==typeof C.total?C.total:null)&&void 0!==c?c:C.info&&"number"==typeof C.info.count?C.info.count:null;if(E&&E.length>0){if(this.remoteOptions=[...this.remoteOptions||[],...E],this.buildOptionsFromRemoteData(E),"number"==typeof O){const t=b*S;this.hasMore=t<O}else this.hasMore=E.length===S;this.currentPage=b}else this.hasMore=!1}catch(t){this.hasMore=!1,"AbortError"!==(null==t?void 0:t.name)&&(console.error("Error loading more options:",t),this.fireEvent("requestCompleted",{url:this.apiUrl,error:t}),(0,l.dispatch)("requestCompleted.hs.select",this.el,{url:this.apiUrl,error:t}))}finally{this.isLoading=!1}})}buildFloatingUI(){if("undefined"!=typeof FloatingUIDOM&&FloatingUIDOM.computePosition){document.body.appendChild(this.dropdown);const t="tags"===this.mode?this.wrapper:this.toggle,e=[FloatingUIDOM.offset([0,5])];this.dropdownAutoPlacement&&"function"==typeof FloatingUIDOM.flip&&e.push(FloatingUIDOM.flip({fallbackPlacements:["bottom-start","bottom-end","top-start","top-end"]}));const i={placement:r.POSITIONS[this.dropdownPlacement]||"bottom",strategy:"fixed",middleware:e},s=()=>{Object.assign(this.dropdown.style,{marginLeft:"",marginTop:"",marginRight:"",marginBottom:""}),FloatingUIDOM.computePosition(t,this.dropdown,i).then(({x:t,y:e,placement:i})=>{Object.assign(this.dropdown.style,{position:"fixed",left:`${t}px`,top:`${e}px`,["margin"+(i.startsWith("bottom")||i.startsWith("top")?"Top":i.startsWith("right")?"Left":"Right")]:`${i.startsWith("top")?"-":""}${this.dropdownSpace}px`}),this.dropdown.setAttribute("data-placement",i)})};s();const o=FloatingUIDOM.autoUpdate(t,this.dropdown,s);this.floatingUIInstance={update:s,destroy:o}}else console.error("FloatingUIDOM not found! Please enable it on the page.")}updateDropdownWidth(){const t="tags"===this.mode?this.wrapper:this.toggle;this.dropdown.style.width=`${t.clientWidth}px`}buildSearch(){var t,e,i;if(!this.hasSearch)return;if("tags"===this.mode){const s=null!==(i=null!==(t=this.tagsInput)&&void 0!==t?t:null===(e=this.wrapper)||void 0===e?void 0:e.querySelector(":scope input"))&&void 0!==i?i:this.el.querySelector(":scope input");return s?(this.search=s,this.searchPlaceholder&&(this.search.placeholder=this.searchPlaceholder),this.searchId&&(this.search.id=this.searchId),this.searchClasses&&(0,l.classToClassList)(this.searchClasses,this.search),void(this.apiUrl&&(this.onSearchInputListener=(0,l.debounce)(t=>this.searchInput(t)),this.search.addEventListener("input",this.onSearchInputListener)))):void 0}let s;this.searchWrapper=(0,l.htmlToElement)(this.searchWrapperTemplate||"<div></div>"),this.searchWrapperClasses&&(0,l.classToClassList)(this.searchWrapperClasses,this.searchWrapper),s=this.searchWrapper.querySelector("[data-input]");const o=(0,l.htmlToElement)(this.searchTemplate||'<input type="text">');this.search="INPUT"===o.tagName?o:o.querySelector(":scope input"),this.search.placeholder=this.searchPlaceholder,this.searchClasses&&(0,l.classToClassList)(this.searchClasses,this.search),this.searchId&&(this.search.id=this.searchId),this.onSearchInputListener=(0,l.debounce)(t=>this.searchInput(t)),this.search.addEventListener("input",this.onSearchInputListener),s?s.append(o):this.searchWrapper.append(o),this.dropdown.append(this.searchWrapper)}buildOption(t,e,i=!1,s=!1,o,n="1",a,r=!1){var d,h,p,c,u;let g=null,v=null,m=null,f=null;const w=(0,l.htmlToElement)(this.optionTag||"<div></div>");w.setAttribute("data-value",e),w.setAttribute("data-title-value",t),w.setAttribute("tabIndex",n),w.classList.add("cursor-pointer"),w.setAttribute("data-id",a||`${this.optionId}`),r&&w.setAttribute("data-static","true"),a||this.optionId++,i&&w.classList.add("disabled"),s&&(this.isMultiple?this.value=[...this.value,e]:this.value=e),this.optionTemplate&&(g=(0,l.htmlToElement)(this.optionTemplate),w.append(g));const y=this.optionValueAsTitle?e:t;if(g?(v=g.querySelector("[data-title]"),v.textContent=y||""):w.textContent=y||"",o){const e=null!==(h=null===(d=o.apiFields)||void 0===d?void 0:d.icon)&&void 0!==h?h:o.icon,i=null!==(c=null===(p=o.apiFields)||void 0===p?void 0:p.description)&&void 0!==c?c:o.description;if(e){const i=(0,l.htmlToElement)(null!==(u=this.apiIconTag)&&void 0!==u?u:e);if(i.classList.add("max-w-full"),(this.apiUrl||o.apiFields)&&(i.setAttribute("alt",t),i.setAttribute("src",e)),g)m=g.querySelector("[data-icon]"),m.append(i);else{const t=(0,l.htmlToElement)("<div></div>");this.iconClasses&&(0,l.classToClassList)(this.iconClasses,t),t.append(i),w.append(t)}}if(Array.isArray(o.additionalClasses)&&o.additionalClasses.forEach(([t,e])=>{const i=t?w.querySelector(t):w;i&&e.forEach(t=>i.classList.add(t))}),i)if(w.dataset.description=i,g)f=g.querySelector("[data-description]"),f&&f.append(i);else{const t=(0,l.htmlToElement)("<div></div>");t.textContent=i,this.descriptionClasses&&(0,l.classToClassList)(this.descriptionClasses,t),w.append(t)}}g&&g.querySelector("[data-icon]")&&!o&&!(null==o?void 0:o.icon)&&g.querySelector("[data-icon]").classList.add("hidden"),this.value&&(this.isMultiple?this.value.includes(e):this.value===e)&&w.classList.add("selected"),i||w.addEventListener("click",()=>this.onSelectOption(e)),this.optionClasses&&(0,l.classToClassList)(this.optionClasses,w),this.dropdown&&this.dropdown.append(w),s&&this.setNewValue()}buildOptionFromRemoteData(t,e,i=!1,s=!1,o="1",l,n){o?this.buildOption(t,e,i,s,n,o,l):alert("ID parameter is required for generating remote options! Please check your API endpoint have it.")}buildOptionsFromRemoteData(t){t.forEach((t,e)=>{let i=null,s="",o="";const l={id:"",val:"",title:"",icon:null,description:null,rest:{}};Object.keys(t).forEach(e=>{var n;t[this.apiFieldsMap.id]&&(i=t[this.apiFieldsMap.id],l.id=`${i}`),t[this.apiFieldsMap.val]&&(o=`${t[this.apiFieldsMap.val]}`,l.val=o),t[this.apiFieldsMap.title]&&(s=t[this.apiFieldsMap.title],l.title=s,t[this.apiFieldsMap.val]||(o=s,l.val=o)),t[this.apiFieldsMap.icon]&&(l.icon=t[this.apiFieldsMap.icon]),t[null===(n=this.apiFieldsMap)||void 0===n?void 0:n.description]&&(l.description=t[this.apiFieldsMap.description]),l.rest[e]=t[e]});const n=this.staticOptions.findIndex(t=>t.val===o);if(-1!==n)return void this.mergeRemoteDataIntoStaticOption(n,o,l,e);if(!this.dropdown.querySelector(`[data-value="${o}"]`)){const t=!!this.apiSelectedValues&&(Array.isArray(this.apiSelectedValues)?this.apiSelectedValues.includes(o):this.apiSelectedValues===o);this.buildOriginalOption(s,o,i,!1,t,l),this.buildOptionFromRemoteData(s,o,!1,t,`${e}`,i,l),t&&(this.isMultiple?(this.value||(this.value=[]),Array.isArray(this.value)&&(this.value=[...this.value,o])):this.value=o,this.toggle&&(this.toggle.querySelector("[data-title]")&&this.setToggleTitle(),this.toggle.querySelector("[data-icon]")&&this.setToggleIcon()))}}),this.sortElements(this.el,"option"),this.sortElements(this.dropdown,"[data-value]")}mergeRemoteDataIntoStaticOption(t,e,i,s){const o=this.staticOptions[t];o.options||(o.options={}),o.options.apiFields||(o.options.apiFields={}),i.title&&(o.title=i.title),i.icon&&(o.options.apiFields.icon=i.icon),i.description&&(o.options.apiFields.description=i.description),Object.keys(i.rest).forEach(t=>{o.options.apiFields[t]=i.rest[t]});const n=this.dropdown.querySelector(`[data-value="${e}"][data-static]`);if(n){if(n.setAttribute("tabIndex",`${s}`),i.id&&n.setAttribute("data-id",`${i.id}`),i.title){n.setAttribute("data-title-value",i.title);const t=n.querySelector("[data-title]");t&&(t.textContent=i.title)}if(i.icon){const t=n.querySelector("[data-icon]");if(t){t.innerHTML="";const e=(0,l.htmlToElement)(this.apiIconTag||"<img />");e.classList.add("max-w-full"),e.setAttribute("alt",o.title),e.setAttribute("src",i.icon),t.append(e)}}if(i.description){n.dataset.description=i.description;const t=n.querySelector("[data-description]");t&&(t.textContent=i.description)}}const a=this.el.querySelector(`option[value="${e}"][data-static]`);if(a){i.id&&a.setAttribute("data-id",`${i.id}`),i.title&&(a.textContent=i.title);const t={id:i.id||"",val:i.val||"",title:i.title||"",icon:i.icon||null,description:i.description||null,rest:i.rest};a.setAttribute("data-hs-select-option",JSON.stringify(t))}const r=this.selectOptions.findIndex(t=>t.val===e);-1!==r&&(this.selectOptions[r]=o);(this.isMultiple?Array.isArray(this.value)&&this.value.includes(e):this.value===e)&&this.toggle&&(i.title&&(this.toggle.querySelector("[data-title]")?this.setToggleTitle():this.toggleTextWrapper&&(this.isMultiple?this.setToggleText(this.toggleTextWrapper,this.stringFromValue()):this.setToggleText(this.toggleTextWrapper,i.title))),i.icon&&this.toggle.querySelector("[data-icon]")&&this.setToggleIcon())}optionsFromRemoteData(){return s(this,arguments,void 0,function*(t=""){const e=(yield this.apiRequest(t))||[];this.remoteOptions=e,e.length?this.buildOptionsFromRemoteData(this.remoteOptions):console.log("There is no data were responded!")})}apiRequest(){return s(this,arguments,void 0,function*(t="",e){var i,s,o,n,a,r,d,h,p,c;try{let u;try{u=new URL(this.apiUrl)}catch(t){try{u=new URL(this.apiUrl,window.location.origin)}catch(t){return console.error("Invalid API URL:",this.apiUrl),null}}const g=new URLSearchParams(null!==(i=this.apiQuery)&&void 0!==i?i:""),v=null!==(s=this.apiOptions)&&void 0!==s?s:{},m=Object.assign({},v);e&&(m.signal=e);const f=null!==(o=this.apiSearchQueryKey)&&void 0!==o?o:"q",w=(null!=t?t:"").trim().toLowerCase();if(""!==w&&g.set(f,w),this.apiLoadMore){const t="object"==typeof this.apiLoadMore?this.apiLoadMore.perPage:10,e=null!==(d=null!==(a=null===(n=this.apiFieldsMap)||void 0===n?void 0:n.page)&&void 0!==a?a:null===(r=this.apiFieldsMap)||void 0===r?void 0:r.offset)&&void 0!==d?d:"page",i=null!==(p=null===(h=this.apiFieldsMap)||void 0===h?void 0:h.limit)&&void 0!==p?p:"limit",s=Boolean(null===(c=this.apiFieldsMap)||void 0===c?void 0:c.offset)?0:1,o="number"==typeof this.apiPageStart?this.apiPageStart:s;g.delete(e),g.delete(i),g.set(e,String(o)),g.set(i,String(t))}u.search=g.toString(),this.fireEvent("request",{url:u.toString()}),(0,l.dispatch)("request.hs.select",this.el,{url:u.toString()});const y=yield fetch(u.toString(),m),S=yield y.json(),b=this.apiDataPart?S[this.apiDataPart]:S;return this.fireEvent("requestCompleted",{url:u.toString(),data:b}),(0,l.dispatch)("requestCompleted.hs.select",this.el,{url:u.toString(),data:b}),b}catch(t){"AbortError"!==(null==t?void 0:t.name)&&(console.error(t),this.fireEvent("requestCompleted",{url:this.apiUrl,error:t}),(0,l.dispatch)("requestCompleted.hs.select",this.el,{url:this.apiUrl,error:t}))}})}sortElements(t,e){if(this.hasOptgroup)return;const i=Array.from(t.querySelectorAll(e));this.isSelectedOptionOnTop&&i.sort((t,e)=>{const i=t.classList.contains("selected")||t.hasAttribute("selected"),s=e.classList.contains("selected")||e.hasAttribute("selected");return i&&!s?-1:!i&&s?1:0}),i.forEach((e,i)=>{t.appendChild(e),e.hasAttribute("tabindex")&&e.setAttribute("tabIndex",`${i}`)})}remoteSearch(t){return s(this,void 0,void 0,function*(){var e,i,s,o;if(this.requestId++,this.remoteSearchAbortController)try{this.remoteSearchAbortController.abort()}catch(t){}if(this.loadMoreAbortController)try{this.loadMoreAbortController.abort()}catch(t){}if(this.remoteSearchAbortController=new AbortController,this.currentPage=0,this.hasMore=!0,this.isLoading=!1,this.filterStaticOptions(t),t.length<=this.minSearchLength){const t=yield this.apiRequest("",null===(e=this.remoteSearchAbortController)||void 0===e?void 0:e.signal);if(!t)return!1;const s=Boolean(null===(i=this.apiFieldsMap)||void 0===i?void 0:i.offset)?0:1,o="number"==typeof this.apiPageStart?this.apiPageStart:s;this.currentPage=o;const l=Array.isArray(this.value)?this.value:this.value?[this.value]:[],n=this.remoteOptions.filter(t=>{var e;return l.includes(`${t[null===(e=this.apiFieldsMap)||void 0===e?void 0:e.val]}`)}),a=new Set(t.map(t=>{var e;return`${t[null===(e=this.apiFieldsMap)||void 0===e?void 0:e.val]}`}));return this.remoteOptions=[...t,...n.filter(t=>{var e;return!a.has(`${t[null===(e=this.apiFieldsMap)||void 0===e?void 0:e.val]}`)})],Array.from(this.dropdown.querySelectorAll("[data-value]:not([data-static])")).forEach(t=>{l.includes(t.getAttribute("data-value"))||t.remove()}),Array.from(this.el.querySelectorAll("option[value][data-hs-select-option]:not([data-static])")).forEach(t=>{l.includes(t.value)||t.remove()}),t.length?this.buildOptionsFromRemoteData(t):console.log("No data responded!"),!1}const l=yield this.apiRequest(t,null===(s=this.remoteSearchAbortController)||void 0===s?void 0:s.signal);if(!l)return;const n=Boolean(null===(o=this.apiFieldsMap)||void 0===o?void 0:o.offset)?0:1,a="number"==typeof this.apiPageStart?this.apiPageStart:n;this.currentPage=a;const r=Array.isArray(this.value)?this.value:this.value?[this.value]:[],d=this.remoteOptions.filter(t=>{var e;return r.includes(`${t[null===(e=this.apiFieldsMap)||void 0===e?void 0:e.val]}`)}),h=new Set(l.map(t=>{var e;return`${t[null===(e=this.apiFieldsMap)||void 0===e?void 0:e.val]}`}));this.remoteOptions=[...l,...d.filter(t=>{var e;return!h.has(`${t[null===(e=this.apiFieldsMap)||void 0===e?void 0:e.val]}`)})];let p=l.map(t=>`${t.id}`),c=null;const u=this.dropdown.querySelectorAll("[data-value]:not([data-static])");this.el.querySelectorAll("[data-hs-select-option]:not([data-static])").forEach(t=>{var e;const i=t.getAttribute("data-id");p.includes(i)||(null===(e=this.value)||void 0===e?void 0:e.includes(t.value))||this.destroyOriginalOption(t.value)}),u.forEach(t=>{var e;const i=t.getAttribute("data-id");p.includes(i)||(null===(e=this.value)||void 0===e?void 0:e.includes(t.getAttribute("data-value")))?p=p.filter(t=>t!==i):this.destroyOption(t.getAttribute("data-value"))}),c=l.filter(t=>p.includes(`${t.id}`)),c.length?this.buildOptionsFromRemoteData(c):console.log("No data responded!")})}filterStaticOptions(t){const e=this.dropdown.querySelectorAll("[data-value][data-static]"),i=t.trim().toLowerCase();e.forEach(t=>{var e,s;if(i.length<=this.minSearchLength)t.classList.remove("hidden");else{const o=(null===(e=t.getAttribute("data-title-value"))||void 0===e?void 0:e.toLowerCase())||"",l=(null===(s=t.dataset.description)||void 0===s?void 0:s.toLowerCase())||"";this.optionMatchesQuery(i,o,l)?t.classList.remove("hidden"):t.classList.add("hidden")}})}normalizeSearchText(t=""){return t.toLocaleLowerCase().replace(/\s+/g," ").trim()}tokenizeSearchQuery(t){return this.normalizeSearchText(t).split(" ").filter(Boolean)}charsSequenceMatch(t,e){const i=t.split("").map(t=>/\w/.test(t)?`${t}[\\W_]*`:"\\W*").join("");return new RegExp(i,"i").test(e)}optionMatchesQuery(t,e,i=""){const s=this.normalizeSearchText(t);if(!s)return!0;const o=this.normalizeSearchText(e),l=this.normalizeSearchText(i),n=this.preventSearchInsideDescription?[o]:[o,l];if("token-all"===this.searchMatchMode){const t=this.tokenizeSearchQuery(s);return n.some(e=>t.every(t=>e.includes(t)))}if("hybrid"===this.searchMatchMode){const t=this.tokenizeSearchQuery(s);return n.some(e=>{const i=t.every(t=>e.includes(t)),o=this.charsSequenceMatch(s,e);return i||o})}return"chars-sequence"===this.searchMatchMode?n.some(t=>this.charsSequenceMatch(s,t)):n.some(t=>t.includes(s))}destroyOption(t){const e=this.dropdown.querySelector(`[data-value="${t}"]`);if(!e)return!1;e.remove()}buildOriginalOption(t,e,i,s,o,n){const a=(0,l.htmlToElement)("<option></option>");a.setAttribute("value",e),s&&a.setAttribute("disabled","disabled"),o&&a.setAttribute("selected","selected"),i&&a.setAttribute("data-id",i),a.setAttribute("data-hs-select-option",JSON.stringify(null!=n?n:null)),a.innerText=t,this.el.append(a)}destroyOriginalOption(t){const e=this.el.querySelector(`[value="${t}"]`);if(!e)return!1;e.remove()}buildTagsInputHelper(){this.tagsInputHelper=document.createElement("span"),this.tagsInputHelper.style.fontSize=window.getComputedStyle(this.tagsInput).fontSize,this.tagsInputHelper.style.fontFamily=window.getComputedStyle(this.tagsInput).fontFamily,this.tagsInputHelper.style.fontWeight=window.getComputedStyle(this.tagsInput).fontWeight,this.tagsInputHelper.style.letterSpacing=window.getComputedStyle(this.tagsInput).letterSpacing,this.tagsInputHelper.style.visibility="hidden",this.tagsInputHelper.style.whiteSpace="pre",this.tagsInputHelper.style.position="absolute",this.wrapper.appendChild(this.tagsInputHelper)}calculateInputWidth(){if(!this.tagsInputHelper)return;this.tagsInputHelper.textContent=this.tagsInput.value||this.tagsInput.placeholder;const t=parseInt(window.getComputedStyle(this.tagsInput).paddingLeft)+parseInt(window.getComputedStyle(this.tagsInput).paddingRight),e=parseInt(window.getComputedStyle(this.tagsInput).borderLeftWidth)+parseInt(window.getComputedStyle(this.tagsInput).borderRightWidth),i=this.tagsInputHelper.offsetWidth+t+e,s=this.wrapper.offsetWidth-(parseInt(window.getComputedStyle(this.wrapper).paddingLeft)+parseInt(window.getComputedStyle(this.wrapper).paddingRight));this.tagsInput.style.width=`${Math.min(i,s)+2}px`}adjustInputWidth(){this.buildTagsInputHelper(),this.calculateInputWidth()}onSelectOption(t){if(this.clearSelections(),this.isMultiple?(Array.isArray(this.value)||(this.value=[]),this.value=this.value.includes(t)?this.value.filter(e=>e!==t):[...this.value,t],this.selectMultipleItems(),this.setNewValue()):(this.value=t,this.selectSingleItem(),this.setNewValue()),this.fireEvent("change",this.value),"tags"===this.mode){const t=this.selectedItems.filter(t=>!this.value.includes(t));t.length&&t.forEach(t=>{this.selectedItems=this.selectedItems.filter(e=>e!==t),this.wrapper.querySelector(`[data-tag-value="${t}"]`).remove()}),this.resetTagsInputField()}this.isMultiple||(this.toggle.querySelector("[data-icon]")&&this.setToggleIcon(),this.toggle.querySelector("[data-title]")&&this.setToggleTitle(),this.close(!0)),this.hasValue()||"tags"!==this.mode||this.reassignTagsInputPlaceholder(this.placeholder),this._isOpened&&"tags"===this.mode&&this.tagsInput&&this.tagsInput.focus(),this.triggerChangeEventForNativeSelect()}triggerChangeEventForNativeSelect(){const t=new Event("change",{bubbles:!0});this.el.dispatchEvent(t),(0,l.dispatch)("change.hs.select",this.el,this.value)}addSelectOption(t,e,i,s,o){this.selectOptions=[...this.selectOptions,{title:t,val:e,disabled:i,selected:s,options:o}]}removeSelectOption(t,e=!1){if(!!!this.selectOptions.some(e=>e.val===t))return!1;this.selectOptions=this.selectOptions.filter(e=>e.val!==t),this.value=e?this.value.filter(e=>e!==t):t}resetTagsInputField(){this.tagsInput.value="",this.reassignTagsInputPlaceholder(""),this.searchOptions("")}clearSelections(){const t=this.el.querySelectorAll("option");Array.from(this.dropdown.children).forEach(t=>{t.classList.contains("selected")&&t.classList.remove("selected")}),Array.from(t).forEach(t=>{t.selected&&(t.selected=!1)})}setNewValue(){if("tags"===this.mode)this.setTagsItems();else if(this.optionAllowEmptyOption&&""===this.value){const t=this.selectOptions.find(t=>""===t.val);this.setToggleText(this.toggleTextWrapper,(null==t?void 0:t.title)||null)}else if(this.hasValue())if(this.apiUrl){const t=this.dropdown.querySelector(`[data-value="${this.value}"]`);if(t)this.setToggleText(this.toggleTextWrapper,t.getAttribute("data-title-value")||null);else{const t=this.staticOptions.find(t=>t.val===this.value);if(t)this.setToggleText(this.toggleTextWrapper,t.title);else{const t=this.remoteOptions.find(t=>(t[this.apiFieldsMap.val]?`${t[this.apiFieldsMap.val]}`:t[this.apiFieldsMap.title])===this.value);this.setToggleText(this.toggleTextWrapper,t?`${t[this.apiFieldsMap.title]}`:this.stringFromValue())}}}else this.setToggleText(this.toggleTextWrapper,this.stringFromValue());else this.setToggleText(this.toggleTextWrapper,null)}stringFromValueBasic(t){var e;const i=[];let s="";if(t.forEach(t=>{this.isMultiple?Array.isArray(this.value)&&this.value.includes(t.val)&&i.push(t.title):this.value===t.val&&i.push(t.title)}),void 0!==this.toggleCountText&&null!==this.toggleCountText&&i.length>=this.toggleCountTextMinItems)if("nItemsAndCount"===this.toggleCountTextMode){const t=i.slice(0,this.toggleCountTextMinItems-1),o=[t.join(this.toggleSeparators.items)],l=""+(i.length-t.length);if((null===(e=null==this?void 0:this.toggleSeparators)||void 0===e?void 0:e.betweenItemsAndCounter)&&o.push(this.toggleSeparators.betweenItemsAndCounter),this.toggleCountText)switch(this.toggleCountTextPlacement){case"postfix-no-space":o.push(`${l}${this.toggleCountText}`);break;case"prefix-no-space":o.push(`${this.toggleCountText}${l}`);break;case"prefix":o.push(`${this.toggleCountText} ${l}`);break;default:o.push(`${l} ${this.toggleCountText}`)}s=o.join(" ")}else s=`${i.length} ${this.toggleCountText}`;else s=i.join(this.toggleSeparators.items);return s}stringFromValueRemoteData(){if(!this.dropdown)return this.stringFromValueBasic(this.selectOptions);const t=this.dropdown.querySelectorAll("[data-title-value]"),e=[];let i="";if(t.forEach(t=>{const i=t.getAttribute("data-value"),s=t.getAttribute("data-title-value");this.isMultiple?Array.isArray(this.value)&&this.value.includes(i)&&e.push(s):this.value===i&&e.push(s)}),this.toggleCountText&&""!==this.toggleCountText&&e.length>=this.toggleCountTextMinItems)if("nItemsAndCount"===this.toggleCountTextMode){const t=e.slice(0,this.toggleCountTextMinItems-1);i=`${t.join(this.toggleSeparators.items)} ${this.toggleSeparators.betweenItemsAndCounter} ${e.length-t.length} ${this.toggleCountText}`}else i=`${e.length} ${this.toggleCountText}`;else i=e.join(this.toggleSeparators.items);return i}stringFromValue(){return this.apiUrl?this.stringFromValueRemoteData():this.stringFromValueBasic(this.selectOptions)}selectSingleItem(){const t=this.el.querySelectorAll("option");Array.from(t).find(t=>this.value===t.value).selected=!0;const e=Array.from(this.dropdown.children).find(t=>this.value===t.getAttribute("data-value"));e&&e.classList.add("selected"),this.sortElements(this.el,"option"),this.sortElements(this.dropdown,"[data-value]")}selectMultipleItems(){if(!Array.isArray(this.value))return;const t=this.el.querySelectorAll("option");Array.from(this.dropdown.children).filter(t=>this.value.includes(t.getAttribute("data-value"))).forEach(t=>t.classList.add("selected")),Array.from(t).filter(t=>this.value.includes(t.value)).forEach(t=>t.selected=!0),this.sortElements(this.el,"option"),this.sortElements(this.dropdown,"[data-value]")}unselectMultipleItems(){const t=this.el.querySelectorAll("option");Array.from(this.dropdown.children).forEach(t=>t.classList.remove("selected")),Array.from(t).forEach(t=>t.selected=!1),this.sortElements(this.el,"option"),this.sortElements(this.dropdown,"[data-value]")}searchOptions(t){if(t.length<=this.minSearchLength){this.searchNoResult&&(this.searchNoResult.remove(),this.searchNoResult=null);return this.dropdown.querySelectorAll("[data-value]").forEach(t=>{t.classList.remove("hidden")}),!1}this.searchNoResult&&(this.searchNoResult.remove(),this.searchNoResult=null),this.searchNoResult=(0,l.htmlToElement)(this.searchNoResultTemplate),this.searchNoResult.innerText=this.searchNoResultText,(0,l.classToClassList)(this.searchNoResultClasses,this.searchNoResult);const e=this.dropdown.querySelectorAll("[data-value]");let i,s=!1;this.searchLimit&&(i=0),e.forEach(e=>{var o;const l=e.getAttribute("data-title-value")||"",n=(null===(o=null==e?void 0:e.dataset)||void 0===o?void 0:o.description)||"";!this.optionMatchesQuery(t,l,n)||this.searchLimit&&i>=this.searchLimit?e.classList.add("hidden"):(e.classList.remove("hidden"),s=!0,this.searchLimit&&i++)}),s||this.dropdown.append(this.searchNoResult)}eraseToggleIcon(){const t=this.toggle.querySelector("[data-icon]");t&&(t.innerHTML=null,t.classList.add("hidden"))}eraseToggleTitle(){const t=this.toggle.querySelector("[data-title]");t?t.innerHTML=this.placeholder:this.toggleTextWrapper.innerHTML=this.placeholder}toggleFn(){this._isOpened?this.close():this.open()}setupAccessibility(){this.accessibilityComponent=window.HSAccessibilityObserver.registerComponent(this.wrapper,{onEnter:()=>{if(this._isOpened){const t=this.dropdown.querySelector(".hs-select-option-highlighted");t&&(this.onSelectOption(t.getAttribute("data-value")||""),this._isOpened&&t.focus())}else this.open()},onSpace:()=>{if(this._isOpened){const t=this.dropdown.querySelector(".hs-select-option-highlighted");t&&(this.onSelectOption(t.getAttribute("data-value")||""),this._isOpened&&t.focus())}else this.open()},onEsc:()=>{this._isOpened&&this.close(!0)},onArrow:t=>{if(!t.metaKey)if(this._isOpened||"ArrowDown"!==t.key){if(this._isOpened)switch(t.key){case"ArrowDown":this.focusMenuItem("next");break;case"ArrowUp":this.focusMenuItem("prev");break;case"Home":this.onStartEnd(!0);break;case"End":this.onStartEnd(!1)}}else this.open()},onHome:()=>{this._isOpened&&this.onStartEnd(!0)},onEnd:()=>{this._isOpened&&this.onStartEnd(!1)},onTab:()=>{this._isOpened&&this.close()},onShiftTab:()=>{this._isOpened&&this.close()}},this._isOpened,"Select",".hs-select",this.dropdown)}focusMenuItem(t){const e=Array.from(this.dropdown.querySelectorAll(":scope > *:not(.hidden)")).filter(t=>!t.classList.contains("disabled")&&!t.hasAttribute("data-optgroup"));if(!e.length)return;const i=this.dropdown.querySelector(".hs-select-option-highlighted"),s=i?e.indexOf(i):-1,o="next"===t?(s+1)%e.length:(s-1+e.length)%e.length;i&&i.classList.remove("hs-select-option-highlighted"),e[o].classList.add("hs-select-option-highlighted"),e[o].focus()}onStartEnd(t=!0){if(!this.dropdown)return;const e=Array.from(this.dropdown.querySelectorAll(":scope > *:not(.hidden)")).filter(t=>!t.classList.contains("disabled"));if(!e.length)return;const i=this.dropdown.querySelector(".hs-select-option-highlighted");i&&i.classList.remove("hs-select-option-highlighted");const s=t?0:e.length-1;e[s].classList.add("hs-select-option-highlighted"),e[s].focus()}destroy(){var t;this.wrapper&&this.wrapper.removeEventListener("click",this.onWrapperClickListener),this.toggle&&this.toggle.removeEventListener("click",this.onToggleClickListener),this.tagsInput&&(this.tagsInput.removeEventListener("focus",this.onTagsInputFocusListener),this.tagsInput.removeEventListener("input",this.onTagsInputInputListener),this.tagsInput.removeEventListener("input",this.onTagsInputInputSecondListener),this.tagsInput.removeEventListener("keydown",this.onTagsInputKeydownListener)),this.search&&this.search.removeEventListener("input",this.onSearchInputListener);const e=this.el.parentElement.parentElement;this.el.classList.add("hidden"),this.el.style.display="",e.prepend(this.el),e.querySelector(".hs-select").remove(),this.wrapper=null,null===(t=this.disabledObserver)||void 0===t||t.disconnect(),this.disabledObserver=null,window.$hsSelectCollection=window.$hsSelectCollection.filter(({element:t})=>t.el!==this.el)}open(){var t;const e=(null===(t=null===window||void 0===window?void 0:window.$hsSelectCollection)||void 0===t?void 0:t.find(t=>t.element.isOpened()))||null;if(e&&e.element.close(),this.animationInProcess)return!1;this.animationInProcess=!0,"window"===this.dropdownScope&&this.dropdown.classList.add("invisible"),this.dropdown.classList.remove("hidden"),"window"!==this.dropdownScope&&this.recalculateDirection(),setTimeout(()=>{var t;if((null===(t=null==this?void 0:this.toggle)||void 0===t?void 0:t.ariaExpanded)&&(this.toggle.ariaExpanded="true"),this.wrapper.classList.add("active"),this.dropdown.classList.add("opened"),this.dropdown.classList.contains("w-full")&&"window"===this.dropdownScope&&this.updateDropdownWidth(),this.floatingUIInstance&&"window"===this.dropdownScope&&(this.floatingUIInstance.update(),this.dropdown.classList.remove("invisible")),this.hasSearch&&!this.preventSearchFocus&&this.search.focus(),this.animationInProcess=!1,this.scrollToSelected&&this.dropdown){const t=this.dropdown.querySelector(".selected");if(t){const e=this.dropdown.clientHeight,i=t.offsetTop-e/2+t.clientHeight/2;this.dropdown.scrollTop=i}}}),this._isOpened=!0,window.HSAccessibilityObserver&&this.accessibilityComponent&&window.HSAccessibilityObserver.updateComponentState(this.accessibilityComponent,this._isOpened)}close(t=!1){var e,i,s,o;if(this.animationInProcess)return!1;this.animationInProcess=!0,(null===(e=null==this?void 0:this.toggle)||void 0===e?void 0:e.ariaExpanded)&&(this.toggle.ariaExpanded="false"),this.wrapper.classList.remove("active"),this.dropdown.classList.remove("opened","bottom-full","top-full"),(null===(i=this.dropdownDirectionClasses)||void 0===i?void 0:i.bottom)&&this.dropdown.classList.remove(this.dropdownDirectionClasses.bottom),(null===(s=this.dropdownDirectionClasses)||void 0===s?void 0:s.top)&&this.dropdown.classList.remove(this.dropdownDirectionClasses.top),this.dropdown.style.marginTop="",this.dropdown.style.marginBottom="",(0,l.afterTransition)(this.dropdown,()=>{var e;this.dropdown.classList.add("hidden"),this.hasSearch&&"tags"!==this.mode&&(this.search.value="",this.apiUrl?this.filterStaticOptions(""):this.search.dispatchEvent(new Event("input",{bubbles:!0})),this.search.blur()),t&&((null===(e=this.mode)||void 0===e?void 0:e.includes("tags"))?this.wrapper.focus():this.toggle.focus()),this.animationInProcess=!1}),null===(o=this.dropdown.querySelector(".hs-select-option-highlighted"))||void 0===o||o.classList.remove("hs-select-option-highlighted"),this._isOpened=!1,window.HSAccessibilityObserver&&this.accessibilityComponent&&window.HSAccessibilityObserver.updateComponentState(this.accessibilityComponent,this._isOpened)}addOption(t){let e=`${this.selectOptions.length}`;const i=t=>{const{title:i,val:s,disabled:o,selected:l,options:n}=t;!!this.selectOptions.some(t=>t.val===s)||(this.addSelectOption(i,s,o,l,n),this.buildOption(i,s,o,l,n,e),this.buildOriginalOption(i,s,null,o,l,n),l&&!this.isMultiple&&this.onSelectOption(s))};Array.isArray(t)?t.forEach(t=>{i(t)}):i(t),this.sortElements(this.el,"option"),this.sortElements(this.dropdown,"[data-value]")}removeOption(t){const e=(t,e=!1)=>{!!this.selectOptions.some(e=>e.val===t)&&(this.removeSelectOption(t,e),this.destroyOption(t),this.destroyOriginalOption(t),this.value===t&&(this.value=null,this.eraseToggleTitle(),this.eraseToggleIcon()))};Array.isArray(t)?t.forEach(t=>{e(t,this.isMultiple)}):e(t,this.isMultiple),this.setNewValue(),this.sortElements(this.el,"option"),this.sortElements(this.dropdown,"[data-value]")}recalculateDirection(){var t,e,i,s;if((null==this?void 0:this.dropdownVerticalFixedPlacement)&&(this.dropdown.classList.contains("bottom-full")||this.dropdown.classList.contains("top-full")))return!1;"top"===(null==this?void 0:this.dropdownVerticalFixedPlacement)?(this.dropdown.classList.add("bottom-full"),this.dropdown.style.marginBottom=`${this.dropdownSpace}px`):"bottom"===(null==this?void 0:this.dropdownVerticalFixedPlacement)?(this.dropdown.classList.add("top-full"),this.dropdown.style.marginTop=`${this.dropdownSpace}px`):(0,l.isEnoughSpace)(this.dropdown,this.toggle||this.tagsInput,"bottom",this.dropdownSpace,this.viewport)?(this.dropdown.classList.remove("bottom-full"),(null===(t=this.dropdownDirectionClasses)||void 0===t?void 0:t.bottom)&&this.dropdown.classList.remove(this.dropdownDirectionClasses.bottom),this.dropdown.style.marginBottom="",this.dropdown.classList.add("top-full"),(null===(e=this.dropdownDirectionClasses)||void 0===e?void 0:e.top)&&this.dropdown.classList.add(this.dropdownDirectionClasses.top),this.dropdown.style.marginTop=`${this.dropdownSpace}px`):(this.dropdown.classList.remove("top-full"),(null===(i=this.dropdownDirectionClasses)||void 0===i?void 0:i.top)&&this.dropdown.classList.remove(this.dropdownDirectionClasses.top),this.dropdown.style.marginTop="",this.dropdown.classList.add("bottom-full"),(null===(s=this.dropdownDirectionClasses)||void 0===s?void 0:s.bottom)&&this.dropdown.classList.add(this.dropdownDirectionClasses.bottom),this.dropdown.style.marginBottom=`${this.dropdownSpace}px`)}isOpened(){return this._isOpened||!1}containsElement(t){var e;return(null===(e=this.wrapper)||void 0===e?void 0:e.contains(t))||!1}containsDropdownElement(t){var e;return(null===(e=this.dropdown)||void 0===e?void 0:e.contains(t))||!1}static findInCollection(t){return d.ensureGlobalHandlers(),window.$hsSelectCollection.find(e=>t instanceof d?e.element.el===t.el:"string"==typeof t?e.element.el===document.querySelector(t):e.element.el===t)||null}static getInstance(t,e){d.ensureGlobalHandlers();const i=window.$hsSelectCollection.find(e=>e.element.el===("string"==typeof t?document.querySelector(t):t));return i?e?i:i.element:null}static autoInit(){d.ensureGlobalHandlers(),window.$hsSelectCollection&&(window.$hsSelectCollection=window.$hsSelectCollection.filter(({element:t})=>document.contains(t.el))),document.querySelectorAll("[data-hs-select]:not(.--prevent-on-load-init)").forEach(t=>{if(!window.$hsSelectCollection.find(e=>{var i;return(null===(i=null==e?void 0:e.element)||void 0===i?void 0:i.el)===t})){const e=t.getAttribute("data-hs-select"),i=e?JSON.parse(e):{};new d(t,i)}})}static ensureGlobalHandlers(){"undefined"!=typeof window&&(window.$hsSelectCollection||(window.$hsSelectCollection=[]),d.globalListenersInitialized||(d.globalListenersInitialized=!0,window.addEventListener("click",t=>{const e=t.target;d.closeCurrentlyOpened(e)})))}static open(t){const e=d.findInCollection(t);e&&!e.element.isOpened()&&e.element.open()}static close(t){const e=d.findInCollection(t);e&&e.element.isOpened()&&e.element.close()}static closeCurrentlyOpened(t=null){if(!t.closest(".hs-select.active")&&!t.closest("[data-hs-select-dropdown].opened")){const t=window.$hsSelectCollection.filter(t=>t.element.isOpened())||null;t&&t.forEach(t=>{t.element.close()})}}}d.globalListenersInitialized=!1,e.default=d},292(t,e){
18
18
  /*
19
- * @version: 4.2.0
19
+ * @version: 5.1.0
20
20
  * @author: Preline Labs Ltd.
21
21
  * @license: Licensed under MIT and Preline UI Fair Use License (https://preline.co/docs/license.html)
22
22
  * Copyright 2024 Preline Labs Ltd.
23
23
  */
24
- Object.defineProperty(e,"__esModule",{value:!0}),e.stringToBoolean=e.menuSearchHistory=e.isScrollable=e.isParentOrElementHidden=e.isJson=e.isIpadOS=e.isIOS=e.isFormElement=e.isFocused=e.isEnoughSpace=e.isDirectChild=e.htmlToElement=e.getZIndex=e.getHighestZIndex=e.getClassPropertyAlt=e.getClassProperty=e.dispatch=e.debounce=e.classToClassList=e.afterTransition=void 0;e.stringToBoolean=t=>"true"===t;e.getClassProperty=(t,e,i="")=>(window.getComputedStyle(t).getPropertyValue(e)||i).replace(" ","");e.getClassPropertyAlt=(t,e,i="")=>{let s="";return t.classList.forEach(t=>{t.includes(e)&&(s=t)}),s.match(/:(.*)]/)?s.match(/:(.*)]/)[1]:i};const i=t=>window.getComputedStyle(t).getPropertyValue("z-index");e.getZIndex=i;e.getHighestZIndex=t=>{let e=Number.NEGATIVE_INFINITY;return t.forEach(t=>{let s=i(t);"auto"!==s&&(s=parseInt(s,10),s>e&&(e=s))}),e};e.isDirectChild=(t,e)=>{const i=t.children;for(let t=0;t<i.length;t++)if(i[t]===e)return!0;return!1};e.isEnoughSpace=(t,e,i="auto",s=10,o=null)=>{const n=e.getBoundingClientRect(),l=o?o.getBoundingClientRect():null,a=window.innerHeight,r=l?n.top-l.top:n.top,d=(o?l.bottom:a)-n.bottom,h=t.clientHeight+s;return"bottom"===i?d>=h:"top"===i?r>=h:r>=h||d>=h};e.isFocused=t=>document.activeElement===t;e.isFormElement=t=>t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement;e.isIOS=()=>!!/iPad|iPhone|iPod/.test(navigator.platform)||navigator.maxTouchPoints&&navigator.maxTouchPoints>2&&/MacIntel/.test(navigator.platform);e.isIpadOS=()=>navigator.maxTouchPoints&&navigator.maxTouchPoints>2&&/MacIntel/.test(navigator.platform);e.isJson=t=>{if("string"!=typeof t)return!1;const e=t.trim()[0],i=t.trim().slice(-1);if("{"===e&&"}"===i||"["===e&&"]"===i)try{return JSON.parse(t),!0}catch(t){return!1}return!1};const s=t=>{if(!t)return!1;return"none"===window.getComputedStyle(t).display||s(t.parentElement)};e.isParentOrElementHidden=s;e.isScrollable=t=>{const e=window.getComputedStyle(t),i=e.overflowY,s=e.overflowX,o=("scroll"===i||"auto"===i)&&t.scrollHeight>t.clientHeight,n=("scroll"===s||"auto"===s)&&t.scrollWidth>t.clientWidth;return o||n};e.debounce=(t,e=200)=>{let i;return(...s)=>{clearTimeout(i),i=setTimeout(()=>{t.apply(this,s)},e)}};e.dispatch=(t,e,i=null)=>{const s=new CustomEvent(t,{detail:{payload:i},bubbles:!0,cancelable:!0,composed:!1});e.dispatchEvent(s)};e.afterTransition=(t,e)=>{const i=()=>{e(),t.removeEventListener("transitionend",i,!0)},s=window.getComputedStyle(t),o=s.getPropertyValue("transition-duration");"none"!==s.getPropertyValue("transition-property")&&parseFloat(o)>0?t.addEventListener("transitionend",i,!0):e()};e.htmlToElement=t=>{const e=document.createElement("template");return t=t.trim(),e.innerHTML=t,e.content.firstChild};e.classToClassList=(t,e,i=" ",s="add")=>{t.split(i).forEach(t=>{t.trim()&&("add"===s?e.classList.add(t):e.classList.remove(t))})};const o={historyIndex:-1,addHistory(t){this.historyIndex=t},existsInHistory(t){return t>this.historyIndex},clearHistory(){this.historyIndex=-1}};e.menuSearchHistory=o}},e={};var i=function i(s){var o=e[s];if(void 0!==o)return o.exports;var n=e[s]={exports:{}};return t[s].call(n.exports,n,n.exports,i),n.exports}(4375);return i})());
24
+ Object.defineProperty(e,"__esModule",{value:!0}),e.stringToBoolean=e.menuSearchHistory=e.isScrollable=e.isParentOrElementHidden=e.isJson=e.isIpadOS=e.isIOS=e.isFormElement=e.isFocused=e.isEnoughSpace=e.isDirectChild=e.htmlToElement=e.getZIndex=e.getHighestZIndex=e.getClassPropertyAlt=e.getClassProperty=e.dispatch=e.debounce=e.classToClassList=e.afterTransition=void 0;e.stringToBoolean=t=>"true"===t;e.getClassProperty=(t,e,i="")=>(window.getComputedStyle(t).getPropertyValue(e)||i).replace(" ","");e.getClassPropertyAlt=(t,e,i="")=>{let s="";return t.classList.forEach(t=>{t.includes(e)&&(s=t)}),s.match(/:(.*)]/)?s.match(/:(.*)]/)[1]:i};const i=t=>window.getComputedStyle(t).getPropertyValue("z-index");e.getZIndex=i;e.getHighestZIndex=t=>{let e=Number.NEGATIVE_INFINITY;return t.forEach(t=>{let s=i(t);"auto"!==s&&(s=parseInt(s,10),s>e&&(e=s))}),e};e.isDirectChild=(t,e)=>{const i=t.children;for(let t=0;t<i.length;t++)if(i[t]===e)return!0;return!1};e.isEnoughSpace=(t,e,i="auto",s=10,o=null)=>{const l=e.getBoundingClientRect(),n=o?o.getBoundingClientRect():null,a=window.innerHeight,r=n?l.top-n.top:l.top,d=(o?n.bottom:a)-l.bottom,h=t.clientHeight+s;return"bottom"===i?d>=h:"top"===i?r>=h:r>=h||d>=h};e.isFocused=t=>document.activeElement===t;e.isFormElement=t=>t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement;e.isIOS=()=>!!/iPad|iPhone|iPod/.test(navigator.platform)||navigator.maxTouchPoints&&navigator.maxTouchPoints>2&&/MacIntel/.test(navigator.platform);e.isIpadOS=()=>navigator.maxTouchPoints&&navigator.maxTouchPoints>2&&/MacIntel/.test(navigator.platform);e.isJson=t=>{if("string"!=typeof t)return!1;const e=t.trim()[0],i=t.trim().slice(-1);if("{"===e&&"}"===i||"["===e&&"]"===i)try{return JSON.parse(t),!0}catch(t){return!1}return!1};const s=t=>{if(!t)return!1;return"none"===window.getComputedStyle(t).display||s(t.parentElement)};e.isParentOrElementHidden=s;e.isScrollable=t=>{const e=window.getComputedStyle(t),i=e.overflowY,s=e.overflowX,o=("scroll"===i||"auto"===i)&&t.scrollHeight>t.clientHeight,l=("scroll"===s||"auto"===s)&&t.scrollWidth>t.clientWidth;return o||l};e.debounce=(t,e=200)=>{let i;return(...s)=>{clearTimeout(i),i=setTimeout(()=>{t.apply(this,s)},e)}};e.dispatch=(t,e,i=null)=>{const s=new CustomEvent(t,{detail:{payload:i},bubbles:!0,cancelable:!0,composed:!1});e.dispatchEvent(s)};e.afterTransition=(t,e)=>{const i=()=>{e(),t.removeEventListener("transitionend",i,!0)},s=window.getComputedStyle(t),o=s.getPropertyValue("transition-duration");"none"!==s.getPropertyValue("transition-property")&&parseFloat(o)>0?t.addEventListener("transitionend",i,!0):e()};e.htmlToElement=t=>{const e=document.createElement("template");return t=t.trim(),e.innerHTML=t,e.content.firstChild};e.classToClassList=(t,e,i=" ",s="add")=>{t.split(i).forEach(t=>{t.trim()&&("add"===s?e.classList.add(t):e.classList.remove(t))})};const o={historyIndex:-1,addHistory(t){this.historyIndex=t},existsInHistory(t){return t>this.historyIndex},clearHistory(){this.historyIndex=-1}};e.menuSearchHistory=o}},e={};var i=function i(s){var o=e[s];if(void 0!==o)return o.exports;var l=e[s]={exports:{}};return t[s].call(l.exports,l,l.exports,i),l.exports}(4375);return i})());