2020-09-10 03:18:04 +08:00
|
|
|
import deepmerge from 'deepmerge'
|
2020-09-03 22:22:08 +08:00
|
|
|
import { Schema } from 'prosemirror-model'
|
2020-09-04 17:59:09 +08:00
|
|
|
import { Extensions } from '../types'
|
2020-09-04 18:10:35 +08:00
|
|
|
import getTopNodeFromExtensions from './getTopNodeFromExtensions'
|
|
|
|
import getNodesFromExtensions from './getNodesFromExtensions'
|
|
|
|
import getMarksFromExtensions from './getMarksFromExtensions'
|
2020-09-10 03:18:04 +08:00
|
|
|
import resolveExtensionConfig from './resolveExtensionConfig'
|
2020-09-03 22:22:08 +08:00
|
|
|
|
2020-09-04 17:59:09 +08:00
|
|
|
export default function getSchema(extensions: Extensions): Schema {
|
2020-09-10 03:18:04 +08:00
|
|
|
extensions.forEach(extension => {
|
|
|
|
resolveExtensionConfig(extension, 'name')
|
|
|
|
resolveExtensionConfig(extension, 'defaults')
|
|
|
|
resolveExtensionConfig(extension, 'topNode')
|
|
|
|
|
2020-09-24 06:29:05 +08:00
|
|
|
const { name } = extension.config
|
2020-10-09 22:37:48 +08:00
|
|
|
const options = {
|
|
|
|
...extension.config.defaults,
|
|
|
|
...extension.options,
|
|
|
|
}
|
2020-09-10 03:18:04 +08:00
|
|
|
|
|
|
|
resolveExtensionConfig(extension, 'schema', { name, options })
|
|
|
|
})
|
|
|
|
|
2020-09-03 22:22:08 +08:00
|
|
|
return new Schema({
|
|
|
|
topNode: getTopNodeFromExtensions(extensions),
|
|
|
|
nodes: getNodesFromExtensions(extensions),
|
|
|
|
marks: getMarksFromExtensions(extensions),
|
|
|
|
})
|
|
|
|
}
|