@team-monolith/cds 1.8.0 → 1.8.2

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,4 +1,5 @@
1
- import { NodeKey, SerializedLexicalNode } from "lexical";
1
+ import { NodeKey, SerializedLexicalNode, Spread } from "lexical";
2
+ import { ProblemInputNode } from "./ProblemInputNode";
2
3
  export interface Answer {
3
4
  textType: "normal" | "code";
4
5
  value: string;
@@ -10,7 +11,7 @@ export interface ProblemInputPayload {
10
11
  showCharacterCount: boolean;
11
12
  placeholder: string;
12
13
  }
13
- export type SerializedProblemInputNode = SerializedLexicalNode & ProblemInputPayload;
14
+ export type SerializedProblemInputNode = Spread<ProblemInputPayload, SerializedLexicalNode>;
14
15
  export declare function InputComponent(props: {
15
- data: ProblemInputPayload;
16
+ node: ProblemInputNode;
16
17
  }): import("@emotion/react/jsx-runtime").JSX.Element;
@@ -1,7 +1,6 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
2
2
  /** @jsxImportSource @emotion/react */
3
3
  import { css, useTheme } from "@emotion/react";
4
- import { $getSelection } from "lexical";
5
4
  import { Suspense, useState } from "react";
6
5
  import { useForm, useFieldArray } from "react-hook-form";
7
6
  import Input from "../../../../components/Input";
@@ -14,15 +13,16 @@ import Tooltip from "../../../../components/Tooltip";
14
13
  import { FormAnswer, FormCharacterCount, FormPlaceholder } from "./Form";
15
14
  import useLexicalEditable from "@lexical/react/useLexicalEditable";
16
15
  import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
17
- import { $createProblemInputNode } from "./ProblemInputNode";
18
16
  export function InputComponent(props) {
19
17
  var _a;
20
18
  const theme = useTheme();
21
- const { data } = props;
22
- const { answers, showCharacterCount, placeholder } = data;
19
+ const { node } = props;
20
+ const [editor] = useLexicalComposerContext();
21
+ const answers = node.getAnswers();
22
+ const showCharacterCount = node.getShowCharacterCount();
23
+ const placeholder = node.getPlaceholder();
23
24
  const [settingOpen, setSettingOpen] = useState(false);
24
25
  const [multiAnswerDisabled, setMultiAnswerDisabled] = useState(showCharacterCount);
25
- const [editor] = useLexicalComposerContext();
26
26
  const isEditable = useLexicalEditable();
27
27
  const { control, handleSubmit, getValues } = useForm({
28
28
  defaultValues: {
@@ -39,10 +39,9 @@ export function InputComponent(props) {
39
39
  });
40
40
  const onSettingSubmit = (data) => {
41
41
  editor.update(() => {
42
- var _a;
43
- const newNode = $createProblemInputNode(Object.assign({}, data));
44
- const currentNode = (_a = $getSelection()) === null || _a === void 0 ? void 0 : _a.getNodes()[0];
45
- currentNode === null || currentNode === void 0 ? void 0 : currentNode.replace(newNode);
42
+ node.setAnswers(data.answers);
43
+ node.setShowCharacterCount(data.showCharacterCount);
44
+ node.setPlaceholder(data.placeholder);
46
45
  });
47
46
  setSettingOpen(false);
48
47
  };
@@ -6,7 +6,12 @@ export declare class ProblemInputNode extends DecoratorNode<ReactNode> {
6
6
  __showCharacterCount: boolean;
7
7
  __placeholder: string;
8
8
  static getType(): string;
9
- get data(): ProblemInputPayload;
9
+ getAnswers(): Answer[];
10
+ getShowCharacterCount(): boolean;
11
+ getPlaceholder(): string;
12
+ setAnswers(answers: Answer[]): void;
13
+ setShowCharacterCount(showCharacterCount: boolean): void;
14
+ setPlaceholder(placeholder: string): void;
10
15
  static clone(node: ProblemInputNode): ProblemInputNode;
11
16
  constructor(answers: Answer[], showCharacterCount: boolean, placeholder: string, key?: NodeKey);
12
17
  createDOM(config: EditorConfig): HTMLElement;
@@ -6,14 +6,26 @@ export class ProblemInputNode extends DecoratorNode {
6
6
  static getType() {
7
7
  return "problem-input";
8
8
  }
9
- get data() {
10
- //fixme: 필요할 때 수정
11
- //const self = this.getLatest();
12
- return {
13
- answers: this.__answers,
14
- showCharacterCount: this.__showCharacterCount,
15
- placeholder: this.__placeholder,
16
- };
9
+ getAnswers() {
10
+ return this.__answers;
11
+ }
12
+ getShowCharacterCount() {
13
+ return this.__showCharacterCount;
14
+ }
15
+ getPlaceholder() {
16
+ return this.__placeholder;
17
+ }
18
+ setAnswers(answers) {
19
+ const self = this.getWritable();
20
+ self.__answers = answers;
21
+ }
22
+ setShowCharacterCount(showCharacterCount) {
23
+ const self = this.getWritable();
24
+ self.__showCharacterCount = showCharacterCount;
25
+ }
26
+ setPlaceholder(placeholder) {
27
+ const self = this.getWritable();
28
+ self.__placeholder = placeholder;
17
29
  }
18
30
  static clone(node) {
19
31
  return $createProblemInputNode({
@@ -56,8 +68,11 @@ export class ProblemInputNode extends DecoratorNode {
56
68
  placeholder: this.__placeholder,
57
69
  };
58
70
  }
71
+ // TODO: 이 노드의 selected가 제대로 동작하지 않습니다.
72
+ // nodeKey를 전달하고 getNodeByKey로 노드를 찾는 것이 일반적이나
73
+ // 현재 이 노드가 selected가 제대로 동작하지 않아서 노드를 직접 전달했습니다.
59
74
  decorate() {
60
- return _jsx(InputComponent, { data: this.data });
75
+ return _jsx(InputComponent, { node: this });
61
76
  }
62
77
  }
63
78
  export function $createProblemInputNode({ key, answers, showCharacterCount, placeholder, }) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@team-monolith/cds",
3
- "version": "1.8.0",
3
+ "version": "1.8.2",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "sideEffects": false,