@preline/select 2.0.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.
Files changed (4) hide show
  1. package/LICENSE +21 -0
  2. package/index.d.ts +156 -0
  3. package/index.js +2 -0
  4. package/package.json +40 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023 Html Stream
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/index.d.ts ADDED
@@ -0,0 +1,156 @@
1
+ export interface ISelectOptions {
2
+ value?: string | string[];
3
+ isOpened?: boolean;
4
+ placeholder?: string;
5
+ hasSearch?: boolean;
6
+ mode?: string;
7
+ viewport?: string;
8
+ toggleTag?: string;
9
+ toggleClasses?: string;
10
+ toggleCountText?: string;
11
+ toggleCountTextMinItems?: number;
12
+ tagsClasses?: string;
13
+ tagsItemTemplate?: string;
14
+ tagsItemClasses?: string;
15
+ tagsInputClasses?: string;
16
+ dropdownTag?: string;
17
+ dropdownClasses?: string;
18
+ dropdownDirectionClasses?: {
19
+ top?: string;
20
+ bottom?: string;
21
+ };
22
+ dropdownSpace: number;
23
+ searchWrapperTemplate?: string;
24
+ searchClasses?: string;
25
+ searchWrapperClasses?: string;
26
+ searchPlaceholder?: string;
27
+ searchNoItemsText?: string;
28
+ searchNoItemsClasses?: string;
29
+ optionTemplate?: string;
30
+ optionTag?: string;
31
+ optionClasses?: string;
32
+ descriptionClasses?: string;
33
+ iconClasses?: string;
34
+ }
35
+ export interface ISelect {
36
+ options?: ISelectOptions;
37
+ open(): void;
38
+ close(): void;
39
+ recalculateDirection(): void;
40
+ }
41
+ export interface IBasePlugin<O, E> {
42
+ el: E;
43
+ options?: O;
44
+ events?: {};
45
+ }
46
+ declare class HSBasePlugin<O, E = HTMLElement> implements IBasePlugin<O, E> {
47
+ el: E;
48
+ options: O;
49
+ events?: any;
50
+ constructor(el: E, options: O, events?: any);
51
+ isIOS(): boolean;
52
+ isIpadOS(): boolean;
53
+ createCollection(collection: any[], element: any): void;
54
+ fireEvent(evt: string, payload?: any): any;
55
+ dispatch(evt: string, element: any, payload?: any): void;
56
+ on(evt: string, cb: Function): void;
57
+ afterTransition(el: HTMLElement, callback: Function): void;
58
+ onTransitionEnd(el: HTMLElement, cb: Function): void;
59
+ getClassProperty(el: HTMLElement, prop: string, val?: string): string;
60
+ getClassPropertyAlt(el: HTMLElement, prop?: string, val?: string): string;
61
+ htmlToElement(html: string): HTMLElement;
62
+ classToClassList(classes: string, target: HTMLElement, splitter?: string): void;
63
+ debounce(func: Function, timeout?: number): (...args: any[]) => void;
64
+ checkIfFormElement(target: HTMLElement): boolean;
65
+ static isEnoughSpace(el: HTMLElement, toggle: HTMLElement, preferredPosition?: "top" | "bottom" | "auto", space?: number, wrapper?: HTMLElement | null): boolean;
66
+ static isParentOrElementHidden(element: any): any;
67
+ }
68
+ declare class HSSelect extends HSBasePlugin<ISelectOptions> implements ISelect {
69
+ value: string | string[] | null;
70
+ private readonly placeholder;
71
+ private readonly hasSearch;
72
+ private readonly mode;
73
+ private readonly viewport;
74
+ isOpened: boolean | null;
75
+ isMultiple: boolean | null;
76
+ isDisabled: boolean | null;
77
+ private readonly toggleTag;
78
+ private readonly toggleClasses;
79
+ private readonly toggleCountText;
80
+ private readonly toggleCountTextMinItems;
81
+ private readonly tagsClasses;
82
+ private readonly tagsItemTemplate;
83
+ private readonly tagsItemClasses;
84
+ private readonly tagsInputClasses;
85
+ private readonly dropdownTag;
86
+ private readonly dropdownClasses;
87
+ private readonly dropdownDirectionClasses;
88
+ dropdownSpace: number | null;
89
+ private readonly searchWrapperTemplate;
90
+ private readonly searchPlaceholder;
91
+ private readonly searchClasses;
92
+ private readonly searchWrapperClasses;
93
+ private readonly optionTag;
94
+ private readonly optionTemplate;
95
+ private readonly optionClasses;
96
+ private readonly descriptionClasses;
97
+ private readonly iconClasses;
98
+ private animationInProcess;
99
+ private wrapper;
100
+ private toggle;
101
+ private toggleTextWrapper;
102
+ private tags;
103
+ private tagsItems;
104
+ private tagsInput;
105
+ private dropdown;
106
+ private searchWrapper;
107
+ private search;
108
+ private selectOptions;
109
+ constructor(el: HTMLElement, options?: ISelectOptions);
110
+ private init;
111
+ private build;
112
+ private buildWrapper;
113
+ private buildToggle;
114
+ private setToggleIcon;
115
+ private setToggleTitle;
116
+ private buildTags;
117
+ private buildTagsItems;
118
+ private buildTagsItem;
119
+ private getItemByValue;
120
+ private setTagsItems;
121
+ private buildTagsInput;
122
+ private buildDropdown;
123
+ private buildSearch;
124
+ private buildOption;
125
+ private onSelectOption;
126
+ private addSelectOption;
127
+ private resetTagsInputField;
128
+ private clearSelections;
129
+ private setNewValue;
130
+ private stringFromValue;
131
+ private selectSingleItem;
132
+ private selectMultipleItems;
133
+ private unselectMultipleItems;
134
+ private searchOptions;
135
+ open(): boolean;
136
+ close(): boolean;
137
+ recalculateDirection(): void;
138
+ static getInstance(target: HTMLElement | string, isInstance?: boolean): HSSelect | {
139
+ id: number;
140
+ element: HSSelect;
141
+ };
142
+ static close(target: HTMLElement | string): void;
143
+ static closeCurrentlyOpened(evtTarget?: HTMLElement | null): void;
144
+ static accessibility(evt: KeyboardEvent): void;
145
+ static onEscape(): void;
146
+ static onArrow(isArrowUp?: boolean): boolean;
147
+ static onTab(isArrowUp?: boolean): boolean;
148
+ static onStartEnd(isStart?: boolean): boolean;
149
+ static onEnter(evt: Event): void;
150
+ }
151
+
152
+ export {
153
+ HSSelect as default,
154
+ };
155
+
156
+ export {};
package/index.js ADDED
@@ -0,0 +1,2 @@
1
+ /*! For license information please see LICENSE */
2
+ !function(t,e){if("object"==typeof exports&&"object"==typeof module)module.exports=e();else if("function"==typeof define&&define.amd)define([],e);else{var s=e();for(var i in s)("object"==typeof exports?exports:t)[i]=s[i]}}(self,(()=>(()=>{"use strict";var t={190:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),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","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","Tab"]},737:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0});var s=function(){function t(t,e,s){this.el=t,this.options=e,this.events=s,this.el=t,this.options=e,this.events={}}return t.prototype.isIOS=function(){return!!/iPad|iPhone|iPod/.test(navigator.platform)||navigator.maxTouchPoints&&navigator.maxTouchPoints>2&&/MacIntel/.test(navigator.platform)},t.prototype.isIpadOS=function(){return navigator.maxTouchPoints&&navigator.maxTouchPoints>2&&/MacIntel/.test(navigator.platform)},t.prototype.createCollection=function(t,e){var s;t.push({id:(null===(s=null==e?void 0:e.el)||void 0===s?void 0:s.id)||t.length+1,element:e})},t.prototype.fireEvent=function(t,e){if(void 0===e&&(e=null),this.events.hasOwnProperty(t))return this.events[t](e)},t.prototype.dispatch=function(t,e,s){void 0===s&&(s=null);var i=new CustomEvent(t,{detail:{payload:s},bubbles:!0,cancelable:!0,composed:!1});e.dispatchEvent(i)},t.prototype.on=function(t,e){this.events[t]=e},t.prototype.afterTransition=function(t,e){var s=function(){e(),t.removeEventListener("transitionend",s,!0)};"all 0s ease 0s"!==window.getComputedStyle(t,null).getPropertyValue("transition")?t.addEventListener("transitionend",s,!0):e()},t.prototype.onTransitionEnd=function(t,e){t.addEventListener("transitionend",(function s(i){i.target===t&&(t.removeEventListener("transitionend",s),e())}))},t.prototype.getClassProperty=function(t,e,s){return void 0===s&&(s=""),(window.getComputedStyle(t).getPropertyValue(e)||s).replace(" ","")},t.prototype.getClassPropertyAlt=function(t,e,s){void 0===s&&(s="");var i="";return t.classList.forEach((function(t){t.includes(e)&&(i=t)})),i.match(/:(.*)]/)?i.match(/:(.*)]/)[1]:s},t.prototype.htmlToElement=function(t){var e=document.createElement("template");return t=t.trim(),e.innerHTML=t,e.content.firstChild},t.prototype.classToClassList=function(t,e,s){void 0===s&&(s=" "),t.split(s).forEach((function(t){return e.classList.add(t)}))},t.prototype.debounce=function(t,e){var s,i=this;return void 0===e&&(e=200),function(){for(var o=[],n=0;n<arguments.length;n++)o[n]=arguments[n];clearTimeout(s),s=setTimeout((function(){t.apply(i,o)}),e)}},t.prototype.checkIfFormElement=function(t){return t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement},t.isEnoughSpace=function(t,e,s,i,o){void 0===s&&(s="auto"),void 0===i&&(i=10),void 0===o&&(o=null);var n=e.getBoundingClientRect(),l=o?o.getBoundingClientRect():null,r=window.innerHeight,a=l?n.top-l.top:n.top,d=(o?l.bottom:r)-n.bottom,c=t.clientHeight+i;return"bottom"===s?d>=c:"top"===s?a>=c:a>=c||d>=c},t.isParentOrElementHidden=function(t){return!!t&&("none"===window.getComputedStyle(t).display||this.isParentOrElementHidden(t.parentElement))},t}();e.default=s,window.HSStaticMethods={afterTransition:function(t,e){var s=function(){e(),t.removeEventListener("transitionend",s,!0)};"all 0s ease 0s"!==window.getComputedStyle(t,null).getPropertyValue("transition")?t.addEventListener("transitionend",s,!0):e()},getClassPropertyAlt:function(t,e,s){void 0===s&&(s="");var i="";return t.classList.forEach((function(t){t.includes(e)&&(i=t)})),i.match(/:(.*)]/)?i.match(/:(.*)]/)[1]:s},getClassProperty:function(t,e,s){return void 0===s&&(s=""),(window.getComputedStyle(t).getPropertyValue(e)||s).replace(" ","")}}},233:function(t,e,s){var i,o=this&&this.__extends||(i=function(t,e){return i=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var s in e)Object.prototype.hasOwnProperty.call(e,s)&&(t[s]=e[s])},i(t,e)},function(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function s(){this.constructor=t}i(t,e),t.prototype=null===e?Object.create(e):(s.prototype=e.prototype,new s)}),n=this&&this.__assign||function(){return n=Object.assign||function(t){for(var e,s=1,i=arguments.length;s<i;s++)for(var o in e=arguments[s])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},n.apply(this,arguments)},l=this&&this.__spreadArray||function(t,e,s){if(s||2===arguments.length)for(var i,o=0,n=e.length;o<n;o++)!i&&o in e||(i||(i=Array.prototype.slice.call(e,0,o)),i[o]=e[o]);return t.concat(i||Array.prototype.slice.call(e))};Object.defineProperty(e,"__esModule",{value:!0});var r=s(737),a=s(190),d=function(t){function e(e,s){var i=t.call(this,e,s)||this,o=e.getAttribute("data-hs-select"),l=o?JSON.parse(o):{},r=n(n({},l),s);return i.value=(null==r?void 0:r.value)||i.el.value||null,i.placeholder=(null==r?void 0:r.placeholder)||"Select...",i.hasSearch=(null==r?void 0:r.hasSearch)||!1,i.mode=(null==r?void 0:r.mode)||"default",i.viewport=void 0!==(null==r?void 0:r.viewport)?document.querySelector(null==r?void 0:r.viewport):null,i.isOpened=Boolean(null==r?void 0:r.isOpened)||!1,i.isMultiple=i.el.hasAttribute("multiple")||!1,i.isDisabled=i.el.hasAttribute("disabled")||!1,i.toggleTag=(null==r?void 0:r.toggleTag)||null,i.toggleClasses=(null==r?void 0:r.toggleClasses)||null,i.toggleCountText=(null==r?void 0:r.toggleCountText)||null,i.toggleCountTextMinItems=(null==r?void 0:r.toggleCountTextMinItems)||1,i.tagsClasses=(null==r?void 0:r.tagsClasses)||null,i.tagsItemTemplate=(null==r?void 0:r.tagsItemTemplate)||null,i.tagsItemClasses=(null==r?void 0:r.tagsItemClasses)||null,i.tagsInputClasses=(null==r?void 0:r.tagsInputClasses)||null,i.dropdownTag=(null==r?void 0:r.dropdownTag)||null,i.dropdownClasses=(null==r?void 0:r.dropdownClasses)||null,i.dropdownDirectionClasses=(null==r?void 0:r.dropdownDirectionClasses)||null,i.dropdownSpace=(null==r?void 0:r.dropdownSpace)||10,i.searchWrapperTemplate=(null==r?void 0:r.searchWrapperTemplate)||null,i.searchWrapperClasses=(null==r?void 0:r.searchWrapperClasses)||"bg-white p-2 sticky top-0",i.searchClasses=(null==r?void 0:r.searchClasses)||"block w-[calc(100%-2rem)] text-sm border-gray-200 rounded-md focus:border-blue-500 focus:ring-blue-500 dark:bg-slate-900 dark:border-gray-700 dark:text-gray-400 py-2 px-3 my-2 mx-4",i.searchPlaceholder=(null==r?void 0:r.searchPlaceholder)||"Search...",i.optionTemplate=(null==r?void 0:r.optionTemplate)||null,i.optionTag=(null==r?void 0:r.optionTag)||null,i.optionClasses=(null==r?void 0:r.optionClasses)||null,i.descriptionClasses=(null==r?void 0:r.descriptionClasses)||null,i.iconClasses=(null==r?void 0:r.iconClasses)||null,i.animationInProcess=!1,i.selectOptions=[],i.init(),i}return o(e,t),e.prototype.init=function(){this.createCollection(window.$hsSelectCollection,this),this.build()},e.prototype.build=function(){var t=this;if(this.el.style.display="none",this.el.children&&Array.from(this.el.children).filter((function(t){return t.value&&""!==t.value})).forEach((function(e){var s=e.getAttribute("data-hs-select-option");t.selectOptions=l(l([],t.selectOptions,!0),[{title:e.textContent,val:e.value,options:s?JSON.parse(s):null}],!1)})),this.isMultiple){var e=Array.from(this.el.options).filter((function(t){return t.selected}));if(e){var s=[];e.forEach((function(t){s.push(t.value)})),this.value=s}}this.buildWrapper(),"tags"===this.mode?this.buildTags():this.buildToggle(),this.buildDropdown()},e.prototype.buildWrapper=function(){this.wrapper=document.createElement("div"),this.wrapper.classList.add("hs-select","relative"),this.el.before(this.wrapper),this.wrapper.append(this.el)},e.prototype.buildToggle=function(){var t,e,s,i=this;this.toggleTextWrapper=document.createElement("span"),this.toggleTextWrapper.classList.add("truncate"),this.toggle=this.htmlToElement(this.toggleTag||"<div></div>"),e=this.toggle.querySelector("[data-icon]"),s=this.toggle.querySelector("[data-title]"),!this.isMultiple&&e&&this.setToggleIcon(),!this.isMultiple&&s&&this.setToggleTitle(),this.isMultiple?this.toggleTextWrapper.innerHTML=this.value.length?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&&this.classToClassList(this.toggleClasses,this.toggle),this.isDisabled&&this.toggle.classList.add("disabled"),this.wrapper&&this.wrapper.append(this.toggle),this.toggle.addEventListener("click",(function(){if(i.isDisabled)return!1;i.isOpened?i.close():i.open()}))},e.prototype.setToggleIcon=function(){var t,e,s=this.toggle.querySelector("[data-icon]");if(s.innerHTML="",s){var i=this.htmlToElement((null===(e=null===(t=this.getItemByValue(this.value))||void 0===t?void 0:t.options)||void 0===e?void 0:e.icon)||"");s.append(i),i?s.classList.remove("hidden"):s.classList.add("hidden")}},e.prototype.setToggleTitle=function(){var t,e=this.toggle.querySelector("[data-title]");if(e.classList.add("truncate"),e.innerHTML="",e){var s=(null===(t=this.getItemByValue(this.value))||void 0===t?void 0:t.title)||this.placeholder;e.innerHTML=s,this.toggle.append(e)}},e.prototype.buildTags=function(){this.tags=document.createElement("div"),this.tags.classList.add("flex"),this.tagsClasses&&this.classToClassList(this.tagsClasses,this.tags),this.buildTagsInput(),this.buildTagsItems(),this.setTagsItems(),this.wrapper&&this.wrapper.append(this.tags)},e.prototype.buildTagsItems=function(){this.tagsItems=document.createElement("div"),this.tagsItems.classList.add("flex","flex-wrap","flex-0","items-center"),this.setTagsItems(),this.tags.append(this.tagsItems)},e.prototype.buildTagsItem=function(t){var e,s,i,o,n,l,r,a=this,d=this.getItemByValue(t),c=document.createElement("div");if(this.tagsItemClasses&&this.classToClassList(this.tagsItemClasses,c),this.tagsItemTemplate&&(o=this.htmlToElement(this.tagsItemTemplate),c.append(o)),null===(e=null==d?void 0:d.options)||void 0===e?void 0:e.icon){var u=this.htmlToElement(null===(s=null==d?void 0:d.options)||void 0===s?void 0:s.icon);(r=o?o.querySelector("[data-icon]"):document.createElement("span")).append(u),o||c.append(r)}o&&o.querySelector("[data-icon]")&&!(null===(i=null==d?void 0:d.options)||void 0===i?void 0:i.icon)&&o.querySelector("[data-icon]").classList.add("hidden"),(n=o?o.querySelector("[data-title]"):document.createElement("span")).textContent=d.title||"",o||c.append(n),o?l=o.querySelector("[data-remove]"):((l=document.createElement("span")).textContent="X",c.append(l)),l.addEventListener("click",(function(){a.value=a.value.filter((function(e){return e!==t})),a.unselectMultipleItems(),a.setTagsItems(),a.selectMultipleItems()})),this.tagsItems.append(c)},e.prototype.getItemByValue=function(t){return this.selectOptions.find((function(e){return e.val===t}))},e.prototype.setTagsItems=function(){var t=this;this.tagsItems.innerHTML="",this.value&&this.value.forEach((function(e){t.buildTagsItem(e)})),this.value.length||(this.tagsInput.placeholder=this.placeholder)},e.prototype.buildTagsInput=function(){var t=this;this.tagsInput=document.createElement("input"),this.tagsInput.placeholder=this.placeholder,this.tagsInputClasses&&this.classToClassList(this.tagsInputClasses,this.tagsInput),this.tagsInput.addEventListener("focus",(function(){return t.open()})),this.tagsInput.addEventListener("input",this.debounce((function(e){return t.searchOptions(e.target.value)}))),this.tagsInput.addEventListener("keydown",(function(e){if("Enter"===e.key){var s=e.target.value;if(t.selectOptions.find((function(t){return t.val===s})))return!1;t.addSelectOption(s,s),t.buildOption(s,s),t.dropdown.querySelector('[data-value="'.concat(s,'"]')).click(),t.resetTagsInputField(),t.close()}})),this.tags.append(this.tagsInput)},e.prototype.buildDropdown=function(){var t=this;this.dropdown=this.htmlToElement(this.dropdownTag||"<div></div>"),this.dropdown.classList.add("absolute","top-full"),this.isOpened||this.dropdown.classList.add("hidden"),this.dropdownClasses&&this.classToClassList(this.dropdownClasses,this.dropdown),this.wrapper&&this.wrapper.append(this.dropdown),this.dropdown&&this.hasSearch&&this.buildSearch(),this.selectOptions&&this.selectOptions.forEach((function(e,s){return t.buildOption(e.title,e.val,e.options,"".concat(s))}))},e.prototype.buildSearch=function(){var t,e=this;this.searchWrapper=this.htmlToElement(this.searchWrapperTemplate||"<div></div>"),this.searchWrapperClasses&&this.classToClassList(this.searchWrapperClasses,this.searchWrapper),t=this.searchWrapper.querySelector("[data-input]"),this.search=this.htmlToElement('<input type="text" />'),this.search.placeholder=this.searchPlaceholder,this.searchClasses&&this.classToClassList(this.searchClasses,this.search),this.search.addEventListener("input",this.debounce((function(t){return e.searchOptions(t.target.value)}))),t?t.append(this.search):this.searchWrapper.append(this.search),this.dropdown.append(this.searchWrapper)},e.prototype.buildOption=function(t,e,s,i){var o=this;void 0===i&&(i="1");var n=null,l=this.htmlToElement(this.optionTag||"<div></div>");if(l.setAttribute("data-value",e),l.setAttribute("data-title-value",t),l.setAttribute("tabIndex",i),l.classList.add("cursor-pointer"),this.optionTemplate&&(n=this.htmlToElement(this.optionTemplate),l.append(n)),n?n.querySelector("[data-title]").textContent=t||"":l.textContent=t||"",s){if(s.icon){var r=this.htmlToElement(s.icon);if(r.classList.add("mw-full"),n)n.querySelector("[data-icon]").append(r);else{var a=this.htmlToElement("<div></div>");this.iconClasses&&this.classToClassList(this.iconClasses,a),a.append(r),l.append(a)}}if(s.description)if(n)n.querySelector("[data-description]").append(s.description);else{var d=this.htmlToElement("<div></div>");d.textContent=s.description,this.descriptionClasses&&this.classToClassList(this.descriptionClasses,d),l.append(d)}}n&&n.querySelector("[data-icon]")&&!s&&!(null==s?void 0:s.icon)&&n.querySelector("[data-icon]").classList.add("hidden"),this.value&&(this.isMultiple?this.value.includes(e):this.value===e)&&l.classList.add("selected"),l.addEventListener("click",(function(){return o.onSelectOption(e)})),this.optionClasses&&this.classToClassList(this.optionClasses,l),this.dropdown&&this.dropdown.append(l)},e.prototype.onSelectOption=function(t){this.clearSelections(),this.isMultiple?(this.value=this.value.includes(t)?Array.from(this.value).filter((function(e){return e!==t})):l(l([],Array.from(this.value),!0),[t],!1),this.selectMultipleItems(),this.setNewValue()):(this.value=t,this.selectSingleItem(),this.setNewValue()),this.fireEvent("change",this.value),this.dispatch("change.hs.select",this.el,this.value),"tags"===this.mode&&this.resetTagsInputField(),this.isMultiple||(this.toggle.querySelector("[data-icon]")&&this.setToggleIcon(),this.toggle.querySelector("[data-title]")&&this.setToggleTitle(),this.close()),this.value.length||"tags"!==this.mode||(this.tagsInput.placeholder=this.placeholder)},e.prototype.addSelectOption=function(t,e,s){this.selectOptions=l(l([],this.selectOptions,!0),[{title:t,val:e,options:s}],!1)},e.prototype.resetTagsInputField=function(){this.tagsInput.value="",this.tagsInput.placeholder="",this.searchOptions("")},e.prototype.clearSelections=function(){Array.from(this.dropdown.children).forEach((function(t){t.classList.contains("selected")&&t.classList.remove("selected")})),Array.from(this.el.children).forEach((function(t){t.selected&&(t.selected=!1)}))},e.prototype.setNewValue=function(){"tags"===this.mode?this.setTagsItems():this.value.length?this.toggleTextWrapper.innerHTML=this.stringFromValue():this.toggleTextWrapper.innerHTML=this.placeholder},e.prototype.stringFromValue=function(){var t=this,e=[];return this.selectOptions.forEach((function(s){t.isMultiple?t.value.includes(s.val)&&e.push(s.title):t.value===s.val&&e.push(s.title)})),this.toggleCountText&&""!==this.toggleCountText&&e.length>=this.toggleCountTextMinItems?"".concat(e.length," ").concat(this.toggleCountText):e.join(", ")},e.prototype.selectSingleItem=function(){var t=this;Array.from(this.el.children).find((function(e){return t.value===e.value})).selected=!0,Array.from(this.dropdown.children).find((function(e){return t.value===e.getAttribute("data-value")})).classList.add("selected")},e.prototype.selectMultipleItems=function(){var t=this;Array.from(this.dropdown.children).filter((function(e){return t.value.includes(e.getAttribute("data-value"))})).forEach((function(t){return t.classList.add("selected")})),Array.from(this.el.children).filter((function(e){return t.value.includes(e.value)})).forEach((function(t){return t.selected=!0}))},e.prototype.unselectMultipleItems=function(){Array.from(this.dropdown.children).forEach((function(t){return t.classList.remove("selected")})),Array.from(this.el.children).forEach((function(t){return t.selected=!1}))},e.prototype.searchOptions=function(t){this.dropdown.querySelectorAll("[data-value]").forEach((function(e){e.getAttribute("data-title-value").toLowerCase().includes(t.toLowerCase())?e.classList.remove("hidden"):e.classList.add("hidden")}))},e.prototype.open=function(){var t=this;if(this.animationInProcess)return!1;this.animationInProcess=!0,this.dropdown.classList.remove("hidden"),this.recalculateDirection(),setTimeout((function(){t.wrapper.classList.add("active"),t.dropdown.classList.add("opened"),t.hasSearch&&t.search.focus(),t.animationInProcess=!1})),this.isOpened=!0},e.prototype.close=function(){var t,e,s,i=this;if(this.animationInProcess)return!1;this.animationInProcess=!0,this.wrapper.classList.remove("active"),this.dropdown.classList.remove("opened","bottom-full","top-full"),(null===(t=this.dropdownDirectionClasses)||void 0===t?void 0:t.bottom)&&this.dropdown.classList.remove(this.dropdownDirectionClasses.bottom),(null===(e=this.dropdownDirectionClasses)||void 0===e?void 0:e.top)&&this.dropdown.classList.remove(this.dropdownDirectionClasses.top),this.dropdown.style.marginTop="",this.dropdown.style.marginBottom="",this.afterTransition(this.dropdown,(function(){i.dropdown.classList.add("hidden"),i.hasSearch&&(i.search.value="",i.search.dispatchEvent(new Event("input",{bubbles:!0})),i.search.blur()),i.animationInProcess=!1})),null===(s=this.dropdown.querySelector(".hs-select-option-highlighted"))||void 0===s||s.classList.remove("hs-select-option-highlighted"),this.isOpened=!1},e.prototype.recalculateDirection=function(){var t,s,i,o;e.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===(s=this.dropdownDirectionClasses)||void 0===s?void 0:s.top)&&this.dropdown.classList.add(this.dropdownDirectionClasses.top),this.dropdown.style.marginTop="".concat(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===(o=this.dropdownDirectionClasses)||void 0===o?void 0:o.bottom)&&this.dropdown.classList.add(this.dropdownDirectionClasses.bottom),this.dropdown.style.marginBottom="".concat(this.dropdownSpace,"px"))},e.getInstance=function(t,e){var s=window.$hsSelectCollection.find((function(e){return e.element.el===("string"==typeof t?document.querySelector(t):t)}));return s?e?s:s.element:null},e.close=function(t){var e=window.$hsSelectCollection.find((function(e){return e.element.el===("string"==typeof t?document.querySelector(t):t)}));e&&e.element.isOpened&&e.element.close()},e.closeCurrentlyOpened=function(t){if(void 0===t&&(t=null),!t.closest(".hs-select.active")){var e=window.$hsSelectCollection.filter((function(t){return t.element.isOpened}))||null;e&&e.forEach((function(t){t.element.close()}))}},e.accessibility=function(t){var e=window.$hsSelectCollection.find((function(t){return t.element.isOpened}));if(e&&a.SELECT_ACCESSIBILITY_KEY_SET.includes(t.code)&&!t.metaKey)switch(console.log(e),console.log("Key code:",t.code),t.code){case"Escape":t.preventDefault(),this.onEscape();break;case"ArrowUp":t.preventDefault(),this.onArrow();break;case"ArrowDown":t.preventDefault(),this.onArrow(!1);break;case"Tab":t.preventDefault(),this.onTab(t.shiftKey);break;case"Home":t.preventDefault(),this.onStartEnd();break;case"End":t.preventDefault(),this.onStartEnd(!1);break;case"Enter":t.preventDefault(),this.onEnter(t)}},e.onEscape=function(){var t=window.$hsSelectCollection.find((function(t){return t.element.isOpened}));t&&t.element.close()},e.onArrow=function(t){void 0===t&&(t=!0);var e=window.$hsSelectCollection.find((function(t){return t.element.isOpened}));if(e){var s=e.element.dropdown;if(!s)return!1;var i=(t?Array.from(s.querySelectorAll(":scope > *")).reverse():Array.from(s.querySelectorAll(":scope > *"))).filter((function(t){return!t.classList.contains("disabled")})),o=s.querySelector(".hs-select-option-highlighted");o||i[0].classList.add("hs-select-option-highlighted");var n=i.findIndex((function(t){return t===o}));n+1<i.length&&n++,i[n].focus(),o&&o.classList.remove("hs-select-option-highlighted"),i[n].classList.add("hs-select-option-highlighted")}},e.onTab=function(t){void 0===t&&(t=!0);var e=window.$hsSelectCollection.find((function(t){return t.element.isOpened}));if(e){var s=e.element.dropdown;if(!s)return!1;var i=(t?Array.from(s.querySelectorAll(":scope > *")).reverse():Array.from(s.querySelectorAll(":scope > *"))).filter((function(t){return!t.classList.contains("disabled")})),o=s.querySelector(".hs-select-option-highlighted");o||i[0].classList.add("hs-select-option-highlighted");var n=i.findIndex((function(t){return t===o}));if(!(n+1<i.length))return o&&o.classList.remove("hs-select-option-highlighted"),e.element.close(),e.element.toggle.focus(),!1;i[++n].focus(),o&&o.classList.remove("hs-select-option-highlighted"),i[n].classList.add("hs-select-option-highlighted")}},e.onStartEnd=function(t){void 0===t&&(t=!0);var e=window.$hsSelectCollection.find((function(t){return t.element.isOpened}));if(e){var s=e.element.dropdown;if(!s)return!1;var i=(t?Array.from(s.querySelectorAll(":scope > *")):Array.from(s.querySelectorAll(":scope > *")).reverse()).filter((function(t){return!t.classList.contains("disabled")})),o=s.querySelector(".hs-select-option-highlighted");i.length&&(i[0].focus(),o&&o.classList.remove("hs-select-option-highlighted"),i[0].classList.add("hs-select-option-highlighted"))}},e.onEnter=function(t){var e=t.target.previousSibling;if(window.$hsSelectCollection.find((function(t){return t.element.el===e}))){var s=window.$hsSelectCollection.find((function(t){return t.element.isOpened})),i=window.$hsSelectCollection.find((function(t){return t.element.el===e}));s.element.close(),i.element.open()}else(i=window.$hsSelectCollection.find((function(t){return t.element.isOpened})))&&i.element.onSelectOption(t.target.dataset.value||"")},e}(r.default);window.addEventListener("load",(function(){window.$hsSelectCollection||(window.$hsSelectCollection=[]),document.querySelectorAll("[data-hs-select]:not(.--prevent-on-load-init)").forEach((function(t){var e=t.getAttribute("data-hs-select"),s=e?JSON.parse(e):{};new d(t,s)})),window.$hsSelectCollection&&(window.addEventListener("click",(function(t){var e=t.target;d.closeCurrentlyOpened(e)})),document.addEventListener("keydown",(function(t){return d.accessibility(t)})))})),document.addEventListener("scroll",(function(){if(!window.$hsSelectCollection)return!1;var t=window.$hsSelectCollection.find((function(t){return t.element.isOpened}));t&&t.element.recalculateDirection()})),t.exports.HSSelect=d,e.default=d}},e={};return function s(i){var o=e[i];if(void 0!==o)return o.exports;var n=e[i]={exports:{}};return t[i].call(n.exports,n,n.exports,s),n.exports}(233)})()));
package/package.json ADDED
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "@preline/select",
3
+ "version": "2.0.0",
4
+ "description": "Preline UI is an open-source set of prebuilt UI components based on the utility-first Tailwind CSS framework.",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "repository": "https://github.com/htmlstreamofficial/preline.git",
8
+ "homepage": "https://preline.co/plugins.html",
9
+ "keywords": [
10
+ "preline",
11
+ "html",
12
+ "css",
13
+ "next",
14
+ "nuxt",
15
+ "vue",
16
+ "react",
17
+ "angular",
18
+ "javascript",
19
+ "typescript",
20
+ "tailwind",
21
+ "tailwind components",
22
+ "tailwind elements",
23
+ "tailwind library",
24
+ "tailwind sections",
25
+ "tailwind css",
26
+ "tailwind ui",
27
+ "tailwind css react",
28
+ "tailwind css vue",
29
+ "tailwind css angular",
30
+ "tailwind css laravel",
31
+ "tailwindcss plugin",
32
+ "tailwindcss plugins",
33
+ "select"
34
+ ],
35
+ "author": "Htmlstream",
36
+ "license": "MIT",
37
+ "publishConfig": {
38
+ "access": "public"
39
+ }
40
+ }