@lobehub/ui 1.2.0 → 1.4.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.
Files changed (219) hide show
  1. package/es/ActionIcon/index.d.ts +10 -5
  2. package/es/ActionIcon/index.js +15 -7
  3. package/es/ActionIcon/style.d.ts +4 -1
  4. package/es/ActionIcon/style.js +5 -3
  5. package/es/Avatar/index.d.ts +10 -0
  6. package/es/Avatar/index.js +61 -0
  7. package/es/ContextMenu/MenuItem/icons.d.ts +4 -0
  8. package/es/ContextMenu/MenuItem/icons.js +73 -0
  9. package/es/ContextMenu/MenuItem/index.d.ts +12 -0
  10. package/es/ContextMenu/MenuItem/index.js +73 -0
  11. package/es/ContextMenu/MenuItem/style.d.ts +7 -0
  12. package/es/ContextMenu/MenuItem/style.js +16 -0
  13. package/es/ContextMenu/index.d.ts +9 -0
  14. package/es/ContextMenu/index.js +265 -0
  15. package/es/ContextMenu/style.d.ts +4 -0
  16. package/es/ContextMenu/style.js +12 -0
  17. package/es/ContextMenu/types/index.d.ts +5 -0
  18. package/es/ContextMenu/types/index.js +2 -0
  19. package/es/ContextMenu/types/menuItem.d.ts +21 -0
  20. package/es/CopyButton/index.d.ts +34 -0
  21. package/es/CopyButton/index.js +49 -0
  22. package/es/DraggablePanel/index.d.ts +10 -4
  23. package/es/DraggablePanel/index.js +10 -11
  24. package/es/DraggablePanel/style.js +2 -2
  25. package/es/EditableText/ControlInput.d.ts +9 -0
  26. package/es/EditableText/ControlInput.js +88 -0
  27. package/es/EditableText/index.d.ts +5 -0
  28. package/es/EditableText/index.js +35 -0
  29. package/es/Highlighter/SyntaxHighlighter/Prism.d.ts +7 -0
  30. package/es/Highlighter/SyntaxHighlighter/Prism.js +40 -0
  31. package/es/Highlighter/SyntaxHighlighter/index.d.ts +5 -0
  32. package/es/Highlighter/SyntaxHighlighter/index.js +58 -0
  33. package/es/Highlighter/SyntaxHighlighter/style.d.ts +5 -0
  34. package/es/Highlighter/SyntaxHighlighter/style.js +15 -0
  35. package/es/Highlighter/index.d.ts +36 -0
  36. package/es/Highlighter/index.js +42 -0
  37. package/es/Highlighter/style.d.ts +5 -0
  38. package/es/Highlighter/style.js +18 -0
  39. package/es/Icon/index.d.ts +2 -3
  40. package/es/Icon/index.js +2 -2
  41. package/es/List/ListItem/index.d.ts +64 -0
  42. package/es/List/ListItem/index.js +110 -0
  43. package/es/List/ListItem/time.d.ts +2 -0
  44. package/es/List/ListItem/time.js +10 -0
  45. package/es/List/index.d.ts +5 -0
  46. package/es/List/index.js +5 -0
  47. package/es/Logo/Divider.d.ts +3 -3
  48. package/es/Logo/Divider.js +6 -4
  49. package/es/Logo/Logo3D.d.ts +3 -3
  50. package/es/Logo/Logo3D.js +6 -4
  51. package/es/Logo/LogoFlat.d.ts +3 -3
  52. package/es/Logo/LogoFlat.js +6 -4
  53. package/es/Logo/LogoHighContrast.d.ts +3 -3
  54. package/es/Logo/LogoHighContrast.js +6 -4
  55. package/es/Logo/LogoText.d.ts +3 -3
  56. package/es/Logo/LogoText.js +6 -4
  57. package/es/Logo/index.d.ts +3 -3
  58. package/es/Logo/index.js +5 -5
  59. package/es/Logo/style.js +1 -1
  60. package/es/Markdown/Code.d.ts +3 -0
  61. package/es/Markdown/Code.js +12 -0
  62. package/es/Markdown/CodeBlock.d.ts +3 -0
  63. package/es/Markdown/CodeBlock.js +27 -0
  64. package/es/Markdown/index.d.ts +13 -0
  65. package/es/Markdown/index.js +28 -0
  66. package/es/Markdown/style.d.ts +4 -0
  67. package/es/Markdown/style.js +12 -0
  68. package/es/MessageInput/index.d.ts +35 -0
  69. package/es/MessageInput/index.js +63 -0
  70. package/es/SearchBar/index.d.ts +5 -0
  71. package/es/SearchBar/index.js +27 -0
  72. package/es/SideNav/index.d.ts +6 -6
  73. package/es/SideNav/index.js +17 -20
  74. package/es/SideNav/style.d.ts +1 -0
  75. package/es/SideNav/style.js +8 -0
  76. package/es/Snippet/index.d.ts +29 -0
  77. package/es/Snippet/index.js +39 -0
  78. package/es/Snippet/style.d.ts +1 -0
  79. package/es/Snippet/style.js +9 -0
  80. package/es/StroyBook/index.d.ts +3 -4
  81. package/es/StroyBook/index.js +14 -7
  82. package/es/StroyBook/style.d.ts +4 -1
  83. package/es/StroyBook/style.js +7 -5
  84. package/es/Swatches/index.d.ts +8 -0
  85. package/es/Swatches/index.js +44 -0
  86. package/es/TabsNav/index.d.ts +3 -3
  87. package/es/TabsNav/index.js +4 -4
  88. package/es/ThemeProvider/GlobalStyle.js +1 -1
  89. package/es/ThemeProvider/index.d.ts +15 -0
  90. package/es/ThemeSwitch/index.d.ts +5 -5
  91. package/es/ThemeSwitch/index.js +5 -9
  92. package/es/Tooltip/index.d.ts +5 -0
  93. package/es/Tooltip/index.js +20 -0
  94. package/es/Tooltip/style.d.ts +3 -0
  95. package/es/Tooltip/style.js +10 -0
  96. package/es/hooks/useCopied.d.ts +4 -0
  97. package/es/hooks/useCopied.js +26 -0
  98. package/es/hooks/useHighlight.d.ts +36 -0
  99. package/es/hooks/useHighlight.js +63 -0
  100. package/es/index.d.ts +12 -0
  101. package/es/index.js +13 -1
  102. package/es/styles/theme/base.d.ts +2 -0
  103. package/es/styles/theme/base.js +15 -0
  104. package/es/styles/theme/dark.js +6 -14
  105. package/es/styles/theme/light.js +11 -12
  106. package/es/types/index.d.ts +14 -5
  107. package/lib/ActionIcon/index.d.ts +10 -5
  108. package/lib/ActionIcon/index.js +39 -50
  109. package/lib/ActionIcon/style.d.ts +4 -1
  110. package/lib/ActionIcon/style.js +29 -22
  111. package/lib/Avatar/index.d.ts +10 -0
  112. package/lib/Avatar/index.js +74 -0
  113. package/lib/ContextMenu/MenuItem/icons.d.ts +4 -0
  114. package/lib/ContextMenu/MenuItem/icons.js +100 -0
  115. package/lib/ContextMenu/MenuItem/index.d.ts +12 -0
  116. package/lib/ContextMenu/MenuItem/index.js +72 -0
  117. package/lib/ContextMenu/MenuItem/style.d.ts +7 -0
  118. package/lib/ContextMenu/MenuItem/style.js +94 -0
  119. package/lib/ContextMenu/index.d.ts +9 -0
  120. package/lib/ContextMenu/index.js +254 -0
  121. package/lib/ContextMenu/style.d.ts +4 -0
  122. package/lib/ContextMenu/style.js +88 -0
  123. package/lib/ContextMenu/types/index.d.ts +5 -0
  124. package/lib/ContextMenu/types/index.js +19 -0
  125. package/lib/ContextMenu/types/menuItem.d.ts +21 -0
  126. package/lib/{types/index.js → ContextMenu/types/menuItem.js} +3 -3
  127. package/lib/CopyButton/index.d.ts +34 -0
  128. package/lib/CopyButton/index.js +70 -0
  129. package/lib/DraggablePanel/index.d.ts +10 -4
  130. package/lib/DraggablePanel/index.js +147 -147
  131. package/lib/DraggablePanel/style.js +1 -2
  132. package/lib/EditableText/ControlInput.d.ts +9 -0
  133. package/lib/EditableText/ControlInput.js +101 -0
  134. package/lib/EditableText/index.d.ts +5 -0
  135. package/lib/EditableText/index.js +52 -0
  136. package/lib/Highlighter/SyntaxHighlighter/Prism.d.ts +7 -0
  137. package/lib/Highlighter/SyntaxHighlighter/Prism.js +41 -0
  138. package/lib/Highlighter/SyntaxHighlighter/index.d.ts +5 -0
  139. package/lib/Highlighter/SyntaxHighlighter/index.js +55 -0
  140. package/lib/Highlighter/SyntaxHighlighter/style.d.ts +5 -0
  141. package/lib/Highlighter/SyntaxHighlighter/style.js +58 -0
  142. package/lib/Highlighter/index.d.ts +36 -0
  143. package/lib/Highlighter/index.js +62 -0
  144. package/lib/Highlighter/style.d.ts +5 -0
  145. package/lib/Highlighter/style.js +107 -0
  146. package/lib/Icon/index.d.ts +2 -3
  147. package/lib/Icon/index.js +3 -13
  148. package/lib/List/ListItem/index.d.ts +64 -0
  149. package/lib/List/ListItem/index.js +157 -0
  150. package/lib/List/ListItem/time.d.ts +2 -0
  151. package/lib/List/ListItem/time.js +50 -0
  152. package/lib/List/index.d.ts +5 -0
  153. package/lib/List/index.js +41 -0
  154. package/lib/Logo/Divider.d.ts +3 -3
  155. package/lib/Logo/Divider.js +5 -15
  156. package/lib/Logo/Logo3D.d.ts +3 -3
  157. package/lib/Logo/Logo3D.js +4 -14
  158. package/lib/Logo/LogoFlat.d.ts +3 -3
  159. package/lib/Logo/LogoFlat.js +18 -28
  160. package/lib/Logo/LogoHighContrast.d.ts +3 -3
  161. package/lib/Logo/LogoHighContrast.js +4 -14
  162. package/lib/Logo/LogoText.d.ts +3 -3
  163. package/lib/Logo/LogoText.js +5 -15
  164. package/lib/Logo/index.d.ts +3 -3
  165. package/lib/Logo/index.js +11 -18
  166. package/lib/Logo/style.js +1 -1
  167. package/lib/Markdown/Code.d.ts +3 -0
  168. package/lib/Markdown/Code.js +33 -0
  169. package/lib/Markdown/CodeBlock.d.ts +3 -0
  170. package/lib/Markdown/CodeBlock.js +64 -0
  171. package/lib/Markdown/index.d.ts +13 -0
  172. package/lib/Markdown/index.js +48 -0
  173. package/lib/Markdown/style.d.ts +4 -0
  174. package/lib/Markdown/style.js +64 -0
  175. package/lib/MessageInput/index.d.ts +35 -0
  176. package/lib/MessageInput/index.js +58 -0
  177. package/lib/SearchBar/index.d.ts +5 -0
  178. package/lib/SearchBar/index.js +42 -0
  179. package/lib/SideNav/index.d.ts +6 -6
  180. package/lib/SideNav/index.js +7 -31
  181. package/lib/SideNav/style.d.ts +1 -0
  182. package/lib/SideNav/style.js +46 -0
  183. package/lib/Snippet/index.d.ts +29 -0
  184. package/lib/Snippet/index.js +47 -0
  185. package/lib/Snippet/style.d.ts +1 -0
  186. package/lib/Snippet/style.js +71 -0
  187. package/lib/StroyBook/index.d.ts +3 -4
  188. package/lib/StroyBook/index.js +20 -13
  189. package/lib/StroyBook/style.d.ts +4 -1
  190. package/lib/StroyBook/style.js +49 -43
  191. package/lib/Swatches/index.d.ts +8 -0
  192. package/lib/Swatches/index.js +68 -0
  193. package/lib/TabsNav/index.d.ts +3 -3
  194. package/lib/TabsNav/index.js +5 -15
  195. package/lib/ThemeProvider/GlobalStyle.js +7 -5
  196. package/lib/ThemeProvider/index.d.ts +15 -0
  197. package/lib/ThemeSwitch/index.d.ts +5 -5
  198. package/lib/ThemeSwitch/index.js +15 -32
  199. package/lib/Tooltip/index.d.ts +5 -0
  200. package/lib/Tooltip/index.js +34 -0
  201. package/lib/Tooltip/style.d.ts +3 -0
  202. package/lib/Tooltip/style.js +51 -0
  203. package/lib/hooks/useCopied.d.ts +4 -0
  204. package/lib/hooks/useCopied.js +44 -0
  205. package/lib/hooks/useHighlight.d.ts +36 -0
  206. package/lib/hooks/useHighlight.js +76 -0
  207. package/lib/index.d.ts +12 -0
  208. package/lib/index.js +38 -0
  209. package/lib/styles/theme/base.d.ts +2 -0
  210. package/lib/styles/theme/base.js +43 -0
  211. package/lib/styles/theme/dark.js +5 -12
  212. package/lib/styles/theme/light.js +10 -10
  213. package/lib/types/index.d.ts +14 -5
  214. package/package.json +14 -4
  215. package/es/ThemeProvider/token.d.ts +0 -3
  216. package/es/ThemeProvider/token.js +0 -45
  217. package/lib/ThemeProvider/token.d.ts +0 -3
  218. package/lib/ThemeProvider/token.js +0 -73
  219. /package/es/{types/index.js → ContextMenu/types/menuItem.js} +0 -0
@@ -1,7 +1,7 @@
1
- import { DivProps } from "../types";
1
+ /// <reference types="react" />
2
2
  import { LucideIcon } from 'lucide-react';
3
- import React from 'react';
4
- export declare type ActionIconSize = 'large' | 'normal' | 'small' | {
3
+ import { DivProps } from "../types";
4
+ export declare type ActionIconSize = 'large' | 'normal' | 'small' | 'site' | {
5
5
  blockSize?: number;
6
6
  fontSize?: number;
7
7
  strokeWidth?: number;
@@ -23,6 +23,11 @@ export interface ActionIconProps extends DivProps {
23
23
  * @type LucideIcon
24
24
  */
25
25
  icon: LucideIcon;
26
+ /**
27
+ * @description Glass blur style
28
+ * @default 'false'
29
+ */
30
+ glass?: boolean;
26
31
  }
27
- declare const _default: React.NamedExoticComponent<ActionIconProps>;
28
- export default _default;
32
+ declare const ActionIcon: import("react").NamedExoticComponent<ActionIconProps>;
33
+ export default ActionIcon;
@@ -1,21 +1,25 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
- var _excluded = ["className", "active", "icon", "size", "style"];
3
+ var _excluded = ["className", "active", "icon", "size", "style", "glass"];
4
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
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
6
  import { Icon } from "./..";
7
- import React from 'react';
7
+ import { memo } from 'react';
8
8
  import { useStyles } from "./style";
9
9
  import { jsx as _jsx } from "react/jsx-runtime";
10
- var ActionIcon = function ActionIcon(_ref) {
10
+ var ActionIcon = /*#__PURE__*/memo(function (_ref) {
11
11
  var className = _ref.className,
12
12
  active = _ref.active,
13
13
  icon = _ref.icon,
14
14
  _ref$size = _ref.size,
15
15
  size = _ref$size === void 0 ? 'normal' : _ref$size,
16
16
  style = _ref.style,
17
+ glass = _ref.glass,
17
18
  props = _objectWithoutProperties(_ref, _excluded);
18
- var _useStyles = useStyles(active),
19
+ var _useStyles = useStyles({
20
+ active: Boolean(active),
21
+ glass: Boolean(glass)
22
+ }),
19
23
  styles = _useStyles.styles,
20
24
  cx = _useStyles.cx;
21
25
  var blockSize;
@@ -33,6 +37,10 @@ var ActionIcon = function ActionIcon(_ref) {
33
37
  blockSize = 28;
34
38
  borderRadius = 5;
35
39
  break;
40
+ case 'site':
41
+ blockSize = 34;
42
+ borderRadius = 5;
43
+ break;
36
44
  default:
37
45
  blockSize = (size === null || size === void 0 ? void 0 : size.blockSize) || 36;
38
46
  borderRadius = (size === null || size === void 0 ? void 0 : size.borderRadius) || 5;
@@ -47,9 +55,9 @@ var ActionIcon = function ActionIcon(_ref) {
47
55
  }, style)
48
56
  }, props), {}, {
49
57
  children: /*#__PURE__*/_jsx(Icon, {
50
- size: size,
58
+ size: size === 'site' ? 'small' : size,
51
59
  icon: icon
52
60
  })
53
61
  }));
54
- };
55
- export default /*#__PURE__*/React.memo(ActionIcon);
62
+ });
63
+ export default ActionIcon;
@@ -1,3 +1,6 @@
1
- export declare const useStyles: (props?: unknown) => import("antd-style").ReturnStyles<{
1
+ export declare const useStyles: (props?: {
2
+ active: boolean;
3
+ glass: boolean;
4
+ } | undefined) => import("antd-style").ReturnStyles<{
2
5
  block: import("antd-style").SerializedStyles;
3
6
  }>;
@@ -1,10 +1,12 @@
1
1
  import _taggedTemplateLiteral from "@babel/runtime/helpers/esm/taggedTemplateLiteral";
2
- var _templateObject;
2
+ var _templateObject, _templateObject2;
3
3
  import { createStyles } from 'antd-style';
4
- export var useStyles = createStyles(function (_ref, active) {
4
+ export var useStyles = createStyles(function (_ref, _ref2) {
5
5
  var css = _ref.css,
6
6
  token = _ref.token;
7
+ var active = _ref2.active,
8
+ glass = _ref2.glass;
7
9
  return {
8
- block: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n cursor: pointer;\n\n display: flex;\n flex: none;\n align-items: center;\n justify-content: center;\n\n color: ", ";\n\n background: ", ";\n\n transition: color 600ms ", ", background-color 100ms ", ";\n\n &:hover {\n color: ", ";\n background-color: ", ";\n }\n\n &:active {\n color: ", ";\n background-color: ", ";\n }\n "])), active ? token.colorText : token.colorTextQuaternary, active ? token.colorFill : 'transparent', token.motionEaseOut, token.motionEaseOut, token.colorText, token.colorFillTertiary, token.colorText, token.colorFill)
10
+ block: css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n cursor: pointer;\n\n display: flex;\n flex: none;\n align-items: center;\n justify-content: center;\n\n color: ", ";\n\n background: ", ";\n\n transition: color 600ms ", ",\n background-color 100ms ", ";\n\n ", "\n\n &:hover {\n color: ", ";\n background-color: ", ";\n }\n\n &:active {\n color: ", ";\n background-color: ", ";\n }\n "])), active ? token.colorText : token.colorTextQuaternary, active ? token.colorFillTertiary : 'transparent', token.motionEaseOut, token.motionEaseOut, glass && css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n backdrop-filter: saturate(180%) blur(10px);\n "]))), token.colorText, active ? token.colorFillSecondary : token.colorFillTertiary, token.colorText, token.colorFill)
9
11
  };
10
12
  });
@@ -0,0 +1,10 @@
1
+ import { FC } from 'react';
2
+ export interface AvatarProps {
3
+ avatar?: string;
4
+ title?: string;
5
+ size?: number;
6
+ shape?: 'circle' | 'square';
7
+ background?: string;
8
+ }
9
+ declare const Avatar: FC<AvatarProps>;
10
+ export default Avatar;
@@ -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,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 &: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,4 @@
1
+ export declare const useStyles: (props?: string | undefined) => import("antd-style").ReturnStyles<{
2
+ container: string;
3
+ button: string;
4
+ }>;