svelte-tel-input 3.0.1 → 3.1.0
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/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# svelte-tel-input
|
|
2
2
|
|
|
3
|
+
## 3.1.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- feat: value can be reseted without country reset ([#165](https://github.com/gyurielf/svelte-tel-input/pull/165))
|
|
8
|
+
|
|
9
|
+
- In order to reset `value` and/or `country` from outside (you must pass (or set if you binded) `null` for the property) have some side-effects:
|
|
10
|
+
|
|
11
|
+
- Reseting the `value` will set (keep the `country` as is):
|
|
12
|
+
- `detailedValue` to `null`
|
|
13
|
+
- dispatch `updateDetailedValue` event
|
|
14
|
+
- Reseting the `country` will set:
|
|
15
|
+
- `value` to `null`
|
|
16
|
+
- `detailedValue` to `null`
|
|
17
|
+
- `valid` to `true` if `invalidateOnCountryChange` config option is false (_@default false_). Otherwise it will be `false`.
|
|
18
|
+
- and dispatch `updateValid`, `updateValue` `updateDetailedValue` events
|
|
19
|
+
- Reseting both `value` and `country` will set:
|
|
20
|
+
- `valid` to `true`
|
|
21
|
+
- `detailedValue` to `null`;
|
|
22
|
+
|
|
3
23
|
## 3.0.1
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -163,7 +163,20 @@ The default export of the library is the main TelInput component. It has the fol
|
|
|
163
163
|
|
|
164
164
|
## Caveats
|
|
165
165
|
|
|
166
|
-
- In order to reset
|
|
166
|
+
- In order to reset `value` and/or `country` from outside (you must pass (or set if you binded) `null` for the property) have some side-effects:
|
|
167
|
+
|
|
168
|
+
- Reseting the `value` will set (keep the `country` as is):
|
|
169
|
+
- `detailedValue` to `null`
|
|
170
|
+
- dispatch `updateDetailedValue` event
|
|
171
|
+
- Reseting the `country` will set:
|
|
172
|
+
- `value` to `null`
|
|
173
|
+
- `detailedValue` to `null`
|
|
174
|
+
- `valid` to `true` if `invalidateOnCountryChange` config option is false (_@default false_). Otherwise it will be `false`.
|
|
175
|
+
- and dispatch `updateValid`, `updateValue` `updateDetailedValue` events
|
|
176
|
+
- Reseting both `value` and `country` will set:
|
|
177
|
+
- `valid` to `true`
|
|
178
|
+
- `detailedValue` to `null`;
|
|
179
|
+
|
|
167
180
|
- Let's assume you pass a `US` `E164` number, which can be a partial `E164`, but long enough to determine the country and you pass `DE` country directly. The country will be updated to `US`, which is determined from the `E164` in this example. If the `E164` is not long enough to determine its country, then the country will stay what you passed to the component (`DE`).
|
|
168
181
|
|
|
169
182
|
<p align="right">(<a href="#readme-top">back to top</a>)</p>
|
|
@@ -62,13 +62,11 @@ const handleParsePhoneNumber = (input, currCountry = null) => {
|
|
|
62
62
|
if (detailedValue?.isValid && combinedOptions.spaces && detailedValue?.formatOriginal) {
|
|
63
63
|
if (inputValue === detailedValue?.formatOriginal) {
|
|
64
64
|
inputValue = null;
|
|
65
|
-
inputValue = "";
|
|
66
65
|
}
|
|
67
66
|
inputValue = detailedValue?.formatOriginal;
|
|
68
67
|
} else if (detailedValue?.isValid && detailedValue?.nationalNumber) {
|
|
69
68
|
if (inputValue === detailedValue?.nationalNumber) {
|
|
70
69
|
inputValue = null;
|
|
71
|
-
inputValue = "";
|
|
72
70
|
}
|
|
73
71
|
inputValue = detailedValue?.nationalNumber;
|
|
74
72
|
}
|
|
@@ -84,7 +82,6 @@ const handleParsePhoneNumber = (input, currCountry = null) => {
|
|
|
84
82
|
value = null;
|
|
85
83
|
if (inputValue !== null || inputValue !== "") {
|
|
86
84
|
inputValue = null;
|
|
87
|
-
inputValue = "";
|
|
88
85
|
}
|
|
89
86
|
detailedValue = null;
|
|
90
87
|
dispatch("updateValid", valid);
|
|
@@ -99,7 +96,6 @@ const handleParsePhoneNumber = (input, currCountry = null) => {
|
|
|
99
96
|
dispatch("updateValid", valid);
|
|
100
97
|
dispatch("updateDetailedValue", detailedValue);
|
|
101
98
|
inputValue = null;
|
|
102
|
-
inputValue = "";
|
|
103
99
|
}
|
|
104
100
|
};
|
|
105
101
|
let countryWatchInitRun = true;
|
|
@@ -114,6 +110,12 @@ $:
|
|
|
114
110
|
$countryChangeWatch = country;
|
|
115
111
|
$:
|
|
116
112
|
getPlaceholder = combinedOptions.autoPlaceholder ? country ? generatePlaceholder(country) : null : placeholder;
|
|
113
|
+
$:
|
|
114
|
+
if (value === null && inputValue !== null && detailedValue !== null) {
|
|
115
|
+
inputValue = null;
|
|
116
|
+
detailedValue = null;
|
|
117
|
+
dispatch("updateDetailedValue", detailedValue);
|
|
118
|
+
}
|
|
117
119
|
const initialize = () => {
|
|
118
120
|
if (value && country) {
|
|
119
121
|
handleParsePhoneNumber(value, country);
|
|
@@ -149,5 +151,9 @@ onMount(() => {
|
|
|
149
151
|
on:keyup
|
|
150
152
|
on:paste
|
|
151
153
|
on:click
|
|
152
|
-
use:telInputAction={{
|
|
154
|
+
use:telInputAction={{
|
|
155
|
+
handler: handleInputAction,
|
|
156
|
+
spaces: combinedOptions.spaces,
|
|
157
|
+
value
|
|
158
|
+
}}
|
|
153
159
|
/>
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { SvelteComponentTyped } from "svelte";
|
|
2
2
|
import type { DetailedValue, CountryCode, E164Number, TelInputOptions } from '../../types';
|
|
3
3
|
declare const __propDef: {
|
|
4
|
-
props: {
|
|
4
|
+
/** Set the required attribute on the input element */ props: {
|
|
5
5
|
[x: string]: any;
|
|
6
6
|
country: CountryCode | null;
|
|
7
7
|
value: E164Number | null;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-tel-input",
|
|
3
3
|
"description": "svelte-tel-input",
|
|
4
|
-
"version": "3.0
|
|
4
|
+
"version": "3.1.0",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/gyurielf/svelte-tel-input.git"
|
|
@@ -36,11 +36,11 @@
|
|
|
36
36
|
"@sveltejs/package": "^1.0.2",
|
|
37
37
|
"@testing-library/svelte": "^3.2.2",
|
|
38
38
|
"@testing-library/user-event": "^14.4.3",
|
|
39
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
40
|
-
"@typescript-eslint/parser": "^5.
|
|
39
|
+
"@typescript-eslint/eslint-plugin": "^5.60.0",
|
|
40
|
+
"@typescript-eslint/parser": "^5.60.0",
|
|
41
41
|
"autoprefixer": "^10.4.14",
|
|
42
42
|
"cssnano": "^6.0.1",
|
|
43
|
-
"dotenv": "^16.3.
|
|
43
|
+
"dotenv": "^16.3.1",
|
|
44
44
|
"edit-package-json": "^0.8.14",
|
|
45
45
|
"eslint": "^8.43.0",
|
|
46
46
|
"eslint-config-prettier": "^8.8.0",
|
|
@@ -1,6 +1,13 @@
|
|
|
1
|
+
import type { E164Number } from 'libphonenumber-js';
|
|
1
2
|
export declare const telInputAction: (node: HTMLInputElement, { handler, spaces }: {
|
|
2
3
|
handler: (val: string) => void;
|
|
3
4
|
spaces: boolean;
|
|
5
|
+
value: E164Number | null;
|
|
4
6
|
}) => {
|
|
7
|
+
update(params: {
|
|
8
|
+
handler: (val: string) => void;
|
|
9
|
+
spaces: boolean;
|
|
10
|
+
value: E164Number | null;
|
|
11
|
+
}): void;
|
|
5
12
|
destroy(): void;
|
|
6
13
|
};
|
|
@@ -2,8 +2,8 @@ import { inspectAllowedChars, inputParser } from '../..';
|
|
|
2
2
|
export const telInputAction = (node, { handler, spaces }) => {
|
|
3
3
|
const onInput = (event) => {
|
|
4
4
|
if (node && node.contains(event.target)) {
|
|
5
|
-
const
|
|
6
|
-
const formattedInput = inputParser(
|
|
5
|
+
const currentValue = event.target.value;
|
|
6
|
+
const formattedInput = inputParser(currentValue, {
|
|
7
7
|
parseCharacter: inspectAllowedChars,
|
|
8
8
|
allowSpaces: spaces
|
|
9
9
|
});
|
|
@@ -13,6 +13,11 @@ export const telInputAction = (node, { handler, spaces }) => {
|
|
|
13
13
|
};
|
|
14
14
|
node.addEventListener('input', onInput, true);
|
|
15
15
|
return {
|
|
16
|
+
update(params) {
|
|
17
|
+
if (params.value === null || params.value === '') {
|
|
18
|
+
node.value = '';
|
|
19
|
+
}
|
|
20
|
+
},
|
|
16
21
|
destroy() {
|
|
17
22
|
node.removeEventListener('input', onInput, true);
|
|
18
23
|
}
|