selectyc 0.0.18 → 0.0.19

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 CHANGED
@@ -48,21 +48,21 @@ class a {
48
48
  }
49
49
  class h {
50
50
  #t = [];
51
- #p;
52
- #g = [];
51
+ #u;
52
+ #m = [];
53
53
  #i;
54
- #w;
54
+ #g;
55
55
  #s;
56
56
  #e;
57
- #n;
57
+ #a;
58
58
  #h;
59
- #f;
60
- #r;
59
+ #p;
61
60
  #o;
62
- #y;
63
- #l = !1;
64
- #v = !1;
65
- #m = !1;
61
+ #w;
62
+ #S;
63
+ #n = !1;
64
+ #y = !1;
65
+ #f = !1;
66
66
  #E = "";
67
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>';
68
68
  constructor(t) {
@@ -83,7 +83,7 @@ class h {
83
83
  return this.clearButton = !0, this;
84
84
  }
85
85
  setSelectedOptions(t) {
86
- this.#t = t, this.#c(t);
86
+ this.#t = t, this.#d(t);
87
87
  }
88
88
  getSelectedOptions() {
89
89
  return this.#t;
@@ -126,22 +126,22 @@ class h {
126
126
  }
127
127
  cleanSelection() {
128
128
  const t = this.#t;
129
- this.#t = [], this.#c(t);
129
+ this.#t = [], this.#d(t);
130
130
  }
131
131
  #L() {
132
132
  this.#N(), this.#s.addEventListener("click", (t) => {
133
133
  if (t.target.classList.contains("remove-tag")) {
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();
134
+ this.#H(t.target.getAttribute("data-value")), this.onUnselect !== void 0 && this.onUnselect(t.target.getAttribute("data-value"), this), this.#n && this.#l(), this.#v();
135
135
  return;
136
136
  }
137
- this.#l ? this.#a() : this.#C();
137
+ this.#n ? this.#l() : this.#v();
138
138
  }), document.addEventListener("click", (t) => {
139
- !this.#i.contains(t.target) && !this.#e.contains(t.target) && !t.target.classList.contains("remove-tag") && this.#a();
139
+ !this.#i.contains(t.target) && !this.#e.contains(t.target) && !t.target.classList.contains("remove-tag") && this.#l();
140
140
  }), window.onresize = () => {
141
- this.#a();
141
+ this.#l();
142
142
  }, window.addEventListener("scroll", () => {
143
- this.#a();
144
- }), this.isMultiple && this.#S();
143
+ this.#l();
144
+ }), this.isMultiple && this.#x();
145
145
  }
146
146
  // Draw functions
147
147
  #N() {
@@ -151,23 +151,23 @@ class h {
151
151
  const e = document.createElement("div");
152
152
  e.className = "custom-multiselect";
153
153
  let s = document.createElement("div");
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);
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.#M()), t.appendChild(e);
155
155
  const i = document.getElementById(this.id), n = document.createElement("input");
156
156
  n.name = i.name, n.setAttribute("data-id", i.id), this.rootClassName !== "" && (n.className = i.className), n.style.display = "none";
157
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);
158
+ t.appendChild(n), l.replaceChild(t, i), this.#u = n, this.#g = s, this.#i = e, this.#s = this.#i.querySelector(".selected-items"), !this.isMultiple && this.#t.length > 0 && (this.#u.value = this.#t[0].value);
159
159
  }
160
160
  #O(t) {
161
161
  const e = document.createElement("input");
162
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;
163
163
  const s = document.createElement("div");
164
- return s.innerHTML = this.#D, t.appendChild(this.#M()), t.appendChild(e), t.appendChild(s), this.#h = e, t;
164
+ return s.innerHTML = this.#D, t.appendChild(this.#I()), t.appendChild(e), t.appendChild(s), this.#h = e, t;
165
165
  }
166
- #M() {
166
+ #I() {
167
167
  const t = document.createElement("input");
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;
168
+ 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;
169
169
  }
170
- #I() {
170
+ #M() {
171
171
  const t = document.createElement("div");
172
172
  t.setAttribute("style", "position:fixed; z-index:999;");
173
173
  const e = document.createElement("div");
@@ -179,48 +179,46 @@ class h {
179
179
  i && clearTimeout(i), i = setTimeout(() => {
180
180
  this.#_(n);
181
181
  }, 70);
182
- }), e.appendChild(s), this.#e = s, this.#r = e, t.appendChild(e), t;
182
+ }), e.appendChild(s), this.#e = s, this.#o = e, t.appendChild(e), t;
183
183
  }
184
184
  #R() {
185
185
  const t = document.createElement("input");
186
186
  return t.type = "text", t.id = "selectyc_search_input", t.className = "search-input", t.placeholder = "Buscar...", t.addEventListener("input", () => {
187
- this.filter = t.value, this.#e.innerHTML = "", this.filter = t.value, this.#x();
188
- }), this.#n = t, t;
187
+ this.filter = t.value, this.#e.innerHTML = "", this.filter = t.value, this.#b();
188
+ }), this.#a = t, t;
189
189
  }
190
- #d(t) {
190
+ #r(t) {
191
191
  const e = document.createElement("div");
192
192
  e.className = "select-option", e.setAttribute("data-value", t.id), e.textContent = t.text, this.#e.appendChild(e), e.addEventListener("click", () => {
193
- t.id !== "sin_resultados" && (this.#A(t.text, t.id), this.onSelect !== void 0 && this.onSelect(t.id, this), this.#a());
193
+ t.id !== "sin_resultados" && (this.#A(t.text, t.id), this.onSelect !== void 0 && this.onSelect(t.id, this), this.#l());
194
194
  });
195
195
  }
196
196
  // Functions
197
197
  #B() {
198
198
  const t = document.getElementById(this.id);
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) => {
199
+ this.name = t.name, this.#y = t.required, this.rootClassName = t.className, this.#w = t.getBoundingClientRect(), this.#S = document.documentElement.clientWidth, Array.from(t.options).forEach((e) => {
200
200
  if (e.outerHTML.includes("selected")) {
201
- const s = e.text, i = this.#u(e.value);
201
+ const s = e.text, i = this.#c(e.value);
202
202
  this.isMultiple ? this.#t.push({ value: i, text: s }) : this.#t[0] = { value: i, text: s };
203
203
  }
204
- this.#g.push({ id: this.#u(e.value), text: e.text });
204
+ this.#m.push({ id: this.#c(e.value), text: e.text });
205
205
  });
206
206
  }
207
- #C() {
208
- if (this.filter = null, this.#l)
207
+ #v() {
208
+ if (this.filter = null, this.#n)
209
209
  return;
210
210
  this.#s.classList.remove(`round${this.bodyRound}`), this.#s.classList.add(`round${this.bodyRound}t`);
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;
211
+ const t = this.#i.getBoundingClientRect();
212
+ this.#o.style.position = "fixed", this.#o.style.top = t.bottom + "px", this.#o.style.left = t.left + "px", this.#e.style.width = t.width + "px", this.#e.style.display = "block", this.searchInputActive && (this.#a.style.display = "block", this.#a.style.width = t.width + "px", this.#a.focus()), this.#b(), this.#n = !0;
215
213
  }
216
214
  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";
215
+ const t = this.#i.getBoundingClientRect(), s = this.#i.getBoundingClientRect().top + window.scrollY, i = t.y - this.#w.y;
216
+ console.log(s), this.#o.style.top = i + "px";
219
217
  }
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);
218
+ #l() {
219
+ this.#n && (this.#e.innerHTML = "", this.#e.style.display = "none", this.searchInputActive && (this.#a.style.display = "none"), this.#s.classList.add(`round${this.bodyRound}`), this.#n = !1);
222
220
  }
223
- async #b() {
221
+ async #C() {
224
222
  if (this.RS === void 0)
225
223
  return this.data;
226
224
  let t = { records: this.records, filter: this.filter };
@@ -229,42 +227,42 @@ class h {
229
227
  t = { ...t, ...i };
230
228
  } else this.bodyData !== null && (t = { ...t, ...this.bodyData });
231
229
  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;
230
+ return this.data = Array.from(new Map([...this.#m, ...s].map((i) => [i.id, i])).values()), this.data;
233
231
  }
234
- async #x() {
235
- this.#d({ id: "loading", text: "cargando ..." }), this.records = 10 + this.#t.length, this.#m = !1;
236
- let t = await this.#b();
232
+ async #b() {
233
+ this.#r({ id: "loading", text: "cargando ..." }), this.records = 10 + this.#t.length, this.#f = !1;
234
+ let t = await this.#C();
237
235
  const e = this.#t.map((s) => s.value);
238
236
  this.#e.lastChild.dataset.value === "loading" && this.#e.removeChild(this.#e.lastChild), t.forEach((s) => {
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 ..." });
237
+ s.text.toLowerCase().includes(this.#E.toLowerCase()) && !e.includes(s.id) && this.#r(s);
238
+ }), this.#e.hasChildNodes() || this.#r({ id: "sin_resultados", text: "sin resultados ..." });
241
239
  }
242
240
  async #T() {
243
241
  const t = this.#t.map((l) => l.value);
244
242
  let e = this.filter === null ? "" : this.filter, s = this.data.map((l) => l.id);
245
243
  this.records = this.records + 10 + this.#t.length;
246
- let i = await this.#b();
244
+ let i = await this.#C();
247
245
  this.#e.lastChild.dataset.value === "loading" && this.#e.removeChild(this.#e.lastChild);
248
246
  const n = this.#e.lastChild.dataset.value;
249
247
  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;
248
+ l.text.toLowerCase().includes(e.toLowerCase()) && !t.includes(l.id) && !s.includes(l.id) && this.#r(l);
249
+ }), this.#f = n === this.#e.lastChild.dataset.value;
252
250
  }
253
251
  #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);
252
+ this.#t.find((i) => i.value === e) || (this.isMultiple || (this.#t = []), this.#t.push({ text: t, value: e })), this.#d(e);
255
253
  }
256
- #c(t) {
257
- this.onChange !== void 0 && this.onChange(t, this), this.isMultiple ? this.#S() : this.#k();
254
+ #d(t) {
255
+ this.onChange !== void 0 && this.onChange(t, this), this.isMultiple ? this.#x() : this.#k();
258
256
  }
259
257
  #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;
258
+ this.#h.value = null, this.#p.value = null, this.#h.value = this.#t.length > 0 ? this.#t[0].text : null, this.#p.value = this.#t.length > 0 ? this.#t[0].text : null, this.#h.placeholder = this.singleLabel, this.#u.value = this.#t.length > 0 ? this.#t[0].value : null;
261
259
  const t = this.#h.parentNode, e = t.firstChild;
262
260
  if (e.className === "remove-tag" && e.remove(), !this.clearButton || this.#t.length <= 0)
263
261
  return;
264
262
  const s = document.createElement("span");
265
263
  s.dataset.value = this.#t[0].value, s.innerHTML = "x", s.className = "remove-tag", t.insertBefore(s, t.firstChild);
266
264
  }
267
- #S() {
265
+ #x() {
268
266
  if (this.#s.innerHTML = "", this.#t.length <= 0) {
269
267
  this.#s.appendChild(document.createElement("div"));
270
268
  return;
@@ -275,18 +273,18 @@ class h {
275
273
  });
276
274
  }
277
275
  #H(t) {
278
- this.#t = this.#t.filter((e) => this.#u(e.value) !== this.#u(t)), this.#c(t);
276
+ this.#t = this.#t.filter((e) => this.#c(e.value) !== this.#c(t)), this.#d(t);
279
277
  }
280
278
  #_(t) {
281
279
  const { scrollTop: e, scrollHeight: s, clientHeight: i } = this.#e;
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()));
280
+ t.target.lastChild !== null && (t.target.lastChild.dataset.value === "loading" || this.#f || e + (i + 1) >= s && (this.#r({ id: "loading", text: "cargando ..." }), this.#T()));
283
281
  }
284
- #u(t) {
282
+ #c(t) {
285
283
  return !isNaN(t) && !isNaN(parseFloat(t)) ? parseInt(t) : t;
286
284
  }
287
285
  async render() {
288
286
  const t = document.getElementById(this.id), e = t === null ? !1 : t.outerHTML.includes("<select");
289
- this.#w === void 0 || e ? this.#L() : this.#c();
287
+ this.#g === void 0 || e ? this.#L() : this.#d();
290
288
  }
291
289
  }
292
290
  export {
@@ -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=[];#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"})});
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=[];#u;#m=[];#i;#g;#s;#e;#a;#h;#p;#o;#y;#x;#n=!1;#w=!1;#f=!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.#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)}#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.#n&&this.#l(),this.#v();return}this.#n?this.#l():this.#v()}),document.addEventListener("click",t=>{!this.#i.contains(t.target)&&!this.#e.contains(t.target)&&!t.target.classList.contains("remove-tag")&&this.#l()}),window.onresize=()=>{this.#l()},window.addEventListener("scroll",()=>{this.#l()}),this.isMultiple&&this.#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.#u=n,this.#g=s,this.#i=e,this.#s=this.#i.querySelector(".selected-items"),!this.isMultiple&&this.#t.length>0&&(this.#u.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.#w,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}#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.#C()}),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),e.addEventListener("click",()=>{t.id!=="sin_resultados"&&(this.#A(t.text,t.id),this.onSelect!==void 0&&this.onSelect(t.id,this),this.#l())})}#T(){const t=document.getElementById(this.id);this.name=t.name,this.#w=t.required,this.rootClassName=t.className,this.#y=t.getBoundingClientRect(),this.#x=document.documentElement.clientWidth,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})})}#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.#i.getBoundingClientRect();this.#o.style.position="fixed",this.#o.style.top=t.bottom+"px",this.#o.style.left=t.left+"px",this.#e.style.width=t.width+"px",this.#e.style.display="block",this.searchInputActive&&(this.#a.style.display="block",this.#a.style.width=t.width+"px",this.#a.focus()),this.#C(),this.#n=!0}repositionDropdown(){const t=this.#i.getBoundingClientRect(),s=this.#i.getBoundingClientRect().top+window.scrollY,i=t.y-this.#y.y;console.log(s),this.#o.style.top=i+"px"}#l(){this.#n&&(this.#e.innerHTML="",this.#e.style.display="none",this.searchInputActive&&(this.#a.style.display="none"),this.#s.classList.add(`round${this.bodyRound}`),this.#n=!1)}async#b(){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#C(){this.#d({id:"loading",text:"cargando ..."}),this.records=10+this.#t.length,this.#f=!1;let t=await this.#b();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.#d(s)}),this.#e.hasChildNodes()||this.#d({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.#b();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.#d(l)}),this.#f=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.#r(e)}#r(t){this.onChange!==void 0&&this.onChange(t,this),this.isMultiple?this.#S():this.#k()}#k(){this.#h.value=null,this.#p.value=null,this.#h.value=this.#t.length>0?this.#t[0].text:null,this.#p.value=this.#t.length>0?this.#t[0].text:null,this.#h.placeholder=this.singleLabel,this.#u.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.#c(e.value)!==this.#c(t)),this.#r(t)}#j(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.#d({id:"loading",text:"cargando ..."}),this.#B()))}#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.#L():this.#r()}}h.selectyc=o,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "selectyc",
3
3
  "description": "select multiple and simple",
4
- "version": "0.0.18",
4
+ "version": "0.0.19",
5
5
  "main": "./dist/selectyc.umd.js",
6
6
  "module": "./dist/selectyc.js",
7
7
  "type": "module",