@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 @@
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,eAAe,OAAe,QAAqB,SAA+B;CAC9F,MAAM,SAAS,WAAW,OAAO,IAAI;CACrC,IAAI,CAAC,QAAQ,OAAO;CACpB,IAAI,WAAW,QAAQ,OAAO,OAAO;CACrC,OAAO,WAAW,aAAa,OAAO,WAAW,OAAO;AACzD;AAEA,MAAa,YAAY,OAAe,SACvC,WAAW,OAAO,IAAI,GAAG,OAAO;;;;;AAMjC,MAAa,gBAAgB,OAAe,SAA2C;CACtF,MAAM,UAAU,MAAM,KAAK;CAC3B,MAAM,SAAS,WAAW,SAAS,IAAI;CACvC,IAAI,QAAQ,SAAS,OAAO,SAAS,OAAO;CAC5C,MAAM,OAAO,QAAQ,QAAQ,GAAG;CAChC,IAAI,SAAS,IAAI,OAAO;CACxB,MAAM,OAAO,QAAQ,MAAM,IAAI;CAE/B,KAAK,IAAI,MAAM,KAAK,IAAI,KAAK,QAAQ,EAAE,GAAG,MAAM,GAAG,OAAO;EACzD,MAAM,YAAY,WAAW,KAAK,MAAM,GAAG,GAAG,GAAG,IAAI;EACrD,IAAI,WAAW,SAAS,UAAU,SAAS,OAAO;CACnD;CACA,OAAO;AACR;AAEA,MAAa,iBAAiB,OAAe,SAC5C,aAAa,OAAO,IAAI,GAAG;AAE5B,MAAa,cACZ,OACA,MACA,SACgB;CAChB,IAAI,MAAM,KAAK,MAAM,IAAI,OAAO;CAChC,MAAM,SAAS,WAAW,OAAO,IAAI;CACrC,IAAI,CAAC,QAAQ,OAAO;CACpB,IAAI,SAAS,YAAY,OAAO,OAAO,WAAW,OAAO;CACzD,IAAI,CAAC,OAAO,OAAO,OAAO;CAC1B,IAAI,SAAS,UACZ,OAAO,OAAO,SAAS,KAAA,KAAa,aAAa,IAAI,OAAO,IAAI,IAAI,OAAO;CAE5E,OAAO;AACR;AAEA,MAAa,mBACZ,OACA,SACA,SACY,IAAI,UAAU,SAAS,KAAK,QAAiB,EAAE,MAAM,KAAK"}
@@ -0,0 +1,72 @@
1
+ import { MetadataSet } from "./engine/metadata.js";
2
+ 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.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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)\n}\n"],"mappings":";;;;;;;;AAcA,MAAM,cAAc,QAA4B,KAAa,WAAgC;CAC5F,IAAI,CAAC,QAAQ,OAAO;CACpB,IAAI,WAAW,QAAQ,OAAO,OAAO;CACrC,OAAO,WAAW,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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
@@ -0,0 +1,57 @@
1
+ import { loadMetadata } from "../engine/metadata.js";
2
+ import { phoneSeed } from "../engine/draft.js";
3
+ import { PhoneNumberField } from "../client/PhoneNumberField.js";
4
+ import { readPhoneOptions } from "./readPhoneOptions.js";
5
+ import { resolvePhoneOptionsSafe } from "./resolvePhoneOptionsSafe.js";
6
+ import { jsx } from "react/jsx-runtime";
7
+ //#region src/fields/phoneNumber/server/PhoneNumberFieldServer.tsx
8
+ /** The stored E.164 string, under either storage shape, or '' when the field is empty. */
9
+ const storedNumber = (sibling, name) => {
10
+ if (typeof sibling !== "object" || sibling === null) return "";
11
+ const own = sibling[name];
12
+ if (typeof own === "string") return own;
13
+ if (typeof own !== "object" || own === null) return "";
14
+ const inner = own.number;
15
+ return typeof inner === "string" ? inner : "";
16
+ };
17
+ /**
18
+ * The factory stamps only the field's own, unresolved option layer (see options.ts),
19
+ * so this is the one place a registry default and a field override are both visible
20
+ * together: resolution has to happen here, per request, not at config-build time.
21
+ */
22
+ const PhoneNumberFieldServer = async (props) => {
23
+ const { clientField, field, path, permissions, readOnly, req, siblingData } = props;
24
+ const resolved = resolvePhoneOptionsSafe({
25
+ fieldOptions: readPhoneOptions({
26
+ component: "PhoneNumberFieldServer",
27
+ field,
28
+ propOptions: props.phoneOptions
29
+ }),
30
+ payload: req.payload
31
+ });
32
+ const { cellFormat, validation, ...clientOptions } = resolved;
33
+ const raw = "name" in field ? storedNumber(siblingData, String(field.name)) : "";
34
+ let seed = null;
35
+ if (raw !== "") try {
36
+ const metadata = await loadMetadata(resolved.metadata);
37
+ seed = phoneSeed(raw, {
38
+ defaultCountry: resolved.defaultCountry,
39
+ metadata
40
+ });
41
+ } catch (error) {
42
+ req.payload.logger.error({ err: error }, "[fields] phoneNumber metadata failed to load for a field seed");
43
+ seed = null;
44
+ }
45
+ return /* @__PURE__ */ jsx(PhoneNumberField, {
46
+ field: clientField,
47
+ path,
48
+ permissions,
49
+ phoneOptions: clientOptions,
50
+ readOnly,
51
+ seed
52
+ });
53
+ };
54
+ //#endregion
55
+ export { PhoneNumberFieldServer };
56
+
57
+ //# sourceMappingURL=PhoneNumberFieldServer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"PhoneNumberFieldServer.js","names":[],"sources":["../../../../src/fields/phoneNumber/server/PhoneNumberFieldServer.tsx"],"sourcesContent":["import type { GroupFieldServerProps, TextFieldServerProps } from 'payload'\nimport { PhoneNumberField } from '../client/PhoneNumberField'\nimport { type PhoneSeed, phoneSeed } from '../engine/draft'\nimport { loadMetadata } from '../engine/metadata'\nimport type { ResolvablePhoneFieldOptions } from '../options'\nimport { readPhoneOptions } from './readPhoneOptions'\nimport { resolvePhoneOptionsSafe } from './resolvePhoneOptionsSafe'\n\ntype PhoneNumberFieldServerComponentProps = {\n\tphoneOptions?: ResolvablePhoneFieldOptions\n} & (GroupFieldServerProps | TextFieldServerProps)\n\n/** The stored E.164 string, under either storage shape, or '' when the field is empty. */\nconst storedNumber = (sibling: unknown, name: string): string => {\n\tif (typeof sibling !== 'object' || sibling === null) return ''\n\tconst own = (sibling as Record<string, unknown>)[name]\n\tif (typeof own === 'string') return own\n\tif (typeof own !== 'object' || own === null) return ''\n\tconst inner = (own as Record<string, unknown>).number\n\treturn typeof inner === 'string' ? inner : ''\n}\n\n/**\n * The factory stamps only the field's own, unresolved option layer (see options.ts),\n * so this is the one place a registry default and a field override are both visible\n * together: resolution has to happen here, per request, not at config-build time.\n */\nexport const PhoneNumberFieldServer = async (props: PhoneNumberFieldServerComponentProps) => {\n\tconst { clientField, field, path, permissions, readOnly, req, siblingData } = props\n\tconst phoneOptions = readPhoneOptions({\n\t\tcomponent: 'PhoneNumberFieldServer',\n\t\tfield,\n\t\tpropOptions: props.phoneOptions,\n\t})\n\tconst resolved = resolvePhoneOptionsSafe({ fieldOptions: phoneOptions, payload: req.payload })\n\t// cellFormat belongs to the list cell and validation is decided server-side; shipping\n\t// either would put a value in every field's clientProps that nothing there may read.\n\tconst { cellFormat, validation, ...clientOptions } = resolved\n\n\t// Metadata is free here and lazy on the client, so the split row is derived once on the\n\t// server and handed over: without it the first client frame paints the raw E.164 and reflows.\n\tconst raw = 'name' in field ? storedNumber(siblingData, String(field.name)) : ''\n\tlet seed: null | PhoneSeed = null\n\tif (raw !== '') {\n\t\ttry {\n\t\t\tconst metadata = await loadMetadata(resolved.metadata)\n\t\t\tseed = phoneSeed(raw, { defaultCountry: resolved.defaultCountry, 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 field seed'\n\t\t\t)\n\t\t\t// The seed is an optimization; a failed load degrades the first frame, never the view\n\t\t\tseed = null\n\t\t}\n\t}\n\n\treturn (\n\t\t<PhoneNumberField\n\t\t\tfield={clientField}\n\t\t\tpath={path}\n\t\t\tpermissions={permissions}\n\t\t\tphoneOptions={clientOptions}\n\t\t\treadOnly={readOnly}\n\t\t\tseed={seed}\n\t\t/>\n\t)\n}\n"],"mappings":";;;;;;;;AAaA,MAAM,gBAAgB,SAAkB,SAAyB;CAChE,IAAI,OAAO,YAAY,YAAY,YAAY,MAAM,OAAO;CAC5D,MAAM,MAAO,QAAoC;CACjD,IAAI,OAAO,QAAQ,UAAU,OAAO;CACpC,IAAI,OAAO,QAAQ,YAAY,QAAQ,MAAM,OAAO;CACpD,MAAM,QAAS,IAAgC;CAC/C,OAAO,OAAO,UAAU,WAAW,QAAQ;AAC5C;;;;;;AAOA,MAAa,yBAAyB,OAAO,UAAgD;CAC5F,MAAM,EAAE,aAAa,OAAO,MAAM,aAAa,UAAU,KAAK,gBAAgB;CAM9E,MAAM,WAAW,wBAAwB;EAAE,cALtB,iBAAiB;GACrC,WAAW;GACX;GACA,aAAa,MAAM;EACpB,CACoE;EAAG,SAAS,IAAI;CAAQ,CAAC;CAG7F,MAAM,EAAE,YAAY,YAAY,GAAG,kBAAkB;CAIrD,MAAM,MAAM,UAAU,QAAQ,aAAa,aAAa,OAAO,MAAM,IAAI,CAAC,IAAI;CAC9E,IAAI,OAAyB;CAC7B,IAAI,QAAQ,IACX,IAAI;EACH,MAAM,WAAW,MAAM,aAAa,SAAS,QAAQ;EACrD,OAAO,UAAU,KAAK;GAAE,gBAAgB,SAAS;GAAgB;EAAS,CAAC;CAC5E,SAAS,OAAO;EACf,IAAI,QAAQ,OAAO,MAClB,EAAE,KAAK,MAAM,GACb,+DACD;EAEA,OAAO;CACR;CAGD,OACC,oBAAC,kBAAD;EACC,OAAO;EACD;EACO;EACb,cAAc;EACJ;EACJ;CACN,CAAA;AAEH"}
@@ -0,0 +1,51 @@
1
+ import { FLAGS_PATH } from "../options.js";
2
+ //#region src/fields/phoneNumber/server/flagsEndpoint.ts
3
+ const FLAGS_ENDPOINT_PATH = `${FLAGS_PATH}/:code`;
4
+ let loading;
5
+ /**
6
+ * Every flag the package ships, imported once per process and held as plain SVG strings.
7
+ * Deferred rather than imported at module scope: the entry point is a barrel over roughly
8
+ * 266 one-line modules, and at module scope that graph would be pulled into every route
9
+ * that loads the Payload config, for a route most requests never touch. A rejected import
10
+ * is evicted from the cache so a later request retries instead of inheriting the failure.
11
+ */
12
+ const flagsByCode = () => {
13
+ loading ??= import("country-flag-icons/string/3x2").then((module) => new Map(Object.entries(module))).catch((err) => {
14
+ loading = void 0;
15
+ throw err;
16
+ });
17
+ return loading;
18
+ };
19
+ const CODE = /^[A-Za-z]{2}$/;
20
+ const SVG_HEADERS = {
21
+ "Content-Type": "image/svg+xml; charset=utf-8",
22
+ "Cache-Control": "public, max-age=31536000, immutable",
23
+ "X-Content-Type-Options": "nosniff",
24
+ "Content-Security-Policy": "default-src 'none'; style-src 'unsafe-inline'"
25
+ };
26
+ /**
27
+ * Public GET serving one country flag as SVG, from `country-flag-icons`, so the admin
28
+ * bundle carries no flag artwork and no client-side flag dependency.
29
+ *
30
+ * Unauthenticated on purpose: a flag is public, static artwork, identical for every
31
+ * caller, and the handler reads only the in-process map above, touching no database, no
32
+ * user, and no request scope. This diverges from this package's `ICON_MANIFEST_PATH`,
33
+ * which is auth-gated because it exposes per-tenant configuration; the difference here
34
+ * is deliberate, not an oversight.
35
+ */
36
+ const makeFlagsHandler = () => async (req) => {
37
+ const raw = req.routeParams?.code;
38
+ const param = typeof raw === "string" ? raw : "";
39
+ const code = param.endsWith(".svg") ? param.slice(0, -4) : param;
40
+ if (!CODE.test(code)) return new Response("Bad Request", { status: 400 });
41
+ const svg = (await flagsByCode()).get(code.toUpperCase());
42
+ if (svg === void 0) return new Response("Not Found", { status: 404 });
43
+ return new Response(svg, {
44
+ headers: SVG_HEADERS,
45
+ status: 200
46
+ });
47
+ };
48
+ //#endregion
49
+ export { FLAGS_ENDPOINT_PATH, makeFlagsHandler };
50
+
51
+ //# sourceMappingURL=flagsEndpoint.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"flagsEndpoint.js","names":[],"sources":["../../../../src/fields/phoneNumber/server/flagsEndpoint.ts"],"sourcesContent":["import type { PayloadHandler } from 'payload'\nimport { FLAGS_PATH } from '../options'\n\nexport const FLAGS_ENDPOINT_PATH = `${FLAGS_PATH}/:code`\n\nlet loading: Promise<Map<string, string>> | undefined\n\n/**\n * Every flag the package ships, imported once per process and held as plain SVG strings.\n * Deferred rather than imported at module scope: the entry point is a barrel over roughly\n * 266 one-line modules, and at module scope that graph would be pulled into every route\n * that loads the Payload config, for a route most requests never touch. A rejected import\n * is evicted from the cache so a later request retries instead of inheriting the failure.\n */\nconst flagsByCode = (): Promise<Map<string, string>> => {\n\tloading ??= import('country-flag-icons/string/3x2')\n\t\t.then((module) => new Map<string, string>(Object.entries(module)))\n\t\t.catch((err: unknown) => {\n\t\t\tloading = undefined\n\t\t\tthrow err\n\t\t})\n\treturn loading\n}\n\nconst CODE = /^[A-Za-z]{2}$/\n\nconst SVG_HEADERS: Record<string, string> = {\n\t'Content-Type': 'image/svg+xml; charset=utf-8',\n\t// The URL is the version: a flag only changes in a new package release, so the\n\t// answer never needs revalidating.\n\t'Cache-Control': 'public, max-age=31536000, immutable',\n\t'X-Content-Type-Options': 'nosniff',\n\t// Opened directly rather than through an <img>, an SVG is a document that can run\n\t// script. This one is denied everything but the inline style the artwork needs.\n\t'Content-Security-Policy': \"default-src 'none'; style-src 'unsafe-inline'\",\n}\n\n/**\n * Public GET serving one country flag as SVG, from `country-flag-icons`, so the admin\n * bundle carries no flag artwork and no client-side flag dependency.\n *\n * Unauthenticated on purpose: a flag is public, static artwork, identical for every\n * caller, and the handler reads only the in-process map above, touching no database, no\n * user, and no request scope. This diverges from this package's `ICON_MANIFEST_PATH`,\n * which is auth-gated because it exposes per-tenant configuration; the difference here\n * is deliberate, not an oversight.\n */\nexport const makeFlagsHandler = (): PayloadHandler => async (req) => {\n\tconst raw = req.routeParams?.code\n\tconst param = typeof raw === 'string' ? raw : ''\n\tconst code = param.endsWith('.svg') ? param.slice(0, -'.svg'.length) : param\n\t// Checked before the artwork is loaded, so a malformed code costs nothing at all.\n\tif (!CODE.test(code)) {\n\t\treturn new Response('Bad Request', { status: 400 })\n\t}\n\tconst svg = (await flagsByCode()).get(code.toUpperCase())\n\tif (svg === undefined) {\n\t\treturn new Response('Not Found', { status: 404 })\n\t}\n\treturn new Response(svg, { headers: SVG_HEADERS, status: 200 })\n}\n"],"mappings":";;AAGA,MAAa,sBAAsB,GAAG,WAAW;AAEjD,IAAI;;;;;;;;AASJ,MAAM,oBAAkD;CACvD,YAAY,OAAO,iCACjB,MAAM,WAAW,IAAI,IAAoB,OAAO,QAAQ,MAAM,CAAC,CAAC,EAChE,OAAO,QAAiB;EACxB,UAAU,KAAA;EACV,MAAM;CACP,CAAC;CACF,OAAO;AACR;AAEA,MAAM,OAAO;AAEb,MAAM,cAAsC;CAC3C,gBAAgB;CAGhB,iBAAiB;CACjB,0BAA0B;CAG1B,2BAA2B;AAC5B;;;;;;;;;;;AAYA,MAAa,yBAAyC,OAAO,QAAQ;CACpE,MAAM,MAAM,IAAI,aAAa;CAC7B,MAAM,QAAQ,OAAO,QAAQ,WAAW,MAAM;CAC9C,MAAM,OAAO,MAAM,SAAS,MAAM,IAAI,MAAM,MAAM,GAAG,EAAc,IAAI;CAEvE,IAAI,CAAC,KAAK,KAAK,IAAI,GAClB,OAAO,IAAI,SAAS,eAAe,EAAE,QAAQ,IAAI,CAAC;CAEnD,MAAM,OAAO,MAAM,YAAY,GAAG,IAAI,KAAK,YAAY,CAAC;CACxD,IAAI,QAAQ,KAAA,GACX,OAAO,IAAI,SAAS,aAAa,EAAE,QAAQ,IAAI,CAAC;CAEjD,OAAO,IAAI,SAAS,KAAK;EAAE,SAAS;EAAa,QAAQ;CAAI,CAAC;AAC/D"}
@@ -0,0 +1,18 @@
1
+ import { PHONE_CUSTOM_KEY } from "../options.js";
2
+ //#region src/fields/phoneNumber/server/readPhoneOptions.ts
3
+ /**
4
+ * The field's own stamped option layer: the clientProp the factory threads through, or the
5
+ * `custom` key a hand-authored config carries instead. Still unresolved, so the caller has
6
+ * to put it through `resolvePhoneOptionsSafe` before rendering any chrome from it.
7
+ */
8
+ const readPhoneOptions = (args) => {
9
+ const { component, field, propOptions } = args;
10
+ const options = propOptions ?? field.custom?.["@10x-media/fields"];
11
+ if (options) return options;
12
+ const name = field.name === void 0 ? "" : String(field.name);
13
+ throw new Error(`${component}: field "${name}" has no phoneOptions clientProp and no custom['${PHONE_CUSTOM_KEY}']`);
14
+ };
15
+ //#endregion
16
+ export { readPhoneOptions };
17
+
18
+ //# sourceMappingURL=readPhoneOptions.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readPhoneOptions.js","names":[],"sources":["../../../../src/fields/phoneNumber/server/readPhoneOptions.ts"],"sourcesContent":["import { PHONE_CUSTOM_KEY, type ResolvablePhoneFieldOptions } from '../options'\n\n/** Both phone server components read the same two places, so they read them the same way. */\ntype PhoneOptionsSource = { custom?: Record<string, unknown>; name?: unknown }\n\n/**\n * The field's own stamped option layer: the clientProp the factory threads through, or the\n * `custom` key a hand-authored config carries instead. Still unresolved, so the caller has\n * to put it through `resolvePhoneOptionsSafe` before rendering any chrome from it.\n */\nexport const readPhoneOptions = (args: {\n\tcomponent: string\n\tfield: PhoneOptionsSource\n\tpropOptions: ResolvablePhoneFieldOptions | undefined\n}): ResolvablePhoneFieldOptions => {\n\tconst { component, field, propOptions } = args\n\tconst options =\n\t\tpropOptions ?? (field.custom?.[PHONE_CUSTOM_KEY] as ResolvablePhoneFieldOptions | undefined)\n\tif (options) return options\n\tconst name = field.name === undefined ? '' : String(field.name)\n\tthrow new Error(\n\t\t`${component}: field \"${name}\" has no phoneOptions clientProp and no custom['${PHONE_CUSTOM_KEY}']`\n\t)\n}\n"],"mappings":";;;;;;;AAUA,MAAa,oBAAoB,SAIE;CAClC,MAAM,EAAE,WAAW,OAAO,gBAAgB;CAC1C,MAAM,UACL,eAAgB,MAAM,SAAA;CACvB,IAAI,SAAS,OAAO;CACpB,MAAM,OAAO,MAAM,SAAS,KAAA,IAAY,KAAK,OAAO,MAAM,IAAI;CAC9D,MAAM,IAAI,MACT,GAAG,UAAU,WAAW,KAAK,kDAAkD,iBAAiB,GACjG;AACD"}