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:
@@ -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}`,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user