@yuntijs/ui 1.0.0-beta.57 → 1.0.0-beta.58

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.
@@ -0,0 +1,21 @@
1
+ import { MarkdownProps } from '@lobehub/ui';
2
+ import { type ReactNode } from 'react';
3
+ import { ChatItemProps } from '../type';
4
+ export interface MessageContentProps {
5
+ editing?: ChatItemProps['editing'];
6
+ fontSize?: number;
7
+ message?: ReactNode;
8
+ messageExtra?: ChatItemProps['messageExtra'];
9
+ onChange?: ChatItemProps['onChange'];
10
+ onDoubleClick?: ChatItemProps['onDoubleClick'];
11
+ onEditingChange?: ChatItemProps['onEditingChange'];
12
+ placement?: ChatItemProps['placement'];
13
+ primary?: ChatItemProps['primary'];
14
+ renderMessage?: ChatItemProps['renderMessage'];
15
+ text?: ChatItemProps['text'];
16
+ type?: ChatItemProps['type'];
17
+ markdownProps?: MarkdownProps;
18
+ markdownClassname?: string;
19
+ }
20
+ declare const MessageContent: import("react").NamedExoticComponent<MessageContentProps>;
21
+ export default MessageContent;
@@ -0,0 +1,59 @@
1
+ import { useResponsive } from 'antd-style';
2
+ import { memo } from 'react';
3
+ import { Flexbox } from 'react-layout-kit';
4
+ import EditableMessage from "../../EditableMessage";
5
+ import { useStyles } from "../style";
6
+ import { jsx as _jsx } from "react/jsx-runtime";
7
+ import { jsxs as _jsxs } from "react/jsx-runtime";
8
+ var MessageContent = /*#__PURE__*/memo(function (_ref) {
9
+ var editing = _ref.editing,
10
+ onChange = _ref.onChange,
11
+ onEditingChange = _ref.onEditingChange,
12
+ text = _ref.text,
13
+ message = _ref.message,
14
+ placement = _ref.placement,
15
+ messageExtra = _ref.messageExtra,
16
+ renderMessage = _ref.renderMessage,
17
+ type = _ref.type,
18
+ primary = _ref.primary,
19
+ onDoubleClick = _ref.onDoubleClick,
20
+ fontSize = _ref.fontSize,
21
+ markdownProps = _ref.markdownProps,
22
+ markdownClassname = _ref.markdownClassname;
23
+ var _useStyles = useStyles({
24
+ editing: editing,
25
+ placement: placement,
26
+ primary: primary,
27
+ type: type
28
+ }),
29
+ cx = _useStyles.cx,
30
+ styles = _useStyles.styles;
31
+ var _useResponsive = useResponsive(),
32
+ mobile = _useResponsive.mobile;
33
+ var content = /*#__PURE__*/_jsx(EditableMessage, {
34
+ classNames: {
35
+ input: styles.editingInput,
36
+ markdown: markdownClassname
37
+ },
38
+ editButtonSize: 'small',
39
+ editing: editing,
40
+ fontSize: fontSize,
41
+ fullFeaturedCodeBlock: true,
42
+ markdownProps: markdownProps,
43
+ onChange: onChange,
44
+ onEditingChange: onEditingChange,
45
+ openModal: mobile ? editing : undefined,
46
+ text: text,
47
+ value: message ? String(message).trim() : ''
48
+ });
49
+ var messageContent = renderMessage ? renderMessage(content) : content;
50
+ return /*#__PURE__*/_jsxs(Flexbox, {
51
+ className: cx(styles.message, editing && styles.editingContainer),
52
+ onDoubleClick: onDoubleClick,
53
+ children: [messageContent, messageExtra && !editing ? /*#__PURE__*/_jsx("div", {
54
+ className: styles.messageExtra,
55
+ children: messageExtra
56
+ }) : null]
57
+ });
58
+ });
59
+ export default MessageContent;
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ import { ChatItemProps } from './type';
3
+ declare const ChatItem: import("react").NamedExoticComponent<ChatItemProps>;
4
+ export default ChatItem;
5
+ export type { ChatItemProps } from './type';
@@ -0,0 +1,121 @@
1
+ 'use client';
2
+
3
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
4
+ import _objectWithoutProperties from "@babel/runtime/helpers/esm/objectWithoutProperties";
5
+ var _excluded = ["avatarAddon", "onAvatarClick", "avatarProps", "actions", "className", "primary", "loading", "message", "placement", "type", "avatar", "error", "showTitle", "time", "editing", "onChange", "onEditingChange", "messageExtra", "renderMessage", "text", "errorMessage", "onDoubleClick", "fontSize", "markdownProps", "markdownClassname"];
6
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
7
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
8
+ import Actions from '@lobehub/ui/es/ChatItem/components/Actions';
9
+ import Avatar from '@lobehub/ui/es/ChatItem/components/Avatar';
10
+ import BorderSpacing from '@lobehub/ui/es/ChatItem/components/BorderSpacing';
11
+ import ErrorContent from '@lobehub/ui/es/ChatItem/components/ErrorContent';
12
+ import Title from '@lobehub/ui/es/ChatItem/components/Title';
13
+ import { useStyles } from '@lobehub/ui/es/ChatItem/style';
14
+ import { useResponsive } from 'antd-style';
15
+ import { memo } from 'react';
16
+ import { Flexbox } from 'react-layout-kit';
17
+ import MessageContent from "./components/MessageContent";
18
+ import { jsx as _jsx } from "react/jsx-runtime";
19
+ import { jsxs as _jsxs } from "react/jsx-runtime";
20
+ var MOBILE_AVATAR_SIZE = 32;
21
+ var ChatItem = /*#__PURE__*/memo(function (_ref) {
22
+ var avatarAddon = _ref.avatarAddon,
23
+ onAvatarClick = _ref.onAvatarClick,
24
+ avatarProps = _ref.avatarProps,
25
+ actions = _ref.actions,
26
+ className = _ref.className,
27
+ primary = _ref.primary,
28
+ loading = _ref.loading,
29
+ message = _ref.message,
30
+ _ref$placement = _ref.placement,
31
+ placement = _ref$placement === void 0 ? 'left' : _ref$placement,
32
+ _ref$type = _ref.type,
33
+ type = _ref$type === void 0 ? 'block' : _ref$type,
34
+ avatar = _ref.avatar,
35
+ error = _ref.error,
36
+ showTitle = _ref.showTitle,
37
+ time = _ref.time,
38
+ editing = _ref.editing,
39
+ onChange = _ref.onChange,
40
+ onEditingChange = _ref.onEditingChange,
41
+ messageExtra = _ref.messageExtra,
42
+ renderMessage = _ref.renderMessage,
43
+ text = _ref.text,
44
+ errorMessage = _ref.errorMessage,
45
+ onDoubleClick = _ref.onDoubleClick,
46
+ fontSize = _ref.fontSize,
47
+ markdownProps = _ref.markdownProps,
48
+ markdownClassname = _ref.markdownClassname,
49
+ rest = _objectWithoutProperties(_ref, _excluded);
50
+ var _useResponsive = useResponsive(),
51
+ mobile = _useResponsive.mobile;
52
+ var _useStyles = useStyles({
53
+ editing: editing,
54
+ placement: placement,
55
+ primary: primary,
56
+ showTitle: showTitle,
57
+ time: time,
58
+ title: avatar.title,
59
+ type: type
60
+ }),
61
+ cx = _useStyles.cx,
62
+ styles = _useStyles.styles;
63
+ return /*#__PURE__*/_jsxs(Flexbox, _objectSpread(_objectSpread({
64
+ className: cx(styles.container, className),
65
+ direction: placement === 'left' ? 'horizontal' : 'horizontal-reverse',
66
+ gap: mobile ? 6 : 12
67
+ }, rest), {}, {
68
+ children: [/*#__PURE__*/_jsx(Avatar, _objectSpread(_objectSpread({}, avatarProps), {}, {
69
+ addon: avatarAddon,
70
+ avatar: avatar,
71
+ loading: loading,
72
+ onClick: onAvatarClick,
73
+ placement: placement,
74
+ size: mobile ? MOBILE_AVATAR_SIZE : undefined
75
+ })), /*#__PURE__*/_jsxs(Flexbox, {
76
+ align: placement === 'left' ? 'flex-start' : 'flex-end',
77
+ className: styles.messageContainer,
78
+ children: [/*#__PURE__*/_jsx(Title, {
79
+ avatar: avatar,
80
+ placement: placement,
81
+ showTitle: showTitle,
82
+ time: time
83
+ }), /*#__PURE__*/_jsxs(Flexbox, {
84
+ align: placement === 'left' ? 'flex-start' : 'flex-end',
85
+ className: styles.messageContent,
86
+ direction:
87
+ // eslint-disable-next-line no-nested-ternary
88
+ type === 'block' ? placement === 'left' ? 'horizontal' : 'horizontal-reverse' : 'vertical',
89
+ gap: 8,
90
+ children: [error ? /*#__PURE__*/_jsx(ErrorContent, {
91
+ error: error,
92
+ message: errorMessage,
93
+ placement: placement
94
+ }) : /*#__PURE__*/_jsx(MessageContent, {
95
+ editing: editing,
96
+ fontSize: fontSize,
97
+ markdownClassname: markdownClassname,
98
+ markdownProps: markdownProps,
99
+ message: message,
100
+ messageExtra: messageExtra,
101
+ onChange: onChange,
102
+ onDoubleClick: onDoubleClick,
103
+ onEditingChange: onEditingChange,
104
+ placement: placement,
105
+ primary: primary,
106
+ renderMessage: renderMessage,
107
+ text: text,
108
+ type: type
109
+ }), /*#__PURE__*/_jsx(Actions, {
110
+ actions: actions,
111
+ editing: editing,
112
+ placement: placement,
113
+ type: type
114
+ })]
115
+ })]
116
+ }), mobile && type === 'block' && /*#__PURE__*/_jsx(BorderSpacing, {
117
+ borderSpacing: MOBILE_AVATAR_SIZE
118
+ })]
119
+ }));
120
+ });
121
+ export default ChatItem;
@@ -0,0 +1,24 @@
1
+ export declare const useStyles: (props?: {
2
+ avatarSize?: number | undefined;
3
+ editing?: boolean | undefined;
4
+ placement?: "left" | "right" | undefined;
5
+ primary?: boolean | undefined;
6
+ showTitle?: boolean | undefined;
7
+ time?: number | undefined;
8
+ title?: string | undefined;
9
+ type?: "block" | "pure" | undefined;
10
+ } | undefined) => import("antd-style").ReturnStyles<{
11
+ actions: string;
12
+ avatarContainer: import("antd-style").SerializedStyles;
13
+ avatarGroupContainer: import("antd-style").SerializedStyles;
14
+ container: string;
15
+ editingContainer: string;
16
+ editingInput: import("antd-style").SerializedStyles;
17
+ errorContainer: import("antd-style").SerializedStyles;
18
+ loading: import("antd-style").SerializedStyles;
19
+ message: string;
20
+ messageContainer: string;
21
+ messageContent: string;
22
+ messageExtra: string;
23
+ name: import("antd-style").SerializedStyles;
24
+ }>;
@@ -0,0 +1,38 @@
1
+ import _taggedTemplateLiteral from "@babel/runtime/helpers/esm/taggedTemplateLiteral";
2
+ var _templateObject, _templateObject2, _templateObject3, _templateObject4, _templateObject5, _templateObject6, _templateObject7, _templateObject8, _templateObject9, _templateObject10, _templateObject11, _templateObject12, _templateObject13, _templateObject14, _templateObject15, _templateObject16, _templateObject17, _templateObject18;
3
+ /* eslint-disable no-nested-ternary */
4
+ import { createStyles } from 'antd-style';
5
+ export var useStyles = createStyles(function (_ref, _ref2) {
6
+ var cx = _ref.cx,
7
+ css = _ref.css,
8
+ token = _ref.token,
9
+ isDarkMode = _ref.isDarkMode,
10
+ responsive = _ref.responsive;
11
+ var placement = _ref2.placement,
12
+ type = _ref2.type,
13
+ title = _ref2.title,
14
+ primary = _ref2.primary,
15
+ avatarSize = _ref2.avatarSize,
16
+ editing = _ref2.editing,
17
+ time = _ref2.time;
18
+ var blockStylish = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n padding-block: 8px;\n padding-inline: 12px;\n\n background-color: ", ";\n border-radius: ", "px;\n\n transition: background-color 100ms ", ";\n "])), primary ? isDarkMode ? token.colorFill : token.colorBgElevated : isDarkMode ? token.colorFillSecondary : token.colorBgContainer, token.borderRadiusLG, token.motionEaseOut);
19
+ var pureStylish = css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n padding-block-start: ", ";\n "])), title ? 0 : '6px');
20
+ var pureContainerStylish = css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n margin-block-end: -16px;\n transition: background-color 100ms ", ";\n "])), token.motionEaseOut);
21
+ var typeStylish = type === 'block' ? blockStylish : pureStylish;
22
+ var editingStylish = editing && css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n width: 100%;\n "])));
23
+ return {
24
+ actions: cx(css(_templateObject5 || (_templateObject5 = _taggedTemplateLiteral(["\n flex: none;\n align-self: ", ";\n justify-content: ", ";\n "])), type === 'block' ? 'flex-end' : placement === 'left' ? 'flex-start' : 'flex-end', placement === 'left' ? 'flex-end' : 'flex-start'), editing && css(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n pointer-events: none !important;\n opacity: 0 !important;\n "])))),
25
+ avatarContainer: css(_templateObject7 || (_templateObject7 = _taggedTemplateLiteral(["\n position: relative;\n flex: none;\n width: ", "px;\n height: ", "px;\n "])), avatarSize, avatarSize),
26
+ avatarGroupContainer: css(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["\n width: ", "px;\n "])), avatarSize),
27
+ container: cx(type === 'pure' && pureContainerStylish, css(_templateObject9 || (_templateObject9 = _taggedTemplateLiteral(["\n position: relative;\n width: 100%;\n max-width: 100vw;\n padding: 16px;\n\n time {\n display: inline-block;\n white-space: nowrap;\n }\n\n div[role='menubar'] {\n display: flex;\n }\n\n time,\n div[role='menubar'] {\n pointer-events: none;\n opacity: 0;\n transition: opacity 200ms ", ";\n }\n\n &:hover {\n time,\n div[role='menubar'] {\n pointer-events: unset;\n opacity: 1;\n }\n }\n\n ", " {\n padding-block: ", ";\n padding-inline: 8px;\n }\n "])), token.motionEaseOut, responsive.mobile, type === 'pure' ? '12px' : '6px')),
28
+ editingContainer: cx(editingStylish, css(_templateObject10 || (_templateObject10 = _taggedTemplateLiteral(["\n padding-block: 8px 12px;\n padding-inline: 12px;\n border: 1px solid ", ";\n\n &:active,\n &:hover {\n border-color: ", ";\n }\n "])), token.colorBorderSecondary, token.colorBorder), type === 'pure' && css(_templateObject11 || (_templateObject11 = _taggedTemplateLiteral(["\n background: ", ";\n border-radius: ", "px;\n "])), token.colorFillQuaternary, token.borderRadius)),
29
+ editingInput: css(_templateObject12 || (_templateObject12 = _taggedTemplateLiteral(["\n width: 100%;\n "]))),
30
+ errorContainer: css(_templateObject13 || (_templateObject13 = _taggedTemplateLiteral(["\n position: relative;\n overflow: hidden;\n width: 100%;\n "]))),
31
+ loading: css(_templateObject14 || (_templateObject14 = _taggedTemplateLiteral(["\n position: absolute;\n inset-block-end: 0;\n inset-inline: ", "\n ", ";\n\n width: 16px;\n height: 16px;\n\n color: ", ";\n\n background: ", ";\n border-radius: 50%;\n "])), placement === 'right' ? '-4px' : 'unset', placement === 'left' ? '-4px' : 'unset', token.colorBgLayout, token.colorPrimary),
32
+ message: cx(typeStylish, css(_templateObject15 || (_templateObject15 = _taggedTemplateLiteral(["\n position: relative;\n overflow: hidden;\n max-width: 100%;\n\n ", " {\n width: 100%;\n }\n "])), responsive.mobile)),
33
+ messageContainer: cx(editingStylish, css(_templateObject16 || (_templateObject16 = _taggedTemplateLiteral(["\n position: relative;\n overflow: hidden;\n max-width: 100%;\n margin-block-start: ", "px;\n\n ", " {\n overflow-x: auto;\n }\n "])), time ? -16 : 0, responsive.mobile)),
34
+ messageContent: cx(editingStylish, css(_templateObject17 || (_templateObject17 = _taggedTemplateLiteral(["\n position: relative;\n overflow: hidden;\n max-width: 100%;\n\n ", " {\n flex-direction: column !important;\n }\n "])), responsive.mobile)),
35
+ messageExtra: cx('message-extra'),
36
+ name: css(_templateObject18 || (_templateObject18 = _taggedTemplateLiteral(["\n pointer-events: none;\n\n margin-block-end: 6px;\n\n font-size: 12px;\n line-height: 1;\n color: ", ";\n text-align: ", ";\n "])), token.colorTextDescription, placement === 'left' ? 'left' : 'right')
37
+ };
38
+ });
@@ -0,0 +1,81 @@
1
+ import { AlertProps, AvatarProps, DivProps, EditableMessageProps, MarkdownProps, MetaData } from '@lobehub/ui';
2
+ import { ReactNode } from 'react';
3
+ export interface ChatItemProps {
4
+ /**
5
+ * @description Actions to be displayed in the chat item
6
+ */
7
+ actions?: ReactNode;
8
+ /**
9
+ * @description Metadata for the avatar
10
+ */
11
+ avatar: MetaData;
12
+ avatarAddon?: ReactNode;
13
+ avatarProps?: AvatarProps;
14
+ /**
15
+ * @description Custom CSS class name for the chat item
16
+ */
17
+ className?: string;
18
+ /**
19
+ * @description Whether the chat item is in editing mode
20
+ */
21
+ editing?: boolean;
22
+ /**
23
+ * @description Props for Error render
24
+ */
25
+ error?: AlertProps;
26
+ errorMessage?: ReactNode;
27
+ fontSize?: number;
28
+ /**
29
+ * @description Whether the chat item is in loading state
30
+ */
31
+ loading?: boolean;
32
+ /**
33
+ * @description The message content of the chat item
34
+ */
35
+ message?: ReactNode;
36
+ messageExtra?: ReactNode;
37
+ onAvatarClick?: () => void;
38
+ /**
39
+ * @description Callback when the message content changes
40
+ * @param value - The new message content
41
+ */
42
+ onChange?: (value: string) => void;
43
+ onDoubleClick?: DivProps['onDoubleClick'];
44
+ /**
45
+ * @description Callback when the editing mode changes
46
+ * @param editing - The new editing mode
47
+ */
48
+ onEditingChange?: (editing: boolean) => void;
49
+ /**
50
+ * @description The placement of the chat item
51
+ * @default 'left'
52
+ */
53
+ placement?: 'left' | 'right';
54
+ /**
55
+ * @description Whether the chat item is primary
56
+ */
57
+ primary?: boolean;
58
+ renderMessage?: (content: ReactNode) => ReactNode;
59
+ /**
60
+ * @description Whether to show the title of the chat item
61
+ */
62
+ showTitle?: boolean;
63
+ text?: EditableMessageProps['text'];
64
+ /**
65
+ * @description The timestamp of the chat item
66
+ */
67
+ time?: number;
68
+ /**
69
+ * @description The type of the chat item
70
+ * @default 'block'
71
+ */
72
+ type?: 'block' | 'pure';
73
+ /**
74
+ * @description The markdownProps of the chat item
75
+ */
76
+ markdownProps?: MarkdownProps;
77
+ /**
78
+ * @description The markdownClassname of the chat item
79
+ */
80
+ markdownClassname?: string;
81
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,76 @@
1
+ import { MarkdownProps, type MessageInputProps, type MessageModalProps } from '@lobehub/ui';
2
+ import { CSSProperties } from 'react';
3
+ export interface EditableMessageProps {
4
+ /**
5
+ * @title The class name for the Markdown and MessageInput component
6
+ */
7
+ classNames?: {
8
+ /**
9
+ * @title The class name for the MessageInput component
10
+ */
11
+ input?: string;
12
+ /**
13
+ * @title The class name for the Markdown component
14
+ */
15
+ markdown?: string;
16
+ textarea?: string;
17
+ };
18
+ editButtonSize?: MessageInputProps['editButtonSize'];
19
+ /**
20
+ * @title Whether the component is in edit mode or not
21
+ * @default false
22
+ */
23
+ editing?: boolean;
24
+ fontSize?: number;
25
+ fullFeaturedCodeBlock?: boolean;
26
+ height?: MessageInputProps['height'];
27
+ inputType?: MessageInputProps['type'];
28
+ model?: {
29
+ extra?: MessageModalProps['extra'];
30
+ footer?: MessageModalProps['footer'];
31
+ };
32
+ /**
33
+ * @title Callback function when the value changes
34
+ * @param value - The new value
35
+ */
36
+ onChange?: (value: string) => void;
37
+ /**
38
+ * @title Callback function when the editing state changes
39
+ * @param editing - Whether the component is in edit mode or not
40
+ */
41
+ onEditingChange?: (editing: boolean) => void;
42
+ /**
43
+ * @title Callback function when the modal open state changes
44
+ * @param open - Whether the modal is open or not
45
+ */
46
+ onOpenChange?: (open: boolean) => void;
47
+ /**
48
+ * @title Whether the modal is open or not
49
+ * @default false
50
+ */
51
+ openModal?: boolean;
52
+ placeholder?: string;
53
+ /**
54
+ * @title Whether to show the edit button when the text value is empty
55
+ * @default false
56
+ */
57
+ showEditWhenEmpty?: boolean;
58
+ styles?: {
59
+ /**
60
+ * @title The style for the MessageInput component
61
+ */
62
+ input?: CSSProperties;
63
+ /**
64
+ * @title The style for the Markdown component
65
+ */
66
+ markdown?: CSSProperties;
67
+ };
68
+ text?: MessageModalProps['text'];
69
+ /**
70
+ * @title The current text value
71
+ */
72
+ value: string;
73
+ markdownProps?: MarkdownProps;
74
+ }
75
+ declare const EditableMessage: import("react").NamedExoticComponent<EditableMessageProps>;
76
+ export default EditableMessage;
@@ -0,0 +1,100 @@
1
+ 'use client';
2
+
3
+ import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
4
+ import _slicedToArray from "@babel/runtime/helpers/esm/slicedToArray";
5
+ function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
6
+ function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
7
+ import { Markdown, MessageInput, MessageModal } from '@lobehub/ui';
8
+ import { memo } from 'react';
9
+ import useControlledState from 'use-merge-value';
10
+ import { jsx as _jsx } from "react/jsx-runtime";
11
+ import { Fragment as _Fragment } from "react/jsx-runtime";
12
+ import { jsxs as _jsxs } from "react/jsx-runtime";
13
+ var EditableMessage = /*#__PURE__*/memo(function (_ref) {
14
+ var value = _ref.value,
15
+ onChange = _ref.onChange,
16
+ _ref$classNames = _ref.classNames,
17
+ classNames = _ref$classNames === void 0 ? {} : _ref$classNames,
18
+ onEditingChange = _ref.onEditingChange,
19
+ editing = _ref.editing,
20
+ openModal = _ref.openModal,
21
+ onOpenChange = _ref.onOpenChange,
22
+ placeholder = _ref.placeholder,
23
+ _ref$showEditWhenEmpt = _ref.showEditWhenEmpty,
24
+ showEditWhenEmpty = _ref$showEditWhenEmpt === void 0 ? false : _ref$showEditWhenEmpt,
25
+ stylesProps = _ref.styles,
26
+ height = _ref.height,
27
+ inputType = _ref.inputType,
28
+ editButtonSize = _ref.editButtonSize,
29
+ text = _ref.text,
30
+ fullFeaturedCodeBlock = _ref.fullFeaturedCodeBlock,
31
+ model = _ref.model,
32
+ fontSize = _ref.fontSize,
33
+ markdownProps = _ref.markdownProps;
34
+ var _useControlledState = useControlledState(false, {
35
+ onChange: onEditingChange,
36
+ value: editing
37
+ }),
38
+ _useControlledState2 = _slicedToArray(_useControlledState, 2),
39
+ isEdit = _useControlledState2[0],
40
+ setTyping = _useControlledState2[1];
41
+ var _useControlledState3 = useControlledState(false, {
42
+ onChange: onOpenChange,
43
+ value: openModal
44
+ }),
45
+ _useControlledState4 = _slicedToArray(_useControlledState3, 2),
46
+ expand = _useControlledState4[0],
47
+ setExpand = _useControlledState4[1];
48
+ var isAutoSize = height === 'auto';
49
+ var input = /*#__PURE__*/_jsx(MessageInput, {
50
+ className: classNames === null || classNames === void 0 ? void 0 : classNames.input,
51
+ classNames: {
52
+ textarea: classNames === null || classNames === void 0 ? void 0 : classNames.textarea
53
+ },
54
+ defaultValue: value,
55
+ editButtonSize: editButtonSize,
56
+ height: height,
57
+ onCancel: function onCancel() {
58
+ return setTyping(false);
59
+ },
60
+ onConfirm: function onConfirm(text) {
61
+ onChange === null || onChange === void 0 || onChange(text);
62
+ setTyping(false);
63
+ },
64
+ placeholder: placeholder,
65
+ style: stylesProps === null || stylesProps === void 0 ? void 0 : stylesProps.input,
66
+ text: text,
67
+ textareaClassname: classNames === null || classNames === void 0 ? void 0 : classNames.input,
68
+ type: inputType
69
+ });
70
+ if (!value && showEditWhenEmpty) return input;
71
+ return /*#__PURE__*/_jsxs(_Fragment, {
72
+ children: [!expand && isEdit ? input : /*#__PURE__*/_jsx(Markdown, _objectSpread(_objectSpread({
73
+ className: classNames === null || classNames === void 0 ? void 0 : classNames.markdown,
74
+ fontSize: fontSize,
75
+ fullFeaturedCodeBlock: fullFeaturedCodeBlock,
76
+ style: _objectSpread({
77
+ height: isAutoSize ? 'unset' : height
78
+ }, stylesProps === null || stylesProps === void 0 ? void 0 : stylesProps.markdown),
79
+ variant: 'chat'
80
+ }, markdownProps), {}, {
81
+ children: value || placeholder || ''
82
+ })), expand && /*#__PURE__*/_jsx(MessageModal, {
83
+ editing: isEdit,
84
+ extra: model === null || model === void 0 ? void 0 : model.extra,
85
+ footer: model === null || model === void 0 ? void 0 : model.footer,
86
+ height: height,
87
+ onChange: onChange,
88
+ onEditingChange: setTyping,
89
+ onOpenChange: function onOpenChange(e) {
90
+ setExpand(e);
91
+ setTyping(false);
92
+ },
93
+ open: expand,
94
+ placeholder: placeholder,
95
+ text: text,
96
+ value: value
97
+ })]
98
+ });
99
+ });
100
+ export default EditableMessage;
package/es/index.d.ts CHANGED
@@ -26,6 +26,8 @@ export * from './Table';
26
26
  export * from './Tree';
27
27
  export * from './Typography';
28
28
  export * from './ChatInputArea';
29
+ export * from './ChatItem';
30
+ export * from './EditableMessage';
29
31
  export * from './Highlighter';
30
32
  export * from './styles';
31
33
  export { Affix, type AffixProps, Anchor, type AnchorProps, type MentionProps as AntdMentionProps, Mentions as AntdMentions, AutoComplete, type AutoCompleteProps, Avatar, type AvatarProps, BackTop, type BackTopProps, Badge, // @todo composed type
package/es/index.js CHANGED
@@ -30,6 +30,8 @@ export * from "./Typography";
30
30
 
31
31
  // ~ custom @lobehub/ui
32
32
  export * from "./ChatInputArea";
33
+ export * from "./ChatItem";
34
+ export * from "./EditableMessage";
33
35
  export * from "./Highlighter";
34
36
  export * from "./styles";
35
37
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@yuntijs/ui",
3
- "version": "1.0.0-beta.57",
3
+ "version": "1.0.0-beta.58",
4
4
  "description": "☁️ Yunti UI - an open-source UI component library for building Cloud Native web apps",
5
5
  "keywords": [
6
6
  "yuntijs",
@@ -100,7 +100,8 @@
100
100
  "react-layout-kit": "^1",
101
101
  "shiki": "^1.10.3",
102
102
  "swr": "^2.2.5",
103
- "url-join": "^5.0.0"
103
+ "url-join": "^5.0.0",
104
+ "use-merge-value": "^1.2.0"
104
105
  },
105
106
  "devDependencies": {
106
107
  "@testing-library/react": "^14",