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.

feat: support new design for mobile link (#7772)

Morn5b2853cca221
diff --git a/frontend/appflowy_flutter/integration_test/mobile/document/toolbar_test.dart b/frontend/appflowy_flutter/integration_test/mobile/document/toolbar_test.dart
index 72da283cd6..badb892fa5 100644
--- a/frontend/appflowy_flutter/integration_test/mobile/document/toolbar_test.dart
+++ b/frontend/appflowy_flutter/integration_test/mobile/document/toolbar_test.dart
@@ -1,12 +1,11 @@
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
+import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet_edit_link_widget.dart';
import 'package:appflowy/mobile/presentation/editor/mobile_editor_screen.dart';
import 'package:appflowy/mobile/presentation/mobile_bottom_navigation_bar.dart';
-import 'package:appflowy/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/appflowy_mobile_toolbar_item.dart';
-import 'package:appflowy/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/util.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:easy_localization/easy_localization.dart';
-import 'package:flowy_infra_ui/style_widget/text_field.dart';
+import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
@@ -15,103 +14,121 @@ import '../../shared/util.dart';
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
- group('toolbar menu:', () {
+ Future<void> createNeaPage(WidgetTester tester) async {
+ final createPageButton =
+ find.byKey(BottomNavigationBarItemType.add.valueKey);
+ await tester.tapButton(createPageButton);
+ expect(find.byType(MobileDocumentScreen), findsOneWidget);
+ final editor = find.byType(AppFlowyEditor);
+ expect(editor, findsOneWidget);
+ }
+
+ const testLink = 'https://appflowy.io/';
+
+ group('links', () {
testWidgets('insert links', (tester) async {
await tester.launchInAnonymousMode();
- final createPageButton = find.byKey(
- BottomNavigationBarItemType.add.valueKey,
- );
- await tester.tapButton(createPageButton);
- expect(find.byType(MobileDocumentScreen), findsOneWidget);
-
- final editor = find.byType(AppFlowyEditor);
- expect(editor, findsOneWidget);
+ await createNeaPage(tester);
+ await tester.editor.tapLineOfEditorAt(0);
final editorState = tester.editor.getCurrentEditorState();
- /// move cursor to content
- final root = editorState.document.root;
- final lastNode = root.children.lastOrNull;
- await editorState.updateSelectionWithReason(
- Selection.collapsed(Position(path: lastNode!.path)),
- );
- await tester.pumpAndSettle();
-
/// insert two lines of text
- const strFirst = 'FirstLine',
- strSecond = 'SecondLine',
- link = 'google.com';
- await editorState.insertTextAtCurrentSelection(strFirst);
- await tester.pumpAndSettle();
+ const strFirst = 'FirstLine', strSecond = 'SecondLine';
+ await tester.ime.insertText(strFirst);
await editorState.insertNewLine();
- await tester.pumpAndSettle();
- await editorState.insertTextAtCurrentSelection(strSecond);
- await tester.pumpAndSettle();
+ await tester.ime.insertText(strSecond);
final firstLine = find.text(strFirst, findRichText: true),
secondLine = find.text(strSecond, findRichText: true);
expect(firstLine, findsOneWidget);
expect(secondLine, findsOneWidget);
/// select the first line
- await tester.longPress(firstLine);
+ await tester.doubleTapAt(tester.getCenter(firstLine));
await tester.pumpAndSettle();
- /// find aa item and tap it
- final aaItem = find.byWidgetPredicate(
- (widget) =>
- widget is AppFlowyMobileToolbarIconItem &&
- widget.icon == FlowySvgs.m_toolbar_aa_m,
- );
- expect(aaItem, findsOneWidget);
- await tester.tapButton(aaItem);
-
/// find link button and tap it
- final linkButton = find.byWidgetPredicate(
- (widget) =>
- widget is MobileToolbarMenuItemWrapper &&
- widget.icon == FlowySvgs.m_toolbar_link_m,
- );
- expect(linkButton, findsOneWidget);
+ final linkButton = find.byFlowySvg(FlowySvgs.toolbar_link_m);
await tester.tapButton(linkButton);
/// input the link
- final linkField = find.byWidgetPredicate(
- (w) =>
- w is FlowyTextField &&
- w.hintText == LocaleKeys.document_inlineLink_url_placeholder.tr(),
- );
- await tester.enterText(linkField, link);
+ final textFormField = find.byType(TextFormField);
+ expect(textFormField, findsNWidgets(2));
+ final linkField = textFormField.last;
+ await tester.enterText(linkField, testLink);
await tester.pumpAndSettle();
+ await tester.tapButton(find.byFlowySvg(FlowySvgs.toolbar_link_earth_m));
- /// complete inputting
+ /// apply the link
await tester.tapButton(find.text(LocaleKeys.button_done.tr()));
/// do it again
/// select the second line
- await tester.longPress(secondLine);
+ await tester.doubleTapAt(tester.getCenter(secondLine));
await tester.pumpAndSettle();
- await tester.tapButton(aaItem);
await tester.tapButton(linkButton);
- await tester.enterText(linkField, link);
+ await tester.enterText(linkField, testLink);
await tester.pumpAndSettle();
+ await tester.tapButton(find.byFlowySvg(FlowySvgs.toolbar_link_earth_m));
await tester.tapButton(find.text(LocaleKeys.button_done.tr()));
final firstNode = editorState.getNodeAtPath([0]);
final secondNode = editorState.getNodeAtPath([1]);
Map commonDeltaJson(String insert) => {
- "insert": insert,
- "attributes": {"href": link},
+ 'insert': insert,
+ 'attributes': {'href': testLink, 'is_page_link': false},
};
expect(
firstNode?.delta?.toJson(),
- commonDeltaJson(strFirst),
+ [commonDeltaJson(strFirst)],
);
expect(
secondNode?.delta?.toJson(),
- commonDeltaJson(strSecond),
+ [commonDeltaJson(strSecond)],
);
});
+
+ testWidgets('change a link', (tester) async {
+ await tester.launchInAnonymousMode();
+
+ await createNeaPage(tester);
+ await tester.editor.tapLineOfEditorAt(0);
+ final editorState = tester.editor.getCurrentEditorState();
+ const testText = 'TestText';
+ await tester.ime.insertText(testText);
+ final textFinder = find.text(testText, findRichText: true);
+
+ /// select the first line
+ await tester.doubleTapAt(tester.getCenter(textFinder));
+ await tester.pumpAndSettle();
+
+ /// find link button and tap it
+ final linkButton = find.byFlowySvg(FlowySvgs.toolbar_link_m);
+ await tester.tapButton(linkButton);
+
+ /// input the link
+ final textFormField = find.byType(TextFormField);
+ expect(textFormField, findsNWidgets(2));
+ final linkField = textFormField.last;
+ await tester.enterText(linkField, testLink);
+ await tester.pumpAndSettle();
+ await tester.tapButton(find.byFlowySvg(FlowySvgs.toolbar_link_earth_m));
+
+ /// apply the link
+ await tester.tapButton(find.text(LocaleKeys.button_done.tr()));
+
+ /// show edit link menu
+ await tester.longPress(textFinder);
+ await tester.pumpAndSettle();
+ final linkEditMenu = find.byType(MobileBottomSheetEditLinkWidget);
+ expect(linkEditMenu, findsOneWidget);
+
+ /// remove the link
+ await tester.tapButton(find.byFlowySvg(FlowySvgs.toolbar_link_unlink_m));
+ final node = editorState.getNodeAtPath([0]);
+ expect(node?.delta?.toJson(), [{'insert': testText}]);
+ });
});
}
diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/bottom_sheet/bottom_sheet_edit_link_widget.dart b/frontend/appflowy_flutter/lib/mobile/presentation/bottom_sheet/bottom_sheet_edit_link_widget.dart
index bed69e1cc4..5da62a725f 100644
--- a/frontend/appflowy_flutter/lib/mobile/presentation/bottom_sheet/bottom_sheet_edit_link_widget.dart
+++ b/frontend/appflowy_flutter/lib/mobile/presentation/bottom_sheet/bottom_sheet_edit_link_widget.dart
@@ -1,22 +1,37 @@
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet_header.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/desktop_toolbar/link/link_edit_menu.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/desktop_toolbar/link/link_search_text_field.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/desktop_toolbar/link/link_styles.dart';
+import 'package:appflowy/plugins/shared/share/constants.dart';
+import 'package:appflowy/user/application/user_service.dart';
+import 'package:appflowy/workspace/application/view/view_service.dart';
+import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
+import 'package:appflowy_result/appflowy_result.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';
import 'package:go_router/go_router.dart';
+// ignore: implementation_imports
+import 'package:appflowy_editor/src/editor/util/link_util.dart';
class MobileBottomSheetEditLinkWidget extends StatefulWidget {
const MobileBottomSheetEditLinkWidget({
super.key,
- required this.text,
- required this.href,
- required this.onEdit,
+ required this.linkInfo,
+ required this.onApply,
+ required this.onRemoveLink,
+ required this.currentViewId,
+ required this.onDispose,
});
- final String text;
- final String? href;
- final void Function(String text, String href) onEdit;
+ final LinkInfo linkInfo;
+ final ValueChanged<LinkInfo> onApply;
+ final ValueChanged<LinkInfo> onRemoveLink;
+ final VoidCallback onDispose;
+ final String currentViewId;
@override
State<MobileBottomSheetEditLinkWidget> createState() =>
@@ -25,80 +40,367 @@ class MobileBottomSheetEditLinkWidget extends StatefulWidget {
class _MobileBottomSheetEditLinkWidgetState
extends State<MobileBottomSheetEditLinkWidget> {
- late final TextEditingController textController;
- late final TextEditingController hrefController;
+ ValueChanged<LinkInfo> get onApply => widget.onApply;
+
+ ValueChanged<LinkInfo> get onRemoveLink => widget.onRemoveLink;
+
+ late TextEditingController linkNameController =
+ TextEditingController(text: linkInfo.name);
+ final textFocusNode = FocusNode();
+ late LinkInfo linkInfo = widget.linkInfo;
+ late LinkSearchTextField searchTextField;
+ bool isShowingSearchResult = false;
+ ViewPB? currentView;
+ bool showErrorText = false;
+ bool showRemoveLink = false;
+
+ AppFlowyThemeData get theme => AppFlowyTheme.of(context);
@override
void initState() {
super.initState();
-
- textController = TextEditingController(
- text: widget.text,
- );
- hrefController = TextEditingController(
- text: widget.href,
- );
+ final isPageLink = linkInfo.isPage;
+ if (isPageLink) getPageView();
+ searchTextField = LinkSearchTextField(
+ initialSearchText: isPageLink ? '' : linkInfo.link,
+ initialViewId: linkInfo.viewId,
+ currentViewId: widget.currentViewId,
+ onEnter: () {},
+ onEscape: () {},
+ onDataRefresh: () {
+ if (mounted) setState(() {});
+ },
+ )..searchRecentViews();
+ if (linkInfo.link.isEmpty) {
+ isShowingSearchResult = true;
+ } else {
+ showRemoveLink = true;
+ textFocusNode.requestFocus();
+ }
+ textFocusNode.addListener(() {
+ if (!mounted) return;
+ if (textFocusNode.hasFocus) {
+ setState(() {
+ isShowingSearchResult = false;
+ });
+ }
+ });
}
@override
void dispose() {
- textController.dispose();
- hrefController.dispose();
+ linkNameController.dispose();
+ textFocusNode.dispose();
+ searchTextField.dispose();
+ widget.onDispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
+ return SizedBox(
+ height: MediaQuery.of(context).size.height * 0.8,
+ child: SingleChildScrollView(
+ child: Column(
+ children: [
+ BottomSheetHeader(
+ title: LocaleKeys.editor_editLink.tr(),
+ onClose: () => context.pop(),
+ confirmButton: FlowyTextButton(
+ LocaleKeys.button_done.tr(),
+ constraints:
+ const BoxConstraints.tightFor(width: 62, height: 30),
+ padding: const EdgeInsets.only(left: 12),
+ fontColor: theme.textColorScheme.onFill,
+ fillColor: Theme.of(context).primaryColor,
+ onPressed: () {
+ if (isShowingSearchResult) {
+ onConfirm();
+ return;
+ }
+ if (linkInfo.link.isEmpty || !isUri(linkInfo.link)) {
+ setState(() {
+ showErrorText = true;
+ });
+ return;
+ }
+ widget.onApply.call(linkInfo);
+ context.pop();
+ },
+ ),
+ ),
+ const VSpace(20.0),
+ buildNameTextField(),
+ const VSpace(16.0),
+ buildLinkField(),
+ const VSpace(20.0),
+ buildRemoveLink(),
+ ],
+ ),
+ ),
+ );
+ }
+
+ Widget buildNameTextField() {
+ return SizedBox(
+ height: 48,
+ child: TextFormField(
+ focusNode: textFocusNode,
+ textAlign: TextAlign.left,
+ controller: linkNameController,
+ style: TextStyle(
+ fontSize: 16,
+ height: 20 / 16,
+ fontWeight: FontWeight.w400,
+ ),
+ onChanged: (text) {
+ linkInfo = LinkInfo(
+ name: text,
+ link: linkInfo.link,
+ isPage: linkInfo.isPage,
+ );
+ },
+ decoration: LinkStyle.buildLinkTextFieldInputDecoration(
+ LocaleKeys.document_toolbar_linkNameHint.tr(),
+ contentPadding: EdgeInsets.all(14),
+ context,
+ ),
+ ),
+ );
+ }
+
+ Widget buildLinkField() {
+ final width = MediaQuery.of(context).size.width;
+ final showPageView = linkInfo.isPage && !isShowingSearchResult;
+ Widget child;
+ if (showPageView) {
+ child = buildPageView();
+ } else if (!isShowingSearchResult) {
+ child = buildLinkView();
+ } else {
+ return Column(
+ mainAxisSize: MainAxisSize.min,
+ crossAxisAlignment: CrossAxisAlignment.start,
+ children: [
+ searchTextField.buildTextField(
+ autofocus: true,
+ context: context,
+ contentPadding: EdgeInsets.all(14),
+ ),
+ VSpace(6),
+ searchTextField.buildResultContainer(
+ context: context,
+ onPageLinkSelected: onPageSelected,
+ onLinkSelected: onLinkSelected,
+ width: width - 32,
+ ),
+ ],
+ );
+ }
return Column(
+ crossAxisAlignment: CrossAxisAlignment.start,
mainAxisSize: MainAxisSize.min,
children: [
- BottomSheetHeader(
- title: LocaleKeys.editor_editLink.tr(),
- onClose: () => context.pop(),
- onDone: () {
- widget.onEdit(textController.text, hrefController.text);
- },
+ child,
+ if (showErrorText)
+ Padding(
+ padding: const EdgeInsets.only(top: 4),
+ child: FlowyText.regular(
+ LocaleKeys.document_plugins_file_networkUrlInvalid.tr(),
+ color: theme.textColorScheme.error,
+ fontSize: 12,
+ figmaLineHeight: 16,
+ ),
+ ),
+ ],
+ );
+ }
+
+ Widget buildPageView() {
+ final height = 48.0;
+ late Widget child;
+ final view = currentView;
+ if (view == null) {
+ child = Center(
+ child: SizedBox.fromSize(
+ size: Size(10, 10),
+ child: CircularProgressIndicator(),
),
- const VSpace(20.0),
- _buildTextField(
- textController,
- LocaleKeys.document_inlineLink_title_placeholder.tr(),
+ );
+ } else {
+ final viewName = view.name;
+ final displayName = viewName.isEmpty
+ ? LocaleKeys.document_title_placeholder.tr()
+ : viewName;
+ child = GestureDetector(
+ onTap: showSearchResult,
+ child: Container(
+ height: height,
+ color: Colors.grey.withAlpha(1),
+ padding: EdgeInsets.all(14),
+ child: Row(
+ children: [
+ searchTextField.buildIcon(view),
+ HSpace(4),
+ Flexible(
+ child: FlowyText.regular(
+ displayName,
+ overflow: TextOverflow.ellipsis,
+ figmaLineHeight: 20,
+ fontSize: 14,
+ ),
+ ),
+ ],
+ ),
),
- const VSpace(12.0),
- _buildTextField(
- hrefController,
- LocaleKeys.document_inlineLink_url_placeholder.tr(),
+ );
+ }
+ return Container(
+ height: height,
+ decoration: buildBorderDecoration(),
+ child: child,
+ );
+ }
+
+ Widget buildLinkView() {
+ return Container(
+ height: 48,
+ decoration: buildBorderDecoration(),
+ child: GestureDetector(
+ onTap: showSearchResult,
+ child: Padding(
+ padding: EdgeInsets.all(12),
+ child: Row(
+ children: [
+ FlowySvg(FlowySvgs.toolbar_link_earth_m),
+ HSpace(8),
+ Flexible(
+ child: FlowyText.regular(
+ linkInfo.link,
+ overflow: TextOverflow.ellipsis,
+ figmaLineHeight: 20,
+ ),
+ ),
+ ],
+ ),
),
- const VSpace(12.0),
- ],
+ ),
);
}
- Widget _buildTextField(
- TextEditingController controller,
- String? hintText,
- ) {
- return SizedBox(
- height: 48.0,
- child: FlowyTextField(
- controller: controller,
- hintText: hintText,
- textStyle: const TextStyle(fontSize: 16.0),
- hintStyle: const TextStyle(fontSize: 16.0),
- suffixIcon: Padding(
- padding: const EdgeInsets.all(4.0),
- child: FlowyButton(
- text: const FlowySvg(
- FlowySvgs.close_lg,
- ),
- margin: EdgeInsets.zero,
- useIntrinsicWidth: true,
- onTap: () {
- controller.clear();
- },
+ Widget buildRemoveLink() {
+ if (!showRemoveLink) return SizedBox.shrink();
+ return GestureDetector(
+ onTap: () {
+ widget.onRemoveLink(linkInfo);
+ context.pop();
+ },
+ child: SizedBox(
+ height: 32,
+ child: Center(
+ child: Row(
+ mainAxisSize: MainAxisSize.min,
+ children: [
+ FlowySvg(
+ FlowySvgs.mobile_icon_remove_link_m,
+ color: theme.iconColorScheme.secondary,
+ ),
+ HSpace(8),
+ FlowyText.regular(
+ LocaleKeys.editor_removeLink.tr(),
+ overflow: TextOverflow.ellipsis,
+ figmaLineHeight: 20,
+ color: theme.textColorScheme.secondary,
+ ),
+ ],
),
),
),
);
}
+
+ void onConfirm() {
+ searchTextField.onSearchResult(
+ onLink: onLinkSelected,
+ onRecentViews: () => onPageSelected(searchTextField.currentRecentView),
+ onSearchViews: () => onPageSelected(searchTextField.currentSearchedView),
+ onEmpty: () {
+ searchTextField.unfocus();
+ },
+ );
+ }
+
+ Future<void> onPageSelected(ViewPB view) async {
+ currentView = view;
+ final link = ShareConstants.buildShareUrl(
+ workspaceId: await UserBackendService.getCurrentWorkspace().fold(
+ (s) => s.id,
+ (f) => '',
+ ),
+ viewId: view.id,
+ );
+ linkInfo = LinkInfo(
+ name: linkInfo.name,
+ link: link,
+ isPage: true,
+ );
+ searchTextField.updateText(linkInfo.link);
+ if (mounted) {
+ setState(() {
+ isShowingSearchResult = false;
+ searchTextField.unfocus();
+ });
+ }
+ }
+
+ void onLinkSelected() {
+ if (mounted) {
+ linkInfo = LinkInfo(
+ name: linkInfo.name,
+ link: searchTextField.searchText,
+ );
+ hideSearchResult();
+ }
+ }
+
+ void hideSearchResult() {
+ setState(() {
+ isShowingSearchResult = false;
+ searchTextField.unfocus();
+ textFocusNode.unfocus();
+ });
+ }
+
+ void showSearchResult() {
+ setState(() {
+ if (linkInfo.isPage) searchTextField.updateText('');
+ isShowingSearchResult = true;
+ searchTextField.requestFocus();
+ });
+ }
+
+ Future<void> getPageView() async {
+ if (!linkInfo.isPage) return;
+ final (view, isInTrash, isDeleted) =
+ await ViewBackendService.getMentionPageStatus(linkInfo.viewId);
+ if (mounted) {
+ setState(() {
+ currentView = view;
+ });
+ }
+ }
+
+ BoxDecoration buildCardDecoration() {
+ return BoxDecoration(
+ borderRadius: BorderRadius.circular(theme.borderRadius.l),
+ boxShadow: theme.shadow.medium,
+ );
+ }
+
+ BoxDecoration buildBorderDecoration() {
+ return BoxDecoration(
+ borderRadius: BorderRadius.circular(theme.borderRadius.l),
+ border: Border.all(color: theme.borderColorScheme.greyPrimary),
+ );
+ }
}
diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/bottom_sheet/bottom_sheet_header.dart b/frontend/appflowy_flutter/lib/mobile/presentation/bottom_sheet/bottom_sheet_header.dart
index e1bc32a6f0..b23b5394bc 100644
--- a/frontend/appflowy_flutter/lib/mobile/presentation/bottom_sheet/bottom_sheet_header.dart
+++ b/frontend/appflowy_flutter/lib/mobile/presentation/bottom_sheet/bottom_sheet_header.dart
@@ -8,11 +8,13 @@ class BottomSheetHeader extends StatelessWidget {
this.title,
this.onClose,
this.onDone,
+ this.confirmButton,
});
final String? title;
final VoidCallback? onClose;
final VoidCallback? onDone;
+ final Widget? confirmButton;
@override
Widget build(BuildContext context) {
@@ -36,12 +38,10 @@ class BottomSheetHeader extends StatelessWidget {
fontSize: 16,
),
),
- if (onDone != null)
+ if (onDone != null || confirmButton != null)
Align(
alignment: Alignment.centerRight,
- child: BottomSheetDoneButton(
- onDone: onDone,
- ),
+ child: confirmButton ?? BottomSheetDoneButton(onDone: onDone),
),
],
);
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 002d569c7b..56b959a302 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
@@ -1,5 +1,4 @@
import 'package:appflowy/generated/locale_keys.g.dart';
-import 'package:appflowy/plugins/document/presentation/editor_plugins/desktop_toolbar/link/link_styles.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/toolbar_item/custom_link_toolbar_item.dart';
import 'package:appflowy/plugins/shared/share/constants.dart';
import 'package:appflowy/workspace/application/user/user_workspace_bloc.dart';
@@ -114,6 +113,7 @@ class _LinkCreateMenuState extends State<LinkCreateMenu> {
}
Widget buildSearchContainer() {
+ final theme = AppFlowyTheme.maybeOf(context);
return Container(
width: 320,
decoration: buildToolbarLinkDecoration(context),
@@ -137,8 +137,9 @@ class _LinkCreateMenuState extends State<LinkCreateMenu> {
constraints: BoxConstraints(maxWidth: 72, minHeight: 32),
fontSize: 14,
fontColor: Colors.white,
- fillColor: LinkStyle.fillThemeThick,
- hoverColor: LinkStyle.fillThemeThick.withAlpha(200),
+ fillColor: theme?.fillColorScheme.themeThick,
+ hoverColor:
+ theme?.fillColorScheme.themeThick.withAlpha(200),
lineHeight: 20 / 14,
fontWeight: FontWeight.w600,
onPressed: onSubmittedLink,
@@ -150,7 +151,7 @@ class _LinkCreateMenuState extends State<LinkCreateMenu> {
padding: const EdgeInsets.only(top: 4),
child: FlowyText.regular(
LocaleKeys.document_plugins_file_networkUrlInvalid.tr(),
- color: LinkStyle.textStatusError,
+ color: theme?.textColorScheme.error,
fontSize: 12,
figmaLineHeight: 16,
),
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/desktop_toolbar/link/link_edit_menu.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/desktop_toolbar/link/link_edit_menu.dart
index e90ee22a80..21a440461c 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/desktop_toolbar/link/link_edit_menu.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/desktop_toolbar/link/link_edit_menu.dart
@@ -3,11 +3,11 @@ import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/toolbar_item/custom_link_toolbar_item.dart';
import 'package:appflowy/plugins/shared/share/constants.dart';
import 'package:appflowy/user/application/user_service.dart';
-import 'package:appflowy/util/theme_extension.dart';
import 'package:appflowy/workspace/application/view/view_service.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:appflowy_result/appflowy_result.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';
@@ -53,6 +53,8 @@ class _LinkEditMenuState extends State<LinkEditMenu> {
ViewPB? currentView;
bool showErrorText = false;
+ AppFlowyThemeData? get theme => AppFlowyTheme.maybeOf(context);
+
@override
void initState() {
super.initState();
@@ -91,6 +93,7 @@ class _LinkEditMenuState extends State<LinkEditMenu> {
final showingRecent =
searchTextField.showingRecent && isShowingSearchResult;
final errorHeight = showErrorText ? 20.0 : 0.0;
+ final theme = AppFlowyTheme.of(context);
return GestureDetector(
onTap: onDismiss,
child: Focus(
@@ -114,7 +117,7 @@ class _LinkEditMenuState extends State<LinkEditMenu> {
left: 20,
child: FlowyText.semibold(
LocaleKeys.document_toolbar_pageOrURL.tr(),
- color: LinkStyle.textTertiary,
+ color: theme.textColorScheme.tertiary,
fontSize: 12,
figmaLineHeight: 16,
),
@@ -124,7 +127,7 @@ class _LinkEditMenuState extends State<LinkEditMenu> {
left: 20,
child: FlowyText.semibold(
LocaleKeys.document_toolbar_linkName.tr(),
- color: LinkStyle.textTertiary,
+ color: theme.textColorScheme.tertiary,
fontSize: 12,
figmaLineHeight: 16,
),
@@ -194,7 +197,7 @@ class _LinkEditMenuState extends State<LinkEditMenu> {
padding: const EdgeInsets.only(top: 4),
child: FlowyText.regular(
LocaleKeys.document_plugins_file_networkUrlInvalid.tr(),
- color: LinkStyle.textStatusError,
+ color: theme?.textColorScheme.error,
fontSize: 12,
figmaLineHeight: 16,
),
@@ -236,9 +239,7 @@ class _LinkEditMenuState extends State<LinkEditMenu> {
constraints: BoxConstraints(maxWidth: 78, minHeight: 32),
fontSize: 14,
lineHeight: 20 / 14,
- fontColor: Theme.of(context).isLightMode
- ? LinkStyle.textPrimary
- : Theme.of(context).iconTheme.color,
+ fontColor: theme?.textColorScheme.primary,
fillColor: Colors.transparent,
fontWeight: FontWeight.w400,
onPressed: onDismiss,
@@ -255,9 +256,9 @@ class _LinkEditMenuState extends State<LinkEditMenu> {
constraints: BoxConstraints(maxWidth: 78, minHeight: 32),
fontSize: 14,
lineHeight: 20 / 14,
- hoverColor: LinkStyle.fillThemeThick.withAlpha(200),
+ hoverColor: theme?.fillColorScheme.themeThick.withAlpha(200),
fontColor: Colors.white,
- fillColor: LinkStyle.fillThemeThick,
+ fillColor: theme?.fillColorScheme.themeThick,
fontWeight: FontWeight.w400,
onPressed: onApply,
);
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/desktop_toolbar/link/link_extension.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/desktop_toolbar/link/link_extension.dart
new file mode 100644
index 0000000000..9232c97276
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/desktop_toolbar/link/link_extension.dart
@@ -0,0 +1,39 @@
+import 'package:appflowy/plugins/document/presentation/editor_plugins/desktop_toolbar/link/link_edit_menu.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/toolbar_item/custom_link_toolbar_item.dart';
+import 'package:appflowy_editor/appflowy_editor.dart';
+
+extension LinkExtension on EditorState {
+ void removeLink(Selection selection) {
+ final node = getNodeAtPath(selection.end.path);
+ if (node == null) {
+ return;
+ }
+ final index = selection.normalized.startIndex;
+ final length = selection.length;
+ final transaction = this.transaction
+ ..formatText(
+ node,
+ index,
+ length,
+ {
+ BuiltInAttributeKey.href: null,
+ kIsPageLink: null,
+ },
+ );
+ apply(transaction);
+ }
+
+ void applyLink(Selection selection, LinkInfo info) {
+ final node = getNodeAtPath(selection.start.path);
+ if (node == null) return;
+ final transaction = this.transaction;
+ transaction.replaceText(
+ node,
+ selection.startIndex,
+ selection.length,
+ info.name,
+ attributes: info.toAttribute(),
+ );
+ apply(transaction);
+ }
+}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/desktop_toolbar/link/link_hover_menu.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/desktop_toolbar/link/link_hover_menu.dart
index c992e40c61..b11a73daff 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/desktop_toolbar/link/link_hover_menu.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/desktop_toolbar/link/link_hover_menu.dart
@@ -10,6 +10,7 @@ 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/mention/mention_block.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/mention/mention_page_block.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/link_toolbar_item.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/toolbar_item/custom_link_toolbar_item.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/util/theme_extension.dart';
@@ -23,9 +24,11 @@ import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
+import 'package:universal_platform/universal_platform.dart';
import 'link_create_menu.dart';
import 'link_edit_menu.dart';
+import 'link_extension.dart';
class LinkHoverTrigger extends StatefulWidget {
const LinkHoverTrigger({
@@ -87,6 +90,20 @@ class _LinkHoverTriggerState extends State<LinkHoverTrigger> {
@override
Widget build(BuildContext context) {
+ final placeHolder = Container(
+ color: Colors.black.withAlpha(1),
+ width: size.width,
+ height: size.height,
+ );
+ if (UniversalPlatform.isMobile) {
+ return GestureDetector(
+ onTap: openLink,
+ onLongPress: () async {
+ await showEditLinkBottomSheet(context, selection, editorState);
+ },
+ child: placeHolder,
+ );
+ }
return MouseRegion(
cursor: SystemMouseCursors.click,
onEnter: (v) {
@@ -101,15 +118,7 @@ class _LinkHoverTriggerState extends State<LinkHoverTrigger> {
isHoverTriggerHovering = false;
tryToDismissLinkHoverMenu();
},
- child: buildHoverPopover(
- buildEditPopover(
- Container(
- color: Colors.black.withAlpha(1),
- width: size.width,
- height: size.height,
- ),
- ),
- ),
+ child: buildHoverPopover(buildEditPopover(placeHolder)),
);
}
@@ -147,7 +156,7 @@ class _LinkHoverTriggerState extends State<LinkHoverTrigger> {
onOpenLink: openLink,
onCopyLink: () => copyLink(context),
onEditLink: showLinkEditMenu,
- onRemoveLink: () => removeLink(editorState, selection),
+ onRemoveLink: () => editorState.removeLink(selection),
),
child: child,
);
@@ -176,18 +185,7 @@ class _LinkHoverTriggerState extends State<LinkHoverTrigger> {
currentViewId: currentViewId,
linkInfo: LinkInfo(name: title, link: href, isPage: isPage),
onDismiss: () => editMenuController.close(),
- onApply: (info) async {
- final transaction = editorState.transaction;
- transaction.replaceText(
- widget.node,
- selection.startIndex,
- selection.length,
- info.name,
- attributes: info.toAttribute(),
- );
- editMenuController.close();
- await editorState.apply(transaction);
- },
+ onApply: (info) => editorState.applyLink(selection, info),
onRemoveLink: (linkinfo) =>
onRemoveAndReplaceLink(editorState, selection, linkinfo.name),
),
@@ -198,7 +196,10 @@ class _LinkHoverTriggerState extends State<LinkHoverTrigger> {
void onToolbarShow() => hoverMenuController.close();
void showLinkHoverMenu() {
- if (isHoverMenuShowing || toolbarController.isToolbarShowing || !mounted) {
+ if (UniversalPlatform.isMobile ||
+ isHoverMenuShowing ||
+ toolbarController.isToolbarShowing ||
+ !mounted) {
return;
}
keepEditorFocusNotifier.increase();
@@ -206,6 +207,7 @@ class _LinkHoverTriggerState extends State<LinkHoverTrigger> {
}
void showLinkEditMenu() {
+ if (UniversalPlatform.isMobile) return;
keepEditorFocusNotifier.increase();
hoverMenuController.close();
editMenuController.show();
@@ -245,29 +247,6 @@ class _LinkHoverTriggerState extends State<LinkHoverTrigger> {
hoverMenuController.close();
}
- void removeLink(
- EditorState editorState,
- Selection selection,
- ) {
- final node = editorState.getNodeAtPath(selection.end.path);
- if (node == null) {
- return;
- }
- final index = selection.normalized.startIndex;
- final length = selection.length;
- final transaction = editorState.transaction
- ..formatText(
- node,
- index,
- length,
- {
- BuiltInAttributeKey.href: null,
- kIsPageLink: null,
- },
- );
- editorState.apply(transaction);
- }
-
Future<void> convertLinkTo(
EditorState editorState,
Selection selection,
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/desktop_toolbar/link/link_replace_menu.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/desktop_toolbar/link/link_replace_menu.dart
index d08442d779..a238af0171 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/desktop_toolbar/link/link_replace_menu.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/desktop_toolbar/link/link_replace_menu.dart
@@ -1,6 +1,7 @@
import 'package:appflowy/generated/locale_keys.g.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_ui/flowy_infra_ui.dart';
import 'package:flutter/material.dart';
@@ -134,7 +135,7 @@ class _LinkReplaceMenuState extends State<LinkReplaceMenu> {
padding: const EdgeInsets.only(top: 4),
child: FlowyText.regular(
LocaleKeys.document_plugins_file_networkUrlInvalid.tr(),
- color: LinkStyle.textStatusError,
+ color: AppFlowyTheme.maybeOf(context)?.textColorScheme.error,
fontSize: 12,
figmaLineHeight: 16,
),
@@ -144,6 +145,7 @@ class _LinkReplaceMenuState extends State<LinkReplaceMenu> {
}
Widget buildReplaceButton() {
+ final fillTheme = AppFlowyTheme.maybeOf(context)?.fillColorScheme;
return FlowyTextButton(
LocaleKeys.button_replace.tr(),
padding: EdgeInsets.zero,
@@ -151,9 +153,9 @@ class _LinkReplaceMenuState extends State<LinkReplaceMenu> {
constraints: BoxConstraints(maxWidth: 78, minHeight: 32),
fontSize: 14,
lineHeight: 20 / 14,
- hoverColor: LinkStyle.fillThemeThick.withAlpha(200),
+ hoverColor: fillTheme?.themeThick.withAlpha(200),
fontColor: Colors.white,
- fillColor: LinkStyle.fillThemeThick,
+ fillColor: fillTheme?.themeThick,
fontWeight: FontWeight.w400,
onPressed: onSubmit,
);
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/desktop_toolbar/link/link_search_text_field.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/desktop_toolbar/link/link_search_text_field.dart
index 97fd6abdad..7f4f8843d7 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/desktop_toolbar/link/link_search_text_field.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/desktop_toolbar/link/link_search_text_field.dart
@@ -14,6 +14,7 @@ import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:appflowy_editor/src/flutter/scrollable_positioned_list/scrollable_positioned_list.dart';
// ignore: implementation_imports
import 'package:appflowy_editor/src/editor/util/link_util.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';
@@ -68,6 +69,7 @@ class LinkSearchTextField {
bool autofocus = false,
bool showError = false,
required BuildContext context,
+ EdgeInsets contentPadding = const EdgeInsets.fromLTRB(8, 6, 8, 6),
}) {
return TextFormField(
autovalidateMode: AutovalidateMode.onUserInteraction,
@@ -93,6 +95,7 @@ class LinkSearchTextField {
LocaleKeys.document_toolbar_linkInputHint.tr(),
context,
showErrorBorder: showError,
+ contentPadding: contentPadding,
),
);
}
@@ -138,7 +141,7 @@ class LinkSearchTextField {
padding: EdgeInsets.all(8),
child: FlowyText.semibold(
LocaleKeys.inlineActions_recentPages.tr(),
- color: LinkStyle.textTertiary,
+ color: AppFlowyTheme.of(context).textColorScheme.tertiary,
fontSize: 12,
figmaLineHeight: 16,
),
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/desktop_toolbar/link/link_styles.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/desktop_toolbar/link/link_styles.dart
index cabc00a312..dfd56af03b 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/desktop_toolbar/link/link_styles.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/desktop_toolbar/link/link_styles.dart
@@ -1,13 +1,8 @@
import 'package:appflowy/util/theme_extension.dart';
+import 'package:appflowy_ui/appflowy_ui.dart';
import 'package:flutter/material.dart';
class LinkStyle {
- static const textTertiary = Color(0xFF99A1A8);
- static const textStatusError = Color(0xffE71D32);
- static const fillThemeThick = Color(0xFF00B5FF);
- static const shadowMedium = Color(0x1F22251F);
- static const textPrimary = Color(0xFF1F2329);
-
static Color borderColor(BuildContext context) =>
Theme.of(context).isLightMode ? Color(0xFFE8ECF3) : Color(0x64BDBDBD);
@@ -15,7 +10,9 @@ class LinkStyle {
String hintText,
BuildContext context, {
bool showErrorBorder = false,
+ EdgeInsets? contentPadding,
}) {
+ final theme = AppFlowyTheme.of(context);
final border = OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(8.0)),
borderSide: BorderSide(color: borderColor(context)),
@@ -23,20 +20,20 @@ class LinkStyle {
final enableBorder = border.copyWith(
borderSide: BorderSide(
color: showErrorBorder
- ? LinkStyle.textStatusError
- : LinkStyle.fillThemeThick,
+ ? theme.textColorScheme.error
+ : theme.fillColorScheme.themeThick,
),
);
- const hintStyle = TextStyle(
+ final hintStyle = TextStyle(
fontSize: 14,
height: 20 / 14,
fontWeight: FontWeight.w400,
- color: LinkStyle.textTertiary,
+ color: theme.textColorScheme.tertiary,
);
return InputDecoration(
hintText: hintText,
hintStyle: hintStyle,
- contentPadding: const EdgeInsets.fromLTRB(8, 6, 8, 6),
+ contentPadding: contentPadding ?? const EdgeInsets.fromLTRB(8, 6, 8, 6),
isDense: true,
border: border,
enabledBorder: border,
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_item/utils.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_item/utils.dart
deleted file mode 100644
index ad4d523812..0000000000
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_item/utils.dart
+++ /dev/null
@@ -1,23 +0,0 @@
-import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet.dart';
-import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet_edit_link_widget.dart';
-import 'package:flutter/material.dart';
-
-Future<T?> showEditLinkBottomSheet<T>(
- BuildContext context,
- String text,
- String? href,
- void Function(BuildContext context, String text, String href) onEdit,
-) {
- return showMobileBottomSheet(
- context,
- showDragHandle: true,
- padding: const EdgeInsets.symmetric(horizontal: 16),
- builder: (context) {
- return MobileBottomSheetEditLinkWidget(
- text: text,
- href: href,
- onEdit: (text, href) => onEdit(context, text, href),
- );
- },
- );
-}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/aa_menu/_block_items.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/aa_menu/_block_items.dart
index 8e1a8533e0..d72aff821d 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/aa_menu/_block_items.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/aa_menu/_block_items.dart
@@ -1,17 +1,16 @@
import 'dart:async';
import 'package:appflowy/generated/flowy_svgs.g.dart';
-import 'package:appflowy/plugins/document/presentation/editor_plugins/mobile_toolbar_item/utils.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/aa_menu/_menu_item.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/aa_menu/_popup_menu.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/aa_menu/_toolbar_theme.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/link_toolbar_item.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';
import 'package:appflowy_editor/appflowy_editor.dart'
hide QuoteBlockKeys, quoteNode;
import 'package:collection/collection.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
import 'package:flutter/material.dart';
-import 'package:go_router/go_router.dart';
class BlockItems extends StatelessWidget {
BlockItems({
@@ -152,38 +151,7 @@ class BlockItems extends StatelessWidget {
),
);
keepEditorFocusNotifier.increase();
-
- final text = editorState
- .getTextInSelection(
- selection,
- )
- .join();
- final href = editorState.getDeltaAttributeValueInSelection<String>(
- AppFlowyRichTextKeys.href,
- selection,
- );
- await showEditLinkBottomSheet(
- context,
- text,
- href,
- (context, newText, newHref) {
- editorState.updateTextAndHref(
- text,
- href,
- newText,
- newHref,
- selection: selection,
- );
- context.pop(true);
- },
- );
- // re-open the keyboard again
- unawaited(
- editorState.updateSelectionWithReason(
- selection,
- extraInfo: {},
- ),
- );
+ await showEditLinkBottomSheet(context, selection, editorState);
}
}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/basic_toolbar_item.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/basic_toolbar_item.dart
index 518060ccf5..1fc83af267 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/basic_toolbar_item.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/basic_toolbar_item.dart
@@ -5,6 +5,8 @@ import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.da
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:flutter/widgets.dart';
+import 'link_toolbar_item.dart';
+
final boldToolbarItem = AppFlowyMobileToolbarItem(
itemBuilder: (context, editorState, _, __, onAction) {
return AppFlowyMobileToolbarIconItem(
@@ -157,3 +159,16 @@ final colorToolbarItem = AppFlowyMobileToolbarItem(
);
},
);
+
+final linkToolbarItem = AppFlowyMobileToolbarItem(
+ itemBuilder: (context, editorState, service, __, onAction) {
+ return AppFlowyMobileToolbarIconItem(
+ editorState: editorState,
+ shouldListenToToggledStyle: true,
+ icon: FlowySvgs.toolbar_link_m,
+ onTap: () {
+ onMobileLinkButtonTap(editorState);
+ },
+ );
+ },
+);
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/link_toolbar_item.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/link_toolbar_item.dart
new file mode 100644
index 0000000000..f6cc369fad
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/link_toolbar_item.dart
@@ -0,0 +1,71 @@
+import 'dart:async';
+
+import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet.dart';
+import 'package:appflowy/mobile/presentation/bottom_sheet/bottom_sheet_edit_link_widget.dart';
+import 'package:appflowy/plugins/document/application/document_bloc.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/desktop_toolbar/link/link_edit_menu.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/desktop_toolbar/link/link_extension.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/toolbar_item/custom_link_toolbar_item.dart';
+import 'package:appflowy_editor/appflowy_editor.dart';
+import 'package:flutter/widgets.dart';
+import 'package:flutter_bloc/flutter_bloc.dart';
+
+Future<void> onMobileLinkButtonTap(EditorState editorState) async {
+ final selection = editorState.selection;
+ if (selection == null) {
+ return;
+ }
+ final nodes = editorState.getNodesInSelection(selection);
+ // show edit link bottom sheet
+ final context = nodes.firstOrNull?.context;
+ if (context != null) {
+ // keep the selection
+ unawaited(
+ editorState.updateSelectionWithReason(
+ selection,
+ extraInfo: {
+ selectionExtraInfoDisableMobileToolbarKey: true,
+ selectionExtraInfoDoNotAttachTextService: true,
+ selectionExtraInfoDisableFloatingToolbar: true,
+ },
+ ),
+ );
+ keepEditorFocusNotifier.increase();
+ await showEditLinkBottomSheet(context, selection, editorState);
+ }
+}
+
+Future<T?> showEditLinkBottomSheet<T>(
+ BuildContext context,
+ Selection selection,
+ EditorState editorState,
+) async {
+ final currentViewId = context.read<DocumentBloc?>()?.documentId ?? '';
+ final text = editorState.getTextInSelection(selection).join();
+ final href = editorState.getDeltaAttributeValueInSelection<String>(
+ AppFlowyRichTextKeys.href,
+ selection,
+ );
+ final isPage = editorState.getDeltaAttributeValueInSelection<bool>(
+ kIsPageLink,
+ selection,
+ );
+ final linkInfo =
+ LinkInfo(name: text, link: href ?? '', isPage: isPage ?? false);
+ return showMobileBottomSheet(
+ context,
+ showDragHandle: true,
+ padding: const EdgeInsets.symmetric(horizontal: 16),
+ builder: (context) {
+ return MobileBottomSheetEditLinkWidget(
+ currentViewId: currentViewId,
+ linkInfo: linkInfo,
+ onApply: (info) => editorState.applyLink(selection, info),
+ onRemoveLink: (_) => editorState.removeLink(selection),
+ onDispose: () {
+ editorState.service.keyboardService?.closeKeyboard();
+ },
+ );
+ },
+ );
+}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/toolbar_item_builder.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/toolbar_item_builder.dart
index 35a3c37e74..aa11881bab 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/toolbar_item_builder.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/toolbar_item_builder.dart
@@ -69,7 +69,11 @@ List<AppFlowyMobileToolbarItem> buildMobileToolbarItems(
}
if (!selection.isCollapsed) {
- return _textToolbarItems;
+ final items = List.of(_textToolbarItems);
+ if (onlyShowInSingleSelectionAndTextType(editorState)) {
+ items.add(linkToolbarItem);
+ }
+ return items;
}
final allSelectedAreListType = editorState
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_style.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_style.dart
index cd9d7bb5e8..86bd641a10 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_style.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_style.dart
@@ -1,11 +1,9 @@
import 'dart:io';
-import 'package:appflowy/core/helpers/url_launcher.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/mobile/application/page_style/document_page_style_bloc.dart';
import 'package:appflowy/plugins/document/application/document_appearance_cubit.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/base/font_colors.dart';
-import 'package:appflowy/plugins/document/presentation/editor_plugins/mobile_toolbar_item/utils.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';
import 'package:appflowy/plugins/inline_actions/inline_actions_menu.dart';
import 'package:appflowy/shared/google_fonts_extension.dart';
@@ -21,10 +19,8 @@ import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra/theme_extension.dart';
import 'package:flowy_infra_ui/style_widget/hover.dart';
import 'package:flowy_infra_ui/widget/flowy_tooltip.dart';
-import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
-import 'package:go_router/go_router.dart';
import 'package:google_fonts/google_fonts.dart';
import 'package:universal_platform/universal_platform.dart';
@@ -188,6 +184,7 @@ class EditorStyleCustomizer {
textScaleFactor: textScaleFactor,
mobileDragHandleLeftExtend: 12.0,
mobileDragHandleWidthExtend: 24.0,
+ textSpanOverlayBuilder: _buildTextSpanOverlay,
);
}
@@ -426,44 +423,7 @@ class EditorStyleCustomizer {
// customize the link on mobile
final href = attributes[AppFlowyRichTextKeys.href] as String?;
if (UniversalPlatform.isMobile && href != null) {
- return TextSpan(
- style: before.style,
- text: text.text,
- recognizer: TapGestureRecognizer()
- ..onTap = () {
- final editorState = context.read<EditorState>();
- if (editorState.selection == null) {
- afLaunchUrlString(href, addingHttpSchemeWhenFailed: true);
- return;
- }
-
- editorState.updateSelectionWithReason(
- editorState.selection,
- extraInfo: {selectionExtraInfoDisableMobileToolbarKey: true},
- );
-
- showEditLinkBottomSheet(
- context,
- text.text,
- href,
- (linkContext, newText, newHref) {
- final selection = Selection.single(
- path: node.path,
- startOffset: index,
- endOffset: index + text.text.length,
- );
- editorState.updateTextAndHref(
- text.text,
- href,
- newText,
- newHref,
- selection: selection,
- );
- linkContext.pop();
- },
- );
- },
- );
+ return TextSpan(style: before.style, text: text.text);
}
if (suggestion != null) {
@@ -594,7 +554,6 @@ class EditorStyleCustomizer {
Node node,
SelectableMixin delegate,
) {
- if (UniversalPlatform.isMobile) return [];
final delta = node.delta;
if (delta == null) return [];
final widgets = <Widget>[];
diff --git a/frontend/resources/flowy_icons/20x/mobile_icon_remove_link.svg b/frontend/resources/flowy_icons/20x/mobile_icon_remove_link.svg
new file mode 100644
index 0000000000..e725708220
--- /dev/null
+++ b/frontend/resources/flowy_icons/20x/mobile_icon_remove_link.svg
@@ -0,0 +1,3 @@
+<svg width="21" height="20" viewBox="0 0 21 20" fill="none" xmlns="http://www.w3.org/2000/svg">
+<path d="M17.5 5.1845C14.91 4.92049 12.3044 4.78448 9.70667 4.78448C8.16667 4.78448 6.62667 4.86449 5.08667 5.02449L3.5 5.1845M7.77799 4.37609L7.9491 3.32805C8.07355 2.56802 8.16688 2 9.48133 2H11.5191C12.8335 2 12.9347 2.60002 13.0513 3.33605L13.2224 4.37609M15.8274 7.71143L15.3219 15.7677C15.2363 17.0238 15.1663 17.9998 12.9963 17.9998H8.003C5.833 17.9998 5.763 17.0238 5.67745 15.7677L5.17189 7.71143M9.20114 13.6001H11.7911M8.55555 10.4004H12.4444" stroke="#6F748C" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round"/>
+</svg>