Skip to content

Commit 677ce77

Browse files
author
Marc Lundgren
committed
Refactor Composer component to use forwardRef and add focusSendBoxInput method; update type exports for ComposerRef
1 parent b052134 commit 677ce77

File tree

5 files changed

+417
-179
lines changed

5 files changed

+417
-179
lines changed

packages/bundle/src/FullComposer.tsx

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,23 @@
1-
import { Components, type ComposerProps } from 'botframework-webchat-component';
1+
import { Components, type ComposerProps, type ComposerRef } from 'botframework-webchat-component';
22
import PropTypes from 'prop-types';
3-
import React from 'react';
3+
import React, { forwardRef } from 'react';
44

55
import AddFullBundle, { type AddFullBundleProps } from './AddFullBundle';
66

77
const { Composer } = Components;
88

99
type FullComposerProps = ComposerProps & AddFullBundleProps;
1010

11-
const FullComposer = (props: FullComposerProps) => (
11+
const FullComposer = forwardRef<ComposerRef, FullComposerProps>((props, ref) => (
1212
<AddFullBundle {...props}>
1313
{extraProps => (
14-
<Composer {...props} {...extraProps}>
14+
<Composer ref={ref} {...props} {...extraProps}>
1515
{/* We need to spread, thus, we cannot we destructuring assignment. */}
16-
{/* eslint-disable-next-line react/destructuring-assignment */}
1716
{props.children}
1817
</Composer>
1918
)}
2019
</AddFullBundle>
21-
);
20+
));
2221

2322
FullComposer.defaultProps = {
2423
...Composer.defaultProps,
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/* eslint dot-notation: ["error", { "allowPattern": "^WebChat$" }] */
2+
// window['WebChat'] is required for TypeScript
3+
4+
import {
5+
Constants,
6+
createStore,
7+
createStoreWithDevTools,
8+
createStoreWithOptions,
9+
version
10+
} from 'botframework-webchat-core';
11+
import { StrictStyleOptions, StyleOptions } from 'botframework-webchat-api';
12+
13+
import ReactWebChat, {
14+
Components,
15+
concatMiddleware,
16+
connectToWebChat,
17+
createStyleSet,
18+
hooks,
19+
withEmoji
20+
} from 'botframework-webchat-component';
21+
22+
export type { ComposerRef } from 'botframework-webchat-component';
23+
24+
import addVersion from './addVersion';
25+
import coreRenderWebChat from './renderWebChat';
26+
import createBrowserWebSpeechPonyfillFactory from './createBrowserWebSpeechPonyfillFactory';
27+
import defaultCreateDirectLine from './createDirectLine';
28+
import defaultCreateDirectLineAppServiceExtension from './createDirectLineAppServiceExtension';
29+
30+
const renderWebChat = coreRenderWebChat.bind(null, ReactWebChat);
31+
32+
export const createDirectLine = options => {
33+
options.botAgent &&
34+
console.warn(
35+
'Web Chat: Developers are not currently allowed to set botAgent in the createDirectLine function. See https://github.com/microsoft/BotFramework-WebChat/issues/2119 for more details.'
36+
);
37+
38+
return defaultCreateDirectLine({ ...options, botAgent: `WebChat/${version} (Minimal)` });
39+
};
40+
41+
export const createDirectLineAppServiceExtension = options => {
42+
options.botAgent &&
43+
console.warn(
44+
'Web Chat: Developers are not currently allowed to set botAgent in the createDirectLine function. See https://github.com/microsoft/BotFramework-WebChat/issues/2119 for more details.'
45+
);
46+
47+
return defaultCreateDirectLineAppServiceExtension({ ...options, botAgent: `WebChat/${version} (Minimal)` });
48+
};
49+
50+
export default ReactWebChat;
51+
52+
export {
53+
Components,
54+
concatMiddleware,
55+
connectToWebChat,
56+
Constants,
57+
createBrowserWebSpeechPonyfillFactory,
58+
createStore,
59+
createStoreWithDevTools,
60+
createStoreWithOptions,
61+
createStyleSet,
62+
hooks,
63+
renderWebChat,
64+
version,
65+
withEmoji
66+
};
67+
68+
export type { StyleOptions, StrictStyleOptions };
69+
70+
// Until we have a development-specific bundle, we are not shipping createStoreWithDevTools in bundle.
71+
window['WebChat'] = {
72+
...window['WebChat'],
73+
concatMiddleware,
74+
connectToWebChat,
75+
Constants,
76+
createBrowserWebSpeechPonyfillFactory,
77+
createDirectLine,
78+
createDirectLineAppServiceExtension,
79+
createStore,
80+
createStoreWithOptions,
81+
createStyleSet,
82+
hooks,
83+
ReactWebChat,
84+
renderWebChat,
85+
withEmoji
86+
};
87+
88+
addVersion('minimal');

packages/bundle/src/index.ts

Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
/* eslint dot-notation: ["error", { "allowPattern": "^WebChat$" }] */
2+
// window['WebChat'] is required for TypeScript
3+
4+
export * from './index-minimal';
5+
export type { ComposerRef } from './index-minimal';
6+
7+
import { Components as MinimalComponents, hooks, version, withEmoji } from './index-minimal';
8+
import AdaptiveCardContent from './adaptiveCards/Attachment/AdaptiveCardContent';
9+
import addVersion from './addVersion';
10+
import AnimationCardContent from './adaptiveCards/Attachment/AnimationCardContent';
11+
import AudioCardContent from './adaptiveCards/Attachment/AudioCardContent';
12+
import coreRenderWebChat from './renderWebChat';
13+
import createAdaptiveCardsAttachmentMiddleware from './adaptiveCards/createAdaptiveCardsAttachmentMiddleware';
14+
import createAdaptiveCardsAttachmentForScreenReaderMiddleware from './adaptiveCards/createAdaptiveCardsAttachmentForScreenReaderMiddleware';
15+
import createCognitiveServicesSpeechServicesPonyfillFactory from './createCognitiveServicesSpeechServicesPonyfillFactory';
16+
import createDirectLineSpeechAdapters from './createDirectLineSpeechAdapters';
17+
import createStyleSet from './createFullStyleSet';
18+
import defaultCreateDirectLine from './createDirectLine';
19+
import defaultCreateDirectLineAppServiceExtension from './createDirectLineAppServiceExtension';
20+
import FullBundleStyleOptions, { StrictFullBundleStyleOptions } from './types/FullBundleStyleOptions';
21+
import FullComposer from './FullComposer';
22+
import HeroCardContent from './adaptiveCards/Attachment/HeroCardContent';
23+
import OAuthCardContent from './adaptiveCards/Attachment/OAuthCardContent';
24+
import ReactWebChat from './FullReactWebChat';
25+
import ReceiptCardContent from './adaptiveCards/Attachment/ReceiptCardContent';
26+
import renderMarkdown from './markdown/renderMarkdown';
27+
import SignInCardContent from './adaptiveCards/Attachment/SignInCardContent';
28+
import ThumbnailCardContent from './adaptiveCards/Attachment/ThumbnailCardContent';
29+
import useAdaptiveCardsHostConfig from './adaptiveCards/hooks/useAdaptiveCardsHostConfig';
30+
import useAdaptiveCardsPackage from './adaptiveCards/hooks/useAdaptiveCardsPackage';
31+
import useStyleOptions from './hooks/useStyleOptions';
32+
import useStyleSet from './hooks/useStyleSet';
33+
import VideoCardContent from './adaptiveCards/Attachment/VideoCardContent';
34+
35+
const renderWebChat = coreRenderWebChat.bind(null, ReactWebChat);
36+
37+
export const createDirectLine = (options: Omit<Parameters<typeof defaultCreateDirectLine>[0], 'botAgent'>) => {
38+
(options as any).botAgent &&
39+
console.warn(
40+
'Web Chat: Developers are not currently allowed to set botAgent. See https://github.com/microsoft/BotFramework-WebChat/issues/2119 for more details.'
41+
);
42+
43+
return defaultCreateDirectLine({ ...options, botAgent: `WebChat/${version} (Full)` });
44+
};
45+
46+
export const createDirectLineAppServiceExtension = (
47+
options: Omit<Parameters<typeof defaultCreateDirectLineAppServiceExtension>[0], 'botAgent'>
48+
) => {
49+
(options as any).botAgent &&
50+
console.warn(
51+
'Web Chat: Developers are not currently allowed to set botAgent. See https://github.com/microsoft/BotFramework-WebChat/issues/2119 for more details.'
52+
);
53+
54+
return defaultCreateDirectLineAppServiceExtension({ ...options, botAgent: `WebChat/${version} (Full)` });
55+
};
56+
57+
const patchedHooks = {
58+
...hooks,
59+
useAdaptiveCardsHostConfig,
60+
useAdaptiveCardsPackage,
61+
useStyleOptions,
62+
useStyleSet
63+
};
64+
65+
const AdditionalComponents = {
66+
AdaptiveCardContent,
67+
AnimationCardContent,
68+
AudioCardContent,
69+
Composer: FullComposer,
70+
HeroCardContent,
71+
OAuthCardContent,
72+
ReceiptCardContent,
73+
SignInCardContent,
74+
ThumbnailCardContent,
75+
VideoCardContent
76+
};
77+
78+
const Components: typeof MinimalComponents & typeof AdditionalComponents = {
79+
...MinimalComponents,
80+
...AdditionalComponents
81+
};
82+
83+
type StyleOptions = FullBundleStyleOptions;
84+
type StrictStyleOptions = StrictFullBundleStyleOptions;
85+
86+
export default ReactWebChat;
87+
88+
export {
89+
Components,
90+
createAdaptiveCardsAttachmentMiddleware,
91+
createAdaptiveCardsAttachmentForScreenReaderMiddleware,
92+
createCognitiveServicesSpeechServicesPonyfillFactory,
93+
createDirectLineSpeechAdapters,
94+
createStyleSet,
95+
patchedHooks as hooks,
96+
renderMarkdown,
97+
renderWebChat,
98+
withEmoji
99+
};
100+
101+
export type { StyleOptions, StrictStyleOptions };
102+
103+
window['WebChat'] = {
104+
...window['WebChat'],
105+
Components,
106+
createAdaptiveCardsAttachmentMiddleware,
107+
createAdaptiveCardsAttachmentForScreenReaderMiddleware,
108+
createCognitiveServicesSpeechServicesPonyfillFactory,
109+
createDirectLine,
110+
createDirectLineAppServiceExtension,
111+
createDirectLineSpeechAdapters,
112+
createStyleSet,
113+
hooks: patchedHooks,
114+
ReactWebChat,
115+
renderMarkdown,
116+
renderWebChat,
117+
withEmoji
118+
};
119+
120+
addVersion('full');

0 commit comments

Comments
 (0)