-
Notifications
You must be signed in to change notification settings - Fork 24
Viewer completeness read-only block types #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 1 commit
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2df7471
Viewer completeness read-only block types
RZEROSTERN 637cd4b
Update lib/src/presentation/utils/html_style_builder.dart
RZEROSTERN fd1190c
Update lib/src/presentation/blocks/quote/quote_renderer.dart
RZEROSTERN 13e04ad
Update lib/src/presentation/blocks/embed/embed_renderer.dart
RZEROSTERN 01e4835
Update lib/src/presentation/blocks/link_tool/link_tool_renderer.dart
RZEROSTERN c3ddc03
Initial plan
Copilot e49c87a
Fix unsafe URL launch in attaches_renderer.dart: use Uri.tryParse, re…
Copilot 6f56057
Merge pull request #21 from RZEROSTERN/copilot/sub-pr-20
RZEROSTERN d025573
Initial plan
Copilot f369f9c
Merge pull request #22 from RZEROSTERN/copilot/sub-pr-20-again
RZEROSTERN File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| import '../../domain/entities/blocks/attaches_block.dart'; | ||
| import 'block_mapper.dart'; | ||
|
|
||
| class AttachesMapper implements BlockMapper<AttachesBlock> { | ||
| const AttachesMapper(); | ||
|
|
||
| @override | ||
| String get supportedType => 'attaches'; | ||
|
|
||
| @override | ||
| AttachesBlock fromJson(Map<String, dynamic> data) { | ||
| final file = data['file'] as Map<String, dynamic>?; | ||
| return AttachesBlock( | ||
| url: (file?['url'] as String?) ?? '', | ||
| name: file?['name'] as String?, | ||
| extension: file?['extension'] as String?, | ||
| size: file?['size'] as int?, | ||
| title: data['title'] as String?, | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| import '../../domain/entities/blocks/embed_block.dart'; | ||
| import 'block_mapper.dart'; | ||
|
|
||
| class EmbedMapper implements BlockMapper<EmbedBlock> { | ||
| const EmbedMapper(); | ||
|
|
||
| @override | ||
| String get supportedType => 'embed'; | ||
|
|
||
| @override | ||
| EmbedBlock fromJson(Map<String, dynamic> data) => EmbedBlock( | ||
| service: (data['service'] as String?) ?? '', | ||
| source: (data['source'] as String?) ?? '', | ||
| embed: (data['embed'] as String?) ?? '', | ||
| width: data['width'] as int?, | ||
| height: data['height'] as int?, | ||
| caption: data['caption'] as String?, | ||
| ); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| import '../../domain/entities/blocks/link_tool_block.dart'; | ||
| import 'block_mapper.dart'; | ||
|
|
||
| class LinkToolMapper implements BlockMapper<LinkToolBlock> { | ||
| const LinkToolMapper(); | ||
|
|
||
| @override | ||
| String get supportedType => 'linkTool'; | ||
|
|
||
| @override | ||
| LinkToolBlock fromJson(Map<String, dynamic> data) { | ||
| final rawMeta = data['meta'] as Map<String, dynamic>?; | ||
| final rawImage = rawMeta?['image'] as Map<String, dynamic>?; | ||
|
|
||
| final meta = rawMeta == null | ||
| ? null | ||
| : LinkToolMeta( | ||
| title: rawMeta['title'] as String?, | ||
| description: rawMeta['description'] as String?, | ||
| imageUrl: rawImage?['url'] as String?, | ||
| ); | ||
|
|
||
| return LinkToolBlock( | ||
| link: (data['link'] as String?) ?? '', | ||
| meta: meta, | ||
| ); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,13 @@ | ||
| import '../../domain/entities/blocks/raw_block.dart'; | ||
| import 'block_mapper.dart'; | ||
|
|
||
| class RawMapper implements BlockMapper<RawBlock> { | ||
| const RawMapper(); | ||
|
|
||
| @override | ||
| String get supportedType => 'raw'; | ||
|
|
||
| @override | ||
| RawBlock fromJson(Map<String, dynamic> data) => | ||
| RawBlock(html: (data['html'] as String?) ?? ''); | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import '../block_entity.dart'; | ||
|
|
||
| class AttachesBlock extends BlockEntity { | ||
| final String url; | ||
| final String? name; | ||
| final String? extension; | ||
|
|
||
| /// File size in bytes. Null if not provided. | ||
| final int? size; | ||
|
|
||
| final String? title; | ||
|
|
||
| const AttachesBlock({ | ||
| required this.url, | ||
| this.name, | ||
| this.extension, | ||
| this.size, | ||
| this.title, | ||
| }); | ||
|
|
||
| @override | ||
| String get type => 'attaches'; | ||
|
|
||
| @override | ||
| Map<String, dynamic> toJson() => { | ||
| 'file': { | ||
| 'url': url, | ||
| if (name != null) 'name': name, | ||
| if (extension != null) 'extension': extension, | ||
| if (size != null) 'size': size, | ||
| }, | ||
| 'title': title ?? '', | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| import '../block_entity.dart'; | ||
|
|
||
| class EmbedBlock extends BlockEntity { | ||
| /// The service name (e.g. 'youtube', 'vimeo', 'codepen'). | ||
| final String service; | ||
|
|
||
| /// Original source URL as entered by the user. | ||
| final String source; | ||
|
|
||
| /// Embed URL (typically an iframe src). Not used for rendering in Flutter, | ||
| /// but preserved for round-trip JSON serialization. | ||
| final String embed; | ||
|
|
||
| final int? width; | ||
| final int? height; | ||
| final String? caption; | ||
|
|
||
| const EmbedBlock({ | ||
| required this.service, | ||
| required this.source, | ||
| required this.embed, | ||
| this.width, | ||
| this.height, | ||
| this.caption, | ||
| }); | ||
|
|
||
| @override | ||
| String get type => 'embed'; | ||
|
|
||
| @override | ||
| Map<String, dynamic> toJson() => { | ||
| 'service': service, | ||
| 'source': source, | ||
| 'embed': embed, | ||
| if (width != null) 'width': width, | ||
| if (height != null) 'height': height, | ||
| 'caption': caption ?? '', | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| import '../block_entity.dart'; | ||
|
|
||
| class LinkToolMeta { | ||
| final String? title; | ||
| final String? description; | ||
| final String? imageUrl; | ||
|
|
||
| const LinkToolMeta({this.title, this.description, this.imageUrl}); | ||
|
|
||
| Map<String, dynamic> toJson() => { | ||
| if (title != null) 'title': title, | ||
| if (description != null) 'description': description, | ||
| if (imageUrl != null) 'image': {'url': imageUrl}, | ||
| }; | ||
| } | ||
|
|
||
| class LinkToolBlock extends BlockEntity { | ||
| final String link; | ||
| final LinkToolMeta? meta; | ||
|
|
||
| const LinkToolBlock({required this.link, this.meta}); | ||
|
|
||
| @override | ||
| String get type => 'linkTool'; | ||
|
|
||
| @override | ||
| Map<String, dynamic> toJson() => { | ||
| 'link': link, | ||
| if (meta != null) 'meta': meta!.toJson(), | ||
| }; | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,14 @@ | ||
| import '../block_entity.dart'; | ||
|
|
||
| /// Raw HTML block. Content is sanitized before rendering. | ||
| class RawBlock extends BlockEntity { | ||
| final String html; | ||
|
|
||
| const RawBlock({required this.html}); | ||
|
|
||
| @override | ||
| String get type => 'raw'; | ||
|
|
||
| @override | ||
| Map<String, dynamic> toJson() => {'html': html}; | ||
| } |
97 changes: 97 additions & 0 deletions
97
lib/src/presentation/blocks/attaches/attaches_renderer.dart
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| import 'package:flutter/material.dart'; | ||
| import 'package:url_launcher/url_launcher.dart'; | ||
|
|
||
| import '../../../domain/entities/blocks/attaches_block.dart'; | ||
| import '../base_block_renderer.dart'; | ||
|
|
||
| class AttachesRenderer extends BlockRenderer<AttachesBlock> { | ||
| const AttachesRenderer( | ||
| {super.key, required super.block, super.styleConfig}); | ||
|
|
||
| @override | ||
| Widget build(BuildContext context) { | ||
| final displayName = | ||
| block.title ?? block.name ?? 'Download file'; | ||
| final ext = block.extension?.toUpperCase(); | ||
|
|
||
| return InkWell( | ||
| onTap: block.url.isNotEmpty | ||
| ? () => launchUrl(Uri.parse(block.url), | ||
| mode: LaunchMode.externalApplication) | ||
| : null, | ||
|
RZEROSTERN marked this conversation as resolved.
|
||
| borderRadius: BorderRadius.circular(8), | ||
| child: Container( | ||
| padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 10), | ||
| decoration: BoxDecoration( | ||
| border: Border.all(color: Colors.grey.shade300), | ||
| borderRadius: BorderRadius.circular(8), | ||
| color: Colors.grey.shade50, | ||
| ), | ||
| child: Row( | ||
| children: [ | ||
| Container( | ||
| padding: const EdgeInsets.all(8), | ||
| decoration: BoxDecoration( | ||
| color: Colors.blue.shade50, | ||
| borderRadius: BorderRadius.circular(6), | ||
| ), | ||
| child: Icon( | ||
| _iconForExtension(block.extension), | ||
| color: Colors.blue.shade700, | ||
| size: 22, | ||
| ), | ||
| ), | ||
| const SizedBox(width: 12), | ||
| Expanded( | ||
| child: Column( | ||
| crossAxisAlignment: CrossAxisAlignment.start, | ||
| children: [ | ||
| Text( | ||
| displayName, | ||
| style: TextStyle( | ||
| fontWeight: FontWeight.w500, | ||
| fontSize: 13, | ||
| fontFamily: styleConfig?.defaultFont, | ||
| ), | ||
| maxLines: 1, | ||
| overflow: TextOverflow.ellipsis, | ||
| ), | ||
| if (ext != null || block.size != null) | ||
| Text( | ||
| [ | ||
| if (ext != null) ext, | ||
| if (block.size != null) _formatSize(block.size!), | ||
| ].join(' · '), | ||
| style: TextStyle( | ||
| fontSize: 11, | ||
| color: Colors.grey.shade500, | ||
| fontFamily: styleConfig?.defaultFont, | ||
| ), | ||
| ), | ||
| ], | ||
| ), | ||
| ), | ||
| Icon(Icons.download_outlined, | ||
| color: Colors.blue.shade700, size: 20), | ||
| ], | ||
| ), | ||
| ), | ||
| ); | ||
| } | ||
|
|
||
| IconData _iconForExtension(String? ext) => switch (ext?.toLowerCase()) { | ||
| 'pdf' => Icons.picture_as_pdf_outlined, | ||
| 'doc' || 'docx' => Icons.description_outlined, | ||
| 'xls' || 'xlsx' => Icons.table_chart_outlined, | ||
| 'zip' || 'rar' || '7z' => Icons.folder_zip_outlined, | ||
| 'mp3' || 'wav' || 'ogg' => Icons.audio_file_outlined, | ||
| 'mp4' || 'mov' || 'avi' => Icons.video_file_outlined, | ||
| _ => Icons.insert_drive_file_outlined, | ||
| }; | ||
|
|
||
| String _formatSize(int bytes) { | ||
| if (bytes < 1024) return '${bytes}B'; | ||
| if (bytes < 1024 * 1024) return '${(bytes / 1024).toStringAsFixed(1)}KB'; | ||
| return '${(bytes / (1024 * 1024)).toStringAsFixed(1)}MB'; | ||
| } | ||
| } | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.