@blockslides/react 0.2.0 → 0.3.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,10 +48,12 @@ __export(index_exports, {
48
48
  ReactNodeViewContext: () => ReactNodeViewContext,
49
49
  ReactNodeViewRenderer: () => ReactNodeViewRenderer,
50
50
  ReactRenderer: () => ReactRenderer,
51
+ ReactSlideEditor: () => SlideEditor,
51
52
  useCurrentEditor: () => useCurrentEditor,
52
53
  useEditor: () => useEditor,
53
54
  useEditorState: () => useEditorState,
54
- useReactNodeView: () => useReactNodeView
55
+ useReactNodeView: () => useReactNodeView,
56
+ useSlideEditor: () => useSlideEditor
55
57
  });
56
58
  module.exports = __toCommonJS(index_exports);
57
59
 
@@ -1072,6 +1074,9 @@ function ReactNodeViewRenderer(component, options) {
1072
1074
  };
1073
1075
  }
1074
1076
 
1077
+ // src/SlideEditor.tsx
1078
+ var import_react13 = require("react");
1079
+
1075
1080
  // src/menus/BubbleMenuPreset.tsx
1076
1081
  var import_react11 = __toESM(require("react"), 1);
1077
1082
  var import_react_dom3 = require("react-dom");
@@ -1082,7 +1087,6 @@ var import_core4 = require("@blockslides/core");
1082
1087
  var import_jsx_runtime8 = require("react/jsx-runtime");
1083
1088
  var BubbleMenuPreset = import_react11.default.forwardRef(
1084
1089
  ({
1085
- pluginKey = "bubbleMenuPreset",
1086
1090
  editor,
1087
1091
  updateDelay,
1088
1092
  resizeDelay,
@@ -1098,8 +1102,11 @@ var BubbleMenuPreset = import_react11.default.forwardRef(
1098
1102
  fonts,
1099
1103
  fontSizes,
1100
1104
  alignments,
1105
+ onTextAction,
1106
+ onImageReplace,
1101
1107
  ...rest
1102
1108
  }, ref) => {
1109
+ const pluginKey = "bubbleMenuPreset";
1103
1110
  const { editor: currentEditor } = useCurrentEditor();
1104
1111
  const menuEl = (0, import_react11.useRef)(null);
1105
1112
  (0, import_react11.useEffect)(() => {
@@ -1115,7 +1122,9 @@ var BubbleMenuPreset = import_react11.default.forwardRef(
1115
1122
  highlightColors: highlightColors != null ? highlightColors : import_extension_bubble_menu_preset.DEFAULT_HIGHLIGHT_PALETTE,
1116
1123
  fonts: fonts != null ? fonts : import_extension_bubble_menu_preset.DEFAULT_FONTS,
1117
1124
  fontSizes: fontSizes != null ? fontSizes : import_extension_bubble_menu_preset.DEFAULT_FONT_SIZES,
1118
- alignments: alignments != null ? alignments : import_extension_bubble_menu_preset.DEFAULT_ALIGNMENTS
1125
+ alignments: alignments != null ? alignments : import_extension_bubble_menu_preset.DEFAULT_ALIGNMENTS,
1126
+ onTextAction,
1127
+ onImageReplace
1119
1128
  });
1120
1129
  menuEl.current = element;
1121
1130
  if (typeof ref === "function") {
@@ -1157,7 +1166,6 @@ var BubbleMenuPreset = import_react11.default.forwardRef(
1157
1166
  }, [
1158
1167
  editor,
1159
1168
  currentEditor,
1160
- pluginKey,
1161
1169
  updateDelay,
1162
1170
  resizeDelay,
1163
1171
  appendTo,
@@ -1172,6 +1180,8 @@ var BubbleMenuPreset = import_react11.default.forwardRef(
1172
1180
  fonts,
1173
1181
  fontSizes,
1174
1182
  alignments,
1183
+ onTextAction,
1184
+ onImageReplace,
1175
1185
  ref
1176
1186
  ]);
1177
1187
  return menuEl.current ? (0, import_react_dom3.createPortal)(/* @__PURE__ */ (0, import_jsx_runtime8.jsx)("div", { ...rest }), menuEl.current) : null;
@@ -1179,6 +1189,220 @@ var BubbleMenuPreset = import_react11.default.forwardRef(
1179
1189
  );
1180
1190
  BubbleMenuPreset.displayName = "BubbleMenuPreset";
1181
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
+
1182
1406
  // src/index.ts
1183
1407
  __reExport(index_exports, require("@blockslides/core"), module.exports);
1184
1408
  // Annotate the CommonJS export names for ESM import in node:
@@ -1200,10 +1424,12 @@ __reExport(index_exports, require("@blockslides/core"), module.exports);
1200
1424
  ReactNodeViewContext,
1201
1425
  ReactNodeViewRenderer,
1202
1426
  ReactRenderer,
1427
+ ReactSlideEditor,
1203
1428
  useCurrentEditor,
1204
1429
  useEditor,
1205
1430
  useEditorState,
1206
1431
  useReactNodeView,
1432
+ useSlideEditor,
1207
1433
  ...require("@blockslides/core")
1208
1434
  });
1209
1435
  //# sourceMappingURL=index.cjs.map