@tiptap/react 3.0.0 → 3.0.2-beta.0
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 +1030 -1163
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +350 -0
- package/dist/index.d.ts +350 -0
- package/dist/index.js +970 -1138
- package/dist/index.js.map +1 -1
- package/dist/menus/index.cjs +142 -0
- package/dist/menus/index.cjs.map +1 -0
- package/dist/menus/index.d.cts +19 -0
- package/dist/menus/index.d.ts +19 -0
- package/dist/menus/index.js +104 -0
- package/dist/menus/index.js.map +1 -0
- package/package.json +34 -21
- package/src/Context.tsx +18 -12
- package/src/Editor.ts +10 -11
- package/src/EditorContent.tsx +104 -64
- package/src/NodeViewContent.tsx +13 -8
- package/src/NodeViewWrapper.tsx +3 -2
- package/src/ReactMarkViewRenderer.tsx +111 -0
- package/src/ReactNodeViewRenderer.tsx +184 -67
- package/src/ReactRenderer.tsx +152 -51
- package/src/index.ts +2 -3
- package/src/menus/BubbleMenu.tsx +68 -0
- package/src/menus/FloatingMenu.tsx +68 -0
- package/src/menus/index.ts +2 -0
- package/src/types.ts +6 -0
- package/src/useEditor.ts +286 -166
- package/src/useEditorState.ts +133 -85
- package/src/useReactNodeView.ts +21 -5
- package/dist/index.umd.js +0 -1219
- package/dist/index.umd.js.map +0 -1
- package/dist/packages/core/src/CommandManager.d.ts +0 -20
- package/dist/packages/core/src/Editor.d.ts +0 -161
- package/dist/packages/core/src/EventEmitter.d.ts +0 -11
- package/dist/packages/core/src/Extension.d.ts +0 -343
- package/dist/packages/core/src/ExtensionManager.d.ts +0 -55
- package/dist/packages/core/src/InputRule.d.ts +0 -42
- package/dist/packages/core/src/Mark.d.ts +0 -451
- package/dist/packages/core/src/Node.d.ts +0 -611
- package/dist/packages/core/src/NodePos.d.ts +0 -44
- package/dist/packages/core/src/NodeView.d.ts +0 -31
- package/dist/packages/core/src/PasteRule.d.ts +0 -50
- package/dist/packages/core/src/Tracker.d.ts +0 -11
- package/dist/packages/core/src/commands/blur.d.ts +0 -13
- package/dist/packages/core/src/commands/clearContent.d.ts +0 -14
- package/dist/packages/core/src/commands/clearNodes.d.ts +0 -13
- package/dist/packages/core/src/commands/command.d.ts +0 -18
- package/dist/packages/core/src/commands/createParagraphNear.d.ts +0 -13
- package/dist/packages/core/src/commands/cut.d.ts +0 -20
- package/dist/packages/core/src/commands/deleteCurrentNode.d.ts +0 -13
- package/dist/packages/core/src/commands/deleteNode.d.ts +0 -15
- package/dist/packages/core/src/commands/deleteRange.d.ts +0 -14
- package/dist/packages/core/src/commands/deleteSelection.d.ts +0 -13
- package/dist/packages/core/src/commands/enter.d.ts +0 -13
- package/dist/packages/core/src/commands/exitCode.d.ts +0 -13
- package/dist/packages/core/src/commands/extendMarkRange.d.ts +0 -25
- package/dist/packages/core/src/commands/first.d.ts +0 -14
- package/dist/packages/core/src/commands/focus.d.ts +0 -27
- package/dist/packages/core/src/commands/forEach.d.ts +0 -14
- package/dist/packages/core/src/commands/index.d.ts +0 -55
- package/dist/packages/core/src/commands/insertContent.d.ts +0 -34
- package/dist/packages/core/src/commands/insertContentAt.d.ts +0 -47
- package/dist/packages/core/src/commands/join.d.ts +0 -41
- package/dist/packages/core/src/commands/joinItemBackward.d.ts +0 -13
- package/dist/packages/core/src/commands/joinItemForward.d.ts +0 -13
- package/dist/packages/core/src/commands/joinTextblockBackward.d.ts +0 -12
- package/dist/packages/core/src/commands/joinTextblockForward.d.ts +0 -12
- package/dist/packages/core/src/commands/keyboardShortcut.d.ts +0 -14
- package/dist/packages/core/src/commands/lift.d.ts +0 -17
- package/dist/packages/core/src/commands/liftEmptyBlock.d.ts +0 -13
- package/dist/packages/core/src/commands/liftListItem.d.ts +0 -15
- package/dist/packages/core/src/commands/newlineInCode.d.ts +0 -13
- package/dist/packages/core/src/commands/resetAttributes.d.ts +0 -16
- package/dist/packages/core/src/commands/scrollIntoView.d.ts +0 -13
- package/dist/packages/core/src/commands/selectAll.d.ts +0 -13
- package/dist/packages/core/src/commands/selectNodeBackward.d.ts +0 -13
- package/dist/packages/core/src/commands/selectNodeForward.d.ts +0 -13
- package/dist/packages/core/src/commands/selectParentNode.d.ts +0 -13
- package/dist/packages/core/src/commands/selectTextblockEnd.d.ts +0 -13
- package/dist/packages/core/src/commands/selectTextblockStart.d.ts +0 -13
- package/dist/packages/core/src/commands/setContent.d.ts +0 -40
- package/dist/packages/core/src/commands/setMark.d.ts +0 -15
- package/dist/packages/core/src/commands/setMeta.d.ts +0 -15
- package/dist/packages/core/src/commands/setNode.d.ts +0 -16
- package/dist/packages/core/src/commands/setNodeSelection.d.ts +0 -14
- package/dist/packages/core/src/commands/setTextSelection.d.ts +0 -14
- package/dist/packages/core/src/commands/sinkListItem.d.ts +0 -15
- package/dist/packages/core/src/commands/splitBlock.d.ts +0 -17
- package/dist/packages/core/src/commands/splitListItem.d.ts +0 -15
- package/dist/packages/core/src/commands/toggleList.d.ts +0 -18
- package/dist/packages/core/src/commands/toggleMark.d.ts +0 -30
- package/dist/packages/core/src/commands/toggleNode.d.ts +0 -17
- package/dist/packages/core/src/commands/toggleWrap.d.ts +0 -16
- package/dist/packages/core/src/commands/undoInputRule.d.ts +0 -13
- package/dist/packages/core/src/commands/unsetAllMarks.d.ts +0 -13
- package/dist/packages/core/src/commands/unsetMark.d.ts +0 -25
- package/dist/packages/core/src/commands/updateAttributes.d.ts +0 -24
- package/dist/packages/core/src/commands/wrapIn.d.ts +0 -16
- package/dist/packages/core/src/commands/wrapInList.d.ts +0 -16
- package/dist/packages/core/src/extensions/clipboardTextSerializer.d.ts +0 -5
- package/dist/packages/core/src/extensions/commands.d.ts +0 -3
- package/dist/packages/core/src/extensions/editable.d.ts +0 -2
- package/dist/packages/core/src/extensions/focusEvents.d.ts +0 -2
- package/dist/packages/core/src/extensions/index.d.ts +0 -6
- package/dist/packages/core/src/extensions/keymap.d.ts +0 -2
- package/dist/packages/core/src/extensions/tabindex.d.ts +0 -2
- package/dist/packages/core/src/helpers/combineTransactionSteps.d.ts +0 -10
- package/dist/packages/core/src/helpers/createChainableState.d.ts +0 -10
- package/dist/packages/core/src/helpers/createDocument.d.ts +0 -12
- package/dist/packages/core/src/helpers/createNodeFromContent.d.ts +0 -15
- package/dist/packages/core/src/helpers/defaultBlockAt.d.ts +0 -7
- package/dist/packages/core/src/helpers/findChildren.d.ts +0 -9
- package/dist/packages/core/src/helpers/findChildrenInRange.d.ts +0 -10
- package/dist/packages/core/src/helpers/findParentNode.d.ts +0 -16
- package/dist/packages/core/src/helpers/findParentNodeClosestToPos.d.ts +0 -17
- package/dist/packages/core/src/helpers/generateHTML.d.ts +0 -8
- package/dist/packages/core/src/helpers/generateJSON.d.ts +0 -8
- package/dist/packages/core/src/helpers/generateText.d.ts +0 -12
- package/dist/packages/core/src/helpers/getAttributes.d.ts +0 -9
- package/dist/packages/core/src/helpers/getAttributesFromExtensions.d.ts +0 -6
- package/dist/packages/core/src/helpers/getChangedRanges.d.ts +0 -11
- package/dist/packages/core/src/helpers/getDebugJSON.d.ts +0 -8
- package/dist/packages/core/src/helpers/getExtensionField.d.ts +0 -9
- package/dist/packages/core/src/helpers/getHTMLFromFragment.d.ts +0 -2
- package/dist/packages/core/src/helpers/getMarkAttributes.d.ts +0 -3
- package/dist/packages/core/src/helpers/getMarkRange.d.ts +0 -3
- package/dist/packages/core/src/helpers/getMarkType.d.ts +0 -2
- package/dist/packages/core/src/helpers/getMarksBetween.d.ts +0 -3
- package/dist/packages/core/src/helpers/getNodeAtPosition.d.ts +0 -11
- package/dist/packages/core/src/helpers/getNodeAttributes.d.ts +0 -3
- package/dist/packages/core/src/helpers/getNodeType.d.ts +0 -2
- package/dist/packages/core/src/helpers/getRenderedAttributes.d.ts +0 -3
- package/dist/packages/core/src/helpers/getSchema.d.ts +0 -4
- package/dist/packages/core/src/helpers/getSchemaByResolvedExtensions.d.ts +0 -10
- package/dist/packages/core/src/helpers/getSchemaTypeByName.d.ts +0 -8
- package/dist/packages/core/src/helpers/getSchemaTypeNameByName.d.ts +0 -8
- package/dist/packages/core/src/helpers/getSplittedAttributes.d.ts +0 -9
- package/dist/packages/core/src/helpers/getText.d.ts +0 -15
- package/dist/packages/core/src/helpers/getTextBetween.d.ts +0 -14
- package/dist/packages/core/src/helpers/getTextContentFromNodes.d.ts +0 -8
- package/dist/packages/core/src/helpers/getTextSerializersFromSchema.d.ts +0 -8
- package/dist/packages/core/src/helpers/index.d.ts +0 -50
- package/dist/packages/core/src/helpers/injectExtensionAttributesToParseRule.d.ts +0 -9
- package/dist/packages/core/src/helpers/isActive.d.ts +0 -2
- package/dist/packages/core/src/helpers/isAtEndOfNode.d.ts +0 -2
- package/dist/packages/core/src/helpers/isAtStartOfNode.d.ts +0 -2
- package/dist/packages/core/src/helpers/isExtensionRulesEnabled.d.ts +0 -2
- package/dist/packages/core/src/helpers/isList.d.ts +0 -2
- package/dist/packages/core/src/helpers/isMarkActive.d.ts +0 -3
- package/dist/packages/core/src/helpers/isNodeActive.d.ts +0 -3
- package/dist/packages/core/src/helpers/isNodeEmpty.d.ts +0 -2
- package/dist/packages/core/src/helpers/isNodeSelection.d.ts +0 -2
- package/dist/packages/core/src/helpers/isTextSelection.d.ts +0 -2
- package/dist/packages/core/src/helpers/posToDOMRect.d.ts +0 -2
- package/dist/packages/core/src/helpers/resolveFocusPosition.d.ts +0 -4
- package/dist/packages/core/src/helpers/selectionToInsertionEnd.d.ts +0 -2
- package/dist/packages/core/src/helpers/splitExtensions.d.ts +0 -9
- package/dist/packages/core/src/index.d.ts +0 -24
- package/dist/packages/core/src/inputRules/index.d.ts +0 -5
- package/dist/packages/core/src/inputRules/markInputRule.d.ts +0 -13
- package/dist/packages/core/src/inputRules/nodeInputRule.d.ts +0 -23
- package/dist/packages/core/src/inputRules/textInputRule.d.ts +0 -10
- package/dist/packages/core/src/inputRules/textblockTypeInputRule.d.ts +0 -15
- package/dist/packages/core/src/inputRules/wrappingInputRule.d.ts +0 -28
- package/dist/packages/core/src/pasteRules/index.d.ts +0 -3
- package/dist/packages/core/src/pasteRules/markPasteRule.d.ts +0 -13
- package/dist/packages/core/src/pasteRules/nodePasteRule.d.ts +0 -13
- package/dist/packages/core/src/pasteRules/textPasteRule.d.ts +0 -10
- package/dist/packages/core/src/style.d.ts +0 -1
- package/dist/packages/core/src/types.d.ts +0 -255
- package/dist/packages/core/src/utilities/callOrReturn.d.ts +0 -9
- package/dist/packages/core/src/utilities/createStyleTag.d.ts +0 -1
- package/dist/packages/core/src/utilities/deleteProps.d.ts +0 -6
- package/dist/packages/core/src/utilities/elementFromString.d.ts +0 -1
- package/dist/packages/core/src/utilities/escapeForRegEx.d.ts +0 -1
- package/dist/packages/core/src/utilities/findDuplicates.d.ts +0 -1
- package/dist/packages/core/src/utilities/fromString.d.ts +0 -1
- package/dist/packages/core/src/utilities/index.d.ts +0 -20
- package/dist/packages/core/src/utilities/isAndroid.d.ts +0 -1
- package/dist/packages/core/src/utilities/isEmptyObject.d.ts +0 -1
- package/dist/packages/core/src/utilities/isFunction.d.ts +0 -1
- package/dist/packages/core/src/utilities/isMacOS.d.ts +0 -1
- package/dist/packages/core/src/utilities/isNumber.d.ts +0 -1
- package/dist/packages/core/src/utilities/isPlainObject.d.ts +0 -1
- package/dist/packages/core/src/utilities/isRegExp.d.ts +0 -1
- package/dist/packages/core/src/utilities/isString.d.ts +0 -1
- package/dist/packages/core/src/utilities/isiOS.d.ts +0 -1
- package/dist/packages/core/src/utilities/mergeAttributes.d.ts +0 -1
- package/dist/packages/core/src/utilities/mergeDeep.d.ts +0 -1
- package/dist/packages/core/src/utilities/minMax.d.ts +0 -1
- package/dist/packages/core/src/utilities/objectIncludes.d.ts +0 -8
- package/dist/packages/core/src/utilities/removeDuplicates.d.ts +0 -8
- package/dist/packages/extension-bubble-menu/src/bubble-menu-plugin.d.ts +0 -76
- package/dist/packages/extension-bubble-menu/src/bubble-menu.d.ts +0 -15
- package/dist/packages/extension-bubble-menu/src/index.d.ts +0 -4
- package/dist/packages/extension-floating-menu/src/floating-menu-plugin.d.ts +0 -66
- package/dist/packages/extension-floating-menu/src/floating-menu.d.ts +0 -15
- package/dist/packages/extension-floating-menu/src/index.d.ts +0 -4
- package/dist/packages/react/src/BubbleMenu.d.ts +0 -11
- package/dist/packages/react/src/Context.d.ts +0 -23
- package/dist/packages/react/src/Editor.d.ts +0 -12
- package/dist/packages/react/src/EditorContent.d.ts +0 -24
- package/dist/packages/react/src/FloatingMenu.d.ts +0 -10
- package/dist/packages/react/src/NodeViewContent.d.ts +0 -6
- package/dist/packages/react/src/NodeViewWrapper.d.ts +0 -6
- package/dist/packages/react/src/ReactNodeViewRenderer.d.ts +0 -16
- package/dist/packages/react/src/ReactRenderer.d.ts +0 -62
- package/dist/packages/react/src/index.d.ts +0 -13
- package/dist/packages/react/src/useEditor.d.ts +0 -39
- package/dist/packages/react/src/useEditorState.d.ts +0 -22
- package/dist/packages/react/src/useReactNodeView.d.ts +0 -6
- package/src/BubbleMenu.tsx +0 -57
- package/src/FloatingMenu.tsx +0 -64
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
import * as react_jsx_runtime_js from 'react/jsx-runtime.js';
|
|
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_js.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_js.JSX.Element;
|
|
84
|
+
}
|
|
85
|
+
declare const EditorContent: React__default.MemoExoticComponent<React__default.ForwardRefExoticComponent<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_js.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: Element;
|
|
141
|
+
props: P;
|
|
142
|
+
reactElement: ReactNode;
|
|
143
|
+
ref: R | null;
|
|
144
|
+
/**
|
|
145
|
+
* Immediately creates element and renders the provided React component.
|
|
146
|
+
*/
|
|
147
|
+
constructor(component: ComponentType<R, P>, { editor, props, as, className }: ReactRendererOptions);
|
|
148
|
+
/**
|
|
149
|
+
* Render the React component.
|
|
150
|
+
*/
|
|
151
|
+
render(): void;
|
|
152
|
+
/**
|
|
153
|
+
* Re-renders the React component with new props.
|
|
154
|
+
*/
|
|
155
|
+
updateProps(props?: Record<string, any>): void;
|
|
156
|
+
/**
|
|
157
|
+
* Destroy the React component.
|
|
158
|
+
*/
|
|
159
|
+
destroy(): void;
|
|
160
|
+
/**
|
|
161
|
+
* Update the attributes of the element that holds the React component.
|
|
162
|
+
*/
|
|
163
|
+
updateAttributes(attributes: Record<string, string>): void;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
interface MarkViewContextProps {
|
|
167
|
+
markViewContentRef: (element: HTMLElement | null) => void;
|
|
168
|
+
}
|
|
169
|
+
declare const ReactMarkViewContext: React__default.Context<MarkViewContextProps>;
|
|
170
|
+
type MarkViewContentProps<T extends keyof React__default.JSX.IntrinsicElements = 'span'> = {
|
|
171
|
+
as?: T;
|
|
172
|
+
} & Omit<React__default.ComponentProps<T>, 'as'>;
|
|
173
|
+
declare const MarkViewContent: <T extends keyof React__default.JSX.IntrinsicElements = "span">(props: MarkViewContentProps<T>) => react_jsx_runtime_js.JSX.Element;
|
|
174
|
+
interface ReactMarkViewRendererOptions extends MarkViewRendererOptions {
|
|
175
|
+
/**
|
|
176
|
+
* The tag name of the element wrapping the React component.
|
|
177
|
+
*/
|
|
178
|
+
as?: string;
|
|
179
|
+
className?: string;
|
|
180
|
+
attrs?: {
|
|
181
|
+
[key: string]: string;
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
declare class ReactMarkView extends MarkView<React__default.ComponentType<MarkViewProps>, ReactMarkViewRendererOptions> {
|
|
185
|
+
renderer: ReactRenderer;
|
|
186
|
+
contentDOMElement: HTMLElement | null;
|
|
187
|
+
didMountContentDomElement: boolean;
|
|
188
|
+
constructor(component: React__default.ComponentType<MarkViewProps>, props: MarkViewProps, options?: Partial<ReactMarkViewRendererOptions>);
|
|
189
|
+
get dom(): HTMLElement;
|
|
190
|
+
get contentDOM(): HTMLElement | null;
|
|
191
|
+
}
|
|
192
|
+
declare function ReactMarkViewRenderer(component: React__default.ComponentType<MarkViewProps>, options?: Partial<ReactMarkViewRendererOptions>): MarkViewRenderer;
|
|
193
|
+
|
|
194
|
+
type ReactNodeViewProps<T = HTMLElement> = NodeViewProps & {
|
|
195
|
+
ref: React__default.RefObject<T | null>;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
interface ReactNodeViewRendererOptions extends NodeViewRendererOptions {
|
|
199
|
+
/**
|
|
200
|
+
* This function is called when the node view is updated.
|
|
201
|
+
* It allows you to compare the old node with the new node and decide if the component should update.
|
|
202
|
+
*/
|
|
203
|
+
update: ((props: {
|
|
204
|
+
oldNode: Node;
|
|
205
|
+
oldDecorations: readonly Decoration[];
|
|
206
|
+
oldInnerDecorations: DecorationSource;
|
|
207
|
+
newNode: Node;
|
|
208
|
+
newDecorations: readonly Decoration[];
|
|
209
|
+
innerDecorations: DecorationSource;
|
|
210
|
+
updateProps: () => void;
|
|
211
|
+
}) => boolean) | null;
|
|
212
|
+
/**
|
|
213
|
+
* The tag name of the element wrapping the React component.
|
|
214
|
+
*/
|
|
215
|
+
as?: string;
|
|
216
|
+
/**
|
|
217
|
+
* The class name of the element wrapping the React component.
|
|
218
|
+
*/
|
|
219
|
+
className?: string;
|
|
220
|
+
/**
|
|
221
|
+
* Attributes that should be applied to the element wrapping the React component.
|
|
222
|
+
* If this is a function, it will be called each time the node view is updated.
|
|
223
|
+
* If this is an object, it will be applied once when the node view is mounted.
|
|
224
|
+
*/
|
|
225
|
+
attrs?: Record<string, string> | ((props: {
|
|
226
|
+
node: Node;
|
|
227
|
+
HTMLAttributes: Record<string, any>;
|
|
228
|
+
}) => Record<string, string>);
|
|
229
|
+
}
|
|
230
|
+
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> {
|
|
231
|
+
/**
|
|
232
|
+
* The renderer instance.
|
|
233
|
+
*/
|
|
234
|
+
renderer: ReactRenderer<unknown, ReactNodeViewProps<T>>;
|
|
235
|
+
/**
|
|
236
|
+
* The element that holds the rich-text content of the node.
|
|
237
|
+
*/
|
|
238
|
+
contentDOMElement: HTMLElement | null;
|
|
239
|
+
constructor(component: Component, props: NodeViewRendererProps, options?: Partial<Options>);
|
|
240
|
+
/**
|
|
241
|
+
* Setup the React component.
|
|
242
|
+
* Called on initialization.
|
|
243
|
+
*/
|
|
244
|
+
mount(): void;
|
|
245
|
+
/**
|
|
246
|
+
* Return the DOM element.
|
|
247
|
+
* This is the element that will be used to display the node view.
|
|
248
|
+
*/
|
|
249
|
+
get dom(): HTMLElement;
|
|
250
|
+
/**
|
|
251
|
+
* Return the content DOM element.
|
|
252
|
+
* This is the element that will be used to display the rich-text content of the node.
|
|
253
|
+
*/
|
|
254
|
+
get contentDOM(): HTMLElement | null;
|
|
255
|
+
/**
|
|
256
|
+
* On editor selection update, check if the node is selected.
|
|
257
|
+
* If it is, call `selectNode`, otherwise call `deselectNode`.
|
|
258
|
+
*/
|
|
259
|
+
handleSelectionUpdate(): void;
|
|
260
|
+
/**
|
|
261
|
+
* On update, update the React component.
|
|
262
|
+
* To prevent unnecessary updates, the `update` option can be used.
|
|
263
|
+
*/
|
|
264
|
+
update(node: Node, decorations: readonly Decoration[], innerDecorations: DecorationSource): boolean;
|
|
265
|
+
/**
|
|
266
|
+
* Select the node.
|
|
267
|
+
* Add the `selected` prop and the `ProseMirror-selectednode` class.
|
|
268
|
+
*/
|
|
269
|
+
selectNode(): void;
|
|
270
|
+
/**
|
|
271
|
+
* Deselect the node.
|
|
272
|
+
* Remove the `selected` prop and the `ProseMirror-selectednode` class.
|
|
273
|
+
*/
|
|
274
|
+
deselectNode(): void;
|
|
275
|
+
/**
|
|
276
|
+
* Destroy the React component instance.
|
|
277
|
+
*/
|
|
278
|
+
destroy(): void;
|
|
279
|
+
/**
|
|
280
|
+
* Update the attributes of the top-level element that holds the React component.
|
|
281
|
+
* Applying the attributes defined in the `attrs` option.
|
|
282
|
+
*/
|
|
283
|
+
updateElementAttributes(): void;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Create a React node view renderer.
|
|
287
|
+
*/
|
|
288
|
+
declare function ReactNodeViewRenderer<T = HTMLElement>(component: ComponentType$1<ReactNodeViewProps<T>>, options?: Partial<ReactNodeViewRendererOptions>): NodeViewRenderer;
|
|
289
|
+
|
|
290
|
+
type EditorStateSnapshot<TEditor extends Editor | null = Editor | null> = {
|
|
291
|
+
editor: TEditor;
|
|
292
|
+
transactionNumber: number;
|
|
293
|
+
};
|
|
294
|
+
type UseEditorStateOptions<TSelectorResult, TEditor extends Editor | null = Editor | null> = {
|
|
295
|
+
/**
|
|
296
|
+
* The editor instance.
|
|
297
|
+
*/
|
|
298
|
+
editor: TEditor;
|
|
299
|
+
/**
|
|
300
|
+
* A selector function to determine the value to compare for re-rendering.
|
|
301
|
+
*/
|
|
302
|
+
selector: (context: EditorStateSnapshot<TEditor>) => TSelectorResult;
|
|
303
|
+
/**
|
|
304
|
+
* A custom equality function to determine if the editor should re-render.
|
|
305
|
+
* @default `deepEqual` from `fast-deep-equal`
|
|
306
|
+
*/
|
|
307
|
+
equalityFn?: (a: TSelectorResult, b: TSelectorResult | null) => boolean;
|
|
308
|
+
};
|
|
309
|
+
/**
|
|
310
|
+
* This hook allows you to watch for changes on the editor instance.
|
|
311
|
+
* It will allow you to select a part of the editor state and re-render the component when it changes.
|
|
312
|
+
* @example
|
|
313
|
+
* ```tsx
|
|
314
|
+
* const editor = useEditor({...options})
|
|
315
|
+
* const { currentSelection } = useEditorState({
|
|
316
|
+
* editor,
|
|
317
|
+
* selector: snapshot => ({ currentSelection: snapshot.editor.state.selection }),
|
|
318
|
+
* })
|
|
319
|
+
*/
|
|
320
|
+
declare function useEditorState<TSelectorResult>(options: UseEditorStateOptions<TSelectorResult, Editor>): TSelectorResult;
|
|
321
|
+
/**
|
|
322
|
+
* This hook allows you to watch for changes on the editor instance.
|
|
323
|
+
* It will allow you to select a part of the editor state and re-render the component when it changes.
|
|
324
|
+
* @example
|
|
325
|
+
* ```tsx
|
|
326
|
+
* const editor = useEditor({...options})
|
|
327
|
+
* const { currentSelection } = useEditorState({
|
|
328
|
+
* editor,
|
|
329
|
+
* selector: snapshot => ({ currentSelection: snapshot.editor.state.selection }),
|
|
330
|
+
* })
|
|
331
|
+
*/
|
|
332
|
+
declare function useEditorState<TSelectorResult>(options: UseEditorStateOptions<TSelectorResult, Editor | null>): TSelectorResult | null;
|
|
333
|
+
|
|
334
|
+
interface ReactNodeViewContextProps {
|
|
335
|
+
onDragStart?: (event: DragEvent) => void;
|
|
336
|
+
nodeViewContentRef?: (element: HTMLElement | null) => void;
|
|
337
|
+
/**
|
|
338
|
+
* This allows you to add children into the NodeViewContent component.
|
|
339
|
+
* This is useful when statically rendering the content of a node view.
|
|
340
|
+
*/
|
|
341
|
+
nodeViewContentChildren?: ReactNode;
|
|
342
|
+
}
|
|
343
|
+
declare const ReactNodeViewContext: React.Context<ReactNodeViewContextProps>;
|
|
344
|
+
declare const ReactNodeViewContentProvider: ({ children, content }: {
|
|
345
|
+
children: ReactNode;
|
|
346
|
+
content: ReactNode;
|
|
347
|
+
}) => React.FunctionComponentElement<React.ProviderProps<ReactNodeViewContextProps>>;
|
|
348
|
+
declare const useReactNodeView: () => ReactNodeViewContextProps;
|
|
349
|
+
|
|
350
|
+
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, type UseEditorOptions, type UseEditorStateOptions, useCurrentEditor, useEditor, useEditorState, useReactNodeView };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,350 @@
|
|
|
1
|
+
import * as react_jsx_runtime_js from 'react/jsx-runtime.js';
|
|
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_js.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_js.JSX.Element;
|
|
84
|
+
}
|
|
85
|
+
declare const EditorContent: React__default.MemoExoticComponent<React__default.ForwardRefExoticComponent<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_js.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: Element;
|
|
141
|
+
props: P;
|
|
142
|
+
reactElement: ReactNode;
|
|
143
|
+
ref: R | null;
|
|
144
|
+
/**
|
|
145
|
+
* Immediately creates element and renders the provided React component.
|
|
146
|
+
*/
|
|
147
|
+
constructor(component: ComponentType<R, P>, { editor, props, as, className }: ReactRendererOptions);
|
|
148
|
+
/**
|
|
149
|
+
* Render the React component.
|
|
150
|
+
*/
|
|
151
|
+
render(): void;
|
|
152
|
+
/**
|
|
153
|
+
* Re-renders the React component with new props.
|
|
154
|
+
*/
|
|
155
|
+
updateProps(props?: Record<string, any>): void;
|
|
156
|
+
/**
|
|
157
|
+
* Destroy the React component.
|
|
158
|
+
*/
|
|
159
|
+
destroy(): void;
|
|
160
|
+
/**
|
|
161
|
+
* Update the attributes of the element that holds the React component.
|
|
162
|
+
*/
|
|
163
|
+
updateAttributes(attributes: Record<string, string>): void;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
interface MarkViewContextProps {
|
|
167
|
+
markViewContentRef: (element: HTMLElement | null) => void;
|
|
168
|
+
}
|
|
169
|
+
declare const ReactMarkViewContext: React__default.Context<MarkViewContextProps>;
|
|
170
|
+
type MarkViewContentProps<T extends keyof React__default.JSX.IntrinsicElements = 'span'> = {
|
|
171
|
+
as?: T;
|
|
172
|
+
} & Omit<React__default.ComponentProps<T>, 'as'>;
|
|
173
|
+
declare const MarkViewContent: <T extends keyof React__default.JSX.IntrinsicElements = "span">(props: MarkViewContentProps<T>) => react_jsx_runtime_js.JSX.Element;
|
|
174
|
+
interface ReactMarkViewRendererOptions extends MarkViewRendererOptions {
|
|
175
|
+
/**
|
|
176
|
+
* The tag name of the element wrapping the React component.
|
|
177
|
+
*/
|
|
178
|
+
as?: string;
|
|
179
|
+
className?: string;
|
|
180
|
+
attrs?: {
|
|
181
|
+
[key: string]: string;
|
|
182
|
+
};
|
|
183
|
+
}
|
|
184
|
+
declare class ReactMarkView extends MarkView<React__default.ComponentType<MarkViewProps>, ReactMarkViewRendererOptions> {
|
|
185
|
+
renderer: ReactRenderer;
|
|
186
|
+
contentDOMElement: HTMLElement | null;
|
|
187
|
+
didMountContentDomElement: boolean;
|
|
188
|
+
constructor(component: React__default.ComponentType<MarkViewProps>, props: MarkViewProps, options?: Partial<ReactMarkViewRendererOptions>);
|
|
189
|
+
get dom(): HTMLElement;
|
|
190
|
+
get contentDOM(): HTMLElement | null;
|
|
191
|
+
}
|
|
192
|
+
declare function ReactMarkViewRenderer(component: React__default.ComponentType<MarkViewProps>, options?: Partial<ReactMarkViewRendererOptions>): MarkViewRenderer;
|
|
193
|
+
|
|
194
|
+
type ReactNodeViewProps<T = HTMLElement> = NodeViewProps & {
|
|
195
|
+
ref: React__default.RefObject<T | null>;
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
interface ReactNodeViewRendererOptions extends NodeViewRendererOptions {
|
|
199
|
+
/**
|
|
200
|
+
* This function is called when the node view is updated.
|
|
201
|
+
* It allows you to compare the old node with the new node and decide if the component should update.
|
|
202
|
+
*/
|
|
203
|
+
update: ((props: {
|
|
204
|
+
oldNode: Node;
|
|
205
|
+
oldDecorations: readonly Decoration[];
|
|
206
|
+
oldInnerDecorations: DecorationSource;
|
|
207
|
+
newNode: Node;
|
|
208
|
+
newDecorations: readonly Decoration[];
|
|
209
|
+
innerDecorations: DecorationSource;
|
|
210
|
+
updateProps: () => void;
|
|
211
|
+
}) => boolean) | null;
|
|
212
|
+
/**
|
|
213
|
+
* The tag name of the element wrapping the React component.
|
|
214
|
+
*/
|
|
215
|
+
as?: string;
|
|
216
|
+
/**
|
|
217
|
+
* The class name of the element wrapping the React component.
|
|
218
|
+
*/
|
|
219
|
+
className?: string;
|
|
220
|
+
/**
|
|
221
|
+
* Attributes that should be applied to the element wrapping the React component.
|
|
222
|
+
* If this is a function, it will be called each time the node view is updated.
|
|
223
|
+
* If this is an object, it will be applied once when the node view is mounted.
|
|
224
|
+
*/
|
|
225
|
+
attrs?: Record<string, string> | ((props: {
|
|
226
|
+
node: Node;
|
|
227
|
+
HTMLAttributes: Record<string, any>;
|
|
228
|
+
}) => Record<string, string>);
|
|
229
|
+
}
|
|
230
|
+
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> {
|
|
231
|
+
/**
|
|
232
|
+
* The renderer instance.
|
|
233
|
+
*/
|
|
234
|
+
renderer: ReactRenderer<unknown, ReactNodeViewProps<T>>;
|
|
235
|
+
/**
|
|
236
|
+
* The element that holds the rich-text content of the node.
|
|
237
|
+
*/
|
|
238
|
+
contentDOMElement: HTMLElement | null;
|
|
239
|
+
constructor(component: Component, props: NodeViewRendererProps, options?: Partial<Options>);
|
|
240
|
+
/**
|
|
241
|
+
* Setup the React component.
|
|
242
|
+
* Called on initialization.
|
|
243
|
+
*/
|
|
244
|
+
mount(): void;
|
|
245
|
+
/**
|
|
246
|
+
* Return the DOM element.
|
|
247
|
+
* This is the element that will be used to display the node view.
|
|
248
|
+
*/
|
|
249
|
+
get dom(): HTMLElement;
|
|
250
|
+
/**
|
|
251
|
+
* Return the content DOM element.
|
|
252
|
+
* This is the element that will be used to display the rich-text content of the node.
|
|
253
|
+
*/
|
|
254
|
+
get contentDOM(): HTMLElement | null;
|
|
255
|
+
/**
|
|
256
|
+
* On editor selection update, check if the node is selected.
|
|
257
|
+
* If it is, call `selectNode`, otherwise call `deselectNode`.
|
|
258
|
+
*/
|
|
259
|
+
handleSelectionUpdate(): void;
|
|
260
|
+
/**
|
|
261
|
+
* On update, update the React component.
|
|
262
|
+
* To prevent unnecessary updates, the `update` option can be used.
|
|
263
|
+
*/
|
|
264
|
+
update(node: Node, decorations: readonly Decoration[], innerDecorations: DecorationSource): boolean;
|
|
265
|
+
/**
|
|
266
|
+
* Select the node.
|
|
267
|
+
* Add the `selected` prop and the `ProseMirror-selectednode` class.
|
|
268
|
+
*/
|
|
269
|
+
selectNode(): void;
|
|
270
|
+
/**
|
|
271
|
+
* Deselect the node.
|
|
272
|
+
* Remove the `selected` prop and the `ProseMirror-selectednode` class.
|
|
273
|
+
*/
|
|
274
|
+
deselectNode(): void;
|
|
275
|
+
/**
|
|
276
|
+
* Destroy the React component instance.
|
|
277
|
+
*/
|
|
278
|
+
destroy(): void;
|
|
279
|
+
/**
|
|
280
|
+
* Update the attributes of the top-level element that holds the React component.
|
|
281
|
+
* Applying the attributes defined in the `attrs` option.
|
|
282
|
+
*/
|
|
283
|
+
updateElementAttributes(): void;
|
|
284
|
+
}
|
|
285
|
+
/**
|
|
286
|
+
* Create a React node view renderer.
|
|
287
|
+
*/
|
|
288
|
+
declare function ReactNodeViewRenderer<T = HTMLElement>(component: ComponentType$1<ReactNodeViewProps<T>>, options?: Partial<ReactNodeViewRendererOptions>): NodeViewRenderer;
|
|
289
|
+
|
|
290
|
+
type EditorStateSnapshot<TEditor extends Editor | null = Editor | null> = {
|
|
291
|
+
editor: TEditor;
|
|
292
|
+
transactionNumber: number;
|
|
293
|
+
};
|
|
294
|
+
type UseEditorStateOptions<TSelectorResult, TEditor extends Editor | null = Editor | null> = {
|
|
295
|
+
/**
|
|
296
|
+
* The editor instance.
|
|
297
|
+
*/
|
|
298
|
+
editor: TEditor;
|
|
299
|
+
/**
|
|
300
|
+
* A selector function to determine the value to compare for re-rendering.
|
|
301
|
+
*/
|
|
302
|
+
selector: (context: EditorStateSnapshot<TEditor>) => TSelectorResult;
|
|
303
|
+
/**
|
|
304
|
+
* A custom equality function to determine if the editor should re-render.
|
|
305
|
+
* @default `deepEqual` from `fast-deep-equal`
|
|
306
|
+
*/
|
|
307
|
+
equalityFn?: (a: TSelectorResult, b: TSelectorResult | null) => boolean;
|
|
308
|
+
};
|
|
309
|
+
/**
|
|
310
|
+
* This hook allows you to watch for changes on the editor instance.
|
|
311
|
+
* It will allow you to select a part of the editor state and re-render the component when it changes.
|
|
312
|
+
* @example
|
|
313
|
+
* ```tsx
|
|
314
|
+
* const editor = useEditor({...options})
|
|
315
|
+
* const { currentSelection } = useEditorState({
|
|
316
|
+
* editor,
|
|
317
|
+
* selector: snapshot => ({ currentSelection: snapshot.editor.state.selection }),
|
|
318
|
+
* })
|
|
319
|
+
*/
|
|
320
|
+
declare function useEditorState<TSelectorResult>(options: UseEditorStateOptions<TSelectorResult, Editor>): TSelectorResult;
|
|
321
|
+
/**
|
|
322
|
+
* This hook allows you to watch for changes on the editor instance.
|
|
323
|
+
* It will allow you to select a part of the editor state and re-render the component when it changes.
|
|
324
|
+
* @example
|
|
325
|
+
* ```tsx
|
|
326
|
+
* const editor = useEditor({...options})
|
|
327
|
+
* const { currentSelection } = useEditorState({
|
|
328
|
+
* editor,
|
|
329
|
+
* selector: snapshot => ({ currentSelection: snapshot.editor.state.selection }),
|
|
330
|
+
* })
|
|
331
|
+
*/
|
|
332
|
+
declare function useEditorState<TSelectorResult>(options: UseEditorStateOptions<TSelectorResult, Editor | null>): TSelectorResult | null;
|
|
333
|
+
|
|
334
|
+
interface ReactNodeViewContextProps {
|
|
335
|
+
onDragStart?: (event: DragEvent) => void;
|
|
336
|
+
nodeViewContentRef?: (element: HTMLElement | null) => void;
|
|
337
|
+
/**
|
|
338
|
+
* This allows you to add children into the NodeViewContent component.
|
|
339
|
+
* This is useful when statically rendering the content of a node view.
|
|
340
|
+
*/
|
|
341
|
+
nodeViewContentChildren?: ReactNode;
|
|
342
|
+
}
|
|
343
|
+
declare const ReactNodeViewContext: React.Context<ReactNodeViewContextProps>;
|
|
344
|
+
declare const ReactNodeViewContentProvider: ({ children, content }: {
|
|
345
|
+
children: ReactNode;
|
|
346
|
+
content: ReactNode;
|
|
347
|
+
}) => React.FunctionComponentElement<React.ProviderProps<ReactNodeViewContextProps>>;
|
|
348
|
+
declare const useReactNodeView: () => ReactNodeViewContextProps;
|
|
349
|
+
|
|
350
|
+
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, type UseEditorOptions, type UseEditorStateOptions, useCurrentEditor, useEditor, useEditorState, useReactNodeView };
|