mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2025-04-24 22:57:12 -04:00
Implement cover plugin 1868 (#1897)
* implement_cover_plugin_#1868 * code cleanup * fix: CI issue fix * fix: cover plugin implementation finalized * fix: localization fixes * fix: added add cover button * chore: optimize the cover plugin code * feat: auto hide the add button and cover buttons when leaving --------- Co-authored-by: Lucas.Xu <lucas.xu@appflowy.io>
This commit is contained in:
parent
fd41459a30
commit
f1316acfcc
13 changed files with 804 additions and 64 deletions
|
@ -1,5 +1,6 @@
|
|||
import 'package:appflowy/plugins/document/presentation/plugins/board/board_menu_item.dart';
|
||||
import 'package:appflowy/plugins/document/presentation/plugins/board/board_node_widget.dart';
|
||||
import 'package:appflowy/plugins/document/presentation/plugins/cover/cover_node_widget.dart';
|
||||
import 'package:appflowy/plugins/document/presentation/plugins/grid/grid_menu_item.dart';
|
||||
import 'package:appflowy/plugins/document/presentation/plugins/grid/grid_node_widget.dart';
|
||||
import 'package:appflowy/plugins/document/presentation/plugins/openai/widgets/auto_completion_node_widget.dart';
|
||||
|
@ -9,6 +10,7 @@ import 'package:appflowy/plugins/document/presentation/plugins/openai/widgets/sm
|
|||
import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart';
|
||||
import 'package:appflowy_editor/appflowy_editor.dart';
|
||||
import 'package:appflowy_editor_plugins/appflowy_editor_plugins.dart';
|
||||
import 'package:dartz/dartz.dart' as dartz;
|
||||
import 'package:flowy_infra_ui/widget/error_page.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
@ -126,9 +128,11 @@ class _AppFlowyEditorPageState extends State<_AppFlowyEditorPage> {
|
|||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final theme = Theme.of(context);
|
||||
final autoFocusParamters = _autoFocusParamters();
|
||||
final editor = AppFlowyEditor(
|
||||
editorState: editorState,
|
||||
autoFocus: editorState.document.isEmpty,
|
||||
autoFocus: autoFocusParamters.value1,
|
||||
focusedSelection: autoFocusParamters.value2,
|
||||
customBuilders: {
|
||||
// Divider
|
||||
kDividerType: DividerWidgetBuilder(),
|
||||
|
@ -144,6 +148,8 @@ class _AppFlowyEditorPageState extends State<_AppFlowyEditorPage> {
|
|||
kCalloutType: CalloutNodeWidgetBuilder(),
|
||||
// Auto Generator,
|
||||
kAutoCompletionInputType: AutoCompletionInputBuilder(),
|
||||
// Cover
|
||||
kCoverType: CoverNodeWidgetBuilder(),
|
||||
// Smart Edit,
|
||||
kSmartEditType: SmartEditInputBuilder(),
|
||||
},
|
||||
|
@ -174,7 +180,7 @@ class _AppFlowyEditorPageState extends State<_AppFlowyEditorPage> {
|
|||
// enable open ai features if needed.
|
||||
if (openAIKey != null && openAIKey!.isNotEmpty) ...[
|
||||
autoGeneratorMenuItem,
|
||||
]
|
||||
],
|
||||
],
|
||||
toolbarItems: [
|
||||
if (openAIKey != null && openAIKey!.isNotEmpty) ...[
|
||||
|
@ -229,4 +235,18 @@ class _AppFlowyEditorPageState extends State<_AppFlowyEditorPage> {
|
|||
await editorState.apply(transaction, withUpdateCursor: false);
|
||||
}
|
||||
}
|
||||
|
||||
dartz.Tuple2<bool, Selection?> _autoFocusParamters() {
|
||||
if (editorState.document.isEmpty) {
|
||||
return dartz.Tuple2(true, Selection.single(path: [0], startOffset: 0));
|
||||
}
|
||||
final texts = editorState.document.root.children.whereType<TextNode>();
|
||||
if (texts.every((element) => element.toPlainText().isEmpty)) {
|
||||
return dartz.Tuple2(
|
||||
true,
|
||||
Selection.single(path: texts.first.path, startOffset: 0),
|
||||
);
|
||||
}
|
||||
return const dartz.Tuple2(false, null);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue