v-money3 3.25.0 → 3.26.0
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 +32 -0
- package/dist/component.vue.d.ts +9 -0
- package/dist/directive.d.ts +3 -3
- package/dist/options.d.ts +1 -0
- package/dist/v-money3.mjs +237 -187
- package/dist/v-money3.umd.js +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -113,6 +113,7 @@ app.directive('money3', Money3Directive)
|
|
|
113
113
|
disabled: false,
|
|
114
114
|
min: null,
|
|
115
115
|
max: null,
|
|
116
|
+
setMaxIfBigger: true,
|
|
116
117
|
allowBlank: false,
|
|
117
118
|
treatZeroAsBlank: true,
|
|
118
119
|
minimumNumberOfCharacters: 0,
|
|
@@ -178,6 +179,7 @@ To ensure proper functionality, you must use `v-model.lazy` for binding.
|
|
|
178
179
|
disabled: false,
|
|
179
180
|
min: null,
|
|
180
181
|
max: null,
|
|
182
|
+
setMaxIfBigger: true,
|
|
181
183
|
allowBlank: false,
|
|
182
184
|
treatZeroAsBlank: true,
|
|
183
185
|
minimumNumberOfCharacters: 0,
|
|
@@ -205,6 +207,34 @@ If you directly bind it, you're perfectly fine as well:
|
|
|
205
207
|
<input :model-modifiers="{ number: true }" v-model.lazy="amount" v-money3="config" />
|
|
206
208
|
```
|
|
207
209
|
|
|
210
|
+
### Use with wrapper components (Vuetify, Nuxt UI, Element Plus, …)
|
|
211
|
+
|
|
212
|
+
The directive works on any component that renders a single inner `<input>`. Apply it to the wrapper and it walks the host's DOM to find the inner input and attach its listeners there.
|
|
213
|
+
|
|
214
|
+
```html
|
|
215
|
+
<template>
|
|
216
|
+
<!-- Vuetify -->
|
|
217
|
+
<v-text-field v-money3="config" v-model="amount" label="Amount" />
|
|
218
|
+
|
|
219
|
+
<!-- Nuxt UI -->
|
|
220
|
+
<UInput v-money3="config" v-model="amount" />
|
|
221
|
+
|
|
222
|
+
<!-- Element Plus -->
|
|
223
|
+
<el-input v-money3="config" v-model="amount" />
|
|
224
|
+
</template>
|
|
225
|
+
```
|
|
226
|
+
|
|
227
|
+
Wrapper components attach their own `@input` listener to the inner input during render, before the directive's `mounted()` runs. Because DOM listener-order is registration-order, the wrapper's handler would otherwise fire on the raw pre-reformat keystroke value, leaving the host's `v-model` one character behind the displayed value (reported as an "off-by-10" in [#78](https://github.com/jonathanpmartins/v-money3/issues/78)). To fix this without framework-specific detection, the directive re-dispatches an `input` event after each reformat so the wrapper re-reads the post-format value. The re-dispatch only happens when the directive sits on a wrapper (`host !== <input>`); bare `<input v-money3>` is unaffected.
|
|
228
|
+
|
|
229
|
+
The synthetic event is dispatched with `bubbles: false`, so it only reaches listeners attached directly to the inner `<input>` (the wrapper's own `@input` handler). Ancestor listeners — e.g. an `@input` on a parent `<div>` or `<form>` — do not see it. If you do attach a listener directly to the inner input and want to skip the directive's re-dispatch, filter on the marker:
|
|
230
|
+
|
|
231
|
+
```js
|
|
232
|
+
function onInput(e) {
|
|
233
|
+
if (e.__v_money3_synth__) return; // skip the directive's re-dispatch
|
|
234
|
+
// …your handler…
|
|
235
|
+
}
|
|
236
|
+
```
|
|
237
|
+
|
|
208
238
|
## Properties
|
|
209
239
|
|
|
210
240
|
| property | Required | Type | Default | Description |
|
|
@@ -219,6 +249,7 @@ If you directly bind it, you're perfectly fine as well:
|
|
|
219
249
|
| disabled | false | Boolean | false | Disable the inner input tag |
|
|
220
250
|
| min | false | Number | null | The min value allowed |
|
|
221
251
|
| max | false | Number | null | The max value allowed |
|
|
252
|
+
| set-max-if-bigger | false | Boolean | true | When `true` (default), values above `max` are clamped down to `max`. Set to `false` to reject keystrokes that would exceed `max` — the input keeps its last valid value instead of jumping to the ceiling. No effect when `max` is `null` |
|
|
222
253
|
| allow-blank | false | Boolean | false | If the field can start blank and be cleared out by user |
|
|
223
254
|
| treat-zero-as-blank | false | Boolean | true | When `allow-blank` is true, controls whether zero is rendered as blank. Set to `false` to distinguish zero from blank (e.g. show `0.00` and only blank on empty input). Has no effect when `allow-blank` is false |
|
|
224
255
|
| minimum-number-of-characters | false | Number | 0 | The minimum number of characters that the mask should show |
|
|
@@ -269,6 +300,7 @@ const config = {
|
|
|
269
300
|
disabled: false,
|
|
270
301
|
min: null,
|
|
271
302
|
max: null,
|
|
303
|
+
setMaxIfBigger: true,
|
|
272
304
|
allowBlank: false,
|
|
273
305
|
treatZeroAsBlank: true,
|
|
274
306
|
minimumNumberOfCharacters: 0,
|
package/dist/component.vue.d.ts
CHANGED
|
@@ -64,6 +64,10 @@ declare const _default: import("vue").DefineComponent<{
|
|
|
64
64
|
type: (NumberConstructor | StringConstructor)[];
|
|
65
65
|
default: () => string | number | null;
|
|
66
66
|
};
|
|
67
|
+
setMaxIfBigger: {
|
|
68
|
+
type: BooleanConstructor;
|
|
69
|
+
default: () => boolean;
|
|
70
|
+
};
|
|
67
71
|
allowBlank: {
|
|
68
72
|
type: BooleanConstructor;
|
|
69
73
|
default: () => boolean;
|
|
@@ -152,6 +156,10 @@ declare const _default: import("vue").DefineComponent<{
|
|
|
152
156
|
type: (NumberConstructor | StringConstructor)[];
|
|
153
157
|
default: () => string | number | null;
|
|
154
158
|
};
|
|
159
|
+
setMaxIfBigger: {
|
|
160
|
+
type: BooleanConstructor;
|
|
161
|
+
default: () => boolean;
|
|
162
|
+
};
|
|
155
163
|
allowBlank: {
|
|
156
164
|
type: BooleanConstructor;
|
|
157
165
|
default: () => boolean;
|
|
@@ -186,6 +194,7 @@ declare const _default: import("vue").DefineComponent<{
|
|
|
186
194
|
disabled: boolean;
|
|
187
195
|
min: string | number;
|
|
188
196
|
max: string | number;
|
|
197
|
+
setMaxIfBigger: boolean;
|
|
189
198
|
allowBlank: boolean;
|
|
190
199
|
treatZeroAsBlank: boolean;
|
|
191
200
|
minimumNumberOfCharacters: number;
|
package/dist/directive.d.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { DirectiveBinding } from 'vue';
|
|
2
2
|
declare const _default: {
|
|
3
|
-
mounted(
|
|
4
|
-
updated(
|
|
5
|
-
beforeUnmount(
|
|
3
|
+
mounted(host: HTMLInputElement, binding: DirectiveBinding): void;
|
|
4
|
+
updated(host: HTMLInputElement, binding: DirectiveBinding): void;
|
|
5
|
+
beforeUnmount(host: HTMLInputElement): void;
|
|
6
6
|
};
|
|
7
7
|
export default _default;
|
package/dist/options.d.ts
CHANGED
package/dist/v-money3.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { computed as e, createElementBlock as t, defineComponent as n, getCurrentInstance as r, mergeProps as i,
|
|
1
|
+
import { computed as e, createElementBlock as t, defineComponent as n, getCurrentInstance as r, mergeProps as i, onMounted as a, openBlock as o, ref as s, resolveDirective as c, toRefs as l, unref as u, useAttrs as d, watch as f, withDirectives as p } from "vue";
|
|
2
2
|
//#region src/options.ts
|
|
3
|
-
var
|
|
3
|
+
var m = {
|
|
4
4
|
debug: !1,
|
|
5
5
|
masked: !1,
|
|
6
6
|
prefix: "",
|
|
@@ -12,6 +12,7 @@ var p = {
|
|
|
12
12
|
disabled: !1,
|
|
13
13
|
min: null,
|
|
14
14
|
max: null,
|
|
15
|
+
setMaxIfBigger: !0,
|
|
15
16
|
allowBlank: !1,
|
|
16
17
|
treatZeroAsBlank: !0,
|
|
17
18
|
minimumNumberOfCharacters: 0,
|
|
@@ -19,58 +20,62 @@ var p = {
|
|
|
19
20
|
shouldRound: !0,
|
|
20
21
|
focusOnRight: !1,
|
|
21
22
|
lazy: !0
|
|
22
|
-
},
|
|
23
|
+
}, h = ["+", "-"], g = [
|
|
23
24
|
"decimal",
|
|
24
25
|
"thousands",
|
|
25
26
|
"prefix",
|
|
26
27
|
"suffix"
|
|
27
28
|
];
|
|
28
|
-
function
|
|
29
|
-
return Math.max(0, Math.min(e,
|
|
29
|
+
function _(e) {
|
|
30
|
+
return Math.max(0, Math.min(e, 100));
|
|
30
31
|
}
|
|
31
|
-
function
|
|
32
|
+
function v(e, t) {
|
|
32
33
|
return e = e.padStart(t + 1, "0"), t === 0 ? e : `${e.slice(0, -t)}.${e.slice(-t)}`;
|
|
33
34
|
}
|
|
34
|
-
function
|
|
35
|
+
function y(e) {
|
|
35
36
|
return e = e ? e.toString() : "", e.replace(/\D+/g, "") || "0";
|
|
36
37
|
}
|
|
37
|
-
function
|
|
38
|
+
function b(e, t) {
|
|
38
39
|
return e.replace(/(\d)(?=(?:\d{3})+\b)/gm, `$1${t}`);
|
|
39
40
|
}
|
|
40
|
-
function
|
|
41
|
+
function x(e, t, n) {
|
|
41
42
|
return t ? e + n + t : e;
|
|
42
43
|
}
|
|
43
|
-
function
|
|
44
|
-
return
|
|
44
|
+
function S(e, t) {
|
|
45
|
+
return h.includes(e) ? (console.warn(`v-money3 "${t}" property don't accept "${e}" as a value.`), !1) : /\d/g.test(e) ? (console.warn(`v-money3 "${t}" property don't accept "${e}" (any number) as a value.`), !1) : !0;
|
|
45
46
|
}
|
|
46
|
-
function
|
|
47
|
-
for (let t of
|
|
47
|
+
function C(e) {
|
|
48
|
+
for (let t of g) if (!S(e[t], t)) return !1;
|
|
48
49
|
return !0;
|
|
49
50
|
}
|
|
50
|
-
function
|
|
51
|
-
for (let t of
|
|
51
|
+
function w(e) {
|
|
52
|
+
for (let t of g) {
|
|
53
|
+
if (typeof e[t] != "string") {
|
|
54
|
+
e[t] = "";
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
52
57
|
e[t] = e[t].replace(/\d+/g, "");
|
|
53
|
-
for (let n of
|
|
58
|
+
for (let n of h) e[t] = e[t].replaceAll(n, "");
|
|
54
59
|
}
|
|
55
60
|
return e;
|
|
56
61
|
}
|
|
57
|
-
function
|
|
62
|
+
function T(e) {
|
|
58
63
|
return e.length - (e.indexOf(".") + 1);
|
|
59
64
|
}
|
|
60
|
-
function
|
|
65
|
+
function E(e) {
|
|
61
66
|
return e.replace(/^(-?)0+(?!\.)(.+)/, "$1$2");
|
|
62
67
|
}
|
|
63
|
-
function
|
|
68
|
+
function D(e) {
|
|
64
69
|
return /^-?[\d]+$/g.test(e);
|
|
65
70
|
}
|
|
66
|
-
function
|
|
71
|
+
function O(e) {
|
|
67
72
|
return /^-?[\d]+(\.[\d]+)$/g.test(e);
|
|
68
73
|
}
|
|
69
|
-
function
|
|
74
|
+
function k(e, t, n) {
|
|
70
75
|
return t > e.length - 1 ? e : e.substring(0, t) + n + e.substring(t + 1);
|
|
71
76
|
}
|
|
72
|
-
function
|
|
73
|
-
let n = t -
|
|
77
|
+
function A(e, t) {
|
|
78
|
+
let n = t - T(e);
|
|
74
79
|
if (n >= 0) return e;
|
|
75
80
|
let r = e.slice(0, n), i = e.slice(n);
|
|
76
81
|
if (r.charAt(r.length - 1) === "." && (r = r.slice(0, -1)), parseInt(i.charAt(0), 10) >= 5) {
|
|
@@ -78,61 +83,61 @@ function k(e, t) {
|
|
|
78
83
|
let t = r.charAt(e);
|
|
79
84
|
if (t !== "." && t !== "-") {
|
|
80
85
|
let n = parseInt(t, 10) + 1;
|
|
81
|
-
if (n < 10) return
|
|
82
|
-
r =
|
|
86
|
+
if (n < 10) return k(r, e, n);
|
|
87
|
+
r = k(r, e, "0");
|
|
83
88
|
}
|
|
84
89
|
}
|
|
85
90
|
return `1${r}`;
|
|
86
91
|
}
|
|
87
92
|
return r;
|
|
88
93
|
}
|
|
89
|
-
function
|
|
94
|
+
function j(e, t) {
|
|
90
95
|
let n = () => {
|
|
91
|
-
e.setSelectionRange(t, t);
|
|
96
|
+
e === document.activeElement && e.setSelectionRange(t, t);
|
|
92
97
|
};
|
|
93
98
|
e === document.activeElement && (n(), setTimeout(n, 1));
|
|
94
99
|
}
|
|
95
|
-
function
|
|
100
|
+
function M(e) {
|
|
96
101
|
return new Event(e, {
|
|
97
102
|
bubbles: !0,
|
|
98
103
|
cancelable: !1
|
|
99
104
|
});
|
|
100
105
|
}
|
|
101
|
-
function
|
|
106
|
+
function N({ debug: e = !1 }, ...t) {
|
|
102
107
|
e && console.log(...t);
|
|
103
108
|
}
|
|
104
109
|
//#endregion
|
|
105
110
|
//#region \0@oxc-project+runtime@0.130.0/helpers/typeof.js
|
|
106
|
-
function
|
|
111
|
+
function P(e) {
|
|
107
112
|
"@babel/helpers - typeof";
|
|
108
|
-
return
|
|
113
|
+
return P = typeof Symbol == "function" && typeof Symbol.iterator == "symbol" ? function(e) {
|
|
109
114
|
return typeof e;
|
|
110
115
|
} : function(e) {
|
|
111
116
|
return e && typeof Symbol == "function" && e.constructor === Symbol && e !== Symbol.prototype ? "symbol" : typeof e;
|
|
112
|
-
},
|
|
117
|
+
}, P(e);
|
|
113
118
|
}
|
|
114
119
|
//#endregion
|
|
115
120
|
//#region \0@oxc-project+runtime@0.130.0/helpers/toPrimitive.js
|
|
116
|
-
function
|
|
117
|
-
if (
|
|
121
|
+
function F(e, t) {
|
|
122
|
+
if (P(e) != "object" || !e) return e;
|
|
118
123
|
var n = e[Symbol.toPrimitive];
|
|
119
124
|
if (n !== void 0) {
|
|
120
125
|
var r = n.call(e, t || "default");
|
|
121
|
-
if (
|
|
126
|
+
if (P(r) != "object") return r;
|
|
122
127
|
throw TypeError("@@toPrimitive must return a primitive value.");
|
|
123
128
|
}
|
|
124
129
|
return (t === "string" ? String : Number)(e);
|
|
125
130
|
}
|
|
126
131
|
//#endregion
|
|
127
132
|
//#region \0@oxc-project+runtime@0.130.0/helpers/toPropertyKey.js
|
|
128
|
-
function
|
|
129
|
-
var t =
|
|
130
|
-
return
|
|
133
|
+
function I(e) {
|
|
134
|
+
var t = F(e, "string");
|
|
135
|
+
return P(t) == "symbol" ? t : t + "";
|
|
131
136
|
}
|
|
132
137
|
//#endregion
|
|
133
138
|
//#region \0@oxc-project+runtime@0.130.0/helpers/defineProperty.js
|
|
134
|
-
function
|
|
135
|
-
return (t =
|
|
139
|
+
function L(e, t, n) {
|
|
140
|
+
return (t = I(t)) in e ? Object.defineProperty(e, t, {
|
|
136
141
|
value: n,
|
|
137
142
|
enumerable: !0,
|
|
138
143
|
configurable: !0,
|
|
@@ -141,9 +146,9 @@ function I(e, t, n) {
|
|
|
141
146
|
}
|
|
142
147
|
//#endregion
|
|
143
148
|
//#region src/BigNumber.ts
|
|
144
|
-
var
|
|
149
|
+
var R = class e {
|
|
145
150
|
constructor(e) {
|
|
146
|
-
|
|
151
|
+
L(this, "number", 0n), L(this, "decimal", 0), this.setNumber(e);
|
|
147
152
|
}
|
|
148
153
|
getNumber() {
|
|
149
154
|
return this.number;
|
|
@@ -156,13 +161,19 @@ var L = class e {
|
|
|
156
161
|
}
|
|
157
162
|
toFixed(e = 0, t = !0) {
|
|
158
163
|
let n = this.toString(), r = e - this.getDecimalPrecision();
|
|
159
|
-
|
|
164
|
+
if (r > 0) return n.includes(".") || (n += "."), n.padEnd(n.length + r, "0");
|
|
165
|
+
if (r < 0) {
|
|
166
|
+
if (t) return A(n, e);
|
|
167
|
+
let i = n.slice(0, r);
|
|
168
|
+
return i.endsWith(".") ? i.slice(0, -1) : i;
|
|
169
|
+
}
|
|
170
|
+
return n;
|
|
160
171
|
}
|
|
161
172
|
toString() {
|
|
162
173
|
let e = this.number.toString();
|
|
163
174
|
if (this.decimal) {
|
|
164
175
|
let t = !1;
|
|
165
|
-
return e.charAt(0) === "-" && (e = e.substring(1), t = !0), e = e.padStart(e.length + this.decimal, "0"), e = `${e.slice(0, -this.decimal)}.${e.slice(-this.decimal)}`, e =
|
|
176
|
+
return e.charAt(0) === "-" && (e = e.substring(1), t = !0), e = e.padStart(e.length + this.decimal, "0"), e = `${e.slice(0, -this.decimal)}.${e.slice(-this.decimal)}`, e = E(e), (t ? "-" : "") + e;
|
|
166
177
|
}
|
|
167
178
|
return e;
|
|
168
179
|
}
|
|
@@ -179,55 +190,57 @@ var L = class e {
|
|
|
179
190
|
return t === n;
|
|
180
191
|
}
|
|
181
192
|
setupString(e) {
|
|
182
|
-
if (e =
|
|
183
|
-
else if (
|
|
184
|
-
else throw Error(`BigNumber has received
|
|
193
|
+
if (e = E(e), D(e)) this.number = BigInt(e);
|
|
194
|
+
else if (O(e)) this.decimal = T(e), this.number = BigInt(e.replace(".", ""));
|
|
195
|
+
else throw Error(`BigNumber has received an invalid format for the constructor: ${e}`);
|
|
185
196
|
}
|
|
186
197
|
adjustComparisonNumbers(t) {
|
|
187
198
|
let n;
|
|
188
|
-
n = t
|
|
199
|
+
n = t instanceof e ? t : new e(t);
|
|
189
200
|
let r = this.getDecimalPrecision() - n.getDecimalPrecision(), i = this.getNumber(), a = n.getNumber();
|
|
190
201
|
return r > 0 ? a = n.getNumber() * 10n ** BigInt(r) : r < 0 && (i = this.getNumber() * 10n ** BigInt(r * -1)), [i, a];
|
|
191
202
|
}
|
|
192
203
|
};
|
|
193
204
|
//#endregion
|
|
194
205
|
//#region src/format.ts
|
|
195
|
-
function
|
|
196
|
-
|
|
206
|
+
function z(e, t = m, n = "") {
|
|
207
|
+
N(t, "utils format() - caller", n), N(t, "utils format() - input1", e);
|
|
208
|
+
let r = _(t.precision);
|
|
209
|
+
if ((e == null || e === "") && t.allowBlank) return "";
|
|
197
210
|
if (e == null) e = "";
|
|
198
|
-
else if (typeof e == "number") e = t.shouldRound ? e.toFixed(
|
|
199
|
-
else if (t.modelModifiers && t.modelModifiers.number &&
|
|
211
|
+
else if (typeof e == "number") e = t.shouldRound ? e.toFixed(r) : e.toFixed(Math.min(r + 1, 100)).slice(0, -1);
|
|
212
|
+
else if (t.modelModifiers && t.modelModifiers.number && D(e)) e = Number(e).toFixed(r);
|
|
200
213
|
else if (!t.disableNegative && e === "-") return e;
|
|
201
|
-
|
|
202
|
-
let
|
|
203
|
-
|
|
204
|
-
let
|
|
205
|
-
|
|
206
|
-
let
|
|
207
|
-
|
|
208
|
-
let
|
|
209
|
-
if (
|
|
210
|
-
let [
|
|
211
|
-
|
|
212
|
-
let
|
|
213
|
-
return
|
|
214
|
+
N(t, "utils format() - input2", e);
|
|
215
|
+
let i = t.disableNegative ? "" : e.indexOf("-") >= 0 ? "-" : "", a = e.replace(t.prefix, "").replace(t.suffix, "");
|
|
216
|
+
N(t, "utils format() - filtered", a), !r && t.thousands !== "." && O(a) && (a = A(a, 0), N(t, "utils format() - !precision && isValidFloat()", a));
|
|
217
|
+
let o = y(a);
|
|
218
|
+
N(t, "utils format() - numbers", o), N(t, "utils format() - numbersToCurrency", i + v(o, r));
|
|
219
|
+
let s = new R(i + v(o, r));
|
|
220
|
+
N(t, "utils format() - bigNumber1", s.toString()), t.setMaxIfBigger !== !1 && t.max !== null && t.max !== void 0 && t.max !== "" && s.biggerThan(t.max) && s.setNumber(t.max), t.min !== null && t.min !== void 0 && t.min !== "" && s.lessThan(t.min) && s.setNumber(t.min), t.disableNegative && s.lessThan(0) && s.setNumber(0);
|
|
221
|
+
let c = s.toFixed(r, t.shouldRound);
|
|
222
|
+
if (N(t, "utils format() - bigNumber2", s.toFixed(r)), /^0(\.0+)?$/g.test(c) && t.allowBlank && t.treatZeroAsBlank) return "";
|
|
223
|
+
let [l, u] = c.split("."), d = u === void 0 ? 0 : u.length, f = l.charAt(0) === "-", p = (f ? l.slice(1) : l).padStart(t.minimumNumberOfCharacters - d, "0");
|
|
224
|
+
l = (f ? "-" : "") + b(p, t.thousands);
|
|
225
|
+
let h = t.prefix + x(l, u, t.decimal) + t.suffix;
|
|
226
|
+
return N(t, "utils format() - output", h), h;
|
|
214
227
|
}
|
|
215
228
|
//#endregion
|
|
216
229
|
//#region src/unformat.ts
|
|
217
|
-
function
|
|
218
|
-
if (
|
|
230
|
+
function B(e, t = m, n = "") {
|
|
231
|
+
if (N(t, "utils unformat() - caller", n), N(t, "utils unformat() - input", e), !t.disableNegative && e === "-") return N(t, "utils unformat() - return netagive symbol", e), e;
|
|
219
232
|
let r = t.disableNegative ? "" : e.indexOf("-") >= 0 ? "-" : "", i = e.replace(t.prefix, "").replace(t.suffix, "");
|
|
220
|
-
|
|
221
|
-
let a =
|
|
222
|
-
|
|
223
|
-
let o = new
|
|
224
|
-
|
|
225
|
-
let s = o.toFixed(
|
|
226
|
-
return t.modelModifiers && t.modelModifiers.number && (s = parseFloat(s)),
|
|
233
|
+
N(t, "utils unformat() - filtered", i);
|
|
234
|
+
let a = y(i);
|
|
235
|
+
N(t, "utils unformat() - numbers", a);
|
|
236
|
+
let o = new R(r + v(a, t.precision));
|
|
237
|
+
N(t, "utils unformat() - bigNumber1", a.toString()), t.setMaxIfBigger !== !1 && t.max !== null && t.max !== void 0 && t.max !== "" && o.biggerThan(t.max) && o.setNumber(t.max), t.min !== null && t.min !== void 0 && t.min !== "" && o.lessThan(t.min) && o.setNumber(t.min), t.disableNegative && o.lessThan(0) && o.setNumber(0);
|
|
238
|
+
let s = o.toFixed(_(t.precision), t.shouldRound);
|
|
239
|
+
return t.modelModifiers && t.modelModifiers.number && (s = parseFloat(s)), N(t, "utils unformat() - output", s), s;
|
|
227
240
|
}
|
|
228
241
|
//#endregion
|
|
229
242
|
//#region src/directive.ts
|
|
230
|
-
var
|
|
243
|
+
var V = [
|
|
231
244
|
"precision",
|
|
232
245
|
"decimal",
|
|
233
246
|
"thousands",
|
|
@@ -235,87 +248,112 @@ var B = [
|
|
|
235
248
|
"suffix",
|
|
236
249
|
"min",
|
|
237
250
|
"max",
|
|
251
|
+
"setMaxIfBigger",
|
|
238
252
|
"allowBlank",
|
|
239
253
|
"treatZeroAsBlank",
|
|
240
254
|
"minimumNumberOfCharacters",
|
|
241
255
|
"shouldRound",
|
|
242
256
|
"modelModifiers"
|
|
243
|
-
],
|
|
244
|
-
if (
|
|
245
|
-
|
|
257
|
+
], H = "__v_money3_last_valid__", U = "__v_money3_is_wrapper__", W = "__v_money3_synth__", G = (e, t, n) => {
|
|
258
|
+
if (N(t, "directive setValue() - caller", n), !C(t)) {
|
|
259
|
+
N(t, "directive setValue() - validateRestrictedOptions() return false. Stopping here...", e.value);
|
|
246
260
|
return;
|
|
247
261
|
}
|
|
248
|
-
let r = e.value.length - (e.selectionEnd || 0), i =
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
262
|
+
let r = e.value.length - (e.selectionEnd || 0), i = z(e.value, t, n);
|
|
263
|
+
if (t.setMaxIfBigger === !1 && t.max !== null && t.max !== void 0 && t.max !== "") {
|
|
264
|
+
let n = B(i, t, "directive setValue overflow check");
|
|
265
|
+
if (new R(String(n)).biggerThan(t.max)) {
|
|
266
|
+
let t = e[H];
|
|
267
|
+
typeof t == "string" && t !== e.value && (e.value = t);
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
if (i === e.value) {
|
|
272
|
+
e[H] = i;
|
|
273
|
+
return;
|
|
256
274
|
}
|
|
257
|
-
|
|
275
|
+
if (e.value = i, e[H] = i, r = Math.max(r, t.suffix.length), r = e.value.length - r, r = Math.max(r, t.prefix.length), j(e, r), e.dispatchEvent(M("change")), e[U]) {
|
|
276
|
+
let t = new Event("input", { bubbles: !1 });
|
|
277
|
+
t[W] = !0, e.dispatchEvent(t);
|
|
278
|
+
}
|
|
279
|
+
}, K = (e, t) => {
|
|
280
|
+
let n = e.currentTarget, r = e.code === "Backspace" || e.code === "Delete", i = n.value.length - (n.selectionEnd || 0) === 0;
|
|
281
|
+
N(t, "directive onkeydown() - el.value", n.value), N(t, "directive onkeydown() - backspacePressed", r), N(t, "directive onkeydown() - isAtEndPosition", i), t.allowBlank && t.treatZeroAsBlank && r && i && parseFloat(String(B(n.value, t, "directive onkeydown allowBlank"))) === 0 && (N(t, "directive onkeydown() - set el.value = \"\"", n.value), n.value = "", n.dispatchEvent(M("change"))), N(t, "directive onkeydown() - e.key", e.key), e.key === "+" && n.value.indexOf("-") >= 0 && (N(t, "directive onkeydown() - flipping sign on el.value", n.value), n.value = n.value.replace("-", ""), G(n, t, "directive onkeydown +"));
|
|
282
|
+
}, q = (e, t) => {
|
|
283
|
+
if (e[W]) return;
|
|
258
284
|
let n = e.currentTarget;
|
|
259
|
-
|
|
260
|
-
},
|
|
285
|
+
N(t, "directive oninput()", n.value), /^[1-9]$/.test(n.value) && (n.value = v(n.value, _(t.precision)), N(t, "directive oninput() - is 1-9", n.value)), G(n, t, "directive oninput");
|
|
286
|
+
}, J = (e, t) => {
|
|
261
287
|
let n = e.currentTarget;
|
|
262
|
-
|
|
263
|
-
},
|
|
288
|
+
N(t, "directive onFocus()", n.value), t.focusOnRight && j(n, n.value.length - t.suffix.length);
|
|
289
|
+
}, Y = (e) => {
|
|
264
290
|
if (e.tagName.toLocaleUpperCase() !== "INPUT") {
|
|
265
291
|
let t = e.getElementsByTagName("input");
|
|
266
292
|
if (t.length !== 1) throw Error(`v-money3 requires 1 input, found ${t.length} elements.`);
|
|
267
293
|
return t[0];
|
|
268
294
|
}
|
|
269
295
|
return e;
|
|
270
|
-
},
|
|
296
|
+
}, ee = (e, t) => {
|
|
271
297
|
e.onkeydown = (e) => {
|
|
272
|
-
|
|
298
|
+
K(e, t);
|
|
273
299
|
}, e.oninput = (e) => {
|
|
274
|
-
|
|
300
|
+
q(e, t);
|
|
275
301
|
}, e.onfocus = (e) => {
|
|
276
|
-
|
|
302
|
+
J(e, t);
|
|
277
303
|
};
|
|
278
304
|
};
|
|
279
|
-
function
|
|
280
|
-
return e ?
|
|
305
|
+
function te(e, t) {
|
|
306
|
+
return e ? V.some((n) => JSON.stringify(e[n]) !== JSON.stringify(t[n])) : !1;
|
|
307
|
+
}
|
|
308
|
+
var X = "__v_money3_input__";
|
|
309
|
+
function Z(e) {
|
|
310
|
+
let t = e[X];
|
|
311
|
+
if (t) return t;
|
|
312
|
+
let n = Y(e);
|
|
313
|
+
return e[X] = n, n;
|
|
281
314
|
}
|
|
282
|
-
var
|
|
315
|
+
var Q = {
|
|
283
316
|
mounted(e, t) {
|
|
284
317
|
if (!t.value) return;
|
|
285
|
-
let n =
|
|
286
|
-
...
|
|
318
|
+
let n = w({
|
|
319
|
+
...m,
|
|
287
320
|
...t.value
|
|
288
321
|
});
|
|
289
|
-
|
|
322
|
+
N(n, "directive mounted() - opt", n);
|
|
323
|
+
let r = Z(e);
|
|
324
|
+
r[U] = e !== r, ee(r, n), N(n, "directive mounted() - el.value", r.value), G(r, n, "directive mounted");
|
|
290
325
|
},
|
|
291
326
|
updated(e, t) {
|
|
292
327
|
if (!t.value) return;
|
|
293
|
-
let n =
|
|
294
|
-
...
|
|
328
|
+
let n = w({
|
|
329
|
+
...m,
|
|
295
330
|
...t.value
|
|
296
331
|
});
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
332
|
+
N(n, "directive updated() - opt", n), N(n, "directive updated() - host.value", e.value);
|
|
333
|
+
let r = Z(e);
|
|
334
|
+
if (r[U] = e !== r, z(r.value, n, "directive updated check") !== r.value) {
|
|
335
|
+
if (te(t.oldValue ? w({
|
|
336
|
+
...m,
|
|
300
337
|
...t.oldValue
|
|
301
|
-
}) : null, n) &&
|
|
338
|
+
}) : null, n) && r.value !== "") {
|
|
302
339
|
console.warn("v-money3: runtime change of format options on the bare directive is unsupported and was skipped to avoid corrupting the value. Re-mount the directive or use the Money3 component instead.");
|
|
303
340
|
return;
|
|
304
341
|
}
|
|
305
|
-
|
|
342
|
+
G(r, n, "directive updated");
|
|
306
343
|
}
|
|
307
344
|
},
|
|
308
345
|
beforeUnmount(e) {
|
|
309
|
-
|
|
346
|
+
let t = e[X] || e;
|
|
347
|
+
t.onkeydown = null, t.oninput = null, t.onfocus = null, delete t[U], delete e[X];
|
|
310
348
|
}
|
|
311
|
-
},
|
|
349
|
+
}, ne = [
|
|
312
350
|
"id",
|
|
313
351
|
"value",
|
|
314
352
|
"disabled"
|
|
315
|
-
],
|
|
353
|
+
], $ = /* @__PURE__ */ n({
|
|
316
354
|
inheritAttrs: !1,
|
|
317
355
|
name: "Money3",
|
|
318
|
-
directives: { money3:
|
|
356
|
+
directives: { money3: Q },
|
|
319
357
|
__name: "component",
|
|
320
358
|
props: {
|
|
321
359
|
debug: {
|
|
@@ -346,34 +384,34 @@ var J = {
|
|
|
346
384
|
},
|
|
347
385
|
precision: {
|
|
348
386
|
type: Number,
|
|
349
|
-
default: () =>
|
|
387
|
+
default: () => m.precision
|
|
350
388
|
},
|
|
351
389
|
decimal: {
|
|
352
390
|
type: String,
|
|
353
|
-
default: () =>
|
|
391
|
+
default: () => m.decimal,
|
|
354
392
|
validator(e) {
|
|
355
|
-
return
|
|
393
|
+
return S(e, "decimal");
|
|
356
394
|
}
|
|
357
395
|
},
|
|
358
396
|
thousands: {
|
|
359
397
|
type: String,
|
|
360
|
-
default: () =>
|
|
398
|
+
default: () => m.thousands,
|
|
361
399
|
validator(e) {
|
|
362
|
-
return
|
|
400
|
+
return S(e, "thousands");
|
|
363
401
|
}
|
|
364
402
|
},
|
|
365
403
|
prefix: {
|
|
366
404
|
type: String,
|
|
367
|
-
default: () =>
|
|
405
|
+
default: () => m.prefix,
|
|
368
406
|
validator(e) {
|
|
369
|
-
return
|
|
407
|
+
return S(e, "prefix");
|
|
370
408
|
}
|
|
371
409
|
},
|
|
372
410
|
suffix: {
|
|
373
411
|
type: String,
|
|
374
|
-
default: () =>
|
|
412
|
+
default: () => m.suffix,
|
|
375
413
|
validator(e) {
|
|
376
|
-
return
|
|
414
|
+
return S(e, "suffix");
|
|
377
415
|
}
|
|
378
416
|
},
|
|
379
417
|
disableNegative: {
|
|
@@ -386,106 +424,118 @@ var J = {
|
|
|
386
424
|
},
|
|
387
425
|
max: {
|
|
388
426
|
type: [Number, String],
|
|
389
|
-
default: () =>
|
|
427
|
+
default: () => m.max
|
|
390
428
|
},
|
|
391
429
|
min: {
|
|
392
430
|
type: [Number, String],
|
|
393
|
-
default: () =>
|
|
431
|
+
default: () => m.min
|
|
432
|
+
},
|
|
433
|
+
setMaxIfBigger: {
|
|
434
|
+
type: Boolean,
|
|
435
|
+
default: () => m.setMaxIfBigger
|
|
394
436
|
},
|
|
395
437
|
allowBlank: {
|
|
396
438
|
type: Boolean,
|
|
397
|
-
default: () =>
|
|
439
|
+
default: () => m.allowBlank
|
|
398
440
|
},
|
|
399
441
|
treatZeroAsBlank: {
|
|
400
442
|
type: Boolean,
|
|
401
|
-
default: () =>
|
|
443
|
+
default: () => m.treatZeroAsBlank
|
|
402
444
|
},
|
|
403
445
|
minimumNumberOfCharacters: {
|
|
404
446
|
type: Number,
|
|
405
|
-
default: () =>
|
|
447
|
+
default: () => m.minimumNumberOfCharacters
|
|
406
448
|
},
|
|
407
449
|
shouldRound: {
|
|
408
450
|
type: Boolean,
|
|
409
|
-
default: () =>
|
|
451
|
+
default: () => m.shouldRound
|
|
410
452
|
},
|
|
411
453
|
focusOnRight: {
|
|
412
454
|
type: Boolean,
|
|
413
|
-
default: () =>
|
|
455
|
+
default: () => m.focusOnRight
|
|
414
456
|
}
|
|
415
457
|
},
|
|
416
458
|
emits: ["update:model-value"],
|
|
417
459
|
setup(n, { emit: r }) {
|
|
418
|
-
let
|
|
419
|
-
|
|
420
|
-
let { value:
|
|
421
|
-
(
|
|
422
|
-
let
|
|
423
|
-
|
|
424
|
-
function
|
|
425
|
-
|
|
426
|
-
let t =
|
|
427
|
-
t !==
|
|
460
|
+
let m = n, { modelValue: h, modelModifiers: g, masked: v, precision: y, shouldRound: b, focusOnRight: x } = l(m);
|
|
461
|
+
N(m, "component setup()", m);
|
|
462
|
+
let { value: S } = h;
|
|
463
|
+
(m.disableNegative || S !== "-") && g.value && g.value.number && (S = b.value ? Number(h.value).toFixed(_(y.value)) : Number(h.value).toFixed(Math.min(_(y.value) + 1, 100)).slice(0, -1));
|
|
464
|
+
let C = s(z(S, m, "component setup"));
|
|
465
|
+
N(m, "component setup() - data.formattedValue", C.value);
|
|
466
|
+
function T(e) {
|
|
467
|
+
N(m, "component watch() -> value", e);
|
|
468
|
+
let t = z(e, w({ ...m }), "component watch");
|
|
469
|
+
t !== C.value && (N(m, "component watch() changed -> formatted", t), C.value = t);
|
|
428
470
|
}
|
|
429
|
-
|
|
430
|
-
let
|
|
431
|
-
function
|
|
432
|
-
let e =
|
|
471
|
+
f(h, T);
|
|
472
|
+
let E = null, D = r;
|
|
473
|
+
function O() {
|
|
474
|
+
let e = w({ ...m }), t = h.value;
|
|
433
475
|
if (t === "-") return;
|
|
434
|
-
let n =
|
|
435
|
-
n !==
|
|
436
|
-
|
|
437
|
-
|
|
476
|
+
let n = z(t, e, "component opts watch");
|
|
477
|
+
if (n !== C.value && (C.value = n), v.value && !(g.value && g.value.number)) {
|
|
478
|
+
n !== t && n !== E && (E = n, D("update:model-value", n));
|
|
479
|
+
return;
|
|
480
|
+
}
|
|
481
|
+
let r = B(n, e, "component opts watch reunformat"), i = Number(t), a = Number(r);
|
|
482
|
+
!Number.isNaN(i) && !Number.isNaN(a) && i !== a && a !== E && (E = a, D("update:model-value", r));
|
|
438
483
|
}
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
484
|
+
f(() => [
|
|
485
|
+
m.precision,
|
|
486
|
+
m.decimal,
|
|
487
|
+
m.thousands,
|
|
488
|
+
m.prefix,
|
|
489
|
+
m.suffix,
|
|
490
|
+
m.min,
|
|
491
|
+
m.max,
|
|
492
|
+
m.setMaxIfBigger,
|
|
493
|
+
m.allowBlank,
|
|
494
|
+
m.treatZeroAsBlank,
|
|
495
|
+
m.minimumNumberOfCharacters,
|
|
496
|
+
m.shouldRound
|
|
497
|
+
], O), f(() => m.modelModifiers, O, { deep: !0 }), a(() => {
|
|
498
|
+
let e = w({ ...m }), t = B(C.value, e, "component mounted reconcile"), n = Number(h.value), r = Number(t);
|
|
499
|
+
Number.isNaN(n) && !Number.isNaN(r) && r !== E && (E = r, D("update:model-value", t));
|
|
500
|
+
});
|
|
501
|
+
function k(e) {
|
|
453
502
|
let t = e.target.value;
|
|
454
|
-
|
|
503
|
+
N(m, "component change() -> evt.target.value", t), v.value && !g.value.number || (t = B(t, w({ ...m }), "component change")), t !== E && (E = t, N(m, "component change() -> update:model-value", t), D("update:model-value", t));
|
|
455
504
|
}
|
|
456
|
-
let
|
|
457
|
-
let e = { ...
|
|
505
|
+
let A = d(), j = e(() => {
|
|
506
|
+
let e = { ...A };
|
|
458
507
|
return delete e["onUpdate:modelValue"], e;
|
|
459
508
|
});
|
|
460
509
|
return (e, r) => {
|
|
461
|
-
let
|
|
462
|
-
return
|
|
510
|
+
let a = c("money3");
|
|
511
|
+
return p((o(), t("input", i({ id: `${n.id}` }, j.value, {
|
|
463
512
|
type: "tel",
|
|
464
513
|
class: "v-money3",
|
|
465
|
-
value:
|
|
466
|
-
disabled:
|
|
467
|
-
onChange:
|
|
468
|
-
}), null, 16,
|
|
469
|
-
precision:
|
|
470
|
-
decimal:
|
|
471
|
-
thousands:
|
|
472
|
-
prefix:
|
|
473
|
-
suffix:
|
|
474
|
-
disableNegative:
|
|
475
|
-
min:
|
|
476
|
-
max:
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
514
|
+
value: C.value,
|
|
515
|
+
disabled: m.disabled,
|
|
516
|
+
onChange: k
|
|
517
|
+
}), null, 16, ne)), [[a, {
|
|
518
|
+
precision: u(y),
|
|
519
|
+
decimal: m.decimal,
|
|
520
|
+
thousands: m.thousands,
|
|
521
|
+
prefix: m.prefix,
|
|
522
|
+
suffix: m.suffix,
|
|
523
|
+
disableNegative: m.disableNegative,
|
|
524
|
+
min: m.min,
|
|
525
|
+
max: m.max,
|
|
526
|
+
setMaxIfBigger: m.setMaxIfBigger,
|
|
527
|
+
allowBlank: m.allowBlank,
|
|
528
|
+
treatZeroAsBlank: m.treatZeroAsBlank,
|
|
529
|
+
minimumNumberOfCharacters: m.minimumNumberOfCharacters,
|
|
530
|
+
debug: m.debug,
|
|
531
|
+
modelModifiers: u(g),
|
|
532
|
+
shouldRound: u(b),
|
|
533
|
+
focusOnRight: u(x)
|
|
484
534
|
}]]);
|
|
485
535
|
};
|
|
486
536
|
}
|
|
487
|
-
}),
|
|
488
|
-
e.component("money3",
|
|
537
|
+
}), re = { install(e) {
|
|
538
|
+
e.component("money3", $), e.directive("money3", Q);
|
|
489
539
|
} };
|
|
490
540
|
//#endregion
|
|
491
|
-
export {
|
|
541
|
+
export { R as BigNumber, $ as Money, $ as Money3, $ as Money3Component, Q as Money3Directive, Q as VMoney, Q as VMoney3, re as default, z as format, B as unformat };
|
package/dist/v-money3.umd.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`vue`)):typeof define==`function`&&define.amd?define([`exports`,`vue`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e[`v-money3`]={},e.Vue))})(this,function(e,t){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var n={debug:!1,masked:!1,prefix:``,suffix:``,thousands:`,`,decimal:`.`,precision:2,disableNegative:!1,disabled:!1,min:null,max:null,allowBlank:!1,treatZeroAsBlank:!0,minimumNumberOfCharacters:0,modelModifiers:{number:!1},shouldRound:!0,focusOnRight:!1,lazy:!0},r=[`+`,`-`],i=[`decimal`,`thousands`,`prefix`,`suffix`];function a(e){return Math.max(0,Math.min(e,1e3))}function o(e,t){return e=e.padStart(t+1,`0`),t===0?e:`${e.slice(0,-t)}.${e.slice(-t)}`}function s(e){return e=e?e.toString():``,e.replace(/\D+/g,``)||`0`}function c(e,t){return e.replace(/(\d)(?=(?:\d{3})+\b)/gm,`$1${t}`)}function l(e,t,n){return t?e+n+t:e}function u(e,t){return r.includes(e)?(console.warn(`v-money3 "${t}" property don't accept "${e}" as a value.`),!1):/\d/g.test(e)?(console.warn(`v-money3 "${t}" property don't accept "${e}" (any number) as a value.`),!1):!0}function d(e){for(let t of i)if(!u(e[t],t))return!1;return!0}function f(e){for(let t of i){e[t]=e[t].replace(/\d+/g,``);for(let n of r)e[t]=e[t].replaceAll(n,``)}return e}function p(e){return e.length-(e.indexOf(`.`)+1)}function m(e){return e.replace(/^(-?)0+(?!\.)(.+)/,`$1$2`)}function h(e){return/^-?[\d]+$/g.test(e)}function g(e){return/^-?[\d]+(\.[\d]+)$/g.test(e)}function _(e,t,n){return t>e.length-1?e:e.substring(0,t)+n+e.substring(t+1)}function v(e,t){let n=t-p(e);if(n>=0)return e;let r=e.slice(0,n),i=e.slice(n);if(r.charAt(r.length-1)===`.`&&(r=r.slice(0,-1)),parseInt(i.charAt(0),10)>=5){for(let e=r.length-1;e>=0;--e){let t=r.charAt(e);if(t!==`.`&&t!==`-`){let n=parseInt(t,10)+1;if(n<10)return _(r,e,n);r=_(r,e,`0`)}}return`1${r}`}return r}function y(e,t){let n=()=>{e.setSelectionRange(t,t)};e===document.activeElement&&(n(),setTimeout(n,1))}function b(e){return new Event(e,{bubbles:!0,cancelable:!1})}function x({debug:e=!1},...t){e&&console.log(...t)}function S(e){"@babel/helpers - typeof";return S=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},S(e)}function C(e,t){if(S(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(S(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function w(e){var t=C(e,`string`);return S(t)==`symbol`?t:t+``}function T(e,t,n){return(t=w(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var E=class e{constructor(e){T(this,`number`,0n),T(this,`decimal`,0),this.setNumber(e)}getNumber(){return this.number}getDecimalPrecision(){return this.decimal}setNumber(e){this.decimal=0,typeof e==`bigint`?this.number=e:typeof e==`number`?this.setupString(e.toString()):this.setupString(e)}toFixed(e=0,t=!0){let n=this.toString(),r=e-this.getDecimalPrecision();return r>0?(n.includes(`.`)||(n+=`.`),n.padEnd(n.length+r,`0`)):r<0?t?v(n,e):n.slice(0,r):n}toString(){let e=this.number.toString();if(this.decimal){let t=!1;return e.charAt(0)===`-`&&(e=e.substring(1),t=!0),e=e.padStart(e.length+this.decimal,`0`),e=`${e.slice(0,-this.decimal)}.${e.slice(-this.decimal)}`,e=m(e),(t?`-`:``)+e}return e}lessThan(e){let[t,n]=this.adjustComparisonNumbers(e);return t<n}biggerThan(e){let[t,n]=this.adjustComparisonNumbers(e);return t>n}isEqual(e){let[t,n]=this.adjustComparisonNumbers(e);return t===n}setupString(e){if(e=m(e),h(e))this.number=BigInt(e);else if(g(e))this.decimal=p(e),this.number=BigInt(e.replace(`.`,``));else throw Error(`BigNumber has received and invalid format for the constructor: ${e}`)}adjustComparisonNumbers(t){let n;n=t.constructor.name===`BigNumber`?t:new e(t);let r=this.getDecimalPrecision()-n.getDecimalPrecision(),i=this.getNumber(),a=n.getNumber();return r>0?a=n.getNumber()*10n**BigInt(r):r<0&&(i=this.getNumber()*10n**BigInt(r*-1)),[i,a]}};function D(e,t=n,r=``){if(x(t,`utils format() - caller`,r),x(t,`utils format() - input1`,e),(e==null||e===``)&&t.allowBlank)return``;if(e==null)e=``;else if(typeof e==`number`)e=t.shouldRound?e.toFixed(a(t.precision)):e.toFixed(a(t.precision)+1).slice(0,-1);else if(t.modelModifiers&&t.modelModifiers.number&&h(e))e=Number(e).toFixed(a(t.precision));else if(!t.disableNegative&&e===`-`)return e;x(t,`utils format() - input2`,e);let i=t.disableNegative?``:e.indexOf(`-`)>=0?`-`:``,u=e.replace(t.prefix,``).replace(t.suffix,``);x(t,`utils format() - filtered`,u),!t.precision&&t.thousands!==`.`&&g(u)&&(u=v(u,0),x(t,`utils format() - !opt.precision && isValidFloat()`,u));let d=s(u);x(t,`utils format() - numbers`,d),x(t,`utils format() - numbersToCurrency`,i+o(d,t.precision));let f=new E(i+o(d,t.precision));x(t,`utils format() - bigNumber1`,f.toString()),t.max&&f.biggerThan(t.max)&&f.setNumber(t.max),t.min&&f.lessThan(t.min)&&f.setNumber(t.min);let p=f.toFixed(a(t.precision),t.shouldRound);if(x(t,`utils format() - bigNumber2`,f.toFixed(a(t.precision))),/^0(\.0+)?$/g.test(p)&&t.allowBlank&&t.treatZeroAsBlank)return``;let[m,_]=p.split(`.`),y=_===void 0?0:_.length;m=m.padStart(t.minimumNumberOfCharacters-y,`0`),m=c(m,t.thousands);let b=t.prefix+l(m,_,t.decimal)+t.suffix;return x(t,`utils format() - output`,b),b}function O(e,t=n,r=``){if(x(t,`utils unformat() - caller`,r),x(t,`utils unformat() - input`,e),!t.disableNegative&&e===`-`)return x(t,`utils unformat() - return netagive symbol`,e),e;let i=t.disableNegative?``:e.indexOf(`-`)>=0?`-`:``,c=e.replace(t.prefix,``).replace(t.suffix,``);x(t,`utils unformat() - filtered`,c);let l=s(c);x(t,`utils unformat() - numbers`,l);let u=new E(i+o(l,t.precision));x(t,`utils unformat() - bigNumber1`,l.toString()),t.max&&u.biggerThan(t.max)&&u.setNumber(t.max),t.min&&u.lessThan(t.min)&&u.setNumber(t.min);let d=u.toFixed(a(t.precision),t.shouldRound);return t.modelModifiers&&t.modelModifiers.number&&(d=parseFloat(d)),x(t,`utils unformat() - output`,d),d}var k=[`precision`,`decimal`,`thousands`,`prefix`,`suffix`,`min`,`max`,`allowBlank`,`treatZeroAsBlank`,`minimumNumberOfCharacters`,`shouldRound`,`modelModifiers`],A=(e,t,n)=>{if(x(t,`directive setValue() - caller`,n),!d(t)){x(t,`directive setValue() - validateRestrictedOptions() return false. Stopping here...`,e.value);return}let r=e.value.length-(e.selectionEnd||0),i=D(e.value,t,n);i!==e.value&&(e.value=i,r=Math.max(r,t.suffix.length),r=e.value.length-r,r=Math.max(r,t.prefix.length),y(e,r),e.dispatchEvent(b(`change`)))},j=(e,t)=>{let n=e.currentTarget,r=e.code===`Backspace`||e.code===`Delete`,i=n.value.length-(n.selectionEnd||0)===0;if(x(t,`directive onkeydown() - el.value`,n.value),x(t,`directive onkeydown() - backspacePressed`,r),x(t,`directive onkeydown() - isAtEndPosition`,i),t.allowBlank&&t.treatZeroAsBlank&&r&&i&&O(n.value,t,`directive onkeydown allowBlank`)===0&&(x(t,`directive onkeydown() - set el.value = ""`,n.value),n.value=``,n.dispatchEvent(b(`change`))),x(t,`directive onkeydown() - e.key`,e.key),e.key===`+`){x(t,`directive onkeydown() - unformat el.value`,n.value);let e=O(n.value,t,`directive onkeydown +`);typeof e==`string`&&(e=parseFloat(e)),e<0&&(n.value=String(e*-1))}},M=(e,t)=>{let n=e.currentTarget;x(t,`directive oninput()`,n.value),/^[1-9]$/.test(n.value)&&(n.value=o(n.value,a(t.precision)),x(t,`directive oninput() - is 1-9`,n.value)),A(n,t,`directive oninput`)},N=(e,t)=>{let n=e.currentTarget;x(t,`directive onFocus()`,n.value),t.focusOnRight&&y(n,n.value.length-t.suffix.length)},P=e=>{if(e.tagName.toLocaleUpperCase()!==`INPUT`){let t=e.getElementsByTagName(`input`);if(t.length!==1)throw Error(`v-money3 requires 1 input, found ${t.length} elements.`);return t[0]}return e},F=(e,t)=>{e.onkeydown=e=>{j(e,t)},e.oninput=e=>{M(e,t)},e.onfocus=e=>{N(e,t)}};function I(e,t){return e?k.some(n=>JSON.stringify(e[n])!==JSON.stringify(t[n])):!1}var L={mounted(e,t){if(!t.value)return;let r=f({...n,...t.value});x(r,`directive mounted() - opt`,r),e=P(e),F(e,r),x(r,`directive mounted() - el.value`,e.value),A(e,r,`directive mounted`)},updated(e,t){if(!t.value)return;let r=f({...n,...t.value});if(x(r,`directive updated() - opt`,r),x(r,`directive updated() - el.value`,e.value),e=P(e),D(e.value,r,`directive updated check`)!==e.value){if(I(t.oldValue?f({...n,...t.oldValue}):null,r)&&e.value!==``){console.warn(`v-money3: runtime change of format options on the bare directive is unsupported and was skipped to avoid corrupting the value. Re-mount the directive or use the Money3 component instead.`);return}A(e,r,`directive updated`)}},beforeUnmount(e){e.onkeydown=null,e.oninput=null,e.onfocus=null}},R=[`id`,`value`,`disabled`],z=(0,t.defineComponent)({inheritAttrs:!1,name:`Money3`,directives:{money3:L},__name:`component`,props:{debug:{required:!1,type:Boolean,default:!1},id:{required:!1,type:[Number,String],default:()=>{let e=(0,t.getCurrentInstance)();return e?e.uid:null}},modelValue:{required:!0,type:[Number,String]},modelModifiers:{required:!1,type:Object,default:()=>({number:!1})},masked:{type:Boolean,default:!1},precision:{type:Number,default:()=>n.precision},decimal:{type:String,default:()=>n.decimal,validator(e){return u(e,`decimal`)}},thousands:{type:String,default:()=>n.thousands,validator(e){return u(e,`thousands`)}},prefix:{type:String,default:()=>n.prefix,validator(e){return u(e,`prefix`)}},suffix:{type:String,default:()=>n.suffix,validator(e){return u(e,`suffix`)}},disableNegative:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},max:{type:[Number,String],default:()=>n.max},min:{type:[Number,String],default:()=>n.min},allowBlank:{type:Boolean,default:()=>n.allowBlank},treatZeroAsBlank:{type:Boolean,default:()=>n.treatZeroAsBlank},minimumNumberOfCharacters:{type:Number,default:()=>n.minimumNumberOfCharacters},shouldRound:{type:Boolean,default:()=>n.shouldRound},focusOnRight:{type:Boolean,default:()=>n.focusOnRight}},emits:[`update:model-value`],setup(e,{emit:n}){let r=e,{modelValue:i,modelModifiers:o,masked:s,precision:c,shouldRound:l,focusOnRight:u}=(0,t.toRefs)(r);x(r,`component setup()`,r);let{value:d}=i;(r.disableNegative||d!==`-`)&&o.value&&o.value.number&&(d=l.value?Number(i.value).toFixed(a(c.value)):Number(i.value).toFixed(a(c.value)+1).slice(0,-1));let p=(0,t.ref)(D(d,r,`component setup`));x(r,`component setup() - data.formattedValue`,p.value);function m(e){x(r,`component watch() -> value`,e);let t=D(e,f({...r}),`component watch`);t!==p.value&&(x(r,`component watch() changed -> formatted`,t),p.value=t)}(0,t.watch)(i,m);let h=null,g=n;function _(){let e=f({...r}),t=i.value;if(t===`-`)return;let n=D(t,e,`component opts watch`);n!==p.value&&(p.value=n);let a=O(n,e,`component opts watch reunformat`),o=Number(t),s=Number(a);!Number.isNaN(o)&&!Number.isNaN(s)&&o!==s&&s!==h&&(h=s,g(`update:model-value`,a))}(0,t.watch)(()=>[r.precision,r.decimal,r.thousands,r.prefix,r.suffix,r.min,r.max,r.allowBlank,r.treatZeroAsBlank,r.minimumNumberOfCharacters,r.shouldRound],_),(0,t.watch)(()=>r.modelModifiers,_,{deep:!0});function v(e){let t=e.target.value;x(r,`component change() -> evt.target.value`,t),s.value&&!o.value.number||(t=O(t,f({...r}),`component change`)),t!==h&&(h=t,x(r,`component change() -> update:model-value`,t),g(`update:model-value`,t))}let y=(0,t.useAttrs)(),b=(0,t.computed)(()=>{let e={...y};return delete e[`onUpdate:modelValue`],e});return(n,i)=>{let a=(0,t.resolveDirective)(`money3`);return(0,t.withDirectives)(((0,t.openBlock)(),(0,t.createElementBlock)(`input`,(0,t.mergeProps)({id:`${e.id}`},b.value,{type:`tel`,class:`v-money3`,value:p.value,disabled:r.disabled,onChange:v}),null,16,R)),[[a,{precision:(0,t.unref)(c),decimal:r.decimal,thousands:r.thousands,prefix:r.prefix,suffix:r.suffix,disableNegative:r.disableNegative,min:r.min,max:r.max,allowBlank:r.allowBlank,treatZeroAsBlank:r.treatZeroAsBlank,minimumNumberOfCharacters:r.minimumNumberOfCharacters,debug:r.debug,modelModifiers:(0,t.unref)(o),shouldRound:(0,t.unref)(l),focusOnRight:(0,t.unref)(u)}]])}}});e.BigNumber=E,e.Money=z,e.Money3=z,e.Money3Component=z,e.Money3Directive=L,e.VMoney=L,e.VMoney3=L,e.default={install(e){e.component(`money3`,z),e.directive(`money3`,L)}},e.format=D,e.unformat=O});
|
|
1
|
+
(function(e,t){typeof exports==`object`&&typeof module<`u`?t(exports,require(`vue`)):typeof define==`function`&&define.amd?define([`exports`,`vue`],t):(e=typeof globalThis<`u`?globalThis:e||self,t(e[`v-money3`]={},e.Vue))})(this,function(e,t){Object.defineProperties(e,{__esModule:{value:!0},[Symbol.toStringTag]:{value:`Module`}});var n={debug:!1,masked:!1,prefix:``,suffix:``,thousands:`,`,decimal:`.`,precision:2,disableNegative:!1,disabled:!1,min:null,max:null,setMaxIfBigger:!0,allowBlank:!1,treatZeroAsBlank:!0,minimumNumberOfCharacters:0,modelModifiers:{number:!1},shouldRound:!0,focusOnRight:!1,lazy:!0},r=[`+`,`-`],i=[`decimal`,`thousands`,`prefix`,`suffix`];function a(e){return Math.max(0,Math.min(e,100))}function o(e,t){return e=e.padStart(t+1,`0`),t===0?e:`${e.slice(0,-t)}.${e.slice(-t)}`}function s(e){return e=e?e.toString():``,e.replace(/\D+/g,``)||`0`}function c(e,t){return e.replace(/(\d)(?=(?:\d{3})+\b)/gm,`$1${t}`)}function l(e,t,n){return t?e+n+t:e}function u(e,t){return r.includes(e)?(console.warn(`v-money3 "${t}" property don't accept "${e}" as a value.`),!1):/\d/g.test(e)?(console.warn(`v-money3 "${t}" property don't accept "${e}" (any number) as a value.`),!1):!0}function d(e){for(let t of i)if(!u(e[t],t))return!1;return!0}function f(e){for(let t of i){if(typeof e[t]!=`string`){e[t]=``;continue}e[t]=e[t].replace(/\d+/g,``);for(let n of r)e[t]=e[t].replaceAll(n,``)}return e}function p(e){return e.length-(e.indexOf(`.`)+1)}function m(e){return e.replace(/^(-?)0+(?!\.)(.+)/,`$1$2`)}function h(e){return/^-?[\d]+$/g.test(e)}function g(e){return/^-?[\d]+(\.[\d]+)$/g.test(e)}function _(e,t,n){return t>e.length-1?e:e.substring(0,t)+n+e.substring(t+1)}function v(e,t){let n=t-p(e);if(n>=0)return e;let r=e.slice(0,n),i=e.slice(n);if(r.charAt(r.length-1)===`.`&&(r=r.slice(0,-1)),parseInt(i.charAt(0),10)>=5){for(let e=r.length-1;e>=0;--e){let t=r.charAt(e);if(t!==`.`&&t!==`-`){let n=parseInt(t,10)+1;if(n<10)return _(r,e,n);r=_(r,e,`0`)}}return`1${r}`}return r}function y(e,t){let n=()=>{e===document.activeElement&&e.setSelectionRange(t,t)};e===document.activeElement&&(n(),setTimeout(n,1))}function b(e){return new Event(e,{bubbles:!0,cancelable:!1})}function x({debug:e=!1},...t){e&&console.log(...t)}function S(e){"@babel/helpers - typeof";return S=typeof Symbol==`function`&&typeof Symbol.iterator==`symbol`?function(e){return typeof e}:function(e){return e&&typeof Symbol==`function`&&e.constructor===Symbol&&e!==Symbol.prototype?`symbol`:typeof e},S(e)}function C(e,t){if(S(e)!=`object`||!e)return e;var n=e[Symbol.toPrimitive];if(n!==void 0){var r=n.call(e,t||`default`);if(S(r)!=`object`)return r;throw TypeError(`@@toPrimitive must return a primitive value.`)}return(t===`string`?String:Number)(e)}function w(e){var t=C(e,`string`);return S(t)==`symbol`?t:t+``}function T(e,t,n){return(t=w(t))in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var E=class e{constructor(e){T(this,`number`,0n),T(this,`decimal`,0),this.setNumber(e)}getNumber(){return this.number}getDecimalPrecision(){return this.decimal}setNumber(e){this.decimal=0,typeof e==`bigint`?this.number=e:typeof e==`number`?this.setupString(e.toString()):this.setupString(e)}toFixed(e=0,t=!0){let n=this.toString(),r=e-this.getDecimalPrecision();if(r>0)return n.includes(`.`)||(n+=`.`),n.padEnd(n.length+r,`0`);if(r<0){if(t)return v(n,e);let i=n.slice(0,r);return i.endsWith(`.`)?i.slice(0,-1):i}return n}toString(){let e=this.number.toString();if(this.decimal){let t=!1;return e.charAt(0)===`-`&&(e=e.substring(1),t=!0),e=e.padStart(e.length+this.decimal,`0`),e=`${e.slice(0,-this.decimal)}.${e.slice(-this.decimal)}`,e=m(e),(t?`-`:``)+e}return e}lessThan(e){let[t,n]=this.adjustComparisonNumbers(e);return t<n}biggerThan(e){let[t,n]=this.adjustComparisonNumbers(e);return t>n}isEqual(e){let[t,n]=this.adjustComparisonNumbers(e);return t===n}setupString(e){if(e=m(e),h(e))this.number=BigInt(e);else if(g(e))this.decimal=p(e),this.number=BigInt(e.replace(`.`,``));else throw Error(`BigNumber has received an invalid format for the constructor: ${e}`)}adjustComparisonNumbers(t){let n;n=t instanceof e?t:new e(t);let r=this.getDecimalPrecision()-n.getDecimalPrecision(),i=this.getNumber(),a=n.getNumber();return r>0?a=n.getNumber()*10n**BigInt(r):r<0&&(i=this.getNumber()*10n**BigInt(r*-1)),[i,a]}};function D(e,t=n,r=``){x(t,`utils format() - caller`,r),x(t,`utils format() - input1`,e);let i=a(t.precision);if((e==null||e===``)&&t.allowBlank)return``;if(e==null)e=``;else if(typeof e==`number`)e=t.shouldRound?e.toFixed(i):e.toFixed(Math.min(i+1,100)).slice(0,-1);else if(t.modelModifiers&&t.modelModifiers.number&&h(e))e=Number(e).toFixed(i);else if(!t.disableNegative&&e===`-`)return e;x(t,`utils format() - input2`,e);let u=t.disableNegative?``:e.indexOf(`-`)>=0?`-`:``,d=e.replace(t.prefix,``).replace(t.suffix,``);x(t,`utils format() - filtered`,d),!i&&t.thousands!==`.`&&g(d)&&(d=v(d,0),x(t,`utils format() - !precision && isValidFloat()`,d));let f=s(d);x(t,`utils format() - numbers`,f),x(t,`utils format() - numbersToCurrency`,u+o(f,i));let p=new E(u+o(f,i));x(t,`utils format() - bigNumber1`,p.toString()),t.setMaxIfBigger!==!1&&t.max!==null&&t.max!==void 0&&t.max!==``&&p.biggerThan(t.max)&&p.setNumber(t.max),t.min!==null&&t.min!==void 0&&t.min!==``&&p.lessThan(t.min)&&p.setNumber(t.min),t.disableNegative&&p.lessThan(0)&&p.setNumber(0);let m=p.toFixed(i,t.shouldRound);if(x(t,`utils format() - bigNumber2`,p.toFixed(i)),/^0(\.0+)?$/g.test(m)&&t.allowBlank&&t.treatZeroAsBlank)return``;let[_,y]=m.split(`.`),b=y===void 0?0:y.length,S=_.charAt(0)===`-`,C=(S?_.slice(1):_).padStart(t.minimumNumberOfCharacters-b,`0`);_=(S?`-`:``)+c(C,t.thousands);let w=t.prefix+l(_,y,t.decimal)+t.suffix;return x(t,`utils format() - output`,w),w}function O(e,t=n,r=``){if(x(t,`utils unformat() - caller`,r),x(t,`utils unformat() - input`,e),!t.disableNegative&&e===`-`)return x(t,`utils unformat() - return netagive symbol`,e),e;let i=t.disableNegative?``:e.indexOf(`-`)>=0?`-`:``,c=e.replace(t.prefix,``).replace(t.suffix,``);x(t,`utils unformat() - filtered`,c);let l=s(c);x(t,`utils unformat() - numbers`,l);let u=new E(i+o(l,t.precision));x(t,`utils unformat() - bigNumber1`,l.toString()),t.setMaxIfBigger!==!1&&t.max!==null&&t.max!==void 0&&t.max!==``&&u.biggerThan(t.max)&&u.setNumber(t.max),t.min!==null&&t.min!==void 0&&t.min!==``&&u.lessThan(t.min)&&u.setNumber(t.min),t.disableNegative&&u.lessThan(0)&&u.setNumber(0);let d=u.toFixed(a(t.precision),t.shouldRound);return t.modelModifiers&&t.modelModifiers.number&&(d=parseFloat(d)),x(t,`utils unformat() - output`,d),d}var k=[`precision`,`decimal`,`thousands`,`prefix`,`suffix`,`min`,`max`,`setMaxIfBigger`,`allowBlank`,`treatZeroAsBlank`,`minimumNumberOfCharacters`,`shouldRound`,`modelModifiers`],A=`__v_money3_last_valid__`,j=`__v_money3_is_wrapper__`,M=`__v_money3_synth__`,N=(e,t,n)=>{if(x(t,`directive setValue() - caller`,n),!d(t)){x(t,`directive setValue() - validateRestrictedOptions() return false. Stopping here...`,e.value);return}let r=e.value.length-(e.selectionEnd||0),i=D(e.value,t,n);if(t.setMaxIfBigger===!1&&t.max!==null&&t.max!==void 0&&t.max!==``){let n=O(i,t,`directive setValue overflow check`);if(new E(String(n)).biggerThan(t.max)){let t=e[A];typeof t==`string`&&t!==e.value&&(e.value=t);return}}if(i===e.value){e[A]=i;return}if(e.value=i,e[A]=i,r=Math.max(r,t.suffix.length),r=e.value.length-r,r=Math.max(r,t.prefix.length),y(e,r),e.dispatchEvent(b(`change`)),e[j]){let t=new Event(`input`,{bubbles:!1});t[M]=!0,e.dispatchEvent(t)}},P=(e,t)=>{let n=e.currentTarget,r=e.code===`Backspace`||e.code===`Delete`,i=n.value.length-(n.selectionEnd||0)===0;x(t,`directive onkeydown() - el.value`,n.value),x(t,`directive onkeydown() - backspacePressed`,r),x(t,`directive onkeydown() - isAtEndPosition`,i),t.allowBlank&&t.treatZeroAsBlank&&r&&i&&parseFloat(String(O(n.value,t,`directive onkeydown allowBlank`)))===0&&(x(t,`directive onkeydown() - set el.value = ""`,n.value),n.value=``,n.dispatchEvent(b(`change`))),x(t,`directive onkeydown() - e.key`,e.key),e.key===`+`&&n.value.indexOf(`-`)>=0&&(x(t,`directive onkeydown() - flipping sign on el.value`,n.value),n.value=n.value.replace(`-`,``),N(n,t,`directive onkeydown +`))},F=(e,t)=>{if(e[M])return;let n=e.currentTarget;x(t,`directive oninput()`,n.value),/^[1-9]$/.test(n.value)&&(n.value=o(n.value,a(t.precision)),x(t,`directive oninput() - is 1-9`,n.value)),N(n,t,`directive oninput`)},I=(e,t)=>{let n=e.currentTarget;x(t,`directive onFocus()`,n.value),t.focusOnRight&&y(n,n.value.length-t.suffix.length)},L=e=>{if(e.tagName.toLocaleUpperCase()!==`INPUT`){let t=e.getElementsByTagName(`input`);if(t.length!==1)throw Error(`v-money3 requires 1 input, found ${t.length} elements.`);return t[0]}return e},R=(e,t)=>{e.onkeydown=e=>{P(e,t)},e.oninput=e=>{F(e,t)},e.onfocus=e=>{I(e,t)}};function z(e,t){return e?k.some(n=>JSON.stringify(e[n])!==JSON.stringify(t[n])):!1}var B=`__v_money3_input__`;function V(e){let t=e[B];if(t)return t;let n=L(e);return e[B]=n,n}var H={mounted(e,t){if(!t.value)return;let r=f({...n,...t.value});x(r,`directive mounted() - opt`,r);let i=V(e);i[j]=e!==i,R(i,r),x(r,`directive mounted() - el.value`,i.value),N(i,r,`directive mounted`)},updated(e,t){if(!t.value)return;let r=f({...n,...t.value});x(r,`directive updated() - opt`,r),x(r,`directive updated() - host.value`,e.value);let i=V(e);if(i[j]=e!==i,D(i.value,r,`directive updated check`)!==i.value){if(z(t.oldValue?f({...n,...t.oldValue}):null,r)&&i.value!==``){console.warn(`v-money3: runtime change of format options on the bare directive is unsupported and was skipped to avoid corrupting the value. Re-mount the directive or use the Money3 component instead.`);return}N(i,r,`directive updated`)}},beforeUnmount(e){let t=e[B]||e;t.onkeydown=null,t.oninput=null,t.onfocus=null,delete t[j],delete e[B]}},U=[`id`,`value`,`disabled`],W=(0,t.defineComponent)({inheritAttrs:!1,name:`Money3`,directives:{money3:H},__name:`component`,props:{debug:{required:!1,type:Boolean,default:!1},id:{required:!1,type:[Number,String],default:()=>{let e=(0,t.getCurrentInstance)();return e?e.uid:null}},modelValue:{required:!0,type:[Number,String]},modelModifiers:{required:!1,type:Object,default:()=>({number:!1})},masked:{type:Boolean,default:!1},precision:{type:Number,default:()=>n.precision},decimal:{type:String,default:()=>n.decimal,validator(e){return u(e,`decimal`)}},thousands:{type:String,default:()=>n.thousands,validator(e){return u(e,`thousands`)}},prefix:{type:String,default:()=>n.prefix,validator(e){return u(e,`prefix`)}},suffix:{type:String,default:()=>n.suffix,validator(e){return u(e,`suffix`)}},disableNegative:{type:Boolean,default:!1},disabled:{type:Boolean,default:!1},max:{type:[Number,String],default:()=>n.max},min:{type:[Number,String],default:()=>n.min},setMaxIfBigger:{type:Boolean,default:()=>n.setMaxIfBigger},allowBlank:{type:Boolean,default:()=>n.allowBlank},treatZeroAsBlank:{type:Boolean,default:()=>n.treatZeroAsBlank},minimumNumberOfCharacters:{type:Number,default:()=>n.minimumNumberOfCharacters},shouldRound:{type:Boolean,default:()=>n.shouldRound},focusOnRight:{type:Boolean,default:()=>n.focusOnRight}},emits:[`update:model-value`],setup(e,{emit:n}){let r=e,{modelValue:i,modelModifiers:o,masked:s,precision:c,shouldRound:l,focusOnRight:u}=(0,t.toRefs)(r);x(r,`component setup()`,r);let{value:d}=i;(r.disableNegative||d!==`-`)&&o.value&&o.value.number&&(d=l.value?Number(i.value).toFixed(a(c.value)):Number(i.value).toFixed(Math.min(a(c.value)+1,100)).slice(0,-1));let p=(0,t.ref)(D(d,r,`component setup`));x(r,`component setup() - data.formattedValue`,p.value);function m(e){x(r,`component watch() -> value`,e);let t=D(e,f({...r}),`component watch`);t!==p.value&&(x(r,`component watch() changed -> formatted`,t),p.value=t)}(0,t.watch)(i,m);let h=null,g=n;function _(){let e=f({...r}),t=i.value;if(t===`-`)return;let n=D(t,e,`component opts watch`);if(n!==p.value&&(p.value=n),s.value&&!(o.value&&o.value.number)){n!==t&&n!==h&&(h=n,g(`update:model-value`,n));return}let a=O(n,e,`component opts watch reunformat`),c=Number(t),l=Number(a);!Number.isNaN(c)&&!Number.isNaN(l)&&c!==l&&l!==h&&(h=l,g(`update:model-value`,a))}(0,t.watch)(()=>[r.precision,r.decimal,r.thousands,r.prefix,r.suffix,r.min,r.max,r.setMaxIfBigger,r.allowBlank,r.treatZeroAsBlank,r.minimumNumberOfCharacters,r.shouldRound],_),(0,t.watch)(()=>r.modelModifiers,_,{deep:!0}),(0,t.onMounted)(()=>{let e=f({...r}),t=O(p.value,e,`component mounted reconcile`),n=Number(i.value),a=Number(t);Number.isNaN(n)&&!Number.isNaN(a)&&a!==h&&(h=a,g(`update:model-value`,t))});function v(e){let t=e.target.value;x(r,`component change() -> evt.target.value`,t),s.value&&!o.value.number||(t=O(t,f({...r}),`component change`)),t!==h&&(h=t,x(r,`component change() -> update:model-value`,t),g(`update:model-value`,t))}let y=(0,t.useAttrs)(),b=(0,t.computed)(()=>{let e={...y};return delete e[`onUpdate:modelValue`],e});return(n,i)=>{let a=(0,t.resolveDirective)(`money3`);return(0,t.withDirectives)(((0,t.openBlock)(),(0,t.createElementBlock)(`input`,(0,t.mergeProps)({id:`${e.id}`},b.value,{type:`tel`,class:`v-money3`,value:p.value,disabled:r.disabled,onChange:v}),null,16,U)),[[a,{precision:(0,t.unref)(c),decimal:r.decimal,thousands:r.thousands,prefix:r.prefix,suffix:r.suffix,disableNegative:r.disableNegative,min:r.min,max:r.max,setMaxIfBigger:r.setMaxIfBigger,allowBlank:r.allowBlank,treatZeroAsBlank:r.treatZeroAsBlank,minimumNumberOfCharacters:r.minimumNumberOfCharacters,debug:r.debug,modelModifiers:(0,t.unref)(o),shouldRound:(0,t.unref)(l),focusOnRight:(0,t.unref)(u)}]])}}});e.BigNumber=E,e.Money=W,e.Money3=W,e.Money3Component=W,e.Money3Directive=H,e.VMoney=H,e.VMoney3=H,e.default={install(e){e.component(`money3`,W),e.directive(`money3`,H)}},e.format=D,e.unformat=O});
|