@@ -24,15 +24,15 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
24
24
:id =" id"
25
25
>
26
26
<component
27
- :is =" props.allViews.get(name).component"
27
+ :is =" props.allViews.get(name)! .component"
28
28
:workflow-name =" workflowName"
29
- v-model:initial-options =" views.get(id).initialOptions"
29
+ v-model:initial-options =" views.get(id)! .initialOptions"
30
30
class =" h-100"
31
31
/>
32
32
</WidgetComponent >
33
33
</template >
34
34
35
- <script setup>
35
+ <script setup lang="ts" >
36
36
import {
37
37
nextTick ,
38
38
onBeforeUnmount ,
@@ -45,8 +45,14 @@ import WidgetComponent from '@/components/cylc/workspace/Widget.vue'
45
45
import LuminoWidget from ' @/components/cylc/workspace/lumino-widget'
46
46
import { BoxPanel , DockPanel , Widget } from ' @lumino/widgets'
47
47
import { when } from ' @/utils'
48
- import { useDefaultView } from ' @/views/views'
49
- import { eventBus } from ' @/services/eventBus'
48
+ import {
49
+ useDefaultView ,
50
+ type CylcView
51
+ } from ' @/views/views'
52
+ import {
53
+ eventBus ,
54
+ type AddViewEvent
55
+ } from ' @/services/eventBus'
50
56
51
57
/*
52
58
* A component to wrap the Lumino application.
@@ -58,47 +64,25 @@ import { eventBus } from '@/services/eventBus'
58
64
* works, but there could be alternative approaches too.
59
65
*/
60
66
61
- /**
62
- * Mitt event for adding a view to the workspace.
63
- * @typedef {Object} AddViewEvent
64
- * @property {string} name - the view to add
65
- * @property {Record<string,*>} initialOptions - prop passed to the view component
66
- */
67
-
68
67
const $store = useStore ()
69
68
70
- const props = defineProps ({
71
- workflowName: {
72
- type: String ,
73
- required: true
74
- },
75
- /**
76
- * All possible view component classes that can be rendered
77
- *
78
- * @type {Map<string, import('@/views/views').CylcView>}
79
- */
80
- allViews: {
81
- type: Map ,
82
- required: true
83
- },
84
- })
69
+ const props = defineProps <{
70
+ workflowName: string
71
+ /** All possible view component classes that can be rendered */
72
+ allViews: Map <string , CylcView >
73
+ }>()
85
74
86
75
const emit = defineEmits ([
87
76
' emptied'
88
77
])
89
78
90
- /**
91
- * Template ref
92
- * @type {import('vue').Ref<HTMLElement>}
93
- */
94
- const mainDiv = ref (null )
79
+ /** Template ref */
80
+ const mainDiv = ref <HTMLElement >()
95
81
96
82
/**
97
83
* Mapping of widget ID to the name of view component and its initialOptions prop.
98
- *
99
- * @type {import('vue').Ref<Map<string, AddViewEvent>>}
100
84
*/
101
- const views = ref (new Map ())
85
+ const views = ref (new Map < string , AddViewEvent > ())
102
86
103
87
const defaultView = useDefaultView ()
104
88
@@ -113,11 +97,14 @@ const resizeObserver = new ResizeObserver(() => {
113
97
boxPanel .update ()
114
98
})
115
99
116
- onMounted (( ) => {
100
+ when ( mainDiv , ( div ) => {
117
101
// Attach box panel to DOM:
118
- Widget .attach (boxPanel, mainDiv . value )
102
+ Widget .attach (boxPanel , div )
119
103
// Watch for resize of the main element to trigger relayout:
120
- resizeObserver .observe (mainDiv .value )
104
+ resizeObserver .observe (div )
105
+ })
106
+
107
+ onMounted (() => {
121
108
eventBus .on (' add-view' , addView )
122
109
eventBus .on (' lumino:deleted' , onWidgetDeleted )
123
110
getLayout (props .workflowName )
@@ -135,13 +122,13 @@ onBeforeUnmount(() => {
135
122
136
123
/**
137
124
* Create a widget and add it to the dock.
138
- *
139
- * @param {AddViewEvent} event
140
- * @param {boolean} onTop
141
125
*/
142
- const addView = ({ name, initialOptions = {} }, onTop = true ) => {
126
+ const addView = (
127
+ { name , initialOptions = {} }: AddViewEvent ,
128
+ onTop : boolean = true
129
+ ) => {
143
130
const id = uniqueId (' widget' )
144
- const luminoWidget = new LuminoWidget (id, startCase (name), /* closable */ true )
131
+ const luminoWidget = new LuminoWidget (id , startCase (name ))
145
132
dockPanel .addWidget (luminoWidget , { mode: ' tab-after' })
146
133
// give time for Lumino's widget DOM element to be created
147
134
nextTick (() => {
@@ -164,10 +151,8 @@ const closeAllViews = () => {
164
151
/**
165
152
* Get the saved layout (if there is one) for the given workflow,
166
153
* else add the default view.
167
- *
168
- * @param {string} workflowName
169
154
*/
170
- const getLayout = (workflowName ) => {
155
+ const getLayout = (workflowName : string ) => {
171
156
restoreLayout (workflowName ) || addView ({ name: defaultView .value })
172
157
}
173
158
@@ -185,10 +170,9 @@ const saveLayout = () => {
185
170
/**
186
171
* Restore the layout for this workflow from the store, if it was saved.
187
172
*
188
- * @param {string} workflowName
189
- * @returns {boolean} true if the layout was restored, false otherwise
173
+ * @returns true if the layout was restored, false otherwise
190
174
*/
191
- const restoreLayout = (workflowName ) => {
175
+ const restoreLayout = (workflowName : string ) : boolean => {
192
176
const stored = $store .state .app .workspaceLayouts .get (workflowName )
193
177
if (stored ) {
194
178
dockPanel .restoreLayout (stored .layout )
@@ -205,9 +189,9 @@ const restoreLayout = (workflowName) => {
205
189
/**
206
190
* Save & close the current layout and open the one for the given workflow.
207
191
*
208
- * @param {string} workflowName
192
+ * @param workflowName
209
193
*/
210
- const changeLayout = (workflowName ) => {
194
+ const changeLayout = (workflowName : string ) => {
211
195
saveLayout ()
212
196
closeAllViews ()
213
197
// Wait if necessary for the workflowName prop to be updated to the new value:
@@ -220,9 +204,9 @@ const changeLayout = (workflowName) => {
220
204
/**
221
205
* React to a deleted event.
222
206
*
223
- * @param {string} id - widget ID
207
+ * @param id - widget ID
224
208
*/
225
- const onWidgetDeleted = (id ) => {
209
+ const onWidgetDeleted = (id : string ) => {
226
210
views .value .delete (id )
227
211
if (! views .value .size ) {
228
212
emit (' emptied' )
0 commit comments