@robin-rossow/vue-input-number 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2016 Kevin Ongko
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,8 @@
1
+ # vue-number-input
2
+
3
+ Input field component to display a formatted currency value based on [Vue](https://vuejs.org/).
4
+ This is rewrite for Vue 3 based on [vue-numeric](https://github.com/kevinongko/vue-numeric)
5
+
6
+ ## License
7
+
8
+ vue-number-input is open-sourced software licensed under the [MIT license](http://opensource.org/licenses/MIT)
@@ -0,0 +1,7 @@
1
+ import type { App } from 'vue';
2
+ import VueInputNumber from './components/VueInputNumber.vue';
3
+ declare const _default: {
4
+ install: (app: App) => void;
5
+ };
6
+ export default _default;
7
+ export { VueInputNumber };
@@ -0,0 +1,214 @@
1
+ import type { PropType as __PropType } from 'vue';
2
+ export interface Props {
3
+ modelValue: string | number;
4
+ allowClear?: boolean;
5
+ currency?: string;
6
+ max?: number;
7
+ min?: number;
8
+ minus?: boolean;
9
+ placeholder?: string;
10
+ emptyValue?: number | string;
11
+ precision?: number;
12
+ separator?: string;
13
+ thousandSeparator?: string | undefined;
14
+ decimalSeparator?: string | undefined;
15
+ outputType: 'Number' | 'String';
16
+ readOnly?: boolean;
17
+ readOnlyClass?: string;
18
+ disabled?: boolean;
19
+ currencySymbolPosition?: 'prefix' | 'suffix';
20
+ }
21
+ declare const _sfc_main: import("vue").DefineComponent<{
22
+ modelValue: {
23
+ type: __PropType<string | number>;
24
+ required: true;
25
+ };
26
+ allowClear: {
27
+ type: __PropType<boolean>;
28
+ required: false;
29
+ default: boolean;
30
+ };
31
+ currency: {
32
+ type: __PropType<string>;
33
+ required: false;
34
+ default: string;
35
+ };
36
+ max: {
37
+ type: __PropType<number>;
38
+ required: false;
39
+ default: number;
40
+ };
41
+ min: {
42
+ type: __PropType<number>;
43
+ required: false;
44
+ default: number;
45
+ };
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
+ precision: {
62
+ type: __PropType<number>;
63
+ required: false;
64
+ default: number;
65
+ };
66
+ separator: {
67
+ type: __PropType<string>;
68
+ required: false;
69
+ default: string;
70
+ };
71
+ thousandSeparator: {
72
+ type: __PropType<string>;
73
+ required: false;
74
+ default: any;
75
+ };
76
+ decimalSeparator: {
77
+ type: __PropType<string>;
78
+ required: false;
79
+ default: any;
80
+ };
81
+ outputType: {
82
+ type: __PropType<"Number" | "String">;
83
+ required: true;
84
+ default: string;
85
+ };
86
+ readOnly: {
87
+ type: __PropType<boolean>;
88
+ required: false;
89
+ default: boolean;
90
+ };
91
+ readOnlyClass: {
92
+ type: __PropType<string>;
93
+ required: false;
94
+ default: string;
95
+ };
96
+ disabled: {
97
+ type: __PropType<boolean>;
98
+ required: false;
99
+ default: boolean;
100
+ };
101
+ currencySymbolPosition: {
102
+ type: __PropType<"prefix" | "suffix">;
103
+ required: false;
104
+ default: string;
105
+ };
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<{
107
+ modelValue: {
108
+ type: __PropType<string | number>;
109
+ required: true;
110
+ };
111
+ allowClear: {
112
+ type: __PropType<boolean>;
113
+ required: false;
114
+ default: boolean;
115
+ };
116
+ currency: {
117
+ type: __PropType<string>;
118
+ required: false;
119
+ default: string;
120
+ };
121
+ max: {
122
+ type: __PropType<number>;
123
+ required: false;
124
+ default: number;
125
+ };
126
+ min: {
127
+ type: __PropType<number>;
128
+ required: false;
129
+ default: number;
130
+ };
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
+ precision: {
147
+ type: __PropType<number>;
148
+ required: false;
149
+ default: number;
150
+ };
151
+ separator: {
152
+ type: __PropType<string>;
153
+ required: false;
154
+ default: string;
155
+ };
156
+ thousandSeparator: {
157
+ type: __PropType<string>;
158
+ required: false;
159
+ default: any;
160
+ };
161
+ decimalSeparator: {
162
+ type: __PropType<string>;
163
+ required: false;
164
+ default: any;
165
+ };
166
+ outputType: {
167
+ type: __PropType<"Number" | "String">;
168
+ required: true;
169
+ default: string;
170
+ };
171
+ readOnly: {
172
+ type: __PropType<boolean>;
173
+ required: false;
174
+ default: boolean;
175
+ };
176
+ readOnlyClass: {
177
+ type: __PropType<string>;
178
+ required: false;
179
+ default: string;
180
+ };
181
+ disabled: {
182
+ type: __PropType<boolean>;
183
+ required: false;
184
+ default: boolean;
185
+ };
186
+ currencySymbolPosition: {
187
+ type: __PropType<"prefix" | "suffix">;
188
+ required: false;
189
+ default: string;
190
+ };
191
+ }>> & {
192
+ "onUpdate:modelValue"?: (...args: any[]) => any;
193
+ onChange?: (...args: any[]) => any;
194
+ onBlur?: (...args: any[]) => any;
195
+ onFocus?: (...args: any[]) => any;
196
+ }, {
197
+ allowClear: boolean;
198
+ currency: string;
199
+ max: number;
200
+ min: number;
201
+ minus: boolean;
202
+ placeholder: string;
203
+ emptyValue: string | number;
204
+ precision: number;
205
+ separator: string;
206
+ thousandSeparator: string;
207
+ decimalSeparator: string;
208
+ outputType: "Number" | "String";
209
+ readOnly: boolean;
210
+ readOnlyClass: string;
211
+ disabled: boolean;
212
+ currencySymbolPosition: "prefix" | "suffix";
213
+ }, {}>;
214
+ export default _sfc_main;
package/dist/index.cjs ADDED
@@ -0,0 +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}/*
2
+ object-assign
3
+ (c) Sindre Sorhus
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;
package/dist/index.js ADDED
@@ -0,0 +1,253 @@
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) {
3
+ return t && t.__esModule && Object.prototype.hasOwnProperty.call(t, "default") ? t.default : t;
4
+ }
5
+ /*
6
+ object-assign
7
+ (c) Sindre Sorhus
8
+ @license MIT
9
+ */
10
+ var N = Object.getOwnPropertySymbols, U = Object.prototype.hasOwnProperty, Z = Object.prototype.propertyIsEnumerable;
11
+ function q(t) {
12
+ if (t == null)
13
+ throw new TypeError("Object.assign cannot be called with null or undefined");
14
+ return Object(t);
15
+ }
16
+ function z() {
17
+ try {
18
+ if (!Object.assign)
19
+ return !1;
20
+ var t = new String("abc");
21
+ if (t[5] = "de", Object.getOwnPropertyNames(t)[0] === "5")
22
+ return !1;
23
+ for (var r = {}, e = 0; e < 10; e++)
24
+ r["_" + String.fromCharCode(e)] = e;
25
+ var o = Object.getOwnPropertyNames(r).map(function(s) {
26
+ return r[s];
27
+ });
28
+ if (o.join("") !== "0123456789")
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";
34
+ } catch {
35
+ return !1;
36
+ }
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]]);
47
+ }
48
+ }
49
+ return o;
50
+ };
51
+ const P = /* @__PURE__ */ w(R);
52
+ var G = function() {
53
+ if (typeof Symbol != "function" || typeof Object.getOwnPropertySymbols != "function")
54
+ return !1;
55
+ if (typeof Symbol.iterator == "symbol")
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]")
59
+ return !1;
60
+ var a = 42;
61
+ r[e] = a;
62
+ for (e in r)
63
+ return !1;
64
+ if (typeof Object.keys == "function" && Object.keys(r).length !== 0 || typeof Object.getOwnPropertyNames == "function" && Object.getOwnPropertyNames(r).length !== 0)
65
+ return !1;
66
+ var s = Object.getOwnPropertySymbols(r);
67
+ if (s.length !== 1 || s[0] !== e || !Object.prototype.propertyIsEnumerable.call(r, e))
68
+ return !1;
69
+ if (typeof Object.getOwnPropertyDescriptor == "function") {
70
+ var u = Object.getOwnPropertyDescriptor(r, e);
71
+ if (u.value !== a || u.enumerable !== !0)
72
+ return !1;
73
+ }
74
+ return !0;
75
+ }, X = G, L = function() {
76
+ return X() && !!Symbol.toStringTag;
77
+ }, J = String.prototype.valueOf, K = function(r) {
78
+ try {
79
+ return J.call(r), !0;
80
+ } catch {
81
+ return !1;
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;
85
+ };
86
+ const re = /* @__PURE__ */ w(ee);
87
+ function te(t) {
88
+ return re(t) && t.match("%v") ? {
89
+ pos: t,
90
+ neg: t.replace("-", "").replace("%v", "-%v"),
91
+ zero: t
92
+ } : t;
93
+ }
94
+ const p = {
95
+ symbol: "$",
96
+ // default currency symbol is '$'
97
+ format: "%s%v",
98
+ // controls output: %s = symbol, %v = value (can be object, see docs)
99
+ decimal: ".",
100
+ // decimal point separator
101
+ thousand: ",",
102
+ // thousands separator
103
+ precision: 2,
104
+ // decimal places
105
+ grouping: 3,
106
+ // digit grouping (not implemented yet)
107
+ stripZeros: !1,
108
+ // strip insignificant zeros from decimal part
109
+ fallback: 0
110
+ // value returned on unformat() failure
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;
115
+ }
116
+ function ae(t, r) {
117
+ return t = Math.round(Math.abs(t)), isNaN(t) ? r : t;
118
+ }
119
+ function O(t, r) {
120
+ r = ae(r, p.precision);
121
+ const e = Math.pow(10, r);
122
+ return (Math.round((t + 1e-8) * e) / e).toFixed(r);
123
+ }
124
+ function V(t, r = {}) {
125
+ if (Array.isArray(t))
126
+ return t.map((u) => V(u, r));
127
+ r = P(
128
+ {},
129
+ p,
130
+ r
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;
134
+ }
135
+ function v(t, r = {}) {
136
+ if (Array.isArray(t))
137
+ return t.map((a) => v(a, r));
138
+ r = P(
139
+ {},
140
+ p,
141
+ r
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));
146
+ }
147
+ function C(t, r = p.decimal, e = p.fallback) {
148
+ if (Array.isArray(t))
149
+ return t.map((m) => C(m, r, e));
150
+ if (typeof t == "number")
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;
154
+ }
155
+ const oe = ["placeholder", "disabled", "type"], ue = /* @__PURE__ */ k({
156
+ __name: "VueInputNumber",
157
+ props: {
158
+ modelValue: {},
159
+ allowClear: { type: Boolean, default: !1 },
160
+ currency: { default: "" },
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
+ 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" }
175
+ },
176
+ emits: ["update:modelValue", "change", "blur", "focus"],
177
+ 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);
187
+ }
188
+ function A(n) {
189
+ if (r("focus", n), typeof u.value == "string" && u.value === "")
190
+ return "";
191
+ a.value = v(u.value, {
192
+ symbol: "",
193
+ format: "%v",
194
+ thousand: "",
195
+ decimal: l.value,
196
+ precision: Number(e.precision)
197
+ });
198
+ }
199
+ function F() {
200
+ d(s.value);
201
+ }
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)));
204
+ }
205
+ function c(n) {
206
+ const i = O(n, e.precision), b = e.outputType.toLowerCase() === "string" ? i : Number(i);
207
+ r("update:modelValue", b);
208
+ }
209
+ function y(n) {
210
+ return typeof n == "string" && n === "" ? "" : v(n, {
211
+ symbol: e.currency,
212
+ format: E.value,
213
+ precision: Number(e.precision),
214
+ decimal: l.value,
215
+ thousand: m.value
216
+ });
217
+ }
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 !== "";
224
+ }
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));
244
+ }
245
+ }), le = {
246
+ install: (t) => {
247
+ t.component("VueInputNumber", ue);
248
+ }
249
+ };
250
+ export {
251
+ ue as VueInputNumber,
252
+ le as default
253
+ };
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@robin-rossow/vue-input-number",
3
+ "version": "0.0.1",
4
+ "type": "module",
5
+ "private": false,
6
+ "exports": {
7
+ ".": "./dist/index.js"
8
+ },
9
+ "license": "MIT",
10
+ "files": [
11
+ "dist"
12
+ ],
13
+ "scripts": {
14
+ "dev": "vite",
15
+ "build": "run-p type-check build-only",
16
+ "preview": "vite preview",
17
+ "test:unit": "vitest",
18
+ "build-only": "vite build",
19
+ "type-check": "vue-tsc --noEmit -p tsconfig.vitest.json --composite false",
20
+ "lint": "eslint . --ext .vue,.js,.jsx,.cjs,.mjs,.ts,.tsx,.cts,.mts --fix --ignore-path .gitignore"
21
+ },
22
+ "dependencies": {
23
+ "accounting-js": "^1.1.1",
24
+ "vite-plugin-dts": "^2.3.0",
25
+ "vue": "^3.3.2"
26
+ },
27
+ "devDependencies": {
28
+ "@rushstack/eslint-patch": "^1.2.0",
29
+ "@tsconfig/node18": "^2.0.1",
30
+ "@types/jsdom": "^21.1.1",
31
+ "@types/node": "^18.16.8",
32
+ "@vitejs/plugin-vue": "^4.2.3",
33
+ "@vue/eslint-config-typescript": "^11.0.3",
34
+ "@vue/test-utils": "^2.3.2",
35
+ "@vue/tsconfig": "^0.4.0",
36
+ "eslint": "^8.39.0",
37
+ "eslint-plugin-vue": "^9.11.0",
38
+ "jsdom": "^22.0.0",
39
+ "npm-run-all": "^4.1.5",
40
+ "typescript": "~5.0.4",
41
+ "vite": "^4.3.5",
42
+ "vitest": "^0.31.0",
43
+ "vue-tsc": "^1.6.4"
44
+ }
45
+ }