2021-09-14 16:22:44 +08:00
|
|
|
import 'dart:convert';
|
|
|
|
|
2021-07-24 14:05:49 +08:00
|
|
|
import 'package:flowy_editor/flowy_editor.dart';
|
2021-07-23 16:45:29 +08:00
|
|
|
import 'package:dartz/dartz.dart';
|
2021-09-14 16:22:44 +08:00
|
|
|
import 'package:flowy_editor/src/model/quill_delta.dart';
|
2021-09-11 20:09:46 +08:00
|
|
|
import 'package:flowy_sdk/protobuf/flowy-document/doc.pb.dart';
|
|
|
|
import 'package:flowy_sdk/protobuf/flowy-workspace/errors.pb.dart';
|
2021-07-23 16:45:29 +08:00
|
|
|
|
2021-09-14 16:22:44 +08:00
|
|
|
class FlowyDoc implements EditorChangesetSender {
|
2021-09-11 20:09:46 +08:00
|
|
|
final Doc doc;
|
2021-09-14 16:22:44 +08:00
|
|
|
final IDoc iDocImpl;
|
|
|
|
Document data;
|
2021-07-24 14:05:49 +08:00
|
|
|
|
2021-09-14 16:22:44 +08:00
|
|
|
FlowyDoc({required this.doc, required this.data, required this.iDocImpl}) {
|
|
|
|
data.sender = this;
|
|
|
|
}
|
2021-09-11 21:30:58 +08:00
|
|
|
String get id => doc.id;
|
2021-09-14 16:22:44 +08:00
|
|
|
|
|
|
|
@override
|
|
|
|
void sendDelta(Delta delta) {
|
|
|
|
final json = jsonEncode(delta.toJson());
|
|
|
|
iDocImpl.applyChangeset(json: json);
|
|
|
|
}
|
2021-07-24 14:05:49 +08:00
|
|
|
}
|
|
|
|
|
2021-07-23 16:45:29 +08:00
|
|
|
abstract class IDoc {
|
2021-09-11 21:30:58 +08:00
|
|
|
Future<Either<Doc, WorkspaceError>> readDoc();
|
2021-09-14 16:22:44 +08:00
|
|
|
Future<Either<Unit, WorkspaceError>> saveDoc({String? json});
|
|
|
|
Future<Either<Unit, WorkspaceError>> applyChangeset({String? json});
|
2021-09-11 20:09:46 +08:00
|
|
|
Future<Either<Unit, WorkspaceError>> closeDoc();
|
2021-07-23 16:45:29 +08:00
|
|
|
}
|