@lobehub/ui 1.3.0 → 1.5.0
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/es/Avatar/index.d.ts +10 -0
- package/es/Avatar/index.js +61 -0
- package/es/ContextMenu/MenuItem/icons.d.ts +4 -0
- package/es/ContextMenu/MenuItem/icons.js +73 -0
- package/es/ContextMenu/MenuItem/index.d.ts +12 -0
- package/es/ContextMenu/MenuItem/index.js +73 -0
- package/es/ContextMenu/MenuItem/style.d.ts +7 -0
- package/es/ContextMenu/MenuItem/style.js +16 -0
- package/es/ContextMenu/index.d.ts +9 -0
- package/es/ContextMenu/index.js +265 -0
- package/es/ContextMenu/style.d.ts +4 -0
- package/es/ContextMenu/style.js +12 -0
- package/es/ContextMenu/types/index.d.ts +5 -0
- package/es/ContextMenu/types/index.js +2 -0
- package/es/ContextMenu/types/menuItem.d.ts +21 -0
- package/es/ContextMenu/types/menuItem.js +1 -0
- package/es/DraggablePanel/index.d.ts +7 -1
- package/es/DraggablePanel/index.js +6 -7
- package/es/DraggablePanel/utils.d.ts +1 -1
- package/es/EditableMessage/index.d.ts +43 -0
- package/es/EditableMessage/index.js +67 -0
- package/es/List/ListItem/index.d.ts +64 -0
- package/es/List/ListItem/index.js +110 -0
- package/es/List/ListItem/time.d.ts +2 -0
- package/es/List/ListItem/time.js +10 -0
- package/es/List/index.d.ts +5 -0
- package/es/List/index.js +5 -0
- package/es/Markdown/CodeBlock.js +2 -1
- package/es/Markdown/index.js +2 -0
- package/es/Markdown/style.js +1 -1
- package/es/MessageModal/index.d.ts +11 -0
- package/es/MessageModal/index.js +80 -0
- package/es/ThemeProvider/GlobalStyle.js +1 -1
- package/es/index.d.ts +5 -0
- package/es/index.js +5 -0
- package/es/styles/theme/base.js +1 -1
- package/lib/Avatar/index.d.ts +10 -0
- package/lib/Avatar/index.js +74 -0
- package/lib/ContextMenu/MenuItem/icons.d.ts +4 -0
- package/lib/ContextMenu/MenuItem/icons.js +100 -0
- package/lib/ContextMenu/MenuItem/index.d.ts +12 -0
- package/lib/ContextMenu/MenuItem/index.js +72 -0
- package/lib/ContextMenu/MenuItem/style.d.ts +7 -0
- package/lib/ContextMenu/MenuItem/style.js +94 -0
- package/lib/ContextMenu/index.d.ts +9 -0
- package/lib/ContextMenu/index.js +254 -0
- package/lib/ContextMenu/style.d.ts +4 -0
- package/lib/ContextMenu/style.js +88 -0
- package/lib/ContextMenu/types/index.d.ts +5 -0
- package/lib/ContextMenu/types/index.js +19 -0
- package/lib/ContextMenu/types/menuItem.d.ts +21 -0
- package/lib/ContextMenu/types/menuItem.js +17 -0
- package/lib/DraggablePanel/index.d.ts +7 -1
- package/lib/DraggablePanel/index.js +17 -19
- package/lib/DraggablePanel/utils.d.ts +1 -1
- package/lib/EditableMessage/index.d.ts +43 -0
- package/lib/EditableMessage/index.js +96 -0
- package/lib/List/ListItem/index.d.ts +64 -0
- package/lib/List/ListItem/index.js +157 -0
- package/lib/List/ListItem/time.d.ts +2 -0
- package/lib/List/ListItem/time.js +50 -0
- package/lib/List/index.d.ts +5 -0
- package/lib/List/index.js +41 -0
- package/lib/Markdown/CodeBlock.js +5 -1
- package/lib/Markdown/index.js +10 -1
- package/lib/Markdown/style.js +84 -9
- package/lib/MessageModal/index.d.ts +11 -0
- package/lib/MessageModal/index.js +98 -0
- package/lib/ThemeProvider/GlobalStyle.js +0 -18
- package/lib/index.d.ts +5 -0
- package/lib/index.js +15 -0
- package/lib/styles/theme/base.js +1 -1
- package/package.json +4 -1
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import _taggedTemplateLiteral from "@babel/runtime/helpers/esm/taggedTemplateLiteral";
|
|
2
|
+
var _templateObject, _templateObject2;
|
|
3
|
+
import { Avatar as A } from 'antd';
|
|
4
|
+
import { createStyles } from 'antd-style';
|
|
5
|
+
import { Center } from 'react-layout-kit';
|
|
6
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
7
|
+
var useStyles = createStyles(function (_ref) {
|
|
8
|
+
var css = _ref.css,
|
|
9
|
+
token = _ref.token;
|
|
10
|
+
return {
|
|
11
|
+
container: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n cursor: pointer;\n\n > * {\n cursor: pointer;\n }\n "]))),
|
|
12
|
+
border: css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n border: 1px solid ", ";\n "])), token.colorBorder)
|
|
13
|
+
};
|
|
14
|
+
});
|
|
15
|
+
var Avatar = function Avatar(_ref2) {
|
|
16
|
+
var avatar = _ref2.avatar,
|
|
17
|
+
title = _ref2.title,
|
|
18
|
+
_ref2$size = _ref2.size,
|
|
19
|
+
size = _ref2$size === void 0 ? 40 : _ref2$size,
|
|
20
|
+
_ref2$shape = _ref2.shape,
|
|
21
|
+
shape = _ref2$shape === void 0 ? 'circle' : _ref2$shape,
|
|
22
|
+
background = _ref2.background;
|
|
23
|
+
var _useStyles = useStyles(),
|
|
24
|
+
styles = _useStyles.styles,
|
|
25
|
+
theme = _useStyles.theme;
|
|
26
|
+
var backgroundColor = background !== null && background !== void 0 ? background : theme.colorBgContainer;
|
|
27
|
+
var isImage = avatar && ['/', 'http', 'data:'].some(function (i) {
|
|
28
|
+
return avatar.startsWith(i);
|
|
29
|
+
});
|
|
30
|
+
return /*#__PURE__*/_jsx(Center, {
|
|
31
|
+
style: {
|
|
32
|
+
width: size,
|
|
33
|
+
height: size,
|
|
34
|
+
borderRadius: shape === 'circle' ? '50%' : 6,
|
|
35
|
+
backgroundColor: backgroundColor,
|
|
36
|
+
borderWidth: isImage ? 1 : 0
|
|
37
|
+
},
|
|
38
|
+
className: styles.container,
|
|
39
|
+
children: !avatar ? /*#__PURE__*/_jsx(A, {
|
|
40
|
+
shape: shape,
|
|
41
|
+
size: size,
|
|
42
|
+
children: title === null || title === void 0 ? void 0 : title.slice(0, 2)
|
|
43
|
+
}) : isImage ? /*#__PURE__*/_jsx(A, {
|
|
44
|
+
shape: shape,
|
|
45
|
+
size: size,
|
|
46
|
+
src: avatar,
|
|
47
|
+
className: styles.border
|
|
48
|
+
}) : /*#__PURE__*/_jsx(Center, {
|
|
49
|
+
className: styles.border,
|
|
50
|
+
style: {
|
|
51
|
+
width: size,
|
|
52
|
+
height: size,
|
|
53
|
+
fontSize: size / 2,
|
|
54
|
+
borderRadius: shape === 'circle' ? '50%' : 6,
|
|
55
|
+
backgroundColor: backgroundColor
|
|
56
|
+
},
|
|
57
|
+
children: avatar
|
|
58
|
+
})
|
|
59
|
+
});
|
|
60
|
+
};
|
|
61
|
+
export default Avatar;
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
export declare const CommandIcon: () => import("react/jsx-runtime").JSX.Element;
|
|
2
|
+
export declare const ControlIcon: () => import("react/jsx-runtime").JSX.Element;
|
|
3
|
+
export declare const ShiftIcon: () => import("react/jsx-runtime").JSX.Element;
|
|
4
|
+
export declare const AltIcon: () => import("react/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
2
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
var strokeWidth = 2.2;
|
|
4
|
+
var iconSize = '13px';
|
|
5
|
+
export var CommandIcon = function CommandIcon() {
|
|
6
|
+
return /*#__PURE__*/_jsx("svg", {
|
|
7
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
8
|
+
width: iconSize,
|
|
9
|
+
height: iconSize,
|
|
10
|
+
viewBox: "0 0 24 24",
|
|
11
|
+
fill: "none",
|
|
12
|
+
stroke: "currentColor",
|
|
13
|
+
strokeWidth: strokeWidth,
|
|
14
|
+
strokeLinecap: "round",
|
|
15
|
+
strokeLinejoin: "round",
|
|
16
|
+
children: /*#__PURE__*/_jsx("path", {
|
|
17
|
+
d: "M18 3a3 3 0 0 0-3 3v12a3 3 0 0 0 3 3 3 3 0 0 0 3-3 3 3 0 0 0-3-3H6a3 3 0 0 0-3 3 3 3 0 0 0 3 3 3 3 0 0 0 3-3V6a3 3 0 0 0-3-3 3 3 0 0 0-3 3 3 3 0 0 0 3 3h12a3 3 0 0 0 3-3 3 3 0 0 0-3-3z"
|
|
18
|
+
})
|
|
19
|
+
});
|
|
20
|
+
};
|
|
21
|
+
export var ControlIcon = function ControlIcon() {
|
|
22
|
+
return /*#__PURE__*/_jsx("svg", {
|
|
23
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
24
|
+
width: iconSize,
|
|
25
|
+
height: iconSize,
|
|
26
|
+
viewBox: "0 0 24 24",
|
|
27
|
+
fill: "none",
|
|
28
|
+
stroke: "currentColor",
|
|
29
|
+
strokeWidth: strokeWidth,
|
|
30
|
+
strokeLinecap: "round",
|
|
31
|
+
strokeLinejoin: "round",
|
|
32
|
+
className: "lucide lucide-chevron-up",
|
|
33
|
+
children: /*#__PURE__*/_jsx("polyline", {
|
|
34
|
+
points: "18 15 12 9 6 15"
|
|
35
|
+
})
|
|
36
|
+
});
|
|
37
|
+
};
|
|
38
|
+
export var ShiftIcon = function ShiftIcon() {
|
|
39
|
+
return /*#__PURE__*/_jsx("svg", {
|
|
40
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
41
|
+
width: iconSize,
|
|
42
|
+
height: iconSize,
|
|
43
|
+
viewBox: "0 0 24 24",
|
|
44
|
+
fill: "none",
|
|
45
|
+
stroke: "currentColor",
|
|
46
|
+
strokeWidth: strokeWidth,
|
|
47
|
+
strokeLinecap: "round",
|
|
48
|
+
strokeLinejoin: "round",
|
|
49
|
+
className: "lucide lucide-chevron-up",
|
|
50
|
+
children: /*#__PURE__*/_jsx("path", {
|
|
51
|
+
d: "M9 18v-6H5l7-7 7 7h-4v6H9z"
|
|
52
|
+
})
|
|
53
|
+
});
|
|
54
|
+
};
|
|
55
|
+
export var AltIcon = function AltIcon() {
|
|
56
|
+
return /*#__PURE__*/_jsxs("svg", {
|
|
57
|
+
xmlns: "http://www.w3.org/2000/svg",
|
|
58
|
+
width: iconSize,
|
|
59
|
+
height: iconSize,
|
|
60
|
+
viewBox: "0 0 24 24",
|
|
61
|
+
fill: "none",
|
|
62
|
+
stroke: "currentColor",
|
|
63
|
+
strokeWidth: strokeWidth,
|
|
64
|
+
strokeLinecap: "round",
|
|
65
|
+
strokeLinejoin: "round",
|
|
66
|
+
className: "lucide lucide-chevron-up",
|
|
67
|
+
children: [/*#__PURE__*/_jsx("path", {
|
|
68
|
+
d: "M3 3h6l6 18h6"
|
|
69
|
+
}), /*#__PURE__*/_jsx("path", {
|
|
70
|
+
d: "M14 3h7"
|
|
71
|
+
})]
|
|
72
|
+
});
|
|
73
|
+
};
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
interface MenuItemProps {
|
|
3
|
+
label: ReactNode;
|
|
4
|
+
disabled?: boolean;
|
|
5
|
+
active?: boolean;
|
|
6
|
+
selected?: boolean;
|
|
7
|
+
nested?: boolean;
|
|
8
|
+
icon?: ReactNode;
|
|
9
|
+
shortcut?: string[];
|
|
10
|
+
}
|
|
11
|
+
declare const MenuItem: import("react").ForwardRefExoticComponent<MenuItemProps & import("react").RefAttributes<HTMLButtonElement>>;
|
|
12
|
+
export default MenuItem;
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
3
|
+
var _excluded = ["label", "icon", "disabled", "nested", "shortcut", "active", "selected"];
|
|
4
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
5
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
6
|
+
import { ChevronRightIcon } from 'lucide-react';
|
|
7
|
+
import { forwardRef } from 'react';
|
|
8
|
+
import { Flexbox } from 'react-layout-kit';
|
|
9
|
+
import { AltIcon, CommandIcon, ControlIcon, ShiftIcon } from "./icons";
|
|
10
|
+
import { useStyles } from "./style";
|
|
11
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
12
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
13
|
+
var KEYBOARD_ICON_MAP = {
|
|
14
|
+
meta: /*#__PURE__*/_jsx(CommandIcon, {}),
|
|
15
|
+
control: /*#__PURE__*/_jsx(ControlIcon, {}),
|
|
16
|
+
shift: /*#__PURE__*/_jsx(ShiftIcon, {}),
|
|
17
|
+
alt: /*#__PURE__*/_jsx(AltIcon, {}),
|
|
18
|
+
enter: '↵'
|
|
19
|
+
};
|
|
20
|
+
var CODE_MAP = {
|
|
21
|
+
meta: 'meta',
|
|
22
|
+
command: 'meta',
|
|
23
|
+
cmd: 'meta',
|
|
24
|
+
ctl: 'control',
|
|
25
|
+
control: 'control',
|
|
26
|
+
shift: 'shift',
|
|
27
|
+
alt: 'alt'
|
|
28
|
+
};
|
|
29
|
+
var MenuItem = /*#__PURE__*/forwardRef(function (_ref, ref) {
|
|
30
|
+
var _cx;
|
|
31
|
+
var label = _ref.label,
|
|
32
|
+
icon = _ref.icon,
|
|
33
|
+
disabled = _ref.disabled,
|
|
34
|
+
nested = _ref.nested,
|
|
35
|
+
shortcut = _ref.shortcut,
|
|
36
|
+
active = _ref.active,
|
|
37
|
+
selected = _ref.selected,
|
|
38
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
39
|
+
var _useStyles = useStyles(),
|
|
40
|
+
styles = _useStyles.styles,
|
|
41
|
+
cx = _useStyles.cx;
|
|
42
|
+
return /*#__PURE__*/_jsxs("button", _objectSpread(_objectSpread({
|
|
43
|
+
type: 'button'
|
|
44
|
+
}, props), {}, {
|
|
45
|
+
ref: ref,
|
|
46
|
+
role: "menuitem",
|
|
47
|
+
disabled: disabled,
|
|
48
|
+
className: cx(styles.item, (_cx = {}, _defineProperty(_cx, styles.selected, selected), _defineProperty(_cx, styles.active, active), _cx)),
|
|
49
|
+
children: [/*#__PURE__*/_jsxs(Flexbox, {
|
|
50
|
+
horizontal: true,
|
|
51
|
+
gap: 8,
|
|
52
|
+
children: [icon && /*#__PURE__*/_jsx("span", {
|
|
53
|
+
children: icon
|
|
54
|
+
}), label]
|
|
55
|
+
}), nested ? /*#__PURE__*/_jsx("span", {
|
|
56
|
+
"aria-hidden": true,
|
|
57
|
+
children: /*#__PURE__*/_jsx(ChevronRightIcon, {
|
|
58
|
+
className: styles.arrow
|
|
59
|
+
})
|
|
60
|
+
}) : shortcut ? /*#__PURE__*/_jsx(Flexbox, {
|
|
61
|
+
horizontal: true,
|
|
62
|
+
align: 'center',
|
|
63
|
+
children: shortcut.map(function (c) {
|
|
64
|
+
var code = CODE_MAP[c.toLowerCase()];
|
|
65
|
+
return /*#__PURE__*/_jsx("kbd", {
|
|
66
|
+
className: styles.kbd,
|
|
67
|
+
children: code ? KEYBOARD_ICON_MAP[code] : c.toUpperCase()
|
|
68
|
+
}, c);
|
|
69
|
+
})
|
|
70
|
+
}) : null]
|
|
71
|
+
}));
|
|
72
|
+
});
|
|
73
|
+
export default MenuItem;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import _taggedTemplateLiteral from "@babel/runtime/helpers/esm/taggedTemplateLiteral";
|
|
2
|
+
var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5;
|
|
3
|
+
import { createStyles } from 'antd-style';
|
|
4
|
+
export var useStyles = createStyles(function (_ref, prefixCls) {
|
|
5
|
+
var css = _ref.css,
|
|
6
|
+
cx = _ref.cx,
|
|
7
|
+
token = _ref.token;
|
|
8
|
+
var selected = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n font-weight: bold;\n color: ", ";\n background: ", ";\n &:hover {\n color: ", ";\n background: ", ";\n }\n "])), token.colorPrimaryText, token.colorPrimaryBg, token.colorPrimaryTextHover, token.colorPrimaryBgHover);
|
|
9
|
+
return {
|
|
10
|
+
item: cx("".concat(prefixCls, "-item"), css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n all: unset;\n\n user-select: none;\n scroll-margin: 50px;\n\n display: flex;\n align-items: center;\n justify-content: space-between;\n\n box-sizing: inherit;\n width: 100%;\n padding: 12px 10px;\n\n font-family: ", ";\n font-weight: normal;\n line-height: 1;\n color: ", ";\n\n background: transparent;\n border-radius: 5px;\n &:hover {\n background: ", ";\n }\n "])), token.fontFamily, token.colorText, token.colorFillTertiary)),
|
|
11
|
+
selected: cx("".concat(prefixCls, "-item-selected"), selected),
|
|
12
|
+
active: cx("".concat(prefixCls, "-item-active"), css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n background: ", ";\n "])), token.colorFillTertiary)),
|
|
13
|
+
arrow: css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n color: ", ";\n "])), token.colorTextTertiary),
|
|
14
|
+
kbd: css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n display: flex;\n align-items: center;\n justify-content: center;\n\n width: 18px;\n height: 20px;\n\n font-family: ", ";\n font-size: 14px;\n color: ", ";\n\n border-radius: 2px;\n "])), token.fontFamily, token.colorTextQuaternary)
|
|
15
|
+
};
|
|
16
|
+
});
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { HTMLProps } from 'react';
|
|
2
|
+
import { MenuItemType } from './types';
|
|
3
|
+
export interface ContextMenuProps {
|
|
4
|
+
label?: string;
|
|
5
|
+
items: MenuItemType[];
|
|
6
|
+
container?: HTMLElement;
|
|
7
|
+
}
|
|
8
|
+
declare const ContextMenu: import("react").ForwardRefExoticComponent<Omit<ContextMenuProps & HTMLProps<HTMLButtonElement>, "ref"> & import("react").RefAttributes<HTMLButtonElement>>;
|
|
9
|
+
export default ContextMenu;
|
|
@@ -0,0 +1,265 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
|
|
3
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
|
|
4
|
+
var _excluded = ["items", "label", "container"];
|
|
5
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
6
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
7
|
+
import { FloatingFocusManager, FloatingNode, FloatingPortal, FloatingTree, autoUpdate, flip, offset, safePolygon, shift, useClick, useDismiss, useFloating, useFloatingNodeId, useFloatingParentNodeId, useFloatingTree, useHover, useInteractions, useListNavigation, useMergeRefs, useRole, useTypeahead } from '@floating-ui/react';
|
|
8
|
+
import { forwardRef, useCallback, useEffect, useRef, useState } from 'react';
|
|
9
|
+
import { Divider } from 'antd';
|
|
10
|
+
import MenuItem from "./MenuItem";
|
|
11
|
+
import { useStyles } from "./style";
|
|
12
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
13
|
+
import { jsxs as _jsxs } from "react/jsx-runtime";
|
|
14
|
+
var MenuComponent = /*#__PURE__*/forwardRef(function (_ref, forwardedRef) {
|
|
15
|
+
var items = _ref.items,
|
|
16
|
+
label = _ref.label,
|
|
17
|
+
container = _ref.container,
|
|
18
|
+
props = _objectWithoutProperties(_ref, _excluded);
|
|
19
|
+
var _useStyles = useStyles(),
|
|
20
|
+
styles = _useStyles.styles;
|
|
21
|
+
var _useState = useState(false),
|
|
22
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
23
|
+
isOpen = _useState2[0],
|
|
24
|
+
setIsOpen = _useState2[1];
|
|
25
|
+
var _useState3 = useState(null),
|
|
26
|
+
_useState4 = _slicedToArray(_useState3, 2),
|
|
27
|
+
activeIndex = _useState4[0],
|
|
28
|
+
setActiveIndex = _useState4[1];
|
|
29
|
+
var _useState5 = useState(false),
|
|
30
|
+
_useState6 = _slicedToArray(_useState5, 2),
|
|
31
|
+
allowHover = _useState6[0],
|
|
32
|
+
setAllowHover = _useState6[1];
|
|
33
|
+
var listItemsRef = useRef([]);
|
|
34
|
+
var listContentRef = useRef(items.map(function (item) {
|
|
35
|
+
return item.label;
|
|
36
|
+
}));
|
|
37
|
+
var allowMouseUpCloseRef = useRef(false);
|
|
38
|
+
var tree = useFloatingTree();
|
|
39
|
+
var nodeId = useFloatingNodeId();
|
|
40
|
+
var parentId = useFloatingParentNodeId();
|
|
41
|
+
var isNested = parentId !== null;
|
|
42
|
+
var _useFloating = useFloating({
|
|
43
|
+
nodeId: nodeId,
|
|
44
|
+
open: isOpen,
|
|
45
|
+
onOpenChange: setIsOpen,
|
|
46
|
+
placement: isNested ? 'right-start' : 'bottom-start',
|
|
47
|
+
middleware: [offset({
|
|
48
|
+
mainAxis: isNested ? 0 : 4,
|
|
49
|
+
alignmentAxis: isNested ? -4 : 0
|
|
50
|
+
}), flip(), shift()],
|
|
51
|
+
whileElementsMounted: autoUpdate
|
|
52
|
+
}),
|
|
53
|
+
refs = _useFloating.refs,
|
|
54
|
+
floatingStyles = _useFloating.floatingStyles,
|
|
55
|
+
context = _useFloating.context;
|
|
56
|
+
var hover = useHover(context, {
|
|
57
|
+
enabled: isNested && allowHover,
|
|
58
|
+
delay: {
|
|
59
|
+
open: 75
|
|
60
|
+
},
|
|
61
|
+
handleClose: safePolygon({
|
|
62
|
+
blockPointerEvents: true
|
|
63
|
+
})
|
|
64
|
+
});
|
|
65
|
+
var click = useClick(context, {
|
|
66
|
+
event: 'mousedown',
|
|
67
|
+
toggle: !isNested || !allowHover,
|
|
68
|
+
ignoreMouse: isNested
|
|
69
|
+
});
|
|
70
|
+
var role = useRole(context, {
|
|
71
|
+
role: 'menu'
|
|
72
|
+
});
|
|
73
|
+
var dismiss = useDismiss(context);
|
|
74
|
+
var listNavigation = useListNavigation(context, {
|
|
75
|
+
listRef: listItemsRef,
|
|
76
|
+
activeIndex: activeIndex,
|
|
77
|
+
nested: isNested,
|
|
78
|
+
onNavigate: setActiveIndex
|
|
79
|
+
});
|
|
80
|
+
var typeahead = useTypeahead(context, {
|
|
81
|
+
enabled: isOpen,
|
|
82
|
+
listRef: listContentRef,
|
|
83
|
+
onMatch: isOpen ? setActiveIndex : undefined,
|
|
84
|
+
activeIndex: activeIndex
|
|
85
|
+
});
|
|
86
|
+
var _useInteractions = useInteractions([hover, click, role, dismiss, listNavigation, typeahead]),
|
|
87
|
+
getReferenceProps = _useInteractions.getReferenceProps,
|
|
88
|
+
getFloatingProps = _useInteractions.getFloatingProps,
|
|
89
|
+
getItemProps = _useInteractions.getItemProps;
|
|
90
|
+
|
|
91
|
+
// Event emitter allows you to communicate across tree components.
|
|
92
|
+
// This effect closes all menus when an item gets clicked anywhere
|
|
93
|
+
// in the tree.
|
|
94
|
+
useEffect(function () {
|
|
95
|
+
if (!tree) return;
|
|
96
|
+
function handleTreeClick() {
|
|
97
|
+
setIsOpen(false);
|
|
98
|
+
}
|
|
99
|
+
function onSubMenuOpen(event) {
|
|
100
|
+
if (event.nodeId !== nodeId && event.parentId === parentId) {
|
|
101
|
+
setIsOpen(false);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
tree.events.on('click', handleTreeClick);
|
|
105
|
+
tree.events.on('menuopen', onSubMenuOpen);
|
|
106
|
+
return function () {
|
|
107
|
+
tree.events.off('click', handleTreeClick);
|
|
108
|
+
tree.events.off('menuopen', onSubMenuOpen);
|
|
109
|
+
};
|
|
110
|
+
}, [tree, nodeId, parentId]);
|
|
111
|
+
useEffect(function () {
|
|
112
|
+
if (isOpen && tree) {
|
|
113
|
+
tree.events.emit('menuopen', {
|
|
114
|
+
parentId: parentId,
|
|
115
|
+
nodeId: nodeId
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
}, [tree, isOpen, nodeId, parentId]);
|
|
119
|
+
|
|
120
|
+
// Determine if "hover" logic can run based on the modality of input. This
|
|
121
|
+
// prevents unwanted focus synchronization as menus open and close with
|
|
122
|
+
// keyboard navigation and the cursor is resting on the menu.
|
|
123
|
+
useEffect(function () {
|
|
124
|
+
function onPointerMove(_ref2) {
|
|
125
|
+
var pointerType = _ref2.pointerType;
|
|
126
|
+
if (pointerType !== 'touch') {
|
|
127
|
+
setAllowHover(true);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
function onKeyDown() {
|
|
131
|
+
setAllowHover(false);
|
|
132
|
+
}
|
|
133
|
+
window.addEventListener('pointermove', onPointerMove, {
|
|
134
|
+
once: true,
|
|
135
|
+
capture: true
|
|
136
|
+
});
|
|
137
|
+
window.addEventListener('keydown', onKeyDown, true);
|
|
138
|
+
return function () {
|
|
139
|
+
window.removeEventListener('pointermove', onPointerMove, {
|
|
140
|
+
capture: true
|
|
141
|
+
});
|
|
142
|
+
window.removeEventListener('keydown', onKeyDown, true);
|
|
143
|
+
};
|
|
144
|
+
}, [allowHover]);
|
|
145
|
+
useEffect(function () {
|
|
146
|
+
var timeout;
|
|
147
|
+
function onContextMenu(e) {
|
|
148
|
+
e.preventDefault();
|
|
149
|
+
refs.setPositionReference({
|
|
150
|
+
getBoundingClientRect: function getBoundingClientRect() {
|
|
151
|
+
return {
|
|
152
|
+
width: 0,
|
|
153
|
+
height: 0,
|
|
154
|
+
x: e.clientX,
|
|
155
|
+
y: e.clientY,
|
|
156
|
+
top: e.clientY,
|
|
157
|
+
right: e.clientX,
|
|
158
|
+
bottom: e.clientY,
|
|
159
|
+
left: e.clientX
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
setIsOpen(true);
|
|
164
|
+
clearTimeout(timeout);
|
|
165
|
+
allowMouseUpCloseRef.current = false;
|
|
166
|
+
timeout = window.setTimeout(function () {
|
|
167
|
+
allowMouseUpCloseRef.current = true;
|
|
168
|
+
}, 300);
|
|
169
|
+
}
|
|
170
|
+
function onMouseUp() {
|
|
171
|
+
if (allowMouseUpCloseRef.current) {
|
|
172
|
+
setIsOpen(false);
|
|
173
|
+
}
|
|
174
|
+
}
|
|
175
|
+
document.addEventListener('contextmenu', onContextMenu);
|
|
176
|
+
document.addEventListener('mouseup', onMouseUp);
|
|
177
|
+
return function () {
|
|
178
|
+
document.removeEventListener('contextmenu', onContextMenu);
|
|
179
|
+
document.removeEventListener('mouseup', onMouseUp);
|
|
180
|
+
clearTimeout(timeout);
|
|
181
|
+
};
|
|
182
|
+
}, [refs, container]);
|
|
183
|
+
var renderMenuItem = useCallback(function (item, index) {
|
|
184
|
+
// 支持渲染分割线
|
|
185
|
+
if ('type' in item && item.type === 'divider') return /*#__PURE__*/_jsx(Divider, {
|
|
186
|
+
style: {
|
|
187
|
+
margin: '4px 12px',
|
|
188
|
+
minWidth: 'auto',
|
|
189
|
+
width: 'auto'
|
|
190
|
+
}
|
|
191
|
+
});
|
|
192
|
+
var data = item;
|
|
193
|
+
var props = _objectSpread({
|
|
194
|
+
label: data.label,
|
|
195
|
+
key: data.key,
|
|
196
|
+
icon: data.icon,
|
|
197
|
+
shortcut: data.shortcut,
|
|
198
|
+
active: activeIndex === index
|
|
199
|
+
}, getItemProps({
|
|
200
|
+
ref: function ref(node) {
|
|
201
|
+
listItemsRef.current[index] = node;
|
|
202
|
+
},
|
|
203
|
+
onClick: function onClick() {
|
|
204
|
+
var _data$onClick;
|
|
205
|
+
(_data$onClick = data.onClick) === null || _data$onClick === void 0 ? void 0 : _data$onClick.call(data);
|
|
206
|
+
setIsOpen(false);
|
|
207
|
+
},
|
|
208
|
+
onMouseUp: function onMouseUp() {
|
|
209
|
+
var _data$onClick2;
|
|
210
|
+
(_data$onClick2 = data.onClick) === null || _data$onClick2 === void 0 ? void 0 : _data$onClick2.call(data);
|
|
211
|
+
setIsOpen(false);
|
|
212
|
+
}
|
|
213
|
+
}));
|
|
214
|
+
if ('children' in item) {
|
|
215
|
+
return /*#__PURE__*/_jsx(MenuComponent, _objectSpread(_objectSpread({}, props), {}, {
|
|
216
|
+
items: item.children
|
|
217
|
+
}));
|
|
218
|
+
}
|
|
219
|
+
return /*#__PURE__*/_jsx(MenuItem, _objectSpread({}, props));
|
|
220
|
+
}, [activeIndex]);
|
|
221
|
+
var referenceRef = useMergeRefs([refs.setReference, forwardedRef]);
|
|
222
|
+
return /*#__PURE__*/_jsxs(FloatingNode, {
|
|
223
|
+
id: nodeId,
|
|
224
|
+
children: [!label ? null : /*#__PURE__*/_jsx(MenuItem, _objectSpread(_objectSpread({
|
|
225
|
+
ref: referenceRef,
|
|
226
|
+
nested: isNested,
|
|
227
|
+
label: label
|
|
228
|
+
// Indicates this is a nested <Menu /> acting as a <MenuItem />.
|
|
229
|
+
,
|
|
230
|
+
role: isNested ? 'menuitem' : 'menu'
|
|
231
|
+
}, props), getReferenceProps({
|
|
232
|
+
onClick: function onClick(event) {
|
|
233
|
+
event.stopPropagation();
|
|
234
|
+
}
|
|
235
|
+
}))), /*#__PURE__*/_jsx(FloatingPortal, {
|
|
236
|
+
children: isOpen && /*#__PURE__*/_jsx(FloatingFocusManager, {
|
|
237
|
+
context: context
|
|
238
|
+
// Prevent outside content interference.
|
|
239
|
+
,
|
|
240
|
+
modal: false
|
|
241
|
+
// Only initially focus the root floating menu.
|
|
242
|
+
,
|
|
243
|
+
initialFocus: isNested ? -1 : 0
|
|
244
|
+
// Only return focus to the root menu's reference when menus close.
|
|
245
|
+
,
|
|
246
|
+
returnFocus: !isNested,
|
|
247
|
+
children: /*#__PURE__*/_jsx("div", _objectSpread(_objectSpread({
|
|
248
|
+
ref: refs.setFloating,
|
|
249
|
+
className: styles.container,
|
|
250
|
+
style: floatingStyles
|
|
251
|
+
}, getFloatingProps()), {}, {
|
|
252
|
+
children: items === null || items === void 0 ? void 0 : items.map(renderMenuItem)
|
|
253
|
+
}))
|
|
254
|
+
})
|
|
255
|
+
})]
|
|
256
|
+
});
|
|
257
|
+
});
|
|
258
|
+
var ContextMenu = /*#__PURE__*/forwardRef(function (props, ref) {
|
|
259
|
+
return /*#__PURE__*/_jsx(FloatingTree, {
|
|
260
|
+
children: /*#__PURE__*/_jsx(MenuComponent, _objectSpread(_objectSpread({}, props), {}, {
|
|
261
|
+
ref: ref
|
|
262
|
+
}))
|
|
263
|
+
});
|
|
264
|
+
});
|
|
265
|
+
export default ContextMenu;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import _taggedTemplateLiteral from "@babel/runtime/helpers/esm/taggedTemplateLiteral";
|
|
2
|
+
var _templateObject, _templateObject2;
|
|
3
|
+
import { createStyles } from 'antd-style';
|
|
4
|
+
export var useStyles = createStyles(function (_ref, prefixCls) {
|
|
5
|
+
var css = _ref.css,
|
|
6
|
+
cx = _ref.cx,
|
|
7
|
+
token = _ref.token;
|
|
8
|
+
return {
|
|
9
|
+
container: cx(prefixCls, css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n user-select: none;\n scrollbar-width: none;\n\n overflow-y: auto;\n overscroll-behavior: contain;\n\n box-sizing: border-box;\n width: 200px;\n padding: 5px;\n\n font-size: ", ";\n\n background: ", ";\n border: 1px solid ", ";\n border-radius: 8px;\n outline: 0;\n box-shadow: ", ";\n\n &::-webkit-scrollbar {\n display: none;\n }\n "])), token.fontSize, token.colorBgContainer, token.colorBorder, token.boxShadowSecondary)),
|
|
10
|
+
button: cx("".concat(prefixCls, "-button"), css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n all: unset;\n\n cursor: default;\n user-select: none;\n\n padding: 12px 10px;\n\n font-size: ", "px;\n line-height: 1;\n color: ", ";\n\n background: ", ";\n border: 1px solid ", ";\n border-radius: ", "px;\n\n -webkit-tap-highlight-color: transparent;\n\n &:hover {\n background: ", ";\n border-color: transparent;\n }\n\n &:focus-visible {\n border-color: ", ";\n box-shadow: 0 0 0 2px ", ";\n }\n "])), token.fontSize, token.colorText, token.colorBgContainer, token.colorBorder, token.borderRadius, token.colorPrimaryBg, token.colorPrimary, token.colorPrimaryBg))
|
|
11
|
+
};
|
|
12
|
+
});
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { ReactNode } from 'react';
|
|
2
|
+
interface CommonType {
|
|
3
|
+
key: string;
|
|
4
|
+
label: string;
|
|
5
|
+
onClick?: () => void;
|
|
6
|
+
icon?: ReactNode;
|
|
7
|
+
}
|
|
8
|
+
export interface GeneralItemType extends CommonType {
|
|
9
|
+
disabled?: boolean;
|
|
10
|
+
danger?: boolean;
|
|
11
|
+
shortcut?: ('meta' | 'control' | 'shift' | 'alt' | string)[];
|
|
12
|
+
}
|
|
13
|
+
export interface SubMenuType extends CommonType {
|
|
14
|
+
children: MenuItemType[];
|
|
15
|
+
}
|
|
16
|
+
export interface MenuDividerType {
|
|
17
|
+
type: 'divider';
|
|
18
|
+
dashed?: boolean;
|
|
19
|
+
}
|
|
20
|
+
export declare type MenuItemType = GeneralItemType | SubMenuType | MenuDividerType;
|
|
21
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
/// <reference types="react" />
|
|
2
1
|
import type { NumberSize, Size } from 're-resizable';
|
|
2
|
+
import { ReactNode } from 'react';
|
|
3
3
|
import type { Props as RndProps } from 'react-rnd';
|
|
4
4
|
import { DivProps } from "../types";
|
|
5
5
|
export declare type placementType = 'right' | 'left' | 'top' | 'bottom';
|
|
@@ -81,6 +81,12 @@ export interface DraggablePanelProps extends DivProps {
|
|
|
81
81
|
* @type CSSProperties
|
|
82
82
|
*/
|
|
83
83
|
hanlderStyle?: React.CSSProperties;
|
|
84
|
+
children: ReactNode;
|
|
85
|
+
className?: string;
|
|
86
|
+
classNames?: {
|
|
87
|
+
handle?: string;
|
|
88
|
+
content?: string;
|
|
89
|
+
};
|
|
84
90
|
}
|
|
85
91
|
declare const DraggablePanel: import("react").NamedExoticComponent<DraggablePanelProps>;
|
|
86
92
|
export default DraggablePanel;
|
|
@@ -39,7 +39,9 @@ var DraggablePanel = /*#__PURE__*/memo(function (_ref) {
|
|
|
39
39
|
className = _ref.className,
|
|
40
40
|
showHandlerWhenUnexpand = _ref.showHandlerWhenUnexpand,
|
|
41
41
|
destroyOnClose = _ref.destroyOnClose,
|
|
42
|
-
hanlderStyle = _ref.hanlderStyle
|
|
42
|
+
hanlderStyle = _ref.hanlderStyle,
|
|
43
|
+
_ref$classNames = _ref.classNames,
|
|
44
|
+
classNames = _ref$classNames === void 0 ? {} : _ref$classNames;
|
|
43
45
|
var ref = useRef(null);
|
|
44
46
|
var isHovering = useHover(ref);
|
|
45
47
|
var isVertical = placement === 'top' || placement === 'bottom';
|
|
@@ -132,13 +134,10 @@ var DraggablePanel = /*#__PURE__*/memo(function (_ref) {
|
|
|
132
134
|
}, [styles, placement]),
|
|
133
135
|
Arrow = _useMemo.Arrow,
|
|
134
136
|
arrowPlacement = _useMemo.className;
|
|
135
|
-
var handler =
|
|
136
|
-
/*#__PURE__*/
|
|
137
|
-
// @ts-ignore
|
|
138
|
-
_jsx(Center
|
|
137
|
+
var handler = /*#__PURE__*/_jsx(Center
|
|
139
138
|
// @ts-ignore
|
|
140
139
|
, {
|
|
141
|
-
className: cx(styles["toggle".concat(arrowPlacement)]),
|
|
140
|
+
className: cx(styles["toggle".concat(arrowPlacement)], classNames.handle),
|
|
142
141
|
style: {
|
|
143
142
|
opacity: isExpand ? !pin ? 0 : undefined : showHandlerWhenUnexpand ? 1 : 0
|
|
144
143
|
},
|
|
@@ -164,7 +163,7 @@ var DraggablePanel = /*#__PURE__*/memo(function (_ref) {
|
|
|
164
163
|
// @ts-ignore
|
|
165
164
|
_jsx(Resizable, _objectSpread(_objectSpread({}, sizeProps), {}, {
|
|
166
165
|
style: style,
|
|
167
|
-
className: styles.panel,
|
|
166
|
+
className: cx(styles.panel, classNames.content),
|
|
168
167
|
enable: canResizing ? resizing : undefined,
|
|
169
168
|
handleClasses: resizeHandleClassNames,
|
|
170
169
|
onResizeStop: function onResizeStop(e, direction, ref, delta) {
|
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
import { placementType } from './index';
|
|
2
|
-
export declare const revesePlacement: (placement: placementType) => "
|
|
2
|
+
export declare const revesePlacement: (placement: placementType) => "left" | "right" | "bottom" | "top";
|