selectyc 0.0.16 → 0.0.17
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 +66 -60
- package/dist/selectyc.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/selectyc.js
CHANGED
|
@@ -48,19 +48,19 @@ class l {
|
|
|
48
48
|
}
|
|
49
49
|
class h {
|
|
50
50
|
#t = [];
|
|
51
|
-
#c;
|
|
52
|
-
#f = [];
|
|
53
|
-
#d;
|
|
54
|
-
#m;
|
|
55
|
-
#s;
|
|
56
|
-
#e;
|
|
57
|
-
#i;
|
|
58
|
-
#a;
|
|
59
51
|
#u;
|
|
52
|
+
#m = [];
|
|
53
|
+
#a;
|
|
60
54
|
#g;
|
|
55
|
+
#i;
|
|
56
|
+
#e;
|
|
57
|
+
#s;
|
|
58
|
+
#l;
|
|
59
|
+
#p;
|
|
60
|
+
#o;
|
|
61
61
|
#n = !1;
|
|
62
62
|
#y = !1;
|
|
63
|
-
#
|
|
63
|
+
#f = !1;
|
|
64
64
|
#b = "";
|
|
65
65
|
#S = '<svg class="w-5 h-5 text-gray-900 dark:text-gray-400" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m19 9-7 7-7-7"/></svg>';
|
|
66
66
|
constructor(t) {
|
|
@@ -81,7 +81,7 @@ class h {
|
|
|
81
81
|
return this.clearButton = !0, this;
|
|
82
82
|
}
|
|
83
83
|
setSelectedOptions(t) {
|
|
84
|
-
this.#t = t, this.#
|
|
84
|
+
this.#t = t, this.#d(t);
|
|
85
85
|
}
|
|
86
86
|
getSelectedOptions() {
|
|
87
87
|
return this.#t;
|
|
@@ -124,20 +124,22 @@ class h {
|
|
|
124
124
|
}
|
|
125
125
|
cleanSelection() {
|
|
126
126
|
const t = this.#t;
|
|
127
|
-
this.#t = [], this.#
|
|
127
|
+
this.#t = [], this.#d(t);
|
|
128
128
|
}
|
|
129
129
|
#E() {
|
|
130
|
-
this.#D(), this.#
|
|
130
|
+
this.#D(), this.#i.addEventListener("click", (t) => {
|
|
131
131
|
if (t.target.classList.contains("remove-tag")) {
|
|
132
|
-
this.#
|
|
132
|
+
this.#A(t.target.getAttribute("data-value")), this.onUnselect !== void 0 && this.onUnselect(t.target.getAttribute("data-value"), this), this.#n && this.#r(), this.#w();
|
|
133
133
|
return;
|
|
134
134
|
}
|
|
135
|
-
this.#n ? this.#
|
|
135
|
+
this.#n ? this.#r() : this.#w();
|
|
136
136
|
}), document.addEventListener("click", (t) => {
|
|
137
|
-
!this.#
|
|
137
|
+
!this.#a.contains(t.target) && !this.#e.contains(t.target) && !t.target.classList.contains("remove-tag") && this.#r();
|
|
138
138
|
}), window.onresize = () => {
|
|
139
|
-
this.#
|
|
140
|
-
},
|
|
139
|
+
this.#r();
|
|
140
|
+
}, window.addEventListener("scroll", () => {
|
|
141
|
+
this.repositionDropdown();
|
|
142
|
+
}), this.isMultiple && this.#C();
|
|
141
143
|
}
|
|
142
144
|
// Draw functions
|
|
143
145
|
#D() {
|
|
@@ -151,17 +153,17 @@ class h {
|
|
|
151
153
|
const i = document.getElementById(this.id), a = document.createElement("input");
|
|
152
154
|
a.name = i.name, a.setAttribute("data-id", i.id), this.rootClassName !== "" && (a.className = i.className), a.style.display = "none";
|
|
153
155
|
let n = i.parentNode;
|
|
154
|
-
t.appendChild(a), n.replaceChild(t, i), this.#
|
|
156
|
+
t.appendChild(a), n.replaceChild(t, i), this.#u = a, this.#g = s, this.#a = e, this.#i = this.#a.querySelector(".selected-items"), !this.isMultiple && this.#t.length > 0 && (this.#u.value = this.#t[0].value);
|
|
155
157
|
}
|
|
156
158
|
#L(t) {
|
|
157
159
|
const e = document.createElement("input");
|
|
158
160
|
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;
|
|
159
161
|
const s = document.createElement("div");
|
|
160
|
-
return s.innerHTML = this.#S, t.appendChild(this.#N()), t.appendChild(e), t.appendChild(s), this.#
|
|
162
|
+
return s.innerHTML = this.#S, t.appendChild(this.#N()), t.appendChild(e), t.appendChild(s), this.#l = e, t;
|
|
161
163
|
}
|
|
162
164
|
#N() {
|
|
163
165
|
const t = document.createElement("input");
|
|
164
|
-
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.#
|
|
166
|
+
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.#p = t, t;
|
|
165
167
|
}
|
|
166
168
|
#O() {
|
|
167
169
|
const t = document.createElement("div");
|
|
@@ -171,7 +173,7 @@ class h {
|
|
|
171
173
|
let s;
|
|
172
174
|
return e.addEventListener("scroll", (i) => {
|
|
173
175
|
s && clearTimeout(s), s = setTimeout(() => {
|
|
174
|
-
this.#
|
|
176
|
+
this.#H(i);
|
|
175
177
|
}, 70);
|
|
176
178
|
}), t.appendChild(e), this.#e = e, t;
|
|
177
179
|
}
|
|
@@ -179,41 +181,45 @@ class h {
|
|
|
179
181
|
const t = document.createElement("input");
|
|
180
182
|
return t.type = "text", t.id = "selectyc_search_input", t.className = "search-input", t.placeholder = "Buscar...", t.addEventListener("input", () => {
|
|
181
183
|
this.filter = t.value, this.#e.innerHTML = "", this.filter = t.value, this.#x();
|
|
182
|
-
}), this.#
|
|
184
|
+
}), this.#s = t, t;
|
|
183
185
|
}
|
|
184
|
-
#
|
|
186
|
+
#h(t) {
|
|
185
187
|
const e = document.createElement("div");
|
|
186
188
|
e.className = "select-option", e.setAttribute("data-value", t.id), e.textContent = t.text, this.#e.appendChild(e), e.addEventListener("click", () => {
|
|
187
|
-
t.id !== "sin_resultados" && (this.#T(t.text, t.id), this.onSelect !== void 0 && this.onSelect(t.id, this), this.#
|
|
189
|
+
t.id !== "sin_resultados" && (this.#T(t.text, t.id), this.onSelect !== void 0 && this.onSelect(t.id, this), this.#r());
|
|
188
190
|
});
|
|
189
191
|
}
|
|
190
192
|
// Functions
|
|
191
193
|
#M() {
|
|
192
194
|
const t = document.getElementById(this.id);
|
|
193
|
-
this.name = t.name, this.#y = t.required, this.rootClassName = t.className, this.#
|
|
195
|
+
this.name = t.name, this.#y = t.required, this.rootClassName = t.className, this.#o = t.getBoundingClientRect(), Array.from(t.options).forEach((e) => {
|
|
194
196
|
if (e.outerHTML.includes("selected")) {
|
|
195
|
-
const s = e.text, i = this.#
|
|
197
|
+
const s = e.text, i = this.#c(e.value);
|
|
196
198
|
this.isMultiple ? this.#t.push({ value: i, text: s }) : this.#t[0] = { value: i, text: s };
|
|
197
199
|
}
|
|
198
|
-
this.#
|
|
200
|
+
this.#m.push({ id: this.#c(e.value), text: e.text });
|
|
199
201
|
});
|
|
200
202
|
}
|
|
201
|
-
#
|
|
203
|
+
#w() {
|
|
202
204
|
if (this.filter = null, this.#n)
|
|
203
205
|
return;
|
|
204
|
-
this.#
|
|
205
|
-
const t = this.#
|
|
206
|
+
this.#i.classList.remove(`round${this.bodyRound}`), this.#i.classList.add(`round${this.bodyRound}t`);
|
|
207
|
+
const t = this.#a.getBoundingClientRect(), e = t.x - this.#o.x, s = t.y - this.#o.y;
|
|
206
208
|
if (this.searchInputActive) {
|
|
207
|
-
this.#
|
|
208
|
-
const
|
|
209
|
-
this.#e.style.top = s + "px", e < 0 ? this.#
|
|
209
|
+
this.#s.style.display = "block", this.#s.style.y = s + "px", this.#s.style.width = t.width + "px";
|
|
210
|
+
const i = this.#s.offsetHeight;
|
|
211
|
+
this.#e.style.top = i + s + "px", e < 0 ? this.#s.style.left = e + "px" : e > 0 && (this.#s.style.right = e * -1 + "px");
|
|
210
212
|
}
|
|
211
|
-
this.#e.style.width = t.width + "px", this.#e.style.x = t.x + "px", this.#e.innerHTML = "", this.#e.style.display = "block", e < 0 ? this.#e.style.left = e + "px" : e > 0 && (this.#e.style.right = e * -1 + "px"), this.searchInputActive && this.#
|
|
213
|
+
this.#e.style.width = t.width + "px", this.#e.style.x = t.x + "px", this.#e.innerHTML = "", this.#e.style.display = "block", e < 0 ? this.#e.style.left = e + "px" : e > 0 && (this.#e.style.right = e * -1 + "px"), this.searchInputActive && this.#s.focus(), this.#x(), this.#n = !0;
|
|
214
|
+
}
|
|
215
|
+
repositionDropdown() {
|
|
216
|
+
const e = this.#a.getBoundingClientRect().y - this.#o.y;
|
|
217
|
+
this.#e.style.top = this.#s.offsetHeight + e + "px", this.#s.style.top = e + "px";
|
|
212
218
|
}
|
|
213
|
-
#
|
|
214
|
-
this.#n && (this.#e.innerHTML = "", this.#e.style.display = "none", this.searchInputActive && (this.#
|
|
219
|
+
#r() {
|
|
220
|
+
this.#n && (this.#e.innerHTML = "", this.#e.style.display = "none", this.searchInputActive && (this.#s.style.display = "none"), this.#i.classList.add(`round${this.bodyRound}`), this.#n = !1);
|
|
215
221
|
}
|
|
216
|
-
async #
|
|
222
|
+
async #v() {
|
|
217
223
|
if (this.RS === void 0)
|
|
218
224
|
return this.data;
|
|
219
225
|
let t = { records: this.records, filter: this.filter };
|
|
@@ -222,64 +228,64 @@ class h {
|
|
|
222
228
|
t = { ...t, ...i };
|
|
223
229
|
} else this.bodyData !== null && (t = { ...t, ...this.bodyData });
|
|
224
230
|
const e = await l.make(this.RS).addData(t).setMethod("POST").go(), s = Array.isArray(e) ? e : e.data;
|
|
225
|
-
return this.data = Array.from(new Map([...this.#
|
|
231
|
+
return this.data = Array.from(new Map([...this.#m, ...s].map((i) => [i.id, i])).values()), this.data;
|
|
226
232
|
}
|
|
227
233
|
async #x() {
|
|
228
|
-
this.#
|
|
229
|
-
let t = await this.#
|
|
234
|
+
this.#h({ id: "loading", text: "cargando ..." }), this.records = 10 + this.#t.length, this.#f = !1;
|
|
235
|
+
let t = await this.#v();
|
|
230
236
|
const e = this.#t.map((s) => s.value);
|
|
231
237
|
this.#e.lastChild.dataset.value === "loading" && this.#e.removeChild(this.#e.lastChild), t.forEach((s) => {
|
|
232
|
-
s.text.toLowerCase().includes(this.#b.toLowerCase()) && !e.includes(s.id) && this.#
|
|
233
|
-
}), this.#e.hasChildNodes() || this.#
|
|
238
|
+
s.text.toLowerCase().includes(this.#b.toLowerCase()) && !e.includes(s.id) && this.#h(s);
|
|
239
|
+
}), this.#e.hasChildNodes() || this.#h({ id: "sin_resultados", text: "sin resultados ..." });
|
|
234
240
|
}
|
|
235
241
|
async #R() {
|
|
236
242
|
const t = this.#t.map((n) => n.value);
|
|
237
243
|
let e = this.filter === null ? "" : this.filter, s = this.data.map((n) => n.id);
|
|
238
244
|
this.records = this.records + 10 + this.#t.length;
|
|
239
|
-
let i = await this.#
|
|
245
|
+
let i = await this.#v();
|
|
240
246
|
this.#e.lastChild.dataset.value === "loading" && this.#e.removeChild(this.#e.lastChild);
|
|
241
247
|
const a = this.#e.lastChild.dataset.value;
|
|
242
248
|
i.forEach((n) => {
|
|
243
|
-
n.text.toLowerCase().includes(e.toLowerCase()) && !t.includes(n.id) && !s.includes(n.id) && this.#
|
|
244
|
-
}), this.#
|
|
249
|
+
n.text.toLowerCase().includes(e.toLowerCase()) && !t.includes(n.id) && !s.includes(n.id) && this.#h(n);
|
|
250
|
+
}), this.#f = a === this.#e.lastChild.dataset.value;
|
|
245
251
|
}
|
|
246
252
|
#T(t, e) {
|
|
247
|
-
this.#t.find((i) => i.value === e) || (this.isMultiple || (this.#t = []), this.#t.push({ text: t, value: e })), this.#
|
|
253
|
+
this.#t.find((i) => i.value === e) || (this.isMultiple || (this.#t = []), this.#t.push({ text: t, value: e })), this.#d(e);
|
|
248
254
|
}
|
|
249
|
-
#
|
|
250
|
-
this.onChange !== void 0 && this.onChange(t, this), this.isMultiple ? this.#C() : this.#
|
|
255
|
+
#d(t) {
|
|
256
|
+
this.onChange !== void 0 && this.onChange(t, this), this.isMultiple ? this.#C() : this.#B();
|
|
251
257
|
}
|
|
252
|
-
#
|
|
253
|
-
this.#
|
|
254
|
-
const t = this.#
|
|
258
|
+
#B() {
|
|
259
|
+
this.#l.value = null, this.#p.value = null, this.#l.value = this.#t.length > 0 ? this.#t[0].text : null, this.#p.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;
|
|
260
|
+
const t = this.#l.parentNode, e = t.firstChild;
|
|
255
261
|
if (e.className === "remove-tag" && e.remove(), !this.clearButton || this.#t.length <= 0)
|
|
256
262
|
return;
|
|
257
263
|
const s = document.createElement("span");
|
|
258
264
|
s.dataset.value = this.#t[0].value, s.innerHTML = "x", s.className = "remove-tag", t.insertBefore(s, t.firstChild);
|
|
259
265
|
}
|
|
260
266
|
#C() {
|
|
261
|
-
if (this.#
|
|
262
|
-
this.#
|
|
267
|
+
if (this.#i.innerHTML = "", this.#t.length <= 0) {
|
|
268
|
+
this.#i.appendChild(document.createElement("div"));
|
|
263
269
|
return;
|
|
264
270
|
}
|
|
265
271
|
this.#t.forEach(({ text: t, value: e }) => {
|
|
266
272
|
const s = document.createElement("div");
|
|
267
|
-
s.className = "selected-tag", s.innerHTML = `${t} <span class="remove-tag" data-value="${e}">x</span>`, this.#
|
|
273
|
+
s.className = "selected-tag", s.innerHTML = `${t} <span class="remove-tag" data-value="${e}">x</span>`, this.#i.appendChild(s);
|
|
268
274
|
});
|
|
269
275
|
}
|
|
270
|
-
#
|
|
271
|
-
this.#t = this.#t.filter((e) => this.#
|
|
276
|
+
#A(t) {
|
|
277
|
+
this.#t = this.#t.filter((e) => this.#c(e.value) !== this.#c(t)), this.#d(t);
|
|
272
278
|
}
|
|
273
|
-
#
|
|
279
|
+
#H(t) {
|
|
274
280
|
const { scrollTop: e, scrollHeight: s, clientHeight: i } = this.#e;
|
|
275
|
-
t.target.lastChild !== null && (t.target.lastChild.dataset.value === "loading" || this.#
|
|
281
|
+
t.target.lastChild !== null && (t.target.lastChild.dataset.value === "loading" || this.#f || e + (i + 1) >= s && (this.#h({ id: "loading", text: "cargando ..." }), this.#R()));
|
|
276
282
|
}
|
|
277
|
-
#
|
|
283
|
+
#c(t) {
|
|
278
284
|
return !isNaN(t) && !isNaN(parseFloat(t)) ? parseInt(t) : t;
|
|
279
285
|
}
|
|
280
286
|
async render() {
|
|
281
287
|
const t = document.getElementById(this.id), e = t === null ? !1 : t.outerHTML.includes("<select");
|
|
282
|
-
this.#
|
|
288
|
+
this.#g === void 0 || e ? this.#E() : this.#d();
|
|
283
289
|
}
|
|
284
290
|
}
|
|
285
291
|
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 r{#t=[];#
|
|
1
|
+
(function(h,a){typeof exports=="object"&&typeof module<"u"?a(exports):typeof define=="function"&&define.amd?define(["exports"],a):(h=typeof globalThis<"u"?globalThis:h||self,a(h.selectyc={}))})(this,function(h){"use strict";class a{constructor(t){this.route=t}static make(t){return new a(t)}setMethod(t){return this.method=t,this}getMethod(){return this.method===void 0?"POST":this.method}setData(t){return this.data=t,this}addData(t){if(this.data===void 0)return this.setData(t);for(const e in t)this.data[e]=t[e];return this}setFun(t){return this.fun=t,this}async go(){try{const t={method:this.getMethod(),headers:{"X-CSRF-TOKEN":window.CSRF_TOKEN,Accept:"application/json"}};this.data!==void 0&&(t.body=this.data,Object.prototype.toString.call(this.data)!=="[object FormData]"&&(t.body=JSON.stringify(this.data),t.headers["Content-Type"]="application/json"));const e=await fetch(this.route,t);if(!e.ok){const s=await e.json();throw new Error(s.message)}return this.fun===void 0?await e.json():await this.fun(e)}catch(t){window.toastNotification.setType(!1).show(t.message)}}}class r{#t=[];#u;#m=[];#l;#g;#i;#e;#s;#a;#p;#d;#n=!1;#y=!1;#f=!1;#C="";#S='<svg class="w-5 h-5 text-gray-900 dark:text-gray-400" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m19 9-7 7-7-7"/></svg>';constructor(t){if(window.selects===void 0&&(window.selects=[]),window.selects[t]!==void 0)return window.selects[t];this.id=t,this.name,this.data=[],this.isMultiple=!1,this.clearButton=!1,this.singleLabel=" ",this.records=10,this.filter=null,this.bodyRound="",this.width="100%",this.searchInputActive=!0,this.bodyData=null,this.boxOverflow="horizontal",window.selects[t]=this}static set(t){return new r(t)}setData(t){return this.data=t,this}setMultiple(t="horizontal"){return this.isMultiple=!0,this.boxOverflow=t,this}setClearButton(){return this.clearButton=!0,this}setSelectedOptions(t){this.#t=t,this.#o(t)}getSelectedOptions(){return this.#t}getSelectedOption(){return this.#t[0]}getOptions(){return this.data}setSingleLabel(t){return this.singleLabel=t,this}setBodyRound(t){return this.bodyRound=`-${t}`,this}setRS(t){return this.RS=t,this}setBodyData(t){return this.bodyData=t,this}desactiveSearchInput(){return this.searchInputActive=!1,this}addOption(t){this.data.push(t)}setWidth(t){return this.width=t,this}setOnSelect(t){return this.onSelect=t,this}setOnUnselect(t){return this.onUnselect=t,this}setOnChange(t){return this.onChange=t,this}cleanSelection(){const t=this.#t;this.#t=[],this.#o(t)}#E(){this.#D(),this.#i.addEventListener("click",t=>{if(t.target.classList.contains("remove-tag")){this.#A(t.target.getAttribute("data-value")),this.onUnselect!==void 0&&this.onUnselect(t.target.getAttribute("data-value"),this),this.#n&&this.#r(),this.#w();return}this.#n?this.#r():this.#w()}),document.addEventListener("click",t=>{!this.#l.contains(t.target)&&!this.#e.contains(t.target)&&!t.target.classList.contains("remove-tag")&&this.#r()}),window.onresize=()=>{this.#r()},window.addEventListener("scroll",()=>{this.repositionDropdown()}),this.isMultiple&&this.#b()}#D(){this.#M();const t=document.createElement("div");t.className="main-div-selectyc",t.style.width=this.width,t.id=`selectyc_main_div_${this.id}`;const e=document.createElement("div");e.className="custom-multiselect";let s=document.createElement("div");s.className="selected-items round"+this.bodyRound,s.tabIndex=0,s.classList.add(this.boxOverflow==="horizontal"?"horizontal-overflow":"vertical-overflow"),this.isMultiple||(s=this.#L(s)),e.appendChild(s),e.appendChild(this.#O()),t.appendChild(e);const i=document.getElementById(this.id),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.#u=l,this.#g=s,this.#l=e,this.#i=this.#l.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.#S,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.#p=t,t}#O(){const t=document.createElement("div");t.setAttribute("style","position:fixed; z-index:999;");const e=document.createElement("div");e.className="global-dropdown",this.searchInputActive&&t.appendChild(this.#I());let s;return e.addEventListener("scroll",i=>{s&&clearTimeout(s),s=setTimeout(()=>{this.#H(i)},70)}),t.appendChild(e),this.#e=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.filter=t.value,this.#x()}),this.#s=t,t}#h(t){const e=document.createElement("div");e.className="select-option",e.setAttribute("data-value",t.id),e.textContent=t.text,this.#e.appendChild(e),e.addEventListener("click",()=>{t.id!=="sin_resultados"&&(this.#R(t.text,t.id),this.onSelect!==void 0&&this.onSelect(t.id,this),this.#r())})}#M(){const t=document.getElementById(this.id);this.name=t.name,this.#y=t.required,this.rootClassName=t.className,this.#d=t.getBoundingClientRect(),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.#m.push({id:this.#c(e.value),text:e.text})})}#w(){if(this.filter=null,this.#n)return;this.#i.classList.remove(`round${this.bodyRound}`),this.#i.classList.add(`round${this.bodyRound}t`);const t=this.#l.getBoundingClientRect(),e=t.x-this.#d.x,s=t.y-this.#d.y;if(this.searchInputActive){this.#s.style.display="block",this.#s.style.y=s+"px",this.#s.style.width=t.width+"px";const i=this.#s.offsetHeight;this.#e.style.top=i+s+"px",e<0?this.#s.style.left=e+"px":e>0&&(this.#s.style.right=e*-1+"px")}this.#e.style.width=t.width+"px",this.#e.style.x=t.x+"px",this.#e.innerHTML="",this.#e.style.display="block",e<0?this.#e.style.left=e+"px":e>0&&(this.#e.style.right=e*-1+"px"),this.searchInputActive&&this.#s.focus(),this.#x(),this.#n=!0}repositionDropdown(){const e=this.#l.getBoundingClientRect().y-this.#d.y;this.#e.style.top=this.#s.offsetHeight+e+"px",this.#s.style.top=e+"px"}#r(){this.#n&&(this.#e.innerHTML="",this.#e.style.display="none",this.searchInputActive&&(this.#s.style.display="none"),this.#i.classList.add(`round${this.bodyRound}`),this.#n=!1)}async#v(){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.#m,...s].map(i=>[i.id,i])).values()),this.data}async#x(){this.#h({id:"loading",text:"cargando ..."}),this.records=10+this.#t.length,this.#f=!1;let t=await this.#v();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.#C.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(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.#v();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.#f=l===this.#e.lastChild.dataset.value}#R(t,e){this.#t.find(i=>i.value===e)||(this.isMultiple||(this.#t=[]),this.#t.push({text:t,value:e})),this.#o(e)}#o(t){this.onChange!==void 0&&this.onChange(t,this),this.isMultiple?this.#b():this.#B()}#B(){this.#a.value=null,this.#p.value=null,this.#a.value=this.#t.length>0?this.#t[0].text:null,this.#p.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)}#b(){if(this.#i.innerHTML="",this.#t.length<=0){this.#i.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.#i.appendChild(s)})}#A(t){this.#t=this.#t.filter(e=>this.#c(e.value)!==this.#c(t)),this.#o(t)}#H(t){const{scrollTop:e,scrollHeight:s,clientHeight:i}=this.#e;t.target.lastChild!==null&&(t.target.lastChild.dataset.value==="loading"||this.#f||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.#g===void 0||e?this.#E():this.#o()}}h.selectyc=r,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
|