feat: add priority option to extensions
This commit is contained in:
@@ -16,6 +16,11 @@ declare module '@tiptap/core' {
|
||||
*/
|
||||
name: string,
|
||||
|
||||
/**
|
||||
* Priority
|
||||
*/
|
||||
priority?: number,
|
||||
|
||||
/**
|
||||
* Default options
|
||||
*/
|
||||
@@ -180,6 +185,7 @@ export class Extension<Options = any> {
|
||||
|
||||
config: ExtensionConfig = {
|
||||
name: 'extension',
|
||||
priority: 100,
|
||||
defaultOptions: {},
|
||||
}
|
||||
|
||||
|
||||
@@ -25,7 +25,7 @@ export default class ExtensionManager {
|
||||
|
||||
constructor(extensions: Extensions, editor: Editor) {
|
||||
this.editor = editor
|
||||
this.extensions = extensions
|
||||
this.extensions = this.sort(extensions)
|
||||
this.schema = getSchema(this.extensions)
|
||||
|
||||
this.extensions.forEach(extension => {
|
||||
@@ -77,6 +77,22 @@ export default class ExtensionManager {
|
||||
})
|
||||
}
|
||||
|
||||
private sort(extensions: Extensions) {
|
||||
const defaultPriority = 100
|
||||
|
||||
return extensions.sort((a, b) => {
|
||||
if ((a.config.priority || defaultPriority) > (b.config.priority || defaultPriority)) {
|
||||
return -1
|
||||
}
|
||||
|
||||
if ((a.config.priority || defaultPriority) < (b.config.priority || defaultPriority)) {
|
||||
return 1
|
||||
}
|
||||
|
||||
return 0
|
||||
})
|
||||
}
|
||||
|
||||
get commands(): RawCommands {
|
||||
return this.extensions.reduce((commands, extension) => {
|
||||
const context = {
|
||||
|
||||
@@ -21,6 +21,11 @@ declare module '@tiptap/core' {
|
||||
*/
|
||||
name: string,
|
||||
|
||||
/**
|
||||
* Priority
|
||||
*/
|
||||
priority?: number,
|
||||
|
||||
/**
|
||||
* Default options
|
||||
*/
|
||||
@@ -254,6 +259,7 @@ export class Mark<Options = any> {
|
||||
|
||||
config: MarkConfig = {
|
||||
name: 'mark',
|
||||
priority: 100,
|
||||
defaultOptions: {},
|
||||
}
|
||||
|
||||
|
||||
@@ -26,6 +26,11 @@ declare module '@tiptap/core' {
|
||||
*/
|
||||
name: string,
|
||||
|
||||
/**
|
||||
* Priority
|
||||
*/
|
||||
priority?: number,
|
||||
|
||||
/**
|
||||
* Default options
|
||||
*/
|
||||
@@ -312,6 +317,7 @@ export class Node<Options = any> {
|
||||
|
||||
config: NodeConfig = {
|
||||
name: 'node',
|
||||
priority: 100,
|
||||
defaultOptions: {},
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user