adverich-kun-ui 0.1.370 → 0.1.371
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.
|
@@ -1,24 +1,24 @@
|
|
|
1
|
-
import { getCurrentInstance as
|
|
2
|
-
import U from "../composables/
|
|
3
|
-
import {
|
|
4
|
-
const
|
|
1
|
+
import { getCurrentInstance as P, ref as s, computed as N, watch as R, createElementBlock as o, openBlock as a, createCommentVNode as u, createElementVNode as c, normalizeClass as y, toDisplayString as f, mergeProps as S, renderSlot as V } from "vue";
|
|
2
|
+
import { KunNumberFieldProps as U } from "../composables/KunNumberFieldProps.js";
|
|
3
|
+
import { parseNumber as g } from "../composables/numberFormatUtils.js";
|
|
4
|
+
const x = {
|
|
5
5
|
key: 0,
|
|
6
6
|
class: "mx-2"
|
|
7
|
-
},
|
|
7
|
+
}, H = ["value", "placeholder", "disabled", "readonly", "maxlength", "aria-invalid", "aria-describedby"], M = ["disabled"], T = {
|
|
8
8
|
key: 2,
|
|
9
9
|
class: "flex flex-col items-center justify-center border-l border-slate-600"
|
|
10
|
-
},
|
|
10
|
+
}, q = ["disabled"], G = ["disabled"], J = {
|
|
11
11
|
key: 3,
|
|
12
12
|
class: "ml-2"
|
|
13
|
-
},
|
|
13
|
+
}, L = {
|
|
14
14
|
key: 0,
|
|
15
15
|
class: "h-[1.25rem]"
|
|
16
|
-
},
|
|
16
|
+
}, O = ["id"], Q = {
|
|
17
17
|
key: 1,
|
|
18
18
|
class: "text-xs text-center"
|
|
19
19
|
}, Z = {
|
|
20
20
|
__name: "KunNumberField",
|
|
21
|
-
props:
|
|
21
|
+
props: U,
|
|
22
22
|
emits: [
|
|
23
23
|
"update:modelValue",
|
|
24
24
|
"focus",
|
|
@@ -27,113 +27,124 @@ const H = {
|
|
|
27
27
|
"keyDown",
|
|
28
28
|
"keyUp"
|
|
29
29
|
],
|
|
30
|
-
setup(
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
30
|
+
setup(I, { expose: F, emit: D }) {
|
|
31
|
+
const l = I, n = D, v = `number-input-${P().uid}`, h = s(null), C = s(null), d = s(!1), w = s(""), k = s(!1), i = s(!1), r = s(l.modelValue != null ? m(l.modelValue, l.separator, l.precision) : ""), b = N(() => l.error || !!w.value && k.value), $ = N(() => d.value || !!r.value || l.dirty);
|
|
32
|
+
function m(e, t = ".", p = 2) {
|
|
33
|
+
return e == null || isNaN(e) ? "" : Number(e).toFixed(p).replace(".", t);
|
|
34
|
+
}
|
|
35
|
+
R(() => l.modelValue, (e) => {
|
|
36
|
+
if (i.value) {
|
|
37
|
+
i.value = !1;
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
const t = m(e, l.separator, l.precision);
|
|
41
|
+
t !== r.value && (r.value = t);
|
|
42
|
+
});
|
|
43
|
+
function B(e) {
|
|
44
|
+
r.value = e.target.value;
|
|
45
|
+
const t = g(r.value, l.separator);
|
|
46
|
+
i.value = !0, n("update:modelValue", t);
|
|
47
|
+
}
|
|
48
|
+
function E() {
|
|
49
|
+
d.value = !1, k.value = !0, n("blur");
|
|
50
|
+
}
|
|
51
|
+
function K() {
|
|
52
|
+
d.value = !0, n("focus");
|
|
53
|
+
}
|
|
54
|
+
function j() {
|
|
55
|
+
r.value = "", i.value = !0, n("update:modelValue", null), k.value = !0;
|
|
56
|
+
}
|
|
57
|
+
function z() {
|
|
58
|
+
const t = (g(r.value, l.separator) || 0) + Number(l.step);
|
|
59
|
+
r.value = m(t, l.separator, l.precision), i.value = !0, n("update:modelValue", t);
|
|
60
|
+
}
|
|
61
|
+
function A() {
|
|
62
|
+
const t = (g(r.value, l.separator) || 0) - Number(l.step);
|
|
63
|
+
r.value = m(t, l.separator, l.precision), i.value = !0, n("update:modelValue", t);
|
|
64
|
+
}
|
|
65
|
+
return F({
|
|
66
|
+
inputField: h,
|
|
67
|
+
rootRef: C,
|
|
54
68
|
focus: () => {
|
|
55
69
|
var e;
|
|
56
|
-
return (e =
|
|
70
|
+
return (e = h.value) == null ? void 0 : e.focus();
|
|
57
71
|
}
|
|
58
|
-
}),
|
|
59
|
-
const z = F(
|
|
60
|
-
() => a.density === "compact" ? "p-1" : a.density === "comfortable" ? "p-2" : "p-3"
|
|
61
|
-
);
|
|
62
|
-
return (e, o) => (s(), r("div", {
|
|
72
|
+
}), (e, t) => (a(), o("div", {
|
|
63
73
|
class: "w-full flex flex-col relative",
|
|
64
74
|
ref_key: "rootRef",
|
|
65
|
-
ref:
|
|
75
|
+
ref: C
|
|
66
76
|
}, [
|
|
67
|
-
e.label ? (
|
|
77
|
+
e.label ? (a(), o("label", {
|
|
68
78
|
key: 0,
|
|
69
|
-
for:
|
|
70
|
-
class:
|
|
79
|
+
for: v,
|
|
80
|
+
class: y([
|
|
71
81
|
e.labelColor,
|
|
72
82
|
"absolute left-2 transition-all duration-200 ease-in-out pointer-events-none select-none z-10",
|
|
73
|
-
|
|
83
|
+
$.value ? "-top-2.25 text-xs opacity-80" : "top-3 text-sm opacity-80"
|
|
74
84
|
])
|
|
75
|
-
},
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
class:
|
|
85
|
+
}, f(e.label), 3)) : u("", !0),
|
|
86
|
+
c("div", S({ class: "w-full flex flex-col justify-center relative" }, e.$attrs), [
|
|
87
|
+
c("div", {
|
|
88
|
+
class: y(["flex items-center w-full border", [
|
|
79
89
|
e.bgInput,
|
|
80
90
|
e.rounded,
|
|
81
|
-
|
|
91
|
+
d.value ? "border-blue-600 shadow-[0_0_0_1px_rgba(59,130,246,0.5)]" : e.borderColor,
|
|
82
92
|
e.disabled ? "opacity-60 cursor-not-allowed" : "cursor-text",
|
|
83
|
-
|
|
93
|
+
b.value ? "bg-red-200 dark:bg-red-900" : ""
|
|
84
94
|
]])
|
|
85
95
|
}, [
|
|
86
|
-
e.prefix ? (
|
|
87
|
-
|
|
88
|
-
|
|
96
|
+
e.prefix ? (a(), o("div", x, f(e.prefix), 1)) : u("", !0),
|
|
97
|
+
V(e.$slots, "prepend-inner"),
|
|
98
|
+
c("input", {
|
|
89
99
|
ref_key: "inputField",
|
|
90
|
-
ref:
|
|
91
|
-
id:
|
|
100
|
+
ref: h,
|
|
101
|
+
id: v,
|
|
92
102
|
type: "text",
|
|
93
|
-
value:
|
|
103
|
+
value: r.value,
|
|
94
104
|
placeholder: e.placeholder,
|
|
95
105
|
disabled: e.disabled,
|
|
96
106
|
readonly: e.readonly,
|
|
97
107
|
maxlength: e.maxlength,
|
|
98
108
|
autocomplete: "off",
|
|
99
|
-
"aria-invalid":
|
|
100
|
-
"aria-describedby":
|
|
101
|
-
class:
|
|
102
|
-
onInput:
|
|
103
|
-
onBlur:
|
|
104
|
-
onFocus:
|
|
105
|
-
onKeydown:
|
|
106
|
-
onKeyup:
|
|
107
|
-
}, null, 42,
|
|
108
|
-
e.clearable &&
|
|
109
|
+
"aria-invalid": b.value ? "true" : "false",
|
|
110
|
+
"aria-describedby": b.value ? `error-${v}` : null,
|
|
111
|
+
class: y([e.inputDensity, e.textColor, e.placeholderColor, e.textCenter ? "text-center" : "", "w-full h-full bg-transparent focus:outline-none"]),
|
|
112
|
+
onInput: B,
|
|
113
|
+
onBlur: E,
|
|
114
|
+
onFocus: K,
|
|
115
|
+
onKeydown: t[0] || (t[0] = (p) => n("keyDown", p)),
|
|
116
|
+
onKeyup: t[1] || (t[1] = (p) => n("keyUp", p))
|
|
117
|
+
}, null, 42, H),
|
|
118
|
+
e.clearable && r.value ? (a(), o("button", {
|
|
109
119
|
key: 1,
|
|
110
120
|
type: "button",
|
|
111
|
-
onClick:
|
|
112
|
-
class:
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
121
|
+
onClick: j,
|
|
122
|
+
class: y(["ml-2", e.textColor]),
|
|
123
|
+
disabled: e.disabled || e.readonly
|
|
124
|
+
}, " × ", 10, M)) : u("", !0),
|
|
125
|
+
e.noArrows ? u("", !0) : (a(), o("div", T, [
|
|
126
|
+
c("button", {
|
|
116
127
|
type: "button",
|
|
117
128
|
class: "p-2",
|
|
118
|
-
onClick:
|
|
129
|
+
onClick: z,
|
|
119
130
|
disabled: e.disabled || e.readonly
|
|
120
|
-
}, "▲", 8,
|
|
121
|
-
|
|
131
|
+
}, "▲", 8, q),
|
|
132
|
+
c("button", {
|
|
122
133
|
type: "button",
|
|
123
134
|
class: "p-2",
|
|
124
|
-
onClick:
|
|
135
|
+
onClick: A,
|
|
125
136
|
disabled: e.disabled || e.readonly
|
|
126
|
-
}, "▼", 8,
|
|
137
|
+
}, "▼", 8, G)
|
|
127
138
|
])),
|
|
128
|
-
|
|
129
|
-
e.suffix ? (
|
|
139
|
+
V(e.$slots, "append-inner"),
|
|
140
|
+
e.suffix ? (a(), o("div", J, f(e.suffix), 1)) : u("", !0)
|
|
130
141
|
], 2),
|
|
131
|
-
e.hideDetails ?
|
|
132
|
-
|
|
142
|
+
e.hideDetails ? u("", !0) : (a(), o("div", L, [
|
|
143
|
+
b.value ? (a(), o("div", {
|
|
133
144
|
key: 0,
|
|
134
|
-
id: `error-${
|
|
145
|
+
id: `error-${v}`,
|
|
135
146
|
class: "text-red-500 text-sm text-center"
|
|
136
|
-
},
|
|
147
|
+
}, f(w.value || e.errorMessage), 9, O)) : e.hint && (e.persistentHint || d.value) ? (a(), o("div", Q, f(e.hint), 1)) : u("", !0)
|
|
137
148
|
]))
|
|
138
149
|
], 16)
|
|
139
150
|
], 512));
|
|
@@ -1,18 +1,7 @@
|
|
|
1
|
-
function
|
|
2
|
-
const
|
|
3
|
-
return
|
|
4
|
-
}
|
|
5
|
-
function l(e, n = ",") {
|
|
6
|
-
const r = e.replace(new RegExp(`\\${n}`, "g"), "."), a = parseFloat(r);
|
|
7
|
-
return isNaN(a) ? null : a;
|
|
8
|
-
}
|
|
9
|
-
function c(e, n = ",", r = 2) {
|
|
10
|
-
if (e === null || isNaN(e)) return "";
|
|
11
|
-
const a = Number(e).toFixed(r);
|
|
12
|
-
return n === "," ? a.replace(".", ",") : a;
|
|
1
|
+
function o(r, n = ",") {
|
|
2
|
+
const a = r.replace(new RegExp(`\\${n}`, "g"), "."), e = parseFloat(a);
|
|
3
|
+
return isNaN(e) ? null : e;
|
|
13
4
|
}
|
|
14
5
|
export {
|
|
15
|
-
|
|
16
|
-
t as normalizeNumber,
|
|
17
|
-
l as parseNumber
|
|
6
|
+
o as parseNumber
|
|
18
7
|
};
|
package/package.json
CHANGED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
import { ref as t, inject as N, computed as D, watch as K, onUnmounted as P } from "vue";
|
|
2
|
-
import { debounce as R } from "../../../../utils/utils.js";
|
|
3
|
-
import { formatNumber as i, normalizeNumber as T, parseNumber as U } from "./numberFormatUtils.js";
|
|
4
|
-
function C(e, n) {
|
|
5
|
-
const l = t(i(e.modelValue, e.separator, e.precision)), a = t(e.modelValue), d = t(!1), r = t(""), o = t(!1), F = t(null), g = t(null), h = t(!1), f = N("registerField", null), m = N("unregisterField", null), I = D(() => e.error || !!r.value && o.value), b = async () => {
|
|
6
|
-
for (const u of e.rules) {
|
|
7
|
-
const c = await Promise.resolve(u(a.value));
|
|
8
|
-
if (c !== !0) return c;
|
|
9
|
-
}
|
|
10
|
-
return !0;
|
|
11
|
-
}, V = R(async () => {
|
|
12
|
-
const u = await b();
|
|
13
|
-
r.value = u === !0 ? "" : u;
|
|
14
|
-
}, e.debounce ?? 300);
|
|
15
|
-
K(() => e.modelValue, (u) => {
|
|
16
|
-
u !== a.value && (h.value = !0, a.value = u, l.value = i(u, e.separator, e.precision));
|
|
17
|
-
});
|
|
18
|
-
function y(u) {
|
|
19
|
-
const c = T(u.target.value, e.separator);
|
|
20
|
-
l.value = c;
|
|
21
|
-
const s = U(c, e.separator);
|
|
22
|
-
isNaN(s) || (a.value = s, n("update:modelValue", s), e.validateOnBlur || V());
|
|
23
|
-
}
|
|
24
|
-
function B() {
|
|
25
|
-
d.value = !1, l.value = i(a.value, e.separator, e.precision), e.validateOnBlur && v(), n("blur");
|
|
26
|
-
}
|
|
27
|
-
function w() {
|
|
28
|
-
d.value = !0, n("focus");
|
|
29
|
-
}
|
|
30
|
-
function O() {
|
|
31
|
-
l.value = "", a.value = null, n("update:modelValue", null), o.value = !0, e.validateOnBlur || V();
|
|
32
|
-
}
|
|
33
|
-
function E() {
|
|
34
|
-
let u = a.value || 0;
|
|
35
|
-
u += Number(e.step), a.value = u, l.value = i(u, e.separator, e.precision), n("update:modelValue", u);
|
|
36
|
-
}
|
|
37
|
-
function j() {
|
|
38
|
-
let u = a.value || 0;
|
|
39
|
-
u -= Number(e.step), a.value = u, l.value = i(u, e.separator, e.precision), n("update:modelValue", u);
|
|
40
|
-
}
|
|
41
|
-
async function v() {
|
|
42
|
-
o.value = !0;
|
|
43
|
-
const u = await b();
|
|
44
|
-
return r.value = u === !0 ? "" : u, u === !0;
|
|
45
|
-
}
|
|
46
|
-
function x() {
|
|
47
|
-
a.value = e.modelValue, l.value = i(e.modelValue, e.separator, e.precision), o.value = !1, r.value = "";
|
|
48
|
-
}
|
|
49
|
-
function z() {
|
|
50
|
-
o.value = !1, r.value = "";
|
|
51
|
-
}
|
|
52
|
-
return f && f({ validate: v }), P(() => {
|
|
53
|
-
m && m({ validate: v });
|
|
54
|
-
}), {
|
|
55
|
-
rawInput: l,
|
|
56
|
-
inputValue: a,
|
|
57
|
-
inputField: F,
|
|
58
|
-
rootRef: g,
|
|
59
|
-
inputFocused: d,
|
|
60
|
-
validationError: r,
|
|
61
|
-
hasError: I,
|
|
62
|
-
handleInput: y,
|
|
63
|
-
handleBlur: B,
|
|
64
|
-
focusInput: w,
|
|
65
|
-
clearInput: O,
|
|
66
|
-
onIncrement: E,
|
|
67
|
-
onDecrement: j,
|
|
68
|
-
validate: v,
|
|
69
|
-
reset: x,
|
|
70
|
-
resetValidation: z
|
|
71
|
-
};
|
|
72
|
-
}
|
|
73
|
-
export {
|
|
74
|
-
C as default
|
|
75
|
-
};
|