feat: Add as option and pass through to ReactRenderer (#2213)

* Add `as` option and pass through to ReactRenderer

* Fix type, oops

* type `as` as string
This commit is contained in:
Jessica Chong
2021-12-02 05:13:03 -08:00
committed by GitHub
parent fa18ffe6d7
commit dedcf17d53

View File

@@ -20,6 +20,7 @@ export interface ReactNodeViewRendererOptions extends NodeViewRendererOptions {
newDecorations: Decoration[],
updateProps: () => void,
}) => boolean) | null,
as?: string,
}
class ReactNodeView extends NodeView<React.FunctionComponent, Editor, ReactNodeViewRendererOptions> {
@@ -81,12 +82,15 @@ class ReactNodeView extends NodeView<React.FunctionComponent, Editor, ReactNodeV
this.contentDOMElement.style.whiteSpace = 'inherit'
}
let as = this.node.isInline ? 'span' : 'div'
if (this.options.as) {
as = this.options.as
}
this.renderer = new ReactRenderer(ReactNodeViewProvider, {
editor: this.editor,
props,
as: this.node.isInline
? 'span'
: 'div',
as,
className: `node-${this.node.type.name}`,
})
}