-
Notifications
You must be signed in to change notification settings - Fork 1.6k
[WIP] Supports <script type="module"> tag #5579
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
30 commits
Select commit
Hold shift + click to select a range
fbca05f
Support <script> tag
compulim 0e22b40
Add React rules
compulim 77c6b69
Disable react/jsx-indent
compulim 69e9b37
Fix build
compulim ecd8bdb
Change path
compulim b0f733b
Fix bot agent
compulim ce1eaeb
Fix module format
compulim f0d64a2
Export createActivityPolymiddlewareFromLegacy
compulim 9fbd4a6
Update to Node.js 22
compulim 7572057
Fix buildInfo.object
compulim 918c5d5
Fix Jest for transpilation
compulim 75dfa14
Add Speech SDK
compulim 60e0182
Better applyConfig API
compulim 65a861d
Use caret versions for devDependencies
compulim a131b1e
Move preset into bundle/src/package-preset
compulim 8605b94
Fix path
compulim fc6de67
Move api-middleware under api/src/package-api-middleware
compulim b81e4a5
Remove private packages from exporting publicly
compulim a9a94ff
Re-export useSuggestedActionsHooks
compulim 5b76be8
Remove api-middleware
compulim 338913e
Fix tsd
compulim 79d9c47
Remove api-middleware
compulim 8ea754f
Remove react/require-default-props
compulim c3370f7
Add --if-present
compulim 592d082
Add fat module tests
compulim 1ae8f70
Clean up
compulim 6bebdf3
Support fat module
compulim bbfbf6f
Remove botframework-webchat-* and install bundle only
compulim 6f43558
Disable Lightning CSS temporarily
compulim bd3fff8
Including reactResolve plugin
compulim File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,102 @@ | ||
| <!doctype html> | ||
| <html lang="en-US"> | ||
| <head> | ||
| <link href="/assets/index.css" rel="stylesheet" type="text/css" /> | ||
| <script crossorigin="anonymous" src="/test-harness.js"></script> | ||
| <script crossorigin="anonymous" src="/test-page-object.js"></script> | ||
| <style type="text/css"> | ||
| /* TODO: [P*] Can we eliminate this style? */ | ||
| .fui-FluentProvider, | ||
| .webchat-fluent { | ||
| height: 100%; | ||
| } | ||
| </style> | ||
| </head> | ||
| <body> | ||
| <main id="webchat"></main> | ||
| <script type="importmap"> | ||
| { | ||
| "imports": { | ||
| "@fluentui/react-components": "https://esm.sh/@fluentui/react-components?deps=react@18.3.1&exports=FluentProvider,createDarkTheme,webLightTheme", | ||
| "botframework-webchat": "/__dist__/packages/bundle/dist/botframework-webchat.mjs", | ||
| "botframework-webchat/internal": "/__dist__/packages/bundle/dist/botframework-webchat/internal.mjs", | ||
| "botframework-webchat-fluent-theme": "/__dist__/packages/fluent-theme/dist/botframework-webchat-fluent-theme.mjs", | ||
| "react": "https://esm.sh/react@18", | ||
| "react-dom": "https://esm.sh/react-dom@18", | ||
| "react-dom/": "https://esm.sh/react-dom@18/" | ||
| } | ||
| } | ||
| </script> | ||
| <script type="module"> | ||
| import React from 'react'; | ||
|
|
||
| // We should allow using React from environment. | ||
| // When web devs import Web Chat as <script type="module">, we want to enable customization. | ||
| // Customization requires React.createElement() and calling some hooks. | ||
| window.React = React; | ||
| </script> | ||
| <script type="module"> | ||
| import { FluentProvider, createDarkTheme, webLightTheme } from '@fluentui/react-components'; | ||
| import { createDirectLine, createStoreWithOptions, hooks, ReactWebChat } from 'botframework-webchat'; | ||
| import { FluentThemeProvider } from 'botframework-webchat-fluent-theme'; | ||
| import { createElement } from 'react'; | ||
| import { createRoot } from 'react-dom/client'; | ||
|
|
||
| const { useStyleOptions } = hooks; | ||
| const { | ||
| testHelpers: { createDirectLineEmulator } | ||
| } = window; | ||
|
|
||
| // TODO: This is for `createDirectLineEmulator` only, should find ways to eliminate this line. | ||
| window.WebChat = { createStoreWithOptions }; | ||
|
|
||
| run(async function () { | ||
| const { directLine, store } = createDirectLineEmulator(); | ||
|
|
||
| const fluentTheme = { | ||
| ...createDarkTheme({ | ||
| 10: '#12174c', | ||
| 20: '#1a1f5b', | ||
| 30: '#21276a', | ||
| 40: '#293079', | ||
| 50: '#303788', | ||
| 60: '#384097', | ||
| 70: '#4049a7', | ||
| 80: '#151e80', | ||
| 90: '#4f59c5', | ||
| 100: '#5661d4', | ||
| 110: '#5e69e3', | ||
| 120: '#7982e8', | ||
| 130: '#949bec', | ||
| 140: '#afb5f1', | ||
| 150: '#c9cdf6', | ||
| 160: '#e4e6fa' | ||
| }), | ||
| colorNeutralBackground1Disabled: '#101010', | ||
| colorNeutralBackground1Hover: '#101010', | ||
| colorNeutralForeground5: '#424242' | ||
| }; | ||
|
|
||
| createRoot(document.getElementsByTagName('main')[0]).render( | ||
| createElement( | ||
| FluentProvider, | ||
| { className: 'fui-FluentProvider', theme: fluentTheme }, | ||
| createElement( | ||
| FluentThemeProvider, | ||
| { variant: 'fluent' }, | ||
| createElement(ReactWebChat, { directLine, store }) | ||
| ) | ||
| ) | ||
| ); | ||
|
|
||
| await pageConditions.uiConnected(); | ||
|
|
||
| await directLine.emulateIncomingActivity('Hello, World!'); | ||
|
|
||
| await pageConditions.numActivitiesShown(1); | ||
|
|
||
| await host.snapshot('local'); | ||
| }); | ||
| </script> | ||
| </body> | ||
| </html> | ||
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,48 @@ | ||
| <!doctype html> | ||
| <html lang="en-US"> | ||
| <head> | ||
| <link href="/assets/index.css" rel="stylesheet" type="text/css" /> | ||
| <script crossorigin="anonymous" src="/test-harness.js"></script> | ||
| <script crossorigin="anonymous" src="/test-page-object.js"></script> | ||
| </head> | ||
| <body> | ||
| <main id="webchat"></main> | ||
| <script type="importmap"> | ||
| { | ||
| "imports": { | ||
| "botframework-webchat": "/__dist__/packages/bundle/dist/botframework-webchat.mjs" | ||
| } | ||
| } | ||
| </script> | ||
| <script type="module"> | ||
| import { createDirectLine, createStoreWithOptions, renderWebChat } from 'botframework-webchat'; | ||
|
|
||
| run(async function () { | ||
| const { | ||
| testHelpers: { createDirectLineEmulator } | ||
| } = window; | ||
|
|
||
| // TODO: This is for `createDirectLineEmulator` only, should find ways to eliminate this line. | ||
| window.WebChat = { createStoreWithOptions }; | ||
|
|
||
| const { directLine, store } = createDirectLineEmulator(); | ||
|
|
||
| renderWebChat( | ||
| { | ||
| directLine, | ||
| store | ||
| }, | ||
| document.getElementById('webchat') | ||
| ); | ||
|
|
||
| await pageConditions.uiConnected(); | ||
|
|
||
| await directLine.emulateIncomingActivity('Hello, World!'); | ||
|
|
||
| await pageConditions.numActivitiesShown(1); | ||
|
|
||
| await host.snapshot('local'); | ||
| }); | ||
| </script> | ||
| </body> | ||
| </html> |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
79 changes: 79 additions & 0 deletions
79
__tests__/html2/simple/fatModule/supportPolymiddleware.reactDOMRender.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,79 @@ | ||
| <!doctype html> | ||
| <html lang="en-US"> | ||
| <head> | ||
| <link href="/assets/index.css" rel="stylesheet" type="text/css" /> | ||
| <script crossorigin="anonymous" src="/test-harness.js"></script> | ||
| <script crossorigin="anonymous" src="/test-page-object.js"></script> | ||
| </head> | ||
| <body> | ||
| <main id="webchat"></main> | ||
| <script type="importmap"> | ||
| { | ||
| "imports": { | ||
| "botframework-webchat": "/__dist__/packages/bundle/dist/botframework-webchat.mjs", | ||
| "botframework-webchat/middleware": "/__dist__/packages/bundle/dist/botframework-webchat/middleware.mjs", | ||
| "react": "https://esm.sh/react@18", | ||
| "react-dom": "https://esm.sh/react-dom@18", | ||
| "react-dom/": "https://esm.sh/react-dom@18/" | ||
| } | ||
| } | ||
| </script> | ||
| <script type="module"> | ||
| import React from 'react'; | ||
|
|
||
| // We should allow using React from environment. | ||
| // When web devs import Web Chat as <script type="module">, we want to enable customization. | ||
| // Customization requires React.createElement() and calling some hooks. | ||
| window.React = React; | ||
| </script> | ||
| <script type="module"> | ||
| import { createDirectLine, createStoreWithOptions, hooks, ReactWebChat } from 'botframework-webchat'; | ||
| import { activityComponent, createActivityPolymiddleware } from 'botframework-webchat/middleware'; | ||
| import { createElement } from 'react'; | ||
| import { createRoot } from 'react-dom/client'; | ||
|
|
||
| const { useStyleOptions } = hooks; | ||
| const { | ||
| testHelpers: { createDirectLineEmulator } | ||
| } = window; | ||
|
|
||
| // TODO: This is for `createDirectLineEmulator` only, should find ways to eliminate this line. | ||
| window.WebChat = { createStoreWithOptions }; | ||
|
|
||
| run(async function () { | ||
| const { directLine, store } = createDirectLineEmulator(); | ||
|
|
||
| function MyMiddleware({ nextResult }) { | ||
| // THEN: Web Chat hooks can be called. | ||
| const [{ accent }] = useStyleOptions(); | ||
|
|
||
| return createElement( | ||
| 'div', | ||
| { style: { borderColor: accent, borderStyle: 'solid', borderWidth: 2 } }, | ||
| nextResult?.render({}) | ||
| ); | ||
| } | ||
|
|
||
| createRoot(document.getElementsByTagName('main')[0]).render( | ||
| createElement(ReactWebChat, { | ||
| directLine, | ||
| polymiddleware: [ | ||
| createActivityPolymiddleware( | ||
| next => request => activityComponent(MyMiddleware, { nextResult: next(request) }) | ||
| ) | ||
| ], | ||
| store | ||
| }) | ||
| ); | ||
|
|
||
| await pageConditions.uiConnected(); | ||
|
|
||
| await directLine.emulateIncomingActivity('Hello, World!'); | ||
|
|
||
| await pageConditions.numActivitiesShown(1); | ||
|
|
||
| await host.snapshot('local'); | ||
| }); | ||
| </script> | ||
| </body> | ||
| </html> |
Binary file added
BIN
+8.73 KB
...s__/html2/simple/fatModule/supportPolymiddleware.reactDOMRender.html.snap-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
80 changes: 80 additions & 0 deletions
80
__tests__/html2/simple/fatModule/supportPolymiddleware.renderWebChat.html
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| <!doctype html> | ||
| <html lang="en-US"> | ||
| <head> | ||
| <link href="/assets/index.css" rel="stylesheet" type="text/css" /> | ||
| <script crossorigin="anonymous" src="/test-harness.js"></script> | ||
| <script crossorigin="anonymous" src="/test-page-object.js"></script> | ||
| </head> | ||
| <body> | ||
| <main id="webchat"></main> | ||
| <script type="importmap"> | ||
| { | ||
| "imports": { | ||
| "botframework-webchat": "/__dist__/packages/bundle/dist/botframework-webchat.mjs", | ||
| "botframework-webchat/middleware": "/__dist__/packages/bundle/dist/botframework-webchat/middleware.mjs", | ||
| "react": "https://esm.sh/react@18", | ||
| "react-dom": "https://esm.sh/react-dom@18" | ||
| } | ||
| } | ||
| </script> | ||
| <script type="module"> | ||
| import React from 'react'; | ||
| import ReactDOM from 'react-dom'; | ||
|
|
||
| // We should allow using React from environment. | ||
| // When web devs import Web Chat as <script type="module">, we want to enable customization. | ||
| // Customization requires React.createElement() and calling some hooks. | ||
| window.React = React; | ||
| window.ReactDOM = ReactDOM; | ||
| </script> | ||
| <script type="module"> | ||
| import { createDirectLine, createStoreWithOptions, hooks, renderWebChat } from 'botframework-webchat'; | ||
| import { activityComponent, createActivityPolymiddleware } from 'botframework-webchat/middleware'; | ||
| import { createElement } from 'react'; | ||
|
|
||
| const { useStyleOptions } = hooks; | ||
| const { | ||
| testHelpers: { createDirectLineEmulator } | ||
| } = window; | ||
|
|
||
| // TODO: This is for `createDirectLineEmulator` only, should find ways to eliminate this line. | ||
| window.WebChat = { createStoreWithOptions }; | ||
|
|
||
| run(async function () { | ||
| const { directLine, store } = createDirectLineEmulator(); | ||
|
|
||
| function MyMiddleware({ nextResult }) { | ||
| // THEN: Web Chat hooks can be called. | ||
| const [{ accent }] = useStyleOptions(); | ||
|
|
||
| return createElement( | ||
| 'div', | ||
| { style: { borderColor: accent, borderStyle: 'solid', borderWidth: 2 } }, | ||
| nextResult?.render({}) | ||
| ); | ||
| } | ||
|
|
||
| renderWebChat( | ||
| { | ||
| directLine, | ||
| polymiddleware: [ | ||
| createActivityPolymiddleware( | ||
| next => request => activityComponent(MyMiddleware, { nextResult: next(request) }) | ||
| ) | ||
| ], | ||
| store | ||
| }, | ||
| document.getElementsByTagName('main')[0] | ||
| ); | ||
|
|
||
| await pageConditions.uiConnected(); | ||
|
|
||
| await directLine.emulateIncomingActivity('Hello, World!'); | ||
|
|
||
| await pageConditions.numActivitiesShown(1); | ||
|
|
||
| await host.snapshot('local'); | ||
| }); | ||
| </script> | ||
| </body> | ||
| </html> |
Binary file added
BIN
+8.73 KB
...ts__/html2/simple/fatModule/supportPolymiddleware.renderWebChat.html.snap-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider us doing
import React from './webchat-react-16.x.x.mjsin the bundled fat module and people could override this via import map if they need a different version of react.