@sheinx/hooks 3.2.1 → 3.2.2
Sign up to get free protection for your applications and to get access to all the features.
- package/cjs/common/use-position-style/index.js +1 -1
- package/cjs/components/use-form/use-form-fieldset/use-form-fieldset.d.ts +1 -0
- package/cjs/components/use-form/use-form-fieldset/use-form-fieldset.d.ts.map +1 -1
- package/cjs/components/use-form/use-form-fieldset/use-form-fieldset.js +2 -1
- package/cjs/components/use-form/use-form.d.ts +6 -0
- package/cjs/components/use-form/use-form.d.ts.map +1 -1
- package/cjs/components/use-form/use-form.js +33 -1
- package/cjs/components/use-form/use-form.type.d.ts +3 -0
- package/cjs/components/use-form/use-form.type.d.ts.map +1 -1
- package/cjs/utils/flat.d.ts +14 -0
- package/cjs/utils/flat.d.ts.map +1 -0
- package/cjs/utils/flat.js +94 -0
- package/cjs/utils/index.d.ts +1 -0
- package/cjs/utils/index.d.ts.map +1 -1
- package/cjs/utils/index.js +8 -1
- package/cjs/utils/render.d.ts +1 -1
- package/cjs/utils/render.d.ts.map +1 -1
- package/cjs/utils/render.js +2 -2
- package/esm/common/use-position-style/index.js +1 -1
- package/esm/components/use-form/use-form-fieldset/use-form-fieldset.d.ts +1 -0
- package/esm/components/use-form/use-form-fieldset/use-form-fieldset.d.ts.map +1 -1
- package/esm/components/use-form/use-form-fieldset/use-form-fieldset.js +2 -1
- package/esm/components/use-form/use-form.d.ts +6 -0
- package/esm/components/use-form/use-form.d.ts.map +1 -1
- package/esm/components/use-form/use-form.js +33 -1
- package/esm/components/use-form/use-form.type.d.ts +3 -0
- package/esm/components/use-form/use-form.type.d.ts.map +1 -1
- package/esm/utils/flat.d.ts +14 -0
- package/esm/utils/flat.d.ts.map +1 -0
- package/esm/utils/flat.js +85 -0
- package/esm/utils/index.d.ts +1 -0
- package/esm/utils/index.d.ts.map +1 -1
- package/esm/utils/index.js +3 -1
- package/esm/utils/render.d.ts +1 -1
- package/esm/utils/render.d.ts.map +1 -1
- package/esm/utils/render.js +2 -2
- package/package.json +1 -1
@@ -24,7 +24,7 @@ var horizontalPosition = ['left-bottom', 'left-top', 'right-bottom', 'right-top'
|
|
24
24
|
var verticalPosition = ['bottom-left', 'bottom-right', 'top-left', 'top-right', 'bottom', 'top'];
|
25
25
|
var hideStyle = {
|
26
26
|
pointerEvents: 'none',
|
27
|
-
position: '
|
27
|
+
position: 'fixed',
|
28
28
|
zIndex: -1000,
|
29
29
|
opacity: 0
|
30
30
|
};
|
@@ -10,6 +10,7 @@ export declare const useFormFieldSet: <T>(props: BaseFormFieldSetProps<T>) => {
|
|
10
10
|
error: Error | undefined;
|
11
11
|
value: T | undefined;
|
12
12
|
onChange: (v: T, ...other: any[]) => void;
|
13
|
+
name: string | (string[] & string);
|
13
14
|
};
|
14
15
|
export default useFormFieldSet;
|
15
16
|
//# sourceMappingURL=use-form-fieldset.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-form-fieldset.d.ts","sourceRoot":"","sources":["use-form-fieldset.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAKjE,eAAO,MAAM,eAAe
|
1
|
+
{"version":3,"file":"use-form-fieldset.d.ts","sourceRoot":"","sources":["use-form-fieldset.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAKjE,eAAO,MAAM,eAAe;;;;;;;;;;;CA2B3B,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
@@ -36,7 +36,8 @@ var useFormFieldSet = exports.useFormFieldSet = function useFormFieldSet(props)
|
|
36
36
|
ProviderValue: ProviderValue,
|
37
37
|
error: error,
|
38
38
|
value: value,
|
39
|
-
onChange: onChange
|
39
|
+
onChange: onChange,
|
40
|
+
name: name
|
40
41
|
};
|
41
42
|
};
|
42
43
|
var _default = exports.default = useFormFieldSet;
|
@@ -20,6 +20,9 @@ declare const useForm: <T extends ObjectType>(props: UseFormProps<T>) => {
|
|
20
20
|
getErrors: () => ObjectType<Error | undefined>;
|
21
21
|
clearValidate: (names?: string[]) => void;
|
22
22
|
validateFields: (fields?: string | string[], config?: any) => Promise<true>;
|
23
|
+
validateFieldset: (name: string) => void;
|
24
|
+
insertError: (name: string, index: number, error?: Error) => void;
|
25
|
+
spliceError: (name: string, index: number) => void;
|
23
26
|
};
|
24
27
|
};
|
25
28
|
formFunc: {
|
@@ -35,6 +38,9 @@ declare const useForm: <T extends ObjectType>(props: UseFormProps<T>) => {
|
|
35
38
|
getErrors: () => ObjectType<Error | undefined>;
|
36
39
|
clearValidate: (names?: string[]) => void;
|
37
40
|
validateFields: (fields?: string | string[], config?: any) => Promise<true>;
|
41
|
+
validateFieldset: (name: string) => void;
|
42
|
+
insertError: (name: string, index: number, error?: Error) => void;
|
43
|
+
spliceError: (name: string, index: number) => void;
|
38
44
|
};
|
39
45
|
};
|
40
46
|
export default useForm;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-form.d.ts","sourceRoot":"","sources":["use-form.ts"],"names":[],"mappings":";
|
1
|
+
{"version":3,"file":"use-form.d.ts","sourceRoot":"","sources":["use-form.ts"],"names":[],"mappings":";AAwBA,OAAO,EAAe,aAAa,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC7F,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI5D,QAAA,MAAM,OAAO;;;;;;;;;wBAgK8B;gBAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;aAAE;8BARzB,MAAM;oCAuDD,OAAO;;6BAfb,MAAM,KAAK,KAAK,GAAG,SAAS;;oCAdrB,MAAM,EAAE;sCArEN,MAAM,GAAG,MAAM,EAAE,mBAAgB,QAAQ,IAAI,CAAC;qCAiI5D,MAAM;gCAzCE,MAAM,SAAS,MAAM,UAAU,KAAK;gCAKpC,MAAM,SAAS,MAAM;;;;;;oBA1CpB;YAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;SAAE;0BARzB,MAAM;gCAuDD,OAAO;;yBAfb,MAAM,KAAK,KAAK,GAAG,SAAS;;gCAdrB,MAAM,EAAE;kCArEN,MAAM,GAAG,MAAM,EAAE,mBAAgB,QAAQ,IAAI,CAAC;iCAiI5D,MAAM;4BAzCE,MAAM,SAAS,MAAM,UAAU,KAAK;4BAKpC,MAAM,SAAS,MAAM;;CA6P9D,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
@@ -10,6 +10,7 @@ var _Provider = require("./Provider");
|
|
10
10
|
var _useLatestObj = _interopRequireDefault(require("../../common/use-latest-obj"));
|
11
11
|
var _usePersistFn = _interopRequireDefault(require("../../common/use-persist-fn"));
|
12
12
|
var _attribute = require("../../utils/attribute");
|
13
|
+
var _flat = require("../../utils/flat");
|
13
14
|
var _immer = require("../../utils/immer");
|
14
15
|
var _utils = require("../../utils");
|
15
16
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
@@ -93,6 +94,15 @@ var useForm = function useForm(props) {
|
|
93
94
|
update();
|
94
95
|
});
|
95
96
|
};
|
97
|
+
var updateFieldsets = (0, _usePersistFn.default)(function (name) {
|
98
|
+
var na = "".concat(name, "[");
|
99
|
+
var no = "".concat(name, ".");
|
100
|
+
context.names.forEach(function (key) {
|
101
|
+
if (key.startsWith(na) || key.startsWith(no)) {
|
102
|
+
update(key);
|
103
|
+
}
|
104
|
+
});
|
105
|
+
});
|
96
106
|
var handleSubmitError = function handleSubmitError(err) {
|
97
107
|
onError === null || onError === void 0 || onError(err);
|
98
108
|
if (!props.scrollToError) return;
|
@@ -210,6 +220,14 @@ var useForm = function useForm(props) {
|
|
210
220
|
context.errors[name] = e;
|
211
221
|
update(name);
|
212
222
|
});
|
223
|
+
var insertError = (0, _usePersistFn.default)(function (name, index, error) {
|
224
|
+
(0, _flat.insertValue)(context.errors, name, index, error);
|
225
|
+
updateFieldsets(name);
|
226
|
+
});
|
227
|
+
var spliceError = (0, _usePersistFn.default)(function (name, index) {
|
228
|
+
(0, _flat.spliceValue)(context.errors, name, index);
|
229
|
+
updateFieldsets(name);
|
230
|
+
});
|
213
231
|
var submit = (0, _usePersistFn.default)(function () {
|
214
232
|
var withValidate = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
215
233
|
if (disabled) return;
|
@@ -266,6 +284,17 @@ var useForm = function useForm(props) {
|
|
266
284
|
other === null || other === void 0 || (_other$onSubmit = other.onSubmit) === null || _other$onSubmit === void 0 || _other$onSubmit.call(other, e);
|
267
285
|
};
|
268
286
|
};
|
287
|
+
var validateFieldset = function validateFieldset(name) {
|
288
|
+
var na = "".concat(name, "[");
|
289
|
+
var no = "".concat(name, ".");
|
290
|
+
var fields = [];
|
291
|
+
context.names.forEach(function (key) {
|
292
|
+
if (key.startsWith(na) || key.startsWith(no)) {
|
293
|
+
fields.push(key);
|
294
|
+
}
|
295
|
+
});
|
296
|
+
validateFields(fields).catch(function () {});
|
297
|
+
};
|
269
298
|
var getDefaultValue = function getDefaultValue() {
|
270
299
|
var v = (0, _immer.produce)(defaultValue, function (draft) {
|
271
300
|
Object.keys(context.defaultValues).forEach(function (key) {
|
@@ -371,7 +400,10 @@ var useForm = function useForm(props) {
|
|
371
400
|
setError: setError,
|
372
401
|
getErrors: getErrors,
|
373
402
|
clearValidate: clearValidate,
|
374
|
-
validateFields: validateFields
|
403
|
+
validateFields: validateFields,
|
404
|
+
validateFieldset: validateFieldset,
|
405
|
+
insertError: insertError,
|
406
|
+
spliceError: spliceError
|
375
407
|
});
|
376
408
|
var formConfig = React.useMemo(function () {
|
377
409
|
return {
|
@@ -80,6 +80,9 @@ export interface FormFunc {
|
|
80
80
|
validateFields: (fields?: string | string[], config?: {
|
81
81
|
ignoreBind?: boolean;
|
82
82
|
}) => Promise<true>;
|
83
|
+
validateFieldset: (name: string) => void;
|
84
|
+
insertError: (name: string, index: number, error?: Error) => void;
|
85
|
+
spliceError: (name: string, index: number) => void;
|
83
86
|
}
|
84
87
|
interface FormRuleObject<T> {
|
85
88
|
[key: string]: FormRuleObject<T> | FormItemRule<T>;
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,CAAC;AAEF,MAAM,MAAM,gBAAgB,CAAC,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,UAAU,CACzE,mBAAmB,EACnB,MAAM,CACP,CAAC"}
|
@@ -0,0 +1,14 @@
|
|
1
|
+
export type insertObject = {
|
2
|
+
[x: string]: any;
|
3
|
+
};
|
4
|
+
export declare function insertPoint(name: string): string;
|
5
|
+
export type Result = {
|
6
|
+
[x: string]: any;
|
7
|
+
};
|
8
|
+
export declare function flatten(data: Result, skipArray?: boolean): Result;
|
9
|
+
export declare function insertValue(obj: insertObject, name: string, index: number, value: any): void;
|
10
|
+
export type SpliceValue = {
|
11
|
+
[x: string]: any;
|
12
|
+
};
|
13
|
+
export declare function spliceValue(obj: SpliceValue, name: keyof SpliceValue & string, index: number): void;
|
14
|
+
//# sourceMappingURL=flat.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"flat.d.ts","sourceRoot":"","sources":["flat.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,YAAY,GAAG;IACzB,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;CAClB,CAAC;AAEF,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,UAGvC;AAED,MAAM,MAAM,MAAM,GAAG;IACnB,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;CAClB,CAAC;AAEF,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,OAAO,UAuCxD;AACD,wBAAgB,WAAW,CAAC,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,QAmBrF;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;CAClB,CAAC;AAEF,wBAAgB,WAAW,CAAC,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,WAAW,GAAG,MAAM,EAAE,KAAK,EAAE,MAAM,QAyB5F"}
|
@@ -0,0 +1,94 @@
|
|
1
|
+
"use strict";
|
2
|
+
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
4
|
+
value: true
|
5
|
+
});
|
6
|
+
exports.flatten = flatten;
|
7
|
+
exports.insertPoint = insertPoint;
|
8
|
+
exports.insertValue = insertValue;
|
9
|
+
exports.spliceValue = spliceValue;
|
10
|
+
var _is = require("./is");
|
11
|
+
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; }
|
12
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
13
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
14
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
15
|
+
function insertPoint(name) {
|
16
|
+
var reg = /(\[\d+\])/gi;
|
17
|
+
return name.replace(reg, function (s, m, i) {
|
18
|
+
return s.replace(m, i === 0 ? m : ".".concat(m));
|
19
|
+
});
|
20
|
+
}
|
21
|
+
function flatten(data, skipArray) {
|
22
|
+
if ((0, _is.isEmpty)(data)) return data;
|
23
|
+
var result = {};
|
24
|
+
function recurse(cur, prop) {
|
25
|
+
if (Object(cur) !== cur || typeof cur === 'function' || cur instanceof Date || cur instanceof Error || skipArray && Array.isArray(cur)) {
|
26
|
+
if (!(cur === undefined && /\[\d+\]$/.test(prop))) {
|
27
|
+
result[prop] = cur;
|
28
|
+
}
|
29
|
+
} else if (Array.isArray(cur)) {
|
30
|
+
if (cur.length === 0) {
|
31
|
+
result[prop] = [];
|
32
|
+
} else {
|
33
|
+
for (var i = 0, l = cur.length; i < l; i++) {
|
34
|
+
recurse(cur[i], prop ? "".concat(prop, "[").concat(i, "]") : "[".concat(i, "]"));
|
35
|
+
}
|
36
|
+
}
|
37
|
+
} else {
|
38
|
+
var empty = true;
|
39
|
+
if (_typeof(cur) === 'object') {
|
40
|
+
// eslint-disable-next-line
|
41
|
+
for (var p in cur) {
|
42
|
+
empty = false;
|
43
|
+
recurse(cur[p], prop ? "".concat(prop, ".").concat(p) : p);
|
44
|
+
}
|
45
|
+
if (empty) {
|
46
|
+
result[prop] = {};
|
47
|
+
}
|
48
|
+
}
|
49
|
+
}
|
50
|
+
}
|
51
|
+
recurse(data, '');
|
52
|
+
return result;
|
53
|
+
}
|
54
|
+
function insertValue(obj, name, index, value) {
|
55
|
+
Object.keys(obj).filter(function (n) {
|
56
|
+
return n.indexOf("".concat(name, "[")) === 0;
|
57
|
+
}).sort().reverse().forEach(function (n) {
|
58
|
+
// const reg = new RegExp(`${name}\\[(\\d+)\\]`)
|
59
|
+
var reg = new RegExp("".concat(name.replace(/\[/g, '\\[').replace(/\]/g, '\\]'), "\\[(\\d+)\\]"));
|
60
|
+
var match = reg.exec(n);
|
61
|
+
var i = parseInt(match[1], 10);
|
62
|
+
if (i < index) return;
|
63
|
+
var newName = n.replace(reg, "".concat(name, "[").concat(i + 1, "]"));
|
64
|
+
if (obj[n]) obj[newName] = obj[n];
|
65
|
+
delete obj[n];
|
66
|
+
});
|
67
|
+
var newValue = flatten(_defineProperty({}, "".concat(name, "[").concat(index, "]"), value));
|
68
|
+
Object.keys(newValue).forEach(function (k) {
|
69
|
+
if (newValue[k] !== undefined) obj[k] = newValue[k];
|
70
|
+
});
|
71
|
+
}
|
72
|
+
function spliceValue(obj, name, index) {
|
73
|
+
var names = Object.keys(obj).filter(function (n) {
|
74
|
+
return n === name || n.indexOf("".concat(name, "[")) === 0;
|
75
|
+
}).sort();
|
76
|
+
names.forEach(function (n) {
|
77
|
+
if (n === name && !Array.isArray(obj[name])) return;
|
78
|
+
if (n === name && Array.isArray(obj[name])) {
|
79
|
+
obj[name].splice(index, 1);
|
80
|
+
return;
|
81
|
+
}
|
82
|
+
var reg = new RegExp("".concat(name.replace(/\[/g, '\\[').replace(/\]/g, '\\]'), "\\[(\\d+)\\]"));
|
83
|
+
var match = reg.exec(n);
|
84
|
+
var i = parseInt(match[1], 10);
|
85
|
+
if (i < index) return;
|
86
|
+
if (i === index) {
|
87
|
+
delete obj[n];
|
88
|
+
return;
|
89
|
+
}
|
90
|
+
var newName = n.replace(reg, "".concat(name, "[").concat(i - 1, "]"));
|
91
|
+
obj[newName] = obj[n];
|
92
|
+
delete obj[n];
|
93
|
+
});
|
94
|
+
}
|
package/cjs/utils/index.d.ts
CHANGED
package/cjs/utils/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,MAAM,CAAC;AACrB,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAC3E,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,OAAO,CAAC;AACtB,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC"}
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,MAAM,CAAC;AACrB,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAC3E,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,OAAO,CAAC;AACtB,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC"}
|
package/cjs/utils/index.js
CHANGED
@@ -1,10 +1,12 @@
|
|
1
1
|
"use strict";
|
2
2
|
|
3
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
3
4
|
Object.defineProperty(exports, "__esModule", {
|
4
5
|
value: true
|
5
6
|
});
|
6
7
|
var _exportNames = {
|
7
|
-
extractEventHandlers: true
|
8
|
+
extractEventHandlers: true,
|
9
|
+
flat: true
|
8
10
|
};
|
9
11
|
Object.defineProperty(exports, "extractEventHandlers", {
|
10
12
|
enumerable: true,
|
@@ -12,6 +14,7 @@ Object.defineProperty(exports, "extractEventHandlers", {
|
|
12
14
|
return _extractEventHandlers.default;
|
13
15
|
}
|
14
16
|
});
|
17
|
+
exports.flat = void 0;
|
15
18
|
var _is = require("./is");
|
16
19
|
Object.keys(_is).forEach(function (key) {
|
17
20
|
if (key === "default" || key === "__esModule") return;
|
@@ -265,4 +268,8 @@ Object.keys(_immer).forEach(function (key) {
|
|
265
268
|
}
|
266
269
|
});
|
267
270
|
});
|
271
|
+
var _flat = _interopRequireWildcard(require("./flat"));
|
272
|
+
exports.flat = _flat;
|
273
|
+
function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(e) { return e ? t : r; })(e); }
|
274
|
+
function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != _typeof(e) && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && Object.prototype.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
|
268
275
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
package/cjs/utils/render.d.ts
CHANGED
@@ -2,5 +2,5 @@ import React from 'react';
|
|
2
2
|
import { KeygenType } from '../common/type';
|
3
3
|
export type renderFunc<T extends any[]> = (...args: T) => React.ReactNode;
|
4
4
|
export declare const render: <T extends any[]>(r: string | renderFunc<T> | undefined, ...args: T) => any;
|
5
|
-
export declare function getKey<T>(gen: KeygenType<T> | undefined, d: T, index?: number): string | number;
|
5
|
+
export declare function getKey<T>(gen: KeygenType<T> | undefined, d: T, index?: number, ignoreError?: boolean): string | number;
|
6
6
|
//# sourceMappingURL=render.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["render.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,GAAG,EAAE,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,KAAK,CAAC,SAAS,CAAC;AAE1E,eAAO,MAAM,MAAM,6EAIlB,CAAC;AAQF,wBAAgB,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,SAAS,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE,MAAM,
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["render.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,GAAG,EAAE,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,KAAK,CAAC,SAAS,CAAC;AAE1E,eAAO,MAAM,MAAM,6EAIlB,CAAC;AAQF,wBAAgB,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,SAAS,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,OAAO,mBAMpG"}
|
package/cjs/utils/render.js
CHANGED
@@ -20,9 +20,9 @@ function $getKey(gen, d, index) {
|
|
20
20
|
if (typeof gen === 'function') return gen(d, index);
|
21
21
|
return index;
|
22
22
|
}
|
23
|
-
function getKey(gen, d, index) {
|
23
|
+
function getKey(gen, d, index, ignoreError) {
|
24
24
|
var key = $getKey(gen, d, index);
|
25
|
-
if (typeof key !== 'string' && typeof key !== 'number') {
|
25
|
+
if (typeof key !== 'string' && typeof key !== 'number' && !ignoreError) {
|
26
26
|
console.error(new Error("keygen result expect a string or a number, get '".concat(_typeof(key), "'")));
|
27
27
|
}
|
28
28
|
return key;
|
@@ -14,7 +14,7 @@ var horizontalPosition = ['left-bottom', 'left-top', 'right-bottom', 'right-top'
|
|
14
14
|
var verticalPosition = ['bottom-left', 'bottom-right', 'top-left', 'top-right', 'bottom', 'top'];
|
15
15
|
var hideStyle = {
|
16
16
|
pointerEvents: 'none',
|
17
|
-
position: '
|
17
|
+
position: 'fixed',
|
18
18
|
zIndex: -1000,
|
19
19
|
opacity: 0
|
20
20
|
};
|
@@ -10,6 +10,7 @@ export declare const useFormFieldSet: <T>(props: BaseFormFieldSetProps<T>) => {
|
|
10
10
|
error: Error | undefined;
|
11
11
|
value: T | undefined;
|
12
12
|
onChange: (v: T, ...other: any[]) => void;
|
13
|
+
name: string | (string[] & string);
|
13
14
|
};
|
14
15
|
export default useFormFieldSet;
|
15
16
|
//# sourceMappingURL=use-form-fieldset.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-form-fieldset.d.ts","sourceRoot":"","sources":["use-form-fieldset.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAKjE,eAAO,MAAM,eAAe
|
1
|
+
{"version":3,"file":"use-form-fieldset.d.ts","sourceRoot":"","sources":["use-form-fieldset.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,0BAA0B,CAAC;AAKjE,eAAO,MAAM,eAAe;;;;;;;;;;;CA2B3B,CAAC;AAEF,eAAe,eAAe,CAAC"}
|
@@ -20,6 +20,9 @@ declare const useForm: <T extends ObjectType>(props: UseFormProps<T>) => {
|
|
20
20
|
getErrors: () => ObjectType<Error | undefined>;
|
21
21
|
clearValidate: (names?: string[]) => void;
|
22
22
|
validateFields: (fields?: string | string[], config?: any) => Promise<true>;
|
23
|
+
validateFieldset: (name: string) => void;
|
24
|
+
insertError: (name: string, index: number, error?: Error) => void;
|
25
|
+
spliceError: (name: string, index: number) => void;
|
23
26
|
};
|
24
27
|
};
|
25
28
|
formFunc: {
|
@@ -35,6 +38,9 @@ declare const useForm: <T extends ObjectType>(props: UseFormProps<T>) => {
|
|
35
38
|
getErrors: () => ObjectType<Error | undefined>;
|
36
39
|
clearValidate: (names?: string[]) => void;
|
37
40
|
validateFields: (fields?: string | string[], config?: any) => Promise<true>;
|
41
|
+
validateFieldset: (name: string) => void;
|
42
|
+
insertError: (name: string, index: number, error?: Error) => void;
|
43
|
+
spliceError: (name: string, index: number) => void;
|
38
44
|
};
|
39
45
|
};
|
40
46
|
export default useForm;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-form.d.ts","sourceRoot":"","sources":["use-form.ts"],"names":[],"mappings":";
|
1
|
+
{"version":3,"file":"use-form.d.ts","sourceRoot":"","sources":["use-form.ts"],"names":[],"mappings":";AAwBA,OAAO,EAAe,aAAa,EAAE,YAAY,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC7F,OAAO,EAAe,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAI5D,QAAA,MAAM,OAAO;;;;;;;;;wBAgK8B;gBAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;aAAE;8BARzB,MAAM;oCAuDD,OAAO;;6BAfb,MAAM,KAAK,KAAK,GAAG,SAAS;;oCAdrB,MAAM,EAAE;sCArEN,MAAM,GAAG,MAAM,EAAE,mBAAgB,QAAQ,IAAI,CAAC;qCAiI5D,MAAM;gCAzCE,MAAM,SAAS,MAAM,UAAU,KAAK;gCAKpC,MAAM,SAAS,MAAM;;;;;;oBA1CpB;YAAE,QAAQ,CAAC,EAAE,OAAO,CAAA;SAAE;0BARzB,MAAM;gCAuDD,OAAO;;yBAfb,MAAM,KAAK,KAAK,GAAG,SAAS;;gCAdrB,MAAM,EAAE;kCArEN,MAAM,GAAG,MAAM,EAAE,mBAAgB,QAAQ,IAAI,CAAC;iCAiI5D,MAAM;4BAzCE,MAAM,SAAS,MAAM,UAAU,KAAK;4BAKpC,MAAM,SAAS,MAAM;;CA6P9D,CAAC;AAEF,eAAe,OAAO,CAAC"}
|
@@ -12,6 +12,7 @@ import { Provider } from "./Provider";
|
|
12
12
|
import useLatestObj from "../../common/use-latest-obj";
|
13
13
|
import usePersistFn from "../../common/use-persist-fn";
|
14
14
|
import { getDataAttributeName } from "../../utils/attribute";
|
15
|
+
import { insertValue, spliceValue } from "../../utils/flat";
|
15
16
|
var globalKey = '__global__&&@@';
|
16
17
|
import { current, produce } from "../../utils/immer";
|
17
18
|
import { deepGet, deepRemove, deepSet, docScroll, extractEventHandlers, isArray, isObject, shallowEqual, wrapFormError, deepClone } from "../../utils";
|
@@ -84,6 +85,15 @@ var useForm = function useForm(props) {
|
|
84
85
|
update();
|
85
86
|
});
|
86
87
|
};
|
88
|
+
var updateFieldsets = usePersistFn(function (name) {
|
89
|
+
var na = "".concat(name, "[");
|
90
|
+
var no = "".concat(name, ".");
|
91
|
+
context.names.forEach(function (key) {
|
92
|
+
if (key.startsWith(na) || key.startsWith(no)) {
|
93
|
+
update(key);
|
94
|
+
}
|
95
|
+
});
|
96
|
+
});
|
87
97
|
var handleSubmitError = function handleSubmitError(err) {
|
88
98
|
onError === null || onError === void 0 || onError(err);
|
89
99
|
if (!props.scrollToError) return;
|
@@ -201,6 +211,14 @@ var useForm = function useForm(props) {
|
|
201
211
|
context.errors[name] = e;
|
202
212
|
update(name);
|
203
213
|
});
|
214
|
+
var insertError = usePersistFn(function (name, index, error) {
|
215
|
+
insertValue(context.errors, name, index, error);
|
216
|
+
updateFieldsets(name);
|
217
|
+
});
|
218
|
+
var spliceError = usePersistFn(function (name, index) {
|
219
|
+
spliceValue(context.errors, name, index);
|
220
|
+
updateFieldsets(name);
|
221
|
+
});
|
204
222
|
var submit = usePersistFn(function () {
|
205
223
|
var withValidate = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : true;
|
206
224
|
if (disabled) return;
|
@@ -257,6 +275,17 @@ var useForm = function useForm(props) {
|
|
257
275
|
other === null || other === void 0 || (_other$onSubmit = other.onSubmit) === null || _other$onSubmit === void 0 || _other$onSubmit.call(other, e);
|
258
276
|
};
|
259
277
|
};
|
278
|
+
var validateFieldset = function validateFieldset(name) {
|
279
|
+
var na = "".concat(name, "[");
|
280
|
+
var no = "".concat(name, ".");
|
281
|
+
var fields = [];
|
282
|
+
context.names.forEach(function (key) {
|
283
|
+
if (key.startsWith(na) || key.startsWith(no)) {
|
284
|
+
fields.push(key);
|
285
|
+
}
|
286
|
+
});
|
287
|
+
validateFields(fields).catch(function () {});
|
288
|
+
};
|
260
289
|
var getDefaultValue = function getDefaultValue() {
|
261
290
|
var v = produce(defaultValue, function (draft) {
|
262
291
|
Object.keys(context.defaultValues).forEach(function (key) {
|
@@ -362,7 +391,10 @@ var useForm = function useForm(props) {
|
|
362
391
|
setError: setError,
|
363
392
|
getErrors: getErrors,
|
364
393
|
clearValidate: clearValidate,
|
365
|
-
validateFields: validateFields
|
394
|
+
validateFields: validateFields,
|
395
|
+
validateFieldset: validateFieldset,
|
396
|
+
insertError: insertError,
|
397
|
+
spliceError: spliceError
|
366
398
|
});
|
367
399
|
var formConfig = React.useMemo(function () {
|
368
400
|
return {
|
@@ -80,6 +80,9 @@ export interface FormFunc {
|
|
80
80
|
validateFields: (fields?: string | string[], config?: {
|
81
81
|
ignoreBind?: boolean;
|
82
82
|
}) => Promise<true>;
|
83
|
+
validateFieldset: (name: string) => void;
|
84
|
+
insertError: (name: string, index: number, error?: Error) => void;
|
85
|
+
spliceError: (name: string, index: number) => void;
|
83
86
|
}
|
84
87
|
interface FormRuleObject<T> {
|
85
88
|
[key: string]: FormRuleObject<T> | FormItemRule<T>;
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"use-form.type.d.ts","sourceRoot":"","sources":["use-form.type.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,OAAO,CAA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
@@ -0,0 +1,14 @@
|
|
1
|
+
export type insertObject = {
|
2
|
+
[x: string]: any;
|
3
|
+
};
|
4
|
+
export declare function insertPoint(name: string): string;
|
5
|
+
export type Result = {
|
6
|
+
[x: string]: any;
|
7
|
+
};
|
8
|
+
export declare function flatten(data: Result, skipArray?: boolean): Result;
|
9
|
+
export declare function insertValue(obj: insertObject, name: string, index: number, value: any): void;
|
10
|
+
export type SpliceValue = {
|
11
|
+
[x: string]: any;
|
12
|
+
};
|
13
|
+
export declare function spliceValue(obj: SpliceValue, name: keyof SpliceValue & string, index: number): void;
|
14
|
+
//# sourceMappingURL=flat.d.ts.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"flat.d.ts","sourceRoot":"","sources":["flat.ts"],"names":[],"mappings":"AACA,MAAM,MAAM,YAAY,GAAG;IACzB,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;CAClB,CAAC;AAEF,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,UAGvC;AAED,MAAM,MAAM,MAAM,GAAG;IACnB,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;CAClB,CAAC;AAEF,wBAAgB,OAAO,CAAC,IAAI,EAAE,MAAM,EAAE,SAAS,CAAC,EAAE,OAAO,UAuCxD;AACD,wBAAgB,WAAW,CAAC,GAAG,EAAE,YAAY,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,KAAK,EAAE,GAAG,QAmBrF;AAED,MAAM,MAAM,WAAW,GAAG;IACxB,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAC;CAClB,CAAC;AAEF,wBAAgB,WAAW,CAAC,GAAG,EAAE,WAAW,EAAE,IAAI,EAAE,MAAM,WAAW,GAAG,MAAM,EAAE,KAAK,EAAE,MAAM,QAyB5F"}
|
@@ -0,0 +1,85 @@
|
|
1
|
+
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; }
|
2
|
+
function _toPropertyKey(t) { var i = _toPrimitive(t, "string"); return "symbol" == _typeof(i) ? i : String(i); }
|
3
|
+
function _toPrimitive(t, r) { if ("object" != _typeof(t) || !t) return t; var e = t[Symbol.toPrimitive]; if (void 0 !== e) { var i = e.call(t, r || "default"); if ("object" != _typeof(i)) return i; throw new TypeError("@@toPrimitive must return a primitive value."); } return ("string" === r ? String : Number)(t); }
|
4
|
+
function _typeof(o) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (o) { return typeof o; } : function (o) { return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o; }, _typeof(o); }
|
5
|
+
import { isEmpty } from "./is";
|
6
|
+
export function insertPoint(name) {
|
7
|
+
var reg = /(\[\d+\])/gi;
|
8
|
+
return name.replace(reg, function (s, m, i) {
|
9
|
+
return s.replace(m, i === 0 ? m : ".".concat(m));
|
10
|
+
});
|
11
|
+
}
|
12
|
+
export function flatten(data, skipArray) {
|
13
|
+
if (isEmpty(data)) return data;
|
14
|
+
var result = {};
|
15
|
+
function recurse(cur, prop) {
|
16
|
+
if (Object(cur) !== cur || typeof cur === 'function' || cur instanceof Date || cur instanceof Error || skipArray && Array.isArray(cur)) {
|
17
|
+
if (!(cur === undefined && /\[\d+\]$/.test(prop))) {
|
18
|
+
result[prop] = cur;
|
19
|
+
}
|
20
|
+
} else if (Array.isArray(cur)) {
|
21
|
+
if (cur.length === 0) {
|
22
|
+
result[prop] = [];
|
23
|
+
} else {
|
24
|
+
for (var i = 0, l = cur.length; i < l; i++) {
|
25
|
+
recurse(cur[i], prop ? "".concat(prop, "[").concat(i, "]") : "[".concat(i, "]"));
|
26
|
+
}
|
27
|
+
}
|
28
|
+
} else {
|
29
|
+
var empty = true;
|
30
|
+
if (_typeof(cur) === 'object') {
|
31
|
+
// eslint-disable-next-line
|
32
|
+
for (var p in cur) {
|
33
|
+
empty = false;
|
34
|
+
recurse(cur[p], prop ? "".concat(prop, ".").concat(p) : p);
|
35
|
+
}
|
36
|
+
if (empty) {
|
37
|
+
result[prop] = {};
|
38
|
+
}
|
39
|
+
}
|
40
|
+
}
|
41
|
+
}
|
42
|
+
recurse(data, '');
|
43
|
+
return result;
|
44
|
+
}
|
45
|
+
export function insertValue(obj, name, index, value) {
|
46
|
+
Object.keys(obj).filter(function (n) {
|
47
|
+
return n.indexOf("".concat(name, "[")) === 0;
|
48
|
+
}).sort().reverse().forEach(function (n) {
|
49
|
+
// const reg = new RegExp(`${name}\\[(\\d+)\\]`)
|
50
|
+
var reg = new RegExp("".concat(name.replace(/\[/g, '\\[').replace(/\]/g, '\\]'), "\\[(\\d+)\\]"));
|
51
|
+
var match = reg.exec(n);
|
52
|
+
var i = parseInt(match[1], 10);
|
53
|
+
if (i < index) return;
|
54
|
+
var newName = n.replace(reg, "".concat(name, "[").concat(i + 1, "]"));
|
55
|
+
if (obj[n]) obj[newName] = obj[n];
|
56
|
+
delete obj[n];
|
57
|
+
});
|
58
|
+
var newValue = flatten(_defineProperty({}, "".concat(name, "[").concat(index, "]"), value));
|
59
|
+
Object.keys(newValue).forEach(function (k) {
|
60
|
+
if (newValue[k] !== undefined) obj[k] = newValue[k];
|
61
|
+
});
|
62
|
+
}
|
63
|
+
export function spliceValue(obj, name, index) {
|
64
|
+
var names = Object.keys(obj).filter(function (n) {
|
65
|
+
return n === name || n.indexOf("".concat(name, "[")) === 0;
|
66
|
+
}).sort();
|
67
|
+
names.forEach(function (n) {
|
68
|
+
if (n === name && !Array.isArray(obj[name])) return;
|
69
|
+
if (n === name && Array.isArray(obj[name])) {
|
70
|
+
obj[name].splice(index, 1);
|
71
|
+
return;
|
72
|
+
}
|
73
|
+
var reg = new RegExp("".concat(name.replace(/\[/g, '\\[').replace(/\]/g, '\\]'), "\\[(\\d+)\\]"));
|
74
|
+
var match = reg.exec(n);
|
75
|
+
var i = parseInt(match[1], 10);
|
76
|
+
if (i < index) return;
|
77
|
+
if (i === index) {
|
78
|
+
delete obj[n];
|
79
|
+
return;
|
80
|
+
}
|
81
|
+
var newName = n.replace(reg, "".concat(name, "[").concat(i - 1, "]"));
|
82
|
+
obj[newName] = obj[n];
|
83
|
+
delete obj[n];
|
84
|
+
});
|
85
|
+
}
|
package/esm/utils/index.d.ts
CHANGED
package/esm/utils/index.d.ts.map
CHANGED
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,MAAM,CAAC;AACrB,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAC3E,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,OAAO,CAAC;AACtB,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC"}
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,cAAc,MAAM,CAAC;AACrB,OAAO,EAAE,OAAO,IAAI,oBAAoB,EAAE,MAAM,0BAA0B,CAAC;AAC3E,cAAc,SAAS,CAAC;AACxB,cAAc,OAAO,CAAC;AACtB,cAAc,UAAU,CAAC;AACzB,cAAc,UAAU,CAAC;AACzB,cAAc,QAAQ,CAAC;AACvB,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,iBAAiB,CAAC;AAChC,cAAc,OAAO,CAAC;AACtB,cAAc,YAAY,CAAC;AAC3B,cAAc,YAAY,CAAC;AAC3B,cAAc,UAAU,CAAC;AACzB,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,cAAc,CAAC;AAC7B,cAAc,aAAa,CAAC;AAC5B,cAAc,UAAU,CAAC;AACzB,cAAc,SAAS,CAAC;AACxB,cAAc,QAAQ,CAAC;AACvB,cAAc,SAAS,CAAC;AACxB,OAAO,KAAK,IAAI,MAAM,QAAQ,CAAC"}
|
package/esm/utils/index.js
CHANGED
package/esm/utils/render.d.ts
CHANGED
@@ -2,5 +2,5 @@ import React from 'react';
|
|
2
2
|
import { KeygenType } from '../common/type';
|
3
3
|
export type renderFunc<T extends any[]> = (...args: T) => React.ReactNode;
|
4
4
|
export declare const render: <T extends any[]>(r: string | renderFunc<T> | undefined, ...args: T) => any;
|
5
|
-
export declare function getKey<T>(gen: KeygenType<T> | undefined, d: T, index?: number): string | number;
|
5
|
+
export declare function getKey<T>(gen: KeygenType<T> | undefined, d: T, index?: number, ignoreError?: boolean): string | number;
|
6
6
|
//# sourceMappingURL=render.d.ts.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["render.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,GAAG,EAAE,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,KAAK,CAAC,SAAS,CAAC;AAE1E,eAAO,MAAM,MAAM,6EAIlB,CAAC;AAQF,wBAAgB,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,SAAS,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE,MAAM,
|
1
|
+
{"version":3,"file":"render.d.ts","sourceRoot":"","sources":["render.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAE5C,MAAM,MAAM,UAAU,CAAC,CAAC,SAAS,GAAG,EAAE,IAAI,CAAC,GAAG,IAAI,EAAE,CAAC,KAAK,KAAK,CAAC,SAAS,CAAC;AAE1E,eAAO,MAAM,MAAM,6EAIlB,CAAC;AAQF,wBAAgB,MAAM,CAAC,CAAC,EAAE,GAAG,EAAE,UAAU,CAAC,CAAC,CAAC,GAAG,SAAS,EAAE,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,WAAW,CAAC,EAAE,OAAO,mBAMpG"}
|
package/esm/utils/render.js
CHANGED
@@ -13,9 +13,9 @@ function $getKey(gen, d, index) {
|
|
13
13
|
if (typeof gen === 'function') return gen(d, index);
|
14
14
|
return index;
|
15
15
|
}
|
16
|
-
export function getKey(gen, d, index) {
|
16
|
+
export function getKey(gen, d, index, ignoreError) {
|
17
17
|
var key = $getKey(gen, d, index);
|
18
|
-
if (typeof key !== 'string' && typeof key !== 'number') {
|
18
|
+
if (typeof key !== 'string' && typeof key !== 'number' && !ignoreError) {
|
19
19
|
console.error(new Error("keygen result expect a string or a number, get '".concat(_typeof(key), "'")));
|
20
20
|
}
|
21
21
|
return key;
|