tiptap/packages/core/src/utils/getSchema.ts

30 lines
996 B
TypeScript
Raw Normal View History

2020-09-10 03:18:04 +08:00
import deepmerge from 'deepmerge'
import { Schema } from 'prosemirror-model'
2020-09-04 17:59:09 +08:00
import { Extensions } from '../types'
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-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 })
})
return new Schema({
topNode: getTopNodeFromExtensions(extensions),
nodes: getNodesFromExtensions(extensions),
marks: getMarksFromExtensions(extensions),
})
}