@farmzone/fz-react-ui 1.1.18 → 1.2.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 +73 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +7 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +73 -13
- package/dist/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
package/dist/index.d.cts
CHANGED
|
@@ -1401,8 +1401,13 @@ interface RichEditorProps {
|
|
|
1401
1401
|
autofocus?: boolean | "start" | "end" | "all" | null;
|
|
1402
1402
|
onSubmit?: () => void;
|
|
1403
1403
|
fileFormat?: ReadonlyArray<string>;
|
|
1404
|
+
maxFiles?: number;
|
|
1404
1405
|
onFileUpload?: (file: File) => string | Promise<string>;
|
|
1405
1406
|
renderFilePreview?: (attachment: FileAttachment, onRemove: () => void) => ReactNode;
|
|
1407
|
+
fileCountUIRender?: (info: {
|
|
1408
|
+
count: number;
|
|
1409
|
+
max?: number;
|
|
1410
|
+
}) => ReactNode;
|
|
1406
1411
|
}
|
|
1407
1412
|
interface UseRichEditorOptions {
|
|
1408
1413
|
defaultValue?: string;
|
|
@@ -1420,6 +1425,7 @@ interface UseRichEditorOptions {
|
|
|
1420
1425
|
editorClassName?: string;
|
|
1421
1426
|
additionalExtensions?: Extensions;
|
|
1422
1427
|
fileFormat?: ReadonlyArray<string>;
|
|
1428
|
+
maxFiles?: number;
|
|
1423
1429
|
onFileUpload?: (file: File) => string | Promise<string>;
|
|
1424
1430
|
onChange?: (html: string) => void;
|
|
1425
1431
|
onSubmit?: () => void;
|
|
@@ -1448,6 +1454,7 @@ interface UseRichEditorReturn {
|
|
|
1448
1454
|
focus: () => void;
|
|
1449
1455
|
isEmpty: boolean;
|
|
1450
1456
|
attachments: FileAttachment[];
|
|
1457
|
+
attachmentCount: number;
|
|
1451
1458
|
removeAttachment: (id: string) => void;
|
|
1452
1459
|
hydrateAttachments: (loaded: FileAttachment[]) => void;
|
|
1453
1460
|
processFiles: (files: File[]) => void;
|
package/dist/index.d.ts
CHANGED
|
@@ -1401,8 +1401,13 @@ interface RichEditorProps {
|
|
|
1401
1401
|
autofocus?: boolean | "start" | "end" | "all" | null;
|
|
1402
1402
|
onSubmit?: () => void;
|
|
1403
1403
|
fileFormat?: ReadonlyArray<string>;
|
|
1404
|
+
maxFiles?: number;
|
|
1404
1405
|
onFileUpload?: (file: File) => string | Promise<string>;
|
|
1405
1406
|
renderFilePreview?: (attachment: FileAttachment, onRemove: () => void) => ReactNode;
|
|
1407
|
+
fileCountUIRender?: (info: {
|
|
1408
|
+
count: number;
|
|
1409
|
+
max?: number;
|
|
1410
|
+
}) => ReactNode;
|
|
1406
1411
|
}
|
|
1407
1412
|
interface UseRichEditorOptions {
|
|
1408
1413
|
defaultValue?: string;
|
|
@@ -1420,6 +1425,7 @@ interface UseRichEditorOptions {
|
|
|
1420
1425
|
editorClassName?: string;
|
|
1421
1426
|
additionalExtensions?: Extensions;
|
|
1422
1427
|
fileFormat?: ReadonlyArray<string>;
|
|
1428
|
+
maxFiles?: number;
|
|
1423
1429
|
onFileUpload?: (file: File) => string | Promise<string>;
|
|
1424
1430
|
onChange?: (html: string) => void;
|
|
1425
1431
|
onSubmit?: () => void;
|
|
@@ -1448,6 +1454,7 @@ interface UseRichEditorReturn {
|
|
|
1448
1454
|
focus: () => void;
|
|
1449
1455
|
isEmpty: boolean;
|
|
1450
1456
|
attachments: FileAttachment[];
|
|
1457
|
+
attachmentCount: number;
|
|
1451
1458
|
removeAttachment: (id: string) => void;
|
|
1452
1459
|
hydrateAttachments: (loaded: FileAttachment[]) => void;
|
|
1453
1460
|
processFiles: (files: File[]) => void;
|
package/dist/index.js
CHANGED
|
@@ -9333,7 +9333,7 @@ function BaseUploader(props) {
|
|
|
9333
9333
|
const errors = [];
|
|
9334
9334
|
for (const file of incoming) {
|
|
9335
9335
|
if (!checkAccept(file, accept)) {
|
|
9336
|
-
errors.push(`${file.name}: \uD5C8\uC6A9\uB418\uC9C0 \uC54A\uB294 \uD30C\uC77C \uD615\uC2DD
|
|
9336
|
+
errors.push(`${file.name}: \uD5C8\uC6A9\uB418\uC9C0 \uC54A\uB294 \uD30C\uC77C \uD615\uC2DD\uC785\uB2C8\uB2E4.`);
|
|
9337
9337
|
continue;
|
|
9338
9338
|
}
|
|
9339
9339
|
if (maxSize && file.size > maxSize) {
|
|
@@ -10693,20 +10693,24 @@ function createPasteHandler(processFilesRef) {
|
|
|
10693
10693
|
return true;
|
|
10694
10694
|
};
|
|
10695
10695
|
}
|
|
10696
|
+
var RICH_EDITOR_DROP_HANDLED = "__richEditorDropHandled";
|
|
10696
10697
|
function createDropHandler(processFilesRef) {
|
|
10697
10698
|
return (_view, event) => {
|
|
10698
10699
|
const files = Array.from(event.dataTransfer?.files ?? []);
|
|
10699
10700
|
if (files.length === 0) return false;
|
|
10700
10701
|
event.preventDefault();
|
|
10702
|
+
event[RICH_EDITOR_DROP_HANDLED] = true;
|
|
10701
10703
|
processFilesRef.current(files);
|
|
10702
10704
|
return true;
|
|
10703
10705
|
};
|
|
10704
10706
|
}
|
|
10707
|
+
|
|
10708
|
+
// src/lib/fileFormat.ts
|
|
10705
10709
|
var FORMAT_EXT_ALIASES = {
|
|
10706
10710
|
JPG: ["jpg", "jpeg"],
|
|
10707
10711
|
JPEG: ["jpg", "jpeg"]
|
|
10708
10712
|
};
|
|
10709
|
-
function
|
|
10713
|
+
function expandFileFormats(fileFormat) {
|
|
10710
10714
|
const exts = /* @__PURE__ */ new Set();
|
|
10711
10715
|
for (const format of fileFormat) {
|
|
10712
10716
|
const key = format.toUpperCase();
|
|
@@ -10715,16 +10719,30 @@ function expandFormats(fileFormat) {
|
|
|
10715
10719
|
}
|
|
10716
10720
|
return exts;
|
|
10717
10721
|
}
|
|
10718
|
-
function
|
|
10722
|
+
function getFileExtension(fileName) {
|
|
10719
10723
|
return fileName.split(".").pop()?.toLowerCase() ?? "";
|
|
10720
10724
|
}
|
|
10721
10725
|
function buildAcceptAttribute(fileFormat) {
|
|
10722
10726
|
if (!fileFormat || fileFormat.length === 0) return void 0;
|
|
10723
|
-
return Array.from(
|
|
10727
|
+
return Array.from(expandFileFormats(fileFormat)).map((ext) => `.${ext}`).join(",");
|
|
10728
|
+
}
|
|
10729
|
+
function splitFilesByFormat(files, fileFormat) {
|
|
10730
|
+
if (!fileFormat || fileFormat.length === 0) return { accepted: [...files], rejected: [] };
|
|
10731
|
+
const allowedExts = expandFileFormats(fileFormat);
|
|
10732
|
+
const accepted = [];
|
|
10733
|
+
const rejected = [];
|
|
10734
|
+
for (const file of files) {
|
|
10735
|
+
(allowedExts.has(getFileExtension(file.name)) ? accepted : rejected).push(file);
|
|
10736
|
+
}
|
|
10737
|
+
return { accepted, rejected };
|
|
10724
10738
|
}
|
|
10739
|
+
|
|
10740
|
+
// src/components/RichEditor/hooks/useRichEditorFiles.ts
|
|
10725
10741
|
function useRichEditorFiles(options = {}) {
|
|
10726
|
-
const { fileFormat, onFileUpload, initialAttachments } = options;
|
|
10742
|
+
const { fileFormat, maxFiles, onFileUpload, initialAttachments } = options;
|
|
10727
10743
|
const [attachments, setAttachments] = useState(() => initialAttachments ?? []);
|
|
10744
|
+
const attachmentsRef = useRef(attachments);
|
|
10745
|
+
attachmentsRef.current = attachments;
|
|
10728
10746
|
const [isUploading, setIsUploading] = useState(false);
|
|
10729
10747
|
const removeAttachment = useCallback((id) => {
|
|
10730
10748
|
setAttachments((prev) => prev.filter((a) => a.id !== id));
|
|
@@ -10734,8 +10752,20 @@ function useRichEditorFiles(options = {}) {
|
|
|
10734
10752
|
}, []);
|
|
10735
10753
|
const processFiles = useCallback(
|
|
10736
10754
|
async (files, editor) => {
|
|
10737
|
-
const
|
|
10738
|
-
|
|
10755
|
+
const { accepted: splitAccepted, rejected: rejectedByFormat } = splitFilesByFormat(files, fileFormat);
|
|
10756
|
+
let accepted = splitAccepted;
|
|
10757
|
+
if (rejectedByFormat.length > 0) {
|
|
10758
|
+
toast.error("\uD5C8\uC6A9\uB418\uC9C0 \uC54A\uB294 \uD655\uC7A5\uC790\uC785\uB2C8\uB2E4.");
|
|
10759
|
+
}
|
|
10760
|
+
if (maxFiles) {
|
|
10761
|
+
const imageCount = editor ? (editor.getHTML().match(/<img\b/gi) ?? []).length : 0;
|
|
10762
|
+
const currentCount = attachmentsRef.current.length + imageCount;
|
|
10763
|
+
const remaining = Math.max(0, maxFiles - currentCount);
|
|
10764
|
+
if (accepted.length > remaining) {
|
|
10765
|
+
toast.error(`\uD30C\uC77C\uC740 \uCD5C\uB300 ${maxFiles}\uAC1C\uAE4C\uC9C0 \uCCA8\uBD80\uD560 \uC218 \uC788\uC2B5\uB2C8\uB2E4.`);
|
|
10766
|
+
}
|
|
10767
|
+
accepted = accepted.slice(0, remaining);
|
|
10768
|
+
}
|
|
10739
10769
|
if (accepted.length === 0) return;
|
|
10740
10770
|
setIsUploading(true);
|
|
10741
10771
|
try {
|
|
@@ -10768,7 +10798,7 @@ function useRichEditorFiles(options = {}) {
|
|
|
10768
10798
|
setIsUploading(false);
|
|
10769
10799
|
}
|
|
10770
10800
|
},
|
|
10771
|
-
[fileFormat, onFileUpload]
|
|
10801
|
+
[fileFormat, maxFiles, onFileUpload]
|
|
10772
10802
|
);
|
|
10773
10803
|
return { attachments, processFiles, removeAttachment, hydrateAttachments, isUploading };
|
|
10774
10804
|
}
|
|
@@ -10843,6 +10873,7 @@ function useRichEditor(options = {}) {
|
|
|
10843
10873
|
editorClassName,
|
|
10844
10874
|
additionalExtensions = [],
|
|
10845
10875
|
fileFormat,
|
|
10876
|
+
maxFiles,
|
|
10846
10877
|
onFileUpload,
|
|
10847
10878
|
onChange,
|
|
10848
10879
|
onSubmit
|
|
@@ -10859,9 +10890,11 @@ function useRichEditor(options = {}) {
|
|
|
10859
10890
|
const initialSplit = initialSplitRef.current;
|
|
10860
10891
|
const { attachments, processFiles, removeAttachment, hydrateAttachments, isUploading } = useRichEditorFiles({
|
|
10861
10892
|
fileFormat,
|
|
10893
|
+
maxFiles,
|
|
10862
10894
|
onFileUpload,
|
|
10863
10895
|
initialAttachments: initialSplit.attachments
|
|
10864
10896
|
});
|
|
10897
|
+
const [imageCount, setImageCount] = useState(() => (initialSplit.html.match(/<img\b/gi) ?? []).length);
|
|
10865
10898
|
const attachmentsRef = useRef(attachments);
|
|
10866
10899
|
attachmentsRef.current = attachments;
|
|
10867
10900
|
const editorRef = useRef(null);
|
|
@@ -10903,6 +10936,15 @@ function useRichEditor(options = {}) {
|
|
|
10903
10936
|
}
|
|
10904
10937
|
});
|
|
10905
10938
|
editorRef.current = editor;
|
|
10939
|
+
useEffect(() => {
|
|
10940
|
+
if (!editor) return;
|
|
10941
|
+
const sync = () => setImageCount((editor.getHTML().match(/<img\b/gi) ?? []).length);
|
|
10942
|
+
sync();
|
|
10943
|
+
editor.on("transaction", sync);
|
|
10944
|
+
return () => {
|
|
10945
|
+
editor.off("transaction", sync);
|
|
10946
|
+
};
|
|
10947
|
+
}, [editor]);
|
|
10906
10948
|
useEffect(() => {
|
|
10907
10949
|
if (!editor) return;
|
|
10908
10950
|
onChangeRef.current?.(composeRichEditorHtml(editor.getHTML(), attachments));
|
|
@@ -10927,6 +10969,7 @@ function useRichEditor(options = {}) {
|
|
|
10927
10969
|
},
|
|
10928
10970
|
isEmpty: editor?.isEmpty ?? true,
|
|
10929
10971
|
attachments,
|
|
10972
|
+
attachmentCount: imageCount + attachments.length,
|
|
10930
10973
|
removeAttachment,
|
|
10931
10974
|
hydrateAttachments,
|
|
10932
10975
|
processFiles: processFilesRef.current,
|
|
@@ -11519,7 +11562,7 @@ function RichEditorToolbar(props) {
|
|
|
11519
11562
|
);
|
|
11520
11563
|
}
|
|
11521
11564
|
function RichEditorDropZone(props) {
|
|
11522
|
-
const { children, className, "data-rich-editor-theme": themeAttr } = props;
|
|
11565
|
+
const { children, className, "data-rich-editor-theme": themeAttr, onDropFiles } = props;
|
|
11523
11566
|
const theme = useRichEditorTheme();
|
|
11524
11567
|
const [isDragging, setIsDragging] = useState(false);
|
|
11525
11568
|
const counterRef = useRef(0);
|
|
@@ -11540,6 +11583,9 @@ function RichEditorDropZone(props) {
|
|
|
11540
11583
|
e.preventDefault();
|
|
11541
11584
|
counterRef.current = 0;
|
|
11542
11585
|
setIsDragging(false);
|
|
11586
|
+
if (e.nativeEvent[RICH_EDITOR_DROP_HANDLED]) return;
|
|
11587
|
+
const files = Array.from(e.dataTransfer.files ?? []);
|
|
11588
|
+
if (files.length > 0) onDropFiles?.(files);
|
|
11543
11589
|
};
|
|
11544
11590
|
return /* @__PURE__ */ jsxs(
|
|
11545
11591
|
"div",
|
|
@@ -11703,8 +11749,10 @@ var RichEditor = forwardRef(function RichEditor2({
|
|
|
11703
11749
|
editable = true,
|
|
11704
11750
|
autofocus,
|
|
11705
11751
|
fileFormat,
|
|
11752
|
+
maxFiles,
|
|
11706
11753
|
onFileUpload,
|
|
11707
|
-
renderFilePreview
|
|
11754
|
+
renderFilePreview,
|
|
11755
|
+
fileCountUIRender
|
|
11708
11756
|
}, ref) {
|
|
11709
11757
|
const showToolbar = toolbar !== false;
|
|
11710
11758
|
const toolbarOptions = typeof toolbar === "object" ? toolbar : {};
|
|
@@ -11724,6 +11772,7 @@ var RichEditor = forwardRef(function RichEditor2({
|
|
|
11724
11772
|
const {
|
|
11725
11773
|
editor,
|
|
11726
11774
|
attachments,
|
|
11775
|
+
attachmentCount,
|
|
11727
11776
|
removeAttachment,
|
|
11728
11777
|
hydrateAttachments,
|
|
11729
11778
|
processFiles,
|
|
@@ -11746,6 +11795,7 @@ var RichEditor = forwardRef(function RichEditor2({
|
|
|
11746
11795
|
autofocus,
|
|
11747
11796
|
editorClassName,
|
|
11748
11797
|
fileFormat,
|
|
11798
|
+
maxFiles,
|
|
11749
11799
|
onFileUpload,
|
|
11750
11800
|
onChange: handleChange,
|
|
11751
11801
|
onSubmit
|
|
@@ -11795,7 +11845,8 @@ var RichEditor = forwardRef(function RichEditor2({
|
|
|
11795
11845
|
...accentColor ? { "--rich-editor-accent-bg": accentColor } : {},
|
|
11796
11846
|
...accentTextColor ? { "--rich-editor-accent-text": accentTextColor } : {}
|
|
11797
11847
|
};
|
|
11798
|
-
|
|
11848
|
+
const showFileCountUI = imageFeatureEnabled && !!fileCountUIRender;
|
|
11849
|
+
const editorBox = /* @__PURE__ */ jsxs(
|
|
11799
11850
|
"div",
|
|
11800
11851
|
{
|
|
11801
11852
|
className: cn("overflow-hidden rounded-lg border border-gray-200 shadow-sm flex flex-col relative", className),
|
|
@@ -11826,7 +11877,7 @@ var RichEditor = forwardRef(function RichEditor2({
|
|
|
11826
11877
|
}
|
|
11827
11878
|
}
|
|
11828
11879
|
),
|
|
11829
|
-
imageFeatureEnabled ? /* @__PURE__ */ jsxs(RichEditorDropZone, { className: "flex flex-1 flex-col", "data-rich-editor-theme": theme, children: [
|
|
11880
|
+
imageFeatureEnabled ? /* @__PURE__ */ jsxs(RichEditorDropZone, { className: "flex flex-1 flex-col", "data-rich-editor-theme": theme, onDropFiles: processFiles, children: [
|
|
11830
11881
|
/* @__PURE__ */ jsx(
|
|
11831
11882
|
RichEditorContent,
|
|
11832
11883
|
{
|
|
@@ -11856,7 +11907,16 @@ var RichEditor = forwardRef(function RichEditor2({
|
|
|
11856
11907
|
)
|
|
11857
11908
|
]
|
|
11858
11909
|
}
|
|
11859
|
-
)
|
|
11910
|
+
);
|
|
11911
|
+
return /* @__PURE__ */ jsx(RichEditorThemeProvider, { value: resolvedTheme, children: showFileCountUI ? (
|
|
11912
|
+
// 바깥에 position: relative 한 단만 더 둬서, fileCountUIRender가 돌려주는 요소가
|
|
11913
|
+
// absolute 포지션이면 에디터 박스 기준으로 겹쳐 뜨고, 일반 요소면 박스 바로 아래
|
|
11914
|
+
// 자연스러운 흐름으로 이어진다 — 호출부가 className 하나로 두 경우를 모두 고를 수 있다.
|
|
11915
|
+
/* @__PURE__ */ jsxs("div", { className: "relative", children: [
|
|
11916
|
+
editorBox,
|
|
11917
|
+
fileCountUIRender({ count: attachmentCount, max: maxFiles })
|
|
11918
|
+
] })
|
|
11919
|
+
) : editorBox });
|
|
11860
11920
|
});
|
|
11861
11921
|
var RichEditor_default = RichEditor;
|
|
11862
11922
|
function useDetailController(params = {}) {
|