| 
									
										
										
										
											2022-08-10 17:59:28 +08:00
										 |  |  | library document_plugin; | 
					
						
							| 
									
										
										
										
											2022-03-01 16:05:45 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-08-14 13:34:01 -07:00
										 |  |  | import 'package:appflowy/generated/flowy_svgs.g.dart'; | 
					
						
							| 
									
										
										
										
											2023-02-26 16:27:17 +08:00
										 |  |  | import 'package:appflowy/generated/locale_keys.g.dart'; | 
					
						
							| 
									
										
										
										
											2024-02-25 16:46:13 +01:00
										 |  |  | import 'package:appflowy/plugins/document/application/document_appearance_cubit.dart'; | 
					
						
							| 
									
										
										
										
											2023-02-26 16:27:17 +08:00
										 |  |  | import 'package:appflowy/plugins/document/document_page.dart'; | 
					
						
							| 
									
										
										
										
											2024-03-28 17:46:31 +08:00
										 |  |  | import 'package:appflowy/plugins/document/presentation/document_collaborators.dart'; | 
					
						
							| 
									
										
										
										
											2024-07-22 13:35:42 +08:00
										 |  |  | import 'package:appflowy/plugins/shared/share/share_button.dart'; | 
					
						
							| 
									
										
										
										
											2023-02-26 16:27:17 +08:00
										 |  |  | import 'package:appflowy/plugins/util.dart'; | 
					
						
							| 
									
										
										
										
											2024-03-21 12:26:48 +07:00
										 |  |  | import 'package:appflowy/shared/feature_flags.dart'; | 
					
						
							| 
									
										
										
										
											2023-02-26 16:27:17 +08:00
										 |  |  | import 'package:appflowy/startup/plugin/plugin.dart'; | 
					
						
							| 
									
										
										
										
											2024-02-25 16:46:13 +01:00
										 |  |  | import 'package:appflowy/workspace/application/view_info/view_info_bloc.dart'; | 
					
						
							| 
									
										
										
										
											2023-02-26 16:27:17 +08:00
										 |  |  | import 'package:appflowy/workspace/presentation/home/home_stack.dart'; | 
					
						
							| 
									
										
										
										
											2024-02-25 21:32:44 +01:00
										 |  |  | import 'package:appflowy/workspace/presentation/widgets/favorite_button.dart'; | 
					
						
							| 
									
										
										
										
											2024-02-25 16:46:13 +01:00
										 |  |  | import 'package:appflowy/workspace/presentation/widgets/more_view_actions/more_view_actions.dart'; | 
					
						
							| 
									
										
										
										
											2023-07-12 13:13:18 +02:00
										 |  |  | import 'package:appflowy/workspace/presentation/widgets/tab_bar_item.dart'; | 
					
						
							| 
									
										
										
										
											2023-11-09 13:11:13 +08:00
										 |  |  | import 'package:appflowy/workspace/presentation/widgets/view_title_bar.dart'; | 
					
						
							| 
									
										
										
										
											2023-12-31 07:29:40 +08:00
										 |  |  | import 'package:appflowy_backend/protobuf/flowy-folder/view.pb.dart'; | 
					
						
							| 
									
										
										
										
											2024-01-24 15:15:57 +01:00
										 |  |  | import 'package:appflowy_editor/appflowy_editor.dart'; | 
					
						
							| 
									
										
										
										
											2023-11-09 13:11:13 +08:00
										 |  |  | import 'package:easy_localization/easy_localization.dart'; | 
					
						
							| 
									
										
										
										
											2023-12-10 13:44:37 +02:00
										 |  |  | import 'package:flowy_infra_ui/flowy_infra_ui.dart'; | 
					
						
							| 
									
										
										
										
											2024-05-27 08:51:49 +08:00
										 |  |  | import 'package:flutter/material.dart'; | 
					
						
							| 
									
										
										
										
											2022-11-28 18:02:05 +08:00
										 |  |  | import 'package:flutter_bloc/flutter_bloc.dart'; | 
					
						
							| 
									
										
										
										
											2022-05-17 20:25:35 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-01 11:22:39 +08:00
										 |  |  | class DocumentPluginBuilder extends PluginBuilder { | 
					
						
							| 
									
										
										
										
											2022-02-28 22:38:53 +08:00
										 |  |  |   @override | 
					
						
							|  |  |  |   Plugin build(dynamic data) { | 
					
						
							| 
									
										
										
										
											2022-07-19 14:11:29 +08:00
										 |  |  |     if (data is ViewPB) { | 
					
						
							| 
									
										
										
										
											2022-02-28 22:38:53 +08:00
										 |  |  |       return DocumentPlugin(pluginType: pluginType, view: data); | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2024-01-24 15:15:57 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     throw FlowyPluginException.invalidData; | 
					
						
							| 
									
										
										
										
											2022-02-28 22:38:53 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							| 
									
										
										
										
											2022-05-17 20:25:35 +02:00
										 |  |  |   String get menuName => LocaleKeys.document_menuName.tr(); | 
					
						
							| 
									
										
										
										
											2022-02-28 22:38:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-15 11:45:23 +08:00
										 |  |  |   @override | 
					
						
							| 
									
										
										
										
											2024-06-04 09:22:47 +08:00
										 |  |  |   FlowySvgData get icon => FlowySvgs.icon_document_s; | 
					
						
							| 
									
										
										
										
											2022-11-15 11:45:23 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-28 22:38:53 +08:00
										 |  |  |   @override | 
					
						
							| 
									
										
										
										
											2024-04-29 13:44:42 +08:00
										 |  |  |   PluginType get pluginType => PluginType.document; | 
					
						
							| 
									
										
										
										
											2022-02-28 22:38:53 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							| 
									
										
										
										
											2024-06-03 14:27:28 +08:00
										 |  |  |   ViewLayoutPB get layoutType => ViewLayoutPB.Document; | 
					
						
							| 
									
										
										
										
											2022-02-28 22:38:53 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-04-29 13:44:42 +08:00
										 |  |  | class DocumentPlugin extends Plugin { | 
					
						
							| 
									
										
										
										
											2022-09-22 13:08:48 +08:00
										 |  |  |   DocumentPlugin({ | 
					
						
							|  |  |  |     required ViewPB view, | 
					
						
							| 
									
										
										
										
											2024-01-24 15:15:57 +01:00
										 |  |  |     required PluginType pluginType, | 
					
						
							|  |  |  |     this.initialSelection, | 
					
						
							| 
									
										
										
										
											2023-06-20 23:48:34 +08:00
										 |  |  |   }) : notifier = ViewPluginNotifier(view: view) { | 
					
						
							| 
									
										
										
										
											2022-09-22 13:08:48 +08:00
										 |  |  |     _pluginType = pluginType; | 
					
						
							| 
									
										
										
										
											2022-11-28 10:37:37 +08:00
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-01-24 15:15:57 +01:00
										 |  |  |   late PluginType _pluginType; | 
					
						
							| 
									
										
										
										
											2024-02-25 16:46:13 +01:00
										 |  |  |   late final ViewInfoBloc _viewInfoBloc; | 
					
						
							| 
									
										
										
										
											2024-01-24 15:15:57 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-11-28 10:37:37 +08:00
										 |  |  |   @override | 
					
						
							| 
									
										
										
										
											2024-01-24 15:15:57 +01:00
										 |  |  |   final ViewPluginNotifier notifier; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   final Selection? initialSelection; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   PluginWidgetBuilder get widgetBuilder => DocumentPluginWidgetBuilder( | 
					
						
							| 
									
										
										
										
											2024-02-25 16:46:13 +01:00
										 |  |  |         bloc: _viewInfoBloc, | 
					
						
							| 
									
										
										
										
											2024-01-24 15:15:57 +01:00
										 |  |  |         notifier: notifier, | 
					
						
							|  |  |  |         initialSelection: initialSelection, | 
					
						
							|  |  |  |       ); | 
					
						
							| 
									
										
										
										
											2021-11-09 23:13:04 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-10 15:58:57 +08:00
										 |  |  |   @override | 
					
						
							| 
									
										
										
										
											2023-06-01 20:23:27 +08:00
										 |  |  |   PluginType get pluginType => _pluginType; | 
					
						
							| 
									
										
										
										
											2022-02-28 22:38:53 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							| 
									
										
										
										
											2022-09-22 13:08:48 +08:00
										 |  |  |   PluginId get id => notifier.view.id; | 
					
						
							| 
									
										
										
										
											2024-02-25 16:46:13 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   void init() { | 
					
						
							|  |  |  |     _viewInfoBloc = ViewInfoBloc(view: notifier.view) | 
					
						
							|  |  |  |       ..add(const ViewInfoEvent.started()); | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							|  |  |  |   void dispose() { | 
					
						
							|  |  |  |     _viewInfoBloc.close(); | 
					
						
							|  |  |  |     notifier.dispose(); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2022-02-28 22:38:53 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-01 20:23:27 +08:00
										 |  |  | class DocumentPluginWidgetBuilder extends PluginWidgetBuilder | 
					
						
							|  |  |  |     with NavigationItem { | 
					
						
							|  |  |  |   DocumentPluginWidgetBuilder({ | 
					
						
							| 
									
										
										
										
											2024-02-25 16:46:13 +01:00
										 |  |  |     required this.bloc, | 
					
						
							| 
									
										
										
										
											2024-01-24 15:15:57 +01:00
										 |  |  |     required this.notifier, | 
					
						
							|  |  |  |     this.initialSelection, | 
					
						
							| 
									
										
										
										
											2022-11-28 10:37:37 +08:00
										 |  |  |   }); | 
					
						
							| 
									
										
										
										
											2021-10-10 15:58:57 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-25 16:46:13 +01:00
										 |  |  |   final ViewInfoBloc bloc; | 
					
						
							| 
									
										
										
										
											2024-01-24 15:15:57 +01:00
										 |  |  |   final ViewPluginNotifier notifier; | 
					
						
							|  |  |  |   ViewPB get view => notifier.view; | 
					
						
							|  |  |  |   int? deletedViewIndex; | 
					
						
							|  |  |  |   final Selection? initialSelection; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-01 20:23:27 +08:00
										 |  |  |   @override | 
					
						
							|  |  |  |   EdgeInsets get contentPadding => EdgeInsets.zero; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-10 15:58:57 +08:00
										 |  |  |   @override | 
					
						
							| 
									
										
										
										
											2024-06-03 14:27:28 +08:00
										 |  |  |   Widget buildWidget({ | 
					
						
							|  |  |  |     required PluginContext context, | 
					
						
							|  |  |  |     required bool shrinkWrap, | 
					
						
							| 
									
										
										
										
											2024-07-22 13:35:42 +08:00
										 |  |  |     Map<String, dynamic>? data, | 
					
						
							| 
									
										
										
										
											2024-06-03 14:27:28 +08:00
										 |  |  |   }) { | 
					
						
							| 
									
										
										
										
											2022-09-26 16:59:58 +08:00
										 |  |  |     notifier.isDeleted.addListener(() { | 
					
						
							| 
									
										
										
										
											2024-02-24 20:54:10 +07:00
										 |  |  |       final deletedView = notifier.isDeleted.value; | 
					
						
							|  |  |  |       if (deletedView != null && deletedView.hasIndex()) { | 
					
						
							|  |  |  |         deletedViewIndex = deletedView.index; | 
					
						
							|  |  |  |       } | 
					
						
							| 
									
										
										
										
											2022-09-26 16:59:58 +08:00
										 |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2024-02-25 16:46:13 +01:00
										 |  |  |     return BlocProvider<ViewInfoBloc>.value( | 
					
						
							|  |  |  |       value: bloc, | 
					
						
							|  |  |  |       child: BlocBuilder<DocumentAppearanceCubit, DocumentAppearance>( | 
					
						
							|  |  |  |         builder: (_, state) => DocumentPage( | 
					
						
							|  |  |  |           key: ValueKey(view.id), | 
					
						
							|  |  |  |           view: view, | 
					
						
							| 
									
										
										
										
											2024-06-03 14:27:28 +08:00
										 |  |  |           onDeleted: () => context.onDeleted?.call(view, deletedViewIndex), | 
					
						
							| 
									
										
										
										
											2024-02-25 16:46:13 +01:00
										 |  |  |           initialSelection: initialSelection, | 
					
						
							|  |  |  |         ), | 
					
						
							| 
									
										
										
										
											2024-01-24 15:15:57 +01:00
										 |  |  |       ), | 
					
						
							| 
									
										
										
										
											2022-09-26 16:59:58 +08:00
										 |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-10-10 17:01:30 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							| 
									
										
										
										
											2024-05-27 08:51:49 +08:00
										 |  |  |   Widget get leftBarItem => ViewTitleBar(key: ValueKey(view.id), view: view); | 
					
						
							| 
									
										
										
										
											2021-10-28 21:55:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-12 13:13:18 +02:00
										 |  |  |   @override | 
					
						
							|  |  |  |   Widget tabBarItem(String pluginId) => ViewTabBarItem(view: notifier.view); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-28 21:55:22 +08:00
										 |  |  |   @override | 
					
						
							| 
									
										
										
										
											2022-11-28 10:37:37 +08:00
										 |  |  |   Widget? get rightBarItem { | 
					
						
							| 
									
										
										
										
											2024-02-25 16:46:13 +01:00
										 |  |  |     return BlocProvider<ViewInfoBloc>.value( | 
					
						
							|  |  |  |       value: bloc, | 
					
						
							|  |  |  |       child: Row( | 
					
						
							| 
									
										
										
										
											2024-03-21 12:26:48 +07:00
										 |  |  |         mainAxisSize: MainAxisSize.min, | 
					
						
							| 
									
										
										
										
											2024-02-25 16:46:13 +01:00
										 |  |  |         children: [ | 
					
						
							| 
									
										
										
										
											2024-03-21 12:26:48 +07:00
										 |  |  |           ...FeatureFlag.syncDocument.isOn | 
					
						
							|  |  |  |               ? [ | 
					
						
							| 
									
										
										
										
											2024-03-28 17:46:31 +08:00
										 |  |  |                   DocumentCollaborators( | 
					
						
							|  |  |  |                     key: ValueKey('collaborators_${view.id}'), | 
					
						
							| 
									
										
										
										
											2024-06-04 09:22:47 +08:00
										 |  |  |                     width: 120, | 
					
						
							| 
									
										
										
										
											2024-03-28 17:46:31 +08:00
										 |  |  |                     height: 32, | 
					
						
							|  |  |  |                     view: view, | 
					
						
							|  |  |  |                   ), | 
					
						
							|  |  |  |                   const HSpace(16), | 
					
						
							| 
									
										
										
										
											2024-03-21 12:26:48 +07:00
										 |  |  |                 ] | 
					
						
							|  |  |  |               : [const HSpace(8)], | 
					
						
							| 
									
										
										
										
											2024-07-22 13:35:42 +08:00
										 |  |  |           ShareButton( | 
					
						
							| 
									
										
										
										
											2024-03-28 17:46:31 +08:00
										 |  |  |             key: ValueKey('share_button_${view.id}'), | 
					
						
							|  |  |  |             view: view, | 
					
						
							|  |  |  |           ), | 
					
						
							| 
									
										
										
										
											2024-05-27 08:51:49 +08:00
										 |  |  |           const HSpace(10), | 
					
						
							| 
									
										
										
										
											2024-02-25 21:32:44 +01:00
										 |  |  |           ViewFavoriteButton( | 
					
						
							| 
									
										
										
										
											2024-02-25 16:46:13 +01:00
										 |  |  |             key: ValueKey('favorite_button_${view.id}'), | 
					
						
							|  |  |  |             view: view, | 
					
						
							|  |  |  |           ), | 
					
						
							|  |  |  |           const HSpace(4), | 
					
						
							|  |  |  |           MoreViewActions(view: view), | 
					
						
							|  |  |  |         ], | 
					
						
							|  |  |  |       ), | 
					
						
							| 
									
										
										
										
											2021-11-09 23:13:04 +08:00
										 |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-07-24 22:27:24 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-11-09 23:13:04 +08:00
										 |  |  |   @override | 
					
						
							| 
									
										
										
										
											2022-11-28 10:37:37 +08:00
										 |  |  |   List<NavigationItem> get navigationItems => [this]; | 
					
						
							| 
									
										
										
										
											2021-11-09 23:13:04 +08:00
										 |  |  | } |