improve plugin order
This commit is contained in:
@@ -70,7 +70,9 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import { Editor, EditorContent, defaultExtensions } from '@tiptap/vue-starter-kit'
|
import {
|
||||||
|
Editor, EditorContent, defaultExtensions, Extension,
|
||||||
|
} from '@tiptap/vue-starter-kit'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
components: {
|
components: {
|
||||||
@@ -85,7 +87,23 @@ export default {
|
|||||||
|
|
||||||
mounted() {
|
mounted() {
|
||||||
this.editor = new Editor({
|
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: `
|
content: `
|
||||||
<h2>
|
<h2>
|
||||||
Hi there,
|
Hi there,
|
||||||
|
|||||||
@@ -195,7 +195,7 @@ export class Editor extends EventEmitter {
|
|||||||
public registerPlugin(plugin: Plugin, handlePlugins?: (newPlugin: Plugin, plugins: Plugin[]) => Plugin[]): void {
|
public registerPlugin(plugin: Plugin, handlePlugins?: (newPlugin: Plugin, plugins: Plugin[]) => Plugin[]): void {
|
||||||
const plugins = typeof handlePlugins === 'function'
|
const plugins = typeof handlePlugins === 'function'
|
||||||
? handlePlugins(plugin, this.state.plugins)
|
? handlePlugins(plugin, this.state.plugins)
|
||||||
: [plugin, ...this.state.plugins]
|
: [...this.state.plugins, plugin]
|
||||||
|
|
||||||
const state = this.state.reconfigure({ plugins })
|
const state = this.state.reconfigure({ plugins })
|
||||||
|
|
||||||
@@ -221,7 +221,7 @@ export class Editor extends EventEmitter {
|
|||||||
*/
|
*/
|
||||||
private createExtensionManager(): void {
|
private createExtensionManager(): void {
|
||||||
const coreExtensions = Object.entries(extensions).map(([, extension]) => extension)
|
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)
|
return ['extension', 'node', 'mark'].includes(extension?.type)
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|||||||
@@ -67,7 +67,8 @@ export default class ExtensionManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get plugins(): Plugin[] {
|
get plugins(): Plugin[] {
|
||||||
return this.extensions
|
return [...this.extensions]
|
||||||
|
.reverse()
|
||||||
.map(extension => {
|
.map(extension => {
|
||||||
const context = {
|
const context = {
|
||||||
options: extension.options,
|
options: extension.options,
|
||||||
|
|||||||
@@ -35,23 +35,23 @@ export function defaultExtensions(options?: Partial<{
|
|||||||
listItem: ListItemOptions,
|
listItem: ListItemOptions,
|
||||||
}>) {
|
}>) {
|
||||||
return [
|
return [
|
||||||
Dropcursor.configure(options?.dropursor),
|
|
||||||
Gapcursor,
|
|
||||||
Document,
|
Document,
|
||||||
History.configure(options?.history),
|
|
||||||
Paragraph.configure(options?.paragraph),
|
Paragraph.configure(options?.paragraph),
|
||||||
Text,
|
Text,
|
||||||
Bold.configure(options?.bold),
|
Bold.configure(options?.bold),
|
||||||
Italic.configure(options?.italic),
|
Italic.configure(options?.italic),
|
||||||
Code.configure(options?.code),
|
Code.configure(options?.code),
|
||||||
CodeBlock.configure(options?.codeBlock),
|
|
||||||
Heading.configure(options?.heading),
|
|
||||||
HardBreak.configure(options?.hardBreak),
|
|
||||||
Strike.configure(options?.strike),
|
Strike.configure(options?.strike),
|
||||||
|
HardBreak.configure(options?.hardBreak),
|
||||||
|
Heading.configure(options?.heading),
|
||||||
Blockquote.configure(options?.blockquote),
|
Blockquote.configure(options?.blockquote),
|
||||||
HorizontalRule.configure(options?.horizontalRule),
|
|
||||||
BulletList.configure(options?.bulletList),
|
BulletList.configure(options?.bulletList),
|
||||||
OrderedList.configure(options?.orderedList),
|
OrderedList.configure(options?.orderedList),
|
||||||
ListItem.configure(options?.listItem),
|
ListItem.configure(options?.listItem),
|
||||||
|
HorizontalRule.configure(options?.horizontalRule),
|
||||||
|
CodeBlock.configure(options?.codeBlock),
|
||||||
|
History.configure(options?.history),
|
||||||
|
Dropcursor.configure(options?.dropursor),
|
||||||
|
Gapcursor,
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user