feat: add support for context menu items to the editor
This commit is contained in:
parent
f4db21c367
commit
28c5adf0f9
6 changed files with 23 additions and 10 deletions
|
|
@ -23,6 +23,7 @@ export 'src/l10n/l10n.dart';
|
||||||
export 'src/plugins/plugins.dart';
|
export 'src/plugins/plugins.dart';
|
||||||
export 'src/render/selection/selectable.dart';
|
export 'src/render/selection/selectable.dart';
|
||||||
export 'src/render/toolbar/toolbar_item.dart';
|
export 'src/render/toolbar/toolbar_item.dart';
|
||||||
|
export 'src/service/context_menu/context_menu.dart';
|
||||||
export 'src/service/internal_key_event_handlers/copy_paste_handler.dart';
|
export 'src/service/internal_key_event_handlers/copy_paste_handler.dart';
|
||||||
export 'src/service/shortcut_event/key_mapping.dart';
|
export 'src/service/shortcut_event/key_mapping.dart';
|
||||||
export 'src/service/shortcut_event/keybinding.dart';
|
export 'src/service/shortcut_event/keybinding.dart';
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
import 'package:appflowy_editor/appflowy_editor.dart';
|
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||||
import 'package:appflowy_editor/src/flutter/overlay.dart';
|
import 'package:appflowy_editor/src/flutter/overlay.dart';
|
||||||
|
import 'package:appflowy_editor/src/service/context_menu/built_in_context_menu_item.dart';
|
||||||
import 'package:flutter/material.dart' hide Overlay, OverlayEntry;
|
import 'package:flutter/material.dart' hide Overlay, OverlayEntry;
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
|
|
@ -19,6 +20,7 @@ class AppFlowyEditor extends StatefulWidget {
|
||||||
Map<String, BlockComponentBuilder>? blockComponentBuilders,
|
Map<String, BlockComponentBuilder>? blockComponentBuilders,
|
||||||
List<CharacterShortcutEvent>? characterShortcutEvents,
|
List<CharacterShortcutEvent>? characterShortcutEvents,
|
||||||
List<CommandShortcutEvent>? commandShortcutEvents,
|
List<CommandShortcutEvent>? commandShortcutEvents,
|
||||||
|
List<List<ContextMenuItem>>? contextMenuItems,
|
||||||
this.editable = true,
|
this.editable = true,
|
||||||
this.autoFocus = false,
|
this.autoFocus = false,
|
||||||
this.focusedSelection,
|
this.focusedSelection,
|
||||||
|
|
@ -33,7 +35,8 @@ class AppFlowyEditor extends StatefulWidget {
|
||||||
characterShortcutEvents =
|
characterShortcutEvents =
|
||||||
characterShortcutEvents ?? standardCharacterShortcutEvents,
|
characterShortcutEvents ?? standardCharacterShortcutEvents,
|
||||||
commandShortcutEvents =
|
commandShortcutEvents =
|
||||||
commandShortcutEvents ?? standardCommandShortcutEvents;
|
commandShortcutEvents ?? standardCommandShortcutEvents,
|
||||||
|
contextMenuItems = contextMenuItems ?? standardContextMenuItems;
|
||||||
|
|
||||||
final EditorState editorState;
|
final EditorState editorState;
|
||||||
|
|
||||||
|
|
@ -101,6 +104,13 @@ class AppFlowyEditor extends StatefulWidget {
|
||||||
/// ```
|
/// ```
|
||||||
final List<CommandShortcutEvent> commandShortcutEvents;
|
final List<CommandShortcutEvent> commandShortcutEvents;
|
||||||
|
|
||||||
|
/// The context menu items.
|
||||||
|
///
|
||||||
|
/// They will be shown when the user right click on the editor.
|
||||||
|
///
|
||||||
|
/// A divider will be added between each list.
|
||||||
|
final List<List<ContextMenuItem>> contextMenuItems;
|
||||||
|
|
||||||
/// Provide a scrollController to control the scroll behavior
|
/// Provide a scrollController to control the scroll behavior
|
||||||
/// if you need to custom the scroll behavior.
|
/// if you need to custom the scroll behavior.
|
||||||
///
|
///
|
||||||
|
|
@ -225,6 +235,7 @@ class _AppFlowyEditorState extends State<AppFlowyEditor> {
|
||||||
key: editorState.service.selectionServiceKey,
|
key: editorState.service.selectionServiceKey,
|
||||||
cursorColor: widget.editorStyle.cursorColor,
|
cursorColor: widget.editorStyle.cursorColor,
|
||||||
selectionColor: widget.editorStyle.selectionColor,
|
selectionColor: widget.editorStyle.selectionColor,
|
||||||
|
contextMenuItems: widget.contextMenuItems,
|
||||||
child: KeyboardServiceWidget(
|
child: KeyboardServiceWidget(
|
||||||
key: editorState.service.keyboardServiceKey,
|
key: editorState.service.keyboardServiceKey,
|
||||||
characterShortcutEvents: widget.characterShortcutEvents,
|
characterShortcutEvents: widget.characterShortcutEvents,
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,9 @@
|
||||||
import 'package:appflowy_editor/appflowy_editor.dart';
|
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||||
import 'package:appflowy_editor/src/flutter/overlay.dart';
|
import 'package:appflowy_editor/src/flutter/overlay.dart';
|
||||||
import 'package:appflowy_editor/src/service/context_menu/built_in_context_menu_item.dart';
|
|
||||||
import 'package:appflowy_editor/src/service/context_menu/context_menu.dart';
|
|
||||||
import 'package:flutter/material.dart' hide Overlay, OverlayEntry;
|
|
||||||
|
|
||||||
import 'package:appflowy_editor/src/render/selection/cursor_widget.dart';
|
import 'package:appflowy_editor/src/render/selection/cursor_widget.dart';
|
||||||
import 'package:appflowy_editor/src/render/selection/selection_widget.dart';
|
import 'package:appflowy_editor/src/render/selection/selection_widget.dart';
|
||||||
import 'package:appflowy_editor/src/service/selection/selection_gesture.dart';
|
import 'package:appflowy_editor/src/service/selection/selection_gesture.dart';
|
||||||
|
import 'package:flutter/material.dart' hide Overlay, OverlayEntry;
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
class DesktopSelectionServiceWidget extends StatefulWidget {
|
class DesktopSelectionServiceWidget extends StatefulWidget {
|
||||||
|
|
@ -14,12 +11,14 @@ class DesktopSelectionServiceWidget extends StatefulWidget {
|
||||||
super.key,
|
super.key,
|
||||||
this.cursorColor = const Color(0xFF00BCF0),
|
this.cursorColor = const Color(0xFF00BCF0),
|
||||||
this.selectionColor = const Color.fromARGB(53, 111, 201, 231),
|
this.selectionColor = const Color.fromARGB(53, 111, 201, 231),
|
||||||
|
required this.contextMenuItems,
|
||||||
required this.child,
|
required this.child,
|
||||||
});
|
});
|
||||||
|
|
||||||
final Widget child;
|
final Widget child;
|
||||||
final Color cursorColor;
|
final Color cursorColor;
|
||||||
final Color selectionColor;
|
final Color selectionColor;
|
||||||
|
final List<List<ContextMenuItem>> contextMenuItems;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<DesktopSelectionServiceWidget> createState() =>
|
State<DesktopSelectionServiceWidget> createState() =>
|
||||||
|
|
@ -542,7 +541,7 @@ class _DesktopSelectionServiceWidgetState
|
||||||
builder: (context) => ContextMenu(
|
builder: (context) => ContextMenu(
|
||||||
position: offset,
|
position: offset,
|
||||||
editorState: editorState,
|
editorState: editorState,
|
||||||
items: builtInContextMenuItems,
|
items: widget.contextMenuItems,
|
||||||
onPressed: () => _clearContextMenu(),
|
onPressed: () => _clearContextMenu(),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
|
|
|
||||||
|
|
@ -5,15 +5,17 @@ import 'package:flutter/material.dart' hide Overlay, OverlayEntry;
|
||||||
|
|
||||||
class SelectionServiceWidget extends StatefulWidget {
|
class SelectionServiceWidget extends StatefulWidget {
|
||||||
const SelectionServiceWidget({
|
const SelectionServiceWidget({
|
||||||
Key? key,
|
super.key,
|
||||||
this.cursorColor = const Color(0xFF00BCF0),
|
this.cursorColor = const Color(0xFF00BCF0),
|
||||||
this.selectionColor = const Color.fromARGB(53, 111, 201, 231),
|
this.selectionColor = const Color.fromARGB(53, 111, 201, 231),
|
||||||
|
required this.contextMenuItems,
|
||||||
required this.child,
|
required this.child,
|
||||||
}) : super(key: key);
|
});
|
||||||
|
|
||||||
final Widget child;
|
final Widget child;
|
||||||
final Color cursorColor;
|
final Color cursorColor;
|
||||||
final Color selectionColor;
|
final Color selectionColor;
|
||||||
|
final List<List<ContextMenuItem>> contextMenuItems;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
State<SelectionServiceWidget> createState() => _SelectionServiceWidgetState();
|
State<SelectionServiceWidget> createState() => _SelectionServiceWidgetState();
|
||||||
|
|
@ -35,6 +37,7 @@ class _SelectionServiceWidgetState extends State<SelectionServiceWidget>
|
||||||
key: forwardKey,
|
key: forwardKey,
|
||||||
cursorColor: widget.cursorColor,
|
cursorColor: widget.cursorColor,
|
||||||
selectionColor: widget.selectionColor,
|
selectionColor: widget.selectionColor,
|
||||||
|
contextMenuItems: widget.contextMenuItems,
|
||||||
child: widget.child,
|
child: widget.child,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import 'package:appflowy_editor/src/service/context_menu/context_menu.dart';
|
||||||
|
|
||||||
import '../internal_key_event_handlers/copy_paste_handler.dart';
|
import '../internal_key_event_handlers/copy_paste_handler.dart';
|
||||||
|
|
||||||
final builtInContextMenuItems = [
|
final standardContextMenuItems = [
|
||||||
[
|
[
|
||||||
// cut
|
// cut
|
||||||
ContextMenuItem(
|
ContextMenuItem(
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,3 @@
|
||||||
import 'package:appflowy_editor/src/service/context_menu/context_menu.dart';
|
|
||||||
import 'package:flutter/gestures.dart';
|
import 'package:flutter/gestures.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_test/flutter_test.dart';
|
import 'package:flutter_test/flutter_test.dart';
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue