@tcn/ui 0.0.4 → 0.2.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/README.md +38 -3
- package/dist/actions/button/base_button/base_button.d.ts.map +1 -1
- package/dist/actions/button/base_button/base_button.js +17 -12
- package/dist/actions/button/base_button/base_button.js.map +1 -1
- package/dist/actions/button/button/button.d.ts.map +1 -1
- package/dist/actions/button/button/button.js +7 -7
- package/dist/actions/button/button/button.js.map +1 -1
- package/dist/actions/button/slim_button/slim_button.js +2 -2
- package/dist/actions/button/slim_button/slim_button.js.map +1 -1
- package/dist/button.css +1 -1
- package/dist/draggable.css +1 -0
- package/dist/feedback/progress/progress_bar.js +1 -1
- package/dist/footer.css +1 -1
- package/dist/form/field/common/field_description.js +1 -1
- package/dist/form/field/common/field_error.js +4 -3
- package/dist/form/field/common/field_error.js.map +1 -1
- package/dist/form/field/common/field_label.js +1 -1
- package/dist/inputs/date_picker/date_picker_date.js +1 -1
- package/dist/inputs/date_picker/date_picker_day.js +1 -1
- package/dist/inputs/date_picker/date_picker_time_selector.js +1 -1
- package/dist/inputs/date_picker/date_picker_year_selector.js +1 -1
- package/dist/inputs/input/input.d.ts +2 -2
- package/dist/inputs/input/input.d.ts.map +1 -1
- package/dist/inputs/input/input.js.map +1 -1
- package/dist/inputs/options/option.d.ts +1 -0
- package/dist/inputs/options/option.d.ts.map +1 -1
- package/dist/inputs/options/option.js.map +1 -1
- package/dist/inputs/phone_number_input/phone_number_input.d.ts +8 -1
- package/dist/inputs/phone_number_input/phone_number_input.d.ts.map +1 -1
- package/dist/inputs/phone_number_input/phone_number_input.js +187 -137
- package/dist/inputs/phone_number_input/phone_number_input.js.map +1 -1
- package/dist/inputs/suggestions/suggestion_item.d.ts +1 -1
- package/dist/inputs/suggestions/suggestion_item.d.ts.map +1 -1
- package/dist/inputs/suggestions/suggestion_item.js +23 -18
- package/dist/inputs/suggestions/suggestion_item.js.map +1 -1
- package/dist/inputs/suggestions/suggestion_list.d.ts +1 -1
- package/dist/inputs/suggestions/suggestion_list.d.ts.map +1 -1
- package/dist/inputs/suggestions/suggestion_list.js +106 -96
- package/dist/inputs/suggestions/suggestion_list.js.map +1 -1
- package/dist/inputs/textarea/textarea.d.ts +2 -2
- package/dist/inputs/textarea/textarea.d.ts.map +1 -1
- package/dist/inputs/textarea/textarea.js.map +1 -1
- package/dist/layouts/footer/footer.js +5 -5
- package/dist/layouts/footer/footer.js.map +1 -1
- package/dist/layouts/header/header.d.ts.map +1 -1
- package/dist/layouts/header/header.js.map +1 -1
- package/dist/layouts/index.d.ts +3 -2
- package/dist/layouts/index.d.ts.map +1 -1
- package/dist/layouts/index.js +26 -24
- package/dist/layouts/index.js.map +1 -1
- package/dist/layouts/list/item.d.ts +1 -0
- package/dist/layouts/list/item.d.ts.map +1 -1
- package/dist/layouts/list/item.js +17 -6
- package/dist/layouts/list/item.js.map +1 -1
- package/dist/layouts/list/list.js +10 -10
- package/dist/layouts/list/list.js.map +1 -1
- package/dist/overlay/context_menu/context_menu.js +4 -4
- package/dist/overlay/frame/frame.d.ts +11 -0
- package/dist/overlay/frame/frame.d.ts.map +1 -0
- package/dist/overlay/frame/frame.js +18 -0
- package/dist/overlay/frame/frame.js.map +1 -0
- package/dist/overlay/index.d.ts +1 -0
- package/dist/overlay/index.d.ts.map +1 -1
- package/dist/overlay/index.js +5 -3
- package/dist/overlay/index.js.map +1 -1
- package/dist/overlay/popper/popper.js +12 -12
- package/dist/{portal-qqIp4SIl.js → overlay/portal/portal.js} +3 -3
- package/dist/overlay/portal/portal.js.map +1 -0
- package/dist/overlay/portal/portal_platform.js +3 -4
- package/dist/overlay/portal/portal_platform.js.map +1 -1
- package/dist/phone_number_input.css +1 -1
- package/dist/slim_button.css +1 -1
- package/dist/stacks/box/box.d.ts +1 -1
- package/dist/stacks/box/box.d.ts.map +1 -1
- package/dist/stacks/box/box.js.map +1 -1
- package/dist/surfaces/card/card.d.ts.map +1 -1
- package/dist/surfaces/card/card.js +7 -16
- package/dist/surfaces/card/card.js.map +1 -1
- package/dist/surfaces/confirm/confirm.js +4 -4
- package/dist/surfaces/index.d.ts +2 -2
- package/dist/surfaces/index.d.ts.map +1 -1
- package/dist/surfaces/index.js +22 -22
- package/dist/surfaces/modal/modal.d.ts +3 -2
- package/dist/surfaces/modal/modal.d.ts.map +1 -1
- package/dist/surfaces/modal/modal.js +14 -13
- package/dist/surfaces/modal/modal.js.map +1 -1
- package/dist/surfaces/window/window.d.ts +3 -2
- package/dist/surfaces/window/window.d.ts.map +1 -1
- package/dist/surfaces/window/window.js +17 -7
- package/dist/surfaces/window/window.js.map +1 -1
- package/dist/themes/index.js +6 -141
- package/dist/themes/index.js.map +1 -1
- package/dist/themes/stylesheets/reset.js +140 -0
- package/dist/themes/stylesheets/reset.js.map +1 -0
- package/dist/themes/themes/ergo/ergo_theme.js +664 -0
- package/dist/themes/themes/ergo/ergo_theme.js.map +1 -0
- package/dist/tokens/bubble/bubble.js +17 -16
- package/dist/tokens/bubble/bubble.js.map +1 -1
- package/dist/tokens/chip/chip.js +9 -8
- package/dist/tokens/chip/chip.js.map +1 -1
- package/dist/typography/title/title.d.ts +2 -1
- package/dist/typography/title/title.d.ts.map +1 -1
- package/dist/typography/title/title.js +24 -23
- package/dist/typography/title/title.js.map +1 -1
- package/dist/utils/dnd/context.d.ts +4 -0
- package/dist/utils/dnd/context.d.ts.map +1 -0
- package/dist/utils/dnd/context.js +20 -0
- package/dist/utils/dnd/context.js.map +1 -0
- package/dist/utils/dnd/draggable/draggable.d.ts +7 -0
- package/dist/utils/dnd/draggable/draggable.d.ts.map +1 -0
- package/dist/utils/dnd/draggable/draggable.js +27 -0
- package/dist/utils/dnd/draggable/draggable.js.map +1 -0
- package/dist/utils/dnd/handle.d.ts +6 -0
- package/dist/utils/dnd/handle.d.ts.map +1 -0
- package/dist/utils/dnd/handle.js +22 -0
- package/dist/utils/dnd/handle.js.map +1 -0
- package/dist/utils/dnd/hooks/use_drag_container.d.ts +7 -0
- package/dist/utils/dnd/hooks/use_drag_container.d.ts.map +1 -0
- package/dist/utils/dnd/hooks/use_drag_container.js +30 -0
- package/dist/utils/dnd/hooks/use_drag_container.js.map +1 -0
- package/dist/utils/{hooks → dnd/hooks}/use_draggable.d.ts +3 -3
- package/dist/utils/dnd/hooks/use_draggable.d.ts.map +1 -0
- package/dist/utils/dnd/hooks/use_draggable.js +41 -0
- package/dist/utils/dnd/hooks/use_draggable.js.map +1 -0
- package/dist/utils/dnd/types.d.ts +10 -0
- package/dist/utils/dnd/types.d.ts.map +1 -0
- package/dist/utils/dnd/types.js +2 -0
- package/dist/utils/dnd/types.js.map +1 -0
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -1
- package/package.json +9 -3
- package/src/actions/button/base_button/base_button.tsx +7 -2
- package/src/actions/button/button/button.module.css +0 -78
- package/src/actions/button/button/button.tsx +2 -4
- package/src/actions/button/slim_button/slim_button.module.css +0 -26
- package/src/actions/button/slim_button/slim_button.tsx +1 -1
- package/src/inputs/input/input.tsx +3 -2
- package/src/inputs/options/option.tsx +1 -0
- package/src/inputs/phone_number_input/phone_number_input.module.css +12 -0
- package/src/inputs/phone_number_input/phone_number_input.stories.tsx +8 -0
- package/src/inputs/phone_number_input/phone_number_input.tsx +107 -21
- package/src/inputs/suggestions/suggestion_item.tsx +12 -2
- package/src/inputs/suggestions/suggestion_list.tsx +22 -3
- package/src/inputs/textarea/textarea.tsx +2 -2
- package/src/layouts/footer/footer.module.css +0 -1
- package/src/layouts/footer/footer.tsx +1 -1
- package/src/layouts/header/header.tsx +0 -1
- package/src/layouts/index.ts +3 -2
- package/src/layouts/list/item.tsx +10 -2
- package/src/layouts/list/list.tsx +2 -2
- package/src/overlay/frame/frame.stories.tsx +40 -0
- package/src/overlay/frame/frame.tsx +34 -0
- package/src/overlay/frame/frame_stories.module.css +14 -0
- package/src/overlay/index.ts +1 -0
- package/src/stacks/box/box.tsx +8 -2
- package/src/surfaces/card/card.tsx +2 -8
- package/src/surfaces/index.ts +2 -2
- package/src/surfaces/modal/__stories__/modal.stories.tsx +19 -27
- package/src/surfaces/modal/modal.tsx +13 -10
- package/src/surfaces/panel/__stories__/panel.stories.tsx +13 -12
- package/src/surfaces/window/window.stories.tsx +37 -4
- package/src/surfaces/window/window.tsx +14 -6
- package/src/themes/themes/ergo/__stories__/components/material_picker/sb_inverted_materials.module.css +34 -0
- package/src/themes/themes/ergo/__stories__/components/material_picker/sb_material_picker.tsx +52 -0
- package/src/themes/themes/ergo/__stories__/components/tone_picker/sb_card.module.css +5 -0
- package/src/themes/themes/ergo/__stories__/components/tone_picker/sb_tone_card.tsx +40 -0
- package/src/themes/themes/ergo/__stories__/components/tone_picker/sb_tone_picker.tsx +83 -0
- package/src/themes/themes/ergo/__stories__/components/tone_picker/types.ts +7 -0
- package/src/themes/themes/ergo/__stories__/material.stories.tsx +154 -0
- package/src/themes/themes/ergo/__stories__/sb_materials.module.css +110 -0
- package/src/themes/themes/ergo/__stories__/utils.ts +92 -0
- package/src/themes/themes/ergo/ergo_theme.css +358 -26
- package/src/typography/title/title.tsx +23 -19
- package/src/utils/dnd/__stories__/draggable.stories.tsx +48 -0
- package/src/utils/dnd/__stories__/draggable_stories.module.css +21 -0
- package/src/utils/{__stories__ → dnd/__stories__}/use_draggable.stories.tsx +15 -10
- package/src/utils/dnd/context.ts +24 -0
- package/src/utils/dnd/draggable/draggable.module.css +8 -0
- package/src/utils/dnd/draggable/draggable.tsx +42 -0
- package/src/utils/dnd/handle.tsx +32 -0
- package/src/utils/dnd/hooks/use_drag_container.ts +42 -0
- package/src/utils/{hooks → dnd/hooks}/use_draggable.ts +23 -17
- package/src/utils/dnd/types.ts +6 -0
- package/src/utils/index.ts +1 -1
- package/tsconfig.json +0 -3
- package/dist/card.css +0 -1
- package/dist/portal-qqIp4SIl.js.map +0 -1
- package/dist/themes/stylesheets/reset.css +0 -1
- package/dist/themes/themes/ergo/ergo_theme.css +0 -1
- package/dist/themes/themes/windows_98/windows_98.css +0 -1
- package/dist/title.module-B16de2jd.js +0 -5
- package/dist/title.module-B16de2jd.js.map +0 -1
- package/dist/utils/hooks/use_draggable.d.ts.map +0 -1
- package/dist/utils/hooks/use_draggable.js +0 -30
- package/dist/utils/hooks/use_draggable.js.map +0 -1
- package/src/surfaces/card/card.module.css +0 -5
- /package/dist/{overlay/portal/portal.css → portal_platform.css} +0 -0
|
@@ -1,50 +1,62 @@
|
|
|
1
|
-
import { jsxs as
|
|
2
|
-
import { HStack as
|
|
3
|
-
import { clsx as
|
|
4
|
-
import
|
|
1
|
+
import { jsxs as Q, jsx as i, Fragment as le } from "react/jsx-runtime";
|
|
2
|
+
import { HStack as X } from "../../stacks/h_stack.js";
|
|
3
|
+
import { clsx as d } from "clsx";
|
|
4
|
+
import me, { useRef as Y, useState as m, useMemo as Z, Children as fe, isValidElement as he, useLayoutEffect as A, useCallback as be } from "react";
|
|
5
5
|
import "../../actions/button/base_button/base_button.js";
|
|
6
6
|
import "../../actions/button/button_group/button_group.js";
|
|
7
|
-
import { SlimButton as
|
|
7
|
+
import { SlimButton as de } from "../../actions/button/slim_button/slim_button.js";
|
|
8
8
|
import "../../actions/button/button/button.js";
|
|
9
9
|
import "../../actions/button/select_group/select_group.js";
|
|
10
10
|
import "../../actions/button/select_group/single_select_group.js";
|
|
11
|
-
import { Select as
|
|
12
|
-
import { MaskInput as
|
|
13
|
-
import { countriesPhoneInformation as
|
|
14
|
-
import { NotebookIcon as
|
|
15
|
-
import { Option as
|
|
16
|
-
import { SuggestionList as
|
|
17
|
-
import { stripNonNumericAfterCountryCode as
|
|
18
|
-
import
|
|
11
|
+
import { Select as ke } from "../select/select.js";
|
|
12
|
+
import { MaskInput as ee } from "../mask_input/mask_input.js";
|
|
13
|
+
import { countriesPhoneInformation as $ } from "./countries_phone_information.js";
|
|
14
|
+
import { NotebookIcon as Ie } from "@tcn/icons/notebook_icon.js";
|
|
15
|
+
import { Option as F } from "../options/option.js";
|
|
16
|
+
import { SuggestionList as Ne } from "../suggestions/suggestion_list.js";
|
|
17
|
+
import { stripNonNumericAfterCountryCode as S } from "./utils.js";
|
|
18
|
+
import "../../utils/focus_redirect.js";
|
|
19
|
+
import "../../utils/click_away_listener.js";
|
|
20
|
+
import "../../utils/scroll_away_listener.js";
|
|
21
|
+
import { useForkRef as ye } from "../../utils/hooks/use_fork_ref.js";
|
|
22
|
+
import "../../utils/hooks/use_resize_observer.js";
|
|
23
|
+
import '../../phone_number_input.css';const xe = "_phone-number-input_5c4483d", ge = "_phone-number-input-select_a7b33ac", Pe = "_phone-number-input-input_5b14556", Se = "_phone-number-input-phone-book-popover_1511f35", _e = "_phone-number-input-phone-book_7999ca1", Be = "_phone-number-input-obfuscated_5a0ed8c", f = { "phone-number-input": xe, "phone-number-input-select": ge, "phone-number-input-input": Pe, "phone-number-input-phone-book-popover": Se, "phone-number-input-phone-book": _e, "phone-number-input-obfuscated": Be }, Oe = "•";
|
|
24
|
+
function Ve(o) {
|
|
25
|
+
return o.map((n) => ({
|
|
26
|
+
...n,
|
|
27
|
+
placeholder: n.mask.replace(/[9a*]/g, Oe)
|
|
28
|
+
}));
|
|
29
|
+
}
|
|
30
|
+
const v = $.map((o) => ({
|
|
19
31
|
name: o.name,
|
|
20
32
|
selectedLabel: o.prefix,
|
|
21
33
|
optionLabel: `${o.prefix} (${o.code}) ${o.unicodeFlag}`,
|
|
22
34
|
value: o.code,
|
|
23
35
|
keywords: o.keywords
|
|
24
36
|
}));
|
|
25
|
-
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
|
|
37
|
+
v.sort((o, n) => parseInt(o.value) - parseInt(n.value));
|
|
38
|
+
const B = /* @__PURE__ */ new Map(), k = /* @__PURE__ */ new Map();
|
|
39
|
+
$.forEach((o) => {
|
|
40
|
+
k.set(o.code, o), B.has(o.prefix) ? B.get(o.prefix)?.push(o) : B.set(o.prefix, [o]);
|
|
29
41
|
});
|
|
30
|
-
function
|
|
42
|
+
function Me(o) {
|
|
31
43
|
if (o != null) {
|
|
32
44
|
const n = {};
|
|
33
|
-
return o.forEach((
|
|
34
|
-
n[
|
|
35
|
-
}),
|
|
36
|
-
|
|
45
|
+
return o.forEach((r) => {
|
|
46
|
+
n[r] = !0;
|
|
47
|
+
}), v.filter((r) => !!n[r.value]).map((r) => /* @__PURE__ */ i(
|
|
48
|
+
F,
|
|
37
49
|
{
|
|
38
|
-
value:
|
|
39
|
-
label:
|
|
40
|
-
keywords:
|
|
41
|
-
children:
|
|
50
|
+
value: r.value,
|
|
51
|
+
label: r.selectedLabel,
|
|
52
|
+
keywords: r.keywords,
|
|
53
|
+
children: r.optionLabel
|
|
42
54
|
},
|
|
43
|
-
|
|
55
|
+
r.value
|
|
44
56
|
));
|
|
45
57
|
} else
|
|
46
|
-
return
|
|
47
|
-
|
|
58
|
+
return v.map((n) => /* @__PURE__ */ i(
|
|
59
|
+
F,
|
|
48
60
|
{
|
|
49
61
|
value: n.value,
|
|
50
62
|
label: n.selectedLabel,
|
|
@@ -54,154 +66,192 @@ function be(o) {
|
|
|
54
66
|
n.value
|
|
55
67
|
));
|
|
56
68
|
}
|
|
57
|
-
function
|
|
58
|
-
for (let
|
|
59
|
-
const
|
|
60
|
-
if (
|
|
61
|
-
const
|
|
62
|
-
(
|
|
69
|
+
function _(o, n, r) {
|
|
70
|
+
for (let h = 5; h > 1; h--) {
|
|
71
|
+
const c = o.slice(0, h), u = B.get(c);
|
|
72
|
+
if (u != null) {
|
|
73
|
+
const I = u.find(
|
|
74
|
+
(O) => O.code === n
|
|
63
75
|
);
|
|
64
|
-
return
|
|
76
|
+
return I ?? u[0];
|
|
65
77
|
}
|
|
66
78
|
}
|
|
67
|
-
return
|
|
79
|
+
return k.get(r.toUpperCase()) || k.get("US");
|
|
68
80
|
}
|
|
69
|
-
const
|
|
81
|
+
const Ye = me.forwardRef(function({
|
|
70
82
|
value: n = "",
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
83
|
+
name: r,
|
|
84
|
+
autoComplete: h,
|
|
85
|
+
defaultCountry: c = "US",
|
|
86
|
+
onChange: u,
|
|
87
|
+
countrySelectRef: I,
|
|
88
|
+
phoneNumberInputRef: O,
|
|
89
|
+
disabled: l = !1,
|
|
90
|
+
allowedCountryCodes: U,
|
|
91
|
+
children: T,
|
|
92
|
+
...oe
|
|
93
|
+
}, ne) {
|
|
94
|
+
const N = Y(n), [j, V] = m(
|
|
81
95
|
null
|
|
82
|
-
),
|
|
96
|
+
), z = j != null, [b, M] = m(c), H = _(
|
|
83
97
|
n,
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
), [
|
|
87
|
-
const e = n.split(
|
|
88
|
-
return e == null ? "" :
|
|
89
|
-
}),
|
|
90
|
-
(e) =>
|
|
91
|
-
), [
|
|
92
|
-
|
|
93
|
-
]), G =
|
|
94
|
-
function
|
|
95
|
-
const
|
|
96
|
-
if (
|
|
98
|
+
b,
|
|
99
|
+
c
|
|
100
|
+
), [y, x] = m(() => {
|
|
101
|
+
const e = n.split(H.prefix)[1];
|
|
102
|
+
return e == null ? "" : S(e);
|
|
103
|
+
}), D = Z(() => fe.toArray(T).filter(
|
|
104
|
+
(e) => he(e) && e.type === F
|
|
105
|
+
), [T]), R = D.length > 0, [C, g] = m(H.code), [W, P] = m([
|
|
106
|
+
...$[0].masks
|
|
107
|
+
]), [a, E] = m(!1), [q, G] = m(!1), L = Y(null), J = ye(O, L), te = Z(() => Me(U), [U]);
|
|
108
|
+
function re(e) {
|
|
109
|
+
const t = k.get(e);
|
|
110
|
+
if (t == null || (g(t.code), P([...t.masks]), M(t.code), y == null))
|
|
97
111
|
return;
|
|
98
|
-
const
|
|
99
|
-
|
|
112
|
+
const p = `${t.prefix}${S(y)}`;
|
|
113
|
+
N.current = p, u && u(p, !1);
|
|
100
114
|
}
|
|
101
|
-
|
|
102
|
-
const e =
|
|
115
|
+
A(() => {
|
|
116
|
+
const e = _(
|
|
103
117
|
n,
|
|
104
|
-
|
|
105
|
-
|
|
118
|
+
b,
|
|
119
|
+
c
|
|
106
120
|
);
|
|
107
|
-
|
|
108
|
-
}, [n,
|
|
109
|
-
function
|
|
110
|
-
const
|
|
111
|
-
|
|
121
|
+
g(e.code), P([...e.masks]), M(e.code);
|
|
122
|
+
}, [n, b, c]);
|
|
123
|
+
function ue(e) {
|
|
124
|
+
const t = k.get(C)?.prefix, p = S(e), s = t + p;
|
|
125
|
+
a && E(!1), N.current = s, y !== e && x(e), u && u(s, !1);
|
|
112
126
|
}
|
|
113
|
-
function
|
|
114
|
-
|
|
127
|
+
function se(e) {
|
|
128
|
+
V(z ? null : e.currentTarget);
|
|
115
129
|
}
|
|
116
|
-
function
|
|
117
|
-
|
|
130
|
+
function K() {
|
|
131
|
+
V(null);
|
|
118
132
|
}
|
|
119
|
-
function
|
|
120
|
-
|
|
133
|
+
function pe(e, t, p, s) {
|
|
134
|
+
E(s), w(e, s), K();
|
|
121
135
|
}
|
|
122
|
-
function
|
|
136
|
+
function ce(e) {
|
|
123
137
|
if (e.startsWith("+")) {
|
|
124
|
-
const
|
|
138
|
+
const t = _(
|
|
125
139
|
e,
|
|
126
|
-
|
|
127
|
-
|
|
140
|
+
b,
|
|
141
|
+
c
|
|
128
142
|
);
|
|
129
|
-
|
|
130
|
-
const
|
|
131
|
-
return
|
|
143
|
+
g(t.code), P([...t.masks]);
|
|
144
|
+
const p = e.split(t.prefix)[1];
|
|
145
|
+
return x(p), p;
|
|
132
146
|
}
|
|
133
147
|
return e;
|
|
134
148
|
}
|
|
135
|
-
|
|
136
|
-
(
|
|
137
|
-
|
|
149
|
+
function ae(e) {
|
|
150
|
+
G(!0), E(!1), x(e);
|
|
151
|
+
const t = k.get(C)?.prefix, p = S(e), s = t + p;
|
|
152
|
+
N.current = s, u && u(s, !1);
|
|
153
|
+
}
|
|
154
|
+
const w = be(
|
|
155
|
+
(e, t = !1) => {
|
|
156
|
+
const p = N.current, s = _(
|
|
138
157
|
e,
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
),
|
|
142
|
-
|
|
158
|
+
b,
|
|
159
|
+
c
|
|
160
|
+
), ie = e.split(s.prefix)[1];
|
|
161
|
+
g(s.code), P([...s.masks]), M(s.code), p !== e && (x(ie), u && u(e, t));
|
|
143
162
|
},
|
|
144
|
-
[
|
|
163
|
+
[c, b, u]
|
|
145
164
|
);
|
|
146
|
-
return
|
|
147
|
-
|
|
148
|
-
}, [n,
|
|
149
|
-
|
|
165
|
+
return A(() => {
|
|
166
|
+
w(n);
|
|
167
|
+
}, [n, w]), A(() => {
|
|
168
|
+
q && !a && L.current && (L.current.focus(), G(!1));
|
|
169
|
+
}, [q, a]), /* @__PURE__ */ Q(
|
|
170
|
+
X,
|
|
150
171
|
{
|
|
151
|
-
ref:
|
|
152
|
-
className:
|
|
172
|
+
ref: ne,
|
|
173
|
+
className: d(f["phone-number-input"], "phone-number-input"),
|
|
153
174
|
height: "auto",
|
|
154
|
-
...
|
|
175
|
+
...oe,
|
|
155
176
|
children: [
|
|
156
|
-
/* @__PURE__ */
|
|
157
|
-
|
|
177
|
+
/* @__PURE__ */ i(
|
|
178
|
+
ke,
|
|
158
179
|
{
|
|
159
|
-
className:
|
|
160
|
-
ref:
|
|
180
|
+
className: d(f["phone-number-input-select"], "phone-number-input-select"),
|
|
181
|
+
ref: I,
|
|
161
182
|
width: "auto",
|
|
162
|
-
value:
|
|
163
|
-
onChange:
|
|
164
|
-
disabled:
|
|
165
|
-
"data-is-disabled":
|
|
166
|
-
|
|
183
|
+
value: a ? "" : C,
|
|
184
|
+
onChange: re,
|
|
185
|
+
disabled: l || a,
|
|
186
|
+
"data-is-disabled": l || a,
|
|
187
|
+
"data-is-obfuscated": a,
|
|
188
|
+
placeholder: a ? "––" : void 0,
|
|
189
|
+
children: te
|
|
167
190
|
}
|
|
168
191
|
),
|
|
169
|
-
/* @__PURE__ */
|
|
170
|
-
|
|
192
|
+
/* @__PURE__ */ i(X, { width: "flex", className: d(f["phone-number-input-container"]), children: a ? /* @__PURE__ */ i(
|
|
193
|
+
ee,
|
|
171
194
|
{
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
195
|
+
name: r,
|
|
196
|
+
autoComplete: h,
|
|
197
|
+
ref: J,
|
|
198
|
+
value: "",
|
|
199
|
+
mask: Ve(W),
|
|
200
|
+
onChange: ae,
|
|
201
|
+
disabled: l,
|
|
202
|
+
"data-is-disabled": l,
|
|
203
|
+
"data-has-phone-book": R,
|
|
204
|
+
"data-is-obfuscated": !0,
|
|
205
|
+
className: d(
|
|
206
|
+
f["phone-number-input"],
|
|
207
|
+
f["phone-number-input-obfuscated"],
|
|
208
|
+
"phone-number-input"
|
|
209
|
+
),
|
|
210
|
+
preparePasteValue: () => "",
|
|
211
|
+
prepareCopyValue: () => "",
|
|
212
|
+
prepareCutValue: () => ""
|
|
213
|
+
},
|
|
214
|
+
"obfuscated"
|
|
215
|
+
) : /* @__PURE__ */ i(
|
|
216
|
+
ee,
|
|
217
|
+
{
|
|
218
|
+
name: r,
|
|
219
|
+
autoComplete: h,
|
|
220
|
+
ref: J,
|
|
221
|
+
value: y,
|
|
222
|
+
mask: W,
|
|
223
|
+
onChange: ue,
|
|
224
|
+
disabled: l,
|
|
225
|
+
"data-is-disabled": l,
|
|
226
|
+
"data-has-phone-book": R,
|
|
227
|
+
"data-is-obfuscated": !1,
|
|
228
|
+
className: d(f["phone-number-input"], "phone-number-input"),
|
|
229
|
+
preparePasteValue: ce
|
|
230
|
+
},
|
|
231
|
+
"normal"
|
|
182
232
|
) }),
|
|
183
|
-
|
|
184
|
-
/* @__PURE__ */
|
|
185
|
-
|
|
233
|
+
R && /* @__PURE__ */ Q(le, { children: [
|
|
234
|
+
/* @__PURE__ */ i(
|
|
235
|
+
de,
|
|
186
236
|
{
|
|
187
|
-
disabled:
|
|
188
|
-
className:
|
|
189
|
-
|
|
237
|
+
disabled: l,
|
|
238
|
+
className: d(
|
|
239
|
+
f["phone-number-input-phone-book"],
|
|
190
240
|
"phone-number-input-phone-book"
|
|
191
241
|
),
|
|
192
|
-
onClick:
|
|
242
|
+
onClick: se,
|
|
193
243
|
size: "md",
|
|
194
|
-
children: /* @__PURE__ */
|
|
244
|
+
children: /* @__PURE__ */ i(Ie, { size: "md" })
|
|
195
245
|
}
|
|
196
246
|
),
|
|
197
|
-
|
|
198
|
-
|
|
247
|
+
z && /* @__PURE__ */ i(
|
|
248
|
+
Ne,
|
|
199
249
|
{
|
|
200
|
-
anchorElement:
|
|
201
|
-
onOptionSelect:
|
|
202
|
-
onClose:
|
|
250
|
+
anchorElement: j,
|
|
251
|
+
onOptionSelect: pe,
|
|
252
|
+
onClose: K,
|
|
203
253
|
noSuggestionMessage: "No phone numbers found",
|
|
204
|
-
children:
|
|
254
|
+
children: D
|
|
205
255
|
}
|
|
206
256
|
)
|
|
207
257
|
] })
|
|
@@ -210,6 +260,6 @@ const Re = ee.forwardRef(function({
|
|
|
210
260
|
);
|
|
211
261
|
});
|
|
212
262
|
export {
|
|
213
|
-
|
|
263
|
+
Ye as PhoneNumberInput
|
|
214
264
|
};
|
|
215
265
|
//# sourceMappingURL=phone_number_input.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"phone_number_input.js","sources":["../../../src/inputs/phone_number_input/phone_number_input.tsx"],"sourcesContent":["import { HStack, type HStackProps } from '../../stacks/h_stack.js';\nimport { clsx } from 'clsx';\nimport React, {\n useCallback,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n Children,\n isValidElement,\n} from 'react';\nimport { SlimButton } from '../../actions/index.js';\nimport { Select } from '../select/select.js';\nimport { MaskInput } from '../mask_input/mask_input.js';\nimport {\n CountryPhoneInformation,\n countriesPhoneInformation,\n} from './countries_phone_information.js';\nimport styles from './phone_number_input.module.css';\nimport { NotebookIcon } from '@tcn/icons/notebook_icon.js';\nimport { Option, OptionProps } from '../options/option.js';\nimport { SuggestionList } from '../suggestions/suggestion_list.js';\nimport { stripNonNumericAfterCountryCode } from './utils.js';\n\nconst countryList = countriesPhoneInformation.map(i => ({\n name: i.name,\n selectedLabel: i.prefix,\n optionLabel: `${i.prefix} (${i.code}) ${i.unicodeFlag}`,\n value: i.code,\n keywords: i.keywords,\n}));\n\ncountryList.sort((a, b) => parseInt(a.value) - parseInt(b.value));\n\nconst countryPrefixMap: Map<string, CountryPhoneInformation[]> = new Map();\nconst countryCodeMap: Map<string, CountryPhoneInformation> = new Map();\ncountriesPhoneInformation.forEach(i => {\n countryCodeMap.set(i.code, i);\n if (countryPrefixMap.has(i.prefix)) {\n countryPrefixMap.get(i.prefix)?.push(i);\n } else {\n countryPrefixMap.set(i.prefix, [i]);\n }\n});\n\nfunction createCountryOptions(allowedCountryCodes?: string[]) {\n if (allowedCountryCodes != null) {\n const allowedMap: Record<string, boolean> = {};\n allowedCountryCodes.forEach(c => {\n allowedMap[c] = true;\n });\n return countryList\n .filter(c => Boolean(allowedMap[c.value]))\n .map(i => {\n return (\n <Option\n key={i.value}\n value={i.value}\n label={i.selectedLabel}\n keywords={i.keywords}\n >\n {i.optionLabel}\n </Option>\n );\n });\n } else {\n return countryList.map(i => {\n return (\n <Option\n key={i.value}\n value={i.value}\n label={i.selectedLabel}\n keywords={i.keywords}\n >\n {i.optionLabel}\n </Option>\n );\n });\n }\n}\n\nfunction getCountryCodeFromValue(\n value: string,\n previousCountry: string,\n defaultCountry: string\n) {\n for (let x = 5; x > 1; x--) {\n const prefix = value.slice(0, x);\n const countriesInformation = countryPrefixMap.get(prefix);\n\n if (countriesInformation != null) {\n const countryInformation = countriesInformation.find(\n c => c.code === previousCountry\n );\n\n if (countryInformation != null) {\n return countryInformation;\n } else {\n return countriesInformation[0];\n }\n }\n }\n\n return (countryCodeMap.get(defaultCountry.toUpperCase()) ||\n countryCodeMap.get('US')) as CountryPhoneInformation;\n}\n\nexport interface PhoneNumberInputProps\n extends Omit<HStackProps, 'onChange' | 'children'> {\n value?: string;\n defaultCountry?: string;\n onChange?: (value: string) => void;\n countrySelectRef?: React.Ref<HTMLButtonElement>;\n phoneNumberInputRef?: React.Ref<HTMLInputElement>;\n disabled?: boolean;\n allowedCountryCodes?: string[];\n children?: React.ReactElement<OptionProps> | React.ReactElement<OptionProps>[];\n}\n\nexport const PhoneNumberInput = React.forwardRef(function PhoneNumberInput(\n {\n value = '',\n defaultCountry = 'US',\n onChange,\n countrySelectRef: countryRef,\n phoneNumberInputRef: numberRef,\n disabled = false,\n allowedCountryCodes,\n children,\n ...props\n }: PhoneNumberInputProps,\n ref: React.Ref<HTMLElement>\n) {\n const lastOutputValueRef = useRef(value);\n const [phoneBookElement, setPhoneBookElement] = useState<HTMLButtonElement | null>(\n null\n );\n const isPhoneBookOpen = phoneBookElement != null;\n const [selectedCountry, setSelectedCountry] = useState(defaultCountry);\n const countryInformation = getCountryCodeFromValue(\n value,\n selectedCountry,\n defaultCountry\n );\n const [phoneNumber, setPhoneNumber] = useState(() => {\n const phoneNumber = value.split(countryInformation.prefix)[1];\n\n return phoneNumber == null ? '' : stripNonNumericAfterCountryCode(phoneNumber);\n });\n\n // Extract valid Option components from children\n const phoneBookOptions = useMemo(() => {\n return Children.toArray(children).filter(\n (child): child is React.ReactElement<OptionProps> =>\n isValidElement(child) && child.type === Option\n );\n }, [children]);\n\n const showPhoneBook = phoneBookOptions.length > 0;\n const [countryCode, setCountryCode] = useState(countryInformation.code);\n const [currentMasks, setCurrentMasks] = useState([\n ...countriesPhoneInformation[0].masks,\n ]);\n\n const countryOptions = useMemo(() => {\n return createCountryOptions(allowedCountryCodes);\n }, [allowedCountryCodes]);\n\n function changeCountry(countryCodeValue: string) {\n const countryInformation = countryCodeMap.get(countryCodeValue);\n\n if (countryInformation == null) {\n return;\n }\n\n setCountryCode(countryInformation.code);\n setCurrentMasks([...countryInformation.masks]);\n setSelectedCountry(countryInformation.code);\n\n if (phoneNumber == null) {\n return;\n }\n\n const value = `${countryInformation.prefix}${stripNonNumericAfterCountryCode(phoneNumber)}`;\n lastOutputValueRef.current = value;\n onChange && onChange(value);\n }\n\n useLayoutEffect(() => {\n const countryInformation = getCountryCodeFromValue(\n value,\n selectedCountry,\n defaultCountry\n );\n setCountryCode(countryInformation.code);\n setCurrentMasks([...countryInformation.masks]);\n setSelectedCountry(countryInformation.code);\n }, [value, selectedCountry, defaultCountry]);\n\n function transformValue(newPhoneNumber: string) {\n const countryPrefix = countryCodeMap.get(countryCode)?.prefix;\n const lineNumber = stripNonNumericAfterCountryCode(newPhoneNumber);\n const outputValue = countryPrefix + lineNumber;\n\n lastOutputValueRef.current = outputValue;\n phoneNumber !== newPhoneNumber && setPhoneNumber(newPhoneNumber);\n onChange && onChange(outputValue);\n }\n\n function togglePhoneBook(e: React.MouseEvent<HTMLButtonElement>) {\n if (isPhoneBookOpen) {\n setPhoneBookElement(null);\n } else {\n setPhoneBookElement(e.currentTarget);\n }\n }\n\n function closePhoneBook() {\n setPhoneBookElement(null);\n }\n\n function handlePhoneBookOptionSelect(value: string) {\n // Update the phone number with the selected value\n updatePhoneNumber(value);\n closePhoneBook();\n }\n\n function preparePasteValue(value: string) {\n if (value.startsWith('+')) {\n const countryInformation = getCountryCodeFromValue(\n value,\n selectedCountry,\n defaultCountry\n );\n setCountryCode(countryInformation.code);\n setCurrentMasks([...countryInformation.masks]);\n\n const phoneNumber = value.split(countryInformation.prefix)[1];\n setPhoneNumber(phoneNumber);\n\n return phoneNumber;\n }\n\n return value;\n }\n\n const updatePhoneNumber = useCallback(\n (value: string) => {\n const oldValue = lastOutputValueRef.current;\n const countryInformation = getCountryCodeFromValue(\n value,\n selectedCountry,\n defaultCountry\n );\n const phoneNumber = value.split(countryInformation.prefix)[1];\n setCountryCode(countryInformation.code);\n setCurrentMasks([...countryInformation.masks]);\n setSelectedCountry(countryInformation.code);\n\n if (oldValue !== value) {\n setPhoneNumber(phoneNumber);\n onChange && onChange(value);\n }\n },\n [defaultCountry, selectedCountry, onChange]\n );\n\n useLayoutEffect(() => {\n updatePhoneNumber(value);\n }, [value, updatePhoneNumber]);\n\n return (\n <HStack\n ref={ref}\n className={clsx(styles['phone-number-input'], 'phone-number-input')}\n height=\"auto\"\n {...props}\n >\n <Select\n className={clsx(styles['phone-number-input-select'], 'phone-number-input-select')}\n ref={countryRef}\n width=\"auto\"\n value={countryCode}\n onChange={changeCountry}\n disabled={disabled}\n data-is-disabled={disabled}\n >\n {countryOptions}\n </Select>\n <HStack width=\"flex\" className={clsx(styles['phone-number-input-container'])}>\n <MaskInput\n ref={numberRef}\n value={phoneNumber}\n mask={currentMasks}\n onChange={transformValue}\n disabled={disabled}\n data-is-disabled={disabled}\n data-has-phone-book={showPhoneBook}\n className={clsx(styles['phone-number-input'], 'phone-number-input')}\n preparePasteValue={preparePasteValue}\n />\n </HStack>\n {showPhoneBook && (\n <>\n <SlimButton\n disabled={disabled}\n className={clsx(\n styles['phone-number-input-phone-book'],\n 'phone-number-input-phone-book'\n )}\n onClick={togglePhoneBook}\n size=\"md\"\n >\n <NotebookIcon size=\"md\" />\n </SlimButton>\n\n {isPhoneBookOpen && (\n <SuggestionList\n anchorElement={phoneBookElement}\n onOptionSelect={handlePhoneBookOptionSelect}\n onClose={closePhoneBook}\n noSuggestionMessage=\"No phone numbers found\"\n >\n {phoneBookOptions}\n </SuggestionList>\n )}\n </>\n )}\n </HStack>\n );\n});\n"],"names":["countryList","countriesPhoneInformation","i","a","b","countryPrefixMap","countryCodeMap","createCountryOptions","allowedCountryCodes","allowedMap","c","jsx","Option","getCountryCodeFromValue","value","previousCountry","defaultCountry","x","prefix","countriesInformation","countryInformation","PhoneNumberInput","React","onChange","countryRef","numberRef","disabled","children","props","ref","lastOutputValueRef","useRef","phoneBookElement","setPhoneBookElement","useState","isPhoneBookOpen","selectedCountry","setSelectedCountry","phoneNumber","setPhoneNumber","stripNonNumericAfterCountryCode","phoneBookOptions","useMemo","Children","child","isValidElement","showPhoneBook","countryCode","setCountryCode","currentMasks","setCurrentMasks","countryOptions","changeCountry","countryCodeValue","useLayoutEffect","transformValue","newPhoneNumber","countryPrefix","lineNumber","outputValue","togglePhoneBook","closePhoneBook","handlePhoneBookOptionSelect","updatePhoneNumber","preparePasteValue","useCallback","oldValue","jsxs","HStack","clsx","styles","Select","MaskInput","Fragment","SlimButton","NotebookIcon","SuggestionList"],"mappings":";;;;;;;;;;;;;;;;;0ZAwBMA,IAAcC,EAA0B,IAAI,CAAAC,OAAM;AAAA,EACtD,MAAMA,EAAE;AAAA,EACR,eAAeA,EAAE;AAAA,EACjB,aAAa,GAAGA,EAAE,MAAM,KAAKA,EAAE,IAAI,KAAKA,EAAE,WAAW;AAAA,EACrD,OAAOA,EAAE;AAAA,EACT,UAAUA,EAAE;AACd,EAAE;AAEFF,EAAY,KAAK,CAACG,GAAGC,MAAM,SAASD,EAAE,KAAK,IAAI,SAASC,EAAE,KAAK,CAAC;AAEhE,MAAMC,wBAA+D,IAAA,GAC/DC,wBAA2D,IAAA;AACjEL,EAA0B,QAAQ,CAAAC,MAAK;AACrC,EAAAI,EAAe,IAAIJ,EAAE,MAAMA,CAAC,GACxBG,EAAiB,IAAIH,EAAE,MAAM,IAC/BG,EAAiB,IAAIH,EAAE,MAAM,GAAG,KAAKA,CAAC,IAEtCG,EAAiB,IAAIH,EAAE,QAAQ,CAACA,CAAC,CAAC;AAEtC,CAAC;AAED,SAASK,GAAqBC,GAAgC;AAC5D,MAAIA,KAAuB,MAAM;AAC/B,UAAMC,IAAsC,CAAA;AAC5C,WAAAD,EAAoB,QAAQ,CAAAE,MAAK;AAC/B,MAAAD,EAAWC,CAAC,IAAI;AAAA,IAClB,CAAC,GACMV,EACJ,OAAO,CAAAU,MAAK,EAAQD,EAAWC,EAAE,KAAK,CAAE,EACxC,IAAI,CAAAR,MAED,gBAAAS;AAAA,MAACC;AAAA,MAAA;AAAA,Q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ACT,MAAK;AAAA,cAEL,UAAA,gBAAAjD,EAACgE,IAAA,EAAa,MAAK,KAAA,CAAK;AAAA,YAAA;AAAA,UAAA;AAAA,UAGzBxC,KACC,gBAAAxB;AAAA,YAACiE;AAAA,YAAA;AAAA,cACC,eAAe5C;AAAA,cACf,gBAAgB8B;AAAA,cAChB,SAASD;AAAA,cACT,qBAAoB;AAAA,cAEnB,UAAApB;AAAA,YAAA;AAAA,UAAA;AAAA,QACH,EAAA,CAEJ;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAIR,CAAC;"}
|
|
1
|
+
{"version":3,"file":"phone_number_input.js","sources":["../../../src/inputs/phone_number_input/phone_number_input.tsx"],"sourcesContent":["import { HStack, type HStackProps } from '../../stacks/h_stack.js';\nimport { clsx } from 'clsx';\nimport React, {\n useCallback,\n useLayoutEffect,\n useMemo,\n useRef,\n useState,\n Children,\n isValidElement,\n} from 'react';\nimport { SlimButton } from '../../actions/index.js';\nimport { Select } from '../select/select.js';\nimport { MaskInput } from '../mask_input/mask_input.js';\nimport {\n CountryPhoneInformation,\n countriesPhoneInformation,\n} from './countries_phone_information.js';\nimport styles from './phone_number_input.module.css';\nimport { NotebookIcon } from '@tcn/icons/notebook_icon.js';\nimport { Option, OptionProps } from '../options/option.js';\nimport { SuggestionList } from '../suggestions/suggestion_list.js';\nimport { stripNonNumericAfterCountryCode } from './utils.js';\nimport { useForkRef } from '../../utils/index.js';\n\nconst OBFUSCATED_CHARACTER = '•';\n\nfunction createObfuscatedMasks(masks: { mask: string; placeholder?: string }[]) {\n return masks.map(m => ({\n ...m,\n placeholder: m.mask.replace(/[9a*]/g, OBFUSCATED_CHARACTER),\n }));\n}\n\nconst countryList = countriesPhoneInformation.map(i => ({\n name: i.name,\n selectedLabel: i.prefix,\n optionLabel: `${i.prefix} (${i.code}) ${i.unicodeFlag}`,\n value: i.code,\n keywords: i.keywords,\n}));\n\ncountryList.sort((a, b) => parseInt(a.value) - parseInt(b.value));\n\nconst countryPrefixMap: Map<string, CountryPhoneInformation[]> = new Map();\nconst countryCodeMap: Map<string, CountryPhoneInformation> = new Map();\ncountriesPhoneInformation.forEach(i => {\n countryCodeMap.set(i.code, i);\n if (countryPrefixMap.has(i.prefix)) {\n countryPrefixMap.get(i.prefix)?.push(i);\n } else {\n countryPrefixMap.set(i.prefix, [i]);\n }\n});\n\nfunction createCountryOptions(allowedCountryCodes?: string[]) {\n if (allowedCountryCodes != null) {\n const allowedMap: Record<string, boolean> = {};\n allowedCountryCodes.forEach(c => {\n allowedMap[c] = true;\n });\n return countryList\n .filter(c => Boolean(allowedMap[c.value]))\n .map(i => {\n return (\n <Option\n key={i.value}\n value={i.value}\n label={i.selectedLabel}\n keywords={i.keywords}\n >\n {i.optionLabel}\n </Option>\n );\n });\n } else {\n return countryList.map(i => {\n return (\n <Option\n key={i.value}\n value={i.value}\n label={i.selectedLabel}\n keywords={i.keywords}\n >\n {i.optionLabel}\n </Option>\n );\n });\n }\n}\n\nfunction getCountryCodeFromValue(\n value: string,\n previousCountry: string,\n defaultCountry: string\n) {\n for (let x = 5; x > 1; x--) {\n const prefix = value.slice(0, x);\n const countriesInformation = countryPrefixMap.get(prefix);\n\n if (countriesInformation != null) {\n const countryInformation = countriesInformation.find(\n c => c.code === previousCountry\n );\n\n if (countryInformation != null) {\n return countryInformation;\n } else {\n return countriesInformation[0];\n }\n }\n }\n\n return (countryCodeMap.get(defaultCountry.toUpperCase()) ||\n countryCodeMap.get('US')) as CountryPhoneInformation;\n}\n\nexport interface PhoneNumberInputProps\n extends Omit<HStackProps, 'onChange' | 'children'> {\n value?: string;\n name?: string;\n autoComplete?: string;\n defaultCountry?: string;\n /**\n * Callback fired when the phone number value changes.\n * @param value - The phone number value with country prefix\n * @param obfuscate - Whether the selected phone number is obfuscated (e.g., from a phone book entry marked as obfuscated)\n */\n onChange?: (value: string, obfuscate: boolean) => void;\n countrySelectRef?: React.Ref<HTMLButtonElement>;\n phoneNumberInputRef?: React.Ref<HTMLInputElement>;\n disabled?: boolean;\n allowedCountryCodes?: string[];\n children?: React.ReactElement<OptionProps> | React.ReactElement<OptionProps>[];\n}\n\nexport const PhoneNumberInput = React.forwardRef(function PhoneNumberInput(\n {\n value = '',\n name,\n autoComplete,\n defaultCountry = 'US',\n onChange,\n countrySelectRef: countryRef,\n phoneNumberInputRef: numberRef,\n disabled = false,\n allowedCountryCodes,\n children,\n ...props\n }: PhoneNumberInputProps,\n ref: React.Ref<HTMLElement>\n) {\n const lastOutputValueRef = useRef(value);\n const [phoneBookElement, setPhoneBookElement] = useState<HTMLButtonElement | null>(\n null\n );\n const isPhoneBookOpen = phoneBookElement != null;\n const [selectedCountry, setSelectedCountry] = useState(defaultCountry);\n const countryInformation = getCountryCodeFromValue(\n value,\n selectedCountry,\n defaultCountry\n );\n const [phoneNumber, setPhoneNumber] = useState(() => {\n const phoneNumber = value.split(countryInformation.prefix)[1];\n\n return phoneNumber == null ? '' : stripNonNumericAfterCountryCode(phoneNumber);\n });\n\n // Extract valid Option components from children\n const phoneBookOptions = useMemo(() => {\n return Children.toArray(children).filter(\n (child): child is React.ReactElement<OptionProps> =>\n isValidElement(child) && child.type === Option\n );\n }, [children]);\n\n const showPhoneBook = phoneBookOptions.length > 0;\n const [countryCode, setCountryCode] = useState(countryInformation.code);\n const [currentMasks, setCurrentMasks] = useState([\n ...countriesPhoneInformation[0].masks,\n ]);\n const [obfuscateValue, setObfuscateValue] = useState(false);\n const [shouldFocusAfterClear, setShouldFocusAfterClear] = useState(false);\n const internalInputRef = useRef<HTMLInputElement>(null);\n const forkedInputRef = useForkRef(numberRef, internalInputRef);\n\n const countryOptions = useMemo(() => {\n return createCountryOptions(allowedCountryCodes);\n }, [allowedCountryCodes]);\n\n function changeCountry(countryCodeValue: string) {\n const countryInformation = countryCodeMap.get(countryCodeValue);\n\n if (countryInformation == null) {\n return;\n }\n\n setCountryCode(countryInformation.code);\n setCurrentMasks([...countryInformation.masks]);\n setSelectedCountry(countryInformation.code);\n\n if (phoneNumber == null) {\n return;\n }\n\n const value = `${countryInformation.prefix}${stripNonNumericAfterCountryCode(phoneNumber)}`;\n lastOutputValueRef.current = value;\n onChange && onChange(value, false);\n }\n\n useLayoutEffect(() => {\n const countryInformation = getCountryCodeFromValue(\n value,\n selectedCountry,\n defaultCountry\n );\n setCountryCode(countryInformation.code);\n setCurrentMasks([...countryInformation.masks]);\n setSelectedCountry(countryInformation.code);\n }, [value, selectedCountry, defaultCountry]);\n\n function transformValue(newPhoneNumber: string) {\n const countryPrefix = countryCodeMap.get(countryCode)?.prefix;\n const lineNumber = stripNonNumericAfterCountryCode(newPhoneNumber);\n const outputValue = countryPrefix + lineNumber;\n\n // Clear obfuscated state when user types manually\n if (obfuscateValue) {\n setObfuscateValue(false);\n }\n\n lastOutputValueRef.current = outputValue;\n phoneNumber !== newPhoneNumber && setPhoneNumber(newPhoneNumber);\n onChange && onChange(outputValue, false);\n }\n\n function togglePhoneBook(e: React.MouseEvent<HTMLButtonElement>) {\n if (isPhoneBookOpen) {\n setPhoneBookElement(null);\n } else {\n setPhoneBookElement(e.currentTarget);\n }\n }\n\n function closePhoneBook() {\n setPhoneBookElement(null);\n }\n\n function handlePhoneBookOptionSelect(\n value: string,\n _label: string | undefined,\n _isSuggestion: boolean,\n obfuscate: boolean\n ) {\n // Update the phone number with the selected value\n setObfuscateValue(obfuscate);\n updatePhoneNumber(value, obfuscate);\n closePhoneBook();\n }\n\n function preparePasteValue(value: string) {\n if (value.startsWith('+')) {\n const countryInformation = getCountryCodeFromValue(\n value,\n selectedCountry,\n defaultCountry\n );\n setCountryCode(countryInformation.code);\n setCurrentMasks([...countryInformation.masks]);\n\n const phoneNumber = value.split(countryInformation.prefix)[1];\n setPhoneNumber(phoneNumber);\n\n return phoneNumber;\n }\n\n return value;\n }\n\n function handleObfuscatedInputChange(newValue: string) {\n // When user types on a obfuscated input, clear the obfuscated state and start fresh\n // The newValue will be the digits the user typed (mask filters to valid input)\n setShouldFocusAfterClear(true);\n setObfuscateValue(false);\n setPhoneNumber(newValue);\n\n const countryPrefix = countryCodeMap.get(countryCode)?.prefix;\n const lineNumber = stripNonNumericAfterCountryCode(newValue);\n const outputValue = countryPrefix + lineNumber;\n lastOutputValueRef.current = outputValue;\n onChange && onChange(outputValue, false);\n }\n\n const updatePhoneNumber = useCallback(\n (value: string, obfuscate = false) => {\n const oldValue = lastOutputValueRef.current;\n const countryInformation = getCountryCodeFromValue(\n value,\n selectedCountry,\n defaultCountry\n );\n const phoneNumber = value.split(countryInformation.prefix)[1];\n setCountryCode(countryInformation.code);\n setCurrentMasks([...countryInformation.masks]);\n setSelectedCountry(countryInformation.code);\n\n if (oldValue !== value) {\n setPhoneNumber(phoneNumber);\n onChange && onChange(value, obfuscate);\n }\n },\n [defaultCountry, selectedCountry, onChange]\n );\n\n useLayoutEffect(() => {\n updatePhoneNumber(value);\n }, [value, updatePhoneNumber]);\n\n // Focus the input after transitioning from obfuscated to normal mode\n useLayoutEffect(() => {\n if (shouldFocusAfterClear && !obfuscateValue && internalInputRef.current) {\n internalInputRef.current.focus();\n setShouldFocusAfterClear(false);\n }\n }, [shouldFocusAfterClear, obfuscateValue]);\n\n return (\n <HStack\n ref={ref}\n className={clsx(styles['phone-number-input'], 'phone-number-input')}\n height=\"auto\"\n {...props}\n >\n <Select\n className={clsx(styles['phone-number-input-select'], 'phone-number-input-select')}\n ref={countryRef}\n width=\"auto\"\n value={obfuscateValue ? '' : countryCode}\n onChange={changeCountry}\n disabled={disabled || obfuscateValue}\n data-is-disabled={disabled || obfuscateValue}\n data-is-obfuscated={obfuscateValue}\n placeholder={obfuscateValue ? '––' : undefined}\n >\n {countryOptions}\n </Select>\n <HStack width=\"flex\" className={clsx(styles['phone-number-input-container'])}>\n {obfuscateValue ? (\n <MaskInput\n key=\"obfuscated\"\n name={name}\n autoComplete={autoComplete}\n ref={forkedInputRef}\n value=\"\"\n mask={createObfuscatedMasks(currentMasks)}\n onChange={handleObfuscatedInputChange}\n disabled={disabled}\n data-is-disabled={disabled}\n data-has-phone-book={showPhoneBook}\n data-is-obfuscated={true}\n className={clsx(\n styles['phone-number-input'],\n styles['phone-number-input-obfuscated'],\n 'phone-number-input'\n )}\n preparePasteValue={() => ''}\n prepareCopyValue={() => ''}\n prepareCutValue={() => ''}\n />\n ) : (\n <MaskInput\n key=\"normal\"\n name={name}\n autoComplete={autoComplete}\n ref={forkedInputRef}\n value={phoneNumber}\n mask={currentMasks}\n onChange={transformValue}\n disabled={disabled}\n data-is-disabled={disabled}\n data-has-phone-book={showPhoneBook}\n data-is-obfuscated={false}\n className={clsx(styles['phone-number-input'], 'phone-number-input')}\n preparePasteValue={preparePasteValue}\n />\n )}\n </HStack>\n {showPhoneBook && (\n <>\n <SlimButton\n disabled={disabled}\n className={clsx(\n styles['phone-number-input-phone-book'],\n 'phone-number-input-phone-book'\n )}\n onClick={togglePhoneBook}\n size=\"md\"\n >\n <NotebookIcon size=\"md\" />\n </SlimButton>\n\n {isPhoneBookOpen && (\n <SuggestionList\n anchorElement={phoneBookElement}\n onOptionSelect={handlePhoneBookOptionSelect}\n onClose={closePhoneBook}\n noSuggestionMessage=\"No phone numbers found\"\n >\n {phoneBookOptions}\n </SuggestionList>\n )}\n </>\n )}\n </HStack>\n );\n});\n"],"names":["OBFUSCATED_CHARACTER","createObfuscatedMasks","masks","m","countryList","countriesPhoneInformation","i","a","b","countryPrefixMap","countryCodeMap","createCountryOptions","allowedCountryCodes","allowedMap","c","jsx","Option","getCountryCodeFromValue","value","previousCountry","defaultCountry","x","prefix","countriesInformation","countryInformation","PhoneNumberInput","React","name","autoComplete","onChange","countryRef","numberRef","disabled","children","props","ref","lastOutputValueRef","useRef","phoneBookElement","setPhoneBookElement","useState","isPhoneBookOpen","selectedCountry","setSelectedCountry","phoneNumber","setPhoneNumber","stripNonNumericAfterCountryCode","phoneBookOptions","useMemo","Children","child","isValidElement","showPhoneBook","countryCode","setCountryCode","currentMasks","setCurrentMasks","obfuscateValue","setObfuscateValue","shouldFocusAfterClear","setShouldFocusAfterClear","internalInputRef","forkedInputRef","useForkRef","countryOptions","changeCountry","countryCodeValue","useLayoutEffect","transformValue","newPhoneNumber","countryPrefix","lineNumber","outputValue","togglePhoneBook","closePhoneBook","handlePhoneBookOptionSelect","_label","_isSuggestion","obfuscate","updatePhoneNumber","preparePasteValue","handleObfuscatedInputChange","newValue","useCallback","oldValue","jsxs","HStack","clsx","styles","Select","MaskInput","Fragment","SlimButton","NotebookIcon","SuggestionList"],"mappings":";;;;;;;;;;;;;;;;;;;;;;8eAyBMA,KAAuB;AAE7B,SAASC,GAAsBC,GAAiD;AAC9E,SAAOA,EAAM,IAAI,CAAAC,OAAM;AAAA,IACrB,GAAGA;AAAA,IACH,aAAaA,EAAE,KAAK,QAAQ,UAAUH,EAAoB;AAAA,EAAA,EAC1D;AACJ;AAEA,MAAMI,IAAcC,EAA0B,IAAI,CAAAC,OAAM;AAAA,EACtD,MAAMA,EAAE;AAAA,EACR,eAAeA,EAAE;AAAA,EACjB,aAAa,GAAGA,EAAE,MAAM,KAAKA,EAAE,IAAI,KAAKA,EAAE,WAAW;AAAA,EACrD,OAAOA,EAAE;AAAA,EACT,UAAUA,EAAE;AACd,EAAE;AAEFF,EAAY,KAAK,CAACG,GAAGC,MAAM,SAASD,EAAE,KAAK,IAAI,SAASC,EAAE,KAAK,CAAC;AAEhE,MAAMC,wBAA+D,IAAA,GAC/DC,wBAA2D,IAAA;AACjEL,EAA0B,QAAQ,CAAAC,MAAK;AACrC,EAAAI,EAAe,IAAIJ,EAAE,MAAMA,CAAC,GACxBG,EAAiB,IAAIH,EAAE,MAAM,IAC/BG,EAAiB,IAAIH,EAAE,MAAM,GAAG,KAAKA,CAAC,IAEtCG,EAAiB,IAAIH,EAAE,QAAQ,CAACA,CAAC,CAAC;AAEtC,CAAC;AAED,SAASK,GAAqBC,GAAgC;AAC5D,MAAIA,KAAuB,MAAM;AAC/B,UAAMC,IAAsC,CAAA;AAC5C,WAAAD,EAAoB,QAAQ,CAAAE,MAAK;AAC/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B;AAAA,YACrB,sBAAoB;AAAA,YACpB,WAAWmC,EAAKC,EAAO,oBAAoB,GAAG,oBAAoB;AAAA,YAClE,mBAAAR;AAAA,UAAA;AAAA,UAZI;AAAA,QAAA,GAeV;AAAA,QACC5B,KACC,gBAAAiC,EAAAM,IAAA,EACE,UAAA;AAAA,UAAA,gBAAA5E;AAAA,YAAC6E;AAAA,YAAA;AAAA,cACC,UAAA5D;AAAA,cACA,WAAWuD;AAAA,gBACTC,EAAO,+BAA+B;AAAA,gBACtC;AAAA,cAAA;AAAA,cAEF,SAASf;AAAA,cACT,MAAK;AAAA,cAEL,UAAA,gBAAA1D,EAAC8E,IAAA,EAAa,MAAK,KAAA,CAAK;AAAA,YAAA;AAAA,UAAA;AAAA,UAGzBpD,KACC,gBAAA1B;AAAA,YAAC+E;AAAA,YAAA;AAAA,cACC,eAAexD;AAAA,cACf,gBAAgBqC;AAAA,cAChB,SAASD;AAAA,cACT,qBAAoB;AAAA,cAEnB,UAAA3B;AAAA,YAAA;AAAA,UAAA;AAAA,QACH,EAAA,CAEJ;AAAA,MAAA;AAAA,IAAA;AAAA,EAAA;AAIR,CAAC;"}
|
|
@@ -3,7 +3,7 @@ export interface SuggestionItemProps {
|
|
|
3
3
|
isFocused: boolean;
|
|
4
4
|
isSelected: boolean;
|
|
5
5
|
option: React.ReactElement;
|
|
6
|
-
onClick?: (value: string, label: string, isSuggestion: boolean) => void;
|
|
6
|
+
onClick?: (value: string, label: string, isSuggestion: boolean, obfuscate: boolean) => void;
|
|
7
7
|
}
|
|
8
8
|
export declare function SuggestionItem({ isFocused, isSelected, option, onClick, }: SuggestionItemProps): import("react/jsx-runtime").JSX.Element;
|
|
9
9
|
//# sourceMappingURL=suggestion_item.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"suggestion_item.d.ts","sourceRoot":"","sources":["../../../src/inputs/suggestions/suggestion_item.tsx"],"names":[],"mappings":"AACA,OAAO,KAA4B,MAAM,OAAO,CAAC;AAGjD,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,OAAO,CAAC;IACpB,MAAM,EAAE,KAAK,CAAC,YAAY,CAAC;IAC3B,OAAO,CAAC,EAAE,
|
|
1
|
+
{"version":3,"file":"suggestion_item.d.ts","sourceRoot":"","sources":["../../../src/inputs/suggestions/suggestion_item.tsx"],"names":[],"mappings":"AACA,OAAO,KAA4B,MAAM,OAAO,CAAC;AAGjD,MAAM,WAAW,mBAAmB;IAClC,SAAS,EAAE,OAAO,CAAC;IACnB,UAAU,EAAE,OAAO,CAAC;IACpB,MAAM,EAAE,KAAK,CAAC,YAAY,CAAC;IAC3B,OAAO,CAAC,EAAE,CACR,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,EACb,YAAY,EAAE,OAAO,EACrB,SAAS,EAAE,OAAO,KACf,IAAI,CAAC;CACX;AAED,wBAAgB,cAAc,CAAC,EAC7B,SAAS,EACT,UAAU,EACV,MAAM,EACN,OAAO,GACR,EAAE,mBAAmB,2CAyCrB"}
|
|
@@ -1,34 +1,39 @@
|
|
|
1
|
-
import { jsx as
|
|
1
|
+
import { jsx as i } from "react/jsx-runtime";
|
|
2
2
|
import { clsx as a } from "clsx";
|
|
3
|
-
import { useRef as c, useEffect as
|
|
4
|
-
import '../../suggestion_item.css';const
|
|
3
|
+
import { useRef as c, useEffect as u } from "react";
|
|
4
|
+
import '../../suggestion_item.css';const f = "_suggestion-item_6b60309", b = { "suggestion-item": f };
|
|
5
5
|
function p({
|
|
6
6
|
isFocused: e,
|
|
7
|
-
isSelected:
|
|
8
|
-
option:
|
|
7
|
+
isSelected: o,
|
|
8
|
+
option: t,
|
|
9
9
|
onClick: l
|
|
10
10
|
}) {
|
|
11
|
-
const
|
|
12
|
-
return
|
|
13
|
-
const
|
|
14
|
-
|
|
15
|
-
}, [
|
|
16
|
-
const
|
|
17
|
-
e &&
|
|
18
|
-
}, [e]), /* @__PURE__ */
|
|
11
|
+
const n = c(null), r = t.props.disabled;
|
|
12
|
+
return u(() => {
|
|
13
|
+
const s = n.current;
|
|
14
|
+
o && s != null && s.scrollIntoView({ block: "start" });
|
|
15
|
+
}, [o]), u(() => {
|
|
16
|
+
const s = n.current;
|
|
17
|
+
e && s != null && s.scrollIntoView({ block: "center" });
|
|
18
|
+
}, [e]), /* @__PURE__ */ i(
|
|
19
19
|
"button",
|
|
20
20
|
{
|
|
21
21
|
tabIndex: -1,
|
|
22
|
-
ref:
|
|
23
|
-
className: a(
|
|
24
|
-
"data-is-selected":
|
|
22
|
+
ref: n,
|
|
23
|
+
className: a(b["suggestion-item"], "suggestion-item"),
|
|
24
|
+
"data-is-selected": o,
|
|
25
25
|
"data-is-focused": e,
|
|
26
26
|
"data-disabled": r,
|
|
27
27
|
disabled: r,
|
|
28
28
|
onClick: () => {
|
|
29
|
-
!r && l && l(
|
|
29
|
+
!r && l && l(
|
|
30
|
+
t.props.value,
|
|
31
|
+
t.props.label,
|
|
32
|
+
!0,
|
|
33
|
+
t.props.obfuscate ?? !1
|
|
34
|
+
);
|
|
30
35
|
},
|
|
31
|
-
children:
|
|
36
|
+
children: t
|
|
32
37
|
}
|
|
33
38
|
);
|
|
34
39
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"suggestion_item.js","sources":["../../../src/inputs/suggestions/suggestion_item.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport React, { useEffect, useRef } from 'react';\nimport styles from './suggestion_item.module.css';\n\nexport interface SuggestionItemProps {\n isFocused: boolean;\n isSelected: boolean;\n option: React.ReactElement;\n onClick?: (value: string
|
|
1
|
+
{"version":3,"file":"suggestion_item.js","sources":["../../../src/inputs/suggestions/suggestion_item.tsx"],"sourcesContent":["import { clsx } from 'clsx';\nimport React, { useEffect, useRef } from 'react';\nimport styles from './suggestion_item.module.css';\n\nexport interface SuggestionItemProps {\n isFocused: boolean;\n isSelected: boolean;\n option: React.ReactElement;\n onClick?: (\n value: string,\n label: string,\n isSuggestion: boolean,\n obfuscate: boolean\n ) => void;\n}\n\nexport function SuggestionItem({\n isFocused,\n isSelected,\n option,\n onClick,\n}: SuggestionItemProps) {\n const buttonRef = useRef<HTMLButtonElement | null>(null);\n const isDisabled = option.props.disabled;\n\n useEffect(() => {\n const button = buttonRef.current;\n if (isSelected && button != null) {\n button.scrollIntoView({ block: 'start' });\n }\n }, [isSelected]);\n\n useEffect(() => {\n const button = buttonRef.current;\n if (isFocused && button != null) {\n button.scrollIntoView({ block: 'center' });\n }\n }, [isFocused]);\n\n return (\n <button\n tabIndex={-1}\n ref={buttonRef}\n className={clsx(styles['suggestion-item'], 'suggestion-item')}\n data-is-selected={isSelected}\n data-is-focused={isFocused}\n data-disabled={isDisabled}\n disabled={isDisabled}\n onClick={() => {\n if (!isDisabled && onClick) {\n onClick(\n option.props.value,\n option.props.label,\n true,\n option.props.obfuscate ?? false\n );\n }\n }}\n >\n {option}\n </button>\n );\n}\n"],"names":["SuggestionItem","isFocused","isSelected","option","onClick","buttonRef","useRef","isDisabled","useEffect","button","jsx","clsx","styles"],"mappings":";;;;AAgBO,SAASA,EAAe;AAAA,EAC7B,WAAAC;AAAA,EACA,YAAAC;AAAA,EACA,QAAAC;AAAA,EACA,SAAAC;AACF,GAAwB;AACtB,QAAMC,IAAYC,EAAiC,IAAI,GACjDC,IAAaJ,EAAO,MAAM;AAEhC,SAAAK,EAAU,MAAM;AACd,UAAMC,IAASJ,EAAU;AACzB,IAAIH,KAAcO,KAAU,QAC1BA,EAAO,eAAe,EAAE,OAAO,QAAA,CAAS;AAAA,EAE5C,GAAG,CAACP,CAAU,CAAC,GAEfM,EAAU,MAAM;AACd,UAAMC,IAASJ,EAAU;AACzB,IAAIJ,KAAaQ,KAAU,QACzBA,EAAO,eAAe,EAAE,OAAO,SAAA,CAAU;AAAA,EAE7C,GAAG,CAACR,CAAS,CAAC,GAGZ,gBAAAS;AAAA,IAAC;AAAA,IAAA;AAAA,MACC,UAAU;AAAA,MACV,KAAKL;AAAA,MACL,WAAWM,EAAKC,EAAO,iBAAiB,GAAG,iBAAiB;AAAA,MAC5D,oBAAkBV;AAAA,MAClB,mBAAiBD;AAAA,MACjB,iBAAeM;AAAA,MACf,UAAUA;AAAA,MACV,SAAS,MAAM;AACb,QAAI,CAACA,KAAcH,KACjBA;AAAA,UACED,EAAO,MAAM;AAAA,UACbA,EAAO,MAAM;AAAA,UACb;AAAA,UACAA,EAAO,MAAM,aAAa;AAAA,QAAA;AAAA,MAGhC;AAAA,MAEC,UAAAA;AAAA,IAAA;AAAA,EAAA;AAGP;"}
|
|
@@ -5,7 +5,7 @@ export interface SuggestionListProps extends Omit<React.HTMLAttributes<HTMLInput
|
|
|
5
5
|
anchorElement: HTMLElement | null;
|
|
6
6
|
children?: React.ReactNode;
|
|
7
7
|
onChange?: (value: string) => void;
|
|
8
|
-
onOptionSelect?: (value: string, label: string | undefined, isSuggestion: boolean) => void;
|
|
8
|
+
onOptionSelect?: (value: string, label: string | undefined, isSuggestion: boolean, obfuscate: boolean) => void;
|
|
9
9
|
noSuggestionMessage?: React.ReactNode;
|
|
10
10
|
trimCustomInput?: boolean;
|
|
11
11
|
haveValueAsOption?: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"suggestion_list.d.ts","sourceRoot":"","sources":["../../../src/inputs/suggestions/suggestion_list.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAoD,MAAM,OAAO,CAAC;AAazE,MAAM,WAAW,mBACf,SAAQ,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,gBAAgB,CAAC,EAAE,UAAU,CAAC;IAChE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,WAAW,GAAG,IAAI,CAAC;IAClC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,cAAc,CAAC,EAAE,CACf,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,YAAY,EAAE,OAAO,
|
|
1
|
+
{"version":3,"file":"suggestion_list.d.ts","sourceRoot":"","sources":["../../../src/inputs/suggestions/suggestion_list.tsx"],"names":[],"mappings":"AAIA,OAAO,KAAoD,MAAM,OAAO,CAAC;AAazE,MAAM,WAAW,mBACf,SAAQ,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,gBAAgB,CAAC,EAAE,UAAU,CAAC;IAChE,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,aAAa,EAAE,WAAW,GAAG,IAAI,CAAC;IAClC,QAAQ,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IAC3B,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IACnC,cAAc,CAAC,EAAE,CACf,KAAK,EAAE,MAAM,EACb,KAAK,EAAE,MAAM,GAAG,SAAS,EACzB,YAAY,EAAE,OAAO,EACrB,SAAS,EAAE,OAAO,KACf,IAAI,CAAC;IACV,mBAAmB,CAAC,EAAE,KAAK,CAAC,SAAS,CAAC;IACtC,eAAe,CAAC,EAAE,OAAO,CAAC;IAC1B,iBAAiB,CAAC,EAAE,OAAO,CAAC;IAC5B,OAAO,CAAC,EAAE,CACR,UAAU,EAAE,MAAM,EAClB,mBAAmB,EAAE,MAAM,GAAG,IAAI,EAClC,iBAAiB,EAAE,MAAM,GAAG,IAAI,KAC7B,IAAI,CAAC;CACX;AAED,wBAAgB,cAAc,CAAC,EAC7B,KAAU,EACV,aAAa,EACb,aAAa,EACb,QAAQ,EACR,cAAc,EACd,mBAAwC,EACxC,OAAO,EACP,QAAQ,EACR,OAAO,EACP,SAAS,EACT,eAAuB,EACvB,iBAAyB,EACzB,GAAG,KAAK,EACT,EAAE,mBAAmB,2CAuXrB"}
|