selectyc 0.0.25 → 0.0.26

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.css CHANGED
@@ -1 +1 @@
1
- .custom-multiselect{position:relative;width:100%}.selected-items{display:flex;gap:5px;padding:0 8px;border:1px solid;cursor:pointer;align-items:center;@apply bg-gray-50 border-gray-300 text-gray-900 text-sm focus:ring-blue-500 focus:border-[2px] focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500;}.horizontal-overflow{flex-wrap:nowrap;height:42px;white-space:nowrap;overflow-x:auto;overflow-y:hidden}.vertical-overflow{flex-wrap:wrap;min-height:42px;height:auto;max-height:120px;white-space:nowrap;overflow-x:auto;overflow-y:auto}.round{@apply rounded-lg;}.roundt{@apply rounded-t-lg;}.round-l{@apply rounded-l-lg;}.round-r{@apply rounded-r-lg;}.round-lt{@apply rounded-tl-lg;}.round-rt{@apply rounded-tr-lg;}.selected-items::-webkit-scrollbar{height:6px;width:8px}.selected-items::-webkit-scrollbar-thumb{border-radius:1rem;@apply bg-cyan-400 dark:bg-cyan-700;}.selected-items::-webkit-scrollbar-thumb:hover{@apply bg-cyan-500 dark:bg-cyan-600;}.custom-single-select{width:100%;padding-left:.2rem;border:0px solid;background:transparent;font-size:.9rem;cursor:pointer;white-space:nowrap;text-overflow:ellipsis}.custom-single-select:focus{border:0px solid transparent;outline:none;box-shadow:none}.custom-single-select::placeholder{opacity:.7;font-style:italic;font-size:14px}.selected-tag{background-color:#007bff;color:#fff;padding:4px 8px;border-radius:12px;display:inline-flex;align-items:center;gap:5px;font-size:14px;white-space:nowrap;flex:0 0 auto}.remove-tag{cursor:pointer;font-weight:700;border:solid 0px;border-radius:.5rem;padding:1px 6px;@apply hover:bg-blue-400 dark:hover:bg-sky-800;}.global-dropdown{background-color:#374151;max-height:200px;overflow-y:auto;display:none;z-index:999;box-shadow:0 2px 8px #0003;border-bottom-left-radius:.6rem;border-bottom-right-radius:.6rem;@apply bg-gray-50 dark:bg-gray-700;}.global-dropdown::-webkit-scrollbar{width:10px;border-radius:.6rem;@apply bg-gray-200 dark:bg-gray-400;}.global-dropdown::-webkit-scrollbar-thumb{border-radius:.6rem;@apply bg-gray-400 dark:bg-gray-600;}.search-input{width:100%;padding:3px 10px;border:1px solid;display:none;z-index:999;outline:none;color:#000;font-size:.9rem;@apply bg-white dark:bg-gray-600 dark:border-gray-500 dark:text-white border-blue-500;}.search-input:focus{@apply dark:border-gray-500 border-blue-500;}.search-input::placeholder{@apply text-gray-700 dark:text-gray-400;}.select-option{padding:3px 10px;cursor:pointer;font-size:.9rem;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}.select-option:hover{background-color:#3777de;color:#fff;white-space:normal;text-overflow:ellipsis}
1
+ .custom-multiselect{position:relative;width:100%}.selected-items{display:flex;gap:5px;padding:0 8px;border:1px solid;cursor:pointer;align-items:center;@apply bg-gray-50 border-gray-300 text-gray-900 text-sm focus:ring-blue-500 focus:border-[2px] focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500;}.horizontal-overflow{flex-wrap:nowrap;height:42px;white-space:nowrap;overflow-x:auto;overflow-y:hidden}.vertical-overflow{flex-wrap:wrap;min-height:42px;height:auto;max-height:120px;white-space:nowrap;overflow-x:auto;overflow-y:auto}.round{@apply rounded-lg;}.roundt{@apply rounded-t-lg;}.round-l{@apply rounded-l-lg;}.round-r{@apply rounded-r-lg;}.round-lt{@apply rounded-tl-lg;}.round-rt{@apply rounded-tr-lg;}.roundt-up{@apply rounded-b-lg;}.round-lt-up{@apply rounded-bl-lg;}.round-rt-up{@apply rounded-br-lg;}.selected-items::-webkit-scrollbar{height:6px;width:8px}.selected-items::-webkit-scrollbar-thumb{border-radius:1rem;@apply bg-cyan-400 dark:bg-cyan-700;}.selected-items::-webkit-scrollbar-thumb:hover{@apply bg-cyan-500 dark:bg-cyan-600;}.custom-single-select{width:100%;padding-left:.2rem;border:0px solid;background:transparent;font-size:.9rem;cursor:pointer;white-space:nowrap;text-overflow:ellipsis}.custom-single-select:focus{border:0px solid transparent;outline:none;box-shadow:none}.custom-single-select::placeholder{opacity:.7;font-style:italic;font-size:14px}.selected-tag{background-color:#007bff;color:#fff;padding:4px 8px;border-radius:12px;display:inline-flex;align-items:center;gap:5px;font-size:14px;white-space:nowrap;flex:0 0 auto}.remove-tag{cursor:pointer;font-weight:700;border:solid 0px;border-radius:.5rem;padding:1px 6px;@apply hover:bg-blue-400 dark:hover:bg-sky-800;}.global-dropdown{background-color:#374151;max-height:200px;overflow-y:auto;display:none;z-index:999;box-shadow:0 2px 8px #0003;@apply bg-gray-50 dark:bg-gray-700;}.global-dropdown-round{border-bottom-left-radius:.6rem;border-bottom-right-radius:.6rem}.global-dropdown::-webkit-scrollbar{width:10px;border-radius:.6rem;@apply bg-gray-200 dark:bg-gray-400;}.global-dropdown::-webkit-scrollbar-thumb{border-radius:.6rem;@apply bg-gray-400 dark:bg-gray-600;}.search-input{width:100%;padding:3px 10px;border:1px solid;display:none;z-index:999;outline:none;color:#000;font-size:.9rem;@apply bg-white dark:bg-gray-600 dark:border-gray-500 dark:text-white border-blue-500;}.search-input:focus{@apply dark:border-gray-500 border-blue-500;}.search-input::placeholder{@apply text-gray-700 dark:text-gray-400;}.select-option{padding:3px 10px;cursor:pointer;font-size:.9rem;overflow:hidden;white-space:nowrap;text-overflow:ellipsis}.select-option:hover{background-color:#3777de;color:#fff}.selectyc-mobile-overlay{position:fixed;inset:0;background:#0006;z-index:9999;display:none}.selectyc-mobile-modal{width:80%;height:70vh;border-radius:16px;display:flex;flex-direction:column;animation:slideUp .25s ease;@apply bg-white dark:bg-gray-600;}@keyframes slideUp{0%{transform:translateY(100%)}to{transform:translateY(0)}}.selectyc-mobile-header{padding:12px;display:flex;gap:10px;align-items:center;@apply border-b border-gray-300 dark:border-gray-500;}.selectyc-mobile-close{border:none;background:none;font-size:20px;@apply text-gray-700 dark:text-gray-400 font-bold px-2;}.selectyc-mobile-search{flex:1;padding:10px;border-radius:8px;@apply bg-white dark:bg-gray-600 dark:border-gray-500 dark:text-white border-gray-300 focus:border-blue-500 dark:focus:border-blue-400;}.selectyc-mobile-search::placeholder{@apply text-gray-700 dark:text-gray-400;}.selectyc-mobile-body{flex:1;overflow-y:auto;-webkit-overflow-scrolling:touch}.mobile-loading,.mobile-empty{padding:20px;text-align:center;color:#999}.mobile-option{padding:10px 16px;font-size:14px;cursor:pointer;transition:background .15s ease,transform .05s ease;@apply border-b border-gray-300 dark:border-gray-500 dark:text-gray-200 text-black;}.mobile-option:hover{background:#f2f4f7}.mobile-option:active{background:#e6f0ff;transform:scale(.98)}.mobile-option.active-touch{background:#e6f0ff}
package/dist/selectyc.js CHANGED
@@ -1,10 +1,10 @@
1
1
  import './selectyc.css';
2
- class l {
2
+ class h {
3
3
  constructor(t) {
4
4
  this.route = t;
5
5
  }
6
6
  static make(t) {
7
- return new l(t);
7
+ return new h(t);
8
8
  }
9
9
  setMethod(t) {
10
10
  return this.method = t, this;
@@ -46,30 +46,36 @@ class l {
46
46
  }
47
47
  }
48
48
  }
49
- class h {
49
+ class d {
50
50
  #t = [];
51
- #u;
52
- #p = [];
53
- #r;
54
- #f;
51
+ #v;
52
+ #y = [];
53
+ #m;
54
+ #g;
55
55
  #s;
56
56
  #e;
57
+ #a;
58
+ #r;
59
+ #w;
57
60
  #i;
61
+ #h = !1;
62
+ #E = !1;
63
+ #b = !1;
64
+ #O = "";
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
+ //{{-------- Mobil variables ---------}}
67
+ #n;
58
68
  #l;
59
- #m;
60
- #o;
61
- #n = !1;
62
- #y = !1;
63
- #g = !1;
64
- #S = "";
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>';
69
+ #C;
70
+ #L = !1;
71
+ #c = !1;
66
72
  constructor(t) {
67
73
  if (window.selects === void 0 && (window.selects = []), window.selects[t] !== void 0)
68
74
  return window.selects[t];
69
- 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;
75
+ 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;
70
76
  }
71
77
  static set(t) {
72
- return new h(t);
78
+ return new d(t);
73
79
  }
74
80
  setData(t) {
75
81
  return this.data = t, this;
@@ -81,7 +87,7 @@ class h {
81
87
  return this.clearButton = !0, this;
82
88
  }
83
89
  setSelectedOptions(t) {
84
- this.#t = t, this.#d(t);
90
+ this.#t = t, this.#u(t);
85
91
  }
86
92
  getSelectedOptions() {
87
93
  return this.#t;
@@ -127,100 +133,149 @@ class h {
127
133
  }
128
134
  cleanSelection() {
129
135
  const t = this.#t;
130
- this.#t = [], this.#d(t);
136
+ this.#t = [], this.#u(t);
131
137
  }
132
138
  setDisableSelect(t) {
133
139
  return this.disabled = t, this;
134
140
  }
135
- #D() {
136
- this.#E(), this.#s.addEventListener("click", (t) => {
141
+ #A() {
142
+ this.#H(), this.#s.addEventListener("click", (t) => {
137
143
  if (!this.disabled) {
138
144
  if (t.target.classList.contains("remove-tag")) {
139
- 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();
145
+ 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();
140
146
  return;
141
147
  }
142
- this.#n ? this.#a() : this.#v();
148
+ this.#h ? this.#o() : this.#M();
143
149
  }
144
150
  }), document.addEventListener("click", (t) => {
145
- !this.#r.contains(t.target) && !this.#e.contains(t.target) && !t.target.classList.contains("remove-tag") && this.#a();
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();
146
152
  }), window.onresize = () => {
147
- this.#a();
153
+ this.#o();
148
154
  }, window.addEventListener("scroll", () => {
149
- this.#a();
150
- }), this.isMultiple && this.#C();
155
+ this.isMobil || this.#o();
156
+ }), this.isMultiple && this.#T();
151
157
  }
152
- // Draw functions
153
- #E() {
154
- this.#M();
158
+ //{{-------- Draw functions ---------}}
159
+ #H() {
160
+ this.#j();
155
161
  const t = document.createElement("div");
156
162
  t.className = "main-div-selectyc", t.style.width = this.width, t.id = `selectyc_main_div_${this.id}`;
157
163
  const e = document.createElement("div");
158
164
  e.className = "custom-multiselect";
159
165
  let s = document.createElement("div");
160
- 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.#L(s)), e.appendChild(s), e.appendChild(this.#O()), t.appendChild(e);
161
- const i = document.getElementById(this.id), n = document.createElement("input");
162
- n.name = i.name, n.setAttribute("data-id", i.id), this.rootClassName !== "" && (n.className = i.className), n.style.display = "none";
163
- let a = i.parentNode;
164
- 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);
166
+ 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);
165
171
  }
166
- #L(t) {
172
+ #R(t) {
167
173
  const e = document.createElement("input");
168
174
  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;
169
175
  const s = document.createElement("div");
170
- return s.innerHTML = this.#x, t.appendChild(this.#N()), t.appendChild(e), t.appendChild(s), this.#l = e, t;
176
+ return s.innerHTML = this.#I, t.appendChild(this.#B()), t.appendChild(e), t.appendChild(s), this.#r = e, t;
171
177
  }
172
- #N() {
178
+ #B() {
173
179
  const t = document.createElement("input");
174
- 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;
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;
175
181
  }
176
- #O() {
182
+ #k() {
177
183
  const t = document.createElement("div");
178
184
  t.setAttribute("style", "position:fixed; z-index:999;");
179
185
  const e = document.createElement("div");
180
186
  e.setAttribute("style", "position:absolute;");
181
187
  const s = document.createElement("div");
182
- s.className = "global-dropdown", this.searchInputActive && e.appendChild(this.#I());
188
+ s.className = "global-dropdown", this.searchInputActive && e.appendChild(this.#$());
183
189
  let i;
184
- return s.addEventListener("scroll", (n) => {
190
+ return s.addEventListener("scroll", (l) => {
185
191
  i && clearTimeout(i), i = setTimeout(() => {
186
- this.#k(n);
192
+ this.#U(l);
187
193
  }, 70);
188
- }), e.appendChild(s), this.#e = s, this.#o = e, t.appendChild(e), t;
194
+ }), e.appendChild(s), this.#e = s, this.#i = e, t.appendChild(e), t;
189
195
  }
190
- #I() {
196
+ #$() {
191
197
  const t = document.createElement("input");
192
- return t.type = "text", t.id = "selectyc_search_input", t.className = "search-input", t.placeholder = "Buscar...", t.addEventListener("input", () => {
193
- this.filter = t.value, this.#e.innerHTML = "", this.#b();
194
- }), this.#i = t, t;
198
+ t.type = "text", t.id = "selectyc_search_input", t.className = "search-input", t.placeholder = "Buscar...";
199
+ let e;
200
+ return t.addEventListener("input", () => {
201
+ this.filter = t.value, this.#e.innerHTML = "", this.#d({ id: "loading", text: "cargando ..." }), e && clearTimeout(e), e = setTimeout(() => {
202
+ this.#e.removeChild(this.#e.lastChild), this.#N();
203
+ }, 150);
204
+ }), this.#a = t, t;
195
205
  }
196
- #h(t) {
206
+ #d(t) {
197
207
  const e = document.createElement("div");
198
- e.className = "select-option", e.setAttribute("data-value", t.id), e.textContent = t.text, this.#e.appendChild(e), e.addEventListener("click", () => {
199
- t.id !== "sin_resultados" && (this.#R(t.text, t.id), this.onSelect !== void 0 && this.onSelect(t.id, this), this.#a());
208
+ e.className = "select-option", e.setAttribute("data-value", t.id), e.textContent = t.text, this.#e.appendChild(e);
209
+ let s;
210
+ e.addEventListener("mouseover", () => {
211
+ clearTimeout(s), s = setTimeout(() => {
212
+ e.style.whiteSpace = "normal";
213
+ }, 500);
214
+ }), e.addEventListener("mouseleave", () => {
215
+ clearTimeout(s), e.style.whiteSpace = "nowrap";
216
+ }), 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());
200
218
  });
201
219
  }
202
- // Functions
203
- #M() {
220
+ //{{-------- Mobile draw modal ---------}}
221
+ #_() {
222
+ if (this.#n) return;
223
+ const t = document.createElement("div");
224
+ t.className = "selectyc-mobile-overlay";
225
+ const e = document.createElement("div");
226
+ e.className = "selectyc-mobile-modal";
227
+ const s = document.createElement("div");
228
+ 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);
233
+ }
234
+ 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;
242
+ }
243
+ //{{-------- Functions ---------}}
244
+ #j() {
204
245
  const t = document.getElementById(this.id);
205
- this.name = t.name, this.#y = t.required, this.rootClassName = t.className, this.disabled = t.disabled, Array.from(t.options).forEach((e) => {
246
+ this.name = t.name, this.#E = t.required, this.rootClassName = t.className, this.disabled = t.disabled, Array.from(t.options).forEach((e) => {
206
247
  if (e.outerHTML.includes("selected")) {
207
- const s = e.text, i = this.#c(e.value);
248
+ const s = e.text, i = this.#f(e.value);
208
249
  this.isMultiple ? this.#t.push({ value: i, text: s }) : this.#t[0] = { value: i, text: s };
209
250
  }
210
- this.#p.push({ id: this.#c(e.value), text: e.text }), this.data = this.#p;
251
+ this.#y.push({ id: this.#f(e.value), text: e.text }), this.data = this.#y;
211
252
  });
212
253
  }
213
- #v() {
214
- if (this.filter = null, this.searchInputActive && (this.#i.value = null), this.#n)
254
+ //{{-------- Show dropdown ---------}}
255
+ #M() {
256
+ if (this.isMobil) {
257
+ this.#z();
215
258
  return;
216
- this.#n = !0, this.#s.classList.remove(`round${this.bodyRound}`), this.#s.classList.add(`round${this.bodyRound}t`);
217
- const t = this.#r.getBoundingClientRect();
218
- 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();
259
+ }
260
+ if (this.filter = null, this.searchInputActive && (this.#a.value = null), this.#h) return;
261
+ this.#h = !0;
262
+ const t = this.#m.getBoundingClientRect(), e = window.innerHeight - t.bottom, s = t.top;
263
+ this.#i.style.position = "fixed", this.#e.style.width = t.width + "px";
264
+ const i = 270;
265
+ 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
+ }
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();
269
+ }
270
+ //{{-------- Hide dropdown ---------}}
271
+ #o() {
272
+ 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}`));
219
273
  }
220
- #a() {
221
- 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}`));
274
+ #x() {
275
+ this.#n && (this.#n.style.display = "none", document.body.style.overflow = "");
222
276
  }
223
- async #w() {
277
+ //{{-------- Render options ---------}}
278
+ async #p() {
224
279
  if (this.RS === void 0)
225
280
  return this.data;
226
281
  let t = { records: this.records, filter: this.filter };
@@ -228,43 +283,80 @@ class h {
228
283
  const i = this.bodyData();
229
284
  t = { ...t, ...i };
230
285
  } else this.bodyData !== null && (t = { ...t, ...this.bodyData });
231
- const e = await l.make(this.RS).addData(t).setMethod("POST").go(), s = Array.isArray(e) ? e : e.data;
232
- return this.data = Array.from(new Map([...this.#p, ...s].map((i) => [i.id, i])).values()), this.data;
286
+ 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;
233
288
  }
234
- async #b() {
235
- this.#h({ id: "loading", text: "cargando ..." }), this.records = 10 + this.#t.length, this.#g = !1;
236
- let t = await this.#w();
289
+ async #N() {
290
+ this.#d({ id: "loading", text: "cargando ..." }), this.records = 10 + this.#t.length, this.#b = !1;
291
+ let t = await this.#p();
237
292
  const e = this.#t.map((s) => s.value);
238
293
  this.#e.lastChild.dataset.value === "loading" && this.#e.removeChild(this.#e.lastChild), t.forEach((s) => {
239
- s.text.toLowerCase().includes(this.#S.toLowerCase()) && !e.includes(s.id) && this.#h(s);
240
- }), this.#e.hasChildNodes() || this.#h({ id: "sin_resultados", text: "sin resultados ..." });
294
+ s.text.toLowerCase().includes(this.#O.toLowerCase()) && !e.includes(s.id) && this.#d(s);
295
+ }), this.#e.hasChildNodes() || this.#d({ id: "sin_resultados", text: "sin resultados ..." });
296
+ }
297
+ 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
+ const e = this.#t.map((i) => i.value);
302
+ let s = 0;
303
+ t.forEach((i) => {
304
+ 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++;
315
+ }
316
+ }), s === 0 && (this.#l.innerHTML = '<div class="mobile-empty">Sin resultados</div>', this.#c = !0);
241
317
  }
242
- async #A() {
243
- const t = this.#t.map((a) => a.value);
244
- let e = this.filter === null ? "" : this.filter, s = this.data.map((a) => a.id);
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);
245
321
  this.records = this.records + 10 + this.#t.length;
246
- let i = await this.#w();
322
+ let i = await this.#p();
247
323
  this.#e.lastChild.dataset.value === "loading" && this.#e.removeChild(this.#e.lastChild);
248
- const n = this.#e.lastChild.dataset.value;
249
- i.forEach((a) => {
250
- a.text.toLowerCase().includes(e.toLowerCase()) && !t.includes(a.id) && !s.includes(a.id) && this.#h(a);
251
- }), this.#g = n === this.#e.lastChild.dataset.value;
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;
328
+ }
329
+ async #F() {
330
+ 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);
333
+ 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)) {
337
+ 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++;
341
+ }
342
+ }), l === 0 && (this.#c = !0);
252
343
  }
253
- #R(t, e) {
254
- this.#t.find((i) => i.value === e) || (this.isMultiple || (this.#t = []), this.#t.push({ text: t, value: e })), this.#d(e);
344
+ #S(t, e) {
345
+ this.#t.find((i) => i.value === e) || (this.isMultiple || (this.#t = []), this.#t.push({ text: t, value: e })), this.#u(e);
255
346
  }
256
- #d(t) {
257
- this.onChange !== void 0 && this.onChange(t, this), this.isMultiple ? this.#C() : this.#T();
347
+ //{{-------- Render main box ---------}}
348
+ #u(t) {
349
+ this.onChange !== void 0 && this.onChange(t, this), this.isMultiple ? this.#T() : this.#P();
258
350
  }
259
- #T() {
260
- 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;
261
- const t = this.#l.parentNode, e = t.firstChild;
351
+ #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;
353
+ const t = this.#r.parentNode, e = t.firstChild;
262
354
  if (e.className === "remove-tag" && e.remove(), !this.clearButton || this.#t.length <= 0)
263
355
  return;
264
356
  const s = document.createElement("span");
265
357
  s.dataset.value = this.#t[0].value, s.innerHTML = "x", s.className = "remove-tag", t.insertBefore(s, t.firstChild);
266
358
  }
267
- #C() {
359
+ #T() {
268
360
  if (this.#s.innerHTML = "", this.#t.length <= 0) {
269
361
  this.#s.appendChild(document.createElement("div"));
270
362
  return;
@@ -274,21 +366,21 @@ class h {
274
366
  s.className = "selected-tag", s.innerHTML = `${t} <span class="remove-tag" data-value="${e}">x</span>`, this.#s.appendChild(s);
275
367
  });
276
368
  }
277
- #B(t) {
278
- this.#t = this.#t.filter((e) => this.#c(e.value) !== this.#c(t)), this.#d(t);
369
+ #V(t) {
370
+ this.#t = this.#t.filter((e) => this.#f(e.value) !== this.#f(t)), this.#u(t);
279
371
  }
280
- #k(t) {
372
+ #U(t) {
281
373
  const { scrollTop: e, scrollHeight: s, clientHeight: i } = this.#e;
282
- t.target.lastChild !== null && (t.target.lastChild.dataset.value === "loading" || this.#g || e + (i + 1) >= s && (this.#h({ id: "loading", text: "cargando ..." }), this.#A()));
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()));
283
375
  }
284
- #c(t) {
376
+ #f(t) {
285
377
  return !isNaN(t) && !isNaN(parseFloat(t)) ? parseInt(t) : t;
286
378
  }
287
379
  async render() {
288
380
  const t = document.getElementById(this.id), e = t === null ? !1 : t.outerHTML.includes("<select");
289
- this.#f === void 0 && t !== null || e ? this.#D() : this.#f !== void 0 && this.#d();
381
+ this.#g === void 0 && t !== null || e ? this.#A() : this.#g !== void 0 && this.#u();
290
382
  }
291
383
  }
292
384
  export {
293
- h as selectyc
385
+ d as selectyc
294
386
  };
@@ -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}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.#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.#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.height!==void 0&&(s.style.height=this.height),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.#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.#l())})}#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()}#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}#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.#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(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"})});
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.25",
4
+ "version": "0.0.26",
5
5
  "main": "./dist/selectyc.umd.js",
6
6
  "module": "./dist/selectyc.js",
7
7
  "type": "module",