Skip to content

Commit c721af4

Browse files
committed
fix(viewer): mount ViewerComponent Vue from text module
The component configured in the viewer handler is instantiated from the vue module inside the viewer. We want to use our own vue module so create an instance with an import of our own vue and mount it. This fixes warnings in development like $attrs is readonly. Also makes the vue2 dev tools work. Signed-off-by: Max <max@nextcloud.com>
1 parent 39ece01 commit c721af4

4 files changed

Lines changed: 45 additions & 5 deletions

File tree

src/apis/connect.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ export async function open(
5353
/**
5454
* Update the guest name
5555
* @param guestName the name to use for the local user
56-
* @param connection connection to close
56+
* @param connection connection to update the guest name for
5757
*/
5858
export async function update(
5959
guestName: string,

src/components/ViewerComponent.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@
2626

2727
<script>
2828
import { getSharingToken } from '@nextcloud/sharing/public'
29+
import { defineComponent } from 'vue'
2930
import getEditorInstance from './Editor.singleton.js'
3031
import SourceView from './SourceView.vue'
3132
32-
export default {
33+
export default defineComponent({
3334
name: 'ViewerComponent',
3435
components: {
3536
SourceView,
@@ -112,7 +113,7 @@ export default {
112113
},
113114
t,
114115
},
115-
}
116+
})
116117
</script>
117118
<style lang="scss" scoped>
118119
.text-editor:not(.viewer__file--hidden) {

src/viewer.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,10 @@ import { openMimetypesMarkdown, openMimetypesPlainText } from './helpers/mime.js
1212
* Wrapper for async registration of ViewerComponent.
1313
* Note: it should be named function - the name is used for component registration.
1414
*
15-
* @return {Promise<import('./components/ViewerComponent.vue')>} ViewerComponent
15+
* @return {Promise<import('./views/ViewerView.js')>} ViewerComponent
1616
*/
1717
function AsyncTextViewerComponent() {
18-
return import('./components/ViewerComponent.vue')
18+
return import('./views/ViewerView.js')
1919
}
2020

2121
if (typeof OCA.Viewer === 'undefined') {

src/views/ViewerView.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/**
2+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
3+
* SPDX-License-Identifier: AGPL-3.0-or-later
4+
*/
5+
6+
import Vue, { defineComponent } from 'vue'
7+
import ViewerComponent from '../components/ViewerComponent.vue'
8+
9+
// The vue instance used inside text constructed with the import above.
10+
let innerVue
11+
12+
/**
13+
* This thin Component wrapper can be rendered inside the viewer.
14+
*
15+
* The viewers vue instance is used for this component as it simply exports
16+
* the options for the options api.
17+
*
18+
* When mounted this component constructs the vue instance
19+
* used inside text based on texts vue import.
20+
*/
21+
export default defineComponent({
22+
name: 'ViewerView',
23+
render: (h) => h('div'),
24+
props: ViewerComponent.props,
25+
mounted() {
26+
innerVue = new Vue({
27+
render: (h) => {
28+
return h(ViewerComponent, {
29+
props: this.$props,
30+
on: this.$listeners,
31+
})
32+
},
33+
})
34+
innerVue.$mount(this.$el)
35+
},
36+
beforeDestroy() {
37+
innerVue.$destroy()
38+
},
39+
})

0 commit comments

Comments
 (0)