From 3d6fa7556bdc6fadd6eca4ba5a6428c0ea4f2c45 Mon Sep 17 00:00:00 2001 From: "Lucas.Xu" Date: Tue, 21 Jan 2025 11:12:56 +0800 Subject: [PATCH 1/3] Revert "feat: upgrade to Flutter 3.27.0 (#1020)" This reverts commit 70990e814cc3dd91a37ca99974e8b972de7fe4cc. --- .github/workflows/test.yml | 2 +- CHANGELOG.md | 59 ------------------- example/.gitignore | 2 - .../lib/pages/customize_theme_for_editor.dart | 2 +- example/lib/pages/editor.dart | 2 +- example/lib/pages/markdown_editor.dart | 2 +- example/macos/Runner/AppDelegate.swift | 6 +- lib/appflowy_editor.dart | 2 +- .../image_upload_widget.dart | 2 +- .../resizable_image.dart | 2 +- .../format_double_characters.dart | 3 + .../format_single_character.dart | 3 + .../shortcuts/command/open_links_command.dart | 5 +- ...ile_text_span_decorator_for_attribute.dart | 30 +++------- .../find_replace_menu/find_menu_service.dart | 2 +- .../find_replace_widget.dart | 32 ++++------ .../selection_menu/selection_menu_widget.dart | 2 +- .../desktop/items/utils/overlay_util.dart | 2 +- .../toolbar/utils/color_generators.dart | 16 ++--- lib/src/editor/util/color_util.dart | 7 +-- lib/src/extensions/color_extension.dart | 5 -- lib/src/flutter/scrollable_helpers.dart | 4 +- lib/src/plugins/html/html_document.dart | 2 +- .../decoder/document_markdown_decoder.dart | 2 +- .../plugins/markdown/document_markdown.dart | 2 +- lib/src/render/color_menu/color_picker.dart | 9 +-- lib/src/render/selection/cursor.dart | 2 +- .../render/selection/mobile_basic_handle.dart | 2 +- .../service/context_menu/context_menu.dart | 2 +- pubspec.yaml | 9 +-- ...d_background_color_tool_bar_item_test.dart | 2 +- 31 files changed, 65 insertions(+), 159 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index e1f7d1385..30714493d 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -33,7 +33,7 @@ jobs: - uses: subosito/flutter-action@v2 with: channel: "stable" - flutter-version: "3.27.0" + flutter-version: "3.22.0" cache: true - name: Run tests diff --git a/CHANGELOG.md b/CHANGELOG.md index 6087df210..abafdc9e5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,62 +1,3 @@ -## 5.0.0 - -- fix: export pdf set font not work by @Linij in https://github.com/AppFlowy-IO/appflowy-editor/pull/923 -- fix: \_deleteBackward deleteRange start must > 0 by @Linij in https://github.com/AppFlowy-IO/appflowy-editor/pull/928 -- chore: update device_info_plus to 11.0.0 by @LucasXu0 in https://github.com/AppFlowy-IO/appflowy-editor/pull/931 -- fix: html decoder ignores h4-h6 tags by @LucasXu0 in https://github.com/AppFlowy-IO/appflowy-editor/pull/932 -- fix: markdown parser doesn't recognize softline breaks by @LucasXu0 in https://github.com/AppFlowy-IO/appflowy-editor/pull/933 -- feat: select multiple lines with block selection style by @LucasXu0 in https://github.com/AppFlowy-IO/appflowy-editor/pull/936 -- feat: custom slice function by @LucasXu0 in https://github.com/AppFlowy-IO/appflowy-editor/pull/935 -- fix: use retain instead of insert/delete for same attr by @LucasXu0 in https://github.com/AppFlowy-IO/appflowy-editor/pull/937 -- fix: update migration guide by @emmanuel-ferdman in https://github.com/AppFlowy-IO/appflowy-editor/pull/929 -- fix: replace texts assertion by @LucasXu0 in https://github.com/AppFlowy-IO/appflowy-editor/pull/938 -- fix: links starting with 0 index lose href attribute after formating by @LucasXu0 in https://github.com/AppFlowy-IO/appflowy-editor/pull/947 -- fix: replace texts may result in incorrect afterSelection by @LucasXu0 in https://github.com/AppFlowy-IO/appflowy-editor/pull/952 -- fix: cancel block selection when tapping the editor on mobile by @LucasXu0 in https://github.com/AppFlowy-IO/appflowy-editor/pull/956 -- fix: highlight search match not scrolling document to reveal said match by @richardshiue in https://github.com/AppFlowy-IO/appflowy-editor/pull/954 -- fix: cursor height is inconsistent when the font size is smaller than the default text size by @LucasXu0 in https://github.com/AppFlowy-IO/appflowy-editor/pull/958 -- feat: exclude padding when highlight heading block by @LucasXu0 in https://github.com/AppFlowy-IO/appflowy-editor/pull/960 -- fix: move cursor up / down error by @LucasXu0 in https://github.com/AppFlowy-IO/appflowy-editor/pull/961 -- fix: table resizing when rect not rendered by @Xazin in https://github.com/AppFlowy-IO/appflowy-editor/pull/967 -- fix: Searching command with / using in18 by @Ahad-patel in https://github.com/AppFlowy-IO/appflowy-editor/pull/966 -- fix: cut collapsed table cell won't crash the editor by @saif-ellafi in https://github.com/AppFlowy-IO/appflowy-editor/pull/963 -- fix: deleting the last table being the last node of the document, places an empty node to avoid the editor to crash by @saif-ellafi in https://github.com/AppFlowy-IO/appflowy-editor/pull/951 -- fix: cross blocks format not reflected on the float toolbar by @LucasXu0 in https://github.com/AppFlowy-IO/appflowy-editor/pull/971 -- feat: support in memory transaction update by @LucasXu0 in https://github.com/AppFlowy-IO/appflowy-editor/pull/972 -- fix: editor now detects phone number and launches it by @ARYPROGRAMMER in https://github.com/AppFlowy-IO/appflowy-editor/pull/970 -- fix: ignore backspace on empty table cells to avoid editor crash by @saif-ellafi in https://github.com/AppFlowy-IO/appflowy-editor/pull/964 -- fix: hide the floating toolbar if no content is visible by @LucasXu0 in https://github.com/AppFlowy-IO/appflowy-editor/pull/976 -- fix: skip repeated key events when the slash menu is opening by @LucasXu0 in https://github.com/AppFlowy-IO/appflowy-editor/pull/978 -- fix: creating document from slash menu leaves text behind by @LucasXu0 in https://github.com/AppFlowy-IO/appflowy-editor/pull/980 -- fix: closing a ')' braket to create a link will erase a text following it to the end of a paragraph by @LucasXu0 in https://github.com/AppFlowy-IO/appflowy-editor/pull/983 -- fix: underscore works should not be interpreted in inline-code by @LucasXu0 in https://github.com/AppFlowy-IO/appflowy-editor/pull/984 -- feat: support customize supported node types for slash menu by @LucasXu0 in https://github.com/AppFlowy-IO/appflowy-editor/pull/982 -- chore: refactor html test by @LucasXu0 in https://github.com/AppFlowy-IO/appflowy-editor/pull/987 -- fix: issue #6808 of appflowy by @asjqkkkk in https://github.com/AppFlowy-IO/appflowy-editor/pull/986 -- fix: cross column deletion in the table by @Linij in https://github.com/AppFlowy-IO/appflowy-editor/pull/934 -- feat: add command shortcut keys to convert text to title by @Ahad-patel in https://github.com/AppFlowy-IO/appflowy-editor/pull/921 -- Fixed menu closing on some devices by @g-apparence in https://github.com/AppFlowy-IO/appflowy-editor/pull/941 -- feat: reset to the default inline code format logic by @LucasXu0 in https://github.com/AppFlowy-IO/appflowy-editor/pull/988 -- feat: add `partialSliced` to support partial sliced attributes by @LucasXu0 in https://github.com/AppFlowy-IO/appflowy-editor/pull/989 -- fix: shift+enter should wrap the line in list by @LucasXu0 in https://github.com/AppFlowy-IO/appflowy-editor/pull/990 -- fix: assertion error in auto_expand_editor example by @mikefaust-jm in https://github.com/AppFlowy-IO/appflowy-editor/pull/991 -- fix: all the text pasted from google doc will be applied inline link by @asjqkkkk in https://github.com/AppFlowy-IO/appflowy-editor/pull/993 -- fix: sougou IME issue on Windows by @asjqkkkk in https://github.com/AppFlowy-IO/appflowy-editor/pull/1000 -- feat: deep copy the node by @LucasXu0 in https://github.com/AppFlowy-IO/appflowy-editor/pull/995 -- fix: checking is mounted before updating the value of PropertyValueNotifier(#977) by @asjqkkkk in https://github.com/AppFlowy-IO/appflowy-editor/pull/997 -- feat: support text align in text-based blocks by @LucasXu0 in https://github.com/AppFlowy-IO/appflowy-editor/pull/1002 -- feat: enable debug paint size for mobile drag handle by @LucasXu0 in https://github.com/AppFlowy-IO/appflowy-editor/pull/1007 -- fix: out of text range while composing error by @kyungilcho in https://github.com/AppFlowy-IO/appflowy-editor/pull/979 -- fix: error format of TextEditingDeltaInsertion by @asjqkkkk in https://github.com/AppFlowy-IO/appflowy-editor/pull/1004 -- feat: clear selection extra info before inserting a new line by @LucasXu0 in https://github.com/AppFlowy-IO/appflowy-editor/pull/1009 -- fix: enter after emoji will create a softbreak on mobile by @LucasXu0 in https://github.com/AppFlowy-IO/appflowy-editor/pull/1010 -- feat: expose text span for text style builder by @LucasXu0 in https://github.com/AppFlowy-IO/appflowy-editor/pull/1011 -- fix: using space bar to move the cursor not working on Android by @asjqkkkk in https://github.com/AppFlowy-IO/appflowy-editor/pull/1013 -- fix: unable to parse image if the image is inside the paragraph by @LucasXu0 in https://github.com/AppFlowy-IO/appflowy-editor/pull/1012 -- fix: use jump to when cursor not rendered by @richardshiue in https://github.com/AppFlowy-IO/appflowy-editor/pull/1015 -- fix: check if scroll service is disposed before scrolling by @richardshiue in https://github.com/AppFlowy-IO/appflowy-editor/pull/1016 -- feat: support copy with indentPadding by @LucasXu0 in https://github.com/AppFlowy-IO/appflowy-editor/pull/1018 - ## 4.0.0 - feat: support dragging to reorder block by @LucasXu0 in [#887](https://github.com/AppFlowy-IO/appflowy-editor/pull/887) diff --git a/example/.gitignore b/example/.gitignore index 221b42254..a8e938c08 100644 --- a/example/.gitignore +++ b/example/.gitignore @@ -5,11 +5,9 @@ *.swp .DS_Store .atom/ -.build/ .buildlog/ .history .svn/ -.swiftpm/ migrate_working_dir/ # IntelliJ related diff --git a/example/lib/pages/customize_theme_for_editor.dart b/example/lib/pages/customize_theme_for_editor.dart index 6c22f2806..db21237de 100644 --- a/example/lib/pages/customize_theme_for_editor.dart +++ b/example/lib/pages/customize_theme_for_editor.dart @@ -158,7 +158,7 @@ class _CustomizeThemeForEditorState extends State { : const EdgeInsets.symmetric(horizontal: 20), cursorColor: Colors.green, dragHandleColor: Colors.green, - selectionColor: Colors.green.withValues(alpha: 0.5), + selectionColor: Colors.green.withOpacity(0.5), textStyleConfiguration: TextStyleConfiguration( text: GoogleFonts.poppins( fontSize: 14.0, diff --git a/example/lib/pages/editor.dart b/example/lib/pages/editor.dart index 33e0a466b..928c625bb 100644 --- a/example/lib/pages/editor.dart +++ b/example/lib/pages/editor.dart @@ -130,7 +130,7 @@ class _EditorState extends State { child: Container( padding: const EdgeInsets.symmetric(vertical: 2, horizontal: 12), decoration: BoxDecoration( - color: Colors.black.withValues(alpha: 0.1), + color: Colors.black.withOpacity(0.1), borderRadius: BorderRadius.only( topLeft: const Radius.circular(8), bottomLeft: UniversalPlatform.isMobile diff --git a/example/lib/pages/markdown_editor.dart b/example/lib/pages/markdown_editor.dart index e5370f767..e546654d5 100644 --- a/example/lib/pages/markdown_editor.dart +++ b/example/lib/pages/markdown_editor.dart @@ -18,7 +18,7 @@ class _MarkdownEditorState extends State { padding: const EdgeInsets.symmetric(horizontal: 16), cursorColor: Colors.transparent, cursorWidth: 0, - selectionColor: Colors.grey.withValues(alpha: 0.3), + selectionColor: Colors.grey.withOpacity(0.3), textStyleConfiguration: TextStyleConfiguration( lineHeight: 1.2, applyHeightToFirstAscent: true, diff --git a/example/macos/Runner/AppDelegate.swift b/example/macos/Runner/AppDelegate.swift index b3c176141..d53ef6437 100644 --- a/example/macos/Runner/AppDelegate.swift +++ b/example/macos/Runner/AppDelegate.swift @@ -1,13 +1,9 @@ import Cocoa import FlutterMacOS -@main +@NSApplicationMain class AppDelegate: FlutterAppDelegate { override func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { return true } - - override func applicationSupportsSecureRestorableState(_ app: NSApplication) -> Bool { - return true - } } diff --git a/lib/appflowy_editor.dart b/lib/appflowy_editor.dart index 88932f68a..c7efc8910 100644 --- a/lib/appflowy_editor.dart +++ b/lib/appflowy_editor.dart @@ -1,5 +1,5 @@ /// AppFlowyEditor library -library; +library appflowy_editor; // core part, including document, node, selection, etc. export 'src/core/core.dart'; diff --git a/lib/src/editor/block_component/image_block_component/image_upload_widget.dart b/lib/src/editor/block_component/image_block_component/image_upload_widget.dart index 3df97b1c7..f3415497d 100644 --- a/lib/src/editor/block_component/image_block_component/image_upload_widget.dart +++ b/lib/src/editor/block_component/image_block_component/image_upload_widget.dart @@ -117,7 +117,7 @@ class _UploadImageMenuState extends State { BoxShadow( blurRadius: 5, spreadRadius: 1, - color: Colors.black.withValues(alpha: 0.1), + color: Colors.black.withOpacity(0.1), ), ], // borderRadius: BorderRadius.circular(6.0), diff --git a/lib/src/editor/block_component/image_block_component/resizable_image.dart b/lib/src/editor/block_component/image_block_component/resizable_image.dart index 5d8e19dab..db6989cb8 100644 --- a/lib/src/editor/block_component/image_block_component/resizable_image.dart +++ b/lib/src/editor/block_component/image_block_component/resizable_image.dart @@ -210,7 +210,7 @@ class _ResizableImageState extends State { child: Container( height: 40, decoration: BoxDecoration( - color: Colors.black.withValues(alpha: 0.5), + color: Colors.black.withOpacity(0.5), borderRadius: const BorderRadius.all( Radius.circular(5.0), ), diff --git a/lib/src/editor/editor_component/service/shortcuts/character/format_double_character/format_double_characters.dart b/lib/src/editor/editor_component/service/shortcuts/character/format_double_character/format_double_characters.dart index 09ff371fd..20ac3633f 100644 --- a/lib/src/editor/editor_component/service/shortcuts/character/format_double_character/format_double_characters.dart +++ b/lib/src/editor/editor_component/service/shortcuts/character/format_double_character/format_double_characters.dart @@ -92,6 +92,9 @@ bool handleFormatByWrappingWithDoubleCharacter({ case DoubleCharacterFormatStyle.strikethrough: style = 'strikethrough'; break; + default: + style = ''; + assert(false, 'Invalid format style'); } // if the text is already formatted, we should remove the format. diff --git a/lib/src/editor/editor_component/service/shortcuts/character/format_single_character/format_single_character.dart b/lib/src/editor/editor_component/service/shortcuts/character/format_single_character/format_single_character.dart index 97fefc5e3..cdf484d35 100644 --- a/lib/src/editor/editor_component/service/shortcuts/character/format_single_character/format_single_character.dart +++ b/lib/src/editor/editor_component/service/shortcuts/character/format_single_character/format_single_character.dart @@ -185,6 +185,9 @@ bool handleFormatByWrappingWithSingleCharacter({ case FormatStyleByWrappingWithSingleChar.strikethrough: style = 'strikethrough'; break; + default: + style = ''; + assert(false, 'Invalid format style'); } // if the text is already formatted, we should remove the format. diff --git a/lib/src/editor/editor_component/service/shortcuts/command/open_links_command.dart b/lib/src/editor/editor_component/service/shortcuts/command/open_links_command.dart index c59800eb5..d032a5502 100644 --- a/lib/src/editor/editor_component/service/shortcuts/command/open_links_command.dart +++ b/lib/src/editor/editor_component/service/shortcuts/command/open_links_command.dart @@ -1,4 +1,5 @@ import 'package:appflowy_editor/appflowy_editor.dart'; +import 'package:collection/collection.dart'; import 'package:flutter/material.dart'; /// Option/Alt + Shift + Enter: to open links @@ -26,13 +27,13 @@ KeyEventResult _openLinksHandler( // A set to store the links which should be opened final links = nodes .map((node) => node.delta) - .nonNulls + .whereNotNull() .expand( (node) => node.map( (op) => op.attributes?[AppFlowyRichTextKeys.href], ), ) - .nonNulls + .whereNotNull() .toSet(); for (final link in links) { diff --git a/lib/src/editor/editor_component/style/mobile_text_span_decorator_for_attribute.dart b/lib/src/editor/editor_component/style/mobile_text_span_decorator_for_attribute.dart index 1321f2c13..804f1d4dc 100644 --- a/lib/src/editor/editor_component/style/mobile_text_span_decorator_for_attribute.dart +++ b/lib/src/editor/editor_component/style/mobile_text_span_decorator_for_attribute.dart @@ -175,11 +175,9 @@ class _LinkEditFormState extends State { widget.hrefText.length, {BuiltInAttributeKey.href: null}, ); - await widget.editorState.apply(transaction).whenComplete(() { - if (context.mounted) { - Navigator.of(context).pop(); - } - }); + await widget.editorState + .apply(transaction) + .whenComplete(() => Navigator.of(context).pop()); }, ), TextButton( @@ -208,12 +206,8 @@ class _LinkEditFormState extends State { }, ); await widget.editorState.apply(transaction).whenComplete( - () { - if (context.mounted) { - Navigator.of(context).pop(); - } - }, - ); + () => Navigator.of(context).pop(), + ); } else if (textChanged && !addressChanged) { final transaction = widget.editorState.transaction ..replaceText( @@ -223,21 +217,13 @@ class _LinkEditFormState extends State { hrefTextTextEditingController.text, ); await widget.editorState.apply(transaction).whenComplete( - () { - if (context.mounted) { - Navigator.of(context).pop(); - } - }, - ); + () => Navigator.of(context).pop(), + ); } else if (!textChanged && addressChanged) { await widget.editorState.formatDelta(widget.selection, { AppFlowyRichTextKeys.href: hrefAddressTextEditingController.value.text, - }).whenComplete(() { - if (context.mounted) { - Navigator.of(context).pop(); - } - }); + }).whenComplete(() => Navigator.of(context).pop()); } else { Navigator.of(context).pop(); } diff --git a/lib/src/editor/find_replace_menu/find_menu_service.dart b/lib/src/editor/find_replace_menu/find_menu_service.dart index 25ad3449a..ffed696d5 100644 --- a/lib/src/editor/find_replace_menu/find_menu_service.dart +++ b/lib/src/editor/find_replace_menu/find_menu_service.dart @@ -89,7 +89,7 @@ class FindReplaceMenu implements FindReplaceService { BoxShadow( blurRadius: 5, spreadRadius: 1, - color: Colors.black.withValues(alpha: 0.1), + color: Colors.black.withOpacity(0.1), ), ], borderRadius: BorderRadius.circular(6.0), diff --git a/lib/src/editor/find_replace_menu/find_replace_widget.dart b/lib/src/editor/find_replace_menu/find_replace_widget.dart index 4740af173..f6760fb61 100644 --- a/lib/src/editor/find_replace_menu/find_replace_widget.dart +++ b/lib/src/editor/find_replace_menu/find_replace_widget.dart @@ -230,11 +230,9 @@ class _FindMenuState extends State { // will request focus, here's a workaround to request the // focus back to the findTextField Future.delayed(const Duration(milliseconds: 50), () { - if (context.mounted) { - FocusScope.of(context).requestFocus( - findTextFieldFocusNode, - ); - } + FocusScope.of(context).requestFocus( + findTextFieldFocusNode, + ); }); }, decoration: _buildInputDecoration( @@ -257,11 +255,9 @@ class _FindMenuState extends State { onPressed: () { // work around to request focus back to the input field Future.delayed(const Duration(milliseconds: 10), () { - if (context.mounted) { - FocusScope.of(context).requestFocus( - findTextFieldFocusNode, - ); - } + FocusScope.of(context).requestFocus( + findTextFieldFocusNode, + ); }); widget.searchService.navigateToMatch(moveUp: true); }, @@ -274,11 +270,9 @@ class _FindMenuState extends State { iconButtonKey: const Key('nextMatchButton'), onPressed: () { Future.delayed(const Duration(milliseconds: 10), () { - if (context.mounted) { - FocusScope.of(context).requestFocus( - findTextFieldFocusNode, - ); - } + FocusScope.of(context).requestFocus( + findTextFieldFocusNode, + ); }); widget.searchService.navigateToMatch(); }, @@ -406,11 +400,9 @@ class _ReplaceMenuState extends State { _replaceSelectedWord(); Future.delayed(const Duration(milliseconds: 50), () { - if (context.mounted) { - FocusScope.of(context).requestFocus( - replaceTextFieldFocusNode, - ); - } + FocusScope.of(context).requestFocus( + replaceTextFieldFocusNode, + ); }); }, decoration: _buildInputDecoration( diff --git a/lib/src/editor/selection_menu/selection_menu_widget.dart b/lib/src/editor/selection_menu/selection_menu_widget.dart index 9816aeb32..16b7b3280 100644 --- a/lib/src/editor/selection_menu/selection_menu_widget.dart +++ b/lib/src/editor/selection_menu/selection_menu_widget.dart @@ -343,7 +343,7 @@ class _SelectionMenuWidgetState extends State { BoxShadow( blurRadius: 5, spreadRadius: 1, - color: Colors.black.withValues(alpha: 0.1), + color: Colors.black.withOpacity(0.1), ), ], borderRadius: BorderRadius.circular(6.0), diff --git a/lib/src/editor/toolbar/desktop/items/utils/overlay_util.dart b/lib/src/editor/toolbar/desktop/items/utils/overlay_util.dart index 4890bc8d2..5e8822167 100644 --- a/lib/src/editor/toolbar/desktop/items/utils/overlay_util.dart +++ b/lib/src/editor/toolbar/desktop/items/utils/overlay_util.dart @@ -20,7 +20,7 @@ BoxDecoration buildOverlayDecoration(BuildContext context) { borderRadius: BorderRadius.circular(6), boxShadow: [ BoxShadow( - color: Colors.black.withValues(alpha: 0.2), + color: Colors.black.withOpacity(0.2), blurRadius: 10, offset: const Offset(0, 2), ), diff --git a/lib/src/editor/toolbar/utils/color_generators.dart b/lib/src/editor/toolbar/utils/color_generators.dart index 618ad8ae2..338fbbb97 100644 --- a/lib/src/editor/toolbar/utils/color_generators.dart +++ b/lib/src/editor/toolbar/utils/color_generators.dart @@ -53,35 +53,35 @@ List generateTextColorOptions() { List generateHighlightColorOptions() { return [ ColorOption( - colorHex: Colors.grey.withValues(alpha: 0.3).toHex(), + colorHex: Colors.grey.withOpacity(0.3).toHex(), name: AppFlowyEditorL10n.current.backgroundColorGray, ), ColorOption( - colorHex: Colors.brown.withValues(alpha: 0.3).toHex(), + colorHex: Colors.brown.withOpacity(0.3).toHex(), name: AppFlowyEditorL10n.current.backgroundColorBrown, ), ColorOption( - colorHex: Colors.yellow.withValues(alpha: 0.3).toHex(), + colorHex: Colors.yellow.withOpacity(0.3).toHex(), name: AppFlowyEditorL10n.current.backgroundColorYellow, ), ColorOption( - colorHex: Colors.green.withValues(alpha: 0.3).toHex(), + colorHex: Colors.green.withOpacity(0.3).toHex(), name: AppFlowyEditorL10n.current.backgroundColorGreen, ), ColorOption( - colorHex: Colors.blue.withValues(alpha: 0.3).toHex(), + colorHex: Colors.blue.withOpacity(0.3).toHex(), name: AppFlowyEditorL10n.current.backgroundColorBlue, ), ColorOption( - colorHex: Colors.purple.withValues(alpha: 0.3).toHex(), + colorHex: Colors.purple.withOpacity(0.3).toHex(), name: AppFlowyEditorL10n.current.backgroundColorPurple, ), ColorOption( - colorHex: Colors.pink.withValues(alpha: 0.3).toHex(), + colorHex: Colors.pink.withOpacity(0.3).toHex(), name: AppFlowyEditorL10n.current.backgroundColorPink, ), ColorOption( - colorHex: Colors.red.withValues(alpha: 0.3).toHex(), + colorHex: Colors.red.withOpacity(0.3).toHex(), name: AppFlowyEditorL10n.current.backgroundColorRed, ), ]; diff --git a/lib/src/editor/util/color_util.dart b/lib/src/editor/util/color_util.dart index 2847e6448..81bd65c96 100644 --- a/lib/src/editor/util/color_util.dart +++ b/lib/src/editor/util/color_util.dart @@ -49,11 +49,6 @@ extension ColorExtension on String { extension HexExtension on Color { String toHex() { - final alpha = (a * 255).toInt().toRadixString(16).padLeft(2, '0'); - final red = (r * 255).toInt().toRadixString(16).padLeft(2, '0'); - final green = (g * 255).toInt().toRadixString(16).padLeft(2, '0'); - final blue = (b * 255).toInt().toRadixString(16).padLeft(2, '0'); - - return '0x$alpha$red$green$blue'.toLowerCase(); + return '0x${value.toRadixString(16)}'; } } diff --git a/lib/src/extensions/color_extension.dart b/lib/src/extensions/color_extension.dart index 41ebf0838..b7b0578c0 100644 --- a/lib/src/extensions/color_extension.dart +++ b/lib/src/extensions/color_extension.dart @@ -31,11 +31,6 @@ extension ColorExtension2 on Color { } String toRgbaString() { - final alpha = (a * 255).toInt(); - final red = (r * 255).toInt(); - final green = (g * 255).toInt(); - final blue = (b * 255).toInt(); - return 'rgba($red, $green, $blue, $alpha)'; } } diff --git a/lib/src/flutter/scrollable_helpers.dart b/lib/src/flutter/scrollable_helpers.dart index 9695a0302..e6714fc70 100644 --- a/lib/src/flutter/scrollable_helpers.dart +++ b/lib/src/flutter/scrollable_helpers.dart @@ -141,7 +141,7 @@ class ScrollableDetails { /// /// The scroll velocity is controlled by the [velocityScalar]: /// -/// velocity = <distance of overscroll> * [velocityScalar]. +/// velocity = * [velocityScalar]. class EdgeDraggingAutoScroller { /// Creates a auto scroller that scrolls the [scrollable]. EdgeDraggingAutoScroller( @@ -166,7 +166,7 @@ class EdgeDraggingAutoScroller { /// The velocity scalar per pixel over scroll. /// /// It represents how the velocity scale with the over scroll distance. The - /// auto-scroll velocity = <distance of overscroll> * velocityScalar. + /// auto-scroll velocity = * velocityScalar. final double velocityScalar; late Rect _dragTargetRelatedToScrollOrigin; diff --git a/lib/src/plugins/html/html_document.dart b/lib/src/plugins/html/html_document.dart index 35ee5b32f..6c7c7995e 100644 --- a/lib/src/plugins/html/html_document.dart +++ b/lib/src/plugins/html/html_document.dart @@ -1,4 +1,4 @@ -library; +library delta_markdown; import 'dart:convert'; diff --git a/lib/src/plugins/markdown/decoder/document_markdown_decoder.dart b/lib/src/plugins/markdown/decoder/document_markdown_decoder.dart index eb7291332..7bfc05d37 100644 --- a/lib/src/plugins/markdown/decoder/document_markdown_decoder.dart +++ b/lib/src/plugins/markdown/decoder/document_markdown_decoder.dart @@ -29,7 +29,7 @@ class DocumentMarkdownDecoder extends Converter { final document = Document.blank(); final nodes = mdNodes .map((e) => _parseNode(e)) - .nonNulls + .whereNotNull() .flattened .toList(growable: false); // avoid lazy evaluation if (nodes.isNotEmpty) { diff --git a/lib/src/plugins/markdown/document_markdown.dart b/lib/src/plugins/markdown/document_markdown.dart index ab6d054b6..f06e01efc 100644 --- a/lib/src/plugins/markdown/document_markdown.dart +++ b/lib/src/plugins/markdown/document_markdown.dart @@ -1,4 +1,4 @@ -library; +library delta_markdown; import 'dart:convert'; diff --git a/lib/src/render/color_menu/color_picker.dart b/lib/src/render/color_menu/color_picker.dart index 268e94cd3..8fbed681b 100644 --- a/lib/src/render/color_menu/color_picker.dart +++ b/lib/src/render/color_menu/color_picker.dart @@ -71,7 +71,7 @@ class _ColorPickerState extends State { BoxShadow( blurRadius: 5, spreadRadius: 1, - color: Colors.black.withValues(alpha: 0.1), + color: Colors.black.withOpacity(0.1), ), ], borderRadius: BorderRadius.circular(6.0), @@ -294,11 +294,6 @@ class _ColorPickerState extends State { extension ConvertToHex on Color { String toHex() { - final alpha = (a * 255).toInt().toRadixString(16).padLeft(2, '0'); - final red = (r * 255).toInt().toRadixString(16).padLeft(2, '0'); - final green = (g * 255).toInt().toRadixString(16).padLeft(2, '0'); - final blue = (b * 255).toInt().toRadixString(16).padLeft(2, '0'); - - return '0x$alpha$red$green$blue'.toUpperCase(); + return '0x${value.toRadixString(16)}'; } } diff --git a/lib/src/render/selection/cursor.dart b/lib/src/render/selection/cursor.dart index e4c6c4dc4..b7b0573ff 100644 --- a/lib/src/render/selection/cursor.dart +++ b/lib/src/render/selection/cursor.dart @@ -87,7 +87,7 @@ class CursorState extends State { return Container( width: size.width, height: size.height, - color: color.withValues(alpha: 0.2), + color: color.withOpacity(0.2), ); } } diff --git a/lib/src/render/selection/mobile_basic_handle.dart b/lib/src/render/selection/mobile_basic_handle.dart index f4cd724a6..b19d67189 100644 --- a/lib/src/render/selection/mobile_basic_handle.dart +++ b/lib/src/render/selection/mobile_basic_handle.dart @@ -121,7 +121,7 @@ class DragHandle extends _IDragHandle { if (debugPaintSizeEnabled) { child = ColoredBox( - color: Colors.red.withValues(alpha: 0.5), + color: Colors.red.withOpacity(0.5), child: child, ); } diff --git a/lib/src/service/context_menu/context_menu.dart b/lib/src/service/context_menu/context_menu.dart index 5c31058a4..9af2070ab 100644 --- a/lib/src/service/context_menu/context_menu.dart +++ b/lib/src/service/context_menu/context_menu.dart @@ -87,7 +87,7 @@ class ContextMenu extends StatelessWidget { BoxShadow( blurRadius: 5, spreadRadius: 1, - color: Colors.black.withValues(alpha: 0.1), + color: Colors.black.withOpacity(0.1), ), ], borderRadius: BorderRadius.circular(6.0), diff --git a/pubspec.yaml b/pubspec.yaml index 967510858..ab67f966c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,12 +1,12 @@ name: "appflowy_editor" -version: 5.0.0 +version: 4.0.0 homepage: "https://github.com/AppFlowy-IO/appflowy-editor" environment: sdk: ">=3.4.0 <4.0.0" - flutter: ">=3.27.0" + flutter: ">=3.22.0" description: A highly customizable rich-text editor for Flutter. The AppFlowy Editor project for AppFlowy and beyond. @@ -19,7 +19,7 @@ dependencies: flutter: sdk: flutter flutter_svg: "^2.0.6" - html: ^0.15.5 + html: "^0.15.0" http: "^1.2.0" intl: "^0.19.0" keyboard_height_plugin: "^0.1.5" @@ -36,7 +36,7 @@ dependencies: url_launcher: "^6.1.11" dev_dependencies: - flutter_lints: ^5.0.0 + flutter_lints: "^4.0.0" flutter_localizations: sdk: flutter flutter_test: @@ -56,6 +56,7 @@ platforms: web: topics: + - ui - widgets - editor - appflowy diff --git a/test/mobile/toolbar/mobile/toolbar_items/color/text_and_background_color_tool_bar_item_test.dart b/test/mobile/toolbar/mobile/toolbar_items/color/text_and_background_color_tool_bar_item_test.dart index e852b7af2..ff1a9518d 100644 --- a/test/mobile/toolbar/mobile/toolbar_items/color/text_and_background_color_tool_bar_item_test.dart +++ b/test/mobile/toolbar/mobile/toolbar_items/color/text_and_background_color_tool_bar_item_test.dart @@ -94,7 +94,7 @@ void main() { return delta.whereType().every( (element) => element.attributes?[AppFlowyRichTextKeys.backgroundColor] == - Colors.red.withValues(alpha: 0.3).toHex(), + Colors.red.withOpacity(0.3).toHex(), ); }), true, From e4648ccbc2c1b9ffc5ceb3168b84a9ebdaa692de Mon Sep 17 00:00:00 2001 From: "Lucas.Xu" Date: Tue, 21 Jan 2025 11:19:01 +0800 Subject: [PATCH 2/3] feat: support copying divider from html --- lib/src/plugins/html/html_document_decoder.dart | 3 +++ test/plugins/html/html_document_test.dart | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/lib/src/plugins/html/html_document_decoder.dart b/lib/src/plugins/html/html_document_decoder.dart index 99a96537b..1b32ccae1 100644 --- a/lib/src/plugins/html/html_document_decoder.dart +++ b/lib/src/plugins/html/html_document_decoder.dart @@ -121,6 +121,8 @@ class DocumentHTMLDecoder extends Converter { return [_parseBlockQuoteElement(element)]; case HTMLTags.image: return [_parseImageElement(element)]; + case HTMLTags.divider: + return [dividerNode()]; default: return _parseParagraphElement(element); } @@ -568,6 +570,7 @@ class HTMLTags { HTMLTags.checkbox, HTMLTags.image, HTMLTags.section, + HTMLTags.divider, ]; static bool isTopLevel(String tag) { diff --git a/test/plugins/html/html_document_test.dart b/test/plugins/html/html_document_test.dart index 938825b11..148756bab 100644 --- a/test/plugins/html/html_document_test.dart +++ b/test/plugins/html/html_document_test.dart @@ -368,4 +368,14 @@ void main() { ], ); }); + + test('sample 13', () { + const html = + '''

Sales Performance Report - Q4 2024

This report provides an overview of the sales performance for the fourth quarter of 2024, including revenue, product performance, and regional sales comparison.


'''; + final document = htmlToDocument(html); + expect(document.root.children.length, 3); + expect(document.nodeAtPath([0])!.type, HeadingBlockKeys.type); + expect(document.nodeAtPath([1])!.type, ParagraphBlockKeys.type); + expect(document.nodeAtPath([2])!.type, DividerBlockKeys.type); + }); } From db117694baad5febd612f3a2895f8332171c313e Mon Sep 17 00:00:00 2001 From: "Lucas.Xu" Date: Tue, 21 Jan 2025 12:01:49 +0800 Subject: [PATCH 3/3] test: copy content from ChatGPT --- test/plugins/html/html_document_test.dart | 54 ++++++++++++++++++++++- 1 file changed, 53 insertions(+), 1 deletion(-) diff --git a/test/plugins/html/html_document_test.dart b/test/plugins/html/html_document_test.dart index 148756bab..3eb700ab6 100644 --- a/test/plugins/html/html_document_test.dart +++ b/test/plugins/html/html_document_test.dart @@ -369,7 +369,7 @@ void main() { ); }); - test('sample 13', () { + test('sample 13 - copy divider and headings from ChatGPT', () { const html = '''

Sales Performance Report - Q4 2024

This report provides an overview of the sales performance for the fourth quarter of 2024, including revenue, product performance, and regional sales comparison.


'''; final document = htmlToDocument(html); @@ -378,4 +378,56 @@ void main() { expect(document.nodeAtPath([1])!.type, ParagraphBlockKeys.type); expect(document.nodeAtPath([2])!.type, DividerBlockKeys.type); }); + + test('sample 14 - copy table from ChatGPT', () { + const html = ''' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
RegionTotal Sales (in \$)Sales Growth (%)Best Performing Product
North America5,200,0008.5Product A
Europe3,800,0006.2Product B
Asia-Pacific2,500,00010.1Product C
Latin America1,200,0004.0Product A
Middle East950,00012.5Product D
+'''; + final document = htmlToDocument(html); + final table = document.nodeAtPath([0])!; + expect(table.type, TableBlockKeys.type); + + print(table.toJson()); + }); }