@botonic/react 0.21.6 → 0.21.7-alpha.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 (424) hide show
  1. package/lib/cjs/app.d.ts +2 -0
  2. package/lib/cjs/app.js +10 -0
  3. package/lib/cjs/app.js.map +1 -0
  4. package/lib/cjs/botonic-tester.d.ts +18 -0
  5. package/lib/cjs/botonic-tester.js +70 -0
  6. package/lib/cjs/botonic-tester.js.map +1 -0
  7. package/lib/cjs/components/audio.d.ts +8 -0
  8. package/lib/cjs/components/audio.js +27 -0
  9. package/lib/cjs/components/audio.js.map +1 -0
  10. package/lib/cjs/components/button.d.ts +15 -0
  11. package/lib/cjs/components/button.js +156 -0
  12. package/lib/cjs/components/button.js.map +1 -0
  13. package/lib/cjs/components/buttons-disabler.d.ts +24 -0
  14. package/lib/cjs/components/buttons-disabler.js +88 -0
  15. package/lib/cjs/components/buttons-disabler.js.map +1 -0
  16. package/lib/cjs/components/carousel.d.ts +9 -0
  17. package/lib/cjs/components/carousel.js +120 -0
  18. package/lib/cjs/components/carousel.js.map +1 -0
  19. package/lib/cjs/components/components.d.ts +12 -0
  20. package/lib/{components → cjs/components}/components.js +6 -11
  21. package/lib/cjs/components/components.js.map +1 -0
  22. package/lib/cjs/components/custom-message.d.ts +10 -0
  23. package/lib/cjs/components/custom-message.js +65 -0
  24. package/lib/cjs/components/custom-message.js.map +1 -0
  25. package/lib/cjs/components/document.d.ts +8 -0
  26. package/lib/cjs/components/document.js +50 -0
  27. package/lib/cjs/components/document.js.map +1 -0
  28. package/lib/cjs/components/element.d.ts +4 -0
  29. package/lib/cjs/components/element.js +55 -0
  30. package/lib/cjs/components/element.js.map +1 -0
  31. package/lib/cjs/components/handoff.d.ts +1 -0
  32. package/lib/cjs/components/handoff.js +58 -0
  33. package/lib/cjs/components/handoff.js.map +1 -0
  34. package/lib/cjs/components/image.d.ts +8 -0
  35. package/lib/cjs/components/image.js +42 -0
  36. package/lib/cjs/components/image.js.map +1 -0
  37. package/lib/cjs/components/index.d.ts +1 -0
  38. package/lib/cjs/components/index.js +44 -0
  39. package/lib/cjs/components/index.js.map +1 -0
  40. package/lib/cjs/components/location.d.ts +11 -0
  41. package/lib/cjs/components/location.js +38 -0
  42. package/lib/cjs/components/location.js.map +1 -0
  43. package/lib/cjs/components/markdown.d.ts +7 -0
  44. package/lib/cjs/components/markdown.js +162 -0
  45. package/lib/cjs/components/markdown.js.map +1 -0
  46. package/lib/cjs/components/message-template.d.ts +1 -0
  47. package/lib/cjs/components/message-template.js +15 -0
  48. package/lib/cjs/components/message-template.js.map +1 -0
  49. package/lib/cjs/components/message.d.ts +1 -0
  50. package/lib/cjs/components/message.js +206 -0
  51. package/lib/cjs/components/message.js.map +1 -0
  52. package/lib/cjs/components/multichannel/facebook/facebook.d.ts +17 -0
  53. package/lib/cjs/components/multichannel/facebook/facebook.js +47 -0
  54. package/lib/cjs/components/multichannel/facebook/facebook.js.map +1 -0
  55. package/lib/cjs/components/multichannel/index.d.ts +1 -0
  56. package/lib/cjs/components/multichannel/index.js +14 -0
  57. package/lib/cjs/components/multichannel/index.js.map +1 -0
  58. package/lib/cjs/components/multichannel/multichannel-button.d.ts +1 -0
  59. package/lib/cjs/components/multichannel/multichannel-button.js +77 -0
  60. package/lib/cjs/components/multichannel/multichannel-button.js.map +1 -0
  61. package/lib/cjs/components/multichannel/multichannel-carousel.d.ts +1 -0
  62. package/lib/cjs/components/multichannel/multichannel-carousel.js +95 -0
  63. package/lib/cjs/components/multichannel/multichannel-carousel.js.map +1 -0
  64. package/lib/cjs/components/multichannel/multichannel-context.d.ts +11 -0
  65. package/lib/cjs/components/multichannel/multichannel-context.js +16 -0
  66. package/lib/cjs/components/multichannel/multichannel-context.js.map +1 -0
  67. package/lib/cjs/components/multichannel/multichannel-reply.d.ts +1 -0
  68. package/lib/cjs/components/multichannel/multichannel-reply.js +24 -0
  69. package/lib/cjs/components/multichannel/multichannel-reply.js.map +1 -0
  70. package/lib/cjs/components/multichannel/multichannel-text.d.ts +1 -0
  71. package/lib/cjs/components/multichannel/multichannel-text.js +147 -0
  72. package/lib/cjs/components/multichannel/multichannel-text.js.map +1 -0
  73. package/lib/cjs/components/multichannel/multichannel-utils.d.ts +24 -0
  74. package/lib/cjs/components/multichannel/multichannel-utils.js +83 -0
  75. package/lib/cjs/components/multichannel/multichannel-utils.js.map +1 -0
  76. package/lib/cjs/components/multichannel/multichannel.d.ts +1 -0
  77. package/lib/cjs/components/multichannel/multichannel.js +72 -0
  78. package/lib/cjs/components/multichannel/multichannel.js.map +1 -0
  79. package/lib/cjs/components/pic.d.ts +6 -0
  80. package/lib/cjs/components/pic.js +29 -0
  81. package/lib/cjs/components/pic.js.map +1 -0
  82. package/lib/cjs/components/raw.d.ts +9 -0
  83. package/lib/cjs/components/raw.js +53 -0
  84. package/lib/cjs/components/raw.js.map +1 -0
  85. package/lib/cjs/components/reply.d.ts +9 -0
  86. package/lib/cjs/components/reply.js +57 -0
  87. package/lib/cjs/components/reply.js.map +1 -0
  88. package/lib/cjs/components/share-button.d.ts +1 -0
  89. package/lib/cjs/components/share-button.js +15 -0
  90. package/lib/cjs/components/share-button.js.map +1 -0
  91. package/lib/cjs/components/subtitle.d.ts +6 -0
  92. package/lib/cjs/components/subtitle.js +25 -0
  93. package/lib/cjs/components/subtitle.js.map +1 -0
  94. package/lib/cjs/components/text.d.ts +8 -0
  95. package/lib/cjs/components/text.js +50 -0
  96. package/lib/cjs/components/text.js.map +1 -0
  97. package/lib/cjs/components/timestamps.d.ts +10 -0
  98. package/lib/cjs/components/timestamps.js +54 -0
  99. package/lib/cjs/components/timestamps.js.map +1 -0
  100. package/lib/cjs/components/title.d.ts +6 -0
  101. package/lib/cjs/components/title.js +21 -0
  102. package/lib/cjs/components/title.js.map +1 -0
  103. package/lib/cjs/components/video.d.ts +8 -0
  104. package/lib/cjs/components/video.js +34 -0
  105. package/lib/cjs/components/video.js.map +1 -0
  106. package/lib/cjs/components/webchat-settings.d.ts +10 -0
  107. package/lib/cjs/components/webchat-settings.js +78 -0
  108. package/lib/cjs/components/webchat-settings.js.map +1 -0
  109. package/lib/cjs/components/whatsapp-template.d.ts +1 -0
  110. package/lib/cjs/components/whatsapp-template.js +26 -0
  111. package/lib/cjs/components/whatsapp-template.js.map +1 -0
  112. package/lib/cjs/constants.d.ts +168 -0
  113. package/lib/cjs/constants.js +190 -0
  114. package/lib/cjs/constants.js.map +1 -0
  115. package/lib/cjs/contexts.d.ts +69 -0
  116. package/lib/cjs/contexts.js +38 -0
  117. package/lib/cjs/contexts.js.map +1 -0
  118. package/lib/cjs/dev-app.d.ts +34 -0
  119. package/lib/cjs/dev-app.js +71 -0
  120. package/lib/cjs/dev-app.js.map +1 -0
  121. package/lib/cjs/index.d.ts +3 -0
  122. package/lib/cjs/index.js +28 -0
  123. package/lib/cjs/index.js.map +1 -0
  124. package/lib/cjs/message-utils.d.ts +18 -0
  125. package/lib/cjs/message-utils.js +61 -0
  126. package/lib/cjs/message-utils.js.map +1 -0
  127. package/lib/cjs/msg-to-botonic.d.ts +18 -0
  128. package/lib/cjs/msg-to-botonic.js +160 -0
  129. package/lib/cjs/msg-to-botonic.js.map +1 -0
  130. package/lib/cjs/node-app.d.ts +11 -0
  131. package/lib/cjs/node-app.js +25 -0
  132. package/lib/cjs/node-app.js.map +1 -0
  133. package/lib/cjs/react-bot.d.ts +8 -0
  134. package/lib/cjs/react-bot.js +35 -0
  135. package/lib/cjs/react-bot.js.map +1 -0
  136. package/lib/cjs/util/dom.d.ts +13 -0
  137. package/lib/cjs/util/dom.js +55 -0
  138. package/lib/cjs/util/dom.js.map +1 -0
  139. package/lib/cjs/util/environment.d.ts +6 -0
  140. package/lib/cjs/util/environment.js +68 -0
  141. package/lib/cjs/util/environment.js.map +1 -0
  142. package/lib/cjs/util/error-boundary.js +47 -0
  143. package/lib/cjs/util/error-boundary.js.map +1 -0
  144. package/lib/cjs/util/index.d.ts +0 -0
  145. package/lib/cjs/util/index.js +2 -0
  146. package/lib/cjs/util/index.js.map +1 -0
  147. package/lib/cjs/util/logs.d.ts +2 -0
  148. package/lib/cjs/util/logs.js +20 -0
  149. package/lib/cjs/util/logs.js.map +1 -0
  150. package/lib/cjs/util/objects.d.ts +3 -0
  151. package/lib/cjs/util/objects.js +44 -0
  152. package/lib/cjs/util/objects.js.map +1 -0
  153. package/lib/cjs/util/react.d.ts +12 -0
  154. package/lib/cjs/util/react.js +42 -0
  155. package/lib/cjs/util/react.js.map +1 -0
  156. package/lib/cjs/util/regexs.d.ts +2 -0
  157. package/lib/cjs/util/regexs.js +23 -0
  158. package/lib/cjs/util/regexs.js.map +1 -0
  159. package/lib/cjs/util/webchat.d.ts +11 -0
  160. package/lib/cjs/util/webchat.js +62 -0
  161. package/lib/cjs/util/webchat.js.map +1 -0
  162. package/lib/cjs/webchat/actions.d.ts +23 -0
  163. package/lib/cjs/webchat/actions.js +27 -0
  164. package/lib/cjs/webchat/actions.js.map +1 -0
  165. package/lib/cjs/webchat/components/attachment.d.ts +5 -0
  166. package/lib/cjs/webchat/components/attachment.js +32 -0
  167. package/lib/cjs/webchat/components/attachment.js.map +1 -0
  168. package/lib/cjs/webchat/components/common.d.ts +1 -0
  169. package/lib/cjs/webchat/components/common.js +13 -0
  170. package/lib/cjs/webchat/components/common.js.map +1 -0
  171. package/lib/cjs/webchat/components/conditional-animation.d.ts +1 -0
  172. package/lib/cjs/webchat/components/conditional-animation.js +18 -0
  173. package/lib/cjs/webchat/components/conditional-animation.js.map +1 -0
  174. package/lib/cjs/webchat/components/emoji-picker.d.ts +5 -0
  175. package/lib/cjs/webchat/components/emoji-picker.js +52 -0
  176. package/lib/cjs/webchat/components/emoji-picker.js.map +1 -0
  177. package/lib/cjs/webchat/components/persistent-menu.d.ts +10 -0
  178. package/lib/cjs/webchat/components/persistent-menu.js +59 -0
  179. package/lib/cjs/webchat/components/persistent-menu.js.map +1 -0
  180. package/lib/cjs/webchat/components/send-button.d.ts +3 -0
  181. package/lib/cjs/webchat/components/send-button.js +24 -0
  182. package/lib/cjs/webchat/components/send-button.js.map +1 -0
  183. package/lib/cjs/webchat/components/styled-scrollbar.d.ts +1 -0
  184. package/lib/cjs/webchat/components/styled-scrollbar.js +54 -0
  185. package/lib/cjs/webchat/components/styled-scrollbar.js.map +1 -0
  186. package/lib/cjs/webchat/components/typing-indicator.d.ts +1 -0
  187. package/lib/cjs/webchat/components/typing-indicator.js +14 -0
  188. package/lib/cjs/webchat/components/typing-indicator.js.map +1 -0
  189. package/lib/cjs/webchat/devices/device-adapter.d.ts +12 -0
  190. package/lib/cjs/webchat/devices/device-adapter.js +47 -0
  191. package/lib/cjs/webchat/devices/device-adapter.js.map +1 -0
  192. package/lib/cjs/webchat/devices/index.d.ts +11 -0
  193. package/lib/cjs/webchat/devices/index.js +23 -0
  194. package/lib/cjs/webchat/devices/index.js.map +1 -0
  195. package/lib/cjs/webchat/devices/scrollbar-controller.d.ts +12 -0
  196. package/lib/cjs/webchat/devices/scrollbar-controller.js +103 -0
  197. package/lib/cjs/webchat/devices/scrollbar-controller.js.map +1 -0
  198. package/lib/cjs/webchat/devices/webchat-resizer.d.ts +9 -0
  199. package/lib/cjs/webchat/devices/webchat-resizer.js +47 -0
  200. package/lib/cjs/webchat/devices/webchat-resizer.js.map +1 -0
  201. package/lib/cjs/webchat/header.d.ts +3 -0
  202. package/lib/cjs/webchat/header.js +95 -0
  203. package/lib/cjs/webchat/header.js.map +1 -0
  204. package/lib/cjs/webchat/hooks.d.ts +80 -0
  205. package/lib/cjs/webchat/hooks.js +218 -0
  206. package/lib/cjs/webchat/hooks.js.map +1 -0
  207. package/lib/cjs/webchat/index.d.ts +4 -0
  208. package/lib/cjs/webchat/index.js +17 -0
  209. package/lib/cjs/webchat/index.js.map +1 -0
  210. package/lib/cjs/webchat/message-list.d.ts +1 -0
  211. package/lib/cjs/webchat/message-list.js +46 -0
  212. package/lib/cjs/webchat/message-list.js.map +1 -0
  213. package/lib/cjs/webchat/messages-reducer.d.ts +1 -0
  214. package/lib/cjs/webchat/messages-reducer.js +58 -0
  215. package/lib/cjs/webchat/messages-reducer.js.map +1 -0
  216. package/lib/cjs/webchat/replies.d.ts +1 -0
  217. package/lib/cjs/webchat/replies.js +46 -0
  218. package/lib/cjs/webchat/replies.js.map +1 -0
  219. package/lib/cjs/webchat/session-view.d.ts +1 -0
  220. package/lib/cjs/webchat/session-view.js +124 -0
  221. package/lib/cjs/webchat/session-view.js.map +1 -0
  222. package/lib/cjs/webchat/use-storage-state-hook.d.ts +1 -0
  223. package/lib/cjs/webchat/use-storage-state-hook.js +32 -0
  224. package/lib/cjs/webchat/use-storage-state-hook.js.map +1 -0
  225. package/lib/cjs/webchat/webchat-dev.d.ts +7 -0
  226. package/lib/cjs/webchat/webchat-dev.js +64 -0
  227. package/lib/cjs/webchat/webchat-dev.js.map +1 -0
  228. package/lib/cjs/webchat/webchat-reducer.d.ts +1 -0
  229. package/lib/cjs/webchat/webchat-reducer.js +48 -0
  230. package/lib/cjs/webchat/webchat-reducer.js.map +1 -0
  231. package/lib/cjs/webchat/webchat.d.ts +3 -0
  232. package/lib/cjs/webchat/webchat.js +703 -0
  233. package/lib/cjs/webchat/webchat.js.map +1 -0
  234. package/lib/cjs/webchat/webview.d.ts +2 -0
  235. package/lib/cjs/webchat/webview.js +92 -0
  236. package/lib/cjs/webchat/webview.js.map +1 -0
  237. package/lib/cjs/webchat-app.d.ts +99 -0
  238. package/lib/cjs/webchat-app.js +269 -0
  239. package/lib/cjs/webchat-app.js.map +1 -0
  240. package/lib/cjs/webview.d.ts +9 -0
  241. package/lib/cjs/webview.js +102 -0
  242. package/lib/cjs/webview.js.map +1 -0
  243. package/package.json +3 -3
  244. package/lib/app.js +0 -19
  245. package/lib/app.js.map +0 -1
  246. package/lib/assets/attachment-icon.svg +0 -7
  247. package/lib/assets/audio.svg +0 -4
  248. package/lib/assets/botonic_react_logo100x100.png +0 -0
  249. package/lib/assets/document.svg +0 -3
  250. package/lib/assets/emojiButton.svg +0 -6
  251. package/lib/assets/image.svg +0 -4
  252. package/lib/assets/leftArrow.svg +0 -3
  253. package/lib/assets/menuButton.svg +0 -3
  254. package/lib/assets/rightArrow.svg +0 -3
  255. package/lib/assets/send-button.svg +0 -1
  256. package/lib/assets/video.svg +0 -3
  257. package/lib/botonic-tester.js +0 -224
  258. package/lib/botonic-tester.js.map +0 -1
  259. package/lib/components/audio.js +0 -48
  260. package/lib/components/audio.js.map +0 -1
  261. package/lib/components/button.js +0 -224
  262. package/lib/components/button.js.map +0 -1
  263. package/lib/components/buttons-disabler.js +0 -133
  264. package/lib/components/buttons-disabler.js.map +0 -1
  265. package/lib/components/carousel.js +0 -194
  266. package/lib/components/carousel.js.map +0 -1
  267. package/lib/components/components.js.map +0 -1
  268. package/lib/components/custom-message.js +0 -131
  269. package/lib/components/custom-message.js.map +0 -1
  270. package/lib/components/document.js +0 -76
  271. package/lib/components/document.js.map +0 -1
  272. package/lib/components/element.js +0 -69
  273. package/lib/components/element.js.map +0 -1
  274. package/lib/components/handoff.js +0 -69
  275. package/lib/components/handoff.js.map +0 -1
  276. package/lib/components/image.js +0 -91
  277. package/lib/components/image.js.map +0 -1
  278. package/lib/components/index.d.ts +0 -228
  279. package/lib/components/index.js +0 -193
  280. package/lib/components/index.js.map +0 -1
  281. package/lib/components/location.js +0 -69
  282. package/lib/components/location.js.map +0 -1
  283. package/lib/components/markdown.js +0 -108
  284. package/lib/components/markdown.js.map +0 -1
  285. package/lib/components/message-template.js +0 -36
  286. package/lib/components/message-template.js.map +0 -1
  287. package/lib/components/message.js +0 -351
  288. package/lib/components/message.js.map +0 -1
  289. package/lib/components/multichannel/facebook/facebook.js +0 -96
  290. package/lib/components/multichannel/facebook/facebook.js.map +0 -1
  291. package/lib/components/multichannel/index.d.ts +0 -65
  292. package/lib/components/multichannel/index.js +0 -46
  293. package/lib/components/multichannel/index.js.map +0 -1
  294. package/lib/components/multichannel/multichannel-button.js +0 -119
  295. package/lib/components/multichannel/multichannel-button.js.map +0 -1
  296. package/lib/components/multichannel/multichannel-carousel.js +0 -143
  297. package/lib/components/multichannel/multichannel-carousel.js.map +0 -1
  298. package/lib/components/multichannel/multichannel-context.js +0 -24
  299. package/lib/components/multichannel/multichannel-context.js.map +0 -1
  300. package/lib/components/multichannel/multichannel-reply.js +0 -46
  301. package/lib/components/multichannel/multichannel-reply.js.map +0 -1
  302. package/lib/components/multichannel/multichannel-text.js +0 -222
  303. package/lib/components/multichannel/multichannel-text.js.map +0 -1
  304. package/lib/components/multichannel/multichannel-utils.js +0 -126
  305. package/lib/components/multichannel/multichannel-utils.js.map +0 -1
  306. package/lib/components/multichannel/multichannel.js +0 -111
  307. package/lib/components/multichannel/multichannel.js.map +0 -1
  308. package/lib/components/pic.js +0 -50
  309. package/lib/components/pic.js.map +0 -1
  310. package/lib/components/raw.js +0 -70
  311. package/lib/components/raw.js.map +0 -1
  312. package/lib/components/reply.js +0 -107
  313. package/lib/components/reply.js.map +0 -1
  314. package/lib/components/share-button.js +0 -36
  315. package/lib/components/share-button.js.map +0 -1
  316. package/lib/components/subtitle.js +0 -54
  317. package/lib/components/subtitle.js.map +0 -1
  318. package/lib/components/text.js +0 -80
  319. package/lib/components/text.js.map +0 -1
  320. package/lib/components/timestamps.js +0 -69
  321. package/lib/components/timestamps.js.map +0 -1
  322. package/lib/components/title.js +0 -52
  323. package/lib/components/title.js.map +0 -1
  324. package/lib/components/video.js +0 -51
  325. package/lib/components/video.js.map +0 -1
  326. package/lib/components/webchat-settings.js +0 -118
  327. package/lib/components/webchat-settings.js.map +0 -1
  328. package/lib/components/whatsapp-template.js +0 -53
  329. package/lib/components/whatsapp-template.js.map +0 -1
  330. package/lib/constants.js +0 -203
  331. package/lib/constants.js.map +0 -1
  332. package/lib/contexts.js +0 -57
  333. package/lib/contexts.js.map +0 -1
  334. package/lib/dev-app.js +0 -241
  335. package/lib/dev-app.js.map +0 -1
  336. package/lib/index.d.ts +0 -238
  337. package/lib/index.js +0 -131
  338. package/lib/index.js.map +0 -1
  339. package/lib/message-utils.js +0 -149
  340. package/lib/message-utils.js.map +0 -1
  341. package/lib/msg-to-botonic.js +0 -199
  342. package/lib/msg-to-botonic.js.map +0 -1
  343. package/lib/node-app.js +0 -97
  344. package/lib/node-app.js.map +0 -1
  345. package/lib/react-bot.js +0 -167
  346. package/lib/react-bot.js.map +0 -1
  347. package/lib/util/dom.js +0 -84
  348. package/lib/util/dom.js.map +0 -1
  349. package/lib/util/environment.js +0 -42
  350. package/lib/util/environment.js.map +0 -1
  351. package/lib/util/error-boundary.js +0 -105
  352. package/lib/util/error-boundary.js.map +0 -1
  353. package/lib/util/index.d.ts +0 -9
  354. package/lib/util/index.js +0 -2
  355. package/lib/util/index.js.map +0 -1
  356. package/lib/util/logs.js +0 -28
  357. package/lib/util/logs.js.map +0 -1
  358. package/lib/util/objects.js +0 -60
  359. package/lib/util/objects.js.map +0 -1
  360. package/lib/util/react.js +0 -75
  361. package/lib/util/react.js.map +0 -1
  362. package/lib/util/regexs.js +0 -31
  363. package/lib/util/regexs.js.map +0 -1
  364. package/lib/util/webchat.js +0 -92
  365. package/lib/util/webchat.js.map +0 -1
  366. package/lib/webchat/actions.js +0 -53
  367. package/lib/webchat/actions.js.map +0 -1
  368. package/lib/webchat/components/attachment.js +0 -68
  369. package/lib/webchat/components/attachment.js.map +0 -1
  370. package/lib/webchat/components/common.js +0 -29
  371. package/lib/webchat/components/common.js.map +0 -1
  372. package/lib/webchat/components/conditional-animation.js +0 -42
  373. package/lib/webchat/components/conditional-animation.js.map +0 -1
  374. package/lib/webchat/components/emoji-picker.js +0 -89
  375. package/lib/webchat/components/emoji-picker.js.map +0 -1
  376. package/lib/webchat/components/persistent-menu.js +0 -104
  377. package/lib/webchat/components/persistent-menu.js.map +0 -1
  378. package/lib/webchat/components/send-button.js +0 -45
  379. package/lib/webchat/components/send-button.js.map +0 -1
  380. package/lib/webchat/components/styled-scrollbar.js +0 -55
  381. package/lib/webchat/components/styled-scrollbar.js.map +0 -1
  382. package/lib/webchat/components/styled-scrollbar.scss +0 -12
  383. package/lib/webchat/components/typing-indicator.js +0 -27
  384. package/lib/webchat/components/typing-indicator.js.map +0 -1
  385. package/lib/webchat/components/typing-indicator.scss +0 -38
  386. package/lib/webchat/devices/device-adapter.js +0 -82
  387. package/lib/webchat/devices/device-adapter.js.map +0 -1
  388. package/lib/webchat/devices/index.js +0 -32
  389. package/lib/webchat/devices/index.js.map +0 -1
  390. package/lib/webchat/devices/scrollbar-controller.js +0 -152
  391. package/lib/webchat/devices/scrollbar-controller.js.map +0 -1
  392. package/lib/webchat/devices/webchat-resizer.js +0 -76
  393. package/lib/webchat/devices/webchat-resizer.js.map +0 -1
  394. package/lib/webchat/header.js +0 -116
  395. package/lib/webchat/header.js.map +0 -1
  396. package/lib/webchat/hooks.js +0 -359
  397. package/lib/webchat/hooks.js.map +0 -1
  398. package/lib/webchat/index.d.ts +0 -62
  399. package/lib/webchat/index.js +0 -32
  400. package/lib/webchat/index.js.map +0 -1
  401. package/lib/webchat/message-list.js +0 -88
  402. package/lib/webchat/message-list.js.map +0 -1
  403. package/lib/webchat/messages-reducer.js +0 -93
  404. package/lib/webchat/messages-reducer.js.map +0 -1
  405. package/lib/webchat/replies.js +0 -78
  406. package/lib/webchat/replies.js.map +0 -1
  407. package/lib/webchat/session-view.js +0 -106
  408. package/lib/webchat/session-view.js.map +0 -1
  409. package/lib/webchat/use-storage-state-hook.js +0 -60
  410. package/lib/webchat/use-storage-state-hook.js.map +0 -1
  411. package/lib/webchat/webchat-dev.js +0 -109
  412. package/lib/webchat/webchat-dev.js.map +0 -1
  413. package/lib/webchat/webchat-reducer.js +0 -108
  414. package/lib/webchat/webchat-reducer.js.map +0 -1
  415. package/lib/webchat/webchat.js +0 -1108
  416. package/lib/webchat/webchat.js.map +0 -1
  417. package/lib/webchat/webview.js +0 -122
  418. package/lib/webchat/webview.js.map +0 -1
  419. package/lib/webchat-app.js +0 -660
  420. package/lib/webchat-app.js.map +0 -1
  421. package/lib/webchat.template.html +0 -37
  422. package/lib/webview.js +0 -231
  423. package/lib/webview.js.map +0 -1
  424. package/lib/webview.template.html +0 -39
@@ -0,0 +1,703 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Webchat = exports.getParsedAction = void 0;
4
+ const tslib_1 = require("tslib");
5
+ const core_1 = require("@botonic/core");
6
+ const lodash_merge_1 = tslib_1.__importDefault(require("lodash.merge"));
7
+ const react_1 = tslib_1.__importStar(require("react"));
8
+ const react_textarea_autosize_1 = tslib_1.__importDefault(require("react-textarea-autosize"));
9
+ const styled_components_1 = tslib_1.__importStar(require("styled-components"));
10
+ const use_async_effect_1 = require("use-async-effect");
11
+ const uuid_1 = require("uuid");
12
+ const components_1 = require("../components");
13
+ const handoff_1 = require("../components/handoff");
14
+ const webchat_settings_1 = require("../components/webchat-settings");
15
+ const constants_1 = require("../constants");
16
+ const contexts_1 = require("../contexts");
17
+ const message_utils_1 = require("../message-utils");
18
+ const msg_to_botonic_1 = require("../msg-to-botonic");
19
+ const dom_1 = require("../util/dom");
20
+ const environment_1 = require("../util/environment");
21
+ const regexs_1 = require("../util/regexs");
22
+ const webchat_1 = require("../util/webchat");
23
+ const attachment_1 = require("./components/attachment");
24
+ const emoji_picker_1 = require("./components/emoji-picker");
25
+ const persistent_menu_1 = require("./components/persistent-menu");
26
+ const send_button_1 = require("./components/send-button");
27
+ const typing_indicator_1 = require("./components/typing-indicator");
28
+ const device_adapter_1 = require("./devices/device-adapter");
29
+ const header_1 = require("./header");
30
+ const hooks_1 = require("./hooks");
31
+ const message_list_1 = require("./message-list");
32
+ const replies_1 = require("./replies");
33
+ const use_storage_state_hook_1 = require("./use-storage-state-hook");
34
+ const webview_1 = require("./webview");
35
+ const getParsedAction = botonicAction => {
36
+ const splittedAction = botonicAction.split('create_case:');
37
+ if (splittedAction.length <= 1)
38
+ return undefined;
39
+ return JSON.parse(splittedAction[1]);
40
+ };
41
+ exports.getParsedAction = getParsedAction;
42
+ const StyledWebchat = styled_components_1.default.div `
43
+ position: fixed;
44
+ right: 20px;
45
+ bottom: 20px;
46
+ width: ${props => props.width}px;
47
+ height: ${props => props.height}px;
48
+ margin: auto;
49
+ background-color: ${constants_1.COLORS.SOLID_WHITE};
50
+ border-radius: 10px;
51
+ box-shadow: ${constants_1.COLORS.SOLID_BLACK_ALPHA_0_2} 0px 0px 12px;
52
+ display: flex;
53
+ flex-direction: column;
54
+ `;
55
+ const StyledTriggerButton = styled_components_1.default.div `
56
+ cursor: pointer;
57
+ position: fixed;
58
+ background: ${constants_1.COLORS.SOLID_WHITE};
59
+ border-radius: 50%;
60
+ display: flex;
61
+ align-items: center;
62
+ justify-content: center;
63
+ overflow: hidden;
64
+ width: 65px;
65
+ height: 65px;
66
+ bottom: 20px;
67
+ right: 10px;
68
+ padding: 8px;
69
+ `;
70
+ const UserInputContainer = styled_components_1.default.div `
71
+ min-height: 52px;
72
+ position: relative;
73
+ display: flex;
74
+ align-items: center;
75
+ justify-content: flex-start;
76
+ gap: 16px;
77
+ padding: 0px 16px;
78
+ z-index: 1;
79
+ border-top: 1px solid ${constants_1.COLORS.SOLID_BLACK_ALPHA_0_5};
80
+ `;
81
+ const TextAreaContainer = styled_components_1.default.div `
82
+ display: flex;
83
+ flex: 1 1 auto;
84
+ align-items: center;
85
+ `;
86
+ const TriggerImage = styled_components_1.default.img `
87
+ max-width: 100%;
88
+ max-height: 100%;
89
+ `;
90
+ const ErrorMessageContainer = styled_components_1.default.div `
91
+ position: relative;
92
+ display: flex;
93
+ z-index: 1;
94
+ justify-content: center;
95
+ width: 100%;
96
+ `;
97
+ const ErrorMessage = styled_components_1.default.div `
98
+ position: absolute;
99
+ top: 10px;
100
+ font-size: 14px;
101
+ line-height: 20px;
102
+ padding: 4px 11px;
103
+ display: flex;
104
+ background-color: ${constants_1.COLORS.ERROR_RED};
105
+ color: ${constants_1.COLORS.CONCRETE_WHITE};
106
+ border-radius: 5px;
107
+ align-items: center;
108
+ justify-content: center;
109
+ font-family: ${constants_1.WEBCHAT.DEFAULTS.FONT_FAMILY};
110
+ `;
111
+ const DarkBackgroundMenu = styled_components_1.default.div `
112
+ background: ${constants_1.COLORS.SOLID_BLACK};
113
+ opacity: 0.3;
114
+ z-index: 1;
115
+ right: 0;
116
+ bottom: 0;
117
+ border-radius: 10px;
118
+ position: absolute;
119
+ width: 100%;
120
+ height: 100%;
121
+ `;
122
+ // eslint-disable-next-line complexity
123
+ exports.Webchat = react_1.forwardRef((props, ref) => {
124
+ const { webchatState, addMessage, addMessageComponent, updateMessage, updateReplies, updateLatestInput, updateTyping, updateWebview, updateSession, updateLastRoutePath, updateHandoff, updateTheme, updateDevSettings, toggleWebchat, toggleEmojiPicker, togglePersistentMenu, toggleCoverComponent, doRenderCustomComponent, setError, setOnline, clearMessages, openWebviewT, closeWebviewT, updateLastMessageDate, setCurrentAttachment,
125
+ // eslint-disable-next-line react-hooks/rules-of-hooks
126
+ } = props.webchatHooks || hooks_1.useWebchat();
127
+ const firstUpdate = react_1.useRef(true);
128
+ const isOnline = () => webchatState.online;
129
+ const currentDateString = () => new Date().toISOString();
130
+ const theme = lodash_merge_1.default(webchatState.theme, props.theme);
131
+ const { initialSession, initialDevSettings, onStateChange } = props;
132
+ const getThemeProperty = webchat_1._getThemeProperty(theme);
133
+ const [customComponent, setCustomComponent] = react_1.useState(null);
134
+ const storage = props.storage;
135
+ const storageKey = typeof props.storageKey === 'function'
136
+ ? props.storageKey()
137
+ : props.storageKey;
138
+ const [botonicState, saveState] = use_storage_state_hook_1.useStorageState(storage, storageKey);
139
+ const host = props.host || document.body;
140
+ const deviceAdapter = new device_adapter_1.DeviceAdapter();
141
+ const saveWebchatState = webchatState => {
142
+ storage &&
143
+ saveState(JSON.parse(regexs_1.stringifyWithRegexs({
144
+ messages: webchatState.messagesJSON,
145
+ session: webchatState.session,
146
+ lastRoutePath: webchatState.lastRoutePath,
147
+ devSettings: webchatState.devSettings,
148
+ lastMessageUpdate: webchatState.lastMessageUpdate,
149
+ themeUpdates: webchatState.themeUpdates,
150
+ })));
151
+ };
152
+ const handleAttachment = event => {
153
+ if (!message_utils_1.isAllowedSize(event.target.files[0].size)) {
154
+ throw new Error(`The file is too large. A maximum of ${constants_1.MAX_ALLOWED_SIZE_MB}MB is allowed.`);
155
+ }
156
+ setCurrentAttachment({
157
+ fileName: event.target.files[0].name,
158
+ file: event.target.files[0],
159
+ attachmentType: message_utils_1.getMediaType(event.target.files[0].type),
160
+ });
161
+ };
162
+ react_1.useEffect(() => {
163
+ if (webchatState.currentAttachment)
164
+ sendAttachment(webchatState.currentAttachment);
165
+ }, [webchatState.currentAttachment]);
166
+ const sendUserInput = async (input) => {
167
+ props.onUserInput &&
168
+ props.onUserInput({
169
+ user: webchatState.session.user,
170
+ input: input,
171
+ session: webchatState.session,
172
+ lastRoutePath: webchatState.lastRoutePath,
173
+ });
174
+ };
175
+ const sendChatEvent = async (chatEvent) => {
176
+ const chatEventInput = {
177
+ id: uuid_1.v4(),
178
+ type: core_1.INPUT.CHAT_EVENT,
179
+ data: chatEvent,
180
+ };
181
+ props.onUserInput &&
182
+ props.onUserInput({
183
+ user: webchatState.session.user,
184
+ input: chatEventInput,
185
+ session: webchatState.session,
186
+ lastRoutePath: webchatState.lastRoutePath,
187
+ });
188
+ };
189
+ // Load styles stored in window._botonicInsertStyles by Webpack
190
+ hooks_1.useComponentWillMount(() => {
191
+ if (window._botonicInsertStyles && window._botonicInsertStyles.length) {
192
+ for (const botonicStyle of window._botonicInsertStyles) {
193
+ // Injecting styles at head is needed even if we use shadowDOM
194
+ // as some dependencies like simplebar rely on creating ephemeral elements
195
+ // on document.body and assume styles will be available globally
196
+ document.head.appendChild(botonicStyle);
197
+ // injecting styles in host node too so that shadowDOM works
198
+ if (props.shadowDOM)
199
+ host.appendChild(botonicStyle.cloneNode(true));
200
+ }
201
+ delete window._botonicInsertStyles;
202
+ }
203
+ if (props.shadowDOM) {
204
+ // emoji-picker-react injects styles in head, so we need to
205
+ // re-inject them in our host node to make it work with shadowDOM
206
+ for (const style of document.querySelectorAll('style')) {
207
+ if (style.textContent &&
208
+ style.textContent.includes('emoji-picker-react'))
209
+ host.appendChild(style.cloneNode(true));
210
+ }
211
+ }
212
+ });
213
+ // Load initial state from storage
214
+ react_1.useEffect(() => {
215
+ let { messages, session, lastRoutePath, devSettings, lastMessageUpdate, themeUpdates, } = botonicState || {};
216
+ session = webchat_1.initSession(session);
217
+ updateSession(session);
218
+ if (webchat_1.shouldKeepSessionOnReload({ initialDevSettings, devSettings })) {
219
+ if (messages) {
220
+ messages.forEach(m => {
221
+ addMessage(m);
222
+ const newComponent = msg_to_botonic_1.msgToBotonic(Object.assign(Object.assign({}, m), { delay: 0, typing: 0 }), (props.theme.message && props.theme.message.customTypes) ||
223
+ props.theme.customMessageTypes);
224
+ if (newComponent)
225
+ addMessageComponent(newComponent);
226
+ });
227
+ }
228
+ if (initialSession)
229
+ updateSession(lodash_merge_1.default(initialSession, session));
230
+ if (lastRoutePath)
231
+ updateLastRoutePath(lastRoutePath);
232
+ }
233
+ else
234
+ updateSession(lodash_merge_1.default(initialSession, session));
235
+ if (devSettings)
236
+ updateDevSettings(devSettings);
237
+ else if (initialDevSettings)
238
+ updateDevSettings(initialDevSettings);
239
+ if (lastMessageUpdate)
240
+ updateLastMessageDate(lastMessageUpdate);
241
+ if (themeUpdates !== undefined)
242
+ updateTheme(lodash_merge_1.default(props.theme, themeUpdates), themeUpdates);
243
+ if (props.onInit)
244
+ setTimeout(() => props.onInit(), 100);
245
+ }, []);
246
+ react_1.useEffect(() => {
247
+ if (!webchatState.isWebchatOpen)
248
+ return;
249
+ deviceAdapter.init(host);
250
+ dom_1.scrollToBottom({ behavior: 'auto', host });
251
+ }, [webchatState.isWebchatOpen]);
252
+ react_1.useEffect(() => {
253
+ if (onStateChange && typeof onStateChange === 'function')
254
+ onStateChange(webchatState);
255
+ saveWebchatState(webchatState);
256
+ }, [
257
+ webchatState.messagesJSON,
258
+ webchatState.session,
259
+ webchatState.lastRoutePath,
260
+ webchatState.devSettings,
261
+ webchatState.lastMessageUpdate,
262
+ ]);
263
+ use_async_effect_1.useAsyncEffect(async () => {
264
+ if (!webchatState.online) {
265
+ setError({
266
+ message: webchat_1.getServerErrorMessage(props.server),
267
+ });
268
+ }
269
+ else {
270
+ if (!firstUpdate.current) {
271
+ setError(undefined);
272
+ }
273
+ }
274
+ }, [webchatState.online]);
275
+ hooks_1.useTyping({ webchatState, updateTyping, updateMessage, host });
276
+ react_1.useEffect(() => {
277
+ updateTheme(lodash_merge_1.default(props.theme, theme, webchatState.themeUpdates));
278
+ }, [props.theme, webchatState.themeUpdates]);
279
+ const openWebview = (webviewComponent, params) => updateWebview(webviewComponent, params);
280
+ const handleSelectedEmoji = (event, emojiObject) => {
281
+ textArea.current.value += emojiObject.emoji;
282
+ textArea.current.focus();
283
+ };
284
+ const closeWebview = options => {
285
+ updateWebview();
286
+ if (userInputEnabled) {
287
+ textArea.current.focus();
288
+ }
289
+ if (options && options.payload) {
290
+ sendPayload(options.payload);
291
+ }
292
+ else if (options && options.path) {
293
+ let params = '';
294
+ if (options.params)
295
+ params = core_1.params2queryString(options.params);
296
+ sendPayload(`__PATH_PAYLOAD__${options.path}?${params}`);
297
+ }
298
+ };
299
+ const handleMenu = () => {
300
+ togglePersistentMenu(!webchatState.isPersistentMenuOpen);
301
+ };
302
+ const handleEmojiClick = () => {
303
+ toggleEmojiPicker(!webchatState.isEmojiPickerOpen);
304
+ };
305
+ const persistentMenuOptions = getThemeProperty(constants_1.WEBCHAT.CUSTOM_PROPERTIES.persistentMenu, props.persistentMenu);
306
+ const darkBackgroundMenu = getThemeProperty(constants_1.WEBCHAT.CUSTOM_PROPERTIES.darkBackgroundMenu, false);
307
+ const getBlockInputs = (rule, inputData) => {
308
+ const processedInput = rule.preprocess
309
+ ? rule.preprocess(inputData)
310
+ : inputData;
311
+ return rule.match.some(regex => {
312
+ if (typeof regex === 'string')
313
+ regex = regexs_1.deserializeRegex(regex);
314
+ return regex.test(processedInput);
315
+ });
316
+ };
317
+ const checkBlockInput = input => {
318
+ // if is a text we check if it is a serialized RE
319
+ const blockInputs = getThemeProperty(constants_1.WEBCHAT.CUSTOM_PROPERTIES.blockInputs, props.blockInputs);
320
+ if (!Array.isArray(blockInputs))
321
+ return false;
322
+ for (const rule of blockInputs) {
323
+ if (getBlockInputs(rule, input.data)) {
324
+ addMessageComponent(<components_1.Text id={input.id} from={constants_1.SENDERS.user} blob={false} style={{
325
+ backgroundColor: constants_1.COLORS.SCORPION_GRAY,
326
+ borderColor: constants_1.COLORS.SCORPION_GRAY,
327
+ padding: '8px 12px',
328
+ }}>
329
+ {rule.message}
330
+ </components_1.Text>);
331
+ updateReplies(false);
332
+ return true;
333
+ }
334
+ }
335
+ return false;
336
+ };
337
+ const closeMenu = () => {
338
+ togglePersistentMenu(false);
339
+ };
340
+ const persistentMenu = () => {
341
+ return (<persistent_menu_1.OpenedPersistentMenu onClick={closeMenu} options={persistentMenuOptions} borderRadius={webchatState.theme.style.borderRadius || '10px'}/>);
342
+ };
343
+ const getCoverComponent = () => {
344
+ return getThemeProperty(constants_1.WEBCHAT.CUSTOM_PROPERTIES.coverComponent, props.coverComponent &&
345
+ (props.coverComponent.component || props.coverComponent));
346
+ };
347
+ const CoverComponent = getCoverComponent();
348
+ const closeCoverComponent = () => {
349
+ toggleCoverComponent(false);
350
+ };
351
+ react_1.useEffect(() => {
352
+ if (!CoverComponent)
353
+ return;
354
+ if (!botonicState ||
355
+ (botonicState.messages && botonicState.messages.length == 0))
356
+ toggleCoverComponent(true);
357
+ }, []);
358
+ const coverComponent = () => {
359
+ const coverComponentProps = getThemeProperty(constants_1.WEBCHAT.CUSTOM_PROPERTIES.coverComponentProps, props.coverComponent && props.coverComponent.props);
360
+ if (CoverComponent && webchatState.isCoverComponentOpen)
361
+ return (<CoverComponent closeComponent={closeCoverComponent} {...coverComponentProps}/>);
362
+ return null;
363
+ };
364
+ const messageComponentFromInput = input => {
365
+ let messageComponent = null;
366
+ if (message_utils_1.isText(input)) {
367
+ messageComponent = (<components_1.Text id={input.id} payload={input.payload} from={constants_1.SENDERS.user}>
368
+ {input.data}
369
+ </components_1.Text>);
370
+ }
371
+ else if (message_utils_1.isMedia(input)) {
372
+ const temporaryDisplayUrl = URL.createObjectURL(input.data);
373
+ const mediaProps = {
374
+ id: input.id,
375
+ from: constants_1.SENDERS.user,
376
+ src: temporaryDisplayUrl,
377
+ };
378
+ if (message_utils_1.isImage(input))
379
+ messageComponent = <components_1.Image {...mediaProps}/>;
380
+ else if (message_utils_1.isAudio(input))
381
+ messageComponent = <components_1.Audio {...mediaProps}/>;
382
+ else if (message_utils_1.isVideo(input))
383
+ messageComponent = <components_1.Video {...mediaProps}/>;
384
+ else if (message_utils_1.isDocument(input))
385
+ messageComponent = <components_1.Document {...mediaProps}/>;
386
+ }
387
+ return messageComponent;
388
+ };
389
+ const sendInput = async (input) => {
390
+ if (!input || Object.keys(input).length == 0)
391
+ return;
392
+ if (message_utils_1.isText(input) && (!input.data || !input.data.trim()))
393
+ return; // in case trim() doesn't work in a browser we can use !/\S/.test(input.data)
394
+ if (message_utils_1.isText(input) && checkBlockInput(input))
395
+ return;
396
+ if (!input.id)
397
+ input.id = uuid_1.v4();
398
+ const messageComponent = messageComponentFromInput(input);
399
+ if (messageComponent)
400
+ addMessageComponent(messageComponent);
401
+ if (message_utils_1.isMedia(input))
402
+ input.data = await message_utils_1.readDataURL(input.data);
403
+ sendUserInput(input);
404
+ updateLatestInput(input);
405
+ isOnline() && updateLastMessageDate(currentDateString());
406
+ updateReplies(false);
407
+ togglePersistentMenu(false);
408
+ toggleEmojiPicker(false);
409
+ };
410
+ /* This is the public API this component exposes to its parents
411
+ https://stackoverflow.com/questions/37949981/call-child-method-from-parent
412
+ */
413
+ const updateSessionWithUser = userToUpdate => updateSession(lodash_merge_1.default(webchatState.session, { user: userToUpdate }));
414
+ react_1.useImperativeHandle(ref, () => ({
415
+ addBotResponse: ({ response, session, lastRoutePath }) => {
416
+ updateTyping(false);
417
+ if (Array.isArray(response))
418
+ response.map(r => addMessageComponent(r));
419
+ else if (response)
420
+ addMessageComponent(response);
421
+ if (session) {
422
+ updateSession(lodash_merge_1.default(session, { user: webchatState.session.user }));
423
+ const action = session._botonic_action || '';
424
+ const handoff = action.startsWith('create_case');
425
+ if (handoff && environment_1.isDev)
426
+ addMessageComponent(<handoff_1.Handoff />);
427
+ updateHandoff(handoff);
428
+ }
429
+ if (lastRoutePath)
430
+ updateLastRoutePath(lastRoutePath);
431
+ updateLastMessageDate(currentDateString());
432
+ },
433
+ setTyping: typing => updateTyping(typing),
434
+ addUserMessage: message => sendInput(message),
435
+ updateUser: updateSessionWithUser,
436
+ openWebchat: () => toggleWebchat(true),
437
+ closeWebchat: () => toggleWebchat(false),
438
+ toggleWebchat: () => toggleWebchat(!webchatState.isWebchatOpen),
439
+ openCoverComponent: () => toggleCoverComponent(true),
440
+ closeCoverComponent: () => toggleCoverComponent(false),
441
+ renderCustomComponent: _customComponent => {
442
+ setCustomComponent(_customComponent);
443
+ doRenderCustomComponent(true);
444
+ },
445
+ unmountCustomComponent: () => doRenderCustomComponent(false),
446
+ toggleCoverComponent: () => toggleCoverComponent(!webchatState.isCoverComponentOpen),
447
+ openWebviewApi: component => openWebviewT(component),
448
+ setError,
449
+ setOnline,
450
+ getMessages: () => webchatState.messagesJSON,
451
+ isOnline,
452
+ clearMessages: () => {
453
+ clearMessages();
454
+ updateReplies(false);
455
+ },
456
+ getLastMessageUpdate: () => webchatState.lastMessageUpdate,
457
+ updateMessageInfo: (msgId, messageInfo) => {
458
+ const messageToUpdate = webchatState.messagesJSON.filter(m => m.id == msgId)[0];
459
+ const updatedMsg = lodash_merge_1.default(messageToUpdate, messageInfo);
460
+ if (updatedMsg.ack === 1)
461
+ delete updatedMsg.unsentInput;
462
+ updateMessage(updatedMsg);
463
+ },
464
+ updateWebchatSettings: settings => {
465
+ const themeUpdates = webchat_settings_1.normalizeWebchatSettings(settings);
466
+ updateTheme(lodash_merge_1.default(webchatState.theme, themeUpdates), themeUpdates);
467
+ },
468
+ }));
469
+ const resolveCase = () => {
470
+ updateHandoff(false);
471
+ updateSession(Object.assign(Object.assign({}, webchatState.session), { _botonic_action: null }));
472
+ };
473
+ const prevSession = hooks_1.usePrevious(webchatState.session);
474
+ react_1.useEffect(() => {
475
+ // Resume conversation after handoff
476
+ if (prevSession &&
477
+ prevSession._botonic_action &&
478
+ !webchatState.session._botonic_action) {
479
+ const action = exports.getParsedAction(prevSession._botonic_action);
480
+ if (action && action.on_finish)
481
+ sendPayload(action.on_finish);
482
+ }
483
+ }, [webchatState.session._botonic_action]);
484
+ const sendText = async (text, payload) => {
485
+ if (!text)
486
+ return;
487
+ const input = { type: core_1.INPUT.TEXT, data: text, payload };
488
+ await sendInput(input);
489
+ };
490
+ const sendPayload = async (payload) => {
491
+ if (!payload)
492
+ return;
493
+ const input = { type: core_1.INPUT.POSTBACK, payload };
494
+ await sendInput(input);
495
+ };
496
+ const sendAttachment = async (attachment) => {
497
+ if (attachment.file) {
498
+ const attachmentType = message_utils_1.getMediaType(attachment.file.type);
499
+ if (!attachmentType)
500
+ return;
501
+ const input = {
502
+ type: attachmentType,
503
+ data: attachment.file,
504
+ };
505
+ await sendInput(input);
506
+ setCurrentAttachment(undefined);
507
+ }
508
+ };
509
+ const sendTextAreaText = () => {
510
+ sendText(textArea.current.value);
511
+ textArea.current.value = '';
512
+ };
513
+ let isTyping = false;
514
+ let typingTimeout = null;
515
+ function clearTimeoutWithReset(reset) {
516
+ const waitTime = 20 * 1000;
517
+ if (typingTimeout)
518
+ clearTimeout(typingTimeout);
519
+ if (reset)
520
+ typingTimeout = setTimeout(stopTyping, waitTime);
521
+ }
522
+ function startTyping() {
523
+ isTyping = true;
524
+ sendChatEvent('typing_on');
525
+ }
526
+ function stopTyping() {
527
+ clearTimeoutWithReset(false);
528
+ isTyping = false;
529
+ sendChatEvent('typing_off');
530
+ }
531
+ const onKeyDown = event => {
532
+ if (event.keyCode === 13 && event.shiftKey === false) {
533
+ event.preventDefault();
534
+ sendTextAreaText();
535
+ stopTyping();
536
+ }
537
+ };
538
+ const onKeyUp = () => {
539
+ if (textArea.current.value === '') {
540
+ stopTyping();
541
+ return;
542
+ }
543
+ if (!isTyping) {
544
+ startTyping();
545
+ }
546
+ clearTimeoutWithReset(true);
547
+ };
548
+ const webviewRequestContext = {
549
+ getString: stringId => props.getString(stringId, webchatState.session),
550
+ setLocale: locale => props.getString(locale, webchatState.session),
551
+ session: webchatState.session || {},
552
+ params: webchatState.webviewParams || {},
553
+ closeWebview: closeWebview,
554
+ defaultDelay: props.defaultDelay || 0,
555
+ defaultTyping: props.defaultTyping || 0,
556
+ };
557
+ react_1.useEffect(() => {
558
+ if (firstUpdate.current) {
559
+ firstUpdate.current = false;
560
+ return;
561
+ }
562
+ if (webchatState.isWebchatOpen && props.onOpen)
563
+ props.onOpen();
564
+ if (!webchatState.isWebchatOpen && props.onClose && !firstUpdate.current) {
565
+ props.onClose();
566
+ toggleEmojiPicker(false);
567
+ togglePersistentMenu(false);
568
+ }
569
+ }, [webchatState.isWebchatOpen]);
570
+ const textArea = react_1.useRef();
571
+ const getTriggerImage = () => {
572
+ const triggerImage = getThemeProperty(constants_1.WEBCHAT.CUSTOM_PROPERTIES.triggerButtonImage, null);
573
+ if (triggerImage === null) {
574
+ webchatState.theme.triggerButtonImage = constants_1.WEBCHAT.DEFAULTS.LOGO;
575
+ return null;
576
+ }
577
+ return triggerImage;
578
+ };
579
+ const triggerButtonStyle = getThemeProperty(constants_1.WEBCHAT.CUSTOM_PROPERTIES.triggerButtonStyle);
580
+ const CustomTriggerButton = getThemeProperty(constants_1.WEBCHAT.CUSTOM_PROPERTIES.customTrigger, undefined);
581
+ const triggerButton = () => {
582
+ if (CustomTriggerButton) {
583
+ return <CustomTriggerButton />;
584
+ }
585
+ return (<StyledTriggerButton role={constants_1.ROLES.TRIGGER_BUTTON} style={Object.assign({}, triggerButtonStyle)}>
586
+ {getTriggerImage() && (<TriggerImage src={environment_1.resolveImage(getTriggerImage())}/>)}
587
+ </StyledTriggerButton>);
588
+ };
589
+ const webchatMessageList = () => (<message_list_1.WebchatMessageList style={{ flex: 1 }}>
590
+ {webchatState.typing && <typing_indicator_1.TypingIndicator />}
591
+ </message_list_1.WebchatMessageList>);
592
+ const webchatReplies = () => <replies_1.WebchatReplies replies={webchatState.replies}/>;
593
+ const isUserInputEnabled = () => {
594
+ const isUserInputEnabled = getThemeProperty(constants_1.WEBCHAT.CUSTOM_PROPERTIES.enableUserInput, props.enableUserInput !== undefined ? props.enableUserInput : true);
595
+ return isUserInputEnabled && !webchatState.isCoverComponentOpen;
596
+ };
597
+ const userInputEnabled = isUserInputEnabled();
598
+ const userInputArea = () => {
599
+ return (userInputEnabled && (<UserInputContainer style={Object.assign({}, getThemeProperty(constants_1.WEBCHAT.CUSTOM_PROPERTIES.userInputStyle))} className='user-input-container'>
600
+ {webchatState.isEmojiPickerOpen && (<emoji_picker_1.OpenedEmojiPicker height={webchatState.theme.style.height} onEmojiClick={handleSelectedEmoji} onClick={handleEmojiClick}/>)}
601
+
602
+ <persistent_menu_1.PersistentMenu onClick={handleMenu} persistentMenu={props.persistentMenu}/>
603
+
604
+ <TextAreaContainer>
605
+ <react_textarea_autosize_1.default name='text' onFocus={() => deviceAdapter.onFocus(host)} onBlur={() => deviceAdapter.onBlur()} maxRows={4} wrap='soft' maxLength='1000' placeholder={getThemeProperty(constants_1.WEBCHAT.CUSTOM_PROPERTIES.textPlaceholder, constants_1.WEBCHAT.DEFAULTS.PLACEHOLDER)} autoFocus={true} inputRef={textArea} onKeyDown={e => onKeyDown(e)} onKeyUp={onKeyUp} style={Object.assign({ display: 'flex', fontSize: deviceAdapter.fontSize(14), width: '100%', border: 'none', resize: 'none', overflow: 'auto', outline: 'none', flex: '1 1 auto', padding: 10, paddingLeft: persistentMenuOptions ? 0 : 10, fontFamily: 'inherit' }, getThemeProperty(constants_1.WEBCHAT.CUSTOM_PROPERTIES.userInputBoxStyle))}/>
606
+ </TextAreaContainer>
607
+
608
+ <emoji_picker_1.EmojiPicker enableEmojiPicker={props.enableEmojiPicker} onClick={handleEmojiClick}/>
609
+
610
+ <attachment_1.Attachment enableAttachments={props.enableAttachments} onChange={handleAttachment} accept={message_utils_1.getFullMimeWhitelist().join(',')}/>
611
+
612
+ <send_button_1.SendButton onClick={sendTextAreaText}/>
613
+ </UserInputContainer>));
614
+ };
615
+ const webchatWebview = () => (<contexts_1.RequestContext.Provider value={webviewRequestContext}>
616
+ <webview_1.WebviewContainer style={Object.assign(Object.assign({}, getThemeProperty(constants_1.WEBCHAT.CUSTOM_PROPERTIES.webviewStyle)), mobileStyle)} webview={webchatState.webview}/>
617
+ </contexts_1.RequestContext.Provider>);
618
+ let mobileStyle = {};
619
+ if (core_1.isMobile(getThemeProperty(constants_1.WEBCHAT.CUSTOM_PROPERTIES.mobileBreakpoint))) {
620
+ mobileStyle = getThemeProperty(constants_1.WEBCHAT.CUSTOM_PROPERTIES.mobileStyle) || {
621
+ width: '100%',
622
+ height: '100%',
623
+ right: 0,
624
+ bottom: 0,
625
+ borderRadius: 0,
626
+ };
627
+ }
628
+ react_1.useEffect(() => {
629
+ // Prod mode
630
+ saveWebchatState(webchatState);
631
+ dom_1.scrollToBottom({ host });
632
+ }, [webchatState.themeUpdates]);
633
+ // Only needed for dev/serve mode
634
+ const updateWebchatDevSettings = settings => {
635
+ // eslint-disable-next-line react-hooks/rules-of-hooks
636
+ react_1.useEffect(() => {
637
+ const themeUpdates = webchat_settings_1.normalizeWebchatSettings(settings);
638
+ updateTheme(lodash_merge_1.default(webchatState.theme, themeUpdates), themeUpdates);
639
+ }, [webchatState.messagesJSON]);
640
+ };
641
+ const DarkenBackground = ({ component }) => {
642
+ return (<div>
643
+ {darkBackgroundMenu && (<DarkBackgroundMenu style={{
644
+ borderRadius: webchatState.theme.style.borderRadius,
645
+ }}/>)}
646
+ {component}
647
+ </div>);
648
+ };
649
+ const _renderCustomComponent = () => {
650
+ if (!customComponent)
651
+ return <></>;
652
+ else
653
+ return customComponent;
654
+ };
655
+ const WebchatComponent = (<contexts_1.WebchatContext.Provider value={{
656
+ sendText,
657
+ sendAttachment,
658
+ sendPayload,
659
+ sendInput,
660
+ openWebview,
661
+ resolveCase,
662
+ webchatState,
663
+ getThemeProperty,
664
+ addMessage,
665
+ toggleWebchat,
666
+ updateMessage,
667
+ updateReplies,
668
+ updateLatestInput,
669
+ updateUser: updateSessionWithUser,
670
+ updateWebchatDevSettings: updateWebchatDevSettings,
671
+ }}>
672
+ {!webchatState.isWebchatOpen && (<div onClick={event => {
673
+ toggleWebchat(true);
674
+ event.preventDefault();
675
+ }}>
676
+ {triggerButton()}
677
+ </div>)}
678
+
679
+ {webchatState.isWebchatOpen && (<StyledWebchat
680
+ // TODO: Distinguis between multiple instances of webchat, e.g. `${uniqueId}-botonic-webchat`
681
+ role={constants_1.ROLES.WEBCHAT} id={constants_1.WEBCHAT.DEFAULTS.ID} width={webchatState.width} height={webchatState.height} style={Object.assign(Object.assign({}, webchatState.theme.style), mobileStyle)}>
682
+ <header_1.StyledWebchatHeader onCloseClick={() => {
683
+ toggleWebchat(false);
684
+ }}/>
685
+ {webchatState.error.message && (<ErrorMessageContainer>
686
+ <ErrorMessage>{webchatState.error.message}</ErrorMessage>
687
+ </ErrorMessageContainer>)}
688
+ {webchatMessageList()}
689
+ {webchatState.replies &&
690
+ Object.keys(webchatState.replies).length > 0 &&
691
+ webchatReplies()}
692
+ {webchatState.isPersistentMenuOpen && (<DarkenBackground component={persistentMenu()}/>)}
693
+ {!webchatState.handoff && userInputArea()}
694
+ {webchatState.webview && webchatWebview()}
695
+ {webchatState.isCoverComponentOpen && coverComponent()}
696
+ {webchatState.isCustomComponentRendered &&
697
+ customComponent &&
698
+ _renderCustomComponent()}
699
+ </StyledWebchat>)}
700
+ </contexts_1.WebchatContext.Provider>);
701
+ return props.shadowDOM ? (<styled_components_1.StyleSheetManager target={host}>{WebchatComponent}</styled_components_1.StyleSheetManager>) : (WebchatComponent);
702
+ });
703
+ //# sourceMappingURL=webchat.js.map