Files
pipelines/app/lib/features/chat/ui/transcript/chat_attachment_gallery.dart
T
alan 7d2c3412a1 Paper design: warm paper, serif reading text and a typeset transcript
Adds the Paper design and generalises design tokens (transcript, composer,
selected-row styles, reading type, panel fill, chat colour saturation).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-03 18:00:07 +00:00

60 lines
2.1 KiB
Dart

import 'package:flutter/widgets.dart';
import '../../../../core/api_gateway.dart';
import '../../../../ui/theme/app_design_tokens.dart';
import '../../data/chat_attachment_images.dart';
import '../../domain/chat_attachment_image.dart';
import 'chat_attachment_thumbnail.dart';
/// Whether a file part draws as a thumbnail: a raster image whose bytes the
/// client can reach (inline, the server's attachment store or a fresh upload).
bool chatPartIsThumbnail(JsonMap part) =>
chatPartImageMime(part) != null &&
chatImageSourceOf('${part['uri'] ?? ''}'.trim()) != null;
/// The operator's attached images above their message, end-aligned like the
/// turn itself (start-aligned under a manuscript's block quote), wrapping
/// onto further lines on a narrow pane.
class ChatAttachmentGallery extends StatelessWidget {
const ChatAttachmentGallery({
super.key,
required this.parts,
required this.images,
});
/// File parts for which [chatPartIsThumbnail] holds.
final List<JsonMap> parts;
final ChatAttachmentImages images;
@override
Widget build(BuildContext context) => Wrap(
key: const Key('chat-attachment-gallery'),
alignment:
AppDesignTokens.of(context).transcript == TranscriptStyle.manuscript
? WrapAlignment.start
: WrapAlignment.end,
spacing: 8,
runSpacing: 8,
children: [
for (final (index, part) in parts.indexed)
ChatAttachmentThumbnail(
key: ValueKey<String>('chat-attachment-image-$index'),
name: chatAttachmentPartName(part),
uri: '${part['uri'] ?? ''}'.trim(),
images: images,
),
],
);
}
/// The web's attachment name rule: its own name, else the URI basename, else
/// `file`. A `data:` URI has no useful basename, so it reads `image`.
String chatAttachmentPartName(JsonMap part) {
final name = '${part['name'] ?? ''}'.trim();
if (name.isNotEmpty) return name;
final uri = '${part['uri'] ?? ''}'.trim();
if (uri.startsWith('data:')) return 'image';
final basename = uri.split('/').last.trim();
return basename.isEmpty ? 'file' : basename;
}