selectyc 0.0.4 → 0.0.6
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 +1 -1
- package/dist/selectyc.js +114 -86
- package/dist/selectyc.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/selectyc.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.custom-multiselect{position:relative;width:100%}.selected-items{display:flex;
|
|
1
|
+
.custom-multiselect{position:relative;width:100%}.selected-items{display:flex;gap:5px;padding:8px;border:1px solid;cursor:default;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:97%;padding-left:.2rem;border:0px solid;background:transparent;cursor:default}.custom-single-select:focus{border:0px solid transparent;outline:none;box-shadow:none}.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{position:absolute;background-color:#374151;max-height:200px;overflow-y:auto;display:none;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{position:absolute;width:100%;padding:3px 10px;border:1px solid;display:none;z-index:999;outline:none;color:#000;font-size:.9rem;@apply dark:border-gray-300 border-blue-500;}.search-input:focus{@apply dark:border-gray-300 border-blue-500;}.search-input::placeholder{color:#4b5563}.select-option{padding:3px 10px;cursor:pointer;font-size:.9rem}.select-option:hover{background-color:#3777de;color:#fff}
|
package/dist/selectyc.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import './selectyc.css';
|
|
2
|
-
class
|
|
2
|
+
class h {
|
|
3
3
|
constructor(t) {
|
|
4
4
|
this.route = t;
|
|
5
5
|
}
|
|
6
6
|
static make(t) {
|
|
7
|
-
return new
|
|
7
|
+
return new h(t);
|
|
8
8
|
}
|
|
9
9
|
setMethod(t) {
|
|
10
10
|
return this.method = t, this;
|
|
@@ -46,32 +46,37 @@ class a {
|
|
|
46
46
|
}
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
|
-
class
|
|
49
|
+
class l {
|
|
50
50
|
#t = [];
|
|
51
|
-
#
|
|
52
|
-
#
|
|
53
|
-
#
|
|
54
|
-
#
|
|
51
|
+
#o;
|
|
52
|
+
#p = [];
|
|
53
|
+
#h;
|
|
54
|
+
#y;
|
|
55
55
|
#s;
|
|
56
56
|
#e;
|
|
57
|
-
#h;
|
|
58
57
|
#l;
|
|
58
|
+
#r;
|
|
59
59
|
#i = !1;
|
|
60
|
-
#
|
|
61
|
-
#
|
|
60
|
+
#f = !1;
|
|
61
|
+
#c = !1;
|
|
62
|
+
#C = "";
|
|
63
|
+
#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>';
|
|
62
64
|
constructor(t) {
|
|
63
65
|
if (window.selects === void 0 && (window.selects = []), window.selects[t] !== void 0)
|
|
64
66
|
return window.selects[t];
|
|
65
|
-
this.id = t, this.name, this.data = [], this.isMultiple = !1, this.singleLabel = " ", this.
|
|
67
|
+
this.id = t, this.name, this.data = [], this.isMultiple = !1, this.clearButton = !1, this.singleLabel = " ", this.records = 10, this.filter = null, this.bodyRound = "", this.width = "100%", this.searchInputActive = !0, this.bodyData = null, this.boxOverflow = "horizontal", window.selects[t] = this;
|
|
66
68
|
}
|
|
67
69
|
static set(t) {
|
|
68
|
-
return new
|
|
70
|
+
return new l(t);
|
|
69
71
|
}
|
|
70
72
|
setData(t) {
|
|
71
73
|
return this.data = t, this;
|
|
72
74
|
}
|
|
73
|
-
setMultiple() {
|
|
74
|
-
return this.isMultiple = !0, this;
|
|
75
|
+
setMultiple(t = "horizontal") {
|
|
76
|
+
return this.isMultiple = !0, this.boxOverflow = t, this;
|
|
77
|
+
}
|
|
78
|
+
setClearButton() {
|
|
79
|
+
return this.clearButton = !0, this;
|
|
75
80
|
}
|
|
76
81
|
getSelectedOptions() {
|
|
77
82
|
return this.#t;
|
|
@@ -91,6 +96,9 @@ class h {
|
|
|
91
96
|
setRS(t) {
|
|
92
97
|
return this.RS = t, this;
|
|
93
98
|
}
|
|
99
|
+
setBodyData(t) {
|
|
100
|
+
return this.bodyData = t, this;
|
|
101
|
+
}
|
|
94
102
|
desactiveSearchInput() {
|
|
95
103
|
return this.searchInputActive = !1, this;
|
|
96
104
|
}
|
|
@@ -109,115 +117,135 @@ class h {
|
|
|
109
117
|
setOnChange(t) {
|
|
110
118
|
return this.onChange = t, this;
|
|
111
119
|
}
|
|
112
|
-
|
|
113
|
-
|
|
120
|
+
cleanSelection() {
|
|
121
|
+
const t = this.#t;
|
|
122
|
+
this.#t = [], this.#u(t);
|
|
123
|
+
}
|
|
124
|
+
#b() {
|
|
125
|
+
this.#x(), this.#s.addEventListener("click", (t) => {
|
|
114
126
|
if (t.target.classList.contains("remove-tag")) {
|
|
115
|
-
this.#
|
|
127
|
+
this.#T(t.target.getAttribute("data-value")), this.onUnselect !== void 0 && this.onUnselect(t.target.getAttribute("data-value")), this.#i && this.#a(), this.#m();
|
|
116
128
|
return;
|
|
117
129
|
}
|
|
118
|
-
this.#i ? this.#
|
|
130
|
+
this.#i ? this.#a() : this.#m();
|
|
119
131
|
}), document.addEventListener("click", (t) => {
|
|
120
|
-
!this.#
|
|
132
|
+
!this.#h.contains(t.target) && !this.#e.contains(t.target) && !t.target.classList.contains("remove-tag") && this.#a();
|
|
121
133
|
}), window.onresize = () => {
|
|
122
|
-
this.#
|
|
123
|
-
}, this.isMultiple && this.#
|
|
134
|
+
this.#a();
|
|
135
|
+
}, this.isMultiple && this.#v();
|
|
124
136
|
}
|
|
125
137
|
// Draw functions
|
|
126
|
-
#
|
|
138
|
+
#x() {
|
|
127
139
|
this.#L();
|
|
128
140
|
const t = document.createElement("div");
|
|
129
141
|
t.className = "main-div-selectyc", t.style.width = this.width;
|
|
130
142
|
const e = document.createElement("div");
|
|
131
143
|
e.className = "custom-multiselect";
|
|
132
144
|
let s = document.createElement("div");
|
|
133
|
-
s.className = "selected-items round" + this.bodyRound, s.tabIndex = 0, this.isMultiple || (s = this.#
|
|
134
|
-
const i = document.getElementById(this.id),
|
|
135
|
-
|
|
136
|
-
let
|
|
137
|
-
t.appendChild(
|
|
145
|
+
s.className = "selected-items round" + this.bodyRound, s.tabIndex = 0, s.classList.add(this.boxOverflow === "horizontal" ? "horizontal-overflow" : "vertical-overflow"), this.isMultiple || (s = this.#E(s)), e.appendChild(s), this.searchInputActive && e.appendChild(this.#O()), e.appendChild(this.#D()), t.appendChild(e);
|
|
146
|
+
const i = document.getElementById(this.id), a = document.createElement("input");
|
|
147
|
+
a.name = i.name, a.style.display = "none";
|
|
148
|
+
let n = i.parentNode;
|
|
149
|
+
t.appendChild(a), n.replaceChild(t, i), this.#o = a, this.#y = s, this.#h = e, this.#s = this.#h.querySelector(".selected-items"), !this.isMultiple && this.#t.length > 0 && (this.#o.value = this.#t[0].value);
|
|
138
150
|
}
|
|
139
|
-
#
|
|
151
|
+
#E(t) {
|
|
140
152
|
const e = document.createElement("input");
|
|
141
|
-
e.className = "custom-single-select", e.
|
|
153
|
+
e.className = "custom-single-select", e.value = this.#t.length === 0 ? this.singleLabel : this.#t[0].text, e.required = this.#f, e.readOnly = !0;
|
|
142
154
|
const s = document.createElement("div");
|
|
143
|
-
return s.innerHTML = this.#
|
|
155
|
+
return s.innerHTML = this.#S, t.appendChild(e), t.appendChild(s), this.#r = e, t;
|
|
144
156
|
}
|
|
145
|
-
#
|
|
157
|
+
#D() {
|
|
146
158
|
const t = document.createElement("div");
|
|
147
|
-
t.style
|
|
159
|
+
t.setAttribute("style", "position:fixed; z-index:999;");
|
|
148
160
|
const e = document.createElement("div");
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
161
|
+
e.className = "global-dropdown";
|
|
162
|
+
let s;
|
|
163
|
+
return e.addEventListener("scroll", (i) => {
|
|
164
|
+
s && clearTimeout(s), s = setTimeout(() => {
|
|
165
|
+
this.#R(i);
|
|
166
|
+
}, 70);
|
|
167
|
+
}), t.appendChild(e), this.#e = e, t;
|
|
168
|
+
}
|
|
169
|
+
#O() {
|
|
152
170
|
const t = document.createElement("input");
|
|
153
171
|
return t.type = "text", t.id = "selectyc_search_input", t.className = "search-input", t.placeholder = "Buscar...", t.addEventListener("input", () => {
|
|
154
|
-
this.filter = t.value, this.#e.innerHTML = "", this
|
|
155
|
-
}), t.focus(), this.#
|
|
172
|
+
this.filter = t.value, this.#e.innerHTML = "", this.filter = t.value, this.#w();
|
|
173
|
+
}), t.focus(), this.#l = t, t;
|
|
156
174
|
}
|
|
157
|
-
#
|
|
175
|
+
#n(t) {
|
|
158
176
|
const e = document.createElement("div");
|
|
159
177
|
e.className = "select-option", e.setAttribute("data-value", t.id), e.textContent = t.text, this.#e.appendChild(e), e.addEventListener("click", () => {
|
|
160
|
-
t.id !== "sin_resultados" && (this.#
|
|
178
|
+
t.id !== "sin_resultados" && (this.#M(t.text, t.id), this.onSelect !== void 0 && this.onSelect(t.id), this.#a());
|
|
161
179
|
});
|
|
162
180
|
}
|
|
163
181
|
// Functions
|
|
164
182
|
#L() {
|
|
165
183
|
const t = document.getElementById(this.id);
|
|
166
|
-
this.name = t.name, this.#
|
|
184
|
+
this.name = t.name, this.#f = t.required, Array.from(t.options).forEach((e) => {
|
|
167
185
|
if (e.selected) {
|
|
168
|
-
const s = e.text, i = this.#
|
|
186
|
+
const s = e.text, i = this.#d(e.value);
|
|
169
187
|
this.isMultiple ? this.#t.push({ value: i, text: s }) : this.#t[0] = { value: i, text: s };
|
|
170
188
|
}
|
|
171
|
-
this.#
|
|
189
|
+
this.#p.push({ id: this.#d(e.value), text: e.text });
|
|
172
190
|
});
|
|
173
191
|
}
|
|
174
|
-
#
|
|
192
|
+
#m() {
|
|
175
193
|
if (this.#i)
|
|
176
194
|
return;
|
|
177
195
|
this.#s.classList.remove(`round${this.bodyRound}`), this.#s.classList.add(`round${this.bodyRound}t`);
|
|
178
|
-
const t = this.#
|
|
196
|
+
const t = this.#h.getBoundingClientRect();
|
|
179
197
|
if (this.searchInputActive) {
|
|
180
|
-
this.#
|
|
181
|
-
const e = this.#
|
|
198
|
+
this.#l.style.display = "block";
|
|
199
|
+
const e = this.#l.offsetHeight;
|
|
182
200
|
this.#e.style.top = e + "px";
|
|
183
201
|
}
|
|
184
|
-
this.#e.style.width = t.width + "px", this.#e.innerHTML = "", this.#e.style.display = "block", this.#
|
|
202
|
+
this.#e.style.width = t.width + "px", this.#e.innerHTML = "", this.#e.style.display = "block", this.#w(), this.#i = !0;
|
|
185
203
|
}
|
|
186
|
-
#
|
|
187
|
-
this.#i && (this.#e.innerHTML = "", this.#e.style.display = "none", this.searchInputActive && (this.#
|
|
204
|
+
#a() {
|
|
205
|
+
this.#i && (this.#e.innerHTML = "", this.#e.style.display = "none", this.searchInputActive && (this.#l.style.display = "none"), this.#s.classList.add(`round${this.bodyRound}`), this.#i = !1);
|
|
188
206
|
}
|
|
189
|
-
async #
|
|
207
|
+
async #g() {
|
|
190
208
|
if (this.RS === void 0)
|
|
191
209
|
return this.data;
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
const
|
|
207
|
-
s.
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
210
|
+
let t = { records: this.records, filter: this.filter };
|
|
211
|
+
t !== null && (t = { ...t, ...this.bodyData });
|
|
212
|
+
const e = await h.make(this.RS).addData(t).setMethod("POST").go(), s = Array.isArray(e) ? e : e.data;
|
|
213
|
+
return this.data = Array.from(new Map([...this.#p, ...s].map((i) => [i.id, i])).values()), this.data;
|
|
214
|
+
}
|
|
215
|
+
async #w() {
|
|
216
|
+
this.#n({ id: "loading", text: "cargando ..." }), this.records = 10 + this.#t.length, this.#c = !1;
|
|
217
|
+
let t = await this.#g();
|
|
218
|
+
const e = this.#t.map((s) => s.value);
|
|
219
|
+
this.#e.lastChild.dataset.value === "loading" && this.#e.removeChild(this.#e.lastChild), t.forEach((s) => {
|
|
220
|
+
s.text.toLowerCase().includes(this.#C.toLowerCase()) && !e.includes(s.id) && this.#n(s);
|
|
221
|
+
}), this.#e.hasChildNodes() || this.#n({ id: "sin_resultados", text: "sin resultados ..." });
|
|
222
|
+
}
|
|
223
|
+
async #N() {
|
|
224
|
+
const t = this.#t.map((n) => n.value);
|
|
225
|
+
let e = this.filter === null ? "" : this.filter, s = this.data.map((n) => n.id);
|
|
226
|
+
this.records = this.records + 10 + this.#t.length;
|
|
227
|
+
let i = await this.#g();
|
|
228
|
+
this.#e.lastChild.dataset.value === "loading" && this.#e.removeChild(this.#e.lastChild);
|
|
229
|
+
const a = this.#e.lastChild.dataset.value;
|
|
230
|
+
i.forEach((n) => {
|
|
231
|
+
n.text.toLowerCase().includes(e.toLowerCase()) && !t.includes(n.id) && !s.includes(n.id) && this.#n(n);
|
|
232
|
+
}), this.#c = a === this.#e.lastChild.dataset.value;
|
|
233
|
+
}
|
|
234
|
+
#M(t, e) {
|
|
235
|
+
this.#t.find((i) => i.value === e) || (this.isMultiple || (this.#t = []), this.#t.push({ text: t, value: e })), this.#u(e);
|
|
236
|
+
}
|
|
237
|
+
#u(t) {
|
|
238
|
+
this.onChange !== void 0 && this.onChange(t), this.isMultiple ? this.#v() : this.#I();
|
|
239
|
+
}
|
|
240
|
+
#I() {
|
|
241
|
+
this.#r.value = null, this.#r.value = this.#t.length > 0 ? this.#t[0].text : null, this.#o.value = this.#t.length > 0 ? this.#t[0].value : null;
|
|
242
|
+
const t = this.#r.parentNode, e = t.firstChild;
|
|
243
|
+
if (e.className === "remove-tag" && e.remove(), !this.clearButton || this.#t.length <= 0)
|
|
244
|
+
return;
|
|
245
|
+
const s = document.createElement("span");
|
|
246
|
+
s.dataset.value = this.#t[0].value, s.innerHTML = "x", s.className = "remove-tag", t.insertBefore(s, t.firstChild);
|
|
219
247
|
}
|
|
220
|
-
#
|
|
248
|
+
#v() {
|
|
221
249
|
if (this.#s.innerHTML = "", this.#t.length <= 0) {
|
|
222
250
|
this.#s.appendChild(document.createElement("div"));
|
|
223
251
|
return;
|
|
@@ -227,20 +255,20 @@ class h {
|
|
|
227
255
|
s.className = "selected-tag", s.innerHTML = `${t} <span class="remove-tag" data-value="${e}">x</span>`, this.#s.appendChild(s);
|
|
228
256
|
});
|
|
229
257
|
}
|
|
230
|
-
#
|
|
231
|
-
this.#t = this.#t.filter((e) => this.#
|
|
258
|
+
#T(t) {
|
|
259
|
+
this.#t = this.#t.filter((e) => this.#d(e.value) !== this.#d(t)), this.#u(t);
|
|
232
260
|
}
|
|
233
|
-
#
|
|
234
|
-
const { scrollTop:
|
|
235
|
-
t +
|
|
261
|
+
#R(t) {
|
|
262
|
+
const { scrollTop: e, scrollHeight: s, clientHeight: i } = this.#e;
|
|
263
|
+
t.target.lastChild !== null && (t.target.lastChild.dataset.value === "loading" || this.#c || e + (i + 1) >= s && (this.#n({ id: "loading", text: "cargando ..." }), this.#N()));
|
|
236
264
|
}
|
|
237
|
-
#
|
|
265
|
+
#d(t) {
|
|
238
266
|
return !isNaN(t) && !isNaN(parseFloat(t)) ? parseInt(t) : t;
|
|
239
267
|
}
|
|
240
268
|
async render() {
|
|
241
|
-
this.#
|
|
269
|
+
this.#b();
|
|
242
270
|
}
|
|
243
271
|
}
|
|
244
272
|
export {
|
|
245
|
-
|
|
273
|
+
l as selectyc
|
|
246
274
|
};
|
package/dist/selectyc.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(l,a){typeof exports=="object"&&typeof module<"u"?a(exports):typeof define=="function"&&define.amd?define(["exports"],a):(l=typeof globalThis<"u"?globalThis:l||self,a(l.selectyc={}))})(this,function(l){"use strict";class a{constructor(t){this.route=t}static make(t){return new a(t)}setMethod(t){return this.method=t,this}getMethod(){return this.method===void 0?"POST":this.method}setData(t){return this.data=t,this}addData(t){if(this.data===void 0)return this.setData(t);for(const e in t)this.data[e]=t[e];return this}setFun(t){return this.fun=t,this}async go(){try{const t={method:this.getMethod(),headers:{"X-CSRF-TOKEN":window.CSRF_TOKEN,Accept:"application/json"}};this.data!==void 0&&(t.body=this.data,Object.prototype.toString.call(this.data)!=="[object FormData]"&&(t.body=JSON.stringify(this.data),t.headers["Content-Type"]="application/json"));const e=await fetch(this.route,t);if(!e.ok){const s=await e.json();throw new Error(s.message)}return this.fun===void 0?await e.json():await this.fun(e)}catch(t){window.toastNotification.setType(!1).show(t.message)}}}class r{#t=[];#o;#f=[];#l;#y;#s;#e;#h;#r;#i=!1;#p=!1;#c=!1;#S="";#C='<svg class="w-5 h-5 text-gray-900 dark:text-gray-400" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="20" height="20" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m19 9-7 7-7-7"/></svg>';constructor(t){if(window.selects===void 0&&(window.selects=[]),window.selects[t]!==void 0)return window.selects[t];this.id=t,this.name,this.data=[],this.isMultiple=!1,this.clearButton=!1,this.singleLabel=" ",this.records=10,this.filter=null,this.bodyRound="",this.width="100%",this.searchInputActive=!0,this.bodyData=null,this.boxOverflow="horizontal",window.selects[t]=this}static set(t){return new r(t)}setData(t){return this.data=t,this}setMultiple(t="horizontal"){return this.isMultiple=!0,this.boxOverflow=t,this}setClearButton(){return this.clearButton=!0,this}getSelectedOptions(){return this.#t}getSelectedOption(){return this.#t[0]}getOptions(){return this.data}setSingleLabel(t){return this.singleLabel=t,this}setBodyRound(t){return this.bodyRound=`-${t}`,this}setRS(t){return this.RS=t,this}setBodyData(t){return this.bodyData=t,this}desactiveSearchInput(){return this.searchInputActive=!1,this}addOption(t){this.data.push(t)}setWidth(t){return this.width=t,this}setOnSelect(t){return this.onSelect=t,this}setOnUnselect(t){return this.onUnselect=t,this}setOnChange(t){return this.onChange=t,this}cleanSelection(){const t=this.#t;this.#t=[],this.#u(t)}#b(){this.#x(),this.#s.addEventListener("click",t=>{if(t.target.classList.contains("remove-tag")){this.#T(t.target.getAttribute("data-value")),this.onUnselect!==void 0&&this.onUnselect(t.target.getAttribute("data-value")),this.#i&&this.#a(),this.#m();return}this.#i?this.#a():this.#m()}),document.addEventListener("click",t=>{!this.#l.contains(t.target)&&!this.#e.contains(t.target)&&!t.target.classList.contains("remove-tag")&&this.#a()}),window.onresize=()=>{this.#a()},this.isMultiple&&this.#v()}#x(){this.#L();const t=document.createElement("div");t.className="main-div-selectyc",t.style.width=this.width;const e=document.createElement("div");e.className="custom-multiselect";let s=document.createElement("div");s.className="selected-items round"+this.bodyRound,s.tabIndex=0,s.classList.add(this.boxOverflow==="horizontal"?"horizontal-overflow":"vertical-overflow"),this.isMultiple||(s=this.#E(s)),e.appendChild(s),this.searchInputActive&&e.appendChild(this.#D()),e.appendChild(this.#O()),t.appendChild(e);const i=document.getElementById(this.id),h=document.createElement("input");h.name=i.name,h.style.display="none";let n=i.parentNode;t.appendChild(h),n.replaceChild(t,i),this.#o=h,this.#y=s,this.#l=e,this.#s=this.#l.querySelector(".selected-items"),!this.isMultiple&&this.#t.length>0&&(this.#o.value=this.#t[0].value)}#E(t){const e=document.createElement("input");e.className="custom-single-select",e.value=this.#t.length===0?this.singleLabel:this.#t[0].text,e.required=this.#p,e.readOnly=!0;const s=document.createElement("div");return s.innerHTML=this.#C,t.appendChild(e),t.appendChild(s),this.#r=e,t}#O(){const t=document.createElement("div");t.setAttribute("style","position:fixed; z-index:999;");const e=document.createElement("div");e.className="global-dropdown";let s;return e.addEventListener("scroll",i=>{s&&clearTimeout(s),s=setTimeout(()=>{this.#R(i)},70)}),t.appendChild(e),this.#e=e,t}#D(){const t=document.createElement("input");return t.type="text",t.id="selectyc_search_input",t.className="search-input",t.placeholder="Buscar...",t.addEventListener("input",()=>{this.filter=t.value,this.#e.innerHTML="",this.filter=t.value,this.#w()}),t.focus(),this.#h=t,t}#n(t){const e=document.createElement("div");e.className="select-option",e.setAttribute("data-value",t.id),e.textContent=t.text,this.#e.appendChild(e),e.addEventListener("click",()=>{t.id!=="sin_resultados"&&(this.#N(t.text,t.id),this.onSelect!==void 0&&this.onSelect(t.id),this.#a())})}#L(){const t=document.getElementById(this.id);this.name=t.name,this.#p=t.required,Array.from(t.options).forEach(e=>{if(e.selected){const s=e.text,i=this.#d(e.value);this.isMultiple?this.#t.push({value:i,text:s}):this.#t[0]={value:i,text:s}}this.#f.push({id:this.#d(e.value),text:e.text})})}#m(){if(this.#i)return;this.#s.classList.remove(`round${this.bodyRound}`),this.#s.classList.add(`round${this.bodyRound}t`);const t=this.#l.getBoundingClientRect();if(this.searchInputActive){this.#h.style.display="block";const e=this.#h.offsetHeight;this.#e.style.top=e+"px"}this.#e.style.width=t.width+"px",this.#e.innerHTML="",this.#e.style.display="block",this.#w(),this.#i=!0}#a(){this.#i&&(this.#e.innerHTML="",this.#e.style.display="none",this.searchInputActive&&(this.#h.style.display="none"),this.#s.classList.add(`round${this.bodyRound}`),this.#i=!1)}async#g(){if(this.RS===void 0)return this.data;let t={records:this.records,filter:this.filter};t!==null&&(t={...t,...this.bodyData});const e=await a.make(this.RS).addData(t).setMethod("POST").go(),s=Array.isArray(e)?e:e.data;return this.data=Array.from(new Map([...this.#f,...s].map(i=>[i.id,i])).values()),this.data}async#w(){this.#n({id:"loading",text:"cargando ..."}),this.records=10+this.#t.length,this.#c=!1;let t=await this.#g();const e=this.#t.map(s=>s.value);this.#e.lastChild.dataset.value==="loading"&&this.#e.removeChild(this.#e.lastChild),t.forEach(s=>{s.text.toLowerCase().includes(this.#S.toLowerCase())&&!e.includes(s.id)&&this.#n(s)}),this.#e.hasChildNodes()||this.#n({id:"sin_resultados",text:"sin resultados ..."})}async#M(){const t=this.#t.map(n=>n.value);let e=this.filter===null?"":this.filter,s=this.data.map(n=>n.id);this.records=this.records+10+this.#t.length;let i=await this.#g();this.#e.lastChild.dataset.value==="loading"&&this.#e.removeChild(this.#e.lastChild);const h=this.#e.lastChild.dataset.value;i.forEach(n=>{n.text.toLowerCase().includes(e.toLowerCase())&&!t.includes(n.id)&&!s.includes(n.id)&&this.#n(n)}),this.#c=h===this.#e.lastChild.dataset.value}#N(t,e){this.#t.find(i=>i.value===e)||(this.isMultiple||(this.#t=[]),this.#t.push({text:t,value:e})),this.#u(e)}#u(t){this.onChange!==void 0&&this.onChange(t),this.isMultiple?this.#v():this.#I()}#I(){this.#r.value=null,this.#r.value=this.#t.length>0?this.#t[0].text:null,this.#o.value=this.#t.length>0?this.#t[0].value:null;const t=this.#r.parentNode,e=t.firstChild;if(e.className==="remove-tag"&&e.remove(),!this.clearButton||this.#t.length<=0)return;const s=document.createElement("span");s.dataset.value=this.#t[0].value,s.innerHTML="x",s.className="remove-tag",t.insertBefore(s,t.firstChild)}#v(){if(this.#s.innerHTML="",this.#t.length<=0){this.#s.appendChild(document.createElement("div"));return}this.#t.forEach(({text:t,value:e})=>{const s=document.createElement("div");s.className="selected-tag",s.innerHTML=`${t} <span class="remove-tag" data-value="${e}">x</span>`,this.#s.appendChild(s)})}#T(t){this.#t=this.#t.filter(e=>this.#d(e.value)!==this.#d(t)),this.#u(t)}#R(t){const{scrollTop:e,scrollHeight:s,clientHeight:i}=this.#e;t.target.lastChild!==null&&(t.target.lastChild.dataset.value==="loading"||this.#c||e+(i+1)>=s&&(this.#n({id:"loading",text:"cargando ..."}),this.#M()))}#d(t){return!isNaN(t)&&!isNaN(parseFloat(t))?parseInt(t):t}async render(){this.#b()}}l.selectyc=r,Object.defineProperty(l,Symbol.toStringTag,{value:"Module"})});
|