@tiptap/react 2.14.0 → 2.22.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.
@@ -1 +1 @@
1
- {"version":3,"file":"ReactRenderer.d.ts","sourceRoot":"","sources":["../src/ReactRenderer.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,cAAc,CAAA;AAC1C,OAAO,KAAK,EACV,cAAc,EACd,yBAAyB,EACzB,iBAAiB,EACjB,eAAe,EACf,SAAS,EACT,aAAa,EACd,MAAM,OAAO,CAAA;AAoDd,MAAM,WAAW,oBAAoB;IACnC;;;OAGG;IACH,MAAM,EAAE,MAAM,CAAC;IAEf;;;;OAIG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAE5B;;;;OAIG;IACH,EAAE,CAAC,EAAE,MAAM,CAAC;IAEZ;;;;;OAKG;IACH,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,KAAK,aAAa,CAAC,CAAC,EAAE,CAAC,IACnB,cAAc,CAAC,CAAC,CAAC,GACjB,iBAAiB,CAAC,CAAC,CAAC,GACpB,yBAAyB,CAAC,eAAe,CAAC,CAAC,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC,CAAC,CAAA;AAEpE;;;;;;;;;;EAUE;AACF,qBAAa,aAAa,CAAC,CAAC,GAAG,OAAO,EAAE,CAAC,SAAS,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,MAAM;IAC5E,EAAE,EAAE,MAAM,CAAA;IAEV,MAAM,EAAE,MAAM,CAAA;IAEd,SAAS,EAAE,GAAG,CAAA;IAEd,OAAO,EAAE,OAAO,CAAA;IAEhB,KAAK,EAAE,CAAC,CAAA;IAER,YAAY,EAAE,SAAS,CAAA;IAEvB,GAAG,EAAE,CAAC,GAAG,IAAI,CAAO;IAEpB;;OAEG;gBACS,SAAS,EAAE,aAAa,CAAC,CAAC,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M,EAAE,MAAM,CAAA;IAEd,SAAS,EAAE,GAAG,CAAA;IAEd,OAAO,EAAE,OAAO,CAAA;IAEhB,KAAK,EAAE,CAAC,CAAA;IAER,YAAY,EAAE,SAAS,CAAA;IAEvB,GAAG,EAAE,CAAC,GAAG,IAAI,CAAO;IAEpB;;OAEG;gBACS,SAAS,EAAE,aAAa,CAAC,CAAC,EAAE,CAAC,CAAC,EAAE,EAC1C,MAAM,EACN,KAAU,EACV,EAAU,EACV,SAAc,GACf,EAAE,oBAAoB;IAuBvB;;OAEG;IACH,MAAM,IAAI,IAAI;IA6Bd;;OAEG;IACH,WAAW,CAAC,KAAK,GAAE,MAAM,CAAC,MAAM,EAAE,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
@@ -1214,9 +1214,46 @@ function isClassComponent(Component) {
1214
1214
  * @returns {boolean}
1215
1215
  */
1216
1216
  function isForwardRefComponent(Component) {
1217
- var _a;
1218
1217
  return !!(typeof Component === 'object'
1219
- && ((_a = Component.$$typeof) === null || _a === void 0 ? void 0 : _a.toString()) === 'Symbol(react.forward_ref)');
1218
+ && Component.$$typeof
1219
+ && (Component.$$typeof.toString() === 'Symbol(react.forward_ref)'
1220
+ || Component.$$typeof.description === 'react.forward_ref'));
1221
+ }
1222
+ /**
1223
+ * Check if a component is a memoized component.
1224
+ * @param Component
1225
+ * @returns {boolean}
1226
+ */
1227
+ function isMemoComponent(Component) {
1228
+ return !!(typeof Component === 'object'
1229
+ && Component.$$typeof
1230
+ && (Component.$$typeof.toString() === 'Symbol(react.memo)' || Component.$$typeof.description === 'react.memo'));
1231
+ }
1232
+ /**
1233
+ * Check if a component can safely receive a ref prop.
1234
+ * This includes class components, forwardRef components, and memoized components
1235
+ * that wrap forwardRef or class components.
1236
+ * @param Component
1237
+ * @returns {boolean}
1238
+ */
1239
+ function canReceiveRef(Component) {
1240
+ // Check if it's a class component
1241
+ if (isClassComponent(Component)) {
1242
+ return true;
1243
+ }
1244
+ // Check if it's a forwardRef component
1245
+ if (isForwardRefComponent(Component)) {
1246
+ return true;
1247
+ }
1248
+ // Check if it's a memoized component
1249
+ if (isMemoComponent(Component)) {
1250
+ // For memoized components, check the wrapped component
1251
+ const wrappedComponent = Component.type;
1252
+ if (wrappedComponent) {
1253
+ return isClassComponent(wrappedComponent) || isForwardRefComponent(wrappedComponent);
1254
+ }
1255
+ }
1256
+ return false;
1220
1257
  }
1221
1258
  /**
1222
1259
  * Check if we're running React 19+ by detecting if function components support ref props
@@ -1285,26 +1322,18 @@ class ReactRenderer {
1285
1322
  const editor = this.editor;
1286
1323
  // Handle ref forwarding with React 18/19 compatibility
1287
1324
  const isReact19 = isReact19Plus();
1288
- const isClassComp = isClassComponent(Component);
1289
- const isForwardRefComp = isForwardRefComponent(Component);
1325
+ const componentCanReceiveRef = canReceiveRef(Component);
1290
1326
  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
1327
+ // Always remove ref if the component cannot receive it (unless React 19+)
1328
+ if (elementProps.ref && !(isReact19 || componentCanReceiveRef)) {
1329
+ delete elementProps.ref;
1330
+ }
1331
+ // Only assign our own ref if allowed
1332
+ if (!elementProps.ref && (isReact19 || componentCanReceiveRef)) {
1333
+ // @ts-ignore - Setting ref prop for compatible components
1334
+ elementProps.ref = (ref) => {
1335
+ this.ref = ref;
1336
+ };
1308
1337
  }
1309
1338
  this.reactElement = React__default.default.createElement(Component, { ...elementProps });
1310
1339
  (_a = editor === null || editor === void 0 ? void 0 : editor.contentComponent) === null || _a === void 0 ? void 0 : _a.setRenderer(this.id, this);