2020-09-10 03:18:04 +08:00
|
|
|
import deepmerge from 'deepmerge'
|
2020-10-10 04:59:25 +08:00
|
|
|
import { NodeSpec, 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-10-10 04:59:25 +08:00
|
|
|
import Node from '../Node'
|
|
|
|
import Mark from '../Mark'
|
|
|
|
import Extension from '../Extension'
|
2020-09-03 22:22:08 +08:00
|
|
|
|
2020-09-04 17:59:09 +08:00
|
|
|
export default function getSchema(extensions: Extensions): Schema {
|
2020-10-10 04:59:25 +08:00
|
|
|
const baseExtensions = extensions.filter(extension => extension.type === 'extension') as Extension[]
|
|
|
|
const nodeExtensions = extensions.filter(extension => extension.type === 'node') as Node[]
|
|
|
|
const markExtensions = extensions.filter(extension => extension.type === 'mark') as Mark[]
|
|
|
|
|
|
|
|
const nodes = Object.fromEntries(nodeExtensions.map(node => {
|
|
|
|
return [
|
|
|
|
node.name,
|
|
|
|
{
|
|
|
|
content: node.content,
|
|
|
|
group: node.group,
|
|
|
|
parseDOM: node.parseHTML(),
|
|
|
|
toDOM: node.renderHTML,
|
|
|
|
} as unknown as NodeSpec,
|
|
|
|
]
|
|
|
|
}))
|
|
|
|
|
|
|
|
console.log({ nodes })
|
|
|
|
|
|
|
|
const topNode = nodeExtensions.find(extension => extension.topNode)?.name
|
|
|
|
|
|
|
|
// extensions.forEach(extension => {
|
|
|
|
// resolveExtensionConfig(extension, 'name')
|
|
|
|
// resolveExtensionConfig(extension, 'defaults')
|
|
|
|
// resolveExtensionConfig(extension, 'topNode')
|
|
|
|
|
|
|
|
// const { name } = extension.config
|
|
|
|
// const options = {
|
|
|
|
// ...extension.config.defaults,
|
|
|
|
// ...extension.options,
|
|
|
|
// }
|
|
|
|
|
|
|
|
// resolveExtensionConfig(extension, 'schema', { name, options })
|
|
|
|
// })
|
|
|
|
|
|
|
|
// return new Schema({
|
|
|
|
// topNode: getTopNodeFromExtensions(extensions),
|
|
|
|
// nodes: getNodesFromExtensions(extensions),
|
|
|
|
// marks: getMarksFromExtensions(extensions),
|
|
|
|
// })
|
2020-09-10 03:18:04 +08:00
|
|
|
|
2020-09-03 22:22:08 +08:00
|
|
|
return new Schema({
|
2020-10-10 04:59:25 +08:00
|
|
|
topNode,
|
|
|
|
nodes,
|
|
|
|
marks: {},
|
|
|
|
// topNode: getTopNodeFromExtensions(extensions),
|
|
|
|
// nodes: getNodesFromExtensions(extensions),
|
|
|
|
// marks: getMarksFromExtensions(extensions),
|
2020-09-03 22:22:08 +08:00
|
|
|
})
|
|
|
|
}
|