@botonic/react 0.23.0 → 0.23.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/cjs/botonic-tester.js +2 -2
- package/lib/cjs/botonic-tester.js.map +1 -1
- package/lib/cjs/components/audio.js +2 -2
- package/lib/cjs/components/audio.js.map +1 -1
- package/lib/cjs/components/button.js +2 -2
- package/lib/cjs/components/button.js.map +1 -1
- package/lib/cjs/components/carousel.js +3 -3
- package/lib/cjs/components/carousel.js.map +1 -1
- package/lib/cjs/components/custom-message.js +1 -1
- package/lib/cjs/components/custom-message.js.map +1 -1
- package/lib/cjs/components/document.js +2 -2
- package/lib/cjs/components/document.js.map +1 -1
- package/lib/cjs/components/handoff.js +2 -2
- package/lib/cjs/components/handoff.js.map +1 -1
- package/lib/cjs/components/image.js +4 -2
- package/lib/cjs/components/image.js.map +1 -1
- package/lib/cjs/components/index-types.d.ts +8 -1
- package/lib/cjs/components/index-types.js.map +1 -1
- package/lib/cjs/components/location.js +2 -2
- package/lib/cjs/components/location.js.map +1 -1
- package/lib/cjs/components/message-template.js +1 -1
- package/lib/cjs/components/message-template.js.map +1 -1
- package/lib/cjs/components/message.js +3 -3
- package/lib/cjs/components/message.js.map +1 -1
- package/lib/cjs/components/multichannel/index-types.d.ts +1 -0
- package/lib/cjs/components/multichannel/multichannel-carousel.js +1 -1
- package/lib/cjs/components/multichannel/multichannel-carousel.js.map +1 -1
- package/lib/cjs/components/multichannel/multichannel-text.js +43 -19
- package/lib/cjs/components/multichannel/multichannel-text.js.map +1 -1
- package/lib/cjs/components/multichannel/multichannel-utils.d.ts +6 -4
- package/lib/cjs/components/multichannel/multichannel-utils.js +3 -1
- package/lib/cjs/components/multichannel/multichannel-utils.js.map +1 -1
- package/lib/cjs/components/multichannel/multichannel.js +2 -2
- package/lib/cjs/components/multichannel/multichannel.js.map +1 -1
- package/lib/cjs/components/raw.js +2 -2
- package/lib/cjs/components/raw.js.map +1 -1
- package/lib/cjs/components/reply.js +4 -4
- package/lib/cjs/components/reply.js.map +1 -1
- package/lib/cjs/components/share-button.js +1 -1
- package/lib/cjs/components/share-button.js.map +1 -1
- package/lib/cjs/components/subtitle.js +1 -1
- package/lib/cjs/components/subtitle.js.map +1 -1
- package/lib/cjs/components/text.js +2 -2
- package/lib/cjs/components/text.js.map +1 -1
- package/lib/cjs/components/timestamps.js +1 -1
- package/lib/cjs/components/timestamps.js.map +1 -1
- package/lib/cjs/components/title.js +1 -1
- package/lib/cjs/components/title.js.map +1 -1
- package/lib/cjs/components/video.js +2 -2
- package/lib/cjs/components/video.js.map +1 -1
- package/lib/cjs/components/webchat-settings.d.ts +3 -10
- package/lib/cjs/components/webchat-settings.js +9 -14
- package/lib/cjs/components/webchat-settings.js.map +1 -1
- package/lib/cjs/components/whatsapp-button-list.d.ts +1 -1
- package/lib/cjs/components/whatsapp-button-list.js +1 -1
- package/lib/cjs/components/whatsapp-button-list.js.map +1 -1
- package/lib/cjs/components/whatsapp-template.js +1 -1
- package/lib/cjs/components/whatsapp-template.js.map +1 -1
- package/lib/cjs/constants.d.ts +148 -148
- package/lib/cjs/contexts.d.ts +4 -62
- package/lib/cjs/contexts.js +45 -19
- package/lib/cjs/contexts.js.map +1 -1
- package/lib/cjs/index-types.d.ts +12 -12
- package/lib/cjs/msg-to-botonic.js +2 -2
- package/lib/cjs/msg-to-botonic.js.map +1 -1
- package/lib/cjs/react-bot.js +1 -1
- package/lib/cjs/react-bot.js.map +1 -1
- package/lib/cjs/util/environment.js +1 -1
- package/lib/cjs/util/environment.js.map +1 -1
- package/lib/cjs/webchat/actions.d.ts +25 -23
- package/lib/cjs/webchat/actions.js +27 -24
- package/lib/cjs/webchat/actions.js.map +1 -1
- package/lib/cjs/webchat/components/attachment.js +1 -1
- package/lib/cjs/webchat/components/attachment.js.map +1 -1
- package/lib/cjs/webchat/components/conditional-animation.js +1 -1
- package/lib/cjs/webchat/components/conditional-animation.js.map +1 -1
- package/lib/cjs/webchat/components/emoji-picker.js +2 -2
- package/lib/cjs/webchat/components/emoji-picker.js.map +1 -1
- package/lib/cjs/webchat/components/persistent-menu.js +4 -4
- package/lib/cjs/webchat/components/persistent-menu.js.map +1 -1
- package/lib/cjs/webchat/components/send-button.js +1 -1
- package/lib/cjs/webchat/components/send-button.js.map +1 -1
- package/lib/cjs/webchat/components/typing-indicator.js +1 -1
- package/lib/cjs/webchat/components/typing-indicator.js.map +1 -1
- package/lib/cjs/webchat/header.js +1 -1
- package/lib/cjs/webchat/header.js.map +1 -1
- package/lib/cjs/webchat/hooks/index.d.ts +5 -0
- package/lib/cjs/webchat/hooks/index.js +15 -0
- package/lib/cjs/webchat/hooks/index.js.map +1 -0
- package/lib/cjs/webchat/hooks/use-component-visible.d.ts +8 -0
- package/lib/cjs/webchat/hooks/use-component-visible.js +24 -0
- package/lib/cjs/webchat/hooks/use-component-visible.js.map +1 -0
- package/lib/cjs/webchat/hooks/use-component-will-mount.d.ts +1 -0
- package/lib/cjs/webchat/hooks/use-component-will-mount.js +9 -0
- package/lib/cjs/webchat/hooks/use-component-will-mount.js.map +1 -0
- package/lib/cjs/webchat/hooks/use-previous.d.ts +1 -0
- package/lib/cjs/webchat/hooks/use-previous.js +13 -0
- package/lib/cjs/webchat/hooks/use-previous.js.map +1 -0
- package/lib/cjs/webchat/hooks/use-typing.d.ts +10 -0
- package/lib/cjs/webchat/hooks/use-typing.js +32 -0
- package/lib/cjs/webchat/hooks/use-typing.js.map +1 -0
- package/lib/cjs/webchat/hooks/use-webchat.d.ts +37 -0
- package/lib/cjs/webchat/hooks/use-webchat.js +167 -0
- package/lib/cjs/webchat/hooks/use-webchat.js.map +1 -0
- package/lib/cjs/webchat/index-types.d.ts +16 -10
- package/lib/cjs/webchat/message-list.js +2 -2
- package/lib/cjs/webchat/message-list.js.map +1 -1
- package/lib/cjs/webchat/messages-reducer.d.ts +6 -1
- package/lib/cjs/webchat/messages-reducer.js +8 -8
- package/lib/cjs/webchat/messages-reducer.js.map +1 -1
- package/lib/cjs/webchat/replies.js +1 -1
- package/lib/cjs/webchat/replies.js.map +1 -1
- package/lib/cjs/webchat/session-view.js +2 -2
- package/lib/cjs/webchat/session-view.js.map +1 -1
- package/lib/cjs/webchat/trigger-button/index.js +1 -3
- package/lib/cjs/webchat/trigger-button/index.js.map +1 -1
- package/lib/cjs/webchat/webchat-reducer.d.ts +6 -1
- package/lib/cjs/webchat/webchat-reducer.js +17 -17
- package/lib/cjs/webchat/webchat-reducer.js.map +1 -1
- package/lib/cjs/webchat/webchat.js +24 -22
- package/lib/cjs/webchat/webchat.js.map +1 -1
- package/lib/cjs/webchat/webview.js +4 -4
- package/lib/cjs/webchat/webview.js.map +1 -1
- package/lib/cjs/webview-app.js +1 -1
- package/lib/cjs/webview-app.js.map +1 -1
- package/lib/esm/botonic-tester.js +2 -2
- package/lib/esm/botonic-tester.js.map +1 -1
- package/lib/esm/components/audio.js +2 -2
- package/lib/esm/components/audio.js.map +1 -1
- package/lib/esm/components/button.js +2 -2
- package/lib/esm/components/button.js.map +1 -1
- package/lib/esm/components/carousel.js +3 -3
- package/lib/esm/components/carousel.js.map +1 -1
- package/lib/esm/components/custom-message.js +1 -1
- package/lib/esm/components/custom-message.js.map +1 -1
- package/lib/esm/components/document.js +2 -2
- package/lib/esm/components/document.js.map +1 -1
- package/lib/esm/components/handoff.js +2 -2
- package/lib/esm/components/handoff.js.map +1 -1
- package/lib/esm/components/image.js +4 -2
- package/lib/esm/components/image.js.map +1 -1
- package/lib/esm/components/index-types.d.ts +8 -1
- package/lib/esm/components/index-types.js.map +1 -1
- package/lib/esm/components/location.js +2 -2
- package/lib/esm/components/location.js.map +1 -1
- package/lib/esm/components/message-template.js +1 -1
- package/lib/esm/components/message-template.js.map +1 -1
- package/lib/esm/components/message.js +3 -3
- package/lib/esm/components/message.js.map +1 -1
- package/lib/esm/components/multichannel/index-types.d.ts +1 -0
- package/lib/esm/components/multichannel/multichannel-carousel.js +1 -1
- package/lib/esm/components/multichannel/multichannel-carousel.js.map +1 -1
- package/lib/esm/components/multichannel/multichannel-text.js +45 -21
- package/lib/esm/components/multichannel/multichannel-text.js.map +1 -1
- package/lib/esm/components/multichannel/multichannel-utils.d.ts +6 -4
- package/lib/esm/components/multichannel/multichannel-utils.js +2 -0
- package/lib/esm/components/multichannel/multichannel-utils.js.map +1 -1
- package/lib/esm/components/multichannel/multichannel.js +2 -2
- package/lib/esm/components/multichannel/multichannel.js.map +1 -1
- package/lib/esm/components/raw.js +2 -2
- package/lib/esm/components/raw.js.map +1 -1
- package/lib/esm/components/reply.js +4 -4
- package/lib/esm/components/reply.js.map +1 -1
- package/lib/esm/components/share-button.js +1 -1
- package/lib/esm/components/share-button.js.map +1 -1
- package/lib/esm/components/subtitle.js +1 -1
- package/lib/esm/components/subtitle.js.map +1 -1
- package/lib/esm/components/text.js +2 -2
- package/lib/esm/components/text.js.map +1 -1
- package/lib/esm/components/timestamps.js +1 -1
- package/lib/esm/components/timestamps.js.map +1 -1
- package/lib/esm/components/title.js +1 -1
- package/lib/esm/components/title.js.map +1 -1
- package/lib/esm/components/video.js +2 -2
- package/lib/esm/components/video.js.map +1 -1
- package/lib/esm/components/webchat-settings.d.ts +3 -10
- package/lib/esm/components/webchat-settings.js +9 -13
- package/lib/esm/components/webchat-settings.js.map +1 -1
- package/lib/esm/components/whatsapp-button-list.d.ts +1 -1
- package/lib/esm/components/whatsapp-button-list.js +1 -1
- package/lib/esm/components/whatsapp-button-list.js.map +1 -1
- package/lib/esm/components/whatsapp-template.js +1 -1
- package/lib/esm/components/whatsapp-template.js.map +1 -1
- package/lib/esm/constants.d.ts +148 -148
- package/lib/esm/contexts.d.ts +4 -62
- package/lib/esm/contexts.js +45 -19
- package/lib/esm/contexts.js.map +1 -1
- package/lib/esm/index-types.d.ts +12 -12
- package/lib/esm/msg-to-botonic.js +2 -2
- package/lib/esm/msg-to-botonic.js.map +1 -1
- package/lib/esm/react-bot.js +1 -1
- package/lib/esm/react-bot.js.map +1 -1
- package/lib/esm/util/environment.js +1 -1
- package/lib/esm/util/environment.js.map +1 -1
- package/lib/esm/webchat/actions.d.ts +25 -23
- package/lib/esm/webchat/actions.js +26 -23
- package/lib/esm/webchat/actions.js.map +1 -1
- package/lib/esm/webchat/components/attachment.js +1 -1
- package/lib/esm/webchat/components/attachment.js.map +1 -1
- package/lib/esm/webchat/components/conditional-animation.js +1 -1
- package/lib/esm/webchat/components/conditional-animation.js.map +1 -1
- package/lib/esm/webchat/components/emoji-picker.js +2 -2
- package/lib/esm/webchat/components/emoji-picker.js.map +1 -1
- package/lib/esm/webchat/components/persistent-menu.js +4 -4
- package/lib/esm/webchat/components/persistent-menu.js.map +1 -1
- package/lib/esm/webchat/components/send-button.js +1 -1
- package/lib/esm/webchat/components/send-button.js.map +1 -1
- package/lib/esm/webchat/components/typing-indicator.js +1 -1
- package/lib/esm/webchat/components/typing-indicator.js.map +1 -1
- package/lib/esm/webchat/header.js +1 -1
- package/lib/esm/webchat/header.js.map +1 -1
- package/lib/esm/webchat/hooks/index.d.ts +5 -0
- package/lib/esm/webchat/hooks/index.js +6 -0
- package/lib/esm/webchat/hooks/index.js.map +1 -0
- package/lib/esm/webchat/hooks/use-component-visible.d.ts +8 -0
- package/lib/esm/webchat/hooks/use-component-visible.js +20 -0
- package/lib/esm/webchat/hooks/use-component-visible.js.map +1 -0
- package/lib/esm/webchat/hooks/use-component-will-mount.d.ts +1 -0
- package/lib/esm/webchat/hooks/use-component-will-mount.js +5 -0
- package/lib/esm/webchat/hooks/use-component-will-mount.js.map +1 -0
- package/lib/esm/webchat/hooks/use-previous.d.ts +1 -0
- package/lib/esm/webchat/hooks/use-previous.js +9 -0
- package/lib/esm/webchat/hooks/use-previous.js.map +1 -0
- package/lib/esm/webchat/hooks/use-typing.d.ts +10 -0
- package/lib/esm/webchat/hooks/use-typing.js +28 -0
- package/lib/esm/webchat/hooks/use-typing.js.map +1 -0
- package/lib/esm/webchat/hooks/use-webchat.d.ts +37 -0
- package/lib/esm/webchat/hooks/use-webchat.js +163 -0
- package/lib/esm/webchat/hooks/use-webchat.js.map +1 -0
- package/lib/esm/webchat/index-types.d.ts +16 -10
- package/lib/esm/webchat/message-list.js +2 -2
- package/lib/esm/webchat/message-list.js.map +1 -1
- package/lib/esm/webchat/messages-reducer.d.ts +6 -1
- package/lib/esm/webchat/messages-reducer.js +9 -9
- package/lib/esm/webchat/messages-reducer.js.map +1 -1
- package/lib/esm/webchat/replies.js +1 -1
- package/lib/esm/webchat/replies.js.map +1 -1
- package/lib/esm/webchat/session-view.js +2 -2
- package/lib/esm/webchat/session-view.js.map +1 -1
- package/lib/esm/webchat/trigger-button/index.js +1 -3
- package/lib/esm/webchat/trigger-button/index.js.map +1 -1
- package/lib/esm/webchat/webchat-reducer.d.ts +6 -1
- package/lib/esm/webchat/webchat-reducer.js +18 -18
- package/lib/esm/webchat/webchat-reducer.js.map +1 -1
- package/lib/esm/webchat/webchat.js +24 -22
- package/lib/esm/webchat/webchat.js.map +1 -1
- package/lib/esm/webchat/webview.js +4 -4
- package/lib/esm/webchat/webview.js.map +1 -1
- package/lib/esm/webview-app.js +1 -1
- package/lib/esm/webview-app.js.map +1 -1
- package/package.json +2 -2
- package/src/components/image.jsx +3 -1
- package/src/components/index-types.ts +8 -1
- package/src/components/multichannel/index-types.ts +1 -0
- package/src/components/multichannel/multichannel-text.jsx +92 -28
- package/src/components/multichannel/multichannel-utils.js +2 -0
- package/src/components/{webchat-settings.jsx → webchat-settings.tsx} +8 -8
- package/src/components/whatsapp-button-list.tsx +1 -1
- package/src/contexts.tsx +64 -0
- package/src/index-types.ts +12 -12
- package/src/util/environment.js +1 -1
- package/src/webchat/actions.ts +25 -0
- package/src/webchat/hooks/index.ts +5 -0
- package/src/webchat/hooks/use-component-visible.ts +29 -0
- package/src/webchat/hooks/use-component-will-mount.ts +5 -0
- package/src/webchat/hooks/use-previous.ts +9 -0
- package/src/webchat/hooks/use-typing.ts +43 -0
- package/src/webchat/hooks/use-webchat.ts +213 -0
- package/src/webchat/index-types.ts +17 -8
- package/src/webchat/{messages-reducer.js → messages-reducer.ts} +25 -19
- package/src/webchat/trigger-button/index.tsx +0 -1
- package/src/webchat/{webchat-reducer.js → webchat-reducer.ts} +23 -37
- package/src/webchat/webchat.jsx +12 -11
- package/lib/cjs/webchat/hooks.d.ts +0 -81
- package/lib/cjs/webchat/hooks.js +0 -222
- package/lib/cjs/webchat/hooks.js.map +0 -1
- package/lib/esm/webchat/hooks.d.ts +0 -81
- package/lib/esm/webchat/hooks.js +0 -214
- package/lib/esm/webchat/hooks.js.map +0 -1
- package/src/contexts.jsx +0 -37
- package/src/webchat/actions.jsx +0 -23
- package/src/webchat/hooks.js +0 -270
package/src/webchat/hooks.js
DELETED
|
@@ -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
|
-
}
|