@@ -24,6 +24,8 @@ class TableCell extends Block {
24
24
return undefined ;
25
25
}
26
26
27
+ next : this | null ;
28
+
27
29
cellOffset ( ) {
28
30
if ( this . parent ) {
29
31
return this . parent . children . indexOf ( this ) ;
@@ -56,15 +58,17 @@ class TableCell extends Block {
56
58
}
57
59
58
60
class TableRow extends Container {
61
+ static blotName = 'table-row' ;
62
+ static tagName = 'TR' ;
63
+
64
+ children : LinkedList < TableCell > ;
65
+ next : this | null ;
66
+
59
67
checkMerge ( ) {
60
68
if ( super . checkMerge ( ) && this . next . children . head != null ) {
61
- // @ts -expect-error all children are table cells
62
69
const thisHead = this . children . head . formats ( ) ;
63
- // @ts -expect-error all children are table cells
64
70
const thisTail = this . children . tail . formats ( ) ;
65
- // @ts -expect-error all children are table cells
66
71
const nextHead = this . next . children . head . formats ( ) ;
67
- // @ts -expect-error all children are table cells
68
72
const nextTail = this . next . children . tail . formats ( ) ;
69
73
return (
70
74
thisHead . table === thisTail . table &&
@@ -78,10 +82,9 @@ class TableRow extends Container {
78
82
optimize ( ...args ) {
79
83
// @ts -expect-error
80
84
super . optimize ( ...args ) ;
81
- ( this . children as LinkedList < TableCell > ) . forEach ( child => {
85
+ this . children . forEach ( child => {
82
86
if ( child . next == null ) return ;
83
87
const childFormats = child . formats ( ) ;
84
- // @ts -expect-error
85
88
const nextFormats = child . next . formats ( ) ;
86
89
if ( childFormats . table !== nextFormats . table ) {
87
90
const next = this . splitAfter ( child ) ;
@@ -109,14 +112,20 @@ class TableRow extends Container {
109
112
return this . parent && this . parent . parent ;
110
113
}
111
114
}
112
- TableRow . blotName = 'table-row' ;
113
- TableRow . tagName = 'TR' ;
114
115
115
- class TableBody extends Container { }
116
- TableBody . blotName = 'table-body' ;
117
- TableBody . tagName = 'TBODY' ;
116
+ class TableBody extends Container {
117
+ static blotName = 'table-body' ;
118
+ static tagName = 'TBODY' ;
119
+
120
+ children : LinkedList < TableRow > ;
121
+ }
118
122
119
123
class TableContainer extends Container {
124
+ static blotName = 'table-container' ;
125
+ static tagName = 'TABLE' ;
126
+
127
+ children : LinkedList < TableBody > ;
128
+
120
129
balanceCells ( ) {
121
130
// @ts -expect-error TODO: fix signature of ParentBlot.descendants
122
131
const rows = this . descendants ( TableRow ) as TableRow [ ] ;
@@ -137,16 +146,16 @@ class TableContainer extends Container {
137
146
} ) ;
138
147
}
139
148
140
- cells ( column ) {
149
+ cells ( column : number ) {
141
150
return this . rows ( ) . map ( row => row . children . at ( column ) ) ;
142
151
}
143
152
144
- deleteColumn ( index ) {
153
+ deleteColumn ( index : number ) {
145
154
// @ts -expect-error
146
155
const [ body ] = this . descendant ( TableBody ) as TableBody [ ] ;
147
156
if ( body == null || body . children . head == null ) return ;
148
157
body . children . forEach ( row => {
149
- const cell = ( row as TableRow ) . children . at ( index ) ;
158
+ const cell = row . children . at ( index ) ;
150
159
if ( cell != null ) {
151
160
cell . remove ( ) ;
152
161
}
@@ -157,7 +166,7 @@ class TableContainer extends Container {
157
166
// @ts -expect-error
158
167
const [ body ] = this . descendant ( TableBody ) as TableBody [ ] ;
159
168
if ( body == null || body . children . head == null ) return ;
160
- ( body . children as LinkedList < TableRow > ) . forEach ( row => {
169
+ body . children . forEach ( row => {
161
170
const ref = row . children . at ( index ) ;
162
171
const value = TableCell . formats ( row . children . head . domNode ) ;
163
172
const cell = this . scroll . create ( TableCell . blotName , value ) ;
@@ -171,7 +180,6 @@ class TableContainer extends Container {
171
180
if ( body == null || body . children . head == null ) return ;
172
181
const id = tableId ( ) ;
173
182
const row = this . scroll . create ( TableRow . blotName ) as TableRow ;
174
- // @ts -expect-error
175
183
body . children . head . children . forEach ( ( ) => {
176
184
const cell = this . scroll . create ( TableCell . blotName , id ) ;
177
185
row . appendChild ( cell ) ;
@@ -183,12 +191,9 @@ class TableContainer extends Container {
183
191
rows ( ) {
184
192
const body = this . children . head ;
185
193
if ( body == null ) return [ ] ;
186
- // @ts -expect-error
187
194
return body . children . map ( row => row ) ;
188
195
}
189
196
}
190
- TableContainer . blotName = 'table-container' ;
191
- TableContainer . tagName = 'TABLE' ;
192
197
193
198
TableContainer . allowedChildren = [ TableBody ] ;
194
199
TableBody . requiredContainer = TableContainer ;
0 commit comments