@tiptap/react 3.0.0-next.3 → 3.0.0-next.4
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/LICENSE.md +21 -0
- package/README.md +5 -1
- package/dist/index.cjs +72 -102
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +24 -26
- package/dist/index.d.ts +24 -26
- package/dist/index.js +72 -119
- package/dist/index.js.map +1 -1
- package/package.json +18 -14
- package/src/BubbleMenu.tsx +7 -32
- package/src/Context.tsx +9 -13
- package/src/Editor.ts +5 -5
- package/src/EditorContent.tsx +8 -18
- package/src/FloatingMenu.tsx +49 -64
- package/src/NodeViewContent.tsx +12 -9
- package/src/NodeViewWrapper.tsx +2 -2
- package/src/ReactNodeViewRenderer.tsx +22 -35
- package/src/ReactRenderer.tsx +16 -25
- package/src/useEditor.ts +11 -20
- package/src/useEditorState.ts +14 -19
- package/src/useReactNodeView.ts +20 -5
package/src/useEditor.ts
CHANGED
|
@@ -1,16 +1,10 @@
|
|
|
1
1
|
import { type EditorOptions, Editor } from '@tiptap/core'
|
|
2
|
-
import {
|
|
3
|
-
DependencyList,
|
|
4
|
-
MutableRefObject,
|
|
5
|
-
useDebugValue,
|
|
6
|
-
useEffect,
|
|
7
|
-
useRef,
|
|
8
|
-
useState,
|
|
9
|
-
} from 'react'
|
|
2
|
+
import { DependencyList, MutableRefObject, useDebugValue, useEffect, useRef, useState } from 'react'
|
|
10
3
|
import { useSyncExternalStore } from 'use-sync-external-store/shim'
|
|
11
4
|
|
|
12
5
|
import { useEditorState } from './useEditorState.js'
|
|
13
6
|
|
|
7
|
+
// @ts-ignore
|
|
14
8
|
const isDev = process.env.NODE_ENV !== 'production'
|
|
15
9
|
const isSSR = typeof window === 'undefined'
|
|
16
10
|
const isNext = isSSR || Boolean(typeof window !== 'undefined' && (window as any).next)
|
|
@@ -25,14 +19,14 @@ export type UseEditorOptions = Partial<EditorOptions> & {
|
|
|
25
19
|
* If server-side rendering, set this to `false`.
|
|
26
20
|
* @default true
|
|
27
21
|
*/
|
|
28
|
-
immediatelyRender?: boolean
|
|
22
|
+
immediatelyRender?: boolean
|
|
29
23
|
/**
|
|
30
24
|
* Whether to re-render the editor on each transaction.
|
|
31
25
|
* This is legacy behavior that will be removed in future versions.
|
|
32
26
|
* @default false
|
|
33
27
|
*/
|
|
34
|
-
shouldRerenderOnTransaction?: boolean
|
|
35
|
-
}
|
|
28
|
+
shouldRerenderOnTransaction?: boolean
|
|
29
|
+
}
|
|
36
30
|
|
|
37
31
|
/**
|
|
38
32
|
* This class handles the creation, destruction, and re-creation of the editor instance.
|
|
@@ -229,8 +223,8 @@ class EditorInstanceManager {
|
|
|
229
223
|
this.previousDeps = deps
|
|
230
224
|
return
|
|
231
225
|
}
|
|
232
|
-
const depsAreEqual =
|
|
233
|
-
&& this.previousDeps.every((dep, index) => dep === deps[index])
|
|
226
|
+
const depsAreEqual =
|
|
227
|
+
this.previousDeps.length === deps.length && this.previousDeps.every((dep, index) => dep === deps[index])
|
|
234
228
|
|
|
235
229
|
if (depsAreEqual) {
|
|
236
230
|
// deps exist and are equal, no need to recreate
|
|
@@ -289,8 +283,8 @@ class EditorInstanceManager {
|
|
|
289
283
|
*/
|
|
290
284
|
export function useEditor(
|
|
291
285
|
options: UseEditorOptions & { immediatelyRender: false },
|
|
292
|
-
deps?: DependencyList
|
|
293
|
-
): Editor | null
|
|
286
|
+
deps?: DependencyList,
|
|
287
|
+
): Editor | null
|
|
294
288
|
|
|
295
289
|
/**
|
|
296
290
|
* This hook allows you to create an editor instance.
|
|
@@ -299,12 +293,9 @@ export function useEditor(
|
|
|
299
293
|
* @returns The editor instance
|
|
300
294
|
* @example const editor = useEditor({ extensions: [...] })
|
|
301
295
|
*/
|
|
302
|
-
export function useEditor(options: UseEditorOptions, deps?: DependencyList): Editor
|
|
296
|
+
export function useEditor(options: UseEditorOptions, deps?: DependencyList): Editor
|
|
303
297
|
|
|
304
|
-
export function useEditor(
|
|
305
|
-
options: UseEditorOptions = {},
|
|
306
|
-
deps: DependencyList = [],
|
|
307
|
-
): Editor | null {
|
|
298
|
+
export function useEditor(options: UseEditorOptions = {}, deps: DependencyList = []): Editor | null {
|
|
308
299
|
const mostRecentOptions = useRef(options)
|
|
309
300
|
|
|
310
301
|
mostRecentOptions.current = options
|
package/src/useEditorState.ts
CHANGED
|
@@ -1,35 +1,30 @@
|
|
|
1
1
|
import type { Editor } from '@tiptap/core'
|
|
2
2
|
import deepEqual from 'fast-deep-equal/es6/react'
|
|
3
|
-
import {
|
|
4
|
-
useDebugValue, useEffect, useLayoutEffect, useState,
|
|
5
|
-
} from 'react'
|
|
3
|
+
import { useDebugValue, useEffect, useLayoutEffect, useState } from 'react'
|
|
6
4
|
import { useSyncExternalStoreWithSelector } from 'use-sync-external-store/shim/with-selector'
|
|
7
5
|
|
|
8
6
|
const useIsomorphicLayoutEffect = typeof window !== 'undefined' ? useLayoutEffect : useEffect
|
|
9
7
|
|
|
10
8
|
export type EditorStateSnapshot<TEditor extends Editor | null = Editor | null> = {
|
|
11
|
-
editor: TEditor
|
|
12
|
-
transactionNumber: number
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export type UseEditorStateOptions<
|
|
16
|
-
TSelectorResult,
|
|
17
|
-
TEditor extends Editor | null = Editor | null,
|
|
18
|
-
> = {
|
|
9
|
+
editor: TEditor
|
|
10
|
+
transactionNumber: number
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export type UseEditorStateOptions<TSelectorResult, TEditor extends Editor | null = Editor | null> = {
|
|
19
14
|
/**
|
|
20
15
|
* The editor instance.
|
|
21
16
|
*/
|
|
22
|
-
editor: TEditor
|
|
17
|
+
editor: TEditor
|
|
23
18
|
/**
|
|
24
19
|
* A selector function to determine the value to compare for re-rendering.
|
|
25
20
|
*/
|
|
26
|
-
selector: (context: EditorStateSnapshot<TEditor>) => TSelectorResult
|
|
21
|
+
selector: (context: EditorStateSnapshot<TEditor>) => TSelectorResult
|
|
27
22
|
/**
|
|
28
23
|
* A custom equality function to determine if the editor should re-render.
|
|
29
24
|
* @default `deepEqual` from `fast-deep-equal`
|
|
30
25
|
*/
|
|
31
|
-
equalityFn?: (a: TSelectorResult, b: TSelectorResult | null) => boolean
|
|
32
|
-
}
|
|
26
|
+
equalityFn?: (a: TSelectorResult, b: TSelectorResult | null) => boolean
|
|
27
|
+
}
|
|
33
28
|
|
|
34
29
|
/**
|
|
35
30
|
* To synchronize the editor instance with the component state,
|
|
@@ -126,8 +121,8 @@ class EditorStateManager<TEditor extends Editor | null = Editor | null> {
|
|
|
126
121
|
* })
|
|
127
122
|
*/
|
|
128
123
|
export function useEditorState<TSelectorResult>(
|
|
129
|
-
options: UseEditorStateOptions<TSelectorResult, Editor
|
|
130
|
-
): TSelectorResult
|
|
124
|
+
options: UseEditorStateOptions<TSelectorResult, Editor>,
|
|
125
|
+
): TSelectorResult
|
|
131
126
|
/**
|
|
132
127
|
* This hook allows you to watch for changes on the editor instance.
|
|
133
128
|
* It will allow you to select a part of the editor state and re-render the component when it changes.
|
|
@@ -140,8 +135,8 @@ export function useEditorState<TSelectorResult>(
|
|
|
140
135
|
* })
|
|
141
136
|
*/
|
|
142
137
|
export function useEditorState<TSelectorResult>(
|
|
143
|
-
options: UseEditorStateOptions<TSelectorResult, Editor | null
|
|
144
|
-
): TSelectorResult | null
|
|
138
|
+
options: UseEditorStateOptions<TSelectorResult, Editor | null>,
|
|
139
|
+
): TSelectorResult | null
|
|
145
140
|
|
|
146
141
|
/**
|
|
147
142
|
* This hook allows you to watch for changes on the editor instance.
|
package/src/useReactNodeView.ts
CHANGED
|
@@ -1,12 +1,27 @@
|
|
|
1
|
-
import { createContext, useContext } from 'react'
|
|
1
|
+
import { createContext, createElement, ReactNode, useContext } from 'react'
|
|
2
2
|
|
|
3
3
|
export interface ReactNodeViewContextProps {
|
|
4
|
-
onDragStart
|
|
5
|
-
nodeViewContentRef
|
|
4
|
+
onDragStart?: (event: DragEvent) => void
|
|
5
|
+
nodeViewContentRef?: (element: HTMLElement | null) => void
|
|
6
|
+
/**
|
|
7
|
+
* This allows you to add children into the NodeViewContent component.
|
|
8
|
+
* This is useful when statically rendering the content of a node view.
|
|
9
|
+
*/
|
|
10
|
+
nodeViewContentChildren?: ReactNode
|
|
6
11
|
}
|
|
7
12
|
|
|
8
|
-
export const ReactNodeViewContext = createContext<
|
|
9
|
-
onDragStart:
|
|
13
|
+
export const ReactNodeViewContext = createContext<ReactNodeViewContextProps>({
|
|
14
|
+
onDragStart: () => {
|
|
15
|
+
// no-op
|
|
16
|
+
},
|
|
17
|
+
nodeViewContentChildren: undefined,
|
|
18
|
+
nodeViewContentRef: () => {
|
|
19
|
+
// no-op
|
|
20
|
+
},
|
|
10
21
|
})
|
|
11
22
|
|
|
23
|
+
export const ReactNodeViewContentProvider = ({ children, content }: { children: ReactNode; content: ReactNode }) => {
|
|
24
|
+
return createElement(ReactNodeViewContext.Provider, { value: { nodeViewContentChildren: content } }, children)
|
|
25
|
+
}
|
|
26
|
+
|
|
12
27
|
export const useReactNodeView = () => useContext(ReactNodeViewContext)
|