@botonic/react 0.22.0-alpha.1 → 0.22.0-beta.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.
- package/lib/cjs/botonic-tester.js +4 -6
- package/lib/cjs/botonic-tester.js.map +1 -1
- package/lib/cjs/components/audio.js +3 -7
- package/lib/cjs/components/audio.js.map +1 -1
- package/lib/cjs/components/button.js +7 -18
- package/lib/cjs/components/button.js.map +1 -1
- package/lib/cjs/components/carousel.d.ts +1 -1
- package/lib/cjs/components/carousel.js +6 -19
- package/lib/cjs/components/carousel.js.map +1 -1
- package/lib/cjs/components/custom-message.d.ts +3 -34
- package/lib/cjs/components/custom-message.js +4 -10
- package/lib/cjs/components/custom-message.js.map +1 -1
- package/lib/cjs/components/document.js +3 -6
- package/lib/cjs/components/document.js.map +1 -1
- package/lib/cjs/components/element.js +3 -2
- package/lib/cjs/components/element.js.map +1 -1
- package/lib/cjs/components/handoff.js +3 -7
- package/lib/cjs/components/handoff.js.map +1 -1
- package/lib/cjs/components/image.js +3 -7
- package/lib/cjs/components/image.js.map +1 -1
- package/lib/cjs/components/index-types.d.ts +174 -0
- package/lib/cjs/components/index-types.js +17 -0
- package/lib/cjs/components/index-types.js.map +1 -0
- package/lib/cjs/components/index.d.ts +22 -20
- package/lib/cjs/components/index.js +4 -1
- package/lib/cjs/components/index.js.map +1 -1
- package/lib/cjs/components/location.js +3 -9
- package/lib/cjs/components/location.js.map +1 -1
- package/lib/cjs/components/message-template.js +2 -3
- package/lib/cjs/components/message-template.js.map +1 -1
- package/lib/cjs/components/message.js +9 -27
- package/lib/cjs/components/message.js.map +1 -1
- package/lib/cjs/components/multichannel/index-types.d.ts +45 -0
- package/lib/cjs/components/multichannel/index-types.js +3 -0
- package/lib/cjs/components/multichannel/index-types.js.map +1 -0
- package/lib/cjs/components/multichannel/index.d.ts +11 -6
- package/lib/cjs/components/multichannel/index.js +2 -0
- package/lib/cjs/components/multichannel/index.js.map +1 -1
- package/lib/cjs/components/multichannel/multichannel-button.js +4 -5
- package/lib/cjs/components/multichannel/multichannel-button.js.map +1 -1
- package/lib/cjs/components/multichannel/multichannel-carousel.js +3 -20
- package/lib/cjs/components/multichannel/multichannel-carousel.js.map +1 -1
- package/lib/cjs/components/multichannel/multichannel-context.d.ts +1 -1
- package/lib/cjs/components/multichannel/multichannel-reply.js +2 -1
- package/lib/cjs/components/multichannel/multichannel-reply.js.map +1 -1
- package/lib/cjs/components/multichannel/multichannel-text.d.ts +1 -1
- package/lib/cjs/components/multichannel/multichannel-text.js +10 -25
- package/lib/cjs/components/multichannel/multichannel-text.js.map +1 -1
- package/lib/cjs/components/multichannel/multichannel.js +16 -28
- package/lib/cjs/components/multichannel/multichannel.js.map +1 -1
- package/lib/cjs/components/pic.js +3 -2
- package/lib/cjs/components/pic.js.map +1 -1
- package/lib/cjs/components/raw.js +3 -12
- package/lib/cjs/components/raw.js.map +1 -1
- package/lib/cjs/components/reply.js +5 -8
- package/lib/cjs/components/reply.js.map +1 -1
- package/lib/cjs/components/share-button.js +2 -3
- package/lib/cjs/components/share-button.js.map +1 -1
- package/lib/cjs/components/subtitle.js +3 -4
- package/lib/cjs/components/subtitle.js.map +1 -1
- package/lib/cjs/components/text.js +3 -6
- package/lib/cjs/components/text.js.map +1 -1
- package/lib/cjs/components/timestamps.js +2 -5
- package/lib/cjs/components/timestamps.js.map +1 -1
- package/lib/cjs/components/title.js +3 -2
- package/lib/cjs/components/title.js.map +1 -1
- package/lib/cjs/components/video.js +3 -6
- package/lib/cjs/components/video.js.map +1 -1
- package/lib/cjs/components/webchat-settings.js +2 -1
- package/lib/cjs/components/webchat-settings.js.map +1 -1
- package/lib/cjs/components/whatsapp-template.js +3 -4
- package/lib/cjs/components/whatsapp-template.js.map +1 -1
- package/lib/cjs/contexts.d.ts +2 -3
- package/lib/cjs/contexts.js +3 -4
- package/lib/cjs/contexts.js.map +1 -1
- package/lib/cjs/dev-app.d.ts +2 -2
- package/lib/cjs/dev-app.js +2 -1
- package/lib/cjs/dev-app.js.map +1 -1
- package/lib/cjs/index-types.d.ts +96 -0
- package/lib/cjs/index-types.js +12 -0
- package/lib/cjs/index-types.js.map +1 -0
- package/lib/cjs/index.d.ts +7 -10
- package/lib/cjs/index.js +6 -10
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/message-utils.d.ts +1 -1
- package/lib/cjs/msg-to-botonic.d.ts +1 -1
- package/lib/cjs/msg-to-botonic.js +24 -46
- package/lib/cjs/msg-to-botonic.js.map +1 -1
- package/lib/cjs/node-app.d.ts +1 -1
- package/lib/cjs/react-bot.d.ts +1 -1
- package/lib/cjs/react-bot.js +3 -4
- package/lib/cjs/react-bot.js.map +1 -1
- package/lib/cjs/util/error-boundary.d.ts +6 -39
- package/lib/cjs/util/error-boundary.js +17 -30
- package/lib/cjs/util/error-boundary.js.map +1 -1
- package/lib/cjs/util/webchat.js.map +1 -1
- package/lib/cjs/webchat/components/attachment.js +7 -10
- package/lib/cjs/webchat/components/attachment.js.map +1 -1
- package/lib/cjs/webchat/components/common.js +2 -1
- package/lib/cjs/webchat/components/common.js.map +1 -1
- package/lib/cjs/webchat/components/conditional-animation.js +2 -3
- package/lib/cjs/webchat/components/conditional-animation.js.map +1 -1
- package/lib/cjs/webchat/components/emoji-picker.js +3 -12
- package/lib/cjs/webchat/components/emoji-picker.js.map +1 -1
- package/lib/cjs/webchat/components/persistent-menu.js +5 -19
- package/lib/cjs/webchat/components/persistent-menu.js.map +1 -1
- package/lib/cjs/webchat/components/send-button.js +2 -7
- package/lib/cjs/webchat/components/send-button.js.map +1 -1
- package/lib/cjs/webchat/components/typing-indicator.js +2 -5
- package/lib/cjs/webchat/components/typing-indicator.js.map +1 -1
- package/lib/cjs/webchat/devices/device-adapter.d.ts +2 -2
- package/lib/cjs/webchat/header.js +4 -14
- package/lib/cjs/webchat/header.js.map +1 -1
- package/lib/cjs/webchat/hooks.js +2 -1
- package/lib/cjs/webchat/hooks.js.map +1 -1
- package/lib/cjs/webchat/index-types.d.ts +55 -0
- package/lib/cjs/webchat/index-types.js +3 -0
- package/lib/cjs/webchat/index-types.js.map +1 -0
- package/lib/cjs/webchat/index.d.ts +4 -6
- package/lib/cjs/webchat/index.js +3 -3
- package/lib/cjs/webchat/index.js.map +1 -1
- package/lib/cjs/webchat/message-list.js +5 -12
- package/lib/cjs/webchat/message-list.js.map +1 -1
- package/lib/cjs/webchat/replies.js +2 -5
- package/lib/cjs/webchat/replies.js.map +1 -1
- package/lib/cjs/webchat/session-view.js +7 -30
- package/lib/cjs/webchat/session-view.js.map +1 -1
- package/lib/cjs/webchat/use-storage-state-hook.js +12 -2
- package/lib/cjs/webchat/use-storage-state-hook.js.map +1 -1
- package/lib/cjs/webchat/webchat-dev.d.ts +1 -1
- package/lib/cjs/webchat/webchat-dev.js +6 -10
- package/lib/cjs/webchat/webchat-dev.js.map +1 -1
- package/lib/cjs/webchat/webchat.d.ts +1 -1
- package/lib/cjs/webchat/webchat.js +43 -86
- package/lib/cjs/webchat/webchat.js.map +1 -1
- package/lib/cjs/webchat/webview.js +5 -13
- package/lib/cjs/webchat/webview.js.map +1 -1
- package/lib/cjs/webchat-app.d.ts +2 -2
- package/lib/cjs/webchat-app.js +2 -1
- package/lib/cjs/webchat-app.js.map +1 -1
- package/lib/cjs/webview-app.js +12 -13
- package/lib/cjs/webview-app.js.map +1 -1
- package/lib/esm/botonic-tester.js +4 -6
- package/lib/esm/botonic-tester.js.map +1 -1
- package/lib/esm/components/audio.js +3 -7
- package/lib/esm/components/audio.js.map +1 -1
- package/lib/esm/components/button.js +7 -18
- package/lib/esm/components/button.js.map +1 -1
- package/lib/esm/components/carousel.d.ts +2 -1
- package/lib/esm/components/carousel.js +6 -19
- package/lib/esm/components/carousel.js.map +1 -1
- package/lib/esm/components/custom-message.d.ts +3 -34
- package/lib/esm/components/custom-message.js +4 -10
- package/lib/esm/components/custom-message.js.map +1 -1
- package/lib/esm/components/document.js +3 -6
- package/lib/esm/components/document.js.map +1 -1
- package/lib/esm/components/element.js +3 -2
- package/lib/esm/components/element.js.map +1 -1
- package/lib/esm/components/handoff.js +3 -7
- package/lib/esm/components/handoff.js.map +1 -1
- package/lib/esm/components/image.js +3 -7
- package/lib/esm/components/image.js.map +1 -1
- package/lib/esm/components/index-types.d.ts +174 -0
- package/lib/esm/components/index-types.js +16 -0
- package/lib/esm/components/index-types.js.map +1 -0
- package/lib/esm/components/index.d.ts +22 -19
- package/lib/esm/components/index.js +2 -0
- package/lib/esm/components/index.js.map +1 -1
- package/lib/esm/components/location.js +3 -9
- package/lib/esm/components/location.js.map +1 -1
- package/lib/esm/components/message-template.js +2 -3
- package/lib/esm/components/message-template.js.map +1 -1
- package/lib/esm/components/message.js +9 -27
- package/lib/esm/components/message.js.map +1 -1
- package/lib/esm/components/multichannel/index-types.d.ts +45 -0
- package/lib/esm/components/multichannel/index-types.js +2 -0
- package/lib/esm/components/multichannel/index-types.js.map +1 -0
- package/lib/esm/components/multichannel/index.d.ts +11 -6
- package/lib/esm/components/multichannel/index.js +1 -0
- package/lib/esm/components/multichannel/index.js.map +1 -1
- package/lib/esm/components/multichannel/multichannel-button.js +4 -5
- package/lib/esm/components/multichannel/multichannel-button.js.map +1 -1
- package/lib/esm/components/multichannel/multichannel-carousel.js +3 -20
- package/lib/esm/components/multichannel/multichannel-carousel.js.map +1 -1
- package/lib/esm/components/multichannel/multichannel-context.d.ts +1 -1
- package/lib/esm/components/multichannel/multichannel-reply.js +2 -1
- package/lib/esm/components/multichannel/multichannel-reply.js.map +1 -1
- package/lib/esm/components/multichannel/multichannel-text.d.ts +1 -1
- package/lib/esm/components/multichannel/multichannel-text.js +10 -25
- package/lib/esm/components/multichannel/multichannel-text.js.map +1 -1
- package/lib/esm/components/multichannel/multichannel.js +11 -23
- package/lib/esm/components/multichannel/multichannel.js.map +1 -1
- package/lib/esm/components/pic.js +3 -2
- package/lib/esm/components/pic.js.map +1 -1
- package/lib/esm/components/raw.js +3 -12
- package/lib/esm/components/raw.js.map +1 -1
- package/lib/esm/components/reply.js +5 -8
- package/lib/esm/components/reply.js.map +1 -1
- package/lib/esm/components/share-button.js +2 -3
- package/lib/esm/components/share-button.js.map +1 -1
- package/lib/esm/components/subtitle.js +3 -4
- package/lib/esm/components/subtitle.js.map +1 -1
- package/lib/esm/components/text.js +3 -6
- package/lib/esm/components/text.js.map +1 -1
- package/lib/esm/components/timestamps.js +2 -5
- package/lib/esm/components/timestamps.js.map +1 -1
- package/lib/esm/components/title.js +3 -2
- package/lib/esm/components/title.js.map +1 -1
- package/lib/esm/components/video.js +3 -6
- package/lib/esm/components/video.js.map +1 -1
- package/lib/esm/components/webchat-settings.js +2 -1
- package/lib/esm/components/webchat-settings.js.map +1 -1
- package/lib/esm/components/whatsapp-template.js +3 -4
- package/lib/esm/components/whatsapp-template.js.map +1 -1
- package/lib/esm/contexts.d.ts +2 -3
- package/lib/esm/contexts.js +3 -3
- package/lib/esm/contexts.js.map +1 -1
- package/lib/esm/dev-app.d.ts +2 -2
- package/lib/esm/dev-app.js +2 -1
- package/lib/esm/dev-app.js.map +1 -1
- package/lib/esm/index-types.d.ts +96 -0
- package/lib/esm/index-types.js +9 -0
- package/lib/esm/index-types.js.map +1 -0
- package/lib/esm/index.d.ts +7 -9
- package/lib/esm/index.js +5 -4
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/message-utils.d.ts +2 -1
- package/lib/esm/msg-to-botonic.d.ts +1 -1
- package/lib/esm/msg-to-botonic.js +23 -45
- package/lib/esm/msg-to-botonic.js.map +1 -1
- package/lib/esm/node-app.d.ts +4 -4
- package/lib/esm/react-bot.d.ts +2 -1
- package/lib/esm/react-bot.js +3 -4
- package/lib/esm/react-bot.js.map +1 -1
- package/lib/esm/util/error-boundary.d.ts +6 -39
- package/lib/esm/util/error-boundary.js +17 -30
- package/lib/esm/util/error-boundary.js.map +1 -1
- package/lib/esm/util/webchat.js.map +1 -1
- package/lib/esm/webchat/components/attachment.js +8 -11
- package/lib/esm/webchat/components/attachment.js.map +1 -1
- package/lib/esm/webchat/components/common.js +2 -1
- package/lib/esm/webchat/components/common.js.map +1 -1
- package/lib/esm/webchat/components/conditional-animation.js +2 -3
- package/lib/esm/webchat/components/conditional-animation.js.map +1 -1
- package/lib/esm/webchat/components/emoji-picker.js +3 -12
- package/lib/esm/webchat/components/emoji-picker.js.map +1 -1
- package/lib/esm/webchat/components/persistent-menu.js +5 -19
- package/lib/esm/webchat/components/persistent-menu.js.map +1 -1
- package/lib/esm/webchat/components/send-button.js +2 -7
- package/lib/esm/webchat/components/send-button.js.map +1 -1
- package/lib/esm/webchat/components/typing-indicator.js +2 -5
- package/lib/esm/webchat/components/typing-indicator.js.map +1 -1
- package/lib/esm/webchat/devices/device-adapter.d.ts +2 -2
- package/lib/esm/webchat/header.js +4 -14
- package/lib/esm/webchat/header.js.map +1 -1
- package/lib/esm/webchat/hooks.js +2 -1
- package/lib/esm/webchat/hooks.js.map +1 -1
- package/lib/esm/webchat/index-types.d.ts +55 -0
- package/lib/esm/webchat/index-types.js +2 -0
- package/lib/esm/webchat/index-types.js.map +1 -0
- package/lib/esm/webchat/index.d.ts +4 -6
- package/lib/esm/webchat/index.js +2 -3
- package/lib/esm/webchat/index.js.map +1 -1
- package/lib/esm/webchat/message-list.js +5 -12
- package/lib/esm/webchat/message-list.js.map +1 -1
- package/lib/esm/webchat/replies.js +2 -5
- package/lib/esm/webchat/replies.js.map +1 -1
- package/lib/esm/webchat/session-view.js +7 -30
- package/lib/esm/webchat/session-view.js.map +1 -1
- package/lib/esm/webchat/use-storage-state-hook.js +12 -2
- package/lib/esm/webchat/use-storage-state-hook.js.map +1 -1
- package/lib/esm/webchat/webchat-dev.d.ts +1 -1
- package/lib/esm/webchat/webchat-dev.js +6 -10
- package/lib/esm/webchat/webchat-dev.js.map +1 -1
- package/lib/esm/webchat/webchat.d.ts +1 -1
- package/lib/esm/webchat/webchat.js +43 -86
- package/lib/esm/webchat/webchat.js.map +1 -1
- package/lib/esm/webchat/webview.js +5 -13
- package/lib/esm/webchat/webview.js.map +1 -1
- package/lib/esm/webchat-app.d.ts +5 -4
- package/lib/esm/webchat-app.js +2 -1
- package/lib/esm/webchat-app.js.map +1 -1
- package/lib/esm/webview-app.js +5 -6
- package/lib/esm/webview-app.js.map +1 -1
- package/package.json +21 -15
- package/src/components/{index.d.ts → index-types.ts} +22 -43
- package/src/components/{index.js → index.ts} +2 -0
- package/src/components/message.jsx +4 -11
- package/src/components/multichannel/{index.d.ts → index-types.ts} +1 -10
- package/src/components/multichannel/{index.js → index.ts} +2 -0
- package/src/components/multichannel/multichannel-text.jsx +2 -5
- package/src/contexts.jsx +3 -3
- package/src/index-types.ts +190 -0
- package/src/{index.js → index.ts} +5 -4
- package/src/msg-to-botonic.jsx +11 -11
- package/src/util/error-boundary.jsx +15 -30
- package/src/util/webchat.js +12 -13
- package/src/webchat/components/attachment.jsx +10 -2
- package/src/webchat/components/emoji-picker.jsx +7 -1
- package/src/webchat/hooks.js +2 -1
- package/src/webchat/{index.d.ts → index-types.ts} +5 -10
- package/src/webchat/{index.js → index.ts} +3 -3
- package/src/webchat/use-storage-state-hook.js +13 -2
- package/src/webchat/webchat.jsx +5 -7
- package/src/webview-app.tsx +1 -1
- package/src/index.d.ts +0 -238
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import React, { useContext } from 'react'
|
|
1
|
+
import React, { useContext, useRef } from 'react'
|
|
2
2
|
|
|
3
3
|
import AttachmentIcon from '../../assets/attachment-icon.svg'
|
|
4
4
|
import { ROLES, WEBCHAT } from '../../constants'
|
|
@@ -9,6 +9,8 @@ import { Icon } from './common'
|
|
|
9
9
|
export const Attachment = ({ onChange, accept, enableAttachments }) => {
|
|
10
10
|
const { getThemeProperty } = useContext(WebchatContext)
|
|
11
11
|
|
|
12
|
+
const fileInputRef = useRef(null)
|
|
13
|
+
|
|
12
14
|
const CustomAttachments = getThemeProperty(
|
|
13
15
|
WEBCHAT.CUSTOM_PROPERTIES.customAttachments,
|
|
14
16
|
undefined
|
|
@@ -25,6 +27,11 @@ export const Attachment = ({ onChange, accept, enableAttachments }) => {
|
|
|
25
27
|
}
|
|
26
28
|
const attachmentsEnabled = isAttachmentsEnabled()
|
|
27
29
|
|
|
30
|
+
const handleOnChange = event => {
|
|
31
|
+
onChange(event)
|
|
32
|
+
fileInputRef.current.value = null
|
|
33
|
+
}
|
|
34
|
+
|
|
28
35
|
return (
|
|
29
36
|
<>
|
|
30
37
|
{attachmentsEnabled ? (
|
|
@@ -38,11 +45,12 @@ export const Attachment = ({ onChange, accept, enableAttachments }) => {
|
|
|
38
45
|
)}
|
|
39
46
|
</label>
|
|
40
47
|
<input
|
|
48
|
+
ref={fileInputRef}
|
|
41
49
|
type='file'
|
|
42
50
|
name='file'
|
|
43
51
|
id='attachment'
|
|
44
52
|
style={{ display: 'none' }}
|
|
45
|
-
onChange={
|
|
53
|
+
onChange={handleOnChange}
|
|
46
54
|
accept={accept}
|
|
47
55
|
/>
|
|
48
56
|
</div>
|
|
@@ -64,7 +64,13 @@ export const OpenedEmojiPicker = props => {
|
|
|
64
64
|
<div ref={ref}>
|
|
65
65
|
{isComponentVisible && (
|
|
66
66
|
<Container role={ROLES.EMOJI_PICKER}>
|
|
67
|
-
<Picker
|
|
67
|
+
<Picker
|
|
68
|
+
width='100%'
|
|
69
|
+
height='19rem'
|
|
70
|
+
previewConfig={{ showPreview: false }}
|
|
71
|
+
onEmojiClick={props.onEmojiClick}
|
|
72
|
+
disableAutoFocus={true}
|
|
73
|
+
/>
|
|
68
74
|
</Container>
|
|
69
75
|
)}
|
|
70
76
|
</div>
|
package/src/webchat/hooks.js
CHANGED
|
@@ -247,7 +247,8 @@ export function useComponentVisible(initialIsVisible, onClickOutside) {
|
|
|
247
247
|
const [isComponentVisible, setIsComponentVisible] = useState(initialIsVisible)
|
|
248
248
|
const ref = useRef(null)
|
|
249
249
|
const handleClickOutside = event => {
|
|
250
|
-
|
|
250
|
+
const target = event.path ? event.path[0] : event.target
|
|
251
|
+
if (ref.current && !ref.current.contains(target)) {
|
|
251
252
|
setIsComponentVisible(false)
|
|
252
253
|
onClickOutside()
|
|
253
254
|
}
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
import * as core from '@botonic/core'
|
|
2
|
-
import * as React from 'react'
|
|
3
2
|
import { RefObject } from 'react'
|
|
4
3
|
|
|
5
|
-
import {
|
|
6
|
-
import { Message, WebchatApp, WebchatArgs } from '../index'
|
|
4
|
+
import { Webview } from '../components/index-types'
|
|
7
5
|
|
|
8
6
|
export interface WebchatStateTheme {
|
|
9
7
|
headerTitle: string
|
|
@@ -20,8 +18,8 @@ export interface WebchatState {
|
|
|
20
18
|
width: number
|
|
21
19
|
height: number
|
|
22
20
|
messagesJSON: any[]
|
|
23
|
-
messagesComponents:
|
|
24
|
-
replies:
|
|
21
|
+
messagesComponents: any[]
|
|
22
|
+
replies: any[]
|
|
25
23
|
latestInput: Partial<core.Input>
|
|
26
24
|
typing: boolean
|
|
27
25
|
webview: Webview | null
|
|
@@ -41,11 +39,11 @@ export interface WebchatState {
|
|
|
41
39
|
currentAttachment: File | undefined
|
|
42
40
|
}
|
|
43
41
|
|
|
44
|
-
export interface WebchatProps extends WebchatArgs {
|
|
42
|
+
// export interface WebchatProps extends WebchatArgs {
|
|
43
|
+
export interface WebchatProps {
|
|
45
44
|
ref: RefObject<any>
|
|
46
45
|
onConnectionRegained?: () => Promise<void>
|
|
47
46
|
}
|
|
48
|
-
export const WebChat: React.ForwardRefExoticComponent<WebchatProps>
|
|
49
47
|
|
|
50
48
|
export interface WebchatDevProps extends WebchatProps {
|
|
51
49
|
initialDevSettings?: {
|
|
@@ -53,9 +51,6 @@ export interface WebchatDevProps extends WebchatProps {
|
|
|
53
51
|
showSessionView?: boolean
|
|
54
52
|
}
|
|
55
53
|
}
|
|
56
|
-
export const WebChatDev: React.ForwardRefExoticComponent<WebchatDevProps>
|
|
57
|
-
|
|
58
|
-
export function getBotonicApp(): WebchatApp
|
|
59
54
|
|
|
60
55
|
export interface CoverComponentProps {
|
|
61
56
|
closeComponent: () => void
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
1
2
|
export { Webchat } from './webchat'
|
|
2
3
|
export { WebchatDev } from './webchat-dev'
|
|
3
4
|
|
|
4
|
-
/**
|
|
5
|
-
* @returns {WebChatApp}
|
|
6
|
-
*/
|
|
7
5
|
export function getBotonicApp() {
|
|
8
6
|
// Botonic is exported from your bot
|
|
9
7
|
// eslint-disable-next-line no-undef
|
|
10
8
|
return Botonic
|
|
11
9
|
}
|
|
10
|
+
|
|
11
|
+
export * from './index-types'
|
|
@@ -1,9 +1,20 @@
|
|
|
1
1
|
import { useCallback, useEffect, useState } from 'react'
|
|
2
2
|
|
|
3
|
-
//Code taken from https://github.com/leny/react-use-storage
|
|
4
|
-
const
|
|
3
|
+
// Code taken from https://github.com/leny/react-use-storage/blob/master/src/index.js
|
|
4
|
+
const IS_BROWSER =
|
|
5
|
+
typeof window !== 'undefined' &&
|
|
6
|
+
typeof navigator !== 'undefined' &&
|
|
7
|
+
typeof document !== 'undefined'
|
|
5
8
|
|
|
6
9
|
export function useStorageState(storage, key, defaultValue) {
|
|
10
|
+
let evtTarget
|
|
11
|
+
|
|
12
|
+
try {
|
|
13
|
+
evtTarget = new EventTarget()
|
|
14
|
+
} catch {
|
|
15
|
+
evtTarget = (IS_BROWSER ? document : {})?.createElement?.('phony')
|
|
16
|
+
}
|
|
17
|
+
|
|
7
18
|
const raw = storage?.getItem(key)
|
|
8
19
|
|
|
9
20
|
const [value, setValue] = useState(raw ? JSON.parse(raw) : defaultValue)
|
package/src/webchat/webchat.jsx
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import { INPUT, isMobile, params2queryString } from '@botonic/core'
|
|
2
|
-
import { motion } from 'framer-motion'
|
|
3
2
|
import merge from 'lodash.merge'
|
|
4
3
|
import React, {
|
|
5
4
|
forwardRef,
|
|
@@ -161,7 +160,7 @@ const DarkBackgroundMenu = styled.div`
|
|
|
161
160
|
height: 100%;
|
|
162
161
|
`
|
|
163
162
|
|
|
164
|
-
// eslint-disable-next-line complexity
|
|
163
|
+
// eslint-disable-next-line complexity, react/display-name
|
|
165
164
|
export const Webchat = forwardRef((props, ref) => {
|
|
166
165
|
const {
|
|
167
166
|
webchatState,
|
|
@@ -372,8 +371,8 @@ export const Webchat = forwardRef((props, ref) => {
|
|
|
372
371
|
const openWebview = (webviewComponent, params) =>
|
|
373
372
|
updateWebview(webviewComponent, params)
|
|
374
373
|
|
|
375
|
-
const handleSelectedEmoji =
|
|
376
|
-
textArea.current.value +=
|
|
374
|
+
const handleSelectedEmoji = event => {
|
|
375
|
+
textArea.current.value += event.emoji
|
|
377
376
|
textArea.current.focus()
|
|
378
377
|
}
|
|
379
378
|
|
|
@@ -712,8 +711,6 @@ export const Webchat = forwardRef((props, ref) => {
|
|
|
712
711
|
}
|
|
713
712
|
}, [webchatState.isWebchatOpen])
|
|
714
713
|
|
|
715
|
-
const textArea = useRef()
|
|
716
|
-
|
|
717
714
|
const getTriggerImage = () => {
|
|
718
715
|
const triggerImage = getThemeProperty(
|
|
719
716
|
WEBCHAT.CUSTOM_PROPERTIES.triggerButtonImage,
|
|
@@ -768,6 +765,7 @@ export const Webchat = forwardRef((props, ref) => {
|
|
|
768
765
|
|
|
769
766
|
const userInputEnabled = isUserInputEnabled()
|
|
770
767
|
|
|
768
|
+
const textArea = useRef(null)
|
|
771
769
|
const userInputArea = () => {
|
|
772
770
|
return (
|
|
773
771
|
userInputEnabled && (
|
|
@@ -792,6 +790,7 @@ export const Webchat = forwardRef((props, ref) => {
|
|
|
792
790
|
|
|
793
791
|
<TextAreaContainer>
|
|
794
792
|
<Textarea
|
|
793
|
+
inputRef={textArea}
|
|
795
794
|
name='text'
|
|
796
795
|
onFocus={() => deviceAdapter.onFocus(host)}
|
|
797
796
|
onBlur={() => deviceAdapter.onBlur()}
|
|
@@ -803,7 +802,6 @@ export const Webchat = forwardRef((props, ref) => {
|
|
|
803
802
|
WEBCHAT.DEFAULTS.PLACEHOLDER
|
|
804
803
|
)}
|
|
805
804
|
autoFocus={true}
|
|
806
|
-
inputRef={textArea}
|
|
807
805
|
onKeyDown={e => onKeyDown(e)}
|
|
808
806
|
onKeyUp={onKeyUp}
|
|
809
807
|
style={{
|
package/src/webview-app.tsx
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @ts-nocheck
|
|
2
|
-
import type { PROVIDER } from '@botonic/core'
|
|
3
2
|
import { getString } from '@botonic/core/lib/esm/i18n'
|
|
3
|
+
import { PROVIDER } from '@botonic/core/lib/esm/models/legacy-types'
|
|
4
4
|
import { params2queryString } from '@botonic/core/lib/esm/utils'
|
|
5
5
|
import axios from 'axios'
|
|
6
6
|
import React from 'react'
|
package/src/index.d.ts
DELETED
|
@@ -1,238 +0,0 @@
|
|
|
1
|
-
import * as core from '@botonic/core'
|
|
2
|
-
import * as React from 'react'
|
|
3
|
-
|
|
4
|
-
import {
|
|
5
|
-
BlockInputOption,
|
|
6
|
-
ButtonProps,
|
|
7
|
-
CoverComponentOptions,
|
|
8
|
-
PersistentMenuTheme,
|
|
9
|
-
ReplyProps,
|
|
10
|
-
ThemeProps,
|
|
11
|
-
WebchatSettingsProps,
|
|
12
|
-
Webview,
|
|
13
|
-
} from './components'
|
|
14
|
-
import { WebchatState } from './webchat'
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* See @botonic/core's Response for the description of the Response's semantics*/
|
|
18
|
-
export interface BotResponse extends core.BotRequest {
|
|
19
|
-
response: [React.ReactNode]
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
export interface Route extends core.Route {
|
|
23
|
-
action?: React.ComponentType<any>
|
|
24
|
-
retryAction?: React.ComponentType<any>
|
|
25
|
-
}
|
|
26
|
-
type Routes = core.Routes<Route>
|
|
27
|
-
|
|
28
|
-
export class ReactBot extends core.CoreBot {
|
|
29
|
-
renderReactActions({
|
|
30
|
-
actions,
|
|
31
|
-
request: ActionRequest,
|
|
32
|
-
}): Promise<React.ReactNode>
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
export class NodeApp {
|
|
36
|
-
constructor(options: Omit<core.CoreBotConfig, 'renderer'>)
|
|
37
|
-
bot: ReactBot
|
|
38
|
-
input(request: core.BotRequest): Promise<BotResponse>
|
|
39
|
-
renderNode(args): string
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// Parameters of the actions' botonicInit method
|
|
43
|
-
export interface ActionRequest {
|
|
44
|
-
defaultDelay: number
|
|
45
|
-
defaultTyping: number
|
|
46
|
-
input: core.Input
|
|
47
|
-
lastRoutePath: string
|
|
48
|
-
params: { [key: string]: string }
|
|
49
|
-
plugins: { [id: string]: core.Plugin }
|
|
50
|
-
session: core.Session
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
export class BotonicInputTester {
|
|
54
|
-
constructor(app: NodeApp)
|
|
55
|
-
|
|
56
|
-
text(
|
|
57
|
-
inp: string,
|
|
58
|
-
session?: core.Session,
|
|
59
|
-
lastRoutePath?: string
|
|
60
|
-
): Promise<string>
|
|
61
|
-
|
|
62
|
-
payload(
|
|
63
|
-
inp: string,
|
|
64
|
-
session?: core.Session,
|
|
65
|
-
lastRoutePath?: string
|
|
66
|
-
): Promise<string>
|
|
67
|
-
}
|
|
68
|
-
|
|
69
|
-
export class BotonicOutputTester {
|
|
70
|
-
constructor(app: NodeApp)
|
|
71
|
-
|
|
72
|
-
text(out: string, replies?: any): Promise<string>
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
export interface RequestContextInterface extends ActionRequest {
|
|
76
|
-
getString: (stringId: string) => string
|
|
77
|
-
setLocale: (locale: string) => string
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export const RequestContext: React.Context<RequestContextInterface>
|
|
81
|
-
export type RequestContext = React.Context<RequestContextInterface>
|
|
82
|
-
|
|
83
|
-
export interface CustomMessageType {
|
|
84
|
-
customTypeName: string
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
export function msgToBotonic(
|
|
88
|
-
msg: any,
|
|
89
|
-
customMessageTypes?: CustomMessageType[]
|
|
90
|
-
): React.ReactNode
|
|
91
|
-
|
|
92
|
-
export function msgsToBotonic(
|
|
93
|
-
msgs: any | any[],
|
|
94
|
-
customMessageTypes?: CustomMessageType[]
|
|
95
|
-
): React.ReactNode
|
|
96
|
-
|
|
97
|
-
export interface WebchatArgs {
|
|
98
|
-
blockInputs?: BlockInputOption[]
|
|
99
|
-
coverComponent?: CoverComponentOptions
|
|
100
|
-
defaultDelay?: number
|
|
101
|
-
defaultTyping?: number
|
|
102
|
-
enableAnimations?: boolean
|
|
103
|
-
enableAttachments?: boolean
|
|
104
|
-
enableEmojiPicker?: boolean
|
|
105
|
-
enableUserInput?: boolean
|
|
106
|
-
shadowDOM?: boolean | (() => boolean)
|
|
107
|
-
hostId?: string
|
|
108
|
-
getString?: (stringId: string, session: core.Session) => string
|
|
109
|
-
onClose?: (app: WebchatApp, args: any) => void
|
|
110
|
-
onInit?: (app: WebchatApp, args: any) => void
|
|
111
|
-
onMessage?: (app: WebchatApp, message: WebchatMessage) => void
|
|
112
|
-
onOpen?: (app: WebchatApp, args: any) => void
|
|
113
|
-
onConnectionChange?: (app: WebchatApp, isOnline: boolean) => void
|
|
114
|
-
persistentMenu?: PersistentMenuTheme
|
|
115
|
-
storage?: Storage | null
|
|
116
|
-
storageKey?: any
|
|
117
|
-
theme?: ThemeProps
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
export interface WebchatAppArgs extends WebchatArgs {
|
|
121
|
-
appId?: string
|
|
122
|
-
visibility?: () => boolean
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
export interface WebchatMessage {
|
|
126
|
-
ack: 0 | 1
|
|
127
|
-
buttons: ButtonProps[]
|
|
128
|
-
data: any
|
|
129
|
-
delay: number
|
|
130
|
-
display: boolean
|
|
131
|
-
from: 'user' | 'bot'
|
|
132
|
-
id: string
|
|
133
|
-
markdown: boolean
|
|
134
|
-
replies: ReplyProps[]
|
|
135
|
-
timestamp: string
|
|
136
|
-
type: core.InputType
|
|
137
|
-
typing: number
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
export interface OnUserInputArgs {
|
|
141
|
-
input: core.Input
|
|
142
|
-
lastRoutePath?: string
|
|
143
|
-
session?: core.Session
|
|
144
|
-
user: core.SessionUser
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
export interface OnStateChangeArgs {
|
|
148
|
-
messagesJSON: WebchatMessage[]
|
|
149
|
-
user: core.SessionUser
|
|
150
|
-
}
|
|
151
|
-
|
|
152
|
-
export interface MessageInfo {
|
|
153
|
-
data: any | 'typing_on'
|
|
154
|
-
id: string
|
|
155
|
-
type: 'update_webchat_settings' | 'sender_action'
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
export interface Event {
|
|
159
|
-
action?: 'update_message_info'
|
|
160
|
-
isError?: boolean
|
|
161
|
-
message?: MessageInfo
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
export class WebchatApp {
|
|
165
|
-
constructor(options: WebchatAppArgs)
|
|
166
|
-
addBotMessage(message: WebchatMessage): void
|
|
167
|
-
addBotText(text: string): void
|
|
168
|
-
addUserMessage(message: WebchatMessage): void
|
|
169
|
-
addUserPayload(payload: string): void
|
|
170
|
-
addUserText(text: string): void
|
|
171
|
-
clearMessages(): void
|
|
172
|
-
close(): void
|
|
173
|
-
closeCoverComponent(): void
|
|
174
|
-
destroy(): void
|
|
175
|
-
getComponent(
|
|
176
|
-
host: HTMLElement,
|
|
177
|
-
optionsAtRuntime?: WebchatAppArgs
|
|
178
|
-
): React.ForwardRefExoticComponent<any>
|
|
179
|
-
getLastMessageUpdate(): string
|
|
180
|
-
getMessages(): WebchatMessage[]
|
|
181
|
-
getVisibility(): Promise<boolean>
|
|
182
|
-
isWebchatVisible({ appId: string }): Promise<boolean>
|
|
183
|
-
onCloseWebchat(args: any): void
|
|
184
|
-
onInitWebchat(args: any): void
|
|
185
|
-
onOpenWebchat(args: any): void
|
|
186
|
-
onServiceEvent(event: Event): void
|
|
187
|
-
onStateChange(args: OnStateChangeArgs): void
|
|
188
|
-
onUserInput(args: OnUserInputArgs): Promise<void>
|
|
189
|
-
open(): void
|
|
190
|
-
openCoverComponent(): void
|
|
191
|
-
render(dest?: HTMLElement, optionsAtRuntime?: WebchatAppArgs): void
|
|
192
|
-
resendUnsentInputs(): Promise<void>
|
|
193
|
-
resolveWebchatVisibility(optionsAtRuntime: {
|
|
194
|
-
appId: string
|
|
195
|
-
visibility: () => boolean
|
|
196
|
-
}): Promise<boolean>
|
|
197
|
-
setTyping(enable: boolean): void
|
|
198
|
-
toggle(): void
|
|
199
|
-
toggleCoverComponent(): void
|
|
200
|
-
updateMessageInfo(msgId: string, messageInfo: MessageInfo): void
|
|
201
|
-
updateLastMessageDate(date: string): void
|
|
202
|
-
updateUser(user: Partial<core.SessionUser>): void
|
|
203
|
-
updateWebchatSettings(settings: WebchatSettingsProps): void
|
|
204
|
-
renderCustomComponent(customComponent: React.ReactNode): void
|
|
205
|
-
unmountCustomComponent(): void
|
|
206
|
-
}
|
|
207
|
-
|
|
208
|
-
export interface WebchatContextProps {
|
|
209
|
-
sendText: (text: string, payload?: string) => void
|
|
210
|
-
sendAttachment: (attachment: File) => void
|
|
211
|
-
sendPayload: (payload: string) => void
|
|
212
|
-
sendInput: (input: core.Input) => void
|
|
213
|
-
openWebview: (webviewComponent: Webview) => void
|
|
214
|
-
addMessage: (message: WebchatMessage) => void
|
|
215
|
-
updateMessage: (message: WebchatMessage) => void
|
|
216
|
-
updateReplies: (replies: boolean) => void
|
|
217
|
-
updateLatestInput: (input: core.Input) => void
|
|
218
|
-
closeWebview: () => void
|
|
219
|
-
toggleWebchat: () => void
|
|
220
|
-
getThemeProperty: (property: string, defaultValue?: string) => any
|
|
221
|
-
resolveCase: () => void
|
|
222
|
-
theme: ThemeProps
|
|
223
|
-
webchatState: WebchatState
|
|
224
|
-
updateWebchatDevSettings: (settings: WebchatSettingsProps) => void
|
|
225
|
-
updateUser: (user: Partial<core.SessionUser>) => void
|
|
226
|
-
}
|
|
227
|
-
export const WebchatContext: React.Context<WebchatContextProps>
|
|
228
|
-
export type WebchatContext = React.Context<WebchatContextProps>
|
|
229
|
-
|
|
230
|
-
export class DevApp extends WebchatApp {
|
|
231
|
-
constructor(args: WebchatAppArgs)
|
|
232
|
-
onUserInput(args: OnUserInputArgs): Promise<void>
|
|
233
|
-
render(dest: HTMLElement, optionsAtRuntime: WebchatAppArgs): void
|
|
234
|
-
}
|
|
235
|
-
|
|
236
|
-
export * from './components'
|
|
237
|
-
export * from './util'
|
|
238
|
-
export * from './webchat'
|