Skip to content

Commit 5b04ab2

Browse files
authored
Support <script type="module"> imports for Fluent skin pack (microsoft#5593)
* Add test * Build /static * Add react@18 and react-dom@18 * Add tests for fluent-theme * Add tsx test * No need object-assign aliasing * Add comment * Add entry
1 parent 1898c00 commit 5b04ab2

31 files changed

+734
-60
lines changed

.dockerignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
!/packages/bundle/static
66
!/packages/debug-theme/dist
77
!/packages/fluent-theme/dist
8+
!/packages/fluent-theme/static
89
!/packages/playground/build
910
!/packages/test/fluent-bundle/dist
1011
!/packages/test/harness/dist

.github/workflows/pull-request-validation.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ jobs:
6060
./packages/bundle/static/
6161
./packages/debug-theme/dist/
6262
./packages/fluent-theme/dist/
63+
./packages/fluent-theme/static/
6364
./packages/test/harness/
6465
./packages/test/page-object/dist/
6566
./packages/test/web-server/dist/

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ Notes: web developers are advised to use [`~` (tilde range)](https://github.com/
138138
- `bundle`: `botframework-webchat/component`, `botframework-webchat/decorator` (internal-use), `botframework-webchat/hook`
139139
- `component`: `botframework-webchat-component/component`, `botframework-webchat-component/hook`
140140
- (Experimental) Added support for importing via `<script type="module">`, by [@compulim](https://github.com/compulim) in PR [#5592](https://github.com/microsoft/BotFramework-WebChat/pull/5592)
141+
- Added support for `botframework-webchat-fluent-theme` package, by [@compulim](https://github.com/compulim) in PR [#5593](https://github.com/microsoft/BotFramework-WebChat/pull/5593)
141142

142143
### Changed
143144

__tests__/html2/simple/fatModule/fluentTheme.skip.html renamed to __tests__/html2/simple/fatModule/esm.sh/fluentTheme.html

Lines changed: 33 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,46 @@
1717
<script type="importmap">
1818
{
1919
"imports": {
20-
"@fluentui/react-components": "https://esm.sh/@fluentui/react-components?deps=react@18.3.1&exports=FluentProvider,createDarkTheme,webLightTheme",
20+
"@fluentui/react-components": "https://esm.sh/@fluentui/react-components?deps=react@18,react-dom@18&exports=FluentProvider,webLightTheme",
2121
"botframework-webchat": "/__dist__/packages/bundle/static/botframework-webchat.js",
22-
"botframework-webchat/internal": "/__dist__/packages/bundle/static/botframework-webchat.internal.mjs",
23-
"botframework-webchat-fluent-theme": "/__dist__/packages/fluent-theme/dist/botframework-webchat-fluent-theme.mjs",
24-
"react": "/__dist__/packages/bundle/static/react.js",
25-
"react-dom": "/__dist__/packages/bundle/static/react-dom.js"
22+
"botframework-webchat/decorator": "/__dist__/packages/bundle/static/botframework-webchat.decorator.js",
23+
"botframework-webchat/internal": "/__dist__/packages/bundle/static/botframework-webchat.internal.js",
24+
"botframework-webchat-fluent-theme": "/__dist__/packages/fluent-theme/static/botframework-webchat-fluent-theme.js",
25+
"jest-mock": "https://esm.sh/jest-mock",
26+
"react": "https://esm.sh/react@18",
27+
"react-dom": "https://esm.sh/react-dom@18",
28+
"react-dom/": "https://esm.sh/react-dom@18/"
2629
}
2730
}
2831
</script>
2932
<script type="module">
30-
import { FluentProvider, createDarkTheme, webLightTheme } from '@fluentui/react-components';
33+
import { fn, spyOn } from 'jest-mock';
34+
import { FluentProvider, webLightTheme } from '@fluentui/react-components';
3135
import { createDirectLine, createStoreWithOptions, hooks, ReactWebChat } from 'botframework-webchat';
3236
import { FluentThemeProvider } from 'botframework-webchat-fluent-theme';
3337
import { createElement } from 'react';
3438
import { createRoot } from 'react-dom/client';
3539

40+
const consoleError = console.error.bind(console);
41+
42+
spyOn(console, 'error').mockImplementation((...args) => {
43+
const [message] = args;
44+
45+
if (
46+
!(
47+
typeof message === 'string' &&
48+
(message.includes(
49+
'Support for defaultProps will be removed from function components in a future major release. Use JavaScript default parameters instead.'
50+
) ||
51+
// TODO: [P0] We should fix the "Cannot update a component while rendering a different component" error.
52+
(message.includes('Cannot update a component') &&
53+
message.includes('while rendering a different component')))
54+
)
55+
) {
56+
consoleError(...args);
57+
}
58+
});
59+
3660
const { useStyleOptions } = hooks;
3761
const {
3862
testHelpers: { createDirectLineEmulator }
@@ -45,27 +69,9 @@
4569
const { directLine, store } = createDirectLineEmulator();
4670

4771
const fluentTheme = {
48-
...createDarkTheme({
49-
10: '#12174c',
50-
20: '#1a1f5b',
51-
30: '#21276a',
52-
40: '#293079',
53-
50: '#303788',
54-
60: '#384097',
55-
70: '#4049a7',
56-
80: '#151e80',
57-
90: '#4f59c5',
58-
100: '#5661d4',
59-
110: '#5e69e3',
60-
120: '#7982e8',
61-
130: '#949bec',
62-
140: '#afb5f1',
63-
150: '#c9cdf6',
64-
160: '#e4e6fa'
65-
}),
66-
colorNeutralBackground1Disabled: '#101010',
67-
colorNeutralBackground1Hover: '#101010',
68-
colorNeutralForeground5: '#424242'
72+
...webLightTheme,
73+
// Original is #242424 which is too light for fui-FluentProvider to pass our accessibility checks.
74+
colorNeutralForeground1: '#1b1b1b'
6975
};
7076

7177
createRoot(document.getElementsByTagName('main')[0]).render(
8.79 KB
Loading
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<!doctype html>
2+
<html lang="en-US">
3+
<head>
4+
<link href="/assets/index.css" rel="stylesheet" type="text/css" />
5+
<script crossorigin="anonymous" src="/test-harness.js"></script>
6+
<script crossorigin="anonymous" src="/test-page-object.js"></script>
7+
<style type="text/css">
8+
/* TODO: [P*] Can we eliminate this style? */
9+
.fui-FluentProvider,
10+
.webchat-fluent {
11+
height: 100%;
12+
}
13+
</style>
14+
</head>
15+
<body>
16+
<main id="webchat"></main>
17+
<script type="importmap">
18+
{
19+
"imports": {
20+
"@fluentui/react-components": "https://esm.sh/@fluentui/react-components?deps=react@18,react-dom@18&exports=FluentProvider,createDarkTheme,webLightTheme",
21+
"botframework-webchat": "/__dist__/packages/bundle/static/botframework-webchat.js",
22+
"botframework-webchat/decorator": "/__dist__/packages/bundle/static/botframework-webchat.decorator.js",
23+
"botframework-webchat/internal": "/__dist__/packages/bundle/static/botframework-webchat.internal.js",
24+
"botframework-webchat-fluent-theme": "/__dist__/packages/fluent-theme/static/botframework-webchat-fluent-theme.js",
25+
"jest-mock": "https://esm.sh/jest-mock",
26+
"react": "https://esm.sh/react@18",
27+
"react-dom": "https://esm.sh/react-dom@18",
28+
"react-dom/": "https://esm.sh/react-dom@18/"
29+
}
30+
}
31+
</script>
32+
<script src="https://esm.sh/tsx" type="module"></script>
33+
<script type="text/babel">
34+
import { fn, spyOn } from 'jest-mock';
35+
import { FluentProvider, webLightTheme } from '@fluentui/react-components';
36+
import { createDirectLine, createStoreWithOptions, hooks, ReactWebChat } from 'botframework-webchat';
37+
import { FluentThemeProvider } from 'botframework-webchat-fluent-theme';
38+
import { createRoot } from 'react-dom/client';
39+
40+
const consoleError = console.error.bind(console);
41+
42+
spyOn(console, 'error').mockImplementation((...args) => {
43+
const [message] = args;
44+
45+
if (
46+
!(
47+
typeof message === 'string' &&
48+
(message.includes(
49+
'Support for defaultProps will be removed from function components in a future major release. Use JavaScript default parameters instead.'
50+
) ||
51+
// TODO: [P0] We should fix the "Cannot update a component while rendering a different component" error.
52+
(message.includes('Cannot update a component') &&
53+
message.includes('while rendering a different component')))
54+
)
55+
) {
56+
consoleError(...args);
57+
}
58+
});
59+
60+
const { useStyleOptions } = hooks;
61+
const {
62+
testHelpers: { createDirectLineEmulator }
63+
} = window;
64+
65+
// TODO: This is for `createDirectLineEmulator` only, should find ways to eliminate this line.
66+
window.WebChat = { createStoreWithOptions };
67+
68+
run(async function () {
69+
const { directLine, store } = createDirectLineEmulator();
70+
71+
const fluentTheme = {
72+
...webLightTheme,
73+
// Original is #242424 which is too light for fui-FluentProvider to pass our accessibility checks.
74+
colorNeutralForeground1: '#1b1b1b'
75+
};
76+
77+
createRoot(document.getElementsByTagName('main')[0]).render(
78+
<FluentProvider className="fui-FluentProvider" theme={fluentTheme}>
79+
<FluentThemeProvider variant="fluent">
80+
<ReactWebChat directLine={directLine} store={store} />
81+
</FluentThemeProvider>
82+
</FluentProvider>
83+
);
84+
85+
await pageConditions.uiConnected();
86+
87+
await directLine.emulateIncomingActivity('Hello, World!');
88+
89+
await pageConditions.numActivitiesShown(1);
90+
91+
await host.snapshot('local');
92+
});
93+
</script>
94+
</body>
95+
</html>
8.79 KB
Loading
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
<!doctype html>
2+
<html lang="en-US">
3+
<head>
4+
<link href="/assets/index.css" rel="stylesheet" type="text/css" />
5+
<script crossorigin="anonymous" src="/test-harness.js"></script>
6+
<script crossorigin="anonymous" src="/test-page-object.js"></script>
7+
<style type="text/css">
8+
/* TODO: [P*] Can we eliminate this style? */
9+
.fui-FluentProvider,
10+
.webchat-fluent {
11+
height: 100%;
12+
}
13+
</style>
14+
</head>
15+
<body>
16+
<main id="webchat"></main>
17+
<!-- Redirect packages on esm.sh loaded by `@fluentui/react-components` -->
18+
<script type="importmap">
19+
{
20+
"imports": {
21+
"@fluentui/react-components": "https://esm.sh/@fluentui/react-components?deps=react@18.3.1,react-dom@18.3.1&exports=FluentProvider,createDarkTheme,webLightTheme",
22+
"botframework-webchat": "/__dist__/packages/bundle/static/botframework-webchat.js",
23+
"botframework-webchat/decorator": "/__dist__/packages/bundle/static/botframework-webchat.decorator.js",
24+
"botframework-webchat/internal": "/__dist__/packages/bundle/static/botframework-webchat.internal.js",
25+
"botframework-webchat-fluent-theme": "/__dist__/packages/fluent-theme/static/botframework-webchat-fluent-theme.js",
26+
"jest-mock": "https://esm.sh/jest-mock",
27+
"react": "/__dist__/packages/bundle/static/react.18.js",
28+
"react-dom": "/__dist__/packages/bundle/static/react-dom.18.js",
29+
"react-dom/client": "/__dist__/packages/bundle/static/react-dom.18/client.js",
30+
"https://esm.sh/react@18.3.1/es2022/react.mjs": "/__dist__/packages/bundle/static/react.18.js",
31+
"https://esm.sh/react@18.3.1/es2022/react-dom.mjs": "/__dist__/packages/bundle/static/react-dom.18.js",
32+
"https://esm.sh/react@18.3.1/es2022/react-dom/client.mjs": "/__dist__/packages/bundle/static/react-dom.18/client.js"
33+
}
34+
}
35+
</script>
36+
<script type="module">
37+
import { fn, spyOn } from 'jest-mock';
38+
import { FluentProvider, webLightTheme } from '@fluentui/react-components';
39+
import { createDirectLine, createStoreWithOptions, hooks, ReactWebChat } from 'botframework-webchat';
40+
import { FluentThemeProvider } from 'botframework-webchat-fluent-theme';
41+
import { createElement } from 'react';
42+
import { createRoot } from 'react-dom/client';
43+
44+
const consoleError = console.error.bind(console);
45+
46+
spyOn(console, 'error').mockImplementation((...args) => {
47+
const [message] = args;
48+
49+
if (
50+
!(
51+
typeof message === 'string' &&
52+
(message.includes(
53+
'Support for defaultProps will be removed from function components in a future major release. Use JavaScript default parameters instead.'
54+
) ||
55+
// TODO: [P0] We should fix the "Cannot update a component while rendering a different component" error.
56+
(message.includes('Cannot update a component') &&
57+
message.includes('while rendering a different component')))
58+
)
59+
) {
60+
consoleError(...args);
61+
}
62+
});
63+
64+
const { useStyleOptions } = hooks;
65+
const {
66+
testHelpers: { createDirectLineEmulator }
67+
} = window;
68+
69+
// TODO: This is for `createDirectLineEmulator` only, should find ways to eliminate this line.
70+
window.WebChat = { createStoreWithOptions };
71+
72+
run(async function () {
73+
const { directLine, store } = createDirectLineEmulator();
74+
75+
const fluentTheme = {
76+
...webLightTheme,
77+
// Original is #242424 which is too light for fui-FluentProvider to pass our accessibility checks.
78+
colorNeutralForeground1: '#1b1b1b'
79+
};
80+
81+
createRoot(document.getElementsByTagName('main')[0]).render(
82+
createElement(
83+
FluentProvider,
84+
{ className: 'fui-FluentProvider', theme: fluentTheme },
85+
createElement(
86+
FluentThemeProvider,
87+
{ variant: 'fluent' },
88+
createElement(ReactWebChat, { directLine, store })
89+
)
90+
)
91+
);
92+
93+
await pageConditions.uiConnected();
94+
95+
await directLine.emulateIncomingActivity('Hello, World!');
96+
97+
await pageConditions.numActivitiesShown(1);
98+
99+
await host.snapshot('local');
100+
});
101+
</script>
102+
</body>
103+
</html>
8.79 KB
Loading

docker-compose-wsl2.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ services:
4747
- ./packages/bundle/static/:/var/web/packages/bundle/static/
4848
- ./packages/debug-theme/dist/:/var/web/packages/debug-theme/dist/
4949
- ./packages/fluent-theme/dist/:/var/web/packages/fluent-theme/dist/
50+
- ./packages/fluent-theme/static/:/var/web/packages/fluent-theme/static/
5051
- ./packages/test/harness/dist/:/var/web/packages/test/harness/dist/
5152
- ./packages/test/page-object/dist/:/var/web/packages/test/page-object/dist/
5253
ports:

0 commit comments

Comments
 (0)