9
9
TabContextMenuEvent ,
10
10
} from '../../dockview/options' ;
11
11
import { IGroupPanelApi } from '../../api/groupPanelApi' ;
12
+ import { usePortalsLifecycle } from '../react' ;
12
13
13
14
export interface IGroupPanelProps {
14
15
api : IGroupPanelApi ;
@@ -51,23 +52,12 @@ export interface IDockviewComponentProps {
51
52
export const DockviewComponent : React . FunctionComponent < IDockviewComponentProps > = (
52
53
props : IDockviewComponentProps
53
54
) => {
54
- const domReference = React . useRef < HTMLDivElement > ( ) ;
55
- const layoutReference = React . useRef < ComponentDockview > ( ) ;
55
+ const domRef = React . useRef < HTMLDivElement > ( ) ;
56
+ const dockviewRef = React . useRef < ComponentDockview > ( ) ;
56
57
57
- const [ portals , setPortals ] = React . useState < React . ReactPortal [ ] > ( [ ] ) ;
58
+ const [ portals , addPortal ] = usePortalsLifecycle ( ) ;
58
59
59
60
React . useEffect ( ( ) => {
60
- const addPortal = ( p : React . ReactPortal ) => {
61
- setPortals ( ( portals ) => [ ...portals , p ] ) ;
62
- return {
63
- dispose : ( ) => {
64
- setPortals ( ( portals ) =>
65
- portals . filter ( ( portal ) => portal !== p )
66
- ) ;
67
- } ,
68
- } ;
69
- } ;
70
-
71
61
const factory : GroupPanelFrameworkComponentFactory = {
72
62
content : {
73
63
createComponent : (
@@ -95,7 +85,7 @@ export const DockviewComponent: React.FunctionComponent<IDockviewComponentProps>
95
85
96
86
const element = document . createElement ( 'div' ) ;
97
87
98
- const layout = new ComponentDockview ( element , {
88
+ const dockview = new ComponentDockview ( element , {
99
89
frameworkComponentFactory : factory ,
100
90
frameworkComponents : props . components ,
101
91
frameworkTabComponents : props . tabComponents ,
@@ -105,28 +95,28 @@ export const DockviewComponent: React.FunctionComponent<IDockviewComponentProps>
105
95
// orientation: props.orientation,
106
96
} ) ;
107
97
108
- layoutReference . current = layout ;
109
- domReference . current . appendChild ( layoutReference . current . element ) ;
110
-
111
- layout . deserializer = new ReactPanelDeserialzier ( layout ) ;
112
-
113
- layout . resizeToFit ( ) ;
98
+ domRef . current . appendChild ( dockview . element ) ;
99
+ dockview . deserializer = new ReactPanelDeserialzier ( dockview ) ;
114
100
115
101
if ( props . serializedLayout ) {
116
- layout . deserialize ( props . serializedLayout ) ;
102
+ dockview . deserialize ( props . serializedLayout ) ;
117
103
}
118
104
105
+ dockview . resizeToFit ( ) ;
106
+
119
107
if ( props . onReady ) {
120
- props . onReady ( { api : layout } ) ;
108
+ props . onReady ( { api : dockview } ) ;
121
109
}
122
110
111
+ dockviewRef . current = dockview ;
112
+
123
113
return ( ) => {
124
- layout . dispose ( ) ;
114
+ dockview . dispose ( ) ;
125
115
} ;
126
116
} , [ ] ) ;
127
117
128
118
React . useEffect ( ( ) => {
129
- const disposable = layoutReference . current . onTabContextMenu ( ( event ) => {
119
+ const disposable = dockviewRef . current . onTabContextMenu ( ( event ) => {
130
120
props . onTabContextMenu ( event ) ;
131
121
} ) ;
132
122
@@ -136,9 +126,7 @@ export const DockviewComponent: React.FunctionComponent<IDockviewComponentProps>
136
126
} , [ props . onTabContextMenu ] ) ;
137
127
138
128
React . useEffect ( ( ) => {
139
- layoutReference . current . setAutoResizeToFit (
140
- props . autoSizeToFitContainer
141
- ) ;
129
+ dockviewRef . current . setAutoResizeToFit ( props . autoSizeToFitContainer ) ;
142
130
} , [ props . autoSizeToFitContainer ] ) ;
143
131
144
132
return (
@@ -147,7 +135,7 @@ export const DockviewComponent: React.FunctionComponent<IDockviewComponentProps>
147
135
// height: '100%',
148
136
width : '100%' ,
149
137
} }
150
- ref = { domReference }
138
+ ref = { domRef }
151
139
>
152
140
{ portals }
153
141
</ div >
0 commit comments