@@ -61,7 +61,7 @@ class Paragraph {
6161 String ? id,
6262 }) : _lines = List <Line >.from (lines),
6363 id = id == null || id.trim ().isEmpty ? nanoid (8 ) : id,
64- _sealed = type == ParagraphType .block
64+ _sealed = type == ParagraphType .block || type == ParagraphType .embed
6565 ? true
6666 : lines.isNotEmpty && lines.length == 1 && lines.first.isNotEmpty
6767 ? lines.first.length > 1
@@ -80,22 +80,37 @@ class Paragraph {
8080 _sealed = true ;
8181
8282 @visibleForTesting
83- factory Paragraph .fragment (TextFragment frag, {String ? id}) {
83+ factory Paragraph .fragment (
84+ TextFragment frag, {
85+ String ? id,
86+ Map <String , dynamic >? blockAttributes,
87+ }) {
8488 return Paragraph .sealed (
8589 id: id,
8690 lines: < Line > [
8791 Line (fragments: < TextFragment > [frag.clone])
8892 ],
89- type: ParagraphType .inline,
93+ type: frag.data is ! String
94+ ? ParagraphType .embed
95+ : frag.data == '\n '
96+ ? ParagraphType .lineBreak
97+ : blockAttributes != null
98+ ? ParagraphType .block
99+ : ParagraphType .inline,
100+ blockAttributes:
101+ blockAttributes? .isNotEmpty ?? false ? blockAttributes : null ,
90102 );
91103 }
92104
93- factory Paragraph .withLine ({String ? id}) {
105+ factory Paragraph .withLine ({
106+ String ? id,
107+ Iterable <TextFragment >? fragments,
108+ }) {
94109 return Paragraph (
95110 id: id,
96111 lines: < Line > [
97112 Line (
98- fragments: [],
113+ fragments: [... ? fragments ],
99114 ),
100115 ],
101116 type: ParagraphType .inline,
@@ -114,14 +129,14 @@ class Paragraph {
114129 Map <String , dynamic >? blockAttributes,
115130 String ? id,
116131 }) {
117- return Paragraph (
132+ return Paragraph . sealed (
118133 id: id,
119134 lines: < Line > [
120135 Line .newLine (),
121136 ],
122137 blockAttributes: blockAttributes,
123138 type: ParagraphType .lineBreak,
124- ).. seal () ;
139+ );
125140 }
126141
127142 /// Constructs a [Paragraph] instance from a Object embed.
@@ -132,7 +147,7 @@ class Paragraph {
132147 Map <String , dynamic >? blockAttributes,
133148 String ? id,
134149 }) {
135- return Paragraph (
150+ return Paragraph . sealed (
136151 id: id,
137152 lines: < Line > [
138153 Line .fromData (data: data, attributes: attributes),
@@ -143,23 +158,31 @@ class Paragraph {
143158 ? ParagraphType .block
144159 : ParagraphType .inline
145160 : ParagraphType .embed,
146- ).. seal () ;
161+ );
147162 }
148163
149164 /// Constructs a [Paragraph] instance from a Quill Delta embed operation.
150165 ///
151166 /// This factory method creates a paragraph with a single line from the provided embed operation.
152167 ///
153168 /// [operation] is the Quill Delta operation representing the embed.
154- factory Paragraph .fromEmbed (fq.Operation operation, {String ? id}) {
155- return Paragraph (
169+ factory Paragraph .fromEmbed (
170+ fq.Operation operation, {
171+ String ? id,
172+ Map <String , dynamic >? blockAttributes,
173+ }) {
174+ final bool isInlineOp = operation.data is String ;
175+ return Paragraph .sealed (
156176 id: id,
157177 lines: < Line > [
158- Line .fromData (data: operation.data! , attributes: operation.attributes),
178+ Line .fromData (
179+ data: operation.data! ,
180+ attributes: operation.attributes,
181+ ),
159182 ],
160- type :
161- operation.data is String ? ParagraphType .inline : ParagraphType .embed,
162- ).. seal () ;
183+ blockAttributes : blockAttributes,
184+ type : isInlineOp ? ParagraphType .inline : ParagraphType .embed,
185+ );
163186 }
164187
165188 /// Get all the Lines into this Paragraph
0 commit comments