1 |
|
2 | "use strict";
|
3 | var __extends = (this && this.__extends) || (function () {
|
4 | var extendStatics = function (d, b) {
|
5 | extendStatics = Object.setPrototypeOf ||
|
6 | ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
7 | function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
|
8 | return extendStatics(d, b);
|
9 | };
|
10 | return function (d, b) {
|
11 | extendStatics(d, b);
|
12 | function __() { this.constructor = d; }
|
13 | d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
14 | };
|
15 | })();
|
16 | Object.defineProperty(exports, "__esModule", { value: true });
|
17 | var ag_grid_community_1 = require("ag-grid-community");
|
18 | var utils_1 = require("./utils");
|
19 | var BaseReactComponent = (function () {
|
20 | function BaseReactComponent() {
|
21 | }
|
22 | return BaseReactComponent;
|
23 | }());
|
24 | var ReactComponent = (function (_super) {
|
25 | __extends(ReactComponent, _super);
|
26 | function ReactComponent(reactComponent, portalManager, componentType) {
|
27 | var _this = _super.call(this) || this;
|
28 | _this.portal = null;
|
29 | _this.reactComponent = reactComponent;
|
30 | _this.portalManager = portalManager;
|
31 | _this.componentType = componentType;
|
32 | _this.statelessComponent = _this.isStateless(_this.reactComponent);
|
33 | return _this;
|
34 | }
|
35 | ReactComponent.prototype.getGui = function () {
|
36 | return this.eParentElement;
|
37 | };
|
38 | ReactComponent.prototype.destroy = function () {
|
39 | if (this.componentInstance && typeof this.componentInstance.destroy == 'function') {
|
40 | this.componentInstance.destroy();
|
41 | }
|
42 | return this.portalManager.destroyPortal(this.portal);
|
43 | };
|
44 | ReactComponent.prototype.createParentElement = function (params) {
|
45 | var componentWrappingElement = this.portalManager.getComponentWrappingElement();
|
46 | var eParentElement = document.createElement(componentWrappingElement || 'div');
|
47 | ag_grid_community_1._.addCssClass(eParentElement, 'ag-react-container');
|
48 |
|
49 |
|
50 | params.reactContainer = eParentElement;
|
51 | return eParentElement;
|
52 | };
|
53 | ReactComponent.prototype.addParentContainerStyleAndClasses = function () {
|
54 | var _this = this;
|
55 | if (!this.componentInstance) {
|
56 | return;
|
57 | }
|
58 | if (this.componentInstance.getReactContainerStyle && this.componentInstance.getReactContainerStyle()) {
|
59 | utils_1.assignProperties(this.eParentElement.style, this.componentInstance.getReactContainerStyle());
|
60 | }
|
61 | if (this.componentInstance.getReactContainerClasses && this.componentInstance.getReactContainerClasses()) {
|
62 | var parentContainerClasses = this.componentInstance.getReactContainerClasses();
|
63 | parentContainerClasses.forEach(function (className) { return ag_grid_community_1._.addCssClass(_this.eParentElement, className); });
|
64 | }
|
65 | };
|
66 | ReactComponent.prototype.statelessComponentRendered = function () {
|
67 |
|
68 | return this.eParentElement.childElementCount > 0 || this.eParentElement.childNodes.length > 0;
|
69 | };
|
70 | ReactComponent.prototype.getFrameworkComponentInstance = function () {
|
71 | return this.componentInstance;
|
72 | };
|
73 | ReactComponent.prototype.isStatelessComponent = function () {
|
74 | return this.statelessComponent;
|
75 | };
|
76 | ReactComponent.prototype.getReactComponentName = function () {
|
77 | return this.reactComponent.name;
|
78 | };
|
79 | ReactComponent.prototype.getMemoType = function () {
|
80 | return this.hasSymbol() ? Symbol.for('react.memo') : 0xead3;
|
81 | };
|
82 | ReactComponent.prototype.hasSymbol = function () {
|
83 | return typeof Symbol === 'function' && Symbol.for;
|
84 | };
|
85 | ReactComponent.prototype.isStateless = function (Component) {
|
86 | return (typeof Component === 'function' && !(Component.prototype && Component.prototype.isReactComponent))
|
87 | || (typeof Component === 'object' && Component.$$typeof === this.getMemoType());
|
88 | };
|
89 | ReactComponent.prototype.hasMethod = function (name) {
|
90 | var frameworkComponentInstance = this.getFrameworkComponentInstance();
|
91 | return (!!frameworkComponentInstance && frameworkComponentInstance[name] !== null) ||
|
92 | this.fallbackMethodAvailable(name);
|
93 | };
|
94 | ReactComponent.prototype.callMethod = function (name, args) {
|
95 | var _this = this;
|
96 | var frameworkComponentInstance = this.getFrameworkComponentInstance();
|
97 | if (this.isStatelessComponent()) {
|
98 | return this.fallbackMethod(name, !!args && args[0] ? args[0] : {});
|
99 | }
|
100 | else if (!(!!frameworkComponentInstance)) {
|
101 |
|
102 | setTimeout(function () { return _this.callMethod(name, args); });
|
103 | return;
|
104 | }
|
105 | var method = frameworkComponentInstance[name];
|
106 | if (!!method) {
|
107 | return method.apply(frameworkComponentInstance, args);
|
108 | }
|
109 | if (this.fallbackMethodAvailable(name)) {
|
110 | return this.fallbackMethod(name, !!args && args[0] ? args[0] : {});
|
111 | }
|
112 | };
|
113 | ReactComponent.prototype.addMethod = function (name, callback) {
|
114 | this[name] = callback;
|
115 | };
|
116 | return ReactComponent;
|
117 | }(BaseReactComponent));
|
118 | exports.ReactComponent = ReactComponent;
|