@up-group/react-controls
Version:
We know that there are a ton of react UI library projects to choose from. Our hope with this one is to provide the next generation of react components that you can use to bootstrap your next project, or as a reference for building a UIKit. Read on to get
74 lines • 5.51 kB
JavaScript
"use strict";
var __extends = (this && this.__extends) || (function () {
var extendStatics = Object.setPrototypeOf ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; };
return function (d, b) {
extendStatics(d, b);
function __() { this.constructor = d; }
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
};
})();
Object.defineProperty(exports, "__esModule", { value: true });
var React = require("react");
var Item_1 = require("./Item");
var utils_1 = require("../utils");
var canResizeLeft = function (item, canResize) {
var value = utils_1._get(item, 'canResize') !== undefined ? utils_1._get(item, 'canResize') : canResize;
return value === 'left' || value === 'both';
};
var canResizeRight = function (item, canResize) {
var value = utils_1._get(item, 'canResize') !== undefined ? utils_1._get(item, 'canResize') : canResize;
return value === 'right' || value === 'both' || value === true;
};
var Items = (function (_super) {
__extends(Items, _super);
function Items(p, c) {
return _super.call(this, p, c) || this;
}
Items.prototype.render = function () {
var _this = this;
var _a = this.props, canvasTimeStart = _a.canvasTimeStart, canvasTimeEnd = _a.canvasTimeEnd, dimensionItems = _a.dimensionItems;
var _b = this.props.keys, itemIdKey = _b.itemIdKey, itemGroupKey = _b.itemGroupKey;
var groupOrders = this.getGroupOrders();
var visibleItems = this.getVisibleItems(canvasTimeStart, canvasTimeEnd, groupOrders);
var sortedDimensionItems = utils_1.keyBy(dimensionItems, 'id');
return (React.createElement("div", { className: 'rct-items' }, visibleItems.filter(function (item) { return sortedDimensionItems[utils_1._get(item, itemIdKey)]; })
.map(function (item) { return React.createElement(Item_1.default, { key: utils_1._get(item, itemIdKey), item: item, keys: _this.props.keys, order: groupOrders[utils_1._get(item, itemGroupKey)], dimensions: sortedDimensionItems[utils_1._get(item, itemIdKey)].dimensions, selected: _this.props.selectedItem === utils_1._get(item, itemIdKey), canChangeGroup: utils_1._get(item, 'canChangeGroup') !== undefined ? utils_1._get(item, 'canChangeGroup') : _this.props.canChangeGroup, canMove: utils_1._get(item, 'canMove') !== undefined ? utils_1._get(item, 'canMove') : _this.props.canMove, canResizeLeft: canResizeLeft(item, _this.props.canResize), canResizeRight: canResizeRight(item, _this.props.canResize), canSelect: utils_1._get(item, 'canSelect') !== undefined ? utils_1._get(item, 'canSelect') : _this.props.canSelect, useResizeHandle: _this.props.useResizeHandle, topOffset: _this.props.topOffset, groupHeights: _this.props.groupHeights, groupTops: _this.props.groupTops, canvasTimeStart: _this.props.canvasTimeStart, canvasTimeEnd: _this.props.canvasTimeEnd, canvasWidth: _this.props.canvasWidth, lineHeight: _this.props.lineHeight, dragSnap: _this.props.dragSnap, minResizeWidth: _this.props.minResizeWidth, onResizing: _this.props.itemResizing, onResized: _this.props.itemResized, moveResizeValidator: _this.props.moveResizeValidator, onDrag: _this.props.itemDrag, onDrop: _this.props.itemDrop, onItemDoubleClick: _this.props.onItemDoubleClick, onContextMenu: _this.props.onItemContextMenu, onSelect: _this.props.itemSelect }); })));
};
Items.prototype.shouldComponentUpdate = function (nextProps, nextState) {
return !(utils_1.arraysEqual(nextProps.groups, this.props.groups) &&
utils_1.arraysEqual(nextProps.items, this.props.items) &&
nextProps.keys === this.props.keys &&
nextProps.canvasTimeStart === this.props.canvasTimeStart &&
nextProps.canvasTimeEnd === this.props.canvasTimeEnd &&
nextProps.canvasWidth === this.props.canvasWidth &&
nextProps.selectedItem === this.props.selectedItem &&
nextProps.lineHeight === this.props.lineHeight &&
nextProps.dragSnap === this.props.dragSnap &&
nextProps.minResizeWidth === this.props.minResizeWidth &&
nextProps.canChangeGroup === this.props.canChangeGroup &&
nextProps.canMove === this.props.canMove &&
nextProps.canResize === this.props.canResize &&
nextProps.canSelect === this.props.canSelect &&
nextProps.dimensionItems === this.props.dimensionItems &&
nextProps.topOffset === this.props.topOffset);
};
Items.prototype.getGroupOrders = function () {
var groupIdKey = this.props.keys.groupIdKey;
var groupOrders = {};
for (var i = 0; i < this.props.groups.length; i++) {
groupOrders[utils_1._get(this.props.groups[i], groupIdKey)] = i;
}
return groupOrders;
};
Items.prototype.getVisibleItems = function (canvasTimeStart, canvasTimeEnd, groupOrders) {
var _a = this.props.keys, itemTimeStartKey = _a.itemTimeStartKey, itemTimeEndKey = _a.itemTimeEndKey;
return this.props.items.filter(function (item) {
return utils_1._get(item, itemTimeStartKey) <= canvasTimeEnd && utils_1._get(item, itemTimeEndKey) >= canvasTimeStart;
});
};
return Items;
}(React.Component));
exports.default = Items;
//# sourceMappingURL=Items.js.map