@magmamath/students-features 0.7.1 → 0.8.0-rc.1

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 (254) hide show
  1. package/dist/commonjs/features/chatbot/components/{ChatMessages/ChatbotMessages.js → Chat/Chat.js} +8 -15
  2. package/dist/commonjs/features/chatbot/components/Chat/Chat.js.map +1 -0
  3. package/dist/commonjs/features/chatbot/components/ChatControls/ChatControls.js +1 -1
  4. package/dist/commonjs/features/chatbot/components/ChatControls/ChatControls.js.map +1 -1
  5. package/dist/commonjs/features/chatbot/components/ChatInput/ChatInput.js +74 -0
  6. package/dist/commonjs/features/chatbot/components/ChatInput/ChatInput.js.map +1 -0
  7. package/dist/commonjs/features/chatbot/components/ChatInput/FreeText/ChatTextInput.js +138 -0
  8. package/dist/commonjs/features/chatbot/components/ChatInput/FreeText/ChatTextInput.js.map +1 -0
  9. package/dist/commonjs/features/chatbot/components/ChatInput/FreeText/FreeTextInputBlock.js +66 -0
  10. package/dist/commonjs/features/chatbot/components/ChatInput/FreeText/FreeTextInputBlock.js.map +1 -0
  11. package/dist/commonjs/features/chatbot/components/ChatInput/FreeText/SendMessageButton.js +106 -0
  12. package/dist/commonjs/features/chatbot/components/ChatInput/FreeText/SendMessageButton.js.map +1 -0
  13. package/dist/commonjs/features/chatbot/components/ChatInput/RequestHintButton.js +144 -0
  14. package/dist/commonjs/features/chatbot/components/ChatInput/RequestHintButton.js.map +1 -0
  15. package/dist/commonjs/features/chatbot/components/ChatMessage/MessageLoader.js +7 -4
  16. package/dist/commonjs/features/chatbot/components/ChatMessage/MessageLoader.js.map +1 -1
  17. package/dist/commonjs/features/chatbot/components/Chatbot.js +2 -2
  18. package/dist/commonjs/features/chatbot/components/Chatbot.js.map +1 -1
  19. package/dist/commonjs/features/chatbot/constants.js +6 -1
  20. package/dist/commonjs/features/chatbot/constants.js.map +1 -1
  21. package/dist/commonjs/features/chatbot/helpers.js +76 -1
  22. package/dist/commonjs/features/chatbot/helpers.js.map +1 -1
  23. package/dist/commonjs/features/chatbot/index.js.map +1 -1
  24. package/dist/commonjs/features/chatbot/model/ChatBotModel.js +49 -11
  25. package/dist/commonjs/features/chatbot/model/ChatBotModel.js.map +1 -1
  26. package/dist/commonjs/features/chatbot/model/ChatBotTextInput.js +16 -0
  27. package/dist/commonjs/features/chatbot/model/ChatBotTextInput.js.map +1 -0
  28. package/dist/commonjs/features/chatbot/model/ChatBotThreadManager.js +11 -19
  29. package/dist/commonjs/features/chatbot/model/ChatBotThreadManager.js.map +1 -1
  30. package/dist/commonjs/features/chatbot/model/{translation.js → ChatbotTranslation.js} +29 -1
  31. package/dist/commonjs/features/chatbot/model/ChatbotTranslation.js.map +1 -0
  32. package/dist/commonjs/features/chatbot/types/model.types.js +6 -1
  33. package/dist/commonjs/features/chatbot/types/model.types.js.map +1 -1
  34. package/dist/commonjs/features/chatbot/types/units.types.js +10 -0
  35. package/dist/commonjs/features/chatbot/types/units.types.js.map +1 -1
  36. package/dist/commonjs/features/exampleSolution/components/ExampleSolutionModalContent.js +8 -0
  37. package/dist/commonjs/features/exampleSolution/components/ExampleSolutionModalContent.js.map +1 -1
  38. package/dist/commonjs/features/exampleSolution/components/LavaIcon.js +44 -0
  39. package/dist/commonjs/features/exampleSolution/components/LavaIcon.js.map +1 -0
  40. package/dist/commonjs/features/exampleSolution/components/MessageBlock.js +61 -0
  41. package/dist/commonjs/features/exampleSolution/components/MessageBlock.js.map +1 -0
  42. package/dist/commonjs/shared/hooks/useKeyDownListener.js +3 -2
  43. package/dist/commonjs/shared/hooks/useKeyDownListener.js.map +1 -1
  44. package/dist/commonjs/shared/translation/localization/ca.json +3 -2
  45. package/dist/commonjs/shared/translation/localization/en.json +3 -2
  46. package/dist/commonjs/shared/translation/localization/gb.json +3 -2
  47. package/dist/commonjs/shared/translation/localization/sct.json +3 -2
  48. package/dist/commonjs/shared/translation/localization/sw.json +3 -2
  49. package/dist/module/features/chatbot/components/{ChatMessages/ChatbotMessages.js → Chat/Chat.js} +6 -13
  50. package/dist/module/features/chatbot/components/Chat/Chat.js.map +1 -0
  51. package/dist/module/features/chatbot/components/ChatControls/ChatControls.js +1 -1
  52. package/dist/module/features/chatbot/components/ChatControls/ChatControls.js.map +1 -1
  53. package/dist/module/features/chatbot/components/ChatInput/ChatInput.js +67 -0
  54. package/dist/module/features/chatbot/components/ChatInput/ChatInput.js.map +1 -0
  55. package/dist/module/features/chatbot/components/ChatInput/FreeText/ChatTextInput.js +131 -0
  56. package/dist/module/features/chatbot/components/ChatInput/FreeText/ChatTextInput.js.map +1 -0
  57. package/dist/module/features/chatbot/components/ChatInput/FreeText/FreeTextInputBlock.js +60 -0
  58. package/dist/module/features/chatbot/components/ChatInput/FreeText/FreeTextInputBlock.js.map +1 -0
  59. package/dist/module/features/chatbot/components/ChatInput/FreeText/SendMessageButton.js +98 -0
  60. package/dist/module/features/chatbot/components/ChatInput/FreeText/SendMessageButton.js.map +1 -0
  61. package/dist/module/features/chatbot/components/ChatInput/RequestHintButton.js +138 -0
  62. package/dist/module/features/chatbot/components/ChatInput/RequestHintButton.js.map +1 -0
  63. package/dist/module/features/chatbot/components/ChatMessage/MessageLoader.js +7 -4
  64. package/dist/module/features/chatbot/components/ChatMessage/MessageLoader.js.map +1 -1
  65. package/dist/module/features/chatbot/components/Chatbot.js +2 -2
  66. package/dist/module/features/chatbot/components/Chatbot.js.map +1 -1
  67. package/dist/module/features/chatbot/constants.js +5 -0
  68. package/dist/module/features/chatbot/constants.js.map +1 -1
  69. package/dist/module/features/chatbot/helpers.js +72 -0
  70. package/dist/module/features/chatbot/helpers.js.map +1 -1
  71. package/dist/module/features/chatbot/index.js.map +1 -1
  72. package/dist/module/features/chatbot/model/ChatBotModel.js +49 -11
  73. package/dist/module/features/chatbot/model/ChatBotModel.js.map +1 -1
  74. package/dist/module/features/chatbot/model/ChatBotTextInput.js +11 -0
  75. package/dist/module/features/chatbot/model/ChatBotTextInput.js.map +1 -0
  76. package/dist/module/features/chatbot/model/ChatBotThreadManager.js +11 -19
  77. package/dist/module/features/chatbot/model/ChatBotThreadManager.js.map +1 -1
  78. package/dist/module/features/chatbot/model/{translation.js → ChatbotTranslation.js} +29 -1
  79. package/dist/module/features/chatbot/model/ChatbotTranslation.js.map +1 -0
  80. package/dist/module/features/chatbot/types/model.types.js +5 -0
  81. package/dist/module/features/chatbot/types/model.types.js.map +1 -1
  82. package/dist/module/features/chatbot/types/units.types.js +6 -0
  83. package/dist/module/features/chatbot/types/units.types.js.map +1 -1
  84. package/dist/module/features/exampleSolution/components/ExampleSolutionModalContent.js +8 -0
  85. package/dist/module/features/exampleSolution/components/ExampleSolutionModalContent.js.map +1 -1
  86. package/dist/module/features/exampleSolution/components/LavaIcon.js +36 -0
  87. package/dist/module/features/exampleSolution/components/LavaIcon.js.map +1 -0
  88. package/dist/module/features/exampleSolution/components/MessageBlock.js +53 -0
  89. package/dist/module/features/exampleSolution/components/MessageBlock.js.map +1 -0
  90. package/dist/module/shared/hooks/useKeyDownListener.js +3 -2
  91. package/dist/module/shared/hooks/useKeyDownListener.js.map +1 -1
  92. package/dist/module/shared/translation/localization/ca.json +3 -2
  93. package/dist/module/shared/translation/localization/en.json +3 -2
  94. package/dist/module/shared/translation/localization/gb.json +3 -2
  95. package/dist/module/shared/translation/localization/sct.json +3 -2
  96. package/dist/module/shared/translation/localization/sw.json +3 -2
  97. package/dist/typescript/{module/features/chatbot/components/ChatMessages/ChatbotMessages.d.ts → commonjs/features/chatbot/components/Chat/Chat.d.ts} +3 -3
  98. package/dist/typescript/commonjs/features/chatbot/components/Chat/Chat.d.ts.map +1 -0
  99. package/dist/typescript/commonjs/features/chatbot/components/ChatControls/ChatControls.d.ts +1 -1
  100. package/dist/typescript/commonjs/features/chatbot/components/ChatControls/ChatControls.d.ts.map +1 -1
  101. package/dist/typescript/commonjs/features/chatbot/components/ChatInput/ChatInput.d.ts +9 -0
  102. package/dist/typescript/commonjs/features/chatbot/components/ChatInput/ChatInput.d.ts.map +1 -0
  103. package/dist/typescript/commonjs/features/chatbot/components/ChatInput/FreeText/ChatTextInput.d.ts +16 -0
  104. package/dist/typescript/commonjs/features/chatbot/components/ChatInput/FreeText/ChatTextInput.d.ts.map +1 -0
  105. package/dist/typescript/commonjs/features/chatbot/components/ChatInput/FreeText/FreeTextInputBlock.d.ts +11 -0
  106. package/dist/typescript/commonjs/features/chatbot/components/ChatInput/FreeText/FreeTextInputBlock.d.ts.map +1 -0
  107. package/dist/typescript/commonjs/features/chatbot/components/ChatInput/FreeText/SendMessageButton.d.ts +10 -0
  108. package/dist/typescript/commonjs/features/chatbot/components/ChatInput/FreeText/SendMessageButton.d.ts.map +1 -0
  109. package/dist/typescript/commonjs/features/chatbot/components/ChatInput/RequestHintButton.d.ts +16 -0
  110. package/dist/typescript/commonjs/features/chatbot/components/ChatInput/RequestHintButton.d.ts.map +1 -0
  111. package/dist/typescript/commonjs/features/chatbot/components/ChatMessage/MessageLoader.d.ts.map +1 -1
  112. package/dist/typescript/commonjs/features/chatbot/components/Chatbot.d.ts +3 -1
  113. package/dist/typescript/commonjs/features/chatbot/components/Chatbot.d.ts.map +1 -1
  114. package/dist/typescript/commonjs/features/chatbot/constants.d.ts +5 -0
  115. package/dist/typescript/commonjs/features/chatbot/constants.d.ts.map +1 -1
  116. package/dist/typescript/commonjs/features/chatbot/helpers.d.ts +5 -0
  117. package/dist/typescript/commonjs/features/chatbot/helpers.d.ts.map +1 -1
  118. package/dist/typescript/commonjs/features/chatbot/index.d.ts.map +1 -1
  119. package/dist/typescript/commonjs/features/chatbot/model/ChatBotModel.d.ts +5 -6
  120. package/dist/typescript/commonjs/features/chatbot/model/ChatBotModel.d.ts.map +1 -1
  121. package/dist/typescript/commonjs/features/chatbot/model/ChatBotTextInput.d.ts +8 -0
  122. package/dist/typescript/commonjs/features/chatbot/model/ChatBotTextInput.d.ts.map +1 -0
  123. package/dist/typescript/commonjs/features/chatbot/model/ChatBotThreadManager.d.ts +3 -2
  124. package/dist/typescript/commonjs/features/chatbot/model/ChatBotThreadManager.d.ts.map +1 -1
  125. package/dist/typescript/{module/features/chatbot/model/translation.d.ts → commonjs/features/chatbot/model/ChatbotTranslation.d.ts} +3 -2
  126. package/dist/typescript/commonjs/features/chatbot/model/ChatbotTranslation.d.ts.map +1 -0
  127. package/dist/typescript/commonjs/features/chatbot/types/api.types.d.ts +28 -6
  128. package/dist/typescript/commonjs/features/chatbot/types/api.types.d.ts.map +1 -1
  129. package/dist/typescript/commonjs/features/chatbot/types/model.types.d.ts +28 -3
  130. package/dist/typescript/commonjs/features/chatbot/types/model.types.d.ts.map +1 -1
  131. package/dist/typescript/commonjs/features/chatbot/types/translation.types.d.ts +5 -0
  132. package/dist/typescript/commonjs/features/chatbot/types/translation.types.d.ts.map +1 -1
  133. package/dist/typescript/commonjs/features/chatbot/types/units.types.d.ts +5 -0
  134. package/dist/typescript/commonjs/features/chatbot/types/units.types.d.ts.map +1 -1
  135. package/dist/typescript/commonjs/features/exampleSolution/components/ExampleSolutionModalContent.d.ts.map +1 -1
  136. package/dist/typescript/commonjs/features/exampleSolution/components/LavaIcon.d.ts +10 -0
  137. package/dist/typescript/commonjs/features/exampleSolution/components/LavaIcon.d.ts.map +1 -0
  138. package/dist/typescript/commonjs/features/exampleSolution/components/MessageBlock.d.ts +10 -0
  139. package/dist/typescript/commonjs/features/exampleSolution/components/MessageBlock.d.ts.map +1 -0
  140. package/dist/typescript/commonjs/shared/hooks/useKeyDownListener.d.ts +1 -1
  141. package/dist/typescript/commonjs/shared/hooks/useKeyDownListener.d.ts.map +1 -1
  142. package/dist/typescript/commonjs/shared/hooks/useKeyboard.d.ts +1 -1
  143. package/dist/typescript/commonjs/shared/hooks/useKeyboard.d.ts.map +1 -1
  144. package/dist/typescript/commonjs/shared/translation/constants.d.ts +5 -0
  145. package/dist/typescript/commonjs/shared/translation/constants.d.ts.map +1 -1
  146. package/dist/typescript/commonjs/shared/translation/model.d.ts +2 -0
  147. package/dist/typescript/commonjs/shared/translation/model.d.ts.map +1 -1
  148. package/dist/typescript/{commonjs/features/chatbot/components/ChatMessages/ChatbotMessages.d.ts → module/features/chatbot/components/Chat/Chat.d.ts} +3 -3
  149. package/dist/typescript/module/features/chatbot/components/Chat/Chat.d.ts.map +1 -0
  150. package/dist/typescript/module/features/chatbot/components/ChatControls/ChatControls.d.ts +1 -1
  151. package/dist/typescript/module/features/chatbot/components/ChatControls/ChatControls.d.ts.map +1 -1
  152. package/dist/typescript/module/features/chatbot/components/ChatInput/ChatInput.d.ts +9 -0
  153. package/dist/typescript/module/features/chatbot/components/ChatInput/ChatInput.d.ts.map +1 -0
  154. package/dist/typescript/module/features/chatbot/components/ChatInput/FreeText/ChatTextInput.d.ts +16 -0
  155. package/dist/typescript/module/features/chatbot/components/ChatInput/FreeText/ChatTextInput.d.ts.map +1 -0
  156. package/dist/typescript/module/features/chatbot/components/ChatInput/FreeText/FreeTextInputBlock.d.ts +11 -0
  157. package/dist/typescript/module/features/chatbot/components/ChatInput/FreeText/FreeTextInputBlock.d.ts.map +1 -0
  158. package/dist/typescript/module/features/chatbot/components/ChatInput/FreeText/SendMessageButton.d.ts +10 -0
  159. package/dist/typescript/module/features/chatbot/components/ChatInput/FreeText/SendMessageButton.d.ts.map +1 -0
  160. package/dist/typescript/module/features/chatbot/components/ChatInput/RequestHintButton.d.ts +16 -0
  161. package/dist/typescript/module/features/chatbot/components/ChatInput/RequestHintButton.d.ts.map +1 -0
  162. package/dist/typescript/module/features/chatbot/components/ChatMessage/MessageLoader.d.ts.map +1 -1
  163. package/dist/typescript/module/features/chatbot/components/Chatbot.d.ts +3 -1
  164. package/dist/typescript/module/features/chatbot/components/Chatbot.d.ts.map +1 -1
  165. package/dist/typescript/module/features/chatbot/constants.d.ts +5 -0
  166. package/dist/typescript/module/features/chatbot/constants.d.ts.map +1 -1
  167. package/dist/typescript/module/features/chatbot/helpers.d.ts +5 -0
  168. package/dist/typescript/module/features/chatbot/helpers.d.ts.map +1 -1
  169. package/dist/typescript/module/features/chatbot/index.d.ts.map +1 -1
  170. package/dist/typescript/module/features/chatbot/model/ChatBotModel.d.ts +5 -6
  171. package/dist/typescript/module/features/chatbot/model/ChatBotModel.d.ts.map +1 -1
  172. package/dist/typescript/module/features/chatbot/model/ChatBotTextInput.d.ts +8 -0
  173. package/dist/typescript/module/features/chatbot/model/ChatBotTextInput.d.ts.map +1 -0
  174. package/dist/typescript/module/features/chatbot/model/ChatBotThreadManager.d.ts +3 -2
  175. package/dist/typescript/module/features/chatbot/model/ChatBotThreadManager.d.ts.map +1 -1
  176. package/dist/typescript/{commonjs/features/chatbot/model/translation.d.ts → module/features/chatbot/model/ChatbotTranslation.d.ts} +3 -2
  177. package/dist/typescript/module/features/chatbot/model/ChatbotTranslation.d.ts.map +1 -0
  178. package/dist/typescript/module/features/chatbot/types/api.types.d.ts +28 -6
  179. package/dist/typescript/module/features/chatbot/types/api.types.d.ts.map +1 -1
  180. package/dist/typescript/module/features/chatbot/types/model.types.d.ts +28 -3
  181. package/dist/typescript/module/features/chatbot/types/model.types.d.ts.map +1 -1
  182. package/dist/typescript/module/features/chatbot/types/translation.types.d.ts +5 -0
  183. package/dist/typescript/module/features/chatbot/types/translation.types.d.ts.map +1 -1
  184. package/dist/typescript/module/features/chatbot/types/units.types.d.ts +5 -0
  185. package/dist/typescript/module/features/chatbot/types/units.types.d.ts.map +1 -1
  186. package/dist/typescript/module/features/exampleSolution/components/ExampleSolutionModalContent.d.ts.map +1 -1
  187. package/dist/typescript/module/features/exampleSolution/components/LavaIcon.d.ts +10 -0
  188. package/dist/typescript/module/features/exampleSolution/components/LavaIcon.d.ts.map +1 -0
  189. package/dist/typescript/module/features/exampleSolution/components/MessageBlock.d.ts +10 -0
  190. package/dist/typescript/module/features/exampleSolution/components/MessageBlock.d.ts.map +1 -0
  191. package/dist/typescript/module/shared/hooks/useKeyDownListener.d.ts +1 -1
  192. package/dist/typescript/module/shared/hooks/useKeyDownListener.d.ts.map +1 -1
  193. package/dist/typescript/module/shared/hooks/useKeyboard.d.ts +1 -1
  194. package/dist/typescript/module/shared/hooks/useKeyboard.d.ts.map +1 -1
  195. package/dist/typescript/module/shared/translation/constants.d.ts +5 -0
  196. package/dist/typescript/module/shared/translation/constants.d.ts.map +1 -1
  197. package/dist/typescript/module/shared/translation/model.d.ts +2 -0
  198. package/dist/typescript/module/shared/translation/model.d.ts.map +1 -1
  199. package/package.json +1 -1
  200. package/src/features/chatbot/components/{ChatMessages/ChatbotMessages.tsx → Chat/Chat.tsx} +13 -18
  201. package/src/features/chatbot/components/ChatControls/ChatControls.tsx +2 -2
  202. package/src/features/chatbot/components/ChatInput/ChatInput.tsx +88 -0
  203. package/src/features/chatbot/components/ChatInput/FreeText/ChatTextInput.tsx +156 -0
  204. package/src/features/chatbot/components/ChatInput/FreeText/FreeTextInputBlock.tsx +71 -0
  205. package/src/features/chatbot/components/ChatInput/FreeText/SendMessageButton.tsx +111 -0
  206. package/src/features/chatbot/components/ChatInput/RequestHintButton.tsx +156 -0
  207. package/src/features/chatbot/components/ChatMessage/MessageLoader.tsx +6 -2
  208. package/src/features/chatbot/components/Chatbot.tsx +5 -3
  209. package/src/features/chatbot/constants.ts +7 -0
  210. package/src/features/chatbot/helpers.ts +71 -1
  211. package/src/features/chatbot/index.ts +1 -0
  212. package/src/features/chatbot/model/ChatBotModel.ts +82 -37
  213. package/src/features/chatbot/model/ChatBotTextInput.ts +10 -0
  214. package/src/features/chatbot/model/ChatBotThreadManager.ts +17 -19
  215. package/src/features/chatbot/model/{translation.ts → ChatbotTranslation.ts} +32 -2
  216. package/src/features/chatbot/types/api.types.ts +31 -6
  217. package/src/features/chatbot/types/model.types.ts +35 -2
  218. package/src/features/chatbot/types/translation.types.ts +6 -0
  219. package/src/features/chatbot/types/units.types.ts +6 -0
  220. package/src/features/exampleSolution/components/ExampleSolutionModalContent.tsx +4 -0
  221. package/src/features/exampleSolution/components/LavaIcon.tsx +35 -0
  222. package/src/features/exampleSolution/components/MessageBlock.tsx +67 -0
  223. package/src/shared/hooks/useKeyDownListener.ts +3 -1
  224. package/src/shared/translation/localization/ca.json +3 -2
  225. package/src/shared/translation/localization/en.json +3 -2
  226. package/src/shared/translation/localization/gb.json +3 -2
  227. package/src/shared/translation/localization/sct.json +3 -2
  228. package/src/shared/translation/localization/sw.json +3 -2
  229. package/dist/commonjs/features/chatbot/components/Alternatives/Alternatives.js +0 -59
  230. package/dist/commonjs/features/chatbot/components/Alternatives/Alternatives.js.map +0 -1
  231. package/dist/commonjs/features/chatbot/components/Alternatives/HelpRequestOption.js +0 -99
  232. package/dist/commonjs/features/chatbot/components/Alternatives/HelpRequestOption.js.map +0 -1
  233. package/dist/commonjs/features/chatbot/components/ChatMessages/ChatbotMessages.js.map +0 -1
  234. package/dist/commonjs/features/chatbot/model/translation.js.map +0 -1
  235. package/dist/module/features/chatbot/components/Alternatives/Alternatives.js +0 -53
  236. package/dist/module/features/chatbot/components/Alternatives/Alternatives.js.map +0 -1
  237. package/dist/module/features/chatbot/components/Alternatives/HelpRequestOption.js +0 -92
  238. package/dist/module/features/chatbot/components/Alternatives/HelpRequestOption.js.map +0 -1
  239. package/dist/module/features/chatbot/components/ChatMessages/ChatbotMessages.js.map +0 -1
  240. package/dist/module/features/chatbot/model/translation.js.map +0 -1
  241. package/dist/typescript/commonjs/features/chatbot/components/Alternatives/Alternatives.d.ts +0 -11
  242. package/dist/typescript/commonjs/features/chatbot/components/Alternatives/Alternatives.d.ts.map +0 -1
  243. package/dist/typescript/commonjs/features/chatbot/components/Alternatives/HelpRequestOption.d.ts +0 -10
  244. package/dist/typescript/commonjs/features/chatbot/components/Alternatives/HelpRequestOption.d.ts.map +0 -1
  245. package/dist/typescript/commonjs/features/chatbot/components/ChatMessages/ChatbotMessages.d.ts.map +0 -1
  246. package/dist/typescript/commonjs/features/chatbot/model/translation.d.ts.map +0 -1
  247. package/dist/typescript/module/features/chatbot/components/Alternatives/Alternatives.d.ts +0 -11
  248. package/dist/typescript/module/features/chatbot/components/Alternatives/Alternatives.d.ts.map +0 -1
  249. package/dist/typescript/module/features/chatbot/components/Alternatives/HelpRequestOption.d.ts +0 -10
  250. package/dist/typescript/module/features/chatbot/components/Alternatives/HelpRequestOption.d.ts.map +0 -1
  251. package/dist/typescript/module/features/chatbot/components/ChatMessages/ChatbotMessages.d.ts.map +0 -1
  252. package/dist/typescript/module/features/chatbot/model/translation.d.ts.map +0 -1
  253. package/src/features/chatbot/components/Alternatives/Alternatives.tsx +0 -60
  254. package/src/features/chatbot/components/Alternatives/HelpRequestOption.tsx +0 -91
@@ -0,0 +1,156 @@
1
+ import React, { useRef, useState } from 'react'
2
+ import Animated, { useAnimatedStyle, useSharedValue, withTiming } from 'react-native-reanimated'
3
+ import {
4
+ NativeSyntheticEvent,
5
+ Platform,
6
+ StyleSheet,
7
+ TextInput,
8
+ TextInputFocusEventData,
9
+ } from 'react-native'
10
+ import { COLORS, FONT_FAMILY, SPACING } from '@magmamath/react-native-ui'
11
+ import { ColorScheme } from '@magmamath/students-features'
12
+ import { useKeyBoard } from '../../../../../shared/hooks/useKeyboard'
13
+ import { KeyboardKeys } from '../../../../../lib/constants'
14
+
15
+ import { SendMessageButton } from './SendMessageButton'
16
+
17
+ const MAX_AVAILABLE_MESSAGE_LENGTH = 500
18
+ const COMPACT_WIDTH = 134
19
+ const FULL_WIDTH = 305
20
+ const ANIMATION_DURATION = 200
21
+
22
+ type ChatTextInputProps = {
23
+ value: string
24
+ onSubmit: () => void
25
+ submitDisabled?: boolean
26
+ onChangeText?: (text: string) => void
27
+ onBlur?: (e: NativeSyntheticEvent<TextInputFocusEventData>) => void
28
+ onFocus?: (e: NativeSyntheticEvent<TextInputFocusEventData>) => void
29
+ placeholder?: string
30
+ colorScheme?: ColorScheme
31
+ }
32
+
33
+ export const ChatTextInput = ({
34
+ value,
35
+ submitDisabled,
36
+ onSubmit,
37
+ onChangeText,
38
+ onBlur,
39
+ onFocus,
40
+ colorScheme = ColorScheme.Blue,
41
+ placeholder,
42
+ }: ChatTextInputProps) => {
43
+ const inputRef = useRef<TextInput>(null)
44
+ const [isFocused, setIsFocused] = useState(false)
45
+ const widthSv = useSharedValue(value ? FULL_WIDTH : COMPACT_WIDTH )
46
+
47
+ const animatedStyle = useAnimatedStyle(
48
+ () => ({
49
+ width: widthSv.value,
50
+ }),
51
+ [widthSv],
52
+ )
53
+
54
+ const handleInputChange = (text: string) => {
55
+ if (text.length > MAX_AVAILABLE_MESSAGE_LENGTH) return
56
+
57
+ onChangeText?.(text)
58
+
59
+ const hasText = text.trim().length > 0
60
+ const isExpanded = widthSv.value > COMPACT_WIDTH
61
+ const shouldCollapseInput = !hasText && isExpanded
62
+ const shouldExpandInput = hasText && !isExpanded
63
+
64
+ if (shouldExpandInput) {
65
+ widthSv.value = withTiming(FULL_WIDTH, { duration: ANIMATION_DURATION })
66
+ } else if (shouldCollapseInput) {
67
+ widthSv.value = withTiming(COMPACT_WIDTH, { duration: ANIMATION_DURATION })
68
+ }
69
+ }
70
+
71
+ const handleSendMessage = () => {
72
+ if (submitDisabled || value.trim().length < 1 || value.length > MAX_AVAILABLE_MESSAGE_LENGTH)
73
+ return
74
+
75
+ onSubmit?.()
76
+ handleInputChange('')
77
+ inputRef.current?.focus()
78
+ }
79
+
80
+ const handleOnFocus = (e: NativeSyntheticEvent<TextInputFocusEventData>) => {
81
+ setIsFocused(true)
82
+ onFocus?.(e)
83
+ }
84
+
85
+ const handleOnBlur = (e: NativeSyntheticEvent<TextInputFocusEventData>) => {
86
+ setIsFocused(false)
87
+ onBlur?.(e)
88
+ }
89
+
90
+ useKeyBoard((event) => {
91
+ if (event.key === KeyboardKeys.ENTER) {
92
+ void handleSendMessage()
93
+ }
94
+ }, isFocused)
95
+
96
+ return (
97
+ <Animated.View style={[styles.inputWrapper, animatedStyle]}>
98
+ <TextInput
99
+ ref={inputRef}
100
+ value={value}
101
+ onChangeText={handleInputChange}
102
+ onBlur={handleOnBlur}
103
+ onFocus={handleOnFocus}
104
+ placeholder={placeholder}
105
+ placeholderTextColor={COLORS.NEUTRAL_6}
106
+ style={styles.input}
107
+ />
108
+ <SendMessageButton
109
+ onPress={handleSendMessage}
110
+ disabled={!!submitDisabled}
111
+ colorScheme={colorScheme}
112
+ />
113
+ </Animated.View>
114
+ )
115
+ }
116
+
117
+ const styles = StyleSheet.create({
118
+ container: {
119
+ position: 'relative',
120
+ width: '100%',
121
+ alignItems: 'flex-end',
122
+ height: 52,
123
+ justifyContent: 'center',
124
+ },
125
+ inputWrapper: {
126
+ position: 'absolute',
127
+ zIndex: 1,
128
+ left: 0,
129
+ flexDirection: 'row',
130
+ borderWidth: 1,
131
+ borderColor: COLORS.NEUTRAL_5,
132
+ borderRadius: 200,
133
+ backgroundColor: COLORS.NEUTRAL_1,
134
+ paddingHorizontal: SPACING[100],
135
+ paddingVertical: SPACING[100],
136
+ elevation: 3,
137
+ shadowColor: '#333',
138
+ shadowOffset: { width: 0, height: 1 },
139
+ shadowOpacity: 0.25,
140
+ shadowRadius: 3,
141
+ },
142
+ input: {
143
+ flex: 1,
144
+ fontSize: 16,
145
+ minWidth: 60,
146
+ minHeight: 22,
147
+ fontWeight: '400',
148
+ fontFamily: FONT_FAMILY.buenosAires,
149
+ paddingHorizontal: SPACING[200],
150
+ paddingVertical: SPACING[200],
151
+ ...(Platform.OS === 'web' && { outlineStyle: 'none' }),
152
+ },
153
+ arrowWrapper: {
154
+ marginLeft: SPACING[200],
155
+ },
156
+ })
@@ -0,0 +1,71 @@
1
+ import React from 'react'
2
+ import { useUnit } from 'effector-react'
3
+ import { StyleSheet, View } from 'react-native'
4
+ import { ColorScheme } from '../../../types/style.types'
5
+ import { HintButtonVariant, RequestHintButton } from '../RequestHintButton'
6
+ import { useChatModel } from '../../../context/ChatBotModelContext'
7
+ import { t } from '../../../../../shared/translation'
8
+ import { ChatTextInput } from './ChatTextInput'
9
+
10
+ type FreeTextInputBlockProps = {
11
+ optionLabel: string
12
+ disabled: boolean
13
+ onOptionPress: () => void
14
+ colorScheme?: ColorScheme
15
+ }
16
+
17
+ export const FreeTextInputBlock = ({
18
+ optionLabel,
19
+ onOptionPress,
20
+ disabled,
21
+ colorScheme,
22
+ }: FreeTextInputBlockProps) => {
23
+ const model = useChatModel()
24
+ const inputValue = useUnit(model.textInput.$value)
25
+
26
+ const handleOnSubmit = async () => {
27
+ const translatedMessage = await model.translation.translateSingleMessageFx(inputValue)
28
+
29
+ void model.textInput.setValue('')
30
+ void model.sendHelpRequestFx({
31
+ message: inputValue,
32
+ translatedMessage,
33
+ isFreeText: true,
34
+ })
35
+ }
36
+ const handleOnBlur = () => model.textInput.setIsFocused(false)
37
+ const handleOnFocus = () => model.textInput.setIsFocused(true)
38
+ const handleOnChangeText = (text: string) => model.textInput.setValue(text)
39
+
40
+ return (
41
+ <View style={styles.container}>
42
+ <ChatTextInput
43
+ value={inputValue}
44
+ onSubmit={handleOnSubmit}
45
+ onChangeText={handleOnChangeText}
46
+ onBlur={handleOnBlur}
47
+ onFocus={handleOnFocus}
48
+ submitDisabled={disabled || inputValue.trim().length < 1}
49
+ colorScheme={colorScheme}
50
+ placeholder={t('chat.inputPlaceholder')}
51
+ />
52
+ <RequestHintButton
53
+ onPress={onOptionPress}
54
+ label={optionLabel}
55
+ disabled={disabled}
56
+ colorScheme={colorScheme}
57
+ variant={HintButtonVariant.Short}
58
+ />
59
+ </View>
60
+ )
61
+ }
62
+
63
+ const styles = StyleSheet.create({
64
+ container: {
65
+ position: 'relative',
66
+ width: '100%',
67
+ alignItems: 'flex-end',
68
+ height: 52,
69
+ justifyContent: 'center',
70
+ },
71
+ })
@@ -0,0 +1,111 @@
1
+ import React from 'react'
2
+ import { Pressable, StyleSheet } from 'react-native'
3
+ import Animated, {
4
+ useSharedValue,
5
+ withTiming,
6
+ useAnimatedStyle,
7
+ interpolateColor,
8
+ } from 'react-native-reanimated'
9
+ import { ArrowUpIcon, COLORS, IS_MOBILE } from '@magmamath/react-native-ui'
10
+ import { ColorScheme } from '@magmamath/students-features'
11
+ import { MESSAGE_COLORS_MAP } from '../../../constants'
12
+
13
+ type SendMessageButtonProps = {
14
+ onPress: () => void
15
+ disabled: boolean
16
+ colorScheme?: ColorScheme
17
+ }
18
+
19
+ export const SendMessageButton = ({
20
+ onPress,
21
+ disabled = false,
22
+ colorScheme = ColorScheme.Blue,
23
+ }: SendMessageButtonProps) => {
24
+ const hoverSv = useSharedValue(0)
25
+
26
+ const onHoverIn = () => {
27
+ if (!disabled) hoverSv.value = withTiming(1, { duration: 200 })
28
+ }
29
+ const onHoverOut = () => {
30
+ if (!disabled) hoverSv.value = withTiming(0, { duration: 200 })
31
+ }
32
+
33
+ const animatedIconStyle = useAnimatedStyle(() => {
34
+ const backgroundColor = interpolateColor(
35
+ hoverSv.value,
36
+ [0, 1],
37
+ [COLORS.NEUTRAL_1, MESSAGE_COLORS_MAP[colorScheme].sent.border],
38
+ )
39
+ const color = interpolateColor(hoverSv.value, [0, 1], [COLORS.NEUTRAL_10, COLORS.NEUTRAL_1])
40
+
41
+ return {
42
+ backgroundColor: disabled ? COLORS.NEUTRAL_2 : backgroundColor,
43
+ borderColor: disabled ? COLORS.NEUTRAL_5 : MESSAGE_COLORS_MAP[colorScheme].sent.border,
44
+ color: disabled ? COLORS.NEUTRAL_5 : color,
45
+ }
46
+ }, [hoverSv, disabled])
47
+
48
+ return (
49
+ <Pressable
50
+ onHoverIn={onHoverIn}
51
+ onHoverOut={onHoverOut}
52
+ onPress={onPress}
53
+ style={[styles.button, disabled && { cursor: 'auto' }]}
54
+ disabled={disabled}
55
+ accessibilityState={{ disabled }}
56
+ accessibilityRole="button"
57
+ >
58
+ {IS_MOBILE ? (
59
+ <Animated.View
60
+ style={[
61
+ styles.iconContainer,
62
+ animatedIconStyle,
63
+ {
64
+ borderColor: disabled
65
+ ? COLORS.NEUTRAL_5
66
+ : MESSAGE_COLORS_MAP[colorScheme].sent.border,
67
+ },
68
+ ]}
69
+ >
70
+ <ArrowUpIcon color={'currentColor'} size={16} />
71
+ </Animated.View>
72
+ ) : (
73
+ <Animated.Text style={[styles.webIconContainer, animatedIconStyle]}>
74
+ <ArrowUpIcon color={'currentColor'} size={16} />
75
+ </Animated.Text>
76
+ )}
77
+ </Pressable>
78
+ )
79
+ }
80
+
81
+ const styles = StyleSheet.create({
82
+ button: {
83
+ flexDirection: 'row',
84
+ justifyContent: 'flex-end',
85
+ height: 44,
86
+ width: 44,
87
+ },
88
+ iconContainer: {
89
+ justifyContent: 'center',
90
+ alignItems: 'center',
91
+ padding: 12,
92
+ borderRadius: 21,
93
+ borderWidth: 1,
94
+ },
95
+ webIconContainer: {
96
+ flex: 1,
97
+ flexDirection: 'row',
98
+ alignItems: 'center',
99
+ paddingHorizontal: 13,
100
+ paddingVertical: 12,
101
+ borderWidth: 1,
102
+ borderRadius: 48,
103
+ elevation: 3,
104
+ shadowColor: '#333',
105
+ shadowOffset: { width: 0, height: 1 },
106
+ shadowOpacity: 0.25,
107
+ shadowRadius: 3,
108
+ backgroundColor: COLORS.NEUTRAL_1,
109
+ borderColor: COLORS.PRIMARY_BLUE,
110
+ },
111
+ })
@@ -0,0 +1,156 @@
1
+ import { Pressable, StyleSheet } from 'react-native'
2
+ import React, { memo } from 'react'
3
+ import Animated, {
4
+ useSharedValue,
5
+ withTiming,
6
+ useAnimatedStyle,
7
+ interpolateColor,
8
+ } from 'react-native-reanimated'
9
+ import {
10
+ ArrowRightIcon,
11
+ ArrowUpIcon,
12
+ COLORS,
13
+ FONT_FAMILY,
14
+ IS_MOBILE,
15
+ SPACING,
16
+ } from '@magmamath/react-native-ui'
17
+ import { ColorScheme } from '@magmamath/students-features'
18
+ import { MESSAGE_COLORS_MAP } from '../../constants'
19
+
20
+ export enum HintButtonVariant {
21
+ Default = 'default',
22
+ Short = 'short',
23
+ }
24
+
25
+ const HOVER_ANIMATION_DURATION = 200
26
+
27
+ const REQUEST_HINT_BUTTON = {
28
+ [HintButtonVariant.Default]: {
29
+ width: 305,
30
+ fontSize: 20,
31
+ },
32
+ [HintButtonVariant.Short]: { width: 163, fontSize: 18 },
33
+ }
34
+
35
+ type RequestHintButtonProps = {
36
+ onPress: () => void
37
+ label: string
38
+ disabled: boolean
39
+ colorScheme?: ColorScheme
40
+ variant: HintButtonVariant
41
+ }
42
+
43
+ export const RequestHintButton = memo(
44
+ ({
45
+ onPress,
46
+ label,
47
+ disabled = false,
48
+ colorScheme = ColorScheme.Blue,
49
+ variant = HintButtonVariant.Default,
50
+ }: RequestHintButtonProps) => {
51
+ const hoverSv = useSharedValue(0)
52
+
53
+ const onHoverIn = () => {
54
+ if (!disabled) hoverSv.value = withTiming(1, { duration: HOVER_ANIMATION_DURATION })
55
+ }
56
+ const onHoverOut = () => {
57
+ if (!disabled) hoverSv.value = withTiming(0, { duration: HOVER_ANIMATION_DURATION })
58
+ }
59
+
60
+ const animatedTextContainerStyle = useAnimatedStyle(() => {
61
+ if (disabled) {
62
+ return {
63
+ backgroundColor: COLORS.NEUTRAL_2,
64
+ borderColor: COLORS.NEUTRAL_5,
65
+ }
66
+ }
67
+
68
+ const defaultBorderColor =
69
+ variant === HintButtonVariant.Default
70
+ ? COLORS.NEUTRAL_1
71
+ : MESSAGE_COLORS_MAP[colorScheme].sent.border
72
+
73
+ return {
74
+ backgroundColor: interpolateColor(
75
+ hoverSv.value,
76
+ [0, 1],
77
+ [COLORS.NEUTRAL_1, MESSAGE_COLORS_MAP[colorScheme].sent.background],
78
+ ),
79
+ borderColor: interpolateColor(
80
+ hoverSv.value,
81
+ [0, 1],
82
+ [defaultBorderColor, MESSAGE_COLORS_MAP[colorScheme].sent.border],
83
+ ),
84
+ }
85
+ }, [hoverSv, disabled, colorScheme])
86
+
87
+ const animatedTextStyle = useAnimatedStyle(() => {
88
+ if (disabled) return { color: COLORS.NEUTRAL_5 }
89
+
90
+ return {
91
+ color: interpolateColor(hoverSv.value, [0, 1], [COLORS.NEUTRAL_10, COLORS.NEUTRAL_1]),
92
+ }
93
+ }, [hoverSv, disabled])
94
+
95
+ const iconColor = disabled ? COLORS.NEUTRAL_5 : 'currentColor'
96
+ const { width, fontSize } = REQUEST_HINT_BUTTON[variant]
97
+
98
+ return (
99
+ <Pressable
100
+ onHoverIn={onHoverIn}
101
+ onHoverOut={onHoverOut}
102
+ onPress={onPress}
103
+ style={[styles.button, { cursor: disabled ? 'auto' : 'pointer', width }]}
104
+ disabled={disabled}
105
+ accessibilityState={{ disabled }}
106
+ accessibilityRole="button"
107
+ >
108
+ <Animated.View style={[styles.content, animatedTextContainerStyle]}>
109
+ <Animated.Text numberOfLines={1} style={[styles.text, animatedTextStyle, { fontSize }]}>
110
+ {label}
111
+ </Animated.Text>
112
+
113
+ <Animated.Text style={[styles.iconWrapper, animatedTextStyle]}>
114
+ {variant === HintButtonVariant.Default ? (
115
+ <ArrowRightIcon color={iconColor} size={16} />
116
+ ) : (
117
+ <ArrowUpIcon color={iconColor} size={16} />
118
+ )}
119
+ </Animated.Text>
120
+ </Animated.View>
121
+ </Pressable>
122
+ )
123
+ },
124
+ )
125
+
126
+ const styles = StyleSheet.create({
127
+ button: {
128
+ flexDirection: 'row',
129
+ justifyContent: 'flex-end',
130
+ },
131
+ text: {
132
+ fontWeight: '400',
133
+ fontFamily: FONT_FAMILY.buenosAires,
134
+ color: COLORS.NEUTRAL_10,
135
+ },
136
+ content: {
137
+ height: 44,
138
+ flex: 1,
139
+ flexDirection: 'row',
140
+ alignItems: 'center',
141
+ justifyContent: 'space-between',
142
+ paddingHorizontal: SPACING[400],
143
+ borderWidth: 1,
144
+ borderRadius: 48,
145
+ elevation: 3,
146
+ shadowColor: '#333',
147
+ shadowOffset: { width: 0, height: 1 },
148
+ shadowOpacity: 0.25,
149
+ shadowRadius: 3,
150
+ backgroundColor: COLORS.PRIMARY_BLUE,
151
+ borderColor: COLORS.PRIMARY_BLUE,
152
+ },
153
+ iconWrapper: {
154
+ top: IS_MOBILE ? 3 : 0,
155
+ },
156
+ })
@@ -6,6 +6,7 @@ import { ChatbotIcon } from '../../../../shared/icons/ChatbotIcon'
6
6
  import { ThreeDotsLoader } from '../ThreeDotsLoader/ThreeDotsLoader'
7
7
  import { CONTROLS_COLORS_MAP } from '../../constants'
8
8
  import { ColorScheme } from '../../types/style.types'
9
+ import { LavaIconInGlasses } from '@magmamath/students-features'
9
10
 
10
11
  type MessageLoaderProps = {
11
12
  colorScheme?: ColorScheme
@@ -14,7 +15,7 @@ type MessageLoaderProps = {
14
15
  export const MessageLoader = ({ colorScheme = ColorScheme.Blue }: MessageLoaderProps) => (
15
16
  <View style={styles.container}>
16
17
  <View style={styles.icon}>
17
- <ChatbotIcon width={60} height={80} />
18
+ <LavaIconInGlasses width={60} height={80} />
18
19
  </View>
19
20
  <View style={styles.loader}>
20
21
  <ThreeDotsLoader backgroundColor={CONTROLS_COLORS_MAP[colorScheme].background} />
@@ -27,10 +28,13 @@ const styles = StyleSheet.create({
27
28
  flexDirection: 'row',
28
29
  width: 327,
29
30
  alignItems: 'flex-end',
31
+ paddingLeft:70
30
32
  },
31
33
  icon: {
34
+ position: 'absolute',
35
+ zIndex:1,
32
36
  alignSelf: 'flex-end',
33
- marginRight: 8,
37
+ left: 0
34
38
  },
35
39
  loader: {
36
40
  flex: 1,
@@ -2,11 +2,12 @@ import React, { ComponentType, PropsWithChildren } from 'react'
2
2
  import { useStoreMap, useUnit } from 'effector-react'
3
3
 
4
4
  import { ChatbotModel } from '../model/ChatBotModel'
5
- import { ChatbotMessages } from './ChatMessages/ChatbotMessages'
5
+ import { Chat } from './Chat/Chat'
6
6
  import { ChatControls } from './ChatControls/ChatControls'
7
7
  import { AUDIO_CONFIG, DEFAULT_VOICE } from '../constants'
8
8
  import { ChatBotModelContext } from '../context/ChatBotModelContext'
9
9
  import { ColorScheme } from '../types/style.types'
10
+ import { ChatInputMode } from '../types/units.types'
10
11
 
11
12
  type ChatbotProps = {
12
13
  model: ChatbotModel
@@ -16,7 +17,8 @@ type ChatbotProps = {
16
17
  voice: typeof DEFAULT_VOICE
17
18
  audioConfig: typeof AUDIO_CONFIG
18
19
  }
19
- ButtonWrapper: ComponentType<PropsWithChildren>
20
+ inputMode?: ChatInputMode
21
+ ButtonWrapper?: ComponentType<PropsWithChildren>
20
22
  iconSize?: { width: number; height: number } // TODO: use number instead
21
23
  colorScheme?: ColorScheme
22
24
  }
@@ -43,7 +45,7 @@ export const Chatbot = ({
43
45
 
44
46
  return (
45
47
  <ChatBotModelContext.Provider value={model}>
46
- <ChatbotMessages
48
+ <Chat
47
49
  model={model}
48
50
  colorScheme={colorScheme}
49
51
  isHintFeedback={isHintFeedback}
@@ -2,6 +2,7 @@ import { ButtonColor, COLORS } from '@magmamath/react-native-ui'
2
2
  import { Platform } from 'react-native'
3
3
  import { MessageVariant } from './types/model.types'
4
4
  import { ColorScheme } from './types/style.types'
5
+ import { ANIMATION_DURATION } from '../gifCelebrations/constants'
5
6
 
6
7
  export const AUDIO_CONFIG = {
7
8
  audioEncoding: 'LINEAR16',
@@ -44,20 +45,24 @@ export const MESSAGE_COLORS_MAP = {
44
45
  [ColorScheme.Blue]: {
45
46
  [MessageVariant.RECEIVED]: {
46
47
  background: COLORS.NEUTRAL_3,
48
+ border: COLORS.NEUTRAL_3,
47
49
  icon: ButtonColor.BLUE,
48
50
  },
49
51
  [MessageVariant.SENT]: {
50
52
  background: COLORS.PRIMARY_BLUE,
53
+ border: COLORS.PRIMARY_BLUE,
51
54
  icon: ButtonColor.BLUE,
52
55
  },
53
56
  },
54
57
  [ColorScheme.Yellow]: {
55
58
  [MessageVariant.RECEIVED]: {
56
59
  background: COLORS.NEUTRAL_3,
60
+ border: COLORS.NEUTRAL_3,
57
61
  icon: ButtonColor.YELLOW,
58
62
  },
59
63
  [MessageVariant.SENT]: {
60
64
  background: COLORS.PRIMARY_YELLOW,
65
+ border: COLORS.PRIMARY_YELLOW,
61
66
  icon: ButtonColor.YELLOW,
62
67
  },
63
68
  },
@@ -73,3 +78,5 @@ export const CONTROLS_COLORS_MAP = {
73
78
  background: COLORS.PRIMARY_YELLOW,
74
79
  },
75
80
  }
81
+
82
+ export const HOVER_ANIMATION_DURATION = 200
@@ -1,5 +1,10 @@
1
+ import { IS_WEB } from '@magmamath/react-native-ui'
1
2
  // https://stackoverflow.com/questions/56575859/google-translate-api-does-not-return-apostrophe-as-apostrophe-in-python
2
3
  import { KATEX_REPLACEMENTS, KATEX_REPLACEMENTS_REVERSE } from './constants'
4
+ import { GetAlternativesResponse, PostMessagePayload } from './types/api.types'
5
+ import { t } from '../../shared/translation'
6
+ import { ThreadItem } from './model/ThreadItem'
7
+ import { ChatRequestPayload, ChatRequestType } from './types/model.types'
3
8
 
4
9
  export const decodeHTMLEntities = (input: string) => {
5
10
  return input.replace(/&#39;/g, "'")
@@ -10,10 +15,75 @@ export const replaceKatexSyntax = (texts: string[], reverse = false) => {
10
15
  ? Object.entries(KATEX_REPLACEMENTS_REVERSE)
11
16
  : Object.entries(KATEX_REPLACEMENTS)
12
17
 
13
- return texts.map(text =>
18
+ return texts.map((text) =>
14
19
  replacements.reduce(
15
20
  (newText, [pattern, placeholder]) => newText.replace(new RegExp(pattern, 'g'), placeholder),
16
21
  text,
17
22
  ),
18
23
  )
19
24
  }
25
+
26
+ export const transformAlternatives = (payload: GetAlternativesResponse | null) => {
27
+ if (!payload) return payload
28
+
29
+ return {
30
+ ...payload,
31
+ options: {
32
+ ...payload.options,
33
+ hints: [
34
+ {
35
+ text: payload.isOpenChatEnabled && IS_WEB ? t('chat.giveHint') : t('chat.anotherHint'),
36
+ promptKey: payload.options.hints[0].promptKey,
37
+ translatedText: payload.options.hints[0].translatedText,
38
+ },
39
+ ],
40
+ },
41
+ } as GetAlternativesResponse
42
+ }
43
+
44
+ export function prepareChatRequestPayload(
45
+ payload: PostMessagePayload,
46
+ threadItem: ThreadItem,
47
+ ): ChatRequestPayload {
48
+ const {
49
+ conversationId,
50
+ freeTextMessage,
51
+ problemDescription,
52
+ problemAnswer,
53
+ language,
54
+ imageCdnId,
55
+ imageAltText,
56
+ answerOptions,
57
+ answer,
58
+ } = payload
59
+
60
+ if (freeTextMessage) {
61
+ return conversationId
62
+ ? { type: ChatRequestType.Freetext, data: { conversationId, message: freeTextMessage } }
63
+ : {
64
+ type: ChatRequestType.Freetext,
65
+ data: {
66
+ message: freeTextMessage,
67
+ correctAnswer: problemAnswer,
68
+ problemDescription,
69
+ language,
70
+ ...(imageCdnId && { imageCdnId }),
71
+ ...(imageAltText && { altText: imageAltText }),
72
+ ...(!!answerOptions?.length && { answerOptions }),
73
+ },
74
+ }
75
+ }
76
+
77
+ return {
78
+ type: ChatRequestType.Hint,
79
+ data: {
80
+ ...threadItem.getNextHintProps(),
81
+ correctAnswer: problemAnswer,
82
+ problemDescription,
83
+ userAnswer: answer,
84
+ language,
85
+ ...(imageCdnId && { imageCdnId }),
86
+ ...(imageAltText && { altText: imageAltText }),
87
+ },
88
+ }
89
+ }
@@ -9,5 +9,6 @@ export {
9
9
  export type { PostMessageResponse } from './types/api.types'
10
10
  export { DefaultMessagesCreator } from './model/DefaultMessageCreator'
11
11
  export type { ChatAnswer } from './types/units.types'
12
+
12
13
  export type { ConversationMessage } from './types/units.types'
13
14
  export { ColorScheme } from './types/style.types'