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 react_1 = require("react");
|
18 | var react_dom_1 = require("react-dom");
|
19 | var ag_grid_community_1 = require("ag-grid-community");
|
20 | var reactComponent_1 = require("./reactComponent");
|
21 | var keyGenerator_1 = require("./keyGenerator");
|
22 | var server_1 = require("react-dom/server");
|
23 | var LegacyReactComponent = (function (_super) {
|
24 | __extends(LegacyReactComponent, _super);
|
25 | function LegacyReactComponent() {
|
26 | var _this = _super !== null && _super.apply(this, arguments) || this;
|
27 | _this.staticMarkup = null;
|
28 | _this.staticRenderTime = 0;
|
29 | return _this;
|
30 | }
|
31 | LegacyReactComponent.prototype.init = function (params) {
|
32 | var _this = this;
|
33 | this.eParentElement = this.createParentElement(params);
|
34 | this.renderStaticMarkup(params);
|
35 | return new ag_grid_community_1.AgPromise(function (resolve) { return _this.createReactComponent(params, resolve); });
|
36 | };
|
37 | LegacyReactComponent.prototype.createReactComponent = function (params, resolve) {
|
38 | var _this = this;
|
39 |
|
40 | if (!this.isStatelessComponent()) {
|
41 |
|
42 | params.ref = function (element) {
|
43 | _this.componentInstance = element;
|
44 | _this.addParentContainerStyleAndClasses();
|
45 | _this.removeStaticMarkup();
|
46 | };
|
47 | }
|
48 | var reactComponent = react_1.createElement(this.reactComponent, params);
|
49 | var portal = react_dom_1.createPortal(reactComponent, this.eParentElement, keyGenerator_1.default()
|
50 | );
|
51 | this.portal = portal;
|
52 | this.parentComponent.mountReactPortal(portal, this, function (value) {
|
53 | resolve(value);
|
54 |
|
55 |
|
56 | if (_this.isStatelessComponent()) {
|
57 | if (_this.isSlowRenderer()) {
|
58 | _this.removeStaticMarkup();
|
59 | }
|
60 | setTimeout(function () {
|
61 | _this.removeStaticMarkup();
|
62 | });
|
63 | }
|
64 | });
|
65 | };
|
66 | LegacyReactComponent.prototype.fallbackMethodAvailable = function (name) {
|
67 | return false;
|
68 | };
|
69 | LegacyReactComponent.prototype.fallbackMethod = function (name, params) { };
|
70 | LegacyReactComponent.prototype.isSlowRenderer = function () {
|
71 | return this.staticRenderTime >= LegacyReactComponent.SLOW_RENDERERING_THRESHOLD;
|
72 | };
|
73 | LegacyReactComponent.prototype.isNullValue = function () {
|
74 | return this.staticMarkup === '';
|
75 | };
|
76 | |
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 | LegacyReactComponent.prototype.renderStaticMarkup = function (params) {
|
83 | if (this.parentComponent.isDisableStaticMarkup() || (this.componentType.isCellRenderer && !this.componentType.isCellRenderer())) {
|
84 | return;
|
85 | }
|
86 | var originalConsoleError = console.error;
|
87 | var reactComponent = react_1.createElement(this.reactComponent, params);
|
88 | try {
|
89 |
|
90 |
|
91 |
|
92 | console.error = function () {
|
93 | };
|
94 | var start = Date.now();
|
95 | var staticMarkup = server_1.renderToStaticMarkup(reactComponent);
|
96 | this.staticRenderTime = Date.now() - start;
|
97 | console.error = originalConsoleError;
|
98 |
|
99 | if (staticMarkup === '') {
|
100 | this.staticMarkup = staticMarkup;
|
101 | }
|
102 | else {
|
103 | if (staticMarkup) {
|
104 |
|
105 |
|
106 | this.staticMarkup = document.createElement('span');
|
107 | this.staticMarkup.innerHTML = staticMarkup;
|
108 | this.eParentElement.appendChild(this.staticMarkup);
|
109 | }
|
110 | }
|
111 | }
|
112 | catch (e) {
|
113 |
|
114 | }
|
115 | finally {
|
116 | console.error = originalConsoleError;
|
117 | }
|
118 | };
|
119 | LegacyReactComponent.prototype.removeStaticMarkup = function () {
|
120 | if (this.parentComponent.isDisableStaticMarkup() || !this.componentType.isCellRenderer()) {
|
121 | return;
|
122 | }
|
123 | if (this.staticMarkup) {
|
124 | if (this.staticMarkup.remove) {
|
125 |
|
126 | this.staticMarkup.remove();
|
127 | this.staticMarkup = null;
|
128 | }
|
129 | else if (this.eParentElement.removeChild) {
|
130 |
|
131 | this.eParentElement.removeChild(this.staticMarkup);
|
132 | this.staticMarkup = null;
|
133 | }
|
134 | }
|
135 | };
|
136 | LegacyReactComponent.prototype.rendered = function () {
|
137 | return this.isNullValue() ||
|
138 | !!this.staticMarkup || (this.isStatelessComponent() && this.statelessComponentRendered()) ||
|
139 | !!(!this.isStatelessComponent() && this.getFrameworkComponentInstance());
|
140 | };
|
141 | LegacyReactComponent.SLOW_RENDERERING_THRESHOLD = 3;
|
142 | return LegacyReactComponent;
|
143 | }(reactComponent_1.ReactComponent));
|
144 | exports.LegacyReactComponent = LegacyReactComponent;
|