vueless 0.0.777 → 0.0.779
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/package.json
CHANGED
|
@@ -8,9 +8,10 @@ import UInput from "../ui.form-input/UInput.vue";
|
|
|
8
8
|
|
|
9
9
|
import defaultConfig from "./config.ts";
|
|
10
10
|
import useFormatCurrency from "./useFormatCurrency.ts";
|
|
11
|
-
import { COMPONENT_NAME } from "./constants.ts";
|
|
11
|
+
import { COMPONENT_NAME, RAW_DECIMAL_MARK } from "./constants.ts";
|
|
12
12
|
|
|
13
13
|
import type { Props, Config } from "./types.ts";
|
|
14
|
+
import { getRawValue } from "./utilFormat.ts";
|
|
14
15
|
|
|
15
16
|
defineOptions({ inheritAttrs: false });
|
|
16
17
|
|
|
@@ -52,9 +53,16 @@ const input = computed(() => {
|
|
|
52
53
|
return moneyInputRef.value?.inputRef || null;
|
|
53
54
|
});
|
|
54
55
|
|
|
55
|
-
const stringLocalValue = computed(() =>
|
|
56
|
-
Object.is(localValue.value, -0)
|
|
57
|
-
|
|
56
|
+
const stringLocalValue = computed(() => {
|
|
57
|
+
if (Object.is(localValue.value, -0)) return "-0";
|
|
58
|
+
|
|
59
|
+
const currentRawValue = getRawValue(String(localValue.value), props);
|
|
60
|
+
const fraction = String(currentRawValue).split(RAW_DECIMAL_MARK).at(1) || "";
|
|
61
|
+
|
|
62
|
+
return props.valueType === "number" && !Number.isNaN(parseFloat(String(localValue.value)))
|
|
63
|
+
? parseFloat(String(localValue.value)).toFixed(fraction.length)
|
|
64
|
+
: String(localValue.value);
|
|
65
|
+
});
|
|
58
66
|
|
|
59
67
|
watch(
|
|
60
68
|
() => props.modelValue,
|
|
@@ -67,6 +75,7 @@ watch(
|
|
|
67
75
|
|
|
68
76
|
onMounted(() => {
|
|
69
77
|
if (localValue.value) {
|
|
78
|
+
// console.log(localValue.value);
|
|
70
79
|
setValue(stringLocalValue.value);
|
|
71
80
|
}
|
|
72
81
|
});
|
|
@@ -2,10 +2,11 @@ import { onMounted, nextTick, ref, onBeforeUnmount, toValue, watch, computed, re
|
|
|
2
2
|
|
|
3
3
|
import { getRawValue, getFormattedValue } from "./utilFormat.ts";
|
|
4
4
|
|
|
5
|
+
import { RAW_DECIMAL_MARK } from "./constants.ts";
|
|
6
|
+
|
|
5
7
|
import type { FormatOptions } from "./types.ts";
|
|
6
8
|
|
|
7
9
|
const digitSet = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "0"];
|
|
8
|
-
const rawDecimalMark = ".";
|
|
9
10
|
const comma = ",";
|
|
10
11
|
const minus = "-";
|
|
11
12
|
|
|
@@ -83,7 +84,7 @@ export default function useFormatCurrency(
|
|
|
83
84
|
|
|
84
85
|
const endsWithDecimal = formattedValue.value.endsWith(options.value.decimalSeparator);
|
|
85
86
|
|
|
86
|
-
if ((event.key === comma || event.key ===
|
|
87
|
+
if ((event.key === comma || event.key === RAW_DECIMAL_MARK) && endsWithDecimal) {
|
|
87
88
|
event.preventDefault();
|
|
88
89
|
|
|
89
90
|
return;
|
|
@@ -120,7 +121,7 @@ export default function useFormatCurrency(
|
|
|
120
121
|
}
|
|
121
122
|
|
|
122
123
|
// Replace dot with decimal separator
|
|
123
|
-
if (eventData ===
|
|
124
|
+
if (eventData === RAW_DECIMAL_MARK || eventData === comma) {
|
|
124
125
|
value = [
|
|
125
126
|
...prevValue.value.slice(0, prevCursorPosition),
|
|
126
127
|
options.value.decimalSeparator,
|
|
@@ -145,7 +146,6 @@ export default function useFormatCurrency(
|
|
|
145
146
|
!options.value.minFractionDigits
|
|
146
147
|
) {
|
|
147
148
|
formattedValue.value = value;
|
|
148
|
-
|
|
149
149
|
rawValue.value = newRawValue;
|
|
150
150
|
|
|
151
151
|
return;
|
|
@@ -156,7 +156,7 @@ export default function useFormatCurrency(
|
|
|
156
156
|
const isDoubleMinus = isMinus && prevValue.value.startsWith(minus);
|
|
157
157
|
const isMinusWithin = newRawValue.includes(minus) && !newRawValue.startsWith(minus);
|
|
158
158
|
|
|
159
|
-
const isReservedSymbol = eventData !==
|
|
159
|
+
const isReservedSymbol = eventData !== RAW_DECIMAL_MARK && eventData !== comma;
|
|
160
160
|
|
|
161
161
|
if (
|
|
162
162
|
(!isNumericValue && isReservedSymbol && !isMinus && eventData.length === 1) ||
|
|
@@ -172,7 +172,15 @@ export default function useFormatCurrency(
|
|
|
172
172
|
return;
|
|
173
173
|
}
|
|
174
174
|
|
|
175
|
-
const
|
|
175
|
+
const currentFraction = (newRawValue.split(RAW_DECIMAL_MARK).at(1) || "").slice(
|
|
176
|
+
0,
|
|
177
|
+
options.value.maxFractionDigits,
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
const newFormattedValue = getFormattedValue(newRawValue, {
|
|
181
|
+
...options.value,
|
|
182
|
+
minFractionDigits: currentFraction.length,
|
|
183
|
+
});
|
|
176
184
|
|
|
177
185
|
if (Number.isNaN(newFormattedValue) || newFormattedValue.includes("NaN")) {
|
|
178
186
|
inputElement.value = prevValue.value;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { RAW_DECIMAL_MARK } from "./constants.ts";
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
import type { FormatOptions } from "./types.ts";
|
|
4
4
|
|
|
5
5
|
export function getRawValue(
|
|
6
6
|
value: string,
|
|
@@ -12,7 +12,7 @@ export function getRawValue(
|
|
|
12
12
|
|
|
13
13
|
const rawValueWithPrefix = value
|
|
14
14
|
.replaceAll(thousandsSeparator, "")
|
|
15
|
-
.replace(decimalSeparator,
|
|
15
|
+
.replace(decimalSeparator, RAW_DECIMAL_MARK);
|
|
16
16
|
|
|
17
17
|
return rawValueWithPrefix.replace(prefix, "") as Intl.StringNumericLiteral;
|
|
18
18
|
}
|