@rpcbase/ui 0.252.0 → 0.254.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/Notifications/types.d.ts +2 -0
- package/dist/components/Notifications/types.d.ts.map +1 -1
- package/dist/index10.js +2 -2
- package/dist/index106.js +1 -1
- package/dist/index11.js +2 -2
- package/dist/index12.js +3 -3
- package/dist/index120.js +10 -10
- package/dist/index122.js +2 -2
- package/dist/index123.js +3 -3
- package/dist/index13.js +2 -2
- package/dist/index14.js +2 -2
- package/dist/index15.js +2 -2
- package/dist/index16.js +8 -8
- package/dist/index167.js +3 -3
- package/dist/index17.js +1 -1
- package/dist/index172.js +3 -3
- package/dist/index175.js +1 -1
- package/dist/index176.js +4 -4
- package/dist/index18.js +7 -7
- package/dist/index182.js +2 -2
- package/dist/index184.js +4 -4
- package/dist/index185.js +14 -14
- package/dist/index186.js +1 -1
- package/dist/index187.js +1 -1
- package/dist/index188.js +6 -6
- package/dist/index189.js +2 -2
- package/dist/index19.js +16 -16
- package/dist/index192.js +2 -2
- package/dist/index193.js +6 -6
- package/dist/index21.js +1 -1
- package/dist/index22.js +2 -2
- package/dist/index23.js +1 -1
- package/dist/index235.js +27 -14
- package/dist/index235.js.map +1 -1
- package/dist/index236.js +12 -7
- package/dist/index236.js.map +1 -1
- package/dist/index237.js +24 -9
- package/dist/index237.js.map +1 -1
- package/dist/index238.js +5 -10
- package/dist/index238.js.map +1 -1
- package/dist/index239.js +15 -20
- package/dist/index239.js.map +1 -1
- package/dist/index24.js +1 -1
- package/dist/index240.js +7 -8
- package/dist/index240.js.map +1 -1
- package/dist/index241.js +10 -9
- package/dist/index241.js.map +1 -1
- package/dist/index242.js +10 -9
- package/dist/index242.js.map +1 -1
- package/dist/index243.js +21 -4
- package/dist/index243.js.map +1 -1
- package/dist/index244.js +8 -5
- package/dist/index244.js.map +1 -1
- package/dist/index245.js +9 -16
- package/dist/index245.js.map +1 -1
- package/dist/index246.js +8 -8
- package/dist/index246.js.map +1 -1
- package/dist/index247.js +4 -18
- package/dist/index247.js.map +1 -1
- package/dist/index248.js +5 -20
- package/dist/index248.js.map +1 -1
- package/dist/index249.js +16 -12
- package/dist/index249.js.map +1 -1
- package/dist/index25.js +1 -1
- package/dist/index250.js +9 -29
- package/dist/index250.js.map +1 -1
- package/dist/index251.js +18 -12
- package/dist/index251.js.map +1 -1
- package/dist/index252.js +20 -25
- package/dist/index252.js.map +1 -1
- package/dist/index253.js +12 -5
- package/dist/index253.js.map +1 -1
- package/dist/index260.js +2 -2
- package/dist/index273.js +1 -1
- package/dist/index277.js +25 -20
- package/dist/index277.js.map +1 -1
- package/dist/index278.js +24 -62
- package/dist/index278.js.map +1 -1
- package/dist/index279.js +16 -6
- package/dist/index279.js.map +1 -1
- package/dist/index28.js +1 -1
- package/dist/index280.js +20 -6
- package/dist/index280.js.map +1 -1
- package/dist/index281.js +66 -11
- package/dist/index281.js.map +1 -1
- package/dist/index282.js +6 -3
- package/dist/index282.js.map +1 -1
- package/dist/index283.js +5 -50
- package/dist/index283.js.map +1 -1
- package/dist/index284.js +12 -4
- package/dist/index284.js.map +1 -1
- package/dist/index285.js +3 -29
- package/dist/index285.js.map +1 -1
- package/dist/index286.js +49 -15
- package/dist/index286.js.map +1 -1
- package/dist/index287.js +4 -6
- package/dist/index287.js.map +1 -1
- package/dist/index288.js +28 -20
- package/dist/index288.js.map +1 -1
- package/dist/index289.js +15 -52
- package/dist/index289.js.map +1 -1
- package/dist/index29.js +3 -56
- package/dist/index29.js.map +1 -1
- package/dist/index290.js +5 -20
- package/dist/index290.js.map +1 -1
- package/dist/index291.js +21 -41
- package/dist/index291.js.map +1 -1
- package/dist/index292.js +53 -39
- package/dist/index292.js.map +1 -1
- package/dist/index293.js +21 -46
- package/dist/index293.js.map +1 -1
- package/dist/index294.js +40 -19
- package/dist/index294.js.map +1 -1
- package/dist/index295.js +38 -69
- package/dist/index295.js.map +1 -1
- package/dist/index296.js +46 -18
- package/dist/index296.js.map +1 -1
- package/dist/index297.js +20 -3
- package/dist/index297.js.map +1 -1
- package/dist/index298.js +69 -10
- package/dist/index298.js.map +1 -1
- package/dist/index299.js +16 -12
- package/dist/index299.js.map +1 -1
- package/dist/index3.js +2 -2
- package/dist/index30.js +242 -3
- package/dist/index30.js.map +1 -1
- package/dist/index300.js +3 -18
- package/dist/index300.js.map +1 -1
- package/dist/index301.js +11 -36
- package/dist/index301.js.map +1 -1
- package/dist/index302.js +12 -238
- package/dist/index302.js.map +1 -1
- package/dist/index303.js +15 -249
- package/dist/index303.js.map +1 -1
- package/dist/index304.js +35 -67
- package/dist/index304.js.map +1 -1
- package/dist/index305.js +233 -93
- package/dist/index305.js.map +1 -1
- package/dist/index306.js +243 -74
- package/dist/index306.js.map +1 -1
- package/dist/index307.js +68 -3
- package/dist/index307.js.map +1 -1
- package/dist/index308.js +96 -26
- package/dist/index308.js.map +1 -1
- package/dist/index309.js +83 -16
- package/dist/index309.js.map +1 -1
- package/dist/index31.js +21 -239
- package/dist/index31.js.map +1 -1
- package/dist/index310.js +4 -35
- package/dist/index310.js.map +1 -1
- package/dist/index311.js +28 -16
- package/dist/index311.js.map +1 -1
- package/dist/index312.js +16 -3
- package/dist/index312.js.map +1 -1
- package/dist/index313.js +35 -27
- package/dist/index313.js.map +1 -1
- package/dist/index314.js +17 -28
- package/dist/index314.js.map +1 -1
- package/dist/index315.js +4 -4
- package/dist/index315.js.map +1 -1
- package/dist/index316.js +23 -75
- package/dist/index316.js.map +1 -1
- package/dist/index317.js +25 -269
- package/dist/index317.js.map +1 -1
- package/dist/index318.js +4 -12
- package/dist/index318.js.map +1 -1
- package/dist/index319.js +79 -11
- package/dist/index319.js.map +1 -1
- package/dist/index32.js +4 -23
- package/dist/index32.js.map +1 -1
- package/dist/index320.js +270 -23
- package/dist/index320.js.map +1 -1
- package/dist/index321.js +11 -16
- package/dist/index321.js.map +1 -1
- package/dist/index322.js +10 -125
- package/dist/index322.js.map +1 -1
- package/dist/index323.js +24 -4
- package/dist/index323.js.map +1 -1
- package/dist/index324.js +16 -65
- package/dist/index324.js.map +1 -1
- package/dist/index325.js +125 -13
- package/dist/index325.js.map +1 -1
- package/dist/index326.js +5 -7
- package/dist/index326.js.map +1 -1
- package/dist/index327.js +65 -5
- package/dist/index327.js.map +1 -1
- package/dist/index328.js +14 -4
- package/dist/index328.js.map +1 -1
- package/dist/index329.js +7 -10
- package/dist/index329.js.map +1 -1
- package/dist/index33.js +6 -3
- package/dist/index33.js.map +1 -1
- package/dist/index330.js +5 -7
- package/dist/index330.js.map +1 -1
- package/dist/index331.js +3 -133
- package/dist/index331.js.map +1 -1
- package/dist/index332.js +9 -398
- package/dist/index332.js.map +1 -1
- package/dist/index333.js +8 -5
- package/dist/index333.js.map +1 -1
- package/dist/index334.js +131 -50
- package/dist/index334.js.map +1 -1
- package/dist/index335.js +399 -11
- package/dist/index335.js.map +1 -1
- package/dist/index336.js +5 -28
- package/dist/index336.js.map +1 -1
- package/dist/index337.js +52 -11
- package/dist/index337.js.map +1 -1
- package/dist/index338.js +11 -24
- package/dist/index338.js.map +1 -1
- package/dist/index339.js +27 -28
- package/dist/index339.js.map +1 -1
- package/dist/index34.js +38 -8
- package/dist/index34.js.map +1 -1
- package/dist/index340.js +11 -16
- package/dist/index340.js.map +1 -1
- package/dist/index341.js +1 -1
- package/dist/index348.js +5 -51
- package/dist/index348.js.map +1 -1
- package/dist/index349.js +51 -5
- package/dist/index349.js.map +1 -1
- package/dist/index35.js +74 -35
- package/dist/index35.js.map +1 -1
- package/dist/index350.js +3 -3
- package/dist/index358.js +5 -5
- package/dist/index359.js +1 -1
- package/dist/index36.js +20 -74
- package/dist/index36.js.map +1 -1
- package/dist/index363.js +5 -5
- package/dist/index368.js +11 -5
- package/dist/index368.js.map +1 -1
- package/dist/index369.js +6 -3
- package/dist/index369.js.map +1 -1
- package/dist/index37.js +33 -18
- package/dist/index37.js.map +1 -1
- package/dist/index370.js +3 -12
- package/dist/index370.js.map +1 -1
- package/dist/index372.js +1 -1
- package/dist/index375.js +2 -2
- package/dist/index376.js +3 -3
- package/dist/index377.js +8 -8
- package/dist/index379.js +5 -5
- package/dist/index38.js +26 -36
- package/dist/index38.js.map +1 -1
- package/dist/index380.js +3 -3
- package/dist/index382.js +1 -1
- package/dist/index384.js +1 -1
- package/dist/index385.js +2 -2
- package/dist/index386.js +1 -1
- package/dist/index388.js +2 -2
- package/dist/index389.js +2 -2
- package/dist/index39.js +21 -26
- package/dist/index39.js.map +1 -1
- package/dist/index399.js +2 -2
- package/dist/index4.js +2 -2
- package/dist/index40.js +56 -20
- package/dist/index40.js.map +1 -1
- package/dist/index41.js +51 -59
- package/dist/index41.js.map +1 -1
- package/dist/index411.js +3 -15
- package/dist/index411.js.map +1 -1
- package/dist/index412.js +15 -3
- package/dist/index412.js.map +1 -1
- package/dist/index413.js +1 -1
- package/dist/index414.js +68 -5
- package/dist/index414.js.map +1 -1
- package/dist/index415.js +30 -55
- package/dist/index415.js.map +1 -1
- package/dist/index416.js +9 -68
- package/dist/index416.js.map +1 -1
- package/dist/index417.js +148 -26
- package/dist/index417.js.map +1 -1
- package/dist/index418.js +108 -9
- package/dist/index418.js.map +1 -1
- package/dist/index419.js +5 -153
- package/dist/index419.js.map +1 -1
- package/dist/index42.js +21 -50
- package/dist/index42.js.map +1 -1
- package/dist/index420.js +54 -106
- package/dist/index420.js.map +1 -1
- package/dist/index43.js +127 -18
- package/dist/index43.js.map +1 -1
- package/dist/index44.js +39 -122
- package/dist/index44.js.map +1 -1
- package/dist/index45.js +85 -42
- package/dist/index45.js.map +1 -1
- package/dist/index46.js +123 -87
- package/dist/index46.js.map +1 -1
- package/dist/index47.js +5 -126
- package/dist/index47.js.map +1 -1
- package/dist/index48.js +332 -5
- package/dist/index48.js.map +1 -1
- package/dist/index49.js +245 -320
- package/dist/index49.js.map +1 -1
- package/dist/index5.js +2 -2
- package/dist/index50.js +23 -254
- package/dist/index50.js.map +1 -1
- package/dist/index51.js +129 -25
- package/dist/index51.js.map +1 -1
- package/dist/index52.js +24 -129
- package/dist/index52.js.map +1 -1
- package/dist/index53.js +19 -22
- package/dist/index53.js.map +1 -1
- package/dist/index54.js +134 -19
- package/dist/index54.js.map +1 -1
- package/dist/index55.js +30 -133
- package/dist/index55.js.map +1 -1
- package/dist/index56.js +24 -30
- package/dist/index56.js.map +1 -1
- package/dist/index57.js +38 -26
- package/dist/index57.js.map +1 -1
- package/dist/index58.js +19 -39
- package/dist/index58.js.map +1 -1
- package/dist/index59.js +133 -18
- package/dist/index59.js.map +1 -1
- package/dist/index6.js +4 -4
- package/dist/index60.js +49 -134
- package/dist/index60.js.map +1 -1
- package/dist/index61.js +25 -48
- package/dist/index61.js.map +1 -1
- package/dist/index62.js +57 -28
- package/dist/index62.js.map +1 -1
- package/dist/index63.js +56 -57
- package/dist/index63.js.map +1 -1
- package/dist/index64.js +5 -5
- package/dist/index64.js.map +1 -1
- package/dist/index66.js +23 -11
- package/dist/index66.js.map +1 -1
- package/dist/index67.js +232 -17
- package/dist/index67.js.map +1 -1
- package/dist/index68.js +5 -5
- package/dist/index68.js.map +1 -1
- package/dist/index7.js +11 -11
- package/dist/index70.js +11 -23
- package/dist/index70.js.map +1 -1
- package/dist/index71.js +17 -232
- package/dist/index71.js.map +1 -1
- package/dist/index72.js +6 -2
- package/dist/index72.js.map +1 -1
- package/dist/index73.js +8 -2
- package/dist/index73.js.map +1 -1
- package/dist/index74.js +6 -2
- package/dist/index74.js.map +1 -1
- package/dist/index75.js +2 -2
- package/dist/index76.js +2 -6
- package/dist/index76.js.map +1 -1
- package/dist/index77.js +2 -8
- package/dist/index77.js.map +1 -1
- package/dist/index78.js +2 -6
- package/dist/index78.js.map +1 -1
- package/dist/index8.js +2 -2
- package/dist/index9.js +1 -1
- package/package.json +1 -1
package/dist/index43.js
CHANGED
|
@@ -1,25 +1,134 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import { getCountryList as E } from "./index72.js";
|
|
2
|
+
import { getCountryCallingCode as s } from "./index47.js";
|
|
3
|
+
const f = "US", u = E(), c = /* @__PURE__ */ new Map(), m = "__default_locale__", _ = Array.from(new Set(u.map((e) => s(e)))).sort((e, t) => t.length - e.length);
|
|
4
|
+
_.reduce((e, t) => Math.max(e, t.length), 0);
|
|
5
|
+
const O = ["0011", "001", "011", "00", "810"];
|
|
6
|
+
function y(e) {
|
|
7
|
+
return e && u.includes(e) ? e : f;
|
|
8
|
+
}
|
|
9
|
+
function C(e) {
|
|
10
|
+
if (typeof Intl > "u" || typeof Intl.DisplayNames > "u")
|
|
11
|
+
return null;
|
|
12
|
+
try {
|
|
13
|
+
const t = Array.isArray(e) ? e : e ? [e] : void 0;
|
|
14
|
+
return new Intl.DisplayNames(t, {
|
|
15
|
+
type: "region"
|
|
16
|
+
});
|
|
17
|
+
} catch {
|
|
18
|
+
return null;
|
|
13
19
|
}
|
|
14
|
-
}
|
|
15
|
-
function
|
|
16
|
-
const t = (
|
|
20
|
+
}
|
|
21
|
+
function N(e) {
|
|
22
|
+
const t = C(e), r = C("en");
|
|
23
|
+
return u.map((n) => {
|
|
24
|
+
const a = s(n), o = t?.of(n) ?? r?.of(n) ?? n, i = r?.of(n) ?? o, g = T(n), l = Array.from(new Set([o, i, n.toUpperCase(), n.toLowerCase(), ...g].filter(Boolean)));
|
|
25
|
+
return {
|
|
26
|
+
value: n,
|
|
27
|
+
name: o,
|
|
28
|
+
dialCode: a,
|
|
29
|
+
label: `${o} (+${a})`,
|
|
30
|
+
flag: A(n),
|
|
31
|
+
searchableTokens: l,
|
|
32
|
+
normalizedSearchableTokens: l.map((p) => U(p))
|
|
33
|
+
};
|
|
34
|
+
}).sort((n, a) => {
|
|
35
|
+
const o = d(n.value), i = d(a.value);
|
|
36
|
+
return o !== i ? o - i : n.name.localeCompare(a.name);
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
function d(e) {
|
|
40
|
+
return e === "US" ? 0 : e === "CA" ? 1 : s(e) === "1" ? 2 : 3;
|
|
41
|
+
}
|
|
42
|
+
function R(e) {
|
|
43
|
+
return e ? Array.isArray(e) ? e.join("\0") : e : m;
|
|
44
|
+
}
|
|
45
|
+
function b(e) {
|
|
46
|
+
if (e !== m) {
|
|
47
|
+
if (e.includes("\0")) {
|
|
48
|
+
const t = e.split("\0").filter(Boolean);
|
|
49
|
+
return t.length === 0 ? void 0 : t.length === 1 ? t[0] ?? void 0 : t;
|
|
50
|
+
}
|
|
51
|
+
return e;
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
function L(e, t) {
|
|
55
|
+
const r = c.get(t);
|
|
56
|
+
if (r)
|
|
57
|
+
return r;
|
|
58
|
+
const n = N(e);
|
|
59
|
+
return c.set(t, n), n;
|
|
60
|
+
}
|
|
61
|
+
function v(e) {
|
|
17
62
|
return {
|
|
18
|
-
|
|
19
|
-
|
|
63
|
+
code: e.value,
|
|
64
|
+
name: e.name,
|
|
65
|
+
dialCode: e.dialCode,
|
|
66
|
+
flag: e.flag
|
|
20
67
|
};
|
|
21
68
|
}
|
|
69
|
+
function F(e) {
|
|
70
|
+
return {
|
|
71
|
+
code: e,
|
|
72
|
+
name: e,
|
|
73
|
+
dialCode: s(e),
|
|
74
|
+
flag: A(e)
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
function A(e) {
|
|
78
|
+
const t = e?.toUpperCase();
|
|
79
|
+
if (!t || t.length !== 2 || /[^A-Z]/.test(t))
|
|
80
|
+
return "";
|
|
81
|
+
const r = 127397;
|
|
82
|
+
return String.fromCodePoint(t.charCodeAt(0) + r, t.charCodeAt(1) + r);
|
|
83
|
+
}
|
|
84
|
+
const S = /[\u0300-\u036f]/g;
|
|
85
|
+
function h(e) {
|
|
86
|
+
return e.normalize("NFD").replace(S, "");
|
|
87
|
+
}
|
|
88
|
+
function U(e) {
|
|
89
|
+
return h(e).toLowerCase();
|
|
90
|
+
}
|
|
91
|
+
function B(e, t) {
|
|
92
|
+
let r = Number.MAX_SAFE_INTEGER;
|
|
93
|
+
for (const n of e) {
|
|
94
|
+
const a = n.indexOf(t);
|
|
95
|
+
a >= 0 && a < r && (r = a);
|
|
96
|
+
}
|
|
97
|
+
return r === Number.MAX_SAFE_INTEGER ? Number.MAX_SAFE_INTEGER : r;
|
|
98
|
+
}
|
|
99
|
+
function T(e) {
|
|
100
|
+
switch (e) {
|
|
101
|
+
case "US":
|
|
102
|
+
return ["USA", "United States", "America", "United States of America"];
|
|
103
|
+
case "GB":
|
|
104
|
+
return ["UK", "United Kingdom", "Great Britain", "England"];
|
|
105
|
+
case "AE":
|
|
106
|
+
return ["UAE", "United Arab Emirates"];
|
|
107
|
+
case "KR":
|
|
108
|
+
return ["South Korea", "Korea"];
|
|
109
|
+
case "CN":
|
|
110
|
+
return ["China", "PRC"];
|
|
111
|
+
case "CD":
|
|
112
|
+
return ["DRC", "Congo-Kinshasa"];
|
|
113
|
+
case "CG":
|
|
114
|
+
return ["Congo-Brazzaville"];
|
|
115
|
+
case "BR":
|
|
116
|
+
return ["Brazil"];
|
|
117
|
+
default:
|
|
118
|
+
return [];
|
|
119
|
+
}
|
|
120
|
+
}
|
|
22
121
|
export {
|
|
23
|
-
|
|
122
|
+
O as COMMON_IDD_PREFIXES,
|
|
123
|
+
_ as COUNTRY_DIAL_CODES,
|
|
124
|
+
f as DEFAULT_COUNTRY,
|
|
125
|
+
F as buildFallbackSelectedCountry,
|
|
126
|
+
L as getCachedCountryOptions,
|
|
127
|
+
R as getLocaleCacheKey,
|
|
128
|
+
y as getValidCountry,
|
|
129
|
+
U as normalizeSearchValue,
|
|
130
|
+
B as optionMatchIndex,
|
|
131
|
+
b as parseLocaleCacheKey,
|
|
132
|
+
v as toSelectedCountry
|
|
24
133
|
};
|
|
25
134
|
//# sourceMappingURL=index43.js.map
|
package/dist/index43.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index43.js","sources":["../src/components/PhoneNumberInput/messages.ts"],"sourcesContent":["import type { PhoneNumberInputMessages } from \"./types\"\n\n\nconst MESSAGE_DICTIONARY: Record<string, PhoneNumberInputMessages> = {\n en: {\n lengthTooLong: (country) =>\n country ? `This number looks too long for ${country}.` : \"This number looks too long.\",\n noMatches: \"No matching countries\",\n selectCountryLabel: \"Select a country\",\n selectedCountryLabel: (country) => (country ? `${country} flag` : \"Selected country\"),\n },\n fr: {\n lengthTooLong: (country) =>\n country\n ? `This number looks too long for ${country}.`\n : \"This number looks too long.\",\n noMatches: \"Aucun pays correspondant\",\n selectCountryLabel: \"Select a country\",\n selectedCountryLabel: (country) => (country ? `${country} flag` : \"Selected country\"),\n },\n}\n\nexport function resolveMessages(\n locale: string | string[] | undefined,\n overrides?: Partial<PhoneNumberInputMessages>\n): PhoneNumberInputMessages {\n const locales = Array.isArray(locale) ? locale : locale ? [locale] : []\n const preferred = locales\n .map((entry) => entry.split(\"-\")[0]?.toLowerCase())\n .find((code) => code && MESSAGE_DICTIONARY[code])\n const base = MESSAGE_DICTIONARY[preferred ?? \"en\"] ?? MESSAGE_DICTIONARY.en\n return {\n ...base,\n ...(overrides ?? {}),\n }\n}\n\n"],"names":["MESSAGE_DICTIONARY","en","lengthTooLong","country","noMatches","selectCountryLabel","selectedCountryLabel","fr","resolveMessages","locale","overrides","preferred","Array","isArray","map","entry","split","toLowerCase","find","code"],"mappings":"AAGA,MAAMA,IAA+D;AAAA,EACnEC,IAAI;AAAA,IACFC,eAAgBC,CAAAA,MACdA,IAAU,kCAAkCA,CAAO,MAAM;AAAA,IAC3DC,WAAW;AAAA,IACXC,oBAAoB;AAAA,IACpBC,sBAAuBH,CAAAA,MAAaA,IAAU,GAAGA,CAAO,UAAU;AAAA,EAAA;AAAA,EAEpEI,IAAI;AAAA,IACFL,eAAgBC,CAAAA,MACdA,IACI,kCAAkCA,CAAO,MACzC;AAAA,IACNC,WAAW;AAAA,IACXC,oBAAoB;AAAA,IACpBC,sBAAuBH,CAAAA,MAAaA,IAAU,GAAGA,CAAO,UAAU;AAAA,EAAA;AAEtE;AAEO,SAASK,EACdC,GACAC,GAC0B;AAE1B,QAAMC,KADUC,MAAMC,QAAQJ,CAAM,IAAIA,IAASA,IAAS,CAACA,CAAM,IAAI,CAAA,GAElEK,IAAKC,OAAUA,EAAMC,MAAM,GAAG,EAAE,CAAC,GAAGC,YAAAA,CAAa,EACjDC,KAAMC,OAASA,KAAQnB,EAAmBmB,CAAI,CAAC;AAElD,SAAO;AAAA,IACL,GAFWnB,EAAmBW,KAAa,IAAI,KAAKX,EAAmBC;AAAAA,IAGvE,GAAIS,KAAa,CAAA;AAAA,EAAC;AAEtB;"}
|
|
1
|
+
{"version":3,"file":"index43.js","sources":["../src/components/PhoneNumberInput/country-options.ts"],"sourcesContent":["import type { CountryCode } from \"libphonenumber-js\"\nimport { getCountryCallingCode } from \"libphonenumber-js\"\n\nimport type { CountryOption, PhoneNumberSelectedCountry } from \"./types\"\nimport { getCountryList } from \"./countries\"\n\n\nexport const DEFAULT_COUNTRY: CountryCode = \"US\"\nconst COUNTRY_OPTIONS = getCountryList()\n\nconst COUNTRY_OPTIONS_CACHE = new Map<string, CountryOption[]>()\nconst DEFAULT_LOCALE_CACHE_KEY = \"__default_locale__\"\nexport const COUNTRY_DIAL_CODES = Array.from(\n new Set(COUNTRY_OPTIONS.map((code) => getCountryCallingCode(code)))\n).sort((a, b) => b.length - a.length)\nexport const MAX_DIAL_CODE_LENGTH = COUNTRY_DIAL_CODES.reduce(\n (max, dial) => Math.max(max, dial.length),\n 0\n)\nexport const COMMON_IDD_PREFIXES = [\"0011\", \"001\", \"011\", \"00\", \"810\"]\n\nexport function getValidCountry(input: CountryCode | undefined) {\n if (!input) {\n return DEFAULT_COUNTRY\n }\n\n return COUNTRY_OPTIONS.includes(input) ? input : DEFAULT_COUNTRY\n}\n\nfunction createDisplayNames(locale?: string | string[]) {\n if (typeof Intl === \"undefined\" || typeof Intl.DisplayNames === \"undefined\") {\n return null\n }\n\n try {\n const locales = Array.isArray(locale) ? locale : locale ? [locale] : undefined\n return new Intl.DisplayNames(locales, { type: \"region\" })\n } catch {\n return null\n }\n}\n\nfunction buildCountryOptions(locale?: string | string[]) {\n const displayNames = createDisplayNames(locale)\n const englishDisplayNames = createDisplayNames(\"en\")\n\n return COUNTRY_OPTIONS\n .map((country) => {\n const dialCode = getCountryCallingCode(country)\n const localizedName = displayNames?.of(country) ?? englishDisplayNames?.of(country) ?? country\n const englishName = englishDisplayNames?.of(country) ?? localizedName\n const aliasTokens = getCountryAliases(country)\n const searchableTokens = Array.from(\n new Set(\n [localizedName, englishName, country.toUpperCase(), country.toLowerCase(), ...aliasTokens].filter(\n Boolean\n )\n )\n ) as string[]\n return {\n value: country,\n name: localizedName,\n dialCode,\n label: `${localizedName} (+${dialCode})`,\n flag: countryCodeToFlagEmoji(country),\n searchableTokens,\n normalizedSearchableTokens: searchableTokens.map((token) => normalizeSearchValue(token)),\n }\n })\n .sort((a, b) => {\n const priorityA = getCountryPriority(a.value)\n const priorityB = getCountryPriority(b.value)\n if (priorityA !== priorityB) {\n return priorityA - priorityB\n }\n return a.name.localeCompare(b.name)\n })\n}\n\nfunction getCountryPriority(code: CountryCode) {\n if (code === \"US\") return 0\n if (code === \"CA\") return 1\n if (getCountryCallingCode(code) === \"1\") return 2\n return 3\n}\n\nexport function getLocaleCacheKey(locale?: string | string[]) {\n if (!locale) {\n return DEFAULT_LOCALE_CACHE_KEY\n }\n if (Array.isArray(locale)) {\n return locale.join(\"\\u0000\")\n }\n return locale\n}\n\nexport function parseLocaleCacheKey(cacheKey: string): string | string[] | undefined {\n if (cacheKey === DEFAULT_LOCALE_CACHE_KEY) {\n return undefined\n }\n\n if (cacheKey.includes(\"\\u0000\")) {\n const parts = cacheKey.split(\"\\u0000\").filter(Boolean)\n if (parts.length === 0) {\n return undefined\n }\n if (parts.length === 1) {\n return parts[0] ?? undefined\n }\n return parts\n }\n\n return cacheKey\n}\n\nexport function getCachedCountryOptions(locale: string | string[] | undefined, cacheKey: string) {\n const cached = COUNTRY_OPTIONS_CACHE.get(cacheKey)\n if (cached) {\n return cached\n }\n const built = buildCountryOptions(locale)\n COUNTRY_OPTIONS_CACHE.set(cacheKey, built)\n return built\n}\n\nexport function toSelectedCountry(option: CountryOption): PhoneNumberSelectedCountry {\n return {\n code: option.value,\n name: option.name,\n dialCode: option.dialCode,\n flag: option.flag,\n }\n}\n\nexport function buildFallbackSelectedCountry(country: CountryCode): PhoneNumberSelectedCountry {\n return {\n code: country,\n name: country,\n dialCode: getCountryCallingCode(country),\n flag: countryCodeToFlagEmoji(country),\n }\n}\n\nfunction countryCodeToFlagEmoji(country: CountryCode) {\n const upper = country?.toUpperCase()\n\n if (!upper || upper.length !== 2 || /[^A-Z]/.test(upper)) {\n return \"\"\n }\n\n const base = 127397\n return String.fromCodePoint(\n upper.charCodeAt(0) + base,\n upper.charCodeAt(1) + base\n )\n}\n\nconst DIACRITICS_REGEX = /[\\u0300-\\u036f]/g\n\nfunction stripDiacritics(value: string) {\n return value.normalize(\"NFD\").replace(DIACRITICS_REGEX, \"\")\n}\n\nexport function normalizeSearchValue(value: string) {\n return stripDiacritics(value).toLowerCase()\n}\n\nexport function optionMatchIndex(tokens: string[], query: string) {\n let best = Number.MAX_SAFE_INTEGER\n for (const token of tokens) {\n const index = token.indexOf(query)\n if (index >= 0 && index < best) {\n best = index\n }\n }\n return best === Number.MAX_SAFE_INTEGER ? Number.MAX_SAFE_INTEGER : best\n}\n\nfunction getCountryAliases(code: CountryCode): string[] {\n switch (code) {\n case \"US\":\n return [\"USA\", \"United States\", \"America\", \"United States of America\"]\n case \"GB\":\n return [\"UK\", \"United Kingdom\", \"Great Britain\", \"England\"]\n case \"AE\":\n return [\"UAE\", \"United Arab Emirates\"]\n case \"KR\":\n return [\"South Korea\", \"Korea\"]\n case \"CN\":\n return [\"China\", \"PRC\"]\n case \"CD\":\n return [\"DRC\", \"Congo-Kinshasa\"]\n case \"CG\":\n return [\"Congo-Brazzaville\"]\n case \"BR\":\n return [\"Brazil\"]\n default:\n return []\n }\n}\n\n"],"names":["DEFAULT_COUNTRY","COUNTRY_OPTIONS","getCountryList","COUNTRY_OPTIONS_CACHE","Map","DEFAULT_LOCALE_CACHE_KEY","COUNTRY_DIAL_CODES","Array","from","Set","map","code","getCountryCallingCode","sort","a","b","length","reduce","max","dial","Math","COMMON_IDD_PREFIXES","getValidCountry","input","includes","createDisplayNames","locale","Intl","DisplayNames","locales","isArray","undefined","type","buildCountryOptions","displayNames","englishDisplayNames","country","dialCode","localizedName","of","englishName","aliasTokens","getCountryAliases","searchableTokens","toUpperCase","toLowerCase","filter","Boolean","value","name","label","flag","countryCodeToFlagEmoji","normalizedSearchableTokens","token","normalizeSearchValue","priorityA","getCountryPriority","priorityB","localeCompare","getLocaleCacheKey","join","parseLocaleCacheKey","cacheKey","parts","split","getCachedCountryOptions","cached","get","built","set","toSelectedCountry","option","buildFallbackSelectedCountry","upper","test","base","String","fromCodePoint","charCodeAt","DIACRITICS_REGEX","stripDiacritics","normalize","replace","optionMatchIndex","tokens","query","best","Number","MAX_SAFE_INTEGER","index","indexOf"],"mappings":";;AAOO,MAAMA,IAA+B,MACtCC,IAAkBC,EAAAA,GAElBC,wBAA4BC,IAAAA,GAC5BC,IAA2B,sBACpBC,IAAqBC,MAAMC,KACtC,IAAIC,IAAIR,EAAgBS,IAAKC,OAASC,EAAsBD,CAAI,CAAC,CAAC,CACpE,EAAEE,KAAK,CAACC,GAAGC,MAAMA,EAAEC,SAASF,EAAEE,MAAM;AACAV,EAAmBW,OACrD,CAACC,GAAKC,MAASC,KAAKF,IAAIA,GAAKC,EAAKH,MAAM,GACxC,CACF;AACO,MAAMK,IAAsB,CAAC,QAAQ,OAAO,OAAO,MAAM,KAAK;AAE9D,SAASC,EAAgBC,GAAgC;AAC9D,SAAKA,KAIEtB,EAAgBuB,SAASD,CAAK,I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
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
return new Intl.DisplayNames(t, {
|
|
15
|
-
type: "region"
|
|
16
|
-
});
|
|
17
|
-
} catch {
|
|
18
|
-
return null;
|
|
19
|
-
}
|
|
1
|
+
import { AsYouType as u } from "./index73.js";
|
|
2
|
+
import { validatePhoneNumberLength as a } from "./index74.js";
|
|
3
|
+
function l(t) {
|
|
4
|
+
return t.replace(/\D/g, "");
|
|
5
|
+
}
|
|
6
|
+
const f = {
|
|
7
|
+
GG: "GB",
|
|
8
|
+
JE: "GB",
|
|
9
|
+
IM: "GB"
|
|
10
|
+
};
|
|
11
|
+
function m(t) {
|
|
12
|
+
if (t)
|
|
13
|
+
return f[t] ?? t;
|
|
20
14
|
}
|
|
21
|
-
function N(
|
|
22
|
-
|
|
23
|
-
return u.map((n) => {
|
|
24
|
-
const a = s(n), o = t?.of(n) ?? r?.of(n) ?? n, i = r?.of(n) ?? o, g = T(n), l = Array.from(new Set([o, i, n.toUpperCase(), n.toLowerCase(), ...g].filter(Boolean)));
|
|
15
|
+
function N(t, n) {
|
|
16
|
+
if (t === "+")
|
|
25
17
|
return {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
searchableTokens: l,
|
|
32
|
-
normalizedSearchableTokens: l.map((p) => U(p))
|
|
18
|
+
international: "+",
|
|
19
|
+
national: "",
|
|
20
|
+
formatted: "+",
|
|
21
|
+
phoneNumber: null,
|
|
22
|
+
detectedCountry: void 0
|
|
33
23
|
};
|
|
34
|
-
|
|
35
|
-
const o = d(n.value), i = d(a.value);
|
|
36
|
-
return o !== i ? o - i : n.name.localeCompare(a.name);
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
|
-
function d(e) {
|
|
40
|
-
return e === "US" ? 0 : e === "CA" ? 1 : s(e) === "1" ? 2 : 3;
|
|
41
|
-
}
|
|
42
|
-
function R(e) {
|
|
43
|
-
return e ? Array.isArray(e) ? e.join("\0") : e : m;
|
|
44
|
-
}
|
|
45
|
-
function b(e) {
|
|
46
|
-
if (e !== m) {
|
|
47
|
-
if (e.includes("\0")) {
|
|
48
|
-
const t = e.split("\0").filter(Boolean);
|
|
49
|
-
return t.length === 0 ? void 0 : t.length === 1 ? t[0] ?? void 0 : t;
|
|
50
|
-
}
|
|
51
|
-
return e;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
function L(e, t) {
|
|
55
|
-
const r = c.get(t);
|
|
56
|
-
if (r)
|
|
57
|
-
return r;
|
|
58
|
-
const n = N(e);
|
|
59
|
-
return c.set(t, n), n;
|
|
60
|
-
}
|
|
61
|
-
function v(e) {
|
|
62
|
-
return {
|
|
63
|
-
code: e.value,
|
|
64
|
-
name: e.name,
|
|
65
|
-
dialCode: e.dialCode,
|
|
66
|
-
flag: e.flag
|
|
67
|
-
};
|
|
68
|
-
}
|
|
69
|
-
function F(e) {
|
|
24
|
+
const r = n ? new u(n) : new u(), o = r.input(t), e = r.getNumber(), c = m(e?.country ?? r.country ?? void 0), i = e?.formatInternational() ?? o, s = e?.formatNational() ?? l(i);
|
|
70
25
|
return {
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
26
|
+
international: i,
|
|
27
|
+
national: s,
|
|
28
|
+
formatted: o,
|
|
29
|
+
phoneNumber: e,
|
|
30
|
+
detectedCountry: c
|
|
75
31
|
};
|
|
76
32
|
}
|
|
77
|
-
function
|
|
78
|
-
|
|
79
|
-
if (!t || t.length !== 2 || /[^A-Z]/.test(t))
|
|
80
|
-
return "";
|
|
81
|
-
const r = 127397;
|
|
82
|
-
return String.fromCodePoint(t.charCodeAt(0) + r, t.charCodeAt(1) + r);
|
|
83
|
-
}
|
|
84
|
-
const S = /[\u0300-\u036f]/g;
|
|
85
|
-
function h(e) {
|
|
86
|
-
return e.normalize("NFD").replace(S, "");
|
|
87
|
-
}
|
|
88
|
-
function U(e) {
|
|
89
|
-
return h(e).toLowerCase();
|
|
33
|
+
function O(t, n) {
|
|
34
|
+
return t.startsWith(n) ? t.slice(n.length) : t;
|
|
90
35
|
}
|
|
91
|
-
function
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
a
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
}
|
|
99
|
-
function T(e) {
|
|
100
|
-
switch (e) {
|
|
101
|
-
case "US":
|
|
102
|
-
return ["USA", "United States", "America", "United States of America"];
|
|
103
|
-
case "GB":
|
|
104
|
-
return ["UK", "United Kingdom", "Great Britain", "England"];
|
|
105
|
-
case "AE":
|
|
106
|
-
return ["UAE", "United Arab Emirates"];
|
|
107
|
-
case "KR":
|
|
108
|
-
return ["South Korea", "Korea"];
|
|
109
|
-
case "CN":
|
|
110
|
-
return ["China", "PRC"];
|
|
111
|
-
case "CD":
|
|
112
|
-
return ["DRC", "Congo-Kinshasa"];
|
|
113
|
-
case "CG":
|
|
114
|
-
return ["Congo-Brazzaville"];
|
|
115
|
-
case "BR":
|
|
116
|
-
return ["Brazil"];
|
|
117
|
-
default:
|
|
118
|
-
return [];
|
|
36
|
+
function d(t, n) {
|
|
37
|
+
if (!n || !t)
|
|
38
|
+
return null;
|
|
39
|
+
try {
|
|
40
|
+
return a(t, n) === "TOO_LONG" ? "TOO_LONG" : null;
|
|
41
|
+
} catch {
|
|
42
|
+
return null;
|
|
119
43
|
}
|
|
120
44
|
}
|
|
121
45
|
export {
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
L as getCachedCountryOptions,
|
|
127
|
-
R as getLocaleCacheKey,
|
|
128
|
-
y as getValidCountry,
|
|
129
|
-
U as normalizeSearchValue,
|
|
130
|
-
B as optionMatchIndex,
|
|
131
|
-
b as parseLocaleCacheKey,
|
|
132
|
-
v as toSelectedCountry
|
|
46
|
+
N as formatWithAsYouType,
|
|
47
|
+
d as getLengthIssue,
|
|
48
|
+
l as sanitizeDigits,
|
|
49
|
+
O as stripPrefix
|
|
133
50
|
};
|
|
134
51
|
//# sourceMappingURL=index44.js.map
|
package/dist/index44.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index44.js","sources":["../src/components/PhoneNumberInput/country-options.ts"],"sourcesContent":["import type { CountryCode } from \"libphonenumber-js\"\nimport { getCountryCallingCode } from \"libphonenumber-js\"\n\nimport type { CountryOption, PhoneNumberSelectedCountry } from \"./types\"\nimport { getCountryList } from \"./countries\"\n\n\nexport const DEFAULT_COUNTRY: CountryCode = \"US\"\nconst COUNTRY_OPTIONS = getCountryList()\n\nconst COUNTRY_OPTIONS_CACHE = new Map<string, CountryOption[]>()\nconst DEFAULT_LOCALE_CACHE_KEY = \"__default_locale__\"\nexport const COUNTRY_DIAL_CODES = Array.from(\n new Set(COUNTRY_OPTIONS.map((code) => getCountryCallingCode(code)))\n).sort((a, b) => b.length - a.length)\nexport const MAX_DIAL_CODE_LENGTH = COUNTRY_DIAL_CODES.reduce(\n (max, dial) => Math.max(max, dial.length),\n 0\n)\nexport const COMMON_IDD_PREFIXES = [\"0011\", \"001\", \"011\", \"00\", \"810\"]\n\nexport function getValidCountry(input: CountryCode | undefined) {\n if (!input) {\n return DEFAULT_COUNTRY\n }\n\n return COUNTRY_OPTIONS.includes(input) ? input : DEFAULT_COUNTRY\n}\n\nfunction createDisplayNames(locale?: string | string[]) {\n if (typeof Intl === \"undefined\" || typeof Intl.DisplayNames === \"undefined\") {\n return null\n }\n\n try {\n const locales = Array.isArray(locale) ? locale : locale ? [locale] : undefined\n return new Intl.DisplayNames(locales, { type: \"region\" })\n } catch {\n return null\n }\n}\n\nfunction buildCountryOptions(locale?: string | string[]) {\n const displayNames = createDisplayNames(locale)\n const englishDisplayNames = createDisplayNames(\"en\")\n\n return COUNTRY_OPTIONS\n .map((country) => {\n const dialCode = getCountryCallingCode(country)\n const localizedName = displayNames?.of(country) ?? englishDisplayNames?.of(country) ?? country\n const englishName = englishDisplayNames?.of(country) ?? localizedName\n const aliasTokens = getCountryAliases(country)\n const searchableTokens = Array.from(\n new Set(\n [localizedName, englishName, country.toUpperCase(), country.toLowerCase(), ...aliasTokens].filter(\n Boolean\n )\n )\n ) as string[]\n return {\n value: country,\n name: localizedName,\n dialCode,\n label: `${localizedName} (+${dialCode})`,\n flag: countryCodeToFlagEmoji(country),\n searchableTokens,\n normalizedSearchableTokens: searchableTokens.map((token) => normalizeSearchValue(token)),\n }\n })\n .sort((a, b) => {\n const priorityA = getCountryPriority(a.value)\n const priorityB = getCountryPriority(b.value)\n if (priorityA !== priorityB) {\n return priorityA - priorityB\n }\n return a.name.localeCompare(b.name)\n })\n}\n\nfunction getCountryPriority(code: CountryCode) {\n if (code === \"US\") return 0\n if (code === \"CA\") return 1\n if (getCountryCallingCode(code) === \"1\") return 2\n return 3\n}\n\nexport function getLocaleCacheKey(locale?: string | string[]) {\n if (!locale) {\n return DEFAULT_LOCALE_CACHE_KEY\n }\n if (Array.isArray(locale)) {\n return locale.join(\"\\u0000\")\n }\n return locale\n}\n\nexport function parseLocaleCacheKey(cacheKey: string): string | string[] | undefined {\n if (cacheKey === DEFAULT_LOCALE_CACHE_KEY) {\n return undefined\n }\n\n if (cacheKey.includes(\"\\u0000\")) {\n const parts = cacheKey.split(\"\\u0000\").filter(Boolean)\n if (parts.length === 0) {\n return undefined\n }\n if (parts.length === 1) {\n return parts[0] ?? undefined\n }\n return parts\n }\n\n return cacheKey\n}\n\nexport function getCachedCountryOptions(locale: string | string[] | undefined, cacheKey: string) {\n const cached = COUNTRY_OPTIONS_CACHE.get(cacheKey)\n if (cached) {\n return cached\n }\n const built = buildCountryOptions(locale)\n COUNTRY_OPTIONS_CACHE.set(cacheKey, built)\n return built\n}\n\nexport function toSelectedCountry(option: CountryOption): PhoneNumberSelectedCountry {\n return {\n code: option.value,\n name: option.name,\n dialCode: option.dialCode,\n flag: option.flag,\n }\n}\n\nexport function buildFallbackSelectedCountry(country: CountryCode): PhoneNumberSelectedCountry {\n return {\n code: country,\n name: country,\n dialCode: getCountryCallingCode(country),\n flag: countryCodeToFlagEmoji(country),\n }\n}\n\nfunction countryCodeToFlagEmoji(country: CountryCode) {\n const upper = country?.toUpperCase()\n\n if (!upper || upper.length !== 2 || /[^A-Z]/.test(upper)) {\n return \"\"\n }\n\n const base = 127397\n return String.fromCodePoint(\n upper.charCodeAt(0) + base,\n upper.charCodeAt(1) + base\n )\n}\n\nconst DIACRITICS_REGEX = /[\\u0300-\\u036f]/g\n\nfunction stripDiacritics(value: string) {\n return value.normalize(\"NFD\").replace(DIACRITICS_REGEX, \"\")\n}\n\nexport function normalizeSearchValue(value: string) {\n return stripDiacritics(value).toLowerCase()\n}\n\nexport function optionMatchIndex(tokens: string[], query: string) {\n let best = Number.MAX_SAFE_INTEGER\n for (const token of tokens) {\n const index = token.indexOf(query)\n if (index >= 0 && index < best) {\n best = index\n }\n }\n return best === Number.MAX_SAFE_INTEGER ? Number.MAX_SAFE_INTEGER : best\n}\n\nfunction getCountryAliases(code: CountryCode): string[] {\n switch (code) {\n case \"US\":\n return [\"USA\", \"United States\", \"America\", \"United States of America\"]\n case \"GB\":\n return [\"UK\", \"United Kingdom\", \"Great Britain\", \"England\"]\n case \"AE\":\n return [\"UAE\", \"United Arab Emirates\"]\n case \"KR\":\n return [\"South Korea\", \"Korea\"]\n case \"CN\":\n return [\"China\", \"PRC\"]\n case \"CD\":\n return [\"DRC\", \"Congo-Kinshasa\"]\n case \"CG\":\n return [\"Congo-Brazzaville\"]\n case \"BR\":\n return [\"Brazil\"]\n default:\n return []\n }\n}\n\n"],"names":["DEFAULT_COUNTRY","COUNTRY_OPTIONS","getCountryList","COUNTRY_OPTIONS_CACHE","Map","DEFAULT_LOCALE_CACHE_KEY","COUNTRY_DIAL_CODES","Array","from","Set","map","code","getCountryCallingCode","sort","a","b","length","reduce","max","dial","Math","COMMON_IDD_PREFIXES","getValidCountry","input","includes","createDisplayNames","locale","Intl","DisplayNames","locales","isArray","undefined","type","buildCountryOptions","displayNames","englishDisplayNames","country","dialCode","localizedName","of","englishName","aliasTokens","getCountryAliases","searchableTokens","toUpperCase","toLowerCase","filter","Boolean","value","name","label","flag","countryCodeToFlagEmoji","normalizedSearchableTokens","token","normalizeSearchValue","priorityA","getCountryPriority","priorityB","localeCompare","getLocaleCacheKey","join","parseLocaleCacheKey","cacheKey","parts","split","getCachedCountryOptions","cached","get","built","set","toSelectedCountry","option","buildFallbackSelectedCountry","upper","test","base","String","fromCodePoint","charCodeAt","DIACRITICS_REGEX","stripDiacritics","normalize","replace","optionMatchIndex","tokens","query","best","Number","MAX_SAFE_INTEGER","index","indexOf"],"mappings":";;AAOO,MAAMA,IAA+B,MACtCC,IAAkBC,EAAAA,GAElBC,wBAA4BC,IAAAA,GAC5BC,IAA2B,sBACpBC,IAAqBC,MAAMC,KACtC,IAAIC,IAAIR,EAAgBS,IAAKC,OAASC,EAAsBD,CAAI,CAAC,CAAC,CACpE,EAAEE,KAAK,CAACC,GAAGC,MAAMA,EAAEC,SAASF,EAAEE,MAAM;AACAV,EAAmBW,OACrD,CAACC,GAAKC,MAASC,KAAKF,IAAIA,GAAKC,EAAKH,MAAM,GACxC,CACF;AACO,MAAMK,IAAsB,CAAC,QAAQ,OAAO,OAAO,MAAM,KAAK;AAE9D,SAASC,EAAgBC,GAAgC;AAC9D,SAAKA,KAIEtB,EAAgBuB,SAASD,CAAK,IAAIA,IAHhCvB;AAIX;AAEA,SAASyB,EAAmBC,GAA4B;AACtD,MAAI,OAAOC,OAAS,OAAe,OAAOA,KAAKC,eAAiB;AAC9D,WAAO;AAGT,MAAI;AACF,UAAMC,IAAUtB,MAAMuB,QAAQJ,CAAM,IAAIA,IAASA,IAAS,CAACA,CAAM,IAAIK;AACrE,WAAO,IAAIJ,KAAKC,aAAaC,GAAS;AAAA,MAAEG,MAAM;AAAA,IAAA,CAAU;AA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AAEC,QAAQH,GAAkB,EAAE;AAC5D;AAEO,SAASzB,EAAqBP,GAAe;AAClD,SAAOiC,EAAgBjC,CAAK,EAAEH,YAAAA;AAChC;AAEO,SAASuC,EAAiBC,GAAkBC,GAAe;AAChE,MAAIC,IAAOC,OAAOC;AAClB,aAAWnC,KAAS+B,GAAQ;AAC1B,UAAMK,IAAQpC,EAAMqC,QAAQL,CAAK;AACjC,IAAII,KAAS,KAAKA,IAAQH,MACxBA,IAAOG;AAAAA,EAEX;AACA,SAAOH,MAASC,OAAOC,mBAAmBD,OAAOC,mBAAmBF;AACtE;AAEA,SAAS7C,EAAkB/B,GAA6B;AACtD,UAAQA,GAAAA;AAAAA,IACR,KAAK;AACH,aAAO,CAAC,OAAO,iBAAiB,WAAW,0BAA0B;AAAA,IACvE,KAAK;AACH,aAAO,CAAC,MAAM,kBAAkB,iBAAiB,SAAS;AAAA,IAC5D,KAAK;AACH,aAAO,CAAC,OAAO,sBAAsB;AAAA,IACvC,KAAK;AACH,aAAO,CAAC,eAAe,OAAO;AAAA,IAChC,KAAK;AACH,aAAO,CAAC,SAAS,KAAK;AAAA,IACxB,KAAK;AACH,aAAO,CAAC,OAAO,gBAAgB;AAAA,IACjC,KAAK;AACH,aAAO,CAAC,mBAAmB;AAAA,IAC7B,KAAK;AACH,aAAO,CAAC,QAAQ;AAAA,IAClB;AACE,aAAO,CAAA;AAAA,EAAA;AAEX;"}
|
|
1
|
+
{"version":3,"file":"index44.js","sources":["../src/components/PhoneNumberInput/normalization.ts"],"sourcesContent":["import type { CountryCode } from \"libphonenumber-js\"\nimport { AsYouType, validatePhoneNumberLength } from \"libphonenumber-js\"\n\n\nexport type LengthIssue = \"TOO_LONG\"\n\nexport function sanitizeDigits(value: string) {\n return value.replace(/\\D/g, \"\")\n}\n\nconst DETECTED_COUNTRY_OVERRIDES: Partial<Record<CountryCode, CountryCode>> = {\n GG: \"GB\",\n JE: \"GB\",\n IM: \"GB\",\n}\n\nfunction canonicalizeDetectedCountry(candidate: CountryCode | undefined): CountryCode | undefined {\n if (!candidate) {\n return undefined\n }\n return DETECTED_COUNTRY_OVERRIDES[candidate] ?? candidate\n}\n\nexport function formatWithAsYouType(value: string, baseCountry?: CountryCode) {\n if (value === \"+\") {\n return {\n international: \"+\",\n national: \"\",\n formatted: \"+\",\n phoneNumber: null,\n detectedCountry: undefined,\n }\n }\n\n const formatter = baseCountry ? new AsYouType(baseCountry) : new AsYouType()\n const formatted = formatter.input(value)\n const phoneNumber = formatter.getNumber()\n const detectedCountry = canonicalizeDetectedCountry(\n (phoneNumber?.country ?? formatter.country ?? undefined) as CountryCode | undefined\n )\n const international = phoneNumber?.formatInternational() ?? formatted\n const national = phoneNumber?.formatNational() ?? sanitizeDigits(international)\n\n return {\n international,\n national,\n formatted,\n phoneNumber,\n detectedCountry,\n }\n}\n\nexport function stripPrefix(value: string, prefix: string) {\n return value.startsWith(prefix) ? value.slice(prefix.length) : value\n}\n\nexport function getLengthIssue(value: string, country: CountryCode | undefined): LengthIssue | null {\n if (!country || !value) {\n return null\n }\n\n try {\n const result = validatePhoneNumberLength(value, country)\n return result === \"TOO_LONG\" ? \"TOO_LONG\" : null\n } catch {\n return null\n }\n}\n"],"names":["sanitizeDigits","value","replace","DETECTED_COUNTRY_OVERRIDES","GG","JE","IM","canonicalizeDetectedCountry","candidate","formatWithAsYouType","baseCountry","international","national","formatted","phoneNumber","detectedCountry","undefined","formatter","AsYouType","input","getNumber","country","formatInternational","formatNational","stripPrefix","prefix","startsWith","slice","length","getLengthIssue","validatePhoneNumberLength"],"mappings":";;AAMO,SAASA,EAAeC,GAAe;AAC5C,SAAOA,EAAMC,QAAQ,OAAO,EAAE;AAChC;AAEA,MAAMC,IAAwE;AAAA,EAC5EC,IAAI;AAAA,EACJC,IAAI;AAAA,EACJC,IAAI;AACN;AAEA,SAASC,EAA4BC,GAA6D;AAChG,MAAKA;AAGL,WAAOL,EAA2BK,CAAS,KAAKA;AAClD;AAEO,SAASC,EAAoBR,GAAeS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0;
|
|
9
|
+
const r = Math.min(e, t.length);
|
|
10
|
+
for (let i = 0; i < r; i += 1)
|
|
11
|
+
c(t[i] ?? "") && (n += 1);
|
|
12
|
+
return n;
|
|
13
|
+
}
|
|
14
|
+
function a(t, e) {
|
|
15
|
+
if (e <= 0)
|
|
16
|
+
return t.startsWith("+") ? Math.min(1, t.length) : 0;
|
|
17
|
+
let n = 0;
|
|
18
|
+
for (let r = 0; r < t.length; r += 1)
|
|
19
|
+
if (c(t[r] ?? "") && (n += 1, n === e))
|
|
20
|
+
return r + 1;
|
|
21
|
+
return t.length;
|
|
22
|
+
}
|
|
23
|
+
function g(t) {
|
|
24
|
+
return !t || c(t) ? !1 : t !== "+";
|
|
25
|
+
}
|
|
26
|
+
function h(t, e) {
|
|
27
|
+
let n = e;
|
|
28
|
+
for (; n > 0; ) {
|
|
29
|
+
const r = t[n - 1] ?? "";
|
|
30
|
+
if (!g(r))
|
|
31
|
+
break;
|
|
32
|
+
n -= 1;
|
|
33
|
+
}
|
|
34
|
+
return n;
|
|
35
|
+
}
|
|
36
|
+
function S(t, e) {
|
|
37
|
+
let n = e;
|
|
38
|
+
for (; n < t.length; ) {
|
|
39
|
+
const r = t[n] ?? "";
|
|
40
|
+
if (!g(r))
|
|
41
|
+
break;
|
|
42
|
+
n += 1;
|
|
43
|
+
}
|
|
44
|
+
return n;
|
|
45
|
+
}
|
|
11
46
|
function m(t) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
}
|
|
15
|
-
function N(t, n) {
|
|
16
|
-
if (t === "+")
|
|
17
|
-
return {
|
|
18
|
-
international: "+",
|
|
19
|
-
national: "",
|
|
20
|
-
formatted: "+",
|
|
21
|
-
phoneNumber: null,
|
|
22
|
-
detectedCountry: void 0
|
|
23
|
-
};
|
|
24
|
-
const r = n ? new u(n) : new u(), o = r.input(t), e = r.getNumber(), c = m(e?.country ?? r.country ?? void 0), i = e?.formatInternational() ?? o, s = e?.formatNational() ?? l(i);
|
|
47
|
+
const {
|
|
48
|
+
value: e
|
|
49
|
+
} = t, n = t.selectionStart ?? e.length, r = t.selectionEnd ?? n, i = n <= 1 && e.startsWith("+"), o = r <= 1 && e.startsWith("+");
|
|
25
50
|
return {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
51
|
+
selectionStart: n,
|
|
52
|
+
selectionEnd: r,
|
|
53
|
+
startDigits: l(e, n),
|
|
54
|
+
endDigits: l(e, r),
|
|
55
|
+
preserveStartIndex: i,
|
|
56
|
+
preserveEndIndex: o,
|
|
57
|
+
wasAtStart: n === 0,
|
|
58
|
+
wasAtEnd: r === e.length
|
|
31
59
|
};
|
|
32
60
|
}
|
|
33
|
-
function
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
61
|
+
function u(t, e) {
|
|
62
|
+
if (t.selectionStart === t.selectionEnd) {
|
|
63
|
+
if (t.wasAtEnd) {
|
|
64
|
+
const f = e.length;
|
|
65
|
+
return {
|
|
66
|
+
start: f,
|
|
67
|
+
end: f
|
|
68
|
+
};
|
|
69
|
+
}
|
|
70
|
+
if (t.wasAtStart)
|
|
71
|
+
return {
|
|
72
|
+
start: 0,
|
|
73
|
+
end: 0
|
|
74
|
+
};
|
|
43
75
|
}
|
|
76
|
+
const n = t.preserveStartIndex ? Math.min(t.selectionStart, e.length) : a(e, t.startDigits), r = t.preserveEndIndex ? Math.min(t.selectionEnd, e.length) : a(e, t.endDigits);
|
|
77
|
+
let i = n, o = r;
|
|
78
|
+
t.wasAtStart && (i = 0), t.wasAtEnd && (o = e.length), t.selectionStart === t.selectionEnd && (i = o);
|
|
79
|
+
const d = Math.min(Math.max(i, 0), e.length), s = Math.min(Math.max(o, 0), e.length);
|
|
80
|
+
return d > s ? {
|
|
81
|
+
start: s,
|
|
82
|
+
end: s
|
|
83
|
+
} : {
|
|
84
|
+
start: d,
|
|
85
|
+
end: s
|
|
86
|
+
};
|
|
44
87
|
}
|
|
45
88
|
export {
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
89
|
+
m as captureSelectionSnapshot,
|
|
90
|
+
u as resolveSelection,
|
|
91
|
+
h as skipFormattingCharactersLeft,
|
|
92
|
+
S as skipFormattingCharactersRight
|
|
50
93
|
};
|
|
51
94
|
//# sourceMappingURL=index45.js.map
|
package/dist/index45.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index45.js","sources":["../src/components/PhoneNumberInput/
|
|
1
|
+
{"version":3,"file":"index45.js","sources":["../src/components/PhoneNumberInput/selection.ts"],"sourcesContent":["function isDigitCharacter(char: string) {\n if (!char) {\n return false\n }\n const code = char.charCodeAt(0)\n return code >= 48 && code <= 57\n}\n\nfunction countDigitsBefore(value: string, index: number) {\n let count = 0\n const limit = Math.min(index, value.length)\n for (let position = 0; position < limit; position += 1) {\n if (isDigitCharacter(value[position] ?? \"\")) {\n count += 1\n }\n }\n return count\n}\n\nfunction findIndexForDigitCount(value: string, digitCount: number) {\n if (digitCount <= 0) {\n return value.startsWith(\"+\") ? Math.min(1, value.length) : 0\n }\n\n let seen = 0\n for (let index = 0; index < value.length; index += 1) {\n if (isDigitCharacter(value[index] ?? \"\")) {\n seen += 1\n if (seen === digitCount) {\n return index + 1\n }\n }\n }\n\n return value.length\n}\n\nfunction isFormattingCharacter(char: string) {\n if (!char) {\n return false\n }\n if (isDigitCharacter(char)) {\n return false\n }\n return char !== \"+\"\n}\n\nexport function skipFormattingCharactersLeft(value: string, index: number) {\n let position = index\n while (position > 0) {\n const next = value[position - 1] ?? \"\"\n if (!isFormattingCharacter(next)) {\n break\n }\n position -= 1\n }\n return position\n}\n\nexport function skipFormattingCharactersRight(value: string, index: number) {\n let position = index\n while (position < value.length) {\n const next = value[position] ?? \"\"\n if (!isFormattingCharacter(next)) {\n break\n }\n position += 1\n }\n return position\n}\n\ntype SelectionSnapshot = {\n selectionStart: number\n selectionEnd: number\n startDigits: number\n endDigits: number\n preserveStartIndex: boolean\n preserveEndIndex: boolean\n wasAtStart: boolean\n wasAtEnd: boolean\n}\n\nexport function captureSelectionSnapshot(input: HTMLInputElement): SelectionSnapshot {\n const { value } = input\n const selectionStart = input.selectionStart ?? value.length\n const selectionEnd = input.selectionEnd ?? selectionStart\n const preserveStartIndex = selectionStart <= 1 && value.startsWith(\"+\")\n const preserveEndIndex = selectionEnd <= 1 && value.startsWith(\"+\")\n\n return {\n selectionStart,\n selectionEnd,\n startDigits: countDigitsBefore(value, selectionStart),\n endDigits: countDigitsBefore(value, selectionEnd),\n preserveStartIndex,\n preserveEndIndex,\n wasAtStart: selectionStart === 0,\n wasAtEnd: selectionEnd === value.length,\n }\n}\n\nexport function resolveSelection(snapshot: SelectionSnapshot, value: string) {\n if (snapshot.selectionStart === snapshot.selectionEnd) {\n if (snapshot.wasAtEnd) {\n const end = value.length\n return { start: end, end }\n }\n if (snapshot.wasAtStart) {\n return { start: 0, end: 0 }\n }\n }\n\n const start = snapshot.preserveStartIndex\n ? Math.min(snapshot.selectionStart, value.length)\n : findIndexForDigitCount(value, snapshot.startDigits)\n const end = snapshot.preserveEndIndex\n ? Math.min(snapshot.selectionEnd, value.length)\n : findIndexForDigitCount(value, snapshot.endDigits)\n\n let resolvedStart = start\n let resolvedEnd = end\n\n if (snapshot.wasAtStart) {\n resolvedStart = 0\n }\n\n if (snapshot.wasAtEnd) {\n resolvedEnd = value.length\n }\n\n if (snapshot.selectionStart === snapshot.selectionEnd) {\n resolvedStart = resolvedEnd\n }\n\n const clampedStart = Math.min(Math.max(resolvedStart, 0), value.length)\n const clampedEnd = Math.min(Math.max(resolvedEnd, 0), value.length)\n\n if (clampedStart > clampedEnd) {\n return { start: clampedEnd, end: clampedEnd }\n }\n\n return { start: clampedStart, end: clampedEnd }\n}\n\n"],"names":["isDigitCharacter","char","code","charCodeAt","countDigitsBefore","value","index","count","limit","Math","min","length","position","findIndexForDigitCount","digitCount","startsWith","seen","isFormattingCharacter","skipFormattingCharactersLeft","next","skipFormattingCharactersRight","captureSelectionSnapshot","input","selectionStart","selectionEnd","preserveStartIndex","preserveEndIndex","startDigits","endDigits","wasAtStart","wasAtEnd","resolveSelection","snapshot","end","start","resolvedStart","resolvedEnd","clampedStart","max","clampedEnd"],"mappings":"AAAA,SAASA,EAAiBC,GAAc;AACtC,MAAI,CAACA;AACH,WAAO;AAET,QAAMC,IAAOD,EAAKE,WAAW,CAAC;AAC9B,SAAOD,KAAQ,MAAMA,KAAQ;AAC/B;AAEA,SAASE,EAAkBC,GAAeC,GAAe;AACvD,MAAIC,IAAQ;AACZ,QAAMC,IAAQC,KAAKC,IAAIJ,GAAOD,EAAMM,MAAM;AAC1C,WAASC,IAAW,GAAGA,IAAWJ,GAAOI,KAAY;AACnD,IAAIZ,EAAiBK,EAAMO,CAAQ,KAAK,EAAE,MACxCL,KAAS;AAGb,SAAOA;AACT;AAEA,SAASM,EAAuBR,GAAeS,GAAoB;AACjE,MAAIA,KAAc;AAChB,WAAOT,EAAMU,WAAW,GAAG,IAAIN,KAAKC,IAAI,GAAGL,EAAMM,MAAM,IAAI;AAG7D,MAAIK,IAAO;AACX,WAASV,IAAQ,GAAGA,IAAQD,EAAMM,QAAQL,KAAS;AACjD,QAAIN,EAAiBK,EAAMC,CAAK,KAAK,EAAE,MACrCU,KAAQ,GACJA,MAASF;AACX,aAAOR,IAAQ;AAKrB,SAAOD,EAAMM;AACf;AAEA,SAASM,EAAsBhB,GAAc;AAI3C,SAHI,CAACA,KAGDD,EAAiBC,CAAI,IAChB,KAEFA,MAAS;AAClB;AAEO,SAASiB,EAA6Bb,GAAeC,GAAe;AACzE,MAAIM,IAAWN;AACf,SAAOM,IAAW,KAAG;AACnB,UAAMO,IAAOd,EAAMO,IAAW,CAAC,KAAK;AACpC,QAAI,CAACK,EAAsBE,CAAI;AAC7B;AAEFP,IAAAA,KAAY;AAAA,EACd;AACA,SAAOA;AACT;A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