@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.cjs
CHANGED
|
@@ -1811,10 +1811,12 @@ var ToastManager = class _ToastManager {
|
|
|
1811
1811
|
const props = this.resolveProps(rawProps);
|
|
1812
1812
|
const position = props.position || "top-center";
|
|
1813
1813
|
const duration = props.duration !== void 0 ? props.duration : 1500;
|
|
1814
|
+
const isSameToast = (other) => (other.props.type ?? "info") === (props.type ?? "info") && other.props.toast === props.toast;
|
|
1814
1815
|
if (props.id) {
|
|
1815
1816
|
for (const [pos, toasts] of this.toasts.entries()) {
|
|
1816
1817
|
const existing = toasts.find((t) => t.id === props.id);
|
|
1817
1818
|
if (existing) {
|
|
1819
|
+
if (isSameToast(existing)) return existing.id;
|
|
1818
1820
|
if (existing.timer) clearTimeout(existing.timer);
|
|
1819
1821
|
const updated = toasts.filter((t) => t.id !== props.id);
|
|
1820
1822
|
this.toasts.set(pos, updated);
|
|
@@ -1825,7 +1827,9 @@ var ToastManager = class _ToastManager {
|
|
|
1825
1827
|
}
|
|
1826
1828
|
}
|
|
1827
1829
|
const positionToasts = this.toasts.get(position) || [];
|
|
1828
|
-
|
|
1830
|
+
const existingAtPosition = positionToasts[0];
|
|
1831
|
+
if (existingAtPosition) {
|
|
1832
|
+
if (isSameToast(existingAtPosition)) return existingAtPosition.id;
|
|
1829
1833
|
positionToasts.forEach((toast2) => {
|
|
1830
1834
|
if (toast2.timer) clearTimeout(toast2.timer);
|
|
1831
1835
|
});
|
|
@@ -3275,25 +3279,24 @@ function SearchBar(props) {
|
|
|
3275
3279
|
function DebouncedButton(props) {
|
|
3276
3280
|
const { debounceDelay = 300, onClick, className, ...rest } = props;
|
|
3277
3281
|
const [isDebouncing, setIsDebouncing] = React6.useState(false);
|
|
3282
|
+
const onClickRef = React6.useRef(onClick);
|
|
3283
|
+
onClickRef.current = onClick;
|
|
3278
3284
|
const debouncedOnClick = React6.useMemo(() => {
|
|
3279
|
-
if (!onClick) return void 0;
|
|
3280
3285
|
return esToolkit.debounce((event) => {
|
|
3281
3286
|
setIsDebouncing(false);
|
|
3282
|
-
|
|
3287
|
+
onClickRef.current?.(event);
|
|
3283
3288
|
}, debounceDelay);
|
|
3284
|
-
}, [debounceDelay
|
|
3289
|
+
}, [debounceDelay]);
|
|
3285
3290
|
React6.useEffect(() => {
|
|
3286
3291
|
return () => {
|
|
3287
|
-
debouncedOnClick
|
|
3292
|
+
debouncedOnClick.cancel();
|
|
3288
3293
|
setIsDebouncing(false);
|
|
3289
3294
|
};
|
|
3290
3295
|
}, [debouncedOnClick]);
|
|
3291
3296
|
const handleClick = (event) => {
|
|
3292
|
-
if (
|
|
3297
|
+
if (onClickRef.current) {
|
|
3293
3298
|
setIsDebouncing(true);
|
|
3294
3299
|
debouncedOnClick(event);
|
|
3295
|
-
} else {
|
|
3296
|
-
onClick?.(event);
|
|
3297
3300
|
}
|
|
3298
3301
|
};
|
|
3299
3302
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
@@ -10431,7 +10434,7 @@ function buildExtensions(config) {
|
|
|
10431
10434
|
accentTextColor,
|
|
10432
10435
|
zIndex
|
|
10433
10436
|
} = config;
|
|
10434
|
-
const exts = [extensionTextStyle.TextStyleKit, buildMarkResetOnEnter()];
|
|
10437
|
+
const exts = [extensionTextStyle.TextStyleKit, buildMarkResetOnEnter(), buildRedundantListMarkerStrip()];
|
|
10435
10438
|
const headingLevels = toolbar.heading === false ? [] : Array.isArray(toolbar.heading) ? [...toolbar.heading] : [1, 2, 3, 4];
|
|
10436
10439
|
exts.push(
|
|
10437
10440
|
StarterKit__default.default.configure({
|
|
@@ -10607,6 +10610,36 @@ function buildMarkResetOnEnter() {
|
|
|
10607
10610
|
}
|
|
10608
10611
|
});
|
|
10609
10612
|
}
|
|
10613
|
+
function buildRedundantListMarkerStrip() {
|
|
10614
|
+
const bulletMarkerRegex = /^\s*([-+*])\s$/;
|
|
10615
|
+
const orderedMarkerRegex = /^(\d+)\.\s$/;
|
|
10616
|
+
function makeRule(listTypeName, regex) {
|
|
10617
|
+
return new core.InputRule({
|
|
10618
|
+
find: regex,
|
|
10619
|
+
handler: ({ state, range, chain }) => {
|
|
10620
|
+
const { $from } = state.selection;
|
|
10621
|
+
if ($from.depth < 2) return null;
|
|
10622
|
+
const parent = $from.node($from.depth - 1);
|
|
10623
|
+
const grandparent = $from.node($from.depth - 2);
|
|
10624
|
+
if (parent.type.name !== "listItem" || grandparent.type.name !== listTypeName) {
|
|
10625
|
+
return null;
|
|
10626
|
+
}
|
|
10627
|
+
chain().deleteRange(range).run();
|
|
10628
|
+
return void 0;
|
|
10629
|
+
}
|
|
10630
|
+
});
|
|
10631
|
+
}
|
|
10632
|
+
return core.Extension.create({
|
|
10633
|
+
name: "redundantListMarkerStrip",
|
|
10634
|
+
priority: 200,
|
|
10635
|
+
addInputRules() {
|
|
10636
|
+
return [
|
|
10637
|
+
makeRule("bulletList", bulletMarkerRegex),
|
|
10638
|
+
makeRule("orderedList", orderedMarkerRegex)
|
|
10639
|
+
];
|
|
10640
|
+
}
|
|
10641
|
+
});
|
|
10642
|
+
}
|
|
10610
10643
|
|
|
10611
10644
|
// src/components/RichEditor/config/keyboardHandlers.ts
|
|
10612
10645
|
function createKeyboardHandler(codeBlockEmptyEnterRef, onSubmitRef) {
|
|
@@ -10687,8 +10720,149 @@ function createKeyboardHandler(codeBlockEmptyEnterRef, onSubmitRef) {
|
|
|
10687
10720
|
};
|
|
10688
10721
|
}
|
|
10689
10722
|
|
|
10723
|
+
// src/components/RichEditor/config/fileHandlers.ts
|
|
10724
|
+
function createPasteHandler(processFilesRef) {
|
|
10725
|
+
return (_view, event) => {
|
|
10726
|
+
const files = Array.from(event.clipboardData?.files ?? []);
|
|
10727
|
+
if (files.length === 0) return false;
|
|
10728
|
+
event.preventDefault();
|
|
10729
|
+
processFilesRef.current(files);
|
|
10730
|
+
return true;
|
|
10731
|
+
};
|
|
10732
|
+
}
|
|
10733
|
+
function createDropHandler(processFilesRef) {
|
|
10734
|
+
return (_view, event) => {
|
|
10735
|
+
const files = Array.from(event.dataTransfer?.files ?? []);
|
|
10736
|
+
if (files.length === 0) return false;
|
|
10737
|
+
event.preventDefault();
|
|
10738
|
+
processFilesRef.current(files);
|
|
10739
|
+
return true;
|
|
10740
|
+
};
|
|
10741
|
+
}
|
|
10742
|
+
var FORMAT_EXT_ALIASES = {
|
|
10743
|
+
JPG: ["jpg", "jpeg"],
|
|
10744
|
+
JPEG: ["jpg", "jpeg"]
|
|
10745
|
+
};
|
|
10746
|
+
function expandFormats(fileFormat) {
|
|
10747
|
+
const exts = /* @__PURE__ */ new Set();
|
|
10748
|
+
for (const format of fileFormat) {
|
|
10749
|
+
const key = format.toUpperCase();
|
|
10750
|
+
const aliases = FORMAT_EXT_ALIASES[key] ?? [format.toLowerCase()];
|
|
10751
|
+
aliases.forEach((ext) => exts.add(ext));
|
|
10752
|
+
}
|
|
10753
|
+
return exts;
|
|
10754
|
+
}
|
|
10755
|
+
function extOf(fileName) {
|
|
10756
|
+
return fileName.split(".").pop()?.toLowerCase() ?? "";
|
|
10757
|
+
}
|
|
10758
|
+
function buildAcceptAttribute(fileFormat) {
|
|
10759
|
+
if (!fileFormat || fileFormat.length === 0) return void 0;
|
|
10760
|
+
return Array.from(expandFormats(fileFormat)).map((ext) => `.${ext}`).join(",");
|
|
10761
|
+
}
|
|
10762
|
+
function useRichEditorFiles(options = {}) {
|
|
10763
|
+
const { fileFormat, onFileUpload, initialAttachments } = options;
|
|
10764
|
+
const [attachments, setAttachments] = React6.useState(() => initialAttachments ?? []);
|
|
10765
|
+
const [isUploading, setIsUploading] = React6.useState(false);
|
|
10766
|
+
const removeAttachment = React6.useCallback((id) => {
|
|
10767
|
+
setAttachments((prev) => prev.filter((a) => a.id !== id));
|
|
10768
|
+
}, []);
|
|
10769
|
+
const hydrateAttachments = React6.useCallback((loaded) => {
|
|
10770
|
+
setAttachments(loaded);
|
|
10771
|
+
}, []);
|
|
10772
|
+
const processFiles = React6.useCallback(
|
|
10773
|
+
async (files, editor) => {
|
|
10774
|
+
const allowedExts = fileFormat ? expandFormats(fileFormat) : null;
|
|
10775
|
+
const accepted = allowedExts ? files.filter((f) => allowedExts.has(extOf(f.name))) : files;
|
|
10776
|
+
if (accepted.length === 0) return;
|
|
10777
|
+
setIsUploading(true);
|
|
10778
|
+
try {
|
|
10779
|
+
for (const file of accepted) {
|
|
10780
|
+
let url;
|
|
10781
|
+
try {
|
|
10782
|
+
url = await (onFileUpload ? onFileUpload(file) : URL.createObjectURL(file));
|
|
10783
|
+
} catch {
|
|
10784
|
+
continue;
|
|
10785
|
+
}
|
|
10786
|
+
if (file.type.startsWith("image/")) {
|
|
10787
|
+
if (!editor) continue;
|
|
10788
|
+
editor.chain().focus().insertContent({ type: "image", attrs: { src: url } }).run();
|
|
10789
|
+
editor.commands.setTextSelection(editor.state.selection.to);
|
|
10790
|
+
} else {
|
|
10791
|
+
setAttachments((prev) => [
|
|
10792
|
+
...prev,
|
|
10793
|
+
{
|
|
10794
|
+
id: `${Date.now()}-${Math.random().toString(36).slice(2)}`,
|
|
10795
|
+
name: file.name,
|
|
10796
|
+
size: file.size,
|
|
10797
|
+
mimeType: file.type,
|
|
10798
|
+
file,
|
|
10799
|
+
url
|
|
10800
|
+
}
|
|
10801
|
+
]);
|
|
10802
|
+
}
|
|
10803
|
+
}
|
|
10804
|
+
} finally {
|
|
10805
|
+
setIsUploading(false);
|
|
10806
|
+
}
|
|
10807
|
+
},
|
|
10808
|
+
[fileFormat, onFileUpload]
|
|
10809
|
+
);
|
|
10810
|
+
return { attachments, processFiles, removeAttachment, hydrateAttachments, isUploading };
|
|
10811
|
+
}
|
|
10812
|
+
|
|
10813
|
+
// src/components/RichEditor/config/attachmentSerialization.ts
|
|
10814
|
+
var ATTACHMENTS_CONTAINER_ATTR = "data-rich-editor-attachments";
|
|
10815
|
+
var ATTACHMENT_ITEM_ATTR = "data-rich-editor-attachment";
|
|
10816
|
+
function escapeHtmlAttr(value) {
|
|
10817
|
+
return value.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">");
|
|
10818
|
+
}
|
|
10819
|
+
function escapeHtmlText(value) {
|
|
10820
|
+
return value.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">");
|
|
10821
|
+
}
|
|
10822
|
+
function serializeAttachmentsBlock(attachments) {
|
|
10823
|
+
if (attachments.length === 0) return "";
|
|
10824
|
+
const items = attachments.map((attachment) => {
|
|
10825
|
+
const href = escapeHtmlAttr(attachment.url);
|
|
10826
|
+
const name = escapeHtmlAttr(attachment.name);
|
|
10827
|
+
return `<a ${ATTACHMENT_ITEM_ATTR}="true" href="${href}" data-name="${name}" data-size="${attachment.size}" data-mime="${escapeHtmlAttr(attachment.mimeType)}">${escapeHtmlText(attachment.name)}</a>`;
|
|
10828
|
+
}).join("");
|
|
10829
|
+
return `<div ${ATTACHMENTS_CONTAINER_ATTR}="true">${items}</div>`;
|
|
10830
|
+
}
|
|
10831
|
+
function splitAttachmentsFromHtml(html) {
|
|
10832
|
+
if (!html || !html.includes(ATTACHMENTS_CONTAINER_ATTR) || typeof DOMParser === "undefined") {
|
|
10833
|
+
return { html, attachments: [] };
|
|
10834
|
+
}
|
|
10835
|
+
const doc = new DOMParser().parseFromString(html, "text/html");
|
|
10836
|
+
const container2 = doc.body.querySelector(`[${ATTACHMENTS_CONTAINER_ATTR}]`);
|
|
10837
|
+
if (!container2) {
|
|
10838
|
+
return { html, attachments: [] };
|
|
10839
|
+
}
|
|
10840
|
+
const attachments = Array.from(
|
|
10841
|
+
container2.querySelectorAll(`[${ATTACHMENT_ITEM_ATTR}]`)
|
|
10842
|
+
).map((el, index) => {
|
|
10843
|
+
const url = el.getAttribute("href") ?? "";
|
|
10844
|
+
const name = el.getAttribute("data-name") ?? el.textContent ?? `file-${index}`;
|
|
10845
|
+
const mimeType = el.getAttribute("data-mime") ?? "";
|
|
10846
|
+
const size2 = Number(el.getAttribute("data-size") ?? "0") || 0;
|
|
10847
|
+
return {
|
|
10848
|
+
id: `loaded-${index}-${Math.random().toString(36).slice(2)}`,
|
|
10849
|
+
name,
|
|
10850
|
+
size: size2,
|
|
10851
|
+
mimeType,
|
|
10852
|
+
file: new File([], name, { type: mimeType }),
|
|
10853
|
+
url
|
|
10854
|
+
};
|
|
10855
|
+
});
|
|
10856
|
+
container2.remove();
|
|
10857
|
+
return { html: doc.body.innerHTML, attachments };
|
|
10858
|
+
}
|
|
10859
|
+
function composeRichEditorHtml(bodyHtml, attachments) {
|
|
10860
|
+
const block = serializeAttachmentsBlock(attachments);
|
|
10861
|
+
return block ? `${bodyHtml}${block}` : bodyHtml;
|
|
10862
|
+
}
|
|
10863
|
+
|
|
10690
10864
|
// src/components/RichEditor/hooks/useRichEditor.ts
|
|
10691
|
-
var DEFAULT_EDITOR_CLASS = "focus:outline-none";
|
|
10865
|
+
var DEFAULT_EDITOR_CLASS = "focus:outline-none h-full";
|
|
10692
10866
|
function useRichEditor(options = {}) {
|
|
10693
10867
|
const {
|
|
10694
10868
|
defaultValue,
|
|
@@ -10705,6 +10879,8 @@ function useRichEditor(options = {}) {
|
|
|
10705
10879
|
autofocus,
|
|
10706
10880
|
editorClassName,
|
|
10707
10881
|
additionalExtensions = [],
|
|
10882
|
+
fileFormat,
|
|
10883
|
+
onFileUpload,
|
|
10708
10884
|
onChange,
|
|
10709
10885
|
onSubmit
|
|
10710
10886
|
} = options;
|
|
@@ -10713,6 +10889,23 @@ function useRichEditor(options = {}) {
|
|
|
10713
10889
|
onChangeRef.current = onChange;
|
|
10714
10890
|
const onSubmitRef = React6.useRef(onSubmit);
|
|
10715
10891
|
onSubmitRef.current = onSubmit;
|
|
10892
|
+
const initialSplitRef = React6.useRef(null);
|
|
10893
|
+
if (initialSplitRef.current === null) {
|
|
10894
|
+
initialSplitRef.current = splitAttachmentsFromHtml(defaultValue ?? "");
|
|
10895
|
+
}
|
|
10896
|
+
const initialSplit = initialSplitRef.current;
|
|
10897
|
+
const { attachments, processFiles, removeAttachment, hydrateAttachments, isUploading } = useRichEditorFiles({
|
|
10898
|
+
fileFormat,
|
|
10899
|
+
onFileUpload,
|
|
10900
|
+
initialAttachments: initialSplit.attachments
|
|
10901
|
+
});
|
|
10902
|
+
const attachmentsRef = React6.useRef(attachments);
|
|
10903
|
+
attachmentsRef.current = attachments;
|
|
10904
|
+
const editorRef = React6.useRef(null);
|
|
10905
|
+
const processFilesRef = React6.useRef(() => {
|
|
10906
|
+
});
|
|
10907
|
+
processFilesRef.current = (files) => processFiles(files, editorRef.current);
|
|
10908
|
+
const imageFeatureEnabled = toolbar.image !== false;
|
|
10716
10909
|
const extensions = [
|
|
10717
10910
|
...buildExtensions({
|
|
10718
10911
|
toolbar,
|
|
@@ -10735,22 +10928,33 @@ function useRichEditor(options = {}) {
|
|
|
10735
10928
|
attributes: {
|
|
10736
10929
|
class: cn(DEFAULT_EDITOR_CLASS, editorClassName)
|
|
10737
10930
|
},
|
|
10738
|
-
handleKeyDown: createKeyboardHandler(codeBlockEmptyEnterRef, onSubmitRef)
|
|
10931
|
+
handleKeyDown: createKeyboardHandler(codeBlockEmptyEnterRef, onSubmitRef),
|
|
10932
|
+
...imageFeatureEnabled ? {
|
|
10933
|
+
handlePaste: createPasteHandler(processFilesRef),
|
|
10934
|
+
handleDrop: createDropHandler(processFilesRef)
|
|
10935
|
+
} : {}
|
|
10739
10936
|
},
|
|
10740
|
-
content:
|
|
10937
|
+
content: initialSplit.html,
|
|
10741
10938
|
onUpdate: ({ editor: editor2 }) => {
|
|
10742
|
-
onChangeRef.current?.(editor2.getHTML());
|
|
10939
|
+
onChangeRef.current?.(composeRichEditorHtml(editor2.getHTML(), attachmentsRef.current));
|
|
10743
10940
|
}
|
|
10744
10941
|
});
|
|
10942
|
+
editorRef.current = editor;
|
|
10745
10943
|
React6.useEffect(() => {
|
|
10746
|
-
if (editor)
|
|
10747
|
-
|
|
10944
|
+
if (!editor) return;
|
|
10945
|
+
onChangeRef.current?.(composeRichEditorHtml(editor.getHTML(), attachments));
|
|
10946
|
+
}, [attachments]);
|
|
10947
|
+
React6.useEffect(() => {
|
|
10948
|
+
if (editor) editor.setEditable(editable && !isUploading);
|
|
10949
|
+
}, [editor, editable, isUploading]);
|
|
10748
10950
|
return {
|
|
10749
10951
|
editor,
|
|
10750
|
-
getHTML: () => editor?.getHTML() ?? "",
|
|
10952
|
+
getHTML: () => composeRichEditorHtml(editor?.getHTML() ?? "", attachments),
|
|
10751
10953
|
getJSON: () => editor?.getJSON() ?? {},
|
|
10752
10954
|
setContent: (html) => {
|
|
10753
|
-
|
|
10955
|
+
const split = splitAttachmentsFromHtml(html);
|
|
10956
|
+
editor?.commands.setContent(split.html);
|
|
10957
|
+
hydrateAttachments(split.attachments);
|
|
10754
10958
|
},
|
|
10755
10959
|
clearContent: () => {
|
|
10756
10960
|
editor?.commands.clearContent();
|
|
@@ -10758,9 +10962,12 @@ function useRichEditor(options = {}) {
|
|
|
10758
10962
|
focus: () => {
|
|
10759
10963
|
editor?.commands.focus();
|
|
10760
10964
|
},
|
|
10761
|
-
isEmpty: editor?.isEmpty ?? true
|
|
10762
|
-
|
|
10763
|
-
|
|
10965
|
+
isEmpty: editor?.isEmpty ?? true,
|
|
10966
|
+
attachments,
|
|
10967
|
+
removeAttachment,
|
|
10968
|
+
hydrateAttachments,
|
|
10969
|
+
processFiles: processFilesRef.current,
|
|
10970
|
+
isUploading
|
|
10764
10971
|
};
|
|
10765
10972
|
}
|
|
10766
10973
|
var MAX_COLS = 8;
|
|
@@ -10949,7 +11156,7 @@ function cmd(fn) {
|
|
|
10949
11156
|
};
|
|
10950
11157
|
}
|
|
10951
11158
|
function RichEditorToolbar(props) {
|
|
10952
|
-
const { editor, toolbar = {}, className, zIndex } = props;
|
|
11159
|
+
const { editor, toolbar = {}, className, zIndex, onImageButtonClick } = props;
|
|
10953
11160
|
const popoverStyle = zIndex !== void 0 ? { zIndex } : void 0;
|
|
10954
11161
|
const theme = useRichEditorTheme();
|
|
10955
11162
|
const [tablePickerOpen, setTablePickerOpen] = React6.useState(false);
|
|
@@ -11223,6 +11430,17 @@ function RichEditorToolbar(props) {
|
|
|
11223
11430
|
}
|
|
11224
11431
|
)
|
|
11225
11432
|
] }),
|
|
11433
|
+
toolbar.image !== false && onImageButtonClick && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
11434
|
+
/* @__PURE__ */ jsxRuntime.jsx(Divider, {}),
|
|
11435
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11436
|
+
ToolbarButton,
|
|
11437
|
+
{
|
|
11438
|
+
onMouseDown: cmd(onImageButtonClick),
|
|
11439
|
+
title: "\uC774\uBBF8\uC9C0/\uD30C\uC77C \uC0BD\uC785",
|
|
11440
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.Image, { size: 16 })
|
|
11441
|
+
}
|
|
11442
|
+
)
|
|
11443
|
+
] }),
|
|
11226
11444
|
toolbar.table && /* @__PURE__ */ jsxRuntime.jsxs(jsxRuntime.Fragment, { children: [
|
|
11227
11445
|
/* @__PURE__ */ jsxRuntime.jsx(Divider, {}),
|
|
11228
11446
|
/* @__PURE__ */ jsxRuntime.jsxs(Popover, { open: tablePickerOpen, onOpenChange: setTablePickerOpen, children: [
|
|
@@ -11337,6 +11555,130 @@ function RichEditorToolbar(props) {
|
|
|
11337
11555
|
}
|
|
11338
11556
|
);
|
|
11339
11557
|
}
|
|
11558
|
+
function RichEditorDropZone(props) {
|
|
11559
|
+
const { children, className, "data-rich-editor-theme": themeAttr } = props;
|
|
11560
|
+
const theme = useRichEditorTheme();
|
|
11561
|
+
const [isDragging, setIsDragging] = React6.useState(false);
|
|
11562
|
+
const counterRef = React6.useRef(0);
|
|
11563
|
+
const handleDragEnter = (e) => {
|
|
11564
|
+
if (!e.dataTransfer.types.includes("Files")) return;
|
|
11565
|
+
e.preventDefault();
|
|
11566
|
+
counterRef.current++;
|
|
11567
|
+
setIsDragging(true);
|
|
11568
|
+
};
|
|
11569
|
+
const handleDragLeave = (_e) => {
|
|
11570
|
+
counterRef.current = Math.max(0, counterRef.current - 1);
|
|
11571
|
+
if (counterRef.current === 0) setIsDragging(false);
|
|
11572
|
+
};
|
|
11573
|
+
const handleDragOver = (e) => {
|
|
11574
|
+
if (e.dataTransfer.types.includes("Files")) e.preventDefault();
|
|
11575
|
+
};
|
|
11576
|
+
const handleDrop = (e) => {
|
|
11577
|
+
e.preventDefault();
|
|
11578
|
+
counterRef.current = 0;
|
|
11579
|
+
setIsDragging(false);
|
|
11580
|
+
};
|
|
11581
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
11582
|
+
"div",
|
|
11583
|
+
{
|
|
11584
|
+
className: cn("relative", className),
|
|
11585
|
+
"data-rich-editor-theme": themeAttr,
|
|
11586
|
+
onDragEnter: handleDragEnter,
|
|
11587
|
+
onDragLeave: handleDragLeave,
|
|
11588
|
+
onDragOver: handleDragOver,
|
|
11589
|
+
onDrop: handleDrop,
|
|
11590
|
+
children: [
|
|
11591
|
+
children,
|
|
11592
|
+
isDragging && /* @__PURE__ */ jsxRuntime.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__ */ jsxRuntime.jsxs("div", { className: "flex flex-col items-center gap-2", children: [
|
|
11593
|
+
/* @__PURE__ */ jsxRuntime.jsx(lucideReact.Upload, { size: 28, strokeWidth: 1.5 }),
|
|
11594
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: "text-sm font-medium", children: "\uD30C\uC77C\uC744 \uC5EC\uAE30\uC5D0 \uB193\uC73C\uC138\uC694" }),
|
|
11595
|
+
/* @__PURE__ */ jsxRuntime.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" })
|
|
11596
|
+
] }) })
|
|
11597
|
+
]
|
|
11598
|
+
}
|
|
11599
|
+
);
|
|
11600
|
+
}
|
|
11601
|
+
var EXT_STYLE = {
|
|
11602
|
+
pdf: "bg-red-100 text-red-700",
|
|
11603
|
+
doc: "bg-blue-100 text-blue-700",
|
|
11604
|
+
docx: "bg-blue-100 text-blue-700",
|
|
11605
|
+
hwp: "bg-blue-100 text-blue-700",
|
|
11606
|
+
xls: "bg-green-100 text-green-700",
|
|
11607
|
+
xlsx: "bg-green-100 text-green-700",
|
|
11608
|
+
csv: "bg-emerald-100 text-emerald-700",
|
|
11609
|
+
ppt: "bg-orange-100 text-orange-700",
|
|
11610
|
+
pptx: "bg-orange-100 text-orange-700",
|
|
11611
|
+
zip: "bg-gray-200 text-gray-700",
|
|
11612
|
+
rar: "bg-gray-200 text-gray-700",
|
|
11613
|
+
"7z": "bg-gray-200 text-gray-700",
|
|
11614
|
+
mp4: "bg-purple-100 text-purple-700",
|
|
11615
|
+
mov: "bg-purple-100 text-purple-700",
|
|
11616
|
+
avi: "bg-purple-100 text-purple-700",
|
|
11617
|
+
mp3: "bg-pink-100 text-pink-700",
|
|
11618
|
+
wav: "bg-pink-100 text-pink-700",
|
|
11619
|
+
txt: "bg-gray-100 text-gray-600",
|
|
11620
|
+
json: "bg-yellow-100 text-yellow-700",
|
|
11621
|
+
xml: "bg-yellow-100 text-yellow-700",
|
|
11622
|
+
js: "bg-yellow-100 text-yellow-700",
|
|
11623
|
+
ts: "bg-blue-100 text-blue-700",
|
|
11624
|
+
html: "bg-orange-100 text-orange-700",
|
|
11625
|
+
css: "bg-sky-100 text-sky-700"
|
|
11626
|
+
};
|
|
11627
|
+
function formatSize(bytes) {
|
|
11628
|
+
if (bytes < 1024) return `${bytes} B`;
|
|
11629
|
+
if (bytes < 1024 * 1024) return `${(bytes / 1024).toFixed(1)} KB`;
|
|
11630
|
+
return `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
11631
|
+
}
|
|
11632
|
+
function RichEditorFileList(props) {
|
|
11633
|
+
const { attachments, onRemove, renderFilePreview } = props;
|
|
11634
|
+
const theme = useRichEditorTheme();
|
|
11635
|
+
if (attachments.length === 0) return null;
|
|
11636
|
+
return /* @__PURE__ */ jsxRuntime.jsxs("div", { className: cn("px-3 py-2.5", theme.fileList.wrapper), children: [
|
|
11637
|
+
/* @__PURE__ */ jsxRuntime.jsxs("p", { className: cn("mb-1.5 text-[11px] font-medium uppercase tracking-wide", theme.fileList.label), children: [
|
|
11638
|
+
"\uCCA8\uBD80\uD30C\uC77C (",
|
|
11639
|
+
attachments.length,
|
|
11640
|
+
")"
|
|
11641
|
+
] }),
|
|
11642
|
+
/* @__PURE__ */ jsxRuntime.jsx("div", { className: "flex flex-wrap gap-2", children: attachments.map((attachment) => {
|
|
11643
|
+
if (renderFilePreview) {
|
|
11644
|
+
return /* @__PURE__ */ jsxRuntime.jsx("div", { children: renderFilePreview(attachment, () => onRemove(attachment.id)) }, attachment.id);
|
|
11645
|
+
}
|
|
11646
|
+
const ext = attachment.name.split(".").pop()?.toLowerCase() ?? "";
|
|
11647
|
+
const extStyle = EXT_STYLE[ext] ?? "bg-gray-100 text-gray-600";
|
|
11648
|
+
return /* @__PURE__ */ jsxRuntime.jsxs(
|
|
11649
|
+
"div",
|
|
11650
|
+
{
|
|
11651
|
+
className: cn("flex items-center gap-2 rounded-md px-2.5 py-1.5 shadow-xs", theme.fileList.item),
|
|
11652
|
+
children: [
|
|
11653
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11654
|
+
"span",
|
|
11655
|
+
{
|
|
11656
|
+
className: cn(
|
|
11657
|
+
"shrink-0 rounded px-1.5 py-0.5 text-[10px] font-bold uppercase tracking-wide",
|
|
11658
|
+
extStyle
|
|
11659
|
+
),
|
|
11660
|
+
children: ext || "FILE"
|
|
11661
|
+
}
|
|
11662
|
+
),
|
|
11663
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: cn("max-w-[140px] truncate text-xs", theme.fileList.itemName), children: attachment.name }),
|
|
11664
|
+
/* @__PURE__ */ jsxRuntime.jsx("span", { className: cn("shrink-0 text-[11px]", theme.fileList.itemSize), children: formatSize(attachment.size) }),
|
|
11665
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11666
|
+
"button",
|
|
11667
|
+
{
|
|
11668
|
+
type: "button",
|
|
11669
|
+
onClick: () => onRemove(attachment.id),
|
|
11670
|
+
title: "\uCCA8\uBD80\uD30C\uC77C \uC81C\uAC70",
|
|
11671
|
+
className: cn("flex h-4 w-4 shrink-0 items-center justify-center rounded-full", theme.fileList.removeBtn),
|
|
11672
|
+
children: /* @__PURE__ */ jsxRuntime.jsx(lucideReact.X, { size: 10 })
|
|
11673
|
+
}
|
|
11674
|
+
)
|
|
11675
|
+
]
|
|
11676
|
+
},
|
|
11677
|
+
attachment.id
|
|
11678
|
+
);
|
|
11679
|
+
}) })
|
|
11680
|
+
] });
|
|
11681
|
+
}
|
|
11340
11682
|
var DEFAULT_TOOLBAR = {
|
|
11341
11683
|
heading: [1, 2, 3, 4],
|
|
11342
11684
|
bold: true,
|
|
@@ -11360,7 +11702,7 @@ function RichEditorContent(props) {
|
|
|
11360
11702
|
return /* @__PURE__ */ jsxRuntime.jsx(
|
|
11361
11703
|
"div",
|
|
11362
11704
|
{
|
|
11363
|
-
className: cn("rich-editor-content cursor-text", className),
|
|
11705
|
+
className: cn("rich-editor-content flex-1 cursor-text", className),
|
|
11364
11706
|
style,
|
|
11365
11707
|
onMouseDown: (e) => {
|
|
11366
11708
|
if (!editor) return;
|
|
@@ -11396,7 +11738,10 @@ var RichEditor = React6.forwardRef(function RichEditor2({
|
|
|
11396
11738
|
zIndex,
|
|
11397
11739
|
themeTokens,
|
|
11398
11740
|
editable = true,
|
|
11399
|
-
autofocus
|
|
11741
|
+
autofocus,
|
|
11742
|
+
fileFormat,
|
|
11743
|
+
onFileUpload,
|
|
11744
|
+
renderFilePreview
|
|
11400
11745
|
}, ref) {
|
|
11401
11746
|
const showToolbar = toolbar !== false;
|
|
11402
11747
|
const toolbarOptions = typeof toolbar === "object" ? toolbar : {};
|
|
@@ -11413,7 +11758,16 @@ var RichEditor = React6.forwardRef(function RichEditor2({
|
|
|
11413
11758
|
},
|
|
11414
11759
|
[onChange]
|
|
11415
11760
|
);
|
|
11416
|
-
const {
|
|
11761
|
+
const {
|
|
11762
|
+
editor,
|
|
11763
|
+
attachments,
|
|
11764
|
+
removeAttachment,
|
|
11765
|
+
hydrateAttachments,
|
|
11766
|
+
processFiles,
|
|
11767
|
+
isUploading,
|
|
11768
|
+
getHTML,
|
|
11769
|
+
setContent
|
|
11770
|
+
} = useRichEditor({
|
|
11417
11771
|
defaultValue: value ?? defaultValue,
|
|
11418
11772
|
toolbar: activeToolbar,
|
|
11419
11773
|
mentionUsers,
|
|
@@ -11428,27 +11782,30 @@ var RichEditor = React6.forwardRef(function RichEditor2({
|
|
|
11428
11782
|
editable,
|
|
11429
11783
|
autofocus,
|
|
11430
11784
|
editorClassName,
|
|
11785
|
+
fileFormat,
|
|
11786
|
+
onFileUpload,
|
|
11431
11787
|
onChange: handleChange,
|
|
11432
11788
|
onSubmit
|
|
11433
11789
|
});
|
|
11790
|
+
const fileInputRef = React6.useRef(null);
|
|
11434
11791
|
React6.useEffect(() => {
|
|
11435
11792
|
if (!editor || value === void 0) return;
|
|
11436
11793
|
if (isInternalChangeRef.current) {
|
|
11437
11794
|
isInternalChangeRef.current = false;
|
|
11438
11795
|
return;
|
|
11439
11796
|
}
|
|
11440
|
-
if (
|
|
11441
|
-
|
|
11797
|
+
if (getHTML() !== value) {
|
|
11798
|
+
const split = splitAttachmentsFromHtml(value);
|
|
11799
|
+
editor.commands.setContent(split.html, { emitUpdate: false });
|
|
11800
|
+
hydrateAttachments(split.attachments);
|
|
11442
11801
|
}
|
|
11443
11802
|
}, [value, editor]);
|
|
11444
11803
|
React6.useImperativeHandle(
|
|
11445
11804
|
ref,
|
|
11446
11805
|
() => ({
|
|
11447
|
-
getHTML
|
|
11806
|
+
getHTML,
|
|
11448
11807
|
getJSON: () => editor?.getJSON() ?? {},
|
|
11449
|
-
setContent
|
|
11450
|
-
editor?.commands.setContent(html);
|
|
11451
|
-
},
|
|
11808
|
+
setContent,
|
|
11452
11809
|
clearContent: () => {
|
|
11453
11810
|
editor?.commands.clearContent();
|
|
11454
11811
|
},
|
|
@@ -11458,11 +11815,13 @@ var RichEditor = React6.forwardRef(function RichEditor2({
|
|
|
11458
11815
|
get isEmpty() {
|
|
11459
11816
|
return editor?.isEmpty ?? true;
|
|
11460
11817
|
},
|
|
11818
|
+
attachments,
|
|
11461
11819
|
editor
|
|
11462
11820
|
}),
|
|
11463
|
-
[editor]
|
|
11821
|
+
[editor, attachments, getHTML, setContent]
|
|
11464
11822
|
);
|
|
11465
11823
|
const isToolbarVisible = showToolbar && editable;
|
|
11824
|
+
const imageFeatureEnabled = activeToolbar.image !== false;
|
|
11466
11825
|
const baseTheme = RICH_EDITOR_THEMES[theme];
|
|
11467
11826
|
const resolvedTheme = themeTokens ? {
|
|
11468
11827
|
...baseTheme,
|
|
@@ -11485,10 +11844,37 @@ var RichEditor = React6.forwardRef(function RichEditor2({
|
|
|
11485
11844
|
{
|
|
11486
11845
|
editor,
|
|
11487
11846
|
toolbar: activeToolbar,
|
|
11488
|
-
zIndex
|
|
11847
|
+
zIndex,
|
|
11848
|
+
onImageButtonClick: imageFeatureEnabled ? () => fileInputRef.current?.click() : void 0
|
|
11489
11849
|
}
|
|
11490
11850
|
),
|
|
11491
|
-
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11851
|
+
imageFeatureEnabled && /* @__PURE__ */ jsxRuntime.jsx(
|
|
11852
|
+
"input",
|
|
11853
|
+
{
|
|
11854
|
+
ref: fileInputRef,
|
|
11855
|
+
type: "file",
|
|
11856
|
+
multiple: true,
|
|
11857
|
+
accept: buildAcceptAttribute(fileFormat),
|
|
11858
|
+
className: "hidden",
|
|
11859
|
+
onChange: (e) => {
|
|
11860
|
+
const files = Array.from(e.target.files ?? []);
|
|
11861
|
+
if (files.length > 0) processFiles(files);
|
|
11862
|
+
e.target.value = "";
|
|
11863
|
+
}
|
|
11864
|
+
}
|
|
11865
|
+
),
|
|
11866
|
+
imageFeatureEnabled ? /* @__PURE__ */ jsxRuntime.jsxs(RichEditorDropZone, { className: "flex flex-1 flex-col", "data-rich-editor-theme": theme, children: [
|
|
11867
|
+
/* @__PURE__ */ jsxRuntime.jsx(
|
|
11868
|
+
RichEditorContent,
|
|
11869
|
+
{
|
|
11870
|
+
editor,
|
|
11871
|
+
className: cn("p-4", bodyClassName),
|
|
11872
|
+
minHeight,
|
|
11873
|
+
maxHeight
|
|
11874
|
+
}
|
|
11875
|
+
),
|
|
11876
|
+
isUploading && /* @__PURE__ */ jsxRuntime.jsx("div", { className: "pointer-events-none absolute inset-0 z-10 flex items-center justify-center", children: /* @__PURE__ */ jsxRuntime.jsx(Loading, { size: "lg" }) })
|
|
11877
|
+
] }) : /* @__PURE__ */ jsxRuntime.jsx(
|
|
11492
11878
|
RichEditorContent,
|
|
11493
11879
|
{
|
|
11494
11880
|
editor,
|
|
@@ -11496,6 +11882,14 @@ var RichEditor = React6.forwardRef(function RichEditor2({
|
|
|
11496
11882
|
minHeight,
|
|
11497
11883
|
maxHeight
|
|
11498
11884
|
}
|
|
11885
|
+
),
|
|
11886
|
+
imageFeatureEnabled && /* @__PURE__ */ jsxRuntime.jsx(
|
|
11887
|
+
RichEditorFileList,
|
|
11888
|
+
{
|
|
11889
|
+
attachments,
|
|
11890
|
+
onRemove: removeAttachment,
|
|
11891
|
+
renderFilePreview
|
|
11892
|
+
}
|
|
11499
11893
|
)
|
|
11500
11894
|
]
|
|
11501
11895
|
}
|