@team-monolith/cds 1.86.2 → 1.87.0
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,58 @@
|
|
|
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
|
+
const ACCEPTABLE_IMAGE_TYPES = [
|
|
25
|
+
"image/",
|
|
26
|
+
"image/heic",
|
|
27
|
+
"image/heif",
|
|
28
|
+
"image/gif",
|
|
29
|
+
"image/webp",
|
|
30
|
+
];
|
|
31
|
+
export function DragDropPastePlugin() {
|
|
32
|
+
var _a;
|
|
33
|
+
const [editor] = useLexicalComposerContext();
|
|
34
|
+
const cdsContext = useContext(CdsContext);
|
|
35
|
+
const uploadByFile = (_a = cdsContext.lexical) === null || _a === void 0 ? void 0 : _a.uploadByFile;
|
|
36
|
+
// eslint-disable-next-line arrow-body-style
|
|
37
|
+
useEffect(() => {
|
|
38
|
+
return editor.registerCommand(DRAG_DROP_PASTE, (files) => {
|
|
39
|
+
(() => __awaiter(this, void 0, void 0, function* () {
|
|
40
|
+
if (!uploadByFile) {
|
|
41
|
+
return false;
|
|
42
|
+
}
|
|
43
|
+
const filesResult = yield mediaFileReader(files, [ACCEPTABLE_IMAGE_TYPES].flatMap((x) => x));
|
|
44
|
+
for (const { file } of filesResult) {
|
|
45
|
+
if (isMimeType(file, ACCEPTABLE_IMAGE_TYPES)) {
|
|
46
|
+
const result = yield uploadByFile(file);
|
|
47
|
+
editor.dispatchCommand(INSERT_IMAGE_COMMAND, {
|
|
48
|
+
altText: file.name,
|
|
49
|
+
src: result,
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}))();
|
|
54
|
+
return true;
|
|
55
|
+
}, COMMAND_PRIORITY_LOW);
|
|
56
|
+
}, [editor, uploadByFile]);
|
|
57
|
+
return null;
|
|
58
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@team-monolith/cds",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.87.0",
|
|
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/**/*",
|