mirror of
https://github.com/ueberdosis/tiptap.git
synced 2024-11-24 19:59:02 +08:00
improve plugin order
This commit is contained in:
parent
cde0d8690a
commit
07cfc99502
@ -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,
|
||||
|
@ -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)
|
||||
})
|
||||
|
||||
|
@ -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,
|
||||
|
@ -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,
|
||||
]
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user