From 57c3c70bcc3d0476a34daa575127fe3c70d0d4b2 Mon Sep 17 00:00:00 2001 From: Nik Graf Date: Tue, 25 Apr 2023 15:55:52 +0200 Subject: [PATCH] feature: allow to customize the tag of the contentDOMElement --- packages/core/src/types.ts | 1 + packages/react/src/ReactNodeViewRenderer.tsx | 10 +++++++--- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/core/src/types.ts b/packages/core/src/types.ts index 8e1780e6ebe..b386e0f9917 100644 --- a/packages/core/src/types.ts +++ b/packages/core/src/types.ts @@ -170,6 +170,7 @@ export interface NodeViewRendererOptions { ignoreMutation: | ((props: { mutation: MutationRecord | { type: 'selection'; target: Element } }) => boolean) | null + contentDOMElementTag: string } export type NodeViewRendererProps = { diff --git a/packages/react/src/ReactNodeViewRenderer.tsx b/packages/react/src/ReactNodeViewRenderer.tsx index 514cb9b3f67..213c0323e18 100644 --- a/packages/react/src/ReactNodeViewRenderer.tsx +++ b/packages/react/src/ReactNodeViewRenderer.tsx @@ -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