@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
package/CHANGELOG.md CHANGED
@@ -1,5 +1,20 @@
1
1
  # @10x-media/fields
2
2
 
3
+ ## 0.1.0-beta.8
4
+
5
+ ### Minor Changes
6
+
7
+ - Add `phoneNumberField()`: an international phone number field with a searchable country picker, live as-you-type formatting, and validation and metadata sized to the install via `libphonenumber-js`.
8
+
9
+ - Two storage shapes: `storage: 'object'` (default) is a `group` of `number` + `country`, plus five `virtual: true` subfields (`national`, `international`, `callingCode`, `uri`, `type`) recomputed on every read by a single `afterRead` hook; `storage: 'e164'` is a plain `text` field holding the E.164 string alone. Virtual subfields can't be queried or sorted; filter and sort on `number` or `country` instead.
10
+ - Three validation modes (`'possible'`, `'valid'`, `'mobile'`) and three metadata sets (`'max'`, `'min'`, `'mobile'`) trading bundle size for classification detail. `validation: 'mobile'` needs metadata `'max'` or `'mobile'`; pairing it with `'min'` is rejected as a configuration error rather than silently failing every number, at plugin build time when set on the plugin and at validation time when set on a field.
11
+ - Country handling: `countries` scopes the picker without restricting what parses, validates, and saves; `priorityCountries` pins a subset above the alphabetized rest, optionally headed by `priorityCountriesLabel` (a string or per-locale map; no label means no heading, only the picker's own group divider); `defaultCountry` seeds the picker and calling-code prefix.
12
+ - Flag artwork: `flags: 'svg'` (default) serves real country flags from a new, unauthenticated `/10x-fields/flags/:code` endpoint; `'emoji'` draws a Unicode regional-indicator pair instead (renders as two separate letters on Windows, which ships no flag emoji font); `'none'` shows the ISO code. `fields({ phoneNumber: { serveFlags: false } })` skips mounting the endpoint. `@10x-media/fields/phone` exports `countryFlagSrc(serverURL, apiRoute, code)` so a frontend can build the same URL without hand-rolling its lowercasing and `.svg` suffix.
13
+ - `fields({ phoneNumber: {...} })` sets install-wide defaults (`defaultCountry`, `countries`, `priorityCountries`, `priorityCountriesLabel`, `validation`, `flags`, `cellFormat`, `metadata`, `serveFlags`); a field's own option always wins.
14
+ - `@10x-media/fields/phone/utils` exports the parsing, formatting, and validation engine standalone for frontend use (`parsePhone`, `formatPhone`, `phoneUri`, `detectCountry`, `salvagePhone`, `checkPhone`, `formatAsYouType`, `countryOptions`, `callingCodeFor`, `emojiFlag`, `isKnownCountry`, `isSupported`, `loadMetadata`).
15
+
16
+ Additive: new phone number field family; no changes to any existing field, option, export, or storage shape.
17
+
3
18
  ## 0.1.0-beta.7
4
19
 
5
20
  ### Minor Changes
package/LICENSE CHANGED
@@ -1,21 +1,21 @@
1
- MIT License
2
-
3
- Copyright (c) 2026 10x Media GmbH
4
-
5
- Permission is hereby granted, free of charge, to any person obtaining a copy
6
- of this software and associated documentation files (the "Software"), to deal
7
- in the Software without restriction, including without limitation the rights
8
- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
- copies of the Software, and to permit persons to whom the Software is
10
- furnished to do so, subject to the following conditions:
11
-
12
- The above copyright notice and this permission notice shall be included in all
13
- copies or substantial portions of the Software.
14
-
15
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
- SOFTWARE.
1
+ MIT License
2
+
3
+ Copyright (c) 2026 10x Media GmbH
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -7,4 +7,7 @@ import { IconLibrarySelect } from "../fields/icon/client/IconLibrarySelect.js";
7
7
  import { MeasurementCell, MeasurementCellProps } from "../fields/measurement/client/MeasurementCell.js";
8
8
  import { MeasurementField, MeasurementFieldProps } from "../fields/measurement/client/MeasurementField.js";
9
9
  import { MeasurementUnitsProvider, useMeasurementUnits } from "../fields/measurement/client/MeasurementUnitsProvider.js";
10
- export { ColorField, type ColorFieldProps, ColorPickerPanel, IconField, IconLibrarySelect, MeasurementCell, type MeasurementCellProps, MeasurementField, type MeasurementFieldProps, MeasurementUnitsProvider, ProtectedField, RichTextRevealGate, useMeasurementUnits };
10
+ import { CountryFlag, CountryFlagProps } from "../fields/phoneNumber/client/CountryFlag.js";
11
+ import { CountryOptionGroups, CountryPicker, CountryPickerProps } from "../fields/phoneNumber/client/CountryPicker.js";
12
+ import { PhoneNumberField, PhoneNumberFieldProps } from "../fields/phoneNumber/client/PhoneNumberField.js";
13
+ export { ColorField, type ColorFieldProps, ColorPickerPanel, CountryFlag, type CountryFlagProps, type CountryOptionGroups, CountryPicker, type CountryPickerProps, IconField, IconLibrarySelect, MeasurementCell, type MeasurementCellProps, MeasurementField, type MeasurementFieldProps, MeasurementUnitsProvider, PhoneNumberField, type PhoneNumberFieldProps, ProtectedField, RichTextRevealGate, useMeasurementUnits };
@@ -8,4 +8,7 @@ import { IconLibrarySelect } from "../fields/icon/client/IconLibrarySelect.js";
8
8
  import { MeasurementUnitsProvider, useMeasurementUnits } from "../fields/measurement/client/MeasurementUnitsProvider.js";
9
9
  import { MeasurementCell } from "../fields/measurement/client/MeasurementCell.js";
10
10
  import { MeasurementField } from "../fields/measurement/client/MeasurementField.js";
11
- export { ColorField, ColorPickerPanel, IconField, IconLibrarySelect, MeasurementCell, MeasurementField, MeasurementUnitsProvider, ProtectedField, RichTextRevealGate, useMeasurementUnits };
11
+ import { CountryFlag } from "../fields/phoneNumber/client/CountryFlag.js";
12
+ import { CountryPicker } from "../fields/phoneNumber/client/CountryPicker.js";
13
+ import { PhoneNumberField } from "../fields/phoneNumber/client/PhoneNumberField.js";
14
+ export { ColorField, ColorPickerPanel, CountryFlag, CountryPicker, IconField, IconLibrarySelect, MeasurementCell, MeasurementField, MeasurementUnitsProvider, PhoneNumberField, ProtectedField, RichTextRevealGate, useMeasurementUnits };
@@ -0,0 +1,4 @@
1
+ import { DEFAULT_METADATA_SET, MetadataSet, PhoneMetadata, loadMetadata } from "../fields/phoneNumber/engine/metadata.js";
2
+ import { CountryCode, ParsedPhone, PhoneCheck, PhoneFormat, PhoneOptions, PhoneValidationMode, checkPhone, detectCountry, formatAsYouType, formatPhone, parsePhone, phoneUri, salvagePhone } from "../fields/phoneNumber/engine/phone.js";
3
+ import { CountryOption, KNOWN_COUNTRY_CODES, callingCodeFor, countryOptions, emojiFlag, isKnownCountry, isSupported } from "../fields/phoneNumber/engine/countries.js";
4
+ export { type CountryCode, type CountryOption, DEFAULT_METADATA_SET, KNOWN_COUNTRY_CODES, type MetadataSet, type ParsedPhone, type PhoneCheck, type PhoneFormat, type PhoneMetadata, type PhoneOptions, type PhoneValidationMode, callingCodeFor, checkPhone, countryOptions, detectCountry, emojiFlag, formatAsYouType, formatPhone, isKnownCountry, isSupported, loadMetadata, parsePhone, phoneUri, salvagePhone };
@@ -0,0 +1,4 @@
1
+ import { KNOWN_COUNTRY_CODES, callingCodeFor, countryOptions, emojiFlag, isKnownCountry, isSupported } from "../fields/phoneNumber/engine/countries.js";
2
+ import { DEFAULT_METADATA_SET, loadMetadata } from "../fields/phoneNumber/engine/metadata.js";
3
+ import { checkPhone, detectCountry, formatAsYouType, formatPhone, parsePhone, phoneUri, salvagePhone } from "../fields/phoneNumber/engine/phone.js";
4
+ export { DEFAULT_METADATA_SET, KNOWN_COUNTRY_CODES, callingCodeFor, checkPhone, countryOptions, detectCountry, emojiFlag, formatAsYouType, formatPhone, isKnownCountry, isSupported, loadMetadata, parsePhone, phoneUri, salvagePhone };
@@ -0,0 +1,6 @@
1
+ import { MetadataSet } from "../fields/phoneNumber/engine/metadata.js";
2
+ import { CountryCode, PhoneFormat, PhoneValidationMode } from "../fields/phoneNumber/engine/phone.js";
3
+ import { AnyPhoneNumberFieldOptions, FLAGS_PATH, PHONE_CUSTOM_KEY, PhoneFlagMode, PhoneNumberE164FieldOptions, PhoneNumberFieldOptions, PhoneStorageMode, ResolvablePhoneFieldOptions, ResolvedPhoneOptions, countryFlagSrc } from "../fields/phoneNumber/options.js";
4
+ import { PhoneNumberGlobalConfig } from "../types.js";
5
+ import { phoneNumberField } from "../fields/phoneNumber/phoneNumberField.js";
6
+ export { type AnyPhoneNumberFieldOptions, type CountryCode, FLAGS_PATH, type MetadataSet, PHONE_CUSTOM_KEY, type PhoneFlagMode, type PhoneFormat, type PhoneNumberE164FieldOptions, type PhoneNumberFieldOptions, type PhoneNumberGlobalConfig, type PhoneStorageMode, type PhoneValidationMode, type ResolvablePhoneFieldOptions, type ResolvedPhoneOptions, countryFlagSrc, phoneNumberField };
@@ -0,0 +1,3 @@
1
+ import { FLAGS_PATH, PHONE_CUSTOM_KEY, countryFlagSrc } from "../fields/phoneNumber/options.js";
2
+ import { phoneNumberField } from "../fields/phoneNumber/phoneNumberField.js";
3
+ export { FLAGS_PATH, PHONE_CUSTOM_KEY, countryFlagSrc, phoneNumberField };
@@ -9,4 +9,6 @@ import { IconFieldServer } from "../fields/icon/rsc/IconFieldServer.js";
9
9
  import { IconLibrarySelectServer } from "../fields/icon/rsc/IconLibrarySelectServer.js";
10
10
  import { MeasurementCellServer } from "../fields/measurement/server/MeasurementCellServer.js";
11
11
  import { MeasurementFieldServer } from "../fields/measurement/server/MeasurementFieldServer.js";
12
- export { ColorCell, ColorFieldServer, type FieldsPluginRegistry, IconCell, IconFieldServer, IconLibrarySelectServer, MeasurementCellServer, MeasurementFieldServer, ProtectedCell, ProtectedRichText, createRscIcon };
12
+ import { PhoneNumberCellServer } from "../fields/phoneNumber/server/PhoneNumberCellServer.js";
13
+ import { PhoneNumberFieldServer } from "../fields/phoneNumber/server/PhoneNumberFieldServer.js";
14
+ export { ColorCell, ColorFieldServer, type FieldsPluginRegistry, IconCell, IconFieldServer, IconLibrarySelectServer, MeasurementCellServer, MeasurementFieldServer, PhoneNumberCellServer, PhoneNumberFieldServer, ProtectedCell, ProtectedRichText, createRscIcon };
@@ -8,4 +8,6 @@ import { IconFieldServer } from "../fields/icon/rsc/IconFieldServer.js";
8
8
  import { IconLibrarySelectServer } from "../fields/icon/rsc/IconLibrarySelectServer.js";
9
9
  import { MeasurementCellServer } from "../fields/measurement/server/MeasurementCellServer.js";
10
10
  import { MeasurementFieldServer } from "../fields/measurement/server/MeasurementFieldServer.js";
11
- export { ColorCell, ColorFieldServer, IconCell, IconFieldServer, IconLibrarySelectServer, MeasurementCellServer, MeasurementFieldServer, ProtectedCell, ProtectedRichText, createRscIcon };
11
+ import { PhoneNumberCellServer } from "../fields/phoneNumber/server/PhoneNumberCellServer.js";
12
+ import { PhoneNumberFieldServer } from "../fields/phoneNumber/server/PhoneNumberFieldServer.js";
13
+ export { ColorCell, ColorFieldServer, IconCell, IconFieldServer, IconLibrarySelectServer, MeasurementCellServer, MeasurementFieldServer, PhoneNumberCellServer, PhoneNumberFieldServer, ProtectedCell, ProtectedRichText, createRscIcon };
@@ -1,4 +1,5 @@
1
- import { ColorFormat, ColorGlobalConfig, ColorPreset, DecryptFailurePolicy, EncryptedGlobalConfig, FieldsPluginRegistry, FieldsResolverArgs, IconAdapter, IconGlobalConfig, IconManifest, IconMeta, IconNode, IconNodeMap, KeysConfig } from "../types.js";
1
+ import { AnyPhoneNumberFieldOptions, PhoneFlagMode, PhoneNumberE164FieldOptions, PhoneNumberFieldOptions, PhoneStorageMode, ResolvablePhoneFieldOptions, ResolvedPhoneOptions } from "../fields/phoneNumber/options.js";
2
+ import { ColorFormat, ColorGlobalConfig, ColorPreset, DecryptFailurePolicy, EncryptedGlobalConfig, FieldsPluginRegistry, FieldsResolverArgs, IconAdapter, IconGlobalConfig, IconManifest, IconMeta, IconNode, IconNodeMap, KeysConfig, PhoneNumberGlobalConfig } from "../types.js";
2
3
  import { ColorFieldClientOptions, ColorFieldOptions, ColorLinkedOptions, ColorPresetsResolver, ColorPresetsSource, ResolvedColorPreset } from "../fields/color/options.js";
3
4
  import { FieldsPluginOptions } from "../index.js";
4
- export type { ColorFieldClientOptions, ColorFieldOptions, ColorFormat, ColorGlobalConfig, ColorLinkedOptions, ColorPreset, ColorPresetsResolver, ColorPresetsSource, DecryptFailurePolicy, EncryptedGlobalConfig, FieldsPluginOptions, FieldsPluginRegistry, FieldsResolverArgs, IconAdapter, IconGlobalConfig, IconManifest, IconMeta, IconNode, IconNodeMap, KeysConfig, ResolvedColorPreset };
5
+ export type { AnyPhoneNumberFieldOptions, ColorFieldClientOptions, ColorFieldOptions, ColorFormat, ColorGlobalConfig, ColorLinkedOptions, ColorPreset, ColorPresetsResolver, ColorPresetsSource, DecryptFailurePolicy, EncryptedGlobalConfig, FieldsPluginOptions, FieldsPluginRegistry, FieldsResolverArgs, IconAdapter, IconGlobalConfig, IconManifest, IconMeta, IconNode, IconNodeMap, KeysConfig, PhoneFlagMode, PhoneNumberE164FieldOptions, PhoneNumberFieldOptions, PhoneNumberGlobalConfig, PhoneStorageMode, ResolvablePhoneFieldOptions, ResolvedColorPreset, ResolvedPhoneOptions };
@@ -1,6 +1,6 @@
1
1
  import { getFieldsRegistry } from "../../../plugin/registry.js";
2
2
  import { resolveAvailableLibraries, unionAlwaysAvailable } from "../server/availability.js";
3
- import { resolveStaticLabel } from "../shared/resolveStaticLabel.js";
3
+ import { resolveStaticLabel } from "../../../utils/resolveStaticLabel.js";
4
4
  import { resolveIconValue } from "../shared/value.js";
5
5
  import { IconField } from "../client/IconFieldClient.js";
6
6
  import { resolveIconMeta } from "../server/resolveIconMeta.js";
@@ -1 +1 @@
1
- {"version":3,"file":"IconFieldServer.js","names":[],"sources":["../../../../src/fields/icon/rsc/IconFieldServer.tsx"],"sourcesContent":["import type { TextFieldServerProps } from 'payload'\nimport { getFromImportMap } from 'payload/shared'\nimport type { ReactNode } from 'react'\nimport { getFieldsRegistry } from '../../../plugin/registry'\nimport type { IconAdapter, IconAvailabilityResolver } from '../../../types'\nimport { IconField } from '../client/IconFieldClient'\nimport { resolveAvailableLibraries, unionAlwaysAvailable } from '../server/availability'\nimport { resolveIconMeta } from '../server/resolveIconMeta'\nimport type { AdapterComponentsEntry } from '../shared/adapterComponents'\nimport { resolveStaticLabel } from '../shared/resolveStaticLabel'\nimport { resolveIconValue } from '../shared/value'\n\ntype IconFieldServerExtraProps = {\n\tadapters?: IconAdapter[]\n\talwaysAvailable?: string[]\n\tdefaultLibrary?: string\n\tresolveAvailable?: IconAvailabilityResolver\n\tshowTextInput?: boolean\n}\n\ntype ServerProps = IconFieldServerExtraProps & TextFieldServerProps\n\n/**\n * Resolves adapters (inline beats registry), availability (memoized per request,\n * fails open), and adapter client components from the importMap, then renders the\n * client field with those component references as props. A missing importMap entry\n * degrades to no glyph for that library rather than throwing, so the edit view\n * never 500s over a mis-registered adapter.\n */\nexport const IconFieldServer = async (props: ServerProps): Promise<ReactNode> => {\n\tconst {\n\t\tclientField,\n\t\tdata,\n\t\ti18n,\n\t\tpath,\n\t\tpayload,\n\t\tpermissions,\n\t\treadOnly,\n\t\treq,\n\t\tschemaPath,\n\t\tsiblingData,\n\t} = props\n\tconst registryIcon = getFieldsRegistry(payload.config)?.icon\n\tconst adapters = props.adapters ?? registryIcon?.adapters ?? []\n\tconst defaultLibrary =\n\t\tprops.defaultLibrary ?? registryIcon?.defaultLibrary ?? adapters[0]?.slug ?? ''\n\tconst resolver = props.resolveAvailable ?? registryIcon?.resolveAvailable\n\tconst alwaysAvailable = unionAlwaysAvailable(props.alwaysAvailable, registryIcon?.alwaysAvailable)\n\n\tconst available = await resolveAvailableLibraries({\n\t\tadapters,\n\t\talwaysAvailable,\n\t\tdata: data as Record<string, unknown> | undefined,\n\t\treq,\n\t\tresolver,\n\t\tsiblingData: siblingData as Record<string, unknown> | undefined,\n\t})\n\n\tconst adapterComponents: Record<string, AdapterComponentsEntry> = {}\n\tfor (const adapter of adapters) {\n\t\tconst Icon = getFromImportMap<AdapterComponentsEntry['Icon']>({\n\t\t\timportMap: payload.importMap,\n\t\t\tPayloadComponent: adapter.Icon,\n\t\t\tschemaPath: `${schemaPath ?? path}.icon-adapter`,\n\t\t\tsilent: true,\n\t\t})\n\t\tconst Assets = getFromImportMap<AdapterComponentsEntry['Assets']>({\n\t\t\timportMap: payload.importMap,\n\t\t\tPayloadComponent: adapter.Assets,\n\t\t\tschemaPath: `${schemaPath ?? path}.icon-adapter`,\n\t\t\tsilent: true,\n\t\t})\n\t\t// Optional: libraries with bulk node-data (lucide, tabler) resolve a Nodes\n\t\t// loader so the drawer renders glyphs inline; radix omits it and falls back\n\t\t// to the per-icon Icon component.\n\t\tconst Nodes = adapter.Nodes\n\t\t\t? getFromImportMap<NonNullable<AdapterComponentsEntry['Nodes']>>({\n\t\t\t\t\timportMap: payload.importMap,\n\t\t\t\t\tPayloadComponent: adapter.Nodes,\n\t\t\t\t\tschemaPath: `${schemaPath ?? path}.icon-adapter`,\n\t\t\t\t\tsilent: true,\n\t\t\t\t})\n\t\t\t: undefined\n\t\tif (Icon && Assets)\n\t\t\tadapterComponents[adapter.slug] = { Assets, canvas: adapter.canvas, Icon, Nodes }\n\t}\n\n\t// The trigger renders from a stored value alone, so a library-supplied label has to\n\t// arrive with it. A miss is not an error here: an unknown or removed icon still\n\t// renders, falling back to the name-derived label exactly as before.\n\tconst storedValue =\n\t\ttypeof siblingData?.[String(clientField.name)] === 'string'\n\t\t\t? (siblingData[String(clientField.name)] as string)\n\t\t\t: null\n\tlet selectedMeta = null\n\tif (storedValue !== null && storedValue !== '') {\n\t\tconst { library, name } = resolveIconValue(storedValue, defaultLibrary)\n\t\tconst adapter = adapters.find((candidate) => candidate.slug === library)\n\t\tif (adapter) selectedMeta = await resolveIconMeta(adapter, name, { payload, req })\n\t}\n\n\treturn (\n\t\t<IconField\n\t\t\tadapterComponents={adapterComponents}\n\t\t\tadapters={adapters.map((adapter) => ({\n\t\t\t\tlabel: resolveStaticLabel(adapter.label, i18n.language) ?? adapter.slug,\n\t\t\t\tslug: adapter.slug,\n\t\t\t}))}\n\t\t\tavailable={available}\n\t\t\tdefaultLibrary={defaultLibrary}\n\t\t\tfield={clientField}\n\t\t\tpath={path}\n\t\t\tpermissions={permissions}\n\t\t\treadOnly={readOnly}\n\t\t\tschemaPath={schemaPath}\n\t\t\tselectedMeta={selectedMeta}\n\t\t\tshowTextInput={props.showTextInput === true}\n\t\t/>\n\t)\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA6BA,MAAa,kBAAkB,OAAO,UAA2C;CAChF,MAAM,EACL,aACA,MACA,MACA,MACA,SACA,aACA,UACA,KACA,YACA,gBACG;CACJ,MAAM,eAAe,kBAAkB,QAAQ,MAAM,GAAG;CACxD,MAAM,WAAW,MAAM,YAAY,cAAc,YAAY,CAAC;CAC9D,MAAM,iBACL,MAAM,kBAAkB,cAAc,kBAAkB,SAAS,IAAI,QAAQ;CAC9E,MAAM,WAAW,MAAM,oBAAoB,cAAc;CAGzD,MAAM,YAAY,MAAM,0BAA0B;EACjD;EACA,iBAJuB,qBAAqB,MAAM,iBAAiB,cAAc,eAInE;EACR;EACN;EACA;EACa;CACd,CAAC;CAED,MAAM,oBAA4D,CAAC;CACnE,KAAK,MAAM,WAAW,UAAU;EAC/B,MAAM,OAAO,iBAAiD;GAC7D,WAAW,QAAQ;GACnB,kBAAkB,QAAQ;GAC1B,YAAY,GAAG,cAAc,KAAK;GAClC,QAAQ;EACT,CAAC;EACD,MAAM,SAAS,iBAAmD;GACjE,WAAW,QAAQ;GACnB,kBAAkB,QAAQ;GAC1B,YAAY,GAAG,cAAc,KAAK;GAClC,QAAQ;EACT,CAAC;EAID,MAAM,QAAQ,QAAQ,QACnB,iBAA+D;GAC/D,WAAW,QAAQ;GACnB,kBAAkB,QAAQ;GAC1B,YAAY,GAAG,cAAc,KAAK;GAClC,QAAQ;EACT,CAAC,IACA,KAAA;EACH,IAAI,QAAQ,QACX,kBAAkB,QAAQ,QAAQ;GAAE;GAAQ,QAAQ,QAAQ;GAAQ;GAAM;EAAM;CAClF;CAKA,MAAM,cACL,OAAO,cAAc,OAAO,YAAY,IAAI,OAAO,WAC/C,YAAY,OAAO,YAAY,IAAI,KACpC;CACJ,IAAI,eAAe;CACnB,IAAI,gBAAgB,QAAQ,gBAAgB,IAAI;EAC/C,MAAM,EAAE,SAAS,SAAS,iBAAiB,aAAa,cAAc;EACtE,MAAM,UAAU,SAAS,MAAM,cAAc,UAAU,SAAS,OAAO;EACvE,IAAI,SAAS,eAAe,MAAM,gBAAgB,SAAS,MAAM;GAAE;GAAS;EAAI,CAAC;CAClF;CAEA,OACC,oBAAC,WAAD;EACoB;EACnB,UAAU,SAAS,KAAK,aAAa;GACpC,OAAO,mBAAmB,QAAQ,OAAO,KAAK,QAAQ,KAAK,QAAQ;GACnE,MAAM,QAAQ;EACf,EAAE;EACS;EACK;EAChB,OAAO;EACD;EACO;EACH;EACE;EACE;EACd,eAAe,MAAM,kBAAkB;CACvC,CAAA;AAEH"}
1
+ {"version":3,"file":"IconFieldServer.js","names":[],"sources":["../../../../src/fields/icon/rsc/IconFieldServer.tsx"],"sourcesContent":["import type { TextFieldServerProps } from 'payload'\nimport { getFromImportMap } from 'payload/shared'\nimport type { ReactNode } from 'react'\nimport { getFieldsRegistry } from '../../../plugin/registry'\nimport type { IconAdapter, IconAvailabilityResolver } from '../../../types'\nimport { resolveStaticLabel } from '../../../utils/resolveStaticLabel'\nimport { IconField } from '../client/IconFieldClient'\nimport { resolveAvailableLibraries, unionAlwaysAvailable } from '../server/availability'\nimport { resolveIconMeta } from '../server/resolveIconMeta'\nimport type { AdapterComponentsEntry } from '../shared/adapterComponents'\nimport { resolveIconValue } from '../shared/value'\n\ntype IconFieldServerExtraProps = {\n\tadapters?: IconAdapter[]\n\talwaysAvailable?: string[]\n\tdefaultLibrary?: string\n\tresolveAvailable?: IconAvailabilityResolver\n\tshowTextInput?: boolean\n}\n\ntype ServerProps = IconFieldServerExtraProps & TextFieldServerProps\n\n/**\n * Resolves adapters (inline beats registry), availability (memoized per request,\n * fails open), and adapter client components from the importMap, then renders the\n * client field with those component references as props. A missing importMap entry\n * degrades to no glyph for that library rather than throwing, so the edit view\n * never 500s over a mis-registered adapter.\n */\nexport const IconFieldServer = async (props: ServerProps): Promise<ReactNode> => {\n\tconst {\n\t\tclientField,\n\t\tdata,\n\t\ti18n,\n\t\tpath,\n\t\tpayload,\n\t\tpermissions,\n\t\treadOnly,\n\t\treq,\n\t\tschemaPath,\n\t\tsiblingData,\n\t} = props\n\tconst registryIcon = getFieldsRegistry(payload.config)?.icon\n\tconst adapters = props.adapters ?? registryIcon?.adapters ?? []\n\tconst defaultLibrary =\n\t\tprops.defaultLibrary ?? registryIcon?.defaultLibrary ?? adapters[0]?.slug ?? ''\n\tconst resolver = props.resolveAvailable ?? registryIcon?.resolveAvailable\n\tconst alwaysAvailable = unionAlwaysAvailable(props.alwaysAvailable, registryIcon?.alwaysAvailable)\n\n\tconst available = await resolveAvailableLibraries({\n\t\tadapters,\n\t\talwaysAvailable,\n\t\tdata: data as Record<string, unknown> | undefined,\n\t\treq,\n\t\tresolver,\n\t\tsiblingData: siblingData as Record<string, unknown> | undefined,\n\t})\n\n\tconst adapterComponents: Record<string, AdapterComponentsEntry> = {}\n\tfor (const adapter of adapters) {\n\t\tconst Icon = getFromImportMap<AdapterComponentsEntry['Icon']>({\n\t\t\timportMap: payload.importMap,\n\t\t\tPayloadComponent: adapter.Icon,\n\t\t\tschemaPath: `${schemaPath ?? path}.icon-adapter`,\n\t\t\tsilent: true,\n\t\t})\n\t\tconst Assets = getFromImportMap<AdapterComponentsEntry['Assets']>({\n\t\t\timportMap: payload.importMap,\n\t\t\tPayloadComponent: adapter.Assets,\n\t\t\tschemaPath: `${schemaPath ?? path}.icon-adapter`,\n\t\t\tsilent: true,\n\t\t})\n\t\t// Optional: libraries with bulk node-data (lucide, tabler) resolve a Nodes\n\t\t// loader so the drawer renders glyphs inline; radix omits it and falls back\n\t\t// to the per-icon Icon component.\n\t\tconst Nodes = adapter.Nodes\n\t\t\t? getFromImportMap<NonNullable<AdapterComponentsEntry['Nodes']>>({\n\t\t\t\t\timportMap: payload.importMap,\n\t\t\t\t\tPayloadComponent: adapter.Nodes,\n\t\t\t\t\tschemaPath: `${schemaPath ?? path}.icon-adapter`,\n\t\t\t\t\tsilent: true,\n\t\t\t\t})\n\t\t\t: undefined\n\t\tif (Icon && Assets)\n\t\t\tadapterComponents[adapter.slug] = { Assets, canvas: adapter.canvas, Icon, Nodes }\n\t}\n\n\t// The trigger renders from a stored value alone, so a library-supplied label has to\n\t// arrive with it. A miss is not an error here: an unknown or removed icon still\n\t// renders, falling back to the name-derived label exactly as before.\n\tconst storedValue =\n\t\ttypeof siblingData?.[String(clientField.name)] === 'string'\n\t\t\t? (siblingData[String(clientField.name)] as string)\n\t\t\t: null\n\tlet selectedMeta = null\n\tif (storedValue !== null && storedValue !== '') {\n\t\tconst { library, name } = resolveIconValue(storedValue, defaultLibrary)\n\t\tconst adapter = adapters.find((candidate) => candidate.slug === library)\n\t\tif (adapter) selectedMeta = await resolveIconMeta(adapter, name, { payload, req })\n\t}\n\n\treturn (\n\t\t<IconField\n\t\t\tadapterComponents={adapterComponents}\n\t\t\tadapters={adapters.map((adapter) => ({\n\t\t\t\tlabel: resolveStaticLabel(adapter.label, i18n.language) ?? adapter.slug,\n\t\t\t\tslug: adapter.slug,\n\t\t\t}))}\n\t\t\tavailable={available}\n\t\t\tdefaultLibrary={defaultLibrary}\n\t\t\tfield={clientField}\n\t\t\tpath={path}\n\t\t\tpermissions={permissions}\n\t\t\treadOnly={readOnly}\n\t\t\tschemaPath={schemaPath}\n\t\t\tselected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AAS,SAAS,iBAAiB,aAAa,cAAc;EACtE,MAAM,UAAU,SAAS,MAAM,cAAc,UAAU,SAAS,OAAO;EACvE,IAAI,SAAS,eAAe,MAAM,gBAAgB,SAAS,MAAM;GAAE;GAAS;EAAI,CAAC;CAClF;CAEA,OACC,oBAAC,WAAD;EACoB;EACnB,UAAU,SAAS,KAAK,aAAa;GACpC,OAAO,mBAAmB,QAAQ,OAAO,KAAK,QAAQ,KAAK,QAAQ;GACnE,MAAM,QAAQ;EACf,EAAE;EACS;EACK;EAChB,OAAO;EACD;EACO;EACH;EACE;EACE;EACd,eAAe,MAAM,kBAAkB;CACvC,CAAA;AAEH"}
@@ -1,4 +1,4 @@
1
- import { resolveStaticLabel } from "../shared/resolveStaticLabel.js";
1
+ import { resolveStaticLabel } from "../../../utils/resolveStaticLabel.js";
2
2
  import { IconLibrarySelect } from "../client/IconLibrarySelect.js";
3
3
  import { getIconLibraryOptions } from "../server/libraryOptions.js";
4
4
  import { jsx } from "react/jsx-runtime";
@@ -1 +1 @@
1
- {"version":3,"file":"IconLibrarySelectServer.js","names":[],"sources":["../../../../src/fields/icon/rsc/IconLibrarySelectServer.tsx"],"sourcesContent":["import type { TextFieldServerProps } from 'payload'\nimport type { ReactNode } from 'react'\nimport type { IconAdapter } from '../../../types'\nimport { IconLibrarySelect } from '../client/IconLibrarySelect'\nimport { getIconLibraryOptions } from '../server/libraryOptions'\nimport { resolveStaticLabel } from '../shared/resolveStaticLabel'\n\ntype ServerProps = { adapters?: IconAdapter[] } & TextFieldServerProps\n\n/** Resolves selectable library options (inline beats registry) and renders the client select. */\nexport const IconLibrarySelectServer = (props: ServerProps): ReactNode => {\n\tconst { clientField, i18n, path, payload, permissions, readOnly, schemaPath } = props\n\tconst options = getIconLibraryOptions(payload.config, props.adapters).map((option) => ({\n\t\tlabel: resolveStaticLabel(option.label, i18n.language) ?? option.value,\n\t\tvalue: option.value,\n\t}))\n\treturn (\n\t\t<IconLibrarySelect\n\t\t\tfield={clientField}\n\t\t\toptions={options}\n\t\t\tpath={path}\n\t\t\tpermissions={permissions}\n\t\t\treadOnly={readOnly}\n\t\t\tschemaPath={schemaPath}\n\t\t/>\n\t)\n}\n"],"mappings":";;;;;;AAUA,MAAa,2BAA2B,UAAkC;CACzE,MAAM,EAAE,aAAa,MAAM,MAAM,SAAS,aAAa,UAAU,eAAe;CAKhF,OACC,oBAAC,mBAAD;EACC,OAAO;EACP,SAPc,sBAAsB,QAAQ,QAAQ,MAAM,QAAQ,EAAE,KAAK,YAAY;GACtF,OAAO,mBAAmB,OAAO,OAAO,KAAK,QAAQ,KAAK,OAAO;GACjE,OAAO,OAAO;EACf,EAIiB;EACT;EACO;EACH;EACE;CACZ,CAAA;AAEH"}
1
+ {"version":3,"file":"IconLibrarySelectServer.js","names":[],"sources":["../../../../src/fields/icon/rsc/IconLibrarySelectServer.tsx"],"sourcesContent":["import type { TextFieldServerProps } from 'payload'\nimport type { ReactNode } from 'react'\nimport type { IconAdapter } from '../../../types'\nimport { resolveStaticLabel } from '../../../utils/resolveStaticLabel'\nimport { IconLibrarySelect } from '../client/IconLibrarySelect'\nimport { getIconLibraryOptions } from '../server/libraryOptions'\n\ntype ServerProps = { adapters?: IconAdapter[] } & TextFieldServerProps\n\n/** Resolves selectable library options (inline beats registry) and renders the client select. */\nexport const IconLibrarySelectServer = (props: ServerProps): ReactNode => {\n\tconst { clientField, i18n, path, payload, permissions, readOnly, schemaPath } = props\n\tconst options = getIconLibraryOptions(payload.config, props.adapters).map((option) => ({\n\t\tlabel: resolveStaticLabel(option.label, i18n.language) ?? option.value,\n\t\tvalue: option.value,\n\t}))\n\treturn (\n\t\t<IconLibrarySelect\n\t\t\tfield={clientField}\n\t\t\toptions={options}\n\t\t\tpath={path}\n\t\t\tpermissions={permissions}\n\t\t\treadOnly={readOnly}\n\t\t\tschemaPath={schemaPath}\n\t\t/>\n\t)\n}\n"],"mappings":";;;;;;AAUA,MAAa,2BAA2B,UAAkC;CACzE,MAAM,EAAE,aAAa,MAAM,MAAM,SAAS,aAAa,UAAU,eAAe;CAKhF,OACC,oBAAC,mBAAD;EACC,OAAO;EACP,SAPc,sBAAsB,QAAQ,QAAQ,MAAM,QAAQ,EAAE,KAAK,YAAY;GACtF,OAAO,mBAAmB,OAAO,OAAO,KAAK,QAAQ,KAAK,OAAO;GACjE,OAAO,OAAO;EACf,EAIiB;EACT;EACO;EACH;EACE;CACZ,CAAA;AAEH"}
@@ -1,5 +1,5 @@
1
+ import { resolveStaticLabel } from "../../../utils/resolveStaticLabel.js";
1
2
  import { formatIconLabel } from "./formatIconLabel.js";
2
- import { resolveStaticLabel } from "./resolveStaticLabel.js";
3
3
  //#region src/fields/icon/shared/iconLabel.ts
4
4
  /**
5
5
  * Resolves the display text for one icon. A library-supplied `label` wins; otherwise
@@ -1 +1 @@
1
- {"version":3,"file":"iconLabel.js","names":[],"sources":["../../../../src/fields/icon/shared/iconLabel.ts"],"sourcesContent":["import type { IconMeta } from '../../../types'\nimport { formatIconLabel } from './formatIconLabel'\nimport { resolveStaticLabel } from './resolveStaticLabel'\n\n/** What an editor sees for one icon: its accessible name, plus the raw name where that adds information. */\nexport type IconDisplayLabel = { code?: string; label: string }\n\n/**\n * Resolves the display text for one icon. A library-supplied `label` wins; otherwise\n * the name is sentence-cased as before, so every existing manifest is unaffected.\n *\n * `code` carries the raw name for surfaces that can show it alongside the label. It is\n * the only place an editor can learn that \"Hungary\" stores as `HUN`, which they need to\n * write frontend code, and it is deliberately kept out of the accessible name: a screen\n * reader announcing \"Hungary HUN\" across 215 cells is the defect this fixes.\n */\nexport const resolveIconDisplay = (args: {\n\tlanguage: string\n\tmeta?: IconMeta | null\n\tname: string\n}): IconDisplayLabel => {\n\tconst derived = formatIconLabel(args.name)\n\tconst supplied = resolveStaticLabel(args.meta?.label, args.language)\n\tif (!supplied) return { label: derived }\n\t// A code only earns its place when the label hides it. A label matching the name, or\n\t// matching what the name would have derived anyway, tells the editor nothing new.\n\tif (supplied === args.name || supplied === derived) return { label: supplied }\n\treturn { code: args.name, label: supplied }\n}\n"],"mappings":";;;;;;;;;;;;AAgBA,MAAa,sBAAsB,SAIX;CACvB,MAAM,UAAU,gBAAgB,KAAK,IAAI;CACzC,MAAM,WAAW,mBAAmB,KAAK,MAAM,OAAO,KAAK,QAAQ;CACnE,IAAI,CAAC,UAAU,OAAO,EAAE,OAAO,QAAQ;CAGvC,IAAI,aAAa,KAAK,QAAQ,aAAa,SAAS,OAAO,EAAE,OAAO,SAAS;CAC7E,OAAO;EAAE,MAAM,KAAK;EAAM,OAAO;CAAS;AAC3C"}
1
+ {"version":3,"file":"iconLabel.js","names":[],"sources":["../../../../src/fields/icon/shared/iconLabel.ts"],"sourcesContent":["import type { IconMeta } from '../../../types'\nimport { resolveStaticLabel } from '../../../utils/resolveStaticLabel'\nimport { formatIconLabel } from './formatIconLabel'\n\n/** What an editor sees for one icon: its accessible name, plus the raw name where that adds information. */\nexport type IconDisplayLabel = { code?: string; label: string }\n\n/**\n * Resolves the display text for one icon. A library-supplied `label` wins; otherwise\n * the name is sentence-cased as before, so every existing manifest is unaffected.\n *\n * `code` carries the raw name for surfaces that can show it alongside the label. It is\n * the only place an editor can learn that \"Hungary\" stores as `HUN`, which they need to\n * write frontend code, and it is deliberately kept out of the accessible name: a screen\n * reader announcing \"Hungary HUN\" across 215 cells is the defect this fixes.\n */\nexport const resolveIconDisplay = (args: {\n\tlanguage: string\n\tmeta?: IconMeta | null\n\tname: string\n}): IconDisplayLabel => {\n\tconst derived = formatIconLabel(args.name)\n\tconst supplied = resolveStaticLabel(args.meta?.label, args.language)\n\tif (!supplied) return { label: derived }\n\t// A code only earns its place when the label hides it. A label matching the name, or\n\t// matching what the name would have derived anyway, tells the editor nothing new.\n\tif (supplied === args.name || supplied === derived) return { label: supplied }\n\treturn { code: args.name, label: supplied }\n}\n"],"mappings":";;;;;;;;;;;;AAgBA,MAAa,sBAAsB,SAIX;CACvB,MAAM,UAAU,gBAAgB,KAAK,IAAI;CACzC,MAAM,WAAW,mBAAmB,KAAK,MAAM,OAAO,KAAK,QAAQ;CACnE,IAAI,CAAC,UAAU,OAAO,EAAE,OAAO,QAAQ;CAGvC,IAAI,aAAa,KAAK,QAAQ,aAAa,SAAS,OAAO,EAAE,OAAO,SAAS;CAC7E,OAAO;EAAE,MAAM,KAAK;EAAM,OAAO;CAAS;AAC3C"}
@@ -0,0 +1,16 @@
1
+ import { CountryCode } from "../engine/phone.js";
2
+ import { PhoneFlagMode } from "../options.js";
3
+ import React from "react";
4
+ //#region src/fields/phoneNumber/client/CountryFlag.d.ts
5
+ type CountryFlagProps = {
6
+ code: CountryCode;
7
+ mode: PhoneFlagMode;
8
+ };
9
+ /**
10
+ * Decorative in every mode: each trigger and row that carries a flag also carries the
11
+ * country's name, so the artwork stays out of the accessibility tree.
12
+ */
13
+ declare const CountryFlag: React.FC<CountryFlagProps>;
14
+ //#endregion
15
+ export { CountryFlag, CountryFlagProps };
16
+ //# sourceMappingURL=CountryFlag.d.ts.map
@@ -0,0 +1,40 @@
1
+ "use client";
2
+ import { emojiFlag } from "../engine/countries.js";
3
+ import { countryFlagSrc } from "../options.js";
4
+ import { useConfig } from "@payloadcms/ui";
5
+ import { useState } from "react";
6
+ import { jsx } from "react/jsx-runtime";
7
+ import "./phoneNumberField.css";
8
+ //#region src/fields/phoneNumber/client/CountryFlag.tsx
9
+ const baseClass = "fields-phone";
10
+ /**
11
+ * Decorative in every mode: each trigger and row that carries a flag also carries the
12
+ * country's name, so the artwork stays out of the accessibility tree.
13
+ */
14
+ const CountryFlag = ({ code, mode }) => {
15
+ const { config } = useConfig();
16
+ const [failedSrc, setFailedSrc] = useState(null);
17
+ if (mode === "none") return null;
18
+ if (mode === "emoji") return /* @__PURE__ */ jsx("span", {
19
+ "aria-hidden": "true",
20
+ className: `${baseClass}__flag ${baseClass}__flag--emoji`,
21
+ children: emojiFlag(code)
22
+ });
23
+ const src = countryFlagSrc(config.serverURL, config.routes.api, code);
24
+ return /* @__PURE__ */ jsx("img", {
25
+ alt: "",
26
+ "aria-hidden": "true",
27
+ className: `${baseClass}__flag`,
28
+ decoding: "async",
29
+ height: 15,
30
+ loading: "lazy",
31
+ onError: () => setFailedSrc(src),
32
+ src,
33
+ style: failedSrc === src ? { visibility: "hidden" } : void 0,
34
+ width: 20
35
+ });
36
+ };
37
+ //#endregion
38
+ export { CountryFlag };
39
+
40
+ //# sourceMappingURL=CountryFlag.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CountryFlag.js","names":[],"sources":["../../../../src/fields/phoneNumber/client/CountryFlag.tsx"],"sourcesContent":["'use client'\n\nimport { useConfig } from '@payloadcms/ui'\nimport type React from 'react'\nimport { useState } from 'react'\nimport { emojiFlag } from '../engine/countries'\nimport type { CountryCode } from '../engine/phone'\nimport { countryFlagSrc, type PhoneFlagMode } from '../options'\nimport './phoneNumberField.css'\n\nconst baseClass = 'fields-phone'\n\nexport type CountryFlagProps = {\n\tcode: CountryCode\n\tmode: PhoneFlagMode\n}\n\n/**\n * Decorative in every mode: each trigger and row that carries a flag also carries the\n * country's name, so the artwork stays out of the accessibility tree.\n */\nexport const CountryFlag: React.FC<CountryFlagProps> = ({ code, mode }) => {\n\tconst { config } = useConfig()\n\tconst [failedSrc, setFailedSrc] = useState<null | string>(null)\n\n\tif (mode === 'none') return null\n\n\tif (mode === 'emoji') {\n\t\treturn (\n\t\t\t<span aria-hidden=\"true\" className={`${baseClass}__flag ${baseClass}__flag--emoji`}>\n\t\t\t\t{emojiFlag(code)}\n\t\t\t</span>\n\t\t)\n\t}\n\n\tconst src = countryFlagSrc(config.serverURL, config.routes.api, code)\n\t// A flag that fails keeps its box rather than unmounting, so the row beside it never\n\t// reflows; keying the failure by src lets a row reused for another country try again.\n\tconst failed = failedSrc === src\n\n\treturn (\n\t\t<img\n\t\t\talt=\"\"\n\t\t\taria-hidden=\"true\"\n\t\t\tclassName={`${baseClass}__flag`}\n\t\t\tdecoding=\"async\"\n\t\t\theight={15}\n\t\t\tloading=\"lazy\"\n\t\t\tonError={() => setFailedSrc(src)}\n\t\t\tsrc={src}\n\t\t\tstyle={failed ? { visibility: 'hidden' } : undefined}\n\t\t\twidth={20}\n\t\t/>\n\t)\n}\n"],"mappings":";;;;;;;;AAUA,MAAM,YAAY;;;;;AAWlB,MAAa,eAA2C,EAAE,MAAM,WAAW;CAC1E,MAAM,EAAE,WAAW,UAAU;CAC7B,MAAM,CAAC,WAAW,gBAAgB,SAAwB,IAAI;CAE9D,IAAI,SAAS,QAAQ,OAAO;CAE5B,IAAI,SAAS,SACZ,OACC,oBAAC,QAAD;EAAM,eAAY;EAAO,WAAW,GAAG,UAAU,SAAS,UAAU;YAClE,UAAU,IAAI;CACV,CAAA;CAIR,MAAM,MAAM,eAAe,OAAO,WAAW,OAAO,OAAO,KAAK,IAAI;CAKpE,OACC,oBAAC,OAAD;EACC,KAAI;EACJ,eAAY;EACZ,WAAW,GAAG,UAAU;EACxB,UAAS;EACT,QAAQ;EACR,SAAQ;EACR,eAAe,aAAa,GAAG;EAC1B;EACL,OAZa,cAAc,MAYX,EAAE,YAAY,SAAS,IAAI,KAAA;EAC3C,OAAO;CACP,CAAA;AAEH"}
@@ -0,0 +1,21 @@
1
+ import { CountryCode } from "../engine/phone.js";
2
+ import { PhoneFlagMode } from "../options.js";
3
+ import { CountryOption } from "../engine/countries.js";
4
+ import React from "react";
5
+ //#region src/fields/phoneNumber/client/CountryPicker.d.ts
6
+ type CountryOptionGroups = {
7
+ priority: CountryOption[];
8
+ rest: CountryOption[];
9
+ };
10
+ type CountryPickerProps = {
11
+ disabled: boolean;
12
+ flags: PhoneFlagMode;
13
+ onSelect: (code: CountryCode) => void;
14
+ options: CountryOptionGroups;
15
+ priorityLabel?: string;
16
+ value: CountryCode | undefined;
17
+ };
18
+ declare const CountryPicker: React.FC<CountryPickerProps>;
19
+ //#endregion
20
+ export { CountryOptionGroups, CountryPicker, CountryPickerProps };
21
+ //# sourceMappingURL=CountryPicker.d.ts.map
@@ -0,0 +1,255 @@
1
+ "use client";
2
+ import { keys } from "../../../translations/keys.js";
3
+ import { useTranslation as useTranslation$1 } from "../../../translations/useTranslation.js";
4
+ import { CountryFlag } from "./CountryFlag.js";
5
+ import { ChevronIcon, Popup, SearchIcon } from "@payloadcms/ui";
6
+ import { useCallback, useEffect, useId, useMemo, useRef, useState } from "react";
7
+ import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
8
+ import "./phoneNumberField.css";
9
+ import { useVirtualizer } from "@tanstack/react-virtual";
10
+ //#region src/fields/phoneNumber/client/CountryPicker.tsx
11
+ const baseClass = "fields-phone";
12
+ const ROW_HEIGHT = 34;
13
+ const estimateRow = () => ROW_HEIGHT;
14
+ const LIST_MAX_HEIGHT = ROW_HEIGHT * 8;
15
+ const matchesQuery = (option, query) => {
16
+ if (option.name.toLowerCase().includes(query)) return true;
17
+ if (option.code.toLowerCase().startsWith(query)) return true;
18
+ const digits = query.replace(/\D/g, "");
19
+ return digits !== "" && option.callingCode.startsWith(digits);
20
+ };
21
+ const filterOptions = (options, query) => query === "" ? options : options.filter((option) => matchesQuery(option, query));
22
+ /**
23
+ * The priority heading renders only with a caller-given label; the plain divider before
24
+ * `rest` carries the split otherwise. Neither appears when either group is empty, since
25
+ * there is then nothing to separate from.
26
+ */
27
+ const buildRows = (options, query, priorityLabel) => {
28
+ const priority = filterOptions(options.priority, query);
29
+ const rest = filterOptions(options.rest, query);
30
+ const split = priority.length > 0 && rest.length > 0;
31
+ return [
32
+ ...split && priorityLabel !== void 0 ? [{
33
+ kind: "heading",
34
+ label: priorityLabel
35
+ }] : [],
36
+ ...priority.map((option) => ({
37
+ kind: "option",
38
+ option
39
+ })),
40
+ ...split ? [{ kind: "divider" }] : [],
41
+ ...rest.map((option) => ({
42
+ kind: "option",
43
+ option
44
+ }))
45
+ ];
46
+ };
47
+ const CountryPanel = ({ close, flags, onSelect, options, priorityLabel, value }) => {
48
+ const { t } = useTranslation$1();
49
+ const [query, setQuery] = useState("");
50
+ const listRef = useRef(null);
51
+ const searchRef = useRef(null);
52
+ const listId = useId();
53
+ useEffect(() => {
54
+ searchRef.current?.focus({ preventScroll: true });
55
+ }, []);
56
+ const rows = useMemo(() => buildRows(options, query.trim().toLowerCase(), priorityLabel), [
57
+ options,
58
+ priorityLabel,
59
+ query
60
+ ]);
61
+ const optionRows = useMemo(() => rows.flatMap((row, index) => row.kind === "option" ? [index] : []), [rows]);
62
+ const virtualizer = useVirtualizer({
63
+ count: rows.length,
64
+ estimateSize: estimateRow,
65
+ getScrollElement: () => listRef.current,
66
+ overscan: 6
67
+ });
68
+ const [activeRow, setActiveRow] = useState(-1);
69
+ useEffect(() => {
70
+ const selected = rows.findIndex((row) => row.kind === "option" && row.option.code === value);
71
+ const next = selected >= 0 ? selected : optionRows[0] ?? -1;
72
+ setActiveRow(next);
73
+ if (next >= 0) virtualizer.scrollToIndex(next, { align: "center" });
74
+ }, [query]);
75
+ const select = useCallback((code) => {
76
+ onSelect(code);
77
+ close();
78
+ }, [close, onSelect]);
79
+ const move = useCallback((step) => {
80
+ const position = optionRows.indexOf(activeRow);
81
+ const next = optionRows[Math.min(Math.max(position + step, 0), optionRows.length - 1)];
82
+ if (next === void 0) return;
83
+ setActiveRow(next);
84
+ virtualizer.scrollToIndex(next);
85
+ }, [
86
+ activeRow,
87
+ optionRows,
88
+ virtualizer
89
+ ]);
90
+ const onKeyDown = (event) => {
91
+ if (event.key === "ArrowDown" || event.key === "ArrowUp") {
92
+ event.preventDefault();
93
+ event.stopPropagation();
94
+ move(event.key === "ArrowDown" ? 1 : -1);
95
+ return;
96
+ }
97
+ if (event.key === "Enter") {
98
+ event.preventDefault();
99
+ const row = rows[activeRow];
100
+ if (row?.kind === "option") select(row.option.code);
101
+ }
102
+ };
103
+ const optionId = (index) => `${listId}-option-${index}`;
104
+ const populated = rows.length > 0;
105
+ const listA11y = populated ? {
106
+ "aria-label": t(keys.selectCountry),
107
+ role: "listbox"
108
+ } : {};
109
+ return /* @__PURE__ */ jsxs("div", {
110
+ className: `${baseClass}__panel`,
111
+ "data-popup-prevent-close": true,
112
+ children: [/* @__PURE__ */ jsxs("div", {
113
+ className: `${baseClass}__search`,
114
+ children: [/* @__PURE__ */ jsx("span", {
115
+ "aria-hidden": "true",
116
+ className: `${baseClass}__search-icon`,
117
+ children: /* @__PURE__ */ jsx(SearchIcon, {})
118
+ }), /* @__PURE__ */ jsx("input", {
119
+ "aria-activedescendant": rows[activeRow]?.kind === "option" ? optionId(activeRow) : void 0,
120
+ "aria-autocomplete": "list",
121
+ "aria-controls": populated ? listId : void 0,
122
+ "aria-expanded": populated,
123
+ "aria-label": t(keys.searchCountries),
124
+ className: `${baseClass}__search-input`,
125
+ onChange: (event) => setQuery(event.target.value),
126
+ onKeyDown,
127
+ placeholder: t(keys.searchCountries),
128
+ ref: searchRef,
129
+ role: "combobox",
130
+ type: "text",
131
+ value: query
132
+ })]
133
+ }), /* @__PURE__ */ jsx("div", {
134
+ className: `${baseClass}__list`,
135
+ id: listId,
136
+ ref: listRef,
137
+ style: { maxHeight: LIST_MAX_HEIGHT },
138
+ ...listA11y,
139
+ children: populated ? /* @__PURE__ */ jsx("div", {
140
+ role: "presentation",
141
+ style: {
142
+ height: virtualizer.getTotalSize(),
143
+ position: "relative",
144
+ width: "100%"
145
+ },
146
+ children: virtualizer.getVirtualItems().map((item) => {
147
+ const row = rows[item.index];
148
+ if (!row) return null;
149
+ const style = {
150
+ height: `${item.size}px`,
151
+ left: 0,
152
+ position: "absolute",
153
+ top: 0,
154
+ transform: `translateY(${item.start}px)`,
155
+ width: "100%"
156
+ };
157
+ if (row.kind === "heading") return /* @__PURE__ */ jsx("div", {
158
+ className: `${baseClass}__group`,
159
+ role: "presentation",
160
+ style,
161
+ children: row.label
162
+ }, "heading");
163
+ if (row.kind === "divider") return /* @__PURE__ */ jsx("div", {
164
+ className: `${baseClass}__group`,
165
+ role: "presentation",
166
+ style
167
+ }, "divider");
168
+ return /* @__PURE__ */ jsxs("button", {
169
+ "aria-posinset": optionRows.indexOf(item.index) + 1,
170
+ "aria-selected": row.option.code === value,
171
+ "aria-setsize": optionRows.length,
172
+ className: `${baseClass}__option`,
173
+ "data-active": item.index === activeRow || void 0,
174
+ id: optionId(item.index),
175
+ onClick: () => select(row.option.code),
176
+ role: "option",
177
+ style,
178
+ tabIndex: -1,
179
+ type: "button",
180
+ children: [
181
+ /* @__PURE__ */ jsx(CountryFlag, {
182
+ code: row.option.code,
183
+ mode: flags
184
+ }),
185
+ /* @__PURE__ */ jsx("span", {
186
+ className: `${baseClass}__option-name`,
187
+ children: row.option.name
188
+ }),
189
+ /* @__PURE__ */ jsx("span", {
190
+ className: `${baseClass}__option-code`,
191
+ children: `+${row.option.callingCode}`
192
+ })
193
+ ]
194
+ }, row.option.code);
195
+ })
196
+ }) : /* @__PURE__ */ jsx("div", {
197
+ className: `${baseClass}__empty`,
198
+ children: t(keys.noCountriesFound)
199
+ })
200
+ })]
201
+ });
202
+ };
203
+ const CountryPicker = ({ disabled, flags, onSelect, options, priorityLabel, value }) => {
204
+ const { t } = useTranslation$1();
205
+ const [open, setOpen] = useState(false);
206
+ const selected = useMemo(() => [...options.priority, ...options.rest].find((option) => option.code === value), [options, value]);
207
+ const label = value === void 0 ? t(keys.selectCountry) : t(keys.phoneCountryFor, { country: selected?.name ?? value });
208
+ const renderFace = () => {
209
+ if (value === void 0) return null;
210
+ if (flags === "none") return /* @__PURE__ */ jsx("span", {
211
+ className: `${baseClass}__code`,
212
+ children: value
213
+ });
214
+ return /* @__PURE__ */ jsx(CountryFlag, {
215
+ code: value,
216
+ mode: flags
217
+ });
218
+ };
219
+ return /* @__PURE__ */ jsx(Popup, {
220
+ button: /* @__PURE__ */ jsxs(Fragment$1, { children: [
221
+ renderFace(),
222
+ /* @__PURE__ */ jsx("span", {
223
+ className: `${baseClass}__sr-only`,
224
+ children: label
225
+ }),
226
+ /* @__PURE__ */ jsx("span", {
227
+ "aria-hidden": "true",
228
+ className: `${baseClass}__caret`,
229
+ children: /* @__PURE__ */ jsx(ChevronIcon, { size: "small" })
230
+ })
231
+ ] }),
232
+ buttonClassName: `${baseClass}__trigger`,
233
+ buttonType: "default",
234
+ caret: false,
235
+ className: `${baseClass}__picker`,
236
+ disabled,
237
+ horizontalAlign: "left",
238
+ onToggleClose: () => setOpen(false),
239
+ onToggleOpen: () => setOpen(true),
240
+ render: ({ close }) => open ? /* @__PURE__ */ jsx(CountryPanel, {
241
+ close,
242
+ flags,
243
+ onSelect,
244
+ options,
245
+ priorityLabel,
246
+ value
247
+ }) : null,
248
+ size: "fit-content",
249
+ verticalAlign: "bottom"
250
+ });
251
+ };
252
+ //#endregion
253
+ export { CountryPicker };
254
+
255
+ //# sourceMappingURL=CountryPicker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"CountryPicker.js","names":["useTranslation"],"sources":["../../../../src/fields/phoneNumber/client/CountryPicker.tsx"],"sourcesContent":["'use client'\n\nimport { ChevronIcon, Popup, SearchIcon } from '@payloadcms/ui'\nimport { useVirtualizer } from '@tanstack/react-virtual'\nimport type React from 'react'\nimport { useCallback, useEffect, useId, useMemo, useRef, useState } from 'react'\nimport { keys } from '../../../translations/keys'\nimport { useTranslation } from '../../../translations/useTranslation'\nimport type { CountryOption } from '../engine/countries'\nimport type { CountryCode } from '../engine/phone'\nimport type { PhoneFlagMode } from '../options'\nimport { CountryFlag } from './CountryFlag'\nimport './phoneNumberField.css'\n\nconst baseClass = 'fields-phone'\n\n// Headings, the divider, and options share one height, so the virtualizer's estimate is\n// exact and the rows it positions can never drift from what the CSS paints.\nconst ROW_HEIGHT = 34\nconst estimateRow = () => ROW_HEIGHT\n\n// The cap is published from here rather than written into the stylesheet: a fractional one\n// clips the last row against the panel edge, which reads as tighter padding at the bottom.\nconst VISIBLE_ROWS = 8\nconst LIST_MAX_HEIGHT = ROW_HEIGHT * VISIBLE_ROWS\n\nexport type CountryOptionGroups = {\n\tpriority: CountryOption[]\n\trest: CountryOption[]\n}\n\ntype PickerRow =\n\t| { kind: 'divider' }\n\t| { kind: 'heading'; label: string }\n\t| { kind: 'option'; option: CountryOption }\n\nconst matchesQuery = (option: CountryOption, query: string): boolean => {\n\tif (option.name.toLowerCase().includes(query)) return true\n\tif (option.code.toLowerCase().startsWith(query)) return true\n\tconst digits = query.replace(/\\D/g, '')\n\treturn digits !== '' && option.callingCode.startsWith(digits)\n}\n\nconst filterOptions = (options: CountryOption[], query: string): CountryOption[] =>\n\tquery === '' ? options : options.filter((option) => matchesQuery(option, query))\n\n/**\n * The priority heading renders only with a caller-given label; the plain divider before\n * `rest` carries the split otherwise. Neither appears when either group is empty, since\n * there is then nothing to separate from.\n */\nconst buildRows = (\n\toptions: CountryOptionGroups,\n\tquery: string,\n\tpriorityLabel: string | undefined\n): PickerRow[] => {\n\tconst priority = filterOptions(options.priority, query)\n\tconst rest = filterOptions(options.rest, query)\n\tconst split = priority.length > 0 && rest.length > 0\n\treturn [\n\t\t...(split && priorityLabel !== undefined\n\t\t\t? [{ kind: 'heading', label: priorityLabel } as const]\n\t\t\t: []),\n\t\t...priority.map((option) => ({ kind: 'option', option }) as const),\n\t\t...(split ? [{ kind: 'divider' } as const] : []),\n\t\t...rest.map((option) => ({ kind: 'option', option }) as const),\n\t]\n}\n\ntype CountryPanelProps = {\n\tclose: () => void\n\tflags: PhoneFlagMode\n\tonSelect: (code: CountryCode) => void\n\toptions: CountryOptionGroups\n\tpriorityLabel?: string\n\tvalue: CountryCode | undefined\n}\n\nconst CountryPanel: React.FC<CountryPanelProps> = ({\n\tclose,\n\tflags,\n\tonSelect,\n\toptions,\n\tpriorityLabel,\n\tvalue,\n}) => {\n\tconst { t } = useTranslation()\n\tconst [query, setQuery] = useState('')\n\tconst listRef = useRef<HTMLDivElement>(null)\n\tconst searchRef = useRef<HTMLInputElement>(null)\n\tconst listId = useId()\n\n\t// The panel is portalled to the body and absolutely positioned, so a plain focus scrolls\n\t// the page to it and drags the row the viewer is reading out from under them.\n\tuseEffect(() => {\n\t\tsearchRef.current?.focus({ preventScroll: true })\n\t}, [])\n\n\tconst rows = useMemo(\n\t\t() => buildRows(options, query.trim().toLowerCase(), priorityLabel),\n\t\t[options, priorityLabel, query]\n\t)\n\tconst optionRows = useMemo(\n\t\t() => rows.flatMap((row, index) => (row.kind === 'option' ? [index] : [])),\n\t\t[rows]\n\t)\n\n\tconst virtualizer = useVirtualizer({\n\t\tcount: rows.length,\n\t\testimateSize: estimateRow,\n\t\tgetScrollElement: () => listRef.current,\n\t\toverscan: 6,\n\t})\n\n\tconst [activeRow, setActiveRow] = useState(-1)\n\t// biome-ignore lint/correctness/useExhaustiveDependencies: the query is the trigger; re-seeding on every parent render would fight the arrow keys\n\tuseEffect(() => {\n\t\tconst selected = rows.findIndex((row) => row.kind === 'option' && row.option.code === value)\n\t\tconst next = selected >= 0 ? selected : (optionRows[0] ?? -1)\n\t\tsetActiveRow(next)\n\t\t// aria-activedescendant has to name a rendered element, and the virtualizer only\n\t\t// renders what is in view: opening on the 200th country must scroll to it.\n\t\tif (next >= 0) virtualizer.scrollToIndex(next, { align: 'center' })\n\t}, [query])\n\n\tconst select = useCallback(\n\t\t(code: CountryCode) => {\n\t\t\tonSelect(code)\n\t\t\tclose()\n\t\t},\n\t\t[close, onSelect]\n\t)\n\n\tconst move = useCallback(\n\t\t(step: number) => {\n\t\t\tconst position = optionRows.indexOf(activeRow)\n\t\t\tconst next = optionRows[Math.min(Math.max(position + step, 0), optionRows.length - 1)]\n\t\t\tif (next === undefined) return\n\t\t\tsetActiveRow(next)\n\t\t\tvirtualizer.scrollToIndex(next)\n\t\t},\n\t\t[activeRow, optionRows, virtualizer]\n\t)\n\n\tconst onKeyDown = (event: React.KeyboardEvent<HTMLInputElement>) => {\n\t\tif (event.key === 'ArrowDown' || event.key === 'ArrowUp') {\n\t\t\t// The arrows drive this list, so they stop here: Payload's Popup otherwise walks\n\t\t\t// focus between the panel's tabbables, which is why rows carry tabIndex={-1}.\n\t\t\tevent.preventDefault()\n\t\t\tevent.stopPropagation()\n\t\t\tmove(event.key === 'ArrowDown' ? 1 : -1)\n\t\t\treturn\n\t\t}\n\t\tif (event.key === 'Enter') {\n\t\t\tevent.preventDefault()\n\t\t\tconst row = rows[activeRow]\n\t\t\tif (row?.kind === 'option') select(row.option.code)\n\t\t}\n\t}\n\n\tconst optionId = (index: number) => `${listId}-option-${index}`\n\tconst populated = rows.length > 0\n\t// A listbox must own option children, so the list claims the role only once it holds\n\t// options; while empty it is a plain container around the no-results message.\n\tconst listA11y: React.HTMLAttributes<HTMLDivElement> = populated\n\t\t? { 'aria-label': t(keys.selectCountry), role: 'listbox' }\n\t\t: {}\n\n\treturn (\n\t\t// Popup closes itself on any click reaching a button inside it, which unmounts this\n\t\t// panel before React dispatches the row's own onClick and loses the selection\n\t\t// entirely. The rows close through `select` instead, so it opts out.\n\t\t<div className={`${baseClass}__panel`} data-popup-prevent-close>\n\t\t\t<div className={`${baseClass}__search`}>\n\t\t\t\t<span aria-hidden=\"true\" className={`${baseClass}__search-icon`}>\n\t\t\t\t\t<SearchIcon />\n\t\t\t\t</span>\n\t\t\t\t<input\n\t\t\t\t\taria-activedescendant={\n\t\t\t\t\t\trows[activeRow]?.kind === 'option' ? optionId(activeRow) : undefined\n\t\t\t\t\t}\n\t\t\t\t\taria-autocomplete=\"list\"\n\t\t\t\t\taria-controls={populated ? listId : undefined}\n\t\t\t\t\taria-expanded={populated}\n\t\t\t\t\taria-label={t(keys.searchCountries)}\n\t\t\t\t\tclassName={`${baseClass}__search-input`}\n\t\t\t\t\tonChange={(event) => setQuery(event.target.value)}\n\t\t\t\t\tonKeyDown={onKeyDown}\n\t\t\t\t\tplaceholder={t(keys.searchCountries)}\n\t\t\t\t\tref={searchRef}\n\t\t\t\t\trole=\"combobox\"\n\t\t\t\t\ttype=\"text\"\n\t\t\t\t\tvalue={query}\n\t\t\t\t/>\n\t\t\t</div>\n\t\t\t<div\n\t\t\t\tclassName={`${baseClass}__list`}\n\t\t\t\tid={listId}\n\t\t\t\tref={listRef}\n\t\t\t\tstyle={{ maxHeight: LIST_MAX_HEIGHT }}\n\t\t\t\t{...listA11y}\n\t\t\t>\n\t\t\t\t{populated ? (\n\t\t\t\t\t<div\n\t\t\t\t\t\trole=\"presentation\"\n\t\t\t\t\t\tstyle={{ height: virtualizer.getTotalSize(), position: 'relative', width: '100%' }}\n\t\t\t\t\t>\n\t\t\t\t\t\t{virtualizer.getVirtualItems().map((item) => {\n\t\t\t\t\t\t\tconst row = rows[item.index]\n\t\t\t\t\t\t\tif (!row) return null\n\t\t\t\t\t\t\tconst style: React.CSSProperties = {\n\t\t\t\t\t\t\t\theight: `${item.size}px`,\n\t\t\t\t\t\t\t\tleft: 0,\n\t\t\t\t\t\t\t\tposition: 'absolute',\n\t\t\t\t\t\t\t\ttop: 0,\n\t\t\t\t\t\t\t\ttransform: `translateY(${item.start}px)`,\n\t\t\t\t\t\t\t\twidth: '100%',\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (row.kind === 'heading') {\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\t\t\tclassName={`${baseClass}__group`}\n\t\t\t\t\t\t\t\t\t\tkey=\"heading\"\n\t\t\t\t\t\t\t\t\t\trole=\"presentation\"\n\t\t\t\t\t\t\t\t\t\tstyle={style}\n\t\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t\t{row.label}\n\t\t\t\t\t\t\t\t\t</div>\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\tif (row.kind === 'divider') {\n\t\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t\t<div\n\t\t\t\t\t\t\t\t\t\tclassName={`${baseClass}__group`}\n\t\t\t\t\t\t\t\t\t\tkey=\"divider\"\n\t\t\t\t\t\t\t\t\t\trole=\"presentation\"\n\t\t\t\t\t\t\t\t\t\tstyle={style}\n\t\t\t\t\t\t\t\t\t/>\n\t\t\t\t\t\t\t\t)\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn (\n\t\t\t\t\t\t\t\t<button\n\t\t\t\t\t\t\t\t\t// Only a dozen rows are ever in the DOM, so a screen reader would otherwise\n\t\t\t\t\t\t\t\t\t// count the window instead of the list and announce \"1 of 12\" for 250 countries.\n\t\t\t\t\t\t\t\t\taria-posinset={optionRows.indexOf(item.index) + 1}\n\t\t\t\t\t\t\t\t\taria-selected={row.option.code === value}\n\t\t\t\t\t\t\t\t\taria-setsize={optionRows.length}\n\t\t\t\t\t\t\t\t\tclassName={`${baseClass}__option`}\n\t\t\t\t\t\t\t\t\tdata-active={item.index === activeRow || undefined}\n\t\t\t\t\t\t\t\t\tid={optionId(item.index)}\n\t\t\t\t\t\t\t\t\tkey={row.option.code}\n\t\t\t\t\t\t\t\t\tonClick={() => select(row.option.code)}\n\t\t\t\t\t\t\t\t\trole=\"option\"\n\t\t\t\t\t\t\t\t\tstyle={style}\n\t\t\t\t\t\t\t\t\ttabIndex={-1}\n\t\t\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t\t\t>\n\t\t\t\t\t\t\t\t\t<CountryFlag code={row.option.code} mode={flags} />\n\t\t\t\t\t\t\t\t\t<span className={`${baseClass}__option-name`}>{row.option.name}</span>\n\t\t\t\t\t\t\t\t\t<span\n\t\t\t\t\t\t\t\t\t\tclassName={`${baseClass}__option-code`}\n\t\t\t\t\t\t\t\t\t>{`+${row.option.callingCode}`}</span>\n\t\t\t\t\t\t\t\t</button>\n\t\t\t\t\t\t\t)\n\t\t\t\t\t\t})}\n\t\t\t\t\t</div>\n\t\t\t\t) : (\n\t\t\t\t\t<div className={`${baseClass}__empty`}>{t(keys.noCountriesFound)}</div>\n\t\t\t\t)}\n\t\t\t</div>\n\t\t</div>\n\t)\n}\n\nexport type CountryPickerProps = {\n\tdisabled: boolean\n\tflags: PhoneFlagMode\n\tonSelect: (code: CountryCode) => void\n\toptions: CountryOptionGroups\n\tpriorityLabel?: string\n\tvalue: CountryCode | undefined\n}\n\nexport const CountryPicker: React.FC<CountryPickerProps> = ({\n\tdisabled,\n\tflags,\n\tonSelect,\n\toptions,\n\tpriorityLabel,\n\tvalue,\n}) => {\n\tconst { t } = useTranslation()\n\t// Payload's Popup renders its panel whether or not it is open, so the list is gated on\n\t// this instead: a closed field builds no rows, and reopening starts from a clean search.\n\tconst [open, setOpen] = useState(false)\n\n\tconst selected = useMemo(\n\t\t() => [...options.priority, ...options.rest].find((option) => option.code === value),\n\t\t[options, value]\n\t)\n\tconst label =\n\t\tvalue === undefined\n\t\t\t? t(keys.selectCountry)\n\t\t\t: t(keys.phoneCountryFor, { country: selected?.name ?? value })\n\n\tconst renderFace = () => {\n\t\tif (value === undefined) return null\n\t\tif (flags === 'none') return <span className={`${baseClass}__code`}>{value}</span>\n\t\treturn <CountryFlag code={value} mode={flags} />\n\t}\n\n\treturn (\n\t\t<Popup\n\t\t\tbutton={\n\t\t\t\t<>\n\t\t\t\t\t{renderFace()}\n\t\t\t\t\t<span className={`${baseClass}__sr-only`}>{label}</span>\n\t\t\t\t\t<span aria-hidden=\"true\" className={`${baseClass}__caret`}>\n\t\t\t\t\t\t{/* Unsized, the icon is --base tall and overflows its 12px box downwards */}\n\t\t\t\t\t\t<ChevronIcon size=\"small\" />\n\t\t\t\t\t</span>\n\t\t\t\t</>\n\t\t\t}\n\t\t\tbuttonClassName={`${baseClass}__trigger`}\n\t\t\tbuttonType=\"default\"\n\t\t\tcaret={false}\n\t\t\tclassName={`${baseClass}__picker`}\n\t\t\tdisabled={disabled}\n\t\t\thorizontalAlign=\"left\"\n\t\t\tonToggleClose={() => setOpen(false)}\n\t\t\tonToggleOpen={() => setOpen(true)}\n\t\t\trender={({ close }) =>\n\t\t\t\topen ? (\n\t\t\t\t\t<CountryPanel\n\t\t\t\t\t\tclose={close}\n\t\t\t\t\t\tflags={flags}\n\t\t\t\t\t\tonSelect={onSelect}\n\t\t\t\t\t\toptions={options}\n\t\t\t\t\t\tpriorityLabel={priorityLabel}\n\t\t\t\t\t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