Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
feat: implemnt export editor state
Lucas.Xu778b55d44e75
diff --git a/frontend/app_flowy/packages/appflowy_editor/example/lib/main.dart b/frontend/app_flowy/packages/appflowy_editor/example/lib/main.dartindex 539bb74425..e5aae9432d 100644--- a/frontend/app_flowy/packages/appflowy_editor/example/lib/main.dart+++ b/frontend/app_flowy/packages/appflowy_editor/example/lib/main.dart@@ -1,4 +1,5 @@import 'dart:convert';+import 'dart:io';import 'package:flutter/material.dart';import 'package:flutter/services.dart';@@ -8,6 +9,7 @@ import 'expandable_floating_action_button.dart';import 'plugin/youtube_link_node_widget.dart';import 'package:appflowy_editor/appflowy_editor.dart';+import 'package:path_provider/path_provider.dart';void main() {runApp(const MyApp());@@ -58,6 +60,7 @@ class MyHomePage extends StatefulWidget {class _MyHomePageState extends State<MyHomePage> {final editorKey = GlobalKey();int page = 0;+ EditorState? _editorState;@overrideWidget build(BuildContext context) {@@ -103,6 +106,7 @@ class _MyHomePageState extends State<MyHomePage> {..handler = (message) {debugPrint(message);};+ _editorState = editorState;return _buildAppFlowyEditor(editorState);} else {return const Center(@@ -146,6 +150,21 @@ class _MyHomePageState extends State<MyHomePage> {);}+ void _exportDocument(EditorState editorState) async {+ // await FileSaver.instance.saveAs(String name, Uint8List bytes, String ext, MimeType);+ final document = editorState.document.toJson();+ debugPrint(document.toString());+ final json = jsonEncode(document);+ debugPrint(json);++ final directory = await getTemporaryDirectory();+ final path = directory.path;+ debugPrint(path);++ final file = File('$path/temp.json');+ await file.writeAsString(json);+ }+Widget _buildExpandableFab() {return ExpandableFab(distance: 112.0,@@ -177,6 +196,12 @@ class _MyHomePageState extends State<MyHomePage> {},icon: const Icon(Icons.text_fields),),+ ActionButton(+ onPressed: () {+ _exportDocument(_editorState!);+ },+ icon: const Icon(Icons.print),+ ),],);}diff --git a/frontend/app_flowy/packages/appflowy_editor/example/linux/flutter/generated_plugin_registrant.cc b/frontend/app_flowy/packages/appflowy_editor/example/linux/flutter/generated_plugin_registrant.ccindex 00fd3bc03f..45a19e066d 100644--- a/frontend/app_flowy/packages/appflowy_editor/example/linux/flutter/generated_plugin_registrant.cc+++ b/frontend/app_flowy/packages/appflowy_editor/example/linux/flutter/generated_plugin_registrant.cc@@ -6,10 +6,14 @@#include "generated_plugin_registrant.h"+#include <file_saver/file_saver_plugin.h>#include <rich_clipboard_linux/rich_clipboard_plugin.h>#include <url_launcher_linux/url_launcher_plugin.h>void fl_register_plugins(FlPluginRegistry* registry) {+ g_autoptr(FlPluginRegistrar) file_saver_registrar =+ fl_plugin_registry_get_registrar_for_plugin(registry, "FileSaverPlugin");+ file_saver_plugin_register_with_registrar(file_saver_registrar);g_autoptr(FlPluginRegistrar) rich_clipboard_linux_registrar =fl_plugin_registry_get_registrar_for_plugin(registry, "RichClipboardPlugin");rich_clipboard_plugin_register_with_registrar(rich_clipboard_linux_registrar);diff --git a/frontend/app_flowy/packages/appflowy_editor/example/linux/flutter/generated_plugins.cmake b/frontend/app_flowy/packages/appflowy_editor/example/linux/flutter/generated_plugins.cmakeindex 0342e3868a..10140a75b4 100644--- a/frontend/app_flowy/packages/appflowy_editor/example/linux/flutter/generated_plugins.cmake+++ b/frontend/app_flowy/packages/appflowy_editor/example/linux/flutter/generated_plugins.cmake@@ -3,6 +3,7 @@#list(APPEND FLUTTER_PLUGIN_LIST+ file_saverrich_clipboard_linuxurl_launcher_linux)diff --git a/frontend/app_flowy/packages/appflowy_editor/example/macos/Flutter/GeneratedPluginRegistrant.swift b/frontend/app_flowy/packages/appflowy_editor/example/macos/Flutter/GeneratedPluginRegistrant.swiftindex cc167443dc..ac60ac6ec9 100644--- a/frontend/app_flowy/packages/appflowy_editor/example/macos/Flutter/GeneratedPluginRegistrant.swift+++ b/frontend/app_flowy/packages/appflowy_editor/example/macos/Flutter/GeneratedPluginRegistrant.swift@@ -5,11 +5,15 @@import FlutterMacOSimport Foundation+import file_saver+import path_provider_macosimport rich_clipboard_macosimport url_launcher_macosimport wakelock_macosfunc RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {+ FileSaverPlugin.register(with: registry.registrar(forPlugin: "FileSaverPlugin"))+ PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin"))RichClipboardPlugin.register(with: registry.registrar(forPlugin: "RichClipboardPlugin"))UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))WakelockMacosPlugin.register(with: registry.registrar(forPlugin: "WakelockMacosPlugin"))diff --git a/frontend/app_flowy/packages/appflowy_editor/example/macos/Podfile.lock b/frontend/app_flowy/packages/appflowy_editor/example/macos/Podfile.lockindex d3a1dd3611..c56e297a68 100644--- a/frontend/app_flowy/packages/appflowy_editor/example/macos/Podfile.lock+++ b/frontend/app_flowy/packages/appflowy_editor/example/macos/Podfile.lock@@ -1,5 +1,9 @@PODS:+ - file_saver (0.0.1):+ - FlutterMacOS- FlutterMacOS (1.0.0)+ - path_provider_macos (0.0.1):+ - FlutterMacOS- rich_clipboard_macos (0.0.1):- FlutterMacOS- url_launcher_macos (0.0.1):@@ -8,14 +12,20 @@ PODS:- FlutterMacOSDEPENDENCIES:+ - file_saver (from `Flutter/ephemeral/.symlinks/plugins/file_saver/macos`)- FlutterMacOS (from `Flutter/ephemeral`)+ - path_provider_macos (from `Flutter/ephemeral/.symlinks/plugins/path_provider_macos/macos`)- rich_clipboard_macos (from `Flutter/ephemeral/.symlinks/plugins/rich_clipboard_macos/macos`)- url_launcher_macos (from `Flutter/ephemeral/.symlinks/plugins/url_launcher_macos/macos`)- wakelock_macos (from `Flutter/ephemeral/.symlinks/plugins/wakelock_macos/macos`)EXTERNAL SOURCES:+ file_saver:+ :path: Flutter/ephemeral/.symlinks/plugins/file_saver/macosFlutterMacOS::path: Flutter/ephemeral+ path_provider_macos:+ :path: Flutter/ephemeral/.symlinks/plugins/path_provider_macos/macosrich_clipboard_macos::path: Flutter/ephemeral/.symlinks/plugins/rich_clipboard_macos/macosurl_launcher_macos:@@ -24,7 +34,9 @@ EXTERNAL SOURCES::path: Flutter/ephemeral/.symlinks/plugins/wakelock_macos/macosSPEC CHECKSUMS:+ file_saver: 44e6fbf666677faf097302460e214e977fdd977bFlutterMacOS: 57701585bf7de1b3fc2bb61f6378d73bbdea8424+ path_provider_macos: 3c0c3b4b0d4a76d2bf989a913c2de869c5641a19rich_clipboard_macos: 43364b66b9dc69d203eb8dd6d758e2d12e02723curl_launcher_macos: 597e05b8e514239626bcf4a850fcf9ef5c856ec3wakelock_macos: bc3f2a9bd8d2e6c89fee1e1822e7ddac3bd004a9diff --git a/frontend/app_flowy/packages/appflowy_editor/example/pubspec.yaml b/frontend/app_flowy/packages/appflowy_editor/example/pubspec.yamlindex 4e2e2d68ab..593d9ff45f 100644--- a/frontend/app_flowy/packages/appflowy_editor/example/pubspec.yaml+++ b/frontend/app_flowy/packages/appflowy_editor/example/pubspec.yaml@@ -40,6 +40,7 @@ dependencies:video_player: ^2.4.5pod_player: 0.0.8flutter_inappwebview: ^5.4.3+7+ file_saver: ^0.1.1dev_dependencies:flutter_test:diff --git a/frontend/app_flowy/packages/appflowy_editor/example/windows/flutter/generated_plugin_registrant.cc b/frontend/app_flowy/packages/appflowy_editor/example/windows/flutter/generated_plugin_registrant.ccindex 4f7884874d..391ef56268 100644--- a/frontend/app_flowy/packages/appflowy_editor/example/windows/flutter/generated_plugin_registrant.cc+++ b/frontend/app_flowy/packages/appflowy_editor/example/windows/flutter/generated_plugin_registrant.cc@@ -6,9 +6,12 @@#include "generated_plugin_registrant.h"+#include <file_saver/file_saver_plugin.h>#include <url_launcher_windows/url_launcher_windows.h>void RegisterPlugins(flutter::PluginRegistry* registry) {+ FileSaverPluginRegisterWithRegistrar(+ registry->GetRegistrarForPlugin("FileSaverPlugin"));UrlLauncherWindowsRegisterWithRegistrar(registry->GetRegistrarForPlugin("UrlLauncherWindows"));}diff --git a/frontend/app_flowy/packages/appflowy_editor/example/windows/flutter/generated_plugins.cmake b/frontend/app_flowy/packages/appflowy_editor/example/windows/flutter/generated_plugins.cmakeindex 88b22e5c77..047111654d 100644--- a/frontend/app_flowy/packages/appflowy_editor/example/windows/flutter/generated_plugins.cmake+++ b/frontend/app_flowy/packages/appflowy_editor/example/windows/flutter/generated_plugins.cmake@@ -3,6 +3,7 @@#list(APPEND FLUTTER_PLUGIN_LIST+ file_saverurl_launcher_windows)diff --git a/frontend/app_flowy/packages/appflowy_editor/lib/src/document/node.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/document/node.dartindex a0c4e33a70..909e7dd494 100644--- a/frontend/app_flowy/packages/appflowy_editor/lib/src/document/node.dart+++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/document/node.dart@@ -163,7 +163,8 @@ class Node extends ChangeNotifier with LinkedListEntry<Node> {'type': type,};if (children.isNotEmpty) {- map['children'] = children.map((node) => node.toJson());+ map['children'] =+ (children.map((node) => node.toJson())).toList(growable: false);}if (_attributes.isNotEmpty) {map['attributes'] = _attributes;diff --git a/frontend/app_flowy/packages/appflowy_editor/lib/src/document/state_tree.dart b/frontend/app_flowy/packages/appflowy_editor/lib/src/document/state_tree.dartindex 5bf49c0048..a17b2fbf98 100644--- a/frontend/app_flowy/packages/appflowy_editor/lib/src/document/state_tree.dart+++ b/frontend/app_flowy/packages/appflowy_editor/lib/src/document/state_tree.dart@@ -33,6 +33,12 @@ class StateTree {return StateTree(root: root);}+ Map<String, Object> toJson() {+ return {+ 'document': root.toJson(),+ };+ }+Node? nodeAtPath(Path path) {return root.childAtPath(path);}