@lobehub/ui 1.22.1 → 1.23.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.
@@ -1,9 +1,11 @@
1
1
  /// <reference types="react" />
2
2
  import { ActionIconProps } from "..";
3
+ import { type MenuProps } from 'antd';
3
4
  import { DivProps } from "../types";
4
5
  export interface ActionIconGroupProps extends DivProps {
5
6
  direction?: 'row' | 'column';
6
- items: ActionIconProps[];
7
+ dropdownMenu?: MenuProps['items'];
8
+ items?: ActionIconProps[];
7
9
  /**
8
10
  * @description The position of the tooltip relative to the target
9
11
  * @enum ["top","left","right","bottom","topLeft","topRight","bottomLeft","bottomRight","leftTop","leftBottom","rightTop","rightBottom"]
@@ -1,9 +1,11 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
- var _excluded = ["type", "items", "placement", "spotlight", "direction"];
3
+ var _excluded = ["type", "items", "placement", "spotlight", "direction", "dropdownMenu"];
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 { ActionIcon, Spotlight } from "./..";
7
+ import { Dropdown } from 'antd';
8
+ import { MoreHorizontal } from 'lucide-react';
7
9
  import { memo } from 'react';
8
10
  import { useStyles } from "./style";
9
11
  import { jsx as _jsx } from "react/jsx-runtime";
@@ -11,26 +13,40 @@ import { jsxs as _jsxs } from "react/jsx-runtime";
11
13
  var ActionIconGroup = /*#__PURE__*/memo(function (_ref) {
12
14
  var _ref$type = _ref.type,
13
15
  type = _ref$type === void 0 ? 'block' : _ref$type,
14
- items = _ref.items,
16
+ _ref$items = _ref.items,
17
+ items = _ref$items === void 0 ? [] : _ref$items,
15
18
  placement = _ref.placement,
16
19
  _ref$spotlight = _ref.spotlight,
17
20
  spotlight = _ref$spotlight === void 0 ? true : _ref$spotlight,
18
21
  _ref$direction = _ref.direction,
19
22
  direction = _ref$direction === void 0 ? 'row' : _ref$direction,
23
+ _ref$dropdownMenu = _ref.dropdownMenu,
24
+ dropdownMenu = _ref$dropdownMenu === void 0 ? [] : _ref$dropdownMenu,
20
25
  props = _objectWithoutProperties(_ref, _excluded);
21
26
  var _useStyles = useStyles({
22
27
  direction: direction,
23
28
  type: type
24
29
  }),
25
30
  styles = _useStyles.styles;
31
+ var tooltipsPlacement = placement || (direction === 'column' ? 'right' : 'top');
26
32
  return /*#__PURE__*/_jsxs("div", _objectSpread(_objectSpread({
27
33
  className: styles.container
28
34
  }, props), {}, {
29
35
  children: [spotlight && /*#__PURE__*/_jsx(Spotlight, {}), items.map(function (item, index) {
30
36
  return /*#__PURE__*/_jsx(ActionIcon, _objectSpread({
31
- placement: placement || (direction === 'column' ? 'right' : 'top'),
37
+ placement: tooltipsPlacement,
32
38
  size: "small"
33
39
  }, item), index);
40
+ }), dropdownMenu && /*#__PURE__*/_jsx(Dropdown, {
41
+ menu: {
42
+ items: dropdownMenu
43
+ },
44
+ trigger: ['click'],
45
+ children: /*#__PURE__*/_jsx(ActionIcon, {
46
+ icon: MoreHorizontal,
47
+ placement: tooltipsPlacement,
48
+ size: "small"
49
+ }, "more")
34
50
  })]
35
51
  }));
36
52
  });
@@ -8,7 +8,7 @@ export var useStyles = createStyles(function (_ref, _ref2) {
8
8
  cx = _ref.cx;
9
9
  var direction = _ref2.direction,
10
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);
11
+ var typeStylish = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n background-color: ", ";\n border: 1px solid ", ";\n "])), type === 'block' ? token.colorFillTertiary : token.colorFillQuaternary, type === 'block' ? 'transparent' : token.colorBorder);
12
12
  return {
13
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
14
  };
@@ -1,8 +1,9 @@
1
- /// <reference types="react" />
2
1
  import { type AlertProps } from 'antd';
2
+ import { ReactNode } from 'react';
3
3
  import type { DivProps } from "../types";
4
4
  import { MetaData } from "../types/meta";
5
5
  export interface ChatItemProps extends DivProps {
6
+ actions?: ReactNode;
6
7
  /**
7
8
  * @description Whether to show alert and alert config
8
9
  */
@@ -1,6 +1,6 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
- var _excluded = ["className", "title", "primary", "borderSpacing", "loading", "message", "placement", "type", "avatar", "alert", "showTitle", "time"];
3
+ var _excluded = ["actions", "className", "title", "primary", "borderSpacing", "loading", "message", "placement", "type", "avatar", "alert", "showTitle", "time"];
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 { Alert } from 'antd';
@@ -13,7 +13,8 @@ import { jsx as _jsx } from "react/jsx-runtime";
13
13
  import { jsxs as _jsxs } from "react/jsx-runtime";
14
14
  var AVATAR_SIZE = 40;
15
15
  var ChatItem = /*#__PURE__*/memo(function (_ref) {
16
- var className = _ref.className,
16
+ var actions = _ref.actions,
17
+ className = _ref.className,
17
18
  title = _ref.title,
18
19
  primary = _ref.primary,
19
20
  _ref$borderSpacing = _ref.borderSpacing,
@@ -35,7 +36,8 @@ var ChatItem = /*#__PURE__*/memo(function (_ref) {
35
36
  title: title,
36
37
  primary: primary,
37
38
  avatarSize: AVATAR_SIZE,
38
- showTitle: showTitle
39
+ showTitle: showTitle,
40
+ borderSpacing: borderSpacing
39
41
  }),
40
42
  cx = _useStyles.cx,
41
43
  styles = _useStyles.styles;
@@ -65,7 +67,7 @@ var ChatItem = /*#__PURE__*/memo(function (_ref) {
65
67
  children: [/*#__PURE__*/_jsxs("div", {
66
68
  className: cx(styles.name, 'chat-item-name'),
67
69
  children: [showTitle ? avatar.title || 'untitled' : null, time && /*#__PURE__*/_jsx("span", {
68
- className: cx(type === 'pure' && !showTitle && styles.time, 'chat-item-time'),
70
+ className: "chat-item-time",
69
71
  children: formatTime(time)
70
72
  })]
71
73
  }), alert ? /*#__PURE__*/_jsx(Alert, _objectSpread({
@@ -75,6 +77,9 @@ var ChatItem = /*#__PURE__*/memo(function (_ref) {
75
77
  children: /*#__PURE__*/_jsx(Markdown, {
76
78
  children: String(message || '...')
77
79
  })
80
+ }), /*#__PURE__*/_jsx("div", {
81
+ className: cx(styles.actions, 'chat-item-actions'),
82
+ children: actions
78
83
  })]
79
84
  }), borderSpacing && /*#__PURE__*/_jsx("div", {
80
85
  style: {
@@ -1,5 +1,6 @@
1
1
  export declare const useStyles: (props?: {
2
2
  avatarSize: number;
3
+ borderSpacing: boolean;
3
4
  placement?: "left" | "right" | undefined;
4
5
  primary?: boolean | undefined;
5
6
  showTitle?: boolean | undefined;
@@ -11,6 +12,6 @@ export declare const useStyles: (props?: {
11
12
  avatarContainer: import("antd-style").SerializedStyles;
12
13
  messageContainer: import("antd-style").SerializedStyles;
13
14
  name: import("antd-style").SerializedStyles;
14
- time: string;
15
15
  message: string;
16
+ actions: string;
16
17
  }>;
@@ -1,28 +1,28 @@
1
1
  import _taggedTemplateLiteral from "@babel/runtime/helpers/esm/taggedTemplateLiteral";
2
- var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10;
2
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12;
3
3
  import { createStyles } from 'antd-style';
4
4
  export var useStyles = createStyles(function (_ref, _ref2) {
5
5
  var cx = _ref.cx,
6
6
  css = _ref.css,
7
- token = _ref.token,
8
- stylish = _ref.stylish;
7
+ token = _ref.token;
9
8
  var placement = _ref2.placement,
10
9
  type = _ref2.type,
11
10
  title = _ref2.title,
12
11
  primary = _ref2.primary,
13
12
  avatarSize = _ref2.avatarSize,
14
- showTitle = _ref2.showTitle;
13
+ showTitle = _ref2.showTitle,
14
+ borderSpacing = _ref2.borderSpacing;
15
15
  var blockStylish = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n padding: 8px 12px;\n background-color: ", ";\n border-radius: ", "px;\n transition: background-color 100ms ", ";\n "])), primary ? token.colorFillSecondary : token.colorFillTertiary, token.borderRadiusLG, token.motionEaseOut);
16
16
  var pureStylish = css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n padding-top: ", ";\n "])), title ? 0 : '6px');
17
- var pureContainerStylish = css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n border-radius: ", "px;\n transition: background-color 100ms ", ";\n\n &:hover {\n background-color: ", ";\n }\n "])), token.borderRadiusLG, token.motionEaseOut, token.colorFillTertiary);
17
+ var pureContainerStylish = css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n transition: background-color 100ms ", ";\n "])), token.motionEaseOut);
18
18
  var typeStylish = type === 'block' ? blockStylish : pureStylish;
19
19
  return {
20
- container: cx(type === 'pure' && pureContainerStylish, css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n position: relative;\n\n display: flex;\n flex-direction: ", ";\n gap: 12px;\n align-items: flex-start;\n justify-content: revert;\n\n width: 100%;\n padding: 12px;\n\n .chat-item-time {\n display: none;\n }\n\n &:hover {\n .chat-item-time {\n display: inline-block;\n }\n }\n "])), placement === 'left' ? 'row' : 'row-reverse')),
20
+ container: cx(type === 'pure' && pureContainerStylish, css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n position: relative;\n\n display: flex;\n flex-direction: ", ";\n gap: 12px;\n align-items: flex-start;\n justify-content: revert;\n\n width: 100%;\n padding: 12px;\n\n .chat-item-time,\n .chat-item-actions {\n display: none;\n }\n\n &:hover {\n .chat-item-time {\n display: inline-block;\n }\n\n .chat-item-actions {\n display: flex;\n }\n }\n "])), placement === 'left' ? 'row' : 'row-reverse')),
21
21
  loading: css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n position: absolute;\n right: ", ";\n bottom: 0;\n left: ", ";\n\n display: flex;\n align-items: center;\n justify-content: center;\n\n width: 16px;\n height: 16px;\n\n color: ", ";\n\n background: ", ";\n border-radius: 50%;\n "])), placement === 'left' ? '-4px' : 'unset', placement === 'right' ? '-4px' : 'unset', token.colorBgLayout, token.colorPrimary),
22
22
  avatarContainer: css(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n position: relative;\n flex: none;\n width: ", "px;\n height: ", "px;\n "])), avatarSize, avatarSize),
23
23
  messageContainer: css(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["\n position: relative;\n\n .ant-alert-with-description {\n padding-block: 12px;\n padding-inline: 12px;\n }\n "]))),
24
24
  name: css(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["\n position: ", ";\n top: ", ";\n right: ", ";\n left: ", ";\n\n display: flex;\n flex-direction: ", ";\n gap: 4px;\n\n margin-bottom: 6px;\n\n font-size: 12px;\n line-height: 1;\n color: ", ";\n text-align: ", ";\n "])), showTitle ? 'relative' : 'absolute', showTitle ? 'unset' : '-16px', placement === 'right' ? '0' : 'unset', placement === 'left' ? '0' : 'unset', placement === 'left' ? 'row' : 'row-reverse', token.colorTextDescription, placement === 'left' ? 'left' : 'right'),
25
- time: cx(stylish.blur, css(_templateObject9 || (_templateObject9 = _taggedTemplateLiteral(["\n display: flex;\n align-items: center;\n justify-content: center;\n\n padding: 4px 6px;\n\n line-height: 1;\n\n background: ", ";\n border-radius: ", "px;\n "])), token.colorFillQuaternary, token.borderRadius)),
26
- message: cx(typeStylish, css(_templateObject10 || (_templateObject10 = _taggedTemplateLiteral(["\n position: relative;\n "]))))
25
+ message: cx(typeStylish, css(_templateObject9 || (_templateObject9 = _taggedTemplateLiteral(["\n position: relative;\n "])))),
26
+ actions: cx(css(_templateObject10 || (_templateObject10 = _taggedTemplateLiteral(["\n position: absolute;\n display: flex;\n align-items: flex-start;\n justify-content: ", ";\n "])), placement === 'left' ? 'flex-end' : 'flex-start'), type === 'block' && borderSpacing ? css(_templateObject11 || (_templateObject11 = _taggedTemplateLiteral(["\n right: ", ";\n bottom: 0;\n left: ", ";\n transform: translateX(", ");\n "])), placement === 'left' ? '-4px' : 'unset', placement === 'right' ? '-4px' : 'unset', placement === 'left' ? '100%' : '-100%') : css(_templateObject12 || (_templateObject12 = _taggedTemplateLiteral(["\n right: ", ";\n bottom: ", ";\n left: ", ";\n "])), placement === 'left' ? '0' : 'unset', type === 'block' ? '-40px' : '-32px', placement === 'right' ? '0' : 'unset'))
27
27
  };
28
28
  });
@@ -0,0 +1,7 @@
1
+ /// <reference types="react" />
2
+ import { type ActionIconGroupProps } from "../index";
3
+ export interface ActionsBarProps extends ActionIconGroupProps {
4
+ primary?: boolean;
5
+ }
6
+ declare const ActionsBar: import("react").NamedExoticComponent<ActionsBarProps>;
7
+ export default ActionsBar;
@@ -0,0 +1,72 @@
1
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
+ import _toConsumableArray from "@babel/runtime/helpers/esm/toConsumableArray";
3
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
4
+ var _excluded = ["primary", "items", "dropdownMenu"];
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 { Copy, Edit, RotateCw, Trash } from 'lucide-react';
8
+ import { memo, useMemo } from 'react';
9
+ import { ActionIconGroup, Icon } from "./..";
10
+ import { jsx as _jsx } from "react/jsx-runtime";
11
+ var ActionsBar = /*#__PURE__*/memo(function (_ref) {
12
+ var primary = _ref.primary,
13
+ _ref$items = _ref.items,
14
+ items = _ref$items === void 0 ? [] : _ref$items,
15
+ _ref$dropdownMenu = _ref.dropdownMenu,
16
+ dropdownMenu = _ref$dropdownMenu === void 0 ? [] : _ref$dropdownMenu,
17
+ props = _objectWithoutProperties(_ref, _excluded);
18
+ var groupItems = useMemo(function () {
19
+ return [primary ? {
20
+ icon: Edit,
21
+ title: 'Edit',
22
+ onClick: function onClick() {
23
+ return console.log('click Edit');
24
+ }
25
+ } : {
26
+ icon: RotateCw,
27
+ title: 'Regenerate',
28
+ onClick: function onClick() {
29
+ return console.log('click Regenerate');
30
+ }
31
+ }].concat(_toConsumableArray(items)).filter(Boolean);
32
+ }, [primary, items]);
33
+ var groupDropdownMenu = useMemo(function () {
34
+ return dropdownMenu.concat([{
35
+ key: 'Edit',
36
+ icon: /*#__PURE__*/_jsx(Icon, {
37
+ icon: Edit,
38
+ size: "small"
39
+ }),
40
+ label: 'Edit'
41
+ }, {
42
+ key: 'Copy',
43
+ icon: /*#__PURE__*/_jsx(Icon, {
44
+ icon: Copy,
45
+ size: "small"
46
+ }),
47
+ label: 'Copy'
48
+ }, {
49
+ key: 'Regenerate',
50
+ icon: /*#__PURE__*/_jsx(Icon, {
51
+ icon: RotateCw,
52
+ size: "small"
53
+ }),
54
+ label: 'Regenerate'
55
+ }, {
56
+ type: 'divider'
57
+ }, {
58
+ key: 'Delete',
59
+ icon: /*#__PURE__*/_jsx(Icon, {
60
+ icon: Trash,
61
+ size: "small"
62
+ }),
63
+ label: 'Delete'
64
+ }]).filter(Boolean);
65
+ }, [primary, dropdownMenu]);
66
+ return /*#__PURE__*/_jsx(ActionIconGroup, _objectSpread({
67
+ dropdownMenu: groupDropdownMenu,
68
+ items: groupItems,
69
+ type: "ghost"
70
+ }, props));
71
+ });
72
+ export default ActionsBar;
@@ -5,6 +5,7 @@ function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (O
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 { memo } from 'react';
7
7
  import { ChatItem } from "./..";
8
+ import ActionsBar from "./ActionsBar";
8
9
  import { useStyles } from "./style";
9
10
  import { jsx as _jsx } from "react/jsx-runtime";
10
11
  var ChatList = /*#__PURE__*/memo(function (_ref) {
@@ -22,6 +23,9 @@ var ChatList = /*#__PURE__*/memo(function (_ref) {
22
23
  }, props), {}, {
23
24
  children: data.map(function (item) {
24
25
  return /*#__PURE__*/_jsx(ChatItem, {
26
+ actions: /*#__PURE__*/_jsx(ActionsBar, {
27
+ primary: item.role === 'user'
28
+ }),
25
29
  avatar: item.meta,
26
30
  borderSpacing: type === 'chat',
27
31
  message: item.content,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/ui",
3
- "version": "1.22.1",
3
+ "version": "1.23.0",
4
4
  "description": "Lobe UI is an open-source UI component library for building chatbot web apps",
5
5
  "keywords": [
6
6
  "lobehub",