@flipdish/ui-library 0.67.1 → 0.69.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/components/atoms/PhoneInput/hooks/usePhoneEntry.cjs +10 -4
- package/dist/components/atoms/PhoneInput/hooks/usePhoneEntry.cjs.map +1 -1
- package/dist/components/atoms/PhoneInput/hooks/usePhoneEntry.d.ts +3 -3
- package/dist/components/atoms/PhoneInput/hooks/usePhoneEntry.d.ts.map +1 -1
- package/dist/components/atoms/PhoneInput/hooks/usePhoneEntry.js +11 -5
- package/dist/components/atoms/PhoneInput/hooks/usePhoneEntry.js.map +1 -1
- package/dist/components/atoms/PhoneInput/utilities/phoneEntry.utils.cjs +13 -0
- package/dist/components/atoms/PhoneInput/utilities/phoneEntry.utils.cjs.map +1 -1
- package/dist/components/atoms/PhoneInput/utilities/phoneEntry.utils.d.ts +9 -0
- package/dist/components/atoms/PhoneInput/utilities/phoneEntry.utils.d.ts.map +1 -1
- package/dist/components/atoms/PhoneInput/utilities/phoneEntry.utils.js +14 -2
- package/dist/components/atoms/PhoneInput/utilities/phoneEntry.utils.js.map +1 -1
- package/dist/components/atoms/PhoneInput/utilities/phoneInput.utils.cjs +51 -16
- package/dist/components/atoms/PhoneInput/utilities/phoneInput.utils.cjs.map +1 -1
- package/dist/components/atoms/PhoneInput/utilities/phoneInput.utils.d.ts +19 -6
- package/dist/components/atoms/PhoneInput/utilities/phoneInput.utils.d.ts.map +1 -1
- package/dist/components/atoms/PhoneInput/utilities/phoneInput.utils.js +51 -17
- package/dist/components/atoms/PhoneInput/utilities/phoneInput.utils.js.map +1 -1
- package/dist/components/forms/Form/index.cjs +5 -3
- package/dist/components/forms/Form/index.cjs.map +1 -1
- package/dist/components/forms/Form/index.d.ts +8 -2
- package/dist/components/forms/Form/index.d.ts.map +1 -1
- package/dist/components/forms/Form/index.js +5 -3
- package/dist/components/forms/Form/index.js.map +1 -1
- package/dist/components/forms/Form/utilities/focusFromCode.utils.cjs +47 -0
- package/dist/components/forms/Form/utilities/focusFromCode.utils.cjs.map +1 -0
- package/dist/components/forms/Form/utilities/focusFromCode.utils.d.ts +12 -0
- package/dist/components/forms/Form/utilities/focusFromCode.utils.d.ts.map +1 -0
- package/dist/components/forms/Form/utilities/focusFromCode.utils.js +45 -0
- package/dist/components/forms/Form/utilities/focusFromCode.utils.js.map +1 -0
- package/dist/components/molecules/EmptyState/index.cjs +4 -2
- package/dist/components/molecules/EmptyState/index.cjs.map +1 -1
- package/dist/components/molecules/EmptyState/index.d.ts.map +1 -1
- package/dist/components/molecules/EmptyState/index.js +4 -2
- package/dist/components/molecules/EmptyState/index.js.map +1 -1
- package/dist/components/molecules/Pagination/index.d.ts +1 -1
- package/dist/components/molecules/Pagination/index.d.ts.map +1 -1
- package/dist/components/molecules/Paginations/Pagination/Pagination.cjs +21 -5
- package/dist/components/molecules/Paginations/Pagination/Pagination.cjs.map +1 -1
- package/dist/components/molecules/Paginations/Pagination/Pagination.d.ts +7 -1
- package/dist/components/molecules/Paginations/Pagination/Pagination.d.ts.map +1 -1
- package/dist/components/molecules/Paginations/Pagination/Pagination.js +22 -6
- package/dist/components/molecules/Paginations/Pagination/Pagination.js.map +1 -1
- package/dist/components/molecules/Paginations/components/PaginationBase.cjs +2 -2
- package/dist/components/molecules/Paginations/components/PaginationBase.cjs.map +1 -1
- package/dist/components/molecules/Paginations/components/PaginationBase.d.ts +4 -2
- package/dist/components/molecules/Paginations/components/PaginationBase.d.ts.map +1 -1
- package/dist/components/molecules/Paginations/components/PaginationBase.js +2 -2
- package/dist/components/molecules/Paginations/components/PaginationBase.js.map +1 -1
- package/dist/components/molecules/Paginations/utilities/paginationScroll.utils.cjs +125 -0
- package/dist/components/molecules/Paginations/utilities/paginationScroll.utils.cjs.map +1 -0
- package/dist/components/molecules/Paginations/utilities/paginationScroll.utils.d.ts +42 -0
- package/dist/components/molecules/Paginations/utilities/paginationScroll.utils.d.ts.map +1 -0
- package/dist/components/molecules/Paginations/utilities/paginationScroll.utils.js +118 -0
- package/dist/components/molecules/Paginations/utilities/paginationScroll.utils.js.map +1 -0
- package/dist/components/organisms/FilterBar/index.cjs +3 -1
- package/dist/components/organisms/FilterBar/index.cjs.map +1 -1
- package/dist/components/organisms/FilterBar/index.d.ts.map +1 -1
- package/dist/components/organisms/FilterBar/index.js +3 -1
- package/dist/components/organisms/FilterBar/index.js.map +1 -1
- package/dist/components/organisms/Table/components/TableCardList.cjs +27 -0
- package/dist/components/organisms/Table/components/TableCardList.cjs.map +1 -0
- package/dist/components/organisms/Table/components/TableCardList.d.ts +4 -0
- package/dist/components/organisms/Table/components/TableCardList.d.ts.map +1 -0
- package/dist/components/organisms/Table/components/TableCardList.js +25 -0
- package/dist/components/organisms/Table/components/TableCardList.js.map +1 -0
- package/dist/components/organisms/Table/components/TableCardRow.cjs +80 -0
- package/dist/components/organisms/Table/components/TableCardRow.cjs.map +1 -0
- package/dist/components/organisms/Table/components/TableCardRow.d.ts +4 -0
- package/dist/components/organisms/Table/components/TableCardRow.d.ts.map +1 -0
- package/dist/components/organisms/Table/components/TableCardRow.js +78 -0
- package/dist/components/organisms/Table/components/TableCardRow.js.map +1 -0
- package/dist/components/organisms/Table/components/TableCardsSelectAll.cjs +24 -0
- package/dist/components/organisms/Table/components/TableCardsSelectAll.cjs.map +1 -0
- package/dist/components/organisms/Table/components/TableCardsSelectAll.d.ts +13 -0
- package/dist/components/organisms/Table/components/TableCardsSelectAll.d.ts.map +1 -0
- package/dist/components/organisms/Table/components/TableCardsSelectAll.js +22 -0
- package/dist/components/organisms/Table/components/TableCardsSelectAll.js.map +1 -0
- package/dist/components/organisms/Table/components/TableFallbackCard.cjs +12 -0
- package/dist/components/organisms/Table/components/TableFallbackCard.cjs.map +1 -0
- package/dist/components/organisms/Table/components/TableFallbackCard.d.ts +6 -0
- package/dist/components/organisms/Table/components/TableFallbackCard.d.ts.map +1 -0
- package/dist/components/organisms/Table/components/TableFallbackCard.js +10 -0
- package/dist/components/organisms/Table/components/TableFallbackCard.js.map +1 -0
- package/dist/components/organisms/Table/components/TableFocusGuard.cjs +23 -0
- package/dist/components/organisms/Table/components/TableFocusGuard.cjs.map +1 -0
- package/dist/components/organisms/Table/components/TableFocusGuard.d.ts +2 -0
- package/dist/components/organisms/Table/components/TableFocusGuard.d.ts.map +1 -0
- package/dist/components/organisms/Table/components/TableFocusGuard.js +21 -0
- package/dist/components/organisms/Table/components/TableFocusGuard.js.map +1 -0
- package/dist/components/organisms/Table/components/TableLayoutToggle.cjs +27 -0
- package/dist/components/organisms/Table/components/TableLayoutToggle.cjs.map +1 -0
- package/dist/components/organisms/Table/components/TableLayoutToggle.d.ts +17 -0
- package/dist/components/organisms/Table/components/TableLayoutToggle.d.ts.map +1 -0
- package/dist/components/organisms/Table/components/TableLayoutToggle.js +25 -0
- package/dist/components/organisms/Table/components/TableLayoutToggle.js.map +1 -0
- package/dist/components/organisms/Table/components/TableRowCard.cjs +79 -0
- package/dist/components/organisms/Table/components/TableRowCard.cjs.map +1 -0
- package/dist/components/organisms/Table/components/TableRowCard.d.ts +71 -0
- package/dist/components/organisms/Table/components/TableRowCard.d.ts.map +1 -0
- package/dist/components/organisms/Table/components/TableRowCard.js +72 -0
- package/dist/components/organisms/Table/components/TableRowCard.js.map +1 -0
- package/dist/components/organisms/Table/components/TableSortMenu.cjs +48 -0
- package/dist/components/organisms/Table/components/TableSortMenu.cjs.map +1 -0
- package/dist/components/organisms/Table/components/TableSortMenu.d.ts +35 -0
- package/dist/components/organisms/Table/components/TableSortMenu.d.ts.map +1 -0
- package/dist/components/organisms/Table/components/TableSortMenu.js +46 -0
- package/dist/components/organisms/Table/components/TableSortMenu.js.map +1 -0
- package/dist/components/organisms/Table/hooks/useFirstSortDirection.cjs +25 -0
- package/dist/components/organisms/Table/hooks/useFirstSortDirection.cjs.map +1 -0
- package/dist/components/organisms/Table/hooks/useFirstSortDirection.d.ts +12 -0
- package/dist/components/organisms/Table/hooks/useFirstSortDirection.d.ts.map +1 -0
- package/dist/components/organisms/Table/hooks/useFirstSortDirection.js +23 -0
- package/dist/components/organisms/Table/hooks/useFirstSortDirection.js.map +1 -0
- package/dist/components/organisms/Table/hooks/useIsAtLeastMd.cjs +21 -0
- package/dist/components/organisms/Table/hooks/useIsAtLeastMd.cjs.map +1 -0
- package/dist/components/organisms/Table/hooks/useIsAtLeastMd.d.ts +9 -0
- package/dist/components/organisms/Table/hooks/useIsAtLeastMd.d.ts.map +1 -0
- package/dist/components/organisms/Table/hooks/useIsAtLeastMd.js +19 -0
- package/dist/components/organisms/Table/hooks/useIsAtLeastMd.js.map +1 -0
- package/dist/components/organisms/Table/hooks/usePlaceholderRows.cjs +43 -0
- package/dist/components/organisms/Table/hooks/usePlaceholderRows.cjs.map +1 -0
- package/dist/components/organisms/Table/hooks/usePlaceholderRows.d.ts +23 -0
- package/dist/components/organisms/Table/hooks/usePlaceholderRows.d.ts.map +1 -0
- package/dist/components/organisms/Table/hooks/usePlaceholderRows.js +40 -0
- package/dist/components/organisms/Table/hooks/usePlaceholderRows.js.map +1 -0
- package/dist/components/organisms/Table/hooks/useSelectableRowRegistry.cjs +20 -2
- package/dist/components/organisms/Table/hooks/useSelectableRowRegistry.cjs.map +1 -1
- package/dist/components/organisms/Table/hooks/useSelectableRowRegistry.d.ts +8 -4
- package/dist/components/organisms/Table/hooks/useSelectableRowRegistry.d.ts.map +1 -1
- package/dist/components/organisms/Table/hooks/useSelectableRowRegistry.js +21 -3
- package/dist/components/organisms/Table/hooks/useSelectableRowRegistry.js.map +1 -1
- package/dist/components/organisms/Table/hooks/useTableSelection.cjs +47 -0
- package/dist/components/organisms/Table/hooks/useTableSelection.cjs.map +1 -0
- package/dist/components/organisms/Table/hooks/useTableSelection.d.ts +31 -0
- package/dist/components/organisms/Table/hooks/useTableSelection.d.ts.map +1 -0
- package/dist/components/organisms/Table/hooks/useTableSelection.js +45 -0
- package/dist/components/organisms/Table/hooks/useTableSelection.js.map +1 -0
- package/dist/components/organisms/Table/index.cjs +169 -38
- package/dist/components/organisms/Table/index.cjs.map +1 -1
- package/dist/components/organisms/Table/index.d.ts +57 -20
- package/dist/components/organisms/Table/index.d.ts.map +1 -1
- package/dist/components/organisms/Table/index.js +162 -33
- package/dist/components/organisms/Table/index.js.map +1 -1
- package/dist/components/organisms/Table/providers/Table.context.cjs +19 -0
- package/dist/components/organisms/Table/providers/Table.context.cjs.map +1 -0
- package/dist/components/organisms/Table/providers/Table.context.d.ts +44 -0
- package/dist/components/organisms/Table/providers/Table.context.d.ts.map +1 -0
- package/dist/components/organisms/Table/providers/Table.context.js +13 -0
- package/dist/components/organisms/Table/providers/Table.context.js.map +1 -0
- package/dist/components/organisms/Table/table.types.d.ts +35 -0
- package/dist/components/organisms/Table/table.types.d.ts.map +1 -0
- package/dist/components/organisms/Table/utilities/tableCard.utils.cjs +197 -0
- package/dist/components/organisms/Table/utilities/tableCard.utils.cjs.map +1 -0
- package/dist/components/organisms/Table/utilities/tableCard.utils.d.ts +161 -0
- package/dist/components/organisms/Table/utilities/tableCard.utils.d.ts.map +1 -0
- package/dist/components/organisms/Table/utilities/tableCard.utils.js +180 -0
- package/dist/components/organisms/Table/utilities/tableCard.utils.js.map +1 -0
- package/dist/components/organisms/Table/utilities/tableChildren.utils.cjs +47 -0
- package/dist/components/organisms/Table/utilities/tableChildren.utils.cjs.map +1 -0
- package/dist/components/organisms/Table/utilities/tableChildren.utils.d.ts +39 -0
- package/dist/components/organisms/Table/utilities/tableChildren.utils.d.ts.map +1 -0
- package/dist/components/organisms/Table/utilities/tableChildren.utils.js +43 -0
- package/dist/components/organisms/Table/utilities/tableChildren.utils.js.map +1 -0
- package/dist/components/organisms/Table/utilities/tableSelection.utils.cjs +106 -0
- package/dist/components/organisms/Table/utilities/tableSelection.utils.cjs.map +1 -0
- package/dist/components/organisms/Table/utilities/tableSelection.utils.d.ts +82 -0
- package/dist/components/organisms/Table/utilities/tableSelection.utils.d.ts.map +1 -0
- package/dist/components/organisms/Table/utilities/tableSelection.utils.js +98 -0
- package/dist/components/organisms/Table/utilities/tableSelection.utils.js.map +1 -0
- package/dist/components/organisms/Table/utilities/tableSort.utils.cjs +87 -0
- package/dist/components/organisms/Table/utilities/tableSort.utils.cjs.map +1 -0
- package/dist/components/organisms/Table/utilities/tableSort.utils.d.ts +67 -0
- package/dist/components/organisms/Table/utilities/tableSort.utils.d.ts.map +1 -0
- package/dist/components/organisms/Table/utilities/tableSort.utils.js +79 -0
- package/dist/components/organisms/Table/utilities/tableSort.utils.js.map +1 -0
- package/dist/hooks/__internal__/useReturnFocus/useReturnFocus.cjs +2 -2
- package/dist/hooks/__internal__/useReturnFocus/useReturnFocus.d.ts +2 -2
- package/dist/hooks/__internal__/useReturnFocus/useReturnFocus.js +2 -2
- package/dist/hooks/useFocusAfterRetry/index.cjs +1 -1
- package/dist/hooks/useFocusAfterRetry/index.d.ts +1 -1
- package/dist/hooks/useFocusAfterRetry/index.js +1 -1
- package/dist/utilities/searchParamsUtils/index.cjs +2 -9
- package/dist/utilities/searchParamsUtils/index.cjs.map +1 -1
- package/dist/utilities/searchParamsUtils/index.d.ts +5 -3
- package/dist/utilities/searchParamsUtils/index.d.ts.map +1 -1
- package/dist/utilities/searchParamsUtils/index.js +2 -9
- package/dist/utilities/searchParamsUtils/index.js.map +1 -1
- package/package.json +2 -2
- package/dist/components/organisms/Table/table.utils.cjs +0 -61
- package/dist/components/organisms/Table/table.utils.cjs.map +0 -1
- package/dist/components/organisms/Table/table.utils.d.ts +0 -48
- package/dist/components/organisms/Table/table.utils.d.ts.map +0 -1
- package/dist/components/organisms/Table/table.utils.js +0 -55
- package/dist/components/organisms/Table/table.utils.js.map +0 -1
|
@@ -12,9 +12,9 @@ var phoneInput_utils = require('../utilities/phoneInput.utils.cjs');
|
|
|
12
12
|
*
|
|
13
13
|
* @param options The field's value, its change handler, the country to start on and any limit on the countries offered.
|
|
14
14
|
* @returns The `country` and `text` to show, the international `value`, `type` to apply an edit to the text, which
|
|
15
|
-
* gives back where the cursor belongs, `chooseCountry` to switch country and keep the digits, `settle` to
|
|
16
|
-
* calling code left half typed when the user leaves the field, and `reset`
|
|
17
|
-
* field started with, as a form reset does.
|
|
15
|
+
* gives back where the cursor belongs, `chooseCountry` to switch country and keep the digits, `settle` to write the
|
|
16
|
+
* number as a saved one shows and drop a calling code left half typed when the user leaves the field, and `reset`
|
|
17
|
+
* to return to the number and country the field started with, as a form reset does.
|
|
18
18
|
*/
|
|
19
19
|
const usePhoneEntry = ({ value: valueProp, defaultValue, onChange, defaultCountry, allowed }) => {
|
|
20
20
|
const [value, setValue] = utils.useControlledState(valueProp, defaultValue ?? '', onChange);
|
|
@@ -64,8 +64,14 @@ const usePhoneEntry = ({ value: valueProp, defaultValue, onChange, defaultCountr
|
|
|
64
64
|
show({ country, text: phoneInput_utils.formatTyped(country, digits) });
|
|
65
65
|
};
|
|
66
66
|
const settle = () => {
|
|
67
|
-
|
|
67
|
+
// A report the owner has yet to hand back is what the field shows once it does, so it is settled as well.
|
|
68
|
+
if (reported)
|
|
69
|
+
setReported(phoneEntry_utils.settledEntry(reported));
|
|
70
|
+
if (shown.isPending) {
|
|
68
71
|
setStored(phoneEntry_utils.entryOf(value, shown.country, allowed));
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
setStored(phoneEntry_utils.settledEntry(shown));
|
|
69
75
|
};
|
|
70
76
|
const reset = () => {
|
|
71
77
|
const initial = defaultValue ?? initialValue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePhoneEntry.cjs","sources":["../../../../../src/components/atoms/PhoneInput/hooks/usePhoneEntry.ts"],"sourcesContent":[null],"names":["useControlledState","useState","entryOf","reconcilePhoneEntry","toInternational","editedDigits","entryFor","caretAfter","significantChars","nationalDigits","formatTyped"],"mappings":";;;;;;;AA4BA;;;;;;;;;;AAUG;AACI,MAAM,aAAa,GAAG,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,QAAQ,EAAE,cAAc,EAAE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,aAAa,CAAC,GAAG,KAAK;AACpE,QAAA,IAAI,CAAC,EAAE,OAAO,EAAE,IAAI,EAAEC,4BAAW,CAAC,OAAO,EAAE,MAAM,CAAC,EAAE,CAAC;AACvD,IAAA,CAAC;IAED,MAAM,MAAM,GAAG,MAAK;
|
|
1
|
+
{"version":3,"file":"usePhoneEntry.cjs","sources":["../../../../../src/components/atoms/PhoneInput/hooks/usePhoneEntry.ts"],"sourcesContent":[null],"names":["useControlledState","useState","entryOf","reconcilePhoneEntry","toInternational","editedDigits","entryFor","caretAfter","significantChars","nationalDigits","formatTyped","settledEntry"],"mappings":";;;;;;;AA4BA;;;;;;;;;;AAUG;AACI,MAAM,aAAa,GAAG,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,YAAY,EAAE,QAAQ,EAAE,cAAc,EAAE,OAAO,EAAqB,KAAI;AACxH,IAAA,MAAM,CAAC,KAAK,EAAE,QAAQ,CAAC,GAAGA,wBAAkB,CAAC,SAAS,EAAE,YAAY,IAAI,EAAE,EAAE,QAAQ,CAAC;;IAErF,MAAM,CAAC,YAAY,CAAC,GAAGC,cAAQ,CAAC,KAAK,CAAC;IACtC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,GAAGA,cAAQ,CAAa,MAAMC,wBAAO,CAAC,KAAK,EAAE,cAAc,EAAE,OAAO,CAAC,CAAC;;IAE/F,MAAM,CAAC,QAAQ,EAAE,WAAW,CAAC,GAAGD,cAAQ,EAAiB;;AAEzD,IAAA,MAAM,CAAC,gBAAgB,EAAE,mBAAmB,CAAC,GAAGA,cAAQ,CAAC,KAAK,KAAK,EAAE,CAAC;AAEtE,IAAA,MAAM,UAAU,GAAGE,oCAAmB,CAAC,EAAE,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,gBAAgB,EAAE,cAAc,EAAE,OAAO,EAAE,CAAC;AAC9G,IAAA,IAAI,UAAU,CAAC,QAAQ,KAAK,QAAQ;AAAE,QAAA,WAAW,CAAC,UAAU,CAAC,QAAQ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K,CAAC;QAChB,QAAQ,CAAC,OAAO,CAAC;AACjB,QAAA,mBAAmB,CAAC,OAAO,KAAK,EAAE,CAAC;AACrC,IAAA,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,KAAK,EAAE;AAChG;;"}
|
|
@@ -19,9 +19,9 @@ export interface PhoneEntryOptions {
|
|
|
19
19
|
*
|
|
20
20
|
* @param options The field's value, its change handler, the country to start on and any limit on the countries offered.
|
|
21
21
|
* @returns The `country` and `text` to show, the international `value`, `type` to apply an edit to the text, which
|
|
22
|
-
* gives back where the cursor belongs, `chooseCountry` to switch country and keep the digits, `settle` to
|
|
23
|
-
* calling code left half typed when the user leaves the field, and `reset`
|
|
24
|
-
* field started with, as a form reset does.
|
|
22
|
+
* gives back where the cursor belongs, `chooseCountry` to switch country and keep the digits, `settle` to write the
|
|
23
|
+
* number as a saved one shows and drop a calling code left half typed when the user leaves the field, and `reset`
|
|
24
|
+
* to return to the number and country the field started with, as a form reset does.
|
|
25
25
|
*/
|
|
26
26
|
export declare const usePhoneEntry: ({ value: valueProp, defaultValue, onChange, defaultCountry, allowed }: PhoneEntryOptions) => {
|
|
27
27
|
country: import("libphonenumber-js/min").CountryCode;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePhoneEntry.d.ts","sourceRoot":"","sources":["../../../../../src/components/atoms/PhoneInput/hooks/usePhoneEntry.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAc,MAAM,qBAAqB,CAAC;AAExE,OAAO,EAML,KAAK,SAAS,EAGf,MAAM,+BAA+B,CAAC;AAEvC,MAAM,WAAW,iBAAiB;IAChC,8DAA8D;IAC9D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,sEAAsE;IACtE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,qIAAqI;IACrI,cAAc,EAAE,gBAAgB,CAAC;IACjC,mEAAmE;IACnE,OAAO,CAAC,EAAE,SAAS,gBAAgB,EAAE,CAAC;CACvC;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa,GAAI,uEAAuE,iBAAiB;;;;iBAuBhG,SAAS,KAAG,MAAM;6BAaN,gBAAgB;;;
|
|
1
|
+
{"version":3,"file":"usePhoneEntry.d.ts","sourceRoot":"","sources":["../../../../../src/components/atoms/PhoneInput/hooks/usePhoneEntry.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,gBAAgB,EAAc,MAAM,qBAAqB,CAAC;AAExE,OAAO,EAML,KAAK,SAAS,EAGf,MAAM,+BAA+B,CAAC;AAEvC,MAAM,WAAW,iBAAiB;IAChC,8DAA8D;IAC9D,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,sEAAsE;IACtE,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,0DAA0D;IAC1D,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,qIAAqI;IACrI,cAAc,EAAE,gBAAgB,CAAC;IACjC,mEAAmE;IACnE,OAAO,CAAC,EAAE,SAAS,gBAAgB,EAAE,CAAC;CACvC;AAED;;;;;;;;;;GAUG;AACH,eAAO,MAAM,aAAa,GAAI,uEAAuE,iBAAiB;;;;iBAuBhG,SAAS,KAAG,MAAM;6BAaN,gBAAgB;;;CAgCjD,CAAC"}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { useControlledState } from '@react-stately/utils';
|
|
2
2
|
import { useState } from 'react';
|
|
3
|
-
import { entryOf, reconcilePhoneEntry } from '../utilities/phoneEntry.utils.js';
|
|
3
|
+
import { entryOf, reconcilePhoneEntry, settledEntry } from '../utilities/phoneEntry.utils.js';
|
|
4
4
|
import { significantChars, toInternational, nationalDigits, formatTyped, editedDigits, entryFor, caretAfter } from '../utilities/phoneInput.utils.js';
|
|
5
5
|
|
|
6
6
|
/**
|
|
@@ -10,9 +10,9 @@ import { significantChars, toInternational, nationalDigits, formatTyped, editedD
|
|
|
10
10
|
*
|
|
11
11
|
* @param options The field's value, its change handler, the country to start on and any limit on the countries offered.
|
|
12
12
|
* @returns The `country` and `text` to show, the international `value`, `type` to apply an edit to the text, which
|
|
13
|
-
* gives back where the cursor belongs, `chooseCountry` to switch country and keep the digits, `settle` to
|
|
14
|
-
* calling code left half typed when the user leaves the field, and `reset`
|
|
15
|
-
* field started with, as a form reset does.
|
|
13
|
+
* gives back where the cursor belongs, `chooseCountry` to switch country and keep the digits, `settle` to write the
|
|
14
|
+
* number as a saved one shows and drop a calling code left half typed when the user leaves the field, and `reset`
|
|
15
|
+
* to return to the number and country the field started with, as a form reset does.
|
|
16
16
|
*/
|
|
17
17
|
const usePhoneEntry = ({ value: valueProp, defaultValue, onChange, defaultCountry, allowed }) => {
|
|
18
18
|
const [value, setValue] = useControlledState(valueProp, defaultValue ?? '', onChange);
|
|
@@ -62,8 +62,14 @@ const usePhoneEntry = ({ value: valueProp, defaultValue, onChange, defaultCountr
|
|
|
62
62
|
show({ country, text: formatTyped(country, digits) });
|
|
63
63
|
};
|
|
64
64
|
const settle = () => {
|
|
65
|
-
|
|
65
|
+
// A report the owner has yet to hand back is what the field shows once it does, so it is settled as well.
|
|
66
|
+
if (reported)
|
|
67
|
+
setReported(settledEntry(reported));
|
|
68
|
+
if (shown.isPending) {
|
|
66
69
|
setStored(entryOf(value, shown.country, allowed));
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
setStored(settledEntry(shown));
|
|
67
73
|
};
|
|
68
74
|
const reset = () => {
|
|
69
75
|
const initial = defaultValue ?? initialValue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"usePhoneEntry.js","sources":["../../../../../src/components/atoms/PhoneInput/hooks/usePh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AAK,CAAC;QAChB,QAAQ,CAAC,OAAO,CAAC;AACjB,QAAA,mBAAmB,CAAC,OAAO,KAAK,EAAE,CAAC;AACrC,IAAA,CAAC;IAED,OAAO,EAAE,OAAO,EAAE,KAAK,CAAC,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,KAAK,EAAE;AAChG;;"}
|
|
@@ -15,6 +15,18 @@ const entryOf = (value, country, allowed) => {
|
|
|
15
15
|
const entry = phoneInput_utils.fromInternational(value, country, allowed) ?? { country, text: phoneInput_utils.formatTyped(country, phoneInput_utils.significantChars(value)) || value };
|
|
16
16
|
return { ...entry, value };
|
|
17
17
|
};
|
|
18
|
+
/**
|
|
19
|
+
* Writes an entry's number as a saved one shows, for when the user leaves the field, so a trunk prefix typed out of habit
|
|
20
|
+
* does not stay beside the calling code.
|
|
21
|
+
*
|
|
22
|
+
* @param entry The entry on screen, or one reported to an owner that has yet to hand its value back.
|
|
23
|
+
* @returns The entry with its text rewritten, in the country it had. The same object when the text already reads that
|
|
24
|
+
* way, or when the value is not a number of that country.
|
|
25
|
+
*/
|
|
26
|
+
const settledEntry = (entry) => {
|
|
27
|
+
const text = phoneInput_utils.settledText(entry.value, entry.country);
|
|
28
|
+
return text === undefined || text === entry.text ? entry : { ...entry, text };
|
|
29
|
+
};
|
|
18
30
|
const shownFor = (value, stored, reported, allowed) => {
|
|
19
31
|
if (stored.value === value)
|
|
20
32
|
return stored;
|
|
@@ -52,4 +64,5 @@ const reconcilePhoneEntry = ({ value, stored, reported, isCountrySettled, defaul
|
|
|
52
64
|
|
|
53
65
|
exports.entryOf = entryOf;
|
|
54
66
|
exports.reconcilePhoneEntry = reconcilePhoneEntry;
|
|
67
|
+
exports.settledEntry = settledEntry;
|
|
55
68
|
//# sourceMappingURL=phoneEntry.utils.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"phoneEntry.utils.cjs","sources":["../../../../../src/components/atoms/PhoneInput/utilities/phoneEntry.utils.ts"],"sourcesContent":[null],"names":["fromInternational","formatTyped","significantChars"],"mappings":";;;;AA2CA;;;;;;;AAOG;AACI,MAAM,OAAO,GAAG,CAAC,KAAa,EAAE,OAAyB,EAAE,OAAqC,KAAgB;;AAErH,IAAA,MAAM,KAAK,GAAGA,kCAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAEC,4BAAW,CAAC,OAAO,EAAEC,iCAAgB,CAAC,KAAK,CAAC,CAAC,IAAI,KAAK,EAAE;AACrI,IAAA,OAAO,EAAE,GAAG,KAAK,EAAE,KAAK,EAAE;AAC5B;AAEA,MAAM,QAAQ,GAAG,CAAC,KAAa,EAAE,MAAkB,EAAE,QAAmC,EAAE,OAAqC,KAAgB;AAC7I,IAAA,IAAI,MAAM,CAAC,KAAK,KAAK,KAAK;AAAE,QAAA,OAAO,MAAM;AACzC,IAAA,IAAI,QAAQ,EAAE,KAAK,KAAK,KAAK;AAAE,QAAA,OAAO,QAAQ;IAC9C,OAAO,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC;AAChD,CAAC;AAED;;;;;;;AAOG;AACI,MAAM,mBAAmB,GAAG,CAAC,EAClC,KAAK,EACL,MAAM,EACN,QAAQ,EACR,gBAAgB,EAChB,cAAc,EACd,OAAO,GACY,KAA0B;AAC7C,IAAA,IAAI,KAAK,GAAG,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAC;;AAEtD,IAAA,MAAM,cAAc,GAAG,KAAK,KAAK,QAAQ,EAAE,KAAK;;IAEhD,MAAM,UAAU,GAAG,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,QAAQ,EAAE,IAAI;IAC/D,IAAI,YAAY,GAAG,QAAQ;AAC3B,IAAA,IAAI,QAAQ,KAAK,cAAc,IAAI,UAAU,CAAC;QAAE,YAAY,GAAG,SAAS;;IAExE,IAAI,WAAW,GAAG,gBAAgB;AAClC,IAAA,IAAI,CAAC,gBAAgB,IAAI,KAAK,CAAC,KAAK,KAAK,EAAE,IAAI,KAAK,KAAK,QAAQ,EAAE,IAAI;QAAE,WAAW,GAAG,IAAI;;IAE3F,IAAI,CAAC,gBAAgB,IAAI,KAAK,CAAC,IAAI,KAAK,EAAE,IAAI,KAAK,CAAC,KAAK,KAAK,EAAE,IAAI,KAAK,CAAC,OAAO,KAAK,cAAc,EAAE;QACpG,KAAK,GAAG,EAAE,GAAG,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE;IAC/C;AAEA,IAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,gBAAgB,EAAE,WAAW,EAAE;AACxF
|
|
1
|
+
{"version":3,"file":"phoneEntry.utils.cjs","sources":["../../../../../src/components/atoms/PhoneInput/utilities/phoneEntry.utils.ts"],"sourcesContent":[null],"names":["fromInternational","formatTyped","significantChars","settledText"],"mappings":";;;;AA2CA;;;;;;;AAOG;AACI,MAAM,OAAO,GAAG,CAAC,KAAa,EAAE,OAAyB,EAAE,OAAqC,KAAgB;;AAErH,IAAA,MAAM,KAAK,GAAGA,kCAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAEC,4BAAW,CAAC,OAAO,EAAEC,iCAAgB,CAAC,KAAK,CAAC,CAAC,IAAI,KAAK,EAAE;AACrI,IAAA,OAAO,EAAE,GAAG,KAAK,EAAE,KAAK,EAAE;AAC5B;AAEA;;;;;;;AAOG;AACI,MAAM,YAAY,GAAG,CAA4B,KAAa,KAAY;AAC/E,IAAA,MAAM,IAAI,GAAGC,4BAAW,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC;IACpD,OAAO,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,KAAK,CAAC,IAA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,EAAE;IAC/C;AAEA,IAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,gBAAgB,EAAE,WAAW,EAAE;AACxF;;;;"}
|
|
@@ -44,6 +44,15 @@ export interface ReconciledPhoneEntry {
|
|
|
44
44
|
* @returns The country and text to show, carrying `value` unchanged.
|
|
45
45
|
*/
|
|
46
46
|
export declare const entryOf: (value: string, country: PhoneCountryCode, allowed?: readonly PhoneCountryCode[]) => ShownEntry;
|
|
47
|
+
/**
|
|
48
|
+
* Writes an entry's number as a saved one shows, for when the user leaves the field, so a trunk prefix typed out of habit
|
|
49
|
+
* does not stay beside the calling code.
|
|
50
|
+
*
|
|
51
|
+
* @param entry The entry on screen, or one reported to an owner that has yet to hand its value back.
|
|
52
|
+
* @returns The entry with its text rewritten, in the country it had. The same object when the text already reads that
|
|
53
|
+
* way, or when the value is not a number of that country.
|
|
54
|
+
*/
|
|
55
|
+
export declare const settledEntry: <TEntry extends ShownEntry>(entry: TEntry) => TEntry;
|
|
47
56
|
/**
|
|
48
57
|
* Brings the entry on screen in line with the number the field's owner holds. The shown text is kept when it belongs
|
|
49
58
|
* to that number, and rebuilt from the number only when the number arrives from outside, so a trunk zero the value
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"phoneEntry.utils.d.ts","sourceRoot":"","sources":["../../../../../src/components/atoms/PhoneInput/utilities/phoneEntry.utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAGxE,0DAA0D;AAC1D,MAAM,WAAW,UAAW,SAAQ,UAAU;IAC5C,KAAK,EAAE,MAAM,CAAC;IACd,wGAAwG;IACxG,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,2FAA2F;AAC3F,MAAM,WAAW,aAAc,SAAQ,UAAU;IAC/C,IAAI,EAAE,MAAM,CAAC;CACd;AAED,mGAAmG;AACnG,MAAM,WAAW,kBAAkB;IACjC,gDAAgD;IAChD,KAAK,EAAE,MAAM,CAAC;IACd,iDAAiD;IACjD,MAAM,EAAE,UAAU,CAAC;IACnB,6FAA6F;IAC7F,QAAQ,EAAE,aAAa,GAAG,SAAS,CAAC;IACpC,kGAAkG;IAClG,gBAAgB,EAAE,OAAO,CAAC;IAC1B,gEAAgE;IAChE,cAAc,EAAE,gBAAgB,CAAC;IACjC,mEAAmE;IACnE,OAAO,CAAC,EAAE,SAAS,gBAAgB,EAAE,CAAC;CACvC;AAED,qFAAqF;AACrF,MAAM,WAAW,oBAAoB;IACnC,oGAAoG;IACpG,KAAK,EAAE,UAAU,CAAC;IAClB,0GAA0G;IAC1G,MAAM,EAAE,UAAU,CAAC;IACnB,wGAAwG;IACxG,QAAQ,EAAE,aAAa,GAAG,SAAS,CAAC;IACpC,8DAA8D;IAC9D,gBAAgB,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,OAAO,GAAI,OAAO,MAAM,EAAE,SAAS,gBAAgB,EAAE,UAAU,SAAS,gBAAgB,EAAE,KAAG,UAIzG,CAAC;AAQF;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,GAAI,yEAOjC,kBAAkB,KAAG,oBAiBvB,CAAC"}
|
|
1
|
+
{"version":3,"file":"phoneEntry.utils.d.ts","sourceRoot":"","sources":["../../../../../src/components/atoms/PhoneInput/utilities/phoneEntry.utils.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAGxE,0DAA0D;AAC1D,MAAM,WAAW,UAAW,SAAQ,UAAU;IAC5C,KAAK,EAAE,MAAM,CAAC;IACd,wGAAwG;IACxG,SAAS,CAAC,EAAE,OAAO,CAAC;CACrB;AAED,2FAA2F;AAC3F,MAAM,WAAW,aAAc,SAAQ,UAAU;IAC/C,IAAI,EAAE,MAAM,CAAC;CACd;AAED,mGAAmG;AACnG,MAAM,WAAW,kBAAkB;IACjC,gDAAgD;IAChD,KAAK,EAAE,MAAM,CAAC;IACd,iDAAiD;IACjD,MAAM,EAAE,UAAU,CAAC;IACnB,6FAA6F;IAC7F,QAAQ,EAAE,aAAa,GAAG,SAAS,CAAC;IACpC,kGAAkG;IAClG,gBAAgB,EAAE,OAAO,CAAC;IAC1B,gEAAgE;IAChE,cAAc,EAAE,gBAAgB,CAAC;IACjC,mEAAmE;IACnE,OAAO,CAAC,EAAE,SAAS,gBAAgB,EAAE,CAAC;CACvC;AAED,qFAAqF;AACrF,MAAM,WAAW,oBAAoB;IACnC,oGAAoG;IACpG,KAAK,EAAE,UAAU,CAAC;IAClB,0GAA0G;IAC1G,MAAM,EAAE,UAAU,CAAC;IACnB,wGAAwG;IACxG,QAAQ,EAAE,aAAa,GAAG,SAAS,CAAC;IACpC,8DAA8D;IAC9D,gBAAgB,EAAE,OAAO,CAAC;CAC3B;AAED;;;;;;;GAOG;AACH,eAAO,MAAM,OAAO,GAAI,OAAO,MAAM,EAAE,SAAS,gBAAgB,EAAE,UAAU,SAAS,gBAAgB,EAAE,KAAG,UAIzG,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,YAAY,GAAI,MAAM,SAAS,UAAU,EAAE,OAAO,MAAM,KAAG,MAGvE,CAAC;AAQF;;;;;;;GAOG;AACH,eAAO,MAAM,mBAAmB,GAAI,yEAOjC,kBAAkB,KAAG,oBAiBvB,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { fromInternational, formatTyped, significantChars } from './phoneInput.utils.js';
|
|
1
|
+
import { fromInternational, formatTyped, significantChars, settledText } from './phoneInput.utils.js';
|
|
2
2
|
|
|
3
3
|
/**
|
|
4
4
|
* Builds the entry a value shows as, in the country it names or the one given when it names none.
|
|
@@ -13,6 +13,18 @@ const entryOf = (value, country, allowed) => {
|
|
|
13
13
|
const entry = fromInternational(value, country, allowed) ?? { country, text: formatTyped(country, significantChars(value)) || value };
|
|
14
14
|
return { ...entry, value };
|
|
15
15
|
};
|
|
16
|
+
/**
|
|
17
|
+
* Writes an entry's number as a saved one shows, for when the user leaves the field, so a trunk prefix typed out of habit
|
|
18
|
+
* does not stay beside the calling code.
|
|
19
|
+
*
|
|
20
|
+
* @param entry The entry on screen, or one reported to an owner that has yet to hand its value back.
|
|
21
|
+
* @returns The entry with its text rewritten, in the country it had. The same object when the text already reads that
|
|
22
|
+
* way, or when the value is not a number of that country.
|
|
23
|
+
*/
|
|
24
|
+
const settledEntry = (entry) => {
|
|
25
|
+
const text = settledText(entry.value, entry.country);
|
|
26
|
+
return text === undefined || text === entry.text ? entry : { ...entry, text };
|
|
27
|
+
};
|
|
16
28
|
const shownFor = (value, stored, reported, allowed) => {
|
|
17
29
|
if (stored.value === value)
|
|
18
30
|
return stored;
|
|
@@ -48,5 +60,5 @@ const reconcilePhoneEntry = ({ value, stored, reported, isCountrySettled, defaul
|
|
|
48
60
|
return { shown, stored: shown, reported: nextReported, isCountrySettled: nextSettled };
|
|
49
61
|
};
|
|
50
62
|
|
|
51
|
-
export { entryOf, reconcilePhoneEntry };
|
|
63
|
+
export { entryOf, reconcilePhoneEntry, settledEntry };
|
|
52
64
|
//# sourceMappingURL=phoneEntry.utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"phoneEntry.utils.js","sources":["../../../../../src/components/atoms/PhoneInput/utilities/phoneEntry.utils.ts"],"sourcesContent":[null],"names":[],"mappings":";;AA2CA;;;;;;;AAOG;AACI,MAAM,OAAO,GAAG,CAAC,KAAa,EAAE,OAAyB,EAAE,OAAqC,KAAgB;;AAErH,IAAA,MAAM,KAAK,GAAG,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,CAAC,OAAO,EAAE,gBAAgB,CAAC,KAAK,CAAC,CAAC,IAAI,KAAK,EAAE;AACrI,IAAA,OAAO,EAAE,GAAG,KAAK,E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AAK,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,gBAAgB,EAAE,WAAW,EAAE;AACxF;;"}
|
|
1
|
+
{"version":3,"file":"phoneEntry.utils.js","sources":["../../../../../src/components/atoms/PhoneInput/utilities/phoneEntry.utils.ts"],"sourcesContent":[null],"names":[],"mappings":";;AA2CA;;;;;;;AAOG;AACI,MAAM,OAAO,GAAG,CAAC,KAAa,EAAE,OAAyB,EAAE,OAAqC,KAAgB;;AAErH,IAAA,MAAM,KAAK,GAAG,iBAAiB,CAAC,KAAK,EAAE,OAAO,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,EAAE,WAAW,CAAC,OAAO,EAAE,gBAAgB,CAAC,KAAK,CAAC,CAAC,IAAI,KAAK,EAAE;AACrI,IAAA,OAAO,EAAE,GAAG,KAAK,EAAE,KAAK,EAAE;AAC5B;AAEA;;;;;;;AAOG;AACI,MAAM,YAAY,GAAG,CAA4B,KAAa,KAAY;AAC/E,IAAA,MAAM,IAAI,GAAG,WAAW,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK,CAAC,OAAO,CAAC;IACpD,OAAO,IAAI,KAAK,SAAS,IAAI,IAAI,KAAK,KAAK,CAAC,IAAI,GAAG,KAAK,GAAG,EAAE,GAAG,KAAK,EAAE,IAAI,EAAE;AAC/E;AAEA,MAAM,QAAQ,GAAG,CAAC,KAAa,EAAE,MAAkB,EAAE,QAAmC,EAAE,OAAqC,KAAgB;AAC7I,IAAA,IAAI,MAAM,CAAC,KAAK,KAAK,KAAK;AAAE,QAAA,OAAO,MAAM;AACzC,IAAA,IAAI,QAAQ,EAAE,KAAK,KAAK,KAAK;AAAE,QAAA,OAAO,QAAQ;IAC9C,OAAO,OAAO,CAAC,KAAK,EAAE,MAAM,CAAC,OAAO,EAAE,OAAO,CAAC;AAChD,CAAC;AAED;;;;;;;AAOG;AACI,MAAM,mBAAmB,GAAG,CAAC,EAClC,KAAK,EACL,MAAM,EACN,QAAQ,EACR,gBAAgB,EAChB,cAAc,EACd,OAAO,GACY,KAA0B;AAC7C,IAAA,IAAI,KAAK,GAAG,QAAQ,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAC;;AAEtD,IAAA,MAAM,cAAc,GAAG,KAAK,KAAK,QAAQ,EAAE,KAAK;;IAEhD,MAAM,UAAU,GAAG,KAAK,KAAK,MAAM,IAAI,KAAK,KAAK,QAAQ,EAAE,IAAI;IAC/D,IAAI,YAAY,GAAG,QAAQ;AAC3B,IAAA,IAAI,QAAQ,KAAK,cAAc,IAAI,UAAU,CAAC;QAAE,YAAY,GAAG,SAAS;;IAExE,IAAI,WAAW,GAAG,gBAAgB;AAClC,IAAA,IAAI,CAAC,gBAAgB,IAAI,KAAK,CAAC,KAAK,KAAK,EAAE,IAAI,KAAK,KAAK,QAAQ,EAAE,IAAI;QAAE,WAAW,GAAG,IAAI;;IAE3F,IAAI,CAAC,gBAAgB,IAAI,KAAK,CAAC,IAAI,KAAK,EAAE,IAAI,KAAK,CAAC,KAAK,KAAK,EAAE,IAAI,KAAK,CAAC,OAAO,KAAK,cAAc,EAAE;QACpG,KAAK,GAAG,EAAE,GAAG,KAAK,EAAE,OAAO,EAAE,cAAc,EAAE;IAC/C;AAEA,IAAA,OAAO,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,QAAQ,EAAE,YAAY,EAAE,gBAAgB,EAAE,WAAW,EAAE;AACxF;;"}
|
|
@@ -66,21 +66,26 @@ const editedDigits = ({ previous, next, caret, inputType }) => {
|
|
|
66
66
|
return { significant, position };
|
|
67
67
|
return { significant: significant.slice(0, index) + significant.slice(index + 1), position: index };
|
|
68
68
|
};
|
|
69
|
+
// The field shows the calling code beside the number, so the number reads on from it as an international one does.
|
|
70
|
+
const afterCallingCode = (international, callingCode) => international.replace(`+${callingCode}`, '').trim();
|
|
69
71
|
/**
|
|
70
|
-
* Formats a number as it is typed
|
|
72
|
+
* Formats a number as it is typed. The country's calling code sits beside the field, so national digits are spaced as
|
|
73
|
+
* they are written after that code.
|
|
71
74
|
*
|
|
72
75
|
* @param country The country whose style applies.
|
|
73
76
|
* @param significant The digits typed so far, after a plus for an international number.
|
|
74
|
-
* @returns The number spaced as
|
|
75
|
-
* trunk prefix, as
|
|
77
|
+
* @returns The number spaced as it is written after the country's calling code, as far as it has been typed. One typed
|
|
78
|
+
* with the country's trunk prefix, such as a leading `0`, keeps it in the national style, and one after a plus is
|
|
79
|
+
* spaced as an international number.
|
|
76
80
|
*/
|
|
77
81
|
const formatTyped = (country, significant) => {
|
|
78
|
-
const
|
|
79
|
-
|
|
82
|
+
const typed = new min.AsYouType(country);
|
|
83
|
+
const national = typed.input(significant);
|
|
84
|
+
// A trunk prefix is not dropped mid-number: where a number can start with the same digit, only the whole number tells them apart.
|
|
85
|
+
if (significant.startsWith('+') || typed.getNumber()?.nationalNumber !== significant)
|
|
80
86
|
return national;
|
|
81
|
-
// The national format of many countries needs the trunk prefix, so a number typed without it would get no spacing at all.
|
|
82
87
|
const callingCode = min.getCountryCallingCode(country);
|
|
83
|
-
return new min.AsYouType().input(`+${callingCode}${significant}`)
|
|
88
|
+
return afterCallingCode(new min.AsYouType().input(`+${callingCode}${significant}`), callingCode);
|
|
84
89
|
};
|
|
85
90
|
/**
|
|
86
91
|
* Writes what the field shows as one international number, the form an API stores.
|
|
@@ -93,6 +98,31 @@ const toInternational = ({ country, text }) => {
|
|
|
93
98
|
typed.input(text);
|
|
94
99
|
return typed.getNumber()?.number ?? '';
|
|
95
100
|
};
|
|
101
|
+
// Where a number starts with its country's trunk digit, as `812` does in Russia, the text after the code would read back as another number, so it keeps the national form.
|
|
102
|
+
const wholeNumberText = (country, number) => {
|
|
103
|
+
const written = afterCallingCode(number.formatInternational(), number.countryCallingCode);
|
|
104
|
+
// A number no pattern fits whole, such as one a digit short, comes back unspaced, so it is spaced as typing it is.
|
|
105
|
+
const text = written === number.nationalNumber ? formatTyped(country, number.nationalNumber) : written;
|
|
106
|
+
return toInternational({ country, text }) === number.number ? text : number.formatNational();
|
|
107
|
+
};
|
|
108
|
+
/**
|
|
109
|
+
* Writes the number a field holds the way a saved one shows, without moving the field off its country, for when the
|
|
110
|
+
* user leaves it.
|
|
111
|
+
*
|
|
112
|
+
* @param value The international number the field holds.
|
|
113
|
+
* @param country The country the field is on.
|
|
114
|
+
* @returns The number as it is written after that country's calling code, or `undefined` when the value is no number,
|
|
115
|
+
* belongs to another calling code, or would not read back in that country as the same number.
|
|
116
|
+
*/
|
|
117
|
+
const settledText = (value, country) => {
|
|
118
|
+
const typed = new min.AsYouType();
|
|
119
|
+
typed.input(significantChars(value));
|
|
120
|
+
const number = typed.getNumber();
|
|
121
|
+
if (!number || number.countryCallingCode !== min.getCountryCallingCode(country))
|
|
122
|
+
return undefined;
|
|
123
|
+
const text = number.isPossible() ? wholeNumberText(country, number) : formatTyped(country, number.nationalNumber);
|
|
124
|
+
return toInternational({ country, text }) === number.number ? text : undefined;
|
|
125
|
+
};
|
|
96
126
|
/**
|
|
97
127
|
* Finds the calling code a run of digits starts with. No calling code starts with another, so the first match is the code.
|
|
98
128
|
*
|
|
@@ -135,8 +165,9 @@ const countryForNumber = (international, current, allowed) => {
|
|
|
135
165
|
* @param value The number, with its plus and calling code.
|
|
136
166
|
* @param current The country the field is on, kept where the number could belong to it.
|
|
137
167
|
* @param allowed The countries the field offers, when the app restricts them.
|
|
138
|
-
* @returns The country and the number
|
|
139
|
-
* number
|
|
168
|
+
* @returns The country and the number as it is written after that country's calling code, with no trunk prefix unless
|
|
169
|
+
* the number needs it to read back as itself, or `undefined` for a value that is not an international number or
|
|
170
|
+
* belongs to a country the field does not offer.
|
|
140
171
|
*/
|
|
141
172
|
const fromInternational = (value, current, allowed) => {
|
|
142
173
|
const significant = significantChars(value);
|
|
@@ -146,8 +177,8 @@ const fromInternational = (value, current, allowed) => {
|
|
|
146
177
|
const typed = new min.AsYouType();
|
|
147
178
|
typed.input(significant);
|
|
148
179
|
const number = typed.getNumber();
|
|
149
|
-
// A
|
|
150
|
-
const text = number?.isPossible() ? number
|
|
180
|
+
// A partial number has no whole form yet, so it is spaced as far as it goes.
|
|
181
|
+
const text = number?.isPossible() ? wholeNumberText(country, number) : formatTyped(country, number?.nationalNumber ?? '');
|
|
151
182
|
return { country, text };
|
|
152
183
|
};
|
|
153
184
|
/**
|
|
@@ -215,10 +246,10 @@ const entryFor = (country, significant, position, allowed) => {
|
|
|
215
246
|
const entry = fromInternational(digits, country, allowed);
|
|
216
247
|
if (!entry)
|
|
217
248
|
return { country, text: formatTyped(country, digits), position: cursor };
|
|
218
|
-
// The national digits before the cursor, shifted by
|
|
249
|
+
// The national digits before the cursor, shifted by a trunk prefix the shown number adds in front of them or leaves out.
|
|
219
250
|
const nationalLength = digits.length - 1 - callingCode.length;
|
|
220
|
-
const
|
|
221
|
-
return { ...entry, position: before.length - callingCode.length +
|
|
251
|
+
const trunkShift = significantChars(entry.text).length - nationalLength;
|
|
252
|
+
return { ...entry, position: Math.max(0, before.length - callingCode.length + trunkShift) };
|
|
222
253
|
};
|
|
223
254
|
/**
|
|
224
255
|
* Lists the countries the field offers, named and sorted for the user's language.
|
|
@@ -239,9 +270,12 @@ const countryOptions = (locale, allowed) => {
|
|
|
239
270
|
* Gives a number that shows a country's format, for the field's placeholder.
|
|
240
271
|
*
|
|
241
272
|
* @param country The country to show.
|
|
242
|
-
* @returns A mobile number
|
|
273
|
+
* @returns A mobile number as it is written after that country's calling code, or `''` when the library has none.
|
|
243
274
|
*/
|
|
244
|
-
const exampleNumber = (country) =>
|
|
275
|
+
const exampleNumber = (country) => {
|
|
276
|
+
const example = min.getExampleNumber(country, examples);
|
|
277
|
+
return example ? wholeNumberText(country, example) : '';
|
|
278
|
+
};
|
|
245
279
|
// Reads the tag's region alone, so neither an extension key (`en-u-ca-gregory`) nor a POSIX codeset (`en_US.UTF-8`) is taken for one.
|
|
246
280
|
const localeRegion = (locale) => {
|
|
247
281
|
try {
|
|
@@ -298,6 +332,7 @@ exports.isFocusInside = isFocusInside;
|
|
|
298
332
|
exports.leadingCallingCode = leadingCallingCode;
|
|
299
333
|
exports.nationalDigits = nationalDigits;
|
|
300
334
|
exports.offeredCountries = offeredCountries;
|
|
335
|
+
exports.settledText = settledText;
|
|
301
336
|
exports.significantChars = significantChars;
|
|
302
337
|
exports.startingCountry = startingCountry;
|
|
303
338
|
exports.toInternational = toInternational;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"phoneInput.utils.cjs","sources":["../../../../../src/components/atoms/PhoneInput/utilities/phoneInput.utils.ts"],"sourcesContent":[null],"names":["parseDigits","AsYouType","getCountryCallingCode","isSupportedCountry","getCountries","getCountryName","getExampleNumber"],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"phoneInput.utils.cjs","sources":["../../../../../src/components/atoms/PhoneInput/utilities/phoneInput.utils.ts"],"sourcesContent":[null],"names":["parseDigits","AsYouType","getCountryCallingCode","isSupportedCountry","getCountries","getCountryName","getExampleNumber"],"mappings":";;;;;;;AAcA;AACA,MAAM,gBAAgB,GAAqB,IAAI;AAE/C;;;;;AAKG;AACI,MAAM,gBAAgB,GAAG,CAAC,IAAY,KAAY;IACvD,IAAI,WAAW,GAAG,EAAE;AACpB,IAAA,KAAK,MAAM,IAAI,IAAI,IAAI,EAAE;AACvB,QAAA,IAAI,IAAI,KAAK,GAAG,EAAE;YAChB,IAAI,WAAW,KAAK,EAAE;gBAAE,WAAW,GAAG,GAAG;QAC3C;aAAO;AACL,YAAA,WAAW,IAAIA,eAAW,CAAC,IAAI,CAAC;QAClC;IACF;AACA,IAAA,OAAO,WAAW;AACpB;AAEA;;;;;;AAMG;MACU,UAAU,GAAG,CAAC,IAAY,EAAE,QAAgB,KAAY;IACnE,IAAI,IAAI,GAAG,CAAC;AACZ,IAAA,KAAK,IAAI,KAAK,GAAG,CAAC,EAAE,KAAK,GAAG,IAAI,CAAC,MAAM,EAAE,KAAK,EAAE,EAAE;QAChD,MAAM,aAAa,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AC,IAAI,EAAE,GAAG,CAAC,CAAC,CAAC,MAAM;IACjF;AAAE,IAAA,MAAM;AACN,QAAA,OAAO,SAAS;IAClB;AACF,CAAC;AAED;;;;;;;;AAQG;AACI,MAAM,eAAe,GAAG,CAAC,SAA6B,EAAE,MAAc,EAAE,OAAqC,KAAsB;AACxI,IAAA,MAAM,SAAS,GAAG,CAAC,IAAwB,KACzC,OAAO,CAAC,IAAI,CAAC,IAAIH,sBAAkB,CAAC,IAAc,CAAC,KAAK,CAAC,OAAO,IAAI,OAAO,CAAC,QAAQ,CAAC,IAAwB,CAAC,CAAC;IACjH,IAAI,SAAS,CAAC,SAAS,CAAC;AAAE,QAAA,OAAO,SAAS;AAC1C,IAAA,MAAM,MAAM,GAAG,YAAY,CAAC,MAAM,CAAC;IACnC,IAAI,SAAS,CAAC,MAAM,CAAC;AAAE,QAAA,OAAO,MAAM;AACpC,IAAA,OAAO,OAAO,GAAG,CAAC,CAAC,IAAI,gBAAgB;AACzC;AAEA;;;;;;;AAOG;AACI,MAAM,aAAa,GAAG,CAAC,IAAwB,EAAE,KAA+B,KACrF,IAAI,KAAK,IAAI,IAAI,KAAK,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK,IAAI,EAAE,QAAQ,CAAC,IAAY,CAAC;AAEpE;;;;;AAKG;AACI,MAAM,gBAAgB,GAAG,CAAC,SAA6B,KAC5D,SAAS,KAAK,SAAS,GAAG,SAAS,GAAG,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,CAAC,IAAI,KAA+BA,sBAAkB,CAAC,IAAI,CAAC;;;;;;;;;;;;;;;;;"}
|
|
@@ -36,12 +36,14 @@ export declare const editedDigits: ({ previous, next, caret, inputType }: PhoneE
|
|
|
36
36
|
position: number;
|
|
37
37
|
};
|
|
38
38
|
/**
|
|
39
|
-
* Formats a number as it is typed
|
|
39
|
+
* Formats a number as it is typed. The country's calling code sits beside the field, so national digits are spaced as
|
|
40
|
+
* they are written after that code.
|
|
40
41
|
*
|
|
41
42
|
* @param country The country whose style applies.
|
|
42
43
|
* @param significant The digits typed so far, after a plus for an international number.
|
|
43
|
-
* @returns The number spaced as
|
|
44
|
-
* trunk prefix, as
|
|
44
|
+
* @returns The number spaced as it is written after the country's calling code, as far as it has been typed. One typed
|
|
45
|
+
* with the country's trunk prefix, such as a leading `0`, keeps it in the national style, and one after a plus is
|
|
46
|
+
* spaced as an international number.
|
|
45
47
|
*/
|
|
46
48
|
export declare const formatTyped: (country: PhoneCountryCode, significant: string) => string;
|
|
47
49
|
/**
|
|
@@ -51,6 +53,16 @@ export declare const formatTyped: (country: PhoneCountryCode, significant: strin
|
|
|
51
53
|
* @returns The number in E.164 form, such as `+353861234567`, as far as it has been typed, or `''` before any digit that counts.
|
|
52
54
|
*/
|
|
53
55
|
export declare const toInternational: ({ country, text }: PhoneEntry) => string;
|
|
56
|
+
/**
|
|
57
|
+
* Writes the number a field holds the way a saved one shows, without moving the field off its country, for when the
|
|
58
|
+
* user leaves it.
|
|
59
|
+
*
|
|
60
|
+
* @param value The international number the field holds.
|
|
61
|
+
* @param country The country the field is on.
|
|
62
|
+
* @returns The number as it is written after that country's calling code, or `undefined` when the value is no number,
|
|
63
|
+
* belongs to another calling code, or would not read back in that country as the same number.
|
|
64
|
+
*/
|
|
65
|
+
export declare const settledText: (value: string, country: PhoneCountryCode) => string | undefined;
|
|
54
66
|
/**
|
|
55
67
|
* Finds the calling code a run of digits starts with. No calling code starts with another, so the first match is the code.
|
|
56
68
|
*
|
|
@@ -75,8 +87,9 @@ export declare const countryForNumber: (international: string, current: PhoneCou
|
|
|
75
87
|
* @param value The number, with its plus and calling code.
|
|
76
88
|
* @param current The country the field is on, kept where the number could belong to it.
|
|
77
89
|
* @param allowed The countries the field offers, when the app restricts them.
|
|
78
|
-
* @returns The country and the number
|
|
79
|
-
* number
|
|
90
|
+
* @returns The country and the number as it is written after that country's calling code, with no trunk prefix unless
|
|
91
|
+
* the number needs it to read back as itself, or `undefined` for a value that is not an international number or
|
|
92
|
+
* belongs to a country the field does not offer.
|
|
80
93
|
*/
|
|
81
94
|
export declare const fromInternational: (value: string, current: PhoneCountryCode, allowed?: readonly PhoneCountryCode[]) => PhoneEntry | undefined;
|
|
82
95
|
/**
|
|
@@ -115,7 +128,7 @@ export declare const countryOptions: (locale: string, allowed?: readonly string[
|
|
|
115
128
|
* Gives a number that shows a country's format, for the field's placeholder.
|
|
116
129
|
*
|
|
117
130
|
* @param country The country to show.
|
|
118
|
-
* @returns A mobile number
|
|
131
|
+
* @returns A mobile number as it is written after that country's calling code, or `''` when the library has none.
|
|
119
132
|
*/
|
|
120
133
|
export declare const exampleNumber: (country: PhoneCountryCode) => string;
|
|
121
134
|
/**
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"phoneInput.utils.d.ts","sourceRoot":"","sources":["../../../../../src/components/atoms/PhoneInput/utilities/phoneInput.utils.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"phoneInput.utils.d.ts","sourceRoot":"","sources":["../../../../../src/components/atoms/PhoneInput/utilities/phoneInput.utils.ts"],"names":[],"mappings":"AAYA,OAAO,KAAK,EAAE,YAAY,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAKtF;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAI,MAAM,MAAM,KAAG,MAU/C,CAAC;AAEF;;;;;;GAMG;AACH,eAAO,MAAM,UAAU,GAAI,MAAM,MAAM,EAAE,UAAU,MAAM,KAAG,MAU3D,CAAC;AAEF,MAAM,WAAW,SAAS;IACxB,iDAAiD;IACjD,QAAQ,EAAE,MAAM,CAAC;IACjB,uDAAuD;IACvD,IAAI,EAAE,MAAM,CAAC;IACb,mDAAmD;IACnD,KAAK,EAAE,MAAM,CAAC;IACd,mFAAmF;IACnF,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;;;GAMG;AACH,eAAO,MAAM,YAAY,GAAI,sCAAsC,SAAS,K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G;AACH,eAAO,MAAM,aAAa,GAAI,SAAS,gBAAgB,KAAG,MAGzD,CAAC;AAWF;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,GAAI,WAAW,MAAM,GAAG,SAAS,EAAE,QAAQ,MAAM,EAAE,UAAU,SAAS,gBAAgB,EAAE,KAAG,gBAOtH,CAAC;AAEF;;;;;;;GAOG;AACH,eAAO,MAAM,aAAa,GAAI,MAAM,WAAW,GAAG,IAAI,EAAE,OAAO,SAAS,CAAC,IAAI,GAAG,IAAI,CAAC,EAAE,KAAG,OACrB,CAAC;AAEtE;;;;;GAKG;AACH,eAAO,MAAM,gBAAgB,GAAI,WAAW,MAAM,GAAG,SAAS,KAAG,gBAAgB,EAAE,GAAG,SAC2C,CAAC"}
|
|
@@ -64,21 +64,26 @@ const editedDigits = ({ previous, next, caret, inputType }) => {
|
|
|
64
64
|
return { significant, position };
|
|
65
65
|
return { significant: significant.slice(0, index) + significant.slice(index + 1), position: index };
|
|
66
66
|
};
|
|
67
|
+
// The field shows the calling code beside the number, so the number reads on from it as an international one does.
|
|
68
|
+
const afterCallingCode = (international, callingCode) => international.replace(`+${callingCode}`, '').trim();
|
|
67
69
|
/**
|
|
68
|
-
* Formats a number as it is typed
|
|
70
|
+
* Formats a number as it is typed. The country's calling code sits beside the field, so national digits are spaced as
|
|
71
|
+
* they are written after that code.
|
|
69
72
|
*
|
|
70
73
|
* @param country The country whose style applies.
|
|
71
74
|
* @param significant The digits typed so far, after a plus for an international number.
|
|
72
|
-
* @returns The number spaced as
|
|
73
|
-
* trunk prefix, as
|
|
75
|
+
* @returns The number spaced as it is written after the country's calling code, as far as it has been typed. One typed
|
|
76
|
+
* with the country's trunk prefix, such as a leading `0`, keeps it in the national style, and one after a plus is
|
|
77
|
+
* spaced as an international number.
|
|
74
78
|
*/
|
|
75
79
|
const formatTyped = (country, significant) => {
|
|
76
|
-
const
|
|
77
|
-
|
|
80
|
+
const typed = new AsYouType(country);
|
|
81
|
+
const national = typed.input(significant);
|
|
82
|
+
// A trunk prefix is not dropped mid-number: where a number can start with the same digit, only the whole number tells them apart.
|
|
83
|
+
if (significant.startsWith('+') || typed.getNumber()?.nationalNumber !== significant)
|
|
78
84
|
return national;
|
|
79
|
-
// The national format of many countries needs the trunk prefix, so a number typed without it would get no spacing at all.
|
|
80
85
|
const callingCode = getCountryCallingCode(country);
|
|
81
|
-
return new AsYouType().input(`+${callingCode}${significant}`)
|
|
86
|
+
return afterCallingCode(new AsYouType().input(`+${callingCode}${significant}`), callingCode);
|
|
82
87
|
};
|
|
83
88
|
/**
|
|
84
89
|
* Writes what the field shows as one international number, the form an API stores.
|
|
@@ -91,6 +96,31 @@ const toInternational = ({ country, text }) => {
|
|
|
91
96
|
typed.input(text);
|
|
92
97
|
return typed.getNumber()?.number ?? '';
|
|
93
98
|
};
|
|
99
|
+
// Where a number starts with its country's trunk digit, as `812` does in Russia, the text after the code would read back as another number, so it keeps the national form.
|
|
100
|
+
const wholeNumberText = (country, number) => {
|
|
101
|
+
const written = afterCallingCode(number.formatInternational(), number.countryCallingCode);
|
|
102
|
+
// A number no pattern fits whole, such as one a digit short, comes back unspaced, so it is spaced as typing it is.
|
|
103
|
+
const text = written === number.nationalNumber ? formatTyped(country, number.nationalNumber) : written;
|
|
104
|
+
return toInternational({ country, text }) === number.number ? text : number.formatNational();
|
|
105
|
+
};
|
|
106
|
+
/**
|
|
107
|
+
* Writes the number a field holds the way a saved one shows, without moving the field off its country, for when the
|
|
108
|
+
* user leaves it.
|
|
109
|
+
*
|
|
110
|
+
* @param value The international number the field holds.
|
|
111
|
+
* @param country The country the field is on.
|
|
112
|
+
* @returns The number as it is written after that country's calling code, or `undefined` when the value is no number,
|
|
113
|
+
* belongs to another calling code, or would not read back in that country as the same number.
|
|
114
|
+
*/
|
|
115
|
+
const settledText = (value, country) => {
|
|
116
|
+
const typed = new AsYouType();
|
|
117
|
+
typed.input(significantChars(value));
|
|
118
|
+
const number = typed.getNumber();
|
|
119
|
+
if (!number || number.countryCallingCode !== getCountryCallingCode(country))
|
|
120
|
+
return undefined;
|
|
121
|
+
const text = number.isPossible() ? wholeNumberText(country, number) : formatTyped(country, number.nationalNumber);
|
|
122
|
+
return toInternational({ country, text }) === number.number ? text : undefined;
|
|
123
|
+
};
|
|
94
124
|
/**
|
|
95
125
|
* Finds the calling code a run of digits starts with. No calling code starts with another, so the first match is the code.
|
|
96
126
|
*
|
|
@@ -133,8 +163,9 @@ const countryForNumber = (international, current, allowed) => {
|
|
|
133
163
|
* @param value The number, with its plus and calling code.
|
|
134
164
|
* @param current The country the field is on, kept where the number could belong to it.
|
|
135
165
|
* @param allowed The countries the field offers, when the app restricts them.
|
|
136
|
-
* @returns The country and the number
|
|
137
|
-
* number
|
|
166
|
+
* @returns The country and the number as it is written after that country's calling code, with no trunk prefix unless
|
|
167
|
+
* the number needs it to read back as itself, or `undefined` for a value that is not an international number or
|
|
168
|
+
* belongs to a country the field does not offer.
|
|
138
169
|
*/
|
|
139
170
|
const fromInternational = (value, current, allowed) => {
|
|
140
171
|
const significant = significantChars(value);
|
|
@@ -144,8 +175,8 @@ const fromInternational = (value, current, allowed) => {
|
|
|
144
175
|
const typed = new AsYouType();
|
|
145
176
|
typed.input(significant);
|
|
146
177
|
const number = typed.getNumber();
|
|
147
|
-
// A
|
|
148
|
-
const text = number?.isPossible() ? number
|
|
178
|
+
// A partial number has no whole form yet, so it is spaced as far as it goes.
|
|
179
|
+
const text = number?.isPossible() ? wholeNumberText(country, number) : formatTyped(country, number?.nationalNumber ?? '');
|
|
149
180
|
return { country, text };
|
|
150
181
|
};
|
|
151
182
|
/**
|
|
@@ -213,10 +244,10 @@ const entryFor = (country, significant, position, allowed) => {
|
|
|
213
244
|
const entry = fromInternational(digits, country, allowed);
|
|
214
245
|
if (!entry)
|
|
215
246
|
return { country, text: formatTyped(country, digits), position: cursor };
|
|
216
|
-
// The national digits before the cursor, shifted by
|
|
247
|
+
// The national digits before the cursor, shifted by a trunk prefix the shown number adds in front of them or leaves out.
|
|
217
248
|
const nationalLength = digits.length - 1 - callingCode.length;
|
|
218
|
-
const
|
|
219
|
-
return { ...entry, position: before.length - callingCode.length +
|
|
249
|
+
const trunkShift = significantChars(entry.text).length - nationalLength;
|
|
250
|
+
return { ...entry, position: Math.max(0, before.length - callingCode.length + trunkShift) };
|
|
220
251
|
};
|
|
221
252
|
/**
|
|
222
253
|
* Lists the countries the field offers, named and sorted for the user's language.
|
|
@@ -237,9 +268,12 @@ const countryOptions = (locale, allowed) => {
|
|
|
237
268
|
* Gives a number that shows a country's format, for the field's placeholder.
|
|
238
269
|
*
|
|
239
270
|
* @param country The country to show.
|
|
240
|
-
* @returns A mobile number
|
|
271
|
+
* @returns A mobile number as it is written after that country's calling code, or `''` when the library has none.
|
|
241
272
|
*/
|
|
242
|
-
const exampleNumber = (country) =>
|
|
273
|
+
const exampleNumber = (country) => {
|
|
274
|
+
const example = getExampleNumber(country, examples);
|
|
275
|
+
return example ? wholeNumberText(country, example) : '';
|
|
276
|
+
};
|
|
243
277
|
// Reads the tag's region alone, so neither an extension key (`en-u-ca-gregory`) nor a POSIX codeset (`en_US.UTF-8`) is taken for one.
|
|
244
278
|
const localeRegion = (locale) => {
|
|
245
279
|
try {
|
|
@@ -284,5 +318,5 @@ const isFocusInside = (next, parts) => next !== null && parts.some((part) => par
|
|
|
284
318
|
*/
|
|
285
319
|
const offeredCountries = (countries) => countries === undefined ? undefined : countries.split(',').filter((code) => isSupportedCountry(code));
|
|
286
320
|
|
|
287
|
-
export { caretAfter, countryForNumber, countryOptions, editedDigits, entryFor, exampleNumber, formatTyped, fromInternational, isFocusInside, leadingCallingCode, nationalDigits, offeredCountries, significantChars, startingCountry, toInternational };
|
|
321
|
+
export { caretAfter, countryForNumber, countryOptions, editedDigits, entryFor, exampleNumber, formatTyped, fromInternational, isFocusInside, leadingCallingCode, nationalDigits, offeredCountries, settledText, significantChars, startingCountry, toInternational };
|
|
288
322
|
//# sourceMappingURL=phoneInput.utils.js.map
|