@10x-media/fields 0.1.0-beta.6 → 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 (151) hide show
  1. package/CHANGELOG.md +41 -0
  2. package/LICENSE +21 -21
  3. package/README.md +3 -1
  4. package/dist/exports/client.d.ts +7 -1
  5. package/dist/exports/client.js +7 -1
  6. package/dist/exports/measurement-utils.d.ts +9 -0
  7. package/dist/exports/measurement-utils.js +8 -0
  8. package/dist/exports/measurement.d.ts +11 -0
  9. package/dist/exports/measurement.js +10 -0
  10. package/dist/exports/phone-utils.d.ts +4 -0
  11. package/dist/exports/phone-utils.js +4 -0
  12. package/dist/exports/phone.d.ts +6 -0
  13. package/dist/exports/phone.js +3 -0
  14. package/dist/exports/rsc.d.ts +5 -1
  15. package/dist/exports/rsc.js +5 -1
  16. package/dist/exports/types.d.ts +3 -2
  17. package/dist/fields/icon/client/icon-field.css +4 -2
  18. package/dist/fields/icon/rsc/IconFieldServer.js +1 -1
  19. package/dist/fields/icon/rsc/IconFieldServer.js.map +1 -1
  20. package/dist/fields/icon/rsc/IconLibrarySelectServer.js +1 -1
  21. package/dist/fields/icon/rsc/IconLibrarySelectServer.js.map +1 -1
  22. package/dist/fields/icon/shared/iconLabel.js +1 -1
  23. package/dist/fields/icon/shared/iconLabel.js.map +1 -1
  24. package/dist/fields/measurement/client/MeasurementCell.d.ts +18 -0
  25. package/dist/fields/measurement/client/MeasurementCell.js +47 -0
  26. package/dist/fields/measurement/client/MeasurementCell.js.map +1 -0
  27. package/dist/fields/measurement/client/MeasurementField.d.ts +11 -0
  28. package/dist/fields/measurement/client/MeasurementField.js +386 -0
  29. package/dist/fields/measurement/client/MeasurementField.js.map +1 -0
  30. package/dist/fields/measurement/client/MeasurementUnitsProvider.d.ts +24 -0
  31. package/dist/fields/measurement/client/MeasurementUnitsProvider.js +61 -0
  32. package/dist/fields/measurement/client/MeasurementUnitsProvider.js.map +1 -0
  33. package/dist/fields/measurement/client/editModel.js +115 -0
  34. package/dist/fields/measurement/client/editModel.js.map +1 -0
  35. package/dist/fields/measurement/client/measurementCell.css +4 -0
  36. package/dist/fields/measurement/client/measurementField.css +215 -0
  37. package/dist/fields/measurement/engine/convert.d.ts +8 -0
  38. package/dist/fields/measurement/engine/convert.js +21 -0
  39. package/dist/fields/measurement/engine/convert.js.map +1 -0
  40. package/dist/fields/measurement/engine/format.d.ts +37 -0
  41. package/dist/fields/measurement/engine/format.js +156 -0
  42. package/dist/fields/measurement/engine/format.js.map +1 -0
  43. package/dist/fields/measurement/engine/locale.d.ts +25 -0
  44. package/dist/fields/measurement/engine/locale.js +79 -0
  45. package/dist/fields/measurement/engine/locale.js.map +1 -0
  46. package/dist/fields/measurement/engine/precision.d.ts +34 -0
  47. package/dist/fields/measurement/engine/precision.js +63 -0
  48. package/dist/fields/measurement/engine/precision.js.map +1 -0
  49. package/dist/fields/measurement/engine/registry.d.ts +55 -0
  50. package/dist/fields/measurement/engine/registry.js +117 -0
  51. package/dist/fields/measurement/engine/registry.js.map +1 -0
  52. package/dist/fields/measurement/engine/units.d.ts +178 -0
  53. package/dist/fields/measurement/engine/units.js +198 -0
  54. package/dist/fields/measurement/engine/units.js.map +1 -0
  55. package/dist/fields/measurement/measurementField.d.ts +17 -0
  56. package/dist/fields/measurement/measurementField.js +139 -0
  57. package/dist/fields/measurement/measurementField.js.map +1 -0
  58. package/dist/fields/measurement/options.d.ts +76 -0
  59. package/dist/fields/measurement/options.js +9 -0
  60. package/dist/fields/measurement/options.js.map +1 -0
  61. package/dist/fields/measurement/presets.d.ts +117 -0
  62. package/dist/fields/measurement/presets.js +136 -0
  63. package/dist/fields/measurement/presets.js.map +1 -0
  64. package/dist/fields/measurement/server/MeasurementCellServer.d.ts +21 -0
  65. package/dist/fields/measurement/server/MeasurementCellServer.js +53 -0
  66. package/dist/fields/measurement/server/MeasurementCellServer.js.map +1 -0
  67. package/dist/fields/measurement/server/MeasurementFieldServer.d.ts +16 -0
  68. package/dist/fields/measurement/server/MeasurementFieldServer.js +45 -0
  69. package/dist/fields/measurement/server/MeasurementFieldServer.js.map +1 -0
  70. package/dist/fields/measurement/server/getUserUnits.js +39 -0
  71. package/dist/fields/measurement/server/getUserUnits.js.map +1 -0
  72. package/dist/fields/measurement/server/resolvePrecisionSafe.js +24 -0
  73. package/dist/fields/measurement/server/resolvePrecisionSafe.js.map +1 -0
  74. package/dist/fields/measurement/server/resolveRegistryDefault.js +26 -0
  75. package/dist/fields/measurement/server/resolveRegistryDefault.js.map +1 -0
  76. package/dist/fields/phoneNumber/client/CountryFlag.d.ts +16 -0
  77. package/dist/fields/phoneNumber/client/CountryFlag.js +40 -0
  78. package/dist/fields/phoneNumber/client/CountryFlag.js.map +1 -0
  79. package/dist/fields/phoneNumber/client/CountryPicker.d.ts +21 -0
  80. package/dist/fields/phoneNumber/client/CountryPicker.js +255 -0
  81. package/dist/fields/phoneNumber/client/CountryPicker.js.map +1 -0
  82. package/dist/fields/phoneNumber/client/PhoneNumberField.d.ts +26 -0
  83. package/dist/fields/phoneNumber/client/PhoneNumberField.js +318 -0
  84. package/dist/fields/phoneNumber/client/PhoneNumberField.js.map +1 -0
  85. package/dist/fields/phoneNumber/client/editModel.js +86 -0
  86. package/dist/fields/phoneNumber/client/editModel.js.map +1 -0
  87. package/dist/fields/phoneNumber/client/phoneNumberField.css +305 -0
  88. package/dist/fields/phoneNumber/engine/countries.d.ts +36 -0
  89. package/dist/fields/phoneNumber/engine/countries.js +68 -0
  90. package/dist/fields/phoneNumber/engine/countries.js.map +1 -0
  91. package/dist/fields/phoneNumber/engine/draft.d.ts +13 -0
  92. package/dist/fields/phoneNumber/engine/draft.js +72 -0
  93. package/dist/fields/phoneNumber/engine/draft.js.map +1 -0
  94. package/dist/fields/phoneNumber/engine/metadata.d.ts +11 -0
  95. package/dist/fields/phoneNumber/engine/metadata.js +32 -0
  96. package/dist/fields/phoneNumber/engine/metadata.js.map +1 -0
  97. package/dist/fields/phoneNumber/engine/phone.d.ts +37 -0
  98. package/dist/fields/phoneNumber/engine/phone.js +59 -0
  99. package/dist/fields/phoneNumber/engine/phone.js.map +1 -0
  100. package/dist/fields/phoneNumber/options.d.ts +72 -0
  101. package/dist/fields/phoneNumber/options.js +37 -0
  102. package/dist/fields/phoneNumber/options.js.map +1 -0
  103. package/dist/fields/phoneNumber/phoneNumberField.d.ts +14 -0
  104. package/dist/fields/phoneNumber/phoneNumberField.js +167 -0
  105. package/dist/fields/phoneNumber/phoneNumberField.js.map +1 -0
  106. package/dist/fields/phoneNumber/server/PhoneNumberCellServer.d.ts +19 -0
  107. package/dist/fields/phoneNumber/server/PhoneNumberCellServer.js +73 -0
  108. package/dist/fields/phoneNumber/server/PhoneNumberCellServer.js.map +1 -0
  109. package/dist/fields/phoneNumber/server/PhoneNumberFieldServer.d.ts +16 -0
  110. package/dist/fields/phoneNumber/server/PhoneNumberFieldServer.js +57 -0
  111. package/dist/fields/phoneNumber/server/PhoneNumberFieldServer.js.map +1 -0
  112. package/dist/fields/phoneNumber/server/flagsEndpoint.js +51 -0
  113. package/dist/fields/phoneNumber/server/flagsEndpoint.js.map +1 -0
  114. package/dist/fields/phoneNumber/server/readPhoneOptions.js +18 -0
  115. package/dist/fields/phoneNumber/server/readPhoneOptions.js.map +1 -0
  116. package/dist/fields/phoneNumber/server/resolvePhoneOptionsSafe.js +33 -0
  117. package/dist/fields/phoneNumber/server/resolvePhoneOptionsSafe.js.map +1 -0
  118. package/dist/index.d.ts +5 -3
  119. package/dist/index.js +33 -0
  120. package/dist/index.js.map +1 -1
  121. package/dist/translations/ar.js +12 -1
  122. package/dist/translations/ar.js.map +1 -1
  123. package/dist/translations/de.js +12 -1
  124. package/dist/translations/de.js.map +1 -1
  125. package/dist/translations/en.js +12 -1
  126. package/dist/translations/en.js.map +1 -1
  127. package/dist/translations/es.js +12 -1
  128. package/dist/translations/es.js.map +1 -1
  129. package/dist/translations/fr.js +12 -1
  130. package/dist/translations/fr.js.map +1 -1
  131. package/dist/translations/id.js +12 -1
  132. package/dist/translations/id.js.map +1 -1
  133. package/dist/translations/keys.d.ts +11 -0
  134. package/dist/translations/keys.js +12 -1
  135. package/dist/translations/keys.js.map +1 -1
  136. package/dist/translations/ko.js +12 -1
  137. package/dist/translations/ko.js.map +1 -1
  138. package/dist/translations/pt.js +12 -1
  139. package/dist/translations/pt.js.map +1 -1
  140. package/dist/translations/ru.js +12 -1
  141. package/dist/translations/ru.js.map +1 -1
  142. package/dist/translations/uk.js +12 -1
  143. package/dist/translations/uk.js.map +1 -1
  144. package/dist/translations/zh.js +12 -1
  145. package/dist/translations/zh.js.map +1 -1
  146. package/dist/types.d.ts +41 -1
  147. package/dist/utils/resolveStaticLabel.js +13 -0
  148. package/dist/utils/resolveStaticLabel.js.map +1 -0
  149. package/package.json +27 -5
  150. package/dist/fields/icon/shared/resolveStaticLabel.js +0 -16
  151. package/dist/fields/icon/shared/resolveStaticLabel.js.map +0 -1
@@ -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
@@ -0,0 +1 @@
1
+ {"version":3,"file":"phone.js","names":[],"sources":["../../../../src/fields/phoneNumber/engine/phone.ts"],"sourcesContent":["import { AsYouType, type CountryCode, parsePhoneNumberFromString } from 'libphonenumber-js/core'\nimport type { PhoneMetadata } from './metadata'\n\nexport type { CountryCode }\nexport type PhoneFormat = 'e164' | 'international' | 'national'\nexport type PhoneValidationMode = 'mobile' | 'possible' | 'valid'\nexport type PhoneCheck = 'empty' | 'invalid' | 'notMobile' | 'ok'\n\nexport type ParsedPhone = {\n\tcallingCode: string\n\tcountry: CountryCode | undefined\n\te164: string\n\text: string | undefined\n\tinternational: string\n\tnational: string\n\tpossible: boolean\n\ttype: string | undefined\n\turi: string\n\tvalid: boolean\n}\n\nexport type PhoneOptions = { defaultCountry?: CountryCode; metadata: PhoneMetadata }\n\nconst MOBILE_TYPES = new Set(['MOBILE', 'FIXED_LINE_OR_MOBILE'])\n\nexport const parsePhone = (input: string, opts: PhoneOptions): null | ParsedPhone => {\n\tif (input === '') return null\n\tconst parsed = parsePhoneNumberFromString(\n\t\tinput,\n\t\t{ defaultCountry: opts.defaultCountry },\n\t\topts.metadata as never\n\t)\n\tif (!parsed) return null\n\treturn {\n\t\tcallingCode: parsed.countryCallingCode,\n\t\tcountry: parsed.country,\n\t\te164: parsed.number,\n\t\text: parsed.ext,\n\t\tinternational: parsed.formatInternational(),\n\t\tnational: parsed.formatNational(),\n\t\tpossible: parsed.isPossible(),\n\t\ttype: parsed.getType(),\n\t\turi: parsed.getURI(),\n\t\tvalid: parsed.isValid(),\n\t}\n}\n\nexport const formatPhone = (input: string, format: PhoneFormat, opts: PhoneOptions): string => {\n\tconst parsed = parsePhone(input, opts)\n\tif (!parsed) return input\n\tif (format === 'e164') return parsed.e164\n\treturn format === 'national' ? parsed.national : parsed.international\n}\n\nexport const phoneUri = (input: string, opts: PhoneOptions): null | string =>\n\tparsePhone(input, opts)?.uri ?? null\n\n/**\n * The longest leading candidate that parses to a valid, country-bearing number, protecting\n * a doubled paste or a punctuation-wrapped one from fabricating a number by stripping characters.\n */\nexport const salvagePhone = (input: string, opts: PhoneOptions): null | ParsedPhone => {\n\tconst trimmed = input.trim()\n\tconst direct = parsePhone(trimmed, opts)\n\tif (direct?.valid && direct.country) return direct\n\tconst plus = trimmed.indexOf('+')\n\tif (plus === -1) return null\n\tconst tail = trimmed.slice(plus)\n\t// E.164 numbers max out at 15 digits; 18 bounds the scan without truncating a real one.\n\tfor (let end = Math.min(tail.length, 18); end > 2; end--) {\n\t\tconst candidate = parsePhone(tail.slice(0, end), opts)\n\t\tif (candidate?.valid && candidate.country) return candidate\n\t}\n\treturn null\n}\n\nexport const detectCountry = (input: string, opts: PhoneOptions): CountryCode | undefined =>\n\tsalvagePhone(input, opts)?.country\n\nexport const checkPhone = (\n\tinput: string,\n\tmode: PhoneValidationMode,\n\topts: PhoneOptions\n): PhoneCheck => {\n\tif (input.trim() === '') return 'empty'\n\tconst parsed = parsePhone(input, opts)\n\tif (!parsed) return 'invalid'\n\tif (mode === 'possible') return parsed.possible ? 'ok' : 'invalid'\n\tif (!parsed.valid) return 'invalid'\n\tif (mode === 'mobile') {\n\t\treturn parsed.type !== undefined && MOBILE_TYPES.has(parsed.type) ? 'ok' : 'notMobile'\n\t}\n\treturn 'ok'\n}\n\nexport const formatAsYouType = (\n\tinput: string,\n\tcountry: CountryCode | undefined,\n\topts: PhoneOptions\n): string => new AsYouType(country, opts.metadata as never).input(input)\n"],"mappings":";;AAuBA,MAAM,eAAe,IAAI,IAAI,CAAC,UAAU,sBAAsB,CAAC;AAE/D,MAAa,cAAc,OAAe,SAA2C;CACpF,IAAI,UAAU,IAAI,OAAO;CACzB,MAAM,SAAS,2BACd,OACA,EAAE,gBAAgB,KAAK,eAAe,GACtC,KAAK,QACN;CACA,IAAI,CAAC,QAAQ,OAAO;CACpB,OAAO;EACN,aAAa,OAAO;EACpB,SAAS,OAAO;EAChB,MAAM,OAAO;EACb,KAAK,OAAO;EACZ,eAAe,OAAO,oBAAoB;EAC1C,UAAU,OAAO,eAAe;EAChC,UAAU,OAAO,WAAW;EAC5B,MAAM,OAAO,QAAQ;EACrB,KAAK,OAAO,OAAO;EACnB,OAAO,OAAO,QAAQ;CACvB;AACD;AAEA,MAAa,eAA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
+ import { CountryCode, PhoneFormat, PhoneValidationMode } from "./engine/phone.js";
3
+ import { GroupField, StaticLabel, TextField } from "payload";
4
+
5
+ //#region src/fields/phoneNumber/options.d.ts
6
+ /** field.custom key the factory stamps its resolved config under, for tooling and secondary apps. */
7
+ declare const PHONE_CUSTOM_KEY = "@10x-media/fields";
8
+ /** Mounted by the plugin; the client builds flag URLs from serverURL + api route + this. */
9
+ declare const FLAGS_PATH = "/10x-fields/flags";
10
+ /**
11
+ * The flag route's URL for one ISO 3166-1 alpha-2 code, built from the app's own API
12
+ * route rather than assumed, so an install that moved `routes.api` still resolves its
13
+ * flags. The `.svg` suffix is there for a reader who opens the URL directly.
14
+ *
15
+ * Lives here, not beside the handler, so the admin client can build a URL without
16
+ * importing the server module and its deferred flag artwork.
17
+ */
18
+ declare const countryFlagSrc: (serverURL: string, apiRoute: string, code: string) => string;
19
+ type PhoneFlagMode = 'emoji' | 'none' | 'svg';
20
+ type PhoneStorageMode = 'e164' | 'object';
21
+ type CommonPhoneOptions = {
22
+ name: string;
23
+ label?: StaticLabel;
24
+ required?: boolean;
25
+ localized?: boolean;
26
+ index?: boolean;
27
+ defaultCountry?: CountryCode;
28
+ countries?: readonly CountryCode[];
29
+ priorityCountries?: readonly CountryCode[]; /** Heading over `priorityCountries` in the picker. No label renders no heading, only the group separator. */
30
+ priorityCountriesLabel?: StaticLabel;
31
+ validation?: PhoneValidationMode;
32
+ flags?: PhoneFlagMode;
33
+ cellFormat?: PhoneFormat;
34
+ /**
35
+ * Default true. False means the value cannot be removed, not merely that the clear
36
+ * affordance is hidden: emptying the input and committing reverts to the last valid value.
37
+ */
38
+ isClearable?: boolean;
39
+ };
40
+ type PhoneNumberFieldOptions = CommonPhoneOptions & {
41
+ storage?: 'object';
42
+ overrides?: (args: {
43
+ field: GroupField;
44
+ }) => GroupField;
45
+ };
46
+ type PhoneNumberE164FieldOptions = CommonPhoneOptions & {
47
+ storage: 'e164';
48
+ overrides?: (args: {
49
+ field: TextField;
50
+ }) => TextField;
51
+ };
52
+ type AnyPhoneNumberFieldOptions = PhoneNumberE164FieldOptions | PhoneNumberFieldOptions;
53
+ /** Every phone option with its layers merged and its defaults applied. Server-side. */
54
+ type ResolvedPhoneOptions = {
55
+ cellFormat: PhoneFormat;
56
+ countries?: readonly CountryCode[];
57
+ defaultCountry?: CountryCode;
58
+ flags: PhoneFlagMode; /** See {@link CommonPhoneOptions.isClearable}. */
59
+ isClearable: boolean;
60
+ metadata: MetadataSet;
61
+ priorityCountries?: readonly CountryCode[];
62
+ priorityCountriesLabel?: StaticLabel;
63
+ storage: PhoneStorageMode;
64
+ validation: PhoneValidationMode;
65
+ };
66
+ /** The field's own, unresolved layer: exactly what the author wrote, no defaults applied. */
67
+ type ResolvablePhoneFieldOptions = Pick<CommonPhoneOptions, 'cellFormat' | 'countries' | 'defaultCountry' | 'flags' | 'isClearable' | 'priorityCountries' | 'priorityCountriesLabel' | 'validation'> & {
68
+ storage?: PhoneStorageMode;
69
+ };
70
+ //#endregion
71
+ export { AnyPhoneNumberFieldOptions, FLAGS_PATH, PHONE_CUSTOM_KEY, PhoneFlagMode, PhoneNumberE164FieldOptions, PhoneNumberFieldOptions, PhoneStorageMode, ResolvablePhoneFieldOptions, ResolvedPhoneOptions, countryFlagSrc };
72
+ //# sourceMappingURL=options.d.ts.map
@@ -0,0 +1,37 @@
1
+ import "./engine/metadata.js";
2
+ //#region src/fields/phoneNumber/options.ts
3
+ /** field.custom key the factory stamps its resolved config under, for tooling and secondary apps. */
4
+ const PHONE_CUSTOM_KEY = "@10x-media/fields";
5
+ /** Mounted by the plugin; the client builds flag URLs from serverURL + api route + this. */
6
+ const FLAGS_PATH = "/10x-fields/flags";
7
+ /**
8
+ * The flag route's URL for one ISO 3166-1 alpha-2 code, built from the app's own API
9
+ * route rather than assumed, so an install that moved `routes.api` still resolves its
10
+ * flags. The `.svg` suffix is there for a reader who opens the URL directly.
11
+ *
12
+ * Lives here, not beside the handler, so the admin client can build a URL without
13
+ * importing the server module and its deferred flag artwork.
14
+ */
15
+ const countryFlagSrc = (serverURL, apiRoute, code) => `${serverURL}${apiRoute}${FLAGS_PATH}/${encodeURIComponent(code.toLowerCase())}.svg`;
16
+ /**
17
+ * Field beats global beats these defaults, via `??` so an explicit `undefined`
18
+ * on a field falls through rather than resetting it. `metadata` is global-only;
19
+ * `storage` is field-only, since the factory's return type is fixed at build time
20
+ * and a plugin-wide storage choice could never be honoured.
21
+ */
22
+ const resolvePhoneOptions = (field, global) => ({
23
+ cellFormat: field.cellFormat ?? global?.cellFormat ?? "international",
24
+ countries: field.countries ?? global?.countries,
25
+ defaultCountry: field.defaultCountry ?? global?.defaultCountry,
26
+ flags: field.flags ?? global?.flags ?? "svg",
27
+ isClearable: field.isClearable ?? true,
28
+ metadata: global?.metadata ?? "max",
29
+ priorityCountries: field.priorityCountries ?? global?.priorityCountries,
30
+ priorityCountriesLabel: field.priorityCountriesLabel ?? global?.priorityCountriesLabel,
31
+ storage: field.storage ?? "object",
32
+ validation: field.validation ?? global?.validation ?? "valid"
33
+ });
34
+ //#endregion
35
+ export { FLAGS_PATH, PHONE_CUSTOM_KEY, countryFlagSrc, resolvePhoneOptions };
36
+
37
+ //# sourceMappingURL=options.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.js","names":[],"sources":["../../../src/fields/phoneNumber/options.ts"],"sourcesContent":["import type { GroupField, StaticLabel, TextField } from 'payload'\nimport type { PhoneNumberGlobalConfig } from '../../types'\nimport { DEFAULT_METADATA_SET, type MetadataSet } from './engine/metadata'\nimport type { CountryCode, PhoneFormat, PhoneValidationMode } from './engine/phone'\n\n/** field.custom key the factory stamps its resolved config under, for tooling and secondary apps. */\nexport const PHONE_CUSTOM_KEY = '@10x-media/fields'\n\n/** Mounted by the plugin; the client builds flag URLs from serverURL + api route + this. */\nexport const FLAGS_PATH = '/10x-fields/flags'\n\n/**\n * The flag route's URL for one ISO 3166-1 alpha-2 code, built from the app's own API\n * route rather than assumed, so an install that moved `routes.api` still resolves its\n * flags. The `.svg` suffix is there for a reader who opens the URL directly.\n *\n * Lives here, not beside the handler, so the admin client can build a URL without\n * importing the server module and its deferred flag artwork.\n */\nexport const countryFlagSrc = (serverURL: string, apiRoute: string, code: string): string =>\n\t`${serverURL}${apiRoute}${FLAGS_PATH}/${encodeURIComponent(code.toLowerCase())}.svg`\n\nexport type PhoneFlagMode = 'emoji' | 'none' | 'svg'\nexport type PhoneStorageMode = 'e164' | 'object'\n\ntype CommonPhoneOptions = {\n\tname: string\n\tlabel?: StaticLabel\n\trequired?: boolean\n\tlocalized?: boolean\n\tindex?: boolean\n\tdefaultCountry?: CountryCode\n\tcountries?: readonly CountryCode[]\n\tpriorityCountries?: readonly CountryCode[]\n\t/** Heading over `priorityCountries` in the picker. No label renders no heading, only the group separator. */\n\tpriorityCountriesLabel?: StaticLabel\n\tvalidation?: PhoneValidationMode\n\tflags?: PhoneFlagMode\n\tcellFormat?: PhoneFormat\n\t/**\n\t * Default true. False means the value cannot be removed, not merely that the clear\n\t * affordance is hidden: emptying the input and committing reverts to the last valid value.\n\t */\n\tisClearable?: boolean\n}\n\nexport type PhoneNumberFieldOptions = CommonPhoneOptions & {\n\tstorage?: 'object'\n\toverrides?: (args: { field: GroupField }) => GroupField\n}\n\nexport type PhoneNumberE164FieldOptions = CommonPhoneOptions & {\n\tstorage: 'e164'\n\toverrides?: (args: { field: TextField }) => TextField\n}\n\nexport type AnyPhoneNumberFieldOptions = PhoneNumberE164FieldOptions | PhoneNumberFieldOptions\n\n/** Every phone option with its layers merged and its defaults applied. Server-side. */\nexport type ResolvedPhoneOptions = {\n\tcellFormat: PhoneFormat\n\tcountries?: readonly CountryCode[]\n\tdefaultCountry?: CountryCode\n\tflags: PhoneFlagMode\n\t/** See {@link CommonPhoneOptions.isClearable}. */\n\tisClearable: boolean\n\tmetadata: MetadataSet\n\tpriorityCountries?: readonly CountryCode[]\n\tpriorityCountriesLabel?: StaticLabel\n\tstorage: PhoneStorageMode\n\tvalidation: PhoneValidationMode\n}\n\n/** The field's own, unresolved layer: exactly what the author wrote, no defaults applied. */\nexport type ResolvablePhoneFieldOptions = Pick<\n\tCommonPhoneOptions,\n\t| 'cellFormat'\n\t| 'countries'\n\t| 'defaultCountry'\n\t| 'flags'\n\t| 'isClearable'\n\t| 'priorityCountries'\n\t| 'priorityCountriesLabel'\n\t| 'validation'\n> & {\n\tstorage?: PhoneStorageMode\n}\n\n/**\n * Field beats global beats these defaults, via `??` so an explicit `undefined`\n * on a field falls through rather than resetting it. `metadata` is global-only;\n * `storage` is field-only, since the factory's return type is fixed at build time\n * and a plugin-wide storage choice could never be honoured.\n */\nexport const resolvePhoneOptions = (\n\tfield: ResolvablePhoneFieldOptions,\n\tglobal: PhoneNumberGlobalConfig | undefined\n): ResolvedPhoneOptions => ({\n\tcellFormat: field.cellFormat ?? global?.cellFormat ?? 'international',\n\tcountries: field.countries ?? global?.countries,\n\tdefaultCountry: field.defaultCountry ?? global?.defaultCountry,\n\tflags: field.flags ?? global?.flags ?? 'svg',\n\tisClearable: field.isClearable ?? true,\n\tmetadata: global?.metadata ?? DEFAULT_METADATA_SET,\n\tpriorityCountries: field.priorityCountries ?? global?.priorityCountries,\n\tpriorityCountriesLabel: field.priorityCountriesLabel ?? global?.priorityCountriesLabel,\n\tstorage: field.storage ?? 'object',\n\tvalidation: field.validation ?? global?.validation ?? 'valid',\n})\n"],"mappings":";;;AAMA,MAAa,mBAAmB;;AAGhC,MAAa,aAAa;;;;;;;;;AAU1B,MAAa,kBAAkB,WAAmB,UAAkB,SACnE,GAAG,YAAY,WAAW,WAAW,GAAG,mBAAmB,KAAK,YAAY,CAAC,EAAE;;;;;;;AA0EhF,MAAa,uBACZ,OACA,YAC2B;CAC3B,YAAY,MAAM,cAAc,QAAQ,cAAc;CACtD,WAAW,MAAM,aAAa,QAAQ;CACtC,gBAAgB,MAAM,kBAAkB,QAAQ;CAChD,OAAO,MAAM,SAAS,QAAQ,SAAS;CACvC,aAAa,MAAM,eAAe;CAClC,UAAU,QAAQ,YAAA;CAClB,mBAAmB,MAAM,qBAAqB,QAAQ;CACtD,wBAAwB,MAAM,0BAA0B,QAAQ;CAChE,SAAS,MAAM,WAAW;CAC1B,YAAY,MAAM,cAAc,QAAQ,cAAc;AACvD"}
@@ -0,0 +1,14 @@
1
+ import { PhoneNumberE164FieldOptions, PhoneNumberFieldOptions } from "./options.js";
2
+ import { GroupField, TextField } from "payload";
3
+
4
+ //#region src/fields/phoneNumber/phoneNumberField.d.ts
5
+ /**
6
+ * Group of `number` + `country`, plus a derived-on-read `national`/`international`/
7
+ * `callingCode`/`uri`/`type`. Spread a preset for `e164` storage via `storage: 'e164'`,
8
+ * which trades the country/derived subfields for a single text field holding the raw string.
9
+ */
10
+ declare function phoneNumberField(options: PhoneNumberE164FieldOptions): TextField;
11
+ declare function phoneNumberField(options: PhoneNumberFieldOptions): GroupField;
12
+ //#endregion
13
+ export { phoneNumberField };
14
+ //# sourceMappingURL=phoneNumberField.d.ts.map
@@ -0,0 +1,167 @@
1
+ import { isKnownCountry } from "./engine/countries.js";
2
+ import { loadMetadata } from "./engine/metadata.js";
3
+ import { PHONE_CUSTOM_KEY } from "./options.js";
4
+ import { keys } from "../../translations/keys.js";
5
+ import { checkPhone, parsePhone } from "./engine/phone.js";
6
+ import { asTranslate } from "../../translations/server.js";
7
+ import { resolvePhoneOptionsSafe } from "./server/resolvePhoneOptionsSafe.js";
8
+ //#region src/fields/phoneNumber/phoneNumberField.ts
9
+ const assertCountries = (opts) => {
10
+ const { countries, defaultCountry, name } = opts;
11
+ for (const code of countries ?? []) if (!isKnownCountry(code)) throw new Error(`phoneNumberField(${name}): countries entry "${code}" is not a supported country`);
12
+ if (defaultCountry === void 0) return;
13
+ if (!isKnownCountry(defaultCountry)) throw new Error(`phoneNumberField(${name}): defaultCountry "${defaultCountry}" is not a supported country`);
14
+ if (countries !== void 0 && !countries.includes(defaultCountry)) throw new Error(`phoneNumberField(${name}): defaultCountry "${defaultCountry}" is not in countries`);
15
+ };
16
+ /**
17
+ * The values the read hook derives, driving both the group's schema and the hook itself: a
18
+ * name the group has no field for would otherwise be written and silently stripped.
19
+ */
20
+ const DERIVED = [
21
+ "national",
22
+ "international",
23
+ "callingCode",
24
+ "uri",
25
+ "type"
26
+ ];
27
+ const derivedFrom = (parsed) => Object.fromEntries(DERIVED.map((key) => [key, parsed[key]]));
28
+ /** Stored and derived alike stay out of the list, so the group reads as one column. */
29
+ const subfield = (name, extra = {}) => ({
30
+ admin: { disableListColumn: true },
31
+ name,
32
+ type: "text",
33
+ ...extra
34
+ });
35
+ /** Both storage shapes render through the same pair, so neither path can drift from it. */
36
+ const phoneComponents = (fieldLayer) => ({
37
+ Cell: {
38
+ clientProps: { phoneOptions: fieldLayer },
39
+ path: "@10x-media/fields/rsc#PhoneNumberCellServer"
40
+ },
41
+ Field: {
42
+ clientProps: { phoneOptions: fieldLayer },
43
+ path: "@10x-media/fields/rsc#PhoneNumberFieldServer"
44
+ }
45
+ });
46
+ /** Configuration errors return a message rather than throw: writes must fail either way. */
47
+ const mobileMetadataMismatch = (name) => `phoneNumberField(${name}): validation "mobile" requires metadata "max" or "mobile", but this install is configured "min"`;
48
+ const buildDerivedHook = (fieldLayer) => async ({ req, value }) => {
49
+ const stored = value ?? {};
50
+ if (typeof stored.number !== "string" || stored.number === "") return value;
51
+ const resolved = resolvePhoneOptionsSafe({
52
+ fieldOptions: fieldLayer,
53
+ payload: req.payload
54
+ });
55
+ let metadata;
56
+ try {
57
+ metadata = await loadMetadata(resolved.metadata);
58
+ } catch (error) {
59
+ req.payload.logger.error({ err: error }, "[fields] phoneNumber metadata failed to load for a derived read");
60
+ return value;
61
+ }
62
+ const parsed = parsePhone(stored.number, {
63
+ defaultCountry: stored.country,
64
+ metadata
65
+ });
66
+ if (!parsed) return value;
67
+ return {
68
+ ...stored,
69
+ ...derivedFrom(parsed)
70
+ };
71
+ };
72
+ /** Object storage keeps the country beside the number, so the stored row speaks for itself. */
73
+ const readStoredPhone = (value) => {
74
+ const stored = value ?? {};
75
+ return {
76
+ country: stored.country,
77
+ raw: typeof stored.number === "string" ? stored.number : ""
78
+ };
79
+ };
80
+ /** e164 storage has no country of its own, so a national number needs the resolved default. */
81
+ const readE164Phone = (value, resolved) => ({
82
+ country: resolved.defaultCountry,
83
+ raw: typeof value === "string" ? value : ""
84
+ });
85
+ const buildValidate = (opts) => async (value, args) => {
86
+ const resolved = resolvePhoneOptionsSafe({
87
+ fieldOptions: opts.fieldLayer,
88
+ payload: args.req.payload
89
+ });
90
+ const { country, raw } = opts.read(value, resolved);
91
+ const check = checkPhone(raw, resolved.validation, {
92
+ defaultCountry: country,
93
+ metadata: await loadMetadata(resolved.metadata)
94
+ });
95
+ if (check === "empty") return opts.required ? asTranslate(args.req.t)(keys.phoneRequired) : true;
96
+ if (check === "notMobile") {
97
+ if (resolved.validation === "mobile" && resolved.metadata === "min") return mobileMetadataMismatch(opts.name);
98
+ return asTranslate(args.req.t)(keys.phoneNotMobile);
99
+ }
100
+ if (check === "invalid") return asTranslate(args.req.t)(keys.invalidPhoneNumber);
101
+ return true;
102
+ };
103
+ function phoneNumberField(options) {
104
+ const { name, label, required, localized, index, defaultCountry, countries, priorityCountries, priorityCountriesLabel, validation, flags, cellFormat, isClearable } = options;
105
+ assertCountries({
106
+ countries,
107
+ defaultCountry,
108
+ name
109
+ });
110
+ const fieldLayer = {
111
+ ...cellFormat !== void 0 ? { cellFormat } : {},
112
+ ...countries !== void 0 ? { countries } : {},
113
+ ...defaultCountry !== void 0 ? { defaultCountry } : {},
114
+ ...flags !== void 0 ? { flags } : {},
115
+ ...isClearable !== void 0 ? { isClearable } : {},
116
+ ...priorityCountries !== void 0 ? { priorityCountries } : {},
117
+ ...priorityCountriesLabel !== void 0 ? { priorityCountriesLabel } : {},
118
+ ...options.storage !== void 0 ? { storage: options.storage } : {},
119
+ ...validation !== void 0 ? { validation } : {}
120
+ };
121
+ if (options.storage === "e164") {
122
+ const base = {
123
+ name,
124
+ type: "text",
125
+ ...label !== void 0 ? { label } : {},
126
+ ...required !== void 0 ? { required } : {},
127
+ ...localized !== void 0 ? { localized } : {},
128
+ ...index !== void 0 ? { index } : {},
129
+ admin: { components: phoneComponents(fieldLayer) },
130
+ custom: { [PHONE_CUSTOM_KEY]: fieldLayer },
131
+ validate: buildValidate({
132
+ fieldLayer,
133
+ name,
134
+ read: readE164Phone,
135
+ required: required ?? false
136
+ })
137
+ };
138
+ return typeof options.overrides === "function" ? options.overrides({ field: base }) : base;
139
+ }
140
+ const base = {
141
+ name,
142
+ type: "group",
143
+ ...label !== void 0 ? { label } : {},
144
+ ...required !== void 0 ? { required } : {},
145
+ ...localized !== void 0 ? { localized } : {},
146
+ ...index !== void 0 ? { index } : {},
147
+ admin: { components: phoneComponents(fieldLayer) },
148
+ custom: { [PHONE_CUSTOM_KEY]: fieldLayer },
149
+ fields: [
150
+ subfield("number"),
151
+ subfield("country"),
152
+ ...DERIVED.map((name) => subfield(name, { virtual: true }))
153
+ ],
154
+ hooks: { afterRead: [buildDerivedHook(fieldLayer)] },
155
+ validate: buildValidate({
156
+ fieldLayer,
157
+ name,
158
+ read: readStoredPhone,
159
+ required: required ?? false
160
+ })
161
+ };
162
+ return typeof options.overrides === "function" ? options.overrides({ field: base }) : base;
163
+ }
164
+ //#endregion
165
+ export { phoneNumberField };
166
+
167
+ //# sourceMappingURL=phoneNumberField.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"phoneNumberField.js","names":[],"sources":["../../../src/fields/phoneNumber/phoneNumberField.ts"],"sourcesContent":["import type { FieldHook, GroupField, TextField, Validate } from 'payload'\nimport { keys } from '../../translations/keys'\nimport { asTranslate } from '../../translations/server'\nimport { isKnownCountry } from './engine/countries'\nimport { loadMetadata, type PhoneMetadata } from './engine/metadata'\nimport { type CountryCode, checkPhone, type ParsedPhone, parsePhone } from './engine/phone'\nimport {\n\ttype AnyPhoneNumberFieldOptions,\n\tPHONE_CUSTOM_KEY,\n\ttype PhoneNumberE164FieldOptions,\n\ttype PhoneNumberFieldOptions,\n\ttype ResolvablePhoneFieldOptions,\n\ttype ResolvedPhoneOptions,\n} from './options'\nimport { resolvePhoneOptionsSafe } from './server/resolvePhoneOptionsSafe'\n\nconst assertCountries = (opts: {\n\tcountries: readonly CountryCode[] | undefined\n\tdefaultCountry: CountryCode | undefined\n\tname: string\n}): void => {\n\tconst { countries, defaultCountry, name } = opts\n\tfor (const code of countries ?? []) {\n\t\tif (!isKnownCountry(code)) {\n\t\t\tthrow new Error(\n\t\t\t\t`phoneNumberField(${name}): countries entry \"${code}\" is not a supported country`\n\t\t\t)\n\t\t}\n\t}\n\tif (defaultCountry === undefined) return\n\tif (!isKnownCountry(defaultCountry)) {\n\t\tthrow new Error(\n\t\t\t`phoneNumberField(${name}): defaultCountry \"${defaultCountry}\" is not a supported country`\n\t\t)\n\t}\n\tif (countries !== undefined && !countries.includes(defaultCountry)) {\n\t\tthrow new Error(\n\t\t\t`phoneNumberField(${name}): defaultCountry \"${defaultCountry}\" is not in countries`\n\t\t)\n\t}\n}\n\n/**\n * The values the read hook derives, driving both the group's schema and the hook itself: a\n * name the group has no field for would otherwise be written and silently stripped.\n */\nconst DERIVED = [\n\t'national',\n\t'international',\n\t'callingCode',\n\t'uri',\n\t'type',\n] as const satisfies readonly (keyof ParsedPhone)[]\n\ntype DerivedPhone = Pick<ParsedPhone, (typeof DERIVED)[number]>\n\nconst derivedFrom = (parsed: ParsedPhone): DerivedPhone =>\n\tObject.fromEntries(DERIVED.map((key) => [key, parsed[key]])) as DerivedPhone\n\n/** Stored and derived alike stay out of the list, so the group reads as one column. */\nconst subfield = (name: string, extra: { virtual?: true } = {}): TextField => ({\n\tadmin: { disableListColumn: true },\n\tname,\n\ttype: 'text',\n\t...extra,\n})\n\n/** Both storage shapes render through the same pair, so neither path can drift from it. */\nconst phoneComponents = (fieldLayer: ResolvablePhoneFieldOptions) => ({\n\tCell: {\n\t\tclientProps: { phoneOptions: fieldLayer },\n\t\tpath: '@10x-media/fields/rsc#PhoneNumberCellServer',\n\t},\n\tField: {\n\t\tclientProps: { phoneOptions: fieldLayer },\n\t\tpath: '@10x-media/fields/rsc#PhoneNumberFieldServer',\n\t},\n})\n\n/** Configuration errors return a message rather than throw: writes must fail either way. */\nconst mobileMetadataMismatch = (name: string): string =>\n\t`phoneNumberField(${name}): validation \"mobile\" requires metadata \"max\" or \"mobile\", but this install is configured \"min\"`\n\nconst buildDerivedHook =\n\t(fieldLayer: ResolvablePhoneFieldOptions): FieldHook =>\n\tasync ({ req, value }) => {\n\t\tconst stored = (value ?? {}) as { country?: CountryCode; number?: string }\n\t\tif (typeof stored.number !== 'string' || stored.number === '') return value\n\t\tconst resolved = resolvePhoneOptionsSafe({ fieldOptions: fieldLayer, payload: req.payload })\n\t\t// A throwing afterRead fails the whole request, so one unloadable chunk would take down\n\t\t// every read of the collection; degrading costs the derived values on this field alone.\n\t\tlet metadata: PhoneMetadata\n\t\ttry {\n\t\t\tmetadata = await loadMetadata(resolved.metadata)\n\t\t} catch (error) {\n\t\t\treq.payload.logger.error(\n\t\t\t\t{ err: error },\n\t\t\t\t'[fields] phoneNumber metadata failed to load for a derived read'\n\t\t\t)\n\t\t\treturn value\n\t\t}\n\t\tconst parsed = parsePhone(stored.number, { defaultCountry: stored.country, metadata })\n\t\tif (!parsed) return value\n\t\t// Persisted keys spread first: this hook enriches the group, it never rewrites it.\n\t\treturn { ...stored, ...derivedFrom(parsed) }\n\t}\n\n/** How one storage shape yields the number to check and the country to read it under. */\ntype PhoneInputReader = (\n\tvalue: unknown,\n\tresolved: ResolvedPhoneOptions\n) => { country: CountryCode | undefined; raw: string }\n\n/** Object storage keeps the country beside the number, so the stored row speaks for itself. */\nconst readStoredPhone: PhoneInputReader = (value) => {\n\tconst stored = (value ?? {}) as { country?: CountryCode; number?: string }\n\treturn { country: stored.country, raw: typeof stored.number === 'string' ? stored.number : '' }\n}\n\n/** e164 storage has no country of its own, so a national number needs the resolved default. */\nconst readE164Phone: PhoneInputReader = (value, resolved) => ({\n\tcountry: resolved.defaultCountry,\n\traw: typeof value === 'string' ? value : '',\n})\n\nconst buildValidate =\n\t(opts: {\n\t\tfieldLayer: ResolvablePhoneFieldOptions\n\t\tname: string\n\t\tread: PhoneInputReader\n\t\trequired: boolean\n\t}): Validate =>\n\tasync (value, args) => {\n\t\tconst resolved = resolvePhoneOptionsSafe({\n\t\t\tfieldOptions: opts.fieldLayer,\n\t\t\tpayload: args.req.payload,\n\t\t})\n\t\tconst { country, raw } = opts.read(value, resolved)\n\t\tconst check = checkPhone(raw, resolved.validation, {\n\t\t\tdefaultCountry: country,\n\t\t\tmetadata: await loadMetadata(resolved.metadata),\n\t\t})\n\t\tif (check === 'empty') {\n\t\t\treturn opts.required ? asTranslate(args.req.t)(keys.phoneRequired) : true\n\t\t}\n\t\tif (check === 'notMobile') {\n\t\t\tif (resolved.validation === 'mobile' && resolved.metadata === 'min') {\n\t\t\t\treturn mobileMetadataMismatch(opts.name)\n\t\t\t}\n\t\t\treturn asTranslate(args.req.t)(keys.phoneNotMobile)\n\t\t}\n\t\tif (check === 'invalid') return asTranslate(args.req.t)(keys.invalidPhoneNumber)\n\t\treturn true\n\t}\n\n/**\n * Group of `number` + `country`, plus a derived-on-read `national`/`international`/\n * `callingCode`/`uri`/`type`. Spread a preset for `e164` storage via `storage: 'e164'`,\n * which trades the country/derived subfields for a single text field holding the raw string.\n */\nexport function phoneNumberField(options: PhoneNumberE164FieldOptions): TextField\nexport function phoneNumberField(options: PhoneNumberFieldOptions): GroupField\nexport function phoneNumberField(options: AnyPhoneNumberFieldOptions): GroupField | TextField {\n\tconst {\n\t\tname,\n\t\tlabel,\n\t\trequired,\n\t\tlocalized,\n\t\tindex,\n\t\tdefaultCountry,\n\t\tcountries,\n\t\tpriorityCountries,\n\t\tpriorityCountriesLabel,\n\t\tvalidation,\n\t\tflags,\n\t\tcellFormat,\n\t\tisClearable,\n\t} = options\n\n\tassertCountries({ countries, defaultCountry, name })\n\n\t// The field's own options, exactly as written, with no defaults applied: registry\n\t// defaults are only visible at request time, via resolvePhoneOptionsSafe below.\n\tconst fieldLayer: ResolvablePhoneFieldOptions = {\n\t\t...(cellFormat !== undefined ? { cellFormat } : {}),\n\t\t...(countries !== undefined ? { countries } : {}),\n\t\t...(defaultCountry !== undefined ? { defaultCountry } : {}),\n\t\t...(flags !== undefined ? { flags } : {}),\n\t\t...(isClearable !== undefined ? { isClearable } : {}),\n\t\t...(priorityCountries !== undefined ? { priorityCountries } : {}),\n\t\t...(priorityCountriesLabel !== undefined ? { priorityCountriesLabel } : {}),\n\t\t...(options.storage !== undefined ? { storage: options.storage } : {}),\n\t\t...(validation !== undefined ? { validation } : {}),\n\t}\n\n\tif (options.storage === 'e164') {\n\t\tconst base: TextField = {\n\t\t\tname,\n\t\t\ttype: 'text',\n\t\t\t...(label !== undefined ? { label } : {}),\n\t\t\t...(required !== undefined ? { required } : {}),\n\t\t\t...(localized !== undefined ? { localized } : {}),\n\t\t\t...(index !== undefined ? { index } : {}),\n\t\t\tadmin: { components: phoneComponents(fieldLayer) },\n\t\t\tcustom: { [PHONE_CUSTOM_KEY]: fieldLayer },\n\t\t\tvalidate: buildValidate({\n\t\t\t\tfieldLayer,\n\t\t\t\tname,\n\t\t\t\tread: readE164Phone,\n\t\t\t\trequired: required ?? false,\n\t\t\t}),\n\t\t}\n\t\treturn typeof options.overrides === 'function' ? options.overrides({ field: base }) : base\n\t}\n\n\tconst base: GroupField = {\n\t\tname,\n\t\ttype: 'group',\n\t\t...(label !== undefined ? { label } : {}),\n\t\t...(required !== undefined ? { required } : {}),\n\t\t...(localized !== undefined ? { localized } : {}),\n\t\t...(index !== undefined ? { index } : {}),\n\t\tadmin: { components: phoneComponents(fieldLayer) },\n\t\tcustom: { [PHONE_CUSTOM_KEY]: fieldLayer },\n\t\tfields: [\n\t\t\tsubfield('number'),\n\t\t\tsubfield('country'),\n\t\t\t...DERIVED.map((name) => subfield(name, { virtual: true })),\n\t\t],\n\t\thooks: { afterRead: [buildDerivedHook(fieldLayer)] },\n\t\tvalidate: buildValidate({\n\t\t\tfieldLayer,\n\t\t\tname,\n\t\t\tread: readStoredPhone,\n\t\t\trequired: required ?? false,\n\t\t}),\n\t}\n\n\treturn typeof options.overrides === 'function' ? options.overrides({ field: base }) : base\n}\n"],"mappings":";;;;;;;;AAgBA,MAAM,mBAAmB,SAIb;CACX,MAAM,EAAE,WAAW,gBAAgB,SAAS;CAC5C,KAAK,MAAM,QAAQ,aAAa,CAAC,GAChC,IAAI,CAAC,eAAe,IAAI,GACvB,MAAM,IAAI,MACT,oBAAoB,KAAK,sBAAsB,KAAK,6BACrD;CAGF,IAAI,mBAAmB,KAAA,GAAW;CAClC,IAAI,CAAC,eAAe,cAAc,GACjC,MAAM,IAAI,MACT,oBAAoB,KAAK,qBAAqB,eAAe,6BAC9D;CAED,IAAI,cAAc,KAAA,KAAa,CAAC,UAAU,SAAS,cAAc,GAChE,MAAM,IAAI,MACT,oBAAoB,KAAK,qBAAqB,eAAe,sBAC9D;AAEF;;;;;AAMA,MAAM,UAAU;CACf;CACA;CACA;CACA;CACA;AACD;AAIA,MAAM,eAAe,WACpB,OAAO,YAAY,QAAQ,KAAK,QAAQ,CAAC,KAAK,OAAO,IAAI,CAAC,CAAC;;AAG5D,MAAM,YAAY,MAAc,QAA4B,CAAC,OAAkB;CAC9E,OAAO,EAAE,mBAAmB,KAAK;CACjC;CACA,MAAM;CACN,GAAG;AACJ;;AAGA,MAAM,mBAAmB,gBAA6C;CACrE,MAAM;EACL,aAAa,EAAE,cAAc,WAAW;EACxC,MAAM;CACP;CACA,OAAO;EACN,aAAa,EAAE,cAAc,WAAW;EACxC,MAAM;CACP;AACD;;AAGA,MAAM,0BAA0B,SAC/B,oBAAoB,KAAK;AAE1B,MAAM,oBACJ,eACD,OAAO,EAAE,KAAK,YAAY;CACzB,MAAM,SAAU,SAAS,CAAC;CAC1B,IAAI,OAAO,OAAO,WAAW,YAAY,OAAO,WAAW,IAAI,OAAO;CACtE,MAAM,WAAW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,KAAK,CAAC,IAAI;CACvF;CAEA,MAAM,OAAmB;EACxB;EACA,MAAM;EACN,GAAI,UAAU,KAAA,IAAY,EAAE,MAAM,IAAI,CAAC;EACvC,GAAI,aAAa,KAAA,IAAY,EAAE,SAAS,IAAI,CAAC;EAC7C,GAAI,cAAc,KAAA,IAAY,EAAE,UAAU,IAAI,CAAC;EAC/C,GAAI,UAAU,KAAA,IAAY,EAAE,MAAM,IAAI,CAAC;EACvC,OAAO,EAAE,YAAY,gBAAgB,UAAU,EAAE;EACjD,QAAQ,GAAG,mBAAmB,WAAW;EACzC,QAAQ;GACP,SAAS,QAAQ;GACjB,SAAS,SAAS;GAClB,GAAG,QAAQ,KAAK,SAAS,SAAS,MAAM,EAAE,SAAS,KAAK,CAAC,CAAC;EAC3D;EACA,OAAO,EAAE,WAAW,CAAC,iBAAiB,UAAU,CAAC,EAAE;EACnD,UAAU,cAAc;GACvB;GACA;GACA,MAAM;GACN,UAAU,YAAY;EACvB,CAAC;CACF;CAEA,OAAO,OAAO,QAAQ,cAAc,aAAa,QAAQ,UAAU,EAAE,OAAO,KAAK,CAAC,IAAI;AACvF"}
@@ -0,0 +1,19 @@
1
+ import { ResolvablePhoneFieldOptions } from "../options.js";
2
+ import { ClientField, DefaultServerCellComponentProps } from "payload";
3
+
4
+ //#region src/fields/phoneNumber/server/PhoneNumberCellServer.d.ts
5
+ type PhoneNumberCellRawValue = {
6
+ country?: string;
7
+ number?: string;
8
+ } | null | string | undefined;
9
+ type PhoneNumberCellServerComponentProps = {
10
+ phoneOptions?: ResolvablePhoneFieldOptions;
11
+ } & DefaultServerCellComponentProps<ClientField, PhoneNumberCellRawValue>;
12
+ /**
13
+ * Formats entirely server-side: unlike measurement's cell, phone has no viewer
14
+ * preference to react to, so this ships zero client JS for the list column.
15
+ */
16
+ declare const PhoneNumberCellServer: (props: PhoneNumberCellServerComponentProps) => Promise<import("react/jsx-runtime").JSX.Element | null>;
17
+ //#endregion
18
+ export { PhoneNumberCellServer };
19
+ //# sourceMappingURL=PhoneNumberCellServer.d.ts.map
@@ -0,0 +1,73 @@
1
+ import { emojiFlag } from "../engine/countries.js";
2
+ import { loadMetadata } from "../engine/metadata.js";
3
+ import { countryFlagSrc } from "../options.js";
4
+ import { parsePhone } from "../engine/phone.js";
5
+ import { readPhoneOptions } from "./readPhoneOptions.js";
6
+ import { resolvePhoneOptionsSafe } from "./resolvePhoneOptionsSafe.js";
7
+ import { jsx, jsxs } from "react/jsx-runtime";
8
+ //#region src/fields/phoneNumber/server/PhoneNumberCellServer.tsx
9
+ const formatText = (parsed, raw, format) => {
10
+ if (!parsed) return raw;
11
+ if (format === "e164") return parsed.e164;
12
+ return format === "national" ? parsed.national : parsed.international;
13
+ };
14
+ const renderFlag = (args) => {
15
+ const { apiRoute, code, flags, serverURL } = args;
16
+ if (flags === "none" || code === void 0) return null;
17
+ if (flags === "emoji") return /* @__PURE__ */ jsx("span", {
18
+ "aria-hidden": "true",
19
+ children: emojiFlag(code)
20
+ });
21
+ return /* @__PURE__ */ jsx("img", {
22
+ alt: "",
23
+ "aria-hidden": "true",
24
+ height: 15,
25
+ src: countryFlagSrc(serverURL, apiRoute, code),
26
+ width: 20
27
+ });
28
+ };
29
+ /**
30
+ * Formats entirely server-side: unlike measurement's cell, phone has no viewer
31
+ * preference to react to, so this ships zero client JS for the list column.
32
+ */
33
+ const PhoneNumberCellServer = async (props) => {
34
+ const { cellData, field, payload } = props;
35
+ const resolved = resolvePhoneOptionsSafe({
36
+ fieldOptions: readPhoneOptions({
37
+ component: "PhoneNumberCellServer",
38
+ field,
39
+ propOptions: props.phoneOptions
40
+ }),
41
+ payload
42
+ });
43
+ const raw = typeof cellData === "string" ? cellData : cellData?.number ?? "";
44
+ if (raw === "") return null;
45
+ const storedCountry = typeof cellData === "object" && cellData?.country ? cellData.country : void 0;
46
+ let parsed = null;
47
+ try {
48
+ parsed = parsePhone(raw, {
49
+ defaultCountry: storedCountry,
50
+ metadata: await loadMetadata(resolved.metadata)
51
+ });
52
+ } catch (error) {
53
+ payload.logger.error({ err: error }, "[fields] phoneNumber metadata failed to load for a list cell");
54
+ }
55
+ const country = parsed?.country ?? storedCountry;
56
+ return /* @__PURE__ */ jsxs("span", {
57
+ style: {
58
+ alignItems: "center",
59
+ display: "inline-flex",
60
+ gap: 6
61
+ },
62
+ children: [renderFlag({
63
+ apiRoute: payload.config.routes.api,
64
+ code: country,
65
+ flags: resolved.flags,
66
+ serverURL: payload.config.serverURL
67
+ }), /* @__PURE__ */ jsx("span", { children: formatText(parsed, raw, resolved.cellFormat) })]
68
+ });
69
+ };
70
+ //#endregion
71
+ export { PhoneNumberCellServer };
72
+
73
+ //# sourceMappingURL=PhoneNumberCellServer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PhoneNumberCellServer.js","names":[],"sources":["../../../../src/fields/phoneNumber/server/PhoneNumberCellServer.tsx"],"sourcesContent":["import type { ClientField, DefaultServerCellComponentProps } from 'payload'\nimport { emojiFlag } from '../engine/countries'\nimport { loadMetadata } from '../engine/metadata'\nimport { type CountryCode, type ParsedPhone, type PhoneFormat, parsePhone } from '../engine/phone'\nimport { countryFlagSrc, type PhoneFlagMode, type ResolvablePhoneFieldOptions } from '../options'\nimport { readPhoneOptions } from './readPhoneOptions'\nimport { resolvePhoneOptionsSafe } from './resolvePhoneOptionsSafe'\n\ntype PhoneNumberCellRawValue = { country?: string; number?: string } | null | string | undefined\n\ntype PhoneNumberCellServerComponentProps = {\n\tphoneOptions?: ResolvablePhoneFieldOptions\n} & DefaultServerCellComponentProps<ClientField, PhoneNumberCellRawValue>\n\nconst formatText = (parsed: null | ParsedPhone, raw: string, format: PhoneFormat): string => {\n\tif (!parsed) return raw\n\tif (format === 'e164') return parsed.e164\n\treturn format === 'national' ? parsed.national : parsed.international\n}\n\nconst renderFlag = (args: {\n\tcode: CountryCode | undefined\n\tflags: PhoneFlagMode\n\tserverURL: string\n\tapiRoute: string\n}) => {\n\tconst { apiRoute, code, flags, serverURL } = args\n\tif (flags === 'none' || code === undefined) return null\n\tif (flags === 'emoji') return <span aria-hidden=\"true\">{emojiFlag(code)}</span>\n\treturn (\n\t\t<img\n\t\t\talt=\"\"\n\t\t\taria-hidden=\"true\"\n\t\t\theight={15}\n\t\t\tsrc={countryFlagSrc(serverURL, apiRoute, code)}\n\t\t\twidth={20}\n\t\t/>\n\t)\n}\n\n/**\n * Formats entirely server-side: unlike measurement's cell, phone has no viewer\n * preference to react to, so this ships zero client JS for the list column.\n */\nexport const PhoneNumberCellServer = async (props: PhoneNumberCellServerComponentProps) => {\n\tconst { cellData, field, payload } = props\n\tconst phoneOptions = readPhoneOptions({\n\t\tcomponent: 'PhoneNumberCellServer',\n\t\tfield,\n\t\tpropOptions: props.phoneOptions,\n\t})\n\tconst resolved = resolvePhoneOptionsSafe({ fieldOptions: phoneOptions, payload })\n\n\tconst raw = typeof cellData === 'string' ? cellData : (cellData?.number ?? '')\n\tif (raw === '') return null\n\n\tconst storedCountry =\n\t\ttypeof cellData === 'object' && cellData?.country\n\t\t\t? (cellData.country as CountryCode)\n\t\t\t: undefined\n\t// An async server component that throws has no error boundary of its own here; a rejected\n\t// chunk degrades this one cell to the raw value instead of failing the whole list page.\n\tlet parsed: ParsedPhone | null = null\n\ttry {\n\t\tconst metadata = await loadMetadata(resolved.metadata)\n\t\tparsed = parsePhone(raw, { defaultCountry: storedCountry, metadata })\n\t} catch (error) {\n\t\tpayload.logger.error(\n\t\t\t{ err: error },\n\t\t\t'[fields] phoneNumber metadata failed to load for a list cell'\n\t\t)\n\t}\n\tconst country = parsed?.country ?? storedCountry\n\n\treturn (\n\t\t<span style={{ alignItems: 'center', display: 'inline-flex', gap: 6 }}>\n\t\t\t{renderFlag({\n\t\t\t\tapiRoute: payload.config.routes.api,\n\t\t\t\tcode: country,\n\t\t\t\tflags: resolved.flags,\n\t\t\t\tserverURL: payload.config.serverURL,\n\t\t\t})}\n\t\t\t<span>{formatText(parsed, raw, resolved.cellFormat)}</span>\n\t\t</span>\n\t)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AChB,WAAW,QAAQ,OAAO;EAC3B,CAAC,GACD,oBAAC,QAAD,EAAA,UAAO,WAAW,QAAQ,KAAK,SAAS,UAAU,EAAQ,CAAA,CACrD;;AAER"}
@@ -0,0 +1,16 @@
1
+ import { ResolvablePhoneFieldOptions } from "../options.js";
2
+ import { GroupFieldServerProps, TextFieldServerProps } from "payload";
3
+
4
+ //#region src/fields/phoneNumber/server/PhoneNumberFieldServer.d.ts
5
+ type PhoneNumberFieldServerComponentProps = {
6
+ phoneOptions?: ResolvablePhoneFieldOptions;
7
+ } & (GroupFieldServerProps | TextFieldServerProps);
8
+ /**
9
+ * The factory stamps only the field's own, unresolved option layer (see options.ts),
10
+ * so this is the one place a registry default and a field override are both visible
11
+ * together: resolution has to happen here, per request, not at config-build time.
12
+ */
13
+ declare const PhoneNumberFieldServer: (props: PhoneNumberFieldServerComponentProps) => Promise<import("react/jsx-runtime").JSX.Element>;
14
+ //#endregion
15
+ export { PhoneNumberFieldServer };
16
+ //# sourceMappingURL=PhoneNumberFieldServer.d.ts.map