@kommo-crm/crm-react-ui-kit 1.3.0-beta.1 → 1.3.0-beta.3

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.
Files changed (48) hide show
  1. package/dist/ContextMenu-CeyT26LX.mjs +229 -0
  2. package/dist/components/ContextMenu/ContextMenu.d.ts +2 -2
  3. package/dist/components/ContextMenu/ContextMenu.d.ts.map +1 -1
  4. package/dist/components/ContextMenu/ContextMenu.js +5 -5
  5. package/dist/components/ContextMenu/ContextMenu.props.d.ts +19 -3
  6. package/dist/components/ContextMenu/ContextMenu.props.d.ts.map +1 -1
  7. package/dist/components/ContextMenu/components/CheckboxItem/CheckboxItem.js +1 -1
  8. package/dist/components/ContextMenu/components/Content/Content.d.ts.map +1 -1
  9. package/dist/components/ContextMenu/components/Content/Content.js +1 -1
  10. package/dist/components/ContextMenu/components/Content/index.js +1 -1
  11. package/dist/components/ContextMenu/components/Item/Item.js +1 -1
  12. package/dist/components/ContextMenu/components/Label/Label.js +1 -1
  13. package/dist/components/ContextMenu/components/RadioItem/RadioItem.js +1 -1
  14. package/dist/components/ContextMenu/components/Sub/Sub.js +1 -1
  15. package/dist/components/ContextMenu/components/Sub/Sub.props.d.ts +3 -3
  16. package/dist/components/ContextMenu/components/Sub/Sub.props.d.ts.map +1 -1
  17. package/dist/components/ContextMenu/components/Sub/hooks/useContextMenuSub/useContextMenuSub.d.ts.map +1 -1
  18. package/dist/components/ContextMenu/components/Sub/hooks/useContextMenuSub/useContextMenuSub.js +80 -88
  19. package/dist/components/ContextMenu/components/Sub/hooks/useContextMenuSub/useContextMenuSub.types.d.ts +2 -2
  20. package/dist/components/ContextMenu/components/Sub/hooks/useContextMenuSub/useContextMenuSub.types.d.ts.map +1 -1
  21. package/dist/components/ContextMenu/components/Sub/index.js +1 -1
  22. package/dist/components/ContextMenu/components/SubContent/SubContent.js +1 -1
  23. package/dist/components/ContextMenu/components/SubRoot/components/Content/Content.js +1 -1
  24. package/dist/components/ContextMenu/components/SubRoot/components/Trigger/Trigger.js +1 -1
  25. package/dist/components/ContextMenu/components/SubRoot/hooks/useContextMenuSubMenu/useContextMenuSubMenu.js +1 -1
  26. package/dist/components/ContextMenu/components/SubTrigger/SubTrigger.js +1 -1
  27. package/dist/components/ContextMenu/hooks/index.js +1 -1
  28. package/dist/components/ContextMenu/hooks/useContentPositioning/useContentPositioning.d.ts.map +1 -1
  29. package/dist/components/ContextMenu/hooks/useContentPositioning/useContentPositioning.js +1 -1
  30. package/dist/components/ContextMenu/hooks/useContextMenu/useContextMenu.d.ts.map +1 -1
  31. package/dist/components/ContextMenu/hooks/useContextMenu/useContextMenu.js +142 -133
  32. package/dist/components/ContextMenu/hooks/useContextMenu/useContextMenu.types.d.ts +14 -2
  33. package/dist/components/ContextMenu/hooks/useContextMenu/useContextMenu.types.d.ts.map +1 -1
  34. package/dist/components/ContextMenu/hooks/useContextMenu/utils/contextMenuBus/contextMenuBus.d.ts +3 -1
  35. package/dist/components/ContextMenu/hooks/useContextMenu/utils/contextMenuBus/contextMenuBus.d.ts.map +1 -1
  36. package/dist/components/ContextMenu/hooks/useContextMenu/utils/contextMenuBus/contextMenuBus.js +16 -10
  37. package/dist/components/ContextMenu/hooks/useContextMenu/utils/contextMenuBus/contextMenuBus.types.d.ts +4 -0
  38. package/dist/components/ContextMenu/hooks/useContextMenu/utils/contextMenuBus/contextMenuBus.types.d.ts.map +1 -1
  39. package/dist/components/ContextMenu/hooks/useContextMenuItemFocus/useContextMenuItemFocus.d.ts.map +1 -1
  40. package/dist/components/ContextMenu/hooks/useContextMenuItemFocus/useContextMenuItemFocus.js +47 -42
  41. package/dist/components/ContextMenu/index.js +1 -1
  42. package/dist/components/List/List.js +1 -1
  43. package/dist/components/Select/components/List/List.js +1 -1
  44. package/dist/index-DBS3EIVR.mjs +273 -0
  45. package/dist/{useContentPositioning-DfyirIME.mjs → useContentPositioning-Dfjbylz5.mjs} +456 -451
  46. package/package.json +3 -3
  47. package/dist/ContextMenu-BUiakpJf.mjs +0 -223
  48. package/dist/index-BH2CXQ4d.mjs +0 -257
@@ -0,0 +1,273 @@
1
+ import { useState as L, useEffect as R, useCallback as D, useRef as T } from "react";
2
+ var k = "ArrowUp", p = "ArrowDown", B = "Escape", P = "Enter", O = "Space", _ = [k, p, P, O], Q = (e) => {
3
+ const {
4
+ itemsLength: t,
5
+ onSelect: n,
6
+ onToggle: r,
7
+ onHoveredIndexChange: c = () => {
8
+ },
9
+ isOpened: o = !1,
10
+ hoveredIndex: s = 0,
11
+ listRef: l
12
+ } = e, [u, f] = L(s);
13
+ R(() => {
14
+ f(s);
15
+ }, [s]);
16
+ const y = (m) => {
17
+ f(m), c(m);
18
+ }, d = D((m) => {
19
+ if (!l || !l.current)
20
+ return;
21
+ const a = l.current, h = a.querySelector(
22
+ `li:nth-child(${m + 1})`
23
+ );
24
+ if (!h)
25
+ return;
26
+ const x = a.getBoundingClientRect().top, i = h.getBoundingClientRect().top, v = a.scrollTop + (i - x) - a.offsetHeight / 2 + h.offsetHeight / 2;
27
+ a.scrollTop = v, y(m);
28
+ }, []), g = D(
29
+ (m) => {
30
+ switch (_.includes(m.code) && m.preventDefault(), m.code) {
31
+ case B:
32
+ o && r(!1);
33
+ break;
34
+ case k:
35
+ o && d(
36
+ u > 0 ? u - 1 : t - 1
37
+ );
38
+ break;
39
+ case p:
40
+ o && d(
41
+ u < t - 1 ? u + 1 : 0
42
+ );
43
+ break;
44
+ case P:
45
+ case O:
46
+ o && u >= 0 && u < t ? n(u) : r(!0);
47
+ break;
48
+ }
49
+ },
50
+ [u, o, t, n, r]
51
+ );
52
+ return R(() => {
53
+ o && (y(u), d(u));
54
+ }, [o]), {
55
+ currentHoveredIndex: u,
56
+ updateHoveredIndex: y,
57
+ updateListPosition: d,
58
+ onKeyDown: g
59
+ };
60
+ }, H = (e, t) => e.filter((n) => n !== t), A = {}, K = (e) => {
61
+ for (const t in A) {
62
+ const n = A[t];
63
+ for (let r = n.length - 1; r > -1; r--) {
64
+ const { ref: c, handler: o } = n[r], s = c.current;
65
+ if (s) {
66
+ if (s.contains(e.target))
67
+ break;
68
+ o(e);
69
+ break;
70
+ }
71
+ }
72
+ }
73
+ };
74
+ document.addEventListener("click", K);
75
+ var Z = (e) => {
76
+ const { handler: t, ref: n, context: r = "global" } = e;
77
+ R(() => {
78
+ A[r] || (A[r] = []);
79
+ const c = { handler: t, ref: n };
80
+ return setTimeout(() => {
81
+ var o;
82
+ (o = A[r]) == null || o.push(c);
83
+ }), () => {
84
+ A[r] = H(A[r], c);
85
+ };
86
+ }, [t, n, r]);
87
+ }, ee = () => {
88
+ const [e, t] = L(() => typeof window > "u" ? !1 : "ontouchstart" in window || navigator.maxTouchPoints > 0);
89
+ return R(() => {
90
+ const n = (r) => {
91
+ r.pointerType === "touch" ? t(!0) : r.pointerType === "mouse" && t(!1);
92
+ };
93
+ return window.addEventListener("pointerdown", n), () => {
94
+ window.removeEventListener("pointerdown", n);
95
+ };
96
+ }, []), e;
97
+ }, N = 20, X = 500, I = (e, t, n) => (t.x - e.x) * (n.y - e.y) - (t.y - e.y) * (n.x - e.x), F = (e, t, n, r) => {
98
+ const c = I(e, t, n), o = I(e, n, r), s = I(e, r, t), l = c < 0 || o < 0 || s < 0, u = c > 0 || o > 0 || s > 0;
99
+ return !(l && u);
100
+ }, U = (e, t, n) => Math.abs(I(e, t, n)) / 2, q = (e) => {
101
+ const t = e.getBoundingClientRect(), n = window.scrollX, r = window.scrollY;
102
+ return [
103
+ {
104
+ x: t.left + n,
105
+ y: t.top + r
106
+ },
107
+ {
108
+ x: t.right + n,
109
+ y: t.top + r
110
+ },
111
+ {
112
+ x: t.right + n,
113
+ y: t.bottom + r
114
+ },
115
+ {
116
+ x: t.left + n,
117
+ y: t.bottom + r
118
+ }
119
+ ];
120
+ }, j = (e) => {
121
+ if (e.length < 3)
122
+ return 0;
123
+ let t = 0;
124
+ for (let n = 0; n < e.length; n++) {
125
+ const r = (n + 1) % e.length;
126
+ t += e[n].x * e[r].y, t -= e[r].x * e[n].y;
127
+ }
128
+ return Math.abs(t) / 2;
129
+ }, V = (e, t, n, r) => {
130
+ const c = (r.y - n.y) * (t.x - e.x) - (r.x - n.x) * (t.y - e.y);
131
+ if (Math.abs(c) < 1e-10)
132
+ return null;
133
+ const o = ((r.x - n.x) * (e.y - n.y) - (r.y - n.y) * (e.x - n.x)) / c, s = ((t.x - e.x) * (e.y - n.y) - (t.y - e.y) * (e.x - n.x)) / c;
134
+ return o < 0 || o > 1 || s < 0 || s > 1 ? null : {
135
+ x: e.x + o * (t.x - e.x),
136
+ y: e.y + o * (t.y - e.y)
137
+ };
138
+ }, S = (e, t) => {
139
+ const [n, r, c, o] = t, s = Math.min(n.x, o.x), l = Math.max(r.x, c.x), u = Math.min(n.y, r.y), f = Math.max(o.y, c.y);
140
+ return e.x >= s && e.x <= l && e.y >= u && e.y <= f;
141
+ }, W = (e, t) => {
142
+ const [n, r, c] = e, [o, s, l, u] = t, f = [];
143
+ for (const a of [n, r, c])
144
+ S(a, t) && f.push(a);
145
+ const y = [
146
+ [o, s],
147
+ [s, l],
148
+ [l, u],
149
+ [u, o]
150
+ ], d = [
151
+ [n, r],
152
+ [r, c],
153
+ [c, n]
154
+ ];
155
+ for (const a of d)
156
+ for (const h of y) {
157
+ const x = V(
158
+ a[0],
159
+ a[1],
160
+ h[0],
161
+ h[1]
162
+ );
163
+ x && f.push(x);
164
+ }
165
+ const g = [];
166
+ for (const a of f)
167
+ g.some(
168
+ (x) => Math.abs(x.x - a.x) < 1e-6 && Math.abs(x.y - a.y) < 1e-6
169
+ ) || g.push(a);
170
+ if (g.length < 3)
171
+ return [];
172
+ const m = {
173
+ x: g.reduce(function(h, x) {
174
+ return h + x.x;
175
+ }, 0) / g.length,
176
+ y: g.reduce(function(h, x) {
177
+ return h + x.y;
178
+ }, 0) / g.length
179
+ };
180
+ return g.sort(function(h, x) {
181
+ const i = Math.atan2(h.y - m.y, h.x - m.x), v = Math.atan2(x.y - m.y, x.x - m.x);
182
+ return i - v;
183
+ }), g;
184
+ }, $ = (e, t, n, r) => {
185
+ const o = W([e, t, n], r);
186
+ return o.length < 3 ? 0 : j(o);
187
+ }, z = (e, t) => {
188
+ const n = [
189
+ [0, 1],
190
+ [0, 2],
191
+ [0, 3],
192
+ [1, 2],
193
+ [1, 3],
194
+ [2, 3]
195
+ ];
196
+ let r = null, c = -1;
197
+ for (const [o, s] of n) {
198
+ const l = t[o], u = t[s], f = U(e, l, u), y = $(e, l, u, t), d = f - y;
199
+ d > c && (c = d, r = [l, u]);
200
+ }
201
+ return r;
202
+ }, G = (e, t, n, r) => F(t, e, n, r), te = (e) => {
203
+ const {
204
+ tolerance: t = N,
205
+ isEnabled: n = !0,
206
+ onChange: r,
207
+ idleTimeout: c = X
208
+ } = e, o = T(null), s = T(!1), l = T(null), u = T(null), f = T(null), y = T(0), d = T(null), g = T(null), m = T(!1), a = (i) => {
209
+ s.current !== i ? (s.current = i, r == null || r(i)) : s.current = i;
210
+ }, h = () => s.current, x = D(() => {
211
+ m.current = !1, g.current = null;
212
+ const i = l.current, v = f.current || u.current, w = o.current;
213
+ if (!i || !w) {
214
+ a(!1), f.current = null, y.current = 0;
215
+ return;
216
+ }
217
+ if (!v) {
218
+ f.current = i, a(!1);
219
+ return;
220
+ }
221
+ if (i.x === v.x && i.y === v.y)
222
+ return;
223
+ const E = q(w);
224
+ if (S(i, E)) {
225
+ a(!1), f.current = i, y.current = 0;
226
+ return;
227
+ }
228
+ const M = z(i, E);
229
+ if (!M) {
230
+ a(!1), y.current = 0, f.current = i;
231
+ return;
232
+ }
233
+ const b = G(v, i, M[0], M[1]);
234
+ if (s.current !== b) {
235
+ const C = !s.current && b ? Math.min(5, t / 4) : t;
236
+ if (y.current < C)
237
+ return;
238
+ }
239
+ y.current = 0, f.current = i, a(b);
240
+ }, [t]);
241
+ return R(() => {
242
+ if (!n) {
243
+ a(!1), l.current = null, u.current = null, f.current = null, y.current = 0, d.current && (clearTimeout(d.current), d.current = null), g.current !== null && (cancelAnimationFrame(g.current), g.current = null), m.current = !1;
244
+ return;
245
+ }
246
+ const i = (v) => {
247
+ const w = { x: v.pageX, y: v.pageY }, E = l.current;
248
+ if (!E || w.x !== E.x || w.y !== E.y) {
249
+ if (E) {
250
+ const b = w.x - E.x, C = w.y - E.y, Y = Math.sqrt(b * b + C * C);
251
+ y.current += Y;
252
+ }
253
+ u.current = l.current, l.current = w, m.current || (m.current = !0, g.current = requestAnimationFrame(() => {
254
+ x();
255
+ })), d.current && (clearTimeout(d.current), d.current = null), d.current = window.setTimeout(() => {
256
+ a(!1), y.current = 0, f.current = null;
257
+ }, c);
258
+ }
259
+ };
260
+ return document.addEventListener("mousemove", i), () => {
261
+ document.removeEventListener("mousemove", i), d.current && clearTimeout(d.current), g.current !== null && cancelAnimationFrame(g.current);
262
+ };
263
+ }, [n, x, c]), {
264
+ isAiming: h,
265
+ ref: o
266
+ };
267
+ };
268
+ export {
269
+ ee as a,
270
+ te as b,
271
+ Q as c,
272
+ Z as u
273
+ };