@webiny/react-composition 5.39.1-beta.0 → 5.39.1-beta.1

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/Compose.d.ts CHANGED
@@ -1,15 +1,8 @@
1
- import React from "react";
2
- import { HigherOrderComponent } from "./Context";
3
- export declare type ComposableFC<TProps = unknown> = React.ComponentType<TProps> & {
4
- original: React.ComponentType<TProps>;
5
- originalName: string;
6
- };
1
+ import { DecoratableTypes } from "./Context";
2
+ import { ComposeWith } from "./types";
7
3
  export interface ComposeProps {
8
- /**
9
- * Component to compose.
10
- * NOTE: ComposableFC<TProps> use `any` because the type of the component props is irrelevant.
11
- */
12
- component: ComposableFC<any>;
13
- with: HigherOrderComponent | HigherOrderComponent[];
4
+ function?: DecoratableTypes;
5
+ component?: DecoratableTypes;
6
+ with: ComposeWith;
14
7
  }
15
8
  export declare const Compose: (props: ComposeProps) => null;
package/Compose.js CHANGED
@@ -11,13 +11,14 @@ var Compose = function Compose(props) {
11
11
  var _useComposition = (0, _Context.useComposition)(),
12
12
  composeComponent = _useComposition.composeComponent;
13
13
  var scope = (0, _CompositionScope.useCompositionScope)();
14
+ var targetFn = props.function ?? props.component;
14
15
  (0, _react.useEffect)(function () {
15
- if (typeof props.component.original === "undefined") {
16
- console.warn("You must make your component \"<".concat(props.component.displayName, ">\" composable, by using the makeComposable() function!"));
16
+ if (typeof targetFn.original === "undefined") {
17
+ console.warn("You must make your function \"".concat(targetFn.originalName ?? targetFn.name, "\" composable, by using the makeDecoratable() function!"));
17
18
  return;
18
19
  }
19
- var hocs = Array.isArray(props.with) ? props.with : [props.with];
20
- return composeComponent(props.component.original, hocs, scope);
20
+ var decorators = Array.isArray(props.with) ? props.with : [props.with];
21
+ return composeComponent(targetFn.original, decorators, scope);
21
22
  }, [props.with]);
22
23
  return null;
23
24
  };
package/Compose.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["_react","require","_Context","_CompositionScope","Compose","props","_useComposition","useComposition","composeComponent","scope","useCompositionScope","useEffect","component","original","console","warn","concat","displayName","hocs","Array","isArray","with","exports"],"sources":["Compose.tsx"],"sourcesContent":["import React, { useEffect } from \"react\";\nimport { HigherOrderComponent, useComposition } from \"./Context\";\nimport { useCompositionScope } from \"~/CompositionScope\";\n\nexport type ComposableFC<TProps = unknown> = React.ComponentType<TProps> & {\n original: React.ComponentType<TProps>;\n originalName: string;\n};\n\nexport interface ComposeProps {\n /**\n * Component to compose.\n * NOTE: ComposableFC<TProps> use `any` because the type of the component props is irrelevant.\n */\n component: ComposableFC<any>;\n with: HigherOrderComponent | HigherOrderComponent[];\n}\n\nexport const Compose = (props: ComposeProps) => {\n const { composeComponent } = useComposition();\n const scope = useCompositionScope();\n\n useEffect(() => {\n if (typeof props.component.original === \"undefined\") {\n console.warn(\n `You must make your component \"<${props.component.displayName}>\" composable, by using the makeComposable() function!`\n );\n\n return;\n }\n\n const hocs = Array.isArray(props.with) ? props.with : [props.with];\n return composeComponent(props.component.original, hocs, scope);\n }, [props.with]);\n\n return null;\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,iBAAA,GAAAF,OAAA;AAgBO,IAAMG,OAAO,GAAG,SAAVA,OAAOA,CAAIC,KAAmB,EAAK;EAC5C,IAAAC,eAAA,GAA6B,IAAAC,uBAAc,EAAC,CAAC;IAArCC,gBAAgB,GAAAF,eAAA,CAAhBE,gBAAgB;EACxB,IAAMC,KAAK,GAAG,IAAAC,qCAAmB,EAAC,CAAC;EAEnC,IAAAC,gBAAS,EAAC,YAAM;IACZ,IAAI,OAAON,KAAK,CAACO,SAAS,CAACC,QAAQ,KAAK,WAAW,EAAE;MACjDC,OAAO,CAACC,IAAI,oCAAAC,MAAA,CAC0BX,KAAK,CAACO,SAAS,CAACK,WAAW,4DACjE,CAAC;MAED;IACJ;IAEA,IAAMC,IAAI,GAAGC,KAAK,CAACC,OAAO,CAACf,KAAK,CAACgB,IAAI,CAAC,GAAGhB,KAAK,CAACgB,IAAI,GAAG,CAAChB,KAAK,CAACgB,IAAI,CAAC;IAClE,OAAOb,gBAAgB,CAACH,KAAK,CAACO,SAAS,CAACC,QAAQ,EAAEK,IAAI,EAAET,KAAK,CAAC;EAClE,CAAC,EAAE,CAACJ,KAAK,CAACgB,IAAI,CAAC,CAAC;EAEhB,OAAO,IAAI;AACf,CAAC;AAACC,OAAA,CAAAlB,OAAA,GAAAA,OAAA"}
1
+ {"version":3,"names":["_react","require","_Context","_CompositionScope","Compose","props","_useComposition","useComposition","composeComponent","scope","useCompositionScope","targetFn","function","component","useEffect","original","console","warn","concat","originalName","name","decorators","Array","isArray","with","exports"],"sources":["Compose.tsx"],"sourcesContent":["import { useEffect } from \"react\";\nimport { DecoratableTypes, useComposition } from \"./Context\";\nimport { useCompositionScope } from \"~/CompositionScope\";\nimport { ComposeWith, Decoratable, Enumerable } from \"./types\";\n\nexport interface ComposeProps {\n function?: DecoratableTypes;\n component?: DecoratableTypes;\n with: ComposeWith;\n}\n\nexport const Compose = (props: ComposeProps) => {\n const { composeComponent } = useComposition();\n const scope = useCompositionScope();\n\n const targetFn = (props.function ?? props.component) as Decoratable;\n\n useEffect(() => {\n if (typeof targetFn.original === \"undefined\") {\n console.warn(\n `You must make your function \"${\n targetFn.originalName ?? targetFn.name\n }\" composable, by using the makeDecoratable() function!`\n );\n\n return;\n }\n\n const decorators = Array.isArray(props.with) ? props.with : [props.with];\n return composeComponent(targetFn.original, decorators as Enumerable<ComposeWith>, scope);\n }, [props.with]);\n\n return null;\n};\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AACA,IAAAE,iBAAA,GAAAF,OAAA;AASO,IAAMG,OAAO,GAAG,SAAVA,OAAOA,CAAIC,KAAmB,EAAK;EAC5C,IAAAC,eAAA,GAA6B,IAAAC,uBAAc,EAAC,CAAC;IAArCC,gBAAgB,GAAAF,eAAA,CAAhBE,gBAAgB;EACxB,IAAMC,KAAK,GAAG,IAAAC,qCAAmB,EAAC,CAAC;EAEnC,IAAMC,QAAQ,GAAIN,KAAK,CAACO,QAAQ,IAAIP,KAAK,CAACQ,SAAyB;EAEnE,IAAAC,gBAAS,EAAC,YAAM;IACZ,IAAI,OAAOH,QAAQ,CAACI,QAAQ,KAAK,WAAW,EAAE;MAC1CC,OAAO,CAACC,IAAI,kCAAAC,MAAA,CAEJP,QAAQ,CAACQ,YAAY,IAAIR,QAAQ,CAACS,IAAI,4DAE9C,CAAC;MAED;IACJ;IAEA,IAAMC,UAAU,GAAGC,KAAK,CAACC,OAAO,CAAClB,KAAK,CAACmB,IAAI,CAAC,GAAGnB,KAAK,CAACmB,IAAI,GAAG,CAACnB,KAAK,CAACmB,IAAI,CAAC;IACxE,OAAOhB,gBAAgB,CAACG,QAAQ,CAACI,QAAQ,EAAEM,UAAU,EAA6BZ,KAAK,CAAC;EAC5F,CAAC,EAAE,CAACJ,KAAK,CAACmB,IAAI,CAAC,CAAC;EAEhB,OAAO,IAAI;AACf,CAAC;AAACC,OAAA,CAAArB,OAAA,GAAAA,OAAA"}
package/Context.d.ts CHANGED
@@ -1,46 +1,40 @@
1
1
  import React, { ComponentType } from "react";
2
- export declare function compose(...fns: Decorator[]): (Base: ComponentType<unknown>) => ComponentType<unknown>;
2
+ import { ComposedFunction, ComposeWith, DecoratableComponent, DecoratableHook, Enumerable, GenericComponent, Decorator, GenericHook } from "./types";
3
+ export declare function compose<T>(...fns: Decorator<T>[]): (decoratee: T) => T;
3
4
  interface ComposedComponent {
4
5
  /**
5
6
  * Ready to use React component.
6
7
  */
7
- component: ComponentType<unknown>;
8
+ component: GenericHook | GenericComponent;
8
9
  /**
9
10
  * HOCs used to compose the original component.
10
11
  */
11
- hocs: Decorator[];
12
+ hocs: Decorator<GenericComponent | GenericHook>[];
12
13
  /**
13
14
  * Component composition can be scoped.
14
15
  */
15
16
  scope?: string;
16
17
  }
17
- /**
18
- * IMPORTANT: TProps default type is `any` because this interface is use as a prop type in the `Compose` component.
19
- * You can pass any Decorator as a prop, regardless of its TProps type. The only way to allow that is
20
- * to let it be `any` in this interface.
21
- */
22
- export interface Decorator<TProps = any> {
23
- (Component: ComponentType<TProps>): ComponentType<TProps>;
24
- }
25
18
  /**
26
19
  * @deprecated Use `Decorator` instead.
27
20
  */
28
21
  export interface HigherOrderComponent<TProps = any, TOutput = TProps> {
29
- (Component: ComponentType<TProps>): ComponentType<TOutput>;
22
+ (Component: GenericComponent<TProps>): GenericComponent<TOutput>;
30
23
  }
31
24
  declare type ComposedComponents = Map<ComponentType<unknown>, ComposedComponent>;
32
25
  declare type ComponentScopes = Map<string, ComposedComponents>;
26
+ export declare type DecoratableTypes = DecoratableComponent | DecoratableHook;
33
27
  interface CompositionContext {
34
28
  components: ComponentScopes;
35
- getComponent(component: ComponentType<unknown>, scope?: string): ComponentType<unknown> | undefined;
36
- composeComponent(component: ComponentType<unknown>, hocs: HigherOrderComponent[], scope?: string): void;
29
+ getComponent(component: ComponentType<unknown>, scope?: string): ComposedFunction | undefined;
30
+ composeComponent(component: ComponentType<unknown>, hocs: Enumerable<ComposeWith>, scope?: string): void;
37
31
  }
38
32
  declare const CompositionContext: React.Context<CompositionContext | undefined>;
39
33
  interface CompositionProviderProps {
40
34
  children: React.ReactNode;
41
35
  }
42
36
  export declare const CompositionProvider: ({ children }: CompositionProviderProps) => JSX.Element;
43
- export declare function useComponent(Component: ComponentType<any>): React.ComponentType<any>;
37
+ export declare function useComponent<T>(baseFunction: T): T;
44
38
  /**
45
39
  * This hook will throw an error if composition context doesn't exist.
46
40
  */
package/Context.js CHANGED
@@ -18,19 +18,13 @@ function compose() {
18
18
  for (var _len = arguments.length, fns = new Array(_len), _key = 0; _key < _len; _key++) {
19
19
  fns[_key] = arguments[_key];
20
20
  }
21
- return function ComposedComponent(Base) {
22
- return fns.reduceRight(function (Component, hoc) {
23
- return hoc(Component);
24
- }, Base);
21
+ return function (decoratee) {
22
+ return fns.reduceRight(function (decoratee, decorator) {
23
+ return decorator(decoratee);
24
+ }, decoratee);
25
25
  };
26
26
  }
27
27
 
28
- /**
29
- * IMPORTANT: TProps default type is `any` because this interface is use as a prop type in the `Compose` component.
30
- * You can pass any Decorator as a prop, regardless of its TProps type. The only way to allow that is
31
- * to let it be `any` in this interface.
32
- */
33
-
34
28
  /**
35
29
  * @deprecated Use `Decorator` instead.
36
30
  */
@@ -106,13 +100,13 @@ var CompositionProvider = function CompositionProvider(_ref) {
106
100
  }, children);
107
101
  };
108
102
  exports.CompositionProvider = CompositionProvider;
109
- function useComponent(Component) {
103
+ function useComponent(baseFunction) {
110
104
  var context = useOptionalComposition();
111
105
  var scope = (0, _CompositionScope.useCompositionScope)();
112
106
  if (!context) {
113
- return Component;
107
+ return baseFunction;
114
108
  }
115
- return context.getComponent(Component, scope) || Component;
109
+ return context.getComponent(baseFunction, scope) || baseFunction;
116
110
  }
117
111
 
118
112
  /**
package/Context.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["_react","_interopRequireWildcard","require","_CompositionScope","compose","_len","arguments","length","fns","Array","_key","ComposedComponent","Base","reduceRight","Component","hoc","CompositionContext","createContext","undefined","CompositionProvider","_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","includes","NewComponent","getComponent","composedComponent","defaultScopeMap","defaultComponent","context","useMemo","createElement","Provider","value","exports","useComponent","useOptionalComposition","useCompositionScope","useComposition","useContext","Error"],"sources":["Context.tsx"],"sourcesContent":["import React, {\n ComponentType,\n useState,\n useCallback,\n createContext,\n useContext,\n useMemo\n} from \"react\";\nimport { useCompositionScope } from \"~/CompositionScope\";\n\nexport function compose(...fns: Decorator[]) {\n return function ComposedComponent(Base: ComponentType<unknown>): ComponentType<unknown> {\n return fns.reduceRight((Component, hoc) => hoc(Component), Base);\n };\n}\n\ninterface ComposedComponent {\n /**\n * Ready to use React component.\n */\n component: ComponentType<unknown>;\n /**\n * HOCs used to compose the original component.\n */\n hocs: Decorator[];\n /**\n * Component composition can be scoped.\n */\n scope?: string;\n}\n\n/**\n * IMPORTANT: TProps default type is `any` because this interface is use as a prop type in the `Compose` component.\n * You can pass any Decorator as a prop, regardless of its TProps type. The only way to allow that is\n * to let it be `any` in this interface.\n */\nexport interface Decorator<TProps = any> {\n (Component: ComponentType<TProps>): ComponentType<TProps>;\n}\n\n/**\n * @deprecated Use `Decorator` instead.\n */\nexport interface HigherOrderComponent<TProps = any, TOutput = TProps> {\n (Component: ComponentType<TProps>): ComponentType<TOutput>;\n}\n\ntype ComposedComponents = Map<ComponentType<unknown>, ComposedComponent>;\ntype ComponentScopes = Map<string, ComposedComponents>;\n\ninterface CompositionContext {\n components: ComponentScopes;\n getComponent(\n component: ComponentType<unknown>,\n scope?: string\n ): ComponentType<unknown> | undefined;\n composeComponent(\n component: ComponentType<unknown>,\n hocs: HigherOrderComponent[],\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 (component, hocs, scope = \"*\") => {\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];\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: CompositionContext[\"getComponent\"] = useCallback(\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(Component: ComponentType<any>) {\n const context = useOptionalComposition();\n const scope = useCompositionScope();\n\n if (!context) {\n return Component;\n }\n\n return context.getComponent(Component, scope) || Component;\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;AAEO,SAASE,OAAOA,CAAA,EAAsB;EAAA,SAAAC,IAAA,GAAAC,SAAA,CAAAC,MAAA,EAAlBC,GAAG,OAAAC,KAAA,CAAAJ,IAAA,GAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;I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G,CAAC;AAACqC,OAAA,CAAAvC,mBAAA,GAAAA,mBAAA;AAEK,SAASwC,YAAYA,CAAC7C,SAA6B,EAAE;EACxD,IAAMuC,OAAO,GAAGO,sBAAsB,CAAC,CAAC;EACxC,IAAM1B,KAAK,GAAG,IAAA2B,qCAAmB,EAAC,CAAC;EAEnC,IAAI,CAACR,OAAO,EAAE;IACV,OAAOvC,SAAS;EACpB;EAEA,OAAOuC,OAAO,CAACJ,YAAY,CAACnC,SAAS,EAAEoB,KAAK,CAAC,IAAIpB,SAAS;AAC9D;;AAEA;AACA;AACA;AACO,SAASgD,cAAcA,CAAA,EAAG;EAC7B,IAAMT,OAAO,GAAG,IAAAU,iBAAU,EAAC/C,kBAAkB,CAAC;EAC9C,IAAI,CAACqC,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,EAAC/C,kBAAkB,CAAC;AACzC"}
1
+ {"version":3,"names":["_react","_interopRequireWildcard","require","_CompositionScope","compose","_len","arguments","length","fns","Array","_key","decoratee","reduceRight","decorator","CompositionContext","createContext","undefined","CompositionProvider","_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","exports","useComponent","baseFunction","useOptionalComposition","useCompositionScope","useComposition","useContext","Error"],"sources":["Context.tsx"],"sourcesContent":["import React, {\n ComponentType,\n useState,\n useCallback,\n createContext,\n useContext,\n useMemo\n} from \"react\";\nimport { useCompositionScope } from \"~/CompositionScope\";\nimport {\n ComposedFunction,\n ComposeWith,\n DecoratableComponent,\n DecoratableHook,\n Enumerable,\n GenericComponent,\n Decorator,\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 CompositionContext {\n components: ComponentScopes;\n getComponent(component: ComponentType<unknown>, scope?: string): ComposedFunction | undefined;\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 (component, hocs, scope = \"*\") => {\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: CompositionContext[\"getComponent\"] = useCallback(\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,GAAAC,SAAA,CAAAC,MAAA,EAArBC,GAAG,OAAAC,KAAA,CAAAJ,IAAA,GAAAK,IAAA,MAAAA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A,CAAAzC,mBAAA,GAAAA,mBAAA;AAEK,SAAS0C,YAAYA,CAAIC,YAAe,EAAE;EAC7C,IAAMP,OAAO,GAAGQ,sBAAsB,CAAC,CAAC;EACxC,IAAM7B,KAAK,GAAG,IAAA8B,qCAAmB,EAAC,CAAC;EAEnC,IAAI,CAACT,OAAO,EAAE;IACV,OAAOO,YAAY;EACvB;EAEA,OAAQP,OAAO,CAACL,YAAY,CAACY,YAAY,EAAS5B,KAAK,CAAC,IAAI4B,YAAY;AAC5E;;AAEA;AACA;AACA;AACO,SAASG,cAAcA,CAAA,EAAG;EAC7B,IAAMV,OAAO,GAAG,IAAAW,iBAAU,EAAClD,kBAAkB,CAAC;EAC9C,IAAI,CAACuC,OAAO,EAAE;IACV,MAAM,IAAIY,KAAK,gFAEf,CAAC;EACL;EAEA,OAAOZ,OAAO;AAClB;;AAEA;AACA;AACA;AACO,SAASQ,sBAAsBA,CAAA,EAAG;EACrC,OAAO,IAAAG,iBAAU,EAAClD,kBAAkB,CAAC;AACzC"}
@@ -0,0 +1,20 @@
1
+ /// <reference types="react" />
2
+ import { CanReturnNull, Decoratable, Decorator } from "./index";
3
+ import { DecoratableComponent, DecoratableHook } from "./types";
4
+ declare type GetBaseFunction<T> = T extends DecoratableComponent<infer F> ? F : never;
5
+ /**
6
+ * Creates a component which, when mounted, registers a Higher Order Component for the given base component.
7
+ * This is particularly useful for decorating (wrapping) existing composable components.
8
+ * For more information, visit https://www.webiny.com/docs/admin-area/basics/framework.
9
+ */
10
+ export declare function createComponentPlugin<T extends Decoratable>(Base: T, hoc: T extends DecoratableComponent ? Decorator<CanReturnNull<GetBaseFunction<T>>> : Decorator<GetBaseFunction<T>>): {
11
+ (): JSX.Element;
12
+ displayName: string | undefined;
13
+ };
14
+ export declare type GetDecorateeParams<T> = T extends (params: infer P) => any ? P : never;
15
+ export declare type GetDecoratee<T> = T extends DecoratableHook<infer F> ? F : T extends DecoratableComponent<infer F> ? F : never;
16
+ export declare function createDecorator<T extends Decoratable>(Base: T, hoc: T extends DecoratableComponent ? Decorator<CanReturnNull<GetBaseFunction<T>>> : Decorator<GetBaseFunction<T>>): {
17
+ (): JSX.Element;
18
+ displayName: string | undefined;
19
+ };
20
+ export {};
@@ -5,6 +5,7 @@ Object.defineProperty(exports, "__esModule", {
5
5
  value: true
6
6
  });
7
7
  exports.createComponentPlugin = createComponentPlugin;
8
+ exports.createDecorator = createDecorator;
8
9
  var _react = _interopRequireDefault(require("react"));
9
10
  var _index = require("./index");
10
11
  /**
@@ -13,14 +14,22 @@ var _index = require("./index");
13
14
  * For more information, visit https://www.webiny.com/docs/admin-area/basics/framework.
14
15
  */
15
16
  function createComponentPlugin(Base, hoc) {
16
- var ComponentPlugin = function ComponentPlugin() {
17
+ return createDecorator(Base, hoc);
18
+ }
19
+ var isDecoratableComponent = function isDecoratableComponent(decoratable) {
20
+ return "displayName" in decoratable;
21
+ };
22
+ function createDecorator(Base, hoc) {
23
+ var DecoratorPlugin = function DecoratorPlugin() {
17
24
  return /*#__PURE__*/_react.default.createElement(_index.Compose, {
18
25
  component: Base,
19
26
  with: hoc
20
27
  });
21
28
  };
22
- ComponentPlugin.displayName = Base.displayName;
23
- return ComponentPlugin;
29
+ if (isDecoratableComponent(Base)) {
30
+ DecoratorPlugin.displayName = Base.displayName;
31
+ }
32
+ return DecoratorPlugin;
24
33
  }
25
34
 
26
- //# sourceMappingURL=createComponentPlugin.js.map
35
+ //# sourceMappingURL=createDecorator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","_interopRequireDefault","require","_index","createComponentPlugin","Base","hoc","createDecorator","isDecoratableComponent","decoratable","DecoratorPlugin","default","createElement","Compose","component","with","displayName"],"sources":["createDecorator.tsx"],"sourcesContent":["import React from \"react\";\nimport { CanReturnNull, Compose, Decoratable, Decorator } from \"./index\";\nimport { DecoratableComponent, DecoratableHook } from \"~/types\";\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\nexport type GetDecorateeParams<T> = T extends (params: infer P) => any ? P : never;\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;AACA,IAAAC,MAAA,GAAAD,OAAA;AAKA;AACA;AACA;AACA;AACA;AACO,SAASE,qBAAqBA,CACjCC,IAAO,EACPC,GAEmC,EACrC;EACE,OAAOC,eAAe,CAACF,IAAI,EAAEC,GAAG,CAAC;AACrC;AAUA,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,MAAA,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"}
package/decorators.d.ts CHANGED
@@ -1,9 +1,9 @@
1
1
  /// <reference types="react" />
2
- import { Decorator } from "./Context";
3
- import { ComposableFC } from "./Compose";
2
+ import { GetDecoratee, GetDecorateeParams } from "./createDecorator";
3
+ import { DecoratableComponent, GenericComponent, Decorator } from "./types";
4
4
  interface ShouldDecorate<TDecorator = any, TComponent = any> {
5
5
  (decoratorProps: TDecorator, componentProps: TComponent): boolean;
6
6
  }
7
- export declare function createConditionalDecorator(shouldDecorate: ShouldDecorate, decorator: Decorator, decoratorProps: unknown): Decorator;
8
- export declare function createDecoratorFactory<TDecorator>(): <TComponent>(Component: ComposableFC<TComponent>, shouldDecorate?: ShouldDecorate<TDecorator, TComponent> | undefined) => (decorator: Decorator<TComponent>) => (props: TDecorator) => JSX.Element;
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<GetDecoratee<TDecoratable>>) => (props: TDecorator) => JSX.Element;
9
9
  export {};
package/decorators.js CHANGED
@@ -13,24 +13,28 @@ function createConditionalDecorator(shouldDecorate, decorator, decoratorProps) {
13
13
  return function ShouldDecorate(props) {
14
14
  if (shouldDecorate(decoratorProps, props)) {
15
15
  var Component = decorator(Original);
16
+ // @ts-expect-error
16
17
  return /*#__PURE__*/_react.default.createElement(Component, props);
17
18
  }
19
+
20
+ // @ts-expect-error
18
21
  return /*#__PURE__*/_react.default.createElement(Original, props);
19
22
  };
20
23
  };
21
24
  }
22
25
  function createDecoratorFactory() {
23
- return function from(Component, shouldDecorate) {
26
+ return function from(decoratable, shouldDecorate) {
24
27
  return function createDecorator(decorator) {
25
28
  return function DecoratorPlugin(props) {
26
29
  if (shouldDecorate) {
30
+ var componentDecorator = createConditionalDecorator(shouldDecorate, decorator, props);
27
31
  return /*#__PURE__*/_react.default.createElement(_Compose.Compose, {
28
- component: Component,
29
- with: createConditionalDecorator(shouldDecorate, decorator, props)
32
+ function: decoratable,
33
+ with: componentDecorator
30
34
  });
31
35
  }
32
36
  return /*#__PURE__*/_react.default.createElement(_Compose.Compose, {
33
- component: Component,
37
+ function: decoratable,
34
38
  with: decorator
35
39
  });
36
40
  };
package/decorators.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["_react","_interopRequireDefault","require","_Compose","createConditionalDecorator","shouldDecorate","decorator","decoratorProps","Original","ShouldDecorate","props","Component","default","createElement","createDecoratorFactory","from","createDecorator","DecoratorPlugin","Compose","component","with"],"sources":["decorators.tsx"],"sourcesContent":["import React from \"react\";\nimport { Decorator } from \"~/Context\";\nimport { ComposableFC, Compose } from \"~/Compose\";\n\ninterface ShouldDecorate<TDecorator = any, TComponent = any> {\n (decoratorProps: TDecorator, componentProps: TComponent): boolean;\n}\n\nexport function createConditionalDecorator(\n shouldDecorate: ShouldDecorate,\n decorator: Decorator,\n decoratorProps: unknown\n): Decorator {\n return (Original: React.ComponentType) => {\n return function ShouldDecorate(props) {\n if (shouldDecorate(decoratorProps, props)) {\n const Component = decorator(Original);\n return <Component {...props} />;\n }\n\n return <Original {...props} />;\n };\n };\n}\n\nexport function createDecoratorFactory<TDecorator>() {\n return function from<TComponent>(\n Component: ComposableFC<TComponent>,\n shouldDecorate?: ShouldDecorate<TDecorator, TComponent>\n ) {\n return function createDecorator(decorator: Decorator<TComponent>) {\n return function DecoratorPlugin(props: TDecorator) {\n if (shouldDecorate) {\n return (\n <Compose\n component={Component}\n with={createConditionalDecorator(shouldDecorate, decorator, props)}\n />\n );\n }\n return <Compose component={Component} with={decorator} />;\n };\n };\n };\n}\n"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAEA,IAAAC,QAAA,GAAAD,OAAA;AAMO,SAASE,0BAA0BA,CACtCC,cAA8B,EAC9BC,SAAoB,EACpBC,cAAuB,EACd;EACT,OAAO,UAACC,QAA6B,EAAK;IACtC,OAAO,SAASC,cAAcA,CAACC,KAAK,EAAE;MAClC,IAAIL,cAAc,CAACE,cAAc,EAAEG,KAAK,CAAC,EAAE;QACvC,IAAMC,SAAS,GAAGL,SAAS,CAACE,QAAQ,CAAC;QACrC,oBAAOR,MAAA,CAAAY,OAAA,CAAAC,aAAA,CAACF,SAAS,EAAKD,KAAQ,CAAC;MACnC;MAEA,oBAAOV,MAAA,CAAAY,OAAA,CAAAC,aAAA,CAACL,QAAQ,EAAKE,KAAQ,CAAC;IAClC,CAAC;EACL,CAAC;AACL;AAEO,SAASI,sBAAsBA,CAAA,EAAe;EACjD,OAAO,SAASC,IAAIA,CAChBJ,SAAmC,EACnCN,cAAuD,EACzD;IACE,OAAO,SAASW,eAAeA,CAACV,SAAgC,EAAE;MAC9D,OAAO,SAASW,eAAeA,CAACP,KAAiB,EAAE;QAC/C,IAAIL,cAAc,EAAE;UAChB,oBACIL,MAAA,CAAAY,OAAA,CAAAC,aAAA,CAACV,QAAA,CAAAe,OAAO;YACJC,SAAS,EAAER,SAAU;YACrBS,IAAI,EAAEhB,0BAA0B,CAACC,cAAc,EAAEC,SAAS,EAAEI,KAAK;UAAE,CACtE,CAAC;QAEV;QACA,oBAAOV,MAAA,CAAAY,OAAA,CAAAC,aAAA,CAACV,QAAA,CAAAe,OAAO;UAACC,SAAS,EAAER,SAAU;UAACS,IAAI,EAAEd;QAAU,CAAE,CAAC;MAC7D,CAAC;IACL,CAAC;EACL,CAAC;AACL"}
1
+ {"version":3,"names":["_react","_interopRequireDefault","require","_Compose","createConditionalDecorator","shouldDecorate","decorator","decoratorProps","Original","ShouldDecorate","props","Component","default","createElement","createDecoratorFactory","from","decoratable","createDecorator","DecoratorPlugin","componentDecorator","Compose","function","with"],"sources":["decorators.tsx"],"sourcesContent":["import React from \"react\";\nimport { Compose } from \"~/Compose\";\nimport { GetDecoratee, GetDecorateeParams } from \"~/createDecorator\";\nimport { DecoratableComponent, GenericComponent, GenericHook, Decorator } from \"~/types\";\n\ninterface 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 return function ShouldDecorate(props: unknown) {\n if (shouldDecorate(decoratorProps, props)) {\n const Component = decorator(Original);\n // @ts-expect-error\n return <Component {...props} />;\n }\n\n // @ts-expect-error\n return <Original {...props} />;\n };\n }) as Decorator<TDecoratee>;\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: Decorator<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={decorator as unknown as Decorator<GenericHook>}\n />\n );\n };\n };\n };\n}\n"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AAQO,SAASE,0BAA0BA,CACtCC,cAA8B,EAC9BC,SAAgC,EAChCC,cAAuB,EACF;EACrB,OAAQ,UAAAC,QAAQ,EAAI;IAChB,OAAO,SAASC,cAAcA,CAACC,KAAc,EAAE;MAC3C,IAAIL,cAAc,CAACE,cAAc,EAAEG,KAAK,CAAC,EAAE;QACvC,IAAMC,SAAS,GAAGL,SAAS,CAACE,QAAQ,CAAC;QACrC;QACA,oBAAOR,MAAA,CAAAY,OAAA,CAAAC,aAAA,CAACF,SAAS,EAAKD,KAAQ,CAAC;MACnC;;MAEA;MACA,oBAAOV,MAAA,CAAAY,OAAA,CAAAC,aAAA,CAACL,QAAQ,EAAKE,KAAQ,CAAC;IAClC,CAAC;EACL,CAAC;AACL;AAEO,SAASI,sBAAsBA,CAAA,EAAe;EACjD,OAAO,SAASC,IAAIA,CAChBC,WAAyB,EACzBX,cAA2F,EAC7F;IACE,OAAO,SAASY,eAAeA,CAACX,SAAgD,EAAE;MAC9E,OAAO,SAASY,eAAeA,CAACR,KAAiB,EAAE;QAC/C,IAAIL,cAAc,EAAE;UAChB,IAAMc,kBAAkB,GAAGf,0BAA0B,CACjDC,cAAc,EACdC,SAAS,EACTI,KACJ,CAAC;UAED,oBAAOV,MAAA,CAAAY,OAAA,CAAAC,aAAA,CAACV,QAAA,CAAAiB,OAAO;YAACC,QAAQ,EAAEL,WAAY;YAACM,IAAI,EAAEH;UAAmB,CAAE,CAAC;QACvE;QAEA,oBACInB,MAAA,CAAAY,OAAA,CAAAC,aAAA,CAACV,QAAA,CAAAiB,OAAO;UACJC,QAAQ,EAAEL,WAAY;UACtBM,IAAI,EAAEhB;QAA+C,CACxD,CAAC;MAEV,CAAC;IACL,CAAC;EACL,CAAC;AACL"}
package/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
1
  export * from "./Context";
2
2
  export * from "./Compose";
3
3
  export * from "./makeComposable";
4
- export * from "./createComponentPlugin";
4
+ export * from "./makeDecoratable";
5
+ export * from "./createDecorator";
5
6
  export * from "./decorators";
6
7
  export * from "./CompositionScope";
8
+ export * from "./types";
package/index.js CHANGED
@@ -36,14 +36,25 @@ Object.keys(_makeComposable).forEach(function (key) {
36
36
  }
37
37
  });
38
38
  });
39
- var _createComponentPlugin = require("./createComponentPlugin");
40
- Object.keys(_createComponentPlugin).forEach(function (key) {
39
+ var _makeDecoratable = require("./makeDecoratable");
40
+ Object.keys(_makeDecoratable).forEach(function (key) {
41
41
  if (key === "default" || key === "__esModule") return;
42
- if (key in exports && exports[key] === _createComponentPlugin[key]) return;
42
+ if (key in exports && exports[key] === _makeDecoratable[key]) return;
43
43
  Object.defineProperty(exports, key, {
44
44
  enumerable: true,
45
45
  get: function get() {
46
- return _createComponentPlugin[key];
46
+ return _makeDecoratable[key];
47
+ }
48
+ });
49
+ });
50
+ var _createDecorator = require("./createDecorator");
51
+ Object.keys(_createDecorator).forEach(function (key) {
52
+ if (key === "default" || key === "__esModule") return;
53
+ if (key in exports && exports[key] === _createDecorator[key]) return;
54
+ Object.defineProperty(exports, key, {
55
+ enumerable: true,
56
+ get: function get() {
57
+ return _createDecorator[key];
47
58
  }
48
59
  });
49
60
  });
@@ -69,5 +80,16 @@ Object.keys(_CompositionScope).forEach(function (key) {
69
80
  }
70
81
  });
71
82
  });
83
+ var _types = require("./types");
84
+ Object.keys(_types).forEach(function (key) {
85
+ if (key === "default" || key === "__esModule") return;
86
+ if (key in exports && exports[key] === _types[key]) return;
87
+ Object.defineProperty(exports, key, {
88
+ enumerable: true,
89
+ get: function get() {
90
+ return _types[key];
91
+ }
92
+ });
93
+ });
72
94
 
73
95
  //# sourceMappingURL=index.js.map
package/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["_Context","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_Compose","_makeComposable","_createComponentPlugin","_decorators","_CompositionScope"],"sources":["index.ts"],"sourcesContent":["export * from \"./Context\";\nexport * from \"./Compose\";\nexport * from \"./makeComposable\";\nexport * from \"./createComponentPlugin\";\nexport * from \"./decorators\";\nexport * from \"./CompositionScope\";\n"],"mappings":";;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GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAO,sBAAA,CAAAP,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAG,sBAAA,CAAAP,GAAA;IAAA;EAAA;AAAA;AACA,IAAAQ,WAAA,GAAAZ,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAU,WAAA,EAAAT,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAQ,WAAA,CAAAR,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAI,WAAA,CAAAR,GAAA;IAAA;EAAA;AAAA;AACA,IAAAS,iBAAA,GAAAb,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAW,iBAAA,EAAAV,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAS,iBAAA,CAAAT,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAK,iBAAA,CAAAT,GAAA;IAAA;EAAA;AAAA"}
1
+ {"version":3,"names":["_Context","require","Object","keys","forEach","key","exports","defineProperty","enumerable","get","_Compose","_makeComposable","_makeDecoratable","_createDecorator","_decorators","_CompositionScope","_types"],"sources":["index.ts"],"sourcesContent":["export * from \"./Context\";\nexport * from \"./Compose\";\nexport * from \"./makeComposable\";\nexport * from \"./makeDecoratable\";\nexport * from \"./createDecorator\";\nexport * from \"./decorators\";\nexport * from \"./CompositionScope\";\nexport * from \"./types\";\n"],"m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UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAM,iBAAA,CAAAV,GAAA;IAAA;EAAA;AAAA;AACA,IAAAW,MAAA,GAAAf,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAa,MAAA,EAAAZ,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAW,MAAA,CAAAX,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAO,MAAA,CAAAX,GAAA;IAAA;EAAA;AAAA"}
@@ -1,5 +1,5 @@
1
- import React from "react";
2
- export declare function makeComposable<TProps>(name: string, Component?: React.ComponentType<TProps>): React.FunctionComponent<TProps> & {
3
- original: React.ComponentType<TProps>;
4
- originalName: string;
5
- };
1
+ import { GenericComponent } from "./types";
2
+ /**
3
+ * @deprecated Use `makeDecoratable` instead.
4
+ */
5
+ export declare function makeComposable<T extends GenericComponent>(name: string, Component?: T): import("./types").DecoratableComponent<(() => null) | import("./types").CanReturnNull<NonNullable<T>>>;
package/makeComposable.js CHANGED
@@ -1,59 +1,22 @@
1
1
  "use strict";
2
2
 
3
- var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
3
  Object.defineProperty(exports, "__esModule", {
6
4
  value: true
7
5
  });
8
6
  exports.makeComposable = makeComposable;
9
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
10
- var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
11
- var _react = _interopRequireWildcard(require("react"));
12
- var _debounce = _interopRequireDefault(require("lodash/debounce"));
13
- var _Context = require("./Context");
7
+ var _react = require("react");
8
+ var _makeDecoratable = require("./makeDecoratable");
14
9
  var ComposableContext = /*#__PURE__*/(0, _react.createContext)([]);
15
10
  ComposableContext.displayName = "ComposableContext";
16
- function useComposableParents() {
17
- var context = (0, _react.useContext)(ComposableContext);
18
- if (!context) {
19
- return [];
20
- }
21
- return context;
22
- }
23
- var createEmptyRenderer = function createEmptyRenderer(name) {
24
- return (0, _defineProperty2.default)({}, name, function () {
25
- (0, _react.useEffect)(function () {
26
- // We need to debounce the log, as it sometimes only requires a single tick to get the new
27
- // composed component to render, and we don't want to scare developers for no reason.
28
- var debounced = (0, _debounce.default)(function () {
29
- console.info("<".concat(name, "/> is not implemented! To provide an implementation, use the <Compose/> component."));
30
- }, 100);
31
- return function () {
32
- debounced.cancel();
33
- };
34
- }, []);
35
- return null;
36
- })[name];
11
+ var nullRenderer = function nullRenderer() {
12
+ return null;
37
13
  };
14
+
15
+ /**
16
+ * @deprecated Use `makeDecoratable` instead.
17
+ */
38
18
  function makeComposable(name, Component) {
39
- if (!Component) {
40
- Component = createEmptyRenderer(name);
41
- }
42
- var Composable = function Composable(props) {
43
- var parents = useComposableParents();
44
- var ComposedComponent = (0, _Context.useComponent)(Component);
45
- var context = (0, _react.useMemo)(function () {
46
- return [].concat((0, _toConsumableArray2.default)(parents), [name]);
47
- }, [parents, name]);
48
- return /*#__PURE__*/_react.default.createElement(ComposableContext.Provider, {
49
- value: context
50
- }, /*#__PURE__*/_react.default.createElement(ComposedComponent, props, props.children));
51
- };
52
- Component.displayName = name;
53
- Composable.original = Component;
54
- Composable.originalName = name;
55
- Composable.displayName = "Composable<".concat(name, ">");
56
- return Composable;
19
+ return (0, _makeDecoratable.makeDecoratable)(name, Component ?? nullRenderer);
57
20
  }
58
21
 
59
22
  //# sourceMappingURL=makeComposable.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_react","_interopRequireWildcard","require","_debounce","_interopRequireDefault","_Context","ComposableContext","createContext","displayName","useComposableParents","context","useContext","createEmptyRenderer","name","_defineProperty2","default","useEffect","debounced","debounce","console","info","concat","cancel","makeComposable","Component","Composable","props","parents","ComposedComponent","useComponent","useMemo","_toConsumableArray2","createElement","Provider","value","children","original","originalName"],"sources":["makeComposable.tsx"],"sourcesContent":["import React, { createContext, useContext, useEffect, useMemo } from \"react\";\nimport debounce from \"lodash/debounce\";\nimport { ComposableFC } from \"./Compose\";\nimport { useComponent } from \"./Context\";\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 createEmptyRenderer = (name: string) => {\n return {\n [name]: function () {\n useEffect(() => {\n // We need to debounce the log, as it sometimes only requires a single tick to get the new\n // composed component to render, and we don't want to scare developers for no reason.\n const debounced = debounce(() => {\n console.info(\n `<${name}/> is not implemented! To provide an implementation, use the <Compose/> component.`\n );\n }, 100);\n\n return () => {\n debounced.cancel();\n };\n }, []);\n\n return null;\n }\n }[name];\n};\n\nexport function makeComposable<TProps>(name: string, Component?: React.ComponentType<TProps>) {\n if (!Component) {\n Component = createEmptyRenderer(name);\n }\n\n const Composable: ComposableFC<TProps> = props => {\n const parents = useComposableParents();\n const ComposedComponent = useComponent(Component as React.ComponentType<TProps>);\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 Component.displayName = name;\n\n Composable.original = Component;\n Composable.originalName = name;\n Composable.displayName = `Composable<${name}>`;\n\n return Composable;\n}\n"],"mappings":";;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,SAAA,GAAAC,sBAAA,CAAAF,OAAA;AAEA,IAAAG,QAAA,GAAAH,OAAA;AAEA,IAAMI,iBAAiB,gBAAG,IAAAC,oBAAa,EAAW,EAAE,CAAC;AACrDD,iBAAiB,CAACE,WAAW,GAAG,mBAAmB;AAEnD,SAASC,oBAAoBA,C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Ae,OAAA,CAAAiB,aAAA,CAACJ,iBAAiB,EAAKF,KAAK,EAAGA,KAAK,CAACS,QAA4B,CACzC,CAAC;EAErC,CAAC;EAEDX,SAAS,CAAChB,WAAW,GAAGK,IAAI;EAE5BY,UAAU,CAACW,QAAQ,GAAGZ,SAAS;EAC/BC,UAAU,CAACY,YAAY,GAAGxB,IAAI;EAC9BY,UAAU,CAACjB,WAAW,iBAAAa,MAAA,CAAiBR,IAAI,MAAG;EAE9C,OAAOY,UAAU;AACrB"}
1
+ {"version":3,"names":["_react","require","_makeDecoratable","ComposableContext","createContext","displayName","nullRenderer","makeComposable","name","Component","makeDecoratable"],"sources":["makeComposable.tsx"],"sourcesContent":["import { createContext } from \"react\";\nimport { GenericComponent } from \"~/types\";\nimport { makeDecoratable } from \"~/makeDecoratable\";\n\nconst ComposableContext = createContext<string[]>([]);\nComposableContext.displayName = \"ComposableContext\";\n\nconst nullRenderer = () => null;\n\n/**\n * @deprecated Use `makeDecoratable` instead.\n */\nexport function makeComposable<T extends GenericComponent>(name: string, Component?: T) {\n return makeDecoratable(name, Component ?? nullRenderer);\n}\n"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,OAAA;AAEA,IAAAC,gBAAA,GAAAD,OAAA;AAEA,IAAME,iBAAiB,gBAAG,IAAAC,oBAAa,EAAW,EAAE,CAAC;AACrDD,iBAAiB,CAACE,WAAW,GAAG,mBAAmB;AAEnD,IAAMC,YAAY,GAAG,SAAfA,YAAYA,CAAA;EAAA,OAAS,IAAI;AAAA;;AAE/B;AACA;AACA;AACO,SAASC,cAAcA,CAA6BC,IAAY,EAAEC,SAAa,EAAE;EACpF,OAAO,IAAAC,gCAAe,EAACF,IAAI,EAAEC,SAAS,IAAIH,YAAY,CAAC;AAC3D"}
@@ -0,0 +1,5 @@
1
+ /// <reference types="react" />
2
+ import { CanReturnNull, DecoratableComponent, DecoratableHook, GenericComponent, GenericHook } from "./types";
3
+ export declare function createVoidComponent<T>(): (props: T) => JSX.Element | null;
4
+ export declare function makeDecoratable<T extends GenericHook>(hook: T): DecoratableHook<T>;
5
+ export declare function makeDecoratable<T extends GenericComponent>(name: string, Component: T): DecoratableComponent<CanReturnNull<T>>;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+
3
+ var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard").default;
4
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.createVoidComponent = createVoidComponent;
9
+ exports.makeDecoratable = makeDecoratable;
10
+ var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
+ var _react = _interopRequireWildcard(require("react"));
12
+ var _Context = require("./Context");
13
+ var ComposableContext = /*#__PURE__*/(0, _react.createContext)([]);
14
+ ComposableContext.displayName = "ComposableContext";
15
+ function useComposableParents() {
16
+ var context = (0, _react.useContext)(ComposableContext);
17
+ if (!context) {
18
+ return [];
19
+ }
20
+ return context;
21
+ }
22
+ var nullRenderer = function nullRenderer() {
23
+ return null;
24
+ };
25
+ function makeDecoratableComponent(name) {
26
+ var Component = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : nullRenderer;
27
+ var Decoratable = function Decoratable(props) {
28
+ var parents = useComposableParents();
29
+ var ComposedComponent = (0, _Context.useComponent)(Component);
30
+ var context = (0, _react.useMemo)(function () {
31
+ return [].concat((0, _toConsumableArray2.default)(parents), [name]);
32
+ }, [parents, name]);
33
+ return /*#__PURE__*/_react.default.createElement(ComposableContext.Provider, {
34
+ value: context
35
+ }, /*#__PURE__*/_react.default.createElement(ComposedComponent, props, props.children));
36
+ };
37
+ Decoratable.original = Component;
38
+ Decoratable.originalName = name;
39
+ Decoratable.displayName = "Decoratable<".concat(name, ">");
40
+ return Decoratable;
41
+ }
42
+ function makeDecoratableHook(hook) {
43
+ var decoratableHook = function decoratableHook(params) {
44
+ var composedHook = (0, _Context.useComponent)(hook);
45
+ return composedHook(params);
46
+ };
47
+ decoratableHook.original = hook;
48
+ return decoratableHook;
49
+ }
50
+ function createVoidComponent() {
51
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
52
+ return function (props) {
53
+ return null;
54
+ };
55
+ }
56
+ function makeDecoratable(hookOrName, Component) {
57
+ if (!Component) {
58
+ return makeDecoratableHook(hookOrName);
59
+ }
60
+ return makeDecoratableComponent(hookOrName, Component);
61
+ }
62
+
63
+ //# sourceMappingURL=makeDecoratable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["_react","_interopRequireWildcard","require","_Context","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","makeDecoratableHook","hook","decoratableHook","params","composedHook","createVoidComponent","makeDecoratable","hookOrName"],"sources":["makeDecoratable.tsx"],"sourcesContent":["import React, { createContext, useContext, useMemo } from \"react\";\nimport { useComponent } from \"./Context\";\nimport {\n CanReturnNull,\n DecoratableComponent,\n DecoratableHook,\n GenericComponent,\n GenericHook\n} from \"~/types\";\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: Parameters<T>[0]): 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 Decoratable;\n}\n\nfunction 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 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>(hook: T): DecoratableHook<T>;\nexport function makeDecoratable<T extends GenericComponent>(\n name: string,\n Component: T\n): DecoratableComponent<CanReturnNull<T>>;\nexport function makeDecoratable(hookOrName: any, Component?: any) {\n if (!Component) {\n return makeDecoratableHook(hookOrName);\n }\n\n return makeDecoratableComponent(hookOrName, Component);\n}\n"],"mappings":";;;;;;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,QAAA,GAAAD,OAAA;AASA,IAAME,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,SAAA,CAAAC,MAAA,QAAAD,SAAA,QAAAE,SAAA,GAAAF,SAAA,MAAGJ,YAAY;EAE3B,IAAMO,WAAW,GAAG,SAAdA,WAAWA,CAAIC,KAAuB,EAAyB;IACjE,IAAMC,OAAO,GAAGZ,oBAAoB,CAAC,CAAC;IACtC,IAAMa,iBAAiB,GAAG,IAAAC,qBAAY,EAACR,SA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
3
- "version": "5.39.1-beta.0",
3
+ "version": "5.39.1-beta.1",
4
4
  "main": "index.js",
5
5
  "repository": {
6
6
  "type": "git",
@@ -16,7 +16,6 @@
16
16
  "dependencies": {
17
17
  "@babel/runtime": "7.22.6",
18
18
  "@types/react": "17.0.39",
19
- "lodash": "4.17.21",
20
19
  "react": "17.0.2",
21
20
  "react-dom": "17.0.2"
22
21
  },
@@ -25,8 +24,9 @@
25
24
  "@babel/core": "7.22.8",
26
25
  "@babel/preset-env": "7.22.7",
27
26
  "@babel/preset-typescript": "7.22.5",
28
- "@webiny/cli": "5.39.1-beta.0",
29
- "@webiny/project-utils": "5.39.1-beta.0",
27
+ "@testing-library/react": "12.1.5",
28
+ "@webiny/cli": "5.39.1-beta.1",
29
+ "@webiny/project-utils": "5.39.1-beta.1",
30
30
  "ttypescript": "1.5.15",
31
31
  "typescript": "4.7.4"
32
32
  },
@@ -38,5 +38,5 @@
38
38
  "build": "yarn webiny run build",
39
39
  "watch": "yarn webiny run watch"
40
40
  },
41
- "gitHead": "4637f8570aa523ec1069e5907c3535c3dcdda5fe"
41
+ "gitHead": "6fc74b45740bd4123dcf9b5890bfacee594208bf"
42
42
  }
package/types.d.ts ADDED
@@ -0,0 +1,28 @@
1
+ import React from "react";
2
+ export declare type GenericHook = (...args: any) => any;
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;
6
+ /**
7
+ * @deprecated
8
+ */
9
+ export declare type ComposableFC<T> = T & {
10
+ displayName?: string;
11
+ original: T;
12
+ originalName: string;
13
+ };
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 & {
17
+ original: T;
18
+ originalName: string;
19
+ };
20
+ export declare type DecoratableComponent<T = GenericComponent> = T & {
21
+ original: T;
22
+ originalName: string;
23
+ };
24
+ export declare type Decoratable = DecoratableComponent | DecoratableHook;
25
+ /**
26
+ * @internal Add `null` to the ReturnType of the given function.
27
+ */
28
+ export declare type CanReturnNull<T> = T extends (...args: any) => any ? (...args: Parameters<T>) => ReturnType<T> | null : never;
package/types.js ADDED
@@ -0,0 +1,7 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+
7
+ //# sourceMappingURL=types.js.map
package/types.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import React from \"react\";\n\nexport type GenericHook = (...args: any) => any;\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};\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":""}
@@ -1,11 +0,0 @@
1
- import { ComponentProps } from "react";
2
- import { ComposableFC, HigherOrderComponent } from "./index";
3
- /**
4
- * Creates a component which, when mounted, registers a Higher Order Component for the given base component.
5
- * This is particularly useful for decorating (wrapping) existing composable components.
6
- * For more information, visit https://www.webiny.com/docs/admin-area/basics/framework.
7
- */
8
- export declare function createComponentPlugin<T extends ComposableFC<ComponentProps<T>>>(Base: T, hoc: HigherOrderComponent<ComponentProps<T>>): {
9
- (): JSX.Element;
10
- displayName: string | undefined;
11
- };
@@ -1 +0,0 @@
1
- {"version":3,"names":["_react","_interopRequireDefault","require","_index","createComponentPlugin","Base","hoc","ComponentPlugin","default","createElement","Compose","component","with","displayName"],"sources":["createComponentPlugin.tsx"],"sourcesContent":["import React, { ComponentProps } from \"react\";\nimport { ComposableFC, Compose, HigherOrderComponent } from \"./index\";\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 ComposableFC<ComponentProps<T>>>(\n Base: T,\n hoc: HigherOrderComponent<ComponentProps<T>>\n) {\n const ComponentPlugin = () => <Compose component={Base} with={hoc} />;\n ComponentPlugin.displayName = Base.displayName;\n return ComponentPlugin;\n}\n"],"mappings":";;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,MAAA,GAAAD,OAAA;AAEA;AACA;AACA;AACA;AACA;AACO,SAASE,qBAAqBA,CACjCC,IAAO,EACPC,GAA4C,EAC9C;EACE,IAAMC,eAAe,GAAG,SAAlBA,eAAeA,CAAA;IAAA,oBAASP,MAAA,CAAAQ,OAAA,CAAAC,aAAA,CAACN,MAAA,CAAAO,OAAO;MAACC,SAAS,EAAEN,IAAK;MAACO,IAAI,EAAEN;IAAI,CAAE,CAAC;EAAA;EACrEC,eAAe,CAACM,WAAW,GAAGR,IAAI,CAACQ,WAAW;EAC9C,OAAON,eAAe;AAC1B"}