@innoways/hooks 9.0.6 → 9.0.7
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.
- package/CHANGELOG.md +8 -0
- package/dist/index.js +61 -3
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
package/dist/index.js
CHANGED
|
@@ -3,8 +3,8 @@ import { useState, useCallback, useRef, useEffect, createContext, useContext, us
|
|
|
3
3
|
import _toConsumableArray from '@babel/runtime/helpers/toConsumableArray';
|
|
4
4
|
import _useDebounceFn2 from 'ahooks/es/useDebounceFn';
|
|
5
5
|
import _defineProperty from '@babel/runtime/helpers/defineProperty';
|
|
6
|
-
import produce, { produce as produce$1 } from 'immer';
|
|
7
6
|
import _typeof from '@babel/runtime/helpers/typeof';
|
|
7
|
+
import produce, { produce as produce$1 } from 'immer';
|
|
8
8
|
import moment from 'moment';
|
|
9
9
|
import { isEmpty, typeCheck, generateReg, fetchFnJsonKey } from '@innoways/utils';
|
|
10
10
|
import _asyncToGenerator from '@babel/runtime/helpers/asyncToGenerator';
|
|
@@ -98,6 +98,60 @@ function ownKeys$4(object, enumerableOnly) { var keys = Object.keys(object); if
|
|
|
98
98
|
|
|
99
99
|
function _objectSpread$4(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys$4(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys$4(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
100
100
|
|
|
101
|
+
function _createForOfIteratorHelper(o, allowArrayLike) { var it = typeof Symbol !== "undefined" && o[Symbol.iterator] || o["@@iterator"]; if (!it) { if (Array.isArray(o) || (it = _unsupportedIterableToArray(o)) || allowArrayLike && o && typeof o.length === "number") { if (it) o = it; var i = 0; var F = function F() {}; return { s: F, n: function n() { if (i >= o.length) return { done: true }; return { done: false, value: o[i++] }; }, e: function e(_e) { throw _e; }, f: F }; } throw new TypeError("Invalid attempt to iterate non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); } var normalCompletion = true, didErr = false, err; return { s: function s() { it = it.call(o); }, n: function n() { var step = it.next(); normalCompletion = step.done; return step; }, e: function e(_e2) { didErr = true; err = _e2; }, f: function f() { try { if (!normalCompletion && it["return"] != null) it["return"](); } finally { if (didErr) throw err; } } }; }
|
|
102
|
+
|
|
103
|
+
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); }
|
|
104
|
+
|
|
105
|
+
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; }
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Recursively collect required-field errors for values that are null or "".
|
|
109
|
+
* AJV's `required` keyword only checks property existence; a property present
|
|
110
|
+
* with value null or "" passes required even though it is effectively empty.
|
|
111
|
+
* This function generates the same errorMessage-style errors for those cases.
|
|
112
|
+
*/
|
|
113
|
+
function collectEmptyRequiredErrors(data, schema, errorsMap) {
|
|
114
|
+
var prefix = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : '';
|
|
115
|
+
if (!data || _typeof(data) !== 'object' || Array.isArray(data)) return;
|
|
116
|
+
var required = (schema === null || schema === void 0 ? void 0 : schema.required) || [];
|
|
117
|
+
|
|
118
|
+
var _iterator = _createForOfIteratorHelper(required),
|
|
119
|
+
_step;
|
|
120
|
+
|
|
121
|
+
try {
|
|
122
|
+
for (_iterator.s(); !(_step = _iterator.n()).done;) {
|
|
123
|
+
var key = _step.value;
|
|
124
|
+
var fullKey = prefix ? "".concat(prefix, ".").concat(key) : key; // Skip if AJV already recorded an error for this field
|
|
125
|
+
|
|
126
|
+
if (errorsMap[fullKey]) continue;
|
|
127
|
+
var val = data[key];
|
|
128
|
+
|
|
129
|
+
if (val === null || val === '') {
|
|
130
|
+
var _schema$errorMessage, _schema$errorMessage$, _schema$properties, _schema$properties$ke, _schema$properties$ke2;
|
|
131
|
+
|
|
132
|
+
var message = (schema === null || schema === void 0 ? void 0 : (_schema$errorMessage = schema.errorMessage) === null || _schema$errorMessage === void 0 ? void 0 : (_schema$errorMessage$ = _schema$errorMessage.required) === null || _schema$errorMessage$ === void 0 ? void 0 : _schema$errorMessage$[key]) || (schema === null || schema === void 0 ? void 0 : (_schema$properties = schema.properties) === null || _schema$properties === void 0 ? void 0 : (_schema$properties$ke = _schema$properties[key]) === null || _schema$properties$ke === void 0 ? void 0 : (_schema$properties$ke2 = _schema$properties$ke.errorMessage) === null || _schema$properties$ke2 === void 0 ? void 0 : _schema$properties$ke2.$required) || '未知错误';
|
|
133
|
+
errorsMap[fullKey] = message;
|
|
134
|
+
}
|
|
135
|
+
} // Recurse into nested object properties
|
|
136
|
+
|
|
137
|
+
} catch (err) {
|
|
138
|
+
_iterator.e(err);
|
|
139
|
+
} finally {
|
|
140
|
+
_iterator.f();
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
if (schema !== null && schema !== void 0 && schema.properties) {
|
|
144
|
+
for (var _i = 0, _Object$keys = Object.keys(schema.properties); _i < _Object$keys.length; _i++) {
|
|
145
|
+
var propKey = _Object$keys[_i];
|
|
146
|
+
var nestedData = data[propKey];
|
|
147
|
+
|
|
148
|
+
if (nestedData !== null && nestedData !== undefined && _typeof(nestedData) === 'object' && !Array.isArray(nestedData)) {
|
|
149
|
+
var nestedPrefix = prefix ? "".concat(prefix, ".").concat(propKey) : propKey;
|
|
150
|
+
collectEmptyRequiredErrors(nestedData, schema.properties[propKey], errorsMap, nestedPrefix);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
}
|
|
101
155
|
/**
|
|
102
156
|
*
|
|
103
157
|
* @param {json} schema 校验数据的json schema
|
|
@@ -109,6 +163,8 @@ function _objectSpread$4(target) { for (var i = 1; i < arguments.length; i++) {
|
|
|
109
163
|
* error {} 校验错误信息
|
|
110
164
|
* }
|
|
111
165
|
*/
|
|
166
|
+
|
|
167
|
+
|
|
112
168
|
var validate = function validate(_ref) {
|
|
113
169
|
var schema = _ref.schema,
|
|
114
170
|
formData = _ref.formData,
|
|
@@ -173,9 +229,11 @@ var validate = function validate(_ref) {
|
|
|
173
229
|
// 根目录required错误
|
|
174
230
|
errorsMap[error.params.errors[0].params.missingProperty] = error.message || '未知错误';
|
|
175
231
|
}
|
|
176
|
-
}); //
|
|
177
|
-
//
|
|
232
|
+
}); // Additionally validate required fields for null/"" values.
|
|
233
|
+
// AJV's `required` keyword only checks property existence, so a field
|
|
234
|
+
// present with value null or "" passes required. We catch those here.
|
|
178
235
|
|
|
236
|
+
collectEmptyRequiredErrors(newFormData, schema, errorsMap);
|
|
179
237
|
Object.keys(errorsMap).map(function (key) {
|
|
180
238
|
if (visibleFieldKey && !(visibleFieldKey !== null && visibleFieldKey !== void 0 && visibleFieldKey.includes(key))) {
|
|
181
239
|
delete errorsMap[key];
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@innoways/hooks",
|
|
3
|
-
"version": "9.0.
|
|
3
|
+
"version": "9.0.7",
|
|
4
4
|
"description": "drip-form通用hooks",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"hooks",
|
|
@@ -31,7 +31,7 @@
|
|
|
31
31
|
},
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@babel/runtime": "^7.10.2",
|
|
34
|
-
"@innoways/utils": "^9.0.
|
|
34
|
+
"@innoways/utils": "^9.0.7",
|
|
35
35
|
"ahooks": "^2.10.12",
|
|
36
36
|
"ajv": "^8.6.2",
|
|
37
37
|
"immer": "^9.0.5",
|