selectyc 0.0.27 → 0.0.29

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
@@ -48,26 +48,26 @@ class h {
48
48
  }
49
49
  class d {
50
50
  #t = [];
51
- #v;
52
- #y = [];
53
- #m;
54
51
  #g;
52
+ #w = [];
53
+ #m;
54
+ #b;
55
55
  #s;
56
56
  #e;
57
57
  #a;
58
58
  #r;
59
- #w;
59
+ #p;
60
60
  #i;
61
61
  #h = !1;
62
62
  #E = !1;
63
- #b = !1;
63
+ #C = !1;
64
64
  #O = "";
65
65
  #I = '<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>';
66
66
  //{{-------- Mobil variables ---------}}
67
- #n;
68
67
  #l;
69
- #C;
70
- #L = !1;
68
+ #n;
69
+ #x;
70
+ #S = !1;
71
71
  #c = !1;
72
72
  constructor(t) {
73
73
  if (window.selects === void 0 && (window.selects = []), window.selects[t] !== void 0)
@@ -138,6 +138,9 @@ class d {
138
138
  setDisableSelect(t) {
139
139
  return this.disabled = t, this;
140
140
  }
141
+ setRequiredSelect(t) {
142
+ return this.#p.required = t, this;
143
+ }
141
144
  #A() {
142
145
  this.#H(), this.#s.addEventListener("click", (t) => {
143
146
  if (!this.disabled) {
@@ -148,7 +151,7 @@ class d {
148
151
  this.#h ? this.#o() : this.#M();
149
152
  }
150
153
  }), document.addEventListener("click", (t) => {
151
- this.isMobil && t.target.classList.contains("selectyc-mobile-overlay") && this.#x(), !this.#m.contains(t.target) && !this.#e.contains(t.target) && !t.target.classList.contains("remove-tag") && this.#o();
154
+ this.isMobil && t.target.classList.contains("selectyc-mobile-overlay") && this.#f(), !this.#m.contains(t.target) && !this.#e.contains(t.target) && !t.target.classList.contains("remove-tag") && this.#o();
152
155
  }), window.onresize = () => {
153
156
  this.#o();
154
157
  }, window.addEventListener("scroll", () => {
@@ -164,10 +167,10 @@ class d {
164
167
  e.className = "custom-multiselect";
165
168
  let s = document.createElement("div");
166
169
  s.className = "selected-items round" + this.bodyRound, s.tabIndex = 0, s.classList.add(this.boxOverflow === "horizontal" ? "horizontal-overflow" : "vertical-overflow"), this.height !== void 0 && (s.style.height = this.height), this.isMultiple || (s = this.#R(s)), e.appendChild(s), e.appendChild(this.#k()), t.appendChild(e);
167
- const i = document.getElementById(this.id), l = document.createElement("input");
168
- l.name = i.name, l.setAttribute("data-id", i.id), this.rootClassName !== "" && (l.className = i.className), l.style.display = "none";
169
- let n = i.parentNode;
170
- t.appendChild(l), n.replaceChild(t, i), this.#v = l, this.#g = s, this.#m = e, this.#s = this.#m.querySelector(".selected-items"), !this.isMultiple && this.#t.length > 0 && (this.#v.value = this.#t[0].value);
170
+ const i = document.getElementById(this.id), n = document.createElement("input");
171
+ n.name = i.name, n.setAttribute("data-id", i.id), this.rootClassName !== "" && (n.className = i.className), n.style.display = "none";
172
+ let l = i.parentNode;
173
+ t.appendChild(n), l.replaceChild(t, i), this.#g = n, this.#b = s, this.#m = e, this.#s = this.#m.querySelector(".selected-items"), !this.isMultiple && this.#t.length > 0 && (this.#g.value = this.#t[0].value);
171
174
  }
172
175
  #R(t) {
173
176
  const e = document.createElement("input");
@@ -177,7 +180,7 @@ class d {
177
180
  }
178
181
  #B() {
179
182
  const t = document.createElement("input");
180
- return t.type = "text", t.required = this.#E, 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.#w = t, t;
183
+ return t.type = "text", t.required = this.#E, 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.#p = t, t;
181
184
  }
182
185
  #k() {
183
186
  const t = document.createElement("div");
@@ -187,9 +190,9 @@ class d {
187
190
  const s = document.createElement("div");
188
191
  s.className = "global-dropdown", this.searchInputActive && e.appendChild(this.#$());
189
192
  let i;
190
- return s.addEventListener("scroll", (l) => {
193
+ return s.addEventListener("scroll", (n) => {
191
194
  i && clearTimeout(i), i = setTimeout(() => {
192
- this.#U(l);
195
+ this.#U(n);
193
196
  }, 70);
194
197
  }), e.appendChild(s), this.#e = s, this.#i = e, t.appendChild(e), t;
195
198
  }
@@ -214,47 +217,47 @@ class d {
214
217
  }), e.addEventListener("mouseleave", () => {
215
218
  clearTimeout(s), e.style.whiteSpace = "nowrap";
216
219
  }), e.addEventListener("click", () => {
217
- t.id !== "sin_resultados" && (this.#S(t.text, t.id), this.onSelect !== void 0 && this.onSelect(t.id, this), this.#o());
220
+ t.id !== "sin_resultados" && (this.#L(t.text, t.id), this.onSelect !== void 0 && this.onSelect(t.id, this), this.#o());
218
221
  });
219
222
  }
220
223
  //{{-------- Mobile draw modal ---------}}
221
224
  #_() {
222
- if (this.#n) return;
225
+ if (this.#l) return;
223
226
  const t = document.createElement("div");
224
227
  t.className = "selectyc-mobile-overlay";
225
228
  const e = document.createElement("div");
226
229
  e.className = "selectyc-mobile-modal";
227
230
  const s = document.createElement("div");
228
231
  if (s.className = "selectyc-mobile-header", this.searchInputActive) {
229
- const n = document.createElement("input");
230
- n.type = "text", n.className = "selectyc-mobile-search", n.placeholder = "Buscar...", n.addEventListener("input", () => {
231
- this.filter = n.value, this.#l.innerHTML = "", this.#D();
232
- }), this.#C = n, s.appendChild(n);
232
+ const l = document.createElement("input");
233
+ l.type = "text", l.className = "selectyc-mobile-search", l.placeholder = "Buscar...", l.addEventListener("input", () => {
234
+ this.filter = l.value, this.#n.innerHTML = "", this.#D();
235
+ }), this.#x = l, s.appendChild(l);
233
236
  }
234
237
  const i = document.createElement("button");
235
- i.innerHTML = "✕", i.className = "selectyc-mobile-close", i.onclick = () => this.#x(), s.appendChild(i);
236
- const l = document.createElement("div");
237
- l.className = "selectyc-mobile-body", l.addEventListener("scroll", async () => {
238
- if (this.#L || this.#c) return;
239
- const { scrollTop: n, scrollHeight: a, clientHeight: o } = l;
240
- n + o >= a - 10 && (this.#L = !0, await this.#F(), this.#L = !1);
241
- }), e.appendChild(s), e.appendChild(l), t.appendChild(e), document.body.appendChild(t), this.#n = t, this.#l = l;
238
+ i.innerHTML = "✕", i.className = "selectyc-mobile-close", i.onclick = () => this.#f(), s.appendChild(i);
239
+ const n = document.createElement("div");
240
+ n.className = "selectyc-mobile-body", n.addEventListener("scroll", async () => {
241
+ if (this.#S || this.#c) return;
242
+ const { scrollTop: l, scrollHeight: a, clientHeight: o } = n;
243
+ l + o >= a - 10 && (this.#S = !0, await this.#F(), this.#S = !1);
244
+ }), e.appendChild(s), e.appendChild(n), t.appendChild(e), document.body.appendChild(t), this.#l = t, this.#n = n;
242
245
  }
243
246
  //{{-------- Functions ---------}}
244
247
  #j() {
245
248
  const t = document.getElementById(this.id);
246
249
  this.name = t.name, this.#E = t.required, this.rootClassName = t.className, this.disabled = t.disabled, Array.from(t.options).forEach((e) => {
247
250
  if (e.outerHTML.includes("selected")) {
248
- const s = e.text, i = this.#f(e.value);
251
+ const s = e.text, i = this.#v(e.value);
249
252
  this.isMultiple ? this.#t.push({ value: i, text: s }) : this.#t[0] = { value: i, text: s };
250
253
  }
251
- this.#y.push({ id: this.#f(e.value), text: e.text }), this.data = this.#y;
254
+ this.#w.push({ id: this.#v(e.value), text: e.text }), this.data = this.#w;
252
255
  });
253
256
  }
254
257
  //{{-------- Show dropdown ---------}}
255
258
  #M() {
256
259
  if (this.isMobil) {
257
- this.#z();
260
+ this.#q();
258
261
  return;
259
262
  }
260
263
  if (this.filter = null, this.searchInputActive && (this.#a.value = null), this.#h) return;
@@ -264,18 +267,18 @@ class d {
264
267
  const i = 270;
265
268
  this.#s.classList.remove(`round${this.bodyRound}`), this.#i.classList.remove("dropdown-up"), this.#s.classList.remove(`round${this.bodyRound}t-up`), this.#s.classList.remove(`round${this.bodyRound}t`), e < i && s > e ? (this.#i.style.top = "auto", this.#i.style.bottom = window.innerHeight - t.top + "px", this.#i.classList.add("dropdown-up"), this.#s.classList.add(`round${this.bodyRound}t-up`), this.#e.classList.remove("global-dropdown-round")) : (this.#i.style.bottom = "auto", this.#i.style.top = t.bottom + "px", this.#s.classList.add(`round${this.bodyRound}t`), this.#e.classList.add("global-dropdown-round")), this.#i.style.left = t.left + "px", this.#e.style.display = "block", this.searchInputActive && (this.#a.style.display = "block", this.#a.style.width = t.width + "px", this.#a.focus()), this.#N();
266
269
  }
267
- #z() {
268
- this.#_(), this.filter = null, this.#C && (this.#C.value = ""), this.#n.style.display = "flex", this.#n.style.justifyContent = "center", this.#n.style.alignItems = "center", document.body.style.overflow = "hidden", this.#D();
270
+ #q() {
271
+ this.#_(), this.filter = null, this.#x && (this.#x.value = ""), this.#l.style.display = "flex", this.#l.style.justifyContent = "center", this.#l.style.alignItems = "center", document.body.style.overflow = "hidden", this.#D();
269
272
  }
270
273
  //{{-------- Hide dropdown ---------}}
271
274
  #o() {
272
275
  this.isMobil || this.#h && (this.#h = !1, this.#e.innerHTML = "", this.#e.style.display = "none", this.searchInputActive && (this.#a.style.display = "none"), this.#s.classList.add(`round${this.bodyRound}`));
273
276
  }
274
- #x() {
275
- this.#n && (this.#n.style.display = "none", document.body.style.overflow = "");
277
+ #f() {
278
+ this.#l && (this.#l.style.display = "none", document.body.style.overflow = "");
276
279
  }
277
280
  //{{-------- Render options ---------}}
278
- async #p() {
281
+ async #y() {
279
282
  if (this.RS === void 0)
280
283
  return this.data;
281
284
  let t = { records: this.records, filter: this.filter };
@@ -284,64 +287,58 @@ class d {
284
287
  t = { ...t, ...i };
285
288
  } else this.bodyData !== null && (t = { ...t, ...this.bodyData });
286
289
  const e = await h.make(this.RS).addData(t).setMethod("POST").go(), s = Array.isArray(e) ? e : e.data;
287
- return this.data = Array.from(new Map([...this.#y, ...s].map((i) => [i.id, i])).values()), this.data;
290
+ return this.data = Array.from(new Map([...this.#w, ...s].map((i) => [i.id, i])).values()), this.data;
288
291
  }
289
292
  async #N() {
290
- this.#d({ id: "loading", text: "cargando ..." }), this.records = 10 + this.#t.length, this.#b = !1;
291
- let t = await this.#p();
293
+ this.#d({ id: "loading", text: "cargando ..." }), this.records = 10 + this.#t.length, this.#C = !1;
294
+ let t = await this.#y();
292
295
  const e = this.#t.map((s) => s.value);
293
296
  this.#e.lastChild.dataset.value === "loading" && this.#e.removeChild(this.#e.lastChild), t.forEach((s) => {
294
297
  s.text.toLowerCase().includes(this.#O.toLowerCase()) && !e.includes(s.id) && this.#d(s);
295
298
  }), this.#e.hasChildNodes() || this.#d({ id: "sin_resultados", text: "sin resultados ..." });
296
299
  }
297
300
  async #D() {
298
- this.records = 10 + this.#t.length, this.#c = !1, this.#l.innerHTML = '<div class="mobile-loading">cargando...</div>';
299
- let t = await this.#p();
300
- this.#l.innerHTML = "";
301
+ this.records = 10 + this.#t.length, this.#c = !1, this.#n.innerHTML = '<div class="mobile-loading">cargando...</div>';
302
+ let t = await this.#y();
303
+ this.#n.innerHTML = "";
301
304
  const e = this.#t.map((i) => i.value);
302
305
  let s = 0;
303
306
  t.forEach((i) => {
304
307
  if (i.text.toLowerCase().includes((this.filter || "").toLowerCase()) && !e.includes(i.id)) {
305
- const l = document.createElement("div");
306
- l.className = "mobile-option", l.innerText = i.text, l.addEventListener("touchstart", () => {
307
- l.classList.add("active-touch");
308
- }), l.addEventListener("touchend", () => {
309
- l.classList.remove("active-touch");
310
- }), l.addEventListener("touchcancel", () => {
311
- l.classList.remove("active-touch");
312
- }), l.onclick = () => {
313
- this.#S(i.text, i.id), this.onSelect && this.onSelect(i.id, this), this.#x();
314
- }, this.#l.appendChild(l), s++;
308
+ const n = document.createElement("div");
309
+ n.className = "mobile-option", n.innerText = i.text, n.onclick = () => {
310
+ this.#L(i.text, i.id), this.onSelect && this.onSelect(i.id, this), this.#f();
311
+ }, this.#n.appendChild(n), s++;
315
312
  }
316
- }), s === 0 && (this.#l.innerHTML = '<div class="mobile-empty">Sin resultados</div>', this.#c = !0);
313
+ }), s === 0 && (this.#n.innerHTML = '<div class="mobile-empty">Sin resultados</div>', this.#c = !0);
317
314
  }
318
- async #q() {
319
- const t = this.#t.map((n) => n.value);
320
- let e = this.filter === null ? "" : this.filter, s = this.data.map((n) => n.id);
315
+ async #z() {
316
+ const t = this.#t.map((l) => l.value);
317
+ let e = this.filter === null ? "" : this.filter, s = this.data.map((l) => l.id);
321
318
  this.records = this.records + 10 + this.#t.length;
322
- let i = await this.#p();
319
+ let i = await this.#y();
323
320
  this.#e.lastChild.dataset.value === "loading" && this.#e.removeChild(this.#e.lastChild);
324
- const l = this.#e.lastChild.dataset.value;
325
- i.forEach((n) => {
326
- n.text.toLowerCase().includes(e.toLowerCase()) && !t.includes(n.id) && !s.includes(n.id) && this.#d(n);
327
- }), this.#b = l === this.#e.lastChild.dataset.value;
321
+ const n = this.#e.lastChild.dataset.value;
322
+ i.forEach((l) => {
323
+ l.text.toLowerCase().includes(e.toLowerCase()) && !t.includes(l.id) && !s.includes(l.id) && this.#d(l);
324
+ }), this.#C = n === this.#e.lastChild.dataset.value;
328
325
  }
329
326
  async #F() {
330
327
  if (this.#c) return;
331
- const t = this.#t.map((n) => n.value);
332
- let e = this.filter || "", s = this.data.map((n) => n.id);
328
+ const t = this.#t.map((l) => l.value);
329
+ let e = this.filter || "", s = this.data.map((l) => l.id);
333
330
  this.records = this.records + 10 + this.#t.length;
334
- let i = await this.#p(), l = 0;
335
- i.forEach((n) => {
336
- if (n.text.toLowerCase().includes(e.toLowerCase()) && !t.includes(n.id) && !s.includes(n.id)) {
331
+ let i = await this.#y(), n = 0;
332
+ i.forEach((l) => {
333
+ if (l.text.toLowerCase().includes(e.toLowerCase()) && !t.includes(l.id) && !s.includes(l.id)) {
337
334
  const a = document.createElement("div");
338
- a.className = "mobile-option", a.innerText = n.text, a.onclick = () => {
339
- this.#S(n.text, n.id), this.onSelect && this.onSelect(n.id, this);
340
- }, this.#l.appendChild(a), l++;
335
+ a.className = "mobile-option", a.innerText = l.text, a.onclick = () => {
336
+ this.#L(l.text, l.id), this.onSelect && this.onSelect(l.id, this), this.#f();
337
+ }, this.#n.appendChild(a), n++;
341
338
  }
342
- }), l === 0 && (this.#c = !0);
339
+ }), n === 0 && (this.#c = !0);
343
340
  }
344
- #S(t, e) {
341
+ #L(t, e) {
345
342
  this.#t.find((i) => i.value === e) || (this.isMultiple || (this.#t = []), this.#t.push({ text: t, value: e })), this.#u(e);
346
343
  }
347
344
  //{{-------- Render main box ---------}}
@@ -349,7 +346,7 @@ class d {
349
346
  this.onChange !== void 0 && this.onChange(t, this), this.isMultiple ? this.#T() : this.#P();
350
347
  }
351
348
  #P() {
352
- this.#r.value = null, this.#w.value = null, this.#r.value = this.#t.length > 0 ? this.#t[0].text : null, this.#w.value = this.#t.length > 0 ? this.#t[0].text : null, this.#r.placeholder = this.singleLabel, this.#v.value = this.#t.length > 0 ? this.#t[0].value : null;
349
+ this.#r.value = null, this.#p.value = null, this.#r.value = this.#t.length > 0 ? this.#t[0].text : null, this.#p.value = this.#t.length > 0 ? this.#t[0].text : null, this.#r.placeholder = this.singleLabel, this.#g.value = this.#t.length > 0 ? this.#t[0].value : null;
353
350
  const t = this.#r.parentNode, e = t.firstChild;
354
351
  if (e.className === "remove-tag" && e.remove(), !this.clearButton || this.#t.length <= 0)
355
352
  return;
@@ -367,18 +364,18 @@ class d {
367
364
  });
368
365
  }
369
366
  #V(t) {
370
- this.#t = this.#t.filter((e) => this.#f(e.value) !== this.#f(t)), this.#u(t);
367
+ this.#t = this.#t.filter((e) => this.#v(e.value) !== this.#v(t)), this.#u(t);
371
368
  }
372
369
  #U(t) {
373
370
  const { scrollTop: e, scrollHeight: s, clientHeight: i } = this.#e;
374
- t.target.lastChild !== null && (t.target.lastChild.dataset.value === "loading" || this.#b || e + (i + 1) >= s && (this.#d({ id: "loading", text: "cargando ..." }), this.#q()));
371
+ t.target.lastChild !== null && (t.target.lastChild.dataset.value === "loading" || this.#C || e + (i + 1) >= s && (this.#d({ id: "loading", text: "cargando ..." }), this.#z()));
375
372
  }
376
- #f(t) {
373
+ #v(t) {
377
374
  return !isNaN(t) && !isNaN(parseFloat(t)) ? parseInt(t) : t;
378
375
  }
379
376
  async render() {
380
377
  const t = document.getElementById(this.id), e = t === null ? !1 : t.outerHTML.includes("<select");
381
- this.#g === void 0 && t !== null || e ? this.#A() : this.#g !== void 0 && this.#u();
378
+ this.#b === void 0 && t !== null || e ? this.#A() : this.#b !== void 0 && this.#u();
382
379
  }
383
380
  }
384
381
  export {
@@ -1 +1 @@
1
- (function(d,a){typeof exports=="object"&&typeof module<"u"?a(exports):typeof define=="function"&&define.amd?define(["exports"],a):(d=typeof globalThis<"u"?globalThis:d||self,a(d.selectyc={}))})(this,function(d){"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 o{#t=[];#y;#v=[];#m;#g;#s;#e;#a;#r;#w;#i;#d=!1;#E=!1;#b=!1;#O="";#I='<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>';#n;#l;#C;#L=!1;#c=!1;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,this.isMobil=/Android|iPhone|iPad|iPod/i.test(navigator.userAgent),window.selects[t]=this}static set(t){return new o(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.#u(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}setHeight(t){return this.height=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)}setDisableSelect(t){return this.disabled=t,this}#A(){this.#H(),this.#s.addEventListener("click",t=>{if(!this.disabled){if(t.target.classList.contains("remove-tag")){this.#V(t.target.getAttribute("data-value")),this.onUnselect!==void 0&&this.onUnselect(t.target.getAttribute("data-value"),this),this.#d&&this.#o(),this.#M();return}this.#d?this.#o():this.#M()}}),document.addEventListener("click",t=>{this.isMobil&&t.target.classList.contains("selectyc-mobile-overlay")&&this.#x(),!this.#m.contains(t.target)&&!this.#e.contains(t.target)&&!t.target.classList.contains("remove-tag")&&this.#o()}),window.onresize=()=>{this.#o()},window.addEventListener("scroll",()=>{this.isMobil||this.#o()}),this.isMultiple&&this.#T()}#H(){this.#_();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.height!==void 0&&(s.style.height=this.height),this.isMultiple||(s=this.#R(s)),e.appendChild(s),e.appendChild(this.#k()),t.appendChild(e);const i=document.getElementById(this.id),l=document.createElement("input");l.name=i.name,l.setAttribute("data-id",i.id),this.rootClassName!==""&&(l.className=i.className),l.style.display="none";let n=i.parentNode;t.appendChild(l),n.replaceChild(t,i),this.#y=l,this.#g=s,this.#m=e,this.#s=this.#m.querySelector(".selected-items"),!this.isMultiple&&this.#t.length>0&&(this.#y.value=this.#t[0].value)}#R(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.#I,t.appendChild(this.#B()),t.appendChild(e),t.appendChild(s),this.#r=e,t}#B(){const t=document.createElement("input");return t.type="text",t.required=this.#E,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.#w=t,t}#k(){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.#$());let i;return s.addEventListener("scroll",l=>{i&&clearTimeout(i),i=setTimeout(()=>{this.#U(l)},70)}),e.appendChild(s),this.#e=s,this.#i=e,t.appendChild(e),t}#$(){const t=document.createElement("input");t.type="text",t.id="selectyc_search_input",t.className="search-input",t.placeholder="Buscar...";let e;return t.addEventListener("input",()=>{this.filter=t.value,this.#e.innerHTML="",this.#h({id:"loading",text:"cargando ..."}),e&&clearTimeout(e),e=setTimeout(()=>{this.#e.removeChild(this.#e.lastChild),this.#N()},150)}),this.#a=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);let s;e.addEventListener("mouseover",()=>{clearTimeout(s),s=setTimeout(()=>{e.style.whiteSpace="normal"},500)}),e.addEventListener("mouseleave",()=>{clearTimeout(s),e.style.whiteSpace="nowrap"}),e.addEventListener("click",()=>{t.id!=="sin_resultados"&&(this.#S(t.text,t.id),this.onSelect!==void 0&&this.onSelect(t.id,this),this.#o())})}#j(){if(this.#n)return;const t=document.createElement("div");t.className="selectyc-mobile-overlay";const e=document.createElement("div");e.className="selectyc-mobile-modal";const s=document.createElement("div");if(s.className="selectyc-mobile-header",this.searchInputActive){const n=document.createElement("input");n.type="text",n.className="selectyc-mobile-search",n.placeholder="Buscar...",n.addEventListener("input",()=>{this.filter=n.value,this.#l.innerHTML="",this.#D()}),this.#C=n,s.appendChild(n)}const i=document.createElement("button");i.innerHTML="✕",i.className="selectyc-mobile-close",i.onclick=()=>this.#x(),s.appendChild(i);const l=document.createElement("div");l.className="selectyc-mobile-body",l.addEventListener("scroll",async()=>{if(this.#L||this.#c)return;const{scrollTop:n,scrollHeight:h,clientHeight:r}=l;n+r>=h-10&&(this.#L=!0,await this.#q(),this.#L=!1)}),e.appendChild(s),e.appendChild(l),t.appendChild(e),document.body.appendChild(t),this.#n=t,this.#l=l}#_(){const t=document.getElementById(this.id);this.name=t.name,this.#E=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.#f(e.value);this.isMultiple?this.#t.push({value:i,text:s}):this.#t[0]={value:i,text:s}}this.#v.push({id:this.#f(e.value),text:e.text}),this.data=this.#v})}#M(){if(this.isMobil){this.#z();return}if(this.filter=null,this.searchInputActive&&(this.#a.value=null),this.#d)return;this.#d=!0;const t=this.#m.getBoundingClientRect(),e=window.innerHeight-t.bottom,s=t.top;this.#i.style.position="fixed",this.#e.style.width=t.width+"px";const i=270;this.#s.classList.remove(`round${this.bodyRound}`),this.#i.classList.remove("dropdown-up"),this.#s.classList.remove(`round${this.bodyRound}t-up`),this.#s.classList.remove(`round${this.bodyRound}t`),e<i&&s>e?(this.#i.style.top="auto",this.#i.style.bottom=window.innerHeight-t.top+"px",this.#i.classList.add("dropdown-up"),this.#s.classList.add(`round${this.bodyRound}t-up`),this.#e.classList.remove("global-dropdown-round")):(this.#i.style.bottom="auto",this.#i.style.top=t.bottom+"px",this.#s.classList.add(`round${this.bodyRound}t`),this.#e.classList.add("global-dropdown-round")),this.#i.style.left=t.left+"px",this.#e.style.display="block",this.searchInputActive&&(this.#a.style.display="block",this.#a.style.width=t.width+"px",this.#a.focus()),this.#N()}#z(){this.#j(),this.filter=null,this.#C&&(this.#C.value=""),this.#n.style.display="flex",this.#n.style.justifyContent="center",this.#n.style.alignItems="center",document.body.style.overflow="hidden",this.#D()}#o(){this.isMobil||this.#d&&(this.#d=!1,this.#e.innerHTML="",this.#e.style.display="none",this.searchInputActive&&(this.#a.style.display="none"),this.#s.classList.add(`round${this.bodyRound}`))}#x(){this.#n&&(this.#n.style.display="none",document.body.style.overflow="")}async#p(){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.#v,...s].map(i=>[i.id,i])).values()),this.data}async#N(){this.#h({id:"loading",text:"cargando ..."}),this.records=10+this.#t.length,this.#b=!1;let t=await this.#p();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.#O.toLowerCase())&&!e.includes(s.id)&&this.#h(s)}),this.#e.hasChildNodes()||this.#h({id:"sin_resultados",text:"sin resultados ..."})}async#D(){this.records=10+this.#t.length,this.#c=!1,this.#l.innerHTML='<div class="mobile-loading">cargando...</div>';let t=await this.#p();this.#l.innerHTML="";const e=this.#t.map(i=>i.value);let s=0;t.forEach(i=>{if(i.text.toLowerCase().includes((this.filter||"").toLowerCase())&&!e.includes(i.id)){const l=document.createElement("div");l.className="mobile-option",l.innerText=i.text,l.addEventListener("touchstart",()=>{l.classList.add("active-touch")}),l.addEventListener("touchend",()=>{l.classList.remove("active-touch")}),l.addEventListener("touchcancel",()=>{l.classList.remove("active-touch")}),l.onclick=()=>{this.#S(i.text,i.id),this.onSelect&&this.onSelect(i.id,this),this.#x()},this.#l.appendChild(l),s++}}),s===0&&(this.#l.innerHTML='<div class="mobile-empty">Sin resultados</div>',this.#c=!0)}async#P(){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.#p();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.#h(n)}),this.#b=l===this.#e.lastChild.dataset.value}async#q(){if(this.#c)return;const t=this.#t.map(n=>n.value);let e=this.filter||"",s=this.data.map(n=>n.id);this.records=this.records+10+this.#t.length;let i=await this.#p(),l=0;i.forEach(n=>{if(n.text.toLowerCase().includes(e.toLowerCase())&&!t.includes(n.id)&&!s.includes(n.id)){const h=document.createElement("div");h.className="mobile-option",h.innerText=n.text,h.onclick=()=>{this.#S(n.text,n.id),this.onSelect&&this.onSelect(n.id,this)},this.#l.appendChild(h),l++}}),l===0&&(this.#c=!0)}#S(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),this.isMultiple?this.#T():this.#F()}#F(){this.#r.value=null,this.#w.value=null,this.#r.value=this.#t.length>0?this.#t[0].text:null,this.#w.value=this.#t.length>0?this.#t[0].text:null,this.#r.placeholder=this.singleLabel,this.#y.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)}#T(){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)})}#V(t){this.#t=this.#t.filter(e=>this.#f(e.value)!==this.#f(t)),this.#u(t)}#U(t){const{scrollTop:e,scrollHeight:s,clientHeight:i}=this.#e;t.target.lastChild!==null&&(t.target.lastChild.dataset.value==="loading"||this.#b||e+(i+1)>=s&&(this.#h({id:"loading",text:"cargando ..."}),this.#P()))}#f(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.#g===void 0&&t!==null||e?this.#A():this.#g!==void 0&&this.#u()}}d.selectyc=o,Object.defineProperty(d,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 o{#t=[];#g;#w=[];#m;#b;#s;#e;#a;#r;#p;#i;#h=!1;#E=!1;#C=!1;#O="";#I='<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>';#n;#l;#x;#S=!1;#c=!1;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,this.isMobil=/Android|iPhone|iPad|iPod/i.test(navigator.userAgent),window.selects[t]=this}static set(t){return new o(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.#u(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}setHeight(t){return this.height=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)}setDisableSelect(t){return this.disabled=t,this}setRequiredSelect(t){return this.#p.required=t,this}#A(){this.#H(),this.#s.addEventListener("click",t=>{if(!this.disabled){if(t.target.classList.contains("remove-tag")){this.#V(t.target.getAttribute("data-value")),this.onUnselect!==void 0&&this.onUnselect(t.target.getAttribute("data-value"),this),this.#h&&this.#o(),this.#M();return}this.#h?this.#o():this.#M()}}),document.addEventListener("click",t=>{this.isMobil&&t.target.classList.contains("selectyc-mobile-overlay")&&this.#f(),!this.#m.contains(t.target)&&!this.#e.contains(t.target)&&!t.target.classList.contains("remove-tag")&&this.#o()}),window.onresize=()=>{this.#o()},window.addEventListener("scroll",()=>{this.isMobil||this.#o()}),this.isMultiple&&this.#T()}#H(){this.#_();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.height!==void 0&&(s.style.height=this.height),this.isMultiple||(s=this.#R(s)),e.appendChild(s),e.appendChild(this.#k()),t.appendChild(e);const i=document.getElementById(this.id),l=document.createElement("input");l.name=i.name,l.setAttribute("data-id",i.id),this.rootClassName!==""&&(l.className=i.className),l.style.display="none";let n=i.parentNode;t.appendChild(l),n.replaceChild(t,i),this.#g=l,this.#b=s,this.#m=e,this.#s=this.#m.querySelector(".selected-items"),!this.isMultiple&&this.#t.length>0&&(this.#g.value=this.#t[0].value)}#R(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.#I,t.appendChild(this.#B()),t.appendChild(e),t.appendChild(s),this.#r=e,t}#B(){const t=document.createElement("input");return t.type="text",t.required=this.#E,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.#p=t,t}#k(){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.#$());let i;return s.addEventListener("scroll",l=>{i&&clearTimeout(i),i=setTimeout(()=>{this.#U(l)},70)}),e.appendChild(s),this.#e=s,this.#i=e,t.appendChild(e),t}#$(){const t=document.createElement("input");t.type="text",t.id="selectyc_search_input",t.className="search-input",t.placeholder="Buscar...";let e;return t.addEventListener("input",()=>{this.filter=t.value,this.#e.innerHTML="",this.#d({id:"loading",text:"cargando ..."}),e&&clearTimeout(e),e=setTimeout(()=>{this.#e.removeChild(this.#e.lastChild),this.#N()},150)}),this.#a=t,t}#d(t){const e=document.createElement("div");e.className="select-option",e.setAttribute("data-value",t.id),e.textContent=t.text,this.#e.appendChild(e);let s;e.addEventListener("mouseover",()=>{clearTimeout(s),s=setTimeout(()=>{e.style.whiteSpace="normal"},500)}),e.addEventListener("mouseleave",()=>{clearTimeout(s),e.style.whiteSpace="nowrap"}),e.addEventListener("click",()=>{t.id!=="sin_resultados"&&(this.#L(t.text,t.id),this.onSelect!==void 0&&this.onSelect(t.id,this),this.#o())})}#j(){if(this.#n)return;const t=document.createElement("div");t.className="selectyc-mobile-overlay";const e=document.createElement("div");e.className="selectyc-mobile-modal";const s=document.createElement("div");if(s.className="selectyc-mobile-header",this.searchInputActive){const n=document.createElement("input");n.type="text",n.className="selectyc-mobile-search",n.placeholder="Buscar...",n.addEventListener("input",()=>{this.filter=n.value,this.#l.innerHTML="",this.#D()}),this.#x=n,s.appendChild(n)}const i=document.createElement("button");i.innerHTML="✕",i.className="selectyc-mobile-close",i.onclick=()=>this.#f(),s.appendChild(i);const l=document.createElement("div");l.className="selectyc-mobile-body",l.addEventListener("scroll",async()=>{if(this.#S||this.#c)return;const{scrollTop:n,scrollHeight:d,clientHeight:r}=l;n+r>=d-10&&(this.#S=!0,await this.#P(),this.#S=!1)}),e.appendChild(s),e.appendChild(l),t.appendChild(e),document.body.appendChild(t),this.#n=t,this.#l=l}#_(){const t=document.getElementById(this.id);this.name=t.name,this.#E=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.#v(e.value);this.isMultiple?this.#t.push({value:i,text:s}):this.#t[0]={value:i,text:s}}this.#w.push({id:this.#v(e.value),text:e.text}),this.data=this.#w})}#M(){if(this.isMobil){this.#q();return}if(this.filter=null,this.searchInputActive&&(this.#a.value=null),this.#h)return;this.#h=!0;const t=this.#m.getBoundingClientRect(),e=window.innerHeight-t.bottom,s=t.top;this.#i.style.position="fixed",this.#e.style.width=t.width+"px";const i=270;this.#s.classList.remove(`round${this.bodyRound}`),this.#i.classList.remove("dropdown-up"),this.#s.classList.remove(`round${this.bodyRound}t-up`),this.#s.classList.remove(`round${this.bodyRound}t`),e<i&&s>e?(this.#i.style.top="auto",this.#i.style.bottom=window.innerHeight-t.top+"px",this.#i.classList.add("dropdown-up"),this.#s.classList.add(`round${this.bodyRound}t-up`),this.#e.classList.remove("global-dropdown-round")):(this.#i.style.bottom="auto",this.#i.style.top=t.bottom+"px",this.#s.classList.add(`round${this.bodyRound}t`),this.#e.classList.add("global-dropdown-round")),this.#i.style.left=t.left+"px",this.#e.style.display="block",this.searchInputActive&&(this.#a.style.display="block",this.#a.style.width=t.width+"px",this.#a.focus()),this.#N()}#q(){this.#j(),this.filter=null,this.#x&&(this.#x.value=""),this.#n.style.display="flex",this.#n.style.justifyContent="center",this.#n.style.alignItems="center",document.body.style.overflow="hidden",this.#D()}#o(){this.isMobil||this.#h&&(this.#h=!1,this.#e.innerHTML="",this.#e.style.display="none",this.searchInputActive&&(this.#a.style.display="none"),this.#s.classList.add(`round${this.bodyRound}`))}#f(){this.#n&&(this.#n.style.display="none",document.body.style.overflow="")}async#y(){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.#w,...s].map(i=>[i.id,i])).values()),this.data}async#N(){this.#d({id:"loading",text:"cargando ..."}),this.records=10+this.#t.length,this.#C=!1;let t=await this.#y();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.#O.toLowerCase())&&!e.includes(s.id)&&this.#d(s)}),this.#e.hasChildNodes()||this.#d({id:"sin_resultados",text:"sin resultados ..."})}async#D(){this.records=10+this.#t.length,this.#c=!1,this.#l.innerHTML='<div class="mobile-loading">cargando...</div>';let t=await this.#y();this.#l.innerHTML="";const e=this.#t.map(i=>i.value);let s=0;t.forEach(i=>{if(i.text.toLowerCase().includes((this.filter||"").toLowerCase())&&!e.includes(i.id)){const l=document.createElement("div");l.className="mobile-option",l.innerText=i.text,l.onclick=()=>{this.#L(i.text,i.id),this.onSelect&&this.onSelect(i.id,this),this.#f()},this.#l.appendChild(l),s++}}),s===0&&(this.#l.innerHTML='<div class="mobile-empty">Sin resultados</div>',this.#c=!0)}async#z(){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.#y();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.#d(n)}),this.#C=l===this.#e.lastChild.dataset.value}async#P(){if(this.#c)return;const t=this.#t.map(n=>n.value);let e=this.filter||"",s=this.data.map(n=>n.id);this.records=this.records+10+this.#t.length;let i=await this.#y(),l=0;i.forEach(n=>{if(n.text.toLowerCase().includes(e.toLowerCase())&&!t.includes(n.id)&&!s.includes(n.id)){const d=document.createElement("div");d.className="mobile-option",d.innerText=n.text,d.onclick=()=>{this.#L(n.text,n.id),this.onSelect&&this.onSelect(n.id,this),this.#f()},this.#l.appendChild(d),l++}}),l===0&&(this.#c=!0)}#L(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),this.isMultiple?this.#T():this.#F()}#F(){this.#r.value=null,this.#p.value=null,this.#r.value=this.#t.length>0?this.#t[0].text:null,this.#p.value=this.#t.length>0?this.#t[0].text:null,this.#r.placeholder=this.singleLabel,this.#g.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)}#T(){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)})}#V(t){this.#t=this.#t.filter(e=>this.#v(e.value)!==this.#v(t)),this.#u(t)}#U(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.#d({id:"loading",text:"cargando ..."}),this.#z()))}#v(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.#b===void 0&&t!==null||e?this.#A():this.#b!==void 0&&this.#u()}}h.selectyc=o,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.27",
4
+ "version": "0.0.29",
5
5
  "main": "./dist/selectyc.umd.js",
6
6
  "module": "./dist/selectyc.js",
7
7
  "type": "module",