@farmzone/fz-react-ui 1.1.15 → 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.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';
@@ -455,7 +455,7 @@ function Input2(props) {
455
455
  onBlur,
456
456
  maxLength,
457
457
  allowLeadingSpace = true,
458
- allowMiddleSpace = true,
458
+ // allowMiddleSpace = true,
459
459
  allowTrailingSpace = true,
460
460
  ...rest
461
461
  } = props;
@@ -533,11 +533,12 @@ function Input2(props) {
533
533
  } else {
534
534
  event.target.value = sanitized;
535
535
  }
536
- } else if (!allowLeadingSpace || !allowMiddleSpace) {
536
+ } else if (!allowLeadingSpace || !allowTrailingSpace) {
537
537
  const { leading, core, trailing } = splitSpaceRuns(value);
538
538
  const nextLeading = allowLeadingSpace ? leading : "";
539
- const nextCore = allowMiddleSpace ? core : core.replace(/ /g, "");
540
- const sanitized = nextLeading + nextCore + trailing;
539
+ const nextCore = core;
540
+ const nextTrailing = allowTrailingSpace ? trailing : "";
541
+ const sanitized = nextLeading + nextCore + nextTrailing;
541
542
  if (sanitized !== value) {
542
543
  event.target.value = sanitized;
543
544
  }
@@ -556,16 +557,6 @@ function Input2(props) {
556
557
  }
557
558
  onKeyDown?.(event);
558
559
  };
559
- const handleBlur = (event) => {
560
- if (!allowTrailingSpace && type !== "number" && type !== "money") {
561
- const trimmed = event.currentTarget.value.replace(/ +$/, "");
562
- if (trimmed !== event.currentTarget.value) {
563
- event.currentTarget.value = trimmed;
564
- onChange?.(event);
565
- }
566
- }
567
- onBlur?.(event);
568
- };
569
560
  const inputBlock = /* @__PURE__ */ jsxs("div", { className: "relative m-0", children: [
570
561
  leftIcon && /* @__PURE__ */ jsx("div", { className: "text-muted-foreground absolute top-1/2 left-3 -translate-y-1/2 transform", children: leftIcon }),
571
562
  /* @__PURE__ */ jsx(
@@ -586,7 +577,7 @@ function Input2(props) {
586
577
  maxLength: type === "money" ? void 0 : maxLength,
587
578
  onChange: handleChange,
588
579
  onKeyDown: handleKeyDown,
589
- onBlur: handleBlur,
580
+ onBlur,
590
581
  ...rest
591
582
  }
592
583
  ),
@@ -1783,10 +1774,12 @@ var ToastManager = class _ToastManager {
1783
1774
  const props = this.resolveProps(rawProps);
1784
1775
  const position = props.position || "top-center";
1785
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;
1786
1778
  if (props.id) {
1787
1779
  for (const [pos, toasts] of this.toasts.entries()) {
1788
1780
  const existing = toasts.find((t) => t.id === props.id);
1789
1781
  if (existing) {
1782
+ if (isSameToast(existing)) return existing.id;
1790
1783
  if (existing.timer) clearTimeout(existing.timer);
1791
1784
  const updated = toasts.filter((t) => t.id !== props.id);
1792
1785
  this.toasts.set(pos, updated);
@@ -1797,7 +1790,9 @@ var ToastManager = class _ToastManager {
1797
1790
  }
1798
1791
  }
1799
1792
  const positionToasts = this.toasts.get(position) || [];
1800
- if (positionToasts.length > 0) {
1793
+ const existingAtPosition = positionToasts[0];
1794
+ if (existingAtPosition) {
1795
+ if (isSameToast(existingAtPosition)) return existingAtPosition.id;
1801
1796
  positionToasts.forEach((toast2) => {
1802
1797
  if (toast2.timer) clearTimeout(toast2.timer);
1803
1798
  });
@@ -2619,8 +2614,33 @@ function useCalendarState(props) {
2619
2614
  handleSelectOpenChange
2620
2615
  };
2621
2616
  }
2617
+
2618
+ // src/components/Modal/ui/modalStack.ts
2619
+ var stack = [];
2620
+ function push(id) {
2621
+ stack = [...stack, id];
2622
+ return stack.length;
2623
+ }
2624
+ function pop(id) {
2625
+ stack = stack.filter((s) => s !== id);
2626
+ }
2627
+ function isTop(id) {
2628
+ return stack.at(-1) === id;
2629
+ }
2630
+ function size() {
2631
+ return stack.length;
2632
+ }
2633
+ var modalStack = { push, pop, isTop, size };
2634
+
2635
+ // src/components/DatePicker/calendar/hooks/useFloatingCalendarPosition.ts
2622
2636
  var CALENDAR_GAP = 4;
2623
2637
  var CALENDAR_MIN_WIDTH = 280;
2638
+ function resolveCalendarZIndex() {
2639
+ const depth = modalStack.size();
2640
+ if (depth === 0) return CALENDAR_PORTAL_Z_INDEX;
2641
+ const topModalContentZ = Z_INDEX.MODAL + Math.max(0, depth - 1) * Z_INDEX.MODAL_Z_STEP;
2642
+ return Math.max(CALENDAR_PORTAL_Z_INDEX, topModalContentZ + (Z_INDEX.CALENDAR_PORTAL - Z_INDEX.MODAL));
2643
+ }
2624
2644
  function useFloatingCalendarPosition(anchorRef, isOpen2, placement, align = "start") {
2625
2645
  const [style, setStyle] = useState({ position: "fixed", visibility: "hidden" });
2626
2646
  useLayoutEffect(() => {
@@ -2629,7 +2649,7 @@ function useFloatingCalendarPosition(anchorRef, isOpen2, placement, align = "sta
2629
2649
  const rect = anchorRef.current.getBoundingClientRect();
2630
2650
  const base = {
2631
2651
  position: "fixed",
2632
- zIndex: CALENDAR_PORTAL_Z_INDEX,
2652
+ zIndex: resolveCalendarZIndex(),
2633
2653
  minWidth: CALENDAR_MIN_WIDTH,
2634
2654
  visibility: "visible",
2635
2655
  ...align === "end" ? { left: rect.left } : { right: window.innerWidth - rect.right }
@@ -3222,25 +3242,24 @@ function SearchBar(props) {
3222
3242
  function DebouncedButton(props) {
3223
3243
  const { debounceDelay = 300, onClick, className, ...rest } = props;
3224
3244
  const [isDebouncing, setIsDebouncing] = useState(false);
3245
+ const onClickRef = useRef(onClick);
3246
+ onClickRef.current = onClick;
3225
3247
  const debouncedOnClick = useMemo(() => {
3226
- if (!onClick) return void 0;
3227
3248
  return debounce((event) => {
3228
3249
  setIsDebouncing(false);
3229
- onClick(event);
3250
+ onClickRef.current?.(event);
3230
3251
  }, debounceDelay);
3231
- }, [debounceDelay, onClick]);
3252
+ }, [debounceDelay]);
3232
3253
  useEffect(() => {
3233
3254
  return () => {
3234
- debouncedOnClick?.cancel();
3255
+ debouncedOnClick.cancel();
3235
3256
  setIsDebouncing(false);
3236
3257
  };
3237
3258
  }, [debouncedOnClick]);
3238
3259
  const handleClick = (event) => {
3239
- if (debouncedOnClick) {
3260
+ if (onClickRef.current) {
3240
3261
  setIsDebouncing(true);
3241
3262
  debouncedOnClick(event);
3242
- } else {
3243
- onClick?.(event);
3244
3263
  }
3245
3264
  };
3246
3265
  return /* @__PURE__ */ jsx(
@@ -3648,23 +3667,6 @@ function Empty(props) {
3648
3667
  }
3649
3668
  return root2;
3650
3669
  }
3651
-
3652
- // src/components/Modal/ui/modalStack.ts
3653
- var stack = [];
3654
- function push(id) {
3655
- stack = [...stack, id];
3656
- return stack.length;
3657
- }
3658
- function pop(id) {
3659
- stack = stack.filter((s) => s !== id);
3660
- }
3661
- function isTop(id) {
3662
- return stack.at(-1) === id;
3663
- }
3664
- function size() {
3665
- return stack.length;
3666
- }
3667
- var modalStack = { push, pop, isTop, size };
3668
3670
  function ModalContent(props) {
3669
3671
  const { ref, children, className, zIndex, ...rest } = props;
3670
3672
  return /* @__PURE__ */ jsx(
@@ -10523,7 +10525,7 @@ function buildCustomTextAlign() {
10523
10525
  });
10524
10526
  }
10525
10527
  function buildCustomImage() {
10526
- const CustomImage = Image.extend({
10528
+ const CustomImage = Image$1.extend({
10527
10529
  addAttributes() {
10528
10530
  return {
10529
10531
  ...this.parent?.(),
@@ -10651,8 +10653,90 @@ function createKeyboardHandler(codeBlockEmptyEnterRef, onSubmitRef) {
10651
10653
  };
10652
10654
  }
10653
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
+
10654
10738
  // src/components/RichEditor/hooks/useRichEditor.ts
10655
- var DEFAULT_EDITOR_CLASS = "focus:outline-none";
10739
+ var DEFAULT_EDITOR_CLASS = "focus:outline-none h-full";
10656
10740
  function useRichEditor(options = {}) {
10657
10741
  const {
10658
10742
  defaultValue,
@@ -10669,6 +10753,8 @@ function useRichEditor(options = {}) {
10669
10753
  autofocus,
10670
10754
  editorClassName,
10671
10755
  additionalExtensions = [],
10756
+ fileFormat,
10757
+ onFileUpload,
10672
10758
  onChange,
10673
10759
  onSubmit
10674
10760
  } = options;
@@ -10677,6 +10763,15 @@ function useRichEditor(options = {}) {
10677
10763
  onChangeRef.current = onChange;
10678
10764
  const onSubmitRef = useRef(onSubmit);
10679
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;
10680
10775
  const extensions = [
10681
10776
  ...buildExtensions({
10682
10777
  toolbar,
@@ -10699,16 +10794,21 @@ function useRichEditor(options = {}) {
10699
10794
  attributes: {
10700
10795
  class: cn(DEFAULT_EDITOR_CLASS, editorClassName)
10701
10796
  },
10702
- handleKeyDown: createKeyboardHandler(codeBlockEmptyEnterRef, onSubmitRef)
10797
+ handleKeyDown: createKeyboardHandler(codeBlockEmptyEnterRef, onSubmitRef),
10798
+ ...imageFeatureEnabled ? {
10799
+ handlePaste: createPasteHandler(processFilesRef),
10800
+ handleDrop: createDropHandler(processFilesRef)
10801
+ } : {}
10703
10802
  },
10704
10803
  content: defaultValue ?? "",
10705
10804
  onUpdate: ({ editor: editor2 }) => {
10706
10805
  onChangeRef.current?.(editor2.getHTML());
10707
10806
  }
10708
10807
  });
10808
+ editorRef.current = editor;
10709
10809
  useEffect(() => {
10710
- if (editor) editor.setEditable(editable);
10711
- }, [editor, editable]);
10810
+ if (editor) editor.setEditable(editable && !isUploading);
10811
+ }, [editor, editable, isUploading]);
10712
10812
  return {
10713
10813
  editor,
10714
10814
  getHTML: () => editor?.getHTML() ?? "",
@@ -10722,9 +10822,11 @@ function useRichEditor(options = {}) {
10722
10822
  focus: () => {
10723
10823
  editor?.commands.focus();
10724
10824
  },
10725
- isEmpty: editor?.isEmpty ?? true
10726
- // attachments,
10727
- // removeAttachment,
10825
+ isEmpty: editor?.isEmpty ?? true,
10826
+ attachments,
10827
+ removeAttachment,
10828
+ processFiles: processFilesRef.current,
10829
+ isUploading
10728
10830
  };
10729
10831
  }
10730
10832
  var MAX_COLS = 8;
@@ -10913,7 +11015,7 @@ function cmd(fn) {
10913
11015
  };
10914
11016
  }
10915
11017
  function RichEditorToolbar(props) {
10916
- const { editor, toolbar = {}, className, zIndex } = props;
11018
+ const { editor, toolbar = {}, className, zIndex, onImageButtonClick } = props;
10917
11019
  const popoverStyle = zIndex !== void 0 ? { zIndex } : void 0;
10918
11020
  const theme = useRichEditorTheme();
10919
11021
  const [tablePickerOpen, setTablePickerOpen] = useState(false);
@@ -11187,6 +11289,17 @@ function RichEditorToolbar(props) {
11187
11289
  }
11188
11290
  )
11189
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
+ ] }),
11190
11303
  toolbar.table && /* @__PURE__ */ jsxs(Fragment, { children: [
11191
11304
  /* @__PURE__ */ jsx(Divider, {}),
11192
11305
  /* @__PURE__ */ jsxs(Popover, { open: tablePickerOpen, onOpenChange: setTablePickerOpen, children: [
@@ -11301,6 +11414,130 @@ function RichEditorToolbar(props) {
11301
11414
  }
11302
11415
  );
11303
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
+ }
11304
11541
  var DEFAULT_TOOLBAR = {
11305
11542
  heading: [1, 2, 3, 4],
11306
11543
  bold: true,
@@ -11324,7 +11561,7 @@ function RichEditorContent(props) {
11324
11561
  return /* @__PURE__ */ jsx(
11325
11562
  "div",
11326
11563
  {
11327
- className: cn("rich-editor-content cursor-text", className),
11564
+ className: cn("rich-editor-content flex-1 cursor-text", className),
11328
11565
  style,
11329
11566
  onMouseDown: (e) => {
11330
11567
  if (!editor) return;
@@ -11360,7 +11597,10 @@ var RichEditor = forwardRef(function RichEditor2({
11360
11597
  zIndex,
11361
11598
  themeTokens,
11362
11599
  editable = true,
11363
- autofocus
11600
+ autofocus,
11601
+ fileFormat,
11602
+ onFileUpload,
11603
+ renderFilePreview
11364
11604
  }, ref) {
11365
11605
  const showToolbar = toolbar !== false;
11366
11606
  const toolbarOptions = typeof toolbar === "object" ? toolbar : {};
@@ -11377,7 +11617,7 @@ var RichEditor = forwardRef(function RichEditor2({
11377
11617
  },
11378
11618
  [onChange]
11379
11619
  );
11380
- const { editor } = useRichEditor({
11620
+ const { editor, attachments, removeAttachment, processFiles, isUploading } = useRichEditor({
11381
11621
  defaultValue: value ?? defaultValue,
11382
11622
  toolbar: activeToolbar,
11383
11623
  mentionUsers,
@@ -11392,9 +11632,12 @@ var RichEditor = forwardRef(function RichEditor2({
11392
11632
  editable,
11393
11633
  autofocus,
11394
11634
  editorClassName,
11635
+ fileFormat,
11636
+ onFileUpload,
11395
11637
  onChange: handleChange,
11396
11638
  onSubmit
11397
11639
  });
11640
+ const fileInputRef = useRef(null);
11398
11641
  useEffect(() => {
11399
11642
  if (!editor || value === void 0) return;
11400
11643
  if (isInternalChangeRef.current) {
@@ -11422,11 +11665,13 @@ var RichEditor = forwardRef(function RichEditor2({
11422
11665
  get isEmpty() {
11423
11666
  return editor?.isEmpty ?? true;
11424
11667
  },
11668
+ attachments,
11425
11669
  editor
11426
11670
  }),
11427
- [editor]
11671
+ [editor, attachments]
11428
11672
  );
11429
11673
  const isToolbarVisible = showToolbar && editable;
11674
+ const imageFeatureEnabled = activeToolbar.image !== false;
11430
11675
  const baseTheme = RICH_EDITOR_THEMES[theme];
11431
11676
  const resolvedTheme = themeTokens ? {
11432
11677
  ...baseTheme,
@@ -11449,10 +11694,37 @@ var RichEditor = forwardRef(function RichEditor2({
11449
11694
  {
11450
11695
  editor,
11451
11696
  toolbar: activeToolbar,
11452
- zIndex
11697
+ zIndex,
11698
+ onImageButtonClick: imageFeatureEnabled ? () => fileInputRef.current?.click() : void 0
11453
11699
  }
11454
11700
  ),
11455
- /* @__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(
11456
11728
  RichEditorContent,
11457
11729
  {
11458
11730
  editor,
@@ -11460,6 +11732,14 @@ var RichEditor = forwardRef(function RichEditor2({
11460
11732
  minHeight,
11461
11733
  maxHeight
11462
11734
  }
11735
+ ),
11736
+ imageFeatureEnabled && /* @__PURE__ */ jsx(
11737
+ RichEditorFileList,
11738
+ {
11739
+ attachments,
11740
+ onRemove: removeAttachment,
11741
+ renderFilePreview
11742
+ }
11463
11743
  )
11464
11744
  ]
11465
11745
  }