adverich-kun-ui 0.1.521 → 0.1.523
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/KunNumberField/src/components/KunNumberField.vue.js +85 -81
- package/dist/components/KunNumberField/src/composables/KunNumberFieldProps.js +6 -1
- package/dist/components/KunNumberField/src/composables/numberFormatUtils.js +8 -24
- package/dist/components/KunNumberField/src/composables/useKunNumberFieldComposable.js +206 -126
- package/package.json +1 -1
|
@@ -1,48 +1,48 @@
|
|
|
1
|
-
import { getCurrentInstance as
|
|
2
|
-
import { KunNumberFieldProps as
|
|
3
|
-
import { useKunNumberField as
|
|
4
|
-
import
|
|
1
|
+
import { getCurrentInstance as E, useSlots as P, nextTick as R, computed as U, createElementBlock as l, openBlock as s, createCommentVNode as n, createElementVNode as d, normalizeClass as c, toDisplayString as u, mergeProps as H, unref as o, createBlock as x, renderSlot as V, createVNode as j, withCtx as L, Fragment as D, renderList as T } from "vue";
|
|
2
|
+
import { KunNumberFieldProps as q } from "../composables/KunNumberFieldProps.js";
|
|
3
|
+
import { useKunNumberField as G } from "../composables/useKunNumberFieldComposable.js";
|
|
4
|
+
import J from "../../../KunBtn/src/components/KunBtn.vue.js";
|
|
5
5
|
import f from "../../../KunIcon/src/components/KunIcon.vue.js";
|
|
6
|
-
import
|
|
7
|
-
const
|
|
6
|
+
import O from "../../../../icons/IconClose.vue.js";
|
|
7
|
+
const Q = {
|
|
8
8
|
key: 0,
|
|
9
9
|
class: "h-full"
|
|
10
|
-
},
|
|
10
|
+
}, W = ["disabled"], X = {
|
|
11
11
|
key: 1,
|
|
12
12
|
class: "mx-2"
|
|
13
|
-
},
|
|
13
|
+
}, Y = {
|
|
14
14
|
key: 2,
|
|
15
15
|
class: "flex items-center justify-center h-full pl-2"
|
|
16
|
-
},
|
|
16
|
+
}, Z = ["value", "placeholder", "readonly", "disabled", "maxlength", "aria-invalid"], _ = {
|
|
17
17
|
key: 3,
|
|
18
18
|
class: "px-2"
|
|
19
|
-
},
|
|
19
|
+
}, ee = {
|
|
20
20
|
key: 0,
|
|
21
21
|
class: "flex items-center h-full"
|
|
22
|
-
},
|
|
22
|
+
}, te = ["disabled"], oe = ["disabled"], re = {
|
|
23
23
|
key: 1,
|
|
24
24
|
class: "flex flex-col items-center justify-center border-l border-slate-600"
|
|
25
|
-
},
|
|
25
|
+
}, se = ["disabled"], le = ["disabled"], ne = {
|
|
26
26
|
key: 5,
|
|
27
27
|
class: "flex items-center justify-center h-full pr-1"
|
|
28
|
-
},
|
|
28
|
+
}, de = {
|
|
29
29
|
key: 6,
|
|
30
30
|
class: "h-full"
|
|
31
|
-
},
|
|
31
|
+
}, ie = ["disabled"], ae = {
|
|
32
32
|
key: 7,
|
|
33
33
|
class: "ml-2"
|
|
34
|
-
},
|
|
34
|
+
}, ue = {
|
|
35
35
|
key: 0,
|
|
36
36
|
class: "h-[1.25rem]"
|
|
37
|
-
},
|
|
37
|
+
}, pe = {
|
|
38
38
|
key: 0,
|
|
39
39
|
class: "text-red-500 text-sm text-center"
|
|
40
|
-
},
|
|
40
|
+
}, be = { key: 0 }, ye = { key: 1 }, ce = {
|
|
41
41
|
key: 1,
|
|
42
42
|
class: "text-xs text-center"
|
|
43
|
-
},
|
|
43
|
+
}, ge = {
|
|
44
44
|
__name: "KunNumberField",
|
|
45
|
-
props:
|
|
45
|
+
props: q,
|
|
46
46
|
emits: [
|
|
47
47
|
"update:modelValue",
|
|
48
48
|
"focus",
|
|
@@ -52,47 +52,50 @@ const O = {
|
|
|
52
52
|
"keyDown",
|
|
53
53
|
"keyUp"
|
|
54
54
|
],
|
|
55
|
-
setup(
|
|
56
|
-
const p =
|
|
55
|
+
setup(F, { expose: K, emit: N }) {
|
|
56
|
+
const p = F, b = N, k = `number-input-${E().uid}`, m = P(), A = !!m["prepend-icon"], B = !!m["append-icon"], {
|
|
57
57
|
inputValue: h,
|
|
58
|
-
numberInput:
|
|
58
|
+
numberInput: y,
|
|
59
59
|
rootRef: v,
|
|
60
60
|
onIncrement: i,
|
|
61
61
|
onDecrement: a,
|
|
62
|
-
onClear:
|
|
63
|
-
validateKey:
|
|
62
|
+
onClear: M,
|
|
63
|
+
validateKey: S,
|
|
64
64
|
focus: w,
|
|
65
65
|
handleFocus: g,
|
|
66
|
-
handleBlur: C
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
66
|
+
handleBlur: C,
|
|
67
|
+
handleInput: I
|
|
68
|
+
} = G(p, b);
|
|
69
|
+
K({
|
|
70
|
+
numberInput: y,
|
|
70
71
|
rootRef: v,
|
|
71
72
|
focus: () => {
|
|
72
|
-
|
|
73
|
+
R(() => {
|
|
73
74
|
var e;
|
|
74
|
-
(e =
|
|
75
|
+
(e = y.value) == null || e.focus();
|
|
75
76
|
});
|
|
76
77
|
}
|
|
77
78
|
});
|
|
78
|
-
const
|
|
79
|
-
|
|
79
|
+
const $ = U(
|
|
80
|
+
() => p.density === "compact" ? "p-1" : p.density === "comfortable" ? "p-2" : "p-3"
|
|
81
|
+
);
|
|
82
|
+
return (e, r) => (s(), l("div", {
|
|
80
83
|
class: "w-full flex flex-col relative h-fit",
|
|
81
84
|
ref_key: "rootRef",
|
|
82
85
|
ref: v
|
|
83
86
|
}, [
|
|
84
|
-
e.label ? (
|
|
87
|
+
e.label ? (s(), l("label", {
|
|
85
88
|
key: 0,
|
|
86
89
|
for: k,
|
|
87
|
-
class:
|
|
90
|
+
class: c([
|
|
88
91
|
e.labelColor,
|
|
89
92
|
"absolute left-2 transition-all duration-200 ease-in-out pointer-events-none select-none z-10",
|
|
90
93
|
"-top-2.25 text-xs opacity-80"
|
|
91
94
|
])
|
|
92
95
|
}, u(e.label), 3)) : n("", !0),
|
|
93
|
-
d("div",
|
|
96
|
+
d("div", H({ class: "w-full flex flex-col justify-center relative" }, e.$attrs), [
|
|
94
97
|
d("div", {
|
|
95
|
-
class:
|
|
98
|
+
class: c(["flex items-center w-full h-full border", [
|
|
96
99
|
e.bgInput,
|
|
97
100
|
e.rounded,
|
|
98
101
|
o(w) ? "border-slate-400 dark:border-slate-600 shadow-[0_0_0_1px_rgba(59,130,246,0.5)]" : e.borderColor,
|
|
@@ -100,25 +103,25 @@ const O = {
|
|
|
100
103
|
e.error ? "bg-red-200 dark:bg-red-900" : ""
|
|
101
104
|
]])
|
|
102
105
|
}, [
|
|
103
|
-
!e.noArrows && e.controlVariant === "split" ? (
|
|
106
|
+
!e.noArrows && e.controlVariant === "split" ? (s(), l("div", Q, [
|
|
104
107
|
d("button", {
|
|
105
108
|
type: "button",
|
|
106
109
|
class: "p-3 text-lg border-r border-slate-600 text-black dark:text-white disabled:opacity-50 cursor-pointer hover:opacity-80",
|
|
107
|
-
onClick:
|
|
110
|
+
onClick: r[0] || (r[0] = (...t) => o(a) && o(a)(...t)),
|
|
108
111
|
disabled: e.disabled || e.readonly
|
|
109
|
-
}, "−", 8,
|
|
112
|
+
}, "−", 8, W)
|
|
110
113
|
])) : n("", !0),
|
|
111
|
-
e.prefix ? (
|
|
112
|
-
e.prependIcon ||
|
|
113
|
-
e.prependIcon ? (
|
|
114
|
+
e.prefix ? (s(), l("div", X, u(e.prefix), 1)) : n("", !0),
|
|
115
|
+
e.prependIcon || A ? (s(), l("div", Y, [
|
|
116
|
+
e.prependIcon ? (s(), x(f, {
|
|
114
117
|
key: 0,
|
|
115
118
|
icon: e.prependIcon
|
|
116
|
-
}, null, 8, ["icon"])) :
|
|
119
|
+
}, null, 8, ["icon"])) : V(e.$slots, "prepend-icon", { key: 1 })
|
|
117
120
|
])) : n("", !0),
|
|
118
121
|
d("input", {
|
|
119
122
|
id: k,
|
|
120
123
|
ref_key: "numberInput",
|
|
121
|
-
ref:
|
|
124
|
+
ref: y,
|
|
122
125
|
type: "text",
|
|
123
126
|
value: o(h),
|
|
124
127
|
placeholder: e.placeholder,
|
|
@@ -126,97 +129,98 @@ const O = {
|
|
|
126
129
|
disabled: e.disabled,
|
|
127
130
|
maxlength: e.maxlength,
|
|
128
131
|
autocomplete: "off",
|
|
129
|
-
class:
|
|
132
|
+
class: c(["w-full h-full bg-transparent rounded focus:outline-none", [$.value, e.textColor, e.placeholderColor, e.textCenter ? "text-center" : ""]]),
|
|
130
133
|
"aria-invalid": e.error ? "true" : "false",
|
|
131
|
-
onBlur:
|
|
132
|
-
onFocus:
|
|
133
|
-
|
|
134
|
-
|
|
134
|
+
onBlur: r[1] || (r[1] = (...t) => o(C) && o(C)(...t)),
|
|
135
|
+
onFocus: r[2] || (r[2] = (...t) => o(g) && o(g)(...t)),
|
|
136
|
+
onInput: r[3] || (r[3] = (...t) => o(I) && o(I)(...t)),
|
|
137
|
+
onKeydown: r[4] || (r[4] = (t) => (o(S)(t), b("keyDown", t))),
|
|
138
|
+
onKeyup: r[5] || (r[5] = (t) => b("keyUp", t)),
|
|
135
139
|
inputmode: "decimal",
|
|
136
140
|
pattern: "[0-9]+([\\.,][0-9]+)?"
|
|
137
|
-
}, null, 42,
|
|
138
|
-
e.clearable && o(h) != null ? (
|
|
139
|
-
|
|
140
|
-
onClick: o(
|
|
141
|
+
}, null, 42, Z),
|
|
142
|
+
e.clearable && o(h) != null ? (s(), l("div", _, [
|
|
143
|
+
j(J, {
|
|
144
|
+
onClick: o(M),
|
|
141
145
|
rounded: "rounded-full",
|
|
142
146
|
bgColor: "bg-red-500/75",
|
|
143
147
|
disabled: e.disabled || e.readonly,
|
|
144
148
|
class: "h-6 w-6"
|
|
145
149
|
}, {
|
|
146
|
-
default:
|
|
147
|
-
|
|
148
|
-
icon:
|
|
150
|
+
default: L(() => [
|
|
151
|
+
j(f, {
|
|
152
|
+
icon: O,
|
|
149
153
|
size: "text-xs"
|
|
150
154
|
})
|
|
151
155
|
]),
|
|
152
156
|
_: 1
|
|
153
157
|
}, 8, ["onClick", "disabled"])
|
|
154
158
|
])) : n("", !0),
|
|
155
|
-
e.noArrows ? n("", !0) : (
|
|
156
|
-
e.controlVariant === "default" ? (
|
|
159
|
+
e.noArrows ? n("", !0) : (s(), l(D, { key: 4 }, [
|
|
160
|
+
e.controlVariant === "default" ? (s(), l("div", ee, [
|
|
157
161
|
d("button", {
|
|
158
162
|
type: "button",
|
|
159
163
|
class: "flex items-center border-l border-slate-600 p-3 justify-center text-black dark:text-white hover:text-black/80 dark:hover:text-white/80 disabled:opacity-50 cursor-pointer hover:opacity-80",
|
|
160
|
-
onClick:
|
|
164
|
+
onClick: r[6] || (r[6] = (...t) => o(i) && o(i)(...t)),
|
|
161
165
|
disabled: e.disabled || e.readonly
|
|
162
|
-
}, "
|
|
166
|
+
}, "▲", 8, te),
|
|
163
167
|
d("button", {
|
|
164
168
|
type: "button",
|
|
165
169
|
class: "flex items-center border-l border-slate-600 p-3 justify-center text-black dark:text-white hover:text-black/80 dark:hover:text-white/80 disabled:opacity-50 cursor-pointer hover:opacity-80",
|
|
166
|
-
onClick:
|
|
170
|
+
onClick: r[7] || (r[7] = (...t) => o(a) && o(a)(...t)),
|
|
167
171
|
disabled: e.disabled || e.readonly
|
|
168
|
-
}, "
|
|
172
|
+
}, "▼", 8, oe)
|
|
169
173
|
])) : n("", !0),
|
|
170
|
-
e.controlVariant === "stacked" ? (
|
|
174
|
+
e.controlVariant === "stacked" ? (s(), l("div", re, [
|
|
171
175
|
d("div", {
|
|
172
176
|
class: "border-b border-slate-600 pb-1 px-3 flex hover:opacity-80 cursor-pointer",
|
|
173
|
-
onClick:
|
|
177
|
+
onClick: r[8] || (r[8] = (...t) => o(i) && o(i)(...t))
|
|
174
178
|
}, [
|
|
175
179
|
d("button", {
|
|
176
180
|
type: "button",
|
|
177
181
|
class: "text-xs text-black dark:text-white hover:text-black/80 dark:hover:text-white/80 disabled:opacity-50 cursor-pointer",
|
|
178
182
|
disabled: e.disabled || e.readonly
|
|
179
|
-
}, "▲", 8,
|
|
183
|
+
}, "▲", 8, se)
|
|
180
184
|
]),
|
|
181
185
|
d("div", {
|
|
182
186
|
class: "border-t border-slate-600 pt-1 px-3 flex hover:opacity-80 cursor-pointer",
|
|
183
|
-
onClick:
|
|
187
|
+
onClick: r[9] || (r[9] = (...t) => o(a) && o(a)(...t))
|
|
184
188
|
}, [
|
|
185
189
|
d("button", {
|
|
186
190
|
type: "button",
|
|
187
191
|
class: "text-xs text-black dark:text-white hover:text-black/80 dark:hover:text-white/80 disabled:opacity-50 cursor-pointer",
|
|
188
192
|
disabled: e.disabled || e.readonly
|
|
189
|
-
}, "▼", 8,
|
|
193
|
+
}, "▼", 8, le)
|
|
190
194
|
])
|
|
191
195
|
])) : n("", !0)
|
|
192
196
|
], 64)),
|
|
193
|
-
e.appendIcon ||
|
|
194
|
-
e.appendIcon ? (
|
|
197
|
+
e.appendIcon || B ? (s(), l("div", ne, [
|
|
198
|
+
e.appendIcon ? (s(), x(f, {
|
|
195
199
|
key: 0,
|
|
196
200
|
icon: e.appendIcon
|
|
197
|
-
}, null, 8, ["icon"])) :
|
|
201
|
+
}, null, 8, ["icon"])) : V(e.$slots, "append-icon", { key: 1 })
|
|
198
202
|
])) : n("", !0),
|
|
199
|
-
!e.noArrows && e.controlVariant === "split" ? (
|
|
203
|
+
!e.noArrows && e.controlVariant === "split" ? (s(), l("div", de, [
|
|
200
204
|
d("button", {
|
|
201
205
|
type: "button",
|
|
202
206
|
class: "p-3 text-lg border-l border-slate-600 text-black dark:text-white disabled:opacity-50 cursor-pointer hover:opacity-80",
|
|
203
|
-
onClick:
|
|
207
|
+
onClick: r[10] || (r[10] = (...t) => o(i) && o(i)(...t)),
|
|
204
208
|
disabled: e.disabled || e.readonly
|
|
205
|
-
}, "+", 8,
|
|
209
|
+
}, "+", 8, ie)
|
|
206
210
|
])) : n("", !0),
|
|
207
|
-
e.suffix ? (
|
|
211
|
+
e.suffix ? (s(), l("div", ae, u(e.suffix), 1)) : n("", !0)
|
|
208
212
|
], 2),
|
|
209
|
-
e.hideDetails ? n("", !0) : (
|
|
210
|
-
e.error || e.errorMessages ? (
|
|
211
|
-
Array.isArray(e.errorMessages) ? (
|
|
212
|
-
(
|
|
213
|
-
])) : typeof e.errorMessages == "string" ? (
|
|
214
|
-
])) : e.hint && (e.persistentHint || o(w)) ? (
|
|
213
|
+
e.hideDetails ? n("", !0) : (s(), l("div", ue, [
|
|
214
|
+
e.error || e.errorMessages ? (s(), l("div", pe, [
|
|
215
|
+
Array.isArray(e.errorMessages) ? (s(), l("div", be, [
|
|
216
|
+
(s(!0), l(D, null, T(e.errorMessages, (t, z) => (s(), l("div", { key: z }, u(t), 1))), 128))
|
|
217
|
+
])) : typeof e.errorMessages == "string" ? (s(), l("div", ye, u(e.errorMessages), 1)) : n("", !0)
|
|
218
|
+
])) : e.hint && (e.persistentHint || o(w)) ? (s(), l("div", ce, u(e.hint), 1)) : n("", !0)
|
|
215
219
|
]))
|
|
216
220
|
], 16)
|
|
217
221
|
], 512));
|
|
218
222
|
}
|
|
219
223
|
};
|
|
220
224
|
export {
|
|
221
|
-
|
|
225
|
+
ge as default
|
|
222
226
|
};
|
|
@@ -43,7 +43,12 @@ const e = {
|
|
|
43
43
|
locale: { type: String, default: "es-AR" },
|
|
44
44
|
separator: { type: String, default: "," },
|
|
45
45
|
useGrouping: { type: Boolean, default: !0 },
|
|
46
|
-
precision: { type: [Number, String], default: 2 }
|
|
46
|
+
precision: { type: [Number, String], default: 2 },
|
|
47
|
+
formatMode: {
|
|
48
|
+
type: String,
|
|
49
|
+
default: "natural"
|
|
50
|
+
// 'bank' | 'natural'
|
|
51
|
+
}
|
|
47
52
|
};
|
|
48
53
|
export {
|
|
49
54
|
e as KunNumberFieldProps
|
|
@@ -1,35 +1,19 @@
|
|
|
1
|
-
function
|
|
1
|
+
function o(t, n, r) {
|
|
2
2
|
return Math.min(Math.max(t, Number(n)), Number(r));
|
|
3
3
|
}
|
|
4
|
-
function
|
|
5
|
-
const m = typeof t == "number" ? t : parseFloat(t);
|
|
6
|
-
if (n === 0)
|
|
7
|
-
return new Intl.NumberFormat(r, {
|
|
8
|
-
minimumFractionDigits: 0,
|
|
9
|
-
maximumFractionDigits: 0,
|
|
10
|
-
useGrouping: e
|
|
11
|
-
}).format(Math.round(m));
|
|
12
|
-
const a = m.toFixed(n);
|
|
13
|
-
return new Intl.NumberFormat(r, {
|
|
14
|
-
minimumFractionDigits: n,
|
|
15
|
-
maximumFractionDigits: n,
|
|
16
|
-
useGrouping: e
|
|
17
|
-
}).format(parseFloat(a));
|
|
18
|
-
}
|
|
19
|
-
function i(t, n) {
|
|
4
|
+
function c(t, n) {
|
|
20
5
|
const r = typeof t == "number" ? t : parseFloat(t);
|
|
21
6
|
return n === 0 ? Math.round(r).toString() : r.toFixed(n).replace(".", "").replace(",", "");
|
|
22
7
|
}
|
|
23
|
-
function
|
|
8
|
+
function m(t, n) {
|
|
24
9
|
if (!t || t.length === 0) return 0;
|
|
25
10
|
if (n === 0)
|
|
26
11
|
return parseInt(t, 10) || 0;
|
|
27
|
-
const r = t.padStart(n + 1, "0"), e = r.slice(0, -n),
|
|
28
|
-
return parseFloat(
|
|
12
|
+
const r = t.padStart(n + 1, "0"), e = r.slice(0, -n), a = r.slice(-n), u = `${e}.${a}`;
|
|
13
|
+
return parseFloat(u);
|
|
29
14
|
}
|
|
30
15
|
export {
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
i as toRawNumberString
|
|
16
|
+
o as clamp,
|
|
17
|
+
m as fromRawString,
|
|
18
|
+
c as toRawNumberString
|
|
35
19
|
};
|
|
@@ -1,158 +1,238 @@
|
|
|
1
|
-
import { ref as
|
|
2
|
-
import {
|
|
3
|
-
function
|
|
4
|
-
const
|
|
5
|
-
let
|
|
6
|
-
const
|
|
7
|
-
const e = Number(
|
|
1
|
+
import { ref as V, computed as Z, watch as _, nextTick as b } from "vue";
|
|
2
|
+
import { clamp as v, toRawNumberString as k, fromRawString as M } from "./numberFormatUtils.js";
|
|
3
|
+
function te(n, s) {
|
|
4
|
+
const r = V(""), o = V(null), T = V(null), w = V(!1), h = V(0);
|
|
5
|
+
let a = "";
|
|
6
|
+
const I = Z(() => {
|
|
7
|
+
const e = Number(n.precision);
|
|
8
8
|
return e > 0 ? e + 1 : 1;
|
|
9
9
|
});
|
|
10
|
-
function
|
|
11
|
-
|
|
10
|
+
function d(e, t = 2, l = !1) {
|
|
11
|
+
if (e == null || isNaN(e)) return "";
|
|
12
|
+
const u = Number(t), f = Number(e) < 0 ? "-" : "", i = Math.abs(Number(e));
|
|
13
|
+
let c = k(i, u);
|
|
14
|
+
const m = u + 1;
|
|
15
|
+
c.length < m && (c = c.padStart(m, "0"));
|
|
16
|
+
const N = c.slice(0, c.length - u) || "0";
|
|
17
|
+
let S = u > 0 ? c.slice(-u) : "";
|
|
18
|
+
u > 0 && l && (S = S.replace(/0+$/, ""));
|
|
19
|
+
const D = N.replace(/\B(?=(\d{3})+(?!\d))/g, ".");
|
|
20
|
+
return u === 0 || !S || S.length === 0 ? f + D : f + D + "," + S;
|
|
12
21
|
}
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
if (!a.value) return;
|
|
32
|
-
const S = l.value.search(/\d/);
|
|
33
|
-
a.value.setSelectionRange(S, S);
|
|
34
|
-
});
|
|
22
|
+
function L(e) {
|
|
23
|
+
if (e == null) return NaN;
|
|
24
|
+
let t = String(e).trim();
|
|
25
|
+
return t ? (t = t.replace(/\s+/g, ""), t = t.replace(/\./g, ""), t = t.replace(/,/g, "."), t = t.replace(/[^0-9\.\-]/g, ""), t === "" ? NaN : parseFloat(t)) : NaN;
|
|
26
|
+
}
|
|
27
|
+
function $(e) {
|
|
28
|
+
const t = o.value;
|
|
29
|
+
if (!t) return;
|
|
30
|
+
let l = t.value;
|
|
31
|
+
const u = Number(n.precision), f = t.selectionStart || 0;
|
|
32
|
+
if (u === 0) {
|
|
33
|
+
let i = l.replace(/[^0-9\-]/g, "");
|
|
34
|
+
i = i.replace(/^0+(\d)/, "$1"), r.value = i, b(() => {
|
|
35
|
+
if (!o.value) return;
|
|
36
|
+
o.value.value = i;
|
|
37
|
+
const c = Math.min(i.length, f);
|
|
38
|
+
o.value.setSelectionRange(c, c);
|
|
39
|
+
}), s("input", i);
|
|
35
40
|
return;
|
|
36
41
|
}
|
|
37
|
-
if (
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
42
|
+
if (l = l.replace(/\./g, ",").replace(/\s+/g, ""), l = l.replace(/[^0-9,\-]/g, ""), (l.match(/,/g) || []).length > 1) {
|
|
43
|
+
const i = l.split(","), c = i.shift() || "", m = i.join("");
|
|
44
|
+
l = c + (m.length ? "," + m : "");
|
|
45
|
+
}
|
|
46
|
+
if (l.includes(",")) {
|
|
47
|
+
const [i, c = ""] = l.split(","), m = c.slice(0, u);
|
|
48
|
+
l = i + (m.length ? "," + m : ",");
|
|
49
|
+
}
|
|
50
|
+
r.value = l, b(A), b(() => {
|
|
51
|
+
const i = f;
|
|
52
|
+
t.setSelectionRange(i, i);
|
|
53
|
+
}), s("input", l);
|
|
54
|
+
}
|
|
55
|
+
function A() {
|
|
56
|
+
o.value && (o.value.value = r.value);
|
|
57
|
+
}
|
|
58
|
+
function K(e) {
|
|
59
|
+
if (w.value = !0, !o.value) return;
|
|
60
|
+
const t = Number(n.modelValue), l = Number(n.precision);
|
|
61
|
+
if (isNaN(t)) {
|
|
62
|
+
r.value = "", s("focus");
|
|
43
63
|
return;
|
|
44
64
|
}
|
|
45
|
-
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
t = t.substring(0, f) + n + t.substring(f), o.value = f + 1;
|
|
54
|
-
else if (v && T > 0) {
|
|
55
|
-
const c = y(l.value, T), S = c - 1;
|
|
56
|
-
if (t.length <= Number(i.precision) + 1) {
|
|
57
|
-
const j = Math.max(0, c - 1);
|
|
58
|
-
t = t.slice(0, j) + t.slice(c), t = N(t), o.value = c, A();
|
|
59
|
-
return;
|
|
65
|
+
let u = k(Math.abs(t), l);
|
|
66
|
+
const f = u.slice(0, u.length - l) || "0";
|
|
67
|
+
let i = l > 0 ? u.slice(-l) : "";
|
|
68
|
+
l > 0 && (i = i.replace(/0+$/, "")), r.value = (t < 0 ? "-" : "") + f + (i.length ? "," + i : ""), b(() => {
|
|
69
|
+
try {
|
|
70
|
+
const c = r.value.length;
|
|
71
|
+
o.value.setSelectionRange(c, c);
|
|
72
|
+
} catch {
|
|
60
73
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
return
|
|
72
|
-
}
|
|
73
|
-
function
|
|
74
|
-
let
|
|
74
|
+
}), s("focus");
|
|
75
|
+
}
|
|
76
|
+
function C() {
|
|
77
|
+
w.value = !1;
|
|
78
|
+
let e = (r.value ?? "").toString().trim();
|
|
79
|
+
e || (e = "0");
|
|
80
|
+
let t = L(e);
|
|
81
|
+
isNaN(t) && (t = 0), t = v(t, n.min, n.max), r.value = d(t, Number(n.precision), !1), s("update:modelValue", t), s("blur");
|
|
82
|
+
}
|
|
83
|
+
function x(e) {
|
|
84
|
+
return Number(n.precision) === 0 ? e === "" ? "0" : e.replace(/^0+(\d)/, "$1") : e.padStart(I.value, "0");
|
|
85
|
+
}
|
|
86
|
+
function F(e, t) {
|
|
87
|
+
let l = 0;
|
|
88
|
+
for (let u = 0; u < t; u++)
|
|
89
|
+
/\d/.test(e[u]) && l++;
|
|
90
|
+
return l;
|
|
91
|
+
}
|
|
92
|
+
function E(e, t) {
|
|
93
|
+
let l = 0;
|
|
75
94
|
for (let u = 0; u < e.length; u++)
|
|
76
95
|
if (/\d/.test(e[u])) {
|
|
77
|
-
if (
|
|
78
|
-
|
|
79
|
-
r++;
|
|
96
|
+
if (l === t) return u;
|
|
97
|
+
l++;
|
|
80
98
|
}
|
|
81
99
|
for (let u = e.length - 1; u >= 0; u--)
|
|
82
|
-
if (/\d/.test(e[u]))
|
|
83
|
-
return u + 1;
|
|
100
|
+
if (/\d/.test(e[u])) return u + 1;
|
|
84
101
|
return e.length;
|
|
85
102
|
}
|
|
86
|
-
function
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
const r = e.search(/\d/);
|
|
93
|
-
return n < r && (n = r), n;
|
|
94
|
-
}
|
|
95
|
-
function A() {
|
|
96
|
-
const e = Number(i.precision) + 1;
|
|
97
|
-
t.padStart(e, "0");
|
|
98
|
-
const n = Math.max(1, t.length - Number(i.precision)), r = t.slice(0, n) || "0", u = t.slice(n).padEnd(Number(i.precision), "0").slice(0, Number(i.precision)), v = `${r}.${u}`, g = parseFloat(v), d = x(g, i.min, i.max);
|
|
99
|
-
t = D(d, Number(i.precision)), l.value = h(d, i), s("update:modelValue", d), s("input", d), V(() => {
|
|
100
|
-
if (a.value)
|
|
103
|
+
function y() {
|
|
104
|
+
const e = Number(n.precision) + 1;
|
|
105
|
+
a = String(a || "").padStart(e, "0");
|
|
106
|
+
const t = Math.max(1, a.length - Number(n.precision)), l = a.slice(0, t) || "0", u = a.slice(t).padEnd(Number(n.precision), "0").slice(0, Number(n.precision)), f = `${l}.${u}`, i = parseFloat(f), c = v(i, n.min, n.max);
|
|
107
|
+
a = k(c, Number(n.precision)), r.value = d(c, Number(n.precision), !1), s("update:modelValue", c), s("input", c), b(() => {
|
|
108
|
+
if (o.value)
|
|
101
109
|
try {
|
|
102
|
-
const
|
|
103
|
-
let
|
|
104
|
-
for (;
|
|
105
|
-
|
|
106
|
-
a.value.setSelectionRange(m, m);
|
|
110
|
+
const m = r.value;
|
|
111
|
+
let N = E(m, h.value);
|
|
112
|
+
for (; N < m.length && !/\d/.test(m[N]); ) N++;
|
|
113
|
+
o.value.setSelectionRange(N, N);
|
|
107
114
|
} catch {
|
|
108
|
-
|
|
115
|
+
o.value.setSelectionRange(r.value.length, r.value.length);
|
|
109
116
|
}
|
|
110
117
|
});
|
|
111
118
|
}
|
|
112
|
-
function
|
|
113
|
-
|
|
114
|
-
const e =
|
|
115
|
-
|
|
116
|
-
}
|
|
117
|
-
function
|
|
118
|
-
|
|
119
|
-
var
|
|
120
|
-
if (!
|
|
121
|
-
if ((e == null ? void 0 : e.relatedTarget) !== void 0 || ((
|
|
122
|
-
const u =
|
|
123
|
-
|
|
119
|
+
function H() {
|
|
120
|
+
w.value = !1, a = x(a);
|
|
121
|
+
const e = M(a, Number(n.precision)), t = v(e, n.min, n.max);
|
|
122
|
+
a = k(t, Number(n.precision)), a = x(a), r.value = d(t, Number(n.precision), !1), s("update:modelValue", t), s("blur");
|
|
123
|
+
}
|
|
124
|
+
function j(e) {
|
|
125
|
+
w.value = !0, b(() => {
|
|
126
|
+
var l;
|
|
127
|
+
if (!o.value) return;
|
|
128
|
+
if ((e == null ? void 0 : e.relatedTarget) !== void 0 || ((l = e == null ? void 0 : e.sourceCapabilities) == null ? void 0 : l.firesTouchEvents) === !1) {
|
|
129
|
+
const u = r.value.length;
|
|
130
|
+
o.value.setSelectionRange(u, u), h.value = r.value.replace(/\D/g, "").length;
|
|
124
131
|
} else {
|
|
125
|
-
const u =
|
|
126
|
-
|
|
132
|
+
const u = o.value.selectionStart || 0;
|
|
133
|
+
h.value = F(r.value, u);
|
|
127
134
|
}
|
|
128
135
|
}), s("focus");
|
|
129
136
|
}
|
|
130
|
-
function
|
|
131
|
-
|
|
132
|
-
|
|
137
|
+
function U(e) {
|
|
138
|
+
var t;
|
|
139
|
+
(t = e.preventDefault) == null || t.call(e);
|
|
133
140
|
}
|
|
134
|
-
function
|
|
135
|
-
|
|
136
|
-
|
|
141
|
+
function q(e) {
|
|
142
|
+
if (n.formatMode !== "bank") return;
|
|
143
|
+
const { key: t, target: l } = e, u = /^[0-9]$/.test(t), f = t === "Backspace", i = t === "Delete", c = ["ArrowLeft", "ArrowRight", "ArrowUp", "ArrowDown"].includes(t), m = e.ctrlKey || e.metaKey, N = t === "Home", S = t === "End";
|
|
144
|
+
if (t === "Tab") return;
|
|
145
|
+
if (N) {
|
|
146
|
+
b(() => {
|
|
147
|
+
if (!o.value) return;
|
|
148
|
+
const P = r.value.search(/\d/);
|
|
149
|
+
o.value.setSelectionRange(P, P);
|
|
150
|
+
});
|
|
151
|
+
return;
|
|
152
|
+
}
|
|
153
|
+
if (S) {
|
|
154
|
+
b(() => {
|
|
155
|
+
if (!o.value) return;
|
|
156
|
+
const R = r.value;
|
|
157
|
+
o.value.setSelectionRange(R.length, R.length);
|
|
158
|
+
});
|
|
159
|
+
return;
|
|
160
|
+
}
|
|
161
|
+
if (c || m) return;
|
|
162
|
+
const X = (l == null ? void 0 : l.selectionStart) ?? 0, Y = r.value || "", g = F(Y, X);
|
|
163
|
+
e.preventDefault();
|
|
164
|
+
const B = Number(n.precision) + 1;
|
|
165
|
+
for (; a.length < B; ) a = "0" + a;
|
|
166
|
+
if (u)
|
|
167
|
+
a = a.substring(0, g) + t + a.substring(g), h.value = g + 1;
|
|
168
|
+
else if (f) {
|
|
169
|
+
if (g > 0) {
|
|
170
|
+
const R = g - 1;
|
|
171
|
+
a = a.substring(0, R) + a.substring(R + 1), h.value = R;
|
|
172
|
+
}
|
|
173
|
+
} else if (i)
|
|
174
|
+
g < a.length && (a = a.substring(0, g) + a.substring(g + 1), h.value = g);
|
|
175
|
+
else return;
|
|
176
|
+
for (; a.length < B; ) a = "0" + a;
|
|
177
|
+
y();
|
|
137
178
|
}
|
|
138
179
|
function z() {
|
|
139
|
-
|
|
140
|
-
|
|
180
|
+
let e;
|
|
181
|
+
n.formatMode === "bank" ? (e = M(a, Number(n.precision)) || 0, e = v(e + Number(n.step), n.min, n.max), a = k(e, Number(n.precision)), r.value = d(e, Number(n.precision), !1), s("update:modelValue", e), s("input", e)) : (e = Number(n.modelValue ?? 0) || 0, e = v(e + Number(n.step), n.min, n.max), r.value = d(e, Number(n.precision), !1), s("update:modelValue", e), s("input", e));
|
|
182
|
+
}
|
|
183
|
+
function G() {
|
|
184
|
+
let e;
|
|
185
|
+
n.formatMode === "bank" ? (e = M(a, Number(n.precision)) || 0, e = v(e - Number(n.step), n.min, n.max), a = k(e, Number(n.precision)), r.value = d(e, Number(n.precision), !1), s("update:modelValue", e), s("input", e)) : (e = Number(n.modelValue ?? 0) || 0, e = v(e - Number(n.step), n.min, n.max), r.value = d(e, Number(n.precision), !1), s("update:modelValue", e), s("input", e));
|
|
186
|
+
}
|
|
187
|
+
function J() {
|
|
188
|
+
n.formatMode === "bank" ? (a = "0".repeat(Number(n.precision) + 1), h.value = Number(n.precision) + 1, y(), b(() => {
|
|
189
|
+
var e, t;
|
|
190
|
+
return (t = (e = o.value) == null ? void 0 : e.focus) == null ? void 0 : t.call(e);
|
|
191
|
+
})) : (r.value = "", s("update:modelValue", null), b(() => {
|
|
192
|
+
var e, t;
|
|
193
|
+
return (t = (e = o.value) == null ? void 0 : e.focus) == null ? void 0 : t.call(e);
|
|
194
|
+
}));
|
|
195
|
+
}
|
|
196
|
+
_(
|
|
197
|
+
[() => n.modelValue, () => n.precision, () => n.formatMode],
|
|
198
|
+
([e, t, l]) => {
|
|
199
|
+
if (l !== "bank") {
|
|
200
|
+
r.value = d(Number(e ?? 0), Number(t), !1);
|
|
201
|
+
return;
|
|
202
|
+
}
|
|
203
|
+
if (e == null || isNaN(e))
|
|
204
|
+
r.value = d(0, Number(t), !1), a = "0".repeat(Number(t) + 1);
|
|
205
|
+
else {
|
|
206
|
+
const u = Number(e), f = v(u, n.min, n.max);
|
|
207
|
+
a = k(f, Number(t)), a.length < Number(t) + 1 && (a = a.padStart(Number(t) + 1, "0")), r.value = d(f, Number(t), !1);
|
|
208
|
+
}
|
|
209
|
+
},
|
|
210
|
+
{ immediate: !0 }
|
|
211
|
+
);
|
|
212
|
+
function O(e) {
|
|
213
|
+
return n.formatMode !== "bank" ? $() : U(e);
|
|
214
|
+
}
|
|
215
|
+
function Q(e) {
|
|
216
|
+
return n.formatMode !== "bank" ? K() : j(e);
|
|
217
|
+
}
|
|
218
|
+
function W(e) {
|
|
219
|
+
return n.formatMode !== "bank" ? C() : H();
|
|
141
220
|
}
|
|
142
221
|
return {
|
|
143
|
-
inputValue:
|
|
144
|
-
numberInput:
|
|
145
|
-
rootRef:
|
|
146
|
-
validateKey:
|
|
147
|
-
handleFocus:
|
|
148
|
-
handleBlur:
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
222
|
+
inputValue: r,
|
|
223
|
+
numberInput: o,
|
|
224
|
+
rootRef: T,
|
|
225
|
+
validateKey: q,
|
|
226
|
+
handleFocus: Q,
|
|
227
|
+
handleBlur: W,
|
|
228
|
+
handleInput: O,
|
|
229
|
+
onIncrement: z,
|
|
230
|
+
onDecrement: G,
|
|
231
|
+
onClear: J,
|
|
232
|
+
isActive: w,
|
|
233
|
+
focus: w
|
|
154
234
|
};
|
|
155
235
|
}
|
|
156
236
|
export {
|
|
157
|
-
|
|
237
|
+
te as useKunNumberField
|
|
158
238
|
};
|