@webiny/react-composition 5.40.5 → 5.41.0-dbt.0

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/Context.d.ts CHANGED
@@ -21,9 +21,9 @@ interface ComposedComponent {
21
21
  export interface HigherOrderComponent<TProps = any, TOutput = TProps> {
22
22
  (Component: GenericComponent<TProps>): GenericComponent<TOutput>;
23
23
  }
24
- declare type ComposedComponents = Map<ComponentType<unknown>, ComposedComponent>;
25
- declare type ComponentScopes = Map<string, ComposedComponents>;
26
- export declare type DecoratableTypes = DecoratableComponent | DecoratableHook;
24
+ type ComposedComponents = Map<ComponentType<unknown>, ComposedComponent>;
25
+ type ComponentScopes = Map<string, ComposedComponents>;
26
+ export type DecoratableTypes = DecoratableComponent | DecoratableHook;
27
27
  interface CompositionContextGetComponentCallable {
28
28
  (component: ComponentType<unknown>, scope?: string): ComposedFunction | GenericComponent | undefined;
29
29
  }
package/Context.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["_react","_interopRequireWildcard","require","_CompositionScope","compose","_len","arguments","length","fns","Array","_key","decoratee","reduceRight","decorator","CompositionContext","createContext","undefined","CompositionProvider","exports","_ref","children","_useState","useState","Map","_useState2","_slicedToArray2","default","components","setComponents","composeComponent","useCallback","component","hocs","scope","prevComponents","scopeMap","get","recipe","newHocs","concat","_toConsumableArray2","set","apply","reverse","newHOCs","filter","hoc","includes","NewComponent","getComponent","Component","composedComponent","defaultScopeMap","defaultComponent","context","useMemo","createElement","Provider","value","useComponent","baseFunction","useOptionalComposition","useCompositionScope","useComposition","useContext","Error"],"sources":["Context.tsx"],"sourcesContent":["import React, {\n ComponentType,\n createContext,\n useCallback,\n useContext,\n useMemo,\n useState\n} from \"react\";\nimport { useCompositionScope } from \"~/CompositionScope\";\nimport {\n ComposedFunction,\n ComposeWith,\n DecoratableComponent,\n DecoratableHook,\n Decorator,\n Enumerable,\n GenericComponent,\n GenericHook\n} from \"~/types\";\n\nexport function compose<T>(...fns: Decorator<T>[]) {\n return (decoratee: T): T => {\n return fns.reduceRight((decoratee, decorator) => decorator(decoratee), decoratee);\n };\n}\n\ninterface ComposedComponent {\n /**\n * Ready to use React component.\n */\n component: GenericHook | GenericComponent;\n /**\n * HOCs used to compose the original component.\n */\n hocs: Decorator<GenericComponent | GenericHook>[];\n /**\n * Component composition can be scoped.\n */\n scope?: string;\n}\n\n/**\n * @deprecated Use `Decorator` instead.\n */\nexport interface HigherOrderComponent<TProps = any, TOutput = TProps> {\n (Component: GenericComponent<TProps>): GenericComponent<TOutput>;\n}\n\ntype ComposedComponents = Map<ComponentType<unknown>, ComposedComponent>;\ntype ComponentScopes = Map<string, ComposedComponents>;\n\nexport type DecoratableTypes = DecoratableComponent | DecoratableHook;\n\ninterface CompositionContextGetComponentCallable {\n (component: ComponentType<unknown>, scope?: string):\n | ComposedFunction\n | GenericComponent\n | undefined;\n}\n\ninterface CompositionContext {\n components: ComponentScopes;\n getComponent: CompositionContextGetComponentCallable;\n composeComponent(\n component: ComponentType<unknown>,\n hocs: Enumerable<ComposeWith>,\n scope?: string\n ): void;\n}\n\nconst CompositionContext = createContext<CompositionContext | undefined>(undefined);\n\ninterface CompositionProviderProps {\n children: React.ReactNode;\n}\n\nexport const CompositionProvider = ({ children }: CompositionProviderProps) => {\n const [components, setComponents] = useState<ComponentScopes>(new Map());\n\n const composeComponent = useCallback(\n (\n component: GenericHook | GenericComponent,\n hocs: HigherOrderComponent<any, any>[],\n scope: string | undefined = \"*\"\n ) => {\n setComponents(prevComponents => {\n const components = new Map(prevComponents);\n const scopeMap: ComposedComponents = components.get(scope) || new Map();\n const recipe = scopeMap.get(component) || { component: null, hocs: [] };\n\n const newHocs = [...(recipe.hocs || []), ...hocs] as Decorator<\n GenericHook | GenericComponent\n >[];\n\n scopeMap.set(component, {\n component: compose(...[...newHocs].reverse())(component),\n hocs: newHocs\n });\n\n components.set(scope, scopeMap);\n return components;\n });\n\n // Return a function that will remove the added HOCs.\n return () => {\n setComponents(prevComponents => {\n const components = new Map(prevComponents);\n const scopeMap: ComposedComponents = components.get(scope) || new Map();\n const recipe = scopeMap.get(component) || {\n component: null,\n hocs: []\n };\n\n const newHOCs = [...recipe.hocs].filter(hoc => !hocs.includes(hoc));\n const NewComponent = compose(...[...newHOCs].reverse())(component);\n\n scopeMap.set(component, {\n component: NewComponent,\n hocs: newHOCs\n });\n\n components.set(scope, scopeMap);\n return components;\n });\n };\n },\n [setComponents]\n );\n\n const getComponent = useCallback<CompositionContextGetComponentCallable>(\n (Component, scope = \"*\") => {\n const scopeMap: ComposedComponents = components.get(scope) || new Map();\n const composedComponent = scopeMap.get(Component);\n if (!composedComponent && scope !== \"*\") {\n // Check if a default scope component exists\n const defaultScopeMap: ComposedComponents = components.get(\"*\") || new Map();\n const defaultComponent = defaultScopeMap.get(Component);\n return defaultComponent ? defaultComponent.component : undefined;\n }\n return composedComponent ? composedComponent.component : undefined;\n },\n [components]\n );\n\n const context: CompositionContext = useMemo(\n () => ({\n getComponent,\n composeComponent,\n components\n }),\n [components, composeComponent]\n );\n\n return <CompositionContext.Provider value={context}>{children}</CompositionContext.Provider>;\n};\n\nexport function useComponent<T>(baseFunction: T) {\n const context = useOptionalComposition();\n const scope = useCompositionScope();\n\n if (!context) {\n return baseFunction;\n }\n\n return (context.getComponent(baseFunction as any, scope) || baseFunction) as T;\n}\n\n/**\n * This hook will throw an error if composition context doesn't exist.\n */\nexport function useComposition() {\n const context = useContext(CompositionContext);\n if (!context) {\n throw new Error(\n `You're missing a <CompositionProvider> higher up in your component hierarchy!`\n );\n }\n\n return context;\n}\n\n/**\n * This hook will not throw an error if composition context doesn't exist.\n */\nexport function useOptionalComposition() {\n return useContext(CompositionContext);\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AAQA,IAAAC,iBAAA,GAAAD,OAAA;AAYO,SAASE,OAAOA,CAAA,EAA4B;EAAA,SAAAC,IAAA,GAAA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B,aAAA,CAAC1C,kBAAkB,CAAC2C,QAAQ;IAACC,KAAK,EAAEJ;EAAQ,GAAElC,QAAsC,CAAC;AAChG,CAAC;AAEM,SAASuC,YAAYA,CAAIC,YAAe,EAAE;EAC7C,IAAMN,OAAO,GAAGO,sBAAsB,CAAC,CAAC;EACxC,IAAM5B,KAAK,GAAG,IAAA6B,qCAAmB,EAAC,CAAC;EAEnC,IAAI,CAACR,OAAO,EAAE;IACV,OAAOM,YAAY;EACvB;EAEA,OAAQN,OAAO,CAACL,YAAY,CAACW,YAAY,EAAS3B,KAAK,CAAC,IAAI2B,YAAY;AAC5E;;AAEA;AACA;AACA;AACO,SAASG,cAAcA,CAAA,EAAG;EAC7B,IAAMT,OAAO,GAAG,IAAAU,iBAAU,EAAClD,kBAAkB,CAAC;EAC9C,IAAI,CAACwC,OAAO,EAAE;IACV,MAAM,IAAIW,KAAK,gFAEf,CAAC;EACL;EAEA,OAAOX,OAAO;AAClB;;AAEA;AACA;AACA;AACO,SAASO,sBAAsBA,CAAA,EAAG;EACrC,OAAO,IAAAG,iBAAU,EAAClD,kBAAkB,CAAC;AACzC","ignoreList":[]}
1
+ {"version":3,"names":["_react","_interopRequireWildcard","require","_CompositionScope","compose","_len","arguments","length","fns","Array","_key","decoratee","reduceRight","decorator","CompositionContext","createContext","undefined","CompositionProvider","exports","_ref","children","_useState","useState","Map","_useState2","_slicedToArray2","default","components","setComponents","composeComponent","useCallback","component","hocs","scope","prevComponents","scopeMap","get","recipe","newHocs","concat","_toConsumableArray2","set","apply","reverse","newHOCs","filter","hoc","includes","NewComponent","getComponent","Component","composedComponent","defaultScopeMap","defaultComponent","context","useMemo","createElement","Provider","value","useComponent","baseFunction","useOptionalComposition","useCompositionScope","useComposition","useContext","Error"],"sources":["Context.tsx"],"sourcesContent":["import React, {\n ComponentType,\n createContext,\n useCallback,\n useContext,\n useMemo,\n useState\n} from \"react\";\nimport { useCompositionScope } from \"~/CompositionScope\";\nimport {\n ComposedFunction,\n ComposeWith,\n DecoratableComponent,\n DecoratableHook,\n Decorator,\n Enumerable,\n GenericComponent,\n GenericHook\n} from \"~/types\";\n\nexport function compose<T>(...fns: Decorator<T>[]) {\n return (decoratee: T): T => {\n return fns.reduceRight((decoratee, decorator) => decorator(decoratee), decoratee) as T;\n };\n}\n\ninterface ComposedComponent {\n /**\n * Ready to use React component.\n */\n component: GenericHook | GenericComponent;\n /**\n * HOCs used to compose the original component.\n */\n hocs: Decorator<GenericComponent | GenericHook>[];\n /**\n * Component composition can be scoped.\n */\n scope?: string;\n}\n\n/**\n * @deprecated Use `Decorator` instead.\n */\nexport interface HigherOrderComponent<TProps = any, TOutput = TProps> {\n (Component: GenericComponent<TProps>): GenericComponent<TOutput>;\n}\n\ntype ComposedComponents = Map<ComponentType<unknown>, ComposedComponent>;\ntype ComponentScopes = Map<string, ComposedComponents>;\n\nexport type DecoratableTypes = DecoratableComponent | DecoratableHook;\n\ninterface CompositionContextGetComponentCallable {\n (component: ComponentType<unknown>, scope?: string):\n | ComposedFunction\n | GenericComponent\n | undefined;\n}\n\ninterface CompositionContext {\n components: ComponentScopes;\n getComponent: CompositionContextGetComponentCallable;\n composeComponent(\n component: ComponentType<unknown>,\n hocs: Enumerable<ComposeWith>,\n scope?: string\n ): void;\n}\n\nconst CompositionContext = createContext<CompositionContext | undefined>(undefined);\n\ninterface CompositionProviderProps {\n children: React.ReactNode;\n}\n\nexport const CompositionProvider = ({ children }: CompositionProviderProps) => {\n const [components, setComponents] = useState<ComponentScopes>(new Map());\n\n const composeComponent = useCallback(\n (\n component: GenericHook | GenericComponent,\n hocs: HigherOrderComponent<any, any>[],\n scope: string | undefined = \"*\"\n ) => {\n setComponents(prevComponents => {\n const components = new Map(prevComponents);\n const scopeMap: ComposedComponents = components.get(scope) || new Map();\n const recipe = scopeMap.get(component) || { component: null, hocs: [] };\n\n const newHocs = [...(recipe.hocs || []), ...hocs] as Decorator<\n GenericHook | GenericComponent\n >[];\n\n scopeMap.set(component, {\n component: compose(...[...newHocs].reverse())(component),\n hocs: newHocs\n });\n\n components.set(scope, scopeMap);\n return components;\n });\n\n // Return a function that will remove the added HOCs.\n return () => {\n setComponents(prevComponents => {\n const components = new Map(prevComponents);\n const scopeMap: ComposedComponents = components.get(scope) || new Map();\n const recipe = scopeMap.get(component) || {\n component: null,\n hocs: []\n };\n\n const newHOCs = [...recipe.hocs].filter(hoc => !hocs.includes(hoc));\n const NewComponent = compose(...[...newHOCs].reverse())(component);\n\n scopeMap.set(component, {\n component: NewComponent,\n hocs: newHOCs\n });\n\n components.set(scope, scopeMap);\n return components;\n });\n };\n },\n [setComponents]\n );\n\n const getComponent = useCallback<CompositionContextGetComponentCallable>(\n (Component, scope = \"*\") => {\n const scopeMap: ComposedComponents = components.get(scope) || new Map();\n const composedComponent = scopeMap.get(Component);\n if (!composedComponent && scope !== \"*\") {\n // Check if a default scope component exists\n const defaultScopeMap: ComposedComponents = components.get(\"*\") || new Map();\n const defaultComponent = defaultScopeMap.get(Component);\n return defaultComponent ? defaultComponent.component : undefined;\n }\n return composedComponent ? composedComponent.component : undefined;\n },\n [components]\n );\n\n const context: CompositionContext = useMemo(\n () => ({\n getComponent,\n composeComponent,\n components\n }),\n [components, composeComponent]\n );\n\n return <CompositionContext.Provider value={context}>{children}</CompositionContext.Provider>;\n};\n\nexport function useComponent<T>(baseFunction: T) {\n const context = useOptionalComposition();\n const scope = useCompositionScope();\n\n if (!context) {\n return baseFunction;\n }\n\n return (context.getComponent(baseFunction as any, scope) || baseFunction) as T;\n}\n\n/**\n * This hook will throw an error if composition context doesn't exist.\n */\nexport function useComposition() {\n const context = useContext(CompositionContext);\n if (!context) {\n throw new Error(\n `You're missing a <CompositionProvider> higher up in your component hierarchy!`\n );\n }\n\n return context;\n}\n\n/**\n * This hook will not throw an error if composition context doesn't exist.\n */\nexport function useOptionalComposition() {\n return useContext(CompositionContext);\n}\n"],"mappings":";;;;;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA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CAAC,EACF,CAACA,UAAU,EAAEE,gBAAgB,CACjC,CAAC;EAED,oBAAO7B,MAAA,CAAA0B,OAAA,CAAA8B,aAAA,CAAC1C,kBAAkB,CAAC2C,QAAQ;IAACC,KAAK,EAAEJ;EAAQ,GAAElC,QAAsC,CAAC;AAChG,CAAC;AAEM,SAASuC,YAAYA,CAAIC,YAAe,EAAE;EAC7C,IAAMN,OAAO,GAAGO,sBAAsB,CAAC,CAAC;EACxC,IAAM5B,KAAK,GAAG,IAAA6B,qCAAmB,EAAC,CAAC;EAEnC,IAAI,CAACR,OAAO,EAAE;IACV,OAAOM,YAAY;EACvB;EAEA,OAAQN,OAAO,CAACL,YAAY,CAACW,YAAY,EAAS3B,KAAK,CAAC,IAAI2B,YAAY;AAC5E;;AAEA;AACA;AACA;AACO,SAASG,cAAcA,CAAA,EAAG;EAC7B,IAAMT,OAAO,GAAG,IAAAU,iBAAU,EAAClD,kBAAkB,CAAC;EAC9C,IAAI,CAACwC,OAAO,EAAE;IACV,MAAM,IAAIW,KAAK,gFAEf,CAAC;EACL;EAEA,OAAOX,OAAO;AAClB;;AAEA;AACA;AACA;AACO,SAASO,sBAAsBA,CAAA,EAAG;EACrC,OAAO,IAAAG,iBAAU,EAAClD,kBAAkB,CAAC;AACzC","ignoreList":[]}
@@ -1,18 +1,18 @@
1
1
  import React from "react";
2
- import { CanReturnNull, Decoratable, DecoratableComponent, DecoratableHook, Decorator } from "./types";
3
- declare type GetBaseFunction<T> = T extends DecoratableComponent<infer F> ? F : never;
2
+ import { CanReturnNullOrElement, Decoratable, DecoratableComponent, DecoratableHook, Decorator } from "./types";
3
+ type GetBaseFunction<T> = T extends DecoratableComponent<infer F> ? F : never;
4
4
  /**
5
5
  * Creates a component which, when mounted, registers a Higher Order Component for the given base component.
6
6
  * This is particularly useful for decorating (wrapping) existing composable components.
7
7
  * For more information, visit https://www.webiny.com/docs/admin-area/basics/framework.
8
8
  */
9
- export declare function createComponentPlugin<T extends Decoratable>(Base: T, hoc: T extends DecoratableComponent ? Decorator<CanReturnNull<GetBaseFunction<T>>> : Decorator<GetBaseFunction<T>>): {
9
+ export declare function createComponentPlugin<T extends Decoratable>(Base: T, hoc: T extends DecoratableComponent ? Decorator<CanReturnNullOrElement<GetBaseFunction<T>>> : Decorator<GetBaseFunction<T>>): {
10
10
  (): React.JSX.Element;
11
11
  displayName: string;
12
12
  };
13
- export declare type GetDecorateeParams<T> = T extends (params?: infer P1) => any ? P1 : T extends (params: infer P2) => any ? P2 : any;
14
- export declare type GetDecoratee<T> = T extends DecoratableHook<infer F> ? F : T extends DecoratableComponent<infer F> ? F : never;
15
- export declare function createDecorator<T extends Decoratable>(Base: T, hoc: T extends DecoratableComponent ? Decorator<CanReturnNull<GetBaseFunction<T>>> : Decorator<GetBaseFunction<T>>): {
13
+ export type GetDecorateeParams<T> = T extends (params?: infer P1) => any ? P1 : T extends (params: infer P2) => any ? P2 : any;
14
+ export type GetDecoratee<T> = T extends DecoratableHook<infer F> ? F : T extends DecoratableComponent<infer F> ? F : never;
15
+ export declare function createDecorator<T extends Decoratable>(Base: T, hoc: T extends DecoratableComponent ? Decorator<CanReturnNullOrElement<GetBaseFunction<T>>> : Decorator<GetBaseFunction<T>>): {
16
16
  (): React.JSX.Element;
17
17
  displayName: string;
18
18
  };
@@ -1 +1 @@
1
- {"version":3,"names":["_react","_interopRequireDefault","require","_Compose","createComponentPlugin","Base","hoc","createDecorator","isDecoratableComponent","decoratable","DecoratorPlugin","default","createElement","Compose","component","with","displayName"],"sources":["createDecorator.tsx"],"sourcesContent":["import React from \"react\";\nimport {\n CanReturnNull,\n Decoratable,\n DecoratableComponent,\n DecoratableHook,\n Decorator\n} from \"~/types\";\nimport { Compose } from \"~/Compose\";\n\ntype GetBaseFunction<T> = T extends DecoratableComponent<infer F> ? F : never;\n\n/**\n * Creates a component which, when mounted, registers a Higher Order Component for the given base component.\n * This is particularly useful for decorating (wrapping) existing composable components.\n * For more information, visit https://www.webiny.com/docs/admin-area/basics/framework.\n */\nexport function createComponentPlugin<T extends Decoratable>(\n Base: T,\n hoc: T extends DecoratableComponent\n ? Decorator<CanReturnNull<GetBaseFunction<T>>>\n : Decorator<GetBaseFunction<T>>\n) {\n return createDecorator(Base, hoc);\n}\n\n// Maybe there's a better way to mark params as non-existent, but for now I left it as `any`.\n// TODO: revisit this type; not sure if `?` can be handled in one clause\nexport type GetDecorateeParams<T> = T extends (params?: infer P1) => any\n ? P1\n : T extends (params: infer P2) => any\n ? P2\n : any;\n\nexport type GetDecoratee<T> = T extends DecoratableHook<infer F>\n ? F\n : T extends DecoratableComponent<infer F>\n ? F\n : never;\n\nconst isDecoratableComponent = (\n decoratable: DecoratableComponent | DecoratableHook\n): decoratable is DecoratableComponent => {\n return \"displayName\" in decoratable;\n};\n\nexport function createDecorator<T extends Decoratable>(\n Base: T,\n hoc: T extends DecoratableComponent\n ? Decorator<CanReturnNull<GetBaseFunction<T>>>\n : Decorator<GetBaseFunction<T>>\n) {\n const DecoratorPlugin = () => <Compose component={Base} with={hoc as any} />;\n if (isDecoratableComponent(Base)) {\n DecoratorPlugin.displayName = Base.displayName;\n }\n return DecoratorPlugin;\n}\n"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAQA,IAAAC,QAAA,GAAAD,OAAA;AAIA;AACA;AACA;AACA;AACA;AACO,SAASE,qBAAqBA,CACjCC,IAAO,EACPC,GAEmC,EACrC;EACE,OAAOC,eAAe,CAACF,IAAI,EAAEC,GAAG,CAAC;AACrC;;AAEA;AACA;;AAaA,IAAME,sBAAsB,GAAG,SAAzBA,sBAAsBA,CACxBC,WAAmD,EACb;EACtC,OAAO,aAAa,IAAIA,WAAW;AACvC,CAAC;AAEM,SAASF,eAAeA,CAC3BF,IAAO,EACPC,GAEmC,EACrC;EACE,IAAMI,eAAe,GAAG,SAAlBA,eAAeA,CAAA;IAAA,oBAASV,MAAA,CAAAW,OAAA,CAAAC,aAAA,CAACT,QAAA,CAAAU,OAAO;MAACC,SAAS,EAAET,IAAK;MAACU,IAAI,EAAET;IAAW,CAAE,CAAC;EAAA;EAC5E,IAAIE,sBAAsB,CAACH,IAAI,CAAC,EAAE;IAC9BK,eAAe,CAACM,WAAW,GAAGX,IAAI,CAACW,WAAW;EAClD;EACA,OAAON,eAAe;AAC1B","ignoreList":[]}
1
+ {"version":3,"names":["_react","_interopRequireDefault","require","_Compose","createComponentPlugin","Base","hoc","createDecorator","isDecoratableComponent","decoratable","DecoratorPlugin","default","createElement","Compose","component","with","displayName"],"sources":["createDecorator.tsx"],"sourcesContent":["import React from \"react\";\nimport {\n CanReturnNullOrElement,\n Decoratable,\n DecoratableComponent,\n DecoratableHook,\n Decorator\n} from \"~/types\";\nimport { Compose } from \"~/Compose\";\n\ntype GetBaseFunction<T> = T extends DecoratableComponent<infer F> ? F : never;\n\n/**\n * Creates a component which, when mounted, registers a Higher Order Component for the given base component.\n * This is particularly useful for decorating (wrapping) existing composable components.\n * For more information, visit https://www.webiny.com/docs/admin-area/basics/framework.\n */\nexport function createComponentPlugin<T extends Decoratable>(\n Base: T,\n hoc: T extends DecoratableComponent\n ? Decorator<CanReturnNullOrElement<GetBaseFunction<T>>>\n : Decorator<GetBaseFunction<T>>\n) {\n return createDecorator(Base, hoc);\n}\n\n// Maybe there's a better way to mark params as non-existent, but for now I left it as `any`.\n// TODO: revisit this type; not sure if `?` can be handled in one clause\nexport type GetDecorateeParams<T> = T extends (params?: infer P1) => any\n ? P1\n : T extends (params: infer P2) => any\n ? P2\n : any;\n\nexport type GetDecoratee<T> = T extends DecoratableHook<infer F>\n ? F\n : T extends DecoratableComponent<infer F>\n ? F\n : never;\n\nconst isDecoratableComponent = (\n decoratable: DecoratableComponent | DecoratableHook\n): decoratable is DecoratableComponent => {\n return \"displayName\" in decoratable;\n};\n\nexport function createDecorator<T extends Decoratable>(\n Base: T,\n hoc: T extends DecoratableComponent\n ? Decorator<CanReturnNullOrElement<GetBaseFunction<T>>>\n : Decorator<GetBaseFunction<T>>\n) {\n const DecoratorPlugin = () => <Compose component={Base} with={hoc as any} />;\n if (isDecoratableComponent(Base)) {\n DecoratorPlugin.displayName = Base.displayName;\n }\n return DecoratorPlugin;\n}\n"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAQA,IAAAC,QAAA,GAAAD,OAAA;AAIA;AACA;AACA;AACA;AACA;AACO,SAASE,qBAAqBA,CACjCC,IAAO,EACPC,GAEmC,EACrC;EACE,OAAOC,eAAe,CAACF,IAAI,EAAEC,GAAG,CAAC;AACrC;;AAEA;AACA;;AAaA,IAAME,sBAAsB,GAAG,SAAzBA,sBAAsBA,CACxBC,WAAmD,EACb;EACtC,OAAO,aAAa,IAAIA,WAAW;AACvC,CAAC;AAEM,SAASF,eAAeA,CAC3BF,IAAO,EACPC,GAEmC,EACrC;EACE,IAAMI,eAAe,GAAG,SAAlBA,eAAeA,CAAA;IAAA,oBAASV,MAAA,CAAAW,OAAA,CAAAC,aAAA,CAACT,QAAA,CAAAU,OAAO;MAACC,SAAS,EAAET,IAAK;MAACU,IAAI,EAAET;IAAW,CAAE,CAAC;EAAA;EAC5E,IAAIE,sBAAsB,CAACH,IAAI,CAAC,EAAE;IAC9BK,eAAe,CAACM,WAAW,GAAGX,IAAI,CAACW,WAAW;EAClD;EACA,OAAON,eAAe;AAC1B","ignoreList":[]}
package/decorators.d.ts CHANGED
@@ -1,18 +1,14 @@
1
1
  import React from "react";
2
2
  import { GetDecoratee, GetDecorateeParams } from "./createDecorator";
3
- import { DecoratableComponent, GenericComponent, Decorator, CanReturnNull, GenericHook, DecoratableHook } from "./types";
3
+ import { DecoratableComponent, GenericComponent, Decorator, GenericHook, DecoratableHook, ComponentDecorator } from "./types";
4
4
  export interface ShouldDecorate<TDecorator = any, TComponent = any> {
5
5
  (decoratorProps: TDecorator, componentProps: TComponent): boolean;
6
6
  }
7
7
  export declare function createConditionalDecorator<TDecoratee extends GenericComponent>(shouldDecorate: ShouldDecorate, decorator: Decorator<TDecoratee>, decoratorProps: unknown): Decorator<TDecoratee>;
8
- export declare function createDecoratorFactory<TDecorator>(): <TDecoratable extends DecoratableComponent<GenericComponent<any>>>(decoratable: TDecoratable, shouldDecorate?: ShouldDecorate<TDecorator, GetDecorateeParams<GetDecoratee<TDecoratable>>> | undefined) => (decorator: Decorator<CanReturnNull<GetDecoratee<TDecoratable>>>) => (props: TDecorator) => React.JSX.Element;
8
+ export declare function createDecoratorFactory<TDecorator>(): <TDecoratable extends DecoratableComponent<GenericComponent<any>>>(decoratable: TDecoratable, shouldDecorate?: ShouldDecorate<TDecorator, GetDecorateeParams<GetDecoratee<TDecoratable>>> | undefined) => (decorator: ComponentDecorator<GetDecoratee<TDecoratable>>) => (props: TDecorator) => React.JSX.Element;
9
9
  export declare function createHookDecoratorFactory(): <TDecoratable extends DecoratableHook<GenericHook<any, any>>>(decoratable: TDecoratable) => (decorator: Decorator<GetDecoratee<TDecoratable>>) => () => React.JSX.Element;
10
- export declare function withDecoratorFactory<TDecorator>(): <TDecoratable extends DecoratableComponent<GenericComponent<any>>>(Component: TDecoratable, shouldDecorate?: ShouldDecorate<TDecorator, GetDecorateeParams<GetDecoratee<TDecoratable>>> | undefined) => GenericComponent<GetDecorateeParams<GetDecoratee<TDecoratable>>> & {
11
- original: GenericComponent<GetDecorateeParams<GetDecoratee<TDecoratable>>>;
12
- originalName: string;
13
- displayName: string;
14
- } & {
15
- createDecorator: (decorator: Decorator<CanReturnNull<GetDecoratee<TDecoratable>>>) => (props: TDecorator) => React.JSX.Element;
10
+ export declare function withDecoratorFactory<TDecorator>(): <TDecoratable extends DecoratableComponent<GenericComponent<any>>>(Component: TDecoratable, shouldDecorate?: ShouldDecorate<TDecorator, GetDecorateeParams<GetDecoratee<TDecoratable>>> | undefined) => TDecoratable & {
11
+ createDecorator: (decorator: ComponentDecorator<GetDecoratee<TDecoratable>>) => (props: TDecorator) => React.JSX.Element;
16
12
  };
17
13
  export declare function withHookDecoratorFactory(): <TDecoratable extends DecoratableHook<GenericHook<any, any>>>(hook: TDecoratable) => GenericHook<GetDecorateeParams<GetDecoratee<TDecoratable>>, ReturnType<GetDecoratee<TDecoratable>>> & {
18
14
  original: GenericHook<GetDecorateeParams<GetDecoratee<TDecoratable>>, ReturnType<GetDecoratee<TDecoratable>>>;
package/decorators.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["_react","_interopRequireDefault","require","_Compose","createConditionalDecorator","shouldDecorate","decorator","decoratorProps","Original","DecoratedComponent","React","memo","displayName","ShouldDecorate","props","default","createElement","memoizedComponent","decoratee","createDecoratorFactory","from","decoratable","createDecorator","DecoratorPlugin","componentDecorator","Compose","function","with","createHookDecoratorFactory","withDecoratorFactory","WithDecorator","Component","Object","assign","withHookDecoratorFactory","WithHookDecorator","hook"],"sources":["decorators.tsx"],"sourcesContent":["import React from \"react\";\nimport { Compose } from \"~/Compose\";\nimport { GetDecoratee, GetDecorateeParams } from \"~/createDecorator\";\nimport {\n DecoratableComponent,\n GenericComponent,\n Decorator,\n CanReturnNull,\n GenericHook,\n DecoratableHook\n} from \"~/types\";\n\nexport interface ShouldDecorate<TDecorator = any, TComponent = any> {\n (decoratorProps: TDecorator, componentProps: TComponent): boolean;\n}\n\nexport function createConditionalDecorator<TDecoratee extends GenericComponent>(\n shouldDecorate: ShouldDecorate,\n decorator: Decorator<TDecoratee>,\n decoratorProps: unknown\n): Decorator<TDecoratee> {\n return (Original => {\n const DecoratedComponent = React.memo(decorator(Original));\n DecoratedComponent.displayName = Original.displayName;\n\n return function ShouldDecorate(props: unknown) {\n if (shouldDecorate(decoratorProps, props)) {\n // @ts-expect-error\n return <DecoratedComponent {...props} />;\n }\n\n // @ts-expect-error\n return <Original {...props} />;\n };\n }) as Decorator<TDecoratee>;\n}\n\nconst memoizedComponent = <T extends GenericComponent>(decorator: Decorator<T>) => {\n return (decoratee: T) => {\n return React.memo(decorator(decoratee));\n };\n};\n\nexport function createDecoratorFactory<TDecorator>() {\n return function from<TDecoratable extends DecoratableComponent>(\n decoratable: TDecoratable,\n shouldDecorate?: ShouldDecorate<TDecorator, GetDecorateeParams<GetDecoratee<TDecoratable>>>\n ) {\n return function createDecorator(\n decorator: Decorator<CanReturnNull<GetDecoratee<TDecoratable>>>\n ) {\n return function DecoratorPlugin(props: TDecorator) {\n if (shouldDecorate) {\n const componentDecorator = createConditionalDecorator<GenericComponent>(\n shouldDecorate,\n decorator as unknown as Decorator<GenericComponent>,\n props\n );\n\n return <Compose function={decoratable} with={componentDecorator} />;\n }\n\n return (\n <Compose\n function={decoratable}\n with={memoizedComponent(\n decorator as unknown as Decorator<GenericComponent>\n )}\n />\n );\n };\n };\n };\n}\n\nexport function createHookDecoratorFactory() {\n return function from<TDecoratable extends DecoratableHook>(decoratable: TDecoratable) {\n return function createDecorator(decorator: Decorator<GetDecoratee<TDecoratable>>) {\n return function DecoratorPlugin() {\n return (\n <Compose\n function={decoratable}\n with={decorator as unknown as Decorator<GenericHook>}\n />\n );\n };\n };\n };\n}\n\nexport function withDecoratorFactory<TDecorator>() {\n return function WithDecorator<TDecoratable extends DecoratableComponent>(\n Component: TDecoratable,\n shouldDecorate?: ShouldDecorate<TDecorator, GetDecorateeParams<GetDecoratee<TDecoratable>>>\n ) {\n const createDecorator = createDecoratorFactory<TDecorator>()(Component, shouldDecorate);\n\n return Object.assign(Component, { createDecorator }) as unknown as DecoratableComponent<\n GenericComponent<GetDecorateeParams<GetDecoratee<TDecoratable>>>\n > & { createDecorator: typeof createDecorator };\n };\n}\n\nexport function withHookDecoratorFactory() {\n return function WithHookDecorator<TDecoratable extends DecoratableHook>(hook: TDecoratable) {\n const createDecorator = createHookDecoratorFactory()(hook);\n\n return Object.assign(hook, { createDecorator }) as unknown as DecoratableHook<\n GenericHook<\n GetDecorateeParams<GetDecoratee<TDecoratable>>,\n ReturnType<GetDecoratee<TDecoratable>>\n >\n > & { createDecorator: typeof createDecorator };\n };\n}\n"],"mappings":";;;;;;;;;;;AAAA,IAAAA,MA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,CAAE,CAAC;QACvE;QAEA,oBACIxB,MAAA,CAAAe,OAAA,CAAAC,aAAA,CAACb,QAAA,CAAAsB,OAAO;UACJC,QAAQ,EAAEL,WAAY;UACtBM,IAAI,EAAEV,iBAAiB,CACnBX,SACJ;QAAE,CACL,CAAC;MAEV,CAAC;IACL,CAAC;EACL,CAAC;AACL;AAEO,SAASsB,0BAA0BA,CAAA,EAAG;EACzC,OAAO,SAASR,IAAIA,CAAuCC,WAAyB,EAAE;IAClF,OAAO,SAASC,eAAeA,CAAChB,SAAgD,EAAE;MAC9E,OAAO,SAASiB,eAAeA,CAAA,EAAG;QAC9B,oBACIvB,MAAA,CAAAe,OAAA,CAAAC,aAAA,CAACb,QAAA,CAAAsB,OAAO;UACJC,QAAQ,EAAEL,WAAY;UACtBM,IAAI,EAAErB;QAA+C,CACxD,CAAC;MAEV,CAAC;IACL,CAAC;EACL,CAAC;AACL;AAEO,SAASuB,oBAAoBA,CAAA,EAAe;EAC/C,OAAO,SAASC,aAAaA,CACzBC,SAAuB,EACvB1B,cAA2F,EAC7F;IACE,IAAMiB,eAAe,GAAGH,sBAAsB,CAAa,CAAC,CAACY,SAAS,EAAE1B,cAAc,CAAC;IAEvF,OAAO2B,MAAM,CAACC,MAAM,CAACF,SAAS,EAAE;MAAET,eAAe,EAAfA;IAAgB,CAAC,CAAC;EAGxD,CAAC;AACL;AAEO,SAASY,wBAAwBA,CAAA,EAAG;EACvC,OAAO,SAASC,iBAAiBA,CAAuCC,IAAkB,EAAE;IACxF,IAAMd,eAAe,GAAGM,0BAA0B,CAAC,CAAC,CAACQ,IAAI,CAAC;IAE1D,OAAOJ,MAAM,CAACC,MAAM,CAACG,IAAI,EAAE;MAAEd,eAAe,EAAfA;IAAgB,CAAC,CAAC;EAMnD,CAAC;AACL","ignoreList":[]}
1
+ {"version":3,"names":["_react","_interopRequireDefault","require","_Compose","createConditionalDecorator","shouldDecorate","decorator","decoratorProps","Original","DecoratedComponent","React","memo","displayName","ShouldDecorate","props","default","createElement","memoizedComponent","decoratee","createDecoratorFactory","from","decoratable","createDecorator","DecoratorPlugin","componentDecorator","Compose","function","with","createHookDecoratorFactory","withDecoratorFactory","WithDecorator","Component","Object","assign","withHookDecoratorFactory","WithHookDecorator","hook"],"sources":["decorators.tsx"],"sourcesContent":["import React from \"react\";\nimport { Compose } from \"~/Compose\";\nimport { GetDecoratee, GetDecorateeParams } from \"~/createDecorator\";\nimport {\n DecoratableComponent,\n GenericComponent,\n Decorator,\n GenericHook,\n DecoratableHook,\n ComponentDecorator\n} from \"~/types\";\n\nexport interface ShouldDecorate<TDecorator = any, TComponent = any> {\n (decoratorProps: TDecorator, componentProps: TComponent): boolean;\n}\n\nexport function createConditionalDecorator<TDecoratee extends GenericComponent>(\n shouldDecorate: ShouldDecorate,\n decorator: Decorator<TDecoratee>,\n decoratorProps: unknown\n): Decorator<TDecoratee> {\n return (Original => {\n const DecoratedComponent = React.memo(decorator(Original));\n DecoratedComponent.displayName = Original.displayName;\n\n return function ShouldDecorate(props: unknown) {\n if (shouldDecorate(decoratorProps, props)) {\n // @ts-expect-error\n return <DecoratedComponent {...props} />;\n }\n\n // @ts-expect-error\n return <Original {...props} />;\n };\n }) as Decorator<TDecoratee>;\n}\n\nconst memoizedComponent = <T extends GenericComponent>(decorator: Decorator<T>) => {\n return (decoratee: T) => {\n return React.memo(decorator(decoratee));\n };\n};\n\nexport function createDecoratorFactory<TDecorator>() {\n return function from<TDecoratable extends DecoratableComponent>(\n decoratable: TDecoratable,\n shouldDecorate?: ShouldDecorate<TDecorator, GetDecorateeParams<GetDecoratee<TDecoratable>>>\n ) {\n return function createDecorator(decorator: ComponentDecorator<GetDecoratee<TDecoratable>>) {\n return function DecoratorPlugin(props: TDecorator) {\n if (shouldDecorate) {\n const componentDecorator = createConditionalDecorator<GenericComponent>(\n shouldDecorate,\n decorator as unknown as Decorator<GenericComponent>,\n props\n );\n\n return <Compose function={decoratable} with={componentDecorator} />;\n }\n\n return (\n <Compose\n function={decoratable}\n with={memoizedComponent(\n decorator as unknown as Decorator<GenericComponent>\n )}\n />\n );\n };\n };\n };\n}\n\nexport function createHookDecoratorFactory() {\n return function from<TDecoratable extends DecoratableHook>(decoratable: TDecoratable) {\n return function createDecorator(decorator: Decorator<GetDecoratee<TDecoratable>>) {\n return function DecoratorPlugin() {\n return (\n <Compose\n function={decoratable}\n with={decorator as unknown as Decorator<GenericHook>}\n />\n );\n };\n };\n };\n}\n\nexport function withDecoratorFactory<TDecorator>() {\n return function WithDecorator<TDecoratable extends DecoratableComponent>(\n Component: TDecoratable,\n shouldDecorate?: ShouldDecorate<TDecorator, GetDecorateeParams<GetDecoratee<TDecoratable>>>\n ) {\n const createDecorator = createDecoratorFactory<TDecorator>()(Component, shouldDecorate);\n\n return Object.assign(Component, { createDecorator }) as TDecoratable & {\n createDecorator: typeof createDecorator;\n };\n };\n}\n\nexport function withHookDecoratorFactory() {\n return function WithHookDecorator<TDecoratable extends DecoratableHook>(hook: TDecoratable) {\n const createDecorator = createHookDecoratorFactory()(hook);\n\n return Object.assign(hook, { createDecorator }) as unknown as DecoratableHook<\n GenericHook<\n GetDecorateeParams<GetDecoratee<TDecoratable>>,\n ReturnType<GetDecoratee<TDecoratable>>\n >\n > & { createDecorator: typeof createDecorator };\n };\n}\n"],"mappings":";;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAeO,SAASE,0BAA0BA,CACtCC,cAA8B,EAC9BC,SAAgC,EAChCC,cAAuB,EACF;EACrB,OAAQ,UAAAC,QAAQ,EAAI;IAChB,IAAMC,kBAAkB,gBAAGC,cAAK,CAACC,IAAI,CAACL,SAAS,CAACE,QAAQ,CAAC,CAAC;IAC1DC,kBAAkB,CAACG,WAAW,GAAGJ,QAAQ,CAACI,WAAW;IAErD,OAAO,SAASC,cAAcA,CAACC,KAAc,EAAE;MAC3C,IAAIT,cAAc,CAACE,cAAc,EAAEO,KAAK,CAAC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,CAAAe,OAAA,CAAAC,aAAA,CAACb,QAAA,CAAAsB,OAAO;UACJC,QAAQ,EAAEL,WAAY;UACtBM,IAAI,EAAErB;QAA+C,CACxD,CAAC;MAEV,CAAC;IACL,CAAC;EACL,CAAC;AACL;AAEO,SAASuB,oBAAoBA,CAAA,EAAe;EAC/C,OAAO,SAASC,aAAaA,CACzBC,SAAuB,EACvB1B,cAA2F,EAC7F;IACE,IAAMiB,eAAe,GAAGH,sBAAsB,CAAa,CAAC,CAACY,SAAS,EAAE1B,cAAc,CAAC;IAEvF,OAAO2B,MAAM,CAACC,MAAM,CAACF,SAAS,EAAE;MAAET,eAAe,EAAfA;IAAgB,CAAC,CAAC;EAGxD,CAAC;AACL;AAEO,SAASY,wBAAwBA,CAAA,EAAG;EACvC,OAAO,SAASC,iBAAiBA,CAAuCC,IAAkB,EAAE;IACxF,IAAMd,eAAe,GAAGM,0BAA0B,CAAC,CAAC,CAACQ,IAAI,CAAC;IAE1D,OAAOJ,MAAM,CAACC,MAAM,CAACG,IAAI,EAAE;MAAEd,eAAe,EAAfA;IAAgB,CAAC,CAAC;EAMnD,CAAC;AACL","ignoreList":[]}
@@ -3,25 +3,42 @@ import { GenericComponent } from "./types";
3
3
  /**
4
4
  * @deprecated Use `makeDecoratable` instead.
5
5
  */
6
- export declare function makeComposable<T extends GenericComponent>(name: string, Component?: T): GenericComponent<import("./createDecorator").GetDecorateeParams<import("./createDecorator").GetDecoratee<import("./types").DecoratableComponent<{
7
- (props: [] | Parameters<NonNullable<T>> extends [infer First] ? undefined extends First ? any : First : any): JSX.Element | null;
8
- original: (() => null) | NonNullable<T>;
6
+ export declare function makeComposable<T extends GenericComponent>(name: string, Component?: T): ((() => null) | T) & {
7
+ original: (() => null) | T;
9
8
  originalName: string;
10
9
  displayName: string;
11
- }>>>> & {
12
- original: GenericComponent<import("./createDecorator").GetDecorateeParams<import("./createDecorator").GetDecoratee<import("./types").DecoratableComponent<{
13
- (props: [] | Parameters<NonNullable<T>> extends [infer First] ? undefined extends First ? any : First : any): JSX.Element | null;
14
- original: (() => null) | NonNullable<T>;
10
+ } & {
11
+ original: ((() => null) | T) & {
12
+ original: (() => null) | T;
15
13
  originalName: string;
16
14
  displayName: string;
17
- }>>>>;
15
+ };
18
16
  originalName: string;
19
17
  displayName: string;
20
18
  } & {
21
- createDecorator: (decorator: import("./types").Decorator<import("./types").CanReturnNull<import("./createDecorator").GetDecoratee<import("./types").DecoratableComponent<{
22
- (props: [] | Parameters<NonNullable<T>> extends [infer First] ? undefined extends First ? any : First : any): JSX.Element | null;
23
- original: (() => null) | NonNullable<T>;
19
+ createDecorator: (decorator: import("./types").ComponentDecorator<import("./createDecorator").GetDecoratee<(() => null) & {
20
+ original: (() => null) | T;
21
+ originalName: string;
22
+ displayName: string;
23
+ } & {
24
+ original: ((() => null) | T) & {
25
+ original: (() => null) | T;
26
+ originalName: string;
27
+ displayName: string;
28
+ };
29
+ originalName: string;
30
+ displayName: string;
31
+ }> | import("./createDecorator").GetDecoratee<T & {
32
+ original: (() => null) | T;
33
+ originalName: string;
34
+ displayName: string;
35
+ } & {
36
+ original: ((() => null) | T) & {
37
+ original: (() => null) | T;
38
+ originalName: string;
39
+ displayName: string;
40
+ };
24
41
  originalName: string;
25
42
  displayName: string;
26
- }>>>>) => (props: unknown) => import("react").JSX.Element;
43
+ }>>) => (props: unknown) => import("react").JSX.Element;
27
44
  };
@@ -1,28 +1,23 @@
1
1
  import React from "react";
2
2
  import { DecoratableComponent, DecoratableHook, GenericComponent, GenericHook } from "./types";
3
- declare type NoProps = any;
4
- declare type GetProps<T extends (...args: any) => any> = Parameters<T> extends [infer First] ? undefined extends First ? NoProps : First : NoProps;
5
- declare function makeDecoratableComponent<T extends GenericComponent>(name: string, Component?: T): GenericComponent<import("./createDecorator").GetDecorateeParams<import("./createDecorator").GetDecoratee<DecoratableComponent<{
6
- (props: GetProps<T>): JSX.Element | null;
3
+ declare function makeDecoratableComponent<T extends GenericComponent>(name: string, Component?: T): T & {
7
4
  original: T;
8
5
  originalName: string;
9
6
  displayName: string;
10
- }>>>> & {
11
- original: GenericComponent<import("./createDecorator").GetDecorateeParams<import("./createDecorator").GetDecoratee<DecoratableComponent<{
12
- (props: GetProps<T>): JSX.Element | null;
7
+ } & {
8
+ original: T & {
13
9
  original: T;
14
10
  originalName: string;
15
11
  displayName: string;
16
- }>>>>;
12
+ };
17
13
  originalName: string;
18
14
  displayName: string;
19
15
  } & {
20
- createDecorator: (decorator: import("./types").Decorator<import("./types").CanReturnNull<import("./createDecorator").GetDecoratee<DecoratableComponent<{
21
- (props: GetProps<T>): JSX.Element | null;
16
+ createDecorator: (decorator: import("./types").ComponentDecorator<import("./createDecorator").GetDecoratee<DecoratableComponent<T & {
22
17
  original: T;
23
18
  originalName: string;
24
19
  displayName: string;
25
- }>>>>) => (props: unknown) => React.JSX.Element;
20
+ }>>>) => (props: unknown) => React.JSX.Element;
26
21
  };
27
22
  export declare function makeDecoratableHook<T extends GenericHook>(hook: T): GenericHook<import("./createDecorator").GetDecorateeParams<import("./createDecorator").GetDecoratee<DecoratableHook<T>>>, ReturnType<import("./createDecorator").GetDecoratee<DecoratableHook<T>>>> & {
28
23
  original: GenericHook<import("./createDecorator").GetDecorateeParams<import("./createDecorator").GetDecoratee<DecoratableHook<T>>>, ReturnType<import("./createDecorator").GetDecoratee<DecoratableHook<T>>>>;
@@ -24,9 +24,6 @@ function useComposableParents() {
24
24
  var nullRenderer = function nullRenderer() {
25
25
  return null;
26
26
  };
27
-
28
- // Maybe there's a better way to mark props as non-existent, but for now I left it as `any`.
29
-
30
27
  function makeDecoratableComponent(name) {
31
28
  var Component = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : nullRenderer;
32
29
  var Decoratable = function Decoratable(props) {
@@ -39,10 +36,12 @@ function makeDecoratableComponent(name) {
39
36
  value: context
40
37
  }, /*#__PURE__*/_react.default.createElement(ComposedComponent, props, props.children));
41
38
  };
42
- Decoratable.original = Component;
43
- Decoratable.originalName = name;
44
- Decoratable.displayName = "Decoratable<".concat(name, ">");
45
- return (0, _decorators.withDecoratorFactory)()(Decoratable);
39
+ var staticProps = {
40
+ original: Component,
41
+ originalName: name,
42
+ displayName: "Decoratable<".concat(name, ">")
43
+ };
44
+ return (0, _decorators.withDecoratorFactory)()(Object.assign(Decoratable, staticProps));
46
45
  }
47
46
  function makeDecoratableHook(hook) {
48
47
  var decoratableHook = function decoratableHook(params) {
@@ -1 +1 @@
1
- {"version":3,"names":["_react","_interopRequireWildcard","require","_Context","_decorators","ComposableContext","createContext","displayName","useComposableParents","context","useContext","nullRenderer","makeDecoratableComponent","name","Component","arguments","length","undefined","Decoratable","props","parents","ComposedComponent","useComponent","useMemo","concat","_toConsumableArray2","default","createElement","Provider","value","children","original","originalName","withDecoratorFactory","makeDecoratableHook","hook","decoratableHook","params","composedHook","withHookDecoratorFactory","createVoidComponent","makeDecoratable","hookOrName","React","memo"],"sources":["makeDecoratable.tsx"],"sourcesContent":["import React, { createContext, useContext, useMemo } from \"react\";\nimport { useComponent } from \"./Context\";\nimport { DecoratableComponent, DecoratableHook, GenericComponent, GenericHook } from \"~/types\";\nimport { withDecoratorFactory, withHookDecoratorFactory } from \"~/decorators\";\n\nconst ComposableContext = createContext<string[]>([]);\nComposableContext.displayName = \"ComposableContext\";\n\nfunction useComposableParents() {\n const context = useContext(ComposableContext);\n if (!context) {\n return [];\n }\n\n return context;\n}\n\nconst nullRenderer = () => null;\n\n// Maybe there's a better way to mark props as non-existent, but for now I left it as `any`.\ntype NoProps = any;\n\ntype GetProps<T extends (...args: any) => any> = Parameters<T> extends [infer First]\n ? undefined extends First\n ? NoProps\n : First\n : NoProps;\n\nfunction makeDecoratableComponent<T extends GenericComponent>(\n name: string,\n Component: T = nullRenderer as unknown as T\n) {\n const Decoratable = (props: GetProps<T>): JSX.Element | null => {\n const parents = useComposableParents();\n const ComposedComponent = useComponent(Component);\n\n const context = useMemo(() => [...parents, name], [parents, name]);\n\n return (\n <ComposableContext.Provider value={context}>\n <ComposedComponent {...props}>{props.children}</ComposedComponent>\n </ComposableContext.Provider>\n );\n };\n\n Decoratable.original = Component;\n Decoratable.originalName = name;\n Decoratable.displayName = `Decoratable<${name}>`;\n\n return withDecoratorFactory()(Decoratable as DecoratableComponent<typeof Decoratable>);\n}\n\nexport function makeDecoratableHook<T extends GenericHook>(hook: T) {\n const decoratableHook = (params: Parameters<T>) => {\n const composedHook = useComponent(hook);\n\n return composedHook(params) as DecoratableHook<T>;\n };\n\n decoratableHook.original = hook;\n\n return withHookDecoratorFactory()(decoratableHook as DecoratableHook<T>);\n}\n\nexport function createVoidComponent<T>() {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n return (props: T): JSX.Element | null => {\n return null;\n };\n}\n\nexport function makeDecoratable<T extends GenericHook>(\n hook: T\n): ReturnType<typeof makeDecoratableHook<T>>;\nexport function makeDecoratable<T extends GenericComponent>(\n name: string,\n Component: T\n): ReturnType<typeof makeDecoratableComponent<T>>;\nexport function makeDecoratable(hookOrName: any, Component?: any) {\n if (Component) {\n return makeDecoratableComponent(hookOrName, React.memo(Component));\n }\n\n return makeDecoratableHook(hookOrName);\n}\n"],"mappings":";;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAEA,IAAAE,WAAA,GAAAF,OAAA;AAEA,IAAMG,iBAAiB,gBAAG,IAAAC,oBAAa,EAAW,EAAE,CAAC;AACrDD,iBAAiB,CAACE,WAAW,GAAG,mBAAmB;AAEnD,SAASC,oBAAoBA,CAAA,EAAG;EAC5B,IAAMC,OAAO,GAAG,IAAAC,iBAAU,EAACL,iBAAiB,CAAC;EAC7C,IAAI,CAACI,OAAO,EAAE;IACV,OAAO,EAAE;EACb;EAEA,OAAOA,OAAO;AAClB;AAEA,IAAME,YAAY,GAAG,SAAfA,YAAYA,CAAA;EAAA,OAAS,IAAI;AAAA;;AAE/B;;AASA,SAASC,wBAAwBA,CAC7BC,IAAY,E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CAAA,EAAM;EACrC;EACA,OAAO,UAACrB,KAAQ,EAAyB;IACrC,OAAO,IAAI;EACf,CAAC;AACL;AASO,SAASsB,eAAeA,CAACC,UAAe,EAAE5B,SAAe,EAAE;EAC9D,IAAIA,SAAS,EAAE;IACX,OAAOF,wBAAwB,CAAC8B,UAAU,eAAEC,cAAK,CAACC,IAAI,CAAC9B,SAAS,CAAC,CAAC;EACtE;EAEA,OAAOoB,mBAAmB,CAACQ,UAAU,CAAC;AAC1C","ignoreList":[]}
1
+ {"version":3,"names":["_react","_interopRequireWildcard","require","_Context","_decorators","ComposableContext","createContext","displayName","useComposableParents","context","useContext","nullRenderer","makeDecoratableComponent","name","Component","arguments","length","undefined","Decoratable","props","parents","ComposedComponent","useComponent","useMemo","concat","_toConsumableArray2","default","createElement","Provider","value","children","staticProps","original","originalName","withDecoratorFactory","Object","assign","makeDecoratableHook","hook","decoratableHook","params","composedHook","withHookDecoratorFactory","createVoidComponent","makeDecoratable","hookOrName","React","memo"],"sources":["makeDecoratable.tsx"],"sourcesContent":["import React, { createContext, useContext, useMemo } from \"react\";\nimport { useComponent } from \"./Context\";\nimport { DecoratableComponent, DecoratableHook, GenericComponent, GenericHook } from \"~/types\";\nimport { withDecoratorFactory, withHookDecoratorFactory } from \"~/decorators\";\n\nconst ComposableContext = createContext<string[]>([]);\nComposableContext.displayName = \"ComposableContext\";\n\nfunction useComposableParents() {\n const context = useContext(ComposableContext);\n if (!context) {\n return [];\n }\n\n return context;\n}\n\nconst nullRenderer = () => null;\n\nfunction makeDecoratableComponent<T extends GenericComponent>(\n name: string,\n Component: T = nullRenderer as unknown as T\n) {\n const Decoratable = (props: React.ComponentProps<T>): JSX.Element | null => {\n const parents = useComposableParents();\n const ComposedComponent = useComponent(Component) as GenericComponent<\n React.ComponentProps<T>\n >;\n\n const context = useMemo(() => [...parents, name], [parents, name]);\n\n return (\n <ComposableContext.Provider value={context}>\n <ComposedComponent {...props}>{props.children}</ComposedComponent>\n </ComposableContext.Provider>\n );\n };\n\n const staticProps = {\n original: Component,\n originalName: name,\n displayName: `Decoratable<${name}>`\n };\n\n return withDecoratorFactory()(\n Object.assign(Decoratable, staticProps) as DecoratableComponent<\n typeof Component & typeof staticProps\n >\n );\n}\n\nexport function makeDecoratableHook<T extends GenericHook>(hook: T) {\n const decoratableHook = (params: Parameters<T>) => {\n const composedHook = useComponent(hook);\n\n return composedHook(params) as DecoratableHook<T>;\n };\n\n decoratableHook.original = hook;\n\n return withHookDecoratorFactory()(decoratableHook as DecoratableHook<T>);\n}\n\nexport function createVoidComponent<T>() {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n return (props: T): JSX.Element | null => {\n return null;\n };\n}\n\nexport function makeDecoratable<T extends GenericHook>(\n hook: T\n): ReturnType<typeof makeDecoratableHook<T>>;\nexport function makeDecoratable<T extends GenericComponent>(\n name: string,\n Component: T\n): ReturnType<typeof makeDecoratableComponent<T>>;\nexport function makeDecoratable(hookOrName: any, Component?: any) {\n if (Component) {\n return makeDecoratableComponent(hookOrName, React.memo(Component));\n }\n\n return makeDecoratableHook(hookOrName);\n}\n"],"mappings":";;;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAEA,IAAAE,WAAA,GAAAF,OAAA;AAEA,IAAMG,iBAAiB,gBAAG,IAAAC,oBAAa,EAAW,EAAE,CAAC;AACrDD,iBAAiB,CAACE,WAAW,GAAG,mBAAmB;AAEnD,SAASC,oBAAoBA,CAAA,EAAG;EAC5B,IAAMC,OAAO,GAAG,IAAAC,iBAAU,EAACL,iBAAiB,CAAC;EAC7C,IAAI,CAACI,OAAO,EAAE;IACV,OAAO,EAAE;EACb;EAEA,OAAOA,OAAO;AAClB;AAEA,IAAME,YAAY,GAAG,SAAfA,YAAYA,CAAA;EAAA,OAAS,IAAI;AAAA;AAE/B,SAASC,wBAAwBA,CAC7BC,IAAY,EAEd;EAAA,IADEC,SAAY,GAAAC,SA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AA,EAAM;EACrC;EACA,OAAO,UAACxB,KAAQ,EAAyB;IACrC,OAAO,IAAI;EACf,CAAC;AACL;AASO,SAASyB,eAAeA,CAACC,UAAe,EAAE/B,SAAe,EAAE;EAC9D,IAAIA,SAAS,EAAE;IACX,OAAOF,wBAAwB,CAACiC,UAAU,eAAEC,cAAK,CAACC,IAAI,CAACjC,SAAS,CAAC,CAAC;EACtE;EAEA,OAAOuB,mBAAmB,CAACQ,UAAU,CAAC;AAC1C","ignoreList":[]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@webiny/react-composition",
3
- "version": "5.40.5",
3
+ "version": "5.41.0-dbt.0",
4
4
  "main": "index.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -25,10 +25,10 @@
25
25
  "@babel/preset-env": "7.24.3",
26
26
  "@babel/preset-typescript": "7.24.1",
27
27
  "@testing-library/react": "15.0.7",
28
- "@webiny/cli": "5.40.5",
29
- "@webiny/project-utils": "5.40.5",
28
+ "@webiny/cli": "5.41.0-dbt.0",
29
+ "@webiny/project-utils": "5.41.0-dbt.0",
30
30
  "ttypescript": "1.5.15",
31
- "typescript": "4.7.4"
31
+ "typescript": "4.9.5"
32
32
  },
33
33
  "publishConfig": {
34
34
  "access": "public",
@@ -38,5 +38,5 @@
38
38
  "build": "yarn webiny run build",
39
39
  "watch": "yarn webiny run watch"
40
40
  },
41
- "gitHead": "f67778732392ed88f28da869ddacbf08a98cdec6"
41
+ "gitHead": "bbaec4dd1685579548c08bbde386aee5d96b80f8"
42
42
  }
package/types.d.ts CHANGED
@@ -1,29 +1,35 @@
1
1
  import React from "react";
2
- export declare type GenericHook<TParams = any, TReturn = any> = (...args: TParams[]) => TReturn;
3
- export declare type GenericComponent<T = any> = React.FunctionComponent<T>;
4
- export declare type ComposedFunction = GenericHook;
5
- export declare type Decorator<T> = (decoratee: T) => T;
2
+ export type GenericHook<TParams = any, TReturn = any> = (...args: TParams[]) => TReturn;
3
+ export type GenericComponent<T = any> = React.FunctionComponent<T>;
4
+ export type ComposedFunction = GenericHook;
5
+ export type Decorator<T> = (decoratee: T) => T;
6
+ /**
7
+ * Some decoratable components will always return `null`, by design.
8
+ * To allow you to decorate these components, we must tell TS that the decorator is allowed to return not just `null`
9
+ * (which is inferred from the component type), but also a JSX.Element.
10
+ */
11
+ export type ComponentDecorator<T> = (decoratee: T) => CanReturnNullOrElement<T>;
6
12
  /**
7
13
  * @deprecated
8
14
  */
9
- export declare type ComposableFC<T> = T & {
15
+ export type ComposableFC<T> = T & {
10
16
  displayName?: string;
11
17
  original: T;
12
18
  originalName: string;
13
19
  };
14
- export declare type Enumerable<T> = T extends Array<infer D> ? Array<D> : never;
15
- export declare type ComposeWith = Decorator<GenericComponent> | Decorator<GenericComponent>[] | Decorator<GenericHook> | Decorator<GenericHook>[];
16
- export declare type DecoratableHook<T extends GenericHook = GenericHook> = T & {
20
+ export type Enumerable<T> = T extends Array<infer D> ? Array<D> : never;
21
+ export type ComposeWith = Decorator<GenericComponent> | Decorator<GenericComponent>[] | Decorator<GenericHook> | Decorator<GenericHook>[];
22
+ export type DecoratableHook<T extends GenericHook = GenericHook> = T & {
17
23
  original: T;
18
24
  originalName: string;
19
25
  };
20
- export declare type DecoratableComponent<T = GenericComponent> = T & {
26
+ export type DecoratableComponent<T = GenericComponent> = T & {
21
27
  original: T;
22
28
  originalName: string;
23
29
  displayName: string;
24
30
  };
25
- export declare type Decoratable = DecoratableComponent | DecoratableHook;
31
+ export type Decoratable = DecoratableComponent | DecoratableHook;
26
32
  /**
27
33
  * @internal Add `null` to the ReturnType of the given function.
28
34
  */
29
- export declare type CanReturnNull<T> = T extends (...args: any) => any ? (...args: Parameters<T>) => ReturnType<T> | null : never;
35
+ export type CanReturnNullOrElement<T> = T extends (...args: any) => any ? (...args: Parameters<T>) => JSX.Element | null : never;
package/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import React from \"react\";\n\nexport type GenericHook<TParams = any, TReturn = any> = (...args: TParams[]) => TReturn;\n\nexport type GenericComponent<T = any> = React.FunctionComponent<T>;\n\nexport type ComposedFunction = GenericHook;\n\nexport type Decorator<T> = (decoratee: T) => T;\n\n/**\n * @deprecated\n */\nexport type ComposableFC<T> = T & {\n displayName?: string;\n original: T;\n originalName: string;\n};\n\nexport type Enumerable<T> = T extends Array<infer D> ? Array<D> : never;\n\nexport type ComposeWith =\n | Decorator<GenericComponent>\n | Decorator<GenericComponent>[]\n | Decorator<GenericHook>\n | Decorator<GenericHook>[];\n\nexport type DecoratableHook<T extends GenericHook = GenericHook> = T & {\n original: T;\n originalName: string;\n};\n\nexport type DecoratableComponent<T = GenericComponent> = T & {\n original: T;\n originalName: string;\n displayName: string;\n};\n\nexport type Decoratable = DecoratableComponent | DecoratableHook;\n\n/**\n * @internal Add `null` to the ReturnType of the given function.\n */\nexport type CanReturnNull<T> = T extends (...args: any) => any\n ? (...args: Parameters<T>) => ReturnType<T> | null\n : never;\n"],"mappings":"","ignoreList":[]}
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import React from \"react\";\n\nexport type GenericHook<TParams = any, TReturn = any> = (...args: TParams[]) => TReturn;\n\nexport type GenericComponent<T = any> = React.FunctionComponent<T>;\n\nexport type ComposedFunction = GenericHook;\n\nexport type Decorator<T> = (decoratee: T) => T;\n\n/**\n * Some decoratable components will always return `null`, by design.\n * To allow you to decorate these components, we must tell TS that the decorator is allowed to return not just `null`\n * (which is inferred from the component type), but also a JSX.Element.\n */\nexport type ComponentDecorator<T> = (decoratee: T) => CanReturnNullOrElement<T>;\n\n/**\n * @deprecated\n */\nexport type ComposableFC<T> = T & {\n displayName?: string;\n original: T;\n originalName: string;\n};\n\nexport type Enumerable<T> = T extends Array<infer D> ? Array<D> : never;\n\nexport type ComposeWith =\n | Decorator<GenericComponent>\n | Decorator<GenericComponent>[]\n | Decorator<GenericHook>\n | Decorator<GenericHook>[];\n\nexport type DecoratableHook<T extends GenericHook = GenericHook> = T & {\n original: T;\n originalName: string;\n};\n\nexport type DecoratableComponent<T = GenericComponent> = T & {\n original: T;\n originalName: string;\n displayName: string;\n};\n\nexport type Decoratable = DecoratableComponent | DecoratableHook;\n\n/**\n * @internal Add `null` to the ReturnType of the given function.\n */\nexport type CanReturnNullOrElement<T> = T extends (...args: any) => any\n ? (...args: Parameters<T>) => JSX.Element | null\n : never;\n"],"mappings":"","ignoreList":[]}