@fairys/valtio-form-basic 0.0.12 → 1.0.0

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 (49) hide show
  1. package/README.md +935 -2
  2. package/esm/{form → common}/hooks/index.d.ts +1 -0
  3. package/esm/{form → common}/hooks/index.js +9 -1
  4. package/esm/common/index.d.ts +4 -0
  5. package/esm/common/index.js +4 -0
  6. package/esm/{form → common}/instance/index.d.ts +34 -7
  7. package/esm/{form → common}/instance/index.js +45 -11
  8. package/esm/{form → common}/utils/index.d.ts +7 -0
  9. package/esm/{form → common}/utils/index.js +11 -1
  10. package/esm/form/form.d.ts +14 -8
  11. package/esm/form/form.item.d.ts +18 -7
  12. package/esm/form/form.item.js +56 -32
  13. package/esm/form/form.js +7 -4
  14. package/esm/form/layout.d.ts +4 -2591
  15. package/esm/form/layout.js +7 -4
  16. package/esm/index.d.ts +1 -2
  17. package/esm/index.js +1 -2
  18. package/esm/styles/index.css +20 -4
  19. package/lib/common/hooks/index.d.ts +35 -0
  20. package/lib/common/hooks/index.js +117 -0
  21. package/lib/common/index.d.ts +4 -0
  22. package/lib/common/index.js +87 -0
  23. package/lib/common/instance/index.d.ts +108 -0
  24. package/lib/common/instance/index.js +269 -0
  25. package/lib/common/interface.d.ts +4 -0
  26. package/lib/common/interface.js +18 -0
  27. package/lib/common/utils/index.d.ts +31 -0
  28. package/lib/common/utils/index.js +119 -0
  29. package/lib/form/form.d.ts +82 -0
  30. package/lib/form/form.item.d.ts +228 -0
  31. package/lib/form/form.item.js +327 -0
  32. package/lib/form/form.js +54 -0
  33. package/lib/form/layout.d.ts +153 -0
  34. package/lib/form/layout.js +196 -0
  35. package/lib/index.d.ts +4 -0
  36. package/lib/index.js +18 -27
  37. package/lib/styles/index.css +308 -0
  38. package/package.json +5 -5
  39. package/src/{form → common}/hooks/index.tsx +9 -1
  40. package/src/common/index.ts +4 -0
  41. package/src/{form → common}/instance/index.ts +110 -21
  42. package/src/{form → common}/utils/index.ts +21 -0
  43. package/src/form/form.item.tsx +87 -40
  44. package/src/form/form.tsx +23 -9
  45. package/src/form/layout.tsx +9 -3
  46. package/src/index.tsx +4 -5
  47. /package/esm/{interface.d.ts → common/interface.d.ts} +0 -0
  48. /package/esm/{interface.js → common/interface.js} +0 -0
  49. /package/src/{interface.ts → common/interface.ts} +0 -0
@@ -0,0 +1,269 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.n = (module)=>{
5
+ var getter = module && module.__esModule ? ()=>module['default'] : ()=>module;
6
+ __webpack_require__.d(getter, {
7
+ a: getter
8
+ });
9
+ return getter;
10
+ };
11
+ })();
12
+ (()=>{
13
+ __webpack_require__.d = (exports1, definition)=>{
14
+ for(var key in definition)if (__webpack_require__.o(definition, key) && !__webpack_require__.o(exports1, key)) Object.defineProperty(exports1, key, {
15
+ enumerable: true,
16
+ get: definition[key]
17
+ });
18
+ };
19
+ })();
20
+ (()=>{
21
+ __webpack_require__.o = (obj, prop)=>Object.prototype.hasOwnProperty.call(obj, prop);
22
+ })();
23
+ (()=>{
24
+ __webpack_require__.r = (exports1)=>{
25
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
26
+ value: 'Module'
27
+ });
28
+ Object.defineProperty(exports1, '__esModule', {
29
+ value: true
30
+ });
31
+ };
32
+ })();
33
+ var __webpack_exports__ = {};
34
+ __webpack_require__.r(__webpack_exports__);
35
+ __webpack_require__.d(__webpack_exports__, {
36
+ useFairysValtioFormInstanceContextState: ()=>useFairysValtioFormInstanceContextState,
37
+ useFairysValtioFormInstanceContext: ()=>useFairysValtioFormInstanceContext,
38
+ useFairysValtioFormInstanceContextHideState: ()=>useFairysValtioFormInstanceContextHideState,
39
+ useFairysValtioFormInstanceToHideState: ()=>useFairysValtioFormInstanceToHideState,
40
+ useFairysValtioFormInstanceToState: ()=>useFairysValtioFormInstanceToState,
41
+ FairysValtioFormInstance: ()=>FairysValtioFormInstance,
42
+ useFairysValtioFormInstance: ()=>useFairysValtioFormInstance,
43
+ FairysValtioFormInstanceContext: ()=>FairysValtioFormInstanceContext
44
+ });
45
+ const external_react_namespaceObject = require("react");
46
+ const external_valtio_namespaceObject = require("valtio");
47
+ const external_async_validator_namespaceObject = require("async-validator");
48
+ var external_async_validator_default = /*#__PURE__*/ __webpack_require__.n(external_async_validator_namespaceObject);
49
+ const external_fast_copy_namespaceObject = require("fast-copy");
50
+ const index_js_namespaceObject = require("../utils/index.js");
51
+ class FairysValtioFormInstance {
52
+ onValuesChange;
53
+ isValtioProxy = (value)=>{
54
+ const { refSet } = (0, external_valtio_namespaceObject.unstable_getInternalStates)();
55
+ const canProxyDefault = (x)=>(0, index_js_namespaceObject.isObject)(x) && !refSet.has(x) && (Array.isArray(x) || !(Symbol.iterator in x)) && !(x instanceof WeakMap) && !(x instanceof WeakSet) && !(x instanceof Error) && !(x instanceof Number) && !(x instanceof Date) && !(x instanceof String) && !(x instanceof RegExp) && !(x instanceof ArrayBuffer) && !(x instanceof Promise);
56
+ return canProxyDefault(value);
57
+ };
58
+ state = (0, external_valtio_namespaceObject.proxy)({});
59
+ errorState = (0, external_valtio_namespaceObject.proxy)({});
60
+ hideState = (0, external_valtio_namespaceObject.proxy)({});
61
+ ctor = (options)=>{
62
+ const { formData, hideState, initFormDataType = 'deepCopy' } = options || {};
63
+ this.clear();
64
+ this.updatedHideInfo(hideState ? (0, external_fast_copy_namespaceObject.copy)(hideState) : {});
65
+ const isValtioProxy = this.isValtioProxy(formData);
66
+ if (isValtioProxy) if ('deepCopy' === initFormDataType) this.updated((0, external_fast_copy_namespaceObject.copy)((0, external_valtio_namespaceObject.snapshot)(formData)), false);
67
+ else this.updated(formData, false);
68
+ else {
69
+ if ('deepCopy' === initFormDataType) this.updated((0, external_fast_copy_namespaceObject.copy)(formData || {}), false);
70
+ this.updated(formData || {}, false);
71
+ }
72
+ };
73
+ updated = (state, isValidate = true)=>{
74
+ const keys = Object.keys(state);
75
+ for(let index = 0; index < keys.length; index++){
76
+ const key = keys[index];
77
+ this.state[key] = state[key];
78
+ }
79
+ if (isValidate) this.validate(keys, false);
80
+ };
81
+ updatedValueByPaths = (path, value)=>{
82
+ (0, index_js_namespaceObject.set)(this.state, (0, index_js_namespaceObject.formatePath)(path), value);
83
+ this.validate([
84
+ path
85
+ ], false);
86
+ this.onValuesChange?.(path, value);
87
+ };
88
+ removeValueByPaths = (path)=>{
89
+ (0, index_js_namespaceObject.removeValueByPaths)(this.state, (0, index_js_namespaceObject.formatePath)(path));
90
+ };
91
+ clearValue = (fields)=>{
92
+ let _fields = fields;
93
+ if (!Array.isArray(fields)) _fields = Object.keys(this.state);
94
+ for(let index = 0; index < _fields.length; index++){
95
+ const field = _fields[index];
96
+ delete this.state[field];
97
+ }
98
+ return this;
99
+ };
100
+ updatedHideInfo = (objectHideInfo)=>{
101
+ const keys = Object.keys(objectHideInfo);
102
+ for(let index = 0; index < keys.length; index++){
103
+ const field = keys[index];
104
+ this.hideState[field] = objectHideInfo[field];
105
+ }
106
+ return this;
107
+ };
108
+ clearHideInfo = (fields)=>{
109
+ let _fields = fields;
110
+ if (!Array.isArray(fields)) _fields = Object.keys(this.hideState);
111
+ for(let index = 0; index < _fields.length; index++){
112
+ const field = _fields[index];
113
+ delete this.hideState[field];
114
+ }
115
+ return this;
116
+ };
117
+ updatedErrorInfo = (objectErrorInfo)=>{
118
+ const keys = Object.keys(objectErrorInfo);
119
+ for(let index = 0; index < keys.length; index++){
120
+ const field = keys[index];
121
+ this.errorState[field] = objectErrorInfo[field];
122
+ }
123
+ return this;
124
+ };
125
+ clearErrorInfo = (fields)=>{
126
+ let _fields = fields;
127
+ if (!Array.isArray(fields)) _fields = Object.keys(this.errorState);
128
+ for(let index = 0; index < _fields.length; index++){
129
+ const field = _fields[index];
130
+ delete this.errorState[field];
131
+ }
132
+ return this;
133
+ };
134
+ clear = ()=>{
135
+ this.clearValue();
136
+ this.clearHideInfo();
137
+ this.clearErrorInfo();
138
+ this.mountRules = {};
139
+ this.rules = {};
140
+ this.nameToPaths = {};
141
+ };
142
+ mountRules = {};
143
+ removeRules = (name)=>{
144
+ delete this.mountRules[name];
145
+ };
146
+ rules = {};
147
+ nameToPaths = {};
148
+ validate = async (fields, isReturn = true)=>{
149
+ const rules = {
150
+ ...this.rules,
151
+ ...this.mountRules
152
+ };
153
+ const _formData = (0, external_valtio_namespaceObject.snapshot)(this.state);
154
+ const _values = {};
155
+ let _fields = Object.keys(rules);
156
+ let _lastRules = {};
157
+ let isPropsFields = false;
158
+ if (Array.isArray(fields) && fields.length) {
159
+ _fields = [
160
+ ...fields
161
+ ];
162
+ isPropsFields = true;
163
+ for(let index = 0; index < fields.length; index++){
164
+ const field = fields[index];
165
+ const paths = this.nameToPaths[field];
166
+ _lastRules[field] = rules[field];
167
+ _values[field] = (0, index_js_namespaceObject.get)(_formData, paths ? paths : (0, index_js_namespaceObject.formatePath)(field));
168
+ }
169
+ } else {
170
+ isPropsFields = false;
171
+ _lastRules = {
172
+ ...rules
173
+ };
174
+ for(let index = 0; index < _fields.length; index++){
175
+ const field = _fields[index];
176
+ const paths = this.nameToPaths[field];
177
+ _values[field] = (0, index_js_namespaceObject.get)(_formData, paths);
178
+ }
179
+ }
180
+ return new Promise((resolve, reject)=>{
181
+ new (external_async_validator_default())({
182
+ ...rules
183
+ }).validate({
184
+ ..._values
185
+ }, (errors, fields)=>{
186
+ for(let index = 0; index < _fields.length; index++){
187
+ const field = _fields[index];
188
+ const fidError = Array.isArray(errors) ? errors.filter((item)=>item.field === field) : void 0;
189
+ if (fidError) this.errorState[field] = (0, external_valtio_namespaceObject.ref)(fidError.map((item)=>item.message || ''));
190
+ else delete this.errorState[field];
191
+ }
192
+ if (isReturn) if (errors) reject({
193
+ errors,
194
+ fields
195
+ });
196
+ else isPropsFields ? resolve({
197
+ ...fields
198
+ }) : resolve({
199
+ ..._formData
200
+ });
201
+ });
202
+ });
203
+ };
204
+ validatePrefixFields = async (prefix, isReturn = true)=>{
205
+ const fields = Object.keys(this.rules);
206
+ const _fields = fields.filter((item)=>prefix.some((p)=>item.toString().startsWith(p)));
207
+ return this.validate(_fields, isReturn);
208
+ };
209
+ }
210
+ function useFairysValtioFormInstance(instance) {
211
+ const ref = (0, external_react_namespaceObject.useRef)();
212
+ if (!ref.current) if (instance) ref.current = instance;
213
+ else ref.current = new FairysValtioFormInstance();
214
+ return ref.current;
215
+ }
216
+ const FairysValtioFormInstanceContext = (0, external_react_namespaceObject.createContext)(new FairysValtioFormInstance());
217
+ function useFairysValtioFormInstanceContext() {
218
+ return (0, external_react_namespaceObject.useContext)(FairysValtioFormInstanceContext);
219
+ }
220
+ function useFairysValtioFormInstanceContextState() {
221
+ const instance = useFairysValtioFormInstanceContext();
222
+ const state = (0, external_valtio_namespaceObject.useSnapshot)(instance.state);
223
+ const errorState = (0, external_valtio_namespaceObject.useSnapshot)(instance.errorState);
224
+ return [
225
+ state,
226
+ errorState,
227
+ instance,
228
+ state.__defaultValue,
229
+ errorState.__defaultValue
230
+ ];
231
+ }
232
+ function useFairysValtioFormInstanceContextHideState() {
233
+ const instance = useFairysValtioFormInstanceContext();
234
+ const hideState = (0, external_valtio_namespaceObject.useSnapshot)(instance.hideState);
235
+ return [
236
+ hideState,
237
+ instance,
238
+ hideState.__defaultValue
239
+ ];
240
+ }
241
+ function useFairysValtioFormInstanceToState(formInstance) {
242
+ const state = (0, external_valtio_namespaceObject.useSnapshot)(formInstance.state);
243
+ return state;
244
+ }
245
+ function useFairysValtioFormInstanceToHideState(formInstance) {
246
+ const hideState = (0, external_valtio_namespaceObject.useSnapshot)(formInstance.hideState);
247
+ return hideState;
248
+ }
249
+ exports.FairysValtioFormInstance = __webpack_exports__.FairysValtioFormInstance;
250
+ exports.FairysValtioFormInstanceContext = __webpack_exports__.FairysValtioFormInstanceContext;
251
+ exports.useFairysValtioFormInstance = __webpack_exports__.useFairysValtioFormInstance;
252
+ exports.useFairysValtioFormInstanceContext = __webpack_exports__.useFairysValtioFormInstanceContext;
253
+ exports.useFairysValtioFormInstanceContextHideState = __webpack_exports__.useFairysValtioFormInstanceContextHideState;
254
+ exports.useFairysValtioFormInstanceContextState = __webpack_exports__.useFairysValtioFormInstanceContextState;
255
+ exports.useFairysValtioFormInstanceToHideState = __webpack_exports__.useFairysValtioFormInstanceToHideState;
256
+ exports.useFairysValtioFormInstanceToState = __webpack_exports__.useFairysValtioFormInstanceToState;
257
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
258
+ "FairysValtioFormInstance",
259
+ "FairysValtioFormInstanceContext",
260
+ "useFairysValtioFormInstance",
261
+ "useFairysValtioFormInstanceContext",
262
+ "useFairysValtioFormInstanceContextHideState",
263
+ "useFairysValtioFormInstanceContextState",
264
+ "useFairysValtioFormInstanceToHideState",
265
+ "useFairysValtioFormInstanceToState"
266
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
267
+ Object.defineProperty(exports, '__esModule', {
268
+ value: true
269
+ });
@@ -0,0 +1,4 @@
1
+ export type MObject<T> = {
2
+ [K in keyof T]: T[K];
3
+ };
4
+ export type MakeFieldRequired<T, K extends keyof T> = Omit<T, K> & Required<Pick<T, K>>;
@@ -0,0 +1,18 @@
1
+ "use strict";
2
+ var __webpack_require__ = {};
3
+ (()=>{
4
+ __webpack_require__.r = (exports1)=>{
5
+ if ('undefined' != typeof Symbol && Symbol.toStringTag) Object.defineProperty(exports1, Symbol.toStringTag, {
6
+ value: 'Module'
7
+ });
8
+ Object.defineProperty(exports1, '__esModule', {
9
+ value: true
10
+ });
11
+ };
12
+ })();
13
+ var __webpack_exports__ = {};
14
+ __webpack_require__.r(__webpack_exports__);
15
+ for(var __webpack_i__ in __webpack_exports__)exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
16
+ Object.defineProperty(exports, '__esModule', {
17
+ value: true
18
+ });
@@ -0,0 +1,31 @@
1
+ /***
2
+ * 设置值
3
+ * @param object 任意对象
4
+ * @param paths 值路径
5
+ * @param nextValue 新值
6
+ *
7
+ * @description
8
+ * 值不存在时,当 paths 路径中的值为 number 类型时,会创建一个空数组。当 paths 路径中的值为 string 类型时,会创建一个空对象。
9
+ */
10
+ export declare function set<T>(state: any, paths: PropertyKey[], nextValue: T): any;
11
+ /***
12
+ * 获取值
13
+ * @param value 任意值
14
+ * @param segments 键路径
15
+ */
16
+ export declare function get<TDefault = unknown>(value: any, segments: PropertyKey[]): TDefault;
17
+ /***
18
+ * 移除值
19
+ * @param value 任意值
20
+ * @param segments 键路径
21
+ */
22
+ export declare function removeValueByPaths(value: any, segments: PropertyKey[]): void;
23
+ /***
24
+ * 格式化路径,将路径中的数组索引转换为数字
25
+ * @param path 路径
26
+ * @returns 格式化后的路径
27
+ */
28
+ export declare function formatePath(path: PropertyKey): (number | symbol)[] | (string | number)[];
29
+ /**格式化属性名*/
30
+ export declare function formateName(name?: string, parentName?: string): string;
31
+ export declare const isObject: (x: unknown) => x is object;
@@ -0,0 +1,119 @@
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
+ formateName: ()=>formateName,
28
+ formatePath: ()=>formatePath,
29
+ get: ()=>get,
30
+ isObject: ()=>isObject,
31
+ removeValueByPaths: ()=>removeValueByPaths,
32
+ set: ()=>set
33
+ });
34
+ function set(state, paths, nextValue) {
35
+ const _keys = [
36
+ ...paths
37
+ ];
38
+ let current = state;
39
+ const length = _keys.length - 1;
40
+ for(let i = 0; i <= length; i++){
41
+ const key = _keys[i];
42
+ const _current = current[key];
43
+ const nextKey = _keys[i + 1];
44
+ if (void 0 === _current && 'number' == typeof nextKey) current[key] = [];
45
+ else if (void 0 === _current && 'string' == typeof nextKey) current[key] = {};
46
+ if (i === length) current[key] = nextValue;
47
+ else current = current[key];
48
+ }
49
+ return state;
50
+ }
51
+ function get(value, segments) {
52
+ let current = value;
53
+ for (const key of segments)current = current?.[key];
54
+ return current;
55
+ }
56
+ function removeValueByPaths(value, segments) {
57
+ let current = value;
58
+ const lg = segments.length;
59
+ for(let index = 0; index < lg; index++){
60
+ const key = segments[index];
61
+ if (index === lg - 1) delete current[key];
62
+ else current = current?.[key];
63
+ }
64
+ }
65
+ function formatePath(path) {
66
+ if ('string' != typeof path) return [
67
+ path
68
+ ];
69
+ return path.split(/[\.]/g).reduce((pre, next)=>{
70
+ if (/\[[0-9]+\]$/.test(next)) {
71
+ const _next = next.split(/\[/);
72
+ let _nextValue = [];
73
+ for(let index = 0; index < _next.length; index++){
74
+ const element = _next[index];
75
+ if (/\]$/.test(element)) {
76
+ const _v = element.replace(/\]$/, '');
77
+ const v = Number.parseInt(_v);
78
+ if (_v.length !== `${v}`.length || Number.isNaN(v)) _nextValue.push(_v);
79
+ else _nextValue.push(v);
80
+ } else _nextValue.push(element);
81
+ }
82
+ return [
83
+ ...pre,
84
+ ..._nextValue
85
+ ];
86
+ }
87
+ return [
88
+ ...pre,
89
+ next
90
+ ];
91
+ }, []).map((item)=>{
92
+ if ('string' == typeof item) return item.trim();
93
+ return item;
94
+ }).filter((item)=>'' !== item);
95
+ }
96
+ function formateName(name, parentName) {
97
+ if (parentName && name) return parentName + '.' + name;
98
+ if (parentName) return parentName;
99
+ if (name) return name;
100
+ return '';
101
+ }
102
+ const isObject = (x)=>'object' == typeof x && null !== x;
103
+ exports.formateName = __webpack_exports__.formateName;
104
+ exports.formatePath = __webpack_exports__.formatePath;
105
+ exports.get = __webpack_exports__.get;
106
+ exports.isObject = __webpack_exports__.isObject;
107
+ exports.removeValueByPaths = __webpack_exports__.removeValueByPaths;
108
+ exports.set = __webpack_exports__.set;
109
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
110
+ "formateName",
111
+ "formatePath",
112
+ "get",
113
+ "isObject",
114
+ "removeValueByPaths",
115
+ "set"
116
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
117
+ Object.defineProperty(exports, '__esModule', {
118
+ value: true
119
+ });
@@ -0,0 +1,82 @@
1
+ import { MObject } from '../common/interface';
2
+ import { FairysValtioFormInstance } from '../common/instance';
3
+ import { type ReactNode } from 'react';
4
+ import { FairysValtioFormLayoutAttrsProps } from './layout';
5
+ import { RuleItem } from 'async-validator';
6
+ export interface FairysValtioFormAttrsProps<T extends MObject<T> = Record<string, any>> extends FairysValtioFormLayoutAttrsProps {
7
+ /**表单实例*/
8
+ form?: FairysValtioFormInstance<T>;
9
+ /**子元素*/
10
+ children: ReactNode;
11
+ /**表单项规则(如果表单项没有指定规则,则使用全局规则,如果表单项指定规则,则使用表单项规则)*/
12
+ rules?: Record<PropertyKey, RuleItem[]>;
13
+ /**表单初始值*/
14
+ formData?: FairysValtioFormInstance<T>['state'];
15
+ /**表单隐藏状态*/
16
+ hideState?: FairysValtioFormInstance<T>['hideState'];
17
+ /**
18
+ * 初始化表单数据类型,默认值为 deepCopy
19
+ * - deepCopy:使用深度拷贝初始化表单数据
20
+ * - immutable:直接使用对象(注意:当传递的不是`valtio`的`proxy`对象时,会使用`valtio`中的`proxy`声明)
21
+ */
22
+ initFormDataType?: 'deepCopy' | 'immutable';
23
+ /**
24
+ * 表单值改变时回调
25
+ * @param path 表单项路径
26
+ * @param value 表单项值
27
+ */
28
+ onValuesChange?: (path: PropertyKey, value: any) => void;
29
+ }
30
+ /**
31
+ * 表单属性处理
32
+ *
33
+ * @example
34
+ *
35
+ * ```tsx
36
+ import { useFairysValtioForm } from "@fairys/valtio-form"
37
+ import type { FairysValtioFormAttrProps } from "@fairys/valtio-form"
38
+ export interface FormProps extends FairysValtioFormAttrProps{}
39
+
40
+ export const Form = (props: FormProps) => {
41
+ const { formInstance,children, ...rest } = useFairysValtioForm(props)
42
+ return (
43
+ <FairysValtioFormInstanceContext.Provider value={formInstance}>
44
+ <布局组件 {...rest}>{children}</布局组件>
45
+ </FairysValtioFormInstanceContext.Provider>
46
+ );
47
+ }
48
+ * ```
49
+ */
50
+ export declare function useFairysValtioForm<T extends MObject<T> = Record<string, any>>(props: FairysValtioFormAttrsProps<T>, ref: React.Ref<FairysValtioFormInstance<T>>): {
51
+ formInstance: FairysValtioFormInstance<T>;
52
+ /**子元素*/
53
+ children: ReactNode;
54
+ gap?: string | number;
55
+ title?: React.ReactNode;
56
+ extra?: React.ReactNode;
57
+ isAllColSpan?: boolean;
58
+ className?: string;
59
+ style?: React.CSSProperties;
60
+ headerClassName?: string;
61
+ headerStyle?: React.CSSProperties;
62
+ bodyClassName?: string;
63
+ bodyStyle?: React.CSSProperties;
64
+ bordered?: boolean;
65
+ boxShadow?: boolean;
66
+ lastItemBordered?: boolean;
67
+ platform?: "pc" | "rn" | "taro";
68
+ colCount?: number;
69
+ errorLayout?: "bottom-left" | "bottom-right" | "top-right" | "top-left" | "left-border-top" | "right-border-top";
70
+ labelMode?: "left" | "top" | "between";
71
+ formItemClassName?: string;
72
+ formItemStyle?: React.CSSProperties;
73
+ formItemLabelClassName?: string;
74
+ formItemLabelStyle?: React.CSSProperties;
75
+ formItemBodyClassName?: string;
76
+ formItemBodyStyle?: React.CSSProperties;
77
+ itemBorderType?: "bottom" | "body" | "none";
78
+ itemBorderColor?: React.CSSProperties["borderColor"];
79
+ isInvalidBorderRed?: boolean;
80
+ isInvalidTextRed?: boolean;
81
+ showColon?: boolean;
82
+ };