@botonic/react 0.20.6 → 0.20.8
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@botonic/react",
|
|
3
|
-
"version": "0.20.
|
|
3
|
+
"version": "0.20.8",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "Build Chatbots using React",
|
|
6
6
|
"main": "src/index.js",
|
|
@@ -43,7 +43,6 @@
|
|
|
43
43
|
"react-reveal": "^1.2.2",
|
|
44
44
|
"react-router-dom": "^5.2.1",
|
|
45
45
|
"react-textarea-autosize": "^7.1.2",
|
|
46
|
-
"react-use-storage": "^0.5.1",
|
|
47
46
|
"reconnecting-websocket": "^4.4.0",
|
|
48
47
|
"simplebar-react": "^2.3.3",
|
|
49
48
|
"styled-components": "^5.3.0",
|
package/src/components/image.jsx
CHANGED
|
@@ -26,7 +26,7 @@ export const Image = props => {
|
|
|
26
26
|
const closePreviewer = () => setIsPreviewerOpened(false)
|
|
27
27
|
|
|
28
28
|
const { getThemeProperty } = useContext(WebchatContext)
|
|
29
|
-
const
|
|
29
|
+
const ImagePreviewer = getThemeProperty(
|
|
30
30
|
WEBCHAT.CUSTOM_PROPERTIES.imagePreviewer,
|
|
31
31
|
null
|
|
32
32
|
)
|
|
@@ -36,15 +36,16 @@ export const Image = props => {
|
|
|
36
36
|
<StyledImage
|
|
37
37
|
src={props.src}
|
|
38
38
|
onClick={openPreviewer}
|
|
39
|
-
hasPreviewer={Boolean(
|
|
39
|
+
hasPreviewer={Boolean(ImagePreviewer)}
|
|
40
40
|
/>
|
|
41
|
-
{
|
|
42
|
-
|
|
43
|
-
src
|
|
44
|
-
isPreviewerOpened
|
|
45
|
-
openPreviewer
|
|
46
|
-
closePreviewer
|
|
47
|
-
|
|
41
|
+
{ImagePreviewer && (
|
|
42
|
+
<ImagePreviewer
|
|
43
|
+
src={props.src}
|
|
44
|
+
isPreviewerOpened={isPreviewerOpened}
|
|
45
|
+
openPreviewer={openPreviewer}
|
|
46
|
+
closePreviewer={closePreviewer}
|
|
47
|
+
/>
|
|
48
|
+
)}
|
|
48
49
|
</>
|
|
49
50
|
)
|
|
50
51
|
}
|
|
@@ -52,8 +52,9 @@ const TimestampText = styled.div`
|
|
|
52
52
|
`
|
|
53
53
|
|
|
54
54
|
export const MessageTimestamp = ({ timestamp, style, isfromuser }) => {
|
|
55
|
+
const classSufix = isfromuser ? 'user' : 'bot'
|
|
55
56
|
return (
|
|
56
|
-
<TimestampContainer>
|
|
57
|
+
<TimestampContainer className={`botonic-timestamp-${classSufix}`}>
|
|
57
58
|
<TimestampText
|
|
58
59
|
isfromuser={isfromuser}
|
|
59
60
|
style={{
|
|
@@ -1,9 +1,44 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
1
|
+
import { useCallback, useEffect, useState } from 'react'
|
|
2
|
+
|
|
3
|
+
//Code taken from https://github.com/leny/react-use-storage
|
|
4
|
+
const evtTarget = new EventTarget()
|
|
5
|
+
|
|
6
|
+
export function useStorageState(storage, key, defaultValue) {
|
|
7
|
+
const raw = storage?.getItem(key)
|
|
8
|
+
|
|
9
|
+
const [value, setValue] = useState(raw ? JSON.parse(raw) : defaultValue)
|
|
10
|
+
|
|
11
|
+
const updater = useCallback(
|
|
12
|
+
(updatedValue, remove = false) => {
|
|
13
|
+
setValue(updatedValue)
|
|
14
|
+
storage[remove ? 'removeItem' : 'setItem'](
|
|
15
|
+
key,
|
|
16
|
+
JSON.stringify(updatedValue)
|
|
17
|
+
)
|
|
18
|
+
evtTarget.dispatchEvent(
|
|
19
|
+
new CustomEvent('storage_change', { detail: { key } })
|
|
20
|
+
)
|
|
21
|
+
},
|
|
22
|
+
[key]
|
|
23
|
+
)
|
|
24
|
+
|
|
25
|
+
defaultValue != null && !raw && updater(defaultValue)
|
|
26
|
+
|
|
27
|
+
useEffect(() => {
|
|
28
|
+
const listener = ({ detail }) => {
|
|
29
|
+
if (detail.key === key) {
|
|
30
|
+
const lraw = storage?.getItem(key)
|
|
31
|
+
|
|
32
|
+
lraw !== raw && setValue(JSON.parse(lraw))
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
evtTarget.addEventListener('storage_change', listener)
|
|
37
|
+
return () => evtTarget.removeEventListener('storage_change', listener)
|
|
38
|
+
})
|
|
39
|
+
|
|
40
|
+
if (storage === null) {
|
|
41
|
+
return [undefined, undefined]
|
|
42
|
+
}
|
|
43
|
+
return [value, updater, () => updater(null, true)]
|
|
9
44
|
}
|