react-input-message
Advanced tools
Comparing version 0.9.4 to 0.10.0
'use strict'; | ||
exports.__esModule = true; | ||
var _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; }; | ||
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'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
var _react2 = _interopRequireDefault(_react); | ||
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; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var React = require('react'); | ||
var shallowEqual = require('./shallowEqual'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
var stringOrArrayofStrings = React.PropTypes.oneOfType([React.PropTypes.string, React.PropTypes.arrayOf(React.PropTypes.string)]); | ||
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; } | ||
module.exports = function (Component) { | ||
return (function (_React$Component) { | ||
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; } | ||
exports.default = function (Component) { | ||
var _class, _temp; | ||
return _temp = _class = function (_React$Component) { | ||
_inherits(MessageListener, _React$Component); | ||
@@ -23,16 +28,7 @@ | ||
_React$Component.apply(this, arguments); | ||
return _possibleConstructorReturn(this, _React$Component.apply(this, arguments)); | ||
} | ||
MessageListener.prototype.shouldComponentUpdate = function shouldComponentUpdate(nextProps, nextState, nextContext) { | ||
if (!(nextContext || {}).messageContainer) return true; | ||
if (!this.state && nextState) return true; | ||
if (this.state && !nextState) return true; | ||
if (this.state.active !== nextState.active) return true; | ||
return !shallowEqual(this.state.messages, nextState.messages) || !shallowEqual(this.props, nextProps); | ||
}; | ||
MessageListener.prototype.componentWillMount = function componentWillMount() { | ||
var _this = this; | ||
var _this2 = this; | ||
@@ -42,4 +38,4 @@ var container = this.context.messageContainer; | ||
if (container) { | ||
this.unsubscribe = container.subscribe(function (getMessages) { | ||
_this.setState(_this._getValidationState(getMessages)); | ||
this.unsubscribe = container.subscribe(function (messages) { | ||
_this2.setState({ messages: messages }); | ||
}); | ||
@@ -54,35 +50,11 @@ } | ||
MessageListener.prototype.render = function render() { | ||
return React.createElement(Component, _extends({}, this.props, this.state)); | ||
return _react2.default.createElement(Component, _extends({}, this.props, this.state)); | ||
}; | ||
MessageListener.prototype._getValidationState = function _getValidationState(getMessages) { | ||
var messages = getMessages(this.props['for'], this.props.group); | ||
return MessageListener; | ||
}(_react2.default.Component), _class.DecoratedComponent = Component, _class.contextTypes = { | ||
messageContainer: _react2.default.PropTypes.object | ||
}, _temp; | ||
}; | ||
return { | ||
messages: messages, | ||
active: !!(messages && Object.keys(messages).length) | ||
}; | ||
}; | ||
_createClass(MessageListener, null, [{ | ||
key: 'DecoratedComponent', | ||
value: Component, | ||
enumerable: true | ||
}, { | ||
key: 'propTypes', | ||
value: { | ||
'for': stringOrArrayofStrings, | ||
group: stringOrArrayofStrings | ||
}, | ||
enumerable: true | ||
}, { | ||
key: 'contextTypes', | ||
value: { | ||
messageContainer: React.PropTypes.object | ||
}, | ||
enumerable: true | ||
}]); | ||
return MessageListener; | ||
})(React.Component); | ||
}; | ||
module.exports = exports['default']; |
132
Message.js
'use strict'; | ||
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 _connectToMessageContainer = require('./connectToMessageContainer'); | ||
var _connectToMessageContainer2 = _interopRequireDefault(_connectToMessageContainer); | ||
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 _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } | ||
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; } | ||
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; } | ||
var React = require('react'), | ||
connectToMessageContainer = require('./connectToMessageContainer'); | ||
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; } | ||
@@ -23,3 +30,17 @@ var values = function values(obj) { | ||
var Message = (function (_React$Component) { | ||
function messagesForNames(names, messages) { | ||
if (!names.length) return messages; | ||
var messagesForNames = {}; | ||
names.forEach(function (name) { | ||
if (messages[name]) messagesForNames[name] = messages[name]; | ||
}); | ||
return messagesForNames; | ||
} | ||
var stringOrArrayOfStrings = _react.PropTypes.oneOfType([_react.PropTypes.string, _react.PropTypes.arrayOf(_react.PropTypes.string)]); | ||
var Message = function (_React$Component) { | ||
_inherits(Message, _React$Component); | ||
@@ -30,47 +51,86 @@ | ||
_React$Component.apply(this, arguments); | ||
return _possibleConstructorReturn(this, _React$Component.apply(this, arguments)); | ||
} | ||
Message.prototype.render = function render() { | ||
Message.prototype.componentWillMount = function componentWillMount() { | ||
var _props = this.props; | ||
var Component = _props.component; | ||
var messagesForNames = _props.messagesForNames; | ||
var messages = _props.messages; | ||
var active = _props.active; | ||
var delim = _props.delim; | ||
var extract = _props.extract; | ||
var filter = _props.filter; | ||
var fieldFor = _props['for']; | ||
var props = _objectWithoutProperties(_props, ['component', 'messages', 'active', 'delim', 'extract', 'filter', 'for']); | ||
var props = _objectWithoutProperties(_props, ['messagesForNames', 'messages']); | ||
if (!active) return null; | ||
this.setState({ | ||
messages: messagesForNames.apply(undefined, [this.resolveNames(), messages].concat(props)) | ||
}); | ||
}; | ||
return React.createElement( | ||
Message.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps, nextContext) { | ||
var messagesForNames = nextProps.messagesForNames; | ||
var messages = nextProps.messages; | ||
var props = _objectWithoutProperties(nextProps, ['messagesForNames', 'messages']); | ||
this.setState({ | ||
messages: messagesForNames.apply(undefined, [this.resolveNames(nextProps, nextContext), messages].concat(props)) | ||
}); | ||
}; | ||
Message.prototype.render = function render() { | ||
var _props2 = this.props; | ||
var | ||
/* eslint-disable no-unused-vars */ | ||
messages = _props2.messages; | ||
var fieldFor = _props2.for; | ||
var Component = _props2.component; | ||
var children = _props2.children; | ||
var props = _objectWithoutProperties(_props2, ['messages', 'for', 'component', 'children']); | ||
var activeMessages = this.state.messages; | ||
if (!Object.keys(activeMessages || {}).length) return null; | ||
return _react2.default.createElement( | ||
Component, | ||
props, | ||
values(messages).reduce(flatten, []).filter(function (v, i, l) { | ||
return filter(v, i, l, extract); | ||
}).map(extract).join(delim) | ||
children(activeMessages) | ||
); | ||
}; | ||
_createClass(Message, null, [{ | ||
key: 'defaultProps', | ||
value: { | ||
component: 'span', | ||
delim: ', ', | ||
extract: function extract(f) { | ||
return f; | ||
}, | ||
filter: function filter(f) { | ||
return true; | ||
} | ||
}, | ||
enumerable: true | ||
}]); | ||
Message.prototype.resolveNames = function resolveNames() { | ||
var props = arguments.length <= 0 || arguments[0] === undefined ? this.props : arguments[0]; | ||
var context = arguments.length <= 1 || arguments[1] === undefined ? this.context : arguments[1]; | ||
var messageContainer = context.messageContainer; | ||
var forNames = props['for']; | ||
var group = props.group; | ||
if (!forNames && group && messageContainer) forNames = messageContainer.namesForGroup(group); | ||
return forNames ? [].concat(forNames) : []; | ||
}; | ||
return Message; | ||
})(React.Component); | ||
}(_react2.default.Component); | ||
module.exports = connectToMessageContainer(Message); | ||
Message.propTypes = { | ||
for: stringOrArrayOfStrings, | ||
group: stringOrArrayOfStrings, | ||
messagesForNames: _react.PropTypes.func, | ||
children: _react.PropTypes.func, | ||
component: _react.PropTypes.oneOfType([_react.PropTypes.string, _react.PropTypes.func]) | ||
}; | ||
Message.defaultProps = { | ||
messagesForNames: messagesForNames, | ||
component: 'span', | ||
children: function children(messages) { | ||
return values(messages).reduce(flatten, []).join(', '); | ||
} | ||
}; | ||
Message.contextTypes = { | ||
messageContainer: _react2.default.PropTypes.object | ||
}; | ||
module.exports = (0, _connectToMessageContainer2.default)(Message); | ||
module.exports._Message = Message; |
'use strict'; | ||
var _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; }; | ||
exports.__esModule = 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'); | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
var _react2 = _interopRequireDefault(_react); | ||
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; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var React = require('react'); | ||
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 uniq = function uniq(array) { | ||
return array.filter(function (item, idx) { | ||
return array.indexOf(item) == idx; | ||
return array.indexOf(item) === idx; | ||
}); | ||
}; | ||
var has = function has(obj, key) { | ||
return obj && ({}).hasOwnProperty.call(obj, key); | ||
var add = function add(array, item) { | ||
return array.indexOf(item) === -1 && array.push(item); | ||
}; | ||
module.exports = (function (_React$Component) { | ||
_inherits(ValidationContainer, _React$Component); | ||
var remove = function remove(array, item) { | ||
return array.filter(function (i) { | ||
return i !== item; | ||
}); | ||
}; | ||
_createClass(ValidationContainer, null, [{ | ||
key: 'defaultProps', | ||
value: { | ||
messages: Object.create(null) | ||
}, | ||
enumerable: true | ||
}, { | ||
key: 'propTypes', | ||
value: { | ||
messages: React.PropTypes.object, | ||
onValidationNeeded: React.PropTypes.func | ||
}, | ||
enumerable: true | ||
}, { | ||
key: 'childContextTypes', | ||
value: { | ||
messageContainer: React.PropTypes.object | ||
}, | ||
enumerable: true | ||
}]); | ||
var MessageContainer = function (_React$Component) { | ||
_inherits(MessageContainer, _React$Component); | ||
function ValidationContainer(props, context) { | ||
_classCallCheck(this, ValidationContainer); | ||
function MessageContainer(props, context) { | ||
_classCallCheck(this, MessageContainer); | ||
_React$Component.call(this, props, context); | ||
this._handlers = []; | ||
this._groups = Object.create(null); | ||
var _this = _possibleConstructorReturn(this, _React$Component.call(this, props, context)); | ||
this._messages = this._messages.bind(this); | ||
_initialiseProps.call(_this); | ||
_this._handlers = []; | ||
_this._groups = Object.create(null); | ||
return _this; | ||
} | ||
ValidationContainer.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) { | ||
MessageContainer.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps) { | ||
this._emit(nextProps); | ||
}; | ||
ValidationContainer.prototype.getChildContext = function getChildContext() { | ||
var _this = this; | ||
return this._context || (this._context = { | ||
MessageContainer.prototype.getChildContext = function getChildContext() { | ||
if (!this._context) this._context = { | ||
messageContainer: { | ||
addToGroup: this.addToGroup, | ||
namesForGroup: this.namesForGroup, | ||
subscribe: this.subscribe, | ||
onValidate: this.onValidate | ||
} | ||
}; | ||
subscribe: function subscribe(listener) { | ||
_this._handlers.push(listener); | ||
listener(_this._listenerContext(_this.props)); | ||
return function () { | ||
return _this._handlers.splice(_this._handlers.indexOf(listener), 1); | ||
}; | ||
}, | ||
return this._context; | ||
}; | ||
addToGroup: function addToGroup(group, fields) { | ||
if (group === undefined) group = ''; | ||
group = _this._groups[group] || (_this._groups[group] = []); | ||
fields = [].concat(fields); | ||
fields.forEach(function (f) { | ||
if (group.indexOf(f) === -1) group.push(f); | ||
}); | ||
return function () { | ||
return fields.forEach(function (f) { | ||
return group.splice(group.indexOf(f), 1); | ||
}); | ||
}; | ||
}, | ||
onValidateFields: function onValidateFields(fields, type, args) { | ||
_this.props.onValidationNeeded && _this.props.onValidationNeeded({ type: type, fields: fields, args: args }); | ||
}, | ||
onValidateGroup: function onValidateGroup(group, type, args) { | ||
var fields = _this.fieldsForGroup(group); | ||
_this.props.onValidationNeeded && _this.props.onValidationNeeded({ type: type, fields: fields, args: args }); | ||
} | ||
} | ||
MessageContainer.prototype._emit = function _emit(props) { | ||
var context = this._listenerContext(props); | ||
this._handlers.forEach(function (fn) { | ||
return fn(context); | ||
}); | ||
}; | ||
ValidationContainer.prototype._listenerContext = function _listenerContext(props) { | ||
return this._messages.bind(null, props.messages || {}); | ||
MessageContainer.prototype._listenerContext = function _listenerContext(_ref) { | ||
var messages = _ref.messages; | ||
return messages; | ||
}; | ||
ValidationContainer.prototype.render = function render() { | ||
MessageContainer.prototype.render = function render() { | ||
return this.props.children; | ||
}; | ||
ValidationContainer.prototype.fieldsForGroup = function fieldsForGroup() { | ||
var _this2 = this; | ||
return MessageContainer; | ||
}(_react2.default.Component); | ||
var groups = arguments.length <= 0 || arguments[0] === undefined ? Object.keys(this._groups) : arguments[0]; | ||
MessageContainer.defaultProps = { | ||
messages: Object.create(null) | ||
}; | ||
MessageContainer.propTypes = { | ||
messages: _react2.default.PropTypes.object, | ||
onValidationNeeded: _react2.default.PropTypes.func | ||
}; | ||
MessageContainer.childContextTypes = { | ||
messageContainer: _react2.default.PropTypes.object | ||
}; | ||
var _initialiseProps = function _initialiseProps() { | ||
var _this2 = this; | ||
this.namesForGroup = function (groups) { | ||
groups = Object.keys(_this2._groups); | ||
groups = [].concat(groups); | ||
return uniq(groups.reduce(function (fields, group) { | ||
@@ -123,24 +108,42 @@ return fields.concat(_this2._groups[group]); | ||
ValidationContainer.prototype._emit = function _emit(props) { | ||
var context = this._listenerContext(props); | ||
this._handlers.forEach(function (fn) { | ||
return fn(context); | ||
this.addToGroup = function (grpName, names) { | ||
var group = _this2._groups[grpName]; | ||
names = names && [].concat(names); | ||
if (!names || !names.length) return; | ||
if (!group) group = _this2._groups[grpName] = []; | ||
names.forEach(function (name) { | ||
return add(group, name); | ||
}); | ||
return function () { | ||
return names.forEach(function (name) { | ||
return remove(group, name); | ||
}); | ||
}; | ||
}; | ||
ValidationContainer.prototype._messages = function _messages(messages, names, groups) { | ||
if (!names || !names.length) { | ||
if (!groups || !groups.length) return _extends({}, messages); | ||
this.onValidate = function (fields, type, args) { | ||
if (!fields || !fields.length) return; | ||
names = this.fieldsForGroup(groups); | ||
} | ||
_this2.props.onValidationNeeded && _this2.props.onValidationNeeded({ type: type, fields: fields, args: args }); | ||
}; | ||
return [].concat(names).reduce(function (o, name) { | ||
if (messages[name]) o[name] = messages[name]; | ||
this.subscribe = function (listener) { | ||
var context = _this2._listenerContext(_this2.props); | ||
return o; | ||
}, {}); | ||
_this2._handlers.push(listener); | ||
listener(context); | ||
return function () { | ||
return remove(_this2._handlers, listener); | ||
}; | ||
}; | ||
}; | ||
return ValidationContainer; | ||
})(React.Component); | ||
exports.default = MessageContainer; | ||
module.exports = exports['default']; |
'use strict'; | ||
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; }; })(); | ||
exports.__esModule = true; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
var _react = require('react'); | ||
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 _react2 = _interopRequireDefault(_react); | ||
var React = require('react'), | ||
Bridge = require('topeka/ChildBridge'), | ||
connectToMessageContainer = require('./connectToMessageContainer'); | ||
var _ChildBridge = require('topeka/ChildBridge'); | ||
var stringOrArrayOfStrings = React.PropTypes.oneOfType([React.PropTypes.string, React.PropTypes.arrayOf(React.PropTypes.string)]); | ||
var _ChildBridge2 = _interopRequireDefault(_ChildBridge); | ||
var MessageTrigger = (function (_React$Component) { | ||
_inherits(MessageTrigger, _React$Component); | ||
var _connectToMessageContainer = require('./connectToMessageContainer'); | ||
_createClass(MessageTrigger, null, [{ | ||
key: 'propTypes', | ||
value: { | ||
events: stringOrArrayOfStrings, | ||
inject: React.PropTypes.func, | ||
var _connectToMessageContainer2 = _interopRequireDefault(_connectToMessageContainer); | ||
'for': stringOrArrayOfStrings, | ||
group: stringOrArrayOfStrings | ||
}, | ||
enumerable: true | ||
}, { | ||
key: 'contextTypes', | ||
value: { | ||
messageContainer: React.PropTypes.object | ||
}, | ||
enumerable: true | ||
}, { | ||
key: 'defaultProps', | ||
value: { | ||
events: 'onChange' | ||
}, | ||
enumerable: true | ||
}]); | ||
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 stringOrArrayOfStrings = _react.PropTypes.oneOfType([_react.PropTypes.string, _react.PropTypes.arrayOf(_react.PropTypes.string)]); | ||
function isActive(names, messages) { | ||
return names.some(function (name) { | ||
return !!messages[name]; | ||
}); | ||
} | ||
var MessageTrigger = function (_React$Component) { | ||
_inherits(MessageTrigger, _React$Component); | ||
function MessageTrigger() { | ||
_classCallCheck(this, MessageTrigger); | ||
_React$Component.call(this); | ||
this._inject = this._inject.bind(this); | ||
this._notify = this._notify.bind(this); | ||
for (var _len = arguments.length, args = Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
var _this = _possibleConstructorReturn(this, _React$Component.call.apply(_React$Component, [this].concat(args))); | ||
_initialiseProps.call(_this); | ||
_this.state = { isActive: false }; | ||
return _this; | ||
} | ||
MessageTrigger.prototype.componentWillMount = function componentWillMount() { | ||
if (!this.context.messageContainer || !this.props['for'] || !this.props['for'].length) return; | ||
var _props = this.props; | ||
var isActive = _props.isActive; | ||
var messages = _props.messages; | ||
this._removeFromGroup = this.context.messageContainer.addToGroup(this.props.group, this.props['for']); | ||
var props = _objectWithoutProperties(_props, ['isActive', 'messages']); | ||
this.addToGroup(); | ||
this.setState({ | ||
isActive: isActive.apply(undefined, [this.resolveNames(), messages].concat(props)) | ||
}); | ||
}; | ||
MessageTrigger.prototype.componentWillReceiveProps = function componentWillReceiveProps(nextProps, nextContext) { | ||
this._removeFromGroup && this._removeFromGroup(); | ||
var isActive = nextProps.isActive; | ||
var messages = nextProps.messages; | ||
if (!nextContext.messageContainer || !nextProps['for'] || !nextProps['for'].length) return; | ||
var props = _objectWithoutProperties(nextProps, ['isActive', 'messages']); | ||
this._removeFromGroup = this.context.messageContainer.addToGroup(nextProps.group, nextProps['for']); | ||
this.addToGroup(nextProps, nextContext); | ||
this.setState({ | ||
isActive: isActive(this.resolveNames(nextProps, nextContext), messages, props) | ||
}); | ||
}; | ||
MessageTrigger.prototype.componentWillUnmount = function componentWillUnmount() { | ||
this._removeFromGroup && this._removeFromGroup(); | ||
this.removeFromGroup && this.removeFromGroup(); | ||
}; | ||
MessageTrigger.prototype.render = function render() { | ||
return React.createElement( | ||
Bridge, | ||
return _react2.default.createElement( | ||
_ChildBridge2.default, | ||
{ | ||
inject: this._inject, | ||
inject: this.inject, | ||
events: this.props.events, | ||
onEvent: this._notify | ||
onEvent: this.onEvent | ||
}, | ||
@@ -80,25 +94,82 @@ this.props.children | ||
MessageTrigger.prototype._inject = function _inject(child) { | ||
var active = this.props['for'] && this.props.active; | ||
MessageTrigger.prototype.addToGroup = function addToGroup() { | ||
var props = arguments.length <= 0 || arguments[0] === undefined ? this.props : arguments[0]; | ||
var context = arguments.length <= 1 || arguments[1] === undefined ? this.context : arguments[1]; | ||
var messageContainer = context.messageContainer; | ||
var forNames = props['for']; | ||
var group = props.group; | ||
if (this.props.inject) return this.props.inject(child, !!active); | ||
this.removeFromGroup && this.removeFromGroup(); | ||
if (!messageContainer || !group || !forNames) return; | ||
this.removeFromGroup = messageContainer.addToGroup(group, forNames); | ||
}; | ||
MessageTrigger.prototype._notify = function _notify(event, handler) { | ||
var container = this.context.messageContainer, | ||
forProps = this.props['for'] ? [].concat(this.props['for']) : []; | ||
MessageTrigger.prototype.resolveNames = function resolveNames() { | ||
var props = arguments.length <= 0 || arguments[0] === undefined ? this.props : arguments[0]; | ||
var context = arguments.length <= 1 || arguments[1] === undefined ? this.context : arguments[1]; | ||
var messageContainer = context.messageContainer; | ||
var forNames = props['for']; | ||
var group = props.group; | ||
for (var _len = arguments.length, args = Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) { | ||
args[_key - 2] = arguments[_key]; | ||
} | ||
handler && handler.apply(this, args); | ||
if (!forNames && group && messageContainer) forNames = messageContainer.namesForGroup(group); | ||
if (!container) return; | ||
if (forProps.length) container.onValidateFields(forProps, event, args);else container.onValidateGroup(this.props.group, event, args); | ||
return forNames ? [].concat(forNames) : []; | ||
}; | ||
return MessageTrigger; | ||
})(React.Component); | ||
}(_react2.default.Component); | ||
module.exports = connectToMessageContainer(MessageTrigger); | ||
MessageTrigger.propTypes = { | ||
events: stringOrArrayOfStrings, | ||
inject: _react2.default.PropTypes.func, | ||
isActive: _react2.default.PropTypes.func.isRequired, | ||
for: stringOrArrayOfStrings, | ||
group: stringOrArrayOfStrings | ||
}; | ||
MessageTrigger.contextTypes = { | ||
messageContainer: _react2.default.PropTypes.object | ||
}; | ||
MessageTrigger.defaultProps = { | ||
isActive: isActive, | ||
events: 'onChange' | ||
}; | ||
var _initialiseProps = function _initialiseProps() { | ||
var _this2 = this; | ||
this.onEvent = function (event, handler) { | ||
for (var _len2 = arguments.length, args = Array(_len2 > 2 ? _len2 - 2 : 0), _key2 = 2; _key2 < _len2; _key2++) { | ||
args[_key2 - 2] = arguments[_key2]; | ||
} | ||
var messageContainer = _this2.context.messageContainer; | ||
handler && handler.apply(_this2, args); | ||
if (!messageContainer) return; | ||
messageContainer.onValidate(_this2.resolveNames(), event, args); | ||
}; | ||
this.inject = function (child) { | ||
var _props2 = _this2.props; | ||
var messages = _props2.messages; | ||
var inject = _props2.inject; | ||
var isActive = _props2.isActive; | ||
if (!inject) return false; | ||
var names = _this2.resolveNames(); | ||
return inject(child, isActive(names, messages)); | ||
}; | ||
}; | ||
exports.default = (0, _connectToMessageContainer2.default)(MessageTrigger); | ||
module.exports = exports['default']; |
{ | ||
"name": "react-input-message", | ||
"description": "unopinionated form input annotation", | ||
"version": "0.9.4", | ||
"version": "0.10.0", | ||
"repository": { | ||
@@ -6,0 +6,0 @@ "url": "git://github.com/jquense/react-input-message.git" |
@@ -5,5 +5,7 @@ 'use strict'; | ||
var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol ? "symbol" : typeof obj; }; | ||
function isEql(a, b) { | ||
if (a === b) return true; | ||
if (typeof a !== typeof b) return false; | ||
if ((typeof a === 'undefined' ? 'undefined' : _typeof(a)) !== (typeof b === 'undefined' ? 'undefined' : _typeof(b))) return false; | ||
@@ -22,3 +24,3 @@ if (Array.isArray(a)) return !a.some(function (a, idx) { | ||
if (typeof objA !== 'object' || objA === null || typeof objB !== 'object' || objB === null) { | ||
if ((typeof objA === 'undefined' ? 'undefined' : _typeof(objA)) !== 'object' || objA === null || (typeof objB === 'undefined' ? 'undefined' : _typeof(objB)) !== 'object' || objB === null) { | ||
return false; | ||
@@ -36,5 +38,5 @@ } | ||
for (var i = 0; i < keysA.length; i++) { | ||
if (!bHasOwnProperty(keysA[i]) || !eql(objA[keysA[i]], objB[keysA[i]])) { | ||
return false; | ||
} | ||
var key = keysA[i]; | ||
if (!bHasOwnProperty(key)) return false; | ||
if (!eql(objA[key], objB[key])) return false; | ||
} | ||
@@ -45,3 +47,3 @@ | ||
exports['default'] = shallowEqual; | ||
exports.default = shallowEqual; | ||
module.exports = exports['default']; |
'use strict'; | ||
exports.__esModule = true; | ||
var _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; }; | ||
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError('Cannot call a class as a function'); } } | ||
var _universalPromise = require('universal-promise'); | ||
var React = require('react'), | ||
Promise = require('universal-promise'); | ||
var _universalPromise2 = _interopRequireDefault(_universalPromise); | ||
var Validator = (function () { | ||
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"); } } | ||
var Validator = function () { | ||
function Validator(validate) { | ||
@@ -43,3 +48,3 @@ _classCallCheck(this, Validator); | ||
return Promise.all(fields).then(function () { | ||
return _universalPromise2.default.all(fields).then(function () { | ||
return _this2.errors(); | ||
@@ -52,8 +57,8 @@ }); | ||
return new Promise(function (resolve, reject) { | ||
Promise.resolve(_this3._validator(name, context)).then(function (msgs) { | ||
return new _universalPromise2.default(function (resolve, reject) { | ||
_universalPromise2.default.resolve(_this3._validator(name, context)).then(function (msgs) { | ||
msgs = msgs == null ? [] : [].concat(msgs); | ||
if (msgs.length) _this3._addError(name, msgs); | ||
resolve(!msgs.length); | ||
})['catch'](reject); | ||
}).catch(reject); | ||
}); | ||
@@ -75,4 +80,5 @@ }; | ||
return Validator; | ||
})(); | ||
}(); | ||
module.exports = Validator; | ||
exports.default = Validator; | ||
module.exports = exports['default']; |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
25072
523
1