diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index c5314cc0..b8ad209b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -25,6 +25,9 @@ jobs: - name: Install flutter_quill_extensions dependencies run: flutter pub get -C flutter_quill_extensions + - name: Install flutter_quill_test dependencies + run: flutter pub get -C flutter_quill_test + - name: Run flutter analysis run: flutter analyze diff --git a/CHANGELOG.md b/CHANGELOG.md index 58ae1a15..91598874 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +## [8.2.2] +- Move the `flutter_quill_test` to seperated package [flutter_quill_test](https://pub.dev/packages/fresh_quill_extensions) + ## [8.2.1] - Update `README.md` diff --git a/README.md b/README.md index 7a9ae38a..63e43be0 100644 --- a/README.md +++ b/README.md @@ -623,19 +623,7 @@ Typescript/Javascript package. ## Testing -To aid in testing applications using the editor an extension to the flutter `WidgetTester` is provided which includes methods to simplify interacting with the editor in test cases. - -Import the test utilities in your test file: - -```dart -import 'package:flutter_quill/flutter_quill_test.dart'; -``` - -and then enter text using `quillEnterText`: - -```dart -await tester.quillEnterText(find.byType(QuillEditor), 'test\n'); -``` +Please use [flutter_quill_test](https://pub.dev/packages/flutter_quill_test) for testing ## License diff --git a/flutter_quill_extensions/LICENSE b/flutter_quill_extensions/LICENSE index 498b3e0a..aaec6d89 100644 --- a/flutter_quill_extensions/LICENSE +++ b/flutter_quill_extensions/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2020 Xin Yao +Copyright (c) 2023 Xin Yao Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/flutter_quill_extensions/pubspec.yaml b/flutter_quill_extensions/pubspec.yaml index 8edb68c9..18c81d21 100644 --- a/flutter_quill_extensions/pubspec.yaml +++ b/flutter_quill_extensions/pubspec.yaml @@ -1,8 +1,8 @@ name: flutter_quill_extensions description: Embed extensions for flutter_quill including image, video, formula and etc. version: 0.6.0-dev.4 -homepage: https://github.com/singerdmx/flutter-quill -repository: https://github.com/singerdmx/flutter-quill +homepage: https://github.com/singerdmx/flutter-quill/tree/master/flutter_quill_extensions +repository: https://github.com/singerdmx/flutter-quill/tree/master/flutter_quill_extensions topics: - ui diff --git a/flutter_quill_test/.gitignore b/flutter_quill_test/.gitignore new file mode 100644 index 00000000..96486fd9 --- /dev/null +++ b/flutter_quill_test/.gitignore @@ -0,0 +1,30 @@ +# Miscellaneous +*.class +*.log +*.pyc +*.swp +.DS_Store +.atom/ +.buildlog/ +.history +.svn/ +migrate_working_dir/ + +# IntelliJ related +*.iml +*.ipr +*.iws +.idea/ + +# The .vscode folder contains launch configuration and tasks you configure in +# VS Code which you may wish to be included in version control, so this line +# is commented out by default. +#.vscode/ + +# Flutter/Dart/Pub related +# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. +/pubspec.lock +**/doc/api/ +.dart_tool/ +.packages +build/ diff --git a/flutter_quill_test/.metadata b/flutter_quill_test/.metadata new file mode 100644 index 00000000..6176c000 --- /dev/null +++ b/flutter_quill_test/.metadata @@ -0,0 +1,10 @@ +# This file tracks properties of this Flutter project. +# Used by Flutter tool to assess capabilities and perform upgrades etc. +# +# This file should be version controlled and should not be manually edited. + +version: + revision: "d211f42860350d914a5ad8102f9ec32764dc6d06" + channel: "stable" + +project_type: package diff --git a/flutter_quill_test/CHANGELOG.md b/flutter_quill_test/CHANGELOG.md new file mode 100644 index 00000000..77b39e53 --- /dev/null +++ b/flutter_quill_test/CHANGELOG.md @@ -0,0 +1,3 @@ +## 0.0.1 + +* initial release. diff --git a/flutter_quill_test/LICENSE b/flutter_quill_test/LICENSE new file mode 100644 index 00000000..19efa532 --- /dev/null +++ b/flutter_quill_test/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) Flutter Quill Team + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/flutter_quill_test/README.md b/flutter_quill_test/README.md new file mode 100644 index 00000000..c32a78fe --- /dev/null +++ b/flutter_quill_test/README.md @@ -0,0 +1,26 @@ +# Flutter Quill Test + +## Testing +To aid in testing applications using the editor an extension to the flutter `WidgetTester` is provided which includes methods to simplify interacting with the editor in test cases. + +Import the test utilities in your test file: + +```dart +import 'package:flutter_quill/flutter_quill_test.dart'; +``` + +and then enter text using `quillEnterText`: + +```dart +await tester.quillEnterText(find.byType(QuillEditor), 'test\n'); +``` + +## Contributing + +We welcome contributions! + +Please follow these guidelines when contributing to our project. See [CONTRIBUTING.md](./../CONTRIBUTING.md) for more details. + +## License + +This project is licensed under the [MIT License](LICENSE) - see the [LICENSE](LICENSE) file for details. \ No newline at end of file diff --git a/flutter_quill_test/analysis_options.yaml b/flutter_quill_test/analysis_options.yaml new file mode 100644 index 00000000..a5744c1c --- /dev/null +++ b/flutter_quill_test/analysis_options.yaml @@ -0,0 +1,4 @@ +include: package:flutter_lints/flutter.yaml + +# Additional information about this file can be found at +# https://dart.dev/guides/language/analysis-options diff --git a/lib/flutter_quill_test.dart b/flutter_quill_test/lib/flutter_quill_test.dart similarity index 100% rename from lib/flutter_quill_test.dart rename to flutter_quill_test/lib/flutter_quill_test.dart diff --git a/lib/src/test/widget_tester_extension.dart b/flutter_quill_test/lib/src/test/widget_tester_extension.dart similarity index 90% rename from lib/src/test/widget_tester_extension.dart rename to flutter_quill_test/lib/src/test/widget_tester_extension.dart index ab811fdc..a3ef9f53 100644 --- a/lib/src/test/widget_tester_extension.dart +++ b/flutter_quill_test/lib/src/test/widget_tester_extension.dart @@ -1,9 +1,7 @@ import 'package:flutter/material.dart'; +import 'package:flutter_quill/flutter_quill.dart'; import 'package:flutter_test/flutter_test.dart'; -import '../widgets/editor/editor.dart'; -import '../widgets/raw_editor/raw_editor.dart'; - /// Extends extension QuillEnterText on WidgetTester { /// Give the QuillEditor widget specified by [finder] the focus. @@ -44,10 +42,11 @@ extension QuillEnterText on WidgetTester { /// `find.byType(QuillEditor)`. Future quillUpdateEditingValue(Finder finder, String text) async { return TestAsyncUtils.guard(() async { - final editor = state( + final editor = state( find.descendant( of: finder, - matching: find.byType(RawEditor, skipOffstage: finder.skipOffstage), + matching: + find.byType(QuillRawEditor, skipOffstage: finder.skipOffstage), matchRoot: true), ); testTextInput.updateEditingValue(TextEditingValue( diff --git a/flutter_quill_test/pubspec.yaml b/flutter_quill_test/pubspec.yaml new file mode 100644 index 00000000..731789dc --- /dev/null +++ b/flutter_quill_test/pubspec.yaml @@ -0,0 +1,29 @@ +name: flutter_quill_test +description: Testing for flutter_quill +version: 0.0.1 +homepage: https://1o24bbs.com/c/bulletjournal/108 +repository: https://github.com/singerdmx/flutter-quill/tree/master/flutter_quill_test + +environment: + sdk: '>=3.1.5 <4.0.0' + flutter: ">=1.17.0" + +dependencies: + flutter: + sdk: flutter + flutter_quill: ^8.2.1 + flutter_test: + sdk: flutter + +dev_dependencies: + flutter_lints: ^2.0.0 + +# In case you are working on changes for both libraries +# Comment the dependency_overrides section when publishing the package, +# then uncomment it back, this will be automated later +dependency_overrides: + flutter_quill: + path: ../ + + +flutter: diff --git a/flutter_quill_test/test/flutter_quill_test_test.dart b/flutter_quill_test/test/flutter_quill_test_test.dart new file mode 100644 index 00000000..ab73b3a2 --- /dev/null +++ b/flutter_quill_test/test/flutter_quill_test_test.dart @@ -0,0 +1 @@ +void main() {} diff --git a/lib/flutter_quill.dart b/lib/flutter_quill.dart index 25f8c901..7f5f6459 100644 --- a/lib/flutter_quill.dart +++ b/lib/flutter_quill.dart @@ -27,6 +27,7 @@ export 'src/widgets/default_styles.dart'; export 'src/widgets/editor/editor.dart'; export 'src/widgets/embeds.dart'; export 'src/widgets/link.dart' show LinkActionPickerDelegate, LinkMenuAction; +export 'src/widgets/raw_editor/raw_editor.dart'; export 'src/widgets/style_widgets/style_widgets.dart'; export 'src/widgets/toolbar/base_toolbar.dart'; export 'src/widgets/toolbar/toolbar.dart'; diff --git a/lib/src/widgets/editor/editor.dart b/lib/src/widgets/editor/editor.dart index 258f32c1..b4e35811 100644 --- a/lib/src/widgets/editor/editor.dart +++ b/lib/src/widgets/editor/editor.dart @@ -15,12 +15,11 @@ import '../box.dart'; import '../cursor.dart'; import '../delegate.dart'; import '../float_cursor.dart'; -import '../raw_editor/raw_editor.dart'; import '../text_selection.dart'; /// Base interface for the editor state which defines contract used by /// various mixins. -abstract class EditorState extends State +abstract class EditorState extends State implements TextSelectionDelegate { ScrollController get scrollController; @@ -239,7 +238,7 @@ class QuillEditorState extends State final child = QuillEditorProvider( editorConfigurations: configurations, - child: RawEditor( + child: QuillRawEditor( key: _editorKey, controller: context.requireQuillController, focusNode: widget.focusNode, @@ -252,7 +251,7 @@ class QuillEditorState extends State onLaunchUrl: configurations.onLaunchUrl, contextMenuBuilder: showSelectionToolbar ? (configurations.contextMenuBuilder ?? - RawEditor.defaultContextMenuBuilder) + QuillRawEditor.defaultContextMenuBuilder) : null, showSelectionHandles: isMobile(theme.platform), showCursor: configurations.showCursor, diff --git a/lib/src/widgets/raw_editor/raw_editor.dart b/lib/src/widgets/raw_editor/raw_editor.dart index fa2944a1..8da91981 100644 --- a/lib/src/widgets/raw_editor/raw_editor.dart +++ b/lib/src/widgets/raw_editor/raw_editor.dart @@ -55,8 +55,8 @@ import '../toolbar/buttons/search/search_dialog.dart'; import 'raw_editor_state_selection_delegate_mixin.dart'; import 'raw_editor_state_text_input_client_mixin.dart'; -class RawEditor extends StatefulWidget { - const RawEditor({ +class QuillRawEditor extends StatefulWidget { + const QuillRawEditor({ required this.controller, required this.focusNode, required this.scrollController, @@ -139,7 +139,7 @@ class RawEditor extends StatefulWidget { static Widget defaultContextMenuBuilder( BuildContext context, - RawEditorState state, + QuillRawEditorState state, ) { return TextFieldTapRegion( child: AdaptiveTextSelectionToolbar.buttonItems( @@ -227,9 +227,10 @@ class RawEditor extends StatefulWidget { /// Delegate for building the text selection handles and toolbar. /// - /// The [RawEditor] widget used on its own will not trigger the display + /// The [QuillRawEditor] widget used on its own will not trigger the display /// of the selection toolbar by itself. The toolbar is shown by calling - /// [RawEditorState.showToolbar] in response to an appropriate user event. + /// [QuillRawEditorState.showToolbar] in response to + /// an appropriate user event. final TextSelectionControls selectionCtrls; /// The appearance of the keyboard. @@ -287,14 +288,14 @@ class RawEditor extends StatefulWidget { final ContentInsertionConfiguration? contentInsertionConfiguration; @override - State createState() => RawEditorState(); + State createState() => QuillRawEditorState(); } -class RawEditorState extends EditorState +class QuillRawEditorState extends EditorState with - AutomaticKeepAliveClientMixin, + AutomaticKeepAliveClientMixin, WidgetsBindingObserver, - TickerProviderStateMixin, + TickerProviderStateMixin, RawEditorStateTextInputClientMixin, RawEditorStateSelectionDelegateMixin { final GlobalKey _editorKey = GlobalKey(); @@ -354,7 +355,7 @@ class RawEditorState extends EditorState } /// Returns the [ContextMenuButtonItem]s representing the buttons in this - /// platform's default selection menu for [RawEditor]. + /// platform's default selection menu for [QuillRawEditor]. /// /// Copied from [EditableTextState]. List get contextMenuButtonItems { @@ -390,7 +391,7 @@ class RawEditorState extends EditorState } /// Gets the line heights at the start and end of the selection for the given - /// [RawEditorState]. + /// [QuillRawEditorState]. /// /// Copied from [EditableTextState]. _GlyphHeights _getGlyphHeights() { @@ -1171,7 +1172,7 @@ class RawEditorState extends EditorState } @override - void didUpdateWidget(RawEditor oldWidget) { + void didUpdateWidget(QuillRawEditor oldWidget) { super.didUpdateWidget(oldWidget); _cursorCont.show.value = widget.showCursor; @@ -2208,7 +2209,7 @@ class _DeleteTextAction extends ContextAction { _DeleteTextAction(this.state, this.getTextBoundariesForIntent); - final RawEditorState state; + final QuillRawEditorState state; final _TextBoundary Function(T intent) getTextBoundariesForIntent; TextRange _expandNonCollapsedRange(TextEditingValue value) { @@ -2280,7 +2281,7 @@ class _UpdateTextSelectionAction _UpdateTextSelectionAction(this.state, this.ignoreNonCollapsedSelection, this.getTextBoundariesForIntent); - final RawEditorState state; + final QuillRawEditorState state; final bool ignoreNonCollapsedSelection; final _TextBoundary Function(T intent) getTextBoundariesForIntent; @@ -2366,7 +2367,7 @@ class _ExtendSelectionOrCaretPositionAction extends ContextAction< _ExtendSelectionOrCaretPositionAction( this.state, this.getTextBoundariesForIntent); - final RawEditorState state; + final QuillRawEditorState state; final _TextBoundary Function( ExtendSelectionToNextWordBoundaryOrCaretLocationIntent intent) getTextBoundariesForIntent; @@ -2417,7 +2418,7 @@ class _UpdateTextSelectionToAdjacentLineAction< T extends DirectionalCaretMovementIntent> extends ContextAction { _UpdateTextSelectionToAdjacentLineAction(this.state); - final RawEditorState state; + final QuillRawEditorState state; QuillVerticalCaretMovementRun? _verticalMovementRun; TextSelection? _runSelection; @@ -2484,7 +2485,7 @@ class _UpdateTextSelectionToAdjacentLineAction< class _SelectAllAction extends ContextAction { _SelectAllAction(this.state); - final RawEditorState state; + final QuillRawEditorState state; @override Object? invoke(SelectAllTextIntent intent, [BuildContext? context]) { @@ -2506,7 +2507,7 @@ class _SelectAllAction extends ContextAction { class _CopySelectionAction extends ContextAction { _CopySelectionAction(this.state); - final RawEditorState state; + final QuillRawEditorState state; @override void invoke(CopySelectionTextIntent intent, [BuildContext? context]) { @@ -2532,7 +2533,7 @@ class _HideSelectionToolbarAction extends ContextAction { _HideSelectionToolbarAction(this.state); - final RawEditorState state; + final QuillRawEditorState state; @override void invoke(HideSelectionToolbarIntent intent, [BuildContext? context]) { @@ -2546,7 +2547,7 @@ class _HideSelectionToolbarAction class _UndoKeyboardAction extends ContextAction { _UndoKeyboardAction(this.state); - final RawEditorState state; + final QuillRawEditorState state; @override void invoke(UndoTextIntent intent, [BuildContext? context]) { @@ -2562,7 +2563,7 @@ class _UndoKeyboardAction extends ContextAction { class _RedoKeyboardAction extends ContextAction { _RedoKeyboardAction(this.state); - final RawEditorState state; + final QuillRawEditorState state; @override void invoke(RedoTextIntent intent, [BuildContext? context]) { @@ -2585,7 +2586,7 @@ class ToggleTextStyleIntent extends Intent { class _ToggleTextStyleAction extends Action { _ToggleTextStyleAction(this.state); - final RawEditorState state; + final QuillRawEditorState state; bool _isStyleActive(Attribute styleAttr, Map attrs) { if (styleAttr.key == Attribute.list.key) { @@ -2620,7 +2621,7 @@ class IndentSelectionIntent extends Intent { class _IndentSelectionAction extends Action { _IndentSelectionAction(this.state); - final RawEditorState state; + final QuillRawEditorState state; @override void invoke(IndentSelectionIntent intent, [BuildContext? context]) { @@ -2639,7 +2640,7 @@ class OpenSearchIntent extends Intent { class _OpenSearchAction extends ContextAction { _OpenSearchAction(this.state); - final RawEditorState state; + final QuillRawEditorState state; @override Future invoke(OpenSearchIntent intent, [BuildContext? context]) async { @@ -2671,7 +2672,7 @@ class ApplyHeaderIntent extends Intent { class _ApplyHeaderAction extends Action { _ApplyHeaderAction(this.state); - final RawEditorState state; + final QuillRawEditorState state; Attribute _getHeaderValue() { return state.controller @@ -2699,7 +2700,7 @@ class ApplyCheckListIntent extends Intent { class _ApplyCheckListAction extends Action { _ApplyCheckListAction(this.state); - final RawEditorState state; + final QuillRawEditorState state; bool _getIsToggled() { final attrs = state.controller.getSelectionStyle().attributes; @@ -2737,7 +2738,7 @@ class ApplyLinkIntent extends Intent { class ApplyLinkAction extends Action { ApplyLinkAction(this.state); - final RawEditorState state; + final QuillRawEditorState state; @override Object? invoke(ApplyLinkIntent intent) async { @@ -2768,7 +2769,7 @@ class InsertEmbedIntent extends Intent { } /// Signature for a widget builder that builds a context menu for the given -/// [RawEditorState]. +/// [QuillRawEditorState]. /// /// See also: /// @@ -2776,7 +2777,7 @@ class InsertEmbedIntent extends Intent { /// [EditableText] typedef QuillEditorContextMenuBuilder = Widget Function( BuildContext context, - RawEditorState rawEditorState, + QuillRawEditorState rawEditorState, ); class _GlyphHeights { diff --git a/pubspec.yaml b/pubspec.yaml index 5d6cd6f2..6ea8f4ea 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: flutter_quill description: A rich text editor built for the modern Android, iOS, web and desktop platforms. It is the WYSIWYG editor and a Quill component for Flutter. -version: 8.2.1 +version: 8.2.2 homepage: https://1o24bbs.com/c/bulletjournal/108 repository: https://github.com/singerdmx/flutter-quill @@ -49,12 +49,13 @@ dependencies: pasteboard: ^0.2.0 equatable: ^2.0.5 flutter_animate: ^4.2.0+1 - - flutter_test: - sdk: flutter meta: ^1.9.1 flutter: uses-material-design: true dev_dependencies: - lints: ^3.0.0 \ No newline at end of file + lints: ^3.0.0 + flutter_test: + sdk: flutter + flutter_quill_test: + path: ./flutter_quill_test \ No newline at end of file diff --git a/test/bug_fix_test.dart b/test/bug_fix_test.dart index 9869d517..041b7d2f 100644 --- a/test/bug_fix_test.dart +++ b/test/bug_fix_test.dart @@ -1,6 +1,6 @@ import 'package:flutter/material.dart'; import 'package:flutter_quill/flutter_quill.dart'; -import 'package:flutter_quill/flutter_quill_test.dart'; +import 'package:flutter_quill_test/flutter_quill_test.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { diff --git a/test/widgets/editor_test.dart b/test/widgets/editor_test.dart index adaaea49..f063e429 100644 --- a/test/widgets/editor_test.dart +++ b/test/widgets/editor_test.dart @@ -3,8 +3,7 @@ import 'dart:convert' show jsonDecode; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_quill/flutter_quill.dart'; -import 'package:flutter_quill/flutter_quill_test.dart'; -import 'package:flutter_quill/src/widgets/raw_editor/raw_editor.dart'; +import 'package:flutter_quill_test/flutter_quill_test.dart'; import 'package:flutter_test/flutter_test.dart'; void main() { @@ -95,7 +94,7 @@ void main() { expect(latestUri, equals(uri)); }); - Widget customBuilder(BuildContext context, RawEditorState state) { + Widget customBuilder(BuildContext context, QuillRawEditorState state) { return AdaptiveTextSelectionToolbar( anchors: state.contextMenuAnchors, children: [