22 - SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
33 - SPDX-License-Identifier: AGPL-3.0-or-later
44-->
5-
65<template >
76 <Wrapper :content-loaded =" true" :show-outline-outside =" false" >
87 <MainContainer >
1312
1413<script >
1514import { Editor } from ' @tiptap/core'
15+ import History from ' @tiptap/extension-history'
1616import MainContainer from ' ./MainContainer.vue'
1717import Wrapper from ' ./Wrapper.vue'
18- /* eslint-disable import/no-named-as-default */
19- import { UndoRedo } from ' @tiptap/extensions'
20- import { provide , watch } from ' vue'
21- import { provideEditor } from ' ../../composables/useEditor.ts'
22- import { editorFlagsKey } from ' ../../composables/useEditorFlags.ts'
23- import { useEditorMethods } from ' ../../composables/useEditorMethods.ts'
24- import { editorWidthKey } from ' ../../composables/useEditorWidth.ts'
25- import { FocusTrap , PlainTable } from ' ../../extensions/index.js'
26- import { createMarkdownSerializer } from ' ../../extensions/Markdown.js'
27- import { EDITOR_UPLOAD } from ' ../Editor.provider.ts'
2818import ContentContainer from ' ./ContentContainer.vue'
19+ import { PlainTable } from ' ../../extensions/index.js'
20+ import { createMarkdownSerializer } from ' ../../extensions/Markdown.js'
21+ import { EDITOR , IS_PUBLIC , IS_RICH_EDITOR , IS_RICH_WORKSPACE , EDITOR_UPLOAD } from ' ../Editor.provider.js'
22+ import markdownit from ' ../../markdownit/index.js'
2923
3024export default {
3125 name: ' PlainTableContentEditor' ,
3226 components: { ContentContainer, MainContainer, Wrapper },
3327
28+ provide () {
29+ const val = {}
30+ Object .defineProperties (val, {
31+ [EDITOR ]: { get : () => this .$editor },
32+ [IS_PUBLIC ]: { get : () => false },
33+ [IS_RICH_EDITOR ]: { get : () => false },
34+ [IS_RICH_WORKSPACE ]: { get : () => false },
35+ [EDITOR_UPLOAD ]: { get : () => false },
36+ })
37+ return val
38+ },
39+
3440 props: {
3541 content: {
3642 type: String ,
37- required : true ,
43+ default : ' ' ,
3844 },
3945 readOnly: {
4046 type: Boolean ,
4147 default: false ,
4248 },
4349 },
44- emits: [' update:content' ],
45-
46- setup (props ) {
47- const extensions = [PlainTable, UndoRedo, FocusTrap]
48- const editor = new Editor ({ extensions })
49-
50- const { setEditable , setContent } = useEditorMethods (editor)
51- watch (
52- () => props .content ,
53- (content ) => {
54- setContent (content)
55- },
56- )
57-
58- setEditable (! props .readOnly )
59- watch (
60- () => props .readOnly ,
61- (readOnly ) => {
62- setEditable (! readOnly)
63- },
64- )
65-
66- provideEditor (editor)
67- provide (editorFlagsKey, {
68- isPublic: false ,
69- isRichEditor: true ,
70- isRichWorkspace: false ,
71- })
72- provide (editorWidthKey, null )
73- provide (EDITOR_UPLOAD , false )
74- return { editor, setContent }
50+
51+ emits: [' update:content' , ' ready' , ' create:content' ],
52+
53+ computed: {
54+ editor () {
55+ return this .$editor
56+ },
7557 },
7658
7759 created () {
78- // Set content after the setup function
79- // as it may render other vue components such as preview toggle
80- // which breaks the context of the setup function.
81- this .setContent (this .content , { addToHistory: false })
82- this .editor .on (' create' , () => {
60+ const html = markdownit .render (this .content )
61+ const extensions = [PlainTable, History ]
62+
63+ this .$editor = new Editor ({
64+ content: html,
65+ extensions,
66+ editable: ! this .readOnly ,
67+ })
68+
69+ this .$editor .on (' create' , () => {
8370 this .$emit (' ready' )
8471 this .$parent .$emit (' ready' )
8572
86- // Emit initial content
8773 try {
88- const markdown = createMarkdownSerializer (
89- this .editor .schema ,
90- ).serialize (this .editor .state .doc )
74+ const markdown = createMarkdownSerializer (this .$editor .schema ).serialize (this .$editor .state .doc )
9175 this .emit (' create:content' , {
92- json: this .editor .state .doc ,
76+ json: this .$ editor .state .doc ,
9377 markdown,
9478 })
9579 } catch (error) {
9680 console .error (' Error serializing table:' , error)
9781 }
9882 })
99- this .editor .on (' update' , ({ editor }) => {
83+
84+ this .$editor .on (' update' , ({ editor }) => {
10085 try {
101- const markdown = createMarkdownSerializer (editor .schema ).serialize (
102- editor .state .doc ,
103- )
86+ const markdown = createMarkdownSerializer (editor .schema ).serialize (editor .state .doc )
10487 this .emit (' update:content' , {
10588 json: editor .state .doc ,
10689 markdown,
@@ -111,8 +94,12 @@ export default {
11194 })
11295 },
11396
97+ updated () {
98+ this .$editor .setEditable (! this .readOnly )
99+ },
100+
114101 beforeDestroy () {
115- this .editor .destroy ()
102+ this .$ editor .destroy ()
116103 },
117104
118105 methods: {
@@ -130,7 +117,6 @@ export default {
130117}
131118< / script>
132119
133- < style lang= " scss" >
134- @use ' ./../../css/prosemirror' ;
135- @use ' ./../../css/print' ;
120+ < style scoped>
121+
136122< / style>
0 commit comments