Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(ViewerComponent): use MarkdownContentEditor for readonly views #6268

Merged
merged 1 commit into from
Aug 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions cypress/e2e/versions.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ describe('Versions', () => {
cy.get('[data-files-versions-versions-list] li a').should('have.length', 3)

cy.get('[data-files-versions-versions-list] li a').eq(1).click()
cy.get('.viewer__content #read-only-editor')
cy.getContent()
.find('h1')
.should('contain.text', 'V2')

cy.get('[data-files-versions-versions-list] li a').eq(2).click()
cy.get('.viewer__content #read-only-editor')
cy.getContent()
.find('h1')
.should('contain.text', 'V1')

Expand Down Expand Up @@ -68,12 +68,12 @@ describe('Versions', () => {
cy.get('[data-files-versions-versions-list] li a').should('have.length', 3)

cy.get('[data-files-versions-versions-list] li a').eq(1).click()
cy.get('.viewer__content #read-only-editor')
cy.getContent()
.find('h1')
.should('contain.text', 'V2')

cy.get('[data-files-versions-versions-list] li a').eq(2).click()
cy.get('.viewer__content #read-only-editor')
cy.getContent()
.find('h1')
.should('contain.text', 'V1')

Expand Down Expand Up @@ -113,7 +113,7 @@ describe('Versions', () => {
.should('contain', 'Compare to current version')
.click()

cy.get('.viewer__content #read-only-editor')
cy.getContent()
.find('h1')
.should('contain.text', '#V1')

Expand Down
19 changes: 13 additions & 6 deletions src/components/Editor/MarkdownContentEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
:show-outline-outside="showOutlineOutside"
@outline-toggled="outlineToggled">
<MainContainer>
<MenuBar v-if="!readOnly" :autohide="false" />
<slot v-else name="readonlyBar">
<ReadonlyBar />
</slot>
<template v-if="showMenuBar">
<MenuBar v-if="!readOnly" :autohide="false" />
<slot v-else name="readonlyBar">
<ReadonlyBar />
</slot>
</template>
<ContentContainer />
</MainContainer>
</Wrapper>
Expand Down Expand Up @@ -75,6 +77,10 @@ export default {
type: String,
default: null,
},
showMenuBar: {
type: Boolean,
default: true,
},
showOutlineOutside: {
type: Boolean,
default: false,
Expand Down Expand Up @@ -175,6 +181,7 @@ export default {
}
</script>

<style scoped>

<style lang="scss">
@import './../../css/prosemirror';
@import './../../css/print';
</style>
12 changes: 8 additions & 4 deletions src/components/ViewerComponent.vue
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
id="editor-container"
data-text-el="editor-container"
class="text-editor source-viewer">
<Component :is="readerComponent" :content="content" />
<Component :is="readerComponent"
:content="content"
:file-id="fileid"
:read-only="true"
:show-menu-bar="false" />
<NcButton v-if="isEmbedded" class="toggle-interactive" @click="toggleEdit">
{{ t('text', 'Edit') }}
<template #icon>
Expand All @@ -33,7 +37,7 @@ 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 MarkdownContentEditor from './Editor/MarkdownContentEditor.vue'
import { translate, translatePlural } from '@nextcloud/l10n'

import { getSharingToken } from '../helpers/token.js'
Expand All @@ -47,8 +51,8 @@ export default {
components: {
NcButton: Vue.extend(NcButton),
PencilIcon: Vue.extend(PencilIcon),
RichTextReader: Vue.extend(RichTextReader),
PlainTextReader: Vue.extend(PlainTextReader),
MarkdownContentEditor: Vue.extend(MarkdownContentEditor),
Editor: getEditorInstance,
},
provide() {
Expand Down Expand Up @@ -112,7 +116,7 @@ export default {

/** @return {boolean} */
readerComponent() {
return this.mime === 'text/markdown' ? RichTextReader : PlainTextReader
return this.mime === 'text/markdown' ? MarkdownContentEditor : PlainTextReader
},
},

Expand Down
Loading