@elice/material-quiz 1.240719.0 → 1.240722.0-dev2.0

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 (29) hide show
  1. package/cjs/components/eb-sortable/EbDraggable.d.ts +1 -12
  2. package/cjs/components/eb-sortable/EbDraggable.js +29 -99
  3. package/cjs/components/eb-sortable/EbDroppable.d.ts +3 -8
  4. package/cjs/components/eb-sortable/EbDroppable.js +17 -43
  5. package/cjs/components/material-quiz/MaterialQuizSelectMultiple.js +2 -1
  6. package/cjs/components/material-quiz/MaterialQuizSelectMultipleOrder.js +246 -173
  7. package/cjs/components/material-quiz/MaterialQuizSelectOne.js +2 -1
  8. package/cjs/components/material-quiz/material-quiz-group/MaterialQuizGroupDesktop.js +41 -10
  9. package/cjs/components/shared/QuizDraggbleDroppedOption.d.ts +1 -1
  10. package/cjs/components/shared/QuizDraggbleDroppedOption.js +35 -10
  11. package/cjs/components/shared/QuizDraggbleDummyOption.d.ts +1 -3
  12. package/cjs/components/shared/QuizDraggbleDummyOption.js +8 -3
  13. package/cjs/components/shared/QuizDraggbleOption.d.ts +0 -1
  14. package/cjs/components/shared/QuizDraggbleOption.js +10 -4
  15. package/es/components/eb-sortable/EbDraggable.d.ts +1 -12
  16. package/es/components/eb-sortable/EbDraggable.js +29 -94
  17. package/es/components/eb-sortable/EbDroppable.d.ts +3 -8
  18. package/es/components/eb-sortable/EbDroppable.js +17 -38
  19. package/es/components/material-quiz/MaterialQuizSelectMultiple.js +2 -1
  20. package/es/components/material-quiz/MaterialQuizSelectMultipleOrder.js +246 -173
  21. package/es/components/material-quiz/MaterialQuizSelectOne.js +2 -1
  22. package/es/components/material-quiz/material-quiz-group/MaterialQuizGroupDesktop.js +42 -11
  23. package/es/components/shared/QuizDraggbleDroppedOption.d.ts +1 -1
  24. package/es/components/shared/QuizDraggbleDroppedOption.js +31 -10
  25. package/es/components/shared/QuizDraggbleDummyOption.d.ts +1 -3
  26. package/es/components/shared/QuizDraggbleDummyOption.js +8 -3
  27. package/es/components/shared/QuizDraggbleOption.d.ts +0 -1
  28. package/es/components/shared/QuizDraggbleOption.js +10 -4
  29. package/package.json +5 -3
@@ -1,6 +1,7 @@
1
1
  import { slicedToArray as _slicedToArray, toConsumableArray as _toConsumableArray, asyncToGenerator as _asyncToGenerator, regeneratorRuntime as _regeneratorRuntime } from '../../_virtual/_rollupPluginBabelHelpers.js';
2
2
  import { jsx, jsxs } from 'react/jsx-runtime';
3
3
  import React from 'react';
4
+ import { useSensors, useSensor, MouseSensor, TouchSensor, DndContext } from '@dnd-kit/core';
4
5
  import { getOrgMaterialQuizResponseGet, getOrgMaterialQuizResponseList, postOrgMaterialQuizResponseAdd } from '@elice/api-client';
5
6
  import { Icon, Flex, Text } from '@elice/blocks';
6
7
  import { base } from '@elice/design-tokens';
@@ -22,6 +23,9 @@ import MaterialQuizInfo from './MaterialQuizInfo.js';
22
23
  import QuizResultBadge from './QuizResultBadge.js';
23
24
  import QuizSubmitStatusText from './QuizSubmitStatusText.js';
24
25
 
26
+ //
27
+ //
28
+ //
25
29
  var StyledVerticalDivider = styled.div.withConfig({
26
30
  componentId: "sc-10067nt-0"
27
31
  })(["display:flex;flex-direction:column;align-items:center;justify-content:center;flex:none !important;padding:1rem;", ""], function (_ref) {
@@ -46,6 +50,9 @@ var StyledOptionBox = styled.div.withConfig({
46
50
  var vertical = _ref3.vertical;
47
51
  return vertical ? "\n flex-direction: column;\n " : '';
48
52
  });
53
+ //
54
+ //
55
+ //
49
56
  var MaterialQuizSelectMultipleOrder = function MaterialQuizSelectMultipleOrder(_ref4) {
50
57
  var hasInlinePassage = _ref4.hasInlinePassage;
51
58
  // context
@@ -100,52 +107,16 @@ var MaterialQuizSelectMultipleOrder = function MaterialQuizSelectMultipleOrder(_
100
107
  }).length || !!userId;
101
108
  // ref
102
109
  var optionBoxRef = React.useRef(null);
103
- // to make jquery touchable
104
- React.useEffect(function () {
105
- var optionBoxElement = optionBoxRef.current;
106
- if (!optionBoxElement) {
107
- return;
110
+ var sensors = useSensors(useSensor(MouseSensor, {
111
+ activationConstraint: {
112
+ distance: 10
108
113
  }
109
- /**
110
- * Lightweight script to convert touch handlers to mouse handlers
111
- * credit: http://stackoverflow.com/a/6141093
112
- */
113
- function touchHandler(event) {
114
- var touches = event.changedTouches;
115
- var first = touches[0];
116
- var type = '';
117
- switch (event.type) {
118
- case 'touchstart':
119
- type = 'mousedown';
120
- break;
121
- case 'touchmove':
122
- type = 'mousemove';
123
- break;
124
- case 'touchend':
125
- type = 'mouseup';
126
- break;
127
- default:
128
- return;
129
- }
130
- // initMouseEvent(type, canBubble, cancelable, view, clickCount,
131
- // screenX, screenY, clientX, clientY, ctrlKey,
132
- // altKey, shiftKey, metaKey, button, relatedTarget);
133
- var simulatedEvent = document.createEvent('MouseEvent');
134
- simulatedEvent.initMouseEvent(type, true, true, window, 1, first.screenX, first.screenY, first.clientX, first.clientY, false, false, false, false, 0 /*left*/, null);
135
- first.target.dispatchEvent(simulatedEvent);
136
- event.preventDefault();
114
+ }), useSensor(TouchSensor, {
115
+ activationConstraint: {
116
+ delay: 50,
117
+ tolerance: 5
137
118
  }
138
- optionBoxElement.addEventListener('touchstart', touchHandler, true);
139
- optionBoxElement.addEventListener('touchmove', touchHandler, true);
140
- optionBoxElement.addEventListener('touchend', touchHandler, true);
141
- optionBoxElement.addEventListener('touchcancel', touchHandler, true);
142
- return function () {
143
- optionBoxElement.removeEventListener('touchstart', touchHandler, true);
144
- optionBoxElement.removeEventListener('touchmove', touchHandler, true);
145
- optionBoxElement.removeEventListener('touchend', touchHandler, true);
146
- optionBoxElement.removeEventListener('touchcancel', touchHandler, true);
147
- };
148
- }, []);
119
+ }));
149
120
  // quiz response fetcher
150
121
  React.useEffect(function () {
151
122
  var _a, _b;
@@ -161,10 +132,11 @@ var MaterialQuizSelectMultipleOrder = function MaterialQuizSelectMultipleOrder(_
161
132
  setMaterialQuizResponse(response.quizResponse);
162
133
  var answer = response.quizResponse.answer; // user submitted
163
134
  var options = (_a = materialQuiz.options) !== null && _a !== void 0 ? _a : []; // options
164
- var answerList = answer.map(function (answer) {
135
+ var answerList = answer.map(function (answer, index) {
165
136
  var _a, _b;
166
137
  return {
167
- order: answer,
138
+ initialOrder: answer,
139
+ order: index,
168
140
  value: (_b = (_a = options[answer]) === null || _a === void 0 ? void 0 : _a.content) !== null && _b !== void 0 ? _b : ''
169
141
  };
170
142
  }, []);
@@ -173,6 +145,9 @@ var MaterialQuizSelectMultipleOrder = function MaterialQuizSelectMultipleOrder(_
173
145
  }).map(function (option) {
174
146
  var _a;
175
147
  return {
148
+ initialOrder: options.findIndex(function (optionInfo) {
149
+ return optionInfo === option;
150
+ }),
176
151
  order: options.findIndex(function (optionInfo) {
177
152
  return optionInfo === option;
178
153
  }),
@@ -191,6 +166,7 @@ var MaterialQuizSelectMultipleOrder = function MaterialQuizSelectMultipleOrder(_
191
166
  setOptionList(((_a = materialQuiz === null || materialQuiz === void 0 ? void 0 : materialQuiz.options) === null || _a === void 0 ? void 0 : _a.map(function (option, index) {
192
167
  var _a;
193
168
  return {
169
+ initialOrder: index,
194
170
  order: index,
195
171
  value: (_a = option === null || option === void 0 ? void 0 : option.content) !== null && _a !== void 0 ? _a : ''
196
172
  };
@@ -199,6 +175,7 @@ var MaterialQuizSelectMultipleOrder = function MaterialQuizSelectMultipleOrder(_
199
175
  length: (_b = materialQuiz === null || materialQuiz === void 0 ? void 0 : materialQuiz.correctOptionCount) !== null && _b !== void 0 ? _b : 0
200
176
  }, function () {
201
177
  return {
178
+ initialOrder: null,
202
179
  order: null,
203
180
  value: null
204
181
  };
@@ -229,6 +206,7 @@ var MaterialQuizSelectMultipleOrder = function MaterialQuizSelectMultipleOrder(_
229
206
  var correctAnswerList = Array.isArray(materialQuizAnswerInfo) ? (_c = materialQuizAnswerInfo === null || materialQuizAnswerInfo === void 0 ? void 0 : materialQuizAnswerInfo.map(function (answerInfo) {
230
207
  var _a, _b, _c;
231
208
  return {
209
+ initialOrder: answerInfo,
232
210
  order: answerInfo,
233
211
  value: (_c = (_b = (_a = materialQuiz.options) === null || _a === void 0 ? void 0 : _a[answerInfo]) === null || _b === void 0 ? void 0 : _b.content) !== null && _c !== void 0 ? _c : ''
234
212
  };
@@ -236,6 +214,7 @@ var MaterialQuizSelectMultipleOrder = function MaterialQuizSelectMultipleOrder(_
236
214
  var answerList = answer.map(function (answer) {
237
215
  var _a, _b;
238
216
  return {
217
+ initialOrder: answer,
239
218
  order: answer,
240
219
  value: (_b = (_a = options[answer]) === null || _a === void 0 ? void 0 : _a.content) !== null && _b !== void 0 ? _b : ''
241
220
  };
@@ -245,6 +224,9 @@ var MaterialQuizSelectMultipleOrder = function MaterialQuizSelectMultipleOrder(_
245
224
  }).map(function (option) {
246
225
  var _a;
247
226
  return {
227
+ initialOrder: options.findIndex(function (optionInfo) {
228
+ return optionInfo === option;
229
+ }),
248
230
  order: options.findIndex(function (optionInfo) {
249
231
  return optionInfo === option;
250
232
  }),
@@ -262,7 +244,9 @@ var MaterialQuizSelectMultipleOrder = function MaterialQuizSelectMultipleOrder(_
262
244
  };
263
245
  }
264
246
  }, [materialQuiz, userId]);
265
- // submit handler
247
+ /**
248
+ * submit handler
249
+ */
266
250
  var handleSubmit = /*#__PURE__*/function () {
267
251
  var _ref5 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime().mark(function _callee() {
268
252
  var _yield$postOrgMateria, quizResponseId, _yield$getOrgMaterial, quizResponse;
@@ -281,8 +265,8 @@ var MaterialQuizSelectMultipleOrder = function MaterialQuizSelectMultipleOrder(_
281
265
  return postOrgMaterialQuizResponseAdd({
282
266
  materialQuizId: materialQuiz.id,
283
267
  answer: answerList.map(function (answer) {
284
- return answer.order;
285
- }) // FIXME: Type mismatch
268
+ return answer.initialOrder;
269
+ })
286
270
  });
287
271
  case 6:
288
272
  _yield$postOrgMateria = _context.sent;
@@ -319,48 +303,175 @@ var MaterialQuizSelectMultipleOrder = function MaterialQuizSelectMultipleOrder(_
319
303
  return _ref5.apply(this, arguments);
320
304
  };
321
305
  }();
306
+ /**
307
+ *
308
+ */
309
+ var handleDragEnd = function handleDragEnd(event) {
310
+ var _a;
311
+ if (checkUserLectureTestEnded(lecture)) {
312
+ return;
313
+ }
314
+ var targetId = Number(event.active.id.split('-').pop());
315
+ var dropzoneId = (_a = event.over) === null || _a === void 0 ? void 0 : _a.id.toString();
316
+ setIsActive(true);
317
+ setHasSubmitted(false);
318
+ dropzoneId === 'quiz-options-dropzone' && onDirty(true);
319
+ if (dropzoneId === 'quiz-options-dropzone') {
320
+ handleDropOptionZone(event, targetId);
321
+ } else if (dropzoneId === null || dropzoneId === void 0 ? void 0 : dropzoneId.includes('quiz-dummy-zone')) {
322
+ handleDropDummyZone(event, targetId);
323
+ } else if (dropzoneId === null || dropzoneId === void 0 ? void 0 : dropzoneId.includes('quiz-answer-zone')) {
324
+ handleDropAnswerZone(event, targetId);
325
+ }
326
+ };
327
+ /**
328
+ *
329
+ */
330
+ var handleDropOptionZone = function handleDropOptionZone(event, targetId) {
331
+ var _a;
332
+ var isAnswerTarget = event.active.id.toString().includes('answer');
333
+ // option to option
334
+ if (!isAnswerTarget) {
335
+ return;
336
+ }
337
+ // answer to option
338
+ else {
339
+ var from = targetId;
340
+ var to = ((_a = event.over) === null || _a === void 0 ? void 0 : _a.id) === 'quiz-options-dropzone' ? optionList.length : 0;
341
+ setOptionList(function (prevOptionList) {
342
+ var _a, _b, _c;
343
+ var newState = _toConsumableArray(prevOptionList);
344
+ newState[to] = {
345
+ initialOrder: (_a = answerList[from]) === null || _a === void 0 ? void 0 : _a.initialOrder,
346
+ order: to,
347
+ value: (_c = (_b = answerList[from]) === null || _b === void 0 ? void 0 : _b.value) !== null && _c !== void 0 ? _c : ''
348
+ };
349
+ return newState;
350
+ });
351
+ setAnswerList(function (prevAnswerList) {
352
+ var newState = _toConsumableArray(prevAnswerList);
353
+ newState[from] = {
354
+ initialOrder: null,
355
+ order: null,
356
+ value: null
357
+ };
358
+ return newState;
359
+ });
360
+ }
361
+ };
362
+ /**
363
+ *
364
+ */
365
+ var handleDropAnswerZone = function handleDropAnswerZone(event, targetId) {
366
+ var _a;
367
+ var isAnswerTarget = event.active.id.toString().includes('answer');
368
+ var dropzoneIndex = Number(((_a = event.over) === null || _a === void 0 ? void 0 : _a.id).split('-').pop());
369
+ var from = targetId;
370
+ var to = dropzoneIndex;
371
+ // answer to answer
372
+ if (isAnswerTarget) {
373
+ setAnswerList(function (prevAnswerList) {
374
+ var newState = _toConsumableArray(prevAnswerList);
375
+ newState[from].order = to;
376
+ newState[to].order = from;
377
+ var temp = newState[from];
378
+ newState[from] = newState[to];
379
+ newState[to] = temp;
380
+ return newState;
381
+ });
382
+ }
383
+ // option to answer
384
+ else {
385
+ setOptionList(function (prevOptionList) {
386
+ var _a, _b;
387
+ var newState = _toConsumableArray(prevOptionList);
388
+ newState[from] = {
389
+ initialOrder: (_a = answerList[to]) === null || _a === void 0 ? void 0 : _a.initialOrder,
390
+ order: from,
391
+ value: (_b = answerList[to]) === null || _b === void 0 ? void 0 : _b.value
392
+ };
393
+ return newState;
394
+ });
395
+ setAnswerList(function (prevAnswerList) {
396
+ var _a, _b, _c;
397
+ var newState = _toConsumableArray(prevAnswerList);
398
+ newState[to] = {
399
+ initialOrder: (_a = optionList[from]) === null || _a === void 0 ? void 0 : _a.initialOrder,
400
+ order: to,
401
+ value: (_c = (_b = optionList[from]) === null || _b === void 0 ? void 0 : _b.value) !== null && _c !== void 0 ? _c : null
402
+ };
403
+ return newState;
404
+ });
405
+ }
406
+ };
407
+ /**
408
+ *
409
+ */
410
+ var handleDropDummyZone = function handleDropDummyZone(event, targetId) {
411
+ var _a;
412
+ var isAnswerTarget = event.active.id.toString().includes('answer');
413
+ var dropzoneIndex = Number(((_a = event.over) === null || _a === void 0 ? void 0 : _a.id).split('-').pop());
414
+ var from = targetId;
415
+ var to = dropzoneIndex;
416
+ // option to dummy
417
+ if (!isAnswerTarget) {
418
+ setAnswerList(function (prevAnswerList) {
419
+ var _a, _b, _c;
420
+ var newState = _toConsumableArray(prevAnswerList);
421
+ newState[dropzoneIndex] = {
422
+ initialOrder: (_a = optionList[from]) === null || _a === void 0 ? void 0 : _a.initialOrder,
423
+ order: to,
424
+ value: (_c = (_b = optionList[from]) === null || _b === void 0 ? void 0 : _b.value) !== null && _c !== void 0 ? _c : null
425
+ };
426
+ return newState;
427
+ });
428
+ setOptionList(function (prevOptionList) {
429
+ var newState = _toConsumableArray(prevOptionList);
430
+ // reorder
431
+ newState.splice(from, 1);
432
+ newState.forEach(function (option, index) {
433
+ if (option.order > targetId) {
434
+ newState[index].order -= 1;
435
+ }
436
+ });
437
+ return newState;
438
+ });
439
+ }
440
+ // answer to dummy
441
+ else {
442
+ setAnswerList(function (prevAnswerList) {
443
+ var _a, _b;
444
+ var newState = _toConsumableArray(prevAnswerList);
445
+ newState[to] = {
446
+ initialOrder: (_a = newState[from]) === null || _a === void 0 ? void 0 : _a.initialOrder,
447
+ order: to,
448
+ value: (_b = newState[from]) === null || _b === void 0 ? void 0 : _b.value
449
+ };
450
+ newState[from] = {
451
+ initialOrder: null,
452
+ order: null,
453
+ value: null
454
+ };
455
+ return newState;
456
+ });
457
+ }
458
+ };
459
+ /**
460
+ *
461
+ */
322
462
  var renderQuizDragOption = function renderQuizDragOption() {
323
463
  return jsxs(StyledQuizOptionsDropZone, {
464
+ id: "quiz-options-dropzone",
324
465
  disabled: !!userId,
325
466
  accept: ".quiz-answer",
326
- onDrop: function onDrop(event, ui) {
327
- if (checkUserLectureTestEnded(lecture)) {
328
- return;
329
- }
330
- setIsActive(true);
331
- setHasSubmitted(false);
332
- var targetId = Number(ui.draggable[0].id);
333
- setOptionList(function (prevOptionList) {
334
- return [].concat(_toConsumableArray(prevOptionList), [answerList.find(function (answer) {
335
- return answer.order === targetId;
336
- })]).sort(function (a, b) {
337
- return a.order - b.order;
338
- });
339
- });
340
- setAnswerList(function (prevAnswerList) {
341
- var removingIndex = prevAnswerList.findIndex(function (answer) {
342
- return answer.order === targetId;
343
- });
344
- return prevAnswerList.map(function (answer, answerIndex) {
345
- if (answerIndex === removingIndex) {
346
- return {
347
- order: null,
348
- value: null
349
- };
350
- } else {
351
- return answer;
352
- }
353
- });
354
- });
355
- },
356
467
  children: [optionList.map(function (option, index) {
357
468
  return jsx(QuizDraggbleOption, {
358
469
  disabled: !!userId,
359
- id: option.order.toString(),
470
+ id: "quiz-option-".concat(index),
360
471
  className: "quiz-option",
361
472
  content: option.value,
362
473
  isMarkdown: !!(course === null || course === void 0 ? void 0 : course.preference.renderMarkdownInQuizOptions)
363
- }, option.order);
474
+ }, "quiz-option-".concat(index));
364
475
  }), optionList.length === 0 && !userId ? jsx(Flex, {
365
476
  align: "center",
366
477
  justify: "center",
@@ -378,6 +489,9 @@ var MaterialQuizSelectMultipleOrder = function MaterialQuizSelectMultipleOrder(_
378
489
  }) : null]
379
490
  });
380
491
  };
492
+ /**
493
+ *
494
+ */
381
495
  var renderQuizDragAnswers = function renderQuizDragAnswers() {
382
496
  return jsx(StyledQuizAnswersDropZone, {
383
497
  children: answerList.map(function (option, index) {
@@ -400,70 +514,24 @@ var MaterialQuizSelectMultipleOrder = function MaterialQuizSelectMultipleOrder(_
400
514
  children: intl.formatMessage({
401
515
  id: 'materialQuiz.selectMultipleOrder.answer.title'
402
516
  }),
403
- indexOrder: index + 1,
404
- onDrop: function onDrop(event, ui) {
405
- if (checkUserLectureTestEnded(lecture)) {
406
- return;
407
- }
408
- setIsActive(true);
409
- setHasSubmitted(false);
410
- onDirty(true);
411
- // from answerList to answerList
412
- if (ui.draggable[0].classList.contains('quiz-answer')) {
413
- var targetOptionId = Number(ui.draggable[0].id);
414
- setAnswerList(function (prevAnswerList) {
415
- var newState = _toConsumableArray(prevAnswerList);
416
- var from = newState.find(function (prevAnswer) {
417
- return prevAnswer.order === targetOptionId;
418
- });
419
- var fromIndex = newState.findIndex(function (prevAnswer) {
420
- return prevAnswer.order === targetOptionId;
421
- });
422
- var to = newState[index];
423
- newState[index] = from;
424
- newState[fromIndex] = to;
425
- return newState;
426
- });
427
- }
428
- // from option-list to answerList-list
429
- else {
430
- var _targetOptionId = Number(ui.draggable[0].id);
431
- setOptionList(function (prevOptions) {
432
- return prevOptions.filter(function (prevOption) {
433
- return prevOption.order !== _targetOptionId;
434
- });
435
- });
436
- setAnswerList(function (prevAnswerList) {
437
- return prevAnswerList.map(function (prevAnswer, prevAnswerIndex) {
438
- var _a, _b;
439
- if (index === prevAnswerIndex) {
440
- return {
441
- order: _targetOptionId,
442
- value: (_b = (_a = optionList.find(function (option) {
443
- return option.order === _targetOptionId;
444
- })) === null || _a === void 0 ? void 0 : _a.value) !== null && _b !== void 0 ? _b : ''
445
- };
446
- } else {
447
- return prevAnswer;
448
- }
449
- });
450
- });
451
- }
452
- }
453
- }, index);
517
+ indexOrder: index + 1
518
+ }, "quiz-dummy-".concat(index));
454
519
  } else {
455
520
  return jsx(QuizDraggbleDroppedOption, {
456
- id: option.order.toString(),
521
+ id: "option-answer-".concat(index),
457
522
  content: option.value,
458
523
  role: getRole(),
459
524
  disabled: !!userId,
460
525
  indexOrder: index + 1,
461
526
  isMarkdown: !!(course === null || course === void 0 ? void 0 : course.preference.renderMarkdownInQuizOptions)
462
- }, index);
527
+ }, "option-answer-".concat(index));
463
528
  }
464
529
  })
465
530
  });
466
531
  };
532
+ //
533
+ //
534
+ //
467
535
  return jsx(QuestionBox, {
468
536
  title: materialQuiz === null || materialQuiz === void 0 ? void 0 : materialQuiz.questionTitle,
469
537
  titlePrefix: "Q.",
@@ -500,47 +568,52 @@ var MaterialQuizSelectMultipleOrder = function MaterialQuizSelectMultipleOrder(_
500
568
  children: jsx(MaterialQuizInfo, {
501
569
  renderWithBox: false
502
570
  })
503
- }), jsxs("div", {
504
- id: MATERIAL_QUIZ_ANSWER_ID,
505
- children: [jsxs(StyledOptionBox, {
506
- ref: optionBoxRef,
507
- vertical: vertical,
508
- children: [renderQuizDragOption(), jsx(StyledVerticalDivider, {
571
+ }), jsx(DndContext, {
572
+ sensors: sensors,
573
+ onDragEnd: handleDragEnd,
574
+ children: jsxs("div", {
575
+ id: MATERIAL_QUIZ_ANSWER_ID,
576
+ children: [jsxs(StyledOptionBox, {
577
+ ref: optionBoxRef,
509
578
  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'
579
+ children: [renderQuizDragOption(), jsx(StyledVerticalDivider, {
580
+ vertical: vertical,
581
+ children: jsx(Icon, {
582
+ size: "elephant",
583
+ icon: eilSortItem,
584
+ rotate: 90,
585
+ style: {
586
+ color: base.color.navy3
587
+ }
530
588
  })
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, {})]
589
+ }), jsx(StyledHorizontalDivider, {
590
+ vertical: vertical
591
+ }), renderQuizDragAnswers()]
592
+ }), !!userId ? jsx(Flex, {
593
+ margintop: "1rem",
594
+ column: true,
595
+ children: jsxs(StyledQuizOptionsDropZone, {
596
+ id: "quiz-answers-dropzone",
597
+ disabled: true,
598
+ children: [jsx(Text, {
599
+ role: "white",
600
+ size: "small",
601
+ children: intl.formatMessage({
602
+ id: 'materialQuiz.answer'
603
+ })
604
+ }), correctAnswerList.map(function (correctAnswer, index) {
605
+ return jsx(QuizDraggbleDroppedOption, {
606
+ id: "option-answer-".concat(index),
607
+ content: correctAnswer.value,
608
+ disabled: true,
609
+ role: "correct",
610
+ indexOrder: index + 1,
611
+ isMarkdown: !!(course === null || course === void 0 ? void 0 : course.preference.renderMarkdownInQuizOptions)
612
+ }, "dropped-option-answer-".concat(index));
613
+ })]
614
+ })
615
+ }) : null, jsx(MaterialQuizAnswerExplanation, {})]
616
+ })
544
617
  })]
545
618
  })
546
619
  });
@@ -8,8 +8,9 @@ import { useTheme, Stack } from '@mui/material';
8
8
  import { MATERIAL_QUIZ_PASSIVE_ID, MATERIAL_QUIZ_ANSWER_ID } from '../../constant/element.js';
9
9
  import { checkUserLectureTestEnded, getOptionStatus, getQuizResult } from '../../helpers/index.js';
10
10
  import { useCaculatePassage } from '../../hooks/useCaculatePassage.js';
11
- import '../shared/QuizDraggbleOption.js';
11
+ import '../shared/QuizDraggbleDroppedOption.js';
12
12
  import '../shared/QuizDraggbleDummyOption.js';
13
+ import '../shared/QuizDraggbleOption.js';
13
14
  import QuestionRadio from '../shared/question-radio/QuestionRadio.js';
14
15
  import QuestionRadioOption from '../shared/question-radio/QuestionRadioOption.js';
15
16
  import '../shared/question-checkbox/QuestionCheckbox.js';
@@ -1,5 +1,6 @@
1
- import { jsxs, jsx } from 'react/jsx-runtime';
1
+ import { jsx, jsxs } from 'react/jsx-runtime';
2
2
  import React from 'react';
3
+ import { useSensors, useSensor, MouseSensor, TouchSensor, DndContext } from '@dnd-kit/core';
3
4
  import { Flex, Button, Vspace, Text, Icon } from '@elice/blocks';
4
5
  import { base } from '@elice/design-tokens';
5
6
  import { eilSortItem } from '@elice/icons';
@@ -10,7 +11,13 @@ import { useMaterialQuizState } from '../context/MaterialQuizContext.js';
10
11
  import QuizGroupContext from './context/context.js';
11
12
  import MaterialQuizGroupOptionItem from './MaterialQuizGroupOptionItem.js';
12
13
 
14
+ //
15
+ //
16
+ //
13
17
  var QUIZ_OPTIONS_CONTENT_WIDTH = 534;
18
+ //
19
+ //
20
+ //
14
21
  var StyledQuizAnswerWrapper = styled.div.withConfig({
15
22
  componentId: "sc-18trt81-0"
16
23
  })(["display:flex;flex-direction:column;flex:0 0 calc((100% - ", "px) / 2);"], QUIZ_OPTIONS_CONTENT_WIDTH);
@@ -32,6 +39,9 @@ var StyledQuizOptions = styled.div.withConfig({
32
39
  var StyledQuizOptionsDropzone = styled(EbDroppable).withConfig({
33
40
  componentId: "sc-18trt81-4"
34
41
  })(["display:flex;flex-wrap:wrap;gap:1rem;min-height:10.25rem;border-radius:0.5rem;outline:1px dashed ", ";&.ui-droppable-hover{outline:1px dashed ", ";}"], base.color.navy4, base.color.gray4);
42
+ //
43
+ //
44
+ //
35
45
  var MaterialQuizGroupDesktop = function MaterialQuizGroupDesktop() {
36
46
  var intl = useRawEliceIntl();
37
47
  var _useMaterialQuizState = useMaterialQuizState(),
@@ -43,6 +53,29 @@ var MaterialQuizGroupDesktop = function MaterialQuizGroupDesktop() {
43
53
  updateCurrentAnswer = _React$useContext.updateCurrentAnswer,
44
54
  updateCurrentOption = _React$useContext.updateCurrentOption,
45
55
  handleAnswerReset = _React$useContext.handleAnswerReset;
56
+ var sensors = useSensors(useSensor(MouseSensor, {
57
+ activationConstraint: {
58
+ distance: 10
59
+ }
60
+ }), useSensor(TouchSensor, {
61
+ activationConstraint: {
62
+ delay: 50,
63
+ tolerance: 5
64
+ }
65
+ }));
66
+ /**
67
+ *
68
+ */
69
+ var handleDragEnd = function handleDragEnd(e) {
70
+ var _a, _b, _c;
71
+ if (!e.over) {
72
+ return;
73
+ }
74
+ var targetId = Number(e.active.id);
75
+ var isOverOptionZone = ((_a = e.over) === null || _a === void 0 ? void 0 : _a.id) === 'quiz-options-dropzone';
76
+ var dropzoneIndex = Number((_c = (_b = e.over) === null || _b === void 0 ? void 0 : _b.id) === null || _c === void 0 ? void 0 : _c.split('-').pop());
77
+ isOverOptionZone ? updateCurrentOption(targetId) : updateCurrentAnswer(targetId, dropzoneIndex);
78
+ };
46
79
  /**
47
80
  *
48
81
  */
@@ -72,13 +105,10 @@ var MaterialQuizGroupDesktop = function MaterialQuizGroupDesktop() {
72
105
  }), jsx(Vspace, {
73
106
  height: 1
74
107
  }), jsx(StyledQuizAnswerDropzone, {
108
+ id: "quiz-answer-dropzone-".concat(dropzoneIndex),
75
109
  accept: ".quiz-answer",
76
110
  disabled: !!userId,
77
111
  isGroupAnswer: isGroupAnswer,
78
- onDrop: function onDrop(event, ui) {
79
- var targetId = Number(ui.draggable[0].id);
80
- updateCurrentAnswer(targetId, dropzoneIndex);
81
- },
82
112
  children: isGroupAnswer ? (_b = currentAnswerList[dropzoneIndex]) === null || _b === void 0 ? void 0 : _b.map(function (answer, index) {
83
113
  return jsx(MaterialQuizGroupOptionItem, {
84
114
  option: answer
@@ -139,11 +169,8 @@ var MaterialQuizGroupDesktop = function MaterialQuizGroupDesktop() {
139
169
  }), jsx(Vspace, {
140
170
  height: 1
141
171
  }), jsx(StyledQuizOptionsDropzone, {
172
+ id: "quiz-options-dropzone",
142
173
  accept: ".quiz-answer",
143
- onDrop: function onDrop(event, ui) {
144
- var targetId = Number(ui.draggable[0].id);
145
- updateCurrentOption(targetId);
146
- },
147
174
  children: currentOptionList.length ? currentOptionList.map(function (option, index) {
148
175
  return jsx(MaterialQuizGroupOptionItem, {
149
176
  option: option
@@ -168,10 +195,14 @@ var MaterialQuizGroupDesktop = function MaterialQuizGroupDesktop() {
168
195
  //
169
196
  //
170
197
  //
171
- return jsxs(Flex, {
198
+ return jsx(Flex, {
172
199
  width: "100%",
173
200
  height: "100%",
174
- children: [renderQuizContentLeft(), renderQuizContentOption(), renderQuizContentRight()]
201
+ children: jsxs(DndContext, {
202
+ sensors: sensors,
203
+ onDragEnd: handleDragEnd,
204
+ children: [renderQuizContentLeft(), renderQuizContentOption(), renderQuizContentRight()]
205
+ })
175
206
  });
176
207
  };
177
208
 
@@ -5,7 +5,7 @@ interface QuizDraggbleDroppedOptionProps {
5
5
  content: string;
6
6
  disabled: boolean;
7
7
  role: QuizDraggbleOptionRole;
8
- indexOrder?: number;
8
+ indexOrder: number;
9
9
  isMarkdown?: boolean;
10
10
  }
11
11
  declare const QuizDraggbleDroppedOption: React.FC<QuizDraggbleDroppedOptionProps>;