@shopify/react-form-state
Advanced tools
Comparing version 1.1.15 to 2.0.0
@@ -5,3 +5,2 @@ 'use strict'; | ||
var _rollupPluginBabelHelpers = require('../_virtual/_rollupPluginBabelHelpers.js'); | ||
var React = require('react'); | ||
@@ -37,7 +36,5 @@ var utilities = require('../utilities.js'); | ||
const existingItem = value[index]; | ||
const newItem = _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, existingItem), {}, { | ||
const newItem = { ...existingItem, | ||
[key]: typeof newValue === 'function' ? newValue(value[index][key]) : newValue | ||
}); | ||
}; | ||
return utilities.replace(value, index, newItem); | ||
@@ -44,0 +41,0 @@ }); |
@@ -5,3 +5,2 @@ 'use strict'; | ||
var _rollupPluginBabelHelpers = require('../_virtual/_rollupPluginBabelHelpers.js'); | ||
var React = require('react'); | ||
@@ -31,5 +30,5 @@ var utilities = require('../utilities.js'); | ||
onChange(value => { | ||
return _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, value), {}, { | ||
return { ...value, | ||
[key]: typeof newValue === 'function' ? newValue(value[key]) : newValue | ||
}); | ||
}; | ||
}); | ||
@@ -36,0 +35,0 @@ }; |
@@ -5,3 +5,2 @@ 'use strict'; | ||
var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js'); | ||
var React = require('react'); | ||
@@ -18,8 +17,6 @@ var utilities = require('./utilities.js'); | ||
/* eslint-disable no-case-declarations */ | ||
class FormState extends React__default["default"].PureComponent { | ||
constructor(...args) { | ||
var _this; | ||
super(...args); | ||
_this = this; | ||
this.state = createFormState(this.props.initialValues, this.props.externalErrors); | ||
@@ -35,66 +32,58 @@ this.mounted = false; | ||
this.submit = /*#__PURE__*/function () { | ||
var _ref = _rollupPluginBabelHelpers.asyncToGenerator(function* (event) { | ||
const { | ||
onSubmit, | ||
validateOnSubmit | ||
} = _this.props; | ||
const { | ||
formData | ||
} = _this; | ||
this.submit = async event => { | ||
const { | ||
onSubmit, | ||
validateOnSubmit | ||
} = this.props; | ||
const { | ||
formData | ||
} = this; | ||
if (!_this.mounted) { | ||
return; | ||
} | ||
if (!this.mounted) { | ||
return; | ||
} | ||
if (event && event.preventDefault && !event.defaultPrevented) { | ||
event.preventDefault(); | ||
} | ||
if (event && event.preventDefault && !event.defaultPrevented) { | ||
event.preventDefault(); | ||
} | ||
if (onSubmit == null) { | ||
return; | ||
} | ||
if (onSubmit == null) { | ||
return; | ||
} | ||
_this.setState({ | ||
submitting: true | ||
}); | ||
this.setState({ | ||
submitting: true | ||
}); | ||
if (validateOnSubmit) { | ||
yield _this.validateForm(); | ||
const clientErrors = _this.clientErrors; | ||
if (validateOnSubmit) { | ||
await this.validateForm(); | ||
const clientErrors = this.clientErrors; | ||
if (clientErrors.length > 0) { | ||
_this.setState({ | ||
submitting: false, | ||
errors: clientErrors | ||
}); | ||
return; | ||
} | ||
} | ||
const errors = (yield onSubmit(formData)) || []; | ||
if (!_this.mounted) { | ||
if (clientErrors.length > 0) { | ||
this.setState({ | ||
submitting: false, | ||
errors: clientErrors | ||
}); | ||
return; | ||
} | ||
} | ||
if (errors.length > 0) { | ||
_this.updateRemoteErrors(errors); | ||
const errors = (await onSubmit(formData)) || []; | ||
_this.setState({ | ||
submitting: false | ||
}); | ||
} else { | ||
_this.setState({ | ||
submitting: false, | ||
errors | ||
}); | ||
} | ||
}); | ||
if (!this.mounted) { | ||
return; | ||
} | ||
return function (_x) { | ||
return _ref.apply(this, arguments); | ||
}; | ||
}(); | ||
if (errors.length > 0) { | ||
this.updateRemoteErrors(errors); | ||
this.setState({ | ||
submitting: false | ||
}); | ||
} else { | ||
this.setState({ | ||
submitting: false, | ||
errors | ||
}); | ||
} | ||
}; | ||
@@ -106,8 +95,7 @@ this.fieldWithHandlers = (field, fieldPath) => { | ||
const result = _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, field), {}, { | ||
const result = { ...field, | ||
name: String(fieldPath), | ||
onChange: this.updateField.bind(this, fieldPath), | ||
onBlur: this.blurField.bind(this, fieldPath) | ||
}); | ||
}; | ||
this.fieldsWithHandlers.set(field, result); | ||
@@ -170,7 +158,7 @@ return result; | ||
} = this; | ||
return children(_rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, formData), {}, { | ||
return children({ ...formData, | ||
submit, | ||
reset, | ||
submitting | ||
})); | ||
}); | ||
} // eslint-disable-next-line @shopify/react-prefer-private-members | ||
@@ -265,5 +253,7 @@ | ||
}), | ||
fields: updatedField === field ? fields : _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, fields), {}, { | ||
fields: updatedField === field ? fields : { // FieldStates<Fields> is not spreadable due to a TS bug | ||
// https://github.com/Microsoft/TypeScript/issues/13557 | ||
...fields, | ||
[fieldPath]: updatedField | ||
}) | ||
} | ||
}; | ||
@@ -308,7 +298,7 @@ }); | ||
return _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, field), {}, { | ||
return { ...field, | ||
value, | ||
dirty, | ||
error | ||
}); | ||
}; | ||
} | ||
@@ -328,7 +318,9 @@ | ||
this.setState(state => ({ | ||
fields: _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, state.fields), {}, { | ||
[fieldPath]: _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, state.fields[fieldPath]), {}, { | ||
fields: { // FieldStates<Fields> is not spreadable due to a TS bug | ||
// https://github.com/Microsoft/TypeScript/issues/13557 | ||
...state.fields, | ||
[fieldPath]: { ...state.fields[fieldPath], | ||
error | ||
}) | ||
}) | ||
} | ||
} | ||
})); | ||
@@ -384,5 +376,5 @@ } | ||
return _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, field), {}, { | ||
return { ...field, | ||
error: errorDictionary[path] | ||
}); | ||
}; | ||
}); | ||
@@ -410,6 +402,6 @@ } | ||
}); | ||
return _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, oldState), {}, { | ||
return { ...oldState, | ||
dirtyFields: Array.from(dirtyFields), | ||
fields: fieldsWithErrors(fields, externalErrors) | ||
}); | ||
}; | ||
} | ||
@@ -471,9 +463,9 @@ | ||
const updatedFields = utilities.mapObject(fields, (field, path) => { | ||
return _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, field), {}, { | ||
return { ...field, | ||
error: runValidator(validators[path], field.value, fields) | ||
}); | ||
}; | ||
}); | ||
return _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, state), {}, { | ||
return { ...state, | ||
fields: updatedFields | ||
}); | ||
}; | ||
} | ||
@@ -480,0 +472,0 @@ |
@@ -5,3 +5,2 @@ 'use strict'; | ||
var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js'); | ||
var isEqual = require('fast-deep-equal'); | ||
@@ -13,3 +12,2 @@ | ||
const _excluded = ["value"]; | ||
function mapObject(input, mapper) { | ||
@@ -40,10 +38,10 @@ return Object.entries(input).reduce((accumulator, [key, value]) => { | ||
} else if (path.length === 1) { | ||
return _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, rootObject), {}, { | ||
return { ...rootObject, | ||
[path[0]]: value | ||
}); | ||
}; | ||
} else { | ||
const [current, ...rest] = path; | ||
return _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, rootObject), {}, { | ||
return { ...rootObject, | ||
[current]: set(rootObject[current] || {}, rest, value) | ||
}); | ||
}; | ||
} | ||
@@ -59,11 +57,10 @@ } | ||
function asChoiceField(_ref) { | ||
let { | ||
value: checked | ||
} = _ref, | ||
fieldData = _rollupPluginBabelHelpers.objectWithoutProperties(_ref, _excluded); | ||
return _rollupPluginBabelHelpers.objectSpread2({ | ||
checked | ||
}, fieldData); | ||
function asChoiceField({ | ||
value: checked, | ||
...fieldData | ||
}) { | ||
return { | ||
checked, | ||
...fieldData | ||
}; | ||
} | ||
@@ -70,0 +67,0 @@ |
{ | ||
"name": "@shopify/react-form-state", | ||
"version": "1.1.15", | ||
"version": "2.0.0", | ||
"license": "MIT", | ||
@@ -23,6 +23,6 @@ "description": "Manage React forms tersely and type-safely with no magic", | ||
"engines": { | ||
"node": ">=12.14.0" | ||
"node": "^14.17.0 || >=16.0.0" | ||
}, | ||
"dependencies": { | ||
"@shopify/predicates": "^2.0.8", | ||
"@shopify/predicates": "^3.0.0", | ||
"fast-deep-equal": "^3.1.3" | ||
@@ -49,6 +49,5 @@ }, | ||
"require": "./index.js" | ||
}, | ||
"./*": "./*" | ||
} | ||
}, | ||
"gitHead": "70feded397084daea784a8c5a523a61ac4fdb34c" | ||
"gitHead": "ef9afc562672dcda9d7800753dc6b777ecd2d751" | ||
} |
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
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
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
78391
40
1611
+ Added@shopify/predicates@3.1.0(transitive)
- Removed@shopify/predicates@2.0.8(transitive)
Updated@shopify/predicates@^3.0.0