fix: add support for priority and nested extension for getSchema
This commit is contained in:
@@ -6,7 +6,7 @@ import { Plugin } from 'prosemirror-state'
|
||||
import { Editor } from './Editor'
|
||||
import { Extensions, RawCommands, AnyConfig } from './types'
|
||||
import getExtensionField from './helpers/getExtensionField'
|
||||
import getSchema from './helpers/getSchema'
|
||||
import getSchemaByResolvedExtensions from './helpers/getSchemaByResolvedExtensions'
|
||||
import getSchemaTypeByName from './helpers/getSchemaTypeByName'
|
||||
import getNodeType from './helpers/getNodeType'
|
||||
import splitExtensions from './helpers/splitExtensions'
|
||||
@@ -27,8 +27,8 @@ export default class ExtensionManager {
|
||||
|
||||
constructor(extensions: Extensions, editor: Editor) {
|
||||
this.editor = editor
|
||||
this.extensions = this.sort(this.flatten(extensions))
|
||||
this.schema = getSchema(this.extensions)
|
||||
this.extensions = ExtensionManager.resolve(extensions)
|
||||
this.schema = getSchemaByResolvedExtensions(this.extensions)
|
||||
|
||||
this.extensions.forEach(extension => {
|
||||
const context = {
|
||||
@@ -128,13 +128,16 @@ export default class ExtensionManager {
|
||||
})
|
||||
}
|
||||
|
||||
private flatten(extensions: Extensions): Extensions {
|
||||
static resolve(extensions: Extensions): Extensions {
|
||||
return ExtensionManager.sort(ExtensionManager.flatten(extensions))
|
||||
}
|
||||
|
||||
static flatten(extensions: Extensions): Extensions {
|
||||
return extensions
|
||||
.map(extension => {
|
||||
const context = {
|
||||
name: extension.name,
|
||||
options: extension.options,
|
||||
editor: this.editor,
|
||||
}
|
||||
|
||||
const addExtensions = getExtensionField<AnyConfig['addExtensions']>(
|
||||
@@ -153,7 +156,7 @@ export default class ExtensionManager {
|
||||
.flat(10)
|
||||
}
|
||||
|
||||
private sort(extensions: Extensions): Extensions {
|
||||
static sort(extensions: Extensions): Extensions {
|
||||
const defaultPriority = 100
|
||||
|
||||
return extensions.sort((a, b) => {
|
||||
|
||||
Reference in New Issue
Block a user