@webiny/react-composition 0.0.0-unstable.de38392959 → 0.0.0-unstable.df7a8bb475

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/decorators.js CHANGED
@@ -1,41 +1,71 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault").default;
4
- Object.defineProperty(exports, "__esModule", {
5
- value: true
6
- });
7
- exports.createConditionalDecorator = createConditionalDecorator;
8
- exports.createDecoratorFactory = createDecoratorFactory;
9
- var _react = _interopRequireDefault(require("react"));
10
- var _Compose = require("./Compose");
11
- function createConditionalDecorator(shouldDecorate, decorator, decoratorProps) {
12
- return function (Original) {
1
+ import React from "react";
2
+ import { Compose } from "./Compose.js";
3
+ export function createConditionalDecorator(shouldDecorate, decorator, decoratorProps) {
4
+ return Original => {
5
+ const DecoratedComponent = /*#__PURE__*/React.memo(decorator(Original));
6
+ DecoratedComponent.displayName = Original.displayName;
13
7
  return function ShouldDecorate(props) {
14
8
  if (shouldDecorate(decoratorProps, props)) {
15
- var Component = decorator(Original);
16
- return /*#__PURE__*/_react.default.createElement(Component, props);
9
+ // @ts-expect-error
10
+ return /*#__PURE__*/React.createElement(DecoratedComponent, props);
17
11
  }
18
- return /*#__PURE__*/_react.default.createElement(Original, props);
12
+
13
+ // @ts-expect-error
14
+ return /*#__PURE__*/React.createElement(Original, props);
19
15
  };
20
16
  };
21
17
  }
22
- function createDecoratorFactory() {
23
- return function from(Component, shouldDecorate) {
18
+ const memoizedComponent = decorator => {
19
+ return decoratee => {
20
+ return /*#__PURE__*/React.memo(decorator(decoratee));
21
+ };
22
+ };
23
+ export function createDecoratorFactory() {
24
+ return function from(decoratable, shouldDecorate) {
24
25
  return function createDecorator(decorator) {
25
26
  return function DecoratorPlugin(props) {
26
27
  if (shouldDecorate) {
27
- return /*#__PURE__*/_react.default.createElement(_Compose.Compose, {
28
- component: Component,
29
- with: createConditionalDecorator(shouldDecorate, decorator, props)
28
+ const componentDecorator = createConditionalDecorator(shouldDecorate, decorator, props);
29
+ return /*#__PURE__*/React.createElement(Compose, {
30
+ function: decoratable,
31
+ with: componentDecorator
30
32
  });
31
33
  }
32
- return /*#__PURE__*/_react.default.createElement(_Compose.Compose, {
33
- component: Component,
34
+ return /*#__PURE__*/React.createElement(Compose, {
35
+ function: decoratable,
36
+ with: memoizedComponent(decorator)
37
+ });
38
+ };
39
+ };
40
+ };
41
+ }
42
+ export function createHookDecoratorFactory() {
43
+ return function from(decoratable) {
44
+ return function createDecorator(decorator) {
45
+ return function DecoratorPlugin() {
46
+ return /*#__PURE__*/React.createElement(Compose, {
47
+ function: decoratable,
34
48
  with: decorator
35
49
  });
36
50
  };
37
51
  };
38
52
  };
39
53
  }
54
+ export function withDecoratorFactory() {
55
+ return function WithDecorator(Component, shouldDecorate) {
56
+ const createDecorator = createDecoratorFactory()(Component, shouldDecorate);
57
+ return Object.assign(Component, {
58
+ createDecorator
59
+ });
60
+ };
61
+ }
62
+ export function withHookDecoratorFactory() {
63
+ return function WithHookDecorator(hook) {
64
+ const createDecorator = createHookDecoratorFactory()(hook);
65
+ return Object.assign(hook, {
66
+ createDecorator
67
+ });
68
+ };
69
+ }
40
70
 
41
71
  //# sourceMappingURL=decorators.js.map
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","Compose","createConditionalDecorator","shouldDecorate","decorator","decoratorProps","Original","DecoratedComponent","memo","displayName","ShouldDecorate","props","createElement","memoizedComponent","decoratee","createDecoratorFactory","from","decoratable","createDecorator","DecoratorPlugin","componentDecorator","function","with","createHookDecoratorFactory","withDecoratorFactory","WithDecorator","Component","Object","assign","withHookDecoratorFactory","WithHookDecorator","hook"],"sources":["decorators.tsx"],"sourcesContent":["import React from \"react\";\nimport { Compose } from \"~/Compose.js\";\nimport type { GetDecoratee, GetDecorateeParams } from \"~/createDecorator.js\";\nimport type {\n DecoratableComponent,\n GenericComponent,\n Decorator,\n GenericHook,\n DecoratableHook,\n ComponentDecorator\n} from \"~/types.js\";\n\nexport interface ShouldDecorate<TDecorator = any, TComponent = any> {\n (decoratorProps: TDecorator, componentProps: TComponent): boolean;\n}\n\nexport function createConditionalDecorator<TDecoratee extends GenericComponent>(\n shouldDecorate: ShouldDecorate,\n decorator: Decorator<TDecoratee>,\n decoratorProps: unknown\n): Decorator<TDecoratee> {\n return (Original => {\n const DecoratedComponent = React.memo(decorator(Original));\n DecoratedComponent.displayName = Original.displayName;\n\n return function ShouldDecorate(props: unknown) {\n if (shouldDecorate(decoratorProps, props)) {\n // @ts-expect-error\n return <DecoratedComponent {...props} />;\n }\n\n // @ts-expect-error\n return <Original {...props} />;\n };\n }) as Decorator<TDecoratee>;\n}\n\nconst memoizedComponent = <T extends GenericComponent>(decorator: Decorator<T>) => {\n return (decoratee: T) => {\n return React.memo(decorator(decoratee));\n };\n};\n\nexport function createDecoratorFactory<TDecorator>() {\n return function from<TDecoratable extends DecoratableComponent>(\n decoratable: TDecoratable,\n shouldDecorate?: ShouldDecorate<TDecorator, GetDecorateeParams<GetDecoratee<TDecoratable>>>\n ) {\n return function createDecorator(decorator: ComponentDecorator<GetDecoratee<TDecoratable>>) {\n return function DecoratorPlugin(props: TDecorator) {\n if (shouldDecorate) {\n const componentDecorator = createConditionalDecorator<GenericComponent>(\n shouldDecorate,\n decorator as unknown as Decorator<GenericComponent>,\n props\n );\n\n return <Compose function={decoratable} with={componentDecorator} />;\n }\n\n return (\n <Compose\n function={decoratable}\n with={memoizedComponent(\n decorator as unknown as Decorator<GenericComponent>\n )}\n />\n );\n };\n };\n };\n}\n\nexport function createHookDecoratorFactory() {\n return function from<TDecoratable extends DecoratableHook>(decoratable: TDecoratable) {\n return function createDecorator(decorator: Decorator<GetDecoratee<TDecoratable>>) {\n return function DecoratorPlugin() {\n return (\n <Compose\n function={decoratable}\n with={decorator as unknown as Decorator<GenericHook>}\n />\n );\n };\n };\n };\n}\n\nexport function withDecoratorFactory<TDecorator>() {\n return function WithDecorator<TDecoratable extends DecoratableComponent>(\n Component: TDecoratable,\n shouldDecorate?: ShouldDecorate<TDecorator, GetDecorateeParams<GetDecoratee<TDecoratable>>>\n ) {\n const createDecorator = createDecoratorFactory<TDecorator>()(Component, shouldDecorate);\n\n return Object.assign(Component, { createDecorator }) as TDecoratable & {\n createDecorator: typeof createDecorator;\n };\n };\n}\n\nexport function withHookDecoratorFactory() {\n return function WithHookDecorator<TDecoratable extends DecoratableHook>(hook: TDecoratable) {\n const createDecorator = createHookDecoratorFactory()(hook);\n\n return Object.assign(hook, { createDecorator }) as unknown as DecoratableHook<\n GenericHook<\n GetDecorateeParams<GetDecoratee<TDecoratable>>,\n ReturnType<GetDecoratee<TDecoratable>>\n >\n > & { createDecorator: typeof createDecorator };\n };\n}\n"],"mappings":"AAAA,OAAOA,KAAK,MAAM,OAAO;AACzB,S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;QAAE,CACL,CAAC;MAEV,CAAC;IACL,CAAC;EACL,CAAC;AACL;AAEA,OAAO,SAASmB,0BAA0BA,CAAA,EAAG;EACzC,OAAO,SAASP,IAAIA,CAAuCC,WAAyB,EAAE;IAClF,OAAO,SAASC,eAAeA,CAACd,SAAgD,EAAE;MAC9E,OAAO,SAASe,eAAeA,CAAA,EAAG;QAC9B,oBACInB,KAAA,CAAAY,aAAA,CAACX,OAAO;UACJoB,QAAQ,EAAEJ,WAAY;UACtBK,IAAI,EAAElB;QAA+C,CACxD,CAAC;MAEV,CAAC;IACL,CAAC;EACL,CAAC;AACL;AAEA,OAAO,SAASoB,oBAAoBA,CAAA,EAAe;EAC/C,OAAO,SAASC,aAAaA,CACzBC,SAAuB,EACvBvB,cAA2F,EAC7F;IACE,MAAMe,eAAe,GAAGH,sBAAsB,CAAa,CAAC,CAACW,SAAS,EAAEvB,cAAc,CAAC;IAEvF,OAAOwB,MAAM,CAACC,MAAM,CAACF,SAAS,EAAE;MAAER;IAAgB,CAAC,CAAC;EAGxD,CAAC;AACL;AAEA,OAAO,SAASW,wBAAwBA,CAAA,EAAG;EACvC,OAAO,SAASC,iBAAiBA,CAAuCC,IAAkB,EAAE;IACxF,MAAMb,eAAe,GAAGK,0BAA0B,CAAC,CAAC,CAACQ,IAAI,CAAC;IAE1D,OAAOJ,MAAM,CAACC,MAAM,CAACG,IAAI,EAAE;MAAEb;IAAgB,CAAC,CAAC;EAMnD,CAAC;AACL","ignoreList":[]}
package/index.d.ts CHANGED
@@ -1,6 +1,8 @@
1
- export * from "./Context";
2
- export * from "./Compose";
3
- export * from "./makeComposable";
4
- export * from "./createComponentPlugin";
5
- export * from "./decorators";
6
- export * from "./CompositionScope";
1
+ export * from "./Context.js";
2
+ export * from "./Compose.js";
3
+ export * from "./makeComposable.js";
4
+ export * from "./makeDecoratable.js";
5
+ export * from "./createDecorator.js";
6
+ export * from "./decorators.js";
7
+ export * from "./CompositionScope.js";
8
+ export type * from "./types.js";
package/index.js CHANGED
@@ -1,73 +1,9 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- var _Context = require("./Context");
7
- Object.keys(_Context).forEach(function (key) {
8
- if (key === "default" || key === "__esModule") return;
9
- if (key in exports && exports[key] === _Context[key]) return;
10
- Object.defineProperty(exports, key, {
11
- enumerable: true,
12
- get: function get() {
13
- return _Context[key];
14
- }
15
- });
16
- });
17
- var _Compose = require("./Compose");
18
- Object.keys(_Compose).forEach(function (key) {
19
- if (key === "default" || key === "__esModule") return;
20
- if (key in exports && exports[key] === _Compose[key]) return;
21
- Object.defineProperty(exports, key, {
22
- enumerable: true,
23
- get: function get() {
24
- return _Compose[key];
25
- }
26
- });
27
- });
28
- var _makeComposable = require("./makeComposable");
29
- Object.keys(_makeComposable).forEach(function (key) {
30
- if (key === "default" || key === "__esModule") return;
31
- if (key in exports && exports[key] === _makeComposable[key]) return;
32
- Object.defineProperty(exports, key, {
33
- enumerable: true,
34
- get: function get() {
35
- return _makeComposable[key];
36
- }
37
- });
38
- });
39
- var _createComponentPlugin = require("./createComponentPlugin");
40
- Object.keys(_createComponentPlugin).forEach(function (key) {
41
- if (key === "default" || key === "__esModule") return;
42
- if (key in exports && exports[key] === _createComponentPlugin[key]) return;
43
- Object.defineProperty(exports, key, {
44
- enumerable: true,
45
- get: function get() {
46
- return _createComponentPlugin[key];
47
- }
48
- });
49
- });
50
- var _decorators = require("./decorators");
51
- Object.keys(_decorators).forEach(function (key) {
52
- if (key === "default" || key === "__esModule") return;
53
- if (key in exports && exports[key] === _decorators[key]) return;
54
- Object.defineProperty(exports, key, {
55
- enumerable: true,
56
- get: function get() {
57
- return _decorators[key];
58
- }
59
- });
60
- });
61
- var _CompositionScope = require("./CompositionScope");
62
- Object.keys(_CompositionScope).forEach(function (key) {
63
- if (key === "default" || key === "__esModule") return;
64
- if (key in exports && exports[key] === _CompositionScope[key]) return;
65
- Object.defineProperty(exports, key, {
66
- enumerable: true,
67
- get: function get() {
68
- return _CompositionScope[key];
69
- }
70
- });
71
- });
1
+ export * from "./Context.js";
2
+ export * from "./Compose.js";
3
+ export * from "./makeComposable.js";
4
+ export * from "./makeDecoratable.js";
5
+ export * from "./createDecorator.js";
6
+ export * from "./decorators.js";
7
+ export * from "./CompositionScope.js";
72
8
 
73
9
  //# 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":";;;;;AAAA,IAAAA,QAAA,GAAAC,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAH,QAAA,EAAAI,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAL,QAAA,CAAAK,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAT,QAAA,CAAAK,GAAA;IAAA;EAAA;AAAA;AACA,IAAAK,QAAA,GAAAT,OAAA;AAAAC,MAAA,CAAAC,IAAA,CAAAO,QAAA,EAAAN,OAAA,WAAAC,GAAA;EAAA,IAAAA,GAAA,kBAAAA,GAAA;EAAA,IAAAA,GAAA,IAAAC,OAAA,IAAAA,OAAA,CAAAD,GAAA,MAAAK,QAAA,CAAAL,GAAA;EAAAH,MAAA,CAAAK,cAAA,CAAAD,OAAA,EAAAD,GAAA;IAAAG,UAAA;IAAAC,GAAA,WAAAA,IAAA;MAAA,OAAAC,QAAA,CAAAL,GAAA;IAAA;EAAA;AAAA;AACA,IAAA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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":[],"sources":["index.ts"],"sourcesContent":["export * from \"./Context.js\";\nexport * from \"./Compose.js\";\nexport * from \"./makeComposable.js\";\nexport * from \"./makeDecoratable.js\";\nexport * from \"./createDecorator.js\";\nexport * from \"./decorators.js\";\nexport * from \"./CompositionScope.js\";\nexport type * from \"./types.js\";\n"],"mappings":"AAAA;AACA;AACA;AACA;AACA;AACA;AACA","ignoreList":[]}
@@ -1,5 +1,43 @@
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>;
1
+ import type { GenericComponent } from "./types.js";
2
+ /**
3
+ * @deprecated Use `makeDecoratable` instead.
4
+ */
5
+ export declare function makeComposable<T extends GenericComponent>(name: string, Component?: T): (((() => null) | T) & {
6
+ original: (() => null) | T;
4
7
  originalName: string;
8
+ displayName: string;
9
+ }) & {
10
+ original: ((() => null) | T) & {
11
+ original: (() => null) | T;
12
+ originalName: string;
13
+ displayName: string;
14
+ };
15
+ originalName: string;
16
+ displayName: string;
17
+ } & {
18
+ createDecorator: (decorator: import("~/types.js").ComponentDecorator<import("./createDecorator").GetDecoratee<(() => null) & {
19
+ original: (() => null) | T;
20
+ originalName: string;
21
+ displayName: string;
22
+ } & {
23
+ original: ((() => null) | T) & {
24
+ original: (() => null) | T;
25
+ originalName: string;
26
+ displayName: string;
27
+ };
28
+ originalName: string;
29
+ displayName: string;
30
+ }> | import("./createDecorator").GetDecoratee<T & {
31
+ original: (() => null) | T;
32
+ originalName: string;
33
+ displayName: string;
34
+ } & {
35
+ original: ((() => null) | T) & {
36
+ original: (() => null) | T;
37
+ originalName: string;
38
+ displayName: string;
39
+ };
40
+ originalName: string;
41
+ displayName: string;
42
+ }>>) => (props: unknown) => import("react").JSX.Element;
5
43
  };
package/makeComposable.js CHANGED
@@ -1,59 +1,14 @@
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.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");
14
- var ComposableContext = /*#__PURE__*/(0, _react.createContext)([]);
1
+ import { createContext } from "react";
2
+ import { makeDecoratable } from "./makeDecoratable.js";
3
+ const ComposableContext = /*#__PURE__*/createContext([]);
15
4
  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];
37
- };
38
- 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;
5
+ const nullRenderer = () => null;
6
+
7
+ /**
8
+ * @deprecated Use `makeDecoratable` instead.
9
+ */
10
+ export function makeComposable(name, Component) {
11
+ return makeDecoratable(name, Component ?? nullRenderer);
57
12
  }
58
13
 
59
14
  //# 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,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,mBAAmB,GAAG,SAAtBA,mBAAmBA,CAAIC,IAAY,EAAK;EAC1C,OAAO,IAAAC,gBAAA,CAAAC,OAAA,MACFF,IAAI,EAAG,YAAY;IAChB,IAAAG,gBAAS,EAAC,YAAM;MACZ;MACA;MACA,IAAMC,SAAS,GAAG,IAAAC,iBAAQ,EAAC,YAAM;QAC7BC,OAAO,CAACC,IAAI,KAAAC,MAAA,CACJR,IAAI,uFACZ,CAAC;MACL,CAAC,EAAE,GAAG,CAAC;MAEP,OAAO,YAAM;QACTI,SAAS,CAACK,MAAM,CAAC,CAAC;MACtB,CAAC;IACL,CAAC,EAAE,EAAE,CAAC;IAEN,OAAO,IAAI;EACf,CAAC,EACHT,IAAI,CAAC;AACX,CAAC;AAEM,SAASU,cAAcA,CAASV,IAAY,EAAEW,SAAuC,EAAE;EAC1F,IAAI,CAACA,SAAS,EAAE;IACZA,SAAS,GAAGZ,mBAAmB,CAACC,IAAI,CAAC;EACzC;EAEA,IAAMY,UAAgC,GAAG,SAAnCA,UAAgCA,CAAGC,KAAK,EAAI;IAC9C,IAAMC,OAAO,GAAGlB,oBAAoB,CAAC,CAAC;IACtC,IAAMmB,iBAAiB,GAAG,IAAAC,qBAAY,EAACL,SAAwC,CAAC;IAEhF,IAAMd,OAAO,GAAG,IAAAoB,cAAO,EAAC;MAAA,UAAAT,MAAA,KAAAU,mBAAA,CAAAhB,OAAA,EAAUY,OAAO,IAAEd,IAAI;IAAA,CAAC,EAAE,CAACc,OAAO,EAAEd,IAAI,CAAC,CAAC;IAElE,oBACIb,MAAA,CAAAe,OAAA,CAAAiB,aAAA,CAAC1B,iBAAiB,CAAC2B,QAAQ;MAACC,KAAK,EAAExB;IAAQ,gBACvCV,MAAA,CAAAe,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":["createContext","makeDecoratable","ComposableContext","displayName","nullRenderer","makeComposable","name","Component"],"sources":["makeComposable.tsx"],"sourcesContent":["import { createContext } from \"react\";\nimport type { GenericComponent } from \"~/types.js\";\nimport { makeDecoratable } from \"~/makeDecoratable.js\";\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,SAASA,aAAa,QAAQ,OAAO;AAErC,SAASC,eAAe;AAExB,MAAMC,iBAAiB,gBAAGF,aAAa,CAAW,EAAE,CAAC;AACrDE,iBAAiB,CAACC,WAAW,GAAG,mBAAmB;AAEnD,MAAMC,YAAY,GAAGA,CAAA,KAAM,IAAI;;AAE/B;AACA;AACA;AACA,OAAO,SAASC,cAAcA,CAA6BC,IAAY,EAAEC,SAAa,EAAE;EACpF,OAAON,eAAe,CAACK,IAAI,EAAEC,SAAS,IAAIH,YAAY,CAAC;AAC3D","ignoreList":[]}
@@ -0,0 +1,31 @@
1
+ import React from "react";
2
+ import type { DecoratableComponent, DecoratableHook, GenericComponent, GenericHook } from "./types.js";
3
+ declare function makeDecoratableComponent<T extends GenericComponent>(name: string, Component?: T): T & {
4
+ original: T;
5
+ originalName: string;
6
+ displayName: string;
7
+ } & {
8
+ original: T & {
9
+ original: T;
10
+ originalName: string;
11
+ displayName: string;
12
+ };
13
+ originalName: string;
14
+ displayName: string;
15
+ } & {
16
+ createDecorator: (decorator: import("~/types.js").ComponentDecorator<import("./createDecorator.js").GetDecoratee<DecoratableComponent<T & {
17
+ original: T;
18
+ originalName: string;
19
+ displayName: string;
20
+ }>>>) => (props: unknown) => React.JSX.Element;
21
+ };
22
+ export declare function makeDecoratableHook<T extends GenericHook>(hook: T): GenericHook<import("./createDecorator.js").GetDecorateeParams<import("./createDecorator.js").GetDecoratee<DecoratableHook<T>>>, ReturnType<import("./createDecorator.js").GetDecoratee<DecoratableHook<T>>>> & {
23
+ original: GenericHook<import("./createDecorator.js").GetDecorateeParams<import("./createDecorator.js").GetDecoratee<DecoratableHook<T>>>, ReturnType<import("./createDecorator.js").GetDecoratee<DecoratableHook<T>>>>;
24
+ originalName: string;
25
+ } & {
26
+ createDecorator: (decorator: import("~/types.js").Decorator<import("./createDecorator.js").GetDecoratee<DecoratableHook<T>>>) => () => React.JSX.Element;
27
+ };
28
+ export declare function createVoidComponent<T>(): (props: T) => JSX.Element | null;
29
+ export declare function makeDecoratable<T extends GenericHook>(hook: T): ReturnType<typeof makeDecoratableHook<T>>;
30
+ export declare function makeDecoratable<T extends GenericComponent>(name: string, Component: T): ReturnType<typeof makeDecoratableComponent<T>>;
31
+ export {};
@@ -0,0 +1,53 @@
1
+ import React, { createContext, useContext, useMemo } from "react";
2
+ import { useComponent } from "./Context.js";
3
+ import { withDecoratorFactory, withHookDecoratorFactory } from "./decorators.js";
4
+ const ComposableContext = /*#__PURE__*/createContext([]);
5
+ ComposableContext.displayName = "ComposableContext";
6
+ function useComposableParents() {
7
+ const context = useContext(ComposableContext);
8
+ if (!context) {
9
+ return [];
10
+ }
11
+ return context;
12
+ }
13
+ const nullRenderer = () => null;
14
+ function makeDecoratableComponent(name, Component = nullRenderer) {
15
+ const Decoratable = props => {
16
+ const parents = useComposableParents();
17
+ const ComposedComponent = useComponent(Component);
18
+ const context = useMemo(() => [...parents, name], [parents, name]);
19
+ return /*#__PURE__*/React.createElement(ComposableContext.Provider, {
20
+ value: context
21
+ }, /*#__PURE__*/React.createElement(ComposedComponent, props, props.children));
22
+ };
23
+ const staticProps = {
24
+ original: Component,
25
+ originalName: name,
26
+ displayName: `Decoratable<${name}>`
27
+ };
28
+ return withDecoratorFactory()(Object.assign(Decoratable, staticProps));
29
+ }
30
+ export function makeDecoratableHook(hook) {
31
+ const decoratableHook = params => {
32
+ const composedHook = useComponent(hook);
33
+ return composedHook(params);
34
+ };
35
+ decoratableHook.original = hook;
36
+ return withHookDecoratorFactory()(decoratableHook);
37
+ }
38
+ export function createVoidComponent() {
39
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
40
+ return props => {
41
+ return null;
42
+ };
43
+ }
44
+ export function makeDecoratable(hookOrName, Component) {
45
+ if (Component) {
46
+ const component = makeDecoratableComponent(hookOrName, /*#__PURE__*/React.memo(Component));
47
+ component.original.displayName = hookOrName;
48
+ return component;
49
+ }
50
+ return makeDecoratableHook(hookOrName);
51
+ }
52
+
53
+ //# sourceMappingURL=makeDecoratable.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["React","createContext","useContext","useMemo","useComponent","withDecoratorFactory","withHookDecoratorFactory","ComposableContext","displayName","useComposableParents","context","nullRenderer","makeDecoratableComponent","name","Component","Decoratable","props","parents","ComposedComponent","createElement","Provider","value","children","staticProps","original","originalName","Object","assign","makeDecoratableHook","hook","decoratableHook","params","composedHook","createVoidComponent","makeDecoratable","hookOrName","component","memo"],"sources":["makeDecoratable.tsx"],"sourcesContent":["import React, { createContext, useContext, useMemo } from \"react\";\nimport { useComponent } from \"./Context.js\";\nimport type {\n DecoratableComponent,\n DecoratableHook,\n GenericComponent,\n GenericHook\n} from \"~/types.js\";\nimport { withDecoratorFactory, withHookDecoratorFactory } from \"~/decorators.js\";\n\nconst ComposableContext = createContext<string[]>([]);\nComposableContext.displayName = \"ComposableContext\";\n\nfunction useComposableParents() {\n const context = useContext(ComposableContext);\n if (!context) {\n return [];\n }\n\n return context;\n}\n\nconst nullRenderer = () => null;\n\nfunction makeDecoratableComponent<T extends GenericComponent>(\n name: string,\n Component: T = nullRenderer as unknown as T\n) {\n const Decoratable = (props: React.ComponentProps<T>): JSX.Element | null => {\n const parents = useComposableParents();\n const ComposedComponent = useComponent(Component) as GenericComponent<\n React.ComponentProps<T>\n >;\n\n const context = useMemo(() => [...parents, name], [parents, name]);\n\n return (\n <ComposableContext.Provider value={context}>\n <ComposedComponent {...props}>{props.children}</ComposedComponent>\n </ComposableContext.Provider>\n );\n };\n\n const staticProps = {\n original: Component,\n originalName: name,\n displayName: `Decoratable<${name}>`\n };\n\n return withDecoratorFactory()(\n Object.assign(Decoratable, staticProps) as DecoratableComponent<\n typeof Component & typeof staticProps\n >\n );\n}\n\nexport function makeDecoratableHook<T extends GenericHook>(hook: T) {\n const decoratableHook = (params: Parameters<T>) => {\n const composedHook = useComponent(hook);\n\n return composedHook(params) as DecoratableHook<T>;\n };\n\n decoratableHook.original = hook;\n\n return withHookDecoratorFactory()(decoratableHook as DecoratableHook<T>);\n}\n\nexport function createVoidComponent<T>() {\n // eslint-disable-next-line @typescript-eslint/no-unused-vars\n return (props: T): JSX.Element | null => {\n return null;\n };\n}\n\nexport function makeDecoratable<T extends GenericHook>(\n hook: T\n): ReturnType<typeof makeDecoratableHook<T>>;\nexport function makeDecoratable<T extends GenericComponent>(\n name: string,\n Component: T\n): ReturnType<typeof makeDecoratableComponent<T>>;\nexport function makeDecoratable(hookOrName: any, Component?: any) {\n if (Component) {\n const component = makeDecoratableComponent(hookOrName, React.memo(Component));\n component.original.displayName = hookOrName;\n return component;\n }\n\n return makeDecoratableHook(hookOrName);\n}\n"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,aAAa,EAAEC,UAAU,EAAEC,OAAO,QAAQ,OAAO;AACjE,SAASC,YAAY;AAOrB,SAASC,oBAAoB,EAAEC,wBAAwB;AAEvD,MAAMC,iBAAiB,gBAAGN,aAAa,CAAW,EAAE,CAAC;AACrDM,iBAAiB,CAACC,WAAW,GAAG,mBAAmB;AAEnD,SAASC,oBAAoBA,CAAA,EAAG;EAC5B,MAAMC,OAAO,GAAGR,UAAU,CAACK,iBAAiB,CAAC;EAC7C,IAAI,CAACG,OAAO,EAAE;IACV,OAAO,EAAE;EACb;EAEA,OAAOA,OAAO;AAClB;AAEA,MAAMC,YAAY,GAAGA,CAAA,KAAM,IAAI;AAE/B,SAASC,wBAAwBA,CAC7BC,IAAY,EACZC,SAAY,GAAGH,YAA4B,EAC7C;EACE,MAAMI,WAAW,GAAIC,KAA8B,IAAyB;IACxE,MAAMC,OAAO,GAAGR,oBAAoB,CAAC,CAAC;IACtC,MAAMS,iBAAiB,GAAGd,YAAY,CAACU,SAAS,CAE/C;IAED,MAAMJ,OAAO,GAAGP,OAAO,CAAC,MAAM,CAAC,GAAGc,OAAO,EAAEJ,IAAI,CAAC,EAAE,CAACI,OAAO,EAAEJ,IAAI,CAAC,CAAC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0.0.0-unstable.de38392959",
3
+ "version": "0.0.0-unstable.df7a8bb475",
4
+ "type": "module",
4
5
  "main": "index.js",
5
6
  "repository": {
6
7
  "type": "git",
@@ -14,29 +15,19 @@
14
15
  ],
15
16
  "license": "MIT",
16
17
  "dependencies": {
17
- "@babel/runtime": "7.22.6",
18
- "@types/react": "17.0.39",
19
- "lodash": "4.17.21",
20
- "react": "17.0.2",
21
- "react-dom": "17.0.2"
18
+ "@types/react": "18.2.79",
19
+ "react": "18.2.0",
20
+ "react-dom": "18.2.0"
22
21
  },
23
22
  "devDependencies": {
24
- "@babel/cli": "7.22.6",
25
- "@babel/core": "7.22.8",
26
- "@babel/preset-env": "7.22.7",
27
- "@babel/preset-typescript": "7.22.5",
28
- "@webiny/cli": "0.0.0-unstable.de38392959",
29
- "@webiny/project-utils": "0.0.0-unstable.de38392959",
30
- "ttypescript": "1.5.15",
31
- "typescript": "4.7.4"
23
+ "@testing-library/react": "15.0.7",
24
+ "@webiny/build-tools": "0.0.0-unstable.df7a8bb475",
25
+ "typescript": "5.9.3",
26
+ "vitest": "3.2.4"
32
27
  },
33
28
  "publishConfig": {
34
29
  "access": "public",
35
30
  "directory": "dist"
36
31
  },
37
- "scripts": {
38
- "build": "yarn webiny run build",
39
- "watch": "yarn webiny run watch"
40
- },
41
- "gitHead": "de38392959f2692d1feb08945a3588cd80e4924c"
32
+ "gitHead": "df7a8bb4755a1da047f0af8c56bdb649cc81bf7d"
42
33
  }
package/types.d.ts ADDED
@@ -0,0 +1,35 @@
1
+ import type React from "react";
2
+ export type GenericHook<TParams = any, TReturn = any> = (...args: TParams[]) => TReturn;
3
+ export type GenericComponent<T = any> = React.FunctionComponent<T>;
4
+ export type ComposedFunction = GenericHook;
5
+ export type Decorator<T> = (decoratee: T) => T;
6
+ /**
7
+ * Some decoratable components will always return `null`, by design.
8
+ * To allow you to decorate these components, we must tell TS that the decorator is allowed to return not just `null`
9
+ * (which is inferred from the component type), but also a JSX.Element.
10
+ */
11
+ export type ComponentDecorator<T> = (decoratee: T) => CanReturnNullOrElement<T>;
12
+ /**
13
+ * @deprecated
14
+ */
15
+ export type ComposableFC<T> = T & {
16
+ displayName?: string;
17
+ original: T;
18
+ originalName: string;
19
+ };
20
+ export type Enumerable<T> = T extends Array<infer D> ? Array<D> : never;
21
+ export type ComposeWith = Decorator<GenericComponent> | Decorator<GenericComponent>[] | Decorator<GenericHook> | Decorator<GenericHook>[];
22
+ export type DecoratableHook<T extends GenericHook = GenericHook> = T & {
23
+ original: T;
24
+ originalName: string;
25
+ };
26
+ export type DecoratableComponent<T = GenericComponent> = T & {
27
+ original: T;
28
+ originalName: string;
29
+ displayName: string;
30
+ };
31
+ export type Decoratable = DecoratableComponent | DecoratableHook;
32
+ /**
33
+ * @internal Add `null` to the ReturnType of the given function.
34
+ */
35
+ export type CanReturnNullOrElement<T> = T extends (...args: any) => any ? (...args: Parameters<T>) => JSX.Element | null : never;
package/types.js ADDED
@@ -0,0 +1,3 @@
1
+ export {};
2
+
3
+ //# sourceMappingURL=types.js.map
package/types.js.map ADDED
@@ -0,0 +1 @@
1
+ {"version":3,"names":[],"sources":["types.ts"],"sourcesContent":["import type React from \"react\";\n\nexport type GenericHook<TParams = any, TReturn = any> = (...args: TParams[]) => TReturn;\n\nexport type GenericComponent<T = any> = React.FunctionComponent<T>;\n\nexport type ComposedFunction = GenericHook;\n\nexport type Decorator<T> = (decoratee: T) => T;\n\n/**\n * Some decoratable components will always return `null`, by design.\n * To allow you to decorate these components, we must tell TS that the decorator is allowed to return not just `null`\n * (which is inferred from the component type), but also a JSX.Element.\n */\nexport type ComponentDecorator<T> = (decoratee: T) => CanReturnNullOrElement<T>;\n\n/**\n * @deprecated\n */\nexport type ComposableFC<T> = T & {\n displayName?: string;\n original: T;\n originalName: string;\n};\n\nexport type Enumerable<T> = T extends Array<infer D> ? Array<D> : never;\n\nexport type ComposeWith =\n | Decorator<GenericComponent>\n | Decorator<GenericComponent>[]\n | Decorator<GenericHook>\n | Decorator<GenericHook>[];\n\nexport type DecoratableHook<T extends GenericHook = GenericHook> = T & {\n original: T;\n originalName: string;\n};\n\nexport type DecoratableComponent<T = GenericComponent> = T & {\n original: T;\n originalName: string;\n displayName: string;\n};\n\nexport type Decoratable = DecoratableComponent | DecoratableHook;\n\n/**\n * @internal Add `null` to the ReturnType of the given function.\n */\nexport type CanReturnNullOrElement<T> = T extends (...args: any) => any\n ? (...args: Parameters<T>) => JSX.Element | null\n : never;\n"],"mappings":"","ignoreList":[]}
@@ -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,26 +0,0 @@
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
- var _react = _interopRequireDefault(require("react"));
9
- var _index = require("./index");
10
- /**
11
- * Creates a component which, when mounted, registers a Higher Order Component for the given base component.
12
- * This is particularly useful for decorating (wrapping) existing composable components.
13
- * For more information, visit https://www.webiny.com/docs/admin-area/basics/framework.
14
- */
15
- function createComponentPlugin(Base, hoc) {
16
- var ComponentPlugin = function ComponentPlugin() {
17
- return /*#__PURE__*/_react.default.createElement(_index.Compose, {
18
- component: Base,
19
- with: hoc
20
- });
21
- };
22
- ComponentPlugin.displayName = Base.displayName;
23
- return ComponentPlugin;
24
- }
25
-
26
- //# sourceMappingURL=createComponentPlugin.js.map
@@ -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"}