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: {},
|
||||
}
|
||||
|
||||
|
||||
@@ -31,6 +31,8 @@ const awarenessStatesToArray = (states: Map<number, { [key: string]: any }>) =>
|
||||
export const CollaborationCursor = Extension.create<CollaborationCursorOptions>({
|
||||
name: 'collaborationCursor',
|
||||
|
||||
priority: 1000,
|
||||
|
||||
defaultOptions: {
|
||||
provider: null,
|
||||
user: {
|
||||
|
||||
@@ -38,6 +38,8 @@ export const pasteRegexWithBrackets = /(?:\()https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%
|
||||
export const Link = Mark.create<LinkOptions>({
|
||||
name: 'link',
|
||||
|
||||
priority: 1000,
|
||||
|
||||
inclusive: false,
|
||||
|
||||
defaultOptions: {
|
||||
|
||||
@@ -20,6 +20,8 @@ declare module '@tiptap/core' {
|
||||
export const Paragraph = Node.create<ParagraphOptions>({
|
||||
name: 'paragraph',
|
||||
|
||||
priority: 1000,
|
||||
|
||||
defaultOptions: {
|
||||
HTMLAttributes: {},
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user