@preline/select 2.0.0 → 2.0.2
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/index.d.ts +35 -19
- package/index.js +17 -2
- package/package.json +3 -28
package/index.d.ts
CHANGED
|
@@ -1,3 +1,13 @@
|
|
|
1
|
+
|
|
2
|
+
export interface ISingleOptionOptions {
|
|
3
|
+
description: string;
|
|
4
|
+
icon: string;
|
|
5
|
+
}
|
|
6
|
+
export interface ISingleOption {
|
|
7
|
+
title: string;
|
|
8
|
+
val: string;
|
|
9
|
+
options?: ISingleOptionOptions | null;
|
|
10
|
+
}
|
|
1
11
|
export interface ISelectOptions {
|
|
2
12
|
value?: string | string[];
|
|
3
13
|
isOpened?: boolean;
|
|
@@ -24,18 +34,22 @@ export interface ISelectOptions {
|
|
|
24
34
|
searchClasses?: string;
|
|
25
35
|
searchWrapperClasses?: string;
|
|
26
36
|
searchPlaceholder?: string;
|
|
27
|
-
|
|
28
|
-
|
|
37
|
+
searchNoResultText?: string | null;
|
|
38
|
+
searchNoResultClasses?: string | null;
|
|
29
39
|
optionTemplate?: string;
|
|
30
40
|
optionTag?: string;
|
|
31
41
|
optionClasses?: string;
|
|
32
42
|
descriptionClasses?: string;
|
|
33
43
|
iconClasses?: string;
|
|
44
|
+
isAddTagOnEnter?: boolean;
|
|
34
45
|
}
|
|
35
46
|
export interface ISelect {
|
|
36
47
|
options?: ISelectOptions;
|
|
48
|
+
destroy(): void;
|
|
37
49
|
open(): void;
|
|
38
50
|
close(): void;
|
|
51
|
+
addOption(items: ISingleOption | ISingleOption[]): void;
|
|
52
|
+
removeOption(values: string | string[]): void;
|
|
39
53
|
recalculateDirection(): void;
|
|
40
54
|
}
|
|
41
55
|
export interface IBasePlugin<O, E> {
|
|
@@ -48,22 +62,13 @@ declare class HSBasePlugin<O, E = HTMLElement> implements IBasePlugin<O, E> {
|
|
|
48
62
|
options: O;
|
|
49
63
|
events?: any;
|
|
50
64
|
constructor(el: E, options: O, events?: any);
|
|
51
|
-
isIOS(): boolean;
|
|
52
|
-
isIpadOS(): boolean;
|
|
53
65
|
createCollection(collection: any[], element: any): void;
|
|
54
66
|
fireEvent(evt: string, payload?: any): any;
|
|
55
|
-
dispatch(evt: string, element: any, payload?: any): void;
|
|
56
67
|
on(evt: string, cb: Function): void;
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
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;
|
|
68
|
+
}
|
|
69
|
+
export interface ICollectionItem<T> {
|
|
70
|
+
id: string | number;
|
|
71
|
+
element: T;
|
|
67
72
|
}
|
|
68
73
|
declare class HSSelect extends HSBasePlugin<ISelectOptions> implements ISelect {
|
|
69
74
|
value: string | string[] | null;
|
|
@@ -90,6 +95,8 @@ declare class HSSelect extends HSBasePlugin<ISelectOptions> implements ISelect {
|
|
|
90
95
|
private readonly searchPlaceholder;
|
|
91
96
|
private readonly searchClasses;
|
|
92
97
|
private readonly searchWrapperClasses;
|
|
98
|
+
private searchNoResultText;
|
|
99
|
+
private searchNoResultClasses;
|
|
93
100
|
private readonly optionTag;
|
|
94
101
|
private readonly optionTemplate;
|
|
95
102
|
private readonly optionClasses;
|
|
@@ -105,7 +112,9 @@ declare class HSSelect extends HSBasePlugin<ISelectOptions> implements ISelect {
|
|
|
105
112
|
private dropdown;
|
|
106
113
|
private searchWrapper;
|
|
107
114
|
private search;
|
|
115
|
+
private searchNoResult;
|
|
108
116
|
private selectOptions;
|
|
117
|
+
private readonly isAddTagOnEnter;
|
|
109
118
|
constructor(el: HTMLElement, options?: ISelectOptions);
|
|
110
119
|
private init;
|
|
111
120
|
private build;
|
|
@@ -122,8 +131,12 @@ declare class HSSelect extends HSBasePlugin<ISelectOptions> implements ISelect {
|
|
|
122
131
|
private buildDropdown;
|
|
123
132
|
private buildSearch;
|
|
124
133
|
private buildOption;
|
|
134
|
+
private destroyOption;
|
|
135
|
+
private buildOriginalOption;
|
|
136
|
+
private destroyOriginalOption;
|
|
125
137
|
private onSelectOption;
|
|
126
138
|
private addSelectOption;
|
|
139
|
+
private removeSelectOption;
|
|
127
140
|
private resetTagsInputField;
|
|
128
141
|
private clearSelections;
|
|
129
142
|
private setNewValue;
|
|
@@ -132,13 +145,16 @@ declare class HSSelect extends HSBasePlugin<ISelectOptions> implements ISelect {
|
|
|
132
145
|
private selectMultipleItems;
|
|
133
146
|
private unselectMultipleItems;
|
|
134
147
|
private searchOptions;
|
|
148
|
+
private eraseToggleIcon;
|
|
149
|
+
private eraseToggleTitle;
|
|
150
|
+
destroy(): void;
|
|
135
151
|
open(): boolean;
|
|
136
152
|
close(): boolean;
|
|
153
|
+
addOption(items: ISingleOption | ISingleOption[]): void;
|
|
154
|
+
removeOption(values: string | string[]): void;
|
|
137
155
|
recalculateDirection(): void;
|
|
138
|
-
static getInstance(target: HTMLElement | string, isInstance?: boolean): HSSelect |
|
|
139
|
-
|
|
140
|
-
element: HSSelect;
|
|
141
|
-
};
|
|
156
|
+
static getInstance(target: HTMLElement | string, isInstance?: boolean): HSSelect | ICollectionItem<HSSelect>;
|
|
157
|
+
static autoInit(): void;
|
|
142
158
|
static close(target: HTMLElement | string): void;
|
|
143
159
|
static closeCurrentlyOpened(evtTarget?: HTMLElement | null): void;
|
|
144
160
|
static accessibility(evt: KeyboardEvent): void;
|
package/index.js
CHANGED
|
@@ -1,2 +1,17 @@
|
|
|
1
|
-
|
|
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)})()));
|
|
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 s=e();for(var o in s)("object"==typeof exports?exports:t)[o]=s[o]}}(self,(()=>(()=>{"use strict";var t={190:(t,e)=>{Object.defineProperty(e,"__esModule",{value:!0}),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","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"],e.COMBO_BOX_ACCESSIBILITY_KEY_SET=["ArrowUp","ArrowLeft","ArrowDown","ArrowRight","Home","End","Escape","Enter"]},737:(t,e)=>{
|
|
2
|
+
/*
|
|
3
|
+
* HSBasePlugin
|
|
4
|
+
* @version: 2.0.3
|
|
5
|
+
* @author: HTMLStream
|
|
6
|
+
* @license: Licensed under MIT (https://preline.co/docs/license.html)
|
|
7
|
+
* Copyright 2023 HTMLStream
|
|
8
|
+
*/
|
|
9
|
+
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.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.on=function(t,e){this.events[t]=e},t}();e.default=s},233:function(t,e,s){
|
|
10
|
+
/*
|
|
11
|
+
* HSSelect
|
|
12
|
+
* @version: 2.0.3
|
|
13
|
+
* @author: HTMLStream
|
|
14
|
+
* @license: Licensed under MIT (https://preline.co/docs/license.html)
|
|
15
|
+
* Copyright 2023 HTMLStream
|
|
16
|
+
*/
|
|
17
|
+
var o,i=this&&this.__extends||(o=function(t,e){return o=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])},o(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}o(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,o=arguments.length;s<o;s++)for(var i in e=arguments[s])Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i]);return t},n.apply(this,arguments)},l=this&&this.__spreadArray||function(t,e,s){if(s||2===arguments.length)for(var o,i=0,n=e.length;i<n;i++)!o&&i in e||(o||(o=Array.prototype.slice.call(e,0,i)),o[i]=e[i]);return t.concat(o||Array.prototype.slice.call(e))};Object.defineProperty(e,"__esModule",{value:!0});var r=s(969),a=s(737),d=s(190),c=function(t){function e(e,s){var o,i=t.call(this,e,s)||this,l=e.getAttribute("data-hs-select"),r=l?JSON.parse(l):{},a=n(n({},r),s);return i.value=(null==a?void 0:a.value)||i.el.value||null,i.placeholder=(null==a?void 0:a.placeholder)||"Select...",i.hasSearch=(null==a?void 0:a.hasSearch)||!1,i.mode=(null==a?void 0:a.mode)||"default",i.viewport=void 0!==(null==a?void 0:a.viewport)?document.querySelector(null==a?void 0:a.viewport):null,i.isOpened=Boolean(null==a?void 0:a.isOpened)||!1,i.isMultiple=i.el.hasAttribute("multiple")||!1,i.isDisabled=i.el.hasAttribute("disabled")||!1,i.toggleTag=(null==a?void 0:a.toggleTag)||null,i.toggleClasses=(null==a?void 0:a.toggleClasses)||null,i.toggleCountText=(null==a?void 0:a.toggleCountText)||null,i.toggleCountTextMinItems=(null==a?void 0:a.toggleCountTextMinItems)||1,i.tagsClasses=(null==a?void 0:a.tagsClasses)||null,i.tagsItemTemplate=(null==a?void 0:a.tagsItemTemplate)||null,i.tagsItemClasses=(null==a?void 0:a.tagsItemClasses)||null,i.tagsInputClasses=(null==a?void 0:a.tagsInputClasses)||null,i.dropdownTag=(null==a?void 0:a.dropdownTag)||null,i.dropdownClasses=(null==a?void 0:a.dropdownClasses)||null,i.dropdownDirectionClasses=(null==a?void 0:a.dropdownDirectionClasses)||null,i.dropdownSpace=(null==a?void 0:a.dropdownSpace)||10,i.searchWrapperTemplate=(null==a?void 0:a.searchWrapperTemplate)||null,i.searchWrapperClasses=(null==a?void 0:a.searchWrapperClasses)||"bg-white p-2 sticky top-0",i.searchClasses=(null==a?void 0:a.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==a?void 0:a.searchPlaceholder)||"Search...",i.searchNoResultText=(null==a?void 0:a.searchNoResultText)||"No options found...",i.searchNoResultClasses=(null==a?void 0:a.searchNoResultClasses)||"px-4 text-sm",i.optionTemplate=(null==a?void 0:a.optionTemplate)||null,i.optionTag=(null==a?void 0:a.optionTag)||null,i.optionClasses=(null==a?void 0:a.optionClasses)||null,i.descriptionClasses=(null==a?void 0:a.descriptionClasses)||null,i.iconClasses=(null==a?void 0:a.iconClasses)||null,i.isAddTagOnEnter=null===(o=null==a?void 0:a.isAddTagOnEnter)||void 0===o||o,i.animationInProcess=!1,i.selectOptions=[],i.init(),i}return i(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:"undefined"!==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,o=this;this.toggleTextWrapper=document.createElement("span"),this.toggleTextWrapper.classList.add("truncate"),this.toggle=(0,r.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&&(0,r.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(o.isDisabled)return!1;o.isOpened?o.close():o.open()}))},e.prototype.setToggleIcon=function(){var t,e,s=this.toggle.querySelector("[data-icon]");if(s.innerHTML="",s){var o=(0,r.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(o),o?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&&(0,r.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,o,i,n,l,a,d=this,c=this.getItemByValue(t),u=document.createElement("div");if(this.tagsItemClasses&&(0,r.classToClassList)(this.tagsItemClasses,u),this.tagsItemTemplate&&(i=(0,r.htmlToElement)(this.tagsItemTemplate),u.append(i)),null===(e=null==c?void 0:c.options)||void 0===e?void 0:e.icon){var p=(0,r.htmlToElement)(null===(s=null==c?void 0:c.options)||void 0===s?void 0:s.icon);(a=i?i.querySelector("[data-icon]"):document.createElement("span")).append(p),i||u.append(a)}i&&i.querySelector("[data-icon]")&&!(null===(o=null==c?void 0:c.options)||void 0===o?void 0:o.icon)&&i.querySelector("[data-icon]").classList.add("hidden"),(n=i?i.querySelector("[data-title]"):document.createElement("span")).textContent=c.title||"",i||u.append(n),i?l=i.querySelector("[data-remove]"):((l=document.createElement("span")).textContent="X",u.append(l)),l.addEventListener("click",(function(){d.value=d.value.filter((function(e){return e!==t})),d.unselectMultipleItems(),d.setTagsItems(),d.selectMultipleItems()})),this.tagsItems.append(u)},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.tagsInput.readOnly=!0),this.value.length||(this.tagsInput.placeholder=this.placeholder,this.tagsInput.readOnly=!1)},e.prototype.buildTagsInput=function(){var t=this;this.tagsInput=document.createElement("input"),this.tagsInput.placeholder=this.placeholder,this.tagsInputClasses&&(0,r.classToClassList)(this.tagsInputClasses,this.tagsInput),this.tagsInput.addEventListener("focus",(function(){return t.open()})),this.tagsInput.addEventListener("input",(0,r.debounce)((function(e){return t.searchOptions(e.target.value)}))),this.tagsInput.addEventListener("keydown",(function(e){if("Enter"===e.key&&t.isAddTagOnEnter){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=(0,r.htmlToElement)(this.dropdownTag||"<div></div>"),this.dropdown.classList.add("absolute","top-full"),this.isOpened||this.dropdown.classList.add("hidden"),this.dropdownClasses&&(0,r.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=(0,r.htmlToElement)(this.searchWrapperTemplate||"<div></div>"),this.searchWrapperClasses&&(0,r.classToClassList)(this.searchWrapperClasses,this.searchWrapper),t=this.searchWrapper.querySelector("[data-input]"),this.search=(0,r.htmlToElement)('<input type="text" />'),this.search.placeholder=this.searchPlaceholder,this.searchClasses&&(0,r.classToClassList)(this.searchClasses,this.search),this.search.addEventListener("input",(0,r.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,o){var i=this;void 0===o&&(o="1");var n=null,l=(0,r.htmlToElement)(this.optionTag||"<div></div>");if(l.setAttribute("data-value",e),l.setAttribute("data-title-value",t),l.setAttribute("tabIndex",o),l.classList.add("cursor-pointer"),this.optionTemplate&&(n=(0,r.htmlToElement)(this.optionTemplate),l.append(n)),n?n.querySelector("[data-title]").textContent=t||"":l.textContent=t||"",s){if(s.icon){var a=(0,r.htmlToElement)(s.icon);if(a.classList.add("mw-full"),n)n.querySelector("[data-icon]").append(a);else{var d=(0,r.htmlToElement)("<div></div>");this.iconClasses&&(0,r.classToClassList)(this.iconClasses,d),d.append(a),l.append(d)}}if(s.description)if(n)n.querySelector("[data-description]").append(s.description);else{var c=(0,r.htmlToElement)("<div></div>");c.textContent=s.description,this.descriptionClasses&&(0,r.classToClassList)(this.descriptionClasses,c),l.append(c)}}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 i.onSelectOption(e)})),this.optionClasses&&(0,r.classToClassList)(this.optionClasses,l),this.dropdown&&this.dropdown.append(l)},e.prototype.destroyOption=function(t){var e=this.dropdown.querySelector('[data-value="'.concat(t,'"]'));if(!e)return!1;e.remove()},e.prototype.buildOriginalOption=function(t,e,s){var o=(0,r.htmlToElement)("<option></option>");o.setAttribute("value",e),o.setAttribute("data-hs-select-option",JSON.stringify(s)),o.innerText=t,this.el.append(o)},e.prototype.destroyOriginalOption=function(t){var e=this.el.querySelector('[value="'.concat(t,'"]'));if(!e)return!1;e.remove()},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),(0,r.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.removeSelectOption=function(t){if(!!!this.selectOptions.some((function(e){return e.val===t})))return!1;this.selectOptions=this.selectOptions.filter((function(e){return e.val!==t}))},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.searchNoResult&&(this.searchNoResult.remove(),this.searchNoResult=null),this.searchNoResult=(0,r.htmlToElement)("<span></span>"),this.searchNoResult.innerText=this.searchNoResultText,(0,r.classToClassList)(this.searchNoResultClasses,this.searchNoResult);var e=this.dropdown.querySelectorAll("[data-value]"),s=!1;e.forEach((function(e){e.getAttribute("data-title-value").toLowerCase().includes(t.toLowerCase())?(e.classList.remove("hidden"),s=!0):e.classList.add("hidden")})),s||this.dropdown.append(this.searchNoResult)},e.prototype.eraseToggleIcon=function(){var t=this.toggle.querySelector("[data-icon]");t&&(t.innerHTML=null,t.classList.add("hidden"))},e.prototype.eraseToggleTitle=function(){var t=this.toggle.querySelector("[data-title]");t?t.innerHTML=this.placeholder:this.toggleTextWrapper.innerHTML=this.placeholder},e.prototype.destroy=function(){var t=this.el.parentElement.parentElement;this.el.classList.remove("hidden"),this.el.style.display="",t.prepend(this.el),t.querySelector(".hs-select").remove(),this.wrapper=null},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,o=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="",(0,r.afterTransition)(this.dropdown,(function(){o.dropdown.classList.add("hidden"),o.hasSearch&&(o.search.value="",o.search.dispatchEvent(new Event("input",{bubbles:!0})),o.search.blur()),o.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.addOption=function(t){var e=this,s="".concat(this.selectOptions.length),o=function(t){var o=t.title,i=t.val,n=t.options;!!e.selectOptions.some((function(t){return t.val===i}))||(e.addSelectOption(o,i,n),e.buildOption(o,i,n,s),e.buildOriginalOption(o,i,n))};Array.isArray(t)?t.forEach((function(t){o(t)})):o(t)},e.prototype.removeOption=function(t){var e=this,s=function(t){!!e.selectOptions.some((function(e){return e.val===t}))&&(e.removeSelectOption(t),e.destroyOption(t),e.destroyOriginalOption(t),e.value===t&&(e.value=null,e.eraseToggleTitle(),e.eraseToggleIcon()))};Array.isArray(t)?t.forEach((function(t){s(t)})):s(t)},e.prototype.recalculateDirection=function(){var t,e,s,o;(0,r.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="".concat(this.dropdownSpace,"px")):(this.dropdown.classList.remove("top-full"),(null===(s=this.dropdownDirectionClasses)||void 0===s?void 0:s.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.autoInit=function(){window.$hsSelectCollection||(window.$hsSelectCollection=[]),document.querySelectorAll("[data-hs-select]:not(.--prevent-on-load-init)").forEach((function(t){if(!window.$hsSelectCollection.find((function(e){var s;return(null===(s=null==e?void 0:e.element)||void 0===s?void 0:s.el)===t}))){var s=t.getAttribute("data-hs-select"),o=s?JSON.parse(s):{};new e(t,o)}})),window.$hsSelectCollection&&(window.addEventListener("click",(function(t){var s=t.target;e.closeCurrentlyOpened(s)})),document.addEventListener("keydown",(function(t){return e.accessibility(t)})))},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&&d.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 o=(t?Array.from(s.querySelectorAll(":scope > *:not(.hidden)")).reverse():Array.from(s.querySelectorAll(":scope > *:not(.hidden)"))).filter((function(t){return!t.classList.contains("disabled")})),i=s.querySelector(".hs-select-option-highlighted");i||o[0].classList.add("hs-select-option-highlighted");var n=o.findIndex((function(t){return t===i}));n+1<o.length&&n++,o[n].focus(),i&&i.classList.remove("hs-select-option-highlighted"),o[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 o=(t?Array.from(s.querySelectorAll(":scope > *:not(.hidden)")).reverse():Array.from(s.querySelectorAll(":scope > *:not(.hidden)"))).filter((function(t){return!t.classList.contains("disabled")})),i=s.querySelector(".hs-select-option-highlighted");i||o[0].classList.add("hs-select-option-highlighted");var n=o.findIndex((function(t){return t===i}));if(!(n+1<o.length))return i&&i.classList.remove("hs-select-option-highlighted"),e.element.close(),e.element.toggle.focus(),!1;o[++n].focus(),i&&i.classList.remove("hs-select-option-highlighted"),o[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 o=(t?Array.from(s.querySelectorAll(":scope > *:not(.hidden)")):Array.from(s.querySelectorAll(":scope > *:not(.hidden)")).reverse()).filter((function(t){return!t.classList.contains("disabled")})),i=s.querySelector(".hs-select-option-highlighted");o.length&&(o[0].focus(),i&&i.classList.remove("hs-select-option-highlighted"),o[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})),o=window.$hsSelectCollection.find((function(t){return t.element.el===e}));s.element.close(),o.element.open()}else{(o=window.$hsSelectCollection.find((function(t){return t.element.isOpened})))&&o.element.onSelectOption(t.target.dataset.value||"")}},e}(a.default);window.addEventListener("load",(function(){c.autoInit()})),document.addEventListener("scroll",(function(){if(!window.$hsSelectCollection)return!1;var t=window.$hsSelectCollection.find((function(t){return t.element.isOpened}));t&&t.element.recalculateDirection()})),"undefined"!=typeof window&&(window.HSSelect=c),e.default=c},969:function(t,e){var s=this;Object.defineProperty(e,"__esModule",{value:!0}),e.menuSearchHistory=e.classToClassList=e.htmlToElement=e.afterTransition=e.dispatch=e.debounce=e.isFormElement=e.isParentOrElementHidden=e.isEnoughSpace=e.isIpadOS=e.isIOS=e.getClassPropertyAlt=e.getClassProperty=void 0;e.getClassProperty=function(t,e,s){return void 0===s&&(s=""),(window.getComputedStyle(t).getPropertyValue(e)||s).replace(" ","")};e.getClassPropertyAlt=function(t,e,s){void 0===s&&(s="");var o="";return t.classList.forEach((function(t){t.includes(e)&&(o=t)})),o.match(/:(.*)]/)?o.match(/:(.*)]/)[1]:s};e.isIOS=function(){return!!/iPad|iPhone|iPod/.test(navigator.platform)||navigator.maxTouchPoints&&navigator.maxTouchPoints>2&&/MacIntel/.test(navigator.platform)};e.isIpadOS=function(){return navigator.maxTouchPoints&&navigator.maxTouchPoints>2&&/MacIntel/.test(navigator.platform)};e.isEnoughSpace=function(t,e,s,o,i){void 0===s&&(s="auto"),void 0===o&&(o=10),void 0===i&&(i=null);var n=e.getBoundingClientRect(),l=i?i.getBoundingClientRect():null,r=window.innerHeight,a=l?n.top-l.top:n.top,d=(i?l.bottom:r)-n.bottom,c=t.clientHeight+o;return"bottom"===s?d>=c:"top"===s?a>=c:a>=c||d>=c};e.isFormElement=function(t){return t instanceof HTMLInputElement||t instanceof HTMLTextAreaElement||t instanceof HTMLSelectElement};var o=function(t){return!!t&&("none"===window.getComputedStyle(t).display||o(t.parentElement))};e.isParentOrElementHidden=o;e.debounce=function(t,e){var o;return void 0===e&&(e=200),function(){for(var i=[],n=0;n<arguments.length;n++)i[n]=arguments[n];clearTimeout(o),o=setTimeout((function(){t.apply(s,i)}),e)}};e.dispatch=function(t,e,s){void 0===s&&(s=null);var o=new CustomEvent(t,{detail:{payload:s},bubbles:!0,cancelable:!0,composed:!1});e.dispatchEvent(o)};e.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()};e.htmlToElement=function(t){var e=document.createElement("template");return t=t.trim(),e.innerHTML=t,e.content.firstChild};e.classToClassList=function(t,e,s){void 0===s&&(s=" "),t.split(s).forEach((function(t){return e.classList.add(t)}))};e.menuSearchHistory={historyIndex:-1,addHistory:function(t){this.historyIndex=t},existsInHistory:function(t){return t>this.historyIndex},clearHistory:function(){this.historyIndex=-1}}}},e={};var s=function s(o){var i=e[o];if(void 0!==i)return i.exports;var n=e[o]={exports:{}};return t[o].call(n.exports,n,n.exports,s),n.exports}(233);return s})()));
|
package/package.json
CHANGED
|
@@ -1,40 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@preline/select",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.2",
|
|
4
4
|
"description": "Preline UI is an open-source set of prebuilt UI components based on the utility-first Tailwind CSS framework.",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"types": "index.d.ts",
|
|
7
7
|
"repository": "https://github.com/htmlstreamofficial/preline.git",
|
|
8
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
|
-
],
|
|
9
|
+
"keywords": ["preline", "html", "css", "next", "nuxt", "vue", "react", "angular", "javascript", "typescript", "tailwind", "tailwind components", "tailwind elements", "tailwind library", "tailwind sections", "tailwind css", "tailwind ui", "tailwind css react", "tailwind css vue", "tailwind css angular", "tailwind css laravel", "tailwindcss plugin", "tailwindcss plugins", "accordion"],
|
|
35
10
|
"author": "Htmlstream",
|
|
36
11
|
"license": "MIT",
|
|
37
12
|
"publishConfig": {
|
|
38
13
|
"access": "public"
|
|
39
14
|
}
|
|
40
|
-
}
|
|
15
|
+
}
|