Skip to content

Commit 50f9ac1

Browse files
committed
feat: #1649 add document for importing data
1 parent 2fb0e8d commit 50f9ac1

File tree

2 files changed

+44
-8
lines changed

2 files changed

+44
-8
lines changed

frontend/app_flowy/packages/appflowy_editor/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
1-
<!--
1+
<!--
22
This README describes the package. If you publish this package to pub.dev,
33
this README's contents appear on the landing page for your package.
44
55
For information about how to write a good package README, see the guide for
6-
[writing package pages](https://dart.dev/guides/libraries/writing-package-pages).
6+
[writing package pages](https://dart.dev/guides/libraries/writing-package-pages).
77
88
For general information about developing packages, see the Dart guide for
99
[creating packages](https://dart.dev/guides/libraries/create-library-packages)
1010
and the Flutter guide for
11-
[developing packages and plugins](https://flutter.dev/developing-packages).
11+
[developing packages and plugins](https://flutter.dev/developing-packages).
1212
-->
1313

1414
<h1 align="center"><b>AppFlowy Editor</b></h1>
@@ -51,7 +51,7 @@ flutter pub get
5151

5252
## Creating Your First Editor
5353

54-
Start by creating a new empty AppFlowyEditor object.
54+
Start by creating a new empty AppFlowyEditor object.
5555

5656
```dart
5757
final editorState = EditorState.empty(); // an empty state
@@ -60,7 +60,7 @@ final editor = AppFlowyEditor(
6060
);
6161
```
6262

63-
You can also create an editor from a JSON object in order to configure your initial state.
63+
You can also create an editor from a JSON object in order to configure your initial state. Or you can [create an editor from Markdown or Quill Delta](https://github.com/AppFlowy-IO/AppFlowy/blob/main/frontend/app_flowy/packages/appflowy_editor/documentation/importing.md).
6464

6565
```dart
6666
final json = ...;
@@ -79,7 +79,7 @@ MaterialApp(
7979
);
8080
```
8181

82-
To get a sense for how the AppFlowy Editor works, run our example:
82+
To get a sense of how the AppFlowy Editor works, run our example:
8383

8484
```shell
8585
git clone https://github.com/AppFlowy-IO/AppFlowy.git
@@ -98,7 +98,7 @@ Below are some examples of component customizations:
9898
* [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
9999
* [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
100100
* 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)
101-
101+
102102
### Customizing Shortcut Events
103103

104104
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).
@@ -113,7 +113,7 @@ Below are some examples of shortcut event customizations:
113113
Please refer to the API documentation.
114114

115115
## Contributing
116-
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
116+
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
117117

118118
Please look at [CONTRIBUTING.md](https://appflowy.gitbook.io/docs/essential-documentation/contribute-to-appflowy/contributing-to-appflowy) for details.
119119

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
# Importing data
2+
3+
For now, we have supported three ways to import data to initialize AppFlowy Editor.
4+
5+
1. From AppFlowy Document JSON
6+
7+
```dart
8+
const document = r'''{"document":{"type":"editor","children":[{"type":"text","attributes":{"subtype":"heading","heading":"h1"},"delta":[{"insert":"Hello AppFlowy!"}]}]}}''';
9+
final json = jsonDecode(document);
10+
final editorState = EditorState(
11+
document: Document.fromJson(
12+
Map<String, Object>.from(json),
13+
),
14+
);
15+
```
16+
17+
2. From Markdown
18+
19+
```dart
20+
const markdown = r'''# Hello AppFlowy!''';
21+
final editorState = EditorState(
22+
document: markdownToDocument(markdown),
23+
);
24+
```
25+
26+
3. From Quill Delta
27+
28+
```dart
29+
const delta = r'''[{"insert":"Hello AppFlowy!"},{"attributes":{"header":1},"insert":"\n"}]''';
30+
final json = jsonDecode(delta);
31+
final editorState = EditorState(
32+
document: DeltaDocumentConvert().convertFromJSON(json),
33+
);
34+
```
35+
36+
For more details, please refer to the function `_importFile` through this [link](https://github.com/AppFlowy-IO/AppFlowy/blob/main/frontend/app_flowy/packages/appflowy_editor/example/lib/home_page.dart).

0 commit comments

Comments
 (0)