@lobehub/ui 1.31.3 → 1.32.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,7 +1,12 @@
1
1
  /// <reference types="react" />
2
2
  import { ActionIconProps } from "..";
3
- import { type MenuProps } from 'antd';
3
+ import { type LucideIcon } from 'lucide-react';
4
4
  import { DivProps } from "../types";
5
+ interface ActionIconGroupItems {
6
+ icon: LucideIcon;
7
+ key: string;
8
+ label: string;
9
+ }
5
10
  export interface ActionIconGroupProps extends DivProps {
6
11
  /**
7
12
  * @description The direction of the icons
@@ -11,12 +16,15 @@ export interface ActionIconGroupProps extends DivProps {
11
16
  /**
12
17
  * @description The menu items for the dropdown
13
18
  */
14
- dropdownMenu?: MenuProps['items'];
19
+ dropdownMenu?: (ActionIconGroupItems | {
20
+ type: 'divider';
21
+ })[];
15
22
  /**
16
23
  * @description The items to be rendered
17
24
  * @default []
18
25
  */
19
- items?: ActionIconProps[];
26
+ items?: ActionIconGroupItems[];
27
+ onActionClick: (key: string) => void;
20
28
  /**
21
29
  * @description The position of the tooltip relative to the target
22
30
  * @enum ["top","left","right","bottom","topLeft","topRight","bottomLeft","bottomRight","leftTop","leftBottom","rightTop","rightBottom"]
@@ -1,9 +1,9 @@
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", "dropdownMenu"];
3
+ var _excluded = ["type", "items", "placement", "spotlight", "direction", "dropdownMenu", "onActionClick"];
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
- import { ActionIcon, Spotlight } from "./..";
6
+ import { ActionIcon, Icon, Spotlight } from "./..";
7
7
  import { Dropdown } from 'antd';
8
8
  import { MoreHorizontal } from 'lucide-react';
9
9
  import { memo } from 'react';
@@ -22,6 +22,8 @@ var ActionIconGroup = /*#__PURE__*/memo(function (_ref) {
22
22
  direction = _ref$direction === void 0 ? 'row' : _ref$direction,
23
23
  _ref$dropdownMenu = _ref.dropdownMenu,
24
24
  dropdownMenu = _ref$dropdownMenu === void 0 ? [] : _ref$dropdownMenu,
25
+ _ref$onActionClick = _ref.onActionClick,
26
+ onActionClick = _ref$onActionClick === void 0 ? function () {} : _ref$onActionClick,
25
27
  props = _objectWithoutProperties(_ref, _excluded);
26
28
  var _useStyles = useStyles({
27
29
  direction: direction,
@@ -32,14 +34,30 @@ var ActionIconGroup = /*#__PURE__*/memo(function (_ref) {
32
34
  return /*#__PURE__*/_jsxs("div", _objectSpread(_objectSpread({
33
35
  className: styles.container
34
36
  }, props), {}, {
35
- children: [spotlight && /*#__PURE__*/_jsx(Spotlight, {}), items.map(function (item, index) {
36
- return /*#__PURE__*/_jsx(ActionIcon, _objectSpread({
37
+ children: [spotlight && /*#__PURE__*/_jsx(Spotlight, {}), items.map(function (item) {
38
+ return /*#__PURE__*/_jsx(ActionIcon, {
39
+ icon: item.icon,
40
+ onClick: function onClick() {
41
+ return onActionClick(item.key);
42
+ },
37
43
  placement: tooltipsPlacement,
38
- size: "small"
39
- }, item), index);
44
+ size: "small",
45
+ title: item.label
46
+ }, item.key);
40
47
  }), dropdownMenu && /*#__PURE__*/_jsx(Dropdown, {
41
48
  menu: {
42
- items: dropdownMenu
49
+ items: dropdownMenu.map(function (item) {
50
+ if (item.type) return item;
51
+ return _objectSpread(_objectSpread({}, item), {}, {
52
+ icon: /*#__PURE__*/_jsx(Icon, {
53
+ icon: item.icon,
54
+ size: "small"
55
+ }),
56
+ onClick: function onClick() {
57
+ return onActionClick(item.key);
58
+ }
59
+ });
60
+ })
43
61
  },
44
62
  trigger: ['click'],
45
63
  children: /*#__PURE__*/_jsx(ActionIcon, {
@@ -1,8 +1,7 @@
1
1
  import { type AlertProps } from 'antd';
2
2
  import { ReactNode } from 'react';
3
- import type { DivProps } from "../types";
4
3
  import { MetaData } from "../types/meta";
5
- export interface ChatItemProps extends DivProps {
4
+ export interface ChatItemProps {
6
5
  actions?: ReactNode;
7
6
  /**
8
7
  * @description Whether to show alert and alert config
@@ -17,6 +16,12 @@ export interface ChatItemProps extends DivProps {
17
16
  * @default true
18
17
  */
19
18
  borderSpacing?: boolean;
19
+ className?: string;
20
+ /**
21
+ * @title Whether the component is in edit mode or not
22
+ * @default false
23
+ */
24
+ editing?: boolean;
20
25
  /**
21
26
  * @description Whether to show a loading spinner
22
27
  * @default false
@@ -26,6 +31,16 @@ export interface ChatItemProps extends DivProps {
26
31
  * @description The message to be displayed
27
32
  */
28
33
  message?: string;
34
+ /**
35
+ * @title Callback function when the value changes
36
+ * @param value - The new value
37
+ */
38
+ onChange?: (value: string) => void;
39
+ /**
40
+ * @title Callback function when the editing state changes
41
+ * @param editing - Whether the component is in edit mode or not
42
+ */
43
+ onEditingChange?: (editing: boolean) => void;
29
44
  /**
30
45
  * @description The placement of the chat item
31
46
  * @default 'left'
@@ -1,14 +1,14 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
2
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
3
- var _excluded = ["actions", "className", "title", "primary", "borderSpacing", "loading", "message", "placement", "type", "avatar", "alert", "showTitle", "time"];
3
+ var _excluded = ["actions", "className", "primary", "borderSpacing", "loading", "message", "placement", "type", "avatar", "alert", "showTitle", "time", "editing", "onChange", "onEditingChange"];
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';
7
7
  import { Loader2 } from 'lucide-react';
8
8
  import { memo } from 'react';
9
9
  import Avatar from "../Avatar";
10
+ import EditableMessage from "../EditableMessage";
10
11
  import Icon from "../Icon";
11
- import Markdown from "../Markdown";
12
12
  import { formatTime } from "../utils/formatTime";
13
13
  import { useStyles } from "./style";
14
14
  import { jsx as _jsx } from "react/jsx-runtime";
@@ -17,7 +17,6 @@ var AVATAR_SIZE = 40;
17
17
  var ChatItem = /*#__PURE__*/memo(function (_ref) {
18
18
  var actions = _ref.actions,
19
19
  className = _ref.className,
20
- title = _ref.title,
21
20
  primary = _ref.primary,
22
21
  _ref$borderSpacing = _ref.borderSpacing,
23
22
  borderSpacing = _ref$borderSpacing === void 0 ? true : _ref$borderSpacing,
@@ -31,6 +30,9 @@ var ChatItem = /*#__PURE__*/memo(function (_ref) {
31
30
  alert = _ref.alert,
32
31
  showTitle = _ref.showTitle,
33
32
  time = _ref.time,
33
+ editing = _ref.editing,
34
+ onChange = _ref.onChange,
35
+ onEditingChange = _ref.onEditingChange,
34
36
  properties = _objectWithoutProperties(_ref, _excluded);
35
37
  var _useStyles = useStyles({
36
38
  avatarSize: AVATAR_SIZE,
@@ -38,7 +40,7 @@ var ChatItem = /*#__PURE__*/memo(function (_ref) {
38
40
  placement: placement,
39
41
  primary: primary,
40
42
  showTitle: showTitle,
41
- title: title,
43
+ title: avatar.title,
42
44
  type: type
43
45
  }),
44
46
  cx = _useStyles.cx,
@@ -76,10 +78,16 @@ var ChatItem = /*#__PURE__*/memo(function (_ref) {
76
78
  showIcon: true
77
79
  }, alert)) : /*#__PURE__*/_jsx("div", {
78
80
  className: styles.message,
79
- children: /*#__PURE__*/_jsx(Markdown, {
80
- children: String(message || '...')
81
+ style: editing ? {
82
+ padding: 12
83
+ } : {},
84
+ children: /*#__PURE__*/_jsx(EditableMessage, {
85
+ editing: editing,
86
+ onChange: onChange,
87
+ onEditingChange: onEditingChange,
88
+ value: String(message || '...')
81
89
  })
82
- }), /*#__PURE__*/_jsx("div", {
90
+ }), !editing && /*#__PURE__*/_jsx("div", {
83
91
  className: cx(styles.actions, 'chat-item-actions'),
84
92
  children: actions
85
93
  })]
@@ -7,7 +7,6 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
7
7
  import { Copy, Edit, RotateCw, Trash } from 'lucide-react';
8
8
  import { memo, useMemo } from 'react';
9
9
  import ActionIconGroup from "../ActionIconGroup";
10
- import Icon from "../Icon";
11
10
  import { jsx as _jsx } from "react/jsx-runtime";
12
11
  var ActionsBar = /*#__PURE__*/memo(function (_ref) {
13
12
  var primary = _ref.primary,
@@ -19,48 +18,32 @@ var ActionsBar = /*#__PURE__*/memo(function (_ref) {
19
18
  var groupItems = useMemo(function () {
20
19
  return [primary ? {
21
20
  icon: Edit,
22
- onClick: function onClick() {
23
- return console.log('click Edit');
24
- },
25
- title: 'Edit'
21
+ key: 'edit',
22
+ label: 'Edit'
26
23
  } : {
27
24
  icon: RotateCw,
28
- onClick: function onClick() {
29
- return console.log('click Regenerate');
30
- },
31
- title: 'Regenerate'
25
+ key: 'regenerate',
26
+ label: 'Regenerate'
32
27
  }].concat(_toConsumableArray(items)).filter(Boolean);
33
28
  }, [primary, items]);
34
29
  var groupDropdownMenu = useMemo(function () {
35
30
  return [].concat(_toConsumableArray(dropdownMenu), [{
36
- icon: /*#__PURE__*/_jsx(Icon, {
37
- icon: Edit,
38
- size: "small"
39
- }),
40
- key: 'Edit',
31
+ icon: Edit,
32
+ key: 'edit',
41
33
  label: 'Edit'
42
34
  }, {
43
- icon: /*#__PURE__*/_jsx(Icon, {
44
- icon: Copy,
45
- size: "small"
46
- }),
47
- key: 'Copy',
35
+ icon: Copy,
36
+ key: 'copy',
48
37
  label: 'Copy'
49
38
  }, {
50
- icon: /*#__PURE__*/_jsx(Icon, {
51
- icon: RotateCw,
52
- size: "small"
53
- }),
54
- key: 'Regenerate',
39
+ icon: RotateCw,
40
+ key: 'regenerate',
55
41
  label: 'Regenerate'
56
42
  }, {
57
43
  type: 'divider'
58
44
  }, {
59
- icon: /*#__PURE__*/_jsx(Icon, {
60
- icon: Trash,
61
- size: "small"
62
- }),
63
- key: 'Delete',
45
+ icon: Trash,
46
+ key: 'Ddelete',
64
47
  label: 'Delete'
65
48
  }]);
66
49
  }, [primary, dropdownMenu]);
@@ -7,6 +7,7 @@ export interface ChatListProps extends DivProps {
7
7
  * @description Data of chat messages to be displayed
8
8
  */
9
9
  data: ChatMessage[];
10
+ onActionClick: (actionKey: string, messageId: string) => void;
10
11
  /**
11
12
  * @description Whether to show name of the chat item
12
13
  * @default false
@@ -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", "data", "type", "showTitle"];
3
+ var _excluded = ["onActionClick", "className", "data", "type", "showTitle"];
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 { memo } from 'react';
@@ -9,7 +9,8 @@ import ActionsBar from "./ActionsBar";
9
9
  import { useStyles } from "./style";
10
10
  import { jsx as _jsx } from "react/jsx-runtime";
11
11
  var ChatList = /*#__PURE__*/memo(function (_ref) {
12
- var className = _ref.className,
12
+ var _onActionClick = _ref.onActionClick,
13
+ className = _ref.className,
13
14
  data = _ref.data,
14
15
  _ref$type = _ref.type,
15
16
  type = _ref$type === void 0 ? 'chat' : _ref$type,
@@ -24,6 +25,9 @@ var ChatList = /*#__PURE__*/memo(function (_ref) {
24
25
  children: data.map(function (item) {
25
26
  return /*#__PURE__*/_jsx(ChatItem, {
26
27
  actions: /*#__PURE__*/_jsx(ActionsBar, {
28
+ onActionClick: function onActionClick(actionKey) {
29
+ return _onActionClick(actionKey, item.id);
30
+ },
27
31
  primary: item.role === 'user'
28
32
  }),
29
33
  avatar: item.meta,
@@ -20,7 +20,6 @@ var Code = /*#__PURE__*/memo(function (properties) {
20
20
  return /*#__PURE__*/_jsx(Highlighter, {
21
21
  className: styles,
22
22
  language: (className === null || className === void 0 ? void 0 : className.replace('language-', '')) || 'markdown',
23
- spotlight: true,
24
23
  theme: theme.appearance,
25
24
  type: "block",
26
25
  children: Array.isArray(children) ? children[0] : children
@@ -1,7 +1,7 @@
1
1
  import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
2
2
  import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
3
3
  import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
4
- var _excluded = ["type", "onCancel", "defaultValue", "onConfirm", "renderButtons", "textareaStyle", "textareaClassname", "height"];
4
+ var _excluded = ["type", "onCancel", "defaultValue", "onConfirm", "renderButtons", "textareaStyle", "textareaClassname", "placeholder", "height"];
5
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
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
7
  import { Button } from 'antd';
@@ -13,13 +13,15 @@ import { Fragment as _Fragment } from "react/jsx-runtime";
13
13
  import { jsxs as _jsxs } from "react/jsx-runtime";
14
14
  var MessageInput = /*#__PURE__*/memo(function (_ref) {
15
15
  var _ref$type = _ref.type,
16
- type = _ref$type === void 0 ? 'ghost' : _ref$type,
16
+ type = _ref$type === void 0 ? 'pure' : _ref$type,
17
17
  onCancel = _ref.onCancel,
18
18
  defaultValue = _ref.defaultValue,
19
19
  onConfirm = _ref.onConfirm,
20
20
  renderButtons = _ref.renderButtons,
21
21
  textareaStyle = _ref.textareaStyle,
22
22
  textareaClassname = _ref.textareaClassname,
23
+ _ref$placeholder = _ref.placeholder,
24
+ placeholder = _ref$placeholder === void 0 ? 'Type something...' : _ref$placeholder,
23
25
  _ref$height = _ref.height,
24
26
  height = _ref$height === void 0 ? 'fit-content' : _ref$height,
25
27
  props = _objectWithoutProperties(_ref, _excluded);
@@ -36,7 +38,7 @@ var MessageInput = /*#__PURE__*/memo(function (_ref) {
36
38
  onValueChange: function onValueChange(value) {
37
39
  setRole(value);
38
40
  },
39
- placeholder: '例如:你是一名擅长翻译的翻译官,请将用户所输入的英文都翻译为中文。',
41
+ placeholder: placeholder,
40
42
  resize: false,
41
43
  style: _objectSpread({
42
44
  height: height
@@ -47,16 +49,20 @@ var MessageInput = /*#__PURE__*/memo(function (_ref) {
47
49
  direction: 'horizontal-reverse',
48
50
  gap: 8,
49
51
  children: renderButtons ? renderButtons(temporarySystemRole).map(function (buttonProps, index) {
50
- return /*#__PURE__*/_jsx(Button, _objectSpread({}, buttonProps), index);
52
+ return /*#__PURE__*/_jsx(Button, _objectSpread({
53
+ size: "small"
54
+ }, buttonProps), index);
51
55
  }) : /*#__PURE__*/_jsxs(_Fragment, {
52
56
  children: [/*#__PURE__*/_jsx(Button, {
53
57
  onClick: function onClick() {
54
58
  onConfirm === null || onConfirm === void 0 ? void 0 : onConfirm(temporarySystemRole);
55
59
  },
60
+ size: "small",
56
61
  type: "primary",
57
62
  children: "Confirm"
58
63
  }), /*#__PURE__*/_jsx(Button, {
59
64
  onClick: onCancel,
65
+ size: "small",
60
66
  children: "Cancel"
61
67
  })]
62
68
  })
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/ui",
3
- "version": "1.31.3",
3
+ "version": "1.32.0",
4
4
  "description": "Lobe UI is an open-source UI component library for building chatbot web apps",
5
5
  "keywords": [
6
6
  "lobehub",