@botonic/react 0.22.0-alpha.1 → 0.22.0-beta.0

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 (306) hide show
  1. package/lib/cjs/botonic-tester.js +4 -6
  2. package/lib/cjs/botonic-tester.js.map +1 -1
  3. package/lib/cjs/components/audio.js +3 -7
  4. package/lib/cjs/components/audio.js.map +1 -1
  5. package/lib/cjs/components/button.js +7 -18
  6. package/lib/cjs/components/button.js.map +1 -1
  7. package/lib/cjs/components/carousel.d.ts +1 -1
  8. package/lib/cjs/components/carousel.js +6 -19
  9. package/lib/cjs/components/carousel.js.map +1 -1
  10. package/lib/cjs/components/custom-message.d.ts +3 -34
  11. package/lib/cjs/components/custom-message.js +4 -10
  12. package/lib/cjs/components/custom-message.js.map +1 -1
  13. package/lib/cjs/components/document.js +3 -6
  14. package/lib/cjs/components/document.js.map +1 -1
  15. package/lib/cjs/components/element.js +3 -2
  16. package/lib/cjs/components/element.js.map +1 -1
  17. package/lib/cjs/components/handoff.js +3 -7
  18. package/lib/cjs/components/handoff.js.map +1 -1
  19. package/lib/cjs/components/image.js +3 -7
  20. package/lib/cjs/components/image.js.map +1 -1
  21. package/lib/cjs/components/index-types.d.ts +174 -0
  22. package/lib/cjs/components/index-types.js +17 -0
  23. package/lib/cjs/components/index-types.js.map +1 -0
  24. package/lib/cjs/components/index.d.ts +22 -20
  25. package/lib/cjs/components/index.js +4 -1
  26. package/lib/cjs/components/index.js.map +1 -1
  27. package/lib/cjs/components/location.js +3 -9
  28. package/lib/cjs/components/location.js.map +1 -1
  29. package/lib/cjs/components/message-template.js +2 -3
  30. package/lib/cjs/components/message-template.js.map +1 -1
  31. package/lib/cjs/components/message.js +9 -27
  32. package/lib/cjs/components/message.js.map +1 -1
  33. package/lib/cjs/components/multichannel/index-types.d.ts +45 -0
  34. package/lib/cjs/components/multichannel/index-types.js +3 -0
  35. package/lib/cjs/components/multichannel/index-types.js.map +1 -0
  36. package/lib/cjs/components/multichannel/index.d.ts +11 -6
  37. package/lib/cjs/components/multichannel/index.js +2 -0
  38. package/lib/cjs/components/multichannel/index.js.map +1 -1
  39. package/lib/cjs/components/multichannel/multichannel-button.js +4 -5
  40. package/lib/cjs/components/multichannel/multichannel-button.js.map +1 -1
  41. package/lib/cjs/components/multichannel/multichannel-carousel.js +3 -20
  42. package/lib/cjs/components/multichannel/multichannel-carousel.js.map +1 -1
  43. package/lib/cjs/components/multichannel/multichannel-context.d.ts +1 -1
  44. package/lib/cjs/components/multichannel/multichannel-reply.js +2 -1
  45. package/lib/cjs/components/multichannel/multichannel-reply.js.map +1 -1
  46. package/lib/cjs/components/multichannel/multichannel-text.d.ts +1 -1
  47. package/lib/cjs/components/multichannel/multichannel-text.js +10 -25
  48. package/lib/cjs/components/multichannel/multichannel-text.js.map +1 -1
  49. package/lib/cjs/components/multichannel/multichannel.js +16 -28
  50. package/lib/cjs/components/multichannel/multichannel.js.map +1 -1
  51. package/lib/cjs/components/pic.js +3 -2
  52. package/lib/cjs/components/pic.js.map +1 -1
  53. package/lib/cjs/components/raw.js +3 -12
  54. package/lib/cjs/components/raw.js.map +1 -1
  55. package/lib/cjs/components/reply.js +5 -8
  56. package/lib/cjs/components/reply.js.map +1 -1
  57. package/lib/cjs/components/share-button.js +2 -3
  58. package/lib/cjs/components/share-button.js.map +1 -1
  59. package/lib/cjs/components/subtitle.js +3 -4
  60. package/lib/cjs/components/subtitle.js.map +1 -1
  61. package/lib/cjs/components/text.js +3 -6
  62. package/lib/cjs/components/text.js.map +1 -1
  63. package/lib/cjs/components/timestamps.js +2 -5
  64. package/lib/cjs/components/timestamps.js.map +1 -1
  65. package/lib/cjs/components/title.js +3 -2
  66. package/lib/cjs/components/title.js.map +1 -1
  67. package/lib/cjs/components/video.js +3 -6
  68. package/lib/cjs/components/video.js.map +1 -1
  69. package/lib/cjs/components/webchat-settings.js +2 -1
  70. package/lib/cjs/components/webchat-settings.js.map +1 -1
  71. package/lib/cjs/components/whatsapp-template.js +3 -4
  72. package/lib/cjs/components/whatsapp-template.js.map +1 -1
  73. package/lib/cjs/contexts.d.ts +2 -3
  74. package/lib/cjs/contexts.js +3 -4
  75. package/lib/cjs/contexts.js.map +1 -1
  76. package/lib/cjs/dev-app.d.ts +2 -2
  77. package/lib/cjs/dev-app.js +2 -1
  78. package/lib/cjs/dev-app.js.map +1 -1
  79. package/lib/cjs/index-types.d.ts +96 -0
  80. package/lib/cjs/index-types.js +12 -0
  81. package/lib/cjs/index-types.js.map +1 -0
  82. package/lib/cjs/index.d.ts +7 -10
  83. package/lib/cjs/index.js +6 -10
  84. package/lib/cjs/index.js.map +1 -1
  85. package/lib/cjs/message-utils.d.ts +1 -1
  86. package/lib/cjs/msg-to-botonic.d.ts +1 -1
  87. package/lib/cjs/msg-to-botonic.js +24 -46
  88. package/lib/cjs/msg-to-botonic.js.map +1 -1
  89. package/lib/cjs/node-app.d.ts +1 -1
  90. package/lib/cjs/react-bot.d.ts +1 -1
  91. package/lib/cjs/react-bot.js +3 -4
  92. package/lib/cjs/react-bot.js.map +1 -1
  93. package/lib/cjs/util/error-boundary.d.ts +6 -39
  94. package/lib/cjs/util/error-boundary.js +17 -30
  95. package/lib/cjs/util/error-boundary.js.map +1 -1
  96. package/lib/cjs/util/webchat.js.map +1 -1
  97. package/lib/cjs/webchat/components/attachment.js +7 -10
  98. package/lib/cjs/webchat/components/attachment.js.map +1 -1
  99. package/lib/cjs/webchat/components/common.js +2 -1
  100. package/lib/cjs/webchat/components/common.js.map +1 -1
  101. package/lib/cjs/webchat/components/conditional-animation.js +2 -3
  102. package/lib/cjs/webchat/components/conditional-animation.js.map +1 -1
  103. package/lib/cjs/webchat/components/emoji-picker.js +3 -12
  104. package/lib/cjs/webchat/components/emoji-picker.js.map +1 -1
  105. package/lib/cjs/webchat/components/persistent-menu.js +5 -19
  106. package/lib/cjs/webchat/components/persistent-menu.js.map +1 -1
  107. package/lib/cjs/webchat/components/send-button.js +2 -7
  108. package/lib/cjs/webchat/components/send-button.js.map +1 -1
  109. package/lib/cjs/webchat/components/typing-indicator.js +2 -5
  110. package/lib/cjs/webchat/components/typing-indicator.js.map +1 -1
  111. package/lib/cjs/webchat/devices/device-adapter.d.ts +2 -2
  112. package/lib/cjs/webchat/header.js +4 -14
  113. package/lib/cjs/webchat/header.js.map +1 -1
  114. package/lib/cjs/webchat/hooks.js +2 -1
  115. package/lib/cjs/webchat/hooks.js.map +1 -1
  116. package/lib/cjs/webchat/index-types.d.ts +55 -0
  117. package/lib/cjs/webchat/index-types.js +3 -0
  118. package/lib/cjs/webchat/index-types.js.map +1 -0
  119. package/lib/cjs/webchat/index.d.ts +4 -6
  120. package/lib/cjs/webchat/index.js +3 -3
  121. package/lib/cjs/webchat/index.js.map +1 -1
  122. package/lib/cjs/webchat/message-list.js +5 -12
  123. package/lib/cjs/webchat/message-list.js.map +1 -1
  124. package/lib/cjs/webchat/replies.js +2 -5
  125. package/lib/cjs/webchat/replies.js.map +1 -1
  126. package/lib/cjs/webchat/session-view.js +7 -30
  127. package/lib/cjs/webchat/session-view.js.map +1 -1
  128. package/lib/cjs/webchat/use-storage-state-hook.js +12 -2
  129. package/lib/cjs/webchat/use-storage-state-hook.js.map +1 -1
  130. package/lib/cjs/webchat/webchat-dev.d.ts +1 -1
  131. package/lib/cjs/webchat/webchat-dev.js +6 -10
  132. package/lib/cjs/webchat/webchat-dev.js.map +1 -1
  133. package/lib/cjs/webchat/webchat.d.ts +1 -1
  134. package/lib/cjs/webchat/webchat.js +43 -86
  135. package/lib/cjs/webchat/webchat.js.map +1 -1
  136. package/lib/cjs/webchat/webview.js +5 -13
  137. package/lib/cjs/webchat/webview.js.map +1 -1
  138. package/lib/cjs/webchat-app.d.ts +2 -2
  139. package/lib/cjs/webchat-app.js +2 -1
  140. package/lib/cjs/webchat-app.js.map +1 -1
  141. package/lib/cjs/webview-app.js +12 -13
  142. package/lib/cjs/webview-app.js.map +1 -1
  143. package/lib/esm/botonic-tester.js +4 -6
  144. package/lib/esm/botonic-tester.js.map +1 -1
  145. package/lib/esm/components/audio.js +3 -7
  146. package/lib/esm/components/audio.js.map +1 -1
  147. package/lib/esm/components/button.js +7 -18
  148. package/lib/esm/components/button.js.map +1 -1
  149. package/lib/esm/components/carousel.d.ts +2 -1
  150. package/lib/esm/components/carousel.js +6 -19
  151. package/lib/esm/components/carousel.js.map +1 -1
  152. package/lib/esm/components/custom-message.d.ts +3 -34
  153. package/lib/esm/components/custom-message.js +4 -10
  154. package/lib/esm/components/custom-message.js.map +1 -1
  155. package/lib/esm/components/document.js +3 -6
  156. package/lib/esm/components/document.js.map +1 -1
  157. package/lib/esm/components/element.js +3 -2
  158. package/lib/esm/components/element.js.map +1 -1
  159. package/lib/esm/components/handoff.js +3 -7
  160. package/lib/esm/components/handoff.js.map +1 -1
  161. package/lib/esm/components/image.js +3 -7
  162. package/lib/esm/components/image.js.map +1 -1
  163. package/lib/esm/components/index-types.d.ts +174 -0
  164. package/lib/esm/components/index-types.js +16 -0
  165. package/lib/esm/components/index-types.js.map +1 -0
  166. package/lib/esm/components/index.d.ts +22 -19
  167. package/lib/esm/components/index.js +2 -0
  168. package/lib/esm/components/index.js.map +1 -1
  169. package/lib/esm/components/location.js +3 -9
  170. package/lib/esm/components/location.js.map +1 -1
  171. package/lib/esm/components/message-template.js +2 -3
  172. package/lib/esm/components/message-template.js.map +1 -1
  173. package/lib/esm/components/message.js +9 -27
  174. package/lib/esm/components/message.js.map +1 -1
  175. package/lib/esm/components/multichannel/index-types.d.ts +45 -0
  176. package/lib/esm/components/multichannel/index-types.js +2 -0
  177. package/lib/esm/components/multichannel/index-types.js.map +1 -0
  178. package/lib/esm/components/multichannel/index.d.ts +11 -6
  179. package/lib/esm/components/multichannel/index.js +1 -0
  180. package/lib/esm/components/multichannel/index.js.map +1 -1
  181. package/lib/esm/components/multichannel/multichannel-button.js +4 -5
  182. package/lib/esm/components/multichannel/multichannel-button.js.map +1 -1
  183. package/lib/esm/components/multichannel/multichannel-carousel.js +3 -20
  184. package/lib/esm/components/multichannel/multichannel-carousel.js.map +1 -1
  185. package/lib/esm/components/multichannel/multichannel-context.d.ts +1 -1
  186. package/lib/esm/components/multichannel/multichannel-reply.js +2 -1
  187. package/lib/esm/components/multichannel/multichannel-reply.js.map +1 -1
  188. package/lib/esm/components/multichannel/multichannel-text.d.ts +1 -1
  189. package/lib/esm/components/multichannel/multichannel-text.js +10 -25
  190. package/lib/esm/components/multichannel/multichannel-text.js.map +1 -1
  191. package/lib/esm/components/multichannel/multichannel.js +11 -23
  192. package/lib/esm/components/multichannel/multichannel.js.map +1 -1
  193. package/lib/esm/components/pic.js +3 -2
  194. package/lib/esm/components/pic.js.map +1 -1
  195. package/lib/esm/components/raw.js +3 -12
  196. package/lib/esm/components/raw.js.map +1 -1
  197. package/lib/esm/components/reply.js +5 -8
  198. package/lib/esm/components/reply.js.map +1 -1
  199. package/lib/esm/components/share-button.js +2 -3
  200. package/lib/esm/components/share-button.js.map +1 -1
  201. package/lib/esm/components/subtitle.js +3 -4
  202. package/lib/esm/components/subtitle.js.map +1 -1
  203. package/lib/esm/components/text.js +3 -6
  204. package/lib/esm/components/text.js.map +1 -1
  205. package/lib/esm/components/timestamps.js +2 -5
  206. package/lib/esm/components/timestamps.js.map +1 -1
  207. package/lib/esm/components/title.js +3 -2
  208. package/lib/esm/components/title.js.map +1 -1
  209. package/lib/esm/components/video.js +3 -6
  210. package/lib/esm/components/video.js.map +1 -1
  211. package/lib/esm/components/webchat-settings.js +2 -1
  212. package/lib/esm/components/webchat-settings.js.map +1 -1
  213. package/lib/esm/components/whatsapp-template.js +3 -4
  214. package/lib/esm/components/whatsapp-template.js.map +1 -1
  215. package/lib/esm/contexts.d.ts +2 -3
  216. package/lib/esm/contexts.js +3 -3
  217. package/lib/esm/contexts.js.map +1 -1
  218. package/lib/esm/dev-app.d.ts +2 -2
  219. package/lib/esm/dev-app.js +2 -1
  220. package/lib/esm/dev-app.js.map +1 -1
  221. package/lib/esm/index-types.d.ts +96 -0
  222. package/lib/esm/index-types.js +9 -0
  223. package/lib/esm/index-types.js.map +1 -0
  224. package/lib/esm/index.d.ts +7 -9
  225. package/lib/esm/index.js +5 -4
  226. package/lib/esm/index.js.map +1 -1
  227. package/lib/esm/message-utils.d.ts +2 -1
  228. package/lib/esm/msg-to-botonic.d.ts +1 -1
  229. package/lib/esm/msg-to-botonic.js +23 -45
  230. package/lib/esm/msg-to-botonic.js.map +1 -1
  231. package/lib/esm/node-app.d.ts +4 -4
  232. package/lib/esm/react-bot.d.ts +2 -1
  233. package/lib/esm/react-bot.js +3 -4
  234. package/lib/esm/react-bot.js.map +1 -1
  235. package/lib/esm/util/error-boundary.d.ts +6 -39
  236. package/lib/esm/util/error-boundary.js +17 -30
  237. package/lib/esm/util/error-boundary.js.map +1 -1
  238. package/lib/esm/util/webchat.js.map +1 -1
  239. package/lib/esm/webchat/components/attachment.js +8 -11
  240. package/lib/esm/webchat/components/attachment.js.map +1 -1
  241. package/lib/esm/webchat/components/common.js +2 -1
  242. package/lib/esm/webchat/components/common.js.map +1 -1
  243. package/lib/esm/webchat/components/conditional-animation.js +2 -3
  244. package/lib/esm/webchat/components/conditional-animation.js.map +1 -1
  245. package/lib/esm/webchat/components/emoji-picker.js +3 -12
  246. package/lib/esm/webchat/components/emoji-picker.js.map +1 -1
  247. package/lib/esm/webchat/components/persistent-menu.js +5 -19
  248. package/lib/esm/webchat/components/persistent-menu.js.map +1 -1
  249. package/lib/esm/webchat/components/send-button.js +2 -7
  250. package/lib/esm/webchat/components/send-button.js.map +1 -1
  251. package/lib/esm/webchat/components/typing-indicator.js +2 -5
  252. package/lib/esm/webchat/components/typing-indicator.js.map +1 -1
  253. package/lib/esm/webchat/devices/device-adapter.d.ts +2 -2
  254. package/lib/esm/webchat/header.js +4 -14
  255. package/lib/esm/webchat/header.js.map +1 -1
  256. package/lib/esm/webchat/hooks.js +2 -1
  257. package/lib/esm/webchat/hooks.js.map +1 -1
  258. package/lib/esm/webchat/index-types.d.ts +55 -0
  259. package/lib/esm/webchat/index-types.js +2 -0
  260. package/lib/esm/webchat/index-types.js.map +1 -0
  261. package/lib/esm/webchat/index.d.ts +4 -6
  262. package/lib/esm/webchat/index.js +2 -3
  263. package/lib/esm/webchat/index.js.map +1 -1
  264. package/lib/esm/webchat/message-list.js +5 -12
  265. package/lib/esm/webchat/message-list.js.map +1 -1
  266. package/lib/esm/webchat/replies.js +2 -5
  267. package/lib/esm/webchat/replies.js.map +1 -1
  268. package/lib/esm/webchat/session-view.js +7 -30
  269. package/lib/esm/webchat/session-view.js.map +1 -1
  270. package/lib/esm/webchat/use-storage-state-hook.js +12 -2
  271. package/lib/esm/webchat/use-storage-state-hook.js.map +1 -1
  272. package/lib/esm/webchat/webchat-dev.d.ts +1 -1
  273. package/lib/esm/webchat/webchat-dev.js +6 -10
  274. package/lib/esm/webchat/webchat-dev.js.map +1 -1
  275. package/lib/esm/webchat/webchat.d.ts +1 -1
  276. package/lib/esm/webchat/webchat.js +43 -86
  277. package/lib/esm/webchat/webchat.js.map +1 -1
  278. package/lib/esm/webchat/webview.js +5 -13
  279. package/lib/esm/webchat/webview.js.map +1 -1
  280. package/lib/esm/webchat-app.d.ts +5 -4
  281. package/lib/esm/webchat-app.js +2 -1
  282. package/lib/esm/webchat-app.js.map +1 -1
  283. package/lib/esm/webview-app.js +5 -6
  284. package/lib/esm/webview-app.js.map +1 -1
  285. package/package.json +21 -15
  286. package/src/components/{index.d.ts → index-types.ts} +22 -43
  287. package/src/components/{index.js → index.ts} +2 -0
  288. package/src/components/message.jsx +4 -11
  289. package/src/components/multichannel/{index.d.ts → index-types.ts} +1 -10
  290. package/src/components/multichannel/{index.js → index.ts} +2 -0
  291. package/src/components/multichannel/multichannel-text.jsx +2 -5
  292. package/src/contexts.jsx +3 -3
  293. package/src/index-types.ts +190 -0
  294. package/src/{index.js → index.ts} +5 -4
  295. package/src/msg-to-botonic.jsx +11 -11
  296. package/src/util/error-boundary.jsx +15 -30
  297. package/src/util/webchat.js +12 -13
  298. package/src/webchat/components/attachment.jsx +10 -2
  299. package/src/webchat/components/emoji-picker.jsx +7 -1
  300. package/src/webchat/hooks.js +2 -1
  301. package/src/webchat/{index.d.ts → index-types.ts} +5 -10
  302. package/src/webchat/{index.js → index.ts} +3 -3
  303. package/src/webchat/use-storage-state-hook.js +13 -2
  304. package/src/webchat/webchat.jsx +5 -7
  305. package/src/webview-app.tsx +1 -1
  306. package/src/index.d.ts +0 -238
package/package.json CHANGED
@@ -1,23 +1,25 @@
1
1
  {
2
2
  "name": "@botonic/react",
3
- "version": "0.22.0-alpha.1",
3
+ "version": "0.22.0-beta.0",
4
4
  "license": "MIT",
5
5
  "description": "Build Chatbots using React",
6
6
  "main": "./lib/cjs",
7
7
  "module": "./lib/esm",
8
8
  "types": "./lib/cjs/index.d.ts",
9
9
  "scripts": {
10
- "test": "../../node_modules/.bin/jest --coverage",
10
+ "test:no-coverage": "./node_modules/.bin/jest --env=jsdom",
11
+ "test": "./node_modules/.bin/jest --env=jsdom --coverage",
11
12
  "cloc": "../../scripts/qa/cloc-package.sh .",
12
13
  "prepublishOnly": "npm run clean; npm run build; npm run copy-files;",
13
14
  "prepare": "node ../../preinstall.js;",
14
- "clean": "rimraf ./lib/",
15
+ "clean": "rm -rf ./lib/",
15
16
  "copy-files": "copyfiles -u 1 src/**/*.svg src/**/*.png src/**/*.scss src/**/*.html lib/esm/; copyfiles -u 1 src/**/*.svg src/**/*.png src/**/*.scss src/**/*.html lib/cjs/;",
16
- "build": "../../node_modules/.bin/tsc -p tsconfig.json && ../../node_modules/.bin/tsc -p tsconfig.esm.json",
17
+ "build": "./node_modules/.bin/tsc -p tsconfig.json && ./node_modules/.bin/tsc -p tsconfig.esm.json",
17
18
  "build:watch": "npm run build -- --watch",
18
- "lint": "npm run lint_core -- --fix",
19
+ "prettier": "../../node_modules/.bin/prettier --no-error-on-unmatched-pattern --write '**/*.md' '**/*.css' '.*.js' '*.js{,on}'",
20
+ "lint": "npm run prettier; npm run lint_core -- --fix",
19
21
  "lint_ci": "npm run lint_core",
20
- "lint_core": "../../node_modules/.bin/eslint_d --cache --quiet '.*.js' '*.js' 'src/**/*.js*' 'src/**/*.d.ts' 'tests/**/*.js' 'tests/**/*.jsx'"
22
+ "lint_core": "../../node_modules/.bin/eslint_d --cache --quiet '.*.js' '*.js' 'src/**/*.js*' 'src/**/*.d.ts' --fix"
21
23
  },
22
24
  "sideEffects": [
23
25
  "*.scss",
@@ -35,14 +37,14 @@
35
37
  "dependencies": {
36
38
  "@botonic/core": "0.22.0-alpha.0",
37
39
  "axios": "^1.4.0",
38
- "emoji-picker-react": "^3.2.3",
40
+ "emoji-picker-react": "^4.4.9",
39
41
  "framer-motion": "^3.1.1",
40
42
  "he": "^1.2.0",
41
43
  "lodash.merge": "^4.6.2",
42
44
  "markdown-it": "^12.0.6",
43
45
  "qrcode.react": "^1.0.1",
44
- "react": "^16.14.0",
45
- "react-dom": "^16.14.0",
46
+ "react": "^17.0.0",
47
+ "react-dom": "^17.0.0",
46
48
  "react-frame-component": "^4.1.3",
47
49
  "react-json-tree": "^0.15.0",
48
50
  "react-reveal": "^1.2.2",
@@ -57,21 +59,25 @@
57
59
  "uuid": "^8.3.2"
58
60
  },
59
61
  "devDependencies": {
60
- "@babel/cli": "^7.21.0",
61
- "@babel/core": "^7.21.4",
62
+ "@babel/cli": "^7.21.5",
63
+ "@babel/core": "^7.21.8",
62
64
  "@babel/plugin-proposal-class-properties": "^7.18.6",
63
65
  "@babel/plugin-proposal-object-rest-spread": "^7.20.7",
64
66
  "@babel/plugin-transform-runtime": "^7.21.4",
65
- "@babel/preset-env": "^7.21.4",
67
+ "@babel/preset-env": "^7.21.5",
66
68
  "@babel/preset-react": "^7.18.6",
67
69
  "@testing-library/react": "^12.0.0",
68
- "@testing-library/react-hooks": "^7.0.0",
70
+ "@testing-library/react-hooks": "^8.0.1",
71
+ "@types/jest": "^29.5.1",
72
+ "@types/parse5": "^7.0.0",
69
73
  "@types/react": "17.0.27",
70
74
  "babel-plugin-add-module-exports": "^1.0.4",
71
75
  "copyfiles": "^2.4.1",
72
76
  "identity-obj-proxy": "^3.0.0",
73
- "react-test-renderer": "^16.14.0",
74
- "rimraf": "^5.0.0",
77
+ "jest": "^29.5.0",
78
+ "jest-environment-jsdom": "^29.5.0",
79
+ "react-test-renderer": "^17.0.0",
80
+ "ts-jest": "^29.1.0",
75
81
  "typescript": "^5.0.4"
76
82
  },
77
83
  "engines": {
@@ -1,7 +1,6 @@
1
- import * as React from 'react'
2
- import { ErrorInfo } from 'react'
1
+ import React, { ErrorInfo } from 'react'
3
2
 
4
- import { CoverComponentProps } from '../webchat'
3
+ import { CoverComponentProps } from '../webchat/index-types'
5
4
 
6
5
  export type MessageType =
7
6
  | 'audio'
@@ -26,18 +25,10 @@ export interface MessageProps {
26
25
  typing?: number
27
26
  }
28
27
 
29
- export const Audio: React.FunctionComponent<MessageProps>
30
- export const Document: React.FunctionComponent<MessageProps>
31
-
32
- export const Message: React.FunctionComponent<MessageProps>
33
- export type Message = React.FunctionComponent<MessageProps>
34
- export const Video: React.FunctionComponent<MessageProps>
35
-
36
28
  export interface TextProps extends MessageProps {
37
29
  // converts markdown syntax to HTML
38
30
  markdown?: boolean
39
31
  }
40
- export const Text: React.FunctionComponent<TextProps>
41
32
 
42
33
  export interface Webview {
43
34
  name: string
@@ -56,23 +47,16 @@ export interface ButtonProps {
56
47
  disabledstyle?: boolean
57
48
  }
58
49
 
59
- export const Button: React.FunctionComponent<ButtonProps>
60
-
61
50
  export interface ReplyProps {
62
51
  path?: string
63
52
  payload?: string
64
53
  children: string
65
54
  }
66
- export const Reply: React.FunctionComponent<ReplyProps>
67
- export type Reply = React.FunctionComponent<ReplyProps>
68
55
 
69
56
  export interface PicProps {
70
57
  src: string
71
58
  }
72
59
 
73
- export const Carousel: React.FunctionComponent<MessageProps>
74
- export const Image: React.FunctionComponent<ImageProps>
75
- export const Pic: React.FunctionComponent<PicProps>
76
60
  export type ImageProps = PicProps
77
61
 
78
62
  export interface TitleProps {
@@ -80,17 +64,14 @@ export interface TitleProps {
80
64
  style: string
81
65
  }
82
66
 
83
- export const Element: React.FunctionComponent<MessageProps>
84
- export const Subtitle: React.FunctionComponent<SubtitleProps>
85
- export const Title: React.FunctionComponent<TitleProps>
86
67
  export type SubtitleProps = TitleProps
87
68
 
88
- type CustomProp = { custom?: React.ComponentType }
89
- type EnableProp = { enable?: boolean }
90
- type ImageProp = { image?: string } // https URL or imported Image asset
91
- type PersistentMenuCloseOption = { closeLabel: string }
92
- type PersistentMenuOption = { label: string } & ButtonProps
93
- type StyleProp = { style?: any }
69
+ export type CustomProp = { custom?: React.ComponentType }
70
+ export type EnableProp = { enable?: boolean }
71
+ export type ImageProp = { image?: string } // https URL or imported Image asset
72
+ export type PersistentMenuCloseOption = { closeLabel: string }
73
+ export type PersistentMenuOption = { label: string } & ButtonProps
74
+ export type StyleProp = { style?: any }
94
75
 
95
76
  export type PersistentMenuTheme = (
96
77
  | PersistentMenuCloseOption
@@ -202,27 +183,25 @@ export interface WebchatSettingsProps {
202
183
  persistentMenu?: PersistentMenuTheme
203
184
  theme?: ThemeProps
204
185
  }
205
- export const WebchatSettings: React.FunctionComponent<WebchatSettingsProps>
206
186
 
207
187
  export type WrappedComponent<Props> = React.FunctionComponent<Props> & {
208
188
  customTypeName: string
209
189
  }
210
190
 
211
- export class ErrorBoundary<Props> extends React.Component<Props> {
212
- componentDidCatch(error: Error, errorInfo: ErrorInfo): void
213
- }
214
-
215
- export function createErrorBoundary<Props>(_?: {
216
- errorComponent: React.ComponentType
217
- }): ErrorBoundary<Props>
191
+ // TODO: Reuse types to be typed in respective functions
192
+ // export class ErrorBoundary<Props> extends React.Component<Props> {
193
+ // componentDidCatch(error: Error, errorInfo: ErrorInfo): void
194
+ // }
218
195
 
219
- export function customMessage<Props>(_: {
220
- name: string
221
- component: React.ComponentType<Props>
222
- defaultProps?: Record<string, unknown>
223
- errorBoundary?: ErrorBoundary<Props>
224
- }): WrappedComponent<Props>
196
+ // export function createErrorBoundary<Props>(_?: {
197
+ // errorComponent: React.ComponentType
198
+ // }): ErrorBoundary<Props>
225
199
 
226
- export function getDisplayName(component: React.ComponentType): string
200
+ // export function customMessage<Props>(_: {
201
+ // name: string
202
+ // component: React.ComponentType<Props>
203
+ // defaultProps?: Record<string, unknown>
204
+ // errorBoundary?: ErrorBoundary<Props>
205
+ // }): WrappedComponent<Props>
227
206
 
228
- export * from './multichannel'
207
+ // export function getDisplayName(component: React.ComponentType): string
@@ -5,7 +5,9 @@ export { customMessage } from './custom-message'
5
5
  export { Document } from './document'
6
6
  export { Element } from './element'
7
7
  export { Image } from './image'
8
+ export * from './index-types'
8
9
  export { Location } from './location'
10
+ export { Message } from './message'
9
11
  export { MessageTemplate } from './message-template'
10
12
  export * from './multichannel'
11
13
  export { Pic } from './pic'
@@ -85,12 +85,8 @@ export const Message = props => {
85
85
  const isFromUser = from === SENDERS.user
86
86
  const isFromBot = from === SENDERS.bot
87
87
  const markdown = props.markdown
88
- const {
89
- webchatState,
90
- addMessage,
91
- updateReplies,
92
- getThemeProperty,
93
- } = useContext(WebchatContext)
88
+ const { webchatState, addMessage, updateReplies, getThemeProperty } =
89
+ useContext(WebchatContext)
94
90
  const [state, setState] = useState({
95
91
  id: props.id || uuidv4(),
96
92
  })
@@ -114,11 +110,8 @@ export const Message = props => {
114
110
  typeof e === 'string' ? renderLinks(e) : e
115
111
  )
116
112
 
117
- const {
118
- timestampsEnabled,
119
- getFormattedTimestamp,
120
- timestampStyle,
121
- } = resolveMessageTimestamps(getThemeProperty, enabletimestamps)
113
+ const { timestampsEnabled, getFormattedTimestamp, timestampStyle } =
114
+ resolveMessageTimestamps(getThemeProperty, enabletimestamps)
122
115
 
123
116
  const getEnvAck = () => {
124
117
  if (isDev) return 1
@@ -1,6 +1,4 @@
1
- import * as React from 'react'
2
-
3
- type IndexMode = 'number' | 'letter' | undefined //undefined means no index
1
+ export type IndexMode = 'number' | 'letter' | undefined //undefined means no index
4
2
 
5
3
  export interface MultichannelViewOptions {
6
4
  boldIndex?: boolean
@@ -23,8 +21,6 @@ export interface MultichannelTextProps extends MultichannelViewOptions {
23
21
  buttonsTextSeparator?: string
24
22
  }
25
23
 
26
- export const MultichannelText: React.FunctionComponent<MultichannelTextProps>
27
-
28
24
  // Carousel
29
25
  export interface MultichannelCarouselProps extends MultichannelViewOptions {
30
26
  enableURL?: boolean
@@ -33,7 +29,6 @@ export interface MultichannelCarouselProps extends MultichannelViewOptions {
33
29
  showSubtitle?: boolean
34
30
  buttonsAsText?: boolean
35
31
  }
36
- export const MultichannelCarousel: React.FunctionComponent<MultichannelCarouselProps>
37
32
 
38
33
  // Button
39
34
  export interface MultichannelButtonProps {
@@ -44,10 +39,8 @@ export interface MultichannelButtonProps {
44
39
  webview?: string
45
40
  asText?: boolean
46
41
  }
47
- export const MultichannelButton: React.FunctionComponent<MultichannelButtonProps>
48
42
 
49
43
  // Reply
50
- export const MultichannelReply: React.FunctionComponent<MultichannelButtonProps>
51
44
 
52
45
  export interface MultichannelProps extends MultichannelViewOptions {
53
46
  firstIndex?: number | string
@@ -61,5 +54,3 @@ export interface MultichannelProps extends MultichannelViewOptions {
61
54
  **/
62
55
  messageSeparator?: string
63
56
  }
64
-
65
- export const Multichannel: React.FunctionComponent<MultichannelProps>
@@ -9,3 +9,5 @@ export { MultichannelText }
9
9
  export { MultichannelButton }
10
10
  export { MultichannelReply }
11
11
  export { MultichannelCarousel }
12
+
13
+ export * from './index-types'
@@ -194,11 +194,8 @@ export const MultichannelText = props => {
194
194
  if (isFacebook(requestContext)) {
195
195
  const text = getText(props.children)
196
196
  const multichannelFacebook = new MultichannelFacebook()
197
- const {
198
- texts,
199
- propsLastText,
200
- propsWithoutChildren,
201
- } = multichannelFacebook.convertText(props, text[0])
197
+ const { texts, propsLastText, propsWithoutChildren } =
198
+ multichannelFacebook.convertText(props, text[0])
202
199
  return (
203
200
  <>
204
201
  {texts &&
package/src/contexts.jsx CHANGED
@@ -1,8 +1,8 @@
1
- import React from 'react'
1
+ import { createContext } from 'react'
2
2
 
3
3
  import { webchatInitialState } from './webchat/hooks'
4
4
 
5
- export const RequestContext = React.createContext({
5
+ export const RequestContext = createContext({
6
6
  getString: () => '',
7
7
  setLocale: () => '',
8
8
  session: {},
@@ -12,7 +12,7 @@ export const RequestContext = React.createContext({
12
12
  defaultTyping: 0,
13
13
  })
14
14
 
15
- export const WebchatContext = React.createContext({
15
+ export const WebchatContext = createContext({
16
16
  sendText: text => {},
17
17
  sendAttachment: attachment => {},
18
18
  sendPayload: payload => {},
@@ -0,0 +1,190 @@
1
+ import * as core from '@botonic/core'
2
+ import React from 'react'
3
+
4
+ import {
5
+ ButtonProps,
6
+ ReplyProps,
7
+ ThemeProps,
8
+ WebchatSettingsProps,
9
+ Webview,
10
+ } from './components/index-types'
11
+ import { WebchatState } from './webchat'
12
+
13
+ /**
14
+ * See @botonic/core's Response for the description of the Response's semantics*/
15
+ export interface BotResponse extends core.BotRequest {
16
+ response: [React.ReactNode]
17
+ }
18
+
19
+ export interface Route extends core.Route {
20
+ action?: React.ComponentType<any>
21
+ retryAction?: React.ComponentType<any>
22
+ }
23
+ export type Routes = core.Routes<Route>
24
+
25
+ // Parameters of the actions' botonicInit method
26
+ export interface ActionRequest {
27
+ defaultDelay: number
28
+ defaultTyping: number
29
+ input: core.Input
30
+ lastRoutePath: string
31
+ params: { [key: string]: string }
32
+ plugins: { [id: string]: core.Plugin }
33
+ session: core.Session
34
+ }
35
+
36
+ export interface RequestContextInterface extends ActionRequest {
37
+ getString: (stringId: string) => string
38
+ setLocale: (locale: string) => string
39
+ }
40
+
41
+ export type RequestContext = React.Context<RequestContextInterface>
42
+
43
+ export interface CustomMessageType {
44
+ customTypeName: string
45
+ }
46
+
47
+ // TODO: Reuse types to be reused in respective components
48
+ // export class WebchatApp {
49
+ // constructor(options: WebchatAppArgs)
50
+ // addBotMessage(message: WebchatMessage): void
51
+ // addBotText(text: string): void
52
+ // addUserMessage(message: WebchatMessage): void
53
+ // addUserPayload(payload: string): void
54
+ // addUserText(text: string): void
55
+ // clearMessages(): void
56
+ // close(): void
57
+ // closeCoverComponent(): void
58
+ // destroy(): void
59
+ // getComponent(
60
+ // host: HTMLElement,
61
+ // optionsAtRuntime?: WebchatAppArgs
62
+ // ): React.ForwardRefExoticComponent<any>
63
+ // getLastMessageUpdate(): string
64
+ // getMessages(): WebchatMessage[]
65
+ // getVisibility(): Promise<boolean>
66
+ // isWebchatVisible({ appId: string }): Promise<boolean>
67
+ // onCloseWebchat(args: any): void
68
+ // onInitWebchat(args: any): void
69
+ // onOpenWebchat(args: any): void
70
+ // onServiceEvent(event: Event): void
71
+ // onStateChange(args: OnStateChangeArgs): void
72
+ // onUserInput(args: OnUserInputArgs): Promise<void>
73
+ // open(): void
74
+ // openCoverComponent(): void
75
+ // render(dest?: HTMLElement, optionsAtRuntime?: WebchatAppArgs): void
76
+ // resendUnsentInputs(): Promise<void>
77
+ // resolveWebchatVisibility(optionsAtRuntime: {
78
+ // appId: string
79
+ // visibility: () => boolean
80
+ // }): Promise<boolean>
81
+ // setTyping(enable: boolean): void
82
+ // toggle(): void
83
+ // toggleCoverComponent(): void
84
+ // updateMessageInfo(msgId: string, messageInfo: MessageInfo): void
85
+ // updateLastMessageDate(date: string): void
86
+ // updateUser(user: Partial<core.SessionUser>): void
87
+ // updateWebchatSettings(settings: WebchatSettingsProps): void
88
+ // renderCustomComponent(customComponent: React.ReactNode): void
89
+ // unmountCustomComponent(): void
90
+ // }
91
+
92
+ // export interface WebchatArgs {
93
+ // blockInputs?: BlockInputOption[]
94
+ // coverComponent?: CoverComponentOptions
95
+ // defaultDelay?: number
96
+ // defaultTyping?: number
97
+ // enableAnimations?: boolean
98
+ // enableAttachments?: boolean
99
+ // enableEmojiPicker?: boolean
100
+ // enableUserInput?: boolean
101
+ // shadowDOM?: boolean | (() => boolean)
102
+ // hostId?: string
103
+ // getString?: (stringId: string, session: core.Session) => string
104
+ // onClose?: (app: WebchatApp, args: any) => void
105
+ // onInit?: (app: WebchatApp, args: any) => void
106
+ // onMessage?: (app: WebchatApp, message: WebchatMessage) => void
107
+ // onOpen?: (app: WebchatApp, args: any) => void
108
+ // onConnectionChange?: (app: WebchatApp, isOnline: boolean) => void
109
+ // persistentMenu?: PersistentMenuTheme
110
+ // storage?: Storage | null
111
+ // storageKey?: any
112
+ // theme?: ThemeProps
113
+ // }
114
+
115
+ // export interface WebchatAppArgs extends WebchatArgs {
116
+ export interface WebchatAppArgs {
117
+ appId?: string
118
+ visibility?: () => boolean
119
+ }
120
+
121
+ export interface WebchatMessage {
122
+ ack: 0 | 1
123
+ buttons: ButtonProps[]
124
+ data: any
125
+ delay: number
126
+ display: boolean
127
+ from: 'user' | 'bot'
128
+ id: string
129
+ markdown: boolean
130
+ replies: ReplyProps[]
131
+ timestamp: string
132
+ type: core.InputType
133
+ typing: number
134
+ }
135
+
136
+ export interface OnUserInputArgs {
137
+ input: core.Input
138
+ lastRoutePath?: string
139
+ session?: core.Session
140
+ user: core.SessionUser
141
+ }
142
+
143
+ export interface OnStateChangeArgs {
144
+ messagesJSON: WebchatMessage[]
145
+ user: core.SessionUser
146
+ }
147
+
148
+ export interface MessageInfo {
149
+ data: any | 'typing_on'
150
+ id: string
151
+ type: 'update_webchat_settings' | 'sender_action'
152
+ }
153
+
154
+ export interface Event {
155
+ action?: 'update_message_info'
156
+ isError?: boolean
157
+ message?: MessageInfo
158
+ }
159
+
160
+ export interface WebchatContextProps {
161
+ sendText: (text: string, payload?: string) => void
162
+ sendAttachment: (attachment: File) => void
163
+ sendPayload: (payload: string) => void
164
+ sendInput: (input: core.Input) => void
165
+ openWebview: (webviewComponent: Webview) => void
166
+ addMessage: (message: WebchatMessage) => void
167
+ updateMessage: (message: WebchatMessage) => void
168
+ updateReplies: (replies: boolean) => void
169
+ updateLatestInput: (input: core.Input) => void
170
+ closeWebview: () => void
171
+ toggleWebchat: () => void
172
+ getThemeProperty: (property: string, defaultValue?: string) => any
173
+ resolveCase: () => void
174
+ theme: ThemeProps
175
+ webchatState: WebchatState
176
+ updateWebchatDevSettings: (settings: WebchatSettingsProps) => void
177
+ updateUser: (user: Partial<core.SessionUser>) => void
178
+ }
179
+
180
+ export type WebchatContext = React.Context<WebchatContextProps>
181
+
182
+ // export class DevApp extends WebchatApp {
183
+ // constructor(args: WebchatAppArgs)
184
+ // onUserInput(args: OnUserInputArgs): Promise<void>
185
+ // render(dest: HTMLElement, optionsAtRuntime: WebchatAppArgs): void
186
+ // }
187
+
188
+ export * from './components'
189
+ export * from './util'
190
+ export * from './webchat'
@@ -1,10 +1,11 @@
1
1
  export { BotonicInputTester, BotonicOutputTester } from './botonic-tester'
2
- export * from './components'
3
- export { RequestContext, WebchatContext } from './contexts'
2
+ // export * from './components'
3
+ // export { RequestContext, WebchatContext } from './contexts'
4
4
  export { DevApp } from './dev-app'
5
+ export * from './index-types'
5
6
  export { msgsToBotonic, msgToBotonic } from './msg-to-botonic'
6
7
  export { NodeApp } from './node-app'
7
- export { staticAsset } from './util/environment'
8
- export { getBotonicApp, Webchat } from './webchat/index.js'
8
+ // export { staticAsset } from './util/environment'
9
+ // export { getBotonicApp, Webchat } from './webchat/index'
9
10
  export { WebchatApp } from './webchat-app'
10
11
  export { WebviewApp } from './webview-app'
@@ -1,16 +1,5 @@
1
1
  import React from 'react'
2
2
 
3
- import {
4
- isAudio,
5
- isButtonMessage,
6
- isCarousel,
7
- isCustom,
8
- isDocument,
9
- isImage,
10
- isLocation,
11
- isText,
12
- isVideo,
13
- } from './message-utils'
14
3
  import { Audio } from './components/audio'
15
4
  import { Button } from './components/button'
16
5
  import { ButtonsDisabler } from './components/buttons-disabler'
@@ -25,6 +14,17 @@ import { Subtitle } from './components/subtitle'
25
14
  import { Text } from './components/text'
26
15
  import { Title } from './components/title'
27
16
  import { Video } from './components/video'
17
+ import {
18
+ isAudio,
19
+ isButtonMessage,
20
+ isCarousel,
21
+ isCustom,
22
+ isDocument,
23
+ isImage,
24
+ isLocation,
25
+ isText,
26
+ isVideo,
27
+ } from './message-utils'
28
28
 
29
29
  /**
30
30
  *
@@ -1,48 +1,33 @@
1
+ // @ts-nocheck
1
2
  import { isNode } from '@botonic/core'
2
- import React from 'react'
3
+ import React, { useState } from 'react'
3
4
 
4
5
  import { Text } from '../components/text'
5
6
 
6
- /**
7
- * Replaces crashed children with the provided fallback component.
8
- * https://reactjs.org/blog/2017/07/26/error-handling-in-react-16.html
9
- * See alternative at https://stackoverflow.com/a/60255291/145289
10
- */
11
7
  export const createErrorBoundary = ({
12
- errorComponent = props => <Text>The message cannot be displayed</Text>,
8
+ errorComponent = ({ errorMessage }) => (
9
+ <Text>The message cannot be displayed</Text>
10
+ ),
13
11
  } = {}) => {
14
- class ErrorBoundary extends React.Component {
15
- constructor(props) {
16
- super(props)
17
- this.state = { error: null }
18
- }
12
+ const ErrorBoundary = ({ children }) => {
13
+ const [error, setError] = useState(null)
19
14
 
20
- /**
21
- * @param error the exception which was trown
22
- * @param errorInfo the stack of component names at the error
23
- */
24
- componentDidCatch(error, errorInfo) {
25
- // No need to log the error because at least chrome & firefox already show
26
- // both component and call stacks
15
+ const componentDidCatch = (error, errorInfo) => {
27
16
  if (isNode()) {
28
- // In node, only the component stack is displayed
29
17
  console.error(`Failure at:`, error)
30
18
  }
31
19
  }
32
20
 
33
- static getDerivedStateFromError(error) {
21
+ const getDerivedStateFromError = error => {
34
22
  return { error }
35
23
  }
36
24
 
37
- render() {
38
- if (this.state.error) {
39
- return errorComponent({
40
- ...this.props,
41
- errorMessage: this.state.error.message,
42
- })
43
- } else {
44
- return this.props.children
45
- }
25
+ if (error) {
26
+ return errorComponent({
27
+ errorMessage: error.message,
28
+ })
29
+ } else {
30
+ return children
46
31
  }
47
32
  }
48
33
 
@@ -10,21 +10,20 @@ import { getProperty } from './objects'
10
10
  * It gives preference to nested defined properties (e.g.: header.style) over plain properties (e.g.: headerStyle).
11
11
  * If property doesn't exist, returns the defaultValue.
12
12
  */
13
- export const _getThemeProperty = theme => (
14
- property,
15
- defaultValue = undefined
16
- ) => {
17
- for (const [k, v] of Object.entries(WEBCHAT.CUSTOM_PROPERTIES)) {
18
- if (v == property) {
19
- const nestedProperty = getProperty(theme, v)
20
- if (nestedProperty !== undefined) return nestedProperty
21
- const plainProperty = getProperty(theme, k)
22
- if (plainProperty !== undefined) return plainProperty
23
- return defaultValue
13
+ export const _getThemeProperty =
14
+ theme =>
15
+ (property, defaultValue = undefined) => {
16
+ for (const [k, v] of Object.entries(WEBCHAT.CUSTOM_PROPERTIES)) {
17
+ if (v == property) {
18
+ const nestedProperty = getProperty(theme, v)
19
+ if (nestedProperty !== undefined) return nestedProperty
20
+ const plainProperty = getProperty(theme, k)
21
+ if (plainProperty !== undefined) return plainProperty
22
+ return defaultValue
23
+ }
24
24
  }
25
+ return undefined
25
26
  }
26
- return undefined
27
- }
28
27
 
29
28
  export const createUser = () => {
30
29
  const parser = new UAParser()