@botonic/react 0.20.2 → 0.20.5
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 +30 -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/index.d.ts +7 -3
- 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/dev-app.js +2 -2
- package/lib/index.d.ts +7 -10
- package/lib/node-app.js +2 -2
- package/lib/react-bot.js +2 -2
- package/lib/util/error-boundary.js +2 -2
- package/lib/webchat/header.js +2 -2
- package/lib/webchat/hooks.js +2 -2
- package/lib/webchat/message-list.js +2 -2
- package/lib/webchat/messages-reducer.js +2 -2
- package/lib/webchat/replies.js +2 -2
- package/lib/webchat/session-view.js +2 -2
- package/lib/webchat/webchat-reducer.js +2 -2
- package/lib/webchat/webchat.js +6 -5
- package/lib/webchat/webchat.js.map +1 -1
- package/lib/webchat/webview.js +2 -2
- package/lib/webchat-app.js +13 -6
- package/lib/webchat-app.js.map +1 -1
- package/package.json +2 -2
- package/src/components/button.jsx +21 -1
- package/src/components/index.d.ts +7 -3
- package/src/index.d.ts +7 -10
- package/src/webchat/webchat.jsx +7 -6
- package/src/webchat-app.jsx +13 -7
|
@@ -85,6 +85,25 @@ export const Button = props => {
|
|
|
85
85
|
}
|
|
86
86
|
}
|
|
87
87
|
|
|
88
|
+
const getClassName = (isCustom = false) => {
|
|
89
|
+
if (isCustom) {
|
|
90
|
+
return 'button-custom'
|
|
91
|
+
}
|
|
92
|
+
if (props.payload) {
|
|
93
|
+
return 'button-payload'
|
|
94
|
+
}
|
|
95
|
+
if (props.url) {
|
|
96
|
+
return 'button-url'
|
|
97
|
+
}
|
|
98
|
+
if (props.webview) {
|
|
99
|
+
return 'button-webview'
|
|
100
|
+
}
|
|
101
|
+
if (props.path) {
|
|
102
|
+
return 'button-path'
|
|
103
|
+
}
|
|
104
|
+
return ''
|
|
105
|
+
}
|
|
106
|
+
|
|
88
107
|
const renderBrowser = () => {
|
|
89
108
|
const buttonStyle = getThemeProperty(WEBCHAT.CUSTOM_PROPERTIES.buttonStyle)
|
|
90
109
|
const CustomButton = getThemeProperty(
|
|
@@ -92,7 +111,7 @@ export const Button = props => {
|
|
|
92
111
|
)
|
|
93
112
|
if (CustomButton) {
|
|
94
113
|
return (
|
|
95
|
-
<div onClick={e => handleClick(e)}>
|
|
114
|
+
<div className={getClassName(true)} onClick={e => handleClick(e)}>
|
|
96
115
|
<CustomButton>{props.children}</CustomButton>
|
|
97
116
|
</div>
|
|
98
117
|
)
|
|
@@ -119,6 +138,7 @@ export const Button = props => {
|
|
|
119
138
|
|
|
120
139
|
return (
|
|
121
140
|
<StyledButton
|
|
141
|
+
className={getClassName()}
|
|
122
142
|
theme={theme}
|
|
123
143
|
onMouseEnter={() => setHover(true)}
|
|
124
144
|
onMouseLeave={() => setHover(false)}
|
|
@@ -102,13 +102,17 @@ export interface PersistentMenuProps {
|
|
|
102
102
|
options: any
|
|
103
103
|
}
|
|
104
104
|
|
|
105
|
-
export type BlockInputOption = {
|
|
105
|
+
export type BlockInputOption = {
|
|
106
|
+
preprocess?: (message: string) => string
|
|
107
|
+
match: RegExp[]
|
|
108
|
+
message: string
|
|
109
|
+
}
|
|
106
110
|
|
|
107
111
|
export interface BlobProps {
|
|
108
112
|
blobTick?: boolean
|
|
109
113
|
blobTickStyle?: any
|
|
110
114
|
blobWidth?: string
|
|
111
|
-
|
|
115
|
+
imageStyle?: any
|
|
112
116
|
}
|
|
113
117
|
|
|
114
118
|
export interface ScrollbarProps {
|
|
@@ -185,7 +189,7 @@ export interface ThemeProps extends StyleProp {
|
|
|
185
189
|
}
|
|
186
190
|
|
|
187
191
|
export interface CoverComponentOptions {
|
|
188
|
-
component: React.
|
|
192
|
+
component: React.ComponentType<CoverComponentProps>
|
|
189
193
|
props?: any
|
|
190
194
|
}
|
|
191
195
|
|
package/src/index.d.ts
CHANGED
|
@@ -25,10 +25,6 @@ export interface Route extends core.Route {
|
|
|
25
25
|
}
|
|
26
26
|
type Routes = core.Routes<Route>
|
|
27
27
|
|
|
28
|
-
export interface BotOptions extends core.BotOptions {
|
|
29
|
-
routes: Routes
|
|
30
|
-
}
|
|
31
|
-
|
|
32
28
|
export class ReactBot extends core.CoreBot {
|
|
33
29
|
renderReactActions({
|
|
34
30
|
actions,
|
|
@@ -37,7 +33,7 @@ export class ReactBot extends core.CoreBot {
|
|
|
37
33
|
}
|
|
38
34
|
|
|
39
35
|
export class NodeApp {
|
|
40
|
-
constructor(options: Omit<
|
|
36
|
+
constructor(options: Omit<core.CoreBotConfig, 'renderer'>)
|
|
41
37
|
bot: ReactBot
|
|
42
38
|
input(request: core.BotRequest): Promise<BotResponse>
|
|
43
39
|
renderNode(args): string
|
|
@@ -116,7 +112,7 @@ export interface WebchatArgs {
|
|
|
116
112
|
onOpen?: (app: WebchatApp, args: any) => void
|
|
117
113
|
onConnectionChange?: (app: WebchatApp, isOnline: boolean) => void
|
|
118
114
|
persistentMenu?: PersistentMenuTheme
|
|
119
|
-
storage?: Storage
|
|
115
|
+
storage?: Storage | null
|
|
120
116
|
storageKey?: any
|
|
121
117
|
theme?: ThemeProps
|
|
122
118
|
}
|
|
@@ -175,6 +171,7 @@ export class WebchatApp {
|
|
|
175
171
|
clearMessages(): void
|
|
176
172
|
close(): void
|
|
177
173
|
closeCoverComponent(): void
|
|
174
|
+
destroy(): void
|
|
178
175
|
getComponent(
|
|
179
176
|
host: HTMLElement,
|
|
180
177
|
optionsAtRuntime?: WebchatAppArgs
|
|
@@ -191,7 +188,7 @@ export class WebchatApp {
|
|
|
191
188
|
onUserInput(args: OnUserInputArgs): Promise<void>
|
|
192
189
|
open(): void
|
|
193
190
|
openCoverComponent(): void
|
|
194
|
-
render(dest
|
|
191
|
+
render(dest?: HTMLElement, optionsAtRuntime?: WebchatAppArgs): void
|
|
195
192
|
resendUnsentInputs(): Promise<void>
|
|
196
193
|
resolveWebchatVisibility(optionsAtRuntime: {
|
|
197
194
|
appId: string
|
|
@@ -202,14 +199,14 @@ export class WebchatApp {
|
|
|
202
199
|
toggleCoverComponent(): void
|
|
203
200
|
updateMessageInfo(msgId: string, messageInfo: MessageInfo): void
|
|
204
201
|
updateLastMessageDate(date: string): void
|
|
205
|
-
updateUser(user: core.SessionUser): void
|
|
202
|
+
updateUser(user: Partial<core.SessionUser>): void
|
|
206
203
|
updateWebchatSettings(settings: WebchatSettingsProps): void
|
|
207
204
|
renderCustomComponent(customComponent: React.ReactNode): void
|
|
208
205
|
unmountCustomComponent(): void
|
|
209
206
|
}
|
|
210
207
|
|
|
211
208
|
export interface WebchatContextProps {
|
|
212
|
-
sendText: (text: string) => void
|
|
209
|
+
sendText: (text: string, payload?: string) => void
|
|
213
210
|
sendAttachment: (attachment: File) => void
|
|
214
211
|
sendPayload: (payload: string) => void
|
|
215
212
|
sendInput: (input: core.Input) => void
|
|
@@ -225,7 +222,7 @@ export interface WebchatContextProps {
|
|
|
225
222
|
theme: ThemeProps
|
|
226
223
|
webchatState: WebchatState
|
|
227
224
|
updateWebchatDevSettings: (settings: WebchatSettingsProps) => void
|
|
228
|
-
updateUser: (user: core.SessionUser) => void
|
|
225
|
+
updateUser: (user: Partial<core.SessionUser>) => void
|
|
229
226
|
}
|
|
230
227
|
export const WebchatContext: React.Context<WebchatContextProps>
|
|
231
228
|
export type WebchatContext = React.Context<WebchatContextProps>
|
package/src/webchat/webchat.jsx
CHANGED
|
@@ -202,16 +202,13 @@ export const Webchat = forwardRef((props, ref) => {
|
|
|
202
202
|
const getThemeProperty = _getThemeProperty(theme)
|
|
203
203
|
|
|
204
204
|
const [customComponent, setCustomComponent] = useState(null)
|
|
205
|
-
const storage = props.storage
|
|
205
|
+
const storage = props.storage
|
|
206
206
|
const storageKey =
|
|
207
207
|
typeof props.storageKey === 'function'
|
|
208
208
|
? props.storageKey()
|
|
209
209
|
: props.storageKey
|
|
210
210
|
|
|
211
|
-
const [botonicState, saveState] = useStorageState(
|
|
212
|
-
storage,
|
|
213
|
-
storageKey || WEBCHAT.DEFAULTS.STORAGE_KEY
|
|
214
|
-
)
|
|
211
|
+
const [botonicState, saveState] = useStorageState(storage, storageKey)
|
|
215
212
|
|
|
216
213
|
const host = props.host || document.body
|
|
217
214
|
|
|
@@ -405,9 +402,13 @@ export const Webchat = forwardRef((props, ref) => {
|
|
|
405
402
|
)
|
|
406
403
|
|
|
407
404
|
const getBlockInputs = (rule, inputData) => {
|
|
405
|
+
const processedInput = rule.preprocess
|
|
406
|
+
? rule.preprocess(inputData)
|
|
407
|
+
: inputData
|
|
408
|
+
|
|
408
409
|
return rule.match.some(regex => {
|
|
409
410
|
if (typeof regex === 'string') regex = deserializeRegex(regex)
|
|
410
|
-
return regex.test(
|
|
411
|
+
return regex.test(processedInput)
|
|
411
412
|
})
|
|
412
413
|
}
|
|
413
414
|
|
package/src/webchat-app.jsx
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { HubtypeService, INPUT } from '@botonic/core'
|
|
2
2
|
import merge from 'lodash.merge'
|
|
3
3
|
import React, { createRef } from 'react'
|
|
4
|
-
import { render } from 'react-dom'
|
|
4
|
+
import { render, unmountComponentAtNode } from 'react-dom'
|
|
5
5
|
|
|
6
6
|
import { SENDERS, WEBCHAT } from './constants'
|
|
7
7
|
import { msgToBotonic } from './msg-to-botonic'
|
|
@@ -51,8 +51,8 @@ export class WebchatApp {
|
|
|
51
51
|
this.hostId = hostId || WEBCHAT.DEFAULTS.HOST_ID
|
|
52
52
|
this.defaultDelay = defaultDelay
|
|
53
53
|
this.defaultTyping = defaultTyping
|
|
54
|
-
this.storage = storage
|
|
55
|
-
this.storageKey = storageKey
|
|
54
|
+
this.storage = storage === undefined ? localStorage : storage
|
|
55
|
+
this.storageKey = storageKey || WEBCHAT.DEFAULTS.STORAGE_KEY
|
|
56
56
|
this.onInit = onInit
|
|
57
57
|
this.onOpen = onOpen
|
|
58
58
|
this.onClose = onClose
|
|
@@ -286,9 +286,9 @@ export class WebchatApp {
|
|
|
286
286
|
enableAnimations = enableAnimations || this.enableAnimations
|
|
287
287
|
defaultDelay = defaultDelay || this.defaultDelay
|
|
288
288
|
defaultTyping = defaultTyping || this.defaultTyping
|
|
289
|
-
storage = storage || this.storage
|
|
290
|
-
storageKey = storageKey || this.storageKey
|
|
291
289
|
server = server || this.server
|
|
290
|
+
this.storage = storage || this.storage
|
|
291
|
+
this.storageKey = storageKey || this.storageKey
|
|
292
292
|
this.onInit = onInit || this.onInit
|
|
293
293
|
this.onOpen = onOpen || this.onOpen
|
|
294
294
|
this.onClose = onClose || this.onClose
|
|
@@ -312,8 +312,8 @@ export class WebchatApp {
|
|
|
312
312
|
enableAttachments={enableAttachments}
|
|
313
313
|
enableUserInput={enableUserInput}
|
|
314
314
|
enableAnimations={enableAnimations}
|
|
315
|
-
storage={storage}
|
|
316
|
-
storageKey={storageKey}
|
|
315
|
+
storage={this.storage}
|
|
316
|
+
storageKey={this.storageKey}
|
|
317
317
|
defaultDelay={defaultDelay}
|
|
318
318
|
defaultTyping={defaultTyping}
|
|
319
319
|
onInit={(...args) => this.onInitWebchat(...args)}
|
|
@@ -351,6 +351,12 @@ export class WebchatApp {
|
|
|
351
351
|
return false
|
|
352
352
|
}
|
|
353
353
|
|
|
354
|
+
destroy() {
|
|
355
|
+
if (this.hubtypeService) this.hubtypeService.destroyPusher()
|
|
356
|
+
unmountComponentAtNode(this.host)
|
|
357
|
+
if (this.storage) this.storage.removeItem(this.storageKey)
|
|
358
|
+
}
|
|
359
|
+
|
|
354
360
|
async render(dest, optionsAtRuntime = {}) {
|
|
355
361
|
onDOMLoaded(async () => {
|
|
356
362
|
const isVisible = await this.resolveWebchatVisibility(optionsAtRuntime)
|