Skip to content
Next Next commit
fix(editorApi): Allow to toggle outline via the API
Signed-off-by: Jonas <[email protected]>
  • Loading branch information
mejo- authored and backportbot-nextcloud[bot] committed Oct 10, 2023
commit e55e2294441f8eefc70be495aa42a441fc9e8ace
7 changes: 6 additions & 1 deletion src/components/Editor/MarkdownContentEditor.vue
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@
-->

<template>
<Wrapper :content-loaded="true">
<Wrapper :content-loaded="true"
:show-outline-outside="showOutlineOutside">
<MainContainer>
<MenuBar v-if="!readOnly" :autohide="false" />
<ReadonlyBar v-else />
Expand Down Expand Up @@ -72,6 +73,10 @@ export default {
type: Boolean,
default: false,
},
showOutlineOutside: {
type: Boolean,
default: false,
},
},
emits: ['update:content'],

Expand Down
17 changes: 17 additions & 0 deletions src/editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,13 @@ class TextEditorEmbed {
return this
}

onOutlineToggle(onOutlineToggleCallback = () => {}) {
this.#vm.$on('outline-toggled', (visible) => {
onOutlineToggleCallback(visible)
})
return this
}

render(el) {
el.innerHTML = ''
const element = document.createElement('div')
Expand All @@ -81,6 +88,11 @@ class TextEditorEmbed {
return this
}

setShowOutline(value) {
this.#vm.$set(this.#data, 'showOutlineOutside', value)
return this
}

setReadOnly(value) {
this.#vm.$set(this.#data, 'readOnly', value)
return this
Expand Down Expand Up @@ -119,6 +131,7 @@ window.OCA.Text.createEditor = async function({
readOnly = false,

onUpdate = ({ markdown }) => {},
onOutlineToggle = (visible) => {},
onLinkClick = undefined,
onFileInsert = undefined,
onMentionSearch = undefined,
Expand All @@ -128,6 +141,7 @@ window.OCA.Text.createEditor = async function({
const { default: Editor } = await import(/* webpackChunkName: "editor" */'./components/Editor.vue')

const data = Vue.observable({
showOutlineOutside: false,
readOnly,
content,
})
Expand Down Expand Up @@ -161,18 +175,21 @@ window.OCA.Text.createEditor = async function({
mime: 'text/markdown',
active: true,
relativePath: filePath,
showOutlineOutside: data.showOutlineOutside,
},
})
: h(MarkdownContentEditor, {
props: {
content: data.content,
readOnly: data.readOnly,
showOutlineOutside: data.showOutlineOutside,
},
})
},
store,
})
return new TextEditorEmbed(vm, data)
.onUpdate(onUpdate)
.onOutlineToggle(onOutlineToggle)
.render(el)
}