@handlewithcare/react-prosemirror 2.8.0-tiptap.23 → 2.8.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (90) hide show
  1. package/dist/cjs/StaticEditorView.js +0 -3
  2. package/dist/cjs/commands/reorderSiblings.js +60 -45
  3. package/dist/cjs/components/nodes/CustomNodeView.js +1 -1
  4. package/dist/cjs/components/nodes/DocNodeView.js +1 -1
  5. package/dist/cjs/components/nodes/ReactNodeView.js +7 -5
  6. package/dist/cjs/hooks/useEditor.js +0 -4
  7. package/dist/cjs/hooks/useEditorEventCallback.js +1 -1
  8. package/dist/cjs/hooks/useNodeViewDescriptor.js +1 -4
  9. package/dist/cjs/viewdesc.js +5 -5
  10. package/dist/esm/StaticEditorView.js +0 -3
  11. package/dist/esm/commands/reorderSiblings.js +49 -42
  12. package/dist/esm/components/nodes/CustomNodeView.js +1 -1
  13. package/dist/esm/components/nodes/DocNodeView.js +1 -1
  14. package/dist/esm/components/nodes/ReactNodeView.js +8 -6
  15. package/dist/esm/hooks/useEditor.js +0 -4
  16. package/dist/esm/hooks/useEditorEffect.js +0 -4
  17. package/dist/esm/hooks/useEditorEventCallback.js +6 -4
  18. package/dist/esm/hooks/useNodeViewDescriptor.js +1 -4
  19. package/dist/esm/viewdesc.js +5 -5
  20. package/dist/tsconfig.tsbuildinfo +1 -1
  21. package/dist/types/AbstractEditorView.d.ts +0 -1
  22. package/dist/types/StaticEditorView.d.ts +0 -1
  23. package/dist/types/commands/__tests__/reorderSiblings.test.d.ts +1 -0
  24. package/dist/types/commands/reorderSiblings.d.ts +3 -1
  25. package/dist/types/constants.d.ts +1 -1
  26. package/dist/types/hooks/useEditorEffect.d.ts +0 -4
  27. package/dist/types/hooks/useEditorEventCallback.d.ts +6 -4
  28. package/dist/types/hooks/useNodeViewDescriptor.d.ts +3 -1
  29. package/dist/types/props.d.ts +26 -26
  30. package/package.json +12 -20
  31. package/dist/cjs/components/CustomNodeView.js +0 -132
  32. package/dist/cjs/components/DefaultNodeView.js +0 -67
  33. package/dist/cjs/components/DocNodeView.js +0 -96
  34. package/dist/cjs/components/MarkView.js +0 -119
  35. package/dist/cjs/components/NodeView.js +0 -86
  36. package/dist/cjs/components/NodeViewComponentProps.js +0 -4
  37. package/dist/cjs/components/ReactNodeView.js +0 -174
  38. package/dist/cjs/tiptap/ReactProseMirrorNodeView.js +0 -26
  39. package/dist/cjs/tiptap/TiptapEditor.js +0 -34
  40. package/dist/cjs/tiptap/TiptapEditorContent.js +0 -142
  41. package/dist/cjs/tiptap/TiptapEditorView.js +0 -118
  42. package/dist/cjs/tiptap/TiptapNodeView.js +0 -26
  43. package/dist/cjs/tiptap/contexts/TiptapEditorContext.js +0 -12
  44. package/dist/cjs/tiptap/extensions/ReactProseMirror.js +0 -79
  45. package/dist/cjs/tiptap/hooks/useIsInReactProseMirror.js +0 -15
  46. package/dist/cjs/tiptap/hooks/useTiptapEditor.js +0 -43
  47. package/dist/cjs/tiptap/hooks/useTiptapEditorEffect.js +0 -35
  48. package/dist/cjs/tiptap/hooks/useTiptapEditorEventCallback.js +0 -35
  49. package/dist/cjs/tiptap/index.js +0 -48
  50. package/dist/cjs/tiptap/tiptapNodeView.js +0 -237
  51. package/dist/esm/components/CustomNodeView.js +0 -81
  52. package/dist/esm/components/DefaultNodeView.js +0 -16
  53. package/dist/esm/components/DocNodeView.js +0 -45
  54. package/dist/esm/components/MarkView.js +0 -68
  55. package/dist/esm/components/NodeView.js +0 -35
  56. package/dist/esm/components/NodeViewComponentProps.js +0 -1
  57. package/dist/esm/components/ReactNodeView.js +0 -123
  58. package/dist/esm/tiptap/ReactProseMirrorNodeView.js +0 -22
  59. package/dist/esm/tiptap/TiptapEditor.js +0 -24
  60. package/dist/esm/tiptap/TiptapEditorContent.js +0 -91
  61. package/dist/esm/tiptap/TiptapEditorView.js +0 -69
  62. package/dist/esm/tiptap/TiptapNodeView.js +0 -22
  63. package/dist/esm/tiptap/contexts/TiptapEditorContext.js +0 -2
  64. package/dist/esm/tiptap/extensions/ReactProseMirror.js +0 -69
  65. package/dist/esm/tiptap/hooks/useIsInReactProseMirror.js +0 -5
  66. package/dist/esm/tiptap/hooks/useTiptapEditor.js +0 -33
  67. package/dist/esm/tiptap/hooks/useTiptapEditorEffect.js +0 -42
  68. package/dist/esm/tiptap/hooks/useTiptapEditorEventCallback.js +0 -35
  69. package/dist/esm/tiptap/index.js +0 -9
  70. package/dist/esm/tiptap/tiptapNodeView.js +0 -205
  71. package/dist/types/components/CustomNodeView.d.ts +0 -12
  72. package/dist/types/components/DefaultNodeView.d.ts +0 -3
  73. package/dist/types/components/DocNodeView.d.ts +0 -12
  74. package/dist/types/components/MarkView.d.ts +0 -9
  75. package/dist/types/components/NodeView.d.ts +0 -11
  76. package/dist/types/components/NodeViewComponentProps.d.ts +0 -12
  77. package/dist/types/components/ReactNodeView.d.ts +0 -13
  78. package/dist/types/tiptap/ReactProseMirrorNodeView.d.ts +0 -15
  79. package/dist/types/tiptap/TiptapEditor.d.ts +0 -6
  80. package/dist/types/tiptap/TiptapEditorContent.d.ts +0 -19
  81. package/dist/types/tiptap/TiptapEditorView.d.ts +0 -16
  82. package/dist/types/tiptap/TiptapNodeView.d.ts +0 -15
  83. package/dist/types/tiptap/contexts/TiptapEditorContext.d.ts +0 -6
  84. package/dist/types/tiptap/extensions/ReactProseMirror.d.ts +0 -9
  85. package/dist/types/tiptap/hooks/useIsInReactProseMirror.d.ts +0 -1
  86. package/dist/types/tiptap/hooks/useTiptapEditor.d.ts +0 -4
  87. package/dist/types/tiptap/hooks/useTiptapEditorEffect.d.ts +0 -21
  88. package/dist/types/tiptap/hooks/useTiptapEditorEventCallback.d.ts +0 -13
  89. package/dist/types/tiptap/index.d.ts +0 -9
  90. package/dist/types/tiptap/tiptapNodeView.d.ts +0 -50
@@ -1,5 +0,0 @@
1
- import { useContext } from "react";
2
- import { EditorContext } from "../../contexts/EditorContext.js";
3
- export function useIsInReactProseMirror() {
4
- return useContext(EditorContext) !== null;
5
- }
@@ -1,33 +0,0 @@
1
- import { useEditor } from "@tiptap/react";
2
- import { StaticEditorView } from "../../StaticEditorView.js";
3
- export function useTiptapEditor(options, deps) {
4
- const editor = useEditor({
5
- ...options,
6
- element: null
7
- }, deps);
8
- // @ts-expect-error private property
9
- editor.editorView ??= new StaticEditorView({
10
- // @ts-expect-error private property
11
- state: editor.editorState,
12
- ...editor.options.editorProps,
13
- attributes: {
14
- role: "textbox",
15
- ...editor.options.editorProps.attributes
16
- }
17
- });
18
- // @ts-expect-error private property
19
- const stateHasPlugins = !!editor.editorState.plugins.length;
20
- const stateNeedsReconfigure = !stateHasPlugins && !editor.isDestroyed;
21
- if (stateNeedsReconfigure) {
22
- const managerPlugins = editor.extensionManager.plugins;
23
- if (managerPlugins.length) {
24
- // @ts-expect-error private property
25
- editor.editorState = editor.editorState.reconfigure({
26
- plugins: editor.extensionManager.plugins
27
- });
28
- // @ts-expect-error private property
29
- editor.editorView.updateState(editor.editorState);
30
- }
31
- }
32
- return editor;
33
- }
@@ -1,42 +0,0 @@
1
- import { useCurrentEditor } from "@tiptap/react";
2
- import { useContext } from "react";
3
- import { ReactEditorView } from "../../ReactEditorView.js";
4
- import { EditorContext } from "../../contexts/EditorContext.js";
5
- import { useEditorEffect } from "../../hooks/useEditorEffect.js";
6
- import { TiptapEditorContext } from "../contexts/TiptapEditorContext.js";
7
- /**
8
- * Registers a layout effect to run after the EditorView has
9
- * been updated with the latest EditorState and Decorations.
10
- *
11
- * Effects can take a Tiptap Editor instance as an argument.
12
- * This hook should be used to execute layout effects that
13
- * depend on the Editor, such as for positioning DOM
14
- * nodes based on ProseMirror positions.
15
- *
16
- * Layout effects registered with this hook still fire
17
- * synchronously after all DOM mutations, but they do so
18
- * _after_ the Editor has been updated, even when the
19
- * Editor lives in an ancestor component.
20
- *
21
- * This hook can only be used in a component that is mounted
22
- * as a child of the TiptapEditorView component, including
23
- * React node view components.
24
- */ export function useTiptapEditorEffect(effect, dependencies) {
25
- const { view } = useContext(EditorContext);
26
- const { editor } = useCurrentEditor();
27
- const { isEditorInitialized } = useContext(TiptapEditorContext);
28
- useEditorEffect(()=>{
29
- if (editor?.view instanceof ReactEditorView && view instanceof ReactEditorView && isEditorInitialized) {
30
- return effect(editor);
31
- }
32
- // The rules of hooks want to be able to statically
33
- // verify the dependencies for the effect, but this will
34
- // have already happened at the call-site.
35
- // eslint-disable-next-line react-hooks/exhaustive-deps
36
- }, dependencies && [
37
- editor,
38
- view,
39
- isEditorInitialized,
40
- ...dependencies
41
- ]);
42
- }
@@ -1,35 +0,0 @@
1
- import { useCurrentEditor } from "@tiptap/react";
2
- import { useCallback, useRef } from "react";
3
- import { useEditorEffect } from "../../hooks/useEditorEffect.js";
4
- function assertEditor(editor) {
5
- if (editor) return;
6
- throw new DOMException("Tiptap Editor is not initialized", "InvalidStateError");
7
- }
8
- /**
9
- * Returns a stable function reference to be used as an
10
- * event handler callback.
11
- *
12
- * The callback will be called with the Tiptap Editor instance
13
- * as its first argument.
14
- *
15
- * This hook can only be used in a component that is mounted
16
- * as a child of the TiptapEditorView component, including
17
- * React node view components.
18
- */ export function useTiptapEditorEventCallback(callback) {
19
- const ref = useRef(callback);
20
- const { editor } = useCurrentEditor();
21
- useEditorEffect(()=>{
22
- ref.current = callback;
23
- }, [
24
- callback
25
- ]);
26
- return useCallback(function() {
27
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
28
- args[_key] = arguments[_key];
29
- }
30
- assertEditor(editor);
31
- return ref.current(editor, ...args);
32
- }, [
33
- editor
34
- ]);
35
- }
@@ -1,9 +0,0 @@
1
- export { tiptapNodeView } from "./tiptapNodeView.js";
2
- export { TiptapEditorView } from "./TiptapEditorView.js";
3
- export { TiptapEditorContent } from "./TiptapEditorContent.js";
4
- export { useTiptapEditorEffect } from "./hooks/useTiptapEditorEffect.js";
5
- export { useIsInReactProseMirror } from "./hooks/useIsInReactProseMirror.js";
6
- export { useTiptapEditorEventCallback } from "./hooks/useTiptapEditorEventCallback.js";
7
- export { TiptapEditor } from "./TiptapEditor.js";
8
- export { useTiptapEditor } from "./hooks/useTiptapEditor.js";
9
- export { ReactProseMirror } from "./extensions/ReactProseMirror.js";
@@ -1,205 +0,0 @@
1
- import { getAttributesFromExtensions, getRenderedAttributes } from "@tiptap/core";
2
- import { ReactNodeViewContext, useCurrentEditor } from "@tiptap/react";
3
- import cx from "classnames";
4
- import React, { forwardRef, memo, useMemo } from "react";
5
- import { useEditorEventCallback } from "../hooks/useEditorEventCallback.js";
6
- import { useIgnoreMutation } from "../hooks/useIgnoreMutation.js";
7
- import { useIsNodeSelected } from "../hooks/useIsNodeSelected.js";
8
- import { useStopEvent } from "../hooks/useStopEvent.js";
9
- import { htmlAttrsToReactProps } from "../props.js";
10
- import { ReactProseMirrorNodeView } from "./ReactProseMirrorNodeView.js";
11
- import { useTiptapEditorEventCallback } from "./hooks/useTiptapEditorEventCallback.js";
12
- /**
13
- * Convert a Tiptap node view component to a React ProseMirror node view component
14
- *
15
- * Given a Tiptap-compatible React component and a Tiptap extension, returns
16
- * a React component that can be passed to React ProseMirror as a custom node view.
17
- *
18
- * Example:
19
- *
20
- * ```tsx
21
- * const nodeViews = {
22
- * codeBlock: nodeView({
23
- * component: function CodeBlock(nodeViewProps) {
24
- * return (
25
- * <AnnotatableNodeViewWrapper {...nodeViewProps}>
26
- * <pre>
27
- * <NodeViewContent as="code" />
28
- * </pre>
29
- * </AnnotatableNodeViewWrapper>
30
- * )
31
- * },
32
- * extension: CodeBlockExtension,
33
- * }),
34
- * }
35
- * ```
36
- */ export function tiptapNodeView(param) {
37
- let { component: WrappedComponent, extension, as, className = "", attrs, contentDOMElementTag: InnerTag = "div", stopEvent, ignoreMutation } = param;
38
- const TiptapNodeView = /*#__PURE__*/ memo(/*#__PURE__*/ forwardRef(function TiptapNodeView(param, ref) {
39
- let { children, nodeProps, ...props } = param;
40
- const { node, getPos, decorations, innerDecorations } = nodeProps;
41
- const OuterTag = as ?? (node.type.isInline ? "span" : "div");
42
- const { editor } = useCurrentEditor();
43
- const extensionManager = editor?.extensionManager ?? null;
44
- const extensions = extensionManager?.extensions ?? null;
45
- const selected = useIsNodeSelected();
46
- const htmlAttributes = useMemo(()=>{
47
- if (!extensions) return {};
48
- const attributes = getAttributesFromExtensions(extensions);
49
- const extensionAttributes = attributes.filter((attribute)=>attribute.type === extension.name);
50
- return getRenderedAttributes(node, extensionAttributes);
51
- }, [
52
- extensions,
53
- node
54
- ]);
55
- useStopEvent(function(_, event) {
56
- if (stopEvent) {
57
- return stopEvent.call({
58
- name: extension.name,
59
- editor,
60
- type: node.type
61
- }, {
62
- event
63
- });
64
- }
65
- if (!editor || !(this.dom instanceof HTMLElement)) return false;
66
- const nodeView = new ReactProseMirrorNodeView(WrappedComponent, {
67
- extension,
68
- decorations,
69
- editor,
70
- getPos,
71
- HTMLAttributes: htmlAttributes,
72
- innerDecorations,
73
- node,
74
- view: editor.view
75
- }, this.dom, this.contentDOM);
76
- return nodeView.stopEvent(event) ?? false;
77
- });
78
- useIgnoreMutation(function(_, mutation) {
79
- if (ignoreMutation) {
80
- return ignoreMutation.call({
81
- name: extension.name,
82
- editor,
83
- type: node.type
84
- }, {
85
- mutation
86
- });
87
- }
88
- if (!editor || !(this.dom instanceof HTMLElement)) return false;
89
- const nodeView = new ReactProseMirrorNodeView(WrappedComponent, {
90
- extension,
91
- decorations,
92
- editor,
93
- getPos,
94
- HTMLAttributes: htmlAttributes,
95
- innerDecorations,
96
- node,
97
- view: editor.view
98
- }, this.dom, this.contentDOM);
99
- return nodeView.ignoreMutation(mutation) ?? false;
100
- });
101
- const { extraClassName, htmlProps } = useMemo(()=>{
102
- if (!attrs) return {};
103
- const resolvedAttrs = typeof attrs === "function" ? attrs({
104
- node,
105
- HTMLAttributes: htmlAttributes
106
- }) : attrs;
107
- const { className: extraClassName, ...htmlProps } = htmlAttrsToReactProps(resolvedAttrs);
108
- return {
109
- extraClassName,
110
- htmlProps
111
- };
112
- }, [
113
- htmlAttributes,
114
- node
115
- ]);
116
- const finalClassName = cx("react-renderer", `node-${node.type.name}`, props.className, className, extraClassName, {
117
- "ProseMirror-selectednode": selected
118
- });
119
- const updateAttributes = useEditorEventCallback((_, attributes)=>{
120
- if (!editor) {
121
- return;
122
- }
123
- editor.commands.command((param)=>{
124
- let { tr } = param;
125
- const pos = getPos();
126
- tr.setNodeMarkup(pos, undefined, {
127
- ...node.attrs,
128
- ...attributes
129
- });
130
- return true;
131
- });
132
- });
133
- const deleteNode = useEditorEventCallback(()=>{
134
- if (!editor) {
135
- return;
136
- }
137
- const from = getPos();
138
- const to = from + node.nodeSize;
139
- editor.commands.deleteRange({
140
- from,
141
- to
142
- });
143
- });
144
- const nodeViewContent = useMemo(()=>/*#__PURE__*/ React.createElement(InnerTag, {
145
- "data-node-view-content-inner": node.type.name,
146
- style: {
147
- whitespace: "inherit"
148
- }
149
- }, children), [
150
- children,
151
- node.type.name
152
- ]);
153
- const onDragStart = useTiptapEditorEventCallback((editor, event)=>{
154
- // TODO: We should probably just merge this with our own
155
- // ref, I'm being lazy since we are providing this
156
- // ref in the first place (in ReactNodeView), so we know
157
- // it's an object
158
- const dom = typeof ref === "object" ? ref?.current : null;
159
- if (!dom) return;
160
- const viewDesc = dom.pmViewDesc;
161
- if (!viewDesc) return;
162
- const nodeView = new ReactProseMirrorNodeView(WrappedComponent, {
163
- extension,
164
- decorations,
165
- editor,
166
- getPos,
167
- HTMLAttributes: htmlAttributes,
168
- innerDecorations,
169
- node,
170
- view: editor.view
171
- }, viewDesc.dom, viewDesc.contentDOM);
172
- return nodeView.onDragStart(event);
173
- });
174
- const nodeViewContext = useMemo(()=>({
175
- nodeViewContentChildren: nodeViewContent,
176
- onDragStart
177
- }), [
178
- nodeViewContent,
179
- onDragStart
180
- ]);
181
- if (!editor) return null;
182
- return /*#__PURE__*/ React.createElement(ReactNodeViewContext.Provider, {
183
- value: nodeViewContext
184
- }, /*#__PURE__*/ React.createElement(OuterTag, {
185
- ref: ref,
186
- ...props,
187
- ...htmlProps,
188
- className: finalClassName
189
- }, /*#__PURE__*/ React.createElement(WrappedComponent, {
190
- node: node,
191
- getPos: getPos,
192
- view: editor.view,
193
- editor: editor,
194
- decorations: decorations,
195
- innerDecorations: innerDecorations,
196
- extension: extension,
197
- HTMLAttributes: htmlAttributes,
198
- selected: selected,
199
- updateAttributes: updateAttributes,
200
- deleteNode: deleteNode
201
- })));
202
- }));
203
- TiptapNodeView.displayName = `TiptapNodeView(${WrappedComponent.displayName ?? "Anonymous"})`;
204
- return TiptapNodeView;
205
- } // const defaultOnDragStart = NodeView.
@@ -1,12 +0,0 @@
1
- import { Node } from "prosemirror-model";
2
- import { Decoration, DecorationSource, NodeViewConstructor } from "prosemirror-view";
3
- import React from "react";
4
- interface Props {
5
- constructor: NodeViewConstructor;
6
- node: Node;
7
- getPos: () => number;
8
- innerDeco: DecorationSource;
9
- outerDeco: readonly Decoration[];
10
- }
11
- export declare const CustomNodeView: React.NamedExoticComponent<Props>;
12
- export {};
@@ -1,3 +0,0 @@
1
- import React from "react";
2
- import { NodeViewComponentProps } from "./NodeViewComponentProps.js";
3
- export declare const DefaultNodeView: React.ForwardRefExoticComponent<Omit<NodeViewComponentProps, "ref"> & React.RefAttributes<HTMLElement>>;
@@ -1,12 +0,0 @@
1
- import { Node } from "prosemirror-model";
2
- import { Decoration, DecorationSource } from "prosemirror-view";
3
- import React, { HTMLProps, ReactElement } from "react";
4
- export interface DocNodeViewProps extends Omit<HTMLProps<HTMLElement>, "as"> {
5
- as?: ReactElement;
6
- node: Node;
7
- getPos: () => number;
8
- decorations: readonly Decoration[];
9
- innerDecorations: DecorationSource;
10
- setMount: (mount: HTMLElement | null) => void;
11
- }
12
- export declare const DocNodeView: React.MemoExoticComponent<React.ForwardRefExoticComponent<Omit<DocNodeViewProps, "ref"> & React.RefAttributes<HTMLElement>>>;
@@ -1,9 +0,0 @@
1
- import { Mark } from "prosemirror-model";
2
- import React, { ReactNode } from "react";
3
- type Props = {
4
- mark: Mark;
5
- getPos: () => number;
6
- children: ReactNode;
7
- };
8
- export declare const MarkView: React.MemoExoticComponent<React.ForwardRefExoticComponent<Props & React.RefAttributes<unknown>>>;
9
- export {};
@@ -1,11 +0,0 @@
1
- import { Node } from "prosemirror-model";
2
- import { Decoration, DecorationSource } from "prosemirror-view";
3
- import React from "react";
4
- type Props = {
5
- node: Node;
6
- getPos: () => number;
7
- outerDeco: readonly Decoration[];
8
- innerDeco: DecorationSource;
9
- };
10
- export declare const NodeView: React.NamedExoticComponent<Props>;
11
- export {};
@@ -1,12 +0,0 @@
1
- import { Node } from "prosemirror-model";
2
- import { Decoration, DecorationSource } from "prosemirror-view";
3
- import { AllHTMLAttributes, LegacyRef } from "react";
4
- export interface NodeViewComponentProps extends AllHTMLAttributes<HTMLElement> {
5
- nodeProps: {
6
- decorations: readonly Decoration[];
7
- innerDecorations: DecorationSource;
8
- node: Node;
9
- getPos: () => number;
10
- };
11
- ref: LegacyRef<any>;
12
- }
@@ -1,13 +0,0 @@
1
- import { Node } from "prosemirror-model";
2
- import { Decoration, DecorationSource } from "prosemirror-view";
3
- import React, { ComponentType } from "react";
4
- import { NodeViewComponentProps } from "./NodeViewComponentProps.js";
5
- type Props = {
6
- component: ComponentType<NodeViewComponentProps>;
7
- outerDeco: readonly Decoration[];
8
- getPos: () => number;
9
- node: Node;
10
- innerDeco: DecorationSource;
11
- };
12
- export declare const ReactNodeView: React.NamedExoticComponent<Props>;
13
- export {};
@@ -1,15 +0,0 @@
1
- import { Editor, NodeView, NodeViewRendererOptions, NodeViewRendererProps } from "@tiptap/core";
2
- /**
3
- * Subclass of Tiptap's NodeView to be used in tiptapNodeView.
4
- *
5
- * Allows us to pass in an existing dom and contentODM from React ProseMirror's
6
- * ViewDesc, so that we can call Tiptap's default stopEvent and ignoreMutation
7
- * methods
8
- */
9
- export declare class ReactProseMirrorNodeView<Component, NodeEditor extends Editor = Editor, Options extends NodeViewRendererOptions = NodeViewRendererOptions> extends NodeView<Component, NodeEditor, Options> {
10
- private _dom;
11
- private _contentDOM;
12
- constructor(component: Component, props: NodeViewRendererProps, dom: HTMLElement, contentDOM: HTMLElement | null, options?: Partial<Options>);
13
- get dom(): HTMLElement;
14
- get contentDOM(): HTMLElement | null;
15
- }
@@ -1,6 +0,0 @@
1
- import { Editor, type EditorOptions } from "@tiptap/core";
2
- import type { EditorView } from "prosemirror-view";
3
- export declare class TiptapEditor extends Editor {
4
- constructor(options?: Partial<EditorOptions>);
5
- get view(): EditorView;
6
- }
@@ -1,19 +0,0 @@
1
- import { Editor } from "@tiptap/core";
2
- import { ReactRenderer } from "@tiptap/react";
3
- import React, { ForwardedRef, HTMLProps, ReactPortal } from "react";
4
- export type ContentComponent = {
5
- setRenderer(id: string, renderer: ReactRenderer): void;
6
- removeRenderer(id: string): void;
7
- subscribe: (callback: () => void) => () => void;
8
- getSnapshot: () => Record<string, ReactPortal>;
9
- getServerSnapshot: () => Record<string, ReactPortal>;
10
- };
11
- export interface EditorContentProps extends HTMLProps<HTMLDivElement> {
12
- editor: Editor | null;
13
- innerRef?: ForwardedRef<HTMLDivElement | null>;
14
- }
15
- interface Props extends Omit<HTMLProps<HTMLElement>, "as"> {
16
- editor: Editor;
17
- }
18
- export declare function TiptapEditorContent({ editor: editorProp, ...props }: Props): React.JSX.Element;
19
- export {};
@@ -1,16 +0,0 @@
1
- import { Editor } from "@tiptap/core";
2
- import React, { ComponentType, ReactNode } from "react";
3
- import { MarkViewComponentProps } from "../components/marks/MarkViewComponentProps.js";
4
- import { NodeViewComponentProps } from "../components/nodes/NodeViewComponentProps.js";
5
- interface Props {
6
- editor: Editor;
7
- nodeViews?: Record<string, ComponentType<NodeViewComponentProps>>;
8
- markViews?: Record<string, ComponentType<MarkViewComponentProps>>;
9
- children?: ReactNode;
10
- static?: boolean;
11
- }
12
- /**
13
- * Render a Tiptap-compatible React ProseMirror editor.
14
- */
15
- export declare function TiptapEditorView({ editor, nodeViews, markViews, children, static: isStatic, }: Props): React.JSX.Element;
16
- export {};
@@ -1,15 +0,0 @@
1
- import { Editor, NodeView, NodeViewRendererOptions, NodeViewRendererProps } from "@tiptap/core";
2
- /**
3
- * Subclass of Tiptap's NodeView to be used in tiptapNodeView.
4
- *
5
- * Allows us to pass in an existing dom and contentODM from React ProseMirror's
6
- * ViewDesc, so that we can call Tiptap's default stopEvent and ignoreMutation
7
- * methods
8
- */
9
- export declare class ReactProseMirrorNodeView<Component, NodeEditor extends Editor = Editor, Options extends NodeViewRendererOptions = NodeViewRendererOptions> extends NodeView<Component, NodeEditor, Options> {
10
- private _dom;
11
- private _contentDOM;
12
- constructor(component: Component, props: NodeViewRendererProps, dom: HTMLElement, contentDOM: HTMLElement | null, options?: Partial<Options>);
13
- get dom(): HTMLElement;
14
- get contentDOM(): HTMLElement | null;
15
- }
@@ -1,6 +0,0 @@
1
- export interface TiptapEditorContextValue {
2
- isEditorInitialized: boolean;
3
- onEditorInitialize: () => void;
4
- onEditorDeinitialize: () => void;
5
- }
6
- export declare const TiptapEditorContext: import("react").Context<TiptapEditorContextValue>;
@@ -1,9 +0,0 @@
1
- import { Extension } from "@tiptap/core";
2
- declare module "@tiptap/core" {
3
- interface Commands<ReturnType> {
4
- reactProseMirrorCommands: {
5
- reorderSiblings: (pos: number, order: number[]) => ReturnType;
6
- };
7
- }
8
- }
9
- export declare const ReactProseMirror: Extension<any, any>;
@@ -1 +0,0 @@
1
- export declare function useIsInReactProseMirror(): boolean;
@@ -1,4 +0,0 @@
1
- import { useEditor } from "@tiptap/react";
2
- import { DependencyList } from "react";
3
- export type UseTiptapEditorOptions = Omit<Parameters<typeof useEditor>[0], "element">;
4
- export declare function useTiptapEditor(options: UseTiptapEditorOptions, deps?: DependencyList): import("@tiptap/core").Editor;
@@ -1,21 +0,0 @@
1
- import { Editor } from "@tiptap/core";
2
- import { DependencyList } from "react";
3
- /**
4
- * Registers a layout effect to run after the EditorView has
5
- * been updated with the latest EditorState and Decorations.
6
- *
7
- * Effects can take a Tiptap Editor instance as an argument.
8
- * This hook should be used to execute layout effects that
9
- * depend on the Editor, such as for positioning DOM
10
- * nodes based on ProseMirror positions.
11
- *
12
- * Layout effects registered with this hook still fire
13
- * synchronously after all DOM mutations, but they do so
14
- * _after_ the Editor has been updated, even when the
15
- * Editor lives in an ancestor component.
16
- *
17
- * This hook can only be used in a component that is mounted
18
- * as a child of the TiptapEditorView component, including
19
- * React node view components.
20
- */
21
- export declare function useTiptapEditorEffect(effect: (editor: Editor) => void | (() => void), dependencies?: DependencyList): void;
@@ -1,13 +0,0 @@
1
- import { Editor } from "@tiptap/core";
2
- /**
3
- * Returns a stable function reference to be used as an
4
- * event handler callback.
5
- *
6
- * The callback will be called with the Tiptap Editor instance
7
- * as its first argument.
8
- *
9
- * This hook can only be used in a component that is mounted
10
- * as a child of the TiptapEditorView component, including
11
- * React node view components.
12
- */
13
- export declare function useTiptapEditorEventCallback<T extends unknown[], R>(callback: (editor: Editor, ...args: T) => R): (...args: T) => R;
@@ -1,9 +0,0 @@
1
- export { tiptapNodeView } from "./tiptapNodeView.js";
2
- export { TiptapEditorView } from "./TiptapEditorView.js";
3
- export { TiptapEditorContent } from "./TiptapEditorContent.js";
4
- export { useTiptapEditorEffect } from "./hooks/useTiptapEditorEffect.js";
5
- export { useIsInReactProseMirror } from "./hooks/useIsInReactProseMirror.js";
6
- export { useTiptapEditorEventCallback } from "./hooks/useTiptapEditorEventCallback.js";
7
- export { TiptapEditor } from "./TiptapEditor.js";
8
- export { type UseTiptapEditorOptions, useTiptapEditor, } from "./hooks/useTiptapEditor.js";
9
- export { ReactProseMirror } from "./extensions/ReactProseMirror.js";
@@ -1,50 +0,0 @@
1
- import { type ReactNodeViewProps } from "@tiptap/react";
2
- import { type Node as ProseMirrorNode } from "prosemirror-model";
3
- import { ViewMutationRecord } from "prosemirror-view";
4
- import React, { type ComponentType, ElementType, Ref } from "react";
5
- import { NodeViewComponentProps } from "../components/nodes/NodeViewComponentProps.js";
6
- export interface TiptapNodeViewProps {
7
- component: ComponentType<Omit<ReactNodeViewProps, "ref"> & {
8
- ref?: Ref<HTMLElement | null>;
9
- }>;
10
- extension: ReactNodeViewProps["extension"];
11
- className?: string | undefined;
12
- attrs?: Record<string, string> | ((props: {
13
- node: ProseMirrorNode;
14
- HTMLAttributes: Record<string, unknown>;
15
- }) => Record<string, string>) | undefined;
16
- as?: ElementType | undefined;
17
- stopEvent?: ((props: {
18
- event: Event;
19
- }) => boolean) | null;
20
- ignoreMutation?: ((props: {
21
- mutation: ViewMutationRecord;
22
- }) => boolean) | null;
23
- contentDOMElementTag?: ElementType | undefined;
24
- }
25
- /**
26
- * Convert a Tiptap node view component to a React ProseMirror node view component
27
- *
28
- * Given a Tiptap-compatible React component and a Tiptap extension, returns
29
- * a React component that can be passed to React ProseMirror as a custom node view.
30
- *
31
- * Example:
32
- *
33
- * ```tsx
34
- * const nodeViews = {
35
- * codeBlock: nodeView({
36
- * component: function CodeBlock(nodeViewProps) {
37
- * return (
38
- * <AnnotatableNodeViewWrapper {...nodeViewProps}>
39
- * <pre>
40
- * <NodeViewContent as="code" />
41
- * </pre>
42
- * </AnnotatableNodeViewWrapper>
43
- * )
44
- * },
45
- * extension: CodeBlockExtension,
46
- * }),
47
- * }
48
- * ```
49
- */
50
- export declare function tiptapNodeView({ component: WrappedComponent, extension, as, className, attrs, contentDOMElementTag: InnerTag, stopEvent, ignoreMutation, }: TiptapNodeViewProps): React.MemoExoticComponent<React.ForwardRefExoticComponent<Omit<NodeViewComponentProps, "ref"> & React.RefAttributes<HTMLElement | null>>>;