File tree 9 files changed +81
-16
lines changed
9 files changed +81
-16
lines changed Original file line number Diff line number Diff line change @@ -7,6 +7,14 @@ const layoutController = container.resolve(LayoutController);
7
7
const layoutService = container . resolve ( LayoutService ) ;
8
8
9
9
describe ( 'The layout controller' , ( ) => {
10
+ test ( 'Should support to listen to the Workbench did mount event' , ( ) => {
11
+ const mockFn = jest . fn ( ) ;
12
+ layoutService . onWorkbenchDidMount ( mockFn ) ;
13
+ layoutController . onWorkbenchDidMount ( ) ;
14
+
15
+ expect ( mockFn ) . toBeCalled ( ) ;
16
+ } ) ;
17
+
10
18
test ( 'Should support to execute onPaneSizeChange' , ( ) => {
11
19
const original = layoutService . setPaneSize ;
12
20
const mockFn = jest . fn ( ) ;
Original file line number Diff line number Diff line change @@ -2,8 +2,10 @@ import 'reflect-metadata';
2
2
import { container , singleton } from 'tsyringe' ;
3
3
import { Controller } from 'mo/react/controller' ;
4
4
import { ILayoutService , LayoutService } from 'mo/services' ;
5
+ import { LayoutEvents } from 'mo/model/workbench/layout' ;
5
6
6
7
export interface ILayoutController extends Partial < Controller > {
8
+ onWorkbenchDidMount ?: ( ) => void ;
7
9
onPaneSizeChange ?: ( splitPanePos : number [ ] ) => void ;
8
10
onHorizontalPaneSizeChange ?: ( horizontalSplitPanePos : number [ ] ) => void ;
9
11
}
@@ -26,4 +28,8 @@ export class LayoutController extends Controller implements ILayoutController {
26
28
public onHorizontalPaneSizeChange = ( horizontalSplitPanePos : number [ ] ) => {
27
29
this . layoutService . setHorizontalPaneSize ( horizontalSplitPanePos ) ;
28
30
} ;
31
+
32
+ public onWorkbenchDidMount = ( ) => {
33
+ this . layoutService . emit ( LayoutEvents . OnWorkbenchDidMount ) ;
34
+ } ;
29
35
}
Original file line number Diff line number Diff line change @@ -8,6 +8,10 @@ export enum MenuBarMode {
8
8
vertical = 'vertical' ,
9
9
}
10
10
11
+ export enum LayoutEvents {
12
+ OnWorkbenchDidMount = 'workbench.didMount' ,
13
+ }
14
+
11
15
export interface ViewVisibility {
12
16
hidden : boolean ;
13
17
}
Original file line number Diff line number Diff line change @@ -14,7 +14,7 @@ export interface IConfigProps {
14
14
defaultLocale ?: string ;
15
15
}
16
16
17
- namespace stanalone {
17
+ namespace standalone {
18
18
let instance : InstanceService | null = null ;
19
19
20
20
/**
@@ -37,12 +37,12 @@ namespace stanalone {
37
37
}
38
38
39
39
export default function create ( config : IConfigProps ) {
40
- return stanalone . create ( config ) ;
40
+ return standalone . create ( config ) ;
41
41
}
42
42
43
43
/**
44
44
* Do NOT call it in production, ONLY used for test cases
45
45
*/
46
46
export function clearInstance ( ) {
47
- stanalone . clearInstance ( ) ;
47
+ standalone . clearInstance ( ) ;
48
48
}
Original file line number Diff line number Diff line change 1
1
import { ID_APP } from 'mo/common/id' ;
2
- import { MenuBarMode , Position } from 'mo/model/workbench/layout' ;
2
+ import { LayoutEvents , MenuBarMode , Position } from 'mo/model/workbench/layout' ;
3
3
import 'reflect-metadata' ;
4
4
import { container } from 'tsyringe' ;
5
5
import { LayoutService } from '../workbench' ;
@@ -143,5 +143,14 @@ describe('The layout service', () => {
143
143
layoutService . setAuxiliaryBar ( ( pre ) => ! pre ) ;
144
144
expect ( layoutService . getState ( ) . auxiliaryBar . hidden ) . toBe ( true ) ;
145
145
} ) ;
146
+
147
+ test ( 'Should support to listen to the Workbench did mount event' , ( ) => {
148
+ const mockFn = jest . fn ( ) ;
149
+ layoutService . onWorkbenchDidMount ( mockFn ) ;
150
+
151
+ layoutService . emit ( LayoutEvents . OnWorkbenchDidMount ) ;
152
+
153
+ expect ( mockFn ) . toBeCalled ( ) ;
154
+ } ) ;
146
155
} ) ;
147
156
} ) ;
Original file line number Diff line number Diff line change @@ -122,7 +122,11 @@ export default class InstanceService
122
122
this . emit ( InstanceHookKind . beforeLoad ) ;
123
123
molecule . extension . load ( others ) ;
124
124
125
- molecule . monacoService . initWorkspace ( molecule . layout . container ! ) ;
125
+ molecule . layout . onWorkbenchDidMount ( ( ) => {
126
+ molecule . monacoService . initWorkspace (
127
+ molecule . layout . container !
128
+ ) ;
129
+ } ) ;
126
130
this . rendered = true ;
127
131
}
128
132
Original file line number Diff line number Diff line change 6
6
Position ,
7
7
LayoutModel ,
8
8
MenuBarMode ,
9
+ LayoutEvents ,
9
10
} from 'mo/model/workbench/layout' ;
10
11
import { MenuBarEvent } from 'mo/model/workbench/menuBar' ;
11
12
@@ -87,6 +88,11 @@ export interface ILayoutService extends Component<ILayout> {
87
88
* Reset all layout data as default value
88
89
*/
89
90
reset ( ) : void ;
91
+ /**
92
+ * Listen to the workbench did mount event
93
+ * @param callback callback function
94
+ */
95
+ onWorkbenchDidMount ( callback : Function ) : void ;
90
96
}
91
97
92
98
@singleton ( )
@@ -101,6 +107,10 @@ export class LayoutService
101
107
this . state = container . resolve ( LayoutModel ) ;
102
108
}
103
109
110
+ public onWorkbenchDidMount ( callback : Function ) : void {
111
+ this . subscribe ( LayoutEvents . OnWorkbenchDidMount , callback ) ;
112
+ }
113
+
104
114
public get container ( ) {
105
115
// Make sure to get the latest dom element.
106
116
this . _container = document . getElementById ( ID_APP ) || document . body ;
Original file line number Diff line number Diff line change 1
1
import 'reflect-metadata' ;
2
- import React from 'react' ;
2
+ import React , { useEffect } from 'react' ;
3
3
import { container } from 'tsyringe' ;
4
4
5
5
import {
@@ -60,6 +60,7 @@ export function WorkbenchView(props: IWorkbench & ILayout & ILayoutController) {
60
60
sidebar,
61
61
statusBar,
62
62
onPaneSizeChange,
63
+ onWorkbenchDidMount,
63
64
onHorizontalPaneSizeChange,
64
65
splitPanePos,
65
66
horizontalSplitPanePos,
@@ -122,6 +123,11 @@ export function WorkbenchView(props: IWorkbench & ILayout & ILayoutController) {
122
123
hideStatusBar
123
124
) ;
124
125
126
+ useEffect ( ( ) => {
127
+ // call onWorkbenchDidMount after the first render
128
+ onWorkbenchDidMount ?.( ) ;
129
+ } , [ ] ) ;
130
+
125
131
return (
126
132
< div id = { ID_APP } className = { appClassName } tabIndex = { 0 } >
127
133
< div className = { workbenchFinalClassName } >
Original file line number Diff line number Diff line change @@ -13,17 +13,35 @@ moInstance.onBeforeInit(() => {
13
13
molecule . builtin . inactiveModule ( 'activityBarData' ) ;
14
14
} ) ;
15
15
16
- export const IDEDemo = ( ) => moInstance . render ( < Workbench /> ) ;
17
-
18
- IDEDemo . story = {
19
- name : 'Workbench' ,
16
+ export default {
17
+ title : 'Workbench' ,
20
18
} ;
21
19
22
- if ( module . hot ) {
23
- module . hot . accept ( ) ;
24
- }
20
+ export const NormalWorkbench = ( ) => moInstance . render ( < Workbench /> ) ;
25
21
26
- export default {
27
- title : 'Workbench' ,
28
- component : IDEDemo ,
22
+ export const EmbeddedWorkbench = ( ) => {
23
+ return (
24
+ < div
25
+ style = { {
26
+ position : 'absolute' ,
27
+ width : '100%' ,
28
+ height : '100%' ,
29
+ top : 0 ,
30
+ left : 0 ,
31
+ } }
32
+ >
33
+ < h1 style = { { textAlign : 'center' , lineHeight : '40px' } } >
34
+ Embedded
35
+ </ h1 >
36
+ < div
37
+ style = { {
38
+ position : 'relative' ,
39
+ width : '100%' ,
40
+ height : 'calc(100% - 40px)' ,
41
+ } }
42
+ >
43
+ { moInstance . render ( < Workbench /> ) }
44
+ </ div >
45
+ </ div >
46
+ ) ;
29
47
} ;
You can’t perform that action at this time.
0 commit comments