|
1 | | -import * as defaultAdaptiveCardsPackage from 'adaptivecards'; |
2 | | -import BasicWebChat, { concatMiddleware } from 'botframework-webchat-component'; |
| 1 | +import BasicWebChat from 'botframework-webchat-component'; |
3 | 2 | import PropTypes from 'prop-types'; |
4 | | -import React, { useEffect, useMemo } from 'react'; |
| 3 | +import React, { useEffect } from 'react'; |
5 | 4 |
|
6 | | -import AdaptiveCardsContext from './adaptiveCards/AdaptiveCardsContext'; |
7 | | -import createAdaptiveCardsAttachmentMiddleware from './adaptiveCards/createAdaptiveCardMiddleware'; |
8 | | -import createDefaultAdaptiveCardHostConfig from './adaptiveCards/Styles/adaptiveCardHostConfig'; |
9 | | -import createStyleSet from './adaptiveCards/Styles/createStyleSetWithAdaptiveCards'; |
10 | | -import defaultRenderMarkdown from './renderMarkdown'; |
| 5 | +import AdaptiveCardsComposer from './adaptiveCards/AdaptiveCardsComposer'; |
| 6 | +import useComposerProps from './useComposerProps'; |
11 | 7 |
|
12 | 8 | // Add additional props to <WebChat>, so it support additional features |
13 | | -const FullReactWebChat = ({ |
14 | | - adaptiveCardHostConfig, |
15 | | - adaptiveCardsHostConfig, |
16 | | - adaptiveCardsPackage, |
17 | | - attachmentMiddleware, |
18 | | - renderMarkdown, |
19 | | - styleOptions, |
20 | | - styleSet, |
21 | | - ...otherProps |
22 | | -}) => { |
| 9 | +const FullReactWebChat = props => { |
| 10 | + const { adaptiveCardHostConfig, adaptiveCardsHostConfig, adaptiveCardsPackage, ...otherProps } = props; |
| 11 | + |
23 | 12 | useEffect(() => { |
24 | 13 | adaptiveCardHostConfig && |
25 | 14 | console.warn( |
26 | 15 | 'Web Chat: "adaptiveCardHostConfig" is deprecated. Please use "adaptiveCardsHostConfig" instead. "adaptiveCardHostConfig" will be removed on or after 2022-01-01.' |
27 | 16 | ); |
28 | 17 | }, [adaptiveCardHostConfig]); |
29 | 18 |
|
30 | | - const patchedStyleSet = useMemo(() => styleSet || createStyleSet(styleOptions), [styleOptions, styleSet]); |
31 | | - const { options: patchedStyleOptions } = patchedStyleSet; |
32 | | - |
33 | | - const patchedAdaptiveCardsHostConfig = useMemo( |
34 | | - () => adaptiveCardsHostConfig || adaptiveCardHostConfig || createDefaultAdaptiveCardHostConfig(patchedStyleOptions), |
35 | | - [adaptiveCardHostConfig, adaptiveCardsHostConfig, patchedStyleOptions] |
36 | | - ); |
37 | | - |
38 | | - const patchedAdaptiveCardsPackage = useMemo(() => adaptiveCardsPackage || defaultAdaptiveCardsPackage, [ |
39 | | - adaptiveCardsPackage |
40 | | - ]); |
41 | | - |
42 | | - const patchedRenderMarkdown = useMemo( |
43 | | - () => renderMarkdown || (markdown => defaultRenderMarkdown(markdown, patchedStyleOptions)), |
44 | | - [renderMarkdown, patchedStyleOptions] |
45 | | - ); |
46 | | - |
47 | | - const patchedAttachmentMiddleware = useMemo( |
48 | | - () => concatMiddleware(attachmentMiddleware, createAdaptiveCardsAttachmentMiddleware()), |
49 | | - [attachmentMiddleware] |
50 | | - ); |
51 | | - |
52 | | - const adaptiveCardsContext = useMemo( |
53 | | - () => ({ |
54 | | - adaptiveCardsPackage: patchedAdaptiveCardsPackage, |
55 | | - hostConfig: patchedAdaptiveCardsHostConfig |
56 | | - }), |
57 | | - [patchedAdaptiveCardsHostConfig, patchedAdaptiveCardsPackage] |
58 | | - ); |
| 19 | + const composerProps = useComposerProps(props); |
59 | 20 |
|
60 | 21 | return ( |
61 | | - <AdaptiveCardsContext.Provider value={adaptiveCardsContext}> |
62 | | - <BasicWebChat |
63 | | - attachmentMiddleware={patchedAttachmentMiddleware} |
64 | | - renderMarkdown={patchedRenderMarkdown} |
65 | | - styleOptions={styleOptions} |
66 | | - styleSet={patchedStyleSet} |
67 | | - {...otherProps} |
68 | | - /> |
69 | | - </AdaptiveCardsContext.Provider> |
| 22 | + <AdaptiveCardsComposer |
| 23 | + adaptiveCardsHostConfig={adaptiveCardHostConfig || adaptiveCardsHostConfig} |
| 24 | + adaptiveCardsPackage={adaptiveCardsPackage} |
| 25 | + > |
| 26 | + <BasicWebChat {...otherProps} {...composerProps} /> |
| 27 | + </AdaptiveCardsComposer> |
70 | 28 | ); |
71 | 29 | }; |
72 | 30 |
|
73 | 31 | FullReactWebChat.defaultProps = { |
| 32 | + ...BasicWebChat.defaultProps, |
74 | 33 | adaptiveCardHostConfig: undefined, |
75 | 34 | adaptiveCardsHostConfig: undefined, |
76 | 35 | adaptiveCardsPackage: undefined, |
77 | | - attachmentMiddleware: undefined, |
78 | | - renderMarkdown: undefined, |
79 | | - styleOptions: undefined, |
80 | | - styleSet: undefined |
| 36 | + renderMarkdown: undefined |
81 | 37 | }; |
82 | 38 |
|
83 | 39 | FullReactWebChat.propTypes = { |
| 40 | + ...BasicWebChat.propTypes, |
84 | 41 | adaptiveCardHostConfig: PropTypes.any, |
85 | 42 | adaptiveCardsHostConfig: PropTypes.any, |
86 | 43 | adaptiveCardsPackage: PropTypes.any, |
87 | | - attachmentMiddleware: PropTypes.func, |
88 | | - renderMarkdown: PropTypes.func, |
89 | | - styleOptions: PropTypes.any, |
90 | | - styleSet: PropTypes.any |
| 44 | + renderMarkdown: PropTypes.func |
91 | 45 | }; |
92 | 46 |
|
93 | 47 | export default FullReactWebChat; |
0 commit comments