@team-monolith/cds 1.8.3 → 1.8.4

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.
@@ -1,5 +1,5 @@
1
1
  import { Control } from "react-hook-form";
2
- import { ProblemInputPayload } from "../InputComponent";
2
+ import { ProblemInputPayload } from "../ProblemInputNode";
3
3
  export interface FormAnswerProps {
4
4
  index: number;
5
5
  control: Control<ProblemInputPayload, any>;
@@ -1,6 +1,6 @@
1
1
  import { Control } from "react-hook-form";
2
- import { ProblemInputPayload } from "../InputComponent";
3
2
  import React from "react";
3
+ import { ProblemInputPayload } from "../ProblemInputNode";
4
4
  export interface FormCharacterCountProps {
5
5
  control: Control<ProblemInputPayload, any>;
6
6
  setMultiAnswerDisabled: React.Dispatch<React.SetStateAction<boolean>>;
@@ -1,5 +1,5 @@
1
1
  import { Control } from "react-hook-form";
2
- import { ProblemInputPayload } from "../InputComponent";
2
+ import { ProblemInputPayload } from "../ProblemInputNode";
3
3
  export interface FormPlaceholderProps {
4
4
  control: Control<ProblemInputPayload, any>;
5
5
  }
@@ -1,17 +1,4 @@
1
- import { NodeKey, SerializedLexicalNode, Spread } from "lexical";
2
1
  import { ProblemInputNode } from "./ProblemInputNode";
3
- export interface Answer {
4
- textType: "normal" | "code";
5
- value: string;
6
- destroyed?: boolean;
7
- }
8
- export interface ProblemInputPayload {
9
- key?: NodeKey;
10
- answers: Answer[];
11
- showCharacterCount: boolean;
12
- placeholder: string;
13
- }
14
- export type SerializedProblemInputNode = Spread<ProblemInputPayload, SerializedLexicalNode>;
15
2
  export declare function InputComponent(props: {
16
3
  node: ProblemInputNode;
17
4
  }): import("@emotion/react/jsx-runtime").JSX.Element;
@@ -14,24 +14,23 @@ import { FormAnswer, FormCharacterCount, FormPlaceholder } from "./Form";
14
14
  import useLexicalEditable from "@lexical/react/useLexicalEditable";
15
15
  import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
16
16
  export function InputComponent(props) {
17
- var _a;
18
17
  const theme = useTheme();
19
18
  const { node } = props;
20
19
  const [editor] = useLexicalComposerContext();
21
20
  const answers = node.getAnswers();
22
21
  const showCharacterCount = node.getShowCharacterCount();
23
22
  const placeholder = node.getPlaceholder();
23
+ const response = node.getResponse();
24
24
  const [settingOpen, setSettingOpen] = useState(false);
25
25
  const [multiAnswerDisabled, setMultiAnswerDisabled] = useState(showCharacterCount);
26
26
  const isEditable = useLexicalEditable();
27
27
  const { control, handleSubmit, getValues } = useForm({
28
28
  defaultValues: {
29
- answers,
29
+ answers: answers !== null && answers !== void 0 ? answers : [],
30
30
  showCharacterCount,
31
31
  placeholder,
32
32
  },
33
33
  });
34
- // TODO: 읽기전용 모드(학생 view)에서 문제 제출 api를 추가해야 합니다.
35
34
  const { fields, append, remove, update } = useFieldArray({
36
35
  control,
37
36
  name: "answers",
@@ -45,20 +44,24 @@ export function InputComponent(props) {
45
44
  });
46
45
  setSettingOpen(false);
47
46
  };
48
- // TODO: 읽기전용 모드(학생 view)에서 문제 제출 api를 추가 후 수정해야 합니다.
49
- const [answerInput, setAnswerInput] = useState("");
47
+ // 학생 view
50
48
  if (!isEditable) {
51
- return (_jsx(Input, { size: "small", placeholder: (_a = getValues("placeholder")) !== null && _a !== void 0 ? _a : "주관식 입력 칸", value: answerInput, onChange: (e) => {
52
- setAnswerInput(e.target.value);
49
+ return (_jsx(Input, { size: "small", placeholder: getValues("placeholder") || "여기에 입력하세요.", value: response, onChange: (e) => {
50
+ editor.update(() => {
51
+ node.setResponse(e.target.value);
52
+ });
53
53
  }, color: "default", css: css `
54
54
  width: 300px;
55
55
  ` }));
56
56
  }
57
+ // 교사 edit view
57
58
  return (_jsxs(Suspense, Object.assign({ fallback: null }, { children: [_jsxs("div", Object.assign({ css: css `
58
59
  display: flex;
59
60
  align-items: center;
60
61
  gap: 4px;
61
- ` }, { children: [_jsx(Input, { size: "small", placeholder: "주관식 입력 칸", defaultValue: "", color: "default", css: css `
62
+ ` }, { children: [_jsx(Input, { size: "small", placeholder: "주관식 입력 칸", value: "", onChange: () => {
63
+ // 수정모드에서는 입력칸 수정을 허용하지 않습니다.
64
+ }, color: "default", css: css `
62
65
  width: 300px;
63
66
  ` }), _jsx(SquareButton, { size: "small", color: "icon", icon: _jsx(Settings3FillIcon, {}), onClick: () => {
64
67
  setSettingOpen(true);
@@ -1,24 +1,43 @@
1
- import { DecoratorNode, EditorConfig, LexicalNode, NodeKey } from "lexical";
1
+ import { DecoratorNode, EditorConfig, LexicalNode, NodeKey, SerializedLexicalNode, Spread } from "lexical";
2
2
  import { ReactNode } from "react";
3
- import { Answer, ProblemInputPayload, SerializedProblemInputNode } from "./InputComponent";
3
+ export interface Answer {
4
+ textType: "normal" | "code";
5
+ value: string;
6
+ destroyed?: boolean;
7
+ }
8
+ export interface ProblemInputPayload {
9
+ showCharacterCount: boolean;
10
+ placeholder: string;
11
+ answers: Answer[];
12
+ response: string;
13
+ key?: NodeKey;
14
+ }
15
+ export type SerializedProblemInputNode = Spread<ProblemInputPayload, SerializedLexicalNode>;
16
+ /**
17
+ * answers는 Answer타입의 배열로서 정답을 담고 있습니다. (교사용)
18
+ * response는 학생이 입력한 답을 담고 있습니다.(학생용)
19
+ */
4
20
  export declare class ProblemInputNode extends DecoratorNode<ReactNode> {
5
21
  __answers: Answer[];
6
22
  __showCharacterCount: boolean;
7
23
  __placeholder: string;
24
+ __response: string;
8
25
  static getType(): string;
9
26
  getAnswers(): Answer[];
10
27
  getShowCharacterCount(): boolean;
11
28
  getPlaceholder(): string;
29
+ getResponse(): string;
12
30
  setAnswers(answers: Answer[]): void;
13
31
  setShowCharacterCount(showCharacterCount: boolean): void;
14
32
  setPlaceholder(placeholder: string): void;
33
+ setResponse(response: string): void;
15
34
  static clone(node: ProblemInputNode): ProblemInputNode;
16
- constructor(answers: Answer[], showCharacterCount: boolean, placeholder: string, key?: NodeKey);
35
+ constructor(showCharacterCount: boolean, placeholder: string, answers: Answer[], response: string, key?: NodeKey);
17
36
  createDOM(config: EditorConfig): HTMLElement;
18
37
  updateDOM(): boolean;
19
38
  static importJSON(serializedNode: SerializedProblemInputNode): ProblemInputNode;
20
39
  exportJSON(): SerializedProblemInputNode;
21
40
  decorate(): ReactNode;
22
41
  }
23
- export declare function $createProblemInputNode({ key, answers, showCharacterCount, placeholder, }: ProblemInputPayload): ProblemInputNode;
42
+ export declare function $createProblemInputNode({ showCharacterCount, placeholder, answers, response, key, }: ProblemInputPayload): ProblemInputNode;
24
43
  export declare function $isProblemInputNode(node: LexicalNode | null | undefined): node is ProblemInputNode;
@@ -1,7 +1,11 @@
1
1
  import { jsx as _jsx } from "react/jsx-runtime";
2
2
  import { $applyNodeReplacement, DecoratorNode, } from "lexical";
3
3
  import { addClassNamesToElement } from "@lexical/utils";
4
- import { InputComponent, } from "./InputComponent";
4
+ import { InputComponent } from "./InputComponent";
5
+ /**
6
+ * answers는 Answer타입의 배열로서 정답을 담고 있습니다. (교사용)
7
+ * response는 학생이 입력한 답을 담고 있습니다.(학생용)
8
+ */
5
9
  export class ProblemInputNode extends DecoratorNode {
6
10
  static getType() {
7
11
  return "problem-input";
@@ -15,6 +19,9 @@ export class ProblemInputNode extends DecoratorNode {
15
19
  getPlaceholder() {
16
20
  return this.__placeholder;
17
21
  }
22
+ getResponse() {
23
+ return this.__response;
24
+ }
18
25
  setAnswers(answers) {
19
26
  const self = this.getWritable();
20
27
  self.__answers = answers;
@@ -27,19 +34,25 @@ export class ProblemInputNode extends DecoratorNode {
27
34
  const self = this.getWritable();
28
35
  self.__placeholder = placeholder;
29
36
  }
37
+ setResponse(response) {
38
+ const self = this.getWritable();
39
+ self.__response = response;
40
+ }
30
41
  static clone(node) {
31
42
  return $createProblemInputNode({
32
- key: node.__key,
33
- answers: node.__answers,
34
43
  showCharacterCount: node.__showCharacterCount,
35
44
  placeholder: node.__placeholder,
45
+ answers: node.__answers,
46
+ response: node.__response,
47
+ key: node.__key,
36
48
  });
37
49
  }
38
- constructor(answers, showCharacterCount, placeholder, key) {
50
+ constructor(showCharacterCount, placeholder, answers, response, key) {
39
51
  super(key);
40
52
  this.__answers = answers;
41
53
  this.__showCharacterCount = showCharacterCount;
42
54
  this.__placeholder = placeholder;
55
+ this.__response = response;
43
56
  }
44
57
  createDOM(config) {
45
58
  // Define the DOM element here
@@ -56,6 +69,7 @@ export class ProblemInputNode extends DecoratorNode {
56
69
  answers: serializedNode.answers,
57
70
  showCharacterCount: serializedNode.showCharacterCount,
58
71
  placeholder: serializedNode.placeholder,
72
+ response: serializedNode.response,
59
73
  });
60
74
  return node;
61
75
  }
@@ -63,9 +77,10 @@ export class ProblemInputNode extends DecoratorNode {
63
77
  return {
64
78
  version: 1,
65
79
  type: "problem-input",
66
- answers: this.__answers,
67
80
  showCharacterCount: this.__showCharacterCount,
68
81
  placeholder: this.__placeholder,
82
+ answers: this.__answers,
83
+ response: this.__response,
69
84
  };
70
85
  }
71
86
  // TODO: 이 노드의 selected가 제대로 동작하지 않습니다.
@@ -75,8 +90,8 @@ export class ProblemInputNode extends DecoratorNode {
75
90
  return _jsx(InputComponent, { node: this });
76
91
  }
77
92
  }
78
- export function $createProblemInputNode({ key, answers, showCharacterCount, placeholder, }) {
79
- return $applyNodeReplacement(new ProblemInputNode(answers, showCharacterCount, placeholder, key));
93
+ export function $createProblemInputNode({ showCharacterCount, placeholder, answers, response, key, }) {
94
+ return $applyNodeReplacement(new ProblemInputNode(showCharacterCount, placeholder, answers, response, key));
80
95
  }
81
96
  export function $isProblemInputNode(node) {
82
97
  return node instanceof ProblemInputNode;
@@ -79,6 +79,7 @@ function getQuizContextOptions(editor, theme) {
79
79
  ],
80
80
  showCharacterCount: false,
81
81
  placeholder: "",
82
+ response: "",
82
83
  }),
83
84
  }),
84
85
  new ComponentPickerOption("객관식 입력 칸", {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@team-monolith/cds",
3
- "version": "1.8.3",
3
+ "version": "1.8.4",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "sideEffects": false,