selectyc 0.0.5 → 0.0.7

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
@@ -50,11 +50,11 @@ class l {
50
50
  #t = [];
51
51
  #o;
52
52
  #p = [];
53
- #h;
53
+ #l;
54
54
  #y;
55
55
  #s;
56
56
  #e;
57
- #l;
57
+ #n;
58
58
  #r;
59
59
  #i = !1;
60
60
  #f = !1;
@@ -64,7 +64,7 @@ class l {
64
64
  constructor(t) {
65
65
  if (window.selects === void 0 && (window.selects = []), window.selects[t] !== void 0)
66
66
  return window.selects[t];
67
- 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, window.selects[t] = this;
67
+ 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", window.selects[t] = this;
68
68
  }
69
69
  static set(t) {
70
70
  return new l(t);
@@ -124,29 +124,29 @@ class l {
124
124
  #b() {
125
125
  this.#x(), this.#s.addEventListener("click", (t) => {
126
126
  if (t.target.classList.contains("remove-tag")) {
127
- this.#T(t.target.getAttribute("data-value")), this.onUnselect !== void 0 && this.onUnselect(t.target.getAttribute("data-value")), this.#i && this.#a(), this.#m();
127
+ this.#T(t.target.getAttribute("data-value")), this.onUnselect !== void 0 && this.onUnselect(t.target.getAttribute("data-value")), this.#i && this.#h(), this.#m();
128
128
  return;
129
129
  }
130
- this.#i ? this.#a() : this.#m();
130
+ this.#i ? this.#h() : this.#m();
131
131
  }), document.addEventListener("click", (t) => {
132
- !this.#h.contains(t.target) && !this.#e.contains(t.target) && !t.target.classList.contains("remove-tag") && this.#a();
132
+ !this.#l.contains(t.target) && !this.#e.contains(t.target) && !t.target.classList.contains("remove-tag") && this.#h();
133
133
  }), window.onresize = () => {
134
- this.#a();
134
+ this.#h();
135
135
  }, this.isMultiple && this.#v();
136
136
  }
137
137
  // Draw functions
138
138
  #x() {
139
- this.#O();
139
+ this.#L();
140
140
  const t = document.createElement("div");
141
141
  t.className = "main-div-selectyc", t.style.width = this.width;
142
142
  const e = document.createElement("div");
143
143
  e.className = "custom-multiselect";
144
144
  let s = document.createElement("div");
145
- s.className = "selected-items round" + this.bodyRound, s.tabIndex = 0, s.classList.add(this.boxOverflow === "horizontal" ? "horizontal-overflow" : "vertical-overflow"), this.isMultiple || (s = this.#E(s)), e.appendChild(s), this.searchInputActive && e.appendChild(this.#L()), e.appendChild(this.#D()), t.appendChild(e);
145
+ s.className = "selected-items round" + this.bodyRound, s.tabIndex = 0, s.classList.add(this.boxOverflow === "horizontal" ? "horizontal-overflow" : "vertical-overflow"), this.isMultiple || (s = this.#E(s)), e.appendChild(s), this.searchInputActive && e.appendChild(this.#O()), e.appendChild(this.#D()), t.appendChild(e);
146
146
  const i = document.getElementById(this.id), a = document.createElement("input");
147
147
  a.name = i.name, a.style.display = "none";
148
148
  let n = i.parentNode;
149
- t.appendChild(a), n.replaceChild(t, i), this.#o = a, this.#y = s, this.#h = e, this.#s = this.#h.querySelector(".selected-items"), !this.isMultiple && this.#t.length > 0 && (this.#o.value = this.#t[0].value);
149
+ t.appendChild(a), n.replaceChild(t, i), this.#o = a, this.#y = s, this.#l = e, this.#s = this.#l.querySelector(".selected-items"), !this.isMultiple && this.#t.length > 0 && (this.#o.value = this.#t[0].value);
150
150
  }
151
151
  #E(t) {
152
152
  const e = document.createElement("input");
@@ -162,24 +162,24 @@ class l {
162
162
  let s;
163
163
  return e.addEventListener("scroll", (i) => {
164
164
  s && clearTimeout(s), s = setTimeout(() => {
165
- this.#R(i);
165
+ this.#A(i);
166
166
  }, 70);
167
167
  }), t.appendChild(e), this.#e = e, t;
168
168
  }
169
- #L() {
169
+ #O() {
170
170
  const t = document.createElement("input");
171
171
  return t.type = "text", t.id = "selectyc_search_input", t.className = "search-input", t.placeholder = "Buscar...", t.addEventListener("input", () => {
172
172
  this.filter = t.value, this.#e.innerHTML = "", this.filter = t.value, this.#w();
173
- }), t.focus(), this.#l = t, t;
173
+ }), this.#n = t, t;
174
174
  }
175
- #n(t) {
175
+ #a(t) {
176
176
  const e = document.createElement("div");
177
177
  e.className = "select-option", e.setAttribute("data-value", t.id), e.textContent = t.text, this.#e.appendChild(e), e.addEventListener("click", () => {
178
- t.id !== "sin_resultados" && (this.#M(t.text, t.id), this.onSelect !== void 0 && this.onSelect(t.id), this.#a());
178
+ t.id !== "sin_resultados" && (this.#M(t.text, t.id), this.onSelect !== void 0 && this.onSelect(t.id), this.#h());
179
179
  });
180
180
  }
181
181
  // Functions
182
- #O() {
182
+ #L() {
183
183
  const t = document.getElementById(this.id);
184
184
  this.name = t.name, this.#f = t.required, Array.from(t.options).forEach((e) => {
185
185
  if (e.selected) {
@@ -193,16 +193,16 @@ class l {
193
193
  if (this.#i)
194
194
  return;
195
195
  this.#s.classList.remove(`round${this.bodyRound}`), this.#s.classList.add(`round${this.bodyRound}t`);
196
- const t = this.#h.getBoundingClientRect();
196
+ const t = this.#l.getBoundingClientRect();
197
197
  if (this.searchInputActive) {
198
- this.#l.style.display = "block";
199
- const e = this.#l.offsetHeight;
198
+ this.#n.style.display = "block";
199
+ const e = this.#n.offsetHeight;
200
200
  this.#e.style.top = e + "px";
201
201
  }
202
- this.#e.style.width = t.width + "px", this.#e.innerHTML = "", this.#e.style.display = "block", this.#w(), this.#i = !0;
202
+ this.#e.style.width = t.width + "px", this.#e.innerHTML = "", this.#e.style.display = "block", this.searchInputActive && this.#n.focus(), this.#w(), this.#i = !0;
203
203
  }
204
- #a() {
205
- this.#i && (this.#e.innerHTML = "", this.#e.style.display = "none", this.searchInputActive && (this.#l.style.display = "none"), this.#s.classList.add(`round${this.bodyRound}`), this.#i = !1);
204
+ #h() {
205
+ this.#i && (this.#e.innerHTML = "", this.#e.style.display = "none", this.searchInputActive && (this.#n.style.display = "none"), this.#s.classList.add(`round${this.bodyRound}`), this.#i = !1);
206
206
  }
207
207
  async #g() {
208
208
  if (this.RS === void 0)
@@ -213,12 +213,12 @@ class l {
213
213
  return this.data = Array.from(new Map([...this.#p, ...s].map((i) => [i.id, i])).values()), this.data;
214
214
  }
215
215
  async #w() {
216
- this.#n({ id: "loading", text: "cargando ..." }), this.records = 10 + this.#t.length, this.#c = !1;
216
+ this.#a({ id: "loading", text: "cargando ..." }), this.records = 10 + this.#t.length, this.#c = !1;
217
217
  let t = await this.#g();
218
218
  const e = this.#t.map((s) => s.value);
219
219
  this.#e.lastChild.dataset.value === "loading" && this.#e.removeChild(this.#e.lastChild), t.forEach((s) => {
220
- s.text.toLowerCase().includes(this.#C.toLowerCase()) && !e.includes(s.id) && this.#n(s);
221
- }), this.#e.hasChildNodes() || this.#n({ id: "sin_resultados", text: "sin resultados ..." });
220
+ s.text.toLowerCase().includes(this.#C.toLowerCase()) && !e.includes(s.id) && this.#a(s);
221
+ }), this.#e.hasChildNodes() || this.#a({ id: "sin_resultados", text: "sin resultados ..." });
222
222
  }
223
223
  async #N() {
224
224
  const t = this.#t.map((n) => n.value);
@@ -228,7 +228,7 @@ class l {
228
228
  this.#e.lastChild.dataset.value === "loading" && this.#e.removeChild(this.#e.lastChild);
229
229
  const a = this.#e.lastChild.dataset.value;
230
230
  i.forEach((n) => {
231
- n.text.toLowerCase().includes(e.toLowerCase()) && !t.includes(n.id) && !s.includes(n.id) && this.#n(n);
231
+ n.text.toLowerCase().includes(e.toLowerCase()) && !t.includes(n.id) && !s.includes(n.id) && this.#a(n);
232
232
  }), this.#c = a === this.#e.lastChild.dataset.value;
233
233
  }
234
234
  #M(t, e) {
@@ -258,9 +258,9 @@ class l {
258
258
  #T(t) {
259
259
  this.#t = this.#t.filter((e) => this.#d(e.value) !== this.#d(t)), this.#u(t);
260
260
  }
261
- #R(t) {
261
+ #A(t) {
262
262
  const { scrollTop: e, scrollHeight: s, clientHeight: i } = this.#e;
263
- t.target.lastChild !== null && (t.target.lastChild.dataset.value === "loading" || this.#c || e + (i + 1) >= s && (this.#n({ id: "loading", text: "cargando ..." }), this.#N()));
263
+ t.target.lastChild !== null && (t.target.lastChild.dataset.value === "loading" || this.#c || e + (i + 1) >= s && (this.#a({ id: "loading", text: "cargando ..." }), this.#N()));
264
264
  }
265
265
  #d(t) {
266
266
  return !isNaN(t) && !isNaN(parseFloat(t)) ? parseInt(t) : t;
@@ -1 +1 @@
1
- (function(l,a){typeof exports=="object"&&typeof module<"u"?a(exports):typeof define=="function"&&define.amd?define(["exports"],a):(l=typeof globalThis<"u"?globalThis:l||self,a(l.selectyc={}))})(this,function(l){"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 r{#t=[];#o;#f=[];#l;#y;#s;#e;#h;#r;#i=!1;#p=!1;#c=!1;#S="";#C='<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,window.selects[t]=this}static set(t){return new r(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}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.#u(t)}#b(){this.#x(),this.#s.addEventListener("click",t=>{if(t.target.classList.contains("remove-tag")){this.#T(t.target.getAttribute("data-value")),this.onUnselect!==void 0&&this.onUnselect(t.target.getAttribute("data-value")),this.#i&&this.#a(),this.#m();return}this.#i?this.#a():this.#m()}),document.addEventListener("click",t=>{!this.#l.contains(t.target)&&!this.#e.contains(t.target)&&!t.target.classList.contains("remove-tag")&&this.#a()}),window.onresize=()=>{this.#a()},this.isMultiple&&this.#v()}#x(){this.#L();const t=document.createElement("div");t.className="main-div-selectyc",t.style.width=this.width;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.#E(s)),e.appendChild(s),this.searchInputActive&&e.appendChild(this.#O()),e.appendChild(this.#D()),t.appendChild(e);const i=document.getElementById(this.id),h=document.createElement("input");h.name=i.name,h.style.display="none";let n=i.parentNode;t.appendChild(h),n.replaceChild(t,i),this.#o=h,this.#y=s,this.#l=e,this.#s=this.#l.querySelector(".selected-items"),!this.isMultiple&&this.#t.length>0&&(this.#o.value=this.#t[0].value)}#E(t){const e=document.createElement("input");e.className="custom-single-select",e.value=this.#t.length===0?this.singleLabel:this.#t[0].text,e.required=this.#p,e.readOnly=!0;const s=document.createElement("div");return s.innerHTML=this.#C,t.appendChild(e),t.appendChild(s),this.#r=e,t}#D(){const t=document.createElement("div");t.setAttribute("style","position:fixed; z-index:999;");const e=document.createElement("div");e.className="global-dropdown";let s;return e.addEventListener("scroll",i=>{s&&clearTimeout(s),s=setTimeout(()=>{this.#R(i)},70)}),t.appendChild(e),this.#e=e,t}#O(){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.filter=t.value,this.#w()}),t.focus(),this.#h=t,t}#n(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.#N(t.text,t.id),this.onSelect!==void 0&&this.onSelect(t.id),this.#a())})}#L(){const t=document.getElementById(this.id);this.name=t.name,this.#p=t.required,Array.from(t.options).forEach(e=>{if(e.selected){const s=e.text,i=this.#d(e.value);this.isMultiple?this.#t.push({value:i,text:s}):this.#t[0]={value:i,text:s}}this.#f.push({id:this.#d(e.value),text:e.text})})}#m(){if(this.#i)return;this.#s.classList.remove(`round${this.bodyRound}`),this.#s.classList.add(`round${this.bodyRound}t`);const t=this.#l.getBoundingClientRect();if(this.searchInputActive){this.#h.style.display="block";const e=this.#h.offsetHeight;this.#e.style.top=e+"px"}this.#e.style.width=t.width+"px",this.#e.innerHTML="",this.#e.style.display="block",this.#w(),this.#i=!0}#a(){this.#i&&(this.#e.innerHTML="",this.#e.style.display="none",this.searchInputActive&&(this.#h.style.display="none"),this.#s.classList.add(`round${this.bodyRound}`),this.#i=!1)}async#g(){if(this.RS===void 0)return this.data;let t={records:this.records,filter:this.filter};t!==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.#f,...s].map(i=>[i.id,i])).values()),this.data}async#w(){this.#n({id:"loading",text:"cargando ..."}),this.records=10+this.#t.length,this.#c=!1;let t=await this.#g();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.#n(s)}),this.#e.hasChildNodes()||this.#n({id:"sin_resultados",text:"sin resultados ..."})}async#M(){const t=this.#t.map(n=>n.value);let e=this.filter===null?"":this.filter,s=this.data.map(n=>n.id);this.records=this.records+10+this.#t.length;let i=await this.#g();this.#e.lastChild.dataset.value==="loading"&&this.#e.removeChild(this.#e.lastChild);const h=this.#e.lastChild.dataset.value;i.forEach(n=>{n.text.toLowerCase().includes(e.toLowerCase())&&!t.includes(n.id)&&!s.includes(n.id)&&this.#n(n)}),this.#c=h===this.#e.lastChild.dataset.value}#N(t,e){this.#t.find(i=>i.value===e)||(this.isMultiple||(this.#t=[]),this.#t.push({text:t,value:e})),this.#u(e)}#u(t){this.onChange!==void 0&&this.onChange(t),this.isMultiple?this.#v():this.#I()}#I(){this.#r.value=null,this.#r.value=this.#t.length>0?this.#t[0].text:null,this.#o.value=this.#t.length>0?this.#t[0].value:null;const t=this.#r.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)}#v(){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)})}#T(t){this.#t=this.#t.filter(e=>this.#d(e.value)!==this.#d(t)),this.#u(t)}#R(t){const{scrollTop:e,scrollHeight:s,clientHeight:i}=this.#e;t.target.lastChild!==null&&(t.target.lastChild.dataset.value==="loading"||this.#c||e+(i+1)>=s&&(this.#n({id:"loading",text:"cargando ..."}),this.#M()))}#d(t){return!isNaN(t)&&!isNaN(parseFloat(t))?parseInt(t):t}async render(){this.#b()}}l.selectyc=r,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
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 r{#t=[];#o;#f=[];#l;#y;#s;#e;#n;#r;#i=!1;#p=!1;#c=!1;#S="";#C='<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",window.selects[t]=this}static set(t){return new r(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}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.#u(t)}#b(){this.#x(),this.#s.addEventListener("click",t=>{if(t.target.classList.contains("remove-tag")){this.#T(t.target.getAttribute("data-value")),this.onUnselect!==void 0&&this.onUnselect(t.target.getAttribute("data-value")),this.#i&&this.#h(),this.#m();return}this.#i?this.#h():this.#m()}),document.addEventListener("click",t=>{!this.#l.contains(t.target)&&!this.#e.contains(t.target)&&!t.target.classList.contains("remove-tag")&&this.#h()}),window.onresize=()=>{this.#h()},this.isMultiple&&this.#w()}#x(){this.#L();const t=document.createElement("div");t.className="main-div-selectyc",t.style.width=this.width;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.#E(s)),e.appendChild(s),this.searchInputActive&&e.appendChild(this.#D()),e.appendChild(this.#O()),t.appendChild(e);const i=document.getElementById(this.id),l=document.createElement("input");l.name=i.name,l.style.display="none";let n=i.parentNode;t.appendChild(l),n.replaceChild(t,i),this.#o=l,this.#y=s,this.#l=e,this.#s=this.#l.querySelector(".selected-items"),!this.isMultiple&&this.#t.length>0&&(this.#o.value=this.#t[0].value)}#E(t){const e=document.createElement("input");e.className="custom-single-select",e.value=this.#t.length===0?this.singleLabel:this.#t[0].text,e.required=this.#p,e.readOnly=!0;const s=document.createElement("div");return s.innerHTML=this.#C,t.appendChild(e),t.appendChild(s),this.#r=e,t}#O(){const t=document.createElement("div");t.setAttribute("style","position:fixed; z-index:999;");const e=document.createElement("div");e.className="global-dropdown";let s;return e.addEventListener("scroll",i=>{s&&clearTimeout(s),s=setTimeout(()=>{this.#A(i)},70)}),t.appendChild(e),this.#e=e,t}#D(){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.filter=t.value,this.#v()}),this.#n=t,t}#a(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.#N(t.text,t.id),this.onSelect!==void 0&&this.onSelect(t.id),this.#h())})}#L(){const t=document.getElementById(this.id);this.name=t.name,this.#p=t.required,Array.from(t.options).forEach(e=>{if(e.selected){const s=e.text,i=this.#d(e.value);this.isMultiple?this.#t.push({value:i,text:s}):this.#t[0]={value:i,text:s}}this.#f.push({id:this.#d(e.value),text:e.text})})}#m(){if(this.#i)return;this.#s.classList.remove(`round${this.bodyRound}`),this.#s.classList.add(`round${this.bodyRound}t`);const t=this.#l.getBoundingClientRect();if(this.searchInputActive){this.#n.style.display="block";const e=this.#n.offsetHeight;this.#e.style.top=e+"px"}this.#e.style.width=t.width+"px",this.#e.innerHTML="",this.#e.style.display="block",this.searchInputActive&&this.#n.focus(),this.#v(),this.#i=!0}#h(){this.#i&&(this.#e.innerHTML="",this.#e.style.display="none",this.searchInputActive&&(this.#n.style.display="none"),this.#s.classList.add(`round${this.bodyRound}`),this.#i=!1)}async#g(){if(this.RS===void 0)return this.data;let t={records:this.records,filter:this.filter};t!==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.#f,...s].map(i=>[i.id,i])).values()),this.data}async#v(){this.#a({id:"loading",text:"cargando ..."}),this.records=10+this.#t.length,this.#c=!1;let t=await this.#g();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.#a(s)}),this.#e.hasChildNodes()||this.#a({id:"sin_resultados",text:"sin resultados ..."})}async#M(){const t=this.#t.map(n=>n.value);let e=this.filter===null?"":this.filter,s=this.data.map(n=>n.id);this.records=this.records+10+this.#t.length;let i=await this.#g();this.#e.lastChild.dataset.value==="loading"&&this.#e.removeChild(this.#e.lastChild);const l=this.#e.lastChild.dataset.value;i.forEach(n=>{n.text.toLowerCase().includes(e.toLowerCase())&&!t.includes(n.id)&&!s.includes(n.id)&&this.#a(n)}),this.#c=l===this.#e.lastChild.dataset.value}#N(t,e){this.#t.find(i=>i.value===e)||(this.isMultiple||(this.#t=[]),this.#t.push({text:t,value:e})),this.#u(e)}#u(t){this.onChange!==void 0&&this.onChange(t),this.isMultiple?this.#w():this.#I()}#I(){this.#r.value=null,this.#r.value=this.#t.length>0?this.#t[0].text:null,this.#o.value=this.#t.length>0?this.#t[0].value:null;const t=this.#r.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)}#w(){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)})}#T(t){this.#t=this.#t.filter(e=>this.#d(e.value)!==this.#d(t)),this.#u(t)}#A(t){const{scrollTop:e,scrollHeight:s,clientHeight:i}=this.#e;t.target.lastChild!==null&&(t.target.lastChild.dataset.value==="loading"||this.#c||e+(i+1)>=s&&(this.#a({id:"loading",text:"cargando ..."}),this.#M()))}#d(t){return!isNaN(t)&&!isNaN(parseFloat(t))?parseInt(t):t}async render(){this.#b()}}h.selectyc=r,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.5",
4
+ "version": "0.0.7",
5
5
  "main": "./dist/selectyc.umd.js",
6
6
  "module": "./dist/selectyc.js",
7
7
  "type": "module",