svelte-tel-input 4.0.0-next.1 → 4.0.0-next.2
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.
|
@@ -103,11 +103,10 @@
|
|
|
103
103
|
}
|
|
104
104
|
});
|
|
105
105
|
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
*/
|
|
106
|
+
// Compute the initial formatted display value synchronously.
|
|
107
|
+
// Runs on both server and client at initialization time, so SSR renders the
|
|
108
|
+
// formatted number and the client's first render matches — no hydration mismatch.
|
|
109
|
+
|
|
111
110
|
const computeInitialDisplayValue = (): string => {
|
|
112
111
|
if (!value) return '';
|
|
113
112
|
let effectiveCountryIso2: CountryCode | null = null;
|
|
@@ -139,18 +138,16 @@
|
|
|
139
138
|
if (prevCountry === undefined) prevCountry = country;
|
|
140
139
|
});
|
|
141
140
|
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
* Initialized to the incoming prop values so the first render never false-fires.
|
|
148
|
-
*/
|
|
141
|
+
//Shadow trackers — record every value this component writes internally so the
|
|
142
|
+
//external-change watchers below can distinguish "we set it" vs "parent set it".
|
|
143
|
+
//Plain let (not $state) because they are only ever read inside untrack(), never
|
|
144
|
+
//as reactive dependencies.
|
|
145
|
+
//Initialized to the incoming prop values so the first render never false-fires.
|
|
149
146
|
let _lastWrittenValue: string = value;
|
|
150
147
|
let _lastWrittenCountry: CountryCode | null | undefined = untrack(() => country);
|
|
151
148
|
// let isInitialized = $state(false);
|
|
152
149
|
|
|
153
|
-
|
|
150
|
+
// Merge options into default opts, to be able to set just one config option.
|
|
154
151
|
const combinedOptions = $derived({
|
|
155
152
|
...defaultOptions,
|
|
156
153
|
...options
|
|
@@ -378,11 +375,9 @@
|
|
|
378
375
|
});
|
|
379
376
|
});
|
|
380
377
|
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
* handleParsePhoneNumber, so any difference here means the parent changed it.
|
|
385
|
-
*/
|
|
378
|
+
//Detect externally driven value changes (e.g. parent sets bind:value, or resets to null).
|
|
379
|
+
//The shadow `_lastWrittenValue` is stamped on every internal write inside
|
|
380
|
+
//handleParsePhoneNumber, so any difference here means the parent changed it.
|
|
386
381
|
$effect(() => {
|
|
387
382
|
const currentValue = value;
|
|
388
383
|
untrack(() => {
|
|
@@ -392,11 +387,9 @@
|
|
|
392
387
|
});
|
|
393
388
|
});
|
|
394
389
|
|
|
395
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
* handleParsePhoneNumber later writes country through countryUpdater.
|
|
399
|
-
*/
|
|
390
|
+
// Detect externally driven country changes (e.g. parent's <select bind:value={country}>).
|
|
391
|
+
// Stamps `_lastWrittenCountry` eagerly so the watcher doesn't re-fire when
|
|
392
|
+
// handleParsePhoneNumber later writes country through countryUpdater.
|
|
400
393
|
$effect(() => {
|
|
401
394
|
const currentCountry = country;
|
|
402
395
|
untrack(() => {
|
|
@@ -425,6 +418,13 @@
|
|
|
425
418
|
onLoad?.();
|
|
426
419
|
});
|
|
427
420
|
|
|
421
|
+
/**
|
|
422
|
+
* Resets the input value and validation state.
|
|
423
|
+
*
|
|
424
|
+
* @param {Object} [options] - Optional settings.
|
|
425
|
+
* @param {boolean} [options.country=false] - If true, resets the country to null; otherwise, resets to defaultCountry.
|
|
426
|
+
* @returns {void}
|
|
427
|
+
*/
|
|
428
428
|
const reset = ({ country: resetCountry = false }: { country?: boolean } = {}) => {
|
|
429
429
|
const targetCountry = resetCountry ? null : (defaultCountry ?? null);
|
|
430
430
|
applyValidity(true, false, targetCountry);
|
|
@@ -438,6 +438,11 @@
|
|
|
438
438
|
onValueChange?.('', null);
|
|
439
439
|
};
|
|
440
440
|
|
|
441
|
+
/**
|
|
442
|
+
* Checks the validity of the current input value and updates validation state.
|
|
443
|
+
*
|
|
444
|
+
* @returns {{ valid: boolean; error: ValidationError }} - The validity status and error type.
|
|
445
|
+
*/
|
|
441
446
|
const checkValidity = (): { valid: boolean; error: ValidationError } => {
|
|
442
447
|
if (inputValue === '') {
|
|
443
448
|
applyValidity(true, false, country);
|
package/dist/types/index.d.ts
CHANGED
|
@@ -99,6 +99,9 @@ export interface TelInputOptions {
|
|
|
99
99
|
}
|
|
100
100
|
|
|
101
101
|
export interface Props extends HTMLInputAttributes {
|
|
102
|
+
/**
|
|
103
|
+
* Autocomplete attribute for autofill hints (e.g. 'tel', 'tel-national').
|
|
104
|
+
*/
|
|
102
105
|
autocomplete?: AutoFill | null;
|
|
103
106
|
/** You can set the classes of the input field*/
|
|
104
107
|
class?: string;
|
|
@@ -135,10 +138,31 @@ export interface Props extends HTMLInputAttributes {
|
|
|
135
138
|
options?: TelInputOptions;
|
|
136
139
|
/** Binding to the underlying `<input>` element */
|
|
137
140
|
el?: HTMLInputElement | undefined;
|
|
141
|
+
/**
|
|
142
|
+
* Callback fired when the country changes (auto-detected or user-selected).
|
|
143
|
+
* @param newCountry The new country code or null.
|
|
144
|
+
*/
|
|
138
145
|
onCountryChange?: (newCountry: CountryCode | null) => void;
|
|
146
|
+
/**
|
|
147
|
+
* Callback fired when validity changes.
|
|
148
|
+
* @param newValidity The new validity state.
|
|
149
|
+
* @param error The validation error type.
|
|
150
|
+
*/
|
|
139
151
|
onValidityChange?: (newValidity: boolean, error: ValidationError) => void;
|
|
152
|
+
/**
|
|
153
|
+
* Callback fired when the value or details change.
|
|
154
|
+
* @param newValue The new E164 value.
|
|
155
|
+
* @param newDetails The new detailed value object.
|
|
156
|
+
*/
|
|
140
157
|
onValueChange?: (newValue: string, newDetails: Readonly<Partial<DetailedValue> | null>) => void;
|
|
158
|
+
/**
|
|
159
|
+
* Callback fired on parse or validation errors.
|
|
160
|
+
* @param error The error message.
|
|
161
|
+
*/
|
|
141
162
|
onError?: (error: string) => void;
|
|
163
|
+
/**
|
|
164
|
+
* Callback fired after component initialization.
|
|
165
|
+
*/
|
|
142
166
|
onLoad?: () => void;
|
|
143
167
|
}
|
|
144
168
|
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "svelte-tel-input",
|
|
3
3
|
"description": "svelte-tel-input",
|
|
4
|
-
"version": "4.0.0-next.
|
|
4
|
+
"version": "4.0.0-next.2",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
7
7
|
"url": "git+https://github.com/gyurielf/svelte-tel-input.git"
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"micromatch": "^4.0.8",
|
|
48
48
|
"postcss": "^8.5.8",
|
|
49
49
|
"publint": "^0.3.18",
|
|
50
|
-
"svelte": "^5.
|
|
50
|
+
"svelte": "^5.54.0",
|
|
51
51
|
"svelte-check": "^4.4.5",
|
|
52
52
|
"svelte2tsx": "^0.7.52",
|
|
53
53
|
"tailwindcss": "^4.2.1",
|