Skip to content

Commit

Permalink
feat(editor): Pass fileId to editor API for reader
Browse files Browse the repository at this point in the history
Only do this if editor API is version 1.1 or newer to not break usage
with older Text versions.

This builds on nextcloud/text#5042.

Fixes: #620
Fixes: #964

Signed-off-by: Jonas <jonas@freesources.org>
  • Loading branch information
mejo- committed Dec 5, 2023
1 parent 204994f commit eb24aea
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,3 +34,5 @@ export const pageModes = {
MODE_VIEW: 0,
MODE_EDIT: 1,
}

export const editorApiReaderFileId = 'READER_FILE_ID'
7 changes: 7 additions & 0 deletions src/mixins/editorMixin.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import debounce from 'debounce'
import { mapGetters, mapMutations } from 'vuex'
import linkHandlerMixin from '../mixins/linkHandlerMixin.js'
import PageInfoBar from '../components/Page/PageInfoBar.vue'
import { editorApiReaderFileId } from '../constants.js'

export default {
mixins: [
Expand All @@ -23,6 +24,7 @@ export default {
'currentCollectiveCanEdit',
'currentPage',
'currentPageFilePath',
'editorApiFlags',
'loading',
'shareTokenParam',
'showing',
Expand Down Expand Up @@ -61,8 +63,13 @@ export default {
]),

async setupReader() {
const fileId = this.editorApiFlags.includes(editorApiReaderFileId)
? this.currentPage.id
: null
this.reader = await window.OCA.Text.createEditor({
el: this.$refs.reader,
fileId,
useSession: false,
content: this.pageContent,
filePath: `/${this.currentPageFilePath}`,
readOnly: true,
Expand Down
15 changes: 11 additions & 4 deletions src/store/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import collectives from './collectives.js'
import pages from './pages.js'
import settings from './settings.js'
import versions from './versions.js'
import { pageModes } from '../constants.js'
import { editorApiReaderFileId, pageModes } from '../constants.js'

Vue.use(Vuex)

Expand Down Expand Up @@ -54,14 +54,21 @@ export default new Store({
isTextEdit: (state) => state.textMode === pageModes.MODE_EDIT,
isTextView: (state) => state.textMode === pageModes.MODE_VIEW,

editorApiVersionCheck() {
const requiredVersion = '1.0'
editorApiVersionCheck: () => (requiredVersion) => {
const apiVersion = window.OCA?.Text?.apiVersion || '0'
return apiVersion.localeCompare(requiredVersion, undefined, { numeric: true, sensitivity: 'base' }) >= 0
},

useEditorApi(_, get) {
return !!window.OCA?.Text?.createEditor && get.editorApiVersionCheck
return !!window.OCA?.Text?.createEditor && get.editorApiVersionCheck('1.0')
},

editorApiFlags(_, get) {
const flags = []
if (get.editorApiVersionCheck('1.1')) {
flags.push(editorApiReaderFileId)
}
return flags
},
},

Expand Down

0 comments on commit eb24aea

Please sign in to comment.