improve plugin order

This commit is contained in:
Philipp Kühn 2021-01-28 17:39:57 +01:00
parent cde0d8690a
commit 07cfc99502
4 changed files with 31 additions and 12 deletions

View File

@ -70,7 +70,9 @@
</template>
<script>
import { Editor, EditorContent, defaultExtensions } from '@tiptap/vue-starter-kit'
import {
Editor, EditorContent, defaultExtensions, Extension,
} from '@tiptap/vue-starter-kit'
export default {
components: {
@ -85,7 +87,23 @@ export default {
mounted() {
this.editor = new Editor({
extensions: defaultExtensions(),
extensions: [
...defaultExtensions(),
Extension.create({
addKeyboardShortcuts() {
return {
'Mod-Enter': () => {
console.log('Mod-Enter plugin')
return false
},
'Shift-Enter': () => {
console.log('Shift-Enter')
return false
},
}
},
}),
],
content: `
<h2>
Hi there,

View File

@ -195,7 +195,7 @@ export class Editor extends EventEmitter {
public registerPlugin(plugin: Plugin, handlePlugins?: (newPlugin: Plugin, plugins: Plugin[]) => Plugin[]): void {
const plugins = typeof handlePlugins === 'function'
? handlePlugins(plugin, this.state.plugins)
: [plugin, ...this.state.plugins]
: [...this.state.plugins, plugin]
const state = this.state.reconfigure({ plugins })
@ -221,7 +221,7 @@ export class Editor extends EventEmitter {
*/
private createExtensionManager(): void {
const coreExtensions = Object.entries(extensions).map(([, extension]) => extension)
const allExtensions = [...this.options.extensions, ...coreExtensions].filter(extension => {
const allExtensions = [...coreExtensions, ...this.options.extensions].filter(extension => {
return ['extension', 'node', 'mark'].includes(extension?.type)
})

View File

@ -67,7 +67,8 @@ export default class ExtensionManager {
}
get plugins(): Plugin[] {
return this.extensions
return [...this.extensions]
.reverse()
.map(extension => {
const context = {
options: extension.options,

View File

@ -35,23 +35,23 @@ export function defaultExtensions(options?: Partial<{
listItem: ListItemOptions,
}>) {
return [
Dropcursor.configure(options?.dropursor),
Gapcursor,
Document,
History.configure(options?.history),
Paragraph.configure(options?.paragraph),
Text,
Bold.configure(options?.bold),
Italic.configure(options?.italic),
Code.configure(options?.code),
CodeBlock.configure(options?.codeBlock),
Heading.configure(options?.heading),
HardBreak.configure(options?.hardBreak),
Strike.configure(options?.strike),
HardBreak.configure(options?.hardBreak),
Heading.configure(options?.heading),
Blockquote.configure(options?.blockquote),
HorizontalRule.configure(options?.horizontalRule),
BulletList.configure(options?.bulletList),
OrderedList.configure(options?.orderedList),
ListItem.configure(options?.listItem),
HorizontalRule.configure(options?.horizontalRule),
CodeBlock.configure(options?.codeBlock),
History.configure(options?.history),
Dropcursor.configure(options?.dropursor),
Gapcursor,
]
}