@particle-academy/react-fancy 1.7.2 → 1.7.4
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 +30 -3
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +5 -1
- package/dist/index.d.ts +5 -1
- package/dist/index.js +30 -3
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -8629,8 +8629,16 @@ function extensionEditorClasses(extensions) {
|
|
|
8629
8629
|
].join(" ");
|
|
8630
8630
|
}).join(" ");
|
|
8631
8631
|
}
|
|
8632
|
-
function EditorContent({ className }) {
|
|
8633
|
-
const { contentRef, lineSpacing, placeholder, extensions, _onInput } = useEditor();
|
|
8632
|
+
function EditorContent({ className, maxHeight }) {
|
|
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]
|
|
@@ -8644,10 +8652,14 @@ function EditorContent({ className }) {
|
|
|
8644
8652
|
"data-react-fancy-editor-content": "",
|
|
8645
8653
|
"data-placeholder": placeholder,
|
|
8646
8654
|
onInput: _onInput,
|
|
8647
|
-
style: {
|
|
8655
|
+
style: {
|
|
8656
|
+
lineHeight: lineSpacing,
|
|
8657
|
+
maxHeight: maxHeight ? `${maxHeight}px` : void 0
|
|
8658
|
+
},
|
|
8648
8659
|
className: cn(
|
|
8649
8660
|
"min-h-[120px] px-4 py-3 text-sm outline-none",
|
|
8650
8661
|
"focus:outline-none",
|
|
8662
|
+
maxHeight && "overflow-y-auto",
|
|
8651
8663
|
proseClasses,
|
|
8652
8664
|
extClasses,
|
|
8653
8665
|
"empty:before:content-[attr(data-placeholder)] empty:before:text-zinc-400 empty:before:pointer-events-none",
|
|
@@ -8736,6 +8748,14 @@ function mergeExtensions(instanceExtensions) {
|
|
|
8736
8748
|
}
|
|
8737
8749
|
return merged;
|
|
8738
8750
|
}
|
|
8751
|
+
function toHtml(value, outputFormat) {
|
|
8752
|
+
if (!value) return "";
|
|
8753
|
+
if (outputFormat === "html") return value;
|
|
8754
|
+
const format = detectFormat(value);
|
|
8755
|
+
if (format === "html") return value;
|
|
8756
|
+
const result = marked.marked.parse(value, { async: false });
|
|
8757
|
+
return result.trim();
|
|
8758
|
+
}
|
|
8739
8759
|
function EditorRoot({
|
|
8740
8760
|
children,
|
|
8741
8761
|
className,
|
|
@@ -8749,6 +8769,12 @@ function EditorRoot({
|
|
|
8749
8769
|
}) {
|
|
8750
8770
|
const contentRef = react.useRef(null);
|
|
8751
8771
|
const [, setValue] = useControllableState(controlledValue, defaultValue, onChange);
|
|
8772
|
+
const initialHtml = react.useMemo(
|
|
8773
|
+
() => toHtml(controlledValue ?? defaultValue, outputFormat),
|
|
8774
|
+
// Only compute once on mount — don't re-run when value changes from user input
|
|
8775
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
8776
|
+
[]
|
|
8777
|
+
);
|
|
8752
8778
|
const extensions = react.useMemo(
|
|
8753
8779
|
() => mergeExtensions(instanceExtensions),
|
|
8754
8780
|
[instanceExtensions]
|
|
@@ -8807,6 +8833,7 @@ function EditorRoot({
|
|
|
8807
8833
|
lineSpacing,
|
|
8808
8834
|
placeholder,
|
|
8809
8835
|
extensions,
|
|
8836
|
+
_initialHtml: initialHtml,
|
|
8810
8837
|
_onInput: handleInput
|
|
8811
8838
|
};
|
|
8812
8839
|
return /* @__PURE__ */ jsxRuntime.jsx(EditorContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsxRuntime.jsx(
|