@tiptap/react 2.6.0 → 2.6.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,6 +1,5 @@
1
1
  import { Editor } from '@tiptap/core';
2
2
  import React from 'react';
3
- import { Editor as ExtendedEditor } from './Editor.js';
4
3
  export interface ReactRendererOptions {
5
4
  /**
6
5
  * The editor instance.
@@ -48,7 +47,7 @@ type ComponentType<R, P> = React.ComponentClass<P> | React.FunctionComponent<P>
48
47
  */
49
48
  export declare class ReactRenderer<R = unknown, P = unknown> {
50
49
  id: string;
51
- editor: ExtendedEditor;
50
+ editor: Editor;
52
51
  component: any;
53
52
  element: Element;
54
53
  props: Record<string, any>;
@@ -1,6 +1,5 @@
1
1
  export * from './BubbleMenu.js';
2
2
  export * from './Context.js';
3
- export { Editor } from './Editor.js';
4
3
  export * from './EditorContent.js';
5
4
  export * from './FloatingMenu.js';
6
5
  export * from './NodeViewContent.js';
@@ -10,4 +9,5 @@ export * from './ReactRenderer.js';
10
9
  export * from './useEditor.js';
11
10
  export * from './useEditorState.js';
12
11
  export * from './useReactNodeView.js';
12
+ export { Editor } from '@tiptap/core';
13
13
  export * from '@tiptap/core';
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.0",
4
+ "version": "2.6.1",
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.0",
33
- "@tiptap/extension-floating-menu": "^2.6.0",
32
+ "@tiptap/extension-bubble-menu": "^2.6.1",
33
+ "@tiptap/extension-floating-menu": "^2.6.1",
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.0",
39
- "@tiptap/pm": "^2.6.0",
38
+ "@tiptap/core": "^2.6.1",
39
+ "@tiptap/pm": "^2.6.1",
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.0",
47
- "@tiptap/pm": "^2.6.0",
46
+ "@tiptap/core": "^2.6.1",
47
+ "@tiptap/pm": "^2.6.1",
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 as ReactEditor} />
47
+ <EditorContent editor={currentEditor} />
49
48
  )}
50
49
  </EditorConsumer>
51
50
  {children}
package/src/Editor.ts CHANGED
@@ -1,16 +1,13 @@
1
- import { Editor as CoreEditor } from '@tiptap/core'
2
- import React from 'react'
1
+ import { Editor } from '@tiptap/core'
2
+ import { ReactPortal } from 'react'
3
3
 
4
4
  import { ReactRenderer } from './ReactRenderer.js'
5
5
 
6
- type ContentComponent = {
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, React.ReactPortal>;
11
- getServerSnapshot: () => Record<string, React.ReactPortal>;
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
  }
@@ -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 { Editor } from './Editor.js'
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: Exclude<Editor['contentComponent'], null> }> = ({
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(): Exclude<Editor['contentComponent'], null> {
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).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 { editor } = this.props
124
+ const editor = this.props.editor as EditorWithContentComponent
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 { editor } = this.props
168
+ const editor = this.props.editor as EditorWithContentComponent
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
@@ -12,6 +12,7 @@ export const NodeViewContent: React.FC<NodeViewContentProps> = props => {
12
12
  const { nodeViewContentRef } = useReactNodeView()
13
13
 
14
14
  return (
15
+ // @ts-ignore
15
16
  <Tag
16
17
  {...props}
17
18
  ref={nodeViewContentRef}
@@ -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 { Editor } from './Editor.js'
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 Editor).contentComponent) {
220
+ if (!(props.editor as EditorWithContentComponent).contentComponent) {
220
221
  return {}
221
222
  }
222
223
 
@@ -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 { Editor as ExtendedEditor } from './Editor.js'
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: ExtendedEditor
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 ExtendedEditor
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
- this.editor?.contentComponent?.setRenderer(this.id, this)
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?.contentComponent?.removeRenderer(this.id)
162
+ const editor = this.editor as EditorWithContentComponent
163
+
164
+ editor?.contentComponent?.removeRenderer(this.id)
162
165
  }
163
166
  }
package/src/index.ts CHANGED
@@ -1,6 +1,5 @@
1
1
  export * from './BubbleMenu.js'
2
2
  export * from './Context.js'
3
- export { Editor } from './Editor.js'
4
3
  export * from './EditorContent.js'
5
4
  export * from './FloatingMenu.js'
6
5
  export * from './NodeViewContent.js'
@@ -10,4 +9,5 @@ export * from './ReactRenderer.js'
10
9
  export * from './useEditor.js'
11
10
  export * from './useEditorState.js'
12
11
  export * from './useReactNodeView.js'
12
+ export { Editor } from '@tiptap/core'
13
13
  export * from '@tiptap/core'