@tiptap/react 3.0.0-next.8 → 3.0.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.
- package/dist/index.cjs +80 -33
- 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 +75 -28
- package/dist/index.js.map +1 -1
- package/package.json +10 -10
- package/src/EditorContent.tsx +1 -1
- package/src/ReactMarkViewRenderer.tsx +8 -6
- package/src/ReactNodeViewRenderer.tsx +52 -27
- package/src/ReactRenderer.tsx +104 -13
- package/src/index.ts +1 -0
- package/src/types.ts +6 -0
- package/src/useEditor.ts +1 -1
- package/src/useEditorState.ts +2 -2
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
|
@@ -4,7 +4,7 @@ import { createContext, useContext, useMemo } from "react";
|
|
|
4
4
|
// src/EditorContent.tsx
|
|
5
5
|
import React, { forwardRef } from "react";
|
|
6
6
|
import ReactDOM from "react-dom";
|
|
7
|
-
import { useSyncExternalStore } from "use-sync-external-store/shim";
|
|
7
|
+
import { useSyncExternalStore } from "use-sync-external-store/shim/index.js";
|
|
8
8
|
import { Fragment, jsx, jsxs } from "react/jsx-runtime";
|
|
9
9
|
var mergeRefs = (...refs) => {
|
|
10
10
|
return (node) => {
|
|
@@ -163,12 +163,12 @@ var EditorContent = React.memo(EditorContentWithKey);
|
|
|
163
163
|
// src/useEditor.ts
|
|
164
164
|
import { Editor } from "@tiptap/core";
|
|
165
165
|
import { useDebugValue as useDebugValue2, useEffect as useEffect2, useRef, useState as useState2 } from "react";
|
|
166
|
-
import { useSyncExternalStore as useSyncExternalStore2 } from "use-sync-external-store/shim";
|
|
166
|
+
import { useSyncExternalStore as useSyncExternalStore2 } from "use-sync-external-store/shim/index.js";
|
|
167
167
|
|
|
168
168
|
// src/useEditorState.ts
|
|
169
|
-
import deepEqual from "fast-deep-equal/es6/react";
|
|
169
|
+
import deepEqual from "fast-deep-equal/es6/react.js";
|
|
170
170
|
import { useDebugValue, useEffect, useLayoutEffect, useState } from "react";
|
|
171
|
-
import { useSyncExternalStoreWithSelector } from "use-sync-external-store/shim/with-selector";
|
|
171
|
+
import { useSyncExternalStoreWithSelector } from "use-sync-external-store/shim/with-selector.js";
|
|
172
172
|
var useIsomorphicLayoutEffect = typeof window !== "undefined" ? useLayoutEffect : useEffect;
|
|
173
173
|
var EditorStateManager = class {
|
|
174
174
|
constructor(initialEditor) {
|
|
@@ -615,14 +615,42 @@ import { MarkView } from "@tiptap/core";
|
|
|
615
615
|
import React4 from "react";
|
|
616
616
|
|
|
617
617
|
// src/ReactRenderer.tsx
|
|
618
|
+
import { version as reactVersion } from "react";
|
|
618
619
|
import { flushSync } from "react-dom";
|
|
619
620
|
import { jsx as jsx5 } from "react/jsx-runtime";
|
|
620
621
|
function isClassComponent(Component) {
|
|
621
622
|
return !!(typeof Component === "function" && Component.prototype && Component.prototype.isReactComponent);
|
|
622
623
|
}
|
|
623
624
|
function isForwardRefComponent(Component) {
|
|
624
|
-
|
|
625
|
-
|
|
625
|
+
return !!(typeof Component === "object" && Component.$$typeof && (Component.$$typeof.toString() === "Symbol(react.forward_ref)" || Component.$$typeof.description === "react.forward_ref"));
|
|
626
|
+
}
|
|
627
|
+
function isMemoComponent(Component) {
|
|
628
|
+
return !!(typeof Component === "object" && Component.$$typeof && (Component.$$typeof.toString() === "Symbol(react.memo)" || Component.$$typeof.description === "react.memo"));
|
|
629
|
+
}
|
|
630
|
+
function canReceiveRef(Component) {
|
|
631
|
+
if (isClassComponent(Component)) {
|
|
632
|
+
return true;
|
|
633
|
+
}
|
|
634
|
+
if (isForwardRefComponent(Component)) {
|
|
635
|
+
return true;
|
|
636
|
+
}
|
|
637
|
+
if (isMemoComponent(Component)) {
|
|
638
|
+
const wrappedComponent = Component.type;
|
|
639
|
+
if (wrappedComponent) {
|
|
640
|
+
return isClassComponent(wrappedComponent) || isForwardRefComponent(wrappedComponent);
|
|
641
|
+
}
|
|
642
|
+
}
|
|
643
|
+
return false;
|
|
644
|
+
}
|
|
645
|
+
function isReact19Plus() {
|
|
646
|
+
try {
|
|
647
|
+
if (reactVersion) {
|
|
648
|
+
const majorVersion = parseInt(reactVersion.split(".")[0], 10);
|
|
649
|
+
return majorVersion >= 19;
|
|
650
|
+
}
|
|
651
|
+
} catch {
|
|
652
|
+
}
|
|
653
|
+
return false;
|
|
626
654
|
}
|
|
627
655
|
var ReactRenderer = class {
|
|
628
656
|
/**
|
|
@@ -644,7 +672,9 @@ var ReactRenderer = class {
|
|
|
644
672
|
this.render();
|
|
645
673
|
});
|
|
646
674
|
} else {
|
|
647
|
-
|
|
675
|
+
queueMicrotask(() => {
|
|
676
|
+
this.render();
|
|
677
|
+
});
|
|
648
678
|
}
|
|
649
679
|
}
|
|
650
680
|
/**
|
|
@@ -655,12 +685,18 @@ var ReactRenderer = class {
|
|
|
655
685
|
const Component = this.component;
|
|
656
686
|
const props = this.props;
|
|
657
687
|
const editor = this.editor;
|
|
658
|
-
|
|
659
|
-
|
|
688
|
+
const isReact19 = isReact19Plus();
|
|
689
|
+
const componentCanReceiveRef = canReceiveRef(Component);
|
|
690
|
+
const elementProps = { ...props };
|
|
691
|
+
if (elementProps.ref && !(isReact19 || componentCanReceiveRef)) {
|
|
692
|
+
delete elementProps.ref;
|
|
693
|
+
}
|
|
694
|
+
if (!elementProps.ref && (isReact19 || componentCanReceiveRef)) {
|
|
695
|
+
elementProps.ref = (ref) => {
|
|
660
696
|
this.ref = ref;
|
|
661
697
|
};
|
|
662
698
|
}
|
|
663
|
-
this.reactElement = /* @__PURE__ */ jsx5(Component, { ...
|
|
699
|
+
this.reactElement = /* @__PURE__ */ jsx5(Component, { ...elementProps });
|
|
664
700
|
(_a = editor == null ? void 0 : editor.contentComponent) == null ? void 0 : _a.setRenderer(this.id, this);
|
|
665
701
|
}
|
|
666
702
|
/**
|
|
@@ -698,11 +734,11 @@ var ReactMarkViewContext = React4.createContext({
|
|
|
698
734
|
}
|
|
699
735
|
});
|
|
700
736
|
var MarkViewContent = (props) => {
|
|
701
|
-
const Tag =
|
|
737
|
+
const { as: Tag = "span", ...rest } = props;
|
|
702
738
|
const { markViewContentRef } = React4.useContext(ReactMarkViewContext);
|
|
703
739
|
return (
|
|
704
740
|
// @ts-ignore
|
|
705
|
-
/* @__PURE__ */ jsx6(Tag, { ...
|
|
741
|
+
/* @__PURE__ */ jsx6(Tag, { ...rest, ref: markViewContentRef, "data-mark-view-content": "" })
|
|
706
742
|
);
|
|
707
743
|
};
|
|
708
744
|
var ReactMarkView = class extends MarkView {
|
|
@@ -710,7 +746,7 @@ var ReactMarkView = class extends MarkView {
|
|
|
710
746
|
super(component, props, options);
|
|
711
747
|
this.didMountContentDomElement = false;
|
|
712
748
|
const { as = "span", attrs, className = "" } = options || {};
|
|
713
|
-
const componentProps = props;
|
|
749
|
+
const componentProps = { ...props, updateAttributes: this.updateAttributes.bind(this) };
|
|
714
750
|
this.contentDOMElement = document.createElement("span");
|
|
715
751
|
const markViewContentRef = (el) => {
|
|
716
752
|
if (el && this.contentDOMElement && el.firstChild !== this.contentDOMElement) {
|
|
@@ -751,9 +787,27 @@ function ReactMarkViewRenderer(component, options = {}) {
|
|
|
751
787
|
|
|
752
788
|
// src/ReactNodeViewRenderer.tsx
|
|
753
789
|
import { getRenderedAttributes, NodeView } from "@tiptap/core";
|
|
754
|
-
import
|
|
790
|
+
import { createElement as createElement2, createRef, memo } from "react";
|
|
755
791
|
import { jsx as jsx7 } from "react/jsx-runtime";
|
|
756
792
|
var ReactNodeView = class extends NodeView {
|
|
793
|
+
constructor(component, props, options) {
|
|
794
|
+
super(component, props, options);
|
|
795
|
+
if (!this.node.isLeaf) {
|
|
796
|
+
if (this.options.contentDOMElementTag) {
|
|
797
|
+
this.contentDOMElement = document.createElement(this.options.contentDOMElementTag);
|
|
798
|
+
} else {
|
|
799
|
+
this.contentDOMElement = document.createElement(this.node.isInline ? "span" : "div");
|
|
800
|
+
}
|
|
801
|
+
this.contentDOMElement.dataset.nodeViewContentReact = "";
|
|
802
|
+
this.contentDOMElement.dataset.nodeViewWrapper = "";
|
|
803
|
+
this.contentDOMElement.style.whiteSpace = "inherit";
|
|
804
|
+
const contentTarget = this.dom.querySelector("[data-node-view-content]");
|
|
805
|
+
if (!contentTarget) {
|
|
806
|
+
return;
|
|
807
|
+
}
|
|
808
|
+
contentTarget.appendChild(this.contentDOMElement);
|
|
809
|
+
}
|
|
810
|
+
}
|
|
757
811
|
/**
|
|
758
812
|
* Setup the React component.
|
|
759
813
|
* Called on initialization.
|
|
@@ -770,7 +824,8 @@ var ReactNodeView = class extends NodeView {
|
|
|
770
824
|
HTMLAttributes: this.HTMLAttributes,
|
|
771
825
|
getPos: () => this.getPos(),
|
|
772
826
|
updateAttributes: (attributes = {}) => this.updateAttributes(attributes),
|
|
773
|
-
deleteNode: () => this.deleteNode()
|
|
827
|
+
deleteNode: () => this.deleteNode(),
|
|
828
|
+
ref: createRef()
|
|
774
829
|
};
|
|
775
830
|
if (!this.component.displayName) {
|
|
776
831
|
const capitalizeFirstChar = (string) => {
|
|
@@ -781,26 +836,18 @@ var ReactNodeView = class extends NodeView {
|
|
|
781
836
|
const onDragStart = this.onDragStart.bind(this);
|
|
782
837
|
const nodeViewContentRef = (element) => {
|
|
783
838
|
if (element && this.contentDOMElement && element.firstChild !== this.contentDOMElement) {
|
|
839
|
+
if (element.hasAttribute("data-node-view-wrapper")) {
|
|
840
|
+
element.removeAttribute("data-node-view-wrapper");
|
|
841
|
+
}
|
|
784
842
|
element.appendChild(this.contentDOMElement);
|
|
785
843
|
}
|
|
786
844
|
};
|
|
787
845
|
const context = { onDragStart, nodeViewContentRef };
|
|
788
846
|
const Component = this.component;
|
|
789
|
-
const ReactNodeViewProvider =
|
|
790
|
-
return /* @__PURE__ */ jsx7(ReactNodeViewContext.Provider, { value: context, children:
|
|
847
|
+
const ReactNodeViewProvider = memo((componentProps) => {
|
|
848
|
+
return /* @__PURE__ */ jsx7(ReactNodeViewContext.Provider, { value: context, children: createElement2(Component, componentProps) });
|
|
791
849
|
});
|
|
792
850
|
ReactNodeViewProvider.displayName = "ReactNodeView";
|
|
793
|
-
if (this.node.isLeaf) {
|
|
794
|
-
this.contentDOMElement = null;
|
|
795
|
-
} else if (this.options.contentDOMElementTag) {
|
|
796
|
-
this.contentDOMElement = document.createElement(this.options.contentDOMElementTag);
|
|
797
|
-
} else {
|
|
798
|
-
this.contentDOMElement = document.createElement(this.node.isInline ? "span" : "div");
|
|
799
|
-
}
|
|
800
|
-
if (this.contentDOMElement) {
|
|
801
|
-
this.contentDOMElement.dataset.nodeViewContentReact = "";
|
|
802
|
-
this.contentDOMElement.style.whiteSpace = "inherit";
|
|
803
|
-
}
|
|
804
851
|
let as = this.node.isInline ? "span" : "div";
|
|
805
852
|
if (this.options.as) {
|
|
806
853
|
as = this.options.as;
|