Skip to content

Commit

Permalink
enh(TextEditor): Pass PageInfoBar component as ReadonlyBar to reader
Browse files Browse the repository at this point in the history
Signed-off-by: Jonas <[email protected]>
  • Loading branch information
mejo- committed Oct 10, 2023
1 parent 6787666 commit 9de988f
Showing 1 changed file with 33 additions and 21 deletions.
54 changes: 33 additions & 21 deletions src/components/Page/TextEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import {
} from '../../store/actions.js'
import linkHandlerMixin from '../../mixins/linkHandlerMixin.js'
import pageContentMixin from '../../mixins/pageContentMixin.js'
import PageInfoBar from '../Page/PageInfoBar.vue'
import SkeletonLoading from '../SkeletonLoading.vue'
export default {
Expand Down Expand Up @@ -74,7 +75,7 @@ export default {
]),
pageContent() {
return this.editorContent || this.davContent
return this.editorContent?.trim() || this.davContent
},
showReader() {
Expand Down Expand Up @@ -165,34 +166,45 @@ export default {
el: this.$refs.reader,
content: this.pageContent,
readOnly: true,
readonlyBar: {
component: PageInfoBar,
props: {
currentPage: this.currentPage,
isFullWidthView: this.isFullWidthView,
},
},
onLinkClick: (_event, attrs) => {
this.followLink(_event, attrs)
},
onOutlineToggle: (visible) => {
this.toggleOutlineFromEditor(visible)
},
}).then((reader) => {
reader.setContent(this.pageContent)
})
},
async setupEditor() {
this.editor = await window.OCA.Text.createEditor({
el: this.$refs.editor,
fileId: this.currentPage.id,
filePath: `/${this.currentPageFilePath}`,
readOnly: false,
shareToken: this.shareTokenParam || null,
autofocus: false,
onLoaded: () => {
this.readyEditor()
},
onUpdate: ({ markdown }) => {
this.editorContent = markdown
this.reader?.setContent(this.pageContent)
},
onOutlineToggle: (visible) => {
this.toggleOutlineFromEditor(visible)
},
})
this.editor = this.currentCollectiveCanEdit
? await window.OCA.Text.createEditor({
el: this.$refs.editor,
fileId: this.currentPage.id,
filePath: `/${this.currentPageFilePath}`,
readOnly: false,
shareToken: this.shareTokenParam || null,
autofocus: false,
onLoaded: () => {
this.readyEditor()
},
onUpdate: ({ markdown }) => {
this.editorContent = markdown
this.reader?.setContent(this.pageContent)
},
onOutlineToggle: (visible) => {
this.toggleOutlineFromEditor(visible)
},
})
: null
},
focusEditor() {
Expand Down Expand Up @@ -239,7 +251,7 @@ export default {
// for new pages
|| this.loading('newPage')
// or when page is empty
|| !this.pageContent.trim()) {
|| !this.pageContent?.trim()) {
this.setTextEdit()
}
},
Expand All @@ -255,7 +267,7 @@ export default {
this.scrollTop = document.getElementById('editor')?.scrollTop || 0
// switch back to edit if there's no content
if (!this.pageContent.trim()) {
if (!this.pageContent?.trim()) {
this.setTextEdit()
this.$nextTick(() => {
this.focusEditor()
Expand Down

0 comments on commit 9de988f

Please sign in to comment.