@redvars/peacock 4.5.1 → 4.6.1

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 (256) hide show
  1. package/dist/{BaseField-BbOj212R.js → BaseField-DOCmylob.js} +16 -3
  2. package/dist/BaseField-DOCmylob.js.map +1 -0
  3. package/dist/accordion.js +1 -1
  4. package/dist/activation-gate-D4IpmwyD.js +23 -0
  5. package/dist/activation-gate-D4IpmwyD.js.map +1 -0
  6. package/dist/avatar-group.js +2 -1
  7. package/dist/avatar-group.js.map +1 -1
  8. package/dist/avatar.js +3 -0
  9. package/dist/avatar.js.map +1 -1
  10. package/dist/{base-button-BJMGMcMv.js → base-button-9tGu5RSC.js} +30 -10
  11. package/dist/base-button-9tGu5RSC.js.map +1 -0
  12. package/dist/button-group.js +5 -3
  13. package/dist/button-group.js.map +1 -1
  14. package/dist/button.js +12 -16
  15. package/dist/button.js.map +1 -1
  16. package/dist/calendar-column-view.js +4 -4
  17. package/dist/{calendar-drag-IXMPZrTN.js → calendar-drag-DdJwSpEz.js} +2 -2
  18. package/dist/{calendar-drag-IXMPZrTN.js.map → calendar-drag-DdJwSpEz.js.map} +1 -1
  19. package/dist/{calendar-event-BQChlMXy.js → calendar-event-BvbYZHx1.js} +2 -2
  20. package/dist/{calendar-event-BQChlMXy.js.map → calendar-event-BvbYZHx1.js.map} +1 -1
  21. package/dist/calendar-month-view.js +65 -14
  22. package/dist/calendar-month-view.js.map +1 -1
  23. package/dist/calendar-timeline.js +9 -4
  24. package/dist/calendar-timeline.js.map +1 -1
  25. package/dist/calendar.js +21 -6
  26. package/dist/calendar.js.map +1 -1
  27. package/dist/card.js +29 -16
  28. package/dist/card.js.map +1 -1
  29. package/dist/chart-doughnut.js +3 -1
  30. package/dist/chart-doughnut.js.map +1 -1
  31. package/dist/chart-pie.js +9 -1
  32. package/dist/chart-pie.js.map +1 -1
  33. package/dist/chip-set.js +1 -1
  34. package/dist/chip.js +10 -19
  35. package/dist/chip.js.map +1 -1
  36. package/dist/code-editor.js +56 -5
  37. package/dist/code-editor.js.map +1 -1
  38. package/dist/color-field.js +4 -1
  39. package/dist/color-field.js.map +1 -1
  40. package/dist/currency-field.js +4 -1
  41. package/dist/currency-field.js.map +1 -1
  42. package/dist/custom-elements-jsdocs.json +29 -23
  43. package/dist/custom-elements.json +758 -93
  44. package/dist/{datasource-OwvH7SVq.js → datasource-DxEA6jHW.js} +6 -4
  45. package/dist/datasource-DxEA6jHW.js.map +1 -0
  46. package/dist/{date-cfPx3alz.js → date-DPQOY8Zd.js} +2 -2
  47. package/dist/{date-cfPx3alz.js.map → date-DPQOY8Zd.js.map} +1 -1
  48. package/dist/date-field.js +8 -5
  49. package/dist/date-field.js.map +1 -1
  50. package/dist/date-picker.js +2 -2
  51. package/dist/date-range-field.js +8 -5
  52. package/dist/date-range-field.js.map +1 -1
  53. package/dist/datetime-field.js +7 -4
  54. package/dist/datetime-field.js.map +1 -1
  55. package/dist/diagram-controls.js +1 -1
  56. package/dist/{throttle-SQ9t-HL7.js → dispatch-event-utils-DfgqVBK8.js} +2 -24
  57. package/dist/dispatch-event-utils-DfgqVBK8.js.map +1 -0
  58. package/dist/{form-submitter-beG1CXAn.js → dispatch-hooks-J_godlHh.js} +2 -87
  59. package/dist/dispatch-hooks-J_godlHh.js.map +1 -0
  60. package/dist/dropdown-button.js +11 -7
  61. package/dist/dropdown-button.js.map +1 -1
  62. package/dist/{event-manager-KGMT2x2Q.js → event-manager-DYfeN3VE.js} +3 -3
  63. package/dist/{event-manager-KGMT2x2Q.js.map → event-manager-DYfeN3VE.js.map} +1 -1
  64. package/dist/fab.js +15 -19
  65. package/dist/fab.js.map +1 -1
  66. package/dist/filter-bar.js +3 -3
  67. package/dist/form-submission-h40coUI8.js +13 -0
  68. package/dist/form-submission-h40coUI8.js.map +1 -0
  69. package/dist/form-submitter-BIFqZ0wq.js +88 -0
  70. package/dist/form-submitter-BIFqZ0wq.js.map +1 -0
  71. package/dist/form.js +1 -9
  72. package/dist/form.js.map +1 -1
  73. package/dist/icon-button.js +15 -19
  74. package/dist/icon-button.js.map +1 -1
  75. package/dist/icon.js +1 -1
  76. package/dist/implicit-submission-ChLdbxaR.js +100 -0
  77. package/dist/implicit-submission-ChLdbxaR.js.map +1 -0
  78. package/dist/index.js +20 -15
  79. package/dist/index.js.map +1 -1
  80. package/dist/{indicator-navigation-item-CmyhsOmy.js → indicator-navigation-item-BsQE3kUr.js} +2 -2
  81. package/dist/{indicator-navigation-item-CmyhsOmy.js.map → indicator-navigation-item-BsQE3kUr.js.map} +1 -1
  82. package/dist/input.js +13 -4
  83. package/dist/input.js.map +1 -1
  84. package/dist/json-viewer.js +1 -1
  85. package/dist/kanban.js +8 -7
  86. package/dist/kanban.js.map +1 -1
  87. package/dist/link-button.js +13 -14
  88. package/dist/link-button.js.map +1 -1
  89. package/dist/list-item.js +52 -16
  90. package/dist/list-item.js.map +1 -1
  91. package/dist/list.js +5 -3
  92. package/dist/list.js.map +1 -1
  93. package/dist/listbox.js +1 -1
  94. package/dist/loader-full.js +17 -12
  95. package/dist/loader-full.js.map +1 -1
  96. package/dist/loader.js +17 -12
  97. package/dist/loader.js.map +1 -1
  98. package/dist/locale-DEsJZCQG.js.map +1 -1
  99. package/dist/mention-input.js +8 -1
  100. package/dist/mention-input.js.map +1 -1
  101. package/dist/menu-item.js +12 -12
  102. package/dist/menu-item.js.map +1 -1
  103. package/dist/menu.js +7 -3
  104. package/dist/menu.js.map +1 -1
  105. package/dist/navigation-bar-item.js +4 -3
  106. package/dist/navigation-bar-item.js.map +1 -1
  107. package/dist/navigation-bar.js +4 -3
  108. package/dist/navigation-bar.js.map +1 -1
  109. package/dist/navigation-drawer-item.js +3 -2
  110. package/dist/navigation-drawer-item.js.map +1 -1
  111. package/dist/navigation-drawer.js +3 -2
  112. package/dist/navigation-drawer.js.map +1 -1
  113. package/dist/{navigation-item-base-kUrvJgCx.js → navigation-item-base-5ljwtLG_.js} +3 -2
  114. package/dist/{navigation-item-base-kUrvJgCx.js.map → navigation-item-base-5ljwtLG_.js.map} +1 -1
  115. package/dist/navigation-rail-item.js +4 -3
  116. package/dist/navigation-rail-item.js.map +1 -1
  117. package/dist/navigation-rail.js +6 -5
  118. package/dist/navigation-rail.js.map +1 -1
  119. package/dist/number-field.js +4 -1
  120. package/dist/number-field.js.map +1 -1
  121. package/dist/option.js +3 -2
  122. package/dist/option.js.map +1 -1
  123. package/dist/password-field.js +11 -4
  124. package/dist/password-field.js.map +1 -1
  125. package/dist/phone-field.js +4 -1
  126. package/dist/phone-field.js.map +1 -1
  127. package/dist/{picker-field-DmXYPvbF.js → picker-field-BiM3iXAQ.js} +2 -2
  128. package/dist/{picker-field-DmXYPvbF.js.map → picker-field-BiM3iXAQ.js.map} +1 -1
  129. package/dist/pin-input.js +4 -1
  130. package/dist/pin-input.js.map +1 -1
  131. package/dist/{range-utils-DZe96GnO.js → range-utils-vgG1SJ2o.js} +2 -2
  132. package/dist/{range-utils-DZe96GnO.js.map → range-utils-vgG1SJ2o.js.map} +1 -1
  133. package/dist/{roving-focus-controller-fm95JkZJ.js → roving-focus-controller-YtNbxH95.js} +30 -7
  134. package/dist/roving-focus-controller-YtNbxH95.js.map +1 -0
  135. package/dist/search.js +12 -6
  136. package/dist/search.js.map +1 -1
  137. package/dist/select.js +11 -3
  138. package/dist/select.js.map +1 -1
  139. package/dist/shipped-icons.js +1 -1
  140. package/dist/split-button.js +9 -1
  141. package/dist/split-button.js.map +1 -1
  142. package/dist/src/__internal/controllers/roving-focus-controller.d.ts +14 -2
  143. package/dist/src/__internal/implicit-submission.d.ts +25 -0
  144. package/dist/src/__internal/utils/activation-gate.d.ts +8 -0
  145. package/dist/src/__internal/utils/form-submission.d.ts +2 -0
  146. package/dist/src/avatar-group/avatar-group.d.ts +1 -1
  147. package/dist/src/button/base-button/base-button.d.ts +1 -1
  148. package/dist/src/button/button/button.d.ts +2 -1
  149. package/dist/src/button/fab/fab.d.ts +2 -1
  150. package/dist/src/button/icon-button/icon-button.d.ts +2 -1
  151. package/dist/src/button/link-button/link-button.d.ts +5 -1
  152. package/dist/src/calendar/calendar-month-view.d.ts +5 -1
  153. package/dist/src/calendar/calendar.d.ts +6 -1
  154. package/dist/src/card/card.d.ts +19 -9
  155. package/dist/src/chart-pie/chart-pie.d.ts +5 -0
  156. package/dist/src/chip/chip/chip.d.ts +4 -4
  157. package/dist/src/code-editor/code-editor.d.ts +3 -3
  158. package/dist/src/dropdown-button/dropdown-button.d.ts +5 -1
  159. package/dist/src/input/BaseField.d.ts +7 -0
  160. package/dist/src/input/input.d.ts +5 -1
  161. package/dist/src/list/list-item.d.ts +2 -1
  162. package/dist/src/mention-input/mention-input.d.ts +2 -0
  163. package/dist/src/menu/menu-item/menu-item.d.ts +6 -4
  164. package/dist/src/password-field/password-field.d.ts +3 -1
  165. package/dist/src/search/search.d.ts +1 -0
  166. package/dist/src/select/select.d.ts +2 -0
  167. package/dist/src/split-button/split-button.d.ts +6 -1
  168. package/dist/src/stepper/step.d.ts +3 -1
  169. package/dist/src/tabs/tab.d.ts +12 -2
  170. package/dist/src/textarea/textarea.d.ts +2 -0
  171. package/dist/src/toolbar/toolbar.d.ts +13 -2
  172. package/dist/step.js +7 -1
  173. package/dist/step.js.map +1 -1
  174. package/dist/stepper.js +10 -1
  175. package/dist/stepper.js.map +1 -1
  176. package/dist/sub-menu.js +3 -2
  177. package/dist/sub-menu.js.map +1 -1
  178. package/dist/svg.js +1 -1
  179. package/dist/tab-group.js +3 -2
  180. package/dist/tab-group.js.map +1 -1
  181. package/dist/tab.js +17 -12
  182. package/dist/tab.js.map +1 -1
  183. package/dist/tabs.js +3 -2
  184. package/dist/tabs.js.map +1 -1
  185. package/dist/test/accessible-name.test.d.ts +1 -0
  186. package/dist/test/helpers/count-activations.d.ts +9 -0
  187. package/dist/test/navigation-rail.test.d.ts +1 -0
  188. package/dist/test/throttle-delay.test.d.ts +1 -0
  189. package/dist/textarea.js +8 -1
  190. package/dist/textarea.js.map +1 -1
  191. package/dist/throttle-C7ZAPqtu.js +24 -0
  192. package/dist/throttle-C7ZAPqtu.js.map +1 -0
  193. package/dist/time-field.js +7 -4
  194. package/dist/time-field.js.map +1 -1
  195. package/dist/time-picker.js +2 -2
  196. package/dist/toolbar.js +25 -8
  197. package/dist/toolbar.js.map +1 -1
  198. package/dist/tree.js +1 -1
  199. package/dist/tsconfig.tsbuildinfo +1 -1
  200. package/dist/url-field.js +4 -1
  201. package/dist/url-field.js.map +1 -1
  202. package/dist/{utils-DcvLgexs.js → utils-CQzycr9J.js} +2 -1
  203. package/dist/utils-CQzycr9J.js.map +1 -0
  204. package/package.json +2 -1
  205. package/src/__internal/controllers/roving-focus-controller.ts +35 -7
  206. package/src/__internal/i18n/locale.ts +1 -1
  207. package/src/__internal/implicit-submission.ts +102 -0
  208. package/src/__internal/utils/activation-gate.ts +20 -0
  209. package/src/__internal/utils/cache-fetch.ts +6 -3
  210. package/src/__internal/utils/form-submission.ts +11 -0
  211. package/src/avatar/avatar.scss +5 -0
  212. package/src/avatar-group/avatar-group.scss +3 -0
  213. package/src/avatar-group/avatar-group.ts +1 -1
  214. package/src/button/base-button/base-button.ts +41 -16
  215. package/src/button/button/button.ts +5 -16
  216. package/src/button/fab/fab.ts +7 -18
  217. package/src/button/icon-button/icon-button.ts +7 -18
  218. package/src/button/link-button/link-button.ts +8 -15
  219. package/src/calendar/_calendar-header.scss +7 -1
  220. package/src/calendar/calendar-month-view.scss +36 -2
  221. package/src/calendar/calendar-month-view.ts +33 -8
  222. package/src/calendar/calendar.ts +17 -2
  223. package/src/calendar/utils.ts +1 -0
  224. package/src/card/card.ts +27 -16
  225. package/src/chart-doughnut/chart-doughnut.ts +6 -1
  226. package/src/chart-pie/chart-pie.ts +10 -1
  227. package/src/chip/chip/chip.ts +6 -26
  228. package/src/code-editor/code-editor.scss +70 -1
  229. package/src/code-editor/code-editor.ts +12 -4
  230. package/src/dropdown-button/dropdown-button.ts +7 -2
  231. package/src/form/form.ts +1 -9
  232. package/src/input/BaseField.ts +17 -0
  233. package/src/input/input.ts +13 -1
  234. package/src/kanban/kanban.scss +11 -7
  235. package/src/list/list-item.scss +5 -0
  236. package/src/list/list-item.ts +44 -16
  237. package/src/mention-input/mention-input.ts +5 -0
  238. package/src/menu/menu/menu.ts +4 -1
  239. package/src/menu/menu-item/menu-item.ts +9 -14
  240. package/src/navigation-rail/navigation-rail.scss +3 -2
  241. package/src/password-field/password-field.ts +11 -1
  242. package/src/search/search.ts +9 -0
  243. package/src/select/select.ts +5 -0
  244. package/src/split-button/split-button.ts +10 -1
  245. package/src/stepper/step.ts +7 -1
  246. package/src/stepper/stepper.scss +13 -0
  247. package/src/tabs/tab.ts +21 -17
  248. package/src/textarea/textarea.ts +5 -0
  249. package/src/toolbar/toolbar.ts +26 -7
  250. package/dist/BaseField-BbOj212R.js.map +0 -1
  251. package/dist/base-button-BJMGMcMv.js.map +0 -1
  252. package/dist/datasource-OwvH7SVq.js.map +0 -1
  253. package/dist/form-submitter-beG1CXAn.js.map +0 -1
  254. package/dist/roving-focus-controller-fm95JkZJ.js.map +0 -1
  255. package/dist/throttle-SQ9t-HL7.js.map +0 -1
  256. package/dist/utils-DcvLgexs.js.map +0 -1
@@ -1 +1 @@
1
- {"version":3,"file":"phone-field.js","sources":["../../src/phone-field/countries.ts","../../src/phone-field/phone-field.ts"],"sourcesContent":["/**\n * ITU-T E.164 calling codes and the countries and territories (ISO 3166-1 alpha-2) that dial\n * them. Each entry is `code:REGION,REGION,...`; the first region is the main one, chosen when a\n * pasted number gives only the code. Non-geographic codes (800, 808, 870, 88x, 979) are left out.\n * `AC` (Ascension Island) and `XK` (Kosovo) are not official ISO codes but are what CLDR and\n * `Intl.DisplayNames` use.\n */\nconst TABLE =\n '1:US,AG,AI,AS,BB,BM,BS,CA,DM,DO,GD,GU,JM,KN,KY,LC,MP,MS,PR,SX,TC,TT,VC,VG,VI;' +\n '7:RU,KZ;20:EG;27:ZA;30:GR;31:NL;32:BE;33:FR;34:ES;36:HU;39:IT,VA;40:RO;41:CH;43:AT;' +\n '44:GB,GG,IM,JE;45:DK;46:SE;47:NO,SJ;48:PL;49:DE;51:PE;52:MX;53:CU;54:AR;55:BR;56:CL;' +\n '57:CO;58:VE;60:MY;61:AU,CC,CX;62:ID;63:PH;64:NZ,PN;65:SG;66:TH;81:JP;82:KR;84:VN;86:CN;' +\n '90:TR;91:IN;92:PK;93:AF;94:LK;95:MM;98:IR;211:SS;212:MA,EH;213:DZ;216:TN;218:LY;220:GM;' +\n '221:SN;222:MR;223:ML;224:GN;225:CI;226:BF;227:NE;228:TG;229:BJ;230:MU;231:LR;232:SL;' +\n '233:GH;234:NG;235:TD;236:CF;237:CM;238:CV;239:ST;240:GQ;241:GA;242:CG;243:CD;244:AO;' +\n '245:GW;246:IO;247:AC;248:SC;249:SD;250:RW;251:ET;252:SO;253:DJ;254:KE;255:TZ;256:UG;' +\n '257:BI;258:MZ;260:ZM;261:MG;262:RE,YT;263:ZW;264:NA;265:MW;266:LS;267:BW;268:SZ;269:KM;' +\n '290:SH,TA;291:ER;297:AW;298:FO;299:GL;350:GI;351:PT;352:LU;353:IE;354:IS;355:AL;356:MT;' +\n '357:CY;358:FI,AX;359:BG;370:LT;371:LV;372:EE;373:MD;374:AM;375:BY;376:AD;377:MC;378:SM;' +\n '380:UA;381:RS;382:ME;383:XK;385:HR;386:SI;387:BA;389:MK;420:CZ;421:SK;423:LI;500:FK,GS;' +\n '501:BZ;502:GT;503:SV;504:HN;505:NI;506:CR;507:PA;508:PM;509:HT;590:GP,BL,MF;591:BO;' +\n '592:GY;593:EC;594:GF;595:PY;596:MQ;597:SR;598:UY;599:CW,BQ;670:TL;672:NF;673:BN;674:NR;' +\n '675:PG;676:TO;677:SB;678:VU;679:FJ;680:PW;681:WF;682:CK;683:NU;685:WS;686:KI;687:NC;' +\n '688:TV;689:PF;690:TK;691:FM;692:MH;850:KP;852:HK;853:MO;855:KH;856:LA;880:BD;886:TW;' +\n '960:MV;961:LB;962:JO;963:SY;964:IQ;965:KW;966:SA;967:YE;968:OM;970:PS;971:AE;972:IL;' +\n '973:BH;974:QA;975:BT;976:MN;977:NP;992:TJ;993:TM;994:AZ;995:GE;996:KG;998:UZ';\n\n/** Calling code of each region, for example `GB` → `44`. */\nconst CODE_OF = new Map<string, string>();\n\n/** Regions of each calling code, main region first, for example `44` → `GB, GG, IM, JE`. */\nconst REGIONS_OF = new Map<string, string[]>();\n\nfor (const entry of TABLE.split(';')) {\n const [code, regions] = entry.split(':');\n const list = regions.split(',');\n REGIONS_OF.set(code, list);\n for (const region of list) CODE_OF.set(region, code);\n}\n\n/** Every region in the table, in table order. */\nexport const ALL_COUNTRIES: readonly string[] = [...CODE_OF.keys()];\n\n/**\n * Regions whose national numbers keep a leading 0 after the calling code (Italy, Vatican City,\n * San Marino, Côte d'Ivoire, Congo). Everywhere else a leading 0 is the trunk prefix and is\n * dropped.\n */\nconst KEEPS_LEADING_ZERO = new Set(['IT', 'VA', 'SM', 'CI', 'CG']);\n\n/** The calling code of `country`, without `+`, or '' for a region not in the table. */\nexport function callingCode(country: string): string {\n return CODE_OF.get(country.toUpperCase()) ?? '';\n}\n\n/** Whether the table knows `country`. */\nexport function isKnownCountry(country: string): boolean {\n return CODE_OF.has(country.toUpperCase());\n}\n\n/**\n * The calling code at the start of `digits` (an international number without `+`), or ''.\n * E.164 codes are prefix-free, so at most one length matches.\n */\nexport function matchCallingCode(digits: string): string {\n for (let length = 1; length <= 3; length += 1) {\n const code = digits.slice(0, length);\n if (code.length === length && REGIONS_OF.has(code)) return code;\n }\n return '';\n}\n\n/**\n * The region to select for a number with calling `code`: `current` when it shares the code (so a\n * +1 number keeps Canada selected), else the first region of the code in `allowed` (when given),\n * else the code's main region.\n */\nexport function countryForCode(\n code: string,\n current: string,\n allowed?: readonly string[],\n): string {\n if (callingCode(current) === code) return current;\n const regions = REGIONS_OF.get(code) ?? [];\n const inList = allowed?.find(region => regions.includes(region));\n return inList ?? regions[0] ?? '';\n}\n\n/**\n * The national significant number of `digits` dialled in `country`: drops the trunk prefix (a\n * leading 0; a leading 1 on an 11-digit +1 number; a leading 8 on an 11-digit +7 number).\n */\nexport function nationalNumber(digits: string, country: string): string {\n const code = callingCode(country);\n if (code === '1' && digits.length === 11 && digits.startsWith('1')) {\n return digits.slice(1);\n }\n if (code === '7' && digits.length === 11 && digits.startsWith('8')) {\n return digits.slice(1);\n }\n if (digits.startsWith('0') && !KEEPS_LEADING_ZERO.has(country)) {\n return digits.slice(1);\n }\n return digits;\n}\n\n/** The flag emoji of a region, from its two regional-indicator letters. */\nexport function flagEmoji(country: string): string {\n const letters = country.toUpperCase();\n if (!/^[A-Z]{2}$/.test(letters)) return '';\n return String.fromCodePoint(\n ...[...letters].map(letter => 0x1f1e6 + letter.charCodeAt(0) - 65),\n );\n}\n\n/** The region of `locale` (`en-GB` → `GB`, `de` → `DE`), or '' when Intl cannot tell. */\nexport function localeRegion(locale: string): string {\n try {\n return new Intl.Locale(locale).maximize().region ?? '';\n } catch {\n return '';\n }\n}\n","import { html, nothing, type PropertyValues } from 'lit';\nimport { property, query, state } from 'lit/decorators.js';\n\nimport { spread } from '@/__internal/directive/spread.js';\nimport { I18nController } from '@/__internal/i18n/i18n-controller.js';\nimport type { FormRestoreState } from '@/__internal/mixins/form-associated.js';\nimport IndividualComponent from '@/IndividualComponent.js';\n\nimport BaseField from '../input/BaseField.js';\nimport type { ControlValidity } from '../input/BaseInput.js';\nimport {\n ALL_COUNTRIES,\n callingCode,\n countryForCode,\n flagEmoji,\n isKnownCountry,\n localeRegion,\n matchCallingCode,\n nationalNumber,\n} from './countries.js';\nimport styles from './phone-field.scss';\n\n/** What `input` and `change` carry. */\nexport interface PhoneFieldEventDetail {\n /** The number in E.164 form, such as `+442079460958`, or '' while there is no valid number. */\n value: string;\n /** The selected country, ISO 3166-1 alpha-2, such as `GB`. */\n country: string;\n}\n\n/** Characters allowed between the digits of a phone number. */\nconst SEPARATORS = /[\\s\\-()]/g;\n\n/** E.164 allows at most 15 digits; fewer than 4 (code included) is no real number. */\nconst MIN_DIGITS = 4;\nconst MAX_DIGITS = 15;\n\n/** The typed text, read as a phone number. */\ninterface ParsedText {\n /** Digits of the national number, trunk prefix dropped. */\n national: string;\n /** Whether the text is a number the field can submit. */\n valid: boolean;\n}\n\n/**\n * @label Phone Field\n * @tag wc-phone-field\n * @rawTag phone-field\n *\n * @summary A field for a phone number, with a country selector for the calling code.\n * @overview\n * <p>Phone field has a country selector at its start, showing the flag and calling code (such as\n * <code>+44</code>), and a field for the national number. Its <code>value</code> is the whole\n * number in E.164 form (<code>+442079460958</code>), ready to store or dial, or '' while the field\n * holds no valid number. A full international number typed or pasted into the field (starting\n * with <code>+</code> or <code>00</code>, such as <code>+44 20 7946 0958</code>) selects its\n * country and leaves the national part. A leading trunk 0 (<code>020 7946 0958</code>) is dropped,\n * except in Italy, Vatican City, San Marino, Côte d'Ivoire and Congo, which keep it.</p>\n * <p>The field checks the shape of the number, not whether it exists: digits only (spaces, dashes\n * and brackets are allowed between them), 4 to 15 digits with the calling code, as E.164 allows.\n * Anything else shows \"Enter a valid phone number\" and blocks form submission, as does an empty\n * <code>required</code> field. Inside a <code>&lt;form&gt;</code> the E.164 value is submitted under\n * its <code>name</code>.</p>\n * <p>The country list holds every ITU calling code, named in the field's locale (the nearest\n * <code>lang</code>, else the browser's). <code>country</code> starts as the locale's region (so\n * <code>lang=\"en-GB\"</code> starts on the United Kingdom), else the United States. Countries that\n * share a code, such as the +1 countries, keep the one the person selected. Limit or order the list\n * with <code>countries</code> and pin the likely ones to the top with\n * <code>preferred-countries</code>.</p>\n *\n * @fires {CustomEvent<{value: string, country: string}>} input - Dispatched as the user types or picks a country.\n * @fires {CustomEvent<{value: string, country: string}>} change - Dispatched when the number or the country is committed.\n *\n * @cssprop --phone-field-country-gap - Space between the flag, the calling code and the arrow.\n *\n * @example\n * ```html\n * <wc-phone-field label=\"Phone\" name=\"phone\" required></wc-phone-field>\n * ```\n * @example\n * ```html\n * <wc-phone-field\n * label=\"Mobile\"\n * country=\"GB\"\n * preferred-countries='[\"GB\", \"IE\"]'\n * value=\"+447700900123\"\n * ></wc-phone-field>\n * ```\n * @tags input, form\n */\n@IndividualComponent\nexport class PhoneField extends BaseField {\n // ── Static ───────────────────────────────────────────────────────────────\n\n static styles = [styles];\n\n // ── Properties ───────────────────────────────────────────────────────────\n\n /** The number in E.164 form (`+442079460958`), or '' while there is no valid number. */\n @property({ type: String })\n value = '';\n\n /**\n * The selected country, ISO 3166-1 alpha-2 (`GB`). Starts as the locale's region, else `US`.\n * A `value` with another calling code selects that code's country.\n */\n @property({ type: String, reflect: true })\n country = '';\n\n /** Limits and orders the country list, as alpha-2 codes. All countries, by name, when unset. */\n @property({ type: Array })\n countries?: string[];\n\n /** Countries pinned to the top of the list, in this order, above a separator. */\n @property({ type: Array, attribute: 'preferred-countries' })\n preferredCountries?: string[];\n\n // ── State ────────────────────────────────────────────────────────────────\n\n /** What the national-number input shows. */\n @state()\n private text = '';\n\n // ── Queries ──────────────────────────────────────────────────────────────\n\n @query('.input-element')\n private inputElement?: HTMLInputElement;\n\n // ── Private fields ───────────────────────────────────────────────────────\n\n /** Peacock's strings for the selector's name and the validation message. */\n private readonly i18n = new I18nController(this);\n\n /** The last value the field produced itself, so `willUpdate` can tell a consumer's value apart. */\n private __ownValue = '';\n\n /** The country the field started with; `form.reset()` returns to it. */\n private __defaultCountry = '';\n\n // ── Lifecycle ────────────────────────────────────────────────────────────\n\n override connectedCallback() {\n super.connectedCallback();\n if (!this.__defaultCountry) {\n this.country = this.country.toUpperCase();\n if (!isKnownCountry(this.country)) {\n this.country = this.__resolvedCountry();\n }\n this.__syncFromValue();\n this.__defaultCountry = this.country;\n }\n }\n\n protected override willUpdate(changed: PropertyValues<this>) {\n super.willUpdate(changed);\n if (changed.has('country')) this.country = this.country.toUpperCase();\n if (changed.has('value') && this.value !== this.__ownValue) {\n this.__syncFromValue();\n } else if (changed.has('country') && this.text) {\n // The country changed under a typed number: the same digits now dial another code.\n this.__applyText(this.text);\n }\n if (!isKnownCountry(this.country)) this.country = this.__resolvedCountry();\n }\n\n // ── Public methods ───────────────────────────────────────────────────────\n\n override focus() {\n this.inputElement?.focus();\n }\n\n override blur() {\n this.inputElement?.blur();\n }\n\n // ── Protected methods ────────────────────────────────────────────────────\n\n protected override computeValidity(): ControlValidity {\n if (!this.disabled && this.text && !this.__parse(this.text).valid) {\n return {\n flags: { typeMismatch: true },\n message: this.i18n.t('phoneInvalid'),\n anchor: this.inputElement,\n };\n }\n return { ...super.computeValidity(), anchor: this.inputElement };\n }\n\n protected override validityAnchor() {\n // `@query` gives null before the first render.\n return this.inputElement ?? undefined;\n }\n\n protected override clearValue() {\n this.text = '';\n this.__setValue('');\n this.__emit('input');\n this.__emit('change');\n }\n\n override formResetCallback() {\n super.formResetCallback();\n this.country = this.__defaultCountry;\n this.__syncFromValue();\n }\n\n override formStateRestoreCallback(restored: FormRestoreState | null) {\n super.formStateRestoreCallback(restored);\n this.__syncFromValue();\n }\n\n // ── Private methods ──────────────────────────────────────────────────────\n\n /** The country to fall back to: the locale's region when the table knows it, else `US`. */\n private __resolvedCountry(): string {\n const region = localeRegion(this.i18n.locale);\n if (this.countries?.length) {\n const allowed = this.__allowedCountries();\n return allowed.includes(region) ? region : (allowed[0] ?? 'US');\n }\n return isKnownCountry(region) ? region : 'US';\n }\n\n /** `countries`, upper-cased and limited to the table, or every country. */\n private __allowedCountries(): string[] {\n const list = (this.countries ?? [])\n .map(country => country.toUpperCase())\n .filter(isKnownCountry);\n return list.length ? list : [...ALL_COUNTRIES];\n }\n\n /** Shows a consumer's `value`: selects its country and puts its national digits in the input. */\n private __syncFromValue() {\n this.__ownValue = this.value;\n const value = this.value.trim();\n if (!value) {\n this.text = '';\n return;\n }\n const digits = value.replace(/^\\+/, '');\n const code = /^\\+\\d+$/.test(value) ? matchCallingCode(digits) : '';\n if (!code) {\n // Not E.164: show it as typed, so the field reports it as invalid.\n this.text = value;\n return;\n }\n this.country = countryForCode(code, this.country, this.countries);\n this.text = digits.slice(code.length);\n }\n\n /**\n * Reads typed text. An international number (`+44 …` or `0044 …`) selects its country and\n * leaves the national part in the input.\n */\n private __applyText(raw: string) {\n let text = raw;\n const international = /^\\s*(\\+|00)/.exec(text);\n if (international) {\n const rest = text.slice(international[0].length);\n const digits = rest.replace(SEPARATORS, '');\n const code = /^\\d+/.test(digits) ? matchCallingCode(digits) : '';\n if (code) {\n this.country = countryForCode(code, this.country, this.countries);\n text = PhoneField.__dropDigits(rest, code.length);\n }\n }\n this.text = text;\n const { national, valid } = this.__parse(text);\n this.__setValue(valid ? `+${callingCode(this.country)}${national}` : '');\n }\n\n /** `text` without its first `count` digits and the separators around them. */\n private static __dropDigits(text: string, count: number): string {\n let seen = 0;\n let index = 0;\n while (index < text.length && seen < count) {\n if (/\\d/.test(text[index])) seen += 1;\n index += 1;\n }\n return text.slice(index).replace(/^[\\s\\-)]+/, '');\n }\n\n /** The national number in `text` and whether it makes a valid E.164 number. */\n private __parse(text: string): ParsedText {\n const compact = text.replace(SEPARATORS, '');\n if (!/^\\d*$/.test(compact)) return { national: '', valid: false };\n const national = nationalNumber(compact, this.country);\n const total = callingCode(this.country).length + national.length;\n return {\n national,\n valid: national.length > 0 && total >= MIN_DIGITS && total <= MAX_DIGITS,\n };\n }\n\n private __setValue(value: string) {\n this.__ownValue = value;\n this.value = value;\n }\n\n private __emit(type: 'input' | 'change') {\n this.dispatchEvent(\n new CustomEvent<PhoneFieldEventDetail>(type, {\n detail: { value: this.value, country: this.country },\n bubbles: true,\n composed: true,\n }),\n );\n }\n\n private __handleInput(event: Event) {\n // Replace the native event, which escapes the shadow root, with the field's own.\n event.stopPropagation();\n this.__applyText((event.target as HTMLInputElement).value);\n this.__emit('input');\n }\n\n private __handleChange(event: Event) {\n event.stopPropagation();\n this.__emit('change');\n }\n\n private __handleCountryChange(event: Event) {\n event.stopPropagation();\n this.country = (event.target as HTMLSelectElement).value;\n this.__applyText(this.text);\n this.__emit('input');\n this.__emit('change');\n }\n\n private __stopEvent(event: Event) {\n // The select's native `input` escapes the shadow root; clicks would focus the number input.\n event.stopPropagation();\n }\n\n /** Country names in the field's locale, or `undefined` where Intl cannot name regions. */\n private __displayNames(): Intl.DisplayNames | undefined {\n try {\n return new Intl.DisplayNames(this.i18n.locale, { type: 'region' });\n } catch {\n return undefined;\n }\n }\n\n /** The countries the selector lists: pinned first, then the rest. */\n private __countryOptions(names: Intl.DisplayNames | undefined): {\n pinned: string[];\n rest: string[];\n } {\n const allowed = this.__allowedCountries();\n if (!allowed.includes(this.country)) allowed.unshift(this.country);\n const name = (country: string) => names?.of(country) ?? country;\n if (!this.countries?.length) {\n const collator = new Intl.Collator(this.i18n.locale);\n allowed.sort((a, b) => collator.compare(name(a), name(b)));\n }\n const pinned = (this.preferredCountries ?? [])\n .map(country => country.toUpperCase())\n .filter(country => allowed.includes(country));\n return {\n pinned,\n rest: allowed.filter(country => !pinned.includes(country)),\n };\n }\n\n // ── Render helpers ───────────────────────────────────────────────────────\n\n private renderOption(country: string, names: Intl.DisplayNames | undefined) {\n const label = `${names?.of(country) ?? country} (+${callingCode(country)})`;\n return html`<option value=${country} ?selected=${country === this.country}>\n ${label}\n </option>`;\n }\n\n private renderCountry() {\n const names = this.__displayNames();\n const { pinned, rest } = this.__countryOptions(names);\n // A transparent native select lies over the flag and code: it opens the platform's list\n // (with typeahead on the names) and screen readers announce it as a combobox.\n return html`<span class=\"country\" slot=\"field-start\">\n <span class=\"flag\" aria-hidden=\"true\">${flagEmoji(this.country)}</span>\n <span class=\"code\" aria-hidden=\"true\">+${callingCode(this.country)}</span>\n <wc-icon\n class=\"arrow\"\n name=\"arrow_drop_down\"\n aria-hidden=\"true\"\n ></wc-icon>\n <select\n class=\"country-select\"\n aria-label=${this.i18n.t('phoneCountry')}\n autocomplete=\"tel-country-code\"\n .value=${this.country}\n ?disabled=${this.disabled || this.readonly}\n @change=${this.__handleCountryChange}\n @input=${this.__stopEvent}\n @click=${this.__stopEvent}\n @focus=${this.handleFieldFocus}\n @blur=${this.handleFieldFocus}\n >\n ${pinned.map(country => this.renderOption(country, names))}\n ${pinned.length ? html`<hr />` : nothing}\n ${rest.map(country => this.renderOption(country, names))}\n </select>\n </span>`;\n }\n\n // ── Render ───────────────────────────────────────────────────────────────\n\n render() {\n return this.renderField(\n html`<input\n class=\"input input-element\"\n type=\"tel\"\n inputmode=\"tel\"\n autocomplete=\"tel-national\"\n placeholder=${this.placeholder}\n .value=${this.text}\n ?readonly=${this.readonly}\n ?required=${this.required}\n ?disabled=${this.disabled}\n @input=${this.__handleInput}\n @change=${this.__handleChange}\n @focus=${this.handleFieldFocus}\n @blur=${this.handleFieldFocus}\n ${spread(this.fieldAria())}\n />`,\n { populated: !!this.text, start: this.renderCountry() },\n );\n }\n}\n"],"names":["html","nothing","styles","property","state","query"],"mappings":";;;;;;;;;;;;;;;;;AAAA;;;;;;AAMG;AACH,MAAM,KAAK,GACT,+EAA+E;IAC/E,qFAAqF;IACrF,sFAAsF;IACtF,yFAAyF;IACzF,yFAAyF;IACzF,sFAAsF;IACtF,sFAAsF;IACtF,sFAAsF;IACtF,yFAAyF;IACzF,yFAAyF;IACzF,yFAAyF;IACzF,yFAAyF;IACzF,qFAAqF;IACrF,yFAAyF;IACzF,sFAAsF;IACtF,sFAAsF;IACtF,sFAAsF;AACtF,IAAA,8EAA8E;AAEhF;AACA,MAAM,OAAO,GAAG,IAAI,GAAG,EAAkB;AAEzC;AACA,MAAM,UAAU,GAAG,IAAI,GAAG,EAAoB;AAE9C,KAAK,MAAM,KAAK,IAAI,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;AACpC,IAAA,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC;IACxC,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC;AAC/B,IAAA,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC;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A,CAAA;AAMtB,UAAA,CAAA;AADP,IAAAC,CAAK;AACY,CAAA,EAAA,UAAA,CAAA,SAAA,EAAA,MAAA,EAAA,MAAA,CAAA;AAKV,UAAA,CAAA;IADPC,CAAK,CAAC,gBAAgB;AACiB,CAAA,EAAA,UAAA,CAAA,SAAA,EAAA,cAAA,EAAA,MAAA,CAAA;AAnC7B,UAAU,GAAA,YAAA,GAAA,UAAA,CAAA;IADtB;AACY,CAAA,EAAA,UAAU,CAiVtB;;;;"}
1
+ {"version":3,"file":"phone-field.js","sources":["../../src/phone-field/countries.ts","../../src/phone-field/phone-field.ts"],"sourcesContent":["/**\n * ITU-T E.164 calling codes and the countries and territories (ISO 3166-1 alpha-2) that dial\n * them. Each entry is `code:REGION,REGION,...`; the first region is the main one, chosen when a\n * pasted number gives only the code. Non-geographic codes (800, 808, 870, 88x, 979) are left out.\n * `AC` (Ascension Island) and `XK` (Kosovo) are not official ISO codes but are what CLDR and\n * `Intl.DisplayNames` use.\n */\nconst TABLE =\n '1:US,AG,AI,AS,BB,BM,BS,CA,DM,DO,GD,GU,JM,KN,KY,LC,MP,MS,PR,SX,TC,TT,VC,VG,VI;' +\n '7:RU,KZ;20:EG;27:ZA;30:GR;31:NL;32:BE;33:FR;34:ES;36:HU;39:IT,VA;40:RO;41:CH;43:AT;' +\n '44:GB,GG,IM,JE;45:DK;46:SE;47:NO,SJ;48:PL;49:DE;51:PE;52:MX;53:CU;54:AR;55:BR;56:CL;' +\n '57:CO;58:VE;60:MY;61:AU,CC,CX;62:ID;63:PH;64:NZ,PN;65:SG;66:TH;81:JP;82:KR;84:VN;86:CN;' +\n '90:TR;91:IN;92:PK;93:AF;94:LK;95:MM;98:IR;211:SS;212:MA,EH;213:DZ;216:TN;218:LY;220:GM;' +\n '221:SN;222:MR;223:ML;224:GN;225:CI;226:BF;227:NE;228:TG;229:BJ;230:MU;231:LR;232:SL;' +\n '233:GH;234:NG;235:TD;236:CF;237:CM;238:CV;239:ST;240:GQ;241:GA;242:CG;243:CD;244:AO;' +\n '245:GW;246:IO;247:AC;248:SC;249:SD;250:RW;251:ET;252:SO;253:DJ;254:KE;255:TZ;256:UG;' +\n '257:BI;258:MZ;260:ZM;261:MG;262:RE,YT;263:ZW;264:NA;265:MW;266:LS;267:BW;268:SZ;269:KM;' +\n '290:SH,TA;291:ER;297:AW;298:FO;299:GL;350:GI;351:PT;352:LU;353:IE;354:IS;355:AL;356:MT;' +\n '357:CY;358:FI,AX;359:BG;370:LT;371:LV;372:EE;373:MD;374:AM;375:BY;376:AD;377:MC;378:SM;' +\n '380:UA;381:RS;382:ME;383:XK;385:HR;386:SI;387:BA;389:MK;420:CZ;421:SK;423:LI;500:FK,GS;' +\n '501:BZ;502:GT;503:SV;504:HN;505:NI;506:CR;507:PA;508:PM;509:HT;590:GP,BL,MF;591:BO;' +\n '592:GY;593:EC;594:GF;595:PY;596:MQ;597:SR;598:UY;599:CW,BQ;670:TL;672:NF;673:BN;674:NR;' +\n '675:PG;676:TO;677:SB;678:VU;679:FJ;680:PW;681:WF;682:CK;683:NU;685:WS;686:KI;687:NC;' +\n '688:TV;689:PF;690:TK;691:FM;692:MH;850:KP;852:HK;853:MO;855:KH;856:LA;880:BD;886:TW;' +\n '960:MV;961:LB;962:JO;963:SY;964:IQ;965:KW;966:SA;967:YE;968:OM;970:PS;971:AE;972:IL;' +\n '973:BH;974:QA;975:BT;976:MN;977:NP;992:TJ;993:TM;994:AZ;995:GE;996:KG;998:UZ';\n\n/** Calling code of each region, for example `GB` → `44`. */\nconst CODE_OF = new Map<string, string>();\n\n/** Regions of each calling code, main region first, for example `44` → `GB, GG, IM, JE`. */\nconst REGIONS_OF = new Map<string, string[]>();\n\nfor (const entry of TABLE.split(';')) {\n const [code, regions] = entry.split(':');\n const list = regions.split(',');\n REGIONS_OF.set(code, list);\n for (const region of list) CODE_OF.set(region, code);\n}\n\n/** Every region in the table, in table order. */\nexport const ALL_COUNTRIES: readonly string[] = [...CODE_OF.keys()];\n\n/**\n * Regions whose national numbers keep a leading 0 after the calling code (Italy, Vatican City,\n * San Marino, Côte d'Ivoire, Congo). Everywhere else a leading 0 is the trunk prefix and is\n * dropped.\n */\nconst KEEPS_LEADING_ZERO = new Set(['IT', 'VA', 'SM', 'CI', 'CG']);\n\n/** The calling code of `country`, without `+`, or '' for a region not in the table. */\nexport function callingCode(country: string): string {\n return CODE_OF.get(country.toUpperCase()) ?? '';\n}\n\n/** Whether the table knows `country`. */\nexport function isKnownCountry(country: string): boolean {\n return CODE_OF.has(country.toUpperCase());\n}\n\n/**\n * The calling code at the start of `digits` (an international number without `+`), or ''.\n * E.164 codes are prefix-free, so at most one length matches.\n */\nexport function matchCallingCode(digits: string): string {\n for (let length = 1; length <= 3; length += 1) {\n const code = digits.slice(0, length);\n if (code.length === length && REGIONS_OF.has(code)) return code;\n }\n return '';\n}\n\n/**\n * The region to select for a number with calling `code`: `current` when it shares the code (so a\n * +1 number keeps Canada selected), else the first region of the code in `allowed` (when given),\n * else the code's main region.\n */\nexport function countryForCode(\n code: string,\n current: string,\n allowed?: readonly string[],\n): string {\n if (callingCode(current) === code) return current;\n const regions = REGIONS_OF.get(code) ?? [];\n const inList = allowed?.find(region => regions.includes(region));\n return inList ?? regions[0] ?? '';\n}\n\n/**\n * The national significant number of `digits` dialled in `country`: drops the trunk prefix (a\n * leading 0; a leading 1 on an 11-digit +1 number; a leading 8 on an 11-digit +7 number).\n */\nexport function nationalNumber(digits: string, country: string): string {\n const code = callingCode(country);\n if (code === '1' && digits.length === 11 && digits.startsWith('1')) {\n return digits.slice(1);\n }\n if (code === '7' && digits.length === 11 && digits.startsWith('8')) {\n return digits.slice(1);\n }\n if (digits.startsWith('0') && !KEEPS_LEADING_ZERO.has(country)) {\n return digits.slice(1);\n }\n return digits;\n}\n\n/** The flag emoji of a region, from its two regional-indicator letters. */\nexport function flagEmoji(country: string): string {\n const letters = country.toUpperCase();\n if (!/^[A-Z]{2}$/.test(letters)) return '';\n return String.fromCodePoint(\n ...[...letters].map(letter => 0x1f1e6 + letter.charCodeAt(0) - 65),\n );\n}\n\n/** The region of `locale` (`en-GB` → `GB`, `de` → `DE`), or '' when Intl cannot tell. */\nexport function localeRegion(locale: string): string {\n try {\n return new Intl.Locale(locale).maximize().region ?? '';\n } catch {\n return '';\n }\n}\n","import { html, nothing, type PropertyValues } from 'lit';\nimport { property, query, state } from 'lit/decorators.js';\n\nimport { spread } from '@/__internal/directive/spread.js';\nimport { I18nController } from '@/__internal/i18n/i18n-controller.js';\nimport type { FormRestoreState } from '@/__internal/mixins/form-associated.js';\nimport IndividualComponent from '@/IndividualComponent.js';\n\nimport BaseField from '../input/BaseField.js';\nimport type { ControlValidity } from '../input/BaseInput.js';\nimport {\n ALL_COUNTRIES,\n callingCode,\n countryForCode,\n flagEmoji,\n isKnownCountry,\n localeRegion,\n matchCallingCode,\n nationalNumber,\n} from './countries.js';\nimport styles from './phone-field.scss';\n\n/** What `input` and `change` carry. */\nexport interface PhoneFieldEventDetail {\n /** The number in E.164 form, such as `+442079460958`, or '' while there is no valid number. */\n value: string;\n /** The selected country, ISO 3166-1 alpha-2, such as `GB`. */\n country: string;\n}\n\n/** Characters allowed between the digits of a phone number. */\nconst SEPARATORS = /[\\s\\-()]/g;\n\n/** E.164 allows at most 15 digits; fewer than 4 (code included) is no real number. */\nconst MIN_DIGITS = 4;\nconst MAX_DIGITS = 15;\n\n/** The typed text, read as a phone number. */\ninterface ParsedText {\n /** Digits of the national number, trunk prefix dropped. */\n national: string;\n /** Whether the text is a number the field can submit. */\n valid: boolean;\n}\n\n/**\n * @label Phone Field\n * @tag wc-phone-field\n * @rawTag phone-field\n *\n * @summary A field for a phone number, with a country selector for the calling code.\n * @overview\n * <p>Phone field has a country selector at its start, showing the flag and calling code (such as\n * <code>+44</code>), and a field for the national number. Its <code>value</code> is the whole\n * number in E.164 form (<code>+442079460958</code>), ready to store or dial, or '' while the field\n * holds no valid number. A full international number typed or pasted into the field (starting\n * with <code>+</code> or <code>00</code>, such as <code>+44 20 7946 0958</code>) selects its\n * country and leaves the national part. A leading trunk 0 (<code>020 7946 0958</code>) is dropped,\n * except in Italy, Vatican City, San Marino, Côte d'Ivoire and Congo, which keep it.</p>\n * <p>The field checks the shape of the number, not whether it exists: digits only (spaces, dashes\n * and brackets are allowed between them), 4 to 15 digits with the calling code, as E.164 allows.\n * Anything else shows \"Enter a valid phone number\" and blocks form submission, as does an empty\n * <code>required</code> field. Inside a <code>&lt;form&gt;</code> the E.164 value is submitted under\n * its <code>name</code>.</p>\n * <p>The country list holds every ITU calling code, named in the field's locale (the nearest\n * <code>lang</code>, else the browser's). <code>country</code> starts as the locale's region (so\n * <code>lang=\"en-GB\"</code> starts on the United Kingdom), else the United States. Countries that\n * share a code, such as the +1 countries, keep the one the person selected. Limit or order the list\n * with <code>countries</code> and pin the likely ones to the top with\n * <code>preferred-countries</code>.</p>\n *\n * @fires {CustomEvent<{value: string, country: string}>} input - Dispatched as the user types or picks a country.\n * @fires {CustomEvent<{value: string, country: string}>} change - Dispatched when the number or the country is committed.\n *\n * @cssprop --phone-field-country-gap - Space between the flag, the calling code and the arrow.\n *\n * @example\n * ```html\n * <wc-phone-field label=\"Phone\" name=\"phone\" required></wc-phone-field>\n * ```\n * @example\n * ```html\n * <wc-phone-field\n * label=\"Mobile\"\n * country=\"GB\"\n * preferred-countries='[\"GB\", \"IE\"]'\n * value=\"+447700900123\"\n * ></wc-phone-field>\n * ```\n * @tags input, form\n */\n@IndividualComponent\nexport class PhoneField extends BaseField {\n // ── Static ───────────────────────────────────────────────────────────────\n\n static styles = [styles];\n\n // ── Properties ───────────────────────────────────────────────────────────\n\n /** The number in E.164 form (`+442079460958`), or '' while there is no valid number. */\n @property({ type: String })\n value = '';\n\n /**\n * The selected country, ISO 3166-1 alpha-2 (`GB`). Starts as the locale's region, else `US`.\n * A `value` with another calling code selects that code's country.\n */\n @property({ type: String, reflect: true })\n country = '';\n\n /** Limits and orders the country list, as alpha-2 codes. All countries, by name, when unset. */\n @property({ type: Array })\n countries?: string[];\n\n /** Countries pinned to the top of the list, in this order, above a separator. */\n @property({ type: Array, attribute: 'preferred-countries' })\n preferredCountries?: string[];\n\n // ── State ────────────────────────────────────────────────────────────────\n\n /** What the national-number input shows. */\n @state()\n private text = '';\n\n // ── Queries ──────────────────────────────────────────────────────────────\n\n @query('.input-element')\n private inputElement?: HTMLInputElement;\n\n // ── Private fields ───────────────────────────────────────────────────────\n\n /** Peacock's strings for the selector's name and the validation message. */\n private readonly i18n = new I18nController(this);\n\n /** The last value the field produced itself, so `willUpdate` can tell a consumer's value apart. */\n private __ownValue = '';\n\n /** The country the field started with; `form.reset()` returns to it. */\n private __defaultCountry = '';\n\n // ── Lifecycle ────────────────────────────────────────────────────────────\n\n override connectedCallback() {\n super.connectedCallback();\n if (!this.__defaultCountry) {\n this.country = this.country.toUpperCase();\n if (!isKnownCountry(this.country)) {\n this.country = this.__resolvedCountry();\n }\n this.__syncFromValue();\n this.__defaultCountry = this.country;\n }\n }\n\n protected override willUpdate(changed: PropertyValues<this>) {\n super.willUpdate(changed);\n if (changed.has('country')) this.country = this.country.toUpperCase();\n if (changed.has('value') && this.value !== this.__ownValue) {\n this.__syncFromValue();\n } else if (changed.has('country') && this.text) {\n // The country changed under a typed number: the same digits now dial another code.\n this.__applyText(this.text);\n }\n if (!isKnownCountry(this.country)) this.country = this.__resolvedCountry();\n }\n\n // ── Public methods ───────────────────────────────────────────────────────\n\n override focus() {\n this.inputElement?.focus();\n }\n\n override blur() {\n this.inputElement?.blur();\n }\n\n // ── Protected methods ────────────────────────────────────────────────────\n\n protected override computeValidity(): ControlValidity {\n if (!this.disabled && this.text && !this.__parse(this.text).valid) {\n return {\n flags: { typeMismatch: true },\n message: this.i18n.t('phoneInvalid'),\n anchor: this.inputElement,\n };\n }\n return { ...super.computeValidity(), anchor: this.inputElement };\n }\n\n protected override validityAnchor() {\n // `@query` gives null before the first render.\n return this.inputElement ?? undefined;\n }\n\n protected override clearValue() {\n this.text = '';\n this.__setValue('');\n this.__emit('input');\n this.__emit('change');\n }\n\n override formResetCallback() {\n super.formResetCallback();\n this.country = this.__defaultCountry;\n this.__syncFromValue();\n }\n\n override formStateRestoreCallback(restored: FormRestoreState | null) {\n super.formStateRestoreCallback(restored);\n this.__syncFromValue();\n }\n\n // ── Private methods ──────────────────────────────────────────────────────\n\n /** The country to fall back to: the locale's region when the table knows it, else `US`. */\n private __resolvedCountry(): string {\n const region = localeRegion(this.i18n.locale);\n if (this.countries?.length) {\n const allowed = this.__allowedCountries();\n return allowed.includes(region) ? region : (allowed[0] ?? 'US');\n }\n return isKnownCountry(region) ? region : 'US';\n }\n\n /** `countries`, upper-cased and limited to the table, or every country. */\n private __allowedCountries(): string[] {\n const list = (this.countries ?? [])\n .map(country => country.toUpperCase())\n .filter(isKnownCountry);\n return list.length ? list : [...ALL_COUNTRIES];\n }\n\n /** Shows a consumer's `value`: selects its country and puts its national digits in the input. */\n private __syncFromValue() {\n this.__ownValue = this.value;\n const value = this.value.trim();\n if (!value) {\n this.text = '';\n return;\n }\n const digits = value.replace(/^\\+/, '');\n const code = /^\\+\\d+$/.test(value) ? matchCallingCode(digits) : '';\n if (!code) {\n // Not E.164: show it as typed, so the field reports it as invalid.\n this.text = value;\n return;\n }\n this.country = countryForCode(code, this.country, this.countries);\n this.text = digits.slice(code.length);\n }\n\n /**\n * Reads typed text. An international number (`+44 …` or `0044 …`) selects its country and\n * leaves the national part in the input.\n */\n private __applyText(raw: string) {\n let text = raw;\n const international = /^\\s*(\\+|00)/.exec(text);\n if (international) {\n const rest = text.slice(international[0].length);\n const digits = rest.replace(SEPARATORS, '');\n const code = /^\\d+/.test(digits) ? matchCallingCode(digits) : '';\n if (code) {\n this.country = countryForCode(code, this.country, this.countries);\n text = PhoneField.__dropDigits(rest, code.length);\n }\n }\n this.text = text;\n const { national, valid } = this.__parse(text);\n this.__setValue(valid ? `+${callingCode(this.country)}${national}` : '');\n }\n\n /** `text` without its first `count` digits and the separators around them. */\n private static __dropDigits(text: string, count: number): string {\n let seen = 0;\n let index = 0;\n while (index < text.length && seen < count) {\n if (/\\d/.test(text[index])) seen += 1;\n index += 1;\n }\n return text.slice(index).replace(/^[\\s\\-)]+/, '');\n }\n\n /** The national number in `text` and whether it makes a valid E.164 number. */\n private __parse(text: string): ParsedText {\n const compact = text.replace(SEPARATORS, '');\n if (!/^\\d*$/.test(compact)) return { national: '', valid: false };\n const national = nationalNumber(compact, this.country);\n const total = callingCode(this.country).length + national.length;\n return {\n national,\n valid: national.length > 0 && total >= MIN_DIGITS && total <= MAX_DIGITS,\n };\n }\n\n private __setValue(value: string) {\n this.__ownValue = value;\n this.value = value;\n }\n\n private __emit(type: 'input' | 'change') {\n this.dispatchEvent(\n new CustomEvent<PhoneFieldEventDetail>(type, {\n detail: { value: this.value, country: this.country },\n bubbles: true,\n composed: true,\n }),\n );\n }\n\n private __handleInput(event: Event) {\n // Replace the native event, which escapes the shadow root, with the field's own.\n event.stopPropagation();\n this.__applyText((event.target as HTMLInputElement).value);\n this.__emit('input');\n }\n\n private __handleChange(event: Event) {\n event.stopPropagation();\n this.__emit('change');\n }\n\n private __handleCountryChange(event: Event) {\n event.stopPropagation();\n this.country = (event.target as HTMLSelectElement).value;\n this.__applyText(this.text);\n this.__emit('input');\n this.__emit('change');\n }\n\n private __stopEvent(event: Event) {\n // The select's native `input` escapes the shadow root; clicks would focus the number input.\n event.stopPropagation();\n }\n\n /** Country names in the field's locale, or `undefined` where Intl cannot name regions. */\n private __displayNames(): Intl.DisplayNames | undefined {\n try {\n return new Intl.DisplayNames(this.i18n.locale, { type: 'region' });\n } catch {\n return undefined;\n }\n }\n\n /** The countries the selector lists: pinned first, then the rest. */\n private __countryOptions(names: Intl.DisplayNames | undefined): {\n pinned: string[];\n rest: string[];\n } {\n const allowed = this.__allowedCountries();\n if (!allowed.includes(this.country)) allowed.unshift(this.country);\n const name = (country: string) => names?.of(country) ?? country;\n if (!this.countries?.length) {\n const collator = new Intl.Collator(this.i18n.locale);\n allowed.sort((a, b) => collator.compare(name(a), name(b)));\n }\n const pinned = (this.preferredCountries ?? [])\n .map(country => country.toUpperCase())\n .filter(country => allowed.includes(country));\n return {\n pinned,\n rest: allowed.filter(country => !pinned.includes(country)),\n };\n }\n\n // ── Render helpers ───────────────────────────────────────────────────────\n\n private renderOption(country: string, names: Intl.DisplayNames | undefined) {\n const label = `${names?.of(country) ?? country} (+${callingCode(country)})`;\n return html`<option value=${country} ?selected=${country === this.country}>\n ${label}\n </option>`;\n }\n\n private renderCountry() {\n const names = this.__displayNames();\n const { pinned, rest } = this.__countryOptions(names);\n // A transparent native select lies over the flag and code: it opens the platform's list\n // (with typeahead on the names) and screen readers announce it as a combobox.\n return html`<span class=\"country\" slot=\"field-start\">\n <span class=\"flag\" aria-hidden=\"true\">${flagEmoji(this.country)}</span>\n <span class=\"code\" aria-hidden=\"true\">+${callingCode(this.country)}</span>\n <wc-icon\n class=\"arrow\"\n name=\"arrow_drop_down\"\n aria-hidden=\"true\"\n ></wc-icon>\n <select\n class=\"country-select\"\n aria-label=${this.i18n.t('phoneCountry')}\n autocomplete=\"tel-country-code\"\n .value=${this.country}\n ?disabled=${this.disabled || this.readonly}\n @change=${this.__handleCountryChange}\n @input=${this.__stopEvent}\n @click=${this.__stopEvent}\n @focus=${this.handleFieldFocus}\n @blur=${this.handleFieldFocus}\n >\n ${pinned.map(country => this.renderOption(country, names))}\n ${pinned.length ? html`<hr />` : nothing}\n ${rest.map(country => this.renderOption(country, names))}\n </select>\n </span>`;\n }\n\n // ── Render ───────────────────────────────────────────────────────────────\n\n render() {\n return this.renderField(\n html`<input\n class=\"input input-element\"\n type=\"tel\"\n inputmode=\"tel\"\n autocomplete=\"tel-national\"\n placeholder=${this.placeholder}\n .value=${this.text}\n ?readonly=${this.readonly}\n ?required=${this.required}\n ?disabled=${this.disabled}\n @input=${this.__handleInput}\n @change=${this.__handleChange}\n @focus=${this.handleFieldFocus}\n @blur=${this.handleFieldFocus}\n ${spread(this.fieldAria())}\n />`,\n { populated: !!this.text, start: this.renderCountry() },\n );\n }\n}\n"],"names":["html","nothing","styles","property","state","query"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;;;;;;AAMG;AACH,MAAM,KAAK,GACT,+EAA+E;IAC/E,qFAAqF;IACrF,sFAAsF;IACtF,yFAAyF;IACzF,yFAAyF;IACzF,sFAAsF;IACtF,sFAAsF;IACtF,sFAAsF;IACtF,yFAAyF;IACzF,yFAAyF;IACzF,yFAAyF;IACzF,yFAAyF;IACzF,qFAAqF;IACrF,yFAAyF;IACzF,sFAAsF;IACtF,sFAAsF;IACtF,sFAAsF;AACtF,IAAA,8EAA8E;AAEhF;AACA,MAAM,OAAO,GAAG,IAAI,GAAG,EAAkB;AAEzC;AACA,MAAM,UAAU,GAAG,IAAI,GAAG,EAAoB;AAE9C,KAAK,MAAM,KAAK,IAAI,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE;AACpC,IAAA,MAAM,CAAC,IAAI,EAAE,OAAO,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC;IACxC,MAAM,IAAI,GAAG,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC;AAC/B,IAAA,UAAU,CAAC,GAAG,CAAC,IAAI,EAAE,IAAI,CAAC;IAC1B,KAAK,MAAM,MAAM,IAAI,IAAI;AAAE,QAAA,OAAO,CAAC,GAAG,CAAC,MAAM,EAAE,IAAI,CAAC;AACtD;AAEA;AACO,MAAM,aAAa,GAAsB,CAAC,GAAG,OAAO,CAAC,IAAI,EAAE,CAAC;AAEnE;;;;AAIG;AACH,MAAM,kBAAkB,GAAG,IAAI,GAAG,CAAC,CAAC,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,EAAE,IAAI,CAAC,CAAC;AAElE;AACM,SAAU,WAAW,CAAC,OAAe,EAAA;IACzC,OAAO,OAAO,CAAC,GAAG,CAAC,OAAO,CAAC,WAAW,EAAE,CAAC,IAAI,EAAE;AACjD;AAEA;AACM,SAAU,cAAc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AC;AACzB,QAAA,CAAA,EACH,EAAE,SAAS,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,CAAC,aAAa,EAAE,EAAE,CACxD;IACH;;AA7UO,UAAA,CAAA,MAAM,GAAG,CAACE,QAAM,CAAC;AAMxB,UAAA,CAAA;AADC,IAAAC,CAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE;AACf,CAAA,EAAA,UAAA,CAAA,SAAA,EAAA,OAAA,EAAA,MAAA,CAAA;AAOX,UAAA,CAAA;IADCA,CAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,OAAO,EAAE,IAAI,EAAE;AAC5B,CAAA,EAAA,UAAA,CAAA,SAAA,EAAA,SAAA,EAAA,MAAA,CAAA;AAIb,UAAA,CAAA;AADC,IAAAA,CAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE;AACJ,CAAA,EAAA,UAAA,CAAA,SAAA,EAAA,WAAA,EAAA,MAAA,CAAA;AAIrB,UAAA,CAAA;IADCA,CAAQ,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,SAAS,EAAE,qBAAqB,EAAE;AAC7B,CAAA,EAAA,UAAA,CAAA,SAAA,EAAA,oBAAA,EAAA,MAAA,CAAA;AAMtB,UAAA,CAAA;AADP,IAAAC,CAAK;AACY,CAAA,EAAA,UAAA,CAAA,SAAA,EAAA,MAAA,EAAA,MAAA,CAAA;AAKV,UAAA,CAAA;IADPC,CAAK,CAAC,gBAAgB;AACiB,CAAA,EAAA,UAAA,CAAA,SAAA,EAAA,cAAA,EAAA,MAAA,CAAA;AAnC7B,UAAU,GAAA,YAAA,GAAA,UAAA,CAAA;IADtB;AACY,CAAA,EAAA,UAAU,CAiVtB;;;;"}
@@ -4,7 +4,7 @@ import { r } from './state-BCeDVCI9.js';
4
4
  import { e } from './query-CHb9Ft_d.js';
5
5
  import { s as spread } from './spread-B5cgadZl.js';
6
6
  import { I as I18nController } from './i18n-controller-BTeChxE0.js';
7
- import { B as BaseField } from './BaseField-BbOj212R.js';
7
+ import { B as BaseField } from './BaseField-DOCmylob.js';
8
8
 
9
9
  /**
10
10
  * Base for text fields that open a picker in a popover: `wc-date-field`, `wc-time-field` and
@@ -294,4 +294,4 @@ __decorate([
294
294
  ], PickerField.prototype, "pickerElement", void 0);
295
295
 
296
296
  export { PickerField as P };
297
- //# sourceMappingURL=picker-field-DmXYPvbF.js.map
297
+ //# sourceMappingURL=picker-field-BiM3iXAQ.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"picker-field-DmXYPvbF.js","sources":["../../src/__internal/picker-field.ts"],"sourcesContent":["import { html, type PropertyValues, type TemplateResult } from 'lit';\nimport { property, query, state } from 'lit/decorators.js';\n\nimport { spread } from '@/__internal/directive/spread.js';\nimport { I18nController } from '@/__internal/i18n/i18n-controller.js';\nimport BaseField from '../input/BaseField.js';\nimport type { ControlValidity } from '../input/BaseInput.js';\nimport type { Popover } from '../popover/popover.js';\n\n/** A picker hosted in a field's popover: it takes focus when the popover opens. */\ninterface FocusablePicker extends HTMLElement {\n focus(): void;\n}\n\n/** Why a parsed value is not allowed: the validity flag it sets and the message to show. */\nexport interface ValueProblem {\n flag: 'rangeUnderflow' | 'rangeOverflow' | 'badInput';\n message: string;\n}\n\n/**\n * Base for text fields that open a picker in a popover: `wc-date-field`, `wc-time-field` and\n * `wc-datetime-field`.\n *\n * The field keeps the typed text in `draft` and parses it on blur or Enter. Valid text becomes\n * `value` (always ISO, so forms submit a locale-independent value) and fires `change`; text that\n * does not parse, or falls outside `min`/`max`, keeps the draft, shows an error and makes the\n * field invalid (`badInput`, `rangeUnderflow` or `rangeOverflow`). Values picked in the popover\n * fire `input` while they change and `change` once committed.\n *\n * Subclasses supply the parsing, formatting, validation and the picker itself.\n */\nexport default abstract class PickerField extends BaseField {\n // ── Properties ───────────────────────────────────────────────────────────\n\n /** The value as an ISO string; empty when there is none. */\n @property({ type: String }) value = '';\n\n /** BCP 47 locale for display and typed input; defaults to the page language. */\n @property({ type: String }) locale = '';\n\n /** Where the picker opens, relative to the field. */\n @property({ type: String }) placement: Popover['placement'] = 'bottom-start';\n\n // ── State ────────────────────────────────────────────────────────────────\n\n /** Text in the input; differs from the formatted `value` while the person is typing. */\n @state() protected draft = '';\n\n @state() protected pickerOpen = false;\n\n /** Message for typed text that could not be used; empty when the text is fine. */\n @state() protected invalidText = '';\n\n /** The validity flag `invalidText` stands for. */\n @state() protected invalidFlag: ValueProblem['flag'] = 'badInput';\n\n // ── Queries ──────────────────────────────────────────────────────────────\n\n @query('wc-popover') protected popoverElement?: Popover;\n\n @query('.input') protected inputElement?: HTMLInputElement;\n\n @query('.picker') protected pickerElement?: FocusablePicker;\n\n // ── Private fields ───────────────────────────────────────────────────────\n\n /** The last value announced with `change`; closing the popover commits anything newer. */\n private lastCommitted = '';\n\n /** Whether to move focus back to the input when the popover closes. */\n private restoreFocus = false;\n\n /** Peacock's strings and the locale values are shown in. */\n protected readonly i18n = new I18nController(this);\n\n // ── Abstract members ─────────────────────────────────────────────────────\n\n /** Material icon name for the button that opens the picker. */\n protected abstract readonly pickerIcon: string;\n\n /** Accessible name for the button that opens the picker. */\n protected abstract get pickerLabel(): string;\n\n /** Whether a value committed in the picker closes the popover. */\n protected abstract closeOnCommit(value: string): boolean;\n\n /** Parses typed text to an ISO value, or returns null when it cannot be read. */\n protected abstract parseText(text: string): string | null;\n\n /** Formats an ISO value as display text. */\n protected abstract formatValue(value: string): string;\n\n /** The format hint used for the placeholder and the error message. */\n protected abstract formatHint(): string;\n\n /** Returns the problem when a parsed value is not allowed (outside min/max), else null. */\n protected abstract validateValue(value: string): ValueProblem | null;\n\n /** Renders the picker inside the popover. It must carry the `picker` class. */\n protected abstract renderPicker(): TemplateResult;\n\n // ── Lifecycle ────────────────────────────────────────────────────────────\n\n override connectedCallback() {\n super.connectedCallback();\n this.lastCommitted = this.value;\n }\n\n protected override willUpdate(changed: PropertyValues<this>) {\n super.willUpdate(changed);\n if (changed.has('value') || changed.has('locale')) {\n this.draft = this.formatValue(this.value);\n this.invalidText = '';\n }\n }\n\n // ── Public methods ───────────────────────────────────────────────────────\n\n override focus() {\n this.inputElement?.focus();\n }\n\n override blur() {\n this.inputElement?.blur();\n }\n\n /** Opens the picker and moves focus into it. */\n showPicker() {\n if (this.disabled || this.readonly) return;\n this.popoverElement?.show();\n this.updateComplete.then(() => {\n requestAnimationFrame(() => this.pickerElement?.focus());\n });\n }\n\n /** Closes the picker. */\n hidePicker() {\n this.popoverElement?.hide();\n }\n\n // ── Protected methods ────────────────────────────────────────────────────\n\n protected get resolvedLocale(): string {\n return this.i18n.locale;\n }\n\n protected override computeValidity(): ControlValidity {\n if (this.invalidText && !this.disabled) {\n return {\n flags: { [this.invalidFlag]: true },\n message: this.invalidText,\n };\n }\n return super.computeValidity();\n }\n\n protected override validityAnchor() {\n return this.inputElement;\n }\n\n /** Sets the value and fires `change`. */\n protected commit(value: string) {\n this.value = value;\n this.lastCommitted = value;\n this.emitValue('change');\n }\n\n /** Sets the value and fires `input`, for a change that is not committed yet. */\n protected preview(value: string) {\n this.value = value;\n this.emitValue('input');\n }\n\n protected override clearValue() {\n this.preview('');\n this.commit('');\n }\n\n protected handlePickerInput(event: CustomEvent<{ value: string }>) {\n event.stopPropagation();\n this.preview(event.detail.value);\n }\n\n protected handlePickerChange(event: CustomEvent<{ value: string }>) {\n event.stopPropagation();\n this.commit(event.detail.value);\n if (this.closeOnCommit(event.detail.value)) {\n this.restoreFocus = true;\n this.hidePicker();\n }\n }\n\n // ── Private methods ──────────────────────────────────────────────────────\n\n private handleTextInput(event: InputEvent) {\n // The native event escapes the shadow root; the field fires its own `input` from the picker.\n event.stopPropagation();\n this.draft = (event.target as HTMLInputElement).value;\n this.invalidText = '';\n }\n\n private handleTextChange(event?: Event) {\n event?.stopPropagation();\n const text = this.draft.trim();\n if (!text) {\n this.invalidText = '';\n if (this.value) this.commit('');\n return;\n }\n const parsed = this.parseText(text);\n if (parsed === null) {\n this.invalidFlag = 'badInput';\n this.invalidText = this.i18n.t('enterFormat')(this.formatHint());\n return;\n }\n const problem = this.validateValue(parsed);\n if (problem) {\n this.invalidFlag = problem.flag;\n this.invalidText = problem.message;\n return;\n }\n if (parsed !== this.value) this.commit(parsed);\n // The value may be unchanged while the text differs (`6/11/26` for `06/11/2026`).\n this.draft = this.formatValue(parsed);\n }\n\n private handleTextKeyDown(event: KeyboardEvent) {\n if (event.key === 'Enter') this.handleTextChange();\n if (event.key === 'ArrowDown' && event.altKey) {\n event.preventDefault();\n this.showPicker();\n }\n }\n\n private handleKeyDown(event: KeyboardEvent) {\n if (event.key === 'Escape' && this.pickerOpen) {\n event.stopPropagation();\n this.restoreFocus = true;\n this.hidePicker();\n }\n }\n\n private handleButtonClick(event: MouseEvent) {\n // Keep the field from moving focus to the text input.\n event.stopPropagation();\n if (this.pickerOpen) this.hidePicker();\n else this.showPicker();\n }\n\n /**\n * The popover's `open`/`close` (and those of anything inside it) are internal: they bubble and\n * are composed, so stop them here, or consumers listening on the field would hear them.\n */\n private handleOverlayEvent = (event: Event) => {\n event.stopPropagation();\n if (event.target !== this.popoverElement) return;\n if (event.type === 'open') this.handlePopoverOpen();\n else this.handlePopoverClose();\n };\n\n private handlePopoverOpen() {\n this.pickerOpen = true;\n }\n\n private handlePopoverClose() {\n this.pickerOpen = false;\n if (this.value !== this.lastCommitted) this.commit(this.value);\n if (this.restoreFocus) {\n this.restoreFocus = false;\n this.focus();\n }\n }\n\n // ── Render helpers ───────────────────────────────────────────────────────\n\n private renderPickerButton() {\n return html`<wc-icon-button\n slot=\"field-end\"\n class=\"picker-button\"\n shape=\"round\"\n variant=\"text\"\n color=\"secondary\"\n size=\"sm\"\n aria-label=${this.pickerLabel}\n aria-haspopup=\"dialog\"\n aria-expanded=${String(this.pickerOpen)}\n ?disabled=${this.disabled || this.readonly}\n @click=${this.handleButtonClick}\n >\n <wc-icon name=${this.pickerIcon}></wc-icon>\n </wc-icon-button>`;\n }\n\n // ── Render ───────────────────────────────────────────────────────────────\n\n render() {\n return html`\n <wc-popover\n class=\"popover\"\n trigger=\"manual\"\n placement=${this.placement}\n offset=\"4\"\n @keydown=${this.handleKeyDown}\n @open=${this.handleOverlayEvent}\n @close=${this.handleOverlayEvent}\n >\n ${this.renderField(\n html`<input\n class=\"input\"\n spellcheck=\"false\"\n autocomplete=\"off\"\n placeholder=${this.placeholder || this.formatHint()}\n .value=${this.draft}\n ?disabled=${this.disabled}\n ?readonly=${this.readonly}\n ?required=${this.required}\n @input=${this.handleTextInput}\n @change=${this.handleTextChange}\n @keydown=${this.handleTextKeyDown}\n @focus=${this.handleFieldFocus}\n @blur=${this.handleFieldFocus}\n ${spread(this.fieldAria(this.invalidText))}\n />`,\n {\n populated: !!this.draft,\n focused: this.focused || this.pickerOpen,\n controlError: this.invalidText,\n end: this.renderPickerButton(),\n },\n )}\n <wc-popover-content\n class=\"picker-panel\"\n role=\"dialog\"\n aria-label=${this.pickerLabel}\n >\n ${this.renderPicker()}\n </wc-popover-content>\n </wc-popover>\n `;\n }\n}\n"],"names":["html","property","state","query"],"mappings":";;;;;;;;AAoBA;;;;;;;;;;;AAWG;AACW,MAAgB,WAAY,SAAQ,SAAS,CAAA;AAA3D,IAAA,WAAA,GAAA;;;;QAI8B,IAAA,CAAA,KAAK,GAAG,EAAE;;QAGV,IAAA,CAAA,MAAM,GAAG,EAAE;;QAGX,IAAA,CAAA,SAAS,GAAyB,cAAc;;;QAKzD,IAAA,CAAA,KAAK,GAAG,EAAE;QAEV,IAAA,CAAA,UAAU,GAAG,KAAK;;QAGlB,IAAA,CAAA,WAAW,GAAG,EAAE;;QAGhB,IAAA,CAAA,WAAW,GAAyB,UAAU;;;QAazD,IAAA,CAAA,aAAa,GAAG,EAAE;;QAGlB,IAAA,CAAA,YAAY,GAAG,KAAK;;AAGT,QAAA,IAAA,CAAA,IAAI,GAAG,IAAI,cAAc,CAAC,IAAI,CAAC;AAgLlD;;;AAGG;AACK,QAAA,IAAA,CAAA,kBAAkB,GAAG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AA,WAAA,CAAA,SAAA,EAAA,OAAA,EAAA,MAAA,CAAA;AAGX,UAAA,CAAA;AAA3B,IAAAA,CAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE;AAAc,CAAA,EAAA,WAAA,CAAA,SAAA,EAAA,QAAA,EAAA,MAAA,CAAA;AAGZ,UAAA,CAAA;AAA3B,IAAAA,CAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE;AAAmD,CAAA,EAAA,WAAA,CAAA,SAAA,EAAA,WAAA,EAAA,MAAA,CAAA;AAK1D,UAAA,CAAA;AAAlB,IAAAC,CAAK;AAAwB,CAAA,EAAA,WAAA,CAAA,SAAA,EAAA,OAAA,EAAA,MAAA,CAAA;AAEX,UAAA,CAAA;AAAlB,IAAAA,CAAK;AAAgC,CAAA,EAAA,WAAA,CAAA,SAAA,EAAA,YAAA,EAAA,MAAA,CAAA;AAGnB,UAAA,CAAA;AAAlB,IAAAA,CAAK;AAA8B,CAAA,EAAA,WAAA,CAAA,SAAA,EAAA,aAAA,EAAA,MAAA,CAAA;AAGjB,UAAA,CAAA;AAAlB,IAAAA,CAAK;AAA4D,CAAA,EAAA,WAAA,CAAA,SAAA,EAAA,aAAA,EAAA,MAAA,CAAA;AAInC,UAAA,CAAA;IAA9BC,CAAK,CAAC,YAAY;AAAqC,CAAA,EAAA,WAAA,CAAA,SAAA,EAAA,gBAAA,EAAA,MAAA,CAAA;AAE7B,UAAA,CAAA;IAA1BA,CAAK,CAAC,QAAQ;AAA4C,CAAA,EAAA,WAAA,CAAA,SAAA,EAAA,cAAA,EAAA,MAAA,CAAA;AAE/B,UAAA,CAAA;IAA3BA,CAAK,CAAC,SAAS;AAA4C,CAAA,EAAA,WAAA,CAAA,SAAA,EAAA,eAAA,EAAA,MAAA,CAAA;;;;"}
1
+ {"version":3,"file":"picker-field-BiM3iXAQ.js","sources":["../../src/__internal/picker-field.ts"],"sourcesContent":["import { html, type PropertyValues, type TemplateResult } from 'lit';\nimport { property, query, state } from 'lit/decorators.js';\n\nimport { spread } from '@/__internal/directive/spread.js';\nimport { I18nController } from '@/__internal/i18n/i18n-controller.js';\nimport BaseField from '../input/BaseField.js';\nimport type { ControlValidity } from '../input/BaseInput.js';\nimport type { Popover } from '../popover/popover.js';\n\n/** A picker hosted in a field's popover: it takes focus when the popover opens. */\ninterface FocusablePicker extends HTMLElement {\n focus(): void;\n}\n\n/** Why a parsed value is not allowed: the validity flag it sets and the message to show. */\nexport interface ValueProblem {\n flag: 'rangeUnderflow' | 'rangeOverflow' | 'badInput';\n message: string;\n}\n\n/**\n * Base for text fields that open a picker in a popover: `wc-date-field`, `wc-time-field` and\n * `wc-datetime-field`.\n *\n * The field keeps the typed text in `draft` and parses it on blur or Enter. Valid text becomes\n * `value` (always ISO, so forms submit a locale-independent value) and fires `change`; text that\n * does not parse, or falls outside `min`/`max`, keeps the draft, shows an error and makes the\n * field invalid (`badInput`, `rangeUnderflow` or `rangeOverflow`). Values picked in the popover\n * fire `input` while they change and `change` once committed.\n *\n * Subclasses supply the parsing, formatting, validation and the picker itself.\n */\nexport default abstract class PickerField extends BaseField {\n // ── Properties ───────────────────────────────────────────────────────────\n\n /** The value as an ISO string; empty when there is none. */\n @property({ type: String }) value = '';\n\n /** BCP 47 locale for display and typed input; defaults to the page language. */\n @property({ type: String }) locale = '';\n\n /** Where the picker opens, relative to the field. */\n @property({ type: String }) placement: Popover['placement'] = 'bottom-start';\n\n // ── State ────────────────────────────────────────────────────────────────\n\n /** Text in the input; differs from the formatted `value` while the person is typing. */\n @state() protected draft = '';\n\n @state() protected pickerOpen = false;\n\n /** Message for typed text that could not be used; empty when the text is fine. */\n @state() protected invalidText = '';\n\n /** The validity flag `invalidText` stands for. */\n @state() protected invalidFlag: ValueProblem['flag'] = 'badInput';\n\n // ── Queries ──────────────────────────────────────────────────────────────\n\n @query('wc-popover') protected popoverElement?: Popover;\n\n @query('.input') protected inputElement?: HTMLInputElement;\n\n @query('.picker') protected pickerElement?: FocusablePicker;\n\n // ── Private fields ───────────────────────────────────────────────────────\n\n /** The last value announced with `change`; closing the popover commits anything newer. */\n private lastCommitted = '';\n\n /** Whether to move focus back to the input when the popover closes. */\n private restoreFocus = false;\n\n /** Peacock's strings and the locale values are shown in. */\n protected readonly i18n = new I18nController(this);\n\n // ── Abstract members ─────────────────────────────────────────────────────\n\n /** Material icon name for the button that opens the picker. */\n protected abstract readonly pickerIcon: string;\n\n /** Accessible name for the button that opens the picker. */\n protected abstract get pickerLabel(): string;\n\n /** Whether a value committed in the picker closes the popover. */\n protected abstract closeOnCommit(value: string): boolean;\n\n /** Parses typed text to an ISO value, or returns null when it cannot be read. */\n protected abstract parseText(text: string): string | null;\n\n /** Formats an ISO value as display text. */\n protected abstract formatValue(value: string): string;\n\n /** The format hint used for the placeholder and the error message. */\n protected abstract formatHint(): string;\n\n /** Returns the problem when a parsed value is not allowed (outside min/max), else null. */\n protected abstract validateValue(value: string): ValueProblem | null;\n\n /** Renders the picker inside the popover. It must carry the `picker` class. */\n protected abstract renderPicker(): TemplateResult;\n\n // ── Lifecycle ────────────────────────────────────────────────────────────\n\n override connectedCallback() {\n super.connectedCallback();\n this.lastCommitted = this.value;\n }\n\n protected override willUpdate(changed: PropertyValues<this>) {\n super.willUpdate(changed);\n if (changed.has('value') || changed.has('locale')) {\n this.draft = this.formatValue(this.value);\n this.invalidText = '';\n }\n }\n\n // ── Public methods ───────────────────────────────────────────────────────\n\n override focus() {\n this.inputElement?.focus();\n }\n\n override blur() {\n this.inputElement?.blur();\n }\n\n /** Opens the picker and moves focus into it. */\n showPicker() {\n if (this.disabled || this.readonly) return;\n this.popoverElement?.show();\n this.updateComplete.then(() => {\n requestAnimationFrame(() => this.pickerElement?.focus());\n });\n }\n\n /** Closes the picker. */\n hidePicker() {\n this.popoverElement?.hide();\n }\n\n // ── Protected methods ────────────────────────────────────────────────────\n\n protected get resolvedLocale(): string {\n return this.i18n.locale;\n }\n\n protected override computeValidity(): ControlValidity {\n if (this.invalidText && !this.disabled) {\n return {\n flags: { [this.invalidFlag]: true },\n message: this.invalidText,\n };\n }\n return super.computeValidity();\n }\n\n protected override validityAnchor() {\n return this.inputElement;\n }\n\n /** Sets the value and fires `change`. */\n protected commit(value: string) {\n this.value = value;\n this.lastCommitted = value;\n this.emitValue('change');\n }\n\n /** Sets the value and fires `input`, for a change that is not committed yet. */\n protected preview(value: string) {\n this.value = value;\n this.emitValue('input');\n }\n\n protected override clearValue() {\n this.preview('');\n this.commit('');\n }\n\n protected handlePickerInput(event: CustomEvent<{ value: string }>) {\n event.stopPropagation();\n this.preview(event.detail.value);\n }\n\n protected handlePickerChange(event: CustomEvent<{ value: string }>) {\n event.stopPropagation();\n this.commit(event.detail.value);\n if (this.closeOnCommit(event.detail.value)) {\n this.restoreFocus = true;\n this.hidePicker();\n }\n }\n\n // ── Private methods ──────────────────────────────────────────────────────\n\n private handleTextInput(event: InputEvent) {\n // The native event escapes the shadow root; the field fires its own `input` from the picker.\n event.stopPropagation();\n this.draft = (event.target as HTMLInputElement).value;\n this.invalidText = '';\n }\n\n private handleTextChange(event?: Event) {\n event?.stopPropagation();\n const text = this.draft.trim();\n if (!text) {\n this.invalidText = '';\n if (this.value) this.commit('');\n return;\n }\n const parsed = this.parseText(text);\n if (parsed === null) {\n this.invalidFlag = 'badInput';\n this.invalidText = this.i18n.t('enterFormat')(this.formatHint());\n return;\n }\n const problem = this.validateValue(parsed);\n if (problem) {\n this.invalidFlag = problem.flag;\n this.invalidText = problem.message;\n return;\n }\n if (parsed !== this.value) this.commit(parsed);\n // The value may be unchanged while the text differs (`6/11/26` for `06/11/2026`).\n this.draft = this.formatValue(parsed);\n }\n\n private handleTextKeyDown(event: KeyboardEvent) {\n if (event.key === 'Enter') this.handleTextChange();\n if (event.key === 'ArrowDown' && event.altKey) {\n event.preventDefault();\n this.showPicker();\n }\n }\n\n private handleKeyDown(event: KeyboardEvent) {\n if (event.key === 'Escape' && this.pickerOpen) {\n event.stopPropagation();\n this.restoreFocus = true;\n this.hidePicker();\n }\n }\n\n private handleButtonClick(event: MouseEvent) {\n // Keep the field from moving focus to the text input.\n event.stopPropagation();\n if (this.pickerOpen) this.hidePicker();\n else this.showPicker();\n }\n\n /**\n * The popover's `open`/`close` (and those of anything inside it) are internal: they bubble and\n * are composed, so stop them here, or consumers listening on the field would hear them.\n */\n private handleOverlayEvent = (event: Event) => {\n event.stopPropagation();\n if (event.target !== this.popoverElement) return;\n if (event.type === 'open') this.handlePopoverOpen();\n else this.handlePopoverClose();\n };\n\n private handlePopoverOpen() {\n this.pickerOpen = true;\n }\n\n private handlePopoverClose() {\n this.pickerOpen = false;\n if (this.value !== this.lastCommitted) this.commit(this.value);\n if (this.restoreFocus) {\n this.restoreFocus = false;\n this.focus();\n }\n }\n\n // ── Render helpers ───────────────────────────────────────────────────────\n\n private renderPickerButton() {\n return html`<wc-icon-button\n slot=\"field-end\"\n class=\"picker-button\"\n shape=\"round\"\n variant=\"text\"\n color=\"secondary\"\n size=\"sm\"\n aria-label=${this.pickerLabel}\n aria-haspopup=\"dialog\"\n aria-expanded=${String(this.pickerOpen)}\n ?disabled=${this.disabled || this.readonly}\n @click=${this.handleButtonClick}\n >\n <wc-icon name=${this.pickerIcon}></wc-icon>\n </wc-icon-button>`;\n }\n\n // ── Render ───────────────────────────────────────────────────────────────\n\n render() {\n return html`\n <wc-popover\n class=\"popover\"\n trigger=\"manual\"\n placement=${this.placement}\n offset=\"4\"\n @keydown=${this.handleKeyDown}\n @open=${this.handleOverlayEvent}\n @close=${this.handleOverlayEvent}\n >\n ${this.renderField(\n html`<input\n class=\"input\"\n spellcheck=\"false\"\n autocomplete=\"off\"\n placeholder=${this.placeholder || this.formatHint()}\n .value=${this.draft}\n ?disabled=${this.disabled}\n ?readonly=${this.readonly}\n ?required=${this.required}\n @input=${this.handleTextInput}\n @change=${this.handleTextChange}\n @keydown=${this.handleTextKeyDown}\n @focus=${this.handleFieldFocus}\n @blur=${this.handleFieldFocus}\n ${spread(this.fieldAria(this.invalidText))}\n />`,\n {\n populated: !!this.draft,\n focused: this.focused || this.pickerOpen,\n controlError: this.invalidText,\n end: this.renderPickerButton(),\n },\n )}\n <wc-popover-content\n class=\"picker-panel\"\n role=\"dialog\"\n aria-label=${this.pickerLabel}\n >\n ${this.renderPicker()}\n </wc-popover-content>\n </wc-popover>\n `;\n }\n}\n"],"names":["html","property","state","query"],"mappings":";;;;;;;;AAoBA;;;;;;;;;;;AAWG;AACW,MAAgB,WAAY,SAAQ,SAAS,CAAA;AAA3D,IAAA,WAAA,GAAA;;;;QAI8B,IAAA,CAAA,KAAK,GAAG,EAAE;;QAGV,IAAA,CAAA,MAAM,GAAG,EAAE;;QAGX,IAAA,CAAA,SAAS,GAAyB,cAAc;;;QAKzD,IAAA,CAAA,KAAK,GAAG,EAAE;QAEV,IAAA,CAAA,UAAU,GAAG,KAAK;;QAGlB,IAAA,CAAA,WAAW,GAAG,EAAE;;QAGhB,IAAA,CAAA,WAAW,GAAyB,UAAU;;;QAazD,IAAA,CAAA,aAAa,GAAG,EAAE;;QAGlB,IAAA,CAAA,YAAY,GAAG,KAAK;;AAGT,QAAA,IAAA,CAAA,IAAI,GAAG,IAAI,cAAc,CAAC,IAAI,CAAC;AAgLlD;;;AAGG;AACK,QAAA,IAAA,CAAA,kBAAkB,GAAG,CAAC,KAAY,KAAI;YAC5C,KAAK,CAAC,eAAe,EAAE;AACvB,YAAA,IAAI,KAAK,CAAC,MAAM,KAAK,IAAI,CAAC,cAAc;gBAAE;AAC1C,YAAA,IAAI,KAAK,CAAC,IAAI,KAAK,MAAM;gBAAE,IAAI,CAAC,iBAAiB,EAAE;;gBAC9C,IAAI,CAAC,kBAAkB,EAAE;AAChC,QAAA,CAAC;IAkFH;;IA7OW,iBAAiB,GAAA;QACxB,KAAK,CAAC,iBAAiB,EAAE;AACzB,QAAA,IAAI,CAAC,aAAa,GAAG,IAAI,CAAC,KAAK;IACjC;AAEmB,IAAA,UAAU,CAAC,OAA6B,EAAA;AACzD,QAAA,KAAK,CAA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,CAAA;AAEX,UAAA,CAAA;AAAlB,IAAAA,CAAK;AAAgC,CAAA,EAAA,WAAA,CAAA,SAAA,EAAA,YAAA,EAAA,MAAA,CAAA;AAGnB,UAAA,CAAA;AAAlB,IAAAA,CAAK;AAA8B,CAAA,EAAA,WAAA,CAAA,SAAA,EAAA,aAAA,EAAA,MAAA,CAAA;AAGjB,UAAA,CAAA;AAAlB,IAAAA,CAAK;AAA4D,CAAA,EAAA,WAAA,CAAA,SAAA,EAAA,aAAA,EAAA,MAAA,CAAA;AAInC,UAAA,CAAA;IAA9BC,CAAK,CAAC,YAAY;AAAqC,CAAA,EAAA,WAAA,CAAA,SAAA,EAAA,gBAAA,EAAA,MAAA,CAAA;AAE7B,UAAA,CAAA;IAA1BA,CAAK,CAAC,QAAQ;AAA4C,CAAA,EAAA,WAAA,CAAA,SAAA,EAAA,cAAA,EAAA,MAAA,CAAA;AAE/B,UAAA,CAAA;IAA3BA,CAAK,CAAC,SAAS;AAA4C,CAAA,EAAA,WAAA,CAAA,SAAA,EAAA,eAAA,EAAA,MAAA,CAAA;;;;"}
package/dist/pin-input.js CHANGED
@@ -5,13 +5,16 @@ import { l } from './live-D_5OfuGD.js';
5
5
  import { a as ALWAYS_SENSITIVE } from './ai-controller-DR_Tg0sN.js';
6
6
  import { s as spread } from './spread-B5cgadZl.js';
7
7
  import { I as I18nController } from './i18n-controller-BTeChxE0.js';
8
- import { B as BaseField } from './BaseField-BbOj212R.js';
8
+ import { B as BaseField } from './BaseField-DOCmylob.js';
9
9
  import './base-Cl6v8-BZ.js';
10
10
  import './directive-ZPhl09Yt.js';
11
11
  import './directive-helpers-Bx3mu42O.js';
12
12
  import './locale-DEsJZCQG.js';
13
13
  import './strings-DeiQWMd9.js';
14
14
  import './state-BCeDVCI9.js';
15
+ import './implicit-submission-ChLdbxaR.js';
16
+ import './dispatch-hooks-J_godlHh.js';
17
+ import './form-submission-h40coUI8.js';
15
18
  import './BaseInput-Cv03GZLu.js';
16
19
  import './element-internals-QME0yEz4.js';
17
20
  import './form-associated-BHbg72PG.js';
@@ -1 +1 @@
1
- {"version":3,"file":"pin-input.js","sources":["../../src/pin-input/pin-input.ts"],"sourcesContent":["import { html, nothing, type PropertyValues } from 'lit';\nimport { property, queryAll } from 'lit/decorators.js';\nimport { live } from 'lit/directives/live.js';\n\nimport { ALWAYS_SENSITIVE } from '@/__internal/ai/ai-controller.js';\nimport { spread } from '@/__internal/directive/spread.js';\nimport { I18nController } from '@/__internal/i18n/i18n-controller.js';\nimport IndividualComponent from '@/IndividualComponent.js';\n\nimport BaseField from '../input/BaseField.js';\nimport type { ControlValidity } from '../input/BaseInput.js';\nimport styles from './pin-input.scss';\n\n/** Which characters a pin input takes: digits only, or letters and digits. */\nexport type PinInputType = 'numeric' | 'alphanumeric';\n\n/**\n * @label Pin Input\n * @tag wc-pin-input\n * @rawTag pin-input\n *\n * @summary A row of single-character cells for a one-time code or PIN.\n * @overview\n * <p>Pin input takes a code of <code>length</code> characters (6 by default), one per cell. Its\n * <code>value</code> is the code as one string, and inside a <code>&lt;form&gt;</code> it is\n * submitted under its <code>name</code>. The cells sit in one field box, so <code>variant</code>,\n * <code>size</code>, the states and the <code>start</code>/<code>end</code> slots look as on every\n * other field.</p>\n * <p><code>type=\"numeric\"</code> (the default) takes digits and shows the numeric keypad on phones;\n * <code>type=\"alphanumeric\"</code> takes the letters A–Z and digits and uppercases letters, so the\n * value is what the cells show. Anything else is ignored, so a pasted or autofilled\n * <code>123-456</code> or <code>G-123456</code> fills <code>123456</code>. <code>masked</code>\n * hides the characters like a password.</p>\n * <p>The first cell has <code>autocomplete=\"one-time-code\"</code>, so a code from a text message can\n * be filled in by the phone. Typing moves to the next cell and typing over a filled cell replaces\n * it. Backspace clears the cell, or, in an empty cell, the one before it; Delete clears the cell.\n * Left, Right, Home and End move between cells, and Tab leaves the row. The code is always filled\n * from the start: a cell after the first empty one cannot be focused. The cells always run left to\n * right, as codes are written, also in right-to-left pages.</p>\n * <p>Validation: with <code>required</code> an empty code is <code>valueMissing</code>; a code that\n * is started but not complete is <code>tooShort</code> (whether required or not), like text under\n * a native <code>minlength</code>. The message shows once the code is committed or the form is\n * submitted.</p>\n *\n * @fires {CustomEvent<{value: string}>} input - Dispatched on every change of the code.\n * @fires {CustomEvent<{value: string}>} change - Dispatched when the code is committed: when it becomes complete, and when focus leaves the cells after a change.\n * @fires {CustomEvent<{value: string}>} complete - Dispatched when the person fills the last empty cell.\n *\n * @cssprop --pin-input-cell-width - Width of each cell.\n *\n * @example\n * ```html\n * <wc-pin-input label=\"Verification code\" name=\"code\" required></wc-pin-input>\n * ```\n * @example\n * ```html\n * <wc-pin-input label=\"PIN\" length=\"4\" masked></wc-pin-input>\n * ```\n * @tags input, form\n */\n@IndividualComponent\nexport class PinInput extends BaseField {\n // ── Static ───────────────────────────────────────────────────────────────\n\n static styles = [styles];\n\n /** A PIN or one-time code never reaches a model (ADR-030002). */\n static readonly [ALWAYS_SENSITIVE] = true;\n\n // ── Properties ───────────────────────────────────────────────────────────\n\n /** The code as one string, from the first cell on. */\n @property({ type: String })\n value = '';\n\n /** Number of cells, the length of a complete code. */\n @property({ type: Number })\n length = 6;\n\n /** Which characters the cells take: `numeric` (digits) or `alphanumeric` (A–Z and digits). */\n @property({ type: String })\n type: PinInputType = 'numeric';\n\n /** Hides the characters like a password. */\n @property({ type: Boolean, reflect: true })\n masked = false;\n\n // ── Queries ──────────────────────────────────────────────────────────────\n\n @queryAll('.cell')\n private cells!: ArrayLike<HTMLInputElement> & Iterable<HTMLInputElement>;\n\n // ── Private fields ───────────────────────────────────────────────────────\n\n /** Peacock's strings for the cell names and the incomplete message. */\n private readonly i18n = new I18nController(this);\n\n /** The cell that takes Tab focus: the focused one, else the first empty one. */\n private activeIndex = 0;\n\n /** The value when it was last committed; `change` fires when it differs. */\n private committedValue = '';\n\n // ── Lifecycle ────────────────────────────────────────────────────────────\n\n override connectedCallback() {\n super.connectedCallback();\n this.committedValue = this.sanitize(this.value);\n }\n\n protected override willUpdate(changed: PropertyValues) {\n super.willUpdate(changed);\n if (changed.has('value') || changed.has('length') || changed.has('type')) {\n // Keep only the characters the cells take, so `value` is always what they show.\n this.value = this.sanitize(this.value);\n }\n }\n\n // ── Public methods ───────────────────────────────────────────────────────\n\n /** Focuses the first empty cell, or the last cell when the code is complete. */\n override focus(options?: Parameters<HTMLElement['focus']>[0]) {\n this.cells?.[this.firstEmptyIndex()]?.focus(options);\n }\n\n override blur() {\n for (const cell of Array.from(this.cells ?? [])) cell.blur();\n }\n\n /** Empties every cell. Like setting `value`, it fires no events and leaves focus alone. */\n clear() {\n this.value = '';\n this.committedValue = '';\n }\n\n // ── Protected methods ────────────────────────────────────────────────────\n\n protected override computeValidity(): ControlValidity {\n if (this.disabled) return { flags: {}, message: '' };\n const anchor = this.cells?.[this.firstEmptyIndex()];\n if (!this.value) {\n return this.required\n ? {\n flags: { valueMissing: true },\n message: this.valueMissingText(),\n anchor,\n }\n : { flags: {}, message: '' };\n }\n if (this.value.length < this.cellCount) {\n return {\n flags: { tooShort: true },\n message: this.i18n.t('pinInputIncomplete')(this.cellCount),\n anchor,\n };\n }\n return { flags: {}, message: '' };\n }\n\n protected override validityAnchor() {\n return this.cells?.[0];\n }\n\n protected override clearValue() {\n super.clearValue();\n this.committedValue = '';\n }\n\n override formResetCallback() {\n super.formResetCallback();\n this.committedValue = this.sanitize(this.value);\n }\n\n // ── Private methods ──────────────────────────────────────────────────────\n\n /** The number of cells: `length` as a whole number, at least 1. */\n private get cellCount(): number {\n const count = Math.floor(Number(this.length));\n return Number.isFinite(count) && count >= 1 ? count : 6;\n }\n\n private get editable(): boolean {\n return !this.disabled && !this.readonly;\n }\n\n /** Index of the first empty cell; the last cell when the code is complete. */\n private firstEmptyIndex(): number {\n return Math.min(this.value.length, this.cellCount - 1);\n }\n\n /** Keeps the characters the type takes (uppercased for alphanumeric), up to `length`. */\n private sanitize(text: unknown): string {\n const raw = text === undefined || text === null ? '' : String(text);\n const kept =\n this.type === 'alphanumeric'\n ? raw.replace(/[^0-9a-z]/gi, '').toUpperCase()\n : raw.replace(/\\D/g, '');\n return kept.slice(0, this.cellCount);\n }\n\n /** Writes `chars` into the cells from `index` on, then moves focus past them. */\n private fill(index: number, chars: string) {\n const before = this.value;\n const next = (\n before.slice(0, index) +\n chars +\n before.slice(index + chars.length)\n ).slice(0, this.cellCount);\n // Value first, so the cell focused next counts as reachable.\n this.setValueFromUser(next);\n this.focusCell(index + chars.length);\n }\n\n /** Removes the character at `index`; the ones after it move up one cell. */\n private removeAt(index: number) {\n if (index >= this.value.length) return;\n this.setValueFromUser(\n this.value.slice(0, index) + this.value.slice(index + 1),\n );\n }\n\n private setValueFromUser(next: string) {\n if (next === this.value) {\n // Put back a character the cell rejected.\n this.requestUpdate();\n return;\n }\n const wasComplete = this.value.length === this.cellCount;\n this.value = next;\n this.emitValue('input');\n if (!wasComplete && next.length === this.cellCount) {\n this.commit();\n this.dispatchEvent(\n new CustomEvent('complete', {\n detail: { value: next },\n bubbles: true,\n composed: true,\n }),\n );\n }\n }\n\n private commit() {\n if (this.value === this.committedValue) return;\n this.committedValue = this.value;\n this.emitValue('change');\n }\n\n private focusCell(index: number) {\n const target = Math.max(0, Math.min(index, this.firstEmptyIndex()));\n this.activeIndex = target;\n const cell = this.cells?.[target];\n cell?.focus();\n cell?.select();\n }\n\n private cellIndex(event: Event): number {\n return Number((event.target as HTMLElement).dataset.index ?? 0);\n }\n\n private handleKeydown(event: KeyboardEvent) {\n const index = this.cellIndex(event);\n const last = this.firstEmptyIndex();\n const { key } = event;\n if (key === 'ArrowLeft' || key === 'ArrowRight') {\n event.preventDefault();\n const step = key === 'ArrowLeft' ? -1 : 1;\n this.focusCell(Math.min(index + step, last));\n return;\n }\n if (key === 'Home' || key === 'End') {\n event.preventDefault();\n this.focusCell(key === 'Home' ? 0 : last);\n return;\n }\n if (!this.editable) return;\n if (key === 'Backspace') {\n event.preventDefault();\n if (index < this.value.length) {\n this.removeAt(index);\n } else if (index > 0) {\n this.focusCell(index - 1);\n this.removeAt(index - 1);\n }\n return;\n }\n if (key === 'Delete') {\n event.preventDefault();\n this.removeAt(index);\n return;\n }\n if (key.length === 1 && !event.ctrlKey && !event.metaKey && !event.altKey) {\n // A typed character: take it here so the cell always holds one; ignore ones the type rejects.\n event.preventDefault();\n const char = this.sanitize(key);\n if (char) this.fill(index, char);\n }\n }\n\n /** Text that reached a cell without a keydown: autofill, phone keyboards, input methods. */\n private handleInput(event: Event) {\n event.stopPropagation();\n const cell = event.target as HTMLInputElement;\n const index = this.cellIndex(event);\n if (!this.editable) return;\n const old = this.value[index] ?? '';\n if (cell.value === '') {\n this.removeAt(index);\n return;\n }\n let chars = this.sanitize(cell.value);\n // A character typed next to the one already there: keep the new one.\n if (old && chars.length === 2 && chars.includes(old)) {\n chars = chars[0] === old ? chars[1] : chars[0];\n }\n if (chars) this.fill(index, chars);\n else this.requestUpdate();\n }\n\n private handlePaste(event: ClipboardEvent) {\n event.preventDefault();\n if (!this.editable) return;\n const chars = this.sanitize(event.clipboardData?.getData('text') ?? '');\n if (chars) this.fill(this.cellIndex(event), chars);\n }\n\n private handleFocusIn(event: FocusEvent) {\n const index = this.cellIndex(event);\n const allowed = this.firstEmptyIndex();\n if (index > allowed) {\n // The code fills from the start: go to the first empty cell instead.\n this.focusCell(allowed);\n return;\n }\n this.activeIndex = index;\n (event.target as HTMLInputElement).select();\n this.focused = true;\n this.requestUpdate();\n }\n\n private handleFocusOut(event: FocusEvent) {\n const next = event.relatedTarget as Node | null;\n if (next && this.renderRoot.contains(next)) return;\n this.focused = false;\n this.activeIndex = this.firstEmptyIndex();\n this.commit();\n }\n\n private stopEvent(event: Event) {\n // Keep native events inside, and keep a click on a cell from refocusing the first empty one.\n event.stopPropagation();\n }\n\n // ── Render helpers ───────────────────────────────────────────────────────\n\n private renderCell(\n index: number,\n count: number,\n aria: Record<string, string | undefined>,\n ) {\n const name =\n this.type === 'alphanumeric'\n ? this.i18n.t('pinInputCharacter')(index + 1, count)\n : this.i18n.t('pinInputDigit')(index + 1, count);\n const tabIndex =\n index === (this.focused ? this.activeIndex : this.firstEmptyIndex())\n ? (aria.tabindex ?? '0')\n : '-1';\n return html`<input\n class=\"cell\"\n data-index=${index}\n type=${this.masked ? 'password' : 'text'}\n inputmode=${this.type === 'numeric' ? 'numeric' : 'text'}\n autocomplete=${index === 0 ? 'one-time-code' : 'off'}\n autocapitalize=${this.type === 'alphanumeric' ? 'characters' : 'off'}\n autocorrect=\"off\"\n spellcheck=\"false\"\n enterkeyhint=${index === count - 1 ? 'done' : 'next'}\n placeholder=${this.placeholder || nothing}\n tabindex=${tabIndex}\n aria-label=${name}\n aria-invalid=${aria['aria-invalid'] ?? nothing}\n aria-describedby=${aria['aria-describedby'] ?? nothing}\n aria-required=${this.required ? 'true' : nothing}\n .value=${live(this.value[index] ?? '')}\n ?readonly=${this.readonly}\n ?disabled=${this.disabled}\n @keydown=${this.handleKeydown}\n @input=${this.handleInput}\n @change=${this.stopEvent}\n @click=${this.stopEvent}\n @paste=${this.handlePaste}\n />`;\n }\n\n // ── Render ───────────────────────────────────────────────────────────────\n\n render() {\n const count = this.cellCount;\n const {\n tabindex,\n 'aria-invalid': invalid,\n 'aria-describedby': describedBy,\n ...groupAria\n } = this.fieldAria();\n const cellAria = {\n tabindex,\n 'aria-invalid': invalid,\n 'aria-describedby': describedBy,\n };\n return this.renderField(\n html`<div\n class=\"cells\"\n role=\"group\"\n dir=\"ltr\"\n @focusin=${this.handleFocusIn}\n @focusout=${this.handleFocusOut}\n ${spread(groupAria)}\n >\n ${Array.from({ length: count }, (_, index) =>\n this.renderCell(index, count, cellAria),\n )}\n </div>`,\n { populated: !!this.value, focused: this.focused },\n );\n }\n}\n"],"names":["html","nothing","live","styles","property","queryAll"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;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QAAA,CAAA,MAAM,GAAG,CAACG,QAAM,CAAC;AAExB;AACgB,QAAA,CAAA,EAAA,CAAkB,GAAG,IAAH;AAMlC,UAAA,CAAA;AADC,IAAAC,CAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE;AACf,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,OAAA,EAAA,MAAA,CAAA;AAIX,UAAA,CAAA;AADC,IAAAA,CAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE;AACf,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,QAAA,EAAA,MAAA,CAAA;AAIX,UAAA,CAAA;AADC,IAAAA,CAAQ,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE;AACK,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,MAAA,EAAA,MAAA,CAAA;AAI/B,UAAA,CAAA;IADCA,CAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE;AAC3B,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,QAAA,EAAA,MAAA,CAAA;AAKP,UAAA,CAAA;IADPC,CAAQ,CAAC,OAAO;AACwD,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,OAAA,EAAA,MAAA,CAAA;AA7B9D,QAAQ,GAAA,UAAA,CAAA;IADpB;AACY,CAAA,EAAA,QAAQ,CA6WpB;;;;"}
1
+ {"version":3,"file":"pin-input.js","sources":["../../src/pin-input/pin-input.ts"],"sourcesContent":["import { html, nothing, type PropertyValues } from 'lit';\nimport { property, queryAll } from 'lit/decorators.js';\nimport { live } from 'lit/directives/live.js';\n\nimport { ALWAYS_SENSITIVE } from '@/__internal/ai/ai-controller.js';\nimport { spread } from '@/__internal/directive/spread.js';\nimport { I18nController } from '@/__internal/i18n/i18n-controller.js';\nimport IndividualComponent from '@/IndividualComponent.js';\n\nimport BaseField from '../input/BaseField.js';\nimport type { ControlValidity } from '../input/BaseInput.js';\nimport styles from './pin-input.scss';\n\n/** Which characters a pin input takes: digits only, or letters and digits. */\nexport type PinInputType = 'numeric' | 'alphanumeric';\n\n/**\n * @label Pin Input\n * @tag wc-pin-input\n * @rawTag pin-input\n *\n * @summary A row of single-character cells for a one-time code or PIN.\n * @overview\n * <p>Pin input takes a code of <code>length</code> characters (6 by default), one per cell. Its\n * <code>value</code> is the code as one string, and inside a <code>&lt;form&gt;</code> it is\n * submitted under its <code>name</code>. The cells sit in one field box, so <code>variant</code>,\n * <code>size</code>, the states and the <code>start</code>/<code>end</code> slots look as on every\n * other field.</p>\n * <p><code>type=\"numeric\"</code> (the default) takes digits and shows the numeric keypad on phones;\n * <code>type=\"alphanumeric\"</code> takes the letters A–Z and digits and uppercases letters, so the\n * value is what the cells show. Anything else is ignored, so a pasted or autofilled\n * <code>123-456</code> or <code>G-123456</code> fills <code>123456</code>. <code>masked</code>\n * hides the characters like a password.</p>\n * <p>The first cell has <code>autocomplete=\"one-time-code\"</code>, so a code from a text message can\n * be filled in by the phone. Typing moves to the next cell and typing over a filled cell replaces\n * it. Backspace clears the cell, or, in an empty cell, the one before it; Delete clears the cell.\n * Left, Right, Home and End move between cells, and Tab leaves the row. The code is always filled\n * from the start: a cell after the first empty one cannot be focused. The cells always run left to\n * right, as codes are written, also in right-to-left pages.</p>\n * <p>Validation: with <code>required</code> an empty code is <code>valueMissing</code>; a code that\n * is started but not complete is <code>tooShort</code> (whether required or not), like text under\n * a native <code>minlength</code>. The message shows once the code is committed or the form is\n * submitted.</p>\n *\n * @fires {CustomEvent<{value: string}>} input - Dispatched on every change of the code.\n * @fires {CustomEvent<{value: string}>} change - Dispatched when the code is committed: when it becomes complete, and when focus leaves the cells after a change.\n * @fires {CustomEvent<{value: string}>} complete - Dispatched when the person fills the last empty cell.\n *\n * @cssprop --pin-input-cell-width - Width of each cell.\n *\n * @example\n * ```html\n * <wc-pin-input label=\"Verification code\" name=\"code\" required></wc-pin-input>\n * ```\n * @example\n * ```html\n * <wc-pin-input label=\"PIN\" length=\"4\" masked></wc-pin-input>\n * ```\n * @tags input, form\n */\n@IndividualComponent\nexport class PinInput extends BaseField {\n // ── Static ───────────────────────────────────────────────────────────────\n\n static styles = [styles];\n\n /** A PIN or one-time code never reaches a model (ADR-030002). */\n static readonly [ALWAYS_SENSITIVE] = true;\n\n // ── Properties ───────────────────────────────────────────────────────────\n\n /** The code as one string, from the first cell on. */\n @property({ type: String })\n value = '';\n\n /** Number of cells, the length of a complete code. */\n @property({ type: Number })\n length = 6;\n\n /** Which characters the cells take: `numeric` (digits) or `alphanumeric` (A–Z and digits). */\n @property({ type: String })\n type: PinInputType = 'numeric';\n\n /** Hides the characters like a password. */\n @property({ type: Boolean, reflect: true })\n masked = false;\n\n // ── Queries ──────────────────────────────────────────────────────────────\n\n @queryAll('.cell')\n private cells!: ArrayLike<HTMLInputElement> & Iterable<HTMLInputElement>;\n\n // ── Private fields ───────────────────────────────────────────────────────\n\n /** Peacock's strings for the cell names and the incomplete message. */\n private readonly i18n = new I18nController(this);\n\n /** The cell that takes Tab focus: the focused one, else the first empty one. */\n private activeIndex = 0;\n\n /** The value when it was last committed; `change` fires when it differs. */\n private committedValue = '';\n\n // ── Lifecycle ────────────────────────────────────────────────────────────\n\n override connectedCallback() {\n super.connectedCallback();\n this.committedValue = this.sanitize(this.value);\n }\n\n protected override willUpdate(changed: PropertyValues) {\n super.willUpdate(changed);\n if (changed.has('value') || changed.has('length') || changed.has('type')) {\n // Keep only the characters the cells take, so `value` is always what they show.\n this.value = this.sanitize(this.value);\n }\n }\n\n // ── Public methods ───────────────────────────────────────────────────────\n\n /** Focuses the first empty cell, or the last cell when the code is complete. */\n override focus(options?: Parameters<HTMLElement['focus']>[0]) {\n this.cells?.[this.firstEmptyIndex()]?.focus(options);\n }\n\n override blur() {\n for (const cell of Array.from(this.cells ?? [])) cell.blur();\n }\n\n /** Empties every cell. Like setting `value`, it fires no events and leaves focus alone. */\n clear() {\n this.value = '';\n this.committedValue = '';\n }\n\n // ── Protected methods ────────────────────────────────────────────────────\n\n protected override computeValidity(): ControlValidity {\n if (this.disabled) return { flags: {}, message: '' };\n const anchor = this.cells?.[this.firstEmptyIndex()];\n if (!this.value) {\n return this.required\n ? {\n flags: { valueMissing: true },\n message: this.valueMissingText(),\n anchor,\n }\n : { flags: {}, message: '' };\n }\n if (this.value.length < this.cellCount) {\n return {\n flags: { tooShort: true },\n message: this.i18n.t('pinInputIncomplete')(this.cellCount),\n anchor,\n };\n }\n return { flags: {}, message: '' };\n }\n\n protected override validityAnchor() {\n return this.cells?.[0];\n }\n\n protected override clearValue() {\n super.clearValue();\n this.committedValue = '';\n }\n\n override formResetCallback() {\n super.formResetCallback();\n this.committedValue = this.sanitize(this.value);\n }\n\n // ── Private methods ──────────────────────────────────────────────────────\n\n /** The number of cells: `length` as a whole number, at least 1. */\n private get cellCount(): number {\n const count = Math.floor(Number(this.length));\n return Number.isFinite(count) && count >= 1 ? count : 6;\n }\n\n private get editable(): boolean {\n return !this.disabled && !this.readonly;\n }\n\n /** Index of the first empty cell; the last cell when the code is complete. */\n private firstEmptyIndex(): number {\n return Math.min(this.value.length, this.cellCount - 1);\n }\n\n /** Keeps the characters the type takes (uppercased for alphanumeric), up to `length`. */\n private sanitize(text: unknown): string {\n const raw = text === undefined || text === null ? '' : String(text);\n const kept =\n this.type === 'alphanumeric'\n ? raw.replace(/[^0-9a-z]/gi, '').toUpperCase()\n : raw.replace(/\\D/g, '');\n return kept.slice(0, this.cellCount);\n }\n\n /** Writes `chars` into the cells from `index` on, then moves focus past them. */\n private fill(index: number, chars: string) {\n const before = this.value;\n const next = (\n before.slice(0, index) +\n chars +\n before.slice(index + chars.length)\n ).slice(0, this.cellCount);\n // Value first, so the cell focused next counts as reachable.\n this.setValueFromUser(next);\n this.focusCell(index + chars.length);\n }\n\n /** Removes the character at `index`; the ones after it move up one cell. */\n private removeAt(index: number) {\n if (index >= this.value.length) return;\n this.setValueFromUser(\n this.value.slice(0, index) + this.value.slice(index + 1),\n );\n }\n\n private setValueFromUser(next: string) {\n if (next === this.value) {\n // Put back a character the cell rejected.\n this.requestUpdate();\n return;\n }\n const wasComplete = this.value.length === this.cellCount;\n this.value = next;\n this.emitValue('input');\n if (!wasComplete && next.length === this.cellCount) {\n this.commit();\n this.dispatchEvent(\n new CustomEvent('complete', {\n detail: { value: next },\n bubbles: true,\n composed: true,\n }),\n );\n }\n }\n\n private commit() {\n if (this.value === this.committedValue) return;\n this.committedValue = this.value;\n this.emitValue('change');\n }\n\n private focusCell(index: number) {\n const target = Math.max(0, Math.min(index, this.firstEmptyIndex()));\n this.activeIndex = target;\n const cell = this.cells?.[target];\n cell?.focus();\n cell?.select();\n }\n\n private cellIndex(event: Event): number {\n return Number((event.target as HTMLElement).dataset.index ?? 0);\n }\n\n private handleKeydown(event: KeyboardEvent) {\n const index = this.cellIndex(event);\n const last = this.firstEmptyIndex();\n const { key } = event;\n if (key === 'ArrowLeft' || key === 'ArrowRight') {\n event.preventDefault();\n const step = key === 'ArrowLeft' ? -1 : 1;\n this.focusCell(Math.min(index + step, last));\n return;\n }\n if (key === 'Home' || key === 'End') {\n event.preventDefault();\n this.focusCell(key === 'Home' ? 0 : last);\n return;\n }\n if (!this.editable) return;\n if (key === 'Backspace') {\n event.preventDefault();\n if (index < this.value.length) {\n this.removeAt(index);\n } else if (index > 0) {\n this.focusCell(index - 1);\n this.removeAt(index - 1);\n }\n return;\n }\n if (key === 'Delete') {\n event.preventDefault();\n this.removeAt(index);\n return;\n }\n if (key.length === 1 && !event.ctrlKey && !event.metaKey && !event.altKey) {\n // A typed character: take it here so the cell always holds one; ignore ones the type rejects.\n event.preventDefault();\n const char = this.sanitize(key);\n if (char) this.fill(index, char);\n }\n }\n\n /** Text that reached a cell without a keydown: autofill, phone keyboards, input methods. */\n private handleInput(event: Event) {\n event.stopPropagation();\n const cell = event.target as HTMLInputElement;\n const index = this.cellIndex(event);\n if (!this.editable) return;\n const old = this.value[index] ?? '';\n if (cell.value === '') {\n this.removeAt(index);\n return;\n }\n let chars = this.sanitize(cell.value);\n // A character typed next to the one already there: keep the new one.\n if (old && chars.length === 2 && chars.includes(old)) {\n chars = chars[0] === old ? chars[1] : chars[0];\n }\n if (chars) this.fill(index, chars);\n else this.requestUpdate();\n }\n\n private handlePaste(event: ClipboardEvent) {\n event.preventDefault();\n if (!this.editable) return;\n const chars = this.sanitize(event.clipboardData?.getData('text') ?? '');\n if (chars) this.fill(this.cellIndex(event), chars);\n }\n\n private handleFocusIn(event: FocusEvent) {\n const index = this.cellIndex(event);\n const allowed = this.firstEmptyIndex();\n if (index > allowed) {\n // The code fills from the start: go to the first empty cell instead.\n this.focusCell(allowed);\n return;\n }\n this.activeIndex = index;\n (event.target as HTMLInputElement).select();\n this.focused = true;\n this.requestUpdate();\n }\n\n private handleFocusOut(event: FocusEvent) {\n const next = event.relatedTarget as Node | null;\n if (next && this.renderRoot.contains(next)) return;\n this.focused = false;\n this.activeIndex = this.firstEmptyIndex();\n this.commit();\n }\n\n private stopEvent(event: Event) {\n // Keep native events inside, and keep a click on a cell from refocusing the first empty one.\n event.stopPropagation();\n }\n\n // ── Render helpers ───────────────────────────────────────────────────────\n\n private renderCell(\n index: number,\n count: number,\n aria: Record<string, string | undefined>,\n ) {\n const name =\n this.type === 'alphanumeric'\n ? this.i18n.t('pinInputCharacter')(index + 1, count)\n : this.i18n.t('pinInputDigit')(index + 1, count);\n const tabIndex =\n index === (this.focused ? this.activeIndex : this.firstEmptyIndex())\n ? (aria.tabindex ?? '0')\n : '-1';\n return html`<input\n class=\"cell\"\n data-index=${index}\n type=${this.masked ? 'password' : 'text'}\n inputmode=${this.type === 'numeric' ? 'numeric' : 'text'}\n autocomplete=${index === 0 ? 'one-time-code' : 'off'}\n autocapitalize=${this.type === 'alphanumeric' ? 'characters' : 'off'}\n autocorrect=\"off\"\n spellcheck=\"false\"\n enterkeyhint=${index === count - 1 ? 'done' : 'next'}\n placeholder=${this.placeholder || nothing}\n tabindex=${tabIndex}\n aria-label=${name}\n aria-invalid=${aria['aria-invalid'] ?? nothing}\n aria-describedby=${aria['aria-describedby'] ?? nothing}\n aria-required=${this.required ? 'true' : nothing}\n .value=${live(this.value[index] ?? '')}\n ?readonly=${this.readonly}\n ?disabled=${this.disabled}\n @keydown=${this.handleKeydown}\n @input=${this.handleInput}\n @change=${this.stopEvent}\n @click=${this.stopEvent}\n @paste=${this.handlePaste}\n />`;\n }\n\n // ── Render ───────────────────────────────────────────────────────────────\n\n render() {\n const count = this.cellCount;\n const {\n tabindex,\n 'aria-invalid': invalid,\n 'aria-describedby': describedBy,\n ...groupAria\n } = this.fieldAria();\n const cellAria = {\n tabindex,\n 'aria-invalid': invalid,\n 'aria-describedby': describedBy,\n };\n return this.renderField(\n html`<div\n class=\"cells\"\n role=\"group\"\n dir=\"ltr\"\n @focusin=${this.handleFocusIn}\n @focusout=${this.handleFocusOut}\n ${spread(groupAria)}\n >\n ${Array.from({ length: count }, (_, index) =>\n this.renderCell(index, count, cellAria),\n )}\n </div>`,\n { populated: !!this.value, focused: this.focused },\n );\n }\n}\n"],"names":["html","nothing","live","styles","property","queryAll"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAgBA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA2CG;AAEI,IAAM,QAAQ,GAAd,MAAM,QAAS,SAAQ,SAAS,CAAA;AAAhC,IAAA,WAAA,GAAA;;;;;QAYL,IAAA,CAAA,KAAK,GAAG,EAAE;;QAIV,IAAA,CAAA,MAAM,GAAG,CAAC;;QAIV,IAAA,CAAA,IAAI,GAAiB,SAAS;;QAI9B,IAAA,CAAA,MAAM,GAAG,KAAK;;;AAUG,QAAA,IAAA,CAAA,IAAI,GAAG,IAAI,cAAc,CAAC,IAAI,CAAC;;QAGxC,IAAA,CAAA,WAAW,GAAG,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AE,MAAM,EAAE;AACK,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,MAAA,EAAA,MAAA,CAAA;AAI/B,UAAA,CAAA;IADCA,CAAQ,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE;AAC3B,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,QAAA,EAAA,MAAA,CAAA;AAKP,UAAA,CAAA;IADPC,CAAQ,CAAC,OAAO;AACwD,CAAA,EAAA,QAAA,CAAA,SAAA,EAAA,OAAA,EAAA,MAAA,CAAA;AA7B9D,QAAQ,GAAA,UAAA,CAAA;IADpB;AACY,CAAA,EAAA,QAAQ,CA6WpB;;;;"}
@@ -1,4 +1,4 @@
1
- import { p as parseIsoDate, f as formatDate, i as isWithin, a as parseRange, l as localeDatePattern } from './date-cfPx3alz.js';
1
+ import { p as parseIsoDate, f as formatDate, i as isWithin, a as parseRange, l as localeDatePattern } from './date-DPQOY8Zd.js';
2
2
 
3
3
  /** Formats a single ISO date for display, or '' when it is not a date. */
4
4
  function formatDateValue(value, locale) {
@@ -52,4 +52,4 @@ function validateDates(dates, limits, locale, i18n) {
52
52
  }
53
53
 
54
54
  export { formatRangeValue as a, formatDateValue as f, isCompleteRange as i, rangeFormatHint as r, validateDates as v };
55
- //# sourceMappingURL=range-utils-DZe96GnO.js.map
55
+ //# sourceMappingURL=range-utils-vgG1SJ2o.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"range-utils-DZe96GnO.js","sources":["../../src/date-field/range-utils.ts"],"sourcesContent":["// Parsing, formatting and validation shared by `wc-date-field` and `wc-date-range-field`.\nimport type { I18nController } from '@/__internal/i18n/i18n-controller.js';\nimport type { ValueProblem } from '@/__internal/picker-field.js';\nimport {\n formatDate,\n isWithin,\n localeDatePattern,\n parseIsoDate,\n parseRange,\n} from '@/__internal/utils/date.js';\n\n/** The limits a picked or typed date is checked against. */\nexport interface DateLimits {\n /** Earliest allowed date (`YYYY-MM-DD`); empty for none. */\n min?: string;\n /** Latest allowed date (`YYYY-MM-DD`); empty for none. */\n max?: string;\n /** Returns true for dates that cannot be picked. */\n isDateDisabled?: (iso: string) => boolean;\n}\n\n/** Formats a single ISO date for display, or '' when it is not a date. */\nexport function formatDateValue(value: string, locale: string): string {\n return parseIsoDate(value) ? formatDate(value, locale) : '';\n}\n\n/** Formats a `start/end` range for display: `11/03/2026 – 11/09/2026`, or just the start. */\nexport function formatRangeValue(value: string, locale: string): string {\n const [start, end] = parseRange(value);\n if (!start) return '';\n return `${formatDate(start, locale)} – ${end ? formatDate(end, locale) : ''}`.trim();\n}\n\n/** The format hint for a range, such as `MM/DD/YYYY – MM/DD/YYYY`. */\nexport function rangeFormatHint(locale: string): string {\n const pattern = localeDatePattern(locale);\n return `${pattern} – ${pattern}`;\n}\n\n/** Whether a `start/end` value has both dates. */\nexport function isCompleteRange(value: string): boolean {\n const [start, end] = parseRange(value);\n return !!start && !!end;\n}\n\n/**\n * Checks each date against the limits and returns the first problem: before `min`, after `max`, or\n * a disabled date. Returns null when every date is allowed.\n */\nexport function validateDates(\n dates: readonly string[],\n limits: DateLimits,\n locale: string,\n i18n: Pick<I18nController, 't'>,\n): ValueProblem | null {\n const min = limits.min || undefined;\n const max = limits.max || undefined;\n for (const date of dates) {\n if (min && date < min) {\n return {\n flag: 'rangeUnderflow',\n message: i18n.t('pickDateOnOrAfter')(formatDate(min, locale)),\n };\n }\n if (max && date > max) {\n return {\n flag: 'rangeOverflow',\n message: i18n.t('pickDateOnOrBefore')(formatDate(max, locale)),\n };\n }\n if (isWithin(date, min, max) && limits.isDateDisabled?.(date)) {\n return {\n flag: 'badInput',\n message: i18n.t('dateUnavailable')(formatDate(date, locale)),\n };\n }\n }\n return null;\n}\n"],"names":[],"mappings":";;AAqBA;AACM,SAAU,eAAe,CAAC,KAAa,EAAE,MAAc,EAAA;AAC3D,IAAA,OAAO,YAAY,CAAC,KAAK,CAAC,GAAG,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,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IAAI,GAAG,GAAG,EAAE;YACrB,OAAO;AACL,gBAAA,IAAI,EAAE,eAAe;AACrB,gBAAA,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,CAAC;aAC/D;QACH;AACA,QAAA,IAAI,QAAQ,CAAC,IAAI,EAAE,GAAG,EAAE,GAAG,CAAC,IAAI,MAAM,CAAC,cAAc,GAAG,IAAI,CAAC,EAAE;YAC7D,OAAO;AACL,gBAAA,IAAI,EAAE,UAAU;AAChB,gBAAA,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;aAC7D;QACH;IACF;AACA,IAAA,OAAO,IAAI;AACb;;;;"}
1
+ {"version":3,"file":"range-utils-vgG1SJ2o.js","sources":["../../src/date-field/range-utils.ts"],"sourcesContent":["// Parsing, formatting and validation shared by `wc-date-field` and `wc-date-range-field`.\nimport type { I18nController } from '@/__internal/i18n/i18n-controller.js';\nimport type { ValueProblem } from '@/__internal/picker-field.js';\nimport {\n formatDate,\n isWithin,\n localeDatePattern,\n parseIsoDate,\n parseRange,\n} from '@/__internal/utils/date.js';\n\n/** The limits a picked or typed date is checked against. */\nexport interface DateLimits {\n /** Earliest allowed date (`YYYY-MM-DD`); empty for none. */\n min?: string;\n /** Latest allowed date (`YYYY-MM-DD`); empty for none. */\n max?: string;\n /** Returns true for dates that cannot be picked. */\n isDateDisabled?: (iso: string) => boolean;\n}\n\n/** Formats a single ISO date for display, or '' when it is not a date. */\nexport function formatDateValue(value: string, locale: string): string {\n return parseIsoDate(value) ? formatDate(value, locale) : '';\n}\n\n/** Formats a `start/end` range for display: `11/03/2026 – 11/09/2026`, or just the start. */\nexport function formatRangeValue(value: string, locale: string): string {\n const [start, end] = parseRange(value);\n if (!start) return '';\n return `${formatDate(start, locale)} – ${end ? formatDate(end, locale) : ''}`.trim();\n}\n\n/** The format hint for a range, such as `MM/DD/YYYY – MM/DD/YYYY`. */\nexport function rangeFormatHint(locale: string): string {\n const pattern = localeDatePattern(locale);\n return `${pattern} – ${pattern}`;\n}\n\n/** Whether a `start/end` value has both dates. */\nexport function isCompleteRange(value: string): boolean {\n const [start, end] = parseRange(value);\n return !!start && !!end;\n}\n\n/**\n * Checks each date against the limits and returns the first problem: before `min`, after `max`, or\n * a disabled date. Returns null when every date is allowed.\n */\nexport function validateDates(\n dates: readonly string[],\n limits: DateLimits,\n locale: string,\n i18n: Pick<I18nController, 't'>,\n): ValueProblem | null {\n const min = limits.min || undefined;\n const max = limits.max || undefined;\n for (const date of dates) {\n if (min && date < min) {\n return {\n flag: 'rangeUnderflow',\n message: i18n.t('pickDateOnOrAfter')(formatDate(min, locale)),\n };\n }\n if (max && date > max) {\n return {\n flag: 'rangeOverflow',\n message: i18n.t('pickDateOnOrBefore')(formatDate(max, locale)),\n };\n }\n if (isWithin(date, min, max) && limits.isDateDisabled?.(date)) {\n return {\n flag: 'badInput',\n message: i18n.t('dateUnavailable')(formatDate(date, locale)),\n };\n }\n }\n return null;\n}\n"],"names":[],"mappings":";;AAqBA;AACM,SAAU,eAAe,CAAC,KAAa,EAAE,MAAc,EAAA;AAC3D,IAAA,OAAO,YAAY,CAAC,KAAK,CAAC,GAAG,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,GAAG,EAAE;AAC7D;AAEA;AACM,SAAU,gBAAgB,CAAC,KAAa,EAAE,MAAc,EAAA;IAC5D,MAAM,CAAC,KAAK,EAAE,GAAG,CAAC,GAAG,UAAU,CAAC,KAAK,CAAC;AACtC,IAAA,IAAI,CAAC,KAAK;AAAE,QAAA,OAAO,EAAE;IACrB,OAAO,CAAA,EAAG,UAAU,CAAC,KAAK,EAAE,MAAM,CAAC,CAAA,GAAA,EAAM,GAAG,GAAG,UAAU,CAAC,GAAG,EAAE,MAAM,CAAC,GAAG,EAAE,CAAA,CAAE,CAAC,IAAI,EAAE;AACtF;A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,IAAI,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;aAC7D;QACH;IACF;AACA,IAAA,OAAO,IAAI;AACb;;;;"}
@@ -62,15 +62,24 @@ class RovingFocusController {
62
62
  get activeItem() {
63
63
  return this.active;
64
64
  }
65
- /** Re-applies the tab stops; call after the items change. */
65
+ /**
66
+ * Re-applies the tab stops; call after the items change, including when one becomes disabled
67
+ * or hidden. An item that can no longer take focus hands the tab stop to the focusable item
68
+ * after it (else the one before it), unless `initialItem` picks another.
69
+ */
66
70
  sync() {
67
- const items = this.focusableItems();
71
+ const all = this.options.items();
72
+ const items = this.focusableItems(all);
68
73
  if (!this.active || !items.includes(this.active)) {
69
- this.active = this.options.initialItem?.(items) ?? items[0] ?? null;
74
+ this.active =
75
+ this.options.initialItem?.(items) ??
76
+ this.nearestFocusable(all, items) ??
77
+ items[0] ??
78
+ null;
70
79
  }
71
80
  if (!(this.options.manageTabIndex?.() ?? true))
72
81
  return;
73
- for (const item of this.options.items()) {
82
+ for (const item of all) {
74
83
  const stop = item === this.active;
75
84
  if (item.tabIndex !== (stop ? 0 : -1))
76
85
  item.tabIndex = stop ? 0 : -1;
@@ -84,9 +93,23 @@ class RovingFocusController {
84
93
  item.focus();
85
94
  }
86
95
  // ── Private ──────────────────────────────────────────────────────────────
87
- focusableItems() {
96
+ focusableItems(all = this.options.items()) {
88
97
  const focusable = this.options.isFocusable ?? defaultFocusable;
89
- return this.options.items().filter(item => focusable(item));
98
+ return all.filter(item => focusable(item));
99
+ }
100
+ /**
101
+ * For an active item that is still in the set but can no longer take focus: the first focusable
102
+ * item after it, else the nearest one before it.
103
+ */
104
+ nearestFocusable(all, focusable) {
105
+ const index = this.active ? all.indexOf(this.active) : -1;
106
+ if (index < 0)
107
+ return undefined;
108
+ return (all.slice(index + 1).find(item => focusable.includes(item)) ??
109
+ all
110
+ .slice(0, index)
111
+ .reverse()
112
+ .find(item => focusable.includes(item)));
90
113
  }
91
114
  itemFromEvent(event) {
92
115
  const items = this.options.items();
@@ -154,4 +177,4 @@ class RovingFocusController {
154
177
  }
155
178
 
156
179
  export { RovingFocusController as R };
157
- //# sourceMappingURL=roving-focus-controller-fm95JkZJ.js.map
180
+ //# sourceMappingURL=roving-focus-controller-YtNbxH95.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"roving-focus-controller-YtNbxH95.js","sources":["../../src/__internal/controllers/roving-focus-controller.ts"],"sourcesContent":["import type { ReactiveController, ReactiveControllerHost } from 'lit';\n\nexport interface RovingFocusOptions {\n /**\n * The items, in order. Disabled or hidden ones are skipped automatically; include them, so that\n * when the item holding the tab stop becomes disabled the next item takes the stop over.\n */\n items: () => HTMLElement[];\n /** `horizontal` uses Left/Right (mirrored in right-to-left), `vertical` Up/Down, `both` all four. */\n orientation?: () => 'horizontal' | 'vertical' | 'both';\n /** Whether moving past the last item goes to the first. Default true. */\n wrap?: () => boolean;\n /** Whether typing a character moves to the next item whose text starts with it. Default false. */\n typeahead?: () => boolean;\n /** The text typeahead matches for an item. Default: its `textContent`. */\n itemText?: (item: HTMLElement) => string;\n /** The item that should hold the tab stop when none has it yet (default: the first). */\n initialItem?: (items: HTMLElement[]) => HTMLElement | null | undefined;\n /** Called after focus moved to `item` by keyboard, for components that select on focus (tabs). */\n onMove?: (item: HTMLElement, event: KeyboardEvent) => void;\n /** Whether an item can take focus; default: not `disabled`, not `aria-disabled=\"true\"`, not hidden. */\n isFocusable?: (item: HTMLElement) => boolean;\n /**\n * Whether to manage `tabindex` (one tab stop for the set). Default true. Set it to false when\n * every item stays in the Tab order and the arrow keys are only a shortcut, as for accordion\n * headers in the WAI-ARIA pattern.\n */\n manageTabIndex?: () => boolean;\n}\n\nconst TYPEAHEAD_RESET_MS = 500;\n\nfunction defaultFocusable(item: HTMLElement) {\n return (\n !item.hidden &&\n !item.hasAttribute('disabled') &&\n item.getAttribute('aria-disabled') !== 'true'\n );\n}\n\n/**\n * Roving tabindex for a set of items (toolbar actions, tabs, list items, accordion headers):\n * one item is the tab stop (`tabindex=\"0\"`), the others `-1`; arrow keys, Home and End move focus\n * between them, mirroring Left/Right in right-to-left layouts.\n *\n * The host attaches `handleKeyDown` and `handleFocusIn` to the element that contains the items\n * (or its host), and calls `sync()` when the items change (on `slotchange` and after updates).\n *\n * @example\n * private readonly roving = new RovingFocusController(this, {\n * items: () => this.slottedTabs(),\n * orientation: () => 'horizontal',\n * });\n * // render: <div role=\"tablist\" @keydown=${this.roving.handleKeyDown}\n * // @focusin=${this.roving.handleFocusIn}><slot @slotchange=${() => this.roving.sync()}>\n */\nexport class RovingFocusController implements ReactiveController {\n private readonly host: ReactiveControllerHost & HTMLElement;\n\n private readonly options: RovingFocusOptions;\n\n private active: HTMLElement | null = null;\n\n private typed = '';\n\n private typedAt = 0;\n\n constructor(\n host: ReactiveControllerHost & HTMLElement,\n options: RovingFocusOptions,\n ) {\n this.host = host;\n this.options = options;\n host.addController(this);\n }\n\n hostUpdated() {\n this.sync();\n }\n\n /** The item that holds the tab stop. */\n get activeItem(): HTMLElement | null {\n return this.active;\n }\n\n /**\n * Re-applies the tab stops; call after the items change, including when one becomes disabled\n * or hidden. An item that can no longer take focus hands the tab stop to the focusable item\n * after it (else the one before it), unless `initialItem` picks another.\n */\n sync() {\n const all = this.options.items();\n const items = this.focusableItems(all);\n if (!this.active || !items.includes(this.active)) {\n this.active =\n this.options.initialItem?.(items) ??\n this.nearestFocusable(all, items) ??\n items[0] ??\n null;\n }\n if (!(this.options.manageTabIndex?.() ?? true)) return;\n for (const item of all) {\n const stop = item === this.active;\n if (item.tabIndex !== (stop ? 0 : -1)) item.tabIndex = stop ? 0 : -1;\n }\n }\n\n /** Makes `item` the tab stop, and focuses it unless `focus` is false. */\n setActive(item: HTMLElement, focus = true) {\n this.active = item;\n this.sync();\n if (focus) item.focus();\n }\n\n /** Keeps the tab stop on the item that got focus by click or Tab. */\n handleFocusIn = (event: FocusEvent) => {\n const item = this.itemFromEvent(event);\n if (item && item !== this.active) {\n this.active = item;\n this.sync();\n }\n };\n\n handleKeyDown = (event: KeyboardEvent) => {\n if (\n event.defaultPrevented ||\n event.altKey ||\n event.ctrlKey ||\n event.metaKey\n ) {\n return;\n }\n const items = this.focusableItems();\n const current = this.itemFromEvent(event);\n if (items.length === 0 || !current) return;\n\n const target = this.targetFor(event, items, current);\n if (!target) return;\n event.preventDefault();\n this.setActive(target);\n this.options.onMove?.(target, event);\n };\n\n // ── Private ──────────────────────────────────────────────────────────────\n\n private focusableItems(all = this.options.items()) {\n const focusable = this.options.isFocusable ?? defaultFocusable;\n return all.filter(item => focusable(item));\n }\n\n /**\n * For an active item that is still in the set but can no longer take focus: the first focusable\n * item after it, else the nearest one before it.\n */\n private nearestFocusable(all: HTMLElement[], focusable: HTMLElement[]) {\n const index = this.active ? all.indexOf(this.active) : -1;\n if (index < 0) return undefined;\n return (\n all.slice(index + 1).find(item => focusable.includes(item)) ??\n all\n .slice(0, index)\n .reverse()\n .find(item => focusable.includes(item))\n );\n }\n\n private itemFromEvent(event: Event): HTMLElement | null {\n const items = this.options.items();\n return (\n (event\n .composedPath()\n .find(node => items.includes(node as HTMLElement)) as\n | HTMLElement\n | undefined) ?? null\n );\n }\n\n private targetFor(\n event: KeyboardEvent,\n items: HTMLElement[],\n current: HTMLElement,\n ): HTMLElement | undefined {\n const orientation = this.options.orientation?.() ?? 'horizontal';\n const rtl = getComputedStyle(this.host).direction === 'rtl';\n const wrap = this.options.wrap?.() ?? true;\n const index = Math.max(0, items.indexOf(current));\n\n const next: string[] = [];\n const previous: string[] = [];\n if (orientation !== 'vertical') {\n next.push(rtl ? 'ArrowLeft' : 'ArrowRight');\n previous.push(rtl ? 'ArrowRight' : 'ArrowLeft');\n }\n if (orientation !== 'horizontal') {\n next.push('ArrowDown');\n previous.push('ArrowUp');\n }\n\n const step = (delta: number) => {\n const to = index + delta;\n if (wrap) return items[(to + items.length) % items.length];\n return items[Math.min(items.length - 1, Math.max(0, to))];\n };\n\n if (next.includes(event.key)) return step(1);\n if (previous.includes(event.key)) return step(-1);\n if (event.key === 'Home') return items[0];\n if (event.key === 'End') return items[items.length - 1];\n\n if (\n this.options.typeahead?.() &&\n event.key.length === 1 &&\n event.key !== ' '\n ) {\n return this.typeaheadTarget(event.key, items, index);\n }\n return undefined;\n }\n\n /** The next item whose text starts with the typed characters (a 500 ms buffer, like native). */\n private typeaheadTarget(key: string, items: HTMLElement[], index: number) {\n const now = Date.now();\n this.typed =\n now - this.typedAt > TYPEAHEAD_RESET_MS ? key : this.typed + key;\n this.typedAt = now;\n // The same letter typed again (\"bb\") cycles through the items starting with it, like a\n // native select; other buffers match as a prefix.\n const typed = this.typed.toLowerCase();\n const repeated = [...typed].every(char => char === typed[0]);\n const query = repeated ? typed[0] : typed;\n const start = query.length === 1 ? index + 1 : index;\n for (let offset = 0; offset < items.length; offset += 1) {\n const item = items[(start + offset) % items.length];\n const text = this.options.itemText?.(item) ?? item.textContent ?? '';\n if (text.trim().toLowerCase().startsWith(query)) {\n return item;\n }\n }\n return undefined;\n }\n}\n"],"names":[],"mappings":"AA8BA,MAAM,kBAAkB,GAAG,GAAG;AAE9B,SAAS,gBAAgB,CAAC,IAAiB,EAAA;AACzC,IAAA,QACE,CAAC,IAAI,CAAC,MAAM;AACZ,QAAA,CAAC,IAAI,CAAC,YAAY,CAAC,UAAU,CAAC;QAC9B,IAAI,CAAC,YAAY,CAAC,eAAe,CAAC,KAAK,MAAM;AAEjD;AAEA;;;;;;;;;;;;;;;AAeG;MACU,qBAAqB,CAAA;IAWhC,WAAA,CACE,IAA0C,EAC1C,OAA2B,EAAA;QARrB,IAAA,CAAA,MAAM,GAAuB,IAAI;QAEjC,IAAA,CAAA,KAAK,GAAG,EAAE;QAEV,IAAA,CAAA,OAAO,GAAG,CAAC;;AAkDnB,QAAA,IAAA,CAAA,aAAa,GAAG,CAAC,KAAiB,KAAI;YACpC,MAAM,IAAI,GAAG,IAAI,CAAC,aAAa,CAAC,KAAK,CAA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