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: refactor slash menu items to support showing in table cell (#7038)

Lucas07c4389f6a11
diff --git a/frontend/appflowy_flutter/integration_test/desktop/document/document_with_simple_table_test.dart b/frontend/appflowy_flutter/integration_test/desktop/document/document_with_simple_table_test.dart
index 23bba09b5b..bcf3fde24f 100644
--- a/frontend/appflowy_flutter/integration_test/desktop/document/document_with_simple_table_test.dart
+++ b/frontend/appflowy_flutter/integration_test/desktop/document/document_with_simple_table_test.dart
@@ -627,6 +627,103 @@ void main() {
final afterAlign3 = editorState.document.nodeAtPath([0])!.tableAlign;
expect(afterAlign3, TableAlign.left);
});
+
+ testWidgets('using option menu to set table align', (tester) async {
+ await tester.initializeAppFlowy();
+ await tester.tapAnonymousSignInButton();
+ await tester.createNewPageWithNameUnderParent(
+ name: 'simple_table_test',
+ );
+
+ await tester.editor.tapLineOfEditorAt(0);
+ await tester.insertTableInDocument();
+ await tester.editor.hoverAndClickOptionMenuButton([0]);
+
+ final editorState = tester.editor.getCurrentEditorState();
+ final beforeAlign = editorState.document.nodeAtPath([0])!.tableAlign;
+ expect(beforeAlign, TableAlign.left);
+
+ await tester.tapButton(
+ find.text(
+ LocaleKeys.document_plugins_simpleTable_moreActions_align.tr(),
+ ),
+ );
+ await tester.pumpAndSettle();
+ await tester.tapButton(
+ find.text(
+ LocaleKeys.document_plugins_optionAction_center.tr(),
+ ),
+ );
+ await tester.pumpAndSettle();
+
+ final afterAlign = editorState.document.nodeAtPath([0])!.tableAlign;
+ expect(afterAlign, TableAlign.center);
+
+ await tester.editor.hoverAndClickOptionMenuButton([0]);
+ await tester.tapButton(
+ find.text(
+ LocaleKeys.document_plugins_simpleTable_moreActions_align.tr(),
+ ),
+ );
+ await tester.pumpAndSettle();
+ await tester.tapButton(
+ find.text(
+ LocaleKeys.document_plugins_optionAction_right.tr(),
+ ),
+ );
+ await tester.pumpAndSettle();
+
+ final afterAlign2 = editorState.document.nodeAtPath([0])!.tableAlign;
+ expect(afterAlign2, TableAlign.right);
+
+ await tester.editor.hoverAndClickOptionMenuButton([0]);
+ await tester.tapButton(
+ find.text(
+ LocaleKeys.document_plugins_simpleTable_moreActions_align.tr(),
+ ),
+ );
+ await tester.pumpAndSettle();
+ await tester.tapButton(
+ find.text(
+ LocaleKeys.document_plugins_optionAction_left.tr(),
+ ),
+ );
+ await tester.pumpAndSettle();
+
+ final afterAlign3 = editorState.document.nodeAtPath([0])!.tableAlign;
+ expect(afterAlign3, TableAlign.left);
+ });
+
+ testWidgets('support slash menu in table', (tester) async {
+ await tester.initializeAppFlowy();
+ await tester.tapAnonymousSignInButton();
+ await tester.createNewPageWithNameUnderParent(
+ name: 'simple_table_test',
+ );
+
+ final editorState = tester.editor.getCurrentEditorState();
+
+ await tester.editor.tapLineOfEditorAt(0);
+ await tester.insertTableInDocument();
+
+ final path = [0, 0, 0, 0];
+ final selection = Selection.collapsed(Position(path: path));
+ editorState.selection = selection;
+ await tester.editor.showSlashMenu();
+ await tester.pumpAndSettle();
+
+ final paragraphItem = find.byWidgetPredicate((w) {
+ return w is SelectionMenuItemWidget &&
+ w.item.name == LocaleKeys.document_slashMenu_name_text.tr();
+ });
+ expect(paragraphItem, findsOneWidget);
+
+ await tester.tap(paragraphItem);
+ await tester.pumpAndSettle();
+
+ final paragraphNode = editorState.document.nodeAtPath(path)!;
+ expect(paragraphNode.type, equals(ParagraphBlockKeys.type));
+ });
}
extension on WidgetTester {
diff --git a/frontend/appflowy_flutter/integration_test/mobile/document/simple_table_test.dart b/frontend/appflowy_flutter/integration_test/mobile/document/simple_table_test.dart
index c7a244fec3..92f825f612 100644
--- a/frontend/appflowy_flutter/integration_test/mobile/document/simple_table_test.dart
+++ b/frontend/appflowy_flutter/integration_test/mobile/document/simple_table_test.dart
@@ -354,16 +354,7 @@ void main() {
// check the first cell is bold
final paragraph = editorState.getNodeAtPath(firstParagraphPath)!;
- expect(paragraph.delta!, isNotEmpty);
- expect(
- paragraph.delta!.toJson(),
- equals([
- {
- 'insert': 'Hello',
- 'attributes': {'bold': true},
- }
- ]),
- );
+ expect(paragraph.isInBoldColumn, isTrue);
}
// clear content
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 3675fe1a94..77a0531180 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_configuration.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_configuration.dart
@@ -28,9 +28,9 @@ final Set<String> supportSlashMenuNodeTypes = {
ToggleListBlockKeys.type,
// Simple table
- // SimpleTableBlockKeys.type,
- // SimpleTableRowBlockKeys.type,
- // SimpleTableCellBlockKeys.type,
+ SimpleTableBlockKeys.type,
+ SimpleTableRowBlockKeys.type,
+ SimpleTableCellBlockKeys.type,
};
/// Build the block component builders.
@@ -47,7 +47,7 @@ Map<String, BlockComponentBuilder> buildBlockComponentBuilders({
required BuildContext context,
required EditorState editorState,
required EditorStyleCustomizer styleCustomizer,
- List<SelectionMenuItem>? slashMenuItems,
+ SlashMenuItemsBuilder? slashMenuItemsBuilder,
bool editable = true,
ShowPlaceholder? showParagraphPlaceholder,
String Function(Node)? placeholderText,
@@ -70,7 +70,7 @@ Map<String, BlockComponentBuilder> buildBlockComponentBuilders({
builders: builders,
editorState: editorState,
styleCustomizer: styleCustomizer,
- slashMenuItems: slashMenuItems,
+ slashMenuItemsBuilder: slashMenuItemsBuilder,
);
}
@@ -154,7 +154,7 @@ void _customBlockOptionActions(
required Map<String, BlockComponentBuilder> builders,
required EditorState editorState,
required EditorStyleCustomizer styleCustomizer,
- List<SelectionMenuItem>? slashMenuItems,
+ SlashMenuItemsBuilder? slashMenuItemsBuilder,
}) {
for (final entry in builders.entries) {
if (entry.key == PageBlockKeys.type) {
@@ -166,6 +166,7 @@ void _customBlockOptionActions(
if (UniversalPlatform.isDesktop) {
builder.showActions = (node) {
final parentTableNode = node.parentTableNode;
+ // disable the option action button in table cell to avoid the misalignment issue
if (node.type != SimpleTableBlockKeys.type && parentTableNode != null) {
return false;
}
@@ -200,9 +201,9 @@ void _customBlockOptionActions(
editorState: editorState,
blockComponentBuilder: builders,
actions: actions,
- showSlashMenu: slashMenuItems != null
- ? () => customSlashCommand(
- slashMenuItems,
+ showSlashMenu: slashMenuItemsBuilder != null
+ ? () => customAppFlowySlashCommand(
+ itemsBuilder: slashMenuItemsBuilder,
shouldInsertSlash: false,
deleteKeywordsByDefault: true,
style: styleCustomizer.selectionMenuStyleBuilder(),
@@ -331,6 +332,7 @@ Map<String, BlockComponentBuilder> _buildBlockComponentBuilderMap(
SubPageBlockKeys.type: _buildSubPageBlockComponentBuilder(
context,
configuration,
+ styleCustomizer: styleCustomizer,
),
errorBlockComponentBuilderKey: ErrorBlockComponentBuilder(
configuration: configuration,
@@ -402,6 +404,11 @@ ParagraphBlockComponentBuilder _buildParagraphBlockComponentBuilder(
node: node,
configuration: configuration,
),
+ textAlign: (node) => _buildTextAlignInTableCell(
+ context,
+ node: node,
+ configuration: configuration,
+ ),
),
showPlaceholder: showParagraphPlaceholder,
);
@@ -414,14 +421,16 @@ TodoListBlockComponentBuilder _buildTodoListBlockComponentBuilder(
return TodoListBlockComponentBuilder(
configuration: configuration.copyWith(
placeholderText: (_) => LocaleKeys.blockPlaceholders_todoList.tr(),
- textStyle: (node) {
- if (node.isInHeaderColumn || node.isInHeaderRow) {
- return configuration.textStyle(node).copyWith(
- fontWeight: FontWeight.bold,
- );
- }
- return configuration.textStyle(node);
- },
+ textStyle: (node) => _buildTextStyleInTableCell(
+ context,
+ node: node,
+ configuration: configuration,
+ ),
+ textAlign: (node) => _buildTextAlignInTableCell(
+ context,
+ node: node,
+ configuration: configuration,
+ ),
),
iconBuilder: (_, node, onCheck) => TodoListIcon(
node: node,
@@ -442,14 +451,16 @@ BulletedListBlockComponentBuilder _buildBulletedListBlockComponentBuilder(
return BulletedListBlockComponentBuilder(
configuration: configuration.copyWith(
placeholderText: (_) => LocaleKeys.blockPlaceholders_bulletList.tr(),
- textStyle: (node) {
- if (node.isInHeaderColumn || node.isInHeaderRow) {
- return configuration.textStyle(node).copyWith(
- fontWeight: FontWeight.bold,
- );
- }
- return configuration.textStyle(node);
- },
+ textStyle: (node) => _buildTextStyleInTableCell(
+ context,
+ node: node,
+ configuration: configuration,
+ ),
+ textAlign: (node) => _buildTextAlignInTableCell(
+ context,
+ node: node,
+ configuration: configuration,
+ ),
),
iconBuilder: (_, node) => BulletedListIcon(node: node),
);
@@ -462,14 +473,16 @@ NumberedListBlockComponentBuilder _buildNumberedListBlockComponentBuilder(
return NumberedListBlockComponentBuilder(
configuration: configuration.copyWith(
placeholderText: (_) => LocaleKeys.blockPlaceholders_numberList.tr(),
- textStyle: (node) {
- if (node.isInHeaderColumn || node.isInHeaderRow) {
- return configuration.textStyle(node).copyWith(
- fontWeight: FontWeight.bold,
- );
- }
- return configuration.textStyle(node);
- },
+ textStyle: (node) => _buildTextStyleInTableCell(
+ context,
+ node: node,
+ configuration: configuration,
+ ),
+ textAlign: (node) => _buildTextAlignInTableCell(
+ context,
+ node: node,
+ configuration: configuration,
+ ),
),
iconBuilder: (_, node, textDirection) {
TextStyle? textStyle;
@@ -494,14 +507,16 @@ QuoteBlockComponentBuilder _buildQuoteBlockComponentBuilder(
return QuoteBlockComponentBuilder(
configuration: configuration.copyWith(
placeholderText: (_) => LocaleKeys.blockPlaceholders_quote.tr(),
- textStyle: (node) {
- if (node.isInHeaderColumn || node.isInHeaderRow) {
- return configuration.textStyle(node).copyWith(
- fontWeight: FontWeight.bold,
- );
- }
- return configuration.textStyle(node);
- },
+ textStyle: (node) => _buildTextStyleInTableCell(
+ context,
+ node: node,
+ configuration: configuration,
+ ),
+ textAlign: (node) => _buildTextAlignInTableCell(
+ context,
+ node: node,
+ configuration: configuration,
+ ),
),
);
}
@@ -546,6 +561,11 @@ HeadingBlockComponentBuilder _buildHeadingBlockComponentBuilder(
args: [level.toString()],
);
},
+ textAlign: (node) => _buildTextAlignInTableCell(
+ context,
+ node: node,
+ configuration: configuration,
+ ),
),
textStyleBuilder: (level) => styleCustomizer.headingStyleBuilder(level),
);
@@ -656,6 +676,16 @@ CalloutBlockComponentBuilder _buildCalloutBlockComponentBuilder(
return CalloutBlockComponentBuilder(
configuration: configuration.copyWith(
padding: (node) => const EdgeInsets.symmetric(vertical: 10),
+ textAlign: (node) => _buildTextAlignInTableCell(
+ context,
+ node: node,
+ configuration: configuration,
+ ),
+ textStyle: (node) => _buildTextStyleInTableCell(
+ context,
+ node: node,
+ configuration: configuration,
+ ),
),
inlinePadding: const EdgeInsets.symmetric(vertical: 8.0),
defaultColor: calloutBGColor,
@@ -741,12 +771,22 @@ ToggleListBlockComponentBuilder _buildToggleListBlockComponentBuilder(
return const EdgeInsets.only(top: 12.0, bottom: 4.0);
},
textStyle: (node) {
+ final textStyle = _buildTextStyleInTableCell(
+ context,
+ node: node,
+ configuration: configuration,
+ );
final level = node.attributes[ToggleListBlockKeys.level] as int?;
if (level == null) {
- return configuration.textStyle(node);
+ return textStyle;
}
- return styleCustomizer.headingStyleBuilder(level);
+ return textStyle.merge(styleCustomizer.headingStyleBuilder(level));
},
+ textAlign: (node) => _buildTextAlignInTableCell(
+ context,
+ node: node,
+ configuration: configuration,
+ ),
placeholderText: (node) {
int? level = node.attributes[ToggleListBlockKeys.level];
if (level == null) {
@@ -811,9 +851,14 @@ FileBlockComponentBuilder _buildFileBlockComponentBuilder(
SubPageBlockComponentBuilder _buildSubPageBlockComponentBuilder(
BuildContext context,
- BlockComponentConfiguration configuration,
-) {
- return SubPageBlockComponentBuilder(configuration: configuration);
+ BlockComponentConfiguration configuration, {
+ required EditorStyleCustomizer styleCustomizer,
+}) {
+ return SubPageBlockComponentBuilder(
+ configuration: configuration.copyWith(
+ textStyle: (node) => styleCustomizer.subPageBlockTextStyleBuilder(),
+ ),
+ );
}
TextStyle _buildTextStyleInTableCell(
@@ -846,3 +891,16 @@ TextStyle _buildTextStyleInTableCell(
return textStyle;
}
+
+TextAlign _buildTextAlignInTableCell(
+ BuildContext context, {
+ required Node node,
+ required BlockComponentConfiguration configuration,
+}) {
+ final isInTable = node.isInTable;
+ if (!isInTable) {
+ return configuration.textAlign(node);
+ }
+
+ return node.tableAlign.textAlign;
+}
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 d38b4e8c2c..0cf39e8bcc 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dart
@@ -97,15 +97,16 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage>
customizeFontToolbarItem..isActive = showInAnyTextType,
];
- late List<SelectionMenuItem> slashMenuItems;
-
List<CharacterShortcutEvent> get characterShortcutEvents {
return buildCharacterShortcutEvents(
context,
documentBloc,
styleCustomizer,
inlineActionsService,
- slashMenuItems,
+ (editorState, node) => _customSlashMenuItems(
+ editorState: editorState,
+ node: node,
+ ),
);
}
@@ -119,7 +120,7 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage>
final editorKeyboardInterceptor = EditorKeyboardInterceptor();
Future<bool> showSlashMenu(editorState) async => customSlashCommand(
- slashMenuItems,
+ _customSlashMenuItems(),
shouldInsertSlash: false,
style: styleCustomizer.selectionMenuStyleBuilder(),
supportSlashMenuNodeTypes: supportSlashMenuNodeTypes,
@@ -151,7 +152,7 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage>
indentableBlockTypes.add(ToggleListBlockKeys.type);
convertibleBlockTypes.add(ToggleListBlockKeys.type);
- slashMenuItems = _customSlashMenuItems();
+
effectiveScrollController = widget.scrollController ?? ScrollController();
// disable the color parse in the HTML decoder.
DocumentHTMLDecoder.enableColorParse = false;
@@ -275,12 +276,6 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage>
super.didChangeDependencies();
}
- @override
- void reassemble() {
- super.reassemble();
- slashMenuItems = _customSlashMenuItems();
- }
-
@override
void dispose() {
widget.editorState.selectionNotifier.removeListener(onSelectionChanged);
@@ -332,7 +327,10 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage>
editorStyle: styleCustomizer.style(),
// customize the block builders
blockComponentBuilders: buildBlockComponentBuilders(
- slashMenuItems: slashMenuItems,
+ slashMenuItemsBuilder: (editorState, node) => _customSlashMenuItems(
+ editorState: editorState,
+ node: node,
+ ),
context: context,
editorState: widget.editorState,
styleCustomizer: widget.styleCustomizer,
@@ -408,42 +406,18 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage>
);
}
- List<SelectionMenuItem> _customSlashMenuItems() {
- final isLocalMode = context.read<DocumentBloc>().isLocalMode;
- return [
- if (!isLocalMode) aiWriterSlashMenuItem,
- textSlashMenuItem,
- heading1SlashMenuItem,
- heading2SlashMenuItem,
- heading3SlashMenuItem,
- imageSlashMenuItem,
- bulletedListSlashMenuItem,
- numberedListSlashMenuItem,
- todoListSlashMenuItem,
- dividerSlashMenuItem,
- quoteSlashMenuItem,
- tableSlashMenuItem,
- referencedDocSlashMenuItem,
- gridSlashMenuItem(documentBloc),
- referencedGridSlashMenuItem,
- kanbanSlashMenuItem(documentBloc),
- referencedKanbanSlashMenuItem,
- calendarSlashMenuItem(documentBloc),
- referencedCalendarSlashMenuItem,
- calloutSlashMenuItem,
- outlineSlashMenuItem,
- mathEquationSlashMenuItem,
- codeBlockSlashMenuItem,
- toggleListSlashMenuItem,
- toggleHeading1SlashMenuItem,
- toggleHeading2SlashMenuItem,
- toggleHeading3SlashMenuItem,
- emojiSlashMenuItem,
- dateOrReminderSlashMenuItem,
- photoGallerySlashMenuItem,
- fileSlashMenuItem,
- subPageSlashMenuItem,
- ];
+ List<SelectionMenuItem> _customSlashMenuItems({
+ EditorState? editorState,
+ Node? node,
+ }) {
+ final documentBloc = context.read<DocumentBloc>();
+ final isLocalMode = documentBloc.isLocalMode;
+ return slashMenuItemsBuilder(
+ editorState: editorState,
+ node: node,
+ isLocalMode: isLocalMode,
+ documentBloc: documentBloc,
+ );
}
(bool, Selection?) _computeAutoFocusParameters() {
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/callout/callout_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/callout/callout_block_component.dart
index f4bd5cb21f..20cf6b5902 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/callout/callout_block_component.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/callout/callout_block_component.dart
@@ -256,6 +256,7 @@ class _CalloutBlockComponentWidgetState
node: widget.node,
editorState: editorState,
placeholderText: placeholderText,
+ textAlign: alignment?.toTextAlign ?? textAlign,
textSpanDecorator: (textSpan) => textSpan.updateTextStyle(
textStyle,
),
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/file/file_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/file/file_block_component.dart
index f1ffbe9d11..41a1e6624c 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/file/file_block_component.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/file/file_block_component.dart
@@ -160,7 +160,7 @@ class FileBlockComponentState extends State<FileBlockComponent>
late EditorDropManagerState? dropManagerState = UniversalPlatform.isMobile
? null
- : context.read<EditorDropManagerState>();
+ : context.read<EditorDropManagerState?>();
final fileKey = GlobalKey();
final showActionsNotifier = ValueNotifier<bool>(false);
@@ -176,7 +176,7 @@ class FileBlockComponentState extends State<FileBlockComponent>
@override
void didChangeDependencies() {
if (!UniversalPlatform.isMobile) {
- dropManagerState = context.read<EditorDropManagerState>();
+ dropManagerState = context.read<EditorDropManagerState?>();
}
super.didChangeDependencies();
}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/custom_image_block_component/image_menu.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/custom_image_block_component/image_menu.dart
index a584acbae1..bffb651d29 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/custom_image_block_component/image_menu.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/image/custom_image_block_component/image_menu.dart
@@ -72,7 +72,7 @@ class _ImageMenuState extends State<ImageMenu> {
const _Divider(),
MenuBlockButton(
tooltip: LocaleKeys.button_delete.tr(),
- iconData: FlowySvgs.delete_s,
+ iconData: FlowySvgs.trash_s,
onTap: deleteImage,
),
const HSpace(4),
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/math_equation/math_equation_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/math_equation/math_equation_block_component.dart
index 6330fd7fd8..286eac3d75 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/math_equation/math_equation_block_component.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/math_equation/math_equation_block_component.dart
@@ -2,6 +2,7 @@ import 'package:appflowy/generated/flowy_svgs.g.dart';
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/base/selectable_svg_widget.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/block_menu/block_menu_button.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
import 'package:easy_localization/easy_localization.dart';
import 'package:flowy_infra_ui/flowy_infra_ui.dart';
@@ -110,16 +111,24 @@ class MathEquationBlockComponentWidgetState
@override
Node get node => widget.node;
- bool isHover = false;
String get formula =>
widget.node.attributes[MathEquationBlockKeys.formula] as String;
late final editorState = context.read<EditorState>();
+ final ValueNotifier<bool> isHover = ValueNotifier(false);
+
+ late final controller = TextEditingController(text: formula);
+
+ @override
+ void dispose() {
+ controller.dispose();
+ super.dispose();
+ }
@override
Widget build(BuildContext context) {
return InkWell(
- onHover: (value) => setState(() => isHover = value),
+ onHover: (value) => isHover.value = value,
onTap: showEditingDialog,
child: _build(context),
);
@@ -165,6 +174,23 @@ class MathEquationBlockComponentWidgetState
);
}
+ if (UniversalPlatform.isDesktopOrWeb) {
+ child = Stack(
+ children: [
+ child,
+ Positioned(
+ right: 6,
+ top: 12,
+ child: ValueListenableBuilder<bool>(
+ valueListenable: isHover,
+ builder: (_, value, __) =>
+ value ? _buildDeleteButton(context) : const SizedBox.shrink(),
+ ),
+ ),
+ ],
+ );
+ }
+
return child;
}
@@ -198,8 +224,18 @@ class MathEquationBlockComponentWidgetState
);
}
+ Widget _buildDeleteButton(BuildContext context) {
+ return MenuBlockButton(
+ tooltip: LocaleKeys.button_delete.tr(),
+ iconData: FlowySvgs.trash_s,
+ onTap: () {
+ final transaction = editorState.transaction..deleteNode(widget.node);
+ editorState.apply(transaction);
+ },
+ );
+ }
+
void showEditingDialog() {
- final controller = TextEditingController(text: formula);
showDialog(
context: context,
builder: (context) {
@@ -246,7 +282,7 @@ class MathEquationBlockComponentWidgetState
actionsAlignment: MainAxisAlignment.spaceAround,
);
},
- ).then((_) => controller.dispose());
+ );
}
void updateMathEquation(String mathEquation, BuildContext context) {
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_date_block.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_date_block.dart
index 7ef29ccba4..b2190d67fa 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_date_block.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_date_block.dart
@@ -83,6 +83,13 @@ class _MentionDateBlockState extends State<MentionDateBlock> {
return const SizedBox.shrink();
}
+ final appearance = context.read<AppearanceSettingsCubit?>();
+ final reminder = context.read<ReminderBloc?>();
+
+ if (appearance == null || reminder == null) {
+ return const SizedBox.shrink();
+ }
+
return BlocBuilder<AppearanceSettingsCubit, AppearanceSettingsState>(
buildWhen: (previous, current) =>
previous.dateFormat != current.dateFormat ||
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_page_block.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_page_block.dart
index fce317cd48..f102c10daf 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_page_block.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/mention_page_block.dart
@@ -421,7 +421,6 @@ class _MentionPageBlockContent extends StatelessWidget {
child: FlowyText(
text,
decoration: TextDecoration.underline,
- decorationThickness: 0.5,
fontSize: textStyle?.fontSize,
fontWeight: textStyle?.fontWeight,
lineHeight: textStyle?.height,
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/slash_menu_items.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/slash_menu_items.dart
deleted file mode 100644
index b13c7fe282..0000000000
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mention/slash_menu_items.dart
+++ /dev/null
@@ -1,47 +0,0 @@
-import 'package:appflowy/generated/flowy_svgs.g.dart';
-import 'package:appflowy/generated/locale_keys.g.dart';
-import 'package:appflowy/plugins/document/presentation/editor_plugins/mention/mention_block.dart';
-import 'package:appflowy_editor/appflowy_editor.dart';
-import 'package:easy_localization/easy_localization.dart';
-
-SelectionMenuItem dateMenuItem = SelectionMenuItem(
- getName: LocaleKeys.document_plugins_insertDate.tr,
- icon: (_, isSelected, style) => FlowySvg(
- FlowySvgs.date_s,
- color: isSelected
- ? style.selectionMenuItemSelectedIconColor
- : style.selectionMenuItemIconColor,
- ),
- keywords: ['insert date', 'date', 'time'],
- handler: (editorState, menuService, context) =>
- insertDateReference(editorState),
-);
-
-Future<void> insertDateReference(EditorState editorState) async {
- 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
- ..replaceText(
- node,
- selection.start.offset,
- 0,
- MentionBlockKeys.mentionChar,
- attributes: {
- MentionBlockKeys.mention: {
- MentionBlockKeys.type: MentionType.date.name,
- MentionBlockKeys.date: DateTime.now().toIso8601String(),
- },
- },
- );
-
- await editorState.apply(transaction);
-}
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 4d1fd95558..571ac53bc0 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
@@ -64,7 +64,8 @@ export 'quote/quote_block_shortcuts.dart';
export 'shortcuts/character_shortcuts.dart';
export 'shortcuts/command_shortcuts.dart';
export 'simple_table/simple_table.dart';
-export 'slash_menu/slash_menu_items.dart';
+export 'slash_menu/slash_command.dart';
+export 'slash_menu/slash_menu_items_builder.dart';
export 'sub_page/sub_page_block_component.dart';
export 'table/table_menu.dart';
export 'table/table_option_action.dart';
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/shortcuts/character_shortcuts.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/shortcuts/character_shortcuts.dart
index c4affb7b69..080027d179 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/shortcuts/character_shortcuts.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/shortcuts/character_shortcuts.dart
@@ -18,7 +18,7 @@ List<CharacterShortcutEvent> buildCharacterShortcutEvents(
DocumentBloc documentBloc,
EditorStyleCustomizer styleCustomizer,
InlineActionsService inlineActionsService,
- List<SelectionMenuItem> slashMenuItems,
+ SlashMenuItemsBuilder slashMenuItemsBuilder,
) {
return [
// code block
@@ -36,8 +36,8 @@ List<CharacterShortcutEvent> buildCharacterShortcutEvents(
insertChildNodeInsideToggleList,
// customize the slash menu command
- customSlashCommand(
- slashMenuItems,
+ customAppFlowySlashCommand(
+ itemsBuilder: slashMenuItemsBuilder,
style: styleCustomizer.selectionMenuStyleBuilder(),
supportSlashMenuNodeTypes: supportSlashMenuNodeTypes,
),
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_cell_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_cell_block_component.dart
index 5e6bbf2d70..108579d213 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_cell_block_component.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_cell_block_component.dart
@@ -1,5 +1,6 @@
-import 'package:appflowy/plugins/document/presentation/editor_plugins/simple_table/simple_table.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';
import 'package:appflowy_editor/appflowy_editor.dart';
+import 'package:appflowy_editor_plugins/appflowy_editor_plugins.dart';
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:universal_platform/universal_platform.dart';
@@ -239,9 +240,19 @@ class SimpleTableCellBlockWidgetState extends State<SimpleTableCellBlockWidget>
),
width: node.columnWidth,
child: node.children.isEmpty
- ? _buildEmptyCellContent()
+ ? Column(
+ children: [
+ // expand the cell to make the empty cell content clickable
+ Expanded(
+ child: _buildEmptyCellContent(),
+ ),
+ ],
+ )
: Column(
- children: node.children.map(_buildCellContent).toList(),
+ children: [
+ ...node.children.map(_buildCellContent),
+ _buildEmptyCellContent(height: 12),
+ ],
),
),
),
@@ -300,21 +311,49 @@ class SimpleTableCellBlockWidgetState extends State<SimpleTableCellBlockWidget>
Widget _buildCellContent(Node childNode) {
final alignment = _buildAlignment();
- return Align(
- alignment: alignment,
- child: IntrinsicWidth(
- child: editorState.renderer.build(context, childNode),
- ),
+ Widget child = IntrinsicWidth(
+ child: editorState.renderer.build(context, childNode),
);
+
+ final notSupportAlignmentBlocks = [
+ DividerBlockKeys.type,
+ CalloutBlockKeys.type,
+ MathEquationBlockKeys.type,
+ CodeBlockKeys.type,
+ SubPageBlockKeys.type,
+ FileBlockKeys.type,
+ CustomImageBlockKeys.type,
+ ];
+ if (notSupportAlignmentBlocks.contains(childNode.type)) {
+ child = SizedBox(
+ width: double.infinity,
+ child: child,
+ );
+ } else {
+ child = Align(
+ alignment: alignment,
+ child: child,
+ );
+ }
+
+ return child;
}
- Widget _buildEmptyCellContent() {
+ Widget _buildEmptyCellContent({
+ double? height,
+ }) {
// if the table cell is empty, we should allow the user to tap on it to create a new paragraph.
- return GestureDetector(
+ final lastChild = node.children.lastOrNull;
+ if (lastChild != null && lastChild.delta?.isEmpty != null) {
+ return const SizedBox.shrink();
+ }
+
+ Widget child = GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
final transaction = editorState.transaction;
- final path = node.path.child(0);
+ final length = node.children.length;
+ final path = node.path.child(length);
transaction
..insertNode(
path,
@@ -324,6 +363,15 @@ class SimpleTableCellBlockWidgetState extends State<SimpleTableCellBlockWidget>
editorState.apply(transaction);
},
);
+
+ if (height != null) {
+ child = SizedBox(
+ height: height,
+ child: child,
+ );
+ }
+
+ return child;
}
Widget _buildRowMoreActionButton() {
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_operations/simple_table_node_extension.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_operations/simple_table_node_extension.dart
index a888db92a7..ff2cd3e674 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_operations/simple_table_node_extension.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_operations/simple_table_node_extension.dart
@@ -51,6 +51,12 @@ enum TableAlign {
TableAlign.center => Alignment.topCenter,
TableAlign.right => Alignment.topRight,
};
+
+ TextAlign get textAlign => switch (this) {
+ TableAlign.left => TextAlign.left,
+ TableAlign.center => TextAlign.center,
+ TableAlign.right => TextAlign.right,
+ };
}
extension TableNodeExtension on Node {
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/simple_table_feedback.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/simple_table_feedback.dart
index 1e5a2cf6c0..355a35fadc 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/simple_table_feedback.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/simple_table_feedback.dart
@@ -64,16 +64,18 @@ class _SimpleTableFeedbackState extends State<SimpleTableFeedback> {
@override
Widget build(BuildContext context) {
- return Provider.value(
- value: widget.editorState,
- child: SimpleTableWidget(
- node: dummyNode,
- simpleTableContext: simpleTableContext,
- enableAddColumnButton: false,
- enableAddRowButton: false,
- enableAddColumnAndRowButton: false,
- enableHoverEffect: false,
- isFeedback: true,
+ return Material(
+ child: Provider.value(
+ value: widget.editorState,
+ child: SimpleTableWidget(
+ node: dummyNode,
+ simpleTableContext: simpleTableContext,
+ enableAddColumnButton: false,
+ enableAddRowButton: false,
+ enableAddColumnAndRowButton: false,
+ enableHoverEffect: false,
+ isFeedback: true,
+ ),
),
);
}
@@ -115,10 +117,16 @@ class _SimpleTableFeedbackState extends State<SimpleTableFeedback> {
return simpleTableRowBlockNode(children: [cell]);
}).toList();
+ final columnWidth = tableNode.columnWidths[widget.index.toString()] ??
+ SimpleTableConstants.defaultColumnWidth;
+
return tableNode.copyWith(
children: rows,
attributes: {
...tableNode.attributes,
+ SimpleTableBlockKeys.columnWidths: {
+ '0': columnWidth,
+ },
if (widget.index != 0)
SimpleTableBlockKeys.enableHeaderColumn: false,
},
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_command.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_command.dart
new file mode 100644
index 0000000000..c20fec9d7d
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_command.dart
@@ -0,0 +1,145 @@
+import 'dart:io';
+
+import 'package:appflowy/plugins/document/presentation/editor_configuration.dart';
+import 'package:appflowy_editor/appflowy_editor.dart';
+import 'package:flutter/foundation.dart';
+import 'package:flutter/material.dart';
+import 'package:universal_platform/universal_platform.dart';
+
+typedef SlashMenuItemsBuilder = List<SelectionMenuItem> Function(
+ EditorState editorState,
+ Node node,
+);
+
+/// Show the slash menu
+///
+/// - support
+/// - desktop
+///
+final CharacterShortcutEvent appFlowySlashCommand = CharacterShortcutEvent(
+ key: 'show the slash menu',
+ character: '/',
+ handler: (editorState) async => _showSlashMenu(
+ editorState,
+ itemsBuilder: (_, __) => standardSelectionMenuItems,
+ supportSlashMenuNodeTypes: supportSlashMenuNodeTypes,
+ ),
+);
+
+CharacterShortcutEvent customAppFlowySlashCommand({
+ required SlashMenuItemsBuilder itemsBuilder,
+ bool shouldInsertSlash = true,
+ bool deleteKeywordsByDefault = false,
+ bool singleColumn = true,
+ SelectionMenuStyle style = SelectionMenuStyle.light,
+ required Set<String> supportSlashMenuNodeTypes,
+}) {
+ return CharacterShortcutEvent(
+ key: 'show the slash menu',
+ character: '/',
+ handler: (editorState) => _showSlashMenu(
+ editorState,
+ shouldInsertSlash: shouldInsertSlash,
+ deleteKeywordsByDefault: deleteKeywordsByDefault,
+ singleColumn: singleColumn,
+ style: style,
+ supportSlashMenuNodeTypes: supportSlashMenuNodeTypes,
+ itemsBuilder: itemsBuilder,
+ ),
+ );
+}
+
+SelectionMenuService? _selectionMenuService;
+Future<bool> _showSlashMenu(
+ EditorState editorState, {
+ required SlashMenuItemsBuilder itemsBuilder,
+ bool shouldInsertSlash = true,
+ bool singleColumn = true,
+ bool deleteKeywordsByDefault = false,
+ SelectionMenuStyle style = SelectionMenuStyle.light,
+ required Set<String> supportSlashMenuNodeTypes,
+}) async {
+ if (UniversalPlatform.isMobile) {
+ return false;
+ }
+
+ final selection = editorState.selection;
+ if (selection == null) {
+ return false;
+ }
+
+ // delete the selection
+ if (!selection.isCollapsed) {
+ await editorState.deleteSelection(selection);
+ }
+
+ final afterSelection = editorState.selection;
+ if (afterSelection == null || !afterSelection.isCollapsed) {
+ assert(false, 'the selection should be collapsed');
+ return true;
+ }
+
+ final node = editorState.getNodeAtPath(selection.start.path);
+
+ // only enable in white-list nodes
+ if (node == null ||
+ !_isSupportSlashMenuNode(node, supportSlashMenuNodeTypes)) {
+ return false;
+ }
+
+ final items = itemsBuilder(editorState, node);
+
+ // insert the slash character
+ if (shouldInsertSlash) {
+ keepEditorFocusNotifier.increase();
+ await editorState.insertTextAtPosition('/', position: selection.start);
+ }
+
+ // show the slash menu
+
+ final context = editorState.getNodeAtPath(selection.start.path)?.context;
+ if (context != null && context.mounted) {
+ _selectionMenuService = SelectionMenu(
+ context: context,
+ editorState: editorState,
+ selectionMenuItems: items,
+ deleteSlashByDefault: shouldInsertSlash,
+ deleteKeywordsByDefault: deleteKeywordsByDefault,
+ singleColumn: singleColumn,
+ style: style,
+ );
+ if (!kIsWeb && Platform.environment.containsKey('FLUTTER_TEST')) {
+ await _selectionMenuService?.show();
+ } else {
+ await _selectionMenuService?.show();
+ }
+ }
+
+ if (shouldInsertSlash) {
+ WidgetsBinding.instance.addPostFrameCallback(
+ (timeStamp) => keepEditorFocusNotifier.decrease(),
+ );
+ }
+
+ return true;
+}
+
+bool _isSupportSlashMenuNode(
+ Node node,
+ Set<String> supportSlashMenuNodeWhiteList,
+) {
+ // Check if current node type is supported
+ if (!supportSlashMenuNodeWhiteList.contains(node.type)) {
+ return false;
+ }
+
+ // If node has a parent and level > 1, recursively check parent nodes
+ if (node.level > 1 && node.parent != null) {
+ return _isSupportSlashMenuNode(
+ node.parent!,
+ supportSlashMenuNodeWhiteList,
+ );
+ }
+
+ return true;
+}
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
deleted file mode 100644
index 5caefe6e62..0000000000
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items.dart
+++ /dev/null
@@ -1,736 +0,0 @@
-import 'package:appflowy/generated/flowy_svgs.g.dart';
-import 'package:appflowy/generated/locale_keys.g.dart';
-import 'package:appflowy/plugins/document/application/prelude.dart';
-import 'package:appflowy/plugins/document/presentation/editor_plugins/base/insert_page_command.dart';
-import 'package:appflowy/plugins/document/presentation/editor_plugins/base/link_to_page_widget.dart';
-import 'package:appflowy/plugins/document/presentation/editor_plugins/base/selectable_svg_widget.dart';
-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';
-import 'package:appflowy_editor/appflowy_editor.dart';
-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(
- getName: () => LocaleKeys.document_slashMenu_name_text.tr(),
- nameBuilder: _slashMenuItemNameBuilder,
- icon: (editorState, isSelected, style) => SelectableSvgWidget(
- data: FlowySvgs.slash_menu_icon_text_s,
- isSelected: isSelected,
- style: style,
- ),
- keywords: ['text', 'paragraph'],
- handler: (editorState, _, __) {
- insertNodeAfterSelection(editorState, paragraphNode());
- },
-);
-
-// heading 1 - 3 menu items
-final heading1SlashMenuItem = SelectionMenuItem(
- getName: () => LocaleKeys.document_slashMenu_name_heading1.tr(),
- nameBuilder: _slashMenuItemNameBuilder,
- icon: (editorState, isSelected, style) => SelectableSvgWidget(
- data: FlowySvgs.slash_menu_icon_h1_s,
- isSelected: isSelected,
- style: style,
- ),
- keywords: ['heading 1', 'h1', 'heading1'],
- handler: (editorState, _, __) {
- insertHeadingAfterSelection(editorState, 1);
- },
-);
-
-final heading2SlashMenuItem = SelectionMenuItem(
- getName: () => LocaleKeys.document_slashMenu_name_heading2.tr(),
- nameBuilder: _slashMenuItemNameBuilder,
- icon: (editorState, isSelected, style) => SelectableSvgWidget(
- data: FlowySvgs.slash_menu_icon_h2_s,
- isSelected: isSelected,
- style: style,
- ),
- keywords: ['heading 2', 'h2', 'heading2'],
- handler: (editorState, _, __) {
- insertHeadingAfterSelection(editorState, 2);
- },
-);
-
-final heading3SlashMenuItem = SelectionMenuItem(
- getName: () => LocaleKeys.document_slashMenu_name_heading3.tr(),
- nameBuilder: _slashMenuItemNameBuilder,
- icon: (editorState, isSelected, style) => SelectableSvgWidget(
- data: FlowySvgs.slash_menu_icon_h3_s,
- isSelected: isSelected,
- style: style,
- ),
- keywords: ['heading 3', 'h3', 'heading3'],
- handler: (editorState, _, __) {
- insertHeadingAfterSelection(editorState, 3);
- },
-);
-
-// toggle heading 1 menu item
-// heading 1 - 3 menu items
-final toggleHeading1SlashMenuItem = SelectionMenuItem(
- getName: () => LocaleKeys.document_slashMenu_name_toggleHeading1.tr(),
- nameBuilder: _slashMenuItemNameBuilder,
- icon: (editorState, isSelected, style) => SelectableSvgWidget(
- data: FlowySvgs.toggle_heading1_s,
- isSelected: isSelected,
- style: style,
- ),
- keywords: ['toggle heading 1', 'toggle h1', 'toggle heading1'],
- handler: (editorState, _, __) {
- insertNodeAfterSelection(
- editorState,
- toggleHeadingNode(),
- );
- },
-);
-
-final toggleHeading2SlashMenuItem = SelectionMenuItem(
- getName: () => LocaleKeys.document_slashMenu_name_toggleHeading2.tr(),
- nameBuilder: _slashMenuItemNameBuilder,
- icon: (editorState, isSelected, style) => SelectableSvgWidget(
- data: FlowySvgs.toggle_heading2_s,
- isSelected: isSelected,
- style: style,
- ),
- keywords: ['toggle heading 2', 'toggle h2', 'toggle heading2'],
- handler: (editorState, _, __) {
- insertNodeAfterSelection(
- editorState,
- toggleHeadingNode(level: 2),
- );
- },
-);
-
-final toggleHeading3SlashMenuItem = SelectionMenuItem(
- getName: () => LocaleKeys.document_slashMenu_name_toggleHeading3.tr(),
- nameBuilder: _slashMenuItemNameBuilder,
- icon: (editorState, isSelected, style) => SelectableSvgWidget(
- data: FlowySvgs.toggle_heading3_s,
- isSelected: isSelected,
- style: style,
- ),
- keywords: ['toggle heading 3', 'toggle h3', 'toggle heading3'],
- handler: (editorState, _, __) {
- insertNodeAfterSelection(
- editorState,
- toggleHeadingNode(level: 3),
- );
- },
-);
-
-// image menu item
-final imageSlashMenuItem = SelectionMenuItem(
- getName: () => LocaleKeys.document_slashMenu_name_image.tr(),
- nameBuilder: _slashMenuItemNameBuilder,
- icon: (editorState, isSelected, style) => SelectableSvgWidget(
- data: FlowySvgs.slash_menu_icon_image_s,
- isSelected: isSelected,
- style: style,
- ),
- keywords: ['image', 'photo', 'picture', 'img'],
- handler: (editorState, menuService, context) async {
- // use the key to retrieve the state of the image block to show the popover automatically
- final imagePlaceholderKey = GlobalKey<ImagePlaceholderState>();
- await editorState.insertEmptyImageBlock(imagePlaceholderKey);
-
- WidgetsBinding.instance.addPostFrameCallback((_) {
- imagePlaceholderKey.currentState?.controller.show();
- });
- },
-);
-
-// bulleted list menu item
-final bulletedListSlashMenuItem = SelectionMenuItem(
- getName: () => LocaleKeys.document_slashMenu_name_bulletedList.tr(),
- nameBuilder: _slashMenuItemNameBuilder,
- icon: (editorState, isSelected, style) => SelectableSvgWidget(
- data: FlowySvgs.slash_menu_icon_bulleted_list_s,
- isSelected: isSelected,
- style: style,
- ),
- keywords: ['bulleted list', 'list', 'unordered list'],
- handler: (editorState, _, __) {
- insertBulletedListAfterSelection(editorState);
- },
-);
-
-// numbered list menu item
-final numberedListSlashMenuItem = SelectionMenuItem(
- getName: () => LocaleKeys.document_slashMenu_name_numberedList.tr(),
- nameBuilder: _slashMenuItemNameBuilder,
- icon: (editorState, isSelected, style) => SelectableSvgWidget(
- data: FlowySvgs.slash_menu_icon_numbered_list_s,
- isSelected: isSelected,
- style: style,
- ),
- keywords: ['numbered list', 'list', 'ordered list'],
- handler: (editorState, _, __) {
- insertNumberedListAfterSelection(editorState);
- },
-);
-
-// todo list menu item
-final todoListSlashMenuItem = SelectionMenuItem(
- getName: () => LocaleKeys.document_slashMenu_name_todoList.tr(),
- nameBuilder: _slashMenuItemNameBuilder,
- icon: (editorState, isSelected, style) => SelectableSvgWidget(
- data: FlowySvgs.slash_menu_icon_checkbox_s,
- isSelected: isSelected,
- style: style,
- ),
- keywords: ['checkbox', 'todo', 'list', 'to-do', 'task'],
- handler: (editorState, _, __) {
- insertCheckboxAfterSelection(editorState);
- },
-);
-
-// quote menu item
-final quoteSlashMenuItem = SelectionMenuItem(
- getName: () => LocaleKeys.document_slashMenu_name_quote.tr(),
- nameBuilder: _slashMenuItemNameBuilder,
- icon: (editorState, isSelected, style) => SelectableSvgWidget(
- data: FlowySvgs.slash_menu_icon_quote_s,
- isSelected: isSelected,
- style: style,
- ),
- keywords: ['quote', 'refer', 'blockquote', 'citation'],
- handler: (editorState, _, __) {
- insertQuoteAfterSelection(editorState);
- },
-);
-
-// divider menu item
-final dividerSlashMenuItem = SelectionMenuItem(
- getName: () => LocaleKeys.document_slashMenu_name_divider.tr(),
- nameBuilder: _slashMenuItemNameBuilder,
- icon: (editorState, isSelected, style) => SelectableSvgWidget(
- data: FlowySvgs.slash_menu_icon_divider_s,
- isSelected: isSelected,
- style: style,
- ),
- keywords: ['divider', 'separator', 'line', 'break', 'horizontal line'],
- handler: (editorState, _, __) {
- final selection = editorState.selection;
- if (selection == null || !selection.isCollapsed) {
- return;
- }
- final path = selection.end.path;
- final node = editorState.getNodeAtPath(path);
- final delta = node?.delta;
- if (node == null || delta == null) {
- return;
- }
- final insertedPath = delta.isEmpty ? path : path.next;
- final transaction = editorState.transaction
- ..insertNode(insertedPath, dividerNode())
- ..insertNode(insertedPath, paragraphNode())
- ..afterSelection = Selection.collapsed(Position(path: insertedPath.next));
- editorState.apply(transaction);
- },
-);
-
-// grid & board & calendar menu item
-SelectionMenuItem gridSlashMenuItem(DocumentBloc documentBloc) {
- return SelectionMenuItem(
- getName: () => LocaleKeys.document_slashMenu_name_grid.tr(),
- nameBuilder: _slashMenuItemNameBuilder,
- icon: (editorState, onSelected, style) => SelectableSvgWidget(
- data: FlowySvgs.slash_menu_icon_grid_s,
- isSelected: onSelected,
- style: style,
- ),
- keywords: ['grid', 'database'],
- handler: (editorState, menuService, context) async {
- // create the view inside current page
- final parentViewId = documentBloc.documentId;
- final value = await ViewBackendService.createView(
- parentViewId: parentViewId,
- name: LocaleKeys.menuAppHeader_defaultNewPageName.tr(),
- layoutType: ViewLayoutPB.Grid,
- );
- value.map((r) => editorState.insertInlinePage(parentViewId, r));
- },
- );
-}
-
-SelectionMenuItem kanbanSlashMenuItem(DocumentBloc documentBloc) {
- return SelectionMenuItem(
- getName: () => LocaleKeys.document_slashMenu_name_kanban.tr(),
- nameBuilder: _slashMenuItemNameBuilder,
- icon: (editorState, onSelected, style) => SelectableSvgWidget(
- data: FlowySvgs.slash_menu_icon_kanban_s,
- isSelected: onSelected,
- style: style,
- ),
- keywords: ['board', 'kanban', 'database'],
- handler: (editorState, menuService, context) async {
- // create the view inside current page
- final parentViewId = documentBloc.documentId;
- final value = await ViewBackendService.createView(
- parentViewId: parentViewId,
- name: LocaleKeys.menuAppHeader_defaultNewPageName.tr(),
- layoutType: ViewLayoutPB.Board,
- );
- value.map((r) => editorState.insertInlinePage(parentViewId, r));
- },
- );
-}
-
-SelectionMenuItem calendarSlashMenuItem(DocumentBloc documentBloc) {
- return SelectionMenuItem(
- getName: () => LocaleKeys.document_slashMenu_name_calendar.tr(),
- nameBuilder: _slashMenuItemNameBuilder,
- icon: (editorState, onSelected, style) => SelectableSvgWidget(
- data: FlowySvgs.slash_menu_icon_calendar_s,
- isSelected: onSelected,
- style: style,
- ),
- keywords: ['calendar', 'database'],
- handler: (editorState, menuService, context) async {
- // create the view inside current page
- final parentViewId = documentBloc.documentId;
- final value = await ViewBackendService.createView(
- parentViewId: parentViewId,
- name: LocaleKeys.menuAppHeader_defaultNewPageName.tr(),
- layoutType: ViewLayoutPB.Calendar,
- );
- value.map((r) => editorState.insertInlinePage(parentViewId, r));
- },
- );
-}
-
-// linked doc menu item
-final referencedDocSlashMenuItem = SelectionMenuItem(
- getName: () => LocaleKeys.document_slashMenu_name_linkedDoc.tr(),
- nameBuilder: _slashMenuItemNameBuilder,
- icon: (editorState, isSelected, style) => SelectableSvgWidget(
- data: FlowySvgs.slash_menu_icon_doc_s,
- isSelected: isSelected,
- style: style,
- ),
- keywords: [
- 'page',
- 'notes',
- 'referenced page',
- 'referenced document',
- 'referenced database',
- 'link to database',
- 'link to document',
- 'link to page',
- 'link to grid',
- 'link to board',
- 'link to calendar',
- ],
- handler: (editorState, menuService, context) => showLinkToPageMenu(
- editorState,
- menuService,
- // enable database and document references
- insertPage: false,
- ),
-);
-
-// linked grid & board & calendar menu item
-SelectionMenuItem referencedGridSlashMenuItem = SelectionMenuItem(
- getName: () => LocaleKeys.document_slashMenu_name_linkedGrid.tr(),
- nameBuilder: _slashMenuItemNameBuilder,
- icon: (editorState, onSelected, style) => SelectableSvgWidget(
- data: FlowySvgs.slash_menu_icon_grid_s,
- isSelected: onSelected,
- style: style,
- ),
- keywords: ['referenced', 'grid', 'database', 'linked'],
- handler: (editorState, menuService, context) => showLinkToPageMenu(
- editorState,
- menuService,
- pageType: ViewLayoutPB.Grid,
- ),
-);
-
-SelectionMenuItem referencedKanbanSlashMenuItem = SelectionMenuItem(
- getName: () => LocaleKeys.document_slashMenu_name_linkedKanban.tr(),
- nameBuilder: _slashMenuItemNameBuilder,
- icon: (editorState, onSelected, style) => SelectableSvgWidget(
- data: FlowySvgs.slash_menu_icon_kanban_s,
- isSelected: onSelected,
- style: style,
- ),
- keywords: ['referenced', 'board', 'kanban', 'linked'],
- handler: (editorState, menuService, context) => showLinkToPageMenu(
- editorState,
- menuService,
- pageType: ViewLayoutPB.Board,
- ),
-);
-
-SelectionMenuItem referencedCalendarSlashMenuItem = SelectionMenuItem(
- getName: () => LocaleKeys.document_slashMenu_name_linkedCalendar.tr(),
- nameBuilder: _slashMenuItemNameBuilder,
- icon: (editorState, onSelected, style) => SelectableSvgWidget(
- data: FlowySvgs.slash_menu_icon_calendar_s,
- isSelected: onSelected,
- style: style,
- ),
- keywords: ['referenced', 'calendar', 'database', 'linked'],
- handler: (editorState, menuService, context) => showLinkToPageMenu(
- editorState,
- menuService,
- pageType: ViewLayoutPB.Calendar,
- ),
-);
-
-// callout menu item
-SelectionMenuItem calloutSlashMenuItem = SelectionMenuItem.node(
- getName: LocaleKeys.document_plugins_callout.tr,
- nameBuilder: _slashMenuItemNameBuilder,
- iconBuilder: (editorState, isSelected, style) => SelectableSvgWidget(
- data: FlowySvgs.slash_menu_icon_callout_s,
- isSelected: isSelected,
- style: style,
- ),
- keywords: [CalloutBlockKeys.type],
- nodeBuilder: (editorState, context) =>
- calloutNode(defaultColor: Colors.transparent),
- replace: (_, node) => node.delta?.isEmpty ?? false,
- updateSelection: (_, path, __, ___) {
- return Selection.single(path: path, startOffset: 0);
- },
-);
-
-// outline menu item
-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'],
- 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(),
- nameBuilder: _slashMenuItemNameBuilder,
- iconBuilder: (editorState, isSelected, style) => SelectableSvgWidget(
- data: FlowySvgs.slash_menu_icon_math_equation_s,
- isSelected: isSelected,
- style: style,
- ),
- keywords: ['tex', 'latex', 'katex', 'math equation', 'formula'],
- nodeBuilder: (editorState, _) => mathEquationNode(),
- replace: (_, node) => node.delta?.isEmpty ?? false,
- updateSelection: (editorState, path, __, ___) {
- WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
- final mathEquationState =
- editorState.getNodeAtPath(path)?.key.currentState;
- if (mathEquationState != null &&
- mathEquationState is MathEquationBlockComponentWidgetState) {
- mathEquationState.showEditingDialog();
- }
- });
- return null;
- },
-);
-
-// code block menu item
-SelectionMenuItem codeBlockSlashMenuItem = SelectionMenuItem.node(
- getName: () => LocaleKeys.document_slashMenu_name_code.tr(),
- nameBuilder: _slashMenuItemNameBuilder,
- iconBuilder: (editorState, isSelected, style) => SelectableSvgWidget(
- data: FlowySvgs.slash_menu_icon_code_block_s,
- isSelected: isSelected,
- style: style,
- ),
- keywords: ['code', 'code block'],
- nodeBuilder: (_, __) => codeBlockNode(),
- replace: (_, node) => node.delta?.isEmpty ?? false,
-);
-
-// toggle menu item
-SelectionMenuItem toggleListSlashMenuItem = SelectionMenuItem.node(
- getName: () => LocaleKeys.document_slashMenu_name_toggleList.tr(),
- nameBuilder: _slashMenuItemNameBuilder,
- iconBuilder: (editorState, isSelected, style) => SelectableSvgWidget(
- data: FlowySvgs.slash_menu_icon_toggle_s,
- isSelected: isSelected,
- style: style,
- ),
- keywords: ['collapsed list', 'toggle list', 'list', 'dropdown'],
- nodeBuilder: (editorState, _) => toggleListBlockNode(),
- replace: (_, node) => node.delta?.isEmpty ?? false,
-);
-
-// emoji menu item
-SelectionMenuItem emojiSlashMenuItem = SelectionMenuItem(
- getName: () => LocaleKeys.document_slashMenu_name_emoji.tr(),
- nameBuilder: _slashMenuItemNameBuilder,
- icon: (editorState, isSelected, style) => SelectableSvgWidget(
- data: FlowySvgs.slash_menu_icon_emoji_picker_s,
- isSelected: isSelected,
- style: style,
- ),
- keywords: ['emoji', 'reaction', 'emoticon'],
- handler: (editorState, menuService, context) {
- final container = Overlay.of(context);
- menuService.dismiss();
- showEmojiPickerMenu(
- container,
- editorState,
- menuService.alignment,
- menuService.offset,
- );
- },
-);
-
-// auto generate menu item
-SelectionMenuItem aiWriterSlashMenuItem = SelectionMenuItem(
- getName: LocaleKeys.document_slashMenu_name_aiWriter.tr,
- icon: (editorState, isSelected, style) => SelectableSvgWidget(
- data: FlowySvgs.slash_menu_icon_ai_writer_s,
- isSelected: isSelected,
- style: style,
- ),
- keywords: ['ai', 'openai', 'writer', 'ai writer', 'autogenerator'],
- 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 newNode = aiWriterNode(start: selection);
-
- final transaction = editorState.transaction;
- //default insert after
- final path = node.path.next;
- transaction
- ..insertNode(path, newNode)
- ..afterSelection = null;
- editorState.apply(
- transaction,
- options: const ApplyOptions(inMemoryUpdate: true),
- );
- },
-);
-
-// table menu item
-SelectionMenuItem tableSlashMenuItem = SelectionMenuItem(
- getName: () => LocaleKeys.document_slashMenu_name_table.tr(),
- nameBuilder: _slashMenuItemNameBuilder,
- icon: (editorState, isSelected, style) => SelectableSvgWidget(
- data: FlowySvgs.slash_menu_icon_simple_table_s,
- isSelected: isSelected,
- style: style,
- ),
- keywords: ['table', 'rows', 'columns', 'data'],
- handler: (editorState, _, __) async {
- final selection = editorState.selection;
- if (selection == null || !selection.isCollapsed) {
- return;
- }
-
- final currentNode = editorState.getNodeAtPath(selection.end.path);
- if (currentNode == null) {
- return;
- }
-
- // create a simple table with 2 columns and 2 rows
- final tableNode = createSimpleTableBlockNode(
- columnCount: 2,
- rowCount: 2,
- );
-
- final transaction = editorState.transaction;
- final delta = currentNode.delta;
- if (delta != null && delta.isEmpty) {
- final path = selection.end.path;
- transaction
- ..insertNode(path, tableNode)
- ..deleteNode(currentNode);
- transaction.afterSelection = Selection.collapsed(
- Position(
- // table -> row -> cell -> paragraph
- path: path + [0, 0, 0],
- ),
- );
- } else {
- final path = selection.end.path.next;
- transaction.insertNode(path, tableNode);
- transaction.afterSelection = Selection.collapsed(
- Position(
- // table -> row -> cell -> paragraph
- path: path + [0, 0, 0],
- ),
- );
- }
-
- await editorState.apply(transaction);
- },
-);
-
-// date or reminder menu item
-SelectionMenuItem dateOrReminderSlashMenuItem = SelectionMenuItem(
- getName: () => LocaleKeys.document_slashMenu_name_dateOrReminder.tr(),
- nameBuilder: _slashMenuItemNameBuilder,
- icon: (editorState, isSelected, style) => SelectableSvgWidget(
- data: FlowySvgs.slash_menu_icon_date_or_reminder_s,
- isSelected: isSelected,
- style: style,
- ),
- keywords: ['insert date', 'date', 'time', 'reminder', 'schedule'],
- handler: (editorState, menuService, context) =>
- insertDateReference(editorState),
-);
-
-// photo gallery menu item
-SelectionMenuItem photoGallerySlashMenuItem = SelectionMenuItem(
- getName: () => LocaleKeys.document_slashMenu_name_photoGallery.tr(),
- nameBuilder: _slashMenuItemNameBuilder,
- icon: (editorState, isSelected, style) => SelectableSvgWidget(
- data: FlowySvgs.slash_menu_icon_photo_gallery_s,
- isSelected: isSelected,
- style: style,
- ),
- keywords: [
- LocaleKeys.document_plugins_photoGallery_imageKeyword.tr(),
- LocaleKeys.document_plugins_photoGallery_imageGalleryKeyword.tr(),
- LocaleKeys.document_plugins_photoGallery_photoKeyword.tr(),
- LocaleKeys.document_plugins_photoGallery_photoBrowserKeyword.tr(),
- LocaleKeys.document_plugins_photoGallery_galleryKeyword.tr(),
- ],
- handler: (editorState, _, __) async {
- final imagePlaceholderKey = GlobalKey<ImagePlaceholderState>();
- await editorState.insertEmptyMultiImageBlock(imagePlaceholderKey);
- WidgetsBinding.instance.addPostFrameCallback(
- (_) => imagePlaceholderKey.currentState?.controller.show(),
- );
- },
-);
-
-// file menu item
-SelectionMenuItem fileSlashMenuItem = SelectionMenuItem(
- getName: () => LocaleKeys.document_slashMenu_name_file.tr(),
- nameBuilder: _slashMenuItemNameBuilder,
- icon: (editorState, isSelected, style) => SelectableSvgWidget(
- data: FlowySvgs.slash_menu_icon_file_s,
- isSelected: isSelected,
- style: style,
- ),
- keywords: ['file upload', 'pdf', 'zip', 'archive', 'upload', 'attachment'],
- handler: (editorState, _, __) async {
- final fileGlobalKey = GlobalKey<FileBlockComponentState>();
- await editorState.insertEmptyFileBlock(fileGlobalKey);
-
- WidgetsBinding.instance.addPostFrameCallback((_) {
- fileGlobalKey.currentState?.controller.show();
- });
- },
-);
-
-// Sub-page menu item
-SelectionMenuItem subPageSlashMenuItem = SelectionMenuItem.node(
- getName: () => LocaleKeys.document_slashMenu_subPage_name.tr(),
- nameBuilder: _slashMenuItemNameBuilder,
- iconBuilder: (_, isSelected, style) => SelectableSvgWidget(
- data: FlowySvgs.insert_document_s,
- isSelected: isSelected,
- style: style,
- ),
- keywords: [
- LocaleKeys.document_slashMenu_subPage_keyword1.tr(),
- LocaleKeys.document_slashMenu_subPage_keyword2.tr(),
- LocaleKeys.document_slashMenu_subPage_keyword3.tr(),
- LocaleKeys.document_slashMenu_subPage_keyword4.tr(),
- LocaleKeys.document_slashMenu_subPage_keyword5.tr(),
- LocaleKeys.document_slashMenu_subPage_keyword6.tr(),
- LocaleKeys.document_slashMenu_subPage_keyword7.tr(),
- LocaleKeys.document_slashMenu_subPage_keyword8.tr(),
- ],
- 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(),
-);
-
-Widget _slashMenuItemNameBuilder(
- String name,
- SelectionMenuStyle style,
- bool isSelected,
-) {
- return FlowyText.regular(
- name,
- fontSize: 12.0,
- figmaLineHeight: 15.0,
- color: isSelected
- ? style.selectionMenuItemSelectedTextColor
- : style.selectionMenuItemTextColor,
- );
-}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/ai_writer_item.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/ai_writer_item.dart
new file mode 100644
index 0000000000..4e3f455522
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/ai_writer_item.dart
@@ -0,0 +1,55 @@
+import 'package:appflowy/generated/flowy_svgs.g.dart';
+import 'package:appflowy/generated/locale_keys.g.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/base/selectable_svg_widget.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';
+
+import 'slash_menu_item_builder.dart';
+
+final _keywords = [
+ 'ai',
+ 'openai',
+ 'writer',
+ 'ai writer',
+ 'autogenerator',
+];
+
+// auto generate menu item
+SelectionMenuItem aiWriterSlashMenuItem = SelectionMenuItem(
+ getName: LocaleKeys.document_slashMenu_name_aiWriter.tr,
+ keywords: _keywords,
+ handler: (editorState, _, __) async => editorState.insertAiWriter(),
+ icon: (_, isSelected, style) => SelectableSvgWidget(
+ data: FlowySvgs.slash_menu_icon_ai_writer_s,
+ isSelected: isSelected,
+ style: style,
+ ),
+ nameBuilder: slashMenuItemNameBuilder,
+);
+
+extension on EditorState {
+ Future<void> insertAiWriter() async {
+ final selection = this.selection;
+ if (selection == null || !selection.isCollapsed) {
+ return;
+ }
+ final node = getNodeAtPath(selection.end.path);
+ final delta = node?.delta;
+ if (node == null || delta == null) {
+ return;
+ }
+ final newNode = aiWriterNode(start: selection);
+
+ final transaction = this.transaction;
+ //default insert after
+ final path = node.path.next;
+ transaction
+ ..insertNode(path, newNode)
+ ..afterSelection = null;
+ await apply(
+ transaction,
+ options: const ApplyOptions(inMemoryUpdate: true),
+ );
+ }
+}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/bulleted_list_item.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/bulleted_list_item.dart
new file mode 100644
index 0000000000..3fee0d0adb
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/bulleted_list_item.dart
@@ -0,0 +1,29 @@
+import 'package:appflowy/generated/flowy_svgs.g.dart';
+import 'package:appflowy/generated/locale_keys.g.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/base/selectable_svg_widget.dart';
+import 'package:appflowy_editor/appflowy_editor.dart';
+import 'package:easy_localization/easy_localization.dart';
+
+import 'slash_menu_item_builder.dart';
+
+final _keywords = [
+ 'bulleted list',
+ 'list',
+ 'unordered list',
+ 'ul',
+];
+
+/// Bulleted list menu item
+final bulletedListSlashMenuItem = SelectionMenuItem(
+ getName: () => LocaleKeys.document_slashMenu_name_bulletedList.tr(),
+ keywords: _keywords,
+ handler: (editorState, _, __) {
+ insertBulletedListAfterSelection(editorState);
+ },
+ nameBuilder: slashMenuItemNameBuilder,
+ icon: (editorState, isSelected, style) => SelectableSvgWidget(
+ data: FlowySvgs.slash_menu_icon_bulleted_list_s,
+ isSelected: isSelected,
+ style: style,
+ ),
+);
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/callout_item.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/callout_item.dart
new file mode 100644
index 0000000000..6f553f5216
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/callout_item.dart
@@ -0,0 +1,31 @@
+import 'package:appflowy/generated/flowy_svgs.g.dart';
+import 'package:appflowy/generated/locale_keys.g.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/base/selectable_svg_widget.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';
+import 'package:flutter/material.dart';
+
+import 'slash_menu_item_builder.dart';
+
+final _keywords = [
+ 'callout',
+];
+
+/// Callout menu item
+SelectionMenuItem calloutSlashMenuItem = SelectionMenuItem.node(
+ getName: LocaleKeys.document_plugins_callout.tr,
+ keywords: _keywords,
+ nodeBuilder: (editorState, context) =>
+ calloutNode(defaultColor: Colors.transparent),
+ replace: (_, node) => node.delta?.isEmpty ?? false,
+ updateSelection: (_, path, __, ___) {
+ return Selection.single(path: path, startOffset: 0);
+ },
+ nameBuilder: slashMenuItemNameBuilder,
+ iconBuilder: (editorState, isSelected, style) => SelectableSvgWidget(
+ data: FlowySvgs.slash_menu_icon_callout_s,
+ isSelected: isSelected,
+ style: style,
+ ),
+);
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/code_block_item.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/code_block_item.dart
new file mode 100644
index 0000000000..44c346a302
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/code_block_item.dart
@@ -0,0 +1,27 @@
+import 'package:appflowy/generated/flowy_svgs.g.dart';
+import 'package:appflowy/generated/locale_keys.g.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/base/selectable_svg_widget.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/slash_menu_item_builder.dart';
+import 'package:appflowy_editor/appflowy_editor.dart';
+import 'package:appflowy_editor_plugins/appflowy_editor_plugins.dart';
+import 'package:easy_localization/easy_localization.dart';
+
+final _keywords = [
+ 'code',
+ 'code block',
+ 'codeblock',
+];
+
+// code block menu item
+SelectionMenuItem codeBlockSlashMenuItem = SelectionMenuItem.node(
+ getName: () => LocaleKeys.document_slashMenu_name_code.tr(),
+ keywords: _keywords,
+ nodeBuilder: (_, __) => codeBlockNode(),
+ replace: (_, node) => node.delta?.isEmpty ?? false,
+ nameBuilder: slashMenuItemNameBuilder,
+ iconBuilder: (_, isSelected, style) => SelectableSvgWidget(
+ data: FlowySvgs.slash_menu_icon_code_block_s,
+ isSelected: isSelected,
+ style: style,
+ ),
+);
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/database_items.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/database_items.dart
new file mode 100644
index 0000000000..176b67586a
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/database_items.dart
@@ -0,0 +1,185 @@
+import 'package:appflowy/generated/flowy_svgs.g.dart';
+import 'package:appflowy/generated/locale_keys.g.dart';
+import 'package:appflowy/plugins/document/application/prelude.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/base/insert_page_command.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/base/link_to_page_widget.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/base/selectable_svg_widget.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:easy_localization/easy_localization.dart';
+
+import 'slash_menu_item_builder.dart';
+
+final _gridKeywords = ['grid', 'database'];
+final _kanbanKeywords = ['board', 'kanban', 'database'];
+final _calendarKeywords = ['calendar', 'database'];
+
+final _linkedDocKeywords = [
+ 'page',
+ 'notes',
+ 'referenced page',
+ 'referenced document',
+ 'referenced database',
+ 'link to database',
+ 'link to document',
+ 'link to page',
+ 'link to grid',
+ 'link to board',
+ 'link to calendar',
+];
+final _linkedGridKeywords = [
+ 'referenced',
+ 'grid',
+ 'database',
+ 'linked',
+];
+final _linkedKanbanKeywords = [
+ 'referenced',
+ 'board',
+ 'kanban',
+ 'linked',
+];
+final _linkedCalendarKeywords = [
+ 'referenced',
+ 'calendar',
+ 'database',
+ 'linked',
+];
+
+/// Grid menu item
+SelectionMenuItem gridSlashMenuItem(DocumentBloc documentBloc) {
+ return SelectionMenuItem(
+ getName: () => LocaleKeys.document_slashMenu_name_grid.tr(),
+ keywords: _gridKeywords,
+ handler: (editorState, menuService, context) async {
+ // create the view inside current page
+ final parentViewId = documentBloc.documentId;
+ final value = await ViewBackendService.createView(
+ parentViewId: parentViewId,
+ name: LocaleKeys.menuAppHeader_defaultNewPageName.tr(),
+ layoutType: ViewLayoutPB.Grid,
+ );
+ value.map((r) => editorState.insertInlinePage(parentViewId, r));
+ },
+ nameBuilder: slashMenuItemNameBuilder,
+ icon: (editorState, onSelected, style) => SelectableSvgWidget(
+ data: FlowySvgs.slash_menu_icon_grid_s,
+ isSelected: onSelected,
+ style: style,
+ ),
+ );
+}
+
+SelectionMenuItem kanbanSlashMenuItem(DocumentBloc documentBloc) {
+ return SelectionMenuItem(
+ getName: () => LocaleKeys.document_slashMenu_name_kanban.tr(),
+ keywords: _kanbanKeywords,
+ handler: (editorState, menuService, context) async {
+ // create the view inside current page
+ final parentViewId = documentBloc.documentId;
+ final value = await ViewBackendService.createView(
+ parentViewId: parentViewId,
+ name: LocaleKeys.menuAppHeader_defaultNewPageName.tr(),
+ layoutType: ViewLayoutPB.Board,
+ );
+ value.map((r) => editorState.insertInlinePage(parentViewId, r));
+ },
+ nameBuilder: slashMenuItemNameBuilder,
+ icon: (editorState, onSelected, style) => SelectableSvgWidget(
+ data: FlowySvgs.slash_menu_icon_kanban_s,
+ isSelected: onSelected,
+ style: style,
+ ),
+ );
+}
+
+SelectionMenuItem calendarSlashMenuItem(DocumentBloc documentBloc) {
+ return SelectionMenuItem(
+ getName: () => LocaleKeys.document_slashMenu_name_calendar.tr(),
+ keywords: _calendarKeywords,
+ handler: (editorState, menuService, context) async {
+ // create the view inside current page
+ final parentViewId = documentBloc.documentId;
+ final value = await ViewBackendService.createView(
+ parentViewId: parentViewId,
+ name: LocaleKeys.menuAppHeader_defaultNewPageName.tr(),
+ layoutType: ViewLayoutPB.Calendar,
+ );
+ value.map((r) => editorState.insertInlinePage(parentViewId, r));
+ },
+ nameBuilder: slashMenuItemNameBuilder,
+ icon: (editorState, onSelected, style) => SelectableSvgWidget(
+ data: FlowySvgs.slash_menu_icon_calendar_s,
+ isSelected: onSelected,
+ style: style,
+ ),
+ );
+}
+
+// linked doc menu item
+final linkToPageSlashMenuItem = SelectionMenuItem(
+ getName: () => LocaleKeys.document_slashMenu_name_linkedDoc.tr(),
+ keywords: _linkedDocKeywords,
+ handler: (editorState, menuService, context) => showLinkToPageMenu(
+ editorState,
+ menuService,
+ // enable database and document references
+ insertPage: false,
+ ),
+ nameBuilder: slashMenuItemNameBuilder,
+ icon: (editorState, isSelected, style) => SelectableSvgWidget(
+ data: FlowySvgs.slash_menu_icon_doc_s,
+ isSelected: isSelected,
+ style: style,
+ ),
+);
+
+// linked grid & board & calendar menu item
+SelectionMenuItem referencedGridSlashMenuItem = SelectionMenuItem(
+ getName: () => LocaleKeys.document_slashMenu_name_linkedGrid.tr(),
+ keywords: _linkedGridKeywords,
+ handler: (editorState, menuService, context) => showLinkToPageMenu(
+ editorState,
+ menuService,
+ pageType: ViewLayoutPB.Grid,
+ ),
+ nameBuilder: slashMenuItemNameBuilder,
+ icon: (editorState, onSelected, style) => SelectableSvgWidget(
+ data: FlowySvgs.slash_menu_icon_grid_s,
+ isSelected: onSelected,
+ style: style,
+ ),
+);
+
+SelectionMenuItem referencedKanbanSlashMenuItem = SelectionMenuItem(
+ getName: () => LocaleKeys.document_slashMenu_name_linkedKanban.tr(),
+ keywords: _linkedKanbanKeywords,
+ handler: (editorState, menuService, context) => showLinkToPageMenu(
+ editorState,
+ menuService,
+ pageType: ViewLayoutPB.Board,
+ ),
+ nameBuilder: slashMenuItemNameBuilder,
+ icon: (editorState, onSelected, style) => SelectableSvgWidget(
+ data: FlowySvgs.slash_menu_icon_kanban_s,
+ isSelected: onSelected,
+ style: style,
+ ),
+);
+
+SelectionMenuItem referencedCalendarSlashMenuItem = SelectionMenuItem(
+ getName: () => LocaleKeys.document_slashMenu_name_linkedCalendar.tr(),
+ keywords: _linkedCalendarKeywords,
+ handler: (editorState, menuService, context) => showLinkToPageMenu(
+ editorState,
+ menuService,
+ pageType: ViewLayoutPB.Calendar,
+ ),
+ nameBuilder: slashMenuItemNameBuilder,
+ icon: (editorState, onSelected, style) => SelectableSvgWidget(
+ data: FlowySvgs.slash_menu_icon_calendar_s,
+ isSelected: onSelected,
+ style: style,
+ ),
+);
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/date_item.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/date_item.dart
new file mode 100644
index 0000000000..0bb09d0a7e
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/date_item.dart
@@ -0,0 +1,59 @@
+import 'package:appflowy/generated/flowy_svgs.g.dart';
+import 'package:appflowy/generated/locale_keys.g.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/base/selectable_svg_widget.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/slash_menu_item_builder.dart';
+import 'package:appflowy_editor/appflowy_editor.dart';
+import 'package:easy_localization/easy_localization.dart';
+
+final _keywords = [
+ 'insert date',
+ 'date',
+ 'time',
+ 'reminder',
+ 'schedule',
+];
+
+// date or reminder menu item
+SelectionMenuItem dateOrReminderSlashMenuItem = SelectionMenuItem(
+ getName: () => LocaleKeys.document_slashMenu_name_dateOrReminder.tr(),
+ keywords: _keywords,
+ handler: (editorState, _, __) async => editorState.insertDateReference(),
+ nameBuilder: slashMenuItemNameBuilder,
+ icon: (_, isSelected, style) => SelectableSvgWidget(
+ data: FlowySvgs.slash_menu_icon_date_or_reminder_s,
+ isSelected: isSelected,
+ style: style,
+ ),
+);
+
+extension on EditorState {
+ Future<void> insertDateReference() async {
+ final selection = this.selection;
+ if (selection == null || !selection.isCollapsed) {
+ return;
+ }
+
+ final node = getNodeAtPath(selection.end.path);
+ final delta = node?.delta;
+ if (node == null || delta == null) {
+ return;
+ }
+
+ final transaction = this.transaction
+ ..replaceText(
+ node,
+ selection.start.offset,
+ 0,
+ MentionBlockKeys.mentionChar,
+ attributes: {
+ MentionBlockKeys.mention: {
+ MentionBlockKeys.type: MentionType.date.name,
+ MentionBlockKeys.date: DateTime.now().toIso8601String(),
+ },
+ },
+ );
+
+ await apply(transaction);
+ }
+}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/divider_item.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/divider_item.dart
new file mode 100644
index 0000000000..a6c4001a68
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/divider_item.dart
@@ -0,0 +1,49 @@
+import 'package:appflowy/generated/flowy_svgs.g.dart';
+import 'package:appflowy/generated/locale_keys.g.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/base/selectable_svg_widget.dart';
+import 'package:appflowy_editor/appflowy_editor.dart';
+import 'package:easy_localization/easy_localization.dart';
+
+import 'slash_menu_item_builder.dart';
+
+final _keywords = [
+ 'divider',
+ 'separator',
+ 'line',
+ 'break',
+ 'horizontal line',
+];
+
+/// Divider menu item
+final dividerSlashMenuItem = SelectionMenuItem(
+ getName: () => LocaleKeys.document_slashMenu_name_divider.tr(),
+ keywords: _keywords,
+ handler: (editorState, _, __) async => editorState.insertDividerBlock(),
+ nameBuilder: slashMenuItemNameBuilder,
+ icon: (editorState, isSelected, style) => SelectableSvgWidget(
+ data: FlowySvgs.slash_menu_icon_divider_s,
+ isSelected: isSelected,
+ style: style,
+ ),
+);
+
+extension on EditorState {
+ Future<void> insertDividerBlock() async {
+ final selection = this.selection;
+ if (selection == null || !selection.isCollapsed) {
+ return;
+ }
+ final path = selection.end.path;
+ final node = getNodeAtPath(path);
+ final delta = node?.delta;
+ if (node == null || delta == null) {
+ return;
+ }
+ final insertedPath = delta.isEmpty ? path : path.next;
+ final transaction = this.transaction
+ ..insertNode(insertedPath, dividerNode())
+ ..insertNode(insertedPath, paragraphNode())
+ ..afterSelection = Selection.collapsed(Position(path: insertedPath.next));
+ await apply(transaction);
+ }
+}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/emoji_item.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/emoji_item.dart
new file mode 100644
index 0000000000..df1c457cc2
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/emoji_item.dart
@@ -0,0 +1,47 @@
+import 'package:appflowy/generated/flowy_svgs.g.dart';
+import 'package:appflowy/generated/locale_keys.g.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/base/selectable_svg_widget.dart';
+import 'package:appflowy/workspace/presentation/settings/widgets/emoji_picker/emoji_menu_item.dart';
+import 'package:appflowy_editor/appflowy_editor.dart';
+import 'package:easy_localization/easy_localization.dart';
+import 'package:flutter/material.dart';
+
+import 'slash_menu_item_builder.dart';
+
+final _keywords = [
+ 'emoji',
+ 'reaction',
+ 'emoticon',
+];
+
+// emoji menu item
+SelectionMenuItem emojiSlashMenuItem = SelectionMenuItem(
+ getName: () => LocaleKeys.document_slashMenu_name_emoji.tr(),
+ keywords: _keywords,
+ handler: (editorState, menuService, context) => editorState.showEmojiPicker(
+ context,
+ menuService: menuService,
+ ),
+ nameBuilder: slashMenuItemNameBuilder,
+ icon: (_, isSelected, style) => SelectableSvgWidget(
+ data: FlowySvgs.slash_menu_icon_emoji_picker_s,
+ isSelected: isSelected,
+ style: style,
+ ),
+);
+
+extension on EditorState {
+ Future<void> showEmojiPicker(
+ BuildContext context, {
+ required SelectionMenuService menuService,
+ }) async {
+ final container = Overlay.of(context);
+ menuService.dismiss();
+ showEmojiPickerMenu(
+ container,
+ this,
+ menuService.alignment,
+ menuService.offset,
+ );
+ }
+}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/file_item.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/file_item.dart
new file mode 100644
index 0000000000..64c529bee8
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/file_item.dart
@@ -0,0 +1,42 @@
+import 'package:appflowy/generated/flowy_svgs.g.dart';
+import 'package:appflowy/generated/locale_keys.g.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/base/selectable_svg_widget.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';
+import 'package:flutter/material.dart';
+
+import 'slash_menu_items.dart';
+
+final _keywords = [
+ 'file upload',
+ 'pdf',
+ 'zip',
+ 'archive',
+ 'upload',
+ 'attachment',
+];
+
+// file menu item
+SelectionMenuItem fileSlashMenuItem = SelectionMenuItem(
+ getName: () => LocaleKeys.document_slashMenu_name_file.tr(),
+ keywords: _keywords,
+ handler: (editorState, _, __) async => editorState.insertFileBlock(),
+ nameBuilder: slashMenuItemNameBuilder,
+ icon: (_, isSelected, style) => SelectableSvgWidget(
+ data: FlowySvgs.slash_menu_icon_file_s,
+ isSelected: isSelected,
+ style: style,
+ ),
+);
+
+extension on EditorState {
+ Future<void> insertFileBlock() async {
+ final fileGlobalKey = GlobalKey<FileBlockComponentState>();
+ await insertEmptyFileBlock(fileGlobalKey);
+
+ WidgetsBinding.instance.addPostFrameCallback((_) {
+ fileGlobalKey.currentState?.controller.show();
+ });
+ }
+}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/heading_items.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/heading_items.dart
new file mode 100644
index 0000000000..115ef22abe
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/heading_items.dart
@@ -0,0 +1,139 @@
+import 'package:appflowy/generated/flowy_svgs.g.dart';
+import 'package:appflowy/generated/locale_keys.g.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/base/selectable_svg_widget.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';
+
+import 'slash_menu_item_builder.dart';
+
+final _h1Keywords = [
+ 'heading 1',
+ 'h1',
+ 'heading1',
+];
+final _h2Keywords = [
+ 'heading 2',
+ 'h2',
+ 'heading2',
+];
+final _h3Keywords = [
+ 'heading 3',
+ 'h3',
+ 'heading3',
+];
+
+final _toggleH1Keywords = [
+ 'toggle heading 1',
+ 'toggle h1',
+ 'toggle heading1',
+ 'toggleheading1',
+ 'toggleh1',
+];
+final _toggleH2Keywords = [
+ 'toggle heading 2',
+ 'toggle h2',
+ 'toggle heading2',
+ 'toggleheading2',
+ 'toggleh2',
+];
+final _toggleH3Keywords = [
+ 'toggle heading 3',
+ 'toggle h3',
+ 'toggle heading3',
+ 'toggleheading3',
+ 'toggleh3',
+];
+
+// heading 1 - 3 menu items
+final heading1SlashMenuItem = SelectionMenuItem(
+ getName: () => LocaleKeys.document_slashMenu_name_heading1.tr(),
+ keywords: _h1Keywords,
+ handler: (editorState, _, __) async => insertHeadingAfterSelection(
+ editorState,
+ 1,
+ ),
+ nameBuilder: slashMenuItemNameBuilder,
+ icon: (editorState, isSelected, style) => SelectableSvgWidget(
+ data: FlowySvgs.slash_menu_icon_h1_s,
+ isSelected: isSelected,
+ style: style,
+ ),
+);
+
+final heading2SlashMenuItem = SelectionMenuItem(
+ getName: () => LocaleKeys.document_slashMenu_name_heading2.tr(),
+ keywords: _h2Keywords,
+ handler: (editorState, _, __) async => insertHeadingAfterSelection(
+ editorState,
+ 2,
+ ),
+ nameBuilder: slashMenuItemNameBuilder,
+ icon: (editorState, isSelected, style) => SelectableSvgWidget(
+ data: FlowySvgs.slash_menu_icon_h2_s,
+ isSelected: isSelected,
+ style: style,
+ ),
+);
+
+final heading3SlashMenuItem = SelectionMenuItem(
+ getName: () => LocaleKeys.document_slashMenu_name_heading3.tr(),
+ keywords: _h3Keywords,
+ handler: (editorState, _, __) async => insertHeadingAfterSelection(
+ editorState,
+ 3,
+ ),
+ nameBuilder: slashMenuItemNameBuilder,
+ icon: (editorState, isSelected, style) => SelectableSvgWidget(
+ data: FlowySvgs.slash_menu_icon_h3_s,
+ isSelected: isSelected,
+ style: style,
+ ),
+);
+
+// toggle heading 1 menu item
+// heading 1 - 3 menu items
+final toggleHeading1SlashMenuItem = SelectionMenuItem(
+ getName: () => LocaleKeys.document_slashMenu_name_toggleHeading1.tr(),
+ keywords: _toggleH1Keywords,
+ handler: (editorState, _, __) async => insertNodeAfterSelection(
+ editorState,
+ toggleHeadingNode(),
+ ),
+ nameBuilder: slashMenuItemNameBuilder,
+ icon: (editorState, isSelected, style) => SelectableSvgWidget(
+ data: FlowySvgs.toggle_heading1_s,
+ isSelected: isSelected,
+ style: style,
+ ),
+);
+
+final toggleHeading2SlashMenuItem = SelectionMenuItem(
+ getName: () => LocaleKeys.document_slashMenu_name_toggleHeading2.tr(),
+ keywords: _toggleH2Keywords,
+ handler: (editorState, _, __) async => insertNodeAfterSelection(
+ editorState,
+ toggleHeadingNode(level: 2),
+ ),
+ nameBuilder: slashMenuItemNameBuilder,
+ icon: (editorState, isSelected, style) => SelectableSvgWidget(
+ data: FlowySvgs.toggle_heading2_s,
+ isSelected: isSelected,
+ style: style,
+ ),
+);
+
+final toggleHeading3SlashMenuItem = SelectionMenuItem(
+ getName: () => LocaleKeys.document_slashMenu_name_toggleHeading3.tr(),
+ keywords: _toggleH3Keywords,
+ handler: (editorState, _, __) async => insertNodeAfterSelection(
+ editorState,
+ toggleHeadingNode(level: 3),
+ ),
+ nameBuilder: slashMenuItemNameBuilder,
+ icon: (editorState, isSelected, style) => SelectableSvgWidget(
+ data: FlowySvgs.toggle_heading3_s,
+ isSelected: isSelected,
+ style: style,
+ ),
+);
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/image_item.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/image_item.dart
new file mode 100644
index 0000000000..f0ce852e41
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/image_item.dart
@@ -0,0 +1,42 @@
+import 'package:appflowy/generated/flowy_svgs.g.dart';
+import 'package:appflowy/generated/locale_keys.g.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/base/selectable_svg_widget.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/image/image_placeholder.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';
+import 'package:flutter/material.dart';
+
+import 'slash_menu_item_builder.dart';
+
+final _keywords = [
+ 'image',
+ 'photo',
+ 'picture',
+ 'img',
+];
+
+/// Image menu item
+final imageSlashMenuItem = SelectionMenuItem(
+ getName: () => LocaleKeys.document_slashMenu_name_image.tr(),
+ keywords: _keywords,
+ handler: (editorState, _, __) async => editorState.insertImageBlock(),
+ nameBuilder: slashMenuItemNameBuilder,
+ icon: (editorState, isSelected, style) => SelectableSvgWidget(
+ data: FlowySvgs.slash_menu_icon_image_s,
+ isSelected: isSelected,
+ style: style,
+ ),
+);
+
+extension on EditorState {
+ Future<void> insertImageBlock() async {
+ // use the key to retrieve the state of the image block to show the popover automatically
+ final imagePlaceholderKey = GlobalKey<ImagePlaceholderState>();
+ await insertEmptyImageBlock(imagePlaceholderKey);
+
+ WidgetsBinding.instance.addPostFrameCallback((_) {
+ imagePlaceholderKey.currentState?.controller.show();
+ });
+ }
+}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/math_equation_item.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/math_equation_item.dart
new file mode 100644
index 0000000000..3274e4ab95
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/math_equation_item.dart
@@ -0,0 +1,42 @@
+import 'package:appflowy/generated/flowy_svgs.g.dart';
+import 'package:appflowy/generated/locale_keys.g.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/base/selectable_svg_widget.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';
+import 'package:flutter/material.dart';
+
+import 'slash_menu_item_builder.dart';
+
+final _keywords = [
+ 'tex',
+ 'latex',
+ 'katex',
+ 'math equation',
+ 'formula',
+];
+
+// math equation
+SelectionMenuItem mathEquationSlashMenuItem = SelectionMenuItem.node(
+ getName: () => LocaleKeys.document_slashMenu_name_mathEquation.tr(),
+ keywords: _keywords,
+ nodeBuilder: (editorState, _) => mathEquationNode(),
+ replace: (_, node) => node.delta?.isEmpty ?? false,
+ updateSelection: (editorState, path, __, ___) {
+ WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
+ final mathEquationState =
+ editorState.getNodeAtPath(path)?.key.currentState;
+ if (mathEquationState != null &&
+ mathEquationState is MathEquationBlockComponentWidgetState) {
+ mathEquationState.showEditingDialog();
+ }
+ });
+ return null;
+ },
+ nameBuilder: slashMenuItemNameBuilder,
+ iconBuilder: (editorState, isSelected, style) => SelectableSvgWidget(
+ data: FlowySvgs.slash_menu_icon_math_equation_s,
+ isSelected: isSelected,
+ style: style,
+ ),
+);
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/numbered_list_item.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/numbered_list_item.dart
new file mode 100644
index 0000000000..2bb04156d6
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/numbered_list_item.dart
@@ -0,0 +1,29 @@
+import 'package:appflowy/generated/flowy_svgs.g.dart';
+import 'package:appflowy/generated/locale_keys.g.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/base/selectable_svg_widget.dart';
+import 'package:appflowy_editor/appflowy_editor.dart';
+import 'package:easy_localization/easy_localization.dart';
+
+import 'slash_menu_item_builder.dart';
+
+final _keywords = [
+ 'numbered list',
+ 'list',
+ 'ordered list',
+ 'ol',
+];
+
+/// Numbered list menu item
+final numberedListSlashMenuItem = SelectionMenuItem(
+ getName: () => LocaleKeys.document_slashMenu_name_numberedList.tr(),
+ keywords: _keywords,
+ handler: (editorState, _, __) async => insertNumberedListAfterSelection(
+ editorState,
+ ),
+ nameBuilder: slashMenuItemNameBuilder,
+ icon: (editorState, isSelected, style) => SelectableSvgWidget(
+ data: FlowySvgs.slash_menu_icon_numbered_list_s,
+ isSelected: isSelected,
+ style: style,
+ ),
+);
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/outline_item.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/outline_item.dart
new file mode 100644
index 0000000000..795f27bc0f
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/outline_item.dart
@@ -0,0 +1,75 @@
+import 'package:appflowy/generated/locale_keys.g.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';
+import 'package:flutter/material.dart';
+
+import 'slash_menu_item_builder.dart';
+
+final _keywords = [
+ 'outline',
+ 'table of contents',
+ 'toc',
+ 'tableofcontents',
+];
+
+/// Outline menu item
+SelectionMenuItem outlineSlashMenuItem = SelectionMenuItem(
+ getName: LocaleKeys.document_selectionMenu_outline.tr,
+ keywords: _keywords,
+ handler: (editorState, _, __) async => editorState.insertOutline(),
+ nameBuilder: slashMenuItemNameBuilder,
+ icon: (editorState, onSelected, style) {
+ return Icon(
+ Icons.list_alt,
+ color: onSelected
+ ? style.selectionMenuItemSelectedIconColor
+ : style.selectionMenuItemIconColor,
+ size: 16.0,
+ );
+ },
+);
+
+extension on EditorState {
+ Future<void> insertOutline() async {
+ final selection = this.selection;
+ if (selection == null || !selection.isCollapsed) {
+ return;
+ }
+
+ final node = getNodeAtPath(selection.end.path);
+ final delta = node?.delta;
+ if (node == null || delta == null) {
+ return;
+ }
+
+ final transaction = this.transaction;
+ final bReplace = node.delta?.isEmpty ?? false;
+
+ //default insert after
+ var path = node.path.next;
+ if (bReplace) {
+ path = node.path;
+ }
+
+ final nextNode = 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);
+ }
+
+ await apply(transaction);
+ }
+}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/paragraph_item.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/paragraph_item.dart
new file mode 100644
index 0000000000..5ad8df64b0
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/paragraph_item.dart
@@ -0,0 +1,28 @@
+import 'package:appflowy/generated/flowy_svgs.g.dart';
+import 'package:appflowy/generated/locale_keys.g.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/base/selectable_svg_widget.dart';
+import 'package:appflowy_editor/appflowy_editor.dart';
+import 'package:easy_localization/easy_localization.dart';
+
+import 'slash_menu_item_builder.dart';
+
+final _keywords = [
+ 'text',
+ 'paragraph',
+];
+
+// paragraph menu item
+final paragraphSlashMenuItem = SelectionMenuItem(
+ getName: () => LocaleKeys.document_slashMenu_name_text.tr(),
+ keywords: _keywords,
+ handler: (editorState, _, __) async => insertNodeAfterSelection(
+ editorState,
+ paragraphNode(),
+ ),
+ nameBuilder: slashMenuItemNameBuilder,
+ icon: (editorState, isSelected, style) => SelectableSvgWidget(
+ data: FlowySvgs.slash_menu_icon_text_s,
+ isSelected: isSelected,
+ style: style,
+ ),
+);
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/photo_gallery_item.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/photo_gallery_item.dart
new file mode 100644
index 0000000000..95ef1a123b
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/photo_gallery_item.dart
@@ -0,0 +1,42 @@
+import 'package:appflowy/generated/flowy_svgs.g.dart';
+import 'package:appflowy/generated/locale_keys.g.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/base/selectable_svg_widget.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/image/image_placeholder.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';
+import 'package:flutter/material.dart';
+
+import 'slash_menu_items.dart';
+
+final _keywords = [
+ LocaleKeys.document_plugins_photoGallery_imageKeyword.tr(),
+ LocaleKeys.document_plugins_photoGallery_imageGalleryKeyword.tr(),
+ LocaleKeys.document_plugins_photoGallery_photoKeyword.tr(),
+ LocaleKeys.document_plugins_photoGallery_photoBrowserKeyword.tr(),
+ LocaleKeys.document_plugins_photoGallery_galleryKeyword.tr(),
+];
+
+// photo gallery menu item
+SelectionMenuItem photoGallerySlashMenuItem = SelectionMenuItem(
+ getName: () => LocaleKeys.document_slashMenu_name_photoGallery.tr(),
+ keywords: _keywords,
+ handler: (editorState, _, __) async => editorState.insertPhotoGalleryBlock(),
+ nameBuilder: slashMenuItemNameBuilder,
+ icon: (_, isSelected, style) => SelectableSvgWidget(
+ data: FlowySvgs.slash_menu_icon_photo_gallery_s,
+ isSelected: isSelected,
+ style: style,
+ ),
+);
+
+extension on EditorState {
+ Future<void> insertPhotoGalleryBlock() async {
+ final imagePlaceholderKey = GlobalKey<ImagePlaceholderState>();
+ await insertEmptyMultiImageBlock(imagePlaceholderKey);
+
+ WidgetsBinding.instance.addPostFrameCallback(
+ (_) => imagePlaceholderKey.currentState?.controller.show(),
+ );
+ }
+}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/quote_item.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/quote_item.dart
new file mode 100644
index 0000000000..7c7f887a67
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/quote_item.dart
@@ -0,0 +1,27 @@
+import 'package:appflowy/generated/flowy_svgs.g.dart';
+import 'package:appflowy/generated/locale_keys.g.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/base/selectable_svg_widget.dart';
+import 'package:appflowy_editor/appflowy_editor.dart';
+import 'package:easy_localization/easy_localization.dart';
+
+import 'slash_menu_item_builder.dart';
+
+final _keywords = [
+ 'quote',
+ 'refer',
+ 'blockquote',
+ 'citation',
+];
+
+/// Quote menu item
+final quoteSlashMenuItem = SelectionMenuItem(
+ getName: () => LocaleKeys.document_slashMenu_name_quote.tr(),
+ keywords: _keywords,
+ handler: (editorState, _, __) async => insertQuoteAfterSelection(editorState),
+ nameBuilder: slashMenuItemNameBuilder,
+ icon: (editorState, isSelected, style) => SelectableSvgWidget(
+ data: FlowySvgs.slash_menu_icon_quote_s,
+ isSelected: isSelected,
+ style: style,
+ ),
+);
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/simple_table_item.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/simple_table_item.dart
new file mode 100644
index 0000000000..1b05d70091
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/simple_table_item.dart
@@ -0,0 +1,74 @@
+import 'package:appflowy/generated/flowy_svgs.g.dart';
+import 'package:appflowy/generated/locale_keys.g.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/base/selectable_svg_widget.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';
+
+import 'slash_menu_item_builder.dart';
+
+final _keywords = [
+ 'table',
+ 'rows',
+ 'columns',
+ 'data',
+];
+
+// table menu item
+SelectionMenuItem tableSlashMenuItem = SelectionMenuItem(
+ getName: () => LocaleKeys.document_slashMenu_name_table.tr(),
+ keywords: _keywords,
+ handler: (editorState, _, __) async => editorState.insertSimpleTable(),
+ nameBuilder: slashMenuItemNameBuilder,
+ icon: (_, isSelected, style) => SelectableSvgWidget(
+ data: FlowySvgs.slash_menu_icon_simple_table_s,
+ isSelected: isSelected,
+ style: style,
+ ),
+);
+
+extension on EditorState {
+ Future<void> insertSimpleTable() async {
+ final selection = this.selection;
+ if (selection == null || !selection.isCollapsed) {
+ return;
+ }
+
+ final currentNode = getNodeAtPath(selection.end.path);
+ if (currentNode == null) {
+ return;
+ }
+
+ // create a simple table with 2 columns and 2 rows
+ final tableNode = createSimpleTableBlockNode(
+ columnCount: 2,
+ rowCount: 2,
+ );
+
+ final transaction = this.transaction;
+ final delta = currentNode.delta;
+ if (delta != null && delta.isEmpty) {
+ final path = selection.end.path;
+ transaction
+ ..insertNode(path, tableNode)
+ ..deleteNode(currentNode);
+ transaction.afterSelection = Selection.collapsed(
+ Position(
+ // table -> row -> cell -> paragraph
+ path: path + [0, 0, 0],
+ ),
+ );
+ } else {
+ final path = selection.end.path.next;
+ transaction.insertNode(path, tableNode);
+ transaction.afterSelection = Selection.collapsed(
+ Position(
+ // table -> row -> cell -> paragraph
+ path: path + [0, 0, 0],
+ ),
+ );
+ }
+
+ await apply(transaction);
+ }
+}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/slash_menu_item_builder.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/slash_menu_item_builder.dart
new file mode 100644
index 0000000000..85f8a6895b
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/slash_menu_item_builder.dart
@@ -0,0 +1,89 @@
+import 'package:appflowy/generated/flowy_svgs.g.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/base/selectable_svg_widget.dart';
+import 'package:appflowy_editor/appflowy_editor.dart';
+import 'package:flowy_infra_ui/style_widget/text.dart';
+import 'package:flutter/material.dart';
+
+/// Builder function for the slash menu item.
+Widget slashMenuItemNameBuilder(
+ String name,
+ SelectionMenuStyle style,
+ bool isSelected,
+) {
+ return SlashMenuItemNameBuilder(
+ name: name,
+ style: style,
+ isSelected: isSelected,
+ );
+}
+
+Widget slashMenuItemIconBuilder(
+ FlowySvgData data,
+ bool isSelected,
+ SelectionMenuStyle style,
+) {
+ return SelectableSvgWidget(
+ data: data,
+ isSelected: isSelected,
+ style: style,
+ );
+}
+
+/// Build the name of the slash menu item.
+class SlashMenuItemNameBuilder extends StatelessWidget {
+ const SlashMenuItemNameBuilder({
+ super.key,
+ required this.name,
+ required this.style,
+ required this.isSelected,
+ });
+
+ /// The name of the slash menu item.
+ final String name;
+
+ /// The style of the slash menu item.
+ final SelectionMenuStyle style;
+
+ /// Whether the slash menu item is selected.
+ final bool isSelected;
+
+ @override
+ Widget build(BuildContext context) {
+ return FlowyText.regular(
+ name,
+ fontSize: 12.0,
+ figmaLineHeight: 15.0,
+ color: isSelected
+ ? style.selectionMenuItemSelectedTextColor
+ : style.selectionMenuItemTextColor,
+ );
+ }
+}
+
+/// Build the icon of the slash menu item.
+class SlashMenuIconBuilder extends StatelessWidget {
+ const SlashMenuIconBuilder({
+ super.key,
+ required this.data,
+ required this.isSelected,
+ required this.style,
+ });
+
+ /// The data of the icon.
+ final FlowySvgData data;
+
+ /// Whether the slash menu item is selected.
+ final bool isSelected;
+
+ /// The style of the slash menu item.
+ final SelectionMenuStyle style;
+
+ @override
+ Widget build(BuildContext context) {
+ return SelectableSvgWidget(
+ data: data,
+ isSelected: isSelected,
+ style: style,
+ );
+ }
+}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/slash_menu_items.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/slash_menu_items.dart
new file mode 100644
index 0000000000..ee76bc0ea3
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/slash_menu_items.dart
@@ -0,0 +1,22 @@
+export 'ai_writer_item.dart';
+export 'bulleted_list_item.dart';
+export 'callout_item.dart';
+export 'code_block_item.dart';
+export 'database_items.dart';
+export 'date_item.dart';
+export 'divider_item.dart';
+export 'emoji_item.dart';
+export 'file_item.dart';
+export 'heading_items.dart';
+export 'image_item.dart';
+export 'math_equation_item.dart';
+export 'numbered_list_item.dart';
+export 'outline_item.dart';
+export 'paragraph_item.dart';
+export 'photo_gallery_item.dart';
+export 'quote_item.dart';
+export 'simple_table_item.dart';
+export 'slash_menu_item_builder.dart';
+export 'sub_page_item.dart';
+export 'todo_list_item.dart';
+export 'toggle_list_item.dart';
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/sub_page_item.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/sub_page_item.dart
new file mode 100644
index 0000000000..bc7f7e46b4
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/sub_page_item.dart
@@ -0,0 +1,47 @@
+import 'package:appflowy/generated/flowy_svgs.g.dart';
+import 'package:appflowy/generated/locale_keys.g.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/base/selectable_svg_widget.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_editor/appflowy_editor.dart';
+import 'package:easy_localization/easy_localization.dart';
+import 'package:flutter/material.dart';
+import 'package:flutter_bloc/flutter_bloc.dart';
+
+import 'slash_menu_items.dart';
+
+final _keywords = [
+ LocaleKeys.document_slashMenu_subPage_keyword1.tr(),
+ LocaleKeys.document_slashMenu_subPage_keyword2.tr(),
+ LocaleKeys.document_slashMenu_subPage_keyword3.tr(),
+ LocaleKeys.document_slashMenu_subPage_keyword4.tr(),
+ LocaleKeys.document_slashMenu_subPage_keyword5.tr(),
+ LocaleKeys.document_slashMenu_subPage_keyword6.tr(),
+ LocaleKeys.document_slashMenu_subPage_keyword7.tr(),
+ LocaleKeys.document_slashMenu_subPage_keyword8.tr(),
+];
+
+// Sub-page menu item
+SelectionMenuItem subPageSlashMenuItem = SelectionMenuItem.node(
+ getName: () => LocaleKeys.document_slashMenu_subPage_name.tr(),
+ keywords: _keywords,
+ 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(),
+ nameBuilder: slashMenuItemNameBuilder,
+ iconBuilder: (_, isSelected, style) => SelectableSvgWidget(
+ data: FlowySvgs.insert_document_s,
+ isSelected: isSelected,
+ style: style,
+ ),
+);
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/todo_list_item.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/todo_list_item.dart
new file mode 100644
index 0000000000..74ffa7e075
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/todo_list_item.dart
@@ -0,0 +1,29 @@
+import 'package:appflowy/generated/flowy_svgs.g.dart';
+import 'package:appflowy/generated/locale_keys.g.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/base/selectable_svg_widget.dart';
+import 'package:appflowy_editor/appflowy_editor.dart';
+import 'package:easy_localization/easy_localization.dart';
+
+import 'slash_menu_item_builder.dart';
+
+final _keywords = [
+ 'checkbox',
+ 'todo',
+ 'list',
+ 'to-do',
+ 'task',
+];
+
+final todoListSlashMenuItem = SelectionMenuItem(
+ getName: () => LocaleKeys.document_slashMenu_name_todoList.tr(),
+ keywords: _keywords,
+ handler: (editorState, _, __) async => insertCheckboxAfterSelection(
+ editorState,
+ ),
+ nameBuilder: slashMenuItemNameBuilder,
+ icon: (editorState, isSelected, style) => SelectableSvgWidget(
+ data: FlowySvgs.slash_menu_icon_checkbox_s,
+ isSelected: isSelected,
+ style: style,
+ ),
+);
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/toggle_list_item.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/toggle_list_item.dart
new file mode 100644
index 0000000000..d93dd3c738
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items/toggle_list_item.dart
@@ -0,0 +1,29 @@
+import 'package:appflowy/generated/flowy_svgs.g.dart';
+import 'package:appflowy/generated/locale_keys.g.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/base/selectable_svg_widget.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';
+
+import 'slash_menu_item_builder.dart';
+
+final _keywords = [
+ 'collapsed list',
+ 'toggle list',
+ 'list',
+ 'dropdown',
+];
+
+// toggle menu item
+SelectionMenuItem toggleListSlashMenuItem = SelectionMenuItem.node(
+ getName: () => LocaleKeys.document_slashMenu_name_toggleList.tr(),
+ keywords: _keywords,
+ nodeBuilder: (editorState, _) => toggleListBlockNode(),
+ replace: (_, node) => node.delta?.isEmpty ?? false,
+ nameBuilder: slashMenuItemNameBuilder,
+ iconBuilder: (editorState, isSelected, style) => SelectableSvgWidget(
+ data: FlowySvgs.slash_menu_icon_toggle_s,
+ isSelected: isSelected,
+ style: style,
+ ),
+);
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items_builder.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items_builder.dart
new file mode 100644
index 0000000000..3e9bdef355
--- /dev/null
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items_builder.dart
@@ -0,0 +1,179 @@
+import 'package:appflowy/plugins/document/application/document_bloc.dart';
+import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';
+import 'package:appflowy_editor/appflowy_editor.dart';
+
+import 'slash_menu_items/slash_menu_items.dart';
+
+/// Build slash menu items
+///
+List<SelectionMenuItem> slashMenuItemsBuilder({
+ bool isLocalMode = false,
+ DocumentBloc? documentBloc,
+ EditorState? editorState,
+ Node? node,
+}) {
+ final isInTable = node != null && node.parentTableCellNode != null;
+
+ if (isInTable) {
+ return _simpleTableSlashMenuItems();
+ } else {
+ return _defaultSlashMenuItems(
+ isLocalMode: isLocalMode,
+ documentBloc: documentBloc,
+ );
+ }
+}
+
+/// The default slash menu items are used in the text-based block.
+///
+/// Except for the simple table block, the slash menu items in the table block are
+/// built by the `tableSlashMenuItem` function.
+/// If in local mode, disable the ai writer feature
+///
+/// The linked database relies on the documentBloc, so it's required to pass in
+/// the documentBloc when building the slash menu items. If the documentBloc is
+/// not provided, the linked database items will be disabled.
+///
+///
+List<SelectionMenuItem> _defaultSlashMenuItems({
+ bool isLocalMode = false,
+ DocumentBloc? documentBloc,
+}) {
+ return [
+ // disable ai writer in local mode
+ if (!isLocalMode) aiWriterSlashMenuItem,
+
+ paragraphSlashMenuItem,
+
+ // heading 1-3
+ heading1SlashMenuItem,
+ heading2SlashMenuItem,
+ heading3SlashMenuItem,
+
+ // image
+ imageSlashMenuItem,
+
+ // list
+ bulletedListSlashMenuItem,
+ numberedListSlashMenuItem,
+ todoListSlashMenuItem,
+
+ // divider
+ dividerSlashMenuItem,
+
+ // quote
+ quoteSlashMenuItem,
+
+ // simple table
+ tableSlashMenuItem,
+
+ // link to page
+ linkToPageSlashMenuItem,
+
+ // grid
+ if (documentBloc != null) gridSlashMenuItem(documentBloc),
+ referencedGridSlashMenuItem,
+
+ // kanban
+ if (documentBloc != null) kanbanSlashMenuItem(documentBloc),
+ referencedKanbanSlashMenuItem,
+
+ // calendar
+ if (documentBloc != null) calendarSlashMenuItem(documentBloc),
+ referencedCalendarSlashMenuItem,
+
+ // callout
+ calloutSlashMenuItem,
+
+ // outline
+ outlineSlashMenuItem,
+
+ // math equation
+ mathEquationSlashMenuItem,
+
+ // code block
+ codeBlockSlashMenuItem,
+
+ // toggle list - toggle headings
+ toggleListSlashMenuItem,
+ toggleHeading1SlashMenuItem,
+ toggleHeading2SlashMenuItem,
+ toggleHeading3SlashMenuItem,
+
+ // emoji
+ emojiSlashMenuItem,
+
+ // date or reminder
+ dateOrReminderSlashMenuItem,
+
+ // photo gallery
+ photoGallerySlashMenuItem,
+
+ // file
+ fileSlashMenuItem,
+
+ // sub page
+ subPageSlashMenuItem,
+ ];
+}
+
+/// The slash menu items in the simple table block.
+///
+/// There're some blocks should be excluded in the slash menu items.
+///
+/// - Database Items
+/// - Image Gallery
+List<SelectionMenuItem> _simpleTableSlashMenuItems() {
+ return [
+ paragraphSlashMenuItem,
+
+ // heading 1-3
+ heading1SlashMenuItem,
+ heading2SlashMenuItem,
+ heading3SlashMenuItem,
+
+ // image
+ imageSlashMenuItem,
+
+ // list
+ bulletedListSlashMenuItem,
+ numberedListSlashMenuItem,
+ todoListSlashMenuItem,
+
+ // divider
+ dividerSlashMenuItem,
+
+ // quote
+ quoteSlashMenuItem,
+
+ // link to page
+ linkToPageSlashMenuItem,
+
+ // callout
+ calloutSlashMenuItem,
+
+ // math equation
+ mathEquationSlashMenuItem,
+
+ // code block
+ codeBlockSlashMenuItem,
+
+ // toggle list - toggle headings
+ toggleListSlashMenuItem,
+ toggleHeading1SlashMenuItem,
+ toggleHeading2SlashMenuItem,
+ toggleHeading3SlashMenuItem,
+
+ // emoji
+ emojiSlashMenuItem,
+
+ // date or reminder
+ dateOrReminderSlashMenuItem,
+
+ // file
+ fileSlashMenuItem,
+
+ // sub page
+ subPageSlashMenuItem,
+ ];
+}
diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_component.dart
index 3e9378d8c1..9f26f7037f 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_component.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_component.dart
@@ -330,7 +330,7 @@ class _ToggleListBlockComponentWidgetState
return result.updateTextStyle(placeholderTextStyle);
},
textDirection: textDirection,
- textAlign: alignment?.toTextAlign,
+ textAlign: alignment?.toTextAlign ?? textAlign,
cursorColor: editorState.editorStyle.cursorColor,
selectionColor: editorState.editorStyle.selectionColor,
);
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 b3700d6e71..de4d431a08 100644
--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_style.dart
+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_style.dart
@@ -244,6 +244,24 @@ class EditorStyleCustomizer {
);
}
+ TextStyle subPageBlockTextStyleBuilder() {
+ if (UniversalPlatform.isMobile) {
+ final pageStyle = context.read<DocumentPageStyleBloc>().state;
+ final fontSize = pageStyle.fontLayout.fontSize;
+ final fontFamily = pageStyle.fontFamily ?? defaultFontFamily;
+ final baseTextStyle = this.baseTextStyle(fontFamily);
+ return baseTextStyle.copyWith(
+ fontSize: fontSize,
+ );
+ } else {
+ final fontSize = context.read<DocumentAppearanceCubit>().state.fontSize;
+ return baseTextStyle(null).copyWith(
+ fontSize: fontSize,
+ height: 1.5,
+ );
+ }
+ }
+
SelectionMenuStyle selectionMenuStyleBuilder() {
final theme = Theme.of(context);
final afThemeExtension = AFThemeExtension.of(context);
diff --git a/frontend/appflowy_flutter/pubspec.lock b/frontend/appflowy_flutter/pubspec.lock
index 9d1b49f159..98fc4c5359 100644
--- a/frontend/appflowy_flutter/pubspec.lock
+++ b/frontend/appflowy_flutter/pubspec.lock
@@ -61,8 +61,8 @@ packages:
dependency: "direct main"
description:
path: "."
- ref: "7a7a8ae"
- resolved-ref: "7a7a8ae3e73790903a19108933c97a3c7f6255e2"
+ ref: c68e5f6
+ resolved-ref: c68e5f6c585205083e27e875b822656425b2853f
url: "https://github.com/AppFlowy-IO/appflowy-editor.git"
source: git
version: "4.0.0"
diff --git a/frontend/appflowy_flutter/pubspec.yaml b/frontend/appflowy_flutter/pubspec.yaml
index aafd320014..6d575a1245 100644
--- a/frontend/appflowy_flutter/pubspec.yaml
+++ b/frontend/appflowy_flutter/pubspec.yaml
@@ -174,7 +174,7 @@ dependency_overrides:
appflowy_editor:
git:
url: https://github.com/AppFlowy-IO/appflowy-editor.git
- ref: "7a7a8ae"
+ ref: "c68e5f6"
appflowy_editor_plugins:
git: