@botonic/react 0.25.0-beta.0 → 0.26.0-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.
- package/lib/cjs/components/message/styles.d.ts +30 -8
- package/lib/cjs/components/message/styles.js.map +1 -1
- package/lib/cjs/contexts.d.ts +16 -9
- package/lib/cjs/contexts.js +8 -2
- package/lib/cjs/contexts.js.map +1 -1
- package/lib/cjs/index.d.ts +1 -1
- package/lib/cjs/index.js +2 -1
- package/lib/cjs/index.js.map +1 -1
- package/lib/cjs/webchat/components/styled-scrollbar.d.ts +2 -1
- package/lib/cjs/webchat/header.d.ts +1 -1
- package/lib/cjs/webchat/message-list/index.js +3 -1
- package/lib/cjs/webchat/message-list/index.js.map +1 -1
- package/lib/cjs/webchat/message-list/styles.d.ts +4 -4
- package/lib/cjs/webchat/trigger-button/styles.d.ts +3 -3
- package/lib/cjs/webchat/webchat-dev.d.ts +1 -1
- package/lib/cjs/webchat/webchat.js +5 -9
- package/lib/cjs/webchat/webchat.js.map +1 -1
- package/lib/cjs/webchat/webview.js +3 -3
- package/lib/cjs/webchat/webview.js.map +1 -1
- package/lib/cjs/webchat-app.d.ts +1 -0
- package/lib/cjs/webchat-app.js +3 -0
- package/lib/cjs/webchat-app.js.map +1 -1
- package/lib/cjs/webview-app.js +3 -3
- package/lib/cjs/webview-app.js.map +1 -1
- package/lib/esm/components/message/styles.d.ts +30 -8
- package/lib/esm/components/message/styles.js.map +1 -1
- package/lib/esm/contexts.d.ts +16 -9
- package/lib/esm/contexts.js +7 -1
- package/lib/esm/contexts.js.map +1 -1
- package/lib/esm/index.d.ts +1 -1
- package/lib/esm/index.js +1 -1
- package/lib/esm/index.js.map +1 -1
- package/lib/esm/webchat/components/styled-scrollbar.d.ts +2 -1
- package/lib/esm/webchat/header.d.ts +1 -1
- package/lib/esm/webchat/message-list/index.js +3 -1
- package/lib/esm/webchat/message-list/index.js.map +1 -1
- package/lib/esm/webchat/message-list/styles.d.ts +4 -4
- package/lib/esm/webchat/trigger-button/styles.d.ts +3 -3
- package/lib/esm/webchat/webchat-dev.d.ts +1 -1
- package/lib/esm/webchat/webchat.js +6 -10
- 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/webchat-app.d.ts +1 -0
- package/lib/esm/webchat-app.js +3 -0
- package/lib/esm/webchat-app.js.map +1 -1
- package/lib/esm/webview-app.js +4 -4
- package/lib/esm/webview-app.js.map +1 -1
- package/package.json +2 -2
- package/src/components/message/styles.ts +30 -6
- package/src/contexts.tsx +29 -5
- package/src/index.ts +5 -1
- package/src/webchat/message-list/index.tsx +1 -0
- package/src/webchat/webchat.jsx +7 -10
- package/src/webchat/webview.jsx +4 -4
- package/src/webchat-app.jsx +4 -0
- package/src/webview-app.tsx +6 -6
package/src/contexts.tsx
CHANGED
|
@@ -1,18 +1,42 @@
|
|
|
1
|
+
import { Input as CoreInput, Session as CoreSession } from '@botonic/core'
|
|
1
2
|
import { createContext } from 'react'
|
|
2
3
|
|
|
3
|
-
import { WebchatContextProps } from './index-types'
|
|
4
|
+
import { ActionRequest, WebchatContextProps } from './index-types'
|
|
4
5
|
import { webchatInitialState } from './webchat/hooks'
|
|
5
6
|
|
|
6
|
-
export const RequestContext = createContext
|
|
7
|
+
export const RequestContext = createContext<
|
|
8
|
+
Partial<ActionRequest> & {
|
|
9
|
+
getString: () => string
|
|
10
|
+
setLocale: () => void
|
|
11
|
+
}
|
|
12
|
+
>({
|
|
7
13
|
getString: () => '',
|
|
8
|
-
setLocale: () =>
|
|
9
|
-
session: {},
|
|
14
|
+
setLocale: () => undefined,
|
|
15
|
+
session: {} as CoreSession,
|
|
10
16
|
params: {},
|
|
11
|
-
input: {},
|
|
17
|
+
input: {} as CoreInput,
|
|
12
18
|
defaultDelay: 0,
|
|
13
19
|
defaultTyping: 0,
|
|
14
20
|
})
|
|
15
21
|
|
|
22
|
+
export interface CloseWebviewOptions {
|
|
23
|
+
payload?: string
|
|
24
|
+
path?: string
|
|
25
|
+
params?: Record<string, any>
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export const WebviewRequestContext = createContext<{
|
|
29
|
+
closeWebview: (options?: CloseWebviewOptions) => undefined
|
|
30
|
+
getString: (stringId: string) => string
|
|
31
|
+
params: Record<string, any>
|
|
32
|
+
session: CoreSession
|
|
33
|
+
}>({
|
|
34
|
+
closeWebview: () => undefined,
|
|
35
|
+
getString: () => '',
|
|
36
|
+
params: {} as Record<string, any>,
|
|
37
|
+
session: {} as CoreSession,
|
|
38
|
+
})
|
|
39
|
+
|
|
16
40
|
export const WebchatContext = createContext<WebchatContextProps>({
|
|
17
41
|
addMessage: () => {
|
|
18
42
|
return
|
package/src/index.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
export { BotonicInputTester, BotonicOutputTester } from './botonic-tester'
|
|
2
2
|
export * from './components'
|
|
3
|
-
export {
|
|
3
|
+
export {
|
|
4
|
+
RequestContext,
|
|
5
|
+
WebchatContext,
|
|
6
|
+
WebviewRequestContext,
|
|
7
|
+
} from './contexts'
|
|
4
8
|
export { DevApp } from './dev-app'
|
|
5
9
|
export * from './index-types'
|
|
6
10
|
export { msgsToBotonic, msgToBotonic } from './msg-to-botonic'
|
|
@@ -93,6 +93,7 @@ export const WebchatMessageList = props => {
|
|
|
93
93
|
role={ROLES.MESSAGE_LIST}
|
|
94
94
|
// TODO: Distinguis between multiple instances of webchat, e.g. `${uniqueId}-botonic-scrollable`
|
|
95
95
|
id='botonic-scrollable-content'
|
|
96
|
+
// @ts-ignore
|
|
96
97
|
scrollbar={scrollbarOptions}
|
|
97
98
|
autoHide={scrollbarOptions.autoHide}
|
|
98
99
|
ismessagescontainer={true.toString()}
|
package/src/webchat/webchat.jsx
CHANGED
|
@@ -16,7 +16,7 @@ import { Audio, Document, Image, Text, Video } from '../components'
|
|
|
16
16
|
import { Handoff } from '../components/handoff'
|
|
17
17
|
import { normalizeWebchatSettings } from '../components/webchat-settings'
|
|
18
18
|
import { COLORS, MAX_ALLOWED_SIZE_MB, ROLES, WEBCHAT } from '../constants'
|
|
19
|
-
import {
|
|
19
|
+
import { WebchatContext, WebviewRequestContext } from '../contexts'
|
|
20
20
|
import { SENDERS } from '../index-types'
|
|
21
21
|
import {
|
|
22
22
|
getFullMimeWhitelist,
|
|
@@ -367,8 +367,7 @@ export const Webchat = forwardRef((props, ref) => {
|
|
|
367
367
|
if (options && options.payload) {
|
|
368
368
|
sendPayload(options.payload)
|
|
369
369
|
} else if (options && options.path) {
|
|
370
|
-
|
|
371
|
-
if (options.params) params = params2queryString(options.params)
|
|
370
|
+
const params = options.params ? params2queryString(options.params) : ''
|
|
372
371
|
sendPayload(`__PATH_PAYLOAD__${options.path}?${params}`)
|
|
373
372
|
}
|
|
374
373
|
}
|
|
@@ -604,6 +603,7 @@ export const Webchat = forwardRef((props, ref) => {
|
|
|
604
603
|
updateTheme(merge(webchatState.theme, themeUpdates), themeUpdates)
|
|
605
604
|
updateTyping(false)
|
|
606
605
|
},
|
|
606
|
+
closeWebview: closeWebview,
|
|
607
607
|
}))
|
|
608
608
|
|
|
609
609
|
const resolveCase = () => {
|
|
@@ -694,13 +694,10 @@ export const Webchat = forwardRef((props, ref) => {
|
|
|
694
694
|
}
|
|
695
695
|
|
|
696
696
|
const webviewRequestContext = {
|
|
697
|
+
closeWebview: closeWebview,
|
|
697
698
|
getString: stringId => props.getString(stringId, webchatState.session),
|
|
698
|
-
setLocale: locale => props.getString(locale, webchatState.session),
|
|
699
|
-
session: webchatState.session || {},
|
|
700
699
|
params: webchatState.webviewParams || {},
|
|
701
|
-
|
|
702
|
-
defaultDelay: props.defaultDelay || 0,
|
|
703
|
-
defaultTyping: props.defaultTyping || 0,
|
|
700
|
+
session: webchatState.session || {},
|
|
704
701
|
}
|
|
705
702
|
|
|
706
703
|
useEffect(() => {
|
|
@@ -808,7 +805,7 @@ export const Webchat = forwardRef((props, ref) => {
|
|
|
808
805
|
}
|
|
809
806
|
|
|
810
807
|
const webchatWebview = () => (
|
|
811
|
-
<
|
|
808
|
+
<WebviewRequestContext.Provider value={webviewRequestContext}>
|
|
812
809
|
<WebviewContainer
|
|
813
810
|
style={{
|
|
814
811
|
...getThemeProperty(WEBCHAT.CUSTOM_PROPERTIES.webviewStyle),
|
|
@@ -816,7 +813,7 @@ export const Webchat = forwardRef((props, ref) => {
|
|
|
816
813
|
}}
|
|
817
814
|
webview={webchatState.webview}
|
|
818
815
|
/>
|
|
819
|
-
</
|
|
816
|
+
</WebviewRequestContext.Provider>
|
|
820
817
|
)
|
|
821
818
|
let mobileStyle = {}
|
|
822
819
|
if (isMobile(getThemeProperty(WEBCHAT.CUSTOM_PROPERTIES.mobileBreakpoint))) {
|
package/src/webchat/webview.jsx
CHANGED
|
@@ -3,7 +3,7 @@ import Frame from 'react-frame-component'
|
|
|
3
3
|
import styled from 'styled-components'
|
|
4
4
|
|
|
5
5
|
import { COLORS, ROLES, WEBCHAT } from '../constants'
|
|
6
|
-
import {
|
|
6
|
+
import { WebchatContext, WebviewRequestContext } from '../contexts'
|
|
7
7
|
|
|
8
8
|
const StyledWebview = styled.div`
|
|
9
9
|
position: absolute;
|
|
@@ -62,7 +62,7 @@ const WebviewMode = props => {
|
|
|
62
62
|
}
|
|
63
63
|
|
|
64
64
|
export const WebviewHeader = () => {
|
|
65
|
-
const { closeWebview } = useContext(
|
|
65
|
+
const { closeWebview } = useContext(WebviewRequestContext)
|
|
66
66
|
const { getThemeProperty } = useContext(WebchatContext)
|
|
67
67
|
return (
|
|
68
68
|
<StyledWebviewHeader
|
|
@@ -78,10 +78,10 @@ export const WebviewHeader = () => {
|
|
|
78
78
|
|
|
79
79
|
export const WebviewContainer = props => {
|
|
80
80
|
const { webchatState } = useContext(WebchatContext)
|
|
81
|
-
const { closeWebview } = useContext(
|
|
81
|
+
const { closeWebview } = useContext(WebviewRequestContext)
|
|
82
82
|
const Webview = webchatState.webview
|
|
83
83
|
|
|
84
|
-
const close = e => e.data
|
|
84
|
+
const close = e => e.data === 'botonicCloseWebview' && closeWebview()
|
|
85
85
|
|
|
86
86
|
useEffect(() => {
|
|
87
87
|
if (window.addEventListener) {
|
package/src/webchat-app.jsx
CHANGED
package/src/webview-app.tsx
CHANGED
|
@@ -5,7 +5,7 @@ import React from 'react'
|
|
|
5
5
|
import { render } from 'react-dom'
|
|
6
6
|
import { BrowserRouter, Route } from 'react-router-dom'
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import { CloseWebviewOptions, WebviewRequestContext } from './contexts'
|
|
9
9
|
|
|
10
10
|
class App extends React.Component {
|
|
11
11
|
constructor(props) {
|
|
@@ -21,7 +21,7 @@ class App extends React.Component {
|
|
|
21
21
|
this.state = { session, params }
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
-
async close(options) {
|
|
24
|
+
async close(options?: CloseWebviewOptions) {
|
|
25
25
|
let payload = options ? options.payload : null
|
|
26
26
|
if (options.path) payload = `__PATH_PAYLOAD__${options.path}`
|
|
27
27
|
if (payload) {
|
|
@@ -76,8 +76,8 @@ class App extends React.Component {
|
|
|
76
76
|
}
|
|
77
77
|
|
|
78
78
|
render() {
|
|
79
|
-
const
|
|
80
|
-
getString: stringId =>
|
|
79
|
+
const webviewRequestContext = {
|
|
80
|
+
getString: (stringId: string) =>
|
|
81
81
|
getString(this.props.locales, this.state.session.__locale, stringId),
|
|
82
82
|
session: this.state.session || {},
|
|
83
83
|
params: this.state.params || {},
|
|
@@ -85,11 +85,11 @@ class App extends React.Component {
|
|
|
85
85
|
}
|
|
86
86
|
|
|
87
87
|
return (
|
|
88
|
-
<
|
|
88
|
+
<WebviewRequestContext.Provider value={webviewRequestContext}>
|
|
89
89
|
{this.props.webviews.map((Webview, i) => (
|
|
90
90
|
<Route key={i} path={`/${Webview.name}`} component={Webview} />
|
|
91
91
|
))}
|
|
92
|
-
</
|
|
92
|
+
</WebviewRequestContext.Provider>
|
|
93
93
|
)
|
|
94
94
|
}
|
|
95
95
|
}
|