selectyc 0.0.12 → 0.0.14
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 +19 -19
- package/dist/selectyc.umd.cjs +1 -1
- package/package.json +1 -1
package/dist/selectyc.js
CHANGED
|
@@ -49,18 +49,18 @@ class l {
|
|
|
49
49
|
class h {
|
|
50
50
|
#t = [];
|
|
51
51
|
#c;
|
|
52
|
-
#
|
|
52
|
+
#f = [];
|
|
53
53
|
#d;
|
|
54
|
-
#
|
|
54
|
+
#m;
|
|
55
55
|
#s;
|
|
56
56
|
#e;
|
|
57
57
|
#i;
|
|
58
58
|
#a;
|
|
59
59
|
#u;
|
|
60
60
|
#n = !1;
|
|
61
|
+
#g = !1;
|
|
61
62
|
#p = !1;
|
|
62
|
-
#
|
|
63
|
-
#b = "";
|
|
63
|
+
#C = "";
|
|
64
64
|
#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>';
|
|
65
65
|
constructor(t) {
|
|
66
66
|
if (window.selects === void 0 && (window.selects = []), window.selects[t] !== void 0)
|
|
@@ -136,7 +136,7 @@ class h {
|
|
|
136
136
|
!this.#d.contains(t.target) && !this.#e.contains(t.target) && !t.target.classList.contains("remove-tag") && this.#h();
|
|
137
137
|
}), window.onresize = () => {
|
|
138
138
|
this.#h();
|
|
139
|
-
}, this.isMultiple && this.#
|
|
139
|
+
}, this.isMultiple && this.#b();
|
|
140
140
|
}
|
|
141
141
|
// Draw functions
|
|
142
142
|
#E() {
|
|
@@ -148,19 +148,19 @@ class h {
|
|
|
148
148
|
let s = document.createElement("div");
|
|
149
149
|
s.className = "selected-items round" + this.bodyRound, s.tabIndex = 0, s.classList.add(this.boxOverflow === "horizontal" ? "horizontal-overflow" : "vertical-overflow"), this.isMultiple || (s = this.#D(s)), e.appendChild(s), e.appendChild(this.#N()), t.appendChild(e);
|
|
150
150
|
const i = document.getElementById(this.id), a = document.createElement("input");
|
|
151
|
-
a.name = i.name, a.id
|
|
151
|
+
a.name = i.name, a.setAttribute("data-id", i.id), this.rootClassName !== "" && (a.className = i.className), a.style.display = "none";
|
|
152
152
|
let n = i.parentNode;
|
|
153
|
-
t.appendChild(a), n.replaceChild(t, i), this.#c = a, this.#
|
|
153
|
+
t.appendChild(a), n.replaceChild(t, i), this.#c = a, 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);
|
|
154
154
|
}
|
|
155
155
|
#D(t) {
|
|
156
156
|
const e = document.createElement("input");
|
|
157
157
|
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;
|
|
158
158
|
const s = document.createElement("div");
|
|
159
|
-
return s.innerHTML = this.#S,
|
|
159
|
+
return s.innerHTML = this.#S, t.appendChild(this.#L()), t.appendChild(e), t.appendChild(s), this.#a = e, t;
|
|
160
160
|
}
|
|
161
161
|
#L() {
|
|
162
162
|
const t = document.createElement("input");
|
|
163
|
-
return t.type = "text", t.required = this.#
|
|
163
|
+
return t.type = "text", t.required = this.#g, 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;
|
|
164
164
|
}
|
|
165
165
|
#N() {
|
|
166
166
|
const t = document.createElement("div");
|
|
@@ -189,12 +189,12 @@ class h {
|
|
|
189
189
|
// Functions
|
|
190
190
|
#I() {
|
|
191
191
|
const t = document.getElementById(this.id);
|
|
192
|
-
this.name = t.name, this.#
|
|
192
|
+
this.name = t.name, this.#g = t.required, this.rootClassName = t.className, Array.from(t.options).forEach((e) => {
|
|
193
193
|
if (e.outerHTML.includes("selected")) {
|
|
194
194
|
const s = e.text, i = this.#o(e.value);
|
|
195
195
|
this.isMultiple ? this.#t.push({ value: i, text: s }) : this.#t[0] = { value: i, text: s };
|
|
196
196
|
}
|
|
197
|
-
this.#
|
|
197
|
+
this.#f.push({ id: this.#o(e.value), text: e.text });
|
|
198
198
|
});
|
|
199
199
|
}
|
|
200
200
|
#v() {
|
|
@@ -221,14 +221,14 @@ class h {
|
|
|
221
221
|
t = { ...t, ...i };
|
|
222
222
|
} else this.bodyData !== null && (t = { ...t, ...this.bodyData });
|
|
223
223
|
const e = await l.make(this.RS).addData(t).setMethod("POST").go(), s = Array.isArray(e) ? e : e.data;
|
|
224
|
-
return this.data = Array.from(new Map([...this.#
|
|
224
|
+
return this.data = Array.from(new Map([...this.#f, ...s].map((i) => [i.id, i])).values()), this.data;
|
|
225
225
|
}
|
|
226
226
|
async #y() {
|
|
227
|
-
this.#l({ id: "loading", text: "cargando ..." }), this.records = 10 + this.#t.length, this.#
|
|
227
|
+
this.#l({ id: "loading", text: "cargando ..." }), this.records = 10 + this.#t.length, this.#p = !1;
|
|
228
228
|
let t = await this.#w();
|
|
229
229
|
const e = this.#t.map((s) => s.value);
|
|
230
230
|
this.#e.lastChild.dataset.value === "loading" && this.#e.removeChild(this.#e.lastChild), t.forEach((s) => {
|
|
231
|
-
s.text.toLowerCase().includes(this.#
|
|
231
|
+
s.text.toLowerCase().includes(this.#C.toLowerCase()) && !e.includes(s.id) && this.#l(s);
|
|
232
232
|
}), this.#e.hasChildNodes() || this.#l({ id: "sin_resultados", text: "sin resultados ..." });
|
|
233
233
|
}
|
|
234
234
|
async #M() {
|
|
@@ -240,13 +240,13 @@ class h {
|
|
|
240
240
|
const a = this.#e.lastChild.dataset.value;
|
|
241
241
|
i.forEach((n) => {
|
|
242
242
|
n.text.toLowerCase().includes(e.toLowerCase()) && !t.includes(n.id) && !s.includes(n.id) && this.#l(n);
|
|
243
|
-
}), this.#
|
|
243
|
+
}), this.#p = a === this.#e.lastChild.dataset.value;
|
|
244
244
|
}
|
|
245
245
|
#T(t, e) {
|
|
246
246
|
this.#t.find((i) => i.value === e) || (this.isMultiple || (this.#t = []), this.#t.push({ text: t, value: e })), this.#r(e);
|
|
247
247
|
}
|
|
248
248
|
#r(t) {
|
|
249
|
-
this.onChange !== void 0 && this.onChange(t, this), this.isMultiple ? this.#
|
|
249
|
+
this.onChange !== void 0 && this.onChange(t, this), this.isMultiple ? this.#b() : this.#R();
|
|
250
250
|
}
|
|
251
251
|
#R() {
|
|
252
252
|
this.#a.value = null, this.#u.value = null, this.#a.value = this.#t.length > 0 ? this.#t[0].text : null, this.#u.value = this.#t.length > 0 ? this.#t[0].text : null, this.#a.placeholder = this.singleLabel, this.#c.value = this.#t.length > 0 ? this.#t[0].value : null;
|
|
@@ -256,7 +256,7 @@ class h {
|
|
|
256
256
|
const s = document.createElement("span");
|
|
257
257
|
s.dataset.value = this.#t[0].value, s.innerHTML = "x", s.className = "remove-tag", t.insertBefore(s, t.firstChild);
|
|
258
258
|
}
|
|
259
|
-
#
|
|
259
|
+
#b() {
|
|
260
260
|
if (this.#s.innerHTML = "", this.#t.length <= 0) {
|
|
261
261
|
this.#s.appendChild(document.createElement("div"));
|
|
262
262
|
return;
|
|
@@ -271,14 +271,14 @@ class h {
|
|
|
271
271
|
}
|
|
272
272
|
#B(t) {
|
|
273
273
|
const { scrollTop: e, scrollHeight: s, clientHeight: i } = this.#e;
|
|
274
|
-
t.target.lastChild !== null && (t.target.lastChild.dataset.value === "loading" || this.#
|
|
274
|
+
t.target.lastChild !== null && (t.target.lastChild.dataset.value === "loading" || this.#p || e + (i + 1) >= s && (this.#l({ id: "loading", text: "cargando ..." }), this.#M()));
|
|
275
275
|
}
|
|
276
276
|
#o(t) {
|
|
277
277
|
return !isNaN(t) && !isNaN(parseFloat(t)) ? parseInt(t) : t;
|
|
278
278
|
}
|
|
279
279
|
async render() {
|
|
280
280
|
const t = document.getElementById(this.id), e = t === null ? !1 : t.outerHTML.includes("<select");
|
|
281
|
-
this.#
|
|
281
|
+
this.#m === void 0 || e ? this.#x() : this.#r();
|
|
282
282
|
}
|
|
283
283
|
}
|
|
284
284
|
export {
|
package/dist/selectyc.umd.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(h,l){typeof exports=="object"&&typeof module<"u"?l(exports):typeof define=="function"&&define.amd?define(["exports"],l):(h=typeof globalThis<"u"?globalThis:h||self,l(h.selectyc={}))})(this,function(h){"use strict";class l{constructor(t){this.route=t}static make(t){return new l(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 d{#t=[];#c;#
|
|
1
|
+
(function(h,l){typeof exports=="object"&&typeof module<"u"?l(exports):typeof define=="function"&&define.amd?define(["exports"],l):(h=typeof globalThis<"u"?globalThis:h||self,l(h.selectyc={}))})(this,function(h){"use strict";class l{constructor(t){this.route=t}static make(t){return new l(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 d{#t=[];#c;#f=[];#r;#m;#s;#e;#i;#a;#u;#n=!1;#g=!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 d(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.#d(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.#d(t)}#x(){this.#E(),this.#s.addEventListener("click",t=>{if(t.target.classList.contains("remove-tag")){this.#A(t.target.getAttribute("data-value")),this.onUnselect!==void 0&&this.onUnselect(t.target.getAttribute("data-value"),this),this.#n&&this.#h(),this.#y();return}this.#n?this.#h():this.#y()}),document.addEventListener("click",t=>{!this.#r.contains(t.target)&&!this.#e.contains(t.target)&&!t.target.classList.contains("remove-tag")&&this.#h()}),window.onresize=()=>{this.#h()},this.isMultiple&&this.#b()}#E(){this.#I();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.#D(s)),e.appendChild(s),e.appendChild(this.#N()),t.appendChild(e);const i=document.getElementById(this.id),a=document.createElement("input");a.name=i.name,a.setAttribute("data-id",i.id),this.rootClassName!==""&&(a.className=i.className),a.style.display="none";let n=i.parentNode;t.appendChild(a),n.replaceChild(t,i),this.#c=a,this.#m=s,this.#r=e,this.#s=this.#r.querySelector(".selected-items"),!this.isMultiple&&this.#t.length>0&&(this.#c.value=this.#t[0].value)}#D(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.#L()),t.appendChild(e),t.appendChild(s),this.#a=e,t}#L(){const t=document.createElement("input");return t.type="text",t.required=this.#g,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}#N(){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.#O());let s;return e.addEventListener("scroll",i=>{s&&clearTimeout(s),s=setTimeout(()=>{this.#B(i)},70)}),t.appendChild(e),this.#e=e,t}#O(){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()}),this.#i=t,t}#l(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.#T(t.text,t.id),this.onSelect!==void 0&&this.onSelect(t.id,this),this.#h())})}#I(){const t=document.getElementById(this.id);this.name=t.name,this.#g=t.required,this.rootClassName=t.className,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})})}#y(){if(this.#n)return;this.#s.classList.remove(`round${this.bodyRound}`),this.#s.classList.add(`round${this.bodyRound}t`);const t=this.#r.getBoundingClientRect();if(this.searchInputActive){this.#i.style.display="block",this.#i.style.width=t.width+"px";const e=this.#i.offsetHeight;this.#e.style.top=e+"px"}this.#e.style.width=t.width+"px",this.#e.innerHTML="",this.#e.style.display="block",this.searchInputActive&&this.#i.focus(),this.#w(),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#v(){if(this.RS===void 0)return this.data;let t={records:this.records,filter:this.filter};if(typeof this.bodyData=="function"){const i=this.bodyData();t={...t,...i}}else this.bodyData!==null&&(t={...t,...this.bodyData});const e=await l.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.#l({id:"loading",text:"cargando ..."}),this.records=10+this.#t.length,this.#p=!1;let t=await this.#v();const e=this.#t.map(s=>s.value);this.#e.lastChild.dataset.value==="loading"&&this.#e.removeChild(this.#e.lastChild),t.forEach(s=>{s.text.toLowerCase().includes(this.#C.toLowerCase())&&!e.includes(s.id)&&this.#l(s)}),this.#e.hasChildNodes()||this.#l({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.#v();this.#e.lastChild.dataset.value==="loading"&&this.#e.removeChild(this.#e.lastChild);const a=this.#e.lastChild.dataset.value;i.forEach(n=>{n.text.toLowerCase().includes(e.toLowerCase())&&!t.includes(n.id)&&!s.includes(n.id)&&this.#l(n)}),this.#p=a===this.#e.lastChild.dataset.value}#T(t,e){this.#t.find(i=>i.value===e)||(this.isMultiple||(this.#t=[]),this.#t.push({text:t,value:e})),this.#d(e)}#d(t){this.onChange!==void 0&&this.onChange(t,this),this.isMultiple?this.#b():this.#R()}#R(){this.#a.value=null,this.#u.value=null,this.#a.value=this.#t.length>0?this.#t[0].text:null,this.#u.value=this.#t.length>0?this.#t[0].text:null,this.#a.placeholder=this.singleLabel,this.#c.value=this.#t.length>0?this.#t[0].value:null;const t=this.#a.parentNode,e=t.firstChild;if(e.className==="remove-tag"&&e.remove(),!this.clearButton||this.#t.length<=0)return;const s=document.createElement("span");s.dataset.value=this.#t[0].value,s.innerHTML="x",s.className="remove-tag",t.insertBefore(s,t.firstChild)}#b(){if(this.#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)})}#A(t){this.#t=this.#t.filter(e=>this.#o(e.value)!==this.#o(t)),this.#d(t)}#B(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.#l({id:"loading",text:"cargando ..."}),this.#M()))}#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.#x():this.#d()}}h.selectyc=d,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
|