@ensi-platform/admin-ui 0.15.0 → 0.15.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/Component-BcBH4MvL.js +179 -0
- package/dist/Component-BcBH4MvL.js.map +1 -0
- package/dist/assets/index26.css +1 -1
- package/dist/cascade-menu/index.js +1 -1
- package/dist/context-menu/Component.d.ts.map +1 -1
- package/dist/context-menu/index.js +1 -1
- package/dist/context-menu/types.d.ts +1 -1
- package/dist/context-menu/types.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/context-menu/docs/Description.md +2 -2
- package/src/context-menu/types.ts +1 -1
- package/dist/Component-B1piMJHv.js +0 -176
- package/dist/Component-B1piMJHv.js.map +0 -1
|
@@ -0,0 +1,179 @@
|
|
|
1
|
+
import { jsxs as k, jsx as b } from "react/jsx-runtime";
|
|
2
|
+
import { useContext as A, createContext as H, useRef as D, useState as O, useLayoutEffect as W, useEffect as B, useMemo as F } from "react";
|
|
3
|
+
import { createPortal as G } from "react-dom";
|
|
4
|
+
import h from "classnames";
|
|
5
|
+
import { useUNSAFE_PortalContext as K } from "react-aria";
|
|
6
|
+
import { s as w } from "./index-h8z54aFR.js";
|
|
7
|
+
import { typographyStyles as M } from "./typography/index.js";
|
|
8
|
+
import { cva as C } from "class-variance-authority";
|
|
9
|
+
import './assets/Component12.css';const L = H({
|
|
10
|
+
size: "md"
|
|
11
|
+
}), U = () => A(L), X = "aub_styles-module_root_424a2", q = "aub_styles-module_danger_078ce", J = "aub_styles-module_sm_ee87d", Q = "aub_styles-module_md_9b45e", Y = "aub_styles-module_lg_965fb", Z = "aub_styles-module_icon_c3730", u = {
|
|
12
|
+
root: X,
|
|
13
|
+
danger: q,
|
|
14
|
+
sm: J,
|
|
15
|
+
md: Q,
|
|
16
|
+
lg: Y,
|
|
17
|
+
icon: Z
|
|
18
|
+
}, tt = C(u.root, {
|
|
19
|
+
variants: {
|
|
20
|
+
size: {
|
|
21
|
+
sm: u.sm,
|
|
22
|
+
md: u.md,
|
|
23
|
+
lg: u.lg
|
|
24
|
+
},
|
|
25
|
+
variant: {
|
|
26
|
+
primary: null,
|
|
27
|
+
danger: u.danger
|
|
28
|
+
}
|
|
29
|
+
},
|
|
30
|
+
defaultVariants: {
|
|
31
|
+
size: "md",
|
|
32
|
+
variant: "primary"
|
|
33
|
+
}
|
|
34
|
+
}), et = {
|
|
35
|
+
sm: M.bodyXs,
|
|
36
|
+
md: M.bodySTight,
|
|
37
|
+
lg: M.bodyM
|
|
38
|
+
}, N = w(
|
|
39
|
+
({
|
|
40
|
+
ref: a,
|
|
41
|
+
children: o,
|
|
42
|
+
icon: t,
|
|
43
|
+
disabled: n = !1,
|
|
44
|
+
variant: e = "primary",
|
|
45
|
+
className: i,
|
|
46
|
+
dataTestId: s,
|
|
47
|
+
onClick: x,
|
|
48
|
+
...y
|
|
49
|
+
}) => {
|
|
50
|
+
const { size: p } = U();
|
|
51
|
+
return /* @__PURE__ */ k(
|
|
52
|
+
"button",
|
|
53
|
+
{
|
|
54
|
+
...y,
|
|
55
|
+
ref: a,
|
|
56
|
+
type: "button",
|
|
57
|
+
role: "menuitem",
|
|
58
|
+
disabled: n,
|
|
59
|
+
className: h(tt({ size: p, variant: e }), et[p], i),
|
|
60
|
+
"data-variant": e,
|
|
61
|
+
"data-test-id": s,
|
|
62
|
+
onClick: x,
|
|
63
|
+
children: [
|
|
64
|
+
t ? /* @__PURE__ */ b(t, { className: u.icon, "aria-hidden": !0, focusable: !1 }) : null,
|
|
65
|
+
o
|
|
66
|
+
]
|
|
67
|
+
}
|
|
68
|
+
);
|
|
69
|
+
}
|
|
70
|
+
);
|
|
71
|
+
N.displayName = "ContextMenu.Item";
|
|
72
|
+
const ot = "aub_styles-module_root_0ca94", nt = {
|
|
73
|
+
root: ot
|
|
74
|
+
}, S = w(({ className: a, dataTestId: o, ...t }) => /* @__PURE__ */ b("div", { ...t, role: "separator", className: h(nt.root, a), "data-test-id": o }));
|
|
75
|
+
S.displayName = "ContextMenu.Separator";
|
|
76
|
+
const st = "aub_styles-module_root_a6382", rt = "aub_styles-module_sm_f6741", at = "aub_styles-module_md_ce9c0", it = "aub_styles-module_lg_3b9bb", mt = "aub_styles-module_primary_5e631", f = {
|
|
77
|
+
root: st,
|
|
78
|
+
sm: rt,
|
|
79
|
+
md: at,
|
|
80
|
+
lg: it,
|
|
81
|
+
primary: mt
|
|
82
|
+
}, ct = C(f.root, {
|
|
83
|
+
variants: {
|
|
84
|
+
size: {
|
|
85
|
+
sm: f.sm,
|
|
86
|
+
md: f.md,
|
|
87
|
+
lg: f.lg
|
|
88
|
+
},
|
|
89
|
+
variant: {
|
|
90
|
+
primary: f.primary
|
|
91
|
+
}
|
|
92
|
+
},
|
|
93
|
+
defaultVariants: {
|
|
94
|
+
size: "md",
|
|
95
|
+
variant: "primary"
|
|
96
|
+
}
|
|
97
|
+
}), c = 8, dt = (a, o, t, n, e) => {
|
|
98
|
+
let i = a, s = o;
|
|
99
|
+
return i + t > e.width - c && (i = Math.max(c, e.width - t - c)), i < c && (i = c), s + n > e.height - c && (s = Math.max(c, o - n)), s < c && (s = c), { left: i, top: s };
|
|
100
|
+
}, P = w(
|
|
101
|
+
({
|
|
102
|
+
ref: a,
|
|
103
|
+
open: o = !1,
|
|
104
|
+
x: t,
|
|
105
|
+
y: n,
|
|
106
|
+
onClose: e,
|
|
107
|
+
onMouseEnter: i,
|
|
108
|
+
size: s = "md",
|
|
109
|
+
variant: x = "primary",
|
|
110
|
+
children: y,
|
|
111
|
+
className: p,
|
|
112
|
+
dataTestId: R,
|
|
113
|
+
style: $,
|
|
114
|
+
...z
|
|
115
|
+
}) => {
|
|
116
|
+
const _ = D(null), { getContainer: I } = K(), [v, T] = O(null), E = v?.x === t && v.y === n ? v : { left: t, top: n };
|
|
117
|
+
W(() => {
|
|
118
|
+
const m = _.current;
|
|
119
|
+
if (!o || !m) return;
|
|
120
|
+
const l = m.getBoundingClientRect(), d = dt(t, n, l.width, l.height, {
|
|
121
|
+
width: window.innerWidth,
|
|
122
|
+
height: window.innerHeight
|
|
123
|
+
});
|
|
124
|
+
T(
|
|
125
|
+
(r) => r?.x === t && r.y === n && r.left === d.left && r.top === d.top ? r : { x: t, y: n, ...d }
|
|
126
|
+
);
|
|
127
|
+
}, [o, t, n, y]), B(() => {
|
|
128
|
+
if (!o)
|
|
129
|
+
return;
|
|
130
|
+
const m = (r) => {
|
|
131
|
+
_.current?.contains(r.target) || e();
|
|
132
|
+
}, l = (r) => {
|
|
133
|
+
r.key === "Escape" && e();
|
|
134
|
+
}, d = (r) => {
|
|
135
|
+
const { target: g } = r;
|
|
136
|
+
g instanceof Node && _.current?.contains(g) || g instanceof HTMLInputElement || g instanceof HTMLTextAreaElement || e();
|
|
137
|
+
};
|
|
138
|
+
return document.addEventListener("mousedown", m), document.addEventListener("keydown", l), document.addEventListener("scroll", d, !0), window.addEventListener("resize", e), () => {
|
|
139
|
+
document.removeEventListener("mousedown", m), document.removeEventListener("keydown", l), document.removeEventListener("scroll", d, !0), window.removeEventListener("resize", e);
|
|
140
|
+
};
|
|
141
|
+
}, [o, e]);
|
|
142
|
+
const V = F(() => ({ size: s }), [s]);
|
|
143
|
+
if (!o || typeof document > "u")
|
|
144
|
+
return null;
|
|
145
|
+
const j = (m) => {
|
|
146
|
+
if (_.current = m, typeof a == "function") {
|
|
147
|
+
a(m);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
a && (a.current = m);
|
|
151
|
+
};
|
|
152
|
+
return G(
|
|
153
|
+
/* @__PURE__ */ b(L.Provider, { value: V, children: /* @__PURE__ */ b(
|
|
154
|
+
"div",
|
|
155
|
+
{
|
|
156
|
+
...z,
|
|
157
|
+
ref: j,
|
|
158
|
+
className: h(ct({ size: s, variant: x }), p),
|
|
159
|
+
style: { ...$, top: E.top, left: E.left },
|
|
160
|
+
role: "menu",
|
|
161
|
+
tabIndex: -1,
|
|
162
|
+
"data-test-id": R,
|
|
163
|
+
onMouseEnter: i,
|
|
164
|
+
children: y
|
|
165
|
+
}
|
|
166
|
+
) }),
|
|
167
|
+
I?.() ?? document.body
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
);
|
|
171
|
+
P.displayName = "ContextMenu";
|
|
172
|
+
const xt = Object.assign(P, {
|
|
173
|
+
Item: N,
|
|
174
|
+
Separator: S
|
|
175
|
+
});
|
|
176
|
+
export {
|
|
177
|
+
xt as C
|
|
178
|
+
};
|
|
179
|
+
//# sourceMappingURL=Component-BcBH4MvL.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Component-BcBH4MvL.js","sources":["../src/context-menu/context.ts","../src/context-menu/components/Item/theme.ts","../src/context-menu/components/Item/index.tsx","../src/context-menu/components/Separator/index.tsx","../src/context-menu/theme.ts","../src/context-menu/utils.ts","../src/context-menu/Component.tsx"],"sourcesContent":["import { createContext, useContext } from 'react';\n\nimport { type TContextMenuSize } from './types';\n\nexport interface IContextMenuContextValue {\n size: TContextMenuSize;\n}\n\nexport const ContextMenuContext = createContext<IContextMenuContextValue>({\n size: 'md',\n});\n\nexport const useContextMenu = () => useContext(ContextMenuContext);\n","import { cva } from 'class-variance-authority';\n\nimport styles from './styles.module.css';\n\nexport const contextMenuItemVariants = cva(styles.root, {\n variants: {\n size: {\n sm: styles.sm,\n md: styles.md,\n lg: styles.lg,\n },\n variant: {\n primary: null,\n danger: styles.danger,\n },\n },\n defaultVariants: {\n size: 'md',\n variant: 'primary',\n },\n});\n","import cn from 'classnames';\n\nimport { supportRef } from '@ds/common/support-ref';\nimport { typographyStyles } from '@ds/typography';\n\nimport { useContextMenu } from '../../context';\nimport { type IContextMenuItemProps } from '../../types';\n\nimport { contextMenuItemVariants } from './theme';\n\nimport styles from './styles.module.css';\n\nconst itemTypography = {\n sm: typographyStyles.bodyXs,\n md: typographyStyles.bodySTight,\n lg: typographyStyles.bodyM,\n} as const;\n\nexport const ContextMenuItem = supportRef(\n ({\n ref,\n children,\n icon: Icon,\n disabled = false,\n variant = 'primary',\n className,\n dataTestId,\n onClick,\n ...props\n }: IContextMenuItemProps) => {\n const { size } = useContextMenu();\n\n return (\n <button\n {...props}\n ref={ref}\n type=\"button\"\n role=\"menuitem\"\n disabled={disabled}\n className={cn(contextMenuItemVariants({ size, variant }), itemTypography[size], className)}\n data-variant={variant}\n data-test-id={dataTestId}\n onClick={onClick}\n >\n {Icon ? <Icon className={styles.icon} aria-hidden focusable={false} /> : null}\n {children}\n </button>\n );\n }\n);\n\nContextMenuItem.displayName = 'ContextMenu.Item';\n","import cn from 'classnames';\n\nimport { supportRef } from '@ds/common/support-ref';\n\nimport { type IContextMenuSeparatorProps } from '../../types';\n\nimport styles from './styles.module.css';\n\nexport const ContextMenuSeparator = supportRef(({ className, dataTestId, ...props }: IContextMenuSeparatorProps) => (\n <div {...props} role=\"separator\" className={cn(styles.root, className)} data-test-id={dataTestId} />\n));\n\nContextMenuSeparator.displayName = 'ContextMenu.Separator';\n","import { cva } from 'class-variance-authority';\n\nimport styles from './styles.module.css';\n\nexport const contextMenuVariants = cva(styles.root, {\n variants: {\n size: {\n sm: styles.sm,\n md: styles.md,\n lg: styles.lg,\n },\n variant: {\n primary: styles.primary,\n },\n },\n defaultVariants: {\n size: 'md',\n variant: 'primary',\n },\n});\n","const VIEWPORT_GAP = 8;\n\n/** Keeps the menu inside the viewport. Overflow to the right shifts left; overflow below flips above the anchor. */\nexport const placeContextMenu = (\n x: number,\n y: number,\n width: number,\n height: number,\n viewport: { width: number; height: number }\n): { left: number; top: number } => {\n let left = x;\n let top = y;\n\n if (left + width > viewport.width - VIEWPORT_GAP) {\n left = Math.max(VIEWPORT_GAP, viewport.width - width - VIEWPORT_GAP);\n }\n\n if (left < VIEWPORT_GAP) left = VIEWPORT_GAP;\n\n if (top + height > viewport.height - VIEWPORT_GAP) {\n top = Math.max(VIEWPORT_GAP, y - height);\n }\n\n if (top < VIEWPORT_GAP) top = VIEWPORT_GAP;\n\n return { left, top };\n};\n","import { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';\n\nimport { createPortal } from 'react-dom';\n\nimport cn from 'classnames';\nimport { useUNSAFE_PortalContext } from 'react-aria';\n\nimport { supportRef } from '@ds/common/support-ref';\n\nimport { ContextMenuItem } from './components/Item';\nimport { ContextMenuSeparator } from './components/Separator';\nimport { ContextMenuContext } from './context';\nimport { contextMenuVariants } from './theme';\nimport { type IContextMenuProps } from './types';\nimport { placeContextMenu } from './utils';\n\nconst ContextMenuRoot = supportRef(\n ({\n ref,\n open = false,\n x,\n y,\n onClose,\n onMouseEnter,\n size = 'md',\n variant = 'primary',\n children,\n className,\n dataTestId,\n style,\n ...props\n }: IContextMenuProps) => {\n const rootRef = useRef<HTMLDivElement | null>(null);\n const { getContainer } = useUNSAFE_PortalContext();\n const [placed, setPlaced] = useState<{ x: number; y: number; left: number; top: number } | null>(null);\n const position = placed?.x === x && placed.y === y ? placed : { left: x, top: y };\n\n useLayoutEffect(() => {\n const node = rootRef.current;\n\n if (!open || !node) return;\n\n const rect = node.getBoundingClientRect();\n const next = placeContextMenu(x, y, rect.width, rect.height, {\n width: window.innerWidth,\n height: window.innerHeight,\n });\n\n setPlaced(current =>\n current?.x === x && current.y === y && current.left === next.left && current.top === next.top\n ? current\n : { x, y, ...next }\n );\n }, [open, x, y, children]);\n\n useEffect(() => {\n if (!open) {\n return;\n }\n\n const onPointerDown = (event: MouseEvent) => {\n if (rootRef.current?.contains(event.target as Node)) {\n return;\n }\n\n onClose();\n };\n\n const onKeyDown = (event: KeyboardEvent) => {\n if (event.key === 'Escape') {\n onClose();\n }\n };\n\n // The menu sits at fixed viewport x/y, so any outside scroll or resize leaves it detached from its anchor.\n const onScroll = (event: Event) => {\n const { target } = event;\n\n if (target instanceof Node && rootRef.current?.contains(target)) return;\n // A text field scrolls its caret into view on focus or typing; that is not a page scroll.\n if (target instanceof HTMLInputElement || target instanceof HTMLTextAreaElement) return;\n\n onClose();\n };\n\n document.addEventListener('mousedown', onPointerDown);\n document.addEventListener('keydown', onKeyDown);\n // Capture phase: scroll does not bubble, so element scrolls only reach document while capturing.\n document.addEventListener('scroll', onScroll, true);\n window.addEventListener('resize', onClose);\n\n return () => {\n document.removeEventListener('mousedown', onPointerDown);\n document.removeEventListener('keydown', onKeyDown);\n document.removeEventListener('scroll', onScroll, true);\n window.removeEventListener('resize', onClose);\n };\n }, [open, onClose]);\n\n const contextValue = useMemo(() => ({ size }), [size]);\n\n if (!open || typeof document === 'undefined') {\n return null;\n }\n\n const setRef = (node: HTMLDivElement | null) => {\n rootRef.current = node;\n\n if (typeof ref === 'function') {\n ref(node);\n return;\n }\n\n if (ref) {\n ref.current = node;\n }\n };\n\n return createPortal(\n <ContextMenuContext.Provider value={contextValue}>\n <div\n {...props}\n ref={setRef}\n className={cn(contextMenuVariants({ size, variant }), className)}\n style={{ ...style, top: position.top, left: position.left }}\n role=\"menu\"\n tabIndex={-1}\n data-test-id={dataTestId}\n onMouseEnter={onMouseEnter}\n >\n {children}\n </div>\n </ContextMenuContext.Provider>,\n getContainer?.() ?? document.body\n );\n }\n);\n\nContextMenuRoot.displayName = 'ContextMenu';\n\nexport const ContextMenu = Object.assign(ContextMenuRoot, {\n Item: ContextMenuItem,\n Separator: ContextMenuSeparator,\n});\n"],"names":["ContextMenuContext","createContext","useContextMenu","useContext","contextMenuItemVariants","cva","styles","itemTypography","typographyStyles","ContextMenuItem","supportRef","ref","children","Icon","disabled","variant","className","dataTestId","onClick","props","size","jsxs","cn","jsx","ContextMenuSeparator","contextMenuVariants","VIEWPORT_GAP","placeContextMenu","x","y","width","height","viewport","left","top","ContextMenuRoot","open","onClose","onMouseEnter","style","rootRef","useRef","getContainer","useUNSAFE_PortalContext","placed","setPlaced","useState","position","useLayoutEffect","node","rect","next","current","useEffect","onPointerDown","event","onKeyDown","onScroll","target","contextValue","useMemo","setRef","createPortal","ContextMenu"],"mappings":";;;;;;;;AAQO,MAAMA,IAAqBC,EAAwC;AAAA,EACtE,MAAM;AACV,CAAC,GAEYC,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GED
|
@@ -1 +1 @@
|
|
|
1
|
-
.aub_styles-module_trigger_f9d5f{display:inline-flex;align-items:center;justify-content:
|
|
1
|
+
.aub_styles-module_trigger_f9d5f{display:inline-flex;align-items:center;justify-content:end;box-sizing:border-box;width:100%;height:100%;margin:0;padding:var(--aui-data-table-pad-y-utility) var(--aui-data-table-pad-x-utility);border:none;background:transparent;color:var(--aui-data-table-fg-muted);cursor:pointer;transition:color var(--aui-data-table-duration-fast) var(--aui-data-table-ease-out)}.aub_styles-module_trigger_f9d5f:hover,.aub_styles-module_trigger_f9d5f:focus-visible{color:var(--aui-data-table-fg-primary)}.aub_styles-module_trigger_f9d5f:focus-visible{outline:2px solid var(--aui-data-table-border-focus);outline-offset:-2px}.aub_styles-module_icon_fcb5d{width:1rem;height:1rem;flex-shrink:0}.aub_styles-module_visuallyHidden_14779{position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0}@media(prefers-reduced-motion:reduce){.aub_styles-module_trigger_f9d5f{transition:none}}
|
|
@@ -4,7 +4,7 @@ import T from "classnames";
|
|
|
4
4
|
import { s as In } from "../index-h8z54aFR.js";
|
|
5
5
|
import { S as We, P as $n, a as On, b as kn, c as _e, E as Tn } from "../Search-dQa9wT3n.js";
|
|
6
6
|
import { u as ve, b as zn } from "../hooks-BSSTu-2y.js";
|
|
7
|
-
import { C as Q } from "../Component-
|
|
7
|
+
import { C as Q } from "../Component-BcBH4MvL.js";
|
|
8
8
|
import { M as Xe } from "../Component-Qhj0uSjq.js";
|
|
9
9
|
import { typographyStyles as X } from "../typography/index.js";
|
|
10
10
|
import { ModalOverlay as Hn, Modal as Bn, Dialog as Wn } from "react-aria-components";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Component.d.ts","sourceRoot":"","sources":["../../../src/context-menu/Component.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,SAAS,CAAC;AA+
|
|
1
|
+
{"version":3,"file":"Component.d.ts","sourceRoot":"","sources":["../../../src/context-menu/Component.tsx"],"names":[],"mappings":"AAaA,OAAO,EAAE,KAAK,iBAAiB,EAAE,MAAM,SAAS,CAAC;AA+HjD,eAAO,MAAM,WAAW,iHA7GjB,iBAAiB;;;;;;;;;CAgHtB,CAAC"}
|
|
@@ -19,7 +19,7 @@ export interface IContextMenuControlProps {
|
|
|
19
19
|
x: number;
|
|
20
20
|
/** Fixed top position (viewport px). */
|
|
21
21
|
y: number;
|
|
22
|
-
/** Close handler (outside click / Escape). */
|
|
22
|
+
/** Close handler (outside click / Escape / outside scroll / window resize). */
|
|
23
23
|
onClose: () => void;
|
|
24
24
|
}
|
|
25
25
|
/** Own / chrome props (not from DOM). */
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../../src/context-menu/types.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,qBAAqB,EAAE,KAAK,UAAU,EAAE,KAAK,SAAS,EAAE,KAAK,GAAG,EAAE,MAAM,OAAO,CAAC;AAE9F,OAAO,EAAE,KAAK,gBAAgB,EAAE,KAAK,SAAS,EAAE,MAAM,YAAY,CAAC;AAEnE,wBAAwB;AACxB,MAAM,MAAM,gBAAgB,GAAG,IAAI,GAAG,IAAI,GAAG,IAAI,CAAC;AAElD,sBAAsB;AACtB,MAAM,MAAM,mBAAmB,GAAG,SAAS,CAAC;AAE5C,oBAAoB;AACpB,MAAM,WAAW,sBAAsB;IACnC,wBAAwB;IACxB,IAAI,CAAC,EAAE,gBAAgB,CAAC;IACxB,sBAAsB;IACtB,OAAO,CAAC,EAAE,mBAAmB,CAAC;CACjC;AAED,0CAA0C;AAC1C,MAAM,WAAW,wBAAwB;IACrC,gCAAgC;IAChC,IAAI,CAAC,EAAE,OAAO,CAAC;IACf,yCAAyC;IACzC,CAAC,EAAE,MAAM,CAAC;IACV,wCAAwC;IACxC,CAAC,EAAE,MAAM,CA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B,CAAC,KAAK,CAAC,EAAE,MAAM,qBAAqB,GAAG,UAAU,CAAC;CAAG;AAElH,iBAAiB;AACjB,MAAM,MAAM,uBAAuB,GAAG,SAAS,GAAG,QAAQ,CAAC;AAE3D,+CAA+C;AAC/C,MAAM,WAAW,wBAAyB,SAAQ,gBAAgB;IAC9D,aAAa;IACb,QAAQ,EAAE,SAAS,CAAC;IACpB,2BAA2B;IAC3B,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB,0BAA0B;IAC1B,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,mBAAmB;IACnB,OAAO,CAAC,EAAE,uBAAuB,CAAC;IAClC,8CAA8C;IAC9C,GAAG,CAAC,EAAE,GAAG,CAAC,iBAAiB,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,qBACb,SACI,wBAAwB,EACxB,IAAI,CAAC,qBAAqB,CAAC,QAAQ,CAAC,EAAE,MAAM,wBAAwB,GAAG,UAAU,GAAG,MAAM,CAAC;CAAG;AAEtG,oDAAoD;AACpD,MAAM,WAAW,6BAA8B,SAAQ,gBAAgB;CAAG;AAE1E,MAAM,WAAW,0BACb,SACI,6BAA6B,EAC7B,IAAI,CAAC,qBAAqB,CAAC,KAAK,CAAC,EAAE,MAAM,6BAA6B,GAAG,UAAU,GAAG,MAAM,CAAC;CAAG"}
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
Fixed cursor menu (RMB / coordinates): portal, dismiss on outside click and
|
|
1
|
+
Fixed cursor menu (RMB / coordinates): portal, dismiss on outside click, Escape, page or container scroll, and window resize.
|
|
2
2
|
|
|
3
3
|
```tsx
|
|
4
4
|
import { ContextMenu } from '@ensi-platform/admin-ui/context-menu';
|
|
@@ -19,7 +19,7 @@ import { ContextMenu } from '@ensi-platform/admin-ui/context-menu';
|
|
|
19
19
|
| `open` | `boolean` | `false` | whether the menu is open |
|
|
20
20
|
| `x` | `number` | — | left position (viewport px) |
|
|
21
21
|
| `y` | `number` | — | top position (viewport px) |
|
|
22
|
-
| `onClose` | `() => void` | — | close (outside / Escape)
|
|
22
|
+
| `onClose` | `() => void` | — | close (outside / Escape / scroll / resize) |
|
|
23
23
|
| `size` | `sm` \| `md` \| `lg` | `md` | size |
|
|
24
24
|
| `variant` | `primary` | `primary` | visual variant |
|
|
25
25
|
| `children` | `ReactNode` | — | `ContextMenu.Item` / `Separator` entries |
|
|
@@ -24,7 +24,7 @@ export interface IContextMenuControlProps {
|
|
|
24
24
|
x: number;
|
|
25
25
|
/** Fixed top position (viewport px). */
|
|
26
26
|
y: number;
|
|
27
|
-
/** Close handler (outside click / Escape). */
|
|
27
|
+
/** Close handler (outside click / Escape / outside scroll / window resize). */
|
|
28
28
|
onClose: () => void;
|
|
29
29
|
}
|
|
30
30
|
|
|
@@ -1,176 +0,0 @@
|
|
|
1
|
-
import { jsxs as k, jsx as _ } from "react/jsx-runtime";
|
|
2
|
-
import { useContext as T, createContext as A, useRef as D, useState as O, useLayoutEffect as W, useEffect as B, useMemo as F } from "react";
|
|
3
|
-
import { createPortal as G } from "react-dom";
|
|
4
|
-
import M from "classnames";
|
|
5
|
-
import { useUNSAFE_PortalContext as H } from "react-aria";
|
|
6
|
-
import { s as v } from "./index-h8z54aFR.js";
|
|
7
|
-
import { typographyStyles as h } from "./typography/index.js";
|
|
8
|
-
import { cva as w } from "class-variance-authority";
|
|
9
|
-
import './assets/Component12.css';const E = A({
|
|
10
|
-
size: "md"
|
|
11
|
-
}), K = () => T(E), U = "aub_styles-module_root_424a2", X = "aub_styles-module_danger_078ce", q = "aub_styles-module_sm_ee87d", J = "aub_styles-module_md_9b45e", Q = "aub_styles-module_lg_965fb", Y = "aub_styles-module_icon_c3730", u = {
|
|
12
|
-
root: U,
|
|
13
|
-
danger: X,
|
|
14
|
-
sm: q,
|
|
15
|
-
md: J,
|
|
16
|
-
lg: Q,
|
|
17
|
-
icon: Y
|
|
18
|
-
}, Z = w(u.root, {
|
|
19
|
-
variants: {
|
|
20
|
-
size: {
|
|
21
|
-
sm: u.sm,
|
|
22
|
-
md: u.md,
|
|
23
|
-
lg: u.lg
|
|
24
|
-
},
|
|
25
|
-
variant: {
|
|
26
|
-
primary: null,
|
|
27
|
-
danger: u.danger
|
|
28
|
-
}
|
|
29
|
-
},
|
|
30
|
-
defaultVariants: {
|
|
31
|
-
size: "md",
|
|
32
|
-
variant: "primary"
|
|
33
|
-
}
|
|
34
|
-
}), tt = {
|
|
35
|
-
sm: h.bodyXs,
|
|
36
|
-
md: h.bodySTight,
|
|
37
|
-
lg: h.bodyM
|
|
38
|
-
}, N = v(
|
|
39
|
-
({
|
|
40
|
-
ref: s,
|
|
41
|
-
children: e,
|
|
42
|
-
icon: t,
|
|
43
|
-
disabled: o = !1,
|
|
44
|
-
variant: a = "primary",
|
|
45
|
-
className: r,
|
|
46
|
-
dataTestId: n,
|
|
47
|
-
onClick: g,
|
|
48
|
-
...y
|
|
49
|
-
}) => {
|
|
50
|
-
const { size: p } = K();
|
|
51
|
-
return /* @__PURE__ */ k(
|
|
52
|
-
"button",
|
|
53
|
-
{
|
|
54
|
-
...y,
|
|
55
|
-
ref: s,
|
|
56
|
-
type: "button",
|
|
57
|
-
role: "menuitem",
|
|
58
|
-
disabled: o,
|
|
59
|
-
className: M(Z({ size: p, variant: a }), tt[p], r),
|
|
60
|
-
"data-variant": a,
|
|
61
|
-
"data-test-id": n,
|
|
62
|
-
onClick: g,
|
|
63
|
-
children: [
|
|
64
|
-
t ? /* @__PURE__ */ _(t, { className: u.icon, "aria-hidden": !0, focusable: !1 }) : null,
|
|
65
|
-
e
|
|
66
|
-
]
|
|
67
|
-
}
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
);
|
|
71
|
-
N.displayName = "ContextMenu.Item";
|
|
72
|
-
const et = "aub_styles-module_root_0ca94", ot = {
|
|
73
|
-
root: et
|
|
74
|
-
}, P = v(({ className: s, dataTestId: e, ...t }) => /* @__PURE__ */ _("div", { ...t, role: "separator", className: M(ot.root, s), "data-test-id": e }));
|
|
75
|
-
P.displayName = "ContextMenu.Separator";
|
|
76
|
-
const nt = "aub_styles-module_root_a6382", st = "aub_styles-module_sm_f6741", at = "aub_styles-module_md_ce9c0", rt = "aub_styles-module_lg_3b9bb", mt = "aub_styles-module_primary_5e631", f = {
|
|
77
|
-
root: nt,
|
|
78
|
-
sm: st,
|
|
79
|
-
md: at,
|
|
80
|
-
lg: rt,
|
|
81
|
-
primary: mt
|
|
82
|
-
}, it = w(f.root, {
|
|
83
|
-
variants: {
|
|
84
|
-
size: {
|
|
85
|
-
sm: f.sm,
|
|
86
|
-
md: f.md,
|
|
87
|
-
lg: f.lg
|
|
88
|
-
},
|
|
89
|
-
variant: {
|
|
90
|
-
primary: f.primary
|
|
91
|
-
}
|
|
92
|
-
},
|
|
93
|
-
defaultVariants: {
|
|
94
|
-
size: "md",
|
|
95
|
-
variant: "primary"
|
|
96
|
-
}
|
|
97
|
-
}), i = 8, lt = (s, e, t, o, a) => {
|
|
98
|
-
let r = s, n = e;
|
|
99
|
-
return r + t > a.width - i && (r = Math.max(i, a.width - t - i)), r < i && (r = i), n + o > a.height - i && (n = Math.max(i, e - o)), n < i && (n = i), { left: r, top: n };
|
|
100
|
-
}, R = v(
|
|
101
|
-
({
|
|
102
|
-
ref: s,
|
|
103
|
-
open: e = !1,
|
|
104
|
-
x: t,
|
|
105
|
-
y: o,
|
|
106
|
-
onClose: a,
|
|
107
|
-
onMouseEnter: r,
|
|
108
|
-
size: n = "md",
|
|
109
|
-
variant: g = "primary",
|
|
110
|
-
children: y,
|
|
111
|
-
className: p,
|
|
112
|
-
dataTestId: S,
|
|
113
|
-
style: $,
|
|
114
|
-
...V
|
|
115
|
-
}) => {
|
|
116
|
-
const b = D(null), { getContainer: I } = H(), [x, L] = O(null), C = x?.x === t && x.y === o ? x : { left: t, top: o };
|
|
117
|
-
W(() => {
|
|
118
|
-
const m = b.current;
|
|
119
|
-
if (!e || !m) return;
|
|
120
|
-
const d = m.getBoundingClientRect(), l = lt(t, o, d.width, d.height, {
|
|
121
|
-
width: window.innerWidth,
|
|
122
|
-
height: window.innerHeight
|
|
123
|
-
});
|
|
124
|
-
L(
|
|
125
|
-
(c) => c?.x === t && c.y === o && c.left === l.left && c.top === l.top ? c : { x: t, y: o, ...l }
|
|
126
|
-
);
|
|
127
|
-
}, [e, t, o, y]), B(() => {
|
|
128
|
-
if (!e)
|
|
129
|
-
return;
|
|
130
|
-
const m = (l) => {
|
|
131
|
-
b.current?.contains(l.target) || a();
|
|
132
|
-
}, d = (l) => {
|
|
133
|
-
l.key === "Escape" && a();
|
|
134
|
-
};
|
|
135
|
-
return document.addEventListener("mousedown", m), document.addEventListener("keydown", d), () => {
|
|
136
|
-
document.removeEventListener("mousedown", m), document.removeEventListener("keydown", d);
|
|
137
|
-
};
|
|
138
|
-
}, [e, a]);
|
|
139
|
-
const z = F(() => ({ size: n }), [n]);
|
|
140
|
-
if (!e || typeof document > "u")
|
|
141
|
-
return null;
|
|
142
|
-
const j = (m) => {
|
|
143
|
-
if (b.current = m, typeof s == "function") {
|
|
144
|
-
s(m);
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
s && (s.current = m);
|
|
148
|
-
};
|
|
149
|
-
return G(
|
|
150
|
-
/* @__PURE__ */ _(E.Provider, { value: z, children: /* @__PURE__ */ _(
|
|
151
|
-
"div",
|
|
152
|
-
{
|
|
153
|
-
...V,
|
|
154
|
-
ref: j,
|
|
155
|
-
className: M(it({ size: n, variant: g }), p),
|
|
156
|
-
style: { ...$, top: C.top, left: C.left },
|
|
157
|
-
role: "menu",
|
|
158
|
-
tabIndex: -1,
|
|
159
|
-
"data-test-id": S,
|
|
160
|
-
onMouseEnter: r,
|
|
161
|
-
children: y
|
|
162
|
-
}
|
|
163
|
-
) }),
|
|
164
|
-
I?.() ?? document.body
|
|
165
|
-
);
|
|
166
|
-
}
|
|
167
|
-
);
|
|
168
|
-
R.displayName = "ContextMenu";
|
|
169
|
-
const bt = Object.assign(R, {
|
|
170
|
-
Item: N,
|
|
171
|
-
Separator: P
|
|
172
|
-
});
|
|
173
|
-
export {
|
|
174
|
-
bt as C
|
|
175
|
-
};
|
|
176
|
-
//# sourceMappingURL=Component-B1piMJHv.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Component-B1piMJHv.js","sources":["../src/context-menu/context.ts","../src/context-menu/components/Item/theme.ts","../src/context-menu/components/Item/index.tsx","../src/context-menu/components/Separator/index.tsx","../src/context-menu/theme.ts","../src/context-menu/utils.ts","../src/context-menu/Component.tsx"],"sourcesContent":["import { createContext, useContext } from 'react';\n\nimport { type TContextMenuSize } from './types';\n\nexport interface IContextMenuContextValue {\n size: TContextMenuSize;\n}\n\nexport const ContextMenuContext = createContext<IContextMenuContextValue>({\n size: 'md',\n});\n\nexport const useContextMenu = () => useContext(ContextMenuContext);\n","import { cva } from 'class-variance-authority';\n\nimport styles from './styles.module.css';\n\nexport const contextMenuItemVariants = cva(styles.root, {\n variants: {\n size: {\n sm: styles.sm,\n md: styles.md,\n lg: styles.lg,\n },\n variant: {\n primary: null,\n danger: styles.danger,\n },\n },\n defaultVariants: {\n size: 'md',\n variant: 'primary',\n },\n});\n","import cn from 'classnames';\n\nimport { supportRef } from '@ds/common/support-ref';\nimport { typographyStyles } from '@ds/typography';\n\nimport { useContextMenu } from '../../context';\nimport { type IContextMenuItemProps } from '../../types';\n\nimport { contextMenuItemVariants } from './theme';\n\nimport styles from './styles.module.css';\n\nconst itemTypography = {\n sm: typographyStyles.bodyXs,\n md: typographyStyles.bodySTight,\n lg: typographyStyles.bodyM,\n} as const;\n\nexport const ContextMenuItem = supportRef(\n ({\n ref,\n children,\n icon: Icon,\n disabled = false,\n variant = 'primary',\n className,\n dataTestId,\n onClick,\n ...props\n }: IContextMenuItemProps) => {\n const { size } = useContextMenu();\n\n return (\n <button\n {...props}\n ref={ref}\n type=\"button\"\n role=\"menuitem\"\n disabled={disabled}\n className={cn(contextMenuItemVariants({ size, variant }), itemTypography[size], className)}\n data-variant={variant}\n data-test-id={dataTestId}\n onClick={onClick}\n >\n {Icon ? <Icon className={styles.icon} aria-hidden focusable={false} /> : null}\n {children}\n </button>\n );\n }\n);\n\nContextMenuItem.displayName = 'ContextMenu.Item';\n","import cn from 'classnames';\n\nimport { supportRef } from '@ds/common/support-ref';\n\nimport { type IContextMenuSeparatorProps } from '../../types';\n\nimport styles from './styles.module.css';\n\nexport const ContextMenuSeparator = supportRef(({ className, dataTestId, ...props }: IContextMenuSeparatorProps) => (\n <div {...props} role=\"separator\" className={cn(styles.root, className)} data-test-id={dataTestId} />\n));\n\nContextMenuSeparator.displayName = 'ContextMenu.Separator';\n","import { cva } from 'class-variance-authority';\n\nimport styles from './styles.module.css';\n\nexport const contextMenuVariants = cva(styles.root, {\n variants: {\n size: {\n sm: styles.sm,\n md: styles.md,\n lg: styles.lg,\n },\n variant: {\n primary: styles.primary,\n },\n },\n defaultVariants: {\n size: 'md',\n variant: 'primary',\n },\n});\n","const VIEWPORT_GAP = 8;\n\n/** Keeps the menu inside the viewport. Overflow to the right shifts left; overflow below flips above the anchor. */\nexport const placeContextMenu = (\n x: number,\n y: number,\n width: number,\n height: number,\n viewport: { width: number; height: number }\n): { left: number; top: number } => {\n let left = x;\n let top = y;\n\n if (left + width > viewport.width - VIEWPORT_GAP) {\n left = Math.max(VIEWPORT_GAP, viewport.width - width - VIEWPORT_GAP);\n }\n\n if (left < VIEWPORT_GAP) left = VIEWPORT_GAP;\n\n if (top + height > viewport.height - VIEWPORT_GAP) {\n top = Math.max(VIEWPORT_GAP, y - height);\n }\n\n if (top < VIEWPORT_GAP) top = VIEWPORT_GAP;\n\n return { left, top };\n};\n","import { useEffect, useLayoutEffect, useMemo, useRef, useState } from 'react';\n\nimport { createPortal } from 'react-dom';\n\nimport cn from 'classnames';\nimport { useUNSAFE_PortalContext } from 'react-aria';\n\nimport { supportRef } from '@ds/common/support-ref';\n\nimport { ContextMenuItem } from './components/Item';\nimport { ContextMenuSeparator } from './components/Separator';\nimport { ContextMenuContext } from './context';\nimport { contextMenuVariants } from './theme';\nimport { type IContextMenuProps } from './types';\nimport { placeContextMenu } from './utils';\n\nconst ContextMenuRoot = supportRef(\n ({\n ref,\n open = false,\n x,\n y,\n onClose,\n onMouseEnter,\n size = 'md',\n variant = 'primary',\n children,\n className,\n dataTestId,\n style,\n ...props\n }: IContextMenuProps) => {\n const rootRef = useRef<HTMLDivElement | null>(null);\n const { getContainer } = useUNSAFE_PortalContext();\n const [placed, setPlaced] = useState<{ x: number; y: number; left: number; top: number } | null>(null);\n const position = placed?.x === x && placed.y === y ? placed : { left: x, top: y };\n\n useLayoutEffect(() => {\n const node = rootRef.current;\n\n if (!open || !node) return;\n\n const rect = node.getBoundingClientRect();\n const next = placeContextMenu(x, y, rect.width, rect.height, {\n width: window.innerWidth,\n height: window.innerHeight,\n });\n\n setPlaced(current =>\n current?.x === x && current.y === y && current.left === next.left && current.top === next.top\n ? current\n : { x, y, ...next }\n );\n }, [open, x, y, children]);\n\n useEffect(() => {\n if (!open) {\n return;\n }\n\n const onPointerDown = (event: MouseEvent) => {\n if (rootRef.current?.contains(event.target as Node)) {\n return;\n }\n\n onClose();\n };\n\n const onKeyDown = (event: KeyboardEvent) => {\n if (event.key === 'Escape') {\n onClose();\n }\n };\n\n document.addEventListener('mousedown', onPointerDown);\n document.addEventListener('keydown', onKeyDown);\n\n return () => {\n document.removeEventListener('mousedown', onPointerDown);\n document.removeEventListener('keydown', onKeyDown);\n };\n }, [open, onClose]);\n\n const contextValue = useMemo(() => ({ size }), [size]);\n\n if (!open || typeof document === 'undefined') {\n return null;\n }\n\n const setRef = (node: HTMLDivElement | null) => {\n rootRef.current = node;\n\n if (typeof ref === 'function') {\n ref(node);\n return;\n }\n\n if (ref) {\n ref.current = node;\n }\n };\n\n return createPortal(\n <ContextMenuContext.Provider value={contextValue}>\n <div\n {...props}\n ref={setRef}\n className={cn(contextMenuVariants({ size, variant }), className)}\n style={{ ...style, top: position.top, left: position.left }}\n role=\"menu\"\n tabIndex={-1}\n data-test-id={dataTestId}\n onMouseEnter={onMouseEnter}\n >\n {children}\n </div>\n </ContextMenuContext.Provider>,\n getContainer?.() ?? document.body\n );\n }\n);\n\nContextMenuRoot.displayName = 'ContextMenu';\n\nexport const ContextMenu = Object.assign(ContextMenuRoot, {\n Item: ContextMenuItem,\n Separator: ContextMenuSeparator,\n});\n"],"names":["ContextMenuContext","createContext","useContextMenu","useContext","contextMenuItemVariants","cva","styles","itemTypography","typographyStyles","ContextMenuItem","supportRef","ref","children","Icon","disabled","variant","className","dataTestId","onClick","props","size","jsxs","cn","jsx","ContextMenuSeparator","contextMenuVariants","VIEWPORT_GAP","placeContextMenu","x","y","width","height","viewport","left","top","ContextMenuRoot","open","onClose","onMouseEnter","style","rootRef","useRef","getContainer","useUNSAFE_PortalContext","placed","setPlaced","useState","position","useLayoutEffect","node","rect","next","current","useEffect","onPointerDown","event","onKeyDown","contextValue","useMemo","setRef","createPortal","ContextMenu"],"mappings":";;;;;;;;AAQO,MAAMA,IAAqBC,EAAwC;AAAA,EACtE,MAAM;AACV,CAAC,GAEYC,IAAiB,MAAMC,EAAWH,CAAkB;;;;;;;GCRpDI,IAA0BC,EAAIC,EAAO,MAAM;AAAA,EACpD,UAAU;AAAA,IACN,MAAM;AAAA,MACF,IAAIA,EAAO;AAAA,MACX,IAAIA,EAAO;AAAA,MACX,IAAIA,EAAO;AAAA,IAAA;AAAA,IAEf,SAAS;AAAA,MACL,SAAS;AAAA,MACT,QAAQA,EAAO;AAAA,IAAA;AAAA,EACnB;AAAA,EAEJ,iBAAiB;AAAA,IACb,MAAM;AAAA,IACN,SAAS;AAAA,EAAA;AAEjB,CAAC,GCRKC,KAAiB;AAAA,EACnB,IAAIC,EAAiB;AAAA,EACrB,IAAIA,EAAiB;AAAA,EACrB,IAAIA,EAAiB;AACzB,GAEaC,IAAkBC;AAAA,EAC3B,CAAC;AAAA,IACG,KAAAC;AAAA,IACA,UAAAC;AAAA,IACA,MAAMC;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