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 | var __assign = (this && this.__assign) || function () {
|
17 | __assign = Object.assign || function(t) {
|
18 | for (var s, i = 1, n = arguments.length; i < n; i++) {
|
19 | s = arguments[i];
|
20 | for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
21 | t[p] = s[p];
|
22 | }
|
23 | return t;
|
24 | };
|
25 | return __assign.apply(this, arguments);
|
26 | };
|
27 | var __spreadArrays = (this && this.__spreadArrays) || function () {
|
28 | for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
|
29 | for (var r = Array(s), k = 0, i = 0; i < il; i++)
|
30 | for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
|
31 | r[k] = a[j];
|
32 | return r;
|
33 | };
|
34 | var __importStar = (this && this.__importStar) || function (mod) {
|
35 | if (mod && mod.__esModule) return mod;
|
36 | var result = {};
|
37 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
38 | result["default"] = mod;
|
39 | return result;
|
40 | };
|
41 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
42 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
43 | };
|
44 | Object.defineProperty(exports, "__esModule", { value: true });
|
45 | var react_1 = __importStar(require("react"));
|
46 | var prop_types_1 = __importDefault(require("prop-types"));
|
47 | var ag_grid_community_1 = require("ag-grid-community");
|
48 | var agGridColumn_1 = require("./agGridColumn");
|
49 | var changeDetectionService_1 = require("./changeDetectionService");
|
50 | var legacyReactComponent_1 = require("./legacyReactComponent");
|
51 | var newReactComponent_1 = require("./newReactComponent");
|
52 | var AgGridReactLegacy = (function (_super) {
|
53 | __extends(AgGridReactLegacy, _super);
|
54 | function AgGridReactLegacy(props) {
|
55 | var _this = _super.call(this, props) || this;
|
56 | _this.props = props;
|
57 | _this.changeDetectionService = new changeDetectionService_1.ChangeDetectionService();
|
58 | _this.api = null;
|
59 | _this.portals = [];
|
60 | _this.hasPendingPortalUpdate = false;
|
61 | _this.destroyed = false;
|
62 | _this.SYNCHRONOUS_CHANGE_PROPERTIES = ['context'];
|
63 | return _this;
|
64 | }
|
65 | AgGridReactLegacy.prototype.render = function () {
|
66 | var _this = this;
|
67 | return react_1.default.createElement('div', {
|
68 | style: this.createStyleForDiv(),
|
69 | className: this.props.className,
|
70 | ref: function (e) {
|
71 | _this.eGridDiv = e;
|
72 | }
|
73 | }, this.portals);
|
74 | };
|
75 | AgGridReactLegacy.prototype.createStyleForDiv = function () {
|
76 | return __assign({ height: '100%' }, (this.props.containerStyle || {}));
|
77 | };
|
78 | AgGridReactLegacy.prototype.componentDidMount = function () {
|
79 | var modules = this.props.modules || [];
|
80 | var gridParams = {
|
81 | providedBeanInstances: {
|
82 | agGridReact: this,
|
83 | frameworkComponentWrapper: new ReactFrameworkComponentWrapper(this)
|
84 | },
|
85 | modules: modules
|
86 | };
|
87 | var gridOptions = this.props.gridOptions || {};
|
88 | var children = this.props.children;
|
89 | if (agGridColumn_1.AgGridColumn.hasChildColumns(children)) {
|
90 | gridOptions.columnDefs = agGridColumn_1.AgGridColumn.mapChildColumnDefs(children);
|
91 | }
|
92 | this.gridOptions = ag_grid_community_1.ComponentUtil.copyAttributesToGridOptions(gridOptions, this.props);
|
93 |
|
94 | new ag_grid_community_1.Grid(this.eGridDiv, this.gridOptions, gridParams);
|
95 | this.api = this.gridOptions.api;
|
96 | this.columnApi = this.gridOptions.columnApi;
|
97 | this.props.setGridApi(this.api, this.columnApi);
|
98 | };
|
99 | AgGridReactLegacy.prototype.waitForInstance = function (reactComponent, resolve, startTime) {
|
100 | var _this = this;
|
101 | if (startTime === void 0) { startTime = Date.now(); }
|
102 |
|
103 | if (this.destroyed) {
|
104 | resolve(null);
|
105 | return;
|
106 | }
|
107 | if (reactComponent.rendered()) {
|
108 | resolve(reactComponent);
|
109 | }
|
110 | else {
|
111 | if (Date.now() - startTime >= this.props.maxComponentCreationTimeMs && !this.hasPendingPortalUpdate) {
|
112 |
|
113 |
|
114 | if (reactComponent.isNullValue()) {
|
115 | resolve(reactComponent);
|
116 | return;
|
117 | }
|
118 | console.error("AG Grid: React Component '" + reactComponent.getReactComponentName() + "' not created within " + AgGridReactLegacy.MAX_COMPONENT_CREATION_TIME_IN_MS + "ms");
|
119 | return;
|
120 | }
|
121 | window.setTimeout(function () {
|
122 | _this.waitForInstance(reactComponent, resolve, startTime);
|
123 | });
|
124 | }
|
125 | };
|
126 | |
127 |
|
128 |
|
129 |
|
130 |
|
131 | AgGridReactLegacy.prototype.mountReactPortal = function (portal, reactComponent, resolve) {
|
132 | this.portals = __spreadArrays(this.portals, [portal]);
|
133 | this.waitForInstance(reactComponent, resolve);
|
134 | this.batchUpdate();
|
135 | };
|
136 | AgGridReactLegacy.prototype.updateReactPortal = function (oldPortal, newPortal) {
|
137 | this.portals[this.portals.indexOf(oldPortal)] = newPortal;
|
138 | this.batchUpdate();
|
139 | };
|
140 | AgGridReactLegacy.prototype.batchUpdate = function () {
|
141 | var _this = this;
|
142 | if (this.hasPendingPortalUpdate) {
|
143 | return;
|
144 | }
|
145 | setTimeout(function () {
|
146 | if (_this.api) {
|
147 | _this.forceUpdate(function () {
|
148 | _this.hasPendingPortalUpdate = false;
|
149 | });
|
150 | }
|
151 | });
|
152 | this.hasPendingPortalUpdate = true;
|
153 | };
|
154 | AgGridReactLegacy.prototype.destroyPortal = function (portal) {
|
155 | this.portals = this.portals.filter(function (curPortal) { return curPortal !== portal; });
|
156 | this.batchUpdate();
|
157 | };
|
158 | AgGridReactLegacy.prototype.getStrategyTypeForProp = function (propKey) {
|
159 | if (propKey === 'rowData') {
|
160 | if (this.props.rowDataChangeDetectionStrategy) {
|
161 | return this.props.rowDataChangeDetectionStrategy;
|
162 | }
|
163 | else if (this.isImmutableDataActive()) {
|
164 | return changeDetectionService_1.ChangeDetectionStrategyType.IdentityCheck;
|
165 | }
|
166 | }
|
167 |
|
168 | return changeDetectionService_1.ChangeDetectionStrategyType.DeepValueCheck;
|
169 | };
|
170 | AgGridReactLegacy.prototype.isImmutableDataActive = function () {
|
171 | return (this.props.deltaRowDataMode || this.props.immutableData) ||
|
172 | (this.props.gridOptions && (this.props.gridOptions.deltaRowDataMode || this.props.gridOptions.immutableData));
|
173 | };
|
174 | AgGridReactLegacy.prototype.shouldComponentUpdate = function (nextProps) {
|
175 | this.processPropsChanges(this.props, nextProps);
|
176 |
|
177 |
|
178 |
|
179 | return false;
|
180 | };
|
181 | AgGridReactLegacy.prototype.componentDidUpdate = function (prevProps) {
|
182 | this.processPropsChanges(prevProps, this.props);
|
183 | };
|
184 | AgGridReactLegacy.prototype.processPropsChanges = function (prevProps, nextProps) {
|
185 | var changes = {};
|
186 | this.extractGridPropertyChanges(prevProps, nextProps, changes);
|
187 | this.extractDeclarativeColDefChanges(nextProps, changes);
|
188 | this.processSynchronousChanges(changes);
|
189 | this.processAsynchronousChanges(changes);
|
190 | };
|
191 | AgGridReactLegacy.prototype.extractDeclarativeColDefChanges = function (nextProps, changes) {
|
192 |
|
193 |
|
194 | if ((this.props.gridOptions && this.props.gridOptions.columnDefs) || this.props.columnDefs) {
|
195 | return;
|
196 | }
|
197 | var debugLogging = !!nextProps.debug;
|
198 | var propKey = 'columnDefs';
|
199 | var currentColDefs = this.gridOptions.columnDefs;
|
200 | if (agGridColumn_1.AgGridColumn.hasChildColumns(nextProps.children)) {
|
201 | var detectionStrategy = this.changeDetectionService.getStrategy(this.getStrategyTypeForProp(propKey));
|
202 | var newColDefs = agGridColumn_1.AgGridColumn.mapChildColumnDefs(nextProps.children);
|
203 | if (!detectionStrategy.areEqual(currentColDefs, newColDefs)) {
|
204 | if (debugLogging) {
|
205 | console.log("agGridReact: colDefs definitions changed");
|
206 | }
|
207 | changes[propKey] =
|
208 | {
|
209 | previousValue: currentColDefs,
|
210 | currentValue: newColDefs
|
211 | };
|
212 | }
|
213 | }
|
214 | else if (currentColDefs && currentColDefs.length > 0) {
|
215 | changes[propKey] =
|
216 | {
|
217 | previousValue: currentColDefs,
|
218 | currentValue: []
|
219 | };
|
220 | }
|
221 | };
|
222 | AgGridReactLegacy.prototype.extractGridPropertyChanges = function (prevProps, nextProps, changes) {
|
223 | var _this = this;
|
224 | var debugLogging = !!nextProps.debug;
|
225 | Object.keys(nextProps).forEach(function (propKey) {
|
226 | if (ag_grid_community_1._.includes(ag_grid_community_1.ComponentUtil.ALL_PROPERTIES, propKey)) {
|
227 | var changeDetectionStrategy = _this.changeDetectionService.getStrategy(_this.getStrategyTypeForProp(propKey));
|
228 | if (!changeDetectionStrategy.areEqual(prevProps[propKey], nextProps[propKey])) {
|
229 | if (debugLogging) {
|
230 | console.log("agGridReact: [" + propKey + "] property changed");
|
231 | }
|
232 | changes[propKey] = {
|
233 | previousValue: prevProps[propKey],
|
234 | currentValue: nextProps[propKey]
|
235 | };
|
236 | }
|
237 | }
|
238 | });
|
239 | ag_grid_community_1.ComponentUtil.getEventCallbacks().forEach(function (funcName) {
|
240 | var propsAny = _this.props;
|
241 | if (propsAny[funcName] !== nextProps[funcName]) {
|
242 | if (debugLogging) {
|
243 | console.log("agGridReact: [" + funcName + "] event callback changed");
|
244 | }
|
245 | changes[funcName] = {
|
246 | previousValue: prevProps[funcName],
|
247 | currentValue: nextProps[funcName]
|
248 | };
|
249 | }
|
250 | });
|
251 | };
|
252 | AgGridReactLegacy.prototype.componentWillUnmount = function () {
|
253 | if (this.api) {
|
254 | this.api.destroy();
|
255 | this.api = null;
|
256 | }
|
257 | this.destroyed = true;
|
258 | };
|
259 | AgGridReactLegacy.prototype.isDisableStaticMarkup = function () {
|
260 | return this.props.disableStaticMarkup === true;
|
261 | };
|
262 | AgGridReactLegacy.prototype.isLegacyComponentRendering = function () {
|
263 | return this.props.legacyComponentRendering === true;
|
264 | };
|
265 | AgGridReactLegacy.prototype.processSynchronousChanges = function (changes) {
|
266 | var asyncChanges = __assign({}, changes);
|
267 | if (Object.keys(asyncChanges).length > 0) {
|
268 | var synchronousChanges_1 = {};
|
269 | this.SYNCHRONOUS_CHANGE_PROPERTIES.forEach(function (synchronousChangeProperty) {
|
270 | if (asyncChanges[synchronousChangeProperty]) {
|
271 | synchronousChanges_1[synchronousChangeProperty] = asyncChanges[synchronousChangeProperty];
|
272 | delete asyncChanges[synchronousChangeProperty];
|
273 | }
|
274 | });
|
275 | if (Object.keys(synchronousChanges_1).length > 0 && !!this.api) {
|
276 | ag_grid_community_1.ComponentUtil.processOnChange(synchronousChanges_1, this.gridOptions, this.api, this.columnApi);
|
277 | }
|
278 | }
|
279 | return asyncChanges;
|
280 | };
|
281 | AgGridReactLegacy.prototype.processAsynchronousChanges = function (changes) {
|
282 | var _this = this;
|
283 | if (Object.keys(changes).length > 0) {
|
284 | window.setTimeout(function () {
|
285 |
|
286 | if (_this.api) {
|
287 | ag_grid_community_1.ComponentUtil.processOnChange(changes, _this.gridOptions, _this.api, _this.columnApi);
|
288 | }
|
289 | });
|
290 | }
|
291 | };
|
292 | AgGridReactLegacy.MAX_COMPONENT_CREATION_TIME_IN_MS = 1000;
|
293 | AgGridReactLegacy.defaultProps = {
|
294 | legacyComponentRendering: false,
|
295 | disableStaticMarkup: false,
|
296 | maxComponentCreationTimeMs: AgGridReactLegacy.MAX_COMPONENT_CREATION_TIME_IN_MS
|
297 | };
|
298 | return AgGridReactLegacy;
|
299 | }(react_1.Component));
|
300 | exports.AgGridReactLegacy = AgGridReactLegacy;
|
301 | AgGridReactLegacy.propTypes = {
|
302 | gridOptions: prop_types_1.default.object
|
303 | };
|
304 | addProperties(ag_grid_community_1.ComponentUtil.getEventCallbacks(), prop_types_1.default.func);
|
305 | addProperties(ag_grid_community_1.ComponentUtil.BOOLEAN_PROPERTIES, prop_types_1.default.bool);
|
306 | addProperties(ag_grid_community_1.ComponentUtil.STRING_PROPERTIES, prop_types_1.default.string);
|
307 | addProperties(ag_grid_community_1.ComponentUtil.OBJECT_PROPERTIES, prop_types_1.default.object);
|
308 | addProperties(ag_grid_community_1.ComponentUtil.ARRAY_PROPERTIES, prop_types_1.default.array);
|
309 | addProperties(ag_grid_community_1.ComponentUtil.NUMBER_PROPERTIES, prop_types_1.default.number);
|
310 | addProperties(ag_grid_community_1.ComponentUtil.FUNCTION_PROPERTIES, prop_types_1.default.func);
|
311 | function addProperties(listOfProps, propType) {
|
312 | listOfProps.forEach(function (propKey) {
|
313 | AgGridReactLegacy[propKey] = propType;
|
314 | });
|
315 | }
|
316 | var ReactFrameworkComponentWrapper = (function (_super) {
|
317 | __extends(ReactFrameworkComponentWrapper, _super);
|
318 | function ReactFrameworkComponentWrapper(agGridReact) {
|
319 | var _this = _super.call(this) || this;
|
320 | _this.agGridReact = agGridReact;
|
321 | return _this;
|
322 | }
|
323 | ReactFrameworkComponentWrapper.prototype.createWrapper = function (UserReactComponent, componentType) {
|
324 | return this.agGridReact.isLegacyComponentRendering() ?
|
325 | new legacyReactComponent_1.LegacyReactComponent(UserReactComponent, this.agGridReact, componentType) :
|
326 | new newReactComponent_1.NewReactComponent(UserReactComponent, this.agGridReact, componentType);
|
327 | };
|
328 | return ReactFrameworkComponentWrapper;
|
329 | }(ag_grid_community_1.BaseComponentWrapper));
|