@fairys/rn-valtio-form-basic 1.0.0 → 1.0.1

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 CHANGED
@@ -236,11 +236,18 @@ export interface FairysValtioFormAttrsProps<T extends MObject<T> = Record<string
236
236
  * - immutable:直接使用对象(注意:当传递的不是`valtio`的`proxy`对象时,会使用`valtio`中的`proxy`声明)
237
237
  */
238
238
  initFormDataType?: 'deepCopy' | 'immutable';
239
+ /**
240
+ * 表单值改变时回调
241
+ * @param path 表单项路径
242
+ * @param value 表单项值
243
+ */
244
+ onValuesChange?: (path: PropertyKey, value: any) => void;
245
+
239
246
  }
240
247
  /**
241
248
  * 表单属性处理
242
249
  */
243
- export declare function useFairysValtioForm<T extends MObject<T> = Record<string, any>>(props: FairysValtioFormAttrsProps<T>, ref: React.Ref<FairysValtioFormInstance<T>>): Omit<FairysValtioFormAttrsProps<T>, "initFormDataType" | "form" | "rules" | "formData" | "hideState"> & {
250
+ export declare function useFairysValtioForm<T extends MObject<T> = Record<string, any>>(props: FairysValtioFormAttrsProps<T>, ref: React.Ref<FairysValtioFormInstance<T>>): Omit<FairysValtioFormAttrsProps<T>, "initFormDataType" | "form" | "rules" | "formData" | "hideState"|"onValuesChange"> & {
244
251
  formInstance: FairysValtioFormInstance<T>;
245
252
  };
246
253
 
@@ -20,11 +20,17 @@ export interface FairysValtioFormAttrsProps<T extends MObject<T> = Record<string
20
20
  * - immutable:直接使用对象(注意:当传递的不是`valtio`的`proxy`对象时,会使用`valtio`中的`proxy`声明)
21
21
  */
22
22
  initFormDataType?: 'deepCopy' | 'immutable';
23
+ /**
24
+ * 表单值改变时回调
25
+ * @param path 表单项路径
26
+ * @param value 表单项值
27
+ */
28
+ onValuesChange?: (path: PropertyKey, value: any) => void;
23
29
  }
24
30
  /**
25
31
  * 表单属性处理
26
32
  *
27
33
  */
28
- export declare function useFairysValtioForm<T extends MObject<T> = Record<string, any>>(props: FairysValtioFormAttrsProps<T>, ref: React.Ref<FairysValtioFormInstance<T>>): Omit<FairysValtioFormAttrsProps<T>, "initFormDataType" | "form" | "rules" | "formData" | "hideState"> & {
34
+ export declare function useFairysValtioForm<T extends MObject<T> = Record<string, any>>(props: FairysValtioFormAttrsProps<T>, ref: React.Ref<FairysValtioFormInstance<T>>): Omit<FairysValtioFormAttrsProps<T>, "initFormDataType" | "form" | "rules" | "formData" | "hideState" | "onValuesChange"> & {
29
35
  formInstance: FairysValtioFormInstance<T>;
30
36
  };
package/esm/hooks/form.js CHANGED
@@ -1,9 +1,10 @@
1
1
  import { useFairysValtioFormInstance } from "@fairys/valtio-form-basic/esm/common";
2
2
  import { useEffect, useImperativeHandle, useMemo } from "react";
3
3
  function useFairysValtioForm(props, ref) {
4
- const { form, rules, formData, hideState, initFormDataType = 'deepCopy', ...rest } = props;
4
+ const { form, rules, formData, hideState, initFormDataType = 'deepCopy', onValuesChange, ...rest } = props;
5
5
  const formInstance = useFairysValtioFormInstance(form);
6
6
  formInstance.rules = rules;
7
+ formInstance.onValuesChange = onValuesChange;
7
8
  useMemo(()=>formInstance.ctor({
8
9
  formData,
9
10
  hideState,
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "author": "SunLxy <1011771396@qq.com>",
4
4
  "description": "rn表单框架组件",
5
5
  "homepage": "https://github.com/autumn-fairy-tales/valtio-form-basic",
6
- "version": "1.0.0",
6
+ "version": "1.0.1",
7
7
  "main": "esm/index.js",
8
8
  "types": "esm/index.d.ts",
9
9
  "module": "esm/index.js",
@@ -25,7 +25,7 @@
25
25
  "esm"
26
26
  ],
27
27
  "dependencies": {
28
- "@fairys/valtio-form-basic": "^1.0.0"
28
+ "@fairys/valtio-form-basic": "^1.0.1"
29
29
  },
30
30
  "devDependencies": {
31
31
  "@types/react": "~18.2.21",
package/src/hooks/form.ts CHANGED
@@ -22,6 +22,12 @@ export interface FairysValtioFormAttrsProps<T extends MObject<T> = Record<string
22
22
  * - immutable:直接使用对象(注意:当传递的不是`valtio`的`proxy`对象时,会使用`valtio`中的`proxy`声明)
23
23
  */
24
24
  initFormDataType?: 'deepCopy' | 'immutable';
25
+ /**
26
+ * 表单值改变时回调
27
+ * @param path 表单项路径
28
+ * @param value 表单项值
29
+ */
30
+ onValuesChange?: (path: PropertyKey, value: any) => void;
25
31
  }
26
32
 
27
33
  /**
@@ -32,10 +38,12 @@ export function useFairysValtioForm<T extends MObject<T> = Record<string, any>>(
32
38
  props: FairysValtioFormAttrsProps<T>,
33
39
  ref: React.Ref<FairysValtioFormInstance<T>>,
34
40
  ) {
35
- const { form, rules, formData, hideState, initFormDataType = 'deepCopy', ...rest } = props;
41
+ const { form, rules, formData, hideState, initFormDataType = 'deepCopy', onValuesChange, ...rest } = props;
36
42
  const formInstance = useFairysValtioFormInstance(form);
37
43
  /**表单规则*/
38
44
  formInstance.rules = rules;
45
+ /**表单值改变时回调*/
46
+ formInstance.onValuesChange = onValuesChange;
39
47
  /**初始化表单值*/
40
48
  useMemo(() => formInstance.ctor({ formData, hideState, initFormDataType }), []);
41
49
  useImperativeHandle(ref, () => formInstance);
@@ -44,7 +52,10 @@ export function useFairysValtioForm<T extends MObject<T> = Record<string, any>>(
44
52
  return {
45
53
  ...rest,
46
54
  formInstance,
47
- } as Omit<FairysValtioFormAttrsProps<T>, 'initFormDataType' | 'form' | 'rules' | 'formData' | 'hideState'> & {
55
+ } as Omit<
56
+ FairysValtioFormAttrsProps<T>,
57
+ 'initFormDataType' | 'form' | 'rules' | 'formData' | 'hideState' | 'onValuesChange'
58
+ > & {
48
59
  formInstance: FairysValtioFormInstance<T>;
49
60
  };
50
61
  }