@botonic/react 0.25.0-alpha.2 → 0.25.0-alpha.4

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