@tiptap/react 2.6.0 → 2.6.2
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.
- package/dist/index.cjs +12 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +15 -17
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +12 -15
- package/dist/index.umd.js.map +1 -1
- package/dist/packages/react/src/Editor.d.ts +8 -9
- package/dist/packages/react/src/EditorContent.d.ts +1 -1
- package/dist/packages/react/src/ReactRenderer.d.ts +1 -2
- package/dist/packages/react/src/index.d.ts +0 -1
- package/package.json +7 -7
- package/src/Context.tsx +1 -2
- package/src/Editor.ts +6 -9
- package/src/EditorContent.tsx +8 -6
- package/src/NodeViewContent.tsx +1 -0
- package/src/ReactNodeViewRenderer.tsx +3 -2
- package/src/ReactRenderer.tsx +8 -5
- package/src/index.ts +0 -1
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tiptap/react",
|
|
3
3
|
"description": "React components for tiptap",
|
|
4
|
-
"version": "2.6.
|
|
4
|
+
"version": "2.6.2",
|
|
5
5
|
"homepage": "https://tiptap.dev",
|
|
6
6
|
"keywords": [
|
|
7
7
|
"tiptap",
|
|
@@ -29,22 +29,22 @@
|
|
|
29
29
|
"dist"
|
|
30
30
|
],
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@tiptap/extension-bubble-menu": "^2.6.
|
|
33
|
-
"@tiptap/extension-floating-menu": "^2.6.
|
|
32
|
+
"@tiptap/extension-bubble-menu": "^2.6.2",
|
|
33
|
+
"@tiptap/extension-floating-menu": "^2.6.2",
|
|
34
34
|
"@types/use-sync-external-store": "^0.0.6",
|
|
35
35
|
"use-sync-external-store": "^1.2.2"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@tiptap/core": "^2.6.
|
|
39
|
-
"@tiptap/pm": "^2.6.
|
|
38
|
+
"@tiptap/core": "^2.6.2",
|
|
39
|
+
"@tiptap/pm": "^2.6.2",
|
|
40
40
|
"@types/react": "^18.2.14",
|
|
41
41
|
"@types/react-dom": "^18.2.6",
|
|
42
42
|
"react": "^18.0.0",
|
|
43
43
|
"react-dom": "^18.0.0"
|
|
44
44
|
},
|
|
45
45
|
"peerDependencies": {
|
|
46
|
-
"@tiptap/core": "^2.6.
|
|
47
|
-
"@tiptap/pm": "^2.6.
|
|
46
|
+
"@tiptap/core": "^2.6.2",
|
|
47
|
+
"@tiptap/pm": "^2.6.2",
|
|
48
48
|
"react": "^17.0.0 || ^18.0.0",
|
|
49
49
|
"react-dom": "^17.0.0 || ^18.0.0"
|
|
50
50
|
},
|
package/src/Context.tsx
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { Editor } from '@tiptap/core'
|
|
2
2
|
import React, { createContext, ReactNode, useContext } from 'react'
|
|
3
3
|
|
|
4
|
-
import { Editor as ReactEditor } from './Editor.js'
|
|
5
4
|
import { EditorContent } from './EditorContent.js'
|
|
6
5
|
import { useEditor, UseEditorOptions } from './useEditor.js'
|
|
7
6
|
|
|
@@ -45,7 +44,7 @@ export function EditorProvider({
|
|
|
45
44
|
{slotBefore}
|
|
46
45
|
<EditorConsumer>
|
|
47
46
|
{({ editor: currentEditor }) => (
|
|
48
|
-
<EditorContent editor={currentEditor
|
|
47
|
+
<EditorContent editor={currentEditor} />
|
|
49
48
|
)}
|
|
50
49
|
</EditorConsumer>
|
|
51
50
|
{children}
|
package/src/Editor.ts
CHANGED
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
import { Editor
|
|
2
|
-
import
|
|
1
|
+
import { Editor } from '@tiptap/core'
|
|
2
|
+
import { ReactPortal } from 'react'
|
|
3
3
|
|
|
4
4
|
import { ReactRenderer } from './ReactRenderer.js'
|
|
5
5
|
|
|
6
|
-
type
|
|
6
|
+
export type EditorWithContentComponent = Editor & { contentComponent?: ContentComponent | null }
|
|
7
|
+
export type ContentComponent = {
|
|
7
8
|
setRenderer(id: string, renderer: ReactRenderer): void;
|
|
8
9
|
removeRenderer(id: string): void;
|
|
9
10
|
subscribe: (callback: () => void) => () => void;
|
|
10
|
-
getSnapshot: () => Record<string,
|
|
11
|
-
getServerSnapshot: () => Record<string,
|
|
12
|
-
}
|
|
13
|
-
|
|
14
|
-
export class Editor extends CoreEditor {
|
|
15
|
-
public contentComponent: ContentComponent | null = null
|
|
11
|
+
getSnapshot: () => Record<string, ReactPortal>;
|
|
12
|
+
getServerSnapshot: () => Record<string, ReactPortal>;
|
|
16
13
|
}
|
package/src/EditorContent.tsx
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
+
import { Editor } from '@tiptap/core'
|
|
1
2
|
import React, {
|
|
2
3
|
ForwardedRef, forwardRef, HTMLProps, LegacyRef, MutableRefObject,
|
|
3
4
|
} from 'react'
|
|
4
5
|
import ReactDOM from 'react-dom'
|
|
5
6
|
import { useSyncExternalStore } from 'use-sync-external-store/shim'
|
|
6
7
|
|
|
7
|
-
import {
|
|
8
|
+
import { ContentComponent, EditorWithContentComponent } from './Editor.js'
|
|
8
9
|
import { ReactRenderer } from './ReactRenderer.js'
|
|
9
10
|
|
|
10
11
|
const mergeRefs = <T extends HTMLDivElement>(
|
|
@@ -24,7 +25,7 @@ const mergeRefs = <T extends HTMLDivElement>(
|
|
|
24
25
|
/**
|
|
25
26
|
* This component renders all of the editor's node views.
|
|
26
27
|
*/
|
|
27
|
-
const Portals: React.FC<{ contentComponent:
|
|
28
|
+
const Portals: React.FC<{ contentComponent: ContentComponent }> = ({
|
|
28
29
|
contentComponent,
|
|
29
30
|
}) => {
|
|
30
31
|
// For performance reasons, we render the node view portals on state changes only
|
|
@@ -47,7 +48,7 @@ export interface EditorContentProps extends HTMLProps<HTMLDivElement> {
|
|
|
47
48
|
innerRef?: ForwardedRef<HTMLDivElement | null>;
|
|
48
49
|
}
|
|
49
50
|
|
|
50
|
-
function getInstance():
|
|
51
|
+
function getInstance(): ContentComponent {
|
|
51
52
|
const subscribers = new Set<() => void>()
|
|
52
53
|
let renderers: Record<string, React.ReactPortal> = {}
|
|
53
54
|
|
|
@@ -107,7 +108,7 @@ export class PureEditorContent extends React.Component<
|
|
|
107
108
|
this.initialized = false
|
|
108
109
|
|
|
109
110
|
this.state = {
|
|
110
|
-
hasContentComponentInitialized: Boolean(props.editor?.contentComponent),
|
|
111
|
+
hasContentComponentInitialized: Boolean((props.editor as EditorWithContentComponent | null)?.contentComponent),
|
|
111
112
|
}
|
|
112
113
|
}
|
|
113
114
|
|
|
@@ -120,7 +121,7 @@ export class PureEditorContent extends React.Component<
|
|
|
120
121
|
}
|
|
121
122
|
|
|
122
123
|
init() {
|
|
123
|
-
const
|
|
124
|
+
const editor = this.props.editor as EditorWithContentComponent | null
|
|
124
125
|
|
|
125
126
|
if (editor && !editor.isDestroyed && editor.options.element) {
|
|
126
127
|
if (editor.contentComponent) {
|
|
@@ -164,7 +165,7 @@ export class PureEditorContent extends React.Component<
|
|
|
164
165
|
}
|
|
165
166
|
|
|
166
167
|
componentWillUnmount() {
|
|
167
|
-
const
|
|
168
|
+
const editor = this.props.editor as EditorWithContentComponent | null
|
|
168
169
|
|
|
169
170
|
if (!editor) {
|
|
170
171
|
return
|
|
@@ -215,6 +216,7 @@ const EditorContentWithKey = forwardRef<HTMLDivElement, EditorContentProps>(
|
|
|
215
216
|
(props: Omit<EditorContentProps, 'innerRef'>, ref) => {
|
|
216
217
|
const key = React.useMemo(() => {
|
|
217
218
|
return Math.floor(Math.random() * 0xffffffff).toString()
|
|
219
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
218
220
|
}, [props.editor])
|
|
219
221
|
|
|
220
222
|
// Can't use JSX here because it conflicts with the type definition of Vue's JSX, so use createElement
|
package/src/NodeViewContent.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
DecorationWithType,
|
|
3
|
+
Editor,
|
|
3
4
|
NodeView,
|
|
4
5
|
NodeViewProps,
|
|
5
6
|
NodeViewRenderer,
|
|
@@ -10,7 +11,7 @@ import { Node as ProseMirrorNode } from '@tiptap/pm/model'
|
|
|
10
11
|
import { Decoration, NodeView as ProseMirrorNodeView } from '@tiptap/pm/view'
|
|
11
12
|
import React from 'react'
|
|
12
13
|
|
|
13
|
-
import {
|
|
14
|
+
import { EditorWithContentComponent } from './Editor.js'
|
|
14
15
|
import { ReactRenderer } from './ReactRenderer.js'
|
|
15
16
|
import { ReactNodeViewContext, ReactNodeViewContextProps } from './useReactNodeView.js'
|
|
16
17
|
|
|
@@ -216,7 +217,7 @@ export function ReactNodeViewRenderer(
|
|
|
216
217
|
// try to get the parent component
|
|
217
218
|
// this is important for vue devtools to show the component hierarchy correctly
|
|
218
219
|
// maybe it’s `undefined` because <editor-content> isn’t rendered yet
|
|
219
|
-
if (!(props.editor as
|
|
220
|
+
if (!(props.editor as EditorWithContentComponent).contentComponent) {
|
|
220
221
|
return {}
|
|
221
222
|
}
|
|
222
223
|
|
package/src/ReactRenderer.tsx
CHANGED
|
@@ -2,7 +2,7 @@ import { Editor } from '@tiptap/core'
|
|
|
2
2
|
import React from 'react'
|
|
3
3
|
import { flushSync } from 'react-dom'
|
|
4
4
|
|
|
5
|
-
import {
|
|
5
|
+
import { EditorWithContentComponent } from './Editor.js'
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Check if a component is a class component.
|
|
@@ -86,7 +86,7 @@ type ComponentType<R, P> =
|
|
|
86
86
|
export class ReactRenderer<R = unknown, P = unknown> {
|
|
87
87
|
id: string
|
|
88
88
|
|
|
89
|
-
editor:
|
|
89
|
+
editor: Editor
|
|
90
90
|
|
|
91
91
|
component: any
|
|
92
92
|
|
|
@@ -107,7 +107,7 @@ export class ReactRenderer<R = unknown, P = unknown> {
|
|
|
107
107
|
}: ReactRendererOptions) {
|
|
108
108
|
this.id = Math.floor(Math.random() * 0xFFFFFFFF).toString()
|
|
109
109
|
this.component = component
|
|
110
|
-
this.editor = editor as
|
|
110
|
+
this.editor = editor as EditorWithContentComponent
|
|
111
111
|
this.props = props
|
|
112
112
|
this.element = document.createElement(as)
|
|
113
113
|
this.element.classList.add('react-renderer')
|
|
@@ -136,6 +136,7 @@ export class ReactRenderer<R = unknown, P = unknown> {
|
|
|
136
136
|
render(): void {
|
|
137
137
|
const Component = this.component
|
|
138
138
|
const props = this.props
|
|
139
|
+
const editor = this.editor as EditorWithContentComponent
|
|
139
140
|
|
|
140
141
|
if (isClassComponent(Component) || isForwardRefComponent(Component)) {
|
|
141
142
|
props.ref = (ref: R) => {
|
|
@@ -145,7 +146,7 @@ export class ReactRenderer<R = unknown, P = unknown> {
|
|
|
145
146
|
|
|
146
147
|
this.reactElement = React.createElement(Component, props)
|
|
147
148
|
|
|
148
|
-
|
|
149
|
+
editor?.contentComponent?.setRenderer(this.id, this)
|
|
149
150
|
}
|
|
150
151
|
|
|
151
152
|
updateProps(props: Record<string, any> = {}): void {
|
|
@@ -158,6 +159,8 @@ export class ReactRenderer<R = unknown, P = unknown> {
|
|
|
158
159
|
}
|
|
159
160
|
|
|
160
161
|
destroy(): void {
|
|
161
|
-
this.editor
|
|
162
|
+
const editor = this.editor as EditorWithContentComponent
|
|
163
|
+
|
|
164
|
+
editor?.contentComponent?.removeRenderer(this.id)
|
|
162
165
|
}
|
|
163
166
|
}
|