diff --git a/web/src/components/Chat/ChatContent.tsx b/web/src/components/Chat/ChatContent.tsx index 4b5a83a8..7ff9f9f5 100644 --- a/web/src/components/Chat/ChatContent.tsx +++ b/web/src/components/Chat/ChatContent.tsx @@ -2,7 +2,7 @@ * @Author: ZhaoYing * @Date: 2025-12-10 16:46:17 * @Last Modified by: ZhaoYing - * @Last Modified time: 2026-04-07 21:29:59 + * @Last Modified time: 2026-04-07 22:13:47 */ import { type FC, useRef, useEffect, useState } from 'react' import clsx from 'clsx' @@ -284,7 +284,7 @@ const ChatContent: FC = ({ } {/* Bottom label (such as timestamp, username, etc.) */} - {labelPosition === 'bottom' && + {(labelPosition === 'bottom' || item.meta_data?.audio_url) && {item.meta_data?.audio_url && <> {playingIndex !== item.meta_data?.audio_url && item.meta_data?.audio_status === 'pending' ? @@ -299,9 +299,9 @@ const ChatContent: FC = ({ /> } } -
+ {labelPosition === 'bottom' &&
{labelFormat(item)} -
+
}
} diff --git a/web/src/components/Markdown/index.tsx b/web/src/components/Markdown/index.tsx index 10cf177b..bd33cf76 100644 --- a/web/src/components/Markdown/index.tsx +++ b/web/src/components/Markdown/index.tsx @@ -2,7 +2,7 @@ * @Author: ZhaoYing * @Date: 2026-02-02 15:17:31 * @Last Modified by: ZhaoYing - * @Last Modified time: 2026-04-07 15:14:02 + * @Last Modified time: 2026-04-07 21:56:00 */ /** * RbMarkdown Component @@ -22,7 +22,7 @@ * @component */ -import { useState, useRef, useEffect, type FC, createContext, useContext, useCallback } from 'react' +import { useState, useRef, useEffect, type FC, createContext, useContext, useCallback, useMemo } from 'react' import { Image, Input, Select, Form, Checkbox, Radio, ColorPicker, DatePicker, TimePicker, InputNumber, Slider } from 'antd' import ReactMarkdown from 'react-markdown' import RemarkGfm from 'remark-gfm' @@ -44,6 +44,11 @@ const FormContext = createContext<{ onSubmit?: (values: Record) => void; } | null>(null) +/** Stable form wrapper component — state lives in RbMarkdown, survives components object rebuilds */ +const RbForm: FC = ({ children, ...props }) => ( +
{children}
+) + /** Props interface for RbMarkdown component */ interface RbMarkdownProps { /** Markdown content to render */ @@ -60,8 +65,8 @@ interface RbMarkdownProps { onFormSubmit?: (values: Record) => void; } -/** Build components with onFormSubmit callback */ -const buildComponents = (onFormSubmit?: (values: Record) => void) => ({ +/** Build stable components map — form submission handled via FormContext */ +const buildComponents = () => ({ h1: ({ children, ...props }: any) =>

{children}

, h2: ({ children, ...props }: any) =>

{children}

, h3: ({ children, ...props }: any) =>

{children}

, @@ -95,49 +100,50 @@ const buildComponents = (onFormSubmit?: (values: Record) => void) = td: ({ children, ...props }: any) => {children}, button: ({ children, ...props }: any) => { const ctx = useContext(FormContext) - return ctx?.onSubmit?.(ctx.values)}>{[children]} + return ctx?.onSubmit?.(ctx?.values ?? {})}>{[children]} }, - input: ({ children, ...props }: any) => { + input: ({ children, value, ...props }: any) => { const ctx = useContext(FormContext) const handleChange = useCallback((val: any) => { if (props.name) ctx?.setValue(props.name, val) }, [ctx, props.name]) + console.log('props', props) switch (props.type) { case 'color': - return + return case 'time': - return + return case 'date': - return + return case 'datetime': case 'datetime-local': - return + return case 'week': - return + return case 'month': - return + return case 'number': - return + return case 'search': - return handleChange(e.target.value)} /> + return handleChange(e.target.value)} /> case 'range': - return + return case 'submit': case 'button': - return ctx?.onSubmit?.(ctx.values)}>{[props.value || children]} + return ctx?.onSubmit?.(ctx?.values ?? {})}>{[props.value || children]} case 'checkbox': - return handleChange(e.target.checked)}>{children} + return handleChange(e.target.checked)}>{children} case 'password': - return handleChange(e.target.value)} /> + return handleChange(e.target.value)} /> case 'radio': - return handleChange(e.target.value)}>{children} + return handleChange(e.target.value)}>{children} case 'select': { const raw = props['data-options'] const options = (typeof raw === 'string' ? JSON.parse(raw) : raw || []).map((v: string) => ({ label: v, value: v })) - return { if (props.name) ctx?.setValue(props.name, val) }} /> } default: - return handleChange(e.target.value)} /> + return handleChange(e.target.value)} /> } }, select: ({ children, ...props }: any) => { @@ -148,15 +154,7 @@ const buildComponents = (onFormSubmit?: (values: Record) => void) = const ctx = useContext(FormContext) return { if (props.name) ctx?.setValue(props.name, e.target.value) }}>{children} }, - form: ({ children, ...props }: any) => { - const [values, setValues] = useState>({}) - const setValue = useCallback((name: string, value: any) => setValues(prev => ({ ...prev, [name]: value })), []) - return ( - -
{children}
-
- ) - }, + form: RbForm, label: ({ children, ...props }: any) => { return }, @@ -171,7 +169,10 @@ const RbMarkdown: FC = ({ className, onFormSubmit, }) => { - const components = buildComponents(onFormSubmit) + const [formValues, setFormValues] = useState>({}) + const setValue = useCallback((name: string, value: any) => setFormValues(prev => ({ ...prev, [name]: value })), []) + const formCtx = useMemo(() => ({ values: formValues, setValue, onSubmit: onFormSubmit }), [formValues, setValue, onFormSubmit]) + const components = useMemo(() => buildComponents(), []) const [editContent, setEditContent] = useState(content) const textareaRef = useRef(null) @@ -238,6 +239,7 @@ const RbMarkdown: FC = ({ /** Render markdown preview mode */ return ( +