react-extras
Advanced tools
Comparing version 1.0.1 to 2.0.0
@@ -5,36 +5,8 @@ // From https://github.com/sindresorhus/auto-bind/blob/master/index.js | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); } | ||
const getAllProperties = object => { | ||
const props = new Set(); | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } | ||
function _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { return; } var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
var getAllProperties = function getAllProperties(object) { | ||
var props = new Set(); | ||
do { | ||
var _iteratorNormalCompletion = true; | ||
var _didIteratorError = false; | ||
var _iteratorError = undefined; | ||
try { | ||
for (var _iterator = Reflect.ownKeys(object)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true) { | ||
var key = _step.value; | ||
props.add([object, key]); | ||
} | ||
} catch (err) { | ||
_didIteratorError = true; | ||
_iteratorError = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion && _iterator["return"] != null) { | ||
_iterator["return"](); | ||
} | ||
} finally { | ||
if (_didIteratorError) { | ||
throw _iteratorError; | ||
} | ||
} | ||
for (const key of Reflect.ownKeys(object)) { | ||
props.add([object, key]); | ||
} | ||
@@ -46,9 +18,7 @@ } while ((object = Reflect.getPrototypeOf(object)) && object !== Object.prototype); | ||
module.exports = function (self, options) { | ||
module.exports = (self, options) => { | ||
options = Object.assign({}, options); | ||
var filter = function filter(key) { | ||
var match = function match(pattern) { | ||
return typeof pattern === 'string' ? key === pattern : pattern.test(key); | ||
}; | ||
const filter = key => { | ||
const match = pattern => typeof pattern === 'string' ? key === pattern : pattern.test(key); | ||
@@ -66,35 +36,12 @@ if (options.include) { | ||
var _iteratorNormalCompletion2 = true; | ||
var _didIteratorError2 = false; | ||
var _iteratorError2 = undefined; | ||
for (const [object, key] of getAllProperties(self.constructor.prototype)) { | ||
if (key === 'constructor' || !filter(key)) { | ||
continue; | ||
} | ||
try { | ||
for (var _iterator2 = getAllProperties(self.constructor.prototype)[Symbol.iterator](), _step2; !(_iteratorNormalCompletion2 = (_step2 = _iterator2.next()).done); _iteratorNormalCompletion2 = true) { | ||
var _step2$value = _slicedToArray(_step2.value, 2), | ||
object = _step2$value[0], | ||
key = _step2$value[1]; | ||
const descriptor = Reflect.getOwnPropertyDescriptor(object, key); | ||
if (key === 'constructor' || !filter(key)) { | ||
continue; | ||
} | ||
var descriptor = Reflect.getOwnPropertyDescriptor(object, key); | ||
if (descriptor && typeof descriptor.value === 'function') { | ||
self[key] = self[key].bind(self); | ||
} | ||
if (descriptor && typeof descriptor.value === 'function') { | ||
self[key] = self[key].bind(self); | ||
} | ||
} catch (err) { | ||
_didIteratorError2 = true; | ||
_iteratorError2 = err; | ||
} finally { | ||
try { | ||
if (!_iteratorNormalCompletion2 && _iterator2["return"] != null) { | ||
_iterator2["return"](); | ||
} | ||
} finally { | ||
if (_didIteratorError2) { | ||
throw _iteratorError2; | ||
} | ||
} | ||
} | ||
@@ -105,5 +52,5 @@ | ||
var excludedReactMethods = ['componentWillMount', 'UNSAFE_componentWillMount', 'render', 'getSnapshotBeforeUpdate', 'componentDidMount', 'componentWillReceiveProps', 'UNSAFE_componentWillReceiveProps', 'shouldComponentUpdate', 'componentWillUpdate', 'UNSAFE_componentWillUpdate', 'componentDidUpdate', 'componentWillUnmount', 'componentDidCatch', 'setState', 'forceUpdate']; | ||
const excludedReactMethods = ['componentWillMount', 'UNSAFE_componentWillMount', 'render', 'getSnapshotBeforeUpdate', 'componentDidMount', 'componentWillReceiveProps', 'UNSAFE_componentWillReceiveProps', 'shouldComponentUpdate', 'componentWillUpdate', 'UNSAFE_componentWillUpdate', 'componentDidUpdate', 'componentWillUnmount', 'componentDidCatch', 'setState', 'forceUpdate']; | ||
module.exports.react = function (self, options) { | ||
module.exports.react = (self, options) => { | ||
options = Object.assign({}, options); | ||
@@ -110,0 +57,0 @@ options.exclude = (options.exclude || []).concat(excludedReactMethods); |
@@ -1,49 +0,11 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = void 0; | ||
var _react = _interopRequireDefault(require("react")); | ||
var _propTypes = _interopRequireDefault(require("prop-types")); | ||
var _elementClass = _interopRequireDefault(require("./element-class")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
var BodyClass = | ||
/*#__PURE__*/ | ||
function (_ElementClass) { | ||
_inherits(BodyClass, _ElementClass); | ||
function BodyClass() { | ||
var _this; | ||
_classCallCheck(this, BodyClass); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(BodyClass).call(this)); | ||
_this.element = document.body; | ||
return _this; | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import ElementClass from './element-class'; | ||
export default class BodyClass extends ElementClass { | ||
constructor() { | ||
super(); | ||
this.element = document.body; | ||
} | ||
return BodyClass; | ||
}(_elementClass["default"]); | ||
exports["default"] = BodyClass; | ||
BodyClass.propTypes = _elementClass["default"].propTypes; | ||
} | ||
BodyClass.propTypes = ElementClass.propTypes; |
@@ -1,21 +0,9 @@ | ||
"use strict"; | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import If from './if'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = void 0; | ||
var _react = _interopRequireDefault(require("react")); | ||
var _propTypes = _interopRequireDefault(require("prop-types")); | ||
var _if = _interopRequireDefault(require("./if")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
var Choose = function Choose(props) { | ||
var when = null; | ||
var otherwise = null; | ||
_react["default"].Children.forEach(props.children, function (children) { | ||
const Choose = props => { | ||
let when = null; | ||
let otherwise = null; | ||
React.Children.forEach(props.children, children => { | ||
if (children.props.condition === undefined) { | ||
@@ -27,3 +15,2 @@ otherwise = children; | ||
}); | ||
return when || otherwise; | ||
@@ -33,17 +20,15 @@ }; | ||
Choose.propTypes = { | ||
children: _propTypes["default"].node | ||
children: PropTypes.node | ||
}; | ||
Choose.When = _if["default"]; | ||
Choose.When = If; | ||
Choose.Otherwise = function (_ref) { | ||
var render = _ref.render, | ||
children = _ref.children; | ||
return render ? render() : children; | ||
}; | ||
Choose.Otherwise = ({ | ||
render, | ||
children | ||
}) => render ? render() : children; | ||
Choose.Otherwise.propTypes = { | ||
children: _propTypes["default"].node, | ||
render: _propTypes["default"].func | ||
children: PropTypes.node, | ||
render: PropTypes.func | ||
}; | ||
var _default = Choose; | ||
exports["default"] = _default; | ||
export default Choose; |
@@ -5,40 +5,12 @@ // From https://github.com/sindresorhus/class-names/blob/master/index.js | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _nonIterableRest(); } | ||
module.exports = (...args) => { | ||
const ret = new Set(); | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance"); } | ||
for (const item of args) { | ||
const type = typeof item; | ||
function _iterableToArrayLimit(arr, i) { if (!(Symbol.iterator in Object(arr) || Object.prototype.toString.call(arr) === "[object Arguments]")) { return; } var _arr = []; var _n = true; var _d = false; var _e = undefined; try { for (var _i = arr[Symbol.iterator](), _s; !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; } | ||
function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; } | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); } | ||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); } | ||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); } | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } } | ||
module.exports = function () { | ||
var ret = new Set(); | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
for (var _i = 0, _args = args; _i < _args.length; _i++) { | ||
var item = _args[_i]; | ||
var type = _typeof(item); | ||
if (type === 'string' && item.length > 0) { | ||
ret.add(item); | ||
} else if (type === 'object' && item !== null) { | ||
for (var _i2 = 0, _Object$entries = Object.entries(item); _i2 < _Object$entries.length; _i2++) { | ||
var _Object$entries$_i = _slicedToArray(_Object$entries[_i2], 2), | ||
key = _Object$entries$_i[0], | ||
value = _Object$entries$_i[1]; | ||
for (const [key, value] of Object.entries(item)) { | ||
if (value) { | ||
@@ -51,3 +23,3 @@ ret.add(key); | ||
return _toConsumableArray(ret).join(' '); | ||
return [...ret].join(' '); | ||
}; |
@@ -1,97 +0,48 @@ | ||
"use strict"; | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
export default class ElementClass extends React.PureComponent { | ||
componentWillMount() { | ||
const { | ||
add, | ||
remove | ||
} = this.props; | ||
const { | ||
classList | ||
} = this.element; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = void 0; | ||
if (add) { | ||
classList.add(...add.trim().split(' ')); | ||
} | ||
var _react = _interopRequireDefault(require("react")); | ||
var _propTypes = _interopRequireDefault(require("prop-types")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _nonIterableSpread(); } | ||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance"); } | ||
function _iterableToArray(iter) { if (Symbol.iterator in Object(iter) || Object.prototype.toString.call(iter) === "[object Arguments]") return Array.from(iter); } | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = new Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a 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); } } | ||
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
var ElementClass = | ||
/*#__PURE__*/ | ||
function (_React$PureComponent) { | ||
_inherits(ElementClass, _React$PureComponent); | ||
function ElementClass() { | ||
_classCallCheck(this, ElementClass); | ||
return _possibleConstructorReturn(this, _getPrototypeOf(ElementClass).apply(this, arguments)); | ||
if (remove) { | ||
classList.remove(...remove.trim().split(' ')); | ||
} | ||
} | ||
_createClass(ElementClass, [{ | ||
key: "componentWillMount", | ||
value: function componentWillMount() { | ||
var _this$props = this.props, | ||
add = _this$props.add, | ||
remove = _this$props.remove; | ||
var classList = this.element.classList; | ||
componentWillUnmount() { | ||
const { | ||
add, | ||
remove | ||
} = this.props; | ||
const { | ||
classList | ||
} = this.element; | ||
if (add) { | ||
classList.add.apply(classList, _toConsumableArray(add.trim().split(' '))); | ||
} | ||
if (remove) { | ||
classList.remove.apply(classList, _toConsumableArray(remove.trim().split(' '))); | ||
} | ||
if (add) { | ||
classList.remove(...add.trim().split(' ')); | ||
} | ||
}, { | ||
key: "componentWillUnmount", | ||
value: function componentWillUnmount() { | ||
var _this$props2 = this.props, | ||
add = _this$props2.add, | ||
remove = _this$props2.remove; | ||
var classList = this.element.classList; | ||
if (add) { | ||
classList.remove.apply(classList, _toConsumableArray(add.trim().split(' '))); | ||
} | ||
if (remove) { | ||
classList.add.apply(classList, _toConsumableArray(remove.trim().split(' '))); | ||
} | ||
if (remove) { | ||
classList.add(...remove.trim().split(' ')); | ||
} | ||
}, { | ||
key: "render", | ||
value: function render() { | ||
return null; | ||
} | ||
}]); | ||
} | ||
return ElementClass; | ||
}(_react["default"].PureComponent); | ||
render() { | ||
return null; | ||
} | ||
exports["default"] = ElementClass; | ||
} | ||
ElementClass.propTypes = { | ||
add: _propTypes["default"].string, | ||
remove: _propTypes["default"].string | ||
add: PropTypes.string, | ||
remove: PropTypes.string | ||
}; |
@@ -1,27 +0,13 @@ | ||
"use strict"; | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = void 0; | ||
const For = ({ | ||
render, | ||
of | ||
}) => of.map((item, index) => render(item, index)); | ||
var _react = _interopRequireDefault(require("react")); | ||
var _propTypes = _interopRequireDefault(require("prop-types")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
var For = function For(_ref) { | ||
var render = _ref.render, | ||
of = _ref.of; | ||
return of.map(function (item, index) { | ||
return render(item, index); | ||
}); | ||
}; | ||
For.propTypes = { | ||
of: _propTypes["default"].array.isRequired, | ||
render: _propTypes["default"].func.isRequired | ||
of: PropTypes.array.isRequired, | ||
render: PropTypes.func.isRequired | ||
}; | ||
var _default = For; | ||
exports["default"] = _default; | ||
export default For; |
@@ -1,24 +0,11 @@ | ||
"use strict"; | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = void 0; | ||
const If = props => props.condition ? props.render ? props.render() : props.children : null; | ||
var _react = _interopRequireDefault(require("react")); | ||
var _propTypes = _interopRequireDefault(require("prop-types")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
var If = function If(props) { | ||
return props.condition ? props.render ? props.render() : props.children : null; | ||
}; | ||
If.propTypes = { | ||
condition: _propTypes["default"].bool.isRequired, | ||
children: _propTypes["default"].node, | ||
render: _propTypes["default"].func | ||
condition: PropTypes.bool.isRequired, | ||
children: PropTypes.node, | ||
render: PropTypes.func | ||
}; | ||
var _default = If; | ||
exports["default"] = _default; | ||
export default If; |
@@ -1,42 +0,26 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = void 0; | ||
var _react = _interopRequireDefault(require("react")); | ||
var _propTypes = _interopRequireDefault(require("prop-types")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); } | ||
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; } | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; } | ||
const Image = ({ | ||
url, | ||
fallbackUrl, | ||
...props | ||
}) => React.createElement("img", _extends({}, props, { | ||
src: url, | ||
onError: event => { | ||
const element = event.currentTarget; | ||
var Image = function Image(_ref) { | ||
var url = _ref.url, | ||
fallbackUrl = _ref.fallbackUrl, | ||
props = _objectWithoutProperties(_ref, ["url", "fallbackUrl"]); | ||
return _react["default"].createElement("img", _extends({}, props, { | ||
src: url, | ||
onError: function onError(event) { | ||
var element = event.currentTarget; | ||
if (fallbackUrl) { | ||
element.src = fallbackUrl; | ||
} else { | ||
element.style.visibility = 'hidden'; | ||
} | ||
if (fallbackUrl) { | ||
element.src = fallbackUrl; | ||
} else { | ||
element.style.visibility = 'hidden'; | ||
} | ||
})); | ||
}; | ||
} | ||
})); | ||
Image.propTypes = { | ||
url: _propTypes["default"].string.isRequired, | ||
fallbackUrl: _propTypes["default"].string | ||
url: PropTypes.string.isRequired, | ||
fallbackUrl: PropTypes.string | ||
}; | ||
@@ -46,3 +30,2 @@ Image.defaultProps = { | ||
}; | ||
var _default = Image; | ||
exports["default"] = _default; | ||
export default Image; |
@@ -1,86 +0,11 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
Object.defineProperty(exports, "autoBind", { | ||
enumerable: true, | ||
get: function get() { | ||
return _autoBind.react; | ||
} | ||
}); | ||
Object.defineProperty(exports, "classNames", { | ||
enumerable: true, | ||
get: function get() { | ||
return _classNames["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "If", { | ||
enumerable: true, | ||
get: function get() { | ||
return _if["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "Choose", { | ||
enumerable: true, | ||
get: function get() { | ||
return _choose["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "For", { | ||
enumerable: true, | ||
get: function get() { | ||
return _for["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "Image", { | ||
enumerable: true, | ||
get: function get() { | ||
return _image["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "RootClass", { | ||
enumerable: true, | ||
get: function get() { | ||
return _rootClass["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, "BodyClass", { | ||
enumerable: true, | ||
get: function get() { | ||
return _bodyClass["default"]; | ||
} | ||
}); | ||
exports.canUseDOM = exports.getDisplayName = exports.isStatelessComponent = void 0; | ||
var _autoBind = require("./auto-bind"); | ||
var _classNames = _interopRequireDefault(require("./class-names")); | ||
var _if = _interopRequireDefault(require("./if")); | ||
var _choose = _interopRequireDefault(require("./choose")); | ||
var _for = _interopRequireDefault(require("./for")); | ||
var _image = _interopRequireDefault(require("./image")); | ||
var _rootClass = _interopRequireDefault(require("./root-class")); | ||
var _bodyClass = _interopRequireDefault(require("./body-class")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
var isStatelessComponent = function isStatelessComponent(Component) { | ||
return !(typeof Component.prototype !== 'undefined' && typeof Component.prototype.render === 'function'); | ||
}; | ||
exports.isStatelessComponent = isStatelessComponent; | ||
var getDisplayName = function getDisplayName(Component) { | ||
return Component.displayName || Component.name || 'Component'; | ||
}; | ||
exports.getDisplayName = getDisplayName; | ||
var canUseDOM = typeof window !== 'undefined' && 'document' in window && 'createElement' in window.document; | ||
exports.canUseDOM = canUseDOM; | ||
export { default as autoBind } from 'auto-bind/react'; | ||
export { default as classNames } from '@sindresorhus/class-names'; | ||
export const isStatelessComponent = Component => !(typeof Component.prototype !== 'undefined' && typeof Component.prototype.render === 'function'); | ||
export const getDisplayName = Component => Component.displayName || Component.name || 'Component'; | ||
export const canUseDOM = typeof window !== 'undefined' && 'document' in window && 'createElement' in window.document; | ||
export { default as If } from './if.js'; | ||
export { default as Choose } from './choose.js'; | ||
export { default as For } from './for.js'; | ||
export { default as Image } from './image.js'; | ||
export { default as RootClass } from './root-class.js'; | ||
export { default as BodyClass } from './body-class.js'; |
@@ -1,49 +0,11 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = void 0; | ||
var _react = _interopRequireDefault(require("react")); | ||
var _propTypes = _interopRequireDefault(require("prop-types")); | ||
var _elementClass = _interopRequireDefault(require("./element-class")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); } | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); } | ||
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); } | ||
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); } | ||
var RootClass = | ||
/*#__PURE__*/ | ||
function (_ElementClass) { | ||
_inherits(RootClass, _ElementClass); | ||
function RootClass() { | ||
var _this; | ||
_classCallCheck(this, RootClass); | ||
_this = _possibleConstructorReturn(this, _getPrototypeOf(RootClass).call(this)); | ||
_this.element = document.documentElement; | ||
return _this; | ||
import React from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import ElementClass from './element-class'; | ||
export default class RootClass extends ElementClass { | ||
constructor() { | ||
super(); | ||
this.element = document.documentElement; | ||
} | ||
return RootClass; | ||
}(_elementClass["default"]); | ||
exports["default"] = RootClass; | ||
RootClass.propTypes = _elementClass["default"].propTypes; | ||
} | ||
RootClass.propTypes = ElementClass.propTypes; |
import {Component as ReactComponent, ComponentClass, HTMLProps, ReactNode} from 'react'; | ||
import classNames = require('@sindresorhus/class-names'); | ||
import autoBind = require('auto-bind/react'); | ||
interface AutoBindOptions { | ||
/** | ||
Bind only the given methods. | ||
*/ | ||
readonly include?: ReadonlyArray<string | RegExp>; | ||
/** | ||
Bind methods except for the given methods. | ||
*/ | ||
readonly exclude?: ReadonlyArray<string | RegExp>; | ||
} | ||
/** | ||
@@ -35,6 +25,3 @@ Automatically binds your `Component` subclass methods to the instance. | ||
*/ | ||
export function autoBind<T extends ReactNode>( | ||
self: T, | ||
options?: AutoBindOptions | ||
): T; | ||
export {autoBind}; | ||
@@ -85,3 +72,3 @@ /** | ||
*/ | ||
export function classNames(...input: Array<string | {[className: string]: any}>): string; | ||
export {classNames}; | ||
@@ -88,0 +75,0 @@ /** |
{ | ||
"name": "react-extras", | ||
"version": "1.0.1", | ||
"version": "2.0.0", | ||
"description": "Useful components and utilities for working with React", | ||
"license": "MIT", | ||
"repository": "sindresorhus/react-extras", | ||
"funding": "https://github.com/sponsors/sindresorhus", | ||
"author": { | ||
"name": "Sindre Sorhus", | ||
"email": "sindresorhus@gmail.com", | ||
"url": "sindresorhus.com" | ||
"url": "https://sindresorhus.com" | ||
}, | ||
"type": "module", | ||
"main": "./dist/index.js", | ||
"engines": { | ||
"node": ">=8" | ||
"node": ">=10" | ||
}, | ||
@@ -19,3 +21,3 @@ "scripts": { | ||
"test": "xo && ava && tsd", | ||
"prepublishOnly": "npm run build" | ||
"prepare": "npm run build" | ||
}, | ||
@@ -46,2 +48,4 @@ "files": [ | ||
"dependencies": { | ||
"@sindresorhus/class-names": "^1.1.0", | ||
"auto-bind": "^4.0.0", | ||
"prop-types": "^15.6.2" | ||
@@ -52,4 +56,2 @@ }, | ||
"@babel/core": "^7.2.2", | ||
"@babel/plugin-transform-modules-commonjs": "^7.2.0", | ||
"@babel/preset-env": "^7.2.3", | ||
"@babel/preset-react": "^7.0.0", | ||
@@ -59,4 +61,4 @@ "@babel/register": "^7.0.0", | ||
"ava": "^2.4.0", | ||
"babel-eslint": "^10.0.1", | ||
"browser-env": "^3.2.5", | ||
"esm": "^3.2.25", | ||
"jest-prop-type-error": "^1.1.0", | ||
@@ -77,14 +79,12 @@ "react": "^16.7.0", | ||
], | ||
"parser": "babel-eslint", | ||
"rules": { | ||
"import/no-unresolved": "off", | ||
"no-unused-vars": "off" | ||
}, | ||
"ignores": [ | ||
"source/auto-bind.js", | ||
"source/class-names.js" | ||
] | ||
"import/extensions": "off", | ||
"no-unused-vars": "off", | ||
"@typescript-eslint/no-unused-vars": "off", | ||
"@typescript-eslint/explicit-function-return-type": "off" | ||
} | ||
}, | ||
"ava": { | ||
"require": [ | ||
"esm", | ||
"@babel/register", | ||
@@ -95,7 +95,3 @@ "jest-prop-type-error" | ||
"babel": { | ||
"plugins": [ | ||
"@babel/plugin-transform-modules-commonjs" | ||
], | ||
"presets": [ | ||
"@babel/preset-env", | ||
"@babel/preset-react" | ||
@@ -102,0 +98,0 @@ ] |
Sorry, the diff of this file is not supported yet
14
Yes
22989
4
476
+ Addedauto-bind@^4.0.0
+ Added@sindresorhus/class-names@1.1.0(transitive)
+ Addedauto-bind@4.0.0(transitive)