@@ -49,6 +49,7 @@ export type SerializedTableNode = Spread<
49
49
colWidths ?: readonly number [ ] ;
50
50
rowStriping ?: boolean ;
51
51
frozenColumnCount ?: number ;
52
+ frozenRowCount ?: number ;
52
53
} ,
53
54
SerializedElementNode
54
55
> ;
@@ -103,6 +104,20 @@ function setFrozenColumns(
103
104
}
104
105
}
105
106
107
+ function setFrozenRows (
108
+ dom : HTMLElement ,
109
+ config : EditorConfig ,
110
+ frozenRowCount : number ,
111
+ ) : void {
112
+ if ( frozenRowCount > 0 ) {
113
+ addClassNamesToElement ( dom , config . theme . tableFrozenRow ) ;
114
+ dom . setAttribute ( 'data-lexical-frozen-row' , 'true' ) ;
115
+ } else {
116
+ removeClassNamesFromElement ( dom , config . theme . tableFrozenRow ) ;
117
+ dom . removeAttribute ( 'data-lexical-frozen-row' ) ;
118
+ }
119
+ }
120
+
106
121
function alignTableElement (
107
122
dom : HTMLElement ,
108
123
config : EditorConfig ,
@@ -153,6 +168,7 @@ export class TableNode extends ElementNode {
153
168
/** @internal */
154
169
__rowStriping : boolean ;
155
170
__frozenColumnCount : number ;
171
+ __frozenRowCount : number ;
156
172
__colWidths ?: readonly number [ ] ;
157
173
158
174
static getType ( ) : string {
@@ -181,6 +197,7 @@ export class TableNode extends ElementNode {
181
197
this . __colWidths = prevNode . __colWidths ;
182
198
this . __rowStriping = prevNode . __rowStriping ;
183
199
this . __frozenColumnCount = prevNode . __frozenColumnCount ;
200
+ this . __frozenRowCount = prevNode . __frozenRowCount ;
184
201
}
185
202
186
203
static importDOM ( ) : DOMConversionMap | null {
@@ -201,13 +218,15 @@ export class TableNode extends ElementNode {
201
218
. updateFromJSON ( serializedNode )
202
219
. setRowStriping ( serializedNode . rowStriping || false )
203
220
. setFrozenColumns ( serializedNode . frozenColumnCount || 0 )
221
+ . setFrozenRows ( serializedNode . frozenRowCount || 0 )
204
222
. setColWidths ( serializedNode . colWidths ) ;
205
223
}
206
224
207
225
constructor ( key ?: NodeKey ) {
208
226
super ( key ) ;
209
227
this . __rowStriping = false ;
210
228
this . __frozenColumnCount = 0 ;
229
+ this . __frozenRowCount = 0 ;
211
230
}
212
231
213
232
exportJSON ( ) : SerializedTableNode {
@@ -217,6 +236,7 @@ export class TableNode extends ElementNode {
217
236
frozenColumnCount : this . __frozenColumnCount
218
237
? this . __frozenColumnCount
219
238
: undefined ,
239
+ frozenRowCount : this . __frozenRowCount ? this . __frozenRowCount : undefined ,
220
240
rowStriping : this . __rowStriping ? this . __rowStriping : undefined ,
221
241
} ;
222
242
}
@@ -259,6 +279,9 @@ export class TableNode extends ElementNode {
259
279
if ( this . __frozenColumnCount ) {
260
280
setFrozenColumns ( tableElement , config , this . __frozenColumnCount ) ;
261
281
}
282
+ if ( this . __frozenRowCount ) {
283
+ setFrozenRows ( tableElement , config , this . __frozenRowCount ) ;
284
+ }
262
285
if ( this . __rowStriping ) {
263
286
setRowStriping ( tableElement , config , true ) ;
264
287
}
@@ -284,6 +307,9 @@ export class TableNode extends ElementNode {
284
307
if ( prevNode . __frozenColumnCount !== this . __frozenColumnCount ) {
285
308
setFrozenColumns ( dom , config , this . __frozenColumnCount ) ;
286
309
}
310
+ if ( prevNode . __frozenRowCount !== this . __frozenRowCount ) {
311
+ setFrozenRows ( dom , config , this . __frozenRowCount ) ;
312
+ }
287
313
updateColgroup ( dom , config , this . getColumnCount ( ) , this . getColWidths ( ) ) ;
288
314
alignTableElement (
289
315
this . getDOMSlot ( dom ) . element ,
@@ -510,6 +536,16 @@ export class TableNode extends ElementNode {
510
536
return this . getLatest ( ) . __frozenColumnCount ;
511
537
}
512
538
539
+ setFrozenRows ( rowCount : number ) : this {
540
+ const self = this . getWritable ( ) ;
541
+ self . __frozenRowCount = rowCount ;
542
+ return self ;
543
+ }
544
+
545
+ getFrozenRows ( ) : number {
546
+ return this . getLatest ( ) . __frozenRowCount ;
547
+ }
548
+
513
549
canSelectBefore ( ) : true {
514
550
return true ;
515
551
}
0 commit comments