@botonic/react 0.23.1-alpha.0 → 0.23.2-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 (261) hide show
  1. package/lib/cjs/botonic-tester.js +2 -2
  2. package/lib/cjs/botonic-tester.js.map +1 -1
  3. package/lib/cjs/components/audio.js +2 -2
  4. package/lib/cjs/components/audio.js.map +1 -1
  5. package/lib/cjs/components/button.js +2 -2
  6. package/lib/cjs/components/button.js.map +1 -1
  7. package/lib/cjs/components/carousel.js +3 -3
  8. package/lib/cjs/components/carousel.js.map +1 -1
  9. package/lib/cjs/components/custom-message.js +1 -1
  10. package/lib/cjs/components/custom-message.js.map +1 -1
  11. package/lib/cjs/components/document.js +2 -2
  12. package/lib/cjs/components/document.js.map +1 -1
  13. package/lib/cjs/components/handoff.js +2 -2
  14. package/lib/cjs/components/handoff.js.map +1 -1
  15. package/lib/cjs/components/image.js +1 -1
  16. package/lib/cjs/components/image.js.map +1 -1
  17. package/lib/cjs/components/index-types.d.ts +1 -1
  18. package/lib/cjs/components/location.js +2 -2
  19. package/lib/cjs/components/location.js.map +1 -1
  20. package/lib/cjs/components/message-template.js +1 -1
  21. package/lib/cjs/components/message-template.js.map +1 -1
  22. package/lib/cjs/components/message.js +3 -3
  23. package/lib/cjs/components/message.js.map +1 -1
  24. package/lib/cjs/components/multichannel/multichannel-carousel.js +1 -1
  25. package/lib/cjs/components/multichannel/multichannel-carousel.js.map +1 -1
  26. package/lib/cjs/components/multichannel/multichannel-text.js +6 -17
  27. package/lib/cjs/components/multichannel/multichannel-text.js.map +1 -1
  28. package/lib/cjs/components/multichannel/multichannel-utils.d.ts +5 -5
  29. package/lib/cjs/components/multichannel/multichannel-utils.js +2 -2
  30. package/lib/cjs/components/multichannel/multichannel-utils.js.map +1 -1
  31. package/lib/cjs/components/multichannel/multichannel.js +2 -2
  32. package/lib/cjs/components/multichannel/multichannel.js.map +1 -1
  33. package/lib/cjs/components/raw.js +2 -2
  34. package/lib/cjs/components/raw.js.map +1 -1
  35. package/lib/cjs/components/reply.js +4 -4
  36. package/lib/cjs/components/reply.js.map +1 -1
  37. package/lib/cjs/components/share-button.js +1 -1
  38. package/lib/cjs/components/share-button.js.map +1 -1
  39. package/lib/cjs/components/subtitle.js +1 -1
  40. package/lib/cjs/components/subtitle.js.map +1 -1
  41. package/lib/cjs/components/text.js +2 -2
  42. package/lib/cjs/components/text.js.map +1 -1
  43. package/lib/cjs/components/timestamps.js +1 -1
  44. package/lib/cjs/components/timestamps.js.map +1 -1
  45. package/lib/cjs/components/title.js +1 -1
  46. package/lib/cjs/components/title.js.map +1 -1
  47. package/lib/cjs/components/video.js +2 -2
  48. package/lib/cjs/components/video.js.map +1 -1
  49. package/lib/cjs/components/whatsapp-button-list.js +1 -1
  50. package/lib/cjs/components/whatsapp-button-list.js.map +1 -1
  51. package/lib/cjs/components/whatsapp-template.js +1 -1
  52. package/lib/cjs/components/whatsapp-template.js.map +1 -1
  53. package/lib/cjs/constants.d.ts +148 -148
  54. package/lib/cjs/contexts.d.ts +4 -62
  55. package/lib/cjs/contexts.js +45 -19
  56. package/lib/cjs/contexts.js.map +1 -1
  57. package/lib/cjs/index-types.d.ts +12 -12
  58. package/lib/cjs/msg-to-botonic.js +2 -2
  59. package/lib/cjs/msg-to-botonic.js.map +1 -1
  60. package/lib/cjs/react-bot.js +1 -1
  61. package/lib/cjs/react-bot.js.map +1 -1
  62. package/lib/cjs/webchat/actions.d.ts +25 -23
  63. package/lib/cjs/webchat/actions.js +27 -24
  64. package/lib/cjs/webchat/actions.js.map +1 -1
  65. package/lib/cjs/webchat/components/attachment.js +1 -1
  66. package/lib/cjs/webchat/components/attachment.js.map +1 -1
  67. package/lib/cjs/webchat/components/conditional-animation.js +1 -1
  68. package/lib/cjs/webchat/components/conditional-animation.js.map +1 -1
  69. package/lib/cjs/webchat/components/emoji-picker.js +2 -2
  70. package/lib/cjs/webchat/components/emoji-picker.js.map +1 -1
  71. package/lib/cjs/webchat/components/persistent-menu.js +4 -4
  72. package/lib/cjs/webchat/components/persistent-menu.js.map +1 -1
  73. package/lib/cjs/webchat/components/send-button.js +1 -1
  74. package/lib/cjs/webchat/components/send-button.js.map +1 -1
  75. package/lib/cjs/webchat/components/typing-indicator.js +1 -1
  76. package/lib/cjs/webchat/components/typing-indicator.js.map +1 -1
  77. package/lib/cjs/webchat/header.js +1 -1
  78. package/lib/cjs/webchat/header.js.map +1 -1
  79. package/lib/cjs/webchat/hooks/index.d.ts +5 -0
  80. package/lib/cjs/webchat/hooks/index.js +15 -0
  81. package/lib/cjs/webchat/hooks/index.js.map +1 -0
  82. package/lib/cjs/webchat/hooks/use-component-visible.d.ts +8 -0
  83. package/lib/cjs/webchat/hooks/use-component-visible.js +24 -0
  84. package/lib/cjs/webchat/hooks/use-component-visible.js.map +1 -0
  85. package/lib/cjs/webchat/hooks/use-component-will-mount.d.ts +1 -0
  86. package/lib/cjs/webchat/hooks/use-component-will-mount.js +9 -0
  87. package/lib/cjs/webchat/hooks/use-component-will-mount.js.map +1 -0
  88. package/lib/cjs/webchat/hooks/use-previous.d.ts +1 -0
  89. package/lib/cjs/webchat/hooks/use-previous.js +13 -0
  90. package/lib/cjs/webchat/hooks/use-previous.js.map +1 -0
  91. package/lib/cjs/webchat/hooks/use-typing.d.ts +10 -0
  92. package/lib/cjs/webchat/hooks/use-typing.js +32 -0
  93. package/lib/cjs/webchat/hooks/use-typing.js.map +1 -0
  94. package/lib/cjs/webchat/hooks/use-webchat.d.ts +37 -0
  95. package/lib/cjs/webchat/hooks/use-webchat.js +167 -0
  96. package/lib/cjs/webchat/hooks/use-webchat.js.map +1 -0
  97. package/lib/cjs/webchat/index-types.d.ts +16 -10
  98. package/lib/cjs/webchat/message-list.js +2 -2
  99. package/lib/cjs/webchat/message-list.js.map +1 -1
  100. package/lib/cjs/webchat/messages-reducer.d.ts +6 -1
  101. package/lib/cjs/webchat/messages-reducer.js +8 -8
  102. package/lib/cjs/webchat/messages-reducer.js.map +1 -1
  103. package/lib/cjs/webchat/replies.js +1 -1
  104. package/lib/cjs/webchat/replies.js.map +1 -1
  105. package/lib/cjs/webchat/session-view.js +2 -2
  106. package/lib/cjs/webchat/session-view.js.map +1 -1
  107. package/lib/cjs/webchat/trigger-button/index.js +1 -3
  108. package/lib/cjs/webchat/trigger-button/index.js.map +1 -1
  109. package/lib/cjs/webchat/webchat-reducer.d.ts +6 -1
  110. package/lib/cjs/webchat/webchat-reducer.js +17 -17
  111. package/lib/cjs/webchat/webchat-reducer.js.map +1 -1
  112. package/lib/cjs/webchat/webchat.js +21 -21
  113. package/lib/cjs/webchat/webchat.js.map +1 -1
  114. package/lib/cjs/webchat/webview.js +4 -4
  115. package/lib/cjs/webchat/webview.js.map +1 -1
  116. package/lib/cjs/webview-app.js +1 -1
  117. package/lib/cjs/webview-app.js.map +1 -1
  118. package/lib/esm/botonic-tester.js +2 -2
  119. package/lib/esm/botonic-tester.js.map +1 -1
  120. package/lib/esm/components/audio.js +2 -2
  121. package/lib/esm/components/audio.js.map +1 -1
  122. package/lib/esm/components/button.js +2 -2
  123. package/lib/esm/components/button.js.map +1 -1
  124. package/lib/esm/components/carousel.js +3 -3
  125. package/lib/esm/components/carousel.js.map +1 -1
  126. package/lib/esm/components/custom-message.js +1 -1
  127. package/lib/esm/components/custom-message.js.map +1 -1
  128. package/lib/esm/components/document.js +2 -2
  129. package/lib/esm/components/document.js.map +1 -1
  130. package/lib/esm/components/handoff.js +2 -2
  131. package/lib/esm/components/handoff.js.map +1 -1
  132. package/lib/esm/components/image.js +1 -1
  133. package/lib/esm/components/image.js.map +1 -1
  134. package/lib/esm/components/index-types.d.ts +1 -1
  135. package/lib/esm/components/location.js +2 -2
  136. package/lib/esm/components/location.js.map +1 -1
  137. package/lib/esm/components/message-template.js +1 -1
  138. package/lib/esm/components/message-template.js.map +1 -1
  139. package/lib/esm/components/message.js +3 -3
  140. package/lib/esm/components/message.js.map +1 -1
  141. package/lib/esm/components/multichannel/multichannel-carousel.js +1 -1
  142. package/lib/esm/components/multichannel/multichannel-carousel.js.map +1 -1
  143. package/lib/esm/components/multichannel/multichannel-text.js +7 -18
  144. package/lib/esm/components/multichannel/multichannel-text.js.map +1 -1
  145. package/lib/esm/components/multichannel/multichannel-utils.d.ts +5 -5
  146. package/lib/esm/components/multichannel/multichannel-utils.js +1 -1
  147. package/lib/esm/components/multichannel/multichannel-utils.js.map +1 -1
  148. package/lib/esm/components/multichannel/multichannel.js +2 -2
  149. package/lib/esm/components/multichannel/multichannel.js.map +1 -1
  150. package/lib/esm/components/raw.js +2 -2
  151. package/lib/esm/components/raw.js.map +1 -1
  152. package/lib/esm/components/reply.js +4 -4
  153. package/lib/esm/components/reply.js.map +1 -1
  154. package/lib/esm/components/share-button.js +1 -1
  155. package/lib/esm/components/share-button.js.map +1 -1
  156. package/lib/esm/components/subtitle.js +1 -1
  157. package/lib/esm/components/subtitle.js.map +1 -1
  158. package/lib/esm/components/text.js +2 -2
  159. package/lib/esm/components/text.js.map +1 -1
  160. package/lib/esm/components/timestamps.js +1 -1
  161. package/lib/esm/components/timestamps.js.map +1 -1
  162. package/lib/esm/components/title.js +1 -1
  163. package/lib/esm/components/title.js.map +1 -1
  164. package/lib/esm/components/video.js +2 -2
  165. package/lib/esm/components/video.js.map +1 -1
  166. package/lib/esm/components/whatsapp-button-list.js +1 -1
  167. package/lib/esm/components/whatsapp-button-list.js.map +1 -1
  168. package/lib/esm/components/whatsapp-template.js +1 -1
  169. package/lib/esm/components/whatsapp-template.js.map +1 -1
  170. package/lib/esm/constants.d.ts +148 -148
  171. package/lib/esm/contexts.d.ts +4 -62
  172. package/lib/esm/contexts.js +45 -19
  173. package/lib/esm/contexts.js.map +1 -1
  174. package/lib/esm/index-types.d.ts +12 -12
  175. package/lib/esm/msg-to-botonic.js +2 -2
  176. package/lib/esm/msg-to-botonic.js.map +1 -1
  177. package/lib/esm/react-bot.js +1 -1
  178. package/lib/esm/react-bot.js.map +1 -1
  179. package/lib/esm/webchat/actions.d.ts +25 -23
  180. package/lib/esm/webchat/actions.js +26 -23
  181. package/lib/esm/webchat/actions.js.map +1 -1
  182. package/lib/esm/webchat/components/attachment.js +1 -1
  183. package/lib/esm/webchat/components/attachment.js.map +1 -1
  184. package/lib/esm/webchat/components/conditional-animation.js +1 -1
  185. package/lib/esm/webchat/components/conditional-animation.js.map +1 -1
  186. package/lib/esm/webchat/components/emoji-picker.js +2 -2
  187. package/lib/esm/webchat/components/emoji-picker.js.map +1 -1
  188. package/lib/esm/webchat/components/persistent-menu.js +4 -4
  189. package/lib/esm/webchat/components/persistent-menu.js.map +1 -1
  190. package/lib/esm/webchat/components/send-button.js +1 -1
  191. package/lib/esm/webchat/components/send-button.js.map +1 -1
  192. package/lib/esm/webchat/components/typing-indicator.js +1 -1
  193. package/lib/esm/webchat/components/typing-indicator.js.map +1 -1
  194. package/lib/esm/webchat/header.js +1 -1
  195. package/lib/esm/webchat/header.js.map +1 -1
  196. package/lib/esm/webchat/hooks/index.d.ts +5 -0
  197. package/lib/esm/webchat/hooks/index.js +6 -0
  198. package/lib/esm/webchat/hooks/index.js.map +1 -0
  199. package/lib/esm/webchat/hooks/use-component-visible.d.ts +8 -0
  200. package/lib/esm/webchat/hooks/use-component-visible.js +20 -0
  201. package/lib/esm/webchat/hooks/use-component-visible.js.map +1 -0
  202. package/lib/esm/webchat/hooks/use-component-will-mount.d.ts +1 -0
  203. package/lib/esm/webchat/hooks/use-component-will-mount.js +5 -0
  204. package/lib/esm/webchat/hooks/use-component-will-mount.js.map +1 -0
  205. package/lib/esm/webchat/hooks/use-previous.d.ts +1 -0
  206. package/lib/esm/webchat/hooks/use-previous.js +9 -0
  207. package/lib/esm/webchat/hooks/use-previous.js.map +1 -0
  208. package/lib/esm/webchat/hooks/use-typing.d.ts +10 -0
  209. package/lib/esm/webchat/hooks/use-typing.js +28 -0
  210. package/lib/esm/webchat/hooks/use-typing.js.map +1 -0
  211. package/lib/esm/webchat/hooks/use-webchat.d.ts +37 -0
  212. package/lib/esm/webchat/hooks/use-webchat.js +163 -0
  213. package/lib/esm/webchat/hooks/use-webchat.js.map +1 -0
  214. package/lib/esm/webchat/index-types.d.ts +16 -10
  215. package/lib/esm/webchat/message-list.js +2 -2
  216. package/lib/esm/webchat/message-list.js.map +1 -1
  217. package/lib/esm/webchat/messages-reducer.d.ts +6 -1
  218. package/lib/esm/webchat/messages-reducer.js +9 -9
  219. package/lib/esm/webchat/messages-reducer.js.map +1 -1
  220. package/lib/esm/webchat/replies.js +1 -1
  221. package/lib/esm/webchat/replies.js.map +1 -1
  222. package/lib/esm/webchat/session-view.js +2 -2
  223. package/lib/esm/webchat/session-view.js.map +1 -1
  224. package/lib/esm/webchat/trigger-button/index.js +1 -3
  225. package/lib/esm/webchat/trigger-button/index.js.map +1 -1
  226. package/lib/esm/webchat/webchat-reducer.d.ts +6 -1
  227. package/lib/esm/webchat/webchat-reducer.js +18 -18
  228. package/lib/esm/webchat/webchat-reducer.js.map +1 -1
  229. package/lib/esm/webchat/webchat.js +21 -21
  230. package/lib/esm/webchat/webchat.js.map +1 -1
  231. package/lib/esm/webchat/webview.js +4 -4
  232. package/lib/esm/webchat/webview.js.map +1 -1
  233. package/lib/esm/webview-app.js +1 -1
  234. package/lib/esm/webview-app.js.map +1 -1
  235. package/package.json +4 -4
  236. package/src/components/index-types.ts +1 -1
  237. package/src/components/multichannel/multichannel-text.jsx +11 -21
  238. package/src/components/multichannel/multichannel-utils.js +1 -1
  239. package/src/contexts.tsx +64 -0
  240. package/src/index-types.ts +12 -12
  241. package/src/webchat/actions.ts +25 -0
  242. package/src/webchat/hooks/index.ts +5 -0
  243. package/src/webchat/hooks/use-component-visible.ts +29 -0
  244. package/src/webchat/hooks/use-component-will-mount.ts +5 -0
  245. package/src/webchat/hooks/use-previous.ts +9 -0
  246. package/src/webchat/hooks/use-typing.ts +43 -0
  247. package/src/webchat/hooks/use-webchat.ts +213 -0
  248. package/src/webchat/index-types.ts +17 -8
  249. package/src/webchat/{messages-reducer.js → messages-reducer.ts} +25 -19
  250. package/src/webchat/trigger-button/index.tsx +0 -1
  251. package/src/webchat/{webchat-reducer.js → webchat-reducer.ts} +23 -37
  252. package/src/webchat/webchat.jsx +8 -9
  253. package/lib/cjs/webchat/hooks.d.ts +0 -81
  254. package/lib/cjs/webchat/hooks.js +0 -222
  255. package/lib/cjs/webchat/hooks.js.map +0 -1
  256. package/lib/esm/webchat/hooks.d.ts +0 -81
  257. package/lib/esm/webchat/hooks.js +0 -214
  258. package/lib/esm/webchat/hooks.js.map +0 -1
  259. package/src/contexts.jsx +0 -37
  260. package/src/webchat/actions.jsx +0 -23
  261. package/src/webchat/hooks.js +0 -270
@@ -1,214 +0,0 @@
1
- import { useEffect, useMemo, useReducer, useRef, useState } from 'react';
2
- import { COLORS, WEBCHAT } from '../constants';
3
- import { scrollToBottom } from '../util/dom';
4
- import { ADD_MESSAGE, ADD_MESSAGE_COMPONENT, CLEAR_MESSAGES, DO_RENDER_CUSTOM_COMPONENT, SET_CURRENT_ATTACHMENT, SET_ERROR, SET_ONLINE, TOGGLE_COVER_COMPONENT, TOGGLE_EMOJI_PICKER, TOGGLE_PERSISTENT_MENU, TOGGLE_WEBCHAT, UPDATE_DEV_SETTINGS, UPDATE_HANDOFF, UPDATE_JWT, UPDATE_LAST_MESSAGE_DATE, UPDATE_LAST_ROUTE_PATH, UPDATE_LATEST_INPUT, UPDATE_MESSAGE, UPDATE_REPLIES, UPDATE_SESSION, UPDATE_THEME, UPDATE_TYPING, UPDATE_WEBVIEW, } from './actions';
5
- import { webchatReducer } from './webchat-reducer';
6
- export const webchatInitialState = {
7
- width: WEBCHAT.DEFAULTS.WIDTH,
8
- height: WEBCHAT.DEFAULTS.HEIGHT,
9
- messagesJSON: [],
10
- messagesComponents: [],
11
- replies: [],
12
- latestInput: {},
13
- typing: false,
14
- webview: null,
15
- webviewParams: null,
16
- session: { user: null },
17
- lastRoutePath: null,
18
- handoff: false,
19
- theme: {
20
- headerTitle: WEBCHAT.DEFAULTS.TITLE,
21
- brandColor: COLORS.BOTONIC_BLUE,
22
- brandImage: WEBCHAT.DEFAULTS.LOGO,
23
- triggerButtonImage: undefined,
24
- textPlaceholder: WEBCHAT.DEFAULTS.PLACEHOLDER,
25
- style: {
26
- fontFamily: WEBCHAT.DEFAULTS.FONT_FAMILY,
27
- },
28
- },
29
- themeUpdates: {},
30
- error: {},
31
- online: true,
32
- devSettings: { keepSessionOnReload: false },
33
- isWebchatOpen: false,
34
- isEmojiPickerOpen: false,
35
- isPersistentMenuOpen: false,
36
- isCoverComponentOpen: false,
37
- isCustomComponentRendered: false,
38
- lastMessageUpdate: undefined,
39
- currentAttachment: undefined,
40
- jwt: null,
41
- unreadMessages: 0,
42
- };
43
- export function useWebchat() {
44
- const [webchatState, webchatDispatch] = useReducer(webchatReducer, webchatInitialState);
45
- const addMessage = message => webchatDispatch({ type: ADD_MESSAGE, payload: message });
46
- const addMessageComponent = message => webchatDispatch({ type: ADD_MESSAGE_COMPONENT, payload: message });
47
- const updateMessage = message => webchatDispatch({ type: UPDATE_MESSAGE, payload: message });
48
- const updateReplies = replies => webchatDispatch({ type: UPDATE_REPLIES, payload: replies });
49
- const updateLatestInput = input => webchatDispatch({ type: UPDATE_LATEST_INPUT, payload: input });
50
- const updateTyping = typing => webchatDispatch({ type: UPDATE_TYPING, payload: typing });
51
- const updateWebview = (webview, params) => webchatDispatch({
52
- type: UPDATE_WEBVIEW,
53
- payload: { webview, webviewParams: params },
54
- });
55
- const updateSession = session => {
56
- webchatDispatch({
57
- type: UPDATE_SESSION,
58
- payload: session,
59
- });
60
- };
61
- const updateLastRoutePath = path => webchatDispatch({
62
- type: UPDATE_LAST_ROUTE_PATH,
63
- payload: path,
64
- });
65
- const updateHandoff = handoff => webchatDispatch({
66
- type: UPDATE_HANDOFF,
67
- payload: handoff,
68
- });
69
- const updateTheme = (theme, themeUpdates = undefined) => {
70
- const payload = themeUpdates !== undefined ? { theme, themeUpdates } : { theme };
71
- webchatDispatch({
72
- type: UPDATE_THEME,
73
- payload,
74
- });
75
- };
76
- const updateDevSettings = settings => webchatDispatch({
77
- type: UPDATE_DEV_SETTINGS,
78
- payload: settings,
79
- });
80
- const toggleWebchat = toggle => {
81
- webchatDispatch({
82
- type: TOGGLE_WEBCHAT,
83
- payload: toggle,
84
- });
85
- };
86
- const toggleEmojiPicker = toggle => webchatDispatch({
87
- type: TOGGLE_EMOJI_PICKER,
88
- payload: toggle,
89
- });
90
- const togglePersistentMenu = toggle => webchatDispatch({
91
- type: TOGGLE_PERSISTENT_MENU,
92
- payload: toggle,
93
- });
94
- const toggleCoverComponent = toggle => webchatDispatch({
95
- type: TOGGLE_COVER_COMPONENT,
96
- payload: toggle,
97
- });
98
- const doRenderCustomComponent = toggle => webchatDispatch({
99
- type: DO_RENDER_CUSTOM_COMPONENT,
100
- payload: toggle,
101
- });
102
- const setError = error => webchatDispatch({
103
- type: SET_ERROR,
104
- payload: error,
105
- });
106
- const setOnline = online => webchatDispatch({
107
- type: SET_ONLINE,
108
- payload: online,
109
- });
110
- const clearMessages = () => {
111
- webchatDispatch({
112
- type: CLEAR_MESSAGES,
113
- });
114
- };
115
- const updateLastMessageDate = date => {
116
- webchatDispatch({
117
- type: UPDATE_LAST_MESSAGE_DATE,
118
- payload: date,
119
- });
120
- };
121
- const setCurrentAttachment = attachment => {
122
- webchatDispatch({
123
- type: SET_CURRENT_ATTACHMENT,
124
- payload: attachment,
125
- });
126
- };
127
- const updateJwt = jwt => {
128
- webchatDispatch({
129
- type: UPDATE_JWT,
130
- payload: jwt,
131
- });
132
- };
133
- return {
134
- webchatState,
135
- webchatDispatch,
136
- addMessage,
137
- addMessageComponent,
138
- updateMessage,
139
- updateReplies,
140
- updateLatestInput,
141
- updateTyping,
142
- updateWebview,
143
- updateSession,
144
- updateLastRoutePath,
145
- updateHandoff,
146
- updateTheme,
147
- updateDevSettings,
148
- toggleWebchat,
149
- toggleEmojiPicker,
150
- togglePersistentMenu,
151
- toggleCoverComponent,
152
- doRenderCustomComponent,
153
- setError,
154
- setOnline,
155
- clearMessages,
156
- updateLastMessageDate,
157
- setCurrentAttachment,
158
- updateJwt,
159
- };
160
- }
161
- export function useTyping({ webchatState, updateTyping, updateMessage, host }) {
162
- useEffect(() => {
163
- let delayTimeout, typingTimeout;
164
- scrollToBottom({ host });
165
- try {
166
- const nextMsg = webchatState.messagesJSON.filter(m => !m.display)[0];
167
- if (nextMsg.delay && nextMsg.typing) {
168
- delayTimeout = setTimeout(() => updateTyping(true), nextMsg.delay * 1000);
169
- }
170
- else if (nextMsg.typing)
171
- updateTyping(true);
172
- const totalDelay = nextMsg.delay + nextMsg.typing;
173
- if (totalDelay)
174
- typingTimeout = setTimeout(() => {
175
- updateMessage(Object.assign(Object.assign({}, nextMsg), { display: true }));
176
- updateTyping(false);
177
- }, totalDelay * 1000);
178
- }
179
- catch (e) { }
180
- return () => {
181
- clearTimeout(delayTimeout);
182
- clearTimeout(typingTimeout);
183
- };
184
- }, [webchatState.messagesJSON, webchatState.typing]);
185
- }
186
- export function usePrevious(value) {
187
- const ref = useRef();
188
- useEffect(() => {
189
- ref.current = value;
190
- });
191
- return ref.current;
192
- }
193
- export function useComponentVisible(initialIsVisible, onClickOutside) {
194
- const [isComponentVisible, setIsComponentVisible] = useState(initialIsVisible);
195
- const ref = useRef(null);
196
- const handleClickOutside = event => {
197
- const target = event.path ? event.path[0] : event.target;
198
- if (ref.current && !ref.current.contains(target)) {
199
- setIsComponentVisible(false);
200
- onClickOutside();
201
- }
202
- };
203
- useEffect(() => {
204
- document.addEventListener('click', handleClickOutside, false);
205
- return () => {
206
- document.removeEventListener('click', handleClickOutside, false);
207
- };
208
- });
209
- return { ref, isComponentVisible, setIsComponentVisible };
210
- }
211
- export const useComponentWillMount = func => {
212
- useMemo(func, []);
213
- };
214
- //# sourceMappingURL=hooks.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"hooks.js","sourceRoot":"src/","sources":["webchat/hooks.js"],"names":[],"mappings":"AAAA,OAA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AE;YACV,QAAQ,CAAC,mBAAmB,CAAC,OAAO,EAAE,kBAAkB,EAAE,KAAK,CAAC,CAAA;QAClE,CAAC,CAAA;IACH,CAAC,CAAC,CAAA;IACF,OAAO,EAAE,GAAG,EAAE,kBAAkB,EAAE,qBAAqB,EAAE,CAAA;AAC3D,CAAC;AAED,MAAM,CAAC,MAAM,qBAAqB,GAAG,IAAI,CAAC,EAAE;IAC1C,OAAO,CAAC,IAAI,EAAE,EAAE,CAAC,CAAA;AACnB,CAAC,CAAA"}
package/src/contexts.jsx DELETED
@@ -1,37 +0,0 @@
1
- import { createContext } from 'react'
2
-
3
- import { webchatInitialState } from './webchat/hooks'
4
-
5
- export const RequestContext = createContext({
6
- getString: () => '',
7
- setLocale: () => '',
8
- session: {},
9
- params: {},
10
- input: {},
11
- defaultDelay: 0,
12
- defaultTyping: 0,
13
- })
14
-
15
- export const WebchatContext = createContext({
16
- sendText: text => {},
17
- sendAttachment: attachment => {},
18
- sendPayload: payload => {},
19
- sendInput: input => {},
20
- setReplies: replies => {},
21
- openWebview: webviewComponent => {},
22
- addMessage: message => {},
23
- updateMessage: message => {},
24
- updateReplies: replies => {},
25
- updateLatestInput: input => {},
26
- closeWebview: () => {},
27
- toggleWebchat: toggle => {},
28
- getThemeProperty: (property, defaultValue) => undefined, // used to retrieve a specific property of the theme defined by the developer in his 'webchat/index.js'
29
- resolveCase: () => {},
30
- theme: {},
31
- webchatState: webchatInitialState,
32
- unreadMessages: 0,
33
- updateWebchatDevSettings: settings => {
34
- return {}
35
- },
36
- updateUser: user => {},
37
- })
@@ -1,23 +0,0 @@
1
- export const ADD_MESSAGE = 'addMessage'
2
- export const ADD_MESSAGE_COMPONENT = 'addMessageComponent'
3
- export const UPDATE_MESSAGE = 'updateMessage'
4
- export const UPDATE_REPLIES = 'updateReplies'
5
- export const UPDATE_LATEST_INPUT = 'updateLatestInput'
6
- export const UPDATE_TYPING = 'updateTyping'
7
- export const UPDATE_WEBVIEW = 'updateWebview'
8
- export const UPDATE_SESSION = 'updateSession'
9
- export const UPDATE_LAST_ROUTE_PATH = 'updateLastRoutePath'
10
- export const UPDATE_HANDOFF = 'updateHandoff'
11
- export const UPDATE_THEME = 'updateTheme'
12
- export const UPDATE_DEV_SETTINGS = 'updateDevSettings'
13
- export const TOGGLE_WEBCHAT = 'toggleWebchat'
14
- export const TOGGLE_EMOJI_PICKER = 'toggleEmojiPicker'
15
- export const TOGGLE_PERSISTENT_MENU = 'togglePersistentMenu'
16
- export const TOGGLE_COVER_COMPONENT = 'toggleCoverComponent'
17
- export const DO_RENDER_CUSTOM_COMPONENT = 'doRenderCustomComponent'
18
- export const SET_ERROR = 'setError'
19
- export const CLEAR_MESSAGES = 'clearMessages'
20
- export const UPDATE_LAST_MESSAGE_DATE = 'updateLastMessageDate'
21
- export const SET_CURRENT_ATTACHMENT = 'setCurrentAttachment'
22
- export const SET_ONLINE = 'setOnline'
23
- export const UPDATE_JWT = 'updateJwt'
@@ -1,270 +0,0 @@
1
- import { useEffect, useMemo, useReducer, useRef, useState } from 'react'
2
-
3
- import { COLORS, WEBCHAT } from '../constants'
4
- import { scrollToBottom } from '../util/dom'
5
- import {
6
- ADD_MESSAGE,
7
- ADD_MESSAGE_COMPONENT,
8
- CLEAR_MESSAGES,
9
- DO_RENDER_CUSTOM_COMPONENT,
10
- SET_CURRENT_ATTACHMENT,
11
- SET_ERROR,
12
- SET_ONLINE,
13
- TOGGLE_COVER_COMPONENT,
14
- TOGGLE_EMOJI_PICKER,
15
- TOGGLE_PERSISTENT_MENU,
16
- TOGGLE_WEBCHAT,
17
- UPDATE_DEV_SETTINGS,
18
- UPDATE_HANDOFF,
19
- UPDATE_JWT,
20
- UPDATE_LAST_MESSAGE_DATE,
21
- UPDATE_LAST_ROUTE_PATH,
22
- UPDATE_LATEST_INPUT,
23
- UPDATE_MESSAGE,
24
- UPDATE_REPLIES,
25
- UPDATE_SESSION,
26
- UPDATE_THEME,
27
- UPDATE_TYPING,
28
- UPDATE_WEBVIEW,
29
- } from './actions'
30
- import { webchatReducer } from './webchat-reducer'
31
-
32
- export const webchatInitialState = {
33
- width: WEBCHAT.DEFAULTS.WIDTH,
34
- height: WEBCHAT.DEFAULTS.HEIGHT,
35
- messagesJSON: [],
36
- messagesComponents: [],
37
- replies: [],
38
- latestInput: {},
39
- typing: false,
40
- webview: null,
41
- webviewParams: null,
42
- session: { user: null },
43
- lastRoutePath: null,
44
- handoff: false,
45
- theme: {
46
- headerTitle: WEBCHAT.DEFAULTS.TITLE,
47
- brandColor: COLORS.BOTONIC_BLUE,
48
- brandImage: WEBCHAT.DEFAULTS.LOGO,
49
- triggerButtonImage: undefined,
50
- textPlaceholder: WEBCHAT.DEFAULTS.PLACEHOLDER,
51
- style: {
52
- fontFamily: WEBCHAT.DEFAULTS.FONT_FAMILY,
53
- },
54
- },
55
- themeUpdates: {},
56
- error: {},
57
- online: true,
58
- devSettings: { keepSessionOnReload: false },
59
- isWebchatOpen: false,
60
- isEmojiPickerOpen: false,
61
- isPersistentMenuOpen: false,
62
- isCoverComponentOpen: false,
63
- isCustomComponentRendered: false,
64
- lastMessageUpdate: undefined,
65
- currentAttachment: undefined,
66
- jwt: null,
67
- unreadMessages: 0,
68
- }
69
-
70
- export function useWebchat() {
71
- const [webchatState, webchatDispatch] = useReducer(
72
- webchatReducer,
73
- webchatInitialState
74
- )
75
- const addMessage = message =>
76
- webchatDispatch({ type: ADD_MESSAGE, payload: message })
77
- const addMessageComponent = message =>
78
- webchatDispatch({ type: ADD_MESSAGE_COMPONENT, payload: message })
79
- const updateMessage = message =>
80
- webchatDispatch({ type: UPDATE_MESSAGE, payload: message })
81
- const updateReplies = replies =>
82
- webchatDispatch({ type: UPDATE_REPLIES, payload: replies })
83
- const updateLatestInput = input =>
84
- webchatDispatch({ type: UPDATE_LATEST_INPUT, payload: input })
85
- const updateTyping = typing =>
86
- webchatDispatch({ type: UPDATE_TYPING, payload: typing })
87
- const updateWebview = (webview, params) =>
88
- webchatDispatch({
89
- type: UPDATE_WEBVIEW,
90
- payload: { webview, webviewParams: params },
91
- })
92
- const updateSession = session => {
93
- webchatDispatch({
94
- type: UPDATE_SESSION,
95
- payload: session,
96
- })
97
- }
98
-
99
- const updateLastRoutePath = path =>
100
- webchatDispatch({
101
- type: UPDATE_LAST_ROUTE_PATH,
102
- payload: path,
103
- })
104
- const updateHandoff = handoff =>
105
- webchatDispatch({
106
- type: UPDATE_HANDOFF,
107
- payload: handoff,
108
- })
109
- const updateTheme = (theme, themeUpdates = undefined) => {
110
- const payload =
111
- themeUpdates !== undefined ? { theme, themeUpdates } : { theme }
112
- webchatDispatch({
113
- type: UPDATE_THEME,
114
- payload,
115
- })
116
- }
117
- const updateDevSettings = settings =>
118
- webchatDispatch({
119
- type: UPDATE_DEV_SETTINGS,
120
- payload: settings,
121
- })
122
-
123
- const toggleWebchat = toggle => {
124
- webchatDispatch({
125
- type: TOGGLE_WEBCHAT,
126
- payload: toggle,
127
- })
128
- }
129
-
130
- const toggleEmojiPicker = toggle =>
131
- webchatDispatch({
132
- type: TOGGLE_EMOJI_PICKER,
133
- payload: toggle,
134
- })
135
- const togglePersistentMenu = toggle =>
136
- webchatDispatch({
137
- type: TOGGLE_PERSISTENT_MENU,
138
- payload: toggle,
139
- })
140
- const toggleCoverComponent = toggle =>
141
- webchatDispatch({
142
- type: TOGGLE_COVER_COMPONENT,
143
- payload: toggle,
144
- })
145
- const doRenderCustomComponent = toggle =>
146
- webchatDispatch({
147
- type: DO_RENDER_CUSTOM_COMPONENT,
148
- payload: toggle,
149
- })
150
- const setError = error =>
151
- webchatDispatch({
152
- type: SET_ERROR,
153
- payload: error,
154
- })
155
- const setOnline = online =>
156
- webchatDispatch({
157
- type: SET_ONLINE,
158
- payload: online,
159
- })
160
-
161
- const clearMessages = () => {
162
- webchatDispatch({
163
- type: CLEAR_MESSAGES,
164
- })
165
- }
166
- const updateLastMessageDate = date => {
167
- webchatDispatch({
168
- type: UPDATE_LAST_MESSAGE_DATE,
169
- payload: date,
170
- })
171
- }
172
- const setCurrentAttachment = attachment => {
173
- webchatDispatch({
174
- type: SET_CURRENT_ATTACHMENT,
175
- payload: attachment,
176
- })
177
- }
178
-
179
- const updateJwt = jwt => {
180
- webchatDispatch({
181
- type: UPDATE_JWT,
182
- payload: jwt,
183
- })
184
- }
185
-
186
- return {
187
- webchatState,
188
- webchatDispatch,
189
- addMessage,
190
- addMessageComponent,
191
- updateMessage,
192
- updateReplies,
193
- updateLatestInput,
194
- updateTyping,
195
- updateWebview,
196
- updateSession,
197
- updateLastRoutePath,
198
- updateHandoff,
199
- updateTheme,
200
- updateDevSettings,
201
- toggleWebchat,
202
- toggleEmojiPicker,
203
- togglePersistentMenu,
204
- toggleCoverComponent,
205
- doRenderCustomComponent,
206
- setError,
207
- setOnline,
208
- clearMessages,
209
- updateLastMessageDate,
210
- setCurrentAttachment,
211
- updateJwt,
212
- }
213
- }
214
-
215
- export function useTyping({ webchatState, updateTyping, updateMessage, host }) {
216
- useEffect(() => {
217
- let delayTimeout, typingTimeout
218
- scrollToBottom({ host })
219
- try {
220
- const nextMsg = webchatState.messagesJSON.filter(m => !m.display)[0]
221
- if (nextMsg.delay && nextMsg.typing) {
222
- delayTimeout = setTimeout(
223
- () => updateTyping(true),
224
- nextMsg.delay * 1000
225
- )
226
- } else if (nextMsg.typing) updateTyping(true)
227
- const totalDelay = nextMsg.delay + nextMsg.typing
228
- if (totalDelay)
229
- typingTimeout = setTimeout(() => {
230
- updateMessage({ ...nextMsg, display: true })
231
- updateTyping(false)
232
- }, totalDelay * 1000)
233
- } catch (e) {}
234
- return () => {
235
- clearTimeout(delayTimeout)
236
- clearTimeout(typingTimeout)
237
- }
238
- }, [webchatState.messagesJSON, webchatState.typing])
239
- }
240
-
241
- export function usePrevious(value) {
242
- const ref = useRef()
243
- useEffect(() => {
244
- ref.current = value
245
- })
246
- return ref.current
247
- }
248
-
249
- export function useComponentVisible(initialIsVisible, onClickOutside) {
250
- const [isComponentVisible, setIsComponentVisible] = useState(initialIsVisible)
251
- const ref = useRef(null)
252
- const handleClickOutside = event => {
253
- const target = event.path ? event.path[0] : event.target
254
- if (ref.current && !ref.current.contains(target)) {
255
- setIsComponentVisible(false)
256
- onClickOutside()
257
- }
258
- }
259
- useEffect(() => {
260
- document.addEventListener('click', handleClickOutside, false)
261
- return () => {
262
- document.removeEventListener('click', handleClickOutside, false)
263
- }
264
- })
265
- return { ref, isComponentVisible, setIsComponentVisible }
266
- }
267
-
268
- export const useComponentWillMount = func => {
269
- useMemo(func, [])
270
- }