intl-tel-input 27.3.0 → 28.0.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.
Files changed (38) hide show
  1. package/dist/css/intlTelInput-no-assets.css +2 -2
  2. package/dist/css/intlTelInput.css +3 -3
  3. package/dist/js/data.d.ts +1 -4
  4. package/dist/js/data.js +3 -9
  5. package/dist/js/data.min.js +2 -2
  6. package/dist/js/data.mjs +2 -8
  7. package/dist/js/i18n.d.ts +1 -1592
  8. package/dist/js/intlTelInput.d.ts +62 -49
  9. package/dist/js/intlTelInput.js +221 -182
  10. package/dist/js/intlTelInput.min.js +6 -6
  11. package/dist/js/intlTelInput.mjs +219 -180
  12. package/dist/js/intlTelInputWithUtils.js +622 -568
  13. package/dist/js/intlTelInputWithUtils.min.js +6 -6
  14. package/dist/js/intlTelInputWithUtils.mjs +620 -566
  15. package/dist/js/utils.js +56 -55
  16. package/package.json +14 -181
  17. package/CHANGELOG.md +0 -33
  18. package/angular/README.md +0 -13
  19. package/angular/dist/IntlTelInput.d.ts +0 -110
  20. package/angular/dist/IntlTelInput.js +0 -5096
  21. package/angular/dist/IntlTelInputWithUtils.d.ts +0 -3
  22. package/angular/dist/IntlTelInputWithUtils.js +0 -11435
  23. package/react/README.md +0 -13
  24. package/react/dist/IntlTelInput.d.ts +0 -25
  25. package/react/dist/IntlTelInput.js +0 -4788
  26. package/react/dist/IntlTelInputWithUtils.d.ts +0 -4
  27. package/react/dist/IntlTelInputWithUtils.js +0 -11127
  28. package/svelte/README.md +0 -14
  29. package/svelte/src/IntlTelInput.svelte +0 -233
  30. package/svelte/src/IntlTelInput.svelte.d.ts +0 -36
  31. package/svelte/src/IntlTelInputWithUtils.svelte +0 -24
  32. package/vue/README.md +0 -14
  33. package/vue/dist/IntlTelInput-jw1tkqdD.js +0 -2657
  34. package/vue/dist/IntlTelInput.js +0 -5
  35. package/vue/dist/IntlTelInput.vue.d.ts +0 -43
  36. package/vue/dist/IntlTelInputWithUtils.js +0 -49403
  37. package/vue/dist/index.d.ts +0 -4
  38. package/vue/dist/indexWithUtils.d.ts +0 -3
package/svelte/README.md DELETED
@@ -1,14 +0,0 @@
1
- # IntlTelInput Svelte Component
2
-
3
- A Svelte 5 component for the [intl-tel-input](https://github.com/jackocnr/intl-tel-input) JavaScript plugin. View the [source code](https://github.com/jackocnr/intl-tel-input/blob/master/svelte/src/IntlTelInput.svelte).
4
-
5
- [Explore docs »](https://intl-tel-input.com/docs/svelte-component)
6
-
7
- ## Running the demos locally
8
-
9
- 1. Initialise the submodules: `git submodule update --init --recursive`
10
- 2. Install dependencies: `npm install`
11
- 3. Build: `npm run build`
12
- 4. Run a demo: `npm run svelte:demo` and copy the given URL into your browser.
13
-
14
- This defaults to the validation demo — to run a different one, set the `DEMO` env var, e.g. `DEMO=simple npm run svelte:demo`. View the full list of [available demos](https://github.com/jackocnr/intl-tel-input/tree/master/svelte/demo).
@@ -1,233 +0,0 @@
1
- <script module lang="ts">
2
- import intlTelInput, { type Iti } from "intl-tel-input";
3
- export { intlTelInput };
4
- </script>
5
-
6
- <script lang="ts">
7
- // Resolves to IntlTelInput.svelte.d.ts (the type declaration file for this component).
8
- import type { Props } from "./IntlTelInput.svelte";
9
- import type { SomeOptions } from "intl-tel-input";
10
- import { onMount, onDestroy } from "svelte";
11
-
12
- // Props
13
- let {
14
- disabled = false,
15
- readonly = false,
16
- inputProps = {},
17
- usePreciseValidation = false,
18
- initialValue = "",
19
- value = undefined,
20
- onChangeNumber,
21
- onChangeCountry,
22
- onChangeValidity,
23
- onChangeErrorCode,
24
- onOpenCountryDropdown,
25
- onCloseCountryDropdown,
26
- onStrictReject,
27
- ...initOptions
28
- } = $props() as Props;
29
-
30
- type StrictRejectDetail = {
31
- source: "key" | "paste";
32
- rejectedInput: string;
33
- reason: "invalid" | "max-length";
34
- };
35
-
36
- // State
37
- let inputElement: HTMLInputElement | undefined = $state();
38
- let instance: Iti | undefined = $state();
39
- // Classes the plugin adds directly to the input (e.g. iti__tel-input)
40
- let pluginInputClasses = $state("");
41
- let lastEmittedNumber: string | undefined = $state();
42
- let lastEmittedCountry: string | undefined = $state();
43
- let lastEmittedValidity: boolean | undefined = $state();
44
- let lastEmittedErrorCode: number | null | undefined = $state();
45
- let hasInitialized = $state(false);
46
- // if an input event fires before utils has loaded, we defer the update until the promise resolves
47
- let pendingUpdate = false;
48
-
49
- // Validation helper
50
- const isValid = (): boolean | null => {
51
- if (!instance) return null;
52
- return usePreciseValidation
53
- ? instance.isValidNumberPrecise()
54
- : instance.isValidNumber();
55
- };
56
-
57
- // Update handlers
58
- const updateValidity = () => {
59
- if (!instance) return;
60
- // if utils has not loaded yet, isValidNumber/getValidationError will throw. defer until the promise resolves.
61
- if (!intlTelInput.utils) {
62
- pendingUpdate = true;
63
- return;
64
- }
65
- const isCurrentlyValid = isValid();
66
- if (isCurrentlyValid === null) return;
67
-
68
- const valid = !!isCurrentlyValid;
69
- const errorCode = valid ? null : instance.getValidationError();
70
-
71
- if (valid !== lastEmittedValidity) {
72
- lastEmittedValidity = valid;
73
- onChangeValidity?.(valid);
74
- }
75
-
76
- if (errorCode !== lastEmittedErrorCode) {
77
- lastEmittedErrorCode = errorCode;
78
- onChangeErrorCode?.(errorCode);
79
- }
80
- };
81
-
82
- const updateValue = () => {
83
- if (!instance?.isActive()) {
84
- return;
85
- }
86
- // if utils has not loaded yet, getNumber will throw. defer until the promise resolves.
87
- if (!intlTelInput.utils) {
88
- pendingUpdate = true;
89
- return;
90
- }
91
- const number = instance.getNumber() ?? "";
92
- if (number !== lastEmittedNumber) {
93
- lastEmittedNumber = number;
94
- onChangeNumber?.(number);
95
- }
96
- updateValidity();
97
- };
98
-
99
- const updateCountry = () => {
100
- if (!instance?.isActive()) {
101
- return;
102
- }
103
- const country = instance.getSelectedCountryData()?.iso2 ?? "";
104
- if (country !== lastEmittedCountry) {
105
- lastEmittedCountry = country;
106
- onChangeCountry?.(country);
107
- }
108
- updateValue();
109
- };
110
-
111
- const handleOpenDropdown = (): void => onOpenCountryDropdown?.();
112
- const handleCloseDropdown = (): void => onCloseCountryDropdown?.();
113
- const handleStrictReject = (e: Event): void => {
114
- const { source, rejectedInput, reason } = (e as CustomEvent<StrictRejectDetail>).detail;
115
- onStrictReject?.(source, rejectedInput, reason);
116
- };
117
-
118
- // Lifecycle
119
- onMount(() => {
120
- if (inputElement) {
121
- instance = intlTelInput(inputElement, initOptions as SomeOptions);
122
- pluginInputClasses = inputElement.className;
123
- if (disabled) instance.setDisabled(disabled);
124
- if (readonly) instance.setReadonly(readonly);
125
-
126
- inputElement.addEventListener("open:countrydropdown", handleOpenDropdown);
127
- inputElement.addEventListener("close:countrydropdown", handleCloseDropdown);
128
- inputElement.addEventListener("strict:reject", handleStrictReject);
129
-
130
- lastEmittedCountry = instance.getSelectedCountryData()?.iso2 ?? "";
131
- hasInitialized = true;
132
-
133
- // wait for utils to load before calling methods that require it (getNumber, setNumber, isValidNumber, etc.)
134
- instance.promise.then(() => {
135
- if (!instance?.isActive()) return;
136
- if (initialValue) instance.setNumber(initialValue);
137
- // if an input event fired during the utils-loading gap, replay it now so the skipped emissions fire.
138
- // otherwise seed silently so we don't fire change callbacks on initial mount.
139
- if (pendingUpdate) {
140
- pendingUpdate = false;
141
- updateCountry();
142
- } else {
143
- lastEmittedNumber = instance.getNumber() ?? "";
144
- const initialValid = isValid();
145
- if (initialValid !== null) {
146
- lastEmittedValidity = !!initialValid;
147
- lastEmittedErrorCode = initialValid ? null : instance.getValidationError();
148
- }
149
- }
150
- });
151
- }
152
- });
153
-
154
- onDestroy(() => {
155
- if (inputElement) {
156
- inputElement.removeEventListener("open:countrydropdown", handleOpenDropdown);
157
- inputElement.removeEventListener("close:countrydropdown", handleCloseDropdown);
158
- inputElement.removeEventListener("strict:reject", handleStrictReject);
159
- }
160
- instance?.destroy();
161
- });
162
-
163
- // Watch disabled prop changes (only after initialization)
164
- $effect(() => {
165
- if (hasInitialized && instance) {
166
- instance.setDisabled(disabled);
167
- }
168
- });
169
-
170
- // Watch readonly prop changes (only after initialization)
171
- $effect(() => {
172
- if (hasInitialized && instance) {
173
- instance.setReadonly(readonly);
174
- }
175
- });
176
-
177
- // Watch value prop changes (only after initialization).
178
- // If value is undefined, the component is uncontrolled — do not touch the input
179
- // (otherwise we would clobber any initialValue with an empty string on mount).
180
- $effect(() => {
181
- if (!hasInitialized || !instance || value === undefined) {
182
- return;
183
- }
184
- const next = value ?? "";
185
- // wait for utils to load before calling methods that require it
186
- instance.promise.then(() => {
187
- if (!instance?.isActive()) return;
188
- const currentCanonical = instance.getNumber() ?? "";
189
- const isFocused = document.activeElement === inputElement;
190
- if (isFocused || currentCanonical === next) {
191
- return;
192
- }
193
- instance.setNumber(next);
194
- updateValidity();
195
- });
196
- });
197
-
198
- // Expose instance and input for parent access
199
- export function getInstance(): Iti | undefined {
200
- return instance;
201
- }
202
- export function getInput(): HTMLInputElement | undefined {
203
- return inputElement;
204
- }
205
-
206
- const warnInputProp = (prop: string): void => {
207
- console.warn(`intl-tel-input: ignoring inputProps.${prop} - see docs for more info.`);
208
- };
209
-
210
- const ignoredInputProps = new Set(["type", "value", "disabled", "readonly", "oninput"]);
211
-
212
- const sanitizeInputProps = (props: Record<string, unknown>) => {
213
- const rest: Record<string, unknown> = {};
214
- for (const [key, val] of Object.entries(props)) {
215
- if (ignoredInputProps.has(key)) {
216
- warnInputProp(key);
217
- } else if (key === "class") {
218
- rest[key] = `${pluginInputClasses} ${val}`;
219
- } else {
220
- rest[key] = val;
221
- }
222
- }
223
- return rest;
224
- };
225
- </script>
226
-
227
- <!-- inputProps must come first, so cannot override the other required props -->
228
- <input
229
- {...sanitizeInputProps(inputProps)}
230
- bind:this={inputElement}
231
- type="tel"
232
- oninput={updateCountry}
233
- />
@@ -1,36 +0,0 @@
1
- // Hand-written because svelte2tsx can't generate correct prop types for Svelte 5's $props() rune.
2
- // See: https://github.com/sveltejs/svelte/discussions/13164
3
- import type { Component } from "svelte";
4
- import type { Iti, SomeOptions } from "intl-tel-input";
5
- import intlTelInput from "intl-tel-input";
6
-
7
- export type StrictRejectSource = "key" | "paste";
8
- export type StrictRejectReason = "invalid" | "max-length";
9
-
10
- export type Props = SomeOptions & {
11
- disabled?: boolean;
12
- readonly?: boolean;
13
- inputProps?: Record<string, unknown>;
14
- initialValue?: string;
15
- value?: string | null;
16
- usePreciseValidation?: boolean;
17
- onChangeNumber?: (number: string) => void;
18
- onChangeCountry?: (iso2: string) => void;
19
- onChangeValidity?: (isValid: boolean) => void;
20
- onChangeErrorCode?: (errorCode: number | null) => void;
21
- onOpenCountryDropdown?: () => void;
22
- onCloseCountryDropdown?: () => void;
23
- onStrictReject?: (source: StrictRejectSource, rejectedInput: string, reason: StrictRejectReason) => void;
24
- };
25
-
26
- export { intlTelInput };
27
-
28
- declare const IntlTelInput: Component<
29
- Props,
30
- {
31
- getInstance: () => Iti | undefined;
32
- getInput: () => HTMLInputElement | undefined;
33
- }
34
- >;
35
-
36
- export default IntlTelInput;
@@ -1,24 +0,0 @@
1
- <script module lang="ts">
2
- import intlTelInput from "intl-tel-input";
3
- import utils from "intl-tel-input/utils";
4
- intlTelInput.utils = utils as typeof intlTelInput.utils;
5
- export { intlTelInput };
6
- </script>
7
-
8
- <script lang="ts">
9
- import IntlTelInput from "./IntlTelInput.svelte";
10
- import type { ComponentProps } from "svelte";
11
- import type { Iti } from "intl-tel-input";
12
-
13
- let { ...props }: ComponentProps<typeof IntlTelInput> = $props();
14
- let inner: ReturnType<typeof IntlTelInput> | undefined = $state();
15
-
16
- export function getInstance(): Iti | undefined {
17
- return inner?.getInstance();
18
- }
19
- export function getInput(): HTMLInputElement | undefined {
20
- return inner?.getInput();
21
- }
22
- </script>
23
-
24
- <IntlTelInput bind:this={inner} {...props} />
package/vue/README.md DELETED
@@ -1,14 +0,0 @@
1
- # IntlTelInput Vue Component
2
-
3
- A Vue component for the [intl-tel-input](https://github.com/jackocnr/intl-tel-input) JavaScript plugin. View the [source code](https://github.com/jackocnr/intl-tel-input/blob/master/vue/src/IntlTelInput.vue).
4
-
5
- [Explore docs »](https://intl-tel-input.com/docs/vue-component)
6
-
7
- ## Running the demos locally
8
-
9
- 1. Initialise the submodules: `git submodule update --init --recursive`
10
- 2. Install dependencies: `npm install`
11
- 3. Build: `npm run build`
12
- 4. Run a demo: `npm run vue:demo` and copy the given URL into your browser.
13
-
14
- This defaults to the validation demo — to run a different one, set the `DEMO` env var, e.g. `DEMO=simple npm run vue:demo`. View the full list of [available demos](https://github.com/jackocnr/intl-tel-input/tree/master/vue/demo).