@canonical/react-ds-global-form 0.35.0 → 0.37.0

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 (86) hide show
  1. package/dist/esm/lib/index.js +2 -0
  2. package/dist/esm/lib/index.js.map +1 -1
  3. package/dist/esm/lib/subcomponent/ComboboxInput/SingleCombobox.js +2 -1
  4. package/dist/esm/lib/subcomponent/ComboboxInput/SingleCombobox.js.map +1 -1
  5. package/dist/esm/lib/subcomponent/ComboboxInput/common/List/List.js +1 -1
  6. package/dist/esm/lib/subcomponent/ComboboxInput/common/List/List.js.map +1 -1
  7. package/dist/esm/lib/subcomponent/ComboboxInput/utils/index.js +0 -1
  8. package/dist/esm/lib/subcomponent/ComboboxInput/utils/index.js.map +1 -1
  9. package/dist/esm/lib/subcomponent/PhoneInput/PhoneInput.js +44 -20
  10. package/dist/esm/lib/subcomponent/PhoneInput/PhoneInput.js.map +1 -1
  11. package/dist/esm/lib/utils/countries/index.js +3 -3
  12. package/dist/esm/lib/utils/countries/index.js.map +1 -1
  13. package/dist/esm/lib/utils/formatter/applyPattern.js +38 -0
  14. package/dist/esm/lib/utils/formatter/applyPattern.js.map +1 -0
  15. package/dist/esm/lib/utils/formatter/createFormatterRegisterOptions.js +22 -0
  16. package/dist/esm/lib/utils/formatter/createFormatterRegisterOptions.js.map +1 -0
  17. package/dist/esm/lib/utils/formatter/createPatternFormatter.js +25 -0
  18. package/dist/esm/lib/utils/formatter/createPatternFormatter.js.map +1 -0
  19. package/dist/esm/lib/utils/formatter/index.js +8 -0
  20. package/dist/esm/lib/utils/formatter/index.js.map +1 -0
  21. package/dist/esm/lib/utils/formatter/stripToDigits.js +12 -0
  22. package/dist/esm/lib/utils/formatter/stripToDigits.js.map +1 -0
  23. package/dist/esm/lib/utils/formatter/types.js +2 -0
  24. package/dist/esm/lib/utils/formatter/types.js.map +1 -0
  25. package/dist/esm/lib/utils/hooks/index.js +1 -0
  26. package/dist/esm/lib/utils/hooks/index.js.map +1 -1
  27. package/dist/esm/lib/utils/hooks/types.js +2 -0
  28. package/dist/esm/lib/utils/hooks/types.js.map +1 -0
  29. package/dist/esm/lib/utils/hooks/useFormattedValue.js +195 -0
  30. package/dist/esm/lib/utils/hooks/useFormattedValue.js.map +1 -0
  31. package/dist/esm/lib/utils/index.js +6 -2
  32. package/dist/esm/lib/utils/index.js.map +1 -1
  33. package/dist/esm/lib/utils/mergeRefs.js +25 -0
  34. package/dist/esm/lib/utils/mergeRefs.js.map +1 -0
  35. package/dist/types/lib/component/PhoneField/PhoneField.d.ts +2 -1
  36. package/dist/types/lib/component/PhoneField/PhoneField.d.ts.map +1 -1
  37. package/dist/types/lib/index.d.ts +4 -0
  38. package/dist/types/lib/index.d.ts.map +1 -1
  39. package/dist/types/lib/subcomponent/ComboboxInput/SingleCombobox.d.ts.map +1 -1
  40. package/dist/types/lib/subcomponent/ComboboxInput/utils/index.d.ts +0 -1
  41. package/dist/types/lib/subcomponent/ComboboxInput/utils/index.d.ts.map +1 -1
  42. package/dist/types/lib/subcomponent/PhoneInput/PhoneInput.d.ts +19 -2
  43. package/dist/types/lib/subcomponent/PhoneInput/PhoneInput.d.ts.map +1 -1
  44. package/dist/types/lib/subcomponent/PhoneInput/types.d.ts +20 -7
  45. package/dist/types/lib/subcomponent/PhoneInput/types.d.ts.map +1 -1
  46. package/dist/types/lib/utils/countries/index.d.ts +0 -3
  47. package/dist/types/lib/utils/countries/index.d.ts.map +1 -1
  48. package/dist/types/lib/utils/formatter/applyPattern.d.ts +17 -0
  49. package/dist/types/lib/utils/formatter/applyPattern.d.ts.map +1 -0
  50. package/dist/types/lib/utils/formatter/createFormatterRegisterOptions.d.ts +20 -0
  51. package/dist/types/lib/utils/formatter/createFormatterRegisterOptions.d.ts.map +1 -0
  52. package/dist/types/lib/utils/formatter/createPatternFormatter.d.ts +19 -0
  53. package/dist/types/lib/utils/formatter/createPatternFormatter.d.ts.map +1 -0
  54. package/dist/types/lib/utils/formatter/index.d.ts +6 -0
  55. package/dist/types/lib/utils/formatter/index.d.ts.map +1 -0
  56. package/dist/types/lib/utils/formatter/stripToDigits.d.ts +10 -0
  57. package/dist/types/lib/utils/formatter/stripToDigits.d.ts.map +1 -0
  58. package/dist/types/lib/utils/formatter/types.d.ts +30 -0
  59. package/dist/types/lib/utils/formatter/types.d.ts.map +1 -0
  60. package/dist/types/lib/utils/hooks/index.d.ts +2 -0
  61. package/dist/types/lib/utils/hooks/index.d.ts.map +1 -1
  62. package/dist/types/lib/utils/hooks/types.d.ts +33 -0
  63. package/dist/types/lib/utils/hooks/types.d.ts.map +1 -0
  64. package/dist/types/lib/utils/hooks/useFormattedValue.d.ts +30 -0
  65. package/dist/types/lib/utils/hooks/useFormattedValue.d.ts.map +1 -0
  66. package/dist/types/lib/utils/index.d.ts +2 -0
  67. package/dist/types/lib/utils/index.d.ts.map +1 -1
  68. package/dist/types/lib/utils/mergeRefs.d.ts +14 -0
  69. package/dist/types/lib/utils/mergeRefs.d.ts.map +1 -0
  70. package/package.json +13 -13
  71. package/dist/esm/lib/subcomponent/ComboboxInput/utils/mergeRefs.js +0 -12
  72. package/dist/esm/lib/subcomponent/ComboboxInput/utils/mergeRefs.js.map +0 -1
  73. package/dist/esm/lib/utils/countries/applyPhoneMask.js +0 -35
  74. package/dist/esm/lib/utils/countries/applyPhoneMask.js.map +0 -1
  75. package/dist/esm/lib/utils/countries/phoneRegisterOptions.js +0 -18
  76. package/dist/esm/lib/utils/countries/phoneRegisterOptions.js.map +0 -1
  77. package/dist/esm/lib/utils/countries/removePhoneMask.js +0 -12
  78. package/dist/esm/lib/utils/countries/removePhoneMask.js.map +0 -1
  79. package/dist/types/lib/subcomponent/ComboboxInput/utils/mergeRefs.d.ts +0 -3
  80. package/dist/types/lib/subcomponent/ComboboxInput/utils/mergeRefs.d.ts.map +0 -1
  81. package/dist/types/lib/utils/countries/applyPhoneMask.d.ts +0 -14
  82. package/dist/types/lib/utils/countries/applyPhoneMask.d.ts.map +0 -1
  83. package/dist/types/lib/utils/countries/phoneRegisterOptions.d.ts +0 -14
  84. package/dist/types/lib/utils/countries/phoneRegisterOptions.d.ts.map +0 -1
  85. package/dist/types/lib/utils/countries/removePhoneMask.d.ts +0 -10
  86. package/dist/types/lib/utils/countries/removePhoneMask.d.ts.map +0 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFormattedValue.js","sourceRoot":"","sources":["../../../../../src/lib/utils/hooks/useFormattedValue.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,eAAe,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAwBrE,4EAA4E;AAC5E,0EAA0E;AAC1E,yDAAyD;AACzD,MAAM,yBAAyB,GAC7B,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,SAAS,CAAC;AAE9D;;;;GAIG;AACH,SAAS,iBAAiB,CAAC,KAAa,EAAE,KAAa;IACrD,OAAO,KAAK,CAAC,KAAK,CAAC,CAAC,EAAE,KAAK,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,KAAK,GAAG,CAAC,CAAC,CAAC;AACxD,CAAC;AAED;;;;;;;;;GASG;AACH,SAAS,cAAc,CACrB,KAA0C;IAE1C,MAAM,EAAE,SAAS,EAAE,GAAG,KAAK,CAAC,WAAkC,CAAC;IAC/D,IAAI,SAAS,KAAK,SAAS;QAAE,OAAO,gBAAgB,CAAC;IACrD,IAAI,SAAS,CAAC,QAAQ,CAAC,SAAS,CAAC;QAAE,OAAO,eAAe,CAAC;IAC1D,IAAI,SAAS,CAAC,UAAU,CAAC,QAAQ,CAAC;QAAE,OAAO,gBAAgB,CAAC;IAC5D,OAAO,QAAQ,CAAC;AAClB,CAAC;AAED;;;;;;;;;;GAUG;AACH,SAAS,eAAe,CACtB,SAAoB,EACpB,IAAY,EACZ,MAAc;IAEd,IAAI,QAAQ,GAAG,CAAC,CAAC;IACjB,OACE,QAAQ,GAAG,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6EAA6E;IAC7E,gFAAgF;IAChF,yBAAyB,CAAC,GAAG,EAAE;QAC7B,MAAM,IAAI,GAAG,GAAG,CAAC,OAAO,CAAC;QACzB,MAAM,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;QAC/B,IAAI,IAAI,KAAK,IAAI,IAAI,MAAM,KAAK,IAAI;YAAE,OAAO;QAC7C,IAAI,IAAI,CAAC,KAAK,KAAK,MAAM,CAAC,IAAI;YAAE,OAAO;QACvC,OAAO,CAAC,OAAO,GAAG,IAAI,CAAC;QACvB,IAAI,QAAQ,CAAC,aAAa,KAAK,IAAI;YAAE,OAAO;QAE5C,MAAM,QAAQ,GAAG,eAAe,CAAC,SAAS,EAAE,IAAI,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;QACvE,IAAI,CAAC,iBAAiB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;IAC7C,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,KAAK,EAAE,aAAa,IAAI,SAAS,CAAC,MAAM,CAAC,KAAK,CAAC;QAC/C,QAAQ,EAAE,YAAY;QACtB,kBAAkB,EAAE,sBAAsB;QAC1C,gBAAgB,EAAE,oBAAoB;QACtC,GAAG;KACJ,CAAC;AACJ,CAAC"}
@@ -1,5 +1,9 @@
1
- // Generic supporting helpers (not an ontology tier): shared hooks + form
2
- // middleware. Any tier may depend on `utils/` downward.
1
+ // Generic supporting helpers (not an ontology tier): shared hooks, value
2
+ // formatting, form middleware, and the ref merger they share. Any tier may
3
+ // depend on `utils/` downward. The country dataset is reached directly rather
4
+ // than through here, since only the phone input has any use for it.
5
+ export * from "./formatter/index.js";
3
6
  export * from "./hooks/index.js";
7
+ export { default as mergeRefs } from "./mergeRefs.js";
4
8
  export * from "./middleware/index.js";
5
9
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/utils/index.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,wDAAwD;AACxD,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/lib/utils/index.ts"],"names":[],"mappings":"AAAA,yEAAyE;AACzE,2EAA2E;AAC3E,8EAA8E;AAC9E,oEAAoE;AACpE,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACtD,cAAc,uBAAuB,CAAC"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Fan one element out to several refs, so a component can keep its own internal
3
+ * ref while still honouring a forwarded one. Accepts both callback refs and ref
4
+ * objects, and ignores `undefined` entries, so an optional forwarded ref can be
5
+ * passed straight through.
6
+ *
7
+ * @example
8
+ * <input ref={mergeRefs(internalRef, forwardedRef)} />
9
+ *
10
+ * @note Pure — returns a new callback ref; the returned callback is impure by
11
+ * necessity, since assigning the element to each ref is its whole purpose.
12
+ */
13
+ export default function mergeRefs(...refs) {
14
+ return (instance) => {
15
+ for (const ref of refs) {
16
+ if (typeof ref === "function") {
17
+ ref(instance);
18
+ }
19
+ else if (ref) {
20
+ ref.current = instance;
21
+ }
22
+ }
23
+ };
24
+ }
25
+ //# sourceMappingURL=mergeRefs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mergeRefs.js","sourceRoot":"","sources":["../../../../src/lib/utils/mergeRefs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,OAAO,UAAU,SAAS,CAC/B,GAAG,IAAkC;IAErC,OAAO,CAAC,QAAkB,EAAE,EAAE;QAC5B,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;YACvB,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE,CAAC;gBAC9B,GAAG,CAAC,QAAQ,CAAC,CAAC;YAChB,CAAC;iBAAM,IAAI,GAAG,EAAE,CAAC;gBACd,GAAiC,CAAC,OAAO,GAAG,QAAQ,CAAC;YACxD,CAAC;QACH,CAAC;IACH,CAAC,CAAC;AACJ,CAAC"}
@@ -27,6 +27,7 @@ declare const _default: (props: {
27
27
  "aria-errormessage"?: string | undefined;
28
28
  "aria-invalid"?: boolean | undefined;
29
29
  "aria-labelledby"?: string | undefined;
30
+ onBlur?: React.FocusEventHandler<HTMLInputElement> | undefined;
30
31
  onChange?: ((value: string | import("../../subcomponent/PhoneInput/types.js").PhoneValue) => void) | undefined;
31
32
  registerProps?: import("react-hook-form").RegisterOptions | undefined;
32
33
  isOptional?: boolean | undefined;
@@ -44,8 +45,8 @@ declare const _default: (props: {
44
45
  }>>) | undefined;
45
46
  condition?: import("../../index.js").Condition | undefined;
46
47
  defaultCountry?: import("../../utils/countries/types.js").KnownCountryCode | undefined;
47
- preferredCountries?: import("../../utils/countries/types.js").KnownCountryCode[] | undefined;
48
48
  filteredCountries?: import("../../utils/countries/types.js").KnownCountryCode[] | undefined;
49
+ preferredCountries?: import("../../utils/countries/types.js").KnownCountryCode[] | undefined;
49
50
  countries?: import("../../utils/countries/types.js").CountryData[] | undefined;
50
51
  valueFormat?: "e164" | "structured" | undefined;
51
52
  countryDisplay?: "code" | "name" | "flag" | undefined;
@@ -1 +1 @@
1
- {"version":3,"file":"PhoneField.d.ts","sourceRoot":"","sources":["../../../../../src/lib/component/PhoneField/PhoneField.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD;;;;;;;;;;;;;GAaG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACH,wBAEE"}
1
+ {"version":3,"file":"PhoneField.d.ts","sourceRoot":"","sources":["../../../../../src/lib/component/PhoneField/PhoneField.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAElD;;;;;;;;;;;;;GAaG;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACH,wBAEE"}
@@ -1,5 +1,9 @@
1
1
  export * from "./pattern/index.js";
2
2
  export type { RatingInputProps, RatingScale, } from "./subcomponent/index.js";
3
3
  export { RatingInput } from "./subcomponent/index.js";
4
+ export type { Formatter } from "./utils/formatter/index.js";
5
+ export { applyPattern, createFormatterRegisterOptions, createPatternFormatter, stripToDigits, } from "./utils/formatter/index.js";
6
+ export type { UseFormattedValueProps, UseFormattedValueResult, } from "./utils/hooks/index.js";
7
+ export { useFormattedValue } from "./utils/hooks/index.js";
4
8
  export * from "./utils/middleware/index.js";
5
9
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/index.ts"],"names":[],"mappings":"AAIA,cAAc,oBAAoB,CAAC;AAMnC,YAAY,EACV,gBAAgB,EAChB,WAAW,GACZ,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,cAAc,6BAA6B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/lib/index.ts"],"names":[],"mappings":"AAIA,cAAc,oBAAoB,CAAC;AAMnC,YAAY,EACV,gBAAgB,EAChB,WAAW,GACZ,MAAM,yBAAyB,CAAC;AACjC,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAMtD,YAAY,EAAE,SAAS,EAAE,MAAM,4BAA4B,CAAC;AAC5D,OAAO,EACL,YAAY,EACZ,8BAA8B,EAC9B,sBAAsB,EACtB,aAAa,GACd,MAAM,4BAA4B,CAAC;AACpC,YAAY,EACV,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,wBAAwB,CAAC;AAChC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,cAAc,6BAA6B,CAAC"}
@@ -1 +1 @@
1
- {"version":3,"file":"SingleCombobox.d.ts","sourceRoot":"","sources":["../../../../../src/lib/subcomponent/ComboboxInput/SingleCombobox.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAI1C,OAAO,EACL,mBAAmB,IAAI,0BAA0B,EACjD,kBAAkB,IAAI,yBAAyB,EAGhD,MAAM,kBAAkB,CAAC;AAC1B,OAAO,cAAc,CAAC;AAGtB;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;oDAsH1B,CAAC;AAEF,eAAe,cAAc,CAAC"}
1
+ {"version":3,"file":"SingleCombobox.d.ts","sourceRoot":"","sources":["../../../../../src/lib/subcomponent/ComboboxInput/SingleCombobox.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAI1C,OAAO,EACL,mBAAmB,IAAI,0BAA0B,EACjD,kBAAkB,IAAI,yBAAyB,EAEhD,MAAM,kBAAkB,CAAC;AAC1B,OAAO,cAAc,CAAC;AAGtB;;;;;;;;;GASG;AACH,eAAO,MAAM,cAAc;;;;;;;;;;;;;;;;oDAsH1B,CAAC;AAEF,eAAe,cAAc,CAAC"}
@@ -1,5 +1,4 @@
1
1
  export { default as convertItemToString } from "./convertItemToString.js";
2
2
  export { default as convertValueToItem } from "./convertValueToItem.js";
3
3
  export { default as filterItems } from "./filterItems.js";
4
- export { default as mergeRefs } from "./mergeRefs.js";
5
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/lib/subcomponent/ComboboxInput/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC1E,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AACxE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,kBAAkB,CAAC;AAC1D,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,gBAAgB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../../src/lib/subcomponent/ComboboxInput/utils/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,mBAAmB,EAAE,MAAM,0BAA0B,CAAC;AAC1E,OAAO,EAAE,OAAO,IAAI,kBAAkB,EAAE,MAAM,yBAAyB,CAAC;AACxE,OAAO,EAAE,OAAO,IAAI,WAAW,EAAE,MAAM,kBAAkB,CAAC"}
@@ -1,5 +1,6 @@
1
1
  import type React from "react";
2
- import type { PhoneInputProps } from "./types.js";
2
+ import { type CountryData, type KnownCountryCode } from "../../utils/countries/index.js";
3
+ import type { PhoneValue } from "./types.js";
3
4
  import "./styles.css";
4
5
  /**
5
6
  * Presentational phone input combining a country code selector with a telephone
@@ -10,12 +11,28 @@ import "./styles.css";
10
11
  * (an E.164 string or a structured `{ countryCode, number }` object). It
11
12
  * defaults defensively, so an undefined initial `value` renders the
12
13
  * `defaultCountry` with an empty number.
14
+ *
15
+ * The forwarded ref reaches the national-number input — the field's focusable
16
+ * element, and what react-hook-form needs for `setFocus` and focus-on-error.
13
17
  * @returns {React.ReactElement} - Rendered Phone
14
18
  *
15
19
  * `import { PhoneInput } from "@canonical/react-ds-global-form";`
16
20
  *
17
21
  * @implements ds:global.subcomponent.phone_input
18
22
  */
19
- export declare const PhoneInput: ({ id, className, style, value, onChange, defaultCountry, preferredCountries, filteredCountries, countries, valueFormat, countryDisplay, mask, disabled, }: PhoneInputProps) => React.ReactElement;
23
+ export declare const PhoneInput: React.ForwardRefExoticComponent<import("../types.js").BaseProps & {
24
+ name?: string;
25
+ value?: string | PhoneValue;
26
+ onChange?: (value: string | PhoneValue) => void;
27
+ onBlur?: React.FocusEventHandler<HTMLInputElement>;
28
+ defaultCountry?: KnownCountryCode;
29
+ filteredCountries?: KnownCountryCode[];
30
+ preferredCountries?: KnownCountryCode[];
31
+ countries?: CountryData[];
32
+ valueFormat?: "e164" | "structured";
33
+ countryDisplay?: "code" | "name" | "flag";
34
+ mask?: boolean;
35
+ disabled?: boolean;
36
+ } & React.RefAttributes<HTMLInputElement>>;
20
37
  export default PhoneInput;
21
38
  //# sourceMappingURL=PhoneInput.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"PhoneInput.d.ts","sourceRoot":"","sources":["../../../../../src/lib/subcomponent/PhoneInput/PhoneInput.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAQ/B,OAAO,KAAK,EAAE,eAAe,EAAc,MAAM,YAAY,CAAC;AAC9D,OAAO,cAAc,CAAC;AAkCtB;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,UAAU,GAAI,2JAcxB,eAAe,KAAG,KAAK,CAAC,YAgI1B,CAAC;AAEF,eAAe,UAAU,CAAC"}
1
+ {"version":3,"file":"PhoneInput.d.ts","sourceRoot":"","sources":["../../../../../src/lib/subcomponent/PhoneInput/PhoneInput.tsx"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EACL,KAAK,WAAW,EAEhB,KAAK,gBAAgB,EACtB,MAAM,gCAAgC,CAAC;AAIxC,OAAO,KAAK,EAAmB,UAAU,EAAE,MAAM,YAAY,CAAC;AAC9D,OAAO,cAAc,CAAC;AAgDtB;;;;;;;;;;;;;;;;;GAiBG;AACH,eAAO,MAAM,UAAU;;;;;;;;;;;;;0CAgKtB,CAAC;AAEF,eAAe,UAAU,CAAC"}
@@ -3,10 +3,22 @@ import type { BaseProps } from "../types.js";
3
3
  export type { CountryCode, CountryData, KnownCountryCode, } from "../../utils/countries/index.js";
4
4
  /** Props for the presentational Phone input (controlled, no react-hook-form). */
5
5
  export type PhoneInputProps = BaseProps & {
6
+ /**
7
+ * Name for the national-number input. The field tier supplies this; it is what
8
+ * gives the control a name in a plain HTML submission, so the entry is not
9
+ * silently dropped when scripting is unavailable.
10
+ */
11
+ name?: string;
6
12
  /** Controlled value — E.164 string or structured object. */
7
13
  value?: string | PhoneValue;
8
14
  /** Called with the next value in the configured `valueFormat`. */
9
15
  onChange?: (value: string | PhoneValue) => void;
16
+ /**
17
+ * Called when the national-number input loses focus. The field tier supplies
18
+ * this; without it react-hook-form never marks the field touched, so
19
+ * `mode: "onTouched"` never validates it and a touched-gated error never shows.
20
+ */
21
+ onBlur?: React.FocusEventHandler<HTMLInputElement>;
10
22
  /** Default country (a known ISO 3166-1 alpha-2 code from the dataset). */
11
23
  defaultCountry?: KnownCountryCode;
12
24
  /**
@@ -42,13 +54,14 @@ export type PhoneInputProps = BaseProps & {
42
54
  */
43
55
  countryDisplay?: "code" | "name" | "flag";
44
56
  /**
45
- * Opt in to live national-number formatting using the selected country's
46
- * display mask (cosmetic spacing/dashes; see {@link CountryData.format}).
47
- * Defaults to `false` — the number is shown as raw digits and `applyPhoneMask`
48
- * is not invoked. The submitted value is always raw digits / E.164 regardless
49
- * of this option. (The RHF-side `removePhoneMask` / `phoneRegisterOptions`
50
- * helpers are separate opt-in modules, so they are tree-shaken out unless
51
- * imported.)
57
+ * Opt in to live national-number grouping using the selected country's display
58
+ * pattern (cosmetic spacing/dashes; see {@link CountryData.format}). Defaults
59
+ * to `false`, which shows the number as raw digits.
60
+ *
61
+ * The submitted value is always raw digits / E.164 either way — the grouping is
62
+ * a display projection only, applied through `utils/formatter` and kept
63
+ * caret-stable by `useFormattedValue`, so the number stays editable in the
64
+ * middle rather than forcing the cursor to the end.
52
65
  */
53
66
  mask?: boolean;
54
67
  /** Whether the input is disabled. */
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/lib/subcomponent/PhoneInput/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,WAAW,EACX,gBAAgB,EACjB,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AAI7C,YAAY,EACV,WAAW,EACX,WAAW,EACX,g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EAAE,MAAM,CAAC;IAEd,4DAA4D;IAC5D,KAAK,CAAC,EAAE,MAAM,GAAG,UAAU,CAAC;IAE5B,kEAAkE;IAClE,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU,KAAK,IAAI,CAAC;IAEhD;;;;OAIG;IACH,MAAM,CAAC,EAAE,KAAK,CAAC,iBAAiB,CAAC,gBAAgB,CAAC,CAAC;IAEnD,0EAA0E;IAC1E,cAAc,CAAC,EAAE,gBAAgB,CAAC;IAElC;;;;;OAKG;IACH,iBAAiB,CAAC,EAAE,gBAAgB,EAAE,CAAC;IAEvC;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,gBAAgB,EAAE,CAAC;IAExC;;;OAGG;IACH,SAAS,CAAC,EAAE,WAAW,EAAE,CAAC;IAE1B,uDAAuD;IACvD,WAAW,CAAC,EAAE,MAAM,GAAG,YAAY,CAAC;IAEpC;;;;;;;;;;OAUG;IACH,cAAc,CAAC,EAAE,MAAM,GAAG,MAAM,GAAG,MAAM,CAAC;IAE1C;;;;;;;;;OASG;IACH,IAAI,CAAC,EAAE,OAAO,CAAC;IAEf,qCAAqC;IACrC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,CAAC;AAEF,MAAM,MAAM,UAAU,GAAG;IACvB,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,MAAM,CAAC;CAChB,CAAC"}
@@ -1,8 +1,5 @@
1
- export { default as applyPhoneMask } from "./applyPhoneMask.js";
2
1
  export { default as countries } from "./countries.js";
3
2
  export type { MaskKey } from "./masks.js";
4
3
  export { default as masks } from "./masks.js";
5
- export { default as phoneRegisterOptions } from "./phoneRegisterOptions.js";
6
- export { default as removePhoneMask } from "./removePhoneMask.js";
7
4
  export type { CountryCode, CountryData, KnownCountryCode } from "./types.js";
8
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/lib/utils/countries/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACtD,YAAY,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAC5E,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,sBAAsB,CAAC;AAClE,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/lib/utils/countries/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACtD,YAAY,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAC1C,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,YAAY,CAAC;AAC9C,YAAY,EAAE,WAAW,EAAE,WAAW,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Group a run of digits according to a display pattern (cosmetic only).
3
+ *
4
+ * The pattern uses `#` as a digit slot; any other character is a literal
5
+ * separator emitted between digits (e.g. `"(###) ###-####"`). Non-digits in
6
+ * `value` are stripped first, so the result is purely a function of the digits
7
+ * given. Extra digits beyond the pattern's slots are appended unformatted, so a
8
+ * longer-than-typical value is never truncated. With no pattern, the digits are
9
+ * returned as they are.
10
+ *
11
+ * This is display-only — callers keep the digits as the source of truth and
12
+ * recover them with {@link stripToDigits}.
13
+ *
14
+ * @note Pure.
15
+ */
16
+ export default function applyPattern(value: string, pattern?: string): string;
17
+ //# sourceMappingURL=applyPattern.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"applyPattern.d.ts","sourceRoot":"","sources":["../../../../../src/lib/utils/formatter/applyPattern.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,KAAK,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,GAAG,MAAM,CAmB5E"}
@@ -0,0 +1,20 @@
1
+ import type { RegisterOptions } from "react-hook-form";
2
+ import type { Formatter } from "./types.js";
3
+ /**
4
+ * Build react-hook-form `register()` options that normalise a formatted display
5
+ * value back to its model form, so the registered value is whatever the
6
+ * formatter's `parse` yields regardless of how the input is decorated on screen.
7
+ * Spread into `register(name, createFormatterRegisterOptions(formatter))`, or
8
+ * merge with your own rules.
9
+ *
10
+ * This covers the `register()` path only. react-hook-form does not apply
11
+ * `setValueAs` to a field bound with `useController`, so a controlled input must
12
+ * normalise in its own change handler instead — as PhoneInput does.
13
+ *
14
+ * @example
15
+ * <input {...register("phone", createFormatterRegisterOptions(formatter))} />
16
+ *
17
+ * @note Pure.
18
+ */
19
+ export default function createFormatterRegisterOptions(formatter: Formatter): RegisterOptions;
20
+ //# sourceMappingURL=createFormatterRegisterOptions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createFormatterRegisterOptions.d.ts","sourceRoot":"","sources":["../../../../../src/lib/utils/formatter/createFormatterRegisterOptions.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AACvD,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,OAAO,UAAU,8BAA8B,CACpD,SAAS,EAAE,SAAS,GACnB,eAAe,CAIjB"}
@@ -0,0 +1,19 @@
1
+ import type { Formatter } from "./types.js";
2
+ /**
3
+ * Build a {@link Formatter} for a fixed digit-grouping pattern — the common
4
+ * case, where the separators sit at the same offsets whatever the value is.
5
+ *
6
+ * The pattern uses `#` as a digit slot and treats any other character as a
7
+ * literal separator, so `"(###) ###-####"` groups ten digits as
8
+ * `"(555) 123-4567"`. With no pattern the formatter still strips the value to
9
+ * digits, which is how a field expresses "normalise but do not decorate".
10
+ *
11
+ * @example
12
+ * const formatter = createPatternFormatter("(###) ###-####");
13
+ * formatter.format("5551234567"); // "(555) 123-4567"
14
+ * formatter.parse("(555) 123-4567"); // "5551234567"
15
+ *
16
+ * @note Pure — the returned formatter's halves are pure too.
17
+ */
18
+ export default function createPatternFormatter(pattern?: string): Formatter;
19
+ //# sourceMappingURL=createPatternFormatter.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createPatternFormatter.d.ts","sourceRoot":"","sources":["../../../../../src/lib/utils/formatter/createPatternFormatter.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5C;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,SAAS,CAK1E"}
@@ -0,0 +1,6 @@
1
+ export { default as applyPattern } from "./applyPattern.js";
2
+ export { default as createFormatterRegisterOptions } from "./createFormatterRegisterOptions.js";
3
+ export { default as createPatternFormatter } from "./createPatternFormatter.js";
4
+ export { default as stripToDigits } from "./stripToDigits.js";
5
+ export type { Formatter } from "./types.js";
6
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/lib/utils/formatter/index.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,mBAAmB,CAAC;AAC5D,OAAO,EAAE,OAAO,IAAI,8BAA8B,EAAE,MAAM,qCAAqC,CAAC;AAChG,OAAO,EAAE,OAAO,IAAI,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAChF,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAC9D,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Reduce a display string to the digits it contains, dropping every separator
3
+ * (spaces, dashes, parens, and anything else). This is the `parse` half of a
4
+ * digit-grouping {@link Formatter} — the inverse of
5
+ * {@link applyPattern}.
6
+ *
7
+ * @note Pure.
8
+ */
9
+ export default function stripToDigits(value: string): string;
10
+ //# sourceMappingURL=stripToDigits.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stripToDigits.d.ts","sourceRoot":"","sources":["../../../../../src/lib/utils/formatter/stripToDigits.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,KAAK,EAAE,MAAM,GAAG,MAAM,CAE3D"}
@@ -0,0 +1,30 @@
1
+ /**
2
+ * A model/view pair for one input: `format` projects the stored value into what
3
+ * the user sees, `parse` recovers the stored value from whatever the user typed.
4
+ *
5
+ * The split exists because for some fields the string on screen is deliberately
6
+ * not the string that is submitted — a phone number shown as `(555) 123-4567` is
7
+ * stored as `5551234567`. The formatter names that split, so the display rule and
8
+ * the normalisation rule travel together instead of drifting apart.
9
+ *
10
+ * Two properties are required of an implementation, because `useFormattedValue`
11
+ * relies on them to place the caret after a reformat:
12
+ *
13
+ * - **`format` accepts partial models.** It is called on every keystroke, so it
14
+ * must render half-typed values (`"555"`) without waiting for a complete one.
15
+ * - **`parse` is total and left-inverse to `format`** — `parse(format(m)) === m`
16
+ * for any model `m` the field can hold, and `parse` never throws, whatever the
17
+ * user pastes in.
18
+ *
19
+ * A fixed pattern is only the simplest case; `createPatternFormatter` builds one
20
+ * from a grouping string. Because `format` is an ordinary function it can just as
21
+ * well choose its grouping from the value itself — which is what a card number
22
+ * needs, since American Express groups 4-6-5 where most brands group 4-4-4-4.
23
+ */
24
+ export type Formatter = {
25
+ /** Project the stored model value into the string the user sees. */
26
+ format: (model: string) => string;
27
+ /** Recover the stored model value from the string the user typed. */
28
+ parse: (view: string) => string;
29
+ };
30
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/lib/utils/formatter/types.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,MAAM,MAAM,SAAS,GAAG;IACtB,oEAAoE;IACpE,MAAM,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IAElC,qEAAqE;IACrE,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,MAAM,CAAC;CACjC,CAAC"}
@@ -1,4 +1,6 @@
1
+ export type { UseFormattedValueProps, UseFormattedValueResult, } from "./types.js";
1
2
  export { default as useFieldAriaProperties } from "./useFieldAriaProperties.js";
2
3
  export { default as useFieldError } from "./useFieldError.js";
4
+ export { default as useFormattedValue } from "./useFormattedValue.js";
3
5
  export { default as useOptionAriaProperties } from "./useOptionAriaProperties.js";
4
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/lib/utils/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAChF,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,OAAO,IAAI,uBAAuB,EAAE,MAAM,8BAA8B,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/lib/utils/hooks/index.ts"],"names":[],"mappings":"AAAA,YAAY,EACV,sBAAsB,EACtB,uBAAuB,GACxB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,OAAO,IAAI,sBAAsB,EAAE,MAAM,6BAA6B,CAAC;AAChF,OAAO,EAAE,OAAO,IAAI,aAAa,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,EAAE,OAAO,IAAI,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AACtE,OAAO,EAAE,OAAO,IAAI,uBAAuB,EAAE,MAAM,8BAA8B,CAAC"}
@@ -0,0 +1,33 @@
1
+ import type React from "react";
2
+ import type { Formatter } from "../formatter/types.js";
3
+ /**
4
+ * Prop and result types for the hooks in this folder.
5
+ *
6
+ * They live together rather than beside each hook so a hook's contract can be
7
+ * read without opening its implementation, and so a consumer typing a wrapper
8
+ * around one has a single import to reach for.
9
+ */
10
+ export type UseFormattedValueProps = {
11
+ /**
12
+ * The model/view pair driving the input. `format` renders the model for
13
+ * display, `parse` recovers the model from what the user typed.
14
+ */
15
+ formatter: Formatter;
16
+ /** The stored value — raw digits, for a phone number. */
17
+ model: string;
18
+ /** Called with the next model whenever the user edits the input. */
19
+ onModelChange: (next: string) => void;
20
+ };
21
+ export type UseFormattedValueResult = {
22
+ /** The formatted string to render as the input's `value`. */
23
+ value: string;
24
+ /** Change handler that keeps the model, the display, and the caret in step. */
25
+ onChange: (event: React.ChangeEvent<HTMLInputElement>) => void;
26
+ /** Suspends reformatting while an IME composition is in progress. */
27
+ onCompositionStart: () => void;
28
+ /** Resumes reformatting and commits the composed text. */
29
+ onCompositionEnd: (event: React.CompositionEvent<HTMLInputElement>) => void;
30
+ /** Must reach the input element — the caret cannot be placed without it. */
31
+ ref: React.RefObject<HTMLInputElement | null>;
32
+ };
33
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../../../src/lib/utils/hooks/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAC/B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAEvD;;;;;;GAMG;AAEH,MAAM,MAAM,sBAAsB,GAAG;IACnC;;;OAGG;IACH,SAAS,EAAE,SAAS,CAAC;IAErB,yDAAyD;IACzD,KAAK,EAAE,MAAM,CAAC;IAEd,oEAAoE;IACpE,aAAa,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,IAAI,CAAC;CACvC,CAAC;AAEF,MAAM,MAAM,uBAAuB,GAAG;IACpC,6DAA6D;IAC7D,KAAK,EAAE,MAAM,CAAC;IAEd,+EAA+E;IAC/E,QAAQ,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,WAAW,CAAC,gBAAgB,CAAC,KAAK,IAAI,CAAC;IAE/D,qEAAqE;IACrE,kBAAkB,EAAE,MAAM,IAAI,CAAC;IAE/B,0DAA0D;IAC1D,gBAAgB,EAAE,CAAC,KAAK,EAAE,KAAK,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,KAAK,IAAI,CAAC;IAE5E,4EAA4E;IAC5E,GAAG,EAAE,KAAK,CAAC,SAAS,CAAC,gBAAgB,GAAG,IAAI,CAAC,CAAC;CAC/C,CAAC"}
@@ -0,0 +1,30 @@
1
+ import type { UseFormattedValueProps, UseFormattedValueResult } from "./types.js";
2
+ /**
3
+ * Drive a text input whose displayed string is a formatted projection of the
4
+ * value it stores, without the caret jumping to the end on every keystroke.
5
+ *
6
+ * The naive spelling of this — `value={format(model)}` with an `onChange` that
7
+ * parses back — reformats the whole string on each edit, so React rewrites
8
+ * `input.value` and the browser drops the caret at the end. Editing anywhere but
9
+ * the end becomes impossible. This hook does the same projection but restores
10
+ * the caret afterwards, by position in the model rather than in the display.
11
+ *
12
+ * Composed text is rendered verbatim until `compositionend`, so an IME is never
13
+ * rewritten mid-composition.
14
+ *
15
+ * The value is owned by the caller: this hook never holds it in state, so it
16
+ * composes with react-hook-form, a `useState` above it, or any other source.
17
+ *
18
+ * The `formatter` must satisfy the contract on {@link Formatter} — in
19
+ * particular `parse(format(m)) === m`. A `parse` that truncates or is not a left
20
+ * inverse will strand the caret at the end and can make a deletion remove the
21
+ * wrong character.
22
+ *
23
+ * Only for inputs that support text selection. `setSelectionRange` throws on
24
+ * `type="number"` and `type="email"`.
25
+ *
26
+ * @note Impure — moves the caret on the element behind `ref`, which is the whole
27
+ * point of the hook and cannot be expressed as a return value.
28
+ */
29
+ export default function useFormattedValue({ formatter, model, onModelChange, }: UseFormattedValueProps): UseFormattedValueResult;
30
+ //# sourceMappingURL=useFormattedValue.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"useFormattedValue.d.ts","sourceRoot":"","sources":["../../../../../src/lib/utils/hooks/useFormattedValue.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EACV,sBAAsB,EACtB,uBAAuB,EACxB,MAAM,YAAY,CAAC;AA+IpB;;;;;;;;;;;;;;;;;;;;;;;;;;GA0BG;AACH,MAAM,CAAC,OAAO,UAAU,iBAAiB,CAAC,EACxC,SAAS,EACT,KAAK,EACL,aAAa,GACd,EAAE,sBAAsB,GAAG,uBAAuB,CAmFlD"}
@@ -1,3 +1,5 @@
1
+ export * from "./formatter/index.js";
1
2
  export * from "./hooks/index.js";
3
+ export { default as mergeRefs } from "./mergeRefs.js";
2
4
  export * from "./middleware/index.js";
3
5
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/index.ts"],"names":[],"mappings":"AAEA,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/index.ts"],"names":[],"mappings":"AAIA,cAAc,sBAAsB,CAAC;AACrC,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,gBAAgB,CAAC;AACtD,cAAc,uBAAuB,CAAC"}
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Fan one element out to several refs, so a component can keep its own internal
3
+ * ref while still honouring a forwarded one. Accepts both callback refs and ref
4
+ * objects, and ignores `undefined` entries, so an optional forwarded ref can be
5
+ * passed straight through.
6
+ *
7
+ * @example
8
+ * <input ref={mergeRefs(internalRef, forwardedRef)} />
9
+ *
10
+ * @note Pure — returns a new callback ref; the returned callback is impure by
11
+ * necessity, since assigning the element to each ref is its whole purpose.
12
+ */
13
+ export default function mergeRefs<T>(...refs: (React.Ref<T> | undefined)[]): (instance: T | null) => void;
14
+ //# sourceMappingURL=mergeRefs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mergeRefs.d.ts","sourceRoot":"","sources":["../../../../src/lib/utils/mergeRefs.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,OAAO,UAAU,SAAS,CAAC,CAAC,EACjC,GAAG,IAAI,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,SAAS,CAAC,EAAE,GACpC,CAAC,QAAQ,EAAE,CAAC,GAAG,IAAI,KAAK,IAAI,CAU9B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@canonical/react-ds-global-form",
3
- "version": "0.35.0",
3
+ "version": "0.37.0",
4
4
  "type": "module",
5
5
  "module": "dist/esm/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -43,10 +43,10 @@
43
43
  "test:vitest:watch": "vitest"
44
44
  },
45
45
  "dependencies": {
46
- "@canonical/react-ds-global": "^0.35.0",
47
- "@canonical/storybook-config": "^0.35.0",
48
- "@canonical/styles": "^0.35.0",
49
- "@canonical/utils": "^0.35.0",
46
+ "@canonical/react-ds-global": "^0.37.0",
47
+ "@canonical/storybook-config": "^0.37.0",
48
+ "@canonical/styles": "^0.37.0",
49
+ "@canonical/utils": "^0.37.0",
50
50
  "downshift": "^9.3.2",
51
51
  "react": "^19.2.4",
52
52
  "react-dom": "^19.2.4",
@@ -54,14 +54,14 @@
54
54
  },
55
55
  "devDependencies": {
56
56
  "@biomejs/biome": "2.4.9",
57
- "@canonical/biome-config": "^0.35.0",
57
+ "@canonical/biome-config": "^0.37.0",
58
58
  "@canonical/design-tokens": "0.8.1",
59
- "@canonical/storybook-addon-form-state": "^0.35.0",
60
- "@canonical/storybook-addon-msw": "^0.35.0",
61
- "@canonical/storybook-helpers": "^0.35.0",
62
- "@canonical/typescript-config-react": "^0.35.0",
63
- "@canonical/vitest-config-react": "^0.35.0",
64
- "@canonical/webarchitect": "^0.35.0",
59
+ "@canonical/storybook-addon-form-state": "^0.37.0",
60
+ "@canonical/storybook-addon-msw": "^0.37.0",
61
+ "@canonical/storybook-helpers": "^0.37.0",
62
+ "@canonical/typescript-config-react": "^0.37.0",
63
+ "@canonical/vitest-config-react": "^0.37.0",
64
+ "@canonical/webarchitect": "^0.37.0",
65
65
  "@chromatic-com/storybook": "^5.0.1",
66
66
  "@storybook/addon-docs": "^10.3.1",
67
67
  "@storybook/react-vite": "^10.3.1",
@@ -81,5 +81,5 @@
81
81
  "vite": "^8.0.1",
82
82
  "vitest": "^4.0.18"
83
83
  },
84
- "gitHead": "5198c5399ef657959272c0e35924391573d81146"
84
+ "gitHead": "ac8383bdb4be1bcd6fa6c4960a1e3d78c0279688"
85
85
  }
@@ -1,12 +0,0 @@
1
- const mergeRefs = (...refs) => (instance) => {
2
- for (const ref of refs) {
3
- if (typeof ref === "function") {
4
- ref(instance);
5
- }
6
- else if (ref) {
7
- ref.current = instance;
8
- }
9
- }
10
- };
11
- export default mergeRefs;
12
- //# sourceMappingURL=mergeRefs.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"mergeRefs.js","sourceRoot":"","sources":["../../../../../../src/lib/subcomponent/ComboboxInput/utils/mergeRefs.ts"],"names":[],"mappings":"AAAA,MAAM,SAAS,GACb,CAAI,GAAG,IAAkC,EAAE,EAAE,CAC7C,CAAC,QAAkB,EAAE,EAAE;IACrB,KAAK,MAAM,GAAG,IAAI,IAAI,EAAE,CAAC;QACvB,IAAI,OAAO,GAAG,KAAK,UAAU,EAAE,CAAC;YAC9B,GAAG,CAAC,QAAQ,CAAC,CAAC;QAChB,CAAC;aAAM,IAAI,GAAG,EAAE,CAAC;YACd,GAAiC,CAAC,OAAO,GAAG,QAAQ,CAAC;QACxD,CAAC;IACH,CAAC;AACH,CAAC,CAAC;AAEJ,eAAe,SAAS,CAAC"}
@@ -1,35 +0,0 @@
1
- /**
2
- * Apply a national-number display mask to a raw value (cosmetic only).
3
- *
4
- * The mask uses `#` as a digit slot; any other character is a literal separator
5
- * emitted between digits (e.g. `"(###) ###-####"`). Non-digits in `value` are
6
- * stripped first, so the result is purely a function of the typed digits. Extra
7
- * digits beyond the mask length are appended unformatted (so longer-than-typical
8
- * numbers are never truncated). With no mask, the raw digits are returned.
9
- *
10
- * This is display-only — callers keep the raw digits as the source of truth.
11
- * @note Pure.
12
- */
13
- export default function applyPhoneMask(value, format) {
14
- const digits = value.replace(/\D/g, "");
15
- if (!format)
16
- return digits;
17
- let out = "";
18
- let d = 0;
19
- for (const char of format) {
20
- if (d >= digits.length)
21
- break;
22
- if (char === "#") {
23
- out += digits[d];
24
- d += 1;
25
- }
26
- else {
27
- out += char;
28
- }
29
- }
30
- // Any digits beyond the mask's slots are appended raw (never dropped).
31
- if (d < digits.length)
32
- out += digits.slice(d);
33
- return out;
34
- }
35
- //# sourceMappingURL=applyPhoneMask.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"applyPhoneMask.js","sourceRoot":"","sources":["../../../../../src/lib/utils/countries/applyPhoneMask.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AACH,MAAM,CAAC,OAAO,UAAU,cAAc,CAAC,KAAa,EAAE,MAAe;IACnE,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACxC,IAAI,CAAC,MAAM;QAAE,OAAO,MAAM,CAAC;IAE3B,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,IAAI,CAAC,GAAG,CAAC,CAAC;IACV,KAAK,MAAM,IAAI,IAAI,MAAM,EAAE,CAAC;QAC1B,IAAI,CAAC,IAAI,MAAM,CAAC,MAAM;YAAE,MAAM;QAC9B,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;YACjB,GAAG,IAAI,MAAM,CAAC,CAAC,CAAC,CAAC;YACjB,CAAC,IAAI,CAAC,CAAC;QACT,CAAC;aAAM,CAAC;YACN,GAAG,IAAI,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IACD,uEAAuE;IACvE,IAAI,CAAC,GAAG,MAAM,CAAC,MAAM;QAAE,GAAG,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC;IAC9C,OAAO,GAAG,CAAC;AACb,CAAC"}