@panneau/fields 5.0.0-alpha.14 → 5.0.0-alpha.16

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 (139) hide show
  1. package/README.md +53 -3
  2. package/dist/address/AddressField.css +44 -0
  3. package/dist/address/AddressField.d.ts +37 -0
  4. package/dist/address/AddressField.d.ts.map +1 -0
  5. package/dist/address/AddressField.js +411 -0
  6. package/dist/address/AddressField.js.map +1 -0
  7. package/dist/address/AddressField.module.js +22 -0
  8. package/dist/address/AddressField.module.js.map +1 -0
  9. package/dist/address/address.d.ts +23 -0
  10. package/dist/address/address.d.ts.map +1 -0
  11. package/dist/address/address.js +58 -0
  12. package/dist/address/address.js.map +1 -0
  13. package/dist/address/index.d.ts +3 -0
  14. package/dist/address/index.d.ts.map +1 -0
  15. package/dist/address/index.js +3 -0
  16. package/dist/color/ColorField.css +9 -0
  17. package/dist/color/ColorField.d.ts +10 -3
  18. package/dist/color/ColorField.d.ts.map +1 -1
  19. package/dist/color/ColorField.js +341 -81
  20. package/dist/color/ColorField.js.map +1 -1
  21. package/dist/color/ColorField.module.js +4 -2
  22. package/dist/color/ColorField.module.js.map +1 -1
  23. package/dist/color/index.d.ts +1 -0
  24. package/dist/color/index.d.ts.map +1 -1
  25. package/dist/color/index.js +3 -1
  26. package/dist/color/palette.d.ts +23 -0
  27. package/dist/color/palette.d.ts.map +1 -0
  28. package/dist/color/palette.js +34 -0
  29. package/dist/color/palette.js.map +1 -0
  30. package/dist/country/CountryField.css +42 -0
  31. package/dist/country/CountryField.d.ts +19 -4
  32. package/dist/country/CountryField.d.ts.map +1 -1
  33. package/dist/country/CountryField.js +355 -82
  34. package/dist/country/CountryField.js.map +1 -1
  35. package/dist/country/CountryField.module.js +20 -0
  36. package/dist/country/CountryField.module.js.map +1 -0
  37. package/dist/country/index.d.ts +1 -1
  38. package/dist/country/index.d.ts.map +1 -1
  39. package/dist/daterange/DateRangeField.css +9 -0
  40. package/dist/daterange/DateRangeField.d.ts +31 -0
  41. package/dist/daterange/DateRangeField.d.ts.map +1 -0
  42. package/dist/daterange/DateRangeField.js +372 -0
  43. package/dist/daterange/DateRangeField.js.map +1 -0
  44. package/dist/daterange/DateRangeField.module.js +12 -0
  45. package/dist/daterange/DateRangeField.module.js.map +1 -0
  46. package/dist/daterange/index.d.ts +3 -0
  47. package/dist/daterange/index.d.ts.map +1 -0
  48. package/dist/daterange/index.js +3 -0
  49. package/dist/daterange/range.d.ts +61 -0
  50. package/dist/daterange/range.d.ts.map +1 -0
  51. package/dist/daterange/range.js +119 -0
  52. package/dist/daterange/range.js.map +1 -0
  53. package/dist/duration/DurationField.css +1 -1
  54. package/dist/duration/DurationField.d.ts +54 -13
  55. package/dist/duration/DurationField.d.ts.map +1 -1
  56. package/dist/duration/DurationField.js +205 -159
  57. package/dist/duration/DurationField.js.map +1 -1
  58. package/dist/duration/DurationField.module.js.map +1 -1
  59. package/dist/duration/index.d.ts +1 -1
  60. package/dist/duration/index.d.ts.map +1 -1
  61. package/dist/duration/index.js +1 -1
  62. package/dist/embed/EmbedField.d.ts +11 -2
  63. package/dist/embed/EmbedField.d.ts.map +1 -1
  64. package/dist/embed/EmbedField.js +179 -116
  65. package/dist/embed/EmbedField.js.map +1 -1
  66. package/dist/link/LinkField.css +12 -0
  67. package/dist/link/LinkField.d.ts +38 -0
  68. package/dist/link/LinkField.d.ts.map +1 -0
  69. package/dist/link/LinkField.js +742 -0
  70. package/dist/link/LinkField.js.map +1 -0
  71. package/dist/link/LinkField.module.js +8 -0
  72. package/dist/link/LinkField.module.js.map +1 -0
  73. package/dist/link/index.d.ts +3 -0
  74. package/dist/link/index.d.ts.map +1 -0
  75. package/dist/link/index.js +3 -0
  76. package/dist/link/link.d.ts +30 -0
  77. package/dist/link/link.d.ts.map +1 -0
  78. package/dist/link/link.js +63 -0
  79. package/dist/link/link.js.map +1 -0
  80. package/dist/link/pages.d.ts +17 -0
  81. package/dist/link/pages.d.ts.map +1 -0
  82. package/dist/link/pages.js +104 -0
  83. package/dist/link/pages.js.map +1 -0
  84. package/dist/location/LocationField.d.ts.map +1 -1
  85. package/dist/location/LocationField.js +9 -85
  86. package/dist/location/LocationField.js.map +1 -1
  87. package/dist/location/nominatim.d.ts +8 -2
  88. package/dist/location/nominatim.d.ts.map +1 -1
  89. package/dist/location/nominatim.js +32 -3
  90. package/dist/location/nominatim.js.map +1 -1
  91. package/dist/location/search.d.ts +10 -0
  92. package/dist/location/search.d.ts.map +1 -0
  93. package/dist/location/search.js +83 -0
  94. package/dist/location/search.js.map +1 -0
  95. package/dist/location/types.d.ts +8 -2
  96. package/dist/location/types.d.ts.map +1 -1
  97. package/dist/money/MoneyField.d.ts +28 -0
  98. package/dist/money/MoneyField.d.ts.map +1 -0
  99. package/dist/money/MoneyField.js +269 -0
  100. package/dist/money/MoneyField.js.map +1 -0
  101. package/dist/money/index.d.ts +3 -0
  102. package/dist/money/index.d.ts.map +1 -0
  103. package/dist/money/index.js +3 -0
  104. package/dist/money/money.d.ts +27 -0
  105. package/dist/money/money.d.ts.map +1 -0
  106. package/dist/money/money.js +56 -0
  107. package/dist/money/money.js.map +1 -0
  108. package/dist/region/RegionField.js +1 -1
  109. package/dist/shared/builtIn.d.ts +3 -1
  110. package/dist/shared/builtIn.d.ts.map +1 -1
  111. package/dist/shared/builtIn.js +18 -8
  112. package/dist/shared/builtIn.js.map +1 -1
  113. package/dist/shared/dates.js +2 -2
  114. package/dist/shared/dates.js.map +1 -1
  115. package/dist/shared/flow.d.ts.map +1 -1
  116. package/dist/shared/flow.js +1 -0
  117. package/dist/shared/flow.js.map +1 -1
  118. package/dist/shared/part.d.ts +26 -0
  119. package/dist/shared/part.d.ts.map +1 -0
  120. package/dist/shared/part.js +64 -0
  121. package/dist/shared/part.js.map +1 -0
  122. package/dist/tel/TelField.css +25 -0
  123. package/dist/tel/TelField.d.ts +14 -2
  124. package/dist/tel/TelField.d.ts.map +1 -1
  125. package/dist/tel/TelField.js +246 -145
  126. package/dist/tel/TelField.js.map +1 -1
  127. package/dist/tel/TelField.module.js +12 -0
  128. package/dist/tel/TelField.module.js.map +1 -0
  129. package/dist/tel/index.d.ts +1 -1
  130. package/dist/tel/index.d.ts.map +1 -1
  131. package/dist/tel/index.js +2 -2
  132. package/dist/tel/phone.d.ts +28 -0
  133. package/dist/tel/phone.d.ts.map +1 -1
  134. package/dist/tel/phone.js +48 -1
  135. package/dist/tel/phone.js.map +1 -1
  136. package/dist/url/UrlField.d.ts.map +1 -1
  137. package/dist/url/UrlField.js +1 -1
  138. package/dist/url/UrlField.js.map +1 -1
  139. package/package.json +24 -4
@@ -0,0 +1,64 @@
1
+ import { getParentPath, useFieldsContext } from "./context.js";
2
+ import { c } from "react/compiler-runtime";
3
+ import { jsx } from "react/jsx-runtime";
4
+ //#region src/shared/part.tsx
5
+ /**
6
+ * A part of a value that a field edits itself (the postal code of an address, the URL of a link):
7
+ * the field keeps its whole value, and the binding of the fields context gives each part the
8
+ * errors of its own path, and marks it touched when it loses focus. Without a binding, the part
9
+ * gets `errors` and `onBlur`.
10
+ */
11
+ function BoundPart(t0) {
12
+ const $ = c(14);
13
+ const { field, path, errors, onBlur, render } = t0;
14
+ const { binding: Binding } = useFieldsContext();
15
+ if (Binding === null) {
16
+ let t1;
17
+ if ($[0] !== errors || $[1] !== onBlur || $[2] !== render) {
18
+ t1 = render({
19
+ ...errors !== void 0 ? { errors } : {},
20
+ ...onBlur !== void 0 ? { onBlur } : {}
21
+ });
22
+ $[0] = errors;
23
+ $[1] = onBlur;
24
+ $[2] = render;
25
+ $[3] = t1;
26
+ } else t1 = $[3];
27
+ return t1;
28
+ }
29
+ let t1;
30
+ if ($[4] !== path) {
31
+ t1 = getParentPath(path);
32
+ $[4] = path;
33
+ $[5] = t1;
34
+ } else t1 = $[5];
35
+ let t2;
36
+ if ($[6] !== render) {
37
+ t2 = (bound) => render({
38
+ ...bound.errors !== void 0 ? { errors: bound.errors } : {},
39
+ ...bound.onBlur !== void 0 ? { onBlur: bound.onBlur } : {}
40
+ });
41
+ $[6] = render;
42
+ $[7] = t2;
43
+ } else t2 = $[7];
44
+ let t3;
45
+ if ($[8] !== Binding || $[9] !== field || $[10] !== path || $[11] !== t1 || $[12] !== t2) {
46
+ t3 = /* @__PURE__ */ jsx(Binding, {
47
+ field,
48
+ path,
49
+ parentPath: t1,
50
+ render: t2
51
+ });
52
+ $[8] = Binding;
53
+ $[9] = field;
54
+ $[10] = path;
55
+ $[11] = t1;
56
+ $[12] = t2;
57
+ $[13] = t3;
58
+ } else t3 = $[13];
59
+ return t3;
60
+ }
61
+ //#endregion
62
+ export { BoundPart };
63
+
64
+ //# sourceMappingURL=part.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"part.js","names":["ReactNode","Field","getParentPath","useFieldsContext","BoundPartProps","errors","onBlur","PartBindingProps","field","path","render","bound","BoundPart","t0","$","_c","binding","Binding","t1","undefined","t2","t3","_c"],"sources":["../../src/shared/part.tsx"],"sourcesContent":["import type { ReactNode } from 'react';\n\nimport type { Field } from '@panneau/protocol';\n\nimport { getParentPath, useFieldsContext } from './context';\n\n/** What a part of a value gets from the binding of the fields context: its errors and its blur. */\nexport interface BoundPartProps {\n errors?: readonly string[];\n onBlur?: () => void;\n}\n\nexport interface PartBindingProps {\n /** The part, as a field of the definition: the binding reads its errors by its path. */\n field: Field;\n /** Dot path of the part (`address.postalCode`). */\n path: string;\n /** Errors of the part without a binding. */\n errors?: readonly string[];\n /** Blur of the part without a binding. */\n onBlur?: () => void;\n render: (bound: BoundPartProps) => ReactNode;\n}\n\n/**\n * A part of a value that a field edits itself (the postal code of an address, the URL of a link):\n * the field keeps its whole value, and the binding of the fields context gives each part the\n * errors of its own path, and marks it touched when it loses focus. Without a binding, the part\n * gets `errors` and `onBlur`.\n */\nexport function BoundPart({ field, path, errors, onBlur, render }: PartBindingProps) {\n const { binding: Binding } = useFieldsContext();\n if (Binding === null) {\n return render({\n ...(errors !== undefined ? { errors } : {}),\n ...(onBlur !== undefined ? { onBlur } : {}),\n });\n }\n return (\n <Binding\n field={field}\n path={path}\n parentPath={getParentPath(path)}\n render={(bound) =>\n render({\n ...(bound.errors !== undefined ? { errors: bound.errors } : {}),\n ...(bound.onBlur !== undefined ? { onBlur: bound.onBlur } : {}),\n })\n }\n />\n );\n}\n"],"mappings":";;;;;;;;;;AA8BA,SAAOY,UAAAC,IAAA;CAAA,MAAAC,IAAAC,EAAA,EAAA;CAAmB,MAAA,EAAAP,OAAAC,MAAAJ,QAAAC,QAAAI,WAAAG;CACtB,MAAA,EAAAG,SAAAC,YAA6Bd,iBAAiB;CAC9C,IAAIc,YAAY,MAAI;EAAA,IAAAC;EAAA,IAAAJ,EAAA,OAAAT,UAAAS,EAAA,OAAAR,UAAAQ,EAAA,OAAAJ,QAAA;GACTQ,KAAAR,OAAO;IAAA,GACNL,WAAWc,KAAAA,IAAX,EAAAd,OAAqC,IAArC,CAAqC;IAAC,GACtCC,WAAWa,KAAAA,IAAX,EAAAb,OAAqC,IAArC,CAAqC;GAC7C,CAAC;GAACQ,EAAA,KAAAT;GAAAS,EAAA,KAAAR;GAAAQ,EAAA,KAAAJ;GAAAI,EAAA,KAAAI;EAAA,OAAAA,KAAAJ,EAAA;EAAA,OAHKI;CAGL;CACL,IAAAA;CAAA,IAAAJ,EAAA,OAAAL,MAAA;EAKmBS,KAAAhB,cAAcO,IAAI;EAACK,EAAA,KAAAL;EAAAK,EAAA,KAAAI;CAAA,OAAAA,KAAAJ,EAAA;CAAA,IAAAM;CAAA,IAAAN,EAAA,OAAAJ,QAAA;EACvBU,MAAAT,UACJD,OAAO;GAAA,GACCC,MAAKN,WAAYc,KAAAA,IAAjB,EAAAd,QAAuCM,MAAKN,OAAa,IAAzD,CAAyD;GAAC,GAC1DM,MAAKL,WAAYa,KAAAA,IAAjB,EAAAb,QAAuCK,MAAKL,OAAa,IAAzD,CAAyD;EACjE,CAAC;EAACQ,EAAA,KAAAJ;EAAAI,EAAA,KAAAM;CAAA,OAAAA,KAAAN,EAAA;CAAA,IAAAO;CAAA,IAAAP,EAAA,OAAAG,WAAAH,EAAA,OAAAN,SAAAM,EAAA,QAAAL,QAAAK,EAAA,QAAAI,MAAAJ,EAAA,QAAAM,IAAA;EARVC,KAAA,oBAAC,SAAD;GACWb;GACDC;GACM,YAAAS;GACJ,QAAAE;EAIF,CAAA;EAERN,EAAA,KAAAG;EAAAH,EAAA,KAAAN;EAAAM,EAAA,MAAAL;EAAAK,EAAA,MAAAI;EAAAJ,EAAA,MAAAM;EAAAN,EAAA,MAAAO;CAAA,OAAAA,KAAAP,EAAA;CAAA,OAVFO;AAUE"}
@@ -0,0 +1,25 @@
1
+ /* The extension, after the number, in the same box. */
2
+ .panneau-tel-field-extension {
3
+ display: inline-flex;
4
+ align-items: center;
5
+ gap: var(--panneau-space-1);
6
+ align-self: stretch;
7
+ padding-inline-start: var(--panneau-space-2);
8
+ border-inline-start: var(--panneau-border-width) solid var(--panneau-color-border-control);
9
+ }
10
+
11
+ .panneau-tel-field-extension-input {
12
+ width: 6ch;
13
+ min-width: 0;
14
+ padding: 0;
15
+ font: inherit;
16
+ color: var(--panneau-color-text);
17
+ background: transparent;
18
+ border: 0;
19
+ outline: none;
20
+ }
21
+
22
+ .panneau-tel-field-extension-input:read-only,
23
+ .panneau-tel-field-extension-input:disabled {
24
+ cursor: inherit;
25
+ }
@@ -6,6 +6,11 @@ export interface TelFieldProps extends Omit<TextFieldProps, 'type' | 'inputMode'
6
6
  * gives `CA`).
7
7
  */
8
8
  country?: string | null;
9
+ /**
10
+ * Adds an input for the extension, after the number. The value is then the number with its
11
+ * extension after `;ext=`, as in a `tel:` URI: `+15145550199;ext=123`.
12
+ */
13
+ extension?: boolean;
9
14
  }
10
15
  /**
11
16
  * A phone number, in E.164 (`+15145550199`). The country of the number, its flag and its calling
@@ -15,8 +20,15 @@ export interface TelFieldProps extends Omit<TextFieldProps, 'type' | 'inputMode'
15
20
  * Until a number is complete, the value is the text as typed, which the `tel` rule refuses. A value
16
21
  * that isn't E.164, kept from before, shows as it is, and becomes E.164 when the field is left, if
17
22
  * it reads as a number of the chosen country.
23
+ *
24
+ * With `extension`, an input after the number takes the digits of an extension, kept after `;ext=`
25
+ * (`+15145550199;ext=123`). An extension typed or pasted after the number (`ext. 123`, `x123`,
26
+ * `poste 123`) moves to that input when the field is left.
27
+ */
28
+ export declare function TelField({ value, onChange, onBlur, country: defaultCountry, extension: allowsExtension, suffix, disabled, readOnly, ...props }: TelFieldProps): import("react").JSX.Element;
29
+ /**
30
+ * The `tel` type: `settings.country` is the country of a new number, and `settings.extension` adds
31
+ * an input for an extension.
18
32
  */
19
- export declare function TelField({ value, onChange, onBlur, country: defaultCountry, disabled, readOnly, ...props }: TelFieldProps): import("react").JSX.Element;
20
- /** The `tel` type: `settings.country` is the country of a new number. */
21
33
  export declare function TelFieldEntry(props: FieldEntryProps): import("react").JSX.Element;
22
34
  //# sourceMappingURL=TelField.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"TelField.d.ts","sourceRoot":"","sources":["../../src/tel/TelField.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAa,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAC;AASnE,MAAM,WAAW,aAAc,SAAQ,IAAI,CACvC,cAAc,EACd,MAAM,GAAG,WAAW,GAAG,QAAQ,GAAG,WAAW,GAAG,QAAQ,CAC3D;IACG;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC3B;AAaD;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,EACrB,KAAK,EACL,QAAQ,EACR,MAAM,EACN,OAAO,EAAE,cAAc,EACvB,QAAQ,EACR,QAAQ,EACR,GAAG,KAAK,EACX,EAAE,aAAa,+BAwFf;AAED,yEAAyE;AACzE,wBAAgB,aAAa,CAAC,KAAK,EAAE,eAAe,+BAUnD"}
1
+ {"version":3,"file":"TelField.d.ts","sourceRoot":"","sources":["../../src/tel/TelField.tsx"],"names":[],"mappings":"AAOA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAa,KAAK,cAAc,EAAE,MAAM,mBAAmB,CAAC;AAcnE,MAAM,WAAW,aAAc,SAAQ,IAAI,CACvC,cAAc,EACd,MAAM,GAAG,WAAW,GAAG,QAAQ,GAAG,WAAW,GAAG,QAAQ,CAC3D;IACG;;;OAGG;IACH,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACxB;;;OAGG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;CACvB;AAgBD;;;;;;;;;;;;GAYG;AACH,wBAAgB,QAAQ,CAAC,EACrB,KAAK,EACL,QAAQ,EACR,MAAM,EACN,OAAO,EAAE,cAAc,EACvB,SAAS,EAAE,eAAuB,EAClC,MAAM,EACN,QAAQ,EACR,QAAQ,EACR,GAAG,KAAK,EACX,EAAE,aAAa,+BAgJf;AAED;;;GAGG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,eAAe,+BAYnD"}
@@ -1,13 +1,16 @@
1
- import { getFieldProps, getSetting, isString } from "../shared/entry.js";
1
+ import { getFieldProps, getSetting, isBoolean, isString } from "../shared/entry.js";
2
2
  import { messages } from "../shared/messages.js";
3
- import { TextField } from "../text/TextField.js";
4
3
  import { getCountryFlag, getCountryName, getLocaleCountry } from "../country/countries.js";
5
- import { formatPhoneInput, getCallingCode, getPhoneCountries, parsePhone, readPhone } from "./phone.js";
4
+ import { TextField } from "../text/TextField.js";
5
+ import TelField_module_default from "./TelField.module.js";
6
+ import { formatPhoneInput, getCallingCode, getPhoneCountries, joinExtension, parsePhone, readExtension, readPhone, splitExtension } from "./phone.js";
6
7
  import { c } from "react/compiler-runtime";
7
8
  import { useState } from "react";
8
9
  import { Select, usePanneauIntl } from "@panneau/ui";
9
- import { jsx } from "react/jsx-runtime";
10
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
10
11
  //#region src/tel/TelField.tsx
12
+ /** Characters that aren't part of a number: an extension typed after it (`x123`, `ext. 123`). */
13
+ var NOT_A_NUMBER = /[^\d\s()+.-]/;
11
14
  /** The text shown for a value: a number of the country in its format, any other as it is. */
12
15
  function display(value, country) {
13
16
  const number = parsePhone(value);
@@ -22,18 +25,24 @@ function display(value, country) {
22
25
  * Until a number is complete, the value is the text as typed, which the `tel` rule refuses. A value
23
26
  * that isn't E.164, kept from before, shows as it is, and becomes E.164 when the field is left, if
24
27
  * it reads as a number of the chosen country.
28
+ *
29
+ * With `extension`, an input after the number takes the digits of an extension, kept after `;ext=`
30
+ * (`+15145550199;ext=123`). An extension typed or pasted after the number (`ext. 123`, `x123`,
31
+ * `poste 123`) moves to that input when the field is left.
25
32
  */
26
33
  function TelField(t0) {
27
- const $ = c(69);
34
+ const $ = c(88);
28
35
  let defaultCountry;
29
36
  let disabled;
30
37
  let onBlur;
31
38
  let onChange;
32
39
  let props;
33
40
  let readOnly;
41
+ let suffix;
42
+ let t1;
34
43
  let value;
35
44
  if ($[0] !== t0) {
36
- ({value, onChange, onBlur, country: defaultCountry, disabled, readOnly, ...props} = t0);
45
+ ({value, onChange, onBlur, country: defaultCountry, extension: t1, suffix, disabled, readOnly, ...props} = t0);
37
46
  $[0] = t0;
38
47
  $[1] = defaultCountry;
39
48
  $[2] = disabled;
@@ -41,7 +50,9 @@ function TelField(t0) {
41
50
  $[4] = onChange;
42
51
  $[5] = props;
43
52
  $[6] = readOnly;
44
- $[7] = value;
53
+ $[7] = suffix;
54
+ $[8] = t1;
55
+ $[9] = value;
45
56
  } else {
46
57
  defaultCountry = $[1];
47
58
  disabled = $[2];
@@ -49,47 +60,63 @@ function TelField(t0) {
49
60
  onChange = $[4];
50
61
  props = $[5];
51
62
  readOnly = $[6];
52
- value = $[7];
63
+ suffix = $[7];
64
+ t1 = $[8];
65
+ value = $[9];
53
66
  }
67
+ const allowsExtension = t1 === void 0 ? false : t1;
54
68
  const intl = usePanneauIntl();
55
69
  const [chosen, setChosen] = useState(null);
56
70
  const [draft, setDraft] = useState(null);
57
- let t1;
58
- if ($[8] !== value) {
59
- t1 = parsePhone(value);
60
- $[8] = value;
61
- $[9] = t1;
62
- } else t1 = $[9];
63
- const number = t1;
71
+ let country;
72
+ let number;
73
+ let parts;
64
74
  let t2;
65
- if ($[10] !== chosen || $[11] !== defaultCountry || $[12] !== intl.locale || $[13] !== number?.country) {
66
- t2 = number?.country ?? chosen ?? defaultCountry ?? getLocaleCountry(intl.locale) ?? null;
67
- $[10] = chosen;
68
- $[11] = defaultCountry;
69
- $[12] = intl.locale;
70
- $[13] = number?.country;
71
- $[14] = t2;
72
- } else t2 = $[14];
73
- const country = t2;
75
+ if ($[10] !== allowsExtension || $[11] !== chosen || $[12] !== defaultCountry || $[13] !== draft || $[14] !== intl.locale || $[15] !== value) {
76
+ parts = allowsExtension ? splitExtension(value) : {
77
+ number: value ?? null,
78
+ extension: null
79
+ };
80
+ number = parsePhone(parts.number);
81
+ country = number?.country ?? chosen ?? defaultCountry ?? getLocaleCountry(intl.locale) ?? null;
82
+ t2 = draft ?? display(parts.number, country);
83
+ $[10] = allowsExtension;
84
+ $[11] = chosen;
85
+ $[12] = defaultCountry;
86
+ $[13] = draft;
87
+ $[14] = intl.locale;
88
+ $[15] = value;
89
+ $[16] = country;
90
+ $[17] = number;
91
+ $[18] = parts;
92
+ $[19] = t2;
93
+ } else {
94
+ country = $[16];
95
+ number = $[17];
96
+ parts = $[18];
97
+ t2 = $[19];
98
+ }
99
+ const shown = t2;
74
100
  let t3;
75
- if ($[15] !== country || $[16] !== draft || $[17] !== value) {
76
- t3 = draft ?? display(value, country);
77
- $[15] = country;
78
- $[16] = draft;
79
- $[17] = value;
80
- $[18] = t3;
81
- } else t3 = $[18];
82
- const shown = t3;
83
- let t4;
84
- if ($[19] !== onChange || $[20] !== value) {
85
- t4 = (next) => {
101
+ if ($[20] !== onChange || $[21] !== value) {
102
+ t3 = (next) => {
86
103
  if (next !== (value ?? null)) onChange?.(next);
87
104
  };
88
- $[19] = onChange;
89
- $[20] = value;
90
- $[21] = t4;
91
- } else t4 = $[21];
92
- const emit = t4;
105
+ $[20] = onChange;
106
+ $[21] = value;
107
+ $[22] = t3;
108
+ } else t3 = $[22];
109
+ const emit = t3;
110
+ let t4;
111
+ if ($[23] !== emit || $[24] !== parts) {
112
+ t4 = (next_0, extension) => {
113
+ emit(joinExtension(next_0, extension === void 0 ? parts.extension : extension));
114
+ };
115
+ $[23] = emit;
116
+ $[24] = parts;
117
+ $[25] = t4;
118
+ } else t4 = $[25];
119
+ const emitNumber = t4;
93
120
  let T0;
94
121
  let t10;
95
122
  let t5;
@@ -97,64 +124,64 @@ function TelField(t0) {
97
124
  let t7;
98
125
  let t8;
99
126
  let t9;
100
- if ($[22] !== disabled || $[23] !== intl || $[24] !== readOnly) {
127
+ if ($[26] !== disabled || $[27] !== intl || $[28] !== readOnly) {
101
128
  const collator = new Intl.Collator(intl.locale);
102
129
  let t11;
103
- if ($[32] !== intl.locale) {
130
+ if ($[36] !== intl.locale) {
104
131
  t11 = (code) => ({
105
132
  code,
106
133
  name: getCountryName(code, intl.locale)
107
134
  });
108
- $[32] = intl.locale;
109
- $[33] = t11;
110
- } else t11 = $[33];
135
+ $[36] = intl.locale;
136
+ $[37] = t11;
137
+ } else t11 = $[37];
111
138
  const countries = getPhoneCountries().map(t11).sort((a, b) => collator.compare(a.name, b.name));
112
139
  T0 = Select;
113
- if ($[34] !== intl) {
140
+ if ($[38] !== intl) {
114
141
  t5 = intl.formatMessage(messages.telCountry);
115
- $[34] = intl;
116
- $[35] = t5;
117
- } else t5 = $[35];
142
+ $[38] = intl;
143
+ $[39] = t5;
144
+ } else t5 = $[39];
118
145
  t6 = "bare";
119
146
  t7 = true;
120
147
  t8 = disabled === true || readOnly === true;
121
148
  t9 = "+";
122
149
  t10 = countries.map(_temp);
123
- $[22] = disabled;
124
- $[23] = intl;
125
- $[24] = readOnly;
126
- $[25] = T0;
127
- $[26] = t10;
128
- $[27] = t5;
129
- $[28] = t6;
130
- $[29] = t7;
131
- $[30] = t8;
132
- $[31] = t9;
150
+ $[26] = disabled;
151
+ $[27] = intl;
152
+ $[28] = readOnly;
153
+ $[29] = T0;
154
+ $[30] = t10;
155
+ $[31] = t5;
156
+ $[32] = t6;
157
+ $[33] = t7;
158
+ $[34] = t8;
159
+ $[35] = t9;
133
160
  } else {
134
- T0 = $[25];
135
- t10 = $[26];
136
- t5 = $[27];
137
- t6 = $[28];
138
- t7 = $[29];
139
- t8 = $[30];
140
- t9 = $[31];
161
+ T0 = $[29];
162
+ t10 = $[30];
163
+ t5 = $[31];
164
+ t6 = $[32];
165
+ t7 = $[33];
166
+ t8 = $[34];
167
+ t9 = $[35];
141
168
  }
142
169
  let t11;
143
- if ($[36] !== emit || $[37] !== number?.nationalNumber || $[38] !== shown) {
144
- t11 = (next_0) => {
145
- const code_1 = next_0 !== null ? String(next_0) : null;
170
+ if ($[40] !== emitNumber || $[41] !== number?.nationalNumber || $[42] !== shown) {
171
+ t11 = (next_1) => {
172
+ const code_1 = next_1 !== null ? String(next_1) : null;
146
173
  setChosen(code_1);
147
174
  setDraft(null);
148
175
  const digits = number?.nationalNumber ?? shown.replace(/^\+/, "");
149
- emit(readPhone(digits, code_1).value);
176
+ emitNumber(readPhone(digits, code_1).value);
150
177
  };
151
- $[36] = emit;
152
- $[37] = number?.nationalNumber;
153
- $[38] = shown;
154
- $[39] = t11;
155
- } else t11 = $[39];
178
+ $[40] = emitNumber;
179
+ $[41] = number?.nationalNumber;
180
+ $[42] = shown;
181
+ $[43] = t11;
182
+ } else t11 = $[43];
156
183
  let t12;
157
- if ($[40] !== T0 || $[41] !== country || $[42] !== t10 || $[43] !== t11 || $[44] !== t5 || $[45] !== t6 || $[46] !== t7 || $[47] !== t8 || $[48] !== t9) {
184
+ if ($[44] !== T0 || $[45] !== country || $[46] !== t10 || $[47] !== t11 || $[48] !== t5 || $[49] !== t6 || $[50] !== t7 || $[51] !== t8 || $[52] !== t9) {
158
185
  t12 = /* @__PURE__ */ jsx(T0, {
159
186
  "aria-label": t5,
160
187
  appearance: t6,
@@ -166,51 +193,105 @@ function TelField(t0) {
166
193
  renderValue: _temp2,
167
194
  onChange: t11
168
195
  });
169
- $[40] = T0;
170
- $[41] = country;
171
- $[42] = t10;
172
- $[43] = t11;
173
- $[44] = t5;
174
- $[45] = t6;
175
- $[46] = t7;
176
- $[47] = t8;
177
- $[48] = t9;
178
- $[49] = t12;
179
- } else t12 = $[49];
196
+ $[44] = T0;
197
+ $[45] = country;
198
+ $[46] = t10;
199
+ $[47] = t11;
200
+ $[48] = t5;
201
+ $[49] = t6;
202
+ $[50] = t7;
203
+ $[51] = t8;
204
+ $[52] = t9;
205
+ $[53] = t12;
206
+ } else t12 = $[53];
180
207
  const picker = t12;
181
208
  let t13;
182
- if ($[50] !== country || $[51] !== emit || $[52] !== shown) {
183
- t13 = (text) => {
209
+ if ($[54] !== allowsExtension || $[55] !== disabled || $[56] !== emitNumber || $[57] !== intl || $[58] !== onBlur || $[59] !== parts || $[60] !== props || $[61] !== readOnly) {
210
+ t13 = allowsExtension ? /* @__PURE__ */ jsxs("span", {
211
+ className: TelField_module_default.extension,
212
+ children: [/* @__PURE__ */ jsx("span", {
213
+ "aria-hidden": "true",
214
+ children: intl.formatMessage(messages.telExtensionShort)
215
+ }), /* @__PURE__ */ jsx("input", {
216
+ className: TelField_module_default.extensionInput,
217
+ type: "text",
218
+ inputMode: "numeric",
219
+ autoComplete: "tel-extension",
220
+ "aria-label": intl.formatMessage(messages.telExtension),
221
+ "aria-invalid": (props.errors?.length ?? 0) > 0 || void 0,
222
+ maxLength: 10,
223
+ value: parts.extension ?? "",
224
+ disabled,
225
+ readOnly,
226
+ onChange: (event) => {
227
+ const digits_0 = event.target.value.replace(/\D/g, "").slice(0, 10);
228
+ emitNumber(parts.number, digits_0 === "" ? null : digits_0);
229
+ },
230
+ onBlur: () => onBlur?.()
231
+ })]
232
+ }) : null;
233
+ $[54] = allowsExtension;
234
+ $[55] = disabled;
235
+ $[56] = emitNumber;
236
+ $[57] = intl;
237
+ $[58] = onBlur;
238
+ $[59] = parts;
239
+ $[60] = props;
240
+ $[61] = readOnly;
241
+ $[62] = t13;
242
+ } else t13 = $[62];
243
+ const extensionInput = t13;
244
+ let t14;
245
+ if ($[63] !== extensionInput || $[64] !== suffix) {
246
+ t14 = extensionInput !== null || suffix !== void 0 ? { suffix: /* @__PURE__ */ jsxs(Fragment, { children: [extensionInput, suffix] }) } : {};
247
+ $[63] = extensionInput;
248
+ $[64] = suffix;
249
+ $[65] = t14;
250
+ } else t14 = $[65];
251
+ let t15;
252
+ if ($[66] !== allowsExtension || $[67] !== country || $[68] !== emitNumber || $[69] !== shown) {
253
+ t15 = (text) => {
184
254
  const typed = text ?? "";
185
- const next_1 = typed.length > shown.length && typed.startsWith(shown) ? formatPhoneInput(typed, country) : typed;
186
- setDraft(next_1);
187
- const read = readPhone(next_1, country);
255
+ const typedExtension = allowsExtension && NOT_A_NUMBER.test(typed);
256
+ const added = typed.startsWith(shown) ? typed.slice(shown.length) : "";
257
+ const next_2 = !typedExtension && added !== "" && !(allowsExtension && added.trim() === "") ? formatPhoneInput(typed, country) : typed;
258
+ setDraft(next_2);
259
+ if (typedExtension) {
260
+ emitNumber(next_2.trim());
261
+ return;
262
+ }
263
+ const read = readPhone(next_2, country);
188
264
  if (read.country !== null && read.country !== country) setChosen(read.country);
189
- emit(read.value);
265
+ emitNumber(read.value);
190
266
  };
191
- $[50] = country;
192
- $[51] = emit;
193
- $[52] = shown;
194
- $[53] = t13;
195
- } else t13 = $[53];
196
- let t14;
197
- if ($[54] !== country || $[55] !== disabled || $[56] !== emit || $[57] !== onBlur || $[58] !== readOnly || $[59] !== value) {
198
- t14 = () => {
267
+ $[66] = allowsExtension;
268
+ $[67] = country;
269
+ $[68] = emitNumber;
270
+ $[69] = shown;
271
+ $[70] = t15;
272
+ } else t15 = $[70];
273
+ let t16;
274
+ if ($[71] !== allowsExtension || $[72] !== country || $[73] !== disabled || $[74] !== emitNumber || $[75] !== onBlur || $[76] !== parts || $[77] !== readOnly) {
275
+ t16 = () => {
199
276
  setDraft(null);
200
- if (readOnly !== true && disabled !== true && isString(value) && parsePhone(value) === null) emit(readPhone(value, country).value);
277
+ if (readOnly !== true && disabled !== true && isString(parts.number) && parsePhone(parts.number) === null) {
278
+ const typed_0 = allowsExtension ? readExtension(parts.number) : null;
279
+ emitNumber(readPhone(typed_0?.number ?? parts.number, country).value, typed_0?.extension ?? parts.extension);
280
+ }
201
281
  onBlur?.();
202
282
  };
203
- $[54] = country;
204
- $[55] = disabled;
205
- $[56] = emit;
206
- $[57] = onBlur;
207
- $[58] = readOnly;
208
- $[59] = value;
209
- $[60] = t14;
210
- } else t14 = $[60];
211
- let t15;
212
- if ($[61] !== disabled || $[62] !== picker || $[63] !== props || $[64] !== readOnly || $[65] !== shown || $[66] !== t13 || $[67] !== t14) {
213
- t15 = /* @__PURE__ */ jsx(TextField, {
283
+ $[71] = allowsExtension;
284
+ $[72] = country;
285
+ $[73] = disabled;
286
+ $[74] = emitNumber;
287
+ $[75] = onBlur;
288
+ $[76] = parts;
289
+ $[77] = readOnly;
290
+ $[78] = t16;
291
+ } else t16 = $[78];
292
+ let t17;
293
+ if ($[79] !== disabled || $[80] !== picker || $[81] !== props || $[82] !== readOnly || $[83] !== shown || $[84] !== t14 || $[85] !== t15 || $[86] !== t16) {
294
+ t17 = /* @__PURE__ */ jsx(TextField, {
214
295
  autoComplete: "tel",
215
296
  ...props,
216
297
  disabled,
@@ -218,22 +299,27 @@ function TelField(t0) {
218
299
  type: "tel",
219
300
  inputMode: "tel",
220
301
  prefix: picker,
302
+ ...t14,
221
303
  value: shown,
222
- onChange: t13,
223
- onBlur: t14
304
+ onChange: t15,
305
+ onBlur: t16
224
306
  });
225
- $[61] = disabled;
226
- $[62] = picker;
227
- $[63] = props;
228
- $[64] = readOnly;
229
- $[65] = shown;
230
- $[66] = t13;
231
- $[67] = t14;
232
- $[68] = t15;
233
- } else t15 = $[68];
234
- return t15;
307
+ $[79] = disabled;
308
+ $[80] = picker;
309
+ $[81] = props;
310
+ $[82] = readOnly;
311
+ $[83] = shown;
312
+ $[84] = t14;
313
+ $[85] = t15;
314
+ $[86] = t16;
315
+ $[87] = t17;
316
+ } else t17 = $[87];
317
+ return t17;
235
318
  }
236
- /** The `tel` type: `settings.country` is the country of a new number. */
319
+ /**
320
+ * The `tel` type: `settings.country` is the country of a new number, and `settings.extension` adds
321
+ * an input for an extension.
322
+ */
237
323
  function _temp2(option) {
238
324
  return `+${getCallingCode(String(option.value)) ?? ""}`;
239
325
  }
@@ -246,7 +332,7 @@ function _temp(t0) {
246
332
  };
247
333
  }
248
334
  function TelFieldEntry(props) {
249
- const $ = c(11);
335
+ const $ = c(16);
250
336
  let t0;
251
337
  if ($[0] !== props.field) {
252
338
  t0 = getSetting(props.field, "country", isString);
@@ -255,33 +341,48 @@ function TelFieldEntry(props) {
255
341
  } else t0 = $[1];
256
342
  const country = t0;
257
343
  let t1;
258
- if ($[2] !== props) {
259
- t1 = getFieldProps(props);
260
- $[2] = props;
344
+ if ($[2] !== props.field) {
345
+ t1 = getSetting(props.field, "extension", isBoolean);
346
+ $[2] = props.field;
261
347
  $[3] = t1;
262
348
  } else t1 = $[3];
349
+ const extension = t1 === true;
263
350
  let t2;
264
- if ($[4] !== country) {
265
- t2 = country !== void 0 ? { country } : {};
266
- $[4] = country;
351
+ if ($[4] !== props) {
352
+ t2 = getFieldProps(props);
353
+ $[4] = props;
267
354
  $[5] = t2;
268
355
  } else t2 = $[5];
269
- const t3 = isString(props.value) ? props.value : null;
356
+ let t3;
357
+ if ($[6] !== country) {
358
+ t3 = country !== void 0 ? { country } : {};
359
+ $[6] = country;
360
+ $[7] = t3;
361
+ } else t3 = $[7];
270
362
  let t4;
271
- if ($[6] !== props.onChange || $[7] !== t1 || $[8] !== t2 || $[9] !== t3) {
272
- t4 = /* @__PURE__ */ jsx(TelField, {
273
- ...t1,
363
+ if ($[8] !== extension) {
364
+ t4 = extension ? { extension } : {};
365
+ $[8] = extension;
366
+ $[9] = t4;
367
+ } else t4 = $[9];
368
+ const t5 = isString(props.value) ? props.value : null;
369
+ let t6;
370
+ if ($[10] !== props.onChange || $[11] !== t2 || $[12] !== t3 || $[13] !== t4 || $[14] !== t5) {
371
+ t6 = /* @__PURE__ */ jsx(TelField, {
274
372
  ...t2,
275
- value: t3,
373
+ ...t3,
374
+ ...t4,
375
+ value: t5,
276
376
  onChange: props.onChange
277
377
  });
278
- $[6] = props.onChange;
279
- $[7] = t1;
280
- $[8] = t2;
281
- $[9] = t3;
282
- $[10] = t4;
283
- } else t4 = $[10];
284
- return t4;
378
+ $[10] = props.onChange;
379
+ $[11] = t2;
380
+ $[12] = t3;
381
+ $[13] = t4;
382
+ $[14] = t5;
383
+ $[15] = t6;
384
+ } else t6 = $[15];
385
+ return t6;
285
386
  }
286
387
  //#endregion
287
388
  export { TelField, TelFieldEntry };