UNPKG

3.72 kBJavaScriptView Raw
1// ag-grid-react v28.1.0
2"use strict";
3var __spreadArrays = (this && this.__spreadArrays) || function () {
4 for (var s = 0, i = 0, il = arguments.length; i < il; i++) s += arguments[i].length;
5 for (var r = Array(s), k = 0, i = 0; i < il; i++)
6 for (var a = arguments[i], j = 0, jl = a.length; j < jl; j++, k++)
7 r[k] = a[j];
8 return r;
9};
10Object.defineProperty(exports, "__esModule", { value: true });
11var PortalManager = /** @class */ (function () {
12 function PortalManager(parent, wrappingElement, maxComponentCreationTimeMs) {
13 this.destroyed = false;
14 this.portals = [];
15 this.hasPendingPortalUpdate = false;
16 this.wrappingElement = wrappingElement ? wrappingElement : 'div';
17 this.parent = parent;
18 this.maxComponentCreationTimeMs = maxComponentCreationTimeMs ? maxComponentCreationTimeMs : PortalManager.MAX_COMPONENT_CREATION_TIME_IN_MS;
19 }
20 PortalManager.prototype.getPortals = function () {
21 return this.portals;
22 };
23 PortalManager.prototype.destroy = function () {
24 this.destroyed = true;
25 };
26 PortalManager.prototype.destroyPortal = function (portal) {
27 this.portals = this.portals.filter(function (curPortal) { return curPortal !== portal; });
28 this.batchUpdate();
29 };
30 PortalManager.prototype.getComponentWrappingElement = function () {
31 return this.wrappingElement;
32 };
33 PortalManager.prototype.mountReactPortal = function (portal, reactComponent, resolve) {
34 this.portals = __spreadArrays(this.portals, [portal]);
35 this.waitForInstance(reactComponent, resolve);
36 this.batchUpdate();
37 };
38 PortalManager.prototype.updateReactPortal = function (oldPortal, newPortal) {
39 this.portals[this.portals.indexOf(oldPortal)] = newPortal;
40 this.batchUpdate();
41 };
42 PortalManager.prototype.batchUpdate = function () {
43 var _this = this;
44 if (this.hasPendingPortalUpdate) {
45 return;
46 }
47 setTimeout(function () {
48 if (!_this.destroyed) { // destroyed?
49 _this.parent.forceUpdate(function () {
50 _this.hasPendingPortalUpdate = false;
51 });
52 }
53 });
54 this.hasPendingPortalUpdate = true;
55 };
56 PortalManager.prototype.waitForInstance = function (reactComponent, resolve, startTime) {
57 var _this = this;
58 if (startTime === void 0) { startTime = Date.now(); }
59 // if the grid has been destroyed in the meantime just resolve
60 if (this.destroyed) {
61 resolve(null);
62 return;
63 }
64 if (reactComponent.rendered()) {
65 resolve(reactComponent);
66 }
67 else {
68 if (Date.now() - startTime >= this.maxComponentCreationTimeMs && !this.hasPendingPortalUpdate) {
69 // last check - we check if this is a null value being rendered - we do this last as using SSR to check the value
70 // can mess up contexts
71 if (reactComponent.isNullValue()) {
72 resolve(reactComponent);
73 return;
74 }
75 console.error("AG Grid: React Component '" + reactComponent.getReactComponentName() + "' not created within " + this.maxComponentCreationTimeMs + "ms");
76 return;
77 }
78 window.setTimeout(function () {
79 _this.waitForInstance(reactComponent, resolve, startTime);
80 });
81 }
82 };
83 PortalManager.MAX_COMPONENT_CREATION_TIME_IN_MS = 1000; // a second should be more than enough to instantiate a component
84 return PortalManager;
85}());
86exports.PortalManager = PortalManager;