@robin-rossow/vue-input-number 1.0.2 → 1.0.3
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/components/VueInputNumber.vue.d.ts +1 -1
- package/dist/index.cjs +2 -2
- package/dist/index.js +37 -35
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const i=require("vue");function j(
|
|
1
|
+
"use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const i=require("vue");function j(t){return t&&t.__esModule&&Object.prototype.hasOwnProperty.call(t,"default")?t.default:t}/*
|
|
2
2
|
object-assign
|
|
3
3
|
(c) Sindre Sorhus
|
|
4
4
|
@license MIT
|
|
5
|
-
*/var O=Object.getOwnPropertySymbols,I=Object.prototype.hasOwnProperty,M=Object.prototype.propertyIsEnumerable;function A(
|
|
5
|
+
*/var O=Object.getOwnPropertySymbols,I=Object.prototype.hasOwnProperty,M=Object.prototype.propertyIsEnumerable;function A(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 n=Object.getOwnPropertyNames(r).map(function(u){return r[u]});if(n.join("")!=="0123456789")return!1;var a={};return"abcdefghijklmnopqrst".split("").forEach(function(u){a[u]=u}),Object.keys(Object.assign({},a)).join("")==="abcdefghijklmnopqrst"}catch{return!1}}var F=T()?Object.assign:function(t,r){for(var e,n=A(t),a,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){a=O(e);for(var s=0;s<a.length;s++)M.call(e,a[s])&&(n[a[s]]=e[a[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 r={},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 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 u=Object.getOwnPropertySymbols(r);if(u.length!==1||u[0]!==e||!Object.prototype.propertyIsEnumerable.call(r,e))return!1;if(typeof Object.getOwnPropertyDescriptor=="function"){var c=Object.getOwnPropertyDescriptor(r,e);if(c.value!==a||c.enumerable!==!0)return!1}return!0},x=k,$=function(){return x()&&!!Symbol.toStringTag},C=String.prototype.valueOf,D=function(r){try{return C.call(r),!0}catch{return!1}},B=Object.prototype.toString,U="[object String]",q=$(),H=function(r){return typeof r=="string"?!0:typeof r!="object"?!1:q?D(r):B.call(r)===U};const R=j(H);function Z(t){return R(t)&&t.match("%v")?{pos:t,neg:t.replace("-","").replace("%v","-%v"),zero:t}:t}const f={symbol:"$",format:"%s%v",decimal:".",thousand:",",precision:2,grouping:3,stripZeros:!1,fallback:0};function z(t,r){const e=t.split(r),n=e[0],a=e[1].replace(/0+$/,"");return a.length>0?n+r+a:n}function G(t,r){return t=Math.round(Math.abs(t)),isNaN(t)?r:t}function d(t,r){r=G(r,f.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(c=>N(c,r));r=S({},f,r);const e=t<0?"-":"",n=parseInt(d(Math.abs(t),r.precision),10)+"",a=n.length>3?n.length%3:0,u=e+(a?n.substr(0,a)+r.thousand:"")+n.substr(a).replace(/(\d{3})(?=\d)/g,"$1"+r.thousand)+(r.precision>0?r.decimal+d(Math.abs(t),r.precision).split(".")[1]:"");return r.stripZeros?z(u,r.decimal):u}function h(t,r={}){if(Array.isArray(t))return t.map(a=>h(a,r));r=S({},f,r);const e=Z(r.format);let n;return t>0?n=e.pos:t<0?n=e.neg:n=e.zero,n.replace("%s",r.symbol).replace("%v",N(Math.abs(t),r))}function w(t,r=f.decimal,e=f.fallback){if(Array.isArray(t))return t.map(p=>w(p,r,e));if(typeof t=="number")return t;const n=new RegExp("[^0-9-(-)-"+r+"]",["g"]),a=(""+t).replace(n,"").replace(r,".").replace(/\(([-]*\d*[^)]?\d+)\)/g,"-$1").replace(/\((.*)\)/,""),u=(a.match(/-/g)||2).length%2,c=parseFloat(a.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(t,{emit:r}){const e=t,n=i.ref(""),a=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,()=>{a.value||(m(s.value),n.value=b(s.value))});function _(o){a.value=!1,r("blur",o),n.value=b(s.value)}function V(o){if(a.value=!0,r("focus",o),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(o){if(typeof o=="string"&&o==="")r("update:modelValue",o);else{if(o=Number(o),o>=e.max){y(e.max);return}if(o<=e.min){y(e.min);return}if(o>e.min&&o<e.max){y(o);return}}}function y(o){const l=d(o,e.precision),g=e.outputType.toLowerCase()==="string"?l:Number(l);r("update:modelValue",g)}function b(o){return typeof o=="string"&&o===""?"":h(o,{symbol:e.currency,format:p.value,precision:Number(e.precision),decimal:e.decimalSeparator,thousand:e.thousandSeparator})}function v(o){if(o===void 0)return o;const l=typeof o=="string"&&o===""?e.emptyValue:o;return typeof l=="string"&&l===""?"":w(l,e.decimalSeparator)}return(o,l)=>i.withDirectives((i.openBlock(),i.createElementBlock("input",i.mergeProps(o.$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:t=>{t.component("VueInputNumber",P)}};exports.VueInputNumber=P;exports.default=X;
|
package/dist/index.js
CHANGED
|
@@ -27,23 +27,23 @@ function B() {
|
|
|
27
27
|
});
|
|
28
28
|
if (n.join("") !== "0123456789")
|
|
29
29
|
return !1;
|
|
30
|
-
var
|
|
30
|
+
var a = {};
|
|
31
31
|
return "abcdefghijklmnopqrst".split("").forEach(function(u) {
|
|
32
|
-
|
|
33
|
-
}), Object.keys(Object.assign({},
|
|
32
|
+
a[u] = u;
|
|
33
|
+
}), Object.keys(Object.assign({}, a)).join("") === "abcdefghijklmnopqrst";
|
|
34
34
|
} catch {
|
|
35
35
|
return !1;
|
|
36
36
|
}
|
|
37
37
|
}
|
|
38
38
|
var U = B() ? Object.assign : function(t, r) {
|
|
39
|
-
for (var e, n = D(t),
|
|
39
|
+
for (var e, n = D(t), a, u = 1; u < arguments.length; u++) {
|
|
40
40
|
e = Object(arguments[u]);
|
|
41
41
|
for (var i in e)
|
|
42
42
|
$.call(e, i) && (n[i] = e[i]);
|
|
43
43
|
if (j) {
|
|
44
|
-
|
|
45
|
-
for (var s = 0; s <
|
|
46
|
-
C.call(e,
|
|
44
|
+
a = j(e);
|
|
45
|
+
for (var s = 0; s < a.length; s++)
|
|
46
|
+
C.call(e, a[s]) && (n[a[s]] = e[a[s]]);
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
return n;
|
|
@@ -57,8 +57,8 @@ var H = function() {
|
|
|
57
57
|
var r = {}, e = Symbol("test"), n = Object(e);
|
|
58
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
|
|
61
|
-
r[e] =
|
|
60
|
+
var a = 42;
|
|
61
|
+
r[e] = a;
|
|
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)
|
|
@@ -68,7 +68,7 @@ var H = function() {
|
|
|
68
68
|
return !1;
|
|
69
69
|
if (typeof Object.getOwnPropertyDescriptor == "function") {
|
|
70
70
|
var i = Object.getOwnPropertyDescriptor(r, e);
|
|
71
|
-
if (i.value !==
|
|
71
|
+
if (i.value !== a || i.enumerable !== !0)
|
|
72
72
|
return !1;
|
|
73
73
|
}
|
|
74
74
|
return !0;
|
|
@@ -110,8 +110,8 @@ const l = {
|
|
|
110
110
|
// value returned on unformat() failure
|
|
111
111
|
};
|
|
112
112
|
function W(t, r) {
|
|
113
|
-
const e = t.split(r), n = e[0],
|
|
114
|
-
return
|
|
113
|
+
const e = t.split(r), n = e[0], a = e[1].replace(/0+$/, "");
|
|
114
|
+
return a.length > 0 ? n + r + a : n;
|
|
115
115
|
}
|
|
116
116
|
function Y(t, r) {
|
|
117
117
|
return t = Math.round(Math.abs(t)), isNaN(t) ? r : t;
|
|
@@ -129,12 +129,12 @@ function w(t, r = {}) {
|
|
|
129
129
|
l,
|
|
130
130
|
r
|
|
131
131
|
);
|
|
132
|
-
const e = t < 0 ? "-" : "", n = parseInt(h(Math.abs(t), r.precision), 10) + "",
|
|
132
|
+
const e = t < 0 ? "-" : "", n = parseInt(h(Math.abs(t), r.precision), 10) + "", a = n.length > 3 ? n.length % 3 : 0, u = e + (a ? n.substr(0, a) + r.thousand : "") + n.substr(a).replace(/(\d{3})(?=\d)/g, "$1" + r.thousand) + (r.precision > 0 ? r.decimal + h(Math.abs(t), r.precision).split(".")[1] : "");
|
|
133
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((
|
|
137
|
+
return t.map((a) => v(a, r));
|
|
138
138
|
r = N(
|
|
139
139
|
{},
|
|
140
140
|
l,
|
|
@@ -149,7 +149,7 @@ function P(t, r = l.decimal, e = l.fallback) {
|
|
|
149
149
|
return t.map((f) => P(f, r, e));
|
|
150
150
|
if (typeof t == "number")
|
|
151
151
|
return t;
|
|
152
|
-
const n = new RegExp("[^0-9-(-)-" + r + "]", ["g"]),
|
|
152
|
+
const n = new RegExp("[^0-9-(-)-" + r + "]", ["g"]), a = ("" + t).replace(n, "").replace(r, ".").replace(/\(([-]*\d*[^)]?\d+)\)/g, "-$1").replace(/\((.*)\)/, ""), u = (a.match(/-/g) || 2).length % 2, i = parseFloat(a.replace(/-/g, "")), s = i * (u ? -1 : 1);
|
|
153
153
|
return isNaN(s) ? e : s;
|
|
154
154
|
}
|
|
155
155
|
const ee = ["value"], re = /* @__PURE__ */ I({
|
|
@@ -168,15 +168,15 @@ const ee = ["value"], re = /* @__PURE__ */ I({
|
|
|
168
168
|
},
|
|
169
169
|
emits: ["update:modelValue", "blur", "focus"],
|
|
170
170
|
setup(t, { emit: r }) {
|
|
171
|
-
const e = t, n = g(""),
|
|
171
|
+
const e = t, n = g(""), a = 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
172
|
p(s.value), n.value = y(s.value), M(e, () => {
|
|
173
|
-
|
|
173
|
+
a.value || (p(s.value), n.value = y(s.value));
|
|
174
174
|
});
|
|
175
|
-
function V(
|
|
176
|
-
|
|
175
|
+
function V(o) {
|
|
176
|
+
a.value = !1, r("blur", o), n.value = y(s.value);
|
|
177
177
|
}
|
|
178
|
-
function E(
|
|
179
|
-
if (
|
|
178
|
+
function E(o) {
|
|
179
|
+
if (a.value = !0, r("focus", o), typeof s.value == "string" && s.value === "")
|
|
180
180
|
return "";
|
|
181
181
|
n.value = v(s.value, {
|
|
182
182
|
symbol: "",
|
|
@@ -189,30 +189,30 @@ const ee = ["value"], re = /* @__PURE__ */ I({
|
|
|
189
189
|
function _() {
|
|
190
190
|
p(i.value);
|
|
191
191
|
}
|
|
192
|
-
function p(
|
|
193
|
-
if (typeof
|
|
194
|
-
r("update:modelValue",
|
|
192
|
+
function p(o) {
|
|
193
|
+
if (typeof o == "string" && o === "")
|
|
194
|
+
r("update:modelValue", o);
|
|
195
195
|
else {
|
|
196
|
-
if (
|
|
196
|
+
if (o = Number(o), o >= e.max) {
|
|
197
197
|
m(e.max);
|
|
198
198
|
return;
|
|
199
199
|
}
|
|
200
|
-
if (
|
|
200
|
+
if (o <= e.min) {
|
|
201
201
|
m(e.min);
|
|
202
202
|
return;
|
|
203
203
|
}
|
|
204
|
-
if (
|
|
205
|
-
m(
|
|
204
|
+
if (o > e.min && o < e.max) {
|
|
205
|
+
m(o);
|
|
206
206
|
return;
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
209
|
}
|
|
210
|
-
function m(
|
|
211
|
-
const c = h(
|
|
210
|
+
function m(o) {
|
|
211
|
+
const c = h(o, e.precision), b = e.outputType.toLowerCase() === "string" ? c : Number(c);
|
|
212
212
|
r("update:modelValue", b);
|
|
213
213
|
}
|
|
214
|
-
function y(
|
|
215
|
-
return typeof
|
|
214
|
+
function y(o) {
|
|
215
|
+
return typeof o == "string" && o === "" ? "" : v(o, {
|
|
216
216
|
symbol: e.currency,
|
|
217
217
|
format: f.value,
|
|
218
218
|
precision: Number(e.precision),
|
|
@@ -220,11 +220,13 @@ const ee = ["value"], re = /* @__PURE__ */ I({
|
|
|
220
220
|
thousand: e.thousandSeparator
|
|
221
221
|
});
|
|
222
222
|
}
|
|
223
|
-
function O(
|
|
224
|
-
|
|
223
|
+
function O(o) {
|
|
224
|
+
if (o === void 0)
|
|
225
|
+
return o;
|
|
226
|
+
const c = typeof o == "string" && o === "" ? e.emptyValue : o;
|
|
225
227
|
return typeof c == "string" && c === "" ? "" : P(c, e.decimalSeparator);
|
|
226
228
|
}
|
|
227
|
-
return (
|
|
229
|
+
return (o, c) => A((F(), T("input", k(o.$attrs, {
|
|
228
230
|
ref_key: "inputElement",
|
|
229
231
|
ref: u,
|
|
230
232
|
"onUpdate:modelValue": c[0] || (c[0] = (b) => n.value = b),
|