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 creating subpage block in row detail page (#6824)

Lucasc24b68481d6f
diff --git a/frontend/appflowy_flutter/integration_test/desktop/database/database_row_page_test.dart b/frontend/appflowy_flutter/integration_test/desktop/database/database_row_page_test.dart
index 26688ac0cf..fec272768c 100644
--- a/frontend/appflowy_flutter/integration_test/desktop/database/database_row_page_test.dart
+++ b/frontend/appflowy_flutter/integration_test/desktop/database/database_row_page_test.dart
@@ -1,17 +1,17 @@
-import 'package:appflowy/plugins/database/widgets/cell/desktop_row_detail/desktop_row_detail_checklist_cell.dart';
-import 'package:appflowy/plugins/database/widgets/cell_editor/checklist_cell_editor.dart';
-import 'package:flowy_infra_ui/flowy_infra_ui.dart';
-import 'package:flutter/material.dart';
-
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/database/grid/presentation/widgets/header/desktop_field_cell.dart';
+import 'package:appflowy/plugins/database/widgets/cell/desktop_row_detail/desktop_row_detail_checklist_cell.dart';
+import 'package:appflowy/plugins/database/widgets/cell_editor/checklist_cell_editor.dart';
import 'package:appflowy/plugins/database/widgets/row/row_detail.dart';
+import 'package:appflowy/plugins/document/document_page.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/header/emoji_icon_widget.dart';
import 'package:appflowy/util/field_type_extension.dart';
import 'package:appflowy_backend/protobuf/flowy-database2/field_entities.pbenum.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:easy_localization/easy_localization.dart';
+import 'package:flowy_infra_ui/flowy_infra_ui.dart';
+import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
@@ -76,6 +76,24 @@ void main() {
// The number of emoji should be two. One in the row displayed in the grid
// one in the row detail page.
expect(emojiText, findsNWidgets(2));
+
+ // insert a sub page in database
+ await tester.editor.tapLineOfEditorAt(0);
+ await tester.editor.showSlashMenu();
+ await tester.pumpAndSettle();
+ await tester.editor.tapSlashMenuItemWithName(
+ LocaleKeys.document_slashMenu_subPage_name.tr(),
+ offset: 100,
+ );
+ await tester.pumpAndSettle();
+
+ // the row detail page should be closed
+ final rowDetailPage = find.byType(RowDetailPage);
+ await tester.pumpUntilNotFound(rowDetailPage);
+
+ // expect to see a document page
+ final documentPage = find.byType(DocumentPage);
+ expect(documentPage, findsOneWidget);
});
testWidgets('remove emoji', (tester) async {
diff --git a/frontend/appflowy_flutter/integration_test/desktop/document/document_sub_page_test.dart b/frontend/appflowy_flutter/integration_test/desktop/document/document_sub_page_test.dart
index efcb915468..e6bdf9e6b6 100644
--- a/frontend/appflowy_flutter/integration_test/desktop/document/document_sub_page_test.dart
+++ b/frontend/appflowy_flutter/integration_test/desktop/document/document_sub_page_test.dart
@@ -1,14 +1,13 @@
import 'dart:io';
-import 'package:appflowy/workspace/presentation/home/menu/view/view_action_type.dart';
-import 'package:flutter/material.dart';
-import 'package:flutter/services.dart';
-
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/sub_page/sub_page_block_component.dart';
+import 'package:appflowy/workspace/presentation/home/menu/view/view_action_type.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:easy_localization/easy_localization.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
diff --git a/frontend/appflowy_flutter/integration_test/desktop/document/document_with_outline_block_test.dart b/frontend/appflowy_flutter/integration_test/desktop/document/document_with_outline_block_test.dart
index 3053bd748a..2f3f8c80b9 100644
--- a/frontend/appflowy_flutter/integration_test/desktop/document/document_with_outline_block_test.dart
+++ b/frontend/appflowy_flutter/integration_test/desktop/document/document_with_outline_block_test.dart
@@ -1,6 +1,7 @@
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';
import 'package:easy_localization/easy_localization.dart';
+import 'package:flutter/services.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:integration_test/integration_test.dart';
@@ -43,6 +44,9 @@ void main() {
* # Heading 1
* ## Heading 2
* ### Heading 3
+ * > # Heading 1
+ * > ## Heading 2
+ * > ### Heading 3
*/
await tester.editor.tapLineOfEditorAt(3);
@@ -53,7 +57,7 @@ void main() {
of: find.byType(OutlineBlockWidget),
matching: find.text(heading1),
),
- findsOneWidget,
+ findsNWidgets(2),
);
// Heading 2 is prefixed with a bullet
@@ -62,7 +66,7 @@ void main() {
of: find.byType(OutlineBlockWidget),
matching: find.text(heading2),
),
- findsOneWidget,
+ findsNWidgets(2),
);
// Heading 3 is prefixed with a dash
@@ -71,7 +75,7 @@ void main() {
of: find.byType(OutlineBlockWidget),
matching: find.text(heading3),
),
- findsOneWidget,
+ findsNWidgets(2),
);
// update the Heading 1 to Heading 1Hello world
@@ -99,13 +103,16 @@ void main() {
* # Heading 1
* ## Heading 2
* ### Heading 3
+ * > # Heading 1
+ * > ## Heading 2
+ * > ### Heading 3
*/
- await tester.editor.tapLineOfEditorAt(3);
+ await tester.editor.tapLineOfEditorAt(7);
await insertOutlineInDocument(tester);
// expect to find only the `heading1` widget under the [OutlineBlockWidget]
- await hoverAndClickDepthOptionAction(tester, [3], 1);
+ await hoverAndClickDepthOptionAction(tester, [6], 1);
expect(
find.descendant(
of: find.byType(OutlineBlockWidget),
@@ -123,7 +130,7 @@ void main() {
//////
/// expect to find only the 'heading1' and 'heading2' under the [OutlineBlockWidget]
- await hoverAndClickDepthOptionAction(tester, [3], 2);
+ await hoverAndClickDepthOptionAction(tester, [6], 2);
expect(
find.descendant(
of: find.byType(OutlineBlockWidget),
@@ -134,13 +141,13 @@ void main() {
//////
// expect to find all the headings under the [OutlineBlockWidget]
- await hoverAndClickDepthOptionAction(tester, [3], 3);
+ await hoverAndClickDepthOptionAction(tester, [6], 3);
expect(
find.descendant(
of: find.byType(OutlineBlockWidget),
matching: find.text(heading1),
),
- findsOneWidget,
+ findsNWidgets(2),
);
expect(
@@ -148,7 +155,7 @@ void main() {
of: find.byType(OutlineBlockWidget),
matching: find.text(heading2),
),
- findsOneWidget,
+ findsNWidgets(2),
);
expect(
@@ -156,7 +163,7 @@ void main() {
of: find.byType(OutlineBlockWidget),
matching: find.text(heading3),
),
- findsOneWidget,
+ findsNWidgets(2),
);
//////
});
@@ -186,7 +193,17 @@ Future<void> hoverAndClickDepthOptionAction(
Future<void> insertHeadingComponent(WidgetTester tester) async {
await tester.editor.tapLineOfEditorAt(0);
+
+ // # heading 1-3
await tester.ime.insertText('# $heading1\n');
await tester.ime.insertText('## $heading2\n');
await tester.ime.insertText('### $heading3\n');
+
+ // > # toggle heading 1-3
+ await tester.ime.insertText('> # $heading1\n');
+ await tester.simulateKeyEvent(LogicalKeyboardKey.backspace);
+ await tester.ime.insertText('> ## $heading2\n');
+ await tester.simulateKeyEvent(LogicalKeyboardKey.backspace);
+ await tester.ime.insertText('> ### $heading3\n');
+ await tester.simulateKeyEvent(LogicalKeyboardKey.backspace);
}
diff --git a/frontend/appflowy_flutter/lib/plugins/database/widgets/row/row_document.dart b/frontend/appflowy_flutter/lib/plugins/database/widgets/row/row_document.dart
index 757ec3a37d..e3d30249ac 100644
--- a/frontend/appflowy_flutter/lib/plugins/database/widgets/row/row_document.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database/widgets/row/row_document.dart
@@ -1,18 +1,20 @@
-import 'package:appflowy/plugins/document/presentation/editor_drop_manager.dart';
-import 'package:flutter/material.dart';
-
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/database/grid/application/row/row_document_bloc.dart';
import 'package:appflowy/plugins/document/application/document_bloc.dart';
import 'package:appflowy/plugins/document/presentation/editor_drop_handler.dart';
+import 'package:appflowy/plugins/document/presentation/editor_drop_manager.dart';
import 'package:appflowy/plugins/document/presentation/editor_page.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/shared_context/shared_context.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/transaction_handler/editor_transaction_service.dart';
import 'package:appflowy/plugins/document/presentation/editor_style.dart';
import 'package:appflowy/shared/flowy_error_page.dart';
import 'package:appflowy/workspace/application/view_info/view_info_bloc.dart';
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:easy_localization/easy_localization.dart';
+import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
+import 'package:provider/provider.dart';
class RowDocument extends StatelessWidget {
const RowDocument({
@@ -103,23 +105,35 @@ class _RowEditor extends StatelessWidget {
child: IntrinsicHeight(
child: Container(
constraints: const BoxConstraints(minHeight: 300),
- child: EditorDropHandler(
- viewId: view.id,
- editorState: editorState,
- isLocalMode: context.read<DocumentBloc>().isLocalMode,
- dropManagerState: context.read<EditorDropManagerState>(),
- child: AppFlowyEditorPage(
- shrinkWrap: true,
- autoFocus: false,
+ child: Provider(
+ create: (_) {
+ final context = SharedEditorContext();
+ context.isInDatabaseRowPage = true;
+ return context;
+ },
+ dispose: (_, editorContext) => editorContext.dispose(),
+ child: EditorDropHandler(
+ viewId: view.id,
editorState: editorState,
- styleCustomizer: EditorStyleCustomizer(
- context: context,
- padding: const EdgeInsets.only(left: 16, right: 54),
+ isLocalMode: context.read<DocumentBloc>().isLocalMode,
+ dropManagerState: context.read<EditorDropManagerState>(),
+ child: EditorTransactionService(
+ viewId: view.id,
+ editorState: editorState,
+ child: AppFlowyEditorPage(
+ shrinkWrap: true,
+ autoFocus: false,
+ editorState: editorState,
+ styleCustomizer: EditorStyleCustomizer(
+ context: context,
+ padding: const EdgeInsets.only(left: 16, right: 54),
+ ),
+ showParagraphPlaceholder: (editorState, _) =>
+ editorState.document.isEmpty,
+ placeholderText: (_) =>
+ LocaleKeys.cardDetails_notesPlaceholder.tr(),
+ ),
),
- showParagraphPlaceholder: (editorState, _) =>
- editorState.document.isEmpty,
- placeholderText: (_) =>
- LocaleKeys.cardDetails_notesPlaceholder.tr(),
),
),
),
diff --git a/frontend/appflowy_flutter/lib/plugins/database_document/database_document_page.dart b/frontend/appflowy_flutter/lib/plugins/database_document/database_document_page.dart
index 2150fcc164..eaa82b22e9 100644
--- a/frontend/appflowy_flutter/lib/plugins/database_document/database_document_page.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database_document/database_document_page.dart
@@ -1,6 +1,3 @@
-import 'package:appflowy/plugins/document/presentation/editor_drop_handler.dart';
-import 'package:flutter/material.dart';
-
import 'package:appflowy/plugins/database/application/row/related_row_detail_bloc.dart';
import 'package:appflowy/plugins/database/grid/application/row/row_detail_bloc.dart';
import 'package:appflowy/plugins/database/grid/presentation/widgets/common/type_option_separator.dart';
@@ -9,8 +6,10 @@ import 'package:appflowy/plugins/database/widgets/row/row_banner.dart';
import 'package:appflowy/plugins/database/widgets/row/row_property.dart';
import 'package:appflowy/plugins/document/application/document_bloc.dart';
import 'package:appflowy/plugins/document/presentation/banner.dart';
+import 'package:appflowy/plugins/document/presentation/editor_drop_handler.dart';
import 'package:appflowy/plugins/document/presentation/editor_notification.dart';
import 'package:appflowy/plugins/document/presentation/editor_page.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/transaction_handler/editor_transaction_service.dart';
import 'package:appflowy/plugins/document/presentation/editor_style.dart';
import 'package:appflowy/shared/flowy_error_page.dart';
import 'package:appflowy/startup/startup.dart';
@@ -19,6 +18,7 @@ import 'package:appflowy/workspace/application/action_navigation/navigation_acti
import 'package:appflowy_backend/log.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/protobuf.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
+import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
// This widget is largely copied from `plugins/document/document_page.dart` intentionally instead of opting for an abstraction. We can make an abstraction after the view refactor is done and there's more clarity in that department.
@@ -122,11 +122,15 @@ class _DatabaseDocumentPageState extends State<DatabaseDocumentPage> {
),
);
- return Column(
- children: [
- if (state.isDeleted) _buildBanner(context),
- Expanded(child: appflowyEditorPage),
- ],
+ return EditorTransactionService(
+ viewId: widget.view.id,
+ editorState: state.editorState!,
+ child: Column(
+ children: [
+ if (state.isDeleted) _buildBanner(context),
+ Expanded(child: appflowyEditorPage),
+ ],
+ ),
);
}
diff --git a/frontend/appflowy_flutter/lib/plugins/database_document/presentation/database_document_title.dart b/frontend/appflowy_flutter/lib/plugins/database_document/presentation/database_document_title.dart
index 002596f0c9..d1a0640446 100644
--- a/frontend/appflowy_flutter/lib/plugins/database_document/presentation/database_document_title.dart
+++ b/frontend/appflowy_flutter/lib/plugins/database_document/presentation/database_document_title.dart
@@ -1,5 +1,3 @@
-import 'package:flutter/material.dart';
-
import 'package:appflowy/generated/flowy_svgs.g.dart';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/database/application/cell/bloc/text_cell_bloc.dart';
@@ -13,6 +11,7 @@ import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
import 'package:collection/collection.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
+import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'database_document_title_bloc.dart';
@@ -192,6 +191,8 @@ class _TitleSkin extends IEditableTextCellSkin {
child: FlowyText.regular(
name,
overflow: TextOverflow.ellipsis,
+ fontSize: 14.0,
+ figmaLineHeight: 18.0,
),
),
],
diff --git a/frontend/appflowy_flutter/lib/plugins/document/document_page.dart b/frontend/appflowy_flutter/lib/plugins/document/document_page.dart
index 5827506b17..80d9cff7a9 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/document_page.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/document_page.dart
@@ -164,9 +164,7 @@ class _DocumentPageState extends State<DocumentPage>
create: (_) {
final context = SharedEditorContext();
if (widget.view.name.isEmpty) {
- WidgetsBinding.instance.addPostFrameCallback((_) {
- context.coverTitleFocusNode.requestFocus();
- });
+ context.requestCoverTitleFocus = true;
}
return context;
},
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 bf4dcb97e0..fdee715c78 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dart
@@ -19,7 +19,6 @@ import 'package:appflowy/workspace/presentation/home/af_focus_manager.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:collection/collection.dart';
import 'package:flowy_infra/theme_extension.dart';
-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';
@@ -348,7 +347,10 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage>
// if the last one isn't a empty node, insert a new empty node.
await _focusOnLastEmptyParagraph();
},
- child: VSpace(UniversalPlatform.isDesktopOrWeb ? 200 : 400),
+ child: SizedBox(
+ width: double.infinity,
+ height: UniversalPlatform.isDesktopOrWeb ? 200 : 400,
+ ),
),
dropTargetStyle: AppFlowyDropTargetStyle(
color: Theme.of(context).colorScheme.primary.withOpacity(0.8),
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/drag_to_reorder/util.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/drag_to_reorder/util.dart
index 6cbf840efb..b157d640b9 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/drag_to_reorder/util.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/drag_to_reorder/util.dart
@@ -52,21 +52,10 @@ Future<void> dragToMoveNode(
Log.info('Moving node($node, ${node.path}) to path($newPath)');
- final newPathNode = editorState.getNodeAtPath(newPath);
- if (newPathNode == null) {
- // if the new path is not a valid path, it means the node is not in the editor.
- // we should perform insertion before deletion.
- final transaction = editorState.transaction;
- transaction.insertNode(newPath, node.copyWith());
- transaction.deleteNode(node);
- await editorState.apply(transaction);
- } else {
- // Perform the node move operation
- final transaction = editorState.transaction;
- transaction.deleteNode(node);
- transaction.insertNode(newPath, node.copyWith());
- await editorState.apply(transaction);
- }
+ final transaction = editorState.transaction;
+ transaction.insertNode(newPath, node.copyWith());
+ transaction.deleteNode(node);
+ await editorState.apply(transaction);
}
(VerticalPosition, HorizontalPosition, Rect)? getDragAreaPosition(
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/header/cover_title.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/header/cover_title.dart
index f48a1aeec2..7dd2de3b78 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/header/cover_title.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/header/cover_title.dart
@@ -12,6 +12,7 @@ import 'package:easy_localization/easy_localization.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';
class CoverTitle extends StatelessWidget {
const CoverTitle({
@@ -63,6 +64,8 @@ class _InnerCoverTitleState extends State<_InnerCoverTitle> {
..addListener(_onFocusChanged);
editorState.selectionNotifier.addListener(_onSelectionChanged);
+
+ _requestInitialFocus();
}
@override
@@ -75,14 +78,6 @@ class _InnerCoverTitleState extends State<_InnerCoverTitle> {
super.dispose();
}
- void _onSelectionChanged() {
- // if title is focused and the selection is not null, clear the selection
- if (editorState.selection != null && titleFocusNode.hasFocus) {
- Log.info('title is focused, clear the editor selection');
- editorState.selection = null;
- }
- }
-
@override
Widget build(BuildContext context) {
final fontStyle = Theme.of(context)
@@ -127,6 +122,36 @@ class _InnerCoverTitleState extends State<_InnerCoverTitle> {
);
}
+ void _requestInitialFocus() {
+ if (editorContext.requestCoverTitleFocus) {
+ void requestFocus() {
+ titleFocusNode.canRequestFocus = true;
+ titleFocusNode.requestFocus();
+ editorContext.requestCoverTitleFocus = false;
+ }
+
+ // on macOS, if we gain focus immediately, the focus won't work.
+ // It's a workaround to delay the focus request.
+ if (UniversalPlatform.isMacOS) {
+ Future.delayed(Durations.short4, () {
+ requestFocus();
+ });
+ } else {
+ WidgetsBinding.instance.addPostFrameCallback((_) {
+ requestFocus();
+ });
+ }
+ }
+ }
+
+ void _onSelectionChanged() {
+ // if title is focused and the selection is not null, clear the selection
+ if (editorState.selection != null && titleFocusNode.hasFocus) {
+ Log.info('title is focused, clear the editor selection');
+ editorState.selection = null;
+ }
+ }
+
void _onListen(BuildContext context, ViewState state) {
_requestFocusIfNeeded(widget.view, state);
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/appflowy_mobile_toolbar.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/appflowy_mobile_toolbar.dart
index 6d7d0860ef..cd806f6c56 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/appflowy_mobile_toolbar.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/appflowy_mobile_toolbar.dart
@@ -276,7 +276,9 @@ class _MobileToolbarState extends State<_MobileToolbar>
if (!closeKeyboardInitiative &&
cachedKeyboardHeight.value != 0 &&
height == 0) {
- widget.editorState.selection = null;
+ if (!widget.editorState.isDisposed) {
+ widget.editorState.selection = null;
+ }
}
// if the menu is shown and the height is not 0, we need to close the menu
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/outline/outline_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/outline/outline_block_component.dart
index ee4ba205f3..f5d1148692 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/outline/outline_block_component.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/outline/outline_block_component.dart
@@ -2,10 +2,10 @@ import 'dart:async';
import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/actions/mobile_block_action_buttons.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:easy_localization/easy_localization.dart' hide TextDirection;
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
-import 'package:flowy_infra_ui/style_widget/hover.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:universal_platform/universal_platform.dart';
@@ -18,15 +18,6 @@ class OutlineBlockKeys {
static const String depth = 'depth';
}
-// defining the callout block menu item for selection
-SelectionMenuItem outlineItem = SelectionMenuItem.node(
- getName: LocaleKeys.document_selectionMenu_outline.tr,
- iconData: Icons.list_alt,
- keywords: ['outline', 'table of contents'],
- nodeBuilder: (editorState, _) => outlineBlockNode(),
- replace: (_, node) => node.delta?.isEmpty ?? false,
-);
-
Node outlineBlockNode() {
return Node(
type: OutlineBlockKeys.type,
@@ -39,6 +30,11 @@ enum _OutlineBlockStatus {
success;
}
+final _availableBlockTypes = [
+ HeadingBlockKeys.type,
+ ToggleListBlockKeys.type,
+];
+
class OutlineBlockComponentBuilder extends BlockComponentBuilder {
OutlineBlockComponentBuilder({
super.configuration,
@@ -203,22 +199,43 @@ class _OutlineBlockWidgetState extends State<OutlineBlockWidget>
}
(_OutlineBlockStatus, Iterable<Node>) getHeadingNodes() {
- final children = editorState.document.root.children;
- final int level =
- node.attributes[OutlineBlockKeys.depth] ?? maxVisibleDepth;
- var headings = children.where(
- (e) => e.type == HeadingBlockKeys.type && e.delta?.isNotEmpty == true,
+ final nodes = NodeIterator(
+ document: editorState.document,
+ startNode: editorState.document.root,
+ ).toList();
+ final level = node.attributes[OutlineBlockKeys.depth] ?? maxVisibleDepth;
+ var headings = nodes.where(
+ (e) => _isHeadingNode(e),
);
if (headings.isEmpty) {
return (_OutlineBlockStatus.noHeadings, []);
}
- headings =
- headings.where((e) => e.attributes[HeadingBlockKeys.level] <= level);
+ headings = headings.where(
+ (e) =>
+ (e.type == HeadingBlockKeys.type &&
+ e.attributes[HeadingBlockKeys.level] <= level) ||
+ (e.type == ToggleListBlockKeys.type &&
+ e.attributes[ToggleListBlockKeys.level] <= level),
+ );
if (headings.isEmpty) {
return (_OutlineBlockStatus.noMatchHeadings, []);
}
return (_OutlineBlockStatus.success, headings);
}
+
+ bool _isHeadingNode(Node node) {
+ if (node.type == HeadingBlockKeys.type && node.delta?.isNotEmpty == true) {
+ return true;
+ }
+
+ if (node.type == ToggleListBlockKeys.type &&
+ node.delta?.isNotEmpty == true &&
+ node.attributes[ToggleListBlockKeys.level] != null) {
+ return true;
+ }
+
+ return false;
+ }
}
class OutlineItemWidget extends StatelessWidget {
@@ -227,7 +244,7 @@ class OutlineItemWidget extends StatelessWidget {
required this.node,
required this.textDirection,
}) {
- assert(node.type == HeadingBlockKeys.type);
+ assert(_availableBlockTypes.contains(node.type));
}
final Node node;
@@ -238,31 +255,19 @@ class OutlineItemWidget extends StatelessWidget {
final editorState = context.read<EditorState>();
final textStyle = editorState.editorStyle.textStyleConfiguration;
final style = textStyle.href.combine(textStyle.text);
- return FlowyHover(
- style: HoverStyle(
- hoverColor: Theme.of(context).hoverColor,
- ),
- builder: (context, onHover) {
- return GestureDetector(
- behavior: HitTestBehavior.translucent,
- onTap: () => scrollToBlock(context),
- child: Row(
+ return FlowyButton(
+ onTap: () => scrollToBlock(context),
+ text: Row(
+ textDirection: textDirection,
+ children: [
+ HSpace(node.leftIndent),
+ Text(
+ node.outlineItemText,
textDirection: textDirection,
- children: [
- HSpace(node.leftIndent),
- Text(
- node.outlineItemText,
- textDirection: textDirection,
- style: style.copyWith(
- color: onHover
- ? Theme.of(context).colorScheme.onSecondary
- : null,
- ),
- ),
- ],
+ style: style,
),
- );
- },
+ ],
+ ),
);
}
@@ -281,13 +286,20 @@ class OutlineItemWidget extends StatelessWidget {
extension on Node {
double get leftIndent {
- assert(type == HeadingBlockKeys.type);
- if (type != HeadingBlockKeys.type) {
+ assert(_availableBlockTypes.contains(type));
+
+ if (!_availableBlockTypes.contains(type)) {
return 0.0;
}
- final level = attributes[HeadingBlockKeys.level];
- final indent = (level - 1) * 15.0 + 10.0;
- return indent;
+
+ final level = attributes[HeadingBlockKeys.level] ??
+ attributes[ToggleListBlockKeys.level];
+ if (level != null) {
+ final indent = (level - 1) * 15.0;
+ return indent;
+ }
+
+ return 0.0;
}
String get outlineItemText {
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/shared_context/shared_context.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/shared_context/shared_context.dart
index 0d344347ba..40d4c54163 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/shared_context/shared_context.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/shared_context/shared_context.dart
@@ -11,6 +11,10 @@ class SharedEditorContext {
// The focus node of the cover title.
final FocusNode _coverTitleFocusNode;
+ bool requestCoverTitleFocus = false;
+
+ bool isInDatabaseRowPage = false;
+
FocusNode get coverTitleFocusNode => _coverTitleFocusNode;
void dispose() {
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items.dart
index 1358c08abf..fdebfddfc7 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items.dart
@@ -7,6 +7,7 @@ import 'package:appflowy/plugins/document/presentation/editor_plugins/base/selec
import 'package:appflowy/plugins/document/presentation/editor_plugins/image/image_placeholder.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/mention/slash_menu_items.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/shared_context/shared_context.dart';
import 'package:appflowy/workspace/application/view/view_service.dart';
import 'package:appflowy/workspace/presentation/settings/widgets/emoji_picker/emoji_menu_item.dart';
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
@@ -15,6 +16,7 @@ import 'package:appflowy_editor_plugins/appflowy_editor_plugins.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/style_widget/text.dart';
import 'package:flutter/material.dart';
+import 'package:flutter_bloc/flutter_bloc.dart';
// text menu item
final textSlashMenuItem = SelectionMenuItem(
@@ -409,19 +411,60 @@ SelectionMenuItem calloutSlashMenuItem = SelectionMenuItem.node(
);
// outline menu item
-SelectionMenuItem outlineSlashMenuItem = SelectionMenuItem.node(
- getName: () => LocaleKeys.document_slashMenu_name_outline.tr(),
- nameBuilder: _slashMenuItemNameBuilder,
- iconBuilder: (editorState, isSelected, style) => SelectableSvgWidget(
- data: FlowySvgs.slash_menu_icon_outline_s,
- isSelected: isSelected,
- style: style,
- ),
+SelectionMenuItem outlineSlashMenuItem = SelectionMenuItem(
+ getName: LocaleKeys.document_selectionMenu_outline.tr,
+ icon: (editorState, onSelected, style) {
+ return Icon(
+ Icons.list_alt,
+ color: onSelected
+ ? style.selectionMenuItemSelectedIconColor
+ : style.selectionMenuItemIconColor,
+ size: 18.0,
+ );
+ },
keywords: ['outline', 'table of contents'],
- nodeBuilder: (editorState, _) => outlineBlockNode(),
- replace: (_, node) => node.delta?.isEmpty ?? false,
-);
+ handler: (editorState, menuService, context) {
+ final selection = editorState.selection;
+ if (selection == null || !selection.isCollapsed) {
+ return;
+ }
+
+ final node = editorState.getNodeAtPath(selection.end.path);
+ final delta = node?.delta;
+ if (node == null || delta == null) {
+ return;
+ }
+ final transaction = editorState.transaction;
+ final bReplace = node.delta?.isEmpty ?? false;
+
+ //default insert after
+ var path = node.path.next;
+ if (bReplace) {
+ path = node.path;
+ }
+
+ final nextNode = editorState.getNodeAtPath(path.next);
+
+ transaction
+ ..insertNodes(
+ path,
+ [
+ outlineBlockNode(),
+ if (nextNode == null || nextNode.delta == null) paragraphNode(),
+ ],
+ )
+ ..afterSelection = Selection.collapsed(
+ Position(path: path.next),
+ );
+
+ if (bReplace) {
+ transaction.deleteNode(node);
+ }
+
+ editorState.apply(transaction);
+ },
+);
// math equation
SelectionMenuItem mathEquationSlashMenuItem = SelectionMenuItem.node(
getName: () => LocaleKeys.document_slashMenu_name_mathEquation.tr(),
@@ -642,8 +685,17 @@ SelectionMenuItem subPageSlashMenuItem = SelectionMenuItem.node(
LocaleKeys.document_slashMenu_subPage_keyword7.tr(),
LocaleKeys.document_slashMenu_subPage_keyword8.tr(),
],
- updateSelection: (_, path, __, ___) =>
- Selection.collapsed(Position(path: path)),
+ updateSelection: (editorState, path, __, ___) {
+ final context = editorState.document.root.context;
+ if (context != null) {
+ final isInDatabase =
+ context.read<SharedEditorContext>().isInDatabaseRowPage;
+ if (isInDatabase) {
+ Navigator.of(context).pop();
+ }
+ }
+ return Selection.collapsed(Position(path: path));
+ },
replace: (_, node) => node.delta?.isEmpty ?? false,
nodeBuilder: (_, __) => subPageNode(),
);
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/sub_page/sub_page_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/sub_page/sub_page_block_component.dart
index 76645f6d66..4b8550570a 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/sub_page/sub_page_block_component.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/sub_page/sub_page_block_component.dart
@@ -1,5 +1,7 @@
import 'package:appflowy/generated/locale_keys.g.dart';
+import 'package:appflowy/mobile/application/mobile_router.dart';
import 'package:appflowy/plugins/document/presentation/editor_plugins/mention/mention_page_block.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/shared_context/shared_context.dart';
import 'package:appflowy/plugins/trash/application/trash_listener.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:appflowy/workspace/application/tabs/tabs_bloc.dart';
@@ -18,6 +20,7 @@ import 'package:flowy_infra_ui/style_widget/text.dart';
import 'package:flowy_infra_ui/widget/spacing.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
+import 'package:universal_platform/universal_platform.dart';
Node subPageNode({String? viewId}) {
return Node(
@@ -224,14 +227,8 @@ class SubPageBlockComponentState extends State<SubPageBlockComponent>
],
child: GestureDetector(
// TODO(Mathias): Handle mobile tap
- onTap: isHandlingPaste
- ? null
- : () => getIt<TabsBloc>().add(
- TabsEvent.openPlugin(
- plugin: view.plugin(),
- view: view,
- ),
- ),
+ onTap:
+ isHandlingPaste ? null : () => _openSubPage(view: view),
child: DecoratedBox(
decoration: BoxDecoration(
color: isHovering
@@ -389,4 +386,25 @@ class SubPageBlockComponentState extends State<SubPageBlockComponent>
@override
Offset localToGlobal(Offset offset, {bool shiftWithBaseOffset = false}) =>
_renderBox!.localToGlobal(offset);
+
+ void _openSubPage({
+ required ViewPB view,
+ }) {
+ if (UniversalPlatform.isDesktop) {
+ final isInDatabase =
+ context.read<SharedEditorContext>().isInDatabaseRowPage;
+ if (isInDatabase) {
+ Navigator.of(context).pop();
+ }
+
+ getIt<TabsBloc>().add(
+ TabsEvent.openPlugin(
+ plugin: view.plugin(),
+ view: view,
+ ),
+ );
+ } else if (UniversalPlatform.isMobile) {
+ context.pushView(view);
+ }
+ }
}