@webiny/react-composition 6.0.0-beta.0 β†’ 6.0.0-rc.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/Compose.d.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { DecoratableTypes } from "./Context";
2
- import { ComposeWith } from "./types";
1
+ import type { DecoratableTypes } from "./Context.js";
2
+ import type { ComposeWith } from "./types.js";
3
3
  export interface ComposeProps {
4
4
  function?: DecoratableTypes;
5
5
  component?: DecoratableTypes;
package/Compose.js CHANGED
@@ -1,24 +1,25 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.Compose = void 0;
7
- var _react = require("react");
8
- var _Context = require("./Context");
9
- var _CompositionScope = require("./CompositionScope");
10
- var Compose = exports.Compose = function Compose(props) {
11
- var _useComposition = (0, _Context.useComposition)(),
12
- composeComponent = _useComposition.composeComponent;
13
- var scope = (0, _CompositionScope.useCompositionScope)();
14
- var targetFn = props.function ?? props.component;
15
- (0, _react.useEffect)(function () {
1
+ import { useEffect } from "react";
2
+ import { useComposition } from "./Context.js";
3
+ import { useCompositionScope } from "./CompositionScope.js";
4
+ export const Compose = props => {
5
+ const {
6
+ composeComponent
7
+ } = useComposition();
8
+ const {
9
+ scope,
10
+ inherit
11
+ } = useCompositionScope();
12
+ const targetFn = props.function ?? props.component;
13
+ useEffect(() => {
14
+ if (!targetFn) {
15
+ console.warn("You must provide a function or a component to compose with!", props);
16
+ }
16
17
  if (typeof targetFn.original === "undefined") {
17
- console.warn("You must make your function \"".concat(targetFn.originalName ?? targetFn.name, "\" composable, by using the makeDecoratable() function!"));
18
+ console.warn(`You must make your function "${targetFn.originalName ?? targetFn.name}" composable, by using the makeDecoratable() function!`);
18
19
  return;
19
20
  }
20
- var decorators = Array.isArray(props.with) ? props.with : [props.with];
21
- return composeComponent(targetFn.original, decorators, scope);
21
+ const decorators = Array.isArray(props.with) ? props.with : [props.with];
22
+ return composeComponent(targetFn.original, decorators, scope[scope.length - 1], inherit);
22
23
  }, [props.with]);
23
24
  return null;
24
25
  };
package/Compose.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"names":["_react","require","_Context","_CompositionScope","Compose","exports","props","_useComposition","useComposition","composeComponent","scope","useCompositionScope","targetFn","function","component","useEffect","original","console","warn","concat","originalName","name","decorators","Array","isArray","with"],"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,GAAAC,OAAA,CAAAD,OAAA,GAAG,SAAVA,OAAOA,CAAIE,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","ignoreList":[]}
1
+ {"version":3,"names":["useEffect","useComposition","useCompositionScope","Compose","props","composeComponent","scope","inherit","targetFn","function","component","console","warn","original","originalName","name","decorators","Array","isArray","with","length"],"sources":["Compose.tsx"],"sourcesContent":["import { useEffect } from \"react\";\nimport type { DecoratableTypes } from \"./Context.js\";\nimport { useComposition } from \"./Context.js\";\nimport { useCompositionScope } from \"~/CompositionScope.js\";\nimport type { ComposeWith, Decoratable, Enumerable } from \"./types.js\";\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, inherit } = useCompositionScope();\n\n const targetFn = (props.function ?? props.component) as Decoratable;\n\n useEffect(() => {\n if (!targetFn) {\n console.warn(\"You must provide a function or a component to compose with!\", props);\n }\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(\n targetFn.original,\n decorators as Enumerable<ComposeWith>,\n scope[scope.length - 1],\n inherit\n );\n }, [props.with]);\n\n return null;\n};\n"],"mappings":"AAAA,SAASA,SAAS,QAAQ,OAAO;AAEjC,SAASC,cAAc;AACvB,SAASC,mBAAmB;AAS5B,OAAO,MAAMC,OAAO,GAAIC,KAAmB,IAAK;EAC5C,MAAM;IAAEC;EAAiB,CAAC,GAAGJ,cAAc,CAAC,CAAC;EAC7C,MAAM;IAAEK,KAAK;IAAEC;EAAQ,CAAC,GAAGL,mBAAmB,CAAC,CAAC;EAEhD,MAAMM,QAAQ,GAAIJ,KAAK,CAACK,QAAQ,IAAIL,KAAK,CAACM,SAAyB;EAEnEV,SAAS,CAAC,MAAM;IACZ,IAAI,CAACQ,QAAQ,EAAE;MACXG,OAAO,CAACC,IAAI,CAAC,6DAA6D,EAAER,KAAK,CAAC;IACtF;IACA,IAAI,OAAOI,QAAQ,CAACK,QAAQ,KAAK,WAAW,EAAE;MAC1CF,OAAO,CAACC,IAAI,CACR,gCACIJ,QAAQ,CAACM,YAAY,IAAIN,QAAQ,CAACO,IAAI,wDAE9C,CAAC;MAED;IACJ;IAEA,MAAMC,UAAU,GAAGC,KAAK,CAACC,OAAO,CAACd,KAAK,CAACe,IAAI,CAAC,GAAGf,KAAK,CAACe,IAAI,GAAG,CAACf,KAAK,CAACe,IAAI,CAAC;IACxE,OAAOd,gBAAgB,CACnBG,QAAQ,CAACK,QAAQ,EACjBG,UAAU,EACVV,KAAK,CAACA,KAAK,CAACc,MAAM,GAAG,CAAC,CAAC,EACvBb,OACJ,CAAC;EACL,CAAC,EAAE,CAACH,KAAK,CAACe,IAAI,CAAC,CAAC;EAEhB,OAAO,IAAI;AACf,CAAC","ignoreList":[]}
@@ -1,11 +1,17 @@
1
1
  import React from "react";
2
2
  export interface CompositionScopeContext {
3
- name: string;
3
+ inherit: boolean;
4
+ scope: string[];
4
5
  }
5
6
  interface CompositionScopeProps {
6
7
  name: string;
8
+ /**
9
+ * Use this prop on components that are used to register decorators.
10
+ * Components are inherited at the time of registration, and then cached.
11
+ */
12
+ inherit?: boolean;
7
13
  children: React.ReactNode;
8
14
  }
9
- export declare const CompositionScope: ({ name, children }: CompositionScopeProps) => React.JSX.Element;
10
- export declare function useCompositionScope(): string | undefined;
15
+ export declare const CompositionScope: ({ name, inherit, children }: CompositionScopeProps) => React.JSX.Element;
16
+ export declare function useCompositionScope(): CompositionScopeContext;
11
17
  export {};
@@ -1,28 +1,27 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.CompositionScope = void 0;
8
- exports.useCompositionScope = useCompositionScope;
9
- var _react = _interopRequireDefault(require("react"));
10
- var CompositionScopeContext = /*#__PURE__*/_react.default.createContext(undefined);
11
- var CompositionScope = exports.CompositionScope = function CompositionScope(_ref) {
12
- var name = _ref.name,
13
- children = _ref.children;
14
- return /*#__PURE__*/_react.default.createElement(CompositionScopeContext.Provider, {
1
+ import React from "react";
2
+ const CompositionScopeContext = /*#__PURE__*/React.createContext(undefined);
3
+ export const CompositionScope = ({
4
+ name,
5
+ inherit = false,
6
+ children
7
+ }) => {
8
+ const parentScope = useCompositionScope();
9
+ return /*#__PURE__*/React.createElement(CompositionScopeContext.Provider, {
15
10
  value: {
16
- name: name
11
+ scope: [...parentScope.scope, name],
12
+ inherit
17
13
  }
18
14
  }, children);
19
15
  };
20
- function useCompositionScope() {
21
- var context = _react.default.useContext(CompositionScopeContext);
16
+ export function useCompositionScope() {
17
+ const context = React.useContext(CompositionScopeContext);
22
18
  if (!context) {
23
- return undefined;
19
+ return {
20
+ scope: [],
21
+ inherit: false
22
+ };
24
23
  }
25
- return context.name;
24
+ return context;
26
25
  }
27
26
 
28
27
  //# sourceMappingURL=CompositionScope.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["_react","_interopRequireDefault","require","CompositionScopeContext","React","createContext","undefined","CompositionScope","exports","_ref","name","children","default","createElement","Provider","value","useCompositionScope","context","useContext"],"sources":["CompositionScope.tsx"],"sourcesContent":["import React from \"react\";\n\nexport interface CompositionScopeContext {\n name: string;\n}\n\nconst CompositionScopeContext = React.createContext<CompositionScopeContext | undefined>(undefined);\n\ninterface CompositionScopeProps {\n name: string;\n children: React.ReactNode;\n}\n\nexport const CompositionScope = ({ name, children }: CompositionScopeProps) => {\n return (\n <CompositionScopeContext.Provider value={{ name }}>\n {children}\n </CompositionScopeContext.Provider>\n );\n};\n\nexport function useCompositionScope() {\n const context = React.useContext(CompositionScopeContext);\n if (!context) {\n return undefined;\n }\n return context.name;\n}\n"],"mappings":";;;;;;;;AAAA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AAMA,IAAMC,uBAAuB,gBAAGC,cAAK,CAACC,aAAa,CAAsCC,SAAS,CAAC;AAO5F,IAAMC,gBAAgB,GAAAC,OAAA,CAAAD,gBAAA,GAAG,SAAnBA,gBAAgBA,CAAAE,IAAA,EAAkD;EAAA,IAA5CC,IAAI,GAAAD,IAAA,CAAJC,IAAI;IAAEC,QAAQ,GAAAF,IAAA,CAARE,QAAQ;EAC7C,oBACIX,MAAA,CAAAY,OAAA,CAAAC,aAAA,CAACV,uBAAuB,CAACW,QAAQ;IAACC,KAAK,EAAE;MAAEL,IAAI,EAAJA;IAAK;EAAE,GAC7CC,QAC6B,CAAC;AAE3C,CAAC;AAEM,SAASK,mBAAmBA,CAAA,EAAG;EAClC,IAAMC,OAAO,GAAGb,cAAK,CAACc,UAAU,CAACf,uBAAuB,CAAC;EACzD,IAAI,CAACc,OAAO,EAAE;IACV,OAAOX,SAAS;EACpB;EACA,OAAOW,OAAO,CAACP,IAAI;AACvB","ignoreList":[]}
1
+ {"version":3,"names":["React","CompositionScopeContext","createContext","undefined","CompositionScope","name","inherit","children","parentScope","useCompositionScope","createElement","Provider","value","scope","context","useContext"],"sources":["CompositionScope.tsx"],"sourcesContent":["import React from \"react\";\n\nexport interface CompositionScopeContext {\n inherit: boolean;\n scope: string[];\n}\n\nconst CompositionScopeContext = React.createContext<CompositionScopeContext | undefined>(undefined);\n\ninterface CompositionScopeProps {\n name: string;\n /**\n * Use this prop on components that are used to register decorators.\n * Components are inherited at the time of registration, and then cached.\n */\n inherit?: boolean;\n children: React.ReactNode;\n}\n\nexport const CompositionScope = ({ name, inherit = false, children }: CompositionScopeProps) => {\n const parentScope = useCompositionScope();\n\n return (\n <CompositionScopeContext.Provider value={{ scope: [...parentScope.scope, name], inherit }}>\n {children}\n </CompositionScopeContext.Provider>\n );\n};\n\nexport function useCompositionScope() {\n const context = React.useContext(CompositionScopeContext);\n\n if (!context) {\n return { scope: [], inherit: false };\n }\n\n return context;\n}\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AAOzB,MAAMC,uBAAuB,gBAAGD,KAAK,CAACE,aAAa,CAAsCC,SAAS,CAAC;AAYnG,OAAO,MAAMC,gBAAgB,GAAGA,CAAC;EAAEC,IAAI;EAAEC,OAAO,GAAG,KAAK;EAAEC;AAAgC,CAAC,KAAK;EAC5F,MAAMC,WAAW,GAAGC,mBAAmB,CAAC,CAAC;EAEzC,oBACIT,KAAA,CAAAU,aAAA,CAACT,uBAAuB,CAACU,QAAQ;IAACC,KAAK,EAAE;MAAEC,KAAK,EAAE,CAAC,GAAGL,WAAW,CAACK,KAAK,EAAER,IAAI,CAAC;MAAEC;IAAQ;EAAE,GACrFC,QAC6B,CAAC;AAE3C,CAAC;AAED,OAAO,SAASE,mBAAmBA,CAAA,EAAG;EAClC,MAAMK,OAAO,GAAGd,KAAK,CAACe,UAAU,CAACd,uBAAuB,CAAC;EAEzD,IAAI,CAACa,OAAO,EAAE;IACV,OAAO;MAAED,KAAK,EAAE,EAAE;MAAEP,OAAO,EAAE;IAAM,CAAC;EACxC;EAEA,OAAOQ,OAAO;AAClB","ignoreList":[]}
package/Context.d.ts CHANGED
@@ -1,5 +1,6 @@
1
- import React, { ComponentType } from "react";
2
- import { ComposedFunction, ComposeWith, DecoratableComponent, DecoratableHook, Decorator, Enumerable, GenericComponent, GenericHook } from "./types";
1
+ import type { ComponentType } from "react";
2
+ import React from "react";
3
+ import type { ComposedFunction, ComposeWith, Decoratable, DecoratableComponent, DecoratableHook, Decorator, Enumerable, GenericComponent, GenericHook } from "./types.js";
3
4
  export declare function compose<T>(...fns: Decorator<T>[]): (decoratee: T) => T;
4
5
  interface ComposedComponent {
5
6
  /**
@@ -21,29 +22,31 @@ interface ComposedComponent {
21
22
  export interface HigherOrderComponent<TProps = any, TOutput = TProps> {
22
23
  (Component: GenericComponent<TProps>): GenericComponent<TOutput>;
23
24
  }
24
- declare type ComposedComponents = Map<ComponentType<unknown>, ComposedComponent>;
25
- declare type ComponentScopes = Map<string, ComposedComponents>;
26
- export declare type DecoratableTypes = DecoratableComponent | DecoratableHook;
25
+ type ComposedComponents = Map<ComponentType<unknown>, ComposedComponent>;
26
+ type ComponentScopes = Map<string, ComposedComponents>;
27
+ export type DecoratableTypes = DecoratableComponent | DecoratableHook;
27
28
  interface CompositionContextGetComponentCallable {
28
- (component: ComponentType<unknown>, scope?: string): ComposedFunction | GenericComponent | undefined;
29
+ (component: ComponentType<unknown>, scope: string[]): ComposedFunction | GenericComponent | undefined;
29
30
  }
30
- interface CompositionContext {
31
+ interface CompositionContextValue {
31
32
  components: ComponentScopes;
32
33
  getComponent: CompositionContextGetComponentCallable;
33
- composeComponent(component: ComponentType<unknown>, hocs: Enumerable<ComposeWith>, scope?: string): void;
34
+ composeComponent(component: ComponentType<unknown>, hocs: Enumerable<ComposeWith>, scope?: string, inherit?: boolean): void;
34
35
  }
35
- declare const CompositionContext: React.Context<CompositionContext | undefined>;
36
+ export type DecoratorsTuple = [Decoratable, Decorator<any>[]];
37
+ export type DecoratorsCollection = Array<DecoratorsTuple>;
36
38
  interface CompositionProviderProps {
39
+ decorators?: DecoratorsCollection;
37
40
  children: React.ReactNode;
38
41
  }
39
- export declare const CompositionProvider: ({ children }: CompositionProviderProps) => React.JSX.Element;
42
+ export declare const CompositionProvider: ({ decorators, children }: CompositionProviderProps) => React.JSX.Element;
40
43
  export declare function useComponent<T>(baseFunction: T): T;
41
44
  /**
42
45
  * This hook will throw an error if composition context doesn't exist.
43
46
  */
44
- export declare function useComposition(): CompositionContext;
47
+ export declare function useComposition(): CompositionContextValue;
45
48
  /**
46
49
  * This hook will not throw an error if composition context doesn't exist.
47
50
  */
48
- export declare function useOptionalComposition(): CompositionContext | undefined;
51
+ export declare function useOptionalComposition(): CompositionContextValue | undefined;
49
52
  export {};
package/Context.js CHANGED
@@ -1,27 +1,8 @@
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.CompositionProvider = void 0;
9
- exports.compose = compose;
10
- exports.useComponent = useComponent;
11
- exports.useComposition = useComposition;
12
- exports.useOptionalComposition = useOptionalComposition;
13
- var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
14
- var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
15
- var _react = _interopRequireWildcard(require("react"));
16
- var _CompositionScope = require("./CompositionScope");
17
- function compose() {
18
- for (var _len = arguments.length, fns = new Array(_len), _key = 0; _key < _len; _key++) {
19
- fns[_key] = arguments[_key];
20
- }
21
- return function (decoratee) {
22
- return fns.reduceRight(function (decoratee, decorator) {
23
- return decorator(decoratee);
24
- }, decoratee);
1
+ import React, { createContext, useCallback, useContext, useMemo, useState } from "react";
2
+ import { useCompositionScope } from "./CompositionScope.js";
3
+ export function compose(...fns) {
4
+ return decoratee => {
5
+ return fns.reduceRight((decoratee, decorator) => decorator(decoratee), decoratee);
25
6
  };
26
7
  }
27
8
 
@@ -29,44 +10,57 @@ function compose() {
29
10
  * @deprecated Use `Decorator` instead.
30
11
  */
31
12
 
32
- var CompositionContext = /*#__PURE__*/(0, _react.createContext)(undefined);
33
- var CompositionProvider = exports.CompositionProvider = function CompositionProvider(_ref) {
34
- var children = _ref.children;
35
- var _useState = (0, _react.useState)(new Map()),
36
- _useState2 = (0, _slicedToArray2.default)(_useState, 2),
37
- components = _useState2[0],
38
- setComponents = _useState2[1];
39
- var composeComponent = (0, _react.useCallback)(function (component, hocs) {
40
- var scope = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : "*";
41
- setComponents(function (prevComponents) {
42
- var components = new Map(prevComponents);
43
- var scopeMap = components.get(scope) || new Map();
44
- var recipe = scopeMap.get(component) || {
13
+ const CompositionContext = /*#__PURE__*/createContext(undefined);
14
+ const composeComponents = (components, decorators, scope = "*", inherit = false) => {
15
+ const scopeMap = components.get(scope) || new Map();
16
+ for (const [component, newHocs] of decorators) {
17
+ const recipe = scopeMap.get(component) || {
18
+ component: null,
19
+ hocs: []
20
+ };
21
+ const existingHocs = [...(recipe.hocs || [])];
22
+ if (inherit && scope !== "*") {
23
+ const globalScope = components.get("*") || new Map();
24
+ const globalRecipe = globalScope.get(component) || {
45
25
  component: null,
46
26
  hocs: []
47
27
  };
48
- var newHocs = [].concat((0, _toConsumableArray2.default)(recipe.hocs || []), (0, _toConsumableArray2.default)(hocs));
49
- scopeMap.set(component, {
50
- component: compose.apply(void 0, (0, _toConsumableArray2.default)((0, _toConsumableArray2.default)(newHocs).reverse()))(component),
51
- hocs: newHocs
52
- });
53
- components.set(scope, scopeMap);
54
- return components;
28
+ existingHocs.unshift(...globalRecipe.hocs);
29
+ }
30
+ const finalHocs = [...existingHocs, ...newHocs];
31
+ scopeMap.set(component, {
32
+ component: compose(...[...finalHocs].reverse())(component),
33
+ hocs: finalHocs
34
+ });
35
+ components.set(scope, scopeMap);
36
+ }
37
+ return components;
38
+ };
39
+ export const CompositionProvider = ({
40
+ decorators = [],
41
+ children
42
+ }) => {
43
+ const [components, setComponents] = useState(() => {
44
+ return composeComponents(new Map(), decorators.map(tuple => {
45
+ return [tuple[0].original, tuple[1]];
46
+ }));
47
+ });
48
+ const composeComponent = useCallback((component, hocs, scope = "*", inherit = false) => {
49
+ setComponents(prevComponents => {
50
+ return composeComponents(new Map(prevComponents), [[component, hocs]], scope, inherit);
55
51
  });
56
52
 
57
53
  // Return a function that will remove the added HOCs.
58
- return function () {
59
- setComponents(function (prevComponents) {
60
- var components = new Map(prevComponents);
61
- var scopeMap = components.get(scope) || new Map();
62
- var recipe = scopeMap.get(component) || {
54
+ return () => {
55
+ setComponents(prevComponents => {
56
+ const components = new Map(prevComponents);
57
+ const scopeMap = components.get(scope) || new Map();
58
+ const recipe = scopeMap.get(component) || {
63
59
  component: null,
64
60
  hocs: []
65
61
  };
66
- var newHOCs = (0, _toConsumableArray2.default)(recipe.hocs).filter(function (hoc) {
67
- return !hocs.includes(hoc);
68
- });
69
- var NewComponent = compose.apply(void 0, (0, _toConsumableArray2.default)((0, _toConsumableArray2.default)(newHOCs).reverse()))(component);
62
+ const newHOCs = [...recipe.hocs].filter(hoc => !hocs.includes(hoc));
63
+ const NewComponent = compose(...[...newHOCs].reverse())(component);
70
64
  scopeMap.set(component, {
71
65
  component: NewComponent,
72
66
  hocs: newHOCs
@@ -76,45 +70,42 @@ var CompositionProvider = exports.CompositionProvider = function CompositionProv
76
70
  });
77
71
  };
78
72
  }, [setComponents]);
79
- var getComponent = (0, _react.useCallback)(function (Component) {
80
- var scope = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : "*";
81
- var scopeMap = components.get(scope) || new Map();
82
- var composedComponent = scopeMap.get(Component);
83
- if (!composedComponent && scope !== "*") {
84
- // Check if a default scope component exists
85
- var defaultScopeMap = components.get("*") || new Map();
86
- var defaultComponent = defaultScopeMap.get(Component);
87
- return defaultComponent ? defaultComponent.component : undefined;
73
+ const getComponent = useCallback((Component, scope = []) => {
74
+ const scopesToResolve = ["*", ...scope].reverse();
75
+ for (const scope of scopesToResolve) {
76
+ const scopeMap = components.get(scope) || new Map();
77
+ const composedComponent = scopeMap.get(Component);
78
+ if (composedComponent) {
79
+ return composedComponent.component;
80
+ }
88
81
  }
89
- return composedComponent ? composedComponent.component : undefined;
82
+ return undefined;
90
83
  }, [components]);
91
- var context = (0, _react.useMemo)(function () {
92
- return {
93
- getComponent: getComponent,
94
- composeComponent: composeComponent,
95
- components: components
96
- };
97
- }, [components, composeComponent]);
98
- return /*#__PURE__*/_react.default.createElement(CompositionContext.Provider, {
84
+ const context = useMemo(() => ({
85
+ getComponent,
86
+ composeComponent,
87
+ components
88
+ }), [components, composeComponent]);
89
+ return /*#__PURE__*/React.createElement(CompositionContext.Provider, {
99
90
  value: context
100
91
  }, children);
101
92
  };
102
- function useComponent(baseFunction) {
103
- var context = useOptionalComposition();
104
- var scope = (0, _CompositionScope.useCompositionScope)();
93
+ export function useComponent(baseFunction) {
94
+ const context = useOptionalComposition();
95
+ const scope = useCompositionScope();
105
96
  if (!context) {
106
97
  return baseFunction;
107
98
  }
108
- return context.getComponent(baseFunction, scope) || baseFunction;
99
+ return context.getComponent(baseFunction, scope.scope) || baseFunction;
109
100
  }
110
101
 
111
102
  /**
112
103
  * This hook will throw an error if composition context doesn't exist.
113
104
  */
114
- function useComposition() {
115
- var context = (0, _react.useContext)(CompositionContext);
105
+ export function useComposition() {
106
+ const context = useContext(CompositionContext);
116
107
  if (!context) {
117
- throw new Error("You're missing a <CompositionProvider> higher up in your component hierarchy!");
108
+ throw new Error(`You're missing a <CompositionProvider> higher up in your component hierarchy!`);
118
109
  }
119
110
  return context;
120
111
  }
@@ -122,8 +113,8 @@ function useComposition() {
122
113
  /**
123
114
  * This hook will not throw an error if composition context doesn't exist.
124
115
  */
125
- function useOptionalComposition() {
126
- return (0, _react.useContext)(CompositionContext);
116
+ export function useOptionalComposition() {
117
+ return useContext(CompositionContext);
127
118
  }
128
119
 
129
120
  //# sourceMappingURL=Context.js.map
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,GAAAC,SAAA,CAAAC,MAAA,EAArBC,GAAG,OAAAC,KAAA,CAAAJ,IAAA,GAAAK,IAAA,MAAAA,IAAA,GAAAL,IAAA,EAAAK,IAAA;IAAHF,GAAG,CAAAE,IAAA,IAAAJ,SAAA,CAAAI,IAAA;EAAA;EAC7B,OAAO,UAACC,SAAY,EAAQ;IACxB,OAAOH,GAAG,CAACI,WAAW,CAAC,UAACD,SAAS,EAAEE,SAAS;MAAA,OAAKA,SAAS,CAACF,SAAS,CAAC;IAAA,GAAEA,SAAS,CAAC;EACrF,CAAC;AACL;;AAiBA;AACA;AACA;;AA2BA,IAAMG,kBAAkB,gBAAG,IAAAC,oBAAa,EAAiCC,SAAS,CAAC;AAM5E,IAAMC,mBAAmB,GAAAC,OAAA,CAAAD,mBAAA,GAAG,SAAtBA,mBAAmBA,CAAAE,IAAA,EAA+C;EAAA,IAAzCC,QAAQ,GAAAD,IAAA,CAARC,QAAQ;EAC1C,IAAAC,SAAA,GAAoC,IAAAC,eAAQ,EAAkB,IAAIC,GAAG,CAAC,CAAC,CAAC;IAAAC,UAAA,OAAAC,eAAA,CAAAC,OAAA,EA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oreList":[]}
1
+ {"version":3,"names":["React","createContext","useCallback","useContext","useMemo","useState","useCompositionScope","compose","fns","decoratee","reduceRight","decorator","CompositionContext","undefined","composeComponents","components","decorators","scope","inherit","scopeMap","get","Map","component","newHocs","recipe","hocs","existingHocs","globalScope","globalRecipe","unshift","finalHocs","set","reverse","CompositionProvider","children","setComponents","map","tuple","original","composeComponent","prevComponents","newHOCs","filter","hoc","includes","NewComponent","getComponent","Component","scopesToResolve","composedComponent","context","createElement","Provider","value","useComponent","baseFunction","useOptionalComposition","useComposition","Error"],"sources":["Context.tsx"],"sourcesContent":["import type { ComponentType } from \"react\";\nimport React, { createContext, useCallback, useContext, useMemo, useState } from \"react\";\nimport { useCompositionScope } from \"~/CompositionScope.js\";\nimport type {\n ComposedFunction,\n ComposeWith,\n Decoratable,\n DecoratableComponent,\n DecoratableHook,\n Decorator,\n Enumerable,\n GenericComponent,\n GenericHook\n} from \"~/types.js\";\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 (\n component: ComponentType<unknown>,\n scope: string[]\n ): ComposedFunction | GenericComponent | undefined;\n}\n\ninterface CompositionContextValue {\n components: ComponentScopes;\n getComponent: CompositionContextGetComponentCallable;\n composeComponent(\n component: ComponentType<unknown>,\n hocs: Enumerable<ComposeWith>,\n scope?: string,\n inherit?: boolean\n ): void;\n}\n\nconst CompositionContext = createContext<CompositionContextValue | undefined>(undefined);\n\nexport type DecoratorsTuple = [Decoratable, Decorator<any>[]];\nexport type DecoratorsCollection = Array<DecoratorsTuple>;\n\ninterface CompositionProviderProps {\n decorators?: DecoratorsCollection;\n children: React.ReactNode;\n}\n\nconst composeComponents = (\n components: ComponentScopes,\n decorators: Array<[GenericComponent | GenericHook, Decorator<any>[]]>,\n scope = \"*\",\n inherit = false\n) => {\n const scopeMap: ComposedComponents = components.get(scope) || new Map();\n for (const [component, newHocs] of decorators) {\n const recipe = scopeMap.get(component) || { component: null, hocs: [] };\n\n const existingHocs = [...(recipe.hocs || [])];\n if (inherit && scope !== \"*\") {\n const globalScope = components.get(\"*\") || new Map();\n const globalRecipe = globalScope.get(component) || { component: null, hocs: [] };\n existingHocs.unshift(...globalRecipe.hocs);\n }\n\n const finalHocs = [...existingHocs, ...newHocs] as Decorator<\n GenericHook | GenericComponent\n >[];\n\n scopeMap.set(component, {\n component: compose(...[...finalHocs].reverse())(component),\n hocs: finalHocs\n });\n\n components.set(scope, scopeMap);\n }\n\n return components;\n};\n\nexport const CompositionProvider = ({ decorators = [], children }: CompositionProviderProps) => {\n const [components, setComponents] = useState<ComponentScopes>(() => {\n return composeComponents(\n new Map(),\n decorators.map(tuple => {\n return [tuple[0].original, tuple[1]];\n })\n );\n });\n\n const composeComponent = useCallback(\n (\n component: GenericComponent | GenericHook,\n hocs: HigherOrderComponent<any, any>[],\n scope: string | undefined = \"*\",\n inherit = false\n ) => {\n setComponents(prevComponents => {\n return composeComponents(\n new Map(prevComponents),\n [[component, hocs]],\n scope,\n inherit\n );\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 scopesToResolve = [\"*\", ...scope].reverse();\n for (const scope of scopesToResolve) {\n const scopeMap: ComposedComponents = components.get(scope) || new Map();\n const composedComponent = scopeMap.get(Component);\n if (composedComponent) {\n return composedComponent.component;\n }\n }\n\n return undefined;\n },\n [components]\n );\n\n const context: CompositionContextValue = 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.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":"AACA,OAAOA,KAAK,IAAIC,aAAa,EAAEC,WAAW,EAAEC,UAAU,EAAEC,OAAO,EAAEC,QAAQ,QAAQ,OAAO;AACxF,SAASC,mBAAmB;AAa5B,OAAO,SAASC,OAAOA,CAAI,GAAGC,GAAmB,EAAE;EAC/C,OAAQC,SAAY,IAAQ;IACxB,OAAOD,GAAG,CAACE,WAAW,CAAC,CAACD,SAAS,EAAEE,SAAS,KAAKA,SAAS,CAACF,SAAS,CAAC,EAAEA,SAAS,CAAC;EACrF,CAAC;AACL;;AAiBA;AACA;AACA;;AA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GAAGM,sBAAsB,CAAC,CAAC;EACxC,MAAMvC,KAAK,GAAGX,mBAAmB,CAAC,CAAC;EAEnC,IAAI,CAAC4C,OAAO,EAAE;IACV,OAAOK,YAAY;EACvB;EAEA,OAAQL,OAAO,CAACJ,YAAY,CAACS,YAAY,EAAStC,KAAK,CAACA,KAAK,CAAC,IAAIsC,YAAY;AAClF;;AAEA;AACA;AACA;AACA,OAAO,SAASE,cAAcA,CAAA,EAAG;EAC7B,MAAMP,OAAO,GAAG/C,UAAU,CAACS,kBAAkB,CAAC;EAC9C,IAAI,CAACsC,OAAO,EAAE;IACV,MAAM,IAAIQ,KAAK,CACX,+EACJ,CAAC;EACL;EAEA,OAAOR,OAAO;AAClB;;AAEA;AACA;AACA;AACA,OAAO,SAASM,sBAAsBA,CAAA,EAAG;EACrC,OAAOrD,UAAU,CAACS,kBAAkB,CAAC;AACzC","ignoreList":[]}
package/README.md CHANGED
@@ -1,8 +1,11 @@
1
- # Validation
2
- [![](https://img.shields.io/npm/dw/@webiny/react-composition.svg)](https://www.npmjs.com/package/@webiny/react-composition)
3
- [![](https://img.shields.io/npm/v/@webiny/react-composition.svg)](https://www.npmjs.com/package/@webiny/react-composition)
4
- [![code style: prettier](https://img.shields.io/badge/code_style-prettier-ff69b4.svg?style=flat-square)](https://github.com/prettier/prettier)
5
- [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](http://makeapullrequest.com)
1
+ # @webiny/react-composition
6
2
 
7
- A tiny composition framework for React components which makes it possible to compose components anywhere in your application.
3
+ > [!NOTE]
4
+ > This package is part of the [Webiny](https://www.webiny.com) monorepo.
5
+ > It’s **included in every Webiny project by default** and is not meant to be used as a standalone package.
8
6
 
7
+ πŸ“˜ **Documentation:** [https://www.webiny.com/docs](https://www.webiny.com/docs)
8
+
9
+ ---
10
+
11
+ _This README file is automatically generated during the publish process._
@@ -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 type { CanReturnNullOrElement, Decoratable, DecoratableComponent, DecoratableHook, Decorator } from "./types.js";
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,35 +1,25 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.createComponentPlugin = createComponentPlugin;
8
- exports.createDecorator = createDecorator;
9
- var _react = _interopRequireDefault(require("react"));
10
- var _Compose = require("./Compose");
1
+ import React from "react";
2
+ import { Compose } from "./Compose.js";
11
3
  /**
12
4
  * Creates a component which, when mounted, registers a Higher Order Component for the given base component.
13
5
  * This is particularly useful for decorating (wrapping) existing composable components.
14
6
  * For more information, visit https://www.webiny.com/docs/admin-area/basics/framework.
15
7
  */
16
- function createComponentPlugin(Base, hoc) {
8
+ export function createComponentPlugin(Base, hoc) {
17
9
  return createDecorator(Base, hoc);
18
10
  }
19
11
 
20
12
  // Maybe there's a better way to mark params as non-existent, but for now I left it as `any`.
21
13
  // TODO: revisit this type; not sure if `?` can be handled in one clause
22
14
 
23
- var isDecoratableComponent = function isDecoratableComponent(decoratable) {
15
+ const isDecoratableComponent = decoratable => {
24
16
  return "displayName" in decoratable;
25
17
  };
26
- function createDecorator(Base, hoc) {
27
- var DecoratorPlugin = function DecoratorPlugin() {
28
- return /*#__PURE__*/_react.default.createElement(_Compose.Compose, {
29
- component: Base,
30
- with: hoc
31
- });
32
- };
18
+ export function createDecorator(Base, hoc) {
19
+ const DecoratorPlugin = () => /*#__PURE__*/React.createElement(Compose, {
20
+ component: Base,
21
+ with: hoc
22
+ });
33
23
  if (isDecoratableComponent(Base)) {
34
24
  DecoratorPlugin.displayName = Base.displayName;
35
25
  }
@@ -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","Compose","createComponentPlugin","Base","hoc","createDecorator","isDecoratableComponent","decoratable","DecoratorPlugin","createElement","component","with","displayName"],"sources":["createDecorator.tsx"],"sourcesContent":["import React from \"react\";\nimport type {\n CanReturnNullOrElement,\n Decoratable,\n DecoratableComponent,\n DecoratableHook,\n Decorator\n} from \"~/types.js\";\nimport { Compose } from \"~/Compose.js\";\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> =\n T extends DecoratableHook<infer F> ? F : T extends DecoratableComponent<infer F> ? F : 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,OAAOA,KAAK,MAAM,OAAO;AAQzB,SAASC,OAAO;AAIhB;AACA;AACA;AACA;AACA;AACA,OAAO,SAASC,qBAAqBA,CACjCC,IAAO,EACPC,GAEmC,EACrC;EACE,OAAOC,eAAe,CAACF,IAAI,EAAEC,GAAG,CAAC;AACrC;;AAEA;AACA;;AAUA,MAAME,sBAAsB,GACxBC,WAAmD,IACb;EACtC,OAAO,aAAa,IAAIA,WAAW;AACvC,CAAC;AAED,OAAO,SAASF,eAAeA,CAC3BF,IAAO,EACPC,GAEmC,EACrC;EACE,MAAMI,eAAe,GAAGA,CAAA,kBAAMR,KAAA,CAAAS,aAAA,CAACR,OAAO;IAACS,SAAS,EAAEP,IAAK;IAACQ,IAAI,EAAEP;EAAW,CAAE,CAAC;EAC5E,IAAIE,sBAAsB,CAACH,IAAI,CAAC,EAAE;IAC9BK,eAAe,CAACI,WAAW,GAAGT,IAAI,CAACS,WAAW;EAClD;EACA,OAAOJ,eAAe;AAC1B","ignoreList":[]}
package/decorators.d.ts CHANGED
@@ -1,22 +1,15 @@
1
1
  import React from "react";
2
- import { GetDecoratee, GetDecorateeParams } from "./createDecorator";
3
- import { DecoratableComponent, GenericComponent, Decorator, CanReturnNull, GenericHook, DecoratableHook } from "./types";
2
+ import type { GetDecoratee, GetDecorateeParams } from "./createDecorator.js";
3
+ import type { DecoratableComponent, GenericComponent, Decorator, GenericHook, DecoratableHook, ComponentDecorator } from "./types.js";
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;
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;
8
+ export declare function createDecoratorFactory<TDecorator>(): <TDecoratable extends DecoratableComponent>(decoratable: TDecoratable, shouldDecorate?: ShouldDecorate<TDecorator, GetDecorateeParams<GetDecoratee<TDecoratable>>>) => (decorator: ComponentDecorator<GetDecoratee<TDecoratable>>) => (props: TDecorator) => React.JSX.Element;
9
+ export declare function createHookDecoratorFactory(): <TDecoratable extends DecoratableHook>(decoratable: TDecoratable) => (decorator: Decorator<GetDecoratee<TDecoratable>>) => () => React.JSX.Element;
10
+ export declare function withDecoratorFactory<TDecorator>(): <TDecoratable extends DecoratableComponent>(Component: TDecoratable, shouldDecorate?: ShouldDecorate<TDecorator, GetDecorateeParams<GetDecoratee<TDecoratable>>>) => TDecoratable & {
11
+ createDecorator: (decorator: ComponentDecorator<GetDecoratee<TDecoratable>>) => (props: TDecorator) => React.JSX.Element;
16
12
  };
17
- export declare function withHookDecoratorFactory(): <TDecoratable extends DecoratableHook<GenericHook<any, any>>>(hook: TDecoratable) => GenericHook<GetDecorateeParams<GetDecoratee<TDecoratable>>, ReturnType<GetDecoratee<TDecoratable>>> & {
18
- original: GenericHook<GetDecorateeParams<GetDecoratee<TDecoratable>>, ReturnType<GetDecoratee<TDecoratable>>>;
19
- originalName: string;
20
- } & {
13
+ export declare function withHookDecoratorFactory(): <TDecoratable extends DecoratableHook>(hook: TDecoratable) => DecoratableHook<GenericHook<GetDecorateeParams<GetDecoratee<TDecoratable>>, ReturnType<GetDecoratee<TDecoratable>>>> & {
21
14
  createDecorator: (decorator: Decorator<GetDecoratee<TDecoratable>>) => () => React.JSX.Element;
22
15
  };