@particle-academy/fancy-slides 0.6.1 → 0.7.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
@@ -477,6 +477,18 @@ var BUILD_KEYFRAMES = `
477
477
  }
478
478
  }
479
479
  `;
480
+
481
+ // src/components/elements/TextElement/editor-preset.ts
482
+ var PRESENTATION_EDITOR_ACTIONS = [
483
+ { icon: "B", label: "Bold", command: "bold" },
484
+ { icon: "I", label: "Italic", command: "italic" },
485
+ { icon: "H", label: "Heading", command: "formatBlock", commandArg: "<h2>" },
486
+ { icon: "P", label: "Paragraph", command: "formatBlock", commandArg: "<p>" },
487
+ { icon: "\u2022", label: "Bullet list", command: "insertUnorderedList" }
488
+ ];
489
+ function normalizeSlideMarkdown(md) {
490
+ return md.replace(/\r\n/g, "\n").replace(/\n{2,}/g, "\n").replace(/[ \t]+$/gm, "").trim();
491
+ }
480
492
  function TextElementRenderer({
481
493
  element,
482
494
  theme,
@@ -515,19 +527,58 @@ function TextElementRenderer({
515
527
  overflow: "hidden"
516
528
  };
517
529
  if (editing && selected) {
518
- return /* @__PURE__ */ jsxRuntime.jsx(
519
- "textarea",
530
+ const fontPx = Math.round((style.fontSize ?? 28) * scale);
531
+ const lh = style.lineHeight ?? 1.4;
532
+ const editScope = scopeId;
533
+ return /* @__PURE__ */ jsxRuntime.jsxs(
534
+ "div",
520
535
  {
521
- value: element.content,
522
- onChange: (e) => onContentChange?.(e.target.value),
536
+ "data-fs-edit-scope": editScope,
523
537
  style: {
524
- ...css,
525
- whiteSpace: "pre-wrap",
526
- resize: "none",
527
- border: "none",
538
+ width: "100%",
539
+ height: "100%",
528
540
  pointerEvents: "auto",
529
- cursor: "text"
530
- }
541
+ cursor: "text",
542
+ textAlign: style.align ?? "left",
543
+ color: style.color ?? t.colors?.text,
544
+ fontFamily: style.fontFamily ?? t.fonts?.body
545
+ },
546
+ onPointerDown: (e) => e.stopPropagation(),
547
+ children: [
548
+ /* @__PURE__ */ jsxRuntime.jsx("style", { children: `
549
+ [data-fs-edit-scope="${editScope}"] [data-react-fancy-editor] {
550
+ border: none; background: transparent; border-radius: 0;
551
+ height: 100%; display: flex; flex-direction: column; overflow: hidden;
552
+ }
553
+ [data-fs-edit-scope="${editScope}"] [data-react-fancy-editor-toolbar] {
554
+ background: rgba(244,244,245,0.85); border-radius: 6px 6px 0 0;
555
+ padding: 2px 4px;
556
+ }
557
+ [data-fs-edit-scope="${editScope}"] [data-react-fancy-editor-content] {
558
+ flex: 1; min-height: 0; padding: 4px 2px; overflow: auto;
559
+ font-size: ${fontPx}px; line-height: ${lh};
560
+ }
561
+ [data-fs-edit-scope="${editScope}"] [data-react-fancy-editor-content] :is(p, ul, ol, li) { font-size: inherit; margin: 0; }
562
+ [data-fs-edit-scope="${editScope}"] [data-react-fancy-editor-content] :where(p, li) + :where(p, li, ul, ol) { margin-top: 0.4em; }
563
+ [data-fs-edit-scope="${editScope}"] [data-react-fancy-editor-content] h1 { font-size: 1.6em; font-weight: 700; margin: 0; }
564
+ [data-fs-edit-scope="${editScope}"] [data-react-fancy-editor-content] h2 { font-size: 1.35em; font-weight: 700; margin: 0; }
565
+ [data-fs-edit-scope="${editScope}"] [data-react-fancy-editor-content] h3 { font-size: 1.15em; font-weight: 600; margin: 0; }
566
+ ` }),
567
+ /* @__PURE__ */ jsxRuntime.jsxs(
568
+ reactFancy.Editor,
569
+ {
570
+ value: element.content,
571
+ onChange: (md) => onContentChange?.(normalizeSlideMarkdown(md)),
572
+ outputFormat: "markdown",
573
+ lineSpacing: lh,
574
+ children: [
575
+ /* @__PURE__ */ jsxRuntime.jsx(reactFancy.Editor.Toolbar, { actions: PRESENTATION_EDITOR_ACTIONS }),
576
+ /* @__PURE__ */ jsxRuntime.jsx(reactFancy.Editor.Content, {})
577
+ ]
578
+ },
579
+ element.id
580
+ )
581
+ ]
531
582
  }
532
583
  );
533
584
  }
@@ -3132,7 +3183,7 @@ function DeckEditor({
3132
3183
  slide,
3133
3184
  theme: deck.theme,
3134
3185
  editing: true,
3135
- onElementContentChange: (eid, content) => ops.updateElement(slide.id, eid, { content }),
3186
+ onElementContentChange: (eid, content) => ops.updateElement(slide.id, eid, { content, format: "markdown" }),
3136
3187
  onElementSelect: setElementIdSelected,
3137
3188
  selectedElementId: elementIdSelected,
3138
3189
  onElementMove: (eid, x, y) => ops.moveElement(slide.id, eid, x, y),
@@ -3173,6 +3224,7 @@ exports.DeckEditor = DeckEditor;
3173
3224
  exports.EditorToolbar = EditorToolbar;
3174
3225
  exports.ElementInspector = ElementInspector;
3175
3226
  exports.ImageElementRenderer = ImageElementRenderer;
3227
+ exports.PRESENTATION_EDITOR_ACTIONS = PRESENTATION_EDITOR_ACTIONS;
3176
3228
  exports.PresenterView = PresenterView;
3177
3229
  exports.ShapeElementRenderer = ShapeElementRenderer;
3178
3230
  exports.Slide = Slide;
@@ -3193,6 +3245,7 @@ exports.defineTheme = defineTheme;
3193
3245
  exports.elementId = elementId;
3194
3246
  exports.isByParagraph = isByParagraph;
3195
3247
  exports.nextId = nextId;
3248
+ exports.normalizeSlideMarkdown = normalizeSlideMarkdown;
3196
3249
  exports.paragraphReveals = paragraphReveals;
3197
3250
  exports.reduceDeck = reduce;
3198
3251
  exports.resolveTheme = resolveTheme;