@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.
Files changed (152) hide show
  1. package/README.md +7 -0
  2. package/esm/hooks/attr/attr.FormItem.d.ts +94 -0
  3. package/esm/hooks/attr/attr.FormItem.js +104 -0
  4. package/esm/hooks/index.d.ts +13 -0
  5. package/esm/hooks/index.js +13 -0
  6. package/esm/hooks/register/register.FormHideItem.d.ts +9 -0
  7. package/esm/hooks/register/register.FormHideItem.js +26 -0
  8. package/esm/hooks/register/register.FormItem.d.ts +24 -0
  9. package/esm/hooks/register/register.FormItem.js +67 -0
  10. package/esm/hooks/register/register.FormList.d.ts +9 -0
  11. package/esm/hooks/register/register.FormList.js +42 -0
  12. package/esm/hooks/register/register.form.d.ts +4 -0
  13. package/esm/hooks/register/register.form.js +10 -0
  14. package/esm/hooks/useAttrs.d.ts +25 -0
  15. package/esm/hooks/useAttrs.js +26 -0
  16. package/esm/hooks/useEffect.d.ts +2 -0
  17. package/esm/hooks/useEffect.js +12 -0
  18. package/esm/hooks/useForm.d.ts +8 -0
  19. package/esm/hooks/useForm.js +21 -0
  20. package/esm/hooks/useFormItem.d.ts +8 -0
  21. package/esm/hooks/useFormItem.js +21 -0
  22. package/esm/hooks/useFormItemParentName.d.ts +18 -0
  23. package/esm/hooks/useFormItemParentName.js +47 -0
  24. package/esm/hooks/useFormList.d.ts +8 -0
  25. package/esm/hooks/useFormList.js +21 -0
  26. package/esm/hooks/useHtmlFor.d.ts +2 -0
  27. package/esm/hooks/useHtmlFor.js +7 -0
  28. package/esm/hooks/useMultipleForm.d.ts +8 -0
  29. package/esm/hooks/useMultipleForm.js +21 -0
  30. package/esm/hooks/useRule.d.ts +4 -0
  31. package/esm/hooks/useRule.js +12 -0
  32. package/esm/index.d.ts +4 -0
  33. package/esm/index.js +4 -0
  34. package/esm/instance/formInstance.d.ts +58 -0
  35. package/esm/instance/formInstance.js +132 -0
  36. package/esm/instance/formItemBaseInstance.d.ts +23 -0
  37. package/esm/instance/formItemBaseInstance.js +6 -0
  38. package/esm/instance/formItemInstance.d.ts +18 -0
  39. package/esm/instance/formItemInstance.js +11 -0
  40. package/esm/instance/formListInstance.d.ts +43 -0
  41. package/esm/instance/formListInstance.js +95 -0
  42. package/esm/instance/index.d.ts +5 -0
  43. package/esm/instance/index.js +5 -0
  44. package/esm/instance/multipleInstance.d.ts +32 -0
  45. package/esm/instance/multipleInstance.js +77 -0
  46. package/esm/instance/ruleIntsnace.d.ts +45 -0
  47. package/esm/instance/ruleIntsnace.js +52 -0
  48. package/esm/interface/index.d.ts +31 -0
  49. package/esm/interface/index.js +0 -0
  50. package/esm/utils/cloneByNamePathList.d.ts +3 -0
  51. package/esm/utils/cloneByNamePathList.js +11 -0
  52. package/esm/utils/get.d.ts +26 -0
  53. package/esm/utils/get.js +13 -0
  54. package/esm/utils/index.d.ts +4 -0
  55. package/esm/utils/index.js +4 -0
  56. package/esm/utils/interface.d.ts +3 -0
  57. package/esm/utils/interface.js +0 -0
  58. package/esm/utils/set.d.ts +32 -0
  59. package/esm/utils/set.js +29 -0
  60. package/esm/utils/utils.d.ts +172 -0
  61. package/esm/utils/utils.js +131 -0
  62. package/lib/hooks/attr/attr.FormItem.d.ts +94 -0
  63. package/lib/hooks/attr/attr.FormItem.js +138 -0
  64. package/lib/hooks/index.d.ts +13 -0
  65. package/lib/hooks/index.js +168 -0
  66. package/lib/hooks/register/register.FormHideItem.d.ts +9 -0
  67. package/lib/hooks/register/register.FormHideItem.js +60 -0
  68. package/lib/hooks/register/register.FormItem.d.ts +24 -0
  69. package/lib/hooks/register/register.FormItem.js +101 -0
  70. package/lib/hooks/register/register.FormList.d.ts +9 -0
  71. package/lib/hooks/register/register.FormList.js +76 -0
  72. package/lib/hooks/register/register.form.d.ts +4 -0
  73. package/lib/hooks/register/register.form.js +44 -0
  74. package/lib/hooks/useAttrs.d.ts +25 -0
  75. package/lib/hooks/useAttrs.js +63 -0
  76. package/lib/hooks/useEffect.d.ts +2 -0
  77. package/lib/hooks/useEffect.js +46 -0
  78. package/lib/hooks/useForm.d.ts +8 -0
  79. package/lib/hooks/useForm.js +61 -0
  80. package/lib/hooks/useFormItem.d.ts +8 -0
  81. package/lib/hooks/useFormItem.js +61 -0
  82. package/lib/hooks/useFormItemParentName.d.ts +18 -0
  83. package/lib/hooks/useFormItemParentName.js +84 -0
  84. package/lib/hooks/useFormList.d.ts +8 -0
  85. package/lib/hooks/useFormList.js +61 -0
  86. package/lib/hooks/useHtmlFor.d.ts +2 -0
  87. package/lib/hooks/useHtmlFor.js +41 -0
  88. package/lib/hooks/useMultipleForm.d.ts +8 -0
  89. package/lib/hooks/useMultipleForm.js +61 -0
  90. package/lib/hooks/useRule.d.ts +4 -0
  91. package/lib/hooks/useRule.js +46 -0
  92. package/lib/index.d.ts +4 -0
  93. package/lib/index.js +87 -0
  94. package/lib/instance/formInstance.d.ts +58 -0
  95. package/lib/instance/formInstance.js +166 -0
  96. package/lib/instance/formItemBaseInstance.d.ts +23 -0
  97. package/lib/instance/formItemBaseInstance.js +40 -0
  98. package/lib/instance/formItemInstance.d.ts +18 -0
  99. package/lib/instance/formItemInstance.js +45 -0
  100. package/lib/instance/formListInstance.d.ts +43 -0
  101. package/lib/instance/formListInstance.js +129 -0
  102. package/lib/instance/index.d.ts +5 -0
  103. package/lib/instance/index.js +96 -0
  104. package/lib/instance/multipleInstance.d.ts +32 -0
  105. package/lib/instance/multipleInstance.js +111 -0
  106. package/lib/instance/ruleIntsnace.d.ts +45 -0
  107. package/lib/instance/ruleIntsnace.js +96 -0
  108. package/lib/interface/index.d.ts +31 -0
  109. package/lib/interface/index.js +18 -0
  110. package/lib/utils/cloneByNamePathList.d.ts +3 -0
  111. package/lib/utils/cloneByNamePathList.js +45 -0
  112. package/lib/utils/get.d.ts +26 -0
  113. package/lib/utils/get.js +47 -0
  114. package/lib/utils/index.d.ts +4 -0
  115. package/lib/utils/index.js +87 -0
  116. package/lib/utils/interface.d.ts +3 -0
  117. package/lib/utils/interface.js +18 -0
  118. package/lib/utils/set.d.ts +32 -0
  119. package/lib/utils/set.js +63 -0
  120. package/lib/utils/utils.d.ts +172 -0
  121. package/lib/utils/utils.js +198 -0
  122. package/package.json +30 -0
  123. package/src/hooks/attr/attr.FormItem.tsx +185 -0
  124. package/src/hooks/index.ts +13 -0
  125. package/src/hooks/register/register.FormHideItem.ts +28 -0
  126. package/src/hooks/register/register.FormItem.ts +93 -0
  127. package/src/hooks/register/register.FormList.ts +49 -0
  128. package/src/hooks/register/register.form.ts +13 -0
  129. package/src/hooks/useAttrs.ts +64 -0
  130. package/src/hooks/useEffect.ts +13 -0
  131. package/src/hooks/useForm.ts +34 -0
  132. package/src/hooks/useFormItem.ts +33 -0
  133. package/src/hooks/useFormItemParentName.ts +49 -0
  134. package/src/hooks/useFormList.ts +33 -0
  135. package/src/hooks/useHtmlFor.ts +9 -0
  136. package/src/hooks/useMultipleForm.ts +30 -0
  137. package/src/hooks/useRule.ts +16 -0
  138. package/src/index.ts +4 -0
  139. package/src/instance/formInstance.ts +220 -0
  140. package/src/instance/formItemBaseInstance.ts +23 -0
  141. package/src/instance/formItemInstance.ts +23 -0
  142. package/src/instance/formListInstance.ts +108 -0
  143. package/src/instance/index.ts +5 -0
  144. package/src/instance/multipleInstance.ts +109 -0
  145. package/src/instance/ruleIntsnace.ts +89 -0
  146. package/src/interface/index.ts +38 -0
  147. package/src/utils/cloneByNamePathList.ts +13 -0
  148. package/src/utils/get.ts +53 -0
  149. package/src/utils/index.ts +4 -0
  150. package/src/utils/interface.ts +4 -0
  151. package/src/utils/set.ts +85 -0
  152. package/src/utils/utils.ts +504 -0
@@ -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;
@@ -0,0 +1,63 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ set: ()=>set
28
+ });
29
+ const external_utils_js_namespaceObject = require("./utils.js");
30
+ function baseSet(object, path, value, customizer) {
31
+ if (!(0, external_utils_js_namespaceObject.isObject)(object)) return object;
32
+ path = (0, external_utils_js_namespaceObject.castPath)(path, object);
33
+ const length = path.length;
34
+ const lastIndex = length - 1;
35
+ let index = -1;
36
+ let nested = object;
37
+ while(null != nested && ++index < length){
38
+ const key = (0, external_utils_js_namespaceObject.toKey)(path[index]);
39
+ let newValue = value;
40
+ if (index !== lastIndex) {
41
+ const objValue = nested[key];
42
+ newValue = customizer ? customizer(objValue, key, nested) : void 0;
43
+ if (void 0 === newValue) newValue = Array.isArray(objValue) ? [
44
+ ...objValue
45
+ ] : null !== objValue && '[object Object]' === Object.prototype.toString.call(objValue) ? {
46
+ ...objValue
47
+ } : (0, external_utils_js_namespaceObject.isObject)(objValue) ? objValue : (0, external_utils_js_namespaceObject.isIndex)(path[index + 1]) ? [] : {};
48
+ }
49
+ (0, external_utils_js_namespaceObject.assignValue)(nested, key, newValue);
50
+ nested = nested[key];
51
+ }
52
+ return object;
53
+ }
54
+ function set(object, path, value) {
55
+ return null == object ? object : baseSet(object, path, value);
56
+ }
57
+ exports.set = __webpack_exports__.set;
58
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
59
+ "set"
60
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
61
+ Object.defineProperty(exports, '__esModule', {
62
+ value: true
63
+ });
@@ -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,198 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.d = (exports1, definition)=>{
5
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
6
+ enumerable: true,
7
+ get: definition[key]
8
+ });
9
+ };
10
+ })();
11
+ (()=>{
12
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
13
+ })();
14
+ (()=>{
15
+ __webpack_require__.r = (exports1)=>{
16
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
17
+ value: 'Module'
18
+ });
19
+ Object.defineProperty(exports1, '__esModule', {
20
+ value: true
21
+ });
22
+ };
23
+ })();
24
+ var __webpack_exports__ = {};
25
+ __webpack_require__.r(__webpack_exports__);
26
+ __webpack_require__.d(__webpack_exports__, {
27
+ assignValue: ()=>assignValue,
28
+ baseAssignValue: ()=>baseAssignValue,
29
+ castPath: ()=>castPath,
30
+ eq: ()=>eq,
31
+ getTag: ()=>getTag,
32
+ has: ()=>has,
33
+ isIndex: ()=>isIndex,
34
+ isKey: ()=>isKey,
35
+ isObject: ()=>isObject,
36
+ isSymbol: ()=>isSymbol,
37
+ stringToPath: ()=>stringToPath,
38
+ toKey: ()=>toKey
39
+ });
40
+ const charCodeOfDot = '.'.charCodeAt(0);
41
+ const reEscapeChar = /\\(\\)?/g;
42
+ const rePropName = RegExp("[^.[\\]]+|\\[(?:([^\"'][^[]*)|([\"'])((?:(?!\\2)[^\\\\]|\\\\.)*?)\\2)\\]|(?=(?:\\.|\\[\\])(?:\\.|\\[\\]|$))", 'g');
43
+ const stringToPath = (string)=>{
44
+ const result = [];
45
+ if (string.charCodeAt(0) === charCodeOfDot) result.push('');
46
+ string.replace(rePropName, (match, expression, quote, subString)=>{
47
+ let key = match;
48
+ if (quote) key = subString.replace(reEscapeChar, '$1');
49
+ else if (expression) key = expression.trim();
50
+ result.push(key);
51
+ });
52
+ return result;
53
+ };
54
+ function getTag(value) {
55
+ const toString = Object.prototype.toString;
56
+ if (null == value) return void 0 === value ? '[object Undefined]' : '[object Null]';
57
+ return toString.call(value);
58
+ }
59
+ function isSymbol(value) {
60
+ const type = typeof value;
61
+ return 'symbol' === type || 'object' === type && null != value && '[object Symbol]' === getTag(value);
62
+ }
63
+ const reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/;
64
+ const reIsPlainProp = /^\w*$/;
65
+ function isKey(value, object) {
66
+ if (Array.isArray(value)) return false;
67
+ const type = typeof value;
68
+ if ('number' === type || 'boolean' === type || null == value || isSymbol(value)) return true;
69
+ return reIsPlainProp.test(value) || !reIsDeepProp.test(value) || null != object && value in Object(object);
70
+ }
71
+ function castPath(value, object) {
72
+ if (Array.isArray(value)) return value;
73
+ return isKey(value, object) ? [
74
+ value
75
+ ] : stringToPath(value);
76
+ }
77
+ const INFINITY = 1 / 0;
78
+ function toKey(value) {
79
+ if ('string' == typeof value || isSymbol(value)) return value;
80
+ const result = `${value}`;
81
+ return '0' === result && 1 / value === -INFINITY ? '-0' : result;
82
+ }
83
+ function isObject(value) {
84
+ const type = typeof value;
85
+ return null != value && ('object' === type || 'function' === type);
86
+ }
87
+ const MAX_SAFE_INTEGER = 9007199254740991;
88
+ const reIsUint = /^(?:0|[1-9]\d*)$/;
89
+ function isIndex(value, length) {
90
+ const type = typeof value;
91
+ length = null == length ? MAX_SAFE_INTEGER : length;
92
+ return !!length && ('number' === type || 'symbol' !== type && reIsUint.test(value)) && value > -1 && value % 1 === 0 && value < length;
93
+ }
94
+ function baseAssignValue(object, key, value) {
95
+ if ('__proto__' === key) Object.defineProperty(object, key, {
96
+ configurable: true,
97
+ enumerable: true,
98
+ value: value,
99
+ writable: true
100
+ });
101
+ else object[key] = value;
102
+ }
103
+ function eq(value, other) {
104
+ return value === other || value !== value && other !== other;
105
+ }
106
+ const hasOwnProperty = Object.prototype.hasOwnProperty;
107
+ function assignValue(object, key, value) {
108
+ const objValue = object[key];
109
+ if (hasOwnProperty.call(object, key) && eq(objValue, value)) {
110
+ if (void 0 === value && !(key in object)) baseAssignValue(object, key, value);
111
+ } else if (0 !== value || 1 / value === 1 / objValue) baseAssignValue(object, key, value);
112
+ }
113
+ function baseHas(object, key) {
114
+ return null != object && hasOwnProperty.call(object, key);
115
+ }
116
+ function isLength(value) {
117
+ return 'number' == typeof value && value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER;
118
+ }
119
+ function isObjectLike(value) {
120
+ return null != value && 'object' == typeof value;
121
+ }
122
+ var objectProto = Object.prototype;
123
+ var nativeObjectToString = objectProto.toString;
124
+ var symToStringTag = Symbol ? Symbol.toStringTag : void 0;
125
+ function getRawTag(value) {
126
+ var isOwn = hasOwnProperty.call(value, symToStringTag), tag = value[symToStringTag];
127
+ try {
128
+ value[symToStringTag] = void 0;
129
+ var unmasked = true;
130
+ } catch (e) {}
131
+ var result = nativeObjectToString.call(value);
132
+ if (unmasked) if (isOwn) value[symToStringTag] = tag;
133
+ else delete value[symToStringTag];
134
+ return result;
135
+ }
136
+ var nativeObjectToString = objectProto.toString;
137
+ function objectToString(value) {
138
+ return nativeObjectToString.call(value);
139
+ }
140
+ var nullTag = '[object Null]', undefinedTag = '[object Undefined]';
141
+ function baseGetTag(value) {
142
+ if (null == value) return void 0 === value ? undefinedTag : nullTag;
143
+ return symToStringTag && symToStringTag in Object(value) ? getRawTag(value) : objectToString(value);
144
+ }
145
+ var argsTag = '[object Arguments]';
146
+ function baseIsArguments(value) {
147
+ return isObjectLike(value) && baseGetTag(value) == argsTag;
148
+ }
149
+ const propertyIsEnumerable = objectProto.propertyIsEnumerable;
150
+ var isArguments = baseIsArguments(function() {
151
+ return arguments;
152
+ }()) ? baseIsArguments : function(value) {
153
+ return isObjectLike(value) && hasOwnProperty.call(value, 'callee') && !propertyIsEnumerable.call(value, 'callee');
154
+ };
155
+ function hasPath(object, path, hasFunc) {
156
+ path = castPath(path, object);
157
+ var index = -1, length = path.length, result = false;
158
+ while(++index < length){
159
+ var key = toKey(path[index]);
160
+ if (!(result = null != object && hasFunc(object, key))) break;
161
+ object = object[key];
162
+ }
163
+ if (result || ++index != length) return result;
164
+ length = null == object ? 0 : object.length;
165
+ return !!length && isLength(length) && isIndex(key, length) && (Array.isArray(object) || isArguments(object));
166
+ }
167
+ function has(object, path) {
168
+ return null != object && hasPath(object, path, baseHas);
169
+ }
170
+ exports.assignValue = __webpack_exports__.assignValue;
171
+ exports.baseAssignValue = __webpack_exports__.baseAssignValue;
172
+ exports.castPath = __webpack_exports__.castPath;
173
+ exports.eq = __webpack_exports__.eq;
174
+ exports.getTag = __webpack_exports__.getTag;
175
+ exports.has = __webpack_exports__.has;
176
+ exports.isIndex = __webpack_exports__.isIndex;
177
+ exports.isKey = __webpack_exports__.isKey;
178
+ exports.isObject = __webpack_exports__.isObject;
179
+ exports.isSymbol = __webpack_exports__.isSymbol;
180
+ exports.stringToPath = __webpack_exports__.stringToPath;
181
+ exports.toKey = __webpack_exports__.toKey;
182
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
183
+ "assignValue",
184
+ "baseAssignValue",
185
+ "castPath",
186
+ "eq",
187
+ "getTag",
188
+ "has",
189
+ "isIndex",
190
+ "isKey",
191
+ "isObject",
192
+ "isSymbol",
193
+ "stringToPath",
194
+ "toKey"
195
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
196
+ Object.defineProperty(exports, '__esModule', {
197
+ value: true
198
+ });
package/package.json ADDED
@@ -0,0 +1,30 @@
1
+ {
2
+ "name": "@carefrees/form-utils-vue-hooks",
3
+ "version": "0.0.13",
4
+ "description": "vue表单hooks",
5
+ "homepage": "https://github.com/SunLxy/carefrees-form-utils",
6
+ "main": "lib/index.js",
7
+ "types": "lib/index.d.ts",
8
+ "module": "esm/index.js",
9
+ "scripts": {
10
+ "build": "carefrees-rslib build --node",
11
+ "watch": "carefrees-rslib build --watch --node"
12
+ },
13
+ "publishConfig": {
14
+ "access": "public"
15
+ },
16
+ "files": [
17
+ "src",
18
+ "lib",
19
+ "esm"
20
+ ],
21
+ "keywords": [],
22
+ "author": "",
23
+ "license": "ISC",
24
+ "dependencies": {
25
+ "async-validator": "~4.2.5"
26
+ },
27
+ "devDependencies": {
28
+ "vue": "^3.5.13"
29
+ }
30
+ }
@@ -0,0 +1,185 @@
1
+ import { FormInstanceBase } from '../../instance/formInstance';
2
+ import { FormItemInstanceBase } from '../../instance/formItemInstance';
3
+ import { get } from '../../utils';
4
+ import { useHtmlFor } from './../useHtmlFor';
5
+ import { useRegisterFormItem, RegisterFormItemOptions } from './../register/register.FormItem';
6
+ import { computed, Ref, ref, toValue, watch } from 'vue';
7
+ import type { RuleInstanceBase } from '../../instance/ruleIntsnace';
8
+
9
+ export interface FormItemAttrOptions extends RegisterFormItemOptions {
10
+ /**依赖更新项*/
11
+ dependencies?: string[];
12
+ /**通知 只用于校验规则提示 字段 */
13
+ noticeOnlyRuleDataField?: string[];
14
+ /**是否保护值(不进行表单项组件卸载重置初始值)*/
15
+ preserve?: boolean;
16
+ /**重写规则*/
17
+ useRules?: (
18
+ ruleInstance: Ref<RuleInstanceBase>,
19
+ form: Ref<FormInstanceBase>,
20
+ formItemInstance: Ref<FormItemInstanceBase>,
21
+ ) => void;
22
+ /**输入框属性重写*/
23
+ useAttrs?: (attrs: any, form: Ref<FormInstanceBase>, formItemInstance: Ref<FormItemInstanceBase>) => any;
24
+ /**输入框属性*/
25
+ inputAttrs?: Object;
26
+ /**传递组件字段*/
27
+ valuePropName?: string;
28
+ /**取值字段(默认和valuePropName值相同)*/
29
+ getValuePath?: string;
30
+ /**自定义获取值*/
31
+ getValueFromEvent?: (event: any, form: Ref<FormInstanceBase>, formItemInstance: Ref<FormItemInstanceBase>) => any;
32
+ /**值格式化*/
33
+ formatValue?: (
34
+ value: any,
35
+ form: Ref<FormInstanceBase>,
36
+ formItemInstance: Ref<FormItemInstanceBase>,
37
+ event: any,
38
+ ) => any;
39
+ /**触发数据更新之后触发(用于数据联动之类的)*/
40
+ onAfterUpdate?: (
41
+ value: any,
42
+ form: Ref<FormInstanceBase>,
43
+ formItemInstance: Ref<FormItemInstanceBase>,
44
+ event: any,
45
+ ) => void;
46
+ /**事件名称*/
47
+ trigger?: string;
48
+ }
49
+
50
+ /**表单项参数*/
51
+ export const useFormItemAttr = (options: FormItemAttrOptions) => {
52
+ const {
53
+ trigger = 'onChange',
54
+ preserve,
55
+ valuePropName = 'value',
56
+ getValuePath = valuePropName,
57
+ getValueFromEvent,
58
+ formatValue,
59
+ onAfterUpdate,
60
+ useAttrs,
61
+ useRules,
62
+ noticeOnlyRuleDataField,
63
+ } = options;
64
+
65
+ const { formItemInstance, form, ruleInstance, newName, newSort } = useRegisterFormItem(options);
66
+ formItemInstance.value.noticeOnlyRuleDataField = noticeOnlyRuleDataField;
67
+ formItemInstance.value.onAfterUpdate = onAfterUpdate;
68
+ formItemInstance.value.preserve = preserve;
69
+ /**获取值*/
70
+ const oldValue = ref(get(toValue(form.value.formData), toValue(newName)));
71
+ const oldInputAttrs = ref(options.inputAttrs || {});
72
+ watch(
73
+ () => options.inputAttrs,
74
+ (newVal) => {
75
+ oldInputAttrs.value = newVal || {};
76
+ },
77
+ );
78
+ watch(
79
+ () => [get(toValue(form.value.formData), toValue(newName)), toValue(newName)],
80
+ () => {
81
+ oldValue.value = form.value.getFieldValue(toValue(newName));
82
+ },
83
+ { immediate: true },
84
+ );
85
+
86
+ watch(
87
+ () => [toValue(formItemInstance).noticeOnlyRuleDataField, toValue(oldValue)],
88
+ () => {
89
+ const formInstance = toValue(form);
90
+ const newVal = toValue(formItemInstance).noticeOnlyRuleDataField;
91
+ if (Array.isArray(newVal) && newVal.length) {
92
+ formInstance.onlyValidate(newVal);
93
+ }
94
+ },
95
+ { immediate: true },
96
+ );
97
+
98
+ const onValueChange = (event: any) => {
99
+ try {
100
+ const formItem = toValue(formItemInstance);
101
+ const formInstance = toValue(form);
102
+ let value = event;
103
+ if (typeof getValueFromEvent === 'function') {
104
+ value = getValueFromEvent(event, form, formItemInstance);
105
+ } else if (event && event.target && typeof event.target === 'object' && getValuePath in event.target) {
106
+ value = get(event.target, getValuePath);
107
+ }
108
+ if (typeof formatValue === 'function') {
109
+ value = formatValue(value, form, formItemInstance, event);
110
+ }
111
+ if (oldValue.value !== value) {
112
+ formInstance.updatedFieldValue(toValue(newName), value, 'validate');
113
+ formItem.onAfterUpdate?.(value, form, formItemInstance, event);
114
+ }
115
+ } catch (error) {
116
+ console.log(error);
117
+ }
118
+ };
119
+
120
+ const htmlFor = useHtmlFor(newName);
121
+
122
+ watch(
123
+ () => toValue(htmlFor),
124
+ () => {
125
+ formItemInstance.value.htmlFor = htmlFor.value;
126
+ },
127
+ { immediate: true },
128
+ );
129
+
130
+ /**属性处理*/
131
+ const newAttrs = computed(() => {
132
+ const _attr = oldInputAttrs.value || {};
133
+ return {
134
+ ..._attr,
135
+ [trigger]: onValueChange,
136
+ name: toValue(newName),
137
+ id: toValue(htmlFor),
138
+ [valuePropName]: toValue(oldValue),
139
+ };
140
+ });
141
+
142
+ const attrsLastData = ref(toValue(newAttrs));
143
+
144
+ watch(
145
+ () => [toValue(newAttrs), toValue(oldValue)],
146
+ () => {
147
+ attrsLastData.value = useAttrs?.(toValue(newAttrs), form, formItemInstance) || toValue(newAttrs);
148
+ formItemInstance.value.control = attrsLastData;
149
+ },
150
+ { immediate: true },
151
+ );
152
+
153
+ /**规则处理**/
154
+ const validateResult = ref(toValue(ruleInstance).getValidateResult());
155
+
156
+ /**规则变化,值变更触发*/
157
+ watch(
158
+ () => [toValue(oldValue), toValue(toValue(ruleInstance).rules)],
159
+ () => {
160
+ useRules?.(ruleInstance, form, formItemInstance);
161
+ ruleInstance.value.validate();
162
+ },
163
+ );
164
+
165
+ watch(
166
+ () => [toValue(toValue(ruleInstance).messages), toValue(toValue(ruleInstance).rules)],
167
+ () => {
168
+ validateResult.value = toValue(ruleInstance).getValidateResult();
169
+ },
170
+ );
171
+
172
+ return {
173
+ valuePropName,
174
+ htmlFor,
175
+ onChange: onValueChange,
176
+ formItemInstance,
177
+ form,
178
+ ruleInstance,
179
+ newAttrs,
180
+ attrsLastData,
181
+ validateResult,
182
+ newSort,
183
+ newName,
184
+ };
185
+ };
@@ -0,0 +1,13 @@
1
+ export * from './useAttrs';
2
+ export * from './useForm';
3
+ export * from './useFormItem';
4
+ export * from './useFormList';
5
+ export * from './useHtmlFor';
6
+ export * from './useMultipleForm';
7
+ export * from './useFormItemParentName';
8
+ export * from './useEffect';
9
+ export * from './register/register.FormHideItem';
10
+ export * from './register/register.FormItem';
11
+ export * from './register/register.FormList';
12
+ export * from './register/register.form';
13
+ export * from './attr/attr.FormItem';