selectyc 0.0.1

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/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # selectyc
2
+ Select simple and multiple with search box
@@ -0,0 +1 @@
1
+ .custom-multiselect{position:relative;width:100%}.selected-items{display:flex;flex-wrap:nowrap;gap:5px;padding:8px;border:1px solid;cursor:default;height:42px;align-items:center;white-space:nowrap;overflow-x:auto;overflow-y:hidden;@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;}.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}.selected-items::-webkit-scrollbar-thumb{border-radius:1rem;@apply bg-cyan-400 dark:bg-cyan-700;}.selected-items::-webkit-scrollbar-thumb:hover{@apply bg-cyan-500 dark:bg-cyan-600;}.custom-single-select{width:97%;padding-left:.2rem;border:0px solid;background:transparent;cursor:default}.custom-single-select:focus{border:0px solid transparent;outline:none;box-shadow:none}.selected-tag{background-color:#007bff;color:#fff;padding:4px 8px;border-radius:12px;display:inline-flex;align-items:center;gap:5px;font-size:14px;white-space:nowrap;flex:0 0 auto}.remove-tag{cursor:pointer;font-weight:700}.global-dropdown{position:absolute;background-color:#374151;max-height:200px;overflow-y:auto;display:none;box-shadow:0 2px 8px #0003;border-bottom-left-radius:.6rem;border-bottom-right-radius:.6rem;@apply bg-gray-50 dark:bg-gray-700;}.global-dropdown::-webkit-scrollbar{width:10px;border-radius:.6rem;@apply bg-gray-200 dark:bg-gray-400;}.global-dropdown::-webkit-scrollbar-thumb{border-radius:.6rem;@apply bg-gray-400 dark:bg-gray-600;}.search-input{position:absolute;width:100%;padding:3px 10px;border:1px solid;display:none;outline:none;color:#000;font-size:.9rem;@apply dark:border-gray-300 border-blue-500;}.search-input:focus{@apply dark:border-gray-300 border-blue-500;}.search-input::placeholder{color:#4b5563}.select-option{padding:3px 10px;cursor:pointer;font-size:.9rem}.select-option:hover{background-color:#3777de;color:#fff}
@@ -0,0 +1,246 @@
1
+ import './selectyc.css';
2
+ class a {
3
+ constructor(t) {
4
+ this.route = t;
5
+ }
6
+ static make(t) {
7
+ return new a(t);
8
+ }
9
+ setMethod(t) {
10
+ return this.method = t, this;
11
+ }
12
+ getMethod() {
13
+ return this.method === void 0 ? "POST" : this.method;
14
+ }
15
+ setData(t) {
16
+ return this.data = t, this;
17
+ }
18
+ addData(t) {
19
+ if (this.data === void 0)
20
+ return this.setData(t);
21
+ for (const e in t)
22
+ this.data[e] = t[e];
23
+ return this;
24
+ }
25
+ setFun(t) {
26
+ return this.fun = t, this;
27
+ }
28
+ async go() {
29
+ try {
30
+ const t = {
31
+ method: this.getMethod(),
32
+ headers: {
33
+ "X-CSRF-TOKEN": window.CSRF_TOKEN,
34
+ Accept: "application/json"
35
+ }
36
+ };
37
+ 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"));
38
+ const e = await fetch(this.route, t);
39
+ if (!e.ok) {
40
+ const s = await e.json();
41
+ throw new Error(s.message);
42
+ }
43
+ return this.fun === void 0 ? await e.json() : await this.fun(e);
44
+ } catch (t) {
45
+ window.toastNotification.setType(!1).show(t.message);
46
+ }
47
+ }
48
+ }
49
+ class h {
50
+ #t = [];
51
+ #d;
52
+ #c = [];
53
+ #a;
54
+ #v;
55
+ #s;
56
+ #e;
57
+ #h;
58
+ #l;
59
+ #i = !1;
60
+ #u = !1;
61
+ #y = '<svg class="w-5 h-5 text-gray-900 dark:text-gray-400" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="none" viewBox="0 0 24 24"><path stroke="currentColor" stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="m19 9-7 7-7-7"/></svg>';
62
+ constructor(t) {
63
+ if (window.selects === void 0 && (window.selects = []), window.selects[t] !== void 0)
64
+ return window.selects[t];
65
+ this.id = t, this.name, this.data = [], this.isMultiple = !1, this.singleLabel = " ", this.page = 1, this.filter = null, this.bodyRound = "", this.width = "100%", this.searchInputActive = !0, window.selects[t] = this;
66
+ }
67
+ static set(t) {
68
+ return new h(t);
69
+ }
70
+ setData(t) {
71
+ return this.data = t, this;
72
+ }
73
+ setMultiple() {
74
+ return this.isMultiple = !0, this;
75
+ }
76
+ getSelectedOptions() {
77
+ return this.#t;
78
+ }
79
+ getSelectedOption() {
80
+ return this.#t[0];
81
+ }
82
+ getOptions() {
83
+ return this.data;
84
+ }
85
+ setSingleLabel(t) {
86
+ return this.singleLabel = t, this;
87
+ }
88
+ setBodyRound(t) {
89
+ return this.bodyRound = `-${t}`, this;
90
+ }
91
+ setRS(t) {
92
+ return this.RS = t, this;
93
+ }
94
+ desactiveSearchInput() {
95
+ return this.searchInputActive = !1, this;
96
+ }
97
+ addOption(t) {
98
+ this.data.push(t);
99
+ }
100
+ setWidth(t) {
101
+ return this.width = t, this;
102
+ }
103
+ setOnSelect(t) {
104
+ return this.onSelect = t, this;
105
+ }
106
+ setOnUnselect(t) {
107
+ return this.onUnselect = t, this;
108
+ }
109
+ setOnChange(t) {
110
+ return this.onChange = t, this;
111
+ }
112
+ #S() {
113
+ this.#b(), this.#s.addEventListener("click", (t) => {
114
+ if (t.target.classList.contains("remove-tag")) {
115
+ this.#I(t.target.getAttribute("data-value")), this.onUnselect !== void 0 && this.onUnselect(t.target.getAttribute("data-value")), this.#i && this.#n(), this.#p();
116
+ return;
117
+ }
118
+ this.#i ? this.#n() : this.#p();
119
+ }), document.addEventListener("click", (t) => {
120
+ !this.#a.contains(t.target) && !this.#e.contains(t.target) && !t.target.classList.contains("remove-tag") && this.#n();
121
+ }), window.onresize = () => {
122
+ this.#n();
123
+ }, this.isMultiple && this.#w();
124
+ }
125
+ // Draw functions
126
+ #b() {
127
+ this.#L();
128
+ const t = document.createElement("div");
129
+ t.className = "main-div-selectyc", t.style.width = this.width;
130
+ const e = document.createElement("div");
131
+ e.className = "custom-multiselect";
132
+ let s = document.createElement("div");
133
+ s.className = "selected-items round" + this.bodyRound, s.tabIndex = 0, this.isMultiple || (s = this.#C(s)), e.appendChild(s), this.searchInputActive && e.appendChild(this.#E()), e.appendChild(this.#x()), t.appendChild(e);
134
+ const i = document.getElementById(this.id), n = document.createElement("input");
135
+ n.name = i.name, n.style.display = "none";
136
+ let r = i.parentNode;
137
+ t.appendChild(n), r.replaceChild(t, i), this.#d = n, this.#v = s, this.#a = e, this.#s = this.#a.querySelector(".selected-items"), !this.isMultiple && this.#t.length > 0 && (this.#d.value = this.#t[0].value);
138
+ }
139
+ #C(t) {
140
+ const e = document.createElement("input");
141
+ e.className = "custom-single-select", e.innerHTML = this.#t.length === 0 ? this.singleLabel : this.#t[0].text, e.required = this.#u, e.readOnly = !0;
142
+ const s = document.createElement("div");
143
+ return s.innerHTML = this.#y, t.appendChild(e), t.appendChild(s), this.#l = e, t;
144
+ }
145
+ #x() {
146
+ const t = document.createElement("div");
147
+ t.style.position = "fixed";
148
+ const e = document.createElement("div");
149
+ return e.className = "global-dropdown", e.addEventListener("scroll", () => this.#N()), t.appendChild(e), this.#e = e, t;
150
+ }
151
+ #E() {
152
+ const t = document.createElement("input");
153
+ return t.type = "text", t.id = "selectyc_search_input", t.className = "search-input", t.placeholder = "Buscar...", t.addEventListener("input", () => {
154
+ this.filter = t.value, this.#e.innerHTML = "", this.#m(t.value);
155
+ }), t.focus(), this.#h = t, t;
156
+ }
157
+ #o(t) {
158
+ const e = document.createElement("div");
159
+ e.className = "select-option", e.setAttribute("data-value", t.id), e.textContent = t.text, this.#e.appendChild(e), e.addEventListener("click", () => {
160
+ t.id !== "sin_resultados" && (this.#O(t.text, t.id), this.onSelect !== void 0 && this.onSelect(t.id), this.#n());
161
+ });
162
+ }
163
+ // Functions
164
+ #L() {
165
+ const t = document.getElementById(this.id);
166
+ this.name = t.name, this.#u = t.required, Array.from(t.options).forEach((e) => {
167
+ if (e.selected) {
168
+ const s = e.text, i = this.#r(e.value);
169
+ this.isMultiple ? this.#t.push({ value: i, text: s }) : this.#t[0] = { value: i, text: s };
170
+ }
171
+ this.#c.push({ id: this.#r(e.value), text: e.text });
172
+ });
173
+ }
174
+ #p() {
175
+ if (this.#i)
176
+ return;
177
+ this.#s.classList.remove(`round${this.bodyRound}`), this.#s.classList.add(`round${this.bodyRound}t`);
178
+ const t = this.#a.getBoundingClientRect();
179
+ if (this.searchInputActive) {
180
+ this.#h.style.display = "block";
181
+ const e = this.#h.offsetHeight;
182
+ this.#e.style.top = e + "px";
183
+ }
184
+ this.#e.style.width = t.width + "px", this.#e.innerHTML = "", this.#e.style.display = "block", this.#m(), this.#i = !0;
185
+ }
186
+ #n() {
187
+ this.#i && (this.#e.innerHTML = "", this.#e.style.display = "none", this.searchInputActive && (this.#h.style.display = "none"), this.#s.classList.add(`round${this.bodyRound}`), this.#i = !1);
188
+ }
189
+ async #f() {
190
+ if (this.RS === void 0)
191
+ return this.data;
192
+ const t = await a.make(this.RS).addData({ page: this.page, filter: this.filter }).setMethod("POST").go();
193
+ return this.data = Array.from(new Map([...this.#c, ...t.data].map((e) => [e.id, e])).values()), this.data;
194
+ }
195
+ async #m(t = "") {
196
+ this.page = 1;
197
+ let e = await this.#f();
198
+ const s = this.#t.map((i) => i.value);
199
+ e.forEach((i) => {
200
+ i.text.toLowerCase().includes(t.toLowerCase()) && !s.includes(i.id) && this.#o(i);
201
+ }), this.#e.hasChildNodes() || this.#o({ id: "sin_resultados", text: "sin resultados ..." });
202
+ }
203
+ async #M() {
204
+ this.page++;
205
+ let t = this.filter === null ? "" : this.filter, e = this.data.map((n) => n.id), s = await this.#f();
206
+ const i = this.#t.map((n) => n.value);
207
+ s.forEach((n) => {
208
+ n.text.toLowerCase().includes(t.toLowerCase()) && !i.includes(n.id) && !e.includes(n.id) && this.#o(n);
209
+ });
210
+ }
211
+ #O(t, e) {
212
+ this.#t.find((i) => i.value === e) || (this.isMultiple || (this.#t = []), this.#t.push({ text: t, value: e })), this.#g(e);
213
+ }
214
+ #g(t) {
215
+ this.onChange !== void 0 && this.onChange(t), this.isMultiple ? this.#w() : this.#D();
216
+ }
217
+ #D() {
218
+ this.#l.value = null, this.#l.value = this.#t[0].text, this.#d.value = this.#t[0].value;
219
+ }
220
+ #w() {
221
+ if (this.#s.innerHTML = "", this.#t.length <= 0) {
222
+ this.#s.appendChild(document.createElement("div"));
223
+ return;
224
+ }
225
+ this.#t.forEach(({ text: t, value: e }) => {
226
+ const s = document.createElement("div");
227
+ s.className = "selected-tag", s.innerHTML = `${t} <span class="remove-tag" data-value="${e}">x</span>`, this.#s.appendChild(s);
228
+ });
229
+ }
230
+ #I(t) {
231
+ this.#t = this.#t.filter((e) => this.#r(e.value) !== this.#r(t)), this.#g(t);
232
+ }
233
+ #N() {
234
+ const { scrollTop: t, scrollHeight: e, clientHeight: s } = this.#e;
235
+ t + s >= e && this.#M();
236
+ }
237
+ #r(t) {
238
+ return !isNaN(t) && !isNaN(parseFloat(t)) ? parseInt(t) : t;
239
+ }
240
+ async render() {
241
+ this.#S();
242
+ }
243
+ }
244
+ export {
245
+ h as selectyc
246
+ };
@@ -0,0 +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 d{#t=[];#r;#c=[];#a;#y;#s;#e;#h;#l;#i=!1;#u=!1;#v='<svg class="w-5 h-5 text-gray-900 dark:text-gray-400" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" 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.singleLabel=" ",this.page=1,this.filter=null,this.bodyRound="",this.width="100%",this.searchInputActive=!0,window.selects[t]=this}static set(t){return new d(t)}setData(t){return this.data=t,this}setMultiple(){return this.isMultiple=!0,this}getSelectedOptions(){return this.#t}getSelectedOption(){return this.#t[0]}getOptions(){return this.data}setSingleLabel(t){return this.singleLabel=t,this}setBodyRound(t){return this.bodyRound=`-${t}`,this}setRS(t){return this.RS=t,this}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}#S(){this.#b(),this.#s.addEventListener("click",t=>{if(t.target.classList.contains("remove-tag")){this.#I(t.target.getAttribute("data-value")),this.onUnselect!==void 0&&this.onUnselect(t.target.getAttribute("data-value")),this.#i&&this.#n(),this.#p();return}this.#i?this.#n():this.#p()}),document.addEventListener("click",t=>{!this.#a.contains(t.target)&&!this.#e.contains(t.target)&&!t.target.classList.contains("remove-tag")&&this.#n()}),window.onresize=()=>{this.#n()},this.isMultiple&&this.#w()}#b(){this.#L();const t=document.createElement("div");t.className="main-div-selectyc",t.style.width=this.width;const e=document.createElement("div");e.className="custom-multiselect";let s=document.createElement("div");s.className="selected-items round"+this.bodyRound,s.tabIndex=0,this.isMultiple||(s=this.#C(s)),e.appendChild(s),this.searchInputActive&&e.appendChild(this.#E()),e.appendChild(this.#x()),t.appendChild(e);const i=document.getElementById(this.id),n=document.createElement("input");n.name=i.name,n.style.display="none";let r=i.parentNode;t.appendChild(n),r.replaceChild(t,i),this.#r=n,this.#y=s,this.#a=e,this.#s=this.#a.querySelector(".selected-items"),!this.isMultiple&&this.#t.length>0&&(this.#r.value=this.#t[0].value)}#C(t){const e=document.createElement("input");e.className="custom-single-select",e.innerHTML=this.#t.length===0?this.singleLabel:this.#t[0].text,e.required=this.#u,e.readOnly=!0;const s=document.createElement("div");return s.innerHTML=this.#v,t.appendChild(e),t.appendChild(s),this.#l=e,t}#x(){const t=document.createElement("div");t.style.position="fixed";const e=document.createElement("div");return e.className="global-dropdown",e.addEventListener("scroll",()=>this.#N()),t.appendChild(e),this.#e=e,t}#E(){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.#m(t.value)}),t.focus(),this.#h=t,t}#o(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.#O(t.text,t.id),this.onSelect!==void 0&&this.onSelect(t.id),this.#n())})}#L(){const t=document.getElementById(this.id);this.name=t.name,this.#u=t.required,Array.from(t.options).forEach(e=>{if(e.selected){const s=e.text,i=this.#d(e.value);this.isMultiple?this.#t.push({value:i,text:s}):this.#t[0]={value:i,text:s}}this.#c.push({id:this.#d(e.value),text:e.text})})}#p(){if(this.#i)return;this.#s.classList.remove(`round${this.bodyRound}`),this.#s.classList.add(`round${this.bodyRound}t`);const t=this.#a.getBoundingClientRect();if(this.searchInputActive){this.#h.style.display="block";const e=this.#h.offsetHeight;this.#e.style.top=e+"px"}this.#e.style.width=t.width+"px",this.#e.innerHTML="",this.#e.style.display="block",this.#m(),this.#i=!0}#n(){this.#i&&(this.#e.innerHTML="",this.#e.style.display="none",this.searchInputActive&&(this.#h.style.display="none"),this.#s.classList.add(`round${this.bodyRound}`),this.#i=!1)}async#f(){if(this.RS===void 0)return this.data;const t=await a.make(this.RS).addData({page:this.page,filter:this.filter}).setMethod("POST").go();return this.data=Array.from(new Map([...this.#c,...t.data].map(e=>[e.id,e])).values()),this.data}async#m(t=""){this.page=1;let e=await this.#f();const s=this.#t.map(i=>i.value);e.forEach(i=>{i.text.toLowerCase().includes(t.toLowerCase())&&!s.includes(i.id)&&this.#o(i)}),this.#e.hasChildNodes()||this.#o({id:"sin_resultados",text:"sin resultados ..."})}async#M(){this.page++;let t=this.filter===null?"":this.filter,e=this.data.map(n=>n.id),s=await this.#f();const i=this.#t.map(n=>n.value);s.forEach(n=>{n.text.toLowerCase().includes(t.toLowerCase())&&!i.includes(n.id)&&!e.includes(n.id)&&this.#o(n)})}#O(t,e){this.#t.find(i=>i.value===e)||(this.isMultiple||(this.#t=[]),this.#t.push({text:t,value:e})),this.#g(e)}#g(t){this.onChange!==void 0&&this.onChange(t),this.isMultiple?this.#w():this.#D()}#D(){this.#l.value=null,this.#l.value=this.#t[0].text,this.#r.value=this.#t[0].value}#w(){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)})}#I(t){this.#t=this.#t.filter(e=>this.#d(e.value)!==this.#d(t)),this.#g(t)}#N(){const{scrollTop:t,scrollHeight:e,clientHeight:s}=this.#e;t+s>=e&&this.#M()}#d(t){return!isNaN(t)&&!isNaN(parseFloat(t))?parseInt(t):t}async render(){this.#S()}}h.selectyc=d,Object.defineProperty(h,Symbol.toStringTag,{value:"Module"})});
package/package.json ADDED
@@ -0,0 +1,52 @@
1
+ {
2
+ "name": "selectyc",
3
+ "description": "select multiple and simple",
4
+ "version": "0.0.1",
5
+ "main": "index.js",
6
+ "module": "./dist/TableScript.js",
7
+ "type": "module",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/CowboyCyberSpace/selectyc.git"
11
+ },
12
+ "exports": {
13
+ ".": {
14
+ "import": "./dist/selectyc.js",
15
+ "require": "./dist/selectyc.umd.cjs",
16
+ "styles": "./dist/selectyc.css"
17
+ }
18
+ },
19
+ "files": [
20
+ "dist"
21
+ ],
22
+ "scripts": {
23
+ "dev": "vite",
24
+ "build": "vite build",
25
+ "preview": "vite preview"
26
+ },
27
+ "devDependencies": {
28
+ "vite": "^7.0.4"
29
+ },
30
+ "peerDependencies": {
31
+ "jquery": "^3.7.1",
32
+ "tailwindcss": "^4.1.11"
33
+ },
34
+ "dependencies": {
35
+ "@tailwindcss/vite": "^4.1.11",
36
+ "esbuild": "^0.25.8",
37
+ "fdir": "^6.4.6",
38
+ "nanoid": "^3.3.11",
39
+ "picocolors": "^1.1.1",
40
+ "picomatch": "^4.0.3",
41
+ "postcss": "^8.5.6",
42
+ "rollup": "^4.46.1",
43
+ "source-map-js": "^1.2.1",
44
+ "tinyglobby": "^0.2.14"
45
+ },
46
+ "author": "Hector Jurado",
47
+ "license": "ISC",
48
+ "bugs": {
49
+ "url": "https://github.com/CowboyCyberSpace/selectyc/issues"
50
+ },
51
+ "homepage": "https://github.com/CowboyCyberSpace/selectyc#readme"
52
+ }