igniteui-react-grids
Version:
Ignite UI React grid components.
366 lines (360 loc) • 12.1 kB
JavaScript
import { __assign, __extends, __values } from "tslib";
import * as React from 'react';
import { RowDirective } from "./RowDirective";
import { TypeRegistrar } from "igniteui-react-core";
import { ReactRenderer, PortalManager } from "igniteui-react-core";
import { NamePatcher, getModifiedProps, isValidProp, ensureBool, toSpinal, initializePropertiesFromCss } from "igniteui-react-core";
var IgrRowDirective = /** @class */ /*@__PURE__*/ (function (_super) {
__extends(IgrRowDirective, _super);
function IgrRowDirective(props) {
var _this = _super.call(this, props) || this;
_this.mounted = false;
_this.__p = null;
_this._hasUserValues = new Set();
_this._stylingContainer = null;
_this._stylingParent = null;
_this._inStyling = false;
if (_this._styling) {
NamePatcher.ensureStylablePatched(Object.getPrototypeOf(_this));
}
_this._implementation = _this.createImplementation();
_this._portalManager = new PortalManager("templates", function () {
if (_this.mounted) {
_this.setState({});
}
});
if (typeof window !== 'undefined' && typeof document !== 'undefined') {
_this._renderer = new ReactRenderer(_this._implementation.nativeElement, document, false, null, _this._portalManager);
}
_this._implementation.externalObject = _this;
_this.onImplementationCreated();
if (_this._initializeAdapters) {
_this._initializeAdapters();
}
return _this;
}
IgrRowDirective.prototype.createImplementation = function () {
return new RowDirective();
};
Object.defineProperty(IgrRowDirective.prototype, "nativeElement", {
get: function () {
return this._implementation.nativeElement;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrRowDirective.prototype, "i", {
/**
* @hidden
*/
get: function () {
return this._implementation;
} /**
* @hidden
*/,
enumerable: false,
configurable: true
});
IgrRowDirective._createFromInternal = function (internal) {
if (!internal) {
return null;
}
if (!internal.$type) {
return null;
}
var name = internal.$type.name;
var externalName = "Igr" + name;
if (!TypeRegistrar.isRegistered(externalName)) {
return null;
}
return TypeRegistrar.create(externalName);
};
IgrRowDirective.prototype.onImplementationCreated = function () {
};
IgrRowDirective.prototype.componentDidMount = function () {
var e_1, _a;
this.mounted = true;
try {
for (var _b = __values(Object.keys(this.props)), _c = _b.next(); !_c.done; _c = _b.next()) {
var p = _c.value;
if (isValidProp(this, p)) {
this[p] = this.props[p];
}
}
}
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;
}
}
};
IgrRowDirective.prototype.shouldComponentUpdate = function (nextProps, nextState) {
var e_2, _a;
var mod = getModifiedProps(this.props, nextProps);
try {
for (var _b = __values(Object.keys(mod)), _c = _b.next(); !_c.done; _c = _b.next()) {
var p = _c.value;
if (isValidProp(this, p)) {
this[p] = mod[p];
}
}
}
catch (e_2_1) {
e_2 = { error: e_2_1 };
}
finally {
try {
if (_c && !_c.done && (_a = _b.return))
_a.call(_b);
}
finally {
if (e_2)
throw e_2.error;
}
}
return true;
};
IgrRowDirective.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 = {};
if (this.props.style) {
style = this.props.style;
}
var div = React.createElement("igc-row-directive", __assign(__assign({}, nativeProps), { ref: this._getMainRef, id: this.props.id, class: this.props.className, style: style, children: children }));
return div;
};
IgrRowDirective.prototype._getMainRef = function (ref) {
this._elRef = ref;
};
Object.defineProperty(IgrRowDirective.prototype, "data", {
/**
* The data passed to the row component.
* ```typescript
* // get the row data for the first selected row
* let selectedRowData = this.grid.selectedRows[0].data;
* ```
*/
get: function () {
return this.i.h;
},
set: function (v) {
this.i.h = v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrRowDirective.prototype, "index", {
/**
* The index of the row.
* ```typescript
* // get the index of the second selected row
* let selectedRowIndex = this.grid.selectedRows[1].index;
* ```
*/
get: function () {
return this.i.f;
},
set: function (v) {
this.i.f = +v;
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrRowDirective.prototype, "disabled", {
/**
* Sets whether this specific row has disabled functionality for editing and row selection.
* Default value is `false`.
* ```typescript
* this.grid.selectedRows[0].pinned = true;
* ```
*/
get: function () {
return this.i.c;
},
set: function (v) {
this.i.c = ensureBool(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrRowDirective.prototype, "pinned", {
/**
* Sets whether the row is pinned.
* Default value is `false`.
* ```typescript
* this.grid.selectedRows[0].pinned = true;
* ```
*/
get: function () {
return this.i.e;
},
set: function (v) {
this.i.e = ensureBool(v);
},
enumerable: false,
configurable: true
});
Object.defineProperty(IgrRowDirective.prototype, "expanded", {
/**
* Gets the expanded state of the row.
* ```typescript
* let isExpanded = row.expanded;
* ```
*/
get: function () {
return this.i.d;
},
set: function (v) {
this.i.d = ensureBool(v);
},
enumerable: false,
configurable: true
});
IgrRowDirective.prototype.findByName = function (name) {
if (this.findEphemera) {
if (name && name.indexOf("@@e:") == 0) {
return this.findEphemera(name);
}
}
return null;
};
Object.defineProperty(IgrRowDirective.prototype, "hasUserValues", {
get: function () {
return this._hasUserValues;
},
enumerable: false,
configurable: true
});
IgrRowDirective.prototype.__m = function (propertyName) {
if (!this._inStyling) {
this._hasUserValues.add(propertyName);
}
};
IgrRowDirective.prototype._styling = function (container, component, parent) {
if (this._inStyling) {
return;
}
this._inStyling = true;
this._stylingContainer = container;
this._stylingParent = component;
var genericPrefix = "";
var typeName = this.i.$type.name;
if (typeName.indexOf("Xam") === 0) {
typeName = typeName.substring(3);
}
genericPrefix = toSpinal("RowDirective");
var additionalPrefixes = [];
var prefix = toSpinal(typeName);
additionalPrefixes.push(prefix + "-");
var b = this.i.$type.baseType;
while (b && b.name != "Object" &&
b.name != "Base" &&
b.name != "Control" &&
b.Name != "DependencyObject" &&
b.Name != "FrameworkElement") {
typeName = b.name;
if (typeName.indexOf("Xam") === 0) {
typeName = typeName.substring(3);
}
var basePrefix = toSpinal(typeName);
additionalPrefixes.push(basePrefix + "-");
b = b.baseType;
}
if (parent) {
var parentTypeName = parent.i.$type.name;
if (parentTypeName.indexOf("Xam") === 0) {
parentTypeName = parentTypeName.substring(3);
}
var parentPrefix = toSpinal(parentTypeName);
additionalPrefixes.push(parentPrefix + "-" + genericPrefix + "-");
additionalPrefixes.push(parentPrefix + "-" + prefix + "-");
}
initializePropertiesFromCss(container, this, genericPrefix + "-", this.hasUserValues, false, additionalPrefixes);
if (this._otherStyling) {
this._otherStyling(container, component, parent);
}
this._inStyling = false;
};
IgrRowDirective.prototype.setNativeElement = function (element) {
this.i.setNativeElement(element);
};
/**
* Updates the specified row object and the data source record with the passed value.
* ```typescript
* // update the second selected row's value
* let newValue = "Apple";
* this.grid.selectedRows[1].update(newValue);
* ```
*/
IgrRowDirective.prototype.update = function (value) {
this.i.p(value);
};
/**
* Removes the specified row from the grid's data source.
* This method emits `rowDeleted` event.
* ```typescript
* // delete the third selected row from the grid
* this.grid.selectedRows[2].delete();
* ```
*/
IgrRowDirective.prototype.del = function () {
this.i.k();
};
IgrRowDirective.prototype.isCellActive = function (visibleColumnIndex) {
this.i.l(visibleColumnIndex);
};
/**
* Pins the specified row.
* This method emits `rowPinning`\`rowPinned` event.
* ```typescript
* // pin the selected row from the grid
* this.grid.selectedRows[0].pin();
* ```
*/
IgrRowDirective.prototype.pin = function () {
this.i.m();
};
/**
* Unpins the specified row.
* This method emits `rowPinning`\`rowPinned` event.
* ```typescript
* // unpin the selected row from the grid
* this.grid.selectedRows[0].unpin();
* ```
*/
IgrRowDirective.prototype.unpin = function () {
this.i.o();
};
/**
* Spawns the add row UI for the specific row.
* @example
* ```typescript
* const row = this.grid1.getRowByIndex(1);
* row.beginAddRow();
* ```
*/
IgrRowDirective.prototype.beginAddRow = function () {
this.i.j();
};
return IgrRowDirective;
}(React.Component));
export { IgrRowDirective };