@robin-rossow/vue-input-number 0.0.2 → 0.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.cjs CHANGED
@@ -1,5 +1,5 @@
1
- "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const l=require("vue");function S(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}/*
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const i=require("vue");function j(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}/*
2
2
  object-assign
3
3
  (c) Sindre Sorhus
4
4
  @license MIT
5
- */var O=Object.getOwnPropertySymbols,A=Object.prototype.hasOwnProperty,B=Object.prototype.propertyIsEnumerable;function F(t){if(t==null)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(t)}function T(){try{if(!Object.assign)return!1;var t=new String("abc");if(t[5]="de",Object.getOwnPropertyNames(t)[0]==="5")return!1;for(var r={},e=0;e<10;e++)r["_"+String.fromCharCode(e)]=e;var o=Object.getOwnPropertyNames(r).map(function(s){return r[s]});if(o.join("")!=="0123456789")return!1;var a={};return"abcdefghijklmnopqrst".split("").forEach(function(s){a[s]=s}),Object.keys(Object.assign({},a)).join("")==="abcdefghijklmnopqrst"}catch{return!1}}var _=T()?Object.assign:function(t,r){for(var e,o=F(t),a,s=1;s<arguments.length;s++){e=Object(arguments[s]);for(var u in e)A.call(e,u)&&(o[u]=e[u]);if(O){a=O(e);for(var i=0;i<a.length;i++)B.call(e,a[i])&&(o[a[i]]=e[a[i]])}}return o};const j=S(_);var D=function(){if(typeof Symbol!="function"||typeof Object.getOwnPropertySymbols!="function")return!1;if(typeof Symbol.iterator=="symbol")return!0;var r={},e=Symbol("test"),o=Object(e);if(typeof e=="string"||Object.prototype.toString.call(e)!=="[object Symbol]"||Object.prototype.toString.call(o)!=="[object Symbol]")return!1;var a=42;r[e]=a;for(e in r)return!1;if(typeof Object.keys=="function"&&Object.keys(r).length!==0||typeof Object.getOwnPropertyNames=="function"&&Object.getOwnPropertyNames(r).length!==0)return!1;var s=Object.getOwnPropertySymbols(r);if(s.length!==1||s[0]!==e||!Object.prototype.propertyIsEnumerable.call(r,e))return!1;if(typeof Object.getOwnPropertyDescriptor=="function"){var u=Object.getOwnPropertyDescriptor(r,e);if(u.value!==a||u.enumerable!==!0)return!1}return!0},$=D,q=function(){return $()&&!!Symbol.toStringTag},H=String.prototype.valueOf,U=function(r){try{return H.call(r),!0}catch{return!1}},Z=Object.prototype.toString,x="[object String]",z=q(),R=function(r){return typeof r=="string"?!0:typeof r!="object"?!1:z?U(r):Z.call(r)===x};const G=S(R);function X(t){return G(t)&&t.match("%v")?{pos:t,neg:t.replace("-","").replace("%v","-%v"),zero:t}:t}const p={symbol:"$",format:"%s%v",decimal:".",thousand:",",precision:2,grouping:3,stripZeros:!1,fallback:0};function L(t,r){const e=t.split(r),o=e[0],a=e[1].replace(/0+$/,"");return a.length>0?o+r+a:o}function J(t,r){return t=Math.round(Math.abs(t)),isNaN(t)?r:t}function g(t,r){r=J(r,p.precision);const e=Math.pow(10,r);return(Math.round((t+1e-8)*e)/e).toFixed(r)}function N(t,r={}){if(Array.isArray(t))return t.map(u=>N(u,r));r=j({},p,r);const e=t<0?"-":"",o=parseInt(g(Math.abs(t),r.precision),10)+"",a=o.length>3?o.length%3:0,s=e+(a?o.substr(0,a)+r.thousand:"")+o.substr(a).replace(/(\d{3})(?=\d)/g,"$1"+r.thousand)+(r.precision>0?r.decimal+g(Math.abs(t),r.precision).split(".")[1]:"");return r.stripZeros?L(s,r.decimal):s}function h(t,r={}){if(Array.isArray(t))return t.map(a=>h(a,r));r=j({},p,r);const e=X(r.format);let o;return t>0?o=e.pos:t<0?o=e.neg:o=e.zero,o.replace("%s",r.symbol).replace("%v",N(Math.abs(t),r))}function w(t,r=p.decimal,e=p.fallback){if(Array.isArray(t))return t.map(m=>w(m,r,e));if(typeof t=="number")return t;const o=new RegExp("[^0-9-(-)-"+r+"]",["g"]),a=(""+t).replace(o,"").replace(r,".").replace(/\(([-]*\d*[^)]?\d+)\)/g,"-$1").replace(/\((.*)\)/,""),s=(a.match(/-/g)||2).length%2,u=parseFloat(a.replace(/-/g,"")),i=u*(s?-1:1);return isNaN(i)?e:i}const K=["placeholder","disabled","type"],P=l.defineComponent({__name:"VueInputNumber",props:{modelValue:{},allowClear:{type:Boolean,default:!1},currency:{default:""},max:{default:Number.MAX_SAFE_INTEGER},min:{default:Number.MAX_SAFE_INTEGER},minus:{type:Boolean,default:!1},placeholder:{default:""},emptyValue:{default:""},precision:{default:0},separator:{default:","},thousandSeparator:{default:void 0},decimalSeparator:{default:void 0},outputType:{default:"Number"},readOnly:{type:Boolean,default:!1},readOnlyClass:{default:""},disabled:{type:Boolean,default:!1},currencySymbolPosition:{default:"prefix"}},emits:["update:modelValue","change","blur","focus"],setup(t,{emit:r}){const e=t,o=defineModel({required:!0}),a=l.ref(""),s=l.computed(()=>v(a.value)),u=l.computed(()=>v(o.value)),i=l.computed(()=>typeof e.decimalSeparator<"u"?e.decimalSeparator:e.separator===","?".":","),m=l.computed(()=>typeof e.thousandSeparator<"u"?e.thousandSeparator:e.separator==="."?".":e.separator==="space"?" ":","),V=l.computed(()=>e.currency?e.currencySymbolPosition==="suffix"?"%v %s":"%s %v":"%v");(u.value||I())&&(d(u.value),a.value=y(u.value),setTimeout(()=>{d(u.value),a.value=y(u.value)},500));function C(n){r("change",n)}function E(n){r("blur",n),a.value=y(u.value)}function M(n){if(r("focus",n),typeof u.value=="string"&&u.value==="")return"";a.value=h(u.value,{symbol:"",format:"%v",thousand:"",decimal:i.value,precision:Number(e.precision)})}function k(){d(s.value)}function d(n){typeof n=="string"&&n===""?r("update:modelValue",n):(n=parseFloat(n+""),n>=e.max&&f(e.max),n<=e.min&&f(e.min),n>e.min&&n<e.max&&f(n),!e.minus&&n<0&&(e.min>=0?f(e.min):f(0)))}function f(n){const c=g(n,e.precision),b=e.outputType.toLowerCase()==="string"?c:Number(c);r("update:modelValue",b)}function y(n){return typeof n=="string"&&n===""?"":h(n,{symbol:e.currency,format:V.value,precision:Number(e.precision),decimal:i.value,thousand:m.value})}function v(n){const c=typeof n=="string"&&n===""?e.emptyValue:n;return typeof c=="string"&&c===""?"":w(c,i.value)}function I(){return u.value===0&&o.value!==""}return(n,c)=>(l.openBlock(),l.createElementBlock(l.Fragment,null,[n.readOnly?l.createCommentVNode("",!0):l.withDirectives((l.openBlock(),l.createElementBlock("input",{key:0,placeholder:n.placeholder,disabled:n.disabled,"onUpdate:modelValue":c[0]||(c[0]=b=>o.value=b),type:n.allowClear?"search":"tel",onBlur:E,onInput:k,onFocus:M,onChange:C},null,40,K)),[[l.vModelDynamic,o.value]]),n.readOnly?(l.openBlock(),l.createElementBlock("span",{key:1,class:l.normalizeClass({readOnlyClass:n.readOnlyClass})},l.toDisplayString(a.value),3)):l.createCommentVNode("",!0)],64))}}),Q={install:t=>{t.component("VueInputNumber",P)}};exports.VueInputNumber=P;exports.default=Q;
5
+ */var O=Object.getOwnPropertySymbols,I=Object.prototype.hasOwnProperty,M=Object.prototype.propertyIsEnumerable;function A(r){if(r==null)throw new TypeError("Object.assign cannot be called with null or undefined");return Object(r)}function T(){try{if(!Object.assign)return!1;var r=new String("abc");if(r[5]="de",Object.getOwnPropertyNames(r)[0]==="5")return!1;for(var t={},e=0;e<10;e++)t["_"+String.fromCharCode(e)]=e;var n=Object.getOwnPropertyNames(t).map(function(u){return t[u]});if(n.join("")!=="0123456789")return!1;var o={};return"abcdefghijklmnopqrst".split("").forEach(function(u){o[u]=u}),Object.keys(Object.assign({},o)).join("")==="abcdefghijklmnopqrst"}catch{return!1}}var F=T()?Object.assign:function(r,t){for(var e,n=A(r),o,u=1;u<arguments.length;u++){e=Object(arguments[u]);for(var c in e)I.call(e,c)&&(n[c]=e[c]);if(O){o=O(e);for(var s=0;s<o.length;s++)M.call(e,o[s])&&(n[o[s]]=e[o[s]])}}return n};const S=j(F);var k=function(){if(typeof Symbol!="function"||typeof Object.getOwnPropertySymbols!="function")return!1;if(typeof Symbol.iterator=="symbol")return!0;var t={},e=Symbol("test"),n=Object(e);if(typeof e=="string"||Object.prototype.toString.call(e)!=="[object Symbol]"||Object.prototype.toString.call(n)!=="[object Symbol]")return!1;var o=42;t[e]=o;for(e in t)return!1;if(typeof Object.keys=="function"&&Object.keys(t).length!==0||typeof Object.getOwnPropertyNames=="function"&&Object.getOwnPropertyNames(t).length!==0)return!1;var u=Object.getOwnPropertySymbols(t);if(u.length!==1||u[0]!==e||!Object.prototype.propertyIsEnumerable.call(t,e))return!1;if(typeof Object.getOwnPropertyDescriptor=="function"){var c=Object.getOwnPropertyDescriptor(t,e);if(c.value!==o||c.enumerable!==!0)return!1}return!0},x=k,$=function(){return x()&&!!Symbol.toStringTag},C=String.prototype.valueOf,D=function(t){try{return C.call(t),!0}catch{return!1}},B=Object.prototype.toString,U="[object String]",q=$(),H=function(t){return typeof t=="string"?!0:typeof t!="object"?!1:q?D(t):B.call(t)===U};const R=j(H);function Z(r){return R(r)&&r.match("%v")?{pos:r,neg:r.replace("-","").replace("%v","-%v"),zero:r}:r}const f={symbol:"$",format:"%s%v",decimal:".",thousand:",",precision:2,grouping:3,stripZeros:!1,fallback:0};function z(r,t){const e=r.split(t),n=e[0],o=e[1].replace(/0+$/,"");return o.length>0?n+t+o:n}function G(r,t){return r=Math.round(Math.abs(r)),isNaN(r)?t:r}function d(r,t){t=G(t,f.precision);const e=Math.pow(10,t);return(Math.round((r+1e-8)*e)/e).toFixed(t)}function N(r,t={}){if(Array.isArray(r))return r.map(c=>N(c,t));t=S({},f,t);const e=r<0?"-":"",n=parseInt(d(Math.abs(r),t.precision),10)+"",o=n.length>3?n.length%3:0,u=e+(o?n.substr(0,o)+t.thousand:"")+n.substr(o).replace(/(\d{3})(?=\d)/g,"$1"+t.thousand)+(t.precision>0?t.decimal+d(Math.abs(r),t.precision).split(".")[1]:"");return t.stripZeros?z(u,t.decimal):u}function h(r,t={}){if(Array.isArray(r))return r.map(o=>h(o,t));t=S({},f,t);const e=Z(t.format);let n;return r>0?n=e.pos:r<0?n=e.neg:n=e.zero,n.replace("%s",t.symbol).replace("%v",N(Math.abs(r),t))}function w(r,t=f.decimal,e=f.fallback){if(Array.isArray(r))return r.map(p=>w(p,t,e));if(typeof r=="number")return r;const n=new RegExp("[^0-9-(-)-"+t+"]",["g"]),o=(""+r).replace(n,"").replace(t,".").replace(/\(([-]*\d*[^)]?\d+)\)/g,"-$1").replace(/\((.*)\)/,""),u=(o.match(/-/g)||2).length%2,c=parseFloat(o.replace(/-/g,"")),s=c*(u?-1:1);return isNaN(s)?e:s}const L=["value"],P=i.defineComponent({__name:"VueInputNumber",props:{modelValue:{},outputType:{default:"Number"},min:{default:Number.MIN_SAFE_INTEGER},max:{default:Number.MAX_SAFE_INTEGER},precision:{default:0},thousandSeparator:{default:","},decimalSeparator:{default:"."},currency:{default:""},currencySymbolPosition:{default:"prefix"},emptyValue:{default:""}},emits:["update:modelValue","blur","focus"],setup(r,{emit:t}){const e=r,n=i.ref(""),o=i.ref(!1),u=i.ref(),c=i.computed(()=>v(n.value)),s=i.computed(()=>v(e.modelValue)),p=i.computed(()=>e.currency?e.currencySymbolPosition==="suffix"?"%v %s":"%s %v":"%v");m(s.value),n.value=b(s.value),i.watch(e,()=>{o.value||(m(s.value),n.value=b(s.value))});function _(a){o.value=!1,t("blur",a),n.value=b(s.value)}function V(a){if(o.value=!0,t("focus",a),typeof s.value=="string"&&s.value==="")return"";n.value=h(s.value,{symbol:"",format:"%v",thousand:"",decimal:e.decimalSeparator,precision:Number(e.precision)})}function E(){m(c.value)}function m(a){if(typeof a=="string"&&a==="")t("update:modelValue",a);else{if(a=Number(a),a>=e.max){y(e.max);return}if(a<=e.min){y(e.min);return}if(a>e.min&&a<e.max){y(a);return}}}function y(a){const l=d(a,e.precision),g=e.outputType.toLowerCase()==="string"?l:Number(l);t("update:modelValue",g)}function b(a){return typeof a=="string"&&a===""?"":h(a,{symbol:e.currency,format:p.value,precision:Number(e.precision),decimal:e.decimalSeparator,thousand:e.thousandSeparator})}function v(a){const l=typeof a=="string"&&a===""?e.emptyValue:a;return typeof l=="string"&&l===""?"":w(l,e.decimalSeparator)}return(a,l)=>i.withDirectives((i.openBlock(),i.createElementBlock("input",i.mergeProps(a.$attrs,{ref_key:"inputElement",ref:u,"onUpdate:modelValue":l[0]||(l[0]=g=>n.value=g),value:n.value,onBlur:_,onInput:E,onFocus:V}),null,16,L)),[[i.vModelDynamic,n.value]])}}),X={install:r=>{r.component("VueInputNumber",P)}};exports.VueInputNumber=P;exports.default=X;
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- import { defineComponent as k, ref as _, computed as f, openBlock as g, createElementBlock as h, Fragment as B, withDirectives as D, vModelDynamic as $, createCommentVNode as j, normalizeClass as x, toDisplayString as H } from "vue";
2
- function w(t) {
1
+ import { defineComponent as I, ref as g, computed as d, watch as M, withDirectives as A, openBlock as F, createElementBlock as T, mergeProps as k, vModelDynamic as x } from "vue";
2
+ function S(t) {
3
3
  return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
4
4
  }
5
5
  /*
@@ -7,13 +7,13 @@ object-assign
7
7
  (c) Sindre Sorhus
8
8
  @license MIT
9
9
  */
10
- var N = Object.getOwnPropertySymbols, U = Object.prototype.hasOwnProperty, Z = Object.prototype.propertyIsEnumerable;
11
- function q(t) {
10
+ var j = Object.getOwnPropertySymbols, $ = Object.prototype.hasOwnProperty, C = Object.prototype.propertyIsEnumerable;
11
+ function D(t) {
12
12
  if (t == null)
13
13
  throw new TypeError("Object.assign cannot be called with null or undefined");
14
14
  return Object(t);
15
15
  }
16
- function z() {
16
+ function B() {
17
17
  try {
18
18
  if (!Object.assign)
19
19
  return !1;
@@ -22,76 +22,76 @@ function z() {
22
22
  return !1;
23
23
  for (var r = {}, e = 0; e < 10; e++)
24
24
  r["_" + String.fromCharCode(e)] = e;
25
- var o = Object.getOwnPropertyNames(r).map(function(s) {
26
- return r[s];
25
+ var n = Object.getOwnPropertyNames(r).map(function(u) {
26
+ return r[u];
27
27
  });
28
- if (o.join("") !== "0123456789")
28
+ if (n.join("") !== "0123456789")
29
29
  return !1;
30
- var a = {};
31
- return "abcdefghijklmnopqrst".split("").forEach(function(s) {
32
- a[s] = s;
33
- }), Object.keys(Object.assign({}, a)).join("") === "abcdefghijklmnopqrst";
30
+ var o = {};
31
+ return "abcdefghijklmnopqrst".split("").forEach(function(u) {
32
+ o[u] = u;
33
+ }), Object.keys(Object.assign({}, o)).join("") === "abcdefghijklmnopqrst";
34
34
  } catch {
35
35
  return !1;
36
36
  }
37
37
  }
38
- var R = z() ? Object.assign : function(t, r) {
39
- for (var e, o = q(t), a, s = 1; s < arguments.length; s++) {
40
- e = Object(arguments[s]);
41
- for (var u in e)
42
- U.call(e, u) && (o[u] = e[u]);
43
- if (N) {
44
- a = N(e);
45
- for (var l = 0; l < a.length; l++)
46
- Z.call(e, a[l]) && (o[a[l]] = e[a[l]]);
38
+ var U = B() ? Object.assign : function(t, r) {
39
+ for (var e, n = D(t), o, u = 1; u < arguments.length; u++) {
40
+ e = Object(arguments[u]);
41
+ for (var i in e)
42
+ $.call(e, i) && (n[i] = e[i]);
43
+ if (j) {
44
+ o = j(e);
45
+ for (var s = 0; s < o.length; s++)
46
+ C.call(e, o[s]) && (n[o[s]] = e[o[s]]);
47
47
  }
48
48
  }
49
- return o;
49
+ return n;
50
50
  };
51
- const P = /* @__PURE__ */ w(R);
52
- var G = function() {
51
+ const N = /* @__PURE__ */ S(U);
52
+ var H = function() {
53
53
  if (typeof Symbol != "function" || typeof Object.getOwnPropertySymbols != "function")
54
54
  return !1;
55
55
  if (typeof Symbol.iterator == "symbol")
56
56
  return !0;
57
- var r = {}, e = Symbol("test"), o = Object(e);
58
- if (typeof e == "string" || Object.prototype.toString.call(e) !== "[object Symbol]" || Object.prototype.toString.call(o) !== "[object Symbol]")
57
+ var r = {}, e = Symbol("test"), n = Object(e);
58
+ if (typeof e == "string" || Object.prototype.toString.call(e) !== "[object Symbol]" || Object.prototype.toString.call(n) !== "[object Symbol]")
59
59
  return !1;
60
- var a = 42;
61
- r[e] = a;
60
+ var o = 42;
61
+ r[e] = o;
62
62
  for (e in r)
63
63
  return !1;
64
64
  if (typeof Object.keys == "function" && Object.keys(r).length !== 0 || typeof Object.getOwnPropertyNames == "function" && Object.getOwnPropertyNames(r).length !== 0)
65
65
  return !1;
66
- var s = Object.getOwnPropertySymbols(r);
67
- if (s.length !== 1 || s[0] !== e || !Object.prototype.propertyIsEnumerable.call(r, e))
66
+ var u = Object.getOwnPropertySymbols(r);
67
+ if (u.length !== 1 || u[0] !== e || !Object.prototype.propertyIsEnumerable.call(r, e))
68
68
  return !1;
69
69
  if (typeof Object.getOwnPropertyDescriptor == "function") {
70
- var u = Object.getOwnPropertyDescriptor(r, e);
71
- if (u.value !== a || u.enumerable !== !0)
70
+ var i = Object.getOwnPropertyDescriptor(r, e);
71
+ if (i.value !== o || i.enumerable !== !0)
72
72
  return !1;
73
73
  }
74
74
  return !0;
75
- }, X = G, L = function() {
76
- return X() && !!Symbol.toStringTag;
77
- }, J = String.prototype.valueOf, K = function(r) {
75
+ }, R = H, Z = function() {
76
+ return R() && !!Symbol.toStringTag;
77
+ }, q = String.prototype.valueOf, z = function(r) {
78
78
  try {
79
- return J.call(r), !0;
79
+ return q.call(r), !0;
80
80
  } catch {
81
81
  return !1;
82
82
  }
83
- }, Q = Object.prototype.toString, W = "[object String]", Y = L(), ee = function(r) {
84
- return typeof r == "string" ? !0 : typeof r != "object" ? !1 : Y ? K(r) : Q.call(r) === W;
83
+ }, G = Object.prototype.toString, L = "[object String]", X = Z(), J = function(r) {
84
+ return typeof r == "string" ? !0 : typeof r != "object" ? !1 : X ? z(r) : G.call(r) === L;
85
85
  };
86
- const re = /* @__PURE__ */ w(ee);
87
- function te(t) {
88
- return re(t) && t.match("%v") ? {
86
+ const K = /* @__PURE__ */ S(J);
87
+ function Q(t) {
88
+ return K(t) && t.match("%v") ? {
89
89
  pos: t,
90
90
  neg: t.replace("-", "").replace("%v", "-%v"),
91
91
  zero: t
92
92
  } : t;
93
93
  }
94
- const p = {
94
+ const l = {
95
95
  symbol: "$",
96
96
  // default currency symbol is '$'
97
97
  format: "%s%v",
@@ -109,145 +109,139 @@ const p = {
109
109
  fallback: 0
110
110
  // value returned on unformat() failure
111
111
  };
112
- function ne(t, r) {
113
- const e = t.split(r), o = e[0], a = e[1].replace(/0+$/, "");
114
- return a.length > 0 ? o + r + a : o;
112
+ function W(t, r) {
113
+ const e = t.split(r), n = e[0], o = e[1].replace(/0+$/, "");
114
+ return o.length > 0 ? n + r + o : n;
115
115
  }
116
- function ae(t, r) {
116
+ function Y(t, r) {
117
117
  return t = Math.round(Math.abs(t)), isNaN(t) ? r : t;
118
118
  }
119
- function O(t, r) {
120
- r = ae(r, p.precision);
119
+ function h(t, r) {
120
+ r = Y(r, l.precision);
121
121
  const e = Math.pow(10, r);
122
122
  return (Math.round((t + 1e-8) * e) / e).toFixed(r);
123
123
  }
124
- function V(t, r = {}) {
124
+ function w(t, r = {}) {
125
125
  if (Array.isArray(t))
126
- return t.map((u) => V(u, r));
127
- r = P(
126
+ return t.map((i) => w(i, r));
127
+ r = N(
128
128
  {},
129
- p,
129
+ l,
130
130
  r
131
131
  );
132
- const e = t < 0 ? "-" : "", o = parseInt(O(Math.abs(t), r.precision), 10) + "", a = o.length > 3 ? o.length % 3 : 0, s = e + (a ? o.substr(0, a) + r.thousand : "") + o.substr(a).replace(/(\d{3})(?=\d)/g, "$1" + r.thousand) + (r.precision > 0 ? r.decimal + O(Math.abs(t), r.precision).split(".")[1] : "");
133
- return r.stripZeros ? ne(s, r.decimal) : s;
132
+ const e = t < 0 ? "-" : "", n = parseInt(h(Math.abs(t), r.precision), 10) + "", o = n.length > 3 ? n.length % 3 : 0, u = e + (o ? n.substr(0, o) + r.thousand : "") + n.substr(o).replace(/(\d{3})(?=\d)/g, "$1" + r.thousand) + (r.precision > 0 ? r.decimal + h(Math.abs(t), r.precision).split(".")[1] : "");
133
+ return r.stripZeros ? W(u, r.decimal) : u;
134
134
  }
135
135
  function v(t, r = {}) {
136
136
  if (Array.isArray(t))
137
- return t.map((a) => v(a, r));
138
- r = P(
137
+ return t.map((o) => v(o, r));
138
+ r = N(
139
139
  {},
140
- p,
140
+ l,
141
141
  r
142
142
  );
143
- const e = te(r.format);
144
- let o;
145
- return t > 0 ? o = e.pos : t < 0 ? o = e.neg : o = e.zero, o.replace("%s", r.symbol).replace("%v", V(Math.abs(t), r));
143
+ const e = Q(r.format);
144
+ let n;
145
+ return t > 0 ? n = e.pos : t < 0 ? n = e.neg : n = e.zero, n.replace("%s", r.symbol).replace("%v", w(Math.abs(t), r));
146
146
  }
147
- function C(t, r = p.decimal, e = p.fallback) {
147
+ function P(t, r = l.decimal, e = l.fallback) {
148
148
  if (Array.isArray(t))
149
- return t.map((m) => C(m, r, e));
149
+ return t.map((f) => P(f, r, e));
150
150
  if (typeof t == "number")
151
151
  return t;
152
- const o = new RegExp("[^0-9-(-)-" + r + "]", ["g"]), a = ("" + t).replace(o, "").replace(r, ".").replace(/\(([-]*\d*[^)]?\d+)\)/g, "-$1").replace(/\((.*)\)/, ""), s = (a.match(/-/g) || 2).length % 2, u = parseFloat(a.replace(/-/g, "")), l = u * (s ? -1 : 1);
153
- return isNaN(l) ? e : l;
152
+ const n = new RegExp("[^0-9-(-)-" + r + "]", ["g"]), o = ("" + t).replace(n, "").replace(r, ".").replace(/\(([-]*\d*[^)]?\d+)\)/g, "-$1").replace(/\((.*)\)/, ""), u = (o.match(/-/g) || 2).length % 2, i = parseFloat(o.replace(/-/g, "")), s = i * (u ? -1 : 1);
153
+ return isNaN(s) ? e : s;
154
154
  }
155
- const oe = ["placeholder", "disabled", "type"], ue = /* @__PURE__ */ k({
155
+ const ee = ["value"], re = /* @__PURE__ */ I({
156
156
  __name: "VueInputNumber",
157
157
  props: {
158
158
  modelValue: {},
159
- allowClear: { type: Boolean, default: !1 },
160
- currency: { default: "" },
159
+ outputType: { default: "Number" },
160
+ min: { default: Number.MIN_SAFE_INTEGER },
161
161
  max: { default: Number.MAX_SAFE_INTEGER },
162
- min: { default: Number.MAX_SAFE_INTEGER },
163
- minus: { type: Boolean, default: !1 },
164
- placeholder: { default: "" },
165
- emptyValue: { default: "" },
166
162
  precision: { default: 0 },
167
- separator: { default: "," },
168
- thousandSeparator: { default: void 0 },
169
- decimalSeparator: { default: void 0 },
170
- outputType: { default: "Number" },
171
- readOnly: { type: Boolean, default: !1 },
172
- readOnlyClass: { default: "" },
173
- disabled: { type: Boolean, default: !1 },
174
- currencySymbolPosition: { default: "prefix" }
163
+ thousandSeparator: { default: "," },
164
+ decimalSeparator: { default: "." },
165
+ currency: { default: "" },
166
+ currencySymbolPosition: { default: "prefix" },
167
+ emptyValue: { default: "" }
175
168
  },
176
- emits: ["update:modelValue", "change", "blur", "focus"],
169
+ emits: ["update:modelValue", "blur", "focus"],
177
170
  setup(t, { emit: r }) {
178
- const e = t, o = defineModel({ required: !0 }), a = _(""), s = f(() => S(a.value)), u = f(() => S(o.value)), l = f(() => typeof e.decimalSeparator < "u" ? e.decimalSeparator : e.separator === "," ? "." : ","), m = f(() => typeof e.thousandSeparator < "u" ? e.thousandSeparator : e.separator === "." ? "." : e.separator === "space" ? " " : ","), E = f(() => e.currency ? e.currencySymbolPosition === "suffix" ? "%v %s" : "%s %v" : "%v");
179
- (u.value || T()) && (d(u.value), a.value = y(u.value), setTimeout(() => {
180
- d(u.value), a.value = y(u.value);
181
- }, 500));
182
- function I(n) {
183
- r("change", n);
184
- }
185
- function M(n) {
186
- r("blur", n), a.value = y(u.value);
171
+ const e = t, n = g(""), o = g(!1), u = g(), i = d(() => O(n.value)), s = d(() => O(e.modelValue)), f = d(() => e.currency ? e.currencySymbolPosition === "suffix" ? "%v %s" : "%s %v" : "%v");
172
+ p(s.value), n.value = y(s.value), M(e, () => {
173
+ o.value || (p(s.value), n.value = y(s.value));
174
+ });
175
+ function V(a) {
176
+ o.value = !1, r("blur", a), n.value = y(s.value);
187
177
  }
188
- function A(n) {
189
- if (r("focus", n), typeof u.value == "string" && u.value === "")
178
+ function E(a) {
179
+ if (o.value = !0, r("focus", a), typeof s.value == "string" && s.value === "")
190
180
  return "";
191
- a.value = v(u.value, {
181
+ n.value = v(s.value, {
192
182
  symbol: "",
193
183
  format: "%v",
194
184
  thousand: "",
195
- decimal: l.value,
185
+ decimal: e.decimalSeparator,
196
186
  precision: Number(e.precision)
197
187
  });
198
188
  }
199
- function F() {
200
- d(s.value);
189
+ function _() {
190
+ p(i.value);
201
191
  }
202
- function d(n) {
203
- typeof n == "string" && n === "" ? r("update:modelValue", n) : (n = parseFloat(n + ""), n >= e.max && c(e.max), n <= e.min && c(e.min), n > e.min && n < e.max && c(n), !e.minus && n < 0 && (e.min >= 0 ? c(e.min) : c(0)));
192
+ function p(a) {
193
+ if (typeof a == "string" && a === "")
194
+ r("update:modelValue", a);
195
+ else {
196
+ if (a = Number(a), a >= e.max) {
197
+ m(e.max);
198
+ return;
199
+ }
200
+ if (a <= e.min) {
201
+ m(e.min);
202
+ return;
203
+ }
204
+ if (a > e.min && a < e.max) {
205
+ m(a);
206
+ return;
207
+ }
208
+ }
204
209
  }
205
- function c(n) {
206
- const i = O(n, e.precision), b = e.outputType.toLowerCase() === "string" ? i : Number(i);
210
+ function m(a) {
211
+ const c = h(a, e.precision), b = e.outputType.toLowerCase() === "string" ? c : Number(c);
207
212
  r("update:modelValue", b);
208
213
  }
209
- function y(n) {
210
- return typeof n == "string" && n === "" ? "" : v(n, {
214
+ function y(a) {
215
+ return typeof a == "string" && a === "" ? "" : v(a, {
211
216
  symbol: e.currency,
212
- format: E.value,
217
+ format: f.value,
213
218
  precision: Number(e.precision),
214
- decimal: l.value,
215
- thousand: m.value
219
+ decimal: e.decimalSeparator,
220
+ thousand: e.thousandSeparator
216
221
  });
217
222
  }
218
- function S(n) {
219
- const i = typeof n == "string" && n === "" ? e.emptyValue : n;
220
- return typeof i == "string" && i === "" ? "" : C(i, l.value);
221
- }
222
- function T() {
223
- return u.value === 0 && o.value !== "";
223
+ function O(a) {
224
+ const c = typeof a == "string" && a === "" ? e.emptyValue : a;
225
+ return typeof c == "string" && c === "" ? "" : P(c, e.decimalSeparator);
224
226
  }
225
- return (n, i) => (g(), h(B, null, [
226
- n.readOnly ? j("", !0) : D((g(), h("input", {
227
- key: 0,
228
- placeholder: n.placeholder,
229
- disabled: n.disabled,
230
- "onUpdate:modelValue": i[0] || (i[0] = (b) => o.value = b),
231
- type: n.allowClear ? "search" : "tel",
232
- onBlur: M,
233
- onInput: F,
234
- onFocus: A,
235
- onChange: I
236
- }, null, 40, oe)), [
237
- [$, o.value]
238
- ]),
239
- n.readOnly ? (g(), h("span", {
240
- key: 1,
241
- class: x({ readOnlyClass: n.readOnlyClass })
242
- }, H(a.value), 3)) : j("", !0)
243
- ], 64));
227
+ return (a, c) => A((F(), T("input", k(a.$attrs, {
228
+ ref_key: "inputElement",
229
+ ref: u,
230
+ "onUpdate:modelValue": c[0] || (c[0] = (b) => n.value = b),
231
+ value: n.value,
232
+ onBlur: V,
233
+ onInput: _,
234
+ onFocus: E
235
+ }), null, 16, ee)), [
236
+ [x, n.value]
237
+ ]);
244
238
  }
245
- }), le = {
239
+ }), ne = {
246
240
  install: (t) => {
247
- t.component("VueInputNumber", ue);
241
+ t.component("VueInputNumber", re);
248
242
  }
249
243
  };
250
244
  export {
251
- ue as VueInputNumber,
252
- le as default
245
+ re as VueInputNumber,
246
+ ne as default
253
247
  };
@@ -1,214 +1,129 @@
1
1
  import type { PropType as __PropType } from 'vue';
2
2
  export interface Props {
3
3
  modelValue: string | number;
4
- allowClear?: boolean;
5
- currency?: string;
6
- max?: number;
4
+ outputType?: 'Number' | 'String';
7
5
  min?: number;
8
- minus?: boolean;
9
- placeholder?: string;
10
- emptyValue?: number | string;
6
+ max?: number;
11
7
  precision?: number;
12
- separator?: string;
13
8
  thousandSeparator?: string | undefined;
14
9
  decimalSeparator?: string | undefined;
15
- outputType: 'Number' | 'String';
16
- readOnly?: boolean;
17
- readOnlyClass?: string;
18
- disabled?: boolean;
10
+ currency?: string;
19
11
  currencySymbolPosition?: 'prefix' | 'suffix';
12
+ emptyValue?: number | '';
20
13
  }
21
14
  declare const _sfc_main: import("vue").DefineComponent<{
22
15
  modelValue: {
23
16
  type: __PropType<string | number>;
24
17
  required: true;
25
18
  };
26
- allowClear: {
27
- type: __PropType<boolean>;
28
- required: false;
29
- default: boolean;
30
- };
31
- currency: {
32
- type: __PropType<string>;
19
+ outputType: {
20
+ type: __PropType<"Number" | "String">;
33
21
  required: false;
34
22
  default: string;
35
23
  };
36
- max: {
24
+ min: {
37
25
  type: __PropType<number>;
38
26
  required: false;
39
27
  default: number;
40
28
  };
41
- min: {
29
+ max: {
42
30
  type: __PropType<number>;
43
31
  required: false;
44
32
  default: number;
45
33
  };
46
- minus: {
47
- type: __PropType<boolean>;
48
- required: false;
49
- default: boolean;
50
- };
51
- placeholder: {
52
- type: __PropType<string>;
53
- required: false;
54
- default: string;
55
- };
56
- emptyValue: {
57
- type: __PropType<string | number>;
58
- required: false;
59
- default: string;
60
- };
61
34
  precision: {
62
35
  type: __PropType<number>;
63
36
  required: false;
64
37
  default: number;
65
38
  };
66
- separator: {
67
- type: __PropType<string>;
68
- required: false;
69
- default: string;
70
- };
71
39
  thousandSeparator: {
72
40
  type: __PropType<string>;
73
41
  required: false;
74
- default: any;
42
+ default: string;
75
43
  };
76
44
  decimalSeparator: {
77
45
  type: __PropType<string>;
78
46
  required: false;
79
- default: any;
80
- };
81
- outputType: {
82
- type: __PropType<"Number" | "String">;
83
- required: true;
84
47
  default: string;
85
48
  };
86
- readOnly: {
87
- type: __PropType<boolean>;
88
- required: false;
89
- default: boolean;
90
- };
91
- readOnlyClass: {
49
+ currency: {
92
50
  type: __PropType<string>;
93
51
  required: false;
94
52
  default: string;
95
53
  };
96
- disabled: {
97
- type: __PropType<boolean>;
98
- required: false;
99
- default: boolean;
100
- };
101
54
  currencySymbolPosition: {
102
55
  type: __PropType<"prefix" | "suffix">;
103
56
  required: false;
104
57
  default: string;
105
58
  };
106
- }, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("update:modelValue" | "change" | "blur" | "focus")[], "update:modelValue" | "change" | "blur" | "focus", import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
59
+ emptyValue: {
60
+ type: __PropType<number | "">;
61
+ required: false;
62
+ default: string;
63
+ };
64
+ }, {}, unknown, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, ("update:modelValue" | "blur" | "focus")[], "update:modelValue" | "blur" | "focus", import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps, Readonly<import("vue").ExtractPropTypes<{
107
65
  modelValue: {
108
66
  type: __PropType<string | number>;
109
67
  required: true;
110
68
  };
111
- allowClear: {
112
- type: __PropType<boolean>;
113
- required: false;
114
- default: boolean;
115
- };
116
- currency: {
117
- type: __PropType<string>;
69
+ outputType: {
70
+ type: __PropType<"Number" | "String">;
118
71
  required: false;
119
72
  default: string;
120
73
  };
121
- max: {
74
+ min: {
122
75
  type: __PropType<number>;
123
76
  required: false;
124
77
  default: number;
125
78
  };
126
- min: {
79
+ max: {
127
80
  type: __PropType<number>;
128
81
  required: false;
129
82
  default: number;
130
83
  };
131
- minus: {
132
- type: __PropType<boolean>;
133
- required: false;
134
- default: boolean;
135
- };
136
- placeholder: {
137
- type: __PropType<string>;
138
- required: false;
139
- default: string;
140
- };
141
- emptyValue: {
142
- type: __PropType<string | number>;
143
- required: false;
144
- default: string;
145
- };
146
84
  precision: {
147
85
  type: __PropType<number>;
148
86
  required: false;
149
87
  default: number;
150
88
  };
151
- separator: {
152
- type: __PropType<string>;
153
- required: false;
154
- default: string;
155
- };
156
89
  thousandSeparator: {
157
90
  type: __PropType<string>;
158
91
  required: false;
159
- default: any;
92
+ default: string;
160
93
  };
161
94
  decimalSeparator: {
162
95
  type: __PropType<string>;
163
96
  required: false;
164
- default: any;
165
- };
166
- outputType: {
167
- type: __PropType<"Number" | "String">;
168
- required: true;
169
97
  default: string;
170
98
  };
171
- readOnly: {
172
- type: __PropType<boolean>;
173
- required: false;
174
- default: boolean;
175
- };
176
- readOnlyClass: {
99
+ currency: {
177
100
  type: __PropType<string>;
178
101
  required: false;
179
102
  default: string;
180
103
  };
181
- disabled: {
182
- type: __PropType<boolean>;
183
- required: false;
184
- default: boolean;
185
- };
186
104
  currencySymbolPosition: {
187
105
  type: __PropType<"prefix" | "suffix">;
188
106
  required: false;
189
107
  default: string;
190
108
  };
109
+ emptyValue: {
110
+ type: __PropType<number | "">;
111
+ required: false;
112
+ default: string;
113
+ };
191
114
  }>> & {
192
115
  "onUpdate:modelValue"?: (...args: any[]) => any;
193
- onChange?: (...args: any[]) => any;
194
116
  onBlur?: (...args: any[]) => any;
195
117
  onFocus?: (...args: any[]) => any;
196
118
  }, {
197
- allowClear: boolean;
198
- currency: string;
199
- max: number;
119
+ outputType: "Number" | "String";
200
120
  min: number;
201
- minus: boolean;
202
- placeholder: string;
203
- emptyValue: string | number;
121
+ max: number;
204
122
  precision: number;
205
- separator: string;
206
123
  thousandSeparator: string;
207
124
  decimalSeparator: string;
208
- outputType: "Number" | "String";
209
- readOnly: boolean;
210
- readOnlyClass: string;
211
- disabled: boolean;
125
+ currency: string;
212
126
  currencySymbolPosition: "prefix" | "suffix";
127
+ emptyValue: number | "";
213
128
  }, {}>;
214
129
  export default _sfc_main;
package/package.json CHANGED
@@ -1,12 +1,17 @@
1
1
  {
2
2
  "name": "@robin-rossow/vue-input-number",
3
- "version": "0.0.2",
3
+ "version": "0.0.4",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "exports": {
7
7
  ".": "./dist/index.js"
8
8
  },
9
+ "types": "./dist/VueInputNumberPlugin.d.ts",
9
10
  "license": "MIT",
11
+ "repository": {
12
+ "type": "git",
13
+ "url": "https://github.com/robinrossow/vue-input-number"
14
+ },
10
15
  "files": [
11
16
  "dist"
12
17
  ],