vueless 0.0.767 → 0.0.768

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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vueless",
3
- "version": "0.0.767",
3
+ "version": "0.0.768",
4
4
  "license": "MIT",
5
5
  "description": "Vue Styleless UI Component Library, powered by Tailwind CSS.",
6
6
  "keywords": [
@@ -56,19 +56,21 @@ watch(
56
56
  () => props.modelValue,
57
57
  () => {
58
58
  if (String(localValue.value) !== String(rawValue.value)) {
59
- setValue(localValue.value);
59
+ setValue(String(localValue.value));
60
60
  }
61
61
  },
62
62
  );
63
63
 
64
64
  onMounted(() => {
65
65
  if (localValue.value) {
66
- setValue(localValue.value);
66
+ setValue(String(localValue.value));
67
67
  }
68
68
  });
69
69
 
70
70
  function onKeyup(event: KeyboardEvent) {
71
- localValue.value = rawValue.value || "";
71
+ const numberValue = rawValue.value ? parseFloat(rawValue.value) : "";
72
+
73
+ localValue.value = props.valueType === "number" ? numberValue : rawValue.value || "";
72
74
 
73
75
  nextTick(() => emit("keyup", event));
74
76
  }
@@ -9,6 +9,7 @@ export default /*tw*/ {
9
9
  thousandsSeparator: " ",
10
10
  labelAlign: "topInside",
11
11
  prefix: "",
12
+ valueType: "number",
12
13
  positiveOnly: false,
13
14
  readonly: false,
14
15
  disabled: false,
@@ -17,7 +17,13 @@ export interface Props {
17
17
  /**
18
18
  * Input value.
19
19
  */
20
- modelValue?: string;
20
+ modelValue?: string | number;
21
+
22
+ /**
23
+ * Set type of the modelValue.
24
+ */
25
+ valueType?: "string" | "number";
26
+
21
27
  /**
22
28
  * Input label.
23
29
  */
@@ -7,7 +7,6 @@ import type { FormatOptions } from "./types.ts";
7
7
  const digitSet = ["1", "2", "3", "4", "5", "6", "7", "9", "0"];
8
8
  const rawDecimalMark = ".";
9
9
  const comma = ",";
10
- const arrowKeys = ["ArrowUp", "ArrowRight", "ArrowDown", "ArrowLeft"];
11
10
  const minus = "-";
12
11
 
13
12
  export default function useFormatCurrency(
@@ -62,8 +61,6 @@ export default function useFormatCurrency(
62
61
 
63
62
  const cursorStart = inputElement.selectionStart || 0;
64
63
  const cursorEnd = inputElement.selectionEnd || 0;
65
- const isEndOfValue = cursorEnd === formattedValue.value.length;
66
- const isKeyCombination = event.ctrlKey || event.shiftKey || event.metaKey || event.altKey;
67
64
  const isSelection = cursorEnd !== cursorStart;
68
65
 
69
66
  if (event.key === "Backspace" && !isSelection) {
@@ -85,25 +82,12 @@ export default function useFormatCurrency(
85
82
  }
86
83
 
87
84
  const endsWithDecimal = formattedValue.value.endsWith(options.value.decimalSeparator);
88
- const includesDecimalMark =
89
- formattedValue.value.includes(options.value.decimalSeparator) && !endsWithDecimal;
90
- const isCharKey = !arrowKeys.includes(event.key) && !isKeyCombination;
91
85
 
92
86
  if ((event.key === comma || event.key === rawDecimalMark) && endsWithDecimal) {
93
87
  event.preventDefault();
94
88
 
95
89
  return;
96
90
  }
97
-
98
- if (isEndOfValue && includesDecimalMark && isCharKey && !isSelection) {
99
- const fraction = prevValue.value.split(options.value.decimalSeparator).at(-1) || "";
100
-
101
- if (fraction.length >= options.value.maxFractionDigits) {
102
- event.preventDefault();
103
- }
104
-
105
- return;
106
- }
107
91
  }
108
92
 
109
93
  async function onInput(event: Event) {
@@ -146,13 +130,25 @@ export default function useFormatCurrency(
146
130
  value = value.split("").with(value.lastIndexOf(options.value.decimalSeparator), "").join("");
147
131
  }
148
132
 
149
- if (value.endsWith(options.value.decimalSeparator)) {
133
+ const decimalSeparatorIndex = value.indexOf(options.value.decimalSeparator);
134
+ const newRawValue = getRawValue(value, options.value);
135
+
136
+ const isEventDataDecimal =
137
+ value.endsWith(options.value.decimalSeparator) ||
138
+ value.endsWith(`${options.value.decimalSeparator}0`);
139
+
140
+ if (
141
+ isEventDataDecimal &&
142
+ cursorStart > decimalSeparatorIndex &&
143
+ !options.value.minFractionDigits
144
+ ) {
150
145
  formattedValue.value = value;
151
146
 
147
+ rawValue.value = newRawValue;
148
+
152
149
  return;
153
150
  }
154
151
 
155
- const newRawValue = getRawValue(value, options.value);
156
152
  const isNumericValue = eventData && digitSet.includes(eventData);
157
153
  const isMinus = cursorEnd === 1 && cursorStart === 1 && eventData === minus;
158
154
  const isDoubleMinus = isMinus && prevValue.value.startsWith(minus);