selectyc 0.0.29 → 0.0.31
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 +140 -125
- package/dist/selectyc.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/selectyc.js
CHANGED
|
@@ -48,31 +48,32 @@ class h {
|
|
|
48
48
|
}
|
|
49
49
|
class d {
|
|
50
50
|
#t = [];
|
|
51
|
-
#
|
|
52
|
-
#
|
|
51
|
+
#w;
|
|
52
|
+
#c = [];
|
|
53
53
|
#m;
|
|
54
54
|
#b;
|
|
55
55
|
#s;
|
|
56
56
|
#e;
|
|
57
|
-
#
|
|
58
|
-
#
|
|
59
|
-
#
|
|
57
|
+
#l;
|
|
58
|
+
#h;
|
|
59
|
+
#f;
|
|
60
60
|
#i;
|
|
61
|
-
#
|
|
62
|
-
#
|
|
61
|
+
#d = !1;
|
|
62
|
+
#M = !1;
|
|
63
63
|
#C = !1;
|
|
64
|
-
#
|
|
65
|
-
#
|
|
64
|
+
#A = "";
|
|
65
|
+
#E = !1;
|
|
66
|
+
#B = '<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
67
|
//{{-------- Mobil variables ---------}}
|
|
67
|
-
#l;
|
|
68
68
|
#n;
|
|
69
|
+
#a;
|
|
69
70
|
#x;
|
|
70
71
|
#S = !1;
|
|
71
|
-
#
|
|
72
|
+
#u = !1;
|
|
72
73
|
constructor(t) {
|
|
73
74
|
if (window.selects === void 0 && (window.selects = []), window.selects[t] !== void 0)
|
|
74
75
|
return window.selects[t];
|
|
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;
|
|
76
|
+
this.id = t, this.name, this.data = [], this.isMultiple = !1, this.clearButton = !1, this.singleLabel = " ", this.records = 10, this.page = 0, 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;
|
|
76
77
|
}
|
|
77
78
|
static set(t) {
|
|
78
79
|
return new d(t);
|
|
@@ -87,7 +88,10 @@ class d {
|
|
|
87
88
|
return this.clearButton = !0, this;
|
|
88
89
|
}
|
|
89
90
|
setSelectedOptions(t) {
|
|
90
|
-
this.#t = t, this.#
|
|
91
|
+
this.#t = t, this.#p(t);
|
|
92
|
+
}
|
|
93
|
+
setPagination() {
|
|
94
|
+
return this.#E = !0, this;
|
|
91
95
|
}
|
|
92
96
|
getSelectedOptions() {
|
|
93
97
|
return this.#t;
|
|
@@ -133,80 +137,86 @@ class d {
|
|
|
133
137
|
}
|
|
134
138
|
cleanSelection() {
|
|
135
139
|
const t = this.#t;
|
|
136
|
-
this.#t = [], this.#
|
|
140
|
+
this.#t = [], this.#p(t);
|
|
137
141
|
}
|
|
138
142
|
setDisableSelect(t) {
|
|
139
143
|
return this.disabled = t, this;
|
|
140
144
|
}
|
|
141
145
|
setRequiredSelect(t) {
|
|
142
|
-
return this.#
|
|
146
|
+
return this.#f.required = t, this;
|
|
143
147
|
}
|
|
144
|
-
#
|
|
145
|
-
this.#
|
|
148
|
+
#H() {
|
|
149
|
+
this.#R(), this.#s.addEventListener("click", (t) => {
|
|
146
150
|
if (!this.disabled) {
|
|
147
151
|
if (t.target.classList.contains("remove-tag")) {
|
|
148
|
-
this.#
|
|
152
|
+
this.#K(t.target.getAttribute("data-value")), this.onUnselect !== void 0 && this.onUnselect(t.target.getAttribute("data-value"), this), this.#d && this.#r(), this.#D();
|
|
149
153
|
return;
|
|
150
154
|
}
|
|
151
|
-
this.#
|
|
155
|
+
this.#d ? this.#r() : this.#D();
|
|
152
156
|
}
|
|
153
157
|
}), document.addEventListener("click", (t) => {
|
|
154
|
-
this.isMobil && t.target.classList.contains("selectyc-mobile-overlay") && this.#
|
|
158
|
+
this.isMobil && t.target.classList.contains("selectyc-mobile-overlay") && this.#g(), !this.#m.contains(t.target) && !this.#e.contains(t.target) && !t.target.classList.contains("remove-tag") && this.#r();
|
|
155
159
|
}), window.onresize = () => {
|
|
156
|
-
this.#
|
|
160
|
+
this.#r();
|
|
157
161
|
}, window.addEventListener("scroll", () => {
|
|
158
|
-
this.isMobil || this.#
|
|
159
|
-
}), this.isMultiple && this.#
|
|
162
|
+
this.isMobil || this.#r();
|
|
163
|
+
}), this.isMultiple && this.#O();
|
|
160
164
|
}
|
|
161
165
|
//{{-------- Draw functions ---------}}
|
|
162
|
-
#
|
|
163
|
-
this.#
|
|
166
|
+
#R() {
|
|
167
|
+
this.#P();
|
|
164
168
|
const t = document.createElement("div");
|
|
165
169
|
t.className = "main-div-selectyc", t.style.width = this.width, t.id = `selectyc_main_div_${this.id}`;
|
|
166
170
|
const e = document.createElement("div");
|
|
167
171
|
e.className = "custom-multiselect";
|
|
168
172
|
let s = document.createElement("div");
|
|
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.#
|
|
170
|
-
const i = document.getElementById(this.id),
|
|
171
|
-
|
|
172
|
-
let
|
|
173
|
-
t.appendChild(
|
|
173
|
+
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.#k(s)), e.appendChild(s), e.appendChild(this.#_()), t.appendChild(e);
|
|
174
|
+
const i = document.getElementById(this.id), a = document.createElement("input");
|
|
175
|
+
a.name = i.name, a.setAttribute("data-id", i.id), this.rootClassName !== "" && (a.className = i.className), a.style.display = "none";
|
|
176
|
+
let n = i.parentNode;
|
|
177
|
+
t.appendChild(a), n.replaceChild(t, i), this.#w = a, this.#b = s, this.#m = e, this.#s = this.#m.querySelector(".selected-items"), !this.isMultiple && this.#t.length > 0 && (this.#w.value = this.#t[0].value);
|
|
174
178
|
}
|
|
175
|
-
#
|
|
179
|
+
#k(t) {
|
|
176
180
|
const e = document.createElement("input");
|
|
177
181
|
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;
|
|
178
182
|
const s = document.createElement("div");
|
|
179
|
-
|
|
183
|
+
s.innerHTML = this.#B, t.appendChild(this.#$()), t.appendChild(e), t.appendChild(s), this.#h = e;
|
|
184
|
+
const i = this.#h.parentNode;
|
|
185
|
+
return this.clearButton && this.#t.length > 0 && i.insertBefore(this.#N(), i.firstChild), t;
|
|
180
186
|
}
|
|
181
|
-
#
|
|
187
|
+
#N() {
|
|
188
|
+
const t = document.createElement("span");
|
|
189
|
+
return t.dataset.value = this.#t[0].value, t.innerHTML = "x", t.className = "remove-tag", t;
|
|
190
|
+
}
|
|
191
|
+
#$() {
|
|
182
192
|
const t = document.createElement("input");
|
|
183
|
-
return t.type = "text", t.required = this.#
|
|
193
|
+
return t.type = "text", t.required = this.#M, 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.#f = t, t;
|
|
184
194
|
}
|
|
185
|
-
#
|
|
195
|
+
#_() {
|
|
186
196
|
const t = document.createElement("div");
|
|
187
197
|
t.setAttribute("style", "position:fixed; z-index:999;");
|
|
188
198
|
const e = document.createElement("div");
|
|
189
199
|
e.setAttribute("style", "position:absolute;");
|
|
190
200
|
const s = document.createElement("div");
|
|
191
|
-
s.className = "global-dropdown", this.searchInputActive && e.appendChild(this
|
|
201
|
+
s.className = "global-dropdown", this.searchInputActive && e.appendChild(this.#j());
|
|
192
202
|
let i;
|
|
193
|
-
return s.addEventListener("scroll", (
|
|
203
|
+
return s.addEventListener("scroll", (a) => {
|
|
194
204
|
i && clearTimeout(i), i = setTimeout(() => {
|
|
195
|
-
this.#
|
|
205
|
+
this.#J(a);
|
|
196
206
|
}, 70);
|
|
197
207
|
}), e.appendChild(s), this.#e = s, this.#i = e, t.appendChild(e), t;
|
|
198
208
|
}
|
|
199
|
-
|
|
209
|
+
#j() {
|
|
200
210
|
const t = document.createElement("input");
|
|
201
211
|
t.type = "text", t.id = "selectyc_search_input", t.className = "search-input", t.placeholder = "Buscar...";
|
|
202
212
|
let e;
|
|
203
213
|
return t.addEventListener("input", () => {
|
|
204
|
-
this.filter = t.value, this.#e.innerHTML = "", this.#
|
|
205
|
-
this.#e.removeChild(this.#e.lastChild), this.#
|
|
206
|
-
},
|
|
207
|
-
}), this.#
|
|
214
|
+
this.filter = t.value, this.#e.innerHTML = "", this.#o({ id: "loading", text: "cargando ..." }), clearTimeout(e), e = setTimeout(() => {
|
|
215
|
+
this.page = 0, this.#e.removeChild(this.#e.lastChild), this.#T();
|
|
216
|
+
}, 800);
|
|
217
|
+
}), this.#l = t, t;
|
|
208
218
|
}
|
|
209
|
-
#
|
|
219
|
+
#o(t) {
|
|
210
220
|
const e = document.createElement("div");
|
|
211
221
|
e.className = "select-option", e.setAttribute("data-value", t.id), e.textContent = t.text, this.#e.appendChild(e);
|
|
212
222
|
let s;
|
|
@@ -217,143 +227,148 @@ class d {
|
|
|
217
227
|
}), e.addEventListener("mouseleave", () => {
|
|
218
228
|
clearTimeout(s), e.style.whiteSpace = "nowrap";
|
|
219
229
|
}), e.addEventListener("click", () => {
|
|
220
|
-
t.id !== "sin_resultados" && (this.#L(t.text, t.id), this.onSelect !== void 0 && this.onSelect(t.id, this), this.#
|
|
230
|
+
t.id !== "sin_resultados" && (this.#L(t.text, t.id), this.onSelect !== void 0 && this.onSelect(t.id, this), this.#r());
|
|
221
231
|
});
|
|
222
232
|
}
|
|
223
233
|
//{{-------- Mobile draw modal ---------}}
|
|
224
|
-
#
|
|
225
|
-
if (this.#
|
|
234
|
+
#q() {
|
|
235
|
+
if (this.#n) return;
|
|
226
236
|
const t = document.createElement("div");
|
|
227
237
|
t.className = "selectyc-mobile-overlay";
|
|
228
238
|
const e = document.createElement("div");
|
|
229
239
|
e.className = "selectyc-mobile-modal";
|
|
230
240
|
const s = document.createElement("div");
|
|
231
241
|
if (s.className = "selectyc-mobile-header", this.searchInputActive) {
|
|
232
|
-
const
|
|
233
|
-
|
|
234
|
-
this.filter =
|
|
235
|
-
}), this.#x =
|
|
242
|
+
const n = document.createElement("input");
|
|
243
|
+
n.type = "text", n.className = "selectyc-mobile-search", n.placeholder = "Buscar...", n.addEventListener("input", () => {
|
|
244
|
+
this.filter = n.value, this.#a.innerHTML = "", this.#I();
|
|
245
|
+
}), this.#x = n, s.appendChild(n);
|
|
236
246
|
}
|
|
237
247
|
const i = document.createElement("button");
|
|
238
|
-
i.innerHTML = "✕", i.className = "selectyc-mobile-close", i.onclick = () => this.#
|
|
239
|
-
const
|
|
240
|
-
|
|
241
|
-
if (this.#S || this.#
|
|
242
|
-
const { scrollTop:
|
|
243
|
-
|
|
244
|
-
}), e.appendChild(s), e.appendChild(
|
|
248
|
+
i.innerHTML = "✕", i.className = "selectyc-mobile-close", i.onclick = () => this.#g(), s.appendChild(i);
|
|
249
|
+
const a = document.createElement("div");
|
|
250
|
+
a.className = "selectyc-mobile-body", a.addEventListener("scroll", async () => {
|
|
251
|
+
if (this.#S || this.#u) return;
|
|
252
|
+
const { scrollTop: n, scrollHeight: l, clientHeight: o } = a;
|
|
253
|
+
n + o >= l - 10 && (this.#S = !0, await this.#V(), this.#S = !1);
|
|
254
|
+
}), e.appendChild(s), e.appendChild(a), t.appendChild(e), document.body.appendChild(t), this.#n = t, this.#a = a;
|
|
245
255
|
}
|
|
246
256
|
//{{-------- Functions ---------}}
|
|
247
|
-
#
|
|
257
|
+
#P() {
|
|
248
258
|
const t = document.getElementById(this.id);
|
|
249
|
-
this.name = t.name, this.#
|
|
259
|
+
this.name = t.name, this.#M = t.required, this.rootClassName = t.className, this.disabled = t.disabled, Array.from(t.options).forEach((e) => {
|
|
250
260
|
if (e.outerHTML.includes("selected")) {
|
|
251
261
|
const s = e.text, i = this.#v(e.value);
|
|
252
262
|
this.isMultiple ? this.#t.push({ value: i, text: s }) : this.#t[0] = { value: i, text: s };
|
|
253
263
|
}
|
|
254
|
-
this.#
|
|
264
|
+
this.#c.push({ id: this.#v(e.value), text: e.text }), this.data = this.#c;
|
|
255
265
|
});
|
|
256
266
|
}
|
|
257
267
|
//{{-------- Show dropdown ---------}}
|
|
258
|
-
#
|
|
268
|
+
#D() {
|
|
259
269
|
if (this.isMobil) {
|
|
260
|
-
this.#
|
|
270
|
+
this.#z();
|
|
261
271
|
return;
|
|
262
272
|
}
|
|
263
|
-
if (this.filter = null, this.searchInputActive && (this.#
|
|
264
|
-
this.#
|
|
273
|
+
if (this.filter = null, this.searchInputActive && (this.#l.value = null), this.#d) return;
|
|
274
|
+
this.#d = !0;
|
|
265
275
|
const t = this.#m.getBoundingClientRect(), e = window.innerHeight - t.bottom, s = t.top;
|
|
266
276
|
this.#i.style.position = "fixed", this.#e.style.width = t.width + "px";
|
|
267
277
|
const i = 270;
|
|
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.#
|
|
278
|
+
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.#l.style.display = "block", this.#l.style.width = t.width + "px", this.#l.focus()), this.#T();
|
|
269
279
|
}
|
|
270
|
-
#
|
|
271
|
-
this.#
|
|
280
|
+
#z() {
|
|
281
|
+
this.#q(), 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.#I();
|
|
272
282
|
}
|
|
273
283
|
//{{-------- Hide dropdown ---------}}
|
|
274
|
-
#
|
|
275
|
-
this.isMobil || this.#
|
|
284
|
+
#r() {
|
|
285
|
+
this.isMobil || this.#d && (this.#d = !1, this.#e.innerHTML = "", this.#e.style.display = "none", this.searchInputActive && (this.#l.style.display = "none"), this.#s.classList.add(`round${this.bodyRound}`), this.page = 0);
|
|
276
286
|
}
|
|
277
|
-
#
|
|
278
|
-
this.#
|
|
287
|
+
#g() {
|
|
288
|
+
this.#n && (this.#n.style.display = "none", document.body.style.overflow = "", this.page = 0);
|
|
279
289
|
}
|
|
280
290
|
//{{-------- Render options ---------}}
|
|
281
291
|
async #y() {
|
|
282
292
|
if (this.RS === void 0)
|
|
283
293
|
return this.data;
|
|
284
|
-
let t = { records: this.records, filter: this.filter };
|
|
294
|
+
let t = { records: this.records, filter: this.filter, page: this.page };
|
|
285
295
|
if (typeof this.bodyData == "function") {
|
|
286
296
|
const i = this.bodyData();
|
|
287
297
|
t = { ...t, ...i };
|
|
288
298
|
} else this.bodyData !== null && (t = { ...t, ...this.bodyData });
|
|
289
299
|
const e = await h.make(this.RS).addData(t).setMethod("POST").go(), s = Array.isArray(e) ? e : e.data;
|
|
290
|
-
return this.data = Array.from(
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
300
|
+
return this.#E ? this.data = Array.from(
|
|
301
|
+
new Map(
|
|
302
|
+
[...this.#c, ...this.data, ...s].map((i) => [i.id, i])
|
|
303
|
+
).values()
|
|
304
|
+
) : this.data = Array.from(
|
|
305
|
+
new Map(
|
|
306
|
+
[...this.#c, ...s].map((i) => [i.id, i])
|
|
307
|
+
).values()
|
|
308
|
+
), this.data = Array.from(new Map([...this.#c, ...s].map((i) => [i.id, i])).values()), this.data;
|
|
309
|
+
}
|
|
310
|
+
async #T() {
|
|
311
|
+
this.#o({ id: "loading", text: "cargando ..." }), this.records = 10 + this.#t.length, this.page = 1 + this.page, this.#C = !1;
|
|
294
312
|
let t = await this.#y();
|
|
295
313
|
const e = this.#t.map((s) => s.value);
|
|
296
314
|
this.#e.lastChild.dataset.value === "loading" && this.#e.removeChild(this.#e.lastChild), t.forEach((s) => {
|
|
297
|
-
s.text.toLowerCase().includes(this.#
|
|
298
|
-
}), this.#e.hasChildNodes() || this.#
|
|
315
|
+
s.text.toLowerCase().includes(this.#A.toLowerCase()) && !e.includes(s.id) && this.#o(s);
|
|
316
|
+
}), this.#e.hasChildNodes() || this.#o({ id: "sin_resultados", text: "sin resultados ..." });
|
|
299
317
|
}
|
|
300
|
-
async #
|
|
301
|
-
this.records = 10 + this.#t.length, this.#
|
|
318
|
+
async #I() {
|
|
319
|
+
this.records = 10 + this.#t.length, this.page = 1 + this.page, this.#u = !1, this.#a.innerHTML = '<div class="mobile-loading">cargando...</div>';
|
|
302
320
|
let t = await this.#y();
|
|
303
|
-
this.#
|
|
321
|
+
this.#a.innerHTML = "";
|
|
304
322
|
const e = this.#t.map((i) => i.value);
|
|
305
323
|
let s = 0;
|
|
306
324
|
t.forEach((i) => {
|
|
307
325
|
if (i.text.toLowerCase().includes((this.filter || "").toLowerCase()) && !e.includes(i.id)) {
|
|
308
|
-
const
|
|
309
|
-
|
|
310
|
-
this.#L(i.text, i.id), this.onSelect && this.onSelect(i.id, this), this.#
|
|
311
|
-
}, this.#
|
|
326
|
+
const a = document.createElement("div");
|
|
327
|
+
a.className = "mobile-option", a.innerText = i.text, a.onclick = () => {
|
|
328
|
+
this.#L(i.text, i.id), this.onSelect && this.onSelect(i.id, this), this.#g();
|
|
329
|
+
}, this.#a.appendChild(a), s++;
|
|
312
330
|
}
|
|
313
|
-
}), s === 0 && (this.#
|
|
331
|
+
}), s === 0 && (this.#a.innerHTML = '<div class="mobile-empty">Sin resultados</div>', this.#u = !0);
|
|
314
332
|
}
|
|
315
|
-
async #
|
|
316
|
-
const t = this.#t.map((
|
|
317
|
-
let e = this.filter === null ? "" : this.filter, s = this.data.map((
|
|
318
|
-
this.records = this.records + 10 + this.#t.length;
|
|
333
|
+
async #F() {
|
|
334
|
+
const t = this.#t.map((n) => n.value);
|
|
335
|
+
let e = this.filter === null ? "" : this.filter, s = this.data.map((n) => n.id);
|
|
336
|
+
this.records = this.records + 10 + this.#t.length, this.page = 1 + this.page;
|
|
319
337
|
let i = await this.#y();
|
|
320
338
|
this.#e.lastChild.dataset.value === "loading" && this.#e.removeChild(this.#e.lastChild);
|
|
321
|
-
const
|
|
322
|
-
i.forEach((
|
|
323
|
-
|
|
324
|
-
}), this.#C =
|
|
325
|
-
}
|
|
326
|
-
async #
|
|
327
|
-
if (this.#
|
|
328
|
-
const t = this.#t.map((
|
|
329
|
-
let e = this.filter || "", s = this.data.map((
|
|
330
|
-
this.records = this.records + 10 + this.#t.length;
|
|
331
|
-
let i = await this.#y(),
|
|
332
|
-
i.forEach((
|
|
333
|
-
if (
|
|
334
|
-
const
|
|
335
|
-
|
|
336
|
-
this.#L(
|
|
337
|
-
}, this.#
|
|
339
|
+
const a = this.#e.lastChild.dataset.value;
|
|
340
|
+
i.forEach((n) => {
|
|
341
|
+
n.text.toLowerCase().includes(e.toLowerCase()) && !t.includes(n.id) && !s.includes(n.id) && this.#o(n);
|
|
342
|
+
}), this.#C = a === this.#e.lastChild.dataset.value;
|
|
343
|
+
}
|
|
344
|
+
async #V() {
|
|
345
|
+
if (this.#u) return;
|
|
346
|
+
const t = this.#t.map((n) => n.value);
|
|
347
|
+
let e = this.filter || "", s = this.data.map((n) => n.id);
|
|
348
|
+
this.records = this.records + 10 + this.#t.length, this.page = 1 + this.page;
|
|
349
|
+
let i = await this.#y(), a = 0;
|
|
350
|
+
i.forEach((n) => {
|
|
351
|
+
if (n.text.toLowerCase().includes(e.toLowerCase()) && !t.includes(n.id) && !s.includes(n.id)) {
|
|
352
|
+
const l = document.createElement("div");
|
|
353
|
+
l.className = "mobile-option", l.innerText = n.text, l.onclick = () => {
|
|
354
|
+
this.#L(n.text, n.id), this.onSelect && this.onSelect(n.id, this), this.#g();
|
|
355
|
+
}, this.#a.appendChild(l), a++;
|
|
338
356
|
}
|
|
339
|
-
}),
|
|
357
|
+
}), a === 0 && (this.#u = !0);
|
|
340
358
|
}
|
|
341
359
|
#L(t, e) {
|
|
342
|
-
this.#t.find((i) => i.value === e) || (this.isMultiple || (this.#t = []), this.#t.push({ text: t, value: e })), this.#
|
|
360
|
+
this.#t.find((i) => i.value === e) || (this.isMultiple || (this.#t = []), this.#t.push({ text: t, value: e })), this.#p(e);
|
|
343
361
|
}
|
|
344
362
|
//{{-------- Render main box ---------}}
|
|
345
|
-
#
|
|
346
|
-
this.onChange !== void 0 && this.onChange(t, this), this.isMultiple ? this.#
|
|
363
|
+
#p(t) {
|
|
364
|
+
this.onChange !== void 0 && this.onChange(t, this), this.isMultiple ? this.#O() : this.#U();
|
|
347
365
|
}
|
|
348
|
-
#
|
|
349
|
-
this.#
|
|
350
|
-
const t = this.#
|
|
351
|
-
|
|
352
|
-
return;
|
|
353
|
-
const s = document.createElement("span");
|
|
354
|
-
s.dataset.value = this.#t[0].value, s.innerHTML = "x", s.className = "remove-tag", t.insertBefore(s, t.firstChild);
|
|
366
|
+
#U() {
|
|
367
|
+
this.#h.value = null, this.#f.value = null, this.#h.value = this.#t.length > 0 ? this.#t[0].text : null, this.#f.value = this.#t.length > 0 ? this.#t[0].text : null, this.#h.placeholder = this.singleLabel, this.#w.value = this.#t.length > 0 ? this.#t[0].value : null;
|
|
368
|
+
const t = this.#h.parentNode, e = t.firstChild;
|
|
369
|
+
e.className === "remove-tag" && e.remove(), !(!this.clearButton || this.#t.length <= 0) && t.insertBefore(this.#N(), t.firstChild);
|
|
355
370
|
}
|
|
356
|
-
#
|
|
371
|
+
#O() {
|
|
357
372
|
if (this.#s.innerHTML = "", this.#t.length <= 0) {
|
|
358
373
|
this.#s.appendChild(document.createElement("div"));
|
|
359
374
|
return;
|
|
@@ -363,19 +378,19 @@ class d {
|
|
|
363
378
|
s.className = "selected-tag", s.innerHTML = `${t} <span class="remove-tag" data-value="${e}">x</span>`, this.#s.appendChild(s);
|
|
364
379
|
});
|
|
365
380
|
}
|
|
366
|
-
#
|
|
367
|
-
this.#t = this.#t.filter((e) => this.#v(e.value) !== this.#v(t)), this.#
|
|
381
|
+
#K(t) {
|
|
382
|
+
this.#t = this.#t.filter((e) => this.#v(e.value) !== this.#v(t)), this.#p(t);
|
|
368
383
|
}
|
|
369
|
-
#
|
|
384
|
+
#J(t) {
|
|
370
385
|
const { scrollTop: e, scrollHeight: s, clientHeight: i } = this.#e;
|
|
371
|
-
t.target.lastChild !== null && (t.target.lastChild.dataset.value === "loading" || this.#C || e + (i + 1) >= s && (this.#
|
|
386
|
+
t.target.lastChild !== null && (t.target.lastChild.dataset.value === "loading" || this.#C || e + (i + 1) >= s && (this.#o({ id: "loading", text: "cargando ..." }), this.#F()));
|
|
372
387
|
}
|
|
373
388
|
#v(t) {
|
|
374
389
|
return !isNaN(t) && !isNaN(parseFloat(t)) ? parseInt(t) : t;
|
|
375
390
|
}
|
|
376
391
|
async render() {
|
|
377
392
|
const t = document.getElementById(this.id), e = t === null ? !1 : t.outerHTML.includes("<select");
|
|
378
|
-
this.#b === void 0 && t !== null || e ? this.#
|
|
393
|
+
this.#b === void 0 && t !== null || e ? this.#H() : this.#b !== void 0 && this.#p();
|
|
379
394
|
}
|
|
380
395
|
}
|
|
381
396
|
export {
|
package/dist/selectyc.umd.cjs
CHANGED
|
@@ -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 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"})});
|
|
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=[];#w;#c=[];#m;#b;#s;#e;#a;#h;#f;#i;#d=!1;#M=!1;#C=!1;#A="";#E=!1;#B='<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;#u=!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.page=0,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.#p(t)}setPagination(){return this.#E=!0,this}getSelectedOptions(){return this.#t}getSelectedOption(){return this.#t[0]}getOptions(){return this.data}setSingleLabel(t){return this.singleLabel=t,this}setBodyRound(t){return this.bodyRound=`-${t}`,this}setRS(t){return this.RS=t,this}setBodyData(t){return this.bodyData=t,this}desactiveSearchInput(){return this.searchInputActive=!1,this}addOption(t){this.data.push(t)}setWidth(t){return this.width=t,this}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.#p(t)}setDisableSelect(t){return this.disabled=t,this}setRequiredSelect(t){return this.#f.required=t,this}#H(){this.#R(),this.#s.addEventListener("click",t=>{if(!this.disabled){if(t.target.classList.contains("remove-tag")){this.#K(t.target.getAttribute("data-value")),this.onUnselect!==void 0&&this.onUnselect(t.target.getAttribute("data-value"),this),this.#d&&this.#r(),this.#D();return}this.#d?this.#r():this.#D()}}),document.addEventListener("click",t=>{this.isMobil&&t.target.classList.contains("selectyc-mobile-overlay")&&this.#g(),!this.#m.contains(t.target)&&!this.#e.contains(t.target)&&!t.target.classList.contains("remove-tag")&&this.#r()}),window.onresize=()=>{this.#r()},window.addEventListener("scroll",()=>{this.isMobil||this.#r()}),this.isMultiple&&this.#I()}#R(){this.#q();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.#k(s)),e.appendChild(s),e.appendChild(this.#j()),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.#w=l,this.#b=s,this.#m=e,this.#s=this.#m.querySelector(".selected-items"),!this.isMultiple&&this.#t.length>0&&(this.#w.value=this.#t[0].value)}#k(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");s.innerHTML=this.#B,t.appendChild(this.#$()),t.appendChild(e),t.appendChild(s),this.#h=e;const i=this.#h.parentNode;return this.clearButton&&this.#t.length>0&&i.insertBefore(this.#N(),i.firstChild),t}#N(){const t=document.createElement("span");return t.dataset.value=this.#t[0].value,t.innerHTML="x",t.className="remove-tag",t}#$(){const t=document.createElement("input");return t.type="text",t.required=this.#M,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.#f=t,t}#j(){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.#J(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.#o({id:"loading",text:"cargando ..."}),clearTimeout(e),e=setTimeout(()=>{this.page=0,this.#e.removeChild(this.#e.lastChild),this.#T()},800)}),this.#a=t,t}#o(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.#r())})}#P(){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.#O()}),this.#x=n,s.appendChild(n)}const i=document.createElement("button");i.innerHTML="✕",i.className="selectyc-mobile-close",i.onclick=()=>this.#g(),s.appendChild(i);const l=document.createElement("div");l.className="selectyc-mobile-body",l.addEventListener("scroll",async()=>{if(this.#S||this.#u)return;const{scrollTop:n,scrollHeight:d,clientHeight:r}=l;n+r>=d-10&&(this.#S=!0,await this.#V(),this.#S=!1)}),e.appendChild(s),e.appendChild(l),t.appendChild(e),document.body.appendChild(t),this.#n=t,this.#l=l}#q(){const t=document.getElementById(this.id);this.name=t.name,this.#M=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.#c.push({id:this.#v(e.value),text:e.text}),this.data=this.#c})}#D(){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.#T()}#z(){this.#P(),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.#O()}#r(){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}`),this.page=0)}#g(){this.#n&&(this.#n.style.display="none",document.body.style.overflow="",this.page=0)}async#y(){if(this.RS===void 0)return this.data;let t={records:this.records,filter:this.filter,page:this.page};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.#E?this.data=Array.from(new Map([...this.#c,...this.data,...s].map(i=>[i.id,i])).values()):this.data=Array.from(new Map([...this.#c,...s].map(i=>[i.id,i])).values()),this.data=Array.from(new Map([...this.#c,...s].map(i=>[i.id,i])).values()),this.data}async#T(){this.#o({id:"loading",text:"cargando ..."}),this.records=10+this.#t.length,this.page=1+this.page,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.#A.toLowerCase())&&!e.includes(s.id)&&this.#o(s)}),this.#e.hasChildNodes()||this.#o({id:"sin_resultados",text:"sin resultados ..."})}async#O(){this.records=10+this.#t.length,this.page=1+this.page,this.#u=!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.#g()},this.#l.appendChild(l),s++}}),s===0&&(this.#l.innerHTML='<div class="mobile-empty">Sin resultados</div>',this.#u=!0)}async#F(){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,this.page=1+this.page;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.#o(n)}),this.#C=l===this.#e.lastChild.dataset.value}async#V(){if(this.#u)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,this.page=1+this.page;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.#g()},this.#l.appendChild(d),l++}}),l===0&&(this.#u=!0)}#L(t,e){this.#t.find(i=>i.value===e)||(this.isMultiple||(this.#t=[]),this.#t.push({text:t,value:e})),this.#p(e)}#p(t){this.onChange!==void 0&&this.onChange(t,this),this.isMultiple?this.#I():this.#U()}#U(){this.#h.value=null,this.#f.value=null,this.#h.value=this.#t.length>0?this.#t[0].text:null,this.#f.value=this.#t.length>0?this.#t[0].text:null,this.#h.placeholder=this.singleLabel,this.#w.value=this.#t.length>0?this.#t[0].value:null;const t=this.#h.parentNode,e=t.firstChild;e.className==="remove-tag"&&e.remove(),!(!this.clearButton||this.#t.length<=0)&&t.insertBefore(this.#N(),t.firstChild)}#I(){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)})}#K(t){this.#t=this.#t.filter(e=>this.#v(e.value)!==this.#v(t)),this.#p(t)}#J(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.#o({id:"loading",text:"cargando ..."}),this.#F()))}#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.#H():this.#b!==void 0&&this.#p()}}h.selectyc=o,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
|