@tiptap/react 3.20.2 → 3.20.3

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.d.ts DELETED
@@ -1,534 +0,0 @@
1
- import * as react_jsx_runtime from 'react/jsx-runtime';
2
- import { EditorOptions, Editor, MarkViewRendererOptions, MarkView, MarkViewProps, MarkViewRenderer, NodeViewProps, NodeViewRendererOptions, NodeView, NodeViewRendererProps, NodeViewRenderer } from '@tiptap/core';
3
- export * from '@tiptap/core';
4
- import * as React from 'react';
5
- import React__default, { DependencyList, ReactNode, HTMLAttributes, HTMLProps, ForwardedRef, ComponentProps, ComponentClass, FunctionComponent, ForwardRefExoticComponent, PropsWithoutRef, RefAttributes, ComponentType as ComponentType$1 } from 'react';
6
- import { Node } from '@tiptap/pm/model';
7
- import { Decoration, DecorationSource } from '@tiptap/pm/view';
8
-
9
- /**
10
- * The options for the `useEditor` hook.
11
- */
12
- type UseEditorOptions = Partial<EditorOptions> & {
13
- /**
14
- * Whether to render the editor on the first render.
15
- * If client-side rendering, set this to `true`.
16
- * If server-side rendering, set this to `false`.
17
- * @default true
18
- */
19
- immediatelyRender?: boolean;
20
- /**
21
- * Whether to re-render the editor on each transaction.
22
- * This is legacy behavior that will be removed in future versions.
23
- * @default false
24
- */
25
- shouldRerenderOnTransaction?: boolean;
26
- };
27
- /**
28
- * This hook allows you to create an editor instance.
29
- * @param options The editor options
30
- * @param deps The dependencies to watch for changes
31
- * @returns The editor instance
32
- * @example const editor = useEditor({ extensions: [...] })
33
- */
34
- declare function useEditor(options: UseEditorOptions & {
35
- immediatelyRender: false;
36
- }, deps?: DependencyList): Editor | null;
37
- /**
38
- * This hook allows you to create an editor instance.
39
- * @param options The editor options
40
- * @param deps The dependencies to watch for changes
41
- * @returns The editor instance
42
- * @example const editor = useEditor({ extensions: [...] })
43
- */
44
- declare function useEditor(options: UseEditorOptions, deps?: DependencyList): Editor;
45
-
46
- type EditorContextValue = {
47
- editor: Editor | null;
48
- };
49
- declare const EditorContext: React__default.Context<EditorContextValue>;
50
- declare const EditorConsumer: React__default.Consumer<EditorContextValue>;
51
- /**
52
- * A hook to get the current editor instance.
53
- */
54
- declare const useCurrentEditor: () => EditorContextValue;
55
- type EditorProviderProps = {
56
- children?: ReactNode;
57
- slotBefore?: ReactNode;
58
- slotAfter?: ReactNode;
59
- editorContainerProps?: HTMLAttributes<HTMLDivElement>;
60
- } & UseEditorOptions;
61
- /**
62
- * This is the provider component for the editor.
63
- * It allows the editor to be accessible across the entire component tree
64
- * with `useCurrentEditor`.
65
- */
66
- declare function EditorProvider({ children, slotAfter, slotBefore, editorContainerProps, ...editorOptions }: EditorProviderProps): react_jsx_runtime.JSX.Element | null;
67
-
68
- interface EditorContentProps extends HTMLProps<HTMLDivElement> {
69
- editor: Editor | null;
70
- innerRef?: ForwardedRef<HTMLDivElement | null>;
71
- }
72
- declare class PureEditorContent extends React__default.Component<EditorContentProps, {
73
- hasContentComponentInitialized: boolean;
74
- }> {
75
- editorContentRef: React__default.RefObject<any>;
76
- initialized: boolean;
77
- unsubscribeToContentComponent?: () => void;
78
- constructor(props: EditorContentProps);
79
- componentDidMount(): void;
80
- componentDidUpdate(): void;
81
- init(): void;
82
- componentWillUnmount(): void;
83
- render(): react_jsx_runtime.JSX.Element;
84
- }
85
- declare const EditorContent: React__default.NamedExoticComponent<Omit<EditorContentProps, "ref"> & React__default.RefAttributes<HTMLDivElement>>;
86
-
87
- type NodeViewContentProps<T extends keyof React__default.JSX.IntrinsicElements = 'div'> = {
88
- as?: NoInfer<T>;
89
- } & ComponentProps<T>;
90
- declare function NodeViewContent<T extends keyof React__default.JSX.IntrinsicElements = 'div'>({ as: Tag, ...props }: NodeViewContentProps<T>): react_jsx_runtime.JSX.Element;
91
-
92
- interface NodeViewWrapperProps {
93
- [key: string]: any;
94
- as?: React__default.ElementType;
95
- }
96
- declare const NodeViewWrapper: React__default.FC<NodeViewWrapperProps>;
97
-
98
- interface ReactRendererOptions {
99
- /**
100
- * The editor instance.
101
- * @type {Editor}
102
- */
103
- editor: Editor;
104
- /**
105
- * The props for the component.
106
- * @type {Record<string, any>}
107
- * @default {}
108
- */
109
- props?: Record<string, any>;
110
- /**
111
- * The tag name of the element.
112
- * @type {string}
113
- * @default 'div'
114
- */
115
- as?: string;
116
- /**
117
- * The class name of the element.
118
- * @type {string}
119
- * @default ''
120
- * @example 'foo bar'
121
- */
122
- className?: string;
123
- }
124
- type ComponentType<R, P> = ComponentClass<P> | FunctionComponent<P> | ForwardRefExoticComponent<PropsWithoutRef<P> & RefAttributes<R>>;
125
- /**
126
- * The ReactRenderer class. It's responsible for rendering React components inside the editor.
127
- * @example
128
- * new ReactRenderer(MyComponent, {
129
- * editor,
130
- * props: {
131
- * foo: 'bar',
132
- * },
133
- * as: 'span',
134
- * })
135
- */
136
- declare class ReactRenderer<R = unknown, P extends Record<string, any> = object> {
137
- id: string;
138
- editor: Editor;
139
- component: any;
140
- element: HTMLElement;
141
- props: P;
142
- reactElement: ReactNode;
143
- ref: R | null;
144
- /**
145
- * Flag to track if the renderer has been destroyed, preventing queued or asynchronous renders from executing after teardown.
146
- */
147
- destroyed: boolean;
148
- /**
149
- * Immediately creates element and renders the provided React component.
150
- */
151
- constructor(component: ComponentType<R, P>, { editor, props, as, className }: ReactRendererOptions);
152
- /**
153
- * Render the React component.
154
- */
155
- render(): void;
156
- /**
157
- * Re-renders the React component with new props.
158
- */
159
- updateProps(props?: Record<string, any>): void;
160
- /**
161
- * Destroy the React component.
162
- */
163
- destroy(): void;
164
- /**
165
- * Update the attributes of the element that holds the React component.
166
- */
167
- updateAttributes(attributes: Record<string, string>): void;
168
- }
169
-
170
- interface MarkViewContextProps {
171
- markViewContentRef: (element: HTMLElement | null) => void;
172
- }
173
- declare const ReactMarkViewContext: React__default.Context<MarkViewContextProps>;
174
- type MarkViewContentProps<T extends keyof React__default.JSX.IntrinsicElements = 'span'> = {
175
- as?: T;
176
- } & Omit<React__default.ComponentProps<T>, 'as'>;
177
- declare const MarkViewContent: <T extends keyof React__default.JSX.IntrinsicElements = "span">(props: MarkViewContentProps<T>) => react_jsx_runtime.JSX.Element;
178
- interface ReactMarkViewRendererOptions extends MarkViewRendererOptions {
179
- /**
180
- * The tag name of the element wrapping the React component.
181
- */
182
- as?: string;
183
- className?: string;
184
- attrs?: {
185
- [key: string]: string;
186
- };
187
- }
188
- declare class ReactMarkView extends MarkView<React__default.ComponentType<MarkViewProps>, ReactMarkViewRendererOptions> {
189
- renderer: ReactRenderer;
190
- contentDOMElement: HTMLElement;
191
- constructor(component: React__default.ComponentType<MarkViewProps>, props: MarkViewProps, options?: Partial<ReactMarkViewRendererOptions>);
192
- get dom(): HTMLElement;
193
- get contentDOM(): HTMLElement;
194
- }
195
- declare function ReactMarkViewRenderer(component: React__default.ComponentType<MarkViewProps>, options?: Partial<ReactMarkViewRendererOptions>): MarkViewRenderer;
196
-
197
- type ReactNodeViewProps<T = HTMLElement> = NodeViewProps & {
198
- ref: React__default.RefObject<T | null>;
199
- };
200
-
201
- interface ReactNodeViewRendererOptions extends NodeViewRendererOptions {
202
- /**
203
- * This function is called when the node view is updated.
204
- * It allows you to compare the old node with the new node and decide if the component should update.
205
- */
206
- update: ((props: {
207
- oldNode: Node;
208
- oldDecorations: readonly Decoration[];
209
- oldInnerDecorations: DecorationSource;
210
- newNode: Node;
211
- newDecorations: readonly Decoration[];
212
- innerDecorations: DecorationSource;
213
- updateProps: () => void;
214
- }) => boolean) | null;
215
- /**
216
- * The tag name of the element wrapping the React component.
217
- */
218
- as?: string;
219
- /**
220
- * The class name of the element wrapping the React component.
221
- */
222
- className?: string;
223
- /**
224
- * Attributes that should be applied to the element wrapping the React component.
225
- * If this is a function, it will be called each time the node view is updated.
226
- * If this is an object, it will be applied once when the node view is mounted.
227
- */
228
- attrs?: Record<string, string> | ((props: {
229
- node: Node;
230
- HTMLAttributes: Record<string, any>;
231
- }) => Record<string, string>);
232
- }
233
- declare class ReactNodeView<T = HTMLElement, Component extends ComponentType$1<ReactNodeViewProps<T>> = ComponentType$1<ReactNodeViewProps<T>>, NodeEditor extends Editor = Editor, Options extends ReactNodeViewRendererOptions = ReactNodeViewRendererOptions> extends NodeView<Component, NodeEditor, Options> {
234
- /**
235
- * The renderer instance.
236
- */
237
- renderer: ReactRenderer<unknown, ReactNodeViewProps<T>>;
238
- /**
239
- * The element that holds the rich-text content of the node.
240
- */
241
- contentDOMElement: HTMLElement | null;
242
- /**
243
- * The requestAnimationFrame ID used for selection updates.
244
- */
245
- selectionRafId: number | null;
246
- constructor(component: Component, props: NodeViewRendererProps, options?: Partial<Options>);
247
- private cachedExtensionWithSyncedStorage;
248
- /**
249
- * Returns a proxy of the extension that redirects storage access to the editor's mutable storage.
250
- * This preserves the original prototype chain (instanceof checks, methods like configure/extend work).
251
- * Cached to avoid proxy creation on every update.
252
- */
253
- get extensionWithSyncedStorage(): NodeViewRendererProps['extension'];
254
- /**
255
- * Setup the React component.
256
- * Called on initialization.
257
- */
258
- mount(): void;
259
- /**
260
- * Return the DOM element.
261
- * This is the element that will be used to display the node view.
262
- */
263
- get dom(): HTMLElement;
264
- /**
265
- * Return the content DOM element.
266
- * This is the element that will be used to display the rich-text content of the node.
267
- */
268
- get contentDOM(): HTMLElement | null;
269
- /**
270
- * On editor selection update, check if the node is selected.
271
- * If it is, call `selectNode`, otherwise call `deselectNode`.
272
- */
273
- handleSelectionUpdate(): void;
274
- /**
275
- * On update, update the React component.
276
- * To prevent unnecessary updates, the `update` option can be used.
277
- */
278
- update(node: Node, decorations: readonly Decoration[], innerDecorations: DecorationSource): boolean;
279
- /**
280
- * Select the node.
281
- * Add the `selected` prop and the `ProseMirror-selectednode` class.
282
- */
283
- selectNode(): void;
284
- /**
285
- * Deselect the node.
286
- * Remove the `selected` prop and the `ProseMirror-selectednode` class.
287
- */
288
- deselectNode(): void;
289
- /**
290
- * Destroy the React component instance.
291
- */
292
- destroy(): void;
293
- /**
294
- * Update the attributes of the top-level element that holds the React component.
295
- * Applying the attributes defined in the `attrs` option.
296
- */
297
- updateElementAttributes(): void;
298
- }
299
- /**
300
- * Create a React node view renderer.
301
- */
302
- declare function ReactNodeViewRenderer<T = HTMLElement>(component: ComponentType$1<ReactNodeViewProps<T>>, options?: Partial<ReactNodeViewRendererOptions>): NodeViewRenderer;
303
-
304
- /**
305
- * The shape of the React context used by the `<Tiptap />` components.
306
- *
307
- * The editor instance is always available when using the default `useEditor`
308
- * configuration. For SSR scenarios where `immediatelyRender: false` is used,
309
- * consider using the legacy `EditorProvider` pattern instead.
310
- */
311
- type TiptapContextType = {
312
- /** The Tiptap editor instance. */
313
- editor: Editor;
314
- };
315
- /**
316
- * React context that stores the current editor instance.
317
- *
318
- * Use `useTiptap()` to read from this context in child components.
319
- */
320
- declare const TiptapContext: React.Context<TiptapContextType>;
321
- /**
322
- * Hook to read the Tiptap context and access the editor instance.
323
- *
324
- * This is a small convenience wrapper around `useContext(TiptapContext)`.
325
- * The editor is always available when used within a `<Tiptap>` provider.
326
- *
327
- * @returns The current `TiptapContextType` value from the provider.
328
- *
329
- * @example
330
- * ```tsx
331
- * import { useTiptap } from '@tiptap/react'
332
- *
333
- * function Toolbar() {
334
- * const { editor } = useTiptap()
335
- *
336
- * return (
337
- * <button onClick={() => editor.chain().focus().toggleBold().run()}>
338
- * Bold
339
- * </button>
340
- * )
341
- * }
342
- * ```
343
- */
344
- declare const useTiptap: () => TiptapContextType;
345
- /**
346
- * Select a slice of the editor state using the context-provided editor.
347
- *
348
- * This is a thin wrapper around `useEditorState` that reads the `editor`
349
- * instance from `useTiptap()` so callers don't have to pass it manually.
350
- *
351
- * @typeParam TSelectorResult - The type returned by the selector.
352
- * @param selector - Function that receives the editor state snapshot and
353
- * returns the piece of state you want to subscribe to.
354
- * @param equalityFn - Optional function to compare previous/next selected
355
- * values and avoid unnecessary updates.
356
- * @returns The selected slice of the editor state.
357
- *
358
- * @example
359
- * ```tsx
360
- * function WordCount() {
361
- * const wordCount = useTiptapState(state => {
362
- * const text = state.editor.state.doc.textContent
363
- * return text.split(/\s+/).filter(Boolean).length
364
- * })
365
- *
366
- * return <span>{wordCount} words</span>
367
- * }
368
- * ```
369
- */
370
- declare function useTiptapState<TSelectorResult>(selector: (context: EditorStateSnapshot<Editor>) => TSelectorResult, equalityFn?: (a: TSelectorResult, b: TSelectorResult | null) => boolean): TSelectorResult;
371
- /**
372
- * Props for the `Tiptap` root/provider component.
373
- */
374
- type TiptapWrapperProps = {
375
- /**
376
- * The editor instance to provide to child components.
377
- * Use `useEditor()` to create this instance.
378
- */
379
- editor?: Editor;
380
- /**
381
- * @deprecated Use `editor` instead. Will be removed in the next major version.
382
- */
383
- instance?: Editor;
384
- children: ReactNode;
385
- };
386
- /**
387
- * Top-level provider component that makes the editor instance available via
388
- * React context to all child components.
389
- *
390
- * This component also provides backwards compatibility with the legacy
391
- * `EditorContext`, so components using `useCurrentEditor()` will work
392
- * inside a `<Tiptap>` provider.
393
- *
394
- * @param props - Component props.
395
- * @returns A context provider element wrapping `children`.
396
- *
397
- * @example
398
- * ```tsx
399
- * import { Tiptap, useEditor } from '@tiptap/react'
400
- *
401
- * function App() {
402
- * const editor = useEditor({ extensions: [...] })
403
- *
404
- * return (
405
- * <Tiptap editor={editor}>
406
- * <Toolbar />
407
- * <Tiptap.Content />
408
- * </Tiptap>
409
- * )
410
- * }
411
- * ```
412
- */
413
- declare function TiptapWrapper({ editor, instance, children }: TiptapWrapperProps): react_jsx_runtime.JSX.Element;
414
- declare namespace TiptapWrapper {
415
- var displayName: string;
416
- }
417
- /**
418
- * Convenience component that renders `EditorContent` using the context-provided
419
- * editor instance. Use this instead of manually passing the `editor` prop.
420
- *
421
- * @param props - All `EditorContent` props except `editor` and `ref`.
422
- * @returns An `EditorContent` element bound to the context editor.
423
- *
424
- * @example
425
- * ```tsx
426
- * // inside a Tiptap provider
427
- * <Tiptap.Content className="editor" />
428
- * ```
429
- */
430
- declare function TiptapContent({ ...rest }: Omit<EditorContentProps, 'editor' | 'ref'>): react_jsx_runtime.JSX.Element;
431
- declare namespace TiptapContent {
432
- var displayName: string;
433
- }
434
- /**
435
- * Root `Tiptap` component. Use it as the provider for all child components.
436
- *
437
- * The exported object includes the `Content` subcomponent for rendering the
438
- * editor content area.
439
- *
440
- * This component provides both the new `TiptapContext` (accessed via `useTiptap()`)
441
- * and the legacy `EditorContext` (accessed via `useCurrentEditor()`) for
442
- * backwards compatibility.
443
- *
444
- * For bubble menus and floating menus, import them separately from
445
- * `@tiptap/react/menus` to keep floating-ui as an optional dependency.
446
- *
447
- * @example
448
- * ```tsx
449
- * import { Tiptap, useEditor } from '@tiptap/react'
450
- * import { BubbleMenu } from '@tiptap/react/menus'
451
- *
452
- * function App() {
453
- * const editor = useEditor({ extensions: [...] })
454
- *
455
- * return (
456
- * <Tiptap editor={editor}>
457
- * <Tiptap.Content />
458
- * <BubbleMenu>
459
- * <button onClick={() => editor.chain().focus().toggleBold().run()}>Bold</button>
460
- * </BubbleMenu>
461
- * </Tiptap>
462
- * )
463
- * }
464
- * ```
465
- */
466
- declare const Tiptap: typeof TiptapWrapper & {
467
- /**
468
- * The Tiptap Content component that renders the EditorContent with the editor instance from the context.
469
- * @see TiptapContent
470
- */
471
- Content: typeof TiptapContent;
472
- };
473
-
474
- type EditorStateSnapshot<TEditor extends Editor | null = Editor | null> = {
475
- editor: TEditor;
476
- transactionNumber: number;
477
- };
478
- type UseEditorStateOptions<TSelectorResult, TEditor extends Editor | null = Editor | null> = {
479
- /**
480
- * The editor instance.
481
- */
482
- editor: TEditor;
483
- /**
484
- * A selector function to determine the value to compare for re-rendering.
485
- */
486
- selector: (context: EditorStateSnapshot<TEditor>) => TSelectorResult;
487
- /**
488
- * A custom equality function to determine if the editor should re-render.
489
- * @default `deepEqual` from `fast-deep-equal`
490
- */
491
- equalityFn?: (a: TSelectorResult, b: TSelectorResult | null) => boolean;
492
- };
493
- /**
494
- * This hook allows you to watch for changes on the editor instance.
495
- * It will allow you to select a part of the editor state and re-render the component when it changes.
496
- * @example
497
- * ```tsx
498
- * const editor = useEditor({...options})
499
- * const { currentSelection } = useEditorState({
500
- * editor,
501
- * selector: snapshot => ({ currentSelection: snapshot.editor.state.selection }),
502
- * })
503
- */
504
- declare function useEditorState<TSelectorResult>(options: UseEditorStateOptions<TSelectorResult, Editor>): TSelectorResult;
505
- /**
506
- * This hook allows you to watch for changes on the editor instance.
507
- * It will allow you to select a part of the editor state and re-render the component when it changes.
508
- * @example
509
- * ```tsx
510
- * const editor = useEditor({...options})
511
- * const { currentSelection } = useEditorState({
512
- * editor,
513
- * selector: snapshot => ({ currentSelection: snapshot.editor.state.selection }),
514
- * })
515
- */
516
- declare function useEditorState<TSelectorResult>(options: UseEditorStateOptions<TSelectorResult, Editor | null>): TSelectorResult | null;
517
-
518
- interface ReactNodeViewContextProps {
519
- onDragStart?: (event: DragEvent) => void;
520
- nodeViewContentRef?: (element: HTMLElement | null) => void;
521
- /**
522
- * This allows you to add children into the NodeViewContent component.
523
- * This is useful when statically rendering the content of a node view.
524
- */
525
- nodeViewContentChildren?: ReactNode;
526
- }
527
- declare const ReactNodeViewContext: React.Context<ReactNodeViewContextProps>;
528
- declare const ReactNodeViewContentProvider: ({ children, content }: {
529
- children: ReactNode;
530
- content: ReactNode;
531
- }) => React.FunctionComponentElement<React.ProviderProps<ReactNodeViewContextProps>>;
532
- declare const useReactNodeView: () => ReactNodeViewContextProps;
533
-
534
- export { EditorConsumer, EditorContent, type EditorContentProps, EditorContext, type EditorContextValue, EditorProvider, type EditorProviderProps, type EditorStateSnapshot, MarkViewContent, type MarkViewContentProps, type MarkViewContextProps, NodeViewContent, type NodeViewContentProps, NodeViewWrapper, type NodeViewWrapperProps, PureEditorContent, ReactMarkView, ReactMarkViewContext, ReactMarkViewRenderer, type ReactMarkViewRendererOptions, ReactNodeView, ReactNodeViewContentProvider, ReactNodeViewContext, type ReactNodeViewContextProps, type ReactNodeViewProps, ReactNodeViewRenderer, type ReactNodeViewRendererOptions, ReactRenderer, type ReactRendererOptions, Tiptap, TiptapContent, TiptapContext, type TiptapContextType, TiptapWrapper, type TiptapWrapperProps, type UseEditorOptions, type UseEditorStateOptions, useCurrentEditor, useEditor, useEditorState, useReactNodeView, useTiptap, useTiptapState };