@@ -64,17 +64,12 @@ class TableLayoutElement extends LayoutElement {
64
64
final rowSizes =
65
65
List .generate (rows.length, (_) => IntrinsicContentTrackSize ());
66
66
67
- // Calculate column bounds to handle rowspan skipping
68
- int columnMax = rows.map ((row) {
69
- return row.children
70
- .where ((tag) => tag.name == "th" || tag.name == "td" )
71
- .fold (0 , (int value, child) {
72
- final colspanText = child.attributes["colspan" ];
73
- final colspan =
74
- colspanText == null ? 1 : int .tryParse (colspanText) ?? 1 ;
75
- return value + colspan;
76
- });
77
- }).fold (0 , max);
67
+ // Calculate column bounds
68
+ int columnMax = rows
69
+ .map ((row) => row.children
70
+ .whereType <TableCellElement >()
71
+ .fold (0 , (int value, child) => value + child.colspan))
72
+ .fold (0 , max);
78
73
79
74
final cells = < GridPlacement > [];
80
75
final columnRowOffset = List .generate (columnMax + 1 , (_) => 0 );
@@ -86,13 +81,7 @@ class TableLayoutElement extends LayoutElement {
86
81
columnRowOffset[columni] = columnRowOffset[columni] - 1 ;
87
82
columni++ ;
88
83
}
89
- if (child.name == "th" || child.name == "td" ) {
90
- final colspanText = child.attributes["colspan" ];
91
- final rowspanText = child.attributes["rowspan" ];
92
- final colspan =
93
- colspanText == null ? 1 : int .tryParse (colspanText) ?? 1 ;
94
- final rowspan =
95
- rowspanText == null ? 1 : int .tryParse (rowspanText) ?? 1 ;
84
+ if (child is TableCellElement ) {
96
85
cells.add (GridPlacement (
97
86
child: Container (
98
87
width: double .infinity,
@@ -107,12 +96,12 @@ class TableLayoutElement extends LayoutElement {
107
96
),
108
97
),
109
98
columnStart: columni,
110
- columnSpan: colspan,
99
+ columnSpan: child. colspan,
111
100
rowStart: rowi,
112
- rowSpan: rowspan,
101
+ rowSpan: child. rowspan,
113
102
));
114
- columnRowOffset[columni] = rowspan - 1 ;
115
- columni += colspan;
103
+ columnRowOffset[columni] = child. rowspan - 1 ;
104
+ columni += child. colspan;
116
105
}
117
106
}
118
107
rowi++ ;
@@ -163,6 +152,52 @@ class TableRowLayoutElement extends LayoutElement {
163
152
}
164
153
}
165
154
155
+ class TableCellElement extends StyledElement {
156
+ int colspan = 1 ;
157
+ int rowspan = 1 ;
158
+
159
+ TableCellElement ({
160
+ String name,
161
+ String elementId,
162
+ List <String > elementClasses,
163
+ @required List <StyledElement > children,
164
+ Style style,
165
+ dom.Element node,
166
+ }) : super (
167
+ name: name,
168
+ elementId: elementId,
169
+ elementClasses: elementClasses,
170
+ children: children,
171
+ style: style,
172
+ node: node) {
173
+ colspan = _parseSpan (this , "colspan" );
174
+ rowspan = _parseSpan (this , "rowspan" );
175
+ }
176
+
177
+ static int _parseSpan (StyledElement element, String attributeName) {
178
+ final spanValue = element.attributes[attributeName];
179
+ return spanValue == null ? 1 : int .tryParse (spanValue) ?? 1 ;
180
+ }
181
+ }
182
+
183
+ TableCellElement parseTableCellElement (dom.Element element,
184
+ List <StyledElement > children,
185
+ ) {
186
+ final cell = TableCellElement (
187
+ name: element.localName,
188
+ elementId: element.id,
189
+ elementClasses: element.classes.toList (),
190
+ children: children,
191
+ node: element,
192
+ );
193
+ if (element.localName == "th" ) {
194
+ cell.style = Style (
195
+ fontWeight: FontWeight .bold,
196
+ );
197
+ }
198
+ return cell;
199
+ }
200
+
166
201
class TableStyleElement extends StyledElement {
167
202
TableStyleElement ({
168
203
String name,
0 commit comments