|
21 | 21 | :mime |
22 | 22 | :source |
23 | 23 | v-bind="$attrs" |
24 | | - @loaded="onLoaded" |
| 24 | + @loaded="onLoadedHandler" |
25 | 25 | @edit="toggleEdit" /> |
26 | 26 | </template> |
27 | 27 |
|
28 | | -<script> |
| 28 | +<script setup lang="ts"> |
29 | 29 | import { getSharingToken } from '@nextcloud/sharing/public' |
30 | | -import { defineComponent } from 'vue' |
| 30 | +import { computed, onMounted, provide, ref, useAttrs } from 'vue' |
31 | 31 | import EditorReloader from './EditorReloader.vue' |
32 | 32 | import SourceView from './SourceView.vue' |
33 | 33 |
|
34 | | -export default defineComponent({ |
35 | | - name: 'ViewerComponent', |
36 | | - components: { |
37 | | - SourceView, |
38 | | - EditorReloader, |
39 | | - }, |
40 | | -
|
41 | | - provide() { |
42 | | - return { |
43 | | - isEmbedded: this.isEmbedded, |
44 | | - } |
45 | | - }, |
46 | | -
|
| 34 | +defineOptions({ |
47 | 35 | inheritAttrs: false, |
48 | | - props: { |
49 | | - filename: { |
50 | | - type: String, |
51 | | - default: null, |
52 | | - }, |
53 | | -
|
54 | | - fileid: { |
55 | | - type: Number, |
56 | | - default: null, |
57 | | - }, |
58 | | -
|
59 | | - active: { |
60 | | - type: Boolean, |
61 | | - default: false, |
62 | | - }, |
63 | | -
|
64 | | - autofocus: { |
65 | | - type: Boolean, |
66 | | - // This is a public interface for Viewer we cannot change for now. |
67 | | - // eslint-disable-next-line vue/no-boolean-default |
68 | | - default: true, |
69 | | - }, |
70 | | -
|
71 | | - shareToken: { |
72 | | - type: String, |
73 | | - default: () => getSharingToken(), |
74 | | - }, |
75 | | -
|
76 | | - mime: { |
77 | | - type: String, |
78 | | - default: null, |
79 | | - }, |
80 | | -
|
81 | | - source: { |
82 | | - type: String, |
83 | | - default: undefined, |
84 | | - }, |
85 | | -
|
86 | | - isEmbedded: { |
87 | | - type: Boolean, |
88 | | - default: false, |
89 | | - }, |
90 | | -
|
91 | | - onLoadedHandler: { |
92 | | - type: Function, |
93 | | - default: () => {}, |
94 | | - }, |
95 | | - }, |
96 | | -
|
97 | | - data() { |
98 | | - return { |
99 | | - hasToggledInteractiveEmbedding: false, |
100 | | - } |
101 | | - }, |
102 | | -
|
103 | | - computed: { |
104 | | - /** @return {boolean} */ |
105 | | - useSourceView() { |
106 | | - return ( |
107 | | - this.source |
108 | | - && (!this.fileid |
109 | | - || this.isEmbedded |
110 | | - || this.isEncrypted) |
111 | | - && !this.hasToggledInteractiveEmbedding |
112 | | - ) |
113 | | - }, |
114 | | -
|
115 | | - isEncrypted() { |
116 | | - return this.$attrs.e2EeIsEncrypted || false |
117 | | - }, |
118 | | - }, |
119 | | -
|
120 | | - mounted() { |
121 | | - if (!this.useSourceView) { |
122 | | - this.onLoaded() |
123 | | - } |
124 | | - }, |
125 | | -
|
126 | | - methods: { |
127 | | - async onLoaded() { |
128 | | - this.onLoadedHandler() |
129 | | - }, |
130 | | -
|
131 | | - toggleEdit() { |
132 | | - this.hasToggledInteractiveEmbedding = true |
133 | | - }, |
134 | | -
|
135 | | - t, |
136 | | - }, |
137 | 36 | }) |
| 37 | +
|
| 38 | +const { |
| 39 | + filename = undefined, |
| 40 | + fileid = undefined, |
| 41 | + // This is a public interface for Viewer we cannot change for now. |
| 42 | + // eslint-disable-next-line vue/no-boolean-default |
| 43 | + autofocus = true, |
| 44 | + shareToken = getSharingToken(), |
| 45 | + mime = undefined, |
| 46 | + source = undefined, |
| 47 | + onLoadedHandler = () => {}, |
| 48 | + ...props |
| 49 | +} = defineProps <{ |
| 50 | + filename?: string | undefined |
| 51 | + fileid?: number | undefined |
| 52 | + active: boolean |
| 53 | + autofocus?: boolean |
| 54 | + shareToken?: string |
| 55 | + mime?: string | undefined |
| 56 | + source?: string | undefined |
| 57 | + isEmbedded: boolean |
| 58 | + onLoadedHandler?: () => void |
| 59 | +}>() |
| 60 | +
|
| 61 | +provide('isEmbedded', props.isEmbedded) |
| 62 | +
|
| 63 | +const hasToggledInteractiveEmbedding = ref(false) |
| 64 | +
|
| 65 | +const attrs = useAttrs() |
| 66 | +const isEncrypted = computed(() => Boolean(attrs.e2EeIsEncrypted)) |
| 67 | +
|
| 68 | +const useSourceView = computed(() => source |
| 69 | + && (!fileid |
| 70 | + || props.isEmbedded |
| 71 | + || isEncrypted.value) |
| 72 | + && !hasToggledInteractiveEmbedding.value) |
| 73 | +
|
| 74 | +onMounted(() => { |
| 75 | + if (!useSourceView.value) { |
| 76 | + onLoadedHandler() |
| 77 | + } |
| 78 | +}) |
| 79 | +
|
| 80 | +/** |
| 81 | + * Toggle interactive editing |
| 82 | + */ |
| 83 | +function toggleEdit() { |
| 84 | + hasToggledInteractiveEmbedding.value = true |
| 85 | +} |
| 86 | +
|
138 | 87 | </script> |
139 | 88 |
|
140 | 89 | <style lang="scss" scoped> |
|
0 commit comments