| 
									
										
										
										
											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'; | 
					
						
							|  |  |  | import 'package:appflowy/plugins/document/document_page.dart'; | 
					
						
							|  |  |  | import 'package:appflowy/plugins/document/presentation/more/cubit/document_appearance_cubit.dart'; | 
					
						
							|  |  |  | import 'package:appflowy/plugins/document/presentation/more/more_button.dart'; | 
					
						
							|  |  |  | import 'package:appflowy/plugins/document/presentation/share/share_button.dart'; | 
					
						
							|  |  |  | import 'package:appflowy/plugins/util.dart'; | 
					
						
							|  |  |  | import 'package:appflowy/startup/plugin/plugin.dart'; | 
					
						
							|  |  |  | import 'package:appflowy/workspace/presentation/home/home_stack.dart'; | 
					
						
							|  |  |  | import 'package:appflowy/workspace/presentation/widgets/left_bar_item.dart'; | 
					
						
							| 
									
										
										
										
											2023-07-12 13:13:18 +02:00
										 |  |  | import 'package:appflowy/workspace/presentation/widgets/tab_bar_item.dart'; | 
					
						
							| 
									
										
										
										
											2021-12-07 23:01:23 +05:30
										 |  |  | import 'package:easy_localization/easy_localization.dart'; | 
					
						
							| 
									
										
										
										
											2023-04-04 08:41:16 +08:00
										 |  |  | import 'package:appflowy_backend/protobuf/flowy-folder2/view.pb.dart'; | 
					
						
							| 
									
										
										
										
											2021-07-24 14:05: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); | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |       throw FlowyPluginException.invalidData; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @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 | 
					
						
							| 
									
										
										
										
											2023-08-14 13:34:01 -07:00
										 |  |  |   FlowySvgData get icon => FlowySvgs.documents_s; | 
					
						
							| 
									
										
										
										
											2022-11-15 11:45:23 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-02-28 22:38:53 +08:00
										 |  |  |   @override | 
					
						
							| 
									
										
										
										
											2022-08-18 19:32:08 +08:00
										 |  |  |   PluginType get pluginType => PluginType.editor; | 
					
						
							| 
									
										
										
										
											2022-02-28 22:38:53 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							| 
									
										
										
										
											2023-04-04 14:08:50 +08:00
										 |  |  |   ViewLayoutPB? get layoutType => ViewLayoutPB.Document; | 
					
						
							| 
									
										
										
										
											2022-02-28 22:38:53 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-09-22 13:08:48 +08:00
										 |  |  | class DocumentPlugin extends Plugin<int> { | 
					
						
							| 
									
										
										
										
											2022-02-28 22:38:53 +08:00
										 |  |  |   late PluginType _pluginType; | 
					
						
							| 
									
										
										
										
											2021-10-28 21:55:22 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-10 15:58:57 +08:00
										 |  |  |   @override | 
					
						
							| 
									
										
										
										
											2022-09-22 13:08:48 +08:00
										 |  |  |   final ViewPluginNotifier notifier; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   DocumentPlugin({ | 
					
						
							|  |  |  |     required PluginType pluginType, | 
					
						
							|  |  |  |     required ViewPB view, | 
					
						
							| 
									
										
										
										
											2023-06-14 22:16:33 +08:00
										 |  |  |     bool listenOnViewChanged = false, | 
					
						
							| 
									
										
										
										
											2022-09-22 13:08:48 +08:00
										 |  |  |     Key? key, | 
					
						
							| 
									
										
										
										
											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
										 |  |  |   } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							| 
									
										
										
										
											2023-06-01 20:23:27 +08:00
										 |  |  |   PluginWidgetBuilder get widgetBuilder { | 
					
						
							|  |  |  |     return DocumentPluginWidgetBuilder( | 
					
						
							| 
									
										
										
										
											2022-11-28 10:37:37 +08:00
										 |  |  |       notifier: notifier, | 
					
						
							|  |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											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; | 
					
						
							| 
									
										
										
										
											2022-02-28 22:38:53 +08:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-01 20:23:27 +08:00
										 |  |  | class DocumentPluginWidgetBuilder extends PluginWidgetBuilder | 
					
						
							|  |  |  |     with NavigationItem { | 
					
						
							| 
									
										
										
										
											2022-09-22 13:08:48 +08:00
										 |  |  |   final ViewPluginNotifier notifier; | 
					
						
							|  |  |  |   ViewPB get view => notifier.view; | 
					
						
							| 
									
										
										
										
											2022-09-26 16:59:58 +08:00
										 |  |  |   int? deletedViewIndex; | 
					
						
							| 
									
										
										
										
											2022-02-28 22:38:53 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-01 20:23:27 +08:00
										 |  |  |   DocumentPluginWidgetBuilder({ | 
					
						
							| 
									
										
										
										
											2022-11-28 10:37:37 +08:00
										 |  |  |     required this.notifier, | 
					
						
							|  |  |  |     Key? key, | 
					
						
							|  |  |  |   }); | 
					
						
							| 
									
										
										
										
											2021-10-10 15:58:57 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-06-01 20:23:27 +08:00
										 |  |  |   @override | 
					
						
							|  |  |  |   EdgeInsets get contentPadding => EdgeInsets.zero; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-10-10 15:58:57 +08:00
										 |  |  |   @override | 
					
						
							| 
									
										
										
										
											2023-08-02 18:07:44 +08:00
										 |  |  |   Widget buildWidget({PluginContext? context, required bool shrinkWrap}) { | 
					
						
							| 
									
										
										
										
											2022-09-26 16:59:58 +08:00
										 |  |  |     notifier.isDeleted.addListener(() { | 
					
						
							|  |  |  |       notifier.isDeleted.value.fold(() => null, (deletedView) { | 
					
						
							|  |  |  |         if (deletedView.hasIndex()) { | 
					
						
							|  |  |  |           deletedViewIndex = deletedView.index; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |       }); | 
					
						
							|  |  |  |     }); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-07-04 14:30:38 -07:00
										 |  |  |     return BlocBuilder<DocumentAppearanceCubit, DocumentAppearance>( | 
					
						
							|  |  |  |       builder: (_, state) { | 
					
						
							|  |  |  |         return DocumentPage( | 
					
						
							|  |  |  |           view: view, | 
					
						
							|  |  |  |           onDeleted: () => context?.onDeleted(view, deletedViewIndex), | 
					
						
							|  |  |  |           key: ValueKey(view.id), | 
					
						
							|  |  |  |         ); | 
					
						
							|  |  |  |       }, | 
					
						
							| 
									
										
										
										
											2022-09-26 16:59:58 +08:00
										 |  |  |     ); | 
					
						
							|  |  |  |   } | 
					
						
							| 
									
										
										
										
											2021-10-10 17:01:30 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  |   @override | 
					
						
							| 
									
										
										
										
											2022-09-22 13:08:48 +08:00
										 |  |  |   Widget get leftBarItem => ViewLeftBarItem(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 { | 
					
						
							|  |  |  |     return Row( | 
					
						
							|  |  |  |       children: [ | 
					
						
							| 
									
										
										
										
											2023-06-19 21:20:53 +08:00
										 |  |  |         DocumentShareButton( | 
					
						
							|  |  |  |           key: ValueKey(view.id), | 
					
						
							|  |  |  |           view: view, | 
					
						
							|  |  |  |         ), | 
					
						
							| 
									
										
										
										
											2022-11-28 10:37:37 +08:00
										 |  |  |         const SizedBox(width: 10), | 
					
						
							| 
									
										
										
										
											2023-07-04 14:30:38 -07:00
										 |  |  |         const DocumentMoreButton(), | 
					
						
							| 
									
										
										
										
											2022-11-28 10:37:37 +08:00
										 |  |  |       ], | 
					
						
							| 
									
										
										
										
											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
										 |  |  | } |