@@ -18,23 +18,23 @@ along with this program. If not, see <http://www.gnu.org/licenses/>.
18
18
<div ref =" main" class =" main pa-2 fill-height" >
19
19
<!-- Lumino box panel gets inserted here -->
20
20
</div >
21
- <div v-show =" false" >
22
- <!-- Hidden div acts as staging area for views before they are
23
- moved into a lumino widget -->
24
- <component
25
- v-for =" (item, id) of views"
26
- :key =" id"
27
- :ref =" (ref) => setViewRef(id, ref)"
28
- :is =" item.view"
29
- :tab-title =" getTabTitle(item.view)"
30
- :workflow-name =" workflowName"
31
- :initialOptions =" item.initialOptions"
32
- class =" h-100"
33
- />
34
- </div >
21
+ <template
22
+ v-for =" (item , id ) in views "
23
+ :key =" id "
24
+ >
25
+ <Teleport :to =" `#${id}`" >
26
+ <component
27
+ :is =" item.view"
28
+ :workflow-name =" workflowName"
29
+ :initialOptions =" item.initialOptions"
30
+ class =" h-100"
31
+ />
32
+ </Teleport >
33
+ </template >
35
34
</template >
36
35
37
36
<script >
37
+ import { startCase } from ' lodash'
38
38
import LuminoWidget from ' @/components/cylc/workflow/lumino-widget'
39
39
import { BoxPanel , DockPanel , Widget } from ' @lumino/widgets'
40
40
@@ -74,27 +74,17 @@ export default {
74
74
type: Array ,
75
75
required: true
76
76
},
77
- /**
78
- * Prop to customize the tab title. Defaults to name.
79
- * If a component does not have the $component.$tabTitleProp
80
- * set, then we still revert to the old default $component.name.
81
- */
82
- tabTitleProp: {
83
- type: String ,
84
- default: ' name'
85
- }
86
77
},
87
78
88
79
emits: [
89
80
' lumino:activated' ,
90
81
' lumino:deleted'
91
82
],
92
83
93
- data () {
94
- return {
95
- /** Keep track of views' refs separate from $refs in order to access
96
- * by ID */
97
- viewRefs: {}
84
+ beforeCreate () {
85
+ // Populate components
86
+ for (const { name , component } of this .allViews ) {
87
+ this .$options .components [name] = component
98
88
}
99
89
},
100
90
@@ -103,12 +93,6 @@ export default {
103
93
* Box panel. In the next tick of Vue, the DOM element and the Vue element/ref are attached.
104
94
*/
105
95
created () {
106
- // We need to load each view used by this view/component.
107
- // See "local-registration" in Vue.js documentation.
108
- this .allViews .forEach (view => {
109
- this .$options .components [view .name ] = view
110
- })
111
-
112
96
// create a box panel, which holds the dock panel, and controls its layout
113
97
this .box = new BoxPanel ({ direction: ' left-to-right' , spacing: 0 })
114
98
// create dock panel, which holds the widgets
@@ -152,40 +136,27 @@ export default {
152
136
},
153
137
154
138
methods: {
155
- /** Keep track of views' refs separate from $refs, allowing access by ID */
156
- setViewRef (id , ref ) {
157
- if (ref) {
158
- this .viewRefs [id] = ref
159
- } else {
160
- delete this .viewRefs [id]
161
- }
162
- },
163
139
/**
164
140
* Look for newly added views, creating a corresponding Lumino Widget
165
141
* for each.
166
142
*/
167
143
syncWidgets (newVal , oldVal ) {
168
- const { tabTitleProp } = this .$props
169
144
for (const [id , item ] of Object .entries (newVal)) {
170
145
if (! (id in oldVal)) {
171
- const view = this .$options .components [item .view ]
172
- const name = view[tabTitleProp] ?? view .name
173
- this .addWidget (id, name)
146
+ this .addWidget (id, item .view )
174
147
}
175
148
}
176
149
},
177
150
178
151
/**
179
- * Create a widget, add it to the dock, and move the corresponding view
180
- * from the hidden div into it.
152
+ * Create a widget and add it to the dock.
181
153
*/
182
154
addWidget (id , name , onTop = true ) {
183
- const luminoWidget = new LuminoWidget (id, name, /* closable */ true )
155
+ const luminoWidget = new LuminoWidget (id, startCase ( name) , /* closable */ true )
184
156
this .dock .addWidget (luminoWidget, { mode: ' tab-after' })
185
157
// give time for Lumino's widget DOM element to be created
186
158
this .$nextTick (() => {
187
159
const widgetEl = document .getElementById (id)
188
- widgetEl .appendChild (this .viewRefs [id].$el )
189
160
widgetEl .addEventListener (' lumino:activated' , this .onWidgetActivated )
190
161
widgetEl .addEventListener (' lumino:deleted' , this .onWidgetDeleted )
191
162
if (onTop) {
@@ -227,10 +198,6 @@ export default {
227
198
widgetEl .removeEventListener (' lumino:activated' , this .onWidgetActivated )
228
199
this .$emit (' lumino:deleted' , customEvent .detail )
229
200
},
230
-
231
- getTabTitle (viewName ) {
232
- return this .$options .components [viewName].data ().widget .title
233
- }
234
201
}
235
202
}
236
203
</script >
0 commit comments