@tinyweb_dev/oe-exam-sdk 0.1.28 → 0.1.29

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 (796) hide show
  1. package/README.md +4 -4
  2. package/dist/api/contest-rooms.js +54 -1
  3. package/dist/api/contest-rooms.types.js +1 -1
  4. package/dist/api/exam-create.js +179 -1
  5. package/dist/api/exam-create.types.js +1 -1
  6. package/dist/api/exam-entry.js +68 -1
  7. package/dist/api/exam-entry.types.js +1 -1
  8. package/dist/api/exam-questions.js +149 -1
  9. package/dist/api/exam-questions.types.js +1 -1
  10. package/dist/api/exam-taking.js +84 -1
  11. package/dist/api/exam-taking.types.d.ts +7 -0
  12. package/dist/api/exam-taking.types.js +1 -1
  13. package/dist/api/index.js +8 -1
  14. package/dist/api/result-review.js +62 -1
  15. package/dist/api/result-review.types.js +16 -1
  16. package/dist/components/CueCardEditor.js +58 -1
  17. package/dist/components/common/ResolvedImage.js +15 -1
  18. package/dist/components/exams/CompletionDialog.js +8 -1
  19. package/dist/components/exams/CreateExamInfoForm.js +84 -1
  20. package/dist/components/exams/CreateExamPageContainer.js +110 -1
  21. package/dist/components/exams/ExamCreator.js +287 -1
  22. package/dist/components/exams/ExamPartTabs.js +138 -1
  23. package/dist/components/exams/ExamPreviewDialog.d.ts +6 -7
  24. package/dist/components/exams/ExamPreviewDialog.js +121 -1
  25. package/dist/components/exams/ExamPreviewPartContent.d.ts +18 -0
  26. package/dist/components/exams/ExamPreviewPartContent.js +27 -0
  27. package/dist/components/exams/ExamPreviewSidebar.d.ts +17 -0
  28. package/dist/components/exams/ExamPreviewSidebar.js +37 -0
  29. package/dist/components/exams/ExamQuestionGrid.js +37 -1
  30. package/dist/components/exams/ExamQuestionsPageContainer.js +112 -1
  31. package/dist/components/exams/ExamViewDialog.js +61 -1
  32. package/dist/components/exams/PartAudioUploader.js +9 -1
  33. package/dist/components/exams/TemplateSelector.js +76 -1
  34. package/dist/components/exams/UnsavedChangesDialog.js +7 -1
  35. package/dist/components/exams/api.js +3 -1
  36. package/dist/components/exams/create-exam.texts.js +1 -1
  37. package/dist/components/exams/create-exam.validation.js +18 -1
  38. package/dist/components/exams/entry/EntryRestartDialog.js +11 -1
  39. package/dist/components/exams/entry/StudentExamEntryPageContainer.js +358 -1
  40. package/dist/components/exams/entry/exam-entry.states.js +26 -1
  41. package/dist/components/exams/entry/exam-entry.utils.js +55 -1
  42. package/dist/components/exams/entry/fullscreen-loading.js +18 -1
  43. package/dist/components/exams/entry/index.js +4 -1
  44. package/dist/components/exams/exam-preview.types.d.ts +30 -0
  45. package/dist/components/exams/exam-preview.types.js +62 -0
  46. package/dist/components/exams/exam-question-status.js +45 -1
  47. package/dist/components/exams/exam-template.utils.js +18 -1
  48. package/dist/components/exams/index.d.ts +1 -0
  49. package/dist/components/exams/index.js +19 -1
  50. package/dist/components/exams/rooms/StudentContestRoomsPageContainer.js +183 -1
  51. package/dist/components/exams/rooms/contest-rooms.utils.js +93 -1
  52. package/dist/components/exams/rooms/index.js +2 -1
  53. package/dist/components/exams/take/ExamTakingApiContext.js +25 -1
  54. package/dist/components/exams/take/ExamTakingPageContainer.js +955 -1
  55. package/dist/components/exams/take/GenericQuestionRenderer.js +14 -1
  56. package/dist/components/exams/take/components/QuestionRenderer.js +207 -1
  57. package/dist/components/exams/take/components/index.js +11 -1
  58. package/dist/components/exams/take/components/question-renderers/ArticlesViewer.js +8 -1
  59. package/dist/components/exams/take/components/question-renderers/MoversAnswerTheQuestionRenderer.js +30 -1
  60. package/dist/components/exams/take/components/question-renderers/MoversChooseAdjectiveRenderer.js +63 -1
  61. package/dist/components/exams/take/components/question-renderers/MoversChooseBestAnswerRenderer.js +136 -1
  62. package/dist/components/exams/take/components/question-renderers/MoversColoringRenderer.js +379 -1
  63. package/dist/components/exams/take/components/question-renderers/MoversCrossOutWordGroupRenderer.d.ts +20 -0
  64. package/dist/components/exams/take/components/question-renderers/MoversCrossOutWordGroupRenderer.js +141 -0
  65. package/dist/components/exams/take/components/question-renderers/MoversFillWordHintRenderer.js +131 -1
  66. package/dist/components/exams/take/components/question-renderers/MoversGridFillRenderer.js +76 -1
  67. package/dist/components/exams/take/components/question-renderers/MoversLabelThePictureRenderer.js +68 -1
  68. package/dist/components/exams/take/components/question-renderers/MoversListenAndWriteRenderer.js +42 -1
  69. package/dist/components/exams/take/components/question-renderers/MoversMatchByWritingAnswerRenderer.js +131 -1
  70. package/dist/components/exams/take/components/question-renderers/MoversPictureChooseRenderer.js +76 -1
  71. package/dist/components/exams/take/components/question-renderers/MoversPictureFillBlankChooseRenderer.js +68 -1
  72. package/dist/components/exams/take/components/question-renderers/MoversReadingPassageRenderer.js +62 -1
  73. package/dist/components/exams/take/components/question-renderers/MoversTrueFalseRenderer.d.ts +1 -1
  74. package/dist/components/exams/take/components/question-renderers/MoversTrueFalseRenderer.js +51 -1
  75. package/dist/components/exams/take/components/question-renderers/MoversWordFillParagraphRenderer.js +171 -1
  76. package/dist/components/exams/take/components/question-renderers/MoversWordFillStructuredFormRenderer.js +198 -1
  77. package/dist/components/exams/take/components/question-renderers/MoversWordOrderAndMatchGroupRenderer.d.ts +15 -0
  78. package/dist/components/exams/take/components/question-renderers/MoversWordOrderAndMatchGroupRenderer.js +36 -0
  79. package/dist/components/exams/take/components/question-renderers/MoversWordOrderingRenderer.js +92 -1
  80. package/dist/components/exams/take/components/question-renderers/MoversWriteSentencesRenderer.js +11 -1
  81. package/dist/components/exams/take/components/question-renderers/MoversWritingRenderer.js +56 -1
  82. package/dist/components/exams/take/components/question-renderers/index.d.ts +2 -0
  83. package/dist/components/exams/take/components/question-renderers/index.js +25 -1
  84. package/dist/components/exams/take/components/speaking/SpeakingAudioPlayer.js +85 -1
  85. package/dist/components/exams/take/components/speaking/SpeakingContentFrame.js +10 -1
  86. package/dist/components/exams/take/components/speaking/SpeakingExamLayout.js +15 -1
  87. package/dist/components/exams/take/components/speaking/SpeakingHeader.js +6 -1
  88. package/dist/components/exams/take/components/speaking/SpeakingInstructionBar.js +8 -1
  89. package/dist/components/exams/take/components/speaking/SpeakingMicButton.js +59 -1
  90. package/dist/components/exams/take/components/speaking/SpeakingNavButton.js +7 -1
  91. package/dist/components/exams/take/components/speaking/SpeakingPartBadge.js +5 -1
  92. package/dist/components/exams/take/components/speaking/SpeakingReadDisplayedContent.module.css +120 -0
  93. package/dist/components/exams/take/components/speaking/SpeakingRecordingPreview.js +73 -1
  94. package/dist/components/exams/take/components/speaking/SpeakingReportErrorButton.js +8 -1
  95. package/dist/components/exams/take/components/speaking/SpeakingSpontaneousQA.module.css +344 -0
  96. package/dist/components/exams/take/components/speaking/SpeakingVideoIntro.js +32 -1
  97. package/dist/components/exams/take/components/speaking/index.js +1 -1
  98. package/dist/components/exams/take/components/speaking/renderers/SpeakingChooseAnswerGroupRenderer.js +63 -1
  99. package/dist/components/exams/take/components/speaking/renderers/SpeakingChooseObjectsRenderer.js +95 -1
  100. package/dist/components/exams/take/components/speaking/renderers/SpeakingCompareImagesRenderer.js +35 -1
  101. package/dist/components/exams/take/components/speaking/renderers/SpeakingConversationRenderer.js +147 -1
  102. package/dist/components/exams/take/components/speaking/renderers/SpeakingCueCardRenderer.js +232 -1
  103. package/dist/components/exams/take/components/speaking/renderers/SpeakingDescribeImageRenderer.js +193 -1
  104. package/dist/components/exams/take/components/speaking/renderers/SpeakingDragObjectsRenderer.js +155 -1
  105. package/dist/components/exams/take/components/speaking/renderers/SpeakingGNInterviewRenderer.js +212 -1
  106. package/dist/components/exams/take/components/speaking/renderers/SpeakingInfoExchangeRenderer.js +77 -1
  107. package/dist/components/exams/take/components/speaking/renderers/SpeakingListenAndSpeakAnswerRenderer.js +64 -1
  108. package/dist/components/exams/take/components/speaking/renderers/SpeakingOddOneOutRenderer.js +69 -1
  109. package/dist/components/exams/take/components/speaking/renderers/SpeakingQuestionListRenderer.js +64 -1
  110. package/dist/components/exams/take/components/speaking/renderers/SpeakingQuestionRenderer.js +92 -1
  111. package/dist/components/exams/take/components/speaking/renderers/SpeakingReadDisplayedContentRenderer.js +202 -1
  112. package/dist/components/exams/take/components/speaking/renderers/SpeakingSpontaneousQARenderer.js +339 -1
  113. package/dist/components/exams/take/components/speaking/renderers/SpeakingSpontaneousQaGroupRenderer.d.ts +19 -0
  114. package/dist/components/exams/take/components/speaking/renderers/SpeakingSpontaneousQaGroupRenderer.js +76 -0
  115. package/dist/components/exams/take/components/speaking/renderers/SpeakingStoryImagesRenderer.js +56 -1
  116. package/dist/components/exams/take/components/speaking/renderers/SpontaneousQACambridgeLayout.d.ts +24 -0
  117. package/dist/components/exams/take/components/speaking/renderers/SpontaneousQACambridgeLayout.js +120 -0
  118. package/dist/components/exams/take/components/speaking/renderers/SpontaneousQAInlineAudioPlayer.d.ts +8 -0
  119. package/dist/components/exams/take/components/speaking/renderers/SpontaneousQAInlineAudioPlayer.js +94 -0
  120. package/dist/components/exams/take/components/speaking/renderers/SpontaneousQASummerSkyAudioPlayer.d.ts +8 -0
  121. package/dist/components/exams/take/components/speaking/renderers/SpontaneousQASummerSkyAudioPlayer.js +101 -0
  122. package/dist/components/exams/take/components/speaking/renderers/index.d.ts +1 -0
  123. package/dist/components/exams/take/components/speaking/renderers/index.js +14 -1
  124. package/dist/components/exams/take/exam-taking.utils.d.ts +13 -0
  125. package/dist/components/exams/take/exam-taking.utils.js +203 -1
  126. package/dist/components/exams/take/hooks/index.js +2 -1
  127. package/dist/components/exams/take/hooks/useAnswerAutosave.js +71 -1
  128. package/dist/components/exams/take/hooks/useAttemptSubmit.js +38 -1
  129. package/dist/components/exams/take/hooks/useAutoSave.js +83 -1
  130. package/dist/components/exams/take/hooks/useExamCountdown.js +35 -1
  131. package/dist/components/exams/take/hooks/useExamTimer.js +97 -1
  132. package/dist/components/exams/take/hooks/useProctoringCamera.js +118 -1
  133. package/dist/components/exams/take/hooks/useProctoringSnapshot.js +76 -1
  134. package/dist/components/exams/take/hooks/useSpeakingConversationAudio.js +178 -1
  135. package/dist/components/exams/take/hooks/useSpeakingNavigation.js +51 -1
  136. package/dist/components/exams/take/hooks/useSpeakingRecorder.js +406 -1
  137. package/dist/components/exams/take/hooks/useSpeakingRendererSetup.js +136 -1
  138. package/dist/components/exams/take/hooks/useSpontaneousQaGroupRecorder.d.ts +11 -0
  139. package/dist/components/exams/take/hooks/useSpontaneousQaGroupRecorder.js +352 -0
  140. package/dist/components/exams/take/hooks/useSpontaneousQaGroupRendererSetup.d.ts +42 -0
  141. package/dist/components/exams/take/hooks/useSpontaneousQaGroupRendererSetup.js +166 -0
  142. package/dist/components/exams/take/hooks/useToeicAudio.js +35 -1
  143. package/dist/components/exams/take/index.js +6 -1
  144. package/dist/components/exams/take/types/speaking-cue-card.types.js +1 -1
  145. package/dist/components/exams/take/types/speaking.types.js +7 -1
  146. package/dist/components/exams/take/types.js +4 -1
  147. package/dist/components/exams/take/utils/answer-transformers.js +452 -1
  148. package/dist/components/exams/take/utils/cambridge-yle-inline-speaking.d.ts +21 -0
  149. package/dist/components/exams/take/utils/cambridge-yle-inline-speaking.js +44 -0
  150. package/dist/components/exams/take/utils/coloring-assignments.js +40 -1
  151. package/dist/components/exams/take/utils/cross-out-word-group.transformer.d.ts +21 -0
  152. package/dist/components/exams/take/utils/cross-out-word-group.transformer.js +83 -0
  153. package/dist/components/exams/take/utils/question-transformers.d.ts +43 -2
  154. package/dist/components/exams/take/utils/question-transformers.js +1137 -1
  155. package/dist/components/features/exam-entry/entry-state-cards.js +19 -1
  156. package/dist/components/features/exam-entry/index.js +2 -1
  157. package/dist/components/features/exam-entry/themed/CambridgeYleWaitingRoom.js +121 -1
  158. package/dist/components/features/exam-entry/themed/ThemedWaitingRoom.js +37 -1
  159. package/dist/components/features/exam-entry/themed/ToeicWaitingRoom.js +15 -1
  160. package/dist/components/features/exam-entry/themed/cambridge-yle-waiting-parts.js +80 -1
  161. package/dist/components/features/exam-entry/themed/components/CloseButton.js +6 -1
  162. package/dist/components/features/exam-entry/themed/components/ExamInfoPanel.js +17 -1
  163. package/dist/components/features/exam-entry/themed/components/ModeSelector.js +6 -1
  164. package/dist/components/features/exam-entry/themed/components/StartButton.js +12 -1
  165. package/dist/components/features/exam-entry/themed/components/index.js +4 -1
  166. package/dist/components/features/exam-entry/themed/index.js +3 -1
  167. package/dist/components/index.d.ts +1 -0
  168. package/dist/components/index.js +43 -1
  169. package/dist/components/questions/_shared/config/question-types.config.js +362 -1
  170. package/dist/components/questions/_shared/constants/color-palette.js +21 -1
  171. package/dist/components/questions/_shared/hooks/useAnswerGroupQuestionGroup.js +105 -1
  172. package/dist/components/questions/_shared/hooks/useBasicQuestionGroup.js +222 -1
  173. package/dist/components/questions/_shared/hooks/useCompareImagesGroup.js +140 -1
  174. package/dist/components/questions/_shared/hooks/useImageQuestionGroup.js +123 -1
  175. package/dist/components/questions/_shared/hooks/useInfoExchangeGroup.js +50 -1
  176. package/dist/components/questions/_shared/hooks/useQuestionFormState.js +54 -1
  177. package/dist/components/questions/_shared/hooks/useQuestionInitialization.js +123 -1
  178. package/dist/components/questions/_shared/hooks/useQuestionListGroup.js +121 -1
  179. package/dist/components/questions/_shared/hooks/useQuestionOnChange.js +70 -1
  180. package/dist/components/questions/_shared/hooks/useSceneQuestionGroup.js +194 -1
  181. package/dist/components/questions/_shared/index.js +7 -1
  182. package/dist/components/questions/_shared/types/answer-the-question.type.js +1 -1
  183. package/dist/components/questions/_shared/types/arrange-letters-into-words.type.js +1 -1
  184. package/dist/components/questions/_shared/types/choose-correct-adjective.type.js +3 -1
  185. package/dist/components/questions/_shared/types/choose-the-correct-answer-group.type.d.ts +1 -0
  186. package/dist/components/questions/_shared/types/choose-the-correct-answer-group.type.js +1 -1
  187. package/dist/components/questions/_shared/types/color-region.config.js +1 -1
  188. package/dist/components/questions/_shared/types/cross-out-word-group.type.d.ts +2 -0
  189. package/dist/components/questions/_shared/types/cross-out-word-group.type.js +1 -1
  190. package/dist/components/questions/_shared/types/fill-in-blank.type.js +1 -1
  191. package/dist/components/questions/_shared/types/fill-missing-words-in-grid.type.js +1 -1
  192. package/dist/components/questions/_shared/types/gn-speaking-interview.type.js +1 -1
  193. package/dist/components/questions/_shared/types/index.d.ts +1 -0
  194. package/dist/components/questions/_shared/types/index.js +14 -1
  195. package/dist/components/questions/_shared/types/label-the-picture.type.js +1 -1
  196. package/dist/components/questions/_shared/types/listen-and-choose-from-answer-group.type.js +1 -1
  197. package/dist/components/questions/_shared/types/listen-and-choose-objects-in-scene.type.js +1 -1
  198. package/dist/components/questions/_shared/types/listen-and-drag-objects-into-scene.type.js +1 -1
  199. package/dist/components/questions/_shared/types/listen-and-speak-answer.type.js +1 -1
  200. package/dist/components/questions/_shared/types/listen-and-speak-compare-images.type.js +1 -1
  201. package/dist/components/questions/_shared/types/listen-and-speak-image-group.type.js +1 -1
  202. package/dist/components/questions/_shared/types/listen-and-speak-info-exchange.type.js +1 -1
  203. package/dist/components/questions/_shared/types/listen-and-speak-odd-one-out.type.js +3 -1
  204. package/dist/components/questions/_shared/types/listen-and-speak-question-list.type.js +1 -1
  205. package/dist/components/questions/_shared/types/listen-and-speak-with-story-images.type.js +3 -1
  206. package/dist/components/questions/_shared/types/listen-and-tick-answer.type.js +1 -1
  207. package/dist/components/questions/_shared/types/listening-drawline.type.js +1 -1
  208. package/dist/components/questions/_shared/types/look-and-choose-answer.type.js +1 -1
  209. package/dist/components/questions/_shared/types/look-picture-fill-word-hint.type.js +1 -1
  210. package/dist/components/questions/_shared/types/match-by-writing-answer.type.js +1 -1
  211. package/dist/components/questions/_shared/types/multiple-choice.type.d.ts +5 -0
  212. package/dist/components/questions/_shared/types/multiple-choice.type.js +1 -1
  213. package/dist/components/questions/_shared/types/question-group.type.js +11 -1
  214. package/dist/components/questions/_shared/types/read-and-color-objects.type.js +1 -1
  215. package/dist/components/questions/_shared/types/read-displayed-content.type.js +1 -1
  216. package/dist/components/questions/_shared/types/read-passage-and-answer-questions.type.js +1 -1
  217. package/dist/components/questions/_shared/types/speaking-describe-image.type.js +1 -1
  218. package/dist/components/questions/_shared/types/spontaneous-qa-group.type.d.ts +37 -0
  219. package/dist/components/questions/_shared/types/spontaneous-qa-group.type.js +1 -0
  220. package/dist/components/questions/_shared/types/spontaneous-qa.type.js +1 -1
  221. package/dist/components/questions/_shared/types/true-false-group.type.js +1 -1
  222. package/dist/components/questions/_shared/types/word-fill-paragraph-with-options.type.js +1 -1
  223. package/dist/components/questions/_shared/types/word-fill-paragraph.type.js +1 -1
  224. package/dist/components/questions/_shared/types/word-fill-structured-form.type.d.ts +20 -11
  225. package/dist/components/questions/_shared/types/word-fill-structured-form.type.js +1 -1
  226. package/dist/components/questions/_shared/types/word-order-and-match-group.type.d.ts +38 -0
  227. package/dist/components/questions/_shared/types/word-order-and-match-group.type.js +1 -0
  228. package/dist/components/questions/_shared/types/word-ordering.type.js +1 -1
  229. package/dist/components/questions/_shared/types/write-a-short-letter.type.js +1 -1
  230. package/dist/components/questions/_shared/types/write-correct-verb-form.type.js +3 -1
  231. package/dist/components/questions/_shared/types/write-sentences.type.js +1 -1
  232. package/dist/components/questions/_shared/types/write-short-paragraph.type.js +1 -1
  233. package/dist/components/questions/_shared/utils/answer-builder.js +79 -1
  234. package/dist/components/questions/_shared/utils/createColorRegionRegistration.js +39 -1
  235. package/dist/components/questions/_shared/utils/id-generator.js +3 -1
  236. package/dist/components/questions/_shared/utils/parseFillBlankStem.d.ts +30 -0
  237. package/dist/components/questions/_shared/utils/parseFillBlankStem.js +69 -0
  238. package/dist/components/questions/_shared/utils/question-validation.js +21 -1
  239. package/dist/components/questions/components/ColorNode.js +85 -1
  240. package/dist/components/questions/components/ColorRegionClient.js +545 -1
  241. package/dist/components/questions/components/ColorRegionCreator.js +420 -1
  242. package/dist/components/questions/components/ColorRegionNode.js +59 -1
  243. package/dist/components/questions/components/CreatorGuide.js +103 -1
  244. package/dist/components/questions/components/NameNode.js +26 -1
  245. package/dist/components/questions/components/QuestionBankOption.js +46 -1
  246. package/dist/components/questions/components/QuestionBasicInfoForm.js +9 -1
  247. package/dist/components/questions/components/QuestionCommonFields.js +33 -1
  248. package/dist/components/questions/components/QuestionSearchDropdown.js +258 -1
  249. package/dist/components/questions/components/QuestionTypeSelector.js +32 -1
  250. package/dist/components/questions/components/QuestionTypeSpecificForms.js +6 -1
  251. package/dist/components/questions/components/RegionNode.js +94 -1
  252. package/dist/components/questions/components/index.js +14 -1
  253. package/dist/components/questions/creator/QuestionCreator.js +90 -1
  254. package/dist/components/questions/creator/QuestionGroupCreator.js +119 -1
  255. package/dist/components/questions/creator/dedicated-component-router.js +79 -1
  256. package/dist/components/questions/creator/index.js +3 -1
  257. package/dist/components/questions/creator/question-type-registry.js +90 -1
  258. package/dist/components/questions/groups/ArticlesGroupCard.js +121 -1
  259. package/dist/components/questions/groups/BasicQuestionGroupCard.js +50 -1
  260. package/dist/components/questions/groups/DocumentGroupCard.js +114 -1
  261. package/dist/components/questions/groups/MatchAnswerGroupCard.js +25 -1
  262. package/dist/components/questions/index.d.ts +1 -0
  263. package/dist/components/questions/index.js +11 -1
  264. package/dist/components/questions/question-bank/EditQuestionBankDialog.d.ts +2 -0
  265. package/dist/components/questions/question-bank/EditQuestionBankDialog.js +114 -0
  266. package/dist/components/questions/question-bank/QuestionEditorRenderer.d.ts +23 -0
  267. package/dist/components/questions/question-bank/QuestionEditorRenderer.js +75 -0
  268. package/dist/components/questions/question-bank/difficulty.d.ts +15 -0
  269. package/dist/components/questions/question-bank/difficulty.js +33 -0
  270. package/dist/components/questions/question-bank/editor-adapters/choice-adapters.d.ts +5 -0
  271. package/dist/components/questions/question-bank/editor-adapters/choice-adapters.js +101 -0
  272. package/dist/components/questions/question-bank/editor-adapters/index.d.ts +5 -0
  273. package/dist/components/questions/question-bank/editor-adapters/index.js +4 -0
  274. package/dist/components/questions/question-bank/editor-adapters/media-adapters.d.ts +6 -0
  275. package/dist/components/questions/question-bank/editor-adapters/media-adapters.js +140 -0
  276. package/dist/components/questions/question-bank/editor-adapters/types.d.ts +1 -0
  277. package/dist/components/questions/question-bank/editor-adapters/types.js +1 -0
  278. package/dist/components/questions/question-bank/editor-adapters/unsupported-fallback.d.ts +8 -0
  279. package/dist/components/questions/question-bank/editor-adapters/unsupported-fallback.js +6 -0
  280. package/dist/components/questions/question-bank/editor-adapters/writing-adapters.d.ts +5 -0
  281. package/dist/components/questions/question-bank/editor-adapters/writing-adapters.js +114 -0
  282. package/dist/components/questions/question-bank/index.d.ts +4 -0
  283. package/dist/components/questions/question-bank/index.js +3 -0
  284. package/dist/components/questions/question-bank/types.d.ts +59 -0
  285. package/dist/components/questions/question-bank/types.js +1 -0
  286. package/dist/components/questions/types/answer-the-question/AnswerTheQuestionClient.js +37 -1
  287. package/dist/components/questions/types/answer-the-question/AnswerTheQuestionCreator.js +351 -1
  288. package/dist/components/questions/types/answer-the-question/register.js +67 -1
  289. package/dist/components/questions/types/answer-the-question/transform.js +36 -1
  290. package/dist/components/questions/types/arrange-letters-into-words/ArrangeLettersIntoWordsClient.js +141 -1
  291. package/dist/components/questions/types/arrange-letters-into-words/ArrangeLettersIntoWordsCreator.js +118 -1
  292. package/dist/components/questions/types/arrange-letters-into-words/index.js +2 -1
  293. package/dist/components/questions/types/arrange-letters-into-words/register.js +4 -1
  294. package/dist/components/questions/types/arrange-letters-into-words/transform.js +24 -1
  295. package/dist/components/questions/types/choose-correct-adjective/ChooseCorrectAdjectiveClient.js +74 -1
  296. package/dist/components/questions/types/choose-correct-adjective/ChooseCorrectAdjectiveCreator.js +169 -1
  297. package/dist/components/questions/types/choose-correct-adjective/index.js +2 -1
  298. package/dist/components/questions/types/choose-correct-adjective/register.js +55 -1
  299. package/dist/components/questions/types/choose-correct-adjective/transform.js +16 -1
  300. package/dist/components/questions/types/choose-the-correct-answer/ChooseTheCorrectAnswerClient.js +149 -1
  301. package/dist/components/questions/types/choose-the-correct-answer/ChooseTheCorrectAnswerCreator.js +568 -1
  302. package/dist/components/questions/types/choose-the-correct-answer/index.js +3 -1
  303. package/dist/components/questions/types/choose-the-correct-answer/normalize.d.ts +9 -0
  304. package/dist/components/questions/types/choose-the-correct-answer/normalize.js +88 -1
  305. package/dist/components/questions/types/choose-the-correct-answer/register.js +99 -1
  306. package/dist/components/questions/types/choose-the-correct-answer/transform.js +70 -1
  307. package/dist/components/questions/types/choose-the-correct-answer-group/ChooseTheCorrectAnswerGroupClient.js +22 -1
  308. package/dist/components/questions/types/choose-the-correct-answer-group/ChooseTheCorrectAnswerGroupCreator.js +163 -1
  309. package/dist/components/questions/types/choose-the-correct-answer-group/index.js +3 -1
  310. package/dist/components/questions/types/choose-the-correct-answer-group/map-choose-the-correct-answer-group-data.js +94 -1
  311. package/dist/components/questions/types/choose-the-correct-answer-group/register.js +36 -1
  312. package/dist/components/questions/types/choose-the-correct-answer-group/transform.js +55 -1
  313. package/dist/components/questions/types/cross-out-word-group/CrossOutWordGroupClient.js +27 -1
  314. package/dist/components/questions/types/cross-out-word-group/CrossOutWordGroupCreator.js +231 -1
  315. package/dist/components/questions/types/cross-out-word-group/index.js +5 -1
  316. package/dist/components/questions/types/cross-out-word-group/map-cross-out-word-group-data.d.ts +1 -1
  317. package/dist/components/questions/types/cross-out-word-group/map-cross-out-word-group-data.js +110 -1
  318. package/dist/components/questions/types/cross-out-word-group/register.js +36 -1
  319. package/dist/components/questions/types/cross-out-word-group/transform.js +67 -1
  320. package/dist/components/questions/types/fill-in-blank/FillInBlankClient.js +275 -1
  321. package/dist/components/questions/types/fill-in-blank/FillInBlankCreator.js +464 -1
  322. package/dist/components/questions/types/fill-in-blank/index.js +2 -1
  323. package/dist/components/questions/types/fill-in-blank/register.js +148 -1
  324. package/dist/components/questions/types/fill-in-blank/transform.js +88 -1
  325. package/dist/components/questions/types/fill-missing-words-in-grid/FillMissingWordsInGridClient.js +117 -1
  326. package/dist/components/questions/types/fill-missing-words-in-grid/FillMissingWordsInGridCreator.js +671 -1
  327. package/dist/components/questions/types/fill-missing-words-in-grid/index.js +2 -1
  328. package/dist/components/questions/types/fill-missing-words-in-grid/register.js +37 -1
  329. package/dist/components/questions/types/fill-missing-words-in-grid/transform.js +15 -1
  330. package/dist/components/questions/types/gn-speaking-interview/GNSpeakingInterviewCreator.js +262 -1
  331. package/dist/components/questions/types/gn-speaking-interview/register.js +121 -1
  332. package/dist/components/questions/types/gn-speaking-interview/transform.js +48 -1
  333. package/dist/components/questions/types/image-object-matching/ImageObjectMatchingClient.js +16 -1
  334. package/dist/components/questions/types/image-object-matching/ImageObjectMatchingCreator.js +27 -1
  335. package/dist/components/questions/types/image-object-matching/index.js +2 -1
  336. package/dist/components/questions/types/image-object-matching/register.js +3 -1
  337. package/dist/components/questions/types/image-object-matching/transform.js +2 -1
  338. package/dist/components/questions/types/label-the-picture/LabelThePictureClient.js +102 -1
  339. package/dist/components/questions/types/label-the-picture/LabelThePictureCreator.js +344 -1
  340. package/dist/components/questions/types/label-the-picture/index.js +2 -1
  341. package/dist/components/questions/types/label-the-picture/register.js +54 -1
  342. package/dist/components/questions/types/label-the-picture/transform.js +28 -1
  343. package/dist/components/questions/types/listen-and-choose-from-answer-group/ListenAndChooseFromAnswerGroupClient.js +78 -1
  344. package/dist/components/questions/types/listen-and-choose-from-answer-group/ListenAndChooseFromAnswerGroupCreator.js +232 -1
  345. package/dist/components/questions/types/listen-and-choose-from-answer-group/index.js +2 -1
  346. package/dist/components/questions/types/listen-and-choose-from-answer-group/register.js +82 -1
  347. package/dist/components/questions/types/listen-and-choose-from-answer-group/transform.js +27 -1
  348. package/dist/components/questions/types/listen-and-choose-objects-in-scene/ListenAndChooseObjectsInSceneClient.js +70 -1
  349. package/dist/components/questions/types/listen-and-choose-objects-in-scene/ListenAndChooseObjectsInSceneCreator.js +386 -1
  350. package/dist/components/questions/types/listen-and-choose-objects-in-scene/index.js +2 -1
  351. package/dist/components/questions/types/listen-and-choose-objects-in-scene/register.js +100 -1
  352. package/dist/components/questions/types/listen-and-choose-objects-in-scene/transform.js +33 -1
  353. package/dist/components/questions/types/listen-and-drag-objects-into-scene/ListenAndDragObjectsIntoSceneClient.js +106 -1
  354. package/dist/components/questions/types/listen-and-drag-objects-into-scene/ListenAndDragObjectsIntoSceneCreator.js +457 -1
  355. package/dist/components/questions/types/listen-and-drag-objects-into-scene/index.js +2 -1
  356. package/dist/components/questions/types/listen-and-drag-objects-into-scene/register.js +110 -1
  357. package/dist/components/questions/types/listen-and-drag-objects-into-scene/transform.js +35 -1
  358. package/dist/components/questions/types/listen-and-speak-answer/ArrowIndicator.js +8 -1
  359. package/dist/components/questions/types/listen-and-speak-answer/ListenAndSpeakAnswerClient.js +22 -1
  360. package/dist/components/questions/types/listen-and-speak-answer/ListenAndSpeakAnswerCreator.js +291 -1
  361. package/dist/components/questions/types/listen-and-speak-answer/index.js +2 -1
  362. package/dist/components/questions/types/listen-and-speak-answer/register.js +84 -1
  363. package/dist/components/questions/types/listen-and-speak-answer/transform.js +27 -1
  364. package/dist/components/questions/types/listen-and-speak-compare-images/ListenAndSpeakCompareImagesClient.js +32 -1
  365. package/dist/components/questions/types/listen-and-speak-compare-images/ListenAndSpeakCompareImagesCreator.js +295 -1
  366. package/dist/components/questions/types/listen-and-speak-compare-images/register.js +79 -1
  367. package/dist/components/questions/types/listen-and-speak-compare-images/transform.js +27 -1
  368. package/dist/components/questions/types/listen-and-speak-image-group/ListenAndSpeakImageGroupClient.js +34 -1
  369. package/dist/components/questions/types/listen-and-speak-image-group/ListenAndSpeakImageGroupCreator.js +285 -1
  370. package/dist/components/questions/types/listen-and-speak-image-group/register.js +81 -1
  371. package/dist/components/questions/types/listen-and-speak-image-group/transform.js +26 -1
  372. package/dist/components/questions/types/listen-and-speak-info-exchange/ListenAndSpeakInfoExchangeClient.js +38 -1
  373. package/dist/components/questions/types/listen-and-speak-info-exchange/ListenAndSpeakInfoExchangeCreator.js +385 -1
  374. package/dist/components/questions/types/listen-and-speak-info-exchange/register.js +87 -1
  375. package/dist/components/questions/types/listen-and-speak-info-exchange/transform.js +32 -1
  376. package/dist/components/questions/types/listen-and-speak-odd-one-out/ListenAndSpeakOddOneOutClient.js +26 -1
  377. package/dist/components/questions/types/listen-and-speak-odd-one-out/ListenAndSpeakOddOneOutCreator.js +247 -1
  378. package/dist/components/questions/types/listen-and-speak-odd-one-out/register.js +59 -1
  379. package/dist/components/questions/types/listen-and-speak-odd-one-out/transform.js +18 -1
  380. package/dist/components/questions/types/listen-and-speak-question-list/ListenAndSpeakQuestionListClient.js +26 -1
  381. package/dist/components/questions/types/listen-and-speak-question-list/ListenAndSpeakQuestionListCreator.js +256 -1
  382. package/dist/components/questions/types/listen-and-speak-question-list/register.js +81 -1
  383. package/dist/components/questions/types/listen-and-speak-question-list/transform.js +26 -1
  384. package/dist/components/questions/types/listen-and-speak-with-story-images/ListenAndSpeakWithStoryImagesClient.js +26 -1
  385. package/dist/components/questions/types/listen-and-speak-with-story-images/ListenAndSpeakWithStoryImagesCreator.js +230 -1
  386. package/dist/components/questions/types/listen-and-speak-with-story-images/register.js +56 -1
  387. package/dist/components/questions/types/listen-and-speak-with-story-images/transform.js +16 -1
  388. package/dist/components/questions/types/look-picture-choose-correct-answer/LookPictureChooseCorrectAnswerClient.js +72 -1
  389. package/dist/components/questions/types/look-picture-choose-correct-answer/LookPictureChooseCorrectAnswerCreator.js +230 -1
  390. package/dist/components/questions/types/look-picture-choose-correct-answer/index.js +1 -1
  391. package/dist/components/questions/types/look-picture-choose-correct-answer/register.js +66 -1
  392. package/dist/components/questions/types/look-picture-choose-correct-answer/transform.js +42 -1
  393. package/dist/components/questions/types/look-picture-fill-blank-choose-answer/LookPictureFillBlankChooseAnswerClient.js +96 -1
  394. package/dist/components/questions/types/look-picture-fill-blank-choose-answer/LookPictureFillBlankChooseAnswerCreator.js +238 -1
  395. package/dist/components/questions/types/look-picture-fill-blank-choose-answer/index.js +2 -1
  396. package/dist/components/questions/types/look-picture-fill-blank-choose-answer/register.js +76 -1
  397. package/dist/components/questions/types/look-picture-fill-blank-choose-answer/transform.js +19 -1
  398. package/dist/components/questions/types/look-picture-fill-word-hint/LookPictureFillWordHintClient.js +134 -1
  399. package/dist/components/questions/types/look-picture-fill-word-hint/LookPictureFillWordHintCreator.js +617 -1
  400. package/dist/components/questions/types/look-picture-fill-word-hint/index.js +2 -1
  401. package/dist/components/questions/types/look-picture-fill-word-hint/register.js +82 -1
  402. package/dist/components/questions/types/look-picture-fill-word-hint/transform.js +29 -1
  403. package/dist/components/questions/types/match-by-writing-answer/MatchByWritingAnswerClient.js +38 -1
  404. package/dist/components/questions/types/match-by-writing-answer/MatchByWritingAnswerCreator.js +359 -1
  405. package/dist/components/questions/types/match-by-writing-answer/index.js +3 -1
  406. package/dist/components/questions/types/match-by-writing-answer/register.js +58 -1
  407. package/dist/components/questions/types/match-by-writing-answer/transform.js +61 -1
  408. package/dist/components/questions/types/read-and-color-objects/ReadAndColorObjectsClient.js +16 -1
  409. package/dist/components/questions/types/read-and-color-objects/ReadAndColorObjectsCreator.js +23 -1
  410. package/dist/components/questions/types/read-and-color-objects/index.js +2 -1
  411. package/dist/components/questions/types/read-and-color-objects/register.js +3 -1
  412. package/dist/components/questions/types/read-and-color-objects/transform.js +36 -1
  413. package/dist/components/questions/types/read-displayed-content/ReadDisplayedContentCreator.js +125 -1
  414. package/dist/components/questions/types/read-displayed-content/register.js +64 -1
  415. package/dist/components/questions/types/read-displayed-content/transform.js +12 -1
  416. package/dist/components/questions/types/read-passage-and-answer-questions/ReadPassageAndAnswerQuestionsClient.js +65 -1
  417. package/dist/components/questions/types/read-passage-and-answer-questions/ReadPassageAndAnswerQuestionsCreator.js +511 -1
  418. package/dist/components/questions/types/read-passage-and-answer-questions/index.js +2 -1
  419. package/dist/components/questions/types/read-passage-and-answer-questions/register.js +58 -1
  420. package/dist/components/questions/types/read-passage-and-answer-questions/transform.js +28 -1
  421. package/dist/components/questions/types/speaking-conversation/SpeakingConversationCreator.js +373 -1
  422. package/dist/components/questions/types/speaking-conversation/SpeakingConversationPreviewClient.js +41 -1
  423. package/dist/components/questions/types/speaking-conversation/register.js +110 -1
  424. package/dist/components/questions/types/speaking-conversation/transform.js +34 -1
  425. package/dist/components/questions/types/speaking-cue-card/SpeakingCueCardCreator.js +74 -1
  426. package/dist/components/questions/types/speaking-cue-card/register.js +52 -1
  427. package/dist/components/questions/types/speaking-cue-card/transform.js +12 -1
  428. package/dist/components/questions/types/speaking-describe-image/SpeakingDescribeImageClient.js +10 -1
  429. package/dist/components/questions/types/speaking-describe-image/SpeakingDescribeImageCreator.js +161 -1
  430. package/dist/components/questions/types/speaking-describe-image/index.js +2 -1
  431. package/dist/components/questions/types/speaking-describe-image/register.js +69 -1
  432. package/dist/components/questions/types/speaking-describe-image/transform.js +16 -1
  433. package/dist/components/questions/types/spontaneous-qa/SpontaneousQACreator.js +234 -1
  434. package/dist/components/questions/types/spontaneous-qa/register.js +93 -1
  435. package/dist/components/questions/types/spontaneous-qa/transform.js +34 -1
  436. package/dist/components/questions/types/spontaneous-qa-group/SpontaneousQaGroupClient.d.ts +2 -0
  437. package/dist/components/questions/types/spontaneous-qa-group/SpontaneousQaGroupClient.js +9 -0
  438. package/dist/components/questions/types/spontaneous-qa-group/SpontaneousQaGroupCreator.d.ts +2 -0
  439. package/dist/components/questions/types/spontaneous-qa-group/SpontaneousQaGroupCreator.js +179 -0
  440. package/dist/components/questions/types/spontaneous-qa-group/creator-helpers.d.ts +5 -0
  441. package/dist/components/questions/types/spontaneous-qa-group/creator-helpers.js +43 -0
  442. package/dist/components/questions/types/spontaneous-qa-group/flatten.d.ts +14 -0
  443. package/dist/components/questions/types/spontaneous-qa-group/flatten.js +69 -0
  444. package/dist/components/questions/types/spontaneous-qa-group/index.d.ts +2 -0
  445. package/dist/components/questions/types/spontaneous-qa-group/index.js +2 -0
  446. package/dist/components/questions/types/spontaneous-qa-group/register.d.ts +2 -0
  447. package/dist/components/questions/types/spontaneous-qa-group/register.js +139 -0
  448. package/dist/components/questions/types/spontaneous-qa-group/transform.d.ts +2 -0
  449. package/dist/components/questions/types/spontaneous-qa-group/transform.js +52 -0
  450. package/dist/components/questions/types/true-false/TrueFalseClient.js +75 -1
  451. package/dist/components/questions/types/true-false/TrueFalseCreator.js +244 -1
  452. package/dist/components/questions/types/true-false/index.js +2 -1
  453. package/dist/components/questions/types/true-false/register.js +77 -1
  454. package/dist/components/questions/types/true-false/transform.js +32 -1
  455. package/dist/components/questions/types/true-false-group/TrueFalseGroupClient.js +25 -1
  456. package/dist/components/questions/types/true-false-group/TrueFalseGroupCreator.js +129 -1
  457. package/dist/components/questions/types/true-false-group/index.js +5 -1
  458. package/dist/components/questions/types/true-false-group/map-true-false-group-data.js +69 -1
  459. package/dist/components/questions/types/true-false-group/register.js +36 -1
  460. package/dist/components/questions/types/true-false-group/transform.js +43 -1
  461. package/dist/components/questions/types/word-fill-paragraph/WordFillParagraphClient.js +233 -1
  462. package/dist/components/questions/types/word-fill-paragraph/WordFillParagraphCreator.js +631 -1
  463. package/dist/components/questions/types/word-fill-paragraph/WordFillParagraphWrapper.js +28 -1
  464. package/dist/components/questions/types/word-fill-paragraph/index.js +2 -1
  465. package/dist/components/questions/types/word-fill-paragraph/register.js +136 -1
  466. package/dist/components/questions/types/word-fill-paragraph/transform.js +56 -1
  467. package/dist/components/questions/types/word-fill-structured-form/WfsfWordBankEditor.js +86 -1
  468. package/dist/components/questions/types/word-fill-structured-form/WordFillStructuredFormClient.js +246 -1
  469. package/dist/components/questions/types/word-fill-structured-form/WordFillStructuredFormCreator.d.ts +2 -0
  470. package/dist/components/questions/types/word-fill-structured-form/WordFillStructuredFormCreator.js +484 -1
  471. package/dist/components/questions/types/word-fill-structured-form/index.js +3 -1
  472. package/dist/components/questions/types/word-fill-structured-form/map-wfsf-question-data.js +113 -1
  473. package/dist/components/questions/types/word-fill-structured-form/register.js +36 -1
  474. package/dist/components/questions/types/word-fill-structured-form/transform.js +77 -1
  475. package/dist/components/questions/types/word-fill-structured-form/wfsf-word-bank.utils.js +110 -1
  476. package/dist/components/questions/types/word-order-and-match-group/WordOrderAndMatchGroupClient.d.ts +3 -0
  477. package/dist/components/questions/types/word-order-and-match-group/WordOrderAndMatchGroupClient.js +190 -0
  478. package/dist/components/questions/types/word-order-and-match-group/WordOrderAndMatchGroupCreator.d.ts +3 -0
  479. package/dist/components/questions/types/word-order-and-match-group/WordOrderAndMatchGroupCreator.js +182 -0
  480. package/dist/components/questions/types/word-order-and-match-group/index.d.ts +4 -0
  481. package/dist/components/questions/types/word-order-and-match-group/index.js +4 -0
  482. package/dist/components/questions/types/word-order-and-match-group/register.d.ts +2 -0
  483. package/dist/components/questions/types/word-order-and-match-group/register.js +121 -0
  484. package/dist/components/questions/types/word-order-and-match-group/transform.d.ts +2 -0
  485. package/dist/components/questions/types/word-order-and-match-group/transform.js +70 -0
  486. package/dist/components/questions/types/word-ordering/WordOrderingClient.js +84 -1
  487. package/dist/components/questions/types/word-ordering/WordOrderingCreator.js +192 -1
  488. package/dist/components/questions/types/word-ordering/index.js +2 -1
  489. package/dist/components/questions/types/word-ordering/register.js +46 -1
  490. package/dist/components/questions/types/word-ordering/transform.js +24 -1
  491. package/dist/components/questions/types/write-a-short-letter/WriteAShortLetterClient.js +99 -1
  492. package/dist/components/questions/types/write-a-short-letter/WriteAShortLetterCreator.js +320 -1
  493. package/dist/components/questions/types/write-a-short-letter/index.js +2 -1
  494. package/dist/components/questions/types/write-a-short-letter/register.js +68 -1
  495. package/dist/components/questions/types/write-a-short-letter/transform.js +25 -1
  496. package/dist/components/questions/types/write-correct-verb-form/WriteCorrectVerbFormClient.js +61 -1
  497. package/dist/components/questions/types/write-correct-verb-form/WriteCorrectVerbFormCreator.js +196 -1
  498. package/dist/components/questions/types/write-correct-verb-form/index.js +2 -1
  499. package/dist/components/questions/types/write-correct-verb-form/register.js +62 -1
  500. package/dist/components/questions/types/write-correct-verb-form/transform.js +17 -1
  501. package/dist/components/questions/types/write-sentences/WriteSentencesClient.js +22 -1
  502. package/dist/components/questions/types/write-sentences/WriteSentencesCreator.js +174 -1
  503. package/dist/components/questions/types/write-sentences/index.js +2 -1
  504. package/dist/components/questions/types/write-sentences/register.js +58 -1
  505. package/dist/components/questions/types/write-sentences/transform.js +28 -1
  506. package/dist/components/questions/types/write-short-paragraph/WriteShortParagraphClient.js +96 -1
  507. package/dist/components/questions/types/write-short-paragraph/WriteShortParagraphCreator.js +161 -1
  508. package/dist/components/questions/types/write-short-paragraph/index.js +2 -1
  509. package/dist/components/questions/types/write-short-paragraph/register.js +4 -1
  510. package/dist/components/questions/types/write-short-paragraph/transform.js +21 -1
  511. package/dist/components/questions/viewer/ChooseTheCorrectAnswerGroupViewer.js +11 -1
  512. package/dist/components/questions/viewer/CrossOutWordGroupViewer.js +8 -1
  513. package/dist/components/questions/viewer/QuestionGroupViewer.js +36 -1
  514. package/dist/components/questions/viewer/QuestionViewer.js +692 -1
  515. package/dist/components/questions/viewer/SpontaneousQaGroupViewer.d.ts +2 -1
  516. package/dist/components/questions/viewer/SpontaneousQaGroupViewer.js +82 -1
  517. package/dist/components/questions/viewer/TrueFalseGroupViewer.js +11 -1
  518. package/dist/components/questions/viewer/WordFillStructuredFormViewer.js +14 -1
  519. package/dist/components/questions/viewer/WordOrderAndMatchGroupViewer.d.ts +3 -1
  520. package/dist/components/questions/viewer/WordOrderAndMatchGroupViewer.js +95 -1
  521. package/dist/components/questions/viewer/index.js +8 -1
  522. package/dist/components/results/ResultReviewPageContainer.js +220 -1
  523. package/dist/components/results/ReviewQuestionRenderer.js +55 -1
  524. package/dist/components/results/hooks/useResultReviewPolling.js +76 -1
  525. package/dist/components/results/index.js +22 -1
  526. package/dist/components/results/renderers/QuestionExplanations.js +19 -1
  527. package/dist/components/results/renderers/ReviewChooseAdjectiveRenderer.js +94 -1
  528. package/dist/components/results/renderers/ReviewChooseBestAnswerRenderer.js +75 -1
  529. package/dist/components/results/renderers/ReviewColoringRenderer.js +110 -1
  530. package/dist/components/results/renderers/ReviewListenAndWriteRenderer.js +48 -1
  531. package/dist/components/results/renderers/ReviewListenChooseAnswerGroupRenderer.js +87 -1
  532. package/dist/components/results/renderers/ReviewListenChooseObjectsRenderer.js +104 -1
  533. package/dist/components/results/renderers/ReviewListenDragObjectsRenderer.js +123 -1
  534. package/dist/components/results/renderers/ReviewListeningHeader.js +104 -1
  535. package/dist/components/results/renderers/ReviewSpeakingAIPanel.js +116 -1
  536. package/dist/components/results/renderers/ReviewSpeakingMedia.js +48 -1
  537. package/dist/components/results/renderers/ReviewSpeakingQuestionItem.js +42 -1
  538. package/dist/components/results/renderers/ReviewSpeakingRenderer.js +12 -1
  539. package/dist/components/results/renderers/ReviewSpeakingRenderer.types.js +85 -1
  540. package/dist/components/results/renderers/review-question-body-dedicated.js +104 -1
  541. package/dist/components/results/renderers/review-question-body-movers.js +148 -1
  542. package/dist/components/results/renderers/review-speaking-map.js +226 -1
  543. package/dist/components/results/renderers/review-spontaneous-qa-group.d.ts +4 -0
  544. package/dist/components/results/renderers/review-spontaneous-qa-group.js +74 -0
  545. package/dist/components/results/report/BadgeTitle.js +5 -1
  546. package/dist/components/results/report/ExamSkillRow.js +20 -1
  547. package/dist/components/results/report/OceanEduExamReport.js +58 -1
  548. package/dist/components/results/report/OceanEduSpeakingReport.js +62 -1
  549. package/dist/components/results/report/OverallAssessmentSection.js +17 -1
  550. package/dist/components/results/report/ResultErrorState.js +18 -1
  551. package/dist/components/results/report/ResultLoadingState.js +10 -1
  552. package/dist/components/results/report/ResultNotPublicState.js +27 -1
  553. package/dist/components/results/report/SpeakingReportParts.js +14 -1
  554. package/dist/components/results/report/SpeakingReportShared.js +86 -1
  555. package/dist/components/results/report/SpeakingRubricSection.js +171 -1
  556. package/dist/components/results/report/speaking-report.utils.js +198 -1
  557. package/dist/components/results/result-review.utils.js +6 -1
  558. package/dist/components/results/review-data.js +222 -1
  559. package/dist/components/results/review-renderer.utils.js +97 -1
  560. package/dist/components/results/review-status.utils.js +36 -1
  561. package/dist/components/results/review-types.js +1 -1
  562. package/dist/components/results/speaking/SpeakingResultAudioPlayer.js +77 -1
  563. package/dist/components/results/speaking/SpeakingReviewResult.js +48 -1
  564. package/dist/components/results/utils/review-score.utils.js +72 -1
  565. package/dist/components/results/utils/speaking-summary.js +224 -1
  566. package/dist/components/results/utils/transform-speaking-review.js +183 -1
  567. package/dist/components/shared/RichTextEditor.d.ts +9 -0
  568. package/dist/components/shared/RichTextEditor.js +47 -0
  569. package/dist/components/shared/audio/SpeakingAudioPlayer.js +100 -1
  570. package/dist/components/themes/cambridge-yle/CambridgeYleAudioPlayer.js +140 -1
  571. package/dist/components/themes/cambridge-yle/CambridgeYleBottomNav.js +10 -1
  572. package/dist/components/themes/cambridge-yle/CambridgeYleExamLayout.d.ts +1 -1
  573. package/dist/components/themes/cambridge-yle/CambridgeYleExamLayout.js +18 -1
  574. package/dist/components/themes/cambridge-yle/CambridgeYleExampleText.js +11 -1
  575. package/dist/components/themes/cambridge-yle/CambridgeYleHeader.js +11 -1
  576. package/dist/components/themes/cambridge-yle/CambridgeYleInstructionBanner.d.ts +2 -1
  577. package/dist/components/themes/cambridge-yle/CambridgeYleInstructionBanner.js +19 -1
  578. package/dist/components/themes/cambridge-yle/CambridgeYleNavButton.js +13 -1
  579. package/dist/components/themes/cambridge-yle/CambridgeYlePartBanner.d.ts +1 -1
  580. package/dist/components/themes/cambridge-yle/CambridgeYlePartBanner.js +3 -1
  581. package/dist/components/themes/cambridge-yle/CambridgeYleProgressBar.js +6 -1
  582. package/dist/components/themes/cambridge-yle/CambridgeYleQuestionCard.js +5 -1
  583. package/dist/components/themes/cambridge-yle/CambridgeYleQuestionCardFullWidth.js +9 -1
  584. package/dist/components/themes/cambridge-yle/CambridgeYleSidebar.d.ts +2 -1
  585. package/dist/components/themes/cambridge-yle/CambridgeYleSidebar.js +61 -1
  586. package/dist/components/themes/cambridge-yle/CambridgeYleTimer.d.ts +1 -1
  587. package/dist/components/themes/cambridge-yle/CambridgeYleTimer.js +25 -1
  588. package/dist/components/themes/cambridge-yle/index.js +13 -1
  589. package/dist/components/themes/english-certification/EcAnswerTheQuestion.js +25 -1
  590. package/dist/components/themes/english-certification/EcMatchByWritingAnswer.js +89 -1
  591. package/dist/components/themes/english-certification/EcWordFillParagraph.js +56 -1
  592. package/dist/components/themes/english-certification/EcWordFillStructuredForm.js +192 -1
  593. package/dist/components/themes/english-certification/EcWritingTask.js +60 -1
  594. package/dist/components/themes/english-certification/EnglishCertificationAudioPlayer.js +108 -1
  595. package/dist/components/themes/english-certification/EnglishCertificationBrand.js +11 -1
  596. package/dist/components/themes/english-certification/EnglishCertificationExamLayout.js +34 -1
  597. package/dist/components/themes/english-certification/EnglishCertificationFlagButton.js +15 -1
  598. package/dist/components/themes/english-certification/EnglishCertificationFooterBar.js +19 -1
  599. package/dist/components/themes/english-certification/EnglishCertificationGroupedQuestion.js +166 -1
  600. package/dist/components/themes/english-certification/EnglishCertificationHeader.js +31 -1
  601. package/dist/components/themes/english-certification/EnglishCertificationInstructionBanner.js +79 -1
  602. package/dist/components/themes/english-certification/EnglishCertificationNavigationPanel.js +71 -1
  603. package/dist/components/themes/english-certification/EnglishCertificationOptionSelector.js +79 -1
  604. package/dist/components/themes/english-certification/EnglishCertificationPartHeader.js +47 -1
  605. package/dist/components/themes/english-certification/EnglishCertificationPassagePanel.js +77 -1
  606. package/dist/components/themes/english-certification/EnglishCertificationQuestionCard.js +25 -1
  607. package/dist/components/themes/english-certification/EnglishCertificationQuestionItem.js +36 -1
  608. package/dist/components/themes/english-certification/EnglishCertificationQuestionRenderer.js +81 -1
  609. package/dist/components/themes/english-certification/EnglishCertificationReadingSection.js +95 -1
  610. package/dist/components/themes/english-certification/EnglishCertificationSingleQuestion.js +18 -1
  611. package/dist/components/themes/english-certification/EnglishCertificationSingleQuestionList.js +32 -1
  612. package/dist/components/themes/english-certification/english-cert-scroll.js +163 -1
  613. package/dist/components/themes/english-certification/english-certification-theme.js +58 -1
  614. package/dist/components/themes/english-certification/grouped-question-utils.js +243 -1
  615. package/dist/components/themes/english-certification/index.js +24 -1
  616. package/dist/components/themes/index.js +25 -1
  617. package/dist/components/themes/summer-sky/SummerSkyAudioPlayer.js +170 -1
  618. package/dist/components/themes/summer-sky/SummerSkyExitModal.js +21 -1
  619. package/dist/components/themes/summer-sky/SummerSkyLayout.js +221 -1
  620. package/dist/components/themes/summer-sky/SummerSkySubmitModal.js +18 -1
  621. package/dist/components/themes/summer-sky/SummerSkyWaitingRoom.js +193 -1
  622. package/dist/components/themes/types.js +1 -1
  623. package/dist/components/ui/alert-dialog.js +26 -1
  624. package/dist/components/ui/alert.js +22 -1
  625. package/dist/components/ui/avatar.js +12 -1
  626. package/dist/components/ui/badge.js +38 -1
  627. package/dist/components/ui/button.js +35 -1
  628. package/dist/components/ui/calendar.js +76 -1
  629. package/dist/components/ui/card.js +16 -1
  630. package/dist/components/ui/carousel.js +91 -1
  631. package/dist/components/ui/checkbox.js +9 -1
  632. package/dist/components/ui/collapsible.js +13 -1
  633. package/dist/components/ui/command.js +34 -1
  634. package/dist/components/ui/confirm-dialog.js +49 -1
  635. package/dist/components/ui/dialog.js +23 -1
  636. package/dist/components/ui/drawer.js +35 -1
  637. package/dist/components/ui/dropdown-menu.js +33 -1
  638. package/dist/components/ui/file-upload.js +155 -1
  639. package/dist/components/ui/form.js +62 -1
  640. package/dist/components/ui/hover-card.js +10 -1
  641. package/dist/components/ui/image-preview.js +29 -1
  642. package/dist/components/ui/input.js +8 -1
  643. package/dist/components/ui/label.js +9 -1
  644. package/dist/components/ui/language-switcher.js +15 -1
  645. package/dist/components/ui/multi-select.js +90 -1
  646. package/dist/components/ui/points-input.js +33 -1
  647. package/dist/components/ui/popover.js +26 -1
  648. package/dist/components/ui/progress.js +16 -1
  649. package/dist/components/ui/radio-group.js +12 -1
  650. package/dist/components/ui/scroll-area.js +11 -1
  651. package/dist/components/ui/select.js +38 -1
  652. package/dist/components/ui/separator.js +8 -1
  653. package/dist/components/ui/sheet.js +40 -1
  654. package/dist/components/ui/single-select.js +76 -1
  655. package/dist/components/ui/skeleton.js +6 -1
  656. package/dist/components/ui/switch.js +8 -1
  657. package/dist/components/ui/table.js +20 -1
  658. package/dist/components/ui/tabs.js +17 -1
  659. package/dist/components/ui/textarea.js +8 -1
  660. package/dist/components/ui/tooltip.js +11 -1
  661. package/dist/index.d.ts +3 -0
  662. package/dist/index.js +24 -1
  663. package/dist/shared/constants/ApiConstant.d.ts +1 -0
  664. package/dist/shared/constants/ApiConstant.js +278 -1
  665. package/dist/shared/constants/QueryKeyConstant.js +112 -1
  666. package/dist/shared/constants/exam-level.enum.js +41 -1
  667. package/dist/shared/constants/landings/placement-test.constants.js +431 -1
  668. package/dist/shared/constants/question-skills.js +277 -1
  669. package/dist/shared/constants/routes.js +81 -1
  670. package/dist/shared/index.js +10 -1
  671. package/dist/shared/lib/hooks/index.js +10 -1
  672. package/dist/shared/lib/hooks/useAlertDialog.js +57 -1
  673. package/dist/shared/lib/hooks/useAudioPlayCounter.js +30 -1
  674. package/dist/shared/lib/hooks/useAudioPreview.js +81 -1
  675. package/dist/shared/lib/hooks/useAudioUpload.js +24 -1
  676. package/dist/shared/lib/hooks/useConfirmDialog.js +89 -1
  677. package/dist/shared/lib/hooks/useDebouncedCallback.js +32 -1
  678. package/dist/shared/lib/hooks/useDelayedAutoPlay.js +12 -1
  679. package/dist/shared/lib/hooks/useFileUpload.js +24 -1
  680. package/dist/shared/lib/hooks/useImageUrl.js +5 -1
  681. package/dist/shared/lib/hooks/usePresignedFileUrl.js +108 -1
  682. package/dist/shared/lib/hooks/useReactHookForm.js +31 -1
  683. package/dist/shared/lib/hooks/useToast.js +62 -1
  684. package/dist/shared/lib/html-content.js +22 -1
  685. package/dist/shared/lib/i18n/index.js +54 -1
  686. package/dist/shared/lib/i18n/messages/en/admin.d.ts +11 -4
  687. package/dist/shared/lib/i18n/messages/en/admin.js +2111 -1
  688. package/dist/shared/lib/i18n/messages/en/auth.js +86 -1
  689. package/dist/shared/lib/i18n/messages/en/common.js +140 -1
  690. package/dist/shared/lib/i18n/messages/en/file-upload.js +18 -1
  691. package/dist/shared/lib/i18n/messages/en/student.js +133 -1
  692. package/dist/shared/lib/i18n/messages/en/terms.js +37 -1
  693. package/dist/shared/lib/i18n/messages/en.d.ts +11 -4
  694. package/dist/shared/lib/i18n/messages/en.js +15 -1
  695. package/dist/shared/lib/i18n/messages/vi/admin.d.ts +11 -4
  696. package/dist/shared/lib/i18n/messages/vi/admin.js +2111 -1
  697. package/dist/shared/lib/i18n/messages/vi/auth.js +86 -1
  698. package/dist/shared/lib/i18n/messages/vi/common.js +140 -1
  699. package/dist/shared/lib/i18n/messages/vi/file-upload.js +18 -1
  700. package/dist/shared/lib/i18n/messages/vi/student.js +133 -1
  701. package/dist/shared/lib/i18n/messages/vi/terms.js +37 -1
  702. package/dist/shared/lib/i18n/messages/vi.d.ts +11 -4
  703. package/dist/shared/lib/i18n/messages/vi.js +15 -1
  704. package/dist/shared/lib/i18n/types.js +1 -1
  705. package/dist/shared/lib/stores/examQuestionStore.js +212 -1
  706. package/dist/shared/lib/stores/examTakingStore.js +240 -1
  707. package/dist/shared/lib/stores/gradingTransientStore.js +39 -1
  708. package/dist/shared/lib/stores/localeStore.js +10 -1
  709. package/dist/shared/lib/themes/config/starters.config.js +71 -1
  710. package/dist/shared/lib/themes/index.js +49 -1
  711. package/dist/shared/lib/themes/types.js +2 -1
  712. package/dist/shared/lib/toast.js +43 -1
  713. package/dist/shared/lib/utils/public-page.js +44 -1
  714. package/dist/shared/lib/utils/question-reverse-transform.js +438 -1
  715. package/dist/shared/lib/utils/question-transform-types.js +1 -1
  716. package/dist/shared/lib/utils/question-transform-validation.js +194 -1
  717. package/dist/shared/lib/utils/question-transform.js +199 -1
  718. package/dist/shared/lib/utils.js +168 -1
  719. package/dist/shared/lib/validation/choose-correct-answer.validation.js +111 -1
  720. package/dist/shared/lib/validation/label-the-picture.validation.js +19 -1
  721. package/dist/shared/lib/validation/listen-and-choose-from-answer-group.validation.js +46 -1
  722. package/dist/shared/lib/validation/listen-and-choose-objects-in-scene.validation.js +21 -1
  723. package/dist/shared/lib/validation/listen-and-drag-objects-into-scene.validation.js +34 -1
  724. package/dist/shared/lib/validation/listen-and-speak-answer.validation.js +40 -1
  725. package/dist/shared/lib/validation/listen-and-speak-compare-images.validation.js +45 -1
  726. package/dist/shared/lib/validation/listen-and-speak-image-group.validation.js +19 -1
  727. package/dist/shared/lib/validation/listen-and-speak-info-exchange.validation.js +39 -1
  728. package/dist/shared/lib/validation/listen-and-speak-odd-one-out.validation.js +32 -1
  729. package/dist/shared/lib/validation/listen-and-speak-question-list.validation.js +19 -1
  730. package/dist/shared/lib/validation/listen-and-speak-with-story-images.validation.js +28 -1
  731. package/dist/shared/lib/validation/look-picture-choose-correct-answer.validation.js +12 -1
  732. package/dist/shared/lib/validation/look-picture-fill-blank-choose-answer.validation.js +47 -1
  733. package/dist/shared/lib/validation/read-and-color-objects.validation.js +29 -1
  734. package/dist/shared/lib/validation/read-displayed-content.validation.js +28 -1
  735. package/dist/shared/lib/validation/speaking-conversation.validation.js +75 -1
  736. package/dist/shared/lib/validation/speaking-describe-image.validation.js +31 -1
  737. package/dist/shared/lib/validation/spontaneous-qa.validation.js +48 -1
  738. package/dist/shared/lib/validation/word-fill-paragraph-default.validation.js +38 -1
  739. package/dist/shared/lib/validation/word-fill-paragraph-with-options.validation.js +39 -1
  740. package/dist/shared/lib/validation/word-fill-paragraph.validation.js +43 -1
  741. package/dist/shared/lib/validation/word-ordering.validation.js +33 -1
  742. package/dist/shared/types/branch.types.js +6 -1
  743. package/dist/shared/types/common.types.js +49 -1
  744. package/dist/shared/types/entities/exam-schedule.types.js +5 -1
  745. package/dist/shared/types/entities/exam.types.js +1 -1
  746. package/dist/shared/types/entities/question.types.js +4 -1
  747. package/dist/shared/types/entities/result.types.js +4 -1
  748. package/dist/shared/types/entities/user.types.js +4 -1
  749. package/dist/shared/types/exam-taking.types.js +2 -1
  750. package/dist/shared/types/history.types.js +34 -1
  751. package/dist/shared/types/index.js +1 -1
  752. package/dist/shared/types/questions/choose-correct-adjective.js +4 -1
  753. package/dist/shared/types/questions/choose-the-correct-answer-group.d.ts +1 -0
  754. package/dist/shared/types/questions/choose-the-correct-answer-group.js +1 -1
  755. package/dist/shared/types/questions/choose-the-correct-answer.js +9 -1
  756. package/dist/shared/types/questions/cross-out-word-group.d.ts +2 -0
  757. package/dist/shared/types/questions/cross-out-word-group.js +1 -1
  758. package/dist/shared/types/questions/fill-missing-words-in-grid.js +11 -1
  759. package/dist/shared/types/questions/index.d.ts +1 -0
  760. package/dist/shared/types/questions/index.js +46 -1
  761. package/dist/shared/types/questions/listen-and-speak-answer.js +1 -1
  762. package/dist/shared/types/questions/listen-and-speak-compare-images.js +1 -1
  763. package/dist/shared/types/questions/listen-and-speak-image-group.js +1 -1
  764. package/dist/shared/types/questions/listen-and-speak-info-exchange.js +3 -1
  765. package/dist/shared/types/questions/listen-and-speak-odd-one-out.js +3 -1
  766. package/dist/shared/types/questions/listen-and-speak-question-list.js +1 -1
  767. package/dist/shared/types/questions/listen-and-speak-with-story-images.js +3 -1
  768. package/dist/shared/types/questions/look-picture-choose-correct-answer.js +5 -1
  769. package/dist/shared/types/questions/look-picture-fill-blank-choose-answer.js +9 -1
  770. package/dist/shared/types/questions/look-picture-fill-word-hint.js +7 -1
  771. package/dist/shared/types/questions/read-displayed-content.js +1 -1
  772. package/dist/shared/types/questions/speaking-conversation.js +7 -1
  773. package/dist/shared/types/questions/speaking-describe-image.js +1 -1
  774. package/dist/shared/types/questions/spontaneous-qa.js +1 -1
  775. package/dist/shared/types/questions/word-order-and-match-group.d.ts +33 -0
  776. package/dist/shared/types/questions/word-order-and-match-group.js +1 -0
  777. package/dist/shared/types/questions/write-correct-verb-form.js +12 -1
  778. package/dist/shared/types/role.types.js +1 -1
  779. package/dist/shared/types/structure-management.js +28 -1
  780. package/dist/shared/types/student.types.js +57 -1
  781. package/dist/shared/types/teacher-dashboard-rooms.js +2 -1
  782. package/package.json +184 -166
  783. package/dist/mcp/config.d.ts +0 -12
  784. package/dist/mcp/config.js +0 -1
  785. package/dist/mcp/http-client.d.ts +0 -6
  786. package/dist/mcp/http-client.js +0 -1
  787. package/dist/mcp/index.d.ts +0 -6
  788. package/dist/mcp/index.js +0 -2
  789. package/dist/mcp/tools/_helpers.d.ts +0 -4
  790. package/dist/mcp/tools/_helpers.js +0 -1
  791. package/dist/mcp/tools/exams.d.ts +0 -2
  792. package/dist/mcp/tools/exams.js +0 -1
  793. package/dist/mcp/tools/index.d.ts +0 -2
  794. package/dist/mcp/tools/index.js +0 -1
  795. package/dist/mcp/tools/results.d.ts +0 -2
  796. package/dist/mcp/tools/results.js +0 -1
@@ -1 +1,178 @@
1
- import{useCallback as e,useEffect as r,useRef as t,useState as n}from"react";import{usePresignedFileUrl as u}from"../../../../shared/lib/hooks/usePresignedFileUrl";export function useSpeakingConversationAudio({interlocutorAudioUrl:a,partnerAudioUrl:i,onSequenceComplete:o}){const[c,l]=n("idle"),[d,s]=n(0),[p,y]=n(0),{previewUrl:m}=u(a??""),{previewUrl:g}=u(i??""),v=t(null),A=t(o);r(()=>{A.current=o},[o]);const E=t(m),L=t(g);r(()=>{E.current=m},[m]),r(()=>{L.current=g},[g]);const U=e(()=>{const e=v.current;e&&(e.pause(),e.src="")},[]),h=e(e=>{let r=v.current;r||(r=new Audio,v.current=r),r.src=e,r.play().catch(()=>{})},[]);r(()=>{let e=v.current;e||(e=new Audio,v.current=e);const r=()=>{l(e=>{if("playing-interlocutor"===e){const e=L.current;e?setTimeout(()=>{l("playing-partner"),h(e)},0):setTimeout(()=>{l("ready"),A.current()},0)}else"playing-partner"===e&&setTimeout(()=>{l("ready"),A.current()},0);return e})},t=()=>{e&&s(e.currentTime)},n=()=>{e&&(y(e.duration),s(0))};return e.addEventListener("ended",r),e.addEventListener("timeupdate",t),e.addEventListener("loadedmetadata",n),()=>{e.removeEventListener("ended",r),e.removeEventListener("timeupdate",t),e.removeEventListener("loadedmetadata",n)}},[h]),r(()=>(U(),l("idle"),m||g?(m?(l("playing-interlocutor"),h(m)):g&&(l("playing-partner"),h(g)),()=>{U()}):(l("ready"),void A.current())),[m,g]),r(()=>()=>{U()},[]);const T=e(()=>{U(),E.current?(l("playing-interlocutor"),h(E.current)):L.current?(l("playing-partner"),h(L.current)):(l("ready"),A.current())},[U,h]),f=e(()=>{const e=v.current;e&&(e.paused?e.play().catch(()=>{}):e.pause())},[]);return{phase:c,isPlaying:Boolean(v.current&&!v.current.paused),replayAll:T,togglePlayPause:f,currentAudioUrl:"playing-interlocutor"===c?m??"":"playing-partner"===c?g??"":"",currentTime:d,duration:p}}
1
+ import { useCallback, useEffect, useRef, useState } from 'react';
2
+ import { usePresignedFileUrl } from '../../../../shared/lib/hooks/usePresignedFileUrl';
3
+ // ============================================
4
+ // Hook
5
+ // ============================================
6
+ export function useSpeakingConversationAudio({ interlocutorAudioUrl, partnerAudioUrl, onSequenceComplete, }) {
7
+ const [phase, setPhase] = useState('idle');
8
+ const [currentTime, setCurrentTime] = useState(0);
9
+ const [duration, setDuration] = useState(0);
10
+ // Resolve presigned URLs for both tracks
11
+ const { previewUrl: resolvedInterlocutorUrl } = usePresignedFileUrl(interlocutorAudioUrl ?? '');
12
+ const { previewUrl: resolvedPartnerUrl } = usePresignedFileUrl(partnerAudioUrl ?? '');
13
+ // Single shared audio element ref — we swap src between phases
14
+ const audioRef = useRef(null);
15
+ // Stable callback ref so we don't retrigger effects when the prop changes identity
16
+ const onSequenceCompleteRef = useRef(onSequenceComplete);
17
+ useEffect(() => {
18
+ onSequenceCompleteRef.current = onSequenceComplete;
19
+ }, [onSequenceComplete]);
20
+ // Refs to hold the latest resolved URLs so event handlers can read them
21
+ const resolvedInterlocutorUrlRef = useRef(resolvedInterlocutorUrl);
22
+ const resolvedPartnerUrlRef = useRef(resolvedPartnerUrl);
23
+ useEffect(() => {
24
+ resolvedInterlocutorUrlRef.current = resolvedInterlocutorUrl;
25
+ }, [resolvedInterlocutorUrl]);
26
+ useEffect(() => {
27
+ resolvedPartnerUrlRef.current = resolvedPartnerUrl;
28
+ }, [resolvedPartnerUrl]);
29
+ // ---------- helpers ----------
30
+ const stopAudio = useCallback(() => {
31
+ const audio = audioRef.current;
32
+ if (!audio)
33
+ return;
34
+ audio.pause();
35
+ audio.src = '';
36
+ }, []);
37
+ const playUrl = useCallback((url) => {
38
+ let audio = audioRef.current;
39
+ if (!audio) {
40
+ audio = new Audio();
41
+ audioRef.current = audio;
42
+ }
43
+ audio.src = url;
44
+ audio.play().catch(() => {
45
+ // If play fails (e.g. AbortError on rapid navigation), skip to ready
46
+ });
47
+ }, []);
48
+ // ---------- wire ended events ----------
49
+ useEffect(() => {
50
+ let audio = audioRef.current;
51
+ if (!audio) {
52
+ audio = new Audio();
53
+ audioRef.current = audio;
54
+ }
55
+ const handleEnded = () => {
56
+ // Read the current phase from refs so the handler always sees latest value
57
+ setPhase((currentPhase) => {
58
+ if (currentPhase === 'playing-interlocutor') {
59
+ const partnerUrl = resolvedPartnerUrlRef.current;
60
+ if (partnerUrl) {
61
+ // Schedule outside the setState callback
62
+ setTimeout(() => {
63
+ setPhase('playing-partner');
64
+ playUrl(partnerUrl);
65
+ }, 0);
66
+ }
67
+ else {
68
+ setTimeout(() => {
69
+ setPhase('ready');
70
+ onSequenceCompleteRef.current();
71
+ }, 0);
72
+ }
73
+ }
74
+ else if (currentPhase === 'playing-partner') {
75
+ setTimeout(() => {
76
+ setPhase('ready');
77
+ onSequenceCompleteRef.current();
78
+ }, 0);
79
+ }
80
+ return currentPhase; // Don't change phase here — we do it in setTimeout
81
+ });
82
+ };
83
+ const handleTimeUpdate = () => {
84
+ if (audio)
85
+ setCurrentTime(audio.currentTime);
86
+ };
87
+ const handleLoadedMetadata = () => {
88
+ if (audio) {
89
+ setDuration(audio.duration);
90
+ setCurrentTime(0);
91
+ }
92
+ };
93
+ audio.addEventListener('ended', handleEnded);
94
+ audio.addEventListener('timeupdate', handleTimeUpdate);
95
+ audio.addEventListener('loadedmetadata', handleLoadedMetadata);
96
+ return () => {
97
+ audio.removeEventListener('ended', handleEnded);
98
+ audio.removeEventListener('timeupdate', handleTimeUpdate);
99
+ audio.removeEventListener('loadedmetadata', handleLoadedMetadata);
100
+ };
101
+ }, [playUrl]);
102
+ // ---------- start / reset when URLs change ----------
103
+ useEffect(() => {
104
+ // Reset state whenever the source keys change (question navigation)
105
+ stopAudio();
106
+ setPhase('idle');
107
+ if (!resolvedInterlocutorUrl && !resolvedPartnerUrl) {
108
+ // No audio at all — go straight to ready
109
+ setPhase('ready');
110
+ onSequenceCompleteRef.current();
111
+ return;
112
+ }
113
+ if (resolvedInterlocutorUrl) {
114
+ setPhase('playing-interlocutor');
115
+ playUrl(resolvedInterlocutorUrl);
116
+ }
117
+ else if (resolvedPartnerUrl) {
118
+ // No interlocutor audio — jump straight to partner
119
+ setPhase('playing-partner');
120
+ playUrl(resolvedPartnerUrl);
121
+ }
122
+ return () => {
123
+ stopAudio();
124
+ };
125
+ // eslint-disable-next-line react-hooks/exhaustive-deps
126
+ }, [resolvedInterlocutorUrl, resolvedPartnerUrl]);
127
+ // ---------- cleanup on unmount ----------
128
+ useEffect(() => {
129
+ return () => {
130
+ stopAudio();
131
+ };
132
+ // eslint-disable-next-line react-hooks/exhaustive-deps
133
+ }, []);
134
+ // ---------- replayAll ----------
135
+ const replayAll = useCallback(() => {
136
+ stopAudio();
137
+ if (resolvedInterlocutorUrlRef.current) {
138
+ setPhase('playing-interlocutor');
139
+ playUrl(resolvedInterlocutorUrlRef.current);
140
+ }
141
+ else if (resolvedPartnerUrlRef.current) {
142
+ setPhase('playing-partner');
143
+ playUrl(resolvedPartnerUrlRef.current);
144
+ }
145
+ else {
146
+ setPhase('ready');
147
+ onSequenceCompleteRef.current();
148
+ }
149
+ }, [stopAudio, playUrl]);
150
+ // ---------- togglePlayPause ----------
151
+ const togglePlayPause = useCallback(() => {
152
+ const audio = audioRef.current;
153
+ if (!audio)
154
+ return;
155
+ if (audio.paused) {
156
+ audio.play().catch(() => { });
157
+ }
158
+ else {
159
+ audio.pause();
160
+ }
161
+ }, []);
162
+ // ---------- derived values ----------
163
+ const isPlaying = Boolean(audioRef.current && !audioRef.current.paused);
164
+ const currentAudioUrl = phase === 'playing-interlocutor'
165
+ ? (resolvedInterlocutorUrl ?? '')
166
+ : phase === 'playing-partner'
167
+ ? (resolvedPartnerUrl ?? '')
168
+ : '';
169
+ return {
170
+ phase,
171
+ isPlaying,
172
+ replayAll,
173
+ togglePlayPause,
174
+ currentAudioUrl,
175
+ currentTime,
176
+ duration,
177
+ };
178
+ }
@@ -1 +1,51 @@
1
- import{useState as t,useCallback as n,useMemo as r}from"react";export function useSpeakingNavigation(e){const{questions:o,initialIndex:a=0}=e,[i,u]=t(a),c=o.length,s=o[i]??null,l=s?.part_no??1,g=s?.partName??"",m=r(()=>{if(!s)return 1;return o.slice(0,i).filter(t=>t.part_no===s.part_no).length+1},[i,s,o]),p=i>0,N=i<c-1,x=n(()=>{u(t=>Math.min(t+1,c-1))},[c]),P=n(()=>{u(t=>Math.max(t-1,0))},[]),f=n(t=>{t>=0&&t<c&&u(t)},[c]);return{currentIndex:i,currentQuestion:s,totalQuestions:c,currentPartNo:l,currentPartName:g,questionNumberInPart:m,canGoPrev:p,canGoNext:N,goNext:x,goPrev:P,goTo:f}}
1
+ import { useState, useCallback, useMemo } from 'react';
2
+ // ============================================
3
+ // Hook
4
+ // ============================================
5
+ export function useSpeakingNavigation(options) {
6
+ const { questions, initialIndex = 0 } = options;
7
+ const [currentIndex, setCurrentIndex] = useState(initialIndex);
8
+ const totalQuestions = questions.length;
9
+ const currentQuestion = questions[currentIndex] ?? null;
10
+ const currentPartNo = currentQuestion?.part_no ?? 1;
11
+ const currentPartName = currentQuestion?.partName ?? '';
12
+ /**
13
+ * Compute 1-based question number within the current part.
14
+ * We count how many questions before currentIndex share the same part_no,
15
+ * then add 1.
16
+ */
17
+ const questionNumberInPart = useMemo(() => {
18
+ if (!currentQuestion)
19
+ return 1;
20
+ const indexWithinPart = questions
21
+ .slice(0, currentIndex)
22
+ .filter((q) => q.part_no === currentQuestion.part_no).length;
23
+ return indexWithinPart + 1;
24
+ }, [currentIndex, currentQuestion, questions]);
25
+ const canGoPrev = currentIndex > 0;
26
+ const canGoNext = currentIndex < totalQuestions - 1;
27
+ const goNext = useCallback(() => {
28
+ setCurrentIndex((prev) => Math.min(prev + 1, totalQuestions - 1));
29
+ }, [totalQuestions]);
30
+ const goPrev = useCallback(() => {
31
+ setCurrentIndex((prev) => Math.max(prev - 1, 0));
32
+ }, []);
33
+ const goTo = useCallback((index) => {
34
+ if (index >= 0 && index < totalQuestions) {
35
+ setCurrentIndex(index);
36
+ }
37
+ }, [totalQuestions]);
38
+ return {
39
+ currentIndex,
40
+ currentQuestion,
41
+ totalQuestions,
42
+ currentPartNo,
43
+ currentPartName,
44
+ questionNumberInPart,
45
+ canGoPrev,
46
+ canGoNext,
47
+ goNext,
48
+ goPrev,
49
+ goTo,
50
+ };
51
+ }
@@ -1 +1,406 @@
1
- import{useState as r,useRef as e,useEffect as n,useCallback as t}from"react";import{usePresignedFileUrl as o}from"../../../../shared/lib/hooks";import{useExamTakingApiOptional as u}from"../ExamTakingApiContext";export function useSpeakingRecorder(i){const c=i.maxDurationMs??3e4,a=Math.floor(c/1e3),d=u(),s=e(d);s.current=d;const l=e(i.onRecordingComplete),p=e(i.onError);l.current=i.onRecordingComplete,p.current=i.onError;const g=e(i.attemptId),h=e(i.questionId);g.current=i.attemptId,h.current=i.questionId;const[m,y]=r("idle"),[f,w]=r(a),[v,A]=r(0),[T,E]=r(null),[R,x]=r(null),[b,k]=r(null),[I,M]=r(!1),K=e(null),D=e(null),P=e([]),S=e(null),U=e(null),O=e(""),_=e(0),q=e(null),L=e(void 0),N=e(0),B=e(!0),V=e(""),C="undefined"!=typeof MediaRecorder,{previewUrl:F}=o(i.existingAnswerKey),G=t(()=>{S.current&&(clearInterval(S.current),S.current=null)},[]),j=t(()=>{U.current&&(U.current.startsWith("blob:")&&URL.revokeObjectURL(U.current),U.current=null)},[]),W=t(()=>{D.current&&(D.current.getTracks().forEach(r=>r.stop()),D.current=null)},[]),X=t(async(r,e,n,t)=>{if(!B.current)return;const o=t||V.current||h.current;h.current===o&&y("uploading");const u=g.current;if("mock-attempt-speaking"===u){if(await new Promise(r=>setTimeout(r,500)),!B.current)return;const r=`mock-audio-key-${o}`;return h.current===o&&(y("uploaded"),x(r)),l.current(r,o),q.current=null,void(L.current=void 0)}try{if(!s.current?.uploadAudioAnswer)throw new Error("uploadAudioAnswer is not implemented by the provided API adapter.");const n=(i=await s.current.uploadAudioAnswer({attemptId:u,questionId:o,audioBlob:r,durationMs:e}))&&"object"==typeof i&&"data"in i?i.data:i;if(!B.current)return;const t=n.audioKey??"";h.current===o&&(y("uploaded"),x(t)),l.current(t,o),q.current=null,L.current=void 0,N.current=0,s.current.realtimeGradeSingle?.({attemptId:u,questionId:o,audioKey:t}).catch(r=>{console.debug("[Realtime Grading] Skipped or failed:",r?.response?.status??r?.message)})}catch(o){if(!B.current)return;const u=o,i=u?.response?.data?.code;if("ATTEMPT_EXPIRED"===i||"ATTEMPT_NOT_IN_PROGRESS"===i){const r="ATTEMPT_EXPIRED"===i?"Bài thi đã hết giờ":"Bài thi đã được nộp.";return y("error"),k(r),M(!0),void p.current?.(r)}if("AUDIO_FILE_TOO_LARGE"===i){const r="Bài ghi âm quá dài. Vui lòng ghi âm ngắn hơn.";return y("error"),k(r),void p.current?.(r)}if(n<3){const o=1e3*Math.pow(2,n);if(await new Promise(r=>setTimeout(r,o)),!B.current)return;N.current=n+1,await X(r,e,n+1,t)}else{const r="Tải lên bản ghi âm thất bại. Vui lòng thử lại.";y("error"),k(r),p.current?.(r)}}var i},[]),z=t(async(r,e,n)=>{q.current=r,L.current=e,N.current=0,await X(r,e,0,n)},[X]),H=t(async()=>{if(i.existingAnswerKey)return y("uploaded"),void x(i.existingAnswerKey);if(!C){const r="Trình duyệt này không hỗ trợ ghi âm. Vui lòng dùng Chrome, Firefox hoặc Edge.";return y("error"),k(r),void p.current?.(r)}const r=function(){if("undefined"==typeof MediaRecorder)return null;const r=["audio/webm;codecs=opus","audio/webm","audio/mp4","audio/ogg;codecs=opus","audio/ogg"];for(const e of r)if(MediaRecorder.isTypeSupported(e))return e;return null}();if(!r){const r="Trình duyệt không hỗ trợ định dạng ghi âm.";return y("error"),k(r),void p.current?.(r)}if("undefined"==typeof navigator||!navigator.mediaDevices?.getUserMedia){const r="Trình duyệt hoặc kết nối (HTTP) không hỗ trợ truy cập microphone.";return y("error"),k(r),void p.current?.(r)}try{const e=await navigator.mediaDevices.getUserMedia({audio:!0});D.current=e,O.current=r;const n=new MediaRecorder(e,{mimeType:r});K.current=n,P.current=[],n.ondataavailable=r=>{r.data.size>0&&P.current.push(r.data)},n.onstop=()=>{const r=Date.now()-_.current,e=new Blob(P.current,{type:O.current}),n=URL.createObjectURL(e),t=V.current;j(),U.current=n,E(n),y("recorded"),z(e,r,t)},n.start(),_.current=Date.now(),V.current=h.current,y("recording"),A(0),w(a),k(null),x(null),E(null),M(!1),S.current=setInterval(()=>{A(r=>r+1),w(r=>{const e=Math.max(0,r-1);return 0===e&&(G(),K.current&&"recording"===K.current.state&&K.current.stop(),W()),e})},1e3)}catch(r){W();const e=r instanceof DOMException?r.name:r?.name;let n="Không thể truy cập microphone. Vui lòng thử lại.";"NotAllowedError"===e||"PermissionDeniedError"===e?n="Vui lòng cấp quyền truy cập microphone trong cài đặt trình duyệt.":"NotFoundError"===e||"DevicesNotFoundError"===e?n="Không tìm thấy thiết bị microphone nào kết nối với máy tính.":"NotReadableError"!==e&&"TrackStartError"!==e||(n="Microphone đang được ứng dụng khác sử dụng hoặc gặp lỗi phần cứng."),y("error"),k(n),p.current?.(n)}},[C,a,i.existingAnswerKey,G,W,z,j]),$=t(()=>{G(),K.current&&"recording"===K.current.state&&K.current.stop(),W()},[G,W]),J=t(()=>{G(),W(),K.current&&"recording"===K.current.state&&K.current.stop(),K.current=null,P.current=[],q.current=null,L.current=void 0,N.current=0,j(),E(null),x(null),A(0),w(a),k(null),y("idle"),M(!1)},[G,W,j,a]),Q=t(async()=>{if(i.existingAnswerKey)return y("uploaded"),void x(i.existingAnswerKey);J(),await H()},[i.existingAnswerKey,J,H]),Y=t(async()=>{const r=q.current;r&&(N.current=0,await X(r,L.current,0,V.current||void 0))},[X]);n(()=>{J()},[i.questionId]),n(()=>{"idle"===m&&F&&i.existingAnswerKey&&!T&&(E(F),U.current=F,x(i.existingAnswerKey),y("uploaded"))},[m,F,i.existingAnswerKey,T]),n(()=>(B.current=!0,()=>{B.current=!1,G(),K.current&&"recording"===K.current.state&&K.current.stop(),W(),j()}),[]);return{status:m,remainingSeconds:f,isWarning:f<=5&&"recording"===m,durationSeconds:v,previewUrl:T,uploadedKey:R,error:b,isSupported:C,isAttemptExpired:I,liveTranscript:null,startRecording:H,stopRecording:$,resetRecording:J,reRecord:Q,retryUpload:Y}}
1
+ import { useState, useRef, useEffect, useCallback } from 'react';
2
+ import { usePresignedFileUrl } from '../../../../shared/lib/hooks';
3
+ import { useExamTakingApiOptional } from '../ExamTakingApiContext';
4
+ /** Unwrap an API response that may be either the raw value or an `{ data }` envelope. */
5
+ function unwrapData(res) {
6
+ return res && typeof res === 'object' && 'data' in res
7
+ ? res.data
8
+ : res;
9
+ }
10
+ // ============================================
11
+ // MIME type detection
12
+ // ============================================
13
+ function detectSupportedMimeType() {
14
+ if (typeof MediaRecorder === 'undefined')
15
+ return null;
16
+ const candidates = [
17
+ 'audio/webm;codecs=opus',
18
+ 'audio/webm',
19
+ 'audio/mp4',
20
+ 'audio/ogg;codecs=opus',
21
+ 'audio/ogg',
22
+ ];
23
+ for (const mimeType of candidates) {
24
+ if (MediaRecorder.isTypeSupported(mimeType)) {
25
+ return mimeType;
26
+ }
27
+ }
28
+ return null;
29
+ }
30
+ // ============================================
31
+ // Constants
32
+ // ============================================
33
+ const DEFAULT_MAX_DURATION_MS = 30000;
34
+ const WARNING_THRESHOLD_SECONDS = 5;
35
+ const MAX_AUTO_RETRIES = 3;
36
+ // ============================================
37
+ // Hook
38
+ // ============================================
39
+ export function useSpeakingRecorder(options) {
40
+ const maxDurationMs = options.maxDurationMs ?? DEFAULT_MAX_DURATION_MS;
41
+ const maxDurationSeconds = Math.floor(maxDurationMs / 1000);
42
+ // Injected API adapter, kept in a ref so the (stable) upload callbacks below
43
+ // can read the latest value without being re-created. Optional: the mic-test
44
+ // in the entry waiting room mounts this hook in mock mode
45
+ // (attemptId === 'mock-attempt-speaking'), where no real upload happens and
46
+ // no provider is mounted — so a missing API must not throw. Real uploads
47
+ // still fail closed below when the adapter is absent.
48
+ const api = useExamTakingApiOptional();
49
+ const apiRef = useRef(api);
50
+ apiRef.current = api;
51
+ // Stable callback refs — avoids re-running effects when callbacks change identity
52
+ const onRecordingCompleteRef = useRef(options.onRecordingComplete);
53
+ const onErrorRef = useRef(options.onError);
54
+ onRecordingCompleteRef.current = options.onRecordingComplete;
55
+ onErrorRef.current = options.onError;
56
+ // Stable option refs for use inside async callbacks
57
+ const attemptIdRef = useRef(options.attemptId);
58
+ const questionIdRef = useRef(options.questionId);
59
+ attemptIdRef.current = options.attemptId;
60
+ questionIdRef.current = options.questionId;
61
+ const [status, setStatus] = useState('idle');
62
+ const [remainingSeconds, setRemainingSeconds] = useState(maxDurationSeconds);
63
+ const [durationSeconds, setDurationSeconds] = useState(0);
64
+ const [previewUrl, setPreviewUrl] = useState(null);
65
+ const [uploadedKey, setUploadedKey] = useState(null);
66
+ const [error, setError] = useState(null);
67
+ const [isAttemptExpired, setIsAttemptExpired] = useState(false);
68
+ const mediaRecorderRef = useRef(null);
69
+ const mediaStreamRef = useRef(null);
70
+ const chunksRef = useRef([]);
71
+ const durationIntervalRef = useRef(null);
72
+ const previewUrlRef = useRef(null); // tracked for cleanup on unmount
73
+ const mimeTypeRef = useRef('');
74
+ const recordStartTimeRef = useRef(0);
75
+ const pendingBlobRef = useRef(null); // blob kept for retry
76
+ const pendingDurationMsRef = useRef(undefined);
77
+ const autoRetryCountRef = useRef(0);
78
+ const isMountedRef = useRef(true);
79
+ // Snapshot of questionId at the moment recording starts — survives navigation changes
80
+ const recordingQuestionIdRef = useRef('');
81
+ const isSupported = typeof MediaRecorder !== 'undefined';
82
+ // Fetch presigned URL for existing answer (to restore playback on navigation back)
83
+ const { previewUrl: existingPresignedUrl } = usePresignedFileUrl(options.existingAnswerKey);
84
+ // ============================================
85
+ // Cleanup helpers
86
+ // ============================================
87
+ const stopDurationTimer = useCallback(() => {
88
+ if (durationIntervalRef.current) {
89
+ clearInterval(durationIntervalRef.current);
90
+ durationIntervalRef.current = null;
91
+ }
92
+ }, []);
93
+ const revokePreviewUrl = useCallback(() => {
94
+ if (previewUrlRef.current) {
95
+ // Only revoke blob: URLs — presigned HTTPS URLs don't need revoking
96
+ if (previewUrlRef.current.startsWith('blob:')) {
97
+ URL.revokeObjectURL(previewUrlRef.current);
98
+ }
99
+ previewUrlRef.current = null;
100
+ }
101
+ }, []);
102
+ const stopMediaStream = useCallback(() => {
103
+ if (mediaStreamRef.current) {
104
+ mediaStreamRef.current.getTracks().forEach((track) => track.stop());
105
+ mediaStreamRef.current = null;
106
+ }
107
+ }, []);
108
+ // ============================================
109
+ // Upload helper — with auto-retry and error code handling
110
+ // ============================================
111
+ const performUpload = useCallback(async (blob, durationMs, retryCount, forQuestionId) => {
112
+ if (!isMountedRef.current)
113
+ return;
114
+ // Only show 'uploading' status if we're still on the same question
115
+ const questionId = forQuestionId || recordingQuestionIdRef.current || questionIdRef.current;
116
+ if (questionIdRef.current === questionId) {
117
+ setStatus('uploading');
118
+ }
119
+ const attemptId = attemptIdRef.current;
120
+ // Mock mode: skip real upload
121
+ if (attemptId === 'mock-attempt-speaking') {
122
+ await new Promise((resolve) => setTimeout(resolve, 500));
123
+ if (!isMountedRef.current)
124
+ return;
125
+ const mockKey = `mock-audio-key-${questionId}`;
126
+ if (questionIdRef.current === questionId) {
127
+ setStatus('uploaded');
128
+ setUploadedKey(mockKey);
129
+ }
130
+ onRecordingCompleteRef.current(mockKey, questionId);
131
+ pendingBlobRef.current = null;
132
+ pendingDurationMsRef.current = undefined;
133
+ return;
134
+ }
135
+ try {
136
+ if (!apiRef.current?.uploadAudioAnswer) {
137
+ throw new Error('uploadAudioAnswer is not implemented by the provided API adapter.');
138
+ }
139
+ const result = unwrapData(await apiRef.current.uploadAudioAnswer({ attemptId, questionId, audioBlob: blob, durationMs }));
140
+ if (!isMountedRef.current)
141
+ return;
142
+ const audioKey = result.audioKey ?? '';
143
+ // Only update UI status if we're still on the same question
144
+ if (questionIdRef.current === questionId) {
145
+ setStatus('uploaded');
146
+ setUploadedKey(audioKey);
147
+ }
148
+ onRecordingCompleteRef.current(audioKey, questionId);
149
+ pendingBlobRef.current = null;
150
+ pendingDurationMsRef.current = undefined;
151
+ autoRetryCountRef.current = 0;
152
+ // Fire-and-forget: trigger AI grading per-question (RECORDING mode)
153
+ // Non-blocking — if this fails, grading will fallback to submit time.
154
+ apiRef.current.realtimeGradeSingle?.({ attemptId, questionId, audioKey }).catch((gradeErr) => {
155
+ console.debug('[Realtime Grading] Skipped or failed:', gradeErr?.response?.status ?? gradeErr?.message);
156
+ });
157
+ }
158
+ catch (err) {
159
+ if (!isMountedRef.current)
160
+ return;
161
+ // Extract backend error code if available
162
+ const axiosError = err;
163
+ const errorCode = axiosError?.response?.data?.code;
164
+ // Handle fatal backend error codes
165
+ if (errorCode === 'ATTEMPT_EXPIRED' || errorCode === 'ATTEMPT_NOT_IN_PROGRESS') {
166
+ const message = errorCode === 'ATTEMPT_EXPIRED'
167
+ ? 'Bài thi đã hết giờ'
168
+ : 'Bài thi đã được nộp.';
169
+ setStatus('error');
170
+ setError(message);
171
+ setIsAttemptExpired(true);
172
+ onErrorRef.current?.(message);
173
+ return;
174
+ }
175
+ if (errorCode === 'AUDIO_FILE_TOO_LARGE') {
176
+ const message = 'Bài ghi âm quá dài. Vui lòng ghi âm ngắn hơn.';
177
+ setStatus('error');
178
+ setError(message);
179
+ onErrorRef.current?.(message);
180
+ return;
181
+ }
182
+ // Network / transient error — auto-retry up to MAX_AUTO_RETRIES
183
+ if (retryCount < MAX_AUTO_RETRIES) {
184
+ const backoffMs = Math.pow(2, retryCount) * 1000; // 1s, 2s, 4s
185
+ await new Promise((resolve) => setTimeout(resolve, backoffMs));
186
+ if (!isMountedRef.current)
187
+ return;
188
+ autoRetryCountRef.current = retryCount + 1;
189
+ await performUpload(blob, durationMs, retryCount + 1, forQuestionId);
190
+ }
191
+ else {
192
+ // Max retries exhausted — expose manual retry
193
+ const message = 'Tải lên bản ghi âm thất bại. Vui lòng thử lại.';
194
+ setStatus('error');
195
+ setError(message);
196
+ onErrorRef.current?.(message);
197
+ }
198
+ }
199
+ },
200
+ // performUpload is stable (only uses refs)
201
+ []);
202
+ const uploadBlob = useCallback(async (blob, durationMs, forQuestionId) => {
203
+ pendingBlobRef.current = blob;
204
+ pendingDurationMsRef.current = durationMs;
205
+ autoRetryCountRef.current = 0;
206
+ await performUpload(blob, durationMs, 0, forQuestionId);
207
+ }, [performUpload]);
208
+ // ============================================
209
+ // Actions
210
+ // ============================================
211
+ const startRecording = useCallback(async () => {
212
+ if (options.existingAnswerKey) {
213
+ setStatus('uploaded');
214
+ setUploadedKey(options.existingAnswerKey);
215
+ return;
216
+ }
217
+ if (!isSupported) {
218
+ const message = 'Trình duyệt này không hỗ trợ ghi âm. Vui lòng dùng Chrome, Firefox hoặc Edge.';
219
+ setStatus('error');
220
+ setError(message);
221
+ onErrorRef.current?.(message);
222
+ return;
223
+ }
224
+ const mimeType = detectSupportedMimeType();
225
+ if (!mimeType) {
226
+ const message = 'Trình duyệt không hỗ trợ định dạng ghi âm.';
227
+ setStatus('error');
228
+ setError(message);
229
+ onErrorRef.current?.(message);
230
+ return;
231
+ }
232
+ if (typeof navigator === 'undefined' || !navigator.mediaDevices?.getUserMedia) {
233
+ const message = 'Trình duyệt hoặc kết nối (HTTP) không hỗ trợ truy cập microphone.';
234
+ setStatus('error');
235
+ setError(message);
236
+ onErrorRef.current?.(message);
237
+ return;
238
+ }
239
+ try {
240
+ const stream = await navigator.mediaDevices.getUserMedia({ audio: true });
241
+ mediaStreamRef.current = stream;
242
+ mimeTypeRef.current = mimeType;
243
+ const recorder = new MediaRecorder(stream, { mimeType });
244
+ mediaRecorderRef.current = recorder;
245
+ chunksRef.current = [];
246
+ recorder.ondataavailable = (event) => {
247
+ if (event.data.size > 0) {
248
+ chunksRef.current.push(event.data);
249
+ }
250
+ };
251
+ recorder.onstop = () => {
252
+ const durationMs = Date.now() - recordStartTimeRef.current;
253
+ const blob = new Blob(chunksRef.current, { type: mimeTypeRef.current });
254
+ const url = URL.createObjectURL(blob);
255
+ // Capture the questionId that was active when recording started
256
+ const snapshotQuestionId = recordingQuestionIdRef.current;
257
+ revokePreviewUrl();
258
+ previewUrlRef.current = url;
259
+ setPreviewUrl(url);
260
+ setStatus('recorded');
261
+ // Auto-upload after recording stops — use snapshotted questionId
262
+ uploadBlob(blob, durationMs, snapshotQuestionId);
263
+ };
264
+ recorder.start();
265
+ recordStartTimeRef.current = Date.now();
266
+ // Snapshot the current questionId — this won't change even if user navigates
267
+ recordingQuestionIdRef.current = questionIdRef.current;
268
+ setStatus('recording');
269
+ setDurationSeconds(0);
270
+ setRemainingSeconds(maxDurationSeconds);
271
+ setError(null);
272
+ setUploadedKey(null);
273
+ setPreviewUrl(null);
274
+ setIsAttemptExpired(false);
275
+ // Start duration counter — counts up (elapsed) and down (remaining)
276
+ durationIntervalRef.current = setInterval(() => {
277
+ setDurationSeconds((prev) => prev + 1);
278
+ setRemainingSeconds((prev) => {
279
+ const next = Math.max(0, prev - 1);
280
+ // Auto-stop when countdown reaches zero
281
+ if (next === 0) {
282
+ stopDurationTimer();
283
+ if (mediaRecorderRef.current && mediaRecorderRef.current.state === 'recording') {
284
+ mediaRecorderRef.current.stop();
285
+ }
286
+ stopMediaStream();
287
+ }
288
+ return next;
289
+ });
290
+ }, 1000);
291
+ }
292
+ catch (err) {
293
+ stopMediaStream();
294
+ const errName = err instanceof DOMException ? err.name : err?.name;
295
+ let message = 'Không thể truy cập microphone. Vui lòng thử lại.';
296
+ if (errName === 'NotAllowedError' || errName === 'PermissionDeniedError') {
297
+ message = 'Vui lòng cấp quyền truy cập microphone trong cài đặt trình duyệt.';
298
+ }
299
+ else if (errName === 'NotFoundError' || errName === 'DevicesNotFoundError') {
300
+ message = 'Không tìm thấy thiết bị microphone nào kết nối với máy tính.';
301
+ }
302
+ else if (errName === 'NotReadableError' || errName === 'TrackStartError') {
303
+ message = 'Microphone đang được ứng dụng khác sử dụng hoặc gặp lỗi phần cứng.';
304
+ }
305
+ setStatus('error');
306
+ setError(message);
307
+ onErrorRef.current?.(message);
308
+ }
309
+ }, [isSupported, maxDurationSeconds, options.existingAnswerKey, stopDurationTimer, stopMediaStream, uploadBlob, revokePreviewUrl]);
310
+ const stopRecording = useCallback(() => {
311
+ stopDurationTimer();
312
+ if (mediaRecorderRef.current && mediaRecorderRef.current.state === 'recording') {
313
+ mediaRecorderRef.current.stop();
314
+ }
315
+ stopMediaStream();
316
+ }, [stopDurationTimer, stopMediaStream]);
317
+ const resetRecording = useCallback(() => {
318
+ stopDurationTimer();
319
+ stopMediaStream();
320
+ if (mediaRecorderRef.current && mediaRecorderRef.current.state === 'recording') {
321
+ mediaRecorderRef.current.stop();
322
+ }
323
+ mediaRecorderRef.current = null;
324
+ chunksRef.current = [];
325
+ pendingBlobRef.current = null;
326
+ pendingDurationMsRef.current = undefined;
327
+ autoRetryCountRef.current = 0;
328
+ revokePreviewUrl();
329
+ setPreviewUrl(null);
330
+ setUploadedKey(null);
331
+ setDurationSeconds(0);
332
+ setRemainingSeconds(maxDurationSeconds);
333
+ setError(null);
334
+ setStatus('idle');
335
+ setIsAttemptExpired(false);
336
+ }, [stopDurationTimer, stopMediaStream, revokePreviewUrl, maxDurationSeconds]);
337
+ const reRecord = useCallback(async () => {
338
+ if (options.existingAnswerKey) {
339
+ setStatus('uploaded');
340
+ setUploadedKey(options.existingAnswerKey);
341
+ return;
342
+ }
343
+ resetRecording();
344
+ await startRecording();
345
+ }, [options.existingAnswerKey, resetRecording, startRecording]);
346
+ const retryUpload = useCallback(async () => {
347
+ const blob = pendingBlobRef.current;
348
+ if (!blob)
349
+ return;
350
+ autoRetryCountRef.current = 0;
351
+ await performUpload(blob, pendingDurationMsRef.current, 0, recordingQuestionIdRef.current || undefined);
352
+ }, [performUpload]);
353
+ // ============================================
354
+ // Reset when questionId changes (navigating to next question)
355
+ // ============================================
356
+ useEffect(() => {
357
+ resetRecording();
358
+ // eslint-disable-next-line react-hooks/exhaustive-deps
359
+ }, [options.questionId]);
360
+ // ============================================
361
+ // Restore playback from existing answer when navigating back
362
+ // ============================================
363
+ useEffect(() => {
364
+ if (status === 'idle' && existingPresignedUrl && options.existingAnswerKey && !previewUrl) {
365
+ setPreviewUrl(existingPresignedUrl);
366
+ previewUrlRef.current = existingPresignedUrl;
367
+ setUploadedKey(options.existingAnswerKey);
368
+ setStatus('uploaded');
369
+ }
370
+ }, [status, existingPresignedUrl, options.existingAnswerKey, previewUrl]);
371
+ // ============================================
372
+ // Cleanup on unmount
373
+ // ============================================
374
+ useEffect(() => {
375
+ isMountedRef.current = true;
376
+ return () => {
377
+ isMountedRef.current = false;
378
+ stopDurationTimer();
379
+ if (mediaRecorderRef.current && mediaRecorderRef.current.state === 'recording') {
380
+ mediaRecorderRef.current.stop();
381
+ }
382
+ stopMediaStream();
383
+ revokePreviewUrl();
384
+ };
385
+ // Only run on unmount — deps intentionally empty
386
+ // eslint-disable-next-line react-hooks/exhaustive-deps
387
+ }, []);
388
+ const isWarning = remainingSeconds <= WARNING_THRESHOLD_SECONDS && status === 'recording';
389
+ return {
390
+ status,
391
+ remainingSeconds,
392
+ isWarning,
393
+ durationSeconds,
394
+ previewUrl,
395
+ uploadedKey,
396
+ error,
397
+ isSupported,
398
+ isAttemptExpired,
399
+ liveTranscript: null,
400
+ startRecording,
401
+ stopRecording,
402
+ resetRecording,
403
+ reRecord,
404
+ retryUpload,
405
+ };
406
+ }