diff --git a/.babelrc b/.babelrc index 76730ac..81c1c09 100644 --- a/.babelrc +++ b/.babelrc @@ -1,6 +1,6 @@ { "presets": ["es2015-loose", "stage-1"], - "plugins": ["transform-object-assign", "transform-object-entries"], + "plugins": ["transform-object-assign", "transform-es2017-object-entries"], "env": { "test": { diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 876ee5c..0243850 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -2,9 +2,12 @@ - - + + + + + @@ -18,44 +21,42 @@ - - - + + + - - + + - - - - - - - - - - - - - + - + - - + + - - + + + + + + + + + + + + @@ -64,62 +65,48 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - + + - - + + - - - - - - - - - - - - + + - + + + + + + + + + + + + + + + + + + + + + @@ -127,6 +114,24 @@ + + + e + entr + ent + a + ass + assi + assig + assign + splitComponentProps + + + I:\yonyou\iuap\tinper-bee-core + I:\yonyou\iuap\tinper-bee-core\js + I:\yonyou\iuap\tinper-bee-core\lib + + @@ -136,6 +141,8 @@ @@ -147,9 +154,12 @@ true DEFINITION_ORDER + + + - @@ -168,8 +178,6 @@ - - @@ -210,26 +218,10 @@ - - - - - - - - - - + + @@ -294,6 +286,12 @@ + project + + + + + @@ -328,32 +326,33 @@ - - + - + + - - + + - + - + - - + @@ -368,23 +367,25 @@ - + - - + + - + - - - + + + + + - + @@ -392,11 +393,67 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - @@ -404,15 +461,6 @@ - - - - - - - - - @@ -445,7 +493,7 @@ - + @@ -460,8 +508,8 @@ - - + + @@ -469,7 +517,7 @@ - + @@ -484,7 +532,7 @@ - + @@ -492,17 +540,17 @@ - + - + - + @@ -516,23 +564,171 @@ - + - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/lib/Align.js b/lib/Align.js index 41e3795..347755a 100644 --- a/lib/Align.js +++ b/lib/Align.js @@ -10,10 +10,6 @@ var _reactDom = require('react-dom'); var _reactDom2 = _interopRequireDefault(_reactDom); -var _createReactClass = require('create-react-class'); - -var _createReactClass2 = _interopRequireDefault(_createReactClass); - var _domAlign = require('dom-align'); var _domAlign2 = _interopRequireDefault(_domAlign); @@ -24,6 +20,12 @@ var _addEventListener2 = _interopRequireDefault(_addEventListener); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } +function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } + +function _possibleConstructorReturn(self, call) { if (!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) { if (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 } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } + //import isWindow from './isWindow'; function isWindow(obj) { @@ -52,39 +54,48 @@ function buffer(fn, ms) { return bufferFn; } -var Align = _react2.default.createClass({ - propTypes: { - childrenProps: _react.PropTypes.object, - align: _react.PropTypes.object.isRequired, - target: _react.PropTypes.func, - onAlign: _react.PropTypes.func, - monitorBufferTime: _react.PropTypes.number, - monitorWindowResize: _react.PropTypes.bool, - disabled: _react.PropTypes.bool, - children: _react.PropTypes.any - }, +var Align = function (_Component) { + _inherits(Align, _Component); - getDefaultProps: function getDefaultProps() { - return { - target: function target() { - return window; - }, - onAlign: function onAlign() {}, + function Align() { + var _temp, _this, _ret; - monitorBufferTime: 50, - monitorWindowResize: false, - disabled: false - }; - }, - componentDidMount: function componentDidMount() { + _classCallCheck(this, Align); + + for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { + args[_key] = arguments[_key]; + } + + return _ret = (_temp = (_this = _possibleConstructorReturn(this, _Component.call.apply(_Component, [this].concat(args))), _this), _this.startMonitorWindowResize = function () { + if (!_this.resizeHandler) { + _this.bufferMonitor = buffer(_this.forceAlign, _this.props.monitorBufferTime); + _this.resizeHandler = (0, _addEventListener2.default)(window, 'resize', _this.bufferMonitor); + } + }, _this.stopMonitorWindowResize = function () { + if (_this.resizeHandler) { + _this.bufferMonitor.clear(); + _this.resizeHandler.remove(); + _this.resizeHandler = null; + } + }, _this.forceAlign = function () { + var props = _this.props; + if (!props.disabled) { + var source = _reactDom2.default.findDOMNode(_this); + props.onAlign(source, (0, _domAlign2.default)(source, props.target(), props.align)); + } + }, _temp), _possibleConstructorReturn(_this, _ret); + } + + Align.prototype.componentDidMount = function componentDidMount() { var props = this.props; // if parent ref not attached .... use document.getElementById this.forceAlign(); if (!props.disabled && props.monitorWindowResize) { this.startMonitorWindowResize(); } - }, - componentDidUpdate: function componentDidUpdate(prevProps) { + }; + + Align.prototype.componentDidUpdate = function componentDidUpdate(prevProps) { var reAlign = false; var props = this.props; @@ -111,31 +122,13 @@ var Align = _react2.default.createClass({ } else { this.stopMonitorWindowResize(); } - }, - componentWillUnmount: function componentWillUnmount() { + }; + + Align.prototype.componentWillUnmount = function componentWillUnmount() { this.stopMonitorWindowResize(); - }, - startMonitorWindowResize: function startMonitorWindowResize() { - if (!this.resizeHandler) { - this.bufferMonitor = buffer(this.forceAlign, this.props.monitorBufferTime); - this.resizeHandler = (0, _addEventListener2.default)(window, 'resize', this.bufferMonitor); - } - }, - stopMonitorWindowResize: function stopMonitorWindowResize() { - if (this.resizeHandler) { - this.bufferMonitor.clear(); - this.resizeHandler.remove(); - this.resizeHandler = null; - } - }, - forceAlign: function forceAlign() { - var props = this.props; - if (!props.disabled) { - var source = _reactDom2.default.findDOMNode(this); - props.onAlign(source, (0, _domAlign2.default)(source, props.target(), props.align)); - } - }, - render: function render() { + }; + + Align.prototype.render = function render() { var _props = this.props, childrenProps = _props.childrenProps, children = _props.children; @@ -151,7 +144,31 @@ var Align = _react2.default.createClass({ return _react2.default.cloneElement(child, newProps); } return child; - } -}); + }; + + return Align; +}(_react.Component); + +Align.propTypes = { + childrenProps: _react.PropTypes.object, + align: _react.PropTypes.object.isRequired, + target: _react.PropTypes.func, + onAlign: _react.PropTypes.func, + monitorBufferTime: _react.PropTypes.number, + monitorWindowResize: _react.PropTypes.bool, + disabled: _react.PropTypes.bool, + children: _react.PropTypes.any +}; +Align.defaultProps = { + target: function target() { + return window; + }, + onAlign: function onAlign() {}, + + monitorBufferTime: 50, + monitorWindowResize: false, + disabled: false +}; +; exports.default = Align; \ No newline at end of file diff --git a/lib/keyCode.js b/lib/keyCode.js index 7d3b325..d3f44f8 100644 --- a/lib/keyCode.js +++ b/lib/keyCode.js @@ -1,4 +1,10 @@ +'use strict'; +/** + * @ignore + * some key-codes definition and utils from closure-library + * @author yiminghe@gmail.com + */ var KeyCode = { /** @@ -424,7 +430,7 @@ var KeyCode = { }; /* - 是否是同时输入文本和特殊的按键的组合键 + whether text and modified key is entered at the same time. */ KeyCode.isTextModifyingKeyEvent = function isTextModifyingKeyEvent(e) { var keyCode = e.keyCode; @@ -467,7 +473,7 @@ KeyCode.isTextModifyingKeyEvent = function isTextModifyingKeyEvent(e) { }; /* - 是否是文本按键 + whether character is entered. */ KeyCode.isCharacterKey = function isCharacterKey(keyCode) { if (keyCode >= KeyCode.ZERO && keyCode <= KeyCode.NINE) { diff --git a/lib/splitComponent.js b/lib/splitComponent.js index f1a98ba..a83449c 100644 --- a/lib/splitComponent.js +++ b/lib/splitComponent.js @@ -1,15 +1,13 @@ "use strict"; -exports.__esModule = true; +(exports.__esModule = true, exports.default = splitComponentProps, function _objectEntries(obj) { + var entries = []; + var keys = Object.keys(obj); -var _entries = require("babel-runtime/core-js/object/entries"); - -var _entries2 = _interopRequireDefault(_entries); - -exports.default = splitComponentProps; - -function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } + for (var k = 0; k < keys.length; ++k) entries.push([keys[k], obj[keys[k]]]); + return entries; +}) /** * 分割要传入父元素和子元素的props * @param {[object]} props 传入的属性 @@ -22,7 +20,7 @@ function splitComponentProps(props, Component) { var parentProps = {}; var childProps = {}; - (0, _entries2.default)(props).forEach(function (_ref) { + _objectEntries(props).forEach(function (_ref) { var propName = _ref[0], propValue = _ref[1]; diff --git a/package.json b/package.json index 98c4f43..20ac7fc 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "tinper-bee-core", - "version": "0.2.5", + "version": "0.3.0", "description": "style core and js util for tinper-bee", "main": "lib/index.js", "engines": { @@ -25,8 +25,9 @@ "devDependencies": { "babel-cli": "^6.18.0", "babel-plugin-istanbul": "^3.0.0", + "babel-plugin-transform-es2017-object-entries": "0.0.4", "babel-plugin-transform-object-assign": "^6.8.0", - "babel-plugin-transform-object-entries": "^1.0.0", + "babel-plugin-transform-runtime": "^6.23.0", "babel-preset-es2015": "^6.18.0", "babel-preset-es2015-loose": "^8.0.0", "babel-preset-stage-1": "^6.16.0",