@team-monolith/cds 1.9.4 → 1.9.5
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/patterns/LexicalEditor/nodes/ProblemInputNode/InputComponent.js +1 -1
- package/dist/patterns/LexicalEditor/nodes/ProblemSelectNode/ProblemSelectNode.d.ts +4 -2
- package/dist/patterns/LexicalEditor/nodes/ProblemSelectNode/ProblemSelectNode.js +7 -5
- package/dist/patterns/LexicalEditor/nodes/ProblemSelectNode/SelectBox.d.ts +1 -1
- package/dist/patterns/LexicalEditor/nodes/ProblemSelectNode/SelectComponent.d.ts +1 -0
- package/dist/patterns/LexicalEditor/nodes/ProblemSelectNode/SelectComponent.js +54 -30
- package/package.json +1 -1
|
@@ -22,7 +22,7 @@ import useLexicalEditable from "@lexical/react/useLexicalEditable";
|
|
|
22
22
|
import { $isProblemInputNode } from "./ProblemInputNode";
|
|
23
23
|
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
24
24
|
import { $getNodeByKey } from "lexical";
|
|
25
|
-
import { LexicalCustomConfigContext
|
|
25
|
+
import { LexicalCustomConfigContext } from "../../LexicalCustomConfigContext";
|
|
26
26
|
export function InputComponent(props) {
|
|
27
27
|
const { answer } = props, settingFormProps = __rest(props, ["answer"]);
|
|
28
28
|
const { placeholder, nodeKey } = settingFormProps;
|
|
@@ -15,6 +15,7 @@ export interface Selection {
|
|
|
15
15
|
export interface ProblemSelectPayload {
|
|
16
16
|
selections: Selection[];
|
|
17
17
|
selected: string[];
|
|
18
|
+
hasMultipleAnswers?: boolean;
|
|
18
19
|
key?: NodeKey;
|
|
19
20
|
}
|
|
20
21
|
export type SerializedProblemSelectNode = Spread<ProblemSelectPayload, SerializedLexicalNode>;
|
|
@@ -25,6 +26,7 @@ export type SerializedProblemSelectNode = Spread<ProblemSelectPayload, Serialize
|
|
|
25
26
|
export declare class ProblemSelectNode extends DecoratorNode<ReactNode> {
|
|
26
27
|
__selections: Selection[];
|
|
27
28
|
__selected: string[];
|
|
29
|
+
__hasMultipleAnswers: boolean | undefined;
|
|
28
30
|
isInline(): boolean;
|
|
29
31
|
static getType(): string;
|
|
30
32
|
getSelections(): Selection[];
|
|
@@ -32,12 +34,12 @@ export declare class ProblemSelectNode extends DecoratorNode<ReactNode> {
|
|
|
32
34
|
setSolutions(selections: Selection[]): void;
|
|
33
35
|
setSelected(selected: string[]): void;
|
|
34
36
|
static clone(node: ProblemSelectNode): ProblemSelectNode;
|
|
35
|
-
constructor(selections: Selection[], selected: string[], key?: NodeKey);
|
|
37
|
+
constructor(selections: Selection[], selected: string[], hasMultipleAnswers?: boolean, key?: NodeKey);
|
|
36
38
|
createDOM(config: EditorConfig): HTMLElement;
|
|
37
39
|
updateDOM(): boolean;
|
|
38
40
|
static importJSON(serializedNode: SerializedProblemSelectNode): ProblemSelectNode;
|
|
39
41
|
exportJSON(): SerializedProblemSelectNode;
|
|
40
42
|
decorate(): ReactNode;
|
|
41
43
|
}
|
|
42
|
-
export declare function $createProblemSelectNode({ selections, selected, key, }: ProblemSelectPayload): ProblemSelectNode;
|
|
44
|
+
export declare function $createProblemSelectNode({ selections, selected, hasMultipleAnswers, key, }: ProblemSelectPayload): ProblemSelectNode;
|
|
43
45
|
export declare function $isProblemSelectNode(node: LexicalNode | null | undefined): node is ProblemSelectNode;
|
|
@@ -28,12 +28,13 @@ export class ProblemSelectNode extends DecoratorNode {
|
|
|
28
28
|
self.__selected = selected;
|
|
29
29
|
}
|
|
30
30
|
static clone(node) {
|
|
31
|
-
return new ProblemSelectNode(node.__selections, node.__selected, node.__key);
|
|
31
|
+
return new ProblemSelectNode(node.__selections, node.__selected, node.__hasMultipleAnswers, node.__key);
|
|
32
32
|
}
|
|
33
|
-
constructor(selections, selected, key) {
|
|
33
|
+
constructor(selections, selected, hasMultipleAnswers, key) {
|
|
34
34
|
super(key);
|
|
35
35
|
this.__selections = selections;
|
|
36
36
|
this.__selected = selected;
|
|
37
|
+
this.__hasMultipleAnswers = hasMultipleAnswers;
|
|
37
38
|
}
|
|
38
39
|
createDOM(config) {
|
|
39
40
|
// Define the DOM element here
|
|
@@ -49,6 +50,7 @@ export class ProblemSelectNode extends DecoratorNode {
|
|
|
49
50
|
key: serializedNode.key,
|
|
50
51
|
selections: serializedNode.selections,
|
|
51
52
|
selected: serializedNode.selected,
|
|
53
|
+
hasMultipleAnswers: serializedNode.hasMultipleAnswers,
|
|
52
54
|
});
|
|
53
55
|
return node;
|
|
54
56
|
}
|
|
@@ -61,11 +63,11 @@ export class ProblemSelectNode extends DecoratorNode {
|
|
|
61
63
|
};
|
|
62
64
|
}
|
|
63
65
|
decorate() {
|
|
64
|
-
return (_jsx(SelectComponent, { selections: this.__selections, selected: this.__selected, nodeKey: this.getKey() }));
|
|
66
|
+
return (_jsx(SelectComponent, { selections: this.__selections, selected: this.__selected, hasMultipleAnswers: this.__hasMultipleAnswers, nodeKey: this.getKey() }));
|
|
65
67
|
}
|
|
66
68
|
}
|
|
67
|
-
export function $createProblemSelectNode({ selections, selected, key, }) {
|
|
68
|
-
return $applyNodeReplacement(new ProblemSelectNode(selections, selected, key));
|
|
69
|
+
export function $createProblemSelectNode({ selections, selected, hasMultipleAnswers, key, }) {
|
|
70
|
+
return $applyNodeReplacement(new ProblemSelectNode(selections, selected, hasMultipleAnswers, key));
|
|
69
71
|
}
|
|
70
72
|
export function $isProblemSelectNode(node) {
|
|
71
73
|
return node instanceof ProblemSelectNode;
|
|
@@ -5,7 +5,7 @@ export interface SelectBoxProps {
|
|
|
5
5
|
isAnswer?: boolean;
|
|
6
6
|
image?: ImageProps;
|
|
7
7
|
text: string;
|
|
8
|
-
onClick
|
|
8
|
+
onClick?: () => void;
|
|
9
9
|
fullWidth?: boolean;
|
|
10
10
|
}
|
|
11
11
|
export default function SelectBox(props: SelectBoxProps): import("@emotion/react/jsx-runtime").JSX.Element;
|
|
@@ -1,18 +1,20 @@
|
|
|
1
|
-
import { jsx as _jsx,
|
|
1
|
+
import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "@emotion/react/jsx-runtime";
|
|
2
2
|
/** @jsxImportSource @emotion/react */
|
|
3
3
|
import { $getNodeByKey } from "lexical";
|
|
4
4
|
import { $isProblemSelectNode, } from "./ProblemSelectNode";
|
|
5
5
|
import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
|
|
6
|
-
import { useState } from "react";
|
|
6
|
+
import { useContext, useState } from "react";
|
|
7
7
|
import useLexicalEditable from "@lexical/react/useLexicalEditable";
|
|
8
8
|
import { useFieldArray, useForm } from "react-hook-form";
|
|
9
9
|
import SelectBox from "./SelectBox";
|
|
10
10
|
import { css } from "@emotion/react";
|
|
11
11
|
import SquareButton from "../../../../components/SquareButton";
|
|
12
|
-
import { Settings3FillIcon } from "../../../../icons";
|
|
12
|
+
import { AlarmWarningFillIcon, Settings3FillIcon } from "../../../../icons";
|
|
13
13
|
import SettingForm from "./SettingForm";
|
|
14
|
+
import styled from "@emotion/styled";
|
|
15
|
+
import { LexicalCustomConfigContext } from "../../LexicalCustomConfigContext";
|
|
14
16
|
export function SelectComponent(props) {
|
|
15
|
-
const { selections, selected, nodeKey } = props;
|
|
17
|
+
const { selections, selected, hasMultipleAnswers, nodeKey } = props;
|
|
16
18
|
const [editor] = useLexicalComposerContext();
|
|
17
19
|
const [settingOpen, setSettingOpen] = useState(false);
|
|
18
20
|
const isEditable = useLexicalEditable();
|
|
@@ -28,34 +30,44 @@ export function SelectComponent(props) {
|
|
|
28
30
|
name: "selections",
|
|
29
31
|
keyName: "uid",
|
|
30
32
|
});
|
|
33
|
+
const lexicalCustomConfig = useContext(LexicalCustomConfigContext);
|
|
31
34
|
// 학생 view
|
|
32
35
|
if (!isEditable) {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
36
|
+
if (lexicalCustomConfig.freezeProblemNode) {
|
|
37
|
+
return (_jsxs(_Fragment, { children: [hasMultipleAnswers && (_jsxs(Alert, { children: [_jsx(AlarmWarningFillIcon, { css: css `
|
|
38
|
+
width: 14px;
|
|
39
|
+
height: 14px;
|
|
40
|
+
` }), "\uC9C8\uBB38\uC5D0 \uD574\uB2F9\uD558\uB294 \uB2F5\uC744 \uBAA8\uB450 \uACE0\uB974\uB294 \uBB38\uC81C\uC785\uB2C8\uB2E4."] })), fields.map((field, index) => (_jsx(SelectBox, { index: index + 1, isSelected: selected.includes(field.value), image: field.show.image, text: field.show.text, fullWidth: true }, index)))] }));
|
|
41
|
+
}
|
|
42
|
+
return (_jsxs(_Fragment, { children: [hasMultipleAnswers && (_jsxs(Alert, { children: [_jsx(AlarmWarningFillIcon, { css: css `
|
|
43
|
+
width: 14px;
|
|
44
|
+
height: 14px;
|
|
45
|
+
` }), "\uC9C8\uBB38\uC5D0 \uD574\uB2F9\uD558\uB294 \uB2F5\uC744 \uBAA8\uB450 \uACE0\uB974\uB294 \uBB38\uC81C\uC785\uB2C8\uB2E4."] })), fields.map((field, index) => (_jsx(SelectBox, { index: index + 1, isSelected: selected.includes(field.value), image: field.show.image, text: field.show.text, onClick: () => {
|
|
46
|
+
const isSelected = selected.includes(field.value);
|
|
47
|
+
if (isSelected) {
|
|
48
|
+
editor.update(() => {
|
|
49
|
+
const node = $getNodeByKey(nodeKey);
|
|
50
|
+
if (!$isProblemSelectNode(node)) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
const newSelected = [...selected];
|
|
54
|
+
const index = newSelected.indexOf(field.value);
|
|
55
|
+
newSelected.splice(index, 1);
|
|
56
|
+
node.setSelected(newSelected);
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
editor.update(() => {
|
|
61
|
+
const node = $getNodeByKey(nodeKey);
|
|
62
|
+
if (!$isProblemSelectNode(node)) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const newSelected = [...selected];
|
|
66
|
+
newSelected.push(field.value);
|
|
67
|
+
node.setSelected(newSelected);
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
}, fullWidth: true }, index)))] }));
|
|
59
71
|
}
|
|
60
72
|
// 교사 edit view
|
|
61
73
|
return (_jsxs(_Fragment, { children: [_jsxs("div", Object.assign({ css: css `
|
|
@@ -69,3 +81,15 @@ export function SelectComponent(props) {
|
|
|
69
81
|
setSettingOpen(true);
|
|
70
82
|
} })] })), settingOpen && (_jsx(SettingForm, { control: control, handleSubmit: handleSubmit, fields: fields, append: append, remove: remove, update: update, nodeKey: nodeKey, onClose: () => setSettingOpen(false) }))] }));
|
|
71
83
|
}
|
|
84
|
+
const Alert = styled.div(({ theme }) => css `
|
|
85
|
+
display: flex;
|
|
86
|
+
gap: 4px;
|
|
87
|
+
margin-bottom: 12px;
|
|
88
|
+
color: ${theme.color.foreground.neutralBaseDisabled};
|
|
89
|
+
/* Default/Label/12px-Md */
|
|
90
|
+
font-family: ${theme.fontFamily.ui};
|
|
91
|
+
font-size: 12px;
|
|
92
|
+
font-style: normal;
|
|
93
|
+
font-weight: 500;
|
|
94
|
+
line-height: 16px; /* 133.333% */
|
|
95
|
+
`);
|