Skip to content

Commit 5bb5337

Browse files
committed
feat: 0.0.5 release preparation
1 parent a371cf3 commit 5bb5337

File tree

12 files changed

+192
-15
lines changed

12 files changed

+192
-15
lines changed

frontend/app_flowy/packages/appflowy_editor/CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 0.0.5
2+
* Support customize the hotkey for a shortcut on different platform.
3+
* Support customize a theme.
4+
* Support localizations.
5+
* Support insert numbered list.
6+
* Fix some bugs.
7+
18
## 0.0.4
29
* Support more shortcut events.
310
* Fix some bugs.

frontend/app_flowy/packages/appflowy_editor/README.md

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ and the Flutter guide for
3636
* Design and modify an ever expanding list of customizable features including
3737
* components (such as form input controls, numbered lists, and rich text widgets)
3838
* shortcut events
39+
* themes
3940
* menu options (**coming soon!**)
40-
* themes (**coming soon!**)
4141
* [Test-coverage](https://github.com/AppFlowy-IO/AppFlowy/blob/main/frontend/app_flowy/packages/appflowy_editor/documentation/testing.md) and on-going maintenance by AppFlowy's core team and community of more than 1,000 builders
4242

4343
## Getting Started
@@ -54,23 +54,36 @@ flutter pub get
5454
Start by creating a new empty AppFlowyEditor object.
5555

5656
```dart
57+
final editorStyle = EditorStyle.defaultStyle();
5758
final editorState = EditorState.empty(); // an empty state
5859
final editor = AppFlowyEditor(
5960
editorState: editorState,
60-
keyEventHandlers: const [],
61+
shortcutEvents: const [],
6162
customBuilders: const {},
63+
editorStyle: editorStyle,
6264
);
6365
```
6466

6567
You can also create an editor from a JSON object in order to configure your initial state.
6668

6769
```dart
6870
final json = ...;
71+
final editorStyle = EditorStyle.defaultStyle();
6972
final editorState = EditorState(StateTree.fromJson(data));
7073
final editor = AppFlowyEditor(
7174
editorState: editorState,
72-
keyEventHandlers: const [],
75+
shortcutEvents: const [],
7376
customBuilders: const {},
77+
editorStyle: editorStyle,
78+
);
79+
```
80+
81+
> Note: The parameters `localizationsDelegates` need to be assigned in MaterialApp widget
82+
```dart
83+
MaterialApp(
84+
localizationsDelegates: const [
85+
AppFlowyEditorLocalizations.delegate,
86+
],
7487
);
7588
```
7689

frontend/app_flowy/packages/appflowy_editor/documentation/customizing.md

Lines changed: 101 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,9 @@ Widget build(BuildContext context) {
1616
alignment: Alignment.topCenter,
1717
child: AppFlowyEditor(
1818
editorState: EditorState.empty(),
19+
editorStyle: EditorStyle.defaultStyle(),
1920
shortcutEvents: const [],
21+
customBuilders: const {},
2022
),
2123
),
2224
);
@@ -116,6 +118,8 @@ Widget build(BuildContext context) {
116118
alignment: Alignment.topCenter,
117119
child: AppFlowyEditor(
118120
editorState: EditorState.empty(),
121+
editorStyle: EditorStyle.defaultStyle(),
122+
customBuilders: const {},
119123
shortcutEvents: [
120124
_underscoreToItalicHandler,
121125
],
@@ -145,7 +149,9 @@ Widget build(BuildContext context) {
145149
alignment: Alignment.topCenter,
146150
child: AppFlowyEditor(
147151
editorState: EditorState.empty(),
148-
keyEventHandlers: const [],
152+
editorStyle: EditorStyle.defaultStyle(),
153+
shortcutEvents: const [],
154+
customBuilders: const {},
149155
),
150156
),
151157
);
@@ -283,6 +289,8 @@ final editorState = EditorState(
283289
);
284290
return AppFlowyEditor(
285291
editorState: editorState,
292+
editorStyle: EditorStyle.defaultStyle(),
293+
shortcutEvents: const [],
286294
customBuilders: {
287295
'network_image': NetworkImageNodeWidgetBuilder(),
288296
},
@@ -292,3 +300,95 @@ return AppFlowyEditor(
292300
![Whew!](./images/customizing_a_component.gif)
293301

294302
Check out the [complete code](https://github.com/AppFlowy-IO/AppFlowy/blob/main/frontend/app_flowy/packages/appflowy_editor/example/lib/plugin/network_image_node_widget.dart) file of this example.
303+
304+
## Customizing a Theme (New Feature in 0.0.5, Alpha)
305+
306+
We will use a simple example to illustrate how to quickly customize a theme.
307+
308+
Let's start with a blank document:
309+
310+
```dart
311+
@override
312+
Widget build(BuildContext context) {
313+
return Scaffold(
314+
body: Container(
315+
alignment: Alignment.topCenter,
316+
child: AppFlowyEditor(
317+
editorState: EditorState.empty(),
318+
editorStyle: EditorStyle.defaultStyle(),
319+
shortcutEvents: const [],
320+
customBuilders: const {},
321+
),
322+
),
323+
);
324+
}
325+
```
326+
327+
At this point, the editor looks like ...
328+
![Before](./images/customizing_a_theme_before.png)
329+
330+
331+
Next, we will customize the `EditorStyle`.
332+
333+
```dart
334+
EditorStyle _customizedStyle() {
335+
final editorStyle = EditorStyle.defaultStyle();
336+
return editorStyle.copyWith(
337+
cursorColor: Colors.white,
338+
selectionColor: Colors.blue.withOpacity(0.3),
339+
textStyle: editorStyle.textStyle.copyWith(
340+
defaultTextStyle: GoogleFonts.poppins().copyWith(
341+
color: Colors.white,
342+
fontSize: 14.0,
343+
),
344+
defaultPlaceholderTextStyle: GoogleFonts.poppins().copyWith(
345+
color: Colors.white.withOpacity(0.5),
346+
fontSize: 14.0,
347+
),
348+
bold: const TextStyle(fontWeight: FontWeight.w900),
349+
code: TextStyle(
350+
fontStyle: FontStyle.italic,
351+
color: Colors.red[300],
352+
backgroundColor: Colors.grey.withOpacity(0.3),
353+
),
354+
highlightColorHex: '0x6FFFEB3B',
355+
),
356+
pluginStyles: {
357+
'text/quote': builtInPluginStyle
358+
..update(
359+
'textStyle',
360+
(_) {
361+
return (EditorState editorState, Node node) {
362+
return TextStyle(
363+
color: Colors.blue[200],
364+
fontStyle: FontStyle.italic,
365+
fontSize: 12.0,
366+
);
367+
};
368+
},
369+
),
370+
},
371+
);
372+
}
373+
```
374+
375+
Now our 'customize style' function is done and the only task left is to inject it into the AppFlowyEditor.
376+
377+
```dart
378+
@override
379+
Widget build(BuildContext context) {
380+
return Scaffold(
381+
body: Container(
382+
alignment: Alignment.topCenter,
383+
child: AppFlowyEditor(
384+
editorState: EditorState.empty(),
385+
editorStyle: _customizedStyle(),
386+
shortcutEvents: const [],
387+
customBuilders: const {},
388+
),
389+
),
390+
);
391+
}
392+
```
393+
394+
![After](./images/customizing_a_theme_after.png)
300 KB
Loading
343 KB
Loading

frontend/app_flowy/packages/appflowy_editor/example/assets/example.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
{
5757
"type": "text",
5858
"attributes": { "subtype": "quote" },
59-
"delta": [{ "insert": "Here is an exmaple you can give it a try" }]
59+
"delta": [{ "insert": "Here is an example you can give a try" }]
6060
},
6161
{ "type": "text", "delta": [] },
6262
{

frontend/app_flowy/packages/appflowy_editor/example/lib/main.dart

Lines changed: 47 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import 'dart:io';
44
import 'package:example/plugin/underscore_to_italic_key_event_handler.dart';
55
import 'package:flutter/material.dart';
66
import 'package:flutter/services.dart';
7+
import 'package:flutter_localizations/flutter_localizations.dart';
8+
import 'package:google_fonts/google_fonts.dart';
79

810
import 'package:path_provider/path_provider.dart';
911

@@ -22,6 +24,9 @@ class MyApp extends StatelessWidget {
2224
Widget build(BuildContext context) {
2325
return MaterialApp(
2426
localizationsDelegates: const [
27+
GlobalMaterialLocalizations.delegate,
28+
GlobalCupertinoLocalizations.delegate,
29+
GlobalWidgetsLocalizations.delegate,
2530
AppFlowyEditorLocalizations.delegate,
2631
],
2732
supportedLocales: AppFlowyEditorLocalizations.delegate.supportedLocales,
@@ -149,11 +154,8 @@ class _MyHomePageState extends State<MyHomePage> {
149154
icon: const Icon(Icons.color_lens),
150155
onPressed: () {
151156
setState(() {
152-
_editorStyle = _editorStyle.copyWith(
153-
textStyle: darkMode
154-
? BuiltInTextStyle.builtIn()
155-
: BuiltInTextStyle.builtInDarkMode(),
156-
);
157+
_editorStyle =
158+
darkMode ? EditorStyle.defaultStyle() : _customizedStyle();
157159
darkMode = !darkMode;
158160
});
159161
},
@@ -196,4 +198,44 @@ class _MyHomePageState extends State<MyHomePage> {
196198
});
197199
}
198200
}
201+
202+
EditorStyle _customizedStyle() {
203+
final editorStyle = EditorStyle.defaultStyle();
204+
return editorStyle.copyWith(
205+
cursorColor: Colors.white,
206+
selectionColor: Colors.blue.withOpacity(0.3),
207+
textStyle: editorStyle.textStyle.copyWith(
208+
defaultTextStyle: GoogleFonts.poppins().copyWith(
209+
color: Colors.white,
210+
fontSize: 14.0,
211+
),
212+
defaultPlaceholderTextStyle: GoogleFonts.poppins().copyWith(
213+
color: Colors.white.withOpacity(0.5),
214+
fontSize: 14.0,
215+
),
216+
bold: const TextStyle(fontWeight: FontWeight.w900),
217+
code: TextStyle(
218+
fontStyle: FontStyle.italic,
219+
color: Colors.red[300],
220+
backgroundColor: Colors.grey.withOpacity(0.3),
221+
),
222+
highlightColorHex: '0x6FFFEB3B',
223+
),
224+
pluginStyles: {
225+
'text/quote': builtInPluginStyle
226+
..update(
227+
'textStyle',
228+
(_) {
229+
return (EditorState editorState, Node node) {
230+
return TextStyle(
231+
color: Colors.blue[200],
232+
fontStyle: FontStyle.italic,
233+
fontSize: 12.0,
234+
);
235+
};
236+
},
237+
),
238+
},
239+
);
240+
}
199241
}

frontend/app_flowy/packages/appflowy_editor/example/pubspec.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ dependencies:
3939
url_launcher: ^6.1.5
4040
video_player: ^2.4.5
4141
pod_player: 0.0.8
42-
flutter_inappwebview: ^5.4.3+7
4342
path_provider: ^2.0.11
43+
google_fonts: ^3.0.1
44+
flutter_localizations:
45+
sdk: flutter
4446

4547
dev_dependencies:
4648
flutter_test:

frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text/bulleted_list_text.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:appflowy_editor/src/render/rich_text/flowy_rich_text.dart';
77
import 'package:appflowy_editor/src/render/selection/selectable.dart';
88
import 'package:appflowy_editor/src/service/render_plugin_service.dart';
99
import 'package:flutter/material.dart';
10+
import 'package:appflowy_editor/src/extensions/text_style_extension.dart';
1011

1112
class BulletedListTextNodeWidgetBuilder extends NodeWidgetBuilder<TextNode> {
1213
@override
@@ -77,6 +78,10 @@ class _BulletedListTextNodeWidgetState extends State<BulletedListTextNodeWidget>
7778
child: FlowyRichText(
7879
key: _richTextKey,
7980
placeholderText: 'List',
81+
textSpanDecorator: (textSpan) =>
82+
textSpan.updateTextStyle(textStyle),
83+
placeholderTextSpanDecorator: (textSpan) =>
84+
textSpan.updateTextStyle(textStyle),
8085
lineHeight: widget.editorState.editorStyle.textStyle.lineHeight,
8186
textNode: widget.textNode,
8287
editorState: widget.editorState,

frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text/quoted_text.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import 'package:appflowy_editor/src/render/rich_text/flowy_rich_text.dart';
77
import 'package:appflowy_editor/src/render/selection/selectable.dart';
88
import 'package:appflowy_editor/src/service/render_plugin_service.dart';
99
import 'package:flutter/material.dart';
10+
import 'package:appflowy_editor/src/extensions/text_style_extension.dart';
1011

1112
class QuotedTextNodeWidgetBuilder extends NodeWidgetBuilder<TextNode> {
1213
@override
@@ -77,6 +78,10 @@ class _QuotedTextNodeWidgetState extends State<QuotedTextNodeWidget>
7778
key: _richTextKey,
7879
placeholderText: 'Quote',
7980
textNode: widget.textNode,
81+
textSpanDecorator: (textSpan) =>
82+
textSpan.updateTextStyle(textStyle),
83+
placeholderTextSpanDecorator: (textSpan) =>
84+
textSpan.updateTextStyle(textStyle),
8085
lineHeight: widget.editorState.editorStyle.textStyle.lineHeight,
8186
editorState: widget.editorState,
8287
),

0 commit comments

Comments
 (0)