@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 +15 -263
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +45 -136
- package/dist/index.d.ts +45 -136
- package/dist/index.js +14 -259
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
- package/src/Tiptap.tsx +58 -189
package/dist/index.js
CHANGED
|
@@ -1058,200 +1058,12 @@ function ReactNodeViewRenderer(component, options) {
|
|
|
1058
1058
|
}
|
|
1059
1059
|
|
|
1060
1060
|
// src/Tiptap.tsx
|
|
1061
|
-
import { createContext as createContext3, useContext as useContext3,
|
|
1062
|
-
|
|
1063
|
-
// src/menus/BubbleMenu.tsx
|
|
1064
|
-
import { BubbleMenuPlugin } from "@tiptap/extension-bubble-menu";
|
|
1065
|
-
import { useCurrentEditor as useCurrentEditor2 } from "@tiptap/react";
|
|
1066
|
-
import React5, { useEffect as useEffect3, useRef as useRef2, useState as useState3 } from "react";
|
|
1067
|
-
import { createPortal } from "react-dom";
|
|
1061
|
+
import { createContext as createContext3, useContext as useContext3, useMemo as useMemo2 } from "react";
|
|
1068
1062
|
import { jsx as jsx8 } from "react/jsx-runtime";
|
|
1069
|
-
var BubbleMenu = React5.forwardRef(
|
|
1070
|
-
({
|
|
1071
|
-
pluginKey = "bubbleMenu",
|
|
1072
|
-
editor,
|
|
1073
|
-
updateDelay,
|
|
1074
|
-
resizeDelay,
|
|
1075
|
-
appendTo,
|
|
1076
|
-
shouldShow = null,
|
|
1077
|
-
getReferencedVirtualElement,
|
|
1078
|
-
options,
|
|
1079
|
-
children,
|
|
1080
|
-
...restProps
|
|
1081
|
-
}, ref) => {
|
|
1082
|
-
const menuEl = useRef2(document.createElement("div"));
|
|
1083
|
-
if (typeof ref === "function") {
|
|
1084
|
-
ref(menuEl.current);
|
|
1085
|
-
} else if (ref) {
|
|
1086
|
-
ref.current = menuEl.current;
|
|
1087
|
-
}
|
|
1088
|
-
const { editor: currentEditor } = useCurrentEditor2();
|
|
1089
|
-
const pluginEditor = editor || currentEditor;
|
|
1090
|
-
const bubbleMenuPluginProps = {
|
|
1091
|
-
updateDelay,
|
|
1092
|
-
resizeDelay,
|
|
1093
|
-
appendTo,
|
|
1094
|
-
pluginKey,
|
|
1095
|
-
shouldShow,
|
|
1096
|
-
getReferencedVirtualElement,
|
|
1097
|
-
options
|
|
1098
|
-
};
|
|
1099
|
-
const bubbleMenuPluginPropsRef = useRef2(bubbleMenuPluginProps);
|
|
1100
|
-
bubbleMenuPluginPropsRef.current = bubbleMenuPluginProps;
|
|
1101
|
-
const [pluginInitialized, setPluginInitialized] = useState3(false);
|
|
1102
|
-
const skipFirstUpdateRef = useRef2(true);
|
|
1103
|
-
useEffect3(() => {
|
|
1104
|
-
if (pluginEditor == null ? void 0 : pluginEditor.isDestroyed) {
|
|
1105
|
-
return;
|
|
1106
|
-
}
|
|
1107
|
-
if (!pluginEditor) {
|
|
1108
|
-
console.warn("BubbleMenu component is not rendered inside of an editor component or does not have editor prop.");
|
|
1109
|
-
return;
|
|
1110
|
-
}
|
|
1111
|
-
const bubbleMenuElement = menuEl.current;
|
|
1112
|
-
bubbleMenuElement.style.visibility = "hidden";
|
|
1113
|
-
bubbleMenuElement.style.position = "absolute";
|
|
1114
|
-
const plugin = BubbleMenuPlugin({
|
|
1115
|
-
...bubbleMenuPluginPropsRef.current,
|
|
1116
|
-
editor: pluginEditor,
|
|
1117
|
-
element: bubbleMenuElement
|
|
1118
|
-
});
|
|
1119
|
-
pluginEditor.registerPlugin(plugin);
|
|
1120
|
-
const createdPluginKey = bubbleMenuPluginPropsRef.current.pluginKey;
|
|
1121
|
-
skipFirstUpdateRef.current = true;
|
|
1122
|
-
setPluginInitialized(true);
|
|
1123
|
-
return () => {
|
|
1124
|
-
setPluginInitialized(false);
|
|
1125
|
-
pluginEditor.unregisterPlugin(createdPluginKey);
|
|
1126
|
-
window.requestAnimationFrame(() => {
|
|
1127
|
-
if (bubbleMenuElement.parentNode) {
|
|
1128
|
-
bubbleMenuElement.parentNode.removeChild(bubbleMenuElement);
|
|
1129
|
-
}
|
|
1130
|
-
});
|
|
1131
|
-
};
|
|
1132
|
-
}, [pluginEditor]);
|
|
1133
|
-
useEffect3(() => {
|
|
1134
|
-
if (!pluginInitialized || !pluginEditor || pluginEditor.isDestroyed) {
|
|
1135
|
-
return;
|
|
1136
|
-
}
|
|
1137
|
-
if (skipFirstUpdateRef.current) {
|
|
1138
|
-
skipFirstUpdateRef.current = false;
|
|
1139
|
-
return;
|
|
1140
|
-
}
|
|
1141
|
-
pluginEditor.view.dispatch(
|
|
1142
|
-
pluginEditor.state.tr.setMeta("bubbleMenu", {
|
|
1143
|
-
type: "updateOptions",
|
|
1144
|
-
options: bubbleMenuPluginPropsRef.current
|
|
1145
|
-
})
|
|
1146
|
-
);
|
|
1147
|
-
}, [
|
|
1148
|
-
pluginInitialized,
|
|
1149
|
-
pluginEditor,
|
|
1150
|
-
updateDelay,
|
|
1151
|
-
resizeDelay,
|
|
1152
|
-
shouldShow,
|
|
1153
|
-
options,
|
|
1154
|
-
appendTo,
|
|
1155
|
-
getReferencedVirtualElement
|
|
1156
|
-
]);
|
|
1157
|
-
return createPortal(/* @__PURE__ */ jsx8("div", { ...restProps, children }), menuEl.current);
|
|
1158
|
-
}
|
|
1159
|
-
);
|
|
1160
|
-
|
|
1161
|
-
// src/menus/FloatingMenu.tsx
|
|
1162
|
-
import { FloatingMenuPlugin } from "@tiptap/extension-floating-menu";
|
|
1163
|
-
import { useCurrentEditor as useCurrentEditor3 } from "@tiptap/react";
|
|
1164
|
-
import React6, { useEffect as useEffect4, useRef as useRef3, useState as useState4 } from "react";
|
|
1165
|
-
import { createPortal as createPortal2 } from "react-dom";
|
|
1166
|
-
import { jsx as jsx9 } from "react/jsx-runtime";
|
|
1167
|
-
var FloatingMenu = React6.forwardRef(
|
|
1168
|
-
({
|
|
1169
|
-
pluginKey = "floatingMenu",
|
|
1170
|
-
editor,
|
|
1171
|
-
updateDelay,
|
|
1172
|
-
resizeDelay,
|
|
1173
|
-
appendTo,
|
|
1174
|
-
shouldShow = null,
|
|
1175
|
-
options,
|
|
1176
|
-
children,
|
|
1177
|
-
...restProps
|
|
1178
|
-
}, ref) => {
|
|
1179
|
-
const menuEl = useRef3(document.createElement("div"));
|
|
1180
|
-
if (typeof ref === "function") {
|
|
1181
|
-
ref(menuEl.current);
|
|
1182
|
-
} else if (ref) {
|
|
1183
|
-
ref.current = menuEl.current;
|
|
1184
|
-
}
|
|
1185
|
-
const { editor: currentEditor } = useCurrentEditor3();
|
|
1186
|
-
const pluginEditor = editor || currentEditor;
|
|
1187
|
-
const floatingMenuPluginProps = {
|
|
1188
|
-
updateDelay,
|
|
1189
|
-
resizeDelay,
|
|
1190
|
-
appendTo,
|
|
1191
|
-
pluginKey,
|
|
1192
|
-
shouldShow,
|
|
1193
|
-
options
|
|
1194
|
-
};
|
|
1195
|
-
const floatingMenuPluginPropsRef = useRef3(floatingMenuPluginProps);
|
|
1196
|
-
floatingMenuPluginPropsRef.current = floatingMenuPluginProps;
|
|
1197
|
-
const [pluginInitialized, setPluginInitialized] = useState4(false);
|
|
1198
|
-
const skipFirstUpdateRef = useRef3(true);
|
|
1199
|
-
useEffect4(() => {
|
|
1200
|
-
if (pluginEditor == null ? void 0 : pluginEditor.isDestroyed) {
|
|
1201
|
-
return;
|
|
1202
|
-
}
|
|
1203
|
-
if (!pluginEditor) {
|
|
1204
|
-
console.warn(
|
|
1205
|
-
"FloatingMenu component is not rendered inside of an editor component or does not have editor prop."
|
|
1206
|
-
);
|
|
1207
|
-
return;
|
|
1208
|
-
}
|
|
1209
|
-
const floatingMenuElement = menuEl.current;
|
|
1210
|
-
floatingMenuElement.style.visibility = "hidden";
|
|
1211
|
-
floatingMenuElement.style.position = "absolute";
|
|
1212
|
-
const plugin = FloatingMenuPlugin({
|
|
1213
|
-
...floatingMenuPluginPropsRef.current,
|
|
1214
|
-
editor: pluginEditor,
|
|
1215
|
-
element: floatingMenuElement
|
|
1216
|
-
});
|
|
1217
|
-
pluginEditor.registerPlugin(plugin);
|
|
1218
|
-
const createdPluginKey = floatingMenuPluginPropsRef.current.pluginKey;
|
|
1219
|
-
skipFirstUpdateRef.current = true;
|
|
1220
|
-
setPluginInitialized(true);
|
|
1221
|
-
return () => {
|
|
1222
|
-
setPluginInitialized(false);
|
|
1223
|
-
pluginEditor.unregisterPlugin(createdPluginKey);
|
|
1224
|
-
window.requestAnimationFrame(() => {
|
|
1225
|
-
if (floatingMenuElement.parentNode) {
|
|
1226
|
-
floatingMenuElement.parentNode.removeChild(floatingMenuElement);
|
|
1227
|
-
}
|
|
1228
|
-
});
|
|
1229
|
-
};
|
|
1230
|
-
}, [pluginEditor]);
|
|
1231
|
-
useEffect4(() => {
|
|
1232
|
-
if (!pluginInitialized || !pluginEditor || pluginEditor.isDestroyed) {
|
|
1233
|
-
return;
|
|
1234
|
-
}
|
|
1235
|
-
if (skipFirstUpdateRef.current) {
|
|
1236
|
-
skipFirstUpdateRef.current = false;
|
|
1237
|
-
return;
|
|
1238
|
-
}
|
|
1239
|
-
pluginEditor.view.dispatch(
|
|
1240
|
-
pluginEditor.state.tr.setMeta("floatingMenu", {
|
|
1241
|
-
type: "updateOptions",
|
|
1242
|
-
options: floatingMenuPluginPropsRef.current
|
|
1243
|
-
})
|
|
1244
|
-
);
|
|
1245
|
-
}, [pluginInitialized, pluginEditor, updateDelay, resizeDelay, shouldShow, options, appendTo]);
|
|
1246
|
-
return createPortal2(/* @__PURE__ */ jsx9("div", { ...restProps, children }), menuEl.current);
|
|
1247
|
-
}
|
|
1248
|
-
);
|
|
1249
|
-
|
|
1250
|
-
// src/Tiptap.tsx
|
|
1251
|
-
import { jsx as jsx10 } from "react/jsx-runtime";
|
|
1252
1063
|
var TiptapContext = createContext3({
|
|
1253
|
-
editor
|
|
1254
|
-
|
|
1064
|
+
get editor() {
|
|
1065
|
+
throw new Error("useTiptap must be used within a <Tiptap> provider");
|
|
1066
|
+
}
|
|
1255
1067
|
});
|
|
1256
1068
|
TiptapContext.displayName = "TiptapContext";
|
|
1257
1069
|
var useTiptap = () => useContext3(TiptapContext);
|
|
@@ -1263,81 +1075,27 @@ function useTiptapState(selector, equalityFn) {
|
|
|
1263
1075
|
equalityFn
|
|
1264
1076
|
});
|
|
1265
1077
|
}
|
|
1266
|
-
function TiptapWrapper({ instance, children }) {
|
|
1267
|
-
|
|
1268
|
-
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
|
|
1272
|
-
|
|
1273
|
-
|
|
1274
|
-
if (instance.isInitialized) {
|
|
1275
|
-
setIsReady(true);
|
|
1276
|
-
return;
|
|
1277
|
-
}
|
|
1278
|
-
const handleCreate = () => {
|
|
1279
|
-
setIsReady(true);
|
|
1280
|
-
};
|
|
1281
|
-
instance.on("create", handleCreate);
|
|
1282
|
-
return () => {
|
|
1283
|
-
instance.off("create", handleCreate);
|
|
1284
|
-
};
|
|
1285
|
-
}, [instance]);
|
|
1286
|
-
const tiptapContextValue = useMemo2(() => ({ editor: instance, isReady }), [instance, isReady]);
|
|
1287
|
-
const legacyContextValue = useMemo2(() => ({ editor: instance }), [instance]);
|
|
1288
|
-
return /* @__PURE__ */ jsx10(EditorContext.Provider, { value: legacyContextValue, children: /* @__PURE__ */ jsx10(TiptapContext.Provider, { value: tiptapContextValue, children }) });
|
|
1078
|
+
function TiptapWrapper({ editor, instance, children }) {
|
|
1079
|
+
const resolvedEditor = editor != null ? editor : instance;
|
|
1080
|
+
if (!resolvedEditor) {
|
|
1081
|
+
throw new Error("Tiptap: An editor instance is required. Pass a non-null `editor` prop.");
|
|
1082
|
+
}
|
|
1083
|
+
const tiptapContextValue = useMemo2(() => ({ editor: resolvedEditor }), [resolvedEditor]);
|
|
1084
|
+
const legacyContextValue = useMemo2(() => ({ editor: resolvedEditor }), [resolvedEditor]);
|
|
1085
|
+
return /* @__PURE__ */ jsx8(EditorContext.Provider, { value: legacyContextValue, children: /* @__PURE__ */ jsx8(TiptapContext.Provider, { value: tiptapContextValue, children }) });
|
|
1289
1086
|
}
|
|
1290
1087
|
TiptapWrapper.displayName = "Tiptap";
|
|
1291
1088
|
function TiptapContent({ ...rest }) {
|
|
1292
1089
|
const { editor } = useTiptap();
|
|
1293
|
-
return /* @__PURE__ */
|
|
1090
|
+
return /* @__PURE__ */ jsx8(EditorContent, { editor, ...rest });
|
|
1294
1091
|
}
|
|
1295
1092
|
TiptapContent.displayName = "Tiptap.Content";
|
|
1296
|
-
function TiptapLoading({ children }) {
|
|
1297
|
-
const { isReady } = useTiptap();
|
|
1298
|
-
if (isReady) {
|
|
1299
|
-
return null;
|
|
1300
|
-
}
|
|
1301
|
-
return children;
|
|
1302
|
-
}
|
|
1303
|
-
TiptapLoading.displayName = "Tiptap.Loading";
|
|
1304
|
-
function TiptapBubbleMenu({ children, ...rest }) {
|
|
1305
|
-
const { editor } = useTiptap();
|
|
1306
|
-
if (!editor) {
|
|
1307
|
-
return null;
|
|
1308
|
-
}
|
|
1309
|
-
return /* @__PURE__ */ jsx10(BubbleMenu, { editor, ...rest, children });
|
|
1310
|
-
}
|
|
1311
|
-
TiptapBubbleMenu.displayName = "Tiptap.BubbleMenu";
|
|
1312
|
-
function TiptapFloatingMenu({ children, ...rest }) {
|
|
1313
|
-
const { editor } = useTiptap();
|
|
1314
|
-
if (!editor) {
|
|
1315
|
-
return null;
|
|
1316
|
-
}
|
|
1317
|
-
return /* @__PURE__ */ jsx10(FloatingMenu, { ...rest, editor, children });
|
|
1318
|
-
}
|
|
1319
|
-
TiptapFloatingMenu.displayName = "Tiptap.FloatingMenu";
|
|
1320
1093
|
var Tiptap = Object.assign(TiptapWrapper, {
|
|
1321
1094
|
/**
|
|
1322
1095
|
* The Tiptap Content component that renders the EditorContent with the editor instance from the context.
|
|
1323
1096
|
* @see TiptapContent
|
|
1324
1097
|
*/
|
|
1325
|
-
Content: TiptapContent
|
|
1326
|
-
/**
|
|
1327
|
-
* The Tiptap Loading component that renders its children only when the editor is not ready.
|
|
1328
|
-
* @see TiptapLoading
|
|
1329
|
-
*/
|
|
1330
|
-
Loading: TiptapLoading,
|
|
1331
|
-
/**
|
|
1332
|
-
* The Tiptap BubbleMenu component that wraps the BubbleMenu from Tiptap and provides the editor instance from the context.
|
|
1333
|
-
* @see TiptapBubbleMenu
|
|
1334
|
-
*/
|
|
1335
|
-
BubbleMenu: TiptapBubbleMenu,
|
|
1336
|
-
/**
|
|
1337
|
-
* The Tiptap FloatingMenu component that wraps the FloatingMenu from Tiptap and provides the editor instance from the context.
|
|
1338
|
-
* @see TiptapFloatingMenu
|
|
1339
|
-
*/
|
|
1340
|
-
FloatingMenu: TiptapFloatingMenu
|
|
1098
|
+
Content: TiptapContent
|
|
1341
1099
|
});
|
|
1342
1100
|
|
|
1343
1101
|
// src/index.ts
|
|
@@ -1360,11 +1118,8 @@ export {
|
|
|
1360
1118
|
ReactNodeViewRenderer,
|
|
1361
1119
|
ReactRenderer,
|
|
1362
1120
|
Tiptap,
|
|
1363
|
-
TiptapBubbleMenu,
|
|
1364
1121
|
TiptapContent,
|
|
1365
1122
|
TiptapContext,
|
|
1366
|
-
TiptapFloatingMenu,
|
|
1367
|
-
TiptapLoading,
|
|
1368
1123
|
TiptapWrapper,
|
|
1369
1124
|
useCurrentEditor,
|
|
1370
1125
|
useEditor,
|