@canonical/react-ds-global-form 0.36.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.
- package/dist/esm/lib/index.js +2 -0
- package/dist/esm/lib/index.js.map +1 -1
- package/dist/esm/lib/subcomponent/ComboboxInput/SingleCombobox.js +2 -1
- package/dist/esm/lib/subcomponent/ComboboxInput/SingleCombobox.js.map +1 -1
- package/dist/esm/lib/subcomponent/ComboboxInput/common/List/List.js +1 -1
- package/dist/esm/lib/subcomponent/ComboboxInput/common/List/List.js.map +1 -1
- package/dist/esm/lib/subcomponent/ComboboxInput/utils/index.js +0 -1
- package/dist/esm/lib/subcomponent/ComboboxInput/utils/index.js.map +1 -1
- package/dist/esm/lib/subcomponent/PhoneInput/PhoneInput.js +44 -20
- package/dist/esm/lib/subcomponent/PhoneInput/PhoneInput.js.map +1 -1
- package/dist/esm/lib/utils/countries/index.js +3 -3
- package/dist/esm/lib/utils/countries/index.js.map +1 -1
- package/dist/esm/lib/utils/formatter/applyPattern.js +38 -0
- package/dist/esm/lib/utils/formatter/applyPattern.js.map +1 -0
- package/dist/esm/lib/utils/formatter/createFormatterRegisterOptions.js +22 -0
- package/dist/esm/lib/utils/formatter/createFormatterRegisterOptions.js.map +1 -0
- package/dist/esm/lib/utils/formatter/createPatternFormatter.js +25 -0
- package/dist/esm/lib/utils/formatter/createPatternFormatter.js.map +1 -0
- package/dist/esm/lib/utils/formatter/index.js +8 -0
- package/dist/esm/lib/utils/formatter/index.js.map +1 -0
- package/dist/esm/lib/utils/formatter/stripToDigits.js +12 -0
- package/dist/esm/lib/utils/formatter/stripToDigits.js.map +1 -0
- package/dist/esm/lib/utils/formatter/types.js +2 -0
- package/dist/esm/lib/utils/formatter/types.js.map +1 -0
- package/dist/esm/lib/utils/hooks/index.js +1 -0
- package/dist/esm/lib/utils/hooks/index.js.map +1 -1
- package/dist/esm/lib/utils/hooks/types.js +2 -0
- package/dist/esm/lib/utils/hooks/types.js.map +1 -0
- package/dist/esm/lib/utils/hooks/useFormattedValue.js +195 -0
- package/dist/esm/lib/utils/hooks/useFormattedValue.js.map +1 -0
- package/dist/esm/lib/utils/index.js +6 -2
- package/dist/esm/lib/utils/index.js.map +1 -1
- package/dist/esm/lib/utils/mergeRefs.js +25 -0
- package/dist/esm/lib/utils/mergeRefs.js.map +1 -0
- package/dist/types/lib/component/PhoneField/PhoneField.d.ts +2 -1
- package/dist/types/lib/component/PhoneField/PhoneField.d.ts.map +1 -1
- package/dist/types/lib/index.d.ts +4 -0
- package/dist/types/lib/index.d.ts.map +1 -1
- package/dist/types/lib/subcomponent/ComboboxInput/SingleCombobox.d.ts.map +1 -1
- package/dist/types/lib/subcomponent/ComboboxInput/utils/index.d.ts +0 -1
- package/dist/types/lib/subcomponent/ComboboxInput/utils/index.d.ts.map +1 -1
- package/dist/types/lib/subcomponent/PhoneInput/PhoneInput.d.ts +19 -2
- package/dist/types/lib/subcomponent/PhoneInput/PhoneInput.d.ts.map +1 -1
- package/dist/types/lib/subcomponent/PhoneInput/types.d.ts +20 -7
- package/dist/types/lib/subcomponent/PhoneInput/types.d.ts.map +1 -1
- package/dist/types/lib/utils/countries/index.d.ts +0 -3
- package/dist/types/lib/utils/countries/index.d.ts.map +1 -1
- package/dist/types/lib/utils/formatter/applyPattern.d.ts +17 -0
- package/dist/types/lib/utils/formatter/applyPattern.d.ts.map +1 -0
- package/dist/types/lib/utils/formatter/createFormatterRegisterOptions.d.ts +20 -0
- package/dist/types/lib/utils/formatter/createFormatterRegisterOptions.d.ts.map +1 -0
- package/dist/types/lib/utils/formatter/createPatternFormatter.d.ts +19 -0
- package/dist/types/lib/utils/formatter/createPatternFormatter.d.ts.map +1 -0
- package/dist/types/lib/utils/formatter/index.d.ts +6 -0
- package/dist/types/lib/utils/formatter/index.d.ts.map +1 -0
- package/dist/types/lib/utils/formatter/stripToDigits.d.ts +10 -0
- package/dist/types/lib/utils/formatter/stripToDigits.d.ts.map +1 -0
- package/dist/types/lib/utils/formatter/types.d.ts +30 -0
- package/dist/types/lib/utils/formatter/types.d.ts.map +1 -0
- package/dist/types/lib/utils/hooks/index.d.ts +2 -0
- package/dist/types/lib/utils/hooks/index.d.ts.map +1 -1
- package/dist/types/lib/utils/hooks/types.d.ts +33 -0
- package/dist/types/lib/utils/hooks/types.d.ts.map +1 -0
- package/dist/types/lib/utils/hooks/useFormattedValue.d.ts +30 -0
- package/dist/types/lib/utils/hooks/useFormattedValue.d.ts.map +1 -0
- package/dist/types/lib/utils/index.d.ts +2 -0
- package/dist/types/lib/utils/index.d.ts.map +1 -1
- package/dist/types/lib/utils/mergeRefs.d.ts +14 -0
- package/dist/types/lib/utils/mergeRefs.d.ts.map +1 -0
- package/package.json +13 -13
- package/dist/esm/lib/subcomponent/ComboboxInput/utils/mergeRefs.js +0 -12
- package/dist/esm/lib/subcomponent/ComboboxInput/utils/mergeRefs.js.map +0 -1
- package/dist/esm/lib/utils/countries/applyPhoneMask.js +0 -35
- package/dist/esm/lib/utils/countries/applyPhoneMask.js.map +0 -1
- package/dist/esm/lib/utils/countries/phoneRegisterOptions.js +0 -18
- package/dist/esm/lib/utils/countries/phoneRegisterOptions.js.map +0 -1
- package/dist/esm/lib/utils/countries/removePhoneMask.js +0 -12
- package/dist/esm/lib/utils/countries/removePhoneMask.js.map +0 -1
- package/dist/types/lib/subcomponent/ComboboxInput/utils/mergeRefs.d.ts +0 -3
- package/dist/types/lib/subcomponent/ComboboxInput/utils/mergeRefs.d.ts.map +0 -1
- package/dist/types/lib/utils/countries/applyPhoneMask.d.ts +0 -14
- package/dist/types/lib/utils/countries/applyPhoneMask.d.ts.map +0 -1
- package/dist/types/lib/utils/countries/phoneRegisterOptions.d.ts +0 -14
- package/dist/types/lib/utils/countries/phoneRegisterOptions.d.ts.map +0 -1
- package/dist/types/lib/utils/countries/removePhoneMask.d.ts +0 -10
- package/dist/types/lib/utils/countries/removePhoneMask.d.ts.map +0 -1
package/dist/esm/lib/index.js
CHANGED
|
@@ -4,5 +4,7 @@
|
|
|
4
4
|
// otherwise internal — composed by the Field pattern, not exported at the root.
|
|
5
5
|
export * from "./pattern/index.js";
|
|
6
6
|
export { RatingInput } from "./subcomponent/index.js";
|
|
7
|
+
export { applyPattern, createFormatterRegisterOptions, createPatternFormatter, stripToDigits, } from "./utils/formatter/index.js";
|
|
8
|
+
export { useFormattedValue } from "./utils/hooks/index.js";
|
|
7
9
|
export * from "./utils/middleware/index.js";
|
|
8
10
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/index.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,4EAA4E;AAC5E,+EAA+E;AAC/E,gFAAgF;AAChF,cAAc,oBAAoB,CAAC;AAUnC,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/lib/index.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,4EAA4E;AAC5E,+EAA+E;AAC/E,gFAAgF;AAChF,cAAc,oBAAoB,CAAC;AAUnC,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AAOtD,OAAO,EACL,YAAY,EACZ,8BAA8B,EAC9B,sBAAsB,EACtB,aAAa,GACd,MAAM,4BAA4B,CAAC;AAKpC,OAAO,EAAE,iBAAiB,EAAE,MAAM,wBAAwB,CAAC;AAC3D,cAAc,6BAA6B,CAAC"}
|
|
@@ -2,9 +2,10 @@ import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
|
2
2
|
/* @canonical/generator-ds 0.9.0-experimental.9 */
|
|
3
3
|
import { useCombobox } from "downshift";
|
|
4
4
|
import { forwardRef, useCallback, useEffect, useRef, useState } from "react";
|
|
5
|
+
import mergeRefs from "../../utils/mergeRefs.js";
|
|
5
6
|
import { List, ResetButton } from "./common/index.js";
|
|
6
7
|
import { VALUE_KEY } from "./constants.js";
|
|
7
|
-
import { convertItemToString as defaultConvertItemToString, convertValueToItem as defaultConvertValueToItem, filterItems as defaultFilterItems,
|
|
8
|
+
import { convertItemToString as defaultConvertItemToString, convertValueToItem as defaultConvertValueToItem, filterItems as defaultFilterItems, } from "./utils/index.js";
|
|
8
9
|
import "./styles.css";
|
|
9
10
|
const componentCssClassName = "ds form-combobox";
|
|
10
11
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SingleCombobox.js","sourceRoot":"","sources":["../../../../../src/lib/subcomponent/ComboboxInput/SingleCombobox.tsx"],"names":[],"mappings":";AAAA,kDAAkD;AAClD,OAAO,EAA+B,WAAW,EAAE,MAAM,WAAW,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"SingleCombobox.js","sourceRoot":"","sources":["../../../../../src/lib/subcomponent/ComboboxInput/SingleCombobox.tsx"],"names":[],"mappings":";AAAA,kDAAkD;AAClD,OAAO,EAA+B,WAAW,EAAE,MAAM,WAAW,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC7E,OAAO,SAAS,MAAM,0BAA0B,CAAC;AAEjD,OAAO,EAAE,IAAI,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAE3C,OAAO,EACL,mBAAmB,IAAI,0BAA0B,EACjD,kBAAkB,IAAI,yBAAyB,EAC/C,WAAW,IAAI,kBAAkB,GAClC,MAAM,kBAAkB,CAAC;AAC1B,OAAO,cAAc,CAAC;AACtB,MAAM,qBAAqB,GAAG,kBAAkB,CAAC;AAEjD;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,cAAc,GAAG,UAAU,CAC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AI,IACxC,EACN,KAAC,IAAI,IACH,MAAM,EAAE,MAAM,EACd,YAAY,EAAE,YAAY,EAC1B,YAAY,EAAE,YAAY,EAC1B,KAAK,EAAE,KAAK,EACZ,gBAAgB,EAAE,gBAAgB,EAClC,UAAU,EAAE,YAAY,EACxB,mBAAmB,EAAE,mBAAmB,EACxC,QAAQ,EAAE,QAAQ,GAClB,IACE,CACP,CAAC;AACJ,CAAC,CACF,CAAC;AAEF,eAAe,cAAc,CAAC"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
2
|
import { createElement as _createElement } from "react";
|
|
3
3
|
import { useEffect, useRef } from "react";
|
|
4
|
-
import mergeRefs from "
|
|
4
|
+
import mergeRefs from "../../../../utils/mergeRefs.js";
|
|
5
5
|
import "./styles.css";
|
|
6
6
|
const componentCssClassName = "ds combobox-list";
|
|
7
7
|
const List = ({ className, style, items, getMenuProps, getItemProps, highlightedIndex, convertItemToString, fieldValue, valueKey, isOpen, }) => {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"List.js","sourceRoot":"","sources":["../../../../../../../src/lib/subcomponent/ComboboxInput/common/List/List.tsx"],"names":[],"mappings":";;AACA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,SAAS,MAAM,
|
|
1
|
+
{"version":3,"file":"List.js","sourceRoot":"","sources":["../../../../../../../src/lib/subcomponent/ComboboxInput/common/List/List.tsx"],"names":[],"mappings":";;AACA,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAC1C,OAAO,SAAS,MAAM,gCAAgC,CAAC;AAEvD,OAAO,cAAc,CAAC;AAEtB,MAAM,qBAAqB,GAAG,kBAAkB,CAAC;AAEjD,MAAM,IAAI,GAAG,CAAC,EACZ,SAAS,EACT,KAAK,EACL,KAAK,EACL,YAAY,EACZ,YAAY,EACZ,gBAAgB,EAChB,m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AAU,CAAC,QAAQ,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC;gBACrD,CAAC;qBAAM,CAAC;oBACN,UAAU,GAAG,UAAU,KAAK,MAAM,CAAC,QAAQ,CAAC,CAAC;gBAC/C,CAAC;YACH,CAAC;YACD,OAAO,CACL,0BACM,YAAY,CAAC,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EACjC,SAAS,EAAE;oBACT,GAAG;oBACH,gBAAgB,KAAK,KAAK,IAAI,aAAa;oBAC3C,UAAU,IAAI,UAAU;iBACzB;qBACE,MAAM,CAAC,OAAO,CAAC;qBACf,IAAI,CAAC,GAAG,CAAC,EACZ,GAAG,EAAE,GAAG,IAEP,mBAAmB,CAAC,IAAI,CAAC,CACvB,CACN,CAAC;QACJ,CAAC,CAAC,GACC,CACN,CAAC;AACJ,CAAC,CAAC;AAEF,eAAe,IAAI,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.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","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
|
+
{"version":3,"file":"index.js","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,8 +1,23 @@
|
|
|
1
1
|
import { jsxs as _jsxs, jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { invariant } from "@canonical/utils";
|
|
3
|
+
import { forwardRef, useCallback, useMemo, useState } from "react";
|
|
4
|
+
import { countries as defaultCountries, } from "../../utils/countries/index.js";
|
|
5
|
+
import createPatternFormatter from "../../utils/formatter/createPatternFormatter.js";
|
|
6
|
+
import useFormattedValue from "../../utils/hooks/useFormattedValue.js";
|
|
7
|
+
import mergeRefs from "../../utils/mergeRefs.js";
|
|
4
8
|
import "./styles.css";
|
|
5
9
|
const componentCssClassName = "ds input phone chrome";
|
|
10
|
+
// Every country lookup falls back to the first entry, so an empty dataset has no
|
|
11
|
+
// country to render at all. Asserted rather than silently read out of bounds, so
|
|
12
|
+
// the cause is named instead of surfacing later as a missing dial code.
|
|
13
|
+
const EMPTY_COUNTRIES_MESSAGE = "PhoneInput requires a non-empty `countries` list.";
|
|
14
|
+
// Digits plus every separator the bundled masks actually use — space, parens,
|
|
15
|
+
// hyphen and the dot that `##.##.##` needs. The constraint applies to the string
|
|
16
|
+
// on screen, which carries those separators whenever `mask` is on, so a
|
|
17
|
+
// digits-only pattern would reject a correctly formatted number outright.
|
|
18
|
+
// Parens are escaped because `pattern` is compiled with the `v` flag first,
|
|
19
|
+
// where they are reserved inside a character class.
|
|
20
|
+
const ALLOWED_NUMBER_CHARACTERS = "[0-9+\\(\\)\\-\\.\\s]*";
|
|
6
21
|
/**
|
|
7
22
|
* Derive the emoji flag for an ISO 3166-1 alpha-2 code by mapping each of its
|
|
8
23
|
* two letters to its regional-indicator symbol (U+1F1E6–U+1F1FF). Non-alpha-2
|
|
@@ -10,20 +25,20 @@ const componentCssClassName = "ds input phone chrome";
|
|
|
10
25
|
* returned unchanged rather than mapped into unrelated code points.
|
|
11
26
|
* @note Pure.
|
|
12
27
|
*/
|
|
13
|
-
function
|
|
28
|
+
function buildFlagEmoji(code) {
|
|
14
29
|
const upper = code.toUpperCase();
|
|
15
30
|
if (!/^[A-Z]{2}$/.test(upper))
|
|
16
31
|
return code;
|
|
17
32
|
return upper.replace(/[A-Z]/g, (char) => String.fromCodePoint(127397 + char.charCodeAt(0)));
|
|
18
33
|
}
|
|
19
34
|
/** Numeric dial code (e.g. "+44" -> 44) for sorting. @note Pure. */
|
|
20
|
-
function
|
|
35
|
+
function getDialCodeValue(dialCode) {
|
|
21
36
|
return Number.parseInt(dialCode.replace(/\D/g, ""), 10);
|
|
22
37
|
}
|
|
23
38
|
/** The selector label for a country after its dial code. @note Pure. */
|
|
24
|
-
function
|
|
39
|
+
function getCountryLabel(country, display) {
|
|
25
40
|
if (display === "flag")
|
|
26
|
-
return
|
|
41
|
+
return buildFlagEmoji(country.code);
|
|
27
42
|
if (display === "name")
|
|
28
43
|
return country.name;
|
|
29
44
|
return country.code;
|
|
@@ -37,13 +52,16 @@ function countryLabel(country, display) {
|
|
|
37
52
|
* (an E.164 string or a structured `{ countryCode, number }` object). It
|
|
38
53
|
* defaults defensively, so an undefined initial `value` renders the
|
|
39
54
|
* `defaultCountry` with an empty number.
|
|
55
|
+
*
|
|
56
|
+
* The forwarded ref reaches the national-number input — the field's focusable
|
|
57
|
+
* element, and what react-hook-form needs for `setFocus` and focus-on-error.
|
|
40
58
|
* @returns {React.ReactElement} - Rendered Phone
|
|
41
59
|
*
|
|
42
60
|
* `import { PhoneInput } from "@canonical/react-ds-global-form";`
|
|
43
61
|
*
|
|
44
62
|
* @implements ds:global.subcomponent.phone_input
|
|
45
63
|
*/
|
|
46
|
-
export const PhoneInput = ({ id, className, style, value, onChange, defaultCountry = "US", preferredCountries = [], filteredCountries, countries = defaultCountries, valueFormat = "e164", countryDisplay = "code", mask = false, disabled = false, })
|
|
64
|
+
export const PhoneInput = forwardRef(function PhoneInput({ id, className, style, name, value, onChange, onBlur, defaultCountry = "US", preferredCountries = [], filteredCountries, countries = defaultCountries, valueFormat = "e164", countryDisplay = "code", mask = false, disabled = false, }, ref) {
|
|
47
65
|
const [selectedCountry, setSelectedCountry] = useState(() => {
|
|
48
66
|
if (valueFormat === "structured" && value && typeof value === "object") {
|
|
49
67
|
return value.countryCode || defaultCountry;
|
|
@@ -51,7 +69,7 @@ export const PhoneInput = ({ id, className, style, value, onChange, defaultCount
|
|
|
51
69
|
return defaultCountry;
|
|
52
70
|
});
|
|
53
71
|
const sortedCountries = useMemo(() => {
|
|
54
|
-
const byDialCode = (a, b) =>
|
|
72
|
+
const byDialCode = (a, b) => getDialCodeValue(a.dialCode) - getDialCodeValue(b.dialCode) ||
|
|
55
73
|
a.name.localeCompare(b.name);
|
|
56
74
|
// 1. `filteredCountries` (if given) restricts the visible universe to a
|
|
57
75
|
// whitelist, kept in the order the consumer listed it. Otherwise the
|
|
@@ -79,7 +97,11 @@ export const PhoneInput = ({ id, className, style, value, onChange, defaultCount
|
|
|
79
97
|
preferredCountries.indexOf(b.code));
|
|
80
98
|
return [...preferred, ...rest];
|
|
81
99
|
}, [preferredCountries, filteredCountries, countries]);
|
|
82
|
-
const currentCountryData = useMemo(() =>
|
|
100
|
+
const currentCountryData = useMemo(() => {
|
|
101
|
+
const country = countries.find((c) => c.code === selectedCountry) ?? countries.at(0);
|
|
102
|
+
invariant(country, EMPTY_COUNTRIES_MESSAGE);
|
|
103
|
+
return country;
|
|
104
|
+
}, [selectedCountry, countries]);
|
|
83
105
|
const getCurrentNumber = useCallback(() => {
|
|
84
106
|
if (valueFormat === "structured" && value && typeof value === "object") {
|
|
85
107
|
return value.number || "";
|
|
@@ -91,7 +113,8 @@ export const PhoneInput = ({ id, className, style, value, onChange, defaultCount
|
|
|
91
113
|
return typeof value === "string" ? value : "";
|
|
92
114
|
}, [value, valueFormat, currentCountryData]);
|
|
93
115
|
const emitValue = useCallback((countryCode, number) => {
|
|
94
|
-
const country = countries.find((c) => c.code === countryCode) ?? countries
|
|
116
|
+
const country = countries.find((c) => c.code === countryCode) ?? countries.at(0);
|
|
117
|
+
invariant(country, EMPTY_COUNTRIES_MESSAGE);
|
|
95
118
|
// The emitted national number is always raw digits — the mask is purely a
|
|
96
119
|
// display concern, never part of the submitted value.
|
|
97
120
|
const digits = number.replace(/\D/g, "");
|
|
@@ -107,15 +130,16 @@ export const PhoneInput = ({ id, className, style, value, onChange, defaultCount
|
|
|
107
130
|
setSelectedCountry(code);
|
|
108
131
|
emitValue(code, getCurrentNumber());
|
|
109
132
|
}, [emitValue, getCurrentNumber]);
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
:
|
|
118
|
-
|
|
119
|
-
};
|
|
133
|
+
// The national number is stored as digits and displayed grouped per the
|
|
134
|
+
// selected country when `mask` is on. With `mask` off the formatter still
|
|
135
|
+
// normalises to digits, so the two modes differ only in decoration.
|
|
136
|
+
const formatter = createPatternFormatter(mask ? currentCountryData.format : undefined);
|
|
137
|
+
const number = useFormattedValue({
|
|
138
|
+
formatter,
|
|
139
|
+
model: formatter.parse(getCurrentNumber()),
|
|
140
|
+
onModelChange: (digits) => emitValue(selectedCountry, digits),
|
|
141
|
+
});
|
|
142
|
+
return (_jsxs("div", { id: id, style: style, className: [componentCssClassName, className].filter(Boolean).join(" "), children: [_jsx("select", { className: "country-select p", value: selectedCountry, onChange: handleCountryChange, disabled: disabled, autoComplete: "tel-country-code", "aria-label": "Country code", children: sortedCountries.map((country) => (_jsxs("option", { value: country.code, children: [country.dialCode, " ", getCountryLabel(country, countryDisplay)] }, country.code))) }), _jsx("input", { type: "tel", className: "number-input p", name: name, inputMode: "tel", autoComplete: "tel-national", pattern: ALLOWED_NUMBER_CHARACTERS, title: "Digits, and the spacing characters used by the number's format.", value: number.value, onChange: number.onChange, onCompositionStart: number.onCompositionStart, onCompositionEnd: number.onCompositionEnd, onBlur: onBlur, ref: mergeRefs(number.ref, ref), disabled: disabled, "aria-label": "Phone number" })] }));
|
|
143
|
+
});
|
|
120
144
|
export default PhoneInput;
|
|
121
145
|
//# sourceMappingURL=PhoneInput.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"PhoneInput.js","sourceRoot":"","sources":["../../../../../src/lib/subcomponent/PhoneInput/PhoneInput.tsx"],"names":[],"mappings":";
|
|
1
|
+
{"version":3,"file":"PhoneInput.js","sourceRoot":"","sources":["../../../../../src/lib/subcomponent/PhoneInput/PhoneInput.tsx"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,kBAAkB,CAAC;AAE7C,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACnE,OAAO,EAEL,SAAS,IAAI,gBAAgB,GAE9B,MAAM,gCAAgC,CAAC;AACxC,OAAO,sBAAsB,MAAM,iDAAiD,CAAC;AACrF,OAAO,iBAAiB,MAAM,wCAAwC,CAAC;AACvE,OAAO,SAAS,MAAM,0BAA0B,CAAC;AAEjD,OAAO,cAAc,CAAC;AAEtB,MAAM,qBAAqB,GAAG,uBAAuB,CAAC;AAEtD,iFAAiF;AACjF,iFAAiF;AACjF,wEAAwE;AACxE,MAAM,uBAAuB,GAC3B,mDAAmD,CAAC;AAEtD,8EAA8E;AAC9E,iFAAiF;AACjF,wEAAwE;AACxE,0EAA0E;AAC1E,4EAA4E;AAC5E,oDAAoD;AACpD,MAAM,yBAAyB,GAAG,wBAAwB,CAAC;AAE3D;;;;;;GAMG;AACH,SAAS,cAAc,CAAC,IAAY;IAClC,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,EAAE,CAAC;IACjC,IAAI,CAAC,YAAY,CAAC,IAAI,CAAC,KAAK,CAAC;QAAE,OAAO,IAAI,CAAC;IA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6 @@
|
|
|
1
|
-
|
|
1
|
+
// The country dataset only. The display-mask helpers that used to live here are
|
|
2
|
+
// now the generic `utils/formatter` module — a phone pattern is one instance of
|
|
3
|
+
// the model/view split, not a phone-specific mechanism.
|
|
2
4
|
export { default as countries } from "./countries.js";
|
|
3
5
|
export { default as masks } from "./masks.js";
|
|
4
|
-
export { default as phoneRegisterOptions } from "./phoneRegisterOptions.js";
|
|
5
|
-
export { default as removePhoneMask } from "./removePhoneMask.js";
|
|
6
6
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/lib/utils/countries/index.ts"],"names":[],"mappings":"AAAA,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/lib/utils/countries/index.ts"],"names":[],"mappings":"AAAA,gFAAgF;AAChF,gFAAgF;AAChF,wDAAwD;AAExD,OAAO,EAAE,OAAO,IAAI,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAEtD,OAAO,EAAE,OAAO,IAAI,KAAK,EAAE,MAAM,YAAY,CAAC"}
|
|
@@ -0,0 +1,38 @@
|
|
|
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, pattern) {
|
|
17
|
+
const digits = value.replace(/\D/g, "");
|
|
18
|
+
if (!pattern)
|
|
19
|
+
return digits;
|
|
20
|
+
let out = "";
|
|
21
|
+
let taken = 0;
|
|
22
|
+
for (const char of pattern) {
|
|
23
|
+
if (taken >= digits.length)
|
|
24
|
+
break;
|
|
25
|
+
if (char === "#") {
|
|
26
|
+
// `slice` rather than an index: it yields a string, not a value the type
|
|
27
|
+
// system claims is always present (see cs:code.array.safe_access).
|
|
28
|
+
out += digits.slice(taken, taken + 1);
|
|
29
|
+
taken += 1;
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
out += char;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
// Any digits beyond the pattern's slots are appended raw (never dropped).
|
|
36
|
+
return out + digits.slice(taken);
|
|
37
|
+
}
|
|
38
|
+
//# sourceMappingURL=applyPattern.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"applyPattern.js","sourceRoot":"","sources":["../../../../../src/lib/utils/formatter/applyPattern.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,MAAM,CAAC,OAAO,UAAU,YAAY,CAAC,KAAa,EAAE,OAAgB;IAClE,MAAM,MAAM,GAAG,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;IACxC,IAAI,CAAC,OAAO;QAAE,OAAO,MAAM,CAAC;IAE5B,IAAI,GAAG,GAAG,EAAE,CAAC;IACb,IAAI,KAAK,GAAG,CAAC,CAAC;IACd,KAAK,MAAM,IAAI,IAAI,OAAO,EAAE,CAAC;QAC3B,IAAI,KAAK,IAAI,MAAM,CAAC,MAAM;YAAE,MAAM;QAClC,IAAI,IAAI,KAAK,GAAG,EAAE,CAAC;YACjB,yEAAyE;YACzE,mEAAmE;YACnE,GAAG,IAAI,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,CAAC,CAAC,CAAC;YACtC,KAAK,IAAI,CAAC,CAAC;QACb,CAAC;aAAM,CAAC;YACN,GAAG,IAAI,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IACD,0EAA0E;IAC1E,OAAO,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;AACnC,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Build react-hook-form `register()` options that normalise a formatted display
|
|
3
|
+
* value back to its model form, so the registered value is whatever the
|
|
4
|
+
* formatter's `parse` yields regardless of how the input is decorated on screen.
|
|
5
|
+
* Spread into `register(name, createFormatterRegisterOptions(formatter))`, or
|
|
6
|
+
* merge with your own rules.
|
|
7
|
+
*
|
|
8
|
+
* This covers the `register()` path only. react-hook-form does not apply
|
|
9
|
+
* `setValueAs` to a field bound with `useController`, so a controlled input must
|
|
10
|
+
* normalise in its own change handler instead — as PhoneInput does.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* <input {...register("phone", createFormatterRegisterOptions(formatter))} />
|
|
14
|
+
*
|
|
15
|
+
* @note Pure.
|
|
16
|
+
*/
|
|
17
|
+
export default function createFormatterRegisterOptions(formatter) {
|
|
18
|
+
return {
|
|
19
|
+
setValueAs: (value) => formatter.parse(String(value ?? "")),
|
|
20
|
+
};
|
|
21
|
+
}
|
|
22
|
+
//# sourceMappingURL=createFormatterRegisterOptions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createFormatterRegisterOptions.js","sourceRoot":"","sources":["../../../../../src/lib/utils/formatter/createFormatterRegisterOptions.ts"],"names":[],"mappings":"AAGA;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,OAAO,UAAU,8BAA8B,CACpD,SAAoB;IAEpB,OAAO;QACL,UAAU,EAAE,CAAC,KAAc,EAAE,EAAE,CAAC,SAAS,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC;KACrE,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import applyPattern from "./applyPattern.js";
|
|
2
|
+
import stripToDigits from "./stripToDigits.js";
|
|
3
|
+
/**
|
|
4
|
+
* Build a {@link Formatter} for a fixed digit-grouping pattern — the common
|
|
5
|
+
* case, where the separators sit at the same offsets whatever the value is.
|
|
6
|
+
*
|
|
7
|
+
* The pattern uses `#` as a digit slot and treats any other character as a
|
|
8
|
+
* literal separator, so `"(###) ###-####"` groups ten digits as
|
|
9
|
+
* `"(555) 123-4567"`. With no pattern the formatter still strips the value to
|
|
10
|
+
* digits, which is how a field expresses "normalise but do not decorate".
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* const formatter = createPatternFormatter("(###) ###-####");
|
|
14
|
+
* formatter.format("5551234567"); // "(555) 123-4567"
|
|
15
|
+
* formatter.parse("(555) 123-4567"); // "5551234567"
|
|
16
|
+
*
|
|
17
|
+
* @note Pure — the returned formatter's halves are pure too.
|
|
18
|
+
*/
|
|
19
|
+
export default function createPatternFormatter(pattern) {
|
|
20
|
+
return {
|
|
21
|
+
format: (model) => applyPattern(model, pattern),
|
|
22
|
+
parse: stripToDigits,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=createPatternFormatter.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"createPatternFormatter.js","sourceRoot":"","sources":["../../../../../src/lib/utils/formatter/createPatternFormatter.ts"],"names":[],"mappings":"AAAA,OAAO,YAAY,MAAM,mBAAmB,CAAC;AAC7C,OAAO,aAAa,MAAM,oBAAoB,CAAC;AAG/C;;;;;;;;;;;;;;;GAeG;AACH,MAAM,CAAC,OAAO,UAAU,sBAAsB,CAAC,OAAgB;IAC7D,OAAO;QACL,MAAM,EAAE,CAAC,KAAa,EAAE,EAAE,CAAC,YAAY,CAAC,KAAK,EAAE,OAAO,CAAC;QACvD,KAAK,EAAE,aAAa;KACrB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
// Value formatting: the model/view split shared by any input whose displayed
|
|
2
|
+
// string is not the string it submits. `Formatter` is the contract; the helpers
|
|
3
|
+
// below cover the fixed-pattern case.
|
|
4
|
+
export { default as applyPattern } from "./applyPattern.js";
|
|
5
|
+
export { default as createFormatterRegisterOptions } from "./createFormatterRegisterOptions.js";
|
|
6
|
+
export { default as createPatternFormatter } from "./createPatternFormatter.js";
|
|
7
|
+
export { default as stripToDigits } from "./stripToDigits.js";
|
|
8
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/lib/utils/formatter/index.ts"],"names":[],"mappings":"AAAA,6EAA6E;AAC7E,gFAAgF;AAChF,sCAAsC;AAEtC,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"}
|
|
@@ -0,0 +1,12 @@
|
|
|
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) {
|
|
10
|
+
return value.replace(/\D/g, "");
|
|
11
|
+
}
|
|
12
|
+
//# sourceMappingURL=stripToDigits.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stripToDigits.js","sourceRoot":"","sources":["../../../../../src/lib/utils/formatter/stripToDigits.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,CAAC,OAAO,UAAU,aAAa,CAAC,KAAa;IACjD,OAAO,KAAK,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC;AAClC,CAAC"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/lib/utils/formatter/types.ts"],"names":[],"mappings":""}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
export { default as useFieldAriaProperties } from "./useFieldAriaProperties.js";
|
|
2
2
|
export { default as useFieldError } from "./useFieldError.js";
|
|
3
|
+
export { default as useFormattedValue } from "./useFormattedValue.js";
|
|
3
4
|
export { default as useOptionAriaProperties } from "./useOptionAriaProperties.js";
|
|
4
5
|
//# sourceMappingURL=index.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/lib/utils/hooks/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../../src/lib/utils/hooks/index.ts"],"names":[],"mappings":"AAIA,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 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../../src/lib/utils/hooks/types.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import { useEffect, useLayoutEffect, useRef, useState } from "react";
|
|
2
|
+
// `useLayoutEffect` has no meaning on the server and React warns when it is
|
|
3
|
+
// called there. The caret work is inherently client-only, so fall back to
|
|
4
|
+
// `useEffect`, which never runs during `renderToString`.
|
|
5
|
+
const useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect;
|
|
6
|
+
/**
|
|
7
|
+
* Drop the model character at `index`.
|
|
8
|
+
*
|
|
9
|
+
* @note Pure.
|
|
10
|
+
*/
|
|
11
|
+
function removeModelCharAt(model, index) {
|
|
12
|
+
return model.slice(0, index) + model.slice(index + 1);
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* Classify an edit as an insertion or a deletion, and which way the deletion
|
|
16
|
+
* ran. Backspace and forward Delete over a separator produce an identical value
|
|
17
|
+
* and caret, so the event is the only thing that tells them apart.
|
|
18
|
+
*
|
|
19
|
+
* Falls back to backspace when `inputType` is absent — synthetic events dispatch
|
|
20
|
+
* a plain `Event`, and backspace is the only deletion worth assuming.
|
|
21
|
+
*
|
|
22
|
+
* @note Pure.
|
|
23
|
+
*/
|
|
24
|
+
function readEditIntent(event) {
|
|
25
|
+
const { inputType } = event.nativeEvent;
|
|
26
|
+
if (inputType === undefined)
|
|
27
|
+
return "deleteBackward";
|
|
28
|
+
if (inputType.includes("Forward"))
|
|
29
|
+
return "deleteForward";
|
|
30
|
+
if (inputType.startsWith("delete"))
|
|
31
|
+
return "deleteBackward";
|
|
32
|
+
return "insert";
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Find the offset in `view` with exactly `offset` model characters before it —
|
|
36
|
+
* where the caret belongs once the value has been reformatted.
|
|
37
|
+
*
|
|
38
|
+
* Display offsets cannot be carried across a reformat directly, because
|
|
39
|
+
* inserting one digit can move every separator after it. Counting model
|
|
40
|
+
* characters is stable under that: the user's caret is "after the 4th digit"
|
|
41
|
+
* whatever decoration surrounds it.
|
|
42
|
+
*
|
|
43
|
+
* @note Pure.
|
|
44
|
+
*/
|
|
45
|
+
function findCaretOffset(formatter, view, offset) {
|
|
46
|
+
let position = 0;
|
|
47
|
+
while (position < view.length &&
|
|
48
|
+
formatter.parse(view.slice(0, position)).length < offset) {
|
|
49
|
+
position += 1;
|
|
50
|
+
}
|
|
51
|
+
return position;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Work out which model an edit produces, and where the caret ends up in it.
|
|
55
|
+
*
|
|
56
|
+
* Deleting a separator is the case worth naming: it leaves the model untouched,
|
|
57
|
+
* so a reformat would put the character straight back and the keystroke would
|
|
58
|
+
* appear to do nothing. A model character is removed instead — the one behind
|
|
59
|
+
* the caret for a backspace, the one ahead of it for a forward delete.
|
|
60
|
+
*
|
|
61
|
+
* That substitution applies only when a deletion removed exactly one display
|
|
62
|
+
* character. A wider edit — a paste, or a range replaced with equivalent text —
|
|
63
|
+
* can legitimately produce the same model from a shorter string, and must not be
|
|
64
|
+
* read as "take a digit instead".
|
|
65
|
+
*
|
|
66
|
+
* @note Pure.
|
|
67
|
+
*/
|
|
68
|
+
function resolveEdit(formatter, model, view, caret, intent) {
|
|
69
|
+
const offset = formatter.parse(view.slice(0, caret)).length;
|
|
70
|
+
const parsed = formatter.parse(view);
|
|
71
|
+
const removedOneCharacter = view.length === formatter.format(model).length - 1;
|
|
72
|
+
if (parsed !== model || intent === "insert" || !removedOneCharacter) {
|
|
73
|
+
return { model: parsed, offset };
|
|
74
|
+
}
|
|
75
|
+
if (intent === "deleteForward") {
|
|
76
|
+
// The caret does not move: the character it was sitting in front of goes.
|
|
77
|
+
return offset < model.length
|
|
78
|
+
? { model: removeModelCharAt(model, offset), offset }
|
|
79
|
+
: { model, offset };
|
|
80
|
+
}
|
|
81
|
+
return offset > 0
|
|
82
|
+
? { model: removeModelCharAt(model, offset - 1), offset: offset - 1 }
|
|
83
|
+
: { model, offset };
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Put the formatted value back on an element after an edit that changed nothing.
|
|
87
|
+
*
|
|
88
|
+
* Typing a character the formatter discards leaves the model equal, so React
|
|
89
|
+
* re-renders nothing and the rejected text would otherwise sit in the DOM.
|
|
90
|
+
*
|
|
91
|
+
* @note Impure — writes the element's value and selection directly, because
|
|
92
|
+
* there is no render to hang the correction on.
|
|
93
|
+
*/
|
|
94
|
+
function restoreRejectedEdit(node, formatter, model, offset) {
|
|
95
|
+
const view = formatter.format(model);
|
|
96
|
+
node.value = view;
|
|
97
|
+
const position = findCaretOffset(formatter, view, offset);
|
|
98
|
+
node.setSelectionRange(position, position);
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Drive a text input whose displayed string is a formatted projection of the
|
|
102
|
+
* value it stores, without the caret jumping to the end on every keystroke.
|
|
103
|
+
*
|
|
104
|
+
* The naive spelling of this — `value={format(model)}` with an `onChange` that
|
|
105
|
+
* parses back — reformats the whole string on each edit, so React rewrites
|
|
106
|
+
* `input.value` and the browser drops the caret at the end. Editing anywhere but
|
|
107
|
+
* the end becomes impossible. This hook does the same projection but restores
|
|
108
|
+
* the caret afterwards, by position in the model rather than in the display.
|
|
109
|
+
*
|
|
110
|
+
* Composed text is rendered verbatim until `compositionend`, so an IME is never
|
|
111
|
+
* rewritten mid-composition.
|
|
112
|
+
*
|
|
113
|
+
* The value is owned by the caller: this hook never holds it in state, so it
|
|
114
|
+
* composes with react-hook-form, a `useState` above it, or any other source.
|
|
115
|
+
*
|
|
116
|
+
* The `formatter` must satisfy the contract on {@link Formatter} — in
|
|
117
|
+
* particular `parse(format(m)) === m`. A `parse` that truncates or is not a left
|
|
118
|
+
* inverse will strand the caret at the end and can make a deletion remove the
|
|
119
|
+
* wrong character.
|
|
120
|
+
*
|
|
121
|
+
* Only for inputs that support text selection. `setSelectionRange` throws on
|
|
122
|
+
* `type="number"` and `type="email"`.
|
|
123
|
+
*
|
|
124
|
+
* @note Impure — moves the caret on the element behind `ref`, which is the whole
|
|
125
|
+
* point of the hook and cannot be expressed as a return value.
|
|
126
|
+
*/
|
|
127
|
+
export default function useFormattedValue({ formatter, model, onModelChange, }) {
|
|
128
|
+
const ref = useRef(null);
|
|
129
|
+
// The caret to restore once the reformatted value has been committed, stamped
|
|
130
|
+
// with the view it belongs to so an unrelated commit cannot consume it.
|
|
131
|
+
const pending = useRef(null);
|
|
132
|
+
const composing = useRef(false);
|
|
133
|
+
// The raw text an IME is composing, rendered verbatim so the element is not
|
|
134
|
+
// rewritten mid-composition. Null whenever no composition is in progress.
|
|
135
|
+
const [composingView, setComposingView] = useState(null);
|
|
136
|
+
const commit = (next, offset) => {
|
|
137
|
+
pending.current = { offset, view: formatter.format(next) };
|
|
138
|
+
onModelChange(next);
|
|
139
|
+
};
|
|
140
|
+
const handleChange = (event) => {
|
|
141
|
+
const node = event.target;
|
|
142
|
+
// Mid-composition the text is provisional. Render it back exactly as typed:
|
|
143
|
+
// formatting it, or simply declining to emit, both let React restore the
|
|
144
|
+
// previous value underneath the IME and destroy the composition.
|
|
145
|
+
if (composing.current) {
|
|
146
|
+
setComposingView(node.value);
|
|
147
|
+
return;
|
|
148
|
+
}
|
|
149
|
+
const caret = node.selectionStart ?? node.value.length;
|
|
150
|
+
const edit = resolveEdit(formatter, model, node.value, caret, readEditIntent(event));
|
|
151
|
+
if (edit.model === model) {
|
|
152
|
+
restoreRejectedEdit(node, formatter, model, edit.offset);
|
|
153
|
+
return;
|
|
154
|
+
}
|
|
155
|
+
commit(edit.model, edit.offset);
|
|
156
|
+
};
|
|
157
|
+
const handleCompositionStart = () => {
|
|
158
|
+
composing.current = true;
|
|
159
|
+
};
|
|
160
|
+
const handleCompositionEnd = (event) => {
|
|
161
|
+
composing.current = false;
|
|
162
|
+
const node = event.currentTarget;
|
|
163
|
+
const composed = node.value;
|
|
164
|
+
const caret = node.selectionStart ?? composed.length;
|
|
165
|
+
setComposingView(null);
|
|
166
|
+
const parsed = formatter.parse(composed);
|
|
167
|
+
if (parsed === model)
|
|
168
|
+
return;
|
|
169
|
+
commit(parsed, formatter.parse(composed.slice(0, caret)).length);
|
|
170
|
+
};
|
|
171
|
+
// Runs after every commit, but acts only on the one this hook's own edit
|
|
172
|
+
// produced — matching the committed view against the caret's stamp. A render
|
|
173
|
+
// the user did not cause (an external `reset()`, say) never moves their cursor.
|
|
174
|
+
useIsomorphicLayoutEffect(() => {
|
|
175
|
+
const node = ref.current;
|
|
176
|
+
const target = pending.current;
|
|
177
|
+
if (node === null || target === null)
|
|
178
|
+
return;
|
|
179
|
+
if (node.value !== target.view)
|
|
180
|
+
return;
|
|
181
|
+
pending.current = null;
|
|
182
|
+
if (document.activeElement !== node)
|
|
183
|
+
return;
|
|
184
|
+
const position = findCaretOffset(formatter, node.value, target.offset);
|
|
185
|
+
node.setSelectionRange(position, position);
|
|
186
|
+
});
|
|
187
|
+
return {
|
|
188
|
+
value: composingView ?? formatter.format(model),
|
|
189
|
+
onChange: handleChange,
|
|
190
|
+
onCompositionStart: handleCompositionStart,
|
|
191
|
+
onCompositionEnd: handleCompositionEnd,
|
|
192
|
+
ref,
|
|
193
|
+
};
|
|
194
|
+
}
|
|
195
|
+
//# sourceMappingURL=useFormattedValue.js.map
|