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[], newDecorations: Decoration[],
updateProps: () => void, updateProps: () => void,
}) => boolean) | null, }) => boolean) | null,
as?: string,
} }
class ReactNodeView extends NodeView<React.FunctionComponent, Editor, ReactNodeViewRendererOptions> { 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' 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, { this.renderer = new ReactRenderer(ReactNodeViewProvider, {
editor: this.editor, editor: this.editor,
props, props,
as: this.node.isInline as,
? 'span'
: 'div',
className: `node-${this.node.type.name}`, className: `node-${this.node.type.name}`,
}) })
} }