@bikdotai/bik-component-library 0.0.876-beta.0 → 0.0.876-beta.1
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/cjs/components/WhatsAppTextEditor/AIRephraseButton.js +2 -2
- package/dist/cjs/components/WhatsAppTextEditor/AIRephraseButton.js.map +1 -1
- package/dist/cjs/components/WhatsAppTextEditor/WhatsAppTextEditor.js +4 -4
- package/dist/cjs/components/WhatsAppTextEditor/WhatsAppTextEditor.js.map +1 -1
- package/dist/cjs/components/WhatsAppTextEditor/WhatsAppTextEditorHeader.js +2 -2
- package/dist/cjs/components/WhatsAppTextEditor/WhatsAppTextEditorHeader.js.map +1 -1
- package/dist/cjs/components/accordion/Accordion.style.js +1 -1
- package/dist/cjs/components/accordion/Accordion.style.js.map +1 -1
- package/dist/cjs/components/action-button/ActionButton.styled.js +1 -1
- package/dist/cjs/components/action-button/ActionButton.styled.js.map +1 -1
- package/dist/cjs/components/analytics-chips-and-dropdowns/CommonStyles.js +1 -1
- package/dist/cjs/components/analytics-chips-and-dropdowns/CommonStyles.js.map +1 -1
- package/dist/cjs/components/bik-layout/SidebarStyles.js +1 -1
- package/dist/cjs/components/bik-layout/SidebarStyles.js.map +1 -1
- package/dist/cjs/components/button/Button.styled.js +3 -3
- package/dist/cjs/components/button/Button.styled.js.map +1 -1
- package/dist/cjs/components/buttonGroup/ButtonGroupStyle.js +1 -1
- package/dist/cjs/components/buttonGroup/ButtonGroupStyle.js.map +1 -1
- package/dist/cjs/components/card-selector/CardSelector.styled.js +1 -1
- package/dist/cjs/components/card-selector/CardSelector.styled.js.map +1 -1
- package/dist/cjs/components/carousel-preview/CarouselPreview.style.js +2 -2
- package/dist/cjs/components/carousel-preview/CarouselPreview.style.js.map +1 -1
- package/dist/cjs/components/checkBox/CheckBox.styled.js +1 -1
- package/dist/cjs/components/checkBox/CheckBox.styled.js.map +1 -1
- package/dist/cjs/components/dropdown/MenuItem/MenuItem.js +1 -1
- package/dist/cjs/components/dropdown/MenuItem/MenuItem.js.map +1 -1
- package/dist/cjs/components/dropdown/OpenedDropdown/components/OpennedDropdown.js +1 -1
- package/dist/cjs/components/dropdown/OpenedDropdown/components/OpennedDropdown.js.map +1 -1
- package/dist/cjs/components/dropdown/OpenedDropdown/components/menu/MenuItem.js +10 -27
- package/dist/cjs/components/dropdown/OpenedDropdown/components/menu/MenuItem.js.map +1 -1
- package/dist/cjs/components/dropdown/OpenedDropdown/components/menu/MenuList.js +1 -1
- package/dist/cjs/components/dropdown/OpenedDropdown/components/menu/MenuList.js.map +1 -1
- package/dist/cjs/components/dropdown/OpenedDropdown/components/menu/SelectAllMenu.js +1 -1
- package/dist/cjs/components/dropdown/OpenedDropdown/components/menu/SelectAllMenu.js.map +1 -1
- package/dist/cjs/components/dropdown/OpenedDropdown/components/multiSelect/MultiSelectDropdownBottomBar.js +1 -1
- package/dist/cjs/components/dropdown/OpenedDropdown/components/multiSelect/MultiSelectDropdownBottomBar.js.map +1 -1
- package/dist/cjs/components/dropdown/OpenedDropdown/utils/iterationOnOptions.js +1 -1
- package/dist/cjs/components/dropdown/OpenedDropdown/utils/iterationOnOptions.js.map +1 -1
- package/dist/cjs/components/dropdown/hooks/useDropdown.js +1 -1
- package/dist/cjs/components/dropdown/hooks/useDropdown.js.map +1 -1
- package/dist/cjs/components/dual-icon-button/DualIconButton.styled.js +2 -2
- package/dist/cjs/components/dual-icon-button/DualIconButton.styled.js.map +1 -1
- package/dist/cjs/components/floating-action-button/FloatingActionButton.styles.js +1 -1
- package/dist/cjs/components/floating-action-button/FloatingActionButton.styles.js.map +1 -1
- package/dist/cjs/components/icon-button/IconButton.styled.js +4 -4
- package/dist/cjs/components/icon-button/IconButton.styled.js.map +1 -1
- package/dist/cjs/components/multi-level-dropdown/MultiLevelDropdown.js +1 -1
- package/dist/cjs/components/multi-level-dropdown/MultiLevelDropdown.js.map +1 -1
- package/dist/cjs/components/multi-level-dropdown/MultiLevelDropdown.styled.js +11 -14
- package/dist/cjs/components/multi-level-dropdown/MultiLevelDropdown.styled.js.map +1 -1
- package/dist/cjs/components/plans/SubscriptionPlanSelector.js +1 -1
- package/dist/cjs/components/plans/SubscriptionPlanSelector.js.map +1 -1
- package/dist/cjs/components/product-picker-v2/style.js +2 -2
- package/dist/cjs/components/product-picker-v2/style.js.map +1 -1
- package/dist/cjs/components/switch/Switch.js +2 -2
- package/dist/cjs/components/switch/Switch.js.map +1 -1
- package/dist/cjs/components/template-preview/RCS/RCSPreview.styled.js +1 -1
- package/dist/cjs/components/template-preview/RCS/RCSPreview.styled.js.map +1 -1
- package/dist/cjs/components/template-preview/WhatsApp/ChatUI.style.js +1 -1
- package/dist/cjs/components/template-preview/WhatsApp/ChatUI.style.js.map +1 -1
- package/dist/esm/components/WhatsAppTextEditor/AIRephraseButton.js +2 -2
- package/dist/esm/components/WhatsAppTextEditor/AIRephraseButton.js.map +1 -1
- package/dist/esm/components/WhatsAppTextEditor/WhatsAppTextEditor.js +4 -4
- package/dist/esm/components/WhatsAppTextEditor/WhatsAppTextEditor.js.map +1 -1
- package/dist/esm/components/WhatsAppTextEditor/WhatsAppTextEditorHeader.js +2 -2
- package/dist/esm/components/WhatsAppTextEditor/WhatsAppTextEditorHeader.js.map +1 -1
- package/dist/esm/components/accordion/Accordion.style.js +1 -1
- package/dist/esm/components/accordion/Accordion.style.js.map +1 -1
- package/dist/esm/components/action-button/ActionButton.styled.js +1 -1
- package/dist/esm/components/action-button/ActionButton.styled.js.map +1 -1
- package/dist/esm/components/analytics-chips-and-dropdowns/CommonStyles.js +1 -1
- package/dist/esm/components/analytics-chips-and-dropdowns/CommonStyles.js.map +1 -1
- package/dist/esm/components/bik-layout/SidebarStyles.js +1 -1
- package/dist/esm/components/bik-layout/SidebarStyles.js.map +1 -1
- package/dist/esm/components/button/Button.styled.js +3 -3
- package/dist/esm/components/button/Button.styled.js.map +1 -1
- package/dist/esm/components/buttonGroup/ButtonGroupStyle.js +1 -1
- package/dist/esm/components/buttonGroup/ButtonGroupStyle.js.map +1 -1
- package/dist/esm/components/card-selector/CardSelector.styled.js +1 -1
- package/dist/esm/components/card-selector/CardSelector.styled.js.map +1 -1
- package/dist/esm/components/carousel-preview/CarouselPreview.style.js +2 -2
- package/dist/esm/components/carousel-preview/CarouselPreview.style.js.map +1 -1
- package/dist/esm/components/checkBox/CheckBox.styled.js +1 -1
- package/dist/esm/components/checkBox/CheckBox.styled.js.map +1 -1
- package/dist/esm/components/dropdown/MenuItem/MenuItem.js +1 -1
- package/dist/esm/components/dropdown/MenuItem/MenuItem.js.map +1 -1
- package/dist/esm/components/dropdown/OpenedDropdown/components/OpennedDropdown.js +278 -300
- package/dist/esm/components/dropdown/OpenedDropdown/components/OpennedDropdown.js.map +1 -1
- package/dist/esm/components/dropdown/OpenedDropdown/components/menu/MenuItem.d.ts +0 -8
- package/dist/esm/components/dropdown/OpenedDropdown/components/menu/MenuItem.js +126 -170
- package/dist/esm/components/dropdown/OpenedDropdown/components/menu/MenuItem.js.map +1 -1
- package/dist/esm/components/dropdown/OpenedDropdown/components/menu/MenuList.d.ts +0 -4
- package/dist/esm/components/dropdown/OpenedDropdown/components/menu/MenuList.js +112 -144
- package/dist/esm/components/dropdown/OpenedDropdown/components/menu/MenuList.js.map +1 -1
- package/dist/esm/components/dropdown/OpenedDropdown/components/menu/SelectAllMenu.d.ts +0 -1
- package/dist/esm/components/dropdown/OpenedDropdown/components/menu/SelectAllMenu.js +31 -32
- package/dist/esm/components/dropdown/OpenedDropdown/components/menu/SelectAllMenu.js.map +1 -1
- package/dist/esm/components/dropdown/OpenedDropdown/components/multiSelect/MultiSelectDropdownBottomBar.d.ts +0 -2
- package/dist/esm/components/dropdown/OpenedDropdown/components/multiSelect/MultiSelectDropdownBottomBar.js +39 -54
- package/dist/esm/components/dropdown/OpenedDropdown/components/multiSelect/MultiSelectDropdownBottomBar.js.map +1 -1
- package/dist/esm/components/dropdown/OpenedDropdown/utils/iterationOnOptions.d.ts +16 -18
- package/dist/esm/components/dropdown/OpenedDropdown/utils/iterationOnOptions.js +27 -73
- package/dist/esm/components/dropdown/OpenedDropdown/utils/iterationOnOptions.js.map +1 -1
- package/dist/esm/components/dropdown/hooks/useDropdown.d.ts +17 -4
- package/dist/esm/components/dropdown/hooks/useDropdown.js +163 -176
- package/dist/esm/components/dropdown/hooks/useDropdown.js.map +1 -1
- package/dist/esm/components/dropdown/type.d.ts +0 -22
- package/dist/esm/components/dual-icon-button/DualIconButton.styled.js +2 -2
- package/dist/esm/components/dual-icon-button/DualIconButton.styled.js.map +1 -1
- package/dist/esm/components/floating-action-button/FloatingActionButton.styles.js +1 -1
- package/dist/esm/components/floating-action-button/FloatingActionButton.styles.js.map +1 -1
- package/dist/esm/components/icon-button/IconButton.styled.js +4 -4
- package/dist/esm/components/icon-button/IconButton.styled.js.map +1 -1
- package/dist/esm/components/multi-level-dropdown/MultiLevelDropdown.js +44 -46
- package/dist/esm/components/multi-level-dropdown/MultiLevelDropdown.js.map +1 -1
- package/dist/esm/components/multi-level-dropdown/MultiLevelDropdown.styled.d.ts +0 -3
- package/dist/esm/components/multi-level-dropdown/MultiLevelDropdown.styled.js +25 -29
- package/dist/esm/components/multi-level-dropdown/MultiLevelDropdown.styled.js.map +1 -1
- package/dist/esm/components/multi-level-dropdown/type.d.ts +0 -5
- package/dist/esm/components/plans/SubscriptionPlanSelector.js +1 -1
- package/dist/esm/components/plans/SubscriptionPlanSelector.js.map +1 -1
- package/dist/esm/components/product-picker-v2/style.js +2 -2
- package/dist/esm/components/product-picker-v2/style.js.map +1 -1
- package/dist/esm/components/switch/Switch.js +2 -2
- package/dist/esm/components/switch/Switch.js.map +1 -1
- package/dist/esm/components/template-preview/RCS/RCSPreview.styled.js +1 -1
- package/dist/esm/components/template-preview/RCS/RCSPreview.styled.js.map +1 -1
- package/dist/esm/components/template-preview/WhatsApp/ChatUI.style.js +1 -1
- package/dist/esm/components/template-preview/WhatsApp/ChatUI.style.js.map +1 -1
- package/package.json +1 -1
|
@@ -1,255 +1,242 @@
|
|
|
1
|
-
import
|
|
2
|
-
import { useState as
|
|
3
|
-
import { iterateOnOptionsRaw as
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
}, [
|
|
9
|
-
if (
|
|
10
|
-
let t = [...
|
|
11
|
-
const
|
|
1
|
+
import X from "lodash/debounce";
|
|
2
|
+
import { useState as E, useRef as j, useEffect as A, useCallback as Y, useMemo as Z } from "react";
|
|
3
|
+
import { iterateOnOptionsRaw as _, iterateOnOptions as O } from "../OpenedDropdown/utils/iterationOnOptions.js";
|
|
4
|
+
const S = (h = "1.0", b, y, I, g, w, k, q = [], a) => {
|
|
5
|
+
const [c, i] = E(b ?? []), [v, p] = E([]), [n, z] = E(""), [B, m] = E(void 0), C = j(c), P = j(w);
|
|
6
|
+
A(() => {
|
|
7
|
+
P.current = w;
|
|
8
|
+
}, [w]), A(() => {
|
|
9
|
+
if (C.current = c, v.length && n && w) {
|
|
10
|
+
let t = [...v];
|
|
11
|
+
const r = c.map((e) => {
|
|
12
12
|
if (e.options)
|
|
13
13
|
return e.options.map((l) => ({
|
|
14
14
|
value: l.value,
|
|
15
15
|
selected: l.selected
|
|
16
16
|
}));
|
|
17
|
-
const
|
|
17
|
+
const s = e;
|
|
18
18
|
return {
|
|
19
|
-
value:
|
|
20
|
-
selected:
|
|
19
|
+
value: s.value,
|
|
20
|
+
selected: s.selected
|
|
21
21
|
};
|
|
22
22
|
}).flat();
|
|
23
23
|
t = t.map((e) => {
|
|
24
|
-
const
|
|
24
|
+
const s = r.find(
|
|
25
25
|
(l) => e.value === l.value
|
|
26
26
|
);
|
|
27
|
-
return
|
|
27
|
+
return s ? {
|
|
28
28
|
...e,
|
|
29
|
-
selected:
|
|
29
|
+
selected: s.selected
|
|
30
30
|
} : e;
|
|
31
|
-
}),
|
|
31
|
+
}), k && (t = t.map((e) => ({
|
|
32
32
|
...e,
|
|
33
|
-
disabled: !
|
|
34
|
-
}))),
|
|
33
|
+
disabled: !q.includes(e.value)
|
|
34
|
+
}))), p(g && !I ? [
|
|
35
35
|
...t.sort(
|
|
36
36
|
(e) => e.selected ? -1 : 1
|
|
37
37
|
)
|
|
38
38
|
] : [...t]);
|
|
39
39
|
}
|
|
40
|
-
}, [
|
|
41
|
-
if (
|
|
42
|
-
const t = [...
|
|
43
|
-
|
|
40
|
+
}, [c]), A(() => {
|
|
41
|
+
if (b) {
|
|
42
|
+
const t = [...b];
|
|
43
|
+
i(g && !I ? [
|
|
44
44
|
...t.sort(
|
|
45
|
-
(
|
|
45
|
+
(r) => r.selected ? -1 : 1
|
|
46
46
|
)
|
|
47
47
|
] : [...t]);
|
|
48
48
|
}
|
|
49
|
-
}, [
|
|
50
|
-
const
|
|
51
|
-
const
|
|
49
|
+
}, [b]);
|
|
50
|
+
const H = (t) => {
|
|
51
|
+
const r = [];
|
|
52
52
|
return t.forEach((e) => {
|
|
53
53
|
if (e.options) {
|
|
54
|
-
const
|
|
54
|
+
const s = e.options.filter(
|
|
55
55
|
(l) => l.selected === !0
|
|
56
56
|
);
|
|
57
|
-
|
|
57
|
+
r.push({
|
|
58
58
|
...e,
|
|
59
|
-
options: [...
|
|
59
|
+
options: [...s]
|
|
60
60
|
});
|
|
61
|
-
} else
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
}, F = (t) => x(t, v).filter((s) => s.selected).length, R = (t) => !b || !i && i !== 0 ? !1 : F(t) >= i, y = _(async (t) => {
|
|
75
|
-
const s = H.current;
|
|
76
|
-
if (!t || !s) return;
|
|
61
|
+
} else
|
|
62
|
+
e.selected && r.push({ ...e });
|
|
63
|
+
}), r;
|
|
64
|
+
}, L = (t) => {
|
|
65
|
+
let r = 0;
|
|
66
|
+
return t.forEach((e) => {
|
|
67
|
+
e.options ? r += e.options.filter(
|
|
68
|
+
(s) => s.selected === !0
|
|
69
|
+
).length : e.selected && r++;
|
|
70
|
+
}), r;
|
|
71
|
+
}, D = (t) => !g || !a && a !== 0 ? !1 : L(t) >= a, R = Y(async (t) => {
|
|
72
|
+
const r = P.current;
|
|
73
|
+
if (!t || !r) return;
|
|
77
74
|
const e = [];
|
|
78
|
-
|
|
79
|
-
|
|
75
|
+
_(C.current, (s) => {
|
|
76
|
+
s.selected && !e.includes(s.value) && e.push(s.value);
|
|
80
77
|
});
|
|
81
78
|
try {
|
|
82
|
-
const
|
|
83
|
-
if (
|
|
84
|
-
const l =
|
|
85
|
-
if (
|
|
86
|
-
const
|
|
79
|
+
const s = await r(t);
|
|
80
|
+
if (m(void 0), s) {
|
|
81
|
+
const l = s.map((f) => {
|
|
82
|
+
if (f.options) {
|
|
83
|
+
const d = f;
|
|
87
84
|
return {
|
|
88
|
-
...
|
|
89
|
-
options:
|
|
85
|
+
...d,
|
|
86
|
+
options: d.options.map((u) => ({
|
|
90
87
|
...u,
|
|
91
88
|
selected: e.includes(u.value)
|
|
92
89
|
}))
|
|
93
90
|
};
|
|
94
91
|
}
|
|
95
92
|
return {
|
|
96
|
-
...
|
|
97
|
-
selected: e.includes(
|
|
93
|
+
...f,
|
|
94
|
+
selected: e.includes(f.value)
|
|
98
95
|
};
|
|
99
96
|
});
|
|
100
|
-
|
|
97
|
+
p([...l]);
|
|
101
98
|
} else
|
|
102
|
-
|
|
103
|
-
} catch (
|
|
104
|
-
|
|
105
|
-
|
|
99
|
+
p([]);
|
|
100
|
+
} catch (s) {
|
|
101
|
+
p([]), m(
|
|
102
|
+
s instanceof Error ? s.message : "Something went wrong while fetching the list. Please try again"
|
|
106
103
|
);
|
|
107
104
|
}
|
|
108
|
-
}, []),
|
|
109
|
-
() =>
|
|
110
|
-
[
|
|
105
|
+
}, []), F = Z(
|
|
106
|
+
() => X(R, 300),
|
|
107
|
+
[R]
|
|
111
108
|
);
|
|
112
|
-
|
|
113
|
-
function
|
|
114
|
-
if (
|
|
115
|
-
|
|
109
|
+
A(() => () => F?.cancel(), [F]);
|
|
110
|
+
function G(t) {
|
|
111
|
+
if (z(t), p([]), m(void 0), !t) {
|
|
112
|
+
F?.cancel();
|
|
116
113
|
return;
|
|
117
114
|
}
|
|
118
|
-
|
|
115
|
+
F(t);
|
|
119
116
|
}
|
|
120
|
-
function
|
|
121
|
-
n && (
|
|
117
|
+
function J() {
|
|
118
|
+
n && (m(void 0), R(n));
|
|
122
119
|
}
|
|
123
|
-
function
|
|
124
|
-
if (!
|
|
125
|
-
|
|
120
|
+
function T(t, r) {
|
|
121
|
+
if (!g)
|
|
122
|
+
y?.(t);
|
|
126
123
|
else {
|
|
127
|
-
if (t.selected &&
|
|
124
|
+
if (t.selected && a && D(c))
|
|
128
125
|
return;
|
|
129
|
-
if (
|
|
126
|
+
if (v.length && n && w)
|
|
130
127
|
if (t.selected) {
|
|
131
|
-
if (
|
|
128
|
+
if (a && D(c))
|
|
132
129
|
return;
|
|
133
130
|
let e = !1;
|
|
134
|
-
const
|
|
135
|
-
|
|
131
|
+
const s = O(
|
|
132
|
+
c,
|
|
136
133
|
{ selected: t.selected },
|
|
137
|
-
(l) => l.value === t.value ? (e = !0, !0) : !1
|
|
138
|
-
v
|
|
134
|
+
(l) => l.value === t.value ? (e = !0, !0) : !1
|
|
139
135
|
);
|
|
140
|
-
if (e ||
|
|
141
|
-
return [...
|
|
142
|
-
|
|
136
|
+
if (e || s.push(t), r)
|
|
137
|
+
return [...s];
|
|
138
|
+
i([...s]), h === "2.0" && o(s);
|
|
143
139
|
} else {
|
|
144
|
-
let e = !1,
|
|
145
|
-
|
|
140
|
+
let e = !1, s = O(
|
|
141
|
+
c,
|
|
146
142
|
{ selected: t.selected },
|
|
147
|
-
(l) => l.value === t.value ? (e = !0, !0) : !1
|
|
148
|
-
v
|
|
143
|
+
(l) => l.value === t.value ? (e = !0, !0) : !1
|
|
149
144
|
);
|
|
150
|
-
if (e && (
|
|
151
|
-
return [...
|
|
152
|
-
|
|
145
|
+
if (e && (s = s.filter((l) => l.value !== t.value)), r)
|
|
146
|
+
return [...s];
|
|
147
|
+
i([...s]), h === "2.0" && o(s);
|
|
153
148
|
}
|
|
154
149
|
else {
|
|
155
150
|
const e = O(
|
|
156
|
-
|
|
151
|
+
c,
|
|
157
152
|
{ selected: t.selected },
|
|
158
|
-
(
|
|
159
|
-
v
|
|
153
|
+
(s) => s.value === t.value
|
|
160
154
|
);
|
|
161
|
-
if (
|
|
155
|
+
if (r)
|
|
162
156
|
return [...e];
|
|
163
|
-
|
|
157
|
+
i([...e]), h === "2.0" && o(e);
|
|
164
158
|
}
|
|
165
159
|
}
|
|
166
160
|
}
|
|
167
|
-
function
|
|
168
|
-
let
|
|
169
|
-
|
|
170
|
-
|
|
161
|
+
function M(t) {
|
|
162
|
+
let r = [...c];
|
|
163
|
+
v.forEach((e) => {
|
|
164
|
+
r = r.map((s) => {
|
|
171
165
|
const l = e;
|
|
172
|
-
return typeof l.value < "u" && l.value ===
|
|
173
|
-
...
|
|
166
|
+
return typeof l.value < "u" && l.value === s.value ? {
|
|
167
|
+
...s,
|
|
174
168
|
selected: !1
|
|
175
|
-
} :
|
|
169
|
+
} : s;
|
|
176
170
|
});
|
|
177
|
-
}),
|
|
171
|
+
}), i([...r]), h === "2.0" && o(r);
|
|
178
172
|
}
|
|
179
|
-
function
|
|
180
|
-
let
|
|
181
|
-
if (
|
|
182
|
-
const e =
|
|
183
|
-
if (
|
|
173
|
+
function N(t) {
|
|
174
|
+
let r = [...c];
|
|
175
|
+
if (a && a > 0) {
|
|
176
|
+
const e = L(r), s = a - e;
|
|
177
|
+
if (s <= 0)
|
|
184
178
|
return;
|
|
185
179
|
let l = 0;
|
|
186
|
-
|
|
187
|
-
if (l >=
|
|
180
|
+
v.forEach((f) => {
|
|
181
|
+
if (l >= s)
|
|
188
182
|
return;
|
|
189
|
-
let
|
|
190
|
-
|
|
191
|
-
const
|
|
192
|
-
return u.selected || u.disabled ? u : typeof
|
|
183
|
+
let d = !1;
|
|
184
|
+
r = r.map((u) => {
|
|
185
|
+
const W = f;
|
|
186
|
+
return u.selected || u.disabled ? u : typeof W.value < "u" && W.value === u.value ? (d = !0, l++, {
|
|
193
187
|
...u,
|
|
194
188
|
selected: !0
|
|
195
189
|
}) : u;
|
|
196
|
-
}), !
|
|
197
|
-
}),
|
|
190
|
+
}), !d && l < s && (f.disabled || (r.push({ ...f, selected: !0 }), l++));
|
|
191
|
+
}), i([...r]), h === "2.0" && o(r);
|
|
198
192
|
}
|
|
199
193
|
}
|
|
200
|
-
function
|
|
201
|
-
if (
|
|
202
|
-
t === "selectAll" ?
|
|
194
|
+
function Q(t) {
|
|
195
|
+
if (v.length && n && w)
|
|
196
|
+
t === "selectAll" ? N() : M();
|
|
203
197
|
else if (t === "selectAll")
|
|
204
|
-
if (
|
|
205
|
-
const
|
|
198
|
+
if (a && a > 0) {
|
|
199
|
+
const r = L(c), e = a - r;
|
|
206
200
|
if (e <= 0)
|
|
207
201
|
return;
|
|
208
|
-
let
|
|
209
|
-
const l =
|
|
210
|
-
if (
|
|
211
|
-
const
|
|
202
|
+
let s = 0;
|
|
203
|
+
const l = c.map((f) => {
|
|
204
|
+
if (f.options) {
|
|
205
|
+
const d = f;
|
|
212
206
|
return {
|
|
213
|
-
...
|
|
214
|
-
options:
|
|
207
|
+
...d,
|
|
208
|
+
options: d.options.map((u) => u.disabled || u.selected || n && !u.label?.toLowerCase().includes(n.toLowerCase()) ? u : s < e ? (s++, { ...u, selected: !0 }) : u)
|
|
215
209
|
};
|
|
216
210
|
} else {
|
|
217
|
-
const
|
|
218
|
-
return
|
|
211
|
+
const d = f;
|
|
212
|
+
return d.disabled || d.selected || n && !d.label?.toLowerCase().includes(n.toLowerCase()) ? f : s < e ? (s++, { ...f, selected: !0 }) : f;
|
|
219
213
|
}
|
|
220
214
|
});
|
|
221
|
-
|
|
215
|
+
i([...l]), h === "2.0" && o(l);
|
|
222
216
|
} else {
|
|
223
|
-
const
|
|
224
|
-
|
|
217
|
+
const r = O(
|
|
218
|
+
c,
|
|
225
219
|
{ selected: !0 },
|
|
226
|
-
(e) => n ? e.label?.toLowerCase().includes(n.toLowerCase()) && !e.disabled : !e.disabled
|
|
227
|
-
v
|
|
220
|
+
(e) => n ? e.label?.toLowerCase().includes(n.toLowerCase()) && !e.disabled : !e.disabled
|
|
228
221
|
);
|
|
229
|
-
|
|
222
|
+
i([...r]), h === "2.0" && o(r);
|
|
230
223
|
}
|
|
231
224
|
else if (t === "notSelected") {
|
|
232
|
-
const
|
|
233
|
-
|
|
225
|
+
const r = O(
|
|
226
|
+
c,
|
|
234
227
|
{ selected: !1 },
|
|
235
|
-
(e) => !e.disabled
|
|
236
|
-
v
|
|
228
|
+
(e) => !e.disabled
|
|
237
229
|
);
|
|
238
|
-
|
|
230
|
+
i([...r]), h === "2.0" && o(r);
|
|
239
231
|
}
|
|
240
232
|
}
|
|
241
|
-
function
|
|
242
|
-
const t = O(
|
|
243
|
-
|
|
244
|
-
{ selected: !1 },
|
|
245
|
-
void 0,
|
|
246
|
-
v
|
|
247
|
-
);
|
|
248
|
-
d([...t]), h === "2.0" && o(t);
|
|
233
|
+
function U() {
|
|
234
|
+
const t = O(c, { selected: !1 });
|
|
235
|
+
i([...t]), h === "2.0" && o(t);
|
|
249
236
|
}
|
|
250
|
-
function
|
|
251
|
-
if (!
|
|
252
|
-
|
|
237
|
+
function V(t) {
|
|
238
|
+
if (!g) {
|
|
239
|
+
T({
|
|
253
240
|
label: n,
|
|
254
241
|
value: n,
|
|
255
242
|
isFreeForm: !0,
|
|
@@ -257,7 +244,7 @@ const re = (h = "1.0", m, I, P, b, g, q, z = [], i, B) => {
|
|
|
257
244
|
});
|
|
258
245
|
return;
|
|
259
246
|
}
|
|
260
|
-
const
|
|
247
|
+
const r = c.map(
|
|
261
248
|
(e) => e.options ? e : {
|
|
262
249
|
...e,
|
|
263
250
|
selected: (
|
|
@@ -269,41 +256,41 @@ const re = (h = "1.0", m, I, P, b, g, q, z = [], i, B) => {
|
|
|
269
256
|
)
|
|
270
257
|
}
|
|
271
258
|
);
|
|
272
|
-
t && (
|
|
259
|
+
t && (r.some(
|
|
273
260
|
(e) => e.label === n && e.value === n
|
|
274
|
-
) ||
|
|
261
|
+
) || r.unshift({
|
|
275
262
|
label: n,
|
|
276
263
|
value: n,
|
|
277
264
|
isFreeForm: !0,
|
|
278
265
|
selected: !0
|
|
279
|
-
})),
|
|
266
|
+
})), i([...r]), h === "2.0" && o(r);
|
|
280
267
|
}
|
|
281
268
|
function o(t) {
|
|
282
|
-
const
|
|
283
|
-
t ??
|
|
269
|
+
const r = H(
|
|
270
|
+
t ?? C.current
|
|
284
271
|
);
|
|
285
|
-
|
|
272
|
+
y?.([...r]);
|
|
286
273
|
}
|
|
287
274
|
return {
|
|
288
|
-
latestDropdownOptionsRef:
|
|
289
|
-
dropdownOptions:
|
|
290
|
-
search:
|
|
275
|
+
latestDropdownOptionsRef: C,
|
|
276
|
+
dropdownOptions: c,
|
|
277
|
+
search: G,
|
|
291
278
|
searchedString: n,
|
|
292
|
-
searchedOptions:
|
|
293
|
-
searchError:
|
|
294
|
-
retrySearch:
|
|
295
|
-
onApplyHandler:
|
|
296
|
-
selectAllHandler:
|
|
297
|
-
onMultiSelectClear:
|
|
298
|
-
onFreeFormSelect:
|
|
279
|
+
searchedOptions: v,
|
|
280
|
+
searchError: B,
|
|
281
|
+
retrySearch: J,
|
|
282
|
+
onApplyHandler: T,
|
|
283
|
+
selectAllHandler: Q,
|
|
284
|
+
onMultiSelectClear: U,
|
|
285
|
+
onFreeFormSelect: V,
|
|
299
286
|
onMultiSelectApply: o,
|
|
300
|
-
getSelectedOptions:
|
|
301
|
-
getCurrentSelectionCount:
|
|
302
|
-
isMaxSelectionsReached:
|
|
303
|
-
maxSelections:
|
|
287
|
+
getSelectedOptions: H,
|
|
288
|
+
getCurrentSelectionCount: L,
|
|
289
|
+
isMaxSelectionsReached: D,
|
|
290
|
+
maxSelections: a
|
|
304
291
|
};
|
|
305
292
|
};
|
|
306
293
|
export {
|
|
307
|
-
|
|
294
|
+
S as useDropdown
|
|
308
295
|
};
|
|
309
296
|
//# sourceMappingURL=useDropdown.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDropdown.js","sources":["../../../../../src/components/dropdown/hooks/useDropdown.tsx"],"sourcesContent":["import debounce from 'lodash/debounce';\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport { SelectAllCheckboxState } from '../OpenedDropdown/components/menu/SelectAllMenu';\nimport {\n\tgetSelectionLeaves,\n\titerateOnOptions,\n\titerateOnOptionsRaw,\n} from '../OpenedDropdown/utils/iterationOnOptions';\nimport { DropdownOption, GroupedOption, SingleOption } from '../type';\n\nexport const useDropdown = (\n\tversion = '1.0',\n\toptions: DropdownOption[],\n\tonSelect: ((option: DropdownOption | DropdownOption[]) => void) | undefined,\n\tskipSorting?: boolean,\n\tisMultiSelect?: boolean,\n\tonSearch?: (searchKey: string) => Promise<DropdownOption[]>,\n\tdisableOtherSearchedOption?: boolean,\n\tdisableSearchedOptionExcept: string[] = [],\n\tmaxSelections?: number,\n\tchildrenLayout?: 'flyout' | 'nested',\n) => {\n\t// Only the nested layout makes children selectable; a flyout submenu click\n\t// marks the parent instead.\n\tconst nestedChildren = childrenLayout === 'nested';\n\tconst [dropdownOptions, setDropdownOptions] = useState(options ?? []);\n\tconst [searchedOptions, setSearchedOptions] = useState<DropdownOption[]>([]);\n\tconst [searchedString, setSearchedString] = useState('');\n\tconst [searchError, setSearchError] = useState<string | undefined>(undefined);\n\tconst latestDropdownOptionsRef = useRef(dropdownOptions);\n\t/** Store latest onSearch so performSearch/debouncedSearch stay stable when parent re-renders with new callback reference. */\n\tconst onSearchRef = useRef(onSearch);\n\n\tuseEffect(() => {\n\t\tonSearchRef.current = onSearch;\n\t}, [onSearch]);\n\n\tuseEffect(() => {\n\t\tlatestDropdownOptionsRef.current = dropdownOptions;\n\n\t\tif (searchedOptions.length && searchedString && onSearch) {\n\t\t\tlet searchedOptionsClone = [...searchedOptions] as SingleOption[];\n\t\t\tconst dropdownOptionFlat = dropdownOptions\n\t\t\t\t.map((option) => {\n\t\t\t\t\tif ((option as GroupedOption).options) {\n\t\t\t\t\t\treturn (option as GroupedOption).options.map((op) => ({\n\t\t\t\t\t\t\tvalue: op.value,\n\t\t\t\t\t\t\tselected: op.selected,\n\t\t\t\t\t\t}));\n\t\t\t\t\t}\n\t\t\t\t\tconst op = option as SingleOption;\n\t\t\t\t\treturn {\n\t\t\t\t\t\tvalue: op.value,\n\t\t\t\t\t\tselected: op.selected,\n\t\t\t\t\t};\n\t\t\t\t})\n\t\t\t\t.flat();\n\n\t\t\tsearchedOptionsClone = searchedOptionsClone.map((option) => {\n\t\t\t\tconst selectedDropdownOption = dropdownOptionFlat.find(\n\t\t\t\t\t(dropdownOption) => {\n\t\t\t\t\t\tif (option.value === dropdownOption.value) {\n\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t},\n\t\t\t\t);\n\n\t\t\t\tif (selectedDropdownOption) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...option,\n\t\t\t\t\t\tselected: selectedDropdownOption.selected,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\treturn option;\n\t\t\t});\n\n\t\t\t// disable other options except selected in searched options\n\t\t\tif (disableOtherSearchedOption) {\n\t\t\t\tsearchedOptionsClone = searchedOptionsClone.map((option) => {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...option,\n\t\t\t\t\t\tdisabled: !disableSearchedOptionExcept.includes(option.value),\n\t\t\t\t\t};\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (isMultiSelect && !skipSorting) {\n\t\t\t\tsetSearchedOptions([\n\t\t\t\t\t...searchedOptionsClone.sort((option) =>\n\t\t\t\t\t\t(option as SingleOption).selected ? -1 : 1,\n\t\t\t\t\t),\n\t\t\t\t]);\n\t\t\t} else {\n\t\t\t\tsetSearchedOptions([...searchedOptionsClone]);\n\t\t\t}\n\t\t}\n\t}, [dropdownOptions]);\n\n\tuseEffect(() => {\n\t\tif (options) {\n\t\t\tconst writeOptions = [...options];\n\t\t\tif (isMultiSelect && !skipSorting) {\n\t\t\t\tsetDropdownOptions([\n\t\t\t\t\t...writeOptions.sort((option) =>\n\t\t\t\t\t\t(option as SingleOption).selected ? -1 : 1,\n\t\t\t\t\t),\n\t\t\t\t]);\n\t\t\t} else {\n\t\t\t\tsetDropdownOptions([...writeOptions]);\n\t\t\t}\n\t\t}\n\t}, [options]);\n\n\tconst getSelectedOptions = (data: DropdownOption[]) => {\n\t\tconst selectedOptions: DropdownOption[] = [];\n\t\tdata.forEach((option) => {\n\t\t\tif ((option as GroupedOption).options) {\n\t\t\t\tconst groupedOptions = (option as GroupedOption).options.filter(\n\t\t\t\t\t(op) => op.selected === true,\n\t\t\t\t);\n\t\t\t\tselectedOptions.push({\n\t\t\t\t\t...option,\n\t\t\t\t\toptions: [...groupedOptions],\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tconst singleOption = option as SingleOption;\n\t\t\t\tif (nestedChildren && singleOption.children?.length) {\n\t\t\t\t\t// A partly selected parent is itself unselected, so report it\n\t\t\t\t\t// whenever any child is selected, carrying only those children.\n\t\t\t\t\tconst selectedChildren = singleOption.children.filter(\n\t\t\t\t\t\t(child) => child.selected,\n\t\t\t\t\t);\n\t\t\t\t\tif (selectedChildren.length) {\n\t\t\t\t\t\tselectedOptions.push({\n\t\t\t\t\t\t\t...singleOption,\n\t\t\t\t\t\t\tchildren: selectedChildren,\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\t\t\t\t} else if (singleOption.selected) {\n\t\t\t\t\tselectedOptions.push({ ...option });\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\treturn selectedOptions;\n\t};\n\n\t// Count current selections for max selection limit\n\tconst getCurrentSelectionCount = (data: DropdownOption[]) =>\n\t\tgetSelectionLeaves(data, nestedChildren).filter((leaf) => leaf.selected)\n\t\t\t.length;\n\n\t// Check if max selections limit is reached\n\tconst isMaxSelectionsReached = (data: DropdownOption[]) => {\n\t\tif (!isMultiSelect || (!maxSelections && maxSelections !== 0)) return false;\n\t\treturn getCurrentSelectionCount(data) >= maxSelections;\n\t};\n\n\t/** Reads onSearch from ref so it stays stable ([] deps). No-ops when onSearchRef.current is undefined. */\n\tconst performSearch = useCallback(async (searchKey: string) => {\n\t\tconst onSearchFn = onSearchRef.current;\n\t\tif (!searchKey || !onSearchFn) return;\n\n\t\tconst selectedIds: (string | number)[] = [];\n\t\titerateOnOptionsRaw(latestDropdownOptionsRef.current, (option) => {\n\t\t\tif (option.selected && !selectedIds.includes(option.value)) {\n\t\t\t\tselectedIds.push(option.value);\n\t\t\t}\n\t\t});\n\n\t\ttry {\n\t\t\tconst response = await onSearchFn(searchKey);\n\t\t\tsetSearchError(undefined);\n\t\t\tif (response) {\n\t\t\t\tconst updatedResponseData = response.map((option) => {\n\t\t\t\t\tif ((option as GroupedOption).options) {\n\t\t\t\t\t\tconst groupedOption = option as GroupedOption;\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...groupedOption,\n\t\t\t\t\t\t\toptions: groupedOption.options.map((op) => ({\n\t\t\t\t\t\t\t\t...op,\n\t\t\t\t\t\t\t\tselected: selectedIds.includes(op.value),\n\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...option,\n\t\t\t\t\t\tselected: selectedIds.includes((option as SingleOption).value),\n\t\t\t\t\t};\n\t\t\t\t});\n\n\t\t\t\tsetSearchedOptions([...updatedResponseData]);\n\t\t\t} else {\n\t\t\t\tsetSearchedOptions([]);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tsetSearchedOptions([]);\n\t\t\tsetSearchError(\n\t\t\t\terror instanceof Error\n\t\t\t\t\t? error.message\n\t\t\t\t\t: 'Something went wrong while fetching the list. Please try again',\n\t\t\t);\n\t\t}\n\t}, []);\n\n\t/** Independent of onSearch so debounce is stable when callers pass inline functions. Pending searches are preserved across parent re-renders. performSearch no-ops when onSearchRef.current is undefined. */\n\tconst debouncedSearch = useMemo(\n\t\t() => debounce(performSearch, 300),\n\t\t[performSearch],\n\t);\n\n\tuseEffect(() => () => debouncedSearch?.cancel(), [debouncedSearch]);\n\n\tfunction search(searchKey: string) {\n\t\tsetSearchedString(searchKey);\n\t\tsetSearchedOptions([]);\n\t\tsetSearchError(undefined);\n\n\t\tif (!searchKey) {\n\t\t\tdebouncedSearch?.cancel();\n\t\t\treturn;\n\t\t}\n\n\t\tdebouncedSearch(searchKey);\n\t}\n\n\tfunction retrySearch() {\n\t\tif (searchedString) {\n\t\t\tsetSearchError(undefined);\n\t\t\tperformSearch(searchedString);\n\t\t}\n\t}\n\n\t/**\n\t * wrapper to prepare option for onSelect\n\t * for single select, this will call the onClose handler ,\n\t * for multiselect, it will do state update for options list\n\t * \t\tto make any option select,\n\t * \t\t\t\tonApplyHandler({ label, value: selected: true })\n\t * to deselect any option\n\t * \t\t\t\tonApplyHandler({ label, value: selected: false })\n\t * @param optionSelect\n\t */\n\tfunction onApplyHandler(optionSelect: SingleOption, returnOnly?: boolean) {\n\t\tif (!isMultiSelect) {\n\t\t\tonSelect?.(optionSelect);\n\t\t} else {\n\t\t\t// Check if trying to select and max selections is reached\n\t\t\tif (\n\t\t\t\toptionSelect.selected &&\n\t\t\t\tmaxSelections &&\n\t\t\t\tisMaxSelectionsReached(dropdownOptions)\n\t\t\t) {\n\t\t\t\t// Max selections reached, don't allow new selections\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (searchedOptions.length && searchedString && onSearch) {\n\t\t\t\t/** Search mode */\n\t\t\t\t/**\n\t\t\t\t * on selected, push it to dropdown options,\n\t\t\t\t * on un-select, remove from dropdown option\n\t\t\t\t */\n\n\t\t\t\tif (optionSelect.selected) {\n\t\t\t\t\t// Check max selections for search mode too\n\t\t\t\t\tif (maxSelections && isMaxSelectionsReached(dropdownOptions)) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\t/** check if already there or not,\n\t\t\t\t\t * if yes, just update\n\t\t\t\t\t * else ,\n\t\t\t\t\t * \tappend\n\t\t\t\t\t */\n\n\t\t\t\t\tlet alreadyPresentInInitialOptions = false;\n\t\t\t\t\tconst currList = iterateOnOptions(\n\t\t\t\t\t\tdropdownOptions,\n\t\t\t\t\t\t{ selected: optionSelect.selected } as Partial<SingleOption>,\n\t\t\t\t\t\t(optionForValidation: SingleOption) => {\n\t\t\t\t\t\t\tif (optionForValidation.value === optionSelect.value) {\n\t\t\t\t\t\t\t\talreadyPresentInInitialOptions = true;\n\t\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t},\n\t\t\t\t\t\tnestedChildren,\n\t\t\t\t\t);\n\n\t\t\t\t\tif (!alreadyPresentInInitialOptions) {\n\t\t\t\t\t\tcurrList.push(optionSelect);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (returnOnly) {\n\t\t\t\t\t\treturn [...currList];\n\t\t\t\t\t}\n\t\t\t\t\tsetDropdownOptions([...currList]);\n\t\t\t\t\tif (version === '2.0') {\n\t\t\t\t\t\tonMultiSelectApply(currList);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t/** un-select,\n\t\t\t\t\t * if already present in initial data,\n\t\t\t\t\t * yes, just update\n\t\t\t\t\t * else,\n\t\t\t\t\t * \tremove\n\t\t\t\t\t */\n\n\t\t\t\t\tlet alreadyPresentInInitialOptions = false;\n\t\t\t\t\tlet currList = iterateOnOptions(\n\t\t\t\t\t\tdropdownOptions,\n\t\t\t\t\t\t{ selected: optionSelect.selected } as Partial<SingleOption>,\n\t\t\t\t\t\t(optionForValidation: SingleOption) => {\n\t\t\t\t\t\t\tif (optionForValidation.value === optionSelect.value) {\n\t\t\t\t\t\t\t\talreadyPresentInInitialOptions = true;\n\t\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t},\n\t\t\t\t\t\tnestedChildren,\n\t\t\t\t\t);\n\n\t\t\t\t\tif (alreadyPresentInInitialOptions) {\n\t\t\t\t\t\tcurrList = currList.filter((option) => {\n\t\t\t\t\t\t\tif ((option as SingleOption).value === optionSelect.value) {\n\t\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tif (returnOnly) {\n\t\t\t\t\t\treturn [...currList];\n\t\t\t\t\t}\n\t\t\t\t\tsetDropdownOptions([...currList]);\n\t\t\t\t\tif (version === '2.0') {\n\t\t\t\t\t\tonMultiSelectApply(currList);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconst currList = iterateOnOptions(\n\t\t\t\t\tdropdownOptions,\n\t\t\t\t\t{ selected: optionSelect.selected } as Partial<SingleOption>,\n\t\t\t\t\t(optionForValidation: SingleOption) =>\n\t\t\t\t\t\toptionForValidation.value === optionSelect.value,\n\t\t\t\t\tnestedChildren,\n\t\t\t\t);\n\n\t\t\t\tif (returnOnly) {\n\t\t\t\t\treturn [...currList];\n\t\t\t\t}\n\t\t\t\tsetDropdownOptions([...currList]);\n\t\t\t\tif (version === '2.0') {\n\t\t\t\t\tonMultiSelectApply(currList);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction selectAllForSearch(select: boolean) {\n\t\t// const allSearchedValues = searchedOptions.map(option => option.value);\n\t\tlet clonedDropdownOptions = [...dropdownOptions];\n\n\t\tif (select) {\n\t\t\tsearchedOptions.forEach((option) => {\n\t\t\t\tlet found = false;\n\t\t\t\tclonedDropdownOptions = clonedDropdownOptions.map((dOption) => {\n\t\t\t\t\tconst singleOption = option as SingleOption;\n\t\t\t\t\tif (\n\t\t\t\t\t\ttypeof singleOption.value !== 'undefined' &&\n\t\t\t\t\t\tsingleOption.value === (dOption as SingleOption).value\n\t\t\t\t\t) {\n\t\t\t\t\t\tfound = true;\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...dOption,\n\t\t\t\t\t\t\tselected: true,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\treturn dOption;\n\t\t\t\t});\n\n\t\t\t\tif (!found) {\n\t\t\t\t\tclonedDropdownOptions.push({ ...option, selected: true });\n\t\t\t\t}\n\t\t\t});\n\t\t} else {\n\t\t\tsearchedOptions.forEach((option) => {\n\t\t\t\tclonedDropdownOptions = clonedDropdownOptions.map((dOption) => {\n\t\t\t\t\tconst singleOption = option as SingleOption;\n\t\t\t\t\tif (\n\t\t\t\t\t\ttypeof singleOption.value !== 'undefined' &&\n\t\t\t\t\t\tsingleOption.value === (dOption as SingleOption).value\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...dOption,\n\t\t\t\t\t\t\tselected: false,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\treturn dOption;\n\t\t\t\t});\n\t\t\t});\n\t\t}\n\n\t\tsetDropdownOptions([...clonedDropdownOptions]);\n\t\tif (version === '2.0') {\n\t\t\tonMultiSelectApply(clonedDropdownOptions);\n\t\t}\n\t}\n\n\tfunction selectAllForSearchWithLimit(select: boolean) {\n\t\tlet clonedDropdownOptions = [...dropdownOptions];\n\n\t\tif (select && maxSelections && maxSelections > 0) {\n\t\t\tconst currentCount = getCurrentSelectionCount(clonedDropdownOptions);\n\t\t\tconst remainingSlots = maxSelections - currentCount;\n\n\t\t\tif (remainingSlots <= 0) {\n\t\t\t\t// Already at max, don't select any more\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet selectedCount = 0;\n\t\t\tsearchedOptions.forEach((option) => {\n\t\t\t\tif (selectedCount >= remainingSlots) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tlet found = false;\n\t\t\t\tclonedDropdownOptions = clonedDropdownOptions.map((dOption) => {\n\t\t\t\t\tconst singleOption = option as SingleOption;\n\t\t\t\t\t// Skip if already selected\n\t\t\t\t\tif ((dOption as SingleOption).selected) {\n\t\t\t\t\t\treturn dOption;\n\t\t\t\t\t}\n\t\t\t\t\t// Skip if disabled\n\t\t\t\t\tif ((dOption as SingleOption).disabled) {\n\t\t\t\t\t\treturn dOption;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\n\t\t\t\t\t\ttypeof singleOption.value !== 'undefined' &&\n\t\t\t\t\t\tsingleOption.value === (dOption as SingleOption).value\n\t\t\t\t\t) {\n\t\t\t\t\t\tfound = true;\n\t\t\t\t\t\tselectedCount++;\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...dOption,\n\t\t\t\t\t\t\tselected: true,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\treturn dOption;\n\t\t\t\t});\n\n\t\t\t\tif (!found && selectedCount < remainingSlots) {\n\t\t\t\t\tconst newOption = option as SingleOption;\n\t\t\t\t\tif (!newOption.disabled) {\n\t\t\t\t\t\tclonedDropdownOptions.push({ ...option, selected: true });\n\t\t\t\t\t\tselectedCount++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tsetDropdownOptions([...clonedDropdownOptions]);\n\t\t\tif (version === '2.0') {\n\t\t\t\tonMultiSelectApply(clonedDropdownOptions);\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction selectAllHandler(newState: SelectAllCheckboxState) {\n\t\tif (searchedOptions.length && searchedString && onSearch) {\n\t\t\tif (newState === 'selectAll') {\n\t\t\t\tselectAllForSearchWithLimit(true);\n\t\t\t} else {\n\t\t\t\tselectAllForSearch(false);\n\t\t\t}\n\t\t} else {\n\t\t\tif (newState === 'selectAll') {\n\t\t\t\tif (maxSelections && maxSelections > 0) {\n\t\t\t\t\t// Only select up to maxSelections limit\n\t\t\t\t\tconst currentCount = getCurrentSelectionCount(dropdownOptions);\n\t\t\t\t\tconst remainingSlots = maxSelections - currentCount;\n\n\t\t\t\t\tif (remainingSlots <= 0) {\n\t\t\t\t\t\t// Already at max, don't select any more\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tlet selectedCount = 0;\n\t\t\t\t\tconst newOptions = dropdownOptions.map((option) => {\n\t\t\t\t\t\tif ((option as GroupedOption).options) {\n\t\t\t\t\t\t\t// Handle grouped options\n\t\t\t\t\t\t\tconst groupedOption = option as GroupedOption;\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t...groupedOption,\n\t\t\t\t\t\t\t\toptions: groupedOption.options.map((op) => {\n\t\t\t\t\t\t\t\t\t// Skip disabled options\n\t\t\t\t\t\t\t\t\tif (op.disabled) {\n\t\t\t\t\t\t\t\t\t\treturn op;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t// Check if already selected\n\t\t\t\t\t\t\t\t\tif (op.selected) {\n\t\t\t\t\t\t\t\t\t\treturn op;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t// Check search filter\n\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\tsearchedString &&\n\t\t\t\t\t\t\t\t\t\t!op.label\n\t\t\t\t\t\t\t\t\t\t\t?.toLowerCase()\n\t\t\t\t\t\t\t\t\t\t\t.includes(searchedString.toLowerCase())\n\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\treturn op;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t// Select if we have remaining slots\n\t\t\t\t\t\t\t\t\tif (selectedCount < remainingSlots) {\n\t\t\t\t\t\t\t\t\t\tselectedCount++;\n\t\t\t\t\t\t\t\t\t\treturn { ...op, selected: true };\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn op;\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tconst singleOption = option as SingleOption;\n\t\t\t\t\t\t\t// Skip disabled options\n\t\t\t\t\t\t\tif (singleOption.disabled) {\n\t\t\t\t\t\t\t\treturn option;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// Check if already selected\n\t\t\t\t\t\t\tif (singleOption.selected) {\n\t\t\t\t\t\t\t\treturn option;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// Check search filter\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tsearchedString &&\n\t\t\t\t\t\t\t\t!singleOption.label\n\t\t\t\t\t\t\t\t\t?.toLowerCase()\n\t\t\t\t\t\t\t\t\t.includes(searchedString.toLowerCase())\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\treturn option;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// Select if we have remaining slots\n\t\t\t\t\t\t\tif (selectedCount < remainingSlots) {\n\t\t\t\t\t\t\t\tselectedCount++;\n\t\t\t\t\t\t\t\treturn { ...option, selected: true };\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn option;\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\n\t\t\t\t\tsetDropdownOptions([...newOptions]);\n\t\t\t\t\tif (version === '2.0') {\n\t\t\t\t\t\tonMultiSelectApply(newOptions);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// No max selection limit, select all\n\t\t\t\t\tconst newOptions = iterateOnOptions(\n\t\t\t\t\t\tdropdownOptions,\n\t\t\t\t\t\t{ selected: true },\n\t\t\t\t\t\t(option) =>\n\t\t\t\t\t\t\tsearchedString\n\t\t\t\t\t\t\t\t? option.label\n\t\t\t\t\t\t\t\t\t\t?.toLowerCase()\n\t\t\t\t\t\t\t\t\t\t.includes(searchedString.toLowerCase()) && !option.disabled\n\t\t\t\t\t\t\t\t: !option.disabled,\n\t\t\t\t\t\tnestedChildren,\n\t\t\t\t\t);\n\t\t\t\t\tsetDropdownOptions([...newOptions]);\n\t\t\t\t\tif (version === '2.0') {\n\t\t\t\t\t\tonMultiSelectApply(newOptions);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if (newState === 'notSelected') {\n\t\t\t\tconst newOptions = iterateOnOptions(\n\t\t\t\t\tdropdownOptions,\n\t\t\t\t\t{ selected: false },\n\t\t\t\t\t(option) => !option.disabled,\n\t\t\t\t\tnestedChildren,\n\t\t\t\t);\n\t\t\t\tsetDropdownOptions([...newOptions]);\n\t\t\t\tif (version === '2.0') {\n\t\t\t\t\tonMultiSelectApply(newOptions);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction onMultiSelectClear() {\n\t\tconst newOptions = iterateOnOptions(\n\t\t\tdropdownOptions,\n\t\t\t{ selected: false },\n\t\t\tundefined,\n\t\t\tnestedChildren,\n\t\t);\n\t\tsetDropdownOptions([...newOptions]);\n\t\tif (version === '2.0') {\n\t\t\tonMultiSelectApply(newOptions);\n\t\t}\n\t}\n\n\tfunction onFreeFormSelect(selected: boolean) {\n\t\tif (!isMultiSelect) {\n\t\t\tonApplyHandler({\n\t\t\t\tlabel: searchedString,\n\t\t\t\tvalue: searchedString,\n\t\t\t\tisFreeForm: true,\n\t\t\t\tselected: true,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tconst updatedList = dropdownOptions.map((option) =>\n\t\t\t(option as GroupedOption).options\n\t\t\t\t? option\n\t\t\t\t: {\n\t\t\t\t\t\t...option,\n\t\t\t\t\t\tselected:\n\t\t\t\t\t\t\t/** free form check */\n\t\t\t\t\t\t\toption.label === searchedString &&\n\t\t\t\t\t\t\t(option as SingleOption).value === searchedString\n\t\t\t\t\t\t\t\t? /** to mark as selected or not */\n\t\t\t\t\t\t\t\t selected\n\t\t\t\t\t\t\t\t: (option as SingleOption).selected,\n\t\t\t\t },\n\t\t);\n\n\t\tif (selected) {\n\t\t\tif (\n\t\t\t\t!updatedList.some(\n\t\t\t\t\t(option) =>\n\t\t\t\t\t\toption.label === searchedString &&\n\t\t\t\t\t\t(option as SingleOption).value === searchedString,\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tupdatedList.unshift({\n\t\t\t\t\tlabel: searchedString,\n\t\t\t\t\tvalue: searchedString,\n\t\t\t\t\tisFreeForm: true,\n\t\t\t\t\tselected: true,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tsetDropdownOptions([...updatedList]);\n\t\tif (version === '2.0') {\n\t\t\tonMultiSelectApply(updatedList);\n\t\t}\n\t}\n\n\t/**\n\t * This is called when appy button is called,\n\t * here iterate and pick all options where selected if true.\n\t */\n\tfunction onMultiSelectApply(options?: DropdownOption[]) {\n\t\tconst optionsToSend: DropdownOption[] = getSelectedOptions(\n\t\t\toptions ?? latestDropdownOptionsRef.current,\n\t\t);\n\n\t\tonSelect?.([...optionsToSend]);\n\t}\n\n\treturn {\n\t\tlatestDropdownOptionsRef,\n\t\tdropdownOptions,\n\t\tsearch,\n\t\tsearchedString,\n\t\tsearchedOptions,\n\t\tsearchError,\n\t\tretrySearch,\n\t\tonApplyHandler,\n\t\tselectAllHandler,\n\t\tonMultiSelectClear,\n\t\tonFreeFormSelect,\n\t\tonMultiSelectApply,\n\t\tgetSelectedOptions,\n\t\tgetCurrentSelectionCount,\n\t\tisMaxSelectionsReached,\n\t\tmaxSelections,\n\t};\n};\n"],"names":["useDropdown","version","options","onSelect","skipSorting","isMultiSelect","onSearch","disableOtherSearchedOption","disableSearchedOptionExcept","maxSelections","childrenLayout","nestedChildren","dropdownOptions","setDropdownOptions","useState","searchedOptions","setSearchedOptions","searchedString","setSearchedString","searchError","setSearchError","latestDropdownOptionsRef","useRef","onSearchRef","useEffect","searchedOptionsClone","dropdownOptionFlat","option","op","selectedDropdownOption","dropdownOption","writeOptions","getSelectedOptions","data","selectedOptions","groupedOptions","singleOption","selectedChildren","child","getCurrentSelectionCount","getSelectionLeaves","leaf","isMaxSelectionsReached","performSearch","useCallback","searchKey","onSearchFn","selectedIds","iterateOnOptionsRaw","response","updatedResponseData","groupedOption","error","debouncedSearch","useMemo","debounce","search","retrySearch","onApplyHandler","optionSelect","returnOnly","alreadyPresentInInitialOptions","currList","iterateOnOptions","optionForValidation","onMultiSelectApply","selectAllForSearch","select","clonedDropdownOptions","dOption","selectAllForSearchWithLimit","currentCount","remainingSlots","selectedCount","found","selectAllHandler","newState","newOptions","onMultiSelectClear","onFreeFormSelect","selected","updatedList","optionsToSend"],"mappings":";;;AAUO,MAAMA,KAAc,CAC1BC,IAAU,OACVC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,IAAwC,CAAA,GACxCC,GACAC,MACI;AAGJ,QAAMC,IAAiBD,MAAmB,UACpC,CAACE,GAAiBC,CAAkB,IAAIC,EAASZ,KAAW,CAAA,CAAE,GAC9D,CAACa,GAAiBC,CAAkB,IAAIF,EAA2B,CAAA,CAAE,GACrE,CAACG,GAAgBC,CAAiB,IAAIJ,EAAS,EAAE,GACjD,CAACK,GAAaC,CAAc,IAAIN,EAA6B,MAAS,GACtEO,IAA2BC,EAAOV,CAAe,GAEjDW,IAAcD,EAAOhB,CAAQ;AAEnC,EAAAkB,EAAU,MAAM;AACf,IAAAD,EAAY,UAAUjB;AAAA,EACvB,GAAG,CAACA,CAAQ,CAAC,GAEbkB,EAAU,MAAM;AAGf,QAFAH,EAAyB,UAAUT,GAE/BG,EAAgB,UAAUE,KAAkBX,GAAU;AACzD,UAAImB,IAAuB,CAAC,GAAGV,CAAe;AAC9C,YAAMW,IAAqBd,EACzB,IAAI,CAACe,MAAW;AAChB,YAAKA,EAAyB;AAC7B,iBAAQA,EAAyB,QAAQ,IAAI,CAACC,OAAQ;AAAA,YACrD,OAAOA,EAAG;AAAA,YACV,UAAUA,EAAG;AAAA,UAAA,EACZ;AAEH,cAAMA,IAAKD;AACX,eAAO;AAAA,UACN,OAAOC,EAAG;AAAA,UACV,UAAUA,EAAG;AAAA,QAAA;AAAA,MAEf,CAAC,EACA,KAAA;AA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I;AAAA,IACA,aAAAsC;AAAA,IACA,gBAAAC;AAAA,IACA,kBAAAiB;AAAA,IACA,oBAAAG;AAAA,IACA,kBAAAC;AAAA,IACA,oBAAAd;AAAA,IACA,oBAAAjC;AAAA,IACA,0BAAAO;AAAA,IACA,wBAAAG;AAAA,IACA,eAAAjC;AAAA,EAAA;AAEF;"}
|
|
1
|
+
{"version":3,"file":"useDropdown.js","sources":["../../../../../src/components/dropdown/hooks/useDropdown.tsx"],"sourcesContent":["import debounce from 'lodash/debounce';\nimport { useCallback, useEffect, useMemo, useRef, useState } from 'react';\nimport { SelectAllCheckboxState } from '../OpenedDropdown/components/menu/SelectAllMenu';\nimport {\n\titerateOnOptions,\n\titerateOnOptionsRaw,\n} from '../OpenedDropdown/utils/iterationOnOptions';\nimport { DropdownOption, GroupedOption, SingleOption } from '../type';\n\nexport const useDropdown = (\n\tversion = '1.0',\n\toptions: DropdownOption[],\n\tonSelect: ((option: DropdownOption | DropdownOption[]) => void) | undefined,\n\tskipSorting?: boolean,\n\tisMultiSelect?: boolean,\n\tonSearch?: (searchKey: string) => Promise<DropdownOption[]>,\n\tdisableOtherSearchedOption?: boolean,\n\tdisableSearchedOptionExcept: string[] = [],\n\tmaxSelections?: number,\n) => {\n\tconst [dropdownOptions, setDropdownOptions] = useState(options ?? []);\n\tconst [searchedOptions, setSearchedOptions] = useState<DropdownOption[]>([]);\n\tconst [searchedString, setSearchedString] = useState('');\n\tconst [searchError, setSearchError] = useState<string | undefined>(undefined);\n\tconst latestDropdownOptionsRef = useRef(dropdownOptions);\n\t/** Store latest onSearch so performSearch/debouncedSearch stay stable when parent re-renders with new callback reference. */\n\tconst onSearchRef = useRef(onSearch);\n\n\tuseEffect(() => {\n\t\tonSearchRef.current = onSearch;\n\t}, [onSearch]);\n\n\tuseEffect(() => {\n\t\tlatestDropdownOptionsRef.current = dropdownOptions;\n\n\t\tif (searchedOptions.length && searchedString && onSearch) {\n\t\t\tlet searchedOptionsClone = [...searchedOptions] as SingleOption[];\n\t\t\tconst dropdownOptionFlat = dropdownOptions\n\t\t\t\t.map((option) => {\n\t\t\t\t\tif ((option as GroupedOption).options) {\n\t\t\t\t\t\treturn (option as GroupedOption).options.map((op) => ({\n\t\t\t\t\t\t\tvalue: op.value,\n\t\t\t\t\t\t\tselected: op.selected,\n\t\t\t\t\t\t}));\n\t\t\t\t\t}\n\t\t\t\t\tconst op = option as SingleOption;\n\t\t\t\t\treturn {\n\t\t\t\t\t\tvalue: op.value,\n\t\t\t\t\t\tselected: op.selected,\n\t\t\t\t\t};\n\t\t\t\t})\n\t\t\t\t.flat();\n\n\t\t\tsearchedOptionsClone = searchedOptionsClone.map((option) => {\n\t\t\t\tconst selectedDropdownOption = dropdownOptionFlat.find(\n\t\t\t\t\t(dropdownOption) => {\n\t\t\t\t\t\tif (option.value === dropdownOption.value) {\n\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t}\n\t\t\t\t\t\treturn false;\n\t\t\t\t\t},\n\t\t\t\t);\n\n\t\t\t\tif (selectedDropdownOption) {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...option,\n\t\t\t\t\t\tselected: selectedDropdownOption.selected,\n\t\t\t\t\t};\n\t\t\t\t}\n\n\t\t\t\treturn option;\n\t\t\t});\n\n\t\t\t// disable other options except selected in searched options\n\t\t\tif (disableOtherSearchedOption) {\n\t\t\t\tsearchedOptionsClone = searchedOptionsClone.map((option) => {\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...option,\n\t\t\t\t\t\tdisabled: !disableSearchedOptionExcept.includes(option.value),\n\t\t\t\t\t};\n\t\t\t\t});\n\t\t\t}\n\n\t\t\tif (isMultiSelect && !skipSorting) {\n\t\t\t\tsetSearchedOptions([\n\t\t\t\t\t...searchedOptionsClone.sort((option) =>\n\t\t\t\t\t\t(option as SingleOption).selected ? -1 : 1,\n\t\t\t\t\t),\n\t\t\t\t]);\n\t\t\t} else {\n\t\t\t\tsetSearchedOptions([...searchedOptionsClone]);\n\t\t\t}\n\t\t}\n\t}, [dropdownOptions]);\n\n\tuseEffect(() => {\n\t\tif (options) {\n\t\t\tconst writeOptions = [...options];\n\t\t\tif (isMultiSelect && !skipSorting) {\n\t\t\t\tsetDropdownOptions([\n\t\t\t\t\t...writeOptions.sort((option) =>\n\t\t\t\t\t\t(option as SingleOption).selected ? -1 : 1,\n\t\t\t\t\t),\n\t\t\t\t]);\n\t\t\t} else {\n\t\t\t\tsetDropdownOptions([...writeOptions]);\n\t\t\t}\n\t\t}\n\t}, [options]);\n\n\tconst getSelectedOptions = (data: DropdownOption[]) => {\n\t\tconst selectedOptions: DropdownOption[] = [];\n\t\tdata.forEach((option) => {\n\t\t\tif ((option as GroupedOption).options) {\n\t\t\t\tconst groupedOptions = (option as GroupedOption).options.filter(\n\t\t\t\t\t(op) => op.selected === true,\n\t\t\t\t);\n\t\t\t\tselectedOptions.push({\n\t\t\t\t\t...option,\n\t\t\t\t\toptions: [...groupedOptions],\n\t\t\t\t});\n\t\t\t} else {\n\t\t\t\tif ((option as SingleOption).selected) {\n\t\t\t\t\tselectedOptions.push({ ...option });\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\treturn selectedOptions;\n\t};\n\n\t// Count current selections for max selection limit\n\tconst getCurrentSelectionCount = (data: DropdownOption[]) => {\n\t\tlet count = 0;\n\t\tdata.forEach((option) => {\n\t\t\tif ((option as GroupedOption).options) {\n\t\t\t\tcount += (option as GroupedOption).options.filter(\n\t\t\t\t\t(op) => op.selected === true,\n\t\t\t\t).length;\n\t\t\t} else {\n\t\t\t\tif ((option as SingleOption).selected) {\n\t\t\t\t\tcount++;\n\t\t\t\t}\n\t\t\t}\n\t\t});\n\t\treturn count;\n\t};\n\n\t// Check if max selections limit is reached\n\tconst isMaxSelectionsReached = (data: DropdownOption[]) => {\n\t\tif (!isMultiSelect || (!maxSelections && maxSelections !== 0)) return false;\n\t\treturn getCurrentSelectionCount(data) >= maxSelections;\n\t};\n\n\t/** Reads onSearch from ref so it stays stable ([] deps). No-ops when onSearchRef.current is undefined. */\n\tconst performSearch = useCallback(async (searchKey: string) => {\n\t\tconst onSearchFn = onSearchRef.current;\n\t\tif (!searchKey || !onSearchFn) return;\n\n\t\tconst selectedIds: (string | number)[] = [];\n\t\titerateOnOptionsRaw(latestDropdownOptionsRef.current, (option) => {\n\t\t\tif (option.selected && !selectedIds.includes(option.value)) {\n\t\t\t\tselectedIds.push(option.value);\n\t\t\t}\n\t\t});\n\n\t\ttry {\n\t\t\tconst response = await onSearchFn(searchKey);\n\t\t\tsetSearchError(undefined);\n\t\t\tif (response) {\n\t\t\t\tconst updatedResponseData = response.map((option) => {\n\t\t\t\t\tif ((option as GroupedOption).options) {\n\t\t\t\t\t\tconst groupedOption = option as GroupedOption;\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...groupedOption,\n\t\t\t\t\t\t\toptions: groupedOption.options.map((op) => ({\n\t\t\t\t\t\t\t\t...op,\n\t\t\t\t\t\t\t\tselected: selectedIds.includes(op.value),\n\t\t\t\t\t\t\t})),\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\n\t\t\t\t\treturn {\n\t\t\t\t\t\t...option,\n\t\t\t\t\t\tselected: selectedIds.includes((option as SingleOption).value),\n\t\t\t\t\t};\n\t\t\t\t});\n\n\t\t\t\tsetSearchedOptions([...updatedResponseData]);\n\t\t\t} else {\n\t\t\t\tsetSearchedOptions([]);\n\t\t\t}\n\t\t} catch (error) {\n\t\t\tsetSearchedOptions([]);\n\t\t\tsetSearchError(\n\t\t\t\terror instanceof Error\n\t\t\t\t\t? error.message\n\t\t\t\t\t: 'Something went wrong while fetching the list. Please try again',\n\t\t\t);\n\t\t}\n\t}, []);\n\n\t/** Independent of onSearch so debounce is stable when callers pass inline functions. Pending searches are preserved across parent re-renders. performSearch no-ops when onSearchRef.current is undefined. */\n\tconst debouncedSearch = useMemo(\n\t\t() => debounce(performSearch, 300),\n\t\t[performSearch],\n\t);\n\n\tuseEffect(() => () => debouncedSearch?.cancel(), [debouncedSearch]);\n\n\tfunction search(searchKey: string) {\n\t\tsetSearchedString(searchKey);\n\t\tsetSearchedOptions([]);\n\t\tsetSearchError(undefined);\n\n\t\tif (!searchKey) {\n\t\t\tdebouncedSearch?.cancel();\n\t\t\treturn;\n\t\t}\n\n\t\tdebouncedSearch(searchKey);\n\t}\n\n\tfunction retrySearch() {\n\t\tif (searchedString) {\n\t\t\tsetSearchError(undefined);\n\t\t\tperformSearch(searchedString);\n\t\t}\n\t}\n\n\t/**\n\t * wrapper to prepare option for onSelect\n\t * for single select, this will call the onClose handler ,\n\t * for multiselect, it will do state update for options list\n\t * \t\tto make any option select,\n\t * \t\t\t\tonApplyHandler({ label, value: selected: true })\n\t * to deselect any option\n\t * \t\t\t\tonApplyHandler({ label, value: selected: false })\n\t * @param optionSelect\n\t */\n\tfunction onApplyHandler(optionSelect: SingleOption, returnOnly?: boolean) {\n\t\tif (!isMultiSelect) {\n\t\t\tonSelect?.(optionSelect);\n\t\t} else {\n\t\t\t// Check if trying to select and max selections is reached\n\t\t\tif (\n\t\t\t\toptionSelect.selected &&\n\t\t\t\tmaxSelections &&\n\t\t\t\tisMaxSelectionsReached(dropdownOptions)\n\t\t\t) {\n\t\t\t\t// Max selections reached, don't allow new selections\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tif (searchedOptions.length && searchedString && onSearch) {\n\t\t\t\t/** Search mode */\n\t\t\t\t/**\n\t\t\t\t * on selected, push it to dropdown options,\n\t\t\t\t * on un-select, remove from dropdown option\n\t\t\t\t */\n\n\t\t\t\tif (optionSelect.selected) {\n\t\t\t\t\t// Check max selections for search mode too\n\t\t\t\t\tif (maxSelections && isMaxSelectionsReached(dropdownOptions)) {\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\t/** check if already there or not,\n\t\t\t\t\t * if yes, just update\n\t\t\t\t\t * else ,\n\t\t\t\t\t * \tappend\n\t\t\t\t\t */\n\n\t\t\t\t\tlet alreadyPresentInInitialOptions = false;\n\t\t\t\t\tconst currList = iterateOnOptions(\n\t\t\t\t\t\tdropdownOptions,\n\t\t\t\t\t\t{ selected: optionSelect.selected } as Partial<SingleOption>,\n\t\t\t\t\t\t(optionForValidation: SingleOption) => {\n\t\t\t\t\t\t\tif (optionForValidation.value === optionSelect.value) {\n\t\t\t\t\t\t\t\talreadyPresentInInitialOptions = true;\n\t\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\n\t\t\t\t\tif (!alreadyPresentInInitialOptions) {\n\t\t\t\t\t\tcurrList.push(optionSelect);\n\t\t\t\t\t}\n\n\t\t\t\t\tif (returnOnly) {\n\t\t\t\t\t\treturn [...currList];\n\t\t\t\t\t}\n\t\t\t\t\tsetDropdownOptions([...currList]);\n\t\t\t\t\tif (version === '2.0') {\n\t\t\t\t\t\tonMultiSelectApply(currList);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t/** un-select,\n\t\t\t\t\t * if already present in initial data,\n\t\t\t\t\t * yes, just update\n\t\t\t\t\t * else,\n\t\t\t\t\t * \tremove\n\t\t\t\t\t */\n\n\t\t\t\t\tlet alreadyPresentInInitialOptions = false;\n\t\t\t\t\tlet currList = iterateOnOptions(\n\t\t\t\t\t\tdropdownOptions,\n\t\t\t\t\t\t{ selected: optionSelect.selected } as Partial<SingleOption>,\n\t\t\t\t\t\t(optionForValidation: SingleOption) => {\n\t\t\t\t\t\t\tif (optionForValidation.value === optionSelect.value) {\n\t\t\t\t\t\t\t\talreadyPresentInInitialOptions = true;\n\t\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t},\n\t\t\t\t\t);\n\n\t\t\t\t\tif (alreadyPresentInInitialOptions) {\n\t\t\t\t\t\tcurrList = currList.filter((option) => {\n\t\t\t\t\t\t\tif (option.value === optionSelect.value) {\n\t\t\t\t\t\t\t\treturn false;\n\t\t\t\t\t\t\t}\n\n\t\t\t\t\t\t\treturn true;\n\t\t\t\t\t\t});\n\t\t\t\t\t}\n\n\t\t\t\t\tif (returnOnly) {\n\t\t\t\t\t\treturn [...currList];\n\t\t\t\t\t}\n\t\t\t\t\tsetDropdownOptions([...currList]);\n\t\t\t\t\tif (version === '2.0') {\n\t\t\t\t\t\tonMultiSelectApply(currList);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else {\n\t\t\t\tconst currList = iterateOnOptions(\n\t\t\t\t\tdropdownOptions,\n\t\t\t\t\t{ selected: optionSelect.selected } as Partial<SingleOption>,\n\t\t\t\t\t(optionForValidation: SingleOption) =>\n\t\t\t\t\t\toptionForValidation.value === optionSelect.value,\n\t\t\t\t);\n\n\t\t\t\tif (returnOnly) {\n\t\t\t\t\treturn [...currList];\n\t\t\t\t}\n\t\t\t\tsetDropdownOptions([...currList]);\n\t\t\t\tif (version === '2.0') {\n\t\t\t\t\tonMultiSelectApply(currList);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction selectAllForSearch(select: boolean) {\n\t\t// const allSearchedValues = searchedOptions.map(option => option.value);\n\t\tlet clonedDropdownOptions = [...dropdownOptions];\n\n\t\tif (select) {\n\t\t\tsearchedOptions.forEach((option) => {\n\t\t\t\tlet found = false;\n\t\t\t\tclonedDropdownOptions = clonedDropdownOptions.map((dOption) => {\n\t\t\t\t\tconst singleOption = option as SingleOption;\n\t\t\t\t\tif (\n\t\t\t\t\t\ttypeof singleOption.value !== 'undefined' &&\n\t\t\t\t\t\tsingleOption.value === (dOption as SingleOption).value\n\t\t\t\t\t) {\n\t\t\t\t\t\tfound = true;\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...dOption,\n\t\t\t\t\t\t\tselected: true,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\treturn dOption;\n\t\t\t\t});\n\n\t\t\t\tif (!found) {\n\t\t\t\t\tclonedDropdownOptions.push({ ...option, selected: true });\n\t\t\t\t}\n\t\t\t});\n\t\t} else {\n\t\t\tsearchedOptions.forEach((option) => {\n\t\t\t\tclonedDropdownOptions = clonedDropdownOptions.map((dOption) => {\n\t\t\t\t\tconst singleOption = option as SingleOption;\n\t\t\t\t\tif (\n\t\t\t\t\t\ttypeof singleOption.value !== 'undefined' &&\n\t\t\t\t\t\tsingleOption.value === (dOption as SingleOption).value\n\t\t\t\t\t) {\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...dOption,\n\t\t\t\t\t\t\tselected: false,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\treturn dOption;\n\t\t\t\t});\n\t\t\t});\n\t\t}\n\n\t\tsetDropdownOptions([...clonedDropdownOptions]);\n\t\tif (version === '2.0') {\n\t\t\tonMultiSelectApply(clonedDropdownOptions);\n\t\t}\n\t}\n\n\tfunction selectAllForSearchWithLimit(select: boolean) {\n\t\tlet clonedDropdownOptions = [...dropdownOptions];\n\n\t\tif (select && maxSelections && maxSelections > 0) {\n\t\t\tconst currentCount = getCurrentSelectionCount(clonedDropdownOptions);\n\t\t\tconst remainingSlots = maxSelections - currentCount;\n\n\t\t\tif (remainingSlots <= 0) {\n\t\t\t\t// Already at max, don't select any more\n\t\t\t\treturn;\n\t\t\t}\n\n\t\t\tlet selectedCount = 0;\n\t\t\tsearchedOptions.forEach((option) => {\n\t\t\t\tif (selectedCount >= remainingSlots) {\n\t\t\t\t\treturn;\n\t\t\t\t}\n\n\t\t\t\tlet found = false;\n\t\t\t\tclonedDropdownOptions = clonedDropdownOptions.map((dOption) => {\n\t\t\t\t\tconst singleOption = option as SingleOption;\n\t\t\t\t\t// Skip if already selected\n\t\t\t\t\tif ((dOption as SingleOption).selected) {\n\t\t\t\t\t\treturn dOption;\n\t\t\t\t\t}\n\t\t\t\t\t// Skip if disabled\n\t\t\t\t\tif ((dOption as SingleOption).disabled) {\n\t\t\t\t\t\treturn dOption;\n\t\t\t\t\t}\n\n\t\t\t\t\tif (\n\t\t\t\t\t\ttypeof singleOption.value !== 'undefined' &&\n\t\t\t\t\t\tsingleOption.value === (dOption as SingleOption).value\n\t\t\t\t\t) {\n\t\t\t\t\t\tfound = true;\n\t\t\t\t\t\tselectedCount++;\n\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t...dOption,\n\t\t\t\t\t\t\tselected: true,\n\t\t\t\t\t\t};\n\t\t\t\t\t}\n\t\t\t\t\treturn dOption;\n\t\t\t\t});\n\n\t\t\t\tif (!found && selectedCount < remainingSlots) {\n\t\t\t\t\tconst newOption = option as SingleOption;\n\t\t\t\t\tif (!newOption.disabled) {\n\t\t\t\t\t\tclonedDropdownOptions.push({ ...option, selected: true });\n\t\t\t\t\t\tselectedCount++;\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t});\n\n\t\t\tsetDropdownOptions([...clonedDropdownOptions]);\n\t\t\tif (version === '2.0') {\n\t\t\t\tonMultiSelectApply(clonedDropdownOptions);\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction selectAllHandler(newState: SelectAllCheckboxState) {\n\t\tif (searchedOptions.length && searchedString && onSearch) {\n\t\t\tif (newState === 'selectAll') {\n\t\t\t\tselectAllForSearchWithLimit(true);\n\t\t\t} else {\n\t\t\t\tselectAllForSearch(false);\n\t\t\t}\n\t\t} else {\n\t\t\tif (newState === 'selectAll') {\n\t\t\t\tif (maxSelections && maxSelections > 0) {\n\t\t\t\t\t// Only select up to maxSelections limit\n\t\t\t\t\tconst currentCount = getCurrentSelectionCount(dropdownOptions);\n\t\t\t\t\tconst remainingSlots = maxSelections - currentCount;\n\n\t\t\t\t\tif (remainingSlots <= 0) {\n\t\t\t\t\t\t// Already at max, don't select any more\n\t\t\t\t\t\treturn;\n\t\t\t\t\t}\n\n\t\t\t\t\tlet selectedCount = 0;\n\t\t\t\t\tconst newOptions = dropdownOptions.map((option) => {\n\t\t\t\t\t\tif ((option as GroupedOption).options) {\n\t\t\t\t\t\t\t// Handle grouped options\n\t\t\t\t\t\t\tconst groupedOption = option as GroupedOption;\n\t\t\t\t\t\t\treturn {\n\t\t\t\t\t\t\t\t...groupedOption,\n\t\t\t\t\t\t\t\toptions: groupedOption.options.map((op) => {\n\t\t\t\t\t\t\t\t\t// Skip disabled options\n\t\t\t\t\t\t\t\t\tif (op.disabled) {\n\t\t\t\t\t\t\t\t\t\treturn op;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t// Check if already selected\n\t\t\t\t\t\t\t\t\tif (op.selected) {\n\t\t\t\t\t\t\t\t\t\treturn op;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t// Check search filter\n\t\t\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\t\t\tsearchedString &&\n\t\t\t\t\t\t\t\t\t\t!op.label\n\t\t\t\t\t\t\t\t\t\t\t?.toLowerCase()\n\t\t\t\t\t\t\t\t\t\t\t.includes(searchedString.toLowerCase())\n\t\t\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\t\t\treturn op;\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\t// Select if we have remaining slots\n\t\t\t\t\t\t\t\t\tif (selectedCount < remainingSlots) {\n\t\t\t\t\t\t\t\t\t\tselectedCount++;\n\t\t\t\t\t\t\t\t\t\treturn { ...op, selected: true };\n\t\t\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t\t\treturn op;\n\t\t\t\t\t\t\t\t}),\n\t\t\t\t\t\t\t};\n\t\t\t\t\t\t} else {\n\t\t\t\t\t\t\tconst singleOption = option as SingleOption;\n\t\t\t\t\t\t\t// Skip disabled options\n\t\t\t\t\t\t\tif (singleOption.disabled) {\n\t\t\t\t\t\t\t\treturn option;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// Check if already selected\n\t\t\t\t\t\t\tif (singleOption.selected) {\n\t\t\t\t\t\t\t\treturn option;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// Check search filter\n\t\t\t\t\t\t\tif (\n\t\t\t\t\t\t\t\tsearchedString &&\n\t\t\t\t\t\t\t\t!singleOption.label\n\t\t\t\t\t\t\t\t\t?.toLowerCase()\n\t\t\t\t\t\t\t\t\t.includes(searchedString.toLowerCase())\n\t\t\t\t\t\t\t) {\n\t\t\t\t\t\t\t\treturn option;\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\t// Select if we have remaining slots\n\t\t\t\t\t\t\tif (selectedCount < remainingSlots) {\n\t\t\t\t\t\t\t\tselectedCount++;\n\t\t\t\t\t\t\t\treturn { ...option, selected: true };\n\t\t\t\t\t\t\t}\n\t\t\t\t\t\t\treturn option;\n\t\t\t\t\t\t}\n\t\t\t\t\t});\n\n\t\t\t\t\tsetDropdownOptions([...newOptions]);\n\t\t\t\t\tif (version === '2.0') {\n\t\t\t\t\t\tonMultiSelectApply(newOptions);\n\t\t\t\t\t}\n\t\t\t\t} else {\n\t\t\t\t\t// No max selection limit, select all\n\t\t\t\t\tconst newOptions = iterateOnOptions(\n\t\t\t\t\t\tdropdownOptions,\n\t\t\t\t\t\t{ selected: true },\n\t\t\t\t\t\t(option) =>\n\t\t\t\t\t\t\tsearchedString\n\t\t\t\t\t\t\t\t? option.label\n\t\t\t\t\t\t\t\t\t\t?.toLowerCase()\n\t\t\t\t\t\t\t\t\t\t.includes(searchedString.toLowerCase()) && !option.disabled\n\t\t\t\t\t\t\t\t: !option.disabled,\n\t\t\t\t\t);\n\t\t\t\t\tsetDropdownOptions([...newOptions]);\n\t\t\t\t\tif (version === '2.0') {\n\t\t\t\t\t\tonMultiSelectApply(newOptions);\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t} else if (newState === 'notSelected') {\n\t\t\t\tconst newOptions = iterateOnOptions(\n\t\t\t\t\tdropdownOptions,\n\t\t\t\t\t{ selected: false },\n\t\t\t\t\t(option) => !option.disabled,\n\t\t\t\t);\n\t\t\t\tsetDropdownOptions([...newOptions]);\n\t\t\t\tif (version === '2.0') {\n\t\t\t\t\tonMultiSelectApply(newOptions);\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t}\n\n\tfunction onMultiSelectClear() {\n\t\tconst newOptions = iterateOnOptions(dropdownOptions, { selected: false });\n\t\tsetDropdownOptions([...newOptions]);\n\t\tif (version === '2.0') {\n\t\t\tonMultiSelectApply(newOptions);\n\t\t}\n\t}\n\n\tfunction onFreeFormSelect(selected: boolean) {\n\t\tif (!isMultiSelect) {\n\t\t\tonApplyHandler({\n\t\t\t\tlabel: searchedString,\n\t\t\t\tvalue: searchedString,\n\t\t\t\tisFreeForm: true,\n\t\t\t\tselected: true,\n\t\t\t});\n\t\t\treturn;\n\t\t}\n\n\t\tconst updatedList = dropdownOptions.map((option) =>\n\t\t\t(option as GroupedOption).options\n\t\t\t\t? option\n\t\t\t\t: {\n\t\t\t\t\t\t...option,\n\t\t\t\t\t\tselected:\n\t\t\t\t\t\t\t/** free form check */\n\t\t\t\t\t\t\toption.label === searchedString &&\n\t\t\t\t\t\t\t(option as SingleOption).value === searchedString\n\t\t\t\t\t\t\t\t? /** to mark as selected or not */\n\t\t\t\t\t\t\t\t selected\n\t\t\t\t\t\t\t\t: (option as SingleOption).selected,\n\t\t\t\t },\n\t\t);\n\n\t\tif (selected) {\n\t\t\tif (\n\t\t\t\t!updatedList.some(\n\t\t\t\t\t(option) =>\n\t\t\t\t\t\toption.label === searchedString &&\n\t\t\t\t\t\t(option as SingleOption).value === searchedString,\n\t\t\t\t)\n\t\t\t) {\n\t\t\t\tupdatedList.unshift({\n\t\t\t\t\tlabel: searchedString,\n\t\t\t\t\tvalue: searchedString,\n\t\t\t\t\tisFreeForm: true,\n\t\t\t\t\tselected: true,\n\t\t\t\t});\n\t\t\t}\n\t\t}\n\n\t\tsetDropdownOptions([...updatedList]);\n\t\tif (version === '2.0') {\n\t\t\tonMultiSelectApply(updatedList);\n\t\t}\n\t}\n\n\t/**\n\t * This is called when appy button is called,\n\t * here iterate and pick all options where selected if true.\n\t */\n\tfunction onMultiSelectApply(options?: DropdownOption[]) {\n\t\tconst optionsToSend: DropdownOption[] = getSelectedOptions(\n\t\t\toptions ?? latestDropdownOptionsRef.current,\n\t\t);\n\n\t\tonSelect?.([...optionsToSend]);\n\t}\n\n\treturn {\n\t\tlatestDropdownOptionsRef,\n\t\tdropdownOptions,\n\t\tsearch,\n\t\tsearchedString,\n\t\tsearchedOptions,\n\t\tsearchError,\n\t\tretrySearch,\n\t\tonApplyHandler,\n\t\tselectAllHandler,\n\t\tonMultiSelectClear,\n\t\tonFreeFormSelect,\n\t\tonMultiSelectApply,\n\t\tgetSelectedOptions,\n\t\tgetCurrentSelectionCount,\n\t\tisMaxSelectionsReached,\n\t\tmaxSelections,\n\t};\n};\n"],"names":["useDropdown","version","options","onSelect","skipSorting","isMultiSelect","onSearch","disableOtherSearchedOption","disableSearchedOptionExcept","maxSelections","dropdownOptions","setDropdownOptions","useState","searchedOptions","setSearchedOptions","searchedString","setSearchedString","searchError","setSearchError","latestDropdownOptionsRef","useRef","onSearchRef","useEffect","searchedOptionsClone","dropdownOptionFlat","option","op","selectedDropdownOption","dropdownOption","writeOptions","getSelectedOptions","data","selectedOptions","groupedOptions","getCurrentSelectionCount","count","isMaxSelectionsReached","performSearch","useCallback","searchKey","onSearchFn","selectedIds","iterateOnOptionsRaw","response","updatedResponseData","groupedOption","error","debouncedSearch","useMemo","debounce","search","retrySearch","onApplyHandler","optionSelect","returnOnly","alreadyPresentInInitialOptions","currList","iterateOnOptions","optionForValidation","onMultiSelectApply","selectAllForSearch","select","clonedDropdownOptions","dOption","singleOption","selectAllForSearchWithLimit","currentCount","remainingSlots","selectedCount","found","selectAllHandler","newState","newOptions","onMultiSelectClear","onFreeFormSelect","selected","updatedList","optionsToSend"],"mappings":";;;AASO,MAAMA,IAAc,CAC1BC,IAAU,OACVC,GACAC,GACAC,GACAC,GACAC,GACAC,GACAC,IAAwC,CAAA,GACxCC,MACI;AACJ,QAAM,CAACC,GAAiBC,CAAkB,IAAIC,EAASV,KAAW,CAAA,CA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