@lobehub/ui 1.21.1 → 1.22.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.
@@ -93,6 +93,10 @@ var ActionIcon = /*#__PURE__*/memo(function (_ref) {
93
93
  if (!title) return actionIconBlock;
94
94
  return /*#__PURE__*/_jsx(Tooltip, {
95
95
  arrow: arrow,
96
+ mouseEnterDelay: 1,
97
+ overlayStyle: {
98
+ pointerEvents: 'none'
99
+ },
96
100
  placement: placement,
97
101
  title: title,
98
102
  children: actionIconBlock
@@ -0,0 +1,24 @@
1
+ /// <reference types="react" />
2
+ import { ActionIconProps } from "..";
3
+ import { DivProps } from "../types";
4
+ export interface ActionIconGroupProps extends DivProps {
5
+ direction?: 'row' | 'column';
6
+ items: ActionIconProps[];
7
+ /**
8
+ * @description The position of the tooltip relative to the target
9
+ * @enum ["top","left","right","bottom","topLeft","topRight","bottomLeft","bottomRight","leftTop","leftBottom","rightTop","rightBottom"]
10
+ */
11
+ placement?: ActionIconProps['placement'];
12
+ /**
13
+ * @description Whether add spotlight background
14
+ * @default true
15
+ */
16
+ spotlight?: boolean;
17
+ /**
18
+ * @description The type of the group
19
+ * @default 'block'
20
+ */
21
+ type?: 'ghost' | 'block' | 'pure';
22
+ }
23
+ declare const ActionIconGroup: import("react").NamedExoticComponent<ActionIconGroupProps>;
24
+ export default ActionIconGroup;
@@ -0,0 +1,37 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
+ var _excluded = ["type", "items", "placement", "spotlight", "direction"];
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 { ActionIcon, Spotlight } from "./..";
7
+ import { memo } from 'react';
8
+ import { useStyles } from "./style";
9
+ import { jsx as _jsx } from "react/jsx-runtime";
10
+ import { jsxs as _jsxs } from "react/jsx-runtime";
11
+ var ActionIconGroup = /*#__PURE__*/memo(function (_ref) {
12
+ var _ref$type = _ref.type,
13
+ type = _ref$type === void 0 ? 'block' : _ref$type,
14
+ items = _ref.items,
15
+ placement = _ref.placement,
16
+ _ref$spotlight = _ref.spotlight,
17
+ spotlight = _ref$spotlight === void 0 ? true : _ref$spotlight,
18
+ _ref$direction = _ref.direction,
19
+ direction = _ref$direction === void 0 ? 'row' : _ref$direction,
20
+ props = _objectWithoutProperties(_ref, _excluded);
21
+ var _useStyles = useStyles({
22
+ direction: direction,
23
+ type: type
24
+ }),
25
+ styles = _useStyles.styles;
26
+ return /*#__PURE__*/_jsxs("div", _objectSpread(_objectSpread({
27
+ className: styles.container
28
+ }, props), {}, {
29
+ children: [spotlight && /*#__PURE__*/_jsx(Spotlight, {}), items.map(function (item, index) {
30
+ return /*#__PURE__*/_jsx(ActionIcon, _objectSpread({
31
+ placement: placement || (direction === 'column' ? 'right' : 'top'),
32
+ size: "small"
33
+ }, item), index);
34
+ })]
35
+ }));
36
+ });
37
+ export default ActionIconGroup;
@@ -0,0 +1,6 @@
1
+ export declare const useStyles: (props?: {
2
+ direction: 'row' | 'column';
3
+ type: 'ghost' | 'block' | 'pure';
4
+ } | undefined) => import("antd-style").ReturnStyles<{
5
+ container: string;
6
+ }>;
@@ -0,0 +1,15 @@
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, _ref2) {
5
+ var css = _ref.css,
6
+ token = _ref.token,
7
+ stylish = _ref.stylish,
8
+ cx = _ref.cx;
9
+ var direction = _ref2.direction,
10
+ type = _ref2.type;
11
+ var typeStylish = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n background-color: ", ";\n border: 1px solid ", ";\n "])), type === 'block' ? token.colorFillTertiary : 'transparent', type === 'block' ? 'transparent' : token.colorBorder);
12
+ return {
13
+ container: cx(type !== 'pure' && typeStylish, stylish.blur, css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n position: relative;\n\n display: flex;\n flex-direction: ", ";\n\n padding: 2px;\n\n border-radius: ", "px;\n "])), direction, token.borderRadius))
14
+ };
15
+ });
@@ -17,22 +17,24 @@ var Avatar = /*#__PURE__*/memo(function (_ref) {
17
17
  shape = _ref$shape === void 0 ? 'circle' : _ref$shape,
18
18
  background = _ref.background,
19
19
  props = _objectWithoutProperties(_ref, _excluded);
20
+ var isImage = avatar && ['/', 'http', 'data:'].some(function (i) {
21
+ return avatar.startsWith(i);
22
+ });
23
+ var isEmoji = avatar && !isImage && /\uD83C[\uDF00-\uDFFF]|\uD83D[\uDC00-\uDE4F]/g.test(avatar);
20
24
  var _useStyles = useStyles({
21
25
  background: background,
22
- size: size
26
+ size: size,
27
+ isEmoji: isEmoji
23
28
  }),
24
29
  styles = _useStyles.styles,
25
30
  cx = _useStyles.cx;
26
- var isImage = avatar && ['/', 'http', 'data:'].some(function (i) {
27
- return avatar.startsWith(i);
28
- });
29
31
  var text = isImage ? title : avatar;
30
32
  return !isImage ? /*#__PURE__*/_jsx(AntAvatar, _objectSpread(_objectSpread({
31
33
  className: cx(styles.avatar, className),
32
34
  shape: shape,
33
35
  size: size
34
36
  }, props), {}, {
35
- children: text === null || text === void 0 ? void 0 : text.toUpperCase().slice(0, 2)
37
+ children: isEmoji ? text : text === null || text === void 0 ? void 0 : text.toUpperCase().slice(0, 2)
36
38
  })) : /*#__PURE__*/_jsx(AntAvatar, _objectSpread({
37
39
  className: cx(styles.avatar, className),
38
40
  shape: shape,
@@ -1,5 +1,6 @@
1
1
  export declare const useStyles: (props?: {
2
2
  background?: string | undefined;
3
+ isEmoji: boolean;
3
4
  size: number;
4
5
  } | undefined) => import("antd-style").ReturnStyles<{
5
6
  avatar: import("antd-style").SerializedStyles;
@@ -6,10 +6,11 @@ export var useStyles = createStyles(function (_ref, _ref2) {
6
6
  var css = _ref.css,
7
7
  token = _ref.token;
8
8
  var background = _ref2.background,
9
- size = _ref2.size;
9
+ size = _ref2.size,
10
+ isEmoji = _ref2.isEmoji;
10
11
  var backgroundColor = background !== null && background !== void 0 ? background : token.colorBgContainer;
11
12
  var color = readableColor(backgroundColor);
12
13
  return {
13
- avatar: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n cursor: pointer;\n\n display: flex;\n align-items: center;\n justify-content: center;\n\n background: ", ";\n border: 1px solid ", ";\n\n > .ant-avatar-string {\n font-size: ", "px;\n font-weight: 700;\n line-height: 1 !important;\n color: ", ";\n }\n\n > * {\n cursor: pointer;\n }\n "])), backgroundColor, background ? 'transparent' : token.colorSplit, size * 0.5, color)
14
+ avatar: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n cursor: pointer;\n\n display: flex;\n align-items: center;\n justify-content: center;\n\n background: ", ";\n border: 1px solid ", ";\n\n > .ant-avatar-string {\n font-size: ", "px;\n font-weight: 700;\n line-height: 1 !important;\n color: ", ";\n }\n\n > * {\n cursor: pointer;\n }\n "])), backgroundColor, background ? 'transparent' : token.colorSplit, size * (isEmoji ? 0.7 : 0.5), color)
14
15
  };
15
16
  });
@@ -1,4 +1,4 @@
1
- export declare const useStyles: (props?: "block" | "pure" | "ghost" | undefined) => import("antd-style").ReturnStyles<{
1
+ export declare const useStyles: (props?: "block" | "ghost" | "pure" | undefined) => import("antd-style").ReturnStyles<{
2
2
  container: string;
3
3
  button: string;
4
4
  lang: string;
@@ -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
+ fill: "none",
8
+ height: iconSize,
9
+ stroke: "currentColor",
10
+ strokeLinecap: "round",
11
+ strokeLinejoin: "round",
12
+ strokeWidth: strokeWidth,
13
+ viewBox: "0 0 24 24",
14
+ width: iconSize,
15
+ xmlns: "http://www.w3.org/2000/svg",
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
+ className: "lucide lucide-chevron-up",
24
+ fill: "none",
25
+ height: iconSize,
26
+ stroke: "currentColor",
27
+ strokeLinecap: "round",
28
+ strokeLinejoin: "round",
29
+ strokeWidth: strokeWidth,
30
+ viewBox: "0 0 24 24",
31
+ width: iconSize,
32
+ xmlns: "http://www.w3.org/2000/svg",
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
+ className: "lucide lucide-chevron-up",
41
+ fill: "none",
42
+ height: iconSize,
43
+ stroke: "currentColor",
44
+ strokeLinecap: "round",
45
+ strokeLinejoin: "round",
46
+ strokeWidth: strokeWidth,
47
+ viewBox: "0 0 24 24",
48
+ width: iconSize,
49
+ xmlns: "http://www.w3.org/2000/svg",
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
+ className: "lucide lucide-chevron-up",
58
+ fill: "none",
59
+ height: iconSize,
60
+ stroke: "currentColor",
61
+ strokeLinecap: "round",
62
+ strokeLinejoin: "round",
63
+ strokeWidth: strokeWidth,
64
+ viewBox: "0 0 24 24",
65
+ width: iconSize,
66
+ xmlns: "http://www.w3.org/2000/svg",
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
+ active?: boolean;
4
+ disabled?: boolean;
5
+ icon?: ReactNode;
6
+ label: ReactNode;
7
+ nested?: boolean;
8
+ selected?: boolean;
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
+ className: cx(styles.item, (_cx = {}, _defineProperty(_cx, styles.selected, selected), _defineProperty(_cx, styles.active, active), _cx)),
46
+ disabled: disabled,
47
+ ref: ref,
48
+ role: "menuitem",
49
+ children: [/*#__PURE__*/_jsxs(Flexbox, {
50
+ gap: 8,
51
+ horizontal: true,
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
+ align: 'center',
62
+ horizontal: true,
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,7 @@
1
+ export declare const useStyles: (props?: unknown) => import("antd-style").ReturnStyles<{
2
+ item: string;
3
+ selected: string;
4
+ active: string;
5
+ arrow: import("antd-style").SerializedStyles;
6
+ kbd: import("antd-style").SerializedStyles;
7
+ }>;
@@ -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\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\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,17 @@
1
+ import MenuItem from './MenuItem';
2
+ import { MenuItemType } from './types';
3
+ export interface ContextMenuProps {
4
+ /**
5
+ * @description Container element for the context menu
6
+ */
7
+ container?: HTMLElement;
8
+ /**
9
+ * @description Items to be displayed in the context menu
10
+ */
11
+ items: MenuItemType[];
12
+ /**
13
+ * @description Label for the context menu
14
+ */
15
+ label?: string;
16
+ }
17
+ export default MenuItem;
@@ -0,0 +1,248 @@
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, autoUpdate, flip, offset, safePolygon, shift, useClick, useDismiss, useFloating, useFloatingNodeId, useFloatingParentNodeId, useFloatingTree, useHover, useInteractions, useListNavigation, useMergeRefs, useRole, useTypeahead } from '@floating-ui/react';
8
+ import { Divider } from 'antd';
9
+ import { forwardRef, useCallback, useEffect, useRef, useState } from 'react';
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
+ context = _useFloating.context;
55
+ var hover = useHover(context, {
56
+ enabled: isNested && allowHover,
57
+ delay: {
58
+ open: 75
59
+ },
60
+ handleClose: safePolygon({
61
+ blockPointerEvents: true
62
+ })
63
+ });
64
+ var click = useClick(context, {
65
+ event: 'mousedown',
66
+ toggle: !isNested || !allowHover,
67
+ ignoreMouse: isNested
68
+ });
69
+ var role = useRole(context, {
70
+ role: 'menu'
71
+ });
72
+ var dismiss = useDismiss(context);
73
+ var listNavigation = useListNavigation(context, {
74
+ listRef: listItemsRef,
75
+ activeIndex: activeIndex,
76
+ nested: isNested,
77
+ onNavigate: setActiveIndex
78
+ });
79
+ var typeahead = useTypeahead(context, {
80
+ enabled: isOpen,
81
+ listRef: listContentRef,
82
+ onMatch: isOpen ? setActiveIndex : undefined,
83
+ activeIndex: activeIndex
84
+ });
85
+ var _useInteractions = useInteractions([hover, click, role, dismiss, listNavigation, typeahead]),
86
+ getReferenceProps = _useInteractions.getReferenceProps,
87
+ getFloatingProps = _useInteractions.getFloatingProps,
88
+ getItemProps = _useInteractions.getItemProps;
89
+
90
+ // Event emitter allows you to communicate across tree components.
91
+ // This effect closes all menus when an item gets clicked anywhere
92
+ // in the tree.
93
+ useEffect(function () {
94
+ if (!tree) return;
95
+ function handleTreeClick() {
96
+ setIsOpen(false);
97
+ }
98
+ function onSubMenuOpen(event) {
99
+ if (event.nodeId !== nodeId && event.parentId === parentId) {
100
+ setIsOpen(false);
101
+ }
102
+ }
103
+ tree.events.on('click', handleTreeClick);
104
+ tree.events.on('menuopen', onSubMenuOpen);
105
+ return function () {
106
+ tree.events.off('click', handleTreeClick);
107
+ tree.events.off('menuopen', onSubMenuOpen);
108
+ };
109
+ }, [tree, nodeId, parentId]);
110
+ useEffect(function () {
111
+ if (isOpen && tree) {
112
+ tree.events.emit('menuopen', {
113
+ parentId: parentId,
114
+ nodeId: nodeId
115
+ });
116
+ }
117
+ }, [tree, isOpen, nodeId, parentId]);
118
+
119
+ // Determine if "hover" logic can run based on the modality of input. This
120
+ // prevents unwanted focus synchronization as menus open and close with
121
+ // keyboard navigation and the cursor is resting on the menu.
122
+ useEffect(function () {
123
+ function onPointerMove(_ref2) {
124
+ var pointerType = _ref2.pointerType;
125
+ if (pointerType !== 'touch') {
126
+ setAllowHover(true);
127
+ }
128
+ }
129
+ function onKeyDown() {
130
+ setAllowHover(false);
131
+ }
132
+ window.addEventListener('pointermove', onPointerMove, {
133
+ once: true,
134
+ capture: true
135
+ });
136
+ window.addEventListener('keydown', onKeyDown, true);
137
+ return function () {
138
+ window.removeEventListener('pointermove', onPointerMove, {
139
+ capture: true
140
+ });
141
+ window.removeEventListener('keydown', onKeyDown, true);
142
+ };
143
+ }, [allowHover]);
144
+ useEffect(function () {
145
+ var timeout;
146
+ function onContextMenu(e) {
147
+ e.preventDefault();
148
+ refs.setPositionReference({
149
+ getBoundingClientRect: function getBoundingClientRect() {
150
+ return {
151
+ width: 0,
152
+ height: 0,
153
+ x: e.clientX,
154
+ y: e.clientY,
155
+ top: e.clientY,
156
+ right: e.clientX,
157
+ bottom: e.clientY,
158
+ left: e.clientX
159
+ };
160
+ }
161
+ });
162
+ setIsOpen(true);
163
+ clearTimeout(timeout);
164
+ allowMouseUpCloseRef.current = false;
165
+ timeout = window.setTimeout(function () {
166
+ allowMouseUpCloseRef.current = true;
167
+ }, 300);
168
+ }
169
+ function onMouseUp() {
170
+ if (allowMouseUpCloseRef.current) {
171
+ setIsOpen(false);
172
+ }
173
+ }
174
+ document.addEventListener('contextmenu', onContextMenu);
175
+ document.addEventListener('mouseup', onMouseUp);
176
+ return function () {
177
+ document.removeEventListener('contextmenu', onContextMenu);
178
+ document.removeEventListener('mouseup', onMouseUp);
179
+ clearTimeout(timeout);
180
+ };
181
+ }, [refs, container]);
182
+ var renderMenuItem = useCallback(function (item, index) {
183
+ // 支持渲染分割线
184
+ if ('type' in item && item.type === 'divider') return /*#__PURE__*/_jsx(Divider, {
185
+ style: {
186
+ margin: '4px 12px',
187
+ minWidth: 'auto',
188
+ width: 'auto'
189
+ }
190
+ });
191
+ var data = item;
192
+ var props = _objectSpread({
193
+ label: data.label,
194
+ key: data.key,
195
+ icon: data.icon,
196
+ shortcut: data.shortcut,
197
+ active: activeIndex === index
198
+ }, getItemProps({
199
+ ref: function ref(node) {
200
+ listItemsRef.current[index] = node;
201
+ },
202
+ onClick: function onClick() {
203
+ var _data$onClick;
204
+ (_data$onClick = data.onClick) === null || _data$onClick === void 0 ? void 0 : _data$onClick.call(data);
205
+ setIsOpen(false);
206
+ },
207
+ onMouseUp: function onMouseUp() {
208
+ var _data$onClick2;
209
+ (_data$onClick2 = data.onClick) === null || _data$onClick2 === void 0 ? void 0 : _data$onClick2.call(data);
210
+ setIsOpen(false);
211
+ }
212
+ }));
213
+ if ('children' in item) {
214
+ return /*#__PURE__*/_jsx(MenuComponent, _objectSpread(_objectSpread({}, props), {}, {
215
+ items: item.children
216
+ }));
217
+ }
218
+ return /*#__PURE__*/_jsx(MenuItem, _objectSpread({}, props));
219
+ }, [activeIndex]);
220
+ var referenceRef = useMergeRefs([refs.setReference, forwardedRef]);
221
+ return /*#__PURE__*/_jsxs(FloatingNode, {
222
+ id: nodeId,
223
+ children: [!label ? null : /*#__PURE__*/_jsx(MenuItem, _objectSpread(_objectSpread({
224
+ label: label,
225
+ nested: isNested,
226
+ ref: referenceRef,
227
+ role: isNested ? 'menuitem' : 'menu'
228
+ }, props), getReferenceProps({
229
+ onClick: function onClick(event) {
230
+ event.stopPropagation();
231
+ }
232
+ }))), /*#__PURE__*/_jsx(FloatingPortal, {
233
+ children: isOpen && /*#__PURE__*/_jsx(FloatingFocusManager, {
234
+ context: context,
235
+ initialFocus: isNested ? -1 : 0,
236
+ modal: false,
237
+ returnFocus: !isNested,
238
+ children: /*#__PURE__*/_jsx("div", _objectSpread(_objectSpread({
239
+ className: styles.container,
240
+ ref: refs.setFloating
241
+ }, getFloatingProps()), {}, {
242
+ children: items === null || items === void 0 ? void 0 : items.map(renderMenuItem)
243
+ }))
244
+ })
245
+ })]
246
+ });
247
+ });
248
+ export default MenuItem;
@@ -0,0 +1,4 @@
1
+ export declare const useStyles: (props?: string | undefined) => import("antd-style").ReturnStyles<{
2
+ container: string;
3
+ button: string;
4
+ }>;
@@ -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,5 @@
1
+ import { MenuItemType } from './menuItem';
2
+ export * from './menuItem';
3
+ export interface MenuProps {
4
+ items: MenuItemType[];
5
+ }
@@ -0,0 +1,2 @@
1
+ export * from "./menuItem";
2
+ export {};
@@ -0,0 +1,21 @@
1
+ import { ReactNode } from 'react';
2
+ interface CommonType {
3
+ icon?: ReactNode;
4
+ key: string;
5
+ label: string;
6
+ onClick?: () => void;
7
+ }
8
+ export interface GeneralItemType extends CommonType {
9
+ danger?: boolean;
10
+ disabled?: boolean;
11
+ shortcut?: ('meta' | 'control' | 'shift' | 'alt' | string)[];
12
+ }
13
+ export interface SubMenuType extends CommonType {
14
+ children: MenuItemType[];
15
+ }
16
+ export interface MenuDividerType {
17
+ dashed?: boolean;
18
+ type: 'divider';
19
+ }
20
+ export declare type MenuItemType = GeneralItemType | SubMenuType | MenuDividerType;
21
+ export {};
@@ -0,0 +1 @@
1
+ export {};
package/es/index.d.ts CHANGED
@@ -1,4 +1,5 @@
1
1
  export { default as ActionIcon, type ActionIconProps, type ActionIconSize } from './ActionIcon';
2
+ export { default as ActionIconGroup, type ActionIconGroupProps } from './ActionIconGroup';
2
3
  export { default as Avatar, type AvatarProps } from './Avatar';
3
4
  export type { ChatMessage, MessageRoleType } from './Chat';
4
5
  export { default as ChatItem, type ChatItemProps } from './ChatItem';
package/es/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  export { default as ActionIcon } from "./ActionIcon";
2
+ export { default as ActionIconGroup } from "./ActionIconGroup";
2
3
  export { default as Avatar } from "./Avatar";
3
4
  export { default as ChatItem } from "./ChatItem";
4
5
  export { default as ChatList } from "./ChatList";
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/ui",
3
- "version": "1.21.1",
3
+ "version": "1.22.0",
4
4
  "description": "Lobe UI is an open-source UI component library for building chatbot web apps",
5
5
  "keywords": [
6
6
  "lobehub",