feat(app): download and share artifacts as named files
This commit is contained in:
@@ -5,6 +5,8 @@ import 'package:flutter/services.dart';
|
||||
import '../../../core/api_gateway.dart';
|
||||
import '../../../ui/adaptive/host.dart';
|
||||
import '../../chat/ui/transcript/chat_markdown_view.dart';
|
||||
import '../actions/artifact_file_actions.dart';
|
||||
import '../actions/artifact_file_bridge.dart';
|
||||
import '../domain/artifact_groups.dart';
|
||||
import '../domain/artifact_kind.dart';
|
||||
import '../domain/artifact_record.dart';
|
||||
@@ -28,8 +30,9 @@ const String artifactGalleryTitle = 'Artifacts';
|
||||
/// never fetched); any other selection opens a native dialog with the recorded
|
||||
/// name, MIME and size, the visit's capture facts and, only when the recorded
|
||||
/// url resolves through [resolveArtifactUrl], native `Open` and `Copy link`
|
||||
/// actions. Markdown previews use the same chat markdown renderer by default.
|
||||
/// It never downloads, shares or filters.
|
||||
/// actions plus file `Download`/`Share` for a server-served url. Markdown
|
||||
/// previews use the same chat markdown renderer by default. It never filters,
|
||||
/// and an external url is never fetched for preview or file transfer.
|
||||
class ArtifactGalleryPage extends StatefulWidget {
|
||||
const ArtifactGalleryPage({
|
||||
super.key,
|
||||
@@ -39,6 +42,7 @@ class ArtifactGalleryPage extends StatefulWidget {
|
||||
this.openExternal = openArtifactExternally,
|
||||
this.fetch = fetchArtifact,
|
||||
this.markdownBuilder = chatMarkdownText,
|
||||
this.fileBridge = const ArtifactFileBridge(),
|
||||
});
|
||||
|
||||
final List<JsonMap> steps;
|
||||
@@ -47,6 +51,7 @@ class ArtifactGalleryPage extends StatefulWidget {
|
||||
final ArtifactExternalOpen openExternal;
|
||||
final ArtifactFetch fetch;
|
||||
final ArtifactMarkdownBuilder markdownBuilder;
|
||||
final ArtifactFileBridge fileBridge;
|
||||
|
||||
@override
|
||||
State<ArtifactGalleryPage> createState() => _ArtifactGalleryPageState();
|
||||
@@ -89,6 +94,7 @@ class _ArtifactGalleryPageState extends State<ArtifactGalleryPage> {
|
||||
openExternal: widget.openExternal,
|
||||
fetch: widget.fetch,
|
||||
markdownBuilder: widget.markdownBuilder,
|
||||
fileBridge: widget.fileBridge,
|
||||
),
|
||||
)
|
||||
: MaterialPageRoute<void>(
|
||||
@@ -99,6 +105,7 @@ class _ArtifactGalleryPageState extends State<ArtifactGalleryPage> {
|
||||
openExternal: widget.openExternal,
|
||||
fetch: widget.fetch,
|
||||
markdownBuilder: widget.markdownBuilder,
|
||||
fileBridge: widget.fileBridge,
|
||||
),
|
||||
),
|
||||
);
|
||||
@@ -120,12 +127,31 @@ class _ArtifactGalleryPageState extends State<ArtifactGalleryPage> {
|
||||
step: step,
|
||||
resolved: resolved,
|
||||
);
|
||||
final content = Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
facts,
|
||||
if (resolved != null && !resolved.external) ...[
|
||||
const SizedBox(height: 12),
|
||||
ArtifactFileActions(
|
||||
key: ValueKey<String>(
|
||||
'artifact-files-${artifactVisitIdentity(group, artifact)}',
|
||||
),
|
||||
artifact: artifact,
|
||||
resolved: resolved,
|
||||
fetch: widget.fetch,
|
||||
bridge: widget.fileBridge,
|
||||
),
|
||||
],
|
||||
],
|
||||
);
|
||||
if (usesCupertinoHost(context)) {
|
||||
return showCupertinoDialog<void>(
|
||||
context: context,
|
||||
builder: (dialogContext) => CupertinoAlertDialog(
|
||||
title: Text(artifactDisplayName(artifact)),
|
||||
content: facts,
|
||||
content: content,
|
||||
actions: [
|
||||
if (resolved != null)
|
||||
CupertinoDialogAction(
|
||||
@@ -150,7 +176,7 @@ class _ArtifactGalleryPageState extends State<ArtifactGalleryPage> {
|
||||
context: context,
|
||||
builder: (dialogContext) => AlertDialog(
|
||||
title: Text(artifactDisplayName(artifact)),
|
||||
content: SingleChildScrollView(child: facts),
|
||||
content: SingleChildScrollView(child: content),
|
||||
actions: [
|
||||
if (resolved != null)
|
||||
TextButton(
|
||||
|
||||
@@ -4,17 +4,21 @@ import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../../../ui/adaptive/host.dart';
|
||||
import '../actions/artifact_file_actions.dart';
|
||||
import '../actions/artifact_file_bridge.dart';
|
||||
import '../domain/artifact_preview.dart';
|
||||
import '../domain/artifact_url.dart';
|
||||
import '../domain/gallery_navigation.dart';
|
||||
import 'artifact_selection_facts.dart';
|
||||
import 'artifact_viewer_content.dart';
|
||||
import 'artifact_viewer_fetch.dart';
|
||||
|
||||
/// One viewer page: the recorded facts, position, live status, preview surface,
|
||||
/// external actions and paging controls.
|
||||
/// file transfer actions, external actions and paging controls.
|
||||
///
|
||||
/// It is stateless so the page owns loading, fetch generations and focus; this
|
||||
/// surface only draws the current page and reports the operator's intent.
|
||||
/// surface only draws the current page and reports the operator's intent. The
|
||||
/// page content scrolls as one column at large text sizes; paging stays fixed.
|
||||
class ArtifactViewerBody extends StatelessWidget {
|
||||
const ArtifactViewerBody({
|
||||
super.key,
|
||||
@@ -28,6 +32,8 @@ class ArtifactViewerBody extends StatelessWidget {
|
||||
required this.onNext,
|
||||
required this.onOpen,
|
||||
required this.onCopy,
|
||||
this.fetch = fetchArtifact,
|
||||
this.fileBridge = const ArtifactFileBridge(),
|
||||
this.text,
|
||||
this.bytes,
|
||||
this.error,
|
||||
@@ -44,6 +50,8 @@ class ArtifactViewerBody extends StatelessWidget {
|
||||
final VoidCallback onNext;
|
||||
final VoidCallback onOpen;
|
||||
final VoidCallback onCopy;
|
||||
final ArtifactFetch fetch;
|
||||
final ArtifactFileBridge fileBridge;
|
||||
final String? text;
|
||||
final Uint8List? bytes;
|
||||
final String? error;
|
||||
@@ -54,42 +62,67 @@ class ArtifactViewerBody extends StatelessWidget {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 12, 16, 4),
|
||||
child: ArtifactSelectionFacts(
|
||||
group: page.group,
|
||||
artifact: page.artifact,
|
||||
step: null,
|
||||
resolved: plan.resolved,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 4, 16, 4),
|
||||
child: Text(
|
||||
artifactViewerPositionLabel(
|
||||
index,
|
||||
count,
|
||||
page.artifact.contentType,
|
||||
Expanded(
|
||||
child: SingleChildScrollView(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 12, 16, 4),
|
||||
child: ArtifactSelectionFacts(
|
||||
group: page.group,
|
||||
artifact: page.artifact,
|
||||
step: null,
|
||||
resolved: plan.resolved,
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 4, 16, 4),
|
||||
child: Text(
|
||||
artifactViewerPositionLabel(
|
||||
index,
|
||||
count,
|
||||
page.artifact.contentType,
|
||||
),
|
||||
),
|
||||
),
|
||||
if (status != null)
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 4),
|
||||
child: Semantics(liveRegion: true, child: Text(status!)),
|
||||
),
|
||||
ArtifactPreviewBody(
|
||||
plan: plan,
|
||||
loading: loading,
|
||||
markdownBuilder: markdownBuilder,
|
||||
text: text,
|
||||
bytes: bytes,
|
||||
error: error,
|
||||
),
|
||||
if (plan.resolved != null && !plan.resolved!.external)
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 4, 16, 4),
|
||||
child: ArtifactFileActions(
|
||||
key: ValueKey<String>(
|
||||
'viewer-files-${page.group.stageKey}\u0000'
|
||||
'${page.group.visit}\u0000${page.artifact.url}',
|
||||
),
|
||||
artifact: page.artifact,
|
||||
resolved: plan.resolved!,
|
||||
fetch: fetch,
|
||||
bridge: fileBridge,
|
||||
),
|
||||
),
|
||||
if (plan.resolved != null)
|
||||
_Actions(
|
||||
resolved: plan.resolved!,
|
||||
onOpen: onOpen,
|
||||
onCopy: onCopy,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
if (status != null)
|
||||
Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 0, 16, 4),
|
||||
child: Semantics(liveRegion: true, child: Text(status!)),
|
||||
),
|
||||
Expanded(
|
||||
child: ArtifactPreviewBody(
|
||||
plan: plan,
|
||||
loading: loading,
|
||||
markdownBuilder: markdownBuilder,
|
||||
text: text,
|
||||
bytes: bytes,
|
||||
error: error,
|
||||
),
|
||||
),
|
||||
if (plan.resolved != null)
|
||||
_Actions(resolved: plan.resolved!, onOpen: onOpen, onCopy: onCopy),
|
||||
_Pager(
|
||||
index: index,
|
||||
count: count,
|
||||
|
||||
@@ -62,9 +62,9 @@ class ArtifactPreviewBody extends StatelessWidget {
|
||||
),
|
||||
);
|
||||
case ArtifactPreviewKind.text:
|
||||
return _ScrollingText(child: SelectableText(text ?? ''));
|
||||
return _PreviewPadding(child: SelectableText(text ?? ''));
|
||||
case ArtifactPreviewKind.markdown:
|
||||
return _ScrollingText(child: markdownBuilder(context, text ?? ''));
|
||||
return _PreviewPadding(child: markdownBuilder(context, text ?? ''));
|
||||
case ArtifactPreviewKind.unsupported:
|
||||
case ArtifactPreviewKind.unavailable:
|
||||
return const SizedBox.shrink();
|
||||
@@ -93,14 +93,16 @@ class _Loading extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class _ScrollingText extends StatelessWidget {
|
||||
const _ScrollingText({required this.child});
|
||||
/// Preview text at its natural height; the viewer body owns the page scroll so
|
||||
/// a long document and its actions scroll together instead of nested scrolls.
|
||||
class _PreviewPadding extends StatelessWidget {
|
||||
const _PreviewPadding({required this.child});
|
||||
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SingleChildScrollView(
|
||||
return Padding(
|
||||
padding: const EdgeInsetsDirectional.fromSTEB(16, 8, 16, 16),
|
||||
child: child,
|
||||
);
|
||||
|
||||
@@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import '../../../ui/adaptive/host.dart';
|
||||
import '../actions/artifact_file_bridge.dart';
|
||||
import '../domain/artifact_groups.dart';
|
||||
import '../domain/artifact_preview.dart';
|
||||
import '../domain/artifact_url.dart';
|
||||
@@ -24,8 +25,9 @@ const String artifactViewerTitle = 'Artifact viewer';
|
||||
/// `text/plain` artifact is selectable text, and a `.md`/`.markdown` or
|
||||
/// `text/markdown` artifact is handed to [markdownBuilder]. The selected page
|
||||
/// keeps its recorded facts visible and offers the existing external Open and
|
||||
/// Copy link actions. Previous/Next walk the same filtered list the gallery
|
||||
/// draws and stop at both ends; closing returns to the gallery row.
|
||||
/// Copy link actions plus Download/Share of the same-origin bytes as a named
|
||||
/// file. Previous/Next walk the same filtered list the gallery draws and stop at
|
||||
/// both ends; closing returns to the gallery row.
|
||||
///
|
||||
/// Nothing is ever drawn for an external, unsafe or unsupported url: the viewer
|
||||
/// reports the exact state instead. External urls are never fetched.
|
||||
@@ -38,6 +40,7 @@ class ArtifactViewerPage extends StatefulWidget {
|
||||
this.fetch = fetchArtifact,
|
||||
this.markdownBuilder = defaultArtifactMarkdown,
|
||||
this.openExternal = openArtifactExternally,
|
||||
this.fileBridge = const ArtifactFileBridge(),
|
||||
});
|
||||
|
||||
final List<ArtifactGroup> groups;
|
||||
@@ -49,6 +52,7 @@ class ArtifactViewerPage extends StatefulWidget {
|
||||
final ArtifactFetch fetch;
|
||||
final ArtifactMarkdownBuilder markdownBuilder;
|
||||
final ArtifactExternalOpen openExternal;
|
||||
final ArtifactFileBridge fileBridge;
|
||||
|
||||
@override
|
||||
State<ArtifactViewerPage> createState() => _ArtifactViewerPageState();
|
||||
@@ -228,6 +232,8 @@ class _ArtifactViewerPageState extends State<ArtifactViewerPage> {
|
||||
bytes: _fetched?.bytes,
|
||||
error: _error,
|
||||
status: _status,
|
||||
fetch: widget.fetch,
|
||||
fileBridge: widget.fileBridge,
|
||||
onPrevious: () => _step(-1),
|
||||
onNext: () => _step(1),
|
||||
onOpen: plan.resolved == null ? () {} : () => _open(plan.resolved!),
|
||||
|
||||
Reference in New Issue
Block a user