| 
									
										
										
										
											2023-02-26 16:27:17 +08:00
										 |  |  | import 'package:appflowy/plugins/document/presentation/more/cubit/document_appearance_cubit.dart'; | 
					
						
							| 
									
										
										
										
											2022-10-22 21:57:44 +08:00
										 |  |  | import 'package:appflowy_editor/appflowy_editor.dart'; | 
					
						
							|  |  |  | import 'package:flutter/material.dart'; | 
					
						
							| 
									
										
										
										
											2022-11-28 10:37:37 +08:00
										 |  |  | import 'package:provider/provider.dart'; | 
					
						
							| 
									
										
										
										
											2022-10-25 22:07:30 +08:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-10-25 21:58:44 +08:00
										 |  |  | EditorStyle customEditorTheme(BuildContext context) { | 
					
						
							| 
									
										
										
										
											2022-12-06 18:36:22 +08:00
										 |  |  |   final documentStyle = context.watch<DocumentAppearanceCubit>().state; | 
					
						
							| 
									
										
										
										
											2022-11-10 14:22:18 +08:00
										 |  |  |   var editorStyle = Theme.of(context).brightness == Brightness.dark | 
					
						
							|  |  |  |       ? EditorStyle.dark | 
					
						
							|  |  |  |       : EditorStyle.light; | 
					
						
							| 
									
										
										
										
											2022-10-25 21:58:44 +08:00
										 |  |  |   editorStyle = editorStyle.copyWith( | 
					
						
							| 
									
										
										
										
											2023-02-02 15:29:12 +07:00
										 |  |  |     padding: const EdgeInsets.symmetric(horizontal: 100, vertical: 28), | 
					
						
							| 
									
										
										
										
											2022-10-25 21:58:44 +08:00
										 |  |  |     textStyle: editorStyle.textStyle?.copyWith( | 
					
						
							| 
									
										
										
										
											2022-10-22 21:57:44 +08:00
										 |  |  |       fontFamily: 'poppins', | 
					
						
							| 
									
										
										
										
											2022-11-28 10:37:37 +08:00
										 |  |  |       fontSize: documentStyle.fontSize, | 
					
						
							| 
									
										
										
										
											2022-10-22 21:57:44 +08:00
										 |  |  |     ), | 
					
						
							| 
									
										
										
										
											2022-10-26 14:51:39 +08:00
										 |  |  |     placeholderTextStyle: editorStyle.placeholderTextStyle?.copyWith( | 
					
						
							|  |  |  |       fontFamily: 'poppins', | 
					
						
							| 
									
										
										
										
											2022-11-28 10:37:37 +08:00
										 |  |  |       fontSize: documentStyle.fontSize, | 
					
						
							| 
									
										
										
										
											2022-10-26 14:51:39 +08:00
										 |  |  |     ), | 
					
						
							| 
									
										
										
										
											2022-10-25 21:58:44 +08:00
										 |  |  |     bold: editorStyle.bold?.copyWith( | 
					
						
							| 
									
										
										
										
											2022-11-28 21:31:33 +08:00
										 |  |  |       fontWeight: FontWeight.w600, | 
					
						
							|  |  |  |       fontFamily: 'poppins-Bold', | 
					
						
							| 
									
										
										
										
											2022-10-22 21:57:44 +08:00
										 |  |  |     ), | 
					
						
							| 
									
										
										
										
											2022-11-14 15:31:39 +08:00
										 |  |  |     backgroundColor: Theme.of(context).colorScheme.surface, | 
					
						
							| 
									
										
										
										
											2023-02-09 12:37:00 +08:00
										 |  |  |     selectionMenuItemSelectedIconColor: | 
					
						
							|  |  |  |         Theme.of(context).textTheme.bodyMedium?.color, | 
					
						
							|  |  |  |     selectionMenuItemSelectedTextColor: | 
					
						
							|  |  |  |         Theme.of(context).textTheme.bodyMedium?.color, | 
					
						
							| 
									
										
										
										
											2022-10-22 21:57:44 +08:00
										 |  |  |   ); | 
					
						
							| 
									
										
										
										
											2022-10-25 21:58:44 +08:00
										 |  |  |   return editorStyle; | 
					
						
							| 
									
										
										
										
											2022-10-22 21:57:44 +08:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2022-10-25 21:58:44 +08:00
										 |  |  | 
 | 
					
						
							|  |  |  | Iterable<ThemeExtension<dynamic>> customPluginTheme(BuildContext context) { | 
					
						
							| 
									
										
										
										
											2022-12-06 18:36:22 +08:00
										 |  |  |   final documentStyle = context.watch<DocumentAppearanceCubit>().state; | 
					
						
							| 
									
										
										
										
											2022-11-28 15:34:55 +08:00
										 |  |  |   final baseFontSize = documentStyle.fontSize; | 
					
						
							| 
									
										
										
										
											2022-10-25 22:07:30 +08:00
										 |  |  |   const basePadding = 12.0; | 
					
						
							| 
									
										
										
										
											2022-11-10 14:22:18 +08:00
										 |  |  |   var headingPluginStyle = Theme.of(context).brightness == Brightness.dark | 
					
						
							|  |  |  |       ? HeadingPluginStyle.dark | 
					
						
							|  |  |  |       : HeadingPluginStyle.light; | 
					
						
							| 
									
										
										
										
											2022-10-25 22:07:30 +08:00
										 |  |  |   headingPluginStyle = headingPluginStyle.copyWith( | 
					
						
							|  |  |  |     textStyle: (EditorState editorState, Node node) { | 
					
						
							|  |  |  |       final headingToFontSize = { | 
					
						
							| 
									
										
										
										
											2022-11-28 10:37:37 +08:00
										 |  |  |         'h1': baseFontSize + 12, | 
					
						
							|  |  |  |         'h2': baseFontSize + 8, | 
					
						
							|  |  |  |         'h3': baseFontSize + 4, | 
					
						
							|  |  |  |         'h4': baseFontSize, | 
					
						
							|  |  |  |         'h5': baseFontSize, | 
					
						
							|  |  |  |         'h6': baseFontSize, | 
					
						
							| 
									
										
										
										
											2022-10-25 22:07:30 +08:00
										 |  |  |       }; | 
					
						
							|  |  |  |       final fontSize = | 
					
						
							| 
									
										
										
										
											2022-11-28 10:37:37 +08:00
										 |  |  |           headingToFontSize[node.attributes.heading] ?? baseFontSize; | 
					
						
							| 
									
										
										
										
											2022-10-25 22:07:30 +08:00
										 |  |  |       return TextStyle(fontSize: fontSize, fontWeight: FontWeight.w600); | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |     padding: (EditorState editorState, Node node) { | 
					
						
							|  |  |  |       final headingToPadding = { | 
					
						
							|  |  |  |         'h1': basePadding + 6, | 
					
						
							|  |  |  |         'h2': basePadding + 4, | 
					
						
							|  |  |  |         'h3': basePadding + 2, | 
					
						
							|  |  |  |         'h4': basePadding, | 
					
						
							|  |  |  |         'h5': basePadding, | 
					
						
							|  |  |  |         'h6': basePadding, | 
					
						
							|  |  |  |       }; | 
					
						
							|  |  |  |       final padding = headingToPadding[node.attributes.heading] ?? basePadding; | 
					
						
							|  |  |  |       return EdgeInsets.only(bottom: padding); | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   ); | 
					
						
							| 
									
										
										
										
											2022-11-28 15:34:55 +08:00
										 |  |  |   var numberListPluginStyle = Theme.of(context).brightness == Brightness.dark | 
					
						
							|  |  |  |       ? NumberListPluginStyle.dark | 
					
						
							|  |  |  |       : NumberListPluginStyle.light; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |   numberListPluginStyle = numberListPluginStyle.copyWith( | 
					
						
							|  |  |  |     icon: (_, textNode) { | 
					
						
							|  |  |  |       const iconPadding = EdgeInsets.only(left: 5.0, right: 5.0); | 
					
						
							|  |  |  |       return Container( | 
					
						
							|  |  |  |         padding: iconPadding, | 
					
						
							|  |  |  |         child: Text( | 
					
						
							|  |  |  |           '${textNode.attributes.number.toString()}.', | 
					
						
							|  |  |  |           style: customEditorTheme(context).textStyle, | 
					
						
							|  |  |  |         ), | 
					
						
							|  |  |  |       ); | 
					
						
							|  |  |  |     }, | 
					
						
							|  |  |  |   ); | 
					
						
							| 
									
										
										
										
											2022-11-10 14:22:18 +08:00
										 |  |  |   final pluginTheme = Theme.of(context).brightness == Brightness.dark | 
					
						
							|  |  |  |       ? darkPlguinStyleExtension | 
					
						
							|  |  |  |       : lightPlguinStyleExtension; | 
					
						
							| 
									
										
										
										
											2022-10-25 22:07:30 +08:00
										 |  |  |   return pluginTheme.toList() | 
					
						
							| 
									
										
										
										
											2022-11-28 15:34:55 +08:00
										 |  |  |     ..removeWhere((element) => | 
					
						
							|  |  |  |         element is HeadingPluginStyle || element is NumberListPluginStyle) | 
					
						
							|  |  |  |     ..add(headingPluginStyle) | 
					
						
							|  |  |  |     ..add(numberListPluginStyle); | 
					
						
							| 
									
										
										
										
											2022-10-25 21:58:44 +08:00
										 |  |  | } |