|
@@ -6,6 +6,7 @@ abstract class Operation {
|
|
|
Operation({required this.path});
|
|
|
Operation copyWithPath(Path path);
|
|
|
Operation invert();
|
|
|
+ Map<String, dynamic> toJson();
|
|
|
}
|
|
|
|
|
|
class InsertOperation extends Operation {
|
|
@@ -29,6 +30,15 @@ class InsertOperation extends Operation {
|
|
|
removedValue: value,
|
|
|
);
|
|
|
}
|
|
|
+
|
|
|
+ @override
|
|
|
+ Map<String, dynamic> toJson() {
|
|
|
+ return {
|
|
|
+ "type": "insert-operation",
|
|
|
+ "path": path.toList(),
|
|
|
+ "value": value.toJson(),
|
|
|
+ };
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
class UpdateOperation extends Operation {
|
|
@@ -59,6 +69,16 @@ class UpdateOperation extends Operation {
|
|
|
oldAttributes: attributes,
|
|
|
);
|
|
|
}
|
|
|
+
|
|
|
+ @override
|
|
|
+ Map<String, dynamic> toJson() {
|
|
|
+ return {
|
|
|
+ "type": "update-operation",
|
|
|
+ "path": path.toList(),
|
|
|
+ "attributes": {...attributes},
|
|
|
+ "oldAttributes": {...oldAttributes},
|
|
|
+ };
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
class DeleteOperation extends Operation {
|
|
@@ -82,6 +102,15 @@ class DeleteOperation extends Operation {
|
|
|
value: removedValue,
|
|
|
);
|
|
|
}
|
|
|
+
|
|
|
+ @override
|
|
|
+ Map<String, dynamic> toJson() {
|
|
|
+ return {
|
|
|
+ "type": "delete-operation",
|
|
|
+ "path": path.toList(),
|
|
|
+ "removedValue": removedValue.toJson(),
|
|
|
+ };
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
class TextEditOperation extends Operation {
|
|
@@ -107,6 +136,16 @@ class TextEditOperation extends Operation {
|
|
|
Operation invert() {
|
|
|
return TextEditOperation(path: path, delta: inverted, inverted: delta);
|
|
|
}
|
|
|
+
|
|
|
+ @override
|
|
|
+ Map<String, dynamic> toJson() {
|
|
|
+ return {
|
|
|
+ "type": "text-edit-operation",
|
|
|
+ "path": path.toList(),
|
|
|
+ "delta": delta.toJson(),
|
|
|
+ "invert": inverted.toJson(),
|
|
|
+ };
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
Path transformPath(Path preInsertPath, Path b, [int delta = 1]) {
|