@shopify/react-form-state
Advanced tools
Comparing version 1.0.0-sknext-beta.2 to 1.0.0
@@ -1,128 +0,87 @@ | ||
"use strict"; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = void 0; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var _react = _interopRequireDefault(require("react")); | ||
var _rollupPluginBabelHelpers = require('../_virtual/_rollupPluginBabelHelpers.js'); | ||
var React = require('react'); | ||
var utilities = require('../utilities.js'); | ||
var _utilities = require("../utilities"); | ||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
var React__default = /*#__PURE__*/_interopDefaultLegacy(React); | ||
function _typeof(obj) { "@babel/helpers - typeof"; 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); } | ||
class List extends React__default['default'].PureComponent { | ||
constructor(...args) { | ||
super(...args); | ||
this.changeHandlers = new Map(); | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
this.handleChange = ({ | ||
index, | ||
key | ||
}) => { | ||
const hashKey = `${index}:${key}`; | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
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 _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); } | ||
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } | ||
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 _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
var List = /*#__PURE__*/function (_React$PureComponent) { | ||
_inherits(List, _React$PureComponent); | ||
var _super = _createSuper(List); | ||
function List() { | ||
var _this; | ||
_classCallCheck(this, List); | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_this = _super.call.apply(_super, [this].concat(args)); | ||
_this.changeHandlers = new Map(); | ||
_this.handleChange = function (_ref) { | ||
var index = _ref.index, | ||
key = _ref.key; | ||
var hashKey = "".concat(index, ":").concat(key); | ||
if (_this.changeHandlers.has(hashKey)) { | ||
return _this.changeHandlers.get(hashKey); | ||
if (this.changeHandlers.has(hashKey)) { | ||
return this.changeHandlers.get(hashKey); | ||
} | ||
var handler = function handler(newValue) { | ||
var onChange = _this.props.field.onChange; | ||
onChange(function (value) { | ||
var existingItem = value[index]; | ||
const handler = newValue => { | ||
const { | ||
field: { | ||
onChange | ||
} | ||
} = this.props; | ||
onChange(value => { | ||
const existingItem = value[index]; | ||
var newItem = _objectSpread(_objectSpread({}, existingItem), {}, _defineProperty({}, key, typeof newValue === 'function' ? newValue(value[index][key]) : newValue)); | ||
const newItem = _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, existingItem), {}, { | ||
[key]: typeof newValue === 'function' ? newValue(value[index][key]) : newValue | ||
}); | ||
return (0, _utilities.replace)(value, index, newItem); | ||
return utilities.replace(value, index, newItem); | ||
}); | ||
}; | ||
_this.changeHandlers.set(hashKey, handler); | ||
this.changeHandlers.set(hashKey, handler); | ||
return handler; | ||
}; | ||
return _this; | ||
} | ||
_createClass(List, [{ | ||
key: "render", | ||
value: function render() { | ||
var _this2 = this; | ||
var _this$props = this.props, | ||
_this$props$field = _this$props.field, | ||
value = _this$props$field.value, | ||
initialValue = _this$props$field.initialValue, | ||
error = _this$props$field.error, | ||
name = _this$props$field.name, | ||
onBlur = _this$props$field.onBlur, | ||
getChildKey = _this$props.getChildKey, | ||
children = _this$props.children; | ||
return value.map(function (fieldValues, index) { | ||
var innerFields = (0, _utilities.mapObject)(fieldValues, function (value, fieldPath) { | ||
var initialFieldValue = initialValue && initialValue[index] && initialValue[index][fieldPath]; | ||
return { | ||
value: value, | ||
onBlur: onBlur, | ||
name: "".concat(name, ".").concat(index, ".").concat(fieldPath), | ||
initialValue: initialFieldValue, | ||
dirty: value !== initialFieldValue, | ||
error: error && error[index] && error[index][fieldPath], | ||
onChange: _this2.handleChange({ | ||
index: index, | ||
key: fieldPath | ||
}) | ||
}; | ||
}); | ||
var key = getChildKey ? getChildKey(fieldValues) : index; | ||
return /*#__PURE__*/_react["default"].createElement(_react["default"].Fragment, { | ||
key: key | ||
}, children(innerFields, index)); | ||
render() { | ||
const { | ||
field: { | ||
value, | ||
initialValue, | ||
error, | ||
name, | ||
onBlur | ||
}, | ||
getChildKey, | ||
children | ||
} = this.props; | ||
return value.map((fieldValues, index) => { | ||
const innerFields = utilities.mapObject(fieldValues, (value, fieldPath) => { | ||
const initialFieldValue = initialValue && initialValue[index] && initialValue[index][fieldPath]; | ||
return { | ||
value, | ||
onBlur, | ||
name: `${name}.${index}.${fieldPath}`, | ||
initialValue: initialFieldValue, | ||
dirty: value !== initialFieldValue, | ||
error: error && error[index] && error[index][fieldPath], | ||
onChange: this.handleChange({ | ||
index, | ||
key: fieldPath | ||
}) | ||
}; | ||
}); | ||
} | ||
}]); | ||
const key = getChildKey ? getChildKey(fieldValues) : index; | ||
return /*#__PURE__*/React__default['default'].createElement(React__default['default'].Fragment, { | ||
key: key | ||
}, children(innerFields, index)); | ||
}); | ||
} | ||
return List; | ||
}(_react["default"].PureComponent); | ||
} | ||
exports["default"] = List; | ||
exports.default = List; |
@@ -1,111 +0,69 @@ | ||
"use strict"; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = void 0; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var _react = _interopRequireDefault(require("react")); | ||
var _rollupPluginBabelHelpers = require('../_virtual/_rollupPluginBabelHelpers.js'); | ||
var React = require('react'); | ||
var utilities = require('../utilities.js'); | ||
var _utilities = require("../utilities"); | ||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
var React__default = /*#__PURE__*/_interopDefaultLegacy(React); | ||
function _typeof(obj) { "@babel/helpers - typeof"; 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); } | ||
class Nested extends React__default['default'].PureComponent { | ||
constructor(...args) { | ||
super(...args); | ||
this.changeHandlers = new Map(); | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
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 _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); } | ||
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } | ||
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 _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
var Nested = /*#__PURE__*/function (_React$PureComponent) { | ||
_inherits(Nested, _React$PureComponent); | ||
var _super = _createSuper(Nested); | ||
function Nested() { | ||
var _this; | ||
_classCallCheck(this, Nested); | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_this = _super.call.apply(_super, [this].concat(args)); | ||
_this.changeHandlers = new Map(); | ||
_this.handleChange = function (key) { | ||
if (_this.changeHandlers.has(key)) { | ||
return _this.changeHandlers.get(key); | ||
this.handleChange = key => { | ||
if (this.changeHandlers.has(key)) { | ||
return this.changeHandlers.get(key); | ||
} | ||
var handler = function handler(newValue) { | ||
var onChange = _this.props.field.onChange; | ||
onChange(function (value) { | ||
return _objectSpread(_objectSpread({}, value), {}, _defineProperty({}, key, typeof newValue === 'function' ? newValue(value[key]) : newValue)); | ||
const handler = newValue => { | ||
const { | ||
field: { | ||
onChange | ||
} | ||
} = this.props; | ||
onChange(value => { | ||
return _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, value), {}, { | ||
[key]: typeof newValue === 'function' ? newValue(value[key]) : newValue | ||
}); | ||
}); | ||
}; | ||
_this.changeHandlers.set(key, handler); | ||
this.changeHandlers.set(key, handler); | ||
return handler; | ||
}; | ||
} | ||
return _this; | ||
render() { | ||
const { | ||
field: { | ||
name, | ||
value, | ||
onBlur, | ||
initialValue, | ||
error | ||
}, | ||
children | ||
} = this.props; | ||
const innerFields = utilities.mapObject(value, (value, fieldPath) => { | ||
const initialFieldValue = initialValue && initialValue[fieldPath]; | ||
return { | ||
value, | ||
onBlur, | ||
name: `${name}.${fieldPath}`, | ||
initialValue: initialFieldValue, | ||
dirty: value !== initialFieldValue, | ||
error: error && error[fieldPath], | ||
onChange: this.handleChange(fieldPath) | ||
}; | ||
}); | ||
return children(innerFields); | ||
} | ||
_createClass(Nested, [{ | ||
key: "render", | ||
value: function render() { | ||
var _this2 = this; | ||
} | ||
var _this$props = this.props, | ||
_this$props$field = _this$props.field, | ||
name = _this$props$field.name, | ||
value = _this$props$field.value, | ||
onBlur = _this$props$field.onBlur, | ||
initialValue = _this$props$field.initialValue, | ||
error = _this$props$field.error, | ||
children = _this$props.children; | ||
var innerFields = (0, _utilities.mapObject)(value, function (value, fieldPath) { | ||
var initialFieldValue = initialValue && initialValue[fieldPath]; | ||
return { | ||
value: value, | ||
onBlur: onBlur, | ||
name: "".concat(name, ".").concat(fieldPath), | ||
initialValue: initialFieldValue, | ||
dirty: value !== initialFieldValue, | ||
error: error && error[fieldPath], | ||
onChange: _this2.handleChange(fieldPath) | ||
}; | ||
}); | ||
return children(innerFields); | ||
} | ||
}]); | ||
return Nested; | ||
}(_react["default"].PureComponent); | ||
exports["default"] = Nested; | ||
exports.default = Nested; |
@@ -1,195 +0,93 @@ | ||
"use strict"; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports["default"] = void 0; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator")); | ||
var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js'); | ||
var React = require('react'); | ||
var utilities = require('./utilities.js'); | ||
var List = require('./components/List.js'); | ||
var Nested = require('./components/Nested.js'); | ||
var isEqual = require('fast-deep-equal'); | ||
var _react = _interopRequireDefault(require("react")); | ||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
var _utilities = require("./utilities"); | ||
var React__default = /*#__PURE__*/_interopDefaultLegacy(React); | ||
var isEqual__default = /*#__PURE__*/_interopDefaultLegacy(isEqual); | ||
var _components = require("./components"); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _typeof(obj) { "@babel/helpers - typeof"; 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) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); } | ||
function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); } | ||
function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function asyncGeneratorStep(gen, resolve, reject, _next, _throw, key, arg) { try { var info = gen[key](arg); var value = info.value; } catch (error) { reject(error); return; } if (info.done) { resolve(value); } else { Promise.resolve(value).then(_next, _throw); } } | ||
function _asyncToGenerator(fn) { return function () { var self = this, args = arguments; return new Promise(function (resolve, reject) { var gen = fn.apply(self, args); function _next(value) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "next", value); } function _throw(err) { asyncGeneratorStep(gen, resolve, reject, _next, _throw, "throw", err); } _next(undefined); }); }; } | ||
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 _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); } | ||
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; } | ||
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 _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } } | ||
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); } | ||
var FormState = /*#__PURE__*/function (_React$PureComponent) { | ||
_inherits(FormState, _React$PureComponent); | ||
var _super = _createSuper(FormState); | ||
function FormState() { | ||
class FormState extends React__default['default'].PureComponent { | ||
constructor(...args) { | ||
var _this; | ||
_classCallCheck(this, FormState); | ||
super(...args); | ||
_this = this; | ||
this.state = createFormState(this.props.initialValues, this.props.externalErrors); | ||
this.mounted = false; | ||
this.fieldsWithHandlers = new WeakMap(); | ||
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) { | ||
args[_key] = arguments[_key]; | ||
} | ||
_this = _super.call.apply(_super, [this].concat(args)); | ||
_this.state = createFormState(_this.props.initialValues, _this.props.externalErrors); | ||
_this.mounted = false; | ||
_this.fieldsWithHandlers = new WeakMap(); | ||
_this.reset = function () { | ||
return new Promise(function (resolve) { | ||
_this.setState(function (_state, props) { | ||
return createFormState(props.initialValues, props.externalErrors); | ||
}, function () { | ||
return resolve(); | ||
}); | ||
this.reset = () => { | ||
return new Promise(resolve => { | ||
this.setState((_state, props) => createFormState(props.initialValues, props.externalErrors), () => resolve()); | ||
}); | ||
}; | ||
_this.submit = /*#__PURE__*/function () { | ||
var _ref = _asyncToGenerator( /*#__PURE__*/_regenerator["default"].mark(function _callee(event) { | ||
var _this$props, onSubmit, validateOnSubmit, _assertThisInitialize, formData, clientErrors, errors; | ||
this.submit = /*#__PURE__*/function () { | ||
var _ref = _rollupPluginBabelHelpers.asyncToGenerator(function* (event) { | ||
const { | ||
onSubmit, | ||
validateOnSubmit | ||
} = _this.props; | ||
const { | ||
formData | ||
} = _this; | ||
return _regenerator["default"].wrap(function _callee$(_context) { | ||
while (1) { | ||
switch (_context.prev = _context.next) { | ||
case 0: | ||
_this$props = _this.props, onSubmit = _this$props.onSubmit, validateOnSubmit = _this$props.validateOnSubmit; | ||
_assertThisInitialize = _assertThisInitialized(_this), formData = _assertThisInitialize.formData; | ||
if (!_this.mounted) { | ||
return; | ||
} | ||
if (_this.mounted) { | ||
_context.next = 4; | ||
break; | ||
} | ||
if (event && event.preventDefault && !event.defaultPrevented) { | ||
event.preventDefault(); | ||
} | ||
return _context.abrupt("return"); | ||
if (onSubmit == null) { | ||
return; | ||
} | ||
case 4: | ||
if (event && event.preventDefault && !event.defaultPrevented) { | ||
event.preventDefault(); | ||
} | ||
_this.setState({ | ||
submitting: true | ||
}); | ||
if (!(onSubmit == null)) { | ||
_context.next = 7; | ||
break; | ||
} | ||
if (validateOnSubmit) { | ||
yield _this.validateForm(); | ||
const clientErrors = _this.clientErrors; | ||
return _context.abrupt("return"); | ||
if (clientErrors.length > 0) { | ||
_this.setState({ | ||
submitting: false, | ||
errors: clientErrors | ||
}); | ||
case 7: | ||
_this.setState({ | ||
submitting: true | ||
}); | ||
return; | ||
} | ||
} | ||
if (!validateOnSubmit) { | ||
_context.next = 15; | ||
break; | ||
} | ||
const errors = (yield onSubmit(formData)) || []; | ||
_context.next = 11; | ||
return _this.validateForm(); | ||
if (!_this.mounted) { | ||
return; | ||
} | ||
case 11: | ||
clientErrors = _this.clientErrors; | ||
if (errors.length > 0) { | ||
_this.updateRemoteErrors(errors); | ||
if (!(clientErrors.length > 0)) { | ||
_context.next = 15; | ||
break; | ||
} | ||
_this.setState({ | ||
submitting: false | ||
}); | ||
} else { | ||
_this.setState({ | ||
submitting: false, | ||
errors | ||
}); | ||
} | ||
}); | ||
_this.setState({ | ||
submitting: false, | ||
errors: clientErrors | ||
}); | ||
return _context.abrupt("return"); | ||
case 15: | ||
_context.next = 17; | ||
return onSubmit(formData); | ||
case 17: | ||
_context.t0 = _context.sent; | ||
if (_context.t0) { | ||
_context.next = 20; | ||
break; | ||
} | ||
_context.t0 = []; | ||
case 20: | ||
errors = _context.t0; | ||
if (_this.mounted) { | ||
_context.next = 23; | ||
break; | ||
} | ||
return _context.abrupt("return"); | ||
case 23: | ||
if (errors.length > 0) { | ||
_this.updateRemoteErrors(errors); | ||
_this.setState({ | ||
submitting: false | ||
}); | ||
} else { | ||
_this.setState({ | ||
submitting: false, | ||
errors: errors | ||
}); | ||
} | ||
case 24: | ||
case "end": | ||
return _context.stop(); | ||
} | ||
} | ||
}, _callee); | ||
})); | ||
return function (_x) { | ||
@@ -200,275 +98,269 @@ return _ref.apply(this, arguments); | ||
_this.fieldWithHandlers = function (field, fieldPath) { | ||
if (_this.fieldsWithHandlers.has(field)) { | ||
return _this.fieldsWithHandlers.get(field); | ||
this.fieldWithHandlers = (field, fieldPath) => { | ||
if (this.fieldsWithHandlers.has(field)) { | ||
return this.fieldsWithHandlers.get(field); | ||
} | ||
var result = _objectSpread(_objectSpread({}, field), {}, { | ||
const result = _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, field), {}, { | ||
name: String(fieldPath), | ||
onChange: _this.updateField.bind(_assertThisInitialized(_this), fieldPath), | ||
onBlur: _this.blurField.bind(_assertThisInitialized(_this), fieldPath) | ||
onChange: this.updateField.bind(this, fieldPath), | ||
onBlur: this.blurField.bind(this, fieldPath) | ||
}); | ||
_this.fieldsWithHandlers.set(field, result); | ||
this.fieldsWithHandlers.set(field, result); | ||
return result; | ||
}; | ||
return _this; | ||
} | ||
_createClass(FormState, [{ | ||
key: "componentDidMount", | ||
value: function componentDidMount() { | ||
this.mounted = true; | ||
static getDerivedStateFromProps(newProps, oldState) { | ||
const { | ||
initialValues, | ||
onInitialValuesChange, | ||
externalErrors = [] | ||
} = newProps; | ||
const externalErrorsChanged = !isEqual__default['default'](externalErrors, oldState.externalErrors); | ||
const updatedExternalErrors = externalErrorsChanged ? { | ||
externalErrors, | ||
fields: fieldsWithErrors(oldState.fields, [...externalErrors, ...oldState.errors]) | ||
} : null; | ||
switch (onInitialValuesChange) { | ||
case 'ignore': | ||
return updatedExternalErrors; | ||
case 'reset-where-changed': | ||
return reconcileFormState(initialValues, oldState, externalErrors); | ||
case 'reset-all': | ||
default: | ||
const oldInitialValues = initialValuesFromFields(oldState.fields); | ||
const valuesMatch = isEqual__default['default'](oldInitialValues, initialValues); | ||
if (valuesMatch) { | ||
return updatedExternalErrors; | ||
} | ||
return createFormState(initialValues, externalErrors); | ||
} | ||
}, { | ||
key: "componentWillUnmount", | ||
value: function componentWillUnmount() { | ||
this.mounted = false; | ||
} | ||
}, { | ||
key: "render", | ||
value: function render() { | ||
var children = this.props.children; | ||
var submitting = this.state.submitting; | ||
var submit = this.submit, | ||
reset = this.reset, | ||
formData = this.formData; | ||
return children(_objectSpread(_objectSpread({}, formData), {}, { | ||
submit: submit, | ||
reset: reset, | ||
submitting: submitting | ||
})); | ||
} // eslint-disable-next-line @shopify/react-prefer-private-members | ||
} | ||
}, { | ||
key: "validateForm", | ||
value: function validateForm() { | ||
var _this2 = this; | ||
componentDidMount() { | ||
this.mounted = true; | ||
} | ||
return new Promise(function (resolve) { | ||
_this2.setState(runAllValidators, function () { | ||
return resolve(); | ||
}); | ||
}); | ||
} // eslint-disable-next-line @shopify/react-prefer-private-members | ||
componentWillUnmount() { | ||
this.mounted = false; | ||
} | ||
}, { | ||
key: "updateField", | ||
value: function updateField(fieldPath, value) { | ||
var _this3 = this; | ||
render() { | ||
const { | ||
children | ||
} = this.props; | ||
const { | ||
submitting | ||
} = this.state; | ||
const { | ||
submit, | ||
reset, | ||
formData | ||
} = this; | ||
return children(_rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, formData), {}, { | ||
submit, | ||
reset, | ||
submitting | ||
})); | ||
} // eslint-disable-next-line @shopify/react-prefer-private-members | ||
this.setState(function (_ref2) { | ||
var fields = _ref2.fields, | ||
dirtyFields = _ref2.dirtyFields; | ||
var field = fields[fieldPath]; | ||
var newValue = typeof value === 'function' ? value(field.value) : value; | ||
var dirty = !(0, _utilities.isEqual)(newValue, field.initialValue); | ||
var updatedField = _this3.getUpdatedField({ | ||
fieldPath: fieldPath, | ||
field: field, | ||
value: newValue, | ||
dirty: dirty | ||
}); | ||
validateForm() { | ||
return new Promise(resolve => { | ||
this.setState(runAllValidators, () => resolve()); | ||
}); | ||
} // eslint-disable-next-line @shopify/react-prefer-private-members | ||
return { | ||
dirtyFields: _this3.getUpdatedDirtyFields({ | ||
fieldPath: fieldPath, | ||
dirty: dirty, | ||
dirtyFields: dirtyFields | ||
}), | ||
fields: updatedField === field ? fields : _objectSpread(_objectSpread({}, fields), {}, _defineProperty({}, fieldPath, updatedField)) | ||
}; | ||
}); | ||
} | ||
}, { | ||
key: "getUpdatedDirtyFields", | ||
value: function getUpdatedDirtyFields(_ref3) { | ||
var fieldPath = _ref3.fieldPath, | ||
dirty = _ref3.dirty, | ||
dirtyFields = _ref3.dirtyFields; | ||
var dirtyFieldsSet = new Set(dirtyFields); | ||
if (dirty) { | ||
dirtyFieldsSet.add(fieldPath); | ||
} else { | ||
dirtyFieldsSet["delete"](fieldPath); | ||
} | ||
get formData() { | ||
const { | ||
errors | ||
} = this.state; | ||
const { | ||
externalErrors = [] | ||
} = this.props; | ||
const { | ||
fields, | ||
dirty, | ||
valid | ||
} = this; | ||
return { | ||
dirty, | ||
valid, | ||
errors: [...errors, ...externalErrors], | ||
fields | ||
}; | ||
} | ||
var newDirtyFields = Array.from(dirtyFieldsSet); | ||
return dirtyFields.length === newDirtyFields.length ? dirtyFields : newDirtyFields; | ||
} | ||
}, { | ||
key: "getUpdatedField", | ||
value: function getUpdatedField(_ref4) { | ||
var fieldPath = _ref4.fieldPath, | ||
field = _ref4.field, | ||
value = _ref4.value, | ||
dirty = _ref4.dirty; | ||
// We only want to update errors as the user types if they already have an error. | ||
// https://polaris.shopify.com/patterns/error-messages#section-form-validation | ||
var skipValidation = field.error == null; | ||
var error = skipValidation ? field.error : this.validateFieldValue(fieldPath, { | ||
value: value, | ||
dirty: dirty | ||
}); | ||
get dirty() { | ||
return this.state.dirtyFields.length > 0; | ||
} | ||
if (value === field.value && error === field.error) { | ||
return field; | ||
} | ||
get valid() { | ||
const { | ||
errors, | ||
externalErrors | ||
} = this.state; | ||
return !this.hasClientErrors && errors.length === 0 && externalErrors.length === 0; | ||
} | ||
return _objectSpread(_objectSpread({}, field), {}, { | ||
value: value, | ||
dirty: dirty, | ||
error: error | ||
}); | ||
} | ||
}, { | ||
key: "blurField", | ||
value: function blurField(fieldPath) { | ||
var fields = this.state.fields; | ||
var field = fields[fieldPath]; | ||
var error = this.validateFieldValue(fieldPath, field); | ||
get hasClientErrors() { | ||
const { | ||
fields | ||
} = this.state; | ||
return Object.keys(fields).some(fieldPath => { | ||
const field = fields[fieldPath]; | ||
return field.error != null; | ||
}); | ||
} | ||
if (error == null) { | ||
return; | ||
} | ||
get clientErrors() { | ||
const { | ||
fields | ||
} = this.state; | ||
return utilities.flatMap(Object.values(fields), ({ | ||
error | ||
}) => collectErrors(error)); | ||
} | ||
this.setState(function (state) { | ||
return { | ||
fields: _objectSpread(_objectSpread({}, state.fields), {}, _defineProperty({}, fieldPath, _objectSpread(_objectSpread({}, state.fields[fieldPath]), {}, { | ||
error: error | ||
}))) | ||
}; | ||
}); | ||
} | ||
}, { | ||
key: "validateFieldValue", | ||
value: function validateFieldValue(fieldPath, _ref5) { | ||
var value = _ref5.value, | ||
dirty = _ref5.dirty; | ||
get fields() { | ||
const { | ||
fields | ||
} = this.state; | ||
const fieldDescriptors = utilities.mapObject(fields, this.fieldWithHandlers); | ||
return fieldDescriptors; | ||
} | ||
if (!dirty) { | ||
return; | ||
} | ||
var _this$props$validator = this.props.validators, | ||
validators = _this$props$validator === void 0 ? {} : _this$props$validator; | ||
var fields = this.state.fields; | ||
return runValidator(validators[fieldPath], value, fields); | ||
} | ||
}, { | ||
key: "updateRemoteErrors", | ||
value: function updateRemoteErrors(errors) { | ||
this.setState(function (_ref6) { | ||
var fields = _ref6.fields, | ||
externalErrors = _ref6.externalErrors; | ||
return { | ||
errors: errors, | ||
fields: fieldsWithErrors(fields, [].concat(_toConsumableArray(errors), _toConsumableArray(externalErrors))) | ||
}; | ||
updateField(fieldPath, value) { | ||
this.setState(({ | ||
fields, | ||
dirtyFields | ||
}) => { | ||
const field = fields[fieldPath]; | ||
const newValue = typeof value === 'function' ? value(field.value) : value; | ||
const dirty = !isEqual__default['default'](newValue, field.initialValue); | ||
const updatedField = this.getUpdatedField({ | ||
fieldPath, | ||
field, | ||
value: newValue, | ||
dirty | ||
}); | ||
} | ||
}, { | ||
key: "formData", | ||
get: function get() { | ||
var errors = this.state.errors; | ||
var _this$props$externalE = this.props.externalErrors, | ||
externalErrors = _this$props$externalE === void 0 ? [] : _this$props$externalE; | ||
var fields = this.fields, | ||
dirty = this.dirty, | ||
valid = this.valid; | ||
return { | ||
dirty: dirty, | ||
valid: valid, | ||
errors: [].concat(_toConsumableArray(errors), _toConsumableArray(externalErrors)), | ||
fields: fields | ||
dirtyFields: this.getUpdatedDirtyFields({ | ||
fieldPath, | ||
dirty, | ||
dirtyFields | ||
}), | ||
fields: updatedField === field ? fields : _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, fields), {}, { | ||
[fieldPath]: updatedField | ||
}) | ||
}; | ||
}); | ||
} | ||
getUpdatedDirtyFields({ | ||
fieldPath, | ||
dirty, | ||
dirtyFields | ||
}) { | ||
const dirtyFieldsSet = new Set(dirtyFields); | ||
if (dirty) { | ||
dirtyFieldsSet.add(fieldPath); | ||
} else { | ||
dirtyFieldsSet.delete(fieldPath); | ||
} | ||
}, { | ||
key: "dirty", | ||
get: function get() { | ||
return this.state.dirtyFields.length > 0; | ||
const newDirtyFields = Array.from(dirtyFieldsSet); | ||
return dirtyFields.length === newDirtyFields.length ? dirtyFields : newDirtyFields; | ||
} | ||
getUpdatedField({ | ||
fieldPath, | ||
field, | ||
value, | ||
dirty | ||
}) { | ||
// We only want to update errors as the user types if they already have an error. | ||
// https://polaris.shopify.com/patterns/error-messages#section-form-validation | ||
const skipValidation = field.error == null; | ||
const error = skipValidation ? field.error : this.validateFieldValue(fieldPath, { | ||
value, | ||
dirty | ||
}); | ||
if (value === field.value && error === field.error) { | ||
return field; | ||
} | ||
}, { | ||
key: "valid", | ||
get: function get() { | ||
var _this$state = this.state, | ||
errors = _this$state.errors, | ||
externalErrors = _this$state.externalErrors; | ||
return !this.hasClientErrors && errors.length === 0 && externalErrors.length === 0; | ||
} | ||
}, { | ||
key: "hasClientErrors", | ||
get: function get() { | ||
var fields = this.state.fields; | ||
return Object.keys(fields).some(function (fieldPath) { | ||
var field = fields[fieldPath]; | ||
return field.error != null; | ||
}); | ||
} | ||
}, { | ||
key: "clientErrors", | ||
get: function get() { | ||
var fields = this.state.fields; | ||
return (0, _utilities.flatMap)(Object.values(fields), function (_ref7) { | ||
var error = _ref7.error; | ||
return collectErrors(error); | ||
}); | ||
} | ||
}, { | ||
key: "fields", | ||
get: function get() { | ||
var fields = this.state.fields; | ||
var fieldDescriptors = (0, _utilities.mapObject)(fields, this.fieldWithHandlers); | ||
return fieldDescriptors; | ||
} | ||
}], [{ | ||
key: "getDerivedStateFromProps", | ||
value: function getDerivedStateFromProps(newProps, oldState) { | ||
var initialValues = newProps.initialValues, | ||
onInitialValuesChange = newProps.onInitialValuesChange, | ||
_newProps$externalErr = newProps.externalErrors, | ||
externalErrors = _newProps$externalErr === void 0 ? [] : _newProps$externalErr; | ||
var externalErrorsChanged = !(0, _utilities.isEqual)(externalErrors, oldState.externalErrors); | ||
var updatedExternalErrors = externalErrorsChanged ? { | ||
externalErrors: externalErrors, | ||
fields: fieldsWithErrors(oldState.fields, [].concat(_toConsumableArray(externalErrors), _toConsumableArray(oldState.errors))) | ||
} : null; | ||
switch (onInitialValuesChange) { | ||
case 'ignore': | ||
return updatedExternalErrors; | ||
return _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, field), {}, { | ||
value, | ||
dirty, | ||
error | ||
}); | ||
} | ||
case 'reset-where-changed': | ||
return reconcileFormState(initialValues, oldState, externalErrors); | ||
blurField(fieldPath) { | ||
const { | ||
fields | ||
} = this.state; | ||
const field = fields[fieldPath]; | ||
const error = this.validateFieldValue(fieldPath, field); | ||
case 'reset-all': | ||
default: | ||
var oldInitialValues = initialValuesFromFields(oldState.fields); | ||
var valuesMatch = (0, _utilities.isEqual)(oldInitialValues, initialValues); | ||
if (error == null) { | ||
return; | ||
} | ||
if (valuesMatch) { | ||
return updatedExternalErrors; | ||
} | ||
this.setState(state => ({ | ||
fields: _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, state.fields), {}, { | ||
[fieldPath]: _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, state.fields[fieldPath]), {}, { | ||
error | ||
}) | ||
}) | ||
})); | ||
} | ||
return createFormState(initialValues, externalErrors); | ||
} | ||
validateFieldValue(fieldPath, { | ||
value, | ||
dirty | ||
}) { | ||
if (!dirty) { | ||
return; | ||
} | ||
}]); | ||
return FormState; | ||
}(_react["default"].PureComponent); | ||
const { | ||
validators = {} | ||
} = this.props; | ||
const { | ||
fields | ||
} = this.state; | ||
return runValidator(validators[fieldPath], value, fields); | ||
} | ||
exports["default"] = FormState; | ||
FormState.List = _components.List; | ||
FormState.Nested = _components.Nested; | ||
updateRemoteErrors(errors) { | ||
this.setState(({ | ||
fields, | ||
externalErrors | ||
}) => ({ | ||
errors, | ||
fields: fieldsWithErrors(fields, [...errors, ...externalErrors]) | ||
})); | ||
} | ||
} | ||
FormState.List = List['default']; | ||
FormState.Nested = Nested['default']; | ||
function fieldsWithErrors(fields, errors) { | ||
var errorDictionary = errors.reduce(function (accumulator, _ref8) { | ||
var field = _ref8.field, | ||
message = _ref8.message; | ||
const errorDictionary = errors.reduce((accumulator, { | ||
field, | ||
message | ||
}) => { | ||
if (field == null) { | ||
@@ -478,5 +370,5 @@ return accumulator; | ||
return (0, _utilities.set)(accumulator, field, message); | ||
return utilities.set(accumulator, field, message); | ||
}, {}); | ||
return (0, _utilities.mapObject)(fields, function (field, path) { | ||
return utilities.mapObject(fields, (field, path) => { | ||
if (!errorDictionary[path]) { | ||
@@ -486,3 +378,3 @@ return field; | ||
return _objectSpread(_objectSpread({}, field), {}, { | ||
return _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, field), {}, { | ||
error: errorDictionary[path] | ||
@@ -493,16 +385,17 @@ }); | ||
function reconcileFormState(values, oldState) { | ||
var externalErrors = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : []; | ||
var oldFields = oldState.fields; | ||
var dirtyFields = new Set(oldState.dirtyFields); | ||
var fields = (0, _utilities.mapObject)(values, function (value, key) { | ||
var oldField = oldFields[key]; | ||
function reconcileFormState(values, oldState, externalErrors = []) { | ||
const { | ||
fields: oldFields | ||
} = oldState; | ||
const dirtyFields = new Set(oldState.dirtyFields); | ||
const fields = utilities.mapObject(values, (value, key) => { | ||
const oldField = oldFields[key]; | ||
if ((0, _utilities.isEqual)(value, oldField.initialValue)) { | ||
if (isEqual__default['default'](value, oldField.initialValue)) { | ||
return oldField; | ||
} | ||
dirtyFields["delete"](key); | ||
dirtyFields.delete(key); | ||
return { | ||
value: value, | ||
value, | ||
initialValue: value, | ||
@@ -512,3 +405,3 @@ dirty: false | ||
}); | ||
return _objectSpread(_objectSpread({}, oldState), {}, { | ||
return _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, oldState), {}, { | ||
dirtyFields: Array.from(dirtyFields), | ||
@@ -519,7 +412,6 @@ fields: fieldsWithErrors(fields, externalErrors) | ||
function createFormState(values) { | ||
var externalErrors = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : []; | ||
var fields = (0, _utilities.mapObject)(values, function (value) { | ||
function createFormState(values, externalErrors = []) { | ||
const fields = utilities.mapObject(values, value => { | ||
return { | ||
value: value, | ||
value, | ||
initialValue: value, | ||
@@ -533,3 +425,3 @@ dirty: false | ||
submitting: false, | ||
externalErrors: externalErrors, | ||
externalErrors, | ||
fields: fieldsWithErrors(fields, externalErrors) | ||
@@ -540,13 +432,8 @@ }; | ||
function initialValuesFromFields(fields) { | ||
return (0, _utilities.mapObject)(fields, function (_ref9) { | ||
var initialValue = _ref9.initialValue; | ||
return initialValue; | ||
}); | ||
return utilities.mapObject(fields, ({ | ||
initialValue | ||
}) => initialValue); | ||
} | ||
function runValidator() { | ||
var validate = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {}; | ||
var value = arguments.length > 1 ? arguments[1] : undefined; | ||
var fields = arguments.length > 2 ? arguments[2] : undefined; | ||
function runValidator(validate = () => {}, value, fields) { | ||
if (typeof validate === 'function') { | ||
@@ -560,7 +447,3 @@ return validate(value, fields); | ||
var errors = validate.map(function (validator) { | ||
return validator(value, fields); | ||
}).filter(function (input) { | ||
return input != null; | ||
}); | ||
const errors = validate.map(validator => validator(value, fields)).filter(input => input != null); | ||
@@ -575,4 +458,8 @@ if (errors.length === 0) { | ||
function runAllValidators(state, props) { | ||
var fields = state.fields; | ||
var validators = props.validators; | ||
const { | ||
fields | ||
} = state; | ||
const { | ||
validators | ||
} = props; | ||
@@ -583,8 +470,8 @@ if (!validators) { | ||
var updatedFields = (0, _utilities.mapObject)(fields, function (field, path) { | ||
return _objectSpread(_objectSpread({}, field), {}, { | ||
const updatedFields = utilities.mapObject(fields, (field, path) => { | ||
return _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, field), {}, { | ||
error: runValidator(validators[path], field.value, fields) | ||
}); | ||
}); | ||
return _objectSpread(_objectSpread({}, state), {}, { | ||
return _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, state), {}, { | ||
fields: updatedFields | ||
@@ -601,3 +488,3 @@ }); | ||
return [{ | ||
message: message | ||
message | ||
}]; | ||
@@ -607,10 +494,8 @@ } | ||
if (Array.isArray(message)) { | ||
return (0, _utilities.flatMap)(message, function (itemError) { | ||
return collectErrors(itemError); | ||
}); | ||
return utilities.flatMap(message, itemError => collectErrors(itemError)); | ||
} | ||
return (0, _utilities.flatMap)(Object.values(message), function (nestedError) { | ||
return collectErrors(nestedError); | ||
}); | ||
} | ||
return utilities.flatMap(Object.values(message), nestedError => collectErrors(nestedError)); | ||
} | ||
exports.default = FormState; |
@@ -1,79 +0,23 @@ | ||
"use strict"; | ||
'use strict'; | ||
function _typeof(obj) { "@babel/helpers - typeof"; 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); } | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
var _exportNames = { | ||
arrayUtils: true, | ||
asChoiceField: true, | ||
validators: true | ||
var FormState = require('./FormState.js'); | ||
var utilities = require('./utilities.js'); | ||
var validators = require('./validators.js'); | ||
const arrayUtils = { | ||
push: utilities.push, | ||
replace: utilities.replace, | ||
remove: utilities.remove | ||
}; | ||
Object.defineProperty(exports, "asChoiceField", { | ||
enumerable: true, | ||
get: function get() { | ||
return _utilities.asChoiceField; | ||
} | ||
}); | ||
Object.defineProperty(exports, "validators", { | ||
enumerable: true, | ||
get: function get() { | ||
return _validators["default"]; | ||
} | ||
}); | ||
exports["default"] = exports.arrayUtils = void 0; | ||
var _FormState = _interopRequireWildcard(require("./FormState")); | ||
Object.keys(_FormState).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _FormState[key]; | ||
} | ||
}); | ||
}); | ||
var _utilities = require("./utilities"); | ||
var _validators = _interopRequireWildcard(require("./validators")); | ||
Object.keys(_validators).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _validators[key]; | ||
} | ||
}); | ||
}); | ||
var _types = require("./types"); | ||
Object.keys(_types).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _types[key]; | ||
} | ||
}); | ||
}); | ||
function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; } | ||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { "default": obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj["default"] = obj; if (cache) { cache.set(obj, newObj); } return newObj; } | ||
var arrayUtils = { | ||
push: _utilities.push, | ||
replace: _utilities.replace, | ||
remove: _utilities.remove | ||
}; | ||
exports.default = FormState['default']; | ||
exports.asChoiceField = utilities.asChoiceField; | ||
exports.validate = validators.validate; | ||
exports.validateList = validators.validateList; | ||
exports.validateNested = validators.validateNested; | ||
exports.validateRequired = validators.validateRequired; | ||
exports.validateWithFields = validators.validateWithFields; | ||
exports.validators = validators['default']; | ||
exports.arrayUtils = arrayUtils; | ||
var _default = _FormState["default"]; | ||
exports["default"] = _default; |
@@ -1,56 +0,14 @@ | ||
"use strict"; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.mapObject = mapObject; | ||
exports.push = push; | ||
exports.remove = remove; | ||
exports.replace = replace; | ||
exports.set = set; | ||
exports.flatMap = flatMap; | ||
exports.asChoiceField = asChoiceField; | ||
Object.defineProperty(exports, "isEqual", { | ||
enumerable: true, | ||
get: function get() { | ||
return _fastDeepEqual["default"]; | ||
} | ||
}); | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var _fastDeepEqual = _interopRequireDefault(require("fast-deep-equal")); | ||
var _rollupPluginBabelHelpers = require('./_virtual/_rollupPluginBabelHelpers.js'); | ||
var isEqual = require('fast-deep-equal'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; } | ||
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; } | ||
var isEqual__default = /*#__PURE__*/_interopDefaultLegacy(isEqual); | ||
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; } | ||
function _toArray(arr) { return _arrayWithHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableRest(); } | ||
function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && Symbol.iterator in Object(iter)) return Array.from(iter); } | ||
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; } | ||
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; } | ||
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; } | ||
function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); } | ||
function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } | ||
function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); } | ||
function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; } | ||
function _iterableToArrayLimit(arr, i) { if (typeof Symbol === "undefined" || !(Symbol.iterator in Object(arr))) 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 mapObject(input, mapper) { | ||
return Object.entries(input).reduce(function (accumulator, _ref) { | ||
var _ref2 = _slicedToArray(_ref, 2), | ||
key = _ref2[0], | ||
value = _ref2[1]; | ||
return Object.entries(input).reduce((accumulator, [key, value]) => { | ||
accumulator[key] = mapper(value, key); | ||
@@ -60,19 +18,10 @@ return accumulator; | ||
} | ||
function push(array) { | ||
for (var _len = arguments.length, values = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) { | ||
values[_key - 1] = arguments[_key]; | ||
} | ||
function push(array, ...values) { | ||
return array.concat(values); | ||
} | ||
function remove(array, targetIndex) { | ||
return array.filter(function (_, index) { | ||
return index !== targetIndex; | ||
}); | ||
return array.filter((_, index) => index !== targetIndex); | ||
} | ||
function replace(array, targetIndex, newValue) { | ||
return array.map(function (value, index) { | ||
return array.map((value, index) => { | ||
if (index !== targetIndex) { | ||
@@ -85,3 +34,2 @@ return value; | ||
} | ||
function set(rootObject, path, value) { | ||
@@ -91,16 +39,14 @@ if (path.length === 0) { | ||
} else if (path.length === 1) { | ||
return _objectSpread(_objectSpread({}, rootObject), {}, _defineProperty({}, path[0], value)); | ||
return _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, rootObject), {}, { | ||
[path[0]]: value | ||
}); | ||
} else { | ||
var _path = _toArray(path), | ||
current = _path[0], | ||
rest = _path.slice(1); | ||
return _objectSpread(_objectSpread({}, rootObject), {}, _defineProperty({}, current, set(rootObject[current] || {}, rest, value))); | ||
const [current, ...rest] = path; | ||
return _rollupPluginBabelHelpers.objectSpread2(_rollupPluginBabelHelpers.objectSpread2({}, rootObject), {}, { | ||
[current]: set(rootObject[current] || {}, rest, value) | ||
}); | ||
} | ||
} | ||
function flatMap(array, mapper) { | ||
return array.reduce(function (acc, item, index) { | ||
return acc.concat(mapper(item, index)); | ||
}, []); | ||
return array.reduce((acc, item, index) => acc.concat(mapper(item, index)), []); | ||
} | ||
@@ -112,10 +58,25 @@ /** | ||
function asChoiceField(_ref) { | ||
let { | ||
value: checked | ||
} = _ref, | ||
fieldData = _rollupPluginBabelHelpers.objectWithoutProperties(_ref, ["value"]); | ||
function asChoiceField(_ref3) { | ||
var checked = _ref3.value, | ||
fieldData = _objectWithoutProperties(_ref3, ["value"]); | ||
return _rollupPluginBabelHelpers.objectSpread2({ | ||
checked | ||
}, fieldData); | ||
} | ||
return _objectSpread({ | ||
checked: checked | ||
}, fieldData); | ||
} | ||
Object.defineProperty(exports, 'isEqual', { | ||
enumerable: true, | ||
get: function () { | ||
return isEqual__default['default']; | ||
} | ||
}); | ||
exports.asChoiceField = asChoiceField; | ||
exports.flatMap = flatMap; | ||
exports.mapObject = mapObject; | ||
exports.push = push; | ||
exports.remove = remove; | ||
exports.replace = replace; | ||
exports.set = set; |
@@ -1,21 +0,12 @@ | ||
"use strict"; | ||
'use strict'; | ||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.validateNested = validateNested; | ||
exports.validateList = validateList; | ||
exports.validateWithFields = validateWithFields; | ||
exports.validate = validate; | ||
exports.validateRequired = validateRequired; | ||
exports["default"] = void 0; | ||
Object.defineProperty(exports, '__esModule', { value: true }); | ||
var _predicates = require("@shopify/predicates"); | ||
var predicates = require('@shopify/predicates'); | ||
var utilities = require('./utilities.js'); | ||
var _utilities = require("./utilities"); | ||
function validateNested(validatorDictionary) { | ||
return function (input, fields) { | ||
var errors = (0, _utilities.mapObject)(input, function (value, field) { | ||
var validate = validatorDictionary[field]; | ||
return (input, fields) => { | ||
const errors = utilities.mapObject(input, (value, field) => { | ||
const validate = validatorDictionary[field]; | ||
@@ -34,7 +25,3 @@ if (validate == null) { | ||
var errors = validate.map(function (validator) { | ||
return validator(value, fields); | ||
}).filter(function (input) { | ||
return input != null; | ||
}); | ||
const errors = validate.map(validator => validator(value, fields)).filter(input => input != null); | ||
@@ -47,7 +34,3 @@ if (errors.length === 0) { | ||
}); | ||
var anyErrors = Object.keys(errors).map(function (key) { | ||
return errors[key]; | ||
}).some(function (value) { | ||
return value != null; | ||
}); | ||
const anyErrors = Object.keys(errors).map(key => errors[key]).some(value => value != null); | ||
@@ -59,13 +42,8 @@ if (anyErrors) { | ||
} | ||
function validateList(validatorDictionary) { | ||
var validateItem = validateNested(validatorDictionary); | ||
return function (input, fields) { | ||
var errors = input.map(function (item) { | ||
return validateItem(item, fields); | ||
}); | ||
const validateItem = validateNested(validatorDictionary); | ||
return (input, fields) => { | ||
const errors = input.map(item => validateItem(item, fields)); | ||
if (errors.some(function (error) { | ||
return error != null; | ||
})) { | ||
if (errors.some(error => error != null)) { | ||
return errors; | ||
@@ -75,10 +53,8 @@ } | ||
} | ||
function validateWithFields(matcher, errorContent) { | ||
return validate(matcher, errorContent); | ||
} | ||
function validate(matcher, errorContent) { | ||
return function (input, fields) { | ||
var matches = matcher(input, fields); | ||
return (input, fields) => { | ||
const matches = matcher(input, fields); | ||
/* | ||
@@ -89,3 +65,3 @@ always mark empty fields valid to match Polaris guidelines | ||
if ((0, _predicates.isEmpty)(input)) { | ||
if (predicates.isEmpty(input)) { | ||
return; | ||
@@ -105,6 +81,5 @@ } | ||
} | ||
function validateRequired(matcher, errorContent) { | ||
return function (input, fields) { | ||
var matches = matcher(input, fields); | ||
return (input, fields) => { | ||
const matches = matcher(input, fields); | ||
@@ -122,25 +97,31 @@ if (matches) { | ||
} | ||
const validators = { | ||
lengthMoreThan(length, errorContent) { | ||
return validate(predicates.lengthMoreThan(length), errorContent); | ||
}, | ||
var validators = { | ||
lengthMoreThan: function lengthMoreThan(length, errorContent) { | ||
return validate((0, _predicates.lengthMoreThan)(length), errorContent); | ||
lengthLessThan(length, errorContent) { | ||
return validate(predicates.lengthLessThan(length), errorContent); | ||
}, | ||
lengthLessThan: function lengthLessThan(length, errorContent) { | ||
return validate((0, _predicates.lengthLessThan)(length), errorContent); | ||
numericString(errorContent) { | ||
return validate(predicates.isNumericString, errorContent); | ||
}, | ||
numericString: function numericString(errorContent) { | ||
return validate(_predicates.isNumericString, errorContent); | ||
positiveNumericString(errorContent) { | ||
return validate(predicates.isPositiveNumericString, errorContent); | ||
}, | ||
positiveNumericString: function positiveNumericString(errorContent) { | ||
return validate(_predicates.isPositiveNumericString, errorContent); | ||
nonNumericString(errorContent) { | ||
return validate(predicates.notNumericString, errorContent); | ||
}, | ||
nonNumericString: function nonNumericString(errorContent) { | ||
return validate(_predicates.notNumericString, errorContent); | ||
requiredString(errorContent) { | ||
return validateRequired(predicates.notEmptyString, errorContent); | ||
}, | ||
requiredString: function requiredString(errorContent) { | ||
return validateRequired(_predicates.notEmptyString, errorContent); | ||
}, | ||
required: function required(errorContent) { | ||
return validateRequired(_predicates.notEmpty, errorContent); | ||
required(errorContent) { | ||
return validateRequired(predicates.notEmpty, errorContent); | ||
} | ||
}; | ||
@@ -156,3 +137,7 @@ | ||
var _default = validators; | ||
exports["default"] = _default; | ||
exports.default = validators; | ||
exports.validate = validate; | ||
exports.validateList = validateList; | ||
exports.validateNested = validateNested; | ||
exports.validateRequired = validateRequired; | ||
exports.validateWithFields = validateWithFields; |
@@ -1,6 +0,2 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var List_1 = require("./List"); | ||
Object.defineProperty(exports, "List", { enumerable: true, get: function () { return List_1.default; } }); | ||
var Nested_1 = require("./Nested"); | ||
Object.defineProperty(exports, "Nested", { enumerable: true, get: function () { return Nested_1.default; } }); | ||
export { default as List } from './List'; | ||
export { default as Nested } from './Nested'; |
@@ -1,83 +0,47 @@ | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var react_1 = __importDefault(require("react")); | ||
var utilities_1 = require("../utilities"); | ||
var List = /** @class */ (function (_super) { | ||
__extends(List, _super); | ||
function List() { | ||
var _this = _super !== null && _super.apply(this, arguments) || this; | ||
_this.changeHandlers = new Map(); | ||
_this.handleChange = function (_a) { | ||
var index = _a.index, key = _a.key; | ||
var hashKey = index + ":" + key; | ||
if (_this.changeHandlers.has(hashKey)) { | ||
return _this.changeHandlers.get(hashKey); | ||
import React from 'react'; | ||
import { mapObject, replace } from '../utilities'; | ||
export default class List extends React.PureComponent { | ||
constructor() { | ||
super(...arguments); | ||
this.changeHandlers = new Map(); | ||
this.handleChange = ({ index, key, }) => { | ||
const hashKey = `${index}:${key}`; | ||
if (this.changeHandlers.has(hashKey)) { | ||
return this.changeHandlers.get(hashKey); | ||
} | ||
var handler = function (newValue) { | ||
var onChange = _this.props.field.onChange; | ||
onChange(function (value) { | ||
var _a; | ||
var existingItem = value[index]; | ||
var newItem = __assign(__assign({}, existingItem), (_a = {}, _a[key] = typeof newValue === 'function' | ||
? newValue(value[index][key]) | ||
: newValue, _a)); | ||
return utilities_1.replace(value, index, newItem); | ||
const handler = (newValue) => { | ||
const { field: { onChange }, } = this.props; | ||
onChange(value => { | ||
const existingItem = value[index]; | ||
const newItem = Object.assign(Object.assign({}, existingItem), { [key]: typeof newValue === 'function' | ||
? newValue(value[index][key]) | ||
: newValue }); | ||
return replace(value, index, newItem); | ||
}); | ||
}; | ||
_this.changeHandlers.set(hashKey, handler); | ||
this.changeHandlers.set(hashKey, handler); | ||
return handler; | ||
}; | ||
return _this; | ||
} | ||
List.prototype.render = function () { | ||
var _this = this; | ||
var _a = this.props, _b = _a.field, value = _b.value, initialValue = _b.initialValue, error = _b.error, name = _b.name, onBlur = _b.onBlur, getChildKey = _a.getChildKey, children = _a.children; | ||
return value.map(function (fieldValues, index) { | ||
var innerFields = utilities_1.mapObject(fieldValues, function (value, fieldPath) { | ||
var initialFieldValue = initialValue && | ||
render() { | ||
const { field: { value, initialValue, error, name, onBlur }, getChildKey, children, } = this.props; | ||
return value.map((fieldValues, index) => { | ||
const innerFields = mapObject(fieldValues, (value, fieldPath) => { | ||
const initialFieldValue = initialValue && | ||
initialValue[index] && | ||
initialValue[index][fieldPath]; | ||
return { | ||
value: value, | ||
onBlur: onBlur, | ||
name: name + "." + index + "." + fieldPath, | ||
value, | ||
onBlur, | ||
name: `${name}.${index}.${fieldPath}`, | ||
initialValue: initialFieldValue, | ||
dirty: value !== initialFieldValue, | ||
error: error && error[index] && error[index][fieldPath], | ||
onChange: _this.handleChange({ index: index, key: fieldPath }), | ||
onChange: this.handleChange({ index, key: fieldPath }), | ||
}; | ||
}); | ||
var key = getChildKey ? getChildKey(fieldValues) : index; | ||
return (react_1.default.createElement(react_1.default.Fragment, { key: key }, children(innerFields, index))); | ||
const key = getChildKey ? getChildKey(fieldValues) : index; | ||
return (React.createElement(React.Fragment, { key: key }, children(innerFields, index))); | ||
}); | ||
}; | ||
return List; | ||
}(react_1.default.PureComponent)); | ||
exports.default = List; | ||
} | ||
} |
@@ -1,74 +0,39 @@ | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
var react_1 = __importDefault(require("react")); | ||
var utilities_1 = require("../utilities"); | ||
var Nested = /** @class */ (function (_super) { | ||
__extends(Nested, _super); | ||
function Nested() { | ||
var _this = _super !== null && _super.apply(this, arguments) || this; | ||
_this.changeHandlers = new Map(); | ||
_this.handleChange = function (key) { | ||
if (_this.changeHandlers.has(key)) { | ||
return _this.changeHandlers.get(key); | ||
import React from 'react'; | ||
import { mapObject } from '../utilities'; | ||
export default class Nested extends React.PureComponent { | ||
constructor() { | ||
super(...arguments); | ||
this.changeHandlers = new Map(); | ||
this.handleChange = (key) => { | ||
if (this.changeHandlers.has(key)) { | ||
return this.changeHandlers.get(key); | ||
} | ||
var handler = function (newValue) { | ||
var onChange = _this.props.field.onChange; | ||
onChange(function (value) { | ||
var _a; | ||
return __assign(__assign({}, value), (_a = {}, _a[key] = typeof newValue === 'function' | ||
? newValue(value[key]) | ||
: newValue, _a)); | ||
const handler = (newValue) => { | ||
const { field: { onChange }, } = this.props; | ||
onChange(value => { | ||
return Object.assign(Object.assign({}, value), { [key]: typeof newValue === 'function' | ||
? newValue(value[key]) | ||
: newValue }); | ||
}); | ||
}; | ||
_this.changeHandlers.set(key, handler); | ||
this.changeHandlers.set(key, handler); | ||
return handler; | ||
}; | ||
return _this; | ||
} | ||
Nested.prototype.render = function () { | ||
var _this = this; | ||
var _a = this.props, _b = _a.field, name = _b.name, value = _b.value, onBlur = _b.onBlur, initialValue = _b.initialValue, error = _b.error, children = _a.children; | ||
var innerFields = utilities_1.mapObject(value, function (value, fieldPath) { | ||
var initialFieldValue = initialValue && initialValue[fieldPath]; | ||
render() { | ||
const { field: { name, value, onBlur, initialValue, error }, children, } = this.props; | ||
const innerFields = mapObject(value, (value, fieldPath) => { | ||
const initialFieldValue = initialValue && initialValue[fieldPath]; | ||
return { | ||
value: value, | ||
onBlur: onBlur, | ||
name: name + "." + fieldPath, | ||
value, | ||
onBlur, | ||
name: `${name}.${fieldPath}`, | ||
initialValue: initialFieldValue, | ||
dirty: value !== initialFieldValue, | ||
error: error && error[fieldPath], | ||
onChange: _this.handleChange(fieldPath), | ||
onChange: this.handleChange(fieldPath), | ||
}; | ||
}); | ||
return children(innerFields); | ||
}; | ||
return Nested; | ||
}(react_1.default.PureComponent)); | ||
exports.default = Nested; | ||
} | ||
} |
@@ -40,3 +40,3 @@ import React from 'react'; | ||
fields: FieldStates<Fields>; | ||
dirtyFields: (keyof Fields)[]; | ||
dirtyFields: Array<keyof Fields>; | ||
errors: RemoteError[]; | ||
@@ -43,0 +43,0 @@ externalErrors: RemoteError[]; |
@@ -1,166 +0,69 @@ | ||
"use strict"; | ||
var __extends = (this && this.__extends) || (function () { | ||
var extendStatics = function (d, b) { | ||
extendStatics = Object.setPrototypeOf || | ||
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || | ||
function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; | ||
return extendStatics(d, b); | ||
}; | ||
return function (d, b) { | ||
extendStatics(d, b); | ||
function __() { this.constructor = d; } | ||
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); | ||
}; | ||
})(); | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { | ||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } | ||
return new (P || (P = Promise))(function (resolve, reject) { | ||
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } | ||
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } | ||
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } | ||
step((generator = generator.apply(thisArg, _arguments || [])).next()); | ||
}); | ||
}; | ||
var __generator = (this && this.__generator) || function (thisArg, body) { | ||
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; | ||
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; | ||
function verb(n) { return function (v) { return step([n, v]); }; } | ||
function step(op) { | ||
if (f) throw new TypeError("Generator is already executing."); | ||
while (_) try { | ||
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; | ||
if (y = 0, t) op = [op[0] & 2, t.value]; | ||
switch (op[0]) { | ||
case 0: case 1: t = op; break; | ||
case 4: _.label++; return { value: op[1], done: false }; | ||
case 5: _.label++; y = op[1]; op = [0]; continue; | ||
case 7: op = _.ops.pop(); _.trys.pop(); continue; | ||
default: | ||
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } | ||
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } | ||
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } | ||
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } | ||
if (t[2]) _.ops.pop(); | ||
_.trys.pop(); continue; | ||
} | ||
op = body.call(thisArg, _); | ||
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } | ||
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; | ||
} | ||
}; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __spread = (this && this.__spread) || function () { | ||
for (var ar = [], i = 0; i < arguments.length; i++) ar = ar.concat(__read(arguments[i])); | ||
return ar; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
/* eslint-disable no-case-declarations */ | ||
var react_1 = __importDefault(require("react")); | ||
var utilities_1 = require("./utilities"); | ||
var components_1 = require("./components"); | ||
var FormState = /** @class */ (function (_super) { | ||
__extends(FormState, _super); | ||
function FormState() { | ||
var _this = _super !== null && _super.apply(this, arguments) || this; | ||
_this.state = createFormState(_this.props.initialValues, _this.props.externalErrors); | ||
_this.mounted = false; | ||
_this.fieldsWithHandlers = new WeakMap(); | ||
import React from 'react'; | ||
import { mapObject, set, isEqual, flatMap } from './utilities'; | ||
import { List, Nested } from './components'; | ||
export default class FormState extends React.PureComponent { | ||
constructor() { | ||
super(...arguments); | ||
this.state = createFormState(this.props.initialValues, this.props.externalErrors); | ||
this.mounted = false; | ||
this.fieldsWithHandlers = new WeakMap(); | ||
// eslint-disable-next-line @shopify/react-prefer-private-members | ||
_this.reset = function () { | ||
return new Promise(function (resolve) { | ||
_this.setState(function (_state, props) { | ||
return createFormState(props.initialValues, props.externalErrors); | ||
}, function () { return resolve(); }); | ||
this.reset = () => { | ||
return new Promise(resolve => { | ||
this.setState((_state, props) => createFormState(props.initialValues, props.externalErrors), () => resolve()); | ||
}); | ||
}; | ||
_this.submit = function (event) { return __awaiter(_this, void 0, void 0, function () { | ||
var _a, onSubmit, validateOnSubmit, formData, clientErrors, errors; | ||
return __generator(this, function (_b) { | ||
switch (_b.label) { | ||
case 0: | ||
_a = this.props, onSubmit = _a.onSubmit, validateOnSubmit = _a.validateOnSubmit; | ||
formData = this.formData; | ||
if (!this.mounted) { | ||
return [2 /*return*/]; | ||
} | ||
if (event && event.preventDefault && !event.defaultPrevented) { | ||
event.preventDefault(); | ||
} | ||
if (onSubmit == null) { | ||
return [2 /*return*/]; | ||
} | ||
this.setState({ submitting: true }); | ||
if (!validateOnSubmit) return [3 /*break*/, 2]; | ||
return [4 /*yield*/, this.validateForm()]; | ||
case 1: | ||
_b.sent(); | ||
clientErrors = this.clientErrors; | ||
if (clientErrors.length > 0) { | ||
this.setState({ submitting: false, errors: clientErrors }); | ||
return [2 /*return*/]; | ||
} | ||
_b.label = 2; | ||
case 2: return [4 /*yield*/, onSubmit(formData)]; | ||
case 3: | ||
errors = (_b.sent()) || []; | ||
if (!this.mounted) { | ||
return [2 /*return*/]; | ||
} | ||
if (errors.length > 0) { | ||
this.updateRemoteErrors(errors); | ||
this.setState({ submitting: false }); | ||
} | ||
else { | ||
this.setState({ submitting: false, errors: errors }); | ||
} | ||
return [2 /*return*/]; | ||
this.submit = async (event) => { | ||
const { onSubmit, validateOnSubmit } = this.props; | ||
const { formData } = this; | ||
if (!this.mounted) { | ||
return; | ||
} | ||
if (event && event.preventDefault && !event.defaultPrevented) { | ||
event.preventDefault(); | ||
} | ||
if (onSubmit == null) { | ||
return; | ||
} | ||
this.setState({ submitting: true }); | ||
if (validateOnSubmit) { | ||
await this.validateForm(); | ||
const clientErrors = this.clientErrors; | ||
if (clientErrors.length > 0) { | ||
this.setState({ submitting: false, errors: clientErrors }); | ||
return; | ||
} | ||
}); | ||
}); }; | ||
_this.fieldWithHandlers = function (field, fieldPath) { | ||
if (_this.fieldsWithHandlers.has(field)) { | ||
return _this.fieldsWithHandlers.get(field); | ||
} | ||
var result = __assign(__assign({}, field), { name: String(fieldPath), onChange: _this.updateField.bind(_this, fieldPath), onBlur: _this.blurField.bind(_this, fieldPath) }); | ||
_this.fieldsWithHandlers.set(field, result); | ||
const errors = (await onSubmit(formData)) || []; | ||
if (!this.mounted) { | ||
return; | ||
} | ||
if (errors.length > 0) { | ||
this.updateRemoteErrors(errors); | ||
this.setState({ submitting: false }); | ||
} | ||
else { | ||
this.setState({ submitting: false, errors }); | ||
} | ||
}; | ||
this.fieldWithHandlers = (field, fieldPath) => { | ||
if (this.fieldsWithHandlers.has(field)) { | ||
return this.fieldsWithHandlers.get(field); | ||
} | ||
const result = Object.assign(Object.assign({}, field), { name: String(fieldPath), onChange: this.updateField.bind(this, fieldPath), onBlur: this.blurField.bind(this, fieldPath) }); | ||
this.fieldsWithHandlers.set(field, result); | ||
return result; | ||
}; | ||
return _this; | ||
} | ||
FormState.getDerivedStateFromProps = function (newProps, oldState) { | ||
var initialValues = newProps.initialValues, onInitialValuesChange = newProps.onInitialValuesChange, _a = newProps.externalErrors, externalErrors = _a === void 0 ? [] : _a; | ||
var externalErrorsChanged = !utilities_1.isEqual(externalErrors, oldState.externalErrors); | ||
var updatedExternalErrors = externalErrorsChanged | ||
static getDerivedStateFromProps(newProps, oldState) { | ||
const { initialValues, onInitialValuesChange, externalErrors = [], } = newProps; | ||
const externalErrorsChanged = !isEqual(externalErrors, oldState.externalErrors); | ||
const updatedExternalErrors = externalErrorsChanged | ||
? { | ||
externalErrors: externalErrors, | ||
fields: fieldsWithErrors(oldState.fields, __spread(externalErrors, oldState.errors)), | ||
externalErrors, | ||
fields: fieldsWithErrors(oldState.fields, [ | ||
...externalErrors, | ||
...oldState.errors, | ||
]), | ||
} | ||
@@ -175,4 +78,4 @@ : null; | ||
default: | ||
var oldInitialValues = initialValuesFromFields(oldState.fields); | ||
var valuesMatch = utilities_1.isEqual(oldInitialValues, initialValues); | ||
const oldInitialValues = initialValuesFromFields(oldState.fields); | ||
const valuesMatch = isEqual(oldInitialValues, initialValues); | ||
if (valuesMatch) { | ||
@@ -183,118 +86,86 @@ return updatedExternalErrors; | ||
} | ||
}; | ||
FormState.prototype.componentDidMount = function () { | ||
} | ||
componentDidMount() { | ||
this.mounted = true; | ||
}; | ||
FormState.prototype.componentWillUnmount = function () { | ||
} | ||
componentWillUnmount() { | ||
this.mounted = false; | ||
}; | ||
FormState.prototype.render = function () { | ||
var children = this.props.children; | ||
var submitting = this.state.submitting; | ||
var _a = this, submit = _a.submit, reset = _a.reset, formData = _a.formData; | ||
return children(__assign(__assign({}, formData), { submit: submit, | ||
reset: reset, | ||
submitting: submitting })); | ||
}; | ||
} | ||
render() { | ||
const { children } = this.props; | ||
const { submitting } = this.state; | ||
const { submit, reset, formData } = this; | ||
return children(Object.assign(Object.assign({}, formData), { submit, | ||
reset, | ||
submitting })); | ||
} | ||
// eslint-disable-next-line @shopify/react-prefer-private-members | ||
FormState.prototype.validateForm = function () { | ||
var _this = this; | ||
return new Promise(function (resolve) { | ||
_this.setState(runAllValidators, function () { return resolve(); }); | ||
validateForm() { | ||
return new Promise(resolve => { | ||
this.setState(runAllValidators, () => resolve()); | ||
}); | ||
}; | ||
Object.defineProperty(FormState.prototype, "formData", { | ||
get: function () { | ||
var errors = this.state.errors; | ||
var _a = this.props.externalErrors, externalErrors = _a === void 0 ? [] : _a; | ||
var _b = this, fields = _b.fields, dirty = _b.dirty, valid = _b.valid; | ||
return { | ||
dirty: dirty, | ||
valid: valid, | ||
errors: __spread(errors, externalErrors), | ||
fields: fields, | ||
}; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(FormState.prototype, "dirty", { | ||
get: function () { | ||
return this.state.dirtyFields.length > 0; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(FormState.prototype, "valid", { | ||
get: function () { | ||
var _a = this.state, errors = _a.errors, externalErrors = _a.externalErrors; | ||
return (!this.hasClientErrors && | ||
errors.length === 0 && | ||
externalErrors.length === 0); | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(FormState.prototype, "hasClientErrors", { | ||
get: function () { | ||
var fields = this.state.fields; | ||
return Object.keys(fields).some(function (fieldPath) { | ||
var field = fields[fieldPath]; | ||
return field.error != null; | ||
}); | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(FormState.prototype, "clientErrors", { | ||
get: function () { | ||
var fields = this.state.fields; | ||
return utilities_1.flatMap(Object.values(fields), function (_a) { | ||
var error = _a.error; | ||
return collectErrors(error); | ||
}); | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
Object.defineProperty(FormState.prototype, "fields", { | ||
get: function () { | ||
var fields = this.state.fields; | ||
var fieldDescriptors = utilities_1.mapObject(fields, this.fieldWithHandlers); | ||
return fieldDescriptors; | ||
}, | ||
enumerable: false, | ||
configurable: true | ||
}); | ||
FormState.prototype.updateField = function (fieldPath, value) { | ||
var _this = this; | ||
this.setState(function (_a) { | ||
var _b; | ||
var fields = _a.fields, dirtyFields = _a.dirtyFields; | ||
var field = fields[fieldPath]; | ||
var newValue = typeof value === 'function' | ||
} | ||
get formData() { | ||
const { errors } = this.state; | ||
const { externalErrors = [] } = this.props; | ||
const { fields, dirty, valid } = this; | ||
return { | ||
dirty, | ||
valid, | ||
errors: [...errors, ...externalErrors], | ||
fields, | ||
}; | ||
} | ||
get dirty() { | ||
return this.state.dirtyFields.length > 0; | ||
} | ||
get valid() { | ||
const { errors, externalErrors } = this.state; | ||
return (!this.hasClientErrors && | ||
errors.length === 0 && | ||
externalErrors.length === 0); | ||
} | ||
get hasClientErrors() { | ||
const { fields } = this.state; | ||
return Object.keys(fields).some(fieldPath => { | ||
const field = fields[fieldPath]; | ||
return field.error != null; | ||
}); | ||
} | ||
get clientErrors() { | ||
const { fields } = this.state; | ||
return flatMap(Object.values(fields), ({ error }) => collectErrors(error)); | ||
} | ||
get fields() { | ||
const { fields } = this.state; | ||
const fieldDescriptors = mapObject(fields, this.fieldWithHandlers); | ||
return fieldDescriptors; | ||
} | ||
updateField(fieldPath, value) { | ||
this.setState(({ fields, dirtyFields }) => { | ||
const field = fields[fieldPath]; | ||
const newValue = typeof value === 'function' | ||
? value(field.value) | ||
: value; | ||
var dirty = !utilities_1.isEqual(newValue, field.initialValue); | ||
var updatedField = _this.getUpdatedField({ | ||
fieldPath: fieldPath, | ||
field: field, | ||
const dirty = !isEqual(newValue, field.initialValue); | ||
const updatedField = this.getUpdatedField({ | ||
fieldPath, | ||
field, | ||
value: newValue, | ||
dirty: dirty, | ||
dirty, | ||
}); | ||
return { | ||
dirtyFields: _this.getUpdatedDirtyFields({ | ||
fieldPath: fieldPath, | ||
dirty: dirty, | ||
dirtyFields: dirtyFields, | ||
dirtyFields: this.getUpdatedDirtyFields({ | ||
fieldPath, | ||
dirty, | ||
dirtyFields, | ||
}), | ||
fields: updatedField === field | ||
? fields | ||
: __assign(__assign({}, fields), (_b = {}, _b[fieldPath] = updatedField, _b)), | ||
: Object.assign(Object.assign({}, fields), { [fieldPath]: updatedField }), | ||
}; | ||
}); | ||
}; | ||
FormState.prototype.getUpdatedDirtyFields = function (_a) { | ||
var fieldPath = _a.fieldPath, dirty = _a.dirty, dirtyFields = _a.dirtyFields; | ||
var dirtyFieldsSet = new Set(dirtyFields); | ||
} | ||
getUpdatedDirtyFields({ fieldPath, dirty, dirtyFields, }) { | ||
const dirtyFieldsSet = new Set(dirtyFields); | ||
if (dirty) { | ||
@@ -306,81 +177,69 @@ dirtyFieldsSet.add(fieldPath); | ||
} | ||
var newDirtyFields = Array.from(dirtyFieldsSet); | ||
const newDirtyFields = Array.from(dirtyFieldsSet); | ||
return dirtyFields.length === newDirtyFields.length | ||
? dirtyFields | ||
: newDirtyFields; | ||
}; | ||
FormState.prototype.getUpdatedField = function (_a) { | ||
var fieldPath = _a.fieldPath, field = _a.field, value = _a.value, dirty = _a.dirty; | ||
} | ||
getUpdatedField({ fieldPath, field, value, dirty, }) { | ||
// We only want to update errors as the user types if they already have an error. | ||
// https://polaris.shopify.com/patterns/error-messages#section-form-validation | ||
var skipValidation = field.error == null; | ||
var error = skipValidation | ||
const skipValidation = field.error == null; | ||
const error = skipValidation | ||
? field.error | ||
: this.validateFieldValue(fieldPath, { value: value, dirty: dirty }); | ||
: this.validateFieldValue(fieldPath, { value, dirty }); | ||
if (value === field.value && error === field.error) { | ||
return field; | ||
} | ||
return __assign(__assign({}, field), { value: value, | ||
dirty: dirty, | ||
error: error }); | ||
}; | ||
FormState.prototype.blurField = function (fieldPath) { | ||
var fields = this.state.fields; | ||
var field = fields[fieldPath]; | ||
var error = this.validateFieldValue(fieldPath, field); | ||
return Object.assign(Object.assign({}, field), { value, | ||
dirty, | ||
error }); | ||
} | ||
blurField(fieldPath) { | ||
const { fields } = this.state; | ||
const field = fields[fieldPath]; | ||
const error = this.validateFieldValue(fieldPath, field); | ||
if (error == null) { | ||
return; | ||
} | ||
this.setState(function (state) { | ||
var _a; | ||
return ({ | ||
fields: __assign(__assign({}, state.fields), (_a = {}, _a[fieldPath] = __assign(__assign({}, state.fields[fieldPath]), { error: error }), _a)), | ||
}); | ||
}); | ||
}; | ||
FormState.prototype.validateFieldValue = function (fieldPath, _a) { | ||
var value = _a.value, dirty = _a.dirty; | ||
this.setState(state => ({ | ||
fields: Object.assign(Object.assign({}, state.fields), { [fieldPath]: Object.assign(Object.assign({}, state.fields[fieldPath]), { error }) }), | ||
})); | ||
} | ||
validateFieldValue(fieldPath, { value, dirty }) { | ||
if (!dirty) { | ||
return; | ||
} | ||
var _b = this.props.validators, validators = _b === void 0 ? {} : _b; | ||
var fields = this.state.fields; | ||
const { validators = {}, } = this.props; | ||
const { fields } = this.state; | ||
return runValidator(validators[fieldPath], value, fields); | ||
}; | ||
FormState.prototype.updateRemoteErrors = function (errors) { | ||
this.setState(function (_a) { | ||
var fields = _a.fields, externalErrors = _a.externalErrors; | ||
return ({ | ||
errors: errors, | ||
fields: fieldsWithErrors(fields, __spread(errors, externalErrors)), | ||
}); | ||
}); | ||
}; | ||
FormState.List = components_1.List; | ||
FormState.Nested = components_1.Nested; | ||
return FormState; | ||
}(react_1.default.PureComponent)); | ||
exports.default = FormState; | ||
} | ||
updateRemoteErrors(errors) { | ||
this.setState(({ fields, externalErrors }) => ({ | ||
errors, | ||
fields: fieldsWithErrors(fields, [...errors, ...externalErrors]), | ||
})); | ||
} | ||
} | ||
FormState.List = List; | ||
FormState.Nested = Nested; | ||
function fieldsWithErrors(fields, errors) { | ||
var errorDictionary = errors.reduce(function (accumulator, _a) { | ||
var field = _a.field, message = _a.message; | ||
const errorDictionary = errors.reduce((accumulator, { field, message }) => { | ||
if (field == null) { | ||
return accumulator; | ||
} | ||
return utilities_1.set(accumulator, field, message); | ||
return set(accumulator, field, message); | ||
}, {}); | ||
return utilities_1.mapObject(fields, function (field, path) { | ||
return mapObject(fields, (field, path) => { | ||
if (!errorDictionary[path]) { | ||
return field; | ||
} | ||
return __assign(__assign({}, field), { error: errorDictionary[path] }); | ||
return Object.assign(Object.assign({}, field), { error: errorDictionary[path] }); | ||
}); | ||
} | ||
function reconcileFormState(values, oldState, externalErrors) { | ||
if (externalErrors === void 0) { externalErrors = []; } | ||
var oldFields = oldState.fields; | ||
var dirtyFields = new Set(oldState.dirtyFields); | ||
var fields = utilities_1.mapObject(values, function (value, key) { | ||
var oldField = oldFields[key]; | ||
if (utilities_1.isEqual(value, oldField.initialValue)) { | ||
function reconcileFormState(values, oldState, externalErrors = []) { | ||
const { fields: oldFields } = oldState; | ||
const dirtyFields = new Set(oldState.dirtyFields); | ||
const fields = mapObject(values, (value, key) => { | ||
const oldField = oldFields[key]; | ||
if (isEqual(value, oldField.initialValue)) { | ||
return oldField; | ||
@@ -390,3 +249,3 @@ } | ||
return { | ||
value: value, | ||
value, | ||
initialValue: value, | ||
@@ -396,9 +255,8 @@ dirty: false, | ||
}); | ||
return __assign(__assign({}, oldState), { dirtyFields: Array.from(dirtyFields), fields: fieldsWithErrors(fields, externalErrors) }); | ||
return Object.assign(Object.assign({}, oldState), { dirtyFields: Array.from(dirtyFields), fields: fieldsWithErrors(fields, externalErrors) }); | ||
} | ||
function createFormState(values, externalErrors) { | ||
if (externalErrors === void 0) { externalErrors = []; } | ||
var fields = utilities_1.mapObject(values, function (value) { | ||
function createFormState(values, externalErrors = []) { | ||
const fields = mapObject(values, value => { | ||
return { | ||
value: value, | ||
value, | ||
initialValue: value, | ||
@@ -412,3 +270,3 @@ dirty: false, | ||
submitting: false, | ||
externalErrors: externalErrors, | ||
externalErrors, | ||
fields: fieldsWithErrors(fields, externalErrors), | ||
@@ -418,9 +276,5 @@ }; | ||
function initialValuesFromFields(fields) { | ||
return utilities_1.mapObject(fields, function (_a) { | ||
var initialValue = _a.initialValue; | ||
return initialValue; | ||
}); | ||
return mapObject(fields, ({ initialValue }) => initialValue); | ||
} | ||
function runValidator(validate, value, fields) { | ||
if (validate === void 0) { validate = function () { }; } | ||
function runValidator(validate = () => { }, value, fields) { | ||
if (typeof validate === 'function') { | ||
@@ -432,5 +286,5 @@ return validate(value, fields); | ||
} | ||
var errors = validate | ||
.map(function (validator) { return validator(value, fields); }) | ||
.filter(function (input) { return input != null; }); | ||
const errors = validate | ||
.map(validator => validator(value, fields)) | ||
.filter(input => input != null); | ||
if (errors.length === 0) { | ||
@@ -442,11 +296,11 @@ return; | ||
function runAllValidators(state, props) { | ||
var fields = state.fields; | ||
var validators = props.validators; | ||
const { fields } = state; | ||
const { validators } = props; | ||
if (!validators) { | ||
return null; | ||
} | ||
var updatedFields = utilities_1.mapObject(fields, function (field, path) { | ||
return __assign(__assign({}, field), { error: runValidator(validators[path], field.value, fields) }); | ||
const updatedFields = mapObject(fields, (field, path) => { | ||
return Object.assign(Object.assign({}, field), { error: runValidator(validators[path], field.value, fields) }); | ||
}); | ||
return __assign(__assign({}, state), { fields: updatedFields }); | ||
return Object.assign(Object.assign({}, state), { fields: updatedFields }); | ||
} | ||
@@ -458,10 +312,8 @@ function collectErrors(message) { | ||
if (typeof message === 'string') { | ||
return [{ message: message }]; | ||
return [{ message }]; | ||
} | ||
if (Array.isArray(message)) { | ||
return utilities_1.flatMap(message, function (itemError) { return collectErrors(itemError); }); | ||
return flatMap(message, itemError => collectErrors(itemError)); | ||
} | ||
return utilities_1.flatMap(Object.values(message), function (nestedError) { | ||
return collectErrors(nestedError); | ||
}); | ||
return flatMap(Object.values(message), nestedError => collectErrors(nestedError)); | ||
} |
@@ -1,26 +0,9 @@ | ||
"use strict"; | ||
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); | ||
}) : (function(o, m, k, k2) { | ||
if (k2 === undefined) k2 = k; | ||
o[k2] = m[k]; | ||
})); | ||
var __exportStar = (this && this.__exportStar) || function(m, exports) { | ||
for (var p in m) if (p !== "default" && !exports.hasOwnProperty(p)) __createBinding(exports, m, p); | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.arrayUtils = exports.asChoiceField = void 0; | ||
var FormState_1 = __importDefault(require("./FormState")); | ||
var utilities_1 = require("./utilities"); | ||
Object.defineProperty(exports, "asChoiceField", { enumerable: true, get: function () { return utilities_1.asChoiceField; } }); | ||
exports.arrayUtils = { push: utilities_1.push, replace: utilities_1.replace, remove: utilities_1.remove }; | ||
var validators_1 = require("./validators"); | ||
Object.defineProperty(exports, "validators", { enumerable: true, get: function () { return validators_1.default; } }); | ||
__exportStar(require("./validators"), exports); | ||
__exportStar(require("./types"), exports); | ||
__exportStar(require("./FormState"), exports); | ||
exports.default = FormState_1.default; | ||
import FormState from './FormState'; | ||
import { asChoiceField, push, replace, remove, } from './utilities'; | ||
export { asChoiceField }; | ||
export const arrayUtils = { push, replace, remove }; | ||
export { default as validators } from './validators'; | ||
export * from './validators'; | ||
export * from './types'; | ||
export * from './FormState'; | ||
export default FormState; |
@@ -25,2 +25,5 @@ export interface FieldState<Value> { | ||
}; | ||
export interface StringMapper { | ||
(input: string): any; | ||
} | ||
//# sourceMappingURL=types.d.ts.map |
@@ -1,50 +0,5 @@ | ||
"use strict"; | ||
var __assign = (this && this.__assign) || function () { | ||
__assign = Object.assign || function(t) { | ||
for (var s, i = 1, n = arguments.length; i < n; i++) { | ||
s = arguments[i]; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) | ||
t[p] = s[p]; | ||
} | ||
return t; | ||
}; | ||
return __assign.apply(this, arguments); | ||
}; | ||
var __rest = (this && this.__rest) || function (s, e) { | ||
var t = {}; | ||
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0) | ||
t[p] = s[p]; | ||
if (s != null && typeof Object.getOwnPropertySymbols === "function") | ||
for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) { | ||
if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i])) | ||
t[p[i]] = s[p[i]]; | ||
} | ||
return t; | ||
}; | ||
var __read = (this && this.__read) || function (o, n) { | ||
var m = typeof Symbol === "function" && o[Symbol.iterator]; | ||
if (!m) return o; | ||
var i = m.call(o), r, ar = [], e; | ||
try { | ||
while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); | ||
} | ||
catch (error) { e = { error: error }; } | ||
finally { | ||
try { | ||
if (r && !r.done && (m = i["return"])) m.call(i); | ||
} | ||
finally { if (e) throw e.error; } | ||
} | ||
return ar; | ||
}; | ||
var __importDefault = (this && this.__importDefault) || function (mod) { | ||
return (mod && mod.__esModule) ? mod : { "default": mod }; | ||
}; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.asChoiceField = exports.flatMap = exports.set = exports.replace = exports.remove = exports.push = exports.mapObject = exports.isEqual = void 0; | ||
var fast_deep_equal_1 = __importDefault(require("fast-deep-equal")); | ||
exports.isEqual = fast_deep_equal_1.default; | ||
function mapObject(input, mapper) { | ||
return Object.entries(input).reduce(function (accumulator, _a) { | ||
var _b = __read(_a, 2), key = _b[0], value = _b[1]; | ||
import isEqual from 'fast-deep-equal'; | ||
export { isEqual }; | ||
export function mapObject(input, mapper) { | ||
return Object.entries(input).reduce((accumulator, [key, value]) => { | ||
accumulator[key] = mapper(value, key); | ||
@@ -54,17 +9,10 @@ return accumulator; | ||
} | ||
exports.mapObject = mapObject; | ||
function push(array) { | ||
var values = []; | ||
for (var _i = 1; _i < arguments.length; _i++) { | ||
values[_i - 1] = arguments[_i]; | ||
} | ||
export function push(array, ...values) { | ||
return array.concat(values); | ||
} | ||
exports.push = push; | ||
function remove(array, targetIndex) { | ||
return array.filter(function (_, index) { return index !== targetIndex; }); | ||
export function remove(array, targetIndex) { | ||
return array.filter((_, index) => index !== targetIndex); | ||
} | ||
exports.remove = remove; | ||
function replace(array, targetIndex, newValue) { | ||
return array.map(function (value, index) { | ||
export function replace(array, targetIndex, newValue) { | ||
return array.map((value, index) => { | ||
if (index !== targetIndex) { | ||
@@ -76,5 +24,3 @@ return value; | ||
} | ||
exports.replace = replace; | ||
function set(rootObject, path, value) { | ||
var _a, _b; | ||
export function set(rootObject, path, value) { | ||
if (path.length === 0) { | ||
@@ -84,14 +30,12 @@ return rootObject; | ||
else if (path.length === 1) { | ||
return __assign(__assign({}, rootObject), (_a = {}, _a[path[0]] = value, _a)); | ||
return Object.assign(Object.assign({}, rootObject), { [path[0]]: value }); | ||
} | ||
else { | ||
var _c = __read(path), current = _c[0], rest = _c.slice(1); | ||
return __assign(__assign({}, rootObject), (_b = {}, _b[current] = set(rootObject[current] || {}, rest, value), _b)); | ||
const [current, ...rest] = path; | ||
return Object.assign(Object.assign({}, rootObject), { [current]: set(rootObject[current] || {}, rest, value) }); | ||
} | ||
} | ||
exports.set = set; | ||
function flatMap(array, mapper) { | ||
return array.reduce(function (acc, item, index) { return acc.concat(mapper(item, index)); }, []); | ||
export function flatMap(array, mapper) { | ||
return array.reduce((acc, item, index) => acc.concat(mapper(item, index)), []); | ||
} | ||
exports.flatMap = flatMap; | ||
/** | ||
@@ -101,6 +45,5 @@ * Transforms a boolean FieldDescriptor object to work with checkboxes and radios. | ||
*/ | ||
function asChoiceField(_a) { | ||
var checked = _a.value, fieldData = __rest(_a, ["value"]); | ||
return __assign({ checked: checked }, fieldData); | ||
export function asChoiceField(_a) { | ||
var { value: checked } = _a, fieldData = __rest(_a, ["value"]); | ||
return Object.assign({ checked }, fieldData); | ||
} | ||
exports.asChoiceField = asChoiceField; |
@@ -0,7 +1,5 @@ | ||
import { StringMapper } from './types'; | ||
interface Matcher<Input, Fields = any> { | ||
(input: Input, fields: Fields): boolean; | ||
} | ||
interface StringMapper { | ||
(input: string): any; | ||
} | ||
declare type ErrorContent = string | StringMapper; | ||
@@ -8,0 +6,0 @@ export declare function validateNested<Input extends object, Fields>(validatorDictionary: any): (input: Input, fields: Fields) => any; |
@@ -1,10 +0,7 @@ | ||
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.validateRequired = exports.validate = exports.validateWithFields = exports.validateList = exports.validateNested = void 0; | ||
var predicates_1 = require("@shopify/predicates"); | ||
var utilities_1 = require("./utilities"); | ||
function validateNested(validatorDictionary) { | ||
return function (input, fields) { | ||
var errors = utilities_1.mapObject(input, function (value, field) { | ||
var validate = validatorDictionary[field]; | ||
import { lengthLessThan, lengthMoreThan, notEmpty, notEmptyString, isEmpty, notNumericString, isNumericString, isPositiveNumericString, } from '@shopify/predicates'; | ||
import { mapObject } from './utilities'; | ||
export function validateNested(validatorDictionary) { | ||
return (input, fields) => { | ||
const errors = mapObject(input, (value, field) => { | ||
const validate = validatorDictionary[field]; | ||
if (validate == null) { | ||
@@ -19,5 +16,5 @@ return null; | ||
} | ||
var errors = validate | ||
.map(function (validator) { return validator(value, fields); }) | ||
.filter(function (input) { return input != null; }); | ||
const errors = validate | ||
.map(validator => validator(value, fields)) | ||
.filter(input => input != null); | ||
if (errors.length === 0) { | ||
@@ -28,5 +25,5 @@ return; | ||
}); | ||
var anyErrors = Object.keys(errors) | ||
.map(function (key) { return errors[key]; }) | ||
.some(function (value) { return value != null; }); | ||
const anyErrors = Object.keys(errors) | ||
.map(key => errors[key]) | ||
.some(value => value != null); | ||
if (anyErrors) { | ||
@@ -37,8 +34,7 @@ return errors; | ||
} | ||
exports.validateNested = validateNested; | ||
function validateList(validatorDictionary) { | ||
var validateItem = validateNested(validatorDictionary); | ||
return function (input, fields) { | ||
var errors = input.map(function (item) { return validateItem(item, fields); }); | ||
if (errors.some(function (error) { return error != null; })) { | ||
export function validateList(validatorDictionary) { | ||
const validateItem = validateNested(validatorDictionary); | ||
return (input, fields) => { | ||
const errors = input.map(item => validateItem(item, fields)); | ||
if (errors.some(error => error != null)) { | ||
return errors; | ||
@@ -48,10 +44,8 @@ } | ||
} | ||
exports.validateList = validateList; | ||
function validateWithFields(matcher, errorContent) { | ||
export function validateWithFields(matcher, errorContent) { | ||
return validate(matcher, errorContent); | ||
} | ||
exports.validateWithFields = validateWithFields; | ||
function validate(matcher, errorContent) { | ||
return function (input, fields) { | ||
var matches = matcher(input, fields); | ||
export function validate(matcher, errorContent) { | ||
return (input, fields) => { | ||
const matches = matcher(input, fields); | ||
/* | ||
@@ -61,3 +55,3 @@ always mark empty fields valid to match Polaris guidelines | ||
*/ | ||
if (predicates_1.isEmpty(input)) { | ||
if (isEmpty(input)) { | ||
return; | ||
@@ -74,6 +68,5 @@ } | ||
} | ||
exports.validate = validate; | ||
function validateRequired(matcher, errorContent) { | ||
return function (input, fields) { | ||
var matches = matcher(input, fields); | ||
export function validateRequired(matcher, errorContent) { | ||
return (input, fields) => { | ||
const matches = matcher(input, fields); | ||
if (matches) { | ||
@@ -88,24 +81,23 @@ return; | ||
} | ||
exports.validateRequired = validateRequired; | ||
var validators = { | ||
lengthMoreThan: function (length, errorContent) { | ||
return validate(predicates_1.lengthMoreThan(length), errorContent); | ||
const validators = { | ||
lengthMoreThan(length, errorContent) { | ||
return validate(lengthMoreThan(length), errorContent); | ||
}, | ||
lengthLessThan: function (length, errorContent) { | ||
return validate(predicates_1.lengthLessThan(length), errorContent); | ||
lengthLessThan(length, errorContent) { | ||
return validate(lengthLessThan(length), errorContent); | ||
}, | ||
numericString: function (errorContent) { | ||
return validate(predicates_1.isNumericString, errorContent); | ||
numericString(errorContent) { | ||
return validate(isNumericString, errorContent); | ||
}, | ||
positiveNumericString: function (errorContent) { | ||
return validate(predicates_1.isPositiveNumericString, errorContent); | ||
positiveNumericString(errorContent) { | ||
return validate(isPositiveNumericString, errorContent); | ||
}, | ||
nonNumericString: function (errorContent) { | ||
return validate(predicates_1.notNumericString, errorContent); | ||
nonNumericString(errorContent) { | ||
return validate(notNumericString, errorContent); | ||
}, | ||
requiredString: function (errorContent) { | ||
return validateRequired(predicates_1.notEmptyString, errorContent); | ||
requiredString(errorContent) { | ||
return validateRequired(notEmptyString, errorContent); | ||
}, | ||
required: function (errorContent) { | ||
return validateRequired(predicates_1.notEmpty, errorContent); | ||
required(errorContent) { | ||
return validateRequired(notEmpty, errorContent); | ||
}, | ||
@@ -119,2 +111,2 @@ }; | ||
} | ||
exports.default = validators; | ||
export default validators; |
@@ -8,13 +8,50 @@ # Changelog | ||
<!-- ## [Unreleased] --> | ||
<!-- ## Unreleased --> | ||
- Added new types of builds (CommonJS, ESM, esnext, Node) for greater tree-shakability | ||
## 1.0.0 - 2021-05-21 | ||
## [0.11.11] - 2019-10-01 | ||
### Breaking Change | ||
- Update minimum supported node version to 12.14.0. Add engines field to help enforce usage of this version. [#1906](https://github.com/Shopify/quilt/pull/1906) | ||
## 0.12.5 - 2021-04-22 | ||
- [Patch] Remove TypeScript type from distributed mjs [#1845](https://github.com/Shopify/quilt/pull/1845) | ||
## 0.12.4 - 2021-04-13 | ||
### Changed | ||
- Removed dependency on tslib, as we no-longer compile with `tsc`. [#1829](https://github.com/Shopify/quilt/pull/1829) | ||
## 0.12.2 - 2021-03-03 | ||
### Fixed | ||
- Updated multi-build outputs to include mandatory extensions to fix "Module not found" issues reported by ESM supported bundlers [#1759](https://github.com/Shopify/quilt/pull/1759) | ||
## 0.12.0 - 2020-12-18 | ||
### Added | ||
- Add new build outputs (CommonJS, ESM, esnext, Node) for greater tree-shakability [#1698](https://github.com/Shopify/quilt/pull/1698) | ||
- Updated `fast-deep-equal` dependency to `^3.1.3` [#1710](https://github.com/Shopify/quilt/pull/1710) | ||
## 0.11.28 - 2020-10-23 | ||
### Fixed | ||
- Export `StringMapper` interface [#1655](https://github.com/Shopify/quilt/pull/1655) | ||
## 0.11.27 - 2020-10-20 | ||
- Updated `tslib` dependency to `^1.14.1`. [#1657](https://github.com/Shopify/quilt/pull/1657) | ||
## 0.11.11 - 2019-10-01 | ||
### Added | ||
- new `asChoiceField` utility function to support `Checkbox` and `RadioButton` [#1070](https://github.com/Shopify/quilt/pull/1070) | ||
## [0.11.8] - 2019-08-29 | ||
## 0.11.8 - 2019-08-29 | ||
@@ -25,3 +62,3 @@ ### Fixed | ||
## [0.11.3] | ||
## 0.11.3 | ||
@@ -32,3 +69,3 @@ ### Added | ||
## [0.11.2] - 2019-05-22 | ||
## 0.11.2 - 2019-05-22 | ||
@@ -39,3 +76,3 @@ ### Fixed | ||
## [0.11.1] - 2019-05-15 | ||
## 0.11.1 - 2019-05-15 | ||
@@ -46,3 +83,3 @@ ### Fixed | ||
## [0.10.0] | ||
## 0.10.0 | ||
@@ -53,3 +90,3 @@ ### Changed | ||
## [0.9.1] | ||
## 0.9.1 | ||
@@ -60,3 +97,3 @@ ### Changed | ||
## [0.9.0] | ||
## 0.9.0 | ||
@@ -67,3 +104,3 @@ ### Removed | ||
## [0.8.0] | ||
## 0.8.0 | ||
@@ -82,3 +119,3 @@ ### Added | ||
## [0.7.0] | ||
## 0.7.0 | ||
@@ -93,3 +130,3 @@ ### Added | ||
## [0.6.0] | ||
## 0.6.0 | ||
@@ -100,3 +137,3 @@ ### Added | ||
## [0.5.0] | ||
## 0.5.0 | ||
@@ -107,3 +144,3 @@ ### Added | ||
## [0.4.1] | ||
## 0.4.1 | ||
@@ -114,3 +151,3 @@ ### Fixed | ||
## [0.4.0] | ||
## 0.4.0 | ||
@@ -121,3 +158,3 @@ ### Added | ||
## [0.3.3] | ||
## 0.3.3 | ||
@@ -128,3 +165,3 @@ ### Fixed | ||
## [0.3.2] | ||
## 0.3.2 | ||
@@ -135,3 +172,3 @@ ### Fixed | ||
## [0.3.0] | ||
## 0.3.0 | ||
@@ -142,3 +179,3 @@ ### Added | ||
## [0.2.10] | ||
## 0.2.10 | ||
@@ -149,3 +186,3 @@ ### Fixed | ||
## [0.2.9] | ||
## 0.2.9 | ||
@@ -156,3 +193,3 @@ ### Fixed | ||
## [0.2.8] | ||
## 0.2.8 | ||
@@ -159,0 +196,0 @@ ### Changed |
@@ -1,1 +0,1 @@ | ||
module.exports = require("./build/cjs/index"); | ||
module.exports = require("./build/cjs/index.js"); |
{ | ||
"name": "@shopify/react-form-state", | ||
"version": "1.0.0-sknext-beta.2", | ||
"version": "1.0.0", | ||
"license": "MIT", | ||
@@ -8,5 +8,2 @@ "description": "Manage React forms tersely and type-safely with no magic", | ||
"types": "index.d.ts", | ||
"scripts": { | ||
"build": "tsc --p tsconfig.json" | ||
}, | ||
"publishConfig": { | ||
@@ -25,6 +22,9 @@ "access": "public", | ||
}, | ||
"homepage": "https://github.com/Shopify/quilt/blob/master/packages/react-form-state/README.md", | ||
"homepage": "https://github.com/Shopify/quilt/blob/main/packages/react-form-state/README.md", | ||
"engines": { | ||
"node": ">=12.14.0" | ||
}, | ||
"dependencies": { | ||
"@shopify/predicates": "1.0.0-sknext-beta.2", | ||
"fast-deep-equal": "^2.0.1" | ||
"@shopify/predicates": "^2.0.0", | ||
"fast-deep-equal": "^3.1.3" | ||
}, | ||
@@ -35,4 +35,4 @@ "peerDependencies": { | ||
"devDependencies": { | ||
"@shopify/enzyme-utilities": "1.0.0-sknext-beta.2", | ||
"@shopify/useful-types": "1.0.0-sknext-beta.2", | ||
"@shopify/enzyme-utilities": "^3.0.0", | ||
"@shopify/useful-types": "^3.0.0", | ||
"faker": "^4.1.0" | ||
@@ -43,3 +43,3 @@ }, | ||
"build/*", | ||
"!tsconfig.tsbuildinfo", | ||
"!*.tsbuildinfo", | ||
"index.js", | ||
@@ -59,3 +59,4 @@ "index.mjs", | ||
} | ||
} | ||
}, | ||
"gitHead": "40de4af181104f298cbab42d2d3d68e228a9a31a" | ||
} |
# `@shopify/react-form-state` | ||
[![Build Status](https://travis-ci.org/Shopify/quilt.svg?branch=master)](https://travis-ci.org/Shopify/quilt) | ||
[![Build Status](https://github.com/Shopify/quilt/workflows/Node-CI/badge.svg?branch=main)](https://github.com/Shopify/quilt/actions?query=workflow%3ANode-CI) | ||
[![Build Status](https://github.com/Shopify/quilt/workflows/Ruby-CI/badge.svg?branch=main)](https://github.com/Shopify/quilt/actions?query=workflow%3ARuby-CI) | ||
[![License: MIT](https://img.shields.io/badge/License-MIT-green.svg)](LICENSE.md) [![npm version](https://badge.fury.io/js/%40shopify%2Freact-form-state.svg)](https://badge.fury.io/js/%40shopify%2Freact-form-state.svg) [![npm bundle size (minified + gzip)](https://img.shields.io/bundlephobia/minzip/@shopify/react-form-state.svg)](https://img.shields.io/bundlephobia/minzip/@shopify/react-form-state.svg) | ||
@@ -8,3 +9,3 @@ | ||
This library is now superseded by [@shopify/react-form](https://github.com/Shopify/quilt/tree/master/packages/react-form) as it allows you to write the preferred, functional, and hooks-driven React components over class-based ones. | ||
This library is now superseded by [@shopify/react-form](https://github.com/Shopify/quilt/tree/main/packages/react-form) as it allows you to write the preferred, functional, and hooks-driven React components over class-based ones. | ||
@@ -48,3 +49,3 @@ ## Installation | ||
For detailed explanations of how to use `<FormState />` check out [the guide](https://github.com/Shopify/quilt/tree/master/packages/react-form-state/docs/building-forms.md). | ||
For detailed explanations of how to use `<FormState />` check out [the guide](https://github.com/Shopify/quilt/tree/main/packages/react-form-state/docs/building-forms.md). | ||
@@ -59,2 +60,2 @@ ### `validators` | ||
For detailed explanations of the validation utilities, check out [the validation docs](https://github.com/Shopify/quilt/tree/master/packages/react-form-state/docs/validators.md). | ||
For detailed explanations of the validation utilities, check out [the validation docs](https://github.com/Shopify/quilt/tree/main/packages/react-form-state/docs/validators.md). |
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
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
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
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
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
No v1
QualityPackage is not semver >=1. This means it is not stable and does not support ^ ranges.
Found 1 instance in 1 package
0
59
112500
52
2388
1
+ Added@shopify/predicates@2.0.8(transitive)
+ Addedfast-deep-equal@3.1.3(transitive)
- Removed@shopify/predicates@1.0.0-sknext-beta.2(transitive)
- Removedfast-deep-equal@2.0.1(transitive)
Updated@shopify/predicates@^2.0.0
Updatedfast-deep-equal@^3.1.3