Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

easy-react-form

Package Overview
Dependencies
Maintainers
1
Versions
56
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

easy-react-form - npm Package Compare versions

Comparing version 1.0.18 to 1.0.19

12

commonjs/actions.js

@@ -79,2 +79,14 @@ "use strict";

};
var removeField = exports.removeField = function removeField(field) {
return function (state) {
delete state.fields[field];
delete state.values[field];
delete state.errors[field];
delete state.showErrors[field];
if (state.latestFocusedField === field) {
state.latestFocusedField = undefined;
}
};
};
//# sourceMappingURL=actions.js.map

18

commonjs/field.js

@@ -217,4 +217,4 @@ 'use strict';

context.onRegisterField(this.getName(), this.validate, this.scroll, this.focus);
context.dispatch((0, _actions.registerField)(this.getName(), value === undefined ? context.getInitialValue(this.getName()) : value, this.validate));
var initialValue = value === undefined ? context.getInitialValue(this.getName()) : value;
context.onRegisterField(this.getName(), initialValue, this.validate, this.scroll, this.focus);

@@ -226,2 +226,9 @@ if (listContext) {

}, {
key: 'unregister',
value: function unregister(prevProps) {
var context = this.props.context;
context.onUnregisterField(this.getName(prevProps));
}
}, {
key: 'componentDidMount',

@@ -234,6 +241,4 @@ value: function componentDidMount() {

value: function componentWillUnmount() {
var context = this.props.context;
// "Unregister" field.
context.dispatch((0, _actions.unregisterField)(this.getName()));
this.unregister();
this.mounted = false;

@@ -254,3 +259,3 @@ }

// Unregister old field.
context.dispatch((0, _actions.unregisterField)(this.getName(prevProps)));
this.unregister(prevProps);
// Register new field.

@@ -264,2 +269,3 @@ this.register();

// then apply this new default value.
// A default value isn't supposed to generate an error.
if (value !== prevProps.value && !this.hasBeenEdited) {

@@ -266,0 +272,0 @@ context.dispatch((0, _actions.setFieldValue)(this.getName(), value));

@@ -40,2 +40,4 @@ 'use strict';

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

@@ -69,6 +71,9 @@

onRegisterField: _this.onRegisterField,
onUnregisterField: _this.onUnregisterField,
getRequiredMessage: function getRequiredMessage() {
return requiredMessage;
},
// Is used by `<List/>`.
// These're used by `<List/>` (plus `.fields`).
resetField: _this.resetField,
cleanUpRemovedFields: _this.cleanUpRemovedFields,
focus: _this.focus,

@@ -133,2 +138,7 @@ getValues: _this.values,

}, {
key: 'componentDidUpdate',
value: function componentDidUpdate() {
this.cleanUpRemovedFields();
}
}, {
key: 'componentWillUnmount',

@@ -167,2 +177,5 @@ value: function componentWillUnmount() {

// Not tested.
// Is called when the form has been submitted.

@@ -452,3 +465,3 @@

this.onRegisterField = function (field, validate, scroll, focus) {
this.onRegisterField = function (field, initialValue, validate, scroll, focus) {
// The stored field info is used to `validate()` field `value`s

@@ -463,2 +476,3 @@ // and set the corresponding `error`s

_this4.fields[field] = {
initialValue: initialValue,
validate: validate,

@@ -471,4 +485,12 @@ scroll: scroll,

}
_this4.dispatch((0, _actions.registerField)(field, initialValue, validate));
};
this.onUnregisterField = function (field) {
_this4.dispatch((0, _actions.unregisterField)(field));
// Rerender the form so that the field is
// removed if it's no longer mounted.
_this4.setState.apply(_this4, _toConsumableArray(_this4.state));
};
this.dispatch = function (action, callback) {

@@ -572,3 +594,3 @@ action(_this4.state);

_this4.setState(_extends({
resetCounter: resetCounter + 1
resetCounter: (0, _utility.getNext)(resetCounter)
}, generateInitialFormState(initialValues), {

@@ -587,6 +609,18 @@ // Form `children` will be unmounted before the new ones are mounted.

this.onAfterSubmit = function () {
var onAfterSubmit = _this4.props.onAfterSubmit;
this.resetField = function (name) {
var initialValue = _this4.fields[name].initialValue === undefined ? _this4.getInitialValue(name) : _this4.fields[name].initialValue;
_this4.dispatch((0, _actions.setFieldValue)(name, initialValue));
// A default value isn't supposed to generate an error.
_this4.dispatch((0, _actions.setFieldError)(name, undefined));
};
for (var _iterator8 = _this4.plugins, _isArray8 = Array.isArray(_iterator8), _i8 = 0, _iterator8 = _isArray8 ? _iterator8 : _iterator8[Symbol.iterator]();;) {
this.removeField = function (field) {
_this4.dispatch((0, _actions.removeField)(field));
delete _this4.fields[field];
};
this.cleanUpRemovedFields = function () {
var fields = _this4.state.fields;
for (var _iterator8 = Object.keys(fields), _isArray8 = Array.isArray(_iterator8), _i8 = 0, _iterator8 = _isArray8 ? _iterator8 : _iterator8[Symbol.iterator]();;) {
var _ref8;

@@ -603,4 +637,28 @@

var plugin = _ref8;
var field = _ref8;
// Remove unmounted `<Field/>`s.
if (fields[field] === 0) {
_this4.removeField(field);
}
}
};
this.onAfterSubmit = function () {
var onAfterSubmit = _this4.props.onAfterSubmit;
for (var _iterator9 = _this4.plugins, _isArray9 = Array.isArray(_iterator9), _i9 = 0, _iterator9 = _isArray9 ? _iterator9 : _iterator9[Symbol.iterator]();;) {
var _ref9;
if (_isArray9) {
if (_i9 >= _iterator9.length) break;
_ref9 = _iterator9[_i9++];
} else {
_i9 = _iterator9.next();
if (_i9.done) break;
_ref9 = _i9.value;
}
var plugin = _ref9;
if (plugin.onAfterSubmit) {

@@ -756,2 +814,3 @@ plugin.onAfterSubmit();

onRegisterField: _propTypes2.default.func.isRequired,
onUnregisterField: _propTypes2.default.func.isRequired,
focus: _propTypes2.default.isRequired,

@@ -758,0 +817,0 @@ dispatch: _propTypes2.default.func.isRequired,

@@ -10,4 +10,2 @@ 'use strict';

var _class, _temp, _initialiseProps;
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

@@ -51,3 +49,3 @@

var List = (_temp = _class = function (_React$Component) {
var List = function (_React$Component) {
_inherits(List, _React$Component);

@@ -60,15 +58,83 @@

_initialiseProps.call(_this);
_this.getFieldName = function (i, name) {
if (typeof i !== 'number') {
throw new Error('Each `<Feild/>` in a `<List/>` must have an `i` property');
}
return (0, _ListPlugin.getFieldName)(_this.props.name, i, name);
};
var name = _this.props.name;
_this.onRegisterField = function (name) {
if (!_this.firstFieldName) {
_this.firstFieldName = name;
}
};
var items = _this.getInitialItems();
_this.state = {
_this.add = function () {
var context = _this.props.context;
var _this$state = _this.state,
items = _this$state.items,
itemsCounter = _this$state.itemsCounter;
_this.setState({
itemsCounter: itemsCounter + 1,
items: items.concat([itemsCounter])
}, function () {
var name = _this.props.name;
if (_this.firstFieldName) {
context.focus(name + ':' + itemsCounter + ':' + _this.firstFieldName);
}
});
};
_this.remove = function (i) {
var items = _this.state.items;
_this.setState({
items: items.filter(function (_) {
return _ !== i;
})
});
};
_this.map = function (func) {
var items = _this.state.items;
return items.map(function (i) {
return func(i);
});
};
_this.reset = function () {
var _this$props = _this.props,
name = _this$props.name,
context = _this$props.context;
for (var _iterator = Object.keys(context.fields), _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var field = _ref;
if (field.indexOf(name + ':') === 0) {
context.resetField(field);
}
}
_this.setState(_this.getInitialItemsState(), context.cleanUpRemovedFields);
};
_this.state = _extends({
context: {
getFieldName: _this.getFieldName,
onRegisterField: _this.onRegisterField
},
items: items,
itemsCounter: items.length
};
}
}, _this.getInitialItemsState());
return _this;

@@ -91,2 +157,14 @@ }

}, {
key: 'getInitialItemsState',
value: function getInitialItemsState() {
var items = this.getInitialItems();
return {
items: items,
itemsCounter: items.length
};
}
// Hasn't been tested.
}, {
key: 'render',

@@ -118,56 +196,4 @@ value: function render() {

return List;
}(_react2.default.Component), _initialiseProps = function _initialiseProps() {
var _this3 = this;
}(_react2.default.Component);
this.getFieldName = function (i, name) {
if (typeof i !== 'number') {
throw new Error('Each `<Feild/>` in a `<List/>` must have an `i` property');
}
return (0, _ListPlugin.getFieldName)(_this3.props.name, i, name);
};
this.onRegisterField = function (name) {
if (!_this3.firstFieldName) {
_this3.firstFieldName = name;
}
};
this.add = function () {
var context = _this3.props.context;
var _state = _this3.state,
items = _state.items,
itemsCounter = _state.itemsCounter;
_this3.setState({
itemsCounter: itemsCounter + 1,
items: items.concat([itemsCounter])
}, function () {
var name = _this3.props.name;
if (_this3.firstFieldName) {
context.focus(name + ':' + itemsCounter + ':' + _this3.firstFieldName);
}
});
};
this.remove = function (i) {
var items = _this3.state.items;
_this3.setState({
items: items.filter(function (_) {
return _ !== i;
})
});
};
this.map = function (func) {
var items = _this3.state.items;
return items.map(function (i) {
return func(i);
});
};
}, _temp);
List.propTypes = {

@@ -174,0 +200,0 @@ name: _propTypes2.default.string.isRequired,

@@ -11,2 +11,3 @@ 'use strict';

exports.getValue = getValue;
exports.getNext = getNext;

@@ -83,2 +84,12 @@ var _scrollIntoViewIfNeeded = require('scroll-into-view-if-needed');

}
// `MAX_SAFE_INTEGER` is not supported by older browsers
var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || Math.pow(2, 53);
function getNext(counter) {
if (counter < MAX_SAFE_INTEGER) {
return counter + 1;
} else {
return 0;
}
}
//# sourceMappingURL=utility.js.map

@@ -79,2 +79,14 @@ "use strict";

};
var removeField = exports.removeField = function removeField(field) {
return function (state) {
delete state.fields[field];
delete state.values[field];
delete state.errors[field];
delete state.showErrors[field];
if (state.latestFocusedField === field) {
state.latestFocusedField = undefined;
}
};
};
//# sourceMappingURL=actions.js.map

@@ -217,4 +217,4 @@ 'use strict';

context.onRegisterField(this.getName(), this.validate, this.scroll, this.focus);
context.dispatch((0, _actions.registerField)(this.getName(), value === undefined ? context.getInitialValue(this.getName()) : value, this.validate));
var initialValue = value === undefined ? context.getInitialValue(this.getName()) : value;
context.onRegisterField(this.getName(), initialValue, this.validate, this.scroll, this.focus);

@@ -226,2 +226,9 @@ if (listContext) {

}, {
key: 'unregister',
value: function unregister(prevProps) {
var context = this.props.context;
context.onUnregisterField(this.getName(prevProps));
}
}, {
key: 'componentDidMount',

@@ -234,6 +241,4 @@ value: function componentDidMount() {

value: function componentWillUnmount() {
var context = this.props.context;
// "Unregister" field.
context.dispatch((0, _actions.unregisterField)(this.getName()));
this.unregister();
this.mounted = false;

@@ -254,3 +259,3 @@ }

// Unregister old field.
context.dispatch((0, _actions.unregisterField)(this.getName(prevProps)));
this.unregister(prevProps);
// Register new field.

@@ -264,2 +269,3 @@ this.register();

// then apply this new default value.
// A default value isn't supposed to generate an error.
if (value !== prevProps.value && !this.hasBeenEdited) {

@@ -266,0 +272,0 @@ context.dispatch((0, _actions.setFieldValue)(this.getName(), value));

@@ -40,2 +40,4 @@ 'use strict';

function _toConsumableArray(arr) { if (Array.isArray(arr)) { for (var i = 0, arr2 = Array(arr.length); i < arr.length; i++) { arr2[i] = arr[i]; } return arr2; } else { return Array.from(arr); } }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }

@@ -69,6 +71,9 @@

onRegisterField: _this.onRegisterField,
onUnregisterField: _this.onUnregisterField,
getRequiredMessage: function getRequiredMessage() {
return requiredMessage;
},
// Is used by `<List/>`.
// These're used by `<List/>` (plus `.fields`).
resetField: _this.resetField,
cleanUpRemovedFields: _this.cleanUpRemovedFields,
focus: _this.focus,

@@ -133,2 +138,7 @@ getValues: _this.values,

}, {
key: 'componentDidUpdate',
value: function componentDidUpdate() {
this.cleanUpRemovedFields();
}
}, {
key: 'componentWillUnmount',

@@ -167,2 +177,5 @@ value: function componentWillUnmount() {

// Not tested.
// Is called when the form has been submitted.

@@ -452,3 +465,3 @@

this.onRegisterField = function (field, validate, scroll, focus) {
this.onRegisterField = function (field, initialValue, validate, scroll, focus) {
// The stored field info is used to `validate()` field `value`s

@@ -463,2 +476,3 @@ // and set the corresponding `error`s

_this4.fields[field] = {
initialValue: initialValue,
validate: validate,

@@ -471,4 +485,12 @@ scroll: scroll,

}
_this4.dispatch((0, _actions.registerField)(field, initialValue, validate));
};
this.onUnregisterField = function (field) {
_this4.dispatch((0, _actions.unregisterField)(field));
// Rerender the form so that the field is
// removed if it's no longer mounted.
_this4.setState.apply(_this4, _toConsumableArray(_this4.state));
};
this.dispatch = function (action, callback) {

@@ -572,3 +594,3 @@ action(_this4.state);

_this4.setState(_extends({
resetCounter: resetCounter + 1
resetCounter: (0, _utility.getNext)(resetCounter)
}, generateInitialFormState(initialValues), {

@@ -587,6 +609,18 @@ // Form `children` will be unmounted before the new ones are mounted.

this.onAfterSubmit = function () {
var onAfterSubmit = _this4.props.onAfterSubmit;
this.resetField = function (name) {
var initialValue = _this4.fields[name].initialValue === undefined ? _this4.getInitialValue(name) : _this4.fields[name].initialValue;
_this4.dispatch((0, _actions.setFieldValue)(name, initialValue));
// A default value isn't supposed to generate an error.
_this4.dispatch((0, _actions.setFieldError)(name, undefined));
};
for (var _iterator8 = _this4.plugins, _isArray8 = Array.isArray(_iterator8), _i8 = 0, _iterator8 = _isArray8 ? _iterator8 : _iterator8[Symbol.iterator]();;) {
this.removeField = function (field) {
_this4.dispatch((0, _actions.removeField)(field));
delete _this4.fields[field];
};
this.cleanUpRemovedFields = function () {
var fields = _this4.state.fields;
for (var _iterator8 = Object.keys(fields), _isArray8 = Array.isArray(_iterator8), _i8 = 0, _iterator8 = _isArray8 ? _iterator8 : _iterator8[Symbol.iterator]();;) {
var _ref8;

@@ -603,4 +637,28 @@

var plugin = _ref8;
var field = _ref8;
// Remove unmounted `<Field/>`s.
if (fields[field] === 0) {
_this4.removeField(field);
}
}
};
this.onAfterSubmit = function () {
var onAfterSubmit = _this4.props.onAfterSubmit;
for (var _iterator9 = _this4.plugins, _isArray9 = Array.isArray(_iterator9), _i9 = 0, _iterator9 = _isArray9 ? _iterator9 : _iterator9[Symbol.iterator]();;) {
var _ref9;
if (_isArray9) {
if (_i9 >= _iterator9.length) break;
_ref9 = _iterator9[_i9++];
} else {
_i9 = _iterator9.next();
if (_i9.done) break;
_ref9 = _i9.value;
}
var plugin = _ref9;
if (plugin.onAfterSubmit) {

@@ -756,2 +814,3 @@ plugin.onAfterSubmit();

onRegisterField: _propTypes2.default.func.isRequired,
onUnregisterField: _propTypes2.default.func.isRequired,
focus: _propTypes2.default.isRequired,

@@ -758,0 +817,0 @@ dispatch: _propTypes2.default.func.isRequired,

@@ -10,4 +10,2 @@ 'use strict';

var _class, _temp, _initialiseProps;
var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; };

@@ -51,3 +49,3 @@

var List = (_temp = _class = function (_React$Component) {
var List = function (_React$Component) {
_inherits(List, _React$Component);

@@ -60,15 +58,83 @@

_initialiseProps.call(_this);
_this.getFieldName = function (i, name) {
if (typeof i !== 'number') {
throw new Error('Each `<Feild/>` in a `<List/>` must have an `i` property');
}
return (0, _ListPlugin.getFieldName)(_this.props.name, i, name);
};
var name = _this.props.name;
_this.onRegisterField = function (name) {
if (!_this.firstFieldName) {
_this.firstFieldName = name;
}
};
var items = _this.getInitialItems();
_this.state = {
_this.add = function () {
var context = _this.props.context;
var _this$state = _this.state,
items = _this$state.items,
itemsCounter = _this$state.itemsCounter;
_this.setState({
itemsCounter: itemsCounter + 1,
items: items.concat([itemsCounter])
}, function () {
var name = _this.props.name;
if (_this.firstFieldName) {
context.focus(name + ':' + itemsCounter + ':' + _this.firstFieldName);
}
});
};
_this.remove = function (i) {
var items = _this.state.items;
_this.setState({
items: items.filter(function (_) {
return _ !== i;
})
});
};
_this.map = function (func) {
var items = _this.state.items;
return items.map(function (i) {
return func(i);
});
};
_this.reset = function () {
var _this$props = _this.props,
name = _this$props.name,
context = _this$props.context;
for (var _iterator = Object.keys(context.fields), _isArray = Array.isArray(_iterator), _i = 0, _iterator = _isArray ? _iterator : _iterator[Symbol.iterator]();;) {
var _ref;
if (_isArray) {
if (_i >= _iterator.length) break;
_ref = _iterator[_i++];
} else {
_i = _iterator.next();
if (_i.done) break;
_ref = _i.value;
}
var field = _ref;
if (field.indexOf(name + ':') === 0) {
context.resetField(field);
}
}
_this.setState(_this.getInitialItemsState(), context.cleanUpRemovedFields);
};
_this.state = _extends({
context: {
getFieldName: _this.getFieldName,
onRegisterField: _this.onRegisterField
},
items: items,
itemsCounter: items.length
};
}
}, _this.getInitialItemsState());
return _this;

@@ -91,2 +157,14 @@ }

}, {
key: 'getInitialItemsState',
value: function getInitialItemsState() {
var items = this.getInitialItems();
return {
items: items,
itemsCounter: items.length
};
}
// Hasn't been tested.
}, {
key: 'render',

@@ -118,56 +196,4 @@ value: function render() {

return List;
}(_react2.default.Component), _initialiseProps = function _initialiseProps() {
var _this3 = this;
}(_react2.default.Component);
this.getFieldName = function (i, name) {
if (typeof i !== 'number') {
throw new Error('Each `<Feild/>` in a `<List/>` must have an `i` property');
}
return (0, _ListPlugin.getFieldName)(_this3.props.name, i, name);
};
this.onRegisterField = function (name) {
if (!_this3.firstFieldName) {
_this3.firstFieldName = name;
}
};
this.add = function () {
var context = _this3.props.context;
var _state = _this3.state,
items = _state.items,
itemsCounter = _state.itemsCounter;
_this3.setState({
itemsCounter: itemsCounter + 1,
items: items.concat([itemsCounter])
}, function () {
var name = _this3.props.name;
if (_this3.firstFieldName) {
context.focus(name + ':' + itemsCounter + ':' + _this3.firstFieldName);
}
});
};
this.remove = function (i) {
var items = _this3.state.items;
_this3.setState({
items: items.filter(function (_) {
return _ !== i;
})
});
};
this.map = function (func) {
var items = _this3.state.items;
return items.map(function (i) {
return func(i);
});
};
}, _temp);
List.propTypes = {

@@ -174,0 +200,0 @@ name: _propTypes2.default.string.isRequired,

@@ -11,2 +11,3 @@ 'use strict';

exports.getValue = getValue;
exports.getNext = getNext;

@@ -83,2 +84,12 @@ var _scrollIntoViewIfNeeded = require('scroll-into-view-if-needed');

}
// `MAX_SAFE_INTEGER` is not supported by older browsers
var MAX_SAFE_INTEGER = Number.MAX_SAFE_INTEGER || Math.pow(2, 53);
function getNext(counter) {
if (counter < MAX_SAFE_INTEGER) {
return counter + 1;
} else {
return 0;
}
}
//# sourceMappingURL=utility.js.map
{
"name": "easy-react-form",
"version": "1.0.18",
"version": "1.0.19",
"description": "Simple, fast and easy-to-use React Form.",

@@ -5,0 +5,0 @@ "main": "index.commonjs.js",

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc