@tiptap/react 3.18.0 → 3.19.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/index.cjs CHANGED
@@ -48,11 +48,8 @@ __export(index_exports, {
48
48
  ReactNodeViewRenderer: () => ReactNodeViewRenderer,
49
49
  ReactRenderer: () => ReactRenderer,
50
50
  Tiptap: () => Tiptap,
51
- TiptapBubbleMenu: () => TiptapBubbleMenu,
52
51
  TiptapContent: () => TiptapContent,
53
52
  TiptapContext: () => TiptapContext,
54
- TiptapFloatingMenu: () => TiptapFloatingMenu,
55
- TiptapLoading: () => TiptapLoading,
56
53
  TiptapWrapper: () => TiptapWrapper,
57
54
  useCurrentEditor: () => useCurrentEditor,
58
55
  useEditor: () => useEditor,
@@ -1123,203 +1120,15 @@ function ReactNodeViewRenderer(component, options) {
1123
1120
  }
1124
1121
 
1125
1122
  // src/Tiptap.tsx
1126
- var import_react14 = require("react");
1127
-
1128
- // src/menus/BubbleMenu.tsx
1129
- var import_extension_bubble_menu = require("@tiptap/extension-bubble-menu");
1130
- var import_react10 = require("@tiptap/react");
1131
- var import_react11 = __toESM(require("react"), 1);
1132
- var import_react_dom3 = require("react-dom");
1123
+ var import_react10 = require("react");
1133
1124
  var import_jsx_runtime8 = require("react/jsx-runtime");
1134
- var BubbleMenu = import_react11.default.forwardRef(
1135
- ({
1136
- pluginKey = "bubbleMenu",
1137
- editor,
1138
- updateDelay,
1139
- resizeDelay,
1140
- appendTo,
1141
- shouldShow = null,
1142
- getReferencedVirtualElement,
1143
- options,
1144
- children,
1145
- ...restProps
1146
- }, ref) => {
1147
- const menuEl = (0, import_react11.useRef)(document.createElement("div"));
1148
- if (typeof ref === "function") {
1149
- ref(menuEl.current);
1150
- } else if (ref) {
1151
- ref.current = menuEl.current;
1152
- }
1153
- const { editor: currentEditor } = (0, import_react10.useCurrentEditor)();
1154
- const pluginEditor = editor || currentEditor;
1155
- const bubbleMenuPluginProps = {
1156
- updateDelay,
1157
- resizeDelay,
1158
- appendTo,
1159
- pluginKey,
1160
- shouldShow,
1161
- getReferencedVirtualElement,
1162
- options
1163
- };
1164
- const bubbleMenuPluginPropsRef = (0, import_react11.useRef)(bubbleMenuPluginProps);
1165
- bubbleMenuPluginPropsRef.current = bubbleMenuPluginProps;
1166
- const [pluginInitialized, setPluginInitialized] = (0, import_react11.useState)(false);
1167
- const skipFirstUpdateRef = (0, import_react11.useRef)(true);
1168
- (0, import_react11.useEffect)(() => {
1169
- if (pluginEditor == null ? void 0 : pluginEditor.isDestroyed) {
1170
- return;
1171
- }
1172
- if (!pluginEditor) {
1173
- console.warn("BubbleMenu component is not rendered inside of an editor component or does not have editor prop.");
1174
- return;
1175
- }
1176
- const bubbleMenuElement = menuEl.current;
1177
- bubbleMenuElement.style.visibility = "hidden";
1178
- bubbleMenuElement.style.position = "absolute";
1179
- const plugin = (0, import_extension_bubble_menu.BubbleMenuPlugin)({
1180
- ...bubbleMenuPluginPropsRef.current,
1181
- editor: pluginEditor,
1182
- element: bubbleMenuElement
1183
- });
1184
- pluginEditor.registerPlugin(plugin);
1185
- const createdPluginKey = bubbleMenuPluginPropsRef.current.pluginKey;
1186
- skipFirstUpdateRef.current = true;
1187
- setPluginInitialized(true);
1188
- return () => {
1189
- setPluginInitialized(false);
1190
- pluginEditor.unregisterPlugin(createdPluginKey);
1191
- window.requestAnimationFrame(() => {
1192
- if (bubbleMenuElement.parentNode) {
1193
- bubbleMenuElement.parentNode.removeChild(bubbleMenuElement);
1194
- }
1195
- });
1196
- };
1197
- }, [pluginEditor]);
1198
- (0, import_react11.useEffect)(() => {
1199
- if (!pluginInitialized || !pluginEditor || pluginEditor.isDestroyed) {
1200
- return;
1201
- }
1202
- if (skipFirstUpdateRef.current) {
1203
- skipFirstUpdateRef.current = false;
1204
- return;
1205
- }
1206
- pluginEditor.view.dispatch(
1207
- pluginEditor.state.tr.setMeta("bubbleMenu", {
1208
- type: "updateOptions",
1209
- options: bubbleMenuPluginPropsRef.current
1210
- })
1211
- );
1212
- }, [
1213
- pluginInitialized,
1214
- pluginEditor,
1215
- updateDelay,
1216
- resizeDelay,
1217
- shouldShow,
1218
- options,
1219
- appendTo,
1220
- getReferencedVirtualElement
1221
- ]);
1222
- return (0, import_react_dom3.createPortal)(/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { ...restProps, children }), menuEl.current);
1125
+ var TiptapContext = (0, import_react10.createContext)({
1126
+ get editor() {
1127
+ throw new Error("useTiptap must be used within a <Tiptap> provider");
1223
1128
  }
1224
- );
1225
-
1226
- // src/menus/FloatingMenu.tsx
1227
- var import_extension_floating_menu = require("@tiptap/extension-floating-menu");
1228
- var import_react12 = require("@tiptap/react");
1229
- var import_react13 = __toESM(require("react"), 1);
1230
- var import_react_dom4 = require("react-dom");
1231
- var import_jsx_runtime9 = require("react/jsx-runtime");
1232
- var FloatingMenu = import_react13.default.forwardRef(
1233
- ({
1234
- pluginKey = "floatingMenu",
1235
- editor,
1236
- updateDelay,
1237
- resizeDelay,
1238
- appendTo,
1239
- shouldShow = null,
1240
- options,
1241
- children,
1242
- ...restProps
1243
- }, ref) => {
1244
- const menuEl = (0, import_react13.useRef)(document.createElement("div"));
1245
- if (typeof ref === "function") {
1246
- ref(menuEl.current);
1247
- } else if (ref) {
1248
- ref.current = menuEl.current;
1249
- }
1250
- const { editor: currentEditor } = (0, import_react12.useCurrentEditor)();
1251
- const pluginEditor = editor || currentEditor;
1252
- const floatingMenuPluginProps = {
1253
- updateDelay,
1254
- resizeDelay,
1255
- appendTo,
1256
- pluginKey,
1257
- shouldShow,
1258
- options
1259
- };
1260
- const floatingMenuPluginPropsRef = (0, import_react13.useRef)(floatingMenuPluginProps);
1261
- floatingMenuPluginPropsRef.current = floatingMenuPluginProps;
1262
- const [pluginInitialized, setPluginInitialized] = (0, import_react13.useState)(false);
1263
- const skipFirstUpdateRef = (0, import_react13.useRef)(true);
1264
- (0, import_react13.useEffect)(() => {
1265
- if (pluginEditor == null ? void 0 : pluginEditor.isDestroyed) {
1266
- return;
1267
- }
1268
- if (!pluginEditor) {
1269
- console.warn(
1270
- "FloatingMenu component is not rendered inside of an editor component or does not have editor prop."
1271
- );
1272
- return;
1273
- }
1274
- const floatingMenuElement = menuEl.current;
1275
- floatingMenuElement.style.visibility = "hidden";
1276
- floatingMenuElement.style.position = "absolute";
1277
- const plugin = (0, import_extension_floating_menu.FloatingMenuPlugin)({
1278
- ...floatingMenuPluginPropsRef.current,
1279
- editor: pluginEditor,
1280
- element: floatingMenuElement
1281
- });
1282
- pluginEditor.registerPlugin(plugin);
1283
- const createdPluginKey = floatingMenuPluginPropsRef.current.pluginKey;
1284
- skipFirstUpdateRef.current = true;
1285
- setPluginInitialized(true);
1286
- return () => {
1287
- setPluginInitialized(false);
1288
- pluginEditor.unregisterPlugin(createdPluginKey);
1289
- window.requestAnimationFrame(() => {
1290
- if (floatingMenuElement.parentNode) {
1291
- floatingMenuElement.parentNode.removeChild(floatingMenuElement);
1292
- }
1293
- });
1294
- };
1295
- }, [pluginEditor]);
1296
- (0, import_react13.useEffect)(() => {
1297
- if (!pluginInitialized || !pluginEditor || pluginEditor.isDestroyed) {
1298
- return;
1299
- }
1300
- if (skipFirstUpdateRef.current) {
1301
- skipFirstUpdateRef.current = false;
1302
- return;
1303
- }
1304
- pluginEditor.view.dispatch(
1305
- pluginEditor.state.tr.setMeta("floatingMenu", {
1306
- type: "updateOptions",
1307
- options: floatingMenuPluginPropsRef.current
1308
- })
1309
- );
1310
- }, [pluginInitialized, pluginEditor, updateDelay, resizeDelay, shouldShow, options, appendTo]);
1311
- return (0, import_react_dom4.createPortal)(/* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { ...restProps, children }), menuEl.current);
1312
- }
1313
- );
1314
-
1315
- // src/Tiptap.tsx
1316
- var import_jsx_runtime10 = require("react/jsx-runtime");
1317
- var TiptapContext = (0, import_react14.createContext)({
1318
- editor: null,
1319
- isReady: false
1320
1129
  });
1321
1130
  TiptapContext.displayName = "TiptapContext";
1322
- var useTiptap = () => (0, import_react14.useContext)(TiptapContext);
1131
+ var useTiptap = () => (0, import_react10.useContext)(TiptapContext);
1323
1132
  function useTiptapState(selector, equalityFn) {
1324
1133
  const { editor } = useTiptap();
1325
1134
  return useEditorState({
@@ -1328,81 +1137,27 @@ function useTiptapState(selector, equalityFn) {
1328
1137
  equalityFn
1329
1138
  });
1330
1139
  }
1331
- function TiptapWrapper({ instance, children }) {
1332
- var _a;
1333
- const [isReady, setIsReady] = (0, import_react14.useState)((_a = instance == null ? void 0 : instance.isInitialized) != null ? _a : false);
1334
- (0, import_react14.useEffect)(() => {
1335
- if (!instance) {
1336
- setIsReady(false);
1337
- return;
1338
- }
1339
- if (instance.isInitialized) {
1340
- setIsReady(true);
1341
- return;
1342
- }
1343
- const handleCreate = () => {
1344
- setIsReady(true);
1345
- };
1346
- instance.on("create", handleCreate);
1347
- return () => {
1348
- instance.off("create", handleCreate);
1349
- };
1350
- }, [instance]);
1351
- const tiptapContextValue = (0, import_react14.useMemo)(() => ({ editor: instance, isReady }), [instance, isReady]);
1352
- const legacyContextValue = (0, import_react14.useMemo)(() => ({ editor: instance }), [instance]);
1353
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(EditorContext.Provider, { value: legacyContextValue, children: /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(TiptapContext.Provider, { value: tiptapContextValue, children }) });
1140
+ function TiptapWrapper({ editor, instance, children }) {
1141
+ const resolvedEditor = editor != null ? editor : instance;
1142
+ if (!resolvedEditor) {
1143
+ throw new Error("Tiptap: An editor instance is required. Pass a non-null `editor` prop.");
1144
+ }
1145
+ const tiptapContextValue = (0, import_react10.useMemo)(() => ({ editor: resolvedEditor }), [resolvedEditor]);
1146
+ const legacyContextValue = (0, import_react10.useMemo)(() => ({ editor: resolvedEditor }), [resolvedEditor]);
1147
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(EditorContext.Provider, { value: legacyContextValue, children: /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(TiptapContext.Provider, { value: tiptapContextValue, children }) });
1354
1148
  }
1355
1149
  TiptapWrapper.displayName = "Tiptap";
1356
1150
  function TiptapContent({ ...rest }) {
1357
1151
  const { editor } = useTiptap();
1358
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(EditorContent, { editor, ...rest });
1152
+ return /* @__PURE__ */ (0, import_jsx_runtime8.jsx)(EditorContent, { editor, ...rest });
1359
1153
  }
1360
1154
  TiptapContent.displayName = "Tiptap.Content";
1361
- function TiptapLoading({ children }) {
1362
- const { isReady } = useTiptap();
1363
- if (isReady) {
1364
- return null;
1365
- }
1366
- return children;
1367
- }
1368
- TiptapLoading.displayName = "Tiptap.Loading";
1369
- function TiptapBubbleMenu({ children, ...rest }) {
1370
- const { editor } = useTiptap();
1371
- if (!editor) {
1372
- return null;
1373
- }
1374
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(BubbleMenu, { editor, ...rest, children });
1375
- }
1376
- TiptapBubbleMenu.displayName = "Tiptap.BubbleMenu";
1377
- function TiptapFloatingMenu({ children, ...rest }) {
1378
- const { editor } = useTiptap();
1379
- if (!editor) {
1380
- return null;
1381
- }
1382
- return /* @__PURE__ */ (0, import_jsx_runtime10.jsx)(FloatingMenu, { ...rest, editor, children });
1383
- }
1384
- TiptapFloatingMenu.displayName = "Tiptap.FloatingMenu";
1385
1155
  var Tiptap = Object.assign(TiptapWrapper, {
1386
1156
  /**
1387
1157
  * The Tiptap Content component that renders the EditorContent with the editor instance from the context.
1388
1158
  * @see TiptapContent
1389
1159
  */
1390
- Content: TiptapContent,
1391
- /**
1392
- * The Tiptap Loading component that renders its children only when the editor is not ready.
1393
- * @see TiptapLoading
1394
- */
1395
- Loading: TiptapLoading,
1396
- /**
1397
- * The Tiptap BubbleMenu component that wraps the BubbleMenu from Tiptap and provides the editor instance from the context.
1398
- * @see TiptapBubbleMenu
1399
- */
1400
- BubbleMenu: TiptapBubbleMenu,
1401
- /**
1402
- * The Tiptap FloatingMenu component that wraps the FloatingMenu from Tiptap and provides the editor instance from the context.
1403
- * @see TiptapFloatingMenu
1404
- */
1405
- FloatingMenu: TiptapFloatingMenu
1160
+ Content: TiptapContent
1406
1161
  });
1407
1162
 
1408
1163
  // src/index.ts
@@ -1426,11 +1181,8 @@ __reExport(index_exports, require("@tiptap/core"), module.exports);
1426
1181
  ReactNodeViewRenderer,
1427
1182
  ReactRenderer,
1428
1183
  Tiptap,
1429
- TiptapBubbleMenu,
1430
1184
  TiptapContent,
1431
1185
  TiptapContext,
1432
- TiptapFloatingMenu,
1433
- TiptapLoading,
1434
1186
  TiptapWrapper,
1435
1187
  useCurrentEditor,
1436
1188
  useEditor,