botframework-webchat-component 4.13.0 → 4.15.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (698) hide show
  1. package/.eslintrc.yml +4 -100
  2. package/.prettierrc.yml +1 -1
  3. package/lib/Activity/Avatar.d.ts +10 -0
  4. package/lib/Activity/Avatar.d.ts.map +1 -0
  5. package/lib/Activity/Avatar.js +2 -1
  6. package/lib/Activity/Bubble.d.ts +11 -0
  7. package/lib/Activity/Bubble.d.ts.map +1 -0
  8. package/lib/Activity/Bubble.js +2 -2
  9. package/lib/Activity/CarouselFilmStrip.js +21 -31
  10. package/lib/Activity/CarouselFilmStripAttachment.js +120 -0
  11. package/lib/Activity/CarouselLayout.js +5 -5
  12. package/lib/Activity/Speak.d.ts +10 -0
  13. package/lib/Activity/Speak.d.ts.map +1 -0
  14. package/lib/Activity/Speak.js +11 -13
  15. package/lib/Activity/StackedLayout.d.ts +18 -0
  16. package/lib/Activity/StackedLayout.d.ts.map +1 -0
  17. package/lib/Activity/StackedLayout.js +19 -15
  18. package/lib/Assets/TypingAnimation.js +2 -2
  19. package/lib/Attachment/Assets/DownloadIcon.js +3 -1
  20. package/lib/Attachment/AudioAttachment.js +2 -2
  21. package/lib/Attachment/AudioContent.d.ts +11 -0
  22. package/lib/Attachment/AudioContent.d.ts.map +1 -0
  23. package/lib/Attachment/AudioContent.js +4 -4
  24. package/lib/Attachment/FileAttachment.js +2 -2
  25. package/lib/Attachment/FileContent.d.ts +10 -0
  26. package/lib/Attachment/FileContent.d.ts.map +1 -0
  27. package/lib/Attachment/FileContent.js +14 -9
  28. package/lib/Attachment/HTMLVideoContent.d.ts +11 -0
  29. package/lib/Attachment/HTMLVideoContent.d.ts.map +1 -0
  30. package/lib/Attachment/HTMLVideoContent.js +2 -2
  31. package/lib/Attachment/ImageContent.d.ts +8 -0
  32. package/lib/Attachment/ImageContent.d.ts.map +1 -0
  33. package/lib/Attachment/ImageContent.js +2 -2
  34. package/lib/Attachment/TextContent.d.ts +8 -0
  35. package/lib/Attachment/TextContent.d.ts.map +1 -0
  36. package/lib/Attachment/TextContent.js +4 -4
  37. package/lib/Attachment/VideoAttachment.js +2 -2
  38. package/lib/Attachment/VideoContent.d.ts +11 -0
  39. package/lib/Attachment/VideoContent.d.ts.map +1 -0
  40. package/lib/Attachment/VideoContent.js +1 -1
  41. package/lib/Attachment/VimeoContent.d.ts +10 -0
  42. package/lib/Attachment/VimeoContent.d.ts.map +1 -0
  43. package/lib/Attachment/VimeoContent.js +8 -8
  44. package/lib/Attachment/YouTubeContent.d.ts +10 -0
  45. package/lib/Attachment/YouTubeContent.d.ts.map +1 -0
  46. package/lib/Attachment/YouTubeContent.js +5 -5
  47. package/lib/Avatar/ImageAvatar.js +2 -2
  48. package/lib/Avatar/InitialsAvatar.js +2 -2
  49. package/lib/BasicConnectivityStatus.js +2 -2
  50. package/lib/BasicSendBox.d.ts +9 -0
  51. package/lib/BasicSendBox.d.ts.map +1 -0
  52. package/lib/BasicSendBox.js +7 -6
  53. package/lib/BasicToast.js +4 -4
  54. package/lib/BasicToaster.js +8 -5
  55. package/lib/BasicTranscript.d.ts +7 -0
  56. package/lib/BasicTranscript.d.ts.map +1 -0
  57. package/lib/BasicTranscript.js +406 -743
  58. package/lib/BasicTypingIndicator.d.ts +6 -0
  59. package/lib/BasicTypingIndicator.d.ts.map +1 -0
  60. package/lib/BasicTypingIndicator.js +13 -5
  61. package/lib/BasicWebChat.d.ts +9 -0
  62. package/lib/BasicWebChat.d.ts.map +1 -0
  63. package/lib/BasicWebChat.js +6 -4
  64. package/lib/Composer.d.ts +23 -0
  65. package/lib/Composer.d.ts.map +1 -0
  66. package/lib/Composer.js +65 -82
  67. package/lib/ConnectivityStatus/Assets/ErrorNotificationIcon.js +2 -2
  68. package/lib/ConnectivityStatus/Assets/SpinnerAnimation.js +2 -2
  69. package/lib/ConnectivityStatus/Assets/WarningNotificationIcon.js +2 -2
  70. package/lib/ConnectivityStatus/Connected.js +1 -1
  71. package/lib/ConnectivityStatus/Connecting.js +4 -4
  72. package/lib/ConnectivityStatus/FailedToConnect.js +2 -2
  73. package/lib/ConnectivityStatus/JavaScriptError.js +2 -2
  74. package/lib/Dictation.js +13 -4
  75. package/lib/ErrorBox.d.ts +8 -0
  76. package/lib/ErrorBox.d.ts.map +1 -0
  77. package/lib/ErrorBox.js +2 -2
  78. package/lib/Middleware/Activity/createCoreMiddleware.d.ts +3 -0
  79. package/lib/Middleware/Activity/createCoreMiddleware.d.ts.map +1 -0
  80. package/lib/Middleware/Activity/createCoreMiddleware.js +1 -1
  81. package/lib/Middleware/ActivityStatus/AbsoluteTime.js +1 -1
  82. package/lib/Middleware/ActivityStatus/RelativeTime.js +1 -1
  83. package/lib/Middleware/ActivityStatus/SendStatus/SendFailedRetry.js +3 -3
  84. package/lib/Middleware/ActivityStatus/SendStatus/SendStatus.d.ts +11 -0
  85. package/lib/Middleware/ActivityStatus/SendStatus/SendStatus.d.ts.map +1 -0
  86. package/lib/Middleware/ActivityStatus/SendStatus/SendStatus.js +5 -5
  87. package/lib/Middleware/ActivityStatus/Timestamp.d.ts +9 -0
  88. package/lib/Middleware/ActivityStatus/Timestamp.d.ts.map +1 -0
  89. package/lib/Middleware/ActivityStatus/Timestamp.js +2 -2
  90. package/lib/Middleware/ActivityStatus/createCoreMiddleware.d.ts +3 -0
  91. package/lib/Middleware/ActivityStatus/createCoreMiddleware.d.ts.map +1 -0
  92. package/lib/Middleware/ActivityStatus/createCoreMiddleware.js +1 -1
  93. package/lib/Middleware/ActivityStatus/createSendStatusMiddleware.js +21 -16
  94. package/lib/Middleware/ActivityStatus/createTimestampMiddleware.js +1 -1
  95. package/lib/Middleware/Attachment/createCoreMiddleware.d.ts +3 -0
  96. package/lib/Middleware/Attachment/createCoreMiddleware.d.ts.map +1 -0
  97. package/lib/Middleware/Attachment/createCoreMiddleware.js +10 -13
  98. package/lib/Middleware/AttachmentForScreenReader/AudioAttachment.js +1 -1
  99. package/lib/Middleware/AttachmentForScreenReader/FileAttachment.js +1 -1
  100. package/lib/Middleware/AttachmentForScreenReader/ImageAttachment.js +1 -1
  101. package/lib/Middleware/AttachmentForScreenReader/TextAttachment.js +1 -1
  102. package/lib/Middleware/AttachmentForScreenReader/VideoAttachment.js +1 -1
  103. package/lib/Middleware/AttachmentForScreenReader/createCoreMiddleware.d.ts +3 -0
  104. package/lib/Middleware/AttachmentForScreenReader/createCoreMiddleware.d.ts.map +1 -0
  105. package/lib/Middleware/AttachmentForScreenReader/createCoreMiddleware.js +9 -5
  106. package/lib/Middleware/Avatar/createCoreMiddleware.d.ts +11 -0
  107. package/lib/Middleware/Avatar/createCoreMiddleware.d.ts.map +1 -0
  108. package/lib/Middleware/Avatar/createCoreMiddleware.js +3 -4
  109. package/lib/Middleware/CardAction/createCoreMiddleware.js +11 -4
  110. package/lib/Middleware/GroupActivities/createCoreMiddleware.js +1 -1
  111. package/lib/Middleware/ScrollToEndButton/ScrollToEndButton.js +71 -0
  112. package/lib/Middleware/ScrollToEndButton/createScrollToEndButtonMiddleware.d.ts +3 -0
  113. package/lib/Middleware/ScrollToEndButton/createScrollToEndButtonMiddleware.d.ts.map +1 -0
  114. package/lib/Middleware/ScrollToEndButton/createScrollToEndButtonMiddleware.js +27 -0
  115. package/lib/Middleware/Toast/createCoreMiddleware.d.ts +4 -0
  116. package/lib/Middleware/Toast/createCoreMiddleware.d.ts.map +1 -0
  117. package/lib/Middleware/Toast/createCoreMiddleware.js +1 -1
  118. package/lib/Middleware/TypingIndicator/createCoreMiddleware.d.ts +3 -0
  119. package/lib/Middleware/TypingIndicator/createCoreMiddleware.d.ts.map +1 -0
  120. package/lib/Middleware/TypingIndicator/createCoreMiddleware.js +9 -6
  121. package/lib/ReactWebChat.d.ts +10 -0
  122. package/lib/ReactWebChat.d.ts.map +1 -0
  123. package/lib/ReactWebChat.js +19 -7
  124. package/lib/ScreenReaderActivity.js +76 -48
  125. package/lib/ScreenReaderText.d.ts +9 -0
  126. package/lib/ScreenReaderText.d.ts.map +1 -0
  127. package/lib/ScreenReaderText.js +22 -8
  128. package/lib/SendBox/Assets/AttachmentIcon.js +3 -1
  129. package/lib/SendBox/Assets/MicrophoneIcon.js +3 -1
  130. package/lib/SendBox/Assets/SendIcon.js +2 -2
  131. package/lib/SendBox/AutoResizeTextArea.d.ts +23 -0
  132. package/lib/SendBox/AutoResizeTextArea.d.ts.map +1 -0
  133. package/lib/SendBox/AutoResizeTextArea.js +6 -6
  134. package/lib/SendBox/DictationInterims.d.ts +9 -0
  135. package/lib/SendBox/DictationInterims.d.ts.map +1 -0
  136. package/lib/SendBox/DictationInterims.js +3 -3
  137. package/lib/SendBox/IconButton.d.ts +11 -0
  138. package/lib/SendBox/IconButton.d.ts.map +1 -0
  139. package/lib/SendBox/IconButton.js +27 -7
  140. package/lib/SendBox/MicrophoneButton.d.ts +11 -0
  141. package/lib/SendBox/MicrophoneButton.d.ts.map +1 -0
  142. package/lib/SendBox/MicrophoneButton.js +25 -24
  143. package/lib/SendBox/SendButton.d.ts +9 -0
  144. package/lib/SendBox/SendButton.d.ts.map +1 -0
  145. package/lib/SendBox/SendButton.js +8 -6
  146. package/lib/SendBox/SuggestedAction.d.ts +17 -0
  147. package/lib/SendBox/SuggestedAction.d.ts.map +1 -0
  148. package/lib/SendBox/SuggestedAction.js +29 -24
  149. package/lib/SendBox/SuggestedActions.d.ts +5 -0
  150. package/lib/SendBox/SuggestedActions.d.ts.map +1 -0
  151. package/lib/SendBox/SuggestedActions.js +33 -13
  152. package/lib/SendBox/TextBox.d.ts +28 -0
  153. package/lib/SendBox/TextBox.d.ts.map +1 -0
  154. package/lib/SendBox/TextBox.js +13 -8
  155. package/lib/SendBox/UploadButton.d.ts +9 -0
  156. package/lib/SendBox/UploadButton.d.ts.map +1 -0
  157. package/lib/SendBox/UploadButton.js +6 -6
  158. package/lib/Styles/StyleSet/Activities.d.ts +5 -0
  159. package/lib/Styles/StyleSet/Activities.d.ts.map +1 -0
  160. package/lib/Styles/StyleSet/AudioAttachment.d.ts +6 -0
  161. package/lib/Styles/StyleSet/AudioAttachment.d.ts.map +1 -0
  162. package/lib/Styles/StyleSet/AudioContent.d.ts +4 -0
  163. package/lib/Styles/StyleSet/AudioContent.d.ts.map +1 -0
  164. package/lib/Styles/StyleSet/AutoResizeTextArea.d.ts +37 -0
  165. package/lib/Styles/StyleSet/AutoResizeTextArea.d.ts.map +1 -0
  166. package/lib/Styles/StyleSet/Avatar.d.ts +9 -0
  167. package/lib/Styles/StyleSet/Avatar.d.ts.map +1 -0
  168. package/lib/Styles/StyleSet/BasicTranscript.d.ts +85 -0
  169. package/lib/Styles/StyleSet/BasicTranscript.d.ts.map +1 -0
  170. package/lib/Styles/StyleSet/BasicTranscript.js +21 -9
  171. package/lib/Styles/StyleSet/Bubble.d.ts +5 -0
  172. package/lib/Styles/StyleSet/Bubble.d.ts.map +1 -0
  173. package/lib/Styles/StyleSet/Bubble.js +2 -2
  174. package/lib/Styles/StyleSet/CarouselFilmStrip.d.ts +5 -0
  175. package/lib/Styles/StyleSet/CarouselFilmStrip.d.ts.map +1 -0
  176. package/lib/Styles/StyleSet/CarouselFilmStrip.js +2 -18
  177. package/lib/Styles/StyleSet/CarouselFilmStripAttachment.d.ts +3 -0
  178. package/lib/Styles/StyleSet/CarouselFilmStripAttachment.d.ts.map +1 -0
  179. package/lib/Styles/StyleSet/CarouselFilmStripAttachment.js +63 -0
  180. package/lib/Styles/StyleSet/CarouselFlipper.d.ts +27 -0
  181. package/lib/Styles/StyleSet/CarouselFlipper.d.ts.map +1 -0
  182. package/lib/Styles/StyleSet/ConnectivityNotification.d.ts +13 -0
  183. package/lib/Styles/StyleSet/ConnectivityNotification.d.ts.map +1 -0
  184. package/lib/Styles/StyleSet/DictationInterims.d.ts +13 -0
  185. package/lib/Styles/StyleSet/DictationInterims.d.ts.map +1 -0
  186. package/lib/Styles/StyleSet/ErrorBox.d.ts +33 -0
  187. package/lib/Styles/StyleSet/ErrorBox.d.ts.map +1 -0
  188. package/lib/Styles/StyleSet/ErrorNotification.d.ts +23 -0
  189. package/lib/Styles/StyleSet/ErrorNotification.d.ts.map +1 -0
  190. package/lib/Styles/StyleSet/FileContent.d.ts +32 -0
  191. package/lib/Styles/StyleSet/FileContent.d.ts.map +1 -0
  192. package/lib/Styles/StyleSet/ImageAvatar.d.ts +7 -0
  193. package/lib/Styles/StyleSet/ImageAvatar.d.ts.map +1 -0
  194. package/lib/Styles/StyleSet/InitialsAvatar.d.ts +19 -0
  195. package/lib/Styles/StyleSet/InitialsAvatar.d.ts.map +1 -0
  196. package/lib/Styles/StyleSet/KeyboardHelp.d.ts +123 -0
  197. package/lib/Styles/StyleSet/KeyboardHelp.d.ts.map +1 -0
  198. package/lib/Styles/StyleSet/KeyboardHelp.js +145 -0
  199. package/lib/Styles/StyleSet/MicrophoneButton.d.ts +13 -0
  200. package/lib/Styles/StyleSet/MicrophoneButton.d.ts.map +1 -0
  201. package/lib/Styles/StyleSet/Root.d.ts +8 -0
  202. package/lib/Styles/StyleSet/Root.d.ts.map +1 -0
  203. package/lib/Styles/StyleSet/ScrollToEndButton.d.ts +36 -0
  204. package/lib/Styles/StyleSet/ScrollToEndButton.d.ts.map +1 -0
  205. package/lib/Styles/StyleSet/ScrollToEndButton.js +36 -34
  206. package/lib/Styles/StyleSet/SendBox.d.ts +24 -0
  207. package/lib/Styles/StyleSet/SendBox.d.ts.map +1 -0
  208. package/lib/Styles/StyleSet/SendBoxButton.d.ts +79 -0
  209. package/lib/Styles/StyleSet/SendBoxButton.d.ts.map +1 -0
  210. package/lib/Styles/StyleSet/SendBoxButton.js +76 -12
  211. package/lib/Styles/StyleSet/SendBoxTextBox.d.ts +41 -0
  212. package/lib/Styles/StyleSet/SendBoxTextBox.d.ts.map +1 -0
  213. package/lib/Styles/StyleSet/SendBoxTextBox.js +3 -3
  214. package/lib/Styles/StyleSet/SendStatus.d.ts +8 -0
  215. package/lib/Styles/StyleSet/SendStatus.d.ts.map +1 -0
  216. package/lib/Styles/StyleSet/SingleAttachmentActivity.d.ts +11 -0
  217. package/lib/Styles/StyleSet/SingleAttachmentActivity.d.ts.map +1 -0
  218. package/lib/Styles/StyleSet/SpinnerAnimation.d.ts +15 -0
  219. package/lib/Styles/StyleSet/SpinnerAnimation.d.ts.map +1 -0
  220. package/lib/Styles/StyleSet/StackedLayout.d.ts +63 -0
  221. package/lib/Styles/StyleSet/StackedLayout.d.ts.map +1 -0
  222. package/lib/Styles/StyleSet/StackedLayout.js +1 -1
  223. package/lib/Styles/StyleSet/SuggestedAction.d.ts +94 -0
  224. package/lib/Styles/StyleSet/SuggestedAction.d.ts.map +1 -0
  225. package/lib/Styles/StyleSet/SuggestedAction.js +116 -41
  226. package/lib/Styles/StyleSet/SuggestedActions.d.ts +125 -0
  227. package/lib/Styles/StyleSet/SuggestedActions.d.ts.map +1 -0
  228. package/lib/Styles/StyleSet/SuggestedActions.js +13 -6
  229. package/lib/Styles/StyleSet/TextContent.d.ts +28 -0
  230. package/lib/Styles/StyleSet/TextContent.d.ts.map +1 -0
  231. package/lib/Styles/StyleSet/Toast.d.ts +65 -0
  232. package/lib/Styles/StyleSet/Toast.d.ts.map +1 -0
  233. package/lib/Styles/StyleSet/Toaster.d.ts +111 -0
  234. package/lib/Styles/StyleSet/Toaster.d.ts.map +1 -0
  235. package/lib/Styles/StyleSet/TypingAnimation.d.ts +8 -0
  236. package/lib/Styles/StyleSet/TypingAnimation.d.ts.map +1 -0
  237. package/lib/Styles/StyleSet/TypingIndicator.d.ts +11 -0
  238. package/lib/Styles/StyleSet/TypingIndicator.d.ts.map +1 -0
  239. package/lib/Styles/StyleSet/UploadButton.d.ts +14 -0
  240. package/lib/Styles/StyleSet/UploadButton.d.ts.map +1 -0
  241. package/lib/Styles/StyleSet/VideoAttachment.d.ts +2 -0
  242. package/lib/Styles/StyleSet/VideoAttachment.d.ts.map +1 -0
  243. package/lib/Styles/StyleSet/VideoContent.d.ts +6 -0
  244. package/lib/Styles/StyleSet/VideoContent.d.ts.map +1 -0
  245. package/lib/Styles/StyleSet/VimeoContent.d.ts +7 -0
  246. package/lib/Styles/StyleSet/VimeoContent.d.ts.map +1 -0
  247. package/lib/Styles/StyleSet/WarningNotification.d.ts +22 -0
  248. package/lib/Styles/StyleSet/WarningNotification.d.ts.map +1 -0
  249. package/lib/Styles/StyleSet/YouTubeContent.d.ts +7 -0
  250. package/lib/Styles/StyleSet/YouTubeContent.d.ts.map +1 -0
  251. package/lib/Styles/createStyleSet.d.ts +1372 -0
  252. package/lib/Styles/createStyleSet.d.ts.map +1 -0
  253. package/lib/Styles/createStyleSet.js +47 -41
  254. package/lib/Styles/mirrorStyle.js +13 -4
  255. package/lib/Toast/CollapseIcon.js +3 -1
  256. package/lib/Toast/DismissIcon.js +3 -1
  257. package/lib/Toast/ExpandIcon.js +3 -1
  258. package/lib/Toast/NotificationIcon.js +7 -3
  259. package/lib/Toast/createToastMiddleware.d.ts +4 -0
  260. package/lib/Toast/createToastMiddleware.d.ts.map +1 -0
  261. package/lib/Toast/createToastMiddleware.js +2 -2
  262. package/lib/Transcript/ActivityRow.d.ts +9 -0
  263. package/lib/Transcript/ActivityRow.d.ts.map +1 -0
  264. package/lib/Transcript/ActivityRow.js +157 -0
  265. package/lib/Transcript/ActivityTextAlt.js +57 -0
  266. package/lib/Transcript/FocusTrap.d.ts +8 -0
  267. package/lib/Transcript/FocusTrap.d.ts.map +1 -0
  268. package/lib/Transcript/FocusTrap.js +74 -0
  269. package/lib/Transcript/KeyboardHelp.d.ts +4 -0
  270. package/lib/Transcript/KeyboardHelp.d.ts.map +1 -0
  271. package/lib/Transcript/KeyboardHelp.js +550 -0
  272. package/lib/Transcript/LiveRegionTranscript.d.ts +8 -0
  273. package/lib/Transcript/LiveRegionTranscript.d.ts.map +1 -0
  274. package/lib/Transcript/LiveRegionTranscript.js +214 -0
  275. package/lib/Transcript/types.d.ts +2 -0
  276. package/lib/Transcript/types.d.ts.map +1 -0
  277. package/lib/Transcript/types.js +2 -0
  278. package/lib/Transcript/useActivityAccessibleName.d.ts +4 -0
  279. package/lib/Transcript/useActivityAccessibleName.d.ts.map +1 -0
  280. package/lib/Transcript/useActivityAccessibleName.js +97 -0
  281. package/lib/Utils/AccessKeySink/Surface.js +7 -5
  282. package/lib/Utils/AccessibleButton.d.ts +11 -0
  283. package/lib/Utils/AccessibleButton.d.ts.map +1 -0
  284. package/lib/Utils/AccessibleButton.js +15 -8
  285. package/lib/Utils/AccessibleInputText.d.ts +21 -0
  286. package/lib/Utils/AccessibleInputText.d.ts.map +1 -0
  287. package/lib/Utils/AccessibleInputText.js +29 -25
  288. package/lib/Utils/AccessibleTextArea.d.ts +20 -0
  289. package/lib/Utils/AccessibleTextArea.d.ts.map +1 -0
  290. package/lib/Utils/AccessibleTextArea.js +35 -24
  291. package/lib/Utils/CroppedImage.js +2 -2
  292. package/lib/Utils/Fade.js +2 -2
  293. package/lib/Utils/FocusRedirector.d.ts +9 -0
  294. package/lib/Utils/FocusRedirector.d.ts.map +1 -0
  295. package/lib/Utils/FocusRedirector.js +18 -15
  296. package/lib/Utils/InlineMarkdown.js +17 -10
  297. package/lib/Utils/TypeFocusSink/FocusBox.js +6 -4
  298. package/lib/Utils/TypeFocusSink/getTabIndex.d.ts +2 -0
  299. package/lib/Utils/TypeFocusSink/getTabIndex.d.ts.map +1 -0
  300. package/lib/Utils/TypeFocusSink/getTabIndex.js +1 -1
  301. package/lib/Utils/TypeFocusSink/inputtableKey.d.ts +2 -0
  302. package/lib/Utils/TypeFocusSink/inputtableKey.d.ts.map +1 -0
  303. package/lib/Utils/TypeFocusSink/inputtableKey.js +5 -2
  304. package/lib/Utils/TypeFocusSink/navigableEvent.js +1 -1
  305. package/lib/Utils/activityAltText.d.ts +8 -0
  306. package/lib/Utils/activityAltText.d.ts.map +1 -0
  307. package/lib/Utils/activityAltText.js +100 -0
  308. package/lib/Utils/addTargetBlankToHyperlinksMarkdown.js +1 -1
  309. package/lib/Utils/createCustomEvent.js +9 -3
  310. package/lib/Utils/debounce.js +1 -1
  311. package/lib/Utils/detectBrowser.js +4 -2
  312. package/lib/Utils/downscaleImageToDataURL/downscaleImageToDataURLUsingWorker.js +3 -3
  313. package/lib/Utils/downscaleImageToDataURL/index.js +2 -2
  314. package/lib/Utils/filterMap.js +1 -1
  315. package/lib/Utils/findAncestor.js +17 -0
  316. package/lib/Utils/getActivityUniqueId.js +4 -2
  317. package/lib/Utils/intersectionOf.d.ts +5 -0
  318. package/lib/Utils/intersectionOf.d.ts.map +1 -0
  319. package/lib/Utils/intersectionOf.js +17 -2
  320. package/lib/Utils/isZeroOrPositive.d.ts +5 -0
  321. package/lib/Utils/isZeroOrPositive.d.ts.map +1 -0
  322. package/lib/Utils/isZeroOrPositive.js +4 -1
  323. package/lib/Utils/mapMap.js +10 -3
  324. package/lib/Utils/readDataURIToBlob.js +3 -3
  325. package/lib/Utils/scrollIntoViewWithBlockNearest.d.ts +7 -0
  326. package/lib/Utils/scrollIntoViewWithBlockNearest.d.ts.map +1 -0
  327. package/lib/Utils/scrollIntoViewWithBlockNearest.js +48 -0
  328. package/lib/Utils/shallowEquals.js +7 -3
  329. package/lib/Utils/singleToArray.js +1 -1
  330. package/lib/Utils/supportPseudoClass.d.ts +2 -0
  331. package/lib/Utils/supportPseudoClass.d.ts.map +1 -0
  332. package/lib/Utils/supportPseudoClass.js +23 -0
  333. package/lib/Utils/tabbableElements.d.ts +2 -0
  334. package/lib/Utils/tabbableElements.d.ts.map +1 -0
  335. package/lib/Utils/tabbableElements.js +2 -2
  336. package/lib/connectToWebChat.js +17 -7
  337. package/lib/hooks/index.d.ts +21 -0
  338. package/lib/hooks/index.d.ts.map +1 -0
  339. package/lib/hooks/index.js +25 -25
  340. package/lib/hooks/internal/BypassSpeechSynthesisPonyfill.js +100 -41
  341. package/lib/hooks/internal/UITracker.js +2 -2
  342. package/lib/hooks/internal/useChanged.js +8 -1
  343. package/lib/hooks/internal/useDispatchScrollPosition.js +3 -7
  344. package/lib/hooks/internal/useDispatchTranscriptFocusByActivityKey.d.ts +2 -0
  345. package/lib/hooks/internal/useDispatchTranscriptFocusByActivityKey.d.ts.map +1 -0
  346. package/lib/hooks/internal/useDispatchTranscriptFocusByActivityKey.js +15 -0
  347. package/lib/hooks/internal/useEnterKeyHint.js +1 -1
  348. package/lib/hooks/internal/useFocusVisible.d.ts +3 -0
  349. package/lib/hooks/internal/useFocusVisible.d.ts.map +1 -0
  350. package/lib/hooks/internal/useFocusVisible.js +48 -0
  351. package/lib/hooks/internal/useForceRender.js +2 -2
  352. package/lib/hooks/internal/useForceRenderAtInterval.js +2 -2
  353. package/lib/hooks/internal/useInternalRenderMarkdownInline.js +1 -1
  354. package/lib/hooks/internal/useLocalizeAccessKey.js +2 -2
  355. package/lib/hooks/internal/useMemoWithPrevious.d.ts +3 -0
  356. package/lib/hooks/internal/useMemoWithPrevious.d.ts.map +1 -0
  357. package/lib/hooks/internal/useMemoWithPrevious.js +22 -0
  358. package/lib/hooks/internal/useMemoize.d.ts +14 -0
  359. package/lib/hooks/internal/useMemoize.d.ts.map +1 -0
  360. package/lib/hooks/internal/useMemoize.js +12 -3
  361. package/lib/hooks/internal/useNavigatorPlatform.js +1 -1
  362. package/lib/hooks/internal/useNonce.js +1 -1
  363. package/lib/hooks/internal/useObserveFocusVisible.d.ts +3 -0
  364. package/lib/hooks/internal/useObserveFocusVisible.d.ts.map +1 -0
  365. package/lib/hooks/internal/useObserveFocusVisible.js +208 -0
  366. package/lib/hooks/internal/usePrevious.d.ts +2 -0
  367. package/lib/hooks/internal/usePrevious.d.ts.map +1 -0
  368. package/lib/hooks/internal/usePrevious.js +18 -0
  369. package/lib/hooks/internal/useRegisterFocusSendBox.js +1 -1
  370. package/lib/hooks/internal/useRegisterFocusTranscript.js +1 -1
  371. package/lib/hooks/internal/useRegisterScrollRelative.js +1 -1
  372. package/lib/hooks/internal/useRegisterScrollTo.js +1 -1
  373. package/lib/hooks/internal/useRegisterScrollToEnd.js +1 -1
  374. package/lib/hooks/internal/useReplaceEmoticon.js +2 -2
  375. package/lib/hooks/internal/useResumeAudioContext.js +33 -0
  376. package/lib/hooks/internal/useScrollRelative.js +1 -1
  377. package/lib/hooks/internal/useSettableDictateAbortable.js +1 -1
  378. package/lib/hooks/internal/useStateRef.d.ts +3 -0
  379. package/lib/hooks/internal/useStateRef.d.ts.map +1 -0
  380. package/lib/hooks/internal/useStateRef.js +40 -0
  381. package/lib/hooks/internal/useSuggestedActionsAccessKey.js +1 -1
  382. package/lib/hooks/internal/useUniqueId.d.ts +2 -0
  383. package/lib/hooks/internal/useUniqueId.d.ts.map +1 -0
  384. package/lib/hooks/internal/useUniqueId.js +1 -1
  385. package/lib/hooks/internal/useValueRef.d.ts +3 -0
  386. package/lib/hooks/internal/useValueRef.d.ts.map +1 -0
  387. package/lib/hooks/internal/useValueRef.js +25 -0
  388. package/lib/hooks/useDictateAbortable.d.ts +2 -0
  389. package/lib/hooks/useDictateAbortable.d.ts.map +1 -0
  390. package/lib/hooks/useDictateAbortable.js +2 -2
  391. package/lib/hooks/useFocus.d.ts +2 -0
  392. package/lib/hooks/useFocus.d.ts.map +1 -0
  393. package/lib/hooks/useFocus.js +1 -1
  394. package/lib/hooks/useFocusSendBox.d.ts +3 -0
  395. package/lib/hooks/useFocusSendBox.d.ts.map +1 -0
  396. package/lib/hooks/useFocusSendBox.js +2 -1
  397. package/lib/hooks/useObserveScrollPosition.d.ts +3 -0
  398. package/lib/hooks/useObserveScrollPosition.d.ts.map +1 -0
  399. package/lib/hooks/useObserveScrollPosition.js +2 -2
  400. package/lib/hooks/useObserveTranscriptFocus.d.ts +5 -0
  401. package/lib/hooks/useObserveTranscriptFocus.d.ts.map +1 -0
  402. package/lib/hooks/useObserveTranscriptFocus.js +2 -2
  403. package/lib/hooks/useRenderMarkdownAsHTML.d.ts +5 -0
  404. package/lib/hooks/useRenderMarkdownAsHTML.d.ts.map +1 -0
  405. package/lib/hooks/useRenderMarkdownAsHTML.js +2 -2
  406. package/lib/hooks/useScrollDown.d.ts +4 -0
  407. package/lib/hooks/useScrollDown.d.ts.map +1 -0
  408. package/lib/hooks/useScrollDown.js +1 -1
  409. package/lib/hooks/useScrollTo.d.ts +5 -0
  410. package/lib/hooks/useScrollTo.d.ts.map +1 -0
  411. package/lib/hooks/useScrollTo.js +1 -1
  412. package/lib/hooks/useScrollToEnd.d.ts +2 -0
  413. package/lib/hooks/useScrollToEnd.d.ts.map +1 -0
  414. package/lib/hooks/useScrollToEnd.js +1 -1
  415. package/lib/hooks/useScrollUp.d.ts +4 -0
  416. package/lib/hooks/useScrollUp.d.ts.map +1 -0
  417. package/lib/hooks/useScrollUp.js +1 -1
  418. package/lib/hooks/useSendFiles.d.ts +2 -0
  419. package/lib/hooks/useSendFiles.d.ts.map +1 -0
  420. package/lib/hooks/useSendFiles.js +3 -3
  421. package/lib/hooks/useStyleSet.d.ts +2 -0
  422. package/lib/hooks/useStyleSet.d.ts.map +1 -0
  423. package/lib/hooks/useStyleSet.js +1 -1
  424. package/lib/hooks/useWebSpeechPonyfill.d.ts +3 -0
  425. package/lib/hooks/useWebSpeechPonyfill.d.ts.map +1 -0
  426. package/lib/hooks/useWebSpeechPonyfill.js +1 -1
  427. package/lib/index.d.ts +219 -22
  428. package/lib/index.d.ts.map +1 -1
  429. package/lib/index.js +22 -20
  430. package/lib/providers/ActivityTree/ActivityTreeComposer.d.ts +5 -0
  431. package/lib/providers/ActivityTree/ActivityTreeComposer.d.ts.map +1 -0
  432. package/lib/providers/ActivityTree/ActivityTreeComposer.js +86 -0
  433. package/lib/providers/ActivityTree/private/Context.d.ts +9 -0
  434. package/lib/providers/ActivityTree/private/Context.d.ts.map +1 -0
  435. package/lib/providers/ActivityTree/private/Context.js +13 -0
  436. package/lib/providers/ActivityTree/private/types.d.ts +10 -0
  437. package/lib/providers/ActivityTree/private/types.d.ts.map +1 -0
  438. package/lib/providers/ActivityTree/private/types.js +2 -0
  439. package/lib/providers/ActivityTree/private/useActivitiesWithRenderer.d.ts +4 -0
  440. package/lib/providers/ActivityTree/private/useActivitiesWithRenderer.d.ts.map +1 -0
  441. package/lib/providers/ActivityTree/private/useActivitiesWithRenderer.js +58 -0
  442. package/lib/providers/ActivityTree/private/useActivityTreeWithRenderer.d.ts +5 -0
  443. package/lib/providers/ActivityTree/private/useActivityTreeWithRenderer.d.ts.map +1 -0
  444. package/lib/providers/ActivityTree/private/useActivityTreeWithRenderer.js +166 -0
  445. package/lib/providers/ActivityTree/private/useContext.d.ts +3 -0
  446. package/lib/providers/ActivityTree/private/useContext.d.ts.map +1 -0
  447. package/lib/providers/ActivityTree/private/useContext.js +24 -0
  448. package/lib/providers/ActivityTree/useActivityTreeWithRenderer.d.ts +8 -0
  449. package/lib/providers/ActivityTree/useActivityTreeWithRenderer.d.ts.map +1 -0
  450. package/lib/providers/ActivityTree/useActivityTreeWithRenderer.js +17 -0
  451. package/lib/providers/LiveRegionTwin/LiveRegionTwinComposer.d.ts +35 -0
  452. package/lib/providers/LiveRegionTwin/LiveRegionTwinComposer.d.ts.map +1 -0
  453. package/lib/providers/LiveRegionTwin/LiveRegionTwinComposer.js +156 -0
  454. package/lib/providers/LiveRegionTwin/private/Context.d.ts +10 -0
  455. package/lib/providers/LiveRegionTwin/private/Context.d.ts.map +1 -0
  456. package/lib/providers/LiveRegionTwin/private/Context.js +13 -0
  457. package/lib/providers/LiveRegionTwin/private/LiveRegionTwinContainer.d.ts +11 -0
  458. package/lib/providers/LiveRegionTwin/private/LiveRegionTwinContainer.d.ts.map +1 -0
  459. package/lib/providers/LiveRegionTwin/private/LiveRegionTwinContainer.js +86 -0
  460. package/lib/providers/LiveRegionTwin/private/types.d.ts +8 -0
  461. package/lib/providers/LiveRegionTwin/private/types.d.ts.map +1 -0
  462. package/lib/providers/LiveRegionTwin/private/types.js +2 -0
  463. package/lib/providers/LiveRegionTwin/private/useContext.d.ts +3 -0
  464. package/lib/providers/LiveRegionTwin/private/useContext.d.ts.map +1 -0
  465. package/lib/providers/LiveRegionTwin/private/useContext.js +24 -0
  466. package/lib/providers/LiveRegionTwin/private/useMarkAllAsRenderedEffect.d.ts +2 -0
  467. package/lib/providers/LiveRegionTwin/private/useMarkAllAsRenderedEffect.d.ts.map +1 -0
  468. package/lib/providers/LiveRegionTwin/private/useMarkAllAsRenderedEffect.js +24 -0
  469. package/lib/providers/LiveRegionTwin/private/useStaticElementEntries.d.ts +3 -0
  470. package/lib/providers/LiveRegionTwin/private/useStaticElementEntries.d.ts.map +1 -0
  471. package/lib/providers/LiveRegionTwin/private/useStaticElementEntries.js +15 -0
  472. package/lib/providers/LiveRegionTwin/useQueueStaticElement.d.ts +8 -0
  473. package/lib/providers/LiveRegionTwin/useQueueStaticElement.d.ts.map +1 -0
  474. package/lib/providers/LiveRegionTwin/useQueueStaticElement.js +20 -0
  475. package/lib/providers/TranscriptFocus/TranscriptFocusComposer.d.ts +7 -0
  476. package/lib/providers/TranscriptFocus/TranscriptFocusComposer.d.ts.map +1 -0
  477. package/lib/providers/TranscriptFocus/TranscriptFocusComposer.js +184 -0
  478. package/lib/providers/TranscriptFocus/private/Context.d.ts +12 -0
  479. package/lib/providers/TranscriptFocus/private/Context.d.ts.map +1 -0
  480. package/lib/providers/TranscriptFocus/private/Context.js +13 -0
  481. package/lib/providers/TranscriptFocus/private/useContext.d.ts +2 -0
  482. package/lib/providers/TranscriptFocus/private/useContext.d.ts.map +1 -0
  483. package/lib/providers/TranscriptFocus/private/useContext.js +24 -0
  484. package/lib/providers/TranscriptFocus/useActiveDescendantId.d.ts +2 -0
  485. package/lib/providers/TranscriptFocus/useActiveDescendantId.d.ts.map +1 -0
  486. package/lib/providers/TranscriptFocus/useActiveDescendantId.js +15 -0
  487. package/lib/providers/TranscriptFocus/useFocusByActivityKey.d.ts +8 -0
  488. package/lib/providers/TranscriptFocus/useFocusByActivityKey.d.ts.map +1 -0
  489. package/lib/providers/TranscriptFocus/useFocusByActivityKey.js +21 -0
  490. package/lib/providers/TranscriptFocus/useFocusRelativeActivity.d.ts +2 -0
  491. package/lib/providers/TranscriptFocus/useFocusRelativeActivity.d.ts.map +1 -0
  492. package/lib/providers/TranscriptFocus/useFocusRelativeActivity.js +15 -0
  493. package/lib/providers/TranscriptFocus/useFocusedActivityKey.d.ts +2 -0
  494. package/lib/providers/TranscriptFocus/useFocusedActivityKey.d.ts.map +1 -0
  495. package/lib/providers/TranscriptFocus/useFocusedActivityKey.js +15 -0
  496. package/lib/providers/TranscriptFocus/useFocusedExplicitly.d.ts +2 -0
  497. package/lib/providers/TranscriptFocus/useFocusedExplicitly.d.ts.map +1 -0
  498. package/lib/providers/TranscriptFocus/useFocusedExplicitly.js +15 -0
  499. package/lib/providers/TranscriptFocus/useGetDescendantIdByActivityKey.d.ts +2 -0
  500. package/lib/providers/TranscriptFocus/useGetDescendantIdByActivityKey.d.ts.map +1 -0
  501. package/lib/providers/TranscriptFocus/useGetDescendantIdByActivityKey.js +15 -0
  502. package/lib/tsconfig.json +1 -1
  503. package/lib/types/ScrollPosition.d.ts +6 -0
  504. package/lib/types/ScrollPosition.d.ts.map +1 -0
  505. package/lib/types/ScrollPosition.js +2 -0
  506. package/package.json +33 -40
  507. package/src/Activity/{Avatar.js → Avatar.tsx} +9 -2
  508. package/src/Activity/{Bubble.js → Bubble.tsx} +10 -2
  509. package/src/Activity/CarouselFilmStrip.js +20 -29
  510. package/src/Activity/CarouselFilmStripAttachment.js +91 -0
  511. package/src/Activity/{Speak.js → Speak.tsx} +12 -5
  512. package/src/Activity/{StackedLayout.js → StackedLayout.tsx} +46 -20
  513. package/src/Attachment/Assets/DownloadIcon.js +8 -1
  514. package/src/Attachment/{AudioContent.js → AudioContent.tsx} +12 -3
  515. package/src/Attachment/FileAttachment.js +1 -1
  516. package/src/Attachment/{FileContent.js → FileContent.tsx} +22 -7
  517. package/src/Attachment/{HTMLVideoContent.js → HTMLVideoContent.tsx} +10 -2
  518. package/src/Attachment/{ImageContent.js → ImageContent.tsx} +7 -2
  519. package/src/Attachment/{TextContent.js → TextContent.tsx} +14 -7
  520. package/src/Attachment/{VideoContent.js → VideoContent.tsx} +10 -2
  521. package/src/Attachment/{VimeoContent.js → VimeoContent.tsx} +15 -8
  522. package/src/Attachment/{YouTubeContent.js → YouTubeContent.tsx} +12 -5
  523. package/src/{BasicSendBox.js → BasicSendBox.tsx} +9 -5
  524. package/src/BasicToaster.js +9 -5
  525. package/src/BasicTranscript.tsx +878 -0
  526. package/src/{BasicTypingIndicator.js → BasicTypingIndicator.tsx} +4 -3
  527. package/src/{BasicWebChat.js → BasicWebChat.tsx} +13 -4
  528. package/src/{Composer.js → Composer.tsx} +82 -71
  529. package/src/Dictation.js +13 -4
  530. package/src/{ErrorBox.js → ErrorBox.tsx} +7 -2
  531. package/src/Middleware/Activity/createCoreMiddleware.tsx +78 -0
  532. package/src/Middleware/ActivityStatus/SendStatus/{SendStatus.js → SendStatus.tsx} +8 -3
  533. package/src/Middleware/ActivityStatus/{Timestamp.js → Timestamp.tsx} +8 -2
  534. package/src/Middleware/ActivityStatus/{createCoreMiddleware.js → createCoreMiddleware.tsx} +3 -1
  535. package/src/Middleware/ActivityStatus/createSendStatusMiddleware.js +10 -6
  536. package/src/Middleware/ActivityStatus/createTimestampMiddleware.js +10 -8
  537. package/src/Middleware/Attachment/createCoreMiddleware.tsx +44 -0
  538. package/src/Middleware/AttachmentForScreenReader/createCoreMiddleware.tsx +40 -0
  539. package/src/Middleware/Avatar/{createCoreMiddleware.js → createCoreMiddleware.tsx} +19 -11
  540. package/src/Middleware/CardAction/createCoreMiddleware.js +51 -42
  541. package/src/Middleware/GroupActivities/createCoreMiddleware.js +6 -4
  542. package/src/Middleware/ScrollToEndButton/ScrollToEndButton.js +45 -0
  543. package/src/Middleware/ScrollToEndButton/createScrollToEndButtonMiddleware.ts +19 -0
  544. package/src/Middleware/Toast/createCoreMiddleware.tsx +24 -0
  545. package/src/Middleware/TypingIndicator/{createCoreMiddleware.js → createCoreMiddleware.tsx} +10 -5
  546. package/src/{ReactWebChat.js → ReactWebChat.tsx} +25 -7
  547. package/src/ScreenReaderActivity.js +65 -40
  548. package/src/{ScreenReaderText.js → ScreenReaderText.tsx} +27 -9
  549. package/src/SendBox/Assets/AttachmentIcon.js +1 -1
  550. package/src/SendBox/Assets/MicrophoneIcon.js +1 -1
  551. package/src/SendBox/{AutoResizeTextArea.js → AutoResizeTextArea.tsx} +30 -4
  552. package/src/SendBox/{DictationInterims.js → DictationInterims.tsx} +6 -2
  553. package/src/SendBox/{IconButton.js → IconButton.tsx} +19 -3
  554. package/src/SendBox/{MicrophoneButton.js → MicrophoneButton.tsx} +35 -25
  555. package/src/SendBox/{SendButton.js → SendButton.tsx} +8 -3
  556. package/src/SendBox/{SuggestedAction.js → SuggestedAction.tsx} +62 -39
  557. package/src/SendBox/{SuggestedActions.js → SuggestedActions.tsx} +70 -22
  558. package/src/SendBox/{TextBox.js → TextBox.tsx} +21 -7
  559. package/src/SendBox/{UploadButton.js → UploadButton.tsx} +7 -3
  560. package/src/Styles/StyleSet/BasicTranscript.ts +34 -20
  561. package/src/Styles/StyleSet/Bubble.ts +0 -1
  562. package/src/Styles/StyleSet/CarouselFilmStrip.ts +12 -30
  563. package/src/Styles/StyleSet/CarouselFilmStripAttachment.ts +57 -0
  564. package/src/Styles/StyleSet/KeyboardHelp.ts +157 -0
  565. package/src/Styles/StyleSet/ScrollToEndButton.ts +33 -31
  566. package/src/Styles/StyleSet/SendBoxButton.ts +84 -13
  567. package/src/Styles/StyleSet/SendBoxTextBox.ts +1 -2
  568. package/src/Styles/StyleSet/StackedLayout.ts +13 -11
  569. package/src/Styles/StyleSet/SuggestedAction.ts +130 -43
  570. package/src/Styles/StyleSet/SuggestedActions.ts +13 -5
  571. package/src/Styles/createStyleSet.ts +43 -40
  572. package/src/Styles/mirrorStyle.js +10 -2
  573. package/src/Toast/CollapseIcon.js +9 -1
  574. package/src/Toast/DismissIcon.js +9 -1
  575. package/src/Toast/ExpandIcon.js +9 -1
  576. package/src/Toast/NotificationIcon.js +4 -1
  577. package/src/Toast/createToastMiddleware.tsx +15 -0
  578. package/src/Transcript/ActivityRow.tsx +124 -0
  579. package/src/Transcript/ActivityTextAlt.tsx +32 -0
  580. package/src/Transcript/FocusTrap.tsx +64 -0
  581. package/src/Transcript/KeyboardHelp.tsx +282 -0
  582. package/src/Transcript/LiveRegionTranscript.tsx +181 -0
  583. package/src/Transcript/types.ts +1 -0
  584. package/src/Transcript/useActivityAccessibleName.ts +85 -0
  585. package/src/Utils/{AccessibleButton.js → AccessibleButton.tsx} +19 -4
  586. package/src/Utils/{AccessibleInputText.js → AccessibleInputText.tsx} +48 -5
  587. package/src/Utils/{AccessibleTextArea.js → AccessibleTextArea.tsx} +67 -6
  588. package/src/Utils/{FocusRedirector.js → FocusRedirector.tsx} +21 -8
  589. package/src/Utils/InlineMarkdown.js +18 -2
  590. package/src/Utils/TypeFocusSink/FocusBox.js +4 -4
  591. package/src/Utils/TypeFocusSink/getTabIndex.ts +1 -1
  592. package/src/Utils/TypeFocusSink/inputtableKey.ts +5 -1
  593. package/src/Utils/activityAltText.ts +135 -0
  594. package/src/Utils/createCustomEvent.js +7 -1
  595. package/src/Utils/detectBrowser.js +2 -1
  596. package/src/Utils/findAncestor.ts +12 -0
  597. package/src/Utils/getActivityUniqueId.ts +5 -0
  598. package/src/Utils/intersectionOf.spec.js +2 -0
  599. package/src/Utils/intersectionOf.ts +14 -0
  600. package/src/Utils/isZeroOrPositive.ts +7 -0
  601. package/src/Utils/mapMap.js +7 -1
  602. package/src/Utils/mapMap.spec.js +2 -0
  603. package/src/Utils/removeInline.spec.js +2 -0
  604. package/src/Utils/scrollIntoViewWithBlockNearest.ts +20 -0
  605. package/src/Utils/shallowEquals.js +8 -1
  606. package/src/Utils/{singleToArray.js → singleToArray.ts} +1 -1
  607. package/src/Utils/supportPseudoClass.ts +17 -0
  608. package/src/Utils/{tabbableElements.js → tabbableElements.ts} +6 -5
  609. package/src/Utils/walkMarkdownTokens.spec.js +3 -3
  610. package/src/connectToWebChat.js +11 -4
  611. package/src/hooks/{index.js → index.ts} +1 -0
  612. package/src/hooks/internal/BypassSpeechSynthesisPonyfill.js +70 -17
  613. package/src/hooks/internal/useChanged.ts +17 -0
  614. package/src/hooks/internal/useDispatchScrollPosition.js +1 -3
  615. package/src/hooks/internal/useDispatchTranscriptFocusByActivityKey.ts +5 -0
  616. package/src/hooks/internal/useFocusVisible.ts +22 -0
  617. package/src/hooks/internal/useMemoWithPrevious.ts +16 -0
  618. package/src/hooks/internal/useMemoize.spec.js +3 -1
  619. package/src/hooks/internal/useMemoize.ts +53 -0
  620. package/src/hooks/internal/useObserveFocusVisible.ts +252 -0
  621. package/src/hooks/internal/usePrevious.ts +12 -0
  622. package/src/hooks/internal/useResumeAudioContext.ts +7 -0
  623. package/src/hooks/internal/useScrollRelative.js +4 -3
  624. package/src/hooks/internal/useStateRef.ts +31 -0
  625. package/src/hooks/internal/{useUniqueId.js → useUniqueId.ts} +1 -1
  626. package/src/hooks/internal/useValueRef.ts +22 -0
  627. package/src/hooks/{useDictateAbortable.js → useDictateAbortable.ts} +1 -1
  628. package/src/hooks/{useFocus.js → useFocus.ts} +1 -1
  629. package/src/hooks/{useFocusSendBox.js → useFocusSendBox.ts} +2 -1
  630. package/src/hooks/{useObserveScrollPosition.js → useObserveScrollPosition.ts} +6 -1
  631. package/src/hooks/{useObserveTranscriptFocus.js → useObserveTranscriptFocus.ts} +6 -1
  632. package/src/hooks/useRenderMarkdownAsHTML.ts +23 -0
  633. package/src/hooks/{useScrollDown.js → useScrollDown.ts} +1 -1
  634. package/src/hooks/useScrollTo.ts +16 -0
  635. package/src/hooks/useScrollToEnd.ts +12 -0
  636. package/src/hooks/{useScrollUp.js → useScrollUp.ts} +1 -1
  637. package/src/hooks/{useSendFiles.js → useSendFiles.ts} +3 -2
  638. package/src/hooks/{useStyleSet.js → useStyleSet.ts} +1 -1
  639. package/src/hooks/useWebSpeechPonyfill.ts +7 -0
  640. package/src/index.ts +7 -12
  641. package/src/providers/ActivityTree/ActivityTreeComposer.tsx +74 -0
  642. package/src/providers/ActivityTree/private/Context.ts +12 -0
  643. package/src/providers/ActivityTree/private/types.ts +12 -0
  644. package/src/providers/ActivityTree/private/useActivitiesWithRenderer.ts +66 -0
  645. package/src/providers/ActivityTree/private/useActivityTreeWithRenderer.ts +140 -0
  646. package/src/providers/ActivityTree/private/useContext.ts +15 -0
  647. package/src/providers/ActivityTree/useActivityTreeWithRenderer.ts +16 -0
  648. package/src/providers/LiveRegionTwin/LiveRegionTwinComposer.tsx +154 -0
  649. package/src/providers/LiveRegionTwin/private/Context.ts +15 -0
  650. package/src/providers/LiveRegionTwin/private/LiveRegionTwinContainer.tsx +64 -0
  651. package/src/providers/LiveRegionTwin/private/types.ts +10 -0
  652. package/src/providers/LiveRegionTwin/private/useContext.ts +15 -0
  653. package/src/providers/LiveRegionTwin/private/useMarkAllAsRenderedEffect.ts +13 -0
  654. package/src/providers/LiveRegionTwin/private/useStaticElementEntries.ts +7 -0
  655. package/src/providers/LiveRegionTwin/useQueueStaticElement.ts +12 -0
  656. package/src/providers/TranscriptFocus/TranscriptFocusComposer.tsx +180 -0
  657. package/src/providers/TranscriptFocus/private/Context.ts +16 -0
  658. package/src/providers/TranscriptFocus/private/useContext.ts +13 -0
  659. package/src/providers/TranscriptFocus/useActiveDescendantId.ts +5 -0
  660. package/src/providers/TranscriptFocus/useFocusByActivityKey.ts +14 -0
  661. package/src/providers/TranscriptFocus/useFocusRelativeActivity.ts +5 -0
  662. package/src/providers/TranscriptFocus/useFocusedActivityKey.ts +5 -0
  663. package/src/providers/TranscriptFocus/useFocusedExplicitly.ts +5 -0
  664. package/src/providers/TranscriptFocus/useGetDescendantIdByActivityKey.ts +5 -0
  665. package/src/tsconfig.json +1 -1
  666. package/src/types/ScrollPosition.ts +6 -0
  667. package/.eslintignore +0 -9
  668. package/lib/Activity/ScrollToEndButton.js +0 -81
  669. package/lib/Attachment/Assets/ErrorIcon.js +0 -22
  670. package/lib/Utils/findLastIndex.js +0 -32
  671. package/lib/Utils/remarkStripMarkdown.js +0 -26
  672. package/lib/hooks/internal/useAcknowledgedActivity.js +0 -90
  673. package/lib/hooks/internal/useDispatchTranscriptFocus.js +0 -19
  674. package/lib/hooks/internal/useStripMarkdown.js +0 -19
  675. package/src/Activity/ScrollToEndButton.js +0 -58
  676. package/src/Attachment/Assets/ErrorIcon.js +0 -9
  677. package/src/BasicTranscript.js +0 -1123
  678. package/src/Middleware/Activity/createCoreMiddleware.js +0 -71
  679. package/src/Middleware/Attachment/createCoreMiddleware.js +0 -43
  680. package/src/Middleware/AttachmentForScreenReader/createCoreMiddleware.js +0 -37
  681. package/src/Middleware/Toast/createCoreMiddleware.js +0 -20
  682. package/src/Toast/createToastMiddleware.js +0 -11
  683. package/src/Utils/findLastIndex.js +0 -11
  684. package/src/Utils/findLastIndex.spec.js +0 -29
  685. package/src/Utils/getActivityUniqueId.js +0 -3
  686. package/src/Utils/intersectionOf.js +0 -11
  687. package/src/Utils/isZeroOrPositive.js +0 -4
  688. package/src/Utils/remarkStripMarkdown.js +0 -13
  689. package/src/hooks/internal/useAcknowledgedActivity.js +0 -65
  690. package/src/hooks/internal/useChanged.js +0 -10
  691. package/src/hooks/internal/useDispatchTranscriptFocus.js +0 -7
  692. package/src/hooks/internal/useMemoize.js +0 -37
  693. package/src/hooks/internal/useStripMarkdown.js +0 -7
  694. package/src/hooks/useRenderMarkdownAsHTML.js +0 -20
  695. package/src/hooks/useScrollTo.js +0 -11
  696. package/src/hooks/useScrollToEnd.js +0 -11
  697. package/src/hooks/useWebSpeechPonyfill.js +0 -5
  698. package/src/index.tsx +0 -35
@@ -1,3 +1,5 @@
1
+ /* eslint no-magic-numbers: "off" */
2
+
1
3
  import mapMap from './mapMap';
2
4
 
3
5
  test('multiple a map by 10', () => {
@@ -1,3 +1,5 @@
1
+ /* eslint no-magic-numbers: "off" */
2
+
1
3
  import removeInline from './removeInline';
2
4
 
3
5
  test('remove single occurrence', () => {
@@ -0,0 +1,20 @@
1
+ import computeScrollIntoView from 'compute-scroll-into-view';
2
+
3
+ /**
4
+ * Calls `targetElement.scrollIntoView({ block: 'nearest' })`.
5
+ *
6
+ * If browser do not support options for `scrollIntoView`, fallback to polyfill.
7
+ */
8
+ export default function scrollIntoViewWithBlockNearest(targetElement: HTMLElement): void {
9
+ // Checks if `scrollIntoView` support options or not.
10
+ // - https://github.com/Modernizr/Modernizr/issues/1568#issuecomment-419457972
11
+ // - https://stackoverflow.com/questions/46919627/is-it-possible-to-test-for-scrollintoview-browser-compatibility
12
+ if ('scrollBehavior' in document.documentElement.style) {
13
+ return targetElement.scrollIntoView({ block: 'nearest' });
14
+ }
15
+
16
+ // We should only move transcript scrollable, and not other scrollable, such as document.body which is from the hosting page.
17
+ const [action] = computeScrollIntoView(targetElement, { block: 'nearest' });
18
+
19
+ action.el.scrollTop = action.top;
20
+ }
@@ -1,3 +1,5 @@
1
+ import { isForbiddenPropertyName } from 'botframework-webchat-core';
2
+
1
3
  export default function shallowEquals(x, y) {
2
4
  if (x === y) {
3
5
  return true;
@@ -6,5 +8,10 @@ export default function shallowEquals(x, y) {
6
8
  const xKeys = Object.keys(x);
7
9
  const yKeys = Object.keys(y);
8
10
 
9
- return xKeys.length === yKeys.length && xKeys.every(key => yKeys.includes(key) && x[key] === y[key]);
11
+ return (
12
+ xKeys.length === yKeys.length &&
13
+ // Mitigated through denylisting.
14
+ // eslint-disable-next-line security/detect-object-injection
15
+ xKeys.every(key => !isForbiddenPropertyName(key) && yKeys.includes(key) && x[key] === y[key])
16
+ );
10
17
  }
@@ -1,3 +1,3 @@
1
- export default function singleToArray(singleOrArray) {
1
+ export default function singleToArray<T>(singleOrArray: T | T[]): T[] {
2
2
  return singleOrArray ? (Array.isArray(singleOrArray) ? singleOrArray : [singleOrArray]) : [];
3
3
  }
@@ -0,0 +1,17 @@
1
+ // This function is adopted from https://stackoverflow.com/questions/8531940/how-to-detect-if-browser-support-specified-css-pseudo-class
2
+ export default function supportPseudoClass(pseudoClass: string, nonce?: string): boolean {
3
+ const styleElement = document.createElement('style');
4
+
5
+ nonce && styleElement.setAttribute('nonce', nonce);
6
+ document.head.appendChild(styleElement);
7
+
8
+ try {
9
+ styleElement.sheet.insertRule('html' + pseudoClass + '{}', 0);
10
+
11
+ return true;
12
+ } catch (error) {
13
+ return false;
14
+ } finally {
15
+ document.head.removeChild(styleElement);
16
+ }
17
+ }
@@ -1,11 +1,12 @@
1
- export default function tabbableElements(element) {
1
+ export default function tabbableElements(element?: HTMLElement): HTMLElement[] {
2
2
  // This is an incomplete list, due to the complexity of testing for every scenario.
3
3
  // For full-list, please refer to https://allyjs.io/data-tables/focusable.html
4
- const candidates = element.querySelectorAll(
5
- 'a[href], area[href], audio[controls], button:not(:disabled), iframe, input:not(:disabled), keygen, select:not(:disabled), summary, textarea:not(:disabled), video[controls], [contenteditable], [tabindex]'
6
- );
4
+ const candidates: ArrayLike<HTMLElement> =
5
+ element?.querySelectorAll(
6
+ 'a[href], area[href], audio[controls], button:not(:disabled), iframe, input:not(:disabled), keygen, select:not(:disabled), summary, textarea:not(:disabled), video[controls], [contenteditable], [tabindex]'
7
+ ) || [];
7
8
 
8
- return [].filter.call(candidates, element => {
9
+ return ([] as HTMLElement[]).filter.call(candidates, (element: HTMLElement) => {
9
10
  const tabIndexAttribute = element.attributes.getNamedItem('tabindex');
10
11
 
11
12
  if (tabIndexAttribute && tabIndexAttribute.specified) {
@@ -6,9 +6,9 @@ import walkMarkdownTokens from './walkMarkdownTokens';
6
6
  test('walk every node and add class="markdown"', () => {
7
7
  const markdownIt = new MarkdownIt();
8
8
  const tree = markdownIt.parse('Hello, [World](#world)!');
9
- const patchedTree = walkMarkdownTokens(tree, token => {
10
- return updateIn(token, ['attrs'], attrs => [...(attrs || []), ['class', 'markdown']]);
11
- });
9
+ const patchedTree = walkMarkdownTokens(tree, token =>
10
+ updateIn(token, ['attrs'], attrs => [...(attrs || []), ['class', 'markdown']])
11
+ );
12
12
  const actual = markdownIt.renderer.render(patchedTree);
13
13
 
14
14
  expect(actual).toMatchInlineSnapshot(`
@@ -1,4 +1,5 @@
1
1
  import { connect } from 'react-redux';
2
+ import { isForbiddenPropertyName } from 'botframework-webchat-core';
2
3
  import React from 'react';
3
4
 
4
5
  import WebChatAPIContext from 'botframework-webchat-api/lib/hooks/internal/WebChatAPIContext';
@@ -6,10 +7,16 @@ import WebChatReduxContext from 'botframework-webchat-api/lib/hooks/internal/Web
6
7
 
7
8
  function removeUndefinedValues(map) {
8
9
  return Object.keys(map).reduce((result, key) => {
9
- const value = map[key];
10
-
11
- if (typeof value !== 'undefined') {
12
- result[key] = value;
10
+ if (!isForbiddenPropertyName(key)) {
11
+ // Mitigated through denylisting.
12
+ // eslint-disable-next-line security/detect-object-injection
13
+ const value = map[key];
14
+
15
+ if (typeof value !== 'undefined') {
16
+ // Mitigated through denylisting.
17
+ // eslint-disable-next-line security/detect-object-injection
18
+ result[key] = value;
19
+ }
13
20
  }
14
21
 
15
22
  return result;
@@ -20,6 +20,7 @@ import { useTypingIndicatorVisible } from '../BasicTypingIndicator';
20
20
  export {
21
21
  useDictateAbortable,
22
22
  useFocus,
23
+ /** @deprecated Please use `useFocus('sendBox')` instead. */
23
24
  useFocusSendBox,
24
25
  useMicrophoneButtonClick,
25
26
  useMicrophoneButtonDisabled,
@@ -6,11 +6,12 @@
6
6
  /* eslint max-classes-per-file: ["error", 4] */
7
7
  /* eslint no-empty-function: "off" */
8
8
 
9
- import EventTarget, { defineEventAttribute } from 'event-target-shim-es5';
9
+ import EventTarget, { Event, getEventAttributeValue, setEventAttributeValue } from 'event-target-shim/es5';
10
10
 
11
- class SpeechSynthesisEvent {
11
+ class SpeechSynthesisEvent extends Event {
12
12
  constructor(type, utterance) {
13
- this._type = type;
13
+ super(type);
14
+
14
15
  this._utterance = utterance;
15
16
  }
16
17
 
@@ -22,10 +23,8 @@ class SpeechSynthesisEvent {
22
23
  return 0;
23
24
  }
24
25
 
25
- get name() {}
26
-
27
- get type() {
28
- return this._type;
26
+ get name() {
27
+ // It is expected to return `undefined`, keeping the function empty to reduce footprint.
29
28
  }
30
29
 
31
30
  get utterance() {
@@ -92,15 +91,63 @@ class SpeechSynthesisUtterance extends EventTarget {
92
91
  set volume(value) {
93
92
  this._volume = value;
94
93
  }
95
- }
96
94
 
97
- defineEventAttribute(SpeechSynthesisUtterance.prototype, 'boundary');
98
- defineEventAttribute(SpeechSynthesisUtterance.prototype, 'end');
99
- defineEventAttribute(SpeechSynthesisUtterance.prototype, 'error');
100
- defineEventAttribute(SpeechSynthesisUtterance.prototype, 'mark');
101
- defineEventAttribute(SpeechSynthesisUtterance.prototype, 'pause');
102
- defineEventAttribute(SpeechSynthesisUtterance.prototype, 'resume');
103
- defineEventAttribute(SpeechSynthesisUtterance.prototype, 'start');
95
+ get onboundary() {
96
+ return getEventAttributeValue(this, 'boundary');
97
+ }
98
+
99
+ set onboundary(value) {
100
+ setEventAttributeValue(this, 'boundary', value);
101
+ }
102
+
103
+ get onend() {
104
+ return getEventAttributeValue(this, 'end');
105
+ }
106
+
107
+ set onend(value) {
108
+ setEventAttributeValue(this, 'end', value);
109
+ }
110
+
111
+ get onerror() {
112
+ return getEventAttributeValue(this, 'error');
113
+ }
114
+
115
+ set onerror(value) {
116
+ setEventAttributeValue(this, 'error', value);
117
+ }
118
+
119
+ get onmark() {
120
+ return getEventAttributeValue(this, 'mark');
121
+ }
122
+
123
+ set onmark(value) {
124
+ setEventAttributeValue(this, 'mark', value);
125
+ }
126
+
127
+ get onpause() {
128
+ return getEventAttributeValue(this, 'pause');
129
+ }
130
+
131
+ set onpause(value) {
132
+ setEventAttributeValue(this, 'pause', value);
133
+ }
134
+
135
+ get onresume() {
136
+ return getEventAttributeValue(this, 'resume');
137
+ }
138
+
139
+ set onresume(value) {
140
+ setEventAttributeValue(this, 'resume', value);
141
+ }
142
+
143
+ get onstart() {
144
+ return getEventAttributeValue(this, 'start');
145
+ }
146
+
147
+ set onstart(value) {
148
+ setEventAttributeValue(this, 'start', value);
149
+ }
150
+ }
104
151
 
105
152
  class SpeechSynthesisVoice {
106
153
  get default() {
@@ -155,9 +202,15 @@ class SpeechSynthesis extends EventTarget {
155
202
  utterance.dispatchEvent(new SpeechSynthesisEvent('start', utterance));
156
203
  utterance.dispatchEvent(new SpeechSynthesisEvent('end', utterance));
157
204
  }
158
- }
159
205
 
160
- defineEventAttribute(SpeechSynthesis.prototype, 'voiceschanged');
206
+ get onvoiceschanged() {
207
+ return getEventAttributeValue(this, 'voiceschanged');
208
+ }
209
+
210
+ set onvoiceschanged(value) {
211
+ setEventAttributeValue(this, 'voiceschanged', value);
212
+ }
213
+ }
161
214
 
162
215
  const speechSynthesis = new SpeechSynthesis();
163
216
 
@@ -0,0 +1,17 @@
1
+ import { useRef } from 'react';
2
+
3
+ /**
4
+ * Returns `true` if the `value` has changed, otherwise, `false`.
5
+ *
6
+ * Note: on initial call, this will return `true`.
7
+ *
8
+ * @param {T} value - The `value` to detect for changes.
9
+ */
10
+ export default function useChanged<T>(value: T): boolean {
11
+ const prevValueRef = useRef(value);
12
+ const changed = value !== prevValueRef.current;
13
+
14
+ prevValueRef.current = value;
15
+
16
+ return changed;
17
+ }
@@ -1,7 +1,5 @@
1
1
  import useWebChatUIContext from './useWebChatUIContext';
2
2
 
3
3
  export default function useDispatchScrollPosition() {
4
- const { dispatchScrollPosition, numScrollPositionObservers } = useWebChatUIContext();
5
-
6
- return numScrollPositionObservers ? dispatchScrollPosition : undefined;
4
+ return useWebChatUIContext().dispatchScrollPosition;
7
5
  }
@@ -0,0 +1,5 @@
1
+ import useWebChatUIContext from './useWebChatUIContext';
2
+
3
+ export default function useDispatchTranscriptFocusByActivityKey(): (activityKey: string | undefined) => void {
4
+ return useWebChatUIContext().dispatchTranscriptFocusByActivityKey;
5
+ }
@@ -0,0 +1,22 @@
1
+ import { RefObject, useCallback, useEffect, useState } from 'react';
2
+
3
+ import useObserveFocusVisible from './useObserveFocusVisible';
4
+
5
+ export default function useFocusVisible(targetRef: RefObject<HTMLElement>): [boolean] {
6
+ const [focusVisible, setFocusVisible] = useState(false);
7
+
8
+ const handleBlur = useCallback(() => setFocusVisible(false), [setFocusVisible]);
9
+ const handleFocusVisible = useCallback(() => setFocusVisible(true), [setFocusVisible]);
10
+
11
+ useObserveFocusVisible(targetRef, handleFocusVisible);
12
+
13
+ useEffect(() => {
14
+ const { current } = targetRef;
15
+
16
+ current.addEventListener('blur', handleBlur);
17
+
18
+ return () => current.removeEventListener('blur', handleBlur);
19
+ }, [handleBlur, targetRef]);
20
+
21
+ return [focusVisible];
22
+ }
@@ -0,0 +1,16 @@
1
+ import { useEffect, useMemo, useRef } from 'react';
2
+
3
+ import type { DependencyList } from 'react';
4
+
5
+ export default function useMemoWithPrevious<T>(factory: (prevValue: T) => T, deps: DependencyList): T {
6
+ const prevValueRef = useRef<T>();
7
+ // We are building a `useMemo`-like hook, `deps` is passed as-is and `factory` is not one fo the dependencies.
8
+ // eslint-disable-next-line react-hooks/exhaustive-deps
9
+ const value = useMemo<T>(() => factory(prevValueRef.current), deps);
10
+
11
+ useEffect(() => {
12
+ prevValueRef.current = value;
13
+ });
14
+
15
+ return value;
16
+ }
@@ -1,3 +1,5 @@
1
+ /* eslint no-magic-numbers: "off" */
2
+
1
3
  import useMemoize from './useMemoize';
2
4
 
3
5
  jest.mock('react', () => {
@@ -5,7 +7,7 @@ jest.mock('react', () => {
5
7
  let lastResult;
6
8
 
7
9
  function arrayEquals(x, y) {
8
- return x.length === y.length && x.every((item, index) => Object.is(item, y[index]));
10
+ return x.length === y.length && [].every.call(x, (item, index) => Object.is(item, y[+index]));
9
11
  }
10
12
 
11
13
  return {
@@ -0,0 +1,53 @@
1
+ import { DependencyList, useMemo } from 'react';
2
+
3
+ type Cache<TArgs, TResult> = { args: TArgs[]; result: TResult };
4
+ type Fn<TArgs, TResult> = (...args: TArgs[]) => TResult;
5
+
6
+ /**
7
+ * `useMemoize` will memoize multiple calls to the same memoize function.
8
+ *
9
+ * This is similar to `useMemo`. But instead of calling it once, `useMemoize` enables multiple calls while the `callback` function is executed.
10
+ *
11
+ * @param {Fn<TArgs, TIntermediate>} fn - The function to be memoized.
12
+ * @param {(fn: Fn<TArgs, TIntermediate>) => TFinal} callback - When called, this function should execute the memoizing function.
13
+ * @param {DependencyList[]} deps - Dependencies to detect for chagnes.
14
+ */
15
+ export default function useMemoize<TArgs extends [], TIntermediate, TFinal>(
16
+ fn: Fn<TArgs, TIntermediate>,
17
+ callback: (fn: Fn<TArgs, TIntermediate>) => TFinal,
18
+ deps: DependencyList[]
19
+ ): TFinal {
20
+ if (typeof fn !== 'function') {
21
+ throw new Error('The first argument must be a function.');
22
+ } else if (typeof callback !== 'function') {
23
+ throw new Error('The second argument must be a function.');
24
+ } else if (!Array.isArray(deps)) {
25
+ throw new Error('The third argument must be an array.');
26
+ }
27
+
28
+ const memoizedFn = useMemo(() => {
29
+ let cache: Cache<TArgs, TIntermediate>[] = [];
30
+
31
+ return (run: (fn: Fn<TArgs, TIntermediate>) => TFinal) => {
32
+ const nextCache: Cache<TArgs, TIntermediate>[] = [];
33
+ const result = run((...args) => {
34
+ const { result } = [...cache, ...nextCache].find(
35
+ ({ args: cachedArgs }) =>
36
+ args.length === cachedArgs.length && args.every((arg, index) => Object.is(arg, cachedArgs[+index]))
37
+ ) || { result: fn(...args) };
38
+
39
+ nextCache.push({ args, result });
40
+
41
+ return result;
42
+ });
43
+
44
+ cache = nextCache;
45
+
46
+ return result;
47
+ };
48
+ // We are manually creating the deps here. The "callback" arg is also designed not to be impact deps, similar to useEffect(fn), where "fn" is not in deps.
49
+ /* eslint-disable-next-line react-hooks/exhaustive-deps */
50
+ }, [fn, ...deps]);
51
+
52
+ return memoizedFn(callback);
53
+ }
@@ -0,0 +1,252 @@
1
+ import { MutableRefObject, RefObject, useCallback, useEffect, useMemo, useRef } from 'react';
2
+
3
+ import supportPseudoClass from '../../Utils/supportPseudoClass';
4
+ import useNonce from './useNonce';
5
+ import useValueRef from './useValueRef';
6
+
7
+ const INPUT_TYPES_ALLOW_LIST = [
8
+ 'date',
9
+ 'datetime-local',
10
+ 'datetime',
11
+ 'email',
12
+ 'month',
13
+ 'number',
14
+ 'password',
15
+ 'search',
16
+ 'tel',
17
+ 'text',
18
+ 'time',
19
+ 'url',
20
+ 'week'
21
+ ];
22
+
23
+ /**
24
+ * Computes whether the given element should automatically trigger the
25
+ * `focus-visible` class being added, i.e. whether it should always match
26
+ * `:focus-visible` when focused.
27
+ * @param {Element} el
28
+ * @return {boolean}
29
+ */
30
+ function focusTriggersKeyboardModality(el: HTMLInputElement | HTMLTextAreaElement): boolean {
31
+ const { isContentEditable, readOnly, tagName, type } = el;
32
+
33
+ return (
34
+ (tagName === 'INPUT' && INPUT_TYPES_ALLOW_LIST.includes(type) && !readOnly) ||
35
+ (tagName === 'TEXTAREA' && !readOnly) ||
36
+ isContentEditable
37
+ );
38
+ }
39
+
40
+ function createEventSubscription(
41
+ target: Element | Node,
42
+ types: string[],
43
+ handler: (event: Event) => void
44
+ ): {
45
+ pause: () => void;
46
+ resume: () => void;
47
+ } {
48
+ let subscribed: true;
49
+
50
+ const subscribe = () => {
51
+ if (!subscribed) {
52
+ types.forEach(type => target.addEventListener(type, handler));
53
+ subscribed = true;
54
+ }
55
+ };
56
+
57
+ const unsubscribe = () => {
58
+ if (subscribed) {
59
+ types.forEach(type => target.removeEventListener(type, handler));
60
+ subscribed = undefined;
61
+ }
62
+ };
63
+
64
+ return {
65
+ pause: unsubscribe,
66
+ resume: subscribe
67
+ };
68
+ }
69
+
70
+ // TODO: Add tests
71
+ // 1. Focus via keyboard vs. mouse
72
+ // 2. Focus via keyboard, switch app, switch back (expect to get another focusVisible after switch back)
73
+ // 3. Focus via mouse, switch app, switch back (do NOT expect to get another focusVisible after switch back)
74
+ function useObserveFocusVisibleForLegacyBrowsers(
75
+ targetRef: RefObject<HTMLElement>,
76
+ onFocusVisibleRef: MutableRefObject<() => void>
77
+ ) {
78
+ // This polyfill algorithm is adopted from https://github.com/WICG/focus-visible.
79
+ const blurSinceRef = useRef(0);
80
+ const hadKeyboardEventRef = useRef(true);
81
+ const hasFocusVisibleRef = useRef(false);
82
+
83
+ const eventSubscription = useMemo(
84
+ () =>
85
+ createEventSubscription(
86
+ document,
87
+ [
88
+ 'mousemove',
89
+ 'mousedown',
90
+ 'mouseup',
91
+ 'pointermove',
92
+ 'pointerdown',
93
+ 'pointerup',
94
+ 'touchmove',
95
+ 'touchstart',
96
+ 'touchend'
97
+ ],
98
+ event => {
99
+ if ((event.target as HTMLElement).nodeName?.toLowerCase() !== 'html') {
100
+ hadKeyboardEventRef.current = false;
101
+ eventSubscription.pause();
102
+ }
103
+ }
104
+ ),
105
+ [hadKeyboardEventRef]
106
+ );
107
+
108
+ const setHasFocusVisible = useCallback(
109
+ nextHasFocusVisible => {
110
+ if (hasFocusVisibleRef.current !== nextHasFocusVisible) {
111
+ hasFocusVisibleRef.current = nextHasFocusVisible;
112
+ nextHasFocusVisible && onFocusVisibleRef?.current();
113
+ }
114
+ },
115
+ [hasFocusVisibleRef, onFocusVisibleRef]
116
+ );
117
+
118
+ const handleKeyDown = useCallback(
119
+ (event: KeyboardEvent) => {
120
+ if (event.altKey || event.ctrlKey || event.metaKey) {
121
+ return;
122
+ }
123
+
124
+ if (event.target === targetRef.current) {
125
+ setHasFocusVisible(true);
126
+ }
127
+
128
+ hadKeyboardEventRef.current = true;
129
+ },
130
+ [hadKeyboardEventRef, setHasFocusVisible, targetRef]
131
+ );
132
+
133
+ const handlePointerDown = useCallback(() => {
134
+ hadKeyboardEventRef.current = false;
135
+ }, [hadKeyboardEventRef]);
136
+
137
+ const handleFocus = useCallback(
138
+ ({ target }: Event) => {
139
+ target === targetRef.current &&
140
+ (hadKeyboardEventRef.current || focusTriggersKeyboardModality(target as HTMLInputElement)) &&
141
+ setHasFocusVisible(true);
142
+ },
143
+ [hadKeyboardEventRef, setHasFocusVisible, targetRef]
144
+ );
145
+
146
+ const handleBlur = useCallback(
147
+ (event: Event) => {
148
+ if (event.target === targetRef.current && hasFocusVisibleRef.current) {
149
+ blurSinceRef.current = Date.now();
150
+
151
+ setHasFocusVisible(false);
152
+ }
153
+ },
154
+ [blurSinceRef, hasFocusVisibleRef, setHasFocusVisible, targetRef]
155
+ );
156
+
157
+ const handleVisibilityChange = useCallback(() => {
158
+ if (document.visibilityState === 'hidden') {
159
+ // The element is blurred due to "visibilityState" set to "hidden".
160
+ // 100ms is referenced from the WICG polyfill.
161
+ // eslint-disable-next-line no-magic-numbers
162
+ if (Date.now() - blurSinceRef.current < 100) {
163
+ hadKeyboardEventRef.current = true;
164
+ }
165
+
166
+ eventSubscription.resume();
167
+ }
168
+ }, [blurSinceRef, eventSubscription, hadKeyboardEventRef]);
169
+
170
+ useEffect(() => {
171
+ document.addEventListener('keydown', handleKeyDown, true);
172
+ document.addEventListener('mousedown', handlePointerDown, true);
173
+ document.addEventListener('pointerdown', handlePointerDown, true);
174
+ document.addEventListener('touchstart', handlePointerDown, true);
175
+ document.addEventListener('visibilitychange', handleVisibilityChange, true);
176
+
177
+ return () => {
178
+ document.removeEventListener('keydown', handleKeyDown);
179
+ document.removeEventListener('mousedown', handlePointerDown);
180
+ document.removeEventListener('pointerdown', handlePointerDown);
181
+ document.removeEventListener('touchstart', handlePointerDown);
182
+ document.removeEventListener('visibilitychange', handleVisibilityChange);
183
+ };
184
+ }, [handleKeyDown, handlePointerDown, handleVisibilityChange]);
185
+
186
+ useEffect(() => {
187
+ const { current: target } = targetRef;
188
+
189
+ target.addEventListener('blur', handleBlur, true);
190
+ target.addEventListener('focus', handleFocus, true);
191
+
192
+ return () => {
193
+ target.removeEventListener('blur', handleBlur);
194
+ target.removeEventListener('focus', handleFocus);
195
+ };
196
+
197
+ // We specifically add "targetRef.current" here.
198
+ // If the target element changed, we should reattach our event listeners.
199
+ }, [handleBlur, handleFocus, targetRef]);
200
+
201
+ useEffect(() => {
202
+ eventSubscription.resume();
203
+
204
+ return () => eventSubscription.pause();
205
+ }, [eventSubscription]);
206
+ }
207
+
208
+ function useObserveFocusVisibleForModernBrowsers(
209
+ targetRef: RefObject<HTMLElement>,
210
+ onFocusVisibleRef: MutableRefObject<() => void>
211
+ ) {
212
+ const handleFocus = useCallback(() => {
213
+ if (targetRef.current.matches(':focus-visible')) {
214
+ onFocusVisibleRef?.current();
215
+ }
216
+ }, [onFocusVisibleRef, targetRef]);
217
+
218
+ useEffect(() => {
219
+ const { current: target } = targetRef;
220
+
221
+ target.addEventListener('focus', handleFocus);
222
+
223
+ return () => target.removeEventListener('focus', handleFocus);
224
+
225
+ // We specifically add "targetRef.current" here.
226
+ // If the target element changed, we should reattach our event listeners.
227
+ // eslint-disable-next-line react-hooks/exhaustive-deps
228
+ }, [handleFocus, targetRef, targetRef.current]);
229
+ }
230
+
231
+ export default function useObserveFocusVisible(targetRef: RefObject<HTMLElement>, onFocusVisible: () => void) {
232
+ const [nonce] = useNonce();
233
+ const onFocusVisibleRef = useValueRef(onFocusVisible);
234
+
235
+ // The nonce is use for browser capabilities. Just in case the "nonce" had changed unexpectedly, the capabilities of the browser should never change.
236
+ // Thus, we are using an initial version of "nonce". In case web devs changed the "nonce" to an invalid value, we won't break rules of hooks (as stated below).
237
+ const nonceRef = useRef(nonce);
238
+
239
+ // ":focus-visible" selector is supported from Chrome/Edge 86+ and not supported in IE11 or Safari.
240
+ // Doing a capability check on pseudo classes requires injecting a stylesheet, thus nonce is needed.
241
+ const supportFocusVisible = useMemo(() => supportPseudoClass(':focus-visible', nonceRef.current), [nonceRef]);
242
+
243
+ // Since "supportPseudoClass" is a browser capability, the result should be constant during the page lifetime.
244
+ // Thus, running hooks conditionally is okay here.
245
+ if (supportFocusVisible) {
246
+ // eslint-disable-next-line react-hooks/rules-of-hooks
247
+ useObserveFocusVisibleForModernBrowsers(targetRef, onFocusVisibleRef);
248
+ } else {
249
+ // eslint-disable-next-line react-hooks/rules-of-hooks
250
+ useObserveFocusVisibleForLegacyBrowsers(targetRef, onFocusVisibleRef);
251
+ }
252
+ }
@@ -0,0 +1,12 @@
1
+ // TODO: [P0] #4133 Don't copy.
2
+ import { useEffect, useRef } from 'react';
3
+
4
+ export default function usePrevious<T>(value: T): T {
5
+ const ref = useRef<T>();
6
+
7
+ useEffect(() => {
8
+ ref.current = value;
9
+ });
10
+
11
+ return ref.current;
12
+ }