svelte-tel-input 3.0.0 → 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,33 @@
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
+
23
+ ## 3.0.1
24
+
25
+ ### Patch Changes
26
+
27
+ - chore: update readme with advanced example REPL ([#162](https://github.com/gyurielf/svelte-tel-input/pull/162))
28
+
29
+ - fix: auto country update after manual country change ([#162](https://github.com/gyurielf/svelte-tel-input/pull/162))
30
+
3
31
  ## 3.0.0
4
32
 
5
33
  ### Major Changes
package/README.md CHANGED
@@ -28,6 +28,10 @@ npm install --save svelte-tel-input
28
28
 
29
29
  ## Usage
30
30
 
31
+ ### Advanced
32
+
33
+ _Snippet would be too long_ - [REPL](https://stackblitz.com/edit/svelte-tel-input-repl-1jfaar?file=README.md) (StackBlitz)
34
+
31
35
  ### Basic
32
36
 
33
37
  [REPL](https://stackblitz.com/edit/svelte-tel-input-repl?file=README.md) (StackBlitz)
@@ -115,7 +119,7 @@ The default export of the library is the main TelInput component. It has the fol
115
119
 
116
120
  Config options:
117
121
 
118
- ```
122
+ ```javascript
119
123
  {
120
124
  // Generates country specific placeholder for the selected country.
121
125
  autoPlaceholder: true,
@@ -159,7 +163,20 @@ The default export of the library is the main TelInput component. It has the fol
159
163
 
160
164
  ## Caveats
161
165
 
162
- - In order to reset the component from outside, you must pass (or set if you binded) `null` for both the `value` and `country` properties.
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
+
163
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`).
164
181
 
165
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
  }
@@ -79,11 +77,11 @@ const handleParsePhoneNumber = (input, currCountry = null) => {
79
77
  dispatch("updateDetailedValue", detailedValue);
80
78
  } else if (input === null && currCountry !== null) {
81
79
  if (currCountry !== prevCountry) {
80
+ prevCountry = currCountry;
82
81
  valid = !options.invalidateOnCountryChange;
83
82
  value = null;
84
83
  if (inputValue !== null || inputValue !== "") {
85
84
  inputValue = null;
86
- inputValue = "";
87
85
  }
88
86
  detailedValue = null;
89
87
  dispatch("updateValid", valid);
@@ -98,7 +96,6 @@ const handleParsePhoneNumber = (input, currCountry = null) => {
98
96
  dispatch("updateValid", valid);
99
97
  dispatch("updateDetailedValue", detailedValue);
100
98
  inputValue = null;
101
- inputValue = "";
102
99
  }
103
100
  };
104
101
  let countryWatchInitRun = true;
@@ -113,6 +110,12 @@ $:
113
110
  $countryChangeWatch = country;
114
111
  $:
115
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
+ }
116
119
  const initialize = () => {
117
120
  if (value && country) {
118
121
  handleParsePhoneNumber(value, country);
@@ -148,5 +151,9 @@ onMount(() => {
148
151
  on:keyup
149
152
  on:paste
150
153
  on:click
151
- use:telInputAction={{ handler: handleInputAction, spaces: combinedOptions.spaces }}
154
+ use:telInputAction={{
155
+ handler: handleInputAction,
156
+ spaces: combinedOptions.spaces,
157
+ value
158
+ }}
152
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.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"
@@ -22,7 +22,7 @@
22
22
  "pnpm": ">= 7"
23
23
  },
24
24
  "dependencies": {
25
- "libphonenumber-js": "^1.10.30",
25
+ "libphonenumber-js": "^1.10.36",
26
26
  "svelte": "^3.58.0"
27
27
  },
28
28
  "devDependencies": {
@@ -30,35 +30,35 @@
30
30
  "@changesets/get-github-info": "^0.5.2",
31
31
  "@changesets/types": "^5.2.1",
32
32
  "@macfja/svelte-persistent-store": "^2.3.0",
33
- "@playwright/test": "^1.33.0",
33
+ "@playwright/test": "^1.35.1",
34
34
  "@sveltejs/adapter-static": "^2.0.2",
35
- "@sveltejs/kit": "^1.16.3",
35
+ "@sveltejs/kit": "^1.20.4",
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.59.5",
40
- "@typescript-eslint/parser": "^5.59.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.0.3",
44
- "edit-package-json": "^0.8.13",
45
- "eslint": "^8.40.0",
43
+ "dotenv": "^16.3.1",
44
+ "edit-package-json": "^0.8.14",
45
+ "eslint": "^8.43.0",
46
46
  "eslint-config-prettier": "^8.8.0",
47
47
  "eslint-plugin-svelte3": "^4.0.0",
48
48
  "husky": "^8.0.3",
49
- "jsdom": "^22.0.0",
49
+ "jsdom": "^22.1.0",
50
50
  "micromatch": "^4.0.5",
51
- "postcss": "^8.4.23",
51
+ "postcss": "^8.4.24",
52
52
  "prettier": "^2.8.8",
53
- "prettier-plugin-svelte": "^2.10.0",
53
+ "prettier-plugin-svelte": "^2.10.1",
54
54
  "schema-dts": "^1.1.2",
55
- "svelte-check": "^3.3.2",
56
- "svelte2tsx": "^0.6.14",
55
+ "svelte-check": "^3.4.3",
56
+ "svelte2tsx": "^0.6.15",
57
57
  "tailwindcss": "^3.3.2",
58
- "tslib": "^2.5.0",
58
+ "tslib": "^2.5.3",
59
59
  "typescript": "^5.0.4",
60
- "vite": "^4.3.5",
61
- "vitest": "^0.31.0"
60
+ "vite": "^4.3.9",
61
+ "vitest": "^0.32.2"
62
62
  },
63
63
  "type": "module",
64
64
  "license": "MIT",
@@ -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 value = event.target.value;
6
- const formattedInput = inputParser(value, {
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
  }