Просмотр исходного кода

create local file when create view with type doc

appflowy 3 лет назад
Родитель
Сommit
af1c35de45
24 измененных файлов с 391 добавлено и 194 удалено
  1. 10 0
      app_flowy/lib/workspace/domain/i_doc.dart
  2. 0 5
      app_flowy/lib/workspace/domain/i_page_stack.dart
  3. 18 2
      app_flowy/lib/workspace/infrastructure/i_app_impl.dart
  4. 32 0
      app_flowy/lib/workspace/infrastructure/repos/doc_repo.dart
  5. 67 16
      app_flowy/packages/flowy_sdk/lib/dispatch/code_gen.dart
  6. 1 0
      app_flowy/packages/flowy_sdk/lib/dispatch/dispatch.dart
  7. 22 8
      app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_create.pb.dart
  8. 4 3
      app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_create.pbjson.dart
  9. 15 15
      app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_modify.pb.dart
  10. 3 3
      app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_modify.pbjson.dart
  11. 1 0
      rust-lib/flowy-editor/Cargo.toml
  12. 6 1
      rust-lib/flowy-editor/src/entities/doc/doc_create.rs
  13. 3 3
      rust-lib/flowy-editor/src/entities/doc/doc_modify.rs
  14. 14 13
      rust-lib/flowy-editor/src/handlers/doc_handler.rs
  15. 102 57
      rust-lib/flowy-editor/src/protobuf/model/doc_create.rs
  16. 52 52
      rust-lib/flowy-editor/src/protobuf/model/doc_modify.rs
  17. 2 1
      rust-lib/flowy-editor/src/protobuf/proto/doc_create.proto
  18. 1 1
      rust-lib/flowy-editor/src/protobuf/proto/doc_modify.proto
  19. 7 3
      rust-lib/flowy-editor/src/services/file_manager/manager.rs
  20. 9 5
      rust-lib/flowy-editor/tests/editor/doc_test.rs
  21. 3 2
      rust-lib/flowy-editor/tests/editor/helper.rs
  22. 4 0
      scripts/flowy-tool/src/dart_event/dart_event.rs
  23. 8 2
      scripts/flowy-tool/src/dart_event/event_template.rs
  24. 7 2
      scripts/flowy-tool/src/dart_event/event_template.tera

+ 10 - 0
app_flowy/lib/workspace/domain/i_doc.dart

@@ -0,0 +1,10 @@
+import 'package:flowy_sdk/protobuf/flowy-editor/doc_create.pb.dart';
+import 'package:dartz/dartz.dart';
+import 'package:flowy_sdk/protobuf/flowy-editor/errors.pb.dart';
+
+abstract class IDoc {
+  Future<Either<DocDescription, EditorError>> createDoc();
+  Future<Either<Doc, EditorError>> readDoc();
+  Future<Either<Unit, EditorError>> updateDoc();
+  Future<Either<Unit, EditorError>> closeDoc();
+}

+ 0 - 5
app_flowy/lib/workspace/domain/i_page_stack.dart

@@ -1,5 +0,0 @@
-import 'package:app_flowy/workspace/domain/page_stack/page_stack.dart';
-
-abstract class IPageStack {
-  void setPageContext(HomeStackView context);
-}

+ 18 - 2
app_flowy/lib/workspace/infrastructure/i_app_impl.dart

@@ -1,9 +1,9 @@
 import 'package:app_flowy/workspace/infrastructure/repos/app_repo.dart';
+import 'package:app_flowy/workspace/infrastructure/repos/doc_repo.dart';
 import 'package:dartz/dartz.dart';
 import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart';
 import 'package:app_flowy/workspace/domain/i_app.dart';
 import 'package:flowy_sdk/protobuf/flowy-workspace/view_create.pb.dart';
-
 export 'package:app_flowy/workspace/domain/i_app.dart';
 
 class IAppImpl extends IApp {
@@ -20,7 +20,23 @@ class IAppImpl extends IApp {
   @override
   Future<Either<View, WorkspaceError>> createView(
       {required String name, String? desc, required ViewType viewType}) {
-    return repo.createView(name, desc ?? "", viewType);
+    return repo.createView(name, desc ?? "", viewType).then((result) {
+      return result.fold(
+        (view) => _createDoc(view),
+        (r) => right(r),
+      );
+    });
+  }
+
+  Future<Either<View, WorkspaceError>> _createDoc(View view) async {
+    switch (view.viewType) {
+      case ViewType.Doc:
+        final docRepo = DocRepository(docId: view.id);
+        final result = await docRepo.createDoc(name: view.name, desc: "");
+        return result.fold((l) => left(view), (r) => left(view));
+      default:
+        return left(view);
+    }
   }
 }
 

+ 32 - 0
app_flowy/lib/workspace/infrastructure/repos/doc_repo.dart

@@ -0,0 +1,32 @@
+import 'package:dartz/dartz.dart';
+import 'package:flowy_sdk/dispatch/dispatch.dart';
+import 'package:flowy_sdk/protobuf/flowy-editor/doc_create.pb.dart';
+import 'package:flowy_sdk/protobuf/flowy-editor/doc_modify.pb.dart';
+import 'package:flowy_sdk/protobuf/flowy-editor/doc_query.pb.dart';
+import 'package:flowy_sdk/protobuf/flowy-editor/errors.pb.dart';
+
+class DocRepository {
+  final String docId;
+  DocRepository({
+    required this.docId,
+  });
+
+  Future<Either<DocDescription, EditorError>> createDoc(
+      {required String name, String? desc}) {
+    final request = CreateDocRequest(id: docId, name: name, desc: desc);
+
+    return EditorEventCreateDoc(request).send();
+  }
+
+  Future<Either<Doc, EditorError>> readDoc() {
+    final request = QueryDocRequest.create()..docId = docId;
+    return EditorEventReadDoc(request).send();
+  }
+
+  Future<Either<Unit, EditorError>> updateDoc(
+      {String? name, String? desc, String? text}) {
+    final request = UpdateDocRequest(id: docId, name: name, text: text);
+
+    return EditorEventUpdateDoc(request).send();
+  }
+}

+ 67 - 16
app_flowy/packages/flowy_sdk/lib/dispatch/code_gen.dart

@@ -2,6 +2,57 @@
 
 /// Auto gen code from rust ast, do not edit
 part of 'dispatch.dart';
+class EditorEventCreateDoc {
+     CreateDocRequest request;
+     EditorEventCreateDoc(this.request);
+
+    Future<Either<DocDescription, EditorError>> send() {
+    final request = FFIRequest.create()
+          ..event = EditorEvent.CreateDoc.toString()
+          ..payload = requestToBytes(this.request);
+
+    return Dispatch.asyncRequest(request)
+        .then((bytesResult) => bytesResult.fold(
+           (okBytes) => left(DocDescription.fromBuffer(okBytes)),
+           (errBytes) => right(EditorError.fromBuffer(errBytes)),
+        ));
+    }
+}
+
+class EditorEventUpdateDoc {
+     UpdateDocRequest request;
+     EditorEventUpdateDoc(this.request);
+
+    Future<Either<Unit, EditorError>> send() {
+    final request = FFIRequest.create()
+          ..event = EditorEvent.UpdateDoc.toString()
+          ..payload = requestToBytes(this.request);
+
+    return Dispatch.asyncRequest(request)
+        .then((bytesResult) => bytesResult.fold(
+           (bytes) => left(unit),
+           (errBytes) => right(EditorError.fromBuffer(errBytes)),
+        ));
+    }
+}
+
+class EditorEventReadDoc {
+     QueryDocRequest request;
+     EditorEventReadDoc(this.request);
+
+    Future<Either<Doc, EditorError>> send() {
+    final request = FFIRequest.create()
+          ..event = EditorEvent.ReadDoc.toString()
+          ..payload = requestToBytes(this.request);
+
+    return Dispatch.asyncRequest(request)
+        .then((bytesResult) => bytesResult.fold(
+           (okBytes) => left(Doc.fromBuffer(okBytes)),
+           (errBytes) => right(EditorError.fromBuffer(errBytes)),
+        ));
+    }
+}
+
 class WorkspaceEventCreateWorkspace {
      CreateWorkspaceRequest request;
      WorkspaceEventCreateWorkspace(this.request);
@@ -13,8 +64,8 @@ class WorkspaceEventCreateWorkspace {
 
     return Dispatch.asyncRequest(request)
         .then((bytesResult) => bytesResult.fold(
-          (okBytes) => left(Workspace.fromBuffer(okBytes)),
-          (errBytes) => right(WorkspaceError.fromBuffer(errBytes)),
+           (okBytes) => left(Workspace.fromBuffer(okBytes)),
+           (errBytes) => right(WorkspaceError.fromBuffer(errBytes)),
         ));
     }
 }
@@ -44,8 +95,8 @@ class WorkspaceEventGetWorkspace {
 
     return Dispatch.asyncRequest(request)
         .then((bytesResult) => bytesResult.fold(
-          (okBytes) => left(Workspace.fromBuffer(okBytes)),
-          (errBytes) => right(WorkspaceError.fromBuffer(errBytes)),
+           (okBytes) => left(Workspace.fromBuffer(okBytes)),
+           (errBytes) => right(WorkspaceError.fromBuffer(errBytes)),
         ));
     }
 }
@@ -61,8 +112,8 @@ class WorkspaceEventCreateApp {
 
     return Dispatch.asyncRequest(request)
         .then((bytesResult) => bytesResult.fold(
-          (okBytes) => left(App.fromBuffer(okBytes)),
-          (errBytes) => right(WorkspaceError.fromBuffer(errBytes)),
+           (okBytes) => left(App.fromBuffer(okBytes)),
+           (errBytes) => right(WorkspaceError.fromBuffer(errBytes)),
         ));
     }
 }
@@ -78,8 +129,8 @@ class WorkspaceEventGetApp {
 
     return Dispatch.asyncRequest(request)
         .then((bytesResult) => bytesResult.fold(
-          (okBytes) => left(App.fromBuffer(okBytes)),
-          (errBytes) => right(WorkspaceError.fromBuffer(errBytes)),
+           (okBytes) => left(App.fromBuffer(okBytes)),
+           (errBytes) => right(WorkspaceError.fromBuffer(errBytes)),
         ));
     }
 }
@@ -95,8 +146,8 @@ class WorkspaceEventCreateView {
 
     return Dispatch.asyncRequest(request)
         .then((bytesResult) => bytesResult.fold(
-          (okBytes) => left(View.fromBuffer(okBytes)),
-          (errBytes) => right(WorkspaceError.fromBuffer(errBytes)),
+           (okBytes) => left(View.fromBuffer(okBytes)),
+           (errBytes) => right(WorkspaceError.fromBuffer(errBytes)),
         ));
     }
 }
@@ -126,8 +177,8 @@ class UserEventSignIn {
 
     return Dispatch.asyncRequest(request)
         .then((bytesResult) => bytesResult.fold(
-          (okBytes) => left(UserDetail.fromBuffer(okBytes)),
-          (errBytes) => right(UserError.fromBuffer(errBytes)),
+           (okBytes) => left(UserDetail.fromBuffer(okBytes)),
+           (errBytes) => right(UserError.fromBuffer(errBytes)),
         ));
     }
 }
@@ -143,8 +194,8 @@ class UserEventSignUp {
 
     return Dispatch.asyncRequest(request)
         .then((bytesResult) => bytesResult.fold(
-          (okBytes) => left(UserDetail.fromBuffer(okBytes)),
-          (errBytes) => right(UserError.fromBuffer(errBytes)),
+           (okBytes) => left(UserDetail.fromBuffer(okBytes)),
+           (errBytes) => right(UserError.fromBuffer(errBytes)),
         ));
     }
 }
@@ -174,8 +225,8 @@ class UserEventUpdateUser {
 
     return Dispatch.asyncRequest(request)
         .then((bytesResult) => bytesResult.fold(
-          (okBytes) => left(UserDetail.fromBuffer(okBytes)),
-          (errBytes) => right(UserError.fromBuffer(errBytes)),
+           (okBytes) => left(UserDetail.fromBuffer(okBytes)),
+           (errBytes) => right(UserError.fromBuffer(errBytes)),
         ));
     }
 }

+ 1 - 0
app_flowy/packages/flowy_sdk/lib/dispatch/dispatch.dart

@@ -13,6 +13,7 @@ import 'package:flowy_sdk/ffi.dart' as ffi;
 import 'package:flowy_sdk/protobuf/flowy-user/protobuf.dart';
 import 'package:flowy_sdk/protobuf/dart-ffi/protobuf.dart';
 import 'package:flowy_sdk/protobuf/flowy-workspace/protobuf.dart';
+import 'package:flowy_sdk/protobuf/flowy-editor/protobuf.dart';
 // ignore: unused_import
 import 'package:flowy_sdk/protobuf/flowy-infra/protobuf.dart';
 import 'package:protobuf/protobuf.dart';

+ 22 - 8
app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_create.pb.dart

@@ -14,6 +14,7 @@ class CreateDocRequest extends $pb.GeneratedMessage {
     ..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'id')
     ..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'name')
     ..aOS(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'desc')
+    ..aOS(4, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'text')
     ..hasRequiredFields = false
   ;
 
@@ -22,6 +23,7 @@ class CreateDocRequest extends $pb.GeneratedMessage {
     $core.String? id,
     $core.String? name,
     $core.String? desc,
+    $core.String? text,
   }) {
     final _result = create();
     if (id != null) {
@@ -33,6 +35,9 @@ class CreateDocRequest extends $pb.GeneratedMessage {
     if (desc != null) {
       _result.desc = desc;
     }
+    if (text != null) {
+      _result.text = text;
+    }
     return _result;
   }
   factory CreateDocRequest.fromBuffer($core.List<$core.int> i, [$pb.ExtensionRegistry r = $pb.ExtensionRegistry.EMPTY]) => create()..mergeFromBuffer(i, r);
@@ -82,6 +87,15 @@ class CreateDocRequest extends $pb.GeneratedMessage {
   $core.bool hasDesc() => $_has(2);
   @$pb.TagNumber(3)
   void clearDesc() => clearField(3);
+
+  @$pb.TagNumber(4)
+  $core.String get text => $_getSZ(3);
+  @$pb.TagNumber(4)
+  set text($core.String v) { $_setString(3, v); }
+  @$pb.TagNumber(4)
+  $core.bool hasText() => $_has(3);
+  @$pb.TagNumber(4)
+  void clearText() => clearField(4);
 }
 
 class DocDescription extends $pb.GeneratedMessage {
@@ -176,21 +190,21 @@ class DocDescription extends $pb.GeneratedMessage {
 class Doc extends $pb.GeneratedMessage {
   static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'Doc', createEmptyInstance: create)
     ..aOM<DocDescription>(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'desc', subBuilder: DocDescription.create)
-    ..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'content')
+    ..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'text')
     ..hasRequiredFields = false
   ;
 
   Doc._() : super();
   factory Doc({
     DocDescription? desc,
-    $core.String? content,
+    $core.String? text,
   }) {
     final _result = create();
     if (desc != null) {
       _result.desc = desc;
     }
-    if (content != null) {
-      _result.content = content;
+    if (text != null) {
+      _result.text = text;
     }
     return _result;
   }
@@ -227,12 +241,12 @@ class Doc extends $pb.GeneratedMessage {
   DocDescription ensureDesc() => $_ensure(0);
 
   @$pb.TagNumber(2)
-  $core.String get content => $_getSZ(1);
+  $core.String get text => $_getSZ(1);
   @$pb.TagNumber(2)
-  set content($core.String v) { $_setString(1, v); }
+  set text($core.String v) { $_setString(1, v); }
   @$pb.TagNumber(2)
-  $core.bool hasContent() => $_has(1);
+  $core.bool hasText() => $_has(1);
   @$pb.TagNumber(2)
-  void clearContent() => clearField(2);
+  void clearText() => clearField(2);
 }
 

+ 4 - 3
app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_create.pbjson.dart

@@ -15,11 +15,12 @@ const CreateDocRequest$json = const {
     const {'1': 'id', '3': 1, '4': 1, '5': 9, '10': 'id'},
     const {'1': 'name', '3': 2, '4': 1, '5': 9, '10': 'name'},
     const {'1': 'desc', '3': 3, '4': 1, '5': 9, '10': 'desc'},
+    const {'1': 'text', '3': 4, '4': 1, '5': 9, '10': 'text'},
   ],
 };
 
 /// Descriptor for `CreateDocRequest`. Decode as a `google.protobuf.DescriptorProto`.
-final $typed_data.Uint8List createDocRequestDescriptor = $convert.base64Decode('ChBDcmVhdGVEb2NSZXF1ZXN0Eg4KAmlkGAEgASgJUgJpZBISCgRuYW1lGAIgASgJUgRuYW1lEhIKBGRlc2MYAyABKAlSBGRlc2M=');
+final $typed_data.Uint8List createDocRequestDescriptor = $convert.base64Decode('ChBDcmVhdGVEb2NSZXF1ZXN0Eg4KAmlkGAEgASgJUgJpZBISCgRuYW1lGAIgASgJUgRuYW1lEhIKBGRlc2MYAyABKAlSBGRlc2MSEgoEdGV4dBgEIAEoCVIEdGV4dA==');
 @$core.Deprecated('Use docDescriptionDescriptor instead')
 const DocDescription$json = const {
   '1': 'DocDescription',
@@ -38,9 +39,9 @@ const Doc$json = const {
   '1': 'Doc',
   '2': const [
     const {'1': 'desc', '3': 1, '4': 1, '5': 11, '6': '.DocDescription', '10': 'desc'},
-    const {'1': 'content', '3': 2, '4': 1, '5': 9, '10': 'content'},
+    const {'1': 'text', '3': 2, '4': 1, '5': 9, '10': 'text'},
   ],
 };
 
 /// Descriptor for `Doc`. Decode as a `google.protobuf.DescriptorProto`.
-final $typed_data.Uint8List docDescriptor = $convert.base64Decode('CgNEb2MSIwoEZGVzYxgBIAEoCzIPLkRvY0Rlc2NyaXB0aW9uUgRkZXNjEhgKB2NvbnRlbnQYAiABKAlSB2NvbnRlbnQ=');
+final $typed_data.Uint8List docDescriptor = $convert.base64Decode('CgNEb2MSIwoEZGVzYxgBIAEoCzIPLkRvY0Rlc2NyaXB0aW9uUgRkZXNjEhIKBHRleHQYAiABKAlSBHRleHQ=');

+ 15 - 15
app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_modify.pb.dart

@@ -19,8 +19,8 @@ enum UpdateDocRequest_OneOfDesc {
   notSet
 }
 
-enum UpdateDocRequest_OneOfContent {
-  content, 
+enum UpdateDocRequest_OneOfText {
+  text, 
   notSet
 }
 
@@ -33,9 +33,9 @@ class UpdateDocRequest extends $pb.GeneratedMessage {
     3 : UpdateDocRequest_OneOfDesc.desc,
     0 : UpdateDocRequest_OneOfDesc.notSet
   };
-  static const $core.Map<$core.int, UpdateDocRequest_OneOfContent> _UpdateDocRequest_OneOfContentByTag = {
-    4 : UpdateDocRequest_OneOfContent.content,
-    0 : UpdateDocRequest_OneOfContent.notSet
+  static const $core.Map<$core.int, UpdateDocRequest_OneOfText> _UpdateDocRequest_OneOfTextByTag = {
+    4 : UpdateDocRequest_OneOfText.text,
+    0 : UpdateDocRequest_OneOfText.notSet
   };
   static final $pb.BuilderInfo _i = $pb.BuilderInfo(const $core.bool.fromEnvironment('protobuf.omit_message_names') ? '' : 'UpdateDocRequest', createEmptyInstance: create)
     ..oo(0, [2])
@@ -44,7 +44,7 @@ class UpdateDocRequest extends $pb.GeneratedMessage {
     ..aOS(1, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'id')
     ..aOS(2, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'name')
     ..aOS(3, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'desc')
-    ..aOS(4, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'content')
+    ..aOS(4, const $core.bool.fromEnvironment('protobuf.omit_field_names') ? '' : 'text')
     ..hasRequiredFields = false
   ;
 
@@ -53,7 +53,7 @@ class UpdateDocRequest extends $pb.GeneratedMessage {
     $core.String? id,
     $core.String? name,
     $core.String? desc,
-    $core.String? content,
+    $core.String? text,
   }) {
     final _result = create();
     if (id != null) {
@@ -65,8 +65,8 @@ class UpdateDocRequest extends $pb.GeneratedMessage {
     if (desc != null) {
       _result.desc = desc;
     }
-    if (content != null) {
-      _result.content = content;
+    if (text != null) {
+      _result.text = text;
     }
     return _result;
   }
@@ -97,8 +97,8 @@ class UpdateDocRequest extends $pb.GeneratedMessage {
   UpdateDocRequest_OneOfDesc whichOneOfDesc() => _UpdateDocRequest_OneOfDescByTag[$_whichOneof(1)]!;
   void clearOneOfDesc() => clearField($_whichOneof(1));
 
-  UpdateDocRequest_OneOfContent whichOneOfContent() => _UpdateDocRequest_OneOfContentByTag[$_whichOneof(2)]!;
-  void clearOneOfContent() => clearField($_whichOneof(2));
+  UpdateDocRequest_OneOfText whichOneOfText() => _UpdateDocRequest_OneOfTextByTag[$_whichOneof(2)]!;
+  void clearOneOfText() => clearField($_whichOneof(2));
 
   @$pb.TagNumber(1)
   $core.String get id => $_getSZ(0);
@@ -128,12 +128,12 @@ class UpdateDocRequest extends $pb.GeneratedMessage {
   void clearDesc() => clearField(3);
 
   @$pb.TagNumber(4)
-  $core.String get content => $_getSZ(3);
+  $core.String get text => $_getSZ(3);
   @$pb.TagNumber(4)
-  set content($core.String v) { $_setString(3, v); }
+  set text($core.String v) { $_setString(3, v); }
   @$pb.TagNumber(4)
-  $core.bool hasContent() => $_has(3);
+  $core.bool hasText() => $_has(3);
   @$pb.TagNumber(4)
-  void clearContent() => clearField(4);
+  void clearText() => clearField(4);
 }
 

+ 3 - 3
app_flowy/packages/flowy_sdk/lib/protobuf/flowy-editor/doc_modify.pbjson.dart

@@ -15,14 +15,14 @@ const UpdateDocRequest$json = const {
     const {'1': 'id', '3': 1, '4': 1, '5': 9, '10': 'id'},
     const {'1': 'name', '3': 2, '4': 1, '5': 9, '9': 0, '10': 'name'},
     const {'1': 'desc', '3': 3, '4': 1, '5': 9, '9': 1, '10': 'desc'},
-    const {'1': 'content', '3': 4, '4': 1, '5': 9, '9': 2, '10': 'content'},
+    const {'1': 'text', '3': 4, '4': 1, '5': 9, '9': 2, '10': 'text'},
   ],
   '8': const [
     const {'1': 'one_of_name'},
     const {'1': 'one_of_desc'},
-    const {'1': 'one_of_content'},
+    const {'1': 'one_of_text'},
   ],
 };
 
 /// Descriptor for `UpdateDocRequest`. Decode as a `google.protobuf.DescriptorProto`.
-final $typed_data.Uint8List updateDocRequestDescriptor = $convert.base64Decode('ChBVcGRhdGVEb2NSZXF1ZXN0Eg4KAmlkGAEgASgJUgJpZBIUCgRuYW1lGAIgASgJSABSBG5hbWUSFAoEZGVzYxgDIAEoCUgBUgRkZXNjEhoKB2NvbnRlbnQYBCABKAlIAlIHY29udGVudEINCgtvbmVfb2ZfbmFtZUINCgtvbmVfb2ZfZGVzY0IQCg5vbmVfb2ZfY29udGVudA==');
+final $typed_data.Uint8List updateDocRequestDescriptor = $convert.base64Decode('ChBVcGRhdGVEb2NSZXF1ZXN0Eg4KAmlkGAEgASgJUgJpZBIUCgRuYW1lGAIgASgJSABSBG5hbWUSFAoEZGVzYxgDIAEoCUgBUgRkZXNjEhQKBHRleHQYBCABKAlIAlIEdGV4dEINCgtvbmVfb2ZfbmFtZUINCgtvbmVfb2ZfZGVzY0INCgtvbmVfb2ZfdGV4dA==');

+ 1 - 0
rust-lib/flowy-editor/Cargo.toml

@@ -19,6 +19,7 @@ unicode-segmentation = "1.7.1"
 lazy_static = "1.4.0"
 log = "0.4.14"
 tokio = {version = "1.6.0", features = ["sync"]}
+tracing = { version = "0.1", features = ["log"] }
 
 [dev-dependencies]
 flowy-test = { path = "../flowy-test" }

+ 6 - 1
rust-lib/flowy-editor/src/entities/doc/doc_create.rs

@@ -15,12 +15,16 @@ pub struct CreateDocRequest {
 
     #[pb(index = 3)]
     pub desc: String,
+
+    #[pb(index = 4)]
+    pub text: String,
 }
 
 pub struct CreateDocParams {
     pub id: String,
     pub name: String,
     pub desc: String,
+    pub text: String,
 }
 
 impl TryInto<CreateDocParams> for CreateDocRequest {
@@ -47,6 +51,7 @@ impl TryInto<CreateDocParams> for CreateDocRequest {
             id,
             name,
             desc: self.desc,
+            text: self.text,
         })
     }
 }
@@ -72,5 +77,5 @@ pub struct Doc {
     pub desc: DocDescription,
 
     #[pb(index = 2)]
-    pub content: String,
+    pub text: String,
 }

+ 3 - 3
rust-lib/flowy-editor/src/entities/doc/doc_modify.rs

@@ -14,14 +14,14 @@ pub struct UpdateDocRequest {
     pub desc: Option<String>,
 
     #[pb(index = 4, one_of)]
-    pub content: Option<String>,
+    pub text: Option<String>,
 }
 
 pub(crate) struct UpdateDocParams {
     pub(crate) id: String,
     pub(crate) name: Option<String>,
     pub(crate) desc: Option<String>,
-    pub(crate) content: Option<String>,
+    pub(crate) text: Option<String>,
 }
 
 impl TryInto<UpdateDocParams> for UpdateDocRequest {
@@ -66,7 +66,7 @@ impl TryInto<UpdateDocParams> for UpdateDocRequest {
             id,
             name,
             desc,
-            content: self.content,
+            text: self.text,
         })
     }
 }

+ 14 - 13
rust-lib/flowy-editor/src/handlers/doc_handler.rs

@@ -7,19 +7,21 @@ use flowy_dispatch::prelude::*;
 use std::{convert::TryInto, path::Path, sync::Arc};
 use tokio::sync::RwLock;
 
+#[tracing::instrument(name = "create_doc", skip(data, controller, manager))]
 pub async fn create_doc(
     data: Data<CreateDocRequest>,
     controller: Unit<DocController>,
     manager: Unit<RwLock<FileManager>>,
 ) -> ResponseResult<DocDescription, EditorError> {
     let params: CreateDocParams = data.into_inner().try_into()?;
-    let path = manager.read().await.make_file_path(&params.id);
+    let path = manager.write().await.create_file(&params.id, &params.text);
     let doc_desc = controller
         .create_doc(params, path.to_str().unwrap())
         .await?;
     response_ok(doc_desc)
 }
 
+#[tracing::instrument(name = "read_doc", skip(data, controller, manager))]
 pub async fn read_doc(
     data: Data<QueryDocRequest>,
     controller: Unit<DocController>,
@@ -27,14 +29,15 @@ pub async fn read_doc(
 ) -> ResponseResult<Doc, EditorError> {
     let params: QueryDocParams = data.into_inner().try_into()?;
     let desc = controller.read_doc(&params.doc_id).await?;
-
     let content = manager
         .write()
         .await
         .open(Path::new(&desc.path), desc.id.clone())?;
 
-    let doc = Doc { desc, content };
-    response_ok(doc)
+    response_ok(Doc {
+        desc,
+        text: content,
+    })
 }
 
 pub async fn update_doc(
@@ -43,15 +46,13 @@ pub async fn update_doc(
     manager: Unit<RwLock<FileManager>>,
 ) -> Result<(), EditorError> {
     let mut params: UpdateDocParams = data.into_inner().try_into()?;
-    match params.content.take() {
-        None => {},
-        Some(s) => {
-            let doc_desc = controller.read_doc(&params.id).await?;
-            manager
-                .write()
-                .await
-                .save(Path::new(&doc_desc.path), &s, params.id.clone());
-        },
+
+    if let Some(s) = params.text.take() {
+        let doc_desc = controller.read_doc(&params.id).await?;
+        manager
+            .write()
+            .await
+            .save(Path::new(&doc_desc.path), &s, params.id.clone());
     }
 
     if params.name.is_some() || params.desc.is_some() {

+ 102 - 57
rust-lib/flowy-editor/src/protobuf/model/doc_create.rs

@@ -29,6 +29,7 @@ pub struct CreateDocRequest {
     pub id: ::std::string::String,
     pub name: ::std::string::String,
     pub desc: ::std::string::String,
+    pub text: ::std::string::String,
     // special fields
     pub unknown_fields: ::protobuf::UnknownFields,
     pub cached_size: ::protobuf::CachedSize,
@@ -122,6 +123,32 @@ impl CreateDocRequest {
     pub fn take_desc(&mut self) -> ::std::string::String {
         ::std::mem::replace(&mut self.desc, ::std::string::String::new())
     }
+
+    // string text = 4;
+
+
+    pub fn get_text(&self) -> &str {
+        &self.text
+    }
+    pub fn clear_text(&mut self) {
+        self.text.clear();
+    }
+
+    // Param is passed by value, moved
+    pub fn set_text(&mut self, v: ::std::string::String) {
+        self.text = v;
+    }
+
+    // Mutable pointer to the field.
+    // If field is not initialized, it is initialized with default value first.
+    pub fn mut_text(&mut self) -> &mut ::std::string::String {
+        &mut self.text
+    }
+
+    // Take field
+    pub fn take_text(&mut self) -> ::std::string::String {
+        ::std::mem::replace(&mut self.text, ::std::string::String::new())
+    }
 }
 
 impl ::protobuf::Message for CreateDocRequest {
@@ -142,6 +169,9 @@ impl ::protobuf::Message for CreateDocRequest {
                 3 => {
                     ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.desc)?;
                 },
+                4 => {
+                    ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.text)?;
+                },
                 _ => {
                     ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?;
                 },
@@ -163,6 +193,9 @@ impl ::protobuf::Message for CreateDocRequest {
         if !self.desc.is_empty() {
             my_size += ::protobuf::rt::string_size(3, &self.desc);
         }
+        if !self.text.is_empty() {
+            my_size += ::protobuf::rt::string_size(4, &self.text);
+        }
         my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields());
         self.cached_size.set(my_size);
         my_size
@@ -178,6 +211,9 @@ impl ::protobuf::Message for CreateDocRequest {
         if !self.desc.is_empty() {
             os.write_string(3, &self.desc)?;
         }
+        if !self.text.is_empty() {
+            os.write_string(4, &self.text)?;
+        }
         os.write_unknown_fields(self.get_unknown_fields())?;
         ::std::result::Result::Ok(())
     }
@@ -231,6 +267,11 @@ impl ::protobuf::Message for CreateDocRequest {
                 |m: &CreateDocRequest| { &m.desc },
                 |m: &mut CreateDocRequest| { &mut m.desc },
             ));
+            fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>(
+                "text",
+                |m: &CreateDocRequest| { &m.text },
+                |m: &mut CreateDocRequest| { &mut m.text },
+            ));
             ::protobuf::reflect::MessageDescriptor::new_pb_name::<CreateDocRequest>(
                 "CreateDocRequest",
                 fields,
@@ -250,6 +291,7 @@ impl ::protobuf::Clear for CreateDocRequest {
         self.id.clear();
         self.name.clear();
         self.desc.clear();
+        self.text.clear();
         self.unknown_fields.clear();
     }
 }
@@ -555,7 +597,7 @@ impl ::protobuf::reflect::ProtobufValue for DocDescription {
 pub struct Doc {
     // message fields
     pub desc: ::protobuf::SingularPtrField<DocDescription>,
-    pub content: ::std::string::String,
+    pub text: ::std::string::String,
     // special fields
     pub unknown_fields: ::protobuf::UnknownFields,
     pub cached_size: ::protobuf::CachedSize,
@@ -605,30 +647,30 @@ impl Doc {
         self.desc.take().unwrap_or_else(|| DocDescription::new())
     }
 
-    // string content = 2;
+    // string text = 2;
 
 
-    pub fn get_content(&self) -> &str {
-        &self.content
+    pub fn get_text(&self) -> &str {
+        &self.text
     }
-    pub fn clear_content(&mut self) {
-        self.content.clear();
+    pub fn clear_text(&mut self) {
+        self.text.clear();
     }
 
     // Param is passed by value, moved
-    pub fn set_content(&mut self, v: ::std::string::String) {
-        self.content = v;
+    pub fn set_text(&mut self, v: ::std::string::String) {
+        self.text = v;
     }
 
     // Mutable pointer to the field.
     // If field is not initialized, it is initialized with default value first.
-    pub fn mut_content(&mut self) -> &mut ::std::string::String {
-        &mut self.content
+    pub fn mut_text(&mut self) -> &mut ::std::string::String {
+        &mut self.text
     }
 
     // Take field
-    pub fn take_content(&mut self) -> ::std::string::String {
-        ::std::mem::replace(&mut self.content, ::std::string::String::new())
+    pub fn take_text(&mut self) -> ::std::string::String {
+        ::std::mem::replace(&mut self.text, ::std::string::String::new())
     }
 }
 
@@ -650,7 +692,7 @@ impl ::protobuf::Message for Doc {
                     ::protobuf::rt::read_singular_message_into(wire_type, is, &mut self.desc)?;
                 },
                 2 => {
-                    ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.content)?;
+                    ::protobuf::rt::read_singular_proto3_string_into(wire_type, is, &mut self.text)?;
                 },
                 _ => {
                     ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?;
@@ -668,8 +710,8 @@ impl ::protobuf::Message for Doc {
             let len = v.compute_size();
             my_size += 1 + ::protobuf::rt::compute_raw_varint32_size(len) + len;
         }
-        if !self.content.is_empty() {
-            my_size += ::protobuf::rt::string_size(2, &self.content);
+        if !self.text.is_empty() {
+            my_size += ::protobuf::rt::string_size(2, &self.text);
         }
         my_size += ::protobuf::rt::unknown_fields_size(self.get_unknown_fields());
         self.cached_size.set(my_size);
@@ -682,8 +724,8 @@ impl ::protobuf::Message for Doc {
             os.write_raw_varint32(v.get_cached_size())?;
             v.write_to_with_cached_sizes(os)?;
         }
-        if !self.content.is_empty() {
-            os.write_string(2, &self.content)?;
+        if !self.text.is_empty() {
+            os.write_string(2, &self.text)?;
         }
         os.write_unknown_fields(self.get_unknown_fields())?;
         ::std::result::Result::Ok(())
@@ -729,9 +771,9 @@ impl ::protobuf::Message for Doc {
                 |m: &mut Doc| { &mut m.desc },
             ));
             fields.push(::protobuf::reflect::accessor::make_simple_field_accessor::<_, ::protobuf::types::ProtobufTypeString>(
-                "content",
-                |m: &Doc| { &m.content },
-                |m: &mut Doc| { &mut m.content },
+                "text",
+                |m: &Doc| { &m.text },
+                |m: &mut Doc| { &mut m.text },
             ));
             ::protobuf::reflect::MessageDescriptor::new_pb_name::<Doc>(
                 "Doc",
@@ -750,7 +792,7 @@ impl ::protobuf::Message for Doc {
 impl ::protobuf::Clear for Doc {
     fn clear(&mut self) {
         self.desc.clear();
-        self.content.clear();
+        self.text.clear();
         self.unknown_fields.clear();
     }
 }
@@ -768,43 +810,46 @@ impl ::protobuf::reflect::ProtobufValue for Doc {
 }
 
 static file_descriptor_proto_data: &'static [u8] = b"\
-    \n\x10doc_create.proto\"J\n\x10CreateDocRequest\x12\x0e\n\x02id\x18\x01\
+    \n\x10doc_create.proto\"^\n\x10CreateDocRequest\x12\x0e\n\x02id\x18\x01\
     \x20\x01(\tR\x02id\x12\x12\n\x04name\x18\x02\x20\x01(\tR\x04name\x12\x12\
-    \n\x04desc\x18\x03\x20\x01(\tR\x04desc\"\\\n\x0eDocDescription\x12\x0e\n\
-    \x02id\x18\x01\x20\x01(\tR\x02id\x12\x12\n\x04name\x18\x02\x20\x01(\tR\
-    \x04name\x12\x12\n\x04desc\x18\x03\x20\x01(\tR\x04desc\x12\x12\n\x04path\
-    \x18\x04\x20\x01(\tR\x04path\"D\n\x03Doc\x12#\n\x04desc\x18\x01\x20\x01(\
-    \x0b2\x0f.DocDescriptionR\x04desc\x12\x18\n\x07content\x18\x02\x20\x01(\
-    \tR\x07contentJ\xc9\x04\n\x06\x12\x04\0\0\x10\x01\n\x08\n\x01\x0c\x12\
-    \x03\0\0\x12\n\n\n\x02\x04\0\x12\x04\x02\0\x06\x01\n\n\n\x03\x04\0\x01\
-    \x12\x03\x02\x08\x18\n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\x04\x12\n\x0c\n\
-    \x05\x04\0\x02\0\x05\x12\x03\x03\x04\n\n\x0c\n\x05\x04\0\x02\0\x01\x12\
-    \x03\x03\x0b\r\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x03\x10\x11\n\x0b\n\
-    \x04\x04\0\x02\x01\x12\x03\x04\x04\x14\n\x0c\n\x05\x04\0\x02\x01\x05\x12\
-    \x03\x04\x04\n\n\x0c\n\x05\x04\0\x02\x01\x01\x12\x03\x04\x0b\x0f\n\x0c\n\
-    \x05\x04\0\x02\x01\x03\x12\x03\x04\x12\x13\n\x0b\n\x04\x04\0\x02\x02\x12\
-    \x03\x05\x04\x14\n\x0c\n\x05\x04\0\x02\x02\x05\x12\x03\x05\x04\n\n\x0c\n\
-    \x05\x04\0\x02\x02\x01\x12\x03\x05\x0b\x0f\n\x0c\n\x05\x04\0\x02\x02\x03\
-    \x12\x03\x05\x12\x13\n\n\n\x02\x04\x01\x12\x04\x07\0\x0c\x01\n\n\n\x03\
-    \x04\x01\x01\x12\x03\x07\x08\x16\n\x0b\n\x04\x04\x01\x02\0\x12\x03\x08\
-    \x04\x12\n\x0c\n\x05\x04\x01\x02\0\x05\x12\x03\x08\x04\n\n\x0c\n\x05\x04\
-    \x01\x02\0\x01\x12\x03\x08\x0b\r\n\x0c\n\x05\x04\x01\x02\0\x03\x12\x03\
-    \x08\x10\x11\n\x0b\n\x04\x04\x01\x02\x01\x12\x03\t\x04\x14\n\x0c\n\x05\
-    \x04\x01\x02\x01\x05\x12\x03\t\x04\n\n\x0c\n\x05\x04\x01\x02\x01\x01\x12\
-    \x03\t\x0b\x0f\n\x0c\n\x05\x04\x01\x02\x01\x03\x12\x03\t\x12\x13\n\x0b\n\
-    \x04\x04\x01\x02\x02\x12\x03\n\x04\x14\n\x0c\n\x05\x04\x01\x02\x02\x05\
-    \x12\x03\n\x04\n\n\x0c\n\x05\x04\x01\x02\x02\x01\x12\x03\n\x0b\x0f\n\x0c\
-    \n\x05\x04\x01\x02\x02\x03\x12\x03\n\x12\x13\n\x0b\n\x04\x04\x01\x02\x03\
-    \x12\x03\x0b\x04\x14\n\x0c\n\x05\x04\x01\x02\x03\x05\x12\x03\x0b\x04\n\n\
-    \x0c\n\x05\x04\x01\x02\x03\x01\x12\x03\x0b\x0b\x0f\n\x0c\n\x05\x04\x01\
-    \x02\x03\x03\x12\x03\x0b\x12\x13\n\n\n\x02\x04\x02\x12\x04\r\0\x10\x01\n\
-    \n\n\x03\x04\x02\x01\x12\x03\r\x08\x0b\n\x0b\n\x04\x04\x02\x02\0\x12\x03\
-    \x0e\x04\x1c\n\x0c\n\x05\x04\x02\x02\0\x06\x12\x03\x0e\x04\x12\n\x0c\n\
-    \x05\x04\x02\x02\0\x01\x12\x03\x0e\x13\x17\n\x0c\n\x05\x04\x02\x02\0\x03\
-    \x12\x03\x0e\x1a\x1b\n\x0b\n\x04\x04\x02\x02\x01\x12\x03\x0f\x04\x17\n\
-    \x0c\n\x05\x04\x02\x02\x01\x05\x12\x03\x0f\x04\n\n\x0c\n\x05\x04\x02\x02\
-    \x01\x01\x12\x03\x0f\x0b\x12\n\x0c\n\x05\x04\x02\x02\x01\x03\x12\x03\x0f\
-    \x15\x16b\x06proto3\
+    \n\x04desc\x18\x03\x20\x01(\tR\x04desc\x12\x12\n\x04text\x18\x04\x20\x01\
+    (\tR\x04text\"\\\n\x0eDocDescription\x12\x0e\n\x02id\x18\x01\x20\x01(\tR\
+    \x02id\x12\x12\n\x04name\x18\x02\x20\x01(\tR\x04name\x12\x12\n\x04desc\
+    \x18\x03\x20\x01(\tR\x04desc\x12\x12\n\x04path\x18\x04\x20\x01(\tR\x04pa\
+    th\">\n\x03Doc\x12#\n\x04desc\x18\x01\x20\x01(\x0b2\x0f.DocDescriptionR\
+    \x04desc\x12\x12\n\x04text\x18\x02\x20\x01(\tR\x04textJ\x80\x05\n\x06\
+    \x12\x04\0\0\x11\x01\n\x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x04\0\x12\
+    \x04\x02\0\x07\x01\n\n\n\x03\x04\0\x01\x12\x03\x02\x08\x18\n\x0b\n\x04\
+    \x04\0\x02\0\x12\x03\x03\x04\x12\n\x0c\n\x05\x04\0\x02\0\x05\x12\x03\x03\
+    \x04\n\n\x0c\n\x05\x04\0\x02\0\x01\x12\x03\x03\x0b\r\n\x0c\n\x05\x04\0\
+    \x02\0\x03\x12\x03\x03\x10\x11\n\x0b\n\x04\x04\0\x02\x01\x12\x03\x04\x04\
+    \x14\n\x0c\n\x05\x04\0\x02\x01\x05\x12\x03\x04\x04\n\n\x0c\n\x05\x04\0\
+    \x02\x01\x01\x12\x03\x04\x0b\x0f\n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\
+    \x04\x12\x13\n\x0b\n\x04\x04\0\x02\x02\x12\x03\x05\x04\x14\n\x0c\n\x05\
+    \x04\0\x02\x02\x05\x12\x03\x05\x04\n\n\x0c\n\x05\x04\0\x02\x02\x01\x12\
+    \x03\x05\x0b\x0f\n\x0c\n\x05\x04\0\x02\x02\x03\x12\x03\x05\x12\x13\n\x0b\
+    \n\x04\x04\0\x02\x03\x12\x03\x06\x04\x14\n\x0c\n\x05\x04\0\x02\x03\x05\
+    \x12\x03\x06\x04\n\n\x0c\n\x05\x04\0\x02\x03\x01\x12\x03\x06\x0b\x0f\n\
+    \x0c\n\x05\x04\0\x02\x03\x03\x12\x03\x06\x12\x13\n\n\n\x02\x04\x01\x12\
+    \x04\x08\0\r\x01\n\n\n\x03\x04\x01\x01\x12\x03\x08\x08\x16\n\x0b\n\x04\
+    \x04\x01\x02\0\x12\x03\t\x04\x12\n\x0c\n\x05\x04\x01\x02\0\x05\x12\x03\t\
+    \x04\n\n\x0c\n\x05\x04\x01\x02\0\x01\x12\x03\t\x0b\r\n\x0c\n\x05\x04\x01\
+    \x02\0\x03\x12\x03\t\x10\x11\n\x0b\n\x04\x04\x01\x02\x01\x12\x03\n\x04\
+    \x14\n\x0c\n\x05\x04\x01\x02\x01\x05\x12\x03\n\x04\n\n\x0c\n\x05\x04\x01\
+    \x02\x01\x01\x12\x03\n\x0b\x0f\n\x0c\n\x05\x04\x01\x02\x01\x03\x12\x03\n\
+    \x12\x13\n\x0b\n\x04\x04\x01\x02\x02\x12\x03\x0b\x04\x14\n\x0c\n\x05\x04\
+    \x01\x02\x02\x05\x12\x03\x0b\x04\n\n\x0c\n\x05\x04\x01\x02\x02\x01\x12\
+    \x03\x0b\x0b\x0f\n\x0c\n\x05\x04\x01\x02\x02\x03\x12\x03\x0b\x12\x13\n\
+    \x0b\n\x04\x04\x01\x02\x03\x12\x03\x0c\x04\x14\n\x0c\n\x05\x04\x01\x02\
+    \x03\x05\x12\x03\x0c\x04\n\n\x0c\n\x05\x04\x01\x02\x03\x01\x12\x03\x0c\
+    \x0b\x0f\n\x0c\n\x05\x04\x01\x02\x03\x03\x12\x03\x0c\x12\x13\n\n\n\x02\
+    \x04\x02\x12\x04\x0e\0\x11\x01\n\n\n\x03\x04\x02\x01\x12\x03\x0e\x08\x0b\
+    \n\x0b\n\x04\x04\x02\x02\0\x12\x03\x0f\x04\x1c\n\x0c\n\x05\x04\x02\x02\0\
+    \x06\x12\x03\x0f\x04\x12\n\x0c\n\x05\x04\x02\x02\0\x01\x12\x03\x0f\x13\
+    \x17\n\x0c\n\x05\x04\x02\x02\0\x03\x12\x03\x0f\x1a\x1b\n\x0b\n\x04\x04\
+    \x02\x02\x01\x12\x03\x10\x04\x14\n\x0c\n\x05\x04\x02\x02\x01\x05\x12\x03\
+    \x10\x04\n\n\x0c\n\x05\x04\x02\x02\x01\x01\x12\x03\x10\x0b\x0f\n\x0c\n\
+    \x05\x04\x02\x02\x01\x03\x12\x03\x10\x12\x13b\x06proto3\
 ";
 
 static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT;

+ 52 - 52
rust-lib/flowy-editor/src/protobuf/model/doc_modify.rs

@@ -30,7 +30,7 @@ pub struct UpdateDocRequest {
     // message oneof groups
     pub one_of_name: ::std::option::Option<UpdateDocRequest_oneof_one_of_name>,
     pub one_of_desc: ::std::option::Option<UpdateDocRequest_oneof_one_of_desc>,
-    pub one_of_content: ::std::option::Option<UpdateDocRequest_oneof_one_of_content>,
+    pub one_of_text: ::std::option::Option<UpdateDocRequest_oneof_one_of_text>,
     // special fields
     pub unknown_fields: ::protobuf::UnknownFields,
     pub cached_size: ::protobuf::CachedSize,
@@ -53,8 +53,8 @@ pub enum UpdateDocRequest_oneof_one_of_desc {
 }
 
 #[derive(Clone,PartialEq,Debug)]
-pub enum UpdateDocRequest_oneof_one_of_content {
-    content(::std::string::String),
+pub enum UpdateDocRequest_oneof_one_of_text {
+    text(::std::string::String),
 }
 
 impl UpdateDocRequest {
@@ -186,48 +186,48 @@ impl UpdateDocRequest {
         }
     }
 
-    // string content = 4;
+    // string text = 4;
 
 
-    pub fn get_content(&self) -> &str {
-        match self.one_of_content {
-            ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_content::content(ref v)) => v,
+    pub fn get_text(&self) -> &str {
+        match self.one_of_text {
+            ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_text::text(ref v)) => v,
             _ => "",
         }
     }
-    pub fn clear_content(&mut self) {
-        self.one_of_content = ::std::option::Option::None;
+    pub fn clear_text(&mut self) {
+        self.one_of_text = ::std::option::Option::None;
     }
 
-    pub fn has_content(&self) -> bool {
-        match self.one_of_content {
-            ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_content::content(..)) => true,
+    pub fn has_text(&self) -> bool {
+        match self.one_of_text {
+            ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_text::text(..)) => true,
             _ => false,
         }
     }
 
     // Param is passed by value, moved
-    pub fn set_content(&mut self, v: ::std::string::String) {
-        self.one_of_content = ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_content::content(v))
+    pub fn set_text(&mut self, v: ::std::string::String) {
+        self.one_of_text = ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_text::text(v))
     }
 
     // Mutable pointer to the field.
-    pub fn mut_content(&mut self) -> &mut ::std::string::String {
-        if let ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_content::content(_)) = self.one_of_content {
+    pub fn mut_text(&mut self) -> &mut ::std::string::String {
+        if let ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_text::text(_)) = self.one_of_text {
         } else {
-            self.one_of_content = ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_content::content(::std::string::String::new()));
+            self.one_of_text = ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_text::text(::std::string::String::new()));
         }
-        match self.one_of_content {
-            ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_content::content(ref mut v)) => v,
+        match self.one_of_text {
+            ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_text::text(ref mut v)) => v,
             _ => panic!(),
         }
     }
 
     // Take field
-    pub fn take_content(&mut self) -> ::std::string::String {
-        if self.has_content() {
-            match self.one_of_content.take() {
-                ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_content::content(v)) => v,
+    pub fn take_text(&mut self) -> ::std::string::String {
+        if self.has_text() {
+            match self.one_of_text.take() {
+                ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_text::text(v)) => v,
                 _ => panic!(),
             }
         } else {
@@ -264,7 +264,7 @@ impl ::protobuf::Message for UpdateDocRequest {
                     if wire_type != ::protobuf::wire_format::WireTypeLengthDelimited {
                         return ::std::result::Result::Err(::protobuf::rt::unexpected_wire_type(wire_type));
                     }
-                    self.one_of_content = ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_content::content(is.read_string()?));
+                    self.one_of_text = ::std::option::Option::Some(UpdateDocRequest_oneof_one_of_text::text(is.read_string()?));
                 },
                 _ => {
                     ::protobuf::rt::read_unknown_or_skip_group(field_number, wire_type, is, self.mut_unknown_fields())?;
@@ -295,9 +295,9 @@ impl ::protobuf::Message for UpdateDocRequest {
                 },
             };
         }
-        if let ::std::option::Option::Some(ref v) = self.one_of_content {
+        if let ::std::option::Option::Some(ref v) = self.one_of_text {
             match v {
-                &UpdateDocRequest_oneof_one_of_content::content(ref v) => {
+                &UpdateDocRequest_oneof_one_of_text::text(ref v) => {
                     my_size += ::protobuf::rt::string_size(4, &v);
                 },
             };
@@ -325,9 +325,9 @@ impl ::protobuf::Message for UpdateDocRequest {
                 },
             };
         }
-        if let ::std::option::Option::Some(ref v) = self.one_of_content {
+        if let ::std::option::Option::Some(ref v) = self.one_of_text {
             match v {
-                &UpdateDocRequest_oneof_one_of_content::content(ref v) => {
+                &UpdateDocRequest_oneof_one_of_text::text(ref v) => {
                     os.write_string(4, v)?;
                 },
             };
@@ -386,9 +386,9 @@ impl ::protobuf::Message for UpdateDocRequest {
                 UpdateDocRequest::get_desc,
             ));
             fields.push(::protobuf::reflect::accessor::make_singular_string_accessor::<_>(
-                "content",
-                UpdateDocRequest::has_content,
-                UpdateDocRequest::get_content,
+                "text",
+                UpdateDocRequest::has_text,
+                UpdateDocRequest::get_text,
             ));
             ::protobuf::reflect::MessageDescriptor::new_pb_name::<UpdateDocRequest>(
                 "UpdateDocRequest",
@@ -409,7 +409,7 @@ impl ::protobuf::Clear for UpdateDocRequest {
         self.id.clear();
         self.one_of_name = ::std::option::Option::None;
         self.one_of_desc = ::std::option::Option::None;
-        self.one_of_content = ::std::option::Option::None;
+        self.one_of_text = ::std::option::Option::None;
         self.unknown_fields.clear();
     }
 }
@@ -427,27 +427,27 @@ impl ::protobuf::reflect::ProtobufValue for UpdateDocRequest {
 }
 
 static file_descriptor_proto_data: &'static [u8] = b"\
-    \n\x10doc_modify.proto\"\x9a\x01\n\x10UpdateDocRequest\x12\x0e\n\x02id\
+    \n\x10doc_modify.proto\"\x91\x01\n\x10UpdateDocRequest\x12\x0e\n\x02id\
     \x18\x01\x20\x01(\tR\x02id\x12\x14\n\x04name\x18\x02\x20\x01(\tH\0R\x04n\
-    ame\x12\x14\n\x04desc\x18\x03\x20\x01(\tH\x01R\x04desc\x12\x1a\n\x07cont\
-    ent\x18\x04\x20\x01(\tH\x02R\x07contentB\r\n\x0bone_of_nameB\r\n\x0bone_\
-    of_descB\x10\n\x0eone_of_contentJ\xd7\x02\n\x06\x12\x04\0\0\x07\x01\n\
-    \x08\n\x01\x0c\x12\x03\0\0\x12\n\n\n\x02\x04\0\x12\x04\x02\0\x07\x01\n\n\
-    \n\x03\x04\0\x01\x12\x03\x02\x08\x18\n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\
-    \x04\x12\n\x0c\n\x05\x04\0\x02\0\x05\x12\x03\x03\x04\n\n\x0c\n\x05\x04\0\
-    \x02\0\x01\x12\x03\x03\x0b\r\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x03\x10\
-    \x11\n\x0b\n\x04\x04\0\x08\0\x12\x03\x04\x04*\n\x0c\n\x05\x04\0\x08\0\
-    \x01\x12\x03\x04\n\x15\n\x0b\n\x04\x04\0\x02\x01\x12\x03\x04\x18(\n\x0c\
-    \n\x05\x04\0\x02\x01\x05\x12\x03\x04\x18\x1e\n\x0c\n\x05\x04\0\x02\x01\
-    \x01\x12\x03\x04\x1f#\n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\x04&'\n\x0b\
-    \n\x04\x04\0\x08\x01\x12\x03\x05\x04*\n\x0c\n\x05\x04\0\x08\x01\x01\x12\
-    \x03\x05\n\x15\n\x0b\n\x04\x04\0\x02\x02\x12\x03\x05\x18(\n\x0c\n\x05\
-    \x04\0\x02\x02\x05\x12\x03\x05\x18\x1e\n\x0c\n\x05\x04\0\x02\x02\x01\x12\
-    \x03\x05\x1f#\n\x0c\n\x05\x04\0\x02\x02\x03\x12\x03\x05&'\n\x0b\n\x04\
-    \x04\0\x08\x02\x12\x03\x06\x040\n\x0c\n\x05\x04\0\x08\x02\x01\x12\x03\
-    \x06\n\x18\n\x0b\n\x04\x04\0\x02\x03\x12\x03\x06\x1b.\n\x0c\n\x05\x04\0\
-    \x02\x03\x05\x12\x03\x06\x1b!\n\x0c\n\x05\x04\0\x02\x03\x01\x12\x03\x06\
-    \")\n\x0c\n\x05\x04\0\x02\x03\x03\x12\x03\x06,-b\x06proto3\
+    ame\x12\x14\n\x04desc\x18\x03\x20\x01(\tH\x01R\x04desc\x12\x14\n\x04text\
+    \x18\x04\x20\x01(\tH\x02R\x04textB\r\n\x0bone_of_nameB\r\n\x0bone_of_des\
+    cB\r\n\x0bone_of_textJ\xd7\x02\n\x06\x12\x04\0\0\x07\x01\n\x08\n\x01\x0c\
+    \x12\x03\0\0\x12\n\n\n\x02\x04\0\x12\x04\x02\0\x07\x01\n\n\n\x03\x04\0\
+    \x01\x12\x03\x02\x08\x18\n\x0b\n\x04\x04\0\x02\0\x12\x03\x03\x04\x12\n\
+    \x0c\n\x05\x04\0\x02\0\x05\x12\x03\x03\x04\n\n\x0c\n\x05\x04\0\x02\0\x01\
+    \x12\x03\x03\x0b\r\n\x0c\n\x05\x04\0\x02\0\x03\x12\x03\x03\x10\x11\n\x0b\
+    \n\x04\x04\0\x08\0\x12\x03\x04\x04*\n\x0c\n\x05\x04\0\x08\0\x01\x12\x03\
+    \x04\n\x15\n\x0b\n\x04\x04\0\x02\x01\x12\x03\x04\x18(\n\x0c\n\x05\x04\0\
+    \x02\x01\x05\x12\x03\x04\x18\x1e\n\x0c\n\x05\x04\0\x02\x01\x01\x12\x03\
+    \x04\x1f#\n\x0c\n\x05\x04\0\x02\x01\x03\x12\x03\x04&'\n\x0b\n\x04\x04\0\
+    \x08\x01\x12\x03\x05\x04*\n\x0c\n\x05\x04\0\x08\x01\x01\x12\x03\x05\n\
+    \x15\n\x0b\n\x04\x04\0\x02\x02\x12\x03\x05\x18(\n\x0c\n\x05\x04\0\x02\
+    \x02\x05\x12\x03\x05\x18\x1e\n\x0c\n\x05\x04\0\x02\x02\x01\x12\x03\x05\
+    \x1f#\n\x0c\n\x05\x04\0\x02\x02\x03\x12\x03\x05&'\n\x0b\n\x04\x04\0\x08\
+    \x02\x12\x03\x06\x04*\n\x0c\n\x05\x04\0\x08\x02\x01\x12\x03\x06\n\x15\n\
+    \x0b\n\x04\x04\0\x02\x03\x12\x03\x06\x18(\n\x0c\n\x05\x04\0\x02\x03\x05\
+    \x12\x03\x06\x18\x1e\n\x0c\n\x05\x04\0\x02\x03\x01\x12\x03\x06\x1f#\n\
+    \x0c\n\x05\x04\0\x02\x03\x03\x12\x03\x06&'b\x06proto3\
 ";
 
 static file_descriptor_proto_lazy: ::protobuf::rt::LazyV2<::protobuf::descriptor::FileDescriptorProto> = ::protobuf::rt::LazyV2::INIT;

+ 2 - 1
rust-lib/flowy-editor/src/protobuf/proto/doc_create.proto

@@ -4,6 +4,7 @@ message CreateDocRequest {
     string id = 1;
     string name = 2;
     string desc = 3;
+    string text = 4;
 }
 message DocDescription {
     string id = 1;
@@ -13,5 +14,5 @@ message DocDescription {
 }
 message Doc {
     DocDescription desc = 1;
-    string content = 2;
+    string text = 2;
 }

+ 1 - 1
rust-lib/flowy-editor/src/protobuf/proto/doc_modify.proto

@@ -4,5 +4,5 @@ message UpdateDocRequest {
     string id = 1;
     oneof one_of_name { string name = 2; };
     oneof one_of_desc { string desc = 3; };
-    oneof one_of_content { string content = 4; };
+    oneof one_of_text { string text = 4; };
 }

+ 7 - 3
rust-lib/flowy-editor/src/services/file_manager/manager.rs

@@ -70,8 +70,12 @@ impl FileManager {
         }
     }
 
-    pub(crate) fn make_file_path(&self, id: &str) -> PathBuf {
-        PathBuf::from(format!("{}/{}", self.config.doc_dir, id))
+    pub(crate) fn create_file(&mut self, id: &str, text: &str) -> PathBuf {
+        let path = PathBuf::from(format!("{}/{}", self.config.doc_dir, id));
+        let file_id: FileId = id.to_owned().into();
+        log::info!("Create doc at: {:?}", path);
+        self.save_new(&path, text, &file_id);
+        path
     }
 
     pub(crate) fn get_info(&self, id: &FileId) -> Option<&FileInfo> { self.file_info.get(id) }
@@ -91,7 +95,7 @@ impl FileManager {
         false
     }
 
-    fn save_new(&mut self, path: &Path, text: &String, id: &FileId) -> Result<(), FileError> {
+    fn save_new(&mut self, path: &Path, text: &str, id: &FileId) -> Result<(), FileError> {
         try_save(path, text, CharacterEncoding::Utf8, self.get_info(id))
             .map_err(|e| FileError::Io(e, path.to_owned()))?;
         let info = FileInfo {

+ 9 - 5
rust-lib/flowy-editor/tests/editor/doc_test.rs

@@ -2,17 +2,21 @@ use crate::helper::*;
 
 #[test]
 fn file_create_test() {
-    let doc_desc = create_doc("hello world", "flutter ❤️ rust");
+    let doc_desc = create_doc("hello world", "flutter ❤️ rust", "123");
     dbg!(&doc_desc);
+
+    let doc = read_doc(&doc_desc.id);
+    assert_eq!(doc.text, "123".to_owned());
 }
 
 #[test]
-fn file_save_test() {
-    let content = "😁😁😁😁😁😁😁😁😁😁".to_owned();
-    let doc_desc = create_doc("hello world", "flutter ❤️ rust");
+fn file_update_text_test() {
+    let doc_desc = create_doc("hello world", "flutter ❤️ rust", "");
     dbg!(&doc_desc);
+
+    let content = "😁😁😁😁😁😁😁😁😁😁".to_owned();
     save_doc(&doc_desc, &content);
 
     let doc = read_doc(&doc_desc.id);
-    assert_eq!(doc.content, content);
+    assert_eq!(doc.text, content);
 }

+ 3 - 2
rust-lib/flowy-editor/tests/editor/helper.rs

@@ -3,11 +3,12 @@ use flowy_test::builder::SingleUserTestBuilder;
 use flowy_editor::{entities::doc::*, event::EditorEvent::*};
 use flowy_infra::uuid;
 
-pub fn create_doc(name: &str, desc: &str) -> DocDescription {
+pub fn create_doc(name: &str, desc: &str, text: &str) -> DocDescription {
     let request = CreateDocRequest {
         id: uuid(),
         name: name.to_owned(),
         desc: desc.to_owned(),
+        text: text.to_owned(),
     };
 
     let doc_desc = SingleUserTestBuilder::new()
@@ -24,7 +25,7 @@ pub fn save_doc(desc: &DocDescription, content: &str) {
         id: desc.id.clone(),
         name: Some(desc.name.clone()),
         desc: Some(desc.desc.clone()),
-        content: Some(content.to_owned()),
+        text: Some(content.to_owned()),
     };
 
     let _ = SingleUserTestBuilder::new()

+ 4 - 0
scripts/flowy-tool/src/dart_event/dart_event.rs

@@ -114,6 +114,10 @@ pub fn ast_to_event_render_ctx(ast: &Vec<EventASTContext>) -> Vec<EventRenderCon
                 Some(ref event_output) => Some(event_output.get_ident().unwrap().to_string()),
                 None => None,
             };
+            // eprintln!(
+            //     "😁 {:?} / {:?}",
+            //     event_ast.event_input, event_ast.event_output
+            // );
 
             return EventRenderContext {
                 input_deserializer,

+ 8 - 2
scripts/flowy-tool/src/dart_event/event_template.rs

@@ -44,8 +44,14 @@ impl EventTemplate {
             Some(ref input) => self.tera_context.insert("input_deserializer", input),
         }
 
-        self.tera_context
-            .insert("has_output", &ctx.output_deserializer.is_some());
+        // eprintln!(
+        //     "😁 {:?} / {:?}",
+        //     &ctx.input_deserializer, &ctx.output_deserializer
+        // );
+
+        let has_output = ctx.output_deserializer.is_some();
+        self.tera_context.insert("has_output", &has_output);
+
         match ctx.output_deserializer {
             None => self.tera_context.insert("output_deserializer", "Unit"),
             Some(ref output) => self.tera_context.insert("output_deserializer", output),

+ 7 - 2
scripts/flowy-tool/src/dart_event/event_template.tera

@@ -19,8 +19,13 @@ class {{ event_class }} {
 
     return Dispatch.asyncRequest(request)
         .then((bytesResult) => bytesResult.fold(
-          (okBytes) => left({{ output_deserializer }}.fromBuffer(okBytes)),
-          (errBytes) => right({{ error_deserializer }}.fromBuffer(errBytes)),
+
+        {%- if has_output  %}
+           (okBytes) => left({{ output_deserializer }}.fromBuffer(okBytes)),
+        {%- else %}
+           (bytes) => left(unit),
+        {%- endif %}
+           (errBytes) => right({{ error_deserializer }}.fromBuffer(errBytes)),
         ));
 
 {%- else %}