@blockslides/react 0.3.3 → 0.4.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 +1 -336
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -82
- package/dist/index.d.ts +3 -82
- package/dist/index.js +1 -345
- package/dist/index.js.map +1 -1
- package/package.json +5 -20
- package/src/index.ts +0 -3
- package/src/SlideEditor.tsx +0 -73
- package/src/menus/BubbleMenu.tsx +0 -89
- package/src/menus/BubbleMenuPreset.tsx +0 -144
- package/src/menus/FloatingMenu.tsx +0 -69
- package/src/menus/index.ts +0 -2
- package/src/useSlideEditor.ts +0 -250
package/dist/index.cjs
CHANGED
|
@@ -31,7 +31,6 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
31
31
|
// src/index.ts
|
|
32
32
|
var index_exports = {};
|
|
33
33
|
__export(index_exports, {
|
|
34
|
-
BubbleMenuPreset: () => BubbleMenuPreset,
|
|
35
34
|
EditorConsumer: () => EditorConsumer,
|
|
36
35
|
EditorContent: () => EditorContent,
|
|
37
36
|
EditorContext: () => EditorContext,
|
|
@@ -48,12 +47,10 @@ __export(index_exports, {
|
|
|
48
47
|
ReactNodeViewContext: () => ReactNodeViewContext,
|
|
49
48
|
ReactNodeViewRenderer: () => ReactNodeViewRenderer,
|
|
50
49
|
ReactRenderer: () => ReactRenderer,
|
|
51
|
-
ReactSlideEditor: () => SlideEditor,
|
|
52
50
|
useCurrentEditor: () => useCurrentEditor,
|
|
53
51
|
useEditor: () => useEditor,
|
|
54
52
|
useEditorState: () => useEditorState,
|
|
55
|
-
useReactNodeView: () => useReactNodeView
|
|
56
|
-
useSlideEditor: () => useSlideEditor
|
|
53
|
+
useReactNodeView: () => useReactNodeView
|
|
57
54
|
});
|
|
58
55
|
module.exports = __toCommonJS(index_exports);
|
|
59
56
|
|
|
@@ -1074,340 +1071,10 @@ function ReactNodeViewRenderer(component, options) {
|
|
|
1074
1071
|
};
|
|
1075
1072
|
}
|
|
1076
1073
|
|
|
1077
|
-
// src/SlideEditor.tsx
|
|
1078
|
-
var import_react13 = require("react");
|
|
1079
|
-
|
|
1080
|
-
// src/menus/BubbleMenuPreset.tsx
|
|
1081
|
-
var import_react11 = __toESM(require("react"), 1);
|
|
1082
|
-
var import_react_dom3 = require("react-dom");
|
|
1083
|
-
var import_extension_bubble_menu = require("@blockslides/extension-bubble-menu");
|
|
1084
|
-
var import_state = require("@blockslides/pm/state");
|
|
1085
|
-
var import_extension_bubble_menu_preset = require("@blockslides/extension-bubble-menu-preset");
|
|
1086
|
-
var import_core4 = require("@blockslides/core");
|
|
1087
|
-
var import_jsx_runtime8 = require("react/jsx-runtime");
|
|
1088
|
-
var BubbleMenuPreset = import_react11.default.forwardRef(
|
|
1089
|
-
({
|
|
1090
|
-
editor,
|
|
1091
|
-
updateDelay,
|
|
1092
|
-
resizeDelay,
|
|
1093
|
-
appendTo,
|
|
1094
|
-
shouldShow,
|
|
1095
|
-
getReferencedVirtualElement,
|
|
1096
|
-
options,
|
|
1097
|
-
items,
|
|
1098
|
-
className,
|
|
1099
|
-
injectStyles,
|
|
1100
|
-
textColors,
|
|
1101
|
-
highlightColors,
|
|
1102
|
-
fonts,
|
|
1103
|
-
fontSizes,
|
|
1104
|
-
alignments,
|
|
1105
|
-
onTextAction,
|
|
1106
|
-
onImageReplace,
|
|
1107
|
-
...rest
|
|
1108
|
-
}, ref) => {
|
|
1109
|
-
const pluginKey = "bubbleMenuPreset";
|
|
1110
|
-
const { editor: currentEditor } = useCurrentEditor();
|
|
1111
|
-
const menuEl = (0, import_react11.useRef)(null);
|
|
1112
|
-
(0, import_react11.useEffect)(() => {
|
|
1113
|
-
const attachToEditor = editor || currentEditor;
|
|
1114
|
-
if (!attachToEditor || attachToEditor.isDestroyed) {
|
|
1115
|
-
return;
|
|
1116
|
-
}
|
|
1117
|
-
const { element, cleanup } = (0, import_extension_bubble_menu_preset.buildMenuElement)(attachToEditor, {
|
|
1118
|
-
items: items != null ? items : import_extension_bubble_menu_preset.DEFAULT_ITEMS,
|
|
1119
|
-
className: className != null ? className : "",
|
|
1120
|
-
injectStyles: injectStyles !== false,
|
|
1121
|
-
textColors: textColors != null ? textColors : import_extension_bubble_menu_preset.DEFAULT_COLOR_PALETTE,
|
|
1122
|
-
highlightColors: highlightColors != null ? highlightColors : import_extension_bubble_menu_preset.DEFAULT_HIGHLIGHT_PALETTE,
|
|
1123
|
-
fonts: fonts != null ? fonts : import_extension_bubble_menu_preset.DEFAULT_FONTS,
|
|
1124
|
-
fontSizes: fontSizes != null ? fontSizes : import_extension_bubble_menu_preset.DEFAULT_FONT_SIZES,
|
|
1125
|
-
alignments: alignments != null ? alignments : import_extension_bubble_menu_preset.DEFAULT_ALIGNMENTS,
|
|
1126
|
-
onTextAction,
|
|
1127
|
-
onImageReplace
|
|
1128
|
-
});
|
|
1129
|
-
menuEl.current = element;
|
|
1130
|
-
if (typeof ref === "function") {
|
|
1131
|
-
ref(element);
|
|
1132
|
-
} else if (ref) {
|
|
1133
|
-
;
|
|
1134
|
-
ref.current = element;
|
|
1135
|
-
}
|
|
1136
|
-
const defaultShouldShow = ({
|
|
1137
|
-
state,
|
|
1138
|
-
editor: editor2
|
|
1139
|
-
}) => {
|
|
1140
|
-
var _a, _b;
|
|
1141
|
-
const sel = state.selection;
|
|
1142
|
-
const imageSelection = sel instanceof import_state.NodeSelection && ["image", "imageBlock"].includes((_b = (_a = sel.node) == null ? void 0 : _a.type) == null ? void 0 : _b.name) || editor2.isActive("image") || editor2.isActive("imageBlock");
|
|
1143
|
-
if (imageSelection) return true;
|
|
1144
|
-
if ((0, import_core4.isTextSelection)(sel) && !sel.empty && !imageSelection) return true;
|
|
1145
|
-
return false;
|
|
1146
|
-
};
|
|
1147
|
-
const plugin = (0, import_extension_bubble_menu.BubbleMenuPlugin)({
|
|
1148
|
-
editor: attachToEditor,
|
|
1149
|
-
element,
|
|
1150
|
-
updateDelay,
|
|
1151
|
-
resizeDelay,
|
|
1152
|
-
appendTo,
|
|
1153
|
-
pluginKey,
|
|
1154
|
-
shouldShow: shouldShow != null ? shouldShow : defaultShouldShow,
|
|
1155
|
-
getReferencedVirtualElement,
|
|
1156
|
-
options
|
|
1157
|
-
});
|
|
1158
|
-
attachToEditor.registerPlugin(plugin);
|
|
1159
|
-
return () => {
|
|
1160
|
-
attachToEditor.unregisterPlugin(pluginKey);
|
|
1161
|
-
cleanup == null ? void 0 : cleanup();
|
|
1162
|
-
if (element.parentNode) {
|
|
1163
|
-
element.parentNode.removeChild(element);
|
|
1164
|
-
}
|
|
1165
|
-
};
|
|
1166
|
-
}, [
|
|
1167
|
-
editor,
|
|
1168
|
-
currentEditor,
|
|
1169
|
-
updateDelay,
|
|
1170
|
-
resizeDelay,
|
|
1171
|
-
appendTo,
|
|
1172
|
-
shouldShow,
|
|
1173
|
-
getReferencedVirtualElement,
|
|
1174
|
-
options,
|
|
1175
|
-
items,
|
|
1176
|
-
className,
|
|
1177
|
-
injectStyles,
|
|
1178
|
-
textColors,
|
|
1179
|
-
highlightColors,
|
|
1180
|
-
fonts,
|
|
1181
|
-
fontSizes,
|
|
1182
|
-
alignments,
|
|
1183
|
-
onTextAction,
|
|
1184
|
-
onImageReplace,
|
|
1185
|
-
ref
|
|
1186
|
-
]);
|
|
1187
|
-
return menuEl.current ? (0, import_react_dom3.createPortal)(/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { ...rest }), menuEl.current) : null;
|
|
1188
|
-
}
|
|
1189
|
-
);
|
|
1190
|
-
BubbleMenuPreset.displayName = "BubbleMenuPreset";
|
|
1191
|
-
|
|
1192
|
-
// src/useSlideEditor.ts
|
|
1193
|
-
var import_react12 = require("react");
|
|
1194
|
-
var import_ai_context = require("@blockslides/ai-context");
|
|
1195
|
-
var import_extension_kit = require("@blockslides/extension-kit");
|
|
1196
|
-
var defaultSlide = () => ({
|
|
1197
|
-
/**
|
|
1198
|
-
* Placeholder slide if no content is provided.
|
|
1199
|
-
*/
|
|
1200
|
-
type: "doc",
|
|
1201
|
-
content: [
|
|
1202
|
-
{
|
|
1203
|
-
type: "slide",
|
|
1204
|
-
attrs: {
|
|
1205
|
-
size: "16x9",
|
|
1206
|
-
className: "",
|
|
1207
|
-
id: "slide-1",
|
|
1208
|
-
backgroundMode: "none",
|
|
1209
|
-
backgroundColor: null,
|
|
1210
|
-
backgroundImage: null,
|
|
1211
|
-
backgroundOverlayColor: null,
|
|
1212
|
-
backgroundOverlayOpacity: null
|
|
1213
|
-
},
|
|
1214
|
-
content: [
|
|
1215
|
-
{
|
|
1216
|
-
type: "column",
|
|
1217
|
-
attrs: {
|
|
1218
|
-
align: "center",
|
|
1219
|
-
padding: "lg",
|
|
1220
|
-
margin: null,
|
|
1221
|
-
gap: "md",
|
|
1222
|
-
backgroundColor: "#ffffff",
|
|
1223
|
-
backgroundImage: null,
|
|
1224
|
-
borderRadius: null,
|
|
1225
|
-
border: null,
|
|
1226
|
-
fill: true,
|
|
1227
|
-
width: null,
|
|
1228
|
-
height: null,
|
|
1229
|
-
justify: "center"
|
|
1230
|
-
},
|
|
1231
|
-
content: [
|
|
1232
|
-
{
|
|
1233
|
-
type: "heading",
|
|
1234
|
-
attrs: {
|
|
1235
|
-
align: null,
|
|
1236
|
-
padding: null,
|
|
1237
|
-
margin: null,
|
|
1238
|
-
gap: null,
|
|
1239
|
-
backgroundColor: null,
|
|
1240
|
-
backgroundImage: null,
|
|
1241
|
-
borderRadius: null,
|
|
1242
|
-
border: null,
|
|
1243
|
-
fill: null,
|
|
1244
|
-
width: null,
|
|
1245
|
-
height: null,
|
|
1246
|
-
justify: null,
|
|
1247
|
-
id: "1fc4664c-333d-4203-a3f1-3ad27a54c535",
|
|
1248
|
-
"data-toc-id": "1fc4664c-333d-4203-a3f1-3ad27a54c535",
|
|
1249
|
-
level: 1
|
|
1250
|
-
},
|
|
1251
|
-
content: [
|
|
1252
|
-
{
|
|
1253
|
-
type: "text",
|
|
1254
|
-
text: "Lorem ipsum dolor sit amet"
|
|
1255
|
-
}
|
|
1256
|
-
]
|
|
1257
|
-
},
|
|
1258
|
-
{
|
|
1259
|
-
type: "paragraph",
|
|
1260
|
-
attrs: {
|
|
1261
|
-
align: null,
|
|
1262
|
-
padding: null,
|
|
1263
|
-
margin: null,
|
|
1264
|
-
gap: null,
|
|
1265
|
-
backgroundColor: null,
|
|
1266
|
-
backgroundImage: null,
|
|
1267
|
-
borderRadius: null,
|
|
1268
|
-
border: null,
|
|
1269
|
-
fill: null,
|
|
1270
|
-
width: null,
|
|
1271
|
-
height: null,
|
|
1272
|
-
justify: null
|
|
1273
|
-
},
|
|
1274
|
-
content: [
|
|
1275
|
-
{
|
|
1276
|
-
type: "text",
|
|
1277
|
-
text: "Consectetur adipiscing elit. Sed do eiusmod tempor incididunt. "
|
|
1278
|
-
}
|
|
1279
|
-
]
|
|
1280
|
-
}
|
|
1281
|
-
]
|
|
1282
|
-
}
|
|
1283
|
-
]
|
|
1284
|
-
}
|
|
1285
|
-
]
|
|
1286
|
-
});
|
|
1287
|
-
var defaultAddSlideButton = (presets) => ({
|
|
1288
|
-
showPresets: true,
|
|
1289
|
-
presets,
|
|
1290
|
-
presetBackground: "#0f172a",
|
|
1291
|
-
presetForeground: "#e5e7eb"
|
|
1292
|
-
});
|
|
1293
|
-
var defaultSlideOptions = {
|
|
1294
|
-
renderMode: "dynamic",
|
|
1295
|
-
hoverOutline: { color: "#3b82f6", width: "1.5px", offset: "4px" },
|
|
1296
|
-
hoverOutlineCascade: false
|
|
1297
|
-
};
|
|
1298
|
-
var useSlideEditor = ({
|
|
1299
|
-
content,
|
|
1300
|
-
onChange,
|
|
1301
|
-
extensions,
|
|
1302
|
-
extensionKitOptions,
|
|
1303
|
-
presetTemplates,
|
|
1304
|
-
deps = [],
|
|
1305
|
-
onEditorReady,
|
|
1306
|
-
immediatelyRender = false,
|
|
1307
|
-
shouldRerenderOnTransaction = false,
|
|
1308
|
-
theme = "light",
|
|
1309
|
-
editorProps,
|
|
1310
|
-
onUpdate,
|
|
1311
|
-
...editorOptions
|
|
1312
|
-
} = {}) => {
|
|
1313
|
-
var _a;
|
|
1314
|
-
const presets = (0, import_react12.useMemo)(
|
|
1315
|
-
() => presetTemplates != null ? presetTemplates : import_ai_context.templatesV1.listPresetTemplates(),
|
|
1316
|
-
[presetTemplates]
|
|
1317
|
-
);
|
|
1318
|
-
const mergedExtensionKitOptions = (0, import_react12.useMemo)(() => {
|
|
1319
|
-
var _a2, _b;
|
|
1320
|
-
const addSlideButton = (extensionKitOptions == null ? void 0 : extensionKitOptions.addSlideButton) === false ? false : {
|
|
1321
|
-
...defaultAddSlideButton(presets),
|
|
1322
|
-
...(_a2 = extensionKitOptions == null ? void 0 : extensionKitOptions.addSlideButton) != null ? _a2 : {}
|
|
1323
|
-
};
|
|
1324
|
-
const slide = (extensionKitOptions == null ? void 0 : extensionKitOptions.slide) === false ? false : {
|
|
1325
|
-
...defaultSlideOptions,
|
|
1326
|
-
...(_b = extensionKitOptions == null ? void 0 : extensionKitOptions.slide) != null ? _b : {}
|
|
1327
|
-
};
|
|
1328
|
-
return {
|
|
1329
|
-
...extensionKitOptions,
|
|
1330
|
-
addSlideButton,
|
|
1331
|
-
slide
|
|
1332
|
-
};
|
|
1333
|
-
}, [extensionKitOptions, presets]);
|
|
1334
|
-
const resolvedExtensions = (0, import_react12.useMemo)(() => {
|
|
1335
|
-
const kit = import_extension_kit.ExtensionKit.configure(mergedExtensionKitOptions);
|
|
1336
|
-
return extensions ? [kit, ...extensions] : [kit];
|
|
1337
|
-
}, [extensions, mergedExtensionKitOptions]);
|
|
1338
|
-
const initialContent = content != null ? content : defaultSlide();
|
|
1339
|
-
const editor = useEditor(
|
|
1340
|
-
{
|
|
1341
|
-
content: initialContent,
|
|
1342
|
-
extensions: resolvedExtensions,
|
|
1343
|
-
immediatelyRender,
|
|
1344
|
-
shouldRerenderOnTransaction,
|
|
1345
|
-
theme,
|
|
1346
|
-
editorProps: {
|
|
1347
|
-
attributes: {
|
|
1348
|
-
autocomplete: "off",
|
|
1349
|
-
autocorrect: "off",
|
|
1350
|
-
autocapitalize: "off",
|
|
1351
|
-
class: "min-h-full min-w-full",
|
|
1352
|
-
...(_a = editorProps == null ? void 0 : editorProps.attributes) != null ? _a : {}
|
|
1353
|
-
},
|
|
1354
|
-
...editorProps
|
|
1355
|
-
},
|
|
1356
|
-
...editorOptions,
|
|
1357
|
-
onUpdate: (ctx) => {
|
|
1358
|
-
const json = ctx.editor.getJSON();
|
|
1359
|
-
onChange == null ? void 0 : onChange(json, ctx.editor);
|
|
1360
|
-
onUpdate == null ? void 0 : onUpdate(ctx);
|
|
1361
|
-
}
|
|
1362
|
-
},
|
|
1363
|
-
deps
|
|
1364
|
-
);
|
|
1365
|
-
(0, import_react12.useEffect)(() => {
|
|
1366
|
-
if (editor && !editor.isDestroyed) {
|
|
1367
|
-
onEditorReady == null ? void 0 : onEditorReady(editor);
|
|
1368
|
-
}
|
|
1369
|
-
}, [editor, onEditorReady]);
|
|
1370
|
-
return { editor, presets };
|
|
1371
|
-
};
|
|
1372
|
-
|
|
1373
|
-
// src/SlideEditor.tsx
|
|
1374
|
-
var import_jsx_runtime9 = require("react/jsx-runtime");
|
|
1375
|
-
var SlideEditor = (0, import_react13.forwardRef)(
|
|
1376
|
-
({
|
|
1377
|
-
bubbleMenuPreset = true,
|
|
1378
|
-
editorContentProps,
|
|
1379
|
-
viewportScale = 1,
|
|
1380
|
-
className,
|
|
1381
|
-
style,
|
|
1382
|
-
...hookProps
|
|
1383
|
-
}, ref) => {
|
|
1384
|
-
const { editor } = useSlideEditor(hookProps);
|
|
1385
|
-
const bubbleMenuProps = (0, import_react13.useMemo)(() => {
|
|
1386
|
-
if (bubbleMenuPreset === false) return null;
|
|
1387
|
-
if (bubbleMenuPreset === true) return {};
|
|
1388
|
-
return bubbleMenuPreset;
|
|
1389
|
-
}, [bubbleMenuPreset]);
|
|
1390
|
-
if (!editor) return null;
|
|
1391
|
-
return /* @__PURE__ */ (0, import_jsx_runtime9.jsx)("div", { ref, className, style, children: /* @__PURE__ */ (0, import_jsx_runtime9.jsxs)(
|
|
1392
|
-
"div",
|
|
1393
|
-
{
|
|
1394
|
-
className: "bs-viewport",
|
|
1395
|
-
style: { ["--zoom"]: viewportScale },
|
|
1396
|
-
children: [
|
|
1397
|
-
/* @__PURE__ */ (0, import_jsx_runtime9.jsx)(EditorContent, { editor, ...editorContentProps }),
|
|
1398
|
-
bubbleMenuProps && /* @__PURE__ */ (0, import_jsx_runtime9.jsx)(BubbleMenuPreset, { editor, ...bubbleMenuProps })
|
|
1399
|
-
]
|
|
1400
|
-
}
|
|
1401
|
-
) });
|
|
1402
|
-
}
|
|
1403
|
-
);
|
|
1404
|
-
SlideEditor.displayName = "SlideEditor";
|
|
1405
|
-
|
|
1406
1074
|
// src/index.ts
|
|
1407
1075
|
__reExport(index_exports, require("@blockslides/core"), module.exports);
|
|
1408
1076
|
// Annotate the CommonJS export names for ESM import in node:
|
|
1409
1077
|
0 && (module.exports = {
|
|
1410
|
-
BubbleMenuPreset,
|
|
1411
1078
|
EditorConsumer,
|
|
1412
1079
|
EditorContent,
|
|
1413
1080
|
EditorContext,
|
|
@@ -1424,12 +1091,10 @@ __reExport(index_exports, require("@blockslides/core"), module.exports);
|
|
|
1424
1091
|
ReactNodeViewContext,
|
|
1425
1092
|
ReactNodeViewRenderer,
|
|
1426
1093
|
ReactRenderer,
|
|
1427
|
-
ReactSlideEditor,
|
|
1428
1094
|
useCurrentEditor,
|
|
1429
1095
|
useEditor,
|
|
1430
1096
|
useEditorState,
|
|
1431
1097
|
useReactNodeView,
|
|
1432
|
-
useSlideEditor,
|
|
1433
1098
|
...require("@blockslides/core")
|
|
1434
1099
|
});
|
|
1435
1100
|
//# sourceMappingURL=index.cjs.map
|