@farmzone/fz-react-ui 1.1.17 → 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 +204 -31
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +8 -0
- package/dist/index.d.ts +8 -0
- package/dist/index.js +205 -32
- 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,7 +1454,9 @@ interface UseRichEditorReturn {
|
|
|
1448
1454
|
focus: () => void;
|
|
1449
1455
|
isEmpty: boolean;
|
|
1450
1456
|
attachments: FileAttachment[];
|
|
1457
|
+
attachmentCount: number;
|
|
1451
1458
|
removeAttachment: (id: string) => void;
|
|
1459
|
+
hydrateAttachments: (loaded: FileAttachment[]) => void;
|
|
1452
1460
|
processFiles: (files: File[]) => void;
|
|
1453
1461
|
isUploading: boolean;
|
|
1454
1462
|
}
|
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,7 +1454,9 @@ interface UseRichEditorReturn {
|
|
|
1448
1454
|
focus: () => void;
|
|
1449
1455
|
isEmpty: boolean;
|
|
1450
1456
|
attachments: FileAttachment[];
|
|
1457
|
+
attachmentCount: number;
|
|
1451
1458
|
removeAttachment: (id: string) => void;
|
|
1459
|
+
hydrateAttachments: (loaded: FileAttachment[]) => void;
|
|
1452
1460
|
processFiles: (files: File[]) => void;
|
|
1453
1461
|
isUploading: boolean;
|
|
1454
1462
|
}
|
package/dist/index.js
CHANGED
|
@@ -30,7 +30,7 @@ import { createJSONStorage, persist } from 'zustand/middleware';
|
|
|
30
30
|
import { v4 } from 'uuid';
|
|
31
31
|
import heic2any from 'heic2any';
|
|
32
32
|
import { useEditor, useEditorState, EditorContent, ReactRenderer } from '@tiptap/react';
|
|
33
|
-
import { Extension } from '@tiptap/core';
|
|
33
|
+
import { Extension, InputRule } from '@tiptap/core';
|
|
34
34
|
import StarterKit from '@tiptap/starter-kit';
|
|
35
35
|
import TextAlign from '@tiptap/extension-text-align';
|
|
36
36
|
import { Image as Image$1 } from '@tiptap/extension-image';
|
|
@@ -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) {
|
|
@@ -10397,7 +10397,7 @@ function buildExtensions(config) {
|
|
|
10397
10397
|
accentTextColor,
|
|
10398
10398
|
zIndex
|
|
10399
10399
|
} = config;
|
|
10400
|
-
const exts = [TextStyleKit, buildMarkResetOnEnter()];
|
|
10400
|
+
const exts = [TextStyleKit, buildMarkResetOnEnter(), buildRedundantListMarkerStrip()];
|
|
10401
10401
|
const headingLevels = toolbar.heading === false ? [] : Array.isArray(toolbar.heading) ? [...toolbar.heading] : [1, 2, 3, 4];
|
|
10402
10402
|
exts.push(
|
|
10403
10403
|
StarterKit.configure({
|
|
@@ -10573,6 +10573,36 @@ function buildMarkResetOnEnter() {
|
|
|
10573
10573
|
}
|
|
10574
10574
|
});
|
|
10575
10575
|
}
|
|
10576
|
+
function buildRedundantListMarkerStrip() {
|
|
10577
|
+
const bulletMarkerRegex = /^\s*([-+*])\s$/;
|
|
10578
|
+
const orderedMarkerRegex = /^(\d+)\.\s$/;
|
|
10579
|
+
function makeRule(listTypeName, regex) {
|
|
10580
|
+
return new InputRule({
|
|
10581
|
+
find: regex,
|
|
10582
|
+
handler: ({ state, range, chain }) => {
|
|
10583
|
+
const { $from } = state.selection;
|
|
10584
|
+
if ($from.depth < 2) return null;
|
|
10585
|
+
const parent = $from.node($from.depth - 1);
|
|
10586
|
+
const grandparent = $from.node($from.depth - 2);
|
|
10587
|
+
if (parent.type.name !== "listItem" || grandparent.type.name !== listTypeName) {
|
|
10588
|
+
return null;
|
|
10589
|
+
}
|
|
10590
|
+
chain().deleteRange(range).run();
|
|
10591
|
+
return void 0;
|
|
10592
|
+
}
|
|
10593
|
+
});
|
|
10594
|
+
}
|
|
10595
|
+
return Extension.create({
|
|
10596
|
+
name: "redundantListMarkerStrip",
|
|
10597
|
+
priority: 200,
|
|
10598
|
+
addInputRules() {
|
|
10599
|
+
return [
|
|
10600
|
+
makeRule("bulletList", bulletMarkerRegex),
|
|
10601
|
+
makeRule("orderedList", orderedMarkerRegex)
|
|
10602
|
+
];
|
|
10603
|
+
}
|
|
10604
|
+
});
|
|
10605
|
+
}
|
|
10576
10606
|
|
|
10577
10607
|
// src/components/RichEditor/config/keyboardHandlers.ts
|
|
10578
10608
|
function createKeyboardHandler(codeBlockEmptyEnterRef, onSubmitRef) {
|
|
@@ -10663,20 +10693,24 @@ function createPasteHandler(processFilesRef) {
|
|
|
10663
10693
|
return true;
|
|
10664
10694
|
};
|
|
10665
10695
|
}
|
|
10696
|
+
var RICH_EDITOR_DROP_HANDLED = "__richEditorDropHandled";
|
|
10666
10697
|
function createDropHandler(processFilesRef) {
|
|
10667
10698
|
return (_view, event) => {
|
|
10668
10699
|
const files = Array.from(event.dataTransfer?.files ?? []);
|
|
10669
10700
|
if (files.length === 0) return false;
|
|
10670
10701
|
event.preventDefault();
|
|
10702
|
+
event[RICH_EDITOR_DROP_HANDLED] = true;
|
|
10671
10703
|
processFilesRef.current(files);
|
|
10672
10704
|
return true;
|
|
10673
10705
|
};
|
|
10674
10706
|
}
|
|
10707
|
+
|
|
10708
|
+
// src/lib/fileFormat.ts
|
|
10675
10709
|
var FORMAT_EXT_ALIASES = {
|
|
10676
10710
|
JPG: ["jpg", "jpeg"],
|
|
10677
10711
|
JPEG: ["jpg", "jpeg"]
|
|
10678
10712
|
};
|
|
10679
|
-
function
|
|
10713
|
+
function expandFileFormats(fileFormat) {
|
|
10680
10714
|
const exts = /* @__PURE__ */ new Set();
|
|
10681
10715
|
for (const format of fileFormat) {
|
|
10682
10716
|
const key = format.toUpperCase();
|
|
@@ -10685,29 +10719,63 @@ function expandFormats(fileFormat) {
|
|
|
10685
10719
|
}
|
|
10686
10720
|
return exts;
|
|
10687
10721
|
}
|
|
10688
|
-
function
|
|
10722
|
+
function getFileExtension(fileName) {
|
|
10689
10723
|
return fileName.split(".").pop()?.toLowerCase() ?? "";
|
|
10690
10724
|
}
|
|
10691
10725
|
function buildAcceptAttribute(fileFormat) {
|
|
10692
10726
|
if (!fileFormat || fileFormat.length === 0) return void 0;
|
|
10693
|
-
return Array.from(
|
|
10727
|
+
return Array.from(expandFileFormats(fileFormat)).map((ext) => `.${ext}`).join(",");
|
|
10694
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 };
|
|
10738
|
+
}
|
|
10739
|
+
|
|
10740
|
+
// src/components/RichEditor/hooks/useRichEditorFiles.ts
|
|
10695
10741
|
function useRichEditorFiles(options = {}) {
|
|
10696
|
-
const { fileFormat, onFileUpload } = options;
|
|
10697
|
-
const [attachments, setAttachments] = useState([]);
|
|
10742
|
+
const { fileFormat, maxFiles, onFileUpload, initialAttachments } = options;
|
|
10743
|
+
const [attachments, setAttachments] = useState(() => initialAttachments ?? []);
|
|
10744
|
+
const attachmentsRef = useRef(attachments);
|
|
10745
|
+
attachmentsRef.current = attachments;
|
|
10698
10746
|
const [isUploading, setIsUploading] = useState(false);
|
|
10699
10747
|
const removeAttachment = useCallback((id) => {
|
|
10700
10748
|
setAttachments((prev) => prev.filter((a) => a.id !== id));
|
|
10701
10749
|
}, []);
|
|
10750
|
+
const hydrateAttachments = useCallback((loaded) => {
|
|
10751
|
+
setAttachments(loaded);
|
|
10752
|
+
}, []);
|
|
10702
10753
|
const processFiles = useCallback(
|
|
10703
10754
|
async (files, editor) => {
|
|
10704
|
-
const
|
|
10705
|
-
|
|
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
|
+
}
|
|
10706
10769
|
if (accepted.length === 0) return;
|
|
10707
10770
|
setIsUploading(true);
|
|
10708
10771
|
try {
|
|
10709
10772
|
for (const file of accepted) {
|
|
10710
|
-
|
|
10773
|
+
let url;
|
|
10774
|
+
try {
|
|
10775
|
+
url = await (onFileUpload ? onFileUpload(file) : URL.createObjectURL(file));
|
|
10776
|
+
} catch {
|
|
10777
|
+
continue;
|
|
10778
|
+
}
|
|
10711
10779
|
if (file.type.startsWith("image/")) {
|
|
10712
10780
|
if (!editor) continue;
|
|
10713
10781
|
editor.chain().focus().insertContent({ type: "image", attrs: { src: url } }).run();
|
|
@@ -10730,9 +10798,60 @@ function useRichEditorFiles(options = {}) {
|
|
|
10730
10798
|
setIsUploading(false);
|
|
10731
10799
|
}
|
|
10732
10800
|
},
|
|
10733
|
-
[fileFormat, onFileUpload]
|
|
10801
|
+
[fileFormat, maxFiles, onFileUpload]
|
|
10734
10802
|
);
|
|
10735
|
-
return { attachments, processFiles, removeAttachment, isUploading };
|
|
10803
|
+
return { attachments, processFiles, removeAttachment, hydrateAttachments, isUploading };
|
|
10804
|
+
}
|
|
10805
|
+
|
|
10806
|
+
// src/components/RichEditor/config/attachmentSerialization.ts
|
|
10807
|
+
var ATTACHMENTS_CONTAINER_ATTR = "data-rich-editor-attachments";
|
|
10808
|
+
var ATTACHMENT_ITEM_ATTR = "data-rich-editor-attachment";
|
|
10809
|
+
function escapeHtmlAttr(value) {
|
|
10810
|
+
return value.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
10811
|
+
}
|
|
10812
|
+
function escapeHtmlText(value) {
|
|
10813
|
+
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
10814
|
+
}
|
|
10815
|
+
function serializeAttachmentsBlock(attachments) {
|
|
10816
|
+
if (attachments.length === 0) return "";
|
|
10817
|
+
const items = attachments.map((attachment) => {
|
|
10818
|
+
const href = escapeHtmlAttr(attachment.url);
|
|
10819
|
+
const name = escapeHtmlAttr(attachment.name);
|
|
10820
|
+
return `<a ${ATTACHMENT_ITEM_ATTR}="true" href="${href}" data-name="${name}" data-size="${attachment.size}" data-mime="${escapeHtmlAttr(attachment.mimeType)}">${escapeHtmlText(attachment.name)}</a>`;
|
|
10821
|
+
}).join("");
|
|
10822
|
+
return `<div ${ATTACHMENTS_CONTAINER_ATTR}="true">${items}</div>`;
|
|
10823
|
+
}
|
|
10824
|
+
function splitAttachmentsFromHtml(html) {
|
|
10825
|
+
if (!html || !html.includes(ATTACHMENTS_CONTAINER_ATTR) || typeof DOMParser === "undefined") {
|
|
10826
|
+
return { html, attachments: [] };
|
|
10827
|
+
}
|
|
10828
|
+
const doc = new DOMParser().parseFromString(html, "text/html");
|
|
10829
|
+
const container2 = doc.body.querySelector(`[${ATTACHMENTS_CONTAINER_ATTR}]`);
|
|
10830
|
+
if (!container2) {
|
|
10831
|
+
return { html, attachments: [] };
|
|
10832
|
+
}
|
|
10833
|
+
const attachments = Array.from(
|
|
10834
|
+
container2.querySelectorAll(`[${ATTACHMENT_ITEM_ATTR}]`)
|
|
10835
|
+
).map((el, index) => {
|
|
10836
|
+
const url = el.getAttribute("href") ?? "";
|
|
10837
|
+
const name = el.getAttribute("data-name") ?? el.textContent ?? `file-${index}`;
|
|
10838
|
+
const mimeType = el.getAttribute("data-mime") ?? "";
|
|
10839
|
+
const size2 = Number(el.getAttribute("data-size") ?? "0") || 0;
|
|
10840
|
+
return {
|
|
10841
|
+
id: `loaded-${index}-${Math.random().toString(36).slice(2)}`,
|
|
10842
|
+
name,
|
|
10843
|
+
size: size2,
|
|
10844
|
+
mimeType,
|
|
10845
|
+
file: new File([], name, { type: mimeType }),
|
|
10846
|
+
url
|
|
10847
|
+
};
|
|
10848
|
+
});
|
|
10849
|
+
container2.remove();
|
|
10850
|
+
return { html: doc.body.innerHTML, attachments };
|
|
10851
|
+
}
|
|
10852
|
+
function composeRichEditorHtml(bodyHtml, attachments) {
|
|
10853
|
+
const block = serializeAttachmentsBlock(attachments);
|
|
10854
|
+
return block ? `${bodyHtml}${block}` : bodyHtml;
|
|
10736
10855
|
}
|
|
10737
10856
|
|
|
10738
10857
|
// src/components/RichEditor/hooks/useRichEditor.ts
|
|
@@ -10754,6 +10873,7 @@ function useRichEditor(options = {}) {
|
|
|
10754
10873
|
editorClassName,
|
|
10755
10874
|
additionalExtensions = [],
|
|
10756
10875
|
fileFormat,
|
|
10876
|
+
maxFiles,
|
|
10757
10877
|
onFileUpload,
|
|
10758
10878
|
onChange,
|
|
10759
10879
|
onSubmit
|
|
@@ -10763,10 +10883,20 @@ function useRichEditor(options = {}) {
|
|
|
10763
10883
|
onChangeRef.current = onChange;
|
|
10764
10884
|
const onSubmitRef = useRef(onSubmit);
|
|
10765
10885
|
onSubmitRef.current = onSubmit;
|
|
10766
|
-
const
|
|
10886
|
+
const initialSplitRef = useRef(null);
|
|
10887
|
+
if (initialSplitRef.current === null) {
|
|
10888
|
+
initialSplitRef.current = splitAttachmentsFromHtml(defaultValue ?? "");
|
|
10889
|
+
}
|
|
10890
|
+
const initialSplit = initialSplitRef.current;
|
|
10891
|
+
const { attachments, processFiles, removeAttachment, hydrateAttachments, isUploading } = useRichEditorFiles({
|
|
10767
10892
|
fileFormat,
|
|
10768
|
-
|
|
10893
|
+
maxFiles,
|
|
10894
|
+
onFileUpload,
|
|
10895
|
+
initialAttachments: initialSplit.attachments
|
|
10769
10896
|
});
|
|
10897
|
+
const [imageCount, setImageCount] = useState(() => (initialSplit.html.match(/<img\b/gi) ?? []).length);
|
|
10898
|
+
const attachmentsRef = useRef(attachments);
|
|
10899
|
+
attachmentsRef.current = attachments;
|
|
10770
10900
|
const editorRef = useRef(null);
|
|
10771
10901
|
const processFilesRef = useRef(() => {
|
|
10772
10902
|
});
|
|
@@ -10800,21 +10930,36 @@ function useRichEditor(options = {}) {
|
|
|
10800
10930
|
handleDrop: createDropHandler(processFilesRef)
|
|
10801
10931
|
} : {}
|
|
10802
10932
|
},
|
|
10803
|
-
content:
|
|
10933
|
+
content: initialSplit.html,
|
|
10804
10934
|
onUpdate: ({ editor: editor2 }) => {
|
|
10805
|
-
onChangeRef.current?.(editor2.getHTML());
|
|
10935
|
+
onChangeRef.current?.(composeRichEditorHtml(editor2.getHTML(), attachmentsRef.current));
|
|
10806
10936
|
}
|
|
10807
10937
|
});
|
|
10808
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]);
|
|
10948
|
+
useEffect(() => {
|
|
10949
|
+
if (!editor) return;
|
|
10950
|
+
onChangeRef.current?.(composeRichEditorHtml(editor.getHTML(), attachments));
|
|
10951
|
+
}, [attachments]);
|
|
10809
10952
|
useEffect(() => {
|
|
10810
10953
|
if (editor) editor.setEditable(editable && !isUploading);
|
|
10811
10954
|
}, [editor, editable, isUploading]);
|
|
10812
10955
|
return {
|
|
10813
10956
|
editor,
|
|
10814
|
-
getHTML: () => editor?.getHTML() ?? "",
|
|
10957
|
+
getHTML: () => composeRichEditorHtml(editor?.getHTML() ?? "", attachments),
|
|
10815
10958
|
getJSON: () => editor?.getJSON() ?? {},
|
|
10816
10959
|
setContent: (html) => {
|
|
10817
|
-
|
|
10960
|
+
const split = splitAttachmentsFromHtml(html);
|
|
10961
|
+
editor?.commands.setContent(split.html);
|
|
10962
|
+
hydrateAttachments(split.attachments);
|
|
10818
10963
|
},
|
|
10819
10964
|
clearContent: () => {
|
|
10820
10965
|
editor?.commands.clearContent();
|
|
@@ -10824,7 +10969,9 @@ function useRichEditor(options = {}) {
|
|
|
10824
10969
|
},
|
|
10825
10970
|
isEmpty: editor?.isEmpty ?? true,
|
|
10826
10971
|
attachments,
|
|
10972
|
+
attachmentCount: imageCount + attachments.length,
|
|
10827
10973
|
removeAttachment,
|
|
10974
|
+
hydrateAttachments,
|
|
10828
10975
|
processFiles: processFilesRef.current,
|
|
10829
10976
|
isUploading
|
|
10830
10977
|
};
|
|
@@ -11415,7 +11562,7 @@ function RichEditorToolbar(props) {
|
|
|
11415
11562
|
);
|
|
11416
11563
|
}
|
|
11417
11564
|
function RichEditorDropZone(props) {
|
|
11418
|
-
const { children, className, "data-rich-editor-theme": themeAttr } = props;
|
|
11565
|
+
const { children, className, "data-rich-editor-theme": themeAttr, onDropFiles } = props;
|
|
11419
11566
|
const theme = useRichEditorTheme();
|
|
11420
11567
|
const [isDragging, setIsDragging] = useState(false);
|
|
11421
11568
|
const counterRef = useRef(0);
|
|
@@ -11436,6 +11583,9 @@ function RichEditorDropZone(props) {
|
|
|
11436
11583
|
e.preventDefault();
|
|
11437
11584
|
counterRef.current = 0;
|
|
11438
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);
|
|
11439
11589
|
};
|
|
11440
11590
|
return /* @__PURE__ */ jsxs(
|
|
11441
11591
|
"div",
|
|
@@ -11599,8 +11749,10 @@ var RichEditor = forwardRef(function RichEditor2({
|
|
|
11599
11749
|
editable = true,
|
|
11600
11750
|
autofocus,
|
|
11601
11751
|
fileFormat,
|
|
11752
|
+
maxFiles,
|
|
11602
11753
|
onFileUpload,
|
|
11603
|
-
renderFilePreview
|
|
11754
|
+
renderFilePreview,
|
|
11755
|
+
fileCountUIRender
|
|
11604
11756
|
}, ref) {
|
|
11605
11757
|
const showToolbar = toolbar !== false;
|
|
11606
11758
|
const toolbarOptions = typeof toolbar === "object" ? toolbar : {};
|
|
@@ -11617,7 +11769,17 @@ var RichEditor = forwardRef(function RichEditor2({
|
|
|
11617
11769
|
},
|
|
11618
11770
|
[onChange]
|
|
11619
11771
|
);
|
|
11620
|
-
const {
|
|
11772
|
+
const {
|
|
11773
|
+
editor,
|
|
11774
|
+
attachments,
|
|
11775
|
+
attachmentCount,
|
|
11776
|
+
removeAttachment,
|
|
11777
|
+
hydrateAttachments,
|
|
11778
|
+
processFiles,
|
|
11779
|
+
isUploading,
|
|
11780
|
+
getHTML,
|
|
11781
|
+
setContent
|
|
11782
|
+
} = useRichEditor({
|
|
11621
11783
|
defaultValue: value ?? defaultValue,
|
|
11622
11784
|
toolbar: activeToolbar,
|
|
11623
11785
|
mentionUsers,
|
|
@@ -11633,6 +11795,7 @@ var RichEditor = forwardRef(function RichEditor2({
|
|
|
11633
11795
|
autofocus,
|
|
11634
11796
|
editorClassName,
|
|
11635
11797
|
fileFormat,
|
|
11798
|
+
maxFiles,
|
|
11636
11799
|
onFileUpload,
|
|
11637
11800
|
onChange: handleChange,
|
|
11638
11801
|
onSubmit
|
|
@@ -11644,18 +11807,18 @@ var RichEditor = forwardRef(function RichEditor2({
|
|
|
11644
11807
|
isInternalChangeRef.current = false;
|
|
11645
11808
|
return;
|
|
11646
11809
|
}
|
|
11647
|
-
if (
|
|
11648
|
-
|
|
11810
|
+
if (getHTML() !== value) {
|
|
11811
|
+
const split = splitAttachmentsFromHtml(value);
|
|
11812
|
+
editor.commands.setContent(split.html, { emitUpdate: false });
|
|
11813
|
+
hydrateAttachments(split.attachments);
|
|
11649
11814
|
}
|
|
11650
11815
|
}, [value, editor]);
|
|
11651
11816
|
useImperativeHandle(
|
|
11652
11817
|
ref,
|
|
11653
11818
|
() => ({
|
|
11654
|
-
getHTML
|
|
11819
|
+
getHTML,
|
|
11655
11820
|
getJSON: () => editor?.getJSON() ?? {},
|
|
11656
|
-
setContent
|
|
11657
|
-
editor?.commands.setContent(html);
|
|
11658
|
-
},
|
|
11821
|
+
setContent,
|
|
11659
11822
|
clearContent: () => {
|
|
11660
11823
|
editor?.commands.clearContent();
|
|
11661
11824
|
},
|
|
@@ -11668,7 +11831,7 @@ var RichEditor = forwardRef(function RichEditor2({
|
|
|
11668
11831
|
attachments,
|
|
11669
11832
|
editor
|
|
11670
11833
|
}),
|
|
11671
|
-
[editor, attachments]
|
|
11834
|
+
[editor, attachments, getHTML, setContent]
|
|
11672
11835
|
);
|
|
11673
11836
|
const isToolbarVisible = showToolbar && editable;
|
|
11674
11837
|
const imageFeatureEnabled = activeToolbar.image !== false;
|
|
@@ -11682,7 +11845,8 @@ var RichEditor = forwardRef(function RichEditor2({
|
|
|
11682
11845
|
...accentColor ? { "--rich-editor-accent-bg": accentColor } : {},
|
|
11683
11846
|
...accentTextColor ? { "--rich-editor-accent-text": accentTextColor } : {}
|
|
11684
11847
|
};
|
|
11685
|
-
|
|
11848
|
+
const showFileCountUI = imageFeatureEnabled && !!fileCountUIRender;
|
|
11849
|
+
const editorBox = /* @__PURE__ */ jsxs(
|
|
11686
11850
|
"div",
|
|
11687
11851
|
{
|
|
11688
11852
|
className: cn("overflow-hidden rounded-lg border border-gray-200 shadow-sm flex flex-col relative", className),
|
|
@@ -11713,7 +11877,7 @@ var RichEditor = forwardRef(function RichEditor2({
|
|
|
11713
11877
|
}
|
|
11714
11878
|
}
|
|
11715
11879
|
),
|
|
11716
|
-
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: [
|
|
11717
11881
|
/* @__PURE__ */ jsx(
|
|
11718
11882
|
RichEditorContent,
|
|
11719
11883
|
{
|
|
@@ -11743,7 +11907,16 @@ var RichEditor = forwardRef(function RichEditor2({
|
|
|
11743
11907
|
)
|
|
11744
11908
|
]
|
|
11745
11909
|
}
|
|
11746
|
-
)
|
|
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 });
|
|
11747
11920
|
});
|
|
11748
11921
|
var RichEditor_default = RichEditor;
|
|
11749
11922
|
function useDetailController(params = {}) {
|