From 72512df842db4d882eb8046dc9cbaa035a30f704 Mon Sep 17 00:00:00 2001 From: "Lucas.Xu" Date: Wed, 11 Sep 2024 17:51:53 +0800 Subject: [PATCH] chore: hide Log and PlatformExtension (#886) --- example/lib/home_page.dart | 9 +- .../lib/pages/collab_selection_editor.dart | 3 +- .../lib/pages/customize_theme_for_editor.dart | 5 +- example/lib/pages/desktop_editor.dart | 1 - example/lib/pages/editor.dart | 15 ++- .../lib/pages/focus_example_for_editor.dart | 3 +- example/lib/pages/mobile_editor.dart | 1 - example/pubspec.yaml | 1 + lib/src/core/document/node.dart | 5 +- lib/src/core/transform/transaction.dart | 3 +- .../standard_block_components.dart | 1 + .../table_block_component/table_action.dart | 2 +- .../table_block_component.dart | 14 +-- .../table_block_component/table_node.dart | 11 ++- .../todo_list_command_shortcut.dart | 1 + .../editor/command/selection_commands.dart | 2 +- .../delta_input_on_action_update_impl.dart | 3 +- .../ime/delta_input_on_delete_impl.dart | 2 +- ...delta_input_on_floating_cursor_update.dart | 4 +- .../ime/delta_input_on_insert_impl.dart | 2 +- .../delta_input_on_non_text_update_impl.dart | 1 + .../ime/delta_input_on_replace_impl.dart | 3 +- .../service/ime/delta_input_service.dart | 4 +- .../service/ime/non_delta_input_service.dart | 9 +- .../service/keyboard_service_widget.dart | 10 +- .../renderer/block_component_container.dart | 3 +- .../renderer/block_component_service.dart | 3 +- .../scroll/auto_scrollable_widget.dart | 2 +- .../scroll/desktop_scroll_service.dart | 4 +- .../service/scroll/mobile_scroll_service.dart | 4 +- .../service/scroll_service_widget.dart | 1 + .../selection/mobile_selection_service.dart | 19 ++-- .../service/selection_service_widget.dart | 7 +- .../shortcuts/character/insert_newline.dart | 2 +- .../shortcuts/character/slash_command.dart | 1 + .../command/find_replace_command.dart | 1 + .../shortcuts/command/page_up_command.dart | 1 + .../command/show_link_menu_command.dart | 1 + .../command/toggle_colors_command.dart | 1 + .../shortcuts/command_shortcut_event.dart | 1 + .../selection_menu/selection_menu_widget.dart | 4 +- .../desktop/items/utils/tooltip_util.dart | 9 +- .../utils/keyboard_height_observer.dart | 7 +- lib/src/editor/util/platform_extension.dart | 61 +++--------- lib/src/editor/util/util.dart | 1 - lib/src/editor_state.dart | 16 ++-- lib/src/history/undo_manager.dart | 8 +- lib/src/infra/log.dart | 77 ++++++++-------- .../plugins/html/html_document_decoder.dart | 2 +- .../decoder/document_markdown_decoder.dart | 2 +- .../render/selection/mobile_basic_handle.dart | 8 +- .../selection/mobile_collapsed_handle.dart | 7 +- .../selection/mobile_selection_handle.dart | 7 +- .../copy_paste_handler.dart | 2 +- pubspec.yaml | 1 + test/editor/util/platform_extension_test.dart | 2 +- test/infra/log_test.dart | 92 +++++++++---------- .../link_mobile_toolbar_item_test.dart | 4 +- .../undo_markdown_test.dart | 5 +- test/new/util/log_util.dart | 8 +- 60 files changed, 236 insertions(+), 253 deletions(-) diff --git a/example/lib/home_page.dart b/example/lib/home_page.dart index e49a34f8c..e213c02fd 100644 --- a/example/lib/home_page.dart +++ b/example/lib/home_page.dart @@ -20,6 +20,7 @@ import 'package:flutter/services.dart'; import 'package:path_provider/path_provider.dart'; import 'package:printing/printing.dart'; import 'package:universal_html/html.dart' as html; +import 'package:universal_platform/universal_platform.dart'; enum ExportFileType { documentJson, @@ -60,7 +61,7 @@ class _HomePageState extends State { void initState() { super.initState(); - _jsonString = PlatformExtension.isDesktopOrWeb + _jsonString = UniversalPlatform.isDesktopOrWeb ? rootBundle.loadString('assets/example.json') : rootBundle.loadString('assets/mobile_example.json'); @@ -91,7 +92,7 @@ class _HomePageState extends State { Widget build(BuildContext context) { return Scaffold( key: _scaffoldKey, - extendBodyBehindAppBar: PlatformExtension.isDesktopOrWeb, + extendBodyBehindAppBar: UniversalPlatform.isDesktopOrWeb, drawer: _buildDrawer(context), appBar: AppBar( backgroundColor: const Color.fromARGB(255, 134, 46, 247), @@ -123,7 +124,7 @@ class _HomePageState extends State { // AppFlowy Editor Demo _buildSeparator(context, 'AppFlowy Editor Demo'), _buildListTile(context, 'With Example.json', () { - final jsonString = PlatformExtension.isDesktopOrWeb + final jsonString = UniversalPlatform.isDesktopOrWeb ? rootBundle.loadString('assets/example.json') : rootBundle.loadString('assets/mobile_example.json'); _loadEditor(context, jsonString); @@ -358,7 +359,7 @@ class _HomePageState extends State { ) ..setAttribute('download', 'document.${fileType.extension}') ..click(); - } else if (PlatformExtension.isMobile) { + } else if (UniversalPlatform.isMobile) { final appStorageDirectory = await getApplicationDocumentsDirectory(); final path = File( diff --git a/example/lib/pages/collab_selection_editor.dart b/example/lib/pages/collab_selection_editor.dart index e23b17c83..51fb7dfc9 100644 --- a/example/lib/pages/collab_selection_editor.dart +++ b/example/lib/pages/collab_selection_editor.dart @@ -3,6 +3,7 @@ import 'dart:convert'; import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:universal_platform/universal_platform.dart'; class CollabSelectionEditor extends StatefulWidget { const CollabSelectionEditor({super.key}); @@ -54,7 +55,7 @@ class _CollabSelectionEditorState extends State { void initState() { super.initState(); - future = PlatformExtension.isDesktopOrWeb + future = UniversalPlatform.isDesktopOrWeb ? rootBundle.loadString('assets/example.json') : rootBundle.loadString('assets/mobile_example.json').then((value) { return value; diff --git a/example/lib/pages/customize_theme_for_editor.dart b/example/lib/pages/customize_theme_for_editor.dart index b87b977fd..56b02819d 100644 --- a/example/lib/pages/customize_theme_for_editor.dart +++ b/example/lib/pages/customize_theme_for_editor.dart @@ -5,6 +5,7 @@ import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:google_fonts/google_fonts.dart'; +import 'package:universal_platform/universal_platform.dart'; class CustomizeThemeForEditor extends StatefulWidget { const CustomizeThemeForEditor({super.key}); @@ -21,7 +22,7 @@ class _CustomizeThemeForEditorState extends State { void initState() { super.initState(); - final jsonString = PlatformExtension.isDesktopOrWeb + final jsonString = UniversalPlatform.isDesktopOrWeb ? rootBundle.loadString('assets/example.json') : rootBundle.loadString('assets/mobile_example.json'); editorState = jsonString.then((value) { @@ -152,7 +153,7 @@ class _CustomizeThemeForEditorState extends State { /// custom the text style EditorStyle customizeEditorStyle() { return EditorStyle( - padding: PlatformExtension.isDesktopOrWeb + padding: UniversalPlatform.isDesktopOrWeb ? const EdgeInsets.only(left: 200, right: 200) : const EdgeInsets.symmetric(horizontal: 20), cursorColor: Colors.green, diff --git a/example/lib/pages/desktop_editor.dart b/example/lib/pages/desktop_editor.dart index 5316faab3..999583752 100644 --- a/example/lib/pages/desktop_editor.dart +++ b/example/lib/pages/desktop_editor.dart @@ -59,7 +59,6 @@ class _DesktopEditorState extends State { @override Widget build(BuildContext context) { - assert(PlatformExtension.isDesktopOrWeb); return FloatingToolbar( items: [ paragraphItem, diff --git a/example/lib/pages/editor.dart b/example/lib/pages/editor.dart index 3e9589fc8..10ed857d2 100644 --- a/example/lib/pages/editor.dart +++ b/example/lib/pages/editor.dart @@ -1,11 +1,10 @@ import 'dart:convert'; -import 'package:flutter/material.dart'; - +import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:example/pages/desktop_editor.dart'; import 'package:example/pages/mobile_editor.dart'; - -import 'package:appflowy_editor/appflowy_editor.dart'; +import 'package:flutter/material.dart'; +import 'package:universal_platform/universal_platform.dart'; class Editor extends StatefulWidget { const Editor({ @@ -97,7 +96,7 @@ class _EditorState extends State { editorState.logConfiguration ..handler = debugPrint - ..level = LogLevel.off; + ..level = AppFlowyEditorLogLevel.off; editorState.transactionStream.listen((event) { if (event.$1 == TransactionTime.after) { @@ -111,12 +110,12 @@ class _EditorState extends State { registerWordCounter(); } - if (PlatformExtension.isDesktopOrWeb) { + if (UniversalPlatform.isDesktopOrWeb) { return DesktopEditor( editorState: editorState!, textDirection: widget.textDirection, ); - } else if (PlatformExtension.isMobile) { + } else if (UniversalPlatform.isMobile) { return MobileEditor(editorState: editorState!); } } @@ -134,7 +133,7 @@ class _EditorState extends State { color: Colors.black.withOpacity(0.1), borderRadius: BorderRadius.only( topLeft: const Radius.circular(8), - bottomLeft: PlatformExtension.isMobile + bottomLeft: UniversalPlatform.isMobile ? const Radius.circular(8) : Radius.zero, ), diff --git a/example/lib/pages/focus_example_for_editor.dart b/example/lib/pages/focus_example_for_editor.dart index 766ce860d..f893814a1 100644 --- a/example/lib/pages/focus_example_for_editor.dart +++ b/example/lib/pages/focus_example_for_editor.dart @@ -3,6 +3,7 @@ import 'dart:convert'; import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:universal_platform/universal_platform.dart'; class FocusExampleForEditor extends StatefulWidget { const FocusExampleForEditor({super.key}); @@ -18,7 +19,7 @@ class _FocusExampleForEditorState extends State { void initState() { super.initState(); - final jsonString = PlatformExtension.isDesktopOrWeb + final jsonString = UniversalPlatform.isDesktopOrWeb ? rootBundle.loadString('assets/example.json') : rootBundle.loadString('assets/mobile_example.json'); editorState = jsonString.then((value) { diff --git a/example/lib/pages/mobile_editor.dart b/example/lib/pages/mobile_editor.dart index 758b55345..3edf78ccd 100644 --- a/example/lib/pages/mobile_editor.dart +++ b/example/lib/pages/mobile_editor.dart @@ -47,7 +47,6 @@ class _MobileEditorState extends State { @override Widget build(BuildContext context) { - assert(PlatformExtension.isMobile); return MobileToolbarV2( toolbarHeight: 48.0, toolbarItems: [ diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 9b7f933e2..32d7335cf 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -46,6 +46,7 @@ dependencies: printing: ^5.11.1 appflowy_editor_plugins: ^0.0.6 markdown: + universal_platform: ^1.1.0 dependency_overrides: appflowy_editor: diff --git a/lib/src/core/document/node.dart b/lib/src/core/document/node.dart index b6cdafa46..2e8b46694 100644 --- a/lib/src/core/document/node.dart +++ b/lib/src/core/document/node.dart @@ -147,7 +147,8 @@ final class Node extends ChangeNotifier with LinkedListEntry { final length = _children.length; index ??= length; - Log.editor.debug('insert Node $entry at path ${path + [index]}}'); + AppFlowyEditorLog.editor + .debug('insert Node $entry at path ${path + [index]}}'); entry._resetRelationshipIfNeeded(); entry.parent = this; @@ -202,7 +203,7 @@ final class Node extends ChangeNotifier with LinkedListEntry { if (parent == null || list == null) { return false; } - Log.editor.debug('delete Node $this from path $path'); + AppFlowyEditorLog.editor.debug('delete Node $this from path $path'); super.unlink(); parent?._cacheChildren = null; diff --git a/lib/src/core/transform/transaction.dart b/lib/src/core/transform/transaction.dart index 2ea4e2d39..b8fb5968a 100644 --- a/lib/src/core/transform/transaction.dart +++ b/lib/src/core/transform/transaction.dart @@ -205,7 +205,8 @@ extension TextTransaction on Transaction { } if (index < 0 || index > delta.length) { - Log.editor.info('The index($index) is out of range or negative.'); + AppFlowyEditorLog.editor + .info('The index($index) is out of range or negative.'); return; } diff --git a/lib/src/editor/block_component/standard_block_components.dart b/lib/src/editor/block_component/standard_block_components.dart index 3d9d0dc81..63e0227b5 100644 --- a/lib/src/editor/block_component/standard_block_components.dart +++ b/lib/src/editor/block_component/standard_block_components.dart @@ -1,4 +1,5 @@ import 'package:appflowy_editor/appflowy_editor.dart'; +import 'package:appflowy_editor/src/editor/util/platform_extension.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; diff --git a/lib/src/editor/block_component/table_block_component/table_action.dart b/lib/src/editor/block_component/table_block_component/table_action.dart index 95e9603a9..5b1c41d17 100644 --- a/lib/src/editor/block_component/table_block_component/table_action.dart +++ b/lib/src/editor/block_component/table_block_component/table_action.dart @@ -193,7 +193,7 @@ void _addRow(Node tableNode, int position, EditorState editorState) async { } if (error) { - Log.editor.debug('unable to insert row'); + AppFlowyEditorLog.editor.debug('unable to insert row'); return; } diff --git a/lib/src/editor/block_component/table_block_component/table_block_component.dart b/lib/src/editor/block_component/table_block_component/table_block_component.dart index 4c6ddd57d..91d4847f3 100644 --- a/lib/src/editor/block_component/table_block_component/table_block_component.dart +++ b/lib/src/editor/block_component/table_block_component/table_block_component.dart @@ -113,14 +113,15 @@ class TableBlockComponentBuilder extends BlockComponentBuilder { bool validate(Node node) { // check the node is valid if (node.attributes.isEmpty) { - Log.editor.debug('TableBlockComponentBuilder: node is empty'); + AppFlowyEditorLog.editor + .debug('TableBlockComponentBuilder: node is empty'); return false; } // check the node has rowPosition and colPosition if (!node.attributes.containsKey(TableBlockKeys.colsLen) || !node.attributes.containsKey(TableBlockKeys.rowsLen)) { - Log.editor.debug( + AppFlowyEditorLog.editor.debug( 'TableBlockComponentBuilder: node has no colsLen or rowsLen', ); return false; @@ -132,12 +133,13 @@ class TableBlockComponentBuilder extends BlockComponentBuilder { // check its children final children = node.children; if (children.isEmpty) { - Log.editor.debug('TableBlockComponentBuilder: children is empty'); + AppFlowyEditorLog.editor + .debug('TableBlockComponentBuilder: children is empty'); return false; } if (children.length != colsLen * rowsLen) { - Log.editor.debug( + AppFlowyEditorLog.editor.debug( 'TableBlockComponentBuilder: children length(${children.length}) is not equal to colsLen * rowsLen($colsLen * $rowsLen)', ); return false; @@ -152,7 +154,7 @@ class TableBlockComponentBuilder extends BlockComponentBuilder { n.attributes[TableCellBlockKeys.rowPosition] == j, ); if (child.isEmpty) { - Log.editor.debug( + AppFlowyEditorLog.editor.debug( 'TableBlockComponentBuilder: child($i, $j) is empty', ); return false; @@ -160,7 +162,7 @@ class TableBlockComponentBuilder extends BlockComponentBuilder { // should only contains one child if (child.length != 1) { - Log.editor.debug( + AppFlowyEditorLog.editor.debug( 'TableBlockComponentBuilder: child($i, $j) is not unique', ); return false; diff --git a/lib/src/editor/block_component/table_block_component/table_node.dart b/lib/src/editor/block_component/table_block_component/table_node.dart index 47b2f3f61..485112b74 100644 --- a/lib/src/editor/block_component/table_block_component/table_node.dart +++ b/lib/src/editor/block_component/table_block_component/table_node.dart @@ -13,7 +13,7 @@ class TableNode { required this.node, }) : _config = TableConfig.fromJson(node.attributes) { if (node.type != TableBlockKeys.type) { - Log.editor.debug('TableNode: node is not a table'); + AppFlowyEditorLog.editor.debug('TableNode: node is not a table'); return; } @@ -25,14 +25,14 @@ class TableNode { rowsLen == null || colsLen is! int || rowsLen is! int) { - Log.editor.debug( + AppFlowyEditorLog.editor.debug( 'TableNode: colsLen or rowsLen is not an integer or null', ); return; } if (node.children.length != colsLen * rowsLen) { - Log.editor.debug( + AppFlowyEditorLog.editor.debug( 'TableNode: the number of children is not equal to the number of cells', ); return; @@ -42,7 +42,8 @@ class TableNode { for (final child in node.children) { if (!child.attributes.containsKey(TableCellBlockKeys.rowPosition) || !child.attributes.containsKey(TableCellBlockKeys.colPosition)) { - Log.editor.debug('TableNode: cell has no rowPosition or colPosition'); + AppFlowyEditorLog.editor + .debug('TableNode: cell has no rowPosition or colPosition'); return; } } @@ -59,7 +60,7 @@ class TableNode { .firstOrNull; if (cell == null) { - Log.editor.debug('TableNode: cell is empty'); + AppFlowyEditorLog.editor.debug('TableNode: cell is empty'); _cells.clear(); return; } diff --git a/lib/src/editor/block_component/todo_list_block_component/todo_list_command_shortcut.dart b/lib/src/editor/block_component/todo_list_block_component/todo_list_command_shortcut.dart index e0c3c50b5..ffb21f2de 100644 --- a/lib/src/editor/block_component/todo_list_block_component/todo_list_command_shortcut.dart +++ b/lib/src/editor/block_component/todo_list_block_component/todo_list_command_shortcut.dart @@ -1,4 +1,5 @@ import 'package:appflowy_editor/appflowy_editor.dart'; +import 'package:appflowy_editor/src/editor/util/platform_extension.dart'; import 'package:flutter/material.dart'; /// Arrow down key events. diff --git a/lib/src/editor/command/selection_commands.dart b/lib/src/editor/command/selection_commands.dart index c7ecb748c..5162760bf 100644 --- a/lib/src/editor/command/selection_commands.dart +++ b/lib/src/editor/command/selection_commands.dart @@ -175,7 +175,7 @@ extension SelectionTransform on EditorState { // After the selection is deleted, we want to move the selection to the // beginning of the deleted selection. transaction.afterSelection = selection.collapse(atStart: true); - Log.editor + AppFlowyEditorLog.editor .debug(transaction.operations.map((e) => e.toString()).toString()); // Apply the transaction. diff --git a/lib/src/editor/editor_component/service/ime/delta_input_on_action_update_impl.dart b/lib/src/editor/editor_component/service/ime/delta_input_on_action_update_impl.dart index 0139d2b6a..12261adff 100644 --- a/lib/src/editor/editor_component/service/ime/delta_input_on_action_update_impl.dart +++ b/lib/src/editor/editor_component/service/ime/delta_input_on_action_update_impl.dart @@ -1,10 +1,9 @@ import 'package:appflowy_editor/appflowy_editor.dart'; - import 'package:flutter/material.dart'; Future onPerformAction( TextInputAction action, EditorState editorState, ) async { - Log.input.debug('onPerformAction: $action'); + AppFlowyEditorLog.input.debug('onPerformAction: $action'); } diff --git a/lib/src/editor/editor_component/service/ime/delta_input_on_delete_impl.dart b/lib/src/editor/editor_component/service/ime/delta_input_on_delete_impl.dart index dae8317e5..99ef3d2f4 100644 --- a/lib/src/editor/editor_component/service/ime/delta_input_on_delete_impl.dart +++ b/lib/src/editor/editor_component/service/ime/delta_input_on_delete_impl.dart @@ -6,7 +6,7 @@ Future onDelete( TextEditingDeltaDeletion deletion, EditorState editorState, ) async { - Log.input.debug('onDelete: $deletion'); + AppFlowyEditorLog.input.debug('onDelete: $deletion'); final selection = editorState.selection; if (selection == null) { diff --git a/lib/src/editor/editor_component/service/ime/delta_input_on_floating_cursor_update.dart b/lib/src/editor/editor_component/service/ime/delta_input_on_floating_cursor_update.dart index 0d727941c..68eee1dae 100644 --- a/lib/src/editor/editor_component/service/ime/delta_input_on_floating_cursor_update.dart +++ b/lib/src/editor/editor_component/service/ime/delta_input_on_floating_cursor_update.dart @@ -1,5 +1,6 @@ import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:appflowy_editor/src/editor/editor_component/service/selection/mobile_selection_service.dart'; +import 'package:appflowy_editor/src/editor/util/platform_extension.dart'; import 'package:appflowy_editor/src/render/selection/mobile_basic_handle.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -10,7 +11,8 @@ Future onFloatingCursorUpdate( RawFloatingCursorPoint point, EditorState editorState, ) async { - Log.input.debug('onFloatingCursorUpdate: ${point.state}, ${point.offset}'); + AppFlowyEditorLog.input + .debug('onFloatingCursorUpdate: ${point.state}, ${point.offset}'); // support updating the cursor position via the space bar on iOS/Android. if (PlatformExtension.isDesktopOrWeb) { diff --git a/lib/src/editor/editor_component/service/ime/delta_input_on_insert_impl.dart b/lib/src/editor/editor_component/service/ime/delta_input_on_insert_impl.dart index 7a080c157..cd14f5072 100644 --- a/lib/src/editor/editor_component/service/ime/delta_input_on_insert_impl.dart +++ b/lib/src/editor/editor_component/service/ime/delta_input_on_insert_impl.dart @@ -8,7 +8,7 @@ Future onInsert( EditorState editorState, List characterShortcutEvents, ) async { - Log.input.debug('onInsert: $insertion'); + AppFlowyEditorLog.input.debug('onInsert: $insertion'); final textInserted = insertion.textInserted; diff --git a/lib/src/editor/editor_component/service/ime/delta_input_on_non_text_update_impl.dart b/lib/src/editor/editor_component/service/ime/delta_input_on_non_text_update_impl.dart index cb90d8fd4..f1581e078 100644 --- a/lib/src/editor/editor_component/service/ime/delta_input_on_non_text_update_impl.dart +++ b/lib/src/editor/editor_component/service/ime/delta_input_on_non_text_update_impl.dart @@ -1,4 +1,5 @@ import 'package:appflowy_editor/appflowy_editor.dart'; +import 'package:appflowy_editor/src/editor/util/platform_extension.dart'; import 'package:flutter/services.dart'; Future onNonTextUpdate( diff --git a/lib/src/editor/editor_component/service/ime/delta_input_on_replace_impl.dart b/lib/src/editor/editor_component/service/ime/delta_input_on_replace_impl.dart index 7c995255e..5607399f4 100644 --- a/lib/src/editor/editor_component/service/ime/delta_input_on_replace_impl.dart +++ b/lib/src/editor/editor_component/service/ime/delta_input_on_replace_impl.dart @@ -1,6 +1,7 @@ import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:appflowy_editor/src/editor/editor_component/service/ime/character_shortcut_event_helper.dart'; import 'package:appflowy_editor/src/editor/editor_component/service/ime/delta_input_impl.dart'; +import 'package:appflowy_editor/src/editor/util/platform_extension.dart'; import 'package:flutter/services.dart'; Future onReplace( @@ -8,7 +9,7 @@ Future onReplace( EditorState editorState, List characterShortcutEvents, ) async { - Log.input.debug('onReplace: $replacement'); + AppFlowyEditorLog.input.debug('onReplace: $replacement'); // delete the selection final selection = editorState.selection; diff --git a/lib/src/editor/editor_component/service/ime/delta_input_service.dart b/lib/src/editor/editor_component/service/ime/delta_input_service.dart index a41da8d4d..3cb647fc2 100644 --- a/lib/src/editor/editor_component/service/ime/delta_input_service.dart +++ b/lib/src/editor/editor_component/service/ime/delta_input_service.dart @@ -65,7 +65,7 @@ class DeltaTextInputService extends TextInputService with DeltaTextInputClient { ..show(); currentTextEditingValue = formattedValue; - Log.input.debug( + AppFlowyEditorLog.input.debug( 'attach text editing value: $textEditingValue', ); } @@ -79,7 +79,7 @@ class DeltaTextInputService extends TextInputService with DeltaTextInputClient { @override void updateEditingValueWithDeltas(List textEditingDeltas) { - Log.input.debug( + AppFlowyEditorLog.input.debug( textEditingDeltas.map((delta) => delta.toString()).toString(), ); apply(textEditingDeltas); diff --git a/lib/src/editor/editor_component/service/ime/non_delta_input_service.dart b/lib/src/editor/editor_component/service/ime/non_delta_input_service.dart index 26acd6cf4..6041dae6a 100644 --- a/lib/src/editor/editor_component/service/ime/non_delta_input_service.dart +++ b/lib/src/editor/editor_component/service/ime/non_delta_input_service.dart @@ -3,6 +3,7 @@ import 'dart:math'; import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:appflowy_editor/src/editor/editor_component/service/ime/text_diff.dart'; import 'package:appflowy_editor/src/editor/editor_component/service/ime/text_input_service.dart'; +import 'package:appflowy_editor/src/editor/util/platform_extension.dart'; import 'package:flutter/services.dart'; class NonDeltaTextInputService extends TextInputService with TextInputClient { @@ -84,7 +85,7 @@ class NonDeltaTextInputService extends TextInputService with TextInputClient { currentTextEditingValue = formattedValue; - Log.input.debug( + AppFlowyEditorLog.input.debug( 'attach text editing value: $textEditingValue', ); } @@ -135,13 +136,13 @@ class NonDeltaTextInputService extends TextInputService with TextInputClient { @override Future performAction(TextInputAction action) async { - Log.editor.debug('performAction: $action'); + AppFlowyEditorLog.editor.debug('performAction: $action'); return onPerformAction(action); } @override void performPrivateCommand(String action, Map data) { - Log.editor.debug('performPrivateCommand: $action, $data'); + AppFlowyEditorLog.editor.debug('performPrivateCommand: $action, $data'); } @override @@ -166,7 +167,7 @@ class NonDeltaTextInputService extends TextInputService with TextInputClient { @override void performSelector(String selectorName) { - Log.editor.debug('performSelector: $selectorName'); + AppFlowyEditorLog.editor.debug('performSelector: $selectorName'); } @override diff --git a/lib/src/editor/editor_component/service/keyboard_service_widget.dart b/lib/src/editor/editor_component/service/keyboard_service_widget.dart index cee1f71f3..80d095a52 100644 --- a/lib/src/editor/editor_component/service/keyboard_service_widget.dart +++ b/lib/src/editor/editor_component/service/keyboard_service_widget.dart @@ -176,12 +176,12 @@ class KeyboardServiceWidgetState extends State if (shortcutEvent.canRespondToRawKeyEvent(event)) { final result = shortcutEvent.handler(editorState); if (result == KeyEventResult.handled) { - Log.keyboard.debug( + AppFlowyEditorLog.keyboard.debug( 'keyboard service - handled by command shortcut event: $shortcutEvent', ); return KeyEventResult.handled; } else if (result == KeyEventResult.skipRemainingHandlers) { - Log.keyboard.debug( + AppFlowyEditorLog.keyboard.debug( 'keyboard service - skip by command shortcut event: $shortcutEvent', ); return KeyEventResult.skipRemainingHandlers; @@ -219,7 +219,7 @@ class KeyboardServiceWidgetState extends State if (editorState.selectionUpdateReason == SelectionUpdateReason.uiEvent) { focusNode.requestFocus(); - Log.editor.debug('keyboard service - request focus'); + AppFlowyEditorLog.editor.debug('keyboard service - request focus'); } } @@ -282,7 +282,7 @@ class KeyboardServiceWidgetState extends State } void _onFocusChanged() { - Log.editor.debug( + AppFlowyEditorLog.editor.debug( 'keyboard service - focus changed: ${focusNode.hasFocus}}', ); @@ -307,7 +307,7 @@ class KeyboardServiceWidgetState extends State } void _onKeepEditorFocusChanged() { - Log.editor.debug( + AppFlowyEditorLog.editor.debug( 'keyboard service - on keep editor focus changed: ${keepEditorFocusNotifier.value}}', ); diff --git a/lib/src/editor/editor_component/service/renderer/block_component_container.dart b/lib/src/editor/editor_component/service/renderer/block_component_container.dart index 949bf6e55..c4d982fb9 100644 --- a/lib/src/editor/editor_component/service/renderer/block_component_container.dart +++ b/lib/src/editor/editor_component/service/renderer/block_component_container.dart @@ -32,7 +32,8 @@ class BlockComponentContainerState extends State { value: widget.node, child: Consumer( builder: (_, __, ___) { - Log.editor.debug('node is rebuilding...: type: ${widget.node.type} '); + AppFlowyEditorLog.editor + .debug('node is rebuilding...: type: ${widget.node.type} '); return CompositedTransformTarget( link: widget.node.layerLink, child: widget.builder(context), diff --git a/lib/src/editor/editor_component/service/renderer/block_component_service.dart b/lib/src/editor/editor_component/service/renderer/block_component_service.dart index fefaa86dd..2975961f9 100644 --- a/lib/src/editor/editor_component/service/renderer/block_component_service.dart +++ b/lib/src/editor/editor_component/service/renderer/block_component_service.dart @@ -151,7 +151,8 @@ class BlockComponentRenderer extends BlockComponentRendererService { @override void register(String type, BlockComponentBuilder builder) { - Log.editor.info('register block component builder for type($type)'); + AppFlowyEditorLog.editor + .info('register block component builder for type($type)'); if (type.isEmpty) { throw ArgumentError('type should not be empty'); } diff --git a/lib/src/editor/editor_component/service/scroll/auto_scrollable_widget.dart b/lib/src/editor/editor_component/service/scroll/auto_scrollable_widget.dart index c2a5fd74c..3685e86b2 100644 --- a/lib/src/editor/editor_component/service/scroll/auto_scrollable_widget.dart +++ b/lib/src/editor/editor_component/service/scroll/auto_scrollable_widget.dart @@ -1,5 +1,5 @@ -import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:appflowy_editor/src/editor/editor_component/service/scroll/auto_scroller.dart'; +import 'package:appflowy_editor/src/editor/util/platform_extension.dart'; import 'package:flutter/material.dart'; class AutoScrollableWidget extends StatefulWidget { diff --git a/lib/src/editor/editor_component/service/scroll/desktop_scroll_service.dart b/lib/src/editor/editor_component/service/scroll/desktop_scroll_service.dart index 3dc9611e9..bae02cd79 100644 --- a/lib/src/editor/editor_component/service/scroll/desktop_scroll_service.dart +++ b/lib/src/editor/editor_component/service/scroll/desktop_scroll_service.dart @@ -85,12 +85,12 @@ class _DesktopScrollServiceState extends State @override void disable() { - Log.scroll.debug('disable scroll service'); + AppFlowyEditorLog.scroll.debug('disable scroll service'); } @override void enable() { - Log.scroll.debug('enable scroll service'); + AppFlowyEditorLog.scroll.debug('enable scroll service'); } @override diff --git a/lib/src/editor/editor_component/service/scroll/mobile_scroll_service.dart b/lib/src/editor/editor_component/service/scroll/mobile_scroll_service.dart index 2ae995617..7416005ea 100644 --- a/lib/src/editor/editor_component/service/scroll/mobile_scroll_service.dart +++ b/lib/src/editor/editor_component/service/scroll/mobile_scroll_service.dart @@ -81,12 +81,12 @@ class _MobileScrollServiceState extends State @override void disable() { - Log.scroll.debug('disable scroll service'); + AppFlowyEditorLog.scroll.debug('disable scroll service'); } @override void enable() { - Log.scroll.debug('enable scroll service'); + AppFlowyEditorLog.scroll.debug('enable scroll service'); } @override diff --git a/lib/src/editor/editor_component/service/scroll_service_widget.dart b/lib/src/editor/editor_component/service/scroll_service_widget.dart index 18c1add9d..7f3664066 100644 --- a/lib/src/editor/editor_component/service/scroll_service_widget.dart +++ b/lib/src/editor/editor_component/service/scroll_service_widget.dart @@ -2,6 +2,7 @@ import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:appflowy_editor/src/editor/editor_component/service/scroll/desktop_scroll_service.dart'; import 'package:appflowy_editor/src/editor/editor_component/service/scroll/mobile_scroll_service.dart'; import 'package:appflowy_editor/src/editor/toolbar/mobile/utils/keyboard_height_observer.dart'; +import 'package:appflowy_editor/src/editor/util/platform_extension.dart'; import 'package:flutter/material.dart'; import 'package:provider/provider.dart'; diff --git a/lib/src/editor/editor_component/service/selection/mobile_selection_service.dart b/lib/src/editor/editor_component/service/selection/mobile_selection_service.dart index daf7624fd..349357d95 100644 --- a/lib/src/editor/editor_component/service/selection/mobile_selection_service.dart +++ b/lib/src/editor/editor_component/service/selection/mobile_selection_service.dart @@ -1,18 +1,16 @@ import 'dart:async'; -import 'dart:io'; - -import 'package:flutter/material.dart' hide Overlay, OverlayEntry; -import 'package:flutter/services.dart'; - -import 'package:provider/provider.dart'; import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:appflowy_editor/src/editor/editor_component/service/selection/mobile_magnifier.dart'; import 'package:appflowy_editor/src/editor/editor_component/service/selection/shared.dart'; +import 'package:appflowy_editor/src/editor/util/platform_extension.dart'; import 'package:appflowy_editor/src/render/selection/mobile_basic_handle.dart'; import 'package:appflowy_editor/src/render/selection/mobile_collapsed_handle.dart'; import 'package:appflowy_editor/src/render/selection/mobile_selection_handle.dart'; import 'package:appflowy_editor/src/service/selection/mobile_selection_gesture.dart'; +import 'package:flutter/material.dart' hide Overlay, OverlayEntry; +import 'package:flutter/services.dart'; +import 'package:provider/provider.dart'; /// only used in mobile /// @@ -135,7 +133,7 @@ class _MobileSelectionServiceWidgetState _buildCollapsedHandle(), ], ); - return Platform.isIOS + return PlatformExtension.isIOS ? MobileSelectionGestureDetector( onTapUp: _onTapUpIOS, onDoubleTapUp: _onDoubleTapUp, @@ -310,7 +308,7 @@ class _MobileSelectionServiceWidgetState if (selection != null) { if (!selection.isCollapsed) { // updates selection area. - Log.selection.debug('update cursor area, $selection'); + AppFlowyEditorLog.selection.debug('update cursor area, $selection'); _updateSelectionAreas(selection); } } @@ -401,7 +399,7 @@ class _MobileSelectionServiceWidgetState if (selection != null) { if (!selection.isCollapsed) { // updates selection area. - Log.selection.debug('update cursor area, $selection'); + AppFlowyEditorLog.selection.debug('update cursor area, $selection'); WidgetsBinding.instance.addPostFrameCallback((timeStamp) { selectionRects.clear(); _clearSelection(); @@ -772,7 +770,8 @@ class _MobileSelectionServiceWidgetState final normalizedSelection = selection.normalized; assert(normalizedSelection.isBackward); - Log.selection.debug('update selection areas, $normalizedSelection'); + AppFlowyEditorLog.selection + .debug('update selection areas, $normalizedSelection'); for (var i = 0; i < backwardNodes.length; i++) { final node = backwardNodes[i]; diff --git a/lib/src/editor/editor_component/service/selection_service_widget.dart b/lib/src/editor/editor_component/service/selection_service_widget.dart index c79abb867..14d2c3e1a 100644 --- a/lib/src/editor/editor_component/service/selection_service_widget.dart +++ b/lib/src/editor/editor_component/service/selection_service_widget.dart @@ -1,10 +1,9 @@ -import 'package:flutter/material.dart' hide Overlay, OverlayEntry; - -import 'package:provider/provider.dart'; - import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:appflowy_editor/src/editor/editor_component/service/selection/desktop_selection_service.dart'; import 'package:appflowy_editor/src/editor/editor_component/service/selection/mobile_selection_service.dart'; +import 'package:appflowy_editor/src/editor/util/platform_extension.dart'; +import 'package:flutter/material.dart' hide Overlay, OverlayEntry; +import 'package:provider/provider.dart'; class SelectionServiceWidget extends StatefulWidget { const SelectionServiceWidget({ diff --git a/lib/src/editor/editor_component/service/shortcuts/character/insert_newline.dart b/lib/src/editor/editor_component/service/shortcuts/character/insert_newline.dart index b71fac348..0bb1c0375 100644 --- a/lib/src/editor/editor_component/service/shortcuts/character/insert_newline.dart +++ b/lib/src/editor/editor_component/service/shortcuts/character/insert_newline.dart @@ -1,6 +1,6 @@ import 'package:appflowy_editor/src/editor/command/transform.dart'; import 'package:appflowy_editor/src/editor/editor_component/service/shortcuts/character_shortcut_event.dart'; -import 'package:appflowy_editor/src/editor/util/util.dart'; +import 'package:appflowy_editor/src/editor/util/platform_extension.dart'; import 'package:flutter/services.dart'; /// insert a new line block diff --git a/lib/src/editor/editor_component/service/shortcuts/character/slash_command.dart b/lib/src/editor/editor_component/service/shortcuts/character/slash_command.dart index b4001a6d0..61bb39e89 100644 --- a/lib/src/editor/editor_component/service/shortcuts/character/slash_command.dart +++ b/lib/src/editor/editor_component/service/shortcuts/character/slash_command.dart @@ -1,6 +1,7 @@ import 'dart:io'; import 'package:appflowy_editor/appflowy_editor.dart'; +import 'package:appflowy_editor/src/editor/util/platform_extension.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; diff --git a/lib/src/editor/editor_component/service/shortcuts/command/find_replace_command.dart b/lib/src/editor/editor_component/service/shortcuts/command/find_replace_command.dart index 141e91703..968f93029 100644 --- a/lib/src/editor/editor_component/service/shortcuts/command/find_replace_command.dart +++ b/lib/src/editor/editor_component/service/shortcuts/command/find_replace_command.dart @@ -1,5 +1,6 @@ import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:appflowy_editor/src/editor/find_replace_menu/find_menu_service.dart'; +import 'package:appflowy_editor/src/editor/util/platform_extension.dart'; import 'package:flutter/material.dart'; List findAndReplaceCommands({ diff --git a/lib/src/editor/editor_component/service/shortcuts/command/page_up_command.dart b/lib/src/editor/editor_component/service/shortcuts/command/page_up_command.dart index 8d39ff9c0..0505e6839 100644 --- a/lib/src/editor/editor_component/service/shortcuts/command/page_up_command.dart +++ b/lib/src/editor/editor_component/service/shortcuts/command/page_up_command.dart @@ -1,4 +1,5 @@ import 'package:appflowy_editor/appflowy_editor.dart'; +import 'package:appflowy_editor/src/editor/util/platform_extension.dart'; import 'package:flutter/material.dart'; /// Page up key event. diff --git a/lib/src/editor/editor_component/service/shortcuts/command/show_link_menu_command.dart b/lib/src/editor/editor_component/service/shortcuts/command/show_link_menu_command.dart index 97174de91..64e50efd1 100644 --- a/lib/src/editor/editor_component/service/shortcuts/command/show_link_menu_command.dart +++ b/lib/src/editor/editor_component/service/shortcuts/command/show_link_menu_command.dart @@ -1,4 +1,5 @@ import 'package:appflowy_editor/appflowy_editor.dart'; +import 'package:appflowy_editor/src/editor/util/platform_extension.dart'; import 'package:flutter/material.dart'; /// Cmd / Ctrl + K: show link menu diff --git a/lib/src/editor/editor_component/service/shortcuts/command/toggle_colors_command.dart b/lib/src/editor/editor_component/service/shortcuts/command/toggle_colors_command.dart index 17b15c88f..5d7b4e9f7 100644 --- a/lib/src/editor/editor_component/service/shortcuts/command/toggle_colors_command.dart +++ b/lib/src/editor/editor_component/service/shortcuts/command/toggle_colors_command.dart @@ -1,4 +1,5 @@ import 'package:appflowy_editor/appflowy_editor.dart'; +import 'package:appflowy_editor/src/editor/util/platform_extension.dart'; import 'package:flutter/material.dart'; /// Toggle Color Commands diff --git a/lib/src/editor/editor_component/service/shortcuts/command_shortcut_event.dart b/lib/src/editor/editor_component/service/shortcuts/command_shortcut_event.dart index a9de986fd..92a1a6239 100644 --- a/lib/src/editor/editor_component/service/shortcuts/command_shortcut_event.dart +++ b/lib/src/editor/editor_component/service/shortcuts/command_shortcut_event.dart @@ -1,4 +1,5 @@ import 'package:appflowy_editor/appflowy_editor.dart'; +import 'package:appflowy_editor/src/editor/util/platform_extension.dart'; import 'package:flutter/material.dart'; typedef CommandShortcutEventHandler = KeyEventResult Function( diff --git a/lib/src/editor/selection_menu/selection_menu_widget.dart b/lib/src/editor/selection_menu/selection_menu_widget.dart index 05a5857a9..adaab2b4e 100644 --- a/lib/src/editor/selection_menu/selection_menu_widget.dart +++ b/lib/src/editor/selection_menu/selection_menu_widget.dart @@ -280,7 +280,7 @@ class _SelectionMenuWidgetState extends State { ) .toList(growable: false); - Log.ui.debug('$items'); + AppFlowyEditorLog.ui.debug('$items'); if (keyword.length >= maxKeywordLength + 2 && !(widget.deleteSlashByDefault && _searchCounter < 2)) { @@ -462,7 +462,7 @@ class _SelectionMenuWidgetState extends State { /// Handles keyword searches /// Handles enter to select item and esc to exit KeyEventResult _onKeyEvent(FocusNode node, KeyEvent event) { - Log.keyboard.debug('slash command, on key $event'); + AppFlowyEditorLog.keyboard.debug('slash command, on key $event'); if (event is! KeyDownEvent) { return KeyEventResult.ignored; diff --git a/lib/src/editor/toolbar/desktop/items/utils/tooltip_util.dart b/lib/src/editor/toolbar/desktop/items/utils/tooltip_util.dart index 531e1c246..45c49dab5 100644 --- a/lib/src/editor/toolbar/desktop/items/utils/tooltip_util.dart +++ b/lib/src/editor/toolbar/desktop/items/utils/tooltip_util.dart @@ -1,6 +1,5 @@ -import 'dart:io'; - import 'package:appflowy_editor/appflowy_editor.dart'; +import 'package:appflowy_editor/src/editor/util/platform_extension.dart'; import 'package:flutter/foundation.dart'; String shortcutTooltips( @@ -9,11 +8,11 @@ String shortcutTooltips( String? linuxString, ) { if (kIsWeb) return ''; - if (Platform.isMacOS && macOSString != null) { + if (PlatformExtension.isMacOS && macOSString != null) { return '\n$macOSString'; - } else if (Platform.isWindows && windowsString != null) { + } else if (PlatformExtension.isWindows && windowsString != null) { return '\n$windowsString'; - } else if (Platform.isLinux && linuxString != null) { + } else if (PlatformExtension.isLinux && linuxString != null) { return '\n$linuxString'; } return ''; diff --git a/lib/src/editor/toolbar/mobile/utils/keyboard_height_observer.dart b/lib/src/editor/toolbar/mobile/utils/keyboard_height_observer.dart index 33861fc2d..ef88c4e12 100644 --- a/lib/src/editor/toolbar/mobile/utils/keyboard_height_observer.dart +++ b/lib/src/editor/toolbar/mobile/utils/keyboard_height_observer.dart @@ -1,5 +1,4 @@ -import 'dart:io'; - +import 'package:appflowy_editor/src/editor/util/platform_extension.dart'; import 'package:device_info_plus/device_info_plus.dart'; import 'package:keyboard_height_plugin/keyboard_height_plugin.dart'; @@ -11,7 +10,7 @@ class KeyboardHeightObserver { static int androidSDKVersion = -1; KeyboardHeightObserver._() { - if (Platform.isAndroid && androidSDKVersion == -1) { + if (PlatformExtension.isAndroid && androidSDKVersion == -1) { DeviceInfoPlugin().androidInfo.then( (value) => androidSDKVersion = value.version.sdkInt, ); @@ -44,7 +43,7 @@ class KeyboardHeightObserver { void notify(double height) { // the keyboard height will notify twice with the same value on Android - if (Platform.isAndroid && height == currentKeyboardHeight) { + if (PlatformExtension.isAndroid && height == currentKeyboardHeight) { return; } diff --git a/lib/src/editor/util/platform_extension.dart b/lib/src/editor/util/platform_extension.dart index 65cead673..80544369c 100644 --- a/lib/src/editor/util/platform_extension.dart +++ b/lib/src/editor/util/platform_extension.dart @@ -2,6 +2,7 @@ import 'dart:io'; import 'package:flutter/foundation.dart'; import 'package:universal_html/html.dart' show window; +import 'package:universal_platform/universal_platform.dart'; // TODO(Xazin): Refactor to honor `Theme.platform` extension PlatformExtension on Platform { @@ -9,36 +10,19 @@ extension PlatformExtension on Platform { window.navigator.platform?.toLowerCase() ?? ''; /// Returns true if the operating system is macOS and not running on Web platform. - static bool get isMacOS { - if (kIsWeb) { - return false; - } - return Platform.isMacOS; - } + static bool get isMacOS => UniversalPlatform.isMacOS; /// Returns true if the operating system is Windows and not running on Web platform. - static bool get isWindows { - if (kIsWeb) { - return false; - } - return Platform.isWindows; - } + static bool get isWindows => UniversalPlatform.isWindows; /// Returns true if the operating system is Linux and not running on Web platform. - static bool get isLinux { - if (kIsWeb) { - return false; - } - return Platform.isLinux; - } + static bool get isLinux => UniversalPlatform.isLinux; /// Returns true if the operating system is iOS and not running on Web platform. - static bool get isIOS { - if (kIsWeb) { - return false; - } - return Platform.isIOS; - } + static bool get isIOS => UniversalPlatform.isIOS; + + /// Returns true if the operating system is Android and not running on Web platform. + static bool get isAndroid => UniversalPlatform.isAndroid; /// Returns true if the operating system is macOS and running on Web platform. static bool get isWebOnMacOS { @@ -64,31 +48,12 @@ extension PlatformExtension on Platform { return _webPlatform.contains('linux') == true; } - static bool get isDesktopOrWeb { - if (kIsWeb) { - return true; - } - return isDesktop; - } + static bool get isDesktopOrWeb => + UniversalPlatform.isWeb || UniversalPlatform.isDesktop; - static bool get isDesktop { - if (kIsWeb) { - return false; - } - return Platform.isWindows || Platform.isLinux || Platform.isMacOS; - } + static bool get isDesktop => UniversalPlatform.isDesktop; - static bool get isMobile { - if (kIsWeb) { - return false; - } - return Platform.isAndroid || Platform.isIOS; - } + static bool get isMobile => UniversalPlatform.isMobile; - static bool get isNotMobile { - if (kIsWeb) { - return false; - } - return !isMobile; - } + static bool get isNotMobile => !isMobile; } diff --git a/lib/src/editor/util/util.dart b/lib/src/editor/util/util.dart index 99a28fcd5..2e6e1512f 100644 --- a/lib/src/editor/util/util.dart +++ b/lib/src/editor/util/util.dart @@ -2,6 +2,5 @@ export 'color_util.dart'; export 'debounce.dart'; export 'delta_util.dart'; export 'editor_state_selectable_extension.dart'; -export 'platform_extension.dart'; export 'property_notifier.dart'; export 'text_direction.dart'; diff --git a/lib/src/editor_state.dart b/lib/src/editor_state.dart index 9d6bc1242..b484e3b0c 100644 --- a/lib/src/editor_state.dart +++ b/lib/src/editor_state.dart @@ -1,12 +1,12 @@ import 'dart:async'; import 'dart:collection'; -import 'package:flutter/foundation.dart'; -import 'package:flutter/material.dart'; - import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:appflowy_editor/src/editor/editor_component/service/scroll/auto_scroller.dart'; +import 'package:appflowy_editor/src/editor/util/platform_extension.dart'; import 'package:appflowy_editor/src/history/undo_manager.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; /// the type of this value is bool. /// @@ -148,7 +148,7 @@ class EditorState { /// Configures log output parameters, /// such as log level and log output callbacks, /// with this variable. - LogConfiguration get logConfiguration => LogConfiguration(); + AppFlowyLogConfiguration get logConfiguration => AppFlowyLogConfiguration(); /// Stores the selection menu items. List selectionMenuItems = []; @@ -531,7 +531,7 @@ class EditorState { } undoItem.afterSelection = transaction.afterSelection; if (skipDebounce && undoManager.undoStack.isNonEmpty) { - Log.editor.debug('Seal history item'); + AppFlowyEditorLog.editor.debug('Seal history item'); final last = undoManager.undoStack.last; last.seal(); } else { @@ -553,7 +553,7 @@ class EditorState { _debouncedSealHistoryItemTimer?.cancel(); _debouncedSealHistoryItemTimer = Timer(minHistoryItemDuration, () { if (undoManager.undoStack.isNonEmpty) { - Log.editor.debug('Seal history item'); + AppFlowyEditorLog.editor.debug('Seal history item'); final last = undoManager.undoStack.last; last.seal(); } @@ -562,7 +562,7 @@ class EditorState { void _applyTransactionInLocal(Transaction transaction) { for (final op in transaction.operations) { - Log.editor.debug('apply op (local): ${op.toJson()}'); + AppFlowyEditorLog.editor.debug('apply op (local): ${op.toJson()}'); if (op is InsertOperation) { document.insert(op.path, op.nodes); @@ -583,7 +583,7 @@ class EditorState { var selection = this.selection; for (final op in transaction.operations) { - Log.editor.debug('apply op (remote): ${op.toJson()}'); + AppFlowyEditorLog.editor.debug('apply op (remote): ${op.toJson()}'); if (op is InsertOperation) { document.insert(op.path, op.nodes); diff --git a/lib/src/history/undo_manager.dart b/lib/src/history/undo_manager.dart index 8a3ed45d2..c0ef15a17 100644 --- a/lib/src/history/undo_manager.dart +++ b/lib/src/history/undo_manager.dart @@ -1,10 +1,10 @@ import 'dart:collection'; import 'package:appflowy_editor/src/core/location/selection.dart'; -import 'package:appflowy_editor/src/infra/log.dart'; import 'package:appflowy_editor/src/core/transform/operation.dart'; import 'package:appflowy_editor/src/core/transform/transaction.dart'; import 'package:appflowy_editor/src/editor_state.dart'; +import 'package:appflowy_editor/src/infra/log.dart'; /// A [HistoryItem] contains list of operations committed by users. /// If a [HistoryItem] is not sealed, operations can be added sequentially. @@ -111,7 +111,7 @@ class UndoManager { } void undo() { - Log.editor.debug('undo'); + AppFlowyEditorLog.editor.debug('undo'); final s = state; if (s == null) { return; @@ -131,7 +131,7 @@ class UndoManager { } void redo() { - Log.editor.debug('redo'); + AppFlowyEditorLog.editor.debug('redo'); final s = state; if (s == null) { return; @@ -151,7 +151,7 @@ class UndoManager { } void forgetRecentUndo() { - Log.editor.debug('forgetRecentUndo'); + AppFlowyEditorLog.editor.debug('forgetRecentUndo'); if (state != null) { undoStack.pop(); } diff --git a/lib/src/infra/log.dart b/lib/src/infra/log.dart index b3e55058d..7259e398e 100644 --- a/lib/src/infra/log.dart +++ b/lib/src/infra/log.dart @@ -1,6 +1,6 @@ import 'package:logging/logging.dart'; -enum LogLevel { +enum AppFlowyEditorLogLevel { off, error, warn, @@ -9,13 +9,13 @@ enum LogLevel { all, } -typedef LogHandler = void Function(String message); +typedef AppFlowyEditorLogHandler = void Function(String message); /// Manages log service for [AppFlowyEditor] /// /// Set the log level and config the handler depending on your need. -class LogConfiguration { - LogConfiguration._() { +class AppFlowyLogConfiguration { + AppFlowyLogConfiguration._() { Logger.root.onRecord.listen((record) { if (handler != null) { handler!( @@ -25,24 +25,25 @@ class LogConfiguration { }); } - factory LogConfiguration() => _logConfiguration; + factory AppFlowyLogConfiguration() => _logConfiguration; - static final LogConfiguration _logConfiguration = LogConfiguration._(); + static final AppFlowyLogConfiguration _logConfiguration = + AppFlowyLogConfiguration._(); - LogHandler? handler; + AppFlowyEditorLogHandler? handler; - LogLevel _level = LogLevel.off; + AppFlowyEditorLogLevel _level = AppFlowyEditorLogLevel.off; - LogLevel get level => _level; - set level(LogLevel level) { + AppFlowyEditorLogLevel get level => _level; + set level(AppFlowyEditorLogLevel level) { _level = level; Logger.root.level = level.toLevel(); } } /// For logging message in AppFlowyEditor -class Log { - Log._({ +class AppFlowyEditorLog { + AppFlowyEditorLog._({ required this.name, }) : _logger = Logger(name); @@ -53,37 +54,37 @@ class Log { /// /// For example, uses the logger when registering plugins /// or handling something related to [EditorState]. - static Log editor = Log._(name: 'editor'); + static AppFlowyEditorLog editor = AppFlowyEditorLog._(name: 'editor'); /// For logging message related to [AppFlowySelectionService]. /// /// For example, uses the logger when updating or clearing selection. - static Log selection = Log._(name: 'selection'); + static AppFlowyEditorLog selection = AppFlowyEditorLog._(name: 'selection'); /// For logging message related to [AppFlowyKeyboardService]. /// /// For example, uses the logger when processing shortcut events. - static Log keyboard = Log._(name: 'keyboard'); + static AppFlowyEditorLog keyboard = AppFlowyEditorLog._(name: 'keyboard'); /// For logging message related to [AppFlowyInputService]. /// /// For example, uses the logger when processing text inputs. - static Log input = Log._(name: 'input'); + static AppFlowyEditorLog input = AppFlowyEditorLog._(name: 'input'); /// For logging message related to [AppFlowyScrollService]. /// /// For example, uses the logger when processing scroll events. - static Log scroll = Log._(name: 'scroll'); + static AppFlowyEditorLog scroll = AppFlowyEditorLog._(name: 'scroll'); /// For logging message related to [FloatingToolbar] or [MobileToolbar]. /// /// For example, uses the logger when processing toolbar events. - static Log toolbar = Log._(name: 'toolbar'); + static AppFlowyEditorLog toolbar = AppFlowyEditorLog._(name: 'toolbar'); /// For logging message related to UI. /// /// For example, uses the logger when building the widget. - static Log ui = Log._(name: 'ui'); + static AppFlowyEditorLog ui = AppFlowyEditorLog._(name: 'ui'); void error(String message) => _logger.severe(message); void warn(String message) => _logger.warning(message); @@ -91,53 +92,53 @@ class Log { void debug(String message) => _logger.fine(message); } -extension on LogLevel { +extension on AppFlowyEditorLogLevel { Level toLevel() { switch (this) { - case LogLevel.off: + case AppFlowyEditorLogLevel.off: return Level.OFF; - case LogLevel.error: + case AppFlowyEditorLogLevel.error: return Level.SEVERE; - case LogLevel.warn: + case AppFlowyEditorLogLevel.warn: return Level.WARNING; - case LogLevel.info: + case AppFlowyEditorLogLevel.info: return Level.INFO; - case LogLevel.debug: + case AppFlowyEditorLogLevel.debug: return Level.FINE; - case LogLevel.all: + case AppFlowyEditorLogLevel.all: return Level.ALL; } } String get name { switch (this) { - case LogLevel.off: + case AppFlowyEditorLogLevel.off: return 'OFF'; - case LogLevel.error: + case AppFlowyEditorLogLevel.error: return 'ERROR'; - case LogLevel.warn: + case AppFlowyEditorLogLevel.warn: return 'WARN'; - case LogLevel.info: + case AppFlowyEditorLogLevel.info: return 'INFO'; - case LogLevel.debug: + case AppFlowyEditorLogLevel.debug: return 'DEBUG'; - case LogLevel.all: + case AppFlowyEditorLogLevel.all: return 'ALL'; } } } extension on Level { - LogLevel toLogLevel() { + AppFlowyEditorLogLevel toLogLevel() { if (this == Level.SEVERE) { - return LogLevel.error; + return AppFlowyEditorLogLevel.error; } else if (this == Level.WARNING) { - return LogLevel.warn; + return AppFlowyEditorLogLevel.warn; } else if (this == Level.INFO) { - return LogLevel.info; + return AppFlowyEditorLogLevel.info; } else if (this == Level.FINE) { - return LogLevel.debug; + return AppFlowyEditorLogLevel.debug; } - return LogLevel.off; + return AppFlowyEditorLogLevel.off; } } diff --git a/lib/src/plugins/html/html_document_decoder.dart b/lib/src/plugins/html/html_document_decoder.dart index a319a1b02..462dcd4c1 100644 --- a/lib/src/plugins/html/html_document_decoder.dart +++ b/lib/src/plugins/html/html_document_decoder.dart @@ -56,7 +56,7 @@ class DocumentHTMLDecoder extends Converter { } delta.insert(domNode.text); } else { - Log.editor.debug('Unknown node type: $domNode'); + AppFlowyEditorLog.editor.debug('Unknown node type: $domNode'); } } if (delta.isNotEmpty) { diff --git a/lib/src/plugins/markdown/decoder/document_markdown_decoder.dart b/lib/src/plugins/markdown/decoder/document_markdown_decoder.dart index 197282eb5..1ed84483e 100644 --- a/lib/src/plugins/markdown/decoder/document_markdown_decoder.dart +++ b/lib/src/plugins/markdown/decoder/document_markdown_decoder.dart @@ -56,7 +56,7 @@ class DocumentMarkdownDecoder extends Converter { } if (nodes.isEmpty) { - Log.editor.debug( + AppFlowyEditorLog.editor.debug( 'empty result from node: $mdNode, text: ${mdNode.textContent}', ); } diff --git a/lib/src/render/selection/mobile_basic_handle.dart b/lib/src/render/selection/mobile_basic_handle.dart index 7d14e8f36..7b52b5409 100644 --- a/lib/src/render/selection/mobile_basic_handle.dart +++ b/lib/src/render/selection/mobile_basic_handle.dart @@ -1,8 +1,8 @@ -import 'dart:io'; import 'dart:math'; import 'package:appflowy_editor/appflowy_editor.dart'; import 'package:appflowy_editor/src/editor/editor_component/service/selection/mobile_selection_service.dart'; +import 'package:appflowy_editor/src/editor/util/platform_extension.dart'; import 'package:flutter/gestures.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; @@ -92,7 +92,7 @@ class DragHandle extends _IDragHandle { Widget build(BuildContext context) { Widget child; - if (Platform.isIOS) { + if (PlatformExtension.isIOS) { child = _IOSDragHandle( handleHeight: handleHeight, handleColor: handleColor, @@ -101,7 +101,7 @@ class DragHandle extends _IDragHandle { handleType: handleType, debugPaintSizeEnabled: debugPaintSizeEnabled, ); - } else if (Platform.isAndroid) { + } else if (PlatformExtension.isAndroid) { child = _AndroidDragHandle( handleHeight: handleHeight, handleColor: handleColor, @@ -122,7 +122,7 @@ class DragHandle extends _IDragHandle { } if (handleType != HandleType.none && handleType != HandleType.collapsed) { - final offset = Platform.isIOS ? -handleWidth : 0.0; + final offset = PlatformExtension.isIOS ? -handleWidth : 0.0; child = Stack( clipBehavior: Clip.none, children: [ diff --git a/lib/src/render/selection/mobile_collapsed_handle.dart b/lib/src/render/selection/mobile_collapsed_handle.dart index 1b0374bf4..77d852c28 100644 --- a/lib/src/render/selection/mobile_collapsed_handle.dart +++ b/lib/src/render/selection/mobile_collapsed_handle.dart @@ -1,5 +1,4 @@ -import 'dart:io'; - +import 'package:appflowy_editor/src/editor/util/platform_extension.dart'; import 'package:appflowy_editor/src/render/selection/mobile_basic_handle.dart'; import 'package:flutter/material.dart'; @@ -23,13 +22,13 @@ class MobileCollapsedHandle extends StatelessWidget { @override Widget build(BuildContext context) { - if (Platform.isIOS) { + if (PlatformExtension.isIOS) { return _IOSCollapsedHandle( layerLink: layerLink, rect: rect, handleWidth: handleWidth, ); - } else if (Platform.isAndroid) { + } else if (PlatformExtension.isAndroid) { return _AndroidCollapsedHandle( layerLink: layerLink, rect: rect, diff --git a/lib/src/render/selection/mobile_selection_handle.dart b/lib/src/render/selection/mobile_selection_handle.dart index 5b0fa3b3e..01436c653 100644 --- a/lib/src/render/selection/mobile_selection_handle.dart +++ b/lib/src/render/selection/mobile_selection_handle.dart @@ -1,5 +1,4 @@ -import 'dart:io'; - +import 'package:appflowy_editor/src/editor/util/platform_extension.dart'; import 'package:appflowy_editor/src/render/selection/mobile_basic_handle.dart'; import 'package:flutter/material.dart'; @@ -29,7 +28,7 @@ class MobileSelectionHandle extends StatelessWidget { var adjustedRect = rect; if (handleType != HandleType.none) { - if (Platform.isIOS) { + if (PlatformExtension.isIOS) { // on iOS, the cursor will still be visible if the selection is not collapsed. // So, adding a threshold padding to avoid row overflow. const threshold = 0.25; @@ -39,7 +38,7 @@ class MobileSelectionHandle extends StatelessWidget { rect.width + 4 * (handleWidth + threshold), rect.height + 2 * handleBallWidth, ); - } else if (Platform.isAndroid) { + } else if (PlatformExtension.isAndroid) { // on Android, normally the cursor will be hidden if the selection is not collapsed. // Extend the click area to make it easier to click. adjustedRect = Rect.fromLTWH( diff --git a/lib/src/service/internal_key_event_handlers/copy_paste_handler.dart b/lib/src/service/internal_key_event_handlers/copy_paste_handler.dart index e536a40a5..3d4a24fed 100644 --- a/lib/src/service/internal_key_event_handlers/copy_paste_handler.dart +++ b/lib/src/service/internal_key_event_handlers/copy_paste_handler.dart @@ -92,7 +92,7 @@ void pasteHTML(EditorState editorState, String html) { return; } - Log.keyboard.debug('paste html: $html'); + AppFlowyEditorLog.keyboard.debug('paste html: $html'); final htmlToNodes = htmlToDocument(html).root.children.where((element) { final delta = element.delta; diff --git a/pubspec.yaml b/pubspec.yaml index 175e9455a..8fc2043ac 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -31,6 +31,7 @@ dependencies: scroll_to_index: "^3.0.1" string_validator: "^1.0.0" universal_html: "^2.2.4" + universal_platform: ^1.1.0 url_launcher: "^6.1.11" dev_dependencies: diff --git a/test/editor/util/platform_extension_test.dart b/test/editor/util/platform_extension_test.dart index df9cd2364..3f3aeed4f 100644 --- a/test/editor/util/platform_extension_test.dart +++ b/test/editor/util/platform_extension_test.dart @@ -1,6 +1,6 @@ import 'dart:io'; -import 'package:appflowy_editor/appflowy_editor.dart'; +import 'package:appflowy_editor/src/editor/util/platform_extension.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter_test/flutter_test.dart'; diff --git a/test/infra/log_test.dart b/test/infra/log_test.dart index bfb9765e3..949a2b498 100644 --- a/test/infra/log_test.dart +++ b/test/infra/log_test.dart @@ -14,12 +14,12 @@ void main() async { final editor = tester.editor; editor.editorState.logConfiguration - ..level = LogLevel.all + ..level = AppFlowyEditorLogLevel.all ..handler = (message) { logs.add(message); }; - Log.editor.debug(text); + AppFlowyEditorLog.editor.debug(text); expect(logs.last.contains('DEBUG'), true); expect(logs.length, 1); }); @@ -28,19 +28,19 @@ void main() async { const text = 'Welcome to Appflowy 😁'; final List logs = []; - LogConfiguration() - ..level = LogLevel.all + AppFlowyLogConfiguration() + ..level = AppFlowyEditorLogLevel.all ..handler = (message) { logs.add(message); }; - Log.editor.debug(text); + AppFlowyEditorLog.editor.debug(text); expect(logs.last.contains('DEBUG'), true); - Log.editor.info(text); + AppFlowyEditorLog.editor.info(text); expect(logs.last.contains('INFO'), true); - Log.editor.warn(text); + AppFlowyEditorLog.editor.warn(text); expect(logs.last.contains('WARN'), true); - Log.editor.error(text); + AppFlowyEditorLog.editor.error(text); expect(logs.last.contains('ERROR'), true); expect(logs.length, 4); @@ -50,16 +50,16 @@ void main() async { const text = 'Welcome to Appflowy 😁'; final List logs = []; - LogConfiguration() - ..level = LogLevel.off + AppFlowyLogConfiguration() + ..level = AppFlowyEditorLogLevel.off ..handler = (message) { logs.add(message); }; - Log.editor.debug(text); - Log.editor.info(text); - Log.editor.warn(text); - Log.editor.error(text); + AppFlowyEditorLog.editor.debug(text); + AppFlowyEditorLog.editor.info(text); + AppFlowyEditorLog.editor.warn(text); + AppFlowyEditorLog.editor.error(text); expect(logs.length, 0); }); @@ -68,16 +68,16 @@ void main() async { const text = 'Welcome to Appflowy 😁'; final List logs = []; - LogConfiguration() - ..level = LogLevel.error + AppFlowyLogConfiguration() + ..level = AppFlowyEditorLogLevel.error ..handler = (message) { logs.add(message); }; - Log.editor.debug(text); - Log.editor.info(text); - Log.editor.warn(text); - Log.editor.error(text); + AppFlowyEditorLog.editor.debug(text); + AppFlowyEditorLog.editor.info(text); + AppFlowyEditorLog.editor.warn(text); + AppFlowyEditorLog.editor.error(text); expect(logs.length, 1); }); @@ -86,16 +86,16 @@ void main() async { const text = 'Welcome to Appflowy 😁'; final List logs = []; - LogConfiguration() - ..level = LogLevel.warn + AppFlowyLogConfiguration() + ..level = AppFlowyEditorLogLevel.warn ..handler = (message) { logs.add(message); }; - Log.editor.debug(text); - Log.editor.info(text); - Log.editor.warn(text); - Log.editor.error(text); + AppFlowyEditorLog.editor.debug(text); + AppFlowyEditorLog.editor.info(text); + AppFlowyEditorLog.editor.warn(text); + AppFlowyEditorLog.editor.error(text); expect(logs.length, 2); }); @@ -104,16 +104,16 @@ void main() async { const text = 'Welcome to Appflowy 😁'; final List logs = []; - LogConfiguration() - ..level = LogLevel.info + AppFlowyLogConfiguration() + ..level = AppFlowyEditorLogLevel.info ..handler = (message) { logs.add(message); }; - Log.editor.debug(text); - Log.editor.info(text); - Log.editor.warn(text); - Log.editor.error(text); + AppFlowyEditorLog.editor.debug(text); + AppFlowyEditorLog.editor.info(text); + AppFlowyEditorLog.editor.warn(text); + AppFlowyEditorLog.editor.error(text); expect(logs.length, 3); }); @@ -122,16 +122,16 @@ void main() async { const text = 'Welcome to Appflowy 😁'; final List logs = []; - LogConfiguration() - ..level = LogLevel.debug + AppFlowyLogConfiguration() + ..level = AppFlowyEditorLogLevel.debug ..handler = (message) { logs.add(message); }; - Log.editor.debug(text); - Log.editor.info(text); - Log.editor.warn(text); - Log.editor.error(text); + AppFlowyEditorLog.editor.debug(text); + AppFlowyEditorLog.editor.info(text); + AppFlowyEditorLog.editor.warn(text); + AppFlowyEditorLog.editor.error(text); expect(logs.length, 4); }); @@ -140,28 +140,28 @@ void main() async { const text = 'Welcome to Appflowy 😁'; final List logs = []; - LogConfiguration() - ..level = LogLevel.all + AppFlowyLogConfiguration() + ..level = AppFlowyEditorLogLevel.all ..handler = (message) { logs.add(message); }; - Log.editor.debug(text); + AppFlowyEditorLog.editor.debug(text); expect(logs.last.contains('editor'), true); - Log.selection.debug(text); + AppFlowyEditorLog.selection.debug(text); expect(logs.last.contains('selection'), true); - Log.keyboard.debug(text); + AppFlowyEditorLog.keyboard.debug(text); expect(logs.last.contains('keyboard'), true); - Log.input.debug(text); + AppFlowyEditorLog.input.debug(text); expect(logs.last.contains('input'), true); - Log.scroll.debug(text); + AppFlowyEditorLog.scroll.debug(text); expect(logs.last.contains('scroll'), true); - Log.ui.debug(text); + AppFlowyEditorLog.ui.debug(text); expect(logs.last.contains('ui'), true); expect(logs.length, 6); diff --git a/test/mobile/toolbar/mobile/toolbar_items/link_mobile_toolbar_item_test.dart b/test/mobile/toolbar/mobile/toolbar_items/link_mobile_toolbar_item_test.dart index ee3e3b1f7..298631807 100644 --- a/test/mobile/toolbar/mobile/toolbar_items/link_mobile_toolbar_item_test.dart +++ b/test/mobile/toolbar/mobile/toolbar_items/link_mobile_toolbar_item_test.dart @@ -1,6 +1,8 @@ +import 'package:appflowy_editor/appflowy_editor.dart'; +import 'package:appflowy_editor/src/editor/util/platform_extension.dart'; import 'package:flutter/material.dart'; import 'package:flutter_test/flutter_test.dart'; -import 'package:appflowy_editor/appflowy_editor.dart'; + import '../../../../new/infra/testable_editor.dart'; import '../test_helpers/mobile_app_with_toolbar_widget.dart'; diff --git a/test/new/editor_component/service/shortcuts/character_shortcuts/undo_markdown_test.dart b/test/new/editor_component/service/shortcuts/character_shortcuts/undo_markdown_test.dart index b0cebaeff..3fa48ed97 100644 --- a/test/new/editor_component/service/shortcuts/character_shortcuts/undo_markdown_test.dart +++ b/test/new/editor_component/service/shortcuts/character_shortcuts/undo_markdown_test.dart @@ -1,9 +1,8 @@ +import 'package:appflowy_editor/appflowy_editor.dart'; +import 'package:appflowy_editor/src/editor/util/platform_extension.dart'; import 'package:flutter/services.dart'; - import 'package:flutter_test/flutter_test.dart'; -import 'package:appflowy_editor/appflowy_editor.dart'; - import '../../../../infra/testable_editor.dart'; void main() async { diff --git a/test/new/util/log_util.dart b/test/new/util/log_util.dart index fc71d8bce..92ca796b6 100644 --- a/test/new/util/log_util.dart +++ b/test/new/util/log_util.dart @@ -7,16 +7,16 @@ void activateLog() { if (!_enableLog) { return; } - LogConfiguration() + AppFlowyLogConfiguration() ..handler = debugPrint - ..level = LogLevel.all; + ..level = AppFlowyEditorLogLevel.all; } void deactivateLog() { if (!_enableLog) { return; } - LogConfiguration() + AppFlowyLogConfiguration() ..handler = null - ..level = LogLevel.off; + ..level = AppFlowyEditorLogLevel.off; }