@@ -20,12 +20,14 @@ import * as PureRenderDecorator from 'pure-render-decorator';
2020import * as React from 'react' ;
2121import { DragDropContext } from 'react-dnd' ;
2222import HTML5 from 'react-dnd-html5-backend' ;
23- import { MosaicActionsPropType , MosaicContext , MosaicRootActions } from './contextTypes' ;
23+ import { v4 as uuid } from 'uuid' ;
24+ import { MosaicContext , MosaicRootActions } from './contextTypes' ;
25+ import { MosaicDropTargetPosition } from './internalTypes' ;
2426import { MosaicWindowDropTarget } from './MosaicDropTarget' ;
2527import { MosaicTile } from './MosaicTile' ;
2628import { createExpandUpdate , createHideUpdate , createRemoveUpdate , updateTree } from './mosaicUpdates' ;
2729import { MosaicZeroStateFactory } from './MosaicZeroState' ;
28- import { MosaicDropTargetPosition , MosaicNode , MosaicPath , MosaicUpdate , TileRenderer } from './types' ;
30+ import { MosaicNode , MosaicPath , MosaicUpdate , TileRenderer } from './types' ;
2931
3032const { div } = React . DOM ;
3133const DEFAULT_EXPAND_PERCENTAGE = 70 ;
@@ -77,31 +79,32 @@ function isUncontrolled<T>(props: MosaicProps<T>): props is MosaicUncontrolledPr
7779 return ( props as MosaicUncontrolledProps < T > ) . initialValue != null ;
7880}
7981
80- interface State < T > {
82+ export interface MosaicState < T > {
8183 currentNode : MosaicNode < T > | null ;
84+ mosaicId : string ;
8285}
8386
8487@( DragDropContext ( HTML5 ) as ClassDecorator )
8588@PureRenderDecorator
86- class MosaicComponentClass < T > extends React . Component < MosaicProps < T > , State < T > > {
89+ export class Mosaic < T > extends React . Component < MosaicProps < T > , MosaicState < T > > {
8790 static defaultProps = {
8891 onChange : ( ) => void 0 ,
8992 resizeable : true ,
9093 zeroStateView : MosaicZeroStateFactory ( ) ,
9194 className : 'mosaic-blueprint-theme' ,
9295 } as any ;
9396
94- static childContextTypes = {
95- mosaicActions : MosaicActionsPropType ,
96- } ;
97+ static childContextTypes = MosaicContext ;
9798
98- state : State < T > = {
99+ state : MosaicState < T > = {
99100 currentNode : null ,
101+ mosaicId : uuid ( ) ,
100102 } ;
101103
102104 getChildContext ( ) : MosaicContext < T > {
103105 return {
104106 mosaicActions : this . actions ,
107+ mosaicId : this . state . mosaicId ,
105108 } ;
106109 }
107110
@@ -120,7 +123,7 @@ class MosaicComponentClass<T> extends React.Component<MosaicProps<T>, State<T>>
120123 getPath : this . getPath ,
121124 } ) ,
122125 div ( { className : 'drop-target-container' } ,
123- _ . values < string > ( MosaicDropTargetPosition ) . map ( ( position ) =>
126+ _ . values < MosaicDropTargetPosition > ( MosaicDropTargetPosition ) . map ( ( position ) =>
124127 MosaicWindowDropTarget ( {
125128 position,
126129 path : [ ] ,
@@ -134,7 +137,6 @@ class MosaicComponentClass<T> extends React.Component<MosaicProps<T>, State<T>>
134137 componentWillReceiveProps ( nextProps : MosaicProps < T > ) {
135138 if ( isUncontrolled ( nextProps ) &&
136139 nextProps . initialValue !== ( this . props as MosaicUncontrolledProps < T > ) . initialValue ) {
137-
138140 this . setState ( { currentNode : nextProps . initialValue } ) ;
139141 }
140142 }
@@ -194,11 +196,10 @@ class MosaicComponentClass<T> extends React.Component<MosaicProps<T>, State<T>>
194196 } ] ) ,
195197 } ;
196198}
197- export const Mosaic : React . ComponentClass < MosaicProps < any > > = MosaicComponentClass ;
198199
199200// Factory that works with generics
200201export function MosaicFactory < T > ( props : MosaicProps < T > & React . Attributes , ...children : React . ReactNode [ ] ) {
201202 const element : React . ReactElement < MosaicProps < T > > =
202- React . createElement ( MosaicComponentClass as React . ComponentClass < MosaicProps < T > > , props , ...children ) ;
203+ React . createElement ( Mosaic as React . ComponentClass < MosaicProps < T > > , props , ...children ) ;
203204 return element ;
204205}
0 commit comments