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.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
feat: support table block on mobile (#7001)
Lucas17c116a53b6a
diff --git a/frontend/appflowy_flutter/ios/Podfile.lock b/frontend/appflowy_flutter/ios/Podfile.lockindex 3089e3f56e..ac6f338698 100644--- a/frontend/appflowy_flutter/ios/Podfile.lock+++ b/frontend/appflowy_flutter/ios/Podfile.lock@@ -88,6 +88,8 @@ PODS:- Toast (4.0.0)- url_launcher_ios (0.0.1):- Flutter+ - webview_flutter_wkwebview (0.0.1):+ - FlutterDEPENDENCIES:- app_links (from `.symlinks/plugins/app_links/ios`)@@ -112,6 +114,7 @@ DEPENDENCIES:- sqflite (from `.symlinks/plugins/sqflite/darwin`)- super_native_extensions (from `.symlinks/plugins/super_native_extensions/ios`)- url_launcher_ios (from `.symlinks/plugins/url_launcher_ios/ios`)+ - webview_flutter_wkwebview (from `.symlinks/plugins/webview_flutter_wkwebview/ios`)SPEC REPOS:trunk:@@ -168,6 +171,8 @@ EXTERNAL SOURCES::path: ".symlinks/plugins/super_native_extensions/ios"url_launcher_ios::path: ".symlinks/plugins/url_launcher_ios/ios"+ webview_flutter_wkwebview:+ :path: ".symlinks/plugins/webview_flutter_wkwebview/ios"SPEC CHECKSUMS:app_links: e70ca16b4b0f88253b3b3660200d4a10b4ea9795@@ -199,6 +204,7 @@ SPEC CHECKSUMS:SwiftyGif: 6c3eafd0ce693cad58bb63d2b2fb9bacb8552780Toast: 91b396c56ee72a5790816f40d3a94dd357abc196url_launcher_ios: 5334b05cef931de560670eeae103fd3e431ac3fe+ webview_flutter_wkwebview: 2a23822e9039b7b1bc52e5add778e5d89ad488d1PODFILE CHECKSUM: d0d9b4ff572d8695c38eb3f9b490f55cdfc57ecadiff --git a/frontend/appflowy_flutter/lib/mobile/application/page_style/document_page_style_bloc.dart b/frontend/appflowy_flutter/lib/mobile/application/page_style/document_page_style_bloc.dartindex 7031f51168..650fbf1d85 100644--- a/frontend/appflowy_flutter/lib/mobile/application/page_style/document_page_style_bloc.dart+++ b/frontend/appflowy_flutter/lib/mobile/application/page_style/document_page_style_bloc.dart@@ -6,7 +6,6 @@ import 'package:appflowy/workspace/application/view/view_ext.dart';import 'package:appflowy/workspace/application/view/view_service.dart';import 'package:appflowy_backend/log.dart';import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';-import 'package:appflowy_result/appflowy_result.dart';import 'package:collection/collection.dart';import 'package:flutter_bloc/flutter_bloc.dart';import 'package:freezed_annotation/freezed_annotation.dart';@@ -26,11 +25,13 @@ class DocumentPageStyleBlocif (view.id.isEmpty) {return;}- final layoutObject =- await ViewBackendService.getView(view.id).fold(- (s) => jsonDecode(s.extra),- (f) => {},- );+ Map layoutObject = {};+ final data = await ViewBackendService.getView(view.id);+ data.onSuccess((s) {+ if (s.extra.isNotEmpty) {+ layoutObject = jsonDecode(s.extra);+ }+ });final fontLayout = _getSelectedFontLayout(layoutObject);final lineHeightLayout = _getSelectedLineHeightLayout(layoutObject,diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/bottom_sheet/bottom_sheet_buttons.dart b/frontend/appflowy_flutter/lib/mobile/presentation/bottom_sheet/bottom_sheet_buttons.dartindex 4d411b7957..8adc2bebec 100644--- a/frontend/appflowy_flutter/lib/mobile/presentation/bottom_sheet/bottom_sheet_buttons.dart+++ b/frontend/appflowy_flutter/lib/mobile/presentation/bottom_sheet/bottom_sheet_buttons.dart@@ -98,7 +98,7 @@ class BottomSheetBackButton extends StatelessWidget {width: 18,height: 18,child: FlowySvg(- FlowySvgs.m_app_bar_back_s,+ FlowySvgs.m_bottom_sheet_back_s,),),),diff --git a/frontend/appflowy_flutter/lib/mobile/presentation/bottom_sheet/show_mobile_bottom_sheet.dart b/frontend/appflowy_flutter/lib/mobile/presentation/bottom_sheet/show_mobile_bottom_sheet.dartindex 1e762f75f7..aa6661a834 100644--- a/frontend/appflowy_flutter/lib/mobile/presentation/bottom_sheet/show_mobile_bottom_sheet.dart+++ b/frontend/appflowy_flutter/lib/mobile/presentation/bottom_sheet/show_mobile_bottom_sheet.dart@@ -211,14 +211,21 @@ class BottomSheetHeader extends StatelessWidget {required this.showDoneButton,this.onRemove,this.onDone,+ this.onBack,+ this.onClose,});+ final String title;+final bool showBackButton;final bool showCloseButton;final bool showRemoveButton;- final String title;final bool showDoneButton;+final VoidCallback? onRemove;+ final VoidCallback? onBack;+ final VoidCallback? onClose;+final void Function(BuildContext context)? onDone;@override@@ -230,14 +237,18 @@ class BottomSheetHeader extends StatelessWidget {child: Stack(children: [if (showBackButton)- const Align(+ Align(alignment: Alignment.centerLeft,- child: BottomSheetBackButton(),+ child: BottomSheetBackButton(+ onTap: onBack,+ ),),if (showCloseButton)- const Align(+ Align(alignment: Alignment.centerLeft,- child: BottomSheetCloseButton(),+ child: BottomSheetCloseButton(+ onTap: onClose,+ ),),if (showRemoveButton)Align(diff --git a/frontend/appflowy_flutter/lib/plugins/document/application/document_validator.dart b/frontend/appflowy_flutter/lib/plugins/document/application/document_validator.dartindex a49a0f9902..8fb2e8008d 100644--- a/frontend/appflowy_flutter/lib/plugins/document/application/document_validator.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/application/document_validator.dart@@ -11,7 +11,7 @@ class DocumentValidator {Future<bool> validate(Transaction transaction) async {// deep copy the document- final root = this.editorState.document.root.copyWith();+ final root = this.editorState.document.root.deepCopy();final dummyDocument = Document(root: root);if (dummyDocument.isEmpty) {return true;@@ -38,7 +38,7 @@ class DocumentValidator {Future<bool> applyTransactionInDummyDocument(Transaction transaction) async {// deep copy the document- final root = this.editorState.document.root.copyWith();+ final root = this.editorState.document.root.deepCopy();final dummyDocument = Document(root: root);if (dummyDocument.isEmpty) {return true;diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_configuration.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_configuration.dartindex 5dd9ab0a7b..f5606dea23 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_configuration.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_configuration.dart@@ -354,7 +354,10 @@ SimpleTableBlockComponentBuilder _buildSimpleTableBlockComponentBuilder(if (UniversalPlatform.isDesktop) {return padding;} else {- return padding.copyWith(right: padding.left);+ return padding.copyWith(+ left: 0,+ right: padding.left,+ );}},);@@ -384,14 +387,11 @@ ParagraphBlockComponentBuilder _buildParagraphBlockComponentBuilder(return ParagraphBlockComponentBuilder(configuration: configuration.copyWith(placeholderText: placeholderText,- 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,+ ),),showPlaceholder: showParagraphPlaceholder,);@@ -797,3 +797,34 @@ SubPageBlockComponentBuilder _buildSubPageBlockComponentBuilder() {return SubPageBlockComponentBuilder(configuration: configuration);}++TextStyle _buildTextStyleInTableCell(+ BuildContext context, {+ required Node node,+ required BlockComponentConfiguration configuration,+}) {+ TextStyle textStyle = configuration.textStyle(node);++ if (node.isInHeaderColumn ||+ node.isInHeaderRow ||+ node.isInBoldColumn ||+ node.isInBoldRow) {+ textStyle = textStyle.copyWith(+ fontWeight: FontWeight.bold,+ );+ }++ final cellTextColor = node.textColorInColumn ?? node.textColorInRow;++ if (cellTextColor != null) {+ textStyle = textStyle.copyWith(+ color: buildEditorCustomizedColor(+ context,+ node,+ cellTextColor,+ ),+ );+ }++ return textStyle;+}diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dartindex af34c169f4..d38b4e8c2c 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_page.dart@@ -574,7 +574,11 @@ Color? buildEditorCustomizedColor(return AFThemeExtension.of(context).tableCellBGColor;}- return null;+ try {+ return colorString.tryToColor();+ } catch (e) {+ return null;+ }}bool showInAnyTextType(EditorState editorState) {diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/block_action_option_cubit.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/block_action_option_cubit.dartindex 2d15479442..52b518a718 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/block_action_option_cubit.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/block_action_option_cubit.dart@@ -107,7 +107,7 @@ class BlockActionOptionCubit extends Cubit<BlockActionOptionState> {}Node _copyBlock(Node node) {- Node copiedNode = node.copyWith();+ Node copiedNode = node.deepCopy();final type = node.type;final builder = blockComponentBuilder[type];@@ -158,7 +158,7 @@ class BlockActionOptionCubit extends Cubit<BlockActionOptionState> {).firstOrNull;if (cell != null) {- newChildren.add(cell.copyWith());+ newChildren.add(cell.deepCopy());} else {newChildren.add(tableCellNode('', i, j),@@ -203,7 +203,7 @@ class BlockActionOptionCubit extends Cubit<BlockActionOptionState> {.firstOrNull;row.add(simpleTableCellBlockNode(- children: [cell?.children.first.copyWith() ?? paragraphNode()],+ children: [cell?.children.first.deepCopy() ?? paragraphNode()],),);}@@ -327,10 +327,10 @@ class BlockActionOptionCubit extends Cubit<BlockActionOptionState> {afterNode = afterNode.copyWith(children: []);afterNode = await _handleSubPageNode(afterNode, node);insertedNode.add(afterNode);- insertedNode.addAll(node.children.map((e) => e.copyWith()));+ insertedNode.addAll(node.children.map((e) => e.deepCopy()));} else if (!EditorOptionActionType.turnInto.supportTypes.contains(node.type)) {- afterNode = node.copyWith();+ afterNode = node.deepCopy();insertedNode.add(afterNode);} else {afterNode = await _handleSubPageNode(afterNode, node);@@ -463,7 +463,7 @@ class BlockActionOptionCubit extends Cubit<BlockActionOptionState> {},children: [...node.children,- ...insertedNodes.map((e) => e.copyWith()),+ ...insertedNodes.map((e) => e.deepCopy()),],);@@ -509,7 +509,7 @@ class BlockActionOptionCubit extends Cubit<BlockActionOptionState> {Log.info('Turn into page');- final insertedNodes = selectedNodes.map((n) => n.copyWith()).toList();+ final insertedNodes = selectedNodes.map((n) => n.deepCopy()).toList();final document = Document.blank()..insert([0], insertedNodes);final name = await _extractNameFromNodes(selectedNodes);diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/drag_to_reorder/draggable_option_button.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/drag_to_reorder/draggable_option_button.dartindex 53a8cd52fe..8ab16aea4c 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/drag_to_reorder/draggable_option_button.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/drag_to_reorder/draggable_option_button.dart@@ -41,7 +41,7 @@ class _DraggableOptionButtonState extends State<DraggableOptionButton> {super.initState();// copy the node to avoid the node in document being updated- node = widget.blockComponentContext.node.copyWith();+ node = widget.blockComponentContext.node.deepCopy();}@overridediff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/drag_to_reorder/draggable_option_button_feedback.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/drag_to_reorder/draggable_option_button_feedback.dartindex 1f04021569..0b6c89599a 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/drag_to_reorder/draggable_option_button_feedback.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/drag_to_reorder/draggable_option_button_feedback.dart@@ -122,7 +122,7 @@ class _DraggleOptionButtonFeedbackState}void _setupLockComponentContext() {- node = widget.blockComponentContext.node.copyWith();+ node = widget.blockComponentContext.node.deepCopy();blockComponentContext = BlockComponentContext(widget.blockComponentContext.buildContext,node,diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/drag_to_reorder/util.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/drag_to_reorder/util.dartindex 1a60d9c49c..ddfb6f3a42 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/drag_to_reorder/util.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/drag_to_reorder/util.dart@@ -65,7 +65,7 @@ Future<void> dragToMoveNode(Log.info('Moving node($node, ${node.path}) to path($newPath)');final transaction = editorState.transaction;- transaction.insertNode(newPath, node.copyWith());+ transaction.insertNode(newPath, node.deepCopy());transaction.deleteNode(node);await editorState.apply(transaction);}diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/mobile_block_action_buttons.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/mobile_block_action_buttons.dartindex 014f4b8669..539dd313b1 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/mobile_block_action_buttons.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/actions/mobile_block_action_buttons.dart@@ -91,7 +91,7 @@ class MobileBlockActionButtons extends StatelessWidget {case BlockActionBottomSheetType.duplicate:transaction.insertNode(node.path.next,- node.copyWith(),+ node.deepCopy(),);break;case BlockActionBottomSheetType.insertAbove:diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/base/markdown_text_robot.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/base/markdown_text_robot.dartindex 4c8ab95d6d..0cc9a50e5c 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/base/markdown_text_robot.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/base/markdown_text_robot.dart@@ -94,7 +94,7 @@ class MarkdownTextRobot {// Convert markdown and deep copy nodesfinal nodes = customMarkdownToDocument(_markdownText).root.children.map(- (node) => node.copyWith(),+ (node) => node.deepCopy(),); // deep copy the nodes to avoid the linked entities being changed.// Insert new nodes at selection startdiff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/code_block/code_block_copy_button.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/code_block/code_block_copy_button.dartindex d2b1c48fa2..cc80119cb9 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/code_block/code_block_copy_button.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/code_block/code_block_copy_button.dart@@ -35,7 +35,7 @@ class _CopyButton extends StatelessWidget {}final document = Document.blank()- ..insert([0], [node.copyWith()])+ ..insert([0], [node.deepCopy()])..toJson();await getIt<ClipboardService>().setData(diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/copy_and_paste/clipboard_service.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/copy_and_paste/clipboard_service.dartindex 1dde980f03..f4aac4fe2c 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/copy_and_paste/clipboard_service.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/copy_and_paste/clipboard_service.dart@@ -8,21 +8,17 @@ import 'package:super_clipboard/super_clipboard.dart';/// Used for in-app copy and paste without losing the format.////// It's a Json string representing the copied editor nodes.-final inAppJsonFormat = CustomValueFormat<String>(+const inAppJsonFormat = CustomValueFormat<String>(applicationId: 'io.appflowy.InAppJsonType',- onDecode: (value, platformType) async {- if (value is PlatformDataProvider) {- final data = await value.getData(platformType);- if (data is List<int>) {- return utf8.decode(data, allowMalformed: true);- }- if (data is String) {- return Uri.decodeFull(data);- }- }- return null;- },- onEncode: (value, platformType) => utf8.encode(value),+ onDecode: _defaultDecode,+ onEncode: _defaultEncode,+);++/// Used for table nodes when coping a row or a column.+const tableJsonFormat = CustomValueFormat<String>(+ applicationId: 'io.appflowy.TableJsonType',+ onDecode: _defaultDecode,+ onEncode: _defaultEncode,);class ClipboardServiceData {@@ -31,12 +27,37 @@ class ClipboardServiceData {this.html,this.image,this.inAppJson,+ this.tableJson,});+ /// The [plainText] is the plain text string.+ ///+ /// It should be used for pasting the plain text from the clipboard.final String? plainText;++ /// The [html] is the html string.+ ///+ /// It should be used for pasting the html from the clipboard.+ /// For example, copy the content in the browser, and paste it in the editor.final String? html;++ /// The [image] is the image data.+ ///+ /// It should be used for pasting the image from the clipboard.+ /// For example, copy the image in the browser or other apps, and paste it in the editor.final (String, Uint8List?)? image;++ /// The [inAppJson] is the json string of the editor nodes.+ ///+ /// It should be used for pasting the content in-app.+ /// For example, pasting the content from document A to document B.final String? inAppJson;++ /// The [tableJson] is the json string of the table nodes.+ ///+ /// It only works for the table nodes when coping a row or a column.+ /// Don't use it for another scenario.+ final String? tableJson;}class ClipboardService {@@ -52,6 +73,7 @@ class ClipboardService {final html = data.html;final inAppJson = data.inAppJson;final image = data.image;+ final tableJson = data.tableJson;final item = DataWriterItem();if (plainText != null) {@@ -63,6 +85,9 @@ class ClipboardService {if (inAppJson != null) {item.add(inAppJsonFormat(inAppJson));}+ if (tableJson != null) {+ item.add(tableJsonFormat(tableJson));+ }if (image != null && image.$2?.isNotEmpty == true) {switch (image.$1) {case 'png':@@ -106,6 +131,7 @@ class ClipboardService {final plainText = await reader.readValue(Formats.plainText);final html = await reader.readValue(Formats.htmlText);final inAppJson = await reader.readValue(inAppJsonFormat);+ final tableJson = await reader.readValue(tableJsonFormat);(String, Uint8List?)? image;if (reader.canProvide(Formats.png)) {image = ('png', await reader.readFile(Formats.png));@@ -122,6 +148,7 @@ class ClipboardService {html: html,image: image,inAppJson: inAppJson,+ tableJson: tableJson,);}}@@ -149,3 +176,22 @@ extension on DataReader {return c.future;}}++/// The default decode function for the clipboard service.+Future<String?> _defaultDecode(Object value, String platformType) async {+ if (value is PlatformDataProvider) {+ final data = await value.getData(platformType);+ if (data is List<int>) {+ return utf8.decode(data, allowMalformed: true);+ }+ if (data is String) {+ return Uri.decodeFull(data);+ }+ }+ return null;+}++/// The default encode function for the clipboard service.+Future<Object> _defaultEncode(String value, String platformType) async {+ return utf8.encode(value);+}diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/copy_and_paste/custom_copy_command.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/copy_and_paste/custom_copy_command.dartindex 6fa9b0b8db..99211920fa 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/copy_and_paste/custom_copy_command.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/copy_and_paste/custom_copy_command.dart@@ -1,11 +1,11 @@import 'dart:convert';import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/clipboard_service.dart';+import 'package:appflowy/plugins/document/presentation/editor_plugins/simple_table/simple_table.dart';import 'package:appflowy/plugins/document/presentation/editor_plugins/sub_page/sub_page_block_component.dart';import 'package:appflowy/startup/startup.dart';import 'package:appflowy_editor/appflowy_editor.dart';import 'package:flutter/material.dart';-import 'package:appflowy/plugins/document/presentation/editor_plugins/simple_table/simple_table.dart';/// Copy.///@@ -50,7 +50,7 @@ KeyEventResult handleCopyCommand(// in app jsonfinal document = Document.blank()- ..insert([0], [_handleNode(node.copyWith(), isCut)]);+ ..insert([0], [_handleNode(node.deepCopy(), isCut)]);inAppJson = jsonEncode(document.toJson());// html@@ -107,7 +107,7 @@ Document _buildCopiedDocument(final document = Document.blank()..insert([0],- filteredNodes.map((e) => e.copyWith()),+ filteredNodes.map((e) => e.deepCopy()),);return document;}@@ -123,7 +123,7 @@ List<Node> _handleSubPageNodes(List<Node> nodes, [bool isCut = false]) {Node _handleNode(Node node, [bool isCut = false]) {if (!isCut) {- return node.copyWith();+ return node.deepCopy();}final newChildren = node.children.map(_handleNode).toList();diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/heading/heading_toolbar_item.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/heading/heading_toolbar_item.dartindex 68fb3305de..c5e1758435 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/heading/heading_toolbar_item.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/heading/heading_toolbar_item.dart@@ -73,7 +73,7 @@ final headingsToolbarItem = ToolbarItem(blockComponentDelta: delta,},);- final children = node.children.map((child) => child.copyWith());+ final children = node.children.map((child) => child.deepCopy());final transaction = editorState.transaction;transaction.insertNodes(diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/aa_menu/_color_list.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/aa_menu/_color_list.dartindex 438aa1264b..d3d4c5daa9 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/aa_menu/_color_list.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/aa_menu/_color_list.dart@@ -83,7 +83,7 @@ class _TextColorAndBackgroundColorState),),const VSpace(6.0),- _TextColors(+ EditorTextColorWidget(selectedColor: selectedTextColor?.tryToColor(),onSelectedColor: (textColor) async {final hex = textColor.alpha == 0 ? null : textColor.toHex();@@ -120,7 +120,7 @@ class _TextColorAndBackgroundColorState),),const VSpace(6.0),- _BackgroundColors(+ EditorBackgroundColors(selectedColor: selectedBackgroundColor?.tryToColor(),onSelectedColor: (backgroundColor) async {final hex =@@ -152,8 +152,9 @@ class _TextColorAndBackgroundColorState}}-class _BackgroundColors extends StatelessWidget {- const _BackgroundColors({+class EditorBackgroundColors extends StatelessWidget {+ const EditorBackgroundColors({+ super.key,this.selectedColor,required this.onSelectedColor,});@@ -225,8 +226,9 @@ class _BackgroundColorItem extends StatelessWidget {}}-class _TextColors extends StatelessWidget {- _TextColors({+class EditorTextColorWidget extends StatelessWidget {+ EditorTextColorWidget({+ super.key,this.selectedColor,required this.onSelectedColor,});diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/add_block_toolbar_item.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/add_block_toolbar_item.dartindex 7032c1b116..3e5d1b5e32 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/add_block_toolbar_item.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/add_block_toolbar_item.dart@@ -119,9 +119,18 @@ class AddBlockMenu extends StatelessWidget {node,);transaction.deleteNode(currentNode);- transaction.afterSelection = Selection.collapsed(- Position(path: selection.end.path),- );+ if (node.type == SimpleTableBlockKeys.type) {+ transaction.afterSelection = Selection.collapsed(+ Position(+ // table -> row -> cell -> paragraph+ path: selection.end.path + [0, 0, 0],+ ),+ );+ } else {+ transaction.afterSelection = Selection.collapsed(+ Position(path: selection.end.path),+ );+ }transaction.selectionExtraInfo = {};await editorState.apply(transaction);return;@@ -179,6 +188,17 @@ class AddBlockMenu extends StatelessWidget {onTap: (_, __) => _insertBlock(todoListNode(checked: false)),),+ // table+ TypeOptionMenuItemValue(+ value: SimpleTableBlockKeys.type,+ backgroundColor: colorMap[SimpleTableBlockKeys.type]!,+ text: LocaleKeys.editor_table.tr(),+ icon: FlowySvgs.slash_menu_icon_simple_table_s,+ onTap: (_, __) => _insertBlock(+ createSimpleTableBlockNode(columnCount: 2, rowCount: 2),+ ),+ ),+// quoteTypeOptionMenuItemValue(value: QuoteBlockKeys.type,@@ -363,6 +383,7 @@ class AddBlockMenu extends StatelessWidget {HeadingBlockKeys.type: const Color(0xFF5465A1),ParagraphBlockKeys.type: const Color(0xFF5465A1),TodoListBlockKeys.type: const Color(0xFF4BB299),+ SimpleTableBlockKeys.type: const Color(0xFF4BB299),QuoteBlockKeys.type: const Color(0xFFBAAC74),BulletedListBlockKeys.type: const Color(0xFFA35F94),NumberedListBlockKeys.type: const Color(0xFFA35F94),@@ -379,6 +400,7 @@ class AddBlockMenu extends StatelessWidget {HeadingBlockKeys.type: const Color(0xFFBECCFF),ParagraphBlockKeys.type: const Color(0xFFBECCFF),TodoListBlockKeys.type: const Color(0xFF98F4CD),+ SimpleTableBlockKeys.type: const Color(0xFF98F4CD),QuoteBlockKeys.type: const Color(0xFFFDEDA7),BulletedListBlockKeys.type: const Color(0xFFFFB9EF),NumberedListBlockKeys.type: const Color(0xFFFFB9EF),diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/util.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/util.dartindex 6d2e2c9f08..37444cd6e1 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/util.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/util.dart@@ -1,9 +1,8 @@-import 'package:flutter/material.dart';-import 'package:appflowy/generated/flowy_svgs.g.dart';import 'package:appflowy/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/aa_menu/_toolbar_theme.dart';import 'package:appflowy_editor/appflowy_editor.dart';import 'package:flowy_infra_ui/flowy_infra_ui.dart';+import 'package:flutter/material.dart';class MobileToolbarMenuItemWrapper extends StatelessWidget {const MobileToolbarMenuItemWrapper({@@ -239,7 +238,7 @@ extension MobileToolbarEditorState on EditorState {needToDeleteChildren = true;transaction.insertNodes(selection.end.path.next,- node.children.map((e) => e.copyWith()),+ node.children.map((e) => e.deepCopy()),);await apply(transaction);}diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/openai/widgets/ask_ai_action_bloc.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/openai/widgets/ask_ai_action_bloc.dartindex fe4af5f493..82cd627180 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/openai/widgets/ask_ai_action_bloc.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/openai/widgets/ask_ai_action_bloc.dart@@ -145,7 +145,7 @@ class AskAIActionBloc extends Bloc<AskAIEvent, AskAIState> {final nodes = customMarkdownToDocument(state.result).root.children- .map((e) => e.copyWith())+ .map((e) => e.deepCopy()).toList();final insertedPath = selection.end.path.next;final transaction = editorState.transaction;@@ -182,7 +182,7 @@ class AskAIActionBloc extends Bloc<AskAIEvent, AskAIState> {final nodes = customMarkdownToDocument(state.result).root.children- .map((e) => e.copyWith())+ .map((e) => e.deepCopy()).toList();if (nodes.isEmpty) {return;diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/parsers/simple_table_node_parser.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/parsers/simple_table_node_parser.dartindex 3c23a19198..b01e797595 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/parsers/simple_table_node_parser.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/parsers/simple_table_node_parser.dart@@ -11,7 +11,7 @@ class SimpleTableNodeParser extends NodeParser {@overrideString transform(Node node, DocumentMarkdownEncoder? encoder) {try {- final tableData = _extractTableData(node);+ final tableData = _extractTableData(node, encoder);if (tableData.isEmpty) {return '';}@@ -23,12 +23,15 @@ class SimpleTableNodeParser extends NodeParser {/// Extracts table data from the node structure into a 2D list of strings/// Each inner list represents a row, and each string represents a cell's content- List<List<String>> _extractTableData(Node node) {+ List<List<String>> _extractTableData(+ Node node,+ DocumentMarkdownEncoder? encoder,+ ) {final tableData = <List<String>>[];final rows = node.children;for (final row in rows) {- final rowData = _extractRowData(row);+ final rowData = _extractRowData(row, encoder);tableData.add(rowData);}@@ -36,12 +39,12 @@ class SimpleTableNodeParser extends NodeParser {}/// Extracts data from a single table row- List<String> _extractRowData(Node row) {+ List<String> _extractRowData(Node row, DocumentMarkdownEncoder? encoder) {final rowData = <String>[];final cells = row.children;for (final cell in cells) {- final content = _extractCellContent(cell);+ final content = _extractCellContent(cell, encoder);rowData.add(content);}@@ -49,14 +52,17 @@ class SimpleTableNodeParser extends NodeParser {}/// Extracts and formats content from a single table cell- String _extractCellContent(Node cell) {+ String _extractCellContent(Node cell, DocumentMarkdownEncoder? encoder) {final contentBuffer = StringBuffer();for (final child in cell.children) {final delta = child.delta;- if (delta == null) continue;- final content = DeltaMarkdownEncoder().convert(delta);+ // if the node doesn't contain delta, fallback to the encoder+ final content = delta != null+ ? DeltaMarkdownEncoder().convert(delta)+ : encoder?.convertNodes([child]).trim() ?? '';+// Escape pipe characters to prevent breaking markdown table structurecontentBuffer.write(content.replaceAll('|', '\\|'));}diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/shortcuts/heading_block_shortcuts.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/shortcuts/heading_block_shortcuts.dartindex 7417aa9184..a65cd61c83 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/shortcuts/heading_block_shortcuts.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/shortcuts/heading_block_shortcuts.dart@@ -36,7 +36,7 @@ CharacterShortcutEvent customFormatSignToHeading = CharacterShortcutEvent(level: numberOfSign,delta: delta.compose(Delta()..delete(numberOfSign)),collapsed: collapsed ?? false,- children: node.children.map((child) => child.copyWith()),+ children: node.children.map((child) => child.deepCopy()),),];}diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_block_component.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_block_component.dartindex 63e41ef872..ba714d399c 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_block_component.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_block_component.dart@@ -11,48 +11,69 @@ typedef SimpleTableColumnWidthMap = Map<String, double>;typedef SimpleTableRowAlignMap = Map<String, String>;typedef SimpleTableColumnAlignMap = Map<String, String>;typedef SimpleTableColorMap = Map<String, String>;+typedef SimpleTableAttributeMap = Map<String, bool>;class SimpleTableBlockKeys {const SimpleTableBlockKeys._();static const String type = 'simple_table';- // enable header row- // it's a bool value, default is false+ /// enable header row+ /// it's a bool value, default is falsestatic const String enableHeaderRow = 'enable_header_row';- // enable column header- // it's a bool value, default is false+ /// enable column header+ /// it's a bool value, default is falsestatic const String enableHeaderColumn = 'enable_header_column';- // column colors- // it's a `SimpleTableColorMap` value, {column_index: color, ...}- // the number of colors should be the same as the number of columns+ /// column colors+ /// it's a [SimpleTableColorMap] value, {column_index: color, ...}+ /// the number of colors should be the same as the number of columnsstatic const String columnColors = 'column_colors';- // row colors- // it's a `SimpleTableColorMap` value, {row_index: color, ...}- // the number of colors should be the same as the number of rows+ /// row colors+ /// it's a [SimpleTableColorMap] value, {row_index: color, ...}+ /// the number of colors should be the same as the number of rowsstatic const String rowColors = 'row_colors';- // column alignments- // it's a `SimpleTableColumnAlignMap` value, {column_index: align, ...}- // the value should be one of the following: 'left', 'center', 'right'+ /// column alignments+ /// it's a [SimpleTableColumnAlignMap] value, {column_index: align, ...}+ /// the value should be one of the following: 'left', 'center', 'right'static const String columnAligns = 'column_aligns';- // row alignments- // it's a `SimpleTableRowAlignMap` value, {row_index: align, ...}- // the value should be one of the following: 'top', 'center', 'bottom'+ /// row alignments+ /// it's a [SimpleTableRowAlignMap] value, {row_index: align, ...}+ /// the value should be one of the following: 'top', 'center', 'bottom'static const String rowAligns = 'row_aligns';- // column widths- // it's a `SimpleTableColumnWidthMap` value, {column_index: width, ...}+ /// column bold attributes+ /// it's a [SimpleTableAttributeMap] value, {column_index: attribute, ...}+ /// the attribute should be one of the following: true, false+ static const String columnBoldAttributes = 'column_bold_attributes';++ /// row bold attributes+ /// it's a [SimpleTableAttributeMap] value, {row_index: true, ...}+ /// the attribute should be one of the following: true, false+ static const String rowBoldAttributes = 'row_bold_attributes';++ /// column text color attributes+ /// it's a [SimpleTableColorMap] value, {column_index: color_hex_code, ...}+ /// the attribute should be the color hex color or appflowy_theme_color+ static const String columnTextColors = 'column_text_colors';++ /// row text color attributes+ /// it's a [SimpleTableColorMap] value, {row_index: color_hex_code, ...}+ /// the attribute should be the color hex color or appflowy_theme_color+ static const String rowTextColors = 'row_text_colors';++ /// column widths+ /// it's a [SimpleTableColumnWidthMap] value, {column_index: width, ...}static const String columnWidths = 'column_widths';- // distribute column widths evenly- // if the user distributed the column widths evenly before, the value should be true,- // and for the newly added column, using the width of the previous column.- // it's a bool value, default is false+ /// distribute column widths evenly+ /// if the user distributed the column widths evenly before, the value should be true,+ /// and for the newly added column, using the width of the previous column.+ /// it's a bool value, default is falsestatic const String distributeColumnWidthsEvenly ='distribute_column_widths_evenly';}@@ -201,12 +222,20 @@ class _SimpleTableBlockWidgetState extends State<SimpleTableBlockWidget>if (UniversalPlatform.isDesktop) {child = Transform.translate(- offset: const Offset(+ offset: Offset(-SimpleTableConstants.tableLeftPadding,0,),child: child,);+ } else if (UniversalPlatform.isMobile) {+ child = Transform.translate(+ offset: Offset(+ -SimpleTableConstants.tableHitTestLeftPadding,+ 0,+ ),+ child: child,+ );}child = Container(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.dartindex 23c9df08f3..ca7837632a 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@@ -127,21 +127,34 @@ class SimpleTableCellBlockWidgetState extends State<SimpleTableCellBlockWidget>if (editorState.editable) ...[if (node.columnIndex == 0)Positioned(- top: 0,+ // if the cell is in the first row, add padding to the top of the cell+ // to make the row action button clickable.+ top: node.rowIndex == 0+ ? SimpleTableConstants.tableHitTestTopPadding+ : 0,bottom: 0,left: -SimpleTableConstants.tableLeftPadding,child: _buildRowMoreActionButton(),),if (node.rowIndex == 0)Positioned(- left: 0,+ left: node.columnIndex == 0+ ? SimpleTableConstants.tableHitTestLeftPadding+ : 0,right: 0,child: _buildColumnMoreActionButton(),),+ if (node.columnIndex == 0 && node.rowIndex == 0)+ Positioned(+ left: 2,+ top: 0,+ child: _buildTableActionMenu(),+ ),Positioned(right: 0,- top:- node.rowIndex == 0 ? SimpleTableConstants.tableTopPadding : 0,+ top: node.rowIndex == 0+ ? SimpleTableConstants.tableHitTestTopPadding+ : 0,bottom: 0,child: SimpleTableColumnResizeHandle(node: node,@@ -163,7 +176,12 @@ class SimpleTableCellBlockWidgetState extends State<SimpleTableCellBlockWidget>// column action button is not clickable.// issue: https://github.com/flutter/flutter/issues/75747padding: EdgeInsets.only(- top: node.rowIndex == 0 ? SimpleTableConstants.tableTopPadding : 0,+ top: node.rowIndex == 0+ ? SimpleTableConstants.tableHitTestTopPadding+ : 0,+ left: node.columnIndex == 0+ ? SimpleTableConstants.tableHitTestLeftPadding+ : 0,),// TODO(Lucas): find a better way to handle the multiple value listenable builder// There's flutter pub can do that.@@ -239,6 +257,7 @@ class SimpleTableCellBlockWidgetState extends State<SimpleTableCellBlockWidget>final rowIndex = node.rowIndex;return SimpleTableMoreActionMenu(+ tableCellNode: node,index: rowIndex,type: SimpleTableMoreActionType.row,);@@ -248,11 +267,24 @@ class SimpleTableCellBlockWidgetState extends State<SimpleTableCellBlockWidget>final columnIndex = node.columnIndex;return SimpleTableMoreActionMenu(+ tableCellNode: node,index: columnIndex,type: SimpleTableMoreActionType.column,);}+ Widget _buildTableActionMenu() {+ final tableNode = node.parentTableNode;+ if (tableNode == null) {+ return const SizedBox.shrink();+ }++ return SimpleTableActionMenu(+ tableNode: tableNode,+ editorState: editorState,+ );+ }+Alignment _buildAlignment() {Alignment alignment = Alignment.topLeft;if (node.columnAlign != TableAlign.left) {@@ -328,8 +360,26 @@ class SimpleTableCellBlockWidgetState extends State<SimpleTableCellBlockWidget>node.path.isAncestorOf(selection.start.path) &&node.path.isAncestorOf(selection.end.path)) {isEditingCellNotifier.value = true;+ simpleTableContext?.isEditingCell.value = node;} else {isEditingCellNotifier.value = false;}++ // if the selection is null or the selection is collapsed, set the isEditingCell to null.+ if (selection == null) {+ simpleTableContext?.isEditingCell.value = null;+ } else if (selection.isCollapsed) {+ // if the selection is collapsed, check if the selection is in the cell.+ final selectedNode =+ editorState.getNodesInSelection(selection).firstOrNull;+ if (selectedNode != null) {+ final tableNode = selectedNode.parentTableNode;+ if (tableNode == null || tableNode.id != node.parentTableNode?.id) {+ simpleTableContext?.isEditingCell.value = null;+ }+ } else {+ simpleTableContext?.isEditingCell.value = null;+ }+ }}}diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_constants.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_constants.dartindex ca82866730..ff225437fa 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_constants.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_constants.dart@@ -76,6 +76,11 @@ class SimpleTableContext {bool get isReordering =>isReorderingColumn.value.$1 || isReorderingRow.value.$1;+ /// isEditingCell is the cell that the user is editing+ ///+ /// This value is available on mobile only+ final ValueNotifier<Node?> isEditingCell = ValueNotifier(null);+void _onHoveringOnColumnsAndRowsChanged() {if (!_enableTableDebugLog) {return;@@ -165,6 +170,7 @@ class SimpleTableContext {isReorderingColumn.dispose();isReorderingRow.dispose();reorderingOffset.dispose();+ isEditingCell.dispose();}}@@ -175,24 +181,28 @@ class SimpleTableConstants {static const defaultRowHeight = 36.0;- static const tableTopPadding = 8.0;- static const tableLeftPadding = 8.0;+ static double get tableHitTestTopPadding =>+ UniversalPlatform.isDesktop ? 8.0 : 24.0;+ static double get tableHitTestLeftPadding =>+ UniversalPlatform.isDesktop ? 0.0 : 24.0;+ static double get tableLeftPadding => UniversalPlatform.isDesktop ? 8.0 : 0.0;static const tableBottomPadding =addRowButtonHeight + 3 * addRowButtonPadding;static const tableRightPadding =addColumnButtonWidth + 2 * SimpleTableConstants.addColumnButtonPadding;- static const tablePadding = EdgeInsets.only(- // don't add padding to the top of the table, the first row will have padding- // to make the column action button clickable.- bottom: tableBottomPadding,- left: tableLeftPadding,- right: tableRightPadding,- );+ static EdgeInsets get tablePadding => EdgeInsets.only(+ // don't add padding to the top of the table, the first row will have padding+ // to make the column action button clickable.+ bottom: tableBottomPadding,+ left: tableLeftPadding,+ right: tableRightPadding,+ );- static double get tablePageOffset =>- EditorStyleCustomizer.optionMenuWidth + 12;+ static double get tablePageOffset => UniversalPlatform.isMobile+ ? EditorStyleCustomizer.optionMenuWidth + 24+ : EditorStyleCustomizer.optionMenuWidth + 12;// Add row buttonstatic const addRowButtonHeight = 16.0;@@ -242,6 +252,16 @@ class SimpleTableConstants {/// Enable the drag to expand the tablestatic const enableDragToExpandTable = false;++ /// Action sheet hit test area on Mobile+ static const rowActionSheetHitTestAreaWidth = 24.0;+ static const columnActionSheetHitTestAreaHeight = 24.0;++ static const actionSheetQuickActionSectionHeight = 44.0;+ static const actionSheetInsertSectionHeight = 52.0;+ static const actionSheetContentSectionHeight = 44.0;+ static const actionSheetNormalActionSectionHeight = 48.0;+ static const actionSheetButtonRadius = 12.0;}enum SimpleTableBorderRenderType {@@ -273,4 +293,12 @@ extension SimpleTableColors on BuildContext {Color get simpleTableDefaultHeaderColor => Theme.of(this).isLightMode? const Color(0xFFF2F2F2): const Color(0x08FFFFFF);++ Color get simpleTableActionButtonBackgroundColor => Theme.of(this).isLightMode+ ? const Color(0xFFFFFFFF)+ : const Color(0xFF2D3036);++ Color get simpleTableInsertActionBackgroundColor => Theme.of(this).isLightMode+ ? const Color(0xFFF2F2F7)+ : const Color(0xFF2D3036);}diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_more_action.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_more_action.dartindex 6d57be00b8..db5cb1ac5c 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_more_action.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_more_action.dart@@ -1,18 +1,21 @@+import 'dart:async';+import 'package:appflowy/generated/flowy_svgs.g.dart';import 'package:appflowy/generated/locale_keys.g.dart';+import 'package:appflowy/mobile/presentation/bottom_sheet/show_mobile_bottom_sheet.dart';import 'package:appflowy/plugins/document/presentation/editor_plugins/simple_table/simple_table.dart';-import 'package:appflowy/workspace/presentation/widgets/toggle/toggle.dart';+import 'package:appflowy_backend/log.dart';import 'package:appflowy_editor/appflowy_editor.dart';import 'package:easy_localization/easy_localization.dart';-import 'package:flowy_infra_ui/flowy_infra_ui.dart';import 'package:flutter/material.dart';import 'package:provider/provider.dart';+import 'package:universal_platform/universal_platform.dart';enum SimpleTableMoreActionType {column,row;- List<SimpleTableMoreAction> buildActions({+ List<SimpleTableMoreAction> buildDesktopActions({required int index,required int columnLength,required int rowLength,@@ -56,6 +59,41 @@ enum SimpleTableMoreActionType {}}+ List<List<SimpleTableMoreAction>> buildMobileActions({+ required int index,+ required int columnLength,+ required int rowLength,+ }) {+ // the actions on mobile are not the same as the desktop ones+ // the mobile actions are grouped into different sections+ switch (this) {+ case SimpleTableMoreActionType.row:+ return [+ if (index == 0) [SimpleTableMoreAction.enableHeaderRow],+ [+ SimpleTableMoreAction.setToPageWidth,+ SimpleTableMoreAction.distributeColumnsEvenly,+ ],+ [+ SimpleTableMoreAction.duplicateRow,+ SimpleTableMoreAction.clearContents,+ ],+ ];+ case SimpleTableMoreActionType.column:+ return [+ if (index == 0) [SimpleTableMoreAction.enableHeaderColumn],+ [+ SimpleTableMoreAction.setToPageWidth,+ SimpleTableMoreAction.distributeColumnsEvenly,+ ],+ [+ SimpleTableMoreAction.duplicateColumn,+ SimpleTableMoreAction.clearContents,+ ],+ ];+ }+ }+FlowySvgData get reorderIconSvg {switch (this) {case SimpleTableMoreActionType.column:@@ -88,7 +126,19 @@ enum SimpleTableMoreAction {enableHeaderRow,setToPageWidth,distributeColumnsEvenly,- divider;+ divider,++ // these actions are only available on mobile+ duplicateRow,+ duplicateColumn,+ cut,+ copy,+ paste,+ bold,+ textColor,+ textBackgroundColor,+ duplicateTable,+ copyLinkToBlock;String get name {return switch (this) {@@ -119,6 +169,22 @@ enum SimpleTableMoreAction {SimpleTableMoreAction.distributeColumnsEvenly => LocaleKeys.document_plugins_simpleTable_moreActions_distributeColumnsWidth.tr(),+ SimpleTableMoreAction.duplicateRow =>+ LocaleKeys.document_plugins_simpleTable_moreActions_duplicateRow.tr(),+ SimpleTableMoreAction.duplicateColumn => LocaleKeys+ .document_plugins_simpleTable_moreActions_duplicateColumn+ .tr(),+ SimpleTableMoreAction.duplicateTable =>+ LocaleKeys.document_plugins_simpleTable_moreActions_duplicateTable.tr(),+ SimpleTableMoreAction.copyLinkToBlock =>+ LocaleKeys.document_plugins_optionAction_copyLinkToBlock.tr(),+ SimpleTableMoreAction.bold ||+ SimpleTableMoreAction.textColor ||+ SimpleTableMoreAction.textBackgroundColor ||+ SimpleTableMoreAction.cut ||+ SimpleTableMoreAction.copy ||+ SimpleTableMoreAction.paste =>+ throw UnimplementedError(),SimpleTableMoreAction.divider => throw UnimplementedError(),};}@@ -139,10 +205,21 @@ enum SimpleTableMoreAction {SimpleTableMoreAction.enableHeaderColumn =>FlowySvgs.table_header_column_s,SimpleTableMoreAction.enableHeaderRow => FlowySvgs.table_header_row_s,+ SimpleTableMoreAction.duplicateRow => FlowySvgs.m_table_duplicate_s,+ SimpleTableMoreAction.duplicateColumn => FlowySvgs.m_table_duplicate_s,+ SimpleTableMoreAction.cut => FlowySvgs.m_table_quick_action_cut_s,+ SimpleTableMoreAction.copy => FlowySvgs.m_table_quick_action_copy_s,+ SimpleTableMoreAction.paste => FlowySvgs.m_table_quick_action_paste_s,+ SimpleTableMoreAction.bold => FlowySvgs.m_aa_bold_s,+ SimpleTableMoreAction.duplicateTable => FlowySvgs.m_table_duplicate_s,+ SimpleTableMoreAction.copyLinkToBlock => FlowySvgs.m_copy_link_s,+ SimpleTableMoreAction.align => FlowySvgs.m_aa_align_left_s,+ SimpleTableMoreAction.textColor =>+ throw UnsupportedError('text color icon is not supported'),+ SimpleTableMoreAction.textBackgroundColor =>+ throw UnsupportedError('text background color icon is not supported'),SimpleTableMoreAction.divider =>throw UnsupportedError('divider icon is not supported'),- SimpleTableMoreAction.align =>- throw UnsupportedError('align icon is not supported'),SimpleTableMoreAction.backgroundColor =>throw UnsupportedError('background color icon is not supported'),};@@ -154,10 +231,12 @@ class SimpleTableMoreActionMenu extends StatefulWidget {super.key,required this.index,required this.type,+ required this.tableCellNode,});final int index;final SimpleTableMoreActionType type;+ final Node tableCellNode;@overrideState<SimpleTableMoreActionMenu> createState() =>@@ -166,588 +245,225 @@ class SimpleTableMoreActionMenu extends StatefulWidget {class _SimpleTableMoreActionMenuState extends State<SimpleTableMoreActionMenu> {ValueNotifier<bool> isShowingMenu = ValueNotifier(false);+ ValueNotifier<bool> isEditingCellNotifier = ValueNotifier(false);- @override- void dispose() {- isShowingMenu.dispose();-- super.dispose();- }-- @override- Widget build(BuildContext context) {- final simpleTableContext = context.read<SimpleTableContext>();- return Align(- alignment: widget.type == SimpleTableMoreActionType.row- ? Alignment.centerLeft- : Alignment.topCenter,- child: ValueListenableBuilder<bool>(- valueListenable: isShowingMenu,- builder: (context, isShowingMenu, child) {- return ValueListenableBuilder(- valueListenable: simpleTableContext.hoveringTableCell,- builder: (context, hoveringTableNode, child) {- final reorderingIndex = switch (widget.type) {- SimpleTableMoreActionType.column =>- simpleTableContext.isReorderingColumn.value.$2,- SimpleTableMoreActionType.row =>- simpleTableContext.isReorderingRow.value.$2,- };- final isReordering = simpleTableContext.isReordering;- if (isReordering) {- // when reordering, hide the menu for another column or row that is not the current dragging one.- if (reorderingIndex != widget.index) {- return const SizedBox.shrink();- } else {- return child!;- }- }-- final hoveringIndex =- widget.type == SimpleTableMoreActionType.column- ? hoveringTableNode?.columnIndex- : hoveringTableNode?.rowIndex;-- if (hoveringIndex != widget.index && !isShowingMenu) {- return const SizedBox.shrink();- }-- return child!;- },- child: SimpleTableMoreActionPopup(- index: widget.index,- isShowingMenu: this.isShowingMenu,- type: widget.type,- ),- );- },- ),- );- }-}--class SimpleTableMoreActionPopup extends StatefulWidget {- const SimpleTableMoreActionPopup({- super.key,- required this.index,- required this.isShowingMenu,- required this.type,- });-- final int index;- final ValueNotifier<bool> isShowingMenu;- final SimpleTableMoreActionType type;-- @override- State<SimpleTableMoreActionPopup> createState() =>- _SimpleTableMoreActionPopupState();-}--class _SimpleTableMoreActionPopupState- extends State<SimpleTableMoreActionPopup> {late final editorState = context.read<EditorState>();-- SelectionGestureInterceptor? gestureInterceptor;-- RenderBox? get renderBox => context.findRenderObject() as RenderBox?;+ late final simpleTableContext = context.read<SimpleTableContext>();@overridevoid initState() {super.initState();- final tableCellNode =- context.read<SimpleTableContext>().hoveringTableCell.value;- gestureInterceptor = SelectionGestureInterceptor(- key: 'simple_table_more_action_popup_interceptor_${tableCellNode?.id}',- canTap: (details) => !_isTapInBounds(details.globalPosition),- );- editorState.service.selectionService.registerGestureInterceptor(- gestureInterceptor!,- );+ editorState.selectionNotifier.addListener(_onSelectionChanged);}@overridevoid dispose() {- if (gestureInterceptor != null) {- editorState.service.selectionService.unregisterGestureInterceptor(- gestureInterceptor!.key,- );- }+ isShowingMenu.dispose();+ isEditingCellNotifier.dispose();++ editorState.selectionNotifier.removeListener(_onSelectionChanged);super.dispose();}@overrideWidget build(BuildContext context) {- final simpleTableContext = context.read<SimpleTableContext>();- final tableCellNode = simpleTableContext.hoveringTableCell.value;- final tableNode = tableCellNode?.parentTableNode;-- if (tableNode == null) {- return const SizedBox.shrink();- }-- return AppFlowyPopover(- onOpen: () => _onOpen(tableCellNode: tableCellNode),- onClose: () => _onClose(),- direction: widget.type == SimpleTableMoreActionType.row- ? PopoverDirection.bottomWithCenterAligned- : PopoverDirection.bottomWithLeftAligned,- offset: widget.type == SimpleTableMoreActionType.row- ? const Offset(24, 14)- : const Offset(-14, 8),- clickHandler: PopoverClickHandler.gestureDetector,- popupBuilder: (_) => _buildPopup(tableCellNode: tableCellNode),- child: SimpleTableDraggableReorderButton(- editorState: editorState,- simpleTableContext: simpleTableContext,- node: tableNode,- index: widget.index,- isShowingMenu: widget.isShowingMenu,- type: widget.type,- ),+ return Align(+ alignment: widget.type == SimpleTableMoreActionType.row+ ? UniversalPlatform.isDesktop+ ? Alignment.centerLeft+ : Alignment.centerRight+ : Alignment.topCenter,+ child: UniversalPlatform.isDesktop+ ? _buildDesktopMenu()+ : _buildMobileMenu(),);}- Widget _buildPopup({Node? tableCellNode}) {- if (tableCellNode == null) {- return const SizedBox.shrink();- }- return MultiProvider(- providers: [- Provider.value(- value: context.read<SimpleTableContext>(),- ),- Provider.value(- value: context.read<EditorState>(),- ),- ],- child: SimpleTableMoreActionList(- type: widget.type,- index: widget.index,- tableCellNode: tableCellNode,- ),+ // On desktop, the menu is a popup and only shows when hovering.+ Widget _buildDesktopMenu() {+ return ValueListenableBuilder<bool>(+ valueListenable: isShowingMenu,+ builder: (context, isShowingMenu, child) {+ return ValueListenableBuilder(+ valueListenable: simpleTableContext.hoveringTableCell,+ builder: (context, hoveringTableNode, child) {+ final reorderingIndex = switch (widget.type) {+ SimpleTableMoreActionType.column =>+ simpleTableContext.isReorderingColumn.value.$2,+ SimpleTableMoreActionType.row =>+ simpleTableContext.isReorderingRow.value.$2,+ };+ final isReordering = simpleTableContext.isReordering;+ if (isReordering) {+ // when reordering, hide the menu for another column or row that is not the current dragging one.+ if (reorderingIndex != widget.index) {+ return const SizedBox.shrink();+ } else {+ return child!;+ }+ }++ final hoveringIndex =+ widget.type == SimpleTableMoreActionType.column+ ? hoveringTableNode?.columnIndex+ : hoveringTableNode?.rowIndex;++ if (hoveringIndex != widget.index && !isShowingMenu) {+ return const SizedBox.shrink();+ }++ return child!;+ },+ child: SimpleTableMoreActionPopup(+ index: widget.index,+ isShowingMenu: this.isShowingMenu,+ type: widget.type,+ ),+ );+ },);}- void _onOpen({Node? tableCellNode}) {- widget.isShowingMenu.value = true;+ // On mobile, the menu is a action sheet and always shows.+ Widget _buildMobileMenu() {+ return ValueListenableBuilder(+ valueListenable: isShowingMenu,+ builder: (context, isShowingMenu, child) {+ return ValueListenableBuilder(+ valueListenable: simpleTableContext.isEditingCell,+ builder: (context, isEditingCell, child) {+ if (isShowingMenu) {+ return child!;+ }- switch (widget.type) {- case SimpleTableMoreActionType.column:- context.read<SimpleTableContext>().selectingColumn.value =- tableCellNode?.columnIndex;- case SimpleTableMoreActionType.row:- context.read<SimpleTableContext>().selectingRow.value =- tableCellNode?.rowIndex;- }+ if (isEditingCell == null) {+ return const SizedBox.shrink();+ }- // Workaround to clear the selection after the menu is opened.- Future.delayed(Durations.short3, () {- if (!editorState.isDisposed) {- editorState.selection = null;- }- });- }+ final columnIndex = isEditingCell.columnIndex;+ final rowIndex = isEditingCell.rowIndex;- void _onClose() {- widget.isShowingMenu.value = false;+ switch (widget.type) {+ case SimpleTableMoreActionType.column:+ if (columnIndex != widget.index) {+ return const SizedBox.shrink();+ }+ case SimpleTableMoreActionType.row:+ if (rowIndex != widget.index) {+ return const SizedBox.shrink();+ }+ }- // clear the selecting index- context.read<SimpleTableContext>().selectingColumn.value = null;- context.read<SimpleTableContext>().selectingRow.value = null;+ return child!;+ },+ child: SimpleTableMobileDraggableReorderButton(+ index: widget.index,+ type: widget.type,+ node: widget.tableCellNode,+ isShowingMenu: this.isShowingMenu,+ editorState: editorState,+ simpleTableContext: simpleTableContext,+ ),+ );+ },+ );}- bool _isTapInBounds(Offset offset) {- if (renderBox == null) {- return false;- }+ void _onSelectionChanged() {+ final selection = editorState.selection;- final localPosition = renderBox!.globalToLocal(offset);- final result = renderBox!.paintBounds.contains(localPosition);- if (result) {- editorState.selection = null;+ // check if the selection is in the cell+ if (selection != null &&+ widget.tableCellNode.path.isAncestorOf(selection.start.path) &&+ widget.tableCellNode.path.isAncestorOf(selection.end.path)) {+ isEditingCellNotifier.value = true;+ } else {+ isEditingCellNotifier.value = false;}- return result;}}-class SimpleTableMoreActionList extends StatefulWidget {- const SimpleTableMoreActionList({+/// This widget is only used on mobile+class SimpleTableActionMenu extends StatelessWidget {+ const SimpleTableActionMenu({super.key,- required this.type,- required this.index,- required this.tableCellNode,- this.mutex,+ required this.tableNode,+ required this.editorState,});- final SimpleTableMoreActionType type;- final int index;- final Node tableCellNode;- final PopoverMutex? mutex;-- @override- State<SimpleTableMoreActionList> createState() =>- _SimpleTableMoreActionListState();-}--class _SimpleTableMoreActionListState extends State<SimpleTableMoreActionList> {- // ensure the background color menu and align menu exclusive- final mutex = PopoverMutex();+ final Node tableNode;+ final EditorState editorState;@overrideWidget build(BuildContext context) {- return Column(- mainAxisSize: MainAxisSize.min,- children: widget.type- .buildActions(- index: widget.index,- columnLength: widget.tableCellNode.columnLength,- rowLength: widget.tableCellNode.rowLength,- )- .map(- (action) => SimpleTableMoreActionItem(- type: widget.type,- action: action,- tableCellNode: widget.tableCellNode,- popoverMutex: mutex,+ final simpleTableContext = context.read<SimpleTableContext>();+ return ValueListenableBuilder<Node?>(+ valueListenable: simpleTableContext.isEditingCell,+ builder: (context, isEditingCell, child) {+ if (isEditingCell == null) {+ return const SizedBox.shrink();+ }++ return GestureDetector(+ onTap: () => _showTableActionBottomSheet(context),+ child: Container(+ width: 20,+ height: 20,+ alignment: Alignment.center,+ child: const FlowySvg(+ FlowySvgs.drag_element_s,+ size: Size.square(18.0),),- )- .toList(),+ ),+ );+ },);}-}--class SimpleTableMoreActionItem extends StatefulWidget {- const SimpleTableMoreActionItem({- super.key,- required this.type,- required this.action,- required this.tableCellNode,- required this.popoverMutex,- });-- final SimpleTableMoreActionType type;- final SimpleTableMoreAction action;- final Node tableCellNode;- final PopoverMutex popoverMutex;-- @override- State<SimpleTableMoreActionItem> createState() =>- _SimpleTableMoreActionItemState();-}--class _SimpleTableMoreActionItemState extends State<SimpleTableMoreActionItem> {- final isEnableHeader = ValueNotifier(false);-- @override- void initState() {- super.initState();-- _initEnableHeader();- }-- @override- void dispose() {- isEnableHeader.dispose();- super.dispose();- }+ Future<void> _showTableActionBottomSheet(BuildContext context) async {+ // check if the table node is a simple table+ assert(tableNode.type == SimpleTableBlockKeys.type);- @override- Widget build(BuildContext context) {- if (widget.action == SimpleTableMoreAction.divider) {- return _buildDivider(context);- } else if (widget.action == SimpleTableMoreAction.align) {- return _buildAlignMenu(context);- } else if (widget.action == SimpleTableMoreAction.backgroundColor) {- return _buildBackgroundColorMenu(context);- } else if (widget.action == SimpleTableMoreAction.enableHeaderColumn) {- return _buildEnableHeaderButton(context);- } else if (widget.action == SimpleTableMoreAction.enableHeaderRow) {- return _buildEnableHeaderButton(context);+ if (tableNode.type != SimpleTableBlockKeys.type) {+ Log.error('The table node is not a simple table');+ return;}- return _buildActionButton(context);- }-- Widget _buildDivider(BuildContext context) {- return const FlowyDivider(- padding: EdgeInsets.symmetric(- vertical: 4.0,- ),- );- }-- Widget _buildAlignMenu(BuildContext context) {- return SimpleTableAlignMenu(- type: widget.type,- tableCellNode: widget.tableCellNode,- mutex: widget.popoverMutex,- );- }-- Widget _buildBackgroundColorMenu(BuildContext context) {- return SimpleTableBackgroundColorMenu(- type: widget.type,- tableCellNode: widget.tableCellNode,- mutex: widget.popoverMutex,- );- }-- Widget _buildEnableHeaderButton(BuildContext context) {- return SimpleTableBasicButton(- text: widget.action.name,- leftIconSvg: widget.action.leftIconSvg,- rightIcon: ValueListenableBuilder(- valueListenable: isEnableHeader,- builder: (context, isEnableHeader, child) {- return Toggle(- value: isEnableHeader,- onChanged: (value) => _toggleEnableHeader(),- padding: EdgeInsets.zero,- );- },- ),- onTap: _toggleEnableHeader,- );- }-- Widget _buildActionButton(BuildContext context) {- return Container(- height: SimpleTableConstants.moreActionHeight,- padding: SimpleTableConstants.moreActionPadding,- child: FlowyIconTextButton(- margin: SimpleTableConstants.moreActionHorizontalMargin,- leftIconBuilder: (onHover) => FlowySvg(- widget.action.leftIconSvg,- color: widget.action == SimpleTableMoreAction.delete && onHover- ? Theme.of(context).colorScheme.error- : null,- ),- iconPadding: 10.0,- textBuilder: (onHover) => FlowyText.regular(- widget.action.name,- fontSize: 14.0,- figmaLineHeight: 18.0,- color: widget.action == SimpleTableMoreAction.delete && onHover- ? Theme.of(context).colorScheme.error- : null,+ unawaited(+ editorState.updateSelectionWithReason(+ Selection.collapsed(+ Position(+ path: tableNode.path,+ ),),- onTap: _onAction,+ customSelectionType: SelectionType.block,),);- }-- void _onAction() {- switch (widget.action) {- case SimpleTableMoreAction.delete:- switch (widget.type) {- case SimpleTableMoreActionType.column:- _deleteColumn();- break;- case SimpleTableMoreActionType.row:- _deleteRow();- break;- }- case SimpleTableMoreAction.insertLeft:- _insertColumnLeft();- case SimpleTableMoreAction.insertRight:- _insertColumnRight();- case SimpleTableMoreAction.insertAbove:- _insertRowAbove();- case SimpleTableMoreAction.insertBelow:- _insertRowBelow();- case SimpleTableMoreAction.clearContents:- _clearContent();- case SimpleTableMoreAction.duplicate:- switch (widget.type) {- case SimpleTableMoreActionType.column:- _duplicateColumn();- break;- case SimpleTableMoreActionType.row:- _duplicateRow();- break;- }- case SimpleTableMoreAction.setToPageWidth:- _setToPageWidth();- case SimpleTableMoreAction.distributeColumnsEvenly:- _distributeColumnsEvenly();- default:- break;- }- PopoverContainer.of(context).close();- }-- void _setToPageWidth() {- final value = _getTableAndTableCellAndCellPosition();- if (value == null) {+ if (!context.mounted) {return;}- final (table, _, _) = value;- final editorState = context.read<EditorState>();- editorState.setColumnWidthToPageWidth(tableNode: table);- }-- void _distributeColumnsEvenly() {- final value = _getTableAndTableCellAndCellPosition();- if (value == null) {- return;- }- final (table, _, _) = value;- final editorState = context.read<EditorState>();- editorState.distributeColumnWidthToPageWidth(tableNode: table);- }- void _duplicateRow() {- final value = _getTableAndTableCellAndCellPosition();- if (value == null) {- return;- }- final (table, node, _) = value;- final editorState = context.read<EditorState>();- editorState.duplicateRowInTable(table, node.rowIndex);- }-- void _duplicateColumn() {- final value = _getTableAndTableCellAndCellPosition();- if (value == null) {- return;- }- final (table, node, _) = value;- final editorState = context.read<EditorState>();- editorState.duplicateColumnInTable(table, node.columnIndex);- }-- void _toggleEnableHeader() {- final value = _getTableAndTableCellAndCellPosition();- if (value == null) {- return;- }-- isEnableHeader.value = !isEnableHeader.value;-- final (table, _, _) = value;- final editorState = context.read<EditorState>();- switch (widget.type) {- case SimpleTableMoreActionType.column:- editorState.toggleEnableHeaderColumn(- table,- isEnableHeader.value,- );- case SimpleTableMoreActionType.row:- editorState.toggleEnableHeaderRow(- table,- isEnableHeader.value,- );- }-- PopoverContainer.of(context).close();- }-- void _clearContent() {- final value = _getTableAndTableCellAndCellPosition();- if (value == null) {- return;- }- final (table, node, _) = value;- final editorState = context.read<EditorState>();- if (widget.type == SimpleTableMoreActionType.column) {- editorState.clearContentAtColumnIndex(table, node.columnIndex);- } else if (widget.type == SimpleTableMoreActionType.row) {- editorState.clearContentAtRowIndex(table, node.rowIndex);- }- }-- void _insertColumnLeft() {- final value = _getTableAndTableCellAndCellPosition();- if (value == null) {- return;- }- final (table, node, _) = value;- final columnIndex = node.columnIndex;- final editorState = context.read<EditorState>();- editorState.insertColumnInTable(table, columnIndex);- }-- void _insertColumnRight() {- final value = _getTableAndTableCellAndCellPosition();- if (value == null) {- return;- }- final (table, node, _) = value;- final columnIndex = node.columnIndex;- final editorState = context.read<EditorState>();- editorState.insertColumnInTable(table, columnIndex + 1);- }-- void _insertRowAbove() {- final value = _getTableAndTableCellAndCellPosition();- if (value == null) {- return;- }- final (table, node, _) = value;- final rowIndex = node.rowIndex;- final editorState = context.read<EditorState>();- editorState.insertRowInTable(table, rowIndex);- }-- void _insertRowBelow() {- final value = _getTableAndTableCellAndCellPosition();- if (value == null) {- return;- }- final (table, node, _) = value;- final rowIndex = node.rowIndex;- final editorState = context.read<EditorState>();- editorState.insertRowInTable(table, rowIndex + 1);- }-- void _deleteRow() {- final value = _getTableAndTableCellAndCellPosition();- if (value == null) {- return;- }- final (table, node, _) = value;- final rowIndex = node.rowIndex;- final editorState = context.read<EditorState>();- editorState.deleteRowInTable(table, rowIndex);- }-- void _deleteColumn() {- final value = _getTableAndTableCellAndCellPosition();- if (value == null) {- return;- }- final (table, node, _) = value;- final columnIndex = node.columnIndex;- final editorState = context.read<EditorState>();- editorState.deleteColumnInTable(table, columnIndex);- }+ final simpleTableContext = context.read<SimpleTableContext>();- (Node, Node, TableCellPosition)? _getTableAndTableCellAndCellPosition() {- final cell = widget.tableCellNode;- final table = cell.parent?.parent;- if (table == null || table.type != SimpleTableBlockKeys.type) {- return null;- }- return (table, cell, cell.cellPosition);- }+ simpleTableContext.isSelectingTable.value = true;++ // show the bottom sheet+ await showMobileBottomSheet(+ context,+ showDragHandle: true,+ showDivider: false,+ builder: (context) => Provider.value(+ value: simpleTableContext,+ child: SimpleTableBottomSheet(+ tableNode: tableNode,+ editorState: editorState,+ ),+ ),+ );- void _initEnableHeader() {- final value = _getTableAndTableCellAndCellPosition();- if (value != null) {- final (table, _, _) = value;- if (widget.type == SimpleTableMoreActionType.column) {- isEnableHeader.value = table- .attributes[SimpleTableBlockKeys.enableHeaderColumn] as bool? ??- false;- } else if (widget.type == SimpleTableMoreActionType.row) {- isEnableHeader.value =- table.attributes[SimpleTableBlockKeys.enableHeaderRow] as bool? ??- false;- }- }+ simpleTableContext.isSelectingTable.value = false;}}diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_operations/simple_table_content_operation.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_operations/simple_table_content_operation.dartindex 3309a6397c..9691a57a0d 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_operations/simple_table_content_operation.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_operations/simple_table_content_operation.dart@@ -1,6 +1,10 @@+import 'dart:convert';++import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/clipboard_service.dart';import 'package:appflowy/plugins/document/presentation/editor_plugins/simple_table/simple_table_block_component.dart';import 'package:appflowy/plugins/document/presentation/editor_plugins/simple_table/simple_table_cell_block_component.dart';import 'package:appflowy/plugins/document/presentation/editor_plugins/simple_table/simple_table_operations/simple_table_node_extension.dart';+import 'package:appflowy/startup/startup.dart';import 'package:appflowy_backend/log.dart';import 'package:appflowy_editor/appflowy_editor.dart';@@ -17,23 +21,26 @@ extension TableContentOperation on EditorState {/// After:/// Row 1: | | |/// Row 2: | 2 | 3 |- Future<void> clearContentAtRowIndex(Node node, int index) async {- assert(node.type == SimpleTableBlockKeys.type);+ Future<void> clearContentAtRowIndex({+ required Node tableNode,+ required int rowIndex,+ }) async {+ assert(tableNode.type == SimpleTableBlockKeys.type);- if (node.type != SimpleTableBlockKeys.type) {+ if (tableNode.type != SimpleTableBlockKeys.type) {return;}- if (index < 0 || index >= node.columnLength) {- Log.warn('clear content in column: index out of range: $index');+ if (rowIndex < 0 || rowIndex >= tableNode.rowLength) {+ Log.warn('clear content in row: index out of range: $rowIndex');return;}- Log.info('clear content in column: $index in table ${node.id}');+ Log.info('clear content in row: $rowIndex in table ${tableNode.id}');final transaction = this.transaction;- final row = node.children[index];+ final row = tableNode.children[rowIndex];for (var i = 0; i < row.children.length; i++) {final cell = row.children[i];transaction.insertNode(cell.path.next, simpleTableCellBlockNode());@@ -55,29 +62,358 @@ extension TableContentOperation on EditorState {/// After:/// Row 1: | 0 | |/// Row 2: | 2 | |- Future<void> clearContentAtColumnIndex(Node node, int index) async {- assert(node.type == SimpleTableBlockKeys.type);+ Future<void> clearContentAtColumnIndex({+ required Node tableNode,+ required int columnIndex,+ }) async {+ assert(tableNode.type == SimpleTableBlockKeys.type);- if (node.type != SimpleTableBlockKeys.type) {+ if (tableNode.type != SimpleTableBlockKeys.type) {return;}- if (index < 0 || index >= node.columnLength) {- Log.warn('clear content in column: index out of range: $index');+ if (columnIndex < 0 || columnIndex >= tableNode.columnLength) {+ Log.warn('clear content in column: index out of range: $columnIndex');return;}- Log.info('clear content in column: $index in table ${node.id}');+ Log.info('clear content in column: $columnIndex in table ${tableNode.id}');final transaction = this.transaction;- for (var i = 0; i < node.rowLength; i++) {- final row = node.children[i];- final cell = index >= row.children.length+ for (var i = 0; i < tableNode.rowLength; i++) {+ final row = tableNode.children[i];+ final cell = columnIndex >= row.children.length? row.children.last- : row.children[index];+ : row.children[columnIndex];transaction.insertNode(cell.path.next, simpleTableCellBlockNode());transaction.deleteNode(cell);}await apply(transaction);}++ /// Clear the content of the table.+ Future<void> clearAllContent({+ required Node tableNode,+ }) async {+ assert(tableNode.type == SimpleTableBlockKeys.type);++ if (tableNode.type != SimpleTableBlockKeys.type) {+ return;+ }++ for (var i = 0; i < tableNode.rowLength; i++) {+ await clearContentAtRowIndex(tableNode: tableNode, rowIndex: i);+ }+ }++ /// Copy the selected column to the clipboard.+ ///+ /// If the [clearContent] is true, the content of the column will be cleared after+ /// copying.+ Future<ClipboardServiceData?> copyColumn({+ required Node tableNode,+ required int columnIndex,+ bool clearContent = false,+ }) async {+ assert(tableNode.type == SimpleTableBlockKeys.type);++ if (tableNode.type != SimpleTableBlockKeys.type) {+ return null;+ }++ if (columnIndex < 0 || columnIndex >= tableNode.columnLength) {+ Log.warn('copy column: index out of range: $columnIndex');+ return null;+ }++ // the plain text content of the column+ final List<String> content = [];++ // the cells of the column+ final List<Node> cells = [];++ for (var i = 0; i < tableNode.rowLength; i++) {+ final row = tableNode.children[i];+ final cell = columnIndex >= row.children.length+ ? row.children.last+ : row.children[columnIndex];+ final startNode = cell.getFirstChildIndex();+ final endNode = cell.getLastChildIndex();+ if (startNode == null || endNode == null) {+ continue;+ }+ final plainText = getTextInSelection(+ Selection(+ start: Position(path: startNode.path),+ end: Position(+ path: endNode.path,+ offset: endNode.delta?.length ?? 0,+ ),+ ),+ );+ content.add(plainText.join('\n'));+ cells.add(cell.deepCopy());+ }++ final plainText = content.join('\n');+ final document = Document.blank()..insert([0], cells);++ if (clearContent) {+ await clearContentAtColumnIndex(+ tableNode: tableNode,+ columnIndex: columnIndex,+ );+ }++ return ClipboardServiceData(+ plainText: plainText,+ tableJson: jsonEncode(document.toJson()),+ );+ }++ /// Copy the selected row to the clipboard.+ ///+ /// If the [clearContent] is true, the content of the row will be cleared after+ /// copying.+ Future<ClipboardServiceData?> copyRow({+ required Node tableNode,+ required int rowIndex,+ bool clearContent = false,+ }) async {+ assert(tableNode.type == SimpleTableBlockKeys.type);++ if (tableNode.type != SimpleTableBlockKeys.type) {+ return null;+ }++ if (rowIndex < 0 || rowIndex >= tableNode.rowLength) {+ Log.warn('copy row: index out of range: $rowIndex');+ return null;+ }++ // the plain text content of the row+ final List<String> content = [];++ // the cells of the row+ final List<Node> cells = [];++ final row = tableNode.children[rowIndex];+ for (var i = 0; i < row.children.length; i++) {+ final cell = row.children[i];+ final startNode = cell.getFirstChildIndex();+ final endNode = cell.getLastChildIndex();+ if (startNode == null || endNode == null) {+ continue;+ }+ final plainText = getTextInSelection(+ Selection(+ start: Position(path: startNode.path),+ end: Position(+ path: endNode.path,+ offset: endNode.delta?.length ?? 0,+ ),+ ),+ );+ content.add(plainText.join('\n'));+ cells.add(cell.deepCopy());+ }++ final plainText = content.join('\n');+ final document = Document.blank()..insert([0], cells);++ if (clearContent) {+ await clearContentAtRowIndex(+ tableNode: tableNode,+ rowIndex: rowIndex,+ );+ }++ return ClipboardServiceData(+ plainText: plainText,+ tableJson: jsonEncode(document.toJson()),+ );+ }++ /// Copy the selected table to the clipboard.+ Future<ClipboardServiceData?> copyTable({+ required Node tableNode,+ bool clearContent = false,+ }) async {+ assert(tableNode.type == SimpleTableBlockKeys.type);++ if (tableNode.type != SimpleTableBlockKeys.type) {+ return null;+ }++ // the plain text content of the table+ final List<String> content = [];++ // the cells of the table+ final List<Node> cells = [];++ for (var i = 0; i < tableNode.rowLength; i++) {+ final row = tableNode.children[i];+ for (var j = 0; j < row.children.length; j++) {+ final cell = row.children[j];+ final startNode = cell.getFirstChildIndex();+ final endNode = cell.getLastChildIndex();+ if (startNode == null || endNode == null) {+ continue;+ }+ final plainText = getTextInSelection(+ Selection(+ start: Position(path: startNode.path),+ end: Position(+ path: endNode.path,+ offset: endNode.delta?.length ?? 0,+ ),+ ),+ );+ content.add(plainText.join('\n'));+ cells.add(cell.deepCopy());+ }+ }++ final plainText = content.join('\n');+ final document = Document.blank()..insert([0], cells);++ if (clearContent) {+ await clearAllContent(tableNode: tableNode);+ }++ return ClipboardServiceData(+ plainText: plainText,+ tableJson: jsonEncode(document.toJson()),+ );+ }++ /// Paste the clipboard content to the table column.+ Future<void> pasteColumn({+ required Node tableNode,+ required int columnIndex,+ }) async {+ assert(tableNode.type == SimpleTableBlockKeys.type);++ if (tableNode.type != SimpleTableBlockKeys.type) {+ return;+ }++ if (columnIndex < 0 || columnIndex >= tableNode.columnLength) {+ Log.warn('paste column: index out of range: $columnIndex');+ return;+ }++ final clipboardData = await getIt<ClipboardService>().getData();+ final tableJson = clipboardData.tableJson;+ if (tableJson == null) {+ return;+ }++ try {+ final document = Document.fromJson(jsonDecode(tableJson));+ final cells = document.root.children;+ final transaction = this.transaction;+ for (var i = 0; i < tableNode.rowLength; i++) {+ final nodes = i < cells.length ? cells[i].children : <Node>[];+ final row = tableNode.children[i];+ final cell = columnIndex >= row.children.length+ ? row.children.last+ : row.children[columnIndex];+ if (nodes.isNotEmpty) {+ transaction.insertNodes(+ cell.path.child(0),+ nodes,+ );+ transaction.deleteNodes(cell.children);+ }+ }+ await apply(transaction);+ } catch (e) {+ Log.error('paste column: failed to paste: $e');+ }+ }++ /// Paste the clipboard content to the table row.+ Future<void> pasteRow({+ required Node tableNode,+ required int rowIndex,+ }) async {+ assert(tableNode.type == SimpleTableBlockKeys.type);++ if (tableNode.type != SimpleTableBlockKeys.type) {+ return;+ }++ if (rowIndex < 0 || rowIndex >= tableNode.rowLength) {+ Log.warn('paste row: index out of range: $rowIndex');+ return;+ }++ final clipboardData = await getIt<ClipboardService>().getData();+ final tableJson = clipboardData.tableJson;+ if (tableJson == null) {+ return;+ }++ try {+ final document = Document.fromJson(jsonDecode(tableJson));+ final cells = document.root.children;+ final transaction = this.transaction;+ final row = tableNode.children[rowIndex];+ for (var i = 0; i < row.children.length; i++) {+ final nodes = i < cells.length ? cells[i].children : <Node>[];+ final cell = row.children[i];+ if (nodes.isNotEmpty) {+ transaction.insertNodes(+ cell.path.child(0),+ nodes,+ );+ transaction.deleteNodes(cell.children);+ }+ }+ await apply(transaction);+ } catch (e) {+ Log.error('paste row: failed to paste: $e');+ }+ }++ /// Paste the clipboard content to the table.+ Future<void> pasteTable({+ required Node tableNode,+ }) async {+ assert(tableNode.type == SimpleTableBlockKeys.type);++ if (tableNode.type != SimpleTableBlockKeys.type) {+ return;+ }++ final clipboardData = await getIt<ClipboardService>().getData();+ final tableJson = clipboardData.tableJson;+ if (tableJson == null) {+ return;+ }++ try {+ final document = Document.fromJson(jsonDecode(tableJson));+ final cells = document.root.children;+ final transaction = this.transaction;+ for (var i = 0; i < tableNode.rowLength; i++) {+ final row = tableNode.children[i];+ for (var j = 0; j < row.children.length; j++) {+ final cell = row.children[j];+ final node = i + j < cells.length ? cells[i + j] : null;+ if (node != null && node.children.isNotEmpty) {+ transaction.insertNodes(+ cell.path.child(0),+ node.children,+ );+ transaction.deleteNodes(cell.children);+ }+ }+ }+ await apply(transaction);+ } catch (e) {+ Log.error('paste row: failed to paste: $e');+ }+ }}diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_operations/simple_table_delete_operation.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_operations/simple_table_delete_operation.dartindex 6598ad5a41..d5dfc02474 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_operations/simple_table_delete_operation.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_operations/simple_table_delete_operation.dart@@ -17,37 +17,37 @@ extension TableDeletionOperations on EditorState {/// After:/// Row 1: | | | |Future<void> deleteRowInTable(- Node node,- int index, {+ Node tableNode,+ int rowIndex, {bool inMemoryUpdate = false,}) async {- assert(node.type == SimpleTableBlockKeys.type);+ assert(tableNode.type == SimpleTableBlockKeys.type);- if (node.type != SimpleTableBlockKeys.type) {+ if (tableNode.type != SimpleTableBlockKeys.type) {return;}- final rowLength = node.rowLength;- if (index < 0 || index >= rowLength) {+ final rowLength = tableNode.rowLength;+ if (rowIndex < 0 || rowIndex >= rowLength) {Log.warn(- 'delete row: index out of range: $index, row length: $rowLength',+ 'delete row: index out of range: $rowIndex, row length: $rowLength',);return;}- Log.info('delete row: $index in table ${node.id}');+ Log.info('delete row: $rowIndex in table ${tableNode.id}');- final attributes = node.mapTableAttributes(- node,+ final attributes = tableNode.mapTableAttributes(+ tableNode,type: TableMapOperationType.deleteRow,- index: index,+ index: rowIndex,);- final row = node.children[index];+ final row = tableNode.children[rowIndex];final transaction = this.transaction;transaction.deleteNode(row);if (attributes != null) {- transaction.updateNode(node, attributes);+ transaction.updateNode(tableNode, attributes);}await apply(transaction,@@ -71,40 +71,40 @@ extension TableDeletionOperations on EditorState {/// Row 1: | 0 | 1 |/// Row 2: | | |Future<void> deleteColumnInTable(- Node node,- int index, {+ Node tableNode,+ int columnIndex, {bool inMemoryUpdate = false,}) async {- assert(node.type == SimpleTableBlockKeys.type);+ assert(tableNode.type == SimpleTableBlockKeys.type);- if (node.type != SimpleTableBlockKeys.type) {+ if (tableNode.type != SimpleTableBlockKeys.type) {return;}- final rowLength = node.rowLength;- final columnLength = node.columnLength;- if (index < 0 || index >= columnLength) {+ final rowLength = tableNode.rowLength;+ final columnLength = tableNode.columnLength;+ if (columnIndex < 0 || columnIndex >= columnLength) {Log.warn(- 'delete column: index out of range: $index, column length: $columnLength',+ 'delete column: index out of range: $columnIndex, column length: $columnLength',);return;}- Log.info('delete column: $index in table ${node.id}');+ Log.info('delete column: $columnIndex in table ${tableNode.id}');- final attributes = node.mapTableAttributes(- node,+ final attributes = tableNode.mapTableAttributes(+ tableNode,type: TableMapOperationType.deleteColumn,- index: index,+ index: columnIndex,);final transaction = this.transaction;for (var i = 0; i < rowLength; i++) {- final row = node.children[i];- transaction.deleteNode(row.children[index]);+ final row = tableNode.children[i];+ transaction.deleteNode(row.children[columnIndex]);}if (attributes != null) {- transaction.updateNode(node, attributes);+ transaction.updateNode(tableNode, attributes);}await apply(transaction,diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_operations/simple_table_duplicate_operation.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_operations/simple_table_duplicate_operation.dartindex 69ab62f0b2..a2fdac4ca2 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_operations/simple_table_duplicate_operation.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_operations/simple_table_duplicate_operation.dart@@ -44,7 +44,7 @@ extension TableDuplicationOperations on EditorState {index: index,);- final newRow = node.children[index].copyWith();+ final newRow = node.children[index].deepCopy();final transaction = this.transaction;final path = index >= columnLength? node.children.last.path.next@@ -89,7 +89,7 @@ extension TableDuplicationOperations on EditorState {final path = index >= rowLength? row.children.last.path.next: row.children[index].path;- final newCell = row.children[index].copyWith();+ final newCell = row.children[index].deepCopy();transaction.insertNode(path,newCell,@@ -100,4 +100,22 @@ extension TableDuplicationOperations on EditorState {}await apply(transaction);}++ /// Duplicate the table.+ ///+ /// This function will duplicate the table and insert it after the original table.+ Future<void> duplicateTable({+ required Node tableNode,+ }) async {+ assert(tableNode.type == SimpleTableBlockKeys.type);++ if (tableNode.type != SimpleTableBlockKeys.type) {+ return;+ }++ final transaction = this.transaction;+ final newTable = tableNode.deepCopy();+ transaction.insertNode(tableNode.path.next, newTable);+ await apply(transaction);+ }}diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_operations/simple_table_header_operation.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_operations/simple_table_header_operation.dartindex 62b5879b1a..021181591f 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_operations/simple_table_header_operation.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_operations/simple_table_header_operation.dart@@ -4,34 +4,42 @@ import 'package:appflowy_editor/appflowy_editor.dart';extension TableHeaderOperation on EditorState {/// Toggle the enable header column of the table.- Future<void> toggleEnableHeaderColumn(Node node, bool enable) async {- assert(node.type == SimpleTableBlockKeys.type);+ Future<void> toggleEnableHeaderColumn({+ required Node tableNode,+ required bool enable,+ }) async {+ assert(tableNode.type == SimpleTableBlockKeys.type);- if (node.type != SimpleTableBlockKeys.type) {+ if (tableNode.type != SimpleTableBlockKeys.type) {return;}- Log.info('toggle enable header column: $enable in table ${node.id}');+ Log.info(+ 'toggle enable header column: $enable in table ${tableNode.id}',+ );final transaction = this.transaction;- transaction.updateNode(node, {+ transaction.updateNode(tableNode, {SimpleTableBlockKeys.enableHeaderColumn: enable,});await apply(transaction);}/// Toggle the enable header row of the table.- Future<void> toggleEnableHeaderRow(Node node, bool enable) async {- assert(node.type == SimpleTableBlockKeys.type);+ Future<void> toggleEnableHeaderRow({+ required Node tableNode,+ required bool enable,+ }) async {+ assert(tableNode.type == SimpleTableBlockKeys.type);- if (node.type != SimpleTableBlockKeys.type) {+ if (tableNode.type != SimpleTableBlockKeys.type) {return;}- Log.info('toggle enable header row: $enable in table ${node.id}');+ Log.info('toggle enable header row: $enable in table ${tableNode.id}');final transaction = this.transaction;- transaction.updateNode(node, {+ transaction.updateNode(tableNode, {SimpleTableBlockKeys.enableHeaderRow: enable,});await apply(transaction);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.dartindex bbc35f7852..683f9cbeea 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@@ -288,6 +288,72 @@ extension TableNodeExtension on Node {parentTableCellNode?.columnIndex == 0;}+ /// Whether the current cell is bold in the column.+ ///+ /// Default is false.+ bool get isInBoldColumn {+ final parentTableCellNode = this.parentTableCellNode;+ final parentTableNode = this.parentTableNode;+ if (parentTableCellNode == null ||+ parentTableNode == null ||+ parentTableNode.type != SimpleTableBlockKeys.type) {+ return false;+ }++ final columnIndex = parentTableCellNode.columnIndex;+ final columnBoldAttributes = parentTableNode.columnBoldAttributes;+ return columnBoldAttributes[columnIndex.toString()] ?? false;+ }++ /// Whether the current cell is bold in the row.+ ///+ /// Default is false.+ bool get isInBoldRow {+ final parentTableCellNode = this.parentTableCellNode;+ final parentTableNode = this.parentTableNode;+ if (parentTableCellNode == null ||+ parentTableNode == null ||+ parentTableNode.type != SimpleTableBlockKeys.type) {+ return false;+ }++ final rowIndex = parentTableCellNode.rowIndex;+ final rowBoldAttributes = parentTableNode.rowBoldAttributes;+ return rowBoldAttributes[rowIndex.toString()] ?? false;+ }++ /// Get the text color of the current cell in the column.+ ///+ /// Default is null.+ String? get textColorInColumn {+ final parentTableCellNode = this.parentTableCellNode;+ final parentTableNode = this.parentTableNode;+ if (parentTableCellNode == null ||+ parentTableNode == null ||+ parentTableNode.type != SimpleTableBlockKeys.type) {+ return null;+ }++ final columnIndex = parentTableCellNode.columnIndex;+ return parentTableNode.columnTextColors[columnIndex.toString()];+ }++ /// Get the text color of the current cell in the row.+ ///+ /// Default is null.+ String? get textColorInRow {+ final parentTableCellNode = this.parentTableCellNode;+ final parentTableNode = this.parentTableNode;+ if (parentTableCellNode == null ||+ parentTableNode == null ||+ parentTableNode.type != SimpleTableBlockKeys.type) {+ return null;+ }++ final rowIndex = parentTableCellNode.rowIndex;+ return parentTableNode.rowTextColors[rowIndex.toString()];+ }+/// Whether the current node is in the header row.////// Default is false.@@ -301,6 +367,7 @@ extension TableNodeExtension on Node {parentTableCellNode?.rowIndex == 0;}+ /// Get the row aligns.SimpleTableRowAlignMap get rowAligns {final rawRowAligns =parentTableNode?.attributes[SimpleTableBlockKeys.rowAligns];@@ -315,6 +382,7 @@ extension TableNodeExtension on Node {}}+ /// Get the row colors.SimpleTableColorMap get rowColors {final rawRowColors =parentTableNode?.attributes[SimpleTableBlockKeys.rowColors];@@ -329,6 +397,7 @@ extension TableNodeExtension on Node {}}+ /// Get the column colors.SimpleTableColorMap get columnColors {final rawColumnColors =parentTableNode?.attributes[SimpleTableBlockKeys.columnColors];@@ -343,7 +412,8 @@ extension TableNodeExtension on Node {}}- SimpleTableRowAlignMap get columnAligns {+ /// Get the column aligns.+ SimpleTableColumnAlignMap get columnAligns {final rawColumnAligns =parentTableNode?.attributes[SimpleTableBlockKeys.columnAligns];if (rawColumnAligns == null) {@@ -357,6 +427,7 @@ extension TableNodeExtension on Node {}}+ /// Get the column widths.SimpleTableColumnWidthMap get columnWidths {final rawColumnWidths =parentTableNode?.attributes[SimpleTableBlockKeys.columnWidths];@@ -371,6 +442,67 @@ extension TableNodeExtension on Node {}}+ /// Get the column text colors+ SimpleTableColorMap get columnTextColors {+ final rawColumnTextColors =+ parentTableNode?.attributes[SimpleTableBlockKeys.columnTextColors];+ if (rawColumnTextColors == null) {+ return SimpleTableColorMap();+ }+ try {+ return SimpleTableColorMap.from(rawColumnTextColors);+ } catch (e) {+ Log.warn('get column text colors: $e');+ return SimpleTableColorMap();+ }+ }++ /// Get the row text colors+ SimpleTableColorMap get rowTextColors {+ final rawRowTextColors =+ parentTableNode?.attributes[SimpleTableBlockKeys.rowTextColors];+ if (rawRowTextColors == null) {+ return SimpleTableColorMap();+ }+ try {+ return SimpleTableColorMap.from(rawRowTextColors);+ } catch (e) {+ Log.warn('get row text colors: $e');+ return SimpleTableColorMap();+ }+ }++ /// Get the column bold attributes+ SimpleTableAttributeMap get columnBoldAttributes {+ final rawColumnBoldAttributes =+ parentTableNode?.attributes[SimpleTableBlockKeys.columnBoldAttributes];+ if (rawColumnBoldAttributes == null) {+ return SimpleTableAttributeMap();+ }+ try {+ return SimpleTableAttributeMap.from(rawColumnBoldAttributes);+ } catch (e) {+ Log.warn('get column bold attributes: $e');+ return SimpleTableAttributeMap();+ }+ }++ /// Get the row bold attributes+ SimpleTableAttributeMap get rowBoldAttributes {+ final rawRowBoldAttributes =+ parentTableNode?.attributes[SimpleTableBlockKeys.rowBoldAttributes];+ if (rawRowBoldAttributes == null) {+ return SimpleTableAttributeMap();+ }+ try {+ return SimpleTableAttributeMap.from(rawRowBoldAttributes);+ } catch (e) {+ Log.warn('get row bold attributes: $e');+ return SimpleTableAttributeMap();+ }+ }++ /// Get the width of the table.double get width {double currentColumnWidth = 0;for (var i = 0; i < columnLength; i++) {@@ -656,4 +788,24 @@ extension TableNodeExtension on Node {return result;}++ /// Get first focusable child in the table cell.+ ///+ /// If the current node is not a table cell node, it will return null.+ Node? getFirstChildIndex() {+ if (children.isEmpty) {+ return this;+ }+ return children.first.getFirstChildIndex();+ }++ /// Get last focusable child in the table cell.+ ///+ /// If the current node is not a table cell node, it will return null.+ Node? getLastChildIndex() {+ if (children.isEmpty) {+ return this;+ }+ return children.last.getLastChildIndex();+ }}diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_operations/simple_table_reorder_operation.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_operations/simple_table_reorder_operation.dartindex 1bc2ad4ba7..02e384ac02 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_operations/simple_table_reorder_operation.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_operations/simple_table_reorder_operation.dart@@ -53,7 +53,7 @@ extension SimpleTableReorderOperation on EditorState {final from = row.children[fromIndex];final to = row.children[toIndex];final path = fromIndex < toIndex ? to.path.next : to.path;- transaction.insertNode(path, from.copyWith());+ transaction.insertNode(path, from.deepCopy());transaction.deleteNode(from);}if (attributes != null) {@@ -110,7 +110,7 @@ extension SimpleTableReorderOperation on EditorState {final from = tableNode.children[fromIndex];final to = tableNode.children[toIndex];final path = fromIndex < toIndex ? to.path.next : to.path;- transaction.insertNode(path, from.copyWith());+ transaction.insertNode(path, from.deepCopy());transaction.deleteNode(from);if (attributes != null) {transaction.updateNode(tableNode, attributes);diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_operations/simple_table_style_operation.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_operations/simple_table_style_operation.dartindex e28bd9f2fe..2b6bd73e62 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_operations/simple_table_style_operation.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_operations/simple_table_style_operation.dart@@ -117,24 +117,13 @@ extension TableOptionOperation on EditorState {required Node tableCellNode,required TableAlign align,}) async {- assert(tableCellNode.type == SimpleTableCellBlockKeys.type);-- final parentTableNode = tableCellNode.parentTableNode;-- if (parentTableNode == null) {- Log.warn('parent table node is null');- return;- }-- final transaction = this.transaction;final columnIndex = tableCellNode.columnIndex;- final attributes = parentTableNode.attributes.mergeValues(- SimpleTableBlockKeys.columnAligns,- parentTableNode.columnAligns,+ await _updateTableAttributes(+ tableCellNode: tableCellNode,+ attributeKey: SimpleTableBlockKeys.columnAligns,+ source: tableCellNode.columnAligns,duplicatedEntry: MapEntry(columnIndex.toString(), align.key),);- transaction.updateNode(parentTableNode, attributes);- await apply(transaction);}/// Update the align of the row at the index where the table cell node is located.@@ -155,23 +144,40 @@ extension TableOptionOperation on EditorState {required Node tableCellNode,required TableAlign align,}) async {- assert(tableCellNode.type == SimpleTableCellBlockKeys.type);+ final rowIndex = tableCellNode.rowIndex;+ await _updateTableAttributes(+ tableCellNode: tableCellNode,+ attributeKey: SimpleTableBlockKeys.rowAligns,+ source: tableCellNode.rowAligns,+ duplicatedEntry: MapEntry(rowIndex.toString(), align.key),+ );+ }- final parentTableNode = tableCellNode.parentTableNode;+ /// Update the align of the table.+ ///+ /// This function will update the align of the table.+ ///+ /// The align is the align to be updated.+ Future<void> updateTableAlign({+ required Node tableNode,+ required TableAlign align,+ }) async {+ assert(tableNode.type == SimpleTableBlockKeys.type);- if (parentTableNode == null) {- Log.warn('parent table node is null');+ if (tableNode.type != SimpleTableBlockKeys.type) {return;}final transaction = this.transaction;- final rowIndex = tableCellNode.rowIndex;- final attributes = parentTableNode.attributes.mergeValues(- SimpleTableBlockKeys.rowAligns,- parentTableNode.rowAligns,- duplicatedEntry: MapEntry(rowIndex.toString(), align.key),- );- transaction.updateNode(parentTableNode, attributes);+ Attributes attributes = tableNode.attributes;+ for (var i = 0; i < tableNode.columnLength; i++) {+ attributes = attributes.mergeValues(+ SimpleTableBlockKeys.columnAligns,+ attributes[SimpleTableBlockKeys.columnAligns],+ duplicatedEntry: MapEntry(i.toString(), align.key),+ );+ }+ transaction.updateNode(tableNode, attributes);await apply(transaction);}@@ -180,29 +186,13 @@ extension TableOptionOperation on EditorState {required Node tableCellNode,required String color,}) async {- assert(tableCellNode.type == SimpleTableCellBlockKeys.type);-- final parentTableNode = tableCellNode.parentTableNode;-- if (parentTableNode == null) {- Log.warn('parent table node is null');- return;- }-final columnIndex = tableCellNode.columnIndex;-- Log.info(- 'update column background color: $color at column $columnIndex in table ${parentTableNode.id}',- );-- final transaction = this.transaction;- final attributes = parentTableNode.attributes.mergeValues(- SimpleTableBlockKeys.columnColors,- parentTableNode.columnColors,+ await _updateTableAttributes(+ tableCellNode: tableCellNode,+ attributeKey: SimpleTableBlockKeys.columnColors,+ source: tableCellNode.columnColors,duplicatedEntry: MapEntry(columnIndex.toString(), color),);- transaction.updateNode(parentTableNode, attributes);- await apply(transaction);}/// Update the background color of the row at the index where the table cell node is located.@@ -210,30 +200,13 @@ extension TableOptionOperation on EditorState {required Node tableCellNode,required String color,}) async {- assert(tableCellNode.type == SimpleTableCellBlockKeys.type);-- final parentTableNode = tableCellNode.parentTableNode;-- if (parentTableNode == null) {- Log.warn('parent table node is null');- return;- }-final rowIndex = tableCellNode.rowIndex;-- Log.info(- 'update row background color: $color at row $rowIndex in table ${parentTableNode.id}',- );-- final transaction = this.transaction;-- final attributes = parentTableNode.attributes.mergeValues(- SimpleTableBlockKeys.rowColors,- parentTableNode.rowColors,+ await _updateTableAttributes(+ tableCellNode: tableCellNode,+ attributeKey: SimpleTableBlockKeys.rowColors,+ source: tableCellNode.rowColors,duplicatedEntry: MapEntry(rowIndex.toString(), color),);- transaction.updateNode(parentTableNode, attributes);- await apply(transaction);}/// Set the column width of the table to the page width.@@ -252,11 +225,6 @@ extension TableOptionOperation on EditorState {Future<void> setColumnWidthToPageWidth({required Node tableNode,}) async {- // Disable in mobile- if (UniversalPlatform.isMobile) {- return;- }-final columnLength = tableNode.columnLength;double? pageWidth = tableNode.renderBox?.size.width;if (pageWidth == null) {@@ -322,4 +290,98 @@ extension TableOptionOperation on EditorState {});await apply(transaction);}++ /// Update the bold attribute of the column+ Future<void> toggleColumnBoldAttribute({+ required Node tableCellNode,+ required bool isBold,+ }) async {+ final columnIndex = tableCellNode.columnIndex;+ await _updateTableAttributes(+ tableCellNode: tableCellNode,+ attributeKey: SimpleTableBlockKeys.columnBoldAttributes,+ source: tableCellNode.columnBoldAttributes,+ duplicatedEntry: MapEntry(columnIndex.toString(), isBold),+ );+ }++ /// Update the bold attribute of the row+ Future<void> toggleRowBoldAttribute({+ required Node tableCellNode,+ required bool isBold,+ }) async {+ final rowIndex = tableCellNode.rowIndex;+ await _updateTableAttributes(+ tableCellNode: tableCellNode,+ attributeKey: SimpleTableBlockKeys.rowBoldAttributes,+ source: tableCellNode.rowBoldAttributes,+ duplicatedEntry: MapEntry(rowIndex.toString(), isBold),+ );+ }++ /// Update the text color of the column+ Future<void> updateColumnTextColor({+ required Node tableCellNode,+ required String color,+ }) async {+ final columnIndex = tableCellNode.columnIndex;+ await _updateTableAttributes(+ tableCellNode: tableCellNode,+ attributeKey: SimpleTableBlockKeys.columnTextColors,+ source: tableCellNode.columnTextColors,+ duplicatedEntry: MapEntry(columnIndex.toString(), color),+ );+ }++ /// Update the text color of the row+ Future<void> updateRowTextColor({+ required Node tableCellNode,+ required String color,+ }) async {+ final rowIndex = tableCellNode.rowIndex;+ await _updateTableAttributes(+ tableCellNode: tableCellNode,+ attributeKey: SimpleTableBlockKeys.rowTextColors,+ source: tableCellNode.rowTextColors,+ duplicatedEntry: MapEntry(rowIndex.toString(), color),+ );+ }++ /// Update the attributes of the table.+ ///+ /// This function is used to update the attributes of the table.+ ///+ /// The attribute key is the key of the attribute to be updated.+ /// The source is the original value of the attribute.+ /// The duplicatedEntry is the entry of the attribute to be updated.+ Future<void> _updateTableAttributes({+ required Node tableCellNode,+ required String attributeKey,+ required Map<String, dynamic> source,+ MapEntry? duplicatedEntry,+ }) async {+ assert(tableCellNode.type == SimpleTableCellBlockKeys.type);++ final parentTableNode = tableCellNode.parentTableNode;++ if (parentTableNode == null) {+ Log.warn('parent table node is null');+ return;+ }++ final columnIndex = tableCellNode.columnIndex;++ Log.info(+ 'update $attributeKey: $source at column $columnIndex in table ${parentTableNode.id}',+ );++ final transaction = this.transaction;+ final attributes = parentTableNode.attributes.mergeValues(+ attributeKey,+ source,+ duplicatedEntry: duplicatedEntry,+ );+ transaction.updateNode(parentTableNode, attributes);+ await apply(transaction);+ }}diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/_desktop_simple_table_widget.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/_desktop_simple_table_widget.dartnew file mode 100644index 0000000000..6e640e4561--- /dev/null+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/_desktop_simple_table_widget.dart@@ -0,0 +1,165 @@+import 'package:appflowy/plugins/document/presentation/editor_plugins/simple_table/simple_table.dart';+import 'package:appflowy_editor/appflowy_editor.dart';+import 'package:flutter/material.dart';+import 'package:provider/provider.dart';++class DesktopSimpleTableWidget extends StatefulWidget {+ const DesktopSimpleTableWidget({+ super.key,+ required this.simpleTableContext,+ required this.node,+ this.enableAddColumnButton = true,+ this.enableAddRowButton = true,+ this.enableAddColumnAndRowButton = true,+ this.enableHoverEffect = true,+ this.isFeedback = false,+ });++ /// Refer to [SimpleTableWidget.node].+ final Node node;++ /// Refer to [SimpleTableWidget.simpleTableContext].+ final SimpleTableContext simpleTableContext;++ /// Refer to [SimpleTableWidget.enableAddColumnButton].+ final bool enableAddColumnButton;++ /// Refer to [SimpleTableWidget.enableAddRowButton].+ final bool enableAddRowButton;++ /// Refer to [SimpleTableWidget.enableAddColumnAndRowButton].+ final bool enableAddColumnAndRowButton;++ /// Refer to [SimpleTableWidget.enableHoverEffect].+ final bool enableHoverEffect;++ /// Refer to [SimpleTableWidget.isFeedback].+ final bool isFeedback;++ @override+ State<DesktopSimpleTableWidget> createState() =>+ _DesktopSimpleTableWidgetState();+}++class _DesktopSimpleTableWidgetState extends State<DesktopSimpleTableWidget> {+ SimpleTableContext get simpleTableContext => widget.simpleTableContext;++ final scrollController = ScrollController();+ late final editorState = context.read<EditorState>();++ @override+ void dispose() {+ scrollController.dispose();++ super.dispose();+ }++ @override+ Widget build(BuildContext context) {+ return widget.isFeedback ? _buildFeedbackTable() : _buildDesktopTable();+ }++ Widget _buildFeedbackTable() {+ return Provider.value(+ value: simpleTableContext,+ child: IntrinsicWidth(+ child: IntrinsicHeight(+ child: Column(+ mainAxisSize: MainAxisSize.min,+ crossAxisAlignment: CrossAxisAlignment.start,+ children: _buildRows(),+ ),+ ),+ ),+ );+ }++ Widget _buildDesktopTable() {+ // table content+ Widget child = Scrollbar(+ controller: scrollController,+ child: SingleChildScrollView(+ controller: scrollController,+ scrollDirection: Axis.horizontal,+ child: Padding(+ padding: SimpleTableConstants.tablePadding,+ // IntrinsicWidth and IntrinsicHeight are used to make the table size fit the content.+ child: IntrinsicWidth(+ child: IntrinsicHeight(+ child: Column(+ mainAxisSize: MainAxisSize.min,+ crossAxisAlignment: CrossAxisAlignment.start,+ children: _buildRows(),+ ),+ ),+ ),+ ),+ ),+ );++ if (widget.enableHoverEffect) {+ child = MouseRegion(+ onEnter: (event) =>+ simpleTableContext.isHoveringOnTableArea.value = true,+ onExit: (event) {+ simpleTableContext.isHoveringOnTableArea.value = false;+ },+ child: Provider.value(+ value: simpleTableContext,+ child: Stack(+ children: [+ MouseRegion(+ hitTestBehavior: HitTestBehavior.opaque,+ onEnter: (event) =>+ simpleTableContext.isHoveringOnColumnsAndRows.value = true,+ onExit: (event) {+ simpleTableContext.isHoveringOnColumnsAndRows.value = false;+ simpleTableContext.hoveringTableCell.value = null;+ },+ child: child,+ ),+ if (editorState.editable) ...[+ if (widget.enableAddColumnButton)+ SimpleTableAddColumnHoverButton(+ editorState: editorState,+ tableNode: widget.node,+ ),+ if (widget.enableAddRowButton)+ SimpleTableAddRowHoverButton(+ editorState: editorState,+ tableNode: widget.node,+ ),+ if (widget.enableAddColumnAndRowButton)+ SimpleTableAddColumnAndRowHoverButton(+ editorState: editorState,+ node: widget.node,+ ),+ ],+ ],+ ),+ ),+ );+ }++ return child;+ }++ List<Widget> _buildRows() {+ final List<Widget> rows = [];++ if (SimpleTableConstants.borderType == SimpleTableBorderRenderType.table) {+ rows.add(const SimpleTableColumnDivider());+ }++ for (final child in widget.node.children) {+ rows.add(editorState.renderer.build(context, child));++ if (SimpleTableConstants.borderType ==+ SimpleTableBorderRenderType.table) {+ rows.add(const SimpleTableColumnDivider());+ }+ }++ return rows;+ }+}diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/_mobile_simple_table_widget.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/_mobile_simple_table_widget.dartnew file mode 100644index 0000000000..41ae29c61c--- /dev/null+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/_mobile_simple_table_widget.dart@@ -0,0 +1,114 @@+import 'package:appflowy/plugins/document/presentation/editor_plugins/simple_table/simple_table.dart';+import 'package:appflowy_editor/appflowy_editor.dart';+import 'package:flutter/material.dart';+import 'package:provider/provider.dart';++class MobileSimpleTableWidget extends StatefulWidget {+ const MobileSimpleTableWidget({+ super.key,+ required this.simpleTableContext,+ required this.node,+ this.enableAddColumnButton = true,+ this.enableAddRowButton = true,+ this.enableAddColumnAndRowButton = true,+ this.enableHoverEffect = true,+ this.isFeedback = false,+ });++ /// Refer to [SimpleTableWidget.node].+ final Node node;++ /// Refer to [SimpleTableWidget.simpleTableContext].+ final SimpleTableContext simpleTableContext;++ /// Refer to [SimpleTableWidget.enableAddColumnButton].+ final bool enableAddColumnButton;++ /// Refer to [SimpleTableWidget.enableAddRowButton].+ final bool enableAddRowButton;++ /// Refer to [SimpleTableWidget.enableAddColumnAndRowButton].+ final bool enableAddColumnAndRowButton;++ /// Refer to [SimpleTableWidget.enableHoverEffect].+ final bool enableHoverEffect;++ /// Refer to [SimpleTableWidget.isFeedback].+ final bool isFeedback;++ @override+ State<MobileSimpleTableWidget> createState() =>+ _MobileSimpleTableWidgetState();+}++class _MobileSimpleTableWidgetState extends State<MobileSimpleTableWidget> {+ SimpleTableContext get simpleTableContext => widget.simpleTableContext;++ final scrollController = ScrollController();+ late final editorState = context.read<EditorState>();++ @override+ void dispose() {+ scrollController.dispose();++ super.dispose();+ }++ @override+ Widget build(BuildContext context) {+ return widget.isFeedback ? _buildFeedbackTable() : _buildMobileTable();+ }++ Widget _buildFeedbackTable() {+ return Provider.value(+ value: simpleTableContext,+ child: IntrinsicWidth(+ child: IntrinsicHeight(+ child: Column(+ mainAxisSize: MainAxisSize.min,+ crossAxisAlignment: CrossAxisAlignment.start,+ children: _buildRows(),+ ),+ ),+ ),+ );+ }++ Widget _buildMobileTable() {+ return Provider.value(+ value: simpleTableContext,+ child: SingleChildScrollView(+ controller: scrollController,+ scrollDirection: Axis.horizontal,+ child: IntrinsicWidth(+ child: IntrinsicHeight(+ child: Column(+ mainAxisSize: MainAxisSize.min,+ crossAxisAlignment: CrossAxisAlignment.start,+ children: _buildRows(),+ ),+ ),+ ),+ ),+ );+ }++ List<Widget> _buildRows() {+ final List<Widget> rows = [];++ if (SimpleTableConstants.borderType == SimpleTableBorderRenderType.table) {+ rows.add(const SimpleTableColumnDivider());+ }++ for (final child in widget.node.children) {+ rows.add(editorState.renderer.build(context, child));++ if (SimpleTableConstants.borderType ==+ SimpleTableBorderRenderType.table) {+ rows.add(const SimpleTableColumnDivider());+ }+ }++ return rows;+ }+}diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/_simple_table_bottom_sheet_actions.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/_simple_table_bottom_sheet_actions.dartnew file mode 100644index 0000000000..80fa91e658--- /dev/null+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/_simple_table_bottom_sheet_actions.dart@@ -0,0 +1,1274 @@+import 'package:appflowy/generated/flowy_svgs.g.dart';+import 'package:appflowy/mobile/presentation/base/animated_gesture.dart';+import 'package:appflowy/plugins/document/presentation/editor_plugins/actions/block_action_option_cubit.dart';+import 'package:appflowy/plugins/document/presentation/editor_plugins/actions/option/option_actions.dart';+import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/clipboard_service.dart';+import 'package:appflowy/plugins/document/presentation/editor_plugins/simple_table/simple_table.dart';+import 'package:appflowy/startup/startup.dart';+import 'package:appflowy_backend/log.dart';+import 'package:appflowy_editor/appflowy_editor.dart';+import 'package:flowy_infra_ui/flowy_infra_ui.dart';+import 'package:flutter/cupertino.dart';+import 'package:flutter/material.dart';+import 'package:provider/provider.dart';++/// Base class for all simple table bottom sheet actions+abstract class ISimpleTableBottomSheetActions extends StatelessWidget {+ const ISimpleTableBottomSheetActions({+ super.key,+ required this.type,+ required this.cellNode,+ required this.editorState,+ });++ final SimpleTableMoreActionType type;+ final Node cellNode;+ final EditorState editorState;+}++/// Quick actions for the table cell+///+/// - Copy+/// - Paste+/// - Cut+/// - Delete+class SimpleTableCellQuickActions extends ISimpleTableBottomSheetActions {+ const SimpleTableCellQuickActions({+ super.key,+ required super.type,+ required super.cellNode,+ required super.editorState,+ });++ @override+ Widget build(BuildContext context) {+ return SizedBox(+ height: SimpleTableConstants.actionSheetQuickActionSectionHeight,+ child: Row(+ mainAxisAlignment: MainAxisAlignment.spaceEvenly,+ children: [+ SimpleTableQuickAction(+ type: SimpleTableMoreAction.cut,+ onTap: () => _onActionTap(+ context,+ SimpleTableMoreAction.cut,+ ),+ ),+ SimpleTableQuickAction(+ type: SimpleTableMoreAction.copy,+ onTap: () => _onActionTap(+ context,+ SimpleTableMoreAction.copy,+ ),+ ),+ FutureBuilder(+ future: getIt<ClipboardService>().getData(),+ builder: (context, snapshot) {+ final hasContent = snapshot.data?.tableJson != null;+ return SimpleTableQuickAction(+ type: SimpleTableMoreAction.paste,+ isEnabled: hasContent,+ onTap: () => _onActionTap(+ context,+ SimpleTableMoreAction.paste,+ ),+ );+ },+ ),+ SimpleTableQuickAction(+ type: SimpleTableMoreAction.delete,+ onTap: () => _onActionTap(+ context,+ SimpleTableMoreAction.delete,+ ),+ ),+ ],+ ),+ );+ }++ void _onActionTap(BuildContext context, SimpleTableMoreAction action) {+ final tableNode = cellNode.parentTableNode;+ if (tableNode == null) {+ Log.error('unable to find table node when performing action: $action');+ return;+ }++ switch (action) {+ case SimpleTableMoreAction.cut:+ _onCut(tableNode);+ case SimpleTableMoreAction.copy:+ _onCopy(tableNode);+ case SimpleTableMoreAction.paste:+ _onPaste(tableNode);+ case SimpleTableMoreAction.delete:+ _onDelete(tableNode);+ default:+ assert(false, 'Unsupported action: $type');+ }++ // close the action menu+ Navigator.of(context).pop();+ }++ Future<void> _onCut(Node tableNode) async {+ ClipboardServiceData? data;++ switch (type) {+ case SimpleTableMoreActionType.column:+ data = await editorState.copyColumn(+ tableNode: tableNode,+ columnIndex: cellNode.columnIndex,+ clearContent: true,+ );+ case SimpleTableMoreActionType.row:+ data = await editorState.copyRow(+ tableNode: tableNode,+ rowIndex: cellNode.rowIndex,+ clearContent: true,+ );+ }++ if (data != null) {+ await getIt<ClipboardService>().setData(data);+ }+ }++ Future<void> _onCopy(+ Node tableNode,+ ) async {+ ClipboardServiceData? data;++ switch (type) {+ case SimpleTableMoreActionType.column:+ data = await editorState.copyColumn(+ tableNode: tableNode,+ columnIndex: cellNode.columnIndex,+ );+ case SimpleTableMoreActionType.row:+ data = await editorState.copyRow(+ tableNode: tableNode,+ rowIndex: cellNode.rowIndex,+ );+ }++ if (data != null) {+ await getIt<ClipboardService>().setData(data);+ }+ }++ void _onPaste(Node tableNode) {+ switch (type) {+ case SimpleTableMoreActionType.column:+ editorState.pasteColumn(+ tableNode: tableNode,+ columnIndex: cellNode.columnIndex,+ );+ case SimpleTableMoreActionType.row:+ editorState.pasteRow(+ tableNode: tableNode,+ rowIndex: cellNode.rowIndex,+ );+ }+ }++ void _onDelete(Node tableNode) {+ switch (type) {+ case SimpleTableMoreActionType.column:+ editorState.deleteColumnInTable(+ tableNode,+ cellNode.columnIndex,+ );+ case SimpleTableMoreActionType.row:+ editorState.deleteRowInTable(+ tableNode,+ cellNode.rowIndex,+ );+ }+ }+}++class SimpleTableQuickAction extends StatelessWidget {+ const SimpleTableQuickAction({+ super.key,+ required this.type,+ required this.onTap,+ this.isEnabled = true,+ });++ final SimpleTableMoreAction type;+ final VoidCallback onTap;+ final bool isEnabled;++ @override+ Widget build(BuildContext context) {+ return Opacity(+ opacity: isEnabled ? 1.0 : 0.5,+ child: AnimatedGestureDetector(+ onTapUp: isEnabled ? onTap : null,+ child: FlowySvg(+ type.leftIconSvg,+ blendMode: null,+ size: const Size.square(24),+ ),+ ),+ );+ }+}++/// Insert actions+///+/// - Column: Insert left or insert right+/// - Row: Insert above or insert below+class SimpleTableInsertActions extends ISimpleTableBottomSheetActions {+ const SimpleTableInsertActions({+ super.key,+ required super.type,+ required super.cellNode,+ required super.editorState,+ });++ @override+ Widget build(BuildContext context) {+ return Container(+ padding: const EdgeInsets.symmetric(horizontal: 16),+ height: SimpleTableConstants.actionSheetInsertSectionHeight,+ child: _buildAction(context),+ );+ }++ Widget _buildAction(BuildContext context) {+ return switch (type) {+ SimpleTableMoreActionType.row => Row(+ children: [+ SimpleTableInsertAction(+ type: SimpleTableMoreAction.insertAbove,+ enableLeftBorder: true,+ onTap: () => _onActionTap(+ context,+ SimpleTableMoreAction.insertAbove,+ ),+ ),+ const HSpace(2),+ SimpleTableInsertAction(+ type: SimpleTableMoreAction.insertBelow,+ enableRightBorder: true,+ onTap: () => _onActionTap(+ context,+ SimpleTableMoreAction.insertBelow,+ ),+ ),+ ],+ ),+ SimpleTableMoreActionType.column => Row(+ children: [+ SimpleTableInsertAction(+ type: SimpleTableMoreAction.insertLeft,+ enableLeftBorder: true,+ onTap: () => _onActionTap(+ context,+ SimpleTableMoreAction.insertLeft,+ ),+ ),+ const HSpace(2),+ SimpleTableInsertAction(+ type: SimpleTableMoreAction.insertRight,+ enableRightBorder: true,+ onTap: () => _onActionTap(+ context,+ SimpleTableMoreAction.insertRight,+ ),+ ),+ ],+ ),+ };+ }++ void _onActionTap(BuildContext context, SimpleTableMoreAction type) {+ final simpleTableContext = context.read<SimpleTableContext>();+ final tableNode = cellNode.parentTableNode;+ if (tableNode == null) {+ Log.error('unable to find table node when performing action: $type');+ return;+ }++ switch (type) {+ case SimpleTableMoreAction.insertAbove:+ // update the highlight status for the selecting row+ simpleTableContext.selectingRow.value = cellNode.rowIndex + 1;+ editorState.insertRowInTable(+ tableNode,+ cellNode.rowIndex,+ );+ case SimpleTableMoreAction.insertBelow:+ editorState.insertRowInTable(+ tableNode,+ cellNode.rowIndex + 1,+ );+ case SimpleTableMoreAction.insertLeft:+ // update the highlight status for the selecting column+ simpleTableContext.selectingColumn.value = cellNode.columnIndex + 1;+ editorState.insertColumnInTable(+ tableNode,+ cellNode.columnIndex,+ );+ case SimpleTableMoreAction.insertRight:+ editorState.insertColumnInTable(+ tableNode,+ cellNode.columnIndex + 1,+ );+ default:+ assert(false, 'Unsupported action: $type');+ }+ }+}++class SimpleTableInsertAction extends StatelessWidget {+ const SimpleTableInsertAction({+ super.key,+ required this.type,+ this.enableLeftBorder = false,+ this.enableRightBorder = false,+ required this.onTap,+ });++ final SimpleTableMoreAction type;+ final bool enableLeftBorder;+ final bool enableRightBorder;+ final void Function() onTap;++ @override+ Widget build(BuildContext context) {+ return Expanded(+ child: DecoratedBox(+ decoration: ShapeDecoration(+ color: context.simpleTableInsertActionBackgroundColor,+ shape: _buildBorder(),+ ),+ child: AnimatedGestureDetector(+ onTapUp: onTap,+ child: Column(+ mainAxisAlignment: MainAxisAlignment.center,+ children: [+ Padding(+ padding: const EdgeInsets.all(1),+ child: FlowySvg(+ type.leftIconSvg,+ size: const Size.square(22),+ ),+ ),+ FlowyText(+ type.name,+ fontSize: 12,+ figmaLineHeight: 16,+ ),+ ],+ ),+ ),+ ),+ );+ }++ RoundedRectangleBorder _buildBorder() {+ const radius = Radius.circular(+ SimpleTableConstants.actionSheetButtonRadius,+ );+ return RoundedRectangleBorder(+ borderRadius: BorderRadius.only(+ topLeft: enableLeftBorder ? radius : Radius.zero,+ bottomLeft: enableLeftBorder ? radius : Radius.zero,+ topRight: enableRightBorder ? radius : Radius.zero,+ bottomRight: enableRightBorder ? radius : Radius.zero,+ ),+ );+ }+}++/// Cell Action buttons+///+/// - Distribute columns evenly+/// - Set to page width+/// - Duplicate row+/// - Duplicate column+/// - Clear contents+class SimpleTableCellActionButtons extends ISimpleTableBottomSheetActions {+ const SimpleTableCellActionButtons({+ super.key,+ required super.type,+ required super.cellNode,+ required super.editorState,+ });++ @override+ Widget build(BuildContext context) {+ return Padding(+ padding: const EdgeInsets.symmetric(horizontal: 16),+ child: Column(+ children: _buildActions(context),+ ),+ );+ }++ List<Widget> _buildActions(BuildContext context) {+ // the actions are grouped into different sections+ // we need to get the index of the table cell node+ // and the length of the columns and rows+ final (index, columnLength, rowLength) = switch (type) {+ SimpleTableMoreActionType.row => (+ cellNode.rowIndex,+ cellNode.columnLength,+ cellNode.rowLength,+ ),+ SimpleTableMoreActionType.column => (+ cellNode.columnIndex,+ cellNode.rowLength,+ cellNode.columnLength,+ ),+ };+ final actionGroups = type.buildMobileActions(+ index: index,+ columnLength: columnLength,+ rowLength: rowLength,+ );+ final List<Widget> widgets = [];++ for (final (actionGroupIndex, actionGroup) in actionGroups.indexed) {+ for (final (index, action) in actionGroup.indexed) {+ widgets.add(+ // enable the corner border if the cell is the first or last in the group+ switch (action) {+ SimpleTableMoreAction.enableHeaderColumn =>+ SimpleTableHeaderActionButton(+ type: action,+ isEnabled: cellNode.isHeaderColumnEnabled,+ onTap: (value) => _onActionTap(+ context,+ action: action,+ toggleHeaderValue: value,+ ),+ ),+ SimpleTableMoreAction.enableHeaderRow =>+ SimpleTableHeaderActionButton(+ type: action,+ isEnabled: cellNode.isHeaderRowEnabled,+ onTap: (value) => _onActionTap(+ context,+ action: action,+ toggleHeaderValue: value,+ ),+ ),+ _ => SimpleTableActionButton(+ type: action,+ enableTopBorder: index == 0,+ enableBottomBorder: index == actionGroup.length - 1,+ onTap: () => _onActionTap(+ context,+ action: action,+ ),+ ),+ },+ );+ // if the action is not the first or last in the group, add a divider+ if (index != actionGroup.length - 1) {+ widgets.add(const FlowyDivider());+ }+ }++ // add padding to separate the action groups+ if (actionGroupIndex != actionGroups.length - 1) {+ widgets.add(const VSpace(16));+ }+ }++ return widgets;+ }++ void _onActionTap(+ BuildContext context, {+ required SimpleTableMoreAction action,+ bool toggleHeaderValue = false,+ }) {+ final tableNode = cellNode.parentTableNode;+ if (tableNode == null) {+ Log.error('unable to find table node when performing action: $action');+ return;+ }++ switch (action) {+ case SimpleTableMoreAction.enableHeaderColumn:+ editorState.toggleEnableHeaderColumn(+ tableNode: tableNode,+ enable: toggleHeaderValue,+ );+ case SimpleTableMoreAction.enableHeaderRow:+ editorState.toggleEnableHeaderRow(+ tableNode: tableNode,+ enable: toggleHeaderValue,+ );+ case SimpleTableMoreAction.distributeColumnsEvenly:+ editorState.distributeColumnWidthToPageWidth(tableNode: tableNode);+ case SimpleTableMoreAction.setToPageWidth:+ editorState.setColumnWidthToPageWidth(tableNode: tableNode);+ case SimpleTableMoreAction.duplicateRow:+ editorState.duplicateRowInTable(+ tableNode,+ cellNode.rowIndex,+ );+ case SimpleTableMoreAction.duplicateColumn:+ editorState.duplicateColumnInTable(+ tableNode,+ cellNode.columnIndex,+ );+ case SimpleTableMoreAction.clearContents:+ switch (type) {+ case SimpleTableMoreActionType.column:+ editorState.clearContentAtColumnIndex(+ tableNode: tableNode,+ columnIndex: cellNode.columnIndex,+ );+ case SimpleTableMoreActionType.row:+ editorState.clearContentAtRowIndex(+ tableNode: tableNode,+ rowIndex: cellNode.rowIndex,+ );+ }+ default:+ assert(false, 'Unsupported action: $action');+ break;+ }++ // close the action menu+ Navigator.of(context).pop();+ }+}++/// Header action button+///+/// - Enable header column+/// - Enable header row+///+/// Notes: These actions are only available for the first column or first row+class SimpleTableHeaderActionButton extends StatefulWidget {+ const SimpleTableHeaderActionButton({+ super.key,+ required this.isEnabled,+ required this.type,+ this.onTap,+ });++ final bool isEnabled;+ final SimpleTableMoreAction type;+ final void Function(bool value)? onTap;++ @override+ State<SimpleTableHeaderActionButton> createState() =>+ _SimpleTableHeaderActionButtonState();+}++class _SimpleTableHeaderActionButtonState+ extends State<SimpleTableHeaderActionButton> {+ bool value = false;++ @override+ void initState() {+ super.initState();++ value = widget.isEnabled;+ }++ @override+ Widget build(BuildContext context) {+ return SimpleTableActionButton(+ type: widget.type,+ enableTopBorder: true,+ enableBottomBorder: true,+ onTap: _toggle,+ rightIconBuilder: (context) {+ return Container(+ width: 36,+ height: 24,+ margin: const EdgeInsets.only(right: 16),+ child: FittedBox(+ fit: BoxFit.fill,+ child: CupertinoSwitch(+ value: value,+ activeColor: Theme.of(context).colorScheme.primary,+ onChanged: (_) {},+ ),+ ),+ );+ },+ );+ }++ void _toggle() {+ setState(() {+ value = !value;+ });++ widget.onTap?.call(value);+ }+}++/// Align text action button+///+/// - Align text to left+/// - Align text to center+/// - Align text to right+///+/// Notes: These actions are only available for the table+class SimpleTableAlignActionButton extends StatefulWidget {+ const SimpleTableAlignActionButton({+ super.key,+ required this.onTap,+ });++ final VoidCallback onTap;++ @override+ State<SimpleTableAlignActionButton> createState() =>+ _SimpleTableAlignActionButtonState();+}++class _SimpleTableAlignActionButtonState+ extends State<SimpleTableAlignActionButton> {+ @override+ Widget build(BuildContext context) {+ return SimpleTableActionButton(+ type: SimpleTableMoreAction.align,+ enableTopBorder: true,+ enableBottomBorder: true,+ onTap: widget.onTap,+ rightIconBuilder: (context) {+ return const Padding(+ padding: EdgeInsets.only(right: 16),+ child: FlowySvg(FlowySvgs.m_aa_arrow_right_s),+ );+ },+ );+ }+}++class SimpleTableActionButton extends StatelessWidget {+ const SimpleTableActionButton({+ super.key,+ required this.type,+ this.enableTopBorder = false,+ this.enableBottomBorder = false,+ this.rightIconBuilder,+ this.onTap,+ });++ final SimpleTableMoreAction type;+ final bool enableTopBorder;+ final bool enableBottomBorder;+ final WidgetBuilder? rightIconBuilder;+ final void Function()? onTap;++ @override+ Widget build(BuildContext context) {+ return GestureDetector(+ behavior: HitTestBehavior.opaque,+ onTap: onTap,+ child: Container(+ height: SimpleTableConstants.actionSheetNormalActionSectionHeight,+ decoration: ShapeDecoration(+ color: context.simpleTableActionButtonBackgroundColor,+ shape: _buildBorder(),+ ),+ child: Row(+ children: [+ const HSpace(16),+ Padding(+ padding: const EdgeInsets.all(1.0),+ child: FlowySvg(+ type.leftIconSvg,+ size: const Size.square(20),+ ),+ ),+ const HSpace(12),+ FlowyText(+ type.name,+ fontSize: 14,+ figmaLineHeight: 20,+ ),+ const Spacer(),+ rightIconBuilder?.call(context) ?? const SizedBox.shrink(),+ ],+ ),+ ),+ );+ }++ RoundedRectangleBorder _buildBorder() {+ const radius = Radius.circular(+ SimpleTableConstants.actionSheetButtonRadius,+ );+ return RoundedRectangleBorder(+ borderRadius: BorderRadius.only(+ topLeft: enableTopBorder ? radius : Radius.zero,+ topRight: enableTopBorder ? radius : Radius.zero,+ bottomLeft: enableBottomBorder ? radius : Radius.zero,+ bottomRight: enableBottomBorder ? radius : Radius.zero,+ ),+ );+ }+}++class SimpleTableContentActions extends ISimpleTableBottomSheetActions {+ const SimpleTableContentActions({+ super.key,+ required super.type,+ required super.cellNode,+ required super.editorState,+ required this.onTextColorSelected,+ required this.onCellBackgroundColorSelected,+ required this.onAlignTap,+ this.selectedTextColor,+ this.selectedCellBackgroundColor,+ this.selectedAlign,+ });++ final VoidCallback onTextColorSelected;+ final VoidCallback onCellBackgroundColorSelected;+ final ValueChanged<TableAlign> onAlignTap;++ final Color? selectedTextColor;+ final Color? selectedCellBackgroundColor;+ final TableAlign? selectedAlign;++ @override+ Widget build(BuildContext context) {+ return Container(+ height: SimpleTableConstants.actionSheetContentSectionHeight,+ padding: const EdgeInsets.symmetric(horizontal: 16),+ child: Row(+ children: [+ SimpleTableContentBoldAction(+ isBold: type == SimpleTableMoreActionType.column+ ? cellNode.isInBoldColumn+ : cellNode.isInBoldRow,+ toggleBold: _toggleBold,+ ),+ const HSpace(2),+ SimpleTableContentTextColorAction(+ onTap: onTextColorSelected,+ selectedTextColor: selectedTextColor,+ ),+ const HSpace(2),+ SimpleTableContentCellBackgroundColorAction(+ onTap: onCellBackgroundColorSelected,+ selectedCellBackgroundColor: selectedCellBackgroundColor,+ ),+ const HSpace(16),+ SimpleTableContentAlignmentAction(+ align: selectedAlign ?? TableAlign.left,+ onTap: onAlignTap,+ ),+ ],+ ),+ );+ }++ void _toggleBold(bool isBold) {+ switch (type) {+ case SimpleTableMoreActionType.column:+ editorState.toggleColumnBoldAttribute(+ tableCellNode: cellNode,+ isBold: isBold,+ );+ case SimpleTableMoreActionType.row:+ editorState.toggleRowBoldAttribute(+ tableCellNode: cellNode,+ isBold: isBold,+ );+ }+ }+}++class SimpleTableContentBoldAction extends StatefulWidget {+ const SimpleTableContentBoldAction({+ super.key,+ required this.toggleBold,+ required this.isBold,+ });++ final ValueChanged<bool> toggleBold;+ final bool isBold;++ @override+ State<SimpleTableContentBoldAction> createState() =>+ _SimpleTableContentBoldActionState();+}++class _SimpleTableContentBoldActionState+ extends State<SimpleTableContentBoldAction> {+ bool isBold = false;++ @override+ void initState() {+ super.initState();++ isBold = widget.isBold;+ }++ @override+ Widget build(BuildContext context) {+ return Expanded(+ child: SimpleTableContentActionDecorator(+ backgroundColor: isBold ? Theme.of(context).colorScheme.primary : null,+ enableLeftBorder: true,+ child: AnimatedGestureDetector(+ onTapUp: () {+ setState(() {+ isBold = !isBold;+ });+ widget.toggleBold.call(isBold);+ },+ child: FlowySvg(+ FlowySvgs.m_aa_bold_s,+ size: const Size.square(24),+ color: isBold ? Theme.of(context).colorScheme.onPrimary : null,+ ),+ ),+ ),+ );+ }+}++class SimpleTableContentTextColorAction extends StatelessWidget {+ const SimpleTableContentTextColorAction({+ super.key,+ required this.onTap,+ this.selectedTextColor,+ });++ final VoidCallback onTap;+ final Color? selectedTextColor;++ @override+ Widget build(BuildContext context) {+ return Expanded(+ child: SimpleTableContentActionDecorator(+ child: AnimatedGestureDetector(+ onTapUp: onTap,+ child: Row(+ mainAxisAlignment: MainAxisAlignment.center,+ children: [+ FlowySvg(+ FlowySvgs.m_table_text_color_m,+ color: selectedTextColor,+ ),+ const HSpace(10),+ const FlowySvg(+ FlowySvgs.m_aa_arrow_right_s,+ size: Size.square(12),+ ),+ ],+ ),+ ),+ ),+ );+ }+}++class SimpleTableContentCellBackgroundColorAction extends StatelessWidget {+ const SimpleTableContentCellBackgroundColorAction({+ super.key,+ required this.onTap,+ this.selectedCellBackgroundColor,+ });++ final VoidCallback onTap;+ final Color? selectedCellBackgroundColor;++ @override+ Widget build(BuildContext context) {+ return Expanded(+ child: SimpleTableContentActionDecorator(+ enableRightBorder: true,+ child: AnimatedGestureDetector(+ onTapUp: onTap,+ child: Row(+ mainAxisAlignment: MainAxisAlignment.center,+ children: [+ _buildTextBackgroundColorPreview(),+ const HSpace(10),+ FlowySvg(+ FlowySvgs.m_aa_arrow_right_s,+ size: const Size.square(12),+ color: selectedCellBackgroundColor,+ ),+ ],+ ),+ ),+ ),+ );+ }++ Widget _buildTextBackgroundColorPreview() {+ return Container(+ width: 24,+ height: 24,+ decoration: ShapeDecoration(+ color: selectedCellBackgroundColor ?? const Color(0xFFFFE6FD),+ shape: RoundedRectangleBorder(+ side: const BorderSide(+ color: Color(0xFFCFD3D9),+ ),+ borderRadius: BorderRadius.circular(100),+ ),+ ),+ );+ }+}++class SimpleTableContentAlignmentAction extends StatelessWidget {+ const SimpleTableContentAlignmentAction({+ super.key,+ this.align = TableAlign.left,+ required this.onTap,+ });++ final TableAlign align;+ final ValueChanged<TableAlign> onTap;++ @override+ Widget build(BuildContext context) {+ return Expanded(+ child: SimpleTableContentActionDecorator(+ enableLeftBorder: true,+ enableRightBorder: true,+ child: AnimatedGestureDetector(+ onTapUp: _onTap,+ child: Row(+ mainAxisAlignment: MainAxisAlignment.center,+ children: [+ FlowySvg(+ align.leftIconSvg,+ size: const Size.square(24),+ ),+ const HSpace(10),+ const FlowySvg(+ FlowySvgs.m_aa_arrow_right_s,+ size: Size.square(12),+ ),+ ],+ ),+ ),+ ),+ );+ }++ void _onTap() {+ final nextAlign = switch (align) {+ TableAlign.left => TableAlign.center,+ TableAlign.center => TableAlign.right,+ TableAlign.right => TableAlign.left,+ };++ onTap(nextAlign);+ }+}++class SimpleTableContentActionDecorator extends StatelessWidget {+ const SimpleTableContentActionDecorator({+ super.key,+ this.enableLeftBorder = false,+ this.enableRightBorder = false,+ this.backgroundColor,+ required this.child,+ });++ final bool enableLeftBorder;+ final bool enableRightBorder;+ final Color? backgroundColor;+ final Widget child;++ @override+ Widget build(BuildContext context) {+ return Container(+ height: SimpleTableConstants.actionSheetNormalActionSectionHeight,+ padding: const EdgeInsets.symmetric(vertical: 10),+ decoration: ShapeDecoration(+ color:+ backgroundColor ?? context.simpleTableInsertActionBackgroundColor,+ shape: _buildBorder(),+ ),+ child: child,+ );+ }++ RoundedRectangleBorder _buildBorder() {+ const radius = Radius.circular(+ SimpleTableConstants.actionSheetButtonRadius,+ );+ return RoundedRectangleBorder(+ borderRadius: BorderRadius.only(+ topLeft: enableLeftBorder ? radius : Radius.zero,+ topRight: enableRightBorder ? radius : Radius.zero,+ bottomLeft: enableLeftBorder ? radius : Radius.zero,+ bottomRight: enableRightBorder ? radius : Radius.zero,+ ),+ );+ }+}++class SimpleTableActionButtons extends StatelessWidget {+ const SimpleTableActionButtons({+ super.key,+ required this.tableNode,+ required this.editorState,+ required this.onAlignTap,+ });++ final Node tableNode;+ final EditorState editorState;+ final VoidCallback onAlignTap;++ @override+ Widget build(BuildContext context) {+ return Padding(+ padding: const EdgeInsets.symmetric(horizontal: 16),+ child: Column(+ children: _buildActions(context),+ ),+ );+ }++ List<Widget> _buildActions(BuildContext context) {+ final actionGroups = [+ [+ SimpleTableMoreAction.setToPageWidth,+ SimpleTableMoreAction.distributeColumnsEvenly,+ ],+ [+ SimpleTableMoreAction.align,+ ],+ [+ SimpleTableMoreAction.duplicateTable,+ SimpleTableMoreAction.copyLinkToBlock,+ ]+ ];+ final List<Widget> widgets = [];++ for (final (actionGroupIndex, actionGroup) in actionGroups.indexed) {+ for (final (index, action) in actionGroup.indexed) {+ widgets.add(+ // enable the corner border if the cell is the first or last in the group+ switch (action) {+ SimpleTableMoreAction.align => SimpleTableAlignActionButton(+ onTap: () => _onActionTap(+ context,+ action: action,+ ),+ ),+ _ => SimpleTableActionButton(+ type: action,+ enableTopBorder: index == 0,+ enableBottomBorder: index == actionGroup.length - 1,+ onTap: () => _onActionTap(+ context,+ action: action,+ ),+ ),+ },+ );+ // if the action is not the first or last in the group, add a divider+ if (index != actionGroup.length - 1) {+ widgets.add(const FlowyDivider());+ }+ }++ // add padding to separate the action groups+ if (actionGroupIndex != actionGroups.length - 1) {+ widgets.add(const VSpace(16));+ }+ }++ return widgets;+ }++ void _onActionTap(+ BuildContext context, {+ required SimpleTableMoreAction action,+ }) {+ final optionCubit = BlockActionOptionCubit(+ editorState: editorState,+ blockComponentBuilder: {},+ );+ switch (action) {+ case SimpleTableMoreAction.setToPageWidth:+ editorState.setColumnWidthToPageWidth(tableNode: tableNode);+ case SimpleTableMoreAction.distributeColumnsEvenly:+ editorState.distributeColumnWidthToPageWidth(tableNode: tableNode);+ case SimpleTableMoreAction.duplicateTable:+ optionCubit.handleAction(OptionAction.duplicate, tableNode);+ case SimpleTableMoreAction.copyLinkToBlock:+ optionCubit.handleAction(OptionAction.copyLinkToBlock, tableNode);+ case SimpleTableMoreAction.align:+ onAlignTap();+ default:+ assert(false, 'Unsupported action: $action');+ break;+ }++ // close the action menu+ if (action != SimpleTableMoreAction.align) {+ Navigator.of(context).pop();+ }+ }+}++class SimpleTableContentAlignAction extends StatefulWidget {+ const SimpleTableContentAlignAction({+ super.key,+ required this.isSelected,+ required this.align,+ required this.onTap,+ });++ final bool isSelected;+ final VoidCallback onTap;+ final TableAlign align;++ @override+ State<SimpleTableContentAlignAction> createState() =>+ _SimpleTableContentAlignActionState();+}++class _SimpleTableContentAlignActionState+ extends State<SimpleTableContentAlignAction> {+ @override+ Widget build(BuildContext context) {+ return Expanded(+ child: SimpleTableContentActionDecorator(+ backgroundColor:+ widget.isSelected ? Theme.of(context).colorScheme.primary : null,+ enableLeftBorder: widget.align == TableAlign.left,+ enableRightBorder: widget.align == TableAlign.right,+ child: AnimatedGestureDetector(+ onTapUp: widget.onTap,+ child: FlowySvg(+ widget.align.leftIconSvg,+ size: const Size.square(24),+ color: widget.isSelected+ ? Theme.of(context).colorScheme.onPrimary+ : null,+ ),+ ),+ ),+ );+ }+}++/// Quick actions for the table+///+/// - Copy+/// - Paste+/// - Cut+/// - Delete+class SimpleTableQuickActions extends StatelessWidget {+ const SimpleTableQuickActions({+ super.key,+ required this.tableNode,+ required this.editorState,+ });++ final Node tableNode;+ final EditorState editorState;++ @override+ Widget build(BuildContext context) {+ return SizedBox(+ height: SimpleTableConstants.actionSheetQuickActionSectionHeight,+ child: Row(+ mainAxisAlignment: MainAxisAlignment.spaceEvenly,+ children: [+ SimpleTableQuickAction(+ type: SimpleTableMoreAction.cut,+ onTap: () => _onActionTap(+ context,+ SimpleTableMoreAction.cut,+ ),+ ),+ SimpleTableQuickAction(+ type: SimpleTableMoreAction.copy,+ onTap: () => _onActionTap(+ context,+ SimpleTableMoreAction.copy,+ ),+ ),+ FutureBuilder(+ future: getIt<ClipboardService>().getData(),+ builder: (context, snapshot) {+ final hasContent = snapshot.data?.tableJson != null;+ return SimpleTableQuickAction(+ type: SimpleTableMoreAction.paste,+ isEnabled: hasContent,+ onTap: () => _onActionTap(+ context,+ SimpleTableMoreAction.paste,+ ),+ );+ },+ ),+ SimpleTableQuickAction(+ type: SimpleTableMoreAction.delete,+ onTap: () => _onActionTap(+ context,+ SimpleTableMoreAction.delete,+ ),+ ),+ ],+ ),+ );+ }++ void _onActionTap(BuildContext context, SimpleTableMoreAction action) {+ switch (action) {+ case SimpleTableMoreAction.cut:+ _onCut(tableNode);+ case SimpleTableMoreAction.copy:+ _onCopy(tableNode);+ case SimpleTableMoreAction.paste:+ _onPaste(tableNode);+ case SimpleTableMoreAction.delete:+ _onDelete(tableNode);+ default:+ assert(false, 'Unsupported action: $action');+ }++ // close the action menu+ Navigator.of(context).pop();+ }++ Future<void> _onCut(Node tableNode) async {+ final data = await editorState.copyTable(+ tableNode: tableNode,+ clearContent: true,+ );+ if (data != null) {+ await getIt<ClipboardService>().setData(data);+ }+ }++ Future<void> _onCopy(Node tableNode) async {+ final data = await editorState.copyTable(+ tableNode: tableNode,+ );+ if (data != null) {+ await getIt<ClipboardService>().setData(data);+ }+ }++ void _onPaste(Node tableNode) => editorState.pasteTable(+ tableNode: tableNode,+ );++ void _onDelete(Node tableNode) {+ final transaction = editorState.transaction;+ transaction.deleteNode(tableNode);+ editorState.apply(transaction);+ }+}diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/simple_table_action_sheet.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/simple_table_action_sheet.dartnew file mode 100644index 0000000000..0bfa576314--- /dev/null+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/simple_table_action_sheet.dart@@ -0,0 +1,225 @@+import 'package:appflowy/mobile/presentation/bottom_sheet/show_mobile_bottom_sheet.dart';+import 'package:appflowy/plugins/document/presentation/editor_plugins/simple_table/simple_table.dart';+import 'package:appflowy_editor/appflowy_editor.dart';+import 'package:flutter/material.dart';+import 'package:provider/provider.dart';++class SimpleTableMobileDraggableReorderButton extends StatelessWidget {+ const SimpleTableMobileDraggableReorderButton({+ super.key,+ required this.node,+ required this.index,+ required this.isShowingMenu,+ required this.type,+ required this.editorState,+ required this.simpleTableContext,+ });++ final Node node;+ final int index;+ final ValueNotifier<bool> isShowingMenu;+ final SimpleTableMoreActionType type;+ final EditorState editorState;+ final SimpleTableContext simpleTableContext;++ @override+ Widget build(BuildContext context) {+ return Draggable<int>(+ data: index,+ onDragStarted: () => _startDragging(),+ onDragUpdate: (details) => _onDragUpdate(details),+ onDragEnd: (_) => _stopDragging(),+ feedback: SimpleTableFeedback(+ editorState: editorState,+ node: node,+ type: type,+ index: index,+ ),+ child: SimpleTableMobileReorderButton(+ index: index,+ type: type,+ node: node,+ isShowingMenu: isShowingMenu,+ ),+ );+ }++ void _startDragging() {+ switch (type) {+ case SimpleTableMoreActionType.column:+ simpleTableContext.isReorderingColumn.value = (true, index);++ case SimpleTableMoreActionType.row:+ simpleTableContext.isReorderingRow.value = (true, index);+ }+ }++ void _onDragUpdate(DragUpdateDetails details) {+ simpleTableContext.reorderingOffset.value = details.globalPosition;+ }++ void _stopDragging() {+ switch (type) {+ case SimpleTableMoreActionType.column:+ _reorderColumn();+ case SimpleTableMoreActionType.row:+ _reorderRow();+ }++ simpleTableContext.reorderingOffset.value = Offset.zero;+ switch (type) {+ case SimpleTableMoreActionType.column:+ simpleTableContext.isReorderingColumn.value = (false, -1);+ break;+ case SimpleTableMoreActionType.row:+ simpleTableContext.isReorderingRow.value = (false, -1);+ break;+ }+ }++ void _reorderColumn() {+ final fromIndex = simpleTableContext.isReorderingColumn.value.$2;+ final toIndex = simpleTableContext.hoveringTableCell.value?.columnIndex;+ if (toIndex == null) {+ return;+ }++ editorState.reorderColumn(+ node,+ fromIndex: fromIndex,+ toIndex: toIndex,+ );+ }++ void _reorderRow() {+ final fromIndex = simpleTableContext.isReorderingRow.value.$2;+ final toIndex = simpleTableContext.hoveringTableCell.value?.rowIndex;+ if (toIndex == null) {+ return;+ }++ editorState.reorderRow(+ node,+ fromIndex: fromIndex,+ toIndex: toIndex,+ );+ }+}++class SimpleTableMobileReorderButton extends StatefulWidget {+ const SimpleTableMobileReorderButton({+ super.key,+ required this.index,+ required this.type,+ required this.node,+ required this.isShowingMenu,+ });++ final int index;+ final SimpleTableMoreActionType type;+ final Node node;+ final ValueNotifier<bool> isShowingMenu;++ @override+ State<SimpleTableMobileReorderButton> createState() =>+ _SimpleTableMobileReorderButtonState();+}++class _SimpleTableMobileReorderButtonState+ extends State<SimpleTableMobileReorderButton> {+ late final EditorState editorState = context.read<EditorState>();+ late final SimpleTableContext simpleTableContext =+ context.read<SimpleTableContext>();++ @override+ void initState() {+ super.initState();++ simpleTableContext.selectingRow.addListener(_onUpdateShowingMenu);+ simpleTableContext.selectingColumn.addListener(_onUpdateShowingMenu);+ }++ @override+ void dispose() {+ simpleTableContext.selectingRow.removeListener(_onUpdateShowingMenu);+ simpleTableContext.selectingColumn.removeListener(_onUpdateShowingMenu);++ super.dispose();+ }++ @override+ Widget build(BuildContext context) {+ return GestureDetector(+ onTap: () async => _onSelecting(),+ behavior: HitTestBehavior.opaque,+ child: SizedBox(+ height: widget.type == SimpleTableMoreActionType.column+ ? SimpleTableConstants.columnActionSheetHitTestAreaHeight+ : null,+ width: widget.type == SimpleTableMoreActionType.row+ ? SimpleTableConstants.rowActionSheetHitTestAreaWidth+ : null,+ child: Align(+ child: SimpleTableReorderButton(+ isShowingMenu: widget.isShowingMenu,+ type: widget.type,+ ),+ ),+ ),+ );+ }++ Future<void> _onSelecting() async {+ widget.isShowingMenu.value = true;++ // update the selecting row or column+ switch (widget.type) {+ case SimpleTableMoreActionType.column:+ simpleTableContext.selectingColumn.value = widget.index;+ simpleTableContext.selectingRow.value = null;+ break;+ case SimpleTableMoreActionType.row:+ simpleTableContext.selectingRow.value = widget.index;+ simpleTableContext.selectingColumn.value = null;+ }++ editorState.selection = null;++ // show the bottom sheet+ await showMobileBottomSheet(+ context,+ showDragHandle: true,+ showDivider: false,+ builder: (context) => Provider.value(+ value: simpleTableContext,+ child: SimpleTableCellBottomSheet(+ type: widget.type,+ cellNode: widget.node,+ editorState: editorState,+ ),+ ),+ );++ // reset the selecting row or column+ simpleTableContext.selectingRow.value = null;+ simpleTableContext.selectingColumn.value = null;++ widget.isShowingMenu.value = false;+ }++ void _onUpdateShowingMenu() {+ // highlight the reorder button when the row or column is selected+ final selectingRow = simpleTableContext.selectingRow.value;+ final selectingColumn = simpleTableContext.selectingColumn.value;++ if (selectingRow == widget.index &&+ widget.type == SimpleTableMoreActionType.row) {+ widget.isShowingMenu.value = true;+ } else if (selectingColumn == widget.index &&+ widget.type == SimpleTableMoreActionType.column) {+ widget.isShowingMenu.value = true;+ } else {+ widget.isShowingMenu.value = false;+ }+ }+}diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/simple_table_add_column_button.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/simple_table_add_column_button.dartindex 9287b78e88..5747125b22 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/simple_table_add_column_button.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/simple_table_add_column_button.dart@@ -74,7 +74,7 @@ class _SimpleTableAddColumnHoverButtonStatehoveringTableCell.columnLength;}return Positioned(- top: SimpleTableConstants.tableTopPadding -+ top: SimpleTableConstants.tableHitTestTopPadding -SimpleTableConstants.cellBorderWidth,bottom: SimpleTableConstants.addColumnButtonBottomPadding,right: 0,diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/simple_table_border_builder.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/simple_table_border_builder.dartindex b24498c599..bc9f5b1909 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/simple_table_border_builder.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/simple_table_border_builder.dart@@ -74,10 +74,10 @@ class SimpleTableBorderBuilder {right: _buildHighlightBorderSide(),top: node.rowIndex == 0? _buildHighlightBorderSide()- : _buildDefaultBorderSide(),+ : _buildLightBorderSide(),bottom: node.rowIndex + 1 == node.parentTableNode?.rowLength? _buildHighlightBorderSide()- : _buildDefaultBorderSide(),+ : _buildLightBorderSide(),);}@@ -95,10 +95,10 @@ class SimpleTableBorderBuilder {bottom: _buildHighlightBorderSide(),left: node.columnIndex == 0? _buildHighlightBorderSide()- : _buildDefaultBorderSide(),+ : _buildLightBorderSide(),right: node.columnIndex + 1 == node.parentTableNode?.columnLength? _buildHighlightBorderSide()- : _buildDefaultBorderSide(),+ : _buildLightBorderSide(),);}diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/simple_table_bottom_sheet.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/simple_table_bottom_sheet.dartnew file mode 100644index 0000000000..5343e73342--- /dev/null+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/simple_table_bottom_sheet.dart@@ -0,0 +1,430 @@+import 'package:appflowy/generated/locale_keys.g.dart';+import 'package:appflowy/mobile/presentation/bottom_sheet/show_mobile_bottom_sheet.dart';+import 'package:appflowy/plugins/document/presentation/editor_plugins/base/string_extension.dart';+import 'package:appflowy/plugins/document/presentation/editor_plugins/mobile_toolbar_v3/aa_menu/_color_list.dart';+import 'package:appflowy/plugins/document/presentation/editor_plugins/simple_table/simple_table.dart';+import 'package:appflowy/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/_simple_table_bottom_sheet_actions.dart';+import 'package:appflowy_editor/appflowy_editor.dart';+import 'package:easy_localization/easy_localization.dart';+import 'package:flowy_infra_ui/flowy_infra_ui.dart';+import 'package:flutter/material.dart';++enum _SimpleTableBottomSheetMenuState {+ cellActionMenu,+ textColor,+ textBackgroundColor,+ tableActionMenu,+ align,+}++/// This bottom sheet is used for the column or row action menu.+/// When selecting a cell and tapping the action menu button around the cell,+/// this bottom sheet will be shown.+///+/// Note: This widget is only used for mobile.+class SimpleTableCellBottomSheet extends StatefulWidget {+ const SimpleTableCellBottomSheet({+ super.key,+ required this.type,+ required this.cellNode,+ required this.editorState,+ });++ final SimpleTableMoreActionType type;+ final Node cellNode;+ final EditorState editorState;++ @override+ State<SimpleTableCellBottomSheet> createState() =>+ _SimpleTableCellBottomSheetState();+}++class _SimpleTableCellBottomSheetState+ extends State<SimpleTableCellBottomSheet> {+ _SimpleTableBottomSheetMenuState menuState =+ _SimpleTableBottomSheetMenuState.cellActionMenu;++ Color? selectedTextColor;+ Color? selectedCellBackgroundColor;+ TableAlign? selectedAlign;++ @override+ void initState() {+ super.initState();++ selectedTextColor = switch (widget.type) {+ SimpleTableMoreActionType.column =>+ widget.cellNode.textColorInColumn?.tryToColor(),+ SimpleTableMoreActionType.row =>+ widget.cellNode.textColorInRow?.tryToColor(),+ };++ selectedCellBackgroundColor = switch (widget.type) {+ SimpleTableMoreActionType.column =>+ widget.cellNode.buildColumnColor(context),+ SimpleTableMoreActionType.row => widget.cellNode.buildRowColor(context),+ };++ selectedAlign = switch (widget.type) {+ SimpleTableMoreActionType.column => widget.cellNode.columnAlign,+ SimpleTableMoreActionType.row => widget.cellNode.rowAlign,+ };+ }++ @override+ Widget build(BuildContext context) {+ return Column(+ mainAxisSize: MainAxisSize.min,+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ // header+ _buildHeader(),++ // content+ ..._buildContent(),+ ],+ );+ }++ Widget _buildHeader() {+ switch (menuState) {+ case _SimpleTableBottomSheetMenuState.cellActionMenu:+ return BottomSheetHeader(+ showBackButton: false,+ showCloseButton: true,+ showDoneButton: false,+ showRemoveButton: false,+ title: widget.type.name.capitalize(),+ onClose: () => Navigator.pop(context),+ );+ case _SimpleTableBottomSheetMenuState.textColor ||+ _SimpleTableBottomSheetMenuState.textBackgroundColor:+ return BottomSheetHeader(+ showBackButton: false,+ showCloseButton: true,+ showDoneButton: false,+ showRemoveButton: false,+ title: widget.type.name.capitalize(),+ onClose: () => setState(() {+ menuState = _SimpleTableBottomSheetMenuState.cellActionMenu;+ }),+ );+ default:+ throw UnimplementedError('Unsupported menu state: $menuState');+ }+ }++ List<Widget> _buildContent() {+ switch (menuState) {+ case _SimpleTableBottomSheetMenuState.cellActionMenu:+ return _buildActionButtons();+ case _SimpleTableBottomSheetMenuState.textColor:+ return _buildTextColor();+ case _SimpleTableBottomSheetMenuState.textBackgroundColor:+ return _buildTextBackgroundColor();+ default:+ throw UnimplementedError('Unsupported menu state: $menuState');+ }+ }++ List<Widget> _buildActionButtons() {+ return [+ // copy, cut, paste, delete+ SimpleTableCellQuickActions(+ type: widget.type,+ cellNode: widget.cellNode,+ editorState: widget.editorState,+ ),+ const VSpace(12),++ // insert row, insert column+ SimpleTableInsertActions(+ type: widget.type,+ cellNode: widget.cellNode,+ editorState: widget.editorState,+ ),+ const VSpace(12),++ // content actions+ SimpleTableContentActions(+ type: widget.type,+ cellNode: widget.cellNode,+ editorState: widget.editorState,+ selectedAlign: selectedAlign,+ selectedTextColor: selectedTextColor,+ selectedCellBackgroundColor: selectedCellBackgroundColor,+ onTextColorSelected: () {+ setState(() {+ menuState = _SimpleTableBottomSheetMenuState.textColor;+ });+ },+ onCellBackgroundColorSelected: () {+ setState(() {+ menuState = _SimpleTableBottomSheetMenuState.textBackgroundColor;+ });+ },+ onAlignTap: _onAlignTap,+ ),+ const VSpace(16),++ // action buttons+ SimpleTableCellActionButtons(+ type: widget.type,+ cellNode: widget.cellNode,+ editorState: widget.editorState,+ ),+ ];+ }++ List<Widget> _buildTextColor() {+ return [+ Padding(+ padding: const EdgeInsets.symmetric(+ horizontal: 16.0,+ ),+ child: FlowyText(+ LocaleKeys.document_plugins_simpleTable_moreActions_textColor.tr(),+ fontSize: 14.0,+ ),+ ),+ const VSpace(12.0),+ Padding(+ padding: const EdgeInsets.symmetric(+ horizontal: 8.0,+ ),+ child: EditorTextColorWidget(+ onSelectedColor: _onTextColorSelected,+ selectedColor: selectedTextColor,+ ),+ ),+ ];+ }++ List<Widget> _buildTextBackgroundColor() {+ return [+ Padding(+ padding: const EdgeInsets.symmetric(+ horizontal: 16.0,+ ),+ child: FlowyText(+ LocaleKeys+ .document_plugins_simpleTable_moreActions_cellBackgroundColor+ .tr(),+ fontSize: 14.0,+ ),+ ),+ const VSpace(12.0),+ Padding(+ padding: const EdgeInsets.symmetric(+ horizontal: 8.0,+ ),+ child: EditorBackgroundColors(+ onSelectedColor: _onCellBackgroundColorSelected,+ selectedColor: selectedCellBackgroundColor,+ ),+ ),+ ];+ }++ void _onTextColorSelected(Color color) {+ final hex = color.alpha == 0 ? null : color.toHex();+ switch (widget.type) {+ case SimpleTableMoreActionType.column:+ widget.editorState.updateColumnTextColor(+ tableCellNode: widget.cellNode,+ color: hex ?? '',+ );+ case SimpleTableMoreActionType.row:+ widget.editorState.updateRowTextColor(+ tableCellNode: widget.cellNode,+ color: hex ?? '',+ );+ }++ setState(() {+ selectedTextColor = color;+ });+ }++ void _onCellBackgroundColorSelected(Color color) {+ final hex = color.alpha == 0 ? null : color.toHex();+ switch (widget.type) {+ case SimpleTableMoreActionType.column:+ widget.editorState.updateColumnBackgroundColor(+ tableCellNode: widget.cellNode,+ color: hex ?? '',+ );+ case SimpleTableMoreActionType.row:+ widget.editorState.updateRowBackgroundColor(+ tableCellNode: widget.cellNode,+ color: hex ?? '',+ );+ }++ setState(() {+ selectedCellBackgroundColor = color;+ });+ }++ void _onAlignTap(TableAlign align) {+ switch (widget.type) {+ case SimpleTableMoreActionType.column:+ widget.editorState.updateColumnAlign(+ tableCellNode: widget.cellNode,+ align: align,+ );+ case SimpleTableMoreActionType.row:+ widget.editorState.updateRowAlign(+ tableCellNode: widget.cellNode,+ align: align,+ );+ }++ setState(() {+ selectedAlign = align;+ });+ }+}++/// This bottom sheet is used for the table action menu.+/// When selecting a table and tapping the action menu button on the top-left corner of the table,+/// this bottom sheet will be shown.+///+/// Note: This widget is only used for mobile.+class SimpleTableBottomSheet extends StatefulWidget {+ const SimpleTableBottomSheet({+ super.key,+ required this.tableNode,+ required this.editorState,+ });++ final Node tableNode;+ final EditorState editorState;++ @override+ State<SimpleTableBottomSheet> createState() => _SimpleTableBottomSheetState();+}++class _SimpleTableBottomSheetState extends State<SimpleTableBottomSheet> {+ _SimpleTableBottomSheetMenuState menuState =+ _SimpleTableBottomSheetMenuState.tableActionMenu;++ TableAlign? selectedAlign;++ @override+ Widget build(BuildContext context) {+ return Column(+ mainAxisSize: MainAxisSize.min,+ crossAxisAlignment: CrossAxisAlignment.start,+ children: [+ // header+ _buildHeader(),++ // content+ ..._buildContent(),+ ],+ );+ }++ Widget _buildHeader() {+ switch (menuState) {+ case _SimpleTableBottomSheetMenuState.tableActionMenu:+ return BottomSheetHeader(+ showBackButton: false,+ showCloseButton: true,+ showDoneButton: false,+ showRemoveButton: false,+ title: LocaleKeys.document_plugins_simpleTable_headerName_table.tr(),+ onClose: () => Navigator.pop(context),+ );+ case _SimpleTableBottomSheetMenuState.align:+ return BottomSheetHeader(+ showBackButton: true,+ showCloseButton: false,+ showDoneButton: true,+ showRemoveButton: false,+ title: LocaleKeys.document_plugins_simpleTable_headerName_table.tr(),+ onBack: () => setState(() {+ menuState = _SimpleTableBottomSheetMenuState.tableActionMenu;+ }),+ onDone: (_) => Navigator.pop(context),+ );+ default:+ throw UnimplementedError('Unsupported menu state: $menuState');+ }+ }++ List<Widget> _buildContent() {+ switch (menuState) {+ case _SimpleTableBottomSheetMenuState.tableActionMenu:+ return _buildActionButtons();+ case _SimpleTableBottomSheetMenuState.align:+ return _buildAlign();+ default:+ throw UnimplementedError('Unsupported menu state: $menuState');+ }+ }++ List<Widget> _buildActionButtons() {+ return [+ // quick actions+ // copy, cut, paste, delete+ SimpleTableQuickActions(+ tableNode: widget.tableNode,+ editorState: widget.editorState,+ ),+ const VSpace(24),++ // action buttons+ SimpleTableActionButtons(+ tableNode: widget.tableNode,+ editorState: widget.editorState,+ onAlignTap: _onTapAlignButton,+ ),+ ];+ }++ List<Widget> _buildAlign() {+ return [+ Padding(+ padding: const EdgeInsets.symmetric(+ horizontal: 16.0,+ ),+ child: Row(+ children: [+ _buildAlignButton(TableAlign.left),+ const HSpace(2),+ _buildAlignButton(TableAlign.center),+ const HSpace(2),+ _buildAlignButton(TableAlign.right),+ ],+ ),+ ),+ ];+ }++ Widget _buildAlignButton(TableAlign align) {+ return SimpleTableContentAlignAction(+ onTap: () => _onTapAlign(align),+ align: align,+ isSelected: selectedAlign == align,+ );+ }++ void _onTapAlignButton() {+ setState(() {+ menuState = _SimpleTableBottomSheetMenuState.align;+ });+ }++ void _onTapAlign(TableAlign align) {+ setState(() {+ selectedAlign = align;+ });++ widget.editorState.updateTableAlign(+ tableNode: widget.tableNode,+ align: align,+ );+ }+}diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/simple_table_more_action_popup.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/simple_table_more_action_popup.dartnew file mode 100644index 0000000000..d2e7340790--- /dev/null+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/simple_table_more_action_popup.dart@@ -0,0 +1,539 @@+import 'package:appflowy/generated/flowy_svgs.g.dart';+import 'package:appflowy/plugins/document/presentation/editor_plugins/simple_table/simple_table.dart';+import 'package:appflowy/workspace/presentation/widgets/toggle/toggle.dart';+import 'package:appflowy_editor/appflowy_editor.dart';+import 'package:flowy_infra_ui/flowy_infra_ui.dart';+import 'package:flutter/material.dart';+import 'package:provider/provider.dart';++class SimpleTableMoreActionPopup extends StatefulWidget {+ const SimpleTableMoreActionPopup({+ super.key,+ required this.index,+ required this.isShowingMenu,+ required this.type,+ });++ final int index;+ final ValueNotifier<bool> isShowingMenu;+ final SimpleTableMoreActionType type;++ @override+ State<SimpleTableMoreActionPopup> createState() =>+ _SimpleTableMoreActionPopupState();+}++class _SimpleTableMoreActionPopupState+ extends State<SimpleTableMoreActionPopup> {+ late final editorState = context.read<EditorState>();++ SelectionGestureInterceptor? gestureInterceptor;++ RenderBox? get renderBox => context.findRenderObject() as RenderBox?;++ @override+ void initState() {+ super.initState();++ final tableCellNode =+ context.read<SimpleTableContext>().hoveringTableCell.value;+ gestureInterceptor = SelectionGestureInterceptor(+ key: 'simple_table_more_action_popup_interceptor_${tableCellNode?.id}',+ canTap: (details) => !_isTapInBounds(details.globalPosition),+ );+ editorState.service.selectionService.registerGestureInterceptor(+ gestureInterceptor!,+ );+ }++ @override+ void dispose() {+ if (gestureInterceptor != null) {+ editorState.service.selectionService.unregisterGestureInterceptor(+ gestureInterceptor!.key,+ );+ }++ super.dispose();+ }++ @override+ Widget build(BuildContext context) {+ final simpleTableContext = context.read<SimpleTableContext>();+ final tableCellNode = simpleTableContext.hoveringTableCell.value;+ final tableNode = tableCellNode?.parentTableNode;++ if (tableNode == null) {+ return const SizedBox.shrink();+ }++ return AppFlowyPopover(+ onOpen: () => _onOpen(tableCellNode: tableCellNode),+ onClose: () => _onClose(),+ direction: widget.type == SimpleTableMoreActionType.row+ ? PopoverDirection.bottomWithCenterAligned+ : PopoverDirection.bottomWithLeftAligned,+ offset: widget.type == SimpleTableMoreActionType.row+ ? const Offset(24, 14)+ : const Offset(-14, 8),+ clickHandler: PopoverClickHandler.gestureDetector,+ popupBuilder: (_) => _buildPopup(tableCellNode: tableCellNode),+ child: SimpleTableDraggableReorderButton(+ editorState: editorState,+ simpleTableContext: simpleTableContext,+ node: tableNode,+ index: widget.index,+ isShowingMenu: widget.isShowingMenu,+ type: widget.type,+ ),+ );+ }++ Widget _buildPopup({Node? tableCellNode}) {+ if (tableCellNode == null) {+ return const SizedBox.shrink();+ }+ return MultiProvider(+ providers: [+ Provider.value(+ value: context.read<SimpleTableContext>(),+ ),+ Provider.value(+ value: context.read<EditorState>(),+ ),+ ],+ child: SimpleTableMoreActionList(+ type: widget.type,+ index: widget.index,+ tableCellNode: tableCellNode,+ ),+ );+ }++ void _onOpen({Node? tableCellNode}) {+ widget.isShowingMenu.value = true;++ switch (widget.type) {+ case SimpleTableMoreActionType.column:+ context.read<SimpleTableContext>().selectingColumn.value =+ tableCellNode?.columnIndex;+ case SimpleTableMoreActionType.row:+ context.read<SimpleTableContext>().selectingRow.value =+ tableCellNode?.rowIndex;+ }++ // Workaround to clear the selection after the menu is opened.+ Future.delayed(Durations.short3, () {+ if (!editorState.isDisposed) {+ editorState.selection = null;+ }+ });+ }++ void _onClose() {+ widget.isShowingMenu.value = false;++ // clear the selecting index+ context.read<SimpleTableContext>().selectingColumn.value = null;+ context.read<SimpleTableContext>().selectingRow.value = null;+ }++ bool _isTapInBounds(Offset offset) {+ if (renderBox == null) {+ return false;+ }++ final localPosition = renderBox!.globalToLocal(offset);+ final result = renderBox!.paintBounds.contains(localPosition);+ if (result) {+ editorState.selection = null;+ }+ return result;+ }+}++class SimpleTableMoreActionList extends StatefulWidget {+ const SimpleTableMoreActionList({+ super.key,+ required this.type,+ required this.index,+ required this.tableCellNode,+ this.mutex,+ });++ final SimpleTableMoreActionType type;+ final int index;+ final Node tableCellNode;+ final PopoverMutex? mutex;++ @override+ State<SimpleTableMoreActionList> createState() =>+ _SimpleTableMoreActionListState();+}++class _SimpleTableMoreActionListState extends State<SimpleTableMoreActionList> {+ // ensure the background color menu and align menu exclusive+ final mutex = PopoverMutex();++ @override+ Widget build(BuildContext context) {+ return Column(+ mainAxisSize: MainAxisSize.min,+ children: widget.type+ .buildDesktopActions(+ index: widget.index,+ columnLength: widget.tableCellNode.columnLength,+ rowLength: widget.tableCellNode.rowLength,+ )+ .map(+ (action) => SimpleTableMoreActionItem(+ type: widget.type,+ action: action,+ tableCellNode: widget.tableCellNode,+ popoverMutex: mutex,+ ),+ )+ .toList(),+ );+ }+}++class SimpleTableMoreActionItem extends StatefulWidget {+ const SimpleTableMoreActionItem({+ super.key,+ required this.type,+ required this.action,+ required this.tableCellNode,+ required this.popoverMutex,+ });++ final SimpleTableMoreActionType type;+ final SimpleTableMoreAction action;+ final Node tableCellNode;+ final PopoverMutex popoverMutex;++ @override+ State<SimpleTableMoreActionItem> createState() =>+ _SimpleTableMoreActionItemState();+}++class _SimpleTableMoreActionItemState extends State<SimpleTableMoreActionItem> {+ final isEnableHeader = ValueNotifier(false);++ @override+ void initState() {+ super.initState();++ _initEnableHeader();+ }++ @override+ void dispose() {+ isEnableHeader.dispose();++ super.dispose();+ }++ @override+ Widget build(BuildContext context) {+ if (widget.action == SimpleTableMoreAction.divider) {+ return _buildDivider(context);+ } else if (widget.action == SimpleTableMoreAction.align) {+ return _buildAlignMenu(context);+ } else if (widget.action == SimpleTableMoreAction.backgroundColor) {+ return _buildBackgroundColorMenu(context);+ } else if (widget.action == SimpleTableMoreAction.enableHeaderColumn) {+ return _buildEnableHeaderButton(context);+ } else if (widget.action == SimpleTableMoreAction.enableHeaderRow) {+ return _buildEnableHeaderButton(context);+ }++ return _buildActionButton(context);+ }++ Widget _buildDivider(BuildContext context) {+ return const FlowyDivider(+ padding: EdgeInsets.symmetric(+ vertical: 4.0,+ ),+ );+ }++ Widget _buildAlignMenu(BuildContext context) {+ return SimpleTableAlignMenu(+ type: widget.type,+ tableCellNode: widget.tableCellNode,+ mutex: widget.popoverMutex,+ );+ }++ Widget _buildBackgroundColorMenu(BuildContext context) {+ return SimpleTableBackgroundColorMenu(+ type: widget.type,+ tableCellNode: widget.tableCellNode,+ mutex: widget.popoverMutex,+ );+ }++ Widget _buildEnableHeaderButton(BuildContext context) {+ return SimpleTableBasicButton(+ text: widget.action.name,+ leftIconSvg: widget.action.leftIconSvg,+ rightIcon: ValueListenableBuilder(+ valueListenable: isEnableHeader,+ builder: (context, isEnableHeader, child) {+ return Toggle(+ value: isEnableHeader,+ onChanged: (value) => _toggleEnableHeader(),+ padding: EdgeInsets.zero,+ );+ },+ ),+ onTap: _toggleEnableHeader,+ );+ }++ Widget _buildActionButton(BuildContext context) {+ return Container(+ height: SimpleTableConstants.moreActionHeight,+ padding: SimpleTableConstants.moreActionPadding,+ child: FlowyIconTextButton(+ margin: SimpleTableConstants.moreActionHorizontalMargin,+ leftIconBuilder: (onHover) => FlowySvg(+ widget.action.leftIconSvg,+ color: widget.action == SimpleTableMoreAction.delete && onHover+ ? Theme.of(context).colorScheme.error+ : null,+ ),+ iconPadding: 10.0,+ textBuilder: (onHover) => FlowyText.regular(+ widget.action.name,+ fontSize: 14.0,+ figmaLineHeight: 18.0,+ color: widget.action == SimpleTableMoreAction.delete && onHover+ ? Theme.of(context).colorScheme.error+ : null,+ ),+ onTap: _onAction,+ ),+ );+ }++ void _onAction() {+ switch (widget.action) {+ case SimpleTableMoreAction.delete:+ switch (widget.type) {+ case SimpleTableMoreActionType.column:+ _deleteColumn();+ break;+ case SimpleTableMoreActionType.row:+ _deleteRow();+ break;+ }+ case SimpleTableMoreAction.insertLeft:+ _insertColumnLeft();+ case SimpleTableMoreAction.insertRight:+ _insertColumnRight();+ case SimpleTableMoreAction.insertAbove:+ _insertRowAbove();+ case SimpleTableMoreAction.insertBelow:+ _insertRowBelow();+ case SimpleTableMoreAction.clearContents:+ _clearContent();+ case SimpleTableMoreAction.duplicate:+ switch (widget.type) {+ case SimpleTableMoreActionType.column:+ _duplicateColumn();+ break;+ case SimpleTableMoreActionType.row:+ _duplicateRow();+ break;+ }+ case SimpleTableMoreAction.setToPageWidth:+ _setToPageWidth();+ case SimpleTableMoreAction.distributeColumnsEvenly:+ _distributeColumnsEvenly();+ default:+ break;+ }++ PopoverContainer.of(context).close();+ }++ void _setToPageWidth() {+ final value = _getTableAndTableCellAndCellPosition();+ if (value == null) {+ return;+ }+ final (table, _, _) = value;+ final editorState = context.read<EditorState>();+ editorState.setColumnWidthToPageWidth(tableNode: table);+ }++ void _distributeColumnsEvenly() {+ final value = _getTableAndTableCellAndCellPosition();+ if (value == null) {+ return;+ }+ final (table, _, _) = value;+ final editorState = context.read<EditorState>();+ editorState.distributeColumnWidthToPageWidth(tableNode: table);+ }++ void _duplicateRow() {+ final value = _getTableAndTableCellAndCellPosition();+ if (value == null) {+ return;+ }+ final (table, node, _) = value;+ final editorState = context.read<EditorState>();+ editorState.duplicateRowInTable(table, node.rowIndex);+ }++ void _duplicateColumn() {+ final value = _getTableAndTableCellAndCellPosition();+ if (value == null) {+ return;+ }+ final (table, node, _) = value;+ final editorState = context.read<EditorState>();+ editorState.duplicateColumnInTable(table, node.columnIndex);+ }++ void _toggleEnableHeader() {+ final value = _getTableAndTableCellAndCellPosition();+ if (value == null) {+ return;+ }++ isEnableHeader.value = !isEnableHeader.value;++ final (table, _, _) = value;+ final editorState = context.read<EditorState>();+ switch (widget.type) {+ case SimpleTableMoreActionType.column:+ editorState.toggleEnableHeaderColumn(+ tableNode: table,+ enable: isEnableHeader.value,+ );+ case SimpleTableMoreActionType.row:+ editorState.toggleEnableHeaderRow(+ tableNode: table,+ enable: isEnableHeader.value,+ );+ }++ PopoverContainer.of(context).close();+ }++ void _clearContent() {+ final value = _getTableAndTableCellAndCellPosition();+ if (value == null) {+ return;+ }+ final (table, node, _) = value;+ final editorState = context.read<EditorState>();+ if (widget.type == SimpleTableMoreActionType.column) {+ editorState.clearContentAtColumnIndex(+ tableNode: table,+ columnIndex: node.columnIndex,+ );+ } else if (widget.type == SimpleTableMoreActionType.row) {+ editorState.clearContentAtRowIndex(+ tableNode: table,+ rowIndex: node.rowIndex,+ );+ }+ }++ void _insertColumnLeft() {+ final value = _getTableAndTableCellAndCellPosition();+ if (value == null) {+ return;+ }+ final (table, node, _) = value;+ final columnIndex = node.columnIndex;+ final editorState = context.read<EditorState>();+ editorState.insertColumnInTable(table, columnIndex);+ }++ void _insertColumnRight() {+ final value = _getTableAndTableCellAndCellPosition();+ if (value == null) {+ return;+ }+ final (table, node, _) = value;+ final columnIndex = node.columnIndex;+ final editorState = context.read<EditorState>();+ editorState.insertColumnInTable(table, columnIndex + 1);+ }++ void _insertRowAbove() {+ final value = _getTableAndTableCellAndCellPosition();+ if (value == null) {+ return;+ }+ final (table, node, _) = value;+ final rowIndex = node.rowIndex;+ final editorState = context.read<EditorState>();+ editorState.insertRowInTable(table, rowIndex);+ }++ void _insertRowBelow() {+ final value = _getTableAndTableCellAndCellPosition();+ if (value == null) {+ return;+ }+ final (table, node, _) = value;+ final rowIndex = node.rowIndex;+ final editorState = context.read<EditorState>();+ editorState.insertRowInTable(table, rowIndex + 1);+ }++ void _deleteRow() {+ final value = _getTableAndTableCellAndCellPosition();+ if (value == null) {+ return;+ }+ final (table, node, _) = value;+ final rowIndex = node.rowIndex;+ final editorState = context.read<EditorState>();+ editorState.deleteRowInTable(table, rowIndex);+ }++ void _deleteColumn() {+ final value = _getTableAndTableCellAndCellPosition();+ if (value == null) {+ return;+ }+ final (table, node, _) = value;+ final columnIndex = node.columnIndex;+ final editorState = context.read<EditorState>();+ editorState.deleteColumnInTable(table, columnIndex);+ }++ (Node, Node, TableCellPosition)? _getTableAndTableCellAndCellPosition() {+ final cell = widget.tableCellNode;+ final table = cell.parent?.parent;+ if (table == null || table.type != SimpleTableBlockKeys.type) {+ return null;+ }+ return (table, cell, cell.cellPosition);+ }++ void _initEnableHeader() {+ final value = _getTableAndTableCellAndCellPosition();+ if (value != null) {+ final (table, _, _) = value;+ if (widget.type == SimpleTableMoreActionType.column) {+ isEnableHeader.value = table+ .attributes[SimpleTableBlockKeys.enableHeaderColumn] as bool? ??+ false;+ } else if (widget.type == SimpleTableMoreActionType.row) {+ isEnableHeader.value =+ table.attributes[SimpleTableBlockKeys.enableHeaderRow] as bool? ??+ false;+ }+ }+ }+}diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/simple_table_reorder_button.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/simple_table_reorder_button.dartindex 740c822ff5..21369395c0 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/simple_table_reorder_button.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/simple_table_reorder_button.dart@@ -218,7 +218,7 @@ class _SimpleTableFeedbackState extends State<SimpleTableFeedback> {/// If the type is [SimpleTableMoreActionType.column], we should build the dummy table node using the data from the first column of the table node.Node _buildDummyNode() {// deep copy the table node to avoid mutating the original node- final tableNode = widget.node.copyWith();+ final tableNode = widget.node.deepCopy();switch (widget.type) {case SimpleTableMoreActionType.row:diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/simple_table_widget.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/simple_table_widget.dartindex 17472029de..7f79082550 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/simple_table_widget.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/simple_table_widget.dart@@ -1,9 +1,11 @@import 'package:appflowy/plugins/document/presentation/editor_plugins/simple_table/simple_table.dart';import 'package:appflowy_editor/appflowy_editor.dart';import 'package:flutter/material.dart';-import 'package:provider/provider.dart';import 'package:universal_platform/universal_platform.dart';+import '_desktop_simple_table_widget.dart';+import '_mobile_simple_table_widget.dart';+class SimpleTableWidget extends StatefulWidget {const SimpleTableWidget({super.key,@@ -52,145 +54,26 @@ class SimpleTableWidget extends StatefulWidget {}class _SimpleTableWidgetState extends State<SimpleTableWidget> {- SimpleTableContext get simpleTableContext => widget.simpleTableContext;-- final scrollController = ScrollController();- late final editorState = context.read<EditorState>();-- @override- void dispose() {- scrollController.dispose();-- super.dispose();- }-@overrideWidget build(BuildContext context) {return UniversalPlatform.isDesktop- ? _buildDesktopTable()- : _buildMobileTable();- }-- Widget _buildDesktopTable() {- if (widget.isFeedback) {- return Provider.value(- value: simpleTableContext,- child: IntrinsicWidth(- child: IntrinsicHeight(- child: Column(- mainAxisSize: MainAxisSize.min,- crossAxisAlignment: CrossAxisAlignment.start,- children: _buildRows(),- ),- ),- ),- );- }-- // table content- Widget child = Scrollbar(- controller: scrollController,- child: SingleChildScrollView(- controller: scrollController,- scrollDirection: Axis.horizontal,- child: Padding(- padding: SimpleTableConstants.tablePadding,- // IntrinsicWidth and IntrinsicHeight are used to make the table size fit the content.- child: IntrinsicWidth(- child: IntrinsicHeight(- child: Column(- mainAxisSize: MainAxisSize.min,- crossAxisAlignment: CrossAxisAlignment.start,- children: _buildRows(),- ),- ),- ),- ),- ),- );-- if (widget.enableHoverEffect) {- child = MouseRegion(- onEnter: (event) =>- simpleTableContext.isHoveringOnTableArea.value = true,- onExit: (event) {- simpleTableContext.isHoveringOnTableArea.value = false;- },- child: Provider.value(- value: simpleTableContext,- child: Stack(- children: [- MouseRegion(- hitTestBehavior: HitTestBehavior.opaque,- onEnter: (event) =>- simpleTableContext.isHoveringOnColumnsAndRows.value = true,- onExit: (event) {- simpleTableContext.isHoveringOnColumnsAndRows.value = false;- simpleTableContext.hoveringTableCell.value = null;- },- child: child,- ),- if (editorState.editable) ...[- if (widget.enableAddColumnButton)- SimpleTableAddColumnHoverButton(- editorState: editorState,- tableNode: widget.node,- ),- if (widget.enableAddRowButton)- SimpleTableAddRowHoverButton(- editorState: editorState,- tableNode: widget.node,- ),- if (widget.enableAddColumnAndRowButton)- SimpleTableAddColumnAndRowHoverButton(- editorState: editorState,- node: widget.node,- ),- ],- ],- ),- ),- );- }-- return child;- }-- Widget _buildMobileTable() {- return Provider.value(- value: simpleTableContext,- child: SingleChildScrollView(- controller: scrollController,- scrollDirection: Axis.horizontal,- child: IntrinsicWidth(- child: IntrinsicHeight(- child: Column(- mainAxisSize: MainAxisSize.min,- crossAxisAlignment: CrossAxisAlignment.start,- children: _buildRows(),- ),- ),- ),- ),- );- }-- List<Widget> _buildRows() {- final List<Widget> rows = [];-- if (SimpleTableConstants.borderType == SimpleTableBorderRenderType.table) {- rows.add(const SimpleTableColumnDivider());- }-- for (final child in widget.node.children) {- rows.add(editorState.renderer.build(context, child));-- if (SimpleTableConstants.borderType ==- SimpleTableBorderRenderType.table) {- rows.add(const SimpleTableColumnDivider());- }- }-- return rows;+ ? DesktopSimpleTableWidget(+ simpleTableContext: widget.simpleTableContext,+ node: widget.node,+ enableAddColumnButton: widget.enableAddColumnButton,+ enableAddRowButton: widget.enableAddRowButton,+ enableAddColumnAndRowButton: widget.enableAddColumnAndRowButton,+ enableHoverEffect: widget.enableHoverEffect,+ isFeedback: widget.isFeedback,+ )+ : MobileSimpleTableWidget(+ simpleTableContext: widget.simpleTableContext,+ node: widget.node,+ enableAddColumnButton: widget.enableAddColumnButton,+ enableAddRowButton: widget.enableAddRowButton,+ enableAddColumnAndRowButton: widget.enableAddColumnAndRowButton,+ enableHoverEffect: widget.enableHoverEffect,+ isFeedback: widget.isFeedback,+ );}}diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/widgets.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/widgets.dartindex 8b9607e2ba..322e3e6a89 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/widgets.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/simple_table/simple_table_widgets/widgets.dart@@ -1,3 +1,4 @@+export 'simple_table_action_sheet.dart';export 'simple_table_add_column_and_row_button.dart';export 'simple_table_add_column_button.dart';export 'simple_table_add_row_button.dart';@@ -5,7 +6,9 @@ export 'simple_table_align_button.dart';export 'simple_table_background_menu.dart';export 'simple_table_basic_button.dart';export 'simple_table_border_builder.dart';+export 'simple_table_bottom_sheet.dart';export 'simple_table_column_resize_handle.dart';export 'simple_table_divider.dart';+export 'simple_table_more_action_popup.dart';export 'simple_table_reorder_button.dart';export 'simple_table_widget.dart';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.dartindex 3d5a32b154..5caefe6e62 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/slash_menu/slash_menu_items.dart@@ -79,7 +79,6 @@ final heading3SlashMenuItem = SelectionMenuItem(// toggle heading 1 menu item// heading 1 - 3 menu itemsfinal toggleHeading1SlashMenuItem = SelectionMenuItem(- // todo: i18ngetName: () => LocaleKeys.document_slashMenu_name_toggleHeading1.tr(),nameBuilder: _slashMenuItemNameBuilder,icon: (editorState, isSelected, style) => SelectableSvgWidget(@@ -97,7 +96,6 @@ final toggleHeading1SlashMenuItem = SelectionMenuItem();final toggleHeading2SlashMenuItem = SelectionMenuItem(- // todo: i18ngetName: () => LocaleKeys.document_slashMenu_name_toggleHeading2.tr(),nameBuilder: _slashMenuItemNameBuilder,icon: (editorState, isSelected, style) => SelectableSvgWidget(@@ -115,7 +113,6 @@ final toggleHeading2SlashMenuItem = SelectionMenuItem();final toggleHeading3SlashMenuItem = SelectionMenuItem(- // todo: i18ngetName: () => LocaleKeys.document_slashMenu_name_toggleHeading3.tr(),nameBuilder: _slashMenuItemNameBuilder,icon: (editorState, isSelected, style) => SelectableSvgWidget(diff --git a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_shortcuts.dart b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_shortcuts.dartindex 508e2a8349..212be0f7bf 100644--- a/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_shortcuts.dart+++ b/frontend/appflowy_flutter/lib/plugins/document/presentation/editor_plugins/toggle/toggle_block_shortcuts.dart@@ -67,7 +67,7 @@ Future<void> _formatGreaterToToggleHeading(node.path,toggleListBlockNode(delta: delta,- children: node.children.map((e) => e.copyWith()).toList(),+ children: node.children.map((e) => e.deepCopy()).toList(),),)..deleteNode(node);diff --git a/frontend/appflowy_flutter/pubspec.lock b/frontend/appflowy_flutter/pubspec.lockindex 120a4b3e07..9d1b49f159 100644--- a/frontend/appflowy_flutter/pubspec.lock+++ b/frontend/appflowy_flutter/pubspec.lock@@ -61,8 +61,8 @@ packages:dependency: "direct main"description:path: "."- ref: c6909a7- resolved-ref: c6909a7a04b31c3ea0352e2b68b059b46170b56a+ ref: "7a7a8ae"+ resolved-ref: "7a7a8ae3e73790903a19108933c97a3c7f6255e2"url: "https://github.com/AppFlowy-IO/appflowy-editor.git"source: gitversion: "4.0.0"diff --git a/frontend/appflowy_flutter/pubspec.yaml b/frontend/appflowy_flutter/pubspec.yamlindex 3a4301e6b0..aafd320014 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: "c6909a7"+ ref: "7a7a8ae"appflowy_editor_plugins:git:diff --git a/frontend/appflowy_flutter/test/unit_test/simple_table/simple_table_contente_operation_test.dart b/frontend/appflowy_flutter/test/unit_test/simple_table/simple_table_contente_operation_test.dartindex c2be7d5026..57b8319d06 100644--- a/frontend/appflowy_flutter/test/unit_test/simple_table/simple_table_contente_operation_test.dart+++ b/frontend/appflowy_flutter/test/unit_test/simple_table/simple_table_contente_operation_test.dart@@ -1,4 +1,6 @@+import 'package:appflowy/plugins/document/presentation/editor_plugins/copy_and_paste/clipboard_service.dart';import 'package:appflowy/plugins/document/presentation/editor_plugins/simple_table/simple_table.dart';+import 'package:appflowy/startup/startup.dart';import 'package:appflowy_backend/log.dart';import 'package:flutter_test/flutter_test.dart';@@ -6,8 +8,14 @@ import 'simple_table_test_helper.dart';void main() {group('Simple table content operation:', () {+ void setupDependencyInjection() {+ getIt.registerSingleton<ClipboardService>(ClipboardService());+ }+setUpAll(() {Log.shared.disableLog = true;++ setupDependencyInjection();});tearDownAll(() {@@ -21,7 +29,10 @@ void main() {columnCount: 3,defaultContent: defaultContent,);- await editorState.clearContentAtRowIndex(tableNode, 0);+ await editorState.clearContentAtRowIndex(+ tableNode: tableNode,+ rowIndex: 0,+ );for (var i = 0; i < tableNode.rowLength; i++) {for (var j = 0; j < tableNode.columnLength; j++) {expect(@@ -44,7 +55,10 @@ void main() {columnCount: 4,defaultContent: defaultContent,);- await editorState.clearContentAtRowIndex(tableNode, 2);+ await editorState.clearContentAtRowIndex(+ tableNode: tableNode,+ rowIndex: 2,+ );for (var i = 0; i < tableNode.rowLength; i++) {for (var j = 0; j < tableNode.columnLength; j++) {expect(@@ -67,7 +81,10 @@ void main() {columnCount: 3,defaultContent: defaultContent,);- await editorState.clearContentAtColumnIndex(tableNode, 0);+ await editorState.clearContentAtColumnIndex(+ tableNode: tableNode,+ columnIndex: 0,+ );for (var i = 0; i < tableNode.rowLength; i++) {for (var j = 0; j < tableNode.columnLength; j++) {expect(@@ -90,7 +107,10 @@ void main() {columnCount: 4,defaultContent: defaultContent,);- await editorState.clearContentAtColumnIndex(tableNode, 3);+ await editorState.clearContentAtColumnIndex(+ tableNode: tableNode,+ columnIndex: 3,+ );for (var i = 0; i < tableNode.rowLength; i++) {for (var j = 0; j < tableNode.columnLength; j++) {expect(@@ -105,5 +125,92 @@ void main() {}}});++ test('copy row 1-2', () async {+ const rowCount = 2;+ const columnCount = 3;++ final (editorState, tableNode) = createEditorStateAndTable(+ rowCount: rowCount,+ columnCount: columnCount,+ contentBuilder: (rowIndex, columnIndex) =>+ 'row $rowIndex, column $columnIndex',+ );++ for (var rowIndex = 0; rowIndex < rowCount; rowIndex++) {+ final data = await editorState.copyRow(+ tableNode: tableNode,+ rowIndex: rowIndex,+ );+ expect(data, isNotNull);+ expect(+ data?.plainText,+ 'row $rowIndex, column 0\nrow $rowIndex, column 1\nrow $rowIndex, column 2',+ );+ }+ });++ test('copy column 1-2', () async {+ const rowCount = 2;+ const columnCount = 3;++ final (editorState, tableNode) = createEditorStateAndTable(+ rowCount: rowCount,+ columnCount: columnCount,+ contentBuilder: (rowIndex, columnIndex) =>+ 'row $rowIndex, column $columnIndex',+ );++ for (var columnIndex = 0; columnIndex < columnCount; columnIndex++) {+ final data = await editorState.copyColumn(+ tableNode: tableNode,+ columnIndex: columnIndex,+ );+ expect(data, isNotNull);+ expect(+ data?.plainText,+ 'row 0, column $columnIndex\nrow 1, column $columnIndex',+ );+ }+ });++ test('cut row 1-2', () async {+ const rowCount = 2;+ const columnCount = 3;++ final (editorState, tableNode) = createEditorStateAndTable(+ rowCount: rowCount,+ columnCount: columnCount,+ contentBuilder: (rowIndex, columnIndex) =>+ 'row $rowIndex, column $columnIndex',+ );++ for (var rowIndex = 0; rowIndex < rowCount; rowIndex++) {+ final data = await editorState.copyRow(+ tableNode: tableNode,+ rowIndex: rowIndex,+ clearContent: true,+ );+ expect(data, isNotNull);+ expect(+ data?.plainText,+ 'row $rowIndex, column 0\nrow $rowIndex, column 1\nrow $rowIndex, column 2',+ );+ }++ for (var rowIndex = 0; rowIndex < rowCount; rowIndex++) {+ for (var columnIndex = 0; columnIndex < columnCount; columnIndex++) {+ expect(+ tableNode+ .getTableCellNode(rowIndex: rowIndex, columnIndex: columnIndex)+ ?.children+ .first+ .delta+ ?.toPlainText(),+ '',+ );+ }+ }+ });});}diff --git a/frontend/appflowy_flutter/test/unit_test/simple_table/simple_table_header_operation_test.dart b/frontend/appflowy_flutter/test/unit_test/simple_table/simple_table_header_operation_test.dartindex ef23a6ac1f..1f0707cc0d 100644--- a/frontend/appflowy_flutter/test/unit_test/simple_table/simple_table_header_operation_test.dart+++ b/frontend/appflowy_flutter/test/unit_test/simple_table/simple_table_header_operation_test.dart@@ -21,9 +21,15 @@ void main() {);// default is not header columnexpect(tableNode.isHeaderColumnEnabled, false);- await editorState.toggleEnableHeaderColumn(tableNode, true);+ await editorState.toggleEnableHeaderColumn(+ tableNode: tableNode,+ enable: true,+ );expect(tableNode.isHeaderColumnEnabled, true);- await editorState.toggleEnableHeaderColumn(tableNode, false);+ await editorState.toggleEnableHeaderColumn(+ tableNode: tableNode,+ enable: false,+ );expect(tableNode.isHeaderColumnEnabled, false);expect(tableNode.rowLength, 2);expect(tableNode.columnLength, 3);@@ -36,9 +42,15 @@ void main() {);// default is not header rowexpect(tableNode.isHeaderRowEnabled, false);- await editorState.toggleEnableHeaderRow(tableNode, true);+ await editorState.toggleEnableHeaderRow(+ tableNode: tableNode,+ enable: true,+ );expect(tableNode.isHeaderRowEnabled, true);- await editorState.toggleEnableHeaderRow(tableNode, false);+ await editorState.toggleEnableHeaderRow(+ tableNode: tableNode,+ enable: false,+ );expect(tableNode.isHeaderRowEnabled, false);expect(tableNode.rowLength, 2);expect(tableNode.columnLength, 3);diff --git a/frontend/resources/flowy_icons/16x/m_bottom_sheet_back.svg b/frontend/resources/flowy_icons/16x/m_bottom_sheet_back.svgnew file mode 100644index 0000000000..e67a6361ba--- /dev/null+++ b/frontend/resources/flowy_icons/16x/m_bottom_sheet_back.svg@@ -0,0 +1,3 @@+<svg width="21" height="21" viewBox="0 0 21 21" fill="none" xmlns="http://www.w3.org/2000/svg">+<path d="M14.5149 2.41107C14.8403 2.73651 14.8403 3.26414 14.5149 3.58958L7.60417 10.5003L14.5149 17.4111C14.8403 17.7365 14.8403 18.2641 14.5149 18.5896C14.1895 18.915 13.6618 18.915 13.3364 18.5896L6.42566 11.6788C5.77478 11.028 5.77478 9.97269 6.42566 9.32182L13.3364 2.41107C13.6618 2.08563 14.1895 2.08563 14.5149 2.41107Z" fill="#2B2F36"/>+</svg>diff --git a/frontend/resources/flowy_icons/16x/m_table_duplicate.svg b/frontend/resources/flowy_icons/16x/m_table_duplicate.svgnew file mode 100644index 0000000000..1a0b6902e4--- /dev/null+++ b/frontend/resources/flowy_icons/16x/m_table_duplicate.svg@@ -0,0 +1,6 @@+<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">+<path fill-rule="evenodd" clip-rule="evenodd" d="M3.66783 9.66783C3.0898 10.2459 2.75 11.224 2.75 12.9V17.1C2.75 18.776 3.0898 19.7541 3.66783 20.3322C4.24586 20.9102 5.22397 21.25 6.9 21.25H11.1C12.776 21.25 13.7541 20.9102 14.3322 20.3322C14.9102 19.7541 15.25 18.776 15.25 17.1V12.9C15.25 11.224 14.9102 10.2459 14.3322 9.66783C13.7541 9.0898 12.776 8.75 11.1 8.75H6.9C5.22397 8.75 4.24586 9.0898 3.66783 9.66783ZM2.60717 8.60717C3.60414 7.6102 5.07603 7.25 6.9 7.25H11.1C12.924 7.25 14.3959 7.6102 15.3928 8.60717C16.3898 9.60414 16.75 11.076 16.75 12.9V17.1C16.75 18.924 16.3898 20.3959 15.3928 21.3928C14.3959 22.3898 12.924 22.75 11.1 22.75H6.9C5.07603 22.75 3.60414 22.3898 2.60717 21.3928C1.6102 20.3959 1.25 18.924 1.25 17.1V12.9C1.25 11.076 1.6102 9.60414 2.60717 8.60717Z" fill="#1F2329"/>+<path fill-rule="evenodd" clip-rule="evenodd" d="M9.66783 3.66783C9.0898 4.24586 8.75 5.22397 8.75 6.9V7.25H11.1C12.924 7.25 14.3959 7.6102 15.3928 8.60717C16.3898 9.60414 16.75 11.076 16.75 12.9V15.25H17.1C18.776 15.25 19.7541 14.9102 20.3322 14.3322C20.9102 13.7541 21.25 12.776 21.25 11.1V6.9C21.25 5.22397 20.9102 4.24586 20.3322 3.66783C19.7541 3.0898 18.776 2.75 17.1 2.75H12.9C11.224 2.75 10.2459 3.0898 9.66783 3.66783ZM8.60717 2.60717C9.60414 1.6102 11.076 1.25 12.9 1.25H17.1C18.924 1.25 20.3959 1.6102 21.3928 2.60717C22.3898 3.60414 22.75 5.07603 22.75 6.9V11.1C22.75 12.924 22.3898 14.3959 21.3928 15.3928C20.3959 16.3898 18.924 16.75 17.1 16.75H16C15.5858 16.75 15.25 16.4142 15.25 16V12.9C15.25 11.224 14.9102 10.2459 14.3322 9.66783C13.7541 9.0898 12.776 8.75 11.1 8.75H8C7.58579 8.75 7.25 8.41421 7.25 8V6.9C7.25 5.07603 7.6102 3.60414 8.60717 2.60717Z" fill="#1F2329"/>+<path fill-rule="evenodd" clip-rule="evenodd" d="M5.25 15C5.25 14.5858 5.58579 14.25 6 14.25H12C12.4142 14.25 12.75 14.5858 12.75 15C12.75 15.4142 12.4142 15.75 12 15.75H6C5.58579 15.75 5.25 15.4142 5.25 15Z" fill="#1F2329"/>+<path fill-rule="evenodd" clip-rule="evenodd" d="M9 11.25C9.41421 11.25 9.75 11.5858 9.75 12V18C9.75 18.4142 9.41421 18.75 9 18.75C8.58579 18.75 8.25 18.4142 8.25 18L8.25 12C8.25 11.5858 8.58579 11.25 9 11.25Z" fill="#1F2329"/>+</svg>diff --git a/frontend/resources/flowy_icons/16x/m_table_quick_action_copy.svg b/frontend/resources/flowy_icons/16x/m_table_quick_action_copy.svgnew file mode 100644index 0000000000..5e69041afe--- /dev/null+++ b/frontend/resources/flowy_icons/16x/m_table_quick_action_copy.svg@@ -0,0 +1,4 @@+<svg width="25" height="24" viewBox="0 0 25 24" fill="none" xmlns="http://www.w3.org/2000/svg">+<path d="M16.2969 12.9V17.1C16.2969 20.6 14.8969 22 11.3969 22H7.19688C3.69688 22 2.29688 20.6 2.29688 17.1V12.9C2.29688 9.4 3.69688 8 7.19688 8H11.3969C14.8969 8 16.2969 9.4 16.2969 12.9Z" stroke="#666D76" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>+<path d="M22.2969 6.9V11.1C22.2969 14.6 20.8969 16 17.3969 16H16.2969V12.9C16.2969 9.4 14.8969 8 11.3969 8H8.29688V6.9C8.29688 3.4 9.69687 2 13.1969 2H17.3969C20.8969 2 22.2969 3.4 22.2969 6.9Z" stroke="#666D76" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>+</svg>diff --git a/frontend/resources/flowy_icons/16x/m_table_quick_action_cut.svg b/frontend/resources/flowy_icons/16x/m_table_quick_action_cut.svgnew file mode 100644index 0000000000..60660f7891--- /dev/null+++ b/frontend/resources/flowy_icons/16x/m_table_quick_action_cut.svg@@ -0,0 +1,4 @@+<svg width="25" height="24" viewBox="0 0 25 24" fill="none" xmlns="http://www.w3.org/2000/svg">+<path d="M16.4482 20.5L6.04688 2M22.0469 19C22.0469 20.6569 20.7038 22 19.0469 22C17.39 22 16.0469 20.6569 16.0469 19C16.0469 17.3431 17.39 16 19.0469 16C20.7038 16 22.0469 17.3431 22.0469 19Z" stroke="#666D76" stroke-width="1.5" stroke-linecap="round"/>+<path d="M7.64552 20.5L18.0469 2M2.04688 19C2.04688 20.6569 3.39003 22 5.04688 22C6.70372 22 8.04688 20.6569 8.04688 19C8.04688 17.3431 6.70372 16 5.04688 16C3.39003 16 2.04688 17.3431 2.04688 19Z" stroke="#666D76" stroke-width="1.5" stroke-linecap="round"/>+</svg>diff --git a/frontend/resources/flowy_icons/16x/m_table_quick_action_delete.svg b/frontend/resources/flowy_icons/16x/m_table_quick_action_delete.svgnew file mode 100644index 0000000000..e11d4fa185--- /dev/null+++ b/frontend/resources/flowy_icons/16x/m_table_quick_action_delete.svg@@ -0,0 +1,7 @@+<svg width="25" height="24" viewBox="0 0 25 24" fill="none" xmlns="http://www.w3.org/2000/svg">+<path d="M21.7969 5.97998C18.4669 5.64998 15.1169 5.47998 11.7769 5.47998C9.79687 5.47998 7.81687 5.57998 5.83687 5.77998L3.79688 5.97998" stroke="#FB006D" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>+<path d="M9.29688 4.97L9.51688 3.66C9.67688 2.71 9.79687 2 11.4869 2H14.1069C15.7969 2 15.9269 2.75 16.0769 3.67L16.2969 4.97" stroke="#FB006D" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>+<path d="M19.6473 9.14014L18.9973 19.2101C18.8873 20.7801 18.7973 22.0001 16.0073 22.0001H9.58727C6.79727 22.0001 6.70727 20.7801 6.59727 19.2101L5.94727 9.14014" stroke="#FB006D" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>+<path d="M11.127 16.5H14.457" stroke="#FB006D" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>+<path d="M10.2969 12.5H15.2969" stroke="#FB006D" stroke-width="1.5" stroke-linecap="round" stroke-linejoin="round"/>+</svg>diff --git a/frontend/resources/flowy_icons/16x/m_table_quick_action_paste.svg b/frontend/resources/flowy_icons/16x/m_table_quick_action_paste.svgnew file mode 100644index 0000000000..6172fc1d40--- /dev/null+++ b/frontend/resources/flowy_icons/16x/m_table_quick_action_paste.svg@@ -0,0 +1,6 @@+<svg width="25" height="24" viewBox="0 0 25 24" fill="none" xmlns="http://www.w3.org/2000/svg">+<path d="M16.5469 4.00195C18.7219 4.01406 19.8998 4.11051 20.6682 4.87889C21.5469 5.75757 21.5469 7.17179 21.5469 10.0002V16.0002C21.5469 18.8286 21.5469 20.2429 20.6682 21.1215C19.7895 22.0002 18.3753 22.0002 15.5469 22.0002H9.54688C6.71845 22.0002 5.30423 22.0002 4.42555 21.1215C3.54688 20.2429 3.54688 18.8286 3.54688 16.0002V10.0002C3.54688 7.17179 3.54688 5.75757 4.42555 4.87889C5.19393 4.11051 6.37185 4.01406 8.54688 4.00195" stroke="#666D76" stroke-width="1.5"/>+<path d="M7.54688 14.5H15.5469" stroke="#666D76" stroke-width="1.5" stroke-linecap="round"/>+<path d="M7.54688 18H13.0469" stroke="#666D76" stroke-width="1.5" stroke-linecap="round"/>+<path d="M8.54688 3.5C8.54688 2.67157 9.21845 2 10.0469 2H15.0469C15.8753 2 16.5469 2.67157 16.5469 3.5V4.5C16.5469 5.32843 15.8753 6 15.0469 6H10.0469C9.21845 6 8.54688 5.32843 8.54688 4.5V3.5Z" stroke="#666D76" stroke-width="1.5"/>+</svg>diff --git a/frontend/resources/flowy_icons/16x/table_header_column.svg b/frontend/resources/flowy_icons/16x/table_header_column.svgindex 2be55acd55..3ba5640bec 100644--- a/frontend/resources/flowy_icons/16x/table_header_column.svg+++ b/frontend/resources/flowy_icons/16x/table_header_column.svg@@ -1,4 +1,7 @@-<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">-<path d="M14.415 13.1609C14.415 13.5549 14.3045 13.8625 14.0835 14.0836C13.8624 14.3046 13.5549 14.415 13.1608 14.415H2.83917C2.44514 14.415 2.13757 14.3046 1.91646 14.0836C1.69548 13.8625 1.585 13.5549 1.585 13.1609L1.585 2.83921C1.585 2.44518 1.69548 2.13761 1.91646 1.9165C2.13757 1.69553 2.44514 1.58504 2.83917 1.58504H13.1608C13.5549 1.58504 13.8624 1.69553 14.0835 1.9165C14.3045 2.13761 14.415 2.44518 14.415 2.83921V13.1609ZM9.9175 8.49754V13.4159H13.1594C13.2342 13.4159 13.2957 13.3918 13.3437 13.3438C13.3918 13.2957 13.4158 13.2343 13.4158 13.1594V8.49754H9.9175ZM9.9175 7.49837H13.4158V2.84066C13.4158 2.7658 13.3918 2.70434 13.3437 2.65629C13.2957 2.60823 13.2342 2.58421 13.1594 2.58421H9.9175V7.49837ZM8.91833 8.49754H5.40375V13.4159H8.91833V8.49754ZM8.91833 7.49837V2.58421H5.40375L5.40375 7.49837L8.91833 7.49837ZM4.40458 13.4159L4.40458 2.58421H2.84062C2.76576 2.58421 2.7043 2.60823 2.65625 2.65629C2.60819 2.70434 2.58416 2.7658 2.58416 2.84066L2.58416 13.1594C2.58416 13.2343 2.60819 13.2957 2.65625 13.3438C2.7043 13.3918 2.76576 13.4159 2.84062 13.4159H4.40458Z" fill="#1F2329"/>-<rect x="2" y="14" width="12" height="3" transform="rotate(-90 2 14)" fill="#1F2329"/>+<svg width="17" height="16" viewBox="0 0 17 16" fill="none" xmlns="http://www.w3.org/2000/svg">+<path d="M2.5 12.6667L2.5 3.33333C2.5 3.33333 2.5 2 3.83333 2H13.1667C13.1667 2 14.5 2 14.5 3.33333V12.6667C14.5 12.6667 14.5 14 13.1667 14H3.83333C3.83333 14 2.5 14 2.5 12.6667Z" stroke="#171717" stroke-linecap="round" stroke-linejoin="round"/>+<path d="M9.35715 14V2" stroke="#171717" stroke-linecap="round" stroke-linejoin="round"/>+<path d="M4.21428 14L4.21428 2" stroke="#171717" stroke-linecap="round" stroke-linejoin="round"/>+<path d="M2.5 8H14.4996" stroke="#171717" stroke-linecap="round" stroke-linejoin="round"/>+<rect x="2.50027" y="14" width="12" height="1.71429" rx="0.857143" transform="rotate(-90 2.50027 14)" fill="#171717"/></svg>diff --git a/frontend/resources/flowy_icons/16x/table_header_row.svg b/frontend/resources/flowy_icons/16x/table_header_row.svgindex 19943b9f17..a4d5c77606 100644--- a/frontend/resources/flowy_icons/16x/table_header_row.svg+++ b/frontend/resources/flowy_icons/16x/table_header_row.svg@@ -1,4 +1,7 @@<svg width="16" height="16" viewBox="0 0 16 16" fill="none" xmlns="http://www.w3.org/2000/svg">-<path d="M2.83913 14.415C2.4451 14.415 2.13753 14.3045 1.91642 14.0835C1.69545 13.8624 1.58496 13.5548 1.58496 13.1608V2.83913C1.58496 2.4451 1.69545 2.13753 1.91642 1.91642C2.13753 1.69545 2.4451 1.58496 2.83913 1.58496H13.1608C13.5548 1.58496 13.8624 1.69545 14.0835 1.91642C14.3045 2.13753 14.415 2.4451 14.415 2.83913V13.1608C14.415 13.5548 14.3045 13.8624 14.0835 14.0835C13.8624 14.3045 13.5548 14.415 13.1608 14.415H2.83913ZM7.50246 9.91746H2.58413V13.1593C2.58413 13.2342 2.60816 13.2957 2.65621 13.3437C2.70427 13.3918 2.76572 13.4158 2.84059 13.4158H7.50246V9.91746ZM8.50163 9.91746V13.4158H13.1593C13.2342 13.4158 13.2957 13.3918 13.3437 13.3437C13.3918 13.2957 13.4158 13.2342 13.4158 13.1593V9.91746H8.50163ZM7.50246 8.91829V5.40371H2.58413V8.91829H7.50246ZM8.50163 8.91829H13.4158V5.40371H8.50163V8.91829ZM2.58413 4.40454H13.4158V2.84059C13.4158 2.76572 13.3918 2.70427 13.3437 2.65621C13.2957 2.60816 13.2342 2.58413 13.1593 2.58413H2.84059C2.76572 2.58413 2.70427 2.60816 2.65621 2.65621C2.60816 2.70427 2.58413 2.76572 2.58413 2.84059V4.40454Z" fill="#1F2329"/>-<rect x="2" y="2" width="12" height="3" fill="#1F2329"/>+<path d="M3.33333 2H12.6667C12.6667 2 14 2 14 3.33333V12.6667C14 12.6667 14 14 12.6667 14H3.33333C3.33333 14 2 14 2 12.6667V3.33333C2 3.33333 2 2 3.33333 2Z" stroke="#171717" stroke-linecap="round" stroke-linejoin="round"/>+<path d="M2 8.85742H14" stroke="#171717" stroke-linecap="round" stroke-linejoin="round"/>+<path d="M2 3.71387H14" stroke="#171717" stroke-linecap="round" stroke-linejoin="round"/>+<path d="M8 2V13.9996" stroke="#171717" stroke-linecap="round" stroke-linejoin="round"/>+<rect x="2" y="2" width="12" height="1.71429" rx="0.857143" fill="#171717"/></svg>diff --git a/frontend/resources/flowy_icons/24x/m_table_text_color.svg b/frontend/resources/flowy_icons/24x/m_table_text_color.svgnew file mode 100644index 0000000000..bd8253ea0d--- /dev/null+++ b/frontend/resources/flowy_icons/24x/m_table_text_color.svg@@ -0,0 +1,4 @@+<svg width="24" height="24" viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">+<path d="M14.8724 11.5318L14.8561 11.4938L14.8155 11.5016C14.7642 11.5114 14.7113 11.5166 14.6571 11.5166H9.34296C9.28863 11.5166 9.23556 11.5114 9.1842 11.5015L9.14353 11.4937L9.12722 11.5318L7.45253 15.4423C7.27102 15.8662 6.78056 16.0625 6.35709 15.8809C5.93359 15.6992 5.73737 15.2084 5.9189 14.7845L10.826 3.32604C11.2683 2.29319 12.7313 2.29319 13.1737 3.32604L18.0807 14.7845C18.2622 15.2084 18.066 15.6992 17.6425 15.8809C17.219 16.0625 16.7286 15.8662 16.5471 15.4423L14.8724 11.5318ZM12.0471 4.93434L11.9998 4.824L11.9526 4.93434L9.87952 9.77508L9.84884 9.84672H9.92677H14.0728H14.1508L14.1201 9.77508L12.0471 4.93434Z" fill="#1E2022" stroke="white" stroke-width="0.102805"/>+<rect x="3" y="18.5" width="18" height="3" rx="1.5" fill="#1E2022"/>+</svg>diff --git a/frontend/resources/translations/en.json b/frontend/resources/translations/en.jsonindex c2dbfff3c3..d0e6351fc4 100644--- a/frontend/resources/translations/en.json+++ b/frontend/resources/translations/en.json@@ -1730,11 +1730,20 @@"headerRow": "Header row","clearContents": "Clear contents","setToPageWidth": "Set to page width",- "distributeColumnsWidth": "Distribute columns evenly"+ "distributeColumnsWidth": "Distribute columns evenly",+ "duplicateRow": "Duplicate row",+ "duplicateColumn": "Duplicate column",+ "textColor": "Text color",+ "cellBackgroundColor": "Cell background color",+ "duplicateTable": "Duplicate table"},"clickToAddNewRow": "Click to add a new row","clickToAddNewColumn": "Click to add a new column",- "clickToAddNewRowAndColumn": "Click to add a new row and column"+ "clickToAddNewRowAndColumn": "Click to add a new row and column",+ "headerName": {+ "table": "Table",+ "alignText": "Align text"+ }},"cover": {"changeCover": "Change Cover",