@farmzone/fz-react-ui 1.1.16 → 1.1.18
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 +427 -33
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +21 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +431 -37
- package/dist/index.js.map +1 -1
- package/dist/styles.css +1 -1
- package/package.json +1 -1
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,
|
|
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';
|
|
@@ -30,10 +30,10 @@ 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
|
-
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
|
-
|
|
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
|
-
|
|
3250
|
+
onClickRef.current?.(event);
|
|
3246
3251
|
}, debounceDelay);
|
|
3247
|
-
}, [debounceDelay
|
|
3252
|
+
}, [debounceDelay]);
|
|
3248
3253
|
useEffect(() => {
|
|
3249
3254
|
return () => {
|
|
3250
|
-
debouncedOnClick
|
|
3255
|
+
debouncedOnClick.cancel();
|
|
3251
3256
|
setIsDebouncing(false);
|
|
3252
3257
|
};
|
|
3253
3258
|
}, [debouncedOnClick]);
|
|
3254
3259
|
const handleClick = (event) => {
|
|
3255
|
-
if (
|
|
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(
|
|
@@ -10394,7 +10397,7 @@ function buildExtensions(config) {
|
|
|
10394
10397
|
accentTextColor,
|
|
10395
10398
|
zIndex
|
|
10396
10399
|
} = config;
|
|
10397
|
-
const exts = [TextStyleKit, buildMarkResetOnEnter()];
|
|
10400
|
+
const exts = [TextStyleKit, buildMarkResetOnEnter(), buildRedundantListMarkerStrip()];
|
|
10398
10401
|
const headingLevels = toolbar.heading === false ? [] : Array.isArray(toolbar.heading) ? [...toolbar.heading] : [1, 2, 3, 4];
|
|
10399
10402
|
exts.push(
|
|
10400
10403
|
StarterKit.configure({
|
|
@@ -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?.(),
|
|
@@ -10570,6 +10573,36 @@ function buildMarkResetOnEnter() {
|
|
|
10570
10573
|
}
|
|
10571
10574
|
});
|
|
10572
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
|
+
}
|
|
10573
10606
|
|
|
10574
10607
|
// src/components/RichEditor/config/keyboardHandlers.ts
|
|
10575
10608
|
function createKeyboardHandler(codeBlockEmptyEnterRef, onSubmitRef) {
|
|
@@ -10650,8 +10683,149 @@ function createKeyboardHandler(codeBlockEmptyEnterRef, onSubmitRef) {
|
|
|
10650
10683
|
};
|
|
10651
10684
|
}
|
|
10652
10685
|
|
|
10686
|
+
// src/components/RichEditor/config/fileHandlers.ts
|
|
10687
|
+
function createPasteHandler(processFilesRef) {
|
|
10688
|
+
return (_view, event) => {
|
|
10689
|
+
const files = Array.from(event.clipboardData?.files ?? []);
|
|
10690
|
+
if (files.length === 0) return false;
|
|
10691
|
+
event.preventDefault();
|
|
10692
|
+
processFilesRef.current(files);
|
|
10693
|
+
return true;
|
|
10694
|
+
};
|
|
10695
|
+
}
|
|
10696
|
+
function createDropHandler(processFilesRef) {
|
|
10697
|
+
return (_view, event) => {
|
|
10698
|
+
const files = Array.from(event.dataTransfer?.files ?? []);
|
|
10699
|
+
if (files.length === 0) return false;
|
|
10700
|
+
event.preventDefault();
|
|
10701
|
+
processFilesRef.current(files);
|
|
10702
|
+
return true;
|
|
10703
|
+
};
|
|
10704
|
+
}
|
|
10705
|
+
var FORMAT_EXT_ALIASES = {
|
|
10706
|
+
JPG: ["jpg", "jpeg"],
|
|
10707
|
+
JPEG: ["jpg", "jpeg"]
|
|
10708
|
+
};
|
|
10709
|
+
function expandFormats(fileFormat) {
|
|
10710
|
+
const exts = /* @__PURE__ */ new Set();
|
|
10711
|
+
for (const format of fileFormat) {
|
|
10712
|
+
const key = format.toUpperCase();
|
|
10713
|
+
const aliases = FORMAT_EXT_ALIASES[key] ?? [format.toLowerCase()];
|
|
10714
|
+
aliases.forEach((ext) => exts.add(ext));
|
|
10715
|
+
}
|
|
10716
|
+
return exts;
|
|
10717
|
+
}
|
|
10718
|
+
function extOf(fileName) {
|
|
10719
|
+
return fileName.split(".").pop()?.toLowerCase() ?? "";
|
|
10720
|
+
}
|
|
10721
|
+
function buildAcceptAttribute(fileFormat) {
|
|
10722
|
+
if (!fileFormat || fileFormat.length === 0) return void 0;
|
|
10723
|
+
return Array.from(expandFormats(fileFormat)).map((ext) => `.${ext}`).join(",");
|
|
10724
|
+
}
|
|
10725
|
+
function useRichEditorFiles(options = {}) {
|
|
10726
|
+
const { fileFormat, onFileUpload, initialAttachments } = options;
|
|
10727
|
+
const [attachments, setAttachments] = useState(() => initialAttachments ?? []);
|
|
10728
|
+
const [isUploading, setIsUploading] = useState(false);
|
|
10729
|
+
const removeAttachment = useCallback((id) => {
|
|
10730
|
+
setAttachments((prev) => prev.filter((a) => a.id !== id));
|
|
10731
|
+
}, []);
|
|
10732
|
+
const hydrateAttachments = useCallback((loaded) => {
|
|
10733
|
+
setAttachments(loaded);
|
|
10734
|
+
}, []);
|
|
10735
|
+
const processFiles = useCallback(
|
|
10736
|
+
async (files, editor) => {
|
|
10737
|
+
const allowedExts = fileFormat ? expandFormats(fileFormat) : null;
|
|
10738
|
+
const accepted = allowedExts ? files.filter((f) => allowedExts.has(extOf(f.name))) : files;
|
|
10739
|
+
if (accepted.length === 0) return;
|
|
10740
|
+
setIsUploading(true);
|
|
10741
|
+
try {
|
|
10742
|
+
for (const file of accepted) {
|
|
10743
|
+
let url;
|
|
10744
|
+
try {
|
|
10745
|
+
url = await (onFileUpload ? onFileUpload(file) : URL.createObjectURL(file));
|
|
10746
|
+
} catch {
|
|
10747
|
+
continue;
|
|
10748
|
+
}
|
|
10749
|
+
if (file.type.startsWith("image/")) {
|
|
10750
|
+
if (!editor) continue;
|
|
10751
|
+
editor.chain().focus().insertContent({ type: "image", attrs: { src: url } }).run();
|
|
10752
|
+
editor.commands.setTextSelection(editor.state.selection.to);
|
|
10753
|
+
} else {
|
|
10754
|
+
setAttachments((prev) => [
|
|
10755
|
+
...prev,
|
|
10756
|
+
{
|
|
10757
|
+
id: `${Date.now()}-${Math.random().toString(36).slice(2)}`,
|
|
10758
|
+
name: file.name,
|
|
10759
|
+
size: file.size,
|
|
10760
|
+
mimeType: file.type,
|
|
10761
|
+
file,
|
|
10762
|
+
url
|
|
10763
|
+
}
|
|
10764
|
+
]);
|
|
10765
|
+
}
|
|
10766
|
+
}
|
|
10767
|
+
} finally {
|
|
10768
|
+
setIsUploading(false);
|
|
10769
|
+
}
|
|
10770
|
+
},
|
|
10771
|
+
[fileFormat, onFileUpload]
|
|
10772
|
+
);
|
|
10773
|
+
return { attachments, processFiles, removeAttachment, hydrateAttachments, isUploading };
|
|
10774
|
+
}
|
|
10775
|
+
|
|
10776
|
+
// src/components/RichEditor/config/attachmentSerialization.ts
|
|
10777
|
+
var ATTACHMENTS_CONTAINER_ATTR = "data-rich-editor-attachments";
|
|
10778
|
+
var ATTACHMENT_ITEM_ATTR = "data-rich-editor-attachment";
|
|
10779
|
+
function escapeHtmlAttr(value) {
|
|
10780
|
+
return value.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
10781
|
+
}
|
|
10782
|
+
function escapeHtmlText(value) {
|
|
10783
|
+
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
10784
|
+
}
|
|
10785
|
+
function serializeAttachmentsBlock(attachments) {
|
|
10786
|
+
if (attachments.length === 0) return "";
|
|
10787
|
+
const items = attachments.map((attachment) => {
|
|
10788
|
+
const href = escapeHtmlAttr(attachment.url);
|
|
10789
|
+
const name = escapeHtmlAttr(attachment.name);
|
|
10790
|
+
return `<a ${ATTACHMENT_ITEM_ATTR}="true" href="${href}" data-name="${name}" data-size="${attachment.size}" data-mime="${escapeHtmlAttr(attachment.mimeType)}">${escapeHtmlText(attachment.name)}</a>`;
|
|
10791
|
+
}).join("");
|
|
10792
|
+
return `<div ${ATTACHMENTS_CONTAINER_ATTR}="true">${items}</div>`;
|
|
10793
|
+
}
|
|
10794
|
+
function splitAttachmentsFromHtml(html) {
|
|
10795
|
+
if (!html || !html.includes(ATTACHMENTS_CONTAINER_ATTR) || typeof DOMParser === "undefined") {
|
|
10796
|
+
return { html, attachments: [] };
|
|
10797
|
+
}
|
|
10798
|
+
const doc = new DOMParser().parseFromString(html, "text/html");
|
|
10799
|
+
const container2 = doc.body.querySelector(`[${ATTACHMENTS_CONTAINER_ATTR}]`);
|
|
10800
|
+
if (!container2) {
|
|
10801
|
+
return { html, attachments: [] };
|
|
10802
|
+
}
|
|
10803
|
+
const attachments = Array.from(
|
|
10804
|
+
container2.querySelectorAll(`[${ATTACHMENT_ITEM_ATTR}]`)
|
|
10805
|
+
).map((el, index) => {
|
|
10806
|
+
const url = el.getAttribute("href") ?? "";
|
|
10807
|
+
const name = el.getAttribute("data-name") ?? el.textContent ?? `file-${index}`;
|
|
10808
|
+
const mimeType = el.getAttribute("data-mime") ?? "";
|
|
10809
|
+
const size2 = Number(el.getAttribute("data-size") ?? "0") || 0;
|
|
10810
|
+
return {
|
|
10811
|
+
id: `loaded-${index}-${Math.random().toString(36).slice(2)}`,
|
|
10812
|
+
name,
|
|
10813
|
+
size: size2,
|
|
10814
|
+
mimeType,
|
|
10815
|
+
file: new File([], name, { type: mimeType }),
|
|
10816
|
+
url
|
|
10817
|
+
};
|
|
10818
|
+
});
|
|
10819
|
+
container2.remove();
|
|
10820
|
+
return { html: doc.body.innerHTML, attachments };
|
|
10821
|
+
}
|
|
10822
|
+
function composeRichEditorHtml(bodyHtml, attachments) {
|
|
10823
|
+
const block = serializeAttachmentsBlock(attachments);
|
|
10824
|
+
return block ? `${bodyHtml}${block}` : bodyHtml;
|
|
10825
|
+
}
|
|
10826
|
+
|
|
10653
10827
|
// src/components/RichEditor/hooks/useRichEditor.ts
|
|
10654
|
-
var DEFAULT_EDITOR_CLASS = "focus:outline-none";
|
|
10828
|
+
var DEFAULT_EDITOR_CLASS = "focus:outline-none h-full";
|
|
10655
10829
|
function useRichEditor(options = {}) {
|
|
10656
10830
|
const {
|
|
10657
10831
|
defaultValue,
|
|
@@ -10668,6 +10842,8 @@ function useRichEditor(options = {}) {
|
|
|
10668
10842
|
autofocus,
|
|
10669
10843
|
editorClassName,
|
|
10670
10844
|
additionalExtensions = [],
|
|
10845
|
+
fileFormat,
|
|
10846
|
+
onFileUpload,
|
|
10671
10847
|
onChange,
|
|
10672
10848
|
onSubmit
|
|
10673
10849
|
} = options;
|
|
@@ -10676,6 +10852,23 @@ function useRichEditor(options = {}) {
|
|
|
10676
10852
|
onChangeRef.current = onChange;
|
|
10677
10853
|
const onSubmitRef = useRef(onSubmit);
|
|
10678
10854
|
onSubmitRef.current = onSubmit;
|
|
10855
|
+
const initialSplitRef = useRef(null);
|
|
10856
|
+
if (initialSplitRef.current === null) {
|
|
10857
|
+
initialSplitRef.current = splitAttachmentsFromHtml(defaultValue ?? "");
|
|
10858
|
+
}
|
|
10859
|
+
const initialSplit = initialSplitRef.current;
|
|
10860
|
+
const { attachments, processFiles, removeAttachment, hydrateAttachments, isUploading } = useRichEditorFiles({
|
|
10861
|
+
fileFormat,
|
|
10862
|
+
onFileUpload,
|
|
10863
|
+
initialAttachments: initialSplit.attachments
|
|
10864
|
+
});
|
|
10865
|
+
const attachmentsRef = useRef(attachments);
|
|
10866
|
+
attachmentsRef.current = attachments;
|
|
10867
|
+
const editorRef = useRef(null);
|
|
10868
|
+
const processFilesRef = useRef(() => {
|
|
10869
|
+
});
|
|
10870
|
+
processFilesRef.current = (files) => processFiles(files, editorRef.current);
|
|
10871
|
+
const imageFeatureEnabled = toolbar.image !== false;
|
|
10679
10872
|
const extensions = [
|
|
10680
10873
|
...buildExtensions({
|
|
10681
10874
|
toolbar,
|
|
@@ -10698,22 +10891,33 @@ function useRichEditor(options = {}) {
|
|
|
10698
10891
|
attributes: {
|
|
10699
10892
|
class: cn(DEFAULT_EDITOR_CLASS, editorClassName)
|
|
10700
10893
|
},
|
|
10701
|
-
handleKeyDown: createKeyboardHandler(codeBlockEmptyEnterRef, onSubmitRef)
|
|
10894
|
+
handleKeyDown: createKeyboardHandler(codeBlockEmptyEnterRef, onSubmitRef),
|
|
10895
|
+
...imageFeatureEnabled ? {
|
|
10896
|
+
handlePaste: createPasteHandler(processFilesRef),
|
|
10897
|
+
handleDrop: createDropHandler(processFilesRef)
|
|
10898
|
+
} : {}
|
|
10702
10899
|
},
|
|
10703
|
-
content:
|
|
10900
|
+
content: initialSplit.html,
|
|
10704
10901
|
onUpdate: ({ editor: editor2 }) => {
|
|
10705
|
-
onChangeRef.current?.(editor2.getHTML());
|
|
10902
|
+
onChangeRef.current?.(composeRichEditorHtml(editor2.getHTML(), attachmentsRef.current));
|
|
10706
10903
|
}
|
|
10707
10904
|
});
|
|
10905
|
+
editorRef.current = editor;
|
|
10708
10906
|
useEffect(() => {
|
|
10709
|
-
if (editor)
|
|
10710
|
-
|
|
10907
|
+
if (!editor) return;
|
|
10908
|
+
onChangeRef.current?.(composeRichEditorHtml(editor.getHTML(), attachments));
|
|
10909
|
+
}, [attachments]);
|
|
10910
|
+
useEffect(() => {
|
|
10911
|
+
if (editor) editor.setEditable(editable && !isUploading);
|
|
10912
|
+
}, [editor, editable, isUploading]);
|
|
10711
10913
|
return {
|
|
10712
10914
|
editor,
|
|
10713
|
-
getHTML: () => editor?.getHTML() ?? "",
|
|
10915
|
+
getHTML: () => composeRichEditorHtml(editor?.getHTML() ?? "", attachments),
|
|
10714
10916
|
getJSON: () => editor?.getJSON() ?? {},
|
|
10715
10917
|
setContent: (html) => {
|
|
10716
|
-
|
|
10918
|
+
const split = splitAttachmentsFromHtml(html);
|
|
10919
|
+
editor?.commands.setContent(split.html);
|
|
10920
|
+
hydrateAttachments(split.attachments);
|
|
10717
10921
|
},
|
|
10718
10922
|
clearContent: () => {
|
|
10719
10923
|
editor?.commands.clearContent();
|
|
@@ -10721,9 +10925,12 @@ function useRichEditor(options = {}) {
|
|
|
10721
10925
|
focus: () => {
|
|
10722
10926
|
editor?.commands.focus();
|
|
10723
10927
|
},
|
|
10724
|
-
isEmpty: editor?.isEmpty ?? true
|
|
10725
|
-
|
|
10726
|
-
|
|
10928
|
+
isEmpty: editor?.isEmpty ?? true,
|
|
10929
|
+
attachments,
|
|
10930
|
+
removeAttachment,
|
|
10931
|
+
hydrateAttachments,
|
|
10932
|
+
processFiles: processFilesRef.current,
|
|
10933
|
+
isUploading
|
|
10727
10934
|
};
|
|
10728
10935
|
}
|
|
10729
10936
|
var MAX_COLS = 8;
|
|
@@ -10912,7 +11119,7 @@ function cmd(fn) {
|
|
|
10912
11119
|
};
|
|
10913
11120
|
}
|
|
10914
11121
|
function RichEditorToolbar(props) {
|
|
10915
|
-
const { editor, toolbar = {}, className, zIndex } = props;
|
|
11122
|
+
const { editor, toolbar = {}, className, zIndex, onImageButtonClick } = props;
|
|
10916
11123
|
const popoverStyle = zIndex !== void 0 ? { zIndex } : void 0;
|
|
10917
11124
|
const theme = useRichEditorTheme();
|
|
10918
11125
|
const [tablePickerOpen, setTablePickerOpen] = useState(false);
|
|
@@ -11186,6 +11393,17 @@ function RichEditorToolbar(props) {
|
|
|
11186
11393
|
}
|
|
11187
11394
|
)
|
|
11188
11395
|
] }),
|
|
11396
|
+
toolbar.image !== false && onImageButtonClick && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
11397
|
+
/* @__PURE__ */ jsx(Divider, {}),
|
|
11398
|
+
/* @__PURE__ */ jsx(
|
|
11399
|
+
ToolbarButton,
|
|
11400
|
+
{
|
|
11401
|
+
onMouseDown: cmd(onImageButtonClick),
|
|
11402
|
+
title: "\uC774\uBBF8\uC9C0/\uD30C\uC77C \uC0BD\uC785",
|
|
11403
|
+
children: /* @__PURE__ */ jsx(Image, { size: 16 })
|
|
11404
|
+
}
|
|
11405
|
+
)
|
|
11406
|
+
] }),
|
|
11189
11407
|
toolbar.table && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
11190
11408
|
/* @__PURE__ */ jsx(Divider, {}),
|
|
11191
11409
|
/* @__PURE__ */ jsxs(Popover, { open: tablePickerOpen, onOpenChange: setTablePickerOpen, children: [
|
|
@@ -11300,6 +11518,130 @@ function RichEditorToolbar(props) {
|
|
|
11300
11518
|
}
|
|
11301
11519
|
);
|
|
11302
11520
|
}
|
|
11521
|
+
function RichEditorDropZone(props) {
|
|
11522
|
+
const { children, className, "data-rich-editor-theme": themeAttr } = props;
|
|
11523
|
+
const theme = useRichEditorTheme();
|
|
11524
|
+
const [isDragging, setIsDragging] = useState(false);
|
|
11525
|
+
const counterRef = useRef(0);
|
|
11526
|
+
const handleDragEnter = (e) => {
|
|
11527
|
+
if (!e.dataTransfer.types.includes("Files")) return;
|
|
11528
|
+
e.preventDefault();
|
|
11529
|
+
counterRef.current++;
|
|
11530
|
+
setIsDragging(true);
|
|
11531
|
+
};
|
|
11532
|
+
const handleDragLeave = (_e) => {
|
|
11533
|
+
counterRef.current = Math.max(0, counterRef.current - 1);
|
|
11534
|
+
if (counterRef.current === 0) setIsDragging(false);
|
|
11535
|
+
};
|
|
11536
|
+
const handleDragOver = (e) => {
|
|
11537
|
+
if (e.dataTransfer.types.includes("Files")) e.preventDefault();
|
|
11538
|
+
};
|
|
11539
|
+
const handleDrop = (e) => {
|
|
11540
|
+
e.preventDefault();
|
|
11541
|
+
counterRef.current = 0;
|
|
11542
|
+
setIsDragging(false);
|
|
11543
|
+
};
|
|
11544
|
+
return /* @__PURE__ */ jsxs(
|
|
11545
|
+
"div",
|
|
11546
|
+
{
|
|
11547
|
+
className: cn("relative", className),
|
|
11548
|
+
"data-rich-editor-theme": themeAttr,
|
|
11549
|
+
onDragEnter: handleDragEnter,
|
|
11550
|
+
onDragLeave: handleDragLeave,
|
|
11551
|
+
onDragOver: handleDragOver,
|
|
11552
|
+
onDrop: handleDrop,
|
|
11553
|
+
children: [
|
|
11554
|
+
children,
|
|
11555
|
+
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: [
|
|
11556
|
+
/* @__PURE__ */ jsx(Upload, { size: 28, strokeWidth: 1.5 }),
|
|
11557
|
+
/* @__PURE__ */ jsx("span", { className: "text-sm font-medium", children: "\uD30C\uC77C\uC744 \uC5EC\uAE30\uC5D0 \uB193\uC73C\uC138\uC694" }),
|
|
11558
|
+
/* @__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" })
|
|
11559
|
+
] }) })
|
|
11560
|
+
]
|
|
11561
|
+
}
|
|
11562
|
+
);
|
|
11563
|
+
}
|
|
11564
|
+
var EXT_STYLE = {
|
|
11565
|
+
pdf: "bg-red-100 text-red-700",
|
|
11566
|
+
doc: "bg-blue-100 text-blue-700",
|
|
11567
|
+
docx: "bg-blue-100 text-blue-700",
|
|
11568
|
+
hwp: "bg-blue-100 text-blue-700",
|
|
11569
|
+
xls: "bg-green-100 text-green-700",
|
|
11570
|
+
xlsx: "bg-green-100 text-green-700",
|
|
11571
|
+
csv: "bg-emerald-100 text-emerald-700",
|
|
11572
|
+
ppt: "bg-orange-100 text-orange-700",
|
|
11573
|
+
pptx: "bg-orange-100 text-orange-700",
|
|
11574
|
+
zip: "bg-gray-200 text-gray-700",
|
|
11575
|
+
rar: "bg-gray-200 text-gray-700",
|
|
11576
|
+
"7z": "bg-gray-200 text-gray-700",
|
|
11577
|
+
mp4: "bg-purple-100 text-purple-700",
|
|
11578
|
+
mov: "bg-purple-100 text-purple-700",
|
|
11579
|
+
avi: "bg-purple-100 text-purple-700",
|
|
11580
|
+
mp3: "bg-pink-100 text-pink-700",
|
|
11581
|
+
wav: "bg-pink-100 text-pink-700",
|
|
11582
|
+
txt: "bg-gray-100 text-gray-600",
|
|
11583
|
+
json: "bg-yellow-100 text-yellow-700",
|
|
11584
|
+
xml: "bg-yellow-100 text-yellow-700",
|
|
11585
|
+
js: "bg-yellow-100 text-yellow-700",
|
|
11586
|
+
ts: "bg-blue-100 text-blue-700",
|
|
11587
|
+
html: "bg-orange-100 text-orange-700",
|
|
11588
|
+
css: "bg-sky-100 text-sky-700"
|
|
11589
|
+
};
|
|
11590
|
+
function formatSize(bytes) {
|
|
11591
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
11592
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
11593
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
11594
|
+
}
|
|
11595
|
+
function RichEditorFileList(props) {
|
|
11596
|
+
const { attachments, onRemove, renderFilePreview } = props;
|
|
11597
|
+
const theme = useRichEditorTheme();
|
|
11598
|
+
if (attachments.length === 0) return null;
|
|
11599
|
+
return /* @__PURE__ */ jsxs("div", { className: cn("px-3 py-2.5", theme.fileList.wrapper), children: [
|
|
11600
|
+
/* @__PURE__ */ jsxs("p", { className: cn("mb-1.5 text-[11px] font-medium uppercase tracking-wide", theme.fileList.label), children: [
|
|
11601
|
+
"\uCCA8\uBD80\uD30C\uC77C (",
|
|
11602
|
+
attachments.length,
|
|
11603
|
+
")"
|
|
11604
|
+
] }),
|
|
11605
|
+
/* @__PURE__ */ jsx("div", { className: "flex flex-wrap gap-2", children: attachments.map((attachment) => {
|
|
11606
|
+
if (renderFilePreview) {
|
|
11607
|
+
return /* @__PURE__ */ jsx("div", { children: renderFilePreview(attachment, () => onRemove(attachment.id)) }, attachment.id);
|
|
11608
|
+
}
|
|
11609
|
+
const ext = attachment.name.split(".").pop()?.toLowerCase() ?? "";
|
|
11610
|
+
const extStyle = EXT_STYLE[ext] ?? "bg-gray-100 text-gray-600";
|
|
11611
|
+
return /* @__PURE__ */ jsxs(
|
|
11612
|
+
"div",
|
|
11613
|
+
{
|
|
11614
|
+
className: cn("flex items-center gap-2 rounded-md px-2.5 py-1.5 shadow-xs", theme.fileList.item),
|
|
11615
|
+
children: [
|
|
11616
|
+
/* @__PURE__ */ jsx(
|
|
11617
|
+
"span",
|
|
11618
|
+
{
|
|
11619
|
+
className: cn(
|
|
11620
|
+
"shrink-0 rounded px-1.5 py-0.5 text-[10px] font-bold uppercase tracking-wide",
|
|
11621
|
+
extStyle
|
|
11622
|
+
),
|
|
11623
|
+
children: ext || "FILE"
|
|
11624
|
+
}
|
|
11625
|
+
),
|
|
11626
|
+
/* @__PURE__ */ jsx("span", { className: cn("max-w-[140px] truncate text-xs", theme.fileList.itemName), children: attachment.name }),
|
|
11627
|
+
/* @__PURE__ */ jsx("span", { className: cn("shrink-0 text-[11px]", theme.fileList.itemSize), children: formatSize(attachment.size) }),
|
|
11628
|
+
/* @__PURE__ */ jsx(
|
|
11629
|
+
"button",
|
|
11630
|
+
{
|
|
11631
|
+
type: "button",
|
|
11632
|
+
onClick: () => onRemove(attachment.id),
|
|
11633
|
+
title: "\uCCA8\uBD80\uD30C\uC77C \uC81C\uAC70",
|
|
11634
|
+
className: cn("flex h-4 w-4 shrink-0 items-center justify-center rounded-full", theme.fileList.removeBtn),
|
|
11635
|
+
children: /* @__PURE__ */ jsx(X, { size: 10 })
|
|
11636
|
+
}
|
|
11637
|
+
)
|
|
11638
|
+
]
|
|
11639
|
+
},
|
|
11640
|
+
attachment.id
|
|
11641
|
+
);
|
|
11642
|
+
}) })
|
|
11643
|
+
] });
|
|
11644
|
+
}
|
|
11303
11645
|
var DEFAULT_TOOLBAR = {
|
|
11304
11646
|
heading: [1, 2, 3, 4],
|
|
11305
11647
|
bold: true,
|
|
@@ -11323,7 +11665,7 @@ function RichEditorContent(props) {
|
|
|
11323
11665
|
return /* @__PURE__ */ jsx(
|
|
11324
11666
|
"div",
|
|
11325
11667
|
{
|
|
11326
|
-
className: cn("rich-editor-content cursor-text", className),
|
|
11668
|
+
className: cn("rich-editor-content flex-1 cursor-text", className),
|
|
11327
11669
|
style,
|
|
11328
11670
|
onMouseDown: (e) => {
|
|
11329
11671
|
if (!editor) return;
|
|
@@ -11359,7 +11701,10 @@ var RichEditor = forwardRef(function RichEditor2({
|
|
|
11359
11701
|
zIndex,
|
|
11360
11702
|
themeTokens,
|
|
11361
11703
|
editable = true,
|
|
11362
|
-
autofocus
|
|
11704
|
+
autofocus,
|
|
11705
|
+
fileFormat,
|
|
11706
|
+
onFileUpload,
|
|
11707
|
+
renderFilePreview
|
|
11363
11708
|
}, ref) {
|
|
11364
11709
|
const showToolbar = toolbar !== false;
|
|
11365
11710
|
const toolbarOptions = typeof toolbar === "object" ? toolbar : {};
|
|
@@ -11376,7 +11721,16 @@ var RichEditor = forwardRef(function RichEditor2({
|
|
|
11376
11721
|
},
|
|
11377
11722
|
[onChange]
|
|
11378
11723
|
);
|
|
11379
|
-
const {
|
|
11724
|
+
const {
|
|
11725
|
+
editor,
|
|
11726
|
+
attachments,
|
|
11727
|
+
removeAttachment,
|
|
11728
|
+
hydrateAttachments,
|
|
11729
|
+
processFiles,
|
|
11730
|
+
isUploading,
|
|
11731
|
+
getHTML,
|
|
11732
|
+
setContent
|
|
11733
|
+
} = useRichEditor({
|
|
11380
11734
|
defaultValue: value ?? defaultValue,
|
|
11381
11735
|
toolbar: activeToolbar,
|
|
11382
11736
|
mentionUsers,
|
|
@@ -11391,27 +11745,30 @@ var RichEditor = forwardRef(function RichEditor2({
|
|
|
11391
11745
|
editable,
|
|
11392
11746
|
autofocus,
|
|
11393
11747
|
editorClassName,
|
|
11748
|
+
fileFormat,
|
|
11749
|
+
onFileUpload,
|
|
11394
11750
|
onChange: handleChange,
|
|
11395
11751
|
onSubmit
|
|
11396
11752
|
});
|
|
11753
|
+
const fileInputRef = useRef(null);
|
|
11397
11754
|
useEffect(() => {
|
|
11398
11755
|
if (!editor || value === void 0) return;
|
|
11399
11756
|
if (isInternalChangeRef.current) {
|
|
11400
11757
|
isInternalChangeRef.current = false;
|
|
11401
11758
|
return;
|
|
11402
11759
|
}
|
|
11403
|
-
if (
|
|
11404
|
-
|
|
11760
|
+
if (getHTML() !== value) {
|
|
11761
|
+
const split = splitAttachmentsFromHtml(value);
|
|
11762
|
+
editor.commands.setContent(split.html, { emitUpdate: false });
|
|
11763
|
+
hydrateAttachments(split.attachments);
|
|
11405
11764
|
}
|
|
11406
11765
|
}, [value, editor]);
|
|
11407
11766
|
useImperativeHandle(
|
|
11408
11767
|
ref,
|
|
11409
11768
|
() => ({
|
|
11410
|
-
getHTML
|
|
11769
|
+
getHTML,
|
|
11411
11770
|
getJSON: () => editor?.getJSON() ?? {},
|
|
11412
|
-
setContent
|
|
11413
|
-
editor?.commands.setContent(html);
|
|
11414
|
-
},
|
|
11771
|
+
setContent,
|
|
11415
11772
|
clearContent: () => {
|
|
11416
11773
|
editor?.commands.clearContent();
|
|
11417
11774
|
},
|
|
@@ -11421,11 +11778,13 @@ var RichEditor = forwardRef(function RichEditor2({
|
|
|
11421
11778
|
get isEmpty() {
|
|
11422
11779
|
return editor?.isEmpty ?? true;
|
|
11423
11780
|
},
|
|
11781
|
+
attachments,
|
|
11424
11782
|
editor
|
|
11425
11783
|
}),
|
|
11426
|
-
[editor]
|
|
11784
|
+
[editor, attachments, getHTML, setContent]
|
|
11427
11785
|
);
|
|
11428
11786
|
const isToolbarVisible = showToolbar && editable;
|
|
11787
|
+
const imageFeatureEnabled = activeToolbar.image !== false;
|
|
11429
11788
|
const baseTheme = RICH_EDITOR_THEMES[theme];
|
|
11430
11789
|
const resolvedTheme = themeTokens ? {
|
|
11431
11790
|
...baseTheme,
|
|
@@ -11448,10 +11807,37 @@ var RichEditor = forwardRef(function RichEditor2({
|
|
|
11448
11807
|
{
|
|
11449
11808
|
editor,
|
|
11450
11809
|
toolbar: activeToolbar,
|
|
11451
|
-
zIndex
|
|
11810
|
+
zIndex,
|
|
11811
|
+
onImageButtonClick: imageFeatureEnabled ? () => fileInputRef.current?.click() : void 0
|
|
11452
11812
|
}
|
|
11453
11813
|
),
|
|
11454
|
-
/* @__PURE__ */ jsx(
|
|
11814
|
+
imageFeatureEnabled && /* @__PURE__ */ jsx(
|
|
11815
|
+
"input",
|
|
11816
|
+
{
|
|
11817
|
+
ref: fileInputRef,
|
|
11818
|
+
type: "file",
|
|
11819
|
+
multiple: true,
|
|
11820
|
+
accept: buildAcceptAttribute(fileFormat),
|
|
11821
|
+
className: "hidden",
|
|
11822
|
+
onChange: (e) => {
|
|
11823
|
+
const files = Array.from(e.target.files ?? []);
|
|
11824
|
+
if (files.length > 0) processFiles(files);
|
|
11825
|
+
e.target.value = "";
|
|
11826
|
+
}
|
|
11827
|
+
}
|
|
11828
|
+
),
|
|
11829
|
+
imageFeatureEnabled ? /* @__PURE__ */ jsxs(RichEditorDropZone, { className: "flex flex-1 flex-col", "data-rich-editor-theme": theme, children: [
|
|
11830
|
+
/* @__PURE__ */ jsx(
|
|
11831
|
+
RichEditorContent,
|
|
11832
|
+
{
|
|
11833
|
+
editor,
|
|
11834
|
+
className: cn("p-4", bodyClassName),
|
|
11835
|
+
minHeight,
|
|
11836
|
+
maxHeight
|
|
11837
|
+
}
|
|
11838
|
+
),
|
|
11839
|
+
isUploading && /* @__PURE__ */ jsx("div", { className: "pointer-events-none absolute inset-0 z-10 flex items-center justify-center", children: /* @__PURE__ */ jsx(Loading, { size: "lg" }) })
|
|
11840
|
+
] }) : /* @__PURE__ */ jsx(
|
|
11455
11841
|
RichEditorContent,
|
|
11456
11842
|
{
|
|
11457
11843
|
editor,
|
|
@@ -11459,6 +11845,14 @@ var RichEditor = forwardRef(function RichEditor2({
|
|
|
11459
11845
|
minHeight,
|
|
11460
11846
|
maxHeight
|
|
11461
11847
|
}
|
|
11848
|
+
),
|
|
11849
|
+
imageFeatureEnabled && /* @__PURE__ */ jsx(
|
|
11850
|
+
RichEditorFileList,
|
|
11851
|
+
{
|
|
11852
|
+
attachments,
|
|
11853
|
+
onRemove: removeAttachment,
|
|
11854
|
+
renderFilePreview
|
|
11855
|
+
}
|
|
11462
11856
|
)
|
|
11463
11857
|
]
|
|
11464
11858
|
}
|