igniteui-react-grids
Version:
Ignite UI React grid components.
250 lines (249 loc) • 10.4 kB
JavaScript
import { __assign, __extends } from "tslib";
import * as React from 'react';
import { IgrGridToolbarBaseActionCollection } from "./igr-grid-toolbar-base-action-collection";
import { IgrGridToolbarContent } from "./igr-grid-toolbar-content";
import { GridToolbarActions } from "./GridToolbarActions";
import { ContentChildrenManager } from "igniteui-react-core";
import { CollectionAdapter, isValidProp } from "igniteui-react-core";
import { GridToolbarBaseAction } from "./GridToolbarBaseAction";
import { NotifyCollectionChangedAction } from "igniteui-react-core";
/**
* Provides a way to template the action portion of the toolbar in the grid.
* @igxModule IgxGridToolbarModule
* @igxParent IgxGridToolbarComponent
* @example
* ```html
* ```
*/
var IgrGridToolbarActions = /** @class */ /*@__PURE__*/ (function (_super) {
__extends(IgrGridToolbarActions, _super);
function IgrGridToolbarActions(props) {
var _this = _super.call(this, props) || this;
_this._actions = null;
_this._getMainRef = _this._getMainRef.bind(_this);
return _this;
}
IgrGridToolbarActions.prototype.createImplementation = function () {
var _a, _b;
var impl = new GridToolbarActions();
var nat;
if (typeof document !== 'undefined') {
nat = document.createElement("igc-grid-toolbar-actions");
}
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(IgrGridToolbarActions.prototype, "i", {
/**
* @hidden
*/
get: function () {
return this._implementation;
},
enumerable: false,
configurable: true
});
IgrGridToolbarActions.prototype._initializeAdapters = function () {
var _this = this;
if (!this._contentChildrenManager) {
var resolveNested_1 = (function (props, propName, nestedPropName) {
var _a;
var prop = props[propName];
if (Array.isArray(prop)) {
return prop.map(function (x) {
var _a;
return (_a = x[nestedPropName]) !== null && _a !== void 0 ? _a : resolveNested_1(x.props, propName, nestedPropName);
}).join("_");
}
else if (prop) {
return (_a = prop.props[nestedPropName]) !== null && _a !== void 0 ? _a : resolveNested_1(prop.props, propName, nestedPropName);
}
else {
return props[nestedPropName];
}
});
this._contentChildrenManager = new ContentChildrenManager(function (ch) {
var key = ch.key || ch.props.name;
if (!key) {
var type = (ch.type);
var instance = new type;
var name_1 = instance.i.$type.name;
switch (name_1) {
case "GridToolbarHiding": return "IgrGridToolbarHiding";
case "GridToolbarPinning": return "IgrGridToolbarPinning";
case "GridToolbarExporter": return "IgrGridToolbarExporter";
case "GridToolbarAdvancedFiltering": return "IgrGridToolbarAdvancedFiltering";
default: return undefined;
}
}
return key;
}, function (ch) {
var key = ch.key || ch.props.name;
if (!key) {
var type = (ch.type);
var instance = new type;
var name_2 = instance.i.$type.name;
switch (name_2) {
case "GridToolbarHiding": return "IgrGridToolbarHiding";
case "GridToolbarPinning": return "IgrGridToolbarPinning";
case "GridToolbarExporter": return "IgrGridToolbarExporter";
case "GridToolbarAdvancedFiltering": return "IgrGridToolbarAdvancedFiltering";
default: return undefined;
}
}
return key;
}, function () {
if (_this._updateContentChildren) {
_this._updateContentChildren();
}
else if (_this._updateAdapters) {
_this._updateAdapters();
}
});
}
this._actionsAdapter = new CollectionAdapter(this.contentActions, this.i.c, this.actualActions, function (c) { return c.i; }, function (i) {
if (_this._initializeElement) {
_this._initializeElement(i);
}
}, function (i) {
if (_this._destroyElement) {
_this._destroyElement(i);
}
});
if (_super.prototype["_initializeAdapters"]) {
_super.prototype["_initializeAdapters"].call(this);
}
};
IgrGridToolbarActions.prototype._updateAdapters = function () {
if (_super.prototype["_updateAdapters"]) {
_super.prototype["_updateAdapters"].call(this);
}
var contentChildrenActual = this._contentChildrenManager.contentChildrenActual;
this.contentActions.length = 0;
for (var i = 0; i < contentChildrenActual.length; i++) {
if ((GridToolbarBaseAction.$type).isAssignableFrom(contentChildrenActual[i].i.$type)) {
this.contentActions.push(contentChildrenActual[i]);
}
}
if (this._actionsAdapter != null) {
this._actionsAdapter.notifyContentChanged();
}
};
IgrGridToolbarActions.prototype.componentDidMount = function () {
this.mounted = true;
_super.prototype.componentDidMount.call(this);
};
IgrGridToolbarActions.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 visibleChildren = [];
React.Children.forEach(this.props.children, function (ch) {
if (ch) {
visibleChildren.push(ch);
}
});
var children = this._contentChildrenManager.getChildren(visibleChildren);
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;
};
IgrGridToolbarActions.prototype._getMainRef = function (ref) {
this._elRef = ref;
};
Object.defineProperty(IgrGridToolbarActions.prototype, "actualActions", {
get: function () {
if (!this._actualActions) {
this._actualActions = [];
}
return this._actualActions;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrGridToolbarActions.prototype, "contentActions", {
get: function () {
if (!this._contentActions) {
this._contentActions = [];
}
return this._contentActions;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrGridToolbarActions.prototype, "actions", {
get: function () {
var _this = this;
if (this._actions === null) {
var coll = new IgrGridToolbarBaseActionCollection();
var inner = coll._innerColl;
this._actions = coll;
inner.addListener(function (sender, e) {
switch (e.action) {
case NotifyCollectionChangedAction.Add:
_this._actionsAdapter.insertManualItem(e.newStartingIndex, e.newItems.item(0));
break;
case NotifyCollectionChangedAction.Remove:
_this._actionsAdapter.removeManualItemAt(e.oldStartingIndex);
break;
case NotifyCollectionChangedAction.Replace:
_this._actionsAdapter.removeManualItemAt(e.oldStartingIndex);
_this._actionsAdapter.insertManualItem(e.newStartingIndex, e.newItems.item(0));
break;
case NotifyCollectionChangedAction.Reset:
_this._actionsAdapter.clearManualItems();
break;
}
});
;
}
return this._actions;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrGridToolbarActions.prototype, "name", {
get: function () {
return this.i.a;
},
set: function (v) {
this.i.a = v;
},
enumerable: false,
configurable: true
});
IgrGridToolbarActions.prototype.findByName = function (name) {
var baseResult = _super.prototype.findByName.call(this, name);
if (baseResult) {
return baseResult;
}
if (this.actions != null && this.actions.findByName && this.actions.findByName(name)) {
return this.actions.findByName(name);
}
return null;
};
IgrGridToolbarActions.prototype.setNativeElement = function (element) {
this.i.setNativeElement(element);
};
return IgrGridToolbarActions;
}(IgrGridToolbarContent));
export { IgrGridToolbarActions };