add basic implementation for attributes
This commit is contained in:
38
packages/core/src/utils/getAttributesFromExtensions.ts
Normal file
38
packages/core/src/utils/getAttributesFromExtensions.ts
Normal file
@@ -0,0 +1,38 @@
|
||||
import {
|
||||
Extensions, Attributes, Attribute, ExtensionAttribute,
|
||||
} from '../types'
|
||||
import splitExtensions from './splitExtensions'
|
||||
|
||||
export default function getAttributesFromExtensions(extensions: Extensions) {
|
||||
const allAttributes: ExtensionAttribute[] = []
|
||||
|
||||
const { nodeExtensions } = splitExtensions(extensions)
|
||||
|
||||
const defaultAttribute: Required<Attribute> = {
|
||||
default: null,
|
||||
rendered: true,
|
||||
renderHTML: () => ({}),
|
||||
parseHTML: () => null,
|
||||
}
|
||||
|
||||
nodeExtensions.forEach(extension => {
|
||||
const context = {
|
||||
options: extension.options,
|
||||
}
|
||||
|
||||
const attributes = extension.createAttributes.bind(context)() as Attributes
|
||||
|
||||
Object.entries(attributes).forEach(([name, attribute]) => {
|
||||
allAttributes.push({
|
||||
type: extension.name,
|
||||
name,
|
||||
attribute: {
|
||||
...defaultAttribute,
|
||||
...attribute,
|
||||
},
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
return allAttributes
|
||||
}
|
||||
Reference in New Issue
Block a user