parent
1a139d5e93
commit
d94c2a575e
11 changed files with 56 additions and 42 deletions
@ -0,0 +1,42 @@ |
|||||||
|
/// An object which can be embedded into a Quill document. |
||||||
|
/// |
||||||
|
/// See also: |
||||||
|
/// |
||||||
|
/// * [BlockEmbed] which represents a block embed. |
||||||
|
class Embeddable { |
||||||
|
const Embeddable(this.type, this.data); |
||||||
|
|
||||||
|
/// The type of this object. |
||||||
|
final String type; |
||||||
|
|
||||||
|
/// The data payload of this object. |
||||||
|
final dynamic data; |
||||||
|
|
||||||
|
Map<String, dynamic> toJson() { |
||||||
|
final m = <String, String>{type: data}; |
||||||
|
return m; |
||||||
|
} |
||||||
|
|
||||||
|
static Embeddable fromJson(Map<String, dynamic> json) { |
||||||
|
final m = Map<String, dynamic>.from(json); |
||||||
|
assert(m.length == 1, 'Embeddable map must only have one key'); |
||||||
|
|
||||||
|
return BlockEmbed(m.keys.first, m.values.first); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
/// An object which occupies an entire line in a document and cannot co-exist |
||||||
|
/// inline with regular text. |
||||||
|
/// |
||||||
|
/// There are two built-in embed types supported by Quill documents, however |
||||||
|
/// the document model itself does not make any assumptions about the types |
||||||
|
/// of embedded objects and allows users to define their own types. |
||||||
|
class BlockEmbed extends Embeddable { |
||||||
|
const BlockEmbed(String type, String data) : super(type, data); |
||||||
|
|
||||||
|
static const String imageType = 'image'; |
||||||
|
static BlockEmbed image(String imageUrl) => BlockEmbed(imageType, imageUrl); |
||||||
|
|
||||||
|
static const String videoType = 'video'; |
||||||
|
static BlockEmbed video(String videoUrl) => BlockEmbed(videoType, videoUrl); |
||||||
|
} |
@ -1,28 +0,0 @@ |
|||||||
/// An object which can be embedded into a Quill document. |
|
||||||
class Embeddable { |
|
||||||
const Embeddable(this.type, this.data); |
|
||||||
|
|
||||||
/// The type of this object. |
|
||||||
final String type; |
|
||||||
|
|
||||||
/// The data payload of this object. |
|
||||||
final String data; |
|
||||||
|
|
||||||
Map<String, String> toJson() { |
|
||||||
final m = <String, String>{type: data}; |
|
||||||
return m; |
|
||||||
} |
|
||||||
|
|
||||||
static Embeddable fromJson(Map<String, String> json) { |
|
||||||
final m = Map<String, String>.from(json); |
|
||||||
assert(m.length == 1, 'Embeddable map must only have one key'); |
|
||||||
|
|
||||||
return Embeddable(m.keys.single, m.values.single); |
|
||||||
} |
|
||||||
|
|
||||||
static const String imageType = 'image'; |
|
||||||
static Embeddable image(String imageUrl) => Embeddable(imageType, imageUrl); |
|
||||||
|
|
||||||
static const String videoType = 'video'; |
|
||||||
static Embeddable video(String videoUrl) => Embeddable(videoType, videoUrl); |
|
||||||
} |
|
Loading…
Reference in new issue