1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 | 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 5× 5× 5× 5× 1× 1× 1× 1× 5× 5× 5× 5× 2× 1× 1× 1× 1× 1× 1× 1× 1× 1× 1× 3× 3× 3× 3× 14× 14× 6× 14× 5× 14× 1× 6× 5× 4× 4× 1× 3× 1× 1× 1× 3× 3× 3× 3× 3× 1× 1× 1× 1× 14× 1× 1× | 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _propTypes = require('prop-types'); var _propTypes2 = _interopRequireDefault(_propTypes); var _deepcopy = require('deepcopy'); var _deepcopy2 = _interopRequireDefault(_deepcopy); var _deepEqual = require('deep-equal'); var _deepEqual2 = _interopRequireDefault(_deepEqual); var _util = require('./util'); var _util2 = _interopRequireDefault(_util); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { 'default': obj }; } function _defaults(obj, defaults) { var keys = Object.getOwnPropertyNames(defaults); for (var i = 0; i < keys.length; i++) { var key = keys[i]; var value = Object.getOwnPropertyDescriptor(defaults, key); Iif (value && value.configurable && obj[key] === undefined) { Object.defineProperty(obj, key, value); } } return obj; } function _classCallCheck(instance, Constructor) { Iif (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { Iif (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { Iif (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); Eif (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : _defaults(subClass, superClass); } /** * Matrix Component for uxcore * @author eternalsky * * Copyright 2015-2016, Uxcore Team, Alinw. * All rights reserved. */ var Matrix = function (_React$Component) { _inherits(Matrix, _React$Component); function Matrix(props) { _classCallCheck(this, Matrix); var _this = _possibleConstructorReturn(this, _React$Component.call(this, props)); _this.data = (0, _deepcopy2['default'])(props.data); _this.state = { vm: _this.getVirtualMatrix(_this.data) }; return _this; } Matrix.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) { var newState = {}; var vmNeedUpdate = false; Eif (!(0, _deepEqual2['default'])(this.data, nextProps.data)) { this.data = (0, _deepcopy2['default'])(nextProps.data); vmNeedUpdate = true; } Eif (vmNeedUpdate) { newState.vm = this.getVirtualMatrix(this.data); } this.setState(newState); }; Matrix.prototype.getRealMatrix = function getRealMatrix() { var _this2 = this; var _props = this.props, prefixCls = _props.prefixCls, cellHeight = _props.cellHeight, cellWidth = _props.cellWidth; console.log(cellHeight); return this.state.vm.numData.map(function (item, index) { var style = { top: _util2['default'].getSubTotal(cellHeight, 0, item.y), left: _util2['default'].getSubTotal(cellWidth, 0, item.x), width: _util2['default'].getSubTotal(cellWidth, item.x, item.x + item.col), height: _util2['default'].getSubTotal(cellHeight, item.y, item.y + item.row) }; if (item.x === 0) { style.borderLeft = 'none'; } if (item.y === _util2['default'].getLargestArr(_this2.state.vm.vm).length - item.row) { style.borderBottom = 'none'; } return _react2['default'].createElement( 'div', { className: prefixCls + '-cell', key: index, style: style }, _this2.props.render(item, style) ); }); }; Matrix.prototype.getVirtualMatrix = function getVirtualMatrix(data) { if (data && data.data) { if (data.data instanceof Array) { var vm = _util2['default'].generateVM(data.data); if (typeof vm === 'string') { throw new Error(vm); } return vm; } throw new Error('Matrix: props.data.data should be an array'); } throw new Error('Matrix: props.data is required'); }; Matrix.prototype.render = function render() { var _props2 = this.props, prefixCls = _props2.prefixCls, height = _props2.height, width = _props2.width, cellWidth = _props2.cellWidth, cellHeight = _props2.cellHeight; var vm = this.state.vm.vm; var matrixHeight = _util2['default'].getSubTotal(cellHeight, 0, _util2['default'].getLargestArr(vm).length); var matrixWidth = _util2['default'].getSubTotal(cellWidth, 0, vm.length); return _react2['default'].createElement( 'div', { className: '' + prefixCls, style: { height: height || matrixHeight + 2, width: width || matrixWidth + 2 } }, _react2['default'].createElement( 'div', { className: prefixCls + '-wrap', style: { height: matrixHeight, width: matrixWidth } }, this.getRealMatrix() ) ); }; return Matrix; }(_react2['default'].Component); Matrix.displayName = 'Matrix'; Matrix.propTypes = { prefixCls: _propTypes2['default'].string, className: _propTypes2['default'].string, width: _propTypes2['default'].oneOfType([_propTypes2['default'].string, _propTypes2['default'].number]), height: _propTypes2['default'].oneOfType([_propTypes2['default'].string, _propTypes2['default'].number]), cellHeight: _propTypes2['default'].oneOfType([_propTypes2['default'].string, _propTypes2['default'].number, _propTypes2['default'].array]), cellWidth: _propTypes2['default'].oneOfType([_propTypes2['default'].string, _propTypes2['default'].number, _propTypes2['default'].array]), render: _propTypes2['default'].func, data: _propTypes2['default'].object }; Matrix.defaultProps = { prefixCls: 'kuma-matrix', data: {}, cellHeight: 50, cellWidth: 100, render: function render(cell) { return cell.text; } }; exports['default'] = Matrix; module.exports = exports['default']; |