1
- import { omit , pick } from '../common/util.js' ;
1
+ import { asNumber , omit , pick } from '../common/util.js' ;
2
2
import type IgcTileManagerComponent from './tile-manager.js' ;
3
+ import type IgcTileComponent from './tile.js' ;
3
4
4
5
export interface SerializedTile {
5
6
colSpan : number ;
@@ -12,6 +13,8 @@ export interface SerializedTile {
12
13
rowSpan : number ;
13
14
rowStart : number | null ;
14
15
tileId : string | null ;
16
+ width : number | null ;
17
+ height : number | null ;
15
18
}
16
19
17
20
class TileManagerSerializer {
@@ -21,9 +24,15 @@ class TileManagerSerializer {
21
24
this . tileManager = tileManager ;
22
25
}
23
26
27
+ private _getResizeContainer ( tile : IgcTileComponent ) {
28
+ // biome-ignore lint/complexity/useLiteralKeys: Until we migrate to a symbol
29
+ return tile [ '_resizeContainer' ] ! ;
30
+ }
31
+
24
32
public save ( ) : SerializedTile [ ] {
25
33
return this . tileManager . tiles . map ( ( tile ) => {
26
34
const { gridColumn, gridRow } = getComputedStyle ( tile ) ;
35
+ const { width, height } = this . _getResizeContainer ( tile ) . getSize ( ) ;
27
36
28
37
return {
29
38
colSpan : tile . colSpan ,
@@ -36,6 +45,8 @@ class TileManagerSerializer {
36
45
rowSpan : tile . rowSpan ,
37
46
rowStart : tile . rowStart ,
38
47
tileId : tile . tileId ,
48
+ width : asNumber ( width ) || null ,
49
+ height : asNumber ( height ) || null ,
39
50
} ;
40
51
} ) ;
41
52
}
@@ -46,18 +57,26 @@ class TileManagerSerializer {
46
57
47
58
public load ( tiles : SerializedTile [ ] ) : void {
48
59
const mapped = new Map ( tiles . map ( ( tile ) => [ tile . tileId , tile ] ) ) ;
60
+ const keys : ( keyof SerializedTile ) [ ] = [
61
+ 'gridColumn' ,
62
+ 'gridRow' ,
63
+ 'width' ,
64
+ 'height' ,
65
+ ] ;
49
66
50
67
for ( const tile of this . tileManager . tiles ) {
51
68
if ( ! mapped . has ( tile . tileId ) ) {
52
69
continue ;
53
70
}
54
71
55
72
const serialized = mapped . get ( tile . tileId ) ! ;
56
- const properties = omit ( serialized , 'gridColumn' , 'gridRow' ) ;
73
+ const properties = omit ( serialized , ... keys ) ;
57
74
const styles = pick ( serialized , 'gridColumn' , 'gridRow' ) ;
75
+ const { width, height } = pick ( serialized , 'width' , 'height' ) ;
58
76
59
77
Object . assign ( tile , properties ) ;
60
78
Object . assign ( tile . style , styles ) ;
79
+ this . _getResizeContainer ( tile ) . setSize ( width , height ) ;
61
80
}
62
81
}
63
82
0 commit comments