igniteui-react-grids
Version:
Ignite UI React grid components.
245 lines (243 loc) • 9.11 kB
JavaScript
import { __assign, __extends, __values } from "tslib";
import * as React from 'react';
import { delegateCombine, delegateRemove } from "igniteui-react-core";
import { IgrExporterEventArgs } from "./igr-exporter-event-args";
import { IgrVoidEventArgs } from "igniteui-react";
import { IgrBaseToolbarDirective } from "./igr-base-toolbar-directive";
import { GridToolbarExporter } from "./GridToolbarExporter";
import { isValidProp, ensureBool } from "igniteui-react-core";
/**
* Provides a pre-configured exporter component for the grid.
* @remarks
* This component still needs the actual exporter service(s) provided in the DI chain
* in order to export something.
* @igxModule IgxGridToolbarModule
* @igxParent IgxGridToolbarComponent
*/
var IgrGridToolbarExporter = /** @class */ /*@__PURE__*/ (function (_super) {
__extends(IgrGridToolbarExporter, _super);
function IgrGridToolbarExporter(props) {
var _this = _super.call(this, props) || this;
_this.portaledContentChildren = [];
_this._exportStarted = null;
_this._exportStarted_wrapped = null;
_this._exportEnded = null;
_this._exportEnded_wrapped = null;
_this._getMainRef = _this._getMainRef.bind(_this);
return _this;
}
IgrGridToolbarExporter.prototype.createImplementation = function () {
var _a, _b;
var impl = new GridToolbarExporter();
var nat;
if (typeof document !== 'undefined') {
nat = document.createElement("igc-grid-toolbar-exporter");
}
else {
nat = {
style: {}
};
}
if ((_a = this.props) === null || _a === void 0 ? void 0 : _a.className) {
nat.className = this.props.className;
}
if ((_b = this.props) === null || _b === void 0 ? void 0 : _b.id) {
nat.id = this.props.id;
}
impl.setNativeElement(nat);
return impl;
};
Object.defineProperty(IgrGridToolbarExporter.prototype, "i", {
/**
* @hidden
*/
get: function () {
return this._implementation;
},
enumerable: false,
configurable: true
});
IgrGridToolbarExporter.prototype.componentWillUnmount = function () {
var e_1, _a;
if (this.portaledContentChildren.length > 0) {
try {
for (var _b = __values(this.portaledContentChildren), _c = _b.next(); !_c.done; _c = _b.next()) {
var item = _c.value;
var nativeElem = item.ele;
if (item.ele.parentElement !== this.nativeElement) {
// put it back where it should be for react's portals to find.
this.nativeElement.appendChild(nativeElem);
}
}
}
catch (e_1_1) {
e_1 = { error: e_1_1 };
}
finally {
try {
if (_c && !_c.done && (_a = _b.return))
_a.call(_b);
}
finally {
if (e_1)
throw e_1.error;
}
}
}
};
IgrGridToolbarExporter.prototype.onImplementationCreated = function () {
var _this = this;
_super.prototype.onImplementationCreated.call(this);
this._portalManager.getPortal(this._renderer.getWrapper(this._implementation.nativeElement), "ChildContent", function (p) {
for (var i = 0; i < p.portalContainer.getChildCount(); i++) {
_this.portaledContentChildren.push(p.portalContainer.getChildAt(i));
}
}, true);
};
IgrGridToolbarExporter.prototype.componentDidMount = function () {
this.mounted = true;
_super.prototype.componentDidMount.call(this);
};
IgrGridToolbarExporter.prototype.render = function () {
var _this = this;
var nativePropsName = Object.keys(this.props).filter(function (prop) { return !isValidProp(_this, prop) && prop !== "originalRef" && prop !== "className"; });
var nativeProps = {};
nativePropsName.forEach(function (propName) {
nativeProps[propName] = _this.props[propName];
});
var propChildren = this.props.children;
var children = [];
React.Children.forEach(propChildren, function (ch) {
children.push(React.cloneElement(ch));
});
this._portalManager.onRender(children);
var style = {};
style.display = 'contents';
if (this.props.style) {
style = this.props.style;
}
var div = React.createElement("div", __assign(__assign({}, nativeProps), { ref: this._getMainRef, style: style, children: children }));
return div;
};
IgrGridToolbarExporter.prototype._getMainRef = function (ref) {
this._elRef = ref;
};
Object.defineProperty(IgrGridToolbarExporter.prototype, "exportCSV", {
/**
* Show entry for CSV export.
*/
get: function () {
return this.i.w;
},
set: function (v) {
this.i.w = ensureBool(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrGridToolbarExporter.prototype, "exportExcel", {
/**
* Show entry for Excel export.
*/
get: function () {
return this.i.x;
},
set: function (v) {
this.i.x = ensureBool(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrGridToolbarExporter.prototype, "filename", {
/**
* The name for the exported file.
*/
get: function () {
return this.i.y;
},
set: function (v) {
this.i.y = v;
},
enumerable: false,
configurable: true
});
/**
* Export the grid's data
* type File type to export
* @param type * File type to export
*/
IgrGridToolbarExporter.prototype.exportGrid = function (type) {
this.i.aa((type == null ? null : type));
};
Object.defineProperty(IgrGridToolbarExporter.prototype, "exportStarted", {
/**
* Emitted when starting an export operation. Re-emitted additionally
* by the grid itself.
*/
get: function () {
return this._exportStarted;
},
set: function (ev) {
var _this = this;
if (this._exportStarted_wrapped !== null) {
this.i.exportStarted = delegateRemove(this.i.exportStarted, this._exportStarted_wrapped);
this._exportStarted_wrapped = null;
this._exportStarted = null;
}
this._exportStarted = ev;
this._exportStarted_wrapped = function (o, e) {
var outerArgs = new IgrExporterEventArgs();
outerArgs._provideImplementation(e);
if (_this.beforeExportStarted) {
_this.beforeExportStarted(_this, outerArgs);
}
if (_this._exportStarted) {
_this._exportStarted(_this, outerArgs);
}
};
this.i.exportStarted = delegateCombine(this.i.exportStarted, this._exportStarted_wrapped);
if (this.i.exportStartedChanged) {
this.i.exportStartedChanged();
}
;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrGridToolbarExporter.prototype, "exportEnded", {
/**
* Emitted on successful ending of an export operation.
*/
get: function () {
return this._exportEnded;
},
set: function (ev) {
var _this = this;
if (this._exportEnded_wrapped !== null) {
this.i.exportEnded = delegateRemove(this.i.exportEnded, this._exportEnded_wrapped);
this._exportEnded_wrapped = null;
this._exportEnded = null;
}
this._exportEnded = ev;
this._exportEnded_wrapped = function (o, e) {
var outerArgs = new IgrVoidEventArgs();
outerArgs._provideImplementation(e);
if (_this.beforeExportEnded) {
_this.beforeExportEnded(_this, outerArgs);
}
if (_this._exportEnded) {
_this._exportEnded(_this, outerArgs);
}
};
this.i.exportEnded = delegateCombine(this.i.exportEnded, this._exportEnded_wrapped);
if (this.i.exportEndedChanged) {
this.i.exportEndedChanged();
}
;
},
enumerable: false,
configurable: true
});
return IgrGridToolbarExporter;
}(IgrBaseToolbarDirective));
export { IgrGridToolbarExporter };