1- import { omit , pick } from '../common/util.js' ;
1+ import { asNumber , omit , pick } from '../common/util.js' ;
22import type IgcTileManagerComponent from './tile-manager.js' ;
3+ import type IgcTileComponent from './tile.js' ;
34
45export interface SerializedTile {
56 colSpan : number ;
@@ -12,6 +13,8 @@ export interface SerializedTile {
1213 rowSpan : number ;
1314 rowStart : number | null ;
1415 tileId : string | null ;
16+ width : number | null ;
17+ height : number | null ;
1518}
1619
1720class TileManagerSerializer {
@@ -21,9 +24,15 @@ class TileManagerSerializer {
2124 this . tileManager = tileManager ;
2225 }
2326
27+ private _getResizeContainer ( tile : IgcTileComponent ) {
28+ // biome-ignore lint/complexity/useLiteralKeys: Until we migrate to a symbol
29+ return tile [ '_resizeContainer' ] ! ;
30+ }
31+
2432 public save ( ) : SerializedTile [ ] {
2533 return this . tileManager . tiles . map ( ( tile ) => {
2634 const { gridColumn, gridRow } = getComputedStyle ( tile ) ;
35+ const { width, height } = this . _getResizeContainer ( tile ) . getSize ( ) ;
2736
2837 return {
2938 colSpan : tile . colSpan ,
@@ -36,6 +45,8 @@ class TileManagerSerializer {
3645 rowSpan : tile . rowSpan ,
3746 rowStart : tile . rowStart ,
3847 tileId : tile . tileId ,
48+ width : asNumber ( width ) || null ,
49+ height : asNumber ( height ) || null ,
3950 } ;
4051 } ) ;
4152 }
@@ -46,18 +57,26 @@ class TileManagerSerializer {
4657
4758 public load ( tiles : SerializedTile [ ] ) : void {
4859 const mapped = new Map ( tiles . map ( ( tile ) => [ tile . tileId , tile ] ) ) ;
60+ const keys : ( keyof SerializedTile ) [ ] = [
61+ 'gridColumn' ,
62+ 'gridRow' ,
63+ 'width' ,
64+ 'height' ,
65+ ] ;
4966
5067 for ( const tile of this . tileManager . tiles ) {
5168 if ( ! mapped . has ( tile . tileId ) ) {
5269 continue ;
5370 }
5471
5572 const serialized = mapped . get ( tile . tileId ) ! ;
56- const properties = omit ( serialized , 'gridColumn' , 'gridRow' ) ;
73+ const properties = omit ( serialized , ... keys ) ;
5774 const styles = pick ( serialized , 'gridColumn' , 'gridRow' ) ;
75+ const { width, height } = pick ( serialized , 'width' , 'height' ) ;
5876
5977 Object . assign ( tile , properties ) ;
6078 Object . assign ( tile . style , styles ) ;
79+ this . _getResizeContainer ( tile ) . setSize ( width , height ) ;
6180 }
6281 }
6382
0 commit comments