ngx-reactify 0.0.2 → 0.1.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/esm2022/util/angular-to-react.mjs +233 -89
- package/esm2022/util/react-to-angular.mjs +42 -17
- package/fesm2022/ngx-reactify.mjs +273 -104
- package/fesm2022/ngx-reactify.mjs.map +1 -1
- package/package.json +1 -1
- package/util/angular-to-react.d.ts +134 -9
- package/util/angular-to-react.d.ts.map +1 -1
- package/util/react-to-angular.d.ts +33 -7
- package/util/react-to-angular.d.ts.map +1 -1
|
@@ -1,18 +1,143 @@
|
|
|
1
|
-
import { Type, ApplicationRef, Injector, NgZone } from '@angular/core';
|
|
1
|
+
import { Type, ApplicationRef, Injector, NgZone, Provider, EnvironmentProviders } from '@angular/core';
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
/**
|
|
4
|
-
* Wrap an
|
|
4
|
+
* Wrap an Angular component inside of a React memo object.
|
|
5
5
|
* Will attempt to bind @Input and @Output properties if provided,
|
|
6
6
|
* and will bind the react arguments directly as @Input properties.
|
|
7
7
|
*
|
|
8
|
+
* Usage: An Angular top-level application with a ReactifyNgComponent react implementation
|
|
9
|
+
* that needs to embed Angular components as children of the react-wrapped component.
|
|
10
|
+
*
|
|
11
|
+
* This is replaced by `WrapAngularComponentInReact`.
|
|
12
|
+
* @deprecated
|
|
13
|
+
*/
|
|
14
|
+
export declare const ReactifyAngularComponent: ({ component, appRef, injector, ngZone, staticInputs, staticOutputs, preSiblings, postSiblings, additionalChildren, rootElementName, containerElementName }: {
|
|
15
|
+
component: Type<any>;
|
|
16
|
+
appRef: Omit<ApplicationRef, '_runningTick'>;
|
|
17
|
+
injector: Injector;
|
|
18
|
+
ngZone: NgZone;
|
|
19
|
+
staticInputs?: {
|
|
20
|
+
[key: string]: any;
|
|
21
|
+
};
|
|
22
|
+
staticOutputs?: {
|
|
23
|
+
[key: string]: Function;
|
|
24
|
+
};
|
|
25
|
+
preSiblings?: React.ReactNode[];
|
|
26
|
+
postSiblings?: React.ReactNode[];
|
|
27
|
+
additionalChildren?: React.ReactNode[];
|
|
28
|
+
rootElementName?: Parameters<typeof React.createElement>[0];
|
|
29
|
+
containerElementName?: string;
|
|
30
|
+
}) => React.NamedExoticComponent<object>;
|
|
31
|
+
/**
|
|
32
|
+
* Do not use this.
|
|
33
|
+
* @hidden
|
|
34
|
+
* @experimental
|
|
35
|
+
*/
|
|
36
|
+
export declare const ng2ReactProps: (obj?: {}) => {};
|
|
37
|
+
/**
|
|
38
|
+
* This method will create a React component that
|
|
39
|
+
* wraps an Angular component.
|
|
40
|
+
* @returns React.NamedExoticComponent
|
|
41
|
+
*
|
|
42
|
+
* @hidden
|
|
43
|
+
* @experimental
|
|
44
|
+
*/
|
|
45
|
+
export declare function WrapAngularComponentInReact({ component, ngZone, appRef, injector, props, containerTag, reactTemplate, projectableNodes }: {
|
|
46
|
+
/**
|
|
47
|
+
* Angular Component to be rendered within React
|
|
48
|
+
*/
|
|
49
|
+
component: Type<any>;
|
|
50
|
+
/**
|
|
51
|
+
* Angular Application Reference. Used for bootstrapping
|
|
52
|
+
* and change detection hierarchy.
|
|
53
|
+
*/
|
|
54
|
+
appRef: Omit<ApplicationRef, '_runningTick'>;
|
|
55
|
+
/**
|
|
56
|
+
* Instance of NgZone class.
|
|
57
|
+
* Very important to prevent Zone.js event performance issues.
|
|
58
|
+
* Do not set if running Zoneless CD.
|
|
59
|
+
*/
|
|
60
|
+
ngZone?: NgZone;
|
|
61
|
+
/**
|
|
62
|
+
* Static properties to be passed into the Angular instance.
|
|
63
|
+
* Automatically generates event proxies for Angular EventEmitters.
|
|
64
|
+
*/
|
|
65
|
+
props?: Record<string, any>;
|
|
66
|
+
/**
|
|
67
|
+
* Local Element Injector provided to the Angular object
|
|
68
|
+
*/
|
|
69
|
+
injector?: Injector;
|
|
70
|
+
/**
|
|
71
|
+
* HTML Tag for the created DOM wrapper. Defaults to `div`.
|
|
72
|
+
*/
|
|
73
|
+
containerTag?: string;
|
|
74
|
+
/**
|
|
75
|
+
* React Function template
|
|
76
|
+
*/
|
|
77
|
+
reactTemplate?: (el: React.ReactElement) => React.ReactElement;
|
|
78
|
+
/**
|
|
79
|
+
* Nodes to be passed to the `ng-content` of the child Angular component.
|
|
80
|
+
*/
|
|
81
|
+
projectableNodes?: Node[][];
|
|
82
|
+
}): React.NamedExoticComponent<object>;
|
|
83
|
+
/**
|
|
84
|
+
* This method will automatically wrap an Angular
|
|
85
|
+
* Component or Directive into a React object.
|
|
86
|
+
* @Outputs (EventEmitters) will be automatically
|
|
87
|
+
* linked into the input properties along with
|
|
88
|
+
* all of the @Inputs.
|
|
89
|
+
* @returns React.NamedExoticComponent
|
|
8
90
|
* @experimental
|
|
9
|
-
* @param componentClass Angular component
|
|
10
|
-
* @param envInjector An `EnvironmentInjector` instance to be used for the component
|
|
11
|
-
* @param injector An `ElementInjector` instance
|
|
12
|
-
* @param _inputs
|
|
13
|
-
* @param _outputs
|
|
14
|
-
* @returns
|
|
15
91
|
*/
|
|
92
|
+
export declare const AutoWrapAngularObject: ({ component, appRef, ngZone, instance, injector, containerTag, reactTemplate, }: {
|
|
93
|
+
/**
|
|
94
|
+
* Angular Component to be rendered within React
|
|
95
|
+
*/
|
|
96
|
+
component: Type<any>;
|
|
97
|
+
/**
|
|
98
|
+
* Angular Application Reference. Used for bootstrapping
|
|
99
|
+
* and change detection hierarchy.
|
|
100
|
+
*/
|
|
101
|
+
appRef: Omit<ApplicationRef, '_runningTick'>;
|
|
102
|
+
/**
|
|
103
|
+
* Instance of NgZone class.
|
|
104
|
+
* Very important to prevent Zone.js event performance issues.
|
|
105
|
+
* Do not set if running Zoneless CD.
|
|
106
|
+
*/
|
|
107
|
+
ngZone?: NgZone;
|
|
108
|
+
/**
|
|
109
|
+
* Static properties to be passed into the Angular instance.
|
|
110
|
+
* Automatically generates event proxies for Angular EventEmitters.
|
|
111
|
+
*/
|
|
112
|
+
props?: Record<string, any>;
|
|
113
|
+
/**
|
|
114
|
+
* Local Element Injector provided to the Angular object
|
|
115
|
+
*/
|
|
116
|
+
injector?: Injector;
|
|
117
|
+
/**
|
|
118
|
+
* HTML Tag for the created DOM wrapper. Defaults to `div`.
|
|
119
|
+
*/
|
|
120
|
+
containerTag?: string;
|
|
121
|
+
/**
|
|
122
|
+
* React Function template
|
|
123
|
+
*/
|
|
124
|
+
reactTemplate?: (el: React.ReactElement) => React.ReactElement;
|
|
125
|
+
/**
|
|
126
|
+
* Nodes to be passed to the `ng-content` of the child Angular component.
|
|
127
|
+
*/
|
|
128
|
+
projectableNodes?: Node[][];
|
|
129
|
+
} & {
|
|
130
|
+
/**
|
|
131
|
+
* Angular Component/Directive instance that will have properties bound to the created
|
|
132
|
+
*/
|
|
133
|
+
instance?: InstanceType<Type<any>> | Record<string, any>;
|
|
134
|
+
}) => React.NamedExoticComponent<object>;
|
|
135
|
+
/**
|
|
136
|
+
* Bootstrap an Angular component with `createApplication` and export it under a
|
|
137
|
+
* react Element.
|
|
138
|
+
* Usage: React top-level application embedding an Angular component.
|
|
139
|
+
*/
|
|
140
|
+
export declare function ReactifyStandaloneAngularComponent(component: Type<any>, props?: any, providers?: (Provider | EnvironmentProviders)[], containerTag?: string): React.DOMElement<React.DOMAttributes<Element>, Element>;
|
|
16
141
|
export declare const ReactifyReactComponent: ({ component, appRef, injector, ngZone, staticInputs, staticOutputs, preSiblings, postSiblings, additionalChildren, rootElementName, containerElementName }: {
|
|
17
142
|
component: Type<any>;
|
|
18
143
|
appRef: Omit<ApplicationRef, '_runningTick'>;
|
|
@@ -30,5 +155,5 @@ export declare const ReactifyReactComponent: ({ component, appRef, injector, ngZ
|
|
|
30
155
|
rootElementName?: Parameters<typeof React.createElement>[0];
|
|
31
156
|
containerElementName?: string;
|
|
32
157
|
}) => React.NamedExoticComponent<object>;
|
|
33
|
-
export declare const
|
|
158
|
+
export declare const ReactifyAngularComponent3: typeof WrapAngularComponentInReact;
|
|
34
159
|
//# sourceMappingURL=angular-to-react.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"angular-to-react.d.ts","sourceRoot":"","sources":["../../../src/util/angular-to-react.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,EAAiC,MAAM,eAAe,CAAC;
|
|
1
|
+
{"version":3,"file":"angular-to-react.d.ts","sourceRoot":"","sources":["../../../src/util/angular-to-react.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,EAAiC,QAAQ,EAAE,oBAAoB,EAAgB,MAAM,eAAe,CAAC;AAEpJ,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B;;;;;;;;;;GAUG;AACH,eAAO,MAAM,wBAAwB;eAatB,KAAK,GAAG,CAAC;YACZ,KAAK,cAAc,EAAE,cAAc,CAAC;cAClC,QAAQ;YACV,MAAM;;;;;;;kBAGA,MAAM,SAAS,EAAE;mBAChB,MAAM,SAAS,EAAE;yBACX,MAAM,SAAS,EAAE;sBACpB,WAAW,OAAO,MAAM,aAAa,CAAC,CAAC,CAAC,CAAC;2BACpC,MAAM;wCAkG/B,CAAC;AAGH;;;;GAIG;AACH,eAAO,MAAM,aAAa,kBAezB,CAAC;AAEF;;;;;;;GAOG;AACH,wBAAgB,2BAA2B,CAAC,EACxC,SAAS,EACT,MAAM,EACN,MAAM,EACN,QAAQ,EACR,KAAK,EACL,YAAY,EACZ,aAAa,EACb,gBAAgB,EACnB,EAAE;IACC;;OAEG;IACH,SAAS,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;IACrB;;;OAGG;IACH,MAAM,EAAE,IAAI,CAAC,cAAc,EAAE,cAAc,CAAC,CAAC;IAC7C;;;;OAIG;IACH,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB;;;OAGG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC5B;;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oCAA8B,CAAC"}
|
|
@@ -2,22 +2,48 @@ import { AfterViewInit, NgZone, OnChanges, OnDestroy, SimpleChanges, ViewContain
|
|
|
2
2
|
import * as React from 'react';
|
|
3
3
|
import * as i0 from "@angular/core";
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
6
|
-
* bindings
|
|
5
|
+
* This component can be used to automatically wrap a React
|
|
6
|
+
* component into Angular bindings with functional change detection.
|
|
7
|
+
* All you need to provide is the @Input and @Output interface
|
|
8
|
+
* for the component in order to tell Angular which keys correspond to what.
|
|
9
|
+
*
|
|
10
|
+
* ### You _must_ override the property `ngReactComponent`.
|
|
7
11
|
*
|
|
8
|
-
* ! You _must_ override the property `ngReactComponent`
|
|
9
12
|
* Failure to do so will result in errors
|
|
10
|
-
*
|
|
13
|
+
*
|
|
14
|
+
* `override readonly ngReactComponent = SomeReactFunction;`
|
|
15
|
+
*
|
|
16
|
+
* Example:
|
|
17
|
+
*
|
|
18
|
+
* ```ts
|
|
19
|
+
* @Component({
|
|
20
|
+
* selector: "app-react-wrapped",
|
|
21
|
+
* standalone: true
|
|
22
|
+
* })
|
|
23
|
+
* export class MyReactWrappedComponent extends ReactifyNgComponent {
|
|
24
|
+
*
|
|
25
|
+
* @Input() data: any;
|
|
26
|
+
* @Input() options: any;
|
|
27
|
+
* @Input() version: any;
|
|
28
|
+
*
|
|
29
|
+
* // Notice how we wrap the result in an array, this is important because
|
|
30
|
+
* // React can pass multiple properties to a callback and Angular can't.
|
|
31
|
+
* @Output() onClick = new EventEmitter<[any]>();
|
|
32
|
+
*
|
|
33
|
+
* }
|
|
34
|
+
* ```
|
|
11
35
|
*/
|
|
12
36
|
export declare class ReactifyNgComponent implements OnChanges, OnDestroy, AfterViewInit {
|
|
13
|
-
|
|
14
|
-
|
|
37
|
+
protected readonly ngContainer: ViewContainerRef;
|
|
38
|
+
protected readonly ngZone: NgZone;
|
|
15
39
|
/**
|
|
16
40
|
* The react component to be wrapped.
|
|
17
41
|
* ! Must be overridden for this wrapper to work
|
|
18
42
|
*/
|
|
19
43
|
ngReactComponent: React.FunctionComponent<any> | React.ComponentClass<any>;
|
|
20
44
|
private _root;
|
|
45
|
+
private _reactElement;
|
|
46
|
+
private _props;
|
|
21
47
|
constructor(ngContainer: ViewContainerRef, ngZone: NgZone);
|
|
22
48
|
ngOnInit(): void;
|
|
23
49
|
ngOnChanges(changes?: SimpleChanges): void;
|
|
@@ -25,6 +51,6 @@ export declare class ReactifyNgComponent implements OnChanges, OnDestroy, AfterV
|
|
|
25
51
|
ngOnDestroy(): void;
|
|
26
52
|
private _render;
|
|
27
53
|
static ɵfac: i0.ɵɵFactoryDeclaration<ReactifyNgComponent, never>;
|
|
28
|
-
static ɵcmp: i0.ɵɵComponentDeclaration<ReactifyNgComponent, "
|
|
54
|
+
static ɵcmp: i0.ɵɵComponentDeclaration<ReactifyNgComponent, "ngx-reactify", never, {}, {}, never, never, true, never>;
|
|
29
55
|
}
|
|
30
56
|
//# sourceMappingURL=react-to-angular.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"react-to-angular.d.ts","sourceRoot":"","sources":["../../../src/util/react-to-angular.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,
|
|
1
|
+
{"version":3,"file":"react-to-angular.d.ts","sourceRoot":"","sources":["../../../src/util/react-to-angular.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAA2B,MAAM,EAAE,SAAS,EAAE,SAAS,EAAE,aAAa,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAC;AACtI,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;;AAI/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+BG;AACH,qBAKa,mBAAoB,YAAW,SAAS,EAAE,SAAS,EAAE,aAAa;IAevE,SAAS,CAAC,QAAQ,CAAC,WAAW,EAAE,gBAAgB;IAChD,SAAS,CAAC,QAAQ,CAAC,MAAM,EAAE,MAAM;IAdrC;;;OAGG;IACH,gBAAgB,EAAE,KAAK,CAAC,iBAAiB,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC,cAAc,CAAC,GAAG,CAAC,CAAC;IAE3E,OAAO,CAAC,KAAK,CAAO;IAEpB,OAAO,CAAC,aAAa,CAAqB;IAE1C,OAAO,CAAC,MAAM,CAAc;gBAGL,WAAW,EAAE,gBAAgB,EAC7B,MAAM,EAAE,MAAM;IAIrC,QAAQ;IAMR,WAAW,CAAC,OAAO,CAAC,EAAE,aAAa,GAAG,IAAI;IAI1C,eAAe;IAIf,WAAW;IAIX,OAAO,CAAC,OAAO;yCAtCN,mBAAmB;2CAAnB,mBAAmB;CA2E/B"}
|