@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.d.cts
CHANGED
|
@@ -1507,6 +1507,8 @@ interface EditorToolbarProps {
|
|
|
1507
1507
|
}
|
|
1508
1508
|
interface EditorContentProps {
|
|
1509
1509
|
className?: string;
|
|
1510
|
+
/** Max height in px before scrolling. When set, content area becomes scrollable. */
|
|
1511
|
+
maxHeight?: number;
|
|
1510
1512
|
}
|
|
1511
1513
|
interface EditorProps {
|
|
1512
1514
|
children: ReactNode;
|
|
@@ -1531,7 +1533,7 @@ declare namespace EditorToolbarSeparator {
|
|
|
1531
1533
|
var displayName: string;
|
|
1532
1534
|
}
|
|
1533
1535
|
|
|
1534
|
-
declare function EditorContent({ className }: EditorContentProps): react_jsx_runtime.JSX.Element;
|
|
1536
|
+
declare function EditorContent({ className, maxHeight }: EditorContentProps): react_jsx_runtime.JSX.Element;
|
|
1535
1537
|
declare namespace EditorContent {
|
|
1536
1538
|
var displayName: string;
|
|
1537
1539
|
}
|
|
@@ -1554,6 +1556,8 @@ interface EditorContextValue {
|
|
|
1554
1556
|
placeholder?: string;
|
|
1555
1557
|
/** Merged render extensions (global + instance). */
|
|
1556
1558
|
extensions: RenderExtension[];
|
|
1559
|
+
/** Initial HTML content to load into the editor on mount */
|
|
1560
|
+
_initialHtml: string;
|
|
1557
1561
|
/** @internal Called by EditorContent on input events */
|
|
1558
1562
|
_onInput: () => void;
|
|
1559
1563
|
}
|
package/dist/index.d.ts
CHANGED
|
@@ -1507,6 +1507,8 @@ interface EditorToolbarProps {
|
|
|
1507
1507
|
}
|
|
1508
1508
|
interface EditorContentProps {
|
|
1509
1509
|
className?: string;
|
|
1510
|
+
/** Max height in px before scrolling. When set, content area becomes scrollable. */
|
|
1511
|
+
maxHeight?: number;
|
|
1510
1512
|
}
|
|
1511
1513
|
interface EditorProps {
|
|
1512
1514
|
children: ReactNode;
|
|
@@ -1531,7 +1533,7 @@ declare namespace EditorToolbarSeparator {
|
|
|
1531
1533
|
var displayName: string;
|
|
1532
1534
|
}
|
|
1533
1535
|
|
|
1534
|
-
declare function EditorContent({ className }: EditorContentProps): react_jsx_runtime.JSX.Element;
|
|
1536
|
+
declare function EditorContent({ className, maxHeight }: EditorContentProps): react_jsx_runtime.JSX.Element;
|
|
1535
1537
|
declare namespace EditorContent {
|
|
1536
1538
|
var displayName: string;
|
|
1537
1539
|
}
|
|
@@ -1554,6 +1556,8 @@ interface EditorContextValue {
|
|
|
1554
1556
|
placeholder?: string;
|
|
1555
1557
|
/** Merged render extensions (global + instance). */
|
|
1556
1558
|
extensions: RenderExtension[];
|
|
1559
|
+
/** Initial HTML content to load into the editor on mount */
|
|
1560
|
+
_initialHtml: string;
|
|
1557
1561
|
/** @internal Called by EditorContent on input events */
|
|
1558
1562
|
_onInput: () => void;
|
|
1559
1563
|
}
|
package/dist/index.js
CHANGED
|
@@ -8319,8 +8319,16 @@ function extensionEditorClasses(extensions) {
|
|
|
8319
8319
|
].join(" ");
|
|
8320
8320
|
}).join(" ");
|
|
8321
8321
|
}
|
|
8322
|
-
function EditorContent({ className }) {
|
|
8323
|
-
const { contentRef, lineSpacing, placeholder, extensions, _onInput } = useEditor();
|
|
8322
|
+
function EditorContent({ className, maxHeight }) {
|
|
8323
|
+
const { contentRef, lineSpacing, placeholder, extensions, _initialHtml, _onInput } = useEditor();
|
|
8324
|
+
const initialized = useRef(false);
|
|
8325
|
+
useEffect(() => {
|
|
8326
|
+
const el = contentRef.current;
|
|
8327
|
+
if (el && _initialHtml && !initialized.current) {
|
|
8328
|
+
el.innerHTML = _initialHtml;
|
|
8329
|
+
initialized.current = true;
|
|
8330
|
+
}
|
|
8331
|
+
}, [contentRef, _initialHtml]);
|
|
8324
8332
|
const extClasses = useMemo(
|
|
8325
8333
|
() => extensionEditorClasses(extensions),
|
|
8326
8334
|
[extensions]
|
|
@@ -8334,10 +8342,14 @@ function EditorContent({ className }) {
|
|
|
8334
8342
|
"data-react-fancy-editor-content": "",
|
|
8335
8343
|
"data-placeholder": placeholder,
|
|
8336
8344
|
onInput: _onInput,
|
|
8337
|
-
style: {
|
|
8345
|
+
style: {
|
|
8346
|
+
lineHeight: lineSpacing,
|
|
8347
|
+
maxHeight: maxHeight ? `${maxHeight}px` : void 0
|
|
8348
|
+
},
|
|
8338
8349
|
className: cn(
|
|
8339
8350
|
"min-h-[120px] px-4 py-3 text-sm outline-none",
|
|
8340
8351
|
"focus:outline-none",
|
|
8352
|
+
maxHeight && "overflow-y-auto",
|
|
8341
8353
|
proseClasses,
|
|
8342
8354
|
extClasses,
|
|
8343
8355
|
"empty:before:content-[attr(data-placeholder)] empty:before:text-zinc-400 empty:before:pointer-events-none",
|
|
@@ -8426,6 +8438,14 @@ function mergeExtensions(instanceExtensions) {
|
|
|
8426
8438
|
}
|
|
8427
8439
|
return merged;
|
|
8428
8440
|
}
|
|
8441
|
+
function toHtml(value, outputFormat) {
|
|
8442
|
+
if (!value) return "";
|
|
8443
|
+
if (outputFormat === "html") return value;
|
|
8444
|
+
const format = detectFormat(value);
|
|
8445
|
+
if (format === "html") return value;
|
|
8446
|
+
const result = marked.parse(value, { async: false });
|
|
8447
|
+
return result.trim();
|
|
8448
|
+
}
|
|
8429
8449
|
function EditorRoot({
|
|
8430
8450
|
children,
|
|
8431
8451
|
className,
|
|
@@ -8439,6 +8459,12 @@ function EditorRoot({
|
|
|
8439
8459
|
}) {
|
|
8440
8460
|
const contentRef = useRef(null);
|
|
8441
8461
|
const [, setValue] = useControllableState(controlledValue, defaultValue, onChange);
|
|
8462
|
+
const initialHtml = useMemo(
|
|
8463
|
+
() => toHtml(controlledValue ?? defaultValue, outputFormat),
|
|
8464
|
+
// Only compute once on mount — don't re-run when value changes from user input
|
|
8465
|
+
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
8466
|
+
[]
|
|
8467
|
+
);
|
|
8442
8468
|
const extensions = useMemo(
|
|
8443
8469
|
() => mergeExtensions(instanceExtensions),
|
|
8444
8470
|
[instanceExtensions]
|
|
@@ -8497,6 +8523,7 @@ function EditorRoot({
|
|
|
8497
8523
|
lineSpacing,
|
|
8498
8524
|
placeholder,
|
|
8499
8525
|
extensions,
|
|
8526
|
+
_initialHtml: initialHtml,
|
|
8500
8527
|
_onInput: handleInput
|
|
8501
8528
|
};
|
|
8502
8529
|
return /* @__PURE__ */ jsx(EditorContext.Provider, { value: contextValue, children: /* @__PURE__ */ jsx(
|