@elice/material-quiz 1.240718.0-trasncript.2 → 1.240718.1

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.
Files changed (127) hide show
  1. package/cjs/components/eb-sortable/EbDraggable.js +33 -42
  2. package/cjs/components/eb-sortable/EbDroppable.js +20 -27
  3. package/cjs/components/markdown-editor/index.d.ts +2 -1
  4. package/cjs/components/markdown-editor/index.js +10 -19
  5. package/cjs/components/material-quiz/MaterialQuiz.js +83 -114
  6. package/cjs/components/material-quiz/MaterialQuizAnswerExplanation.js +29 -36
  7. package/cjs/components/material-quiz/MaterialQuizInfo.js +149 -151
  8. package/cjs/components/material-quiz/MaterialQuizSelectMultiple.js +127 -175
  9. package/cjs/components/material-quiz/MaterialQuizSelectMultipleOrder.js +286 -360
  10. package/cjs/components/material-quiz/MaterialQuizSelectOne.js +126 -172
  11. package/cjs/components/material-quiz/MaterialQuizShimmer.js +39 -46
  12. package/cjs/components/material-quiz/MaterialQuizText.js +115 -163
  13. package/cjs/components/material-quiz/QuizResultBadge.js +22 -32
  14. package/cjs/components/material-quiz/QuizSubmitStatusText.js +16 -21
  15. package/cjs/components/material-quiz/constants/color.js +5 -5
  16. package/cjs/components/material-quiz/context/MaterialQuizContext.d.ts +1 -1
  17. package/cjs/components/material-quiz/context/MaterialQuizContext.js +93 -156
  18. package/cjs/components/material-quiz/material-quiz-group/MaterialQuizGroup.js +161 -259
  19. package/cjs/components/material-quiz/material-quiz-group/MaterialQuizGroupDesktop.js +100 -134
  20. package/cjs/components/material-quiz/material-quiz-group/MaterialQuizGroupMobile.js +101 -130
  21. package/cjs/components/material-quiz/material-quiz-group/MaterialQuizGroupOptionItem.js +52 -64
  22. package/cjs/components/material-quiz/material-quiz-group/context/context.js +1 -5
  23. package/cjs/components/material-quiz-edit/MaterialQuizEdit.js +36 -47
  24. package/cjs/components/material-quiz-edit/MaterialQuizEditContent.js +232 -280
  25. package/cjs/components/material-quiz-edit/context.js +2 -8
  26. package/cjs/components/material-quiz-edit/options/OptionEditor.js +46 -70
  27. package/cjs/components/material-quiz-edit/options/OptionSelectMultiple.js +148 -174
  28. package/cjs/components/material-quiz-edit/options/OptionSelectMultipleOrder.js +149 -175
  29. package/cjs/components/material-quiz-edit/options/OptionSelectOne.js +144 -164
  30. package/cjs/components/material-quiz-edit/options/OptionText.js +82 -90
  31. package/cjs/components/material-quiz-edit/options/options-group/OptionGroup.js +8 -9
  32. package/cjs/components/material-quiz-edit/options/options-group/OptionGroupAnswerInfo.js +112 -156
  33. package/cjs/components/material-quiz-edit/options/options-group/OptionGroupAnswerListItem.js +196 -288
  34. package/cjs/components/material-quiz-edit/options/options-group/OptionGroupGroupInfo.js +75 -88
  35. package/cjs/components/material-quiz-edit/options/options-group/OptionGroupGroupListItem.js +92 -108
  36. package/cjs/components/material-quiz-edit/utils/checkTwoDimensionArray.js +1 -5
  37. package/cjs/components/material-quiz-edit/utils/editValue.js +12 -21
  38. package/cjs/components/shared/QuestionBox.js +165 -198
  39. package/cjs/components/shared/QuizDraggbleDroppedOption.js +12 -11
  40. package/cjs/components/shared/QuizDraggbleDummyOption.js +16 -23
  41. package/cjs/components/shared/QuizDraggbleOption.js +59 -65
  42. package/cjs/components/shared/StyledMarkdown.js +1 -5
  43. package/cjs/components/shared/question-checkbox/QuestionCheckbox.js +7 -13
  44. package/cjs/components/shared/question-checkbox/QuestionCheckboxContext.d.ts +1 -1
  45. package/cjs/components/shared/question-checkbox/QuestionCheckboxContext.js +17 -24
  46. package/cjs/components/shared/question-checkbox/QuestionCheckboxOption.js +68 -59
  47. package/cjs/components/shared/question-radio/QuestionRadio.js +7 -13
  48. package/cjs/components/shared/question-radio/QuestionRadioContext.d.ts +1 -1
  49. package/cjs/components/shared/question-radio/QuestionRadioContext.js +17 -24
  50. package/cjs/components/shared/question-radio/QuestionRadioOption.js +59 -52
  51. package/cjs/components/shared/utils/getQuestionStatusStyle.js +9 -7
  52. package/cjs/components/shared/utils/mergeRefs.js +6 -15
  53. package/cjs/constant/element.js +3 -3
  54. package/cjs/helpers/index.js +10 -8
  55. package/cjs/hooks/useCaculatePassage.js +20 -21
  56. package/es/components/eb-sortable/EbDraggable.js +33 -37
  57. package/es/components/eb-sortable/EbDroppable.js +20 -22
  58. package/es/components/markdown-editor/index.d.ts +2 -1
  59. package/es/components/markdown-editor/index.js +10 -15
  60. package/es/components/material-quiz/MaterialQuiz.js +83 -109
  61. package/es/components/material-quiz/MaterialQuizAnswerExplanation.js +29 -32
  62. package/es/components/material-quiz/MaterialQuizInfo.js +150 -148
  63. package/es/components/material-quiz/MaterialQuizSelectMultiple.js +127 -171
  64. package/es/components/material-quiz/MaterialQuizSelectMultipleOrder.js +287 -356
  65. package/es/components/material-quiz/MaterialQuizSelectOne.js +126 -168
  66. package/es/components/material-quiz/MaterialQuizShimmer.js +39 -42
  67. package/es/components/material-quiz/MaterialQuizText.js +115 -158
  68. package/es/components/material-quiz/QuizResultBadge.js +22 -27
  69. package/es/components/material-quiz/QuizSubmitStatusText.js +16 -17
  70. package/es/components/material-quiz/constants/color.js +5 -5
  71. package/es/components/material-quiz/context/MaterialQuizContext.d.ts +1 -1
  72. package/es/components/material-quiz/context/MaterialQuizContext.js +94 -153
  73. package/es/components/material-quiz/material-quiz-group/MaterialQuizGroup.js +161 -253
  74. package/es/components/material-quiz/material-quiz-group/MaterialQuizGroupDesktop.js +100 -129
  75. package/es/components/material-quiz/material-quiz-group/MaterialQuizGroupMobile.js +101 -125
  76. package/es/components/material-quiz/material-quiz-group/MaterialQuizGroupOptionItem.js +52 -60
  77. package/es/components/material-quiz/material-quiz-group/context/context.js +1 -1
  78. package/es/components/material-quiz-edit/MaterialQuizEdit.js +36 -43
  79. package/es/components/material-quiz-edit/MaterialQuizEditContent.js +229 -272
  80. package/es/components/material-quiz-edit/context.js +2 -4
  81. package/es/components/material-quiz-edit/options/OptionEditor.js +46 -64
  82. package/es/components/material-quiz-edit/options/OptionSelectMultiple.js +148 -170
  83. package/es/components/material-quiz-edit/options/OptionSelectMultipleOrder.js +149 -171
  84. package/es/components/material-quiz-edit/options/OptionSelectOne.js +144 -159
  85. package/es/components/material-quiz-edit/options/OptionText.js +82 -86
  86. package/es/components/material-quiz-edit/options/options-group/OptionGroup.js +8 -9
  87. package/es/components/material-quiz-edit/options/options-group/OptionGroupAnswerInfo.js +112 -151
  88. package/es/components/material-quiz-edit/options/options-group/OptionGroupAnswerListItem.js +197 -283
  89. package/es/components/material-quiz-edit/options/options-group/OptionGroupGroupInfo.js +75 -83
  90. package/es/components/material-quiz-edit/options/options-group/OptionGroupGroupListItem.js +92 -103
  91. package/es/components/material-quiz-edit/utils/checkTwoDimensionArray.js +1 -5
  92. package/es/components/material-quiz-edit/utils/editValue.js +12 -17
  93. package/es/components/shared/QuestionBox.js +165 -192
  94. package/es/components/shared/QuizDraggbleDroppedOption.js +12 -11
  95. package/es/components/shared/QuizDraggbleDummyOption.js +16 -19
  96. package/es/components/shared/QuizDraggbleOption.js +59 -61
  97. package/es/components/shared/StyledMarkdown.js +1 -1
  98. package/es/components/shared/question-checkbox/QuestionCheckbox.js +7 -9
  99. package/es/components/shared/question-checkbox/QuestionCheckboxContext.d.ts +1 -1
  100. package/es/components/shared/question-checkbox/QuestionCheckboxContext.js +17 -20
  101. package/es/components/shared/question-checkbox/QuestionCheckboxOption.js +68 -54
  102. package/es/components/shared/question-radio/QuestionRadio.js +7 -9
  103. package/es/components/shared/question-radio/QuestionRadioContext.d.ts +1 -1
  104. package/es/components/shared/question-radio/QuestionRadioContext.js +17 -20
  105. package/es/components/shared/question-radio/QuestionRadioOption.js +59 -47
  106. package/es/components/shared/utils/getQuestionStatusStyle.js +9 -7
  107. package/es/components/shared/utils/mergeRefs.js +6 -15
  108. package/es/constant/element.js +3 -3
  109. package/es/helpers/index.js +10 -8
  110. package/es/hooks/useCaculatePassage.js +20 -21
  111. package/package.json +15 -12
  112. package/cjs/_virtual/_rollupPluginBabelHelpers.js +0 -423
  113. package/cjs/components/material-quiz/index.js +0 -9
  114. package/cjs/components/material-quiz/locales/index.js +0 -13
  115. package/cjs/components/material-quiz-edit/index.js +0 -7
  116. package/cjs/components/material-quiz-edit/locales/index.js +0 -13
  117. package/cjs/components/shared/index.js +0 -19
  118. package/cjs/constant/index.js +0 -9
  119. package/cjs/hooks/index.js +0 -7
  120. package/es/_virtual/_rollupPluginBabelHelpers.js +0 -408
  121. package/es/components/material-quiz/index.js +0 -2
  122. package/es/components/material-quiz/locales/index.js +0 -4
  123. package/es/components/material-quiz-edit/index.js +0 -1
  124. package/es/components/material-quiz-edit/locales/index.js +0 -4
  125. package/es/components/shared/index.js +0 -7
  126. package/es/constant/index.js +0 -1
  127. package/es/hooks/index.js +0 -1
@@ -1,5 +1,3 @@
1
- import { slicedToArray as _slicedToArray, toConsumableArray as _toConsumableArray, asyncToGenerator as _asyncToGenerator, regeneratorRuntime as _regeneratorRuntime } from '../../_virtual/_rollupPluginBabelHelpers.js';
2
- import { jsx, jsxs } from 'react/jsx-runtime';
3
1
  import React from 'react';
4
2
  import { getOrgMaterialQuizResponseGet, getOrgMaterialQuizResponseList, postOrgMaterialQuizResponseAdd } from '@elice/api-client';
5
3
  import { Icon, Flex, Text } from '@elice/blocks';
@@ -9,7 +7,7 @@ import { useRawEliceIntl } from '@elice/intl';
9
7
  import { useTheme, Stack } from '@mui/material';
10
8
  import styled from 'styled-components';
11
9
  import { MATERIAL_QUIZ_PASSIVE_ID, MATERIAL_QUIZ_ANSWER_ID } from '../../constant/element.js';
12
- import { checkUserLectureTestEnded, getQuizResultStatus, QuizResultStatus, getQuizResult } from '../../helpers/index.js';
10
+ import { getQuizResult, checkUserLectureTestEnded, getQuizResultStatus, QuizResultStatus } from '../../helpers/index.js';
13
11
  import { useCaculatePassage } from '../../hooks/useCaculatePassage.js';
14
12
  import EbDroppable from '../eb-sortable/EbDroppable.js';
15
13
  import QuestionBox from '../shared/QuestionBox.js';
@@ -22,87 +20,80 @@ import MaterialQuizInfo from './MaterialQuizInfo.js';
22
20
  import QuizResultBadge from './QuizResultBadge.js';
23
21
  import QuizSubmitStatusText from './QuizSubmitStatusText.js';
24
22
 
25
- var StyledVerticalDivider = styled.div.withConfig({
23
+ const StyledVerticalDivider = styled.div.withConfig({
26
24
  componentId: "sc-10067nt-0"
27
- })(["display:flex;flex-direction:column;align-items:center;justify-content:center;flex:none !important;padding:1rem;", ""], function (_ref) {
28
- var vertical = _ref.vertical;
29
- return vertical ? "\n display: none;\n " : '';
25
+ })(["display:flex;flex-direction:column;align-items:center;justify-content:center;flex:none !important;padding:1rem;", ""], ({
26
+ vertical
27
+ }) => {
28
+ return vertical ? `
29
+ display: none;
30
+ ` : '';
30
31
  });
31
- var StyledHorizontalDivider = styled.hr.withConfig({
32
+ const StyledHorizontalDivider = styled.hr.withConfig({
32
33
  componentId: "sc-10067nt-1"
33
- })(["display:none;", ""], function (_ref2) {
34
- var vertical = _ref2.vertical;
35
- return vertical ? "\n display: block;\n margin: 1rem 0;\n width: 100%;\n border: solid 1px ".concat(base.color.navy5, ";\n ") : '';
34
+ })(["display:none;", ""], ({
35
+ vertical
36
+ }) => {
37
+ return vertical ? `
38
+ display: block;
39
+ margin: 1rem 0;
40
+ width: 100%;
41
+ border: solid 1px ${base.color.navy5};
42
+ ` : '';
36
43
  });
37
- var StyledQuizOptionsDropZone = styled(EbDroppable).withConfig({
44
+ const StyledQuizOptionsDropZone = styled(EbDroppable).withConfig({
38
45
  componentId: "sc-10067nt-2"
39
46
  })(["display:flex;flex-direction:column;flex:1 1 50%;padding:1rem;border-radius:8px;background-color:", ";&.ui-droppable-hover{outline:1px dashed ", ";margin:1px 0;}"], base.color.navy7, base.color.gray4);
40
- var StyledQuizAnswersDropZone = styled.div.withConfig({
47
+ const StyledQuizAnswersDropZone = styled.div.withConfig({
41
48
  componentId: "sc-10067nt-3"
42
49
  })(["position:relative;display:flex;flex-direction:column;flex:1 1 50%;padding:1rem;border-radius:8px;background-color:", ";"], base.color.navy6);
43
- var StyledOptionBox = styled.div.withConfig({
50
+ const StyledOptionBox = styled.div.withConfig({
44
51
  componentId: "sc-10067nt-4"
45
- })(["display:flex;", ""], function (_ref3) {
46
- var vertical = _ref3.vertical;
47
- return vertical ? "\n flex-direction: column;\n " : '';
52
+ })(["display:flex;", ""], ({
53
+ vertical
54
+ }) => {
55
+ return vertical ? `
56
+ flex-direction: column;
57
+ ` : '';
48
58
  });
49
- var MaterialQuizSelectMultipleOrder = function MaterialQuizSelectMultipleOrder(_ref4) {
50
- var hasInlinePassage = _ref4.hasInlinePassage;
59
+ const MaterialQuizSelectMultipleOrder = ({
60
+ hasInlinePassage
61
+ }) => {
51
62
  // context
52
- var _useMaterialQuizState = useMaterialQuizState(),
53
- lecture = _useMaterialQuizState.lecture,
54
- materialQuiz = _useMaterialQuizState.materialQuiz,
55
- userId = _useMaterialQuizState.userId,
56
- vertical = _useMaterialQuizState.vertical,
57
- course = _useMaterialQuizState.course;
58
- var _useMaterialQuizDispa = useMaterialQuizDispatch(),
59
- onSubmit = _useMaterialQuizDispa.onSubmit,
60
- onNext = _useMaterialQuizDispa.onNext,
61
- refreshOrgMaterialQuiz = _useMaterialQuizDispa.refreshOrgMaterialQuiz,
62
- onDirty = _useMaterialQuizDispa.onDirty;
63
- var theme = useTheme();
63
+ const {
64
+ lecture,
65
+ materialQuiz,
66
+ userId,
67
+ vertical,
68
+ course
69
+ } = useMaterialQuizState();
70
+ const {
71
+ onSubmit,
72
+ onNext,
73
+ refreshOrgMaterialQuiz,
74
+ onDirty
75
+ } = useMaterialQuizDispatch();
76
+ const theme = useTheme();
64
77
  // state
65
- var intl = useRawEliceIntl();
66
- var _React$useState = React.useState(),
67
- _React$useState2 = _slicedToArray(_React$useState, 2),
68
- materialQuizResponse = _React$useState2[0],
69
- setMaterialQuizResponse = _React$useState2[1];
70
- var _React$useState3 = React.useState('idle'),
71
- _React$useState4 = _slicedToArray(_React$useState3, 2),
72
- submitStatus = _React$useState4[0],
73
- setSubmitStatus = _React$useState4[1];
74
- var _React$useState5 = React.useState(false),
75
- _React$useState6 = _slicedToArray(_React$useState5, 2),
76
- isActive = _React$useState6[0],
77
- setIsActive = _React$useState6[1];
78
- var _useCaculatePassage = useCaculatePassage(),
79
- containerRef = _useCaculatePassage.containerRef,
80
- questionRef = _useCaculatePassage.questionRef;
81
- var _React$useState7 = React.useState([]),
82
- _React$useState8 = _slicedToArray(_React$useState7, 2),
83
- optionList = _React$useState8[0],
84
- setOptionList = _React$useState8[1];
85
- var _React$useState9 = React.useState([]),
86
- _React$useState10 = _slicedToArray(_React$useState9, 2),
87
- answerList = _React$useState10[0],
88
- setAnswerList = _React$useState10[1];
89
- var _React$useState11 = React.useState([]),
90
- _React$useState12 = _slicedToArray(_React$useState11, 2),
91
- correctAnswerList = _React$useState12[0],
92
- setCorrectAnswerList = _React$useState12[1];
93
- var _React$useState13 = React.useState(false),
94
- _React$useState14 = _slicedToArray(_React$useState13, 2),
95
- hasSubmitted = _React$useState14[0],
96
- setHasSubmitted = _React$useState14[1];
97
- var isNextActive = hasSubmitted && typeof onNext === 'function';
98
- var isDisabled = (materialQuiz === null || materialQuiz === void 0 ? void 0 : materialQuiz.correctOptionCount) !== answerList.filter(function (answer) {
99
- return answer.order !== null;
100
- }).length || !!userId;
78
+ const intl = useRawEliceIntl();
79
+ const [materialQuizResponse, setMaterialQuizResponse] = React.useState();
80
+ const [submitStatus, setSubmitStatus] = React.useState('idle');
81
+ const [isActive, setIsActive] = React.useState(false);
82
+ const {
83
+ containerRef,
84
+ questionRef
85
+ } = useCaculatePassage();
86
+ const [optionList, setOptionList] = React.useState([]);
87
+ const [answerList, setAnswerList] = React.useState([]);
88
+ const [correctAnswerList, setCorrectAnswerList] = React.useState([]);
89
+ const [hasSubmitted, setHasSubmitted] = React.useState(false);
90
+ const isNextActive = hasSubmitted && typeof onNext === 'function';
91
+ const isDisabled = (materialQuiz === null || materialQuiz === void 0 ? void 0 : materialQuiz.correctOptionCount) !== answerList.filter(answer => answer.order !== null).length || !!userId;
101
92
  // ref
102
- var optionBoxRef = React.useRef(null);
93
+ const optionBoxRef = React.useRef(null);
103
94
  // to make jquery touchable
104
- React.useEffect(function () {
105
- var optionBoxElement = optionBoxRef.current;
95
+ React.useEffect(() => {
96
+ const optionBoxElement = optionBoxRef.current;
106
97
  if (!optionBoxElement) {
107
98
  return;
108
99
  }
@@ -111,9 +102,9 @@ var MaterialQuizSelectMultipleOrder = function MaterialQuizSelectMultipleOrder(_
111
102
  * credit: http://stackoverflow.com/a/6141093
112
103
  */
113
104
  function touchHandler(event) {
114
- var touches = event.changedTouches;
115
- var first = touches[0];
116
- var type = '';
105
+ const touches = event.changedTouches;
106
+ const first = touches[0];
107
+ let type = '';
117
108
  switch (event.type) {
118
109
  case 'touchstart':
119
110
  type = 'mousedown';
@@ -130,7 +121,7 @@ var MaterialQuizSelectMultipleOrder = function MaterialQuizSelectMultipleOrder(_
130
121
  // initMouseEvent(type, canBubble, cancelable, view, clickCount,
131
122
  // screenX, screenY, clientX, clientY, ctrlKey,
132
123
  // altKey, shiftKey, metaKey, button, relatedTarget);
133
- var simulatedEvent = document.createEvent('MouseEvent');
124
+ const simulatedEvent = document.createEvent('MouseEvent');
134
125
  simulatedEvent.initMouseEvent(type, true, true, window, 1, first.screenX, first.screenY, first.clientX, first.clientY, false, false, false, false, 0 /*left*/, null);
135
126
  first.target.dispatchEvent(simulatedEvent);
136
127
  event.preventDefault();
@@ -139,7 +130,7 @@ var MaterialQuizSelectMultipleOrder = function MaterialQuizSelectMultipleOrder(_
139
130
  optionBoxElement.addEventListener('touchmove', touchHandler, true);
140
131
  optionBoxElement.addEventListener('touchend', touchHandler, true);
141
132
  optionBoxElement.addEventListener('touchcancel', touchHandler, true);
142
- return function () {
133
+ return () => {
143
134
  optionBoxElement.removeEventListener('touchstart', touchHandler, true);
144
135
  optionBoxElement.removeEventListener('touchmove', touchHandler, true);
145
136
  optionBoxElement.removeEventListener('touchend', touchHandler, true);
@@ -147,48 +138,44 @@ var MaterialQuizSelectMultipleOrder = function MaterialQuizSelectMultipleOrder(_
147
138
  };
148
139
  }, []);
149
140
  // quiz response fetcher
150
- React.useEffect(function () {
141
+ React.useEffect(() => {
151
142
  var _a, _b;
152
143
  if (!userId && (materialQuiz === null || materialQuiz === void 0 ? void 0 : materialQuiz.lastQuizResponseId)) {
153
- var controller = new AbortController();
154
- var signal = controller.signal;
144
+ const controller = new AbortController();
145
+ const {
146
+ signal
147
+ } = controller;
155
148
  getOrgMaterialQuizResponseGet({
156
149
  quizResponseId: materialQuiz.lastQuizResponseId
157
150
  }, {
158
- signal: signal
159
- }).then(function (response) {
151
+ signal
152
+ }).then(response => {
160
153
  var _a;
161
154
  setMaterialQuizResponse(response.quizResponse);
162
- var answer = response.quizResponse.answer; // user submitted
163
- var options = (_a = materialQuiz.options) !== null && _a !== void 0 ? _a : []; // options
164
- var answerList = answer.map(function (answer) {
155
+ const answer = response.quizResponse.answer; // user submitted
156
+ const options = (_a = materialQuiz.options) !== null && _a !== void 0 ? _a : []; // options
157
+ const answerList = answer.map(answer => {
165
158
  var _a, _b;
166
159
  return {
167
160
  order: answer,
168
161
  value: (_b = (_a = options[answer]) === null || _a === void 0 ? void 0 : _a.content) !== null && _b !== void 0 ? _b : ''
169
162
  };
170
163
  }, []);
171
- var optionList = options.filter(function (item, index) {
172
- return !answer.includes(index);
173
- }).map(function (option) {
164
+ const optionList = options.filter((item, index) => !answer.includes(index)).map(option => {
174
165
  var _a;
175
166
  return {
176
- order: options.findIndex(function (optionInfo) {
177
- return optionInfo === option;
178
- }),
167
+ order: options.findIndex(optionInfo => optionInfo === option),
179
168
  value: (_a = option === null || option === void 0 ? void 0 : option.content) !== null && _a !== void 0 ? _a : ''
180
169
  };
181
170
  });
182
171
  setAnswerList(answerList);
183
172
  setOptionList(optionList);
184
- }).catch(function (error) {
173
+ }).catch(error => {
185
174
  console.error(error);
186
175
  });
187
- return function () {
188
- return controller.abort();
189
- };
176
+ return () => controller.abort();
190
177
  } else {
191
- setOptionList(((_a = materialQuiz === null || materialQuiz === void 0 ? void 0 : materialQuiz.options) === null || _a === void 0 ? void 0 : _a.map(function (option, index) {
178
+ setOptionList(((_a = materialQuiz === null || materialQuiz === void 0 ? void 0 : materialQuiz.options) === null || _a === void 0 ? void 0 : _a.map((option, index) => {
192
179
  var _a;
193
180
  return {
194
181
  order: index,
@@ -197,19 +184,19 @@ var MaterialQuizSelectMultipleOrder = function MaterialQuizSelectMultipleOrder(_
197
184
  })) || []);
198
185
  setAnswerList(Array.from({
199
186
  length: (_b = materialQuiz === null || materialQuiz === void 0 ? void 0 : materialQuiz.correctOptionCount) !== null && _b !== void 0 ? _b : 0
200
- }, function () {
201
- return {
202
- order: null,
203
- value: null
204
- };
205
- }));
187
+ }, () => ({
188
+ order: null,
189
+ value: null
190
+ })));
206
191
  }
207
192
  }, [materialQuiz, userId]);
208
193
  // quiz response fetcher
209
- React.useEffect(function () {
194
+ React.useEffect(() => {
210
195
  if (userId && materialQuiz) {
211
- var controller = new AbortController();
212
- var signal = controller.signal;
196
+ const controller = new AbortController();
197
+ const {
198
+ signal
199
+ } = controller;
213
200
  getOrgMaterialQuizResponseList({
214
201
  materialQuizId: materialQuiz.id,
215
202
  filterUserIds: [userId],
@@ -218,130 +205,93 @@ var MaterialQuizSelectMultipleOrder = function MaterialQuizSelectMultipleOrder(_
218
205
  offset: 0,
219
206
  count: 1
220
207
  }, {
221
- signal: signal
222
- }).then(function (response) {
208
+ signal
209
+ }).then(response => {
223
210
  var _a, _b, _c;
224
- var quizResponse = response.quizResponses[0];
211
+ const quizResponse = response.quizResponses[0];
225
212
  setMaterialQuizResponse(quizResponse);
226
- var answer = (_a = quizResponse === null || quizResponse === void 0 ? void 0 : quizResponse.answer) !== null && _a !== void 0 ? _a : []; // user submitted
227
- var options = (_b = materialQuiz.options) !== null && _b !== void 0 ? _b : []; // options
228
- var materialQuizAnswerInfo = materialQuiz.answerInfo;
229
- var correctAnswerList = Array.isArray(materialQuizAnswerInfo) ? (_c = materialQuizAnswerInfo === null || materialQuizAnswerInfo === void 0 ? void 0 : materialQuizAnswerInfo.map(function (answerInfo) {
213
+ const answer = (_a = quizResponse === null || quizResponse === void 0 ? void 0 : quizResponse.answer) !== null && _a !== void 0 ? _a : []; // user submitted
214
+ const options = (_b = materialQuiz.options) !== null && _b !== void 0 ? _b : []; // options
215
+ const materialQuizAnswerInfo = materialQuiz.answerInfo;
216
+ const correctAnswerList = Array.isArray(materialQuizAnswerInfo) ? (_c = materialQuizAnswerInfo === null || materialQuizAnswerInfo === void 0 ? void 0 : materialQuizAnswerInfo.map(answerInfo => {
230
217
  var _a, _b, _c;
231
218
  return {
232
219
  order: answerInfo,
233
220
  value: (_c = (_b = (_a = materialQuiz.options) === null || _a === void 0 ? void 0 : _a[answerInfo]) === null || _b === void 0 ? void 0 : _b.content) !== null && _c !== void 0 ? _c : ''
234
221
  };
235
222
  })) !== null && _c !== void 0 ? _c : [] : [];
236
- var answerList = answer.map(function (answer) {
223
+ const answerList = answer.map(answer => {
237
224
  var _a, _b;
238
225
  return {
239
226
  order: answer,
240
227
  value: (_b = (_a = options[answer]) === null || _a === void 0 ? void 0 : _a.content) !== null && _b !== void 0 ? _b : ''
241
228
  };
242
229
  }, []);
243
- var optionList = options.filter(function (item, index) {
244
- return !answer.includes(index);
245
- }).map(function (option) {
230
+ const optionList = options.filter((item, index) => !answer.includes(index)).map(option => {
246
231
  var _a;
247
232
  return {
248
- order: options.findIndex(function (optionInfo) {
249
- return optionInfo === option;
250
- }),
233
+ order: options.findIndex(optionInfo => optionInfo === option),
251
234
  value: (_a = option === null || option === void 0 ? void 0 : option.content) !== null && _a !== void 0 ? _a : ''
252
235
  };
253
236
  });
254
237
  setCorrectAnswerList(correctAnswerList);
255
238
  setAnswerList(answerList);
256
239
  setOptionList(optionList);
257
- }).catch(function (error) {
240
+ }).catch(error => {
258
241
  console.error(error);
259
242
  });
260
- return function () {
261
- return controller.abort();
262
- };
243
+ return () => controller.abort();
263
244
  }
264
245
  }, [materialQuiz, userId]);
265
246
  // submit handler
266
- var handleSubmit = /*#__PURE__*/function () {
267
- var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
268
- var _yield$postOrgMateria, quizResponseId, _yield$getOrgMaterial, quizResponse;
269
- return _regeneratorRuntime().wrap(function _callee$(_context) {
270
- while (1) switch (_context.prev = _context.next) {
271
- case 0:
272
- if (materialQuiz) {
273
- _context.next = 2;
274
- break;
275
- }
276
- return _context.abrupt("return");
277
- case 2:
278
- setSubmitStatus('pending');
279
- _context.prev = 3;
280
- _context.next = 6;
281
- return postOrgMaterialQuizResponseAdd({
282
- materialQuizId: materialQuiz.id,
283
- answer: answerList.map(function (answer) {
284
- return answer.order;
285
- }) // FIXME: Type mismatch
286
- });
287
- case 6:
288
- _yield$postOrgMateria = _context.sent;
289
- quizResponseId = _yield$postOrgMateria.quizResponseId;
290
- _context.next = 10;
291
- return getOrgMaterialQuizResponseGet({
292
- quizResponseId: quizResponseId
293
- });
294
- case 10:
295
- _yield$getOrgMaterial = _context.sent;
296
- quizResponse = _yield$getOrgMaterial.quizResponse;
297
- setIsActive(false);
298
- setHasSubmitted(true);
299
- setMaterialQuizResponse(quizResponse);
300
- void refreshOrgMaterialQuiz();
301
- onSubmit(true, getQuizResult(quizResponse));
302
- setSubmitStatus('resolved');
303
- onDirty(false);
304
- _context.next = 26;
305
- break;
306
- case 21:
307
- _context.prev = 21;
308
- _context.t0 = _context["catch"](3);
309
- console.error(_context.t0);
310
- onSubmit(false);
311
- setSubmitStatus('rejected');
312
- case 26:
313
- case "end":
314
- return _context.stop();
315
- }
316
- }, _callee, null, [[3, 21]]);
317
- }));
318
- return function handleSubmit() {
319
- return _ref5.apply(this, arguments);
320
- };
321
- }();
322
- var renderQuizDragOption = function renderQuizDragOption() {
323
- return jsxs(StyledQuizOptionsDropZone, {
247
+ const handleSubmit = async () => {
248
+ if (!materialQuiz) {
249
+ return;
250
+ }
251
+ setSubmitStatus('pending');
252
+ try {
253
+ const {
254
+ quizResponseId
255
+ } = await postOrgMaterialQuizResponseAdd({
256
+ materialQuizId: materialQuiz.id,
257
+ answer: answerList.map(answer => answer.order) // FIXME: Type mismatch
258
+ });
259
+
260
+ const {
261
+ quizResponse
262
+ } = await getOrgMaterialQuizResponseGet({
263
+ quizResponseId
264
+ });
265
+ setIsActive(false);
266
+ setHasSubmitted(true);
267
+ setMaterialQuizResponse(quizResponse);
268
+ void refreshOrgMaterialQuiz();
269
+ onSubmit(true, getQuizResult(quizResponse));
270
+ setSubmitStatus('resolved');
271
+ onDirty(false);
272
+ } catch (error) {
273
+ console.error(error);
274
+ onSubmit(false);
275
+ setSubmitStatus('rejected');
276
+ }
277
+ };
278
+ const renderQuizDragOption = () => {
279
+ return React.createElement(StyledQuizOptionsDropZone, {
324
280
  disabled: !!userId,
325
281
  accept: ".quiz-answer",
326
- onDrop: function onDrop(event, ui) {
282
+ onDrop: (event, ui) => {
327
283
  if (checkUserLectureTestEnded(lecture)) {
328
284
  return;
329
285
  }
330
286
  setIsActive(true);
331
287
  setHasSubmitted(false);
332
- var targetId = Number(ui.draggable[0].id);
333
- setOptionList(function (prevOptionList) {
334
- return [].concat(_toConsumableArray(prevOptionList), [answerList.find(function (answer) {
335
- return answer.order === targetId;
336
- })]).sort(function (a, b) {
337
- return a.order - b.order;
338
- });
288
+ const targetId = Number(ui.draggable[0].id);
289
+ setOptionList(prevOptionList => {
290
+ return [...prevOptionList, answerList.find(answer => answer.order === targetId)].sort((a, b) => a.order - b.order);
339
291
  });
340
- setAnswerList(function (prevAnswerList) {
341
- var removingIndex = prevAnswerList.findIndex(function (answer) {
342
- return answer.order === targetId;
343
- });
344
- return prevAnswerList.map(function (answer, answerIndex) {
292
+ setAnswerList(prevAnswerList => {
293
+ const removingIndex = prevAnswerList.findIndex(answer => answer.order === targetId);
294
+ return prevAnswerList.map((answer, answerIndex) => {
345
295
  if (answerIndex === removingIndex) {
346
296
  return {
347
297
  order: null,
@@ -352,127 +302,117 @@ var MaterialQuizSelectMultipleOrder = function MaterialQuizSelectMultipleOrder(_
352
302
  }
353
303
  });
354
304
  });
355
- },
356
- children: [optionList.map(function (option, index) {
357
- return jsx(QuizDraggbleOption, {
358
- disabled: !!userId,
359
- id: option.order.toString(),
360
- className: "quiz-option",
361
- content: option.value,
362
- isMarkdown: !!(course === null || course === void 0 ? void 0 : course.preference.renderMarkdownInQuizOptions)
363
- }, option.order);
364
- }), optionList.length === 0 && !userId ? jsx(Flex, {
365
- align: "center",
366
- justify: "center",
367
- style: {
368
- minWidth: '200px',
369
- height: '100%'
370
- },
371
- children: jsx(Text, {
372
- size: "tiny",
373
- role: "white",
374
- children: intl.formatMessage({
375
- id: 'materialQuiz.order.answerEmpty'
376
- })
377
- })
378
- }) : null]
379
- });
305
+ }
306
+ }, optionList.map((option, index) => {
307
+ return React.createElement(QuizDraggbleOption, {
308
+ disabled: !!userId,
309
+ key: option.order,
310
+ id: option.order.toString(),
311
+ className: "quiz-option",
312
+ content: option.value,
313
+ isMarkdown: !!(course === null || course === void 0 ? void 0 : course.preference.renderMarkdownInQuizOptions)
314
+ });
315
+ }), optionList.length === 0 && !userId ? React.createElement(Flex, {
316
+ align: "center",
317
+ justify: "center",
318
+ style: {
319
+ minWidth: '200px',
320
+ height: '100%'
321
+ }
322
+ }, React.createElement(Text, {
323
+ size: "tiny",
324
+ role: "white"
325
+ }, intl.formatMessage({
326
+ id: 'materialQuiz.order.answerEmpty'
327
+ }))) : null);
380
328
  };
381
- var renderQuizDragAnswers = function renderQuizDragAnswers() {
382
- return jsx(StyledQuizAnswersDropZone, {
383
- children: answerList.map(function (option, index) {
384
- var getRole = function getRole() {
385
- if (isActive) {
329
+ const renderQuizDragAnswers = () => {
330
+ return React.createElement(StyledQuizAnswersDropZone, null, answerList.map((option, index) => {
331
+ const getRole = () => {
332
+ if (isActive) {
333
+ return 'default';
334
+ }
335
+ const status = getQuizResultStatus(materialQuizResponse);
336
+ switch (status) {
337
+ case QuizResultStatus.Correct:
338
+ return 'correct';
339
+ case QuizResultStatus.Wrong:
340
+ return 'wrong';
341
+ default:
386
342
  return 'default';
387
- }
388
- var status = getQuizResultStatus(materialQuizResponse);
389
- switch (status) {
390
- case QuizResultStatus.Correct:
391
- return 'correct';
392
- case QuizResultStatus.Wrong:
393
- return 'wrong';
394
- default:
395
- return 'default';
396
- }
397
- };
398
- if (option.value === null) {
399
- return jsx(QuizDraggbleDummyOption, {
400
- children: intl.formatMessage({
401
- id: 'materialQuiz.selectMultipleOrder.answer.title'
402
- }),
403
- indexOrder: index + 1,
404
- onDrop: function onDrop(event, ui) {
405
- if (checkUserLectureTestEnded(lecture)) {
406
- return;
407
- }
408
- setIsActive(true);
409
- setHasSubmitted(false);
410
- onDirty(true);
411
- // from answerList to answerList
412
- if (ui.draggable[0].classList.contains('quiz-answer')) {
413
- var targetOptionId = Number(ui.draggable[0].id);
414
- setAnswerList(function (prevAnswerList) {
415
- var newState = _toConsumableArray(prevAnswerList);
416
- var from = newState.find(function (prevAnswer) {
417
- return prevAnswer.order === targetOptionId;
418
- });
419
- var fromIndex = newState.findIndex(function (prevAnswer) {
420
- return prevAnswer.order === targetOptionId;
421
- });
422
- var to = newState[index];
423
- newState[index] = from;
424
- newState[fromIndex] = to;
425
- return newState;
426
- });
427
- }
428
- // from option-list to answerList-list
429
- else {
430
- var _targetOptionId = Number(ui.draggable[0].id);
431
- setOptionList(function (prevOptions) {
432
- return prevOptions.filter(function (prevOption) {
433
- return prevOption.order !== _targetOptionId;
434
- });
435
- });
436
- setAnswerList(function (prevAnswerList) {
437
- return prevAnswerList.map(function (prevAnswer, prevAnswerIndex) {
438
- var _a, _b;
439
- if (index === prevAnswerIndex) {
440
- return {
441
- order: _targetOptionId,
442
- value: (_b = (_a = optionList.find(function (option) {
443
- return option.order === _targetOptionId;
444
- })) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : ''
445
- };
446
- } else {
447
- return prevAnswer;
448
- }
449
- });
343
+ }
344
+ };
345
+ if (option.value === null) {
346
+ return React.createElement(QuizDraggbleDummyOption, {
347
+ children: intl.formatMessage({
348
+ id: 'materialQuiz.selectMultipleOrder.answer.title'
349
+ }),
350
+ key: index,
351
+ indexOrder: index + 1,
352
+ onDrop: (event, ui) => {
353
+ if (checkUserLectureTestEnded(lecture)) {
354
+ return;
355
+ }
356
+ setIsActive(true);
357
+ setHasSubmitted(false);
358
+ onDirty(true);
359
+ // from answerList to answerList
360
+ if (ui.draggable[0].classList.contains('quiz-answer')) {
361
+ const targetOptionId = Number(ui.draggable[0].id);
362
+ setAnswerList(prevAnswerList => {
363
+ const newState = [...prevAnswerList];
364
+ const from = newState.find(prevAnswer => prevAnswer.order === targetOptionId);
365
+ const fromIndex = newState.findIndex(prevAnswer => prevAnswer.order === targetOptionId);
366
+ const to = newState[index];
367
+ newState[index] = from;
368
+ newState[fromIndex] = to;
369
+ return newState;
370
+ });
371
+ }
372
+ // from option-list to answerList-list
373
+ else {
374
+ const targetOptionId = Number(ui.draggable[0].id);
375
+ setOptionList(prevOptions => {
376
+ return prevOptions.filter(prevOption => prevOption.order !== targetOptionId);
377
+ });
378
+ setAnswerList(prevAnswerList => {
379
+ return prevAnswerList.map((prevAnswer, prevAnswerIndex) => {
380
+ var _a, _b;
381
+ if (index === prevAnswerIndex) {
382
+ return {
383
+ order: targetOptionId,
384
+ value: (_b = (_a = optionList.find(option => option.order === targetOptionId)) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : ''
385
+ };
386
+ } else {
387
+ return prevAnswer;
388
+ }
450
389
  });
451
- }
390
+ });
452
391
  }
453
- }, index);
454
- } else {
455
- return jsx(QuizDraggbleDroppedOption, {
456
- id: option.order.toString(),
457
- content: option.value,
458
- role: getRole(),
459
- disabled: !!userId,
460
- indexOrder: index + 1,
461
- isMarkdown: !!(course === null || course === void 0 ? void 0 : course.preference.renderMarkdownInQuizOptions)
462
- }, index);
463
- }
464
- })
465
- });
392
+ }
393
+ });
394
+ } else {
395
+ return React.createElement(QuizDraggbleDroppedOption, {
396
+ key: index,
397
+ id: option.order.toString(),
398
+ content: option.value,
399
+ role: getRole(),
400
+ disabled: !!userId,
401
+ indexOrder: index + 1,
402
+ isMarkdown: !!(course === null || course === void 0 ? void 0 : course.preference.renderMarkdownInQuizOptions)
403
+ });
404
+ }
405
+ }));
466
406
  };
467
- return jsx(QuestionBox, {
407
+ return React.createElement(QuestionBox, {
468
408
  title: materialQuiz === null || materialQuiz === void 0 ? void 0 : materialQuiz.questionTitle,
469
409
  titlePrefix: "Q.",
470
410
  onNext: onNext,
471
411
  isNextActive: isNextActive,
472
- submitStatus: jsx(QuizSubmitStatusText, {
412
+ submitStatus: React.createElement(QuizSubmitStatusText, {
473
413
  status: submitStatus
474
414
  }),
475
- submitResult: jsx(QuizResultBadge, {
415
+ submitResult: React.createElement(QuizResultBadge, {
476
416
  materialQuizResponse: materialQuizResponse
477
417
  }),
478
418
  bodyContainerRef: containerRef,
@@ -490,60 +430,51 @@ var MaterialQuizSelectMultipleOrder = function MaterialQuizSelectMultipleOrder(_
490
430
  backgroundColor: isNextActive ? theme.palette.secondary.main : isDisabled ? base.color.gray6 : theme.palette.primary.main,
491
431
  color: isNextActive ? theme.palette.secondary.contrastText : isDisabled ? base.color.gray3 : theme.palette.primary.contrastText
492
432
  }
493
- }],
494
- children: jsxs(Stack, {
495
- height: "100%",
496
- gap: "1rem",
497
- children: [hasInlinePassage && jsx("div", {
498
- id: MATERIAL_QUIZ_PASSIVE_ID,
499
- ref: questionRef,
500
- children: jsx(MaterialQuizInfo, {
501
- renderWithBox: false
502
- })
503
- }), jsxs("div", {
504
- id: MATERIAL_QUIZ_ANSWER_ID,
505
- children: [jsxs(StyledOptionBox, {
506
- ref: optionBoxRef,
507
- vertical: vertical,
508
- children: [renderQuizDragOption(), jsx(StyledVerticalDivider, {
509
- vertical: vertical,
510
- children: jsx(Icon, {
511
- size: "elephant",
512
- icon: eilSortItem,
513
- rotate: 90,
514
- style: {
515
- color: base.color.navy3
516
- }
517
- })
518
- }), jsx(StyledHorizontalDivider, {
519
- vertical: vertical
520
- }), renderQuizDragAnswers()]
521
- }), !!userId ? jsx(Flex, {
522
- margintop: "1rem",
523
- column: true,
524
- children: jsxs(StyledQuizOptionsDropZone, {
525
- children: [jsx(Text, {
526
- role: "white",
527
- size: "small",
528
- children: intl.formatMessage({
529
- id: 'materialQuiz.answer'
530
- })
531
- }), correctAnswerList.map(function (correctAnswer, index) {
532
- var _a;
533
- return jsx(QuizDraggbleDroppedOption, {
534
- id: (_a = correctAnswer.order) === null || _a === void 0 ? void 0 : _a.toString(),
535
- content: correctAnswer.value,
536
- disabled: true,
537
- role: "correct",
538
- indexOrder: index + 1,
539
- isMarkdown: !!(course === null || course === void 0 ? void 0 : course.preference.renderMarkdownInQuizOptions)
540
- }, correctAnswer.order);
541
- })]
542
- })
543
- }) : null, jsx(MaterialQuizAnswerExplanation, {})]
544
- })]
545
- })
546
- });
433
+ }]
434
+ }, React.createElement(Stack, {
435
+ height: "100%",
436
+ gap: "1rem"
437
+ }, hasInlinePassage && React.createElement("div", {
438
+ id: MATERIAL_QUIZ_PASSIVE_ID,
439
+ ref: questionRef
440
+ }, React.createElement(MaterialQuizInfo, {
441
+ renderWithBox: false
442
+ })), React.createElement("div", {
443
+ id: MATERIAL_QUIZ_ANSWER_ID
444
+ }, React.createElement(StyledOptionBox, {
445
+ ref: optionBoxRef,
446
+ vertical: vertical
447
+ }, renderQuizDragOption(), React.createElement(StyledVerticalDivider, {
448
+ vertical: vertical
449
+ }, React.createElement(Icon, {
450
+ size: "elephant",
451
+ icon: eilSortItem,
452
+ rotate: 90,
453
+ style: {
454
+ color: base.color.navy3
455
+ }
456
+ })), React.createElement(StyledHorizontalDivider, {
457
+ vertical: vertical
458
+ }), renderQuizDragAnswers()), !!userId ? React.createElement(Flex, {
459
+ margintop: "1rem",
460
+ column: true
461
+ }, React.createElement(StyledQuizOptionsDropZone, null, React.createElement(Text, {
462
+ role: "white",
463
+ size: "small"
464
+ }, intl.formatMessage({
465
+ id: 'materialQuiz.answer'
466
+ })), correctAnswerList.map((correctAnswer, index) => {
467
+ var _a;
468
+ return React.createElement(QuizDraggbleDroppedOption, {
469
+ key: correctAnswer.order,
470
+ id: (_a = correctAnswer.order) === null || _a === void 0 ? void 0 : _a.toString(),
471
+ content: correctAnswer.value,
472
+ disabled: true,
473
+ role: "correct",
474
+ indexOrder: index + 1,
475
+ isMarkdown: !!(course === null || course === void 0 ? void 0 : course.preference.renderMarkdownInQuizOptions)
476
+ });
477
+ }))) : null, React.createElement(MaterialQuizAnswerExplanation, null))));
547
478
  };
548
479
 
549
480
  export { MaterialQuizSelectMultipleOrder as default };