mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
feat: typedef Map<String, Object> to Attributes
This commit is contained in:
parent
59d92a8ced
commit
d2e62f882b
@ -40,7 +40,6 @@
|
|||||||
"attributes": {
|
"attributes": {
|
||||||
"url": "x.mp4"
|
"url": "x.mp4"
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
@ -1,11 +1,13 @@
|
|||||||
import 'dart:collection';
|
import 'dart:collection';
|
||||||
import 'package:flowy_editor/document/path.dart';
|
import 'package:flowy_editor/document/path.dart';
|
||||||
|
|
||||||
|
typedef Attributes = Map<String, Object>;
|
||||||
|
|
||||||
class Node extends LinkedListEntry<Node> {
|
class Node extends LinkedListEntry<Node> {
|
||||||
Node? parent;
|
Node? parent;
|
||||||
final String type;
|
final String type;
|
||||||
final LinkedList<Node> children;
|
final LinkedList<Node> children;
|
||||||
final Map<String, Object> attributes;
|
final Attributes attributes;
|
||||||
|
|
||||||
Node({
|
Node({
|
||||||
required this.type,
|
required this.type,
|
||||||
@ -20,15 +22,15 @@ class Node extends LinkedListEntry<Node> {
|
|||||||
final jType = json['type'] as String;
|
final jType = json['type'] as String;
|
||||||
final jChildren = json['children'] as List?;
|
final jChildren = json['children'] as List?;
|
||||||
final jAttributes = json['attributes'] != null
|
final jAttributes = json['attributes'] != null
|
||||||
? Map<String, Object>.from(json['attributes'] as Map)
|
? Attributes.from(json['attributes'] as Map)
|
||||||
: <String, Object>{};
|
: Attributes.from({});
|
||||||
|
|
||||||
final LinkedList<Node> children = LinkedList();
|
final LinkedList<Node> children = LinkedList();
|
||||||
if (jChildren != null) {
|
if (jChildren != null) {
|
||||||
children.addAll(
|
children.addAll(
|
||||||
jChildren.map(
|
jChildren.map(
|
||||||
(jnode) => Node.fromJson(
|
(jChild) => Node.fromJson(
|
||||||
Map<String, Object>.from(jnode),
|
Map<String, Object>.from(jChild),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
@ -47,7 +49,7 @@ class Node extends LinkedListEntry<Node> {
|
|||||||
return node;
|
return node;
|
||||||
}
|
}
|
||||||
|
|
||||||
void updateAttributes(Map<String, Object> attributes) {
|
void updateAttributes(Attributes attributes) {
|
||||||
for (final attribute in attributes.entries) {
|
for (final attribute in attributes.entries) {
|
||||||
this.attributes[attribute.key] = attribute.value;
|
this.attributes[attribute.key] = attribute.value;
|
||||||
}
|
}
|
||||||
|
@ -6,7 +6,7 @@ class StateTree {
|
|||||||
|
|
||||||
StateTree({required this.root});
|
StateTree({required this.root});
|
||||||
|
|
||||||
factory StateTree.fromJson(Map<String, Object> json) {
|
factory StateTree.fromJson(Attributes json) {
|
||||||
assert(json['document'] is Map);
|
assert(json['document'] is Map);
|
||||||
|
|
||||||
final document = Map<String, Object>.from(json['document'] as Map);
|
final document = Map<String, Object>.from(json['document'] as Map);
|
||||||
@ -41,7 +41,7 @@ class StateTree {
|
|||||||
return deletedNode;
|
return deletedNode;
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, Object>? update(Path path, Map<String, Object> attributes) {
|
Attributes? update(Path path, Attributes attributes) {
|
||||||
if (path.isEmpty) {
|
if (path.isEmpty) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user