selectyc 0.0.16 → 0.0.18
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 +97 -90
- 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;gap:5px;padding:8px;border:1px solid;cursor:pointer;align-items:center;@apply bg-gray-50 border-gray-300 text-gray-900 text-sm focus:ring-blue-500 focus:border-[2px] focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500;}.horizontal-overflow{flex-wrap:nowrap;height:42px;white-space:nowrap;overflow-x:auto;overflow-y:hidden}.vertical-overflow{flex-wrap:wrap;min-height:42px;height:auto;max-height:120px;white-space:nowrap;overflow-x:auto;overflow-y:auto}.round{@apply rounded-lg;}.roundt{@apply rounded-t-lg;}.round-l{@apply rounded-l-lg;}.round-r{@apply rounded-r-lg;}.round-lt{@apply rounded-tl-lg;}.round-rt{@apply rounded-tr-lg;}.selected-items::-webkit-scrollbar{height:6px;width:8px}.selected-items::-webkit-scrollbar-thumb{border-radius:1rem;@apply bg-cyan-400 dark:bg-cyan-700;}.selected-items::-webkit-scrollbar-thumb:hover{@apply bg-cyan-500 dark:bg-cyan-600;}.custom-single-select{width:97%;padding-left:.2rem;border:0px solid;background:transparent;font-size:.9rem;cursor:pointer}.custom-single-select:focus{border:0px solid transparent;outline:none;box-shadow:none}.custom-single-select::placeholder{opacity:.7;font-style:italic;font-size:14px}.selected-tag{background-color:#007bff;color:#fff;padding:4px 8px;border-radius:12px;display:inline-flex;align-items:center;gap:5px;font-size:14px;white-space:nowrap;flex:0 0 auto}.remove-tag{cursor:pointer;font-weight:700;border:solid 0px;border-radius:.5rem;padding:1px 6px;@apply hover:bg-blue-400 dark:hover:bg-sky-800;}.global-dropdown{
|
|
1
|
+
.custom-multiselect{position:relative;width:100%}.selected-items{display:flex;gap:5px;padding:8px;border:1px solid;cursor:pointer;align-items:center;@apply bg-gray-50 border-gray-300 text-gray-900 text-sm focus:ring-blue-500 focus:border-[2px] focus:border-blue-500 dark:bg-gray-700 dark:border-gray-600 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500;}.horizontal-overflow{flex-wrap:nowrap;height:42px;white-space:nowrap;overflow-x:auto;overflow-y:hidden}.vertical-overflow{flex-wrap:wrap;min-height:42px;height:auto;max-height:120px;white-space:nowrap;overflow-x:auto;overflow-y:auto}.round{@apply rounded-lg;}.roundt{@apply rounded-t-lg;}.round-l{@apply rounded-l-lg;}.round-r{@apply rounded-r-lg;}.round-lt{@apply rounded-tl-lg;}.round-rt{@apply rounded-tr-lg;}.selected-items::-webkit-scrollbar{height:6px;width:8px}.selected-items::-webkit-scrollbar-thumb{border-radius:1rem;@apply bg-cyan-400 dark:bg-cyan-700;}.selected-items::-webkit-scrollbar-thumb:hover{@apply bg-cyan-500 dark:bg-cyan-600;}.custom-single-select{width:97%;padding-left:.2rem;border:0px solid;background:transparent;font-size:.9rem;cursor:pointer}.custom-single-select:focus{border:0px solid transparent;outline:none;box-shadow:none}.custom-single-select::placeholder{opacity:.7;font-style:italic;font-size:14px}.selected-tag{background-color:#007bff;color:#fff;padding:4px 8px;border-radius:12px;display:inline-flex;align-items:center;gap:5px;font-size:14px;white-space:nowrap;flex:0 0 auto}.remove-tag{cursor:pointer;font-weight:700;border:solid 0px;border-radius:.5rem;padding:1px 6px;@apply hover:bg-blue-400 dark:hover:bg-sky-800;}.global-dropdown{background-color:#374151;max-height:200px;overflow-y:auto;display:none;z-index:999;box-shadow:0 2px 8px #0003;border-bottom-left-radius:.6rem;border-bottom-right-radius:.6rem;@apply bg-gray-50 dark:bg-gray-700;}.global-dropdown::-webkit-scrollbar{width:10px;border-radius:.6rem;@apply bg-gray-200 dark:bg-gray-400;}.global-dropdown::-webkit-scrollbar-thumb{border-radius:.6rem;@apply bg-gray-400 dark:bg-gray-600;}.search-input{width:100%;padding:3px 10px;border:1px solid;display:none;z-index:999;outline:none;color:#000;font-size:.9rem;@apply bg-white dark:bg-gray-600 dark:border-gray-500 dark:text-white border-blue-500;}.search-input:focus{@apply dark:border-gray-500 border-blue-500;}.search-input::placeholder{@apply text-gray-700 dark:text-gray-400;}.select-option{padding:3px 10px;cursor:pointer;font-size:.9rem}.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 a {
|
|
3
3
|
constructor(t) {
|
|
4
4
|
this.route = t;
|
|
5
5
|
}
|
|
6
6
|
static make(t) {
|
|
7
|
-
return new
|
|
7
|
+
return new a(t);
|
|
8
8
|
}
|
|
9
9
|
setMethod(t) {
|
|
10
10
|
return this.method = t, this;
|
|
@@ -48,21 +48,23 @@ class l {
|
|
|
48
48
|
}
|
|
49
49
|
class h {
|
|
50
50
|
#t = [];
|
|
51
|
-
#
|
|
52
|
-
#
|
|
53
|
-
#
|
|
54
|
-
#
|
|
51
|
+
#p;
|
|
52
|
+
#g = [];
|
|
53
|
+
#i;
|
|
54
|
+
#w;
|
|
55
55
|
#s;
|
|
56
56
|
#e;
|
|
57
|
-
#
|
|
58
|
-
#
|
|
59
|
-
#
|
|
60
|
-
#
|
|
61
|
-
#
|
|
62
|
-
#y
|
|
63
|
-
#
|
|
64
|
-
#
|
|
65
|
-
#
|
|
57
|
+
#n;
|
|
58
|
+
#h;
|
|
59
|
+
#f;
|
|
60
|
+
#r;
|
|
61
|
+
#o;
|
|
62
|
+
#y;
|
|
63
|
+
#l = !1;
|
|
64
|
+
#v = !1;
|
|
65
|
+
#m = !1;
|
|
66
|
+
#E = "";
|
|
67
|
+
#D = '<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
68
|
constructor(t) {
|
|
67
69
|
if (window.selects === void 0 && (window.selects = []), window.selects[t] !== void 0)
|
|
68
70
|
return window.selects[t];
|
|
@@ -81,7 +83,7 @@ class h {
|
|
|
81
83
|
return this.clearButton = !0, this;
|
|
82
84
|
}
|
|
83
85
|
setSelectedOptions(t) {
|
|
84
|
-
this.#t = t, this.#
|
|
86
|
+
this.#t = t, this.#c(t);
|
|
85
87
|
}
|
|
86
88
|
getSelectedOptions() {
|
|
87
89
|
return this.#t;
|
|
@@ -124,96 +126,101 @@ class h {
|
|
|
124
126
|
}
|
|
125
127
|
cleanSelection() {
|
|
126
128
|
const t = this.#t;
|
|
127
|
-
this.#t = [], this.#
|
|
129
|
+
this.#t = [], this.#c(t);
|
|
128
130
|
}
|
|
129
|
-
#
|
|
130
|
-
this.#
|
|
131
|
+
#L() {
|
|
132
|
+
this.#N(), this.#s.addEventListener("click", (t) => {
|
|
131
133
|
if (t.target.classList.contains("remove-tag")) {
|
|
132
|
-
this.#
|
|
134
|
+
this.#H(t.target.getAttribute("data-value")), this.onUnselect !== void 0 && this.onUnselect(t.target.getAttribute("data-value"), this), this.#l && this.#a(), this.#C();
|
|
133
135
|
return;
|
|
134
136
|
}
|
|
135
|
-
this.#
|
|
137
|
+
this.#l ? this.#a() : this.#C();
|
|
136
138
|
}), document.addEventListener("click", (t) => {
|
|
137
|
-
!this.#
|
|
139
|
+
!this.#i.contains(t.target) && !this.#e.contains(t.target) && !t.target.classList.contains("remove-tag") && this.#a();
|
|
138
140
|
}), window.onresize = () => {
|
|
139
|
-
this.#
|
|
140
|
-
},
|
|
141
|
+
this.#a();
|
|
142
|
+
}, window.addEventListener("scroll", () => {
|
|
143
|
+
this.#a();
|
|
144
|
+
}), this.isMultiple && this.#S();
|
|
141
145
|
}
|
|
142
146
|
// Draw functions
|
|
143
|
-
#
|
|
144
|
-
this.#
|
|
147
|
+
#N() {
|
|
148
|
+
this.#B();
|
|
145
149
|
const t = document.createElement("div");
|
|
146
150
|
t.className = "main-div-selectyc", t.style.width = this.width, t.id = `selectyc_main_div_${this.id}`;
|
|
147
151
|
const e = document.createElement("div");
|
|
148
152
|
e.className = "custom-multiselect";
|
|
149
153
|
let s = document.createElement("div");
|
|
150
|
-
s.className = "selected-items round" + this.bodyRound, s.tabIndex = 0, s.classList.add(this.boxOverflow === "horizontal" ? "horizontal-overflow" : "vertical-overflow"), this.isMultiple || (s = this.#
|
|
151
|
-
const i = document.getElementById(this.id),
|
|
152
|
-
|
|
153
|
-
let
|
|
154
|
-
t.appendChild(
|
|
154
|
+
s.className = "selected-items round" + this.bodyRound, s.tabIndex = 0, s.classList.add(this.boxOverflow === "horizontal" ? "horizontal-overflow" : "vertical-overflow"), this.isMultiple || (s = this.#O(s)), e.appendChild(s), e.appendChild(this.#I()), t.appendChild(e);
|
|
155
|
+
const i = document.getElementById(this.id), n = document.createElement("input");
|
|
156
|
+
n.name = i.name, n.setAttribute("data-id", i.id), this.rootClassName !== "" && (n.className = i.className), n.style.display = "none";
|
|
157
|
+
let l = i.parentNode;
|
|
158
|
+
t.appendChild(n), l.replaceChild(t, i), this.#p = n, this.#w = s, this.#i = e, this.#s = this.#i.querySelector(".selected-items"), !this.isMultiple && this.#t.length > 0 && (this.#p.value = this.#t[0].value);
|
|
155
159
|
}
|
|
156
|
-
#
|
|
160
|
+
#O(t) {
|
|
157
161
|
const e = document.createElement("input");
|
|
158
162
|
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
163
|
const s = document.createElement("div");
|
|
160
|
-
return s.innerHTML = this.#
|
|
164
|
+
return s.innerHTML = this.#D, t.appendChild(this.#M()), t.appendChild(e), t.appendChild(s), this.#h = e, t;
|
|
161
165
|
}
|
|
162
|
-
#
|
|
166
|
+
#M() {
|
|
163
167
|
const t = document.createElement("input");
|
|
164
|
-
return t.type = "text", t.required = this.#
|
|
168
|
+
return t.type = "text", t.required = this.#v, 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;
|
|
165
169
|
}
|
|
166
|
-
#
|
|
170
|
+
#I() {
|
|
167
171
|
const t = document.createElement("div");
|
|
168
172
|
t.setAttribute("style", "position:fixed; z-index:999;");
|
|
169
173
|
const e = document.createElement("div");
|
|
170
|
-
e.
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
174
|
+
e.setAttribute("style", "position:absolute;");
|
|
175
|
+
const s = document.createElement("div");
|
|
176
|
+
s.className = "global-dropdown", this.searchInputActive && e.appendChild(this.#R());
|
|
177
|
+
let i;
|
|
178
|
+
return s.addEventListener("scroll", (n) => {
|
|
179
|
+
i && clearTimeout(i), i = setTimeout(() => {
|
|
180
|
+
this.#_(n);
|
|
175
181
|
}, 70);
|
|
176
|
-
}),
|
|
182
|
+
}), e.appendChild(s), this.#e = s, this.#r = e, t.appendChild(e), t;
|
|
177
183
|
}
|
|
178
|
-
#
|
|
184
|
+
#R() {
|
|
179
185
|
const t = document.createElement("input");
|
|
180
186
|
return t.type = "text", t.id = "selectyc_search_input", t.className = "search-input", t.placeholder = "Buscar...", t.addEventListener("input", () => {
|
|
181
187
|
this.filter = t.value, this.#e.innerHTML = "", this.filter = t.value, this.#x();
|
|
182
|
-
}), this.#
|
|
188
|
+
}), this.#n = t, t;
|
|
183
189
|
}
|
|
184
|
-
#
|
|
190
|
+
#d(t) {
|
|
185
191
|
const e = document.createElement("div");
|
|
186
192
|
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.#
|
|
193
|
+
t.id !== "sin_resultados" && (this.#A(t.text, t.id), this.onSelect !== void 0 && this.onSelect(t.id, this), this.#a());
|
|
188
194
|
});
|
|
189
195
|
}
|
|
190
196
|
// Functions
|
|
191
|
-
#
|
|
197
|
+
#B() {
|
|
192
198
|
const t = document.getElementById(this.id);
|
|
193
|
-
this.name = t.name, this.#
|
|
199
|
+
this.name = t.name, this.#v = t.required, this.rootClassName = t.className, this.#o = t.getBoundingClientRect(), this.#y = document.documentElement.clientWidth, Array.from(t.options).forEach((e) => {
|
|
194
200
|
if (e.outerHTML.includes("selected")) {
|
|
195
|
-
const s = e.text, i = this.#
|
|
201
|
+
const s = e.text, i = this.#u(e.value);
|
|
196
202
|
this.isMultiple ? this.#t.push({ value: i, text: s }) : this.#t[0] = { value: i, text: s };
|
|
197
203
|
}
|
|
198
|
-
this.#
|
|
204
|
+
this.#g.push({ id: this.#u(e.value), text: e.text });
|
|
199
205
|
});
|
|
200
206
|
}
|
|
201
|
-
#
|
|
202
|
-
if (this.filter = null, this.#
|
|
207
|
+
#C() {
|
|
208
|
+
if (this.filter = null, this.#l)
|
|
203
209
|
return;
|
|
204
210
|
this.#s.classList.remove(`round${this.bodyRound}`), this.#s.classList.add(`round${this.bodyRound}t`);
|
|
205
|
-
const t = this.#
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
211
|
+
const t = this.#i.getBoundingClientRect(), s = this.#n.getBoundingClientRect().top + window.scrollY;
|
|
212
|
+
this.#r.style.top = s * -1 + "px";
|
|
213
|
+
let i = t.x - this.#o.x;
|
|
214
|
+
i = Math.abs(i) > this.#y - document.documentElement.clientWidth ? i : 0, i < 0 && this.#o.x !== 0 ? this.#r.style.left = i + "px" : i > 0 && this.#o.x !== 0 && (this.#r.style.right = i * -1 + "px"), this.searchInputActive && (this.#n.style.display = "block", this.#n.style.width = t.width + "px"), this.#e.style.width = t.width + "px", this.#e.innerHTML = "", this.#e.style.display = "block", this.searchInputActive && this.#n.focus(), this.#x(), this.#l = !0;
|
|
215
|
+
}
|
|
216
|
+
repositionDropdown() {
|
|
217
|
+
const t = this.#i.getBoundingClientRect(), s = this.#i.getBoundingClientRect().top + window.scrollY, i = t.y - this.#o.y;
|
|
218
|
+
console.log(s), this.#r.style.top = i + "px";
|
|
212
219
|
}
|
|
213
|
-
#
|
|
214
|
-
this.#
|
|
220
|
+
#a() {
|
|
221
|
+
this.#l && (this.#e.innerHTML = "", this.#e.style.display = "none", this.searchInputActive && (this.#n.style.display = "none"), this.#s.classList.add(`round${this.bodyRound}`), this.#l = !1);
|
|
215
222
|
}
|
|
216
|
-
async #
|
|
223
|
+
async #b() {
|
|
217
224
|
if (this.RS === void 0)
|
|
218
225
|
return this.data;
|
|
219
226
|
let t = { records: this.records, filter: this.filter };
|
|
@@ -221,43 +228,43 @@ class h {
|
|
|
221
228
|
const i = this.bodyData();
|
|
222
229
|
t = { ...t, ...i };
|
|
223
230
|
} else this.bodyData !== null && (t = { ...t, ...this.bodyData });
|
|
224
|
-
const e = await
|
|
225
|
-
return this.data = Array.from(new Map([...this.#
|
|
231
|
+
const e = await a.make(this.RS).addData(t).setMethod("POST").go(), s = Array.isArray(e) ? e : e.data;
|
|
232
|
+
return this.data = Array.from(new Map([...this.#g, ...s].map((i) => [i.id, i])).values()), this.data;
|
|
226
233
|
}
|
|
227
234
|
async #x() {
|
|
228
|
-
this.#
|
|
229
|
-
let t = await this.#
|
|
235
|
+
this.#d({ id: "loading", text: "cargando ..." }), this.records = 10 + this.#t.length, this.#m = !1;
|
|
236
|
+
let t = await this.#b();
|
|
230
237
|
const e = this.#t.map((s) => s.value);
|
|
231
238
|
this.#e.lastChild.dataset.value === "loading" && this.#e.removeChild(this.#e.lastChild), t.forEach((s) => {
|
|
232
|
-
s.text.toLowerCase().includes(this.#
|
|
233
|
-
}), this.#e.hasChildNodes() || this.#
|
|
239
|
+
s.text.toLowerCase().includes(this.#E.toLowerCase()) && !e.includes(s.id) && this.#d(s);
|
|
240
|
+
}), this.#e.hasChildNodes() || this.#d({ id: "sin_resultados", text: "sin resultados ..." });
|
|
234
241
|
}
|
|
235
|
-
async #
|
|
236
|
-
const t = this.#t.map((
|
|
237
|
-
let e = this.filter === null ? "" : this.filter, s = this.data.map((
|
|
242
|
+
async #T() {
|
|
243
|
+
const t = this.#t.map((l) => l.value);
|
|
244
|
+
let e = this.filter === null ? "" : this.filter, s = this.data.map((l) => l.id);
|
|
238
245
|
this.records = this.records + 10 + this.#t.length;
|
|
239
|
-
let i = await this.#
|
|
246
|
+
let i = await this.#b();
|
|
240
247
|
this.#e.lastChild.dataset.value === "loading" && this.#e.removeChild(this.#e.lastChild);
|
|
241
|
-
const
|
|
242
|
-
i.forEach((
|
|
243
|
-
|
|
244
|
-
}), this.#
|
|
248
|
+
const n = this.#e.lastChild.dataset.value;
|
|
249
|
+
i.forEach((l) => {
|
|
250
|
+
l.text.toLowerCase().includes(e.toLowerCase()) && !t.includes(l.id) && !s.includes(l.id) && this.#d(l);
|
|
251
|
+
}), this.#m = n === this.#e.lastChild.dataset.value;
|
|
245
252
|
}
|
|
246
|
-
#
|
|
247
|
-
this.#t.find((i) => i.value === e) || (this.isMultiple || (this.#t = []), this.#t.push({ text: t, value: e })), this.#
|
|
253
|
+
#A(t, e) {
|
|
254
|
+
this.#t.find((i) => i.value === e) || (this.isMultiple || (this.#t = []), this.#t.push({ text: t, value: e })), this.#c(e);
|
|
248
255
|
}
|
|
249
|
-
#
|
|
250
|
-
this.onChange !== void 0 && this.onChange(t, this), this.isMultiple ? this.#
|
|
256
|
+
#c(t) {
|
|
257
|
+
this.onChange !== void 0 && this.onChange(t, this), this.isMultiple ? this.#S() : this.#k();
|
|
251
258
|
}
|
|
252
|
-
#
|
|
253
|
-
this.#
|
|
254
|
-
const t = this.#
|
|
259
|
+
#k() {
|
|
260
|
+
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.#p.value = this.#t.length > 0 ? this.#t[0].value : null;
|
|
261
|
+
const t = this.#h.parentNode, e = t.firstChild;
|
|
255
262
|
if (e.className === "remove-tag" && e.remove(), !this.clearButton || this.#t.length <= 0)
|
|
256
263
|
return;
|
|
257
264
|
const s = document.createElement("span");
|
|
258
265
|
s.dataset.value = this.#t[0].value, s.innerHTML = "x", s.className = "remove-tag", t.insertBefore(s, t.firstChild);
|
|
259
266
|
}
|
|
260
|
-
#
|
|
267
|
+
#S() {
|
|
261
268
|
if (this.#s.innerHTML = "", this.#t.length <= 0) {
|
|
262
269
|
this.#s.appendChild(document.createElement("div"));
|
|
263
270
|
return;
|
|
@@ -267,19 +274,19 @@ class h {
|
|
|
267
274
|
s.className = "selected-tag", s.innerHTML = `${t} <span class="remove-tag" data-value="${e}">x</span>`, this.#s.appendChild(s);
|
|
268
275
|
});
|
|
269
276
|
}
|
|
270
|
-
#
|
|
271
|
-
this.#t = this.#t.filter((e) => this.#
|
|
277
|
+
#H(t) {
|
|
278
|
+
this.#t = this.#t.filter((e) => this.#u(e.value) !== this.#u(t)), this.#c(t);
|
|
272
279
|
}
|
|
273
|
-
#
|
|
280
|
+
#_(t) {
|
|
274
281
|
const { scrollTop: e, scrollHeight: s, clientHeight: i } = this.#e;
|
|
275
|
-
t.target.lastChild !== null && (t.target.lastChild.dataset.value === "loading" || this.#
|
|
282
|
+
t.target.lastChild !== null && (t.target.lastChild.dataset.value === "loading" || this.#m || e + (i + 1) >= s && (this.#d({ id: "loading", text: "cargando ..." }), this.#T()));
|
|
276
283
|
}
|
|
277
|
-
#
|
|
284
|
+
#u(t) {
|
|
278
285
|
return !isNaN(t) && !isNaN(parseFloat(t)) ? parseInt(t) : t;
|
|
279
286
|
}
|
|
280
287
|
async render() {
|
|
281
288
|
const t = document.getElementById(this.id), e = t === null ? !1 : t.outerHTML.includes("<select");
|
|
282
|
-
this.#
|
|
289
|
+
this.#w === void 0 || e ? this.#L() : this.#c();
|
|
283
290
|
}
|
|
284
291
|
}
|
|
285
292
|
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=[];#c;#f=[];#d;#m;#s;#e;#i;#l;#u;#g;#n=!1;#y=!1;#p=!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.#r(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.#r(t)}#E(){this.#D(),this.#s.addEventListener("click",t=>{if(t.target.classList.contains("remove-tag")){this.#B(t.target.getAttribute("data-value")),this.onUnselect!==void 0&&this.onUnselect(t.target.getAttribute("data-value"),this),this.#n&&this.#h(),this.#v();return}this.#n?this.#h():this.#v()}),document.addEventListener("click",t=>{!this.#d.contains(t.target)&&!this.#e.contains(t.target)&&!t.target.classList.contains("remove-tag")&&this.#h()}),window.onresize=()=>{this.#h()},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.#c=l,this.#m=s,this.#d=e,this.#s=this.#d.querySelector(".selected-items"),!this.isMultiple&&this.#t.length>0&&(this.#c.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.#l=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.#u=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.#k(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.#i=t,t}#a(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.#h())})}#M(){const t=document.getElementById(this.id);this.name=t.name,this.#y=t.required,this.rootClassName=t.className,this.#g=t.getBoundingClientRect(),Array.from(t.options).forEach(e=>{if(e.outerHTML.includes("selected")){const s=e.text,i=this.#o(e.value);this.isMultiple?this.#t.push({value:i,text:s}):this.#t[0]={value:i,text:s}}this.#f.push({id:this.#o(e.value),text:e.text})})}#v(){if(this.filter=null,this.#n)return;this.#s.classList.remove(`round${this.bodyRound}`),this.#s.classList.add(`round${this.bodyRound}t`);const t=this.#d.getBoundingClientRect(),e=t.x-this.#g.x;if(this.searchInputActive){this.#i.style.display="block",this.#i.style.width=t.width+"px";const s=this.#i.offsetHeight;this.#e.style.top=s+"px",e<0?this.#i.style.left=e+"px":e>0&&(this.#i.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.#i.focus(),this.#x(),this.#n=!0}#h(){this.#n&&(this.#e.innerHTML="",this.#e.style.display="none",this.searchInputActive&&(this.#i.style.display="none"),this.#s.classList.add(`round${this.bodyRound}`),this.#n=!1)}async#w(){if(this.RS===void 0)return this.data;let t={records:this.records,filter:this.filter};if(typeof this.bodyData=="function"){const i=this.bodyData();t={...t,...i}}else this.bodyData!==null&&(t={...t,...this.bodyData});const e=await a.make(this.RS).addData(t).setMethod("POST").go(),s=Array.isArray(e)?e:e.data;return this.data=Array.from(new Map([...this.#f,...s].map(i=>[i.id,i])).values()),this.data}async#x(){this.#a({id:"loading",text:"cargando ..."}),this.records=10+this.#t.length,this.#p=!1;let t=await this.#w();const e=this.#t.map(s=>s.value);this.#e.lastChild.dataset.value==="loading"&&this.#e.removeChild(this.#e.lastChild),t.forEach(s=>{s.text.toLowerCase().includes(this.#C.toLowerCase())&&!e.includes(s.id)&&this.#a(s)}),this.#e.hasChildNodes()||this.#a({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.#w();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.#a(n)}),this.#p=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.#r(e)}#r(t){this.onChange!==void 0&&this.onChange(t,this),this.isMultiple?this.#b():this.#A()}#A(){this.#l.value=null,this.#u.value=null,this.#l.value=this.#t.length>0?this.#t[0].text:null,this.#u.value=this.#t.length>0?this.#t[0].text:null,this.#l.placeholder=this.singleLabel,this.#c.value=this.#t.length>0?this.#t[0].value:null;const t=this.#l.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.#s.innerHTML="",this.#t.length<=0){this.#s.appendChild(document.createElement("div"));return}this.#t.forEach(({text:t,value:e})=>{const s=document.createElement("div");s.className="selected-tag",s.innerHTML=`${t} <span class="remove-tag" data-value="${e}">x</span>`,this.#s.appendChild(s)})}#B(t){this.#t=this.#t.filter(e=>this.#o(e.value)!==this.#o(t)),this.#r(t)}#k(t){const{scrollTop:e,scrollHeight:s,clientHeight:i}=this.#e;t.target.lastChild!==null&&(t.target.lastChild.dataset.value==="loading"||this.#p||e+(i+1)>=s&&(this.#a({id:"loading",text:"cargando ..."}),this.#T()))}#o(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.#m===void 0||e?this.#E():this.#r()}}h.selectyc=r,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=[];#p;#g=[];#i;#y;#s;#e;#n;#h;#f;#o;#d;#w;#l=!1;#v=!1;#m=!1;#E="";#D='<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 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.#c(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.#c(t)}#L(){this.#N(),this.#s.addEventListener("click",t=>{if(t.target.classList.contains("remove-tag")){this.#H(t.target.getAttribute("data-value")),this.onUnselect!==void 0&&this.onUnselect(t.target.getAttribute("data-value"),this),this.#l&&this.#a(),this.#b();return}this.#l?this.#a():this.#b()}),document.addEventListener("click",t=>{!this.#i.contains(t.target)&&!this.#e.contains(t.target)&&!t.target.classList.contains("remove-tag")&&this.#a()}),window.onresize=()=>{this.#a()},window.addEventListener("scroll",()=>{this.#a()}),this.isMultiple&&this.#S()}#N(){this.#T();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.#O(s)),e.appendChild(s),e.appendChild(this.#I()),t.appendChild(e);const i=document.getElementById(this.id),n=document.createElement("input");n.name=i.name,n.setAttribute("data-id",i.id),this.rootClassName!==""&&(n.className=i.className),n.style.display="none";let l=i.parentNode;t.appendChild(n),l.replaceChild(t,i),this.#p=n,this.#y=s,this.#i=e,this.#s=this.#i.querySelector(".selected-items"),!this.isMultiple&&this.#t.length>0&&(this.#p.value=this.#t[0].value)}#O(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.#D,t.appendChild(this.#M()),t.appendChild(e),t.appendChild(s),this.#h=e,t}#M(){const t=document.createElement("input");return t.type="text",t.required=this.#v,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}#I(){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.#R());let i;return s.addEventListener("scroll",n=>{i&&clearTimeout(i),i=setTimeout(()=>{this.#j(n)},70)}),e.appendChild(s),this.#e=s,this.#o=e,t.appendChild(e),t}#R(){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.#n=t,t}#r(t){const e=document.createElement("div");e.className="select-option",e.setAttribute("data-value",t.id),e.textContent=t.text,this.#e.appendChild(e),e.addEventListener("click",()=>{t.id!=="sin_resultados"&&(this.#A(t.text,t.id),this.onSelect!==void 0&&this.onSelect(t.id,this),this.#a())})}#T(){const t=document.getElementById(this.id);this.name=t.name,this.#v=t.required,this.rootClassName=t.className,this.#d=t.getBoundingClientRect(),this.#w=document.documentElement.clientWidth,Array.from(t.options).forEach(e=>{if(e.outerHTML.includes("selected")){const s=e.text,i=this.#u(e.value);this.isMultiple?this.#t.push({value:i,text:s}):this.#t[0]={value:i,text:s}}this.#g.push({id:this.#u(e.value),text:e.text})})}#b(){if(this.filter=null,this.#l)return;this.#s.classList.remove(`round${this.bodyRound}`),this.#s.classList.add(`round${this.bodyRound}t`);const t=this.#i.getBoundingClientRect(),s=this.#n.getBoundingClientRect().top+window.scrollY;this.#o.style.top=s*-1+"px";let i=t.x-this.#d.x;i=Math.abs(i)>this.#w-document.documentElement.clientWidth?i:0,i<0&&this.#d.x!==0?this.#o.style.left=i+"px":i>0&&this.#d.x!==0&&(this.#o.style.right=i*-1+"px"),this.searchInputActive&&(this.#n.style.display="block",this.#n.style.width=t.width+"px"),this.#e.style.width=t.width+"px",this.#e.innerHTML="",this.#e.style.display="block",this.searchInputActive&&this.#n.focus(),this.#x(),this.#l=!0}repositionDropdown(){const t=this.#i.getBoundingClientRect(),s=this.#i.getBoundingClientRect().top+window.scrollY,i=t.y-this.#d.y;console.log(s),this.#o.style.top=i+"px"}#a(){this.#l&&(this.#e.innerHTML="",this.#e.style.display="none",this.searchInputActive&&(this.#n.style.display="none"),this.#s.classList.add(`round${this.bodyRound}`),this.#l=!1)}async#C(){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.#g,...s].map(i=>[i.id,i])).values()),this.data}async#x(){this.#r({id:"loading",text:"cargando ..."}),this.records=10+this.#t.length,this.#m=!1;let t=await this.#C();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.#E.toLowerCase())&&!e.includes(s.id)&&this.#r(s)}),this.#e.hasChildNodes()||this.#r({id:"sin_resultados",text:"sin resultados ..."})}async#B(){const t=this.#t.map(l=>l.value);let e=this.filter===null?"":this.filter,s=this.data.map(l=>l.id);this.records=this.records+10+this.#t.length;let i=await this.#C();this.#e.lastChild.dataset.value==="loading"&&this.#e.removeChild(this.#e.lastChild);const n=this.#e.lastChild.dataset.value;i.forEach(l=>{l.text.toLowerCase().includes(e.toLowerCase())&&!t.includes(l.id)&&!s.includes(l.id)&&this.#r(l)}),this.#m=n===this.#e.lastChild.dataset.value}#A(t,e){this.#t.find(i=>i.value===e)||(this.isMultiple||(this.#t=[]),this.#t.push({text:t,value:e})),this.#c(e)}#c(t){this.onChange!==void 0&&this.onChange(t,this),this.isMultiple?this.#S():this.#k()}#k(){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.#p.value=this.#t.length>0?this.#t[0].value:null;const t=this.#h.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)}#S(){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)})}#H(t){this.#t=this.#t.filter(e=>this.#u(e.value)!==this.#u(t)),this.#c(t)}#j(t){const{scrollTop:e,scrollHeight:s,clientHeight:i}=this.#e;t.target.lastChild!==null&&(t.target.lastChild.dataset.value==="loading"||this.#m||e+(i+1)>=s&&(this.#r({id:"loading",text:"cargando ..."}),this.#B()))}#u(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.#y===void 0||e?this.#L():this.#c()}}h.selectyc=o,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
|