feat: render wrapper element for inline node views as span, fix #242
This commit is contained in:
@@ -66,6 +66,9 @@ class ReactNodeView extends NodeView<React.FunctionComponent, Editor> {
|
|||||||
this.renderer = new ReactRenderer(ReactNodeViewProvider, {
|
this.renderer = new ReactRenderer(ReactNodeViewProvider, {
|
||||||
editor: this.editor,
|
editor: this.editor,
|
||||||
props,
|
props,
|
||||||
|
as: this.node.isInline
|
||||||
|
? 'span'
|
||||||
|
: 'div'
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -11,9 +11,9 @@ function isClassComponent(Component: any) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
export interface ReactRendererOptions {
|
export interface ReactRendererOptions {
|
||||||
as?: string,
|
|
||||||
editor: Editor,
|
editor: Editor,
|
||||||
props?: AnyObject,
|
props?: AnyObject,
|
||||||
|
as?: string,
|
||||||
}
|
}
|
||||||
|
|
||||||
export class ReactRenderer {
|
export class ReactRenderer {
|
||||||
@@ -31,12 +31,12 @@ export class ReactRenderer {
|
|||||||
|
|
||||||
ref: React.Component | null = null
|
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.id = Math.floor(Math.random() * 0xFFFFFFFF).toString()
|
||||||
this.component = component
|
this.component = component
|
||||||
this.editor = editor
|
this.editor = editor
|
||||||
this.props = props
|
this.props = props
|
||||||
this.element = document.createElement('div')
|
this.element = document.createElement(as)
|
||||||
this.element.classList.add('react-renderer')
|
this.element.classList.add('react-renderer')
|
||||||
this.render()
|
this.render()
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user