Browse Source

chore: refactor the service type

Lucas.Xu 2 năm trước cách đây
mục cha
commit
1eec97c761

+ 4 - 0
frontend/app_flowy/packages/flowy_editor/lib/flowy_editor.dart

@@ -14,3 +14,7 @@ export 'src/render/selection/selectable.dart';
 export 'src/service/editor_service.dart';
 export 'src/service/render_plugin_service.dart';
 export 'src/service/service.dart';
+export 'src/service/selection_service.dart';
+export 'src/service/scroll_service.dart';
+export 'src/service/keyboard_service.dart';
+export 'src/service/input_service.dart';

+ 2 - 3
frontend/app_flowy/packages/flowy_editor/lib/src/service/input_service.dart

@@ -7,7 +7,7 @@ import 'package:flowy_editor/src/editor_state.dart';
 import 'package:flowy_editor/src/extensions/node_extensions.dart';
 import 'package:flowy_editor/src/operation/transaction_builder.dart';
 
-mixin FlowyInputService {
+abstract class FlowyInputService {
   void attach(TextEditingValue textEditingValue);
   void apply(List<TextEditingDelta> deltas);
   void close();
@@ -29,8 +29,7 @@ class FlowyInput extends StatefulWidget {
 }
 
 class _FlowyInputState extends State<FlowyInput>
-    with FlowyInputService
-    implements DeltaTextInputClient {
+    implements FlowyInputService, DeltaTextInputClient {
   TextInputConnection? _textInputConnection;
   TextRange? _composingTextRange;
 

+ 2 - 2
frontend/app_flowy/packages/flowy_editor/lib/src/service/keyboard_service.dart

@@ -3,7 +3,7 @@ import 'package:flutter/services.dart';
 
 import 'package:flutter/material.dart';
 
-mixin FlowyKeyboardService<T extends StatefulWidget> on State<T> {
+abstract class FlowyKeyboardService {
   void enable();
   void disable();
 }
@@ -31,7 +31,7 @@ class FlowyKeyboard extends StatefulWidget {
 }
 
 class _FlowyKeyboardState extends State<FlowyKeyboard>
-    with FlowyKeyboardService {
+    implements FlowyKeyboardService {
   final FocusNode _focusNode = FocusNode(debugLabel: 'flowy_keyboard_service');
 
   bool isFocus = true;

+ 3 - 2
frontend/app_flowy/packages/flowy_editor/lib/src/service/scroll_service.dart

@@ -1,7 +1,7 @@
 import 'package:flutter/gestures.dart';
 import 'package:flutter/material.dart';
 
-mixin FlowyScrollService<T extends StatefulWidget> on State<T> {
+abstract class FlowyScrollService {
   double get dy;
 
   void scrollTo(double dy);
@@ -22,7 +22,8 @@ class FlowyScroll extends StatefulWidget {
   State<FlowyScroll> createState() => _FlowyScrollState();
 }
 
-class _FlowyScrollState extends State<FlowyScroll> with FlowyScrollService {
+class _FlowyScrollState extends State<FlowyScroll>
+    implements FlowyScrollService {
   final _scrollController = ScrollController();
   final _scrollViewKey = GlobalKey();
 

+ 3 - 2
frontend/app_flowy/packages/flowy_editor/lib/src/service/selection_service.dart

@@ -29,7 +29,7 @@ import 'package:flowy_editor/src/render/selection/selection_widget.dart';
 /// final nodes = selectionService.currentSelectedNodes;
 /// ```
 ///
-mixin FlowySelectionService<T extends StatefulWidget> on State<T> {
+abstract class FlowySelectionService {
   /// The current [Selection] in editor.
   ///
   /// The value is null if there is no nodes are selected.
@@ -90,7 +90,8 @@ class FlowySelection extends StatefulWidget {
 }
 
 class _FlowySelectionState extends State<FlowySelection>
-    with FlowySelectionService, WidgetsBindingObserver {
+    with WidgetsBindingObserver
+    implements FlowySelectionService {
   final _cursorKey = GlobalKey(debugLabel: 'cursor');
 
   final List<OverlayEntry> _selectionOverlays = [];

+ 3 - 2
frontend/app_flowy/packages/flowy_editor/lib/src/service/toolbar_service.dart

@@ -3,7 +3,7 @@ import 'package:flutter/material.dart';
 import 'package:flowy_editor/flowy_editor.dart';
 import 'package:flowy_editor/src/render/selection/toolbar_widget.dart';
 
-mixin FlowyToolbarService {
+abstract class FlowyToolbarService {
   /// Show the toolbar widget beside the offset.
   void showInOffset(Offset offset, LayerLink layerLink);
 
@@ -25,7 +25,8 @@ class FlowyToolbar extends StatefulWidget {
   State<FlowyToolbar> createState() => _FlowyToolbarState();
 }
 
-class _FlowyToolbarState extends State<FlowyToolbar> with FlowyToolbarService {
+class _FlowyToolbarState extends State<FlowyToolbar>
+    implements FlowyToolbarService {
   OverlayEntry? _toolbarOverlay;
 
   @override