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