1- import { ContextProvider , consume } from '@lit/context' ;
1+ import { ContextProvider } from '@lit/context' ;
22import { LitElement , type PropertyValues , html } from 'lit' ;
33import { property , query , state } from 'lit/decorators.js' ;
44import { styleMap } from 'lit/directives/style-map.js' ;
55import { themes } from '../../theming/theming-decorator.js' ;
66import {
77 type TileContext ,
8- type TileManagerContext ,
98 tileContext ,
109 tileManagerContext ,
1110} from '../common/context.js' ;
11+ import { createAsyncContext } from '../common/controllers/async-consumer.js' ;
1212import { registerComponent } from '../common/definitions/register.js' ;
1313import type { Constructor } from '../common/mixins/constructor.js' ;
1414import { EventEmitterMixin } from '../common/mixins/event-emitter.js' ;
@@ -113,14 +113,16 @@ export default class IgcTileComponent extends EventEmitterMixin<
113113
114114 // Tile manager context properties and helpers
115115
116- @consume ( { context : tileManagerContext , subscribe : true } )
117- private _managerContext ?: TileManagerContext ;
116+ private _managerContext = createAsyncContext ( this , tileManagerContext ) ;
117+
118+ private get _tileManager ( ) {
119+ return this . _managerContext . value ;
120+ }
118121
119122 private _createContext ( ) : TileContext {
120123 return {
121124 instance : this ,
122- setFullscreenState : ( fullscreen ) =>
123- this . _fullscreenController . setState ( fullscreen ) ,
125+ fullscreenController : this . _fullscreenController ,
124126 } ;
125127 }
126128
@@ -134,12 +136,12 @@ export default class IgcTileComponent extends EventEmitterMixin<
134136 }
135137
136138 private get _draggedItem ( ) : IgcTileComponent | null {
137- return this . _managerContext ?. draggedItem ?? null ;
139+ return this . _tileManager ?. draggedItem ?? null ;
138140 }
139141
140142 private get _isSlideMode ( ) : boolean {
141- return this . _managerContext
142- ? this . _managerContext . instance . dragMode === 'slide'
143+ return this . _tileManager
144+ ? this . _tileManager . instance . dragMode === 'slide'
143145 : true ;
144146 }
145147
@@ -227,8 +229,8 @@ export default class IgcTileComponent extends EventEmitterMixin<
227229 this . _maximized = value ;
228230 this . _setTileContext ( ) ;
229231
230- if ( this . _managerContext ) {
231- this . _managerContext . instance . requestUpdate ( ) ;
232+ if ( this . _tileManager ) {
233+ this . _tileManager . instance . requestUpdate ( ) ;
232234 }
233235 }
234236
@@ -274,9 +276,7 @@ export default class IgcTileComponent extends EventEmitterMixin<
274276
275277 protected get gridColumnWidth ( ) : number {
276278 const tileManager =
277- this . _managerContext ! . instance ! . shadowRoot ! . querySelector (
278- "[part~='base']"
279- ) ! ;
279+ this . _tileManager ! . instance ! . shadowRoot ! . querySelector ( "[part~='base']" ) ! ;
280280
281281 const gridTemplateColumns = getComputedStyle ( tileManager ) . getPropertyValue (
282282 'grid-template-columns'
@@ -365,26 +365,22 @@ export default class IgcTileComponent extends EventEmitterMixin<
365365 return ;
366366 }
367367
368+ const tileManager = this . _tileManager ! ;
369+
368370 if ( isSameTile ( this , this . _draggedItem ) ) {
369371 this . _tileContent . style . visibility = 'hidden' ;
370372 if ( this . _dragGhost ) {
371373 Object . assign ( this . _dragGhost . style , {
372374 visibility : 'visible' ,
373375 } ) ;
374376 }
375- if ( this . _managerContext ) {
376- this . _managerContext . lastSwapTile = null ;
377- }
377+ tileManager . lastSwapTile = null ;
378378 } else if ( this . _isSlideMode ) {
379379 if (
380- this . _managerContext &&
381- ( ! this . _managerContext . lastSwapTile ||
382- this . hasPointerLeftLastSwapTile (
383- event ,
384- this . _managerContext . lastSwapTile
385- ) )
380+ ! tileManager . lastSwapTile ||
381+ this . hasPointerLeftLastSwapTile ( event , tileManager . lastSwapTile )
386382 ) {
387- this . _managerContext . lastSwapTile = this ;
383+ tileManager . lastSwapTile = this ;
388384 swapTiles ( this , this . _draggedItem ! ) ;
389385 }
390386 }
@@ -435,8 +431,8 @@ export default class IgcTileComponent extends EventEmitterMixin<
435431 pointerY < rect . top ||
436432 pointerY > rect . bottom ;
437433
438- if ( outsideBoundaries && this . _managerContext ) {
439- this . _managerContext . lastSwapTile = null ;
434+ if ( outsideBoundaries ) {
435+ this . _tileManager ! . lastSwapTile = null ;
440436 }
441437
442438 return outsideBoundaries ;
0 commit comments