numora 1.0.3 → 1.0.4

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/index.d.ts CHANGED
@@ -1 +1,4 @@
1
1
  export * from './NumericInput';
2
+ export * from './utils/event-handlers';
3
+ export * from './utils/sanitization';
4
+ export * from './utils/decimals';
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- "use strict";var b=Object.defineProperty;var E=(t,e,n)=>e in t?b(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var l=(t,e,n)=>E(t,typeof e!="symbol"?e+"":e,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const C=t=>t.replace(/[^0-9.]/g,""),D=t=>t.replace(/(\..*?)\./g,"$1"),p=t=>D(C(t)),f=t=>t.replace(/,/g,"."),L=t=>[".",","].some(n=>t.key===n&&t.target&&t.target.value.includes(".")),o=(t,e)=>{const[n,s]=t.split(".");return s?`${n}.${s.slice(0,e)}`:t};function y(t,e){const n=t.target;n.value=f(n.value),n.value=p(n.value),n.value=o(n.value,e)}function I(t){L(t)&&t.preventDefault()}function A(t,e){var m;const n=t.target,{value:s,selectionStart:i,selectionEnd:g}=n,r=p(((m=t.clipboardData)==null?void 0:m.getData("text/plain"))||""),c=s.slice(0,i||0)+r+s.slice(g||0),[v,...h]=c.split("."),a=v+(h.length>0?"."+h.join(""):"");t.preventDefault(),n.value=o(a,e);const u=(i||0)+r.length-(c.length-a.length);return n.setSelectionRange(u,u),o(a,e)}const d=2;class N{constructor(e,{maxDecimals:n=d,onChange:s,...i}){l(this,"element");l(this,"options");this.options={maxDecimals:n,onChange:s,...i},this.createInputElement(e),this.setupEventListeners()}createInputElement(e){this.element=document.createElement("input"),this.element.setAttribute("minlength","1"),this.element.setAttribute("pattern","^[0-9]*[.,]?[0-9]*$"),this.element.setAttribute("spellcheck","false"),this.element.setAttribute("type","text"),this.element.setAttribute("inputmode","decimal");const{maxDecimals:n,onChange:s,...i}=this.options;Object.assign(this.element,i),e.appendChild(this.element)}setupEventListeners(){this.element.addEventListener("input",this.handleChange.bind(this)),this.element.addEventListener("keydown",this.handleKeyDown.bind(this)),this.element.addEventListener("paste",this.handlePaste.bind(this))}handleChange(e){y(e,this.options.maxDecimals||d),this.options.onChange&&this.options.onChange(e.target.value)}handleKeyDown(e){I(e)}handlePaste(e){A(e,this.options.maxDecimals),this.options.onChange&&this.options.onChange(e.target.value)}getValue(){return this.element.value}setValue(e){this.element.value=e}disable(){this.element.disabled=!0}enable(){this.element.disabled=!1}addEventListener(e,n){this.element.addEventListener(e,n)}removeEventListener(e,n){this.element.removeEventListener(e,n)}}exports.NumericInput=N;
1
+ "use strict";var N=Object.defineProperty;var f=(t,e,n)=>e in t?N(t,e,{enumerable:!0,configurable:!0,writable:!0,value:n}):t[e]=n;var r=(t,e,n)=>f(t,typeof e!="symbol"?e+"":e,n);Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"});const y=t=>t.replace(/[^0-9.]/g,""),L=t=>t.replace(/(\..*?)\./g,"$1"),o=t=>L(y(t)),g=t=>t.replace(/,/g,"."),v=t=>[".",","].some(n=>t.key===n&&t.target&&t.target.value.includes(".")),a=(t,e)=>{const[n,i]=t.split(".");return i?`${n}.${i.slice(0,e)}`:t};function D(t,e){const n=t.target;n.value=g(n.value),n.value=o(n.value),n.value=a(n.value,e)}function b(t){v(t)&&t.preventDefault()}function C(t,e){var d;const n=t.target,{value:i,selectionStart:s,selectionEnd:E}=n,c=o(((d=t.clipboardData)==null?void 0:d.getData("text/plain"))||""),u=i.slice(0,s||0)+c+i.slice(E||0),[I,...h]=u.split("."),l=I+(h.length>0?"."+h.join(""):"");t.preventDefault(),n.value=a(l,e);const m=(s||0)+c.length-(u.length-l.length);return n.setSelectionRange(m,m),a(l,e)}const p=2;class A{constructor(e,{maxDecimals:n=p,onChange:i,...s}){r(this,"element");r(this,"options");this.options={maxDecimals:n,onChange:i,...s},this.createInputElement(e),this.setupEventListeners()}createInputElement(e){this.element=document.createElement("input"),this.element.setAttribute("minlength","1"),this.element.setAttribute("pattern","^[0-9]*[.,]?[0-9]*$"),this.element.setAttribute("spellcheck","false"),this.element.setAttribute("type","text"),this.element.setAttribute("inputmode","decimal");const{maxDecimals:n,onChange:i,...s}=this.options;Object.assign(this.element,s),e.appendChild(this.element)}setupEventListeners(){this.element.addEventListener("input",this.handleChange.bind(this)),this.element.addEventListener("keydown",this.handleKeyDown.bind(this)),this.element.addEventListener("paste",this.handlePaste.bind(this))}handleChange(e){D(e,this.options.maxDecimals||p),this.options.onChange&&this.options.onChange(e.target.value)}handleKeyDown(e){b(e)}handlePaste(e){C(e,this.options.maxDecimals),this.options.onChange&&this.options.onChange(e.target.value)}getValue(){return this.element.value}setValue(e){this.element.value=e}disable(){this.element.disabled=!0}enable(){this.element.disabled=!1}addEventListener(e,n){this.element.addEventListener(e,n)}removeEventListener(e,n){this.element.removeEventListener(e,n)}}exports.NumericInput=A;exports.alreadyHasDecimal=v;exports.handleOnChangeNumericInput=D;exports.handleOnKeyDownNumericInput=b;exports.handleOnPasteNumericInput=C;exports.replaceCommasWithDots=g;exports.sanitizeNumericInput=o;exports.trimToMaxDecimals=a;
package/dist/index.mjs CHANGED
@@ -69,5 +69,12 @@ class N {
69
69
  }
70
70
  }
71
71
  export {
72
- N as NumericInput
72
+ N as NumericInput,
73
+ f as alreadyHasDecimal,
74
+ A as handleOnChangeNumericInput,
75
+ I as handleOnKeyDownNumericInput,
76
+ x as handleOnPasteNumericInput,
77
+ L as replaceCommasWithDots,
78
+ p as sanitizeNumericInput,
79
+ o as trimToMaxDecimals
73
80
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "numora",
3
- "version": "1.0.3",
3
+ "version": "1.0.4",
4
4
  "description": "Framework-agnostic headless finance input library",
5
5
  "homepage": "https://numora.netlify.app/",
6
6
  "main": "dist/index.js",
@@ -10,9 +10,9 @@
10
10
  ],
11
11
  "exports": {
12
12
  ".": {
13
+ "types": "./dist/index.d.ts",
13
14
  "import": "./dist/index.mjs",
14
- "require": "./dist/index.js",
15
- "types": "./dist/index.d.ts"
15
+ "require": "./dist/index.js"
16
16
  }
17
17
  },
18
18
  "repository": {