@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
@@ -2,6 +2,8 @@
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');
5
7
  var React = require('react');
6
8
  var apiClient = require('@elice/api-client');
7
9
  var blocks = require('@elice/blocks');
@@ -24,80 +26,92 @@ var MaterialQuizInfo = require('./MaterialQuizInfo.js');
24
26
  var QuizResultBadge = require('./QuizResultBadge.js');
25
27
  var QuizSubmitStatusText = require('./QuizSubmitStatusText.js');
26
28
 
27
- const StyledVerticalDivider = styled.div.withConfig({
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({
28
35
  componentId: "sc-10067nt-0"
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
- ` : '';
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 " : '';
35
39
  });
36
- const StyledHorizontalDivider = styled.hr.withConfig({
40
+ var StyledHorizontalDivider = styled__default.default.hr.withConfig({
37
41
  componentId: "sc-10067nt-1"
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
- ` : '';
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 ") : '';
47
45
  });
48
- const StyledQuizOptionsDropZone = styled(EbDroppable.default).withConfig({
46
+ var StyledQuizOptionsDropZone = styled__default.default(EbDroppable.default).withConfig({
49
47
  componentId: "sc-10067nt-2"
50
48
  })(["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);
51
- const StyledQuizAnswersDropZone = styled.div.withConfig({
49
+ var StyledQuizAnswersDropZone = styled__default.default.div.withConfig({
52
50
  componentId: "sc-10067nt-3"
53
51
  })(["position:relative;display:flex;flex-direction:column;flex:1 1 50%;padding:1rem;border-radius:8px;background-color:", ";"], designTokens.base.color.navy6);
54
- const StyledOptionBox = styled.div.withConfig({
52
+ var StyledOptionBox = styled__default.default.div.withConfig({
55
53
  componentId: "sc-10067nt-4"
56
- })(["display:flex;", ""], ({
57
- vertical
58
- }) => {
59
- return vertical ? `
60
- flex-direction: column;
61
- ` : '';
54
+ })(["display:flex;", ""], function (_ref3) {
55
+ var vertical = _ref3.vertical;
56
+ return vertical ? "\n flex-direction: column;\n " : '';
62
57
  });
63
- const MaterialQuizSelectMultipleOrder = ({
64
- hasInlinePassage
65
- }) => {
58
+ var MaterialQuizSelectMultipleOrder = function MaterialQuizSelectMultipleOrder(_ref4) {
59
+ var hasInlinePassage = _ref4.hasInlinePassage;
66
60
  // context
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();
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();
81
73
  // state
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;
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;
96
110
  // ref
97
- const optionBoxRef = React.useRef(null);
111
+ var optionBoxRef = React__default.default.useRef(null);
98
112
  // to make jquery touchable
99
- React.useEffect(() => {
100
- const optionBoxElement = optionBoxRef.current;
113
+ React__default.default.useEffect(function () {
114
+ var optionBoxElement = optionBoxRef.current;
101
115
  if (!optionBoxElement) {
102
116
  return;
103
117
  }
@@ -106,9 +120,9 @@ const MaterialQuizSelectMultipleOrder = ({
106
120
  * credit: http://stackoverflow.com/a/6141093
107
121
  */
108
122
  function touchHandler(event) {
109
- const touches = event.changedTouches;
110
- const first = touches[0];
111
- let type = '';
123
+ var touches = event.changedTouches;
124
+ var first = touches[0];
125
+ var type = '';
112
126
  switch (event.type) {
113
127
  case 'touchstart':
114
128
  type = 'mousedown';
@@ -125,7 +139,7 @@ const MaterialQuizSelectMultipleOrder = ({
125
139
  // initMouseEvent(type, canBubble, cancelable, view, clickCount,
126
140
  // screenX, screenY, clientX, clientY, ctrlKey,
127
141
  // altKey, shiftKey, metaKey, button, relatedTarget);
128
- const simulatedEvent = document.createEvent('MouseEvent');
142
+ var simulatedEvent = document.createEvent('MouseEvent');
129
143
  simulatedEvent.initMouseEvent(type, true, true, window, 1, first.screenX, first.screenY, first.clientX, first.clientY, false, false, false, false, 0 /*left*/, null);
130
144
  first.target.dispatchEvent(simulatedEvent);
131
145
  event.preventDefault();
@@ -134,7 +148,7 @@ const MaterialQuizSelectMultipleOrder = ({
134
148
  optionBoxElement.addEventListener('touchmove', touchHandler, true);
135
149
  optionBoxElement.addEventListener('touchend', touchHandler, true);
136
150
  optionBoxElement.addEventListener('touchcancel', touchHandler, true);
137
- return () => {
151
+ return function () {
138
152
  optionBoxElement.removeEventListener('touchstart', touchHandler, true);
139
153
  optionBoxElement.removeEventListener('touchmove', touchHandler, true);
140
154
  optionBoxElement.removeEventListener('touchend', touchHandler, true);
@@ -142,44 +156,48 @@ const MaterialQuizSelectMultipleOrder = ({
142
156
  };
143
157
  }, []);
144
158
  // quiz response fetcher
145
- React.useEffect(() => {
159
+ React__default.default.useEffect(function () {
146
160
  var _a, _b;
147
161
  if (!userId && (materialQuiz === null || materialQuiz === void 0 ? void 0 : materialQuiz.lastQuizResponseId)) {
148
- const controller = new AbortController();
149
- const {
150
- signal
151
- } = controller;
162
+ var controller = new AbortController();
163
+ var signal = controller.signal;
152
164
  apiClient.getOrgMaterialQuizResponseGet({
153
165
  quizResponseId: materialQuiz.lastQuizResponseId
154
166
  }, {
155
- signal
156
- }).then(response => {
167
+ signal: signal
168
+ }).then(function (response) {
157
169
  var _a;
158
170
  setMaterialQuizResponse(response.quizResponse);
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 => {
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) {
162
174
  var _a, _b;
163
175
  return {
164
176
  order: answer,
165
177
  value: (_b = (_a = options[answer]) === null || _a === void 0 ? void 0 : _a.content) !== null && _b !== void 0 ? _b : ''
166
178
  };
167
179
  }, []);
168
- const optionList = options.filter((item, index) => !answer.includes(index)).map(option => {
180
+ var optionList = options.filter(function (item, index) {
181
+ return !answer.includes(index);
182
+ }).map(function (option) {
169
183
  var _a;
170
184
  return {
171
- order: options.findIndex(optionInfo => optionInfo === option),
185
+ order: options.findIndex(function (optionInfo) {
186
+ return optionInfo === option;
187
+ }),
172
188
  value: (_a = option === null || option === void 0 ? void 0 : option.content) !== null && _a !== void 0 ? _a : ''
173
189
  };
174
190
  });
175
191
  setAnswerList(answerList);
176
192
  setOptionList(optionList);
177
- }).catch(error => {
193
+ }).catch(function (error) {
178
194
  console.error(error);
179
195
  });
180
- return () => controller.abort();
196
+ return function () {
197
+ return controller.abort();
198
+ };
181
199
  } else {
182
- setOptionList(((_a = materialQuiz === null || materialQuiz === void 0 ? void 0 : materialQuiz.options) === null || _a === void 0 ? void 0 : _a.map((option, index) => {
200
+ setOptionList(((_a = materialQuiz === null || materialQuiz === void 0 ? void 0 : materialQuiz.options) === null || _a === void 0 ? void 0 : _a.map(function (option, index) {
183
201
  var _a;
184
202
  return {
185
203
  order: index,
@@ -188,19 +206,19 @@ const MaterialQuizSelectMultipleOrder = ({
188
206
  })) || []);
189
207
  setAnswerList(Array.from({
190
208
  length: (_b = materialQuiz === null || materialQuiz === void 0 ? void 0 : materialQuiz.correctOptionCount) !== null && _b !== void 0 ? _b : 0
191
- }, () => ({
192
- order: null,
193
- value: null
194
- })));
209
+ }, function () {
210
+ return {
211
+ order: null,
212
+ value: null
213
+ };
214
+ }));
195
215
  }
196
216
  }, [materialQuiz, userId]);
197
217
  // quiz response fetcher
198
- React.useEffect(() => {
218
+ React__default.default.useEffect(function () {
199
219
  if (userId && materialQuiz) {
200
- const controller = new AbortController();
201
- const {
202
- signal
203
- } = controller;
220
+ var controller = new AbortController();
221
+ var signal = controller.signal;
204
222
  apiClient.getOrgMaterialQuizResponseList({
205
223
  materialQuizId: materialQuiz.id,
206
224
  filterUserIds: [userId],
@@ -209,93 +227,130 @@ const MaterialQuizSelectMultipleOrder = ({
209
227
  offset: 0,
210
228
  count: 1
211
229
  }, {
212
- signal
213
- }).then(response => {
230
+ signal: signal
231
+ }).then(function (response) {
214
232
  var _a, _b, _c;
215
- const quizResponse = response.quizResponses[0];
233
+ var quizResponse = response.quizResponses[0];
216
234
  setMaterialQuizResponse(quizResponse);
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 => {
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) {
221
239
  var _a, _b, _c;
222
240
  return {
223
241
  order: answerInfo,
224
242
  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 : ''
225
243
  };
226
244
  })) !== null && _c !== void 0 ? _c : [] : [];
227
- const answerList = answer.map(answer => {
245
+ var answerList = answer.map(function (answer) {
228
246
  var _a, _b;
229
247
  return {
230
248
  order: answer,
231
249
  value: (_b = (_a = options[answer]) === null || _a === void 0 ? void 0 : _a.content) !== null && _b !== void 0 ? _b : ''
232
250
  };
233
251
  }, []);
234
- const optionList = options.filter((item, index) => !answer.includes(index)).map(option => {
252
+ var optionList = options.filter(function (item, index) {
253
+ return !answer.includes(index);
254
+ }).map(function (option) {
235
255
  var _a;
236
256
  return {
237
- order: options.findIndex(optionInfo => optionInfo === option),
257
+ order: options.findIndex(function (optionInfo) {
258
+ return optionInfo === option;
259
+ }),
238
260
  value: (_a = option === null || option === void 0 ? void 0 : option.content) !== null && _a !== void 0 ? _a : ''
239
261
  };
240
262
  });
241
263
  setCorrectAnswerList(correctAnswerList);
242
264
  setAnswerList(answerList);
243
265
  setOptionList(optionList);
244
- }).catch(error => {
266
+ }).catch(function (error) {
245
267
  console.error(error);
246
268
  });
247
- return () => controller.abort();
269
+ return function () {
270
+ return controller.abort();
271
+ };
248
272
  }
249
273
  }, [materialQuiz, userId]);
250
274
  // submit handler
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, {
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, {
284
333
  disabled: !!userId,
285
334
  accept: ".quiz-answer",
286
- onDrop: (event, ui) => {
335
+ onDrop: function onDrop(event, ui) {
287
336
  if (index.checkUserLectureTestEnded(lecture)) {
288
337
  return;
289
338
  }
290
339
  setIsActive(true);
291
340
  setHasSubmitted(false);
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);
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
+ });
295
348
  });
296
- setAnswerList(prevAnswerList => {
297
- const removingIndex = prevAnswerList.findIndex(answer => answer.order === targetId);
298
- return prevAnswerList.map((answer, answerIndex) => {
349
+ setAnswerList(function (prevAnswerList) {
350
+ var removingIndex = prevAnswerList.findIndex(function (answer) {
351
+ return answer.order === targetId;
352
+ });
353
+ return prevAnswerList.map(function (answer, answerIndex) {
299
354
  if (answerIndex === removingIndex) {
300
355
  return {
301
356
  order: null,
@@ -306,117 +361,127 @@ const MaterialQuizSelectMultipleOrder = ({
306
361
  }
307
362
  });
308
363
  });
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);
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
+ });
332
389
  };
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:
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) {
346
395
  return 'default';
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
- }
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
+ });
393
459
  });
394
- });
460
+ }
395
461
  }
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
- }));
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
+ });
410
475
  };
411
- return React.createElement(QuestionBox.default, {
476
+ return jsxRuntime.jsx(QuestionBox.default, {
412
477
  title: materialQuiz === null || materialQuiz === void 0 ? void 0 : materialQuiz.questionTitle,
413
478
  titlePrefix: "Q.",
414
479
  onNext: onNext,
415
480
  isNextActive: isNextActive,
416
- submitStatus: React.createElement(QuizSubmitStatusText.default, {
481
+ submitStatus: jsxRuntime.jsx(QuizSubmitStatusText.default, {
417
482
  status: submitStatus
418
483
  }),
419
- submitResult: React.createElement(QuizResultBadge.default, {
484
+ submitResult: jsxRuntime.jsx(QuizResultBadge.default, {
420
485
  materialQuizResponse: materialQuizResponse
421
486
  }),
422
487
  bodyContainerRef: containerRef,
@@ -434,51 +499,60 @@ const MaterialQuizSelectMultipleOrder = ({
434
499
  backgroundColor: isNextActive ? theme.palette.secondary.main : isDisabled ? designTokens.base.color.gray6 : theme.palette.primary.main,
435
500
  color: isNextActive ? theme.palette.secondary.contrastText : isDisabled ? designTokens.base.color.gray3 : theme.palette.primary.contrastText
436
501
  }
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))));
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
+ });
482
556
  };
483
557
 
484
558
  exports.default = MaterialQuizSelectMultipleOrder;