asterui 0.12.42 → 0.12.44
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/components/Button.d.ts +1 -0
- package/dist/components/Button.js +60 -52
- package/dist/components/Button.js.map +1 -1
- package/dist/components/ContextMenu.d.ts +4 -4
- package/dist/components/ContextMenu.js +96 -89
- package/dist/components/ContextMenu.js.map +1 -1
- package/dist/components/Dropdown.d.ts +7 -6
- package/dist/components/Dropdown.js +192 -186
- package/dist/components/Dropdown.js.map +1 -1
- package/dist/components/Menu.d.ts +7 -5
- package/dist/components/Menu.js +106 -99
- package/dist/components/Menu.js.map +1 -1
- package/dist/components/Tabs.d.ts +0 -2
- package/dist/components/Tabs.js +46 -43
- package/dist/components/Tabs.js.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +185 -184
- package/package.json +1 -1
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { default as React } from 'react';
|
|
2
|
+
export declare const IconSizeContext: React.Context<"xs" | "sm" | "md" | "lg" | "xl" | undefined>;
|
|
2
3
|
type BaseButtonProps = {
|
|
3
4
|
/** Button color */
|
|
4
5
|
color?: 'primary' | 'secondary' | 'accent' | 'info' | 'success' | 'warning' | 'error' | 'neutral';
|
|
@@ -1,21 +1,22 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
1
|
+
import { jsx as r, jsxs as I, Fragment as E } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as F } from "react";
|
|
3
|
+
const $ = F(void 0), Q = ({
|
|
4
|
+
children: a,
|
|
5
|
+
color: p,
|
|
6
|
+
variant: i,
|
|
7
|
+
size: c = "md",
|
|
8
|
+
active: x = !1,
|
|
9
|
+
loading: t = !1,
|
|
10
|
+
shape: d,
|
|
11
|
+
noAnimation: C = !1,
|
|
12
|
+
icon: l,
|
|
13
|
+
iconPosition: n = "start",
|
|
14
|
+
danger: k = !1,
|
|
14
15
|
pressed: b,
|
|
15
|
-
className:
|
|
16
|
-
...
|
|
16
|
+
className: v = "",
|
|
17
|
+
...o
|
|
17
18
|
}) => {
|
|
18
|
-
const
|
|
19
|
+
const m = k ? "error" : p, g = {
|
|
19
20
|
primary: "btn-primary",
|
|
20
21
|
secondary: "btn-secondary",
|
|
21
22
|
accent: "btn-accent",
|
|
@@ -24,7 +25,7 @@ const J = ({
|
|
|
24
25
|
warning: "btn-warning",
|
|
25
26
|
error: "btn-error",
|
|
26
27
|
neutral: "btn-neutral"
|
|
27
|
-
},
|
|
28
|
+
}, w = {
|
|
28
29
|
solid: "",
|
|
29
30
|
// default, no extra class needed
|
|
30
31
|
outline: "btn-outline",
|
|
@@ -32,13 +33,13 @@ const J = ({
|
|
|
32
33
|
soft: "btn-soft",
|
|
33
34
|
ghost: "btn-ghost",
|
|
34
35
|
link: "btn-link"
|
|
35
|
-
},
|
|
36
|
+
}, D = {
|
|
36
37
|
xs: "btn-xs",
|
|
37
38
|
sm: "btn-sm",
|
|
38
39
|
md: "",
|
|
39
40
|
lg: "btn-lg",
|
|
40
41
|
xl: "btn-xl"
|
|
41
|
-
},
|
|
42
|
+
}, B = {
|
|
42
43
|
square: "btn-square",
|
|
43
44
|
circle: "btn-circle",
|
|
44
45
|
wide: "btn-wide",
|
|
@@ -46,61 +47,68 @@ const J = ({
|
|
|
46
47
|
round: "rounded-full"
|
|
47
48
|
}, u = [
|
|
48
49
|
"btn",
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
].filter(Boolean).join(" "),
|
|
57
|
-
n
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
50
|
+
m && g[m],
|
|
51
|
+
i && w[i],
|
|
52
|
+
D[c],
|
|
53
|
+
x && "btn-active",
|
|
54
|
+
d && B[d],
|
|
55
|
+
C && "no-animation",
|
|
56
|
+
v
|
|
57
|
+
].filter(Boolean).join(" "), K = a != null && a !== "" ? {
|
|
58
|
+
xs: n === "start" ? "mr-1" : "ml-1",
|
|
59
|
+
sm: n === "start" ? "mr-1" : "ml-1",
|
|
60
|
+
md: n === "start" ? "mr-1.5" : "ml-1.5",
|
|
61
|
+
lg: n === "start" ? "mr-2" : "ml-2",
|
|
62
|
+
xl: n === "start" ? "mr-2" : "ml-2"
|
|
63
|
+
}[c] : "", f = l && /* @__PURE__ */ r($.Provider, { value: c, children: /* @__PURE__ */ r("span", { className: `inline-flex items-center ${K}`, "aria-hidden": "true", children: l }) }), h = /* @__PURE__ */ I(E, { children: [
|
|
64
|
+
t && /* @__PURE__ */ r("span", { className: "loading loading-spinner", "aria-hidden": "true" }),
|
|
65
|
+
!t && l && n === "start" && f,
|
|
66
|
+
a,
|
|
67
|
+
!t && l && n === "end" && f
|
|
61
68
|
] });
|
|
62
|
-
if ("href" in
|
|
63
|
-
const { href:
|
|
64
|
-
return /* @__PURE__ */
|
|
69
|
+
if ("href" in o && o.href !== void 0) {
|
|
70
|
+
const { href: S, disabled: T, onKeyDown: j, onClick: q, ...z } = o, s = T || t;
|
|
71
|
+
return /* @__PURE__ */ r(
|
|
65
72
|
"a",
|
|
66
73
|
{
|
|
67
|
-
href:
|
|
74
|
+
href: s ? void 0 : S,
|
|
68
75
|
role: "button",
|
|
69
76
|
className: u,
|
|
70
|
-
"aria-disabled":
|
|
71
|
-
"aria-busy":
|
|
77
|
+
"aria-disabled": s || void 0,
|
|
78
|
+
"aria-busy": t || void 0,
|
|
72
79
|
"aria-pressed": b,
|
|
73
|
-
tabIndex:
|
|
74
|
-
onKeyDown: (
|
|
75
|
-
|
|
80
|
+
tabIndex: s ? -1 : 0,
|
|
81
|
+
onKeyDown: (e) => {
|
|
82
|
+
e.key === " " && !s && (e.preventDefault(), e.currentTarget.click()), j?.(e);
|
|
76
83
|
},
|
|
77
|
-
onClick: (
|
|
78
|
-
if (
|
|
79
|
-
|
|
84
|
+
onClick: (e) => {
|
|
85
|
+
if (s) {
|
|
86
|
+
e.preventDefault();
|
|
80
87
|
return;
|
|
81
88
|
}
|
|
82
|
-
|
|
89
|
+
q?.(e);
|
|
83
90
|
},
|
|
84
|
-
...
|
|
91
|
+
...z,
|
|
85
92
|
children: h
|
|
86
93
|
}
|
|
87
94
|
);
|
|
88
95
|
}
|
|
89
|
-
const { htmlType:
|
|
90
|
-
return /* @__PURE__ */
|
|
96
|
+
const { htmlType: N, ...y } = o;
|
|
97
|
+
return /* @__PURE__ */ r(
|
|
91
98
|
"button",
|
|
92
99
|
{
|
|
93
|
-
type:
|
|
100
|
+
type: N ?? "button",
|
|
94
101
|
className: u,
|
|
95
|
-
"aria-busy":
|
|
102
|
+
"aria-busy": t || void 0,
|
|
96
103
|
"aria-pressed": b,
|
|
97
|
-
disabled:
|
|
98
|
-
...
|
|
104
|
+
disabled: t || y.disabled,
|
|
105
|
+
...y,
|
|
99
106
|
children: h
|
|
100
107
|
}
|
|
101
108
|
);
|
|
102
109
|
};
|
|
103
110
|
export {
|
|
104
|
-
|
|
111
|
+
Q as Button,
|
|
112
|
+
$ as IconSizeContext
|
|
105
113
|
};
|
|
106
114
|
//# sourceMappingURL=Button.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"Button.js","sources":["../../src/components/Button.tsx"],"sourcesContent":["import React from 'react'\n\ntype BaseButtonProps = {\n /** Button color */\n color?: 'primary' | 'secondary' | 'accent' | 'info' | 'success' | 'warning' | 'error' | 'neutral'\n /** Button style variant */\n variant?: 'solid' | 'outline' | 'dash' | 'soft' | 'ghost' | 'link'\n /** Button size */\n size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl'\n /** Active/pressed visual state */\n active?: boolean\n /** Show loading spinner and disable button */\n loading?: boolean\n /** Button shape */\n shape?: 'square' | 'circle' | 'wide' | 'block' | 'round'\n /** Disable click animation */\n noAnimation?: boolean\n /** Icon element to display */\n icon?: React.ReactNode\n /** Position of the icon */\n iconPosition?: 'start' | 'end'\n /** Applies error/danger styling (shorthand for color=\"error\") */\n danger?: boolean\n /** Toggle button pressed state (sets aria-pressed) */\n pressed?: boolean\n}\n\ntype ButtonAsButton = BaseButtonProps &\n Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'type'> & {\n href?: undefined\n htmlType?: 'button' | 'submit' | 'reset'\n }\n\ntype ButtonAsAnchor = BaseButtonProps &\n Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'type'> & {\n href: string\n htmlType?: undefined\n /** Disable the link button */\n disabled?: boolean\n }\n\nexport type ButtonProps = ButtonAsButton | ButtonAsAnchor\n\nexport const Button: React.FC<ButtonProps> = ({\n children,\n color,\n variant,\n size = 'md',\n active = false,\n loading = false,\n shape,\n noAnimation = false,\n icon,\n iconPosition = 'start',\n danger = false,\n pressed,\n className = '',\n ...props\n}) => {\n // danger prop is a shorthand for color=\"error\"\n const effectiveColor = danger ? 'error' : color\n\n const colorClasses = {\n primary: 'btn-primary',\n secondary: 'btn-secondary',\n accent: 'btn-accent',\n info: 'btn-info',\n success: 'btn-success',\n warning: 'btn-warning',\n error: 'btn-error',\n neutral: 'btn-neutral',\n }\n\n const variantClasses = {\n solid: '', // default, no extra class needed\n outline: 'btn-outline',\n dash: 'btn-dash',\n soft: 'btn-soft',\n ghost: 'btn-ghost',\n link: 'btn-link',\n }\n\n const sizeClasses = {\n xs: 'btn-xs',\n sm: 'btn-sm',\n md: '',\n lg: 'btn-lg',\n xl: 'btn-xl',\n }\n\n const shapeClasses = {\n square: 'btn-square',\n circle: 'btn-circle',\n wide: 'btn-wide',\n block: 'btn-block',\n round: 'rounded-full',\n }\n\n const classes = [\n 'btn',\n effectiveColor && colorClasses[effectiveColor],\n variant && variantClasses[variant],\n sizeClasses[size],\n active && 'btn-active',\n shape && shapeClasses[shape],\n noAnimation && 'no-animation',\n className,\n ]\n .filter(Boolean)\n .join(' ')\n\n // Determine icon spacing based on whether there's text content\n const hasChildren = children !== undefined && children !== null && children !== ''\n const
|
|
1
|
+
{"version":3,"file":"Button.js","sources":["../../src/components/Button.tsx"],"sourcesContent":["import React, { createContext } from 'react'\n\nexport const IconSizeContext = createContext<'xs' | 'sm' | 'md' | 'lg' | 'xl' | undefined>(undefined)\n\ntype BaseButtonProps = {\n /** Button color */\n color?: 'primary' | 'secondary' | 'accent' | 'info' | 'success' | 'warning' | 'error' | 'neutral'\n /** Button style variant */\n variant?: 'solid' | 'outline' | 'dash' | 'soft' | 'ghost' | 'link'\n /** Button size */\n size?: 'xs' | 'sm' | 'md' | 'lg' | 'xl'\n /** Active/pressed visual state */\n active?: boolean\n /** Show loading spinner and disable button */\n loading?: boolean\n /** Button shape */\n shape?: 'square' | 'circle' | 'wide' | 'block' | 'round'\n /** Disable click animation */\n noAnimation?: boolean\n /** Icon element to display */\n icon?: React.ReactNode\n /** Position of the icon */\n iconPosition?: 'start' | 'end'\n /** Applies error/danger styling (shorthand for color=\"error\") */\n danger?: boolean\n /** Toggle button pressed state (sets aria-pressed) */\n pressed?: boolean\n}\n\ntype ButtonAsButton = BaseButtonProps &\n Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, 'type'> & {\n href?: undefined\n htmlType?: 'button' | 'submit' | 'reset'\n }\n\ntype ButtonAsAnchor = BaseButtonProps &\n Omit<React.AnchorHTMLAttributes<HTMLAnchorElement>, 'type'> & {\n href: string\n htmlType?: undefined\n /** Disable the link button */\n disabled?: boolean\n }\n\nexport type ButtonProps = ButtonAsButton | ButtonAsAnchor\n\nexport const Button: React.FC<ButtonProps> = ({\n children,\n color,\n variant,\n size = 'md',\n active = false,\n loading = false,\n shape,\n noAnimation = false,\n icon,\n iconPosition = 'start',\n danger = false,\n pressed,\n className = '',\n ...props\n}) => {\n // danger prop is a shorthand for color=\"error\"\n const effectiveColor = danger ? 'error' : color\n\n const colorClasses = {\n primary: 'btn-primary',\n secondary: 'btn-secondary',\n accent: 'btn-accent',\n info: 'btn-info',\n success: 'btn-success',\n warning: 'btn-warning',\n error: 'btn-error',\n neutral: 'btn-neutral',\n }\n\n const variantClasses = {\n solid: '', // default, no extra class needed\n outline: 'btn-outline',\n dash: 'btn-dash',\n soft: 'btn-soft',\n ghost: 'btn-ghost',\n link: 'btn-link',\n }\n\n const sizeClasses = {\n xs: 'btn-xs',\n sm: 'btn-sm',\n md: '',\n lg: 'btn-lg',\n xl: 'btn-xl',\n }\n\n const shapeClasses = {\n square: 'btn-square',\n circle: 'btn-circle',\n wide: 'btn-wide',\n block: 'btn-block',\n round: 'rounded-full',\n }\n\n const classes = [\n 'btn',\n effectiveColor && colorClasses[effectiveColor],\n variant && variantClasses[variant],\n sizeClasses[size],\n active && 'btn-active',\n shape && shapeClasses[shape],\n noAnimation && 'no-animation',\n className,\n ]\n .filter(Boolean)\n .join(' ')\n\n // Determine icon spacing based on whether there's text content and button size\n const hasChildren = children !== undefined && children !== null && children !== ''\n const spacingBySize = {\n xs: iconPosition === 'start' ? 'mr-1' : 'ml-1',\n sm: iconPosition === 'start' ? 'mr-1' : 'ml-1',\n md: iconPosition === 'start' ? 'mr-1.5' : 'ml-1.5',\n lg: iconPosition === 'start' ? 'mr-2' : 'ml-2',\n xl: iconPosition === 'start' ? 'mr-2' : 'ml-2',\n }\n const iconSpacing = hasChildren ? spacingBySize[size] : ''\n\n const iconElement = icon && (\n <IconSizeContext.Provider value={size}>\n <span className={`inline-flex items-center ${iconSpacing}`} aria-hidden=\"true\">\n {icon}\n </span>\n </IconSizeContext.Provider>\n )\n\n const content = (\n <>\n {loading && <span className=\"loading loading-spinner\" aria-hidden=\"true\"></span>}\n {!loading && icon && iconPosition === 'start' && iconElement}\n {children}\n {!loading && icon && iconPosition === 'end' && iconElement}\n </>\n )\n\n if ('href' in props && props.href !== undefined) {\n const { href, disabled, onKeyDown, onClick, ...anchorProps } = props as ButtonAsAnchor & {\n onKeyDown?: React.KeyboardEventHandler<HTMLAnchorElement>\n onClick?: React.MouseEventHandler<HTMLAnchorElement>\n }\n const isDisabled = disabled || loading\n\n // Handle Space key for anchor buttons (links only respond to Enter natively)\n const handleKeyDown = (event: React.KeyboardEvent<HTMLAnchorElement>) => {\n if (event.key === ' ' && !isDisabled) {\n event.preventDefault()\n event.currentTarget.click()\n }\n onKeyDown?.(event)\n }\n\n // Prevent click when disabled\n const handleClick = (event: React.MouseEvent<HTMLAnchorElement>) => {\n if (isDisabled) {\n event.preventDefault()\n return\n }\n onClick?.(event)\n }\n\n return (\n <a\n href={isDisabled ? undefined : href}\n role=\"button\"\n className={classes}\n aria-disabled={isDisabled || undefined}\n aria-busy={loading || undefined}\n aria-pressed={pressed}\n tabIndex={isDisabled ? -1 : 0}\n onKeyDown={handleKeyDown}\n onClick={handleClick}\n {...anchorProps}\n >\n {content}\n </a>\n )\n }\n\n const { htmlType, ...buttonProps } = props as Omit<ButtonAsButton, keyof BaseButtonProps>\n const buttonType: 'button' | 'submit' | 'reset' = htmlType ?? 'button'\n return (\n <button\n type={buttonType}\n className={classes}\n aria-busy={loading || undefined}\n aria-pressed={pressed}\n disabled={loading || buttonProps.disabled}\n {...buttonProps}\n >\n {content}\n </button>\n )\n}\n"],"names":["IconSizeContext","createContext","Button","children","color","variant","size","active","loading","shape","noAnimation","icon","iconPosition","danger","pressed","className","props","effectiveColor","colorClasses","variantClasses","sizeClasses","shapeClasses","classes","iconSpacing","iconElement","jsx","content","jsxs","Fragment","href","disabled","onKeyDown","onClick","anchorProps","isDisabled","event","htmlType","buttonProps"],"mappings":";;AAEO,MAAMA,IAAkBC,EAA4D,MAAS,GA2CvFC,IAAgC,CAAC;AAAA,EAC5C,UAAAC;AAAA,EACA,OAAAC;AAAA,EACA,SAAAC;AAAA,EACA,MAAAC,IAAO;AAAA,EACP,QAAAC,IAAS;AAAA,EACT,SAAAC,IAAU;AAAA,EACV,OAAAC;AAAA,EACA,aAAAC,IAAc;AAAA,EACd,MAAAC;AAAA,EACA,cAAAC,I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AAA,MACX,aAAWd,KAAW;AAAA,MACtB,gBAAcM;AAAA,MACd,UAAUN,KAAW6B,EAAY;AAAA,MAChC,GAAGA;AAAA,MAEH,UAAAX;AAAA,IAAA;AAAA,EAAA;AAGP;"}
|
|
@@ -21,8 +21,6 @@ export interface ContextMenuProps {
|
|
|
21
21
|
className?: string;
|
|
22
22
|
}
|
|
23
23
|
export interface ContextMenuItemProps {
|
|
24
|
-
/** Unique key for the item */
|
|
25
|
-
itemKey: string;
|
|
26
24
|
/** Item content */
|
|
27
25
|
children: React.ReactNode;
|
|
28
26
|
/** Icon to display before label */
|
|
@@ -33,14 +31,14 @@ export interface ContextMenuItemProps {
|
|
|
33
31
|
danger?: boolean;
|
|
34
32
|
/** Additional CSS classes */
|
|
35
33
|
className?: string;
|
|
34
|
+
/** @internal */
|
|
35
|
+
_key?: string;
|
|
36
36
|
}
|
|
37
37
|
export interface ContextMenuDividerProps {
|
|
38
38
|
/** Additional CSS classes */
|
|
39
39
|
className?: string;
|
|
40
40
|
}
|
|
41
41
|
export interface ContextMenuSubMenuProps {
|
|
42
|
-
/** Unique key for the submenu */
|
|
43
|
-
itemKey: string;
|
|
44
42
|
/** Submenu label */
|
|
45
43
|
label: React.ReactNode;
|
|
46
44
|
/** Icon to display before label */
|
|
@@ -51,6 +49,8 @@ export interface ContextMenuSubMenuProps {
|
|
|
51
49
|
children: React.ReactNode;
|
|
52
50
|
/** Additional CSS classes */
|
|
53
51
|
className?: string;
|
|
52
|
+
/** @internal */
|
|
53
|
+
_key?: string;
|
|
54
54
|
}
|
|
55
55
|
export declare const ContextMenu: React.FC<ContextMenuProps> & {
|
|
56
56
|
Item: React.FC<ContextMenuItemProps>;
|
|
@@ -1,25 +1,25 @@
|
|
|
1
|
-
import { jsxs as b, Fragment as
|
|
2
|
-
import
|
|
3
|
-
import { createPortal as
|
|
4
|
-
const
|
|
5
|
-
const e =
|
|
1
|
+
import { jsxs as b, Fragment as B, jsx as n } from "react/jsx-runtime";
|
|
2
|
+
import C, { useState as g, useRef as y, useCallback as M, useEffect as E, createContext as I, useContext as K } from "react";
|
|
3
|
+
import { createPortal as V } from "react-dom";
|
|
4
|
+
const L = I(null), A = () => {
|
|
5
|
+
const e = K(L);
|
|
6
6
|
if (!e)
|
|
7
7
|
throw new Error("ContextMenu compound components must be used within a ContextMenu");
|
|
8
8
|
return e;
|
|
9
|
-
},
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
icon: l,
|
|
9
|
+
}, S = ({
|
|
10
|
+
children: e,
|
|
11
|
+
icon: c,
|
|
13
12
|
disabled: s = !1,
|
|
14
13
|
danger: d = !1,
|
|
15
|
-
className:
|
|
14
|
+
className: h = "",
|
|
15
|
+
_key: l
|
|
16
16
|
}) => {
|
|
17
|
-
const { onSelect:
|
|
18
|
-
return /* @__PURE__ */ n("li", { className:
|
|
17
|
+
const { onSelect: m, onClose: o } = A();
|
|
18
|
+
return /* @__PURE__ */ n("li", { className: h, children: /* @__PURE__ */ b(
|
|
19
19
|
"button",
|
|
20
20
|
{
|
|
21
21
|
onClick: () => {
|
|
22
|
-
s || (
|
|
22
|
+
s || !l || (m(l), o());
|
|
23
23
|
},
|
|
24
24
|
disabled: s,
|
|
25
25
|
className: `
|
|
@@ -28,30 +28,30 @@ const E = W(null), I = () => {
|
|
|
28
28
|
${d ? "text-error hover:bg-error/10" : ""}
|
|
29
29
|
`,
|
|
30
30
|
children: [
|
|
31
|
-
|
|
32
|
-
/* @__PURE__ */ n("span", { className: "flex-1", children:
|
|
31
|
+
c && /* @__PURE__ */ n("span", { className: "w-4 h-4", children: c }),
|
|
32
|
+
/* @__PURE__ */ n("span", { className: "flex-1", children: e })
|
|
33
33
|
]
|
|
34
34
|
}
|
|
35
35
|
) });
|
|
36
|
-
}, H = ({ className: e = "" }) => /* @__PURE__ */ n("li", { className: `divider my-1 ${e}` }),
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
icon: l,
|
|
36
|
+
}, H = ({ className: e = "" }) => /* @__PURE__ */ n("li", { className: `divider my-1 ${e}` }), R = ({
|
|
37
|
+
label: e,
|
|
38
|
+
icon: c,
|
|
40
39
|
disabled: s = !1,
|
|
41
40
|
children: d,
|
|
42
|
-
className:
|
|
41
|
+
className: h = "",
|
|
42
|
+
_key: l
|
|
43
43
|
}) => {
|
|
44
|
-
const [
|
|
45
|
-
s || (a.current && clearTimeout(a.current),
|
|
46
|
-
},
|
|
47
|
-
a.current = setTimeout(() =>
|
|
44
|
+
const [m, o] = g(!1), a = y(null), u = () => {
|
|
45
|
+
s || (a.current && clearTimeout(a.current), o(!0));
|
|
46
|
+
}, f = () => {
|
|
47
|
+
a.current = setTimeout(() => o(!1), 100);
|
|
48
48
|
};
|
|
49
49
|
return /* @__PURE__ */ b(
|
|
50
50
|
"li",
|
|
51
51
|
{
|
|
52
|
-
onMouseEnter:
|
|
53
|
-
onMouseLeave:
|
|
54
|
-
className: `relative ${
|
|
52
|
+
onMouseEnter: u,
|
|
53
|
+
onMouseLeave: f,
|
|
54
|
+
className: `relative ${h}`,
|
|
55
55
|
children: [
|
|
56
56
|
/* @__PURE__ */ b(
|
|
57
57
|
"button",
|
|
@@ -62,46 +62,46 @@ const E = W(null), I = () => {
|
|
|
62
62
|
${s ? "opacity-50 cursor-not-allowed" : "hover:bg-base-200"}
|
|
63
63
|
`,
|
|
64
64
|
children: [
|
|
65
|
-
|
|
66
|
-
/* @__PURE__ */ n("span", { className: "flex-1", children:
|
|
65
|
+
c && /* @__PURE__ */ n("span", { className: "w-4 h-4", children: c }),
|
|
66
|
+
/* @__PURE__ */ n("span", { className: "flex-1", children: e }),
|
|
67
67
|
/* @__PURE__ */ n("svg", { className: "w-4 h-4", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ n("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M9 5l7 7-7 7" }) })
|
|
68
68
|
]
|
|
69
69
|
}
|
|
70
70
|
),
|
|
71
|
-
|
|
71
|
+
m && /* @__PURE__ */ n(
|
|
72
72
|
"ul",
|
|
73
73
|
{
|
|
74
74
|
className: "menu bg-base-100 rounded-box shadow-lg border border-base-300 absolute left-full top-0 min-w-[160px] z-50 p-1",
|
|
75
|
-
onMouseEnter:
|
|
76
|
-
onMouseLeave:
|
|
75
|
+
onMouseEnter: u,
|
|
76
|
+
onMouseLeave: f,
|
|
77
77
|
children: d
|
|
78
78
|
}
|
|
79
79
|
)
|
|
80
80
|
]
|
|
81
81
|
}
|
|
82
82
|
);
|
|
83
|
-
},
|
|
84
|
-
const [
|
|
83
|
+
}, $ = ({ item: e, onSelect: c, onClose: s }) => {
|
|
84
|
+
const [d, h] = g(!1), l = y(null);
|
|
85
85
|
if (e.divider)
|
|
86
86
|
return /* @__PURE__ */ n("li", { className: "divider my-1" });
|
|
87
|
-
const
|
|
88
|
-
e.disabled || e.children && e.children.length > 0 || (
|
|
89
|
-
},
|
|
90
|
-
|
|
91
|
-
},
|
|
92
|
-
|
|
87
|
+
const m = () => {
|
|
88
|
+
e.disabled || e.children && e.children.length > 0 || (c(e.key), s());
|
|
89
|
+
}, o = e.children && e.children.length > 0, a = () => {
|
|
90
|
+
o && (l.current && clearTimeout(l.current), h(!0));
|
|
91
|
+
}, u = () => {
|
|
92
|
+
o && (l.current = setTimeout(() => h(!1), 100));
|
|
93
93
|
};
|
|
94
94
|
return /* @__PURE__ */ b(
|
|
95
95
|
"li",
|
|
96
96
|
{
|
|
97
97
|
onMouseEnter: a,
|
|
98
|
-
onMouseLeave:
|
|
98
|
+
onMouseLeave: u,
|
|
99
99
|
className: "relative",
|
|
100
100
|
children: [
|
|
101
101
|
/* @__PURE__ */ b(
|
|
102
102
|
"button",
|
|
103
103
|
{
|
|
104
|
-
onClick:
|
|
104
|
+
onClick: m,
|
|
105
105
|
disabled: e.disabled,
|
|
106
106
|
className: `
|
|
107
107
|
flex items-center gap-2 w-full px-4 py-2 text-left text-sm
|
|
@@ -111,17 +111,17 @@ const E = W(null), I = () => {
|
|
|
111
111
|
children: [
|
|
112
112
|
e.icon && /* @__PURE__ */ n("span", { className: "w-4 h-4", children: e.icon }),
|
|
113
113
|
/* @__PURE__ */ n("span", { className: "flex-1", children: e.label }),
|
|
114
|
-
|
|
114
|
+
o && /* @__PURE__ */ n("svg", { className: "w-4 h-4", fill: "none", viewBox: "0 0 24 24", stroke: "currentColor", children: /* @__PURE__ */ n("path", { strokeLinecap: "round", strokeLinejoin: "round", strokeWidth: 2, d: "M9 5l7 7-7 7" }) })
|
|
115
115
|
]
|
|
116
116
|
}
|
|
117
117
|
),
|
|
118
|
-
|
|
118
|
+
o && d && /* @__PURE__ */ n(
|
|
119
119
|
"ul",
|
|
120
120
|
{
|
|
121
121
|
className: "menu bg-base-100 rounded-box shadow-lg border border-base-300 absolute left-full top-0 min-w-[160px] z-50 p-1",
|
|
122
122
|
onMouseEnter: a,
|
|
123
|
-
onMouseLeave:
|
|
124
|
-
children: e.children.map((
|
|
123
|
+
onMouseLeave: u,
|
|
124
|
+
children: e.children.map((f) => /* @__PURE__ */ n($, { item: f, onSelect: c, onClose: s }, f.key))
|
|
125
125
|
}
|
|
126
126
|
)
|
|
127
127
|
]
|
|
@@ -129,69 +129,76 @@ const E = W(null), I = () => {
|
|
|
129
129
|
);
|
|
130
130
|
}, O = ({
|
|
131
131
|
children: e,
|
|
132
|
-
items:
|
|
133
|
-
onSelect:
|
|
134
|
-
disabled:
|
|
135
|
-
className:
|
|
132
|
+
items: c,
|
|
133
|
+
onSelect: s,
|
|
134
|
+
disabled: d = !1,
|
|
135
|
+
className: h = ""
|
|
136
136
|
}) => {
|
|
137
|
-
const [
|
|
137
|
+
const [l, m] = g(!1), [o, a] = g({ x: 0, y: 0 }), u = y(null), f = y(null), j = M(
|
|
138
138
|
(r) => {
|
|
139
|
-
if (
|
|
139
|
+
if (d) return;
|
|
140
140
|
r.preventDefault(), r.stopPropagation();
|
|
141
|
-
let
|
|
142
|
-
a({ x:
|
|
141
|
+
let t = r.clientX, i = r.clientY;
|
|
142
|
+
a({ x: t, y: i }), m(!0);
|
|
143
143
|
},
|
|
144
|
-
[
|
|
145
|
-
),
|
|
146
|
-
|
|
147
|
-
}, []),
|
|
144
|
+
[d]
|
|
145
|
+
), p = M(() => {
|
|
146
|
+
m(!1);
|
|
147
|
+
}, []), k = M(
|
|
148
148
|
(r) => {
|
|
149
|
-
|
|
149
|
+
s?.(r);
|
|
150
150
|
},
|
|
151
|
-
[
|
|
151
|
+
[s]
|
|
152
152
|
);
|
|
153
|
-
|
|
154
|
-
if (
|
|
155
|
-
const
|
|
156
|
-
let { x: v, y: w } =
|
|
157
|
-
v +
|
|
153
|
+
E(() => {
|
|
154
|
+
if (l && u.current) {
|
|
155
|
+
const t = u.current.getBoundingClientRect(), i = window.innerWidth, x = window.innerHeight;
|
|
156
|
+
let { x: v, y: w } = o;
|
|
157
|
+
v + t.width > i && (v = i - t.width - 8), w + t.height > x && (w = x - t.height - 8), (v !== o.x || w !== o.y) && a({ x: v, y: w });
|
|
158
158
|
}
|
|
159
|
-
}, [
|
|
160
|
-
if (!
|
|
161
|
-
const r = (
|
|
162
|
-
|
|
163
|
-
},
|
|
164
|
-
|
|
165
|
-
},
|
|
166
|
-
|
|
159
|
+
}, [l, o]), E(() => {
|
|
160
|
+
if (!l) return;
|
|
161
|
+
const r = (x) => {
|
|
162
|
+
u.current && !u.current.contains(x.target) && p();
|
|
163
|
+
}, t = (x) => {
|
|
164
|
+
x.key === "Escape" && p();
|
|
165
|
+
}, i = () => {
|
|
166
|
+
p();
|
|
167
167
|
};
|
|
168
|
-
return document.addEventListener("mousedown", r), document.addEventListener("keydown",
|
|
169
|
-
document.removeEventListener("mousedown", r), document.removeEventListener("keydown",
|
|
168
|
+
return document.addEventListener("mousedown", r), document.addEventListener("keydown", t), document.addEventListener("scroll", i, !0), () => {
|
|
169
|
+
document.removeEventListener("mousedown", r), document.removeEventListener("keydown", t), document.removeEventListener("scroll", i, !0);
|
|
170
170
|
};
|
|
171
|
-
}, [
|
|
172
|
-
const
|
|
173
|
-
|
|
174
|
-
|
|
171
|
+
}, [l, p]);
|
|
172
|
+
const D = (r) => C.Children.map(r, (t) => {
|
|
173
|
+
if (C.isValidElement(t)) {
|
|
174
|
+
const i = t.key != null ? String(t.key) : void 0;
|
|
175
|
+
if (t.type === S || t.type === R)
|
|
176
|
+
return C.cloneElement(t, { _key: i });
|
|
177
|
+
}
|
|
178
|
+
return t;
|
|
179
|
+
}), N = C.Children.toArray(e), W = N[0], P = D(N.slice(1)), T = c && c.length > 0, z = {
|
|
180
|
+
onSelect: k,
|
|
181
|
+
onClose: p
|
|
175
182
|
};
|
|
176
|
-
return /* @__PURE__ */ b(
|
|
177
|
-
/* @__PURE__ */ n("div", { ref:
|
|
178
|
-
|
|
179
|
-
/* @__PURE__ */ n(
|
|
183
|
+
return /* @__PURE__ */ b(B, { children: [
|
|
184
|
+
/* @__PURE__ */ n("div", { ref: f, onContextMenu: j, className: "inline-block", children: W }),
|
|
185
|
+
l && V(
|
|
186
|
+
/* @__PURE__ */ n(L.Provider, { value: z, children: /* @__PURE__ */ n(
|
|
180
187
|
"ul",
|
|
181
188
|
{
|
|
182
|
-
ref:
|
|
183
|
-
className: `menu bg-base-100 rounded-box shadow-lg border border-base-300 min-w-[160px] p-1 fixed z-[9999] ${
|
|
184
|
-
style: { left:
|
|
185
|
-
children:
|
|
189
|
+
ref: u,
|
|
190
|
+
className: `menu bg-base-100 rounded-box shadow-lg border border-base-300 min-w-[160px] p-1 fixed z-[9999] ${h}`,
|
|
191
|
+
style: { left: o.x, top: o.y },
|
|
192
|
+
children: T ? c.map((r) => /* @__PURE__ */ n($, { item: r, onSelect: k, onClose: p }, r.key)) : P
|
|
186
193
|
}
|
|
187
194
|
) }),
|
|
188
195
|
document.body
|
|
189
196
|
)
|
|
190
197
|
] });
|
|
191
198
|
}, Y = Object.assign(O, {
|
|
192
|
-
Item:
|
|
199
|
+
Item: S,
|
|
193
200
|
Divider: H,
|
|
194
|
-
SubMenu:
|
|
201
|
+
SubMenu: R
|
|
195
202
|
});
|
|
196
203
|
export {
|
|
197
204
|
Y as ContextMenu
|