Skip to content

armgit / cindy

Public Imported from GitHub
0

Consider it done. The open-source AI agent that works out of the box · 想到,就能做到。开源、开箱即用的 AI Agent。

fix(mail): 对齐草稿中换行后的附件

Dash78dc3979aebd
diff --git a/apps/desktop/src/renderer/components/chat/GhostCardForm.tsx b/apps/desktop/src/renderer/components/chat/GhostCardForm.tsx
index dfc4e97106..4a84d71e62 100644
--- a/apps/desktop/src/renderer/components/chat/GhostCardForm.tsx
+++ b/apps/desktop/src/renderer/components/chat/GhostCardForm.tsx
@@ -56,37 +56,118 @@ export function GhostCardForm({
<div className="flex flex-wrap gap-x-2 p-3">
{fields.map((field) => {
if (field.kind === 'hidden') return null;
- if (field.kind === 'mail-html') return <MailHtmlPreview key={field.name} value={values[field.name]} images={mailPreviewImages(values, images)} disabled={disabled} reading={expanded} onEnlarge={onEnlarge}
- onChange={readOnly ? undefined : (html, text) => {
- const plain = field.name === 'quoteHtml' ? 'quote' : 'body';
- const next = { ...values, [field.name]: html, ...(plain in values ? { [plain]: text } : {}) };
- setValues(next); onChange(next);
- }} />;
+ if (field.kind === 'mail-html')
+ return (
+ <MailHtmlPreview
+ key={field.name}
+ value={values[field.name]}
+ images={mailPreviewImages(values, images)}
+ disabled={disabled}
+ reading={expanded}
+ onEnlarge={onEnlarge}
+ onChange={
+ readOnly
+ ? undefined
+ : (html, text) => {
+ const plain = field.name === 'quoteHtml' ? 'quote' : 'body';
+ const next = {
+ ...values,
+ [field.name]: html,
+ ...(plain in values ? { [plain]: text } : {}),
+ };
+ setValues(next);
+ onChange(next);
+ }
+ }
+ />
+ );
if (field.kind === 'mail-attachments') {
const files = visibleMailAttachments(values, field.name);
if (!files.length && (readOnly || !onAttach)) return null;
- return <div key={field.name} className="flex w-full flex-wrap gap-2 py-2">
- {!readOnly && onAttach && <button type="button" disabled={disabled} onClick={() => onAttach(false)}
- aria-label={t('chat.ghostCall.mailAttach')} title={t('chat.ghostCall.mailAttach')}
- className="rounded p-1 text-muted-foreground hover:bg-[var(--surface-hover)] disabled:opacity-40"><Paperclip className="h-4 w-4" /></button>}
- {files.map(file => <div key={file.key} className="inline-flex max-w-full items-center gap-1 rounded-lg border border-border bg-[var(--surface)] text-12">
- <button type="button" disabled={!file.previewUrl} onClick={() => setPreview(file.previewUrl)} title={file.filename}
- className="flex min-w-0 items-center gap-2 rounded-lg px-3 py-2 text-left enabled:hover:bg-[var(--surface-hover)]">
- {file.previewUrl ? <img src={file.previewUrl} alt="" className="h-9 w-9 shrink-0 rounded object-cover" /> : <FileTypeIcon name={file.filename} mimeType={file.mimeType} size={20} />}
- <span className="min-w-0"><span className="block truncate">{file.filename}</span><span className="block text-muted-foreground">{file.filename.split('.').pop()?.toUpperCase()}{file.bytes !== undefined ? ' · ' + formatByteSize(file.bytes) : ''}</span></span>
- </button>
- {!readOnly && canInsertMailImage(values, file) && <button type="button" disabled={disabled}
- className="shrink-0 rounded px-2 py-2 text-muted-foreground hover:bg-[var(--surface-hover)] disabled:opacity-40"
- onClick={() => { const next = insertMailImage(values, field.name, file.key); setValues(next); onChange(next); }}>
- {t('chat.ghostCall.mailInsertImage')}
- </button>}
- {!readOnly && <button type="button" disabled={disabled} className="mr-1 rounded p-2 text-muted-foreground hover:bg-[var(--surface-hover)] disabled:opacity-40"
- title={t('chat.ghostCall.mailRemoveAttachment', { name: file.filename })} aria-label={t('chat.ghostCall.mailRemoveAttachment', { name: file.filename })} onClick={() => {
- const next = removeMailAttachment(values, field.name, file.key);
- setValues(next); onChange(next);
- }}><X className="h-3.5 w-3.5" /></button>}
- </div>)}
- </div>;
+ return (
+ <div key={field.name} className="flex w-full items-start gap-2 py-2">
+ {!readOnly && onAttach && (
+ <button
+ type="button"
+ disabled={disabled}
+ onClick={() => onAttach(false)}
+ aria-label={t('chat.ghostCall.mailAttach')}
+ title={t('chat.ghostCall.mailAttach')}
+ className={
+ (files.length ? 'mt-3 ' : '') +
+ 'shrink-0 rounded p-1 text-muted-foreground hover:bg-[var(--surface-hover)] disabled:opacity-40'
+ }
+ >
+ <Paperclip className="h-4 w-4" />
+ </button>
+ )}
+ <div className="flex min-w-0 flex-1 flex-wrap gap-2">
+ {files.map((file) => (
+ <div
+ key={file.key}
+ className="inline-flex max-w-full items-center gap-1 rounded-lg border border-border bg-[var(--surface)] text-12"
+ >
+ <button
+ type="button"
+ disabled={!file.previewUrl}
+ onClick={() => setPreview(file.previewUrl)}
+ title={file.filename}
+ className="flex min-w-0 items-center gap-2 rounded-lg px-3 py-2 text-left enabled:hover:bg-[var(--surface-hover)]"
+ >
+ {file.previewUrl ? (
+ <img
+ src={file.previewUrl}
+ alt=""
+ className="h-9 w-9 shrink-0 rounded object-cover"
+ />
+ ) : (
+ <FileTypeIcon name={file.filename} mimeType={file.mimeType} size={20} />
+ )}
+ <span className="min-w-0">
+ <span className="block truncate">{file.filename}</span>
+ <span className="block text-muted-foreground">
+ {file.filename.split('.').pop()?.toUpperCase()}
+ {file.bytes !== undefined ? ' · ' + formatByteSize(file.bytes) : ''}
+ </span>
+ </span>
+ </button>
+ {!readOnly && canInsertMailImage(values, file) && (
+ <button
+ type="button"
+ disabled={disabled}
+ className="shrink-0 rounded px-2 py-2 text-muted-foreground hover:bg-[var(--surface-hover)] disabled:opacity-40"
+ onClick={() => {
+ const next = insertMailImage(values, field.name, file.key);
+ setValues(next);
+ onChange(next);
+ }}
+ >
+ {t('chat.ghostCall.mailInsertImage')}
+ </button>
+ )}
+ {!readOnly && (
+ <button
+ type="button"
+ disabled={disabled}
+ className="mr-1 rounded p-2 text-muted-foreground hover:bg-[var(--surface-hover)] disabled:opacity-40"
+ title={t('chat.ghostCall.mailRemoveAttachment', { name: file.filename })}
+ aria-label={t('chat.ghostCall.mailRemoveAttachment', {
+ name: file.filename,
+ })}
+ onClick={() => {
+ const next = removeMailAttachment(values, field.name, file.key);
+ setValues(next);
+ onChange(next);
+ }}
+ >
+ <X className="h-3.5 w-3.5" />
+ </button>
+ )}
+ </div>
+ ))}
+ </div>
+ </div>
+ );
}
if (field.kind === 'recipients') {
const group = fields.filter(
@@ -103,7 +184,11 @@ export function GhostCardForm({
/>
);
}
- const control = readOnly ? <div className="whitespace-pre-wrap break-words p-1 text-13 text-foreground">{values[field.name]}</div> : field.multiline ? (
+ const control = readOnly ? (
+ <div className="whitespace-pre-wrap break-words p-1 text-13 text-foreground">
+ {values[field.name]}
+ </div>
+ ) : field.multiline ? (
<CardTextarea
expanded={expanded}
aria-label={field.label}
@@ -148,10 +233,19 @@ export function GhostCardForm({
</span>
)}
<div className="min-w-0 flex-1">
- {field.name === 'body' && onEnlarge && !expanded && <div className="flex justify-end">
- <button type="button" onClick={onEnlarge} title={t('chat.ghostCall.mailEnlarge')} aria-label={t('chat.ghostCall.mailEnlarge')}
- className="rounded p-1 text-muted-foreground hover:bg-[var(--surface-hover)]"><Maximize2 className="h-3.5 w-3.5" /></button>
- </div>}
+ {field.name === 'body' && onEnlarge && !expanded && (
+ <div className="flex justify-end">
+ <button
+ type="button"
+ onClick={onEnlarge}
+ title={t('chat.ghostCall.mailEnlarge')}
+ aria-label={t('chat.ghostCall.mailEnlarge')}
+ className="rounded p-1 text-muted-foreground hover:bg-[var(--surface-hover)]"
+ >
+ <Maximize2 className="h-3.5 w-3.5" />
+ </button>
+ </div>
+ )}
{control}
</div>
</div>