refactoring
This commit is contained in:
35
packages/core/src/utils/resolveExtensionConfig.ts
Normal file
35
packages/core/src/utils/resolveExtensionConfig.ts
Normal file
@@ -0,0 +1,35 @@
|
||||
import deepmerge from 'deepmerge'
|
||||
import Extension from '../Extension'
|
||||
import Node from '../Node'
|
||||
import Mark from '../Mark'
|
||||
|
||||
export default function resolveExtensionConfig(
|
||||
extension: Extension | Node | Mark,
|
||||
name: string,
|
||||
props = {},
|
||||
): void {
|
||||
if (!extension.configs[name]) {
|
||||
return
|
||||
}
|
||||
|
||||
extension.config[name] = extension.configs[name]
|
||||
.reduce((accumulator, { stategy, value: rawValue }) => {
|
||||
const value = typeof rawValue === 'function'
|
||||
? rawValue(props)
|
||||
: rawValue
|
||||
|
||||
if (accumulator === undefined) {
|
||||
return value
|
||||
}
|
||||
|
||||
if (stategy === 'overwrite') {
|
||||
return value
|
||||
}
|
||||
|
||||
if (stategy === 'extend') {
|
||||
return deepmerge(accumulator, value)
|
||||
}
|
||||
|
||||
return accumulator
|
||||
}, undefined)
|
||||
}
|
||||
Reference in New Issue
Block a user