@botonic/react 0.44.0-alpha.0 → 0.44.0-alpha.2

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.
Files changed (79) hide show
  1. package/lib/cjs/components/button/index.d.ts +1 -0
  2. package/lib/cjs/components/button/index.js +2 -0
  3. package/lib/cjs/components/button/index.js.map +1 -1
  4. package/lib/cjs/components/carousel.d.ts +1 -0
  5. package/lib/cjs/components/carousel.js +2 -0
  6. package/lib/cjs/components/carousel.js.map +1 -1
  7. package/lib/cjs/components/constants.d.ts +11 -0
  8. package/lib/cjs/components/constants.js +15 -0
  9. package/lib/cjs/components/constants.js.map +1 -0
  10. package/lib/cjs/components/multichannel/multichannel-button.d.ts +3 -0
  11. package/lib/cjs/components/multichannel/multichannel-button.js +4 -2
  12. package/lib/cjs/components/multichannel/multichannel-button.js.map +1 -1
  13. package/lib/cjs/components/multichannel/multichannel-reply.d.ts +3 -0
  14. package/lib/cjs/components/multichannel/multichannel-reply.js +2 -0
  15. package/lib/cjs/components/multichannel/multichannel-reply.js.map +1 -1
  16. package/lib/cjs/components/multichannel/multichannel-utils.d.ts +35 -20
  17. package/lib/cjs/components/multichannel/multichannel-utils.js +10 -21
  18. package/lib/cjs/components/multichannel/multichannel-utils.js.map +1 -1
  19. package/lib/cjs/components/pic.d.ts +1 -0
  20. package/lib/cjs/components/pic.js +2 -0
  21. package/lib/cjs/components/pic.js.map +1 -1
  22. package/lib/cjs/components/reply.d.ts +1 -0
  23. package/lib/cjs/components/reply.js +2 -0
  24. package/lib/cjs/components/reply.js.map +1 -1
  25. package/lib/cjs/components/subtitle.d.ts +1 -0
  26. package/lib/cjs/components/subtitle.js +2 -0
  27. package/lib/cjs/components/subtitle.js.map +1 -1
  28. package/lib/cjs/components/text.d.ts +1 -0
  29. package/lib/cjs/components/text.js +2 -0
  30. package/lib/cjs/components/text.js.map +1 -1
  31. package/lib/cjs/components/title.d.ts +1 -0
  32. package/lib/cjs/components/title.js +2 -0
  33. package/lib/cjs/components/title.js.map +1 -1
  34. package/lib/esm/components/button/index.d.ts +1 -0
  35. package/lib/esm/components/button/index.js +2 -0
  36. package/lib/esm/components/button/index.js.map +1 -1
  37. package/lib/esm/components/carousel.d.ts +1 -0
  38. package/lib/esm/components/carousel.js +2 -0
  39. package/lib/esm/components/carousel.js.map +1 -1
  40. package/lib/esm/components/constants.d.ts +11 -0
  41. package/lib/esm/components/constants.js +15 -0
  42. package/lib/esm/components/constants.js.map +1 -0
  43. package/lib/esm/components/multichannel/multichannel-button.d.ts +3 -0
  44. package/lib/esm/components/multichannel/multichannel-button.js +4 -2
  45. package/lib/esm/components/multichannel/multichannel-button.js.map +1 -1
  46. package/lib/esm/components/multichannel/multichannel-reply.d.ts +3 -0
  47. package/lib/esm/components/multichannel/multichannel-reply.js +2 -0
  48. package/lib/esm/components/multichannel/multichannel-reply.js.map +1 -1
  49. package/lib/esm/components/multichannel/multichannel-utils.d.ts +35 -20
  50. package/lib/esm/components/multichannel/multichannel-utils.js +10 -21
  51. package/lib/esm/components/multichannel/multichannel-utils.js.map +1 -1
  52. package/lib/esm/components/pic.d.ts +1 -0
  53. package/lib/esm/components/pic.js +2 -0
  54. package/lib/esm/components/pic.js.map +1 -1
  55. package/lib/esm/components/reply.d.ts +1 -0
  56. package/lib/esm/components/reply.js +2 -0
  57. package/lib/esm/components/reply.js.map +1 -1
  58. package/lib/esm/components/subtitle.d.ts +1 -0
  59. package/lib/esm/components/subtitle.js +2 -0
  60. package/lib/esm/components/subtitle.js.map +1 -1
  61. package/lib/esm/components/text.d.ts +1 -0
  62. package/lib/esm/components/text.js +2 -0
  63. package/lib/esm/components/text.js.map +1 -1
  64. package/lib/esm/components/title.d.ts +1 -0
  65. package/lib/esm/components/title.js +2 -0
  66. package/lib/esm/components/title.js.map +1 -1
  67. package/package.json +2 -2
  68. package/src/components/button/index.tsx +3 -0
  69. package/src/components/carousel.tsx +3 -0
  70. package/src/components/constants.ts +11 -0
  71. package/src/components/multichannel/multichannel-button.jsx +3 -0
  72. package/src/components/multichannel/multichannel-reply.jsx +3 -0
  73. package/src/components/multichannel/multichannel-utils.ts +111 -0
  74. package/src/components/pic.tsx +3 -0
  75. package/src/components/reply.tsx +3 -0
  76. package/src/components/subtitle.tsx +3 -0
  77. package/src/components/text.tsx +3 -0
  78. package/src/components/title.tsx +3 -0
  79. package/src/components/multichannel/multichannel-utils.js +0 -91
@@ -0,0 +1,111 @@
1
+ import { COMPONENT_DISPLAY_NAMES } from '../constants'
2
+
3
+ interface ReactElementWithDisplayName {
4
+ type?: {
5
+ displayName?: string
6
+ }
7
+ }
8
+
9
+ interface ElementWithProps {
10
+ props?: {
11
+ url?: string
12
+ payload?: string
13
+ path?: string
14
+ webview?: unknown
15
+ }
16
+ }
17
+
18
+ export function isMultichannelButton(
19
+ node?: ReactElementWithDisplayName
20
+ ): boolean {
21
+ return node?.type?.displayName === COMPONENT_DISPLAY_NAMES.MultichannelButton
22
+ }
23
+
24
+ export function isMultichannelReply(
25
+ node?: ReactElementWithDisplayName
26
+ ): boolean {
27
+ return node?.type?.displayName === COMPONENT_DISPLAY_NAMES.MultichannelReply
28
+ }
29
+
30
+ export function isNodeText(node?: ReactElementWithDisplayName): boolean {
31
+ return node?.type?.displayName === COMPONENT_DISPLAY_NAMES.Text
32
+ }
33
+
34
+ export function isNodeButton(node?: ReactElementWithDisplayName): boolean {
35
+ return node?.type?.displayName === COMPONENT_DISPLAY_NAMES.Button
36
+ }
37
+
38
+ export function isNodeCarousel(node?: ReactElementWithDisplayName): boolean {
39
+ return node?.type?.displayName === COMPONENT_DISPLAY_NAMES.Carousel
40
+ }
41
+
42
+ export function isNodeReply(node?: ReactElementWithDisplayName): boolean {
43
+ return node?.type?.displayName === COMPONENT_DISPLAY_NAMES.Reply
44
+ }
45
+
46
+ export function isNodePic(node?: ReactElementWithDisplayName): boolean {
47
+ return node?.type?.displayName === COMPONENT_DISPLAY_NAMES.Pic
48
+ }
49
+
50
+ export function isNodeTitle(node?: ReactElementWithDisplayName): boolean {
51
+ return node?.type?.displayName === COMPONENT_DISPLAY_NAMES.Title
52
+ }
53
+
54
+ export function isNodeSubtitle(node?: ReactElementWithDisplayName): boolean {
55
+ return node?.type?.displayName === COMPONENT_DISPLAY_NAMES.Subtitle
56
+ }
57
+
58
+ export function elementHasUrl(element?: ElementWithProps): string | undefined {
59
+ return element?.props?.url
60
+ }
61
+
62
+ export function elementHasPostback(
63
+ element?: ElementWithProps
64
+ ): string | undefined {
65
+ return element?.props?.payload || element?.props?.path
66
+ }
67
+
68
+ export function elementHasWebview(element?: ElementWithProps): unknown {
69
+ return element?.props?.webview
70
+ }
71
+
72
+ export const buttonTypes = {
73
+ POSTBACK: 'postback',
74
+ URL: 'url',
75
+ WEBVIEW: 'webview',
76
+ } as const
77
+
78
+ export type ButtonType = (typeof buttonTypes)[keyof typeof buttonTypes]
79
+
80
+ export function getButtonType(
81
+ multichannelButton?: ElementWithProps
82
+ ): ButtonType | undefined {
83
+ if (elementHasUrl(multichannelButton)) return buttonTypes.URL
84
+ if (elementHasPostback(multichannelButton)) return buttonTypes.POSTBACK
85
+ if (elementHasWebview(multichannelButton)) return buttonTypes.WEBVIEW
86
+
87
+ return undefined
88
+ }
89
+
90
+ export function getFilteredElements<T extends ReactElementWithDisplayName>(
91
+ node: Iterable<T>,
92
+ filter: (n: T) => boolean
93
+ ): T[] {
94
+ const elements: T[] = []
95
+ for (const n of node) {
96
+ if (filter(n)) elements.push(n)
97
+ }
98
+ return elements
99
+ }
100
+
101
+ export function getMultichannelButtons(
102
+ node: Iterable<ReactElementWithDisplayName>
103
+ ): ReactElementWithDisplayName[] {
104
+ return getFilteredElements(node, isMultichannelButton)
105
+ }
106
+
107
+ export function getMultichannelReplies(
108
+ node: Iterable<ReactElementWithDisplayName>
109
+ ): ReactElementWithDisplayName[] {
110
+ return getFilteredElements(node, isMultichannelReply)
111
+ }
@@ -4,6 +4,7 @@ import styled from 'styled-components'
4
4
  import { COLORS, WEBCHAT } from '../constants'
5
5
  import { staticAsset } from '../util/environment'
6
6
  import { renderComponent } from '../util/react'
7
+ import { COMPONENT_DISPLAY_NAMES } from './constants'
7
8
 
8
9
  const PicStyled = styled.img`
9
10
  border-top-left-radius: 8px;
@@ -29,6 +30,8 @@ export const Pic = (props: PicProps) => {
29
30
  return renderComponent({ renderBrowser, renderNode })
30
31
  }
31
32
 
33
+ Pic.displayName = COMPONENT_DISPLAY_NAMES.Pic
34
+
32
35
  Pic.serialize = (props: PicProps) => {
33
36
  return { pic: props.src }
34
37
  }
@@ -4,6 +4,7 @@ import styled from 'styled-components'
4
4
  import { COLORS, WEBCHAT } from '../constants'
5
5
  import { renderComponent } from '../util/react'
6
6
  import { WebchatContext } from '../webchat/context'
7
+ import { COMPONENT_DISPLAY_NAMES } from './constants'
7
8
  import { ReplyProps } from './index-types'
8
9
 
9
10
  const StyledButton = styled.button`
@@ -67,6 +68,8 @@ export const Reply = (props: ReplyProps) => {
67
68
  return renderComponent({ renderBrowser, renderNode })
68
69
  }
69
70
 
71
+ Reply.displayName = COMPONENT_DISPLAY_NAMES.Reply
72
+
70
73
  Reply.serialize = (replyProps: ReplyProps) => {
71
74
  let payload = replyProps.payload
72
75
  if (replyProps.path) payload = `__PATH_PAYLOAD__${replyProps.path}`
@@ -3,6 +3,7 @@ import styled from 'styled-components'
3
3
 
4
4
  import { COLORS } from '../constants'
5
5
  import { renderComponent } from '../util/react'
6
+ import { COMPONENT_DISPLAY_NAMES } from './constants'
6
7
 
7
8
  const SubtitleContainer = styled.div`
8
9
  font-size: 12px;
@@ -24,6 +25,8 @@ export const Subtitle = (props: SubtitleProps) => {
24
25
  return renderComponent({ renderBrowser, renderNode })
25
26
  }
26
27
 
28
+ Subtitle.displayName = COMPONENT_DISPLAY_NAMES.Subtitle
29
+
27
30
  Subtitle.serialize = (props: SubtitleProps) => {
28
31
  return { subtitle: props.children }
29
32
  }
@@ -2,6 +2,7 @@ import { INPUT } from '@botonic/core'
2
2
  import React, { Children } from 'react'
3
3
 
4
4
  import { mapObjectNonBooleanValues } from '../util/react'
5
+ import { COMPONENT_DISPLAY_NAMES } from './constants'
5
6
  import { TextProps } from './index-types'
6
7
  import { serializeMarkdown, toMarkdownChildren } from './markdown'
7
8
  import { Message } from './message'
@@ -53,4 +54,6 @@ export const Text = (props: TextProps) => {
53
54
  )
54
55
  }
55
56
 
57
+ Text.displayName = COMPONENT_DISPLAY_NAMES.Text
58
+
56
59
  Text.serialize = serialize
@@ -2,6 +2,7 @@ import React from 'react'
2
2
  import styled from 'styled-components'
3
3
 
4
4
  import { renderComponent } from '../util/react'
5
+ import { COMPONENT_DISPLAY_NAMES } from './constants'
5
6
 
6
7
  const TitleContainer = styled.div`
7
8
  font-size: 14px;
@@ -19,6 +20,8 @@ export const Title = (props: TitleProps) => {
19
20
  return renderComponent({ renderBrowser, renderNode })
20
21
  }
21
22
 
23
+ Title.displayName = COMPONENT_DISPLAY_NAMES.Title
24
+
22
25
  Title.serialize = (props: TitleProps) => {
23
26
  return { title: props.children }
24
27
  }
@@ -1,91 +0,0 @@
1
- import { Button } from '../button/index'
2
- import { Carousel } from '../carousel'
3
- import { Pic } from '../pic'
4
- import { Reply } from '../reply'
5
- import { Subtitle } from '../subtitle'
6
- import { Text } from '../text'
7
- import { Title } from '../title'
8
- import { MultichannelButton } from './multichannel-button'
9
- import { MultichannelReply } from './multichannel-reply'
10
-
11
- function isNodeKind(node, kind) {
12
- return node?.type?.name === kind
13
- }
14
-
15
- export function isMultichannelButton(node) {
16
- return isNodeKind(node, MultichannelButton.name)
17
- }
18
-
19
- export function isMultichannelReply(node) {
20
- return isNodeKind(node, MultichannelReply.name)
21
- }
22
-
23
- export function isNodeText(node) {
24
- return isNodeKind(node, Text.name)
25
- }
26
-
27
- export function isNodeButton(node) {
28
- return isNodeKind(node, Button.name)
29
- }
30
-
31
- export function isNodeCarousel(node) {
32
- return isNodeKind(node, Carousel.name)
33
- }
34
-
35
- export function isNodeReply(node) {
36
- return isNodeKind(node, Reply.name)
37
- }
38
-
39
- export function isNodePic(node) {
40
- return isNodeKind(node, Pic.name)
41
- }
42
-
43
- export function isNodeTitle(node) {
44
- return isNodeKind(node, Title.name)
45
- }
46
-
47
- export function isNodeSubtitle(node) {
48
- return isNodeKind(node, Subtitle.name)
49
- }
50
-
51
- export function elementHasUrl(element) {
52
- return element?.props?.url
53
- }
54
-
55
- export function elementHasPostback(element) {
56
- return element?.props?.payload || element?.props?.path
57
- }
58
-
59
- export function elementHasWebview(element) {
60
- return element?.props?.webview
61
- }
62
-
63
- export const buttonTypes = {
64
- POSTBACK: 'postback',
65
- URL: 'url',
66
- WEBVIEW: 'webview',
67
- }
68
-
69
- export function getButtonType(multichannelButton) {
70
- if (elementHasUrl(multichannelButton)) return buttonTypes.URL
71
- if (elementHasPostback(multichannelButton)) return buttonTypes.POSTBACK
72
- if (elementHasWebview(multichannelButton)) return buttonTypes.WEBVIEW
73
-
74
- return undefined
75
- }
76
-
77
- export function getFilteredElements(node, filter) {
78
- const elements = []
79
- for (const n of node) {
80
- if (filter(n)) elements.push(n)
81
- }
82
- return elements
83
- }
84
-
85
- export function getMultichannelButtons(node) {
86
- return getFilteredElements(node, isMultichannelButton)
87
- }
88
-
89
- export function getMultichannelReplies(node) {
90
- return getFilteredElements(node, isMultichannelReply)
91
- }