@tiptap/react 2.11.9 → 2.13.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/dist/EditorContent.d.ts +1 -1
- package/dist/EditorContent.d.ts.map +1 -1
- package/dist/ReactNodeViewRenderer.d.ts +9 -7
- package/dist/ReactNodeViewRenderer.d.ts.map +1 -1
- package/dist/ReactRenderer.d.ts +4 -4
- package/dist/ReactRenderer.d.ts.map +1 -1
- package/dist/index.cjs +46 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +47 -9
- package/dist/index.js.map +1 -1
- package/dist/index.umd.js +44 -6
- package/dist/index.umd.js.map +1 -1
- package/dist/types.d.ts +6 -0
- package/dist/types.d.ts.map +1 -0
- package/package.json +9 -9
- package/src/ReactNodeViewRenderer.tsx +25 -27
- package/src/ReactRenderer.tsx +58 -11
- package/src/index.ts +1 -0
- package/src/types.ts +6 -0
package/dist/EditorContent.d.ts
CHANGED
|
@@ -17,5 +17,5 @@ export declare class PureEditorContent extends React.Component<EditorContentProp
|
|
|
17
17
|
componentWillUnmount(): void;
|
|
18
18
|
render(): React.JSX.Element;
|
|
19
19
|
}
|
|
20
|
-
export declare const EditorContent: React.
|
|
20
|
+
export declare const EditorContent: React.NamedExoticComponent<Omit<EditorContentProps, "ref"> & React.RefAttributes<HTMLDivElement>>;
|
|
21
21
|
//# sourceMappingURL=EditorContent.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"EditorContent.d.ts","sourceRoot":"","sources":["../src/EditorContent.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AACrC,OAAO,KAAK,EAAE,EACZ,YAAY,EAAc,SAAS,EACpC,MAAM,OAAO,CAAA;AA0Cd,MAAM,WAAW,kBAAmB,SAAQ,SAAS,CAAC,cAAc,CAAC;IACnE,MAAM,EAA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AAmBD,eAAO,MAAM,aAAa,mGAAmC,CAAA"}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
-
import { Editor,
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
1
|
+
import type { Editor, NodeViewRenderer, NodeViewRendererOptions } from '@tiptap/core';
|
|
2
|
+
import { NodeView } from '@tiptap/core';
|
|
3
|
+
import type { Node, Node as ProseMirrorNode } from '@tiptap/pm/model';
|
|
4
|
+
import type { Decoration, DecorationSource } from '@tiptap/pm/view';
|
|
5
|
+
import type { ComponentType } from 'react';
|
|
5
6
|
import { ReactRenderer } from './ReactRenderer.js';
|
|
7
|
+
import type { ReactNodeViewProps } from './types.js';
|
|
6
8
|
export interface ReactNodeViewRendererOptions extends NodeViewRendererOptions {
|
|
7
9
|
/**
|
|
8
10
|
* This function is called when the node view is updated.
|
|
@@ -35,11 +37,11 @@ export interface ReactNodeViewRendererOptions extends NodeViewRendererOptions {
|
|
|
35
37
|
HTMLAttributes: Record<string, any>;
|
|
36
38
|
}) => Record<string, string>);
|
|
37
39
|
}
|
|
38
|
-
export declare class ReactNodeView<Component extends ComponentType<
|
|
40
|
+
export declare class ReactNodeView<T = HTMLElement, Component extends ComponentType<ReactNodeViewProps<T>> = ComponentType<ReactNodeViewProps<T>>, NodeEditor extends Editor = Editor, Options extends ReactNodeViewRendererOptions = ReactNodeViewRendererOptions> extends NodeView<Component, NodeEditor, Options> {
|
|
39
41
|
/**
|
|
40
42
|
* The renderer instance.
|
|
41
43
|
*/
|
|
42
|
-
renderer: ReactRenderer<unknown,
|
|
44
|
+
renderer: ReactRenderer<unknown, ReactNodeViewProps<T>>;
|
|
43
45
|
/**
|
|
44
46
|
* The element that holds the rich-text content of the node.
|
|
45
47
|
*/
|
|
@@ -92,5 +94,5 @@ export declare class ReactNodeView<Component extends ComponentType<NodeViewProps
|
|
|
92
94
|
/**
|
|
93
95
|
* Create a React node view renderer.
|
|
94
96
|
*/
|
|
95
|
-
export declare function ReactNodeViewRenderer(component: ComponentType<
|
|
97
|
+
export declare function ReactNodeViewRenderer<T = HTMLElement>(component: ComponentType<ReactNodeViewProps<T>>, options?: Partial<ReactNodeViewRendererOptions>): NodeViewRenderer;
|
|
96
98
|
//# sourceMappingURL=ReactNodeViewRenderer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReactNodeViewRenderer.d.ts","sourceRoot":"","sources":["../src/ReactNodeViewRenderer.tsx"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"ReactNodeViewRenderer.d.ts","sourceRoot":"","sources":["../src/ReactNodeViewRenderer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACU,MAAM,EAAE,gBAAgB,EAAE,uBAAuB,EACtE,MAAM,cAAc,CAAA;AACrB,OAAO,EAAyB,QAAQ,EAAE,MAAM,cAAc,CAAA;AAC9D,OAAO,KAAK,EAAE,IAAI,EAAE,IAAI,IAAI,eAAe,EAAE,MAAM,kBAAkB,CAAA;AACrE,OAAO,KAAK,EAAE,UAAU,EAAE,gBAAgB,EAAmC,MAAM,iBAAiB,CAAA;AACpG,OAAO,KAAK,EAAE,aAAa,EAAwB,MAAM,OAAO,CAAA;AAIhE,OAAO,EAAE,aAAa,EAAE,MAAM,oBAAoB,CAAA;AAClD,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAA;AAIpD,MAAM,WAAW,4BAA6B,SAAQ,uBAAuB;IAC3E;;;OAGG;IACH,MAAM,EACF,CAAC,CAAC,KAAK,EAAE;QACP,OAAO,EAAE,eAAe,CAAC;QACzB,cAAc,EAAE,SAAS,UAAU,EAAE,CAAC;QACtC,mBAAmB,EAAE,gBAAgB,CAAC;QACtC,OAAO,EAAE,eAAe,CAAC;QACzB,cAAc,EAAE,SAAS,UAAU,EAAE,CAAC;QACtC,gBAAgB,EAAE,gBAAgB,CAAC;QACnC,WAAW,EAAE,MAAM,IAAI,CAAC;KACzB,KAAK,OAA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gB,qBAAqB,CAAC,CAAC,GAAG,WAAW,EACnD,SAAS,EAAE,aAAa,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,EAC/C,OAAO,CAAC,EAAE,OAAO,CAAC,4BAA4B,CAAC,GAC9C,gBAAgB,CAWlB"}
|
package/dist/ReactRenderer.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Editor } from '@tiptap/core';
|
|
2
|
-
import
|
|
1
|
+
import type { Editor } from '@tiptap/core';
|
|
2
|
+
import type { ComponentClass, ForwardRefExoticComponent, FunctionComponent, PropsWithoutRef, ReactNode, RefAttributes } from 'react';
|
|
3
3
|
export interface ReactRendererOptions {
|
|
4
4
|
/**
|
|
5
5
|
* The editor instance.
|
|
@@ -26,7 +26,7 @@ export interface ReactRendererOptions {
|
|
|
26
26
|
*/
|
|
27
27
|
className?: string;
|
|
28
28
|
}
|
|
29
|
-
type ComponentType<R, P> =
|
|
29
|
+
type ComponentType<R, P> = ComponentClass<P> | FunctionComponent<P> | ForwardRefExoticComponent<PropsWithoutRef<P> & RefAttributes<R>>;
|
|
30
30
|
/**
|
|
31
31
|
* The ReactRenderer class. It's responsible for rendering React components inside the editor.
|
|
32
32
|
* @example
|
|
@@ -44,7 +44,7 @@ export declare class ReactRenderer<R = unknown, P extends Record<string, any> =
|
|
|
44
44
|
component: any;
|
|
45
45
|
element: Element;
|
|
46
46
|
props: P;
|
|
47
|
-
reactElement:
|
|
47
|
+
reactElement: ReactNode;
|
|
48
48
|
ref: R | null;
|
|
49
49
|
/**
|
|
50
50
|
* Immediately creates element and renders the provided React component.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ReactRenderer.d.ts","sourceRoot":"","sources":["../src/ReactRenderer.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"ReactRenderer.d.ts","sourceRoot":"","sources":["../src/ReactRenderer.tsx"],"names":[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GAAG,CAAM,GAAG,IAAI;IASlD;;OAEG;IACH,OAAO,IAAI,IAAI;IAMf;;OAEG;IACH,gBAAgB,CAAC,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,GAAG,IAAI;CAK3D"}
|
package/dist/index.cjs
CHANGED
|
@@ -1218,6 +1218,26 @@ function isForwardRefComponent(Component) {
|
|
|
1218
1218
|
return !!(typeof Component === 'object'
|
|
1219
1219
|
&& ((_a = Component.$$typeof) === null || _a === void 0 ? void 0 : _a.toString()) === 'Symbol(react.forward_ref)');
|
|
1220
1220
|
}
|
|
1221
|
+
/**
|
|
1222
|
+
* Check if we're running React 19+ by detecting if function components support ref props
|
|
1223
|
+
* @returns {boolean}
|
|
1224
|
+
*/
|
|
1225
|
+
function isReact19Plus() {
|
|
1226
|
+
// React 19 is detected by checking React version if available
|
|
1227
|
+
// In practice, we'll use a more conservative approach and assume React 18 behavior
|
|
1228
|
+
// unless we can definitively detect React 19
|
|
1229
|
+
try {
|
|
1230
|
+
// @ts-ignore
|
|
1231
|
+
if (React.version) {
|
|
1232
|
+
const majorVersion = parseInt(React.version.split('.')[0], 10);
|
|
1233
|
+
return majorVersion >= 19;
|
|
1234
|
+
}
|
|
1235
|
+
}
|
|
1236
|
+
catch {
|
|
1237
|
+
// Fallback to React 18 behavior if we can't determine version
|
|
1238
|
+
}
|
|
1239
|
+
return false;
|
|
1240
|
+
}
|
|
1221
1241
|
/**
|
|
1222
1242
|
* The ReactRenderer class. It's responsible for rendering React components inside the editor.
|
|
1223
1243
|
* @example
|
|
@@ -1263,13 +1283,30 @@ class ReactRenderer {
|
|
|
1263
1283
|
const Component = this.component;
|
|
1264
1284
|
const props = this.props;
|
|
1265
1285
|
const editor = this.editor;
|
|
1266
|
-
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1286
|
+
// Handle ref forwarding with React 18/19 compatibility
|
|
1287
|
+
const isReact19 = isReact19Plus();
|
|
1288
|
+
const isClassComp = isClassComponent(Component);
|
|
1289
|
+
const isForwardRefComp = isForwardRefComponent(Component);
|
|
1290
|
+
const elementProps = { ...props };
|
|
1291
|
+
if (!elementProps.ref) {
|
|
1292
|
+
if (isReact19) {
|
|
1293
|
+
// React 19: ref is a standard prop for all components
|
|
1294
|
+
// @ts-ignore - Setting ref prop for React 19 compatibility
|
|
1295
|
+
elementProps.ref = (ref) => {
|
|
1296
|
+
this.ref = ref;
|
|
1297
|
+
};
|
|
1298
|
+
}
|
|
1299
|
+
else if (isClassComp || isForwardRefComp) {
|
|
1300
|
+
// React 18 and prior: only set ref for class components and forwardRef components
|
|
1301
|
+
// @ts-ignore - Setting ref prop for React 18 class/forwardRef components
|
|
1302
|
+
elementProps.ref = (ref) => {
|
|
1303
|
+
this.ref = ref;
|
|
1304
|
+
};
|
|
1305
|
+
}
|
|
1306
|
+
// For function components in React 18, we can't use ref - the component won't receive it
|
|
1307
|
+
// This is a limitation we have to accept for React 18 function components without forwardRef
|
|
1271
1308
|
}
|
|
1272
|
-
this.reactElement = React__default.default.createElement(Component, { ...
|
|
1309
|
+
this.reactElement = React__default.default.createElement(Component, { ...elementProps });
|
|
1273
1310
|
(_a = editor === null || editor === void 0 ? void 0 : editor.contentComponent) === null || _a === void 0 ? void 0 : _a.setRenderer(this.id, this);
|
|
1274
1311
|
}
|
|
1275
1312
|
/**
|
|
@@ -1318,6 +1355,7 @@ class ReactNodeView extends core.NodeView {
|
|
|
1318
1355
|
getPos: () => this.getPos(),
|
|
1319
1356
|
updateAttributes: (attributes = {}) => this.updateAttributes(attributes),
|
|
1320
1357
|
deleteNode: () => this.deleteNode(),
|
|
1358
|
+
ref: React.createRef(),
|
|
1321
1359
|
};
|
|
1322
1360
|
if (!this.component.displayName) {
|
|
1323
1361
|
const capitalizeFirstChar = (string) => {
|
|
@@ -1335,8 +1373,8 @@ class ReactNodeView extends core.NodeView {
|
|
|
1335
1373
|
const Component = this.component;
|
|
1336
1374
|
// For performance reasons, we memoize the provider component
|
|
1337
1375
|
// And all of the things it requires are declared outside of the component, so it doesn't need to re-render
|
|
1338
|
-
const ReactNodeViewProvider =
|
|
1339
|
-
return (React__default.default.createElement(ReactNodeViewContext.Provider, { value: context },
|
|
1376
|
+
const ReactNodeViewProvider = React.memo(componentProps => {
|
|
1377
|
+
return (React__default.default.createElement(ReactNodeViewContext.Provider, { value: context }, React.createElement(Component, componentProps)));
|
|
1340
1378
|
});
|
|
1341
1379
|
ReactNodeViewProvider.displayName = 'ReactNodeView';
|
|
1342
1380
|
if (this.node.isLeaf) {
|