@tiptap/react 3.0.0-next.1 → 3.0.0-next.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.cjs +255 -130
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +155 -42
- package/dist/index.d.ts +155 -42
- package/dist/index.js +244 -113
- package/dist/index.js.map +1 -1
- package/package.json +9 -8
- package/src/BubbleMenu.tsx +70 -50
- package/src/Context.tsx +14 -6
- package/src/FloatingMenu.tsx +51 -45
- package/src/ReactNodeViewRenderer.tsx +152 -41
- package/src/ReactRenderer.tsx +26 -19
- package/src/useEditor.ts +17 -9
- package/src/useEditorState.ts +49 -10
package/dist/index.d.ts
CHANGED
|
@@ -1,22 +1,25 @@
|
|
|
1
1
|
import { BubbleMenuPluginProps } from '@tiptap/extension-bubble-menu';
|
|
2
2
|
import * as React from 'react';
|
|
3
|
-
import React__default, { DependencyList, ReactNode, HTMLProps, ForwardedRef } from 'react';
|
|
4
|
-
import { EditorOptions, Editor, NodeViewRendererOptions, NodeViewRenderer } from '@tiptap/core';
|
|
3
|
+
import React__default, { DependencyList, ReactNode, HTMLAttributes, HTMLProps, ForwardedRef, ComponentType as ComponentType$1 } from 'react';
|
|
4
|
+
import { EditorOptions, Editor, NodeViewRendererOptions, NodeViewProps, NodeView, NodeViewRenderer } from '@tiptap/core';
|
|
5
5
|
export * from '@tiptap/core';
|
|
6
6
|
import { FloatingMenuPluginProps } from '@tiptap/extension-floating-menu';
|
|
7
7
|
import { Node } from '@tiptap/pm/model';
|
|
8
|
-
import { Decoration } from '@tiptap/pm/view';
|
|
8
|
+
import { Decoration, DecorationSource } from '@tiptap/pm/view';
|
|
9
9
|
|
|
10
10
|
type Optional$1<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
|
|
11
11
|
type BubbleMenuProps = Omit<Optional$1<BubbleMenuPluginProps, 'pluginKey'>, 'element' | 'editor'> & {
|
|
12
12
|
editor: BubbleMenuPluginProps['editor'] | null;
|
|
13
|
-
className?: string;
|
|
14
|
-
children: React__default.ReactNode;
|
|
15
13
|
updateDelay?: number;
|
|
16
14
|
resizeDelay?: number;
|
|
17
15
|
options?: BubbleMenuPluginProps['options'];
|
|
18
|
-
}
|
|
19
|
-
declare const BubbleMenu:
|
|
16
|
+
} & React__default.HTMLAttributes<HTMLDivElement>;
|
|
17
|
+
declare const BubbleMenu: React__default.ForwardRefExoticComponent<Omit<Optional$1<BubbleMenuPluginProps, "pluginKey">, "editor" | "element"> & {
|
|
18
|
+
editor: BubbleMenuPluginProps["editor"] | null;
|
|
19
|
+
updateDelay?: number;
|
|
20
|
+
resizeDelay?: number;
|
|
21
|
+
options?: BubbleMenuPluginProps["options"];
|
|
22
|
+
} & React__default.HTMLAttributes<HTMLDivElement> & React__default.RefAttributes<HTMLDivElement>>;
|
|
20
23
|
|
|
21
24
|
/**
|
|
22
25
|
* The options for the `useEditor` hook.
|
|
@@ -32,7 +35,7 @@ type UseEditorOptions = Partial<EditorOptions> & {
|
|
|
32
35
|
/**
|
|
33
36
|
* Whether to re-render the editor on each transaction.
|
|
34
37
|
* This is legacy behavior that will be removed in future versions.
|
|
35
|
-
* @default
|
|
38
|
+
* @default false
|
|
36
39
|
*/
|
|
37
40
|
shouldRerenderOnTransaction?: boolean;
|
|
38
41
|
};
|
|
@@ -44,8 +47,8 @@ type UseEditorOptions = Partial<EditorOptions> & {
|
|
|
44
47
|
* @example const editor = useEditor({ extensions: [...] })
|
|
45
48
|
*/
|
|
46
49
|
declare function useEditor(options: UseEditorOptions & {
|
|
47
|
-
immediatelyRender:
|
|
48
|
-
}, deps?: DependencyList): Editor;
|
|
50
|
+
immediatelyRender: false;
|
|
51
|
+
}, deps?: DependencyList): Editor | null;
|
|
49
52
|
/**
|
|
50
53
|
* This hook allows you to create an editor instance.
|
|
51
54
|
* @param options The editor options
|
|
@@ -53,7 +56,7 @@ declare function useEditor(options: UseEditorOptions & {
|
|
|
53
56
|
* @returns The editor instance
|
|
54
57
|
* @example const editor = useEditor({ extensions: [...] })
|
|
55
58
|
*/
|
|
56
|
-
declare function useEditor(options
|
|
59
|
+
declare function useEditor(options: UseEditorOptions, deps?: DependencyList): Editor;
|
|
57
60
|
|
|
58
61
|
type EditorContextValue = {
|
|
59
62
|
editor: Editor | null;
|
|
@@ -68,13 +71,14 @@ type EditorProviderProps = {
|
|
|
68
71
|
children?: ReactNode;
|
|
69
72
|
slotBefore?: ReactNode;
|
|
70
73
|
slotAfter?: ReactNode;
|
|
74
|
+
editorContainerProps?: HTMLAttributes<HTMLDivElement>;
|
|
71
75
|
} & UseEditorOptions;
|
|
72
76
|
/**
|
|
73
77
|
* This is the provider component for the editor.
|
|
74
78
|
* It allows the editor to be accessible across the entire component tree
|
|
75
79
|
* with `useCurrentEditor`.
|
|
76
80
|
*/
|
|
77
|
-
declare function EditorProvider({ children, slotAfter, slotBefore, ...editorOptions }: EditorProviderProps): React__default.JSX.Element | null;
|
|
81
|
+
declare function EditorProvider({ children, slotAfter, slotBefore, editorContainerProps, ...editorOptions }: EditorProviderProps): React__default.JSX.Element | null;
|
|
78
82
|
|
|
79
83
|
interface EditorContentProps extends HTMLProps<HTMLDivElement> {
|
|
80
84
|
editor: Editor | null;
|
|
@@ -98,11 +102,12 @@ declare const EditorContent: React__default.MemoExoticComponent<React__default.F
|
|
|
98
102
|
type Optional<T, K extends keyof T> = Pick<Partial<T>, K> & Omit<T, K>;
|
|
99
103
|
type FloatingMenuProps = Omit<Optional<FloatingMenuPluginProps, 'pluginKey'>, 'element' | 'editor'> & {
|
|
100
104
|
editor: FloatingMenuPluginProps['editor'] | null;
|
|
101
|
-
className?: string;
|
|
102
|
-
children: React__default.ReactNode;
|
|
103
105
|
options?: FloatingMenuPluginProps['options'];
|
|
104
|
-
}
|
|
105
|
-
declare const FloatingMenu:
|
|
106
|
+
} & React__default.HTMLAttributes<HTMLDivElement>;
|
|
107
|
+
declare const FloatingMenu: React__default.ForwardRefExoticComponent<Omit<Optional<FloatingMenuPluginProps, "pluginKey">, "editor" | "element"> & {
|
|
108
|
+
editor: FloatingMenuPluginProps["editor"] | null;
|
|
109
|
+
options?: FloatingMenuPluginProps["options"];
|
|
110
|
+
} & React__default.HTMLAttributes<HTMLDivElement> & React__default.RefAttributes<HTMLDivElement>>;
|
|
106
111
|
|
|
107
112
|
interface NodeViewContentProps {
|
|
108
113
|
[key: string]: any;
|
|
@@ -116,20 +121,6 @@ interface NodeViewWrapperProps {
|
|
|
116
121
|
}
|
|
117
122
|
declare const NodeViewWrapper: React__default.FC<NodeViewWrapperProps>;
|
|
118
123
|
|
|
119
|
-
interface ReactNodeViewRendererOptions extends NodeViewRendererOptions {
|
|
120
|
-
update: ((props: {
|
|
121
|
-
oldNode: Node;
|
|
122
|
-
oldDecorations: Decoration[];
|
|
123
|
-
newNode: Node;
|
|
124
|
-
newDecorations: Decoration[];
|
|
125
|
-
updateProps: () => void;
|
|
126
|
-
}) => boolean) | null;
|
|
127
|
-
as?: string;
|
|
128
|
-
className?: string;
|
|
129
|
-
attrs?: Record<string, string>;
|
|
130
|
-
}
|
|
131
|
-
declare function ReactNodeViewRenderer(component: any, options?: Partial<ReactNodeViewRendererOptions>): NodeViewRenderer;
|
|
132
|
-
|
|
133
124
|
interface ReactRendererOptions {
|
|
134
125
|
/**
|
|
135
126
|
* The editor instance.
|
|
@@ -155,13 +146,6 @@ interface ReactRendererOptions {
|
|
|
155
146
|
* @example 'foo bar'
|
|
156
147
|
*/
|
|
157
148
|
className?: string;
|
|
158
|
-
/**
|
|
159
|
-
* The attributes of the element.
|
|
160
|
-
* @type {Record<string, string>}
|
|
161
|
-
* @default {}
|
|
162
|
-
* @example { 'data-foo': 'bar' }
|
|
163
|
-
*/
|
|
164
|
-
attrs?: Record<string, string>;
|
|
165
149
|
}
|
|
166
150
|
type ComponentType<R, P> = React__default.ComponentClass<P> | React__default.FunctionComponent<P> | React__default.ForwardRefExoticComponent<React__default.PropsWithoutRef<P> & React__default.RefAttributes<R>>;
|
|
167
151
|
/**
|
|
@@ -175,19 +159,126 @@ type ComponentType<R, P> = React__default.ComponentClass<P> | React__default.Fun
|
|
|
175
159
|
* as: 'span',
|
|
176
160
|
* })
|
|
177
161
|
*/
|
|
178
|
-
declare class ReactRenderer<R = unknown, P =
|
|
162
|
+
declare class ReactRenderer<R = unknown, P extends Record<string, any> = {}> {
|
|
179
163
|
id: string;
|
|
180
164
|
editor: Editor;
|
|
181
165
|
component: any;
|
|
182
166
|
element: Element;
|
|
183
|
-
props:
|
|
167
|
+
props: P;
|
|
184
168
|
reactElement: React__default.ReactNode;
|
|
185
169
|
ref: R | null;
|
|
186
|
-
|
|
170
|
+
/**
|
|
171
|
+
* Immediately creates element and renders the provided React component.
|
|
172
|
+
*/
|
|
173
|
+
constructor(component: ComponentType<R, P>, { editor, props, as, className, }: ReactRendererOptions);
|
|
174
|
+
/**
|
|
175
|
+
* Render the React component.
|
|
176
|
+
*/
|
|
187
177
|
render(): void;
|
|
178
|
+
/**
|
|
179
|
+
* Re-renders the React component with new props.
|
|
180
|
+
*/
|
|
188
181
|
updateProps(props?: Record<string, any>): void;
|
|
182
|
+
/**
|
|
183
|
+
* Destroy the React component.
|
|
184
|
+
*/
|
|
185
|
+
destroy(): void;
|
|
186
|
+
/**
|
|
187
|
+
* Update the attributes of the element that holds the React component.
|
|
188
|
+
*/
|
|
189
|
+
updateAttributes(attributes: Record<string, string>): void;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
interface ReactNodeViewRendererOptions extends NodeViewRendererOptions {
|
|
193
|
+
/**
|
|
194
|
+
* This function is called when the node view is updated.
|
|
195
|
+
* It allows you to compare the old node with the new node and decide if the component should update.
|
|
196
|
+
*/
|
|
197
|
+
update: ((props: {
|
|
198
|
+
oldNode: Node;
|
|
199
|
+
oldDecorations: readonly Decoration[];
|
|
200
|
+
oldInnerDecorations: DecorationSource;
|
|
201
|
+
newNode: Node;
|
|
202
|
+
newDecorations: readonly Decoration[];
|
|
203
|
+
innerDecorations: DecorationSource;
|
|
204
|
+
updateProps: () => void;
|
|
205
|
+
}) => boolean) | null;
|
|
206
|
+
/**
|
|
207
|
+
* The tag name of the element wrapping the React component.
|
|
208
|
+
*/
|
|
209
|
+
as?: string;
|
|
210
|
+
/**
|
|
211
|
+
* The class name of the element wrapping the React component.
|
|
212
|
+
*/
|
|
213
|
+
className?: string;
|
|
214
|
+
/**
|
|
215
|
+
* Attributes that should be applied to the element wrapping the React component.
|
|
216
|
+
* If this is a function, it will be called each time the node view is updated.
|
|
217
|
+
* If this is an object, it will be applied once when the node view is mounted.
|
|
218
|
+
*/
|
|
219
|
+
attrs?: Record<string, string> | ((props: {
|
|
220
|
+
node: Node;
|
|
221
|
+
HTMLAttributes: Record<string, any>;
|
|
222
|
+
}) => Record<string, string>);
|
|
223
|
+
}
|
|
224
|
+
declare class ReactNodeView<Component extends ComponentType$1<NodeViewProps> = ComponentType$1<NodeViewProps>, NodeEditor extends Editor = Editor, Options extends ReactNodeViewRendererOptions = ReactNodeViewRendererOptions> extends NodeView<Component, NodeEditor, Options> {
|
|
225
|
+
/**
|
|
226
|
+
* The renderer instance.
|
|
227
|
+
*/
|
|
228
|
+
renderer: ReactRenderer<unknown, NodeViewProps>;
|
|
229
|
+
/**
|
|
230
|
+
* The element that holds the rich-text content of the node.
|
|
231
|
+
*/
|
|
232
|
+
contentDOMElement: HTMLElement | null;
|
|
233
|
+
/**
|
|
234
|
+
* Setup the React component.
|
|
235
|
+
* Called on initialization.
|
|
236
|
+
*/
|
|
237
|
+
mount(): void;
|
|
238
|
+
/**
|
|
239
|
+
* Return the DOM element.
|
|
240
|
+
* This is the element that will be used to display the node view.
|
|
241
|
+
*/
|
|
242
|
+
get dom(): HTMLElement;
|
|
243
|
+
/**
|
|
244
|
+
* Return the content DOM element.
|
|
245
|
+
* This is the element that will be used to display the rich-text content of the node.
|
|
246
|
+
*/
|
|
247
|
+
get contentDOM(): HTMLElement | null;
|
|
248
|
+
/**
|
|
249
|
+
* On editor selection update, check if the node is selected.
|
|
250
|
+
* If it is, call `selectNode`, otherwise call `deselectNode`.
|
|
251
|
+
*/
|
|
252
|
+
handleSelectionUpdate(): void;
|
|
253
|
+
/**
|
|
254
|
+
* On update, update the React component.
|
|
255
|
+
* To prevent unnecessary updates, the `update` option can be used.
|
|
256
|
+
*/
|
|
257
|
+
update(node: Node, decorations: readonly Decoration[], innerDecorations: DecorationSource): boolean;
|
|
258
|
+
/**
|
|
259
|
+
* Select the node.
|
|
260
|
+
* Add the `selected` prop and the `ProseMirror-selectednode` class.
|
|
261
|
+
*/
|
|
262
|
+
selectNode(): void;
|
|
263
|
+
/**
|
|
264
|
+
* Deselect the node.
|
|
265
|
+
* Remove the `selected` prop and the `ProseMirror-selectednode` class.
|
|
266
|
+
*/
|
|
267
|
+
deselectNode(): void;
|
|
268
|
+
/**
|
|
269
|
+
* Destroy the React component instance.
|
|
270
|
+
*/
|
|
189
271
|
destroy(): void;
|
|
272
|
+
/**
|
|
273
|
+
* Update the attributes of the top-level element that holds the React component.
|
|
274
|
+
* Applying the attributes defined in the `attrs` option.
|
|
275
|
+
*/
|
|
276
|
+
updateElementAttributes(): void;
|
|
190
277
|
}
|
|
278
|
+
/**
|
|
279
|
+
* Create a React node view renderer.
|
|
280
|
+
*/
|
|
281
|
+
declare function ReactNodeViewRenderer(component: ComponentType$1<NodeViewProps>, options?: Partial<ReactNodeViewRendererOptions>): NodeViewRenderer;
|
|
191
282
|
|
|
192
283
|
type EditorStateSnapshot<TEditor extends Editor | null = Editor | null> = {
|
|
193
284
|
editor: TEditor;
|
|
@@ -204,11 +295,33 @@ type UseEditorStateOptions<TSelectorResult, TEditor extends Editor | null = Edit
|
|
|
204
295
|
selector: (context: EditorStateSnapshot<TEditor>) => TSelectorResult;
|
|
205
296
|
/**
|
|
206
297
|
* A custom equality function to determine if the editor should re-render.
|
|
207
|
-
* @default `
|
|
298
|
+
* @default `deepEqual` from `fast-deep-equal`
|
|
208
299
|
*/
|
|
209
300
|
equalityFn?: (a: TSelectorResult, b: TSelectorResult | null) => boolean;
|
|
210
301
|
};
|
|
302
|
+
/**
|
|
303
|
+
* This hook allows you to watch for changes on the editor instance.
|
|
304
|
+
* It will allow you to select a part of the editor state and re-render the component when it changes.
|
|
305
|
+
* @example
|
|
306
|
+
* ```tsx
|
|
307
|
+
* const editor = useEditor({...options})
|
|
308
|
+
* const { currentSelection } = useEditorState({
|
|
309
|
+
* editor,
|
|
310
|
+
* selector: snapshot => ({ currentSelection: snapshot.editor.state.selection }),
|
|
311
|
+
* })
|
|
312
|
+
*/
|
|
211
313
|
declare function useEditorState<TSelectorResult>(options: UseEditorStateOptions<TSelectorResult, Editor>): TSelectorResult;
|
|
314
|
+
/**
|
|
315
|
+
* This hook allows you to watch for changes on the editor instance.
|
|
316
|
+
* It will allow you to select a part of the editor state and re-render the component when it changes.
|
|
317
|
+
* @example
|
|
318
|
+
* ```tsx
|
|
319
|
+
* const editor = useEditor({...options})
|
|
320
|
+
* const { currentSelection } = useEditorState({
|
|
321
|
+
* editor,
|
|
322
|
+
* selector: snapshot => ({ currentSelection: snapshot.editor.state.selection }),
|
|
323
|
+
* })
|
|
324
|
+
*/
|
|
212
325
|
declare function useEditorState<TSelectorResult>(options: UseEditorStateOptions<TSelectorResult, Editor | null>): TSelectorResult | null;
|
|
213
326
|
|
|
214
327
|
interface ReactNodeViewContextProps {
|
|
@@ -218,4 +331,4 @@ interface ReactNodeViewContextProps {
|
|
|
218
331
|
declare const ReactNodeViewContext: React.Context<Partial<ReactNodeViewContextProps>>;
|
|
219
332
|
declare const useReactNodeView: () => Partial<ReactNodeViewContextProps>;
|
|
220
333
|
|
|
221
|
-
export { BubbleMenu, type BubbleMenuProps, EditorConsumer, EditorContent, type EditorContentProps, EditorContext, type EditorContextValue, EditorProvider, type EditorProviderProps, type EditorStateSnapshot, FloatingMenu, type FloatingMenuProps, NodeViewContent, type NodeViewContentProps, NodeViewWrapper, type NodeViewWrapperProps, PureEditorContent, ReactNodeViewContext, type ReactNodeViewContextProps, ReactNodeViewRenderer, type ReactNodeViewRendererOptions, ReactRenderer, type ReactRendererOptions, type UseEditorOptions, type UseEditorStateOptions, useCurrentEditor, useEditor, useEditorState, useReactNodeView };
|
|
334
|
+
export { BubbleMenu, type BubbleMenuProps, EditorConsumer, EditorContent, type EditorContentProps, EditorContext, type EditorContextValue, EditorProvider, type EditorProviderProps, type EditorStateSnapshot, FloatingMenu, type FloatingMenuProps, NodeViewContent, type NodeViewContentProps, NodeViewWrapper, type NodeViewWrapperProps, PureEditorContent, ReactNodeView, ReactNodeViewContext, type ReactNodeViewContextProps, ReactNodeViewRenderer, type ReactNodeViewRendererOptions, ReactRenderer, type ReactRendererOptions, type UseEditorOptions, type UseEditorStateOptions, useCurrentEditor, useEditor, useEditorState, useReactNodeView };
|