@popovandrii/ui-elements 0.0.13 → 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/README.md CHANGED
@@ -6,7 +6,7 @@ UI elements that contain a large share of JavaScript.
6
6
 
7
7
  ## add JS
8
8
  ```js
9
- import { SpinBox, Switch } from '@popovandrii/ui-elements';
9
+ import { SpinBox, Switch, Select } from '@popovandrii/ui-elements';
10
10
  ```
11
11
  Connection with `standard styles` from the package by element name.
12
12
  ```js
@@ -156,7 +156,7 @@ radius: `r-0` `r-1`<br>
156
156
  #### Select UI
157
157
  ```html
158
158
  <div class="UIselect lg r-1 info" id="mySelect" tabindex="0" role="listbox" aria-activedescendant="">
159
- <input type="hidden" name="myId">
159
+ <input type="hidden" name="myName">
160
160
  <span class="UIselect-selected">Select an option</span>
161
161
  <span class="UIselect-arrow">&#9662;</span>
162
162
  <ul class="UIselect-options" hidden>
@@ -164,13 +164,17 @@ radius: `r-0` `r-1`<br>
164
164
  <li role="option" data-value="two">Option 2</li>
165
165
  <li role="presentation" class="divider" aria-hidden="true"></li>
166
166
  <li role="option" data-value="thre">Option 3</li>
167
+ <li role="option" data-value="4" ia-selected="true">Default val</li>
167
168
  </ul>
168
169
  </div>
169
170
  ```
170
171
  ##### Send to server
171
172
  ```js
172
- const input = document.querySelector("#myId input[type='hidden']");
173
- SomeSendToServer(input.value);
173
+ const select = document.getElementById('mySelect');
174
+ select?.addEventListener('change', (e) => {
175
+ const value = e.detail?.value;
176
+ console.log('Value:', value);
177
+ });
174
178
  ```
175
179
 
176
180
  <p align="center">
@@ -197,6 +201,7 @@ $ npm run build # Compile the project into the ./dist folder.
197
201
  $ npm run dev # Work on the project
198
202
  $ npm run lint
199
203
  $ npm run format
204
+ $ npm install # before publishing the package (generation of the package-lock.json file)
200
205
  $ npm publish --access public
201
206
  $ npm info @popovandrii/ui-elements@0.0.x
202
207
  $ npm install @popovandrii/ui-elements@latest
package/dist/Select.d.ts CHANGED
@@ -15,6 +15,8 @@ export declare class Select {
15
15
  private itemArrow;
16
16
  private itemsPosition;
17
17
  private items;
18
+ private defaultSelect;
19
+ private costomEvent;
18
20
  private toggle;
19
21
  private close;
20
22
  static closeAll(map: SelectorMap): void;
package/dist/index.cjs.js CHANGED
@@ -1 +1 @@
1
- "use strict";var M=Object.defineProperty;var F=d=>{throw TypeError(d)};var T=(d,e,i)=>e in d?M(d,e,{enumerable:!0,configurable:!0,writable:!0,value:i}):d[e]=i;var b=(d,e,i)=>T(d,typeof e!="symbol"?e+"":e,i),C=(d,e,i)=>e.has(d)||F("Cannot "+i);var m=(d,e,i)=>(C(d,e,"read from private field"),i?i.call(d):e.get(d)),A=(d,e,i)=>e.has(d)?F("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(d):e.set(d,i);var g=(d,e,i)=>(C(d,e,"access private method"),i);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var v,y,w,D;class V{constructor(e={}){A(this,w);b(this,"selectors");b(this,"spinBoxes");A(this,v,(e,i,t,n=0,s=0)=>{e==n||e<n?(i.classList.add(this.selectors.disabledBtn),i.disabled=!0):(i.classList.remove(this.selectors.disabledBtn),i.disabled=!1),s!==0&&(e==s||e>s?(t.classList.add(this.selectors.disabledBtn),t.disabled=!0):(t.classList.remove(this.selectors.disabledBtn),t.disabled=!1))});A(this,y,(e,i)=>{const t=e.getAttribute(`data-${i}`);return t===null||t.trim()===""||isNaN(Number(t))?0:Number(t)});const i={main:"UIsp",btn:"UIsp__btn",input:"UIsp__input",disabledBtn:"disabled"};this.selectors={...i,...e},this.spinBoxes=document.querySelectorAll(`.${this.selectors.main}`),g(this,w,D).call(this)}}v=new WeakMap,y=new WeakMap,w=new WeakSet,D=function(){this.spinBoxes.forEach(e=>{const i=e.querySelectorAll(`.${this.selectors.btn}`),t=i[0],n=i[1],s=e.querySelector(`.${this.selectors.input}`),r=Number(e.dataset.step),c=Number(e.dataset.min),a=m(this,y).call(this,e,"max"),h=o=>{e.setAttribute("aria-valuenow",String(o)),e.setAttribute("aria-valuetext",`${o} items`)};Number(s.value)<=c&&(s.value=c.toFixed(r)),a!==0?(Number(s.value)>=a&&(s.value=a.toFixed(r)),a&&e.setAttribute("aria-valuemax",a.toFixed(r))):s.value=Number(s.value).toFixed(r),c&&e.setAttribute("aria-valuemin",c.toFixed(r)),m(this,v).call(this,Number(s.value),t,n,c,a),h(s.value);let u=null;const f=(o=1)=>{s.value=String(Math.abs(Number(s.value)));let l=parseFloat(s.value)||0;l=l+1*o/Math.pow(10,r),l>a&&a!==0&&(l=a),s.value=l.toFixed(r),m(this,v).call(this,Number(s.value),t,n,c,a),h(s.value)},E=(o=1)=>{s.value=String(Math.abs(Number(s.value)));let l=parseFloat(s.value)||0;l=l-1*o/Math.pow(10,r),l<c&&(l=c),s.value=l.toFixed(r),m(this,v).call(this,Number(s.value),t,n,c,a),h(s.value)},x=(o,l=150)=>{u===null&&(u=window.setInterval(o,l))},L=()=>{u!==null&&(clearInterval(u),u=null)};n.addEventListener("mousedown",o=>{const l=o.shiftKey?3:1;x(()=>f(l))}),n.addEventListener("touchstart",()=>x(f)),["mouseup","mouseleave","mouseout","touchend","touchcancel"].forEach(o=>{n.addEventListener(o,L)}),n.addEventListener("click",o=>{const l=o.shiftKey?3:1;u===null&&f(l)}),t.addEventListener("click",o=>{const l=o.shiftKey?3:1;u===null&&E(l)}),t.addEventListener("mousedown",o=>{const l=o.shiftKey?3:1;x(()=>E(l),100)}),t.addEventListener("touchstart",()=>x(E,100)),["mouseup","mouseleave","mouseout","touchend","touchcancel"].forEach(o=>{t.addEventListener(o,L)}),s.addEventListener("keydown",o=>{const l=o.key,K=o.shiftKey?3:1;if(["Backspace","Delete","ArrowLeft","ArrowRight","Tab","Enter","Home","End"].includes(l)||(o.ctrlKey||o.metaKey)&&["a","c","v","x"].includes(l.toLowerCase()))return;if(["e","+","-"].includes(l)){o.preventDefault();return}if(l==="ArrowUp"||l==="ArrowDown"){o.preventDefault();const q=parseFloat(s.value)||0,U=1*K/Math.pow(10,r);let S=l==="ArrowUp"?q+U:q-U;S<c&&(S=c),s.value=S.toFixed(r),Number(s.value)<c&&(s.value=c.toFixed(r)),Number(s.value)>a&&a!==0&&(s.value=a.toFixed(r)),m(this,v).call(this,Number(s.value),t,n,c,a),h(s.value);return}const I=l===","?".":l,$=/^[0-9]$/.test(I),N=I===".",P=s.value.includes(".");(r===0&&!$||r>0&&!($||N)||N&&P)&&o.preventDefault()}),s.addEventListener("change",()=>{Number(s.value)<c&&(s.value=c.toFixed(r)),Number(s.value)>a&&a!==0?s.value=a.toFixed(r):s.value=Number(s.value).toFixed(r),m(this,v).call(this,Number(s.value),t,n,c,a)})})};var k,B;class _{constructor(e={}){A(this,k);b(this,"selectors");b(this,"main");const i={main:"UIsw",label:"UIsw-label"};this.selectors={...i,...e},this.main=document.querySelectorAll(`.${this.selectors.main}`),g(this,k,B).call(this)}}k=new WeakSet,B=function(){this.main.forEach(e=>{const i=e.querySelector(`.${this.selectors.label}`),t=e.querySelector("input");i&&i.id&&e.setAttribute("aria-labelledby",i.id),t&&(t.checked?e.setAttribute("aria-checked","true"):e.setAttribute("aria-checked","false"),e.addEventListener("click",()=>{t.checked=!t.checked,e.setAttribute("aria-checked",String(t.checked))}),e.addEventListener("keydown",s=>{s.key==="ArrowRight"?(t.checked=!0,n(String(t.checked)),s.preventDefault()):s.key==="ArrowLeft"&&(t.checked=!1,n(String(t.checked)),s.preventDefault())}));const n=s=>{e.setAttribute("aria-checked",String(s))}})};class p{constructor(e={}){b(this,"selectors");b(this,"main");const i={idPrefix:"UI-option-",main:"UIselect",selected:"UIselect-selected",arrow:"UIselect-arrow",optionsList:"UIselect-options",excludedItems:["divider","test"]};this.selectors={...i,...e},this.main=document.querySelectorAll(`.${this.selectors.main}`),this.event(),p.initGlobalListener(this.selectors)}filterExcluded(e,i){return Array.from(e).filter(t=>!i.some(n=>typeof n=="string"?t.classList.contains(n)||t.id===n:t===n))}event(){this.main.forEach(e=>{const i=e.querySelector(`.${this.selectors.main} input[type='hidden']`);try{if(!i)throw new Error('<input type="hidden" name="YouUniqueId">')}catch(a){return console.warn("Not found:",a.message)}const t=e.querySelector(`.${this.selectors.selected}`),n=e.querySelector(`.${this.selectors.arrow}`),s=e.querySelector(`.${this.selectors.optionsList}`);n&&n.addEventListener("click",()=>{this.toggle(e,s)}),t.addEventListener("click",()=>{this.toggle(e,s)}),e.addEventListener("click",()=>{this.itemsPosition(e,s)});const r=s.querySelectorAll("li"),c=this.filterExcluded(r,this.selectors.excludedItems);this.itemArrow(e,s,c,t,i),this.items(e,s,c,t,i)})}itemArrow(e,i,t,n,s){let r=-1;const c=n.textContent?n.textContent:"";e.addEventListener("keydown",a=>{const h=t.length;if(a.key==="ArrowDown"){a.preventDefault(),e.getAttribute("aria-expanded")==="false"&&this.toggle(e,i),r=(r+1)%h,n.textContent=t[r].textContent,t.forEach(f=>f.removeAttribute("aria-selected")),t[r].setAttribute("aria-selected","true");const u=t[r].id||`${this.selectors.idPrefix}${r}`;e.setAttribute("aria-activedescendant",u),t[r].scrollIntoView({block:"nearest"})}else if(a.key==="ArrowUp"){a.preventDefault(),r=(r-1+h)%h,n.textContent=t[r].textContent,t.forEach(f=>f.removeAttribute("aria-selected")),t[r].setAttribute("aria-selected","true");const u=t[r].id||`${this.selectors.idPrefix}${r}`;e.setAttribute("aria-activedescendant",u),t[r].scrollIntoView({block:"nearest"})}else if(a.key==="Enter"||a.key===" ")if(a.preventDefault(),r>=0){n.textContent=t[r].textContent,t.forEach(f=>f.removeAttribute("aria-selected")),t[r].setAttribute("aria-selected","true");const u=t[r].id||`${this.selectors.idPrefix}${r}`;e.setAttribute("aria-activedescendant",u),s.value=String(t[r].dataset.value),this.close(e,i)}else this.toggle(e,i);else a.key==="Escape"&&(e.getAttribute("aria-activedescendant")||(n.textContent=c),this.close(e,i))})}itemsPosition(e,i){const t=i.querySelector('[aria-selected="true"]');t&&t.scrollIntoView({block:"nearest"})}items(e,i,t,n,s){t.forEach((r,c)=>{r.addEventListener("click",()=>{const a=t[c];if(a){n.textContent=a.textContent,t.forEach(u=>u.removeAttribute("aria-selected")),a.setAttribute("aria-selected","true");const h=a.id||`${this.selectors.idPrefix}${c}`;e.setAttribute("aria-expanded","false"),e.setAttribute("aria-activedescendant",h),s.value=String(t[c].dataset.value),this.close(e,i)}})})}toggle(e,i){p.closeAll(this.selectors),i.hidden?(i.hidden=!1,e.setAttribute("aria-expanded","true")):this.close(e,i)}close(e,i){i.hidden=!0,e.setAttribute("aria-expanded","false")}static closeAll(e){document.querySelectorAll(`.${e.main}`).forEach(i=>{const t=i.querySelector(`.${e.optionsList}`);t.hidden=!0,i.setAttribute("aria-expanded","false")})}static initGlobalListener(e){window.__UIselectGlobalClickInitialized||(document.addEventListener("click",i=>{const t=i.target;[...document.querySelectorAll(`.${e.main}`)].some(s=>s.contains(t))||p.closeAll(e)}),window.__UIselectGlobalClickInitialized=!0)}}exports.Select=p;exports.SpinBox=V;exports.Switch=_;
1
+ "use strict";var M=Object.defineProperty;var U=d=>{throw TypeError(d)};var T=(d,e,t)=>e in d?M(d,e,{enumerable:!0,configurable:!0,writable:!0,value:t}):d[e]=t;var b=(d,e,t)=>T(d,typeof e!="symbol"?e+"":e,t),D=(d,e,t)=>e.has(d)||U("Cannot "+t);var m=(d,e,t)=>(D(d,e,"read from private field"),t?t.call(d):e.get(d)),A=(d,e,t)=>e.has(d)?U("Cannot add the same private member more than once"):e instanceof WeakSet?e.add(d):e.set(d,t);var g=(d,e,t)=>(D(d,e,"access private method"),t);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});var f,y,w,F;class V{constructor(e={}){A(this,w);b(this,"selectors");b(this,"spinBoxes");A(this,f,(e,t,s,n=0,i=0)=>{e==n||e<n?(t.classList.add(this.selectors.disabledBtn),t.disabled=!0):(t.classList.remove(this.selectors.disabledBtn),t.disabled=!1),i!==0&&(e==i||e>i?(s.classList.add(this.selectors.disabledBtn),s.disabled=!0):(s.classList.remove(this.selectors.disabledBtn),s.disabled=!1))});A(this,y,(e,t)=>{const s=e.getAttribute(`data-${t}`);return s===null||s.trim()===""||isNaN(Number(s))?0:Number(s)});const t={main:"UIsp",btn:"UIsp__btn",input:"UIsp__input",disabledBtn:"disabled"};this.selectors={...t,...e},this.spinBoxes=document.querySelectorAll(`.${this.selectors.main}`),g(this,w,F).call(this)}}f=new WeakMap,y=new WeakMap,w=new WeakSet,F=function(){this.spinBoxes.forEach(e=>{const t=e.querySelectorAll(`.${this.selectors.btn}`),s=t[0],n=t[1],i=e.querySelector(`.${this.selectors.input}`),r=Number(e.dataset.step),c=Number(e.dataset.min),a=m(this,y).call(this,e,"max"),h=o=>{e.setAttribute("aria-valuenow",String(o)),e.setAttribute("aria-valuetext",`${o} items`)};Number(i.value)<=c&&(i.value=c.toFixed(r)),a!==0?(Number(i.value)>=a&&(i.value=a.toFixed(r)),a&&e.setAttribute("aria-valuemax",a.toFixed(r))):i.value=Number(i.value).toFixed(r),c&&e.setAttribute("aria-valuemin",c.toFixed(r)),m(this,f).call(this,Number(i.value),s,n,c,a),h(i.value);let u=null;const v=(o=1)=>{i.value=String(Math.abs(Number(i.value)));let l=parseFloat(i.value)||0;l=l+1*o/Math.pow(10,r),l>a&&a!==0&&(l=a),i.value=l.toFixed(r),m(this,f).call(this,Number(i.value),s,n,c,a),h(i.value)},k=(o=1)=>{i.value=String(Math.abs(Number(i.value)));let l=parseFloat(i.value)||0;l=l-1*o/Math.pow(10,r),l<c&&(l=c),i.value=l.toFixed(r),m(this,f).call(this,Number(i.value),s,n,c,a),h(i.value)},p=(o,l=150)=>{u===null&&(u=window.setInterval(o,l))},L=()=>{u!==null&&(clearInterval(u),u=null)};n.addEventListener("mousedown",o=>{const l=o.shiftKey?3:1;p(()=>v(l))}),n.addEventListener("touchstart",()=>p(v)),["mouseup","mouseleave","mouseout","touchend","touchcancel"].forEach(o=>{n.addEventListener(o,L)}),n.addEventListener("click",o=>{const l=o.shiftKey?3:1;u===null&&v(l)}),s.addEventListener("click",o=>{const l=o.shiftKey?3:1;u===null&&k(l)}),s.addEventListener("mousedown",o=>{const l=o.shiftKey?3:1;p(()=>k(l),100)}),s.addEventListener("touchstart",()=>p(k,100)),["mouseup","mouseleave","mouseout","touchend","touchcancel"].forEach(o=>{s.addEventListener(o,L)}),i.addEventListener("keydown",o=>{const l=o.key,K=o.shiftKey?3:1;if(["Backspace","Delete","ArrowLeft","ArrowRight","Tab","Enter","Home","End"].includes(l)||(o.ctrlKey||o.metaKey)&&["a","c","v","x"].includes(l.toLowerCase()))return;if(["e","+","-"].includes(l)){o.preventDefault();return}if(l==="ArrowUp"||l==="ArrowDown"){o.preventDefault();const q=parseFloat(i.value)||0,C=1*K/Math.pow(10,r);let S=l==="ArrowUp"?q+C:q-C;S<c&&(S=c),i.value=S.toFixed(r),Number(i.value)<c&&(i.value=c.toFixed(r)),Number(i.value)>a&&a!==0&&(i.value=a.toFixed(r)),m(this,f).call(this,Number(i.value),s,n,c,a),h(i.value);return}const I=l===","?".":l,$=/^[0-9]$/.test(I),N=I===".",P=i.value.includes(".");(r===0&&!$||r>0&&!($||N)||N&&P)&&o.preventDefault()}),i.addEventListener("change",()=>{Number(i.value)<c&&(i.value=c.toFixed(r)),Number(i.value)>a&&a!==0?i.value=a.toFixed(r):i.value=Number(i.value).toFixed(r),m(this,f).call(this,Number(i.value),s,n,c,a)})})};var E,B;class _{constructor(e={}){A(this,E);b(this,"selectors");b(this,"main");const t={main:"UIsw",label:"UIsw-label"};this.selectors={...t,...e},this.main=document.querySelectorAll(`.${this.selectors.main}`),g(this,E,B).call(this)}}E=new WeakSet,B=function(){this.main.forEach(e=>{const t=e.querySelector(`.${this.selectors.label}`),s=e.querySelector("input");t&&t.id&&e.setAttribute("aria-labelledby",t.id),s&&(s.checked?e.setAttribute("aria-checked","true"):e.setAttribute("aria-checked","false"),e.addEventListener("click",()=>{s.checked=!s.checked,e.setAttribute("aria-checked",String(s.checked))}),e.addEventListener("keydown",i=>{i.key==="ArrowRight"?(s.checked=!0,n(String(s.checked)),i.preventDefault()):i.key==="ArrowLeft"&&(s.checked=!1,n(String(s.checked)),i.preventDefault())}));const n=i=>{e.setAttribute("aria-checked",String(i))}})};class x{constructor(e={}){b(this,"selectors");b(this,"main");const t={idPrefix:"UI-option-",main:"UIselect",selected:"UIselect-selected",arrow:"UIselect-arrow",optionsList:"UIselect-options",excludedItems:["divider","test"]};this.selectors={...t,...e},this.main=document.querySelectorAll(`.${this.selectors.main}`),this.event(),x.initGlobalListener(this.selectors)}filterExcluded(e,t){return Array.from(e).filter(s=>!t.some(n=>typeof n=="string"?s.classList.contains(n)||s.id===n:s===n))}event(){this.main.forEach(e=>{const t=e.querySelector(`.${this.selectors.main} input[type='hidden']`);try{if(!t)throw new Error('<input type="hidden" name="YouUniqueId">')}catch(h){return console.warn("Not found:",h.message)}const s=e.querySelector(`.${this.selectors.selected}`),n=e.querySelector(`.${this.selectors.arrow}`),i=e.querySelector(`.${this.selectors.optionsList}`);n&&n.addEventListener("click",()=>{this.toggle(e,i)}),s.addEventListener("click",()=>{this.toggle(e,i)}),e.addEventListener("click",()=>{this.itemsPosition(i)});const r=i.querySelectorAll("li"),c=this.filterExcluded(r,this.selectors.excludedItems),a=e.querySelector("[aria-selected='true']");a&&this.defaultSelect(e,a,s,t),this.itemArrow(e,i,c,s,t),this.items(e,i,c,s,t)})}itemArrow(e,t,s,n,i){let r=-1;const c=n.textContent?n.textContent:"";e.addEventListener("keydown",a=>{const h=s.length;if(a.key==="ArrowDown"){a.preventDefault(),e.getAttribute("aria-expanded")==="false"&&this.toggle(e,t),r=(r+1)%h,n.textContent=s[r].textContent,s.forEach(v=>v.removeAttribute("aria-selected")),s[r].setAttribute("aria-selected","true");const u=s[r].id||`${this.selectors.idPrefix}${r}`;e.setAttribute("aria-activedescendant",u),s[r].scrollIntoView({block:"nearest"})}else if(a.key==="ArrowUp"){a.preventDefault(),r=(r-1+h)%h,n.textContent=s[r].textContent,s.forEach(v=>v.removeAttribute("aria-selected")),s[r].setAttribute("aria-selected","true");const u=s[r].id||`${this.selectors.idPrefix}${r}`;e.setAttribute("aria-activedescendant",u),s[r].scrollIntoView({block:"nearest"})}else if(a.key==="Enter"||a.key===" ")if(a.preventDefault(),r>=0){n.textContent=s[r].textContent,s.forEach(v=>v.removeAttribute("aria-selected")),s[r].setAttribute("aria-selected","true");const u=s[r].id||`${this.selectors.idPrefix}${r}`;e.setAttribute("aria-activedescendant",u),i.value=String(s[r].dataset.value),this.costomEvent(e,i.value),this.close(e,t)}else this.toggle(e,t);else a.key==="Escape"&&(e.getAttribute("aria-activedescendant")||(n.textContent=c),this.close(e,t))})}itemsPosition(e){const t=e.querySelector('[aria-selected="true"]');t&&t.scrollIntoView({block:"nearest"})}items(e,t,s,n,i){s.forEach((r,c)=>{r.addEventListener("click",()=>{const a=s[c];if(a){n.textContent=a.textContent,s.forEach(u=>u.removeAttribute("aria-selected")),a.setAttribute("aria-selected","true");const h=a.id||`${this.selectors.idPrefix}${c}`;e.setAttribute("aria-expanded","false"),e.setAttribute("aria-activedescendant",h),i.value=String(s[c].dataset.value),this.costomEvent(e,i.value),this.close(e,t)}})})}defaultSelect(e,t,s,n){t&&(n.setAttribute("value",t.dataset.value??""),s.textContent=t.textContent??"",e.setAttribute("aria-activedescendant",t.id||""))}costomEvent(e,t){e.dispatchEvent(new CustomEvent("change",{detail:{val:t},bubbles:!0}))}toggle(e,t){x.closeAll(this.selectors),t.hidden?(t.hidden=!1,e.setAttribute("aria-expanded","true")):this.close(e,t)}close(e,t){t.hidden=!0,e.setAttribute("aria-expanded","false")}static closeAll(e){document.querySelectorAll(`.${e.main}`).forEach(t=>{const s=t.querySelector(`.${e.optionsList}`);s.hidden=!0,t.setAttribute("aria-expanded","false")})}static initGlobalListener(e){window.__UIselectGlobalClickInitialized||(document.addEventListener("click",t=>{const s=t.target;[...document.querySelectorAll(`.${e.main}`)].some(i=>i.contains(s))||x.closeAll(e)}),window.__UIselectGlobalClickInitialized=!0)}}exports.Select=x;exports.SpinBox=V;exports.Switch=_;
package/dist/index.es.js CHANGED
@@ -1,80 +1,80 @@
1
1
  var M = Object.defineProperty;
2
- var F = (d) => {
2
+ var U = (d) => {
3
3
  throw TypeError(d);
4
4
  };
5
- var V = (d, e, i) => e in d ? M(d, e, { enumerable: !0, configurable: !0, writable: !0, value: i }) : d[e] = i;
6
- var b = (d, e, i) => V(d, typeof e != "symbol" ? e + "" : e, i), C = (d, e, i) => e.has(d) || F("Cannot " + i);
7
- var m = (d, e, i) => (C(d, e, "read from private field"), i ? i.call(d) : e.get(d)), A = (d, e, i) => e.has(d) ? F("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(d) : e.set(d, i);
8
- var S = (d, e, i) => (C(d, e, "access private method"), i);
9
- var v, y, w, D;
5
+ var V = (d, e, t) => e in d ? M(d, e, { enumerable: !0, configurable: !0, writable: !0, value: t }) : d[e] = t;
6
+ var b = (d, e, t) => V(d, typeof e != "symbol" ? e + "" : e, t), D = (d, e, t) => e.has(d) || U("Cannot " + t);
7
+ var m = (d, e, t) => (D(d, e, "read from private field"), t ? t.call(d) : e.get(d)), A = (d, e, t) => e.has(d) ? U("Cannot add the same private member more than once") : e instanceof WeakSet ? e.add(d) : e.set(d, t);
8
+ var S = (d, e, t) => (D(d, e, "access private method"), t);
9
+ var f, y, w, F;
10
10
  class G {
11
11
  constructor(e = {}) {
12
12
  A(this, w);
13
13
  b(this, "selectors");
14
14
  b(this, "spinBoxes");
15
- A(this, v, (e, i, t, n = 0, s = 0) => {
16
- e == n || e < n ? (i.classList.add(this.selectors.disabledBtn), i.disabled = !0) : (i.classList.remove(this.selectors.disabledBtn), i.disabled = !1), s !== 0 && (e == s || e > s ? (t.classList.add(this.selectors.disabledBtn), t.disabled = !0) : (t.classList.remove(this.selectors.disabledBtn), t.disabled = !1));
15
+ A(this, f, (e, t, s, n = 0, i = 0) => {
16
+ e == n || e < n ? (t.classList.add(this.selectors.disabledBtn), t.disabled = !0) : (t.classList.remove(this.selectors.disabledBtn), t.disabled = !1), i !== 0 && (e == i || e > i ? (s.classList.add(this.selectors.disabledBtn), s.disabled = !0) : (s.classList.remove(this.selectors.disabledBtn), s.disabled = !1));
17
17
  });
18
- A(this, y, (e, i) => {
19
- const t = e.getAttribute(`data-${i}`);
20
- return t === null || t.trim() === "" || isNaN(Number(t)) ? 0 : Number(t);
18
+ A(this, y, (e, t) => {
19
+ const s = e.getAttribute(`data-${t}`);
20
+ return s === null || s.trim() === "" || isNaN(Number(s)) ? 0 : Number(s);
21
21
  });
22
- const i = {
22
+ const t = {
23
23
  main: "UIsp",
24
24
  btn: "UIsp__btn",
25
25
  input: "UIsp__input",
26
26
  disabledBtn: "disabled"
27
27
  };
28
- this.selectors = { ...i, ...e }, this.spinBoxes = document.querySelectorAll(
28
+ this.selectors = { ...t, ...e }, this.spinBoxes = document.querySelectorAll(
29
29
  `.${this.selectors.main}`
30
- ), S(this, w, D).call(this);
30
+ ), S(this, w, F).call(this);
31
31
  }
32
32
  }
33
- v = new WeakMap(), y = new WeakMap(), w = new WeakSet(), D = function() {
33
+ f = new WeakMap(), y = new WeakMap(), w = new WeakSet(), F = function() {
34
34
  this.spinBoxes.forEach((e) => {
35
- const i = e.querySelectorAll(
35
+ const t = e.querySelectorAll(
36
36
  `.${this.selectors.btn}`
37
- ), t = i[0], n = i[1], s = e.querySelector(
37
+ ), s = t[0], n = t[1], i = e.querySelector(
38
38
  `.${this.selectors.input}`
39
39
  ), r = Number(e.dataset.step), c = Number(e.dataset.min), a = m(this, y).call(this, e, "max"), h = (o) => {
40
40
  e.setAttribute("aria-valuenow", String(o)), e.setAttribute("aria-valuetext", `${o} items`);
41
41
  };
42
- Number(s.value) <= c && (s.value = c.toFixed(r)), a !== 0 ? (Number(s.value) >= a && (s.value = a.toFixed(r)), a && e.setAttribute("aria-valuemax", a.toFixed(r))) : s.value = Number(s.value).toFixed(r), c && e.setAttribute("aria-valuemin", c.toFixed(r)), m(this, v).call(this, Number(s.value), t, n, c, a), h(s.value);
42
+ Number(i.value) <= c && (i.value = c.toFixed(r)), a !== 0 ? (Number(i.value) >= a && (i.value = a.toFixed(r)), a && e.setAttribute("aria-valuemax", a.toFixed(r))) : i.value = Number(i.value).toFixed(r), c && e.setAttribute("aria-valuemin", c.toFixed(r)), m(this, f).call(this, Number(i.value), s, n, c, a), h(i.value);
43
43
  let u = null;
44
- const f = (o = 1) => {
45
- s.value = String(Math.abs(Number(s.value)));
46
- let l = parseFloat(s.value) || 0;
47
- l = l + 1 * o / Math.pow(10, r), l > a && a !== 0 && (l = a), s.value = l.toFixed(r), m(this, v).call(this, Number(s.value), t, n, c, a), h(s.value);
48
- }, E = (o = 1) => {
49
- s.value = String(Math.abs(Number(s.value)));
50
- let l = parseFloat(s.value) || 0;
51
- l = l - 1 * o / Math.pow(10, r), l < c && (l = c), s.value = l.toFixed(r), m(this, v).call(this, Number(s.value), t, n, c, a), h(s.value);
52
- }, p = (o, l = 150) => {
44
+ const v = (o = 1) => {
45
+ i.value = String(Math.abs(Number(i.value)));
46
+ let l = parseFloat(i.value) || 0;
47
+ l = l + 1 * o / Math.pow(10, r), l > a && a !== 0 && (l = a), i.value = l.toFixed(r), m(this, f).call(this, Number(i.value), s, n, c, a), h(i.value);
48
+ }, k = (o = 1) => {
49
+ i.value = String(Math.abs(Number(i.value)));
50
+ let l = parseFloat(i.value) || 0;
51
+ l = l - 1 * o / Math.pow(10, r), l < c && (l = c), i.value = l.toFixed(r), m(this, f).call(this, Number(i.value), s, n, c, a), h(i.value);
52
+ }, x = (o, l = 150) => {
53
53
  u === null && (u = window.setInterval(o, l));
54
54
  }, L = () => {
55
55
  u !== null && (clearInterval(u), u = null);
56
56
  };
57
57
  n.addEventListener("mousedown", (o) => {
58
58
  const l = o.shiftKey ? 3 : 1;
59
- p(() => f(l));
60
- }), n.addEventListener("touchstart", () => p(f)), ["mouseup", "mouseleave", "mouseout", "touchend", "touchcancel"].forEach(
59
+ x(() => v(l));
60
+ }), n.addEventListener("touchstart", () => x(v)), ["mouseup", "mouseleave", "mouseout", "touchend", "touchcancel"].forEach(
61
61
  (o) => {
62
62
  n.addEventListener(o, L);
63
63
  }
64
64
  ), n.addEventListener("click", (o) => {
65
65
  const l = o.shiftKey ? 3 : 1;
66
- u === null && f(l);
67
- }), t.addEventListener("click", (o) => {
66
+ u === null && v(l);
67
+ }), s.addEventListener("click", (o) => {
68
68
  const l = o.shiftKey ? 3 : 1;
69
- u === null && E(l);
70
- }), t.addEventListener("mousedown", (o) => {
69
+ u === null && k(l);
70
+ }), s.addEventListener("mousedown", (o) => {
71
71
  const l = o.shiftKey ? 3 : 1;
72
- p(() => E(l), 100);
73
- }), t.addEventListener("touchstart", () => p(E, 100)), ["mouseup", "mouseleave", "mouseout", "touchend", "touchcancel"].forEach(
72
+ x(() => k(l), 100);
73
+ }), s.addEventListener("touchstart", () => x(k, 100)), ["mouseup", "mouseleave", "mouseout", "touchend", "touchcancel"].forEach(
74
74
  (o) => {
75
- t.addEventListener(o, L);
75
+ s.addEventListener(o, L);
76
76
  }
77
- ), s.addEventListener("keydown", (o) => {
77
+ ), i.addEventListener("keydown", (o) => {
78
78
  const l = o.key, K = o.shiftKey ? 3 : 1;
79
79
  if ([
80
80
  "Backspace",
@@ -93,51 +93,51 @@ v = new WeakMap(), y = new WeakMap(), w = new WeakSet(), D = function() {
93
93
  }
94
94
  if (l === "ArrowUp" || l === "ArrowDown") {
95
95
  o.preventDefault();
96
- const q = parseFloat(s.value) || 0, U = 1 * K / Math.pow(10, r);
97
- let g = l === "ArrowUp" ? q + U : q - U;
98
- g < c && (g = c), s.value = g.toFixed(r), Number(s.value) < c && (s.value = c.toFixed(r)), Number(s.value) > a && a !== 0 && (s.value = a.toFixed(r)), m(this, v).call(this, Number(s.value), t, n, c, a), h(s.value);
96
+ const q = parseFloat(i.value) || 0, C = 1 * K / Math.pow(10, r);
97
+ let g = l === "ArrowUp" ? q + C : q - C;
98
+ g < c && (g = c), i.value = g.toFixed(r), Number(i.value) < c && (i.value = c.toFixed(r)), Number(i.value) > a && a !== 0 && (i.value = a.toFixed(r)), m(this, f).call(this, Number(i.value), s, n, c, a), h(i.value);
99
99
  return;
100
100
  }
101
- const I = l === "," ? "." : l, $ = /^[0-9]$/.test(I), N = I === ".", P = s.value.includes(".");
101
+ const I = l === "," ? "." : l, $ = /^[0-9]$/.test(I), N = I === ".", P = i.value.includes(".");
102
102
  (r === 0 && !$ || r > 0 && !($ || N) || N && P) && o.preventDefault();
103
- }), s.addEventListener("change", () => {
104
- Number(s.value) < c && (s.value = c.toFixed(r)), Number(s.value) > a && a !== 0 ? s.value = a.toFixed(r) : s.value = Number(s.value).toFixed(r), m(this, v).call(this, Number(s.value), t, n, c, a);
103
+ }), i.addEventListener("change", () => {
104
+ Number(i.value) < c && (i.value = c.toFixed(r)), Number(i.value) > a && a !== 0 ? i.value = a.toFixed(r) : i.value = Number(i.value).toFixed(r), m(this, f).call(this, Number(i.value), s, n, c, a);
105
105
  });
106
106
  });
107
107
  };
108
- var k, B;
108
+ var E, B;
109
109
  class T {
110
110
  constructor(e = {}) {
111
- A(this, k);
111
+ A(this, E);
112
112
  b(this, "selectors");
113
113
  b(this, "main");
114
- const i = {
114
+ const t = {
115
115
  main: "UIsw",
116
116
  label: "UIsw-label"
117
117
  };
118
- this.selectors = { ...i, ...e }, this.main = document.querySelectorAll(
118
+ this.selectors = { ...t, ...e }, this.main = document.querySelectorAll(
119
119
  `.${this.selectors.main}`
120
- ), S(this, k, B).call(this);
120
+ ), S(this, E, B).call(this);
121
121
  }
122
122
  }
123
- k = new WeakSet(), B = function() {
123
+ E = new WeakSet(), B = function() {
124
124
  this.main.forEach((e) => {
125
- const i = e.querySelector(`.${this.selectors.label}`), t = e.querySelector("input");
126
- i && i.id && e.setAttribute("aria-labelledby", i.id), t && (t.checked ? e.setAttribute("aria-checked", "true") : e.setAttribute("aria-checked", "false"), e.addEventListener("click", () => {
127
- t.checked = !t.checked, e.setAttribute("aria-checked", String(t.checked));
128
- }), e.addEventListener("keydown", (s) => {
129
- s.key === "ArrowRight" ? (t.checked = !0, n(String(t.checked)), s.preventDefault()) : s.key === "ArrowLeft" && (t.checked = !1, n(String(t.checked)), s.preventDefault());
125
+ const t = e.querySelector(`.${this.selectors.label}`), s = e.querySelector("input");
126
+ t && t.id && e.setAttribute("aria-labelledby", t.id), s && (s.checked ? e.setAttribute("aria-checked", "true") : e.setAttribute("aria-checked", "false"), e.addEventListener("click", () => {
127
+ s.checked = !s.checked, e.setAttribute("aria-checked", String(s.checked));
128
+ }), e.addEventListener("keydown", (i) => {
129
+ i.key === "ArrowRight" ? (s.checked = !0, n(String(s.checked)), i.preventDefault()) : i.key === "ArrowLeft" && (s.checked = !1, n(String(s.checked)), i.preventDefault());
130
130
  }));
131
- const n = (s) => {
132
- e.setAttribute("aria-checked", String(s));
131
+ const n = (i) => {
132
+ e.setAttribute("aria-checked", String(i));
133
133
  };
134
134
  });
135
135
  };
136
- class x {
136
+ class p {
137
137
  constructor(e = {}) {
138
138
  b(this, "selectors");
139
139
  b(this, "main");
140
- const i = {
140
+ const t = {
141
141
  idPrefix: "UI-option-",
142
142
  main: "UIselect",
143
143
  selected: "UIselect-selected",
@@ -146,109 +146,122 @@ class x {
146
146
  excludedItems: ["divider", "test"]
147
147
  // class=""
148
148
  };
149
- this.selectors = { ...i, ...e }, this.main = document.querySelectorAll(
149
+ this.selectors = { ...t, ...e }, this.main = document.querySelectorAll(
150
150
  `.${this.selectors.main}`
151
- ), this.event(), x.initGlobalListener(this.selectors);
151
+ ), this.event(), p.initGlobalListener(this.selectors);
152
152
  }
153
- filterExcluded(e, i) {
154
- return Array.from(e).filter((t) => !i.some((n) => typeof n == "string" ? t.classList.contains(n) || t.id === n : t === n));
153
+ filterExcluded(e, t) {
154
+ return Array.from(e).filter((s) => !t.some((n) => typeof n == "string" ? s.classList.contains(n) || s.id === n : s === n));
155
155
  }
156
156
  event() {
157
157
  this.main.forEach((e) => {
158
- const i = e.querySelector(
158
+ const t = e.querySelector(
159
159
  `.${this.selectors.main} input[type='hidden']`
160
160
  );
161
161
  try {
162
- if (!i)
162
+ if (!t)
163
163
  throw new Error('<input type="hidden" name="YouUniqueId">');
164
- } catch (a) {
165
- return console.warn("Not found:", a.message);
164
+ } catch (h) {
165
+ return console.warn("Not found:", h.message);
166
166
  }
167
- const t = e.querySelector(
167
+ const s = e.querySelector(
168
168
  `.${this.selectors.selected}`
169
169
  ), n = e.querySelector(
170
170
  `.${this.selectors.arrow}`
171
- ), s = e.querySelector(
171
+ ), i = e.querySelector(
172
172
  `.${this.selectors.optionsList}`
173
173
  );
174
174
  n && n.addEventListener("click", () => {
175
- this.toggle(e, s);
176
- }), t.addEventListener("click", () => {
177
- this.toggle(e, s);
175
+ this.toggle(e, i);
176
+ }), s.addEventListener("click", () => {
177
+ this.toggle(e, i);
178
178
  }), e.addEventListener("click", () => {
179
- this.itemsPosition(e, s);
179
+ this.itemsPosition(i);
180
180
  });
181
- const r = s.querySelectorAll("li"), c = this.filterExcluded(
181
+ const r = i.querySelectorAll("li"), c = this.filterExcluded(
182
182
  r,
183
183
  this.selectors.excludedItems
184
+ ), a = e.querySelector(
185
+ "[aria-selected='true']"
184
186
  );
185
- this.itemArrow(e, s, c, t, i), this.items(e, s, c, t, i);
187
+ a && this.defaultSelect(e, a, s, t), this.itemArrow(e, i, c, s, t), this.items(e, i, c, s, t);
186
188
  });
187
189
  }
188
- itemArrow(e, i, t, n, s) {
190
+ itemArrow(e, t, s, n, i) {
189
191
  let r = -1;
190
192
  const c = n.textContent ? n.textContent : "";
191
193
  e.addEventListener("keydown", (a) => {
192
- const h = t.length;
194
+ const h = s.length;
193
195
  if (a.key === "ArrowDown") {
194
- a.preventDefault(), e.getAttribute("aria-expanded") === "false" && this.toggle(e, i), r = (r + 1) % h, n.textContent = t[r].textContent, t.forEach((f) => f.removeAttribute("aria-selected")), t[r].setAttribute("aria-selected", "true");
195
- const u = t[r].id || `${this.selectors.idPrefix}${r}`;
196
- e.setAttribute("aria-activedescendant", u), t[r].scrollIntoView({ block: "nearest" });
196
+ a.preventDefault(), e.getAttribute("aria-expanded") === "false" && this.toggle(e, t), r = (r + 1) % h, n.textContent = s[r].textContent, s.forEach((v) => v.removeAttribute("aria-selected")), s[r].setAttribute("aria-selected", "true");
197
+ const u = s[r].id || `${this.selectors.idPrefix}${r}`;
198
+ e.setAttribute("aria-activedescendant", u), s[r].scrollIntoView({ block: "nearest" });
197
199
  } else if (a.key === "ArrowUp") {
198
- a.preventDefault(), r = (r - 1 + h) % h, n.textContent = t[r].textContent, t.forEach((f) => f.removeAttribute("aria-selected")), t[r].setAttribute("aria-selected", "true");
199
- const u = t[r].id || `${this.selectors.idPrefix}${r}`;
200
- e.setAttribute("aria-activedescendant", u), t[r].scrollIntoView({ block: "nearest" });
200
+ a.preventDefault(), r = (r - 1 + h) % h, n.textContent = s[r].textContent, s.forEach((v) => v.removeAttribute("aria-selected")), s[r].setAttribute("aria-selected", "true");
201
+ const u = s[r].id || `${this.selectors.idPrefix}${r}`;
202
+ e.setAttribute("aria-activedescendant", u), s[r].scrollIntoView({ block: "nearest" });
201
203
  } else if (a.key === "Enter" || a.key === " ")
202
204
  if (a.preventDefault(), r >= 0) {
203
- n.textContent = t[r].textContent, t.forEach((f) => f.removeAttribute("aria-selected")), t[r].setAttribute("aria-selected", "true");
204
- const u = t[r].id || `${this.selectors.idPrefix}${r}`;
205
- e.setAttribute("aria-activedescendant", u), s.value = String(t[r].dataset.value), this.close(e, i);
205
+ n.textContent = s[r].textContent, s.forEach((v) => v.removeAttribute("aria-selected")), s[r].setAttribute("aria-selected", "true");
206
+ const u = s[r].id || `${this.selectors.idPrefix}${r}`;
207
+ e.setAttribute("aria-activedescendant", u), i.value = String(s[r].dataset.value), this.costomEvent(e, i.value), this.close(e, t);
206
208
  } else
207
- this.toggle(e, i);
208
- else a.key === "Escape" && (e.getAttribute("aria-activedescendant") || (n.textContent = c), this.close(e, i));
209
+ this.toggle(e, t);
210
+ else a.key === "Escape" && (e.getAttribute("aria-activedescendant") || (n.textContent = c), this.close(e, t));
209
211
  });
210
212
  }
211
- itemsPosition(e, i) {
212
- const t = i.querySelector(
213
+ itemsPosition(e) {
214
+ const t = e.querySelector(
213
215
  '[aria-selected="true"]'
214
216
  );
215
217
  t && t.scrollIntoView({ block: "nearest" });
216
218
  }
217
- items(e, i, t, n, s) {
218
- t.forEach((r, c) => {
219
+ items(e, t, s, n, i) {
220
+ s.forEach((r, c) => {
219
221
  r.addEventListener("click", () => {
220
- const a = t[c];
222
+ const a = s[c];
221
223
  if (a) {
222
- n.textContent = a.textContent, t.forEach((u) => u.removeAttribute("aria-selected")), a.setAttribute("aria-selected", "true");
224
+ n.textContent = a.textContent, s.forEach((u) => u.removeAttribute("aria-selected")), a.setAttribute("aria-selected", "true");
223
225
  const h = a.id || `${this.selectors.idPrefix}${c}`;
224
- e.setAttribute("aria-expanded", "false"), e.setAttribute("aria-activedescendant", h), s.value = String(t[c].dataset.value), this.close(e, i);
226
+ e.setAttribute("aria-expanded", "false"), e.setAttribute("aria-activedescendant", h), i.value = String(s[c].dataset.value), this.costomEvent(e, i.value), this.close(e, t);
225
227
  }
226
228
  });
227
229
  });
228
230
  }
229
- toggle(e, i) {
230
- x.closeAll(this.selectors), i.hidden ? (i.hidden = !1, e.setAttribute("aria-expanded", "true")) : this.close(e, i);
231
+ defaultSelect(e, t, s, n) {
232
+ t && (n.setAttribute("value", t.dataset.value ?? ""), s.textContent = t.textContent ?? "", e.setAttribute("aria-activedescendant", t.id || ""));
233
+ }
234
+ costomEvent(e, t) {
235
+ e.dispatchEvent(
236
+ new CustomEvent("change", {
237
+ detail: { val: t },
238
+ bubbles: !0
239
+ })
240
+ );
241
+ }
242
+ toggle(e, t) {
243
+ p.closeAll(this.selectors), t.hidden ? (t.hidden = !1, e.setAttribute("aria-expanded", "true")) : this.close(e, t);
231
244
  }
232
- close(e, i) {
233
- i.hidden = !0, e.setAttribute("aria-expanded", "false");
245
+ close(e, t) {
246
+ t.hidden = !0, e.setAttribute("aria-expanded", "false");
234
247
  }
235
248
  static closeAll(e) {
236
- document.querySelectorAll(`.${e.main}`).forEach((i) => {
237
- const t = i.querySelector(`.${e.optionsList}`);
238
- t.hidden = !0, i.setAttribute("aria-expanded", "false");
249
+ document.querySelectorAll(`.${e.main}`).forEach((t) => {
250
+ const s = t.querySelector(`.${e.optionsList}`);
251
+ s.hidden = !0, t.setAttribute("aria-expanded", "false");
239
252
  });
240
253
  }
241
254
  static initGlobalListener(e) {
242
- window.__UIselectGlobalClickInitialized || (document.addEventListener("click", (i) => {
243
- const t = i.target;
255
+ window.__UIselectGlobalClickInitialized || (document.addEventListener("click", (t) => {
256
+ const s = t.target;
244
257
  [...document.querySelectorAll(`.${e.main}`)].some(
245
- (s) => s.contains(t)
246
- ) || x.closeAll(e);
258
+ (i) => i.contains(s)
259
+ ) || p.closeAll(e);
247
260
  }), window.__UIselectGlobalClickInitialized = !0);
248
261
  }
249
262
  }
250
263
  export {
251
- x as Select,
264
+ p as Select,
252
265
  G as SpinBox,
253
266
  T as Switch
254
267
  };
package/dist/index.umd.js CHANGED
@@ -1 +1 @@
1
- (function(o,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(o=typeof globalThis<"u"?globalThis:o||self,u(o.UiElements={}))})(this,function(o){"use strict";var _=Object.defineProperty;var D=o=>{throw TypeError(o)};var z=(o,u,h)=>u in o?_(o,u,{enumerable:!0,configurable:!0,writable:!0,value:h}):o[u]=h;var p=(o,u,h)=>z(o,typeof u!="symbol"?u+"":u,h),B=(o,u,h)=>u.has(o)||D("Cannot "+h);var A=(o,u,h)=>(B(o,u,"read from private field"),h?h.call(o):u.get(o)),x=(o,u,h)=>u.has(o)?D("Cannot add the same private member more than once"):u instanceof WeakSet?u.add(o):u.set(o,h);var I=(o,u,h)=>(B(o,u,"access private method"),h);var m,w,k,K,E,P;class u{constructor(e={}){x(this,k);p(this,"selectors");p(this,"spinBoxes");x(this,m,(e,i,t,a=0,s=0)=>{e==a||e<a?(i.classList.add(this.selectors.disabledBtn),i.disabled=!0):(i.classList.remove(this.selectors.disabledBtn),i.disabled=!1),s!==0&&(e==s||e>s?(t.classList.add(this.selectors.disabledBtn),t.disabled=!0):(t.classList.remove(this.selectors.disabledBtn),t.disabled=!1))});x(this,w,(e,i)=>{const t=e.getAttribute(`data-${i}`);return t===null||t.trim()===""||isNaN(Number(t))?0:Number(t)});const i={main:"UIsp",btn:"UIsp__btn",input:"UIsp__input",disabledBtn:"disabled"};this.selectors={...i,...e},this.spinBoxes=document.querySelectorAll(`.${this.selectors.main}`),I(this,k,K).call(this)}}m=new WeakMap,w=new WeakMap,k=new WeakSet,K=function(){this.spinBoxes.forEach(e=>{const i=e.querySelectorAll(`.${this.selectors.btn}`),t=i[0],a=i[1],s=e.querySelector(`.${this.selectors.input}`),r=Number(e.dataset.step),d=Number(e.dataset.min),n=A(this,w).call(this,e,"max"),v=c=>{e.setAttribute("aria-valuenow",String(c)),e.setAttribute("aria-valuetext",`${c} items`)};Number(s.value)<=d&&(s.value=d.toFixed(r)),n!==0?(Number(s.value)>=n&&(s.value=n.toFixed(r)),n&&e.setAttribute("aria-valuemax",n.toFixed(r))):s.value=Number(s.value).toFixed(r),d&&e.setAttribute("aria-valuemin",d.toFixed(r)),A(this,m).call(this,Number(s.value),t,a,d,n),v(s.value);let f=null;const b=(c=1)=>{s.value=String(Math.abs(Number(s.value)));let l=parseFloat(s.value)||0;l=l+1*c/Math.pow(10,r),l>n&&n!==0&&(l=n),s.value=l.toFixed(r),A(this,m).call(this,Number(s.value),t,a,d,n),v(s.value)},g=(c=1)=>{s.value=String(Math.abs(Number(s.value)));let l=parseFloat(s.value)||0;l=l-1*c/Math.pow(10,r),l<d&&(l=d),s.value=l.toFixed(r),A(this,m).call(this,Number(s.value),t,a,d,n),v(s.value)},S=(c,l=150)=>{f===null&&(f=window.setInterval(c,l))},$=()=>{f!==null&&(clearInterval(f),f=null)};a.addEventListener("mousedown",c=>{const l=c.shiftKey?3:1;S(()=>b(l))}),a.addEventListener("touchstart",()=>S(b)),["mouseup","mouseleave","mouseout","touchend","touchcancel"].forEach(c=>{a.addEventListener(c,$)}),a.addEventListener("click",c=>{const l=c.shiftKey?3:1;f===null&&b(l)}),t.addEventListener("click",c=>{const l=c.shiftKey?3:1;f===null&&g(l)}),t.addEventListener("mousedown",c=>{const l=c.shiftKey?3:1;S(()=>g(l),100)}),t.addEventListener("touchstart",()=>S(g,100)),["mouseup","mouseleave","mouseout","touchend","touchcancel"].forEach(c=>{t.addEventListener(c,$)}),s.addEventListener("keydown",c=>{const l=c.key,M=c.shiftKey?3:1;if(["Backspace","Delete","ArrowLeft","ArrowRight","Tab","Enter","Home","End"].includes(l)||(c.ctrlKey||c.metaKey)&&["a","c","v","x"].includes(l.toLowerCase()))return;if(["e","+","-"].includes(l)){c.preventDefault();return}if(l==="ArrowUp"||l==="ArrowDown"){c.preventDefault();const F=parseFloat(s.value)||0,C=1*M/Math.pow(10,r);let L=l==="ArrowUp"?F+C:F-C;L<d&&(L=d),s.value=L.toFixed(r),Number(s.value)<d&&(s.value=d.toFixed(r)),Number(s.value)>n&&n!==0&&(s.value=n.toFixed(r)),A(this,m).call(this,Number(s.value),t,a,d,n),v(s.value);return}const N=l===","?".":l,U=/^[0-9]$/.test(N),q=N===".",V=s.value.includes(".");(r===0&&!U||r>0&&!(U||q)||q&&V)&&c.preventDefault()}),s.addEventListener("change",()=>{Number(s.value)<d&&(s.value=d.toFixed(r)),Number(s.value)>n&&n!==0?s.value=n.toFixed(r):s.value=Number(s.value).toFixed(r),A(this,m).call(this,Number(s.value),t,a,d,n)})})};class h{constructor(e={}){x(this,E);p(this,"selectors");p(this,"main");const i={main:"UIsw",label:"UIsw-label"};this.selectors={...i,...e},this.main=document.querySelectorAll(`.${this.selectors.main}`),I(this,E,P).call(this)}}E=new WeakSet,P=function(){this.main.forEach(e=>{const i=e.querySelector(`.${this.selectors.label}`),t=e.querySelector("input");i&&i.id&&e.setAttribute("aria-labelledby",i.id),t&&(t.checked?e.setAttribute("aria-checked","true"):e.setAttribute("aria-checked","false"),e.addEventListener("click",()=>{t.checked=!t.checked,e.setAttribute("aria-checked",String(t.checked))}),e.addEventListener("keydown",s=>{s.key==="ArrowRight"?(t.checked=!0,a(String(t.checked)),s.preventDefault()):s.key==="ArrowLeft"&&(t.checked=!1,a(String(t.checked)),s.preventDefault())}));const a=s=>{e.setAttribute("aria-checked",String(s))}})};class y{constructor(e={}){p(this,"selectors");p(this,"main");const i={idPrefix:"UI-option-",main:"UIselect",selected:"UIselect-selected",arrow:"UIselect-arrow",optionsList:"UIselect-options",excludedItems:["divider","test"]};this.selectors={...i,...e},this.main=document.querySelectorAll(`.${this.selectors.main}`),this.event(),y.initGlobalListener(this.selectors)}filterExcluded(e,i){return Array.from(e).filter(t=>!i.some(a=>typeof a=="string"?t.classList.contains(a)||t.id===a:t===a))}event(){this.main.forEach(e=>{const i=e.querySelector(`.${this.selectors.main} input[type='hidden']`);try{if(!i)throw new Error('<input type="hidden" name="YouUniqueId">')}catch(n){return console.warn("Not found:",n.message)}const t=e.querySelector(`.${this.selectors.selected}`),a=e.querySelector(`.${this.selectors.arrow}`),s=e.querySelector(`.${this.selectors.optionsList}`);a&&a.addEventListener("click",()=>{this.toggle(e,s)}),t.addEventListener("click",()=>{this.toggle(e,s)}),e.addEventListener("click",()=>{this.itemsPosition(e,s)});const r=s.querySelectorAll("li"),d=this.filterExcluded(r,this.selectors.excludedItems);this.itemArrow(e,s,d,t,i),this.items(e,s,d,t,i)})}itemArrow(e,i,t,a,s){let r=-1;const d=a.textContent?a.textContent:"";e.addEventListener("keydown",n=>{const v=t.length;if(n.key==="ArrowDown"){n.preventDefault(),e.getAttribute("aria-expanded")==="false"&&this.toggle(e,i),r=(r+1)%v,a.textContent=t[r].textContent,t.forEach(b=>b.removeAttribute("aria-selected")),t[r].setAttribute("aria-selected","true");const f=t[r].id||`${this.selectors.idPrefix}${r}`;e.setAttribute("aria-activedescendant",f),t[r].scrollIntoView({block:"nearest"})}else if(n.key==="ArrowUp"){n.preventDefault(),r=(r-1+v)%v,a.textContent=t[r].textContent,t.forEach(b=>b.removeAttribute("aria-selected")),t[r].setAttribute("aria-selected","true");const f=t[r].id||`${this.selectors.idPrefix}${r}`;e.setAttribute("aria-activedescendant",f),t[r].scrollIntoView({block:"nearest"})}else if(n.key==="Enter"||n.key===" ")if(n.preventDefault(),r>=0){a.textContent=t[r].textContent,t.forEach(b=>b.removeAttribute("aria-selected")),t[r].setAttribute("aria-selected","true");const f=t[r].id||`${this.selectors.idPrefix}${r}`;e.setAttribute("aria-activedescendant",f),s.value=String(t[r].dataset.value),this.close(e,i)}else this.toggle(e,i);else n.key==="Escape"&&(e.getAttribute("aria-activedescendant")||(a.textContent=d),this.close(e,i))})}itemsPosition(e,i){const t=i.querySelector('[aria-selected="true"]');t&&t.scrollIntoView({block:"nearest"})}items(e,i,t,a,s){t.forEach((r,d)=>{r.addEventListener("click",()=>{const n=t[d];if(n){a.textContent=n.textContent,t.forEach(f=>f.removeAttribute("aria-selected")),n.setAttribute("aria-selected","true");const v=n.id||`${this.selectors.idPrefix}${d}`;e.setAttribute("aria-expanded","false"),e.setAttribute("aria-activedescendant",v),s.value=String(t[d].dataset.value),this.close(e,i)}})})}toggle(e,i){y.closeAll(this.selectors),i.hidden?(i.hidden=!1,e.setAttribute("aria-expanded","true")):this.close(e,i)}close(e,i){i.hidden=!0,e.setAttribute("aria-expanded","false")}static closeAll(e){document.querySelectorAll(`.${e.main}`).forEach(i=>{const t=i.querySelector(`.${e.optionsList}`);t.hidden=!0,i.setAttribute("aria-expanded","false")})}static initGlobalListener(e){window.__UIselectGlobalClickInitialized||(document.addEventListener("click",i=>{const t=i.target;[...document.querySelectorAll(`.${e.main}`)].some(s=>s.contains(t))||y.closeAll(e)}),window.__UIselectGlobalClickInitialized=!0)}}o.Select=y,o.SpinBox=u,o.Switch=h,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
1
+ (function(o,u){typeof exports=="object"&&typeof module<"u"?u(exports):typeof define=="function"&&define.amd?define(["exports"],u):(o=typeof globalThis<"u"?globalThis:o||self,u(o.UiElements={}))})(this,function(o){"use strict";var _=Object.defineProperty;var F=o=>{throw TypeError(o)};var z=(o,u,h)=>u in o?_(o,u,{enumerable:!0,configurable:!0,writable:!0,value:h}):o[u]=h;var A=(o,u,h)=>z(o,typeof u!="symbol"?u+"":u,h),B=(o,u,h)=>u.has(o)||F("Cannot "+h);var p=(o,u,h)=>(B(o,u,"read from private field"),h?h.call(o):u.get(o)),x=(o,u,h)=>u.has(o)?F("Cannot add the same private member more than once"):u instanceof WeakSet?u.add(o):u.set(o,h);var I=(o,u,h)=>(B(o,u,"access private method"),h);var m,w,E,K,k,P;class u{constructor(e={}){x(this,E);A(this,"selectors");A(this,"spinBoxes");x(this,m,(e,i,t,a=0,s=0)=>{e==a||e<a?(i.classList.add(this.selectors.disabledBtn),i.disabled=!0):(i.classList.remove(this.selectors.disabledBtn),i.disabled=!1),s!==0&&(e==s||e>s?(t.classList.add(this.selectors.disabledBtn),t.disabled=!0):(t.classList.remove(this.selectors.disabledBtn),t.disabled=!1))});x(this,w,(e,i)=>{const t=e.getAttribute(`data-${i}`);return t===null||t.trim()===""||isNaN(Number(t))?0:Number(t)});const i={main:"UIsp",btn:"UIsp__btn",input:"UIsp__input",disabledBtn:"disabled"};this.selectors={...i,...e},this.spinBoxes=document.querySelectorAll(`.${this.selectors.main}`),I(this,E,K).call(this)}}m=new WeakMap,w=new WeakMap,E=new WeakSet,K=function(){this.spinBoxes.forEach(e=>{const i=e.querySelectorAll(`.${this.selectors.btn}`),t=i[0],a=i[1],s=e.querySelector(`.${this.selectors.input}`),r=Number(e.dataset.step),d=Number(e.dataset.min),n=p(this,w).call(this,e,"max"),v=c=>{e.setAttribute("aria-valuenow",String(c)),e.setAttribute("aria-valuetext",`${c} items`)};Number(s.value)<=d&&(s.value=d.toFixed(r)),n!==0?(Number(s.value)>=n&&(s.value=n.toFixed(r)),n&&e.setAttribute("aria-valuemax",n.toFixed(r))):s.value=Number(s.value).toFixed(r),d&&e.setAttribute("aria-valuemin",d.toFixed(r)),p(this,m).call(this,Number(s.value),t,a,d,n),v(s.value);let f=null;const b=(c=1)=>{s.value=String(Math.abs(Number(s.value)));let l=parseFloat(s.value)||0;l=l+1*c/Math.pow(10,r),l>n&&n!==0&&(l=n),s.value=l.toFixed(r),p(this,m).call(this,Number(s.value),t,a,d,n),v(s.value)},g=(c=1)=>{s.value=String(Math.abs(Number(s.value)));let l=parseFloat(s.value)||0;l=l-1*c/Math.pow(10,r),l<d&&(l=d),s.value=l.toFixed(r),p(this,m).call(this,Number(s.value),t,a,d,n),v(s.value)},S=(c,l=150)=>{f===null&&(f=window.setInterval(c,l))},$=()=>{f!==null&&(clearInterval(f),f=null)};a.addEventListener("mousedown",c=>{const l=c.shiftKey?3:1;S(()=>b(l))}),a.addEventListener("touchstart",()=>S(b)),["mouseup","mouseleave","mouseout","touchend","touchcancel"].forEach(c=>{a.addEventListener(c,$)}),a.addEventListener("click",c=>{const l=c.shiftKey?3:1;f===null&&b(l)}),t.addEventListener("click",c=>{const l=c.shiftKey?3:1;f===null&&g(l)}),t.addEventListener("mousedown",c=>{const l=c.shiftKey?3:1;S(()=>g(l),100)}),t.addEventListener("touchstart",()=>S(g,100)),["mouseup","mouseleave","mouseout","touchend","touchcancel"].forEach(c=>{t.addEventListener(c,$)}),s.addEventListener("keydown",c=>{const l=c.key,M=c.shiftKey?3:1;if(["Backspace","Delete","ArrowLeft","ArrowRight","Tab","Enter","Home","End"].includes(l)||(c.ctrlKey||c.metaKey)&&["a","c","v","x"].includes(l.toLowerCase()))return;if(["e","+","-"].includes(l)){c.preventDefault();return}if(l==="ArrowUp"||l==="ArrowDown"){c.preventDefault();const U=parseFloat(s.value)||0,D=1*M/Math.pow(10,r);let L=l==="ArrowUp"?U+D:U-D;L<d&&(L=d),s.value=L.toFixed(r),Number(s.value)<d&&(s.value=d.toFixed(r)),Number(s.value)>n&&n!==0&&(s.value=n.toFixed(r)),p(this,m).call(this,Number(s.value),t,a,d,n),v(s.value);return}const N=l===","?".":l,q=/^[0-9]$/.test(N),C=N===".",V=s.value.includes(".");(r===0&&!q||r>0&&!(q||C)||C&&V)&&c.preventDefault()}),s.addEventListener("change",()=>{Number(s.value)<d&&(s.value=d.toFixed(r)),Number(s.value)>n&&n!==0?s.value=n.toFixed(r):s.value=Number(s.value).toFixed(r),p(this,m).call(this,Number(s.value),t,a,d,n)})})};class h{constructor(e={}){x(this,k);A(this,"selectors");A(this,"main");const i={main:"UIsw",label:"UIsw-label"};this.selectors={...i,...e},this.main=document.querySelectorAll(`.${this.selectors.main}`),I(this,k,P).call(this)}}k=new WeakSet,P=function(){this.main.forEach(e=>{const i=e.querySelector(`.${this.selectors.label}`),t=e.querySelector("input");i&&i.id&&e.setAttribute("aria-labelledby",i.id),t&&(t.checked?e.setAttribute("aria-checked","true"):e.setAttribute("aria-checked","false"),e.addEventListener("click",()=>{t.checked=!t.checked,e.setAttribute("aria-checked",String(t.checked))}),e.addEventListener("keydown",s=>{s.key==="ArrowRight"?(t.checked=!0,a(String(t.checked)),s.preventDefault()):s.key==="ArrowLeft"&&(t.checked=!1,a(String(t.checked)),s.preventDefault())}));const a=s=>{e.setAttribute("aria-checked",String(s))}})};class y{constructor(e={}){A(this,"selectors");A(this,"main");const i={idPrefix:"UI-option-",main:"UIselect",selected:"UIselect-selected",arrow:"UIselect-arrow",optionsList:"UIselect-options",excludedItems:["divider","test"]};this.selectors={...i,...e},this.main=document.querySelectorAll(`.${this.selectors.main}`),this.event(),y.initGlobalListener(this.selectors)}filterExcluded(e,i){return Array.from(e).filter(t=>!i.some(a=>typeof a=="string"?t.classList.contains(a)||t.id===a:t===a))}event(){this.main.forEach(e=>{const i=e.querySelector(`.${this.selectors.main} input[type='hidden']`);try{if(!i)throw new Error('<input type="hidden" name="YouUniqueId">')}catch(v){return console.warn("Not found:",v.message)}const t=e.querySelector(`.${this.selectors.selected}`),a=e.querySelector(`.${this.selectors.arrow}`),s=e.querySelector(`.${this.selectors.optionsList}`);a&&a.addEventListener("click",()=>{this.toggle(e,s)}),t.addEventListener("click",()=>{this.toggle(e,s)}),e.addEventListener("click",()=>{this.itemsPosition(s)});const r=s.querySelectorAll("li"),d=this.filterExcluded(r,this.selectors.excludedItems),n=e.querySelector("[aria-selected='true']");n&&this.defaultSelect(e,n,t,i),this.itemArrow(e,s,d,t,i),this.items(e,s,d,t,i)})}itemArrow(e,i,t,a,s){let r=-1;const d=a.textContent?a.textContent:"";e.addEventListener("keydown",n=>{const v=t.length;if(n.key==="ArrowDown"){n.preventDefault(),e.getAttribute("aria-expanded")==="false"&&this.toggle(e,i),r=(r+1)%v,a.textContent=t[r].textContent,t.forEach(b=>b.removeAttribute("aria-selected")),t[r].setAttribute("aria-selected","true");const f=t[r].id||`${this.selectors.idPrefix}${r}`;e.setAttribute("aria-activedescendant",f),t[r].scrollIntoView({block:"nearest"})}else if(n.key==="ArrowUp"){n.preventDefault(),r=(r-1+v)%v,a.textContent=t[r].textContent,t.forEach(b=>b.removeAttribute("aria-selected")),t[r].setAttribute("aria-selected","true");const f=t[r].id||`${this.selectors.idPrefix}${r}`;e.setAttribute("aria-activedescendant",f),t[r].scrollIntoView({block:"nearest"})}else if(n.key==="Enter"||n.key===" ")if(n.preventDefault(),r>=0){a.textContent=t[r].textContent,t.forEach(b=>b.removeAttribute("aria-selected")),t[r].setAttribute("aria-selected","true");const f=t[r].id||`${this.selectors.idPrefix}${r}`;e.setAttribute("aria-activedescendant",f),s.value=String(t[r].dataset.value),this.costomEvent(e,s.value),this.close(e,i)}else this.toggle(e,i);else n.key==="Escape"&&(e.getAttribute("aria-activedescendant")||(a.textContent=d),this.close(e,i))})}itemsPosition(e){const i=e.querySelector('[aria-selected="true"]');i&&i.scrollIntoView({block:"nearest"})}items(e,i,t,a,s){t.forEach((r,d)=>{r.addEventListener("click",()=>{const n=t[d];if(n){a.textContent=n.textContent,t.forEach(f=>f.removeAttribute("aria-selected")),n.setAttribute("aria-selected","true");const v=n.id||`${this.selectors.idPrefix}${d}`;e.setAttribute("aria-expanded","false"),e.setAttribute("aria-activedescendant",v),s.value=String(t[d].dataset.value),this.costomEvent(e,s.value),this.close(e,i)}})})}defaultSelect(e,i,t,a){i&&(a.setAttribute("value",i.dataset.value??""),t.textContent=i.textContent??"",e.setAttribute("aria-activedescendant",i.id||""))}costomEvent(e,i){e.dispatchEvent(new CustomEvent("change",{detail:{val:i},bubbles:!0}))}toggle(e,i){y.closeAll(this.selectors),i.hidden?(i.hidden=!1,e.setAttribute("aria-expanded","true")):this.close(e,i)}close(e,i){i.hidden=!0,e.setAttribute("aria-expanded","false")}static closeAll(e){document.querySelectorAll(`.${e.main}`).forEach(i=>{const t=i.querySelector(`.${e.optionsList}`);t.hidden=!0,i.setAttribute("aria-expanded","false")})}static initGlobalListener(e){window.__UIselectGlobalClickInitialized||(document.addEventListener("click",i=>{const t=i.target;[...document.querySelectorAll(`.${e.main}`)].some(s=>s.contains(t))||y.closeAll(e)}),window.__UIselectGlobalClickInitialized=!0)}}o.Select=y,o.SpinBox=u,o.Switch=h,Object.defineProperty(o,Symbol.toStringTag,{value:"Module"})});
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "author": "Andrii Popov",
3
3
  "name": "@popovandrii/ui-elements",
4
4
  "description": "User interface elements. Color scheme. Elements with complex logic Java Script. Contrasting UI elements.",
5
- "version": "0.0.13",
5
+ "version": "0.0.14",
6
6
  "license": "MIT",
7
7
  "keywords": [
8
8
  "spinbox",