Skip to content

Commit

Permalink
Merge pull request #5596 from nextcloud/backport/5579/stable29
Browse files Browse the repository at this point in the history
  • Loading branch information
juliushaertl committed Apr 3, 2024
2 parents f3e6c54 + 23d6ff9 commit ddcfddf
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
5 changes: 4 additions & 1 deletion src/components/Editor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
:has-connection-issue="hasConnectionIssue"
@reconnect="reconnect" />

<SkeletonLoading v-if="!contentLoaded && !displayedStatus" />
<SkeletonLoading v-if="showLoadingSkeleton" />
<Wrapper v-if="displayed"
:sync-error="syncError"
:has-connection-issue="hasConnectionIssue"
Expand Down Expand Up @@ -286,6 +286,9 @@ export default {
displayedStatus() {
return this.displayed || !!this.syncError
},
showLoadingSkeleton() {
return (!this.contentLoaded || !this.displayed) && !this.syncError
},
renderRichEditorMenus() {
return this.contentLoaded
&& this.isRichEditor
Expand Down
43 changes: 40 additions & 3 deletions src/components/ViewerComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -27,29 +27,45 @@
:active="active || isEmbedded"
:autofocus="autofocus"
:share-token="shareToken"
:class="{ 'text-editor--embedding': isEmbedded }"
:mime="mime"
:show-outline-outside="showOutlineOutside" />
<div v-else
id="editor-container"
data-text-el="editor-container"
class="text-editor source-viewer">
<Component :is="readerComponent" :content="content" />
<NcButton v-if="isEmbedded" class="toggle-interactive" @click="toggleEdit">
{{ t('text', 'Edit') }}
<template #icon>
<PencilIcon />
</template>
</NcButton>
</div>
</template>

<script>
import Vue from 'vue'
import axios from '@nextcloud/axios'
import PencilIcon from 'vue-material-design-icons/Pencil.vue'
import NcButton from '@nextcloud/vue/dist/Components/NcButton.js'
import PlainTextReader from './PlainTextReader.vue'
import RichTextReader from './RichTextReader.vue'
import { translate, translatePlural } from '@nextcloud/l10n'
import { getSharingToken } from '../helpers/token.js'
import getEditorInstance from './Editor.singleton.js'
Vue.prototype.t = translate
Vue.prototype.n = translatePlural
export default {
name: 'ViewerComponent',
components: {
RichTextReader,
PlainTextReader,
NcButton: Vue.extend(NcButton),
PencilIcon: Vue.extend(PencilIcon),
RichTextReader: Vue.extend(RichTextReader),
PlainTextReader: Vue.extend(PlainTextReader),
Editor: getEditorInstance,
},
provide() {
Expand Down Expand Up @@ -102,12 +118,13 @@ export default {
data() {
return {
content: '',
hasToggledInteractiveEmbedding: false,
}
},
computed: {
/** @return {boolean} */
useSourceView() {
return this.source && (this.fileVersion || !this.fileid)
return this.source && (this.fileVersion || !this.fileid || this.isEmbedded) && !this.hasToggledInteractiveEmbedding
},
/** @return {boolean} */
Expand All @@ -127,6 +144,7 @@ export default {
},
methods: {
t: translate,
async loadFileContent() {
if (this.useSourceView) {
const response = await axios.get(this.source)
Expand All @@ -135,6 +153,9 @@ export default {
}
this.$emit('update:loaded', true)
},
toggleEdit() {
this.hasToggledInteractiveEmbedding = true
},
},
}
</script>
Expand All @@ -151,10 +172,26 @@ export default {
background-color: var(--color-main-background);
&.source-viewer {
display: block;
.text-editor__content-wrapper {
margin-top: var(--header-height);
}
.toggle-interactive {
position: sticky;
bottom: 0;
right: 0;
z-index: 1;
margin-left: auto;
margin-right: 0;
}
}
&.text-editor--embedding {
min-height: 400px;
}
}
</style>
<style lang="scss">
Expand Down

0 comments on commit ddcfddf

Please sign in to comment.