@farmzone/fz-react-ui 1.1.16 → 1.1.17
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 +303 -22
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +20 -0
- package/dist/index.d.ts +20 -0
- package/dist/index.js +306 -25
- package/dist/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -1811,10 +1811,12 @@ var ToastManager = class _ToastManager {
|
|
|
1811
1811
|
const props = this.resolveProps(rawProps);
|
|
1812
1812
|
const position = props.position || "top-center";
|
|
1813
1813
|
const duration = props.duration !== void 0 ? props.duration : 1500;
|
|
1814
|
+
const isSameToast = (other) => (other.props.type ?? "info") === (props.type ?? "info") && other.props.toast === props.toast;
|
|
1814
1815
|
if (props.id) {
|
|
1815
1816
|
for (const [pos, toasts] of this.toasts.entries()) {
|
|
1816
1817
|
const existing = toasts.find((t) => t.id === props.id);
|
|
1817
1818
|
if (existing) {
|
|
1819
|
+
if (isSameToast(existing)) return existing.id;
|
|
1818
1820
|
if (existing.timer) clearTimeout(existing.timer);
|
|
1819
1821
|
const updated = toasts.filter((t) => t.id !== props.id);
|
|
1820
1822
|
this.toasts.set(pos, updated);
|
|
@@ -1825,7 +1827,9 @@ var ToastManager = class _ToastManager {
|
|
|
1825
1827
|
}
|
|
1826
1828
|
}
|
|
1827
1829
|
const positionToasts = this.toasts.get(position) || [];
|
|
1828
|
-
|
|
1830
|
+
const existingAtPosition = positionToasts[0];
|
|
1831
|
+
if (existingAtPosition) {
|
|
1832
|
+
if (isSameToast(existingAtPosition)) return existingAtPosition.id;
|
|
1829
1833
|
positionToasts.forEach((toast2) => {
|
|
1830
1834
|
if (toast2.timer) clearTimeout(toast2.timer);
|
|
1831
1835
|
});
|
|
@@ -3275,25 +3279,24 @@ function SearchBar(props) {
|
|
|
3275
3279
|
function DebouncedButton(props) {
|
|
3276
3280
|
const { debounceDelay = 300, onClick, className, ...rest } = props;
|
|
3277
3281
|
const [isDebouncing, setIsDebouncing] = React6.useState(false);
|
|
3282
|
+
const onClickRef = React6.useRef(onClick);
|
|
3283
|
+
onClickRef.current = onClick;
|
|
3278
3284
|
const debouncedOnClick = React6.useMemo(() => {
|
|
3279
|
-
if (!onClick) return void 0;
|
|
3280
3285
|
return esToolkit.debounce((event) => {
|
|
3281
3286
|
setIsDebouncing(false);
|
|
3282
|
-
|
|
3287
|
+
onClickRef.current?.(event);
|
|
3283
3288
|
}, debounceDelay);
|
|
3284
|
-
}, [debounceDelay
|
|
3289
|
+
}, [debounceDelay]);
|
|
3285
3290
|
React6.useEffect(() => {
|
|
3286
3291
|
return () => {
|
|
3287
|
-
debouncedOnClick
|
|
3292
|
+
debouncedOnClick.cancel();
|
|
3288
3293
|
setIsDebouncing(false);
|
|
3289
3294
|
};
|
|
3290
3295
|
}, [debouncedOnClick]);
|
|
3291
3296
|
const handleClick = (event) => {
|
|
3292
|
-
if (
|
|
3297
|
+
if (onClickRef.current) {
|
|
3293
3298
|
setIsDebouncing(true);
|
|
3294
3299
|
debouncedOnClick(event);
|
|
3295
|
-
} else {
|
|
3296
|
-
onClick?.(event);
|
|
3297
3300
|
}
|
|
3298
3301
|
};
|
|
3299
3302
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -10687,8 +10690,90 @@ function createKeyboardHandler(codeBlockEmptyEnterRef, onSubmitRef) {
|
|
|
10687
10690
|
};
|
|
10688
10691
|
}
|
|
10689
10692
|
|
|
10693
|
+
// src/components/RichEditor/config/fileHandlers.ts
|
|
10694
|
+
function createPasteHandler(processFilesRef) {
|
|
10695
|
+
return (_view, event) => {
|
|
10696
|
+
const files = Array.from(event.clipboardData?.files ?? []);
|
|
10697
|
+
if (files.length === 0) return false;
|
|
10698
|
+
event.preventDefault();
|
|
10699
|
+
processFilesRef.current(files);
|
|
10700
|
+
return true;
|
|
10701
|
+
};
|
|
10702
|
+
}
|
|
10703
|
+
function createDropHandler(processFilesRef) {
|
|
10704
|
+
return (_view, event) => {
|
|
10705
|
+
const files = Array.from(event.dataTransfer?.files ?? []);
|
|
10706
|
+
if (files.length === 0) return false;
|
|
10707
|
+
event.preventDefault();
|
|
10708
|
+
processFilesRef.current(files);
|
|
10709
|
+
return true;
|
|
10710
|
+
};
|
|
10711
|
+
}
|
|
10712
|
+
var FORMAT_EXT_ALIASES = {
|
|
10713
|
+
JPG: ["jpg", "jpeg"],
|
|
10714
|
+
JPEG: ["jpg", "jpeg"]
|
|
10715
|
+
};
|
|
10716
|
+
function expandFormats(fileFormat) {
|
|
10717
|
+
const exts = /* @__PURE__ */ new Set();
|
|
10718
|
+
for (const format of fileFormat) {
|
|
10719
|
+
const key = format.toUpperCase();
|
|
10720
|
+
const aliases = FORMAT_EXT_ALIASES[key] ?? [format.toLowerCase()];
|
|
10721
|
+
aliases.forEach((ext) => exts.add(ext));
|
|
10722
|
+
}
|
|
10723
|
+
return exts;
|
|
10724
|
+
}
|
|
10725
|
+
function extOf(fileName) {
|
|
10726
|
+
return fileName.split(".").pop()?.toLowerCase() ?? "";
|
|
10727
|
+
}
|
|
10728
|
+
function buildAcceptAttribute(fileFormat) {
|
|
10729
|
+
if (!fileFormat || fileFormat.length === 0) return void 0;
|
|
10730
|
+
return Array.from(expandFormats(fileFormat)).map((ext) => `.${ext}`).join(",");
|
|
10731
|
+
}
|
|
10732
|
+
function useRichEditorFiles(options = {}) {
|
|
10733
|
+
const { fileFormat, onFileUpload } = options;
|
|
10734
|
+
const [attachments, setAttachments] = React6.useState([]);
|
|
10735
|
+
const [isUploading, setIsUploading] = React6.useState(false);
|
|
10736
|
+
const removeAttachment = React6.useCallback((id) => {
|
|
10737
|
+
setAttachments((prev) => prev.filter((a) => a.id !== id));
|
|
10738
|
+
}, []);
|
|
10739
|
+
const processFiles = React6.useCallback(
|
|
10740
|
+
async (files, editor) => {
|
|
10741
|
+
const allowedExts = fileFormat ? expandFormats(fileFormat) : null;
|
|
10742
|
+
const accepted = allowedExts ? files.filter((f) => allowedExts.has(extOf(f.name))) : files;
|
|
10743
|
+
if (accepted.length === 0) return;
|
|
10744
|
+
setIsUploading(true);
|
|
10745
|
+
try {
|
|
10746
|
+
for (const file of accepted) {
|
|
10747
|
+
const url = await (onFileUpload ? onFileUpload(file) : URL.createObjectURL(file));
|
|
10748
|
+
if (file.type.startsWith("image/")) {
|
|
10749
|
+
if (!editor) continue;
|
|
10750
|
+
editor.chain().focus().insertContent({ type: "image", attrs: { src: url } }).run();
|
|
10751
|
+
editor.commands.setTextSelection(editor.state.selection.to);
|
|
10752
|
+
} else {
|
|
10753
|
+
setAttachments((prev) => [
|
|
10754
|
+
...prev,
|
|
10755
|
+
{
|
|
10756
|
+
id: `${Date.now()}-${Math.random().toString(36).slice(2)}`,
|
|
10757
|
+
name: file.name,
|
|
10758
|
+
size: file.size,
|
|
10759
|
+
mimeType: file.type,
|
|
10760
|
+
file,
|
|
10761
|
+
url
|
|
10762
|
+
}
|
|
10763
|
+
]);
|
|
10764
|
+
}
|
|
10765
|
+
}
|
|
10766
|
+
} finally {
|
|
10767
|
+
setIsUploading(false);
|
|
10768
|
+
}
|
|
10769
|
+
},
|
|
10770
|
+
[fileFormat, onFileUpload]
|
|
10771
|
+
);
|
|
10772
|
+
return { attachments, processFiles, removeAttachment, isUploading };
|
|
10773
|
+
}
|
|
10774
|
+
|
|
10690
10775
|
// src/components/RichEditor/hooks/useRichEditor.ts
|
|
10691
|
-
var DEFAULT_EDITOR_CLASS = "focus:outline-none";
|
|
10776
|
+
var DEFAULT_EDITOR_CLASS = "focus:outline-none h-full";
|
|
10692
10777
|
function useRichEditor(options = {}) {
|
|
10693
10778
|
const {
|
|
10694
10779
|
defaultValue,
|
|
@@ -10705,6 +10790,8 @@ function useRichEditor(options = {}) {
|
|
|
10705
10790
|
autofocus,
|
|
10706
10791
|
editorClassName,
|
|
10707
10792
|
additionalExtensions = [],
|
|
10793
|
+
fileFormat,
|
|
10794
|
+
onFileUpload,
|
|
10708
10795
|
onChange,
|
|
10709
10796
|
onSubmit
|
|
10710
10797
|
} = options;
|
|
@@ -10713,6 +10800,15 @@ function useRichEditor(options = {}) {
|
|
|
10713
10800
|
onChangeRef.current = onChange;
|
|
10714
10801
|
const onSubmitRef = React6.useRef(onSubmit);
|
|
10715
10802
|
onSubmitRef.current = onSubmit;
|
|
10803
|
+
const { attachments, processFiles, removeAttachment, isUploading } = useRichEditorFiles({
|
|
10804
|
+
fileFormat,
|
|
10805
|
+
onFileUpload
|
|
10806
|
+
});
|
|
10807
|
+
const editorRef = React6.useRef(null);
|
|
10808
|
+
const processFilesRef = React6.useRef(() => {
|
|
10809
|
+
});
|
|
10810
|
+
processFilesRef.current = (files) => processFiles(files, editorRef.current);
|
|
10811
|
+
const imageFeatureEnabled = toolbar.image !== false;
|
|
10716
10812
|
const extensions = [
|
|
10717
10813
|
...buildExtensions({
|
|
10718
10814
|
toolbar,
|
|
@@ -10735,16 +10831,21 @@ function useRichEditor(options = {}) {
|
|
|
10735
10831
|
attributes: {
|
|
10736
10832
|
class: cn(DEFAULT_EDITOR_CLASS, editorClassName)
|
|
10737
10833
|
},
|
|
10738
|
-
handleKeyDown: createKeyboardHandler(codeBlockEmptyEnterRef, onSubmitRef)
|
|
10834
|
+
handleKeyDown: createKeyboardHandler(codeBlockEmptyEnterRef, onSubmitRef),
|
|
10835
|
+
...imageFeatureEnabled ? {
|
|
10836
|
+
handlePaste: createPasteHandler(processFilesRef),
|
|
10837
|
+
handleDrop: createDropHandler(processFilesRef)
|
|
10838
|
+
} : {}
|
|
10739
10839
|
},
|
|
10740
10840
|
content: defaultValue ?? "",
|
|
10741
10841
|
onUpdate: ({ editor: editor2 }) => {
|
|
10742
10842
|
onChangeRef.current?.(editor2.getHTML());
|
|
10743
10843
|
}
|
|
10744
10844
|
});
|
|
10845
|
+
editorRef.current = editor;
|
|
10745
10846
|
React6.useEffect(() => {
|
|
10746
|
-
if (editor) editor.setEditable(editable);
|
|
10747
|
-
}, [editor, editable]);
|
|
10847
|
+
if (editor) editor.setEditable(editable && !isUploading);
|
|
10848
|
+
}, [editor, editable, isUploading]);
|
|
10748
10849
|
return {
|
|
10749
10850
|
editor,
|
|
10750
10851
|
getHTML: () => editor?.getHTML() ?? "",
|
|
@@ -10758,9 +10859,11 @@ function useRichEditor(options = {}) {
|
|
|
10758
10859
|
focus: () => {
|
|
10759
10860
|
editor?.commands.focus();
|
|
10760
10861
|
},
|
|
10761
|
-
isEmpty: editor?.isEmpty ?? true
|
|
10762
|
-
|
|
10763
|
-
|
|
10862
|
+
isEmpty: editor?.isEmpty ?? true,
|
|
10863
|
+
attachments,
|
|
10864
|
+
removeAttachment,
|
|
10865
|
+
processFiles: processFilesRef.current,
|
|
10866
|
+
isUploading
|
|
10764
10867
|
};
|
|
10765
10868
|
}
|
|
10766
10869
|
var MAX_COLS = 8;
|
|
@@ -10949,7 +11052,7 @@ function cmd(fn) {
|
|
|
10949
11052
|
};
|
|
10950
11053
|
}
|
|
10951
11054
|
function RichEditorToolbar(props) {
|
|
10952
|
-
const { editor, toolbar = {}, className, zIndex } = props;
|
|
11055
|
+
const { editor, toolbar = {}, className, zIndex, onImageButtonClick } = props;
|
|
10953
11056
|
const popoverStyle = zIndex !== void 0 ? { zIndex } : void 0;
|
|
10954
11057
|
const theme = useRichEditorTheme();
|
|
10955
11058
|
const [tablePickerOpen, setTablePickerOpen] = React6.useState(false);
|
|
@@ -11223,6 +11326,17 @@ function RichEditorToolbar(props) {
|
|
|
11223
11326
|
}
|
|
11224
11327
|
)
|
|
11225
11328
|
] }),
|
|
11329
|
+
toolbar.image !== false && onImageButtonClick && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
11330
|
+
/* @__PURE__ */ jsxRuntime.jsx(Divider, {}),
|
|
11331
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11332
|
+
ToolbarButton,
|
|
11333
|
+
{
|
|
11334
|
+
onMouseDown: cmd(onImageButtonClick),
|
|
11335
|
+
title: "\uC774\uBBF8\uC9C0/\uD30C\uC77C \uC0BD\uC785",
|
|
11336
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Image, { size: 16 })
|
|
11337
|
+
}
|
|
11338
|
+
)
|
|
11339
|
+
] }),
|
|
11226
11340
|
toolbar.table && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
11227
11341
|
/* @__PURE__ */ jsxRuntime.jsx(Divider, {}),
|
|
11228
11342
|
/* @__PURE__ */ jsxRuntime.jsxs(Popover, { open: tablePickerOpen, onOpenChange: setTablePickerOpen, children: [
|
|
@@ -11337,6 +11451,130 @@ function RichEditorToolbar(props) {
|
|
|
11337
11451
|
}
|
|
11338
11452
|
);
|
|
11339
11453
|
}
|
|
11454
|
+
function RichEditorDropZone(props) {
|
|
11455
|
+
const { children, className, "data-rich-editor-theme": themeAttr } = props;
|
|
11456
|
+
const theme = useRichEditorTheme();
|
|
11457
|
+
const [isDragging, setIsDragging] = React6.useState(false);
|
|
11458
|
+
const counterRef = React6.useRef(0);
|
|
11459
|
+
const handleDragEnter = (e) => {
|
|
11460
|
+
if (!e.dataTransfer.types.includes("Files")) return;
|
|
11461
|
+
e.preventDefault();
|
|
11462
|
+
counterRef.current++;
|
|
11463
|
+
setIsDragging(true);
|
|
11464
|
+
};
|
|
11465
|
+
const handleDragLeave = (_e) => {
|
|
11466
|
+
counterRef.current = Math.max(0, counterRef.current - 1);
|
|
11467
|
+
if (counterRef.current === 0) setIsDragging(false);
|
|
11468
|
+
};
|
|
11469
|
+
const handleDragOver = (e) => {
|
|
11470
|
+
if (e.dataTransfer.types.includes("Files")) e.preventDefault();
|
|
11471
|
+
};
|
|
11472
|
+
const handleDrop = (e) => {
|
|
11473
|
+
e.preventDefault();
|
|
11474
|
+
counterRef.current = 0;
|
|
11475
|
+
setIsDragging(false);
|
|
11476
|
+
};
|
|
11477
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
11478
|
+
"div",
|
|
11479
|
+
{
|
|
11480
|
+
className: cn("relative", className),
|
|
11481
|
+
"data-rich-editor-theme": themeAttr,
|
|
11482
|
+
onDragEnter: handleDragEnter,
|
|
11483
|
+
onDragLeave: handleDragLeave,
|
|
11484
|
+
onDragOver: handleDragOver,
|
|
11485
|
+
onDrop: handleDrop,
|
|
11486
|
+
children: [
|
|
11487
|
+
children,
|
|
11488
|
+
isDragging && /* @__PURE__ */ jsxRuntime.jsx("div", { className: cn("pointer-events-none absolute inset-0 z-50 flex items-center justify-center rounded-lg border-2 border-dashed", theme.dropZone.overlay), children: /* @__PURE__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-center gap-2", children: [
|
|
11489
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Upload, { size: 28, strokeWidth: 1.5 }),
|
|
11490
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm font-medium", children: "\uD30C\uC77C\uC744 \uC5EC\uAE30\uC5D0 \uB193\uC73C\uC138\uC694" }),
|
|
11491
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: cn("text-xs", theme.dropZone.subText), children: "\uC774\uBBF8\uC9C0 \u2192 \uBCF8\uBB38 \uC0BD\uC785 \xA0\xB7\xA0 \uADF8 \uC678 \uD30C\uC77C \u2192 \uD558\uB2E8 \uCCA8\uBD80" })
|
|
11492
|
+
] }) })
|
|
11493
|
+
]
|
|
11494
|
+
}
|
|
11495
|
+
);
|
|
11496
|
+
}
|
|
11497
|
+
var EXT_STYLE = {
|
|
11498
|
+
pdf: "bg-red-100 text-red-700",
|
|
11499
|
+
doc: "bg-blue-100 text-blue-700",
|
|
11500
|
+
docx: "bg-blue-100 text-blue-700",
|
|
11501
|
+
hwp: "bg-blue-100 text-blue-700",
|
|
11502
|
+
xls: "bg-green-100 text-green-700",
|
|
11503
|
+
xlsx: "bg-green-100 text-green-700",
|
|
11504
|
+
csv: "bg-emerald-100 text-emerald-700",
|
|
11505
|
+
ppt: "bg-orange-100 text-orange-700",
|
|
11506
|
+
pptx: "bg-orange-100 text-orange-700",
|
|
11507
|
+
zip: "bg-gray-200 text-gray-700",
|
|
11508
|
+
rar: "bg-gray-200 text-gray-700",
|
|
11509
|
+
"7z": "bg-gray-200 text-gray-700",
|
|
11510
|
+
mp4: "bg-purple-100 text-purple-700",
|
|
11511
|
+
mov: "bg-purple-100 text-purple-700",
|
|
11512
|
+
avi: "bg-purple-100 text-purple-700",
|
|
11513
|
+
mp3: "bg-pink-100 text-pink-700",
|
|
11514
|
+
wav: "bg-pink-100 text-pink-700",
|
|
11515
|
+
txt: "bg-gray-100 text-gray-600",
|
|
11516
|
+
json: "bg-yellow-100 text-yellow-700",
|
|
11517
|
+
xml: "bg-yellow-100 text-yellow-700",
|
|
11518
|
+
js: "bg-yellow-100 text-yellow-700",
|
|
11519
|
+
ts: "bg-blue-100 text-blue-700",
|
|
11520
|
+
html: "bg-orange-100 text-orange-700",
|
|
11521
|
+
css: "bg-sky-100 text-sky-700"
|
|
11522
|
+
};
|
|
11523
|
+
function formatSize(bytes) {
|
|
11524
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
11525
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
11526
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
11527
|
+
}
|
|
11528
|
+
function RichEditorFileList(props) {
|
|
11529
|
+
const { attachments, onRemove, renderFilePreview } = props;
|
|
11530
|
+
const theme = useRichEditorTheme();
|
|
11531
|
+
if (attachments.length === 0) return null;
|
|
11532
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("px-3 py-2.5", theme.fileList.wrapper), children: [
|
|
11533
|
+
/* @__PURE__ */ jsxRuntime.jsxs("p", { className: cn("mb-1.5 text-[11px] font-medium uppercase tracking-wide", theme.fileList.label), children: [
|
|
11534
|
+
"\uCCA8\uBD80\uD30C\uC77C (",
|
|
11535
|
+
attachments.length,
|
|
11536
|
+
")"
|
|
11537
|
+
] }),
|
|
11538
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-wrap gap-2", children: attachments.map((attachment) => {
|
|
11539
|
+
if (renderFilePreview) {
|
|
11540
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { children: renderFilePreview(attachment, () => onRemove(attachment.id)) }, attachment.id);
|
|
11541
|
+
}
|
|
11542
|
+
const ext = attachment.name.split(".").pop()?.toLowerCase() ?? "";
|
|
11543
|
+
const extStyle = EXT_STYLE[ext] ?? "bg-gray-100 text-gray-600";
|
|
11544
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
11545
|
+
"div",
|
|
11546
|
+
{
|
|
11547
|
+
className: cn("flex items-center gap-2 rounded-md px-2.5 py-1.5 shadow-xs", theme.fileList.item),
|
|
11548
|
+
children: [
|
|
11549
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11550
|
+
"span",
|
|
11551
|
+
{
|
|
11552
|
+
className: cn(
|
|
11553
|
+
"shrink-0 rounded px-1.5 py-0.5 text-[10px] font-bold uppercase tracking-wide",
|
|
11554
|
+
extStyle
|
|
11555
|
+
),
|
|
11556
|
+
children: ext || "FILE"
|
|
11557
|
+
}
|
|
11558
|
+
),
|
|
11559
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: cn("max-w-[140px] truncate text-xs", theme.fileList.itemName), children: attachment.name }),
|
|
11560
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: cn("shrink-0 text-[11px]", theme.fileList.itemSize), children: formatSize(attachment.size) }),
|
|
11561
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11562
|
+
"button",
|
|
11563
|
+
{
|
|
11564
|
+
type: "button",
|
|
11565
|
+
onClick: () => onRemove(attachment.id),
|
|
11566
|
+
title: "\uCCA8\uBD80\uD30C\uC77C \uC81C\uAC70",
|
|
11567
|
+
className: cn("flex h-4 w-4 shrink-0 items-center justify-center rounded-full", theme.fileList.removeBtn),
|
|
11568
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { size: 10 })
|
|
11569
|
+
}
|
|
11570
|
+
)
|
|
11571
|
+
]
|
|
11572
|
+
},
|
|
11573
|
+
attachment.id
|
|
11574
|
+
);
|
|
11575
|
+
}) })
|
|
11576
|
+
] });
|
|
11577
|
+
}
|
|
11340
11578
|
var DEFAULT_TOOLBAR = {
|
|
11341
11579
|
heading: [1, 2, 3, 4],
|
|
11342
11580
|
bold: true,
|
|
@@ -11360,7 +11598,7 @@ function RichEditorContent(props) {
|
|
|
11360
11598
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
11361
11599
|
"div",
|
|
11362
11600
|
{
|
|
11363
|
-
className: cn("rich-editor-content cursor-text", className),
|
|
11601
|
+
className: cn("rich-editor-content flex-1 cursor-text", className),
|
|
11364
11602
|
style,
|
|
11365
11603
|
onMouseDown: (e) => {
|
|
11366
11604
|
if (!editor) return;
|
|
@@ -11396,7 +11634,10 @@ var RichEditor = React6.forwardRef(function RichEditor2({
|
|
|
11396
11634
|
zIndex,
|
|
11397
11635
|
themeTokens,
|
|
11398
11636
|
editable = true,
|
|
11399
|
-
autofocus
|
|
11637
|
+
autofocus,
|
|
11638
|
+
fileFormat,
|
|
11639
|
+
onFileUpload,
|
|
11640
|
+
renderFilePreview
|
|
11400
11641
|
}, ref) {
|
|
11401
11642
|
const showToolbar = toolbar !== false;
|
|
11402
11643
|
const toolbarOptions = typeof toolbar === "object" ? toolbar : {};
|
|
@@ -11413,7 +11654,7 @@ var RichEditor = React6.forwardRef(function RichEditor2({
|
|
|
11413
11654
|
},
|
|
11414
11655
|
[onChange]
|
|
11415
11656
|
);
|
|
11416
|
-
const { editor } = useRichEditor({
|
|
11657
|
+
const { editor, attachments, removeAttachment, processFiles, isUploading } = useRichEditor({
|
|
11417
11658
|
defaultValue: value ?? defaultValue,
|
|
11418
11659
|
toolbar: activeToolbar,
|
|
11419
11660
|
mentionUsers,
|
|
@@ -11428,9 +11669,12 @@ var RichEditor = React6.forwardRef(function RichEditor2({
|
|
|
11428
11669
|
editable,
|
|
11429
11670
|
autofocus,
|
|
11430
11671
|
editorClassName,
|
|
11672
|
+
fileFormat,
|
|
11673
|
+
onFileUpload,
|
|
11431
11674
|
onChange: handleChange,
|
|
11432
11675
|
onSubmit
|
|
11433
11676
|
});
|
|
11677
|
+
const fileInputRef = React6.useRef(null);
|
|
11434
11678
|
React6.useEffect(() => {
|
|
11435
11679
|
if (!editor || value === void 0) return;
|
|
11436
11680
|
if (isInternalChangeRef.current) {
|
|
@@ -11458,11 +11702,13 @@ var RichEditor = React6.forwardRef(function RichEditor2({
|
|
|
11458
11702
|
get isEmpty() {
|
|
11459
11703
|
return editor?.isEmpty ?? true;
|
|
11460
11704
|
},
|
|
11705
|
+
attachments,
|
|
11461
11706
|
editor
|
|
11462
11707
|
}),
|
|
11463
|
-
[editor]
|
|
11708
|
+
[editor, attachments]
|
|
11464
11709
|
);
|
|
11465
11710
|
const isToolbarVisible = showToolbar && editable;
|
|
11711
|
+
const imageFeatureEnabled = activeToolbar.image !== false;
|
|
11466
11712
|
const baseTheme = RICH_EDITOR_THEMES[theme];
|
|
11467
11713
|
const resolvedTheme = themeTokens ? {
|
|
11468
11714
|
...baseTheme,
|
|
@@ -11485,10 +11731,37 @@ var RichEditor = React6.forwardRef(function RichEditor2({
|
|
|
11485
11731
|
{
|
|
11486
11732
|
editor,
|
|
11487
11733
|
toolbar: activeToolbar,
|
|
11488
|
-
zIndex
|
|
11734
|
+
zIndex,
|
|
11735
|
+
onImageButtonClick: imageFeatureEnabled ? () => fileInputRef.current?.click() : void 0
|
|
11489
11736
|
}
|
|
11490
11737
|
),
|
|
11491
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11738
|
+
imageFeatureEnabled && /* @__PURE__ */ jsxRuntime.jsx(
|
|
11739
|
+
"input",
|
|
11740
|
+
{
|
|
11741
|
+
ref: fileInputRef,
|
|
11742
|
+
type: "file",
|
|
11743
|
+
multiple: true,
|
|
11744
|
+
accept: buildAcceptAttribute(fileFormat),
|
|
11745
|
+
className: "hidden",
|
|
11746
|
+
onChange: (e) => {
|
|
11747
|
+
const files = Array.from(e.target.files ?? []);
|
|
11748
|
+
if (files.length > 0) processFiles(files);
|
|
11749
|
+
e.target.value = "";
|
|
11750
|
+
}
|
|
11751
|
+
}
|
|
11752
|
+
),
|
|
11753
|
+
imageFeatureEnabled ? /* @__PURE__ */ jsxRuntime.jsxs(RichEditorDropZone, { className: "flex flex-1 flex-col", "data-rich-editor-theme": theme, children: [
|
|
11754
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11755
|
+
RichEditorContent,
|
|
11756
|
+
{
|
|
11757
|
+
editor,
|
|
11758
|
+
className: cn("p-4", bodyClassName),
|
|
11759
|
+
minHeight,
|
|
11760
|
+
maxHeight
|
|
11761
|
+
}
|
|
11762
|
+
),
|
|
11763
|
+
isUploading && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pointer-events-none absolute inset-0 z-10 flex items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(Loading, { size: "lg" }) })
|
|
11764
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
11492
11765
|
RichEditorContent,
|
|
11493
11766
|
{
|
|
11494
11767
|
editor,
|
|
@@ -11496,6 +11769,14 @@ var RichEditor = React6.forwardRef(function RichEditor2({
|
|
|
11496
11769
|
minHeight,
|
|
11497
11770
|
maxHeight
|
|
11498
11771
|
}
|
|
11772
|
+
),
|
|
11773
|
+
imageFeatureEnabled && /* @__PURE__ */ jsxRuntime.jsx(
|
|
11774
|
+
RichEditorFileList,
|
|
11775
|
+
{
|
|
11776
|
+
attachments,
|
|
11777
|
+
onRemove: removeAttachment,
|
|
11778
|
+
renderFilePreview
|
|
11779
|
+
}
|
|
11499
11780
|
)
|
|
11500
11781
|
]
|
|
11501
11782
|
}
|