@desource/phone-mask-vue 0.2.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.
@@ -0,0 +1,184 @@
1
+ import type { MaskFull, CountryKey } from '@desource/phone-mask';
2
+ export type Size = 'compact' | 'normal' | 'large';
3
+ export type Theme = 'auto' | 'light' | 'dark';
4
+ export type PhoneNumber = {
5
+ full: string;
6
+ fullFormatted: string;
7
+ digits: string;
8
+ };
9
+ export interface PhoneInputProps {
10
+ /** Whether to preselect a country by its ISO 3166-1 alpha-2 code */
11
+ country?: CountryKey;
12
+ /**
13
+ * Whether to auto-detect country via geo IP lookup.
14
+ * Note: This requires an external geo IP service and may not work in all environments.
15
+ * @default true
16
+ */
17
+ detect?: boolean;
18
+ /** Locale for country names (defaults to browser language) */
19
+ locale?: string;
20
+ /**
21
+ * Size preset for the component ("compact" | "normal" | "large").
22
+ * @default 'normal'
23
+ */
24
+ size?: Size;
25
+ /**
26
+ * Theme preset for the component ("auto" | "light" | "dark").
27
+ * @default 'auto'
28
+ */
29
+ theme?: Theme;
30
+ /**
31
+ * Whether the input is disabled.
32
+ * @default false
33
+ */
34
+ disabled?: boolean;
35
+ /**
36
+ * Whether the input is readonly.
37
+ * @default false
38
+ */
39
+ readonly?: boolean;
40
+ /**
41
+ * Whether to show the copy button.
42
+ * @default true
43
+ */
44
+ showCopy?: boolean;
45
+ /**
46
+ * Whether to show the clear button.
47
+ * @default false
48
+ */
49
+ showClear?: boolean;
50
+ /**
51
+ * Whether to show validation related styles (border & outline).
52
+ * @default true
53
+ */
54
+ withValidity?: boolean;
55
+ /**
56
+ * Custom search placeholder.
57
+ * @default 'Search country or code...'
58
+ */
59
+ searchPlaceholder?: string;
60
+ /**
61
+ * Custom no results text.
62
+ * @default 'No countries found'
63
+ */
64
+ noResultsText?: string;
65
+ /**
66
+ * Custom clear button label.
67
+ * @default 'Clear phone number'
68
+ */
69
+ clearButtonLabel?: string;
70
+ /** Dropdown menu custom class */
71
+ dropdownClass?: string;
72
+ /**
73
+ * Whether to disable default internal styles.
74
+ * @default false
75
+ */
76
+ disableDefaultStyles?: boolean;
77
+ }
78
+ export interface PhoneInputEmits {
79
+ /**
80
+ * Emitted when the value changes.
81
+ * Provides an object with:
82
+ * - full: Full phone number with country code (e.g. +1234567890)
83
+ * - fullFormatted: Full phone number formatted according to country rules (e.g. +1 234-567-890)
84
+ * - digits: Only the digits of the phone number without country code (e.g. 234567890)
85
+ */
86
+ (e: 'change', value: PhoneNumber): void;
87
+ /** Emitted when the country changes */
88
+ (e: 'country-change', country: MaskFull): void;
89
+ /** Emitted when validation state changes */
90
+ (e: 'validation-change', isValid: boolean): void;
91
+ /** Emitted on focus */
92
+ (e: 'focus', event: FocusEvent): void;
93
+ /** Emitted on blur */
94
+ (e: 'blur', event: FocusEvent): void;
95
+ /** Emitted when phone number is copied */
96
+ (e: 'copy', value: string): void;
97
+ /** Emitted when input is cleared */
98
+ (e: 'clear'): void;
99
+ }
100
+ export interface PhoneInputSlots {
101
+ /** Slot for custom action buttons before default ones */
102
+ 'actions-before': {};
103
+ /** Slots for flag icons in the country list and country selector */
104
+ flag: {
105
+ country: MaskFull;
106
+ };
107
+ /** Slot for custom copy buttons */
108
+ 'copy-svg': {
109
+ copied: boolean;
110
+ };
111
+ /** Slot for custom clear button */
112
+ 'clear-svg': {};
113
+ }
114
+ export interface PhoneInputExposed {
115
+ /** Focus the phone input */
116
+ focus: () => void;
117
+ /** Blur the phone input */
118
+ blur: () => void;
119
+ /** Clear the phone input */
120
+ clear: () => void;
121
+ /** Select a country by its ISO 3166-1 alpha-2 code */
122
+ selectCountry: (country: CountryKey) => void;
123
+ /** Get the full phone number with country code (e.g. +1234567890) */
124
+ getFullNumber: () => string;
125
+ /** Get the full phone number formatted according to country rules (e.g. +1 234-567-890) */
126
+ getFullFormattedNumber: () => string;
127
+ /** Get only the digits of the phone number without country code (e.g. 234567890) */
128
+ getDigits: () => string;
129
+ /** Check if the current phone number is valid */
130
+ isValid: () => boolean;
131
+ /** Check if the current phone number is complete */
132
+ isComplete: () => boolean;
133
+ }
134
+ export interface FormatterHelpers {
135
+ formatDisplay: (digits: string) => string;
136
+ getMaxDigits: () => number;
137
+ getPlaceholder: () => string;
138
+ getCaretPosition: (digitIndex: number) => number;
139
+ getDigitRange: (digits: string, selStart: number, selEnd: number) => [number, number] | null;
140
+ isComplete: (digits: string) => boolean;
141
+ }
142
+ export interface PMaskGeoCache {
143
+ country_code: string;
144
+ ts: number;
145
+ }
146
+ /** Configuration options for the phone mask directive */
147
+ export interface PMaskDirectiveOptions {
148
+ /** Country ISO code (e.g., 'US', 'DE', 'GB') */
149
+ country?: string;
150
+ /** Locale for country names (default: navigator.language) */
151
+ locale?: string;
152
+ /** Auto-detect country from IP/locale (default: false) */
153
+ detect?: boolean;
154
+ /**
155
+ * Callback when formatted value changes.
156
+ * Provides full number, formatted phone number, and raw digits.
157
+ * @example
158
+ * onChange: (phone) => {
159
+ * console.log(phone.full); // +1234567890
160
+ * console.log(phone.fullFormatted); // +1 234-567-890
161
+ * console.log(phone.digits); // 234567890
162
+ * }
163
+ */
164
+ onChange?: (phone: PhoneNumber) => void;
165
+ /** Callback when country changes */
166
+ onCountryChange?: (country: MaskFull) => void;
167
+ }
168
+ /** Internal state stored on the input element of the directive */
169
+ export interface PMaskDirectiveState {
170
+ country: MaskFull;
171
+ formatter: FormatterHelpers;
172
+ digits: string;
173
+ locale: string;
174
+ options: PMaskDirectiveOptions;
175
+ beforeInputHandler?: (e: InputEvent) => void;
176
+ inputHandler?: (e: Event) => void;
177
+ keydownHandler?: (e: KeyboardEvent) => void;
178
+ pasteHandler?: (e: ClipboardEvent) => void;
179
+ }
180
+ /** Extended HTMLInputElement with directive state */
181
+ export interface DirectiveHTMLInputElement extends HTMLInputElement {
182
+ __phoneMaskState?: PMaskDirectiveState;
183
+ }
184
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRo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AAE,CAAC,CAAC,EAAE,UAAU,KAAK,IAAI,CAAC;IAC7C,YAAY,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,KAAK,IAAI,CAAC;IAClC,cAAc,CAAC,EAAE,CAAC,CAAC,EAAE,aAAa,KAAK,IAAI,CAAC;IAC5C,YAAY,CAAC,EAAE,CAAC,CAAC,EAAE,cAAc,KAAK,IAAI,CAAC;CAC5C;AAED,qDAAqD;AACrD,MAAM,WAAW,yBAA0B,SAAQ,gBAAgB;IACjE,gBAAgB,CAAC,EAAE,mBAAmB,CAAC;CACxC"}
package/package.json ADDED
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "@desource/phone-mask-vue",
3
+ "version": "0.2.0",
4
+ "description": "🔌 Vue 3 component & directive for international phone number masking. Powered by @desource/phone-mask with Google libphonenumber sync.",
5
+ "keywords": [
6
+ "vue",
7
+ "vue3",
8
+ "phone",
9
+ "mask",
10
+ "input",
11
+ "component",
12
+ "directive",
13
+ "international",
14
+ "libphonenumber",
15
+ "country-code",
16
+ "phone-number",
17
+ "formatting",
18
+ "validation",
19
+ "composition-api",
20
+ "typescript"
21
+ ],
22
+ "author": "Stefan Popov <stefan@desource-labs.org>",
23
+ "license": "MIT",
24
+ "repository": {
25
+ "type": "git",
26
+ "url": "git+https://github.com/DeSource-Labs/phone-mask.git",
27
+ "directory": "packages/phone-mask-vue"
28
+ },
29
+ "bugs": {
30
+ "url": "https://github.com/DeSource-Labs/phone-mask/issues"
31
+ },
32
+ "homepage": "https://github.com/DeSource-Labs/phone-mask/tree/main/packages/phone-mask-vue#readme",
33
+ "private": false,
34
+ "publishConfig": {
35
+ "access": "public"
36
+ },
37
+ "sideEffects": false,
38
+ "type": "module",
39
+ "main": "dist/index.cjs",
40
+ "module": "dist/index.mjs",
41
+ "types": "dist/types/index.d.ts",
42
+ "exports": {
43
+ ".": {
44
+ "types": "./dist/types/index.d.ts",
45
+ "import": "./dist/index.mjs",
46
+ "require": "./dist/index.cjs"
47
+ },
48
+ "./assets/lib.css": "./dist/phone-mask-vue.css"
49
+ },
50
+ "files": [
51
+ "dist",
52
+ "CHANGELOG.md",
53
+ "README.md"
54
+ ],
55
+ "dependencies": {
56
+ "@desource/phone-mask": "0.2.0"
57
+ },
58
+ "devDependencies": {
59
+ "@vitejs/plugin-vue": "^6.0.1",
60
+ "vue-tsc": "^3.1.3",
61
+ "vue": "^3.5.22"
62
+ },
63
+ "peerDependencies": {
64
+ "vue": "^3.4.33"
65
+ },
66
+ "scripts": {
67
+ "clean": "rimraf dist tsconfig.tsbuildinfo",
68
+ "build": "pnpm build-lib && pnpm build-types",
69
+ "build-lib": "vite build",
70
+ "build-types": "vue-tsc --emitDeclarationOnly --declaration -p tsconfig.json",
71
+ "typecheck": "tsc -p tsconfig.json --noEmit"
72
+ }
73
+ }