@elice/material-quiz 1.240718.0-trasncript.0 → 1.240718.0-trasncript.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.
Files changed (127) hide show
  1. package/cjs/_virtual/_rollupPluginBabelHelpers.js +423 -0
  2. package/cjs/components/eb-sortable/EbDraggable.js +42 -33
  3. package/cjs/components/eb-sortable/EbDroppable.js +27 -20
  4. package/cjs/components/markdown-editor/index.d.ts +1 -2
  5. package/cjs/components/markdown-editor/index.js +19 -10
  6. package/cjs/components/material-quiz/MaterialQuiz.js +114 -83
  7. package/cjs/components/material-quiz/MaterialQuizAnswerExplanation.js +36 -29
  8. package/cjs/components/material-quiz/MaterialQuizInfo.js +151 -149
  9. package/cjs/components/material-quiz/MaterialQuizSelectMultiple.js +175 -127
  10. package/cjs/components/material-quiz/MaterialQuizSelectMultipleOrder.js +360 -286
  11. package/cjs/components/material-quiz/MaterialQuizSelectOne.js +172 -126
  12. package/cjs/components/material-quiz/MaterialQuizShimmer.js +46 -39
  13. package/cjs/components/material-quiz/MaterialQuizText.js +163 -115
  14. package/cjs/components/material-quiz/QuizResultBadge.js +32 -22
  15. package/cjs/components/material-quiz/QuizSubmitStatusText.js +21 -16
  16. package/cjs/components/material-quiz/constants/color.js +5 -5
  17. package/cjs/components/material-quiz/context/MaterialQuizContext.d.ts +1 -1
  18. package/cjs/components/material-quiz/context/MaterialQuizContext.js +156 -93
  19. package/cjs/components/material-quiz/index.js +9 -0
  20. package/cjs/components/material-quiz/locales/index.js +13 -0
  21. package/cjs/components/material-quiz/material-quiz-group/MaterialQuizGroup.js +259 -161
  22. package/cjs/components/material-quiz/material-quiz-group/MaterialQuizGroupDesktop.js +134 -100
  23. package/cjs/components/material-quiz/material-quiz-group/MaterialQuizGroupMobile.js +130 -101
  24. package/cjs/components/material-quiz/material-quiz-group/MaterialQuizGroupOptionItem.js +64 -52
  25. package/cjs/components/material-quiz/material-quiz-group/context/context.js +5 -1
  26. package/cjs/components/material-quiz-edit/MaterialQuizEdit.js +47 -36
  27. package/cjs/components/material-quiz-edit/MaterialQuizEditContent.js +280 -232
  28. package/cjs/components/material-quiz-edit/context.js +8 -2
  29. package/cjs/components/material-quiz-edit/index.js +7 -0
  30. package/cjs/components/material-quiz-edit/locales/index.js +13 -0
  31. package/cjs/components/material-quiz-edit/options/OptionEditor.js +70 -46
  32. package/cjs/components/material-quiz-edit/options/OptionSelectMultiple.js +174 -148
  33. package/cjs/components/material-quiz-edit/options/OptionSelectMultipleOrder.js +175 -149
  34. package/cjs/components/material-quiz-edit/options/OptionSelectOne.js +164 -144
  35. package/cjs/components/material-quiz-edit/options/OptionText.js +90 -82
  36. package/cjs/components/material-quiz-edit/options/options-group/OptionGroup.js +9 -8
  37. package/cjs/components/material-quiz-edit/options/options-group/OptionGroupAnswerInfo.js +156 -112
  38. package/cjs/components/material-quiz-edit/options/options-group/OptionGroupAnswerListItem.js +288 -196
  39. package/cjs/components/material-quiz-edit/options/options-group/OptionGroupGroupInfo.js +88 -75
  40. package/cjs/components/material-quiz-edit/options/options-group/OptionGroupGroupListItem.js +108 -92
  41. package/cjs/components/material-quiz-edit/utils/checkTwoDimensionArray.js +5 -1
  42. package/cjs/components/material-quiz-edit/utils/editValue.js +21 -12
  43. package/cjs/components/shared/QuestionBox.js +198 -165
  44. package/cjs/components/shared/QuizDraggbleDroppedOption.js +11 -12
  45. package/cjs/components/shared/QuizDraggbleDummyOption.js +23 -16
  46. package/cjs/components/shared/QuizDraggbleOption.js +65 -59
  47. package/cjs/components/shared/StyledMarkdown.js +5 -1
  48. package/cjs/components/shared/index.js +19 -0
  49. package/cjs/components/shared/question-checkbox/QuestionCheckbox.js +13 -7
  50. package/cjs/components/shared/question-checkbox/QuestionCheckboxContext.d.ts +1 -1
  51. package/cjs/components/shared/question-checkbox/QuestionCheckboxContext.js +24 -17
  52. package/cjs/components/shared/question-checkbox/QuestionCheckboxOption.js +59 -68
  53. package/cjs/components/shared/question-radio/QuestionRadio.js +13 -7
  54. package/cjs/components/shared/question-radio/QuestionRadioContext.d.ts +1 -1
  55. package/cjs/components/shared/question-radio/QuestionRadioContext.js +24 -17
  56. package/cjs/components/shared/question-radio/QuestionRadioOption.js +52 -59
  57. package/cjs/components/shared/utils/getQuestionStatusStyle.js +7 -9
  58. package/cjs/components/shared/utils/mergeRefs.js +15 -6
  59. package/cjs/constant/element.js +3 -3
  60. package/cjs/constant/index.js +9 -0
  61. package/cjs/helpers/index.js +8 -10
  62. package/cjs/hooks/index.js +7 -0
  63. package/cjs/hooks/useCaculatePassage.js +21 -20
  64. package/es/_virtual/_rollupPluginBabelHelpers.js +408 -0
  65. package/es/components/eb-sortable/EbDraggable.js +37 -33
  66. package/es/components/eb-sortable/EbDroppable.js +22 -20
  67. package/es/components/markdown-editor/index.d.ts +1 -2
  68. package/es/components/markdown-editor/index.js +15 -10
  69. package/es/components/material-quiz/MaterialQuiz.js +109 -83
  70. package/es/components/material-quiz/MaterialQuizAnswerExplanation.js +32 -29
  71. package/es/components/material-quiz/MaterialQuizInfo.js +148 -150
  72. package/es/components/material-quiz/MaterialQuizSelectMultiple.js +171 -127
  73. package/es/components/material-quiz/MaterialQuizSelectMultipleOrder.js +356 -287
  74. package/es/components/material-quiz/MaterialQuizSelectOne.js +168 -126
  75. package/es/components/material-quiz/MaterialQuizShimmer.js +42 -39
  76. package/es/components/material-quiz/MaterialQuizText.js +158 -115
  77. package/es/components/material-quiz/QuizResultBadge.js +27 -22
  78. package/es/components/material-quiz/QuizSubmitStatusText.js +17 -16
  79. package/es/components/material-quiz/constants/color.js +5 -5
  80. package/es/components/material-quiz/context/MaterialQuizContext.d.ts +1 -1
  81. package/es/components/material-quiz/context/MaterialQuizContext.js +153 -94
  82. package/es/components/material-quiz/index.js +2 -0
  83. package/es/components/material-quiz/locales/index.js +4 -0
  84. package/es/components/material-quiz/material-quiz-group/MaterialQuizGroup.js +253 -161
  85. package/es/components/material-quiz/material-quiz-group/MaterialQuizGroupDesktop.js +129 -100
  86. package/es/components/material-quiz/material-quiz-group/MaterialQuizGroupMobile.js +125 -101
  87. package/es/components/material-quiz/material-quiz-group/MaterialQuizGroupOptionItem.js +60 -52
  88. package/es/components/material-quiz/material-quiz-group/context/context.js +1 -1
  89. package/es/components/material-quiz-edit/MaterialQuizEdit.js +43 -36
  90. package/es/components/material-quiz-edit/MaterialQuizEditContent.js +272 -229
  91. package/es/components/material-quiz-edit/context.js +4 -2
  92. package/es/components/material-quiz-edit/index.js +1 -0
  93. package/es/components/material-quiz-edit/locales/index.js +4 -0
  94. package/es/components/material-quiz-edit/options/OptionEditor.js +64 -46
  95. package/es/components/material-quiz-edit/options/OptionSelectMultiple.js +170 -148
  96. package/es/components/material-quiz-edit/options/OptionSelectMultipleOrder.js +171 -149
  97. package/es/components/material-quiz-edit/options/OptionSelectOne.js +159 -144
  98. package/es/components/material-quiz-edit/options/OptionText.js +86 -82
  99. package/es/components/material-quiz-edit/options/options-group/OptionGroup.js +9 -8
  100. package/es/components/material-quiz-edit/options/options-group/OptionGroupAnswerInfo.js +151 -112
  101. package/es/components/material-quiz-edit/options/options-group/OptionGroupAnswerListItem.js +283 -197
  102. package/es/components/material-quiz-edit/options/options-group/OptionGroupGroupInfo.js +83 -75
  103. package/es/components/material-quiz-edit/options/options-group/OptionGroupGroupListItem.js +103 -92
  104. package/es/components/material-quiz-edit/utils/checkTwoDimensionArray.js +5 -1
  105. package/es/components/material-quiz-edit/utils/editValue.js +17 -12
  106. package/es/components/shared/QuestionBox.js +192 -165
  107. package/es/components/shared/QuizDraggbleDroppedOption.js +11 -12
  108. package/es/components/shared/QuizDraggbleDummyOption.js +19 -16
  109. package/es/components/shared/QuizDraggbleOption.js +61 -59
  110. package/es/components/shared/StyledMarkdown.js +1 -1
  111. package/es/components/shared/index.js +7 -0
  112. package/es/components/shared/question-checkbox/QuestionCheckbox.js +9 -7
  113. package/es/components/shared/question-checkbox/QuestionCheckboxContext.d.ts +1 -1
  114. package/es/components/shared/question-checkbox/QuestionCheckboxContext.js +20 -17
  115. package/es/components/shared/question-checkbox/QuestionCheckboxOption.js +54 -68
  116. package/es/components/shared/question-radio/QuestionRadio.js +9 -7
  117. package/es/components/shared/question-radio/QuestionRadioContext.d.ts +1 -1
  118. package/es/components/shared/question-radio/QuestionRadioContext.js +20 -17
  119. package/es/components/shared/question-radio/QuestionRadioOption.js +47 -59
  120. package/es/components/shared/utils/getQuestionStatusStyle.js +7 -9
  121. package/es/components/shared/utils/mergeRefs.js +15 -6
  122. package/es/constant/element.js +3 -3
  123. package/es/constant/index.js +1 -0
  124. package/es/helpers/index.js +8 -10
  125. package/es/hooks/index.js +1 -0
  126. package/es/hooks/useCaculatePassage.js +21 -20
  127. package/package.json +12 -15
@@ -1,3 +1,5 @@
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';
1
3
  import React from 'react';
2
4
  import { getOrgMaterialQuizResponseGet, getOrgMaterialQuizResponseList, postOrgMaterialQuizResponseAdd } from '@elice/api-client';
3
5
  import { Icon, Flex, Text } from '@elice/blocks';
@@ -7,7 +9,7 @@ import { useRawEliceIntl } from '@elice/intl';
7
9
  import { useTheme, Stack } from '@mui/material';
8
10
  import styled from 'styled-components';
9
11
  import { MATERIAL_QUIZ_PASSIVE_ID, MATERIAL_QUIZ_ANSWER_ID } from '../../constant/element.js';
10
- import { getQuizResult, checkUserLectureTestEnded, getQuizResultStatus, QuizResultStatus } from '../../helpers/index.js';
12
+ import { checkUserLectureTestEnded, getQuizResultStatus, QuizResultStatus, getQuizResult } from '../../helpers/index.js';
11
13
  import { useCaculatePassage } from '../../hooks/useCaculatePassage.js';
12
14
  import EbDroppable from '../eb-sortable/EbDroppable.js';
13
15
  import QuestionBox from '../shared/QuestionBox.js';
@@ -20,80 +22,87 @@ import MaterialQuizInfo from './MaterialQuizInfo.js';
20
22
  import QuizResultBadge from './QuizResultBadge.js';
21
23
  import QuizSubmitStatusText from './QuizSubmitStatusText.js';
22
24
 
23
- const StyledVerticalDivider = styled.div.withConfig({
25
+ var StyledVerticalDivider = styled.div.withConfig({
24
26
  componentId: "sc-10067nt-0"
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
- ` : '';
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 " : '';
31
30
  });
32
- const StyledHorizontalDivider = styled.hr.withConfig({
31
+ var StyledHorizontalDivider = styled.hr.withConfig({
33
32
  componentId: "sc-10067nt-1"
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
- ` : '';
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 ") : '';
43
36
  });
44
- const StyledQuizOptionsDropZone = styled(EbDroppable).withConfig({
37
+ var StyledQuizOptionsDropZone = styled(EbDroppable).withConfig({
45
38
  componentId: "sc-10067nt-2"
46
39
  })(["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);
47
- const StyledQuizAnswersDropZone = styled.div.withConfig({
40
+ var StyledQuizAnswersDropZone = styled.div.withConfig({
48
41
  componentId: "sc-10067nt-3"
49
42
  })(["position:relative;display:flex;flex-direction:column;flex:1 1 50%;padding:1rem;border-radius:8px;background-color:", ";"], base.color.navy6);
50
- const StyledOptionBox = styled.div.withConfig({
43
+ var StyledOptionBox = styled.div.withConfig({
51
44
  componentId: "sc-10067nt-4"
52
- })(["display:flex;", ""], ({
53
- vertical
54
- }) => {
55
- return vertical ? `
56
- flex-direction: column;
57
- ` : '';
45
+ })(["display:flex;", ""], function (_ref3) {
46
+ var vertical = _ref3.vertical;
47
+ return vertical ? "\n flex-direction: column;\n " : '';
58
48
  });
59
- const MaterialQuizSelectMultipleOrder = ({
60
- hasInlinePassage
61
- }) => {
49
+ var MaterialQuizSelectMultipleOrder = function MaterialQuizSelectMultipleOrder(_ref4) {
50
+ var hasInlinePassage = _ref4.hasInlinePassage;
62
51
  // context
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();
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();
77
64
  // state
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;
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;
92
101
  // ref
93
- const optionBoxRef = React.useRef(null);
102
+ var optionBoxRef = React.useRef(null);
94
103
  // to make jquery touchable
95
- React.useEffect(() => {
96
- const optionBoxElement = optionBoxRef.current;
104
+ React.useEffect(function () {
105
+ var optionBoxElement = optionBoxRef.current;
97
106
  if (!optionBoxElement) {
98
107
  return;
99
108
  }
@@ -102,9 +111,9 @@ const MaterialQuizSelectMultipleOrder = ({
102
111
  * credit: http://stackoverflow.com/a/6141093
103
112
  */
104
113
  function touchHandler(event) {
105
- const touches = event.changedTouches;
106
- const first = touches[0];
107
- let type = '';
114
+ var touches = event.changedTouches;
115
+ var first = touches[0];
116
+ var type = '';
108
117
  switch (event.type) {
109
118
  case 'touchstart':
110
119
  type = 'mousedown';
@@ -121,7 +130,7 @@ const MaterialQuizSelectMultipleOrder = ({
121
130
  // initMouseEvent(type, canBubble, cancelable, view, clickCount,
122
131
  // screenX, screenY, clientX, clientY, ctrlKey,
123
132
  // altKey, shiftKey, metaKey, button, relatedTarget);
124
- const simulatedEvent = document.createEvent('MouseEvent');
133
+ var simulatedEvent = document.createEvent('MouseEvent');
125
134
  simulatedEvent.initMouseEvent(type, true, true, window, 1, first.screenX, first.screenY, first.clientX, first.clientY, false, false, false, false, 0 /*left*/, null);
126
135
  first.target.dispatchEvent(simulatedEvent);
127
136
  event.preventDefault();
@@ -130,7 +139,7 @@ const MaterialQuizSelectMultipleOrder = ({
130
139
  optionBoxElement.addEventListener('touchmove', touchHandler, true);
131
140
  optionBoxElement.addEventListener('touchend', touchHandler, true);
132
141
  optionBoxElement.addEventListener('touchcancel', touchHandler, true);
133
- return () => {
142
+ return function () {
134
143
  optionBoxElement.removeEventListener('touchstart', touchHandler, true);
135
144
  optionBoxElement.removeEventListener('touchmove', touchHandler, true);
136
145
  optionBoxElement.removeEventListener('touchend', touchHandler, true);
@@ -138,44 +147,48 @@ const MaterialQuizSelectMultipleOrder = ({
138
147
  };
139
148
  }, []);
140
149
  // quiz response fetcher
141
- React.useEffect(() => {
150
+ React.useEffect(function () {
142
151
  var _a, _b;
143
152
  if (!userId && (materialQuiz === null || materialQuiz === void 0 ? void 0 : materialQuiz.lastQuizResponseId)) {
144
- const controller = new AbortController();
145
- const {
146
- signal
147
- } = controller;
153
+ var controller = new AbortController();
154
+ var signal = controller.signal;
148
155
  getOrgMaterialQuizResponseGet({
149
156
  quizResponseId: materialQuiz.lastQuizResponseId
150
157
  }, {
151
- signal
152
- }).then(response => {
158
+ signal: signal
159
+ }).then(function (response) {
153
160
  var _a;
154
161
  setMaterialQuizResponse(response.quizResponse);
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 => {
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) {
158
165
  var _a, _b;
159
166
  return {
160
167
  order: answer,
161
168
  value: (_b = (_a = options[answer]) === null || _a === void 0 ? void 0 : _a.content) !== null && _b !== void 0 ? _b : ''
162
169
  };
163
170
  }, []);
164
- const optionList = options.filter((item, index) => !answer.includes(index)).map(option => {
171
+ var optionList = options.filter(function (item, index) {
172
+ return !answer.includes(index);
173
+ }).map(function (option) {
165
174
  var _a;
166
175
  return {
167
- order: options.findIndex(optionInfo => optionInfo === option),
176
+ order: options.findIndex(function (optionInfo) {
177
+ return optionInfo === option;
178
+ }),
168
179
  value: (_a = option === null || option === void 0 ? void 0 : option.content) !== null && _a !== void 0 ? _a : ''
169
180
  };
170
181
  });
171
182
  setAnswerList(answerList);
172
183
  setOptionList(optionList);
173
- }).catch(error => {
184
+ }).catch(function (error) {
174
185
  console.error(error);
175
186
  });
176
- return () => controller.abort();
187
+ return function () {
188
+ return controller.abort();
189
+ };
177
190
  } else {
178
- setOptionList(((_a = materialQuiz === null || materialQuiz === void 0 ? void 0 : materialQuiz.options) === null || _a === void 0 ? void 0 : _a.map((option, index) => {
191
+ setOptionList(((_a = materialQuiz === null || materialQuiz === void 0 ? void 0 : materialQuiz.options) === null || _a === void 0 ? void 0 : _a.map(function (option, index) {
179
192
  var _a;
180
193
  return {
181
194
  order: index,
@@ -184,19 +197,19 @@ const MaterialQuizSelectMultipleOrder = ({
184
197
  })) || []);
185
198
  setAnswerList(Array.from({
186
199
  length: (_b = materialQuiz === null || materialQuiz === void 0 ? void 0 : materialQuiz.correctOptionCount) !== null && _b !== void 0 ? _b : 0
187
- }, () => ({
188
- order: null,
189
- value: null
190
- })));
200
+ }, function () {
201
+ return {
202
+ order: null,
203
+ value: null
204
+ };
205
+ }));
191
206
  }
192
207
  }, [materialQuiz, userId]);
193
208
  // quiz response fetcher
194
- React.useEffect(() => {
209
+ React.useEffect(function () {
195
210
  if (userId && materialQuiz) {
196
- const controller = new AbortController();
197
- const {
198
- signal
199
- } = controller;
211
+ var controller = new AbortController();
212
+ var signal = controller.signal;
200
213
  getOrgMaterialQuizResponseList({
201
214
  materialQuizId: materialQuiz.id,
202
215
  filterUserIds: [userId],
@@ -205,93 +218,130 @@ const MaterialQuizSelectMultipleOrder = ({
205
218
  offset: 0,
206
219
  count: 1
207
220
  }, {
208
- signal
209
- }).then(response => {
221
+ signal: signal
222
+ }).then(function (response) {
210
223
  var _a, _b, _c;
211
- const quizResponse = response.quizResponses[0];
224
+ var quizResponse = response.quizResponses[0];
212
225
  setMaterialQuizResponse(quizResponse);
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 => {
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) {
217
230
  var _a, _b, _c;
218
231
  return {
219
232
  order: answerInfo,
220
233
  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 : ''
221
234
  };
222
235
  })) !== null && _c !== void 0 ? _c : [] : [];
223
- const answerList = answer.map(answer => {
236
+ var answerList = answer.map(function (answer) {
224
237
  var _a, _b;
225
238
  return {
226
239
  order: answer,
227
240
  value: (_b = (_a = options[answer]) === null || _a === void 0 ? void 0 : _a.content) !== null && _b !== void 0 ? _b : ''
228
241
  };
229
242
  }, []);
230
- const optionList = options.filter((item, index) => !answer.includes(index)).map(option => {
243
+ var optionList = options.filter(function (item, index) {
244
+ return !answer.includes(index);
245
+ }).map(function (option) {
231
246
  var _a;
232
247
  return {
233
- order: options.findIndex(optionInfo => optionInfo === option),
248
+ order: options.findIndex(function (optionInfo) {
249
+ return optionInfo === option;
250
+ }),
234
251
  value: (_a = option === null || option === void 0 ? void 0 : option.content) !== null && _a !== void 0 ? _a : ''
235
252
  };
236
253
  });
237
254
  setCorrectAnswerList(correctAnswerList);
238
255
  setAnswerList(answerList);
239
256
  setOptionList(optionList);
240
- }).catch(error => {
257
+ }).catch(function (error) {
241
258
  console.error(error);
242
259
  });
243
- return () => controller.abort();
260
+ return function () {
261
+ return controller.abort();
262
+ };
244
263
  }
245
264
  }, [materialQuiz, userId]);
246
265
  // submit handler
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, {
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, {
280
324
  disabled: !!userId,
281
325
  accept: ".quiz-answer",
282
- onDrop: (event, ui) => {
326
+ onDrop: function onDrop(event, ui) {
283
327
  if (checkUserLectureTestEnded(lecture)) {
284
328
  return;
285
329
  }
286
330
  setIsActive(true);
287
331
  setHasSubmitted(false);
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);
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
+ });
291
339
  });
292
- setAnswerList(prevAnswerList => {
293
- const removingIndex = prevAnswerList.findIndex(answer => answer.order === targetId);
294
- return prevAnswerList.map((answer, answerIndex) => {
340
+ setAnswerList(function (prevAnswerList) {
341
+ var removingIndex = prevAnswerList.findIndex(function (answer) {
342
+ return answer.order === targetId;
343
+ });
344
+ return prevAnswerList.map(function (answer, answerIndex) {
295
345
  if (answerIndex === removingIndex) {
296
346
  return {
297
347
  order: null,
@@ -302,117 +352,127 @@ const MaterialQuizSelectMultipleOrder = ({
302
352
  }
303
353
  });
304
354
  });
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);
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
+ });
328
380
  };
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:
381
+ var renderQuizDragAnswers = function renderQuizDragAnswers() {
382
+ return jsx(StyledQuizAnswersDropZone, {
383
+ children: answerList.map(function (option, index) {
384
+ var getRole = function getRole() {
385
+ if (isActive) {
342
386
  return 'default';
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
- }
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;
389
426
  });
390
- });
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
+ });
450
+ });
451
+ }
391
452
  }
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
- }));
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
+ });
406
466
  };
407
- return React.createElement(QuestionBox, {
467
+ return jsx(QuestionBox, {
408
468
  title: materialQuiz === null || materialQuiz === void 0 ? void 0 : materialQuiz.questionTitle,
409
469
  titlePrefix: "Q.",
410
470
  onNext: onNext,
411
471
  isNextActive: isNextActive,
412
- submitStatus: React.createElement(QuizSubmitStatusText, {
472
+ submitStatus: jsx(QuizSubmitStatusText, {
413
473
  status: submitStatus
414
474
  }),
415
- submitResult: React.createElement(QuizResultBadge, {
475
+ submitResult: jsx(QuizResultBadge, {
416
476
  materialQuizResponse: materialQuizResponse
417
477
  }),
418
478
  bodyContainerRef: containerRef,
@@ -430,51 +490,60 @@ const MaterialQuizSelectMultipleOrder = ({
430
490
  backgroundColor: isNextActive ? theme.palette.secondary.main : isDisabled ? base.color.gray6 : theme.palette.primary.main,
431
491
  color: isNextActive ? theme.palette.secondary.contrastText : isDisabled ? base.color.gray3 : theme.palette.primary.contrastText
432
492
  }
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))));
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
+ });
478
547
  };
479
548
 
480
549
  export { MaterialQuizSelectMultipleOrder as default };