@botonic/react 0.21.4 → 0.21.6

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.21.4",
3
+ "version": "0.21.6",
4
4
  "license": "MIT",
5
5
  "description": "Build Chatbots using React",
6
6
  "main": "src/index.js",
@@ -29,7 +29,7 @@
29
29
  "README.md"
30
30
  ],
31
31
  "dependencies": {
32
- "@botonic/core": "~0.21.5",
32
+ "@botonic/core": "^0.21.6",
33
33
  "axios": "^0.24.0",
34
34
  "emoji-picker-react": "^3.2.3",
35
35
  "framer-motion": "^3.1.1",
@@ -42,14 +42,14 @@
42
42
  "react-frame-component": "^4.1.3",
43
43
  "react-json-tree": "^0.15.0",
44
44
  "react-reveal": "^1.2.2",
45
- "react-router-dom": "^5.2.1",
45
+ "react-router-dom": "^5.3.4",
46
46
  "react-textarea-autosize": "^7.1.2",
47
47
  "reconnecting-websocket": "^4.4.0",
48
- "simplebar-react": "^2.3.3",
48
+ "simplebar-react": "^2.4.3",
49
49
  "styled-components": "^5.3.0",
50
- "ua-parser-js": "^0.7.21",
50
+ "ua-parser-js": "^0.8.1",
51
51
  "unescape": "^1.0.1",
52
- "use-async-effect": "^2.2.3",
52
+ "use-async-effect": "^2.2.7",
53
53
  "uuid": "^8.3.2"
54
54
  },
55
55
  "devDependencies": {
@@ -2,6 +2,7 @@ import { INPUT, isBrowser } from '@botonic/core'
2
2
  import React from 'react'
3
3
 
4
4
  import { ROLES } from '../constants'
5
+ import { staticAsset } from '../util/environment'
5
6
  import { Message } from './message'
6
7
 
7
8
  const serialize = audioProps => {
@@ -9,6 +10,7 @@ const serialize = audioProps => {
9
10
  }
10
11
 
11
12
  export const Audio = props => {
13
+ props = { ...props, src: staticAsset(props.src) }
12
14
  let content = props.children
13
15
  if (isBrowser())
14
16
  content = (
@@ -4,6 +4,7 @@ import styled from 'styled-components'
4
4
 
5
5
  import { ROLES, WEBCHAT } from '../constants'
6
6
  import { WebchatContext } from '../contexts'
7
+ import { staticAsset } from '../util/environment'
7
8
  import { Message } from './message'
8
9
 
9
10
  const StyledButton = styled.a`
@@ -29,6 +30,7 @@ const serialize = documentProps => {
29
30
  }
30
31
 
31
32
  export const Document = props => {
33
+ props = { ...props, src: staticAsset(props.src) }
32
34
  let content = props.children
33
35
 
34
36
  const { getThemeProperty } = useContext(WebchatContext)
@@ -4,6 +4,7 @@ import styled from 'styled-components'
4
4
 
5
5
  import { ROLES, WEBCHAT } from '../constants'
6
6
  import { WebchatContext } from '../contexts'
7
+ import { staticAsset } from '../util/environment'
7
8
  import { Message } from './message'
8
9
 
9
10
  const StyledImage = styled.img`
@@ -19,6 +20,7 @@ const serialize = imageProps => {
19
20
  }
20
21
 
21
22
  export const Image = props => {
23
+ props = { ...props, src: staticAsset(props.src) }
22
24
  let content = props.children
23
25
 
24
26
  const [isPreviewerOpened, setIsPreviewerOpened] = useState(false)
@@ -2,6 +2,7 @@ import React from 'react'
2
2
  import styled from 'styled-components'
3
3
 
4
4
  import { COLORS, WEBCHAT } from '../constants'
5
+ import { staticAsset } from '../util/environment'
5
6
  import { renderComponent } from '../util/react'
6
7
 
7
8
  const PicStyled = styled.img`
@@ -15,6 +16,7 @@ const PicStyled = styled.img`
15
16
  `
16
17
 
17
18
  export const Pic = props => {
19
+ props = { ...props, src: staticAsset(props.src) }
18
20
  const renderBrowser = () => <PicStyled src={props.src} />
19
21
  const renderNode = () => <pic>{props.src}</pic>
20
22
  return renderComponent({ renderBrowser, renderNode })
@@ -3,6 +3,7 @@ import React from 'react'
3
3
  import styled from 'styled-components'
4
4
 
5
5
  import { COLORS, ROLES } from '../constants'
6
+ import { staticAsset } from '../util/environment'
6
7
  import { Message } from './message'
7
8
 
8
9
  const StyledVideo = styled.video`
@@ -18,6 +19,7 @@ const serialize = videoProps => {
18
19
  }
19
20
 
20
21
  export const Video = props => {
22
+ props = { ...props, src: staticAsset(props.src) }
21
23
  let content = props.children
22
24
  if (isBrowser())
23
25
  content = (
@@ -9,10 +9,11 @@ export const staticAsset = path => {
9
9
  .getAttribute('src')
10
10
  const scriptName = scriptBaseURL.split('/').pop()
11
11
  const basePath = scriptBaseURL.replace('/' + scriptName, '/')
12
- return basePath + path
12
+ const resolvedStaticAssetPath = basePath + path
13
+ return resolvedStaticAssetPath
13
14
  } catch (e) {
14
15
  console.error(`Could not resolve path: '${path}'`)
15
- return path
16
+ return normalize(path)
16
17
  }
17
18
  }
18
19
 
@@ -26,3 +27,31 @@ export const isURL = urlPath => {
26
27
  const pattern = new RegExp(/^(https?|ftp):\/\/[^\s/$.?#].[^\s]*$/)
27
28
  return !!pattern.test(urlPath)
28
29
  }
30
+
31
+ export function normalize(path) {
32
+ const isAbsolute = path.charAt(0) === '/'
33
+ const trailingSlash = path && path[path.length - 1] === '/'
34
+ // Normalize the path
35
+ path = normalizeArray(path.split('/'), !isAbsolute).join('/')
36
+ if (!path && !isAbsolute) path = '.'
37
+ if (path && trailingSlash) path += '/'
38
+ return (isAbsolute ? '/' : '') + path
39
+ }
40
+
41
+ function normalizeArray(parts, allowAboveRoot) {
42
+ const res = []
43
+ for (let i = 0; i < parts.length; i++) {
44
+ const p = parts[i]
45
+ if (!p || p === '.') continue
46
+ if (p === '..') {
47
+ if (res.length && res[res.length - 1] !== '..') {
48
+ res.pop()
49
+ } else if (allowAboveRoot) {
50
+ res.push('..')
51
+ }
52
+ } else {
53
+ res.push(p)
54
+ }
55
+ }
56
+ return res
57
+ }