|
@@ -1,24 +1,25 @@
|
|
|
|
+import 'package:flowy_editor/service/internal_key_event_handlers/delele_text_handler.dart';
|
|
|
|
+import 'package:flowy_editor/service/internal_key_event_handlers/update_text_style_by_command_x_handler.dart';
|
|
|
|
+import 'package:flutter/material.dart';
|
|
|
|
+
|
|
|
|
+import 'package:flowy_editor/editor_state.dart';
|
|
import 'package:flowy_editor/render/editor/editor_entry.dart';
|
|
import 'package:flowy_editor/render/editor/editor_entry.dart';
|
|
|
|
+import 'package:flowy_editor/render/rich_text/bulleted_list_text.dart';
|
|
import 'package:flowy_editor/render/rich_text/checkbox_text.dart';
|
|
import 'package:flowy_editor/render/rich_text/checkbox_text.dart';
|
|
import 'package:flowy_editor/render/rich_text/flowy_rich_text.dart';
|
|
import 'package:flowy_editor/render/rich_text/flowy_rich_text.dart';
|
|
|
|
+import 'package:flowy_editor/render/rich_text/heading_text.dart';
|
|
|
|
+import 'package:flowy_editor/render/rich_text/number_list_text.dart';
|
|
|
|
+import 'package:flowy_editor/render/rich_text/quoted_text.dart';
|
|
import 'package:flowy_editor/render/selection/floating_shortcut_widget.dart';
|
|
import 'package:flowy_editor/render/selection/floating_shortcut_widget.dart';
|
|
import 'package:flowy_editor/service/input_service.dart';
|
|
import 'package:flowy_editor/service/input_service.dart';
|
|
-import 'package:flowy_editor/service/internal_key_event_handlers/enter_in_edge_of_text_node_handler.dart';
|
|
|
|
-import 'package:flowy_editor/service/render_plugin_service.dart';
|
|
|
|
-import 'package:flowy_editor/service/shortcut_service.dart';
|
|
|
|
import 'package:flowy_editor/service/internal_key_event_handlers/arrow_keys_handler.dart';
|
|
import 'package:flowy_editor/service/internal_key_event_handlers/arrow_keys_handler.dart';
|
|
import 'package:flowy_editor/service/internal_key_event_handlers/delete_nodes_handler.dart';
|
|
import 'package:flowy_editor/service/internal_key_event_handlers/delete_nodes_handler.dart';
|
|
-import 'package:flowy_editor/service/internal_key_event_handlers/delete_single_text_node_handler.dart';
|
|
|
|
|
|
+import 'package:flowy_editor/service/internal_key_event_handlers/enter_in_edge_of_text_node_handler.dart';
|
|
import 'package:flowy_editor/service/internal_key_event_handlers/shortcut_handler.dart';
|
|
import 'package:flowy_editor/service/internal_key_event_handlers/shortcut_handler.dart';
|
|
import 'package:flowy_editor/service/keyboard_service.dart';
|
|
import 'package:flowy_editor/service/keyboard_service.dart';
|
|
|
|
+import 'package:flowy_editor/service/render_plugin_service.dart';
|
|
import 'package:flowy_editor/service/selection_service.dart';
|
|
import 'package:flowy_editor/service/selection_service.dart';
|
|
-import 'package:flowy_editor/editor_state.dart';
|
|
|
|
-import 'package:flowy_editor/render/rich_text/bulleted_list_text.dart';
|
|
|
|
-import 'package:flowy_editor/render/rich_text/heading_text.dart';
|
|
|
|
-import 'package:flowy_editor/render/rich_text/number_list_text.dart';
|
|
|
|
-import 'package:flowy_editor/render/rich_text/quoted_text.dart';
|
|
|
|
-
|
|
|
|
-import 'package:flutter/material.dart';
|
|
|
|
|
|
+import 'package:flowy_editor/service/shortcut_service.dart';
|
|
|
|
|
|
NodeWidgetBuilders defaultBuilders = {
|
|
NodeWidgetBuilders defaultBuilders = {
|
|
'editor': EditorEntryWidgetBuilder(),
|
|
'editor': EditorEntryWidgetBuilder(),
|
|
@@ -30,6 +31,15 @@ NodeWidgetBuilders defaultBuilders = {
|
|
'text/quote': QuotedTextNodeWidgetBuilder(),
|
|
'text/quote': QuotedTextNodeWidgetBuilder(),
|
|
};
|
|
};
|
|
|
|
|
|
|
|
+List<FlowyKeyEventHandler> defaultKeyEventHandler = [
|
|
|
|
+ deleteTextHandler,
|
|
|
|
+ slashShortcutHandler,
|
|
|
|
+ flowyDeleteNodesHandler,
|
|
|
|
+ arrowKeysHandler,
|
|
|
|
+ enterInEdgeOfTextNodeHandler,
|
|
|
|
+ updateTextStyleByCommandXHandler,
|
|
|
|
+];
|
|
|
|
+
|
|
class FlowyEditor extends StatefulWidget {
|
|
class FlowyEditor extends StatefulWidget {
|
|
const FlowyEditor({
|
|
const FlowyEditor({
|
|
Key? key,
|
|
Key? key,
|
|
@@ -61,13 +71,16 @@ class _FlowyEditorState extends State<FlowyEditor> {
|
|
void initState() {
|
|
void initState() {
|
|
super.initState();
|
|
super.initState();
|
|
|
|
|
|
- editorState.service.renderPluginService = FlowyRenderPlugin(
|
|
|
|
- editorState: editorState,
|
|
|
|
- builders: {
|
|
|
|
- ...defaultBuilders,
|
|
|
|
- ...widget.customBuilders,
|
|
|
|
- },
|
|
|
|
- );
|
|
|
|
|
|
+ editorState.service.renderPluginService = _createRenderPlugin();
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @override
|
|
|
|
+ void didUpdateWidget(covariant FlowyEditor oldWidget) {
|
|
|
|
+ super.didUpdateWidget(oldWidget);
|
|
|
|
+
|
|
|
|
+ if (editorState.service != oldWidget.editorState.service) {
|
|
|
|
+ editorState.service.renderPluginService = _createRenderPlugin();
|
|
|
|
+ }
|
|
}
|
|
}
|
|
|
|
|
|
@override
|
|
@override
|
|
@@ -81,11 +94,7 @@ class _FlowyEditorState extends State<FlowyEditor> {
|
|
child: FlowyKeyboard(
|
|
child: FlowyKeyboard(
|
|
key: editorState.service.keyboardServiceKey,
|
|
key: editorState.service.keyboardServiceKey,
|
|
handlers: [
|
|
handlers: [
|
|
- slashShortcutHandler,
|
|
|
|
- flowyDeleteNodesHandler,
|
|
|
|
- deleteSingleTextNodeHandler,
|
|
|
|
- arrowKeysHandler,
|
|
|
|
- enterInEdgeOfTextNodeHandler,
|
|
|
|
|
|
+ ...defaultKeyEventHandler,
|
|
...widget.keyEventHandlers,
|
|
...widget.keyEventHandlers,
|
|
],
|
|
],
|
|
editorState: editorState,
|
|
editorState: editorState,
|
|
@@ -106,4 +115,12 @@ class _FlowyEditorState extends State<FlowyEditor> {
|
|
),
|
|
),
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ FlowyRenderPlugin _createRenderPlugin() => FlowyRenderPlugin(
|
|
|
|
+ editorState: editorState,
|
|
|
|
+ builders: {
|
|
|
|
+ ...defaultBuilders,
|
|
|
|
+ ...widget.customBuilders,
|
|
|
|
+ },
|
|
|
|
+ );
|
|
}
|
|
}
|