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 __importStar = (this && this.__importStar) || function (mod) {
|
28 | if (mod && mod.__esModule) return mod;
|
29 | var result = {};
|
30 | if (mod != null) for (var k in mod) if (Object.hasOwnProperty.call(mod, k)) result[k] = mod[k];
|
31 | result["default"] = mod;
|
32 | return result;
|
33 | };
|
34 | var __importDefault = (this && this.__importDefault) || function (mod) {
|
35 | return (mod && mod.__esModule) ? mod : { "default": mod };
|
36 | };
|
37 | Object.defineProperty(exports, "__esModule", { value: true });
|
38 | var ag_grid_community_1 = require("ag-grid-community");
|
39 | var react_1 = __importStar(require("react"));
|
40 | var agGridColumn_1 = require("../shared/agGridColumn");
|
41 | var changeDetectionService_1 = require("../shared/changeDetectionService");
|
42 | var newReactComponent_1 = require("../shared/newReactComponent");
|
43 | var portalManager_1 = require("../shared/portalManager");
|
44 | var gridComp_1 = __importDefault(require("./gridComp"));
|
45 | var reactFrameworkOverrides_1 = require("./reactFrameworkOverrides");
|
46 | var AgGridReactUi = (function (_super) {
|
47 | __extends(AgGridReactUi, _super);
|
48 | function AgGridReactUi(props) {
|
49 | var _this = _super.call(this, props) || this;
|
50 | _this.props = props;
|
51 | _this.destroyFuncs = [];
|
52 | _this.changeDetectionService = new changeDetectionService_1.ChangeDetectionService();
|
53 | _this.eGui = react_1.default.createRef();
|
54 | _this.state = { context: undefined };
|
55 | _this.portalManager = new portalManager_1.PortalManager(_this, props.componentWrappingElement, props.maxComponentCreationTimeMs);
|
56 | return _this;
|
57 | }
|
58 | AgGridReactUi.prototype.render = function () {
|
59 | return (react_1.default.createElement("div", { style: this.createStyleForDiv(), className: this.props.className, ref: this.eGui },
|
60 | this.state.context && react_1.default.createElement(gridComp_1.default, { context: this.state.context }),
|
61 | this.portalManager.getPortals()));
|
62 | };
|
63 | AgGridReactUi.prototype.createStyleForDiv = function () {
|
64 | return __assign({ height: '100%' }, (this.props.containerStyle || {}));
|
65 | };
|
66 | AgGridReactUi.prototype.componentDidMount = function () {
|
67 | var _this = this;
|
68 | var modules = this.props.modules || [];
|
69 | var gridParams = {
|
70 | providedBeanInstances: {
|
71 | frameworkComponentWrapper: new ReactFrameworkComponentWrapper(this.portalManager)
|
72 | },
|
73 | modules: modules,
|
74 | frameworkOverrides: new reactFrameworkOverrides_1.ReactFrameworkOverrides()
|
75 | };
|
76 | this.gridOptions = __assign({}, this.props.gridOptions);
|
77 | var children = this.props.children;
|
78 | if (agGridColumn_1.AgGridColumn.hasChildColumns(children)) {
|
79 | this.gridOptions.columnDefs = agGridColumn_1.AgGridColumn.mapChildColumnDefs(children);
|
80 | }
|
81 | this.gridOptions = ag_grid_community_1.ComponentUtil.copyAttributesToGridOptions(this.gridOptions, this.props);
|
82 |
|
83 | var gridCoreCreator = new ag_grid_community_1.GridCoreCreator();
|
84 | gridCoreCreator.create(this.eGui.current, this.gridOptions, function (context) {
|
85 | _this.setState({ context: context });
|
86 | }, gridParams);
|
87 | this.destroyFuncs.push(function () { return _this.gridOptions.api.destroy(); });
|
88 | this.api = this.gridOptions.api;
|
89 | this.columnApi = this.gridOptions.columnApi;
|
90 | this.props.setGridApi(this.api, this.columnApi);
|
91 | };
|
92 | AgGridReactUi.prototype.componentWillUnmount = function () {
|
93 | this.destroyFuncs.forEach(function (f) { return f(); });
|
94 | };
|
95 | AgGridReactUi.prototype.componentDidUpdate = function (prevProps) {
|
96 | this.processPropsChanges(prevProps, this.props);
|
97 | };
|
98 | AgGridReactUi.prototype.processPropsChanges = function (prevProps, nextProps) {
|
99 | var changes = {};
|
100 | this.extractGridPropertyChanges(prevProps, nextProps, changes);
|
101 | this.extractDeclarativeColDefChanges(nextProps, changes);
|
102 | this.processChanges(changes);
|
103 | };
|
104 | AgGridReactUi.prototype.extractDeclarativeColDefChanges = function (nextProps, changes) {
|
105 |
|
106 |
|
107 | if ((this.props.gridOptions && this.props.gridOptions.columnDefs) || this.props.columnDefs) {
|
108 | return;
|
109 | }
|
110 | var debugLogging = !!nextProps.debug;
|
111 | var propKey = 'columnDefs';
|
112 | var currentColDefs = this.gridOptions.columnDefs;
|
113 | if (agGridColumn_1.AgGridColumn.hasChildColumns(nextProps.children)) {
|
114 | var detectionStrategy = this.changeDetectionService.getStrategy(this.getStrategyTypeForProp(propKey));
|
115 | var newColDefs = agGridColumn_1.AgGridColumn.mapChildColumnDefs(nextProps.children);
|
116 | if (!detectionStrategy.areEqual(currentColDefs, newColDefs)) {
|
117 | if (debugLogging) {
|
118 | console.log("agGridReact: colDefs definitions changed");
|
119 | }
|
120 | changes[propKey] =
|
121 | {
|
122 | previousValue: currentColDefs,
|
123 | currentValue: newColDefs
|
124 | };
|
125 | }
|
126 | }
|
127 | else if (currentColDefs && currentColDefs.length > 0) {
|
128 | changes[propKey] =
|
129 | {
|
130 | previousValue: currentColDefs,
|
131 | currentValue: []
|
132 | };
|
133 | }
|
134 | };
|
135 | AgGridReactUi.prototype.extractGridPropertyChanges = function (prevProps, nextProps, changes) {
|
136 | var _this = this;
|
137 | var debugLogging = !!nextProps.debug;
|
138 | Object.keys(nextProps).forEach(function (propKey) {
|
139 | if (ag_grid_community_1._.includes(ag_grid_community_1.ComponentUtil.ALL_PROPERTIES, propKey)) {
|
140 | var changeDetectionStrategy = _this.changeDetectionService.getStrategy(_this.getStrategyTypeForProp(propKey));
|
141 | if (!changeDetectionStrategy.areEqual(prevProps[propKey], nextProps[propKey])) {
|
142 | if (debugLogging) {
|
143 | console.log("agGridReact: [" + propKey + "] property changed");
|
144 | }
|
145 | changes[propKey] = {
|
146 | previousValue: prevProps[propKey],
|
147 | currentValue: nextProps[propKey]
|
148 | };
|
149 | }
|
150 | }
|
151 | });
|
152 | ag_grid_community_1.ComponentUtil.getEventCallbacks().forEach(function (funcName) {
|
153 | if (prevProps[funcName] !== nextProps[funcName]) {
|
154 | if (debugLogging) {
|
155 | console.log("agGridReact: [" + funcName + "] event callback changed");
|
156 | }
|
157 | changes[funcName] = {
|
158 | previousValue: prevProps[funcName],
|
159 | currentValue: nextProps[funcName]
|
160 | };
|
161 | }
|
162 | });
|
163 | };
|
164 | AgGridReactUi.prototype.processChanges = function (changes) {
|
165 | if (this.api) {
|
166 | ag_grid_community_1.ComponentUtil.processOnChange(changes, this.gridOptions, this.api, this.columnApi);
|
167 | }
|
168 | };
|
169 | AgGridReactUi.prototype.getStrategyTypeForProp = function (propKey) {
|
170 | if (propKey === 'rowData') {
|
171 | if (this.props.rowDataChangeDetectionStrategy) {
|
172 | return this.props.rowDataChangeDetectionStrategy;
|
173 | }
|
174 | if (this.isImmutableDataActive()) {
|
175 | return changeDetectionService_1.ChangeDetectionStrategyType.IdentityCheck;
|
176 | }
|
177 | }
|
178 |
|
179 | return changeDetectionService_1.ChangeDetectionStrategyType.DeepValueCheck;
|
180 | };
|
181 | AgGridReactUi.prototype.isImmutableDataActive = function () {
|
182 | return (this.props.deltaRowDataMode || this.props.immutableData) ||
|
183 | (this.props.gridOptions && (this.props.gridOptions.deltaRowDataMode || this.props.gridOptions.immutableData));
|
184 | };
|
185 | return AgGridReactUi;
|
186 | }(react_1.Component));
|
187 | exports.AgGridReactUi = AgGridReactUi;
|
188 | var ReactFrameworkComponentWrapper = (function (_super) {
|
189 | __extends(ReactFrameworkComponentWrapper, _super);
|
190 | function ReactFrameworkComponentWrapper(parent) {
|
191 | var _this = _super.call(this) || this;
|
192 | _this.parent = parent;
|
193 | return _this;
|
194 | }
|
195 | ReactFrameworkComponentWrapper.prototype.createWrapper = function (UserReactComponent, componentType) {
|
196 | return new newReactComponent_1.NewReactComponent(UserReactComponent, this.parent, componentType);
|
197 | };
|
198 | ReactFrameworkComponentWrapper.prototype.unwrap = function (comp) {
|
199 | if (comp && comp.getFrameworkComponentInstance) {
|
200 | return comp.getFrameworkComponentInstance();
|
201 | }
|
202 | return comp;
|
203 | };
|
204 | return ReactFrameworkComponentWrapper;
|
205 | }(ag_grid_community_1.BaseComponentWrapper));
|