Line data Source code
1 : import 'package:flusmic/src/models/info/dimension.dart';
2 : import 'package:flusmic/src/models/types/simple/span/span.dart';
3 : import 'package:freezed_annotation/freezed_annotation.dart';
4 :
5 : import 'embed_data/embed_data.dart';
6 :
7 : part 'richable.freezed.dart';
8 : part 'richable.g.dart';
9 :
10 : ///Base class for items in RichText
11 : ///
12 : ///`RichableParagraph`, `RichableImage` or a `RichableEmbed`
13 : @Freezed(unionKey: 'type', unionValueCase: FreezedUnionCase.kebab)
14 : class Richable with _$Richable {
15 : ///RichableHeading1 model
16 : ///
17 : ///Represents a heading1 inside RichText
18 : const factory Richable.heading1({
19 : required List<Span> spans,
20 : required String text,
21 : required String type,
22 : }) = RichableHeading1;
23 :
24 : ///RichableHeading2 model
25 : ///
26 : ///Represents a heading2 inside RichText
27 : const factory Richable.heading2({
28 : required List<Span> spans,
29 : required String text,
30 : required String type,
31 : }) = RichableHeading2;
32 :
33 : ///RichableHeading3 model
34 : ///
35 : ///Represents a heading3 inside RichText
36 : const factory Richable.heading3({
37 : required List<Span> spans,
38 : required String text,
39 : required String type,
40 : }) = RichableHeading3;
41 :
42 : ///RichableHeading4 model
43 : ///
44 : ///Represents a heading4 inside RichText
45 : const factory Richable.heading4({
46 : required List<Span> spans,
47 : required String text,
48 : required String type,
49 : }) = RichableHeading4;
50 :
51 : ///RichableHeading5 model
52 : ///
53 : ///Represents a heading5 inside RichText
54 : const factory Richable.heading5({
55 : required List<Span> spans,
56 : required String text,
57 : required String type,
58 : }) = RichableHeading5;
59 :
60 : ///RichableHeading6 model
61 : ///
62 : ///Represents a heading6 inside RichText
63 : const factory Richable.heading6({
64 : required List<Span> spans,
65 : required String text,
66 : required String type,
67 : }) = RichableHeading6;
68 :
69 : ///RichableParagraph model
70 : ///
71 : ///Represents a paragraph inside RichText
72 : const factory Richable.paragraph({
73 : required List<Span> spans,
74 : required String text,
75 : required String type,
76 : }) = RichableParagraph;
77 :
78 : ///RichableListItem model
79 : ///
80 : ///Represents a list-item inside RichText
81 : @FreezedUnionValue('list-item')
82 : const factory Richable.listItem({
83 : required List<Span> spans,
84 : required String text,
85 : required String type,
86 : }) = RichableListItem;
87 :
88 : ///RichableListItem model
89 : ///
90 : ///Represents a list-item inside RichText
91 : @FreezedUnionValue('o-list-item')
92 : const factory Richable.orderedListItem({
93 : required List<Span> spans,
94 : required String text,
95 : required String type,
96 : }) = RichableOrderedListItem;
97 :
98 : ///RichableImage model
99 : ///
100 : ///Represents a image inside RichText
101 : const factory Richable.image({
102 : String? alt,
103 : String? copyright,
104 : required Dimension dimensions,
105 : required String url,
106 : }) = RichableImage;
107 :
108 : ///RichableEmbed model
109 : ///
110 : ///Represents an embed element inside RichText
111 : const factory Richable.embed({
112 : @JsonKey(name: 'oembed') required EmbedData info,
113 : required String type,
114 : }) = RichableEmbed;
115 :
116 : ///Creates a Richable object from json
117 : ///
118 : ///Can create a `EmbedImage`, `EmbedParagraph` or another `Embed`
119 : ///depending on type from json.
120 1 : factory Richable.fromJson(Map<String, dynamic> json) =>
121 1 : _$RichableFromJson(json);
122 : }
|