Skip to content

Commit 40be457

Browse files
committed
fix: backport for stable29
Signed-off-by: Benjamin Frueh <[email protected]>
1 parent 4d5f180 commit 40be457

File tree

3 files changed

+50
-62
lines changed

3 files changed

+50
-62
lines changed

src/components/Editor/PlainTableContentEditor.vue

Lines changed: 47 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
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>
@@ -13,94 +12,78 @@
1312

1413
<script>
1514
import { Editor } from '@tiptap/core'
15+
import History from '@tiptap/extension-history'
1616
import MainContainer from './MainContainer.vue'
1717
import 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'
2818
import 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
3024
export 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>

src/editor.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ window.OCA.Text.createEditor = async function({
259259
.render(el)
260260
}
261261

262-
window.OCA.Text.createTable = async function ({
262+
window.OCA.Text.createTable = async function({
263263
// Element to render the editor to
264264
el,
265265

src/extensions/index.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import FocusTrap from './FocusTrap.js'
2626
import Keymap from './Keymap.js'
2727
import UserColor from './UserColor.js'
2828
import Markdown from './Markdown.js'
29+
import PlainTable from './PlainTable.js'
2930
import PlainText from './PlainText.js'
3031
import RichText from './RichText.js'
3132
import KeepSyntax from './KeepSyntax.js'
@@ -38,6 +39,7 @@ export {
3839
Keymap,
3940
UserColor,
4041
Markdown,
42+
PlainTable,
4143
PlainText,
4244
RichText,
4345
KeepSyntax,

0 commit comments

Comments
 (0)