fix some more errors
This commit is contained in:
@@ -45,37 +45,85 @@ export default class ExtensionManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// if (typeof extension.config.onBeforeCreate === 'function') {
|
const onBeforeCreate = getExtensionField<AnyConfig['onBeforeCreate']>(
|
||||||
// this.editor.on('beforeCreate', extension.config.onBeforeCreate.bind(context))
|
extension,
|
||||||
// }
|
'onBeforeCreate',
|
||||||
|
context,
|
||||||
|
)
|
||||||
|
|
||||||
// if (typeof extension.config.onCreate === 'function') {
|
if (onBeforeCreate) {
|
||||||
// this.editor.on('create', extension.config.onCreate.bind(context))
|
this.editor.on('beforeCreate', onBeforeCreate)
|
||||||
// }
|
}
|
||||||
|
|
||||||
// if (typeof extension.config.onUpdate === 'function') {
|
const onCreate = getExtensionField<AnyConfig['onCreate']>(
|
||||||
// this.editor.on('update', extension.config.onUpdate.bind(context))
|
extension,
|
||||||
// }
|
'onCreate',
|
||||||
|
context,
|
||||||
|
)
|
||||||
|
|
||||||
// if (typeof extension.config.onSelectionUpdate === 'function') {
|
if (onCreate) {
|
||||||
// this.editor.on('selectionUpdate', extension.config.onSelectionUpdate.bind(context))
|
this.editor.on('create', onCreate)
|
||||||
// }
|
}
|
||||||
|
|
||||||
// if (typeof extension.config.onTransaction === 'function') {
|
const onUpdate = getExtensionField<AnyConfig['onUpdate']>(
|
||||||
// this.editor.on('transaction', extension.config.onTransaction.bind(context))
|
extension,
|
||||||
// }
|
'onUpdate',
|
||||||
|
context,
|
||||||
|
)
|
||||||
|
|
||||||
// if (typeof extension.config.onFocus === 'function') {
|
if (onUpdate) {
|
||||||
// this.editor.on('focus', extension.config.onFocus.bind(context))
|
this.editor.on('update', onUpdate)
|
||||||
// }
|
}
|
||||||
|
|
||||||
// if (typeof extension.config.onBlur === 'function') {
|
const onSelectionUpdate = getExtensionField<AnyConfig['onSelectionUpdate']>(
|
||||||
// this.editor.on('blur', extension.config.onBlur.bind(context))
|
extension,
|
||||||
// }
|
'onSelectionUpdate',
|
||||||
|
context,
|
||||||
|
)
|
||||||
|
|
||||||
// if (typeof extension.config.onDestroy === 'function') {
|
if (onSelectionUpdate) {
|
||||||
// this.editor.on('destroy', extension.config.onDestroy.bind(context))
|
this.editor.on('selectionUpdate', onSelectionUpdate)
|
||||||
// }
|
}
|
||||||
|
|
||||||
|
const onTransaction = getExtensionField<AnyConfig['onTransaction']>(
|
||||||
|
extension,
|
||||||
|
'onTransaction',
|
||||||
|
context,
|
||||||
|
)
|
||||||
|
|
||||||
|
if (onTransaction) {
|
||||||
|
this.editor.on('transaction', onTransaction)
|
||||||
|
}
|
||||||
|
|
||||||
|
const onFocus = getExtensionField<AnyConfig['onFocus']>(
|
||||||
|
extension,
|
||||||
|
'onFocus',
|
||||||
|
context,
|
||||||
|
)
|
||||||
|
|
||||||
|
if (onFocus) {
|
||||||
|
this.editor.on('focus', onFocus)
|
||||||
|
}
|
||||||
|
|
||||||
|
const onBlur = getExtensionField<AnyConfig['onBlur']>(
|
||||||
|
extension,
|
||||||
|
'onBlur',
|
||||||
|
context,
|
||||||
|
)
|
||||||
|
|
||||||
|
if (onBlur) {
|
||||||
|
this.editor.on('blur', onBlur)
|
||||||
|
}
|
||||||
|
|
||||||
|
const onDestroy = getExtensionField<AnyConfig['onDestroy']>(
|
||||||
|
extension,
|
||||||
|
'onDestroy',
|
||||||
|
context,
|
||||||
|
)
|
||||||
|
|
||||||
|
if (onDestroy) {
|
||||||
|
this.editor.on('destroy', onDestroy)
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -83,11 +131,14 @@ export default class ExtensionManager {
|
|||||||
const defaultPriority = 100
|
const defaultPriority = 100
|
||||||
|
|
||||||
return extensions.sort((a, b) => {
|
return extensions.sort((a, b) => {
|
||||||
if ((a.config.priority || defaultPriority) > (b.config.priority || defaultPriority)) {
|
const priorityA = getExtensionField<AnyConfig['priority']>(a, 'priority') || defaultPriority
|
||||||
|
const priorityB = getExtensionField<AnyConfig['priority']>(b, 'priority') || defaultPriority
|
||||||
|
|
||||||
|
if (priorityA > priorityB) {
|
||||||
return -1
|
return -1
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((a.config.priority || defaultPriority) < (b.config.priority || defaultPriority)) {
|
if (priorityA < priorityB) {
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -103,13 +154,19 @@ export default class ExtensionManager {
|
|||||||
type: getSchemaTypeByName(extension.name, this.schema),
|
type: getSchemaTypeByName(extension.name, this.schema),
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!extension.config.addCommands) {
|
const addCommands = getExtensionField<AnyConfig['addCommands']>(
|
||||||
|
extension,
|
||||||
|
'addCommands',
|
||||||
|
context,
|
||||||
|
)
|
||||||
|
|
||||||
|
if (!addCommands) {
|
||||||
return commands
|
return commands
|
||||||
}
|
}
|
||||||
|
|
||||||
return {
|
return {
|
||||||
...commands,
|
...commands,
|
||||||
...getExtensionField(extension, 'addCommands', context)(),
|
...addCommands(),
|
||||||
}
|
}
|
||||||
}, {} as RawCommands)
|
}, {} as RawCommands)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user