@team-monolith/cds 1.9.7 → 1.9.9

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.
@@ -38,30 +38,19 @@ export function InputComponent(props) {
38
38
  return (_jsx(Input, { size: "small", placeholder: placeholder || "여기에 입력하세요.", value: answerInput, color: "default", fullWidth: true, inputProps: { readOnly: true } }));
39
39
  }
40
40
  else {
41
- return (_jsx(Input, { size: "small", placeholder: placeholder || "여기에 입력하세요.", value: answerInput, onChange: (e) => setAnswerInput(e.target.value),
42
- // 한글 입력시에 onChange마다 update가 일어나는 것을 방지하기 위해 입력 완료후 onBlur시에 update하는 전략을 사용합니다.
43
- // 이를 위해 answerInput을 state로 관리합니다.
44
- inputProps: {
45
- onBlur: (_e) => {
46
- editor.update(() => {
47
- const node = $getNodeByKey(nodeKey);
48
- if (!$isProblemInputNode(node)) {
49
- return;
50
- }
51
- node.setAnswer(answerInput);
52
- });
53
- },
54
- onKeyPress: (e) => {
55
- if (e.key === "Enter") {
56
- editor.update(() => {
57
- const node = $getNodeByKey(nodeKey);
58
- if (!$isProblemInputNode(node)) {
59
- return;
60
- }
61
- node.setAnswer(answerInput);
62
- });
41
+ return (_jsx(Input, { size: "small", placeholder: placeholder || "여기에 입력하세요.", value: answerInput, onChange: (e) => {
42
+ // SoT를 EditorState로 설정하는 경우 한글 입력시 문제가 생김.
43
+ // ex) "나비" 입력시 -> "ㄴ나납ㅂ비"
44
+ // SoT를 내부 State로 관리하고 EditorState를 따로 설정.
45
+ // 문제를 파악하고 추후 개선 필요.
46
+ setAnswerInput(e.target.value);
47
+ editor.update(() => {
48
+ const node = $getNodeByKey(nodeKey);
49
+ if (!$isProblemInputNode(node)) {
50
+ return;
63
51
  }
64
- },
52
+ node.setAnswer(e.target.value);
53
+ });
65
54
  }, color: "default", fullWidth: true }));
66
55
  }
67
56
  }
@@ -1,11 +1,21 @@
1
+ var __rest = (this && this.__rest) || function (s, e) {
2
+ var t = {};
3
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
4
+ t[p] = s[p];
5
+ if (s != null && typeof Object.getOwnPropertySymbols === "function")
6
+ for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
7
+ if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
8
+ t[p[i]] = s[p[i]];
9
+ }
10
+ return t;
11
+ };
1
12
  import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "@emotion/react/jsx-runtime";
2
13
  /** @jsxImportSource @emotion/react */
3
14
  import { $getNodeByKey } from "lexical";
4
- import { $isProblemSelectNode, } from "./ProblemSelectNode";
15
+ import { $isProblemSelectNode } from "./ProblemSelectNode";
5
16
  import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
6
17
  import { useContext, useState } from "react";
7
18
  import useLexicalEditable from "@lexical/react/useLexicalEditable";
8
- import { useFieldArray, useForm } from "react-hook-form";
9
19
  import SelectBox from "./SelectBox";
10
20
  import { css } from "@emotion/react";
11
21
  import SquareButton from "../../../../components/SquareButton";
@@ -14,36 +24,21 @@ import SettingForm from "./SettingForm";
14
24
  import styled from "@emotion/styled";
15
25
  import { LexicalCustomConfigContext } from "../../LexicalCustomConfigContext";
16
26
  export function SelectComponent(props) {
17
- const { selections, selected, hasMultipleAnswers, nodeKey } = props;
27
+ const { selected, hasMultipleAnswers } = props, settingFormProps = __rest(props, ["selected", "hasMultipleAnswers"]);
28
+ const { selections, nodeKey } = settingFormProps;
18
29
  const [editor] = useLexicalComposerContext();
19
30
  const [settingOpen, setSettingOpen] = useState(false);
20
31
  const isEditable = useLexicalEditable();
21
- const { control, handleSubmit } = useForm({
22
- mode: "all",
23
- defaultValues: {
24
- selections,
25
- selected,
26
- },
27
- });
28
- const { fields, append, remove, update } = useFieldArray({
29
- control,
30
- name: "selections",
31
- keyName: "uid",
32
- });
33
32
  const lexicalCustomConfig = useContext(LexicalCustomConfigContext);
34
33
  // 학생 view
35
34
  if (!isEditable) {
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
35
  return (_jsxs(_Fragment, { children: [hasMultipleAnswers && (_jsxs(Alert, { children: [_jsx(AlarmWarningFillIcon, { css: css `
43
36
  width: 14px;
44
37
  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);
38
+ ` }), "\uC9C8\uBB38\uC5D0 \uD574\uB2F9\uD558\uB294 \uB2F5\uC744 \uBAA8\uB450 \uACE0\uB974\uB294 \uBB38\uC81C\uC785\uB2C8\uB2E4."] })), selections.map((selection, index) => (_jsx(SelectBox, { index: index + 1, isSelected: selected.includes(selection.value), image: selection.show.image, text: selection.show.text, onClick: () => {
39
+ if (lexicalCustomConfig.freezeProblemNode)
40
+ return;
41
+ const isSelected = selected.includes(selection.value);
47
42
  if (isSelected) {
48
43
  editor.update(() => {
49
44
  const node = $getNodeByKey(nodeKey);
@@ -51,7 +46,7 @@ export function SelectComponent(props) {
51
46
  return;
52
47
  }
53
48
  const newSelected = [...selected];
54
- const index = newSelected.indexOf(field.value);
49
+ const index = newSelected.indexOf(selection.value);
55
50
  newSelected.splice(index, 1);
56
51
  node.setSelected(newSelected);
57
52
  });
@@ -63,7 +58,7 @@ export function SelectComponent(props) {
63
58
  return;
64
59
  }
65
60
  const newSelected = [...selected];
66
- newSelected.push(field.value);
61
+ newSelected.push(selection.value);
67
62
  node.setSelected(newSelected);
68
63
  });
69
64
  }
@@ -77,9 +72,9 @@ export function SelectComponent(props) {
77
72
  display: flex;
78
73
  flex-direction: column;
79
74
  gap: 4px;
80
- ` }, { children: fields.map((field, index) => (_jsx(SelectBox, { index: index + 1, isAnswer: field.isAnswer, image: field.show.image, text: field.show.text || `${index + 1}번 선택지`, onClick: () => setSettingOpen(true) }, index))) })), _jsx(SquareButton, { size: "small", color: "icon", icon: _jsx(Settings3FillIcon, {}), onClick: () => {
75
+ ` }, { children: selections.map((selection, index) => (_jsx(SelectBox, { index: index + 1, isAnswer: selection.isAnswer, image: selection.show.image, text: selection.show.text || `${index + 1}번 선택지`, onClick: () => setSettingOpen(true) }, index))) })), _jsx(SquareButton, { size: "small", color: "icon", icon: _jsx(Settings3FillIcon, {}), onClick: () => {
81
76
  setSettingOpen(true);
82
- } })] })), settingOpen && (_jsx(SettingForm, { control: control, handleSubmit: handleSubmit, fields: fields, append: append, remove: remove, update: update, nodeKey: nodeKey, onClose: () => setSettingOpen(false) }))] }));
77
+ } })] })), settingOpen && (_jsx(SettingForm, Object.assign({}, settingFormProps, { onClose: () => setSettingOpen(false) })))] }));
83
78
  }
84
79
  const Alert = styled.div(({ theme }) => css `
85
80
  display: flex;
@@ -1,10 +1,16 @@
1
- import { ProblemSelectPayload } from "../ProblemSelectNode";
1
+ import { Selection } from "../ProblemSelectNode";
2
2
  import { Control, FieldArrayWithId, UseFieldArrayUpdate } from "react-hook-form";
3
3
  export interface FormSelectionProps {
4
4
  index: number;
5
- control: Control<ProblemSelectPayload, any>;
6
- field: FieldArrayWithId<ProblemSelectPayload, "selections", "uid">;
7
- update: UseFieldArrayUpdate<ProblemSelectPayload, "selections">;
5
+ control: Control<{
6
+ selections: Selection[];
7
+ }, any>;
8
+ field: FieldArrayWithId<{
9
+ selections: Selection[];
10
+ }, "selections", "uid">;
11
+ update: UseFieldArrayUpdate<{
12
+ selections: Selection[];
13
+ }, "selections">;
8
14
  rules?: any;
9
15
  onDelete?: () => void;
10
16
  }
@@ -40,7 +40,6 @@ export function FormSelection(props) {
40
40
  },
41
41
  onBlur: (_e) => {
42
42
  setInputFocused(false);
43
- // onBlur시에 선택지 미리보기에 반영합니다.
44
43
  update(index, Object.assign(Object.assign({}, field), { show: Object.assign(Object.assign({}, field.show), { text: value }) }));
45
44
  },
46
45
  }, placeholder: `${index + 1}번 선택지`, hintIcon: invalid ? _jsx(ErrorWarningFillIcon, {}) : undefined, hintText: error === null || error === void 0 ? void 0 : error.message, multiline: true, fullWidth: true, css: css `
@@ -54,7 +53,6 @@ export function FormSelection(props) {
54
53
  setImageOpen(true);
55
54
  } }), _jsx(Controller, { name: `selections.${index}.isAnswer`, control: control, render: ({ field: { value, onChange } }) => (_jsxs(Answer, Object.assign({ onClick: () => {
56
55
  onChange(!value);
57
- // 선택지 미리보기에 정답여부를 반영합니다.
58
56
  update(index, Object.assign(Object.assign({}, field), { isAnswer: !value }));
59
57
  } }, { children: ["\uC815\uB2F5", _jsx(Switch, { checked: value, size: "small" })] }))) }), onDelete && (_jsx(SquareButton, { color: "white", size: "xsmall", icon: _jsx(DeleteBinLineIcon, {}), onClick: onDelete }))] }))] })] }));
60
58
  }
@@ -1,14 +1,7 @@
1
- /** @jsxImportSource @emotion/react */
2
- import { Control, FieldArrayWithId, UseFieldArrayAppend, UseFieldArrayRemove, UseFieldArrayUpdate, UseFormHandleSubmit } from "react-hook-form";
3
- import { ProblemSelectPayload } from "../ProblemSelectNode";
1
+ import { Selection } from "../ProblemSelectNode";
4
2
  import { NodeKey } from "lexical";
5
3
  export interface SettingFormProps {
6
- control: Control<ProblemSelectPayload, any>;
7
- handleSubmit: UseFormHandleSubmit<ProblemSelectPayload, undefined>;
8
- fields: FieldArrayWithId<ProblemSelectPayload, "selections", "uid">[];
9
- append: UseFieldArrayAppend<ProblemSelectPayload, "selections">;
10
- remove: UseFieldArrayRemove;
11
- update: UseFieldArrayUpdate<ProblemSelectPayload, "selections">;
4
+ selections: Selection[];
12
5
  nodeKey: NodeKey;
13
6
  onClose: () => void;
14
7
  }
@@ -1,5 +1,7 @@
1
1
  import { jsx as _jsx, jsxs as _jsxs } from "@emotion/react/jsx-runtime";
2
- import { $isProblemSelectNode, } from "../ProblemSelectNode";
2
+ /** @jsxImportSource @emotion/react */
3
+ import { useFieldArray, useForm, } from "react-hook-form";
4
+ import { $isProblemSelectNode } from "../ProblemSelectNode";
3
5
  import { $getNodeByKey } from "lexical";
4
6
  import { css } from "@emotion/react";
5
7
  import { useLexicalComposerContext } from "@lexical/react/LexicalComposerContext";
@@ -11,9 +13,20 @@ import { FormSelection } from "./FormSelection";
11
13
  import Tooltip from "../../../../../components/Tooltip";
12
14
  import { useState } from "react";
13
15
  export default function SettingForm(props) {
14
- const { control, handleSubmit, fields, append, remove, update, nodeKey, onClose, } = props;
16
+ const { selections, nodeKey, onClose } = props;
15
17
  const [editor] = useLexicalComposerContext();
16
18
  const [tooltipOpen, setTooltipOpen] = useState(false);
19
+ const { control, handleSubmit } = useForm({
20
+ mode: "all",
21
+ defaultValues: {
22
+ selections,
23
+ },
24
+ });
25
+ const { fields, append, remove, update } = useFieldArray({
26
+ control,
27
+ name: "selections",
28
+ keyName: "uid",
29
+ });
17
30
  const onSettingSubmit = (data) => {
18
31
  editor.update(() => {
19
32
  const node = $getNodeByKey(nodeKey);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@team-monolith/cds",
3
- "version": "1.9.7",
3
+ "version": "1.9.9",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "sideEffects": false,