|
1 | 1 | import 'package:appflowy/plugins/document/application/doc_bloc.dart'; |
2 | | -import 'package:appflowy/plugins/document/presentation/editor_plugins/actions/option_action.dart'; |
3 | | -import 'package:appflowy/plugins/document/presentation/editor_plugins/actions/block_action_list.dart'; |
4 | 2 | import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart'; |
5 | 3 | import 'package:appflowy/plugins/document/presentation/editor_style.dart'; |
6 | 4 | import 'package:appflowy/plugins/document/presentation/editor_plugins/inline_page/inline_page_reference.dart'; |
7 | 5 | import 'package:appflowy_editor/appflowy_editor.dart'; |
| 6 | +import 'package:collection/collection.dart'; |
8 | 7 | import 'package:flowy_infra_ui/flowy_infra_ui.dart'; |
9 | 8 | import 'package:flutter/material.dart'; |
10 | 9 | import 'package:flutter_bloc/flutter_bloc.dart'; |
@@ -55,20 +54,7 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> { |
55 | 54 | highlightColorItem, |
56 | 55 | ]; |
57 | 56 |
|
58 | | - late final slashMenuItems = [ |
59 | | - inlineGridMenuItem(documentBloc), |
60 | | - referencedGridMenuItem, |
61 | | - inlineBoardMenuItem(documentBloc), |
62 | | - referencedBoardMenuItem, |
63 | | - inlineCalendarMenuItem(documentBloc), |
64 | | - referencedCalendarMenuItem, |
65 | | - calloutItem, |
66 | | - mathEquationItem, |
67 | | - codeBlockItem, |
68 | | - emojiMenuItem, |
69 | | - autoGeneratorMenuItem, |
70 | | - outlineItem, |
71 | | - ]; |
| 57 | + late final List<SelectionMenuItem> slashMenuItems; |
72 | 58 |
|
73 | 59 | late final Map<String, BlockComponentBuilder> blockComponentBuilders = |
74 | 60 | _customAppFlowyBlockComponentBuilders(); |
@@ -119,6 +105,9 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> { |
119 | 105 | @override |
120 | 106 | void initState() { |
121 | 107 | super.initState(); |
| 108 | + |
| 109 | + slashMenuItems = _customSlashMenuItems(); |
| 110 | + |
122 | 111 | effectiveScrollController = widget.scrollController ?? ScrollController(); |
123 | 112 | } |
124 | 113 |
|
@@ -219,6 +208,15 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> { |
219 | 208 | ), |
220 | 209 | ImageBlockKeys.type: ImageBlockComponentBuilder( |
221 | 210 | configuration: configuration, |
| 211 | + showMenu: true, |
| 212 | + menuBuilder: (node, state) => Positioned( |
| 213 | + top: 0, |
| 214 | + right: 10, |
| 215 | + child: ImageMenu( |
| 216 | + node: node, |
| 217 | + state: state, |
| 218 | + ), |
| 219 | + ), |
222 | 220 | ), |
223 | 221 | DatabaseBlockKeys.gridType: DatabaseViewBlockComponentBuilder( |
224 | 222 | configuration: configuration, |
@@ -254,8 +252,15 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> { |
254 | 252 | ), |
255 | 253 | AutoCompletionBlockKeys.type: AutoCompletionBlockComponentBuilder(), |
256 | 254 | SmartEditBlockKeys.type: SmartEditBlockComponentBuilder(), |
257 | | - ToggleListBlockKeys.type: ToggleListBlockComponentBuilder(), |
258 | | - OutlineBlockKeys.type: OutlineBlockComponentBuilder(), |
| 255 | + ToggleListBlockKeys.type: ToggleListBlockComponentBuilder( |
| 256 | + configuration: configuration, |
| 257 | + ), |
| 258 | + OutlineBlockKeys.type: OutlineBlockComponentBuilder( |
| 259 | + configuration: configuration.copyWith( |
| 260 | + placeholderTextStyle: (_) => |
| 261 | + styleCustomizer.outlineBlockPlaceholderStyleBuilder(), |
| 262 | + ), |
| 263 | + ), |
259 | 264 | }; |
260 | 265 |
|
261 | 266 | final builders = { |
@@ -325,6 +330,34 @@ class _AppFlowyEditorPageState extends State<AppFlowyEditorPage> { |
325 | 330 | return builders; |
326 | 331 | } |
327 | 332 |
|
| 333 | + List<SelectionMenuItem> _customSlashMenuItems() { |
| 334 | + final items = [...standardSelectionMenuItems]; |
| 335 | + final imageItem = items.firstWhereOrNull( |
| 336 | + (element) => element.name == AppFlowyEditorLocalizations.current.image, |
| 337 | + ); |
| 338 | + if (imageItem != null) { |
| 339 | + final imageItemIndex = items.indexOf(imageItem); |
| 340 | + if (imageItemIndex != -1) { |
| 341 | + items[imageItemIndex] = customImageMenuItem; |
| 342 | + } |
| 343 | + } |
| 344 | + return [ |
| 345 | + ...items, |
| 346 | + inlineGridMenuItem(documentBloc), |
| 347 | + referencedGridMenuItem, |
| 348 | + inlineBoardMenuItem(documentBloc), |
| 349 | + referencedBoardMenuItem, |
| 350 | + inlineCalendarMenuItem(documentBloc), |
| 351 | + referencedCalendarMenuItem, |
| 352 | + calloutItem, |
| 353 | + outlineItem, |
| 354 | + mathEquationItem, |
| 355 | + codeBlockItem, |
| 356 | + emojiMenuItem, |
| 357 | + autoGeneratorMenuItem, |
| 358 | + ]; |
| 359 | + } |
| 360 | + |
328 | 361 | (bool, Selection?) _computeAutoFocusParameters() { |
329 | 362 | if (widget.editorState.document.isEmpty) { |
330 | 363 | return (true, Selection.collapse([0], 0)); |
|
0 commit comments