@@ -19,47 +19,139 @@ abstract class LayoutElement extends StyledElement {
19
19
20
20
class TableLayoutElement extends LayoutElement {
21
21
TableLayoutElement ({
22
+ String name,
23
+ Style style,
22
24
@required List <StyledElement > children,
23
- }) : super (children: children);
25
+ dom.Element node,
26
+ }) : super (name: name, style: style, children: children, node: node);
24
27
25
28
@override
26
29
Widget toWidget (RenderContext context) {
30
+
31
+ final colWidths = children.where ((c) => c.name == "colgroup" ).map ((group) {
32
+ return group.children.where ((c) => c.name == "col" ).map ((c) {
33
+ final widthStr = c.attributes["width" ] ?? "" ;
34
+ if (widthStr.endsWith ("%" )) {
35
+ final width = double .tryParse (widthStr.substring (0 , widthStr.length - 1 )) * 0.01 ;
36
+ return FractionColumnWidth (width);
37
+ } else {
38
+ final width = double .tryParse (widthStr);
39
+ return FixedColumnWidth (width);
40
+ }
41
+ });
42
+ }).expand ((i) => i).toList ().asMap ();
43
+
27
44
return Table (
28
- // children: children.where((e) => e.name == 'tr').map(),
45
+ columnWidths: colWidths,
46
+ children: children
47
+ .map ((c) {
48
+ if (c is TableSectionLayoutElement ) {
49
+ return c.toTableRows (context);
50
+ }
51
+ return null ;
52
+ })
53
+ .where ((t) {
54
+ return t != null ;
55
+ })
56
+ .toList ()
57
+ .expand ((i) => i)
58
+ .toList (),
29
59
);
30
60
}
31
61
}
32
62
63
+ class TableSectionLayoutElement extends LayoutElement {
64
+ TableSectionLayoutElement ({
65
+ String name,
66
+ @required List <StyledElement > children,
67
+ }) : super (name: name, children: children);
68
+
69
+ @override
70
+ Widget toWidget (RenderContext context) {
71
+ return Container (child: Text ("TABLE SECTION" ));
72
+ }
73
+
74
+ List <TableRow > toTableRows (RenderContext context) {
75
+ return children.map ((c) {
76
+ if (c is TableRowLayoutElement ) {
77
+ return c.toTableRow (context);
78
+ }
79
+ return null ;
80
+ }).where ((t) {
81
+ return t != null ;
82
+ }).toList ();
83
+ }
84
+ }
85
+
33
86
class TableRowLayoutElement extends LayoutElement {
34
87
TableRowLayoutElement ({
88
+ String name,
35
89
@required List <StyledElement > children,
36
- }) : super (children: children);
90
+ dom.Element node,
91
+ }) : super (name: name, children: children, node: node);
37
92
38
93
@override
39
94
Widget toWidget (RenderContext context) {
40
95
return Container (child: Text ("TABLE ROW" ));
41
96
}
42
97
43
98
TableRow toTableRow (RenderContext context) {
44
-
99
+ return TableRow (
100
+ children: children.map ((c) {
101
+ return RichText (text: context.parser.parseTree (context, c));
102
+ }).toList ());
45
103
}
46
104
}
47
105
48
- LayoutElement parseLayoutElement (dom.Element element, List <StyledElement > children) {
106
+ class TableStyleElement extends StyledElement {
107
+ TableStyleElement ({
108
+ String name,
109
+ List <StyledElement > children,
110
+ Style style,
111
+ dom.Element node,
112
+ }) : super (name: name, children: children, style: style, node: node);
113
+ }
114
+
115
+ TableStyleElement parseTableDefinitionElement (
116
+ dom.Element element, List <StyledElement > children) {
117
+ switch (element.localName) {
118
+ case "colgroup" :
119
+ case "col" :
120
+ return TableStyleElement (
121
+ name: element.localName,
122
+ children: children,
123
+ node: element
124
+ );
125
+ default :
126
+ return TableStyleElement ();
127
+ }
128
+ }
129
+ LayoutElement parseLayoutElement (
130
+ dom.Element element, List <StyledElement > children) {
49
131
switch (element.localName) {
50
132
case "table" :
51
133
return TableLayoutElement (
134
+ name: element.localName,
135
+ children: children,
136
+ node: element,
137
+ );
138
+ break ;
139
+ case "thead" :
140
+ case "tbody" :
141
+ case "tfoot" :
142
+ return TableSectionLayoutElement (
143
+ name: element.localName,
52
144
children: children,
53
145
);
54
146
break ;
55
147
case "tr" :
56
- return TableLayoutElement (
148
+ return TableRowLayoutElement (
149
+ name: element.localName,
57
150
children: children,
151
+ node: element
58
152
);
59
153
break ;
60
154
default :
61
- return TableLayoutElement (
62
- children: children
63
- );
155
+ return TableLayoutElement (children: children);
64
156
}
65
157
}
0 commit comments