@tiptap/react 3.0.0-beta.2 → 3.0.0-beta.21
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 +75 -42
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +16 -11
- package/dist/index.d.ts +16 -11
- package/dist/index.js +70 -37
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
- package/src/EditorContent.tsx +4 -8
- package/src/ReactMarkViewRenderer.tsx +7 -5
- package/src/ReactNodeViewRenderer.tsx +46 -27
- package/src/ReactRenderer.tsx +100 -19
- package/src/index.ts +1 -0
- package/src/types.ts +6 -0
- package/src/useEditorState.ts +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as react_jsx_runtime_js from 'react/jsx-runtime.js';
|
|
2
|
-
import { EditorOptions, Editor, MarkViewRendererOptions, MarkView, MarkViewProps, MarkViewRenderer,
|
|
2
|
+
import { EditorOptions, Editor, MarkViewRendererOptions, MarkView, MarkViewProps, MarkViewRenderer, NodeViewProps, NodeViewRendererOptions, NodeView, NodeViewRendererProps, NodeViewRenderer } from '@tiptap/core';
|
|
3
3
|
export * from '@tiptap/core';
|
|
4
4
|
import * as React from 'react';
|
|
5
|
-
import React__default, { DependencyList, ReactNode, HTMLAttributes, HTMLProps, ForwardedRef, ComponentProps, ComponentType as ComponentType$1 } from 'react';
|
|
5
|
+
import React__default, { DependencyList, ReactNode, HTMLAttributes, HTMLProps, ForwardedRef, ComponentProps, ComponentClass, FunctionComponent, ForwardRefExoticComponent, PropsWithoutRef, RefAttributes, ComponentType as ComponentType$1 } from 'react';
|
|
6
6
|
import { Node } from '@tiptap/pm/model';
|
|
7
7
|
import { Decoration, DecorationSource } from '@tiptap/pm/view';
|
|
8
8
|
|
|
@@ -121,7 +121,7 @@ interface ReactRendererOptions {
|
|
|
121
121
|
*/
|
|
122
122
|
className?: string;
|
|
123
123
|
}
|
|
124
|
-
type ComponentType<R, P> =
|
|
124
|
+
type ComponentType<R, P> = ComponentClass<P> | FunctionComponent<P> | ForwardRefExoticComponent<PropsWithoutRef<P> & RefAttributes<R>>;
|
|
125
125
|
/**
|
|
126
126
|
* The ReactRenderer class. It's responsible for rendering React components inside the editor.
|
|
127
127
|
* @example
|
|
@@ -139,7 +139,7 @@ declare class ReactRenderer<R = unknown, P extends Record<string, any> = object>
|
|
|
139
139
|
component: any;
|
|
140
140
|
element: Element;
|
|
141
141
|
props: P;
|
|
142
|
-
reactElement:
|
|
142
|
+
reactElement: ReactNode;
|
|
143
143
|
ref: R | null;
|
|
144
144
|
/**
|
|
145
145
|
* Immediately creates element and renders the provided React component.
|
|
@@ -168,9 +168,9 @@ interface MarkViewContextProps {
|
|
|
168
168
|
}
|
|
169
169
|
declare const ReactMarkViewContext: React__default.Context<MarkViewContextProps>;
|
|
170
170
|
type MarkViewContentProps<T extends keyof React__default.JSX.IntrinsicElements = 'span'> = {
|
|
171
|
-
as?:
|
|
172
|
-
} & React__default.ComponentProps<T>;
|
|
173
|
-
declare const MarkViewContent: React__default.
|
|
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
174
|
interface ReactMarkViewRendererOptions extends MarkViewRendererOptions {
|
|
175
175
|
/**
|
|
176
176
|
* The tag name of the element wrapping the React component.
|
|
@@ -191,6 +191,10 @@ declare class ReactMarkView extends MarkView<React__default.ComponentType<MarkVi
|
|
|
191
191
|
}
|
|
192
192
|
declare function ReactMarkViewRenderer(component: React__default.ComponentType<MarkViewProps>, options?: Partial<ReactMarkViewRendererOptions>): MarkViewRenderer;
|
|
193
193
|
|
|
194
|
+
type ReactNodeViewProps<T = HTMLElement> = NodeViewProps & {
|
|
195
|
+
ref: React__default.RefObject<T | null>;
|
|
196
|
+
};
|
|
197
|
+
|
|
194
198
|
interface ReactNodeViewRendererOptions extends NodeViewRendererOptions {
|
|
195
199
|
/**
|
|
196
200
|
* This function is called when the node view is updated.
|
|
@@ -223,15 +227,16 @@ interface ReactNodeViewRendererOptions extends NodeViewRendererOptions {
|
|
|
223
227
|
HTMLAttributes: Record<string, any>;
|
|
224
228
|
}) => Record<string, string>);
|
|
225
229
|
}
|
|
226
|
-
declare class ReactNodeView<Component extends ComponentType$1<
|
|
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> {
|
|
227
231
|
/**
|
|
228
232
|
* The renderer instance.
|
|
229
233
|
*/
|
|
230
|
-
renderer: ReactRenderer<unknown,
|
|
234
|
+
renderer: ReactRenderer<unknown, ReactNodeViewProps<T>>;
|
|
231
235
|
/**
|
|
232
236
|
* The element that holds the rich-text content of the node.
|
|
233
237
|
*/
|
|
234
238
|
contentDOMElement: HTMLElement | null;
|
|
239
|
+
constructor(component: Component, props: NodeViewRendererProps, options?: Partial<Options>);
|
|
235
240
|
/**
|
|
236
241
|
* Setup the React component.
|
|
237
242
|
* Called on initialization.
|
|
@@ -280,7 +285,7 @@ declare class ReactNodeView<Component extends ComponentType$1<NodeViewProps> = C
|
|
|
280
285
|
/**
|
|
281
286
|
* Create a React node view renderer.
|
|
282
287
|
*/
|
|
283
|
-
declare function ReactNodeViewRenderer(component: ComponentType$1<
|
|
288
|
+
declare function ReactNodeViewRenderer<T = HTMLElement>(component: ComponentType$1<ReactNodeViewProps<T>>, options?: Partial<ReactNodeViewRendererOptions>): NodeViewRenderer;
|
|
284
289
|
|
|
285
290
|
type EditorStateSnapshot<TEditor extends Editor | null = Editor | null> = {
|
|
286
291
|
editor: TEditor;
|
|
@@ -342,4 +347,4 @@ declare const ReactNodeViewContentProvider: ({ children, content }: {
|
|
|
342
347
|
}) => React.FunctionComponentElement<React.ProviderProps<ReactNodeViewContextProps>>;
|
|
343
348
|
declare const useReactNodeView: () => ReactNodeViewContextProps;
|
|
344
349
|
|
|
345
|
-
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, ReactNodeViewRenderer, type ReactNodeViewRendererOptions, ReactRenderer, type ReactRendererOptions, type UseEditorOptions, type UseEditorStateOptions, useCurrentEditor, useEditor, useEditorState, useReactNodeView };
|
|
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
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import * as react_jsx_runtime_js from 'react/jsx-runtime.js';
|
|
2
|
-
import { EditorOptions, Editor, MarkViewRendererOptions, MarkView, MarkViewProps, MarkViewRenderer,
|
|
2
|
+
import { EditorOptions, Editor, MarkViewRendererOptions, MarkView, MarkViewProps, MarkViewRenderer, NodeViewProps, NodeViewRendererOptions, NodeView, NodeViewRendererProps, NodeViewRenderer } from '@tiptap/core';
|
|
3
3
|
export * from '@tiptap/core';
|
|
4
4
|
import * as React from 'react';
|
|
5
|
-
import React__default, { DependencyList, ReactNode, HTMLAttributes, HTMLProps, ForwardedRef, ComponentProps, ComponentType as ComponentType$1 } from 'react';
|
|
5
|
+
import React__default, { DependencyList, ReactNode, HTMLAttributes, HTMLProps, ForwardedRef, ComponentProps, ComponentClass, FunctionComponent, ForwardRefExoticComponent, PropsWithoutRef, RefAttributes, ComponentType as ComponentType$1 } from 'react';
|
|
6
6
|
import { Node } from '@tiptap/pm/model';
|
|
7
7
|
import { Decoration, DecorationSource } from '@tiptap/pm/view';
|
|
8
8
|
|
|
@@ -121,7 +121,7 @@ interface ReactRendererOptions {
|
|
|
121
121
|
*/
|
|
122
122
|
className?: string;
|
|
123
123
|
}
|
|
124
|
-
type ComponentType<R, P> =
|
|
124
|
+
type ComponentType<R, P> = ComponentClass<P> | FunctionComponent<P> | ForwardRefExoticComponent<PropsWithoutRef<P> & RefAttributes<R>>;
|
|
125
125
|
/**
|
|
126
126
|
* The ReactRenderer class. It's responsible for rendering React components inside the editor.
|
|
127
127
|
* @example
|
|
@@ -139,7 +139,7 @@ declare class ReactRenderer<R = unknown, P extends Record<string, any> = object>
|
|
|
139
139
|
component: any;
|
|
140
140
|
element: Element;
|
|
141
141
|
props: P;
|
|
142
|
-
reactElement:
|
|
142
|
+
reactElement: ReactNode;
|
|
143
143
|
ref: R | null;
|
|
144
144
|
/**
|
|
145
145
|
* Immediately creates element and renders the provided React component.
|
|
@@ -168,9 +168,9 @@ interface MarkViewContextProps {
|
|
|
168
168
|
}
|
|
169
169
|
declare const ReactMarkViewContext: React__default.Context<MarkViewContextProps>;
|
|
170
170
|
type MarkViewContentProps<T extends keyof React__default.JSX.IntrinsicElements = 'span'> = {
|
|
171
|
-
as?:
|
|
172
|
-
} & React__default.ComponentProps<T>;
|
|
173
|
-
declare const MarkViewContent: React__default.
|
|
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
174
|
interface ReactMarkViewRendererOptions extends MarkViewRendererOptions {
|
|
175
175
|
/**
|
|
176
176
|
* The tag name of the element wrapping the React component.
|
|
@@ -191,6 +191,10 @@ declare class ReactMarkView extends MarkView<React__default.ComponentType<MarkVi
|
|
|
191
191
|
}
|
|
192
192
|
declare function ReactMarkViewRenderer(component: React__default.ComponentType<MarkViewProps>, options?: Partial<ReactMarkViewRendererOptions>): MarkViewRenderer;
|
|
193
193
|
|
|
194
|
+
type ReactNodeViewProps<T = HTMLElement> = NodeViewProps & {
|
|
195
|
+
ref: React__default.RefObject<T | null>;
|
|
196
|
+
};
|
|
197
|
+
|
|
194
198
|
interface ReactNodeViewRendererOptions extends NodeViewRendererOptions {
|
|
195
199
|
/**
|
|
196
200
|
* This function is called when the node view is updated.
|
|
@@ -223,15 +227,16 @@ interface ReactNodeViewRendererOptions extends NodeViewRendererOptions {
|
|
|
223
227
|
HTMLAttributes: Record<string, any>;
|
|
224
228
|
}) => Record<string, string>);
|
|
225
229
|
}
|
|
226
|
-
declare class ReactNodeView<Component extends ComponentType$1<
|
|
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> {
|
|
227
231
|
/**
|
|
228
232
|
* The renderer instance.
|
|
229
233
|
*/
|
|
230
|
-
renderer: ReactRenderer<unknown,
|
|
234
|
+
renderer: ReactRenderer<unknown, ReactNodeViewProps<T>>;
|
|
231
235
|
/**
|
|
232
236
|
* The element that holds the rich-text content of the node.
|
|
233
237
|
*/
|
|
234
238
|
contentDOMElement: HTMLElement | null;
|
|
239
|
+
constructor(component: Component, props: NodeViewRendererProps, options?: Partial<Options>);
|
|
235
240
|
/**
|
|
236
241
|
* Setup the React component.
|
|
237
242
|
* Called on initialization.
|
|
@@ -280,7 +285,7 @@ declare class ReactNodeView<Component extends ComponentType$1<NodeViewProps> = C
|
|
|
280
285
|
/**
|
|
281
286
|
* Create a React node view renderer.
|
|
282
287
|
*/
|
|
283
|
-
declare function ReactNodeViewRenderer(component: ComponentType$1<
|
|
288
|
+
declare function ReactNodeViewRenderer<T = HTMLElement>(component: ComponentType$1<ReactNodeViewProps<T>>, options?: Partial<ReactNodeViewRendererOptions>): NodeViewRenderer;
|
|
284
289
|
|
|
285
290
|
type EditorStateSnapshot<TEditor extends Editor | null = Editor | null> = {
|
|
286
291
|
editor: TEditor;
|
|
@@ -342,4 +347,4 @@ declare const ReactNodeViewContentProvider: ({ children, content }: {
|
|
|
342
347
|
}) => React.FunctionComponentElement<React.ProviderProps<ReactNodeViewContextProps>>;
|
|
343
348
|
declare const useReactNodeView: () => ReactNodeViewContextProps;
|
|
344
349
|
|
|
345
|
-
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, ReactNodeViewRenderer, type ReactNodeViewRendererOptions, ReactRenderer, type ReactRendererOptions, type UseEditorOptions, type UseEditorStateOptions, useCurrentEditor, useEditor, useEditorState, useReactNodeView };
|
|
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.js
CHANGED
|
@@ -120,13 +120,10 @@ var PureEditorContent = class extends React.Component {
|
|
|
120
120
|
return;
|
|
121
121
|
}
|
|
122
122
|
this.initialized = false;
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
});
|
|
128
|
-
}
|
|
129
|
-
} catch {
|
|
123
|
+
if (!editor.isDestroyed) {
|
|
124
|
+
editor.view.setProps({
|
|
125
|
+
nodeViews: {}
|
|
126
|
+
});
|
|
130
127
|
}
|
|
131
128
|
if (this.unsubscribeToContentComponent) {
|
|
132
129
|
this.unsubscribeToContentComponent();
|
|
@@ -169,7 +166,7 @@ import { useDebugValue as useDebugValue2, useEffect as useEffect2, useRef, useSt
|
|
|
169
166
|
import { useSyncExternalStore as useSyncExternalStore2 } from "use-sync-external-store/shim";
|
|
170
167
|
|
|
171
168
|
// src/useEditorState.ts
|
|
172
|
-
import deepEqual from "fast-deep-equal/es6/react";
|
|
169
|
+
import deepEqual from "fast-deep-equal/es6/react.js";
|
|
173
170
|
import { useDebugValue, useEffect, useLayoutEffect, useState } from "react";
|
|
174
171
|
import { useSyncExternalStoreWithSelector } from "use-sync-external-store/shim/with-selector";
|
|
175
172
|
var useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect;
|
|
@@ -618,14 +615,41 @@ import { MarkView } from "@tiptap/core";
|
|
|
618
615
|
import React4 from "react";
|
|
619
616
|
|
|
620
617
|
// src/ReactRenderer.tsx
|
|
621
|
-
import {
|
|
618
|
+
import { version as reactVersion } from "react";
|
|
622
619
|
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
623
620
|
function isClassComponent(Component) {
|
|
624
621
|
return !!(typeof Component === "function" && Component.prototype && Component.prototype.isReactComponent);
|
|
625
622
|
}
|
|
626
623
|
function isForwardRefComponent(Component) {
|
|
627
|
-
|
|
628
|
-
|
|
624
|
+
return !!(typeof Component === "object" && Component.$$typeof && (Component.$$typeof.toString() === "Symbol(react.forward_ref)" || Component.$$typeof.description === "react.forward_ref"));
|
|
625
|
+
}
|
|
626
|
+
function isMemoComponent(Component) {
|
|
627
|
+
return !!(typeof Component === "object" && Component.$$typeof && (Component.$$typeof.toString() === "Symbol(react.memo)" || Component.$$typeof.description === "react.memo"));
|
|
628
|
+
}
|
|
629
|
+
function canReceiveRef(Component) {
|
|
630
|
+
if (isClassComponent(Component)) {
|
|
631
|
+
return true;
|
|
632
|
+
}
|
|
633
|
+
if (isForwardRefComponent(Component)) {
|
|
634
|
+
return true;
|
|
635
|
+
}
|
|
636
|
+
if (isMemoComponent(Component)) {
|
|
637
|
+
const wrappedComponent = Component.type;
|
|
638
|
+
if (wrappedComponent) {
|
|
639
|
+
return isClassComponent(wrappedComponent) || isForwardRefComponent(wrappedComponent);
|
|
640
|
+
}
|
|
641
|
+
}
|
|
642
|
+
return false;
|
|
643
|
+
}
|
|
644
|
+
function isReact19Plus() {
|
|
645
|
+
try {
|
|
646
|
+
if (reactVersion) {
|
|
647
|
+
const majorVersion = parseInt(reactVersion.split(".")[0], 10);
|
|
648
|
+
return majorVersion >= 19;
|
|
649
|
+
}
|
|
650
|
+
} catch {
|
|
651
|
+
}
|
|
652
|
+
return false;
|
|
629
653
|
}
|
|
630
654
|
var ReactRenderer = class {
|
|
631
655
|
/**
|
|
@@ -642,13 +666,9 @@ var ReactRenderer = class {
|
|
|
642
666
|
if (className) {
|
|
643
667
|
this.element.classList.add(...className.split(" "));
|
|
644
668
|
}
|
|
645
|
-
|
|
646
|
-
flushSync(() => {
|
|
647
|
-
this.render();
|
|
648
|
-
});
|
|
649
|
-
} else {
|
|
669
|
+
queueMicrotask(() => {
|
|
650
670
|
this.render();
|
|
651
|
-
}
|
|
671
|
+
});
|
|
652
672
|
}
|
|
653
673
|
/**
|
|
654
674
|
* Render the React component.
|
|
@@ -658,12 +678,18 @@ var ReactRenderer = class {
|
|
|
658
678
|
const Component = this.component;
|
|
659
679
|
const props = this.props;
|
|
660
680
|
const editor = this.editor;
|
|
661
|
-
|
|
662
|
-
|
|
681
|
+
const isReact19 = isReact19Plus();
|
|
682
|
+
const componentCanReceiveRef = canReceiveRef(Component);
|
|
683
|
+
const elementProps = { ...props };
|
|
684
|
+
if (elementProps.ref && !(isReact19 || componentCanReceiveRef)) {
|
|
685
|
+
delete elementProps.ref;
|
|
686
|
+
}
|
|
687
|
+
if (!elementProps.ref && (isReact19 || componentCanReceiveRef)) {
|
|
688
|
+
elementProps.ref = (ref) => {
|
|
663
689
|
this.ref = ref;
|
|
664
690
|
};
|
|
665
691
|
}
|
|
666
|
-
this.reactElement = /* @__PURE__ */ jsx5(Component, { ...
|
|
692
|
+
this.reactElement = /* @__PURE__ */ jsx5(Component, { ...elementProps });
|
|
667
693
|
(_a = editor == null ? void 0 : editor.contentComponent) == null ? void 0 : _a.setRenderer(this.id, this);
|
|
668
694
|
}
|
|
669
695
|
/**
|
|
@@ -701,11 +727,11 @@ var ReactMarkViewContext = React4.createContext({
|
|
|
701
727
|
}
|
|
702
728
|
});
|
|
703
729
|
var MarkViewContent = (props) => {
|
|
704
|
-
const Tag =
|
|
730
|
+
const { as: Tag = "span", ...rest } = props;
|
|
705
731
|
const { markViewContentRef } = React4.useContext(ReactMarkViewContext);
|
|
706
732
|
return (
|
|
707
733
|
// @ts-ignore
|
|
708
|
-
/* @__PURE__ */ jsx6(Tag, { ...
|
|
734
|
+
/* @__PURE__ */ jsx6(Tag, { ...rest, ref: markViewContentRef, "data-mark-view-content": "" })
|
|
709
735
|
);
|
|
710
736
|
};
|
|
711
737
|
var ReactMarkView = class extends MarkView {
|
|
@@ -754,9 +780,23 @@ function ReactMarkViewRenderer(component, options = {}) {
|
|
|
754
780
|
|
|
755
781
|
// src/ReactNodeViewRenderer.tsx
|
|
756
782
|
import { getRenderedAttributes, NodeView } from "@tiptap/core";
|
|
757
|
-
import
|
|
783
|
+
import { createElement as createElement2, createRef, memo } from "react";
|
|
758
784
|
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
759
785
|
var ReactNodeView = class extends NodeView {
|
|
786
|
+
constructor(component, props, options) {
|
|
787
|
+
super(component, props, options);
|
|
788
|
+
if (!this.node.isLeaf) {
|
|
789
|
+
if (this.options.contentDOMElementTag) {
|
|
790
|
+
this.contentDOMElement = document.createElement(this.options.contentDOMElementTag);
|
|
791
|
+
} else {
|
|
792
|
+
this.contentDOMElement = document.createElement(this.node.isInline ? "span" : "div");
|
|
793
|
+
}
|
|
794
|
+
this.contentDOMElement.dataset.nodeViewContentReact = "";
|
|
795
|
+
this.contentDOMElement.dataset.nodeViewWrapper = "";
|
|
796
|
+
this.contentDOMElement.style.whiteSpace = "inherit";
|
|
797
|
+
this.dom.appendChild(this.contentDOMElement);
|
|
798
|
+
}
|
|
799
|
+
}
|
|
760
800
|
/**
|
|
761
801
|
* Setup the React component.
|
|
762
802
|
* Called on initialization.
|
|
@@ -773,7 +813,8 @@ var ReactNodeView = class extends NodeView {
|
|
|
773
813
|
HTMLAttributes: this.HTMLAttributes,
|
|
774
814
|
getPos: () => this.getPos(),
|
|
775
815
|
updateAttributes: (attributes = {}) => this.updateAttributes(attributes),
|
|
776
|
-
deleteNode: () => this.deleteNode()
|
|
816
|
+
deleteNode: () => this.deleteNode(),
|
|
817
|
+
ref: createRef()
|
|
777
818
|
};
|
|
778
819
|
if (!this.component.displayName) {
|
|
779
820
|
const capitalizeFirstChar = (string) => {
|
|
@@ -784,26 +825,18 @@ var ReactNodeView = class extends NodeView {
|
|
|
784
825
|
const onDragStart = this.onDragStart.bind(this);
|
|
785
826
|
const nodeViewContentRef = (element) => {
|
|
786
827
|
if (element && this.contentDOMElement && element.firstChild !== this.contentDOMElement) {
|
|
828
|
+
if (element.hasAttribute("data-node-view-wrapper")) {
|
|
829
|
+
element.removeAttribute("data-node-view-wrapper");
|
|
830
|
+
}
|
|
787
831
|
element.appendChild(this.contentDOMElement);
|
|
788
832
|
}
|
|
789
833
|
};
|
|
790
834
|
const context = { onDragStart, nodeViewContentRef };
|
|
791
835
|
const Component = this.component;
|
|
792
|
-
const ReactNodeViewProvider =
|
|
793
|
-
return /* @__PURE__ */ jsx7(ReactNodeViewContext.Provider, { value: context, children:
|
|
836
|
+
const ReactNodeViewProvider = memo((componentProps) => {
|
|
837
|
+
return /* @__PURE__ */ jsx7(ReactNodeViewContext.Provider, { value: context, children: createElement2(Component, componentProps) });
|
|
794
838
|
});
|
|
795
839
|
ReactNodeViewProvider.displayName = "ReactNodeView";
|
|
796
|
-
if (this.node.isLeaf) {
|
|
797
|
-
this.contentDOMElement = null;
|
|
798
|
-
} else if (this.options.contentDOMElementTag) {
|
|
799
|
-
this.contentDOMElement = document.createElement(this.options.contentDOMElementTag);
|
|
800
|
-
} else {
|
|
801
|
-
this.contentDOMElement = document.createElement(this.node.isInline ? "span" : "div");
|
|
802
|
-
}
|
|
803
|
-
if (this.contentDOMElement) {
|
|
804
|
-
this.contentDOMElement.dataset.nodeViewContentReact = "";
|
|
805
|
-
this.contentDOMElement.style.whiteSpace = "inherit";
|
|
806
|
-
}
|
|
807
840
|
let as = this.node.isInline ? "span" : "div";
|
|
808
841
|
if (this.options.as) {
|
|
809
842
|
as = this.options.as;
|