react-chain-of-responsibility 0.4.3-main.202512240619.c88c248 → 0.4.3-main.202512312342.8e5988c

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/createChainOfResponsibility.tsx","../src/isReactComponent.ts"],"sourcesContent":["import { applyMiddleware } from 'handler-chain';\nimport React, {\n createContext,\n isValidElement,\n memo,\n useCallback,\n useContext,\n useMemo,\n type ComponentType,\n type PropsWithChildren\n} from 'react';\n\nimport isReactComponent from './isReactComponent.ts';\nimport { type ComponentEnhancer, type ComponentMiddleware } from './types.ts';\n\n// TODO: Simplify to ComponentType<Props> | undefined.\ntype ResultComponent<Props> = ComponentType<Props> | false | null | undefined;\n\ntype UseBuildComponentCallbackOptions<Props> = {\n fallbackComponent?: ResultComponent<Props> | undefined;\n};\n\ninterface UseBuildComponentCallback<Request, Props> {\n (request: Request, options?: undefined | UseBuildComponentCallbackOptions<Props>): ComponentType<Props> | undefined;\n}\n\ntype ProviderContext<Request, Props> = {\n get enhancer(): ComponentEnhancer<Request, Props> | undefined;\n useBuildComponentCallback: UseBuildComponentCallback<Request, Props>;\n};\n\ntype ProviderProps<Request, Props, Init> = PropsWithChildren<{\n middleware: readonly ComponentMiddleware<Request, Props, Init>[];\n}> &\n (Init extends never | void\n ? { readonly init?: undefined }\n : Init extends undefined | void\n ? { readonly init?: Init }\n : { readonly init: Init });\n\ntype ProxyProps<Request, Props extends object> = Props & {\n readonly fallbackComponent?: ComponentType<Props> | undefined;\n readonly request: Request;\n};\n\ntype CreateChainOfResponsibilityOptions = {\n /**\n * Allows a middleware to pass another request object when calling its next middleware. Default is false.\n *\n * However, middleware could modify the request object before calling its next middleware. It is recommended\n * to use Object.freeze() to prevent middleware from modifying the request object.\n */\n readonly passModifiedRequest?: boolean | undefined;\n};\n\ntype AsMiddlewareProps<Request, Props, Init> = {\n readonly init: Init;\n readonly Next: ComponentType<Partial<Props>>;\n readonly request: Request;\n};\n\ntype AsMiddlewareComponentProps<Request, Props, Init> = Props & {\n readonly middleware: AsMiddlewareProps<Request, Props, Init>;\n};\n\ntype ChainOfResponsibility<Request, Props extends object, Init> = {\n readonly asMiddleware: (\n middlewareComponent: ComponentType<AsMiddlewareComponentProps<Request, Props, Init>>\n ) => ComponentMiddleware<Request, Props, Init>;\n readonly Provider: ComponentType<ProviderProps<Request, Props, Init>>;\n readonly Proxy: ComponentType<ProxyProps<Request, Props>>;\n readonly types: {\n readonly init: Init;\n readonly middleware: ComponentMiddleware<Request, Props, Init>;\n readonly middlewareComponentProps: AsMiddlewareComponentProps<Request, Props, Init>;\n readonly props: Props;\n readonly proxyProps: ProxyProps<Request, Props>;\n readonly request: Request;\n };\n readonly useBuildComponentCallback: () => UseBuildComponentCallback<Request, Props>;\n};\n\nfunction createChainOfResponsibility<Request = void, Props extends object = { readonly children?: never }, Init = void>(\n options: CreateChainOfResponsibilityOptions = {}\n): ChainOfResponsibility<Request, Props, Init> {\n const defaultUseBuildComponentCallback: ProviderContext<Request, Props> = {\n get enhancer() {\n return undefined;\n },\n useBuildComponentCallback(_request, options): ComponentType<Props> {\n if (!options?.fallbackComponent) {\n throw new Error('This component/hook cannot be used outside of its corresponding <Provider>');\n }\n\n return options.fallbackComponent;\n }\n };\n\n const context = createContext<ProviderContext<Request, Props>>(defaultUseBuildComponentCallback);\n\n function ChainOfResponsibilityProvider({ children, init, middleware }: ProviderProps<Request, Props, Init>) {\n // TODO: Related to https://github.com/microsoft/TypeScript/issues/17002.\n // typescript@5.2.2 has a bug, Array.isArray() is a type predicate but only works with mutable array, not readonly array.\n // After removing \"as unknown\", `middleware` on the next line become `any[]`.\n if (!Array.isArray(middleware as unknown) || middleware.some(middleware => typeof middleware !== 'function')) {\n throw new Error('middleware prop must be an array of functions');\n }\n\n const patchedMiddleware: readonly ComponentMiddleware<Request, Props, Init>[] = Object.freeze(\n middleware\n ? middleware.map(fn => (init: Init) => {\n const enhancer = fn(init);\n\n return (next: (request: Request) => ComponentType<Props> | false | null | undefined) =>\n (originalRequest: Request) => {\n // False positive: although we did not re-assign the variable from true, it was initialized as undefined.\n // eslint-disable-next-line prefer-const\n let hasReturned: boolean;\n\n const returnValue = enhancer(nextRequest => {\n if (hasReturned) {\n throw new Error('next() cannot be called after the function had returned synchronously');\n }\n\n !options.passModifiedRequest &&\n nextRequest !== originalRequest &&\n console.warn(\n 'react-chain-of-responsibility: \"options.passModifiedRequest\" must be set to true to pass a different request object to next().'\n );\n\n return next(options.passModifiedRequest ? nextRequest : originalRequest);\n })(originalRequest);\n\n hasReturned = true;\n\n if (isValidElement(returnValue)) {\n throw new Error('middleware must not return React element directly');\n } else if (\n returnValue !== false &&\n returnValue !== null &&\n typeof returnValue !== 'undefined' &&\n !isReactComponent(returnValue)\n ) {\n throw new Error(\n 'middleware must return false, null, undefined, function component, or class component'\n );\n }\n\n return returnValue;\n };\n })\n : []\n );\n\n const { enhancer: parentEnhancer } = useContext(context);\n\n const enhancer = useMemo(\n () =>\n // We are reversing because it is easier to read:\n // - With reverse, [a, b, c] will become a(b(c(fn)))\n // - Without reverse, [a, b, c] will become c(b(a(fn)))\n applyMiddleware<ResultComponent<Props>, Request, Init>(\n ...[...patchedMiddleware, ...(parentEnhancer ? [() => parentEnhancer] : [])]\n )(init as Init),\n [init, middleware, parentEnhancer]\n );\n\n const useBuildComponentCallback = useCallback<UseBuildComponentCallback<Request, Props>>(\n (request, options = {}) => enhancer(() => options.fallbackComponent)(request) || undefined,\n [enhancer]\n );\n\n const contextValue = useMemo<ProviderContext<Request, Props>>(\n () => ({ enhancer, useBuildComponentCallback }),\n [enhancer, useBuildComponentCallback]\n );\n\n return <context.Provider value={contextValue}>{children}</context.Provider>;\n }\n\n const useBuildComponentCallback = () => useContext(context).useBuildComponentCallback;\n\n function Proxy({ fallbackComponent, request, ...props }: ProxyProps<Request, Props>) {\n const enhancer = useBuildComponentCallback();\n\n const Component = enhancer(request as Request, { fallbackComponent });\n\n return Component ? <Component {...(props as Props)} /> : null;\n }\n\n const asMiddleware: (\n middlewareComponent: ComponentType<AsMiddlewareComponentProps<Request, Props, Init>>\n ) => ComponentMiddleware<Request, Props, Init> =\n (\n MiddlewareComponent: ComponentType<AsMiddlewareComponentProps<Request, Props, Init>>\n ): ComponentMiddleware<Request, Props, Init> =>\n init =>\n next =>\n request => {\n const RawNextComponent = next(request);\n\n // TODO: Can we pre-build this component during init?\n const MiddlewareOf = (props: Props) => {\n const middleware = useMemo(\n () =>\n Object.freeze({\n init,\n Next: memo<Partial<Props>>(\n RawNextComponent\n ? (overridingProps: Partial<Props>) => <RawNextComponent {...props} {...overridingProps} />\n : () => null\n ),\n request\n }),\n []\n );\n\n return <MiddlewareComponent {...props} middleware={middleware} />;\n };\n\n MiddlewareOf.displayName = `MiddlewareOf<${MiddlewareComponent.displayName || ''}>`;\n\n return memo<Props>(MiddlewareOf);\n };\n\n return Object.freeze({\n asMiddleware,\n Provider: memo<ProviderProps<Request, Props, Init>>(ChainOfResponsibilityProvider),\n Proxy: memo<ProxyProps<Request, Props>>(Proxy),\n types: Object.freeze({\n middlewareComponentProps: undefined as unknown as AsMiddlewareComponentProps<Request, Props, Init>,\n init: undefined as unknown as Init,\n middleware: undefined as unknown as ComponentMiddleware<Request, Props, Init>,\n props: undefined as unknown as Props,\n proxyProps: undefined as unknown as ProxyProps<Request, Props>,\n request: undefined as unknown as Request\n }),\n useBuildComponentCallback\n });\n}\n\nexport default createChainOfResponsibility;\nexport {\n type ChainOfResponsibility,\n type CreateChainOfResponsibilityOptions,\n type ProxyProps,\n type UseBuildComponentCallback\n};\n","import {\n type ComponentClass,\n type ComponentType,\n type Consumer,\n type Fragment,\n type FunctionComponent,\n type Provider\n} from 'react';\nimport { custom } from 'valibot';\n\nfunction isConsumer(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n component: any\n): component is Consumer<unknown> {\n return component?.$$typeof?.toString() === 'Symbol(react.context)';\n}\n\nfunction isProvider(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n component: any\n): component is Provider<unknown> {\n return component?.$$typeof?.toString() === 'Symbol(react.provider)';\n}\n\nfunction isFragment(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n component: any\n): component is typeof Fragment {\n return component?.toString() === 'Symbol(react.fragment)';\n}\n\nfunction isFunctionComponent(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n component: any\n): component is FunctionComponent {\n if (typeof component === 'function') {\n return true;\n }\n\n return isPureFunctionComponent(component);\n}\n\nfunction isPureFunctionComponent(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n component: any\n): component is FunctionComponent {\n return component?.$$typeof?.toString() === 'Symbol(react.memo)' && isFunctionComponent(component.type);\n}\n\nfunction isComponentClass(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n component: any\n): component is ComponentClass {\n return typeof component === 'object' && typeof component?.['render'] === 'function';\n}\n\n// There are no definitive ways to check if an object is a React component or not.\n// We are checking if the object has a render function (classic component).\n// Note: \"forwardRef()\" returns plain object, not class instance.\nfunction isReactComponent(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n component: any\n): component is ComponentType {\n return (\n isFunctionComponent(component) ||\n isComponentClass(component) ||\n isFragment(component) ||\n isConsumer(component) ||\n isProvider(component)\n );\n}\n\nconst reactComponent = () =>\n custom<ComponentType<unknown>>(value => isReactComponent(value), 'not a valid React component');\n\nexport default isReactComponent;\nexport { reactComponent };\n"],"mappings":";AAAA,SAAS,uBAAuB;AAChC,OAAO;AAAA,EACL;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;;;ACFP,SAAS,cAAc;AAEvB,SAAS,WAEP,WACgC;AAChC,SAAO,WAAW,UAAU,SAAS,MAAM;AAC7C;AAEA,SAAS,WAEP,WACgC;AAChC,SAAO,WAAW,UAAU,SAAS,MAAM;AAC7C;AAEA,SAAS,WAEP,WAC8B;AAC9B,SAAO,WAAW,SAAS,MAAM;AACn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AAI,OAAiB,IAAK;AAAA,EAC3D;AAEA,QAAM,eAGJ,CACE,wBAEF,UACA,UACA,aAAW;AACT,UAAM,mBAAmB,KAAK,OAAO;AAGrC,UAAM,eAAe,CAAC,UAAiB;AACrC,YAAM,aAAa;AAAA,QACjB,MACE,OAAO,OAAO;AAAA,UACZ;AAAA,UACA,MAAM;AAAA,YACJ,mBACI,CAAC,oBAAoC,oCAAC,oBAAkB,GAAG,OAAQ,GAAG,iBAAiB,IACvF,MAAM;AAAA,UACZ;AAAA,UACA;AAAA,QACF,CAAC;AAAA,QACH,CAAC;AAAA,MACH;AAEA,aAAO,oCAAC,uBAAqB,GAAG,OAAO,YAAwB;AAAA,IACjE;AAEA,iBAAa,cAAc,gBAAgB,oBAAoB,eAAe,EAAE;AAEhF,WAAO,KAAY,YAAY;AAAA,EACjC;AAEF,SAAO,OAAO,OAAO;AAAA,IACnB;AAAA,IACA,UAAU,KAA0C,6BAA6B;AAAA,IACjF,OAAO,KAAiC,KAAK;AAAA,IAC7C,OAAO,OAAO,OAAO;AAAA,MACnB,0BAA0B;AAAA,MAC1B,MAAM;AAAA,MACN,YAAY;AAAA,MACZ,OAAO;AAAA,MACP,YAAY;AAAA,MACZ,SAAS;AAAA,IACX,CAAC;AAAA,IACD;AAAA,EACF,CAAC;AACH;AAEA,IAAO,sCAAQ;","names":["options","middleware","init","enhancer","useBuildComponentCallback"]}
@@ -1,66 +0,0 @@
1
- import { ComponentType, PropsWithChildren } from 'react';
2
- import { Middleware } from 'handler-chain';
3
-
4
- type ComponentResult<Props = {
5
- children?: never;
6
- }> = ComponentType<Props> | false | null | undefined;
7
- type ComponentMiddleware<Request, Props = {
8
- children?: never;
9
- }, Init = undefined> = Middleware<ComponentResult<Props>, Request, Init>;
10
-
11
- type ResultComponent<Props> = ComponentType<Props> | false | null | undefined;
12
- type UseBuildComponentCallbackOptions<Props> = {
13
- fallbackComponent?: ResultComponent<Props> | undefined;
14
- };
15
- interface UseBuildComponentCallback<Request, Props> {
16
- (request: Request, options?: undefined | UseBuildComponentCallbackOptions<Props>): ComponentType<Props> | undefined;
17
- }
18
- type ProviderProps<Request, Props, Init> = PropsWithChildren<{
19
- middleware: readonly ComponentMiddleware<Request, Props, Init>[];
20
- }> & (Init extends never | void ? {
21
- readonly init?: undefined;
22
- } : Init extends undefined | void ? {
23
- readonly init?: Init;
24
- } : {
25
- readonly init: Init;
26
- });
27
- type ProxyProps<Request, Props extends object> = Props & {
28
- readonly fallbackComponent?: ComponentType<Props> | undefined;
29
- readonly request: Request;
30
- };
31
- type CreateChainOfResponsibilityOptions = {
32
- /**
33
- * Allows a middleware to pass another request object when calling its next middleware. Default is false.
34
- *
35
- * However, middleware could modify the request object before calling its next middleware. It is recommended
36
- * to use Object.freeze() to prevent middleware from modifying the request object.
37
- */
38
- readonly passModifiedRequest?: boolean | undefined;
39
- };
40
- type AsMiddlewareProps<Request, Props, Init> = {
41
- readonly init: Init;
42
- readonly Next: ComponentType<Partial<Props>>;
43
- readonly request: Request;
44
- };
45
- type AsMiddlewareComponentProps<Request, Props, Init> = Props & {
46
- readonly middleware: AsMiddlewareProps<Request, Props, Init>;
47
- };
48
- type ChainOfResponsibility<Request, Props extends object, Init> = {
49
- readonly asMiddleware: (middlewareComponent: ComponentType<AsMiddlewareComponentProps<Request, Props, Init>>) => ComponentMiddleware<Request, Props, Init>;
50
- readonly Provider: ComponentType<ProviderProps<Request, Props, Init>>;
51
- readonly Proxy: ComponentType<ProxyProps<Request, Props>>;
52
- readonly types: {
53
- readonly init: Init;
54
- readonly middleware: ComponentMiddleware<Request, Props, Init>;
55
- readonly middlewareComponentProps: AsMiddlewareComponentProps<Request, Props, Init>;
56
- readonly props: Props;
57
- readonly proxyProps: ProxyProps<Request, Props>;
58
- readonly request: Request;
59
- };
60
- readonly useBuildComponentCallback: () => UseBuildComponentCallback<Request, Props>;
61
- };
62
- declare function createChainOfResponsibility<Request = void, Props extends object = {
63
- readonly children?: never;
64
- }, Init = void>(options?: CreateChainOfResponsibilityOptions): ChainOfResponsibility<Request, Props, Init>;
65
-
66
- export { type CreateChainOfResponsibilityOptions as C, type ComponentMiddleware as a, createChainOfResponsibility as c };
@@ -1,66 +0,0 @@
1
- import { ComponentType, PropsWithChildren } from 'react';
2
- import { Middleware } from 'handler-chain';
3
-
4
- type ComponentResult<Props = {
5
- children?: never;
6
- }> = ComponentType<Props> | false | null | undefined;
7
- type ComponentMiddleware<Request, Props = {
8
- children?: never;
9
- }, Init = undefined> = Middleware<ComponentResult<Props>, Request, Init>;
10
-
11
- type ResultComponent<Props> = ComponentType<Props> | false | null | undefined;
12
- type UseBuildComponentCallbackOptions<Props> = {
13
- fallbackComponent?: ResultComponent<Props> | undefined;
14
- };
15
- interface UseBuildComponentCallback<Request, Props> {
16
- (request: Request, options?: undefined | UseBuildComponentCallbackOptions<Props>): ComponentType<Props> | undefined;
17
- }
18
- type ProviderProps<Request, Props, Init> = PropsWithChildren<{
19
- middleware: readonly ComponentMiddleware<Request, Props, Init>[];
20
- }> & (Init extends never | void ? {
21
- readonly init?: undefined;
22
- } : Init extends undefined | void ? {
23
- readonly init?: Init;
24
- } : {
25
- readonly init: Init;
26
- });
27
- type ProxyProps<Request, Props extends object> = Props & {
28
- readonly fallbackComponent?: ComponentType<Props> | undefined;
29
- readonly request: Request;
30
- };
31
- type CreateChainOfResponsibilityOptions = {
32
- /**
33
- * Allows a middleware to pass another request object when calling its next middleware. Default is false.
34
- *
35
- * However, middleware could modify the request object before calling its next middleware. It is recommended
36
- * to use Object.freeze() to prevent middleware from modifying the request object.
37
- */
38
- readonly passModifiedRequest?: boolean | undefined;
39
- };
40
- type AsMiddlewareProps<Request, Props, Init> = {
41
- readonly init: Init;
42
- readonly Next: ComponentType<Partial<Props>>;
43
- readonly request: Request;
44
- };
45
- type AsMiddlewareComponentProps<Request, Props, Init> = Props & {
46
- readonly middleware: AsMiddlewareProps<Request, Props, Init>;
47
- };
48
- type ChainOfResponsibility<Request, Props extends object, Init> = {
49
- readonly asMiddleware: (middlewareComponent: ComponentType<AsMiddlewareComponentProps<Request, Props, Init>>) => ComponentMiddleware<Request, Props, Init>;
50
- readonly Provider: ComponentType<ProviderProps<Request, Props, Init>>;
51
- readonly Proxy: ComponentType<ProxyProps<Request, Props>>;
52
- readonly types: {
53
- readonly init: Init;
54
- readonly middleware: ComponentMiddleware<Request, Props, Init>;
55
- readonly middlewareComponentProps: AsMiddlewareComponentProps<Request, Props, Init>;
56
- readonly props: Props;
57
- readonly proxyProps: ProxyProps<Request, Props>;
58
- readonly request: Request;
59
- };
60
- readonly useBuildComponentCallback: () => UseBuildComponentCallback<Request, Props>;
61
- };
62
- declare function createChainOfResponsibility<Request = void, Props extends object = {
63
- readonly children?: never;
64
- }, Init = void>(options?: CreateChainOfResponsibilityOptions): ChainOfResponsibility<Request, Props, Init>;
65
-
66
- export { type CreateChainOfResponsibilityOptions as C, type ComponentMiddleware as a, createChainOfResponsibility as c };
@@ -1,17 +0,0 @@
1
- import { IRenderFunction } from '@fluentui/react';
2
- import { Key } from 'react';
3
- import { C as CreateChainOfResponsibilityOptions, c as createChainOfResponsibility } from './index-Dm_KqEiI.mjs';
4
- import 'handler-chain';
5
-
6
- type UseBuildRenderFunctionOptions<Props> = {
7
- getKey?: (props: Props | undefined) => Key;
8
- };
9
- type UseBuildRenderFunction<Props> = (options?: UseBuildRenderFunctionOptions<Props>) => IRenderFunction<Props>;
10
- /**
11
- * @deprecated Fluent UI v9 no longer use `IRenderFunction` for custom render. We no longer validate the correctness of this function.
12
- */
13
- declare function createChainOfResponsibilityForFluentUI<Props extends object, Init = undefined>(options?: CreateChainOfResponsibilityOptions): ReturnType<typeof createChainOfResponsibility<Props | undefined, Props, Init>> & {
14
- useBuildRenderFunction: UseBuildRenderFunction<Props>;
15
- };
16
-
17
- export { createChainOfResponsibilityForFluentUI };
@@ -1,17 +0,0 @@
1
- import { IRenderFunction } from '@fluentui/react';
2
- import { Key } from 'react';
3
- import { C as CreateChainOfResponsibilityOptions, c as createChainOfResponsibility } from './index-Dm_KqEiI.js';
4
- import 'handler-chain';
5
-
6
- type UseBuildRenderFunctionOptions<Props> = {
7
- getKey?: (props: Props | undefined) => Key;
8
- };
9
- type UseBuildRenderFunction<Props> = (options?: UseBuildRenderFunctionOptions<Props>) => IRenderFunction<Props>;
10
- /**
11
- * @deprecated Fluent UI v9 no longer use `IRenderFunction` for custom render. We no longer validate the correctness of this function.
12
- */
13
- declare function createChainOfResponsibilityForFluentUI<Props extends object, Init = undefined>(options?: CreateChainOfResponsibilityOptions): ReturnType<typeof createChainOfResponsibility<Props | undefined, Props, Init>> & {
14
- useBuildRenderFunction: UseBuildRenderFunction<Props>;
15
- };
16
-
17
- export { createChainOfResponsibilityForFluentUI };
@@ -1,203 +0,0 @@
1
- "use strict";
2
- var __create = Object.create;
3
- var __defProp = Object.defineProperty;
4
- var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
- var __getOwnPropNames = Object.getOwnPropertyNames;
6
- var __getProtoOf = Object.getPrototypeOf;
7
- var __hasOwnProp = Object.prototype.hasOwnProperty;
8
- var __export = (target, all) => {
9
- for (var name in all)
10
- __defProp(target, name, { get: all[name], enumerable: true });
11
- };
12
- var __copyProps = (to, from, except, desc) => {
13
- if (from && typeof from === "object" || typeof from === "function") {
14
- for (let key of __getOwnPropNames(from))
15
- if (!__hasOwnProp.call(to, key) && key !== except)
16
- __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
- }
18
- return to;
19
- };
20
- var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
- // If the importer is in node compatibility mode or this is not an ESM
22
- // file that has been converted to a CommonJS file using a Babel-
23
- // compatible transform (i.e. "__esModule" has not been set), then set
24
- // "default" to the CommonJS "module.exports" for node compatibility.
25
- isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
- mod
27
- ));
28
- var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
-
30
- // src/index.fluentUI.ts
31
- var index_fluentUI_exports = {};
32
- __export(index_fluentUI_exports, {
33
- createChainOfResponsibilityForFluentUI: () => createChainOfResponsibilityForFluentUI
34
- });
35
- module.exports = __toCommonJS(index_fluentUI_exports);
36
-
37
- // src/createChainOfResponsibilityForFluentUI.tsx
38
- var import_react2 = __toESM(require("react"));
39
-
40
- // src/createChainOfResponsibility.tsx
41
- var import_handler_chain = require("handler-chain");
42
- var import_react = __toESM(require("react"));
43
-
44
- // src/isReactComponent.ts
45
- var import_valibot = require("valibot");
46
- function isConsumer(component) {
47
- var _a;
48
- return ((_a = component == null ? void 0 : component.$$typeof) == null ? void 0 : _a.toString()) === "Symbol(react.context)";
49
- }
50
- function isProvider(component) {
51
- var _a;
52
- return ((_a = component == null ? void 0 : component.$$typeof) == null ? void 0 : _a.toString()) === "Symbol(react.provider)";
53
- }
54
- function isFragment(component) {
55
- return (component == null ? void 0 : component.toString()) === "Symbol(react.fragment)";
56
- }
57
- function isFunctionComponent(component) {
58
- if (typeof component === "function") {
59
- return true;
60
- }
61
- return isPureFunctionComponent(component);
62
- }
63
- function isPureFunctionComponent(component) {
64
- var _a;
65
- return ((_a = component == null ? void 0 : component.$$typeof) == null ? void 0 : _a.toString()) === "Symbol(react.memo)" && isFunctionComponent(component.type);
66
- }
67
- function isComponentClass(component) {
68
- return typeof component === "object" && typeof (component == null ? void 0 : component["render"]) === "function";
69
- }
70
- function isReactComponent(component) {
71
- return isFunctionComponent(component) || isComponentClass(component) || isFragment(component) || isConsumer(component) || isProvider(component);
72
- }
73
- var isReactComponent_default = isReactComponent;
74
-
75
- // src/createChainOfResponsibility.tsx
76
- function createChainOfResponsibility(options = {}) {
77
- const defaultUseBuildComponentCallback = {
78
- get enhancer() {
79
- return void 0;
80
- },
81
- useBuildComponentCallback(_request, options2) {
82
- if (!(options2 == null ? void 0 : options2.fallbackComponent)) {
83
- throw new Error("This component/hook cannot be used outside of its corresponding <Provider>");
84
- }
85
- return options2.fallbackComponent;
86
- }
87
- };
88
- const context = (0, import_react.createContext)(defaultUseBuildComponentCallback);
89
- function ChainOfResponsibilityProvider({ children, init, middleware }) {
90
- if (!Array.isArray(middleware) || middleware.some((middleware2) => typeof middleware2 !== "function")) {
91
- throw new Error("middleware prop must be an array of functions");
92
- }
93
- const patchedMiddleware = Object.freeze(
94
- middleware ? middleware.map((fn) => (init2) => {
95
- const enhancer2 = fn(init2);
96
- return (next) => (originalRequest) => {
97
- let hasReturned;
98
- const returnValue = enhancer2((nextRequest) => {
99
- if (hasReturned) {
100
- throw new Error("next() cannot be called after the function had returned synchronously");
101
- }
102
- !options.passModifiedRequest && nextRequest !== originalRequest && console.warn(
103
- 'react-chain-of-responsibility: "options.passModifiedRequest" must be set to true to pass a different request object to next().'
104
- );
105
- return next(options.passModifiedRequest ? nextRequest : originalRequest);
106
- })(originalRequest);
107
- hasReturned = true;
108
- if ((0, import_react.isValidElement)(returnValue)) {
109
- throw new Error("middleware must not return React element directly");
110
- } else if (returnValue !== false && returnValue !== null && typeof returnValue !== "undefined" && !isReactComponent_default(returnValue)) {
111
- throw new Error(
112
- "middleware must return false, null, undefined, function component, or class component"
113
- );
114
- }
115
- return returnValue;
116
- };
117
- }) : []
118
- );
119
- const { enhancer: parentEnhancer } = (0, import_react.useContext)(context);
120
- const enhancer = (0, import_react.useMemo)(
121
- () => (
122
- // We are reversing because it is easier to read:
123
- // - With reverse, [a, b, c] will become a(b(c(fn)))
124
- // - Without reverse, [a, b, c] will become c(b(a(fn)))
125
- (0, import_handler_chain.applyMiddleware)(
126
- ...[...patchedMiddleware, ...parentEnhancer ? [() => parentEnhancer] : []]
127
- )(init)
128
- ),
129
- [init, middleware, parentEnhancer]
130
- );
131
- const useBuildComponentCallback2 = (0, import_react.useCallback)(
132
- (request, options2 = {}) => enhancer(() => options2.fallbackComponent)(request) || void 0,
133
- [enhancer]
134
- );
135
- const contextValue = (0, import_react.useMemo)(
136
- () => ({ enhancer, useBuildComponentCallback: useBuildComponentCallback2 }),
137
- [enhancer, useBuildComponentCallback2]
138
- );
139
- return /* @__PURE__ */ import_react.default.createElement(context.Provider, { value: contextValue }, children);
140
- }
141
- const useBuildComponentCallback = () => (0, import_react.useContext)(context).useBuildComponentCallback;
142
- function Proxy2({ fallbackComponent, request, ...props }) {
143
- const enhancer = useBuildComponentCallback();
144
- const Component = enhancer(request, { fallbackComponent });
145
- return Component ? /* @__PURE__ */ import_react.default.createElement(Component, { ...props }) : null;
146
- }
147
- const asMiddleware = (MiddlewareComponent) => (init) => (next) => (request) => {
148
- const RawNextComponent = next(request);
149
- const MiddlewareOf = (props) => {
150
- const middleware = (0, import_react.useMemo)(
151
- () => Object.freeze({
152
- init,
153
- Next: (0, import_react.memo)(
154
- RawNextComponent ? (overridingProps) => /* @__PURE__ */ import_react.default.createElement(RawNextComponent, { ...props, ...overridingProps }) : () => null
155
- ),
156
- request
157
- }),
158
- []
159
- );
160
- return /* @__PURE__ */ import_react.default.createElement(MiddlewareComponent, { ...props, middleware });
161
- };
162
- MiddlewareOf.displayName = `MiddlewareOf<${MiddlewareComponent.displayName || ""}>`;
163
- return (0, import_react.memo)(MiddlewareOf);
164
- };
165
- return Object.freeze({
166
- asMiddleware,
167
- Provider: (0, import_react.memo)(ChainOfResponsibilityProvider),
168
- Proxy: (0, import_react.memo)(Proxy2),
169
- types: Object.freeze({
170
- middlewareComponentProps: void 0,
171
- init: void 0,
172
- middleware: void 0,
173
- props: void 0,
174
- proxyProps: void 0,
175
- request: void 0
176
- }),
177
- useBuildComponentCallback
178
- });
179
- }
180
- var createChainOfResponsibility_default = createChainOfResponsibility;
181
-
182
- // src/createChainOfResponsibilityForFluentUI.tsx
183
- function createChainOfResponsibilityForFluentUI(options) {
184
- const returnValue = createChainOfResponsibility_default(options);
185
- const { Proxy: Proxy2 } = returnValue;
186
- const useBuildRenderFunction = (options2 = {}) => {
187
- const { getKey } = options2;
188
- return (0, import_react2.useCallback)(
189
- (props, defaultRender) => (
190
- // We no longer validate the correctness of this function.
191
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
192
- /* @__PURE__ */ import_react2.default.createElement(Proxy2, { ...props, fallbackComponent: defaultRender, key: getKey == null ? void 0 : getKey(props), request: props })
193
- ),
194
- [getKey]
195
- );
196
- };
197
- return { ...returnValue, useBuildRenderFunction };
198
- }
199
- // Annotate the CommonJS export names for ESM import in node:
200
- 0 && (module.exports = {
201
- createChainOfResponsibilityForFluentUI
202
- });
203
- //# sourceMappingURL=react-chain-of-responsibility.fluentUI.js.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/index.fluentUI.ts","../src/createChainOfResponsibilityForFluentUI.tsx","../src/createChainOfResponsibility.tsx","../src/isReactComponent.ts"],"sourcesContent":["// eslint-disable-next-line import/no-deprecated\nimport createChainOfResponsibilityForFluentUI from './createChainOfResponsibilityForFluentUI.tsx';\n\n// eslint-disable-next-line import/no-deprecated\nexport { createChainOfResponsibilityForFluentUI };\n","import { type IRenderFunction } from '@fluentui/react';\nimport React, { useCallback, type Key } from 'react';\n\nimport createChainOfResponsibility, {\n type CreateChainOfResponsibilityOptions\n} from './createChainOfResponsibility.tsx';\n\ntype UseBuildRenderFunctionOptions<Props> = { getKey?: (props: Props | undefined) => Key };\n\ntype UseBuildRenderFunction<Props> = (options?: UseBuildRenderFunctionOptions<Props>) => IRenderFunction<Props>;\n\n// We are using the props as both \"Request\" and \"Props\".\n// This should eases migration from `onRender` to chain of responsibility.\n// Downside is, web developers could accidentally pass request as props and not honoring props modified by upstreamers.\n\n/**\n * @deprecated Fluent UI v9 no longer use `IRenderFunction` for custom render. We no longer validate the correctness of this function.\n */\nexport default function createChainOfResponsibilityForFluentUI<Props extends object, Init = undefined>(\n options?: CreateChainOfResponsibilityOptions\n): ReturnType<typeof createChainOfResponsibility<Props | undefined, Props, Init>> & {\n useBuildRenderFunction: UseBuildRenderFunction<Props>;\n} {\n // We no longer validate the correctness of this function.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const returnValue = createChainOfResponsibility<Props | undefined, Props, Init>(options as any);\n\n const { Proxy } = returnValue;\n\n const useBuildRenderFunction: UseBuildRenderFunction<Props> = (options = {}) => {\n const { getKey } = options;\n\n return useCallback<IRenderFunction<Props>>(\n (props, defaultRender) => (\n // We no longer validate the correctness of this function.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n <Proxy {...(props as Props)} fallbackComponent={defaultRender as any} key={getKey?.(props)} request={props} />\n ),\n [getKey]\n );\n };\n\n // We no longer validate the correctness of this function.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return { ...returnValue, useBuildRenderFunction } as any;\n}\n","import { applyMiddleware } from 'handler-chain';\nimport React, {\n createContext,\n isValidElement,\n memo,\n useCallback,\n useContext,\n useMemo,\n type ComponentType,\n type PropsWithChildren\n} from 'react';\n\nimport isReactComponent from './isReactComponent.ts';\nimport { type ComponentEnhancer, type ComponentMiddleware } from './types.ts';\n\n// TODO: Simplify to ComponentType<Props> | undefined.\ntype ResultComponent<Props> = ComponentType<Props> | false | null | undefined;\n\ntype UseBuildComponentCallbackOptions<Props> = {\n fallbackComponent?: ResultComponent<Props> | undefined;\n};\n\ninterface UseBuildComponentCallback<Request, Props> {\n (request: Request, options?: undefined | UseBuildComponentCallbackOptions<Props>): ComponentType<Props> | undefined;\n}\n\ntype ProviderContext<Request, Props> = {\n get enhancer(): ComponentEnhancer<Request, Props> | undefined;\n useBuildComponentCallback: UseBuildComponentCallback<Request, Props>;\n};\n\ntype ProviderProps<Request, Props, Init> = PropsWithChildren<{\n middleware: readonly ComponentMiddleware<Request, Props, Init>[];\n}> &\n (Init extends never | void\n ? { readonly init?: undefined }\n : Init extends undefined | void\n ? { readonly init?: Init }\n : { readonly init: Init });\n\ntype ProxyProps<Request, Props extends object> = Props & {\n readonly fallbackComponent?: ComponentType<Props> | undefined;\n readonly request: Request;\n};\n\ntype CreateChainOfResponsibilityOptions = {\n /**\n * Allows a middleware to pass another request object when calling its next middleware. Default is false.\n *\n * However, middleware could modify the request object before calling its next middleware. It is recommended\n * to use Object.freeze() to prevent middleware from modifying the request object.\n */\n readonly passModifiedRequest?: boolean | undefined;\n};\n\ntype AsMiddlewareProps<Request, Props, Init> = {\n readonly init: Init;\n readonly Next: ComponentType<Partial<Props>>;\n readonly request: Request;\n};\n\ntype AsMiddlewareComponentProps<Request, Props, Init> = Props & {\n readonly middleware: AsMiddlewareProps<Request, Props, Init>;\n};\n\ntype ChainOfResponsibility<Request, Props extends object, Init> = {\n readonly asMiddleware: (\n middlewareComponent: ComponentType<AsMiddlewareComponentProps<Request, Props, Init>>\n ) => ComponentMiddleware<Request, Props, Init>;\n readonly Provider: ComponentType<ProviderProps<Request, Props, Init>>;\n readonly Proxy: ComponentType<ProxyProps<Request, Props>>;\n readonly types: {\n readonly init: Init;\n readonly middleware: ComponentMiddleware<Request, Props, Init>;\n readonly middlewareComponentProps: AsMiddlewareComponentProps<Request, Props, Init>;\n readonly props: Props;\n readonly proxyProps: ProxyProps<Request, Props>;\n readonly request: Request;\n };\n readonly useBuildComponentCallback: () => UseBuildComponentCallback<Request, Props>;\n};\n\nfunction createChainOfResponsibility<Request = void, Props extends object = { readonly children?: never }, Init = void>(\n options: CreateChainOfResponsibilityOptions = {}\n): ChainOfResponsibility<Request, Props, Init> {\n const defaultUseBuildComponentCallback: ProviderContext<Request, Props> = {\n get enhancer() {\n return undefined;\n },\n useBuildComponentCallback(_request, options): ComponentType<Props> {\n if (!options?.fallbackComponent) {\n throw new Error('This component/hook cannot be used outside of its corresponding <Provider>');\n }\n\n return options.fallbackComponent;\n }\n };\n\n const context = createContext<ProviderContext<Request, Props>>(defaultUseBuildComponentCallback);\n\n function ChainOfResponsibilityProvider({ children, init, middleware }: ProviderProps<Request, Props, Init>) {\n // TODO: Related to https://github.com/microsoft/TypeScript/issues/17002.\n // typescript@5.2.2 has a bug, Array.isArray() is a type predicate but only works with mutable array, not readonly array.\n // After removing \"as unknown\", `middleware` on the next line become `any[]`.\n if (!Array.isArray(middleware as unknown) || middleware.some(middleware => typeof middleware !== 'function')) {\n throw new Error('middleware prop must be an array of functions');\n }\n\n const patchedMiddleware: readonly ComponentMiddleware<Request, Props, Init>[] = Object.freeze(\n middleware\n ? middleware.map(fn => (init: Init) => {\n const enhancer = fn(init);\n\n return (next: (request: Request) => ComponentType<Props> | false | null | undefined) =>\n (originalRequest: Request) => {\n // False positive: although we did not re-assign the variable from true, it was initialized as undefined.\n // eslint-disable-next-line prefer-const\n let hasReturned: boolean;\n\n const returnValue = enhancer(nextRequest => {\n if (hasReturned) {\n throw new Error('next() cannot be called after the function had returned synchronously');\n }\n\n !options.passModifiedRequest &&\n nextRequest !== originalRequest &&\n console.warn(\n 'react-chain-of-responsibility: \"options.passModifiedRequest\" must be set to true to pass a different request object to next().'\n );\n\n return next(options.passModifiedRequest ? nextRequest : originalRequest);\n })(originalRequest);\n\n hasReturned = true;\n\n if (isValidElement(returnValue)) {\n throw new Error('middleware must not return React element directly');\n } else if (\n returnValue !== false &&\n returnValue !== null &&\n typeof returnValue !== 'undefined' &&\n !isReactComponent(returnValue)\n ) {\n throw new Error(\n 'middleware must return false, null, undefined, function component, or class component'\n );\n }\n\n return returnValue;\n };\n })\n : []\n );\n\n const { enhancer: parentEnhancer } = useContext(context);\n\n const enhancer = useMemo(\n () =>\n // We are reversing because it is easier to read:\n // - With reverse, [a, b, c] will become a(b(c(fn)))\n // - Without reverse, [a, b, c] will become c(b(a(fn)))\n applyMiddleware<ResultComponent<Props>, Request, Init>(\n ...[...patchedMiddleware, ...(parentEnhancer ? [() => parentEnhancer] : [])]\n )(init as Init),\n [init, middleware, parentEnhancer]\n );\n\n const useBuildComponentCallback = useCallback<UseBuildComponentCallback<Request, Props>>(\n (request, options = {}) => enhancer(() => options.fallbackComponent)(request) || undefined,\n [enhancer]\n );\n\n const contextValue = useMemo<ProviderContext<Request, Props>>(\n () => ({ enhancer, useBuildComponentCallback }),\n [enhancer, useBuildComponentCallback]\n );\n\n return <context.Provider value={contextValue}>{children}</context.Provider>;\n }\n\n const useBuildComponentCallback = () => useContext(context).useBuildComponentCallback;\n\n function Proxy({ fallbackComponent, request, ...props }: ProxyProps<Request, Props>) {\n const enhancer = useBuildComponentCallback();\n\n const Component = enhancer(request as Request, { fallbackComponent });\n\n return Component ? <Component {...(props as Props)} /> : null;\n }\n\n const asMiddleware: (\n middlewareComponent: ComponentType<AsMiddlewareComponentProps<Request, Props, Init>>\n ) => ComponentMiddleware<Request, Props, Init> =\n (\n MiddlewareComponent: ComponentType<AsMiddlewareComponentProps<Request, Props, Init>>\n ): ComponentMiddleware<Request, Props, Init> =>\n init =>\n next =>\n request => {\n const RawNextComponent = next(request);\n\n // TODO: Can we pre-build this component during init?\n const MiddlewareOf = (props: Props) => {\n const middleware = useMemo(\n () =>\n Object.freeze({\n init,\n Next: memo<Partial<Props>>(\n RawNextComponent\n ? (overridingProps: Partial<Props>) => <RawNextComponent {...props} {...overridingProps} />\n : () => null\n ),\n request\n }),\n []\n );\n\n return <MiddlewareComponent {...props} middleware={middleware} />;\n };\n\n MiddlewareOf.displayName = `MiddlewareOf<${MiddlewareComponent.displayName || ''}>`;\n\n return memo<Props>(MiddlewareOf);\n };\n\n return Object.freeze({\n asMiddleware,\n Provider: memo<ProviderProps<Request, Props, Init>>(ChainOfResponsibilityProvider),\n Proxy: memo<ProxyProps<Request, Props>>(Proxy),\n types: Object.freeze({\n middlewareComponentProps: undefined as unknown as AsMiddlewareComponentProps<Request, Props, Init>,\n init: undefined as unknown as Init,\n middleware: undefined as unknown as ComponentMiddleware<Request, Props, Init>,\n props: undefined as unknown as Props,\n proxyProps: undefined as unknown as ProxyProps<Request, Props>,\n request: undefined as unknown as Request\n }),\n useBuildComponentCallback\n });\n}\n\nexport default createChainOfResponsibility;\nexport {\n type ChainOfResponsibility,\n type CreateChainOfResponsibilityOptions,\n type ProxyProps,\n type UseBuildComponentCallback\n};\n","import {\n type ComponentClass,\n type ComponentType,\n type Consumer,\n type Fragment,\n type FunctionComponent,\n type Provider\n} from 'react';\nimport { custom } from 'valibot';\n\nfunction isConsumer(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n component: any\n): component is Consumer<unknown> {\n return component?.$$typeof?.toString() === 'Symbol(react.context)';\n}\n\nfunction isProvider(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n component: any\n): component is Provider<unknown> {\n return component?.$$typeof?.toString() === 'Symbol(react.provider)';\n}\n\nfunction isFragment(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n component: any\n): component is typeof Fragment {\n return component?.toString() === 'Symbol(react.fragment)';\n}\n\nfunction isFunctionComponent(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n component: any\n): component is FunctionComponent {\n if (typeof component === 'function') {\n return true;\n }\n\n return isPureFunctionComponent(component);\n}\n\nfunction isPureFunctionComponent(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n component: any\n): component is FunctionComponent {\n return component?.$$typeof?.toString() === 'Symbol(react.memo)' && isFunctionComponent(component.type);\n}\n\nfunction isComponentClass(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n component: any\n): component is ComponentClass {\n return typeof component === 'object' && typeof component?.['render'] === 'function';\n}\n\n// There are no definitive ways to check if an object is a React component or not.\n// We are checking if the object has a render function (classic component).\n// Note: \"forwardRef()\" returns plain object, not class instance.\nfunction isReactComponent(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n component: any\n): component is ComponentType {\n return (\n isFunctionComponent(component) ||\n isComponentClass(component) ||\n isFragment(component) ||\n isConsumer(component) ||\n isProvider(component)\n );\n}\n\nconst reactComponent = () =>\n custom<ComponentType<unknown>>(value => isReactComponent(value), 'not a valid React component');\n\nexport default isReactComponent;\nexport { reactComponent };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,IAAAA,gBAA6C;;;ACD7C,2BAAgC;AAChC,mBASO;;;ACFP,qBAAuB;AAE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B,QAAM,yBAAwD,CAACC,WAAU,CAAC,MAAM;AAC9E,UAAM,EAAE,OAAO,IAAIA;AAEnB,eAAO;AAAA,MACL,CAAC,OAAO;AAAA;AAAA;AAAA,QAGN,8BAAAC,QAAA,cAACF,QAAA,EAAO,GAAI,OAAiB,mBAAmB,eAAsB,KAAK,iCAAS,QAAQ,SAAS,OAAO;AAAA;AAAA,MAE9G,CAAC,MAAM;AAAA,IACT;AAAA,EACF;AAIA,SAAO,EAAE,GAAG,aAAa,uBAAuB;AAClD;","names":["import_react","options","middleware","init","enhancer","useBuildComponentCallback","React","Proxy","Proxy","options","React"]}
@@ -1,26 +0,0 @@
1
- import {
2
- createChainOfResponsibility_default
3
- } from "./chunk-U4UF7NZV.mjs";
4
-
5
- // src/createChainOfResponsibilityForFluentUI.tsx
6
- import React, { useCallback } from "react";
7
- function createChainOfResponsibilityForFluentUI(options) {
8
- const returnValue = createChainOfResponsibility_default(options);
9
- const { Proxy } = returnValue;
10
- const useBuildRenderFunction = (options2 = {}) => {
11
- const { getKey } = options2;
12
- return useCallback(
13
- (props, defaultRender) => (
14
- // We no longer validate the correctness of this function.
15
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
16
- /* @__PURE__ */ React.createElement(Proxy, { ...props, fallbackComponent: defaultRender, key: getKey?.(props), request: props })
17
- ),
18
- [getKey]
19
- );
20
- };
21
- return { ...returnValue, useBuildRenderFunction };
22
- }
23
- export {
24
- createChainOfResponsibilityForFluentUI
25
- };
26
- //# sourceMappingURL=react-chain-of-responsibility.fluentUI.mjs.map
@@ -1 +0,0 @@
1
- {"version":3,"sources":["../src/createChainOfResponsibilityForFluentUI.tsx"],"sourcesContent":["import { type IRenderFunction } from '@fluentui/react';\nimport React, { useCallback, type Key } from 'react';\n\nimport createChainOfResponsibility, {\n type CreateChainOfResponsibilityOptions\n} from './createChainOfResponsibility.tsx';\n\ntype UseBuildRenderFunctionOptions<Props> = { getKey?: (props: Props | undefined) => Key };\n\ntype UseBuildRenderFunction<Props> = (options?: UseBuildRenderFunctionOptions<Props>) => IRenderFunction<Props>;\n\n// We are using the props as both \"Request\" and \"Props\".\n// This should eases migration from `onRender` to chain of responsibility.\n// Downside is, web developers could accidentally pass request as props and not honoring props modified by upstreamers.\n\n/**\n * @deprecated Fluent UI v9 no longer use `IRenderFunction` for custom render. We no longer validate the correctness of this function.\n */\nexport default function createChainOfResponsibilityForFluentUI<Props extends object, Init = undefined>(\n options?: CreateChainOfResponsibilityOptions\n): ReturnType<typeof createChainOfResponsibility<Props | undefined, Props, Init>> & {\n useBuildRenderFunction: UseBuildRenderFunction<Props>;\n} {\n // We no longer validate the correctness of this function.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n const returnValue = createChainOfResponsibility<Props | undefined, Props, Init>(options as any);\n\n const { Proxy } = returnValue;\n\n const useBuildRenderFunction: UseBuildRenderFunction<Props> = (options = {}) => {\n const { getKey } = options;\n\n return useCallback<IRenderFunction<Props>>(\n (props, defaultRender) => (\n // We no longer validate the correctness of this function.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n <Proxy {...(props as Props)} fallbackComponent={defaultRender as any} key={getKey?.(props)} request={props} />\n ),\n [getKey]\n );\n };\n\n // We no longer validate the correctness of this function.\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n return { ...returnValue, useBuildRenderFunction } as any;\n}\n"],"mappings":";;;;;AACA,OAAO,SAAS,mBAA6B;AAiB9B,SAAR,uCACL,SAGA;AAGA,QAAM,cAAc,oCAA4D,OAAc;AAE9F,QAAM,EAAE,MAAM,IAAI;AAElB,QAAM,yBAAwD,CAACA,WAAU,CAAC,MAAM;AAC9E,UAAM,EAAE,OAAO,IAAIA;AAEnB,WAAO;AAAA,MACL,CAAC,OAAO;AAAA;AAAA;AAAA,QAGN,oCAAC,SAAO,GAAI,OAAiB,mBAAmB,eAAsB,KAAK,SAAS,KAAK,GAAG,SAAS,OAAO;AAAA;AAAA,MAE9G,CAAC,MAAM;AAAA,IACT;AAAA,EACF;AAIA,SAAO,EAAE,GAAG,aAAa,uBAAuB;AAClD;","names":["options"]}