selectyc 0.0.23 → 0.0.24

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/dist/selectyc.js CHANGED
@@ -59,7 +59,7 @@ class h {
59
59
  #m;
60
60
  #o;
61
61
  #n = !1;
62
- #w = !1;
62
+ #v = !1;
63
63
  #g = !1;
64
64
  #S = "";
65
65
  #x = '<svg class="w-5 h-5 text-gray-900 dark:text-gray-400" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m19 9-7 7-7-7"/></svg>';
@@ -133,10 +133,10 @@ class h {
133
133
  this.#E(), this.#s.addEventListener("click", (t) => {
134
134
  if (!this.disabled) {
135
135
  if (t.target.classList.contains("remove-tag")) {
136
- this.#B(t.target.getAttribute("data-value")), this.onUnselect !== void 0 && this.onUnselect(t.target.getAttribute("data-value"), this), this.#n && this.#a(), this.#y();
136
+ this.#B(t.target.getAttribute("data-value")), this.onUnselect !== void 0 && this.onUnselect(t.target.getAttribute("data-value"), this), this.#n && this.#a(), this.#w();
137
137
  return;
138
138
  }
139
- this.#n ? this.#a() : this.#y();
139
+ this.#n ? this.#a() : this.#w();
140
140
  }
141
141
  }), document.addEventListener("click", (t) => {
142
142
  !this.#r.contains(t.target) && !this.#e.contains(t.target) && !t.target.classList.contains("remove-tag") && this.#a();
@@ -168,7 +168,7 @@ class h {
168
168
  }
169
169
  #N() {
170
170
  const t = document.createElement("input");
171
- return t.type = "text", t.required = this.#w, t.tabIndex = -1, t.style.position = "absolute", t.style.opacity = "0", t.style.pointerEvents = "none", t.style.height = "0", t.style.width = "0", t.style.left = "50%", t.value = this.#t.length === 0 ? "" : this.#t[0].text, this.#m = t, t;
171
+ return t.type = "text", t.required = this.#v, t.tabIndex = -1, t.style.position = "absolute", t.style.opacity = "0", t.style.pointerEvents = "none", t.style.height = "0", t.style.width = "0", t.style.left = "50%", t.value = this.#t.length === 0 ? "" : this.#t[0].text, this.#m = t, t;
172
172
  }
173
173
  #O() {
174
174
  const t = document.createElement("div");
@@ -193,13 +193,13 @@ class h {
193
193
  #h(t) {
194
194
  const e = document.createElement("div");
195
195
  e.className = "select-option", e.setAttribute("data-value", t.id), e.textContent = t.text, this.#e.appendChild(e), e.addEventListener("click", () => {
196
- t.id !== "sin_resultados" && (this.#T(t.text, t.id), this.onSelect !== void 0 && this.onSelect(t.id, this), this.#a());
196
+ t.id !== "sin_resultados" && (this.#R(t.text, t.id), this.onSelect !== void 0 && this.onSelect(t.id, this), this.#a());
197
197
  });
198
198
  }
199
199
  // Functions
200
200
  #M() {
201
201
  const t = document.getElementById(this.id);
202
- this.name = t.name, this.#w = t.required, this.rootClassName = t.className, this.disabled = t.disabled, Array.from(t.options).forEach((e) => {
202
+ this.name = t.name, this.#v = t.required, this.rootClassName = t.className, this.disabled = t.disabled, Array.from(t.options).forEach((e) => {
203
203
  if (e.outerHTML.includes("selected")) {
204
204
  const s = e.text, i = this.#c(e.value);
205
205
  this.isMultiple ? this.#t.push({ value: i, text: s }) : this.#t[0] = { value: i, text: s };
@@ -207,8 +207,8 @@ class h {
207
207
  this.#p.push({ id: this.#c(e.value), text: e.text }), this.data = this.#p;
208
208
  });
209
209
  }
210
- #y() {
211
- if (this.filter = null, this.#i.value = null, this.#n)
210
+ #w() {
211
+ if (this.filter = null, this.searchInputActive && (this.#i.value = null), this.#n)
212
212
  return;
213
213
  this.#n = !0, this.#s.classList.remove(`round${this.bodyRound}`), this.#s.classList.add(`round${this.bodyRound}t`);
214
214
  const t = this.#r.getBoundingClientRect();
@@ -217,7 +217,7 @@ class h {
217
217
  #a() {
218
218
  this.#n && (this.#n = !1, this.#e.innerHTML = "", this.#e.style.display = "none", this.searchInputActive && (this.#i.style.display = "none"), this.#s.classList.add(`round${this.bodyRound}`));
219
219
  }
220
- async #v() {
220
+ async #y() {
221
221
  if (this.RS === void 0)
222
222
  return this.data;
223
223
  let t = { records: this.records, filter: this.filter };
@@ -230,30 +230,30 @@ class h {
230
230
  }
231
231
  async #b() {
232
232
  this.#h({ id: "loading", text: "cargando ..." }), this.records = 10 + this.#t.length, this.#g = !1;
233
- let t = await this.#v();
233
+ let t = await this.#y();
234
234
  const e = this.#t.map((s) => s.value);
235
235
  this.#e.lastChild.dataset.value === "loading" && this.#e.removeChild(this.#e.lastChild), t.forEach((s) => {
236
236
  s.text.toLowerCase().includes(this.#S.toLowerCase()) && !e.includes(s.id) && this.#h(s);
237
237
  }), this.#e.hasChildNodes() || this.#h({ id: "sin_resultados", text: "sin resultados ..." });
238
238
  }
239
- async #R() {
239
+ async #A() {
240
240
  const t = this.#t.map((a) => a.value);
241
241
  let e = this.filter === null ? "" : this.filter, s = this.data.map((a) => a.id);
242
242
  this.records = this.records + 10 + this.#t.length;
243
- let i = await this.#v();
243
+ let i = await this.#y();
244
244
  this.#e.lastChild.dataset.value === "loading" && this.#e.removeChild(this.#e.lastChild);
245
245
  const n = this.#e.lastChild.dataset.value;
246
246
  i.forEach((a) => {
247
247
  a.text.toLowerCase().includes(e.toLowerCase()) && !t.includes(a.id) && !s.includes(a.id) && this.#h(a);
248
248
  }), this.#g = n === this.#e.lastChild.dataset.value;
249
249
  }
250
- #T(t, e) {
250
+ #R(t, e) {
251
251
  this.#t.find((i) => i.value === e) || (this.isMultiple || (this.#t = []), this.#t.push({ text: t, value: e })), this.#d(e);
252
252
  }
253
253
  #d(t) {
254
- this.onChange !== void 0 && this.onChange(t, this), this.isMultiple ? this.#C() : this.#A();
254
+ this.onChange !== void 0 && this.onChange(t, this), this.isMultiple ? this.#C() : this.#T();
255
255
  }
256
- #A() {
256
+ #T() {
257
257
  this.#l.value = null, this.#m.value = null, this.#l.value = this.#t.length > 0 ? this.#t[0].text : null, this.#m.value = this.#t.length > 0 ? this.#t[0].text : null, this.#l.placeholder = this.singleLabel, this.#u.value = this.#t.length > 0 ? this.#t[0].value : null;
258
258
  const t = this.#l.parentNode, e = t.firstChild;
259
259
  if (e.className === "remove-tag" && e.remove(), !this.clearButton || this.#t.length <= 0)
@@ -276,7 +276,7 @@ class h {
276
276
  }
277
277
  #k(t) {
278
278
  const { scrollTop: e, scrollHeight: s, clientHeight: i } = this.#e;
279
- t.target.lastChild !== null && (t.target.lastChild.dataset.value === "loading" || this.#g || e + (i + 1) >= s && (this.#h({ id: "loading", text: "cargando ..." }), this.#R()));
279
+ t.target.lastChild !== null && (t.target.lastChild.dataset.value === "loading" || this.#g || e + (i + 1) >= s && (this.#h({ id: "loading", text: "cargando ..." }), this.#A()));
280
280
  }
281
281
  #c(t) {
282
282
  return !isNaN(t) && !isNaN(parseFloat(t)) ? parseInt(t) : t;
@@ -1 +1 @@
1
- (function(h,a){typeof exports=="object"&&typeof module<"u"?a(exports):typeof define=="function"&&define.amd?define(["exports"],a):(h=typeof globalThis<"u"?globalThis:h||self,a(h.selectyc={}))})(this,function(h){"use strict";class a{constructor(t){this.route=t}static make(t){return new a(t)}setMethod(t){return this.method=t,this}getMethod(){return this.method===void 0?"POST":this.method}setData(t){return this.data=t,this}addData(t){if(this.data===void 0)return this.setData(t);for(const e in t)this.data[e]=t[e];return this}setFun(t){return this.fun=t,this}async go(){try{const t={method:this.getMethod(),headers:{"X-CSRF-TOKEN":window.CSRF_TOKEN,Accept:"application/json"}};this.data!==void 0&&(t.body=this.data,Object.prototype.toString.call(this.data)!=="[object FormData]"&&(t.body=JSON.stringify(this.data),t.headers["Content-Type"]="application/json"));const e=await fetch(this.route,t);if(!e.ok){const s=await e.json();throw new Error(s.message)}return this.fun===void 0?await e.json():await this.fun(e)}catch(t){window.toastNotification.setType(!1).show(t.message)}}}class d{#t=[];#u;#p=[];#r;#f;#s;#e;#i;#a;#m;#o;#n=!1;#y=!1;#g=!1;#S="";#x='<svg class="w-5 h-5 text-gray-900 dark:text-gray-400" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m19 9-7 7-7-7"/></svg>';constructor(t){if(window.selects===void 0&&(window.selects=[]),window.selects[t]!==void 0)return window.selects[t];this.id=t,this.name,this.data=[],this.isMultiple=!1,this.clearButton=!1,this.singleLabel=" ",this.records=10,this.filter=null,this.bodyRound="",this.width="100%",this.searchInputActive=!0,this.bodyData=null,this.boxOverflow="horizontal",this.disabled=!1,window.selects[t]=this}static set(t){return new d(t)}setData(t){return this.data=t,this}setMultiple(t="horizontal"){return this.isMultiple=!0,this.boxOverflow=t,this}setClearButton(){return this.clearButton=!0,this}setSelectedOptions(t){this.#t=t,this.#d(t)}getSelectedOptions(){return this.#t}getSelectedOption(){return this.#t[0]}getOptions(){return this.data}setSingleLabel(t){return this.singleLabel=t,this}setBodyRound(t){return this.bodyRound=`-${t}`,this}setRS(t){return this.RS=t,this}setBodyData(t){return this.bodyData=t,this}desactiveSearchInput(){return this.searchInputActive=!1,this}addOption(t){this.data.push(t)}setWidth(t){return this.width=t,this}setOnSelect(t){return this.onSelect=t,this}setOnUnselect(t){return this.onUnselect=t,this}setOnChange(t){return this.onChange=t,this}cleanSelection(){const t=this.#t;this.#t=[],this.#d(t)}setDisableSelect(t){return this.disabled=t,this}#D(){this.#E(),this.#s.addEventListener("click",t=>{if(!this.disabled){if(t.target.classList.contains("remove-tag")){this.#B(t.target.getAttribute("data-value")),this.onUnselect!==void 0&&this.onUnselect(t.target.getAttribute("data-value"),this),this.#n&&this.#l(),this.#v();return}this.#n?this.#l():this.#v()}}),document.addEventListener("click",t=>{!this.#r.contains(t.target)&&!this.#e.contains(t.target)&&!t.target.classList.contains("remove-tag")&&this.#l()}),window.onresize=()=>{this.#l()},window.addEventListener("scroll",()=>{this.#l()}),this.isMultiple&&this.#C()}#E(){this.#I();const t=document.createElement("div");t.className="main-div-selectyc",t.style.width=this.width,t.id=`selectyc_main_div_${this.id}`;const e=document.createElement("div");e.className="custom-multiselect";let s=document.createElement("div");s.className="selected-items round"+this.bodyRound,s.tabIndex=0,s.classList.add(this.boxOverflow==="horizontal"?"horizontal-overflow":"vertical-overflow"),this.isMultiple||(s=this.#L(s)),e.appendChild(s),e.appendChild(this.#O()),t.appendChild(e);const i=document.getElementById(this.id),n=document.createElement("input");n.name=i.name,n.setAttribute("data-id",i.id),this.rootClassName!==""&&(n.className=i.className),n.style.display="none";let l=i.parentNode;t.appendChild(n),l.replaceChild(t,i),this.#u=n,this.#f=s,this.#r=e,this.#s=this.#r.querySelector(".selected-items"),!this.isMultiple&&this.#t.length>0&&(this.#u.value=this.#t[0].value)}#L(t){const e=document.createElement("input");e.className="custom-single-select",e.id=`selectyc_text_box_${this.id}`,e.placeholder=this.singleLabel,e.value=this.#t.length===0?null:this.#t[0].text,e.readOnly=!0;const s=document.createElement("div");return s.innerHTML=this.#x,t.appendChild(this.#N()),t.appendChild(e),t.appendChild(s),this.#a=e,t}#N(){const t=document.createElement("input");return t.type="text",t.required=this.#y,t.tabIndex=-1,t.style.position="absolute",t.style.opacity="0",t.style.pointerEvents="none",t.style.height="0",t.style.width="0",t.style.left="50%",t.value=this.#t.length===0?"":this.#t[0].text,this.#m=t,t}#O(){const t=document.createElement("div");t.setAttribute("style","position:fixed; z-index:999;");const e=document.createElement("div");e.setAttribute("style","position:absolute;");const s=document.createElement("div");s.className="global-dropdown",this.searchInputActive&&e.appendChild(this.#M());let i;return s.addEventListener("scroll",n=>{i&&clearTimeout(i),i=setTimeout(()=>{this.#k(n)},70)}),e.appendChild(s),this.#e=s,this.#o=e,t.appendChild(e),t}#M(){const t=document.createElement("input");return t.type="text",t.id="selectyc_search_input",t.className="search-input",t.placeholder="Buscar...",t.addEventListener("input",()=>{this.filter=t.value,this.#e.innerHTML="",this.#b()}),this.#i=t,t}#h(t){const e=document.createElement("div");e.className="select-option",e.setAttribute("data-value",t.id),e.textContent=t.text,this.#e.appendChild(e),e.addEventListener("click",()=>{t.id!=="sin_resultados"&&(this.#R(t.text,t.id),this.onSelect!==void 0&&this.onSelect(t.id,this),this.#l())})}#I(){const t=document.getElementById(this.id);this.name=t.name,this.#y=t.required,this.rootClassName=t.className,this.disabled=t.disabled,Array.from(t.options).forEach(e=>{if(e.outerHTML.includes("selected")){const s=e.text,i=this.#c(e.value);this.isMultiple?this.#t.push({value:i,text:s}):this.#t[0]={value:i,text:s}}this.#p.push({id:this.#c(e.value),text:e.text}),this.data=this.#p})}#v(){if(this.filter=null,this.#i.value=null,this.#n)return;this.#n=!0,this.#s.classList.remove(`round${this.bodyRound}`),this.#s.classList.add(`round${this.bodyRound}t`);const t=this.#r.getBoundingClientRect();this.#o.style.position="fixed",this.#o.style.top=t.bottom+"px",this.#o.style.left=t.left+"px",this.#e.style.width=t.width+"px",this.#e.style.display="block",this.searchInputActive&&(this.#i.style.display="block",this.#i.style.width=t.width+"px",this.#i.focus()),this.#b()}#l(){this.#n&&(this.#n=!1,this.#e.innerHTML="",this.#e.style.display="none",this.searchInputActive&&(this.#i.style.display="none"),this.#s.classList.add(`round${this.bodyRound}`))}async#w(){if(this.RS===void 0)return this.data;let t={records:this.records,filter:this.filter};if(typeof this.bodyData=="function"){const i=this.bodyData();t={...t,...i}}else this.bodyData!==null&&(t={...t,...this.bodyData});const e=await a.make(this.RS).addData(t).setMethod("POST").go(),s=Array.isArray(e)?e:e.data;return this.data=Array.from(new Map([...this.#p,...s].map(i=>[i.id,i])).values()),this.data}async#b(){this.#h({id:"loading",text:"cargando ..."}),this.records=10+this.#t.length,this.#g=!1;let t=await this.#w();const e=this.#t.map(s=>s.value);this.#e.lastChild.dataset.value==="loading"&&this.#e.removeChild(this.#e.lastChild),t.forEach(s=>{s.text.toLowerCase().includes(this.#S.toLowerCase())&&!e.includes(s.id)&&this.#h(s)}),this.#e.hasChildNodes()||this.#h({id:"sin_resultados",text:"sin resultados ..."})}async#T(){const t=this.#t.map(l=>l.value);let e=this.filter===null?"":this.filter,s=this.data.map(l=>l.id);this.records=this.records+10+this.#t.length;let i=await this.#w();this.#e.lastChild.dataset.value==="loading"&&this.#e.removeChild(this.#e.lastChild);const n=this.#e.lastChild.dataset.value;i.forEach(l=>{l.text.toLowerCase().includes(e.toLowerCase())&&!t.includes(l.id)&&!s.includes(l.id)&&this.#h(l)}),this.#g=n===this.#e.lastChild.dataset.value}#R(t,e){this.#t.find(i=>i.value===e)||(this.isMultiple||(this.#t=[]),this.#t.push({text:t,value:e})),this.#d(e)}#d(t){this.onChange!==void 0&&this.onChange(t,this),this.isMultiple?this.#C():this.#A()}#A(){this.#a.value=null,this.#m.value=null,this.#a.value=this.#t.length>0?this.#t[0].text:null,this.#m.value=this.#t.length>0?this.#t[0].text:null,this.#a.placeholder=this.singleLabel,this.#u.value=this.#t.length>0?this.#t[0].value:null;const t=this.#a.parentNode,e=t.firstChild;if(e.className==="remove-tag"&&e.remove(),!this.clearButton||this.#t.length<=0)return;const s=document.createElement("span");s.dataset.value=this.#t[0].value,s.innerHTML="x",s.className="remove-tag",t.insertBefore(s,t.firstChild)}#C(){if(this.#s.innerHTML="",this.#t.length<=0){this.#s.appendChild(document.createElement("div"));return}this.#t.forEach(({text:t,value:e})=>{const s=document.createElement("div");s.className="selected-tag",s.innerHTML=`${t} <span class="remove-tag" data-value="${e}">x</span>`,this.#s.appendChild(s)})}#B(t){this.#t=this.#t.filter(e=>this.#c(e.value)!==this.#c(t)),this.#d(t)}#k(t){const{scrollTop:e,scrollHeight:s,clientHeight:i}=this.#e;t.target.lastChild!==null&&(t.target.lastChild.dataset.value==="loading"||this.#g||e+(i+1)>=s&&(this.#h({id:"loading",text:"cargando ..."}),this.#T()))}#c(t){return!isNaN(t)&&!isNaN(parseFloat(t))?parseInt(t):t}async render(){const t=document.getElementById(this.id),e=t===null?!1:t.outerHTML.includes("<select");this.#f===void 0&&t!==null||e?this.#D():this.#f!==void 0&&this.#d()}}h.selectyc=d,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
1
+ (function(h,l){typeof exports=="object"&&typeof module<"u"?l(exports):typeof define=="function"&&define.amd?define(["exports"],l):(h=typeof globalThis<"u"?globalThis:h||self,l(h.selectyc={}))})(this,function(h){"use strict";class l{constructor(t){this.route=t}static make(t){return new l(t)}setMethod(t){return this.method=t,this}getMethod(){return this.method===void 0?"POST":this.method}setData(t){return this.data=t,this}addData(t){if(this.data===void 0)return this.setData(t);for(const e in t)this.data[e]=t[e];return this}setFun(t){return this.fun=t,this}async go(){try{const t={method:this.getMethod(),headers:{"X-CSRF-TOKEN":window.CSRF_TOKEN,Accept:"application/json"}};this.data!==void 0&&(t.body=this.data,Object.prototype.toString.call(this.data)!=="[object FormData]"&&(t.body=JSON.stringify(this.data),t.headers["Content-Type"]="application/json"));const e=await fetch(this.route,t);if(!e.ok){const s=await e.json();throw new Error(s.message)}return this.fun===void 0?await e.json():await this.fun(e)}catch(t){window.toastNotification.setType(!1).show(t.message)}}}class d{#t=[];#u;#p=[];#r;#f;#s;#e;#i;#l;#m;#o;#n=!1;#y=!1;#g=!1;#S="";#x='<svg class="w-5 h-5 text-gray-900 dark:text-gray-400" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m19 9-7 7-7-7"/></svg>';constructor(t){if(window.selects===void 0&&(window.selects=[]),window.selects[t]!==void 0)return window.selects[t];this.id=t,this.name,this.data=[],this.isMultiple=!1,this.clearButton=!1,this.singleLabel=" ",this.records=10,this.filter=null,this.bodyRound="",this.width="100%",this.searchInputActive=!0,this.bodyData=null,this.boxOverflow="horizontal",this.disabled=!1,window.selects[t]=this}static set(t){return new d(t)}setData(t){return this.data=t,this}setMultiple(t="horizontal"){return this.isMultiple=!0,this.boxOverflow=t,this}setClearButton(){return this.clearButton=!0,this}setSelectedOptions(t){this.#t=t,this.#d(t)}getSelectedOptions(){return this.#t}getSelectedOption(){return this.#t[0]}getOptions(){return this.data}setSingleLabel(t){return this.singleLabel=t,this}setBodyRound(t){return this.bodyRound=`-${t}`,this}setRS(t){return this.RS=t,this}setBodyData(t){return this.bodyData=t,this}desactiveSearchInput(){return this.searchInputActive=!1,this}addOption(t){this.data.push(t)}setWidth(t){return this.width=t,this}setOnSelect(t){return this.onSelect=t,this}setOnUnselect(t){return this.onUnselect=t,this}setOnChange(t){return this.onChange=t,this}cleanSelection(){const t=this.#t;this.#t=[],this.#d(t)}setDisableSelect(t){return this.disabled=t,this}#D(){this.#E(),this.#s.addEventListener("click",t=>{if(!this.disabled){if(t.target.classList.contains("remove-tag")){this.#B(t.target.getAttribute("data-value")),this.onUnselect!==void 0&&this.onUnselect(t.target.getAttribute("data-value"),this),this.#n&&this.#a(),this.#v();return}this.#n?this.#a():this.#v()}}),document.addEventListener("click",t=>{!this.#r.contains(t.target)&&!this.#e.contains(t.target)&&!t.target.classList.contains("remove-tag")&&this.#a()}),window.onresize=()=>{this.#a()},window.addEventListener("scroll",()=>{this.#a()}),this.isMultiple&&this.#C()}#E(){this.#M();const t=document.createElement("div");t.className="main-div-selectyc",t.style.width=this.width,t.id=`selectyc_main_div_${this.id}`;const e=document.createElement("div");e.className="custom-multiselect";let s=document.createElement("div");s.className="selected-items round"+this.bodyRound,s.tabIndex=0,s.classList.add(this.boxOverflow==="horizontal"?"horizontal-overflow":"vertical-overflow"),this.isMultiple||(s=this.#L(s)),e.appendChild(s),e.appendChild(this.#O()),t.appendChild(e);const i=document.getElementById(this.id),n=document.createElement("input");n.name=i.name,n.setAttribute("data-id",i.id),this.rootClassName!==""&&(n.className=i.className),n.style.display="none";let a=i.parentNode;t.appendChild(n),a.replaceChild(t,i),this.#u=n,this.#f=s,this.#r=e,this.#s=this.#r.querySelector(".selected-items"),!this.isMultiple&&this.#t.length>0&&(this.#u.value=this.#t[0].value)}#L(t){const e=document.createElement("input");e.className="custom-single-select",e.id=`selectyc_text_box_${this.id}`,e.placeholder=this.singleLabel,e.value=this.#t.length===0?null:this.#t[0].text,e.readOnly=!0;const s=document.createElement("div");return s.innerHTML=this.#x,t.appendChild(this.#N()),t.appendChild(e),t.appendChild(s),this.#l=e,t}#N(){const t=document.createElement("input");return t.type="text",t.required=this.#y,t.tabIndex=-1,t.style.position="absolute",t.style.opacity="0",t.style.pointerEvents="none",t.style.height="0",t.style.width="0",t.style.left="50%",t.value=this.#t.length===0?"":this.#t[0].text,this.#m=t,t}#O(){const t=document.createElement("div");t.setAttribute("style","position:fixed; z-index:999;");const e=document.createElement("div");e.setAttribute("style","position:absolute;");const s=document.createElement("div");s.className="global-dropdown",this.searchInputActive&&e.appendChild(this.#I());let i;return s.addEventListener("scroll",n=>{i&&clearTimeout(i),i=setTimeout(()=>{this.#k(n)},70)}),e.appendChild(s),this.#e=s,this.#o=e,t.appendChild(e),t}#I(){const t=document.createElement("input");return t.type="text",t.id="selectyc_search_input",t.className="search-input",t.placeholder="Buscar...",t.addEventListener("input",()=>{this.filter=t.value,this.#e.innerHTML="",this.#b()}),this.#i=t,t}#h(t){const e=document.createElement("div");e.className="select-option",e.setAttribute("data-value",t.id),e.textContent=t.text,this.#e.appendChild(e),e.addEventListener("click",()=>{t.id!=="sin_resultados"&&(this.#A(t.text,t.id),this.onSelect!==void 0&&this.onSelect(t.id,this),this.#a())})}#M(){const t=document.getElementById(this.id);this.name=t.name,this.#y=t.required,this.rootClassName=t.className,this.disabled=t.disabled,Array.from(t.options).forEach(e=>{if(e.outerHTML.includes("selected")){const s=e.text,i=this.#c(e.value);this.isMultiple?this.#t.push({value:i,text:s}):this.#t[0]={value:i,text:s}}this.#p.push({id:this.#c(e.value),text:e.text}),this.data=this.#p})}#v(){if(this.filter=null,this.searchInputActive&&(this.#i.value=null),this.#n)return;this.#n=!0,this.#s.classList.remove(`round${this.bodyRound}`),this.#s.classList.add(`round${this.bodyRound}t`);const t=this.#r.getBoundingClientRect();this.#o.style.position="fixed",this.#o.style.top=t.bottom+"px",this.#o.style.left=t.left+"px",this.#e.style.width=t.width+"px",this.#e.style.display="block",this.searchInputActive&&(this.#i.style.display="block",this.#i.style.width=t.width+"px",this.#i.focus()),this.#b()}#a(){this.#n&&(this.#n=!1,this.#e.innerHTML="",this.#e.style.display="none",this.searchInputActive&&(this.#i.style.display="none"),this.#s.classList.add(`round${this.bodyRound}`))}async#w(){if(this.RS===void 0)return this.data;let t={records:this.records,filter:this.filter};if(typeof this.bodyData=="function"){const i=this.bodyData();t={...t,...i}}else this.bodyData!==null&&(t={...t,...this.bodyData});const e=await l.make(this.RS).addData(t).setMethod("POST").go(),s=Array.isArray(e)?e:e.data;return this.data=Array.from(new Map([...this.#p,...s].map(i=>[i.id,i])).values()),this.data}async#b(){this.#h({id:"loading",text:"cargando ..."}),this.records=10+this.#t.length,this.#g=!1;let t=await this.#w();const e=this.#t.map(s=>s.value);this.#e.lastChild.dataset.value==="loading"&&this.#e.removeChild(this.#e.lastChild),t.forEach(s=>{s.text.toLowerCase().includes(this.#S.toLowerCase())&&!e.includes(s.id)&&this.#h(s)}),this.#e.hasChildNodes()||this.#h({id:"sin_resultados",text:"sin resultados ..."})}async#T(){const t=this.#t.map(a=>a.value);let e=this.filter===null?"":this.filter,s=this.data.map(a=>a.id);this.records=this.records+10+this.#t.length;let i=await this.#w();this.#e.lastChild.dataset.value==="loading"&&this.#e.removeChild(this.#e.lastChild);const n=this.#e.lastChild.dataset.value;i.forEach(a=>{a.text.toLowerCase().includes(e.toLowerCase())&&!t.includes(a.id)&&!s.includes(a.id)&&this.#h(a)}),this.#g=n===this.#e.lastChild.dataset.value}#A(t,e){this.#t.find(i=>i.value===e)||(this.isMultiple||(this.#t=[]),this.#t.push({text:t,value:e})),this.#d(e)}#d(t){this.onChange!==void 0&&this.onChange(t,this),this.isMultiple?this.#C():this.#R()}#R(){this.#l.value=null,this.#m.value=null,this.#l.value=this.#t.length>0?this.#t[0].text:null,this.#m.value=this.#t.length>0?this.#t[0].text:null,this.#l.placeholder=this.singleLabel,this.#u.value=this.#t.length>0?this.#t[0].value:null;const t=this.#l.parentNode,e=t.firstChild;if(e.className==="remove-tag"&&e.remove(),!this.clearButton||this.#t.length<=0)return;const s=document.createElement("span");s.dataset.value=this.#t[0].value,s.innerHTML="x",s.className="remove-tag",t.insertBefore(s,t.firstChild)}#C(){if(this.#s.innerHTML="",this.#t.length<=0){this.#s.appendChild(document.createElement("div"));return}this.#t.forEach(({text:t,value:e})=>{const s=document.createElement("div");s.className="selected-tag",s.innerHTML=`${t} <span class="remove-tag" data-value="${e}">x</span>`,this.#s.appendChild(s)})}#B(t){this.#t=this.#t.filter(e=>this.#c(e.value)!==this.#c(t)),this.#d(t)}#k(t){const{scrollTop:e,scrollHeight:s,clientHeight:i}=this.#e;t.target.lastChild!==null&&(t.target.lastChild.dataset.value==="loading"||this.#g||e+(i+1)>=s&&(this.#h({id:"loading",text:"cargando ..."}),this.#T()))}#c(t){return!isNaN(t)&&!isNaN(parseFloat(t))?parseInt(t):t}async render(){const t=document.getElementById(this.id),e=t===null?!1:t.outerHTML.includes("<select");this.#f===void 0&&t!==null||e?this.#D():this.#f!==void 0&&this.#d()}}h.selectyc=d,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "selectyc",
3
3
  "description": "select multiple and simple",
4
- "version": "0.0.23",
4
+ "version": "0.0.24",
5
5
  "main": "./dist/selectyc.umd.js",
6
6
  "module": "./dist/selectyc.js",
7
7
  "type": "module",