diff --git a/frontend/app_flowy/packages/flowy_editor/assets/document.json b/frontend/app_flowy/packages/flowy_editor/assets/document.json index 5c9ca5175b..715b6c4e64 100644 --- a/frontend/app_flowy/packages/flowy_editor/assets/document.json +++ b/frontend/app_flowy/packages/flowy_editor/assets/document.json @@ -40,7 +40,6 @@ "attributes": { "url": "x.mp4" } - } ] } diff --git a/frontend/app_flowy/packages/flowy_editor/lib/document/node.dart b/frontend/app_flowy/packages/flowy_editor/lib/document/node.dart index 743ae6fd15..e4ff84b99c 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/document/node.dart +++ b/frontend/app_flowy/packages/flowy_editor/lib/document/node.dart @@ -1,11 +1,13 @@ import 'dart:collection'; import 'package:flowy_editor/document/path.dart'; +typedef Attributes = Map; + class Node extends LinkedListEntry { Node? parent; final String type; final LinkedList children; - final Map attributes; + final Attributes attributes; Node({ required this.type, @@ -20,15 +22,15 @@ class Node extends LinkedListEntry { final jType = json['type'] as String; final jChildren = json['children'] as List?; final jAttributes = json['attributes'] != null - ? Map.from(json['attributes'] as Map) - : {}; + ? Attributes.from(json['attributes'] as Map) + : Attributes.from({}); final LinkedList children = LinkedList(); if (jChildren != null) { children.addAll( jChildren.map( - (jnode) => Node.fromJson( - Map.from(jnode), + (jChild) => Node.fromJson( + Map.from(jChild), ), ), ); @@ -47,7 +49,7 @@ class Node extends LinkedListEntry { return node; } - void updateAttributes(Map attributes) { + void updateAttributes(Attributes attributes) { for (final attribute in attributes.entries) { this.attributes[attribute.key] = attribute.value; } diff --git a/frontend/app_flowy/packages/flowy_editor/lib/document/state_tree.dart b/frontend/app_flowy/packages/flowy_editor/lib/document/state_tree.dart index 57b601c0e2..368b575c90 100644 --- a/frontend/app_flowy/packages/flowy_editor/lib/document/state_tree.dart +++ b/frontend/app_flowy/packages/flowy_editor/lib/document/state_tree.dart @@ -6,7 +6,7 @@ class StateTree { StateTree({required this.root}); - factory StateTree.fromJson(Map json) { + factory StateTree.fromJson(Attributes json) { assert(json['document'] is Map); final document = Map.from(json['document'] as Map); @@ -41,7 +41,7 @@ class StateTree { return deletedNode; } - Map? update(Path path, Map attributes) { + Attributes? update(Path path, Attributes attributes) { if (path.isEmpty) { return null; }