From 85b45bbf8ce9d944d6446af4b088c51e52ca9b10 Mon Sep 17 00:00:00 2001 From: Jonas Date: Mon, 27 Nov 2023 14:50:15 +0100 Subject: [PATCH] feat(editor): Pass fileId to editor API for reader 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 --- src/constants.js | 2 ++ src/mixins/editorMixin.js | 7 +++++++ src/store/store.js | 15 +++++++++++---- 3 files changed, 20 insertions(+), 4 deletions(-) diff --git a/src/constants.js b/src/constants.js index 557963c25f..d366c110a7 100644 --- a/src/constants.js +++ b/src/constants.js @@ -34,3 +34,5 @@ export const pageModes = { MODE_VIEW: 0, MODE_EDIT: 1, } + +export const editorApiReaderFileId = 'READER_FILE_ID' diff --git a/src/mixins/editorMixin.js b/src/mixins/editorMixin.js index c9add27f7c..ef769d10ef 100644 --- a/src/mixins/editorMixin.js +++ b/src/mixins/editorMixin.js @@ -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: [ @@ -23,6 +24,7 @@ export default { 'currentCollectiveCanEdit', 'currentPage', 'currentPageFilePath', + 'editorApiFlags', 'loading', 'shareTokenParam', 'showing', @@ -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, diff --git a/src/store/store.js b/src/store/store.js index 2260cb8166..d3a08e9e69 100644 --- a/src/store/store.js +++ b/src/store/store.js @@ -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) @@ -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 }, },