@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.cjs
CHANGED
|
@@ -9370,7 +9370,7 @@ function BaseUploader(props) {
|
|
|
9370
9370
|
const errors = [];
|
|
9371
9371
|
for (const file of incoming) {
|
|
9372
9372
|
if (!checkAccept(file, accept)) {
|
|
9373
|
-
errors.push(`${file.name}: \uD5C8\uC6A9\uB418\uC9C0 \uC54A\uB294 \uD30C\uC77C \uD615\uC2DD
|
|
9373
|
+
errors.push(`${file.name}: \uD5C8\uC6A9\uB418\uC9C0 \uC54A\uB294 \uD30C\uC77C \uD615\uC2DD\uC785\uB2C8\uB2E4.`);
|
|
9374
9374
|
continue;
|
|
9375
9375
|
}
|
|
9376
9376
|
if (maxSize && file.size > maxSize) {
|
|
@@ -10730,20 +10730,24 @@ function createPasteHandler(processFilesRef) {
|
|
|
10730
10730
|
return true;
|
|
10731
10731
|
};
|
|
10732
10732
|
}
|
|
10733
|
+
var RICH_EDITOR_DROP_HANDLED = "__richEditorDropHandled";
|
|
10733
10734
|
function createDropHandler(processFilesRef) {
|
|
10734
10735
|
return (_view, event) => {
|
|
10735
10736
|
const files = Array.from(event.dataTransfer?.files ?? []);
|
|
10736
10737
|
if (files.length === 0) return false;
|
|
10737
10738
|
event.preventDefault();
|
|
10739
|
+
event[RICH_EDITOR_DROP_HANDLED] = true;
|
|
10738
10740
|
processFilesRef.current(files);
|
|
10739
10741
|
return true;
|
|
10740
10742
|
};
|
|
10741
10743
|
}
|
|
10744
|
+
|
|
10745
|
+
// src/lib/fileFormat.ts
|
|
10742
10746
|
var FORMAT_EXT_ALIASES = {
|
|
10743
10747
|
JPG: ["jpg", "jpeg"],
|
|
10744
10748
|
JPEG: ["jpg", "jpeg"]
|
|
10745
10749
|
};
|
|
10746
|
-
function
|
|
10750
|
+
function expandFileFormats(fileFormat) {
|
|
10747
10751
|
const exts = /* @__PURE__ */ new Set();
|
|
10748
10752
|
for (const format of fileFormat) {
|
|
10749
10753
|
const key = format.toUpperCase();
|
|
@@ -10752,16 +10756,30 @@ function expandFormats(fileFormat) {
|
|
|
10752
10756
|
}
|
|
10753
10757
|
return exts;
|
|
10754
10758
|
}
|
|
10755
|
-
function
|
|
10759
|
+
function getFileExtension(fileName) {
|
|
10756
10760
|
return fileName.split(".").pop()?.toLowerCase() ?? "";
|
|
10757
10761
|
}
|
|
10758
10762
|
function buildAcceptAttribute(fileFormat) {
|
|
10759
10763
|
if (!fileFormat || fileFormat.length === 0) return void 0;
|
|
10760
|
-
return Array.from(
|
|
10764
|
+
return Array.from(expandFileFormats(fileFormat)).map((ext) => `.${ext}`).join(",");
|
|
10765
|
+
}
|
|
10766
|
+
function splitFilesByFormat(files, fileFormat) {
|
|
10767
|
+
if (!fileFormat || fileFormat.length === 0) return { accepted: [...files], rejected: [] };
|
|
10768
|
+
const allowedExts = expandFileFormats(fileFormat);
|
|
10769
|
+
const accepted = [];
|
|
10770
|
+
const rejected = [];
|
|
10771
|
+
for (const file of files) {
|
|
10772
|
+
(allowedExts.has(getFileExtension(file.name)) ? accepted : rejected).push(file);
|
|
10773
|
+
}
|
|
10774
|
+
return { accepted, rejected };
|
|
10761
10775
|
}
|
|
10776
|
+
|
|
10777
|
+
// src/components/RichEditor/hooks/useRichEditorFiles.ts
|
|
10762
10778
|
function useRichEditorFiles(options = {}) {
|
|
10763
|
-
const { fileFormat, onFileUpload, initialAttachments } = options;
|
|
10779
|
+
const { fileFormat, maxFiles, onFileUpload, initialAttachments } = options;
|
|
10764
10780
|
const [attachments, setAttachments] = React6.useState(() => initialAttachments ?? []);
|
|
10781
|
+
const attachmentsRef = React6.useRef(attachments);
|
|
10782
|
+
attachmentsRef.current = attachments;
|
|
10765
10783
|
const [isUploading, setIsUploading] = React6.useState(false);
|
|
10766
10784
|
const removeAttachment = React6.useCallback((id) => {
|
|
10767
10785
|
setAttachments((prev) => prev.filter((a) => a.id !== id));
|
|
@@ -10771,8 +10789,20 @@ function useRichEditorFiles(options = {}) {
|
|
|
10771
10789
|
}, []);
|
|
10772
10790
|
const processFiles = React6.useCallback(
|
|
10773
10791
|
async (files, editor) => {
|
|
10774
|
-
const
|
|
10775
|
-
|
|
10792
|
+
const { accepted: splitAccepted, rejected: rejectedByFormat } = splitFilesByFormat(files, fileFormat);
|
|
10793
|
+
let accepted = splitAccepted;
|
|
10794
|
+
if (rejectedByFormat.length > 0) {
|
|
10795
|
+
toast.error("\uD5C8\uC6A9\uB418\uC9C0 \uC54A\uB294 \uD655\uC7A5\uC790\uC785\uB2C8\uB2E4.");
|
|
10796
|
+
}
|
|
10797
|
+
if (maxFiles) {
|
|
10798
|
+
const imageCount = editor ? (editor.getHTML().match(/<img\b/gi) ?? []).length : 0;
|
|
10799
|
+
const currentCount = attachmentsRef.current.length + imageCount;
|
|
10800
|
+
const remaining = Math.max(0, maxFiles - currentCount);
|
|
10801
|
+
if (accepted.length > remaining) {
|
|
10802
|
+
toast.error(`\uD30C\uC77C\uC740 \uCD5C\uB300 ${maxFiles}\uAC1C\uAE4C\uC9C0 \uCCA8\uBD80\uD560 \uC218 \uC788\uC2B5\uB2C8\uB2E4.`);
|
|
10803
|
+
}
|
|
10804
|
+
accepted = accepted.slice(0, remaining);
|
|
10805
|
+
}
|
|
10776
10806
|
if (accepted.length === 0) return;
|
|
10777
10807
|
setIsUploading(true);
|
|
10778
10808
|
try {
|
|
@@ -10805,7 +10835,7 @@ function useRichEditorFiles(options = {}) {
|
|
|
10805
10835
|
setIsUploading(false);
|
|
10806
10836
|
}
|
|
10807
10837
|
},
|
|
10808
|
-
[fileFormat, onFileUpload]
|
|
10838
|
+
[fileFormat, maxFiles, onFileUpload]
|
|
10809
10839
|
);
|
|
10810
10840
|
return { attachments, processFiles, removeAttachment, hydrateAttachments, isUploading };
|
|
10811
10841
|
}
|
|
@@ -10880,6 +10910,7 @@ function useRichEditor(options = {}) {
|
|
|
10880
10910
|
editorClassName,
|
|
10881
10911
|
additionalExtensions = [],
|
|
10882
10912
|
fileFormat,
|
|
10913
|
+
maxFiles,
|
|
10883
10914
|
onFileUpload,
|
|
10884
10915
|
onChange,
|
|
10885
10916
|
onSubmit
|
|
@@ -10896,9 +10927,11 @@ function useRichEditor(options = {}) {
|
|
|
10896
10927
|
const initialSplit = initialSplitRef.current;
|
|
10897
10928
|
const { attachments, processFiles, removeAttachment, hydrateAttachments, isUploading } = useRichEditorFiles({
|
|
10898
10929
|
fileFormat,
|
|
10930
|
+
maxFiles,
|
|
10899
10931
|
onFileUpload,
|
|
10900
10932
|
initialAttachments: initialSplit.attachments
|
|
10901
10933
|
});
|
|
10934
|
+
const [imageCount, setImageCount] = React6.useState(() => (initialSplit.html.match(/<img\b/gi) ?? []).length);
|
|
10902
10935
|
const attachmentsRef = React6.useRef(attachments);
|
|
10903
10936
|
attachmentsRef.current = attachments;
|
|
10904
10937
|
const editorRef = React6.useRef(null);
|
|
@@ -10940,6 +10973,15 @@ function useRichEditor(options = {}) {
|
|
|
10940
10973
|
}
|
|
10941
10974
|
});
|
|
10942
10975
|
editorRef.current = editor;
|
|
10976
|
+
React6.useEffect(() => {
|
|
10977
|
+
if (!editor) return;
|
|
10978
|
+
const sync = () => setImageCount((editor.getHTML().match(/<img\b/gi) ?? []).length);
|
|
10979
|
+
sync();
|
|
10980
|
+
editor.on("transaction", sync);
|
|
10981
|
+
return () => {
|
|
10982
|
+
editor.off("transaction", sync);
|
|
10983
|
+
};
|
|
10984
|
+
}, [editor]);
|
|
10943
10985
|
React6.useEffect(() => {
|
|
10944
10986
|
if (!editor) return;
|
|
10945
10987
|
onChangeRef.current?.(composeRichEditorHtml(editor.getHTML(), attachments));
|
|
@@ -10964,6 +11006,7 @@ function useRichEditor(options = {}) {
|
|
|
10964
11006
|
},
|
|
10965
11007
|
isEmpty: editor?.isEmpty ?? true,
|
|
10966
11008
|
attachments,
|
|
11009
|
+
attachmentCount: imageCount + attachments.length,
|
|
10967
11010
|
removeAttachment,
|
|
10968
11011
|
hydrateAttachments,
|
|
10969
11012
|
processFiles: processFilesRef.current,
|
|
@@ -11556,7 +11599,7 @@ function RichEditorToolbar(props) {
|
|
|
11556
11599
|
);
|
|
11557
11600
|
}
|
|
11558
11601
|
function RichEditorDropZone(props) {
|
|
11559
|
-
const { children, className, "data-rich-editor-theme": themeAttr } = props;
|
|
11602
|
+
const { children, className, "data-rich-editor-theme": themeAttr, onDropFiles } = props;
|
|
11560
11603
|
const theme = useRichEditorTheme();
|
|
11561
11604
|
const [isDragging, setIsDragging] = React6.useState(false);
|
|
11562
11605
|
const counterRef = React6.useRef(0);
|
|
@@ -11577,6 +11620,9 @@ function RichEditorDropZone(props) {
|
|
|
11577
11620
|
e.preventDefault();
|
|
11578
11621
|
counterRef.current = 0;
|
|
11579
11622
|
setIsDragging(false);
|
|
11623
|
+
if (e.nativeEvent[RICH_EDITOR_DROP_HANDLED]) return;
|
|
11624
|
+
const files = Array.from(e.dataTransfer.files ?? []);
|
|
11625
|
+
if (files.length > 0) onDropFiles?.(files);
|
|
11580
11626
|
};
|
|
11581
11627
|
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
11582
11628
|
"div",
|
|
@@ -11740,8 +11786,10 @@ var RichEditor = React6.forwardRef(function RichEditor2({
|
|
|
11740
11786
|
editable = true,
|
|
11741
11787
|
autofocus,
|
|
11742
11788
|
fileFormat,
|
|
11789
|
+
maxFiles,
|
|
11743
11790
|
onFileUpload,
|
|
11744
|
-
renderFilePreview
|
|
11791
|
+
renderFilePreview,
|
|
11792
|
+
fileCountUIRender
|
|
11745
11793
|
}, ref) {
|
|
11746
11794
|
const showToolbar = toolbar !== false;
|
|
11747
11795
|
const toolbarOptions = typeof toolbar === "object" ? toolbar : {};
|
|
@@ -11761,6 +11809,7 @@ var RichEditor = React6.forwardRef(function RichEditor2({
|
|
|
11761
11809
|
const {
|
|
11762
11810
|
editor,
|
|
11763
11811
|
attachments,
|
|
11812
|
+
attachmentCount,
|
|
11764
11813
|
removeAttachment,
|
|
11765
11814
|
hydrateAttachments,
|
|
11766
11815
|
processFiles,
|
|
@@ -11783,6 +11832,7 @@ var RichEditor = React6.forwardRef(function RichEditor2({
|
|
|
11783
11832
|
autofocus,
|
|
11784
11833
|
editorClassName,
|
|
11785
11834
|
fileFormat,
|
|
11835
|
+
maxFiles,
|
|
11786
11836
|
onFileUpload,
|
|
11787
11837
|
onChange: handleChange,
|
|
11788
11838
|
onSubmit
|
|
@@ -11832,7 +11882,8 @@ var RichEditor = React6.forwardRef(function RichEditor2({
|
|
|
11832
11882
|
...accentColor ? { "--rich-editor-accent-bg": accentColor } : {},
|
|
11833
11883
|
...accentTextColor ? { "--rich-editor-accent-text": accentTextColor } : {}
|
|
11834
11884
|
};
|
|
11835
|
-
|
|
11885
|
+
const showFileCountUI = imageFeatureEnabled && !!fileCountUIRender;
|
|
11886
|
+
const editorBox = /* @__PURE__ */ jsxRuntime.jsxs(
|
|
11836
11887
|
"div",
|
|
11837
11888
|
{
|
|
11838
11889
|
className: cn("overflow-hidden rounded-lg border border-gray-200 shadow-sm flex flex-col relative", className),
|
|
@@ -11863,7 +11914,7 @@ var RichEditor = React6.forwardRef(function RichEditor2({
|
|
|
11863
11914
|
}
|
|
11864
11915
|
}
|
|
11865
11916
|
),
|
|
11866
|
-
imageFeatureEnabled ? /* @__PURE__ */ jsxRuntime.jsxs(RichEditorDropZone, { className: "flex flex-1 flex-col", "data-rich-editor-theme": theme, children: [
|
|
11917
|
+
imageFeatureEnabled ? /* @__PURE__ */ jsxRuntime.jsxs(RichEditorDropZone, { className: "flex flex-1 flex-col", "data-rich-editor-theme": theme, onDropFiles: processFiles, children: [
|
|
11867
11918
|
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11868
11919
|
RichEditorContent,
|
|
11869
11920
|
{
|
|
@@ -11893,7 +11944,16 @@ var RichEditor = React6.forwardRef(function RichEditor2({
|
|
|
11893
11944
|
)
|
|
11894
11945
|
]
|
|
11895
11946
|
}
|
|
11896
|
-
)
|
|
11947
|
+
);
|
|
11948
|
+
return /* @__PURE__ */ jsxRuntime.jsx(RichEditorThemeProvider, { value: resolvedTheme, children: showFileCountUI ? (
|
|
11949
|
+
// 바깥에 position: relative 한 단만 더 둬서, fileCountUIRender가 돌려주는 요소가
|
|
11950
|
+
// absolute 포지션이면 에디터 박스 기준으로 겹쳐 뜨고, 일반 요소면 박스 바로 아래
|
|
11951
|
+
// 자연스러운 흐름으로 이어진다 — 호출부가 className 하나로 두 경우를 모두 고를 수 있다.
|
|
11952
|
+
/* @__PURE__ */ jsxRuntime.jsxs("div", { className: "relative", children: [
|
|
11953
|
+
editorBox,
|
|
11954
|
+
fileCountUIRender({ count: attachmentCount, max: maxFiles })
|
|
11955
|
+
] })
|
|
11956
|
+
) : editorBox });
|
|
11897
11957
|
});
|
|
11898
11958
|
var RichEditor_default = RichEditor;
|
|
11899
11959
|
function useDetailController(params = {}) {
|