igniteui-react-grids
Version:
Ignite UI React grid components.
139 lines (138 loc) • 5.37 kB
JavaScript
import { __assign, __extends } from "tslib";
import * as React from 'react';
import { delegateCombine, delegateRemove } from "igniteui-react-core";
import { IgrGridStateInfoEventArgs } from "./igr-grid-state-info-event-args";
import { IgrGridStateBaseDirective } from "./igr-grid-state-base-directive";
import { GridState } from "./GridState";
import { isValidProp, interfaceToInternal } from "igniteui-react-core";
import { GridStateInfo } from "./GridStateInfo";
/**
* State component allows saving and restoring the state of the grid features.
* @igxParent IgxGridComponent, IgxTreeGridComponent, IgxHierarchicalGridComponent, IgxPivotGridComponent, *
*/
var IgrGridState = /** @class */ /*@__PURE__*/ (function (_super) {
__extends(IgrGridState, _super);
function IgrGridState(props) {
var _this = _super.call(this, props) || this;
_this._stateParsed = null;
_this._stateParsed_wrapped = null;
_this._getMainRef = _this._getMainRef.bind(_this);
return _this;
}
IgrGridState.prototype.createImplementation = function () {
var _a, _b;
var impl = new GridState();
var nat;
if (typeof document !== 'undefined') {
nat = document.createElement("igc-grid-state");
}
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(IgrGridState.prototype, "i", {
/**
* @hidden
*/
get: function () {
return this._implementation;
},
enumerable: false,
configurable: true
});
IgrGridState.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;
};
IgrGridState.prototype._getMainRef = function (ref) {
this._elRef = ref;
};
IgrGridState.prototype.applyState = function (state, features) {
this.i.k((state == null ? null : interfaceToInternal(state, function () { return new GridStateInfo(); })), features);
};
IgrGridState.prototype.applyStateFromString = function (state, features) {
this.i.l(state, features);
};
IgrGridState.prototype.getState = function (features) {
var iv = this.i.h(features);
var ret = null;
if (iv && iv.externalObject) {
ret = iv.externalObject;
}
else {
if (iv) {
ret = iv.nativeElement;
delete ret.externalObject;
}
}
return ret;
};
IgrGridState.prototype.getStateAsString = function (features) {
var iv = this.i.j(features);
return (iv);
};
Object.defineProperty(IgrGridState.prototype, "stateParsed", {
/**
* Event emitted when set state is called with a string.
* Returns the parsed state object so that it can be further modified before applying to the grid.
*/
get: function () {
return this._stateParsed;
},
set: function (ev) {
var _this = this;
if (this._stateParsed_wrapped !== null) {
this.i.stateParsed = delegateRemove(this.i.stateParsed, this._stateParsed_wrapped);
this._stateParsed_wrapped = null;
this._stateParsed = null;
}
this._stateParsed = ev;
this._stateParsed_wrapped = function (o, e) {
var outerArgs = new IgrGridStateInfoEventArgs();
outerArgs._provideImplementation(e);
if (_this.beforeStateParsed) {
_this.beforeStateParsed(_this, outerArgs);
}
if (_this._stateParsed) {
_this._stateParsed(_this, outerArgs);
}
};
this.i.stateParsed = delegateCombine(this.i.stateParsed, this._stateParsed_wrapped);
if (this.i.stateParsedChanged) {
this.i.stateParsedChanged();
}
;
},
enumerable: false,
configurable: true
});
return IgrGridState;
}(IgrGridStateBaseDirective));
export { IgrGridState };