UNPKG

@lobehub/ui

Version:

Lobe UI is an open-source UI component library for building AIGC web apps

80 lines (77 loc) 2.4 kB
'use client'; import Markdown_default from "../../Markdown/Markdown.mjs"; import MessageInput_default from "../MessageInput/MessageInput.mjs"; import MessageModal_default from "../MessageModal/MessageModal.mjs"; import { memo } from "react"; import { Fragment as Fragment$1, jsx, jsxs } from "react/jsx-runtime"; import { cx } from "antd-style"; import useMergeState from "use-merge-value"; //#region src/chat/EditableMessage/EditableMessage.tsx const EditableMessage = memo(({ value, onChange, classNames = {}, onEditingChange, editing, openModal, onOpenChange, placeholder, showEditWhenEmpty = false, styles: customStyles, className, style, height, variant, editButtonSize, text, fullFeaturedCodeBlock, model, fontSize, language = "markdown", markdownProps }) => { const [isEdit, setTyping] = useMergeState(false, { onChange: onEditingChange, value: editing }); const [expand, setExpand] = useMergeState(false, { onChange: onOpenChange, value: openModal }); const isAutoSize = height === "auto"; const input = /* @__PURE__ */ jsx(MessageInput_default, { className: cx(className, classNames?.input), classNames, defaultValue: value, editButtonSize, height, language, onCancel: () => setTyping(false), onConfirm: (text$1) => { onChange?.(text$1); setTyping(false); }, placeholder, shortcut: true, style: { ...style, ...customStyles?.input }, styles: customStyles, text, variant }); if (!value && showEditWhenEmpty) return input; return /* @__PURE__ */ jsxs(Fragment$1, { children: [!expand && isEdit ? input : /* @__PURE__ */ jsx(Markdown_default, { className: cx(className, classNames?.markdown), fontSize, fullFeaturedCodeBlock, style: { height: isAutoSize ? "unset" : height, ...style, ...customStyles?.markdown }, variant: "chat", ...markdownProps, children: value || placeholder || "" }), expand && /* @__PURE__ */ jsx(MessageModal_default, { editing: isEdit, extra: model?.extra, footer: model?.footer, height, language, onChange, onEditingChange: setTyping, onOpenChange: (e) => { setExpand(e); setTyping(false); }, open: expand, placeholder, text, value })] }); }); EditableMessage.displayName = "EditableMessage"; var EditableMessage_default = EditableMessage; //#endregion export { EditableMessage_default as default }; //# sourceMappingURL=EditableMessage.mjs.map