@tiptap/react 2.23.1 → 2.24.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,9 @@
1
1
  import type {
2
- DecorationWithType, Editor, NodeViewRenderer, NodeViewRendererOptions,
2
+ DecorationWithType,
3
+ Editor,
4
+ NodeViewRenderer,
5
+ NodeViewRendererOptions,
6
+ NodeViewRendererProps,
3
7
  } from '@tiptap/core'
4
8
  import { getRenderedAttributes, NodeView } from '@tiptap/core'
5
9
  import type { Node, Node as ProseMirrorNode } from '@tiptap/pm/model'
@@ -66,6 +70,28 @@ export class ReactNodeView<
66
70
  */
67
71
  contentDOMElement!: HTMLElement | null
68
72
 
73
+ constructor(component: Component, props: NodeViewRendererProps, options?: Partial<Options>) {
74
+ super(component, props, options)
75
+
76
+ if (!this.node.isLeaf) {
77
+ if (this.options.contentDOMElementTag) {
78
+ this.contentDOMElement = document.createElement(this.options.contentDOMElementTag)
79
+ } else {
80
+ this.contentDOMElement = document.createElement(this.node.isInline ? 'span' : 'div')
81
+ }
82
+
83
+ this.contentDOMElement.dataset.nodeViewContentReact = ''
84
+ this.contentDOMElement.dataset.nodeViewWrapper = ''
85
+
86
+ // For some reason the whiteSpace prop is not inherited properly in Chrome and Safari
87
+ // With this fix it seems to work fine
88
+ // See: https://github.com/ueberdosis/tiptap/issues/1197
89
+ this.contentDOMElement.style.whiteSpace = 'inherit'
90
+
91
+ this.dom.appendChild(this.contentDOMElement)
92
+ }
93
+ }
94
+
69
95
  /**
70
96
  * Setup the React component.
71
97
  * Called on initialization.
@@ -97,6 +123,10 @@ export class ReactNodeView<
97
123
  const onDragStart = this.onDragStart.bind(this)
98
124
  const nodeViewContentRef: ReactNodeViewContextProps['nodeViewContentRef'] = element => {
99
125
  if (element && this.contentDOMElement && element.firstChild !== this.contentDOMElement) {
126
+ // remove the nodeViewWrapper attribute from the element
127
+ if (element.hasAttribute('data-node-view-wrapper')) {
128
+ element.removeAttribute('data-node-view-wrapper')
129
+ }
100
130
  element.appendChild(this.contentDOMElement)
101
131
  }
102
132
  }
@@ -114,22 +144,6 @@ export class ReactNodeView<
114
144
 
115
145
  ReactNodeViewProvider.displayName = 'ReactNodeView'
116
146
 
117
- if (this.node.isLeaf) {
118
- this.contentDOMElement = null
119
- } else if (this.options.contentDOMElementTag) {
120
- this.contentDOMElement = document.createElement(this.options.contentDOMElementTag)
121
- } else {
122
- this.contentDOMElement = document.createElement(this.node.isInline ? 'span' : 'div')
123
- }
124
-
125
- if (this.contentDOMElement) {
126
- this.contentDOMElement.dataset.nodeViewContentReact = ''
127
- // For some reason the whiteSpace prop is not inherited properly in Chrome and Safari
128
- // With this fix it seems to work fine
129
- // See: https://github.com/ueberdosis/tiptap/issues/1197
130
- this.contentDOMElement.style.whiteSpace = 'inherit'
131
- }
132
-
133
147
  let as = this.node.isInline ? 'span' : 'div'
134
148
 
135
149
  if (this.options.as) {
@@ -8,7 +8,6 @@ import type {
8
8
  RefAttributes,
9
9
  } from 'react'
10
10
  import React, { version as reactVersion } from 'react'
11
- import { flushSync } from 'react-dom'
12
11
 
13
12
  import { EditorWithContentComponent } from './Editor.js'
14
13
 
@@ -185,15 +184,9 @@ export class ReactRenderer<R = unknown, P extends Record<string, any> = object>
185
184
  this.element.classList.add(...className.split(' '))
186
185
  }
187
186
 
188
- if (this.editor.isInitialized) {
189
- // On first render, we need to flush the render synchronously
190
- // Renders afterwards can be async, but this fixes a cursor positioning issue
191
- flushSync(() => {
192
- this.render()
193
- })
194
- } else {
187
+ queueMicrotask(() => {
195
188
  this.render()
196
- }
189
+ })
197
190
  }
198
191
 
199
192
  /**