@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.d.cts CHANGED
@@ -1332,6 +1332,15 @@ interface RichEditorThemeOverride {
1332
1332
  mention?: Partial<RichEditorThemeTokens["mention"]>;
1333
1333
  }
1334
1334
 
1335
+ interface FileAttachment {
1336
+ id: string;
1337
+ name: string;
1338
+ size: number;
1339
+ mimeType: string;
1340
+ file: File;
1341
+ url: string;
1342
+ }
1343
+
1335
1344
  type RichEditorHeadingLevel = 1 | 2 | 3 | 4;
1336
1345
  interface MentionItem {
1337
1346
  id: string;
@@ -1363,6 +1372,7 @@ interface RichEditorHandle {
1363
1372
  clearContent: () => void;
1364
1373
  focus: () => void;
1365
1374
  isEmpty: boolean;
1375
+ attachments: FileAttachment[];
1366
1376
  editor: _tiptap_core.Editor | null;
1367
1377
  }
1368
1378
  interface RichEditorProps {
@@ -1390,6 +1400,9 @@ interface RichEditorProps {
1390
1400
  editable?: boolean;
1391
1401
  autofocus?: boolean | "start" | "end" | "all" | null;
1392
1402
  onSubmit?: () => void;
1403
+ fileFormat?: ReadonlyArray<string>;
1404
+ onFileUpload?: (file: File) => string | Promise<string>;
1405
+ renderFilePreview?: (attachment: FileAttachment, onRemove: () => void) => ReactNode;
1393
1406
  }
1394
1407
  interface UseRichEditorOptions {
1395
1408
  defaultValue?: string;
@@ -1406,6 +1419,8 @@ interface UseRichEditorOptions {
1406
1419
  autofocus?: boolean | "start" | "end" | "all" | null;
1407
1420
  editorClassName?: string;
1408
1421
  additionalExtensions?: Extensions;
1422
+ fileFormat?: ReadonlyArray<string>;
1423
+ onFileUpload?: (file: File) => string | Promise<string>;
1409
1424
  onChange?: (html: string) => void;
1410
1425
  onSubmit?: () => void;
1411
1426
  }
@@ -1421,6 +1436,7 @@ interface RichEditorToolbarProps {
1421
1436
  toolbar?: RichEditorToolbarConfig;
1422
1437
  className?: string;
1423
1438
  zIndex?: number;
1439
+ onImageButtonClick?: () => void;
1424
1440
  }
1425
1441
 
1426
1442
  interface UseRichEditorReturn {
@@ -1431,6 +1447,10 @@ interface UseRichEditorReturn {
1431
1447
  clearContent: () => void;
1432
1448
  focus: () => void;
1433
1449
  isEmpty: boolean;
1450
+ attachments: FileAttachment[];
1451
+ removeAttachment: (id: string) => void;
1452
+ processFiles: (files: File[]) => void;
1453
+ isUploading: boolean;
1434
1454
  }
1435
1455
  declare function useRichEditor(options?: UseRichEditorOptions): UseRichEditorReturn;
1436
1456
 
package/dist/index.d.ts CHANGED
@@ -1332,6 +1332,15 @@ interface RichEditorThemeOverride {
1332
1332
  mention?: Partial<RichEditorThemeTokens["mention"]>;
1333
1333
  }
1334
1334
 
1335
+ interface FileAttachment {
1336
+ id: string;
1337
+ name: string;
1338
+ size: number;
1339
+ mimeType: string;
1340
+ file: File;
1341
+ url: string;
1342
+ }
1343
+
1335
1344
  type RichEditorHeadingLevel = 1 | 2 | 3 | 4;
1336
1345
  interface MentionItem {
1337
1346
  id: string;
@@ -1363,6 +1372,7 @@ interface RichEditorHandle {
1363
1372
  clearContent: () => void;
1364
1373
  focus: () => void;
1365
1374
  isEmpty: boolean;
1375
+ attachments: FileAttachment[];
1366
1376
  editor: _tiptap_core.Editor | null;
1367
1377
  }
1368
1378
  interface RichEditorProps {
@@ -1390,6 +1400,9 @@ interface RichEditorProps {
1390
1400
  editable?: boolean;
1391
1401
  autofocus?: boolean | "start" | "end" | "all" | null;
1392
1402
  onSubmit?: () => void;
1403
+ fileFormat?: ReadonlyArray<string>;
1404
+ onFileUpload?: (file: File) => string | Promise<string>;
1405
+ renderFilePreview?: (attachment: FileAttachment, onRemove: () => void) => ReactNode;
1393
1406
  }
1394
1407
  interface UseRichEditorOptions {
1395
1408
  defaultValue?: string;
@@ -1406,6 +1419,8 @@ interface UseRichEditorOptions {
1406
1419
  autofocus?: boolean | "start" | "end" | "all" | null;
1407
1420
  editorClassName?: string;
1408
1421
  additionalExtensions?: Extensions;
1422
+ fileFormat?: ReadonlyArray<string>;
1423
+ onFileUpload?: (file: File) => string | Promise<string>;
1409
1424
  onChange?: (html: string) => void;
1410
1425
  onSubmit?: () => void;
1411
1426
  }
@@ -1421,6 +1436,7 @@ interface RichEditorToolbarProps {
1421
1436
  toolbar?: RichEditorToolbarConfig;
1422
1437
  className?: string;
1423
1438
  zIndex?: number;
1439
+ onImageButtonClick?: () => void;
1424
1440
  }
1425
1441
 
1426
1442
  interface UseRichEditorReturn {
@@ -1431,6 +1447,10 @@ interface UseRichEditorReturn {
1431
1447
  clearContent: () => void;
1432
1448
  focus: () => void;
1433
1449
  isEmpty: boolean;
1450
+ attachments: FileAttachment[];
1451
+ removeAttachment: (id: string) => void;
1452
+ processFiles: (files: File[]) => void;
1453
+ isUploading: boolean;
1434
1454
  }
1435
1455
  declare function useRichEditor(options?: UseRichEditorOptions): UseRichEditorReturn;
1436
1456
 
package/dist/index.js CHANGED
@@ -6,7 +6,7 @@ import * as React6 from 'react';
6
6
  import React6__default, { forwardRef, useState, useRef, useEffect, useImperativeHandle, useCallback, memo, createContext, useContext, useMemo, useId, useLayoutEffect, useDeferredValue, Fragment as Fragment$1 } from 'react';
7
7
  import { Slot } from '@radix-ui/react-slot';
8
8
  import * as TooltipPrimitive from '@radix-ui/react-tooltip';
9
- import { ChevronLeft, ChevronRight, FileText, ZoomIn, ZoomOut, RotateCcw, RotateCw, Download, X, Heading1, Heading2, Heading3, Heading4, Bold, Italic, Strikethrough, Code, Baseline, AlignLeft, AlignCenter, AlignRight, List, ListOrdered, Quote, FileCode, Table as Table$1, Plus, Minus, Trash2, Check, CircleX, EyeOff, Eye, ChevronDown, Calendar, CircleIcon, ChevronUp, ChevronsLeft, ChevronsRight, Search, TriangleAlert, Info, Pencil, BadgePlus, FileSearch2, Upload, FileUp, PanelRightClose, PanelLeftClose, ChevronFirst, ChevronLast, MoreHorizontal } from 'lucide-react';
9
+ import { ChevronLeft, ChevronRight, FileText, ZoomIn, ZoomOut, RotateCcw, RotateCw, Download, X, Heading1, Heading2, Heading3, Heading4, Bold, Italic, Strikethrough, Code, Baseline, AlignLeft, AlignCenter, AlignRight, List, ListOrdered, Quote, FileCode, Image, Table as Table$1, Plus, Minus, Trash2, Upload, Check, CircleX, EyeOff, Eye, ChevronDown, Calendar, CircleIcon, ChevronUp, ChevronsLeft, ChevronsRight, Search, TriangleAlert, Info, Pencil, BadgePlus, FileSearch2, FileUp, PanelRightClose, PanelLeftClose, ChevronFirst, ChevronLast, MoreHorizontal } from 'lucide-react';
10
10
  import * as SwitchPrimitive from '@radix-ui/react-switch';
11
11
  import * as RadixSlider from '@radix-ui/react-slider';
12
12
  import * as SelectPrimitive from '@radix-ui/react-select';
@@ -33,7 +33,7 @@ import { useEditor, useEditorState, EditorContent, ReactRenderer } from '@tiptap
33
33
  import { Extension } from '@tiptap/core';
34
34
  import StarterKit from '@tiptap/starter-kit';
35
35
  import TextAlign from '@tiptap/extension-text-align';
36
- import { Image } from '@tiptap/extension-image';
36
+ import { Image as Image$1 } from '@tiptap/extension-image';
37
37
  import { TextStyleKit } from '@tiptap/extension-text-style';
38
38
  import { Heading } from '@tiptap/extension-heading';
39
39
  import { Placeholder } from '@tiptap/extension-placeholder';
@@ -1774,10 +1774,12 @@ var ToastManager = class _ToastManager {
1774
1774
  const props = this.resolveProps(rawProps);
1775
1775
  const position = props.position || "top-center";
1776
1776
  const duration = props.duration !== void 0 ? props.duration : 1500;
1777
+ const isSameToast = (other) => (other.props.type ?? "info") === (props.type ?? "info") && other.props.toast === props.toast;
1777
1778
  if (props.id) {
1778
1779
  for (const [pos, toasts] of this.toasts.entries()) {
1779
1780
  const existing = toasts.find((t) => t.id === props.id);
1780
1781
  if (existing) {
1782
+ if (isSameToast(existing)) return existing.id;
1781
1783
  if (existing.timer) clearTimeout(existing.timer);
1782
1784
  const updated = toasts.filter((t) => t.id !== props.id);
1783
1785
  this.toasts.set(pos, updated);
@@ -1788,7 +1790,9 @@ var ToastManager = class _ToastManager {
1788
1790
  }
1789
1791
  }
1790
1792
  const positionToasts = this.toasts.get(position) || [];
1791
- if (positionToasts.length > 0) {
1793
+ const existingAtPosition = positionToasts[0];
1794
+ if (existingAtPosition) {
1795
+ if (isSameToast(existingAtPosition)) return existingAtPosition.id;
1792
1796
  positionToasts.forEach((toast2) => {
1793
1797
  if (toast2.timer) clearTimeout(toast2.timer);
1794
1798
  });
@@ -3238,25 +3242,24 @@ function SearchBar(props) {
3238
3242
  function DebouncedButton(props) {
3239
3243
  const { debounceDelay = 300, onClick, className, ...rest } = props;
3240
3244
  const [isDebouncing, setIsDebouncing] = useState(false);
3245
+ const onClickRef = useRef(onClick);
3246
+ onClickRef.current = onClick;
3241
3247
  const debouncedOnClick = useMemo(() => {
3242
- if (!onClick) return void 0;
3243
3248
  return debounce((event) => {
3244
3249
  setIsDebouncing(false);
3245
- onClick(event);
3250
+ onClickRef.current?.(event);
3246
3251
  }, debounceDelay);
3247
- }, [debounceDelay, onClick]);
3252
+ }, [debounceDelay]);
3248
3253
  useEffect(() => {
3249
3254
  return () => {
3250
- debouncedOnClick?.cancel();
3255
+ debouncedOnClick.cancel();
3251
3256
  setIsDebouncing(false);
3252
3257
  };
3253
3258
  }, [debouncedOnClick]);
3254
3259
  const handleClick = (event) => {
3255
- if (debouncedOnClick) {
3260
+ if (onClickRef.current) {
3256
3261
  setIsDebouncing(true);
3257
3262
  debouncedOnClick(event);
3258
- } else {
3259
- onClick?.(event);
3260
3263
  }
3261
3264
  };
3262
3265
  return /* @__PURE__ */ jsx(
@@ -10522,7 +10525,7 @@ function buildCustomTextAlign() {
10522
10525
  });
10523
10526
  }
10524
10527
  function buildCustomImage() {
10525
- const CustomImage = Image.extend({
10528
+ const CustomImage = Image$1.extend({
10526
10529
  addAttributes() {
10527
10530
  return {
10528
10531
  ...this.parent?.(),
@@ -10650,8 +10653,90 @@ function createKeyboardHandler(codeBlockEmptyEnterRef, onSubmitRef) {
10650
10653
  };
10651
10654
  }
10652
10655
 
10656
+ // src/components/RichEditor/config/fileHandlers.ts
10657
+ function createPasteHandler(processFilesRef) {
10658
+ return (_view, event) => {
10659
+ const files = Array.from(event.clipboardData?.files ?? []);
10660
+ if (files.length === 0) return false;
10661
+ event.preventDefault();
10662
+ processFilesRef.current(files);
10663
+ return true;
10664
+ };
10665
+ }
10666
+ function createDropHandler(processFilesRef) {
10667
+ return (_view, event) => {
10668
+ const files = Array.from(event.dataTransfer?.files ?? []);
10669
+ if (files.length === 0) return false;
10670
+ event.preventDefault();
10671
+ processFilesRef.current(files);
10672
+ return true;
10673
+ };
10674
+ }
10675
+ var FORMAT_EXT_ALIASES = {
10676
+ JPG: ["jpg", "jpeg"],
10677
+ JPEG: ["jpg", "jpeg"]
10678
+ };
10679
+ function expandFormats(fileFormat) {
10680
+ const exts = /* @__PURE__ */ new Set();
10681
+ for (const format of fileFormat) {
10682
+ const key = format.toUpperCase();
10683
+ const aliases = FORMAT_EXT_ALIASES[key] ?? [format.toLowerCase()];
10684
+ aliases.forEach((ext) => exts.add(ext));
10685
+ }
10686
+ return exts;
10687
+ }
10688
+ function extOf(fileName) {
10689
+ return fileName.split(".").pop()?.toLowerCase() ?? "";
10690
+ }
10691
+ function buildAcceptAttribute(fileFormat) {
10692
+ if (!fileFormat || fileFormat.length === 0) return void 0;
10693
+ return Array.from(expandFormats(fileFormat)).map((ext) => `.${ext}`).join(",");
10694
+ }
10695
+ function useRichEditorFiles(options = {}) {
10696
+ const { fileFormat, onFileUpload } = options;
10697
+ const [attachments, setAttachments] = useState([]);
10698
+ const [isUploading, setIsUploading] = useState(false);
10699
+ const removeAttachment = useCallback((id) => {
10700
+ setAttachments((prev) => prev.filter((a) => a.id !== id));
10701
+ }, []);
10702
+ const processFiles = useCallback(
10703
+ async (files, editor) => {
10704
+ const allowedExts = fileFormat ? expandFormats(fileFormat) : null;
10705
+ const accepted = allowedExts ? files.filter((f) => allowedExts.has(extOf(f.name))) : files;
10706
+ if (accepted.length === 0) return;
10707
+ setIsUploading(true);
10708
+ try {
10709
+ for (const file of accepted) {
10710
+ const url = await (onFileUpload ? onFileUpload(file) : URL.createObjectURL(file));
10711
+ if (file.type.startsWith("image/")) {
10712
+ if (!editor) continue;
10713
+ editor.chain().focus().insertContent({ type: "image", attrs: { src: url } }).run();
10714
+ editor.commands.setTextSelection(editor.state.selection.to);
10715
+ } else {
10716
+ setAttachments((prev) => [
10717
+ ...prev,
10718
+ {
10719
+ id: `${Date.now()}-${Math.random().toString(36).slice(2)}`,
10720
+ name: file.name,
10721
+ size: file.size,
10722
+ mimeType: file.type,
10723
+ file,
10724
+ url
10725
+ }
10726
+ ]);
10727
+ }
10728
+ }
10729
+ } finally {
10730
+ setIsUploading(false);
10731
+ }
10732
+ },
10733
+ [fileFormat, onFileUpload]
10734
+ );
10735
+ return { attachments, processFiles, removeAttachment, isUploading };
10736
+ }
10737
+
10653
10738
  // src/components/RichEditor/hooks/useRichEditor.ts
10654
- var DEFAULT_EDITOR_CLASS = "focus:outline-none";
10739
+ var DEFAULT_EDITOR_CLASS = "focus:outline-none h-full";
10655
10740
  function useRichEditor(options = {}) {
10656
10741
  const {
10657
10742
  defaultValue,
@@ -10668,6 +10753,8 @@ function useRichEditor(options = {}) {
10668
10753
  autofocus,
10669
10754
  editorClassName,
10670
10755
  additionalExtensions = [],
10756
+ fileFormat,
10757
+ onFileUpload,
10671
10758
  onChange,
10672
10759
  onSubmit
10673
10760
  } = options;
@@ -10676,6 +10763,15 @@ function useRichEditor(options = {}) {
10676
10763
  onChangeRef.current = onChange;
10677
10764
  const onSubmitRef = useRef(onSubmit);
10678
10765
  onSubmitRef.current = onSubmit;
10766
+ const { attachments, processFiles, removeAttachment, isUploading } = useRichEditorFiles({
10767
+ fileFormat,
10768
+ onFileUpload
10769
+ });
10770
+ const editorRef = useRef(null);
10771
+ const processFilesRef = useRef(() => {
10772
+ });
10773
+ processFilesRef.current = (files) => processFiles(files, editorRef.current);
10774
+ const imageFeatureEnabled = toolbar.image !== false;
10679
10775
  const extensions = [
10680
10776
  ...buildExtensions({
10681
10777
  toolbar,
@@ -10698,16 +10794,21 @@ function useRichEditor(options = {}) {
10698
10794
  attributes: {
10699
10795
  class: cn(DEFAULT_EDITOR_CLASS, editorClassName)
10700
10796
  },
10701
- handleKeyDown: createKeyboardHandler(codeBlockEmptyEnterRef, onSubmitRef)
10797
+ handleKeyDown: createKeyboardHandler(codeBlockEmptyEnterRef, onSubmitRef),
10798
+ ...imageFeatureEnabled ? {
10799
+ handlePaste: createPasteHandler(processFilesRef),
10800
+ handleDrop: createDropHandler(processFilesRef)
10801
+ } : {}
10702
10802
  },
10703
10803
  content: defaultValue ?? "",
10704
10804
  onUpdate: ({ editor: editor2 }) => {
10705
10805
  onChangeRef.current?.(editor2.getHTML());
10706
10806
  }
10707
10807
  });
10808
+ editorRef.current = editor;
10708
10809
  useEffect(() => {
10709
- if (editor) editor.setEditable(editable);
10710
- }, [editor, editable]);
10810
+ if (editor) editor.setEditable(editable && !isUploading);
10811
+ }, [editor, editable, isUploading]);
10711
10812
  return {
10712
10813
  editor,
10713
10814
  getHTML: () => editor?.getHTML() ?? "",
@@ -10721,9 +10822,11 @@ function useRichEditor(options = {}) {
10721
10822
  focus: () => {
10722
10823
  editor?.commands.focus();
10723
10824
  },
10724
- isEmpty: editor?.isEmpty ?? true
10725
- // attachments,
10726
- // removeAttachment,
10825
+ isEmpty: editor?.isEmpty ?? true,
10826
+ attachments,
10827
+ removeAttachment,
10828
+ processFiles: processFilesRef.current,
10829
+ isUploading
10727
10830
  };
10728
10831
  }
10729
10832
  var MAX_COLS = 8;
@@ -10912,7 +11015,7 @@ function cmd(fn) {
10912
11015
  };
10913
11016
  }
10914
11017
  function RichEditorToolbar(props) {
10915
- const { editor, toolbar = {}, className, zIndex } = props;
11018
+ const { editor, toolbar = {}, className, zIndex, onImageButtonClick } = props;
10916
11019
  const popoverStyle = zIndex !== void 0 ? { zIndex } : void 0;
10917
11020
  const theme = useRichEditorTheme();
10918
11021
  const [tablePickerOpen, setTablePickerOpen] = useState(false);
@@ -11186,6 +11289,17 @@ function RichEditorToolbar(props) {
11186
11289
  }
11187
11290
  )
11188
11291
  ] }),
11292
+ toolbar.image !== false && onImageButtonClick && /* @__PURE__ */ jsxs(Fragment, { children: [
11293
+ /* @__PURE__ */ jsx(Divider, {}),
11294
+ /* @__PURE__ */ jsx(
11295
+ ToolbarButton,
11296
+ {
11297
+ onMouseDown: cmd(onImageButtonClick),
11298
+ title: "\uC774\uBBF8\uC9C0/\uD30C\uC77C \uC0BD\uC785",
11299
+ children: /* @__PURE__ */ jsx(Image, { size: 16 })
11300
+ }
11301
+ )
11302
+ ] }),
11189
11303
  toolbar.table && /* @__PURE__ */ jsxs(Fragment, { children: [
11190
11304
  /* @__PURE__ */ jsx(Divider, {}),
11191
11305
  /* @__PURE__ */ jsxs(Popover, { open: tablePickerOpen, onOpenChange: setTablePickerOpen, children: [
@@ -11300,6 +11414,130 @@ function RichEditorToolbar(props) {
11300
11414
  }
11301
11415
  );
11302
11416
  }
11417
+ function RichEditorDropZone(props) {
11418
+ const { children, className, "data-rich-editor-theme": themeAttr } = props;
11419
+ const theme = useRichEditorTheme();
11420
+ const [isDragging, setIsDragging] = useState(false);
11421
+ const counterRef = useRef(0);
11422
+ const handleDragEnter = (e) => {
11423
+ if (!e.dataTransfer.types.includes("Files")) return;
11424
+ e.preventDefault();
11425
+ counterRef.current++;
11426
+ setIsDragging(true);
11427
+ };
11428
+ const handleDragLeave = (_e) => {
11429
+ counterRef.current = Math.max(0, counterRef.current - 1);
11430
+ if (counterRef.current === 0) setIsDragging(false);
11431
+ };
11432
+ const handleDragOver = (e) => {
11433
+ if (e.dataTransfer.types.includes("Files")) e.preventDefault();
11434
+ };
11435
+ const handleDrop = (e) => {
11436
+ e.preventDefault();
11437
+ counterRef.current = 0;
11438
+ setIsDragging(false);
11439
+ };
11440
+ return /* @__PURE__ */ jsxs(
11441
+ "div",
11442
+ {
11443
+ className: cn("relative", className),
11444
+ "data-rich-editor-theme": themeAttr,
11445
+ onDragEnter: handleDragEnter,
11446
+ onDragLeave: handleDragLeave,
11447
+ onDragOver: handleDragOver,
11448
+ onDrop: handleDrop,
11449
+ children: [
11450
+ children,
11451
+ isDragging && /* @__PURE__ */ 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__ */ jsxs("div", { className: "flex flex-col items-center gap-2", children: [
11452
+ /* @__PURE__ */ jsx(Upload, { size: 28, strokeWidth: 1.5 }),
11453
+ /* @__PURE__ */ jsx("span", { className: "text-sm font-medium", children: "\uD30C\uC77C\uC744 \uC5EC\uAE30\uC5D0 \uB193\uC73C\uC138\uC694" }),
11454
+ /* @__PURE__ */ 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" })
11455
+ ] }) })
11456
+ ]
11457
+ }
11458
+ );
11459
+ }
11460
+ var EXT_STYLE = {
11461
+ pdf: "bg-red-100 text-red-700",
11462
+ doc: "bg-blue-100 text-blue-700",
11463
+ docx: "bg-blue-100 text-blue-700",
11464
+ hwp: "bg-blue-100 text-blue-700",
11465
+ xls: "bg-green-100 text-green-700",
11466
+ xlsx: "bg-green-100 text-green-700",
11467
+ csv: "bg-emerald-100 text-emerald-700",
11468
+ ppt: "bg-orange-100 text-orange-700",
11469
+ pptx: "bg-orange-100 text-orange-700",
11470
+ zip: "bg-gray-200 text-gray-700",
11471
+ rar: "bg-gray-200 text-gray-700",
11472
+ "7z": "bg-gray-200 text-gray-700",
11473
+ mp4: "bg-purple-100 text-purple-700",
11474
+ mov: "bg-purple-100 text-purple-700",
11475
+ avi: "bg-purple-100 text-purple-700",
11476
+ mp3: "bg-pink-100 text-pink-700",
11477
+ wav: "bg-pink-100 text-pink-700",
11478
+ txt: "bg-gray-100 text-gray-600",
11479
+ json: "bg-yellow-100 text-yellow-700",
11480
+ xml: "bg-yellow-100 text-yellow-700",
11481
+ js: "bg-yellow-100 text-yellow-700",
11482
+ ts: "bg-blue-100 text-blue-700",
11483
+ html: "bg-orange-100 text-orange-700",
11484
+ css: "bg-sky-100 text-sky-700"
11485
+ };
11486
+ function formatSize(bytes) {
11487
+ if (bytes < 1024) return `${bytes} B`;
11488
+ if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
11489
+ return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
11490
+ }
11491
+ function RichEditorFileList(props) {
11492
+ const { attachments, onRemove, renderFilePreview } = props;
11493
+ const theme = useRichEditorTheme();
11494
+ if (attachments.length === 0) return null;
11495
+ return /* @__PURE__ */ jsxs("div", { className: cn("px-3 py-2.5", theme.fileList.wrapper), children: [
11496
+ /* @__PURE__ */ jsxs("p", { className: cn("mb-1.5 text-[11px] font-medium uppercase tracking-wide", theme.fileList.label), children: [
11497
+ "\uCCA8\uBD80\uD30C\uC77C (",
11498
+ attachments.length,
11499
+ ")"
11500
+ ] }),
11501
+ /* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-2", children: attachments.map((attachment) => {
11502
+ if (renderFilePreview) {
11503
+ return /* @__PURE__ */ jsx("div", { children: renderFilePreview(attachment, () => onRemove(attachment.id)) }, attachment.id);
11504
+ }
11505
+ const ext = attachment.name.split(".").pop()?.toLowerCase() ?? "";
11506
+ const extStyle = EXT_STYLE[ext] ?? "bg-gray-100 text-gray-600";
11507
+ return /* @__PURE__ */ jsxs(
11508
+ "div",
11509
+ {
11510
+ className: cn("flex items-center gap-2 rounded-md px-2.5 py-1.5 shadow-xs", theme.fileList.item),
11511
+ children: [
11512
+ /* @__PURE__ */ jsx(
11513
+ "span",
11514
+ {
11515
+ className: cn(
11516
+ "shrink-0 rounded px-1.5 py-0.5 text-[10px] font-bold uppercase tracking-wide",
11517
+ extStyle
11518
+ ),
11519
+ children: ext || "FILE"
11520
+ }
11521
+ ),
11522
+ /* @__PURE__ */ jsx("span", { className: cn("max-w-[140px] truncate text-xs", theme.fileList.itemName), children: attachment.name }),
11523
+ /* @__PURE__ */ jsx("span", { className: cn("shrink-0 text-[11px]", theme.fileList.itemSize), children: formatSize(attachment.size) }),
11524
+ /* @__PURE__ */ jsx(
11525
+ "button",
11526
+ {
11527
+ type: "button",
11528
+ onClick: () => onRemove(attachment.id),
11529
+ title: "\uCCA8\uBD80\uD30C\uC77C \uC81C\uAC70",
11530
+ className: cn("flex h-4 w-4 shrink-0 items-center justify-center rounded-full", theme.fileList.removeBtn),
11531
+ children: /* @__PURE__ */ jsx(X, { size: 10 })
11532
+ }
11533
+ )
11534
+ ]
11535
+ },
11536
+ attachment.id
11537
+ );
11538
+ }) })
11539
+ ] });
11540
+ }
11303
11541
  var DEFAULT_TOOLBAR = {
11304
11542
  heading: [1, 2, 3, 4],
11305
11543
  bold: true,
@@ -11323,7 +11561,7 @@ function RichEditorContent(props) {
11323
11561
  return /* @__PURE__ */ jsx(
11324
11562
  "div",
11325
11563
  {
11326
- className: cn("rich-editor-content cursor-text", className),
11564
+ className: cn("rich-editor-content flex-1 cursor-text", className),
11327
11565
  style,
11328
11566
  onMouseDown: (e) => {
11329
11567
  if (!editor) return;
@@ -11359,7 +11597,10 @@ var RichEditor = forwardRef(function RichEditor2({
11359
11597
  zIndex,
11360
11598
  themeTokens,
11361
11599
  editable = true,
11362
- autofocus
11600
+ autofocus,
11601
+ fileFormat,
11602
+ onFileUpload,
11603
+ renderFilePreview
11363
11604
  }, ref) {
11364
11605
  const showToolbar = toolbar !== false;
11365
11606
  const toolbarOptions = typeof toolbar === "object" ? toolbar : {};
@@ -11376,7 +11617,7 @@ var RichEditor = forwardRef(function RichEditor2({
11376
11617
  },
11377
11618
  [onChange]
11378
11619
  );
11379
- const { editor } = useRichEditor({
11620
+ const { editor, attachments, removeAttachment, processFiles, isUploading } = useRichEditor({
11380
11621
  defaultValue: value ?? defaultValue,
11381
11622
  toolbar: activeToolbar,
11382
11623
  mentionUsers,
@@ -11391,9 +11632,12 @@ var RichEditor = forwardRef(function RichEditor2({
11391
11632
  editable,
11392
11633
  autofocus,
11393
11634
  editorClassName,
11635
+ fileFormat,
11636
+ onFileUpload,
11394
11637
  onChange: handleChange,
11395
11638
  onSubmit
11396
11639
  });
11640
+ const fileInputRef = useRef(null);
11397
11641
  useEffect(() => {
11398
11642
  if (!editor || value === void 0) return;
11399
11643
  if (isInternalChangeRef.current) {
@@ -11421,11 +11665,13 @@ var RichEditor = forwardRef(function RichEditor2({
11421
11665
  get isEmpty() {
11422
11666
  return editor?.isEmpty ?? true;
11423
11667
  },
11668
+ attachments,
11424
11669
  editor
11425
11670
  }),
11426
- [editor]
11671
+ [editor, attachments]
11427
11672
  );
11428
11673
  const isToolbarVisible = showToolbar && editable;
11674
+ const imageFeatureEnabled = activeToolbar.image !== false;
11429
11675
  const baseTheme = RICH_EDITOR_THEMES[theme];
11430
11676
  const resolvedTheme = themeTokens ? {
11431
11677
  ...baseTheme,
@@ -11448,10 +11694,37 @@ var RichEditor = forwardRef(function RichEditor2({
11448
11694
  {
11449
11695
  editor,
11450
11696
  toolbar: activeToolbar,
11451
- zIndex
11697
+ zIndex,
11698
+ onImageButtonClick: imageFeatureEnabled ? () => fileInputRef.current?.click() : void 0
11452
11699
  }
11453
11700
  ),
11454
- /* @__PURE__ */ jsx(
11701
+ imageFeatureEnabled && /* @__PURE__ */ jsx(
11702
+ "input",
11703
+ {
11704
+ ref: fileInputRef,
11705
+ type: "file",
11706
+ multiple: true,
11707
+ accept: buildAcceptAttribute(fileFormat),
11708
+ className: "hidden",
11709
+ onChange: (e) => {
11710
+ const files = Array.from(e.target.files ?? []);
11711
+ if (files.length > 0) processFiles(files);
11712
+ e.target.value = "";
11713
+ }
11714
+ }
11715
+ ),
11716
+ imageFeatureEnabled ? /* @__PURE__ */ jsxs(RichEditorDropZone, { className: "flex flex-1 flex-col", "data-rich-editor-theme": theme, children: [
11717
+ /* @__PURE__ */ jsx(
11718
+ RichEditorContent,
11719
+ {
11720
+ editor,
11721
+ className: cn("p-4", bodyClassName),
11722
+ minHeight,
11723
+ maxHeight
11724
+ }
11725
+ ),
11726
+ isUploading && /* @__PURE__ */ jsx("div", { className: "pointer-events-none absolute inset-0 z-10 flex items-center justify-center", children: /* @__PURE__ */ jsx(Loading, { size: "lg" }) })
11727
+ ] }) : /* @__PURE__ */ jsx(
11455
11728
  RichEditorContent,
11456
11729
  {
11457
11730
  editor,
@@ -11459,6 +11732,14 @@ var RichEditor = forwardRef(function RichEditor2({
11459
11732
  minHeight,
11460
11733
  maxHeight
11461
11734
  }
11735
+ ),
11736
+ imageFeatureEnabled && /* @__PURE__ */ jsx(
11737
+ RichEditorFileList,
11738
+ {
11739
+ attachments,
11740
+ onRemove: removeAttachment,
11741
+ renderFilePreview
11742
+ }
11462
11743
  )
11463
11744
  ]
11464
11745
  }