Skip to content

Commit 6e33a6e

Browse files
committed
Bump react-chain-of-responsibility and handler-chain
1 parent 5671929 commit 6e33a6e

9 files changed

Lines changed: 116 additions & 33 deletions

File tree

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
<!doctype html>
2+
<html lang="en-US">
3+
<head>
4+
<link href="/assets/index.css" rel="stylesheet" type="text/css" />
5+
<script type="importmap">
6+
{
7+
"imports": {
8+
"react": "https://esm.sh/react@18.3.1"
9+
}
10+
}
11+
</script>
12+
<script crossorigin="anonymous" src="/test-harness.js"></script>
13+
<script crossorigin="anonymous" src="/test-page-object.js"></script>
14+
<script crossorigin="anonymous" src="/__dist__/webchat-es5.js"></script>
15+
<!-- <script crossorigin="anonymous" src="https://unpkg.com/botframework-webchat@main/dist/webchat-es5.js"></script> -->
16+
</head>
17+
18+
<body>
19+
<main id="webchat"></main>
20+
<script type="module">
21+
import { createElement } from 'react';
22+
23+
run(async function () {
24+
const {
25+
testHelpers: { createDirectLineEmulator }
26+
} = window;
27+
28+
const { directLine, store } = createDirectLineEmulator();
29+
30+
const activityMiddleware = [
31+
() => next => request => next(request),
32+
() => next => request => {
33+
const render = next(request);
34+
35+
if (!request.activity.entities) {
36+
return render;
37+
}
38+
39+
expect(request.activity).toEqual(
40+
expect.objectContaining({
41+
text: 'Do you like my response?',
42+
type: 'message'
43+
})
44+
);
45+
46+
return (renderAttachment, options) => {
47+
// TODO: Test every of the following deeply to make sure they are working as expected.
48+
expect(typeof renderAttachment).toBe('function');
49+
expect(options.hideTimestamp).toEqual(false);
50+
expect(typeof options.renderActivityStatus).toBe('function');
51+
expect(options.renderAvatar).toBe(false);
52+
expect(options.showCallout).toEqual(false);
53+
54+
return createElement('div', { style: { border: 'solid 2px red' } }, render(renderAttachment, options));
55+
};
56+
}
57+
];
58+
59+
WebChat.renderWebChat(
60+
{
61+
activityMiddleware,
62+
directLine,
63+
store
64+
},
65+
document.getElementById('webchat')
66+
);
67+
68+
await pageConditions.uiConnected();
69+
70+
await directLine.emulateIncomingActivity({
71+
text: 'This is the solution.\n\n\\[x - 1 = 0\\]\n\n\\[x = 1\\]',
72+
type: 'message'
73+
});
74+
75+
await directLine.emulateIncomingActivity({
76+
entities: [
77+
{
78+
'@id': '',
79+
'@type': 'Message',
80+
additionalType: 'Feedback'
81+
}
82+
],
83+
text: 'Do you like my response?',
84+
type: 'message'
85+
});
86+
});
87+
</script>
88+
</body>
89+
</html>

package-lock.json

Lines changed: 11 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/api/src/types/ActivityMiddleware.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import type { ReactNode } from 'react';
2-
import type { RenderAttachment } from './AttachmentMiddleware';
3-
import type { WebChatActivity } from 'botframework-webchat-core';
1+
// TODO: Move this to botframework-webchat-middleware.
2+
import { type WebChatActivity } from 'botframework-webchat-core';
3+
import { type ReactNode } from 'react';
4+
5+
import { type RenderAttachment } from './AttachmentMiddleware';
46

57
type ActivityProps = {
68
hideTimestamp: boolean;

packages/component/src/Composer.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ const InternalComposer = ({
451451
() =>
452452
Object.freeze([
453453
// TODO: Add <FallbackComponent>.
454-
createActivityPolyMiddlewareFromLegacy(LegacyActivityBridge, () => undefined, ...patchedActivityMiddleware)
454+
createActivityPolyMiddlewareFromLegacy(LegacyActivityBridge, () => null, ...patchedActivityMiddleware)
455455
]),
456456
[patchedActivityMiddleware]
457457
);

packages/middleware/package.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@
5050
"precommit:eslint": "../../node_modules/.bin/eslint --report-unused-disable-directives --max-warnings 0",
5151
"precommit:typecheck": "tsc --project ./src --emitDeclarationOnly false --esModuleInterop true --noEmit --pretty false",
5252
"preversion": "cat package.json | jq '(.localDependencies // {} | to_entries | map([if .value == \"production\" then \"dependencies\" else \"devDependencies\" end, .key])) as $P | delpaths($P)' > package-temp.json && mv package-temp.json package.json",
53-
"start": "npm run build -- --watch"
53+
"start": "npm run build -- --onSuccess=\"touch ../api/src/index.ts ../component/src/index.ts\" --watch"
5454
},
5555
"devDependencies": {
5656
"@jridgewell/sourcemap-codec": "^1.5.0",
@@ -66,7 +66,8 @@
6666
"react": ">= 16.8.6"
6767
},
6868
"dependencies": {
69-
"react-chain-of-responsibility": "0.4.0-main.235b355",
69+
"handler-chain": "^0.1.0",
70+
"react-chain-of-responsibility": "0.4.0-main.a361688",
7071
"valibot": "1.1.0"
7172
}
7273
}

packages/middleware/src/internal/createActivityPolyMiddlewareFromLegacy.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import { type ActivityMiddleware, type RenderAttachment } from 'botframework-webchat-api';
22
import { type WebChatActivity } from 'botframework-webchat-core';
3+
import { composeEnhancer } from 'handler-chain';
34
import React, { type ComponentType, type ReactNode } from 'react';
45

56
import { custom, function_, never, object, optional, pipe, readonly, safeParse, type InferInput } from 'valibot';
@@ -8,7 +9,6 @@ import {
89
createActivityPolyMiddleware,
910
type ActivityPolyMiddleware
1011
} from '../activityPolyMiddleware';
11-
import composeEnhancer from '../types/GenericMiddleware';
1212

1313
const webChatActivitySchema = custom<WebChatActivity>(value => safeParse(object({}), value).success);
1414

packages/middleware/src/private/templateMiddleware.tsx

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { warnOnce } from 'botframework-webchat-core';
2+
import { type Enhancer } from 'handler-chain';
23
import React, { memo, type ReactNode } from 'react';
34
import {
45
createChainOfResponsibility,
@@ -12,16 +13,14 @@ import {
1213
} from 'react-chain-of-responsibility/preview';
1314
import { array, function_, safeParse, type InferOutput } from 'valibot';
1415

15-
import { type GenericEnhancer } from '../types/GenericMiddleware';
16-
1716
const arrayOfFunctionSchema = array(function_());
1817
// TODO: Move marker inside templateMiddleware. Think if every type of middleware should have their own marker and not crossed.
1918
const middlewareFactoryMarker = Symbol();
2019

2120
const isArrayOfFunction = (middleware: unknown): middleware is InferOutput<typeof arrayOfFunctionSchema> =>
2221
safeParse(arrayOfFunctionSchema, middleware).success;
2322

24-
const BYPASS_ENHANCER: GenericEnhancer<any, any> = next => request => next(request);
23+
const BYPASS_ENHANCER: Enhancer<any, any> = next => request => next(request);
2524
const EMPTY_ARRAY = Object.freeze([]);
2625

2726
// Following @types/react to use {} for props.

packages/middleware/src/types/GenericMiddleware.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
1+
import { type Enhancer, type Handler, type Middleware } from 'handler-chain';
12
import { type ComponentType } from 'react';
23

3-
import { type GenericEnhancer, type GenericHandler, type GenericMiddleware } from './GenericMiddleware';
4-
5-
type LegacyComponentHandler<Request, Props extends object> = GenericHandler<ComponentType<Props>, Request>;
6-
type LegacyComponentEnhancer<Request, Props extends object> = GenericEnhancer<ComponentType<Props>, Request>;
7-
type LegacyComponentMiddleware<Request, Props extends object, Init> = GenericMiddleware<
8-
ComponentType<Props>,
9-
Request,
10-
Init
11-
>;
4+
type LegacyComponentHandler<Request, Props extends object> = Handler<ComponentType<Props>, Request>;
5+
type LegacyComponentEnhancer<Request, Props extends object> = Enhancer<ComponentType<Props>, Request>;
6+
type LegacyComponentMiddleware<Request, Props extends object, Init> = Middleware<ComponentType<Props>, Request, Init>;
127

138
export { type LegacyComponentEnhancer, type LegacyComponentHandler, type LegacyComponentMiddleware };

0 commit comments

Comments
 (0)