@desource/phone-mask-vue 0.2.3 → 1.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.
- package/CHANGELOG.md +46 -0
- package/LICENSE +1 -1
- package/README.md +154 -11
- package/dist/index.cjs +858 -961
- package/dist/index.js +858 -961
- package/dist/index.mjs +859 -962
- package/dist/phone-mask-vue.css +64 -64
- package/dist/types/components/PhoneInput.vue.d.ts +7 -7
- package/dist/types/components/PhoneInput.vue.d.ts.map +1 -1
- package/dist/types/composables/internal/useCopyAction.d.ts +14 -0
- package/dist/types/composables/internal/useCopyAction.d.ts.map +1 -0
- package/dist/types/composables/internal/useCountry.d.ts +22 -0
- package/dist/types/composables/internal/useCountry.d.ts.map +1 -0
- package/dist/types/composables/internal/useCountrySelector.d.ts +30 -0
- package/dist/types/composables/internal/useCountrySelector.d.ts.map +1 -0
- package/dist/types/composables/internal/useFormatter.d.ts +46 -0
- package/dist/types/composables/internal/useFormatter.d.ts.map +1 -0
- package/dist/types/composables/internal/useInputHandlers.d.ts +20 -0
- package/dist/types/composables/internal/useInputHandlers.d.ts.map +1 -0
- package/dist/types/composables/internal/useTheme.d.ts +10 -0
- package/dist/types/composables/internal/useTheme.d.ts.map +1 -0
- package/dist/types/composables/internal/useValidationHint.d.ts +6 -0
- package/dist/types/composables/internal/useValidationHint.d.ts.map +1 -0
- package/dist/types/composables/usePhoneMask.d.ts +8 -0
- package/dist/types/composables/usePhoneMask.d.ts.map +1 -0
- package/dist/types/composables/{useClipboard.d.ts → utility/useClipboard.d.ts} +1 -2
- package/dist/types/composables/utility/useClipboard.d.ts.map +1 -0
- package/dist/types/composables/utility/useTimer.d.ts +9 -0
- package/dist/types/composables/utility/useTimer.d.ts.map +1 -0
- package/dist/types/directives/vPhoneMask.d.ts.map +1 -1
- package/dist/types/index.d.ts +4 -2
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/types.d.ts +31 -13
- package/dist/types/types.d.ts.map +1 -1
- package/package.json +18 -12
- package/dist/types/composables/useClipboard.d.ts.map +0 -1
- package/dist/types/composables/useCountrySelector.d.ts +0 -21
- package/dist/types/composables/useCountrySelector.d.ts.map +0 -1
- package/dist/types/composables/useMask.d.ts +0 -20
- package/dist/types/composables/useMask.d.ts.map +0 -1
- package/dist/types/composables/usePhoneFormatter.d.ts +0 -16
- package/dist/types/composables/usePhoneFormatter.d.ts.map +0 -1
- package/dist/types/consts.d.ts +0 -8
- package/dist/types/consts.d.ts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,51 @@
|
|
|
1
1
|
# @desource/phone-mask-vue
|
|
2
2
|
|
|
3
|
+
## 1.0.0
|
|
4
|
+
|
|
5
|
+
### Major Changes
|
|
6
|
+
|
|
7
|
+
- Core Upgrades:
|
|
8
|
+
- Refactored core architecture for better separation of concerns and reusability
|
|
9
|
+
- Added zero-config browser script support path
|
|
10
|
+
- Improved Intl.DisplayNames caching for performance
|
|
11
|
+
- Fixed various edge cases in formatting and event handling
|
|
12
|
+
- Added comprehensive unit tests for core utilities and handlers
|
|
13
|
+
|
|
14
|
+
- React Upgrades:
|
|
15
|
+
- Major internal refactor to a controlled pattern with consistent hooks
|
|
16
|
+
- Improved React 18/19 compatibility for ref behavior
|
|
17
|
+
- Added and expanded unit/e2e tests for React components and behavior
|
|
18
|
+
|
|
19
|
+
- Vue Upgrades:
|
|
20
|
+
- Refactored to align composable structure and reuse core utilities
|
|
21
|
+
- Fixed directive behavior for external value updates and dropdown close logic
|
|
22
|
+
- Added substantial unit/e2e test coverage for Vue composables and directive
|
|
23
|
+
|
|
24
|
+
- 🚀 Svelte Upgrades:
|
|
25
|
+
- Introduced Svelte version of phone-mask library
|
|
26
|
+
|
|
27
|
+
- Nuxt Upgrades:
|
|
28
|
+
- Added full test foundation with @nuxt/test-utils
|
|
29
|
+
- Added unit tests for module and runtime behavior
|
|
30
|
+
- Added e2e fixtures/tests and shared e2e utilities
|
|
31
|
+
|
|
32
|
+
### Patch Changes
|
|
33
|
+
|
|
34
|
+
- Updated dependencies []:
|
|
35
|
+
- @desource/phone-mask@1.0.0
|
|
36
|
+
|
|
37
|
+
## 0.3.0
|
|
38
|
+
|
|
39
|
+
### Minor Changes
|
|
40
|
+
|
|
41
|
+
- React: Design React version of phone-mask library
|
|
42
|
+
- Core: Add geoip reusable service for country detection based on IP address
|
|
43
|
+
|
|
44
|
+
### Patch Changes
|
|
45
|
+
|
|
46
|
+
- Updated dependencies []:
|
|
47
|
+
- @desource/phone-mask@0.3.0
|
|
48
|
+
|
|
3
49
|
## 0.2.3
|
|
4
50
|
|
|
5
51
|
### Patch Changes
|
package/LICENSE
CHANGED
package/README.md
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
[](https://bundlephobia.com/package/@desource/phone-mask-vue)
|
|
7
7
|
[](https://github.com/DeSource-Labs/phone-mask/blob/main/LICENSE)
|
|
8
8
|
|
|
9
|
-
Beautiful, accessible, extreme small & tree-
|
|
9
|
+
Beautiful, accessible, extreme small & tree-shakeable Vue 3 phone input with auto-formatting, country selector, and validation.
|
|
10
10
|
|
|
11
11
|
## ✨ Features
|
|
12
12
|
|
|
@@ -36,19 +36,36 @@ pnpm add @desource/phone-mask-vue
|
|
|
36
36
|
|
|
37
37
|
### Importing
|
|
38
38
|
|
|
39
|
+
Component mode:
|
|
40
|
+
|
|
39
41
|
```ts
|
|
40
42
|
import { createApp } from 'vue';
|
|
41
|
-
import { PhoneInput
|
|
42
|
-
import '@desource/phone-mask-vue/assets/lib.css'; // Import styles
|
|
43
|
+
import { PhoneInput } from '@desource/phone-mask-vue';
|
|
44
|
+
import '@desource/phone-mask-vue/assets/lib.css'; // Import styles
|
|
43
45
|
|
|
44
46
|
const app = createApp(App);
|
|
47
|
+
app.component('PhoneInput', PhoneInput);
|
|
48
|
+
app.mount('#app');
|
|
49
|
+
```
|
|
50
|
+
|
|
51
|
+
Directive mode (for custom input implementations):
|
|
45
52
|
|
|
46
|
-
|
|
47
|
-
|
|
53
|
+
```ts
|
|
54
|
+
import { createApp } from 'vue';
|
|
55
|
+
import { vPhoneMask } from '@desource/phone-mask-vue';
|
|
56
|
+
|
|
57
|
+
const app = createApp(App);
|
|
58
|
+
app.directive('phone-mask', vPhoneMask);
|
|
48
59
|
app.mount('#app');
|
|
49
60
|
```
|
|
50
61
|
|
|
51
|
-
|
|
62
|
+
Composable mode (for custom input implementations in case even directive doesn't fit your needs):
|
|
63
|
+
|
|
64
|
+
```ts
|
|
65
|
+
import { usePhoneMask } from '@desource/phone-mask-vue';
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Register all at once (component + directive):
|
|
52
69
|
|
|
53
70
|
```ts
|
|
54
71
|
import { createApp } from 'vue';
|
|
@@ -56,8 +73,7 @@ import phoneMask from '@desource/phone-mask-vue';
|
|
|
56
73
|
import '@desource/phone-mask-vue/assets/lib.css'; // Import styles for component mode
|
|
57
74
|
|
|
58
75
|
const app = createApp(App);
|
|
59
|
-
|
|
60
|
-
app.use(phoneMask); // Registers both component and directive
|
|
76
|
+
app.use(phoneMask); // Registers component and directive
|
|
61
77
|
app.mount('#app');
|
|
62
78
|
```
|
|
63
79
|
|
|
@@ -119,6 +135,35 @@ const handleChange = (phone: PMaskPhoneNumber) => {
|
|
|
119
135
|
</template>
|
|
120
136
|
```
|
|
121
137
|
|
|
138
|
+
### Composable Mode
|
|
139
|
+
|
|
140
|
+
For custom input implementations (in case even directive doesn't fit your needs):
|
|
141
|
+
|
|
142
|
+
```vue
|
|
143
|
+
<script setup lang="ts">
|
|
144
|
+
import { ref } from 'vue';
|
|
145
|
+
import { usePhoneMask } from '@desource/phone-mask-vue';
|
|
146
|
+
|
|
147
|
+
const value = ref('');
|
|
148
|
+
|
|
149
|
+
const { inputRef, digits, full, fullFormatted, isComplete, setCountry } = usePhoneMask({
|
|
150
|
+
value,
|
|
151
|
+
onChange: (newValue) => (value.value = newValue),
|
|
152
|
+
country: 'US',
|
|
153
|
+
detect: true
|
|
154
|
+
});
|
|
155
|
+
</script>
|
|
156
|
+
|
|
157
|
+
<template>
|
|
158
|
+
<div>
|
|
159
|
+
<input ref="inputRef" type="tel" placeholder="Phone number" />
|
|
160
|
+
<p>Formatted: {{ fullFormatted }}</p>
|
|
161
|
+
<p>Valid: {{ isComplete ? 'Yes' : 'No' }}</p>
|
|
162
|
+
<button @click="setCountry('GB')">Use UK</button>
|
|
163
|
+
</div>
|
|
164
|
+
</template>
|
|
165
|
+
```
|
|
166
|
+
|
|
122
167
|
## 📖 Component API
|
|
123
168
|
|
|
124
169
|
### Props
|
|
@@ -405,6 +450,103 @@ const handleChange = (phone: PMaskPhoneNumber) => {
|
|
|
405
450
|
</template>
|
|
406
451
|
```
|
|
407
452
|
|
|
453
|
+
## 🪝 Composable API
|
|
454
|
+
|
|
455
|
+
### `usePhoneMask`
|
|
456
|
+
|
|
457
|
+
For custom input implementations:
|
|
458
|
+
|
|
459
|
+
```vue
|
|
460
|
+
<script setup lang="ts">
|
|
461
|
+
import { ref } from 'vue';
|
|
462
|
+
import { usePhoneMask } from '@desource/phone-mask-vue';
|
|
463
|
+
|
|
464
|
+
const value = ref('');
|
|
465
|
+
|
|
466
|
+
const { inputRef, digits, full, fullFormatted, isComplete, setCountry, clear } = usePhoneMask({
|
|
467
|
+
value,
|
|
468
|
+
onChange: (newValue) => (value.value = newValue),
|
|
469
|
+
country: 'US',
|
|
470
|
+
detect: false
|
|
471
|
+
});
|
|
472
|
+
</script>
|
|
473
|
+
|
|
474
|
+
<template>
|
|
475
|
+
<div>
|
|
476
|
+
<input ref="inputRef" type="tel" />
|
|
477
|
+
<button @click="setCountry('GB')">Switch to UK</button>
|
|
478
|
+
<button @click="clear">Clear</button>
|
|
479
|
+
<p>Full: {{ fullFormatted || '—' }}</p>
|
|
480
|
+
<p>Valid: {{ isComplete ? 'Yes' : 'No' }}</p>
|
|
481
|
+
</div>
|
|
482
|
+
</template>
|
|
483
|
+
```
|
|
484
|
+
|
|
485
|
+
### Options
|
|
486
|
+
|
|
487
|
+
> **Note:** The composable requires controlled behavior. Both `value` and `onChange` options are required.
|
|
488
|
+
|
|
489
|
+
```ts
|
|
490
|
+
interface UsePhoneMaskOptions {
|
|
491
|
+
// Controlled value (digits only, without country code) - REQUIRED
|
|
492
|
+
value: MaybeRefOrGetter<string>;
|
|
493
|
+
|
|
494
|
+
// Callback when the digits value changes - REQUIRED
|
|
495
|
+
onChange: (digits: string) => void;
|
|
496
|
+
|
|
497
|
+
// Predefined country ISO code (e.g., 'US', 'DE', 'GB')
|
|
498
|
+
country?: MaybeRefOrGetter<string | undefined>;
|
|
499
|
+
|
|
500
|
+
// Locale for country names (default: navigator.language)
|
|
501
|
+
locale?: MaybeRefOrGetter<string | undefined>;
|
|
502
|
+
|
|
503
|
+
// Auto-detect country from IP/locale (default: false)
|
|
504
|
+
detect?: MaybeRefOrGetter<boolean | undefined>;
|
|
505
|
+
|
|
506
|
+
// Callback when the phone changes (full, fullFormatted, digits)
|
|
507
|
+
onPhoneChange?: (phone: PhoneNumber) => void;
|
|
508
|
+
|
|
509
|
+
// Country change callback
|
|
510
|
+
onCountryChange?: (country: MaskFull) => void;
|
|
511
|
+
}
|
|
512
|
+
```
|
|
513
|
+
|
|
514
|
+
### Return Value
|
|
515
|
+
|
|
516
|
+
```ts
|
|
517
|
+
interface UsePhoneMaskReturn {
|
|
518
|
+
// Ref to attach to your input element - REQUIRED
|
|
519
|
+
inputRef: ShallowRef<HTMLInputElement | null>;
|
|
520
|
+
|
|
521
|
+
// Raw digits without formatting (e.g., "1234567890")
|
|
522
|
+
digits: ComputedRef<string>;
|
|
523
|
+
|
|
524
|
+
// Full phone number with country code (e.g., "+11234567890")
|
|
525
|
+
full: ComputedRef<string>;
|
|
526
|
+
|
|
527
|
+
// Full phone number formatted (e.g., "+1 123-456-7890")
|
|
528
|
+
fullFormatted: ComputedRef<string>;
|
|
529
|
+
|
|
530
|
+
// Whether the phone number is complete
|
|
531
|
+
isComplete: ComputedRef<boolean>;
|
|
532
|
+
|
|
533
|
+
// Whether the input is empty
|
|
534
|
+
isEmpty: ComputedRef<boolean>;
|
|
535
|
+
|
|
536
|
+
// Whether to show validation warning
|
|
537
|
+
shouldShowWarn: ComputedRef<boolean>;
|
|
538
|
+
|
|
539
|
+
// Current country data
|
|
540
|
+
country: ComputedRef<MaskFull>;
|
|
541
|
+
|
|
542
|
+
// Change country programmatically
|
|
543
|
+
setCountry: (countryCode?: string | null) => boolean;
|
|
544
|
+
|
|
545
|
+
// Clear the input
|
|
546
|
+
clear: () => void;
|
|
547
|
+
}
|
|
548
|
+
```
|
|
549
|
+
|
|
408
550
|
## 📚 Examples
|
|
409
551
|
|
|
410
552
|
### With Validation
|
|
@@ -439,12 +581,12 @@ const errorMessage = computed(() => {
|
|
|
439
581
|
```vue
|
|
440
582
|
<script setup lang="ts">
|
|
441
583
|
import { ref } from 'vue';
|
|
442
|
-
import { PhoneInput, type
|
|
584
|
+
import { PhoneInput, type PMaskFull } from '@desource/phone-mask-vue';
|
|
443
585
|
|
|
444
586
|
const phone = ref('');
|
|
445
587
|
const detectedCountry = ref('');
|
|
446
588
|
|
|
447
|
-
const handleCountryChange = (country:
|
|
589
|
+
const handleCountryChange = (country: PMaskFull) => {
|
|
448
590
|
detectedCountry.value = country.name;
|
|
449
591
|
};
|
|
450
592
|
</script>
|
|
@@ -538,10 +680,11 @@ const form = reactive({
|
|
|
538
680
|
|
|
539
681
|
- [@desource/phone-mask](../phone-mask) — Core library
|
|
540
682
|
- [@desource/phone-mask-nuxt](../phone-mask-nuxt) — Nuxt module
|
|
683
|
+
- [@desource/phone-mask-react](../phone-mask-react) — React bindings
|
|
541
684
|
|
|
542
685
|
## 📄 License
|
|
543
686
|
|
|
544
|
-
[MIT](../../LICENSE) ©
|
|
687
|
+
[MIT](../../LICENSE) © 2026 DeSource Labs
|
|
545
688
|
|
|
546
689
|
## 🤝 Contributing
|
|
547
690
|
|