react-chain-of-responsibility 0.3.1-main.cc0a3ac → 0.4.0-main.235b355

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
@@ -356,12 +356,14 @@ function createChainOfResponsibility<Request = undefined, Props = { children?: n
356
356
 
357
357
  ### Options
358
358
 
359
+ #### `passModifiedRequest`
360
+
359
361
  > `passModifiedRequest` is not supported by `asMiddleware`.
360
362
 
361
363
  ```ts
362
364
  type Options = {
363
365
  /** Allows a middleware to pass another request object to its next middleware. Default is false. */
364
- passModifiedRequest?: boolean;
366
+ passModifiedRequest?: boolean | undefined;
365
367
  };
366
368
  ```
367
369
 
@@ -431,6 +433,14 @@ type UseBuildRenderFunction<Props> = (options?: UseBuildRenderFunctionOptions<Pr
431
433
 
432
434
  When rendering the element, `getKey` is called to compute the `key` attribute. This is required for some `onRenderXXX` props. These props are usually used to render more than one elements, such as [`DetailsList.onRenderField`](https://developer.microsoft.com/en-us/fluentui#/controls/web/detailslist#implementation), which renders every field (a.k.a. cell) in the [`<DetailsList>`](https://developer.microsoft.com/en-us/fluentui#/controls/web/detailslist).
433
435
 
436
+ ### `withBuildProps` higher-order helper function
437
+
438
+ `withBuildProps` is a higher-order function that extends the chain-of-responsibility with props transformation capability. It modified the `<Proxy>` and `useBuildComponentCallback` hook so that request can be hoisted and accessible in props.
439
+
440
+ However, this should be used with care. Given an identical request, the returning component from the `useBuildComponentCallback()` hook will never be stable. Explicit memoization is required for stabilizing the result.
441
+
442
+ For `<Proxy>`, memoization is provided automatically through React `memo()` function. No explicity memoization is required.
443
+
434
444
  ## Designs
435
445
 
436
446
  ### How can I choose between request and props?
@@ -450,6 +460,8 @@ For example:
450
460
  - Request: text input, number input, password input
451
461
  - Props: label, value, instruction
452
462
 
463
+ In some cases, you may want to have request accessible via props. The `withBuildProps` higher-order helper function can be used to hoist the request object in props. However, currently, `withBuildProps` does not honor the `passModifiedRequest` option.
464
+
453
465
  ### Why the type of request and props can be different?
454
466
 
455
467
  This is to support advanced scenarios where props are not ready until all rendering components are built.
@@ -1,3 +1,7 @@
1
+ import {
2
+ applyMiddleware
3
+ } from "./chunk-TNTIZJJ5.mjs";
4
+
1
5
  // src/createChainOfResponsibility.tsx
2
6
  import React, {
3
7
  createContext,
@@ -9,16 +13,15 @@ import React, {
9
13
  } from "react";
10
14
 
11
15
  // src/isReactComponent.ts
16
+ import { custom } from "valibot";
12
17
  function isConsumer(component) {
13
- var _a;
14
- return ((_a = component == null ? void 0 : component.$$typeof) == null ? void 0 : _a.toString()) === "Symbol(react.context)";
18
+ return component?.$$typeof?.toString() === "Symbol(react.context)";
15
19
  }
16
20
  function isProvider(component) {
17
- var _a;
18
- return ((_a = component == null ? void 0 : component.$$typeof) == null ? void 0 : _a.toString()) === "Symbol(react.provider)";
21
+ return component?.$$typeof?.toString() === "Symbol(react.provider)";
19
22
  }
20
23
  function isFragment(component) {
21
- return (component == null ? void 0 : component.toString()) === "Symbol(react.fragment)";
24
+ return component?.toString() === "Symbol(react.fragment)";
22
25
  }
23
26
  function isFunctionComponent(component) {
24
27
  if (typeof component === "function") {
@@ -27,28 +30,15 @@ function isFunctionComponent(component) {
27
30
  return isPureFunctionComponent(component);
28
31
  }
29
32
  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);
33
+ return component?.$$typeof?.toString() === "Symbol(react.memo)" && isFunctionComponent(component.type);
32
34
  }
33
35
  function isComponentClass(component) {
34
- return typeof component === "object" && typeof (component == null ? void 0 : component["render"]) === "function";
36
+ return typeof component === "object" && typeof component?.["render"] === "function";
35
37
  }
36
38
  function isReactComponent(component) {
37
39
  return isFunctionComponent(component) || isComponentClass(component) || isFragment(component) || isConsumer(component) || isProvider(component);
38
40
  }
39
-
40
- // src/private/compose.ts
41
- function compose(...fns) {
42
- return (fn) => fns.reduce((chain, fn2) => fn2(chain), fn);
43
- }
44
-
45
- // src/private/applyMiddleware.ts
46
- function applyMiddleware(...arrayOfMiddleware) {
47
- return (...init) => {
48
- const chain = arrayOfMiddleware.map((middleware) => middleware(...init));
49
- return compose(...chain);
50
- };
51
- }
41
+ var isReactComponent_default = isReactComponent;
52
42
 
53
43
  // src/createChainOfResponsibility.tsx
54
44
  function createChainOfResponsibility(options = {}) {
@@ -56,11 +46,11 @@ function createChainOfResponsibility(options = {}) {
56
46
  get enhancer() {
57
47
  return void 0;
58
48
  },
59
- useBuildComponentCallback(_, options2) {
60
- if (options2 == null ? void 0 : options2.fallbackComponent) {
61
- return options2.fallbackComponent;
49
+ useBuildComponentCallback(_request, options2) {
50
+ if (!options2?.fallbackComponent) {
51
+ throw new Error("This component/hook cannot be used outside of its corresponding <Provider>");
62
52
  }
63
- throw new Error("This component/hook cannot be used outside of its corresponding <Provider>");
53
+ return options2.fallbackComponent;
64
54
  }
65
55
  };
66
56
  const context = createContext(defaultUseBuildComponentCallback);
@@ -85,7 +75,7 @@ function createChainOfResponsibility(options = {}) {
85
75
  hasReturned = true;
86
76
  if (isValidElement(returnValue)) {
87
77
  throw new Error("middleware must not return React element directly");
88
- } else if (returnValue !== false && returnValue !== null && typeof returnValue !== "undefined" && !isReactComponent(returnValue)) {
78
+ } else if (returnValue !== false && returnValue !== null && typeof returnValue !== "undefined" && !isReactComponent_default(returnValue)) {
89
79
  throw new Error(
90
80
  "middleware must return false, null, undefined, function component, or class component"
91
81
  );
@@ -117,10 +107,10 @@ function createChainOfResponsibility(options = {}) {
117
107
  return /* @__PURE__ */ React.createElement(context.Provider, { value: contextValue }, children);
118
108
  }
119
109
  const useBuildComponentCallback = () => useContext(context).useBuildComponentCallback;
120
- function Proxy({ children, fallbackComponent, request, ...props }) {
110
+ function Proxy({ fallbackComponent, request, ...props }) {
121
111
  const enhancer = useBuildComponentCallback();
122
112
  const Component = enhancer(request, { fallbackComponent });
123
- return Component ? /* @__PURE__ */ React.createElement(Component, { ...props }, children) : null;
113
+ return Component ? /* @__PURE__ */ React.createElement(Component, { ...props }) : null;
124
114
  }
125
115
  const asMiddleware = (MiddlewareComponent) => (init) => (next) => (request) => {
126
116
  const RawNextComponent = next(request);
@@ -140,22 +130,24 @@ function createChainOfResponsibility(options = {}) {
140
130
  MiddlewareOf.displayName = `MiddlewareOf<${MiddlewareComponent.displayName || ""}>`;
141
131
  return memo(MiddlewareOf);
142
132
  };
143
- return {
133
+ return Object.freeze({
144
134
  asMiddleware,
145
135
  Provider: memo(ChainOfResponsibilityProvider),
146
136
  Proxy: memo(Proxy),
147
- types: {
137
+ types: Object.freeze({
148
138
  middlewareComponentProps: void 0,
149
139
  init: void 0,
150
140
  middleware: void 0,
151
141
  props: void 0,
142
+ proxyProps: void 0,
152
143
  request: void 0
153
- },
144
+ }),
154
145
  useBuildComponentCallback
155
- };
146
+ });
156
147
  }
148
+ var createChainOfResponsibility_default = createChainOfResponsibility;
157
149
 
158
150
  export {
159
- createChainOfResponsibility
151
+ createChainOfResponsibility_default
160
152
  };
161
- //# sourceMappingURL=chunk-RAUACXXD.mjs.map
153
+ //# sourceMappingURL=chunk-3IVASMVM.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/createChainOfResponsibility.tsx","../src/isReactComponent.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> = {\n fallbackComponent?: ResultComponent<Props> | undefined;\n};\n\ninterface UseBuildComponentCallback<Request, Props> {\n (request: Request, options?: undefined | UseBuildComponentCallbackOptions<Props>): ComponentType<Props> | undefined;\n}\n\ntype ProviderContext<Request, Props> = {\n get enhancer(): 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\n ? { readonly init?: undefined }\n : Init extends undefined | void\n ? { readonly init?: Init }\n : { readonly init: Init });\n\ntype ProxyProps<Request, Props extends object> = Props & {\n readonly fallbackComponent?: ComponentType<Props> | undefined;\n readonly request: Request;\n};\n\ntype CreateChainOfResponsibilityOptions = {\n /**\n * Allows a middleware to pass another request object when calling its next middleware. Default is false.\n *\n * However, middleware could modify the request object before calling its next middleware. It is recommended\n * to use Object.freeze() to prevent middleware from modifying the request object.\n */\n readonly passModifiedRequest?: boolean | undefined;\n};\n\ntype AsMiddlewareProps<Request, Props, Init> = {\n readonly init: Init;\n readonly Next: ComponentType<Partial<Props>>;\n readonly request: Request;\n};\n\ntype AsMiddlewareComponentProps<Request, Props, Init> = Props & {\n readonly middleware: AsMiddlewareProps<Request, Props, Init>;\n};\n\ntype ChainOfResponsibility<Request, Props extends object, Init> = {\n readonly asMiddleware: (\n middlewareComponent: ComponentType<AsMiddlewareComponentProps<Request, Props, Init>>\n ) => ComponentMiddleware<Request, Props, Init>;\n readonly Provider: ComponentType<ProviderProps<Request, Props, Init>>;\n readonly Proxy: ComponentType<ProxyProps<Request, Props>>;\n readonly types: {\n readonly init: Init;\n readonly middleware: ComponentMiddleware<Request, Props, Init>;\n readonly middlewareComponentProps: AsMiddlewareComponentProps<Request, Props, Init>;\n readonly props: Props;\n readonly proxyProps: ProxyProps<Request, Props>;\n readonly request: Request;\n };\n readonly useBuildComponentCallback: () => UseBuildComponentCallback<Request, Props>;\n};\n\nfunction createChainOfResponsibility<Request = void, Props extends object = { readonly children?: never }, Init = void>(\n options: CreateChainOfResponsibilityOptions = {}\n): ChainOfResponsibility<Request, Props, Init> {\n const defaultUseBuildComponentCallback: ProviderContext<Request, Props> = {\n get enhancer() {\n return undefined;\n },\n useBuildComponentCallback(_request, options): ComponentType<Props> {\n if (!options?.fallbackComponent) {\n throw new Error('This component/hook cannot be used outside of its corresponding <Provider>');\n }\n\n return options.fallbackComponent;\n }\n };\n\n const context = createContext<ProviderContext<Request, Props>>(defaultUseBuildComponentCallback);\n\n function ChainOfResponsibilityProvider({ children, init, middleware }: ProviderProps<Request, Props, Init>) {\n // TODO: Related to https://github.com/microsoft/TypeScript/issues/17002.\n // typescript@5.2.2 has a bug, Array.isArray() is a type predicate but only works with mutable array, not readonly array.\n // After removing \"as unknown\", `middleware` on the next line become `any[]`.\n if (!Array.isArray(middleware as unknown) || middleware.some(middleware => typeof middleware !== 'function')) {\n throw new Error('middleware prop must be an array of functions');\n }\n\n const patchedMiddleware: readonly ComponentMiddleware<Request, Props, Init>[] = Object.freeze(\n middleware\n ? middleware.map(fn => (init: Init) => {\n const enhancer = fn(init);\n\n return (next: (request: Request) => ComponentType<Props> | false | null | undefined) =>\n (originalRequest: Request) => {\n // False positive: although we did not re-assign the variable from true, it was initialized as undefined.\n // eslint-disable-next-line prefer-const\n let hasReturned: boolean;\n\n const returnValue = enhancer(nextRequest => {\n if (hasReturned) {\n throw new Error('next() cannot be called after the function had returned synchronously');\n }\n\n !options.passModifiedRequest &&\n nextRequest !== originalRequest &&\n console.warn(\n 'react-chain-of-responsibility: \"options.passModifiedRequest\" must be set to true to pass a different request object to next().'\n );\n\n return next(options.passModifiedRequest ? nextRequest : originalRequest);\n })(originalRequest);\n\n hasReturned = true;\n\n if (isValidElement(returnValue)) {\n throw new Error('middleware must not return React element directly');\n } else if (\n returnValue !== false &&\n returnValue !== null &&\n typeof returnValue !== 'undefined' &&\n !isReactComponent(returnValue)\n ) {\n throw new Error(\n 'middleware must return false, null, undefined, function component, or class component'\n );\n }\n\n return returnValue;\n };\n })\n : []\n );\n\n const { enhancer: parentEnhancer } = useContext(context);\n\n const enhancer = useMemo(\n () =>\n // We are reversing because it is easier to read:\n // - With reverse, [a, b, c] will become a(b(c(fn)))\n // - Without reverse, [a, b, c] will become c(b(a(fn)))\n applyMiddleware<[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({ fallbackComponent, request, ...props }: ProxyProps<Request, Props>) {\n const enhancer = useBuildComponentCallback();\n\n const Component = enhancer(request as Request, { fallbackComponent });\n\n return Component ? <Component {...(props as Props)} /> : null;\n }\n\n const asMiddleware: (\n middlewareComponent: ComponentType<AsMiddlewareComponentProps<Request, Props, Init>>\n ) => ComponentMiddleware<Request, Props, Init> =\n (\n MiddlewareComponent: ComponentType<AsMiddlewareComponentProps<Request, Props, Init>>\n ): ComponentMiddleware<Request, Props, Init> =>\n init =>\n next =>\n request => {\n const RawNextComponent = next(request);\n\n // TODO: Can we pre-build this component during init?\n const MiddlewareOf = (props: Props) => {\n const middleware = useMemo(\n () =>\n Object.freeze({\n init,\n Next: memo<Partial<Props>>(\n RawNextComponent\n ? (overridingProps: Partial<Props>) => <RawNextComponent {...props} {...overridingProps} />\n : () => null\n ),\n request\n }),\n []\n );\n\n return <MiddlewareComponent {...props} middleware={middleware} />;\n };\n\n MiddlewareOf.displayName = `MiddlewareOf<${MiddlewareComponent.displayName || ''}>`;\n\n return memo<Props>(MiddlewareOf);\n };\n\n return Object.freeze({\n asMiddleware,\n Provider: memo<ProviderProps<Request, Props, Init>>(ChainOfResponsibilityProvider),\n Proxy: memo<ProxyProps<Request, Props>>(Proxy),\n types: Object.freeze({\n middlewareComponentProps: undefined as unknown as AsMiddlewareComponentProps<Request, Props, Init>,\n init: undefined as unknown as Init,\n middleware: undefined as unknown as ComponentMiddleware<Request, Props, Init>,\n props: undefined as unknown as Props,\n proxyProps: undefined as unknown as ProxyProps<Request, Props>,\n request: undefined as unknown as Request\n }),\n useBuildComponentCallback\n });\n}\n\nexport default createChainOfResponsibility;\nexport {\n type ChainOfResponsibility,\n type CreateChainOfResponsibilityOptions,\n type ProxyProps,\n type UseBuildComponentCallback\n};\n","import {\n type ComponentClass,\n type ComponentType,\n type Consumer,\n type Fragment,\n type FunctionComponent,\n type Provider\n} from 'react';\nimport { custom } from 'valibot';\n\nfunction isConsumer(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n component: any\n): component is Consumer<unknown> {\n return component?.$$typeof?.toString() === 'Symbol(react.context)';\n}\n\nfunction isProvider(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n component: any\n): component is Provider<unknown> {\n return component?.$$typeof?.toString() === 'Symbol(react.provider)';\n}\n\nfunction isFragment(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n component: any\n): component is typeof Fragment {\n return component?.toString() === 'Symbol(react.fragment)';\n}\n\nfunction isFunctionComponent(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n component: any\n): component is FunctionComponent {\n if (typeof component === 'function') {\n return true;\n }\n\n return isPureFunctionComponent(component);\n}\n\nfunction isPureFunctionComponent(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n component: any\n): component is FunctionComponent {\n return component?.$$typeof?.toString() === 'Symbol(react.memo)' && isFunctionComponent(component.type);\n}\n\nfunction isComponentClass(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n component: any\n): component is ComponentClass {\n return typeof component === 'object' && typeof component?.['render'] === 'function';\n}\n\n// There are no definitive ways to check if an object is a React component or not.\n// We are checking if the object has a render function (classic component).\n// Note: \"forwardRef()\" returns plain object, not class instance.\nfunction isReactComponent(\n // eslint-disable-next-line @typescript-eslint/no-explicit-any\n component: any\n): component is ComponentType {\n return (\n isFunctionComponent(component) ||\n isComponentClass(component) ||\n isFragment(component) ||\n isConsumer(component) ||\n isProvider(component)\n );\n}\n\nconst reactComponent = () =>\n custom<ComponentType<unknown>>(value => isReactComponent(value), 'not a valid React component');\n\nexport default isReactComponent;\nexport { reactComponent };\n"],"mappings":";;;;;AAAA,OAAO;AAAA,EACL;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,OAGK;;;ACDP,SAAS,cAAc;AAEvB,SAAS,WAEP,WACgC;AAChC,SAAO,WAAW,UAAU,SAAS,MAAM;AAC7C;AAEA,SAAS,WAEP,WACgC;AAChC,SAAO,WAAW,UAAU,SAAS,MAAM;AAC7C;AAEA,SAAS,WAEP,WAC8B;AAC9B,SAAO,WAAW,SAAS,MAAM;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;AAKA,SAAS,iBAEP,WAC4B;AAC5B,SACE,oBAAoB,SAAS,KAC7B,iBAAiB,SAAS,KAC1B,WAAW,SAAS,KACpB,WAAW,SAAS,KACpB,WAAW,SAAS;AAExB;AAKA,IAAO,2BAAQ;;;ADOf,SAAS,4BACP,UAA8C,CAAC,GACF;AAC7C,QAAM,mCAAoE;AAAA,IACxE,IAAI,WAAW;AACb,aAAO;AAAA,IACT;AAAA,IACA,0BAA0B,UAAUA,UAA+B;AACjE,UAAI,CAACA,UAAS,mBAAmB;AAC/B,cAAM,IAAI,MAA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O,OAAO;AAAA,MACnB,0BAA0B;AAAA,MAC1B,MAAM;AAAA,MACN,YAAY;AAAA,MACZ,OAAO;AAAA,MACP,YAAY;AAAA,MACZ,SAAS;AAAA,IACX,CAAC;AAAA,IACD;AAAA,EACF,CAAC;AACH;AAEA,IAAO,sCAAQ;","names":["options","middleware","init","enhancer","useBuildComponentCallback"]}
@@ -0,0 +1,17 @@
1
+ // src/private/compose.ts
2
+ function compose(...fns) {
3
+ return (fn) => fns.reduce((chain, fn2) => fn2(chain), fn);
4
+ }
5
+
6
+ // src/private/applyMiddleware.ts
7
+ function applyMiddleware(...arrayOfMiddleware) {
8
+ return (...init) => {
9
+ const chain = arrayOfMiddleware.map((middleware) => middleware(...init));
10
+ return compose(...chain);
11
+ };
12
+ }
13
+
14
+ export {
15
+ applyMiddleware
16
+ };
17
+ //# sourceMappingURL=chunk-TNTIZJJ5.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../src/private/compose.ts","../src/private/applyMiddleware.ts"],"sourcesContent":["// 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":";AAOe,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;","names":["fn"]}
@@ -0,0 +1,70 @@
1
+ import { ComponentType, PropsWithChildren } from 'react';
2
+
3
+ type Fn<P extends any[], R> = (...args: P) => R;
4
+ type Enhancer<P extends any[], R> = (next: Fn<P, R>) => Fn<P, R>;
5
+ type Middleware<P extends any[], R, S extends any[]> = (...init: S) => Enhancer<P, R>;
6
+
7
+ type ComponentMiddleware<Request, Props = {
8
+ children?: never;
9
+ }, Init = undefined> = Middleware<[
10
+ Request
11
+ ], ComponentType<Props> | false | null | undefined, [
12
+ Init
13
+ ]>;
14
+
15
+ type ResultComponent<Props> = ComponentType<Props> | false | null | undefined;
16
+ type UseBuildComponentCallbackOptions<Props> = {
17
+ fallbackComponent?: ResultComponent<Props> | undefined;
18
+ };
19
+ interface UseBuildComponentCallback<Request, Props> {
20
+ (request: Request, options?: undefined | UseBuildComponentCallbackOptions<Props>): ComponentType<Props> | undefined;
21
+ }
22
+ type ProviderProps<Request, Props, Init> = PropsWithChildren<{
23
+ middleware: readonly ComponentMiddleware<Request, Props, Init>[];
24
+ }> & (Init extends never | void ? {
25
+ readonly init?: undefined;
26
+ } : Init extends undefined | void ? {
27
+ readonly init?: Init;
28
+ } : {
29
+ readonly init: Init;
30
+ });
31
+ type ProxyProps<Request, Props extends object> = Props & {
32
+ readonly fallbackComponent?: ComponentType<Props> | undefined;
33
+ readonly request: Request;
34
+ };
35
+ type CreateChainOfResponsibilityOptions = {
36
+ /**
37
+ * Allows a middleware to pass another request object when calling its next middleware. Default is false.
38
+ *
39
+ * However, middleware could modify the request object before calling its next middleware. It is recommended
40
+ * to use Object.freeze() to prevent middleware from modifying the request object.
41
+ */
42
+ readonly passModifiedRequest?: boolean | undefined;
43
+ };
44
+ type AsMiddlewareProps<Request, Props, Init> = {
45
+ readonly init: Init;
46
+ readonly Next: ComponentType<Partial<Props>>;
47
+ readonly request: Request;
48
+ };
49
+ type AsMiddlewareComponentProps<Request, Props, Init> = Props & {
50
+ readonly middleware: AsMiddlewareProps<Request, Props, Init>;
51
+ };
52
+ type ChainOfResponsibility<Request, Props extends object, Init> = {
53
+ readonly asMiddleware: (middlewareComponent: ComponentType<AsMiddlewareComponentProps<Request, Props, Init>>) => ComponentMiddleware<Request, Props, Init>;
54
+ readonly Provider: ComponentType<ProviderProps<Request, Props, Init>>;
55
+ readonly Proxy: ComponentType<ProxyProps<Request, Props>>;
56
+ readonly types: {
57
+ readonly init: Init;
58
+ readonly middleware: ComponentMiddleware<Request, Props, Init>;
59
+ readonly middlewareComponentProps: AsMiddlewareComponentProps<Request, Props, Init>;
60
+ readonly props: Props;
61
+ readonly proxyProps: ProxyProps<Request, Props>;
62
+ readonly request: Request;
63
+ };
64
+ readonly useBuildComponentCallback: () => UseBuildComponentCallback<Request, Props>;
65
+ };
66
+ declare function createChainOfResponsibility<Request = void, Props extends object = {
67
+ readonly children?: never;
68
+ }, Init = void>(options?: CreateChainOfResponsibilityOptions): ChainOfResponsibility<Request, Props, Init>;
69
+
70
+ export { type CreateChainOfResponsibilityOptions as C, type ComponentMiddleware as a, createChainOfResponsibility as c };
@@ -0,0 +1,70 @@
1
+ import { ComponentType, PropsWithChildren } from 'react';
2
+
3
+ type Fn<P extends any[], R> = (...args: P) => R;
4
+ type Enhancer<P extends any[], R> = (next: Fn<P, R>) => Fn<P, R>;
5
+ type Middleware<P extends any[], R, S extends any[]> = (...init: S) => Enhancer<P, R>;
6
+
7
+ type ComponentMiddleware<Request, Props = {
8
+ children?: never;
9
+ }, Init = undefined> = Middleware<[
10
+ Request
11
+ ], ComponentType<Props> | false | null | undefined, [
12
+ Init
13
+ ]>;
14
+
15
+ type ResultComponent<Props> = ComponentType<Props> | false | null | undefined;
16
+ type UseBuildComponentCallbackOptions<Props> = {
17
+ fallbackComponent?: ResultComponent<Props> | undefined;
18
+ };
19
+ interface UseBuildComponentCallback<Request, Props> {
20
+ (request: Request, options?: undefined | UseBuildComponentCallbackOptions<Props>): ComponentType<Props> | undefined;
21
+ }
22
+ type ProviderProps<Request, Props, Init> = PropsWithChildren<{
23
+ middleware: readonly ComponentMiddleware<Request, Props, Init>[];
24
+ }> & (Init extends never | void ? {
25
+ readonly init?: undefined;
26
+ } : Init extends undefined | void ? {
27
+ readonly init?: Init;
28
+ } : {
29
+ readonly init: Init;
30
+ });
31
+ type ProxyProps<Request, Props extends object> = Props & {
32
+ readonly fallbackComponent?: ComponentType<Props> | undefined;
33
+ readonly request: Request;
34
+ };
35
+ type CreateChainOfResponsibilityOptions = {
36
+ /**
37
+ * Allows a middleware to pass another request object when calling its next middleware. Default is false.
38
+ *
39
+ * However, middleware could modify the request object before calling its next middleware. It is recommended
40
+ * to use Object.freeze() to prevent middleware from modifying the request object.
41
+ */
42
+ readonly passModifiedRequest?: boolean | undefined;
43
+ };
44
+ type AsMiddlewareProps<Request, Props, Init> = {
45
+ readonly init: Init;
46
+ readonly Next: ComponentType<Partial<Props>>;
47
+ readonly request: Request;
48
+ };
49
+ type AsMiddlewareComponentProps<Request, Props, Init> = Props & {
50
+ readonly middleware: AsMiddlewareProps<Request, Props, Init>;
51
+ };
52
+ type ChainOfResponsibility<Request, Props extends object, Init> = {
53
+ readonly asMiddleware: (middlewareComponent: ComponentType<AsMiddlewareComponentProps<Request, Props, Init>>) => ComponentMiddleware<Request, Props, Init>;
54
+ readonly Provider: ComponentType<ProviderProps<Request, Props, Init>>;
55
+ readonly Proxy: ComponentType<ProxyProps<Request, Props>>;
56
+ readonly types: {
57
+ readonly init: Init;
58
+ readonly middleware: ComponentMiddleware<Request, Props, Init>;
59
+ readonly middlewareComponentProps: AsMiddlewareComponentProps<Request, Props, Init>;
60
+ readonly props: Props;
61
+ readonly proxyProps: ProxyProps<Request, Props>;
62
+ readonly request: Request;
63
+ };
64
+ readonly useBuildComponentCallback: () => UseBuildComponentCallback<Request, Props>;
65
+ };
66
+ declare function createChainOfResponsibility<Request = void, Props extends object = {
67
+ readonly children?: never;
68
+ }, Init = void>(options?: CreateChainOfResponsibilityOptions): ChainOfResponsibility<Request, Props, Init>;
69
+
70
+ export { type CreateChainOfResponsibilityOptions as C, type ComponentMiddleware as a, createChainOfResponsibility as c };
@@ -1,72 +1,2 @@
1
- import { ComponentType, PropsWithChildren } from 'react';
2
-
3
- type Fn<P extends any[], R> = (...args: P) => R;
4
- type Enhancer<P extends any[], R> = (next: Fn<P, R>) => Fn<P, R>;
5
- type Middleware<P extends any[], R, S extends any[]> = (...init: S) => Enhancer<P, R>;
6
-
7
- type ComponentMiddleware<Request, Props = {
8
- children?: never;
9
- }, Init = undefined> = Middleware<[
10
- Request
11
- ], ComponentType<Props> | false | null | undefined, [
12
- Init
13
- ]>;
14
-
15
- type ResultComponent<Props> = ComponentType<Props> | false | null | undefined;
16
- type UseBuildComponentCallbackOptions<Props> = {
17
- fallbackComponent?: ResultComponent<Props>;
18
- };
19
- type UseBuildComponentCallback<Request, Props> = (request: Request, options?: UseBuildComponentCallbackOptions<Props>) => ComponentType<Props> | undefined;
20
- type ProviderProps<Request, Props, Init> = PropsWithChildren<{
21
- middleware: readonly ComponentMiddleware<Request, Props, Init>[];
22
- }> & (Init extends never | void ? {
23
- init?: undefined;
24
- } : Init extends undefined ? {
25
- init?: Init;
26
- } : {
27
- init: Init;
28
- });
29
- type ProxyProps<Request, Props extends object> = PropsWithChildren<Request extends never | void ? Props & {
30
- fallbackComponent?: ComponentType<Props>;
31
- request?: undefined;
32
- } : Request extends undefined ? Props & {
33
- fallbackComponent?: ComponentType<Props>;
34
- request?: Request;
35
- } : Props & {
36
- fallbackComponent?: ComponentType<Props>;
37
- request: Request;
38
- }>;
39
- type Options = {
40
- /**
41
- * Allows a middleware to pass another request object when calling its next middleware. Default is false.
42
- *
43
- * However, middleware could modify the request object before calling its next middleware. It is recommended
44
- * to use Object.freeze() to prevent middleware from modifying the request object.
45
- */
46
- passModifiedRequest?: boolean;
47
- };
48
- type MiddlewareProps<Request, Props, Init> = Readonly<{
49
- init: Init;
50
- Next: ComponentType<Partial<Props>>;
51
- request: Request;
52
- }>;
53
- type MiddlewareComponentProps<Request, Props, Init> = Props & Readonly<{
54
- middleware: MiddlewareProps<Request, Props, Init>;
55
- }>;
56
- declare function createChainOfResponsibility<Request = undefined, Props extends object = Readonly<{
57
- children?: never;
58
- }>, Init = undefined>(options?: Options): {
59
- asMiddleware: (middlewareComponent: ComponentType<MiddlewareComponentProps<Request, Props, Init>>) => ComponentMiddleware<Request, Props, Init>;
60
- Provider: ComponentType<ProviderProps<Request, Props, Init>>;
61
- Proxy: ComponentType<ProxyProps<Request, Props>>;
62
- types: {
63
- init: Init;
64
- middleware: ComponentMiddleware<Request, Props, Init>;
65
- middlewareComponentProps: MiddlewareComponentProps<Request, Props, Init>;
66
- props: Props;
67
- request: Request;
68
- };
69
- useBuildComponentCallback: () => UseBuildComponentCallback<Request, Props>;
70
- };
71
-
72
- export { type ComponentMiddleware, createChainOfResponsibility };
1
+ export { a as ComponentMiddleware, c as createChainOfResponsibility } from './index-Cx9W9BxD.mjs';
2
+ import 'react';
@@ -1,72 +1,2 @@
1
- import { ComponentType, PropsWithChildren } from 'react';
2
-
3
- type Fn<P extends any[], R> = (...args: P) => R;
4
- type Enhancer<P extends any[], R> = (next: Fn<P, R>) => Fn<P, R>;
5
- type Middleware<P extends any[], R, S extends any[]> = (...init: S) => Enhancer<P, R>;
6
-
7
- type ComponentMiddleware<Request, Props = {
8
- children?: never;
9
- }, Init = undefined> = Middleware<[
10
- Request
11
- ], ComponentType<Props> | false | null | undefined, [
12
- Init
13
- ]>;
14
-
15
- type ResultComponent<Props> = ComponentType<Props> | false | null | undefined;
16
- type UseBuildComponentCallbackOptions<Props> = {
17
- fallbackComponent?: ResultComponent<Props>;
18
- };
19
- type UseBuildComponentCallback<Request, Props> = (request: Request, options?: UseBuildComponentCallbackOptions<Props>) => ComponentType<Props> | undefined;
20
- type ProviderProps<Request, Props, Init> = PropsWithChildren<{
21
- middleware: readonly ComponentMiddleware<Request, Props, Init>[];
22
- }> & (Init extends never | void ? {
23
- init?: undefined;
24
- } : Init extends undefined ? {
25
- init?: Init;
26
- } : {
27
- init: Init;
28
- });
29
- type ProxyProps<Request, Props extends object> = PropsWithChildren<Request extends never | void ? Props & {
30
- fallbackComponent?: ComponentType<Props>;
31
- request?: undefined;
32
- } : Request extends undefined ? Props & {
33
- fallbackComponent?: ComponentType<Props>;
34
- request?: Request;
35
- } : Props & {
36
- fallbackComponent?: ComponentType<Props>;
37
- request: Request;
38
- }>;
39
- type Options = {
40
- /**
41
- * Allows a middleware to pass another request object when calling its next middleware. Default is false.
42
- *
43
- * However, middleware could modify the request object before calling its next middleware. It is recommended
44
- * to use Object.freeze() to prevent middleware from modifying the request object.
45
- */
46
- passModifiedRequest?: boolean;
47
- };
48
- type MiddlewareProps<Request, Props, Init> = Readonly<{
49
- init: Init;
50
- Next: ComponentType<Partial<Props>>;
51
- request: Request;
52
- }>;
53
- type MiddlewareComponentProps<Request, Props, Init> = Props & Readonly<{
54
- middleware: MiddlewareProps<Request, Props, Init>;
55
- }>;
56
- declare function createChainOfResponsibility<Request = undefined, Props extends object = Readonly<{
57
- children?: never;
58
- }>, Init = undefined>(options?: Options): {
59
- asMiddleware: (middlewareComponent: ComponentType<MiddlewareComponentProps<Request, Props, Init>>) => ComponentMiddleware<Request, Props, Init>;
60
- Provider: ComponentType<ProviderProps<Request, Props, Init>>;
61
- Proxy: ComponentType<ProxyProps<Request, Props>>;
62
- types: {
63
- init: Init;
64
- middleware: ComponentMiddleware<Request, Props, Init>;
65
- middlewareComponentProps: MiddlewareComponentProps<Request, Props, Init>;
66
- props: Props;
67
- request: Request;
68
- };
69
- useBuildComponentCallback: () => UseBuildComponentCallback<Request, Props>;
70
- };
71
-
72
- export { type ComponentMiddleware, createChainOfResponsibility };
1
+ export { a as ComponentMiddleware, c as createChainOfResponsibility } from './index-Cx9W9BxD.js';
2
+ import 'react';
@@ -1,12 +1,15 @@
1
1
  import { IRenderFunction } from '@fluentui/react';
2
2
  import { Key } from 'react';
3
- import { createChainOfResponsibility } from './react-chain-of-responsibility.mjs';
3
+ import { C as CreateChainOfResponsibilityOptions, c as createChainOfResponsibility } from './index-Cx9W9BxD.mjs';
4
4
 
5
5
  type UseBuildRenderFunctionOptions<Props> = {
6
6
  getKey?: (props: Props | undefined) => Key;
7
7
  };
8
8
  type UseBuildRenderFunction<Props> = (options?: UseBuildRenderFunctionOptions<Props>) => IRenderFunction<Props>;
9
- declare function createChainOfResponsibilityForFluentUI<Props extends object, Init = undefined>(options?: Parameters<typeof createChainOfResponsibility>[0]): ReturnType<typeof createChainOfResponsibility<Props | undefined, Props, Init>> & {
9
+ /**
10
+ * @deprecated Fluent UI v9 no longer use `IRenderFunction` for custom render. We no longer validate the correctness of this function.
11
+ */
12
+ declare function createChainOfResponsibilityForFluentUI<Props extends object, Init = undefined>(options?: CreateChainOfResponsibilityOptions): ReturnType<typeof createChainOfResponsibility<Props | undefined, Props, Init>> & {
10
13
  useBuildRenderFunction: UseBuildRenderFunction<Props>;
11
14
  };
12
15
 
@@ -1,12 +1,15 @@
1
1
  import { IRenderFunction } from '@fluentui/react';
2
2
  import { Key } from 'react';
3
- import { createChainOfResponsibility } from './react-chain-of-responsibility.js';
3
+ import { C as CreateChainOfResponsibilityOptions, c as createChainOfResponsibility } from './index-Cx9W9BxD.js';
4
4
 
5
5
  type UseBuildRenderFunctionOptions<Props> = {
6
6
  getKey?: (props: Props | undefined) => Key;
7
7
  };
8
8
  type UseBuildRenderFunction<Props> = (options?: UseBuildRenderFunctionOptions<Props>) => IRenderFunction<Props>;
9
- declare function createChainOfResponsibilityForFluentUI<Props extends object, Init = undefined>(options?: Parameters<typeof createChainOfResponsibility>[0]): ReturnType<typeof createChainOfResponsibility<Props | undefined, Props, Init>> & {
9
+ /**
10
+ * @deprecated Fluent UI v9 no longer use `IRenderFunction` for custom render. We no longer validate the correctness of this function.
11
+ */
12
+ declare function createChainOfResponsibilityForFluentUI<Props extends object, Init = undefined>(options?: CreateChainOfResponsibilityOptions): ReturnType<typeof createChainOfResponsibility<Props | undefined, Props, Init>> & {
10
13
  useBuildRenderFunction: UseBuildRenderFunction<Props>;
11
14
  };
12
15