Skip to content

Commit

Permalink
feature: allow to customize the tag of the contentDOMElement
Browse files Browse the repository at this point in the history
  • Loading branch information
nikgraf committed Apr 25, 2023
1 parent 0dcc684 commit 540a38d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
1 change: 1 addition & 0 deletions packages/core/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ export interface NodeViewRendererOptions {
ignoreMutation:
| ((props: { mutation: MutationRecord | { type: 'selection'; target: Element } }) => boolean)
| null
preventContentDOMElement: boolean
}

export type NodeViewRendererProps = {
Expand Down
10 changes: 7 additions & 3 deletions packages/react/src/ReactNodeViewRenderer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,13 @@ class ReactNodeView extends NodeView<

ReactNodeViewProvider.displayName = 'ReactNodeView'

this.contentDOMElement = this.node.isLeaf
? null
: document.createElement(this.node.isInline ? 'span' : 'div')
if (this.node.isLeaf) {
this.contentDOMElement = null
} else if (this.options.contentDOMElementTag) {
this.contentDOMElement = document.createElement(this.options.contentDOMElementTag)
} else {
this.contentDOMElement = document.createElement(this.node.isInline ? 'span' : 'div')
}

if (this.contentDOMElement) {
// For some reason the whiteSpace prop is not inherited properly in Chrome and Safari
Expand Down

0 comments on commit 540a38d

Please sign in to comment.