react-mui-form-validator 1.0.6 → 1.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,214 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports["default"] = exports.FormContext = void 0;
7
- var _react = _interopRequireDefault(require("react"));
8
- var _propTypes = _interopRequireDefault(require("prop-types"));
9
- var _promisePolyfill = _interopRequireDefault(require("promise-polyfill"));
10
- var _index = _interopRequireDefault(require("../context/index"));
11
- var _ValidationRules = _interopRequireDefault(require("./ValidationRules"));
12
- var _excluded = ["onSubmit", "instantValidate", "onError", "debounceTime", "children"];
13
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
14
- function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
15
- function _extends() { _extends = Object.assign ? Object.assign.bind() : 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; }; return _extends.apply(this, arguments); }
16
- 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; }
17
- 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; }
18
- function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
19
- 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, _toPropertyKey(descriptor.key), descriptor); } }
20
- function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
21
- 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 } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
22
- function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
23
- 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); }; }
24
- function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
25
- function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
26
- function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
27
- function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
28
- function _defineProperty(obj, key, value) { key = _toPropertyKey(key); if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
29
- function _toPropertyKey(arg) { var key = _toPrimitive(arg, "string"); return _typeof(key) === "symbol" ? key : String(key); }
30
- function _toPrimitive(input, hint) { if (_typeof(input) !== "object" || input === null) return input; var prim = input[Symbol.toPrimitive]; if (prim !== undefined) { var res = prim.call(input, hint || "default"); if (_typeof(res) !== "object") return res; throw new TypeError("@@toPrimitive must return a primitive value."); } return (hint === "string" ? String : Number)(input); } /* eslint-disable */ /* eslint-enable */
31
- var FormContext = (0, _index["default"])("form");
32
- exports.FormContext = FormContext;
33
- var ValidatorForm = /*#__PURE__*/function (_React$Component) {
34
- _inherits(ValidatorForm, _React$Component);
35
- var _super = _createSuper(ValidatorForm);
36
- function ValidatorForm() {
37
- var _this;
38
- _classCallCheck(this, ValidatorForm);
39
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
40
- args[_key] = arguments[_key];
41
- }
42
- _this = _super.call.apply(_super, [this].concat(args));
43
- _defineProperty(_assertThisInitialized(_this), "getFormHelpers", function () {
44
- return {
45
- form: {
46
- attachToForm: _this.attachToForm,
47
- detachFromForm: _this.detachFromForm,
48
- instantValidate: _this.instantValidate,
49
- debounceTime: _this.debounceTime
50
- }
51
- };
52
- });
53
- _defineProperty(_assertThisInitialized(_this), "instantValidate", _this.props.instantValidate !== undefined ? _this.props.instantValidate : true);
54
- _defineProperty(_assertThisInitialized(_this), "debounceTime", _this.props.debounceTime);
55
- _defineProperty(_assertThisInitialized(_this), "childs", []);
56
- _defineProperty(_assertThisInitialized(_this), "errors", []);
57
- _defineProperty(_assertThisInitialized(_this), "attachToForm", function (component) {
58
- if (_this.childs.indexOf(component) === -1) {
59
- _this.childs.push(component);
60
- }
61
- });
62
- _defineProperty(_assertThisInitialized(_this), "detachFromForm", function (component) {
63
- var componentPos = _this.childs.indexOf(component);
64
- if (componentPos !== -1) {
65
- _this.childs = _this.childs.slice(0, componentPos).concat(_this.childs.slice(componentPos + 1));
66
- }
67
- });
68
- _defineProperty(_assertThisInitialized(_this), "submit", function (event) {
69
- if (event) {
70
- event.preventDefault();
71
- event.persist();
72
- }
73
- _this.errors = [];
74
- _this.walk(_this.childs).then(function (result) {
75
- if (_this.errors.length) {
76
- _this.props.onError(_this.errors);
77
- }
78
- if (result) {
79
- _this.props.onSubmit(event);
80
- }
81
- return result;
82
- });
83
- });
84
- _defineProperty(_assertThisInitialized(_this), "walk", function (children, dryRun) {
85
- var self = _assertThisInitialized(_this);
86
- return new _promisePolyfill["default"](function (resolve) {
87
- var result = true;
88
- if (Array.isArray(children)) {
89
- _promisePolyfill["default"].all(children.map(function (input) {
90
- return self.checkInput(input, dryRun);
91
- })).then(function (data) {
92
- data.forEach(function (item) {
93
- if (!item) {
94
- result = false;
95
- }
96
- });
97
- resolve(result);
98
- });
99
- } else {
100
- self.walk([children], dryRun).then(function (result) {
101
- return resolve(result);
102
- });
103
- }
104
- });
105
- });
106
- _defineProperty(_assertThisInitialized(_this), "checkInput", function (input, dryRun) {
107
- return new _promisePolyfill["default"](function (resolve) {
108
- var result = true;
109
- var validators = input.props.validators;
110
- if (validators) {
111
- _this.validate(input, true, dryRun).then(function (data) {
112
- if (!data) {
113
- result = false;
114
- }
115
- resolve(result);
116
- });
117
- } else {
118
- resolve(result);
119
- }
120
- });
121
- });
122
- _defineProperty(_assertThisInitialized(_this), "validate", function (input, includeRequired, dryRun) {
123
- return new _promisePolyfill["default"](function (resolve) {
124
- var value = input.props.value;
125
- input.validate(value, includeRequired, dryRun).then(function (valid) {
126
- if (!valid) {
127
- _this.errors.push(input);
128
- }
129
- resolve(valid);
130
- });
131
- });
132
- });
133
- _defineProperty(_assertThisInitialized(_this), "find", function (collection, fn) {
134
- for (var i = 0, l = collection.length; i < l; i++) {
135
- var item = collection[i];
136
- if (fn(item)) {
137
- return item;
138
- }
139
- }
140
- return null;
141
- });
142
- _defineProperty(_assertThisInitialized(_this), "resetValidations", function () {
143
- _this.childs.forEach(function (child) {
144
- child.validateDebounced.cancel();
145
- child.setState({
146
- isValid: true
147
- });
148
- });
149
- });
150
- _defineProperty(_assertThisInitialized(_this), "isFormValid", function () {
151
- var dryRun = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
152
- return _this.walk(_this.childs, dryRun);
153
- });
154
- return _this;
155
- }
156
- _createClass(ValidatorForm, [{
157
- key: "render",
158
- value: function render() {
159
- // eslint-disable-next-line
160
- var _this$props = this.props,
161
- onSubmit = _this$props.onSubmit,
162
- instantValidate = _this$props.instantValidate,
163
- onError = _this$props.onError,
164
- debounceTime = _this$props.debounceTime,
165
- children = _this$props.children,
166
- rest = _objectWithoutProperties(_this$props, _excluded);
167
- return /*#__PURE__*/_react["default"].createElement(FormContext.Provider, {
168
- value: this.getFormHelpers()
169
- }, /*#__PURE__*/_react["default"].createElement("form", _extends({}, rest, {
170
- onSubmit: this.submit
171
- }), children));
172
- }
173
- }]);
174
- return ValidatorForm;
175
- }(_react["default"].Component);
176
- _defineProperty(ValidatorForm, "getValidator", function (validator, value, includeRequired) {
177
- var result = true;
178
- var name = validator;
179
- if (name !== "required" || includeRequired) {
180
- var extra;
181
- var splitIdx = validator.indexOf(":");
182
- if (splitIdx !== -1) {
183
- name = validator.substring(0, splitIdx);
184
- extra = validator.substring(splitIdx + 1);
185
- }
186
- result = _ValidationRules["default"][name](value, extra);
187
- }
188
- return result;
189
- });
190
- ValidatorForm.addValidationRule = function (name, callback) {
191
- _ValidationRules["default"][name] = callback;
192
- };
193
- ValidatorForm.getValidationRule = function (name) {
194
- return _ValidationRules["default"][name];
195
- };
196
- ValidatorForm.hasValidationRule = function (name) {
197
- return _ValidationRules["default"][name] && typeof _ValidationRules["default"][name] === "function";
198
- };
199
- ValidatorForm.removeValidationRule = function (name) {
200
- delete _ValidationRules["default"][name];
201
- };
202
- ValidatorForm.propTypes = {
203
- onSubmit: _propTypes["default"].func.isRequired,
204
- instantValidate: _propTypes["default"].bool,
205
- children: _propTypes["default"].node,
206
- onError: _propTypes["default"].func,
207
- debounceTime: _propTypes["default"].number
208
- };
209
- ValidatorForm.defaultProps = {
210
- onError: function onError() {},
211
- debounceTime: 0
212
- };
213
- var _default = ValidatorForm;
214
- exports["default"] = _default;
package/lib/index.js DELETED
@@ -1,11 +0,0 @@
1
- "use strict";
2
-
3
- var _MuiComponent = _interopRequireDefault(require("./core/MuiComponent"));
4
- var _MuiForm = _interopRequireDefault(require("./core/MuiForm"));
5
- var _MuiTextField = _interopRequireDefault(require("./components/MuiTextField"));
6
- var _MuiCheckbox = _interopRequireDefault(require("./components/MuiCheckbox"));
7
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; }
8
- exports.MuiTextField = _MuiTextField["default"];
9
- exports.MuiCheckbox = _MuiCheckbox["default"];
10
- exports.MuiComponent = _MuiComponent["default"];
11
- exports.MuiForm = _MuiForm["default"];