UNPKG

@yeutech-lab/rollup-umd-documentation

Version:

Quickly build awesome documentation for your rollup-umd project.

146 lines (117 loc) 6.03 kB
'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); var _react = require('react'); var _react2 = _interopRequireDefault(_react); var _propTypes = require('prop-types'); var _propTypes2 = _interopRequireDefault(_propTypes); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } 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; } var _require = require('../../package.json'), homepage = _require.homepage; var withRedux = require('./Wrappers/withRedux'); var withIntl = require('./Wrappers/withIntl'); var propTypes = { /** You can pass `require('redux')` to provide redux to the autoconfiguration */ redux: _propTypes2.default.object, /** You can pass `require('react-redux')` to provide react-redux to the autoconfiguration */ 'react-redux': _propTypes2.default.object, /** You can pass `require('react-intl')` to provide react-intl to the autoconfiguration */ 'react-intl': _propTypes2.default.object, /** If passed, redux will be configured */ reducer: _propTypes2.default.func, /** If passed, react-intl.js will be configured */ messages: _propTypes2.default.object, /** Example will be passed as Wrapper children automatically. */ children: _propTypes2.default.oneOfType([_propTypes2.default.arrayOf(_propTypes2.default.node), _propTypes2.default.node]).isRequired }; var defaultProps = { redux: null, 'react-redux': null, 'react-intl': null, reducer: null, messages: null }; var Wrapper = function (_React$PureComponent) { _inherits(Wrapper, _React$PureComponent); function Wrapper() { var _ref; var _temp, _this, _ret; _classCallCheck(this, Wrapper); for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { args[_key] = arguments[_key]; } return _ret = (_temp = (_this = _possibleConstructorReturn(this, (_ref = Wrapper.__proto__ || Object.getPrototypeOf(Wrapper)).call.apply(_ref, [this].concat(args))), _this), _this.state = { hocList: [] }, _temp), _possibleConstructorReturn(_this, _ret); } _createClass(Wrapper, [{ key: 'componentWillMount', value: function componentWillMount() { var _props = this.props, redux = _props.redux, reactRedux = _props['react-redux'], reactIntl = _props['react-intl'], rest = _objectWithoutProperties(_props, ['redux', 'react-redux', 'react-intl']); var reducer = rest.reducer, messages = rest.messages; var hocList = []; if (reducer) { if (!redux || !reactRedux) { throw new Error('Wrapper: You need to pass the props `redux` and `react-redux` to use props `reducer`, see ' + homepage + '/#wrapper'); } hocList.push(withRedux({ redux: redux, 'react-redux': reactRedux }, reducer)); } if (messages) { if (!redux || !reactRedux || !reactIntl) { throw new Error('Wrapper: You need to pass the props `redux`, `react-redux` and `redux-intl` to use props `reducer`, see ' + homepage + '/#wrapper'); } if (!reducer) { throw new Error('Wrapper: `react-intl` can\'t work without a reducer, see ' + homepage + '/#wrapper'); } var _reducer = reducer(), locale = _reducer.locale; if (!locale) { throw new Error('Wrapper: `react-intl` must have a locale set in redux store, see ' + homepage + '/#wrapper'); } hocList.push(withIntl({ 'react-intl': reactIntl }, locale, messages)); } this.setState({ hocList: hocList }); } }, { key: 'render', value: function render() { var children = this.props.children; if (this.state.hocList.length === 0) { return _react2.default.createElement( 'div', null, children ); } var Component = null; var cursor = void 0; // eslint-disable-next-line no-cond-assign while (cursor = this.state.hocList.shift()) { Component = cursor(Component || 'div'); } return _react2.default.createElement( Component, null, children ); } }]); return Wrapper; }(_react2.default.PureComponent); Wrapper.propTypes = propTypes; Wrapper.defaultProps = defaultProps; exports.default = Wrapper; module.exports = exports['default'];