DocumentJsonCodec constructor
DocumentJsonCodec({
- Iterable<
TextAttributeCodec< attributes = const [],TextAttribute> > - Iterable<
LineModifierCodec< lineModifiers = const [],LineModifier> > - Iterable<
ParagraphEmbedCodec< embeds = const [],ParagraphEmbed> >
Create a codec to convert a document to or from JSON with codecs for attributes, line modifiers and embeds that are supported for conversion.
Implementation
factory DocumentJsonCodec({
Iterable<TextAttributeCodec> attributes = const [],
Iterable<LineModifierCodec> lineModifiers = const [],
Iterable<ParagraphEmbedCodec> embeds = const [],
}) {
final decoder = _JsonDecoder(
attributeDecoders:
{for (final ac in attributes) ac.typeStr: ac.decode}.build(),
lineModifierDecoders:
{for (final lc in lineModifiers) lc.typeStr: lc.decode}.build(),
embedDecoders: {for (final lc in embeds) lc.typeStr: lc.decode}.build(),
);
final encoder = _JsonEncoder(
attributes: {for (final attr in attributes) attr.type: attr}.build(),
lineModifiers: {for (final lc in lineModifiers) lc.type: lc}.build(),
embeds: {for (final embed in embeds) embed.type: embed}.build(),
);
return DocumentJsonCodec._(decoder, encoder);
}