@team-monolith/cds 1.86.2 → 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.
|
@@ -34,6 +34,7 @@ import { SheetSelectPlugin } from "./plugins/SheetSelectPlugin";
|
|
|
34
34
|
import { SheetInputPlugin } from "./plugins/SheetInputPlugin";
|
|
35
35
|
import { SelfEvaluationPlugin } from "./plugins/SelfEvaluationPlugin";
|
|
36
36
|
import { FilePlugin } from "./plugins/FilePlugin";
|
|
37
|
+
import { DragDropPastePlugin } from "./plugins/DragDropPastePlugin";
|
|
37
38
|
export function Plugins(props) {
|
|
38
39
|
const { className, contentEditableClassName, onChange, isSheetEnabled, isQuizEnabled, showFileUpload, } = props;
|
|
39
40
|
const isEditable = useLexicalEditable();
|
|
@@ -44,7 +45,7 @@ export function Plugins(props) {
|
|
|
44
45
|
setFloatingAnchorElem(_floatingAnchorElem);
|
|
45
46
|
}
|
|
46
47
|
};
|
|
47
|
-
return (_jsxs(_Fragment, { children: [_jsx(RichTextPlugin, { contentEditable: _jsx(ScrollArea, Object.assign({ className: className }, { children: _jsx(FloatingAnchor, Object.assign({ ref: onRef }, { children: _jsx(StyledContentEditable, { className: contentEditableClassName, isEditable: isEditable }) })) })), placeholder: null, ErrorBoundary: LexicalErrorBoundary }), _jsx(OnChangePlugin, { onChange: (editorState) => {
|
|
48
|
+
return (_jsxs(_Fragment, { children: [_jsx(DragDropPastePlugin, {}), _jsx(RichTextPlugin, { contentEditable: _jsx(ScrollArea, Object.assign({ className: className }, { children: _jsx(FloatingAnchor, Object.assign({ ref: onRef }, { children: _jsx(StyledContentEditable, { className: contentEditableClassName, isEditable: isEditable }) })) })), placeholder: null, ErrorBoundary: LexicalErrorBoundary }), _jsx(OnChangePlugin, { onChange: (editorState) => {
|
|
48
49
|
onChange === null || onChange === void 0 ? void 0 : onChange(editorState.toJSON());
|
|
49
50
|
},
|
|
50
51
|
// ignore 하지 않으면 Form에서 수정하지 않았는데 Dirty로 처리됨.
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
/**
|
|
9
|
+
* 이미지/파일을 붙여넣기를 시도하면 이미지/파일을 업로드하고 이미지/파일 노드를 삽입합니다.
|
|
10
|
+
* https://github.com/facebook/lexical/blob/main/packages/lexical-playground/src/plugins/DragDropPastePlugin/index.ts
|
|
11
|
+
*/
|
|
12
|
+
export declare function DragDropPastePlugin(): null;
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
|
3
|
+
*
|
|
4
|
+
* This source code is licensed under the MIT license found in the
|
|
5
|
+
* LICENSE file in the root directory of this source tree.
|
|
6
|
+
*
|
|
7
|
+
*/
|
|
8
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
9
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
10
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
11
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
12
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
13
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
14
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
18
|
+
import { DRAG_DROP_PASTE } from "@lexical/rich-text";
|
|
19
|
+
import { isMimeType, mediaFileReader } from "@lexical/utils";
|
|
20
|
+
import { COMMAND_PRIORITY_LOW } from "lexical";
|
|
21
|
+
import { useContext, useEffect } from "react";
|
|
22
|
+
import { INSERT_IMAGE_COMMAND } from "../ImagesPlugin";
|
|
23
|
+
import { CdsContext } from "../../../../CdsProvider";
|
|
24
|
+
import { UPLOAD_FILE_COMMAND } from "../FilePlugin";
|
|
25
|
+
import moment from "moment";
|
|
26
|
+
const ACCEPTABLE_IMAGE_TYPES = [
|
|
27
|
+
"image/",
|
|
28
|
+
"image/heic",
|
|
29
|
+
"image/heif",
|
|
30
|
+
"image/gif",
|
|
31
|
+
"image/webp",
|
|
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
|
+
*/
|
|
38
|
+
export function DragDropPastePlugin() {
|
|
39
|
+
var _a, _b;
|
|
40
|
+
const [editor] = useLexicalComposerContext();
|
|
41
|
+
const cdsContext = useContext(CdsContext);
|
|
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;
|
|
44
|
+
// eslint-disable-next-line arrow-body-style
|
|
45
|
+
useEffect(() => {
|
|
46
|
+
return editor.registerCommand(DRAG_DROP_PASTE, (files) => {
|
|
47
|
+
(() => __awaiter(this, void 0, void 0, function* () {
|
|
48
|
+
if (!uploadByFile) {
|
|
49
|
+
return false;
|
|
50
|
+
}
|
|
51
|
+
const filesResult = yield mediaFileReader(files, [""]);
|
|
52
|
+
for (const { file } of filesResult) {
|
|
53
|
+
if (isMimeType(file, ACCEPTABLE_IMAGE_TYPES)) {
|
|
54
|
+
const result = yield uploadByFile(file);
|
|
55
|
+
editor.dispatchCommand(INSERT_IMAGE_COMMAND, {
|
|
56
|
+
altText: file.name,
|
|
57
|
+
src: result,
|
|
58
|
+
});
|
|
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
|
+
}
|
|
74
|
+
}
|
|
75
|
+
}))();
|
|
76
|
+
return true;
|
|
77
|
+
}, COMMAND_PRIORITY_LOW);
|
|
78
|
+
}, [editor, showFileError, uploadByFile]);
|
|
79
|
+
return null;
|
|
80
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@team-monolith/cds",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.87.1",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"types": "dist/index.d.ts",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -17,14 +17,14 @@
|
|
|
17
17
|
"hex-to-css-filter": "^5.4.0",
|
|
18
18
|
"lexical": "^0.17.1",
|
|
19
19
|
"lodash": "^4.17.21",
|
|
20
|
+
"moment": "^2.30.1",
|
|
20
21
|
"react": "^18.2.0",
|
|
21
22
|
"react-dom": "^18.2.0",
|
|
22
23
|
"react-hook-form": "^7.48.2",
|
|
23
24
|
"remixicon": "^4.3.0",
|
|
24
25
|
"typescript": "^4.9.5",
|
|
25
26
|
"uid": "^2.0.2",
|
|
26
|
-
"usehooks-ts": "^2.9.1"
|
|
27
|
-
"moment": "^2.30.1"
|
|
27
|
+
"usehooks-ts": "^2.9.1"
|
|
28
28
|
},
|
|
29
29
|
"files": [
|
|
30
30
|
"dist/**/*",
|