cynx-lib 1.3.102 → 1.3.104

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 (46) hide show
  1. package/gen.js +77 -77
  2. package/package.json +1 -1
  3. package/ui/components/ActionsMenu.jsx +357 -357
  4. package/ui/components/Drawer.jsx +208 -208
  5. package/ui/components/Globe.jsx +764 -764
  6. package/ui/components/HoverCard.jsx +85 -85
  7. package/ui/components/Pagination.jsx +146 -145
  8. package/ui/components/PrivacyBlur.jsx +603 -603
  9. package/ui/components/XTable.jsx +116 -112
  10. package/ui/components/useRuler.jsx +94 -0
  11. package/ui/index.cjs +5 -0
  12. package/ui/index.js +3 -0
  13. package/utils/index.js +24 -24
  14. package/utils/utils/duration.js +139 -139
  15. package/utils/utils/oidc.js +214 -214
  16. package/utils/utils/realtime.js +1634 -1634
  17. package/utils/utils/server.js +371 -371
  18. package/utils/utils/session.js +131 -131
  19. package/utils/utils/session_manager.js +580 -580
  20. package/utils/utils/sso_manager.js +702 -702
  21. package/utils/utils/storage.js +393 -393
  22. package/utils/utils/ui.js +111 -111
  23. package/vue/components/Badge.vue +79 -79
  24. package/vue/components/Button.vue +209 -209
  25. package/vue/components/Checkbox.vue +103 -103
  26. package/vue/components/CircularProgress.vue +383 -383
  27. package/vue/components/Divider.vue +94 -94
  28. package/vue/components/Drawer.vue +243 -243
  29. package/vue/components/InfoBadge.vue +223 -223
  30. package/vue/components/Input.vue +341 -341
  31. package/vue/components/LinearProgress.vue +268 -268
  32. package/vue/components/Modal.vue +226 -226
  33. package/vue/components/Pagination.vue +199 -199
  34. package/vue/components/Select.vue +713 -713
  35. package/vue/components/Sidebar.vue +955 -955
  36. package/vue/components/Skeleton.vue +91 -91
  37. package/vue/components/Spinner.vue +263 -263
  38. package/vue/components/StatusTag.vue +89 -89
  39. package/vue/components/TabBar.vue +176 -176
  40. package/vue/components/Table.vue +388 -388
  41. package/vue/components/TimePicker.vue +399 -399
  42. package/vue/components/Toggle.vue +115 -115
  43. package/vue/components/XTable.vue +140 -140
  44. package/vue/composables/useAutoSkeletonRows.ts +71 -71
  45. package/vue/index.d.ts +67 -67
  46. package/vue/index.js +86 -86
@@ -1,357 +1,357 @@
1
- import { useState, useRef, useEffect, useCallback, useLayoutEffect } from 'react';
2
- import { createPortal } from 'react-dom';
3
-
4
- function ActionSubmenu({ items, menuRect, itemRect, closeAll, onMouseEnter, onMouseLeave }) {
5
- const subRef = useRef(null);
6
-
7
- useLayoutEffect(() => {
8
- const sub = subRef.current;
9
- if (!sub || !menuRect || !itemRect) return;
10
-
11
- const subWidth = sub.offsetWidth || 190;
12
- const subHeight = sub.offsetHeight || 150;
13
-
14
- // Determine horizontal docking relative to PARENT MENU container
15
- const spaceRight = window.innerWidth - menuRect.right;
16
- let left;
17
- let originX = 'left';
18
-
19
- if (spaceRight >= subWidth + 8) {
20
- // Dock cleanly to the right side of parent menu
21
- left = menuRect.right + 4;
22
- originX = 'left';
23
- } else {
24
- // Dock cleanly to the left side of parent menu (never overlaps!)
25
- left = menuRect.left - subWidth - 4;
26
- originX = 'right';
27
- }
28
-
29
- // Keep within viewport bounds
30
- left = Math.max(8, Math.min(left, window.innerWidth - subWidth - 8));
31
-
32
- // Determine vertical docking relative to the active item
33
- let top = itemRect.top - 5;
34
- let originY = 'top';
35
-
36
- if (top + subHeight > window.innerHeight - 8) {
37
- top = Math.max(8, window.innerHeight - subHeight - 8);
38
- originY = 'bottom';
39
- }
40
-
41
- sub.style.top = top + 'px';
42
- sub.style.left = left + 'px';
43
- sub.style.transformOrigin = `${originY} ${originX}`;
44
- }, [menuRect, itemRect]);
45
-
46
- return createPortal(
47
- <div
48
- ref={subRef}
49
- data-cynx-submenu="true"
50
- onMouseEnter={onMouseEnter}
51
- onMouseLeave={onMouseLeave}
52
- style={{
53
- position: 'fixed',
54
- zIndex: 100000,
55
- minWidth: 190,
56
- padding: 5,
57
- top: itemRect ? (itemRect.top - 5) + 'px' : '0px',
58
- left: menuRect ? (menuRect.left - 200) + 'px' : '0px',
59
- background: 'var(--surface,#fff)',
60
- border: '1.5px solid var(--border-light,#e2e8f0)',
61
- borderRadius: 'var(--rads,8px)',
62
- boxShadow: 'var(--shadow-lg, 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -4px rgba(0,0,0,.06))',
63
- animation: 'actionsDrop .12s cubic-bezier(.16,1,.3,1)',
64
- }}
65
- >
66
- {items.map((subItem, j) => (
67
- subItem.dividerBefore ? (
68
- <div key={j} style={{ height: 1, background: 'var(--border-light,#e2e8f0)', margin: '4px 0' }} />
69
- ) : (
70
- <div
71
- key={j}
72
- onClick={() => { closeAll(); subItem.onClick?.(); }}
73
- style={{
74
- display: 'flex', alignItems: 'center', gap: 8,
75
- padding: '6px 10px', borderRadius: 'var(--rads,8px)',
76
- fontSize: 12, cursor: 'pointer', transition: 'all .14s',
77
- whiteSpace: 'nowrap',
78
- color: (subItem.variant === 'danger' || subItem.danger) ? 'var(--danger, #ef4444)' : subItem.variant === 'success' ? 'var(--success, #16a34a)' : subItem.variant === 'warning' ? 'var(--warning, #f59e0b)' : 'var(--primary-text, #18181b)',
79
- fontWeight: 500,
80
- }}
81
- onMouseEnter={e => {
82
- e.currentTarget.style.background = (subItem.variant === 'danger' || subItem.danger) ? 'var(--danger-bg, rgba(239,68,68,.10))' : subItem.variant === 'success' ? 'var(--success-bg, rgba(22,163,74,.10))' : subItem.variant === 'warning' ? 'var(--warning-bg, rgba(245,158,11,.12))' : 'var(--grey-1, #f4f4f5)';
83
- }}
84
- onMouseLeave={e => { e.currentTarget.style.background = 'transparent'; }}
85
- >
86
- {subItem.icon && (
87
- <span style={{
88
- width: 24, height: 24, borderRadius: 5,
89
- display: 'flex', alignItems: 'center', justifyContent: 'center',
90
- flexShrink: 0, color: 'inherit', fontSize: 12,
91
- }}>{subItem.icon}</span>
92
- )}
93
- <span>{subItem.label}</span>
94
- </div>
95
- )
96
- ))}
97
- </div>,
98
- document.body
99
- );
100
- }
101
-
102
- export function ActionsMenu({ items, align = 'right' }) {
103
- const [open, setOpen] = useState(false);
104
- const [closing, setClosing] = useState(false);
105
- const [activeSub, setActiveSub] = useState(null); // { index, items, itemRect, menuRect }
106
- const wrapRef = useRef(null);
107
- const menuRef = useRef(null);
108
- const btnRef = useRef(null);
109
- const subTimerRef = useRef(null);
110
-
111
- const close = useCallback(() => {
112
- setClosing(true);
113
- setActiveSub(null);
114
- clearTimeout(subTimerRef.current);
115
- setTimeout(() => { setClosing(false); setOpen(false); }, 140);
116
- }, []);
117
-
118
- const openSub = (index, subItems, e) => {
119
- clearTimeout(subTimerRef.current);
120
- const itemRect = e.currentTarget.getBoundingClientRect();
121
- const menuRect = menuRef.current ? menuRef.current.getBoundingClientRect() : itemRect;
122
- setActiveSub({ index, items: subItems, itemRect, menuRect });
123
- };
124
-
125
- const scheduleCloseSub = () => {
126
- clearTimeout(subTimerRef.current);
127
- subTimerRef.current = setTimeout(() => {
128
- setActiveSub(null);
129
- }, 150);
130
- };
131
-
132
- const cancelCloseSub = () => {
133
- clearTimeout(subTimerRef.current);
134
- };
135
-
136
- const positionMenu = useCallback(() => {
137
- const btn = btnRef.current;
138
- const menu = menuRef.current;
139
- if (!btn || !menu) return;
140
- const br = btn.getBoundingClientRect();
141
- const mw = menu.offsetWidth || 180;
142
- const mh = menu.offsetHeight || 120;
143
- const spaceBelow = window.innerHeight - br.bottom;
144
- const spaceAbove = br.top;
145
- const openUp = spaceBelow < mh + 12 && spaceAbove > spaceBelow;
146
-
147
- let top, left;
148
- if (openUp) {
149
- top = br.top - mh - 6;
150
- } else {
151
- top = br.bottom + 6;
152
- }
153
- if (align === 'left') {
154
- left = br.left;
155
- } else {
156
- left = br.right - mw;
157
- }
158
- left = Math.max(8, Math.min(left, window.innerWidth - mw - 8));
159
-
160
- menu.style.top = top + 'px';
161
- menu.style.left = left + 'px';
162
- menu.style.transformOrigin = openUp
163
- ? (align === 'left' ? 'bottom left' : 'bottom right')
164
- : (align === 'left' ? 'top left' : 'top right');
165
- menu.classList.toggle('open-up', openUp);
166
- if (!closing) {
167
- menu.style.animationName = openUp ? 'actionsDropUp' : 'actionsDrop';
168
- }
169
- }, [align, closing]);
170
-
171
- useEffect(() => {
172
- if (!open) return;
173
- function onDocClick(e) {
174
- if (
175
- wrapRef.current && !wrapRef.current.contains(e.target) &&
176
- menuRef.current && !menuRef.current.contains(e.target) &&
177
- !e.target.closest?.('[data-cynx-submenu]')
178
- ) {
179
- close();
180
- }
181
- }
182
- function onScroll() { positionMenu(); }
183
- document.addEventListener('mousedown', onDocClick);
184
- document.addEventListener('scroll', onScroll, true);
185
- window.addEventListener('resize', onScroll);
186
- return () => {
187
- document.removeEventListener('mousedown', onDocClick);
188
- document.removeEventListener('scroll', onScroll, true);
189
- window.removeEventListener('resize', onScroll);
190
- };
191
- }, [open, close, positionMenu]);
192
-
193
- useLayoutEffect(() => {
194
- if (open) {
195
- positionMenu();
196
- }
197
- }, [open, positionMenu]);
198
-
199
- function toggle() {
200
- if (open) close();
201
- else { setOpen(true); setClosing(false); setActiveSub(null); }
202
- }
203
-
204
- const isOpen = open && !closing;
205
-
206
- return (
207
- <div ref={wrapRef} style={{ position: 'relative', display: 'inline-block' }}>
208
- <button
209
- ref={btnRef}
210
- type="button"
211
- onClick={toggle}
212
- style={{
213
- width: 32, height: 32, borderRadius: 'var(--rads,8px)',
214
- border: isOpen ? '1px solid var(--accent,#f99e2c)' : '1px solid var(--border-light,#d7d8e0)',
215
- background: 'var(--surface,#fff)',
216
- cursor: 'pointer', display: 'flex', alignItems: 'center', justifyContent: 'center',
217
- color: isOpen ? 'var(--accent, #f99e2c)' : 'var(--muted,#797b8d)', transition: 'all .14s',
218
- boxShadow: isOpen ? 'var(--pd, rgba(249,158,44,.12))' : 'var(--shadow, 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06))',
219
- }}
220
- >
221
- <svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">
222
- <circle cx="5" cy="12" r="1.5" /><circle cx="12" cy="12" r="1.5" /><circle cx="19" cy="12" r="1.5" />
223
- </svg>
224
- </button>
225
-
226
- {open && typeof document !== 'undefined' && createPortal(
227
- <div
228
- ref={menuRef}
229
- style={{
230
- position: 'fixed', zIndex: 99999, minWidth: 180, padding: 5,
231
- background: 'var(--surface,#fff)', border: '1.5px solid var(--border-light,#e2e8f0)',
232
- borderRadius: 'var(--rads,8px)',
233
- boxShadow: 'var(--shadow-lg, 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -4px rgba(0,0,0,.06))',
234
- transformOrigin: align === 'left' ? 'top left' : 'top right',
235
- animation: closing
236
- ? 'actionsClose .14s ease forwards'
237
- : 'actionsDrop .14s cubic-bezier(.16,1,.3,1)',
238
- }}
239
- >
240
- {items.map((item, i) => {
241
- if (item.dividerBefore) {
242
- return <div key={i} style={{ height: 1, background: 'var(--border-light,#e2e8f0)', margin: '4px 0' }} />;
243
- }
244
-
245
- const hasSub = Array.isArray(item.items) && item.items.length > 0;
246
- const isSubActive = activeSub && activeSub.index === i;
247
-
248
- return (
249
- <div
250
- key={i}
251
- onClick={(e) => {
252
- if (hasSub) {
253
- e.stopPropagation();
254
- openSub(i, item.items, e);
255
- } else {
256
- close();
257
- item.onClick?.();
258
- }
259
- }}
260
- onMouseEnter={(e) => {
261
- if (hasSub) {
262
- openSub(i, item.items, e);
263
- } else {
264
- clearTimeout(subTimerRef.current);
265
- setActiveSub(null);
266
- }
267
- e.currentTarget.style.background = (item.variant === 'danger' || item.danger)
268
- ? 'var(--danger-bg, rgba(239,68,68,.10))'
269
- : item.variant === 'success'
270
- ? 'var(--success-bg, rgba(22,163,74,.10))'
271
- : item.variant === 'warning'
272
- ? 'var(--warning-bg, rgba(245,158,11,.12))'
273
- : 'var(--grey-1, #f4f4f5)';
274
- }}
275
- onMouseLeave={(e) => {
276
- if (hasSub) {
277
- scheduleCloseSub();
278
- }
279
- if (!isSubActive) {
280
- e.currentTarget.style.background = 'transparent';
281
- }
282
- }}
283
- style={{
284
- display: 'flex', alignItems: 'center', gap: 8,
285
- padding: '6px 10px', borderRadius: 'var(--rads,8px)',
286
- fontSize: 12, cursor: 'pointer', transition: 'all .14s',
287
- whiteSpace: 'nowrap',
288
- background: isSubActive ? 'var(--grey-1, #f4f4f5)' : 'transparent',
289
- color: (item.variant === 'danger' || item.danger)
290
- ? 'var(--danger, #ef4444)'
291
- : item.variant === 'success'
292
- ? 'var(--success, #16a34a)'
293
- : item.variant === 'warning'
294
- ? 'var(--warning, #f59e0b)'
295
- : 'var(--primary-text, #18181b)',
296
- fontWeight: 500,
297
- }}
298
- >
299
- {item.icon && (
300
- <span style={{
301
- width: 24, height: 24, borderRadius: 5,
302
- display: 'flex', alignItems: 'center', justifyContent: 'center',
303
- flexShrink: 0, color: 'inherit', fontSize: 12,
304
- }}>{item.icon}</span>
305
- )}
306
- <span>{item.label}</span>
307
-
308
- {hasSub && (
309
- <svg
310
- width="12"
311
- height="12"
312
- viewBox="0 0 24 24"
313
- fill="none"
314
- stroke="currentColor"
315
- strokeWidth="2.5"
316
- strokeLinecap="round"
317
- strokeLinejoin="round"
318
- style={{ marginLeft: 'auto', opacity: 0.55 }}
319
- >
320
- <polyline points="9 18 15 12 9 6" />
321
- </svg>
322
- )}
323
- </div>
324
- );
325
- })}
326
- </div>,
327
- document.body
328
- )}
329
-
330
- {open && activeSub && (
331
- <ActionSubmenu
332
- items={activeSub.items}
333
- menuRect={activeSub.menuRect}
334
- itemRect={activeSub.itemRect}
335
- closeAll={close}
336
- onMouseEnter={cancelCloseSub}
337
- onMouseLeave={scheduleCloseSub}
338
- />
339
- )}
340
-
341
- <style>{`
342
- @keyframes actionsDrop {
343
- from { opacity: 0; transform: translateY(-6px); }
344
- to { opacity: 1; transform: translateY(0); }
345
- }
346
- @keyframes actionsDropUp {
347
- from { opacity: 0; transform: translateY(6px); }
348
- to { opacity: 1; transform: translateY(0); }
349
- }
350
- @keyframes actionsClose {
351
- from { opacity: 1; transform: translateY(0); }
352
- to { opacity: 0; transform: translateY(-4px); }
353
- }
354
- `}</style>
355
- </div>
356
- );
357
- }
1
+ import { useState, useRef, useEffect, useCallback, useLayoutEffect } from 'react';
2
+ import { createPortal } from 'react-dom';
3
+
4
+ function ActionSubmenu({ items, menuRect, itemRect, closeAll, onMouseEnter, onMouseLeave }) {
5
+ const subRef = useRef(null);
6
+
7
+ useLayoutEffect(() => {
8
+ const sub = subRef.current;
9
+ if (!sub || !menuRect || !itemRect) return;
10
+
11
+ const subWidth = sub.offsetWidth || 190;
12
+ const subHeight = sub.offsetHeight || 150;
13
+
14
+ // Determine horizontal docking relative to PARENT MENU container
15
+ const spaceRight = window.innerWidth - menuRect.right;
16
+ let left;
17
+ let originX = 'left';
18
+
19
+ if (spaceRight >= subWidth + 8) {
20
+ // Dock cleanly to the right side of parent menu
21
+ left = menuRect.right + 4;
22
+ originX = 'left';
23
+ } else {
24
+ // Dock cleanly to the left side of parent menu (never overlaps!)
25
+ left = menuRect.left - subWidth - 4;
26
+ originX = 'right';
27
+ }
28
+
29
+ // Keep within viewport bounds
30
+ left = Math.max(8, Math.min(left, window.innerWidth - subWidth - 8));
31
+
32
+ // Determine vertical docking relative to the active item
33
+ let top = itemRect.top - 5;
34
+ let originY = 'top';
35
+
36
+ if (top + subHeight > window.innerHeight - 8) {
37
+ top = Math.max(8, window.innerHeight - subHeight - 8);
38
+ originY = 'bottom';
39
+ }
40
+
41
+ sub.style.top = top + 'px';
42
+ sub.style.left = left + 'px';
43
+ sub.style.transformOrigin = `${originY} ${originX}`;
44
+ }, [menuRect, itemRect]);
45
+
46
+ return createPortal(
47
+ <div
48
+ ref={subRef}
49
+ data-cynx-submenu="true"
50
+ onMouseEnter={onMouseEnter}
51
+ onMouseLeave={onMouseLeave}
52
+ style={{
53
+ position: 'fixed',
54
+ zIndex: 100000,
55
+ minWidth: 190,
56
+ padding: 5,
57
+ top: itemRect ? (itemRect.top - 5) + 'px' : '0px',
58
+ left: menuRect ? (menuRect.left - 200) + 'px' : '0px',
59
+ background: 'var(--surface,#fff)',
60
+ border: '1.5px solid var(--border-light,#e2e8f0)',
61
+ borderRadius: 'var(--rads,8px)',
62
+ boxShadow: 'var(--shadow-lg, 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -4px rgba(0,0,0,.06))',
63
+ animation: 'actionsDrop .12s cubic-bezier(.16,1,.3,1)',
64
+ }}
65
+ >
66
+ {items.map((subItem, j) => (
67
+ subItem.dividerBefore ? (
68
+ <div key={j} style={{ height: 1, background: 'var(--border-light,#e2e8f0)', margin: '4px 0' }} />
69
+ ) : (
70
+ <div
71
+ key={j}
72
+ onClick={() => { closeAll(); subItem.onClick?.(); }}
73
+ style={{
74
+ display: 'flex', alignItems: 'center', gap: 8,
75
+ padding: '6px 10px', borderRadius: 'var(--rads,8px)',
76
+ fontSize: 12, cursor: 'pointer', transition: 'all .14s',
77
+ whiteSpace: 'nowrap',
78
+ color: (subItem.variant === 'danger' || subItem.danger) ? 'var(--danger, #ef4444)' : subItem.variant === 'success' ? 'var(--success, #16a34a)' : subItem.variant === 'warning' ? 'var(--warning, #f59e0b)' : 'var(--primary-text, #18181b)',
79
+ fontWeight: 500,
80
+ }}
81
+ onMouseEnter={e => {
82
+ e.currentTarget.style.background = (subItem.variant === 'danger' || subItem.danger) ? 'var(--danger-bg, rgba(239,68,68,.10))' : subItem.variant === 'success' ? 'var(--success-bg, rgba(22,163,74,.10))' : subItem.variant === 'warning' ? 'var(--warning-bg, rgba(245,158,11,.12))' : 'var(--grey-1, #f4f4f5)';
83
+ }}
84
+ onMouseLeave={e => { e.currentTarget.style.background = 'transparent'; }}
85
+ >
86
+ {subItem.icon && (
87
+ <span style={{
88
+ width: 24, height: 24, borderRadius: 5,
89
+ display: 'flex', alignItems: 'center', justifyContent: 'center',
90
+ flexShrink: 0, color: 'inherit', fontSize: 12,
91
+ }}>{subItem.icon}</span>
92
+ )}
93
+ <span>{subItem.label}</span>
94
+ </div>
95
+ )
96
+ ))}
97
+ </div>,
98
+ document.body
99
+ );
100
+ }
101
+
102
+ export function ActionsMenu({ items, align = 'right' }) {
103
+ const [open, setOpen] = useState(false);
104
+ const [closing, setClosing] = useState(false);
105
+ const [activeSub, setActiveSub] = useState(null); // { index, items, itemRect, menuRect }
106
+ const wrapRef = useRef(null);
107
+ const menuRef = useRef(null);
108
+ const btnRef = useRef(null);
109
+ const subTimerRef = useRef(null);
110
+
111
+ const close = useCallback(() => {
112
+ setClosing(true);
113
+ setActiveSub(null);
114
+ clearTimeout(subTimerRef.current);
115
+ setTimeout(() => { setClosing(false); setOpen(false); }, 140);
116
+ }, []);
117
+
118
+ const openSub = (index, subItems, e) => {
119
+ clearTimeout(subTimerRef.current);
120
+ const itemRect = e.currentTarget.getBoundingClientRect();
121
+ const menuRect = menuRef.current ? menuRef.current.getBoundingClientRect() : itemRect;
122
+ setActiveSub({ index, items: subItems, itemRect, menuRect });
123
+ };
124
+
125
+ const scheduleCloseSub = () => {
126
+ clearTimeout(subTimerRef.current);
127
+ subTimerRef.current = setTimeout(() => {
128
+ setActiveSub(null);
129
+ }, 150);
130
+ };
131
+
132
+ const cancelCloseSub = () => {
133
+ clearTimeout(subTimerRef.current);
134
+ };
135
+
136
+ const positionMenu = useCallback(() => {
137
+ const btn = btnRef.current;
138
+ const menu = menuRef.current;
139
+ if (!btn || !menu) return;
140
+ const br = btn.getBoundingClientRect();
141
+ const mw = menu.offsetWidth || 180;
142
+ const mh = menu.offsetHeight || 120;
143
+ const spaceBelow = window.innerHeight - br.bottom;
144
+ const spaceAbove = br.top;
145
+ const openUp = spaceBelow < mh + 12 && spaceAbove > spaceBelow;
146
+
147
+ let top, left;
148
+ if (openUp) {
149
+ top = br.top - mh - 6;
150
+ } else {
151
+ top = br.bottom + 6;
152
+ }
153
+ if (align === 'left') {
154
+ left = br.left;
155
+ } else {
156
+ left = br.right - mw;
157
+ }
158
+ left = Math.max(8, Math.min(left, window.innerWidth - mw - 8));
159
+
160
+ menu.style.top = top + 'px';
161
+ menu.style.left = left + 'px';
162
+ menu.style.transformOrigin = openUp
163
+ ? (align === 'left' ? 'bottom left' : 'bottom right')
164
+ : (align === 'left' ? 'top left' : 'top right');
165
+ menu.classList.toggle('open-up', openUp);
166
+ if (!closing) {
167
+ menu.style.animationName = openUp ? 'actionsDropUp' : 'actionsDrop';
168
+ }
169
+ }, [align, closing]);
170
+
171
+ useEffect(() => {
172
+ if (!open) return;
173
+ function onDocClick(e) {
174
+ if (
175
+ wrapRef.current && !wrapRef.current.contains(e.target) &&
176
+ menuRef.current && !menuRef.current.contains(e.target) &&
177
+ !e.target.closest?.('[data-cynx-submenu]')
178
+ ) {
179
+ close();
180
+ }
181
+ }
182
+ function onScroll() { positionMenu(); }
183
+ document.addEventListener('mousedown', onDocClick);
184
+ document.addEventListener('scroll', onScroll, true);
185
+ window.addEventListener('resize', onScroll);
186
+ return () => {
187
+ document.removeEventListener('mousedown', onDocClick);
188
+ document.removeEventListener('scroll', onScroll, true);
189
+ window.removeEventListener('resize', onScroll);
190
+ };
191
+ }, [open, close, positionMenu]);
192
+
193
+ useLayoutEffect(() => {
194
+ if (open) {
195
+ positionMenu();
196
+ }
197
+ }, [open, positionMenu]);
198
+
199
+ function toggle() {
200
+ if (open) close();
201
+ else { setOpen(true); setClosing(false); setActiveSub(null); }
202
+ }
203
+
204
+ const isOpen = open && !closing;
205
+
206
+ return (
207
+ <div ref={wrapRef} style={{ position: 'relative', display: 'inline-block' }}>
208
+ <button
209
+ ref={btnRef}
210
+ type="button"
211
+ onClick={toggle}
212
+ style={{
213
+ width: 32, height: 32, borderRadius: 'var(--rads,8px)',
214
+ border: isOpen ? '1px solid var(--accent,#f99e2c)' : '1px solid var(--border-light,#d7d8e0)',
215
+ background: 'var(--surface,#fff)',
216
+ cursor: 'pointer', display: 'flex', alignItems: 'center', justifyContent: 'center',
217
+ color: isOpen ? 'var(--accent, #f99e2c)' : 'var(--muted,#797b8d)', transition: 'all .14s',
218
+ boxShadow: isOpen ? 'var(--pd, rgba(249,158,44,.12))' : 'var(--shadow, 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06))',
219
+ }}
220
+ >
221
+ <svg width="16" height="16" viewBox="0 0 24 24" fill="currentColor">
222
+ <circle cx="5" cy="12" r="1.5" /><circle cx="12" cy="12" r="1.5" /><circle cx="19" cy="12" r="1.5" />
223
+ </svg>
224
+ </button>
225
+
226
+ {open && typeof document !== 'undefined' && createPortal(
227
+ <div
228
+ ref={menuRef}
229
+ style={{
230
+ position: 'fixed', zIndex: 99999, minWidth: 180, padding: 5,
231
+ background: 'var(--surface,#fff)', border: '1.5px solid var(--border-light,#e2e8f0)',
232
+ borderRadius: 'var(--rads,8px)',
233
+ boxShadow: 'var(--shadow-lg, 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -4px rgba(0,0,0,.06))',
234
+ transformOrigin: align === 'left' ? 'top left' : 'top right',
235
+ animation: closing
236
+ ? 'actionsClose .14s ease forwards'
237
+ : 'actionsDrop .14s cubic-bezier(.16,1,.3,1)',
238
+ }}
239
+ >
240
+ {items.map((item, i) => {
241
+ if (item.dividerBefore) {
242
+ return <div key={i} style={{ height: 1, background: 'var(--border-light,#e2e8f0)', margin: '4px 0' }} />;
243
+ }
244
+
245
+ const hasSub = Array.isArray(item.items) && item.items.length > 0;
246
+ const isSubActive = activeSub && activeSub.index === i;
247
+
248
+ return (
249
+ <div
250
+ key={i}
251
+ onClick={(e) => {
252
+ if (hasSub) {
253
+ e.stopPropagation();
254
+ openSub(i, item.items, e);
255
+ } else {
256
+ close();
257
+ item.onClick?.();
258
+ }
259
+ }}
260
+ onMouseEnter={(e) => {
261
+ if (hasSub) {
262
+ openSub(i, item.items, e);
263
+ } else {
264
+ clearTimeout(subTimerRef.current);
265
+ setActiveSub(null);
266
+ }
267
+ e.currentTarget.style.background = (item.variant === 'danger' || item.danger)
268
+ ? 'var(--danger-bg, rgba(239,68,68,.10))'
269
+ : item.variant === 'success'
270
+ ? 'var(--success-bg, rgba(22,163,74,.10))'
271
+ : item.variant === 'warning'
272
+ ? 'var(--warning-bg, rgba(245,158,11,.12))'
273
+ : 'var(--grey-1, #f4f4f5)';
274
+ }}
275
+ onMouseLeave={(e) => {
276
+ if (hasSub) {
277
+ scheduleCloseSub();
278
+ }
279
+ if (!isSubActive) {
280
+ e.currentTarget.style.background = 'transparent';
281
+ }
282
+ }}
283
+ style={{
284
+ display: 'flex', alignItems: 'center', gap: 8,
285
+ padding: '6px 10px', borderRadius: 'var(--rads,8px)',
286
+ fontSize: 12, cursor: 'pointer', transition: 'all .14s',
287
+ whiteSpace: 'nowrap',
288
+ background: isSubActive ? 'var(--grey-1, #f4f4f5)' : 'transparent',
289
+ color: (item.variant === 'danger' || item.danger)
290
+ ? 'var(--danger, #ef4444)'
291
+ : item.variant === 'success'
292
+ ? 'var(--success, #16a34a)'
293
+ : item.variant === 'warning'
294
+ ? 'var(--warning, #f59e0b)'
295
+ : 'var(--primary-text, #18181b)',
296
+ fontWeight: 500,
297
+ }}
298
+ >
299
+ {item.icon && (
300
+ <span style={{
301
+ width: 24, height: 24, borderRadius: 5,
302
+ display: 'flex', alignItems: 'center', justifyContent: 'center',
303
+ flexShrink: 0, color: 'inherit', fontSize: 12,
304
+ }}>{item.icon}</span>
305
+ )}
306
+ <span>{item.label}</span>
307
+
308
+ {hasSub && (
309
+ <svg
310
+ width="12"
311
+ height="12"
312
+ viewBox="0 0 24 24"
313
+ fill="none"
314
+ stroke="currentColor"
315
+ strokeWidth="2.5"
316
+ strokeLinecap="round"
317
+ strokeLinejoin="round"
318
+ style={{ marginLeft: 'auto', opacity: 0.55 }}
319
+ >
320
+ <polyline points="9 18 15 12 9 6" />
321
+ </svg>
322
+ )}
323
+ </div>
324
+ );
325
+ })}
326
+ </div>,
327
+ document.body
328
+ )}
329
+
330
+ {open && activeSub && (
331
+ <ActionSubmenu
332
+ items={activeSub.items}
333
+ menuRect={activeSub.menuRect}
334
+ itemRect={activeSub.itemRect}
335
+ closeAll={close}
336
+ onMouseEnter={cancelCloseSub}
337
+ onMouseLeave={scheduleCloseSub}
338
+ />
339
+ )}
340
+
341
+ <style>{`
342
+ @keyframes actionsDrop {
343
+ from { opacity: 0; transform: translateY(-6px); }
344
+ to { opacity: 1; transform: translateY(0); }
345
+ }
346
+ @keyframes actionsDropUp {
347
+ from { opacity: 0; transform: translateY(6px); }
348
+ to { opacity: 1; transform: translateY(0); }
349
+ }
350
+ @keyframes actionsClose {
351
+ from { opacity: 1; transform: translateY(0); }
352
+ to { opacity: 0; transform: translateY(-4px); }
353
+ }
354
+ `}</style>
355
+ </div>
356
+ );
357
+ }