@10x-media/fields 0.1.0-beta.7 → 0.1.0-beta.8

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 (93) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/LICENSE +21 -21
  3. package/dist/exports/client.d.ts +4 -1
  4. package/dist/exports/client.js +4 -1
  5. package/dist/exports/phone-utils.d.ts +4 -0
  6. package/dist/exports/phone-utils.js +4 -0
  7. package/dist/exports/phone.d.ts +6 -0
  8. package/dist/exports/phone.js +3 -0
  9. package/dist/exports/rsc.d.ts +3 -1
  10. package/dist/exports/rsc.js +3 -1
  11. package/dist/exports/types.d.ts +3 -2
  12. package/dist/fields/icon/rsc/IconFieldServer.js +1 -1
  13. package/dist/fields/icon/rsc/IconFieldServer.js.map +1 -1
  14. package/dist/fields/icon/rsc/IconLibrarySelectServer.js +1 -1
  15. package/dist/fields/icon/rsc/IconLibrarySelectServer.js.map +1 -1
  16. package/dist/fields/icon/shared/iconLabel.js +1 -1
  17. package/dist/fields/icon/shared/iconLabel.js.map +1 -1
  18. package/dist/fields/phoneNumber/client/CountryFlag.d.ts +16 -0
  19. package/dist/fields/phoneNumber/client/CountryFlag.js +40 -0
  20. package/dist/fields/phoneNumber/client/CountryFlag.js.map +1 -0
  21. package/dist/fields/phoneNumber/client/CountryPicker.d.ts +21 -0
  22. package/dist/fields/phoneNumber/client/CountryPicker.js +255 -0
  23. package/dist/fields/phoneNumber/client/CountryPicker.js.map +1 -0
  24. package/dist/fields/phoneNumber/client/PhoneNumberField.d.ts +26 -0
  25. package/dist/fields/phoneNumber/client/PhoneNumberField.js +318 -0
  26. package/dist/fields/phoneNumber/client/PhoneNumberField.js.map +1 -0
  27. package/dist/fields/phoneNumber/client/editModel.js +86 -0
  28. package/dist/fields/phoneNumber/client/editModel.js.map +1 -0
  29. package/dist/fields/phoneNumber/client/phoneNumberField.css +305 -0
  30. package/dist/fields/phoneNumber/engine/countries.d.ts +36 -0
  31. package/dist/fields/phoneNumber/engine/countries.js +68 -0
  32. package/dist/fields/phoneNumber/engine/countries.js.map +1 -0
  33. package/dist/fields/phoneNumber/engine/draft.d.ts +13 -0
  34. package/dist/fields/phoneNumber/engine/draft.js +72 -0
  35. package/dist/fields/phoneNumber/engine/draft.js.map +1 -0
  36. package/dist/fields/phoneNumber/engine/metadata.d.ts +11 -0
  37. package/dist/fields/phoneNumber/engine/metadata.js +32 -0
  38. package/dist/fields/phoneNumber/engine/metadata.js.map +1 -0
  39. package/dist/fields/phoneNumber/engine/phone.d.ts +37 -0
  40. package/dist/fields/phoneNumber/engine/phone.js +59 -0
  41. package/dist/fields/phoneNumber/engine/phone.js.map +1 -0
  42. package/dist/fields/phoneNumber/options.d.ts +72 -0
  43. package/dist/fields/phoneNumber/options.js +37 -0
  44. package/dist/fields/phoneNumber/options.js.map +1 -0
  45. package/dist/fields/phoneNumber/phoneNumberField.d.ts +14 -0
  46. package/dist/fields/phoneNumber/phoneNumberField.js +167 -0
  47. package/dist/fields/phoneNumber/phoneNumberField.js.map +1 -0
  48. package/dist/fields/phoneNumber/server/PhoneNumberCellServer.d.ts +19 -0
  49. package/dist/fields/phoneNumber/server/PhoneNumberCellServer.js +73 -0
  50. package/dist/fields/phoneNumber/server/PhoneNumberCellServer.js.map +1 -0
  51. package/dist/fields/phoneNumber/server/PhoneNumberFieldServer.d.ts +16 -0
  52. package/dist/fields/phoneNumber/server/PhoneNumberFieldServer.js +57 -0
  53. package/dist/fields/phoneNumber/server/PhoneNumberFieldServer.js.map +1 -0
  54. package/dist/fields/phoneNumber/server/flagsEndpoint.js +51 -0
  55. package/dist/fields/phoneNumber/server/flagsEndpoint.js.map +1 -0
  56. package/dist/fields/phoneNumber/server/readPhoneOptions.js +18 -0
  57. package/dist/fields/phoneNumber/server/readPhoneOptions.js.map +1 -0
  58. package/dist/fields/phoneNumber/server/resolvePhoneOptionsSafe.js +33 -0
  59. package/dist/fields/phoneNumber/server/resolvePhoneOptionsSafe.js.map +1 -0
  60. package/dist/index.d.ts +4 -3
  61. package/dist/index.js +17 -0
  62. package/dist/index.js.map +1 -1
  63. package/dist/translations/ar.js +9 -1
  64. package/dist/translations/ar.js.map +1 -1
  65. package/dist/translations/de.js +9 -1
  66. package/dist/translations/de.js.map +1 -1
  67. package/dist/translations/en.js +9 -1
  68. package/dist/translations/en.js.map +1 -1
  69. package/dist/translations/es.js +9 -1
  70. package/dist/translations/es.js.map +1 -1
  71. package/dist/translations/fr.js +9 -1
  72. package/dist/translations/fr.js.map +1 -1
  73. package/dist/translations/id.js +9 -1
  74. package/dist/translations/id.js.map +1 -1
  75. package/dist/translations/keys.d.ts +8 -0
  76. package/dist/translations/keys.js +9 -1
  77. package/dist/translations/keys.js.map +1 -1
  78. package/dist/translations/ko.js +9 -1
  79. package/dist/translations/ko.js.map +1 -1
  80. package/dist/translations/pt.js +9 -1
  81. package/dist/translations/pt.js.map +1 -1
  82. package/dist/translations/ru.js +9 -1
  83. package/dist/translations/ru.js.map +1 -1
  84. package/dist/translations/uk.js +9 -1
  85. package/dist/translations/uk.js.map +1 -1
  86. package/dist/translations/zh.js +9 -1
  87. package/dist/translations/zh.js.map +1 -1
  88. package/dist/types.d.ts +22 -1
  89. package/dist/utils/resolveStaticLabel.js +13 -0
  90. package/dist/utils/resolveStaticLabel.js.map +1 -0
  91. package/package.json +15 -3
  92. package/dist/fields/icon/shared/resolveStaticLabel.js +0 -16
  93. package/dist/fields/icon/shared/resolveStaticLabel.js.map +0 -1
@@ -0,0 +1,305 @@
1
+ /* Mirrors Payload's formInput mixin (packages/ui/src/scss/vars.scss) so the composite
2
+ row reads as one native text input; focus rides :focus-within.
3
+ Dimensions are static px on purpose: Payload compiles scss base() to literal px
4
+ (native inputs stay 40px tall at every breakpoint), while the runtime --base var
5
+ is rem-based and shrinks with the responsive html font-size. */
6
+ .fields-phone__container {
7
+ display: flex;
8
+ align-items: center;
9
+ gap: 6px;
10
+ width: 100%;
11
+ height: 40px;
12
+ padding: 0 8px 0 4px;
13
+ border: 1px solid var(--theme-elevation-150);
14
+ border-radius: var(--style-radius-s);
15
+ background: var(--theme-input-bg);
16
+ color: var(--theme-elevation-800);
17
+ font-family: var(--font-body);
18
+ font-size: 1rem;
19
+ box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.1);
20
+ transition-property: border, box-shadow, background-color;
21
+ transition-duration: 100ms, 100ms, 500ms;
22
+ transition-timing-function: cubic-bezier(0, 0.2, 0.2, 1);
23
+ }
24
+
25
+ .fields-phone__container:hover {
26
+ border-color: var(--theme-elevation-250);
27
+ box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.2);
28
+ }
29
+
30
+ .fields-phone__container:focus-within {
31
+ border-color: var(--theme-elevation-400);
32
+ outline: 0;
33
+ }
34
+
35
+ html[data-theme="light"] .fields-phone.error .fields-phone__container {
36
+ background-color: var(--theme-error-50);
37
+ border-color: var(--theme-error-500);
38
+ }
39
+
40
+ html[data-theme="dark"] .fields-phone.error .fields-phone__container {
41
+ background-color: var(--theme-error-100);
42
+ border-color: var(--theme-error-400);
43
+ }
44
+
45
+ html[data-theme="dark"] .fields-phone.error .fields-phone__container:hover {
46
+ border-color: var(--theme-error-500);
47
+ }
48
+
49
+ .fields-phone.read-only .fields-phone__container,
50
+ .fields-phone.read-only .fields-phone__container:hover {
51
+ border-color: var(--theme-elevation-150);
52
+ background: var(--theme-elevation-100);
53
+ color: var(--theme-elevation-400);
54
+ box-shadow: none;
55
+ }
56
+
57
+ /* Popup's own root. The trigger is inset rather than stretched, so its hover fill clears the
58
+ container's border by the same 4px on the left, top and bottom instead of bleeding into it. */
59
+ .fields-phone__picker {
60
+ display: flex;
61
+ align-self: center;
62
+ }
63
+
64
+ /* 10px of padding puts the flag on the 15px text column every native input starts at. */
65
+ .fields-phone__trigger {
66
+ display: inline-flex;
67
+ flex-shrink: 0;
68
+ align-items: center;
69
+ gap: 4px;
70
+ height: 30px;
71
+ padding: 0 10px;
72
+ border: 0;
73
+ border-radius: var(--style-radius-s);
74
+ background: transparent;
75
+ color: var(--theme-elevation-500);
76
+ cursor: pointer;
77
+ }
78
+
79
+ .fields-phone__trigger:hover {
80
+ background: var(--theme-elevation-100);
81
+ color: var(--theme-elevation-800);
82
+ }
83
+
84
+ .fields-phone__trigger:focus-visible {
85
+ outline: var(--accessibility-outline);
86
+ }
87
+
88
+ .fields-phone__trigger:disabled {
89
+ background: transparent;
90
+ cursor: not-allowed;
91
+ }
92
+
93
+ .fields-phone__caret {
94
+ display: flex;
95
+ flex-shrink: 0;
96
+ align-items: center;
97
+ justify-content: center;
98
+ width: 12px;
99
+ height: 12px;
100
+ }
101
+
102
+ .fields-phone__code {
103
+ color: var(--theme-elevation-800);
104
+ font-size: 0.85rem;
105
+ white-space: nowrap;
106
+ }
107
+
108
+ /* A calling code is LTR wherever it is shown: under an RTL page the leading + is a neutral and
109
+ bidi reorders "+49" to "49+". The UA stylesheet does the same for input[type="tel"]. */
110
+ .fields-phone__prefix {
111
+ flex-shrink: 0;
112
+ direction: ltr;
113
+ font-variant-numeric: tabular-nums;
114
+ white-space: nowrap;
115
+ }
116
+
117
+ /* Chrome-less: the container owns the border, background and focus ring */
118
+ .fields-phone__input {
119
+ flex: 1;
120
+ min-width: 0;
121
+ height: 100%;
122
+ padding: 0;
123
+ border: 0;
124
+ background: transparent;
125
+ color: inherit;
126
+ font-family: var(--font-body);
127
+ font-size: 1rem;
128
+ line-height: 20px;
129
+ outline: 0;
130
+ -webkit-appearance: none;
131
+ }
132
+
133
+ .fields-phone__input::placeholder {
134
+ color: var(--theme-elevation-400);
135
+ font-weight: normal;
136
+ font-size: 1rem;
137
+ }
138
+
139
+ /* Matches the native select's clear indicator: bare icon, no button chrome */
140
+ .fields-phone__clear {
141
+ display: flex;
142
+ flex-shrink: 0;
143
+ align-items: center;
144
+ padding: 0;
145
+ border: 0;
146
+ background: transparent;
147
+ color: var(--theme-elevation-500);
148
+ cursor: pointer;
149
+ }
150
+
151
+ .fields-phone__clear:hover {
152
+ color: var(--theme-elevation-800);
153
+ }
154
+
155
+ .fields-phone__clear:focus-visible {
156
+ outline: var(--accessibility-outline);
157
+ }
158
+
159
+ .fields-phone__flag {
160
+ display: block;
161
+ flex-shrink: 0;
162
+ width: 20px;
163
+ height: 15px;
164
+ border-radius: 1px;
165
+ object-fit: cover;
166
+ }
167
+
168
+ .fields-phone__flag--emoji {
169
+ width: auto;
170
+ font-size: 15px;
171
+ line-height: 1;
172
+ }
173
+
174
+ .fields-phone__sr-only {
175
+ position: absolute;
176
+ width: 1px;
177
+ height: 1px;
178
+ margin: -1px;
179
+ padding: 0;
180
+ overflow: hidden;
181
+ clip: rect(0 0 0 0);
182
+ white-space: nowrap;
183
+ border-width: 0;
184
+ }
185
+
186
+ /* Payload portals popup content to document.body, and caps that scroll container at
187
+ calc(var(--base) * 10); a country list is taller than that and would be clipped behind
188
+ a hidden scrollbar. The panel already bounds its own height, so the outer cap comes off
189
+ entirely rather than being kept in step with it by arithmetic. */
190
+ .popup__scroll-container:has(> .fields-phone__panel) {
191
+ max-height: none;
192
+ }
193
+
194
+ /* The gap matches Popup's own content padding, so the search clears the panel edge by the
195
+ same 10px on all four sides. */
196
+ .fields-phone__panel {
197
+ display: flex;
198
+ flex-direction: column;
199
+ gap: 10px;
200
+ width: 260px;
201
+ }
202
+
203
+ /* Native input size: Payload's scale carries nothing smaller than 40px at 1rem */
204
+ .fields-phone__search {
205
+ display: flex;
206
+ flex-shrink: 0;
207
+ align-items: center;
208
+ gap: 6px;
209
+ height: 40px;
210
+ padding: 0 8px;
211
+ border: 1px solid var(--theme-elevation-150);
212
+ border-radius: var(--style-radius-s);
213
+ background: var(--theme-input-bg);
214
+ }
215
+
216
+ .fields-phone__search:focus-within {
217
+ border-color: var(--theme-elevation-400);
218
+ }
219
+
220
+ .fields-phone__search-icon {
221
+ display: flex;
222
+ flex-shrink: 0;
223
+ width: 14px;
224
+ height: 14px;
225
+ color: var(--theme-elevation-400);
226
+ }
227
+
228
+ .fields-phone__search-input {
229
+ flex: 1;
230
+ min-width: 0;
231
+ border: 0;
232
+ background: transparent;
233
+ color: inherit;
234
+ font-family: var(--font-body);
235
+ font-size: 1rem;
236
+ outline: 0;
237
+ }
238
+
239
+ .fields-phone__search-input::placeholder {
240
+ color: var(--theme-elevation-400);
241
+ }
242
+
243
+ /* max-height comes from the component, off the same row height the virtualizer measures with. */
244
+ .fields-phone__list {
245
+ overflow-y: auto;
246
+ }
247
+
248
+ .fields-phone__group {
249
+ display: flex;
250
+ align-items: center;
251
+ padding: 0 8px;
252
+ border-top: 1px solid var(--theme-elevation-100);
253
+ /* elevation-500 fails 4.5:1 at this font size against the panel background */
254
+ color: var(--theme-elevation-700);
255
+ font-size: 0.7rem;
256
+ letter-spacing: 0.06em;
257
+ text-transform: uppercase;
258
+ }
259
+
260
+ .fields-phone__option {
261
+ display: flex;
262
+ align-items: center;
263
+ gap: 8px;
264
+ padding: 0 8px;
265
+ border: 0;
266
+ border-radius: var(--style-radius-s);
267
+ background: transparent;
268
+ color: var(--theme-elevation-800);
269
+ font-family: var(--font-body);
270
+ font-size: 0.9rem;
271
+ text-align: left;
272
+ cursor: pointer;
273
+ }
274
+
275
+ .fields-phone__option:hover,
276
+ .fields-phone__option[data-active="true"] {
277
+ background: var(--theme-elevation-100);
278
+ }
279
+
280
+ .fields-phone__option[aria-selected="true"] {
281
+ background: var(--theme-elevation-150);
282
+ }
283
+
284
+ .fields-phone__option-name {
285
+ flex: 1;
286
+ min-width: 0;
287
+ overflow: hidden;
288
+ white-space: nowrap;
289
+ text-overflow: ellipsis;
290
+ }
291
+
292
+ .fields-phone__option-code {
293
+ flex-shrink: 0;
294
+ direction: ltr;
295
+ /* elevation-500 fails 4.5:1 at this font size against the panel background */
296
+ color: var(--theme-elevation-700);
297
+ font-variant-numeric: tabular-nums;
298
+ }
299
+
300
+ .fields-phone__empty {
301
+ padding: 12px 8px;
302
+ color: var(--theme-elevation-700);
303
+ font-size: 0.9rem;
304
+ text-align: center;
305
+ }
@@ -0,0 +1,36 @@
1
+ import { PhoneMetadata } from "./metadata.js";
2
+ import { CountryCode } from "./phone.js";
3
+
4
+ //#region src/fields/phoneNumber/engine/countries.d.ts
5
+ type CountryOption = {
6
+ callingCode: string;
7
+ code: CountryCode;
8
+ name: string;
9
+ };
10
+ /** Regional indicator pairs are pure arithmetic over the ISO code, so no artwork is needed. */
11
+ declare const emojiFlag: (code: CountryCode) => string;
12
+ declare const isSupported: (code: string, metadata: PhoneMetadata) => boolean;
13
+ /**
14
+ * A property of the country itself, so it holds for a stored country the field's `countries`
15
+ * allowlist does not offer. Undefined rather than a throw for one this set does not carry.
16
+ */
17
+ declare const callingCodeFor: (code: CountryCode, metadata: PhoneMetadata) => string | undefined;
18
+ /**
19
+ * Every code libphonenumber-js ships, identical across all three metadata sets (pinned
20
+ * against the real 'max' set below). Unlike `isSupported`, this needs no metadata, so
21
+ * synchronous config-time guards can use it without awaiting `loadMetadata`.
22
+ */
23
+ declare const KNOWN_COUNTRY_CODES: ReadonlySet<string>;
24
+ declare const isKnownCountry: (code: string) => boolean;
25
+ declare const countryOptions: (opts: {
26
+ countries?: readonly CountryCode[];
27
+ locale: string;
28
+ metadata: PhoneMetadata;
29
+ priorityCountries?: readonly CountryCode[];
30
+ }) => {
31
+ priority: CountryOption[];
32
+ rest: CountryOption[];
33
+ };
34
+ //#endregion
35
+ export { CountryOption, KNOWN_COUNTRY_CODES, callingCodeFor, countryOptions, emojiFlag, isKnownCountry, isSupported };
36
+ //# sourceMappingURL=countries.d.ts.map
@@ -0,0 +1,68 @@
1
+ import { getCountries, getCountryCallingCode, isSupportedCountry } from "libphonenumber-js/core";
2
+ //#region src/fields/phoneNumber/engine/countries.ts
3
+ const REGIONAL_INDICATOR_A = 127462;
4
+ const LATIN_A = "A".charCodeAt(0);
5
+ /** Regional indicator pairs are pure arithmetic over the ISO code, so no artwork is needed. */
6
+ const emojiFlag = (code) => [...code.toUpperCase()].map((char) => String.fromCodePoint(REGIONAL_INDICATOR_A + char.charCodeAt(0) - LATIN_A)).join("");
7
+ const isSupported = (code, metadata) => isSupportedCountry(code, metadata);
8
+ /**
9
+ * A property of the country itself, so it holds for a stored country the field's `countries`
10
+ * allowlist does not offer. Undefined rather than a throw for one this set does not carry.
11
+ */
12
+ const callingCodeFor = (code, metadata) => {
13
+ try {
14
+ return getCountryCallingCode(code, metadata);
15
+ } catch {
16
+ return;
17
+ }
18
+ };
19
+ /**
20
+ * Every code libphonenumber-js ships, identical across all three metadata sets (pinned
21
+ * against the real 'max' set below). Unlike `isSupported`, this needs no metadata, so
22
+ * synchronous config-time guards can use it without awaiting `loadMetadata`.
23
+ */
24
+ const KNOWN_COUNTRY_CODES = new Set("AC AD AE AF AG AI AL AM AO AR AS AT AU AW AX AZ BA BB BD BE BF BG BH BI BJ BL BM BN BO BQ BR BS BT BW BY BZ CA CC CD CF CG CH CI CK CL CM CN CO CR CU CV CW CX CY CZ DE DJ DK DM DO DZ EC EE EG EH ER ES ET FI FJ FK FM FO FR GA GB GD GE GF GG GH GI GL GM GN GP GQ GR GT GU GW GY HK HN HR HT HU ID IE IL IM IN IO IQ IR IS IT JE JM JO JP KE KG KH KI KM KN KP KR KW KY KZ LA LB LC LI LK LR LS LT LU LV LY MA MC MD ME MF MG MH MK ML MM MN MO MP MQ MR MS MT MU MV MW MX MY MZ NA NC NE NF NG NI NL NO NP NR NU NZ OM PA PE PF PG PH PK PL PM PR PS PT PW PY QA RE RO RS RU RW SA SB SC SD SE SG SH SI SJ SK SL SM SN SO SR SS ST SV SX SY SZ TA TC TD TG TH TJ TK TL TM TN TO TR TT TV TW TZ UA UG US UY UZ VA VC VE VG VI VN VU WF WS XK YE YT ZA ZM ZW".split(" "));
25
+ const isKnownCountry = (code) => KNOWN_COUNTRY_CODES.has(code);
26
+ /**
27
+ * The country a calling code belongs to when it belongs to several, which libphonenumber
28
+ * records as the first of the list. No exported accessor reaches that list, so the metadata
29
+ * is read directly here and its shape is pinned by a test rather than trusted.
30
+ */
31
+ const mainCountryForCallingCode = (callingCode, metadata) => {
32
+ const map = metadata.country_calling_codes;
33
+ if (typeof map !== "object" || map === null) return void 0;
34
+ const listed = map[callingCode];
35
+ const first = Array.isArray(listed) ? listed[0] : void 0;
36
+ return typeof first === "string" && isKnownCountry(first) ? first : void 0;
37
+ };
38
+ /**
39
+ * Intl.DisplayNames covers every admin locale natively, so no translation keys are needed.
40
+ * Only a malformed tag throws; a well-formed but unrecognized one resolves to a default.
41
+ */
42
+ const displayNames = (locale) => {
43
+ try {
44
+ return new Intl.DisplayNames([locale], { type: "region" });
45
+ } catch {
46
+ return null;
47
+ }
48
+ };
49
+ const countryOptions = (opts) => {
50
+ const names = displayNames(opts.locale);
51
+ const available = new Set(getCountries(opts.metadata));
52
+ const selected = (opts.countries ?? [...available]).filter((code) => available.has(code));
53
+ const toOption = (code) => ({
54
+ callingCode: getCountryCallingCode(code, opts.metadata),
55
+ code,
56
+ name: names?.of(code) ?? code
57
+ });
58
+ const priorityCodes = (opts.priorityCountries ?? []).filter((code) => selected.includes(code));
59
+ const prioritySet = new Set(priorityCodes);
60
+ return {
61
+ priority: priorityCodes.map(toOption),
62
+ rest: selected.filter((code) => !prioritySet.has(code)).map(toOption).sort((a, b) => a.name.localeCompare(b.name, opts.locale))
63
+ };
64
+ };
65
+ //#endregion
66
+ export { KNOWN_COUNTRY_CODES, callingCodeFor, countryOptions, emojiFlag, isKnownCountry, isSupported, mainCountryForCallingCode };
67
+
68
+ //# sourceMappingURL=countries.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"countries.js","names":[],"sources":["../../../../src/fields/phoneNumber/engine/countries.ts"],"sourcesContent":["import { getCountries, getCountryCallingCode, isSupportedCountry } from 'libphonenumber-js/core'\nimport type { PhoneMetadata } from './metadata'\nimport type { CountryCode } from './phone'\n\nexport type CountryOption = { callingCode: string; code: CountryCode; name: string }\n\nconst REGIONAL_INDICATOR_A = 0x1f1e6\nconst LATIN_A = 'A'.charCodeAt(0)\n\n/** Regional indicator pairs are pure arithmetic over the ISO code, so no artwork is needed. */\nexport const emojiFlag = (code: CountryCode): string =>\n\t[...code.toUpperCase()]\n\t\t.map((char) => String.fromCodePoint(REGIONAL_INDICATOR_A + char.charCodeAt(0) - LATIN_A))\n\t\t.join('')\n\nexport const isSupported = (code: string, metadata: PhoneMetadata): boolean =>\n\tisSupportedCountry(code as CountryCode, metadata as never)\n\n/**\n * A property of the country itself, so it holds for a stored country the field's `countries`\n * allowlist does not offer. Undefined rather than a throw for one this set does not carry.\n */\nexport const callingCodeFor = (code: CountryCode, metadata: PhoneMetadata): string | undefined => {\n\ttry {\n\t\treturn getCountryCallingCode(code, metadata as never)\n\t} catch {\n\t\treturn undefined\n\t}\n}\n\n/**\n * Every code libphonenumber-js ships, identical across all three metadata sets (pinned\n * against the real 'max' set below). Unlike `isSupported`, this needs no metadata, so\n * synchronous config-time guards can use it without awaiting `loadMetadata`.\n */\nexport const KNOWN_COUNTRY_CODES: ReadonlySet<string> = new Set(\n\t(\n\t\t'AC AD AE AF AG AI AL AM AO AR AS AT AU AW AX AZ BA BB BD BE BF BG BH BI BJ BL BM BN BO BQ BR ' +\n\t\t'BS BT BW BY BZ CA CC CD CF CG CH CI CK CL CM CN CO CR CU CV CW CX CY CZ DE DJ DK DM DO DZ EC ' +\n\t\t'EE EG EH ER ES ET FI FJ FK FM FO FR GA GB GD GE GF GG GH GI GL GM GN GP GQ GR GT GU GW GY HK ' +\n\t\t'HN HR HT HU ID IE IL IM IN IO IQ IR IS IT JE JM JO JP KE KG KH KI KM KN KP KR KW KY KZ LA LB ' +\n\t\t'LC LI LK LR LS LT LU LV LY MA MC MD ME MF MG MH MK ML MM MN MO MP MQ MR MS MT MU MV MW MX MY ' +\n\t\t'MZ NA NC NE NF NG NI NL NO NP NR NU NZ OM PA PE PF PG PH PK PL PM PR PS PT PW PY QA RE RO RS ' +\n\t\t'RU RW SA SB SC SD SE SG SH SI SJ SK SL SM SN SO SR SS ST SV SX SY SZ TA TC TD TG TH TJ TK TL ' +\n\t\t'TM TN TO TR TT TV TW TZ UA UG US UY UZ VA VC VE VG VI VN VU WF WS XK YE YT ZA ZM ZW'\n\t).split(' ')\n)\n\nexport const isKnownCountry = (code: string): boolean => KNOWN_COUNTRY_CODES.has(code)\n\n/**\n * The country a calling code belongs to when it belongs to several, which libphonenumber\n * records as the first of the list. No exported accessor reaches that list, so the metadata\n * is read directly here and its shape is pinned by a test rather than trusted.\n */\nexport const mainCountryForCallingCode = (\n\tcallingCode: string,\n\tmetadata: PhoneMetadata\n): CountryCode | undefined => {\n\tconst map: unknown = metadata.country_calling_codes\n\tif (typeof map !== 'object' || map === null) return undefined\n\tconst listed: unknown = (map as Record<string, unknown>)[callingCode]\n\tconst first: unknown = Array.isArray(listed) ? (listed as readonly unknown[])[0] : undefined\n\treturn typeof first === 'string' && isKnownCountry(first) ? (first as CountryCode) : undefined\n}\n\n/**\n * Intl.DisplayNames covers every admin locale natively, so no translation keys are needed.\n * Only a malformed tag throws; a well-formed but unrecognized one resolves to a default.\n */\nconst displayNames = (locale: string): Intl.DisplayNames | null => {\n\ttry {\n\t\treturn new Intl.DisplayNames([locale], { type: 'region' })\n\t} catch {\n\t\treturn null\n\t}\n}\n\nexport const countryOptions = (opts: {\n\tcountries?: readonly CountryCode[]\n\tlocale: string\n\tmetadata: PhoneMetadata\n\tpriorityCountries?: readonly CountryCode[]\n}): { priority: CountryOption[]; rest: CountryOption[] } => {\n\tconst names = displayNames(opts.locale)\n\tconst available = new Set(getCountries(opts.metadata as never))\n\tconst selected = (opts.countries ?? [...available]).filter((code) => available.has(code))\n\n\tconst toOption = (code: CountryCode): CountryOption => ({\n\t\tcallingCode: getCountryCallingCode(code, opts.metadata as never),\n\t\tcode,\n\t\tname: names?.of(code) ?? code,\n\t})\n\n\tconst priorityCodes = (opts.priorityCountries ?? []).filter((code) => selected.includes(code))\n\tconst prioritySet = new Set(priorityCodes)\n\n\treturn {\n\t\tpriority: priorityCodes.map(toOption),\n\t\trest: selected\n\t\t\t.filter((code) => !prioritySet.has(code))\n\t\t\t.map(toOption)\n\t\t\t.sort((a, b) => a.name.localeCompare(b.name, opts.locale)),\n\t}\n}\n"],"mappings":";;AAMA,MAAM,uBAAuB;AAC7B,MAAM,UAAU,IAAI,WAAW,CAAC;;AAGhC,MAAa,aAAa,SACzB,CAAC,GAAG,KAAK,YAAY,CAAC,EACpB,KAAK,SAAS,OAAO,cAAc,uBAAuB,KAAK,WAAW,CAAC,IAAI,OAAO,CAAC,EACvF,KAAK,EAAE;AAEV,MAAa,eAAe,MAAc,aACzC,mBAAmB,MAAqB,QAAiB;;;;;AAM1D,MAAa,kBAAkB,MAAmB,aAAgD;CACjG,IAAI;EACH,OAAO,sBAAsB,MAAM,QAAiB;CACrD,QAAQ;EACP;CACD;AACD;;;;;;AAOA,MAAa,sBAA2C,IAAI,IAE1D,iuBAQC,MAAM,GAAG,CACZ;AAEA,MAAa,kBAAkB,SAA0B,oBAAoB,IAAI,IAAI;;;;;;AAOrF,MAAa,6BACZ,aACA,aAC6B;CAC7B,MAAM,MAAe,SAAS;CAC9B,IAAI,OAAO,QAAQ,YAAY,QAAQ,MAAM,OAAO,KAAA;CACpD,MAAM,SAAmB,IAAgC;CACzD,MAAM,QAAiB,MAAM,QAAQ,MAAM,IAAK,OAA8B,KAAK,KAAA;CACnF,OAAO,OAAO,UAAU,YAAY,eAAe,KAAK,IAAK,QAAwB,KAAA;AACtF;;;;;AAMA,MAAM,gBAAgB,WAA6C;CAClE,IAAI;EACH,OAAO,IAAI,KAAK,aAAa,CAAC,MAAM,GAAG,EAAE,MAAM,SAAS,CAAC;CAC1D,QAAQ;EACP,OAAO;CACR;AACD;AAEA,MAAa,kBAAkB,SAK6B;CAC3D,MAAM,QAAQ,aAAa,KAAK,MAAM;CACtC,MAAM,YAAY,IAAI,IAAI,aAAa,KAAK,QAAiB,CAAC;CAC9D,MAAM,YAAY,KAAK,aAAa,CAAC,GAAG,SAAS,GAAG,QAAQ,SAAS,UAAU,IAAI,IAAI,CAAC;CAExF,MAAM,YAAY,UAAsC;EACvD,aAAa,sBAAsB,MAAM,KAAK,QAAiB;EAC/D;EACA,MAAM,OAAO,GAAG,IAAI,KAAK;CAC1B;CAEA,MAAM,iBAAiB,KAAK,qBAAqB,CAAC,GAAG,QAAQ,SAAS,SAAS,SAAS,IAAI,CAAC;CAC7F,MAAM,cAAc,IAAI,IAAI,aAAa;CAEzC,OAAO;EACN,UAAU,cAAc,IAAI,QAAQ;EACpC,MAAM,SACJ,QAAQ,SAAS,CAAC,YAAY,IAAI,IAAI,CAAC,EACvC,IAAI,QAAQ,EACZ,MAAM,GAAG,MAAM,EAAE,KAAK,cAAc,EAAE,MAAM,KAAK,MAAM,CAAC;CAC3D;AACD"}
@@ -0,0 +1,13 @@
1
+ import { CountryCode } from "./phone.js";
2
+
3
+ //#region src/fields/phoneNumber/engine/draft.d.ts
4
+ /** What the admin row shows for a stored number, split the way the row lays it out. */
5
+ type PhoneSeed = {
6
+ callingCode: string;
7
+ country: CountryCode | undefined;
8
+ national: string;
9
+ number: string;
10
+ };
11
+ //#endregion
12
+ export { PhoneSeed };
13
+ //# sourceMappingURL=draft.d.ts.map
@@ -0,0 +1,72 @@
1
+ import { mainCountryForCallingCode } from "./countries.js";
2
+ import { parsePhone } from "./phone.js";
3
+ import { AsYouType, validatePhoneNumberLength } from "libphonenumber-js/core";
4
+ //#region src/fields/phoneNumber/engine/draft.ts
5
+ /**
6
+ * Admin-input plumbing over the engine: what a half-typed draft already implies, how long it
7
+ * may still grow, and how the row splits a stored number. None of it is published through
8
+ * `@10x-media/fields/phone/utils`, which carries the engine proper.
9
+ */
10
+ /** E.164 allows 15 digits after the `+`, the country calling code counted among them. */
11
+ const E164_MAX_DIGITS = 15;
12
+ /** Digits, spacing and the separators real-world sources wrap a number in. */
13
+ const PHONE_INPUT_PATTERN = /^[\d\s+()./-]*$/;
14
+ /** Whether a draft holds only characters a phone number can be written with. */
15
+ const isPhoneInput = (input) => PHONE_INPUT_PATTERN.test(input);
16
+ const isInternational = (input) => input.trimStart().startsWith("+");
17
+ const digitCount = (input) => (input.match(/\d/g) ?? []).length;
18
+ /**
19
+ * Whether a draft is already longer than any number it could still become. The country's own
20
+ * ceiling decides wherever the metadata defines one, and E.164's 15 digits backstop the rest:
21
+ * several countries, Germany among them, carry no upper bound of their own.
22
+ */
23
+ const exceedsPhoneLength = (input, opts) => {
24
+ const digits = digitCount(input);
25
+ if (digits === 0) return false;
26
+ if (digits + (isInternational(input) ? 0 : digitCount(opts.callingCode ?? "")) > E164_MAX_DIGITS) return true;
27
+ return validatePhoneNumberLength(input, { defaultCountry: opts.defaultCountry }, opts.metadata) === "TOO_LONG";
28
+ };
29
+ /** The number without its calling code, so it reads as one phrase beside the prefix. */
30
+ const nationalPart = (parsed) => {
31
+ const prefix = `+${parsed.callingCode}`;
32
+ return parsed.international.startsWith(prefix) ? parsed.international.slice(prefix.length).trimStart() : parsed.national;
33
+ };
34
+ /**
35
+ * Derived wherever metadata is already free (the server), so the first client frame can
36
+ * match the frame the engine paints once the lazy metadata import resolves.
37
+ */
38
+ const phoneSeed = (raw, opts) => {
39
+ const parsed = parsePhone(raw, opts);
40
+ if (!parsed) return null;
41
+ return {
42
+ callingCode: parsed.callingCode,
43
+ country: parsed.country,
44
+ national: nationalPart(parsed),
45
+ number: raw
46
+ };
47
+ };
48
+ const readTyping = (input, metadata) => {
49
+ const typing = new AsYouType(void 0, metadata);
50
+ typing.input(input);
51
+ return {
52
+ callingCode: typing.getCallingCode(),
53
+ country: typing.getCountry()
54
+ };
55
+ };
56
+ /** The calling code the typed digits already identify, undefined while none fits them. */
57
+ const callingCodeOf = (input, opts) => readTyping(input, opts.metadata).callingCode;
58
+ /**
59
+ * The country a partial international draft already implies. Which calling code this is settles
60
+ * on sight; which country within a shared one takes more digits, so the code's main country
61
+ * stands in until the leading digits distinguish a specific one. Undefined for anything that
62
+ * carries no calling code at all, so junk still names no country.
63
+ */
64
+ const provisionalCountry = (input, opts) => {
65
+ const { callingCode, country } = readTyping(input, opts.metadata);
66
+ if (country !== void 0) return country;
67
+ return callingCode === void 0 ? void 0 : mainCountryForCallingCode(callingCode, opts.metadata);
68
+ };
69
+ //#endregion
70
+ export { callingCodeOf, digitCount, exceedsPhoneLength, isInternational, isPhoneInput, nationalPart, phoneSeed, provisionalCountry };
71
+
72
+ //# sourceMappingURL=draft.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"draft.js","names":[],"sources":["../../../../src/fields/phoneNumber/engine/draft.ts"],"sourcesContent":["/**\n * Admin-input plumbing over the engine: what a half-typed draft already implies, how long it\n * may still grow, and how the row splits a stored number. None of it is published through\n * `@10x-media/fields/phone/utils`, which carries the engine proper.\n */\nimport { AsYouType, validatePhoneNumberLength } from 'libphonenumber-js/core'\nimport { mainCountryForCallingCode } from './countries'\nimport type { PhoneMetadata } from './metadata'\nimport { type CountryCode, type ParsedPhone, type PhoneOptions, parsePhone } from './phone'\n\n/** E.164 allows 15 digits after the `+`, the country calling code counted among them. */\nconst E164_MAX_DIGITS = 15\n\n/** Digits, spacing and the separators real-world sources wrap a number in. */\nconst PHONE_INPUT_PATTERN = /^[\\d\\s+()./-]*$/\n\n/** Whether a draft holds only characters a phone number can be written with. */\nexport const isPhoneInput = (input: string): boolean => PHONE_INPUT_PATTERN.test(input)\n\nexport const isInternational = (input: string): boolean => input.trimStart().startsWith('+')\n\nexport const digitCount = (input: string): number => (input.match(/\\d/g) ?? []).length\n\n/** A national draft spends the calling code's digits before its own. */\nexport type PhoneLengthOptions = PhoneOptions & { callingCode?: string }\n\n/**\n * Whether a draft is already longer than any number it could still become. The country's own\n * ceiling decides wherever the metadata defines one, and E.164's 15 digits backstop the rest:\n * several countries, Germany among them, carry no upper bound of their own.\n */\nexport const exceedsPhoneLength = (input: string, opts: PhoneLengthOptions): boolean => {\n\tconst digits = digitCount(input)\n\tif (digits === 0) return false\n\tconst carried = isInternational(input) ? 0 : digitCount(opts.callingCode ?? '')\n\tif (digits + carried > E164_MAX_DIGITS) return true\n\tconst length = validatePhoneNumberLength(\n\t\tinput,\n\t\t{ defaultCountry: opts.defaultCountry },\n\t\topts.metadata as never\n\t)\n\t// Only TOO_LONG: INVALID_LENGTH lands on any country whose possible lengths have a gap,\n\t// which a half-typed number passes through on its way to a longer valid one.\n\treturn length === 'TOO_LONG'\n}\n/** The number without its calling code, so it reads as one phrase beside the prefix. */\nexport const nationalPart = (parsed: ParsedPhone): string => {\n\tconst prefix = `+${parsed.callingCode}`\n\treturn parsed.international.startsWith(prefix)\n\t\t? parsed.international.slice(prefix.length).trimStart()\n\t\t: parsed.national\n}\n\n/** What the admin row shows for a stored number, split the way the row lays it out. */\nexport type PhoneSeed = {\n\tcallingCode: string\n\tcountry: CountryCode | undefined\n\tnational: string\n\tnumber: string\n}\n\n/**\n * Derived wherever metadata is already free (the server), so the first client frame can\n * match the frame the engine paints once the lazy metadata import resolves.\n */\nexport const phoneSeed = (raw: string, opts: PhoneOptions): null | PhoneSeed => {\n\tconst parsed = parsePhone(raw, opts)\n\tif (!parsed) return null\n\treturn {\n\t\tcallingCode: parsed.callingCode,\n\t\tcountry: parsed.country,\n\t\tnational: nationalPart(parsed),\n\t\tnumber: raw,\n\t}\n}\nconst readTyping = (\n\tinput: string,\n\tmetadata: PhoneMetadata\n): { callingCode: string | undefined; country: CountryCode | undefined } => {\n\tconst typing = new AsYouType(undefined, metadata as never)\n\ttyping.input(input)\n\treturn { callingCode: typing.getCallingCode(), country: typing.getCountry() }\n}\n\n/** The calling code the typed digits already identify, undefined while none fits them. */\nexport const callingCodeOf = (input: string, opts: PhoneOptions): string | undefined =>\n\treadTyping(input, opts.metadata).callingCode\n\n/**\n * The country a partial international draft already implies. Which calling code this is settles\n * on sight; which country within a shared one takes more digits, so the code's main country\n * stands in until the leading digits distinguish a specific one. Undefined for anything that\n * carries no calling code at all, so junk still names no country.\n */\nexport const provisionalCountry = (input: string, opts: PhoneOptions): CountryCode | undefined => {\n\tconst { callingCode, country } = readTyping(input, opts.metadata)\n\tif (country !== undefined) return country\n\treturn callingCode === undefined\n\t\t? undefined\n\t\t: mainCountryForCallingCode(callingCode, opts.metadata)\n}\n"],"mappings":";;;;;;;;;;AAWA,MAAM,kBAAkB;;AAGxB,MAAM,sBAAsB;;AAG5B,MAAa,gBAAgB,UAA2B,oBAAoB,KAAK,KAAK;AAEtF,MAAa,mBAAmB,UAA2B,MAAM,UAAU,EAAE,WAAW,GAAG;AAE3F,MAAa,cAAc,WAA2B,MAAM,MAAM,KAAK,KAAK,CAAC,GAAG;;;;;;AAUhF,MAAa,sBAAsB,OAAe,SAAsC;CACvF,MAAM,SAAS,WAAW,KAAK;CAC/B,IAAI,WAAW,GAAG,OAAO;CAEzB,IAAI,UADY,gBAAgB,KAAK,IAAI,IAAI,WAAW,KAAK,eAAe,EAAE,KACvD,iBAAiB,OAAO;CAQ/C,OAPe,0BACd,OACA,EAAE,gBAAgB,KAAK,eAAe,GACtC,KAAK,QAIM,MAAM;AACnB;;AAEA,MAAa,gBAAgB,WAAgC;CAC5D,MAAM,SAAS,IAAI,OAAO;CAC1B,OAAO,OAAO,cAAc,WAAW,MAAM,IAC1C,OAAO,cAAc,MAAM,OAAO,MAAM,EAAE,UAAU,IACpD,OAAO;AACX;;;;;AAcA,MAAa,aAAa,KAAa,SAAyC;CAC/E,MAAM,SAAS,WAAW,KAAK,IAAI;CACnC,IAAI,CAAC,QAAQ,OAAO;CACpB,OAAO;EACN,aAAa,OAAO;EACpB,SAAS,OAAO;EAChB,UAAU,aAAa,MAAM;EAC7B,QAAQ;CACT;AACD;AACA,MAAM,cACL,OACA,aAC2E;CAC3E,MAAM,SAAS,IAAI,UAAU,KAAA,GAAW,QAAiB;CACzD,OAAO,MAAM,KAAK;CAClB,OAAO;EAAE,aAAa,OAAO,eAAe;EAAG,SAAS,OAAO,WAAW;CAAE;AAC7E;;AAGA,MAAa,iBAAiB,OAAe,SAC5C,WAAW,OAAO,KAAK,QAAQ,EAAE;;;;;;;AAQlC,MAAa,sBAAsB,OAAe,SAAgD;CACjG,MAAM,EAAE,aAAa,YAAY,WAAW,OAAO,KAAK,QAAQ;CAChE,IAAI,YAAY,KAAA,GAAW,OAAO;CAClC,OAAO,gBAAgB,KAAA,IACpB,KAAA,IACA,0BAA0B,aAAa,KAAK,QAAQ;AACxD"}
@@ -0,0 +1,11 @@
1
+ //#region src/fields/phoneNumber/engine/metadata.d.ts
2
+ type MetadataSet = 'max' | 'min' | 'mobile';
3
+ /** Opaque libphonenumber metadata; only the library itself reads its shape. */
4
+ type PhoneMetadata = Readonly<Record<string, unknown>>;
5
+ /** The only set carrying per-type patterns, so the only one supporting getType(). */
6
+ declare const DEFAULT_METADATA_SET: MetadataSet;
7
+ /** A rejection is evicted so a later call retries instead of inheriting the failure. */
8
+ declare const loadMetadata: (set: MetadataSet) => Promise<PhoneMetadata>;
9
+ //#endregion
10
+ export { DEFAULT_METADATA_SET, MetadataSet, PhoneMetadata, loadMetadata };
11
+ //# sourceMappingURL=metadata.d.ts.map
@@ -0,0 +1,32 @@
1
+ //#region src/fields/phoneNumber/engine/metadata.ts
2
+ /** The only set carrying per-type patterns, so the only one supporting getType(). */
3
+ const DEFAULT_METADATA_SET = "max";
4
+ /**
5
+ * Static map of dynamic imports rather than a computed specifier, so bundlers can
6
+ * split all three sets and ship only the one an install selects.
7
+ */
8
+ const loaders = {
9
+ max: () => import("libphonenumber-js/metadata.max.json"),
10
+ min: () => import("libphonenumber-js/metadata.min.json"),
11
+ mobile: () => import("libphonenumber-js/metadata.mobile.json")
12
+ };
13
+ /** Whether a string is one of the sets `loadMetadata` can actually load. */
14
+ const isMetadataSet = (value) => value in loaders;
15
+ const cache = /* @__PURE__ */ new Map();
16
+ /** A rejection is evicted so a later call retries instead of inheriting the failure. */
17
+ const loadMetadata = (set) => {
18
+ const cached = cache.get(set);
19
+ if (cached) return cached;
20
+ const loader = loaders[set];
21
+ if (!loader) return Promise.reject(/* @__PURE__ */ new Error(`unknown phone metadata set "${String(set)}"`));
22
+ const loading = loader().then((module) => module.default).catch((err) => {
23
+ cache.delete(set);
24
+ throw err;
25
+ });
26
+ cache.set(set, loading);
27
+ return loading;
28
+ };
29
+ //#endregion
30
+ export { DEFAULT_METADATA_SET, isMetadataSet, loadMetadata };
31
+
32
+ //# sourceMappingURL=metadata.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"metadata.js","names":[],"sources":["../../../../src/fields/phoneNumber/engine/metadata.ts"],"sourcesContent":["export type MetadataSet = 'max' | 'min' | 'mobile'\n\n/** Opaque libphonenumber metadata; only the library itself reads its shape. */\nexport type PhoneMetadata = Readonly<Record<string, unknown>>\n\n/** The only set carrying per-type patterns, so the only one supporting getType(). */\nexport const DEFAULT_METADATA_SET: MetadataSet = 'max'\n\n/**\n * Static map of dynamic imports rather than a computed specifier, so bundlers can\n * split all three sets and ship only the one an install selects.\n */\nconst loaders: Record<MetadataSet, () => Promise<{ default: PhoneMetadata }>> = {\n\tmax: () => import('libphonenumber-js/metadata.max.json'),\n\tmin: () => import('libphonenumber-js/metadata.min.json'),\n\tmobile: () => import('libphonenumber-js/metadata.mobile.json'),\n}\n\n/** Whether a string is one of the sets `loadMetadata` can actually load. */\nexport const isMetadataSet = (value: string): value is MetadataSet => value in loaders\n\nconst cache = new Map<MetadataSet, Promise<PhoneMetadata>>()\n\n/** A rejection is evicted so a later call retries instead of inheriting the failure. */\nexport const loadMetadata = (set: MetadataSet): Promise<PhoneMetadata> => {\n\tconst cached = cache.get(set)\n\tif (cached) return cached\n\tconst loader = loaders[set]\n\t// An out-of-union set arrives from unvalidated config; rejecting rather than throwing keeps\n\t// every caller's degrade path in charge instead of taking the render down with it.\n\tif (!loader) return Promise.reject(new Error(`unknown phone metadata set \"${String(set)}\"`))\n\tconst loading = loader()\n\t\t.then((module) => module.default)\n\t\t.catch((err: unknown) => {\n\t\t\tcache.delete(set)\n\t\t\tthrow err\n\t\t})\n\tcache.set(set, loading)\n\treturn loading\n}\n"],"mappings":";;AAMA,MAAa,uBAAoC;;;;;AAMjD,MAAM,UAA0E;CAC/E,WAAW,OAAO;CAClB,WAAW,OAAO;CAClB,cAAc,OAAO;AACtB;;AAGA,MAAa,iBAAiB,UAAwC,SAAS;AAE/E,MAAM,wBAAQ,IAAI,IAAyC;;AAG3D,MAAa,gBAAgB,QAA6C;CACzE,MAAM,SAAS,MAAM,IAAI,GAAG;CAC5B,IAAI,QAAQ,OAAO;CACnB,MAAM,SAAS,QAAQ;CAGvB,IAAI,CAAC,QAAQ,OAAO,QAAQ,uBAAO,IAAI,MAAM,+BAA+B,OAAO,GAAG,EAAE,EAAE,CAAC;CAC3F,MAAM,UAAU,OAAO,EACrB,MAAM,WAAW,OAAO,OAAO,EAC/B,OAAO,QAAiB;EACxB,MAAM,OAAO,GAAG;EAChB,MAAM;CACP,CAAC;CACF,MAAM,IAAI,KAAK,OAAO;CACtB,OAAO;AACR"}
@@ -0,0 +1,37 @@
1
+ import { PhoneMetadata } from "./metadata.js";
2
+ import { CountryCode } from "libphonenumber-js/core";
3
+
4
+ //#region src/fields/phoneNumber/engine/phone.d.ts
5
+ type PhoneFormat = 'e164' | 'international' | 'national';
6
+ type PhoneValidationMode = 'mobile' | 'possible' | 'valid';
7
+ type PhoneCheck = 'empty' | 'invalid' | 'notMobile' | 'ok';
8
+ type ParsedPhone = {
9
+ callingCode: string;
10
+ country: CountryCode | undefined;
11
+ e164: string;
12
+ ext: string | undefined;
13
+ international: string;
14
+ national: string;
15
+ possible: boolean;
16
+ type: string | undefined;
17
+ uri: string;
18
+ valid: boolean;
19
+ };
20
+ type PhoneOptions = {
21
+ defaultCountry?: CountryCode;
22
+ metadata: PhoneMetadata;
23
+ };
24
+ declare const parsePhone: (input: string, opts: PhoneOptions) => null | ParsedPhone;
25
+ declare const formatPhone: (input: string, format: PhoneFormat, opts: PhoneOptions) => string;
26
+ declare const phoneUri: (input: string, opts: PhoneOptions) => null | string;
27
+ /**
28
+ * The longest leading candidate that parses to a valid, country-bearing number, protecting
29
+ * a doubled paste or a punctuation-wrapped one from fabricating a number by stripping characters.
30
+ */
31
+ declare const salvagePhone: (input: string, opts: PhoneOptions) => null | ParsedPhone;
32
+ declare const detectCountry: (input: string, opts: PhoneOptions) => CountryCode | undefined;
33
+ declare const checkPhone: (input: string, mode: PhoneValidationMode, opts: PhoneOptions) => PhoneCheck;
34
+ declare const formatAsYouType: (input: string, country: CountryCode | undefined, opts: PhoneOptions) => string;
35
+ //#endregion
36
+ export { type CountryCode, ParsedPhone, PhoneCheck, PhoneFormat, PhoneOptions, PhoneValidationMode, checkPhone, detectCountry, formatAsYouType, formatPhone, parsePhone, phoneUri, salvagePhone };
37
+ //# sourceMappingURL=phone.d.ts.map
@@ -0,0 +1,59 @@
1
+ import { AsYouType, parsePhoneNumberFromString } from "libphonenumber-js/core";
2
+ //#region src/fields/phoneNumber/engine/phone.ts
3
+ const MOBILE_TYPES = new Set(["MOBILE", "FIXED_LINE_OR_MOBILE"]);
4
+ const parsePhone = (input, opts) => {
5
+ if (input === "") return null;
6
+ const parsed = parsePhoneNumberFromString(input, { defaultCountry: opts.defaultCountry }, opts.metadata);
7
+ if (!parsed) return null;
8
+ return {
9
+ callingCode: parsed.countryCallingCode,
10
+ country: parsed.country,
11
+ e164: parsed.number,
12
+ ext: parsed.ext,
13
+ international: parsed.formatInternational(),
14
+ national: parsed.formatNational(),
15
+ possible: parsed.isPossible(),
16
+ type: parsed.getType(),
17
+ uri: parsed.getURI(),
18
+ valid: parsed.isValid()
19
+ };
20
+ };
21
+ const formatPhone = (input, format, opts) => {
22
+ const parsed = parsePhone(input, opts);
23
+ if (!parsed) return input;
24
+ if (format === "e164") return parsed.e164;
25
+ return format === "national" ? parsed.national : parsed.international;
26
+ };
27
+ const phoneUri = (input, opts) => parsePhone(input, opts)?.uri ?? null;
28
+ /**
29
+ * The longest leading candidate that parses to a valid, country-bearing number, protecting
30
+ * a doubled paste or a punctuation-wrapped one from fabricating a number by stripping characters.
31
+ */
32
+ const salvagePhone = (input, opts) => {
33
+ const trimmed = input.trim();
34
+ const direct = parsePhone(trimmed, opts);
35
+ if (direct?.valid && direct.country) return direct;
36
+ const plus = trimmed.indexOf("+");
37
+ if (plus === -1) return null;
38
+ const tail = trimmed.slice(plus);
39
+ for (let end = Math.min(tail.length, 18); end > 2; end--) {
40
+ const candidate = parsePhone(tail.slice(0, end), opts);
41
+ if (candidate?.valid && candidate.country) return candidate;
42
+ }
43
+ return null;
44
+ };
45
+ const detectCountry = (input, opts) => salvagePhone(input, opts)?.country;
46
+ const checkPhone = (input, mode, opts) => {
47
+ if (input.trim() === "") return "empty";
48
+ const parsed = parsePhone(input, opts);
49
+ if (!parsed) return "invalid";
50
+ if (mode === "possible") return parsed.possible ? "ok" : "invalid";
51
+ if (!parsed.valid) return "invalid";
52
+ if (mode === "mobile") return parsed.type !== void 0 && MOBILE_TYPES.has(parsed.type) ? "ok" : "notMobile";
53
+ return "ok";
54
+ };
55
+ const formatAsYouType = (input, country, opts) => new AsYouType(country, opts.metadata).input(input);
56
+ //#endregion
57
+ export { checkPhone, detectCountry, formatAsYouType, formatPhone, parsePhone, phoneUri, salvagePhone };
58
+
59
+ //# sourceMappingURL=phone.js.map