@carefrees/form-utils-vue-hooks 0.0.13
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/README.md +7 -0
- package/esm/hooks/attr/attr.FormItem.d.ts +94 -0
- package/esm/hooks/attr/attr.FormItem.js +104 -0
- package/esm/hooks/index.d.ts +13 -0
- package/esm/hooks/index.js +13 -0
- package/esm/hooks/register/register.FormHideItem.d.ts +9 -0
- package/esm/hooks/register/register.FormHideItem.js +26 -0
- package/esm/hooks/register/register.FormItem.d.ts +24 -0
- package/esm/hooks/register/register.FormItem.js +67 -0
- package/esm/hooks/register/register.FormList.d.ts +9 -0
- package/esm/hooks/register/register.FormList.js +42 -0
- package/esm/hooks/register/register.form.d.ts +4 -0
- package/esm/hooks/register/register.form.js +10 -0
- package/esm/hooks/useAttrs.d.ts +25 -0
- package/esm/hooks/useAttrs.js +26 -0
- package/esm/hooks/useEffect.d.ts +2 -0
- package/esm/hooks/useEffect.js +12 -0
- package/esm/hooks/useForm.d.ts +8 -0
- package/esm/hooks/useForm.js +21 -0
- package/esm/hooks/useFormItem.d.ts +8 -0
- package/esm/hooks/useFormItem.js +21 -0
- package/esm/hooks/useFormItemParentName.d.ts +18 -0
- package/esm/hooks/useFormItemParentName.js +47 -0
- package/esm/hooks/useFormList.d.ts +8 -0
- package/esm/hooks/useFormList.js +21 -0
- package/esm/hooks/useHtmlFor.d.ts +2 -0
- package/esm/hooks/useHtmlFor.js +7 -0
- package/esm/hooks/useMultipleForm.d.ts +8 -0
- package/esm/hooks/useMultipleForm.js +21 -0
- package/esm/hooks/useRule.d.ts +4 -0
- package/esm/hooks/useRule.js +12 -0
- package/esm/index.d.ts +4 -0
- package/esm/index.js +4 -0
- package/esm/instance/formInstance.d.ts +58 -0
- package/esm/instance/formInstance.js +132 -0
- package/esm/instance/formItemBaseInstance.d.ts +23 -0
- package/esm/instance/formItemBaseInstance.js +6 -0
- package/esm/instance/formItemInstance.d.ts +18 -0
- package/esm/instance/formItemInstance.js +11 -0
- package/esm/instance/formListInstance.d.ts +43 -0
- package/esm/instance/formListInstance.js +95 -0
- package/esm/instance/index.d.ts +5 -0
- package/esm/instance/index.js +5 -0
- package/esm/instance/multipleInstance.d.ts +32 -0
- package/esm/instance/multipleInstance.js +77 -0
- package/esm/instance/ruleIntsnace.d.ts +45 -0
- package/esm/instance/ruleIntsnace.js +52 -0
- package/esm/interface/index.d.ts +31 -0
- package/esm/interface/index.js +0 -0
- package/esm/utils/cloneByNamePathList.d.ts +3 -0
- package/esm/utils/cloneByNamePathList.js +11 -0
- package/esm/utils/get.d.ts +26 -0
- package/esm/utils/get.js +13 -0
- package/esm/utils/index.d.ts +4 -0
- package/esm/utils/index.js +4 -0
- package/esm/utils/interface.d.ts +3 -0
- package/esm/utils/interface.js +0 -0
- package/esm/utils/set.d.ts +32 -0
- package/esm/utils/set.js +29 -0
- package/esm/utils/utils.d.ts +172 -0
- package/esm/utils/utils.js +131 -0
- package/lib/hooks/attr/attr.FormItem.d.ts +94 -0
- package/lib/hooks/attr/attr.FormItem.js +138 -0
- package/lib/hooks/index.d.ts +13 -0
- package/lib/hooks/index.js +168 -0
- package/lib/hooks/register/register.FormHideItem.d.ts +9 -0
- package/lib/hooks/register/register.FormHideItem.js +60 -0
- package/lib/hooks/register/register.FormItem.d.ts +24 -0
- package/lib/hooks/register/register.FormItem.js +101 -0
- package/lib/hooks/register/register.FormList.d.ts +9 -0
- package/lib/hooks/register/register.FormList.js +76 -0
- package/lib/hooks/register/register.form.d.ts +4 -0
- package/lib/hooks/register/register.form.js +44 -0
- package/lib/hooks/useAttrs.d.ts +25 -0
- package/lib/hooks/useAttrs.js +63 -0
- package/lib/hooks/useEffect.d.ts +2 -0
- package/lib/hooks/useEffect.js +46 -0
- package/lib/hooks/useForm.d.ts +8 -0
- package/lib/hooks/useForm.js +61 -0
- package/lib/hooks/useFormItem.d.ts +8 -0
- package/lib/hooks/useFormItem.js +61 -0
- package/lib/hooks/useFormItemParentName.d.ts +18 -0
- package/lib/hooks/useFormItemParentName.js +84 -0
- package/lib/hooks/useFormList.d.ts +8 -0
- package/lib/hooks/useFormList.js +61 -0
- package/lib/hooks/useHtmlFor.d.ts +2 -0
- package/lib/hooks/useHtmlFor.js +41 -0
- package/lib/hooks/useMultipleForm.d.ts +8 -0
- package/lib/hooks/useMultipleForm.js +61 -0
- package/lib/hooks/useRule.d.ts +4 -0
- package/lib/hooks/useRule.js +46 -0
- package/lib/index.d.ts +4 -0
- package/lib/index.js +87 -0
- package/lib/instance/formInstance.d.ts +58 -0
- package/lib/instance/formInstance.js +166 -0
- package/lib/instance/formItemBaseInstance.d.ts +23 -0
- package/lib/instance/formItemBaseInstance.js +40 -0
- package/lib/instance/formItemInstance.d.ts +18 -0
- package/lib/instance/formItemInstance.js +45 -0
- package/lib/instance/formListInstance.d.ts +43 -0
- package/lib/instance/formListInstance.js +129 -0
- package/lib/instance/index.d.ts +5 -0
- package/lib/instance/index.js +96 -0
- package/lib/instance/multipleInstance.d.ts +32 -0
- package/lib/instance/multipleInstance.js +111 -0
- package/lib/instance/ruleIntsnace.d.ts +45 -0
- package/lib/instance/ruleIntsnace.js +96 -0
- package/lib/interface/index.d.ts +31 -0
- package/lib/interface/index.js +18 -0
- package/lib/utils/cloneByNamePathList.d.ts +3 -0
- package/lib/utils/cloneByNamePathList.js +45 -0
- package/lib/utils/get.d.ts +26 -0
- package/lib/utils/get.js +47 -0
- package/lib/utils/index.d.ts +4 -0
- package/lib/utils/index.js +87 -0
- package/lib/utils/interface.d.ts +3 -0
- package/lib/utils/interface.js +18 -0
- package/lib/utils/set.d.ts +32 -0
- package/lib/utils/set.js +63 -0
- package/lib/utils/utils.d.ts +172 -0
- package/lib/utils/utils.js +198 -0
- package/package.json +30 -0
- package/src/hooks/attr/attr.FormItem.tsx +185 -0
- package/src/hooks/index.ts +13 -0
- package/src/hooks/register/register.FormHideItem.ts +28 -0
- package/src/hooks/register/register.FormItem.ts +93 -0
- package/src/hooks/register/register.FormList.ts +49 -0
- package/src/hooks/register/register.form.ts +13 -0
- package/src/hooks/useAttrs.ts +64 -0
- package/src/hooks/useEffect.ts +13 -0
- package/src/hooks/useForm.ts +34 -0
- package/src/hooks/useFormItem.ts +33 -0
- package/src/hooks/useFormItemParentName.ts +49 -0
- package/src/hooks/useFormList.ts +33 -0
- package/src/hooks/useHtmlFor.ts +9 -0
- package/src/hooks/useMultipleForm.ts +30 -0
- package/src/hooks/useRule.ts +16 -0
- package/src/index.ts +4 -0
- package/src/instance/formInstance.ts +220 -0
- package/src/instance/formItemBaseInstance.ts +23 -0
- package/src/instance/formItemInstance.ts +23 -0
- package/src/instance/formListInstance.ts +108 -0
- package/src/instance/index.ts +5 -0
- package/src/instance/multipleInstance.ts +109 -0
- package/src/instance/ruleIntsnace.ts +89 -0
- package/src/interface/index.ts +38 -0
- package/src/utils/cloneByNamePathList.ts +13 -0
- package/src/utils/get.ts +53 -0
- package/src/utils/index.ts +4 -0
- package/src/utils/interface.ts +4 -0
- package/src/utils/set.ts +85 -0
- package/src/utils/utils.ts +504 -0
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import async_validator from "async-validator";
|
|
2
|
+
import { ref, toValue } from "vue";
|
|
3
|
+
class RuleInstanceBase {
|
|
4
|
+
sort;
|
|
5
|
+
instance;
|
|
6
|
+
name = '';
|
|
7
|
+
rules = ref([]);
|
|
8
|
+
messages = ref([]);
|
|
9
|
+
isRequired = ()=>{
|
|
10
|
+
const findItem = (toValue(this.rules) || []).find((item)=>item?.required);
|
|
11
|
+
return !!findItem;
|
|
12
|
+
};
|
|
13
|
+
isValidate = ()=>{
|
|
14
|
+
const rules = toValue(this.rules);
|
|
15
|
+
return Array.isArray(rules) && rules.length;
|
|
16
|
+
};
|
|
17
|
+
updatedMessages = (messages)=>{
|
|
18
|
+
this.messages.value = messages;
|
|
19
|
+
};
|
|
20
|
+
updatedRules = (rules)=>{
|
|
21
|
+
this.rules.value = rules;
|
|
22
|
+
this.updatedMessages?.([]);
|
|
23
|
+
};
|
|
24
|
+
validate = ()=>new Promise((resolve, reject)=>{
|
|
25
|
+
const rules = toValue(this.rules);
|
|
26
|
+
const form = toValue(this.instance);
|
|
27
|
+
const value = form?.getFieldValue?.(this.name);
|
|
28
|
+
new async_validator({
|
|
29
|
+
[this.name]: rules || []
|
|
30
|
+
}).validate({
|
|
31
|
+
[this.name]: value
|
|
32
|
+
}).then((values)=>{
|
|
33
|
+
this.updatedMessages([]);
|
|
34
|
+
resolve(values);
|
|
35
|
+
}).catch(({ errors })=>{
|
|
36
|
+
if (Array.isArray(errors)) {
|
|
37
|
+
this.updatedMessages(errors);
|
|
38
|
+
reject(errors);
|
|
39
|
+
} else reject();
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
getValidateResult = ()=>{
|
|
43
|
+
const msg = toValue(this.messages);
|
|
44
|
+
const tip = Array.isArray(msg) ? msg.map((it)=>it.message) : '';
|
|
45
|
+
const isInvalid = Array.isArray(tip) ? !!tip.length : !!tip;
|
|
46
|
+
return {
|
|
47
|
+
tip,
|
|
48
|
+
isInvalid
|
|
49
|
+
};
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
export { RuleInstanceBase };
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { ComputedRef, Ref } from 'vue';
|
|
2
|
+
export interface MessageType {
|
|
3
|
+
/**信息*/
|
|
4
|
+
message?: string;
|
|
5
|
+
[s: string]: unknown;
|
|
6
|
+
}
|
|
7
|
+
export interface ErrorDataField {
|
|
8
|
+
/**字段*/
|
|
9
|
+
name: string;
|
|
10
|
+
/**排序*/
|
|
11
|
+
sort?: string;
|
|
12
|
+
/**错误信息*/
|
|
13
|
+
errors: MessageType[];
|
|
14
|
+
}
|
|
15
|
+
export interface ValidateErrorEntity<Values = any> {
|
|
16
|
+
values: Values;
|
|
17
|
+
/**错误信息*/
|
|
18
|
+
errorFields: ErrorDataField[];
|
|
19
|
+
}
|
|
20
|
+
export interface Callbacks<Values = any> {
|
|
21
|
+
/**值更新触发*/
|
|
22
|
+
onValuesChange?: (changedValues: any, values: Values) => void;
|
|
23
|
+
/**提交保存 验证成功*/
|
|
24
|
+
onFinish?: (values: Values) => void;
|
|
25
|
+
/**提交保存 验证失败*/
|
|
26
|
+
onFinishFailed?: (errorInfo: ValidateErrorEntity<Values>) => void;
|
|
27
|
+
}
|
|
28
|
+
export type ComputedRefBase<T> = ComputedRef<T> | Ref<T>;
|
|
29
|
+
export type PartialComputedRefs<T> = {
|
|
30
|
+
[K in keyof T]: ComputedRefBase<T[K]>;
|
|
31
|
+
};
|
|
File without changes
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { get } from "./get.js";
|
|
2
|
+
import { set } from "./set.js";
|
|
3
|
+
function cloneByNamePathList(store, namePathList) {
|
|
4
|
+
let newStore = {};
|
|
5
|
+
namePathList.forEach((namePath)=>{
|
|
6
|
+
const value = get(store, namePath);
|
|
7
|
+
newStore = set(newStore, namePath, value);
|
|
8
|
+
});
|
|
9
|
+
return newStore;
|
|
10
|
+
}
|
|
11
|
+
export { cloneByNamePathList };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { PropertyPath } from './interface';
|
|
2
|
+
/**
|
|
3
|
+
* Gets the value at `path` of `object`. If the resolved value is
|
|
4
|
+
* `undefined`, the `defaultValue` is returned in its place.
|
|
5
|
+
*
|
|
6
|
+
* @since 3.7.0
|
|
7
|
+
* @category Object
|
|
8
|
+
* @param {Object} object The object to query.
|
|
9
|
+
* @param {Array|string} path The path of the property to get.
|
|
10
|
+
* @param {*} [defaultValue] The value returned for `undefined` resolved values.
|
|
11
|
+
* @returns {*} Returns the resolved value.
|
|
12
|
+
* @see has, hasIn, set, unset
|
|
13
|
+
* @example
|
|
14
|
+
*
|
|
15
|
+
* const object = { 'a': [{ 'b': { 'c': 3 } }] }
|
|
16
|
+
*
|
|
17
|
+
* get(object, 'a[0].b.c')
|
|
18
|
+
* // => 3
|
|
19
|
+
*
|
|
20
|
+
* get(object, ['a', '0', 'b', 'c'])
|
|
21
|
+
* // => 3
|
|
22
|
+
*
|
|
23
|
+
* get(object, 'a.b.c', 'default')
|
|
24
|
+
* // => 'default'
|
|
25
|
+
*/
|
|
26
|
+
export declare const get: (object: Object, path: PropertyPath, defaultValue?: any) => any;
|
package/esm/utils/get.js
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { castPath, toKey } from "./utils.js";
|
|
2
|
+
function baseGet(object, path) {
|
|
3
|
+
path = castPath(path, object);
|
|
4
|
+
let index = 0;
|
|
5
|
+
const length = path.length;
|
|
6
|
+
while(null != object && index < length)object = object[toKey(path[index++])];
|
|
7
|
+
return index && index === length ? object : void 0;
|
|
8
|
+
}
|
|
9
|
+
const get = (object, path, defaultValue)=>{
|
|
10
|
+
const result = null == object ? void 0 : baseGet(object, path);
|
|
11
|
+
return void 0 === result ? defaultValue : result;
|
|
12
|
+
};
|
|
13
|
+
export { get };
|
|
File without changes
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description [从lodash中搬了部分需要的代码块](https://www.lodashjs.com/)
|
|
3
|
+
*/
|
|
4
|
+
import { PropertyPath } from './interface';
|
|
5
|
+
/**
|
|
6
|
+
* Sets the value at `path` of `object`. If a portion of `path` doesn't exist,
|
|
7
|
+
* it's created. Arrays are created for missing index properties while objects
|
|
8
|
+
* are created for all other missing properties. Use `setWith` to customize
|
|
9
|
+
* `path` creation.
|
|
10
|
+
*
|
|
11
|
+
* **Note:** This method mutates `object`.
|
|
12
|
+
*
|
|
13
|
+
* @since 3.7.0
|
|
14
|
+
* @category Object
|
|
15
|
+
* @param {Object} object The object to modify.
|
|
16
|
+
* @param {Array|string} path The path of the property to set.
|
|
17
|
+
* @param {*} value The value to set.
|
|
18
|
+
* @returns {Object} Returns `object`.
|
|
19
|
+
* @see has, hasIn, get, unset
|
|
20
|
+
* @example
|
|
21
|
+
*
|
|
22
|
+
* const object = { 'a': [{ 'b': { 'c': 3 } }] }
|
|
23
|
+
*
|
|
24
|
+
* set(object, 'a[0].b.c', 4)
|
|
25
|
+
* console.log(object.a[0].b.c)
|
|
26
|
+
* // => 4
|
|
27
|
+
*
|
|
28
|
+
* set(object, ['x', '0', 'y', 'z'], 5)
|
|
29
|
+
* console.log(object.x[0].y.z)
|
|
30
|
+
* // => 5
|
|
31
|
+
*/
|
|
32
|
+
export declare function set<T = any>(object: T, path: PropertyPath, value: any): T;
|
package/esm/utils/set.js
ADDED
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { assignValue, castPath, isIndex, isObject, toKey } from "./utils.js";
|
|
2
|
+
function baseSet(object, path, value, customizer) {
|
|
3
|
+
if (!isObject(object)) return object;
|
|
4
|
+
path = castPath(path, object);
|
|
5
|
+
const length = path.length;
|
|
6
|
+
const lastIndex = length - 1;
|
|
7
|
+
let index = -1;
|
|
8
|
+
let nested = object;
|
|
9
|
+
while(null != nested && ++index < length){
|
|
10
|
+
const key = toKey(path[index]);
|
|
11
|
+
let newValue = value;
|
|
12
|
+
if (index !== lastIndex) {
|
|
13
|
+
const objValue = nested[key];
|
|
14
|
+
newValue = customizer ? customizer(objValue, key, nested) : void 0;
|
|
15
|
+
if (void 0 === newValue) newValue = Array.isArray(objValue) ? [
|
|
16
|
+
...objValue
|
|
17
|
+
] : null !== objValue && '[object Object]' === Object.prototype.toString.call(objValue) ? {
|
|
18
|
+
...objValue
|
|
19
|
+
} : isObject(objValue) ? objValue : isIndex(path[index + 1]) ? [] : {};
|
|
20
|
+
}
|
|
21
|
+
assignValue(nested, key, newValue);
|
|
22
|
+
nested = nested[key];
|
|
23
|
+
}
|
|
24
|
+
return object;
|
|
25
|
+
}
|
|
26
|
+
function set(object, path, value) {
|
|
27
|
+
return null == object ? object : baseSet(object, path, value);
|
|
28
|
+
}
|
|
29
|
+
export { set };
|
|
@@ -0,0 +1,172 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @description [从lodash中搬了部分需要的代码块](https://www.lodashjs.com/)
|
|
3
|
+
*/
|
|
4
|
+
import { PropertyPath } from './interface';
|
|
5
|
+
/**
|
|
6
|
+
* Converts `string` to a property path array.
|
|
7
|
+
*
|
|
8
|
+
* @param {string} string The string to convert.
|
|
9
|
+
* @returns {Array} Returns the property path array.
|
|
10
|
+
*/
|
|
11
|
+
export declare const stringToPath: (string: string) => string[];
|
|
12
|
+
/**
|
|
13
|
+
* Gets the `toStringTag` of `value`.
|
|
14
|
+
*
|
|
15
|
+
* @private
|
|
16
|
+
* @param {*} value The value to query.
|
|
17
|
+
* @returns {string} Returns the `toStringTag`.
|
|
18
|
+
*/
|
|
19
|
+
export declare function getTag(value: any): string;
|
|
20
|
+
/**
|
|
21
|
+
* Checks if `value` is classified as a `Symbol` primitive or object.
|
|
22
|
+
*
|
|
23
|
+
* @since 4.0.0
|
|
24
|
+
* @category Lang
|
|
25
|
+
* @param {*} value The value to check.
|
|
26
|
+
* @returns {boolean} Returns `true` if `value` is a symbol, else `false`.
|
|
27
|
+
* @example
|
|
28
|
+
*
|
|
29
|
+
* isSymbol(Symbol.iterator)
|
|
30
|
+
* // => true
|
|
31
|
+
*
|
|
32
|
+
* isSymbol('abc')
|
|
33
|
+
* // => false
|
|
34
|
+
*/
|
|
35
|
+
export declare function isSymbol(value: any): boolean;
|
|
36
|
+
/**
|
|
37
|
+
* Checks if `value` is a property name and not a property path.
|
|
38
|
+
*
|
|
39
|
+
* @private
|
|
40
|
+
* @param {*} value The value to check.
|
|
41
|
+
* @param {Object} [object] The object to query keys on.
|
|
42
|
+
* @returns {boolean} Returns `true` if `value` is a property name, else `false`.
|
|
43
|
+
*/
|
|
44
|
+
export declare function isKey(value: any, object: any): boolean;
|
|
45
|
+
/**
|
|
46
|
+
* Casts `value` to a path array if it's not one.
|
|
47
|
+
*
|
|
48
|
+
* @private
|
|
49
|
+
* @param {*} value The value to inspect.
|
|
50
|
+
* @param {Object} [object] The object to query keys on.
|
|
51
|
+
* @returns {Array} Returns the cast property path array.
|
|
52
|
+
*/
|
|
53
|
+
export declare function castPath(value: any, object: any): any[];
|
|
54
|
+
/**
|
|
55
|
+
* Converts `value` to a string key if it's not a string or symbol.
|
|
56
|
+
*
|
|
57
|
+
* @private
|
|
58
|
+
* @param {*} value The value to inspect.
|
|
59
|
+
* @returns {string|symbol} Returns the key.
|
|
60
|
+
*/
|
|
61
|
+
export declare function toKey(value: any): any;
|
|
62
|
+
/**
|
|
63
|
+
* Checks if `value` is the
|
|
64
|
+
* [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types)
|
|
65
|
+
* of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`)
|
|
66
|
+
*
|
|
67
|
+
* @since 0.1.0
|
|
68
|
+
* @category Lang
|
|
69
|
+
* @param {*} value The value to check.
|
|
70
|
+
* @returns {boolean} Returns `true` if `value` is an object, else `false`.
|
|
71
|
+
* @example
|
|
72
|
+
*
|
|
73
|
+
* isObject({})
|
|
74
|
+
* // => true
|
|
75
|
+
*
|
|
76
|
+
* isObject([1, 2, 3])
|
|
77
|
+
* // => true
|
|
78
|
+
*
|
|
79
|
+
* isObject(Function)
|
|
80
|
+
* // => true
|
|
81
|
+
*
|
|
82
|
+
* isObject(null)
|
|
83
|
+
* // => false
|
|
84
|
+
*/
|
|
85
|
+
export declare function isObject(value: any): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Checks if `value` is a valid array-like index.
|
|
88
|
+
*
|
|
89
|
+
* @private
|
|
90
|
+
* @param {*} value The value to check.
|
|
91
|
+
* @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index.
|
|
92
|
+
* @returns {boolean} Returns `true` if `value` is a valid index, else `false`.
|
|
93
|
+
*/
|
|
94
|
+
export declare function isIndex(value: any, length?: number): boolean;
|
|
95
|
+
/**
|
|
96
|
+
* The base implementation of `assignValue` and `assignMergeValue` without
|
|
97
|
+
* value checks.
|
|
98
|
+
*
|
|
99
|
+
* @private
|
|
100
|
+
* @param {Object} object The object to modify.
|
|
101
|
+
* @param {string} key The key of the property to assign.
|
|
102
|
+
* @param {*} value The value to assign.
|
|
103
|
+
*/
|
|
104
|
+
export declare function baseAssignValue(object: any, key: any, value: any): void;
|
|
105
|
+
/**
|
|
106
|
+
* Performs a
|
|
107
|
+
* [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero)
|
|
108
|
+
* comparison between two values to determine if they are equivalent.
|
|
109
|
+
*
|
|
110
|
+
* @since 4.0.0
|
|
111
|
+
* @category Lang
|
|
112
|
+
* @param {*} value The value to compare.
|
|
113
|
+
* @param {*} other The other value to compare.
|
|
114
|
+
* @returns {boolean} Returns `true` if the values are equivalent, else `false`.
|
|
115
|
+
* @example
|
|
116
|
+
*
|
|
117
|
+
* const object = { 'a': 1 }
|
|
118
|
+
* const other = { 'a': 1 }
|
|
119
|
+
*
|
|
120
|
+
* eq(object, object)
|
|
121
|
+
* // => true
|
|
122
|
+
*
|
|
123
|
+
* eq(object, other)
|
|
124
|
+
* // => false
|
|
125
|
+
*
|
|
126
|
+
* eq('a', 'a')
|
|
127
|
+
* // => true
|
|
128
|
+
*
|
|
129
|
+
* eq('a', Object('a'))
|
|
130
|
+
* // => false
|
|
131
|
+
*
|
|
132
|
+
* eq(NaN, NaN)
|
|
133
|
+
* // => true
|
|
134
|
+
*/
|
|
135
|
+
export declare function eq(value: any, other: any): boolean;
|
|
136
|
+
/**
|
|
137
|
+
* Assigns `value` to `key` of `object` if the existing value is not equivalent.
|
|
138
|
+
*
|
|
139
|
+
* @private
|
|
140
|
+
* @param {Object} object The object to modify.
|
|
141
|
+
* @param {string} key The key of the property to assign.
|
|
142
|
+
* @param {*} value The value to assign.
|
|
143
|
+
*/
|
|
144
|
+
export declare function assignValue(object: any, key: any, value: any): void;
|
|
145
|
+
/**
|
|
146
|
+
* Checks if `path` is a direct property of `object`.
|
|
147
|
+
*
|
|
148
|
+
* @static
|
|
149
|
+
* @since 0.1.0
|
|
150
|
+
* @memberOf _
|
|
151
|
+
* @category Object
|
|
152
|
+
* @param {Object} object The object to query.
|
|
153
|
+
* @param {Array|string} path The path to check.
|
|
154
|
+
* @returns {boolean} Returns `true` if `path` exists, else `false`.
|
|
155
|
+
* @example
|
|
156
|
+
*
|
|
157
|
+
* var object = { 'a': { 'b': 2 } };
|
|
158
|
+
* var other = _.create({ 'a': _.create({ 'b': 2 }) });
|
|
159
|
+
*
|
|
160
|
+
* _.has(object, 'a');
|
|
161
|
+
* // => true
|
|
162
|
+
*
|
|
163
|
+
* _.has(object, 'a.b');
|
|
164
|
+
* // => true
|
|
165
|
+
*
|
|
166
|
+
* _.has(object, ['a', 'b']);
|
|
167
|
+
* // => true
|
|
168
|
+
*
|
|
169
|
+
* _.has(other, 'a');
|
|
170
|
+
* // => false
|
|
171
|
+
*/
|
|
172
|
+
export declare function has<T = any>(object: T, path: PropertyPath): boolean;
|
|
@@ -0,0 +1,131 @@
|
|
|
1
|
+
const charCodeOfDot = '.'.charCodeAt(0);
|
|
2
|
+
const reEscapeChar = /\\(\\)?/g;
|
|
3
|
+
const rePropName = RegExp("[^.[\\]]+|\\[(?:([^\"'][^[]*)|([\"'])((?:(?!\\2)[^\\\\]|\\\\.)*?)\\2)\\]|(?=(?:\\.|\\[\\])(?:\\.|\\[\\]|$))", 'g');
|
|
4
|
+
const stringToPath = (string)=>{
|
|
5
|
+
const result = [];
|
|
6
|
+
if (string.charCodeAt(0) === charCodeOfDot) result.push('');
|
|
7
|
+
string.replace(rePropName, (match, expression, quote, subString)=>{
|
|
8
|
+
let key = match;
|
|
9
|
+
if (quote) key = subString.replace(reEscapeChar, '$1');
|
|
10
|
+
else if (expression) key = expression.trim();
|
|
11
|
+
result.push(key);
|
|
12
|
+
});
|
|
13
|
+
return result;
|
|
14
|
+
};
|
|
15
|
+
function getTag(value) {
|
|
16
|
+
const toString = Object.prototype.toString;
|
|
17
|
+
if (null == value) return void 0 === value ? '[object Undefined]' : '[object Null]';
|
|
18
|
+
return toString.call(value);
|
|
19
|
+
}
|
|
20
|
+
function isSymbol(value) {
|
|
21
|
+
const type = typeof value;
|
|
22
|
+
return 'symbol' === type || 'object' === type && null != value && '[object Symbol]' === getTag(value);
|
|
23
|
+
}
|
|
24
|
+
const reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/;
|
|
25
|
+
const reIsPlainProp = /^\w*$/;
|
|
26
|
+
function isKey(value, object) {
|
|
27
|
+
if (Array.isArray(value)) return false;
|
|
28
|
+
const type = typeof value;
|
|
29
|
+
if ('number' === type || 'boolean' === type || null == value || isSymbol(value)) return true;
|
|
30
|
+
return reIsPlainProp.test(value) || !reIsDeepProp.test(value) || null != object && value in Object(object);
|
|
31
|
+
}
|
|
32
|
+
function castPath(value, object) {
|
|
33
|
+
if (Array.isArray(value)) return value;
|
|
34
|
+
return isKey(value, object) ? [
|
|
35
|
+
value
|
|
36
|
+
] : stringToPath(value);
|
|
37
|
+
}
|
|
38
|
+
const INFINITY = 1 / 0;
|
|
39
|
+
function toKey(value) {
|
|
40
|
+
if ('string' == typeof value || isSymbol(value)) return value;
|
|
41
|
+
const result = `${value}`;
|
|
42
|
+
return '0' === result && 1 / value === -INFINITY ? '-0' : result;
|
|
43
|
+
}
|
|
44
|
+
function isObject(value) {
|
|
45
|
+
const type = typeof value;
|
|
46
|
+
return null != value && ('object' === type || 'function' === type);
|
|
47
|
+
}
|
|
48
|
+
const MAX_SAFE_INTEGER = 9007199254740991;
|
|
49
|
+
const reIsUint = /^(?:0|[1-9]\d*)$/;
|
|
50
|
+
function isIndex(value, length) {
|
|
51
|
+
const type = typeof value;
|
|
52
|
+
length = null == length ? MAX_SAFE_INTEGER : length;
|
|
53
|
+
return !!length && ('number' === type || 'symbol' !== type && reIsUint.test(value)) && value > -1 && value % 1 === 0 && value < length;
|
|
54
|
+
}
|
|
55
|
+
function baseAssignValue(object, key, value) {
|
|
56
|
+
if ('__proto__' === key) Object.defineProperty(object, key, {
|
|
57
|
+
configurable: true,
|
|
58
|
+
enumerable: true,
|
|
59
|
+
value: value,
|
|
60
|
+
writable: true
|
|
61
|
+
});
|
|
62
|
+
else object[key] = value;
|
|
63
|
+
}
|
|
64
|
+
function eq(value, other) {
|
|
65
|
+
return value === other || value !== value && other !== other;
|
|
66
|
+
}
|
|
67
|
+
const utils_hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
68
|
+
function assignValue(object, key, value) {
|
|
69
|
+
const objValue = object[key];
|
|
70
|
+
if (utils_hasOwnProperty.call(object, key) && eq(objValue, value)) {
|
|
71
|
+
if (void 0 === value && !(key in object)) baseAssignValue(object, key, value);
|
|
72
|
+
} else if (0 !== value || 1 / value === 1 / objValue) baseAssignValue(object, key, value);
|
|
73
|
+
}
|
|
74
|
+
function baseHas(object, key) {
|
|
75
|
+
return null != object && utils_hasOwnProperty.call(object, key);
|
|
76
|
+
}
|
|
77
|
+
function isLength(value) {
|
|
78
|
+
return 'number' == typeof value && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
|
|
79
|
+
}
|
|
80
|
+
function isObjectLike(value) {
|
|
81
|
+
return null != value && 'object' == typeof value;
|
|
82
|
+
}
|
|
83
|
+
var objectProto = Object.prototype;
|
|
84
|
+
var nativeObjectToString = objectProto.toString;
|
|
85
|
+
var symToStringTag = Symbol ? Symbol.toStringTag : void 0;
|
|
86
|
+
function getRawTag(value) {
|
|
87
|
+
var isOwn = utils_hasOwnProperty.call(value, symToStringTag), tag = value[symToStringTag];
|
|
88
|
+
try {
|
|
89
|
+
value[symToStringTag] = void 0;
|
|
90
|
+
var unmasked = true;
|
|
91
|
+
} catch (e) {}
|
|
92
|
+
var result = nativeObjectToString.call(value);
|
|
93
|
+
if (unmasked) if (isOwn) value[symToStringTag] = tag;
|
|
94
|
+
else delete value[symToStringTag];
|
|
95
|
+
return result;
|
|
96
|
+
}
|
|
97
|
+
var nativeObjectToString = objectProto.toString;
|
|
98
|
+
function objectToString(value) {
|
|
99
|
+
return nativeObjectToString.call(value);
|
|
100
|
+
}
|
|
101
|
+
var nullTag = '[object Null]', undefinedTag = '[object Undefined]';
|
|
102
|
+
function baseGetTag(value) {
|
|
103
|
+
if (null == value) return void 0 === value ? undefinedTag : nullTag;
|
|
104
|
+
return symToStringTag && symToStringTag in Object(value) ? getRawTag(value) : objectToString(value);
|
|
105
|
+
}
|
|
106
|
+
var argsTag = '[object Arguments]';
|
|
107
|
+
function baseIsArguments(value) {
|
|
108
|
+
return isObjectLike(value) && baseGetTag(value) == argsTag;
|
|
109
|
+
}
|
|
110
|
+
const propertyIsEnumerable = objectProto.propertyIsEnumerable;
|
|
111
|
+
var isArguments = baseIsArguments(function() {
|
|
112
|
+
return arguments;
|
|
113
|
+
}()) ? baseIsArguments : function(value) {
|
|
114
|
+
return isObjectLike(value) && utils_hasOwnProperty.call(value, 'callee') && !propertyIsEnumerable.call(value, 'callee');
|
|
115
|
+
};
|
|
116
|
+
function hasPath(object, path, hasFunc) {
|
|
117
|
+
path = castPath(path, object);
|
|
118
|
+
var index = -1, length = path.length, result = false;
|
|
119
|
+
while(++index < length){
|
|
120
|
+
var key = toKey(path[index]);
|
|
121
|
+
if (!(result = null != object && hasFunc(object, key))) break;
|
|
122
|
+
object = object[key];
|
|
123
|
+
}
|
|
124
|
+
if (result || ++index != length) return result;
|
|
125
|
+
length = null == object ? 0 : object.length;
|
|
126
|
+
return !!length && isLength(length) && isIndex(key, length) && (Array.isArray(object) || isArguments(object));
|
|
127
|
+
}
|
|
128
|
+
function has(object, path) {
|
|
129
|
+
return null != object && hasPath(object, path, baseHas);
|
|
130
|
+
}
|
|
131
|
+
export { assignValue, baseAssignValue, castPath, eq, getTag, has, isIndex, isKey, isObject, isSymbol, stringToPath, toKey };
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
import { FormInstanceBase } from '../../instance/formInstance';
|
|
2
|
+
import { FormItemInstanceBase } from '../../instance/formItemInstance';
|
|
3
|
+
import { RegisterFormItemOptions } from './../register/register.FormItem';
|
|
4
|
+
import { Ref } from 'vue';
|
|
5
|
+
import type { RuleInstanceBase } from '../../instance/ruleIntsnace';
|
|
6
|
+
export interface FormItemAttrOptions extends RegisterFormItemOptions {
|
|
7
|
+
/**依赖更新项*/
|
|
8
|
+
dependencies?: string[];
|
|
9
|
+
/**通知 只用于校验规则提示 字段 */
|
|
10
|
+
noticeOnlyRuleDataField?: string[];
|
|
11
|
+
/**是否保护值(不进行表单项组件卸载重置初始值)*/
|
|
12
|
+
preserve?: boolean;
|
|
13
|
+
/**重写规则*/
|
|
14
|
+
useRules?: (ruleInstance: Ref<RuleInstanceBase>, form: Ref<FormInstanceBase>, formItemInstance: Ref<FormItemInstanceBase>) => void;
|
|
15
|
+
/**输入框属性重写*/
|
|
16
|
+
useAttrs?: (attrs: any, form: Ref<FormInstanceBase>, formItemInstance: Ref<FormItemInstanceBase>) => any;
|
|
17
|
+
/**输入框属性*/
|
|
18
|
+
inputAttrs?: Object;
|
|
19
|
+
/**传递组件字段*/
|
|
20
|
+
valuePropName?: string;
|
|
21
|
+
/**取值字段(默认和valuePropName值相同)*/
|
|
22
|
+
getValuePath?: string;
|
|
23
|
+
/**自定义获取值*/
|
|
24
|
+
getValueFromEvent?: (event: any, form: Ref<FormInstanceBase>, formItemInstance: Ref<FormItemInstanceBase>) => any;
|
|
25
|
+
/**值格式化*/
|
|
26
|
+
formatValue?: (value: any, form: Ref<FormInstanceBase>, formItemInstance: Ref<FormItemInstanceBase>, event: any) => any;
|
|
27
|
+
/**触发数据更新之后触发(用于数据联动之类的)*/
|
|
28
|
+
onAfterUpdate?: (value: any, form: Ref<FormInstanceBase>, formItemInstance: Ref<FormItemInstanceBase>, event: any) => void;
|
|
29
|
+
/**事件名称*/
|
|
30
|
+
trigger?: string;
|
|
31
|
+
}
|
|
32
|
+
/**表单项参数*/
|
|
33
|
+
export declare const useFormItemAttr: (options: FormItemAttrOptions) => {
|
|
34
|
+
valuePropName: string;
|
|
35
|
+
htmlFor: import("vue").ComputedRef<string>;
|
|
36
|
+
onChange: (event: any) => void;
|
|
37
|
+
formItemInstance: Ref<FormItemInstanceBase, FormItemInstanceBase>;
|
|
38
|
+
form: Ref<FormInstanceBase<any>, FormInstanceBase<any>>;
|
|
39
|
+
ruleInstance: Ref<RuleInstanceBase, RuleInstanceBase>;
|
|
40
|
+
newAttrs: import("vue").ComputedRef<{
|
|
41
|
+
name: string;
|
|
42
|
+
id: string;
|
|
43
|
+
constructor: Function;
|
|
44
|
+
toString(): string;
|
|
45
|
+
toLocaleString(): string;
|
|
46
|
+
valueOf(): Object;
|
|
47
|
+
hasOwnProperty(v: PropertyKey): boolean;
|
|
48
|
+
isPrototypeOf(v: Object): boolean;
|
|
49
|
+
propertyIsEnumerable(v: PropertyKey): boolean;
|
|
50
|
+
}>;
|
|
51
|
+
attrsLastData: Ref<{
|
|
52
|
+
name: string;
|
|
53
|
+
id: string;
|
|
54
|
+
constructor: Function;
|
|
55
|
+
toString: () => string;
|
|
56
|
+
toLocaleString: () => string;
|
|
57
|
+
valueOf: () => Object;
|
|
58
|
+
hasOwnProperty: (v: PropertyKey) => boolean;
|
|
59
|
+
isPrototypeOf: (v: Object) => boolean;
|
|
60
|
+
propertyIsEnumerable: (v: PropertyKey) => boolean;
|
|
61
|
+
}, {
|
|
62
|
+
name: string;
|
|
63
|
+
id: string;
|
|
64
|
+
constructor: Function;
|
|
65
|
+
toString(): string;
|
|
66
|
+
toLocaleString(): string;
|
|
67
|
+
valueOf(): Object;
|
|
68
|
+
hasOwnProperty(v: PropertyKey): boolean;
|
|
69
|
+
isPrototypeOf(v: Object): boolean;
|
|
70
|
+
propertyIsEnumerable(v: PropertyKey): boolean;
|
|
71
|
+
} | {
|
|
72
|
+
name: string;
|
|
73
|
+
id: string;
|
|
74
|
+
constructor: Function;
|
|
75
|
+
toString: () => string;
|
|
76
|
+
toLocaleString: () => string;
|
|
77
|
+
valueOf: () => Object;
|
|
78
|
+
hasOwnProperty: (v: PropertyKey) => boolean;
|
|
79
|
+
isPrototypeOf: (v: Object) => boolean;
|
|
80
|
+
propertyIsEnumerable: (v: PropertyKey) => boolean;
|
|
81
|
+
}>;
|
|
82
|
+
validateResult: Ref<{
|
|
83
|
+
tip: string | (string | undefined)[];
|
|
84
|
+
isInvalid: boolean;
|
|
85
|
+
}, {
|
|
86
|
+
tip: string | (string | undefined)[];
|
|
87
|
+
isInvalid: boolean;
|
|
88
|
+
} | {
|
|
89
|
+
tip: string | (string | undefined)[];
|
|
90
|
+
isInvalid: boolean;
|
|
91
|
+
}>;
|
|
92
|
+
newSort: import("vue").ComputedRef<string>;
|
|
93
|
+
newName: import("vue").ComputedRef<string>;
|
|
94
|
+
};
|