@10x-media/fields 0.1.0-beta.9 → 4.0.0-alpha.2

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 (76) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/README.md +9 -4
  3. package/dist/fields/color/client/ColorInput.js +17 -6
  4. package/dist/fields/color/client/ColorInput.js.map +1 -1
  5. package/dist/fields/color/client/ColorPickerPanel.js +18 -12
  6. package/dist/fields/color/client/ColorPickerPanel.js.map +1 -1
  7. package/dist/fields/color/client/colorField.css +131 -178
  8. package/dist/fields/color/client/icons.js +17 -24
  9. package/dist/fields/color/client/icons.js.map +1 -1
  10. package/dist/fields/color/colorField.js +5 -3
  11. package/dist/fields/color/colorField.js.map +1 -1
  12. package/dist/fields/color/server/colorCell.css +8 -9
  13. package/dist/fields/encrypted/components/EncryptedInput.js +44 -26
  14. package/dist/fields/encrypted/components/EncryptedInput.js.map +1 -1
  15. package/dist/fields/encrypted/components/EncryptedTextarea.js +29 -29
  16. package/dist/fields/encrypted/components/EncryptedTextarea.js.map +1 -1
  17. package/dist/fields/encrypted/components/EyeToggle.js +14 -35
  18. package/dist/fields/encrypted/components/EyeToggle.js.map +1 -1
  19. package/dist/fields/encrypted/components/ProtectedField.css +107 -159
  20. package/dist/fields/encrypted/components/ProtectedField.js +6 -2
  21. package/dist/fields/encrypted/components/ProtectedField.js.map +1 -1
  22. package/dist/fields/encrypted/components/RichTextRevealGate.js +3 -3
  23. package/dist/fields/encrypted/components/RichTextRevealGate.js.map +1 -1
  24. package/dist/fields/encrypted/components/WriteOnlyActions.js +58 -53
  25. package/dist/fields/encrypted/components/WriteOnlyActions.js.map +1 -1
  26. package/dist/fields/encrypted/components/WriteOnlyField.js +39 -21
  27. package/dist/fields/encrypted/components/WriteOnlyField.js.map +1 -1
  28. package/dist/fields/encrypted/components/facsimiles.js +70 -79
  29. package/dist/fields/encrypted/components/facsimiles.js.map +1 -1
  30. package/dist/fields/encrypted/components/placement.js.map +1 -1
  31. package/dist/fields/encrypted/encryptedField.js +25 -12
  32. package/dist/fields/encrypted/encryptedField.js.map +1 -1
  33. package/dist/fields/encrypted/{typescriptSchema.js → jsonSchema.js} +4 -4
  34. package/dist/fields/encrypted/jsonSchema.js.map +1 -0
  35. package/dist/fields/encrypted/queryRewrite.js +20 -0
  36. package/dist/fields/encrypted/queryRewrite.js.map +1 -1
  37. package/dist/fields/encrypted/validators.js +1 -1
  38. package/dist/fields/encrypted/validators.js.map +1 -1
  39. package/dist/fields/icon/adapters/tabler/generated/nodes.js +1 -1
  40. package/dist/fields/icon/adapters/tabler/generated/nodes.js.map +1 -1
  41. package/dist/fields/icon/client/IconDrawerContent.js +8 -6
  42. package/dist/fields/icon/client/IconDrawerContent.js.map +1 -1
  43. package/dist/fields/icon/client/IconFieldClient.js +15 -37
  44. package/dist/fields/icon/client/IconFieldClient.js.map +1 -1
  45. package/dist/fields/icon/client/icon-field.css +137 -233
  46. package/dist/fields/icon/codegen/sources/tabler.js +25 -6
  47. package/dist/fields/icon/codegen/sources/tabler.js.map +1 -1
  48. package/dist/fields/icon/layers/upload.js +3 -0
  49. package/dist/fields/icon/layers/upload.js.map +1 -1
  50. package/dist/fields/icon/react/createIcon.js +4 -4
  51. package/dist/fields/icon/react/createIcon.js.map +1 -1
  52. package/dist/fields/measurement/client/MeasurementInput.js +18 -32
  53. package/dist/fields/measurement/client/MeasurementInput.js.map +1 -1
  54. package/dist/fields/measurement/client/editModel.js +12 -3
  55. package/dist/fields/measurement/client/editModel.js.map +1 -1
  56. package/dist/fields/measurement/client/measurementField.css +58 -105
  57. package/dist/fields/measurement/server/getUserUnits.js +2 -1
  58. package/dist/fields/measurement/server/getUserUnits.js.map +1 -1
  59. package/dist/fields/phoneNumber/client/CountryPicker.js +14 -9
  60. package/dist/fields/phoneNumber/client/CountryPicker.js.map +1 -1
  61. package/dist/fields/phoneNumber/client/PhoneNumberField.d.ts +1 -1
  62. package/dist/fields/phoneNumber/client/PhoneNumberField.js +22 -4
  63. package/dist/fields/phoneNumber/client/PhoneNumberField.js.map +1 -1
  64. package/dist/fields/phoneNumber/client/phoneNumberField.css +109 -142
  65. package/dist/fields/phoneNumber/phoneNumberField.js +1 -1
  66. package/dist/fields/phoneNumber/phoneNumberField.js.map +1 -1
  67. package/dist/fields/phoneNumber/server/PhoneNumberCellServer.js +2 -1
  68. package/dist/fields/phoneNumber/server/PhoneNumberCellServer.js.map +1 -1
  69. package/dist/index.d.ts +3 -2
  70. package/dist/index.js +5 -4
  71. package/dist/index.js.map +1 -1
  72. package/dist/plugin/companionSelect.d.ts +12 -0
  73. package/dist/plugin/companionSelect.js +107 -0
  74. package/dist/plugin/companionSelect.js.map +1 -0
  75. package/package.json +15 -15
  76. package/dist/fields/encrypted/typescriptSchema.js.map +0 -1
@@ -2,61 +2,36 @@
2
2
  position: relative;
3
3
  }
4
4
 
5
- /* Mirrors Payload's formInput mixin (packages/ui/src/scss/vars.scss) so the composite
6
- container reads as one native text input; focus rides :focus-within.
7
- Dimensions are static px on purpose: Payload compiles scss base() to literal px
8
- (native inputs stay 40px tall at every breakpoint), while the runtime --base var
9
- is rem-based and shrinks with the responsive html font-size. Deriving from
10
- var(--base) made this container 3px shorter than native inputs at <=1024px. */
11
- .fields-measurement__container {
5
+ .fields-measurement > .field-type__wrap {
12
6
  display: flex;
13
- align-items: center;
14
- gap: 3px;
15
- width: 100%;
16
- height: 40px;
17
- padding: 0 8px 0 6px;
18
- border: 1px solid var(--theme-elevation-150);
19
- border-radius: var(--style-radius-s);
20
- background: var(--theme-input-bg);
21
- color: var(--theme-elevation-800);
22
- font-family: var(--font-body);
23
- font-size: 1rem;
24
- box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.1);
25
- transition-property: border, box-shadow, background-color;
26
- transition-duration: 100ms, 100ms, 500ms;
27
- transition-timing-function: cubic-bezier(0, 0.2, 0.2, 1);
28
- }
29
-
30
- .fields-measurement__container:hover {
31
- border-color: var(--theme-elevation-250);
32
- box-shadow: 0 2px 2px -1px rgba(0, 0, 0, 0.2);
33
- }
34
-
35
- .fields-measurement__container:focus-within {
36
- border-color: var(--theme-elevation-400);
37
- outline: 0;
38
- }
39
-
40
- html[data-theme="light"] .fields-measurement.error .fields-measurement__container {
41
- background-color: var(--theme-error-50);
42
- border-color: var(--theme-error-500);
7
+ flex-direction: column;
8
+ gap: var(--spacer-2);
43
9
  }
44
10
 
45
- html[data-theme="dark"] .fields-measurement.error .fields-measurement__container {
46
- background-color: var(--theme-error-100);
47
- border-color: var(--theme-error-400);
11
+ /* Payload's .form-input-group (on the same element) owns the border, background, radius,
12
+ height and the hover, focus, error and disabled states; this only lays out the row. */
13
+ .fields-measurement__container {
14
+ align-items: center;
15
+ gap: var(--spacer-1);
16
+ padding-inline: var(--field-padding-inline) var(--spacer-1);
17
+ color: var(--field-color-text);
18
+ font-family: var(--font-body);
19
+ font-size: var(--text-body-medium-font-size);
20
+ font-weight: var(--text-body-medium-font-weight);
21
+ line-height: var(--text-body-medium-line-height);
48
22
  }
49
23
 
50
- html[data-theme="dark"] .fields-measurement.error .fields-measurement__container:hover {
51
- border-color: var(--theme-error-500);
24
+ /* Native read-only inputs are disabled inputs on v4, so the row takes the disabled look.
25
+ A read-only input still takes focus here; Payload's .form-input:read-only:focus answers
26
+ that with the hover border, and so does this. */
27
+ .fields-measurement.read-only .fields-measurement__container {
28
+ border-color: var(--field-color-border-disabled);
29
+ background: var(--field-color-bg-disabled);
30
+ color: var(--field-color-text-disabled);
52
31
  }
53
32
 
54
- .fields-measurement.read-only .fields-measurement__container,
55
- .fields-measurement.read-only .fields-measurement__container:hover {
56
- border-color: var(--theme-elevation-150);
57
- background: var(--theme-elevation-100);
58
- color: var(--theme-elevation-400);
59
- box-shadow: none;
33
+ .fields-measurement.read-only .fields-measurement__container:focus-within {
34
+ border-color: var(--field-color-border-hover);
60
35
  }
61
36
 
62
37
  /* Each value hugs its unit; the wider gap separates the pairs, so the row
@@ -64,32 +39,27 @@ html[data-theme="dark"] .fields-measurement.error .fields-measurement__container
64
39
  .fields-measurement__compound {
65
40
  display: flex;
66
41
  flex: 1 1 auto;
42
+ align-self: stretch;
67
43
  min-width: 0;
68
44
  align-items: center;
69
- gap: 12px;
70
- height: 100%;
45
+ gap: var(--spacer-2-5);
71
46
  }
72
47
 
73
48
  .fields-measurement__part {
74
49
  display: flex;
50
+ align-self: stretch;
75
51
  align-items: center;
76
- gap: 3px;
77
- height: 100%;
52
+ gap: var(--spacer-1);
78
53
  }
79
54
 
80
55
  /* Width comes from an inline style tracking the draft's length, so every value
81
56
  (scalar or compound part) hugs its digits instead of stretching the row */
82
57
  .fields-measurement__input {
83
58
  flex: 0 1 auto;
59
+ align-self: stretch;
84
60
  min-width: 2ch;
85
- height: 100%;
86
- padding: 0;
87
- border: 0;
88
- background: transparent;
89
61
  color: inherit;
90
- font-family: inherit;
91
- font-size: inherit;
92
- appearance: none;
62
+ appearance: textfield;
93
63
  -webkit-appearance: none;
94
64
  -moz-appearance: textfield;
95
65
  }
@@ -105,13 +75,13 @@ html[data-theme="dark"] .fields-measurement.error .fields-measurement__container
105
75
  }
106
76
 
107
77
  .fields-measurement__input::placeholder {
108
- color: var(--theme-elevation-400);
78
+ color: var(--field-color-placeholder);
109
79
  }
110
80
 
111
- /* margin-left auto pins the kebab to the row's right edge, away from the
112
- value-unit phrase on the left */
81
+ /* margin-inline-start auto pins the kebab to the row's end, away from the
82
+ value-unit phrase */
113
83
  .fields-measurement__popup {
114
- margin-left: auto;
84
+ margin-inline-start: auto;
115
85
  }
116
86
 
117
87
  .fields-measurement__popup,
@@ -121,35 +91,30 @@ html[data-theme="dark"] .fields-measurement.error .fields-measurement__container
121
91
  }
122
92
 
123
93
  /* The trigger is a real button so it keeps native focus/keyboard semantics; the
124
- kebab is aria-hidden and a sr-only span next to it carries the name */
94
+ kebab is aria-hidden and a sr-only span next to it carries the name. Payload's
95
+ .popup-button paints its hover and pressed fills. */
125
96
  .fields-measurement__unit-trigger {
126
- display: inline-flex;
127
97
  flex-shrink: 0;
128
98
  align-items: center;
129
99
  justify-content: center;
130
- width: 24px;
131
- height: 24px;
132
- padding: 0;
133
- border: 0;
134
- border-radius: var(--style-radius-s);
135
- background: transparent;
136
- color: var(--theme-elevation-500);
137
- cursor: pointer;
100
+ width: var(--spacer-4);
101
+ height: var(--spacer-4);
102
+ color: var(--color-icon-secondary);
138
103
  }
139
104
 
140
105
  .fields-measurement__unit-trigger:hover {
141
- background: var(--theme-elevation-100);
142
- color: var(--theme-elevation-800);
106
+ color: var(--color-icon);
143
107
  }
144
108
 
145
109
  .fields-measurement__unit-trigger:focus-visible {
146
110
  outline: var(--accessibility-outline);
147
111
  }
148
112
 
113
+ /* MoreIcon's three dots sit symmetric about the centre of its box, so a quarter turn makes an
114
+ upright kebab without moving it. */
149
115
  .fields-measurement__kebab {
150
116
  flex-shrink: 0;
151
- width: 4px;
152
- height: 14px;
117
+ transform: rotate(90deg);
153
118
  }
154
119
 
155
120
  .fields-measurement__sr-only {
@@ -164,52 +129,40 @@ html[data-theme="dark"] .fields-measurement.error .fields-measurement__container
164
129
  border-width: 0;
165
130
  }
166
131
 
167
- /* The unit is always a passive suffix hugging its value; interactivity lives
168
- on the kebab at the row's right edge (absent when there is nothing to open) */
132
+ /* The unit is always a passive suffix hugging its value, styled as the native number
133
+ field's suffix; interactivity lives on the kebab at the row's end (absent when there
134
+ is nothing to open) */
169
135
  .fields-measurement__unit-static {
170
136
  flex-shrink: 0;
171
- color: var(--theme-elevation-500);
172
- font-size: 0.85rem;
137
+ color: var(--color-text-secondary);
173
138
  white-space: nowrap;
174
139
  cursor: default;
140
+ user-select: none;
175
141
  }
176
142
 
177
- .popup__scroll-container:has(> .fields-measurement__unit-panel) {
178
- max-height: none;
143
+ .fields-measurement.read-only .fields-measurement__unit-static {
144
+ color: inherit;
179
145
  }
180
146
 
147
+ /* Payload's .popup-button-list (on the same element) supplies the list padding, and
148
+ .popup-button-list__button the item type, radius, hover and selected fills. */
181
149
  .fields-measurement__unit-panel {
182
- display: flex;
183
- flex-direction: column;
184
- gap: 2px;
185
150
  min-width: 180px;
186
- padding: 4px;
187
151
  }
188
152
 
189
153
  .fields-measurement__unit-option {
190
- display: flex;
191
154
  align-items: center;
192
155
  justify-content: space-between;
193
- gap: 12px;
194
- padding: 6px 8px;
195
- border: 0;
196
- border-radius: var(--style-radius-s);
197
- background: transparent;
198
- color: var(--theme-elevation-800);
199
- font-size: 1rem;
156
+ gap: var(--spacer-2-5);
157
+ padding: var(--spacer-1) var(--spacer-2);
200
158
  text-align: start;
201
- cursor: pointer;
202
- }
203
-
204
- .fields-measurement__unit-option:hover {
205
- background: var(--theme-elevation-100);
206
159
  }
207
160
 
208
- .fields-measurement__unit-option[aria-selected="true"] {
209
- background: var(--theme-elevation-150);
161
+ .fields-measurement__unit-symbol {
162
+ color: var(--color-text-secondary);
210
163
  }
211
164
 
212
- .fields-measurement__unit-symbol {
213
- color: var(--theme-elevation-800);
214
- font-size: 0.75rem;
165
+ .fields-measurement__unit-option:is(:hover, [aria-selected="true"])
166
+ .fields-measurement__unit-symbol {
167
+ color: inherit;
215
168
  }
@@ -6,7 +6,7 @@ const isPreference = (value) => typeof value === "object" && value !== null && !
6
6
  /**
7
7
  * The viewer's saved unit map, one query per request however many measurement
8
8
  * fields the document renders. Mirrors Payload's own server-side preference
9
- * lookup (packages/next getPreferences): find on payload-preferences by key
9
+ * lookup (getPreferences): find on payload-preferences by key
10
10
  * and polymorphic user.
11
11
  */
12
12
  const getUserMeasurementUnits = (req) => {
@@ -18,6 +18,7 @@ const getUserMeasurementUnits = (req) => {
18
18
  collection: "payload-preferences",
19
19
  depth: 0,
20
20
  limit: 1,
21
+ overrideAccess: true,
21
22
  pagination: false,
22
23
  sort: "-updatedAt",
23
24
  where: { and: [
@@ -1 +1 @@
1
- {"version":3,"file":"getUserUnits.js","names":[],"sources":["../../../../src/fields/measurement/server/getUserUnits.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\nimport { memoForRequest } from '../../../utils/memoForRequest'\nimport { MEASUREMENT_PREFERENCE_KEY, type MeasurementUnitsPreference } from '../options'\n\nconst USER_UNITS_MEMO = Symbol('measurementField:userUnits')\n\nconst isPreference = (value: unknown): value is MeasurementUnitsPreference =>\n\ttypeof value === 'object' && value !== null && !Array.isArray(value)\n\n/**\n * The viewer's saved unit map, one query per request however many measurement\n * fields the document renders. Mirrors Payload's own server-side preference\n * lookup (packages/next getPreferences): find on payload-preferences by key\n * and polymorphic user.\n */\nexport const getUserMeasurementUnits = (\n\treq: PayloadRequest\n): Promise<MeasurementUnitsPreference | null> => {\n\tconst { user } = req\n\tif (!user) return Promise.resolve(null)\n\treturn memoForRequest(req, USER_UNITS_MEMO, async () => {\n\t\ttry {\n\t\t\tconst result = await req.payload.find({\n\t\t\t\tcollection: 'payload-preferences',\n\t\t\t\tdepth: 0,\n\t\t\t\tlimit: 1,\n\t\t\t\tpagination: false,\n\t\t\t\tsort: '-updatedAt',\n\t\t\t\twhere: {\n\t\t\t\t\tand: [\n\t\t\t\t\t\t{ key: { equals: MEASUREMENT_PREFERENCE_KEY } },\n\t\t\t\t\t\t{ 'user.value': { equals: user.id } },\n\t\t\t\t\t\t{ 'user.relationTo': { equals: user.collection } },\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t})\n\t\t\tconst value = result.docs[0]?.value\n\t\t\treturn isPreference(value) ? value : null\n\t\t} catch (error) {\n\t\t\treq.payload.logger.error({ err: error }, '[fields] measurement preference read failed')\n\t\t\treturn null\n\t\t}\n\t})\n}\n"],"mappings":";;;AAIA,MAAM,kBAAkB,OAAO,4BAA4B;AAE3D,MAAM,gBAAgB,UACrB,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;;;;;;;AAQpE,MAAa,2BACZ,QACgD;CAChD,MAAM,EAAE,SAAS;CACjB,IAAI,CAAC,MAAM,OAAO,QAAQ,QAAQ,IAAI;CACtC,OAAO,eAAe,KAAK,iBAAiB,YAAY;EACvD,IAAI;GAeH,MAAM,SAAQ,MAdO,IAAI,QAAQ,KAAK;IACrC,YAAY;IACZ,OAAO;IACP,OAAO;IACP,YAAY;IACZ,MAAM;IACN,OAAO,EACN,KAAK;KACJ,EAAE,KAAK,EAAE,QAAQ,2BAA2B,EAAE;KAC9C,EAAE,cAAc,EAAE,QAAQ,KAAK,GAAG,EAAE;KACpC,EAAE,mBAAmB,EAAE,QAAQ,KAAK,WAAW,EAAE;IAClD,EACD;GACD,CAAC,GACoB,KAAK,IAAI;GAC9B,OAAO,aAAa,KAAK,IAAI,QAAQ;EACtC,SAAS,OAAO;GACf,IAAI,QAAQ,OAAO,MAAM,EAAE,KAAK,MAAM,GAAG,6CAA6C;GACtF,OAAO;EACR;CACD,CAAC;AACF"}
1
+ {"version":3,"file":"getUserUnits.js","names":[],"sources":["../../../../src/fields/measurement/server/getUserUnits.ts"],"sourcesContent":["import type { PayloadRequest } from 'payload'\nimport { memoForRequest } from '../../../utils/memoForRequest'\nimport { MEASUREMENT_PREFERENCE_KEY, type MeasurementUnitsPreference } from '../options'\n\nconst USER_UNITS_MEMO = Symbol('measurementField:userUnits')\n\nconst isPreference = (value: unknown): value is MeasurementUnitsPreference =>\n\ttypeof value === 'object' && value !== null && !Array.isArray(value)\n\n/**\n * The viewer's saved unit map, one query per request however many measurement\n * fields the document renders. Mirrors Payload's own server-side preference\n * lookup (getPreferences): find on payload-preferences by key\n * and polymorphic user.\n */\nexport const getUserMeasurementUnits = (\n\treq: PayloadRequest\n): Promise<MeasurementUnitsPreference | null> => {\n\tconst { user } = req\n\tif (!user) return Promise.resolve(null)\n\treturn memoForRequest(req, USER_UNITS_MEMO, async () => {\n\t\ttry {\n\t\t\tconst result = await req.payload.find({\n\t\t\t\tcollection: 'payload-preferences',\n\t\t\t\tdepth: 0,\n\t\t\t\tlimit: 1,\n\t\t\t\t// Scoped to req.user by the where below, as Payload's own preference reads are.\n\t\t\t\toverrideAccess: true,\n\t\t\t\tpagination: false,\n\t\t\t\tsort: '-updatedAt',\n\t\t\t\twhere: {\n\t\t\t\t\tand: [\n\t\t\t\t\t\t{ key: { equals: MEASUREMENT_PREFERENCE_KEY } },\n\t\t\t\t\t\t{ 'user.value': { equals: user.id } },\n\t\t\t\t\t\t{ 'user.relationTo': { equals: user.collection } },\n\t\t\t\t\t],\n\t\t\t\t},\n\t\t\t})\n\t\t\tconst value = result.docs[0]?.value\n\t\t\treturn isPreference(value) ? value : null\n\t\t} catch (error) {\n\t\t\treq.payload.logger.error({ err: error }, '[fields] measurement preference read failed')\n\t\t\treturn null\n\t\t}\n\t})\n}\n"],"mappings":";;;AAIA,MAAM,kBAAkB,OAAO,4BAA4B;AAE3D,MAAM,gBAAgB,UACrB,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;;;;;;;AAQpE,MAAa,2BACZ,QACgD;CAChD,MAAM,EAAE,SAAS;CACjB,IAAI,CAAC,MAAM,OAAO,QAAQ,QAAQ,IAAI;CACtC,OAAO,eAAe,KAAK,iBAAiB,YAAY;EACvD,IAAI;GAiBH,MAAM,SAAQ,MAhBO,IAAI,QAAQ,KAAK;IACrC,YAAY;IACZ,OAAO;IACP,OAAO;IAEP,gBAAgB;IAChB,YAAY;IACZ,MAAM;IACN,OAAO,EACN,KAAK;KACJ,EAAE,KAAK,EAAE,QAAQ,2BAA2B,EAAE;KAC9C,EAAE,cAAc,EAAE,QAAQ,KAAK,GAAG,EAAE;KACpC,EAAE,mBAAmB,EAAE,QAAQ,KAAK,WAAW,EAAE;IAClD,EACD;GACD,CAAC,GACoB,KAAK,IAAI;GAC9B,OAAO,aAAa,KAAK,IAAI,QAAQ;EACtC,SAAS,OAAO;GACf,IAAI,QAAQ,OAAO,MAAM,EAAE,KAAK,MAAM,GAAG,6CAA6C;GACtF,OAAO;EACR;CACD,CAAC;AACF"}
@@ -4,14 +4,14 @@ import { useTranslation as useTranslation$1 } from "../../../translations/useTra
4
4
  import { CountryFlag } from "./CountryFlag.js";
5
5
  import { ChevronIcon, Popup, SearchIcon } from "@payloadcms/ui";
6
6
  import { useCallback, useEffect, useId, useMemo, useRef, useState } from "react";
7
- import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime";
7
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
8
8
  import "./phoneNumberField.css";
9
9
  import { useVirtualizer } from "@tanstack/react-virtual";
10
10
  //#region src/fields/phoneNumber/client/CountryPicker.tsx
11
11
  const baseClass = "fields-phone";
12
- const ROW_HEIGHT = 34;
12
+ const ROW_HEIGHT = 24;
13
13
  const estimateRow = () => ROW_HEIGHT;
14
- const LIST_MAX_HEIGHT = ROW_HEIGHT * 8;
14
+ const LIST_MAX_HEIGHT = ROW_HEIGHT * 10;
15
15
  const matchesQuery = (option, query) => {
16
16
  if (option.name.toLowerCase().includes(query)) return true;
17
17
  if (option.code.toLowerCase().startsWith(query)) return true;
@@ -51,7 +51,8 @@ const CountryPanel = ({ close, flags, onSelect, options, priorityLabel, value })
51
51
  const searchRef = useRef(null);
52
52
  const listId = useId();
53
53
  useEffect(() => {
54
- searchRef.current?.focus({ preventScroll: true });
54
+ const frame = requestAnimationFrame(() => searchRef.current?.focus({ preventScroll: true }));
55
+ return () => cancelAnimationFrame(frame);
55
56
  }, []);
56
57
  const rows = useMemo(() => buildRows(options, query.trim().toLowerCase(), priorityLabel), [
57
58
  options,
@@ -114,7 +115,7 @@ const CountryPanel = ({ close, flags, onSelect, options, priorityLabel, value })
114
115
  children: [/* @__PURE__ */ jsx("span", {
115
116
  "aria-hidden": "true",
116
117
  className: `${baseClass}__search-icon`,
117
- children: /* @__PURE__ */ jsx(SearchIcon, {})
118
+ children: /* @__PURE__ */ jsx(SearchIcon, { size: 24 })
118
119
  }), /* @__PURE__ */ jsx("input", {
119
120
  "aria-activedescendant": rows[activeRow]?.kind === "option" ? optionId(activeRow) : void 0,
120
121
  "aria-autocomplete": "list",
@@ -131,7 +132,7 @@ const CountryPanel = ({ close, flags, onSelect, options, priorityLabel, value })
131
132
  value: query
132
133
  })]
133
134
  }), /* @__PURE__ */ jsx("div", {
134
- className: `${baseClass}__list`,
135
+ className: `${baseClass}__list popup-button-list`,
135
136
  id: listId,
136
137
  ref: listRef,
137
138
  style: { maxHeight: LIST_MAX_HEIGHT },
@@ -169,7 +170,11 @@ const CountryPanel = ({ close, flags, onSelect, options, priorityLabel, value })
169
170
  "aria-posinset": optionRows.indexOf(item.index) + 1,
170
171
  "aria-selected": row.option.code === value,
171
172
  "aria-setsize": optionRows.length,
172
- className: `${baseClass}__option`,
173
+ className: [
174
+ `${baseClass}__option`,
175
+ "popup-button-list__button",
176
+ row.option.code === value && "popup-button-list__button--selected"
177
+ ].filter(Boolean).join(" "),
173
178
  "data-active": item.index === activeRow || void 0,
174
179
  id: optionId(item.index),
175
180
  onClick: () => select(row.option.code),
@@ -217,7 +222,7 @@ const CountryPicker = ({ disabled, flags, onSelect, options, priorityLabel, valu
217
222
  });
218
223
  };
219
224
  return /* @__PURE__ */ jsx(Popup, {
220
- button: /* @__PURE__ */ jsxs(Fragment$1, { children: [
225
+ button: /* @__PURE__ */ jsxs(Fragment, { children: [
221
226
  renderFace(),
222
227
  /* @__PURE__ */ jsx("span", {
223
228
  className: `${baseClass}__sr-only`,
@@ -226,7 +231,7 @@ const CountryPicker = ({ disabled, flags, onSelect, options, priorityLabel, valu
226
231
  /* @__PURE__ */ jsx("span", {
227
232
  "aria-hidden": "true",
228
233
  className: `${baseClass}__caret`,
229
- children: /* @__PURE__ */ jsx(ChevronIcon, { size: "small" })
234
+ children: /* @__PURE__ */ jsx(ChevronIcon, { size: 16 })
230
235
  })
231
236
  ] }),
232
237
  buttonClassName: `${baseClass}__trigger`,
@@ -1 +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\tvalue={value}\n\t\t\t\t\t/>\n\t\t\t\t) : null\n\t\t\t}\n\t\t\tsize=\"fit-content\"\n\t\t\tverticalAlign=\"bottom\"\n\t\t/>\n\t)\n}\n"],"mappings":";;;;;;;;;;AAcA,MAAM,YAAY;AAIlB,MAAM,aAAa;AACnB,MAAM,oBAAoB;AAK1B,MAAM,kBAAkB,aAAa;AAYrC,MAAM,gBAAgB,QAAuB,UAA2B;CACvE,IAAI,OAAO,KAAK,YAAY,EAAE,SAAS,KAAK,GAAG,OAAO;CACtD,IAAI,OAAO,KAAK,YAAY,EAAE,WAAW,KAAK,GAAG,OAAO;CACxD,MAAM,SAAS,MAAM,QAAQ,OAAO,EAAE;CACtC,OAAO,WAAW,MAAM,OAAO,YAAY,WAAW,MAAM;AAC7D;AAEA,MAAM,iBAAiB,SAA0B,UAChD,UAAU,KAAK,UAAU,QAAQ,QAAQ,WAAW,aAAa,QAAQ,KAAK,CAAC;;;;;;AAOhF,MAAM,aACL,SACA,OACA,kBACiB;CACjB,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AA,CAAA;EAEH,iBAAiB,GAAG,UAAU;EAC9B,YAAW;EACX,OAAO;EACP,WAAW,GAAG,UAAU;EACd;EACV,iBAAgB;EAChB,qBAAqB,QAAQ,KAAK;EAClC,oBAAoB,QAAQ,IAAI;EAChC,SAAS,EAAE,YACV,OACC,oBAAC,cAAD;GACQ;GACA;GACG;GACD;GACM;GACR;EACP,CAAA,IACE;EAEL,MAAK;EACL,eAAc;CACd,CAAA;AAEH"}
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. 24px is\n// Payload's popup list item: 4px of padding around the 16px body line.\nconst ROW_HEIGHT = 24\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 = 10\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. Deferred a\n\t// frame: this effect runs before Popup's own, which is what shows the popover, and an\n\t// element in a hidden popover cannot take focus.\n\tuseEffect(() => {\n\t\tconst frame = requestAnimationFrame(() => searchRef.current?.focus({ preventScroll: true }))\n\t\treturn () => cancelAnimationFrame(frame)\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 size={24} />\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 popup-button-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={[\n\t\t\t\t\t\t\t\t\t\t`${baseClass}__option`,\n\t\t\t\t\t\t\t\t\t\t'popup-button-list__button',\n\t\t\t\t\t\t\t\t\t\trow.option.code === value && 'popup-button-list__button--selected',\n\t\t\t\t\t\t\t\t\t]\n\t\t\t\t\t\t\t\t\t\t.filter(Boolean)\n\t\t\t\t\t\t\t\t\t\t.join(' ')}\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// @todo Payload 4's Popup pins its panel to the viewport edge once the field scrolls out of\n\t\t// view (v3 let it scroll away with the field). Adopt the option if Payload adds one.\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<ChevronIcon size={16} />\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\tvalue={value}\n\t\t\t\t\t/>\n\t\t\t\t) : null\n\t\t\t}\n\t\t\tsize=\"fit-content\"\n\t\t\tverticalAlign=\"bottom\"\n\t\t/>\n\t)\n}\n"],"mappings":";;;;;;;;;;AAcA,MAAM,YAAY;AAKlB,MAAM,aAAa;AACnB,MAAM,oBAAoB;AAK1B,MAAM,kBAAkB,aAAa;AAYrC,MAAM,gBAAgB,QAAuB,UAA2B;CACvE,IAAI,OAAO,KAAK,YAAY,EAAE,SAAS,KAAK,GAAG,OAAO;CACtD,IAAI,OAAO,KAAK,YAAY,EAAE,WAAW,KAAK,GAAG,OAAO;CACxD,MAAM,SAAS,MAAM,QAAQ,OAAO,EAAE;CACtC,OAAO,WAAW,MAAM,OAAO,YAAY,WAAW,MAAM;AAC7D;AAEA,MAAM,iBAAiB,SAA0B,UAChD,UAAU,KAAK,UAAU,QAAQ,QAAQ,WAAW,aAAa,QAAQ,KAAK,CAAC;;;;;;AAOhF,MAAM,aACL,SACA,OACA,kBACiB;CACjB,MAAM,WAAW,cAAc,QAAQ,UAAU,KAAK;CACtD,MAAM,OAAO,cAAc,QAAQ,MAAM,KAAK;CAC9C,MAAM,QAAQ,SAAS,SAAS,KAAK,KAAK,SAAS;CACnD,OAAO;EACN,GAAI,SAAS,kBAAkB,KAAA,IAC5B,CAAC;GAAE,MAAM;GAAW,OAAO;EAAc,CAAU,IACnD,CAAC;EACJ,GAAG,SAAS,KAAK,YAAY;GAAE,MAAM;GAAU;EAAO,EAAW;EACjE,GAAI,QAAQ,CAAC,EAAE,MAAM,UAAU,CAAU,IAAI,CAAC;E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;GACD;GACM;GACR;EACP,CAAA,IACE;EAEL,MAAK;EACL,eAAc;CACd,CAAA;AAEH"}
@@ -16,7 +16,7 @@ type PhoneNumberFieldProps = {
16
16
  seed?: null | PhoneSeed;
17
17
  } & Omit<GroupFieldClientProps, 'field'>;
18
18
  /**
19
- * One 40px row holding the country trigger, the calling-code prefix, a borderless entry and
19
+ * One native-height row holding the country trigger, the calling-code prefix, a borderless entry and
20
20
  * a clear affordance. `phoneOptions` must already be resolved through `resolvePhoneOptionsSafe`:
21
21
  * the field's own stamped layer carries no defaults and would render the wrong chrome.
22
22
  */
@@ -8,7 +8,7 @@ import { CountryPicker } from "./CountryPicker.js";
8
8
  import { detectCountry, parsePhone } from "../engine/phone.js";
9
9
  import { isInternational, provisionalCountry } from "../engine/draft.js";
10
10
  import { displayFor, dropCallingCode, formatDraft, resolveCommit } from "./editModel.js";
11
- import { FieldDescription, FieldError, FieldLabel, RenderCustomComponent, XIcon, fieldBaseClass, useField, useForm, useFormFields } from "@payloadcms/ui";
11
+ import { CircledXIcon, FieldDescription, FieldError, FieldLabel, RenderCustomComponent, fieldBaseClass, useField, useForm, useFormFields } from "@payloadcms/ui";
12
12
  import { mergeFieldStyles } from "@payloadcms/ui/shared";
13
13
  import { useCallback, useEffect, useMemo, useRef, useState } from "react";
14
14
  import { jsx, jsxs } from "react/jsx-runtime";
@@ -21,7 +21,7 @@ const NO_COUNTRIES = {
21
21
  rest: []
22
22
  };
23
23
  /**
24
- * One 40px row holding the country trigger, the calling-code prefix, a borderless entry and
24
+ * One native-height row holding the country trigger, the calling-code prefix, a borderless entry and
25
25
  * a clear affordance. `phoneOptions` must already be resolved through `resolvePhoneOptionsSafe`:
26
26
  * the field's own stamped layer carries no defaults and would render the wrong chrome.
27
27
  */
@@ -166,6 +166,20 @@ const PhoneNumberField = (props) => {
166
166
  debounceRef.current = null;
167
167
  }, []);
168
168
  useEffect(() => cancelPending, [cancelPending]);
169
+ useEffect(() => {
170
+ const input = inputRef.current;
171
+ if (!metadata || !editingRef.current || !input || draft === "") return;
172
+ if (input.selectionStart !== null && input.selectionStart !== draft.length) return;
173
+ const formatted = formatDraft({
174
+ atEnd: true,
175
+ callingCode,
176
+ country,
177
+ metadata,
178
+ previous: "",
179
+ raw: draft
180
+ });
181
+ if (formatted !== null && formatted !== draft) setDraft(formatted);
182
+ }, [metadata]);
169
183
  const onChange = useCallback((event) => {
170
184
  const input = event.target;
171
185
  const raw = input.value;
@@ -264,7 +278,11 @@ const PhoneNumberField = (props) => {
264
278
  }),
265
279
  BeforeInput,
266
280
  /* @__PURE__ */ jsxs("div", {
267
- className: `${baseClass}__container`,
281
+ className: [
282
+ `${baseClass}__container`,
283
+ "form-input-group",
284
+ hasError && "form-input-group-error"
285
+ ].filter(Boolean).join(" "),
268
286
  children: [
269
287
  /* @__PURE__ */ jsx(CountryPicker, {
270
288
  disabled: isReadOnly || metadata === null,
@@ -296,7 +314,7 @@ const PhoneNumberField = (props) => {
296
314
  className: `${baseClass}__clear`,
297
315
  onClick: onClear,
298
316
  type: "button",
299
- children: /* @__PURE__ */ jsx(XIcon, {})
317
+ children: /* @__PURE__ */ jsx(CircledXIcon, { size: 24 })
300
318
  }) : null
301
319
  ]
302
320
  }),
@@ -1 +1 @@
1
- {"version":3,"file":"PhoneNumberField.js","names":["useTranslation"],"sources":["../../../../src/fields/phoneNumber/client/PhoneNumberField.tsx"],"sourcesContent":["'use client'\n\nimport {\n\tFieldDescription,\n\tFieldError,\n\tFieldLabel,\n\tfieldBaseClass,\n\tRenderCustomComponent,\n\tuseField,\n\tuseForm,\n\tuseFormFields,\n\tXIcon,\n} from '@payloadcms/ui'\nimport { mergeFieldStyles } from '@payloadcms/ui/shared'\nimport type { GroupFieldClientProps, StaticLabel, TextFieldClientProps } from 'payload'\nimport type React from 'react'\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react'\nimport { keys } from '../../../translations/keys'\nimport { useTranslation } from '../../../translations/useTranslation'\nimport { resolveStaticLabel } from '../../../utils/resolveStaticLabel'\nimport { callingCodeFor, countryOptions } from '../engine/countries'\nimport { isInternational, type PhoneSeed, provisionalCountry } from '../engine/draft'\nimport { loadMetadata, type PhoneMetadata } from '../engine/metadata'\nimport { type CountryCode, detectCountry, parsePhone } from '../engine/phone'\nimport type { ResolvedPhoneOptions } from '../options'\nimport { type CountryOptionGroups, CountryPicker } from './CountryPicker'\nimport {\n\tdisplayFor,\n\tdropCallingCode,\n\tformatDraft,\n\ttype PhoneEntry,\n\tresolveCommit,\n} from './editModel'\nimport './phoneNumberField.css'\n\nconst baseClass = 'fields-phone'\nconst COMMIT_DELAY = 250\nconst NO_COUNTRIES: CountryOptionGroups = { priority: [], rest: [] }\n\n/**\n * Payload copies `required` and `admin.placeholder` onto the client field at runtime, but\n * `GroupFieldClient` types neither; the e164 variant is a `TextFieldClient` and types both.\n */\ntype PhonePassthrough = {\n\tadmin?: { placeholder?: StaticLabel; readOnly?: boolean }\n\trequired?: boolean\n}\n\n/**\n * `cellFormat` and `validation` are read only on the server, so they are neither shipped\n * nor readable here: reading `validation` client-side would state a verdict the server\n * has not reached.\n */\nexport type PhoneFieldClientOptions = Omit<ResolvedPhoneOptions, 'cellFormat' | 'validation'>\n\n/** A group under object storage, a text field under e164; the row is identical either way. */\nexport type PhoneNumberFieldProps = {\n\tfield: GroupFieldClientProps['field'] | TextFieldClientProps['field']\n\tphoneOptions: PhoneFieldClientOptions\n\t/** The stored row as the server already split it, painted until metadata lands. */\n\tseed?: null | PhoneSeed\n} & Omit<GroupFieldClientProps, 'field'>\n\n/**\n * One 40px row holding the country trigger, the calling-code prefix, a borderless entry and\n * a clear affordance. `phoneOptions` must already be resolved through `resolvePhoneOptionsSafe`:\n * the field's own stamped layer carries no defaults and would render the wrong chrome.\n */\nexport const PhoneNumberField: React.FC<PhoneNumberFieldProps> = (props) => {\n\tconst { field, path, phoneOptions, readOnly: readOnlyFromProps, seed } = props\n\tconst { admin: { className, description } = {}, label, localized } = field\n\tconst passthrough: PhonePassthrough = field\n\tconst { placeholder, readOnly: readOnlyFromAdmin } = passthrough.admin ?? {}\n\tconst required = passthrough.required ?? false\n\tconst {\n\t\tcountries,\n\t\tdefaultCountry,\n\t\tflags,\n\t\tisClearable,\n\t\tmetadata: metadataSet,\n\t\tpriorityCountries,\n\t\tpriorityCountriesLabel,\n\t\tstorage,\n\t} = phoneOptions\n\n\tconst { i18n, t } = useTranslation()\n\tconst { dispatchFields, setModified } = useForm()\n\tconst {\n\t\tcustomComponents: { AfterInput, BeforeInput, Description, Error: ErrorComponent, Label } = {},\n\t\tdisabled,\n\t\terrorPaths,\n\t\tformSubmitted,\n\t\tsetValue,\n\t\tshowError,\n\t\tvalue,\n\t} = useField<null | string>({ path })\n\n\t// Form state is flat by path: the group entry carries no value, so each subfield is read\n\t// at its own path and written there too.\n\tconst numberPath = `${path}.number`\n\tconst countryPath = `${path}.country`\n\tconst numberState = useFormFields(([fields]) => fields?.[numberPath]?.value)\n\tconst countryState = useFormFields(([fields]) => fields?.[countryPath]?.value)\n\n\tconst [metadata, setMetadata] = useState<null | PhoneMetadata>(null)\n\tuseEffect(() => {\n\t\tlet active = true\n\t\tloadMetadata(metadataSet)\n\t\t\t.then((loaded) => {\n\t\t\t\tif (active) setMetadata(loaded)\n\t\t\t})\n\t\t\t// A failed load degrades to unformatted entry; loadMetadata retries on a later mount\n\t\t\t.catch(() => undefined)\n\t\treturn () => {\n\t\t\tactive = false\n\t\t}\n\t}, [metadataSet])\n\n\tconst isE164 = storage === 'e164'\n\tconst [pickedCountry, setPickedCountry] = useState<CountryCode | undefined>(undefined)\n\n\tconst rawStored = isE164 ? value : numberState\n\tconst storedNumber = typeof rawStored === 'string' ? rawStored : ''\n\n\t// e164 storage has no country subfield, so the country is read back out of the number\n\tconst storedCountry = useMemo<CountryCode | undefined>(() => {\n\t\tif (!isE164) return typeof countryState === 'string' ? (countryState as CountryCode) : undefined\n\t\tif (!metadata || storedNumber === '') return undefined\n\t\treturn parsePhone(storedNumber, { defaultCountry: pickedCountry ?? defaultCountry, metadata })\n\t\t\t?.country\n\t}, [countryState, defaultCountry, isE164, metadata, pickedCountry, storedNumber])\n\n\t// The server's own derivation of the row, painted until the lazy metadata import lands so the\n\t// prefix and the entry never reflow. It describes one stored number, hence the match.\n\tconst seeded = metadata === null && seed?.number === storedNumber ? seed : null\n\n\tconst display = useMemo(\n\t\t() =>\n\t\t\tseeded?.national ??\n\t\t\tdisplayFor({ country: storedCountry, number: storedNumber || null }, metadata),\n\t\t[metadata, seeded, storedCountry, storedNumber]\n\t)\n\tconst [draft, setDraft] = useState(display)\n\tconst editingRef = useRef(false)\n\tuseEffect(() => {\n\t\tif (!editingRef.current) setDraft(display)\n\t}, [display])\n\n\t// The validated read refines the provisional one: `+1` is the United States on sight, and\n\t// stays so until enough digits arrive for libphonenumber to name Canada instead.\n\tconst draftCountry = useMemo(\n\t\t() =>\n\t\t\tmetadata && isInternational(draft)\n\t\t\t\t? (detectCountry(draft, { metadata }) ?? provisionalCountry(draft, { metadata }))\n\t\t\t\t: undefined,\n\t\t[draft, metadata]\n\t)\n\t// The pick outranks the stored country because e164 storage has no country column to write\n\t// it to: there the stored country is re-read off the number, which cannot know about a pick.\n\tconst country =\n\t\tdraftCountry ?? pickedCountry ?? storedCountry ?? seeded?.country ?? defaultCountry\n\n\tconst countriesKey = countries?.join()\n\tconst priorityKey = priorityCountries?.join()\n\t// biome-ignore lint/correctness/useExhaustiveDependencies: a form-state round trip hands the same allowlist back as a new array, so the contents are the dependency, not the identity\n\tconst options = useMemo(\n\t\t() =>\n\t\t\tmetadata\n\t\t\t\t? countryOptions({ countries, locale: i18n.language, metadata, priorityCountries })\n\t\t\t\t: NO_COUNTRIES,\n\t\t[countriesKey, i18n.language, metadata, priorityKey]\n\t)\n\t// Off the country, not off `options`: an allowlist that does not offer the stored country\n\t// would otherwise drop the prefix once metadata lands, reflowing the row back.\n\tconst callingCode = useMemo(\n\t\t() =>\n\t\t\t(country && metadata ? callingCodeFor(country, metadata) : undefined) ?? seeded?.callingCode,\n\t\t[country, metadata, seeded]\n\t)\n\n\t// The revert target for a non-clearable commit, tracked from stored values so a picked\n\t// country, a document load and a save response all count.\n\tconst lastValidRef = useRef<null | PhoneEntry>(null)\n\tuseEffect(() => {\n\t\tif (storedNumber === '' || !metadata) return\n\t\tif (parsePhone(storedNumber, { defaultCountry: storedCountry, metadata })?.valid) {\n\t\t\tlastValidRef.current = { country: storedCountry, number: storedNumber }\n\t\t}\n\t}, [metadata, storedCountry, storedNumber])\n\n\tconst write = useCallback(\n\t\t(entry: PhoneEntry) => {\n\t\t\tif (isE164) {\n\t\t\t\tsetValue(entry.number)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tdispatchFields({ type: 'UPDATE', path: numberPath, value: entry.number })\n\t\t\tdispatchFields({ type: 'UPDATE', path: countryPath, value: entry.country ?? null })\n\t\t\t// dispatchFields, unlike setValue, leaves the form unmodified\n\t\t\tsetModified(true)\n\t\t},\n\t\t[countryPath, dispatchFields, isE164, numberPath, setModified, setValue]\n\t)\n\n\tconst commit = useCallback(\n\t\t(raw: string, opts: { country?: CountryCode; salvage?: boolean } = {}): PhoneEntry => {\n\t\t\tconst { derived, ...entry } = resolveCommit({\n\t\t\t\tcountry: opts.country ?? country,\n\t\t\t\tdraft: raw,\n\t\t\t\tisClearable,\n\t\t\t\tlastValid: lastValidRef.current,\n\t\t\t\tmetadata,\n\t\t\t\tpicked: opts.country !== undefined,\n\t\t\t\tsalvage: opts.salvage === true,\n\t\t\t})\n\t\t\t// A pick speaks for the country only until the value speaks for itself, or it would\n\t\t\t// keep overriding every number committed after it.\n\t\t\tif (derived) setPickedCountry(undefined)\n\t\t\twrite(entry)\n\t\t\treturn entry\n\t\t},\n\t\t[country, isClearable, metadata, write]\n\t)\n\n\tconst debounceRef = useRef<null | ReturnType<typeof setTimeout>>(null)\n\tconst cancelPending = useCallback(() => {\n\t\tif (debounceRef.current) clearTimeout(debounceRef.current)\n\t\tdebounceRef.current = null\n\t}, [])\n\tuseEffect(() => cancelPending, [cancelPending])\n\n\tconst onChange = useCallback(\n\t\t(event: React.ChangeEvent<HTMLInputElement>) => {\n\t\t\tconst input = event.target\n\t\t\tconst raw = input.value\n\t\t\tconst caret = input.selectionStart\n\t\t\tconst next = formatDraft({\n\t\t\t\tatEnd: caret === null || caret === raw.length,\n\t\t\t\tcallingCode,\n\t\t\t\tcountry,\n\t\t\t\tmetadata,\n\t\t\t\tprevious: draft,\n\t\t\t\traw,\n\t\t\t})\n\t\t\tif (next === null) {\n\t\t\t\t// React re-renders nothing when the state is unchanged, so the refused line is put\n\t\t\t\t// back here, with the caret where the refused characters would have gone.\n\t\t\t\tconst at = Math.max((caret ?? raw.length) - (raw.length - draft.length), 0)\n\t\t\t\tinput.value = draft\n\t\t\t\tinput.setSelectionRange(at, at)\n\t\t\t\treturn\n\t\t\t}\n\t\t\teditingRef.current = true\n\t\t\tsetDraft(next)\n\t\t\tcancelPending()\n\t\t\tdebounceRef.current = setTimeout(() => commit(next), COMMIT_DELAY)\n\t\t},\n\t\t[callingCode, cancelPending, commit, country, draft, metadata]\n\t)\n\n\tconst onBlur = useCallback(() => {\n\t\tcancelPending()\n\t\tif (!editingRef.current) return\n\t\teditingRef.current = false\n\t\tsetDraft(displayFor(commit(draft, { salvage: true }), metadata))\n\t}, [cancelPending, commit, draft, metadata])\n\n\tconst selectCountry = useCallback(\n\t\t(code: CountryCode) => {\n\t\t\tcancelPending()\n\t\t\teditingRef.current = false\n\t\t\tsetPickedCountry(code)\n\t\t\tconst entry = commit(dropCallingCode(draft, metadata), { country: code })\n\t\t\tsetDraft(displayFor(entry, metadata))\n\t\t},\n\t\t[cancelPending, commit, draft, metadata]\n\t)\n\n\t// The clear control unmounts on the same commit that empties the field, so focus moves to\n\t// the input first; otherwise a keyboard viewer is dropped back to the document body.\n\tconst inputRef = useRef<HTMLInputElement>(null)\n\tconst onClear = useCallback(() => {\n\t\tcancelPending()\n\t\teditingRef.current = false\n\t\tsetPickedCountry(undefined)\n\t\tsetDraft('')\n\t\twrite({ country: undefined, number: null })\n\t\tinputRef.current?.focus()\n\t}, [cancelPending, write])\n\n\t// renderField only maps permissions into the readOnly clientProp; admin.readOnly reaches\n\t// custom Field components solely via clientField.admin\n\tconst isReadOnly = Boolean(readOnlyFromProps || disabled || readOnlyFromAdmin)\n\t// A child subfield's error marks the group invalid without giving it a message of its own\n\tconst hasError = showError || (formSubmitted && (errorPaths?.length ?? 0) > 0)\n\tconst showClear = isClearable && !required && !isReadOnly && (draft !== '' || storedNumber !== '')\n\tconst showPrefix = callingCode !== undefined && !isInternational(draft)\n\tconst styles = useMemo(() => mergeFieldStyles(field), [field])\n\n\treturn (\n\t\t<div\n\t\t\tclassName={[\n\t\t\t\tfieldBaseClass,\n\t\t\t\tbaseClass,\n\t\t\t\tclassName,\n\t\t\t\thasError && 'error',\n\t\t\t\tisReadOnly && 'read-only',\n\t\t\t]\n\t\t\t\t.filter(Boolean)\n\t\t\t\t.join(' ')}\n\t\t\tstyle={styles}\n\t\t>\n\t\t\t<RenderCustomComponent\n\t\t\t\tCustomComponent={Label}\n\t\t\t\tFallback={\n\t\t\t\t\t<FieldLabel label={label} localized={localized} path={path} required={required} />\n\t\t\t\t}\n\t\t\t/>\n\t\t\t<div className={`${fieldBaseClass}__wrap`}>\n\t\t\t\t<RenderCustomComponent\n\t\t\t\t\tCustomComponent={ErrorComponent}\n\t\t\t\t\tFallback={<FieldError path={path} showError={hasError} />}\n\t\t\t\t/>\n\t\t\t\t{BeforeInput}\n\t\t\t\t<div className={`${baseClass}__container`}>\n\t\t\t\t\t<CountryPicker\n\t\t\t\t\t\tdisabled={isReadOnly || metadata === null}\n\t\t\t\t\t\tflags={flags}\n\t\t\t\t\t\tonSelect={selectCountry}\n\t\t\t\t\t\toptions={options}\n\t\t\t\t\t\tpriorityLabel={resolveStaticLabel(priorityCountriesLabel, i18n.language)}\n\t\t\t\t\t\tvalue={country}\n\t\t\t\t\t/>\n\t\t\t\t\t{showPrefix ? <span className={`${baseClass}__prefix`}>{`+${callingCode}`}</span> : null}\n\t\t\t\t\t<input\n\t\t\t\t\t\tclassName={`${baseClass}__input`}\n\t\t\t\t\t\tid={`field-${path.replace(/\\./g, '__')}`}\n\t\t\t\t\t\tinputMode=\"tel\"\n\t\t\t\t\t\tname={path}\n\t\t\t\t\t\tonBlur={onBlur}\n\t\t\t\t\t\tonChange={onChange}\n\t\t\t\t\t\tplaceholder={resolveStaticLabel(placeholder, i18n.language)}\n\t\t\t\t\t\treadOnly={isReadOnly}\n\t\t\t\t\t\tref={inputRef}\n\t\t\t\t\t\ttype=\"tel\"\n\t\t\t\t\t\tvalue={draft}\n\t\t\t\t\t/>\n\t\t\t\t\t{showClear ? (\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\taria-label={t(keys.clearPhoneNumber)}\n\t\t\t\t\t\t\tclassName={`${baseClass}__clear`}\n\t\t\t\t\t\t\tonClick={onClear}\n\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<XIcon />\n\t\t\t\t\t\t</button>\n\t\t\t\t\t) : null}\n\t\t\t\t</div>\n\t\t\t\t{AfterInput}\n\t\t\t\t<RenderCustomComponent\n\t\t\t\t\tCustomComponent={Description}\n\t\t\t\t\tFallback={<FieldDescription description={description} path={path} />}\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</div>\n\t)\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAmCA,MAAM,YAAY;AAClB,MAAM,eAAe;AACrB,MAAM,eAAoC;CAAE,UAAU,CAAC;CAAG,MAAM,CAAC;AAAE;;;;;;AA+BnE,MAAa,oBAAqD,UAAU;CAC3E,MAAM,EAAE,OAAO,MAAM,cAAc,UAAU,mBAAmB,SAAS;CACzE,MAAM,EAAE,OAAO,EAAE,WAAW,gBAAgB,CAAC,GAAG,OAAO,cAAc;CACrE,MAAM,cAAgC;CACtC,MAAM,EAAE,aAAa,UAAU,sBAAsB,YAAY,SAAS,CAAC;CAC3E,MAAM,WAA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B,UAAU,oBAAC,YAAD;MAAkB;MAAM,WAAW;KAAW,CAAA;IACxD,CAAA;IACA;IACD,qBAAC,OAAD;KAAK,WAAW,GAAG,UAAU;eAA7B;MACC,oBAAC,eAAD;OACC,UAAU,cAAc,aAAa;OAC9B;OACP,UAAU;OACD;OACT,eAAe,mBAAmB,wBAAwB,KAAK,QAAQ;OACvE,OAAO;MACP,CAAA;MACA,aAAa,oBAAC,QAAD;OAAM,WAAW,GAAG,UAAU;iBAAY,IAAI;MAAoB,CAAA,IAAI;MACpF,oBAAC,SAAD;OACC,WAAW,GAAG,UAAU;OACxB,IAAI,SAAS,KAAK,QAAQ,OAAO,IAAI;OACrC,WAAU;OACV,MAAM;OACE;OACE;OACV,aAAa,mBAAmB,aAAa,KAAK,QAAQ;OAC1D,UAAU;OACV,KAAK;OACL,MAAK;OACL,OAAO;MACP,CAAA;MACA,YACA,oBAAC,UAAD;OACC,cAAY,EAAE,KAAK,gBAAgB;OACnC,WAAW,GAAG,UAAU;OACxB,SAAS;OACT,MAAK;iBAEL,oBAAC,OAAD,CAAQ,CAAA;MACD,CAAA,IACL;KACA;;IACJ;IACD,oBAAC,uBAAD;KACC,iBAAiB;KACjB,UAAU,oBAAC,kBAAD;MAA+B;MAAmB;KAAO,CAAA;IACnE,CAAA;GACG;IACD;;AAEP"}
1
+ {"version":3,"file":"PhoneNumberField.js","names":["useTranslation"],"sources":["../../../../src/fields/phoneNumber/client/PhoneNumberField.tsx"],"sourcesContent":["'use client'\n\nimport {\n\tCircledXIcon,\n\tFieldDescription,\n\tFieldError,\n\tFieldLabel,\n\tfieldBaseClass,\n\tRenderCustomComponent,\n\tuseField,\n\tuseForm,\n\tuseFormFields,\n} from '@payloadcms/ui'\nimport { mergeFieldStyles } from '@payloadcms/ui/shared'\nimport type { GroupFieldClientProps, StaticLabel, TextFieldClientProps } from 'payload'\nimport type React from 'react'\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react'\nimport { keys } from '../../../translations/keys'\nimport { useTranslation } from '../../../translations/useTranslation'\nimport { resolveStaticLabel } from '../../../utils/resolveStaticLabel'\nimport { callingCodeFor, countryOptions } from '../engine/countries'\nimport { isInternational, type PhoneSeed, provisionalCountry } from '../engine/draft'\nimport { loadMetadata, type PhoneMetadata } from '../engine/metadata'\nimport { type CountryCode, detectCountry, parsePhone } from '../engine/phone'\nimport type { ResolvedPhoneOptions } from '../options'\nimport { type CountryOptionGroups, CountryPicker } from './CountryPicker'\nimport {\n\tdisplayFor,\n\tdropCallingCode,\n\tformatDraft,\n\ttype PhoneEntry,\n\tresolveCommit,\n} from './editModel'\nimport './phoneNumberField.css'\n\nconst baseClass = 'fields-phone'\nconst COMMIT_DELAY = 250\nconst NO_COUNTRIES: CountryOptionGroups = { priority: [], rest: [] }\n\n/**\n * Payload copies `required` and `admin.placeholder` onto the client field at runtime, but\n * `GroupFieldClient` types neither; the e164 variant is a `TextFieldClient` and types both.\n */\ntype PhonePassthrough = {\n\tadmin?: { placeholder?: StaticLabel; readOnly?: boolean }\n\trequired?: boolean\n}\n\n/**\n * `cellFormat` and `validation` are read only on the server, so they are neither shipped\n * nor readable here: reading `validation` client-side would state a verdict the server\n * has not reached.\n */\nexport type PhoneFieldClientOptions = Omit<ResolvedPhoneOptions, 'cellFormat' | 'validation'>\n\n/** A group under object storage, a text field under e164; the row is identical either way. */\nexport type PhoneNumberFieldProps = {\n\tfield: GroupFieldClientProps['field'] | TextFieldClientProps['field']\n\tphoneOptions: PhoneFieldClientOptions\n\t/** The stored row as the server already split it, painted until metadata lands. */\n\tseed?: null | PhoneSeed\n} & Omit<GroupFieldClientProps, 'field'>\n\n/**\n * One native-height row holding the country trigger, the calling-code prefix, a borderless entry and\n * a clear affordance. `phoneOptions` must already be resolved through `resolvePhoneOptionsSafe`:\n * the field's own stamped layer carries no defaults and would render the wrong chrome.\n */\nexport const PhoneNumberField: React.FC<PhoneNumberFieldProps> = (props) => {\n\tconst { field, path, phoneOptions, readOnly: readOnlyFromProps, seed } = props\n\tconst { admin: { className, description } = {}, label, localized } = field\n\tconst passthrough: PhonePassthrough = field\n\tconst { placeholder, readOnly: readOnlyFromAdmin } = passthrough.admin ?? {}\n\tconst required = passthrough.required ?? false\n\tconst {\n\t\tcountries,\n\t\tdefaultCountry,\n\t\tflags,\n\t\tisClearable,\n\t\tmetadata: metadataSet,\n\t\tpriorityCountries,\n\t\tpriorityCountriesLabel,\n\t\tstorage,\n\t} = phoneOptions\n\n\tconst { i18n, t } = useTranslation()\n\tconst { dispatchFields, setModified } = useForm()\n\tconst {\n\t\tcustomComponents: { AfterInput, BeforeInput, Description, Error: ErrorComponent, Label } = {},\n\t\tdisabled,\n\t\terrorPaths,\n\t\tformSubmitted,\n\t\tsetValue,\n\t\tshowError,\n\t\tvalue,\n\t} = useField<null | string>({ path })\n\n\t// Form state is flat by path: the group entry carries no value, so each subfield is read\n\t// at its own path and written there too.\n\tconst numberPath = `${path}.number`\n\tconst countryPath = `${path}.country`\n\tconst numberState = useFormFields(([fields]) => fields?.[numberPath]?.value)\n\tconst countryState = useFormFields(([fields]) => fields?.[countryPath]?.value)\n\n\tconst [metadata, setMetadata] = useState<null | PhoneMetadata>(null)\n\tuseEffect(() => {\n\t\tlet active = true\n\t\tloadMetadata(metadataSet)\n\t\t\t.then((loaded) => {\n\t\t\t\tif (active) setMetadata(loaded)\n\t\t\t})\n\t\t\t// A failed load degrades to unformatted entry; loadMetadata retries on a later mount\n\t\t\t.catch(() => undefined)\n\t\treturn () => {\n\t\t\tactive = false\n\t\t}\n\t}, [metadataSet])\n\n\tconst isE164 = storage === 'e164'\n\tconst [pickedCountry, setPickedCountry] = useState<CountryCode | undefined>(undefined)\n\n\tconst rawStored = isE164 ? value : numberState\n\tconst storedNumber = typeof rawStored === 'string' ? rawStored : ''\n\n\t// e164 storage has no country subfield, so the country is read back out of the number\n\tconst storedCountry = useMemo<CountryCode | undefined>(() => {\n\t\tif (!isE164) return typeof countryState === 'string' ? (countryState as CountryCode) : undefined\n\t\tif (!metadata || storedNumber === '') return undefined\n\t\treturn parsePhone(storedNumber, { defaultCountry: pickedCountry ?? defaultCountry, metadata })\n\t\t\t?.country\n\t}, [countryState, defaultCountry, isE164, metadata, pickedCountry, storedNumber])\n\n\t// The server's own derivation of the row, painted until the lazy metadata import lands so the\n\t// prefix and the entry never reflow. It describes one stored number, hence the match.\n\tconst seeded = metadata === null && seed?.number === storedNumber ? seed : null\n\n\tconst display = useMemo(\n\t\t() =>\n\t\t\tseeded?.national ??\n\t\t\tdisplayFor({ country: storedCountry, number: storedNumber || null }, metadata),\n\t\t[metadata, seeded, storedCountry, storedNumber]\n\t)\n\tconst [draft, setDraft] = useState(display)\n\tconst editingRef = useRef(false)\n\tuseEffect(() => {\n\t\tif (!editingRef.current) setDraft(display)\n\t}, [display])\n\n\t// The validated read refines the provisional one: `+1` is the United States on sight, and\n\t// stays so until enough digits arrive for libphonenumber to name Canada instead.\n\tconst draftCountry = useMemo(\n\t\t() =>\n\t\t\tmetadata && isInternational(draft)\n\t\t\t\t? (detectCountry(draft, { metadata }) ?? provisionalCountry(draft, { metadata }))\n\t\t\t\t: undefined,\n\t\t[draft, metadata]\n\t)\n\t// The pick outranks the stored country because e164 storage has no country column to write\n\t// it to: there the stored country is re-read off the number, which cannot know about a pick.\n\tconst country =\n\t\tdraftCountry ?? pickedCountry ?? storedCountry ?? seeded?.country ?? defaultCountry\n\n\tconst countriesKey = countries?.join()\n\tconst priorityKey = priorityCountries?.join()\n\t// biome-ignore lint/correctness/useExhaustiveDependencies: a form-state round trip hands the same allowlist back as a new array, so the contents are the dependency, not the identity\n\tconst options = useMemo(\n\t\t() =>\n\t\t\tmetadata\n\t\t\t\t? countryOptions({ countries, locale: i18n.language, metadata, priorityCountries })\n\t\t\t\t: NO_COUNTRIES,\n\t\t[countriesKey, i18n.language, metadata, priorityKey]\n\t)\n\t// Off the country, not off `options`: an allowlist that does not offer the stored country\n\t// would otherwise drop the prefix once metadata lands, reflowing the row back.\n\tconst callingCode = useMemo(\n\t\t() =>\n\t\t\t(country && metadata ? callingCodeFor(country, metadata) : undefined) ?? seeded?.callingCode,\n\t\t[country, metadata, seeded]\n\t)\n\n\t// The revert target for a non-clearable commit, tracked from stored values so a picked\n\t// country, a document load and a save response all count.\n\tconst lastValidRef = useRef<null | PhoneEntry>(null)\n\tuseEffect(() => {\n\t\tif (storedNumber === '' || !metadata) return\n\t\tif (parsePhone(storedNumber, { defaultCountry: storedCountry, metadata })?.valid) {\n\t\t\tlastValidRef.current = { country: storedCountry, number: storedNumber }\n\t\t}\n\t}, [metadata, storedCountry, storedNumber])\n\n\tconst write = useCallback(\n\t\t(entry: PhoneEntry) => {\n\t\t\tif (isE164) {\n\t\t\t\tsetValue(entry.number)\n\t\t\t\treturn\n\t\t\t}\n\t\t\tdispatchFields({ type: 'UPDATE', path: numberPath, value: entry.number })\n\t\t\tdispatchFields({ type: 'UPDATE', path: countryPath, value: entry.country ?? null })\n\t\t\t// dispatchFields, unlike setValue, leaves the form unmodified\n\t\t\tsetModified(true)\n\t\t},\n\t\t[countryPath, dispatchFields, isE164, numberPath, setModified, setValue]\n\t)\n\n\tconst commit = useCallback(\n\t\t(raw: string, opts: { country?: CountryCode; salvage?: boolean } = {}): PhoneEntry => {\n\t\t\tconst { derived, ...entry } = resolveCommit({\n\t\t\t\tcountry: opts.country ?? country,\n\t\t\t\tdraft: raw,\n\t\t\t\tisClearable,\n\t\t\t\tlastValid: lastValidRef.current,\n\t\t\t\tmetadata,\n\t\t\t\tpicked: opts.country !== undefined,\n\t\t\t\tsalvage: opts.salvage === true,\n\t\t\t})\n\t\t\t// A pick speaks for the country only until the value speaks for itself, or it would\n\t\t\t// keep overriding every number committed after it.\n\t\t\tif (derived) setPickedCountry(undefined)\n\t\t\twrite(entry)\n\t\t\treturn entry\n\t\t},\n\t\t[country, isClearable, metadata, write]\n\t)\n\n\tconst debounceRef = useRef<null | ReturnType<typeof setTimeout>>(null)\n\tconst cancelPending = useCallback(() => {\n\t\tif (debounceRef.current) clearTimeout(debounceRef.current)\n\t\tdebounceRef.current = null\n\t}, [])\n\tuseEffect(() => cancelPending, [cancelPending])\n\n\t// Typed or pasted before the lazy metadata landed, the draft went in unformatted; format it\n\t// once on arrival, but only with the caret at the end, so the reformat cannot move it.\n\t// biome-ignore lint/correctness/useExhaustiveDependencies: the metadata arrival is the trigger, not every keystroke\n\tuseEffect(() => {\n\t\tconst input = inputRef.current\n\t\tif (!metadata || !editingRef.current || !input || draft === '') return\n\t\tif (input.selectionStart !== null && input.selectionStart !== draft.length) return\n\t\tconst formatted = formatDraft({\n\t\t\tatEnd: true,\n\t\t\tcallingCode,\n\t\t\tcountry,\n\t\t\tmetadata,\n\t\t\tprevious: '',\n\t\t\traw: draft,\n\t\t})\n\t\tif (formatted !== null && formatted !== draft) setDraft(formatted)\n\t}, [metadata])\n\n\tconst onChange = useCallback(\n\t\t(event: React.ChangeEvent<HTMLInputElement>) => {\n\t\t\tconst input = event.target\n\t\t\tconst raw = input.value\n\t\t\tconst caret = input.selectionStart\n\t\t\tconst next = formatDraft({\n\t\t\t\tatEnd: caret === null || caret === raw.length,\n\t\t\t\tcallingCode,\n\t\t\t\tcountry,\n\t\t\t\tmetadata,\n\t\t\t\tprevious: draft,\n\t\t\t\traw,\n\t\t\t})\n\t\t\tif (next === null) {\n\t\t\t\t// React re-renders nothing when the state is unchanged, so the refused line is put\n\t\t\t\t// back here, with the caret where the refused characters would have gone.\n\t\t\t\tconst at = Math.max((caret ?? raw.length) - (raw.length - draft.length), 0)\n\t\t\t\tinput.value = draft\n\t\t\t\tinput.setSelectionRange(at, at)\n\t\t\t\treturn\n\t\t\t}\n\t\t\teditingRef.current = true\n\t\t\tsetDraft(next)\n\t\t\tcancelPending()\n\t\t\tdebounceRef.current = setTimeout(() => commit(next), COMMIT_DELAY)\n\t\t},\n\t\t[callingCode, cancelPending, commit, country, draft, metadata]\n\t)\n\n\tconst onBlur = useCallback(() => {\n\t\tcancelPending()\n\t\tif (!editingRef.current) return\n\t\teditingRef.current = false\n\t\tsetDraft(displayFor(commit(draft, { salvage: true }), metadata))\n\t}, [cancelPending, commit, draft, metadata])\n\n\tconst selectCountry = useCallback(\n\t\t(code: CountryCode) => {\n\t\t\tcancelPending()\n\t\t\teditingRef.current = false\n\t\t\tsetPickedCountry(code)\n\t\t\tconst entry = commit(dropCallingCode(draft, metadata), { country: code })\n\t\t\tsetDraft(displayFor(entry, metadata))\n\t\t},\n\t\t[cancelPending, commit, draft, metadata]\n\t)\n\n\t// The clear control unmounts on the same commit that empties the field, so focus moves to\n\t// the input first; otherwise a keyboard viewer is dropped back to the document body.\n\tconst inputRef = useRef<HTMLInputElement>(null)\n\tconst onClear = useCallback(() => {\n\t\tcancelPending()\n\t\teditingRef.current = false\n\t\tsetPickedCountry(undefined)\n\t\tsetDraft('')\n\t\twrite({ country: undefined, number: null })\n\t\tinputRef.current?.focus()\n\t}, [cancelPending, write])\n\n\t// renderField only maps permissions into the readOnly clientProp; admin.readOnly reaches\n\t// custom Field components solely via clientField.admin\n\tconst isReadOnly = Boolean(readOnlyFromProps || disabled || readOnlyFromAdmin)\n\t// A child subfield's error marks the group invalid without giving it a message of its own\n\tconst hasError = showError || (formSubmitted && (errorPaths?.length ?? 0) > 0)\n\tconst showClear = isClearable && !required && !isReadOnly && (draft !== '' || storedNumber !== '')\n\tconst showPrefix = callingCode !== undefined && !isInternational(draft)\n\tconst styles = useMemo(() => mergeFieldStyles(field), [field])\n\n\treturn (\n\t\t<div\n\t\t\tclassName={[\n\t\t\t\tfieldBaseClass,\n\t\t\t\tbaseClass,\n\t\t\t\tclassName,\n\t\t\t\thasError && 'error',\n\t\t\t\tisReadOnly && 'read-only',\n\t\t\t]\n\t\t\t\t.filter(Boolean)\n\t\t\t\t.join(' ')}\n\t\t\tstyle={styles}\n\t\t>\n\t\t\t<RenderCustomComponent\n\t\t\t\tCustomComponent={Label}\n\t\t\t\tFallback={\n\t\t\t\t\t<FieldLabel label={label} localized={localized} path={path} required={required} />\n\t\t\t\t}\n\t\t\t/>\n\t\t\t<div className={`${fieldBaseClass}__wrap`}>\n\t\t\t\t<RenderCustomComponent\n\t\t\t\t\tCustomComponent={ErrorComponent}\n\t\t\t\t\tFallback={<FieldError path={path} showError={hasError} />}\n\t\t\t\t/>\n\t\t\t\t{BeforeInput}\n\t\t\t\t<div\n\t\t\t\t\tclassName={[\n\t\t\t\t\t\t`${baseClass}__container`,\n\t\t\t\t\t\t'form-input-group',\n\t\t\t\t\t\thasError && 'form-input-group-error',\n\t\t\t\t\t]\n\t\t\t\t\t\t.filter(Boolean)\n\t\t\t\t\t\t.join(' ')}\n\t\t\t\t>\n\t\t\t\t\t<CountryPicker\n\t\t\t\t\t\tdisabled={isReadOnly || metadata === null}\n\t\t\t\t\t\tflags={flags}\n\t\t\t\t\t\tonSelect={selectCountry}\n\t\t\t\t\t\toptions={options}\n\t\t\t\t\t\tpriorityLabel={resolveStaticLabel(priorityCountriesLabel, i18n.language)}\n\t\t\t\t\t\tvalue={country}\n\t\t\t\t\t/>\n\t\t\t\t\t{showPrefix ? <span className={`${baseClass}__prefix`}>{`+${callingCode}`}</span> : null}\n\t\t\t\t\t<input\n\t\t\t\t\t\tclassName={`${baseClass}__input`}\n\t\t\t\t\t\tid={`field-${path.replace(/\\./g, '__')}`}\n\t\t\t\t\t\tinputMode=\"tel\"\n\t\t\t\t\t\tname={path}\n\t\t\t\t\t\tonBlur={onBlur}\n\t\t\t\t\t\tonChange={onChange}\n\t\t\t\t\t\tplaceholder={resolveStaticLabel(placeholder, i18n.language)}\n\t\t\t\t\t\treadOnly={isReadOnly}\n\t\t\t\t\t\tref={inputRef}\n\t\t\t\t\t\ttype=\"tel\"\n\t\t\t\t\t\tvalue={draft}\n\t\t\t\t\t/>\n\t\t\t\t\t{showClear ? (\n\t\t\t\t\t\t<button\n\t\t\t\t\t\t\taria-label={t(keys.clearPhoneNumber)}\n\t\t\t\t\t\t\tclassName={`${baseClass}__clear`}\n\t\t\t\t\t\t\tonClick={onClear}\n\t\t\t\t\t\t\ttype=\"button\"\n\t\t\t\t\t\t>\n\t\t\t\t\t\t\t<CircledXIcon size={24} />\n\t\t\t\t\t\t</button>\n\t\t\t\t\t) : null}\n\t\t\t\t</div>\n\t\t\t\t{AfterInput}\n\t\t\t\t<RenderCustomComponent\n\t\t\t\t\tCustomComponent={Description}\n\t\t\t\t\tFallback={<FieldDescription description={description} path={path} />}\n\t\t\t\t/>\n\t\t\t</div>\n\t\t</div>\n\t)\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAmCA,MAAM,YAAY;AAClB,MAAM,eAAe;AACrB,MAAM,eAAoC;CAAE,UAAU,CAAC;CAAG,MAAM,CAAC;AAAE;;;;;;AA+BnE,MAAa,oBAAqD,UAAU;CAC3E,MAAM,EAAE,OAAO,MAAM,cAAc,UAAU,mBAAmB,SAAS;CACzE,MAAM,EAAE,OAAO,EAAE,WAAW,gBAAgB,CAAC,GAAG,OAAO,cAAc;CACrE,MAAM,cAAgC;CACtC,MAAM,EAAE,aAAa,UAAU,sBAAsB,YAAY,SAAS,CAAC;CAC3E,MAAM,WAAW,YAAY,YAAY;CACzC,MAAM,EACL,WACA,gBACA,OACA,aACA,UAAU,aACV,mBACA,wBACA,YACG;CAEJ,MAAM,EAAE,MAAM,MAAMA,iBAAe;CACnC,MAAM,EAAE,gBAAgB,gBAAgB,QAAQ;CAChD,MAAM,EACL,kBAAkB,EAAE,YAAY,aAAa,aAAa,OAAO,gBAAgB,UAAU,CAAC,GAC5F,UACA,YACA,eACA,UACA,WACA,UACG,SAAwB,EAAE,KAAK,CAAC;CAIpC,MAAM,aAAa,GAAG,KAAK;CAC3B,MAAM,cAAc,GAAG,KAAK;CAC5B,MAAM,cAAc,eAAe,CAAC,YAAY,SAAS,aAAa,KAAK;CAC3E,MAAM,eAAe,eAAe,CAAC,YAAY,SAAS,cAAc,KAAK;CAE7E,MAAM,CAAC,UAAU,eAAe,SAA+B,IAAI;CACnE,gBAAgB;EACf,IAAI,SAAS;EACb,aAAa,WAAW,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