mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: optimize the align toolbar item (#4364)
This commit is contained in:
parent
cd82c13753
commit
690a3746fa
@ -13,23 +13,27 @@ const _center = 'center';
|
|||||||
const _right = 'right';
|
const _right = 'right';
|
||||||
|
|
||||||
class AlignItems extends StatelessWidget {
|
class AlignItems extends StatelessWidget {
|
||||||
const AlignItems({
|
AlignItems({
|
||||||
super.key,
|
super.key,
|
||||||
required this.editorState,
|
required this.editorState,
|
||||||
});
|
});
|
||||||
|
|
||||||
final EditorState editorState;
|
final EditorState editorState;
|
||||||
|
final List<(String, FlowySvgData)> _alignMenuItems = [
|
||||||
|
(_left, FlowySvgs.m_aa_align_left_s),
|
||||||
|
(_center, FlowySvgs.m_aa_align_center_s),
|
||||||
|
(_right, FlowySvgs.m_aa_align_right_s),
|
||||||
|
];
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final currentAlignItem = _getCurrentAlignItem();
|
final currentAlignItem = _getCurrentAlignItem();
|
||||||
final alignMenuItems = _getAlignMenuItems();
|
|
||||||
final theme = ToolbarColorExtension.of(context);
|
final theme = ToolbarColorExtension.of(context);
|
||||||
return PopupMenu(
|
return PopupMenu(
|
||||||
itemLength: alignMenuItems.length,
|
itemLength: _alignMenuItems.length,
|
||||||
onSelected: (index) {
|
onSelected: (index) {
|
||||||
editorState.alignBlock(
|
editorState.alignBlock(
|
||||||
alignMenuItems[index].$1,
|
_alignMenuItems[index].$1,
|
||||||
selectionExtraInfo: {
|
selectionExtraInfo: {
|
||||||
selectionExtraInfoDoNotAttachTextService: true,
|
selectionExtraInfoDoNotAttachTextService: true,
|
||||||
selectionExtraInfoDisableFloatingToolbar: true,
|
selectionExtraInfoDisableFloatingToolbar: true,
|
||||||
@ -37,7 +41,7 @@ class AlignItems extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
menuBuilder: (context, keys, currentIndex) {
|
menuBuilder: (context, keys, currentIndex) {
|
||||||
final children = alignMenuItems
|
final children = _alignMenuItems
|
||||||
.mapIndexed(
|
.mapIndexed(
|
||||||
(index, e) => [
|
(index, e) => [
|
||||||
PopupMenuItemWrapper(
|
PopupMenuItemWrapper(
|
||||||
@ -45,7 +49,7 @@ class AlignItems extends StatelessWidget {
|
|||||||
isSelected: currentIndex == index,
|
isSelected: currentIndex == index,
|
||||||
icon: e.$2,
|
icon: e.$2,
|
||||||
),
|
),
|
||||||
if (index != 0 && index != alignMenuItems.length - 1)
|
if (index != 0 && index != _alignMenuItems.length - 1)
|
||||||
const HSpace(12),
|
const HSpace(12),
|
||||||
],
|
],
|
||||||
)
|
)
|
||||||
@ -84,36 +88,12 @@ class AlignItems extends StatelessWidget {
|
|||||||
(String, FlowySvgData) _getCurrentAlignItem() {
|
(String, FlowySvgData) _getCurrentAlignItem() {
|
||||||
final align = _getCurrentBlockAlign();
|
final align = _getCurrentBlockAlign();
|
||||||
if (align == _center) {
|
if (align == _center) {
|
||||||
return (_center, FlowySvgs.m_aa_align_center_s);
|
|
||||||
} else if (align == _right) {
|
|
||||||
return (_right, FlowySvgs.m_aa_align_right_s);
|
return (_right, FlowySvgs.m_aa_align_right_s);
|
||||||
|
} else if (align == _right) {
|
||||||
|
return (_left, FlowySvgs.m_aa_align_left_s);
|
||||||
|
} else {
|
||||||
|
return (_center, FlowySvgs.m_aa_align_center_s);
|
||||||
}
|
}
|
||||||
return (_left, FlowySvgs.m_aa_align_left_s);
|
|
||||||
}
|
|
||||||
|
|
||||||
List<(String, FlowySvgData)> _getAlignMenuItems() {
|
|
||||||
return [
|
|
||||||
(_left, FlowySvgs.m_aa_align_left_s),
|
|
||||||
(_center, FlowySvgs.m_aa_align_center_s),
|
|
||||||
(_right, FlowySvgs.m_aa_align_right_s),
|
|
||||||
];
|
|
||||||
// final align = _getCurrentBlockAlign();
|
|
||||||
|
|
||||||
// if (align == _center) {
|
|
||||||
// return [
|
|
||||||
// (_left, FlowySvgs.m_aa_align_left_s),
|
|
||||||
// (_right, FlowySvgs.m_aa_align_right_s),
|
|
||||||
// ];
|
|
||||||
// } else if (align == _right) {
|
|
||||||
// return [
|
|
||||||
// (_left, FlowySvgs.m_aa_align_left_s),
|
|
||||||
// (_center, FlowySvgs.m_aa_align_center_s),
|
|
||||||
// ];
|
|
||||||
// }
|
|
||||||
// return [
|
|
||||||
// (_center, FlowySvgs.m_aa_align_center_s),
|
|
||||||
// (_right, FlowySvgs.m_aa_align_right_s),
|
|
||||||
// ];
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String _getCurrentBlockAlign() {
|
String _getCurrentBlockAlign() {
|
||||||
|
@ -80,7 +80,7 @@ class _HeadingOrTextItem extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _convert(bool isSelected) async {
|
Future<void> _convert(bool isSelected) async {
|
||||||
editorState.convertBlockType(
|
await editorState.convertBlockType(
|
||||||
blockType,
|
blockType,
|
||||||
isSelected: isSelected,
|
isSelected: isSelected,
|
||||||
extraAttributes: level != null
|
extraAttributes: level != null
|
||||||
@ -90,6 +90,14 @@ class _HeadingOrTextItem extends StatelessWidget {
|
|||||||
: null,
|
: null,
|
||||||
selectionExtraInfo: {
|
selectionExtraInfo: {
|
||||||
selectionExtraInfoDoNotAttachTextService: true,
|
selectionExtraInfoDoNotAttachTextService: true,
|
||||||
|
selectionExtraInfoDisableFloatingToolbar: true,
|
||||||
|
},
|
||||||
|
);
|
||||||
|
await editorState.updateSelectionWithReason(
|
||||||
|
editorState.selection,
|
||||||
|
extraInfo: {
|
||||||
|
selectionExtraInfoDisableFloatingToolbar: true,
|
||||||
|
selectionExtraInfoDoNotAttachTextService: true,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,23 +0,0 @@
|
|||||||
import 'package:appflowy/plugins/document/presentation/editor_plugins/plugins.dart';
|
|
||||||
import 'package:appflowy_editor/appflowy_editor.dart';
|
|
||||||
|
|
||||||
class CodeBlockNodeParser extends NodeParser {
|
|
||||||
const CodeBlockNodeParser();
|
|
||||||
|
|
||||||
@override
|
|
||||||
String get id => CodeBlockKeys.type;
|
|
||||||
|
|
||||||
@override
|
|
||||||
String transform(Node node, DocumentMarkdownEncoder? encoder) {
|
|
||||||
final delta = node.delta;
|
|
||||||
final language = node.attributes[CodeBlockKeys.language] ?? '';
|
|
||||||
if (delta == null) {
|
|
||||||
throw Exception('Delta is null');
|
|
||||||
}
|
|
||||||
final markdown = DeltaMarkdownEncoder().convert(delta);
|
|
||||||
final result = '```$language\n$markdown\n```';
|
|
||||||
final suffix = node.next == null ? '' : '\n';
|
|
||||||
|
|
||||||
return '$result$suffix';
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,13 +0,0 @@
|
|||||||
import 'package:appflowy_editor/appflowy_editor.dart';
|
|
||||||
|
|
||||||
class DividerNodeParser extends NodeParser {
|
|
||||||
const DividerNodeParser();
|
|
||||||
|
|
||||||
@override
|
|
||||||
String get id => DividerBlockKeys.type;
|
|
||||||
|
|
||||||
@override
|
|
||||||
String transform(Node node, DocumentMarkdownEncoder? encoder) {
|
|
||||||
return '---\n';
|
|
||||||
}
|
|
||||||
}
|
|
@ -1,6 +1,4 @@
|
|||||||
export 'callout_node_parser.dart';
|
export 'callout_node_parser.dart';
|
||||||
export 'code_block_node_parser.dart';
|
|
||||||
export 'custom_image_node_parser.dart';
|
export 'custom_image_node_parser.dart';
|
||||||
export 'divider_node_parser.dart';
|
|
||||||
export 'math_equation_node_parser.dart';
|
export 'math_equation_node_parser.dart';
|
||||||
export 'toggle_list_node_parser.dart';
|
export 'toggle_list_node_parser.dart';
|
||||||
|
@ -1,5 +1,3 @@
|
|||||||
export 'callout_node_parser.dart';
|
export 'callout_node_parser.dart';
|
||||||
export 'code_block_node_parser.dart';
|
|
||||||
export 'divider_node_parser.dart';
|
|
||||||
export 'math_equation_node_parser.dart';
|
export 'math_equation_node_parser.dart';
|
||||||
export 'toggle_list_node_parser.dart';
|
export 'toggle_list_node_parser.dart';
|
||||||
|
@ -11,9 +11,7 @@ import 'package:dartz/dartz.dart';
|
|||||||
import 'package:easy_localization/easy_localization.dart';
|
import 'package:easy_localization/easy_localization.dart';
|
||||||
|
|
||||||
const List<NodeParser> _customParsers = [
|
const List<NodeParser> _customParsers = [
|
||||||
DividerNodeParser(),
|
|
||||||
MathEquationNodeParser(),
|
MathEquationNodeParser(),
|
||||||
CodeBlockNodeParser(),
|
|
||||||
CalloutNodeParser(),
|
CalloutNodeParser(),
|
||||||
ToggleListNodeParser(),
|
ToggleListNodeParser(),
|
||||||
CustomImageNodeParser(),
|
CustomImageNodeParser(),
|
||||||
|
@ -53,11 +53,11 @@ packages:
|
|||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
path: "."
|
path: "."
|
||||||
ref: "49575bc"
|
ref: "3d373be"
|
||||||
resolved-ref: "49575bc58f0332810e8aebbeae752eac77275d54"
|
resolved-ref: "3d373be64d28e13558e43d489728a6e0616821a9"
|
||||||
url: "https://github.com/AppFlowy-IO/appflowy-editor.git"
|
url: "https://github.com/AppFlowy-IO/appflowy-editor.git"
|
||||||
source: git
|
source: git
|
||||||
version: "2.2.0"
|
version: "2.3.0"
|
||||||
appflowy_editor_plugins:
|
appflowy_editor_plugins:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
@ -164,7 +164,7 @@ dependency_overrides:
|
|||||||
appflowy_editor:
|
appflowy_editor:
|
||||||
git:
|
git:
|
||||||
url: https://github.com/AppFlowy-IO/appflowy-editor.git
|
url: https://github.com/AppFlowy-IO/appflowy-editor.git
|
||||||
ref: "49575bc"
|
ref: "3d373be"
|
||||||
|
|
||||||
file: ^7.0.0
|
file: ^7.0.0
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user