@botonic/react 0.20.1-alpha.1 → 0.20.3

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 (128) hide show
  1. package/lib/app.js +4 -3
  2. package/lib/app.js.map +1 -1
  3. package/lib/components/button.js +22 -2
  4. package/lib/components/button.js.map +1 -1
  5. package/lib/components/buttons-disabler.js +2 -2
  6. package/lib/components/carousel.js +2 -2
  7. package/lib/components/custom-message.js +2 -2
  8. package/lib/components/document.js +2 -2
  9. package/lib/components/image.js +28 -32
  10. package/lib/components/image.js.map +1 -1
  11. package/lib/components/message.js +2 -2
  12. package/lib/components/multichannel/facebook/facebook.js +2 -2
  13. package/lib/components/reply.js +2 -2
  14. package/lib/components/subtitle.js +2 -2
  15. package/lib/components/text.js +2 -2
  16. package/lib/components/timestamps.js +2 -2
  17. package/lib/components/title.js +2 -2
  18. package/lib/constants.js +201 -0
  19. package/lib/constants.js.map +1 -0
  20. package/lib/contexts.js +57 -0
  21. package/lib/contexts.js.map +1 -0
  22. package/lib/dev-app.js +241 -0
  23. package/lib/dev-app.js.map +1 -0
  24. package/lib/index.d.ts +241 -0
  25. package/lib/index.js +131 -0
  26. package/lib/index.js.map +1 -0
  27. package/lib/message-utils.js +149 -0
  28. package/lib/message-utils.js.map +1 -0
  29. package/lib/msg-to-botonic.js +199 -0
  30. package/lib/msg-to-botonic.js.map +1 -0
  31. package/lib/node-app.js +97 -0
  32. package/lib/node-app.js.map +1 -0
  33. package/lib/react-bot.js +167 -0
  34. package/lib/react-bot.js.map +1 -0
  35. package/lib/util/dom.js +84 -0
  36. package/lib/util/dom.js.map +1 -0
  37. package/lib/util/environment.js +42 -0
  38. package/lib/util/environment.js.map +1 -0
  39. package/lib/util/error-boundary.js +105 -0
  40. package/lib/util/error-boundary.js.map +1 -0
  41. package/lib/util/index.d.ts +9 -0
  42. package/lib/util/index.js +2 -0
  43. package/lib/util/index.js.map +1 -0
  44. package/lib/util/logs.js +28 -0
  45. package/lib/util/logs.js.map +1 -0
  46. package/lib/util/objects.js +60 -0
  47. package/lib/util/objects.js.map +1 -0
  48. package/lib/util/react.js +75 -0
  49. package/lib/util/react.js.map +1 -0
  50. package/lib/util/regexs.js +31 -0
  51. package/lib/util/regexs.js.map +1 -0
  52. package/lib/util/webchat.js +92 -0
  53. package/lib/util/webchat.js.map +1 -0
  54. package/lib/webchat/actions.js +53 -0
  55. package/lib/webchat/actions.js.map +1 -0
  56. package/lib/webchat/components/attachment.js +43 -0
  57. package/lib/webchat/components/attachment.js.map +1 -0
  58. package/lib/webchat/components/common.js +33 -0
  59. package/lib/webchat/components/common.js.map +1 -0
  60. package/lib/webchat/components/emoji-picker.js +58 -0
  61. package/lib/webchat/components/emoji-picker.js.map +1 -0
  62. package/lib/webchat/components/persistent-menu.js +96 -0
  63. package/lib/webchat/components/persistent-menu.js.map +1 -0
  64. package/lib/webchat/components/send-button.js +27 -0
  65. package/lib/webchat/components/send-button.js.map +1 -0
  66. package/lib/webchat/components/styled-scrollbar.js +55 -0
  67. package/lib/webchat/components/styled-scrollbar.js.map +1 -0
  68. package/lib/webchat/components/styled-scrollbar.scss +12 -0
  69. package/lib/webchat/components/typing-indicator.js +27 -0
  70. package/lib/webchat/components/typing-indicator.js.map +1 -0
  71. package/lib/webchat/components/typing-indicator.scss +38 -0
  72. package/lib/webchat/devices/device-adapter.js +82 -0
  73. package/lib/webchat/devices/device-adapter.js.map +1 -0
  74. package/lib/webchat/devices/index.js +32 -0
  75. package/lib/webchat/devices/index.js.map +1 -0
  76. package/lib/webchat/devices/scrollbar-controller.js +152 -0
  77. package/lib/webchat/devices/scrollbar-controller.js.map +1 -0
  78. package/lib/webchat/devices/webchat-resizer.js +76 -0
  79. package/lib/webchat/devices/webchat-resizer.js.map +1 -0
  80. package/lib/webchat/header.js +116 -0
  81. package/lib/webchat/header.js.map +1 -0
  82. package/lib/webchat/hooks.js +359 -0
  83. package/lib/webchat/hooks.js.map +1 -0
  84. package/lib/webchat/index.d.ts +62 -0
  85. package/lib/webchat/index.js +32 -0
  86. package/lib/webchat/index.js.map +1 -0
  87. package/lib/webchat/message-list.js +88 -0
  88. package/lib/webchat/message-list.js.map +1 -0
  89. package/lib/webchat/messages-reducer.js +93 -0
  90. package/lib/webchat/messages-reducer.js.map +1 -0
  91. package/lib/webchat/replies.js +78 -0
  92. package/lib/webchat/replies.js.map +1 -0
  93. package/lib/webchat/session-view.js +106 -0
  94. package/lib/webchat/session-view.js.map +1 -0
  95. package/lib/webchat/use-storage-state-hook.js +29 -0
  96. package/lib/webchat/use-storage-state-hook.js.map +1 -0
  97. package/lib/webchat/webchat-dev.js +109 -0
  98. package/lib/webchat/webchat-dev.js.map +1 -0
  99. package/lib/webchat/webchat-reducer.js +108 -0
  100. package/lib/webchat/webchat-reducer.js.map +1 -0
  101. package/lib/webchat/webchat.js +1059 -0
  102. package/lib/webchat/webchat.js.map +1 -0
  103. package/lib/webchat/webview.js +122 -0
  104. package/lib/webchat/webview.js.map +1 -0
  105. package/lib/webchat-app.js +653 -0
  106. package/lib/webchat-app.js.map +1 -0
  107. package/lib/webchat.template.html +37 -0
  108. package/lib/webview.js +214 -0
  109. package/lib/webview.js.map +1 -0
  110. package/lib/webview.template.html +39 -0
  111. package/package.json +2 -2
  112. package/src/components/button.jsx +21 -1
  113. package/src/components/image.jsx +22 -27
  114. package/src/components/index.d.ts +5 -1
  115. package/src/constants.js +1 -0
  116. package/src/index.d.ts +3 -7
  117. package/src/index.js +0 -1
  118. package/src/webchat/actions.jsx +1 -1
  119. package/src/webchat/hooks.js +5 -5
  120. package/src/webchat/webchat-reducer.js +3 -3
  121. package/src/webchat/webchat.jsx +20 -17
  122. package/src/webchat-app.jsx +4 -4
  123. package/src/webchat/components/portal-modal/backdrop.jsx +0 -38
  124. package/src/webchat/components/portal-modal/constants.js +0 -7
  125. package/src/webchat/components/portal-modal/content.jsx +0 -10
  126. package/src/webchat/components/portal-modal/index.js +0 -5
  127. package/src/webchat/components/portal-modal/portal-modal-component.jsx +0 -72
  128. package/src/webchat/components/portal-modal/portal.jsx +0 -21
@@ -47,7 +47,6 @@ import {
47
47
  initSession,
48
48
  shouldKeepSessionOnReload,
49
49
  } from '../util/webchat'
50
- import { PortalModalComponent } from '../webchat/components/portal-modal'
51
50
  import { Attachment } from './components/attachment'
52
51
  import { EmojiPicker, OpenedEmojiPicker } from './components/emoji-picker'
53
52
  import {
@@ -185,7 +184,7 @@ export const Webchat = forwardRef((props, ref) => {
185
184
  toggleEmojiPicker,
186
185
  togglePersistentMenu,
187
186
  toggleCoverComponent,
188
- toggleModal,
187
+ doRenderCustomComponent,
189
188
  setError,
190
189
  setOnline,
191
190
  clearMessages,
@@ -202,8 +201,7 @@ export const Webchat = forwardRef((props, ref) => {
202
201
  const { initialSession, initialDevSettings, onStateChange } = props
203
202
  const getThemeProperty = _getThemeProperty(theme)
204
203
 
205
- const [customModalContent, setCustomModalContent] = useState(undefined)
206
-
204
+ const [customComponent, setCustomComponent] = useState(null)
207
205
  const storage = props.storage === undefined ? localStorage : props.storage
208
206
  const storageKey =
209
207
  typeof props.storageKey === 'function'
@@ -407,9 +405,13 @@ export const Webchat = forwardRef((props, ref) => {
407
405
  )
408
406
 
409
407
  const getBlockInputs = (rule, inputData) => {
408
+ const processedInput = rule.preprocess
409
+ ? rule.preprocess(inputData)
410
+ : inputData
411
+
410
412
  return rule.match.some(regex => {
411
413
  if (typeof regex === 'string') regex = deserializeRegex(regex)
412
- return regex.test(inputData)
414
+ return regex.test(processedInput)
413
415
  })
414
416
  }
415
417
 
@@ -564,11 +566,11 @@ export const Webchat = forwardRef((props, ref) => {
564
566
  toggleWebchat: () => toggleWebchat(!webchatState.isWebchatOpen),
565
567
  openCoverComponent: () => toggleCoverComponent(true),
566
568
  closeCoverComponent: () => toggleCoverComponent(false),
567
- openModal: customModalContent => {
568
- setCustomModalContent(customModalContent)
569
- toggleModal(true)
569
+ renderCustomComponent: _customComponent => {
570
+ setCustomComponent(_customComponent)
571
+ doRenderCustomComponent(true)
570
572
  },
571
- closeModal: () => toggleModal(false),
573
+ unmountCustomComponent: () => doRenderCustomComponent(false),
572
574
  toggleCoverComponent: () =>
573
575
  toggleCoverComponent(!webchatState.isCoverComponentOpen),
574
576
  openWebviewApi: component => openWebviewT(component),
@@ -896,6 +898,11 @@ export const Webchat = forwardRef((props, ref) => {
896
898
  )
897
899
  }
898
900
 
901
+ const _renderCustomComponent = () => {
902
+ if (!customComponent) return <></>
903
+ else return customComponent
904
+ }
905
+
899
906
  const WebchatComponent = (
900
907
  <WebchatContext.Provider
901
908
  value={{
@@ -926,6 +933,7 @@ export const Webchat = forwardRef((props, ref) => {
926
933
  {triggerButton()}
927
934
  </div>
928
935
  )}
936
+
929
937
  {webchatState.isWebchatOpen && (
930
938
  <StyledWebchat
931
939
  // TODO: Distinguis between multiple instances of webchat, e.g. `${uniqueId}-botonic-webchat`
@@ -958,14 +966,9 @@ export const Webchat = forwardRef((props, ref) => {
958
966
  {!webchatState.handoff && userInputArea()}
959
967
  {webchatState.webview && webchatWebview()}
960
968
  {webchatState.isCoverComponentOpen && coverComponent()}
961
- {webchatState.isModalOpen && (
962
- <PortalModalComponent
963
- open={webchatState.isModalOpen}
964
- onClose={() => toggleModal(false)}
965
- locked={false}
966
- customContent={customModalContent}
967
- />
968
- )}
969
+ {webchatState.isCustomComponentRendered &&
970
+ customComponent &&
971
+ _renderCustomComponent()}
969
972
  </StyledWebchat>
970
973
  )}
971
974
  </WebchatContext.Provider>
@@ -211,12 +211,12 @@ export class WebchatApp {
211
211
  this.webchatRef.current.closeCoverComponent()
212
212
  }
213
213
 
214
- openModal(customModalContent) {
215
- this.webchatRef.current.openModal(customModalContent)
214
+ renderCustomComponent(_customComponent) {
215
+ this.webchatRef.current.renderCustomComponent(_customComponent)
216
216
  }
217
217
 
218
- closeModal() {
219
- this.webchatRef.current.closeModal()
218
+ unmountCustomComponent() {
219
+ this.webchatRef.current.unmountCustomComponent()
220
220
  }
221
221
 
222
222
  toggleCoverComponent() {
@@ -1,38 +0,0 @@
1
- import styled from 'styled-components'
2
-
3
- import { MODAL_ACTIVE_CLASSNAME, MODAL_CONTENT_CLASSNAME } from './constants'
4
-
5
- export const Backdrop = styled.div`
6
- position: fixed;
7
- top: 0;
8
- right: 0;
9
- bottom: 0;
10
- left: 0;
11
- background-color: rgba(51, 51, 51, 0.3);
12
- backdrop-filter: blur(1px);
13
- opacity: 0;
14
- transition: all 100ms cubic-bezier(0.4, 0, 0.2, 1);
15
- transition-delay: 200ms;
16
- display: flex;
17
- align-items: center;
18
- justify-content: center;
19
-
20
- & .${MODAL_CONTENT_CLASSNAME} {
21
- transform: translateY(100px);
22
- transition: all 200ms cubic-bezier(0.4, 0, 0.2, 1);
23
- opacity: 0;
24
- }
25
-
26
- &.${MODAL_ACTIVE_CLASSNAME} {
27
- transition-duration: 250ms;
28
- transition-delay: 0ms;
29
- opacity: 1;
30
-
31
- & .${MODAL_CONTENT_CLASSNAME} {
32
- transform: translateY(0);
33
- opacity: 1;
34
- transition-delay: 150ms;
35
- transition-duration: 350ms;
36
- }
37
- }
38
- `
@@ -1,7 +0,0 @@
1
- // Portal
2
- export const BOTONIC_PORTAL_CLASS_LIST_NAME = 'botonic-portal-container'
3
-
4
- // Modal
5
- export const MODAL_PORTAL_CLASS_NAME = 'modal-portal'
6
- export const MODAL_CONTENT_CLASSNAME = 'modal-content'
7
- export const MODAL_ACTIVE_CLASSNAME = 'active'
@@ -1,10 +0,0 @@
1
- import styled from 'styled-components'
2
-
3
- export const ModalContent = styled.div`
4
- position: relative;
5
- padding: 4px;
6
- box-sizing: border-box;
7
- box-shadow: 0 3px 6px rgba(0, 0, 0, 0.16), 0 3px 6px rgba(0, 0, 0, 0.23);
8
- background-color: white;
9
- border-radius: 2px;
10
- `
@@ -1,5 +0,0 @@
1
- export * from './backdrop'
2
- export * from './constants'
3
- export * from './content'
4
- export * from './portal'
5
- export * from './portal-modal-component'
@@ -1,72 +0,0 @@
1
- import React, { useEffect, useRef, useState } from 'react'
2
-
3
- import { Backdrop } from './backdrop'
4
- import {
5
- MODAL_ACTIVE_CLASSNAME,
6
- MODAL_CONTENT_CLASSNAME,
7
- MODAL_PORTAL_CLASS_NAME,
8
- } from './constants'
9
- import { ModalContent } from './content'
10
- import { Portal } from './portal'
11
-
12
- const ESCAPE_KEY_CODE = 27
13
-
14
- export function PortalModalComponent({
15
- open,
16
- onClose,
17
- locked,
18
- children,
19
- customContent,
20
- }) {
21
- const [active, setActive] = useState(false)
22
-
23
- const backdrop = useRef(null)
24
-
25
- useEffect(() => {
26
- const { current } = backdrop
27
- const transitionEnd = () => setActive(open)
28
- const keyHandler = e =>
29
- !locked && [ESCAPE_KEY_CODE].indexOf(e.which) >= 0 && onClose()
30
- const clickHandler = e => !locked && e.target === current && onClose()
31
-
32
- if (current) {
33
- current.addEventListener('transitionend', transitionEnd)
34
- current.addEventListener('click', clickHandler)
35
- window.addEventListener('keyup', keyHandler)
36
- }
37
-
38
- if (open) {
39
- window.setTimeout(() => {
40
- document.activeElement.blur()
41
- setActive(open)
42
- }, 10)
43
- }
44
-
45
- return () => {
46
- if (current) {
47
- current.removeEventListener('transitionend', transitionEnd)
48
- current.removeEventListener('click', clickHandler)
49
- }
50
- window.removeEventListener('keyup', keyHandler)
51
- }
52
- }, [open, locked, onClose])
53
-
54
- return (
55
- (open || active) && (
56
- <Portal className={MODAL_PORTAL_CLASS_NAME}>
57
- <Backdrop
58
- ref={backdrop}
59
- className={active && open && MODAL_ACTIVE_CLASSNAME}
60
- >
61
- {customContent ? (
62
- customContent
63
- ) : (
64
- <ModalContent className={MODAL_CONTENT_CLASSNAME}>
65
- {children}
66
- </ModalContent>
67
- )}
68
- </Backdrop>
69
- </Portal>
70
- )
71
- )
72
- }
@@ -1,21 +0,0 @@
1
- import { useEffect, useMemo } from 'react'
2
- import { createPortal } from 'react-dom'
3
-
4
- import { BOTONIC_PORTAL_CLASS_LIST_NAME } from './constants'
5
-
6
- export function Portal({ children, parent, className }) {
7
- const element = useMemo(() => document.createElement('div'), [])
8
-
9
- useEffect(() => {
10
- const target = parent && parent.appendChild ? parent : document.body
11
- const classList = [BOTONIC_PORTAL_CLASS_LIST_NAME]
12
-
13
- if (className) className.split(' ').forEach(item => classList.push(item))
14
- classList.forEach(item => element.classList.add(item))
15
- target.appendChild(element)
16
-
17
- return () => target.removeChild(element)
18
- }, [element, parent, className])
19
-
20
- return createPortal(children, element)
21
- }