@team-monolith/cds 1.87.0 → 1.87.1
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.
|
@@ -5,4 +5,8 @@
|
|
|
5
5
|
* LICENSE file in the root directory of this source tree.
|
|
6
6
|
*
|
|
7
7
|
*/
|
|
8
|
+
/**
|
|
9
|
+
* 이미지/파일을 붙여넣기를 시도하면 이미지/파일을 업로드하고 이미지/파일 노드를 삽입합니다.
|
|
10
|
+
* https://github.com/facebook/lexical/blob/main/packages/lexical-playground/src/plugins/DragDropPastePlugin/index.ts
|
|
11
|
+
*/
|
|
8
12
|
export declare function DragDropPastePlugin(): null;
|
|
@@ -21,6 +21,8 @@ import { COMMAND_PRIORITY_LOW } from "lexical";
|
|
|
21
21
|
import { useContext, useEffect } from "react";
|
|
22
22
|
import { INSERT_IMAGE_COMMAND } from "../ImagesPlugin";
|
|
23
23
|
import { CdsContext } from "../../../../CdsProvider";
|
|
24
|
+
import { UPLOAD_FILE_COMMAND } from "../FilePlugin";
|
|
25
|
+
import moment from "moment";
|
|
24
26
|
const ACCEPTABLE_IMAGE_TYPES = [
|
|
25
27
|
"image/",
|
|
26
28
|
"image/heic",
|
|
@@ -28,11 +30,17 @@ const ACCEPTABLE_IMAGE_TYPES = [
|
|
|
28
30
|
"image/gif",
|
|
29
31
|
"image/webp",
|
|
30
32
|
];
|
|
33
|
+
const MAX_FILE_SIZE = 1 * 1024 * 1024 * 1024; // 1GB
|
|
34
|
+
/**
|
|
35
|
+
* 이미지/파일을 붙여넣기를 시도하면 이미지/파일을 업로드하고 이미지/파일 노드를 삽입합니다.
|
|
36
|
+
* https://github.com/facebook/lexical/blob/main/packages/lexical-playground/src/plugins/DragDropPastePlugin/index.ts
|
|
37
|
+
*/
|
|
31
38
|
export function DragDropPastePlugin() {
|
|
32
|
-
var _a;
|
|
39
|
+
var _a, _b;
|
|
33
40
|
const [editor] = useLexicalComposerContext();
|
|
34
41
|
const cdsContext = useContext(CdsContext);
|
|
35
42
|
const uploadByFile = (_a = cdsContext.lexical) === null || _a === void 0 ? void 0 : _a.uploadByFile;
|
|
43
|
+
const showFileError = (_b = cdsContext.lexical) === null || _b === void 0 ? void 0 : _b.showFileError;
|
|
36
44
|
// eslint-disable-next-line arrow-body-style
|
|
37
45
|
useEffect(() => {
|
|
38
46
|
return editor.registerCommand(DRAG_DROP_PASTE, (files) => {
|
|
@@ -40,7 +48,7 @@ export function DragDropPastePlugin() {
|
|
|
40
48
|
if (!uploadByFile) {
|
|
41
49
|
return false;
|
|
42
50
|
}
|
|
43
|
-
const filesResult = yield mediaFileReader(files, [
|
|
51
|
+
const filesResult = yield mediaFileReader(files, [""]);
|
|
44
52
|
for (const { file } of filesResult) {
|
|
45
53
|
if (isMimeType(file, ACCEPTABLE_IMAGE_TYPES)) {
|
|
46
54
|
const result = yield uploadByFile(file);
|
|
@@ -49,10 +57,24 @@ export function DragDropPastePlugin() {
|
|
|
49
57
|
src: result,
|
|
50
58
|
});
|
|
51
59
|
}
|
|
60
|
+
else {
|
|
61
|
+
if (file.size >= MAX_FILE_SIZE) {
|
|
62
|
+
showFileError === null || showFileError === void 0 ? void 0 : showFileError("upload", "용량이 너무 큽니다. 1GB 이하의 파일을 선택해 주세요.");
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
const result = yield uploadByFile(file);
|
|
66
|
+
editor.dispatchCommand(UPLOAD_FILE_COMMAND, {
|
|
67
|
+
fileUrl: result,
|
|
68
|
+
fileName: file.name,
|
|
69
|
+
fileSize: file.size,
|
|
70
|
+
fileUploadDate: moment().format("YYYY.MM.DD HH:mm:ss"),
|
|
71
|
+
});
|
|
72
|
+
}
|
|
73
|
+
}
|
|
52
74
|
}
|
|
53
75
|
}))();
|
|
54
76
|
return true;
|
|
55
77
|
}, COMMAND_PRIORITY_LOW);
|
|
56
|
-
}, [editor, uploadByFile]);
|
|
78
|
+
}, [editor, showFileError, uploadByFile]);
|
|
57
79
|
return null;
|
|
58
80
|
}
|