Skip to content

Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.

fix: link_preview launch review issues (#7731)

Morn54df6b2863ce
diff --git a/frontend/appflowy_flutter/integration_test/desktop/document/document_copy_and_paste_test.dart b/frontend/appflowy_flutter/integration_test/desktop/document/document_copy_and_paste_test.dart
index ee82f01d3f..d1e34edcb5 100644
--- a/frontend/appflowy_flutter/integration_test/desktop/document/document_copy_and_paste_test.dart
+++ b/frontend/appflowy_flutter/integration_test/desktop/document/document_copy_and_paste_test.dart
@@ -347,8 +347,9 @@ void main() {
await tester.tapButton(menu);
final convertToLinkButton = find.text(
- LocaleKeys.document_plugins_linkPreview_linkPreviewMenu_toUrl.tr(),
- );
+ LocaleKeys.document_plugins_linkPreview_linkPreviewMenu_toUrl
+ .tr(),
+ );
expect(convertToLinkButton, findsOneWidget);
await tester.tapButton(convertToLinkButton);
},
@@ -384,7 +385,6 @@ void main() {
expect(node.attributes[LinkPreviewBlockKeys.url], url);
});
-
await tester.simulateKeyEvent(
LogicalKeyboardKey.keyZ,
isControlPressed:
@@ -483,16 +483,6 @@ void main() {
});
});
- testWidgets('paste image url without extension', (tester) async {
- const plainText =
- 'https://images.unsplash.com/photo-1469474968028-56623f02e42e?ixlib=rb-4.0.3&q=85&fm=jpg&crop=entropy&cs=srgb&dl=david-marcu-78A265wPiO4-unsplash.jpg&w=640';
- await tester.pasteContent(plainText: plainText, (editorState) {
- final node = editorState.getNodeAtPath([0])!;
- expect(node.type, ImageBlockKeys.type);
- expect(node.attributes[ImageBlockKeys.url], isNotEmpty);
- });
- });
-
const testMarkdownText = '''
# I'm h1
## I'm h2
diff --git a/frontend/appflowy_flutter/integration_test/desktop/document/document_link_preview_test.dart b/frontend/appflowy_flutter/integration_test/desktop/document/document_link_preview_test.dart
index f74011ee2b..39f8bfd4f6 100644
--- a/frontend/appflowy_flutter/integration_test/desktop/document/document_link_preview_test.dart
+++ b/frontend/appflowy_flutter/integration_test/desktop/document/document_link_preview_test.dart
@@ -5,6 +5,7 @@ import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/clipboard_service.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/desktop_toolbar/link/link_hover_menu.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/link_embed/link_embed_block_component.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/link_embed/link_embed_menu.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/link_preview/custom_link_preview_block_component.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/link_preview/link_preview_menu.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/link_preview/paste_as/paste_as_menu.dart';
@@ -397,7 +398,7 @@ void main() {
Future<void> hoverAndConvert(
WidgetTester tester,
- PasteMenuType command,
+ LinkEmbedConvertCommand command,
) async {
final embed = find.byType(LinkEmbedBlockComponent);
expect(embed, findsOneWidget);
@@ -425,7 +426,7 @@ void main() {
final link = avaliableLink;
await preparePage(tester);
await pasteAsEmbed(tester, link);
- await hoverAndConvert(tester, PasteMenuType.mention);
+ await hoverAndConvert(tester, LinkEmbedConvertCommand.toMention);
final node = tester.editor.getNodeAtPath([0]);
checkMention(node, link);
});
@@ -434,7 +435,7 @@ void main() {
final link = avaliableLink;
await preparePage(tester);
await pasteAsEmbed(tester, link);
- await hoverAndConvert(tester, PasteMenuType.url);
+ await hoverAndConvert(tester, LinkEmbedConvertCommand.toURL);
final node = tester.editor.getNodeAtPath([0]);
checkUrl(node, link);
});
@@ -444,7 +445,7 @@ void main() {
final link = avaliableLink;
await preparePage(tester);
await pasteAsEmbed(tester, link);
- await hoverAndConvert(tester, PasteMenuType.bookmark);
+ await hoverAndConvert(tester, LinkEmbedConvertCommand.toBookmark);
final node = tester.editor.getNodeAtPath([0]);
checkBookmark(node, link);
});
diff --git a/frontend/appflowy_flutter/lib/core/helpers/url_launcher.dart b/frontend/appflowy_flutter/lib/core/helpers/url_launcher.dart
index fa61e7f5b8..0502e79604 100644
--- a/frontend/appflowy_flutter/lib/core/helpers/url_launcher.dart
+++ b/frontend/appflowy_flutter/lib/core/helpers/url_launcher.dart
@@ -45,16 +45,18 @@ Future<bool> afLaunchUri(
}
// try to launch the uri directly
- bool result;
- try {
- result = await launcher.launchUrl(
- uri,
- mode: mode,
- webOnlyWindowName: webOnlyWindowName,
- );
- } on PlatformException catch (e) {
- Log.error('Failed to open uri: $e');
- return false;
+ bool result = await launcher.canLaunchUrl(uri);
+ if (result) {
+ try {
+ result = await launcher.launchUrl(
+ uri,
+ mode: mode,
+ webOnlyWindowName: webOnlyWindowName,
+ );
+ } on PlatformException catch (e) {
+ Log.error('Failed to open uri: $e');
+ return false;
+ }
}
// if the uri is not a valid url, try to launch it with http scheme
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_configuration.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_configuration.dart
index b3d99ab84b..5e7eefc24e 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_configuration.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_configuration.dart
@@ -983,7 +983,6 @@ CustomLinkPreviewBlockComponentBuilder _buildLinkPreviewBlockComponentBuilder(
return const EdgeInsets.symmetric(vertical: 10);
},
),
- cache: LinkPreviewDataCache(),
);
}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dart
index c2c18e48eb..0ffb7de73a 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dart
@@ -20,9 +20,9 @@ import 'package:appflowy/workspace/application/view/view_lock_status_bloc.dart';
import 'package:appflowy/workspace/application/view_info/view_info_bloc.dart';
import 'package:appflowy/workspace/presentation/home/af_focus_manager.dart';
import 'package:appflowy_editor/appflowy_editor.dart' hide QuoteBlockKeys;
+import 'package:appflowy_ui/appflowy_ui.dart';
import 'package:collection/collection.dart';
import 'package:flowy_infra/theme_extension.dart';
-import 'package:flowy_infra/theme_extension_v2.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
@@ -352,7 +352,6 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage>
final isLocked =
context.read<ViewLockStatusBloc?>()?.state.isLocked ?? false;
- final themeV2 = AFThemeExtensionV2.of(context);
final editor = Directionality(
textDirection: textDirection,
child: AppFlowyEditor(
@@ -431,6 +430,7 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage>
),
);
}
+ final appTheme = AppFlowyTheme.of(context);
return Center(
child: BlocProvider.value(
value: context.read<DocumentBloc>(),
@@ -443,15 +443,9 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage>
),
items: toolbarItems,
decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(8),
- color: Theme.of(context).cardColor,
- boxShadow: [
- BoxShadow(
- offset: Offset(0, 4),
- blurRadius: 24,
- color: themeV2.shadow_medium,
- ),
- ],
+ borderRadius: BorderRadius.circular(appTheme.borderRadius.l),
+ color: appTheme.surfaceColorScheme.primary,
+ boxShadow: [appTheme.shadow.small],
),
toolbarBuilder: (_, child, onDismiss, isMetricsChanged) =>
BlocProvider.value(
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/ai/ai_writer_toolbar_item.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/ai/ai_writer_toolbar_item.dart
index 35575fe85a..467a847c53 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/ai/ai_writer_toolbar_item.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/ai/ai_writer_toolbar_item.dart
@@ -5,8 +5,8 @@ import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.da
import 'package:appflowy/plugins/document/presentation/editor_style.dart';
import 'package:appflowy/workspace/presentation/widgets/dialogs.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
+import 'package:appflowy_ui/appflowy_ui.dart';
import 'package:easy_localization/easy_localization.dart';
-import 'package:flowy_infra/theme_extension_v2.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
@@ -119,7 +119,7 @@ class _AiWriterToolbarActionListState extends State<AiWriterToolbarActionList> {
}
Widget buildChild(BuildContext context) {
- final themeV2 = AFThemeExtensionV2.of(context);
+ final theme = AppFlowyTheme.of(context), iconScheme = theme.iconColorTheme;
final child = FlowyIconButton(
width: 48,
height: 32,
@@ -131,13 +131,13 @@ class _AiWriterToolbarActionListState extends State<AiWriterToolbarActionList> {
FlowySvg(
FlowySvgs.toolbar_ai_writer_m,
size: Size.square(20),
- color: themeV2.icon_primary,
+ color: iconScheme.primary,
),
HSpace(4),
FlowySvg(
FlowySvgs.toolbar_arrow_down_m,
size: Size(12, 20),
- color: themeV2.icon_tertiary,
+ color: iconScheme.primary,
),
],
),
@@ -180,6 +180,7 @@ class ImproveWritingButton extends StatelessWidget {
@override
Widget build(BuildContext context) {
+ final theme = AppFlowyTheme.of(context);
final child = FlowyIconButton(
width: 36,
height: 32,
@@ -187,7 +188,7 @@ class ImproveWritingButton extends StatelessWidget {
icon: FlowySvg(
FlowySvgs.toolbar_ai_improve_writing_m,
size: Size.square(20.0),
- color: AFThemeExtensionV2.of(context).icon_primary,
+ color: theme.iconColorTheme.primary,
),
onPressed: () {
if (_isAIEnabled(editorState)) {
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/copy_and_paste/custom_paste_command.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/copy_and_paste/custom_paste_command.dart
index dd3f7362a9..6399d3b11f 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/copy_and_paste/custom_paste_command.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/copy_and_paste/custom_paste_command.dart
@@ -186,7 +186,7 @@ Future<bool> _pasteAsLinkPreview(
node.delta?.toPlainText().isNotEmpty == true) {
return false;
}
-
+ if (!isMobile) return false;
final bool isImageUrl;
try {
isImageUrl = await _isImageUrl(text);
@@ -195,7 +195,7 @@ Future<bool> _pasteAsLinkPreview(
return false;
}
- if (!isMobile && !isImageUrl) return false;
+ if (!isImageUrl) return false;
// insert the text with link format
final textTransaction = editorState.transaction
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/delta/text_delta_extension.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/delta/text_delta_extension.dart
index 5beba66c32..905c033bda 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/delta/text_delta_extension.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/delta/text_delta_extension.dart
@@ -1,3 +1,4 @@
+import 'package:appflowy/plugins/document/presentation/editor_plugins/link_preview/custom_link_parser.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/mention/mention_block.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
@@ -27,9 +28,15 @@ extension TextDeltaExtension on Delta {
if (op.text == MentionBlockKeys.mentionChar) {
final mention = attributes?[MentionBlockKeys.mention];
final mentionPageId = mention?[MentionBlockKeys.pageId];
+ final mentionType = mention?[MentionBlockKeys.type];
if (mentionPageId != null) {
text += await getMentionPageName(mentionPageId);
continue;
+ } else if (mentionType == MentionType.externalLink.name) {
+ final url = mention?[MentionBlockKeys.url] ?? '';
+ final info = await LinkInfoCache.get(url);
+ text += info?.title ?? url;
+ continue;
}
}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/desktop_toolbar/link/link_create_menu.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/desktop_toolbar/link/link_create_menu.dart
index a6e1a78299..6213896feb 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/desktop_toolbar/link/link_create_menu.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/desktop_toolbar/link/link_create_menu.dart
@@ -5,6 +5,7 @@ import 'package:appflowy/plugins/shared/share/constants.dart';
import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
+import 'package:appflowy_ui/appflowy_ui.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter/material.dart';
@@ -307,17 +308,13 @@ void showLinkCreateMenu(
ShapeDecoration buildToolbarLinkDecoration(
BuildContext context, {
double radius = 12.0,
-}) =>
- ShapeDecoration(
- color: Theme.of(context).cardColor,
- shape: RoundedRectangleBorder(
- borderRadius: BorderRadius.circular(radius),
- ),
- shadows: [
- const BoxShadow(
- color: LinkStyle.shadowMedium,
- blurRadius: 24,
- offset: Offset(0, 4),
- ),
- ],
- );
+}) {
+ final theme = AppFlowyTheme.of(context);
+ return ShapeDecoration(
+ color: theme.surfaceColorScheme.primary,
+ shape: RoundedRectangleBorder(
+ borderRadius: BorderRadius.circular(radius),
+ ),
+ shadows: [theme.shadow.small],
+ );
+}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_embed/link_embed_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_embed/link_embed_block_component.dart
index 6dc6501c03..baf9702a36 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_embed/link_embed_block_component.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_embed/link_embed_block_component.dart
@@ -1,6 +1,9 @@
+import 'package:appflowy/core/helpers/url_launcher.dart';
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/callout/callout_block_component.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/link_preview/custom_link_parser.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/link_preview/default_selectable_mixin.dart';
import 'package:appflowy/shared/appflowy_network_image.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor_plugins/appflowy_editor_plugins.dart';
@@ -37,11 +40,12 @@ class LinkEmbedBlockComponent extends BlockComponentStatefulWidget {
});
@override
- State<LinkEmbedBlockComponent> createState() =>
+ DefaultSelectableMixinState<LinkEmbedBlockComponent> createState() =>
LinkEmbedBlockComponentState();
}
-class LinkEmbedBlockComponentState extends State<LinkEmbedBlockComponent>
+class LinkEmbedBlockComponentState
+ extends DefaultSelectableMixinState<LinkEmbedBlockComponent>
with BlockComponentConfigurable {
@override
BlockComponentConfiguration get configuration => widget.configuration;
@@ -49,11 +53,11 @@ class LinkEmbedBlockComponentState extends State<LinkEmbedBlockComponent>
@override
Node get node => widget.node;
- String get url => widget.node.attributes[LinkPreviewBlockKeys.url]!;
+ String get url => widget.node.attributes[LinkPreviewBlockKeys.url] ?? '';
- EmbedLoadingStatus status = EmbedLoadingStatus.loading;
+ LinkLoadingStatus status = LinkLoadingStatus.loading;
final parser = LinkParser();
- LinkInfo linkInfo = LinkInfo();
+ late LinkInfo linkInfo = LinkInfo(url: url);
final showActionsNotifier = ValueNotifier<bool>(false);
bool isMenuShowing = false, isHovering = false;
@@ -62,13 +66,14 @@ class LinkEmbedBlockComponentState extends State<LinkEmbedBlockComponent>
void initState() {
super.initState();
parser.addLinkInfoListener((v) {
+ final hasNewInfo = !v.isEmpty(), hasOldInfo = !linkInfo.isEmpty();
if (mounted) {
setState(() {
- if (v.isEmpty() && linkInfo.isEmpty()) {
- status = EmbedLoadingStatus.error;
- } else {
+ if (hasNewInfo) {
linkInfo = v;
- status = EmbedLoadingStatus.idle;
+ status = LinkLoadingStatus.idle;
+ } else if (!hasOldInfo) {
+ status = LinkLoadingStatus.error;
}
});
}
@@ -98,7 +103,13 @@ class LinkEmbedBlockComponentState extends State<LinkEmbedBlockComponent>
},
child: buildChild(context),
);
- result = Padding(padding: padding, child: result);
+ final parent = node.parent;
+ EdgeInsets newPadding = padding;
+ if (parent?.type == CalloutBlockKeys.type) {
+ newPadding = padding.copyWith(right: padding.right + 10);
+ }
+
+ result = Padding(padding: newPadding, child: result);
if (widget.showActions && widget.actionBuilder != null) {
result = BlockComponentActionWrapper(
@@ -115,7 +126,7 @@ class LinkEmbedBlockComponentState extends State<LinkEmbedBlockComponent>
fillSceme = theme.fillColorScheme,
borderScheme = theme.borderColorScheme;
Widget child;
- final isIdle = status == EmbedLoadingStatus.idle;
+ final isIdle = status == LinkLoadingStatus.idle;
if (isIdle) {
child = buildContent(context);
} else {
@@ -123,6 +134,7 @@ class LinkEmbedBlockComponentState extends State<LinkEmbedBlockComponent>
}
return Container(
height: 450,
+ key: widgetKey,
decoration: BoxDecoration(
color: isIdle ? Theme.of(context).cardColor : fillSceme.tertiaryHover,
borderRadius: BorderRadius.all(Radius.circular(16)),
@@ -150,7 +162,7 @@ class LinkEmbedBlockComponentState extends State<LinkEmbedBlockComponent>
node: node,
onReload: () {
setState(() {
- status = EmbedLoadingStatus.loading;
+ status = LinkLoadingStatus.loading;
});
Future.delayed(const Duration(milliseconds: 200), () {
if (mounted) parser.start(url);
@@ -185,43 +197,51 @@ class LinkEmbedBlockComponentState extends State<LinkEmbedBlockComponent>
),
),
),
- Container(
- height: 64,
- padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 20),
- child: Row(
- children: [
- SizedBox.square(
- dimension: 40,
- child: Center(
- child: linkInfo.buildIconWidget(size: Size.square(32)),
- ),
- ),
- HSpace(12),
- Expanded(
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- mainAxisSize: MainAxisSize.min,
- children: [
- FlowyText(
- linkInfo.siteName ?? '',
- color: textScheme.primary,
- fontSize: 14,
- figmaLineHeight: 20,
- fontWeight: FontWeight.w600,
- overflow: TextOverflow.ellipsis,
+ MouseRegion(
+ cursor: SystemMouseCursors.click,
+ child: GestureDetector(
+ behavior: HitTestBehavior.opaque,
+ onTap: () =>
+ afLaunchUrlString(url, addingHttpSchemeWhenFailed: true),
+ child: Container(
+ height: 64,
+ padding: const EdgeInsets.symmetric(vertical: 12, horizontal: 20),
+ child: Row(
+ children: [
+ SizedBox.square(
+ dimension: 40,
+ child: Center(
+ child: linkInfo.buildIconWidget(size: Size.square(32)),
),
- VSpace(4),
- FlowyText.regular(
- url,
- color: textScheme.secondary,
- fontSize: 12,
- figmaLineHeight: 16,
- overflow: TextOverflow.ellipsis,
+ ),
+ HSpace(12),
+ Expanded(
+ child: Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ FlowyText(
+ linkInfo.siteName ?? '',
+ color: textScheme.primary,
+ fontSize: 14,
+ figmaLineHeight: 20,
+ fontWeight: FontWeight.w600,
+ overflow: TextOverflow.ellipsis,
+ ),
+ VSpace(4),
+ FlowyText.regular(
+ url,
+ color: textScheme.secondary,
+ fontSize: 12,
+ figmaLineHeight: 16,
+ overflow: TextOverflow.ellipsis,
+ ),
+ ],
),
- ],
- ),
+ ),
+ ],
),
- ],
+ ),
),
),
],
@@ -230,7 +250,7 @@ class LinkEmbedBlockComponentState extends State<LinkEmbedBlockComponent>
Widget buildErrorLoadingWidget(BuildContext context) {
final theme = AppFlowyTheme.of(context), textSceme = theme.textColorScheme;
- final isLoading = status == EmbedLoadingStatus.loading;
+ final isLoading = status == LinkLoadingStatus.loading;
return isLoading
? Center(
child: SizedBox.square(
@@ -264,7 +284,7 @@ class LinkEmbedBlockComponentState extends State<LinkEmbedBlockComponent>
),
TextSpan(
text: LocaleKeys
- .document_plugins_linkPreview_linkPreviewMenu_refuseConnect
+ .document_plugins_linkPreview_linkPreviewMenu_unableToDisplay
.tr(),
style: TextStyle(
color: textSceme.primary,
@@ -281,6 +301,10 @@ class LinkEmbedBlockComponentState extends State<LinkEmbedBlockComponent>
),
);
}
-}
-enum EmbedLoadingStatus { loading, idle, error }
+ @override
+ Node get currentNode => node;
+
+ @override
+ EdgeInsets get boxPadding => padding;
+}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_embed/link_embed_menu.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_embed/link_embed_menu.dart
index 8b9ac122a8..bddfcb9b54 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_embed/link_embed_menu.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_embed/link_embed_menu.dart
@@ -3,7 +3,6 @@ import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/desktop_toolbar/link/link_hover_menu.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/desktop_toolbar/link/link_replace_menu.dart';
-import 'package:appflowy/plugins/document/presentation/editor_plugins/link_preview/paste_as/paste_as_menu.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/link_preview/shared.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/menu/menu_extension.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
@@ -70,7 +69,7 @@ class _LinkEmbedMenuState extends State<LinkEmbedMenu> {
return Container(
padding: EdgeInsets.all(4),
decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(16),
+ borderRadius: BorderRadius.circular(12),
color: fillScheme.primaryAlpha80,
),
child: Row(
@@ -90,18 +89,19 @@ class _LinkEmbedMenuState extends State<LinkEmbedMenu> {
FlowySvgs.toolbar_link_m,
color: iconScheme.tertiary,
),
+ radius: BorderRadius.all(Radius.circular(theme.borderRadius.m)),
tooltipText: LocaleKeys.editor_copyLink.tr(),
preferBelow: false,
onPressed: () => copyLink(context),
),
- buildTurnIntoBotton(),
+ buildconvertBotton(),
buildMoreOptionBotton(),
],
),
);
}
- Widget buildTurnIntoBotton() {
+ Widget buildconvertBotton() {
final theme = AppFlowyTheme.of(context), iconScheme = theme.iconColorTheme;
return AppFlowyPopover(
offset: Offset(0, 6),
@@ -117,22 +117,22 @@ class _LinkEmbedMenuState extends State<LinkEmbedMenu> {
turnintoMenuNum--;
checkToHideMenu();
},
- popupBuilder: (context) => buildTurnIntoMenu(),
+ popupBuilder: (context) => buildConvertMenu(),
child: FlowyIconButton(
icon: FlowySvg(
FlowySvgs.turninto_m,
color: iconScheme.tertiary,
),
- tooltipText: LocaleKeys.document_toolbar_turnInto.tr(),
+ radius: BorderRadius.all(Radius.circular(theme.borderRadius.m)),
+ tooltipText: LocaleKeys.editor_convertTo.tr(),
preferBelow: false,
onPressed: showTurnIntoMenu,
),
);
}
- Widget buildTurnIntoMenu() {
- final types =
- PasteMenuType.values.where((e) => e != PasteMenuType.embed).toList();
+ Widget buildConvertMenu() {
+ final types = LinkEmbedConvertCommand.values;
return Padding(
padding: const EdgeInsets.all(8.0),
child: SeparatedColumn(
@@ -149,16 +149,16 @@ class _LinkEmbedMenuState extends State<LinkEmbedMenu> {
figmaLineHeight: 20,
),
onTap: () {
- if (command == PasteMenuType.bookmark) {
+ if (command == LinkEmbedConvertCommand.toBookmark) {
final transaction = editorState.transaction;
transaction.updateNode(node, {
LinkPreviewBlockKeys.url: url,
LinkEmbedKeys.previewType: '',
});
editorState.apply(transaction);
- } else if (command == PasteMenuType.mention) {
+ } else if (command == LinkEmbedConvertCommand.toMention) {
convertUrlPreviewNodeToMention(editorState, node);
- } else if (command == PasteMenuType.url) {
+ } else if (command == LinkEmbedConvertCommand.toURL) {
convertUrlPreviewNodeToLink(editorState, node);
}
},
@@ -192,6 +192,7 @@ class _LinkEmbedMenuState extends State<LinkEmbedMenu> {
FlowySvgs.toolbar_more_m,
color: iconScheme.tertiary,
),
+ radius: BorderRadius.all(Radius.circular(theme.borderRadius.m)),
tooltipText: LocaleKeys.document_toolbar_moreOptions.tr(),
preferBelow: false,
onPressed: showMoreOptionMenu,
@@ -330,3 +331,24 @@ enum LinkEmbedMenuCommand {
}
}
}
+
+enum LinkEmbedConvertCommand {
+ toMention,
+ toURL,
+ toBookmark;
+
+ String get title {
+ switch (this) {
+ case toMention:
+ return LocaleKeys.document_plugins_linkPreview_linkPreviewMenu_toMetion
+ .tr();
+ case toURL:
+ return LocaleKeys.document_plugins_linkPreview_linkPreviewMenu_toUrl
+ .tr();
+ case toBookmark:
+ return LocaleKeys
+ .document_plugins_linkPreview_linkPreviewMenu_toBookmark
+ .tr();
+ }
+ }
+}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_preview/custom_link_parser.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_preview/custom_link_parser.dart
index 0032d9cd33..1907f68d29 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_preview/custom_link_parser.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_preview/custom_link_parser.dart
@@ -5,39 +5,39 @@ import 'package:appflowy/shared/appflowy_network_image.dart';
import 'package:appflowy/shared/appflowy_network_svg.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy_backend/log.dart';
-import 'package:favicon/favicon.dart';
import 'package:flutter/material.dart';
-// ignore: depend_on_referenced_packages
-import 'package:flutter_link_previewer/flutter_link_previewer.dart' hide Size;
+import 'link_parsers/default_parser.dart';
+import 'link_parsers/youtube_parser.dart';
class LinkParser {
- static final LinkInfoCache _cache = LinkInfoCache();
final Set<ValueChanged<LinkInfo>> _listeners = <ValueChanged<LinkInfo>>{};
+ static final Map<String, LinkInfoParser> _hostToParsers = {
+ 'www.youtube.com': YoutubeParser(),
+ 'youtube.com': YoutubeParser(),
+ 'youtu.be': YoutubeParser(),
+ };
- Future<void> start(String url) async {
- final data = await _cache.get(url);
+ Future<void> start(String url, {LinkInfoParser? parser}) async {
+ final uri = Uri.tryParse(LinkInfoParser.formatUrl(url)) ?? Uri.parse(url);
+ final data = await LinkInfoCache.get(uri);
if (data != null) {
refreshLinkInfo(data);
}
- await _getLinkInfo(url);
+
+ final host = uri.host;
+ final currentParser = parser ?? _hostToParsers[host] ?? DefaultParser();
+ await _getLinkInfo(uri, currentParser);
}
- Future<LinkInfo?> _getLinkInfo(String url) async {
+ Future<LinkInfo?> _getLinkInfo(Uri uri, LinkInfoParser parser) async {
try {
- final previewData = await getPreviewData(url);
- final favicon = await FaviconFinder.getBest(url);
- final linkInfo = LinkInfo(
- siteName: previewData.title,
- description: previewData.description,
- imageUrl: previewData.image?.url,
- faviconUrl: favicon?.url,
- );
- if (!linkInfo.isEmpty()) await _cache.set(url, linkInfo);
+ final linkInfo = await parser.parse(uri) ?? LinkInfo(url: '$uri');
+ if (!linkInfo.isEmpty()) await LinkInfoCache.set(uri, linkInfo);
refreshLinkInfo(linkInfo);
return linkInfo;
} catch (e, s) {
Log.error('get link info error: ', e, s);
- refreshLinkInfo(LinkInfo());
+ refreshLinkInfo(LinkInfo(url: '$uri'));
return null;
}
}
@@ -60,35 +60,45 @@ class LinkParser {
class LinkInfo {
factory LinkInfo.fromJson(Map<String, dynamic> json) => LinkInfo(
siteName: json['siteName'],
+ url: json['url'] ?? '',
+ title: json['title'],
description: json['description'],
imageUrl: json['imageUrl'],
faviconUrl: json['faviconUrl'],
);
LinkInfo({
+ required this.url,
this.siteName,
+ this.title,
this.description,
this.imageUrl,
this.faviconUrl,
});
+ final String url;
final String? siteName;
+ final String? title;
final String? description;
final String? imageUrl;
final String? faviconUrl;
Map<String, dynamic> toJson() => {
+ 'url': url,
'siteName': siteName,
+ 'title': title,
'description': description,
'imageUrl': imageUrl,
'faviconUrl': faviconUrl,
};
+ @override
+ String toString() {
+ return 'LinkInfo{url: $url, siteName: $siteName, title: $title, description: $description, imageUrl: $imageUrl, faviconUrl: $faviconUrl}';
+ }
+
bool isEmpty() {
- return siteName == null ||
- description == null ||
- imageUrl == null ||
- faviconUrl == null;
+ return title == null;
}
Widget buildIconWidget({Size size = const Size.square(20.0)}) {
@@ -116,20 +126,26 @@ class LinkInfo {
}
class LinkInfoCache {
- final _linkInfoPrefix = 'link_info';
+ static const _linkInfoPrefix = 'link_info';
- Future<LinkInfo?> get(String url) async {
+ static Future<LinkInfo?> get(Uri uri) async {
final option = await getIt<KeyValueStorage>().getWithFormat<LinkInfo?>(
- _linkInfoPrefix + url,
+ '$_linkInfoPrefix$uri',
(value) => LinkInfo.fromJson(jsonDecode(value)),
);
return option;
}
- Future<void> set(String url, LinkInfo data) async {
+ static Future<void> set(Uri uri, LinkInfo data) async {
await getIt<KeyValueStorage>().set(
- _linkInfoPrefix + url,
+ '$_linkInfoPrefix$uri',
jsonEncode(data.toJson()),
);
}
}
+
+enum LinkLoadingStatus {
+ loading,
+ idle,
+ error,
+}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_preview/custom_link_preview.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_preview/custom_link_preview.dart
index 0b6ad9fd7b..880a33b817 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_preview/custom_link_preview.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_preview/custom_link_preview.dart
@@ -3,8 +3,10 @@ import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/presentation/widgets/widgets.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/actions/mobile_block_action_buttons.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/callout/callout_block_component.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/link_preview/shared.dart';
import 'package:appflowy/shared/appflowy_network_image.dart';
+import 'package:appflowy/util/theme_extension.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
@@ -14,6 +16,8 @@ import 'package:provider/provider.dart';
import 'package:universal_platform/universal_platform.dart';
import 'package:appflowy_ui/appflowy_ui.dart';
+import 'custom_link_parser.dart';
+
class CustomLinkPreviewWidget extends StatelessWidget {
const CustomLinkPreviewWidget({
super.key,
@@ -23,7 +27,7 @@ class CustomLinkPreviewWidget extends StatelessWidget {
this.description,
this.imageUrl,
this.isHovering = false,
- this.status = LinkPreviewStatus.loading,
+ this.status = LinkLoadingStatus.loading,
});
final Node node;
@@ -32,7 +36,7 @@ class CustomLinkPreviewWidget extends StatelessWidget {
final String? imageUrl;
final String url;
final bool isHovering;
- final LinkPreviewStatus status;
+ final LinkLoadingStatus status;
@override
Widget build(BuildContext context) {
@@ -46,6 +50,8 @@ class CustomLinkPreviewWidget extends StatelessWidget {
.text
.fontSize ??
16.0;
+ final isInDarkCallout = node.parent?.type == CalloutBlockKeys.type &&
+ !Theme.of(context).isLightMode;
final (fontSize, width) = UniversalPlatform.isDesktopOrWeb
? (documentFontSize, 160.0)
: (documentFontSize - 2, 120.0);
@@ -53,7 +59,7 @@ class CustomLinkPreviewWidget extends StatelessWidget {
clipBehavior: Clip.hardEdge,
decoration: BoxDecoration(
border: Border.all(
- color: isHovering
+ color: isHovering || isInDarkCallout
? borderScheme.greyTertiaryHover
: borderScheme.greyTertiary,
),
@@ -67,43 +73,44 @@ class CustomLinkPreviewWidget extends StatelessWidget {
buildImage(context),
Expanded(
child: Padding(
- padding: const EdgeInsets.fromLTRB(20, 12, 60, 12),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- buildLoadingOrErrorWidget(),
- if (title != null)
- Padding(
- padding: const EdgeInsets.only(bottom: 4.0),
- child: FlowyText.medium(
- title!,
- overflow: TextOverflow.ellipsis,
- fontSize: fontSize,
- color: textScheme.primary,
- figmaLineHeight: 20,
- ),
- ),
- if (description != null)
- Padding(
- padding: const EdgeInsets.only(bottom: 16.0),
- child: FlowyText(
- description!,
- overflow: TextOverflow.ellipsis,
- fontSize: fontSize - 4,
- figmaLineHeight: 16,
- color: textScheme.primary,
- ),
+ padding: const EdgeInsets.fromLTRB(20, 12, 58, 12),
+ child: status != LinkLoadingStatus.idle
+ ? buildLoadingOrErrorWidget()
+ : Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
+ mainAxisAlignment: MainAxisAlignment.spaceBetween,
+ children: [
+ if (title != null)
+ Padding(
+ padding: const EdgeInsets.only(bottom: 4.0),
+ child: FlowyText.medium(
+ title!,
+ overflow: TextOverflow.ellipsis,
+ fontSize: fontSize,
+ color: textScheme.primary,
+ figmaLineHeight: 20,
+ ),
+ ),
+ if (description != null)
+ Padding(
+ padding: const EdgeInsets.only(bottom: 16.0),
+ child: FlowyText(
+ description!,
+ overflow: TextOverflow.ellipsis,
+ fontSize: fontSize - 4,
+ figmaLineHeight: 16,
+ color: textScheme.primary,
+ ),
+ ),
+ FlowyText(
+ url.toString(),
+ overflow: TextOverflow.ellipsis,
+ color: textScheme.secondary,
+ fontSize: fontSize - 4,
+ figmaLineHeight: 16,
+ ),
+ ],
),
- FlowyText(
- url.toString(),
- overflow: TextOverflow.ellipsis,
- color: textScheme.secondary,
- fontSize: fontSize - 4,
- figmaLineHeight: 16,
- ),
- ],
- ),
),
),
],
@@ -112,9 +119,12 @@ class CustomLinkPreviewWidget extends StatelessWidget {
);
if (UniversalPlatform.isDesktopOrWeb) {
- return InkWell(
- onTap: () => afLaunchUrlString(url),
- child: child,
+ return MouseRegion(
+ cursor: SystemMouseCursors.click,
+ child: GestureDetector(
+ onTap: () => afLaunchUrlString(url),
+ child: child,
+ ),
);
}
@@ -156,7 +166,7 @@ class CustomLinkPreviewWidget extends StatelessWidget {
iconScheme = theme.iconColorTheme;
final width = UniversalPlatform.isDesktopOrWeb ? 160.0 : 120.0;
Widget child;
- if (imageUrl != null) {
+ if (imageUrl?.isNotEmpty ?? false) {
child = FlowyNetworkImage(
url: imageUrl!,
width: width,
@@ -184,26 +194,22 @@ class CustomLinkPreviewWidget extends StatelessWidget {
}
Widget buildLoadingOrErrorWidget() {
- if (status == LinkPreviewStatus.loading) {
- return Expanded(
- child: const Center(
- child: SizedBox(
- height: 16,
- width: 16,
- child: CircularProgressIndicator.adaptive(),
- ),
+ if (status == LinkLoadingStatus.loading) {
+ return const Center(
+ child: SizedBox(
+ height: 16,
+ width: 16,
+ child: CircularProgressIndicator.adaptive(),
),
);
- } else if (status == LinkPreviewStatus.error) {
- return Expanded(
- child: const Center(
- child: SizedBox(
- height: 16,
- width: 16,
- child: Icon(
- Icons.error_outline,
- color: Colors.red,
- ),
+ } else if (status == LinkLoadingStatus.error) {
+ return const Center(
+ child: SizedBox(
+ height: 16,
+ width: 16,
+ child: Icon(
+ Icons.error_outline,
+ color: Colors.red,
),
),
);
@@ -211,5 +217,3 @@ class CustomLinkPreviewWidget extends StatelessWidget {
return SizedBox.shrink();
}
}
-
-enum LinkPreviewStatus { loading, error, idle }
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_preview/custom_link_preview_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_preview/custom_link_preview_block_component.dart
index 3772169331..3f2128db52 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_preview/custom_link_preview_block_component.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_preview/custom_link_preview_block_component.dart
@@ -1,19 +1,19 @@
+import 'package:appflowy/plugins/document/presentation/editor_plugins/callout/callout_block_component.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/link_embed/link_embed_block_component.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/link_preview/custom_link_parser.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_editor_plugins/appflowy_editor_plugins.dart';
import 'package:flutter/material.dart';
import 'custom_link_preview.dart';
+import 'default_selectable_mixin.dart';
import 'link_preview_menu.dart';
class CustomLinkPreviewBlockComponentBuilder extends BlockComponentBuilder {
CustomLinkPreviewBlockComponentBuilder({
super.configuration,
- this.cache,
});
- final LinkPreviewDataCacheInterface? cache;
-
@override
BlockComponentWidget build(BlockComponentContext blockComponentContext) {
final node = blockComponentContext.node;
@@ -35,7 +35,6 @@ class CustomLinkPreviewBlockComponentBuilder extends BlockComponentBuilder {
configuration: configuration,
showActions: showActions(node),
actionBuilder: (_, state) => actionBuilder(blockComponentContext, state),
- cache: cache,
);
}
@@ -51,18 +50,15 @@ class CustomLinkPreviewBlockComponent extends BlockComponentStatefulWidget {
super.showActions,
super.actionBuilder,
super.configuration = const BlockComponentConfiguration(),
- this.cache,
});
- final LinkPreviewDataCacheInterface? cache;
-
@override
- State<CustomLinkPreviewBlockComponent> createState() =>
+ DefaultSelectableMixinState<CustomLinkPreviewBlockComponent> createState() =>
CustomLinkPreviewBlockComponentState();
}
class CustomLinkPreviewBlockComponentState
- extends State<CustomLinkPreviewBlockComponent>
+ extends DefaultSelectableMixinState<CustomLinkPreviewBlockComponent>
with BlockComponentConfigurable {
@override
BlockComponentConfiguration get configuration => widget.configuration;
@@ -72,8 +68,9 @@ class CustomLinkPreviewBlockComponentState
String get url => widget.node.attributes[LinkPreviewBlockKeys.url]!;
- late final LinkPreviewParser parser;
- late Future<void> future;
+ final parser = LinkParser();
+ LinkLoadingStatus status = LinkLoadingStatus.loading;
+ late LinkInfo linkInfo = LinkInfo(url: url);
final showActionsNotifier = ValueNotifier<bool>(false);
bool isMenuShowing = false, isHovering = false;
@@ -81,21 +78,26 @@ class CustomLinkPreviewBlockComponentState
@override
void initState() {
super.initState();
- parser = LinkPreviewParser(url: url, cache: widget.cache);
- future = parser.start();
+ parser.addLinkInfoListener((v) {
+ final hasNewInfo = !v.isEmpty(), hasOldInfo = !linkInfo.isEmpty();
+ if (mounted) {
+ setState(() {
+ if (hasNewInfo) {
+ linkInfo = v;
+ status = LinkLoadingStatus.idle;
+ } else if (!hasOldInfo) {
+ status = LinkLoadingStatus.error;
+ }
+ });
+ }
+ });
+ parser.start(url);
}
@override
- void didUpdateWidget(CustomLinkPreviewBlockComponent oldWidget) {
- super.didUpdateWidget(oldWidget);
- final url = widget.node.attributes[LinkPreviewBlockKeys.url]!;
- final oldUrl = oldWidget.node.attributes[LinkPreviewBlockKeys.url]!;
- if (url != oldUrl) {
- parser = LinkPreviewParser(url: url, cache: widget.cache);
- setState(() {
- future = parser.start();
- });
- }
+ void dispose() {
+ parser.dispose();
+ super.dispose();
}
@override
@@ -114,91 +116,79 @@ class CustomLinkPreviewBlockComponentState
},
hitTestBehavior: HitTestBehavior.opaque,
opaque: false,
- child: ValueListenableBuilder<bool>(
+ child: ValueListenableBuilder(
valueListenable: showActionsNotifier,
builder: (context, showActions, child) {
- return FutureBuilder(
- future: future,
- builder: (context, snapshot) {
- Widget child;
-
- if (snapshot.connectionState != ConnectionState.done) {
- child = CustomLinkPreviewWidget(
- node: node,
- url: url,
- isHovering: showActions,
- );
- } else {
- final title = parser.getContent(LinkPreviewRegex.title);
- final description =
- parser.getContent(LinkPreviewRegex.description);
- final image = parser.getContent(LinkPreviewRegex.image);
-
- if (title == null && description == null && image == null) {
- child = CustomLinkPreviewWidget(
- node: node,
- url: url,
- isHovering: showActions,
- status: LinkPreviewStatus.error,
- );
- } else {
- child = CustomLinkPreviewWidget(
- node: node,
- url: url,
- title: title,
- description: description,
- imageUrl: image,
- isHovering: showActions,
- status: LinkPreviewStatus.idle,
- );
- }
- }
-
- child = Padding(padding: padding, child: child);
-
- if (widget.showActions && widget.actionBuilder != null) {
- child = BlockComponentActionWrapper(
- node: node,
- actionBuilder: widget.actionBuilder!,
- child: child,
- );
- }
-
- child = Stack(
- children: [
- child,
- if (showActions)
- Positioned(
- top: 16,
- right: 16,
- child: CustomLinkPreviewMenu(
- onMenuShowed: () {
- isMenuShowing = true;
- },
- onMenuHided: () {
- isMenuShowing = false;
- if (!isHovering && mounted) {
- showActionsNotifier.value = false;
- }
- },
- onReload: () {
- if (mounted) {
- setState(() {
- future = parser.start();
- });
- }
- },
- node: node,
- ),
- ),
- ],
- );
-
- return child;
- },
- );
+ return buildPreview(showActions);
},
),
);
}
+
+ Widget buildPreview(bool showActions) {
+ Widget child = CustomLinkPreviewWidget(
+ key: widgetKey,
+ node: node,
+ url: url,
+ isHovering: showActions,
+ title: linkInfo.siteName,
+ description: linkInfo.description,
+ imageUrl: linkInfo.imageUrl,
+ status: status,
+ );
+
+ if (widget.showActions && widget.actionBuilder != null) {
+ child = BlockComponentActionWrapper(
+ node: node,
+ actionBuilder: widget.actionBuilder!,
+ child: child,
+ );
+ }
+
+ child = Stack(
+ children: [
+ child,
+ if (showActions)
+ Positioned(
+ top: 12,
+ right: 12,
+ child: CustomLinkPreviewMenu(
+ onMenuShowed: () {
+ isMenuShowing = true;
+ },
+ onMenuHided: () {
+ isMenuShowing = false;
+ if (!isHovering && mounted) {
+ showActionsNotifier.value = false;
+ }
+ },
+ onReload: () {
+ setState(() {
+ status = LinkLoadingStatus.loading;
+ });
+ Future.delayed(const Duration(milliseconds: 200), () {
+ if (mounted) parser.start(url);
+ });
+ },
+ node: node,
+ ),
+ ),
+ ],
+ );
+
+ final parent = node.parent;
+ EdgeInsets newPadding = padding;
+ if (parent?.type == CalloutBlockKeys.type) {
+ newPadding = padding.copyWith(right: padding.right + 10);
+ }
+ child = Padding(padding: newPadding, child: child);
+
+ return child;
+ }
+
+ @override
+ Node get currentNode => node;
+
+ @override
+ EdgeInsets get boxPadding => padding;
}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_preview/default_selectable_mixin.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_preview/default_selectable_mixin.dart
new file mode 100644
index 0000000000..c894811522
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_preview/default_selectable_mixin.dart
@@ -0,0 +1,77 @@
+import 'package:appflowy_editor/appflowy_editor.dart';
+import 'package:flutter/widgets.dart';
+
+abstract class DefaultSelectableMixinState<T extends StatefulWidget>
+ extends State<T> with SelectableMixin {
+ final widgetKey = GlobalKey();
+ RenderBox? get _renderBox =>
+ widgetKey.currentContext?.findRenderObject() as RenderBox?;
+
+ Node get currentNode;
+
+ EdgeInsets get boxPadding => EdgeInsets.zero;
+
+ @override
+ Position start() => Position(path: currentNode.path);
+
+ @override
+ Position end() => Position(path: currentNode.path, offset: 1);
+
+ @override
+ Position getPositionInOffset(Offset start) => end();
+
+ @override
+ bool get shouldCursorBlink => false;
+
+ @override
+ CursorStyle get cursorStyle => CursorStyle.cover;
+
+ @override
+ Rect getBlockRect({
+ bool shiftWithBaseOffset = false,
+ }) {
+ final box = _renderBox;
+ if (box is RenderBox) {
+ return boxPadding.topLeft & box.size;
+ }
+ return Rect.zero;
+ }
+
+ @override
+ Rect? getCursorRectInPosition(
+ Position position, {
+ bool shiftWithBaseOffset = false,
+ }) {
+ final rects = getRectsInSelection(Selection.collapsed(position));
+ return rects.firstOrNull;
+ }
+
+ @override
+ List<Rect> getRectsInSelection(
+ Selection selection, {
+ bool shiftWithBaseOffset = false,
+ }) {
+ if (_renderBox == null) {
+ return [];
+ }
+ final parentBox = context.findRenderObject();
+ final box = widgetKey.currentContext?.findRenderObject();
+ if (parentBox is RenderBox && box is RenderBox) {
+ return [
+ box.localToGlobal(Offset.zero, ancestor: parentBox) & box.size,
+ ];
+ }
+ return [Offset.zero & _renderBox!.size];
+ }
+
+ @override
+ Selection getSelectionInRange(Offset start, Offset end) => Selection.single(
+ path: currentNode.path,
+ startOffset: 0,
+ endOffset: 1,
+ );
+
+ @override
+ Offset localToGlobal(Offset offset, {bool shiftWithBaseOffset = false}) =>
+ _renderBox!.localToGlobal(offset);
+}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_preview/link_parsers/default_parser.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_preview/link_parsers/default_parser.dart
new file mode 100644
index 0000000000..f05f4a9706
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_preview/link_parsers/default_parser.dart
@@ -0,0 +1,88 @@
+import 'package:appflowy/plugins/document/presentation/editor_plugins/link_preview/custom_link_parser.dart';
+import 'package:appflowy_backend/log.dart';
+
+import 'package:http/http.dart' as http;
+// ignore: depend_on_referenced_packages
+import 'package:html/parser.dart' as html_parser;
+
+abstract class LinkInfoParser {
+ Future<LinkInfo?> parse(
+ Uri link, {
+ Duration timeout = const Duration(seconds: 8),
+ Map<String, String>? headers,
+ });
+
+ static String formatUrl(String url) {
+ Uri? uri = Uri.tryParse(url);
+ if (uri == null) return url;
+ if (!uri.hasScheme) uri = Uri.tryParse('http://$url');
+ if (uri == null) return url;
+ final isHome = (uri.hasEmptyPath || uri.path == '/') && !uri.hasQuery;
+ final homeUrl = '${uri.scheme}://${uri.host}/';
+ if (isHome) return homeUrl;
+ return '$uri';
+ }
+}
+
+class DefaultParser implements LinkInfoParser {
+ @override
+ Future<LinkInfo?> parse(
+ Uri link, {
+ Duration timeout = const Duration(seconds: 8),
+ Map<String, String>? headers,
+ }) async {
+ try {
+ final isHome = (link.hasEmptyPath || link.path == '/') && !link.hasQuery;
+ final http.Response response =
+ await http.get(link, headers: headers).timeout(timeout);
+ final code = response.statusCode;
+ if (code != 200 && isHome) {
+ throw Exception('Http request error: $code');
+ }
+ // else if (!isHome && code == 403) {
+ // uri = Uri.parse('${uri.scheme}://${uri.host}/');
+ // response = await http.get(uri).timeout(timeout);
+ // }
+
+ final document = html_parser.parse(response.body);
+
+ final siteName = document
+ .querySelector('meta[property="og:site_name"]')
+ ?.attributes['content'];
+
+ String? title = document
+ .querySelector('meta[property="og:title"]')
+ ?.attributes['content'];
+ title ??= document.querySelector('title')?.text;
+
+ String? description = document
+ .querySelector('meta[property="og:description"]')
+ ?.attributes['content'];
+ description ??= document
+ .querySelector('meta[name="description"]')
+ ?.attributes['content'];
+
+ String? imageUrl = document
+ .querySelector('meta[property="og:image"]')
+ ?.attributes['content'];
+ if (imageUrl != null && !imageUrl.startsWith('http')) {
+ imageUrl = link.resolve(imageUrl).toString();
+ }
+
+ final favicon =
+ 'https://www.google.com/s2/favicons?sz=64&domain=${link.host}';
+
+ return LinkInfo(
+ url: '$link',
+ siteName: siteName,
+ title: title,
+ description: description,
+ imageUrl: imageUrl,
+ faviconUrl: favicon,
+ );
+ } catch (e) {
+ Log.error('Parse link $link error: $e');
+ return null;
+ }
+ }
+}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_preview/link_parsers/youtube_parser.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_preview/link_parsers/youtube_parser.dart
new file mode 100644
index 0000000000..6f1ac6fb22
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_preview/link_parsers/youtube_parser.dart
@@ -0,0 +1,86 @@
+import 'dart:convert';
+
+import 'package:appflowy/plugins/document/presentation/editor_plugins/link_preview/custom_link_parser.dart';
+import 'package:appflowy_backend/log.dart';
+import 'package:http/http.dart' as http;
+import 'default_parser.dart';
+
+class YoutubeParser implements LinkInfoParser {
+ @override
+ Future<LinkInfo?> parse(
+ Uri link, {
+ Duration timeout = const Duration(seconds: 8),
+ Map<String, String>? headers,
+ }) async {
+ try {
+ final isHome = (link.hasEmptyPath || link.path == '/') && !link.hasQuery;
+ if (isHome) {
+ return DefaultParser().parse(
+ link,
+ timeout: timeout,
+ headers: headers,
+ );
+ }
+
+ final requestLink =
+ 'https://www.youtube.com/oembed?url=$link&format=json';
+ final http.Response response = await http
+ .get(Uri.parse(requestLink), headers: headers)
+ .timeout(timeout);
+ final code = response.statusCode;
+ if (code != 200) {
+ throw Exception('Http request error: $code');
+ }
+
+ final youtubeInfo = YoutubeInfo.fromJson(jsonDecode(response.body));
+
+ final favicon =
+ 'https://www.google.com/s2/favicons?sz=64&domain=${link.host}';
+ return LinkInfo(
+ url: '$link',
+ title: youtubeInfo.title,
+ siteName: youtubeInfo.authorName,
+ imageUrl: youtubeInfo.thumbnailUrl,
+ faviconUrl: favicon,
+ );
+ } catch (e) {
+ Log.error('Parse link $link error: $e');
+ return null;
+ }
+ }
+}
+
+class YoutubeInfo {
+ YoutubeInfo({
+ this.title,
+ this.authorName,
+ this.version,
+ this.providerName,
+ this.providerUrl,
+ this.thumbnailUrl,
+ });
+
+ YoutubeInfo.fromJson(Map<String, dynamic> json) {
+ title = json['title'];
+ authorName = json['author_name'];
+ version = json['version'];
+ providerName = json['provider_name'];
+ providerUrl = json['provider_url'];
+ thumbnailUrl = json['thumbnail_url'];
+ }
+ String? title;
+ String? authorName;
+ String? version;
+ String? providerName;
+ String? providerUrl;
+ String? thumbnailUrl;
+
+ Map<String, dynamic> toJson() => {
+ 'title': title,
+ 'author_name': authorName,
+ 'version': version,
+ 'provider_name': providerName,
+ 'provider_url': providerUrl,
+ 'thumbnail_url': thumbnailUrl,
+ };
+}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_preview/link_preview_cache.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_preview/link_preview_cache.dart
deleted file mode 100644
index 6688cfe304..0000000000
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_preview/link_preview_cache.dart
+++ /dev/null
@@ -1,25 +0,0 @@
-import 'dart:convert';
-
-import 'package:appflowy/core/config/kv.dart';
-import 'package:appflowy/startup/startup.dart';
-import 'package:appflowy_editor_plugins/appflowy_editor_plugins.dart';
-
-class LinkPreviewDataCache implements LinkPreviewDataCacheInterface {
- @override
- Future<LinkPreviewData?> get(String url) async {
- final option =
- await getIt<KeyValueStorage>().getWithFormat<LinkPreviewData?>(
- url,
- (value) => LinkPreviewData.fromJson(jsonDecode(value)),
- );
- return option;
- }
-
- @override
- Future<void> set(String url, LinkPreviewData data) async {
- await getIt<KeyValueStorage>().set(
- url,
- jsonEncode(data.toJson()),
- );
- }
-}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_preview/paste_as/paste_as_menu.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_preview/paste_as/paste_as_menu.dart
index 16febe54cb..d31b2f8fd9 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_preview/paste_as/paste_as_menu.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/link_preview/paste_as/paste_as_menu.dart
@@ -3,8 +3,8 @@ import 'package:appflowy/plugins/document/presentation/editor_plugins/link_embed
import 'package:appflowy/plugins/document/presentation/editor_plugins/link_preview/shared.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/menu/menu_extension.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
+import 'package:appflowy_ui/appflowy_ui.dart';
import 'package:easy_localization/easy_localization.dart';
-import 'package:flowy_infra/theme_extension_v2.dart';
import 'package:flowy_infra_ui/style_widget/button.dart';
import 'package:flowy_infra_ui/style_widget/text.dart';
import 'package:flutter/material.dart';
@@ -28,11 +28,10 @@ class PasteAsMenuService {
void dismiss() {
if (_menuEntry != null) {
- editorState.service.keyboardService?.enable();
- editorState.service.scrollService?.enable();
keepEditorFocusNotifier.decrease();
+ // editorState.service.scrollService?.enable();
+ // editorState.service.keyboardService?.enable();
}
-
_menuEntry?.remove();
_menuEntry = null;
}
@@ -58,6 +57,7 @@ class PasteAsMenuService {
children: [
ltrb.buildPositioned(
child: PasteAsMenu(
+ editorState: editorState,
onSelect: (t) {
final selection = editorState.selection;
if (selection == null) return;
@@ -91,8 +91,9 @@ class PasteAsMenuService {
Overlay.of(context).insert(_menuEntry!);
- editorState.service.keyboardService?.disable(showCursor: true);
- editorState.service.scrollService?.disable();
+ keepEditorFocusNotifier.increase();
+ // editorState.service.keyboardService?.disable(showCursor: true);
+ // editorState.service.scrollService?.disable();
}
}
@@ -101,9 +102,11 @@ class PasteAsMenu extends StatefulWidget {
super.key,
required this.onSelect,
required this.onDismiss,
+ required this.editorState,
});
final ValueChanged<PasteMenuType?> onSelect;
final VoidCallback onDismiss;
+ final EditorState editorState;
@override
State<PasteAsMenu> createState() => _PasteAsMenuState();
@@ -113,24 +116,28 @@ class _PasteAsMenuState extends State<PasteAsMenu> {
final focusNode = FocusNode(debugLabel: 'paste_as_menu');
final ValueNotifier<int> selectedIndexNotifier = ValueNotifier(0);
+ EditorState get editorState => widget.editorState;
+
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback(
(_) => focusNode.requestFocus(),
);
+ editorState.selectionNotifier.addListener(dismiss);
}
@override
void dispose() {
focusNode.dispose();
selectedIndexNotifier.dispose();
+ editorState.selectionNotifier.removeListener(dismiss);
super.dispose();
}
@override
Widget build(BuildContext context) {
- final themeV2 = AFThemeExtensionV2.of(context);
+ final theme = AppFlowyTheme.of(context);
return Focus(
focusNode: focusNode,
onKeyEvent: onKeyEvent,
@@ -140,14 +147,8 @@ class _PasteAsMenuState extends State<PasteAsMenu> {
padding: EdgeInsets.all(6),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(8),
- color: Theme.of(context).cardColor,
- boxShadow: [
- BoxShadow(
- offset: Offset(0, 4),
- blurRadius: 16,
- color: themeV2.shadow_medium,
- ),
- ],
+ color: theme.surfaceColorScheme.primary,
+ boxShadow: [theme.shadow.medium],
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
@@ -156,7 +157,7 @@ class _PasteAsMenuState extends State<PasteAsMenu> {
height: 32,
padding: EdgeInsets.all(8),
child: FlowyText.semibold(
- color: themeV2.text_tertiary,
+ color: theme.textColorScheme.primary,
LocaleKeys.document_plugins_linkPreview_typeSelection_pasteAs
.tr(),
),
@@ -201,8 +202,11 @@ class _PasteAsMenuState extends State<PasteAsMenu> {
length = PasteMenuType.values.length;
if (event.logicalKey == LogicalKeyboardKey.enter) {
onSelect(PasteMenuType.values[index]);
+ return KeyEventResult.handled;
} else if (event.logicalKey == LogicalKeyboardKey.escape) {
dismiss();
+ } else if (event.logicalKey == LogicalKeyboardKey.backspace) {
+ dismiss();
} else if ([LogicalKeyboardKey.arrowUp, LogicalKeyboardKey.arrowLeft]
.contains(event.logicalKey)) {
if (index == 0) {
@@ -211,6 +215,7 @@ class _PasteAsMenuState extends State<PasteAsMenu> {
index--;
}
changeIndex(index);
+ return KeyEventResult.handled;
} else if ([LogicalKeyboardKey.arrowDown, LogicalKeyboardKey.arrowRight]
.contains(event.logicalKey)) {
if (index == length - 1) {
@@ -219,8 +224,9 @@ class _PasteAsMenuState extends State<PasteAsMenu> {
index++;
}
changeIndex(index);
+ return KeyEventResult.handled;
}
- return KeyEventResult.handled;
+ return KeyEventResult.ignored;
}
void onSelect(PasteMenuType type) => widget.onSelect.call(type);
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_link_block.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_link_block.dart
index 7a807fef64..06ebcb5002 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_link_block.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_link_block.dart
@@ -42,8 +42,8 @@ class MentionLinkBlock extends StatefulWidget {
class _MentionLinkBlockState extends State<MentionLinkBlock> {
final parser = LinkParser();
_LoadingStatus status = _LoadingStatus.loading;
+ late LinkInfo linkInfo = LinkInfo(url: url);
final previewController = PopoverController();
- LinkInfo linkInfo = LinkInfo();
bool isHovering = false;
int previewFocusNum = 0;
bool isPreviewHovering = false;
@@ -67,13 +67,14 @@ class _MentionLinkBlockState extends State<MentionLinkBlock> {
super.initState();
parser.addLinkInfoListener((v) {
+ final hasNewInfo = !v.isEmpty(), hasOldInfo = !linkInfo.isEmpty();
if (mounted) {
setState(() {
- if (v.isEmpty() && linkInfo.isEmpty()) {
- status = _LoadingStatus.error;
- } else {
+ if (hasNewInfo) {
linkInfo = v;
status = _LoadingStatus.idle;
+ } else if (!hasOldInfo) {
+ status = _LoadingStatus.error;
}
});
}
@@ -148,6 +149,7 @@ class _MentionLinkBlockState extends State<MentionLinkBlock> {
Widget buildIconWithTitle(BuildContext context) {
final theme = AppFlowyTheme.of(context);
+ final siteName = linkInfo.siteName, linkTitle = linkInfo.title ?? url;
return MouseRegion(
cursor: SystemMouseCursors.click,
@@ -169,12 +171,25 @@ class _MentionLinkBlockState extends State<MentionLinkBlock> {
buildIcon(),
HSpace(4),
Flexible(
- child: FlowyText(
- linkInfo.siteName ?? url,
- color: theme.textColorScheme.primary,
- fontSize: 14,
- figmaLineHeight: 20,
+ child: RichText(
overflow: TextOverflow.ellipsis,
+ text: TextSpan(
+ children: [
+ if (siteName != null) ...[
+ TextSpan(
+ text: siteName,
+ style: theme.textStyle.body
+ .standard(color: theme.textColorScheme.secondary),
+ ),
+ WidgetSpan(child: HSpace(2)),
+ ],
+ TextSpan(
+ text: linkTitle,
+ style: theme.textStyle.body
+ .standard(color: theme.textColorScheme.primary),
+ ),
+ ],
+ ),
),
),
HSpace(2),
@@ -323,9 +338,10 @@ class _MentionLinkBlockState extends State<MentionLinkBlock> {
maxHeight: 48 + size.height,
);
}
+ final hasImage = linkInfo.imageUrl?.isNotEmpty ?? false;
return BoxConstraints(
maxWidth: max(300, size.width),
- maxHeight: 300,
+ maxHeight: hasImage ? 300 : 180,
);
}
}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_link_preview.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_link_preview.dart
index 00082f127a..00b161379e 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_link_preview.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_link_preview.dart
@@ -56,7 +56,9 @@ class _MentionLinkPreviewState extends State<MentionLinkPreview> {
Widget build(BuildContext context) {
final theme = AppFlowyTheme.of(context),
textColorScheme = theme.textColorScheme;
-
+ final imageUrl = linkInfo.imageUrl ?? '',
+ description = linkInfo.description ?? '';
+ final imageHeight = 120.0;
final card = MouseRegion(
onEnter: widget.onEnter,
onExit: widget.onExit,
@@ -67,20 +69,21 @@ class _MentionLinkPreviewState extends State<MentionLinkPreview> {
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
- ClipRRect(
- borderRadius:
- const BorderRadius.vertical(top: Radius.circular(16)),
- child: FlowyNetworkImage(
- url: linkInfo.imageUrl ?? '',
- width: 280,
- height: 120,
+ if (imageUrl.isNotEmpty)
+ ClipRRect(
+ borderRadius:
+ const BorderRadius.vertical(top: Radius.circular(16)),
+ child: FlowyNetworkImage(
+ url: linkInfo.imageUrl ?? '',
+ width: 280,
+ height: imageHeight,
+ ),
),
- ),
VSpace(12),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: FlowyText.semibold(
- linkInfo.siteName ?? '',
+ linkInfo.title ?? linkInfo.siteName ?? '',
fontSize: 14,
figmaLineHeight: 20,
color: textColorScheme.primary,
@@ -88,18 +91,20 @@ class _MentionLinkPreviewState extends State<MentionLinkPreview> {
),
),
VSpace(4),
- Padding(
- padding: const EdgeInsets.symmetric(horizontal: 16),
- child: FlowyText(
- linkInfo.description ?? '',
- fontSize: 12,
- figmaLineHeight: 16,
- color: textColorScheme.secondary,
- maxLines: 3,
- overflow: TextOverflow.ellipsis,
+ if (description.isNotEmpty) ...[
+ Padding(
+ padding: const EdgeInsets.symmetric(horizontal: 16),
+ child: FlowyText(
+ description,
+ fontSize: 12,
+ figmaLineHeight: 16,
+ color: textColorScheme.secondary,
+ maxLines: 3,
+ overflow: TextOverflow.ellipsis,
+ ),
),
- ),
- VSpace(36),
+ VSpace(36),
+ ],
Container(
margin: const EdgeInsets.symmetric(horizontal: 16),
height: 28,
@@ -109,7 +114,7 @@ class _MentionLinkPreviewState extends State<MentionLinkPreview> {
HSpace(6),
Expanded(
child: FlowyText(
- linkInfo.description ?? '',
+ linkInfo.siteName ?? linkInfo.url,
fontSize: 12,
figmaLineHeight: 16,
color: textColorScheme.primary,
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/plugins.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/plugins.dart
index 63aaf34e8d..4161036a08 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/plugins.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/plugins.dart
@@ -40,7 +40,6 @@ export 'inline_math_equation/inline_math_equation.dart';
export 'inline_math_equation/inline_math_equation_toolbar_item.dart';
export 'keyboard_interceptor/keyboard_interceptor.dart';
export 'link_preview/custom_link_preview.dart';
-export 'link_preview/link_preview_cache.dart';
export 'link_preview/link_preview_menu.dart';
export 'math_equation/math_equation_block_component.dart';
export 'math_equation/mobile_math_equation_toolbar_item.dart';
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toolbar_item/custom_format_toolbar_items.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toolbar_item/custom_format_toolbar_items.dart
index 77d94451c8..7dbf192bae 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toolbar_item/custom_format_toolbar_items.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toolbar_item/custom_format_toolbar_items.dart
@@ -6,8 +6,8 @@ import 'package:appflowy/util/theme_extension.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
// ignore: implementation_imports
import 'package:appflowy_editor/src/editor/toolbar/desktop/items/utils/tooltip_util.dart';
+import 'package:appflowy_ui/appflowy_ui.dart';
import 'package:easy_localization/easy_localization.dart';
-import 'package:flowy_infra/theme_extension_v2.dart';
import 'package:flowy_infra_ui/style_widget/icon_button.dart';
import 'package:flutter/material.dart';
@@ -70,6 +70,7 @@ class _FormatToolbarItem extends ToolbarItem {
? highlightColor
: EditorStyleCustomizer.toolbarHoverColor(context);
final isDark = !Theme.of(context).isLightMode;
+ final theme = AppFlowyTheme.of(context);
final child = FlowyIconButton(
width: 36,
@@ -81,7 +82,7 @@ class _FormatToolbarItem extends ToolbarItem {
size: Size.square(20.0),
color: (isDark && isHighlight)
? Color(0xFF282E3A)
- : AFThemeExtensionV2.of(context).icon_primary,
+ : theme.iconColorTheme.primary,
),
onPressed: () => editorState.toggleAttribute(
name,
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toolbar_item/custom_hightlight_color_toolbar_item.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toolbar_item/custom_hightlight_color_toolbar_item.dart
index cd332e14ef..2e115d240d 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toolbar_item/custom_hightlight_color_toolbar_item.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toolbar_item/custom_hightlight_color_toolbar_item.dart
@@ -3,7 +3,7 @@ import 'package:appflowy/plugins/document/presentation/editor_page.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/desktop_toolbar/color_picker.dart';
import 'package:appflowy/plugins/document/presentation/editor_style.dart';
import 'package:appflowy_editor/appflowy_editor.dart' hide ColorPicker;
-import 'package:flowy_infra/theme_extension_v2.dart';
+import 'package:appflowy_ui/appflowy_ui.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter/material.dart';
@@ -82,7 +82,8 @@ class _HighlightColorPickerWidgetState
}
Widget buildChild(BuildContext context) {
- final iconColor = AFThemeExtensionV2.of(context).icon_primary;
+ final theme = AppFlowyTheme.of(context),
+ iconColor = theme.iconColorTheme.primary;
final child = FlowyIconButton(
width: 36,
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toolbar_item/custom_link_toolbar_item.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toolbar_item/custom_link_toolbar_item.dart
index 693c7a64ce..cbbce9c943 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toolbar_item/custom_link_toolbar_item.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toolbar_item/custom_link_toolbar_item.dart
@@ -8,7 +8,7 @@ import 'package:appflowy/plugins/document/presentation/editor_style.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/util/theme_extension.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
-import 'package:flowy_infra/theme_extension_v2.dart';
+import 'package:appflowy_ui/appflowy_ui.dart';
import 'package:flowy_infra_ui/style_widget/icon_button.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
@@ -34,7 +34,7 @@ final customLinkItem = ToolbarItem(
final hoverColor = isHref
? highlightColor
: EditorStyleCustomizer.toolbarHoverColor(context);
-
+ final theme = AppFlowyTheme.of(context);
final child = FlowyIconButton(
width: 36,
height: 32,
@@ -45,7 +45,7 @@ final customLinkItem = ToolbarItem(
size: Size.square(20.0),
color: (isDark && isHref)
? Color(0xFF282E3A)
- : AFThemeExtensionV2.of(context).icon_primary,
+ : theme.iconColorTheme.primary,
),
onPressed: () {
getIt<FloatingToolbarController>().hideToolbar();
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toolbar_item/custom_text_align_toolbar_item.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toolbar_item/custom_text_align_toolbar_item.dart
index d751728526..2a1688db19 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toolbar_item/custom_text_align_toolbar_item.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toolbar_item/custom_text_align_toolbar_item.dart
@@ -3,8 +3,8 @@ import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/base/toolbar_extension.dart';
import 'package:appflowy/plugins/document/presentation/editor_style.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
+import 'package:appflowy_ui/appflowy_ui.dart';
import 'package:easy_localization/easy_localization.dart';
-import 'package:flowy_infra/theme_extension_v2.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter/material.dart';
@@ -96,7 +96,8 @@ class _TextAlignActionListState extends State<TextAlignActionList> {
}
Widget buildChild(BuildContext context) {
- final themeV2 = AFThemeExtensionV2.of(context);
+ final theme = AppFlowyTheme.of(context),
+ iconColor = theme.iconColorTheme.primary;
final child = FlowyIconButton(
width: 48,
height: 32,
@@ -108,13 +109,13 @@ class _TextAlignActionListState extends State<TextAlignActionList> {
FlowySvg(
FlowySvgs.toolbar_alignment_m,
size: Size.square(20),
- color: themeV2.icon_primary,
+ color: iconColor,
),
HSpace(4),
FlowySvg(
FlowySvgs.toolbar_arrow_down_m,
size: Size(12, 20),
- color: themeV2.icon_tertiary,
+ color: iconColor,
),
],
),
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toolbar_item/custom_text_color_toolbar_item.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toolbar_item/custom_text_color_toolbar_item.dart
index 525eebe917..80f2d3138d 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toolbar_item/custom_text_color_toolbar_item.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toolbar_item/custom_text_color_toolbar_item.dart
@@ -4,8 +4,8 @@ import 'package:appflowy/plugins/document/presentation/editor_page.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/desktop_toolbar/color_picker.dart';
import 'package:appflowy/plugins/document/presentation/editor_style.dart';
import 'package:appflowy_editor/appflowy_editor.dart' hide ColorPicker;
+import 'package:appflowy_ui/appflowy_ui.dart';
import 'package:easy_localization/easy_localization.dart';
-import 'package:flowy_infra/theme_extension_v2.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter/material.dart';
import 'toolbar_id_enum.dart';
@@ -57,6 +57,9 @@ class _TextColorPickerWidgetState extends State<TextColorPickerWidget> {
@override
Widget build(BuildContext context) {
+ if (editorState.selection == null) {
+ return const SizedBox.shrink();
+ }
final selectionRectList = editorState.selectionRects();
final top =
selectionRectList.isEmpty ? 0.0 : selectionRectList.first.height;
@@ -78,7 +81,8 @@ class _TextColorPickerWidgetState extends State<TextColorPickerWidget> {
}
Widget buildChild(BuildContext context) {
- final iconColor = AFThemeExtensionV2.of(context).icon_primary;
+ final theme = AppFlowyTheme.of(context),
+ iconColor = theme.iconColorTheme.primary;
final child = FlowyIconButton(
width: 36,
height: 32,
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toolbar_item/text_heading_toolbar_item.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toolbar_item/text_heading_toolbar_item.dart
index 625fedff79..8140a7b7f3 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toolbar_item/text_heading_toolbar_item.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toolbar_item/text_heading_toolbar_item.dart
@@ -4,8 +4,8 @@ import 'package:appflowy/plugins/document/presentation/editor_plugins/actions/bl
import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';
import 'package:appflowy/plugins/document/presentation/editor_style.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
+import 'package:appflowy_ui/appflowy_ui.dart';
import 'package:easy_localization/easy_localization.dart';
-import 'package:flowy_infra/theme_extension_v2.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter/material.dart';
@@ -78,7 +78,8 @@ class _TextHeadingActionListState extends State<TextHeadingActionList> {
}
Widget buildChild(BuildContext context) {
- final themeV2 = AFThemeExtensionV2.of(context);
+ final theme = AppFlowyTheme.of(context),
+ iconColor = theme.iconColorTheme.primary;
final child = FlowyIconButton(
width: 48,
height: 32,
@@ -90,13 +91,13 @@ class _TextHeadingActionListState extends State<TextHeadingActionList> {
FlowySvg(
FlowySvgs.toolbar_text_format_m,
size: Size.square(20),
- color: themeV2.icon_primary,
+ color: iconColor,
),
HSpace(4),
FlowySvg(
FlowySvgs.toolbar_arrow_down_m,
size: Size(12, 20),
- color: themeV2.icon_tertiary,
+ color: iconColor,
),
],
),
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toolbar_item/text_suggestions_toolbar_item.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toolbar_item/text_suggestions_toolbar_item.dart
index a0aded3f8e..3c8f55caef 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toolbar_item/text_suggestions_toolbar_item.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toolbar_item/text_suggestions_toolbar_item.dart
@@ -8,9 +8,9 @@ import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/workspace/presentation/home/menu/menu_shared_state.dart';
import 'package:appflowy_editor/appflowy_editor.dart'
hide QuoteBlockComponentBuilder, quoteNode, QuoteBlockKeys;
+import 'package:appflowy_ui/appflowy_ui.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/size.dart';
-import 'package:flowy_infra/theme_extension_v2.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flowy_infra_ui/style_widget/hover.dart';
import 'package:flutter/material.dart';
@@ -119,8 +119,8 @@ class _SuggestionsActionListState extends State<SuggestionsActionList> {
}
Widget buildChild(BuildContext context) {
- final themeV2 = AFThemeExtensionV2.of(context);
-
+ final theme = AppFlowyTheme.of(context),
+ iconColor = theme.iconColorTheme.primary;
final child = FlowyHover(
isSelected: () => isSelected,
style: HoverStyle(
@@ -163,7 +163,7 @@ class _SuggestionsActionListState extends State<SuggestionsActionList> {
FlowySvg(
FlowySvgs.toolbar_arrow_down_m,
size: Size(12, 20),
- color: themeV2.icon_tertiary,
+ color: iconColor,
),
],
),
diff --git a/frontend/appflowy_flutter/lib/shared/flowy_error_page.dart b/frontend/appflowy_flutter/lib/shared/flowy_error_page.dart
index 5c5e788ddb..5942271206 100644
--- a/frontend/appflowy_flutter/lib/shared/flowy_error_page.dart
+++ b/frontend/appflowy_flutter/lib/shared/flowy_error_page.dart
@@ -100,7 +100,6 @@ class _DesktopSyncErrorPage extends StatelessWidget {
onTapUp: () {
getIt<ClipboardService>().setPlainText(error.toString());
showToastNotification(
-
message: LocaleKeys.message_copy_success.tr(),
bottomPadding: 0,
);
diff --git a/frontend/appflowy_flutter/lib/startup/tasks/appflowy_cloud_task.dart b/frontend/appflowy_flutter/lib/startup/tasks/appflowy_cloud_task.dart
index d8dc4dd121..184cc9dd09 100644
--- a/frontend/appflowy_flutter/lib/startup/tasks/appflowy_cloud_task.dart
+++ b/frontend/appflowy_flutter/lib/startup/tasks/appflowy_cloud_task.dart
@@ -136,7 +136,6 @@ class AppFlowyCloudDeepLink {
final context = AppGlobals.rootNavKey.currentState?.context;
if (context != null) {
showToastNotification(
-
message: err.msg,
);
}
diff --git a/frontend/appflowy_flutter/lib/user/presentation/helpers/handle_open_workspace_error.dart b/frontend/appflowy_flutter/lib/user/presentation/helpers/handle_open_workspace_error.dart
index 51c693843f..ccad6c0a26 100644
--- a/frontend/appflowy_flutter/lib/user/presentation/helpers/handle_open_workspace_error.dart
+++ b/frontend/appflowy_flutter/lib/user/presentation/helpers/handle_open_workspace_error.dart
@@ -17,14 +17,12 @@ void handleOpenWorkspaceError(BuildContext context, FlowyError error) {
case ErrorCode.InvalidEncryptSecret:
case ErrorCode.NetworkError:
showToastNotification(
-
message: error.msg,
type: ToastificationType.error,
);
break;
default:
showToastNotification(
-
message: error.msg,
type: ToastificationType.error,
callbacks: ToastificationCallbacks(
diff --git a/frontend/appflowy_flutter/lib/util/share_log_files.dart b/frontend/appflowy_flutter/lib/util/share_log_files.dart
index 0435c5fe52..b8dd390627 100644
--- a/frontend/appflowy_flutter/lib/util/share_log_files.dart
+++ b/frontend/appflowy_flutter/lib/util/share_log_files.dart
@@ -25,7 +25,6 @@ Future<void> shareLogFiles(BuildContext? context) async {
if (archiveLogFiles.isEmpty) {
if (context != null && context.mounted) {
showToastNotification(
-
message: LocaleKeys.noLogFiles.tr(),
type: ToastificationType.error,
);
@@ -42,7 +41,6 @@ Future<void> shareLogFiles(BuildContext? context) async {
if (zip == null) {
if (context != null && context.mounted) {
showToastNotification(
-
message: LocaleKeys.noLogFiles.tr(),
type: ToastificationType.error,
);
@@ -72,7 +70,6 @@ Future<void> shareLogFiles(BuildContext? context) async {
} catch (e) {
if (context != null && context.mounted) {
showToastNotification(
-
message: e.toString(),
type: ToastificationType.error,
);
diff --git a/frontend/appflowy_flutter/lib/workspace/application/settings/appearance/desktop_appearance.dart b/frontend/appflowy_flutter/lib/workspace/application/settings/appearance/desktop_appearance.dart
index 568fd76db0..2a707b6b2d 100644
--- a/frontend/appflowy_flutter/lib/workspace/application/settings/appearance/desktop_appearance.dart
+++ b/frontend/appflowy_flutter/lib/workspace/application/settings/appearance/desktop_appearance.dart
@@ -2,7 +2,6 @@ import 'package:appflowy/workspace/application/settings/appearance/base_appearan
import 'package:flowy_infra/size.dart';
import 'package:flowy_infra/theme.dart';
import 'package:flowy_infra/theme_extension.dart';
-import 'package:flowy_infra/theme_extension_v2.dart';
import 'package:flutter/material.dart';
class DesktopAppearance extends BaseAppearance {
@@ -152,11 +151,6 @@ class DesktopAppearance extends BaseAppearance {
lightIconColor: theme.lightIconColor,
toolbarHoverColor: theme.toolbarHoverColor,
),
- isLight
- ? lightAFThemeV2
- : darkAFThemeV2.copyWith(
- icon_primary: theme.icon,
- ),
],
);
}
diff --git a/frontend/appflowy_flutter/lib/workspace/application/settings/appearance/mobile_appearance.dart b/frontend/appflowy_flutter/lib/workspace/application/settings/appearance/mobile_appearance.dart
index 7778f1c9ce..eda3153459 100644
--- a/frontend/appflowy_flutter/lib/workspace/application/settings/appearance/mobile_appearance.dart
+++ b/frontend/appflowy_flutter/lib/workspace/application/settings/appearance/mobile_appearance.dart
@@ -4,7 +4,6 @@ import 'package:appflowy/workspace/application/settings/appearance/base_appearan
import 'package:flowy_infra/size.dart';
import 'package:flowy_infra/theme.dart';
import 'package:flowy_infra/theme_extension.dart';
-import 'package:flowy_infra/theme_extension_v2.dart';
import 'package:flutter/material.dart';
class MobileAppearance extends BaseAppearance {
@@ -30,7 +29,6 @@ class MobileAppearance extends BaseAppearance {
);
final codeFontStyle = getFontStyle(fontFamily: codeFontFamily);
- final isLight = brightness == Brightness.light;
final theme = brightness == Brightness.light
? appTheme.lightTheme
@@ -285,11 +283,6 @@ class MobileAppearance extends BaseAppearance {
toolbarHoverColor: theme.toolbarHoverColor,
),
ToolbarColorExtension.fromBrightness(brightness),
- isLight
- ? lightAFThemeV2
- : darkAFThemeV2.copyWith(
- icon_primary: theme.icon,
- ),
],
);
}
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/workspace/sidebar_workspace.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/workspace/sidebar_workspace.dart
index 20160d32ec..50ea9d83c7 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/workspace/sidebar_workspace.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/workspace/sidebar_workspace.dart
@@ -169,7 +169,6 @@ class _SidebarWorkspaceState extends State<SidebarWorkspace> {
if (message != null) {
showToastNotification(
-
message: message,
type: result.fold(
(_) => ToastificationType.success,
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/account/account_deletion.dart b/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/account/account_deletion.dart
index 8cabffc6e3..e6c011156b 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/account/account_deletion.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/account/account_deletion.dart
@@ -193,7 +193,6 @@ Future<void> deleteMyAccount(
if (!isChecked) {
showToastNotification(
-
type: ToastificationType.warning,
bottomPadding: bottomPadding,
message: LocaleKeys
@@ -208,7 +207,6 @@ Future<void> deleteMyAccount(
if (confirmText.isEmpty || !_isConfirmTextValid(confirmText)) {
showToastNotification(
-
type: ToastificationType.warning,
bottomPadding: bottomPadding,
message: LocaleKeys
@@ -226,7 +224,6 @@ Future<void> deleteMyAccount(
loading.stop();
showToastNotification(
-
message: LocaleKeys
.newSettings_myAccount_deleteAccount_deleteAccountSuccess
.tr(),
@@ -245,7 +242,6 @@ Future<void> deleteMyAccount(
loading.stop();
showToastNotification(
-
type: ToastificationType.error,
bottomPadding: bottomPadding,
message: f.msg,
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/settings_manage_data_view.dart b/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/settings_manage_data_view.dart
index 194ad02beb..a2d911ea40 100644
--- a/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/settings_manage_data_view.dart
+++ b/frontend/appflowy_flutter/lib/workspace/presentation/settings/pages/settings_manage_data_view.dart
@@ -157,7 +157,6 @@ class SettingsManageDataView extends StatelessWidget {
if (context.mounted) {
showToastNotification(
-
message: LocaleKeys
.settings_manageDataPage_cache_dialog_successHint
.tr(),
diff --git a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/data/builder.dart b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/data/builder.dart
index c17dd14578..32b3335d0f 100644
--- a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/data/builder.dart
+++ b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/data/builder.dart
@@ -8,6 +8,7 @@ import 'package:appflowy_ui/src/theme/color_scheme/icon/icon_color_theme.dart';
import 'package:appflowy_ui/src/theme/color_scheme/surface/surface_color_scheme.dart';
import 'package:appflowy_ui/src/theme/color_scheme/text/text_color_scheme.dart';
import 'package:appflowy_ui/src/theme/dimensions.dart';
+import 'package:appflowy_ui/src/theme/shadow/shadow.dart';
import 'package:appflowy_ui/src/theme/spacing/spacing.dart';
import 'package:flutter/material.dart';
@@ -92,6 +93,35 @@ class AppFlowyThemeBuilder {
};
}
+ AppFlowyShadow buildShadow(Brightness brightness) {
+ return switch (brightness) {
+ Brightness.light => AppFlowyShadow(
+ small: const BoxShadow(
+ offset: Offset(0.0, 2.0),
+ blurRadius: 16.0,
+ color: Color(0x1F000000),
+ ),
+ medium: const BoxShadow(
+ offset: Offset(0.0, 4.0),
+ blurRadius: 32.0,
+ color: Color(0x1F000000),
+ ),
+ ),
+ Brightness.dark => AppFlowyShadow(
+ small: BoxShadow(
+ offset: Offset(0.0, 2.0),
+ blurRadius: 16.0,
+ color: Color(0x7A000000),
+ ),
+ medium: BoxShadow(
+ offset: Offset(0.0, 4.0),
+ blurRadius: 32.0,
+ color: Color(0x7A000000),
+ ),
+ ),
+ };
+ }
+
AppFlowyBorderColorScheme buildBorderColorScheme(
AppFlowyBaseColorScheme colorScheme,
Brightness brightness,
diff --git a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/data/data.dart b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/data/data.dart
index 68fb378c0f..9494bdf0e2 100644
--- a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/data/data.dart
+++ b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/data/data.dart
@@ -8,6 +8,7 @@ import 'package:appflowy_ui/src/theme/color_scheme/icon/icon_color_theme.dart';
import 'package:appflowy_ui/src/theme/color_scheme/surface/surface_color_scheme.dart';
import 'package:appflowy_ui/src/theme/color_scheme/text/text_color_scheme.dart';
import 'package:appflowy_ui/src/theme/data/builder.dart';
+import 'package:appflowy_ui/src/theme/shadow/shadow.dart';
import 'package:appflowy_ui/src/theme/spacing/spacing.dart';
import 'package:appflowy_ui/src/theme/text_style/text_style.dart';
import 'package:flutter/material.dart';
@@ -36,6 +37,8 @@ abstract class AppFlowyBaseTheme {
AppFlowySpacing get spacing;
AppFlowyBrandColorScheme get brandColorScheme;
+
+ AppFlowyShadow get shadow;
}
class AppFlowyThemeData extends AppFlowyBaseTheme {
@@ -67,10 +70,10 @@ class AppFlowyThemeData extends AppFlowyBaseTheme {
colorScheme,
Brightness.light,
);
+ final shadow = themeBuilder.buildShadow(Brightness.light);
final brandColorScheme = themeBuilder.buildBrandColorScheme(colorScheme);
final borderRadius = themeBuilder.buildBorderRadius(colorScheme);
final spacing = themeBuilder.buildSpacing(colorScheme);
-
return AppFlowyThemeData(
colorScheme: colorScheme,
textColorScheme: textColorScheme,
@@ -83,6 +86,7 @@ class AppFlowyThemeData extends AppFlowyBaseTheme {
borderRadius: borderRadius,
spacing: spacing,
brandColorScheme: brandColorScheme,
+ shadow: shadow,
);
}
@@ -113,10 +117,10 @@ class AppFlowyThemeData extends AppFlowyBaseTheme {
colorScheme,
Brightness.dark,
);
+ final shadow = themeBuilder.buildShadow(Brightness.dark);
final brandColorScheme = themeBuilder.buildBrandColorScheme(colorScheme);
final borderRadius = themeBuilder.buildBorderRadius(colorScheme);
final spacing = themeBuilder.buildSpacing(colorScheme);
-
return AppFlowyThemeData(
colorScheme: colorScheme,
textColorScheme: textColorScheme,
@@ -129,6 +133,7 @@ class AppFlowyThemeData extends AppFlowyBaseTheme {
borderRadius: borderRadius,
spacing: spacing,
brandColorScheme: brandColorScheme,
+ shadow: shadow,
);
}
@@ -144,6 +149,7 @@ class AppFlowyThemeData extends AppFlowyBaseTheme {
required this.brandColorScheme,
required this.iconColorTheme,
required this.backgroundColorScheme,
+ required this.shadow,
this.brightness = Brightness.light,
});
@@ -184,6 +190,9 @@ class AppFlowyThemeData extends AppFlowyBaseTheme {
@override
final AppFlowyBackgroundColorScheme backgroundColorScheme;
+ @override
+ final AppFlowyShadow shadow;
+
static AppFlowyTextColorScheme buildTextColorScheme(
AppFlowyBaseColorScheme colorScheme,
Brightness brightness,
diff --git a/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/shadow/shadow.dart b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/shadow/shadow.dart
new file mode 100644
index 0000000000..9bb2ac1116
--- /dev/null
+++ b/frontend/appflowy_flutter/packages/appflowy_ui/lib/src/theme/shadow/shadow.dart
@@ -0,0 +1,8 @@
+import 'package:flutter/widgets.dart';
+
+class AppFlowyShadow {
+ AppFlowyShadow({required this.small, required this.medium});
+
+ final BoxShadow small;
+ final BoxShadow medium;
+}
diff --git a/frontend/appflowy_flutter/packages/flowy_infra/lib/language.dart b/frontend/appflowy_flutter/packages/flowy_infra/lib/language.dart
index 5ad2435e99..6f37058f00 100644
--- a/frontend/appflowy_flutter/packages/flowy_infra/lib/language.dart
+++ b/frontend/appflowy_flutter/packages/flowy_infra/lib/language.dart
@@ -81,7 +81,7 @@ String languageFromLocale(Locale locale) {
case "ur":
return "اردو";
case "hin":
- return "हिन्दी";
+ return "हिन्दी";
}
// If not found then the language code will be displayed
return locale.languageCode;
diff --git a/frontend/appflowy_flutter/packages/flowy_infra/lib/theme_extension_v2.dart b/frontend/appflowy_flutter/packages/flowy_infra/lib/theme_extension_v2.dart
deleted file mode 100644
index b9136a00bc..0000000000
--- a/frontend/appflowy_flutter/packages/flowy_infra/lib/theme_extension_v2.dart
+++ /dev/null
@@ -1,99 +0,0 @@
-// ignore_for_file: non_constant_identifier_names
-
-import 'package:flutter/material.dart';
-
-@immutable
-class AFThemeExtensionV2 extends ThemeExtension<AFThemeExtensionV2> {
- static AFThemeExtensionV2 of(BuildContext context) =>
- Theme.of(context).extension<AFThemeExtensionV2>()!;
-
- static AFThemeExtensionV2? maybeOf(BuildContext context) =>
- Theme.of(context).extension<AFThemeExtensionV2>();
-
- const AFThemeExtensionV2({
- required this.icon_primary,
- required this.icon_tertiary,
- required this.text_tertiary,
- required this.border_grey_quaternary,
- required this.fill_theme_select,
- required this.fill_grey_thick_alpha_1,
- required this.shadow_medium,
- });
-
- final Color icon_primary;
- final Color icon_tertiary;
- final Color text_tertiary;
- final Color border_grey_quaternary;
- final Color fill_theme_select;
- final Color fill_grey_thick_alpha_1;
- final Color shadow_medium;
-
- @override
- AFThemeExtensionV2 copyWith({
- Color? icon_primary,
- Color? icon_tertiary,
- Color? text_tertiary,
- Color? border_grey_quaternary,
- Color? fill_theme_select,
- Color? fill_grey_thick_alpha_1,
- Color? shadow_medium,
- }) =>
- AFThemeExtensionV2(
- icon_primary: icon_primary ?? this.icon_primary,
- icon_tertiary: icon_tertiary ?? this.icon_tertiary,
- text_tertiary: text_tertiary ?? this.text_tertiary,
- border_grey_quaternary:
- border_grey_quaternary ?? this.border_grey_quaternary,
- fill_theme_select: fill_theme_select ?? this.fill_theme_select,
- fill_grey_thick_alpha_1:
- fill_grey_thick_alpha_1 ?? this.fill_grey_thick_alpha_1,
- shadow_medium: shadow_medium ?? this.shadow_medium,
- );
-
- @override
- ThemeExtension<AFThemeExtensionV2> lerp(
- ThemeExtension<AFThemeExtensionV2>? other, double t) {
- if (other is! AFThemeExtensionV2) {
- return this;
- }
- return AFThemeExtensionV2(
- icon_primary:
- Color.lerp(icon_primary, other.icon_primary, t) ?? icon_primary,
- icon_tertiary:
- Color.lerp(icon_tertiary, other.icon_tertiary, t) ?? icon_tertiary,
- text_tertiary:
- Color.lerp(text_tertiary, other.text_tertiary, t) ?? text_tertiary,
- border_grey_quaternary:
- Color.lerp(border_grey_quaternary, other.border_grey_quaternary, t) ??
- border_grey_quaternary,
- fill_theme_select:
- Color.lerp(fill_theme_select, other.fill_theme_select, t) ??
- fill_theme_select,
- fill_grey_thick_alpha_1: Color.lerp(
- fill_grey_thick_alpha_1, other.fill_grey_thick_alpha_1, t) ??
- fill_grey_thick_alpha_1,
- shadow_medium:
- Color.lerp(shadow_medium, other.shadow_medium, t) ?? shadow_medium,
- );
- }
-}
-
-const AFThemeExtensionV2 darkAFThemeV2 = AFThemeExtensionV2(
- icon_primary: Color(0xFF1F2329),
- icon_tertiary: Color(0xFF99A1A8),
- text_tertiary: Color(0xFFB5BBD3),
- border_grey_quaternary: Color(0xFFE8ECF3),
- fill_theme_select: Color(0x00BCF01F),
- fill_grey_thick_alpha_1: Color(0x1F23290F),
- shadow_medium: Color(0x1F22251F),
-);
-
-const AFThemeExtensionV2 lightAFThemeV2 = AFThemeExtensionV2(
- icon_primary: Color(0xFF1F2329),
- icon_tertiary: Color(0xFF99A1A8),
- text_tertiary: Color(0xFFB5BBD3),
- border_grey_quaternary: Color(0xFFE8ECF3),
- fill_theme_select: Color(0x00BCF01F),
- fill_grey_thick_alpha_1: Color(0x1F23290F),
- shadow_medium: Color(0x1F22251F),
-);
diff --git a/frontend/appflowy_flutter/pubspec.lock b/frontend/appflowy_flutter/pubspec.lock
index ae44b95eb3..1c6d66431d 100644
--- a/frontend/appflowy_flutter/pubspec.lock
+++ b/frontend/appflowy_flutter/pubspec.lock
@@ -673,14 +673,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "1.3.1"
- favicon:
- dependency: "direct main"
- description:
- name: favicon
- sha256: ebb7423ba7ccc87d3cce9b60de1b5f72004de3cddeedd88d98463fc7f66faf0c
- url: "https://pub.dev"
- source: hosted
- version: "1.1.2"
ffi:
dependency: transitive
description:
diff --git a/frontend/appflowy_flutter/pubspec.yaml b/frontend/appflowy_flutter/pubspec.yaml
index de26c31c1e..0cc553d1a7 100644
--- a/frontend/appflowy_flutter/pubspec.yaml
+++ b/frontend/appflowy_flutter/pubspec.yaml
@@ -31,7 +31,6 @@ dependencies:
auto_size_text_field: ^2.2.3
auto_updater: ^1.0.0
avatar_stack: ^3.0.0
- favicon: ^1.1.2
# BitsDojo Window for Windows
bitsdojo_window: ^0.1.6
diff --git a/frontend/appflowy_flutter/test/unit_test/link_preview/link_preview_test.dart b/frontend/appflowy_flutter/test/unit_test/link_preview/link_preview_test.dart
new file mode 100644
index 0000000000..5b6f88801a
--- /dev/null
+++ b/frontend/appflowy_flutter/test/unit_test/link_preview/link_preview_test.dart
@@ -0,0 +1,47 @@
+import 'package:appflowy/plugins/document/presentation/editor_plugins/link_preview/link_parsers/default_parser.dart';
+import 'package:flutter/foundation.dart';
+import 'package:flutter_test/flutter_test.dart';
+
+void main() async {
+ test(
+ 'description',
+ () async {
+ final links = [
+ 'https://www.baidu.com/',
+ 'https://appflowy.io/',
+ 'https://github.com/AppFlowy-IO/AppFlowy',
+ 'https://github.com/',
+ 'https://www.figma.com/design/3K0ai4FhDOJ3Lts8G3KOVP/Page?node-id=7282-4007&p=f&t=rpfvEvh9K9J9WkIo-0',
+ 'https://www.figma.com/files/drafts',
+ 'https://www.youtube.com/watch?v=LyY5Rh9qBvA',
+ 'https://www.youtube.com/',
+ 'https://www.youtube.com/watch?v=a6GDT7',
+ 'http://www.test.com/',
+ 'https://www.baidu.com/s?wd=test&rsv_spt=1&rsv_iqid=0xb6a7840b00e5324a&issp=1&f=8&rsv_bp=1&rsv_idx=2&ie=utf-8&tn=22073068_7_oem_dg&rsv_dl=tb&rsv_enter=1&rsv_sug3=5&rsv_sug1=4&rsv_sug7=100&rsv_sug2=0&rsv_btype=i&prefixsug=test&rsp=9&inputT=478&rsv_sug4=547',
+ 'https://www.google.com/',
+ 'https://www.google.com.hk/search?q=test&oq=test&gs_lcrp=EgZjaHJvbWUyCQgAEEUYORiABDIHCAEQABiABDIHCAIQABiABDIHCAMQABiABDIHCAQQABiABDIHCAUQABiABDIHCAYQABiABDIHCAcQABiABDIHCAgQLhiABDIHCAkQABiABNIBCTE4MDJqMGoxNagCCLACAfEFAQs7K9PprSfxBQELOyvT6a0n&sourceid=chrome&ie=UTF-8',
+ 'www.baidu.com',
+ 'baidu.com',
+ 'com',
+ 'https://www.baidu.com',
+ 'https://github.com/AppFlowy-IO/AppFlowy',
+ 'https://appflowy.com/app/c29fafc4-b7c0-4549-8702-71339b0fd9ea/59f36be8-9b2f-4d3e-b6a1-816c6c2043e5?blockId=GCY_T4',
+ ];
+
+ final parser = DefaultParser();
+ int i = 1;
+ for (final link in links) {
+ final formatLink = LinkInfoParser.formatUrl(link);
+ final siteInfo = await parser
+ .parse(Uri.tryParse(formatLink) ?? Uri.parse(formatLink));
+ if (siteInfo?.isEmpty() ?? true) {
+ debugPrint('$i : $formatLink ---- empty \n');
+ } else {
+ debugPrint('$i : $formatLink ---- \n$siteInfo \n');
+ }
+ i++;
+ }
+ },
+ timeout: const Timeout(Duration(seconds: 120)),
+ );
+}
diff --git a/frontend/resources/translations/en.json b/frontend/resources/translations/en.json
index 91f9ce7743..46cab3030a 100644
--- a/frontend/resources/translations/en.json
+++ b/frontend/resources/translations/en.json
@@ -2041,7 +2041,7 @@
"reload": "Reload",
"removeLink": "Remove Link",
"pasteHint": "Paste in https://...",
- "refuseConnect": "refued to connect."
+ "unableToDisplay": "unable to display"
}
}
},
diff --git a/frontend/resources/translations/zh-CN.json b/frontend/resources/translations/zh-CN.json
index 2731a0fb2e..d1433929bc 100644
--- a/frontend/resources/translations/zh-CN.json
+++ b/frontend/resources/translations/zh-CN.json
@@ -1517,6 +1517,27 @@
"placeholder": "粘贴视频链接",
"copiedToPasteBoard": "视频链接已复制到剪贴板",
"insertVideo": "添加视频"
+ },
+ "linkPreview": {
+ "typeSelection": {
+ "pasteAs": "粘贴为",
+ "mention": "提及",
+ "URL": "URL",
+ "bookmark": "书签",
+ "embed": "嵌入"
+ },
+ "linkPreviewMenu": {
+ "toMetion": "转换为提及",
+ "toUrl": "转换为URL",
+ "toEmbed": "转换为嵌入",
+ "toBookmark": "转换为书签",
+ "copyLink": "复制链接",
+ "replace": "替换",
+ "reload": "重新加载",
+ "removeLink": "移除链接",
+ "pasteHint": "粘贴 https://...",
+ "unableToDisplay": "无法显示"
+ }
}
},
"outlineBlock": {