Skip to content

Commit 9a01f90

Browse files
authored
doc: Editorial updates to the ReadMe for AppFlowyEditor (#900)
docs: Editorial updates to the ReadMe for AppFlowyEditor
1 parent 1b9f096 commit 9a01f90

File tree

3 files changed

+115
-82
lines changed

3 files changed

+115
-82
lines changed

frontend/app_flowy/packages/appflowy_editor/README.md

Lines changed: 37 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,27 @@ and the Flutter guide for
2626

2727
## Key Features
2828

29-
* Allow you to build rich, intuitive editors
30-
* Design and modify it your way by customizing components, shortcut events, and many more coming soon including menu options and themes
31-
* [Test-covered](https://github.com/AppFlowy-IO/AppFlowy/blob/main/frontend/app_flowy/packages/appflowy_editor/documentation/testing.md) and maintained by AppFlowy's core team along with a community of more than 1,000 builders
29+
* Build rich, intuitive editors
30+
* Design and modify an ever expanding list of customizable features including
31+
* components (such as form input controls, numbered lists, and rich text widgets)
32+
* shortcut events
33+
* menu options (**coming soon!**)
34+
* themes (**coming soon!**)
35+
* [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
3236

37+
## Getting Started
3338

34-
## Getting started
39+
Add the AppFlowy editor [Flutter package](https://docs.flutter.dev/development/packages-and-plugins/using-packages) to your environment.
3540

3641
```shell
3742
flutter pub add appflowy_editor
3843
flutter pub get
3944
```
4045

41-
## How to use
46+
## Creating Your First Editor
47+
48+
Start by creating a new empty AppFlowyEditor object.
4249

43-
Let's create a new AppFlowyEditor object
4450
```dart
4551
final editorState = EditorState.empty(); // an empty state
4652
final editor = AppFlowyEditor(
@@ -50,7 +56,8 @@ final editor = AppFlowyEditor(
5056
);
5157
```
5258

53-
You can also create an editor from a JSON file
59+
You can also create an editor from a JSON object in order to configure your initial state.
60+
5461
```dart
5562
final json = ...;
5663
final editorState = EditorState(StateTree.fromJson(data));
@@ -61,37 +68,43 @@ final editor = AppFlowyEditor(
6168
);
6269
```
6370

64-
To get a sense for how you might use it, run this example:
71+
To get a sense for how the AppFlowy Editor works, run our example:
72+
6573
```shell
6674
git clone https://github.com/AppFlowy-IO/AppFlowy.git
6775
cd frontend/app_flowy/packages/appflowy_editor/example
6876
flutter run
6977
```
7078

79+
## Customizing Your Editor
80+
81+
### Customizing Components
7182

72-
## How to customize
73-
### Customize a component
74-
Please refer to [customizing a component](https://github.com/AppFlowy-IO/AppFlowy/blob/main/frontend/app_flowy/packages/appflowy_editor/documentation/customizing.md#customize-a-component) for more details.
83+
Please refer to our documentation on customizing AppFlowy for a detailed discussion about [customizing components](https://github.com/AppFlowy-IO/AppFlowy/blob/main/frontend/app_flowy/packages/appflowy_editor/documentation/customizing.md#customize-a-component).
7584

85+
Below are some examples of component customizations:
7686

77-
### Customize a shortcut event
78-
Please refer to [customizing a shortcut event](https://github.com/AppFlowy-IO/AppFlowy/blob/main/frontend/app_flowy/packages/appflowy_editor/documentation/customizing.md#customize-a-shortcut-event) for more details.
87+
* [Checkbox Text](https://github.com/AppFlowy-IO/AppFlowy/blob/main/frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text/checkbox_text.dart) demonstrates how to extend new styles based on existing rich text components
88+
* [Image](https://github.com/AppFlowy-IO/AppFlowy/blob/main/frontend/app_flowy/packages/appflowy_editor/example/lib/plugin/network_image_node_widget.dart) demonstrates how to extend a new node and render it
89+
* See further examples of [rich-text plugins](https://github.com/AppFlowy-IO/AppFlowy/blob/main/frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text)
90+
91+
### Customizing Shortcut Events
7992

80-
## More Examples
81-
* Customize a component
82-
* [Checkbox Text](https://github.com/AppFlowy-IO/AppFlowy/blob/main/frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text/checkbox_text.dart) shows you how to extend new styles based on existing rich text components
83-
* [Image](https://github.com/AppFlowy-IO/AppFlowy/blob/main/frontend/app_flowy/packages/appflowy_editor/example/lib/plugin/network_image_node_widget.dart) teaches you how to extend a new node and render it
84-
* And more examples on [rich-text plugins](https://github.com/AppFlowy-IO/AppFlowy/blob/main/frontend/app_flowy/packages/appflowy_editor/lib/src/render/rich_text)
85-
* Customize a shortcut event
86-
* [BIUS](https://github.com/AppFlowy-IO/AppFlowy/blob/main/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/update_text_style_by_command_x_handler.dart) shows you how to make text bold/italic/underline/strikethrough through shortcut keys
87-
* [Paste HTML](https://github.com/AppFlowy-IO/AppFlowy/blob/main/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/copy_paste_handler.dart) gives you an idea on how to handle pasted styles through shortcut keys
88-
* Need more examples? Check out [Internal key event handlers](https://github.com/AppFlowy-IO/AppFlowy/blob/main/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers)
93+
Please refer to our documentation on customizing AppFlowy for a detailed discussion about [customizing shortcut events](https://github.com/AppFlowy-IO/AppFlowy/blob/main/frontend/app_flowy/packages/appflowy_editor/documentation/customizing.md#customize-a-shortcut-event).
94+
95+
Below are some examples of shortcut event customizations:
96+
97+
* [BIUS](https://github.com/AppFlowy-IO/AppFlowy/blob/main/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/update_text_style_by_command_x_handler.dart) demonstrates how to make text bold/italic/underline/strikethrough through shortcut keys
98+
* [Paste HTML](https://github.com/AppFlowy-IO/AppFlowy/blob/main/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers/copy_paste_handler.dart) gives you an idea on how to handle pasted styles through shortcut keys
99+
* Need more examples? Check out [Internal key event handlers](https://github.com/AppFlowy-IO/AppFlowy/blob/main/frontend/app_flowy/packages/appflowy_editor/lib/src/service/internal_key_event_handlers)
89100

90101
## Glossary
91102
Please refer to the API documentation.
92103

93104
## Contributing
94-
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated. Please look at [CONTRIBUTING.md](https://appflowy.gitbook.io/docs/essential-documentation/contribute-to-appflowy/contributing-to-appflowy) for details.
105+
Contributions are what make the open source community such an amazing place to be learn, inspire, and create. Any contributions you make are greatly appreciated.
106+
107+
Please look at [CONTRIBUTING.md](https://appflowy.gitbook.io/docs/essential-documentation/contribute-to-appflowy/contributing-to-appflowy) for details.
95108

96109
## License
97-
Distributed under the AGPLv3 License. See LICENSE for more information.
110+
Distributed under the AGPLv3 License. See [LICENSE](https://github.com/AppFlowy-IO/AppFlowy-Docs/blob/main/LICENSE) for more information.

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

Lines changed: 35 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
# How to customize ...
1+
# Customizing Editor Features
22

3-
## Customize a shortcut event
3+
## Customizing a Shortcut Event
44

55
We will use a simple example to illustrate how to quickly add a shortcut event.
66

7-
For example, typing `_xxx_` will be converted into _xxx_.
7+
In this example, text that starts and ends with an underscore ( \_ ) character will be rendered in italics for emphasis. So typing `_xxx_` will automatically be converted into _xxx_.
88

9-
Let's start with a blank document.
9+
Let's start with a blank document:
1010

1111
```dart
1212
@override
@@ -27,31 +27,33 @@ At this point, nothing magic will happen after typing `_xxx_`.
2727

2828
![Before](./images/customizing_a_shortcut_event_before.gif)
2929

30-
Next, we will create a function to handle an underscore input.
30+
To implement our shortcut event we will create a function to handle an underscore input.
3131

3232
```dart
3333
import 'package:appflowy_editor/appflowy_editor.dart';
3434
import 'package:flutter/material.dart';
3535
import 'package:flutter/services.dart';
3636
3737
FlowyKeyEventHandler underscoreToItalicHandler = (editorState, event) {
38-
// Since we only need to handler the input of `underscore`.
39-
// All inputs except `underscore` will be ignored directly.
38+
// Since we only need to handle the input of an 'underscore' character,
39+
// all inputs except `underscore` will be ignored immediately.
4040
if (event.logicalKey != LogicalKeyboardKey.underscore) {
4141
return KeyEventResult.ignored;
4242
}
4343
};
4444
```
4545

46-
Then, we need to determine if the currently selected node is `TextNode` and the selection is collapsed.
46+
Then, we need to determine if the currently selected node is a `TextNode` and if the selection is collapsed.
47+
48+
If so, we will continue.
4749

4850
```dart
4951
// ...
5052
FlowyKeyEventHandler underscoreToItalicHandler = (editorState, event) {
5153
// ...
5254
53-
// Obtaining the selection and selected nodes of the current document through `selectionService`.
54-
// And determine whether the selection is collapsed and whether the selected node is a text node.
55+
// Obtain the selection and selected nodes of the current document through the 'selectionService'
56+
// to determine whether the selection is collapsed and whether the selected node is a text node.
5557
final selectionService = editorState.service.selectionService;
5658
final selection = selectionService.currentSelection.value;
5759
final textNodes = selectionService.currentSelectedNodes.whereType<TextNode>();
@@ -60,11 +62,11 @@ FlowyKeyEventHandler underscoreToItalicHandler = (editorState, event) {
6062
}
6163
```
6264

63-
Now, we start dealing with underscore.
65+
Now, we deal with handling the underscore.
6466

6567
Look for the position of the previous underscore and
66-
1. return, if not found.
67-
2. if found, the text wrapped in between two underscores will be displayed in italic.
68+
1. if one is _not_ found, return without doing anything.
69+
2. if one is found, the text enclosed within the two underscores will be formatted to display in italics.
6870

6971
```dart
7072
// ...
@@ -73,14 +75,14 @@ FlowyKeyEventHandler underscoreToItalicHandler = (editorState, event) {
7375
7476
final textNode = textNodes.first;
7577
final text = textNode.toRawString();
76-
// Determine if `underscore` already exists in the text node
78+
// Determine if an 'underscore' already exists in the text node
7779
final previousUnderscore = text.indexOf('_');
7880
if (previousUnderscore == -1) {
7981
return KeyEventResult.ignored;
8082
}
8183
82-
// Delete the previous `underscore`,
83-
// update the style of the text surrounded by two underscores to `italic`,
84+
// Delete the previous 'underscore',
85+
// update the style of the text surrounded by the two underscores to 'italic',
8486
// and update the cursor position.
8587
TransactionBuilder(editorState)
8688
..deleteText(textNode, previousUnderscore, 1)
@@ -99,7 +101,7 @@ FlowyKeyEventHandler underscoreToItalicHandler = (editorState, event) {
99101
};
100102
```
101103

102-
So far, the 'underscore handler' function is done and the only task left is to inject it into the AppFlowyEditor.
104+
Now our 'underscore handler' function is done and the only task left is to inject it into the AppFlowyEditor.
103105

104106
```dart
105107
@override
@@ -120,14 +122,15 @@ Widget build(BuildContext context) {
120122

121123
![After](./images/customizing_a_shortcut_event_after.gif)
122124

123-
[Complete code example]()
125+
Check out the [complete code](https://github.com/AppFlowy-IO/AppFlowy/blob/main/frontend/app_flowy/packages/appflowy_editor/example/lib/plugin/underscore_to_italic_key_event_handler.dart) file of this example.
126+
124127

125-
## Customize a component
126-
We will use a simple example to showcase how to quickly add a custom component.
128+
## Customizing a Component
129+
We will use a simple example to show how to quickly add a custom component.
127130

128-
For example, we want to render an image from the network.
131+
In this example we will render an image from the network.
129132

130-
To start with, let's create an empty document by running commands as follows:
133+
Let's start with a blank document:
131134

132135
```dart
133136
@override
@@ -144,9 +147,9 @@ Widget build(BuildContext context) {
144147
}
145148
```
146149

147-
Next, we choose a unique string for your custom node's type. We use `network_image` in this case. And we add `network_image_src` to the `attributes` to describe the link of the image.
150+
Next, we will choose a unique string for your custom node's type.
148151

149-
> For the definition of the [Node](), please refer to this [link]().
152+
We'll use `network_image` in this case. And we add `network_image_src` to the `attributes` to describe the link of the image.
150153

151154
```JSON
152155
{
@@ -157,9 +160,9 @@ Next, we choose a unique string for your custom node's type. We use `network_ima
157160
}
158161
```
159162

160-
Then, we create a class that inherits [NodeWidgetBuilder](). As shown in the autoprompt, we need to implement two functions:
163+
Then, we create a class that inherits [NodeWidgetBuilder](../lib/src/service/render_plugin_service.dart). As shown in the autoprompt, we need to implement two functions:
161164
1. one returns a widget
162-
2. the other verifies the correctness of the [Node]().
165+
2. the other verifies the correctness of the [Node](../lib/src/document/node.dart).
163166

164167

165168
```dart
@@ -179,9 +182,7 @@ class NetworkImageNodeWidgetBuilder extends NodeWidgetBuilder {
179182

180183
Now, let's implement a simple image widget based on `Image`.
181184

182-
**It is important to note that the `State` of the returned `Widget` must be with [Selectable]().**
183-
184-
> For the definition of the [Selectable](), please refer to this [link]().
185+
Note that the `State` object that is returned by the `Widget` must implement [Selectable](../lib/src/render/selection/selectable.dart) using the `with` keyword.
185186

186187
```dart
187188
class _NetworkImageNodeWidget extends StatefulWidget {
@@ -236,7 +237,7 @@ class __NetworkImageNodeWidgetState extends State<_NetworkImageNodeWidget>
236237
}
237238
```
238239

239-
Finally, we return `_NetworkImageNodeWidget` in the `build` function of `NetworkImageNodeWidgetBuilder` and register `NetworkImageNodeWidgetBuilder` into `AppFlowyEditor`.
240+
Finally, we return `_NetworkImageNodeWidget` in the `build` function of `NetworkImageNodeWidgetBuilder`...
240241

241242
```dart
242243
class NetworkImageNodeWidgetBuilder extends NodeWidgetBuilder {
@@ -256,6 +257,8 @@ class NetworkImageNodeWidgetBuilder extends NodeWidgetBuilder {
256257
}
257258
```
258259

260+
... and register `NetworkImageNodeWidgetBuilder` in the `AppFlowyEditor`.
261+
259262
```dart
260263
final editorState = EditorState(
261264
document: StateTree.empty()
@@ -281,6 +284,6 @@ return AppFlowyEditor(
281284
);
282285
```
283286

284-
![](./images/customizing_a_component.gif)
287+
![Whew!](./images/customizing_a_component.gif)
285288

286-
[Here you can check out the complete code file of this example]()
289+
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.

0 commit comments

Comments
 (0)