@particle-academy/react-fancy 1.7.2 → 1.7.3

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
@@ -8630,7 +8630,15 @@ function extensionEditorClasses(extensions) {
8630
8630
  }).join(" ");
8631
8631
  }
8632
8632
  function EditorContent({ className }) {
8633
- const { contentRef, lineSpacing, placeholder, extensions, _onInput } = useEditor();
8633
+ const { contentRef, lineSpacing, placeholder, extensions, _initialHtml, _onInput } = useEditor();
8634
+ const initialized = react.useRef(false);
8635
+ react.useEffect(() => {
8636
+ const el = contentRef.current;
8637
+ if (el && _initialHtml && !initialized.current) {
8638
+ el.innerHTML = _initialHtml;
8639
+ initialized.current = true;
8640
+ }
8641
+ }, [contentRef, _initialHtml]);
8634
8642
  const extClasses = react.useMemo(
8635
8643
  () => extensionEditorClasses(extensions),
8636
8644
  [extensions]
@@ -8736,6 +8744,14 @@ function mergeExtensions(instanceExtensions) {
8736
8744
  }
8737
8745
  return merged;
8738
8746
  }
8747
+ function toHtml(value, outputFormat) {
8748
+ if (!value) return "";
8749
+ if (outputFormat === "html") return value;
8750
+ const format = detectFormat(value);
8751
+ if (format === "html") return value;
8752
+ const result = marked.marked.parse(value, { async: false });
8753
+ return result.trim();
8754
+ }
8739
8755
  function EditorRoot({
8740
8756
  children,
8741
8757
  className,
@@ -8749,6 +8765,12 @@ function EditorRoot({
8749
8765
  }) {
8750
8766
  const contentRef = react.useRef(null);
8751
8767
  const [, setValue] = useControllableState(controlledValue, defaultValue, onChange);
8768
+ const initialHtml = react.useMemo(
8769
+ () => toHtml(controlledValue ?? defaultValue, outputFormat),
8770
+ // Only compute once on mount — don't re-run when value changes from user input
8771
+ // eslint-disable-next-line react-hooks/exhaustive-deps
8772
+ []
8773
+ );
8752
8774
  const extensions = react.useMemo(
8753
8775
  () => mergeExtensions(instanceExtensions),
8754
8776
  [instanceExtensions]
@@ -8807,6 +8829,7 @@ function EditorRoot({
8807
8829
  lineSpacing,
8808
8830
  placeholder,
8809
8831
  extensions,
8832
+ _initialHtml: initialHtml,
8810
8833
  _onInput: handleInput
8811
8834
  };
8812
8835
  return /* @__PURE__ */ jsxRuntime.jsx(EditorContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsxRuntime.jsx(