Skip to content

Commit 28d37f7

Browse files
authored
Merge pull request #5579 from nextcloud/fix/5532
fix: Make edit mode in interactive widgets opt-in
2 parents e4a84b6 + 4badeff commit 28d37f7

2 files changed

Lines changed: 44 additions & 4 deletions

File tree

src/components/Editor.vue

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
:has-connection-issue="hasConnectionIssue"
3434
@reconnect="reconnect" />
3535

36-
<SkeletonLoading v-if="!contentLoaded && !displayedStatus" />
36+
<SkeletonLoading v-if="showLoadingSkeleton" />
3737
<Wrapper v-if="displayed"
3838
:sync-error="syncError"
3939
:has-connection-issue="hasConnectionIssue"
@@ -286,6 +286,9 @@ export default {
286286
displayedStatus() {
287287
return this.displayed || !!this.syncError
288288
},
289+
showLoadingSkeleton() {
290+
return (!this.contentLoaded || !this.displayed) && !this.syncError
291+
},
289292
renderRichEditorMenus() {
290293
return this.contentLoaded
291294
&& this.isRichEditor

src/components/ViewerComponent.vue

Lines changed: 40 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,29 +27,45 @@
2727
:active="active || isEmbedded"
2828
:autofocus="autofocus"
2929
:share-token="shareToken"
30+
:class="{ 'text-editor--embedding': isEmbedded }"
3031
:mime="mime"
3132
:show-outline-outside="showOutlineOutside" />
3233
<div v-else
3334
id="editor-container"
3435
data-text-el="editor-container"
3536
class="text-editor source-viewer">
3637
<Component :is="readerComponent" :content="content" />
38+
<NcButton v-if="isEmbedded" class="toggle-interactive" @click="toggleEdit">
39+
{{ t('text', 'Edit') }}
40+
<template #icon>
41+
<PencilIcon />
42+
</template>
43+
</NcButton>
3744
</div>
3845
</template>
3946

4047
<script>
48+
import Vue from 'vue'
4149
import axios from '@nextcloud/axios'
50+
import PencilIcon from 'vue-material-design-icons/Pencil.vue'
51+
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
4252
import PlainTextReader from './PlainTextReader.vue'
4353
import RichTextReader from './RichTextReader.vue'
54+
import { translate, translatePlural } from '@nextcloud/l10n'
4455
4556
import { getSharingToken } from '../helpers/token.js'
4657
import getEditorInstance from './Editor.singleton.js'
4758
59+
Vue.prototype.t = translate
60+
Vue.prototype.n = translatePlural
61+
4862
export default {
4963
name: 'ViewerComponent',
5064
components: {
51-
RichTextReader,
52-
PlainTextReader,
65+
NcButton: Vue.extend(NcButton),
66+
PencilIcon: Vue.extend(PencilIcon),
67+
RichTextReader: Vue.extend(RichTextReader),
68+
PlainTextReader: Vue.extend(PlainTextReader),
5369
Editor: getEditorInstance,
5470
},
5571
provide() {
@@ -102,12 +118,13 @@ export default {
102118
data() {
103119
return {
104120
content: '',
121+
hasToggledInteractiveEmbedding: false,
105122
}
106123
},
107124
computed: {
108125
/** @return {boolean} */
109126
useSourceView() {
110-
return this.source && (this.fileVersion || !this.fileid)
127+
return this.source && (this.fileVersion || !this.fileid || this.isEmbedded) && !this.hasToggledInteractiveEmbedding
111128
},
112129
113130
/** @return {boolean} */
@@ -127,6 +144,7 @@ export default {
127144
},
128145
129146
methods: {
147+
t: translate,
130148
async loadFileContent() {
131149
if (this.useSourceView) {
132150
const response = await axios.get(this.source)
@@ -135,6 +153,9 @@ export default {
135153
}
136154
this.$emit('update:loaded', true)
137155
},
156+
toggleEdit() {
157+
this.hasToggledInteractiveEmbedding = true
158+
},
138159
},
139160
}
140161
</script>
@@ -151,10 +172,26 @@ export default {
151172
background-color: var(--color-main-background);
152173
153174
&.source-viewer {
175+
display: block;
176+
154177
.text-editor__content-wrapper {
155178
margin-top: var(--header-height);
156179
}
180+
181+
.toggle-interactive {
182+
position: sticky;
183+
bottom: 0;
184+
right: 0;
185+
z-index: 1;
186+
margin-left: auto;
187+
margin-right: 0;
188+
}
189+
}
190+
191+
&.text-editor--embedding {
192+
min-height: 400px;
157193
}
194+
158195
}
159196
</style>
160197
<style lang="scss">

0 commit comments

Comments
 (0)