|
@@ -1,5 +1,7 @@
|
|
import 'dart:collection';
|
|
import 'dart:collection';
|
|
|
|
|
|
|
|
+import 'package:flowy_editor/document/path.dart';
|
|
|
|
+
|
|
class Node extends LinkedListEntry<Node> {
|
|
class Node extends LinkedListEntry<Node> {
|
|
Node? parent;
|
|
Node? parent;
|
|
final String type;
|
|
final String type;
|
|
@@ -40,6 +42,22 @@ class Node extends LinkedListEntry<Node> {
|
|
);
|
|
);
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+ Node? childAtIndex(int index) {
|
|
|
|
+ if (children.length <= index) {
|
|
|
|
+ return null;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return children.elementAt(index);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ Node? childAtPath(Path path) {
|
|
|
|
+ if (path.isEmpty) {
|
|
|
|
+ return this;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return childAtIndex(path.first)?.childAtPath(path.sublist(1));
|
|
|
|
+ }
|
|
|
|
+
|
|
Map<String, Object> toJson() {
|
|
Map<String, Object> toJson() {
|
|
var map = <String, Object>{
|
|
var map = <String, Object>{
|
|
'type': type,
|
|
'type': type,
|