@botonic/react 0.20.1-alpha.1 → 0.20.3
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/app.js +4 -3
- package/lib/app.js.map +1 -1
- package/lib/components/button.js +22 -2
- package/lib/components/button.js.map +1 -1
- package/lib/components/buttons-disabler.js +2 -2
- package/lib/components/carousel.js +2 -2
- package/lib/components/custom-message.js +2 -2
- package/lib/components/document.js +2 -2
- package/lib/components/image.js +28 -32
- package/lib/components/image.js.map +1 -1
- package/lib/components/message.js +2 -2
- package/lib/components/multichannel/facebook/facebook.js +2 -2
- package/lib/components/reply.js +2 -2
- package/lib/components/subtitle.js +2 -2
- package/lib/components/text.js +2 -2
- package/lib/components/timestamps.js +2 -2
- package/lib/components/title.js +2 -2
- package/lib/constants.js +201 -0
- package/lib/constants.js.map +1 -0
- package/lib/contexts.js +57 -0
- package/lib/contexts.js.map +1 -0
- package/lib/dev-app.js +241 -0
- package/lib/dev-app.js.map +1 -0
- package/lib/index.d.ts +241 -0
- package/lib/index.js +131 -0
- package/lib/index.js.map +1 -0
- package/lib/message-utils.js +149 -0
- package/lib/message-utils.js.map +1 -0
- package/lib/msg-to-botonic.js +199 -0
- package/lib/msg-to-botonic.js.map +1 -0
- package/lib/node-app.js +97 -0
- package/lib/node-app.js.map +1 -0
- package/lib/react-bot.js +167 -0
- package/lib/react-bot.js.map +1 -0
- package/lib/util/dom.js +84 -0
- package/lib/util/dom.js.map +1 -0
- package/lib/util/environment.js +42 -0
- package/lib/util/environment.js.map +1 -0
- package/lib/util/error-boundary.js +105 -0
- package/lib/util/error-boundary.js.map +1 -0
- package/lib/util/index.d.ts +9 -0
- package/lib/util/index.js +2 -0
- package/lib/util/index.js.map +1 -0
- package/lib/util/logs.js +28 -0
- package/lib/util/logs.js.map +1 -0
- package/lib/util/objects.js +60 -0
- package/lib/util/objects.js.map +1 -0
- package/lib/util/react.js +75 -0
- package/lib/util/react.js.map +1 -0
- package/lib/util/regexs.js +31 -0
- package/lib/util/regexs.js.map +1 -0
- package/lib/util/webchat.js +92 -0
- package/lib/util/webchat.js.map +1 -0
- package/lib/webchat/actions.js +53 -0
- package/lib/webchat/actions.js.map +1 -0
- package/lib/webchat/components/attachment.js +43 -0
- package/lib/webchat/components/attachment.js.map +1 -0
- package/lib/webchat/components/common.js +33 -0
- package/lib/webchat/components/common.js.map +1 -0
- package/lib/webchat/components/emoji-picker.js +58 -0
- package/lib/webchat/components/emoji-picker.js.map +1 -0
- package/lib/webchat/components/persistent-menu.js +96 -0
- package/lib/webchat/components/persistent-menu.js.map +1 -0
- package/lib/webchat/components/send-button.js +27 -0
- package/lib/webchat/components/send-button.js.map +1 -0
- package/lib/webchat/components/styled-scrollbar.js +55 -0
- package/lib/webchat/components/styled-scrollbar.js.map +1 -0
- package/lib/webchat/components/styled-scrollbar.scss +12 -0
- package/lib/webchat/components/typing-indicator.js +27 -0
- package/lib/webchat/components/typing-indicator.js.map +1 -0
- package/lib/webchat/components/typing-indicator.scss +38 -0
- package/lib/webchat/devices/device-adapter.js +82 -0
- package/lib/webchat/devices/device-adapter.js.map +1 -0
- package/lib/webchat/devices/index.js +32 -0
- package/lib/webchat/devices/index.js.map +1 -0
- package/lib/webchat/devices/scrollbar-controller.js +152 -0
- package/lib/webchat/devices/scrollbar-controller.js.map +1 -0
- package/lib/webchat/devices/webchat-resizer.js +76 -0
- package/lib/webchat/devices/webchat-resizer.js.map +1 -0
- package/lib/webchat/header.js +116 -0
- package/lib/webchat/header.js.map +1 -0
- package/lib/webchat/hooks.js +359 -0
- package/lib/webchat/hooks.js.map +1 -0
- package/lib/webchat/index.d.ts +62 -0
- package/lib/webchat/index.js +32 -0
- package/lib/webchat/index.js.map +1 -0
- package/lib/webchat/message-list.js +88 -0
- package/lib/webchat/message-list.js.map +1 -0
- package/lib/webchat/messages-reducer.js +93 -0
- package/lib/webchat/messages-reducer.js.map +1 -0
- package/lib/webchat/replies.js +78 -0
- package/lib/webchat/replies.js.map +1 -0
- package/lib/webchat/session-view.js +106 -0
- package/lib/webchat/session-view.js.map +1 -0
- package/lib/webchat/use-storage-state-hook.js +29 -0
- package/lib/webchat/use-storage-state-hook.js.map +1 -0
- package/lib/webchat/webchat-dev.js +109 -0
- package/lib/webchat/webchat-dev.js.map +1 -0
- package/lib/webchat/webchat-reducer.js +108 -0
- package/lib/webchat/webchat-reducer.js.map +1 -0
- package/lib/webchat/webchat.js +1059 -0
- package/lib/webchat/webchat.js.map +1 -0
- package/lib/webchat/webview.js +122 -0
- package/lib/webchat/webview.js.map +1 -0
- package/lib/webchat-app.js +653 -0
- package/lib/webchat-app.js.map +1 -0
- package/lib/webchat.template.html +37 -0
- package/lib/webview.js +214 -0
- package/lib/webview.js.map +1 -0
- package/lib/webview.template.html +39 -0
- package/package.json +2 -2
- package/src/components/button.jsx +21 -1
- package/src/components/image.jsx +22 -27
- package/src/components/index.d.ts +5 -1
- package/src/constants.js +1 -0
- package/src/index.d.ts +3 -7
- package/src/index.js +0 -1
- package/src/webchat/actions.jsx +1 -1
- package/src/webchat/hooks.js +5 -5
- package/src/webchat/webchat-reducer.js +3 -3
- package/src/webchat/webchat.jsx +20 -17
- package/src/webchat-app.jsx +4 -4
- package/src/webchat/components/portal-modal/backdrop.jsx +0 -38
- package/src/webchat/components/portal-modal/constants.js +0 -7
- package/src/webchat/components/portal-modal/content.jsx +0 -10
- package/src/webchat/components/portal-modal/index.js +0 -5
- package/src/webchat/components/portal-modal/portal-modal-component.jsx +0 -72
- package/src/webchat/components/portal-modal/portal.jsx +0 -21
package/src/webchat/webchat.jsx
CHANGED
|
@@ -47,7 +47,6 @@ import {
|
|
|
47
47
|
initSession,
|
|
48
48
|
shouldKeepSessionOnReload,
|
|
49
49
|
} from '../util/webchat'
|
|
50
|
-
import { PortalModalComponent } from '../webchat/components/portal-modal'
|
|
51
50
|
import { Attachment } from './components/attachment'
|
|
52
51
|
import { EmojiPicker, OpenedEmojiPicker } from './components/emoji-picker'
|
|
53
52
|
import {
|
|
@@ -185,7 +184,7 @@ export const Webchat = forwardRef((props, ref) => {
|
|
|
185
184
|
toggleEmojiPicker,
|
|
186
185
|
togglePersistentMenu,
|
|
187
186
|
toggleCoverComponent,
|
|
188
|
-
|
|
187
|
+
doRenderCustomComponent,
|
|
189
188
|
setError,
|
|
190
189
|
setOnline,
|
|
191
190
|
clearMessages,
|
|
@@ -202,8 +201,7 @@ export const Webchat = forwardRef((props, ref) => {
|
|
|
202
201
|
const { initialSession, initialDevSettings, onStateChange } = props
|
|
203
202
|
const getThemeProperty = _getThemeProperty(theme)
|
|
204
203
|
|
|
205
|
-
const [
|
|
206
|
-
|
|
204
|
+
const [customComponent, setCustomComponent] = useState(null)
|
|
207
205
|
const storage = props.storage === undefined ? localStorage : props.storage
|
|
208
206
|
const storageKey =
|
|
209
207
|
typeof props.storageKey === 'function'
|
|
@@ -407,9 +405,13 @@ export const Webchat = forwardRef((props, ref) => {
|
|
|
407
405
|
)
|
|
408
406
|
|
|
409
407
|
const getBlockInputs = (rule, inputData) => {
|
|
408
|
+
const processedInput = rule.preprocess
|
|
409
|
+
? rule.preprocess(inputData)
|
|
410
|
+
: inputData
|
|
411
|
+
|
|
410
412
|
return rule.match.some(regex => {
|
|
411
413
|
if (typeof regex === 'string') regex = deserializeRegex(regex)
|
|
412
|
-
return regex.test(
|
|
414
|
+
return regex.test(processedInput)
|
|
413
415
|
})
|
|
414
416
|
}
|
|
415
417
|
|
|
@@ -564,11 +566,11 @@ export const Webchat = forwardRef((props, ref) => {
|
|
|
564
566
|
toggleWebchat: () => toggleWebchat(!webchatState.isWebchatOpen),
|
|
565
567
|
openCoverComponent: () => toggleCoverComponent(true),
|
|
566
568
|
closeCoverComponent: () => toggleCoverComponent(false),
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
569
|
+
renderCustomComponent: _customComponent => {
|
|
570
|
+
setCustomComponent(_customComponent)
|
|
571
|
+
doRenderCustomComponent(true)
|
|
570
572
|
},
|
|
571
|
-
|
|
573
|
+
unmountCustomComponent: () => doRenderCustomComponent(false),
|
|
572
574
|
toggleCoverComponent: () =>
|
|
573
575
|
toggleCoverComponent(!webchatState.isCoverComponentOpen),
|
|
574
576
|
openWebviewApi: component => openWebviewT(component),
|
|
@@ -896,6 +898,11 @@ export const Webchat = forwardRef((props, ref) => {
|
|
|
896
898
|
)
|
|
897
899
|
}
|
|
898
900
|
|
|
901
|
+
const _renderCustomComponent = () => {
|
|
902
|
+
if (!customComponent) return <></>
|
|
903
|
+
else return customComponent
|
|
904
|
+
}
|
|
905
|
+
|
|
899
906
|
const WebchatComponent = (
|
|
900
907
|
<WebchatContext.Provider
|
|
901
908
|
value={{
|
|
@@ -926,6 +933,7 @@ export const Webchat = forwardRef((props, ref) => {
|
|
|
926
933
|
{triggerButton()}
|
|
927
934
|
</div>
|
|
928
935
|
)}
|
|
936
|
+
|
|
929
937
|
{webchatState.isWebchatOpen && (
|
|
930
938
|
<StyledWebchat
|
|
931
939
|
// TODO: Distinguis between multiple instances of webchat, e.g. `${uniqueId}-botonic-webchat`
|
|
@@ -958,14 +966,9 @@ export const Webchat = forwardRef((props, ref) => {
|
|
|
958
966
|
{!webchatState.handoff && userInputArea()}
|
|
959
967
|
{webchatState.webview && webchatWebview()}
|
|
960
968
|
{webchatState.isCoverComponentOpen && coverComponent()}
|
|
961
|
-
{webchatState.
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
onClose={() => toggleModal(false)}
|
|
965
|
-
locked={false}
|
|
966
|
-
customContent={customModalContent}
|
|
967
|
-
/>
|
|
968
|
-
)}
|
|
969
|
+
{webchatState.isCustomComponentRendered &&
|
|
970
|
+
customComponent &&
|
|
971
|
+
_renderCustomComponent()}
|
|
969
972
|
</StyledWebchat>
|
|
970
973
|
)}
|
|
971
974
|
</WebchatContext.Provider>
|
package/src/webchat-app.jsx
CHANGED
|
@@ -211,12 +211,12 @@ export class WebchatApp {
|
|
|
211
211
|
this.webchatRef.current.closeCoverComponent()
|
|
212
212
|
}
|
|
213
213
|
|
|
214
|
-
|
|
215
|
-
this.webchatRef.current.
|
|
214
|
+
renderCustomComponent(_customComponent) {
|
|
215
|
+
this.webchatRef.current.renderCustomComponent(_customComponent)
|
|
216
216
|
}
|
|
217
217
|
|
|
218
|
-
|
|
219
|
-
this.webchatRef.current.
|
|
218
|
+
unmountCustomComponent() {
|
|
219
|
+
this.webchatRef.current.unmountCustomComponent()
|
|
220
220
|
}
|
|
221
221
|
|
|
222
222
|
toggleCoverComponent() {
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import styled from 'styled-components'
|
|
2
|
-
|
|
3
|
-
import { MODAL_ACTIVE_CLASSNAME, MODAL_CONTENT_CLASSNAME } from './constants'
|
|
4
|
-
|
|
5
|
-
export const Backdrop = styled.div`
|
|
6
|
-
position: fixed;
|
|
7
|
-
top: 0;
|
|
8
|
-
right: 0;
|
|
9
|
-
bottom: 0;
|
|
10
|
-
left: 0;
|
|
11
|
-
background-color: rgba(51, 51, 51, 0.3);
|
|
12
|
-
backdrop-filter: blur(1px);
|
|
13
|
-
opacity: 0;
|
|
14
|
-
transition: all 100ms cubic-bezier(0.4, 0, 0.2, 1);
|
|
15
|
-
transition-delay: 200ms;
|
|
16
|
-
display: flex;
|
|
17
|
-
align-items: center;
|
|
18
|
-
justify-content: center;
|
|
19
|
-
|
|
20
|
-
& .${MODAL_CONTENT_CLASSNAME} {
|
|
21
|
-
transform: translateY(100px);
|
|
22
|
-
transition: all 200ms cubic-bezier(0.4, 0, 0.2, 1);
|
|
23
|
-
opacity: 0;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
&.${MODAL_ACTIVE_CLASSNAME} {
|
|
27
|
-
transition-duration: 250ms;
|
|
28
|
-
transition-delay: 0ms;
|
|
29
|
-
opacity: 1;
|
|
30
|
-
|
|
31
|
-
& .${MODAL_CONTENT_CLASSNAME} {
|
|
32
|
-
transform: translateY(0);
|
|
33
|
-
opacity: 1;
|
|
34
|
-
transition-delay: 150ms;
|
|
35
|
-
transition-duration: 350ms;
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
`
|
|
@@ -1,10 +0,0 @@
|
|
|
1
|
-
import styled from 'styled-components'
|
|
2
|
-
|
|
3
|
-
export const ModalContent = styled.div`
|
|
4
|
-
position: relative;
|
|
5
|
-
padding: 4px;
|
|
6
|
-
box-sizing: border-box;
|
|
7
|
-
box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
|
|
8
|
-
background-color: white;
|
|
9
|
-
border-radius: 2px;
|
|
10
|
-
`
|
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import React, { useEffect, useRef, useState } from 'react'
|
|
2
|
-
|
|
3
|
-
import { Backdrop } from './backdrop'
|
|
4
|
-
import {
|
|
5
|
-
MODAL_ACTIVE_CLASSNAME,
|
|
6
|
-
MODAL_CONTENT_CLASSNAME,
|
|
7
|
-
MODAL_PORTAL_CLASS_NAME,
|
|
8
|
-
} from './constants'
|
|
9
|
-
import { ModalContent } from './content'
|
|
10
|
-
import { Portal } from './portal'
|
|
11
|
-
|
|
12
|
-
const ESCAPE_KEY_CODE = 27
|
|
13
|
-
|
|
14
|
-
export function PortalModalComponent({
|
|
15
|
-
open,
|
|
16
|
-
onClose,
|
|
17
|
-
locked,
|
|
18
|
-
children,
|
|
19
|
-
customContent,
|
|
20
|
-
}) {
|
|
21
|
-
const [active, setActive] = useState(false)
|
|
22
|
-
|
|
23
|
-
const backdrop = useRef(null)
|
|
24
|
-
|
|
25
|
-
useEffect(() => {
|
|
26
|
-
const { current } = backdrop
|
|
27
|
-
const transitionEnd = () => setActive(open)
|
|
28
|
-
const keyHandler = e =>
|
|
29
|
-
!locked && [ESCAPE_KEY_CODE].indexOf(e.which) >= 0 && onClose()
|
|
30
|
-
const clickHandler = e => !locked && e.target === current && onClose()
|
|
31
|
-
|
|
32
|
-
if (current) {
|
|
33
|
-
current.addEventListener('transitionend', transitionEnd)
|
|
34
|
-
current.addEventListener('click', clickHandler)
|
|
35
|
-
window.addEventListener('keyup', keyHandler)
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
if (open) {
|
|
39
|
-
window.setTimeout(() => {
|
|
40
|
-
document.activeElement.blur()
|
|
41
|
-
setActive(open)
|
|
42
|
-
}, 10)
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
return () => {
|
|
46
|
-
if (current) {
|
|
47
|
-
current.removeEventListener('transitionend', transitionEnd)
|
|
48
|
-
current.removeEventListener('click', clickHandler)
|
|
49
|
-
}
|
|
50
|
-
window.removeEventListener('keyup', keyHandler)
|
|
51
|
-
}
|
|
52
|
-
}, [open, locked, onClose])
|
|
53
|
-
|
|
54
|
-
return (
|
|
55
|
-
(open || active) && (
|
|
56
|
-
<Portal className={MODAL_PORTAL_CLASS_NAME}>
|
|
57
|
-
<Backdrop
|
|
58
|
-
ref={backdrop}
|
|
59
|
-
className={active && open && MODAL_ACTIVE_CLASSNAME}
|
|
60
|
-
>
|
|
61
|
-
{customContent ? (
|
|
62
|
-
customContent
|
|
63
|
-
) : (
|
|
64
|
-
<ModalContent className={MODAL_CONTENT_CLASSNAME}>
|
|
65
|
-
{children}
|
|
66
|
-
</ModalContent>
|
|
67
|
-
)}
|
|
68
|
-
</Backdrop>
|
|
69
|
-
</Portal>
|
|
70
|
-
)
|
|
71
|
-
)
|
|
72
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { useEffect, useMemo } from 'react'
|
|
2
|
-
import { createPortal } from 'react-dom'
|
|
3
|
-
|
|
4
|
-
import { BOTONIC_PORTAL_CLASS_LIST_NAME } from './constants'
|
|
5
|
-
|
|
6
|
-
export function Portal({ children, parent, className }) {
|
|
7
|
-
const element = useMemo(() => document.createElement('div'), [])
|
|
8
|
-
|
|
9
|
-
useEffect(() => {
|
|
10
|
-
const target = parent && parent.appendChild ? parent : document.body
|
|
11
|
-
const classList = [BOTONIC_PORTAL_CLASS_LIST_NAME]
|
|
12
|
-
|
|
13
|
-
if (className) className.split(' ').forEach(item => classList.push(item))
|
|
14
|
-
classList.forEach(item => element.classList.add(item))
|
|
15
|
-
target.appendChild(element)
|
|
16
|
-
|
|
17
|
-
return () => target.removeChild(element)
|
|
18
|
-
}, [element, parent, className])
|
|
19
|
-
|
|
20
|
-
return createPortal(children, element)
|
|
21
|
-
}
|