react-final-form
Advanced tools
Comparing version 3.7.0 to 4.0.0
@@ -100,1 +100,5 @@ import * as React from 'react' | ||
export var version: string | ||
export function withReactFinalForm<T>( | ||
component: React.ComponentType<T> | ||
): React.ComponentType<T & ReactContext> |
@@ -5,6 +5,3 @@ 'use strict'; | ||
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; } | ||
var React = require('react'); | ||
var PropTypes = _interopDefault(require('prop-types')); | ||
var finalForm = require('final-form'); | ||
@@ -169,2 +166,32 @@ | ||
var ReactFinalFormContext = React.createContext(null); | ||
var withReactFinalForm = function withReactFinalForm(Component) { | ||
return ( | ||
/*#__PURE__*/ | ||
function (_React$Component) { | ||
_inheritsLoose(_class, _React$Component); | ||
function _class() { | ||
return _React$Component.apply(this, arguments) || this; | ||
} | ||
var _proto = _class.prototype; | ||
_proto.render = function render() { | ||
var _this = this; | ||
return React.createElement(ReactFinalFormContext.Consumer, { | ||
children: function children(reactFinalForm) { | ||
return React.createElement(Component, _extends({ | ||
reactFinalForm: reactFinalForm | ||
}, _this.props)); | ||
} | ||
}); | ||
}; | ||
return _class; | ||
}(React.Component) | ||
); | ||
}; | ||
var all = finalForm.fieldSubscriptionItems.reduce(function (result, key) { | ||
@@ -180,6 +207,6 @@ result[key] = true; | ||
function Field(_props, context) { | ||
function Field(_props) { | ||
var _this; | ||
_this = _React$Component.call(this, _props, context) || this; | ||
_this = _React$Component.call(this, _props) || this; | ||
@@ -191,3 +218,3 @@ _this.subscribe = function (_ref, listener) { | ||
validateFields = _ref.validateFields; | ||
_this.unsubscribe = _this.context.reactFinalForm.registerField(name, listener, subscription || all, { | ||
_this.unsubscribe = _this.props.reactFinalForm.registerField(name, listener, subscription || all, { | ||
isEqual: isEqual, | ||
@@ -251,7 +278,7 @@ getValidator: function getValidator() { | ||
if (process.env.NODE_ENV !== 'production' && !context.reactFinalForm) { | ||
if (process.env.NODE_ENV !== 'production' && !_this.props.reactFinalForm) { | ||
console.error('Warning: Field must be used inside of a ReactFinalForm component'); | ||
} | ||
if (_this.context.reactFinalForm) { | ||
if (_this.props.reactFinalForm) { | ||
// avoid error, warning will alert developer to their mistake | ||
@@ -281,3 +308,3 @@ _this.subscribe(_props, function (state) { | ||
if (prevProps.name !== name || diffSubscription(prevProps.subscription, subscription, finalForm.fieldSubscriptionItems)) { | ||
if (this.context.reactFinalForm) { | ||
if (this.props.reactFinalForm) { | ||
// avoid error, warning will alert developer to their mistake | ||
@@ -307,4 +334,5 @@ this.unsubscribe(); | ||
validateFields = _this$props4.validateFields, | ||
reactFinalForm = _this$props4.reactFinalForm, | ||
_value = _this$props4.value, | ||
rest = _objectWithoutPropertiesLoose(_this$props4, ["allowNull", "component", "children", "format", "formatOnBlur", "parse", "isEqual", "name", "subscription", "validate", "validateFields", "value"]); | ||
rest = _objectWithoutPropertiesLoose(_this$props4, ["allowNull", "component", "children", "format", "formatOnBlur", "parse", "isEqual", "name", "subscription", "validate", "validateFields", "reactFinalForm", "value"]); | ||
@@ -395,5 +423,2 @@ var _ref3 = this.state.state || {}, | ||
Field.contextTypes = { | ||
reactFinalForm: PropTypes.object | ||
}; | ||
Field.defaultProps = { | ||
@@ -407,2 +432,3 @@ format: function format(value, name) { | ||
}; | ||
var Field$1 = withReactFinalForm(Field); | ||
@@ -535,8 +561,2 @@ // | ||
_proto.getChildContext = function getChildContext() { | ||
return { | ||
reactFinalForm: this.form | ||
}; | ||
}; | ||
_proto.componentWillMount = function componentWillMount() { | ||
@@ -690,5 +710,7 @@ if (this.form) { | ||
return renderComponent(_extends({}, props, renderProps, { | ||
return React.createElement(ReactFinalFormContext.Provider, { | ||
value: this.form | ||
}, renderComponent(_extends({}, props, renderProps, { | ||
__versions: versions | ||
}), 'ReactFinalForm'); | ||
}), 'ReactFinalForm')); | ||
}; | ||
@@ -699,6 +721,2 @@ | ||
ReactFinalForm.childContextTypes = { | ||
reactFinalForm: PropTypes.object | ||
}; | ||
var FormSpy = | ||
@@ -709,10 +727,10 @@ /*#__PURE__*/ | ||
function FormSpy(props, context) { | ||
function FormSpy(props) { | ||
var _this; | ||
_this = _React$Component.call(this, props, context) || this; | ||
_this = _React$Component.call(this, props) || this; | ||
_this.subscribe = function (_ref, listener) { | ||
var subscription = _ref.subscription; | ||
_this.unsubscribe = _this.context.reactFinalForm.subscribe(listener, subscription || all$1); | ||
_this.unsubscribe = _this.props.reactFinalForm.subscribe(listener, subscription || all$1); | ||
}; | ||
@@ -732,7 +750,7 @@ | ||
if (process.env.NODE_ENV !== 'production' && !context.reactFinalForm) { | ||
if (process.env.NODE_ENV !== 'production' && !_this.props.reactFinalForm) { | ||
console.error('Warning: FormSpy must be used inside of a ReactFinalForm component'); | ||
} | ||
if (_this.context.reactFinalForm) { | ||
if (_this.props.reactFinalForm) { | ||
// avoid error, warning will alert developer to their mistake | ||
@@ -767,3 +785,3 @@ _this.subscribe(props, function (state) { | ||
if (diffSubscription(prevProps.subscription, subscription, finalForm.formSubscriptionItems)) { | ||
if (this.context.reactFinalForm) { | ||
if (this.props.reactFinalForm) { | ||
// avoid error, warning will alert developer to their mistake | ||
@@ -783,6 +801,5 @@ this.unsubscribe(); | ||
onChange = _this$props.onChange, | ||
subscription = _this$props.subscription, | ||
rest = _objectWithoutPropertiesLoose(_this$props, ["onChange", "subscription"]); | ||
reactFinalForm = _this$props.reactFinalForm, | ||
rest = _objectWithoutPropertiesLoose(_this$props, ["onChange", "reactFinalForm"]); | ||
var reactFinalForm = this.context.reactFinalForm; | ||
var renderProps = { | ||
@@ -868,11 +885,10 @@ batch: reactFinalForm && function (fn) { | ||
FormSpy.contextTypes = { | ||
reactFinalForm: PropTypes.object | ||
}; | ||
var FormSpy$1 = withReactFinalForm(FormSpy); | ||
// | ||
exports.Field = Field; | ||
exports.Field = Field$1; | ||
exports.Form = ReactFinalForm; | ||
exports.version = version; | ||
exports.FormSpy = FormSpy; | ||
exports.FormSpy = FormSpy$1; | ||
exports.withReactFinalForm = withReactFinalForm; |
@@ -1,3 +0,2 @@ | ||
import { createElement, Component } from 'react'; | ||
import PropTypes from 'prop-types'; | ||
import { createElement, Component, createContext } from 'react'; | ||
import { fieldSubscriptionItems, configOptions, createForm, formSubscriptionItems, version } from 'final-form'; | ||
@@ -162,2 +161,32 @@ | ||
var ReactFinalFormContext = createContext(null); | ||
var withReactFinalForm = function withReactFinalForm(Component$$1) { | ||
return ( | ||
/*#__PURE__*/ | ||
function (_React$Component) { | ||
_inheritsLoose(_class, _React$Component); | ||
function _class() { | ||
return _React$Component.apply(this, arguments) || this; | ||
} | ||
var _proto = _class.prototype; | ||
_proto.render = function render() { | ||
var _this = this; | ||
return createElement(ReactFinalFormContext.Consumer, { | ||
children: function children(reactFinalForm) { | ||
return createElement(Component$$1, _extends({ | ||
reactFinalForm: reactFinalForm | ||
}, _this.props)); | ||
} | ||
}); | ||
}; | ||
return _class; | ||
}(Component) | ||
); | ||
}; | ||
var all = fieldSubscriptionItems.reduce(function (result, key) { | ||
@@ -173,6 +202,6 @@ result[key] = true; | ||
function Field(_props, context) { | ||
function Field(_props) { | ||
var _this; | ||
_this = _React$Component.call(this, _props, context) || this; | ||
_this = _React$Component.call(this, _props) || this; | ||
@@ -184,3 +213,3 @@ _this.subscribe = function (_ref, listener) { | ||
validateFields = _ref.validateFields; | ||
_this.unsubscribe = _this.context.reactFinalForm.registerField(name, listener, subscription || all, { | ||
_this.unsubscribe = _this.props.reactFinalForm.registerField(name, listener, subscription || all, { | ||
isEqual: isEqual, | ||
@@ -244,7 +273,7 @@ getValidator: function getValidator() { | ||
if (process.env.NODE_ENV !== 'production' && !context.reactFinalForm) { | ||
if (process.env.NODE_ENV !== 'production' && !_this.props.reactFinalForm) { | ||
console.error('Warning: Field must be used inside of a ReactFinalForm component'); | ||
} | ||
if (_this.context.reactFinalForm) { | ||
if (_this.props.reactFinalForm) { | ||
// avoid error, warning will alert developer to their mistake | ||
@@ -274,3 +303,3 @@ _this.subscribe(_props, function (state) { | ||
if (prevProps.name !== name || diffSubscription(prevProps.subscription, subscription, fieldSubscriptionItems)) { | ||
if (this.context.reactFinalForm) { | ||
if (this.props.reactFinalForm) { | ||
// avoid error, warning will alert developer to their mistake | ||
@@ -300,4 +329,5 @@ this.unsubscribe(); | ||
validateFields = _this$props4.validateFields, | ||
reactFinalForm = _this$props4.reactFinalForm, | ||
_value = _this$props4.value, | ||
rest = _objectWithoutPropertiesLoose(_this$props4, ["allowNull", "component", "children", "format", "formatOnBlur", "parse", "isEqual", "name", "subscription", "validate", "validateFields", "value"]); | ||
rest = _objectWithoutPropertiesLoose(_this$props4, ["allowNull", "component", "children", "format", "formatOnBlur", "parse", "isEqual", "name", "subscription", "validate", "validateFields", "reactFinalForm", "value"]); | ||
@@ -388,5 +418,2 @@ var _ref3 = this.state.state || {}, | ||
Field.contextTypes = { | ||
reactFinalForm: PropTypes.object | ||
}; | ||
Field.defaultProps = { | ||
@@ -400,2 +427,3 @@ format: function format(value, name) { | ||
}; | ||
var Field$1 = withReactFinalForm(Field); | ||
@@ -528,8 +556,2 @@ // | ||
_proto.getChildContext = function getChildContext() { | ||
return { | ||
reactFinalForm: this.form | ||
}; | ||
}; | ||
_proto.componentWillMount = function componentWillMount() { | ||
@@ -683,5 +705,7 @@ if (this.form) { | ||
return renderComponent(_extends({}, props, renderProps, { | ||
return createElement(ReactFinalFormContext.Provider, { | ||
value: this.form | ||
}, renderComponent(_extends({}, props, renderProps, { | ||
__versions: versions | ||
}), 'ReactFinalForm'); | ||
}), 'ReactFinalForm')); | ||
}; | ||
@@ -692,6 +716,2 @@ | ||
ReactFinalForm.childContextTypes = { | ||
reactFinalForm: PropTypes.object | ||
}; | ||
var FormSpy = | ||
@@ -702,10 +722,10 @@ /*#__PURE__*/ | ||
function FormSpy(props, context) { | ||
function FormSpy(props) { | ||
var _this; | ||
_this = _React$Component.call(this, props, context) || this; | ||
_this = _React$Component.call(this, props) || this; | ||
_this.subscribe = function (_ref, listener) { | ||
var subscription = _ref.subscription; | ||
_this.unsubscribe = _this.context.reactFinalForm.subscribe(listener, subscription || all$1); | ||
_this.unsubscribe = _this.props.reactFinalForm.subscribe(listener, subscription || all$1); | ||
}; | ||
@@ -725,7 +745,7 @@ | ||
if (process.env.NODE_ENV !== 'production' && !context.reactFinalForm) { | ||
if (process.env.NODE_ENV !== 'production' && !_this.props.reactFinalForm) { | ||
console.error('Warning: FormSpy must be used inside of a ReactFinalForm component'); | ||
} | ||
if (_this.context.reactFinalForm) { | ||
if (_this.props.reactFinalForm) { | ||
// avoid error, warning will alert developer to their mistake | ||
@@ -760,3 +780,3 @@ _this.subscribe(props, function (state) { | ||
if (diffSubscription(prevProps.subscription, subscription, formSubscriptionItems)) { | ||
if (this.context.reactFinalForm) { | ||
if (this.props.reactFinalForm) { | ||
// avoid error, warning will alert developer to their mistake | ||
@@ -776,6 +796,5 @@ this.unsubscribe(); | ||
onChange = _this$props.onChange, | ||
subscription = _this$props.subscription, | ||
rest = _objectWithoutPropertiesLoose(_this$props, ["onChange", "subscription"]); | ||
reactFinalForm = _this$props.reactFinalForm, | ||
rest = _objectWithoutPropertiesLoose(_this$props, ["onChange", "reactFinalForm"]); | ||
var reactFinalForm = this.context.reactFinalForm; | ||
var renderProps = { | ||
@@ -861,8 +880,6 @@ batch: reactFinalForm && function (fn) { | ||
FormSpy.contextTypes = { | ||
reactFinalForm: PropTypes.object | ||
}; | ||
var FormSpy$1 = withReactFinalForm(FormSpy); | ||
// | ||
export { Field, ReactFinalForm as Form, version$1 as version, FormSpy }; | ||
export { Field$1 as Field, ReactFinalForm as Form, version$1 as version, FormSpy$1 as FormSpy, withReactFinalForm }; |
(function (global, factory) { | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('prop-types'), require('final-form')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'react', 'prop-types', 'final-form'], factory) : | ||
(factory((global['react-final-form'] = {}),global.React,global.PropTypes,global.FinalForm)); | ||
}(this, (function (exports,React,PropTypes,finalForm) { 'use strict'; | ||
typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('react'), require('final-form')) : | ||
typeof define === 'function' && define.amd ? define(['exports', 'react', 'final-form'], factory) : | ||
(factory((global['react-final-form'] = {}),global.React,global.FinalForm)); | ||
}(this, (function (exports,React,finalForm) { 'use strict'; | ||
PropTypes = PropTypes && PropTypes.hasOwnProperty('default') ? PropTypes['default'] : PropTypes; | ||
function _extends() { | ||
@@ -166,2 +164,32 @@ _extends = Object.assign || function (target) { | ||
var ReactFinalFormContext = React.createContext(null); | ||
var withReactFinalForm = function withReactFinalForm(Component) { | ||
return ( | ||
/*#__PURE__*/ | ||
function (_React$Component) { | ||
_inheritsLoose(_class, _React$Component); | ||
function _class() { | ||
return _React$Component.apply(this, arguments) || this; | ||
} | ||
var _proto = _class.prototype; | ||
_proto.render = function render() { | ||
var _this = this; | ||
return React.createElement(ReactFinalFormContext.Consumer, { | ||
children: function children(reactFinalForm) { | ||
return React.createElement(Component, _extends({ | ||
reactFinalForm: reactFinalForm | ||
}, _this.props)); | ||
} | ||
}); | ||
}; | ||
return _class; | ||
}(React.Component) | ||
); | ||
}; | ||
var all = finalForm.fieldSubscriptionItems.reduce(function (result, key) { | ||
@@ -177,6 +205,6 @@ result[key] = true; | ||
function Field(_props, context) { | ||
function Field(_props) { | ||
var _this; | ||
_this = _React$Component.call(this, _props, context) || this; | ||
_this = _React$Component.call(this, _props) || this; | ||
@@ -188,3 +216,3 @@ _this.subscribe = function (_ref, listener) { | ||
validateFields = _ref.validateFields; | ||
_this.unsubscribe = _this.context.reactFinalForm.registerField(name, listener, subscription || all, { | ||
_this.unsubscribe = _this.props.reactFinalForm.registerField(name, listener, subscription || all, { | ||
isEqual: isEqual, | ||
@@ -248,7 +276,7 @@ getValidator: function getValidator() { | ||
if (!context.reactFinalForm) { | ||
if (!_this.props.reactFinalForm) { | ||
console.error('Warning: Field must be used inside of a ReactFinalForm component'); | ||
} | ||
if (_this.context.reactFinalForm) { | ||
if (_this.props.reactFinalForm) { | ||
// avoid error, warning will alert developer to their mistake | ||
@@ -278,3 +306,3 @@ _this.subscribe(_props, function (state) { | ||
if (prevProps.name !== name || diffSubscription(prevProps.subscription, subscription, finalForm.fieldSubscriptionItems)) { | ||
if (this.context.reactFinalForm) { | ||
if (this.props.reactFinalForm) { | ||
// avoid error, warning will alert developer to their mistake | ||
@@ -304,4 +332,5 @@ this.unsubscribe(); | ||
validateFields = _this$props4.validateFields, | ||
reactFinalForm = _this$props4.reactFinalForm, | ||
_value = _this$props4.value, | ||
rest = _objectWithoutPropertiesLoose(_this$props4, ["allowNull", "component", "children", "format", "formatOnBlur", "parse", "isEqual", "name", "subscription", "validate", "validateFields", "value"]); | ||
rest = _objectWithoutPropertiesLoose(_this$props4, ["allowNull", "component", "children", "format", "formatOnBlur", "parse", "isEqual", "name", "subscription", "validate", "validateFields", "reactFinalForm", "value"]); | ||
@@ -392,5 +421,2 @@ var _ref3 = this.state.state || {}, | ||
Field.contextTypes = { | ||
reactFinalForm: PropTypes.object | ||
}; | ||
Field.defaultProps = { | ||
@@ -404,2 +430,3 @@ format: function format(value, name) { | ||
}; | ||
var Field$1 = withReactFinalForm(Field); | ||
@@ -532,8 +559,2 @@ // | ||
_proto.getChildContext = function getChildContext() { | ||
return { | ||
reactFinalForm: this.form | ||
}; | ||
}; | ||
_proto.componentWillMount = function componentWillMount() { | ||
@@ -687,5 +708,7 @@ if (this.form) { | ||
return renderComponent(_extends({}, props, renderProps, { | ||
return React.createElement(ReactFinalFormContext.Provider, { | ||
value: this.form | ||
}, renderComponent(_extends({}, props, renderProps, { | ||
__versions: versions | ||
}), 'ReactFinalForm'); | ||
}), 'ReactFinalForm')); | ||
}; | ||
@@ -696,6 +719,2 @@ | ||
ReactFinalForm.childContextTypes = { | ||
reactFinalForm: PropTypes.object | ||
}; | ||
var FormSpy = | ||
@@ -706,10 +725,10 @@ /*#__PURE__*/ | ||
function FormSpy(props, context) { | ||
function FormSpy(props) { | ||
var _this; | ||
_this = _React$Component.call(this, props, context) || this; | ||
_this = _React$Component.call(this, props) || this; | ||
_this.subscribe = function (_ref, listener) { | ||
var subscription = _ref.subscription; | ||
_this.unsubscribe = _this.context.reactFinalForm.subscribe(listener, subscription || all$1); | ||
_this.unsubscribe = _this.props.reactFinalForm.subscribe(listener, subscription || all$1); | ||
}; | ||
@@ -729,7 +748,7 @@ | ||
if (!context.reactFinalForm) { | ||
if (!_this.props.reactFinalForm) { | ||
console.error('Warning: FormSpy must be used inside of a ReactFinalForm component'); | ||
} | ||
if (_this.context.reactFinalForm) { | ||
if (_this.props.reactFinalForm) { | ||
// avoid error, warning will alert developer to their mistake | ||
@@ -764,3 +783,3 @@ _this.subscribe(props, function (state) { | ||
if (diffSubscription(prevProps.subscription, subscription, finalForm.formSubscriptionItems)) { | ||
if (this.context.reactFinalForm) { | ||
if (this.props.reactFinalForm) { | ||
// avoid error, warning will alert developer to their mistake | ||
@@ -780,6 +799,5 @@ this.unsubscribe(); | ||
onChange = _this$props.onChange, | ||
subscription = _this$props.subscription, | ||
rest = _objectWithoutPropertiesLoose(_this$props, ["onChange", "subscription"]); | ||
reactFinalForm = _this$props.reactFinalForm, | ||
rest = _objectWithoutPropertiesLoose(_this$props, ["onChange", "reactFinalForm"]); | ||
var reactFinalForm = this.context.reactFinalForm; | ||
var renderProps = { | ||
@@ -865,12 +883,11 @@ batch: reactFinalForm && function (fn) { | ||
FormSpy.contextTypes = { | ||
reactFinalForm: PropTypes.object | ||
}; | ||
var FormSpy$1 = withReactFinalForm(FormSpy); | ||
// | ||
exports.Field = Field; | ||
exports.Field = Field$1; | ||
exports.Form = ReactFinalForm; | ||
exports.version = version; | ||
exports.FormSpy = FormSpy; | ||
exports.FormSpy = FormSpy$1; | ||
exports.withReactFinalForm = withReactFinalForm; | ||
@@ -877,0 +894,0 @@ Object.defineProperty(exports, '__esModule', { value: true }); |
@@ -1,2 +0,2 @@ | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react"),require("prop-types"),require("final-form")):"function"==typeof define&&define.amd?define(["exports","react","prop-types","final-form"],e):e(t["react-final-form"]={},t.React,t.PropTypes,t.FinalForm)}(this,function(t,h,e,s){"use strict";function b(){return(b=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}function n(t,e){t.prototype=Object.create(e.prototype),(t.prototype.constructor=t).__proto__=e}function v(t,e){if(null==t)return{};var n,r,i={},o=Object.keys(t);for(r=0;r<o.length;r++)n=o[r],0<=e.indexOf(n)||(i[n]=t[n]);return i}function o(e,n,t){return e?!n||t.some(function(t){return e[t]!==n[t]}):!!n}function y(t,e){var n=t.render,r=t.children,i=t.component,o=v(t,["render","children","component"]);return i?h.createElement(i,b({},o,{children:r,render:n})):n?n(b({},o,{children:r})):"function"!=typeof r?null:r(o)}e=e&&e.hasOwnProperty("default")?e.default:e;var u="undefined"!=typeof window&&window.navigator&&window.navigator.product&&"ReactNative"===window.navigator.product,c=s.fieldSubscriptionItems.reduce(function(t,e){return t[e]=!0,t},{}),r=function(r){function d(t,e){var a,n;return(a=r.call(this,t,e)||this).subscribe=function(t,e){var n=t.isEqual,r=t.name,i=t.subscription,o=t.validateFields;a.unsubscribe=a.context.reactFinalForm.registerField(r,e,i||c,{isEqual:n,getValidator:function(){return a.props.validate},validateFields:o})},a.notify=function(t){return a.setState({state:t})},a.handlers={onBlur:function(t){var e=a.state.state;if(e){var n=a.props,r=n.format,i=n.formatOnBlur;e.blur(),r&&i&&e.change(r(e.value,e.name))}},onChange:function(t){var e=a.props,n=e.parse,r=e.value,i=t&&t.target?function(t,e,n,r){if(!r&&t.nativeEvent&&void 0!==t.nativeEvent.text)return t.nativeEvent.text;if(r&&t.nativeEvent)return t.nativeEvent.text;var i=t.target,o=i.type,a=i.value,s=i.checked;switch(o){case"checkbox":if(void 0===n)return!!s;if(s)return Array.isArray(e)?e.concat(n):[n];if(!Array.isArray(e))return e;var u=e.indexOf(n);return u<0?e:e.slice(0,u).concat(e.slice(u+1));case"select-multiple":return function(t){var e=[];if(t)for(var n=0;n<t.length;n++){var r=t[n];r.selected&&e.push(r.value)}return e}(t.target.options);default:return a}}(t,a.state.state&&a.state.state.value,r,u):t;a.state.state&&a.state.state.change(n?n(i,a.props.name):i)},onFocus:function(t){a.state.state&&a.state.state.focus()}},a.context.reactFinalForm&&a.subscribe(t,function(t){n?a.notify(t):n=t}),a.state={state:n},a}n(d,r);var t=d.prototype;return t.componentDidUpdate=function(t){var e=this.props,n=e.name,r=e.subscription;(t.name!==n||o(t.subscription,r,s.fieldSubscriptionItems))&&this.context.reactFinalForm&&(this.unsubscribe(),this.subscribe(this.props,this.notify))},t.componentWillUnmount=function(){this.unsubscribe()},t.render=function(){var t=this.props,e=t.allowNull,n=t.component,r=t.children,i=t.format,o=t.formatOnBlur,a=(t.parse,t.isEqual,t.name),s=(t.subscription,t.validate,t.validateFields,t.value),u=v(t,["allowNull","component","children","format","formatOnBlur","parse","isEqual","name","subscription","validate","validateFields","value"]),c=this.state.state||{},f=(c.blur,c.change,c.focus,c.value),l=(c.name,v(c,["blur","change","focus","value","name"])),p={active:l.active,data:l.data,dirty:l.dirty,dirtySinceLastSubmit:l.dirtySinceLastSubmit,error:l.error,initial:l.initial,invalid:l.invalid,pristine:l.pristine,submitError:l.submitError,submitFailed:l.submitFailed,submitSucceeded:l.submitSucceeded,submitting:l.submitting,touched:l.touched,valid:l.valid,visited:l.visited};o?f=d.defaultProps.format(f,a):i&&(f=i(f,a)),null!==f||e||(f="");var m=b({name:a,value:f},this.handlers);return"checkbox"===u.type?void 0===s?m.checked=!!f:(m.checked=!(!Array.isArray(f)||!~f.indexOf(s)),m.value=s):"radio"===u.type?(m.checked=f===s,m.value=s):"select"===n&&u.multiple&&(m.value=m.value||[]),"function"==typeof r?r(b({input:m,meta:p},u)):"string"==typeof n?h.createElement(n,b({},m,{children:r},u)):y(b({},{input:m,meta:p},{children:r,component:n},u))},d}(h.Component);r.contextTypes={reactFinalForm:e.object},r.defaultProps={format:function(t,e){return void 0===t?"":t},parse:function(t,e){return""===t?void 0:t}};var f=function(t){return!(!t||"function"!=typeof t.stopPropagation)},i="3.6.0",l={"final-form":s.version,"react-final-form":i},p=s.formSubscriptionItems.reduce(function(t,e){return t[e]=!0,t},{}),a=function(a){function t(t){var e;(e=a.call(this,t)||this).notify=function(t){e.mounted&&e.setState({state:t}),e.mounted=!0},e.handleSubmit=function(t){return t&&("function"==typeof t.preventDefault&&t.preventDefault(),"function"==typeof t.stopPropagation&&t.stopPropagation()),e.form.submit()};t.children,t.component,t.render;var n=t.subscription,r=t.decorators,i=v(t,["children","component","render","subscription","decorators"]);e.mounted=!1;try{e.form=s.createForm(i)}catch(t){}if(e.unsubscriptions=[],e.form){var o={};e.form.subscribe(function(t){o=t},n||p)(),e.state={state:o}}return r&&r.forEach(function(t){e.unsubscriptions.push(t(e.form))}),e}n(t,a);var e=t.prototype;return e.getChildContext=function(){return{reactFinalForm:this.form}},e.componentWillMount=function(){this.form&&this.form.pauseValidation()},e.componentDidMount=function(){this.form&&(this.unsubscriptions.push(this.form.subscribe(this.notify,this.props.subscription||p)),this.form.resumeValidation())},e.componentWillUpdate=function(){this.form&&(this.resumeValidation=this.resumeValidation||!this.form.isValidationPaused(),this.form.pauseValidation())},e.componentDidUpdate=function(e){var n=this;this.form&&this.resumeValidation&&this.form.resumeValidation(),this.props.initialValues&&!(this.props.initialValuesEqual||function(t,e){if(t===e)return!0;if("object"!=typeof t||!t||"object"!=typeof e||!e)return!1;var n=Object.keys(t),r=Object.keys(e);if(n.length!==r.length)return!1;for(var i=Object.prototype.hasOwnProperty.bind(e),o=0;o<n.length;o++){var a=n[o];if(!i(a)||t[a]!==e[a])return!1}return!0})(e.initialValues,this.props.initialValues)&&this.form.initialize(this.props.initialValues),s.configOptions.forEach(function(t){"initialValues"!==t&&e[t]!==n.props[t]&&n.form.setConfig(t,n.props[t])})},e.componentWillUnmount=function(){this.unsubscriptions.forEach(function(t){return t()})},e.render=function(){var n=this,t=this.props;t.debug,t.initialValues,t.mutators,t.onSubmit,t.subscription,t.validate,t.validateOnBlur;return y(b({},v(t,["debug","initialValues","mutators","onSubmit","subscription","validate","validateOnBlur"]),b({},this.state?this.state.state:{},{batch:this.form&&function(t){return n.form.batch(t)},blur:this.form&&function(t){return n.form.blur(t)},change:this.form&&function(t,e){return n.form.change(t,e)},focus:this.form&&function(t){return n.form.focus(t)},form:b({},this.form,{reset:function(t){f(t)?n.form.reset():n.form.reset(t)}}),handleSubmit:this.handleSubmit,initialize:this.form&&function(t){return n.form.initialize(t)},mutators:this.form&&Object.keys(this.form.mutators).reduce(function(t,e){return t[e]=function(){var t;(t=n.form.mutators)[e].apply(t,arguments)},t},{}),reset:this.form&&function(t){return n.form.reset(t)}}),{__versions:l}))},t}(h.Component);a.childContextTypes={reactFinalForm:e.object};var m=function(i){function t(e,t){var r,n;return(r=i.call(this,e,t)||this).subscribe=function(t,e){var n=t.subscription;r.unsubscribe=r.context.reactFinalForm.subscribe(e,n||p)},r.notify=function(t){r.setState({state:t}),r.props.onChange&&r.props.onChange(t)},r.context.reactFinalForm&&r.subscribe(e,function(t){n?r.notify(t):(n=t,e.onChange&&e.onChange(t))}),n&&(r.state={state:n}),r}n(t,i);var e=t.prototype;return e.componentDidUpdate=function(t){var e=this.props.subscription;o(t.subscription,e,s.formSubscriptionItems)&&this.context.reactFinalForm&&(this.unsubscribe(),this.subscribe(this.props,this.notify))},e.componentWillUnmount=function(){this.unsubscribe()},e.render=function(){var t=this.props,e=t.onChange,n=(t.subscription,v(t,["onChange","subscription"])),r=this.context.reactFinalForm,i={batch:r&&function(t){return r.batch(t)},blur:r&&function(t){return r.blur(t)},change:r&&function(t,e){return r.change(t,e)},focus:r&&function(t){return r.focus(t)},form:b({},r,{reset:function(t){f(t)?r.reset():r.reset(t)}}),initialize:r&&function(t){return r.initialize(t)},mutators:r&&Object.keys(r.mutators).reduce(function(t,e){return t[e]=function(){var t;(t=r.mutators)[e].apply(t,arguments)},t},{}),reset:r&&function(t){return r.reset(t)}};return e?null:y(b({},n,this.state?this.state.state:{},i))},t}(h.Component);m.contextTypes={reactFinalForm:e.object},t.Field=r,t.Form=a,t.version=i,t.FormSpy=m,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports,require("react"),require("final-form")):"function"==typeof define&&define.amd?define(["exports","react","final-form"],e):e(t["react-final-form"]={},t.React,t.FinalForm)}(this,function(t,h,s){"use strict";function v(){return(v=Object.assign||function(t){for(var e=1;e<arguments.length;e++){var n=arguments[e];for(var r in n)Object.prototype.hasOwnProperty.call(n,r)&&(t[r]=n[r])}return t}).apply(this,arguments)}function r(t,e){t.prototype=Object.create(e.prototype),(t.prototype.constructor=t).__proto__=e}function b(t,e){if(null==t)return{};var n,r,i={},o=Object.keys(t);for(r=0;r<o.length;r++)n=o[r],0<=e.indexOf(n)||(i[n]=t[n]);return i}function i(e,n,t){return e?!n||t.some(function(t){return e[t]!==n[t]}):!!n}function y(t,e){var n=t.render,r=t.children,i=t.component,o=b(t,["render","children","component"]);return i?h.createElement(i,v({},o,{children:r,render:n})):n?n(v({},o,{children:r})):"function"!=typeof r?null:r(o)}var o="undefined"!=typeof window&&window.navigator&&window.navigator.product&&"ReactNative"===window.navigator.product,u=h.createContext(null),e=function(n){return function(t){function e(){return t.apply(this,arguments)||this}return r(e,t),e.prototype.render=function(){var e=this;return h.createElement(u.Consumer,{children:function(t){return h.createElement(n,v({reactFinalForm:t},e.props))}})},e}(h.Component)},c=s.fieldSubscriptionItems.reduce(function(t,e){return t[e]=!0,t},{}),n=function(n){function d(t){var a,e;return(a=n.call(this,t)||this).subscribe=function(t,e){var n=t.isEqual,r=t.name,i=t.subscription,o=t.validateFields;a.unsubscribe=a.props.reactFinalForm.registerField(r,e,i||c,{isEqual:n,getValidator:function(){return a.props.validate},validateFields:o})},a.notify=function(t){return a.setState({state:t})},a.handlers={onBlur:function(t){var e=a.state.state;if(e){var n=a.props,r=n.format,i=n.formatOnBlur;e.blur(),r&&i&&e.change(r(e.value,e.name))}},onChange:function(t){var e=a.props,n=e.parse,r=e.value,i=t&&t.target?function(t,e,n,r){if(!r&&t.nativeEvent&&void 0!==t.nativeEvent.text)return t.nativeEvent.text;if(r&&t.nativeEvent)return t.nativeEvent.text;var i=t.target,o=i.type,a=i.value,s=i.checked;switch(o){case"checkbox":if(void 0===n)return!!s;if(s)return Array.isArray(e)?e.concat(n):[n];if(!Array.isArray(e))return e;var u=e.indexOf(n);return u<0?e:e.slice(0,u).concat(e.slice(u+1));case"select-multiple":return function(t){var e=[];if(t)for(var n=0;n<t.length;n++){var r=t[n];r.selected&&e.push(r.value)}return e}(t.target.options);default:return a}}(t,a.state.state&&a.state.state.value,r,o):t;a.state.state&&a.state.state.change(n?n(i,a.props.name):i)},onFocus:function(t){a.state.state&&a.state.state.focus()}},a.props.reactFinalForm&&a.subscribe(t,function(t){e?a.notify(t):e=t}),a.state={state:e},a}r(d,n);var t=d.prototype;return t.componentDidUpdate=function(t){var e=this.props,n=e.name,r=e.subscription;(t.name!==n||i(t.subscription,r,s.fieldSubscriptionItems))&&this.props.reactFinalForm&&(this.unsubscribe(),this.subscribe(this.props,this.notify))},t.componentWillUnmount=function(){this.unsubscribe()},t.render=function(){var t=this.props,e=t.allowNull,n=t.component,r=t.children,i=t.format,o=t.formatOnBlur,a=(t.parse,t.isEqual,t.name),s=(t.subscription,t.validate,t.validateFields,t.reactFinalForm,t.value),u=b(t,["allowNull","component","children","format","formatOnBlur","parse","isEqual","name","subscription","validate","validateFields","reactFinalForm","value"]),c=this.state.state||{},f=(c.blur,c.change,c.focus,c.value),l=(c.name,b(c,["blur","change","focus","value","name"])),p={active:l.active,data:l.data,dirty:l.dirty,dirtySinceLastSubmit:l.dirtySinceLastSubmit,error:l.error,initial:l.initial,invalid:l.invalid,pristine:l.pristine,submitError:l.submitError,submitFailed:l.submitFailed,submitSucceeded:l.submitSucceeded,submitting:l.submitting,touched:l.touched,valid:l.valid,visited:l.visited};o?f=d.defaultProps.format(f,a):i&&(f=i(f,a)),null!==f||e||(f="");var m=v({name:a,value:f},this.handlers);return"checkbox"===u.type?void 0===s?m.checked=!!f:(m.checked=!(!Array.isArray(f)||!~f.indexOf(s)),m.value=s):"radio"===u.type?(m.checked=f===s,m.value=s):"select"===n&&u.multiple&&(m.value=m.value||[]),"function"==typeof r?r(v({input:m,meta:p},u)):"string"==typeof n?h.createElement(n,v({},m,{children:r},u)):y(v({},{input:m,meta:p},{children:r,component:n},u))},d}(h.Component);n.defaultProps={format:function(t,e){return void 0===t?"":t},parse:function(t,e){return""===t?void 0:t}};var a=e(n),f=function(t){return!(!t||"function"!=typeof t.stopPropagation)},l="3.6.0",p={"final-form":s.version,"react-final-form":l},m=s.formSubscriptionItems.reduce(function(t,e){return t[e]=!0,t},{}),d=function(a){function t(t){var e;(e=a.call(this,t)||this).notify=function(t){e.mounted&&e.setState({state:t}),e.mounted=!0},e.handleSubmit=function(t){return t&&("function"==typeof t.preventDefault&&t.preventDefault(),"function"==typeof t.stopPropagation&&t.stopPropagation()),e.form.submit()};t.children,t.component,t.render;var n=t.subscription,r=t.decorators,i=b(t,["children","component","render","subscription","decorators"]);e.mounted=!1;try{e.form=s.createForm(i)}catch(t){}if(e.unsubscriptions=[],e.form){var o={};e.form.subscribe(function(t){o=t},n||m)(),e.state={state:o}}return r&&r.forEach(function(t){e.unsubscriptions.push(t(e.form))}),e}r(t,a);var e=t.prototype;return e.componentWillMount=function(){this.form&&this.form.pauseValidation()},e.componentDidMount=function(){this.form&&(this.unsubscriptions.push(this.form.subscribe(this.notify,this.props.subscription||m)),this.form.resumeValidation())},e.componentWillUpdate=function(){this.form&&(this.resumeValidation=this.resumeValidation||!this.form.isValidationPaused(),this.form.pauseValidation())},e.componentDidUpdate=function(e){var n=this;this.form&&this.resumeValidation&&this.form.resumeValidation(),this.props.initialValues&&!(this.props.initialValuesEqual||function(t,e){if(t===e)return!0;if("object"!=typeof t||!t||"object"!=typeof e||!e)return!1;var n=Object.keys(t),r=Object.keys(e);if(n.length!==r.length)return!1;for(var i=Object.prototype.hasOwnProperty.bind(e),o=0;o<n.length;o++){var a=n[o];if(!i(a)||t[a]!==e[a])return!1}return!0})(e.initialValues,this.props.initialValues)&&this.form.initialize(this.props.initialValues),s.configOptions.forEach(function(t){"initialValues"!==t&&e[t]!==n.props[t]&&n.form.setConfig(t,n.props[t])})},e.componentWillUnmount=function(){this.unsubscriptions.forEach(function(t){return t()})},e.render=function(){var n=this,t=this.props,e=(t.debug,t.initialValues,t.mutators,t.onSubmit,t.subscription,t.validate,t.validateOnBlur,b(t,["debug","initialValues","mutators","onSubmit","subscription","validate","validateOnBlur"])),r=v({},this.state?this.state.state:{},{batch:this.form&&function(t){return n.form.batch(t)},blur:this.form&&function(t){return n.form.blur(t)},change:this.form&&function(t,e){return n.form.change(t,e)},focus:this.form&&function(t){return n.form.focus(t)},form:v({},this.form,{reset:function(t){f(t)?n.form.reset():n.form.reset(t)}}),handleSubmit:this.handleSubmit,initialize:this.form&&function(t){return n.form.initialize(t)},mutators:this.form&&Object.keys(this.form.mutators).reduce(function(t,e){return t[e]=function(){var t;(t=n.form.mutators)[e].apply(t,arguments)},t},{}),reset:this.form&&function(t){return n.form.reset(t)}});return h.createElement(u.Provider,{value:this.form},y(v({},e,r,{__versions:p})))},t}(h.Component),g=e(function(t){function e(e){var r,n;return(r=t.call(this,e)||this).subscribe=function(t,e){var n=t.subscription;r.unsubscribe=r.props.reactFinalForm.subscribe(e,n||m)},r.notify=function(t){r.setState({state:t}),r.props.onChange&&r.props.onChange(t)},r.props.reactFinalForm&&r.subscribe(e,function(t){n?r.notify(t):(n=t,e.onChange&&e.onChange(t))}),n&&(r.state={state:n}),r}r(e,t);var n=e.prototype;return n.componentDidUpdate=function(t){var e=this.props.subscription;i(t.subscription,e,s.formSubscriptionItems)&&this.props.reactFinalForm&&(this.unsubscribe(),this.subscribe(this.props,this.notify))},n.componentWillUnmount=function(){this.unsubscribe()},n.render=function(){var t=this.props,e=t.onChange,n=t.reactFinalForm,r=b(t,["onChange","reactFinalForm"]),i={batch:n&&function(t){return n.batch(t)},blur:n&&function(t){return n.blur(t)},change:n&&function(t,e){return n.change(t,e)},focus:n&&function(t){return n.focus(t)},form:v({},n,{reset:function(t){f(t)?n.reset():n.reset(t)}}),initialize:n&&function(t){return n.initialize(t)},mutators:n&&Object.keys(n.mutators).reduce(function(t,e){return t[e]=function(){var t;(t=n.mutators)[e].apply(t,arguments)},t},{}),reset:n&&function(t){return n.reset(t)}};return e?null:y(v({},r,this.state?this.state.state:{},i))},e}(h.Component));t.Field=a,t.Form=d,t.version=l,t.FormSpy=g,t.withReactFinalForm=e,Object.defineProperty(t,"__esModule",{value:!0})}); | ||
//# sourceMappingURL=react-final-form.umd.min.js.map |
{ | ||
"name": "react-final-form", | ||
"version": "3.7.0", | ||
"version": "4.0.0", | ||
"description": "🏁 High performance subscription-based form state management for React", | ||
@@ -88,3 +88,3 @@ "main": "dist/react-final-form.cjs.js", | ||
"prop-types": "^15.6.0", | ||
"react": "^15.3.0 || ^16.0.0-0" | ||
"react": "^16.3.0" | ||
}, | ||
@@ -91,0 +91,0 @@ "lint-staged": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
147806
2295