react-chain-of-responsibility 0.3.0-main.e6dfb8e → 0.3.1-main.20ef5bb

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.
package/README.md CHANGED
@@ -14,13 +14,13 @@ Click here for [our live demo](https://compulim.github.io/react-chain-of-respons
14
14
 
15
15
  ## How to use?
16
16
 
17
- 3 steps to adopt the chain of responsibility pattern.
17
+ There are 3 steps to adopt the chain of responsibility pattern.
18
18
 
19
19
  1. [Create a chain](#create-a-chain)
20
20
  1. [Register handlers in the chain](#register-handlers-in-the-chain)
21
21
  1. [Make a render request](#make-a-render-request)
22
22
 
23
- In this sample, we will use chain of responsibility pattern to create a file preview UI which can handle various file types.
23
+ In this sample, we will use chain of responsibility pattern to create a file preview UI to handle various file types.
24
24
 
25
25
  ### Create a chain
26
26
 
@@ -77,19 +77,19 @@ const Binary = ({ url }) => <a href={url}>{url}</a>;
77
77
  const middleware = [asMiddleware(Image), asMiddleware(Video), asMiddleware(Binary)];
78
78
  ```
79
79
 
80
- In this sample, 3 middleware are registered:
80
+ In this sample, 3 middleware will be registered in the chain. They will be called based on their order in the array:
81
81
 
82
- - `<Image>` will render `<img>` if content type is `'image/*'`, otherwise, will pass to next middleware (`<Video>`)
83
- - `<Video>` will render `<video>` if content type is `'video/*'`, otherwise, will pass to next middleware (`<Binary>`)
84
- - `<Binary>` is a catch-all and will render as a link
82
+ 1. `<Image>` will render `<img>` if content type is `'image/*'`, otherwise, will pass to next middleware
83
+ 1. `<Video>` will render `<video>` if content type is `'video/*'`, otherwise, will pass to next middleware
84
+ 1. `<Binary>` is a catch-all and will render as a link
85
85
 
86
- Notes: props passed to `<Next>` will override original props, however, `request` cannot be overridden.
86
+ Notes: if props are passed to `<Next>`, they will override the original props. However, `request` cannot be overridden.
87
87
 
88
88
  ### Make a render request
89
89
 
90
- Before calling any components or hooks, the `<Provider>` component must be set up with the chain.
90
+ Before calling any components or hooks, the `<Provider>` component must be initialized with the chain.
91
91
 
92
- When `<Proxy>` is being rendered, it will pass the `request` to the chain. The component returned from the chain will be rendered with `...props`. If no component is returned, it will be rendered as `undefined`.
92
+ When `<Proxy>` is being rendered, it will pass the `request` to the chain. The component returned from the chain will be rendered with `...props`. If no component is returned, it will render `undefined`.
93
93
 
94
94
  ```tsx
95
95
  render(
@@ -115,7 +115,7 @@ For advanced scenario with precise rendering control, use the `useBuildComponent
115
115
 
116
116
  ## How should I use?
117
117
 
118
- Here are some recipes on leveraging the chain of responsibility pattern for UI composition.
118
+ Here are some recipes leveraging the chain of responsibility pattern for UI composition and customization.
119
119
 
120
120
  ### Bring your own component
121
121
 
@@ -180,11 +180,12 @@ For example, in a date picker UI, using the chain of responsibility pattern enab
180
180
  The "which component to render" decision in the middleware enables 4 key customization techniques:
181
181
 
182
182
  - Add a new component
183
- - Register a new `<Audio>` middleware component to handle content type of "audio/\*"
183
+ - Register a new `<Audio>` middleware component to handle content type of `audio/\*`
184
184
  - Replace an existing component
185
- - Register a new `<Image2>` middleware component to handle content type of "image/\*"
185
+ - Register a new `<ImageV2>` middleware component to handle content type of `image/\*`
186
+ - The original `<Image>` will be replaced through starvation
186
187
  - Remove an existing component
187
- - Return `undefined` when handling content type of "video/\*"
188
+ - Return `undefined` when handling content type of `video/\*`
188
189
  - Decorate an existing component
189
190
  - Return a component which render `<div class="my-border"><Next /></div>`
190
191
 
@@ -194,15 +195,15 @@ After a bundle is lazy-loaded, register the component in the middleware.
194
195
 
195
196
  When the chain of the `<Provider>` is updated, the lazy-loaded component will be rendered immediately.
196
197
 
197
- This recipe can also used to build multiple flavors of bundle and allow bundle to be composited to suit the apps need.
198
+ This recipe can also help creating bundles with multiple flavors.
198
199
 
199
200
  ## Advanced usage
200
201
 
201
- ### Registering component using functional pattern
202
+ ### Registering component via functional programming
202
203
 
203
- The `asMiddleware()` is a helper function to turn a React component into a component middleware for simpler registration. As it operates in render-time, there are disadvantages. For example, a VDOM node is always required.
204
+ The `asMiddleware()` is a helper function to turn a React component into a middleware for simpler registration. As it operates in render-time, there are disadvantages. For example, a VDOM node is always required.
204
205
 
205
- If precise rendering control is a requirement, consider registering the component natively using functional programming.
206
+ If precise rendering control is required, consider registering the component natively using functional programming.
206
207
 
207
208
  The following code snippet shows the conversion from the `<Image>` middleware component in our previous sample, into a component registered via functional programming.
208
209
 
@@ -345,13 +346,13 @@ function createChainOfResponsibility<Request = undefined, Props = { children?: n
345
346
 
346
347
  ### Return value
347
348
 
348
- | Name | Description |
349
- | --------------------------- | ------------------------------------------------------------------------------------- |
350
- | `asMiddleware` | A helper function to convert a React component into a middleware. |
351
- | `Provider` | Entrypoint component, must wraps all usage of customizations |
352
- | `Proxy` | Proxy component, process the `request` from props and morph into the result component |
353
- | `types` | TypeScript: shorthand types, all objects are `undefined` intentionally |
354
- | `useBuildComponentCallback` | Callback hook which return a function to build the component for rendering the result |
349
+ | Name | Description |
350
+ | --------------------------- | -------------------------------------------------------------------------------------- |
351
+ | `asMiddleware` | A helper function to convert a React component into a middleware. |
352
+ | `Provider` | Entrypoint component, must wraps all usage of customizations |
353
+ | `Proxy` | Proxy component, process the `request` from props and morph into the result component |
354
+ | `types` | TypeScript: shorthand types, all objects are `undefined` intentionally |
355
+ | `useBuildComponentCallback` | Callback hook which return a function to build the component for rendering the request |
355
356
 
356
357
  ### Options
357
358
 
@@ -366,26 +367,26 @@ type Options = {
366
367
 
367
368
  If `passModifiedRequest` is default or `false`, middleware will not be allowed to pass another reference of `request` object to their `next()` middleware. Instead, the `request` object passed to `next()` will be ignored and the next middleware always receive the original `request` object. This behavior is similar to [Express](https://expressjs.com/) middleware.
368
369
 
369
- Setting to `true` will enable advanced scenarios and allow a middleware to influence their downstreamers.
370
+ Setting to `true` will enable advanced scenarios and allow one middleware to pass another instance of `request` object to influence their downstreamers.
370
371
 
371
- When the option is default or `false`, middleware could still modify the `request` object and influence their downstreamers. It is recommended to follow immutable pattern when handling the `request` object, or use deep [`Object.freeze()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze) to guarantee immutability.
372
+ When the option is default or `false` but the `request` object is mutable, one middleware could still modify the `request` object and influence their downstreamers. It is recommended to follow immutable pattern when handling the `request` object, or use deep [`Object.freeze()`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Object/freeze) to guarantee immutability.
372
373
 
373
374
  ### API of `asMiddleware`
374
375
 
376
+ `asMiddleware` wraps a React component into a middleware. Build will be done through additional `middleware` prop.
377
+
375
378
  ```ts
376
379
  function asMiddleware(
377
380
  middlewareComponent: ComponentType<MiddlewareComponentProps<Request, Props, Init>>
378
381
  ): ComponentMiddleware<Request, Props, Init>;
379
382
 
380
- type MiddlewareProps<Request, Props, Init> = Readonly<{
381
- init: Init;
382
- Next: ComponentType<Partial<Props>>;
383
- request: Request;
384
- }>;
385
-
386
383
  type MiddlewareComponentProps<Request, Props, Init> = Props &
387
384
  Readonly<{
388
- middleware: MiddlewareProps<Request, Props, Init>
385
+ middleware: Readonly<{
386
+ init: Init;
387
+ Next: ComponentType<Partial<Props>>;
388
+ request: Request;
389
+ }>
389
390
  }>;
390
391
  ```
391
392
 
@@ -400,9 +401,9 @@ type UseBuildComponentCallback<Request, Props> = (
400
401
  ) => ComponentType<Props> | undefined;
401
402
  ```
402
403
 
403
- For simplicity, instead of returning a component or `false`/`null`/`undefined`, the `useBuildComponentCallback` will only return a component or `undefined`.
404
+ For simplicity, instead of returning a React component or `false`/`null`/`undefined`, the `useBuildComponentCallback` will only return a React component or `undefined`.
404
405
 
405
- The `fallbackComponent` is a component which all unhandled requests will sink into, including calls without ancestral `<Provider>`.
406
+ The `fallbackComponent` is a component which all unhandled requests will sink into, including calls outside of `<Provider>`.
406
407
 
407
408
  ### API for Fluent UI
408
409
 
@@ -432,7 +433,7 @@ When rendering the element, `getKey` is called to compute the `key` attribute. T
432
433
 
433
434
  ## Designs
434
435
 
435
- ### What is the difference between request, and props?
436
+ ### How can I choose between request and props?
436
437
 
437
438
  - Request is for *appearance*, while props is for *content*
438
439
  - Request is for *deciding which component to render*, while props is for *what to render*
@@ -10,15 +10,13 @@ import React, {
10
10
 
11
11
  // src/isReactComponent.ts
12
12
  function isConsumer(component) {
13
- var _a;
14
- return ((_a = component == null ? void 0 : component.$$typeof) == null ? void 0 : _a.toString()) === "Symbol(react.context)";
13
+ return component?.$$typeof?.toString() === "Symbol(react.context)";
15
14
  }
16
15
  function isProvider(component) {
17
- var _a;
18
- return ((_a = component == null ? void 0 : component.$$typeof) == null ? void 0 : _a.toString()) === "Symbol(react.provider)";
16
+ return component?.$$typeof?.toString() === "Symbol(react.provider)";
19
17
  }
20
18
  function isFragment(component) {
21
- return (component == null ? void 0 : component.toString()) === "Symbol(react.fragment)";
19
+ return component?.toString() === "Symbol(react.fragment)";
22
20
  }
23
21
  function isFunctionComponent(component) {
24
22
  if (typeof component === "function") {
@@ -27,11 +25,10 @@ function isFunctionComponent(component) {
27
25
  return isPureFunctionComponent(component);
28
26
  }
29
27
  function isPureFunctionComponent(component) {
30
- var _a;
31
- return ((_a = component == null ? void 0 : component.$$typeof) == null ? void 0 : _a.toString()) === "Symbol(react.memo)" && isFunctionComponent(component.type);
28
+ return component?.$$typeof?.toString() === "Symbol(react.memo)" && isFunctionComponent(component.type);
32
29
  }
33
30
  function isComponentClass(component) {
34
- return typeof component === "object" && typeof (component == null ? void 0 : component["render"]) === "function";
31
+ return typeof component === "object" && typeof component?.["render"] === "function";
35
32
  }
36
33
  function isReactComponent(component) {
37
34
  return isFunctionComponent(component) || isComponentClass(component) || isFragment(component) || isConsumer(component) || isProvider(component);
@@ -57,7 +54,7 @@ function createChainOfResponsibility(options = {}) {
57
54
  return void 0;
58
55
  },
59
56
  useBuildComponentCallback(_, options2) {
60
- if (options2 == null ? void 0 : options2.fallbackComponent) {
57
+ if (options2?.fallbackComponent) {
61
58
  return options2.fallbackComponent;
62
59
  }
63
60
  throw new Error("This component/hook cannot be used outside of its corresponding <Provider>");
@@ -158,4 +155,4 @@ function createChainOfResponsibility(options = {}) {
158
155
  export {
159
156
  createChainOfResponsibility
160
157
  };
161
- //# sourceMappingURL=chunk-RAUACXXD.mjs.map
158
+ //# sourceMappingURL=chunk-LPY4PJSC.mjs.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/createChainOfResponsibility.tsx","../src/isReactComponent.ts","../src/private/compose.ts","../src/private/applyMiddleware.ts"],"sourcesContent":["import 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 applyMiddleware, { type Enhancer } from './private/applyMiddleware.ts';\nimport { 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> = { fallbackComponent?: ResultComponent<Props> };\n\ntype UseBuildComponentCallback<Request, Props> = (\n request: Request,\n options?: UseBuildComponentCallbackOptions<Props>\n) => ComponentType<Props> | undefined;\n\ntype ProviderContext<Request, Props> = {\n get enhancer(): Enhancer<[Request], ResultComponent<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 ? { init?: undefined } : Init extends undefined ? { init?: Init } : { init: Init });\n\ntype ProxyProps<Request, Props extends object> = PropsWithChildren<\n Request extends never | void\n ? Props & { fallbackComponent?: ComponentType<Props>; request?: undefined }\n : Request extends undefined\n ? Props & { fallbackComponent?: ComponentType<Props>; request?: Request }\n : Props & { fallbackComponent?: ComponentType<Props>; request: Request }\n>;\n\ntype Options = {\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 passModifiedRequest?: boolean;\n};\n\ntype MiddlewareProps<Request, Props, Init> = Readonly<{\n init: Init;\n Next: ComponentType<Partial<Props>>;\n request: Request;\n}>;\n\ntype MiddlewareComponentProps<Request, Props, Init> = Props &\n Readonly<{ middleware: MiddlewareProps<Request, Props, Init> }>;\n\nexport default function createChainOfResponsibility<\n Request = undefined,\n Props extends object = Readonly<{ children?: never }>,\n Init = undefined\n>(\n options: Options = {}\n): {\n asMiddleware: (\n middlewareComponent: ComponentType<MiddlewareComponentProps<Request, Props, Init>>\n ) => ComponentMiddleware<Request, Props, Init>;\n Provider: ComponentType<ProviderProps<Request, Props, Init>>;\n Proxy: ComponentType<ProxyProps<Request, Props>>;\n types: {\n init: Init;\n middleware: ComponentMiddleware<Request, Props, Init>;\n middlewareComponentProps: MiddlewareComponentProps<Request, Props, Init>;\n props: Props;\n request: Request;\n };\n useBuildComponentCallback: () => UseBuildComponentCallback<Request, Props>;\n} {\n const defaultUseBuildComponentCallback: ProviderContext<Request, Props> = {\n get enhancer() {\n return undefined;\n },\n useBuildComponentCallback(_, options) {\n if (options?.fallbackComponent) {\n return options.fallbackComponent;\n }\n\n throw new Error('This component/hook cannot be used outside of its corresponding <Provider>');\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<[Request], ResultComponent<Props>, [Init]>(\n ...[...patchedMiddleware, ...(parentEnhancer ? [() => parentEnhancer] : [])].reverse()\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({ children, fallbackComponent, request, ...props }: ProxyProps<Request, Props>) {\n const enhancer = useBuildComponentCallback();\n const Component = enhancer(request as Request, { fallbackComponent });\n\n return Component ? <Component {...(props as Props)}>{children}</Component> : null;\n }\n\n const asMiddleware: (\n middlewareComponent: ComponentType<MiddlewareComponentProps<Request, Props, Init>>\n ) => ComponentMiddleware<Request, Props, Init> =\n (\n MiddlewareComponent: ComponentType<MiddlewareComponentProps<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 {\n asMiddleware,\n Provider: memo<ProviderProps<Request, Props, Init>>(ChainOfResponsibilityProvider),\n Proxy: memo<ProxyProps<Request, Props>>(Proxy),\n types: {\n middlewareComponentProps: undefined as unknown as MiddlewareComponentProps<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 request: undefined as unknown as Request\n },\n useBuildComponentCallback\n };\n}\n","import {\n type ComponentClass,\n type ComponentType,\n type Consumer,\n type Fragment,\n type FunctionComponent,\n type Provider\n} from 'react';\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.\nexport default function 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","// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Fn<P extends any[], R> = (...args: P) => R;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Enhancer<P extends any[], R> = (next: Fn<P, R>) => Fn<P, R>;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport default function compose<P extends any[], R>(...fns: Enhancer<P, R>[]): Enhancer<P, R> {\n return (fn: Fn<P, R>): Fn<P, R> => fns.reduce((chain, fn) => fn(chain), fn);\n}\n","import compose from './compose.ts';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Fn<P extends any[], R> = (...args: P) => R;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type Enhancer<P extends any[], R> = (next: Fn<P, R>) => Fn<P, R>;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type Middleware<P extends any[], R, S extends any[]> = (...init: S) => Enhancer<P, R>;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport default function applyMiddleware<P extends any[], R, S extends any[]>(\n ...arrayOfMiddleware: Middleware<P, R, S>[]\n) {\n return (...init: S) => {\n const chain = arrayOfMiddleware.map(middleware => middleware(...init));\n\n return compose(...chain);\n };\n}\n"],"mappings":";AAAA,OAAO;AAAA,EACL;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;;;ACAP,SAAS,WAEP,WACgC;AAZlC;AAaE,WAAO,4CAAW,aAAX,mBAAqB,gBAAe;AAC7C;AAEA,SAAS,WAEP,WACgC;AAnBlC;AAoBE,WAAO,4CAAW,aAAX,mBAAqB,gBAAe;AAC7C;AAEA,SAAS,WAEP,WAC8B;AAC9B,UAAO,uCAAW,gBAAe;AACnC;AAEA,SAAS,oBAEP,WACgC;AAChC,MAAI,OAAO,cAAc,YAAY;AACnC,WAAO;AAAA,EACT;AAEA,SAAO,wBAAwB,SAAS;AAC1C;AAEA,SAAS,wBAEP,WACgC;AA5ClC;AA6CE,WAAO,4CAAW,aAAX,mBAAqB,gBAAe,wBAAwB,oBAAoB,UAAU,IAAI;AACvG;AAEA,SAAS,iBAEP,WAC6B;AAC7B,SAAO,OAAO,cAAc,YAAY,QAAO,uCAAY,eAAc;AAC3E;AAKe,SAAR,iBAEL,WAC4B;AAC5B,SACE,oBAAoB,SAAS,KAC7B,iBAAiB,SAAS,KAC1B,WAAW,SAAS,KACpB,WAAW,SAAS,KACpB,WAAW,SAAS;AAExB;;;AC9De,SAAR,WAAgD,KAAuC;AAC5F,SAAO,CAAC,OAA2B,IAAI,OAAO,CAAC,OAAOA,QAAOA,IAAG,KAAK,GAAG,EAAE;AAC5E;;;ACGe,SAAR,mBACF,mBACH;AACA,SAAO,IAAI,SAAY;AACrB,UAAM,QAAQ,kBAAkB,IAAI,gBAAc,WAAW,GAAG,IAAI,CAAC;AAErE,WAAO,QAAQ,GAAG,KAAK;AAAA,EACzB;AACF;;;AH0Ce,SAAR,4BAKL,UAAmB,CAAC,GAepB;AACA,QAAM,mCAAoE;AAAA,IACxE,IAAI,WAAW;AACb,aAAO;AAAA,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AAO;AAAA,IACL;AAAA,IACA,UAAU,KAA0C,6BAA6B;AAAA,IACjF,OAAO,KAAiC,KAAK;AAAA,IAC7C,OAAO;AAAA,MACL,0BAA0B;AAAA,MAC1B,MAAM;AAAA,MACN,YAAY;AAAA,MACZ,OAAO;AAAA,MACP,SAAS;AAAA,IACX;AAAA,IACA;AAAA,EACF;AACF;","names":["fn","options","middleware","init","enhancer","useBuildComponentCallback"]}
1
+ {"version":3,"sources":["../src/createChainOfResponsibility.tsx","../src/isReactComponent.ts","../src/private/compose.ts","../src/private/applyMiddleware.ts"],"sourcesContent":["import 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 applyMiddleware, { type Enhancer } from './private/applyMiddleware.ts';\nimport { 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> = { fallbackComponent?: ResultComponent<Props> };\n\ntype UseBuildComponentCallback<Request, Props> = (\n request: Request,\n options?: UseBuildComponentCallbackOptions<Props>\n) => ComponentType<Props> | undefined;\n\ntype ProviderContext<Request, Props> = {\n get enhancer(): Enhancer<[Request], ResultComponent<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 ? { init?: undefined } : Init extends undefined ? { init?: Init } : { init: Init });\n\ntype ProxyProps<Request, Props extends object> = PropsWithChildren<\n Request extends never | void\n ? Props & { fallbackComponent?: ComponentType<Props>; request?: undefined }\n : Request extends undefined\n ? Props & { fallbackComponent?: ComponentType<Props>; request?: Request }\n : Props & { fallbackComponent?: ComponentType<Props>; request: Request }\n>;\n\ntype Options = {\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 passModifiedRequest?: boolean;\n};\n\ntype MiddlewareProps<Request, Props, Init> = Readonly<{\n init: Init;\n Next: ComponentType<Partial<Props>>;\n request: Request;\n}>;\n\ntype MiddlewareComponentProps<Request, Props, Init> = Props &\n Readonly<{ middleware: MiddlewareProps<Request, Props, Init> }>;\n\nexport default function createChainOfResponsibility<\n Request = undefined,\n Props extends object = Readonly<{ children?: never }>,\n Init = undefined\n>(\n options: Options = {}\n): {\n asMiddleware: (\n middlewareComponent: ComponentType<MiddlewareComponentProps<Request, Props, Init>>\n ) => ComponentMiddleware<Request, Props, Init>;\n Provider: ComponentType<ProviderProps<Request, Props, Init>>;\n Proxy: ComponentType<ProxyProps<Request, Props>>;\n types: {\n init: Init;\n middleware: ComponentMiddleware<Request, Props, Init>;\n middlewareComponentProps: MiddlewareComponentProps<Request, Props, Init>;\n props: Props;\n request: Request;\n };\n useBuildComponentCallback: () => UseBuildComponentCallback<Request, Props>;\n} {\n const defaultUseBuildComponentCallback: ProviderContext<Request, Props> = {\n get enhancer() {\n return undefined;\n },\n useBuildComponentCallback(_, options) {\n if (options?.fallbackComponent) {\n return options.fallbackComponent;\n }\n\n throw new Error('This component/hook cannot be used outside of its corresponding <Provider>');\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<[Request], ResultComponent<Props>, [Init]>(\n ...[...patchedMiddleware, ...(parentEnhancer ? [() => parentEnhancer] : [])].reverse()\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({ children, fallbackComponent, request, ...props }: ProxyProps<Request, Props>) {\n const enhancer = useBuildComponentCallback();\n const Component = enhancer(request as Request, { fallbackComponent });\n\n return Component ? <Component {...(props as Props)}>{children}</Component> : null;\n }\n\n const asMiddleware: (\n middlewareComponent: ComponentType<MiddlewareComponentProps<Request, Props, Init>>\n ) => ComponentMiddleware<Request, Props, Init> =\n (\n MiddlewareComponent: ComponentType<MiddlewareComponentProps<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 {\n asMiddleware,\n Provider: memo<ProviderProps<Request, Props, Init>>(ChainOfResponsibilityProvider),\n Proxy: memo<ProxyProps<Request, Props>>(Proxy),\n types: {\n middlewareComponentProps: undefined as unknown as MiddlewareComponentProps<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 request: undefined as unknown as Request\n },\n useBuildComponentCallback\n };\n}\n","import {\n type ComponentClass,\n type ComponentType,\n type Consumer,\n type Fragment,\n type FunctionComponent,\n type Provider\n} from 'react';\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.\nexport default function 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","// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Fn<P extends any[], R> = (...args: P) => R;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Enhancer<P extends any[], R> = (next: Fn<P, R>) => Fn<P, R>;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport default function compose<P extends any[], R>(...fns: Enhancer<P, R>[]): Enhancer<P, R> {\n return (fn: Fn<P, R>): Fn<P, R> => fns.reduce((chain, fn) => fn(chain), fn);\n}\n","import compose from './compose.ts';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Fn<P extends any[], R> = (...args: P) => R;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type Enhancer<P extends any[], R> = (next: Fn<P, R>) => Fn<P, R>;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type Middleware<P extends any[], R, S extends any[]> = (...init: S) => Enhancer<P, R>;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport default function applyMiddleware<P extends any[], R, S extends any[]>(\n ...arrayOfMiddleware: Middleware<P, R, S>[]\n) {\n return (...init: S) => {\n const chain = arrayOfMiddleware.map(middleware => middleware(...init));\n\n return compose(...chain);\n };\n}\n"],"mappings":";AAAA,OAAO;AAAA,EACL;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;;;ACAP,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;AACnC;AAEA,SAAS,oBAEP,WACgC;AAChC,MAAI,OAAO,cAAc,YAAY;AACnC,WAAO;AAAA,EACT;AAEA,SAAO,wBAAwB,SAAS;AAC1C;AAEA,SAAS,wBAEP,WACgC;AAChC,SAAO,WAAW,UAAU,SAAS,MAAM,wBAAwB,oBAAoB,UAAU,IAAI;AACvG;AAEA,SAAS,iBAEP,WAC6B;AAC7B,SAAO,OAAO,cAAc,YAAY,OAAO,YAAY,QAAQ,MAAM;AAC3E;AAKe,SAAR,iBAEL,WAC4B;AAC5B,SACE,oBAAoB,SAAS,KAC7B,iBAAiB,SAAS,KAC1B,WAAW,SAAS,KACpB,WAAW,SAAS,KACpB,WAAW,SAAS;AAExB;;;AC9De,SAAR,WAAgD,KAAuC;AAC5F,SAAO,CAAC,OAA2B,IAAI,OAAO,CAAC,OAAOA,QAAOA,IAAG,KAAK,GAAG,EAAE;AAC5E;;;ACGe,SAAR,mBACF,mBACH;AACA,SAAO,IAAI,SAAY;AACrB,UAAM,QAAQ,kBAAkB,IAAI,gBAAc,WAAW,GAAG,IAAI,CAAC;AAErE,WAAO,QAAQ,GAAG,KAAK;AAAA,EACzB;AACF;;;AH0Ce,SA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c,gBAAgB,oBAAoB,eAAe,EAAE;AAEhF,WAAO,KAAY,YAAY;AAAA,EACjC;AAEF,SAAO;AAAA,IACL;AAAA,IACA,UAAU,KAA0C,6BAA6B;AAAA,IACjF,OAAO,KAAiC,KAAK;AAAA,IAC7C,OAAO;AAAA,MACL,0BAA0B;AAAA,MAC1B,MAAM;AAAA,MACN,YAAY;AAAA,MACZ,OAAO;AAAA,MACP,SAAS;AAAA,IACX;AAAA,IACA;AAAA,EACF;AACF;","names":["fn","options","middleware","init","enhancer","useBuildComponentCallback"]}
@@ -42,15 +42,13 @@ var import_react = __toESM(require("react"));
42
42
 
43
43
  // src/isReactComponent.ts
44
44
  function isConsumer(component) {
45
- var _a;
46
- return ((_a = component == null ? void 0 : component.$$typeof) == null ? void 0 : _a.toString()) === "Symbol(react.context)";
45
+ return component?.$$typeof?.toString() === "Symbol(react.context)";
47
46
  }
48
47
  function isProvider(component) {
49
- var _a;
50
- return ((_a = component == null ? void 0 : component.$$typeof) == null ? void 0 : _a.toString()) === "Symbol(react.provider)";
48
+ return component?.$$typeof?.toString() === "Symbol(react.provider)";
51
49
  }
52
50
  function isFragment(component) {
53
- return (component == null ? void 0 : component.toString()) === "Symbol(react.fragment)";
51
+ return component?.toString() === "Symbol(react.fragment)";
54
52
  }
55
53
  function isFunctionComponent(component) {
56
54
  if (typeof component === "function") {
@@ -59,11 +57,10 @@ function isFunctionComponent(component) {
59
57
  return isPureFunctionComponent(component);
60
58
  }
61
59
  function isPureFunctionComponent(component) {
62
- var _a;
63
- return ((_a = component == null ? void 0 : component.$$typeof) == null ? void 0 : _a.toString()) === "Symbol(react.memo)" && isFunctionComponent(component.type);
60
+ return component?.$$typeof?.toString() === "Symbol(react.memo)" && isFunctionComponent(component.type);
64
61
  }
65
62
  function isComponentClass(component) {
66
- return typeof component === "object" && typeof (component == null ? void 0 : component["render"]) === "function";
63
+ return typeof component === "object" && typeof component?.["render"] === "function";
67
64
  }
68
65
  function isReactComponent(component) {
69
66
  return isFunctionComponent(component) || isComponentClass(component) || isFragment(component) || isConsumer(component) || isProvider(component);
@@ -89,7 +86,7 @@ function createChainOfResponsibility(options = {}) {
89
86
  return void 0;
90
87
  },
91
88
  useBuildComponentCallback(_, options2) {
92
- if (options2 == null ? void 0 : options2.fallbackComponent) {
89
+ if (options2?.fallbackComponent) {
93
90
  return options2.fallbackComponent;
94
91
  }
95
92
  throw new Error("This component/hook cannot be used outside of its corresponding <Provider>");
@@ -194,7 +191,7 @@ function createChainOfResponsibilityForFluentUI(options) {
194
191
  const useBuildRenderFunction = (options2 = {}) => {
195
192
  const { getKey } = options2;
196
193
  return (0, import_react2.useCallback)(
197
- (props, defaultRender) => /* @__PURE__ */ import_react2.default.createElement(Proxy2, { ...props, fallbackComponent: defaultRender, key: getKey == null ? void 0 : getKey(props), request: props }),
194
+ (props, defaultRender) => /* @__PURE__ */ import_react2.default.createElement(Proxy2, { ...props, fallbackComponent: defaultRender, key: getKey?.(props), request: props }),
198
195
  [getKey]
199
196
  );
200
197
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.fluentUI.ts","../src/createChainOfResponsibilityForFluentUI.tsx","../src/createChainOfResponsibility.tsx","../src/isReactComponent.ts","../src/private/compose.ts","../src/private/applyMiddleware.ts"],"sourcesContent":["import createChainOfResponsibilityForFluentUI from './createChainOfResponsibilityForFluentUI.tsx';\n\nexport { createChainOfResponsibilityForFluentUI };\n","import { type IRenderFunction } from '@fluentui/react';\nimport React, { useCallback, type Key } from 'react';\n\nimport createChainOfResponsibility 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.\nexport default function createChainOfResponsibilityForFluentUI<Props extends object, Init = undefined>(\n options?: Parameters<typeof createChainOfResponsibility>[0]\n): ReturnType<typeof createChainOfResponsibility<Props | undefined, Props, Init>> & {\n useBuildRenderFunction: UseBuildRenderFunction<Props>;\n} {\n const returnValue = createChainOfResponsibility<Props | undefined, Props, Init>(options);\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 <Proxy {...(props as Props)} fallbackComponent={defaultRender} key={getKey?.(props)} request={props} />\n ),\n [getKey]\n );\n };\n\n return { ...returnValue, useBuildRenderFunction };\n}\n","import 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 applyMiddleware, { type Enhancer } from './private/applyMiddleware.ts';\nimport { 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> = { fallbackComponent?: ResultComponent<Props> };\n\ntype UseBuildComponentCallback<Request, Props> = (\n request: Request,\n options?: UseBuildComponentCallbackOptions<Props>\n) => ComponentType<Props> | undefined;\n\ntype ProviderContext<Request, Props> = {\n get enhancer(): Enhancer<[Request], ResultComponent<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 ? { init?: undefined } : Init extends undefined ? { init?: Init } : { init: Init });\n\ntype ProxyProps<Request, Props extends object> = PropsWithChildren<\n Request extends never | void\n ? Props & { fallbackComponent?: ComponentType<Props>; request?: undefined }\n : Request extends undefined\n ? Props & { fallbackComponent?: ComponentType<Props>; request?: Request }\n : Props & { fallbackComponent?: ComponentType<Props>; request: Request }\n>;\n\ntype Options = {\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 passModifiedRequest?: boolean;\n};\n\ntype MiddlewareProps<Request, Props, Init> = Readonly<{\n init: Init;\n Next: ComponentType<Partial<Props>>;\n request: Request;\n}>;\n\ntype MiddlewareComponentProps<Request, Props, Init> = Props &\n Readonly<{ middleware: MiddlewareProps<Request, Props, Init> }>;\n\nexport default function createChainOfResponsibility<\n Request = undefined,\n Props extends object = Readonly<{ children?: never }>,\n Init = undefined\n>(\n options: Options = {}\n): {\n asMiddleware: (\n middlewareComponent: ComponentType<MiddlewareComponentProps<Request, Props, Init>>\n ) => ComponentMiddleware<Request, Props, Init>;\n Provider: ComponentType<ProviderProps<Request, Props, Init>>;\n Proxy: ComponentType<ProxyProps<Request, Props>>;\n types: {\n init: Init;\n middleware: ComponentMiddleware<Request, Props, Init>;\n middlewareComponentProps: MiddlewareComponentProps<Request, Props, Init>;\n props: Props;\n request: Request;\n };\n useBuildComponentCallback: () => UseBuildComponentCallback<Request, Props>;\n} {\n const defaultUseBuildComponentCallback: ProviderContext<Request, Props> = {\n get enhancer() {\n return undefined;\n },\n useBuildComponentCallback(_, options) {\n if (options?.fallbackComponent) {\n return options.fallbackComponent;\n }\n\n throw new Error('This component/hook cannot be used outside of its corresponding <Provider>');\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<[Request], ResultComponent<Props>, [Init]>(\n ...[...patchedMiddleware, ...(parentEnhancer ? [() => parentEnhancer] : [])].reverse()\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({ children, fallbackComponent, request, ...props }: ProxyProps<Request, Props>) {\n const enhancer = useBuildComponentCallback();\n const Component = enhancer(request as Request, { fallbackComponent });\n\n return Component ? <Component {...(props as Props)}>{children}</Component> : null;\n }\n\n const asMiddleware: (\n middlewareComponent: ComponentType<MiddlewareComponentProps<Request, Props, Init>>\n ) => ComponentMiddleware<Request, Props, Init> =\n (\n MiddlewareComponent: ComponentType<MiddlewareComponentProps<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 {\n asMiddleware,\n Provider: memo<ProviderProps<Request, Props, Init>>(ChainOfResponsibilityProvider),\n Proxy: memo<ProxyProps<Request, Props>>(Proxy),\n types: {\n middlewareComponentProps: undefined as unknown as MiddlewareComponentProps<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 request: undefined as unknown as Request\n },\n useBuildComponentCallback\n };\n}\n","import {\n type ComponentClass,\n type ComponentType,\n type Consumer,\n type Fragment,\n type FunctionComponent,\n type Provider\n} from 'react';\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.\nexport default function 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","// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Fn<P extends any[], R> = (...args: P) => R;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Enhancer<P extends any[], R> = (next: Fn<P, R>) => Fn<P, R>;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport default function compose<P extends any[], R>(...fns: Enhancer<P, R>[]): Enhancer<P, R> {\n return (fn: Fn<P, R>): Fn<P, R> => fns.reduce((chain, fn) => fn(chain), fn);\n}\n","import compose from './compose.ts';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Fn<P extends any[], R> = (...args: P) => R;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type Enhancer<P extends any[], R> = (next: Fn<P, R>) => Fn<P, R>;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type Middleware<P extends any[], R, S extends any[]> = (...init: S) => Enhancer<P, R>;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport default function applyMiddleware<P extends any[], R, S extends any[]>(\n ...arrayOfMiddleware: Middleware<P, R, S>[]\n) {\n return (...init: S) => {\n const chain = arrayOfMiddleware.map(middleware => middleware(...init));\n\n return compose(...chain);\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,IAAAA,gBAA6C;;;ACD7C,mBASO;;;ACAP,SAAS,WAEP,WACgC;AAZlC;AAaE,WAAO,4CAAW,aAAX,mBAAqB,gBAAe;AAC7C;AAEA,SAAS,WAEP,WACgC;AAnBlC;AAoBE,WAAO,4CAAW,aAAX,mBAAqB,gBAAe;AAC7C;AAEA,SAAS,WAEP,WAC8B;AAC9B,UAAO,uCAAW,gBAAe;AACnC;AAEA,SAAS,oBAEP,WACgC;AAChC,MAAI,OAAO,cAAc,YAAY;AACnC,WAAO;AAAA,EACT;AAEA,SAAO,wBAAwB,SAAS;AAC1C;AAEA,SAAS,wBAEP,WACgC;AA5ClC;AA6CE,WAAO,4CAAW,aAAX,mBAAqB,gBAAe,wBAAwB,oBAAoB,UAAU,IAAI;AACvG;AAEA,SAAS,iBAEP,WAC6B;AAC7B,SAAO,OAAO,cAAc,YAAY,QAAO,uCAAY,eAAc;AAC3E;AAKe,SAAR,iBAEL,WAC4B;AAC5B,SACE,oBAAoB,SAAS,KAC7B,iBAAiB,SAAS,KAC1B,WAAW,SAAS,KACpB,WAAW,SAAS,KACpB,WAAW,SAAS;AAExB;;;AC9De,SAAR,WAAgD,KAAuC;AAC5F,SAAO,CAAC,OAA2B,IAAI,OAAO,CAAC,OAAOC,QAAOA,IAAG,KAAK,GAAG,EAAE;AAC5E;;;ACGe,SAAR,mBACF,mBACH;AACA,SAAO,IAAI,SAAY;AACrB,UAAM,QAAQ,kBAAkB,IAAI,gBAAc,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AAM;AAAA,UACZ;AAAA,UACA;AAAA,QACF,CAAC;AAAA,QACH,CAAC;AAAA,MACH;AAEA,aAAO,6BAAAA,QAAA,cAAC,uBAAqB,GAAG,OAAO,YAAwB;AAAA,IACjE;AAEA,iBAAa,cAAc,gBAAgB,oBAAoB,eAAe,EAAE;AAEhF,eAAO,mBAAY,YAAY;AAAA,EACjC;AAEF,SAAO;AAAA,IACL;AAAA,IACA,cAAU,mBAA0C,6BAA6B;AAAA,IACjF,WAAO,mBAAiCC,MAAK;AAAA,IAC7C,OAAO;AAAA,MACL,0BAA0B;AAAA,MAC1B,MAAM;AAAA,MACN,YAAY;AAAA,MACZ,OAAO;AAAA,MACP,SAAS;AAAA,IACX;AAAA,IACA;AAAA,EACF;AACF;;;AD/Ne,SAAR,uCACL,SAGA;AACA,QAAM,cAAc,4BAA4D,OAAO;AAEvF,QAAM,EAAE,OAAAC,OAAM,IAAI;AAElB,QAAM,yBAAwD,CAACC,WAAU,CAAC,MAAM;AAC9E,UAAM,EAAE,OAAO,IAAIA;AAEnB,eAAO;AAAA,MACL,CAAC,OAAO,kBACN,8BAAAC,QAAA,cAACF,QAAA,EAAO,GAAI,OAAiB,mBAAmB,eAAe,KAAK,iCAAS,QAAQ,SAAS,OAAO;AAAA,MAEvG,CAAC,MAAM;AAAA,IACT;AAAA,EACF;AAEA,SAAO,EAAE,GAAG,aAAa,uBAAuB;AAClD;","names":["import_react","fn","options","middleware","init","enhancer","useBuildComponentCallback","React","Proxy","Proxy","options","React"]}
1
+ {"version":3,"sources":["../src/index.fluentUI.ts","../src/createChainOfResponsibilityForFluentUI.tsx","../src/createChainOfResponsibility.tsx","../src/isReactComponent.ts","../src/private/compose.ts","../src/private/applyMiddleware.ts"],"sourcesContent":["import createChainOfResponsibilityForFluentUI from './createChainOfResponsibilityForFluentUI.tsx';\n\nexport { createChainOfResponsibilityForFluentUI };\n","import { type IRenderFunction } from '@fluentui/react';\nimport React, { useCallback, type Key } from 'react';\n\nimport createChainOfResponsibility 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.\nexport default function createChainOfResponsibilityForFluentUI<Props extends object, Init = undefined>(\n options?: Parameters<typeof createChainOfResponsibility>[0]\n): ReturnType<typeof createChainOfResponsibility<Props | undefined, Props, Init>> & {\n useBuildRenderFunction: UseBuildRenderFunction<Props>;\n} {\n const returnValue = createChainOfResponsibility<Props | undefined, Props, Init>(options);\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 <Proxy {...(props as Props)} fallbackComponent={defaultRender} key={getKey?.(props)} request={props} />\n ),\n [getKey]\n );\n };\n\n return { ...returnValue, useBuildRenderFunction };\n}\n","import 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 applyMiddleware, { type Enhancer } from './private/applyMiddleware.ts';\nimport { 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> = { fallbackComponent?: ResultComponent<Props> };\n\ntype UseBuildComponentCallback<Request, Props> = (\n request: Request,\n options?: UseBuildComponentCallbackOptions<Props>\n) => ComponentType<Props> | undefined;\n\ntype ProviderContext<Request, Props> = {\n get enhancer(): Enhancer<[Request], ResultComponent<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 ? { init?: undefined } : Init extends undefined ? { init?: Init } : { init: Init });\n\ntype ProxyProps<Request, Props extends object> = PropsWithChildren<\n Request extends never | void\n ? Props & { fallbackComponent?: ComponentType<Props>; request?: undefined }\n : Request extends undefined\n ? Props & { fallbackComponent?: ComponentType<Props>; request?: Request }\n : Props & { fallbackComponent?: ComponentType<Props>; request: Request }\n>;\n\ntype Options = {\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 passModifiedRequest?: boolean;\n};\n\ntype MiddlewareProps<Request, Props, Init> = Readonly<{\n init: Init;\n Next: ComponentType<Partial<Props>>;\n request: Request;\n}>;\n\ntype MiddlewareComponentProps<Request, Props, Init> = Props &\n Readonly<{ middleware: MiddlewareProps<Request, Props, Init> }>;\n\nexport default function createChainOfResponsibility<\n Request = undefined,\n Props extends object = Readonly<{ children?: never }>,\n Init = undefined\n>(\n options: Options = {}\n): {\n asMiddleware: (\n middlewareComponent: ComponentType<MiddlewareComponentProps<Request, Props, Init>>\n ) => ComponentMiddleware<Request, Props, Init>;\n Provider: ComponentType<ProviderProps<Request, Props, Init>>;\n Proxy: ComponentType<ProxyProps<Request, Props>>;\n types: {\n init: Init;\n middleware: ComponentMiddleware<Request, Props, Init>;\n middlewareComponentProps: MiddlewareComponentProps<Request, Props, Init>;\n props: Props;\n request: Request;\n };\n useBuildComponentCallback: () => UseBuildComponentCallback<Request, Props>;\n} {\n const defaultUseBuildComponentCallback: ProviderContext<Request, Props> = {\n get enhancer() {\n return undefined;\n },\n useBuildComponentCallback(_, options) {\n if (options?.fallbackComponent) {\n return options.fallbackComponent;\n }\n\n throw new Error('This component/hook cannot be used outside of its corresponding <Provider>');\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<[Request], ResultComponent<Props>, [Init]>(\n ...[...patchedMiddleware, ...(parentEnhancer ? [() => parentEnhancer] : [])].reverse()\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({ children, fallbackComponent, request, ...props }: ProxyProps<Request, Props>) {\n const enhancer = useBuildComponentCallback();\n const Component = enhancer(request as Request, { fallbackComponent });\n\n return Component ? <Component {...(props as Props)}>{children}</Component> : null;\n }\n\n const asMiddleware: (\n middlewareComponent: ComponentType<MiddlewareComponentProps<Request, Props, Init>>\n ) => ComponentMiddleware<Request, Props, Init> =\n (\n MiddlewareComponent: ComponentType<MiddlewareComponentProps<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 {\n asMiddleware,\n Provider: memo<ProviderProps<Request, Props, Init>>(ChainOfResponsibilityProvider),\n Proxy: memo<ProxyProps<Request, Props>>(Proxy),\n types: {\n middlewareComponentProps: undefined as unknown as MiddlewareComponentProps<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 request: undefined as unknown as Request\n },\n useBuildComponentCallback\n };\n}\n","import {\n type ComponentClass,\n type ComponentType,\n type Consumer,\n type Fragment,\n type FunctionComponent,\n type Provider\n} from 'react';\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.\nexport default function 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","// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Fn<P extends any[], R> = (...args: P) => R;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Enhancer<P extends any[], R> = (next: Fn<P, R>) => Fn<P, R>;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport default function compose<P extends any[], R>(...fns: Enhancer<P, R>[]): Enhancer<P, R> {\n return (fn: Fn<P, R>): Fn<P, R> => fns.reduce((chain, fn) => fn(chain), fn);\n}\n","import compose from './compose.ts';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Fn<P extends any[], R> = (...args: P) => R;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type Enhancer<P extends any[], R> = (next: Fn<P, R>) => Fn<P, R>;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type Middleware<P extends any[], R, S extends any[]> = (...init: S) => Enhancer<P, R>;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport default function applyMiddleware<P extends any[], R, S extends any[]>(\n ...arrayOfMiddleware: Middleware<P, R, S>[]\n) {\n return (...init: S) => {\n const chain = arrayOfMiddleware.map(middleware => middleware(...init));\n\n return compose(...chain);\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACCA,IAAAA,gBAA6C;;;ACD7C,mBASO;;;ACAP,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;AACnC;AAEA,SAAS,oBAEP,WACgC;AAChC,MAAI,OAAO,cAAc,YAAY;AACnC,WAAO;AAAA,EACT;AAEA,SAAO,wBAAwB,SAAS;AAC1C;AAEA,SAAS,wBAEP,WACgC;AAChC,SAAO,WAAW,UAAU,SAAS,MAAM,wBAAwB,oBAAoB,UAAU,IAAI;AACvG;AAEA,SAAS,iBAEP,WAC6B;AAC7B,SAAO,OAAO,cAAc,YAAY,OAAO,YAAY,QAAQ,MAAM;AAC3E;AAKe,SAAR,iBAEL,WAC4B;AAC5B,SACE,oBAAoB,SAAS,KAC7B,iBAAiB,SAAS,KAC1B,WAA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A,aAAW;AACT,UAAM,mBAAmB,KAAK,OAAO;AAGrC,UAAM,eAAe,CAAC,UAAiB;AACrC,YAAM,iBAAa;AAAA,QACjB,MACE,OAAO,OAAO;AAAA,UACZ;AAAA,UACA,UAAM;AAAA,YACJ,mBACI,CAAC,oBAAoC,6BAAAA,QAAA,cAAC,oBAAkB,GAAG,OAAQ,GAAG,iBAAiB,IACvF,MAAM;AAAA,UACZ;AAAA,UACA;AAAA,QACF,CAAC;AAAA,QACH,CAAC;AAAA,MACH;AAEA,aAAO,6BAAAA,QAAA,cAAC,uBAAqB,GAAG,OAAO,YAAwB;AAAA,IACjE;AAEA,iBAAa,cAAc,gBAAgB,oBAAoB,eAAe,EAAE;AAEhF,eAAO,mBAAY,YAAY;AAAA,EACjC;AAEF,SAAO;AAAA,IACL;AAAA,IACA,cAAU,mBAA0C,6BAA6B;AAAA,IACjF,WAAO,mBAAiCC,MAAK;AAAA,IAC7C,OAAO;AAAA,MACL,0BAA0B;AAAA,MAC1B,MAAM;AAAA,MACN,YAAY;AAAA,MACZ,OAAO;AAAA,MACP,SAAS;AAAA,IACX;AAAA,IACA;AAAA,EACF;AACF;;;AD/Ne,SAAR,uCACL,SAGA;AACA,QAAM,cAAc,4BAA4D,OAAO;AAEvF,QAAM,EAAE,OAAAC,OAAM,IAAI;AAElB,QAAM,yBAAwD,CAACC,WAAU,CAAC,MAAM;AAC9E,UAAM,EAAE,OAAO,IAAIA;AAEnB,eAAO;AAAA,MACL,CAAC,OAAO,kBACN,8BAAAC,QAAA,cAACF,QAAA,EAAO,GAAI,OAAiB,mBAAmB,eAAe,KAAK,SAAS,KAAK,GAAG,SAAS,OAAO;AAAA,MAEvG,CAAC,MAAM;AAAA,IACT;AAAA,EACF;AAEA,SAAO,EAAE,GAAG,aAAa,uBAAuB;AAClD;","names":["import_react","fn","options","middleware","init","enhancer","useBuildComponentCallback","React","Proxy","Proxy","options","React"]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createChainOfResponsibility
3
- } from "./chunk-RAUACXXD.mjs";
3
+ } from "./chunk-LPY4PJSC.mjs";
4
4
 
5
5
  // src/createChainOfResponsibilityForFluentUI.tsx
6
6
  import React, { useCallback } from "react";
@@ -10,7 +10,7 @@ function createChainOfResponsibilityForFluentUI(options) {
10
10
  const useBuildRenderFunction = (options2 = {}) => {
11
11
  const { getKey } = options2;
12
12
  return useCallback(
13
- (props, defaultRender) => /* @__PURE__ */ React.createElement(Proxy, { ...props, fallbackComponent: defaultRender, key: getKey == null ? void 0 : getKey(props), request: props }),
13
+ (props, defaultRender) => /* @__PURE__ */ React.createElement(Proxy, { ...props, fallbackComponent: defaultRender, key: getKey?.(props), request: props }),
14
14
  [getKey]
15
15
  );
16
16
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/createChainOfResponsibilityForFluentUI.tsx"],"sourcesContent":["import { type IRenderFunction } from '@fluentui/react';\nimport React, { useCallback, type Key } from 'react';\n\nimport createChainOfResponsibility 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.\nexport default function createChainOfResponsibilityForFluentUI<Props extends object, Init = undefined>(\n options?: Parameters<typeof createChainOfResponsibility>[0]\n): ReturnType<typeof createChainOfResponsibility<Props | undefined, Props, Init>> & {\n useBuildRenderFunction: UseBuildRenderFunction<Props>;\n} {\n const returnValue = createChainOfResponsibility<Props | undefined, Props, Init>(options);\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 <Proxy {...(props as Props)} fallbackComponent={defaultRender} key={getKey?.(props)} request={props} />\n ),\n [getKey]\n );\n };\n\n return { ...returnValue, useBuildRenderFunction };\n}\n"],"mappings":";;;;;AACA,OAAO,SAAS,mBAA6B;AAW9B,SAAR,uCACL,SAGA;AACA,QAAM,cAAc,4BAA4D,OAAO;AAEvF,QAAM,EAAE,MAAM,IAAI;AAElB,QAAM,yBAAwD,CAACA,WAAU,CAAC,MAAM;AAC9E,UAAM,EAAE,OAAO,IAAIA;AAEnB,WAAO;AAAA,MACL,CAAC,OAAO,kBACN,oCAAC,SAAO,GAAI,OAAiB,mBAAmB,eAAe,KAAK,iCAAS,QAAQ,SAAS,OAAO;AAAA,MAEvG,CAAC,MAAM;AAAA,IACT;AAAA,EACF;AAEA,SAAO,EAAE,GAAG,aAAa,uBAAuB;AAClD;","names":["options"]}
1
+ {"version":3,"sources":["../src/createChainOfResponsibilityForFluentUI.tsx"],"sourcesContent":["import { type IRenderFunction } from '@fluentui/react';\nimport React, { useCallback, type Key } from 'react';\n\nimport createChainOfResponsibility 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.\nexport default function createChainOfResponsibilityForFluentUI<Props extends object, Init = undefined>(\n options?: Parameters<typeof createChainOfResponsibility>[0]\n): ReturnType<typeof createChainOfResponsibility<Props | undefined, Props, Init>> & {\n useBuildRenderFunction: UseBuildRenderFunction<Props>;\n} {\n const returnValue = createChainOfResponsibility<Props | undefined, Props, Init>(options);\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 <Proxy {...(props as Props)} fallbackComponent={defaultRender} key={getKey?.(props)} request={props} />\n ),\n [getKey]\n );\n };\n\n return { ...returnValue, useBuildRenderFunction };\n}\n"],"mappings":";;;;;AACA,OAAO,SAAS,mBAA6B;AAW9B,SAAR,uCACL,SAGA;AACA,QAAM,cAAc,4BAA4D,OAAO;AAEvF,QAAM,EAAE,MAAM,IAAI;AAElB,QAAM,yBAAwD,CAACA,WAAU,CAAC,MAAM;AAC9E,UAAM,EAAE,OAAO,IAAIA;AAEnB,WAAO;AAAA,MACL,CAAC,OAAO,kBACN,oCAAC,SAAO,GAAI,OAAiB,mBAAmB,eAAe,KAAK,SAAS,KAAK,GAAG,SAAS,OAAO;AAAA,MAEvG,CAAC,MAAM;AAAA,IACT;AAAA,EACF;AAEA,SAAO,EAAE,GAAG,aAAa,uBAAuB;AAClD;","names":["options"]}
@@ -39,15 +39,13 @@ var import_react = __toESM(require("react"));
39
39
 
40
40
  // src/isReactComponent.ts
41
41
  function isConsumer(component) {
42
- var _a;
43
- return ((_a = component == null ? void 0 : component.$$typeof) == null ? void 0 : _a.toString()) === "Symbol(react.context)";
42
+ return component?.$$typeof?.toString() === "Symbol(react.context)";
44
43
  }
45
44
  function isProvider(component) {
46
- var _a;
47
- return ((_a = component == null ? void 0 : component.$$typeof) == null ? void 0 : _a.toString()) === "Symbol(react.provider)";
45
+ return component?.$$typeof?.toString() === "Symbol(react.provider)";
48
46
  }
49
47
  function isFragment(component) {
50
- return (component == null ? void 0 : component.toString()) === "Symbol(react.fragment)";
48
+ return component?.toString() === "Symbol(react.fragment)";
51
49
  }
52
50
  function isFunctionComponent(component) {
53
51
  if (typeof component === "function") {
@@ -56,11 +54,10 @@ function isFunctionComponent(component) {
56
54
  return isPureFunctionComponent(component);
57
55
  }
58
56
  function isPureFunctionComponent(component) {
59
- var _a;
60
- return ((_a = component == null ? void 0 : component.$$typeof) == null ? void 0 : _a.toString()) === "Symbol(react.memo)" && isFunctionComponent(component.type);
57
+ return component?.$$typeof?.toString() === "Symbol(react.memo)" && isFunctionComponent(component.type);
61
58
  }
62
59
  function isComponentClass(component) {
63
- return typeof component === "object" && typeof (component == null ? void 0 : component["render"]) === "function";
60
+ return typeof component === "object" && typeof component?.["render"] === "function";
64
61
  }
65
62
  function isReactComponent(component) {
66
63
  return isFunctionComponent(component) || isComponentClass(component) || isFragment(component) || isConsumer(component) || isProvider(component);
@@ -86,7 +83,7 @@ function createChainOfResponsibility(options = {}) {
86
83
  return void 0;
87
84
  },
88
85
  useBuildComponentCallback(_, options2) {
89
- if (options2 == null ? void 0 : options2.fallbackComponent) {
86
+ if (options2?.fallbackComponent) {
90
87
  return options2.fallbackComponent;
91
88
  }
92
89
  throw new Error("This component/hook cannot be used outside of its corresponding <Provider>");
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/index.ts","../src/createChainOfResponsibility.tsx","../src/isReactComponent.ts","../src/private/compose.ts","../src/private/applyMiddleware.ts"],"sourcesContent":["export { default as createChainOfResponsibility } from './createChainOfResponsibility.tsx';\nexport { type ComponentMiddleware } from './types.ts';\n","import 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 applyMiddleware, { type Enhancer } from './private/applyMiddleware.ts';\nimport { 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> = { fallbackComponent?: ResultComponent<Props> };\n\ntype UseBuildComponentCallback<Request, Props> = (\n request: Request,\n options?: UseBuildComponentCallbackOptions<Props>\n) => ComponentType<Props> | undefined;\n\ntype ProviderContext<Request, Props> = {\n get enhancer(): Enhancer<[Request], ResultComponent<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 ? { init?: undefined } : Init extends undefined ? { init?: Init } : { init: Init });\n\ntype ProxyProps<Request, Props extends object> = PropsWithChildren<\n Request extends never | void\n ? Props & { fallbackComponent?: ComponentType<Props>; request?: undefined }\n : Request extends undefined\n ? Props & { fallbackComponent?: ComponentType<Props>; request?: Request }\n : Props & { fallbackComponent?: ComponentType<Props>; request: Request }\n>;\n\ntype Options = {\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 passModifiedRequest?: boolean;\n};\n\ntype MiddlewareProps<Request, Props, Init> = Readonly<{\n init: Init;\n Next: ComponentType<Partial<Props>>;\n request: Request;\n}>;\n\ntype MiddlewareComponentProps<Request, Props, Init> = Props &\n Readonly<{ middleware: MiddlewareProps<Request, Props, Init> }>;\n\nexport default function createChainOfResponsibility<\n Request = undefined,\n Props extends object = Readonly<{ children?: never }>,\n Init = undefined\n>(\n options: Options = {}\n): {\n asMiddleware: (\n middlewareComponent: ComponentType<MiddlewareComponentProps<Request, Props, Init>>\n ) => ComponentMiddleware<Request, Props, Init>;\n Provider: ComponentType<ProviderProps<Request, Props, Init>>;\n Proxy: ComponentType<ProxyProps<Request, Props>>;\n types: {\n init: Init;\n middleware: ComponentMiddleware<Request, Props, Init>;\n middlewareComponentProps: MiddlewareComponentProps<Request, Props, Init>;\n props: Props;\n request: Request;\n };\n useBuildComponentCallback: () => UseBuildComponentCallback<Request, Props>;\n} {\n const defaultUseBuildComponentCallback: ProviderContext<Request, Props> = {\n get enhancer() {\n return undefined;\n },\n useBuildComponentCallback(_, options) {\n if (options?.fallbackComponent) {\n return options.fallbackComponent;\n }\n\n throw new Error('This component/hook cannot be used outside of its corresponding <Provider>');\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<[Request], ResultComponent<Props>, [Init]>(\n ...[...patchedMiddleware, ...(parentEnhancer ? [() => parentEnhancer] : [])].reverse()\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({ children, fallbackComponent, request, ...props }: ProxyProps<Request, Props>) {\n const enhancer = useBuildComponentCallback();\n const Component = enhancer(request as Request, { fallbackComponent });\n\n return Component ? <Component {...(props as Props)}>{children}</Component> : null;\n }\n\n const asMiddleware: (\n middlewareComponent: ComponentType<MiddlewareComponentProps<Request, Props, Init>>\n ) => ComponentMiddleware<Request, Props, Init> =\n (\n MiddlewareComponent: ComponentType<MiddlewareComponentProps<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 {\n asMiddleware,\n Provider: memo<ProviderProps<Request, Props, Init>>(ChainOfResponsibilityProvider),\n Proxy: memo<ProxyProps<Request, Props>>(Proxy),\n types: {\n middlewareComponentProps: undefined as unknown as MiddlewareComponentProps<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 request: undefined as unknown as Request\n },\n useBuildComponentCallback\n };\n}\n","import {\n type ComponentClass,\n type ComponentType,\n type Consumer,\n type Fragment,\n type FunctionComponent,\n type Provider\n} from 'react';\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.\nexport default function 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","// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Fn<P extends any[], R> = (...args: P) => R;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Enhancer<P extends any[], R> = (next: Fn<P, R>) => Fn<P, R>;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport default function compose<P extends any[], R>(...fns: Enhancer<P, R>[]): Enhancer<P, R> {\n return (fn: Fn<P, R>): Fn<P, R> => fns.reduce((chain, fn) => fn(chain), fn);\n}\n","import compose from './compose.ts';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Fn<P extends any[], R> = (...args: P) => R;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type Enhancer<P extends any[], R> = (next: Fn<P, R>) => Fn<P, R>;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type Middleware<P extends any[], R, S extends any[]> = (...init: S) => Enhancer<P, R>;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport default function applyMiddleware<P extends any[], R, S extends any[]>(\n ...arrayOfMiddleware: Middleware<P, R, S>[]\n) {\n return (...init: S) => {\n const chain = arrayOfMiddleware.map(middleware => middleware(...init));\n\n return compose(...chain);\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBASO;;;ACAP,SAAS,WAEP,WACgC;AAZlC;AAaE,WAAO,4CAAW,aAAX,mBAAqB,gBAAe;AAC7C;AAEA,SAAS,WAEP,WACgC;AAnBlC;AAoBE,WAAO,4CAAW,aAAX,mBAAqB,gBAAe;AAC7C;AAEA,SAAS,WAEP,WAC8B;AAC9B,UAAO,uCAAW,gBAAe;AACnC;AAEA,SAAS,oBAEP,WACgC;AAChC,MAAI,OAAO,cAAc,YAAY;AACnC,WAAO;AAAA,EACT;AAEA,SAAO,wBAAwB,SAAS;AAC1C;AAEA,SAAS,wBAEP,WACgC;AA5ClC;AA6CE,WAAO,4CAAW,aAAX,mBAAqB,gBAAe,wBAAwB,oBAAoB,UAAU,IAAI;AACvG;AAEA,SAAS,iBAEP,WAC6B;AAC7B,SAAO,OAAO,cAAc,YAAY,QAAO,uCAAY,eAAc;AAC3E;AAKe,SAAR,iBAEL,WAC4B;AAC5B,SACE,oBAAoB,SAAS,KAC7B,iBAAiB,SAAS,KAC1B,WAAW,SAAS,KACpB,WAAW,SAAS,KACpB,WAAW,SAAS;AAExB;;;AC9De,SAAR,WAA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AAe,CAAC,UAAiB;AACrC,YAAM,iBAAa;AAAA,QACjB,MACE,OAAO,OAAO;AAAA,UACZ;AAAA,UACA,UAAM;AAAA,YACJ,mBACI,CAAC,oBAAoC,6BAAAA,QAAA,cAAC,oBAAkB,GAAG,OAAQ,GAAG,iBAAiB,IACvF,MAAM;AAAA,UACZ;AAAA,UACA;AAAA,QACF,CAAC;AAAA,QACH,CAAC;AAAA,MACH;AAEA,aAAO,6BAAAA,QAAA,cAAC,uBAAqB,GAAG,OAAO,YAAwB;AAAA,IACjE;AAEA,iBAAa,cAAc,gBAAgB,oBAAoB,eAAe,EAAE;AAEhF,eAAO,mBAAY,YAAY;AAAA,EACjC;AAEF,SAAO;AAAA,IACL;AAAA,IACA,cAAU,mBAA0C,6BAA6B;AAAA,IACjF,WAAO,mBAAiCC,MAAK;AAAA,IAC7C,OAAO;AAAA,MACL,0BAA0B;AAAA,MAC1B,MAAM;AAAA,MACN,YAAY;AAAA,MACZ,OAAO;AAAA,MACP,SAAS;AAAA,IACX;AAAA,IACA;AAAA,EACF;AACF;","names":["fn","options","middleware","init","enhancer","useBuildComponentCallback","React","Proxy"]}
1
+ {"version":3,"sources":["../src/index.ts","../src/createChainOfResponsibility.tsx","../src/isReactComponent.ts","../src/private/compose.ts","../src/private/applyMiddleware.ts"],"sourcesContent":["export { default as createChainOfResponsibility } from './createChainOfResponsibility.tsx';\nexport { type ComponentMiddleware } from './types.ts';\n","import 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 applyMiddleware, { type Enhancer } from './private/applyMiddleware.ts';\nimport { 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> = { fallbackComponent?: ResultComponent<Props> };\n\ntype UseBuildComponentCallback<Request, Props> = (\n request: Request,\n options?: UseBuildComponentCallbackOptions<Props>\n) => ComponentType<Props> | undefined;\n\ntype ProviderContext<Request, Props> = {\n get enhancer(): Enhancer<[Request], ResultComponent<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 ? { init?: undefined } : Init extends undefined ? { init?: Init } : { init: Init });\n\ntype ProxyProps<Request, Props extends object> = PropsWithChildren<\n Request extends never | void\n ? Props & { fallbackComponent?: ComponentType<Props>; request?: undefined }\n : Request extends undefined\n ? Props & { fallbackComponent?: ComponentType<Props>; request?: Request }\n : Props & { fallbackComponent?: ComponentType<Props>; request: Request }\n>;\n\ntype Options = {\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 passModifiedRequest?: boolean;\n};\n\ntype MiddlewareProps<Request, Props, Init> = Readonly<{\n init: Init;\n Next: ComponentType<Partial<Props>>;\n request: Request;\n}>;\n\ntype MiddlewareComponentProps<Request, Props, Init> = Props &\n Readonly<{ middleware: MiddlewareProps<Request, Props, Init> }>;\n\nexport default function createChainOfResponsibility<\n Request = undefined,\n Props extends object = Readonly<{ children?: never }>,\n Init = undefined\n>(\n options: Options = {}\n): {\n asMiddleware: (\n middlewareComponent: ComponentType<MiddlewareComponentProps<Request, Props, Init>>\n ) => ComponentMiddleware<Request, Props, Init>;\n Provider: ComponentType<ProviderProps<Request, Props, Init>>;\n Proxy: ComponentType<ProxyProps<Request, Props>>;\n types: {\n init: Init;\n middleware: ComponentMiddleware<Request, Props, Init>;\n middlewareComponentProps: MiddlewareComponentProps<Request, Props, Init>;\n props: Props;\n request: Request;\n };\n useBuildComponentCallback: () => UseBuildComponentCallback<Request, Props>;\n} {\n const defaultUseBuildComponentCallback: ProviderContext<Request, Props> = {\n get enhancer() {\n return undefined;\n },\n useBuildComponentCallback(_, options) {\n if (options?.fallbackComponent) {\n return options.fallbackComponent;\n }\n\n throw new Error('This component/hook cannot be used outside of its corresponding <Provider>');\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<[Request], ResultComponent<Props>, [Init]>(\n ...[...patchedMiddleware, ...(parentEnhancer ? [() => parentEnhancer] : [])].reverse()\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({ children, fallbackComponent, request, ...props }: ProxyProps<Request, Props>) {\n const enhancer = useBuildComponentCallback();\n const Component = enhancer(request as Request, { fallbackComponent });\n\n return Component ? <Component {...(props as Props)}>{children}</Component> : null;\n }\n\n const asMiddleware: (\n middlewareComponent: ComponentType<MiddlewareComponentProps<Request, Props, Init>>\n ) => ComponentMiddleware<Request, Props, Init> =\n (\n MiddlewareComponent: ComponentType<MiddlewareComponentProps<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 {\n asMiddleware,\n Provider: memo<ProviderProps<Request, Props, Init>>(ChainOfResponsibilityProvider),\n Proxy: memo<ProxyProps<Request, Props>>(Proxy),\n types: {\n middlewareComponentProps: undefined as unknown as MiddlewareComponentProps<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 request: undefined as unknown as Request\n },\n useBuildComponentCallback\n };\n}\n","import {\n type ComponentClass,\n type ComponentType,\n type Consumer,\n type Fragment,\n type FunctionComponent,\n type Provider\n} from 'react';\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.\nexport default function 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","// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Fn<P extends any[], R> = (...args: P) => R;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Enhancer<P extends any[], R> = (next: Fn<P, R>) => Fn<P, R>;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport default function compose<P extends any[], R>(...fns: Enhancer<P, R>[]): Enhancer<P, R> {\n return (fn: Fn<P, R>): Fn<P, R> => fns.reduce((chain, fn) => fn(chain), fn);\n}\n","import compose from './compose.ts';\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\ntype Fn<P extends any[], R> = (...args: P) => R;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type Enhancer<P extends any[], R> = (next: Fn<P, R>) => Fn<P, R>;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport type Middleware<P extends any[], R, S extends any[]> = (...init: S) => Enhancer<P, R>;\n\n// eslint-disable-next-line @typescript-eslint/no-explicit-any\nexport default function applyMiddleware<P extends any[], R, S extends any[]>(\n ...arrayOfMiddleware: Middleware<P, R, S>[]\n) {\n return (...init: S) => {\n const chain = arrayOfMiddleware.map(middleware => middleware(...init));\n\n return compose(...chain);\n };\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,mBASO;;;ACAP,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;AACnC;AAEA,SAAS,oBAEP,WACgC;AAChC,MAAI,OAAO,cAAc,YAAY;AACnC,WAAO;AAAA,EACT;AAEA,SAAO,wBAAwB,SAAS;AAC1C;AAEA,SAAS,wBAEP,WACgC;AAChC,SAAO,WAAW,UAAU,SAAS,MAAM,wBAAwB,oBAAoB,UAAU,IAAI;AACvG;AAEA,SAA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AM,YAAY,SAAS,SAAoB,EAAE,kBAAkB,CAAC;AAEpE,WAAO,YAAY,6BAAAD,QAAA,cAAC,aAAW,GAAI,SAAkB,QAAS,IAAe;AAAA,EAC/E;AAEA,QAAM,eAGJ,CACE,wBAEF,UACA,UACA,aAAW;AACT,UAAM,mBAAmB,KAAK,OAAO;AAGrC,UAAM,eAAe,CAAC,UAAiB;AACrC,YAAM,iBAAa;AAAA,QACjB,MACE,OAAO,OAAO;AAAA,UACZ;AAAA,UACA,UAAM;AAAA,YACJ,mBACI,CAAC,oBAAoC,6BAAAA,QAAA,cAAC,oBAAkB,GAAG,OAAQ,GAAG,iBAAiB,IACvF,MAAM;AAAA,UACZ;AAAA,UACA;AAAA,QACF,CAAC;AAAA,QACH,CAAC;AAAA,MACH;AAEA,aAAO,6BAAAA,QAAA,cAAC,uBAAqB,GAAG,OAAO,YAAwB;AAAA,IACjE;AAEA,iBAAa,cAAc,gBAAgB,oBAAoB,eAAe,EAAE;AAEhF,eAAO,mBAAY,YAAY;AAAA,EACjC;AAEF,SAAO;AAAA,IACL;AAAA,IACA,cAAU,mBAA0C,6BAA6B;AAAA,IACjF,WAAO,mBAAiCC,MAAK;AAAA,IAC7C,OAAO;AAAA,MACL,0BAA0B;AAAA,MAC1B,MAAM;AAAA,MACN,YAAY;AAAA,MACZ,OAAO;AAAA,MACP,SAAS;AAAA,IACX;AAAA,IACA;AAAA,EACF;AACF;","names":["fn","options","middleware","init","enhancer","useBuildComponentCallback","React","Proxy"]}
@@ -1,6 +1,6 @@
1
1
  import {
2
2
  createChainOfResponsibility
3
- } from "./chunk-RAUACXXD.mjs";
3
+ } from "./chunk-LPY4PJSC.mjs";
4
4
  export {
5
5
  createChainOfResponsibility
6
6
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-chain-of-responsibility",
3
- "version": "0.3.0-main.e6dfb8e",
3
+ "version": "0.3.1-main.20ef5bb",
4
4
  "description": "Using chain of responsibility design pattern for compositing and customizing React component.",
5
5
  "files": [
6
6
  "./dist/"
@@ -45,7 +45,7 @@
45
45
  },
46
46
  "repository": {
47
47
  "type": "git",
48
- "url": "git+https://github.com/compulim/react-chain-of-responsibility.git"
48
+ "url": "https://github.com/compulim/react-chain-of-responsibility.git"
49
49
  },
50
50
  "keywords": [
51
51
  "react",
@@ -131,6 +131,6 @@
131
131
  "react": ">=16.8.0"
132
132
  },
133
133
  "dependencies": {
134
- "react-chain-of-responsibility": "^0.3.0-main.e6dfb8e"
134
+ "react-chain-of-responsibility": "^0.3.1-main.20ef5bb"
135
135
  }
136
136
  }