Skip to content

Commit 9305516

Browse files
committed
fix(editor): rollback to the old vue2 provide hack
Calling `provide` in the setup function is still buggy in vue2. This led to the editor not being rendered in deck. Signed-off-by: Max <[email protected]>
1 parent 236fb11 commit 9305516

6 files changed

Lines changed: 44 additions & 20 deletions

File tree

renovate.json

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,14 @@
6464
},
6565
{
6666
"matchUpdateTypes": ["major", "minor"],
67-
"matchBaseBranches": ["stable31", "stable30", "stable29", "stable28", "stable27", "stable26"],
67+
"matchBaseBranches": [
68+
"stable31",
69+
"stable30",
70+
"stable29",
71+
"stable28",
72+
"stable27",
73+
"stable26"
74+
],
6875
"enabled": false
6976
},
7077
{

src/components/BaseReader.vue

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
import { Editor } from '@tiptap/core'
2626
import { EditorContent } from '@tiptap/vue-2'
2727
import { inject, watch } from 'vue'
28-
import { provideEditor } from '../composables/useEditor.ts'
28+
import { editorKey } from '../composables/useEditor.ts'
2929
import { useEditorMethods } from '../composables/useEditorMethods.ts'
3030
import EditorOutline from './Editor/EditorOutline.vue'
3131
import {
@@ -40,6 +40,16 @@ export default {
4040
EditorOutline,
4141
},
4242
43+
provide() {
44+
const val = {}
45+
Object.defineProperties(val, {
46+
[editorKey]: {
47+
get: () => this.editor,
48+
},
49+
})
50+
return val
51+
},
52+
4353
mixins: [useOutlineStateMixin, useOutlineActions],
4454
4555
props: {
@@ -57,7 +67,6 @@ export default {
5767
content: renderHtml(props.content),
5868
extensions: extensions(),
5969
})
60-
provideEditor(editor)
6170
watch(
6271
() => props.content,
6372
(content) => {

src/components/Editor.vue

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@ import { defineComponent, ref, shallowRef, watch } from 'vue'
8787
import { Doc } from 'yjs'
8888
import Autofocus from '../extensions/Autofocus.js'
8989
90-
import { provideEditor } from '../composables/useEditor.ts'
91-
import { provideEditorFlags } from '../composables/useEditorFlags.ts'
90+
import { editorKey } from '../composables/useEditor.ts'
91+
import { editorFlagsKey, getEditorFlags } from '../composables/useEditorFlags.ts'
9292
import { ATTACHMENT_RESOLVER, FILE, IS_MOBILE } from './Editor.provider.ts'
9393
import ReadonlyBar from './Menu/ReadonlyBar.vue'
9494
@@ -164,6 +164,16 @@ export default defineComponent({
164164
[IS_MOBILE]: {
165165
get: () => this.isMobile,
166166
},
167+
[editorKey]: {
168+
get: () => this.editor,
169+
},
170+
[editorFlagsKey]: {
171+
get: () => ({
172+
isPublic: this.isPublic,
173+
isRichEditor: this.isRichEditor,
174+
isRichWorkspace: this.isRichWorkspace,
175+
}),
176+
},
167177
})
168178
169179
return val
@@ -229,7 +239,7 @@ export default defineComponent({
229239
const awareness = new Awareness(ydoc)
230240
const hasConnectionIssue = ref(false)
231241
const { delayed: requireReconnect } = useDelayedFlag(hasConnectionIssue)
232-
const { isPublic, isRichEditor, isRichWorkspace } = provideEditorFlags(props)
242+
const { isPublic, isRichEditor, isRichWorkspace } = getEditorFlags(props)
233243
const { language, lowlightLoaded } = useSyntaxHighlighting(
234244
isRichEditor,
235245
props,
@@ -249,7 +259,6 @@ export default defineComponent({
249259
isEmbedded: props.isEmbedded,
250260
})
251261
: createPlainEditor({ language, extensions })
252-
provideEditor(editor)
253262
254263
const { applyEditorWidth } = provideEditorWidth()
255264
applyEditorWidth()

src/components/Editor/MarkdownContentEditor.vue

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@ import Wrapper from './Wrapper.vue'
2828
/* eslint-disable import/no-named-as-default */
2929
import { getCurrentUser } from '@nextcloud/auth'
3030
import History from '@tiptap/extension-history'
31-
import { provide, watch } from 'vue'
32-
import { provideEditor } from '../../composables/useEditor.ts'
31+
import { watch } from 'vue'
32+
import { editorKey } from '../../composables/useEditor.ts'
3333
import { editorFlagsKey } from '../../composables/useEditorFlags.ts'
3434
import { useEditorMethods } from '../../composables/useEditorMethods.ts'
3535
import { FocusTrap, RichText } from '../../extensions/index.js'
@@ -50,6 +50,14 @@ export default {
5050
[ATTACHMENT_RESOLVER]: {
5151
get: () => this.$attachmentResolver ?? null,
5252
},
53+
[editorKey]: {
54+
get: () => this.editor,
55+
},
56+
[editorFlagsKey]: {
57+
isPublic: false,
58+
isRichEditor: true,
59+
isRichWorkspace: false,
60+
},
5361
})
5462
5563
return val
@@ -115,12 +123,6 @@ export default {
115123
},
116124
)
117125
118-
provideEditor(editor)
119-
provide(editorFlagsKey, {
120-
isPublic: false,
121-
isRichEditor: true,
122-
isRichWorkspace: false,
123-
})
124126
return { editor }
125127
},
126128

src/composables/useEditor.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@
44
*/
55

66
import { Editor } from '@tiptap/core'
7-
import { inject, type InjectionKey, provide } from 'vue'
7+
import { inject, type InjectionKey } from 'vue'
88

99
export const editorKey = Symbol('tiptap:editor') as InjectionKey<Editor>
10-
export const provideEditor = (editor: Editor) => {
11-
provide(editorKey, editor)
12-
}
1310
export const useEditor = () => {
1411
const editor = inject(editorKey)
1512
if (!editor) {

src/composables/useEditorFlags.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ interface Props {
1818
mime: string
1919
}
2020
export const editorFlagsKey = Symbol('editor:flags') as InjectionKey<EditorFlags>
21-
export const provideEditorFlags = (props: Props) => {
21+
export const getEditorFlags = (props: Props) => {
2222
const isPublic = props.isDirectEditing || isPublicShare()
2323
const isRichWorkspace = props.richWorkspace ?? false
2424
const isRichEditor =

0 commit comments

Comments
 (0)