@team-monolith/cds 1.11.2 → 1.11.3

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,29 +38,23 @@ export function InputComponent(props) {
38
38
  const lexicalCustomConfig = useContext(LexicalCustomConfigContext);
39
39
  // "** ***" 같은 형태입니다.
40
40
  const answerFormat = solutions[0].value;
41
+ const handleChange = (value) => {
42
+ setAnswerInput(value);
43
+ editor.update(() => {
44
+ const node = $getNodeByKey(nodeKey);
45
+ if (!$isProblemInputNode(node)) {
46
+ return;
47
+ }
48
+ node.setAnswer(value);
49
+ });
50
+ };
41
51
  // 학생 view
42
52
  if (!isEditable) {
43
53
  if (showCharacterNumber) {
44
- return (_jsx(SegmentedInput, { readOnly: lexicalCustomConfig.freezeProblemNode, answerFormat: answerFormat, placeholder: placeholder || "여기에 입력하세요.", value: answerInput, onChange: (value) => {
45
- setAnswerInput(value);
46
- editor.update(() => {
47
- const node = $getNodeByKey(nodeKey);
48
- if (!$isProblemInputNode(node)) {
49
- return;
50
- }
51
- node.setAnswer(value);
52
- });
53
- } }));
54
+ return (_jsx(SegmentedInput, { readOnly: lexicalCustomConfig.freezeProblemNode, answerFormat: answerFormat, placeholder: placeholder || "여기에 입력하세요.", value: answerInput, onChange: handleChange }));
54
55
  }
55
56
  return (_jsx(TextInput, { readOnly: lexicalCustomConfig.freezeProblemNode, size: "small", color: "default", placeholder: placeholder || "여기에 입력하세요.", value: answerInput, onChange: (e) => {
56
- setAnswerInput(e.target.value);
57
- editor.update(() => {
58
- const node = $getNodeByKey(nodeKey);
59
- if (!$isProblemInputNode(node)) {
60
- return;
61
- }
62
- node.setAnswer(e.target.value);
63
- });
57
+ handleChange(e.target.value);
64
58
  }, fullWidth: true }));
65
59
  }
66
60
  // 교사 edit view
@@ -4,14 +4,6 @@ import { css } from "@emotion/react";
4
4
  import styled from "@emotion/styled";
5
5
  import { InputBase } from "../../../../components/InputBase";
6
6
  import { useRef, useState } from "react";
7
- function getDiffIndex(short, long) {
8
- for (let i = 0; i < short.length; i++) {
9
- if (short[i] !== long[i]) {
10
- return i;
11
- }
12
- }
13
- return short.length;
14
- }
15
7
  /**
16
8
  * SOT는 value이고, 그 value는 숨겨진 input에 작성됩니다.
17
9
  * 그리고 그 value는 split되어 segmented input에 표시됩니다.
@@ -29,28 +21,21 @@ export default function SegmentedInput(props) {
29
21
  const hiddenRef = useRef(null);
30
22
  return (_jsxs(Container, { children: [_jsx("input", { type: "input", ref: hiddenRef, value: splitedValues.join(""), readOnly: readOnly, onKeyDown: (e) => {
31
23
  if (e.key === "ArrowLeft") {
32
- if (focusedIndex === null || focusedIndex <= 0) {
33
- return;
34
- }
35
- else {
24
+ if (focusedIndex !== null && focusedIndex > 0) {
36
25
  setFocusedIndex(focusedIndex - 1);
37
26
  }
38
27
  }
39
28
  else if (e.key === "ArrowRight") {
40
- if (focusedIndex === null ||
41
- focusedIndex >= despacedFormat.length - 1) {
42
- return;
43
- }
44
- else {
29
+ if (focusedIndex !== null &&
30
+ focusedIndex < despacedFormat.length - 1) {
45
31
  setFocusedIndex(focusedIndex + 1);
46
32
  }
47
33
  }
48
34
  }, onChange: (event) => {
49
- const latestValue = splitedValues.join("");
50
- const eventValue = event.target.value;
51
- const diffIndex = getDiffIndex(latestValue, eventValue);
52
- onChange(eventValue);
53
- setFocusedIndex(diffIndex);
35
+ var _a;
36
+ onChange(event.target.value);
37
+ const selectionStart = (_a = hiddenRef.current) === null || _a === void 0 ? void 0 : _a.selectionStart;
38
+ setFocusedIndex(selectionStart ? selectionStart - 1 : null);
54
39
  }, onBlur: (e) => {
55
40
  setFocusedIndex(null);
56
41
  const eventValue = e.target.value;
@@ -68,6 +53,8 @@ export default function SegmentedInput(props) {
68
53
  readOnly,
69
54
  onFocus: () => {
70
55
  var _a, _b;
56
+ if (readOnly)
57
+ return;
71
58
  setFocusedIndex(i);
72
59
  (_a = hiddenRef.current) === null || _a === void 0 ? void 0 : _a.focus();
73
60
  (_b = hiddenRef.current) === null || _b === void 0 ? void 0 : _b.setSelectionRange(i, i);
@@ -44,9 +44,7 @@ const Index = styled.div(({ theme, isSelected }) => css `
44
44
  width: 20px;
45
45
  height: 20px;
46
46
  padding: 4px;
47
- // https://www.w3schools.com/howto/howto_css_disable_text_selection.asp
48
- -webkit-user-select: none; /* Safari */
49
- -ms-user-select: none; /* IE 10 and IE 11 */
47
+
50
48
  user-select: none; /* Standard syntax */
51
49
 
52
50
  justify-content: center;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@team-monolith/cds",
3
- "version": "1.11.2",
3
+ "version": "1.11.3",
4
4
  "main": "dist/index.js",
5
5
  "types": "dist/index.d.ts",
6
6
  "sideEffects": false,