isRequired on attrs

This commit is contained in:
Jon Noronha
2022-03-22 18:01:35 -07:00
committed by Dominik
parent 6fe302430e
commit 23483d5e1a
2 changed files with 13 additions and 5 deletions

View File

@@ -24,6 +24,7 @@ export function getAttributesFromExtensions(extensions: Extensions): ExtensionAt
renderHTML: null, renderHTML: null,
parseHTML: null, parseHTML: null,
keepOnSplit: true, keepOnSplit: true,
isRequired: false,
} }
extensions.forEach(extension => { extensions.forEach(extension => {
@@ -87,14 +88,20 @@ export function getAttributesFromExtensions(extensions: Extensions): ExtensionAt
Object Object
.entries(attributes) .entries(attributes)
.forEach(([name, attribute]) => { .forEach(([name, attribute]) => {
const mergedAttr = {
...defaultAttribute,
...attribute,
}
if (attribute.isRequired && attribute.default === undefined) {
delete mergedAttr.default;
}
extensionAttributes.push({ extensionAttributes.push({
type: extension.name, type: extension.name,
name, name,
attribute: { attribute: mergedAttr,
...defaultAttribute, });
...attribute,
},
})
}) })
}) })

View File

@@ -128,6 +128,7 @@ export type Attribute = {
renderHTML?: ((attributes: Record<string, any>) => Record<string, any> | null) | null, renderHTML?: ((attributes: Record<string, any>) => Record<string, any> | null) | null,
parseHTML?: ((element: HTMLElement) => any | null) | null, parseHTML?: ((element: HTMLElement) => any | null) | null,
keepOnSplit: boolean, keepOnSplit: boolean,
isRequired?: boolean,
} }
export type Attributes = { export type Attributes = {