feat: render wrapper element for inline node views as span, fix #242

This commit is contained in:
Philipp Kühn
2021-04-04 21:43:48 +02:00
parent 5faf1ab10f
commit bdb5d72495
2 changed files with 6 additions and 3 deletions

View File

@@ -66,6 +66,9 @@ class ReactNodeView extends NodeView<React.FunctionComponent, Editor> {
this.renderer = new ReactRenderer(ReactNodeViewProvider, {
editor: this.editor,
props,
as: this.node.isInline
? 'span'
: 'div'
})
}

View File

@@ -11,9 +11,9 @@ function isClassComponent(Component: any) {
}
export interface ReactRendererOptions {
as?: string,
editor: Editor,
props?: AnyObject,
as?: string,
}
export class ReactRenderer {
@@ -31,12 +31,12 @@ export class ReactRenderer {
ref: React.Component | null = null
constructor(component: React.Component | React.FunctionComponent, { props = {}, editor }: ReactRendererOptions) {
constructor(component: React.Component | React.FunctionComponent, { editor, props = {}, as = 'div' }: ReactRendererOptions) {
this.id = Math.floor(Math.random() * 0xFFFFFFFF).toString()
this.component = component
this.editor = editor
this.props = props
this.element = document.createElement('div')
this.element = document.createElement(as)
this.element.classList.add('react-renderer')
this.render()
}