Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nextcloud/text.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMax <max@nextcloud.com>2022-06-01 13:49:57 +0300
committerMax <max@nextcloud.com>2022-06-07 20:42:05 +0300
commit36730c264a25b64347515a1e83a4ca0b1732896c (patch)
tree547185f47678e115a0a7c4a3c3f7a73bba735c63 /src/components/BaseReader.vue
parent9a8f7613e733baa44eacc5cd651efe369e6d5906 (diff)
refactor: BaseReader for shared code between Readers
Signed-off-by: Max <max@nextcloud.com>
Diffstat (limited to 'src/components/BaseReader.vue')
-rw-r--r--src/components/BaseReader.vue77
1 files changed, 77 insertions, 0 deletions
diff --git a/src/components/BaseReader.vue b/src/components/BaseReader.vue
new file mode 100644
index 000000000..1f48b1f60
--- /dev/null
+++ b/src/components/BaseReader.vue
@@ -0,0 +1,77 @@
+<!--
+ - @copyright Copyright (c) 2019 Julius Härtl <jus@bitgrid.net>
+ -
+ - @author Julius Härtl <jus@bitgrid.net>
+ -
+ - @license GNU AGPL version 3 or any later version
+ -
+ - This program is free software: you can redistribute it and/or modify
+ - it under the terms of the GNU Affero General Public License as
+ - published by the Free Software Foundation, either version 3 of the
+ - License, or (at your option) any later version.
+ -
+ - This program is distributed in the hope that it will be useful,
+ - but WITHOUT ANY WARRANTY; without even the implied warranty of
+ - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ - GNU Affero General Public License for more details.
+ -
+ - You should have received a copy of the GNU Affero General Public License
+ - along with this program. If not, see <http://www.gnu.org/licenses/>.
+ -
+ -->
+
+<template>
+ <EditorContent v-if="$editor" id="read-only-editor" :editor="$editor" />
+</template>
+
+<script>
+import { Editor } from '@tiptap/core'
+import { EditorContent } from '@tiptap/vue-2'
+
+export default {
+ name: 'BaseReader',
+ components: { EditorContent },
+ inject: ['renderHtml', 'extensions'],
+
+ props: {
+ content: {
+ type: String,
+ required: true,
+ },
+ },
+
+ computed: {
+ htmlContent() {
+ return this.renderHtml(this.content)
+ },
+ },
+
+ watch: {
+ content() {
+ this.updateContent()
+ },
+ },
+
+ created() {
+ this.$editor = this.createEditor()
+ this.$editor.setOptions({ editable: false })
+ },
+
+ beforeDestroy() {
+ this.$editor.destroy()
+ },
+
+ methods: {
+ createEditor() {
+ return new Editor({
+ content: this.htmlContent,
+ extensions: this.extensions,
+ })
+ },
+
+ updateContent() {
+ this.$editor.commands.setContent(this.htmlContent)
+ },
+ },
+}
+</script>