@canutin/svelte-currency-input 0.11.2 → 0.11.4
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/CurrencyInput.svelte +19 -7
- package/package.json +1 -4
|
@@ -50,8 +50,13 @@ const handleKeyDown = (event) => {
|
|
|
50
50
|
if (isPunctuationDuplicated() || !isDeletion && !isModifier && !isArrowKey && isInvalidCharacter && !isTab)
|
|
51
51
|
event.preventDefault();
|
|
52
52
|
};
|
|
53
|
-
const handleOnBlur = () => setFormattedValue(
|
|
54
|
-
|
|
53
|
+
const handleOnBlur = () => setFormattedValue();
|
|
54
|
+
let dom;
|
|
55
|
+
let inputElement;
|
|
56
|
+
onMount(() => {
|
|
57
|
+
dom = document;
|
|
58
|
+
setFormattedValue();
|
|
59
|
+
});
|
|
55
60
|
let inputTarget;
|
|
56
61
|
const currencyDecimal = new Intl.NumberFormat(locale).format(1.1).charAt(1);
|
|
57
62
|
const isDecimalComma = currencyDecimal === ",";
|
|
@@ -88,17 +93,23 @@ const setUnformattedValue = (event) => {
|
|
|
88
93
|
}
|
|
89
94
|
}
|
|
90
95
|
};
|
|
91
|
-
const setFormattedValue = (
|
|
92
|
-
|
|
96
|
+
const setFormattedValue = () => {
|
|
97
|
+
if (!dom)
|
|
98
|
+
return;
|
|
99
|
+
const startCaretPosition = inputElement?.selectionStart || 0;
|
|
93
100
|
const previousFormattedValueLength = formattedValue.length;
|
|
94
|
-
formattedValue = isZero && !isZeroNullish ? "" : formatCurrency(
|
|
101
|
+
formattedValue = isZero && !isZeroNullish ? "" : formatCurrency(
|
|
102
|
+
value,
|
|
103
|
+
fractionDigits,
|
|
104
|
+
dom.activeElement === inputElement ? 0 : fractionDigits
|
|
105
|
+
);
|
|
95
106
|
setUnformattedValue();
|
|
96
107
|
let retries = 0;
|
|
97
108
|
while (previousFormattedValueLength === formattedValue.length && retries < 10)
|
|
98
109
|
retries++;
|
|
99
110
|
if (previousFormattedValueLength !== formattedValue.length) {
|
|
100
111
|
const endCaretPosition = startCaretPosition + formattedValue.length - previousFormattedValueLength;
|
|
101
|
-
|
|
112
|
+
inputElement?.setSelectionRange(endCaretPosition, endCaretPosition);
|
|
102
113
|
}
|
|
103
114
|
onValueChange(value);
|
|
104
115
|
};
|
|
@@ -140,12 +151,13 @@ $:
|
|
|
140
151
|
: ''}
|
|
141
152
|
"
|
|
142
153
|
type="text"
|
|
143
|
-
inputmode=
|
|
154
|
+
inputmode={fractionDigits > 0 ? 'decimal' : 'numeric'}
|
|
144
155
|
name={`formatted-${name}`}
|
|
145
156
|
required={required && !isZero}
|
|
146
157
|
placeholder={handlePlaceholder(placeholder)}
|
|
147
158
|
{autocomplete}
|
|
148
159
|
{disabled}
|
|
160
|
+
bind:this={inputElement}
|
|
149
161
|
bind:value={formattedValue}
|
|
150
162
|
on:keydown={handleKeyDown}
|
|
151
163
|
on:keyup={setUnformattedValue}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@canutin/svelte-currency-input",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.4",
|
|
4
4
|
"scripts": {
|
|
5
5
|
"dev": "vite dev",
|
|
6
6
|
"build": "vite build",
|
|
@@ -23,9 +23,6 @@
|
|
|
23
23
|
"!dist/**/*.test.*",
|
|
24
24
|
"!dist/**/*.spec.*"
|
|
25
25
|
],
|
|
26
|
-
"peerDependencies": {
|
|
27
|
-
"svelte": "^3.59.2"
|
|
28
|
-
},
|
|
29
26
|
"devDependencies": {
|
|
30
27
|
"@playwright/test": "^1.39.0",
|
|
31
28
|
"@sveltejs/adapter-auto": "^2.0.0",
|