@carefrees/form-utils-react-hooks 0.0.4

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 (72) hide show
  1. package/README.md +9 -0
  2. package/esm/hooks/register/register.FormHideItem.d.ts +9 -0
  3. package/esm/hooks/register/register.FormHideItem.js +31 -0
  4. package/esm/hooks/register/register.FormItem.d.ts +23 -0
  5. package/esm/hooks/register/register.FormItem.js +42 -0
  6. package/esm/hooks/register/register.FormList.d.ts +9 -0
  7. package/esm/hooks/register/register.FormList.js +31 -0
  8. package/esm/hooks/register/register.form.d.ts +3 -0
  9. package/esm/hooks/register/register.form.js +17 -0
  10. package/esm/hooks/useAttrs.d.ts +30 -0
  11. package/esm/hooks/useAttrs.js +10 -0
  12. package/esm/hooks/useForm.d.ts +7 -0
  13. package/esm/hooks/useForm.js +13 -0
  14. package/esm/hooks/useFormItem.d.ts +7 -0
  15. package/esm/hooks/useFormItem.js +11 -0
  16. package/esm/hooks/useFormItemParentName.d.ts +30 -0
  17. package/esm/hooks/useFormItemParentName.js +61 -0
  18. package/esm/hooks/useFormList.d.ts +7 -0
  19. package/esm/hooks/useFormList.js +11 -0
  20. package/esm/hooks/useHtmlFor.d.ts +1 -0
  21. package/esm/hooks/useHtmlFor.js +10 -0
  22. package/esm/hooks/useMultipleForm.d.ts +13 -0
  23. package/esm/hooks/useMultipleForm.js +19 -0
  24. package/esm/hooks/useUpdate.d.ts +2 -0
  25. package/esm/hooks/useUpdate.js +10 -0
  26. package/esm/hooks/useWatch.d.ts +19 -0
  27. package/esm/hooks/useWatch.js +41 -0
  28. package/esm/index.d.ts +13 -0
  29. package/esm/index.js +13 -0
  30. package/lib/hooks/register/register.FormHideItem.d.ts +9 -0
  31. package/lib/hooks/register/register.FormHideItem.js +65 -0
  32. package/lib/hooks/register/register.FormItem.d.ts +23 -0
  33. package/lib/hooks/register/register.FormItem.js +76 -0
  34. package/lib/hooks/register/register.FormList.d.ts +9 -0
  35. package/lib/hooks/register/register.FormList.js +65 -0
  36. package/lib/hooks/register/register.form.d.ts +3 -0
  37. package/lib/hooks/register/register.form.js +51 -0
  38. package/lib/hooks/useAttrs.d.ts +30 -0
  39. package/lib/hooks/useAttrs.js +47 -0
  40. package/lib/hooks/useForm.d.ts +7 -0
  41. package/lib/hooks/useForm.js +53 -0
  42. package/lib/hooks/useFormItem.d.ts +7 -0
  43. package/lib/hooks/useFormItem.js +51 -0
  44. package/lib/hooks/useFormItemParentName.d.ts +30 -0
  45. package/lib/hooks/useFormItemParentName.js +101 -0
  46. package/lib/hooks/useFormList.d.ts +7 -0
  47. package/lib/hooks/useFormList.js +51 -0
  48. package/lib/hooks/useHtmlFor.d.ts +1 -0
  49. package/lib/hooks/useHtmlFor.js +44 -0
  50. package/lib/hooks/useMultipleForm.d.ts +13 -0
  51. package/lib/hooks/useMultipleForm.js +62 -0
  52. package/lib/hooks/useUpdate.d.ts +2 -0
  53. package/lib/hooks/useUpdate.js +44 -0
  54. package/lib/hooks/useWatch.d.ts +19 -0
  55. package/lib/hooks/useWatch.js +78 -0
  56. package/lib/index.d.ts +13 -0
  57. package/lib/index.js +168 -0
  58. package/package.json +30 -0
  59. package/src/hooks/register/register.FormHideItem.ts +29 -0
  60. package/src/hooks/register/register.FormItem.ts +52 -0
  61. package/src/hooks/register/register.FormList.ts +31 -0
  62. package/src/hooks/register/register.form.ts +18 -0
  63. package/src/hooks/useAttrs.ts +40 -0
  64. package/src/hooks/useForm.ts +23 -0
  65. package/src/hooks/useFormItem.ts +21 -0
  66. package/src/hooks/useFormItemParentName.ts +49 -0
  67. package/src/hooks/useFormList.ts +21 -0
  68. package/src/hooks/useHtmlFor.ts +9 -0
  69. package/src/hooks/useMultipleForm.ts +36 -0
  70. package/src/hooks/useUpdate.ts +12 -0
  71. package/src/hooks/useWatch.ts +61 -0
  72. package/src/index.ts +13 -0
package/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # 表单工具
2
+
3
+ - [ ] 表单项
4
+ - [ ] 隐藏表单项
5
+ - [ ] 空表单项
6
+ - [ ] list表单项
7
+ - [ ] layout分组标题
8
+ - [ ] 依赖项表单项更新
9
+ - [ ] 通知表单项更新
@@ -0,0 +1,9 @@
1
+ import { RegisterFormItemOptions } from './register.FormItem';
2
+ interface RegisterFormHideItemOptions extends Omit<RegisterFormItemOptions, 'rules'> {
3
+ }
4
+ /**注册表单隐藏表单项到表单实例中*/
5
+ export declare const useRegisterFormHideItem: (options: RegisterFormHideItemOptions) => {
6
+ form: import("@carefrees/form-utils").FormInstanceBase<any>;
7
+ isHide: any;
8
+ };
9
+ export {};
@@ -0,0 +1,31 @@
1
+ import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
2
+ import * as __WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_f42d2666__ from "@carefrees/form-utils";
3
+ import * as __WEBPACK_EXTERNAL_MODULE__useFormItemParentName_js_a729dfb1__ from "../useFormItemParentName.js";
4
+ import * as __WEBPACK_EXTERNAL_MODULE__useForm_js_2c14e707__ from "../useForm.js";
5
+ import * as __WEBPACK_EXTERNAL_MODULE__useUpdate_js_b5f1687a__ from "../useUpdate.js";
6
+ const useRegisterFormHideItem = (options)=>{
7
+ const { name, sort, isJoinParentField = true } = options;
8
+ const form = (0, __WEBPACK_EXTERNAL_MODULE__useForm_js_2c14e707__.useFormInstance)();
9
+ const _update = (0, __WEBPACK_EXTERNAL_MODULE__useUpdate_js_b5f1687a__.useUpdate)();
10
+ const { newName, newSort } = (0, __WEBPACK_EXTERNAL_MODULE__useFormItemParentName_js_a729dfb1__.useFormItemParentName)({
11
+ name,
12
+ sort,
13
+ isJoinParentField
14
+ });
15
+ const hideItemInstance = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(new __WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_f42d2666__.FormHideItemInstanceBase().ctor(newName)).current;
16
+ const isHide = form.getFieldHideValue(newName);
17
+ hideItemInstance.instance = form;
18
+ hideItemInstance.updated = _update.current;
19
+ hideItemInstance.sort = newSort;
20
+ (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
21
+ const unMount = form.registerFormHideItem(hideItemInstance);
22
+ return ()=>unMount();
23
+ }, [
24
+ newName
25
+ ]);
26
+ return {
27
+ form,
28
+ isHide
29
+ };
30
+ };
31
+ export { useRegisterFormHideItem };
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @description 注册组件
3
+ */
4
+ import { RuleInstanceBase } from '@carefrees/form-utils';
5
+ import type { RuleItem } from 'async-validator';
6
+ export interface RegisterFormItemOptions {
7
+ /**字段*/
8
+ name: string;
9
+ /**规则*/
10
+ rules?: RuleItem[];
11
+ /**排序值*/
12
+ sort?: string;
13
+ /**是否拼接父级字段*/
14
+ isJoinParentField?: boolean;
15
+ }
16
+ /**注册表单项到表单实例中*/
17
+ export declare const useRegisterFormItem: (options: RegisterFormItemOptions) => {
18
+ ruleInstance: RuleInstanceBase;
19
+ formItemInstance: import("@carefrees/form-utils").FormItemInstanceBase;
20
+ form: import("@carefrees/form-utils").FormInstanceBase<any>;
21
+ parentName: string;
22
+ newName: string;
23
+ };
@@ -0,0 +1,42 @@
1
+ import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
2
+ import * as __WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_f42d2666__ from "@carefrees/form-utils";
3
+ import * as __WEBPACK_EXTERNAL_MODULE__useUpdate_js_b5f1687a__ from "../useUpdate.js";
4
+ import * as __WEBPACK_EXTERNAL_MODULE__useForm_js_2c14e707__ from "../useForm.js";
5
+ import * as __WEBPACK_EXTERNAL_MODULE__useFormItem_js_cd5761e5__ from "../useFormItem.js";
6
+ import * as __WEBPACK_EXTERNAL_MODULE__useFormItemParentName_js_a729dfb1__ from "../useFormItemParentName.js";
7
+ const useRegisterFormItem = (options)=>{
8
+ const { name, rules, sort, isJoinParentField = true } = options;
9
+ const form = (0, __WEBPACK_EXTERNAL_MODULE__useForm_js_2c14e707__.useFormInstance)();
10
+ const { newName, newSort, parentName } = (0, __WEBPACK_EXTERNAL_MODULE__useFormItemParentName_js_a729dfb1__.useFormItemParentName)({
11
+ name,
12
+ sort,
13
+ isJoinParentField
14
+ });
15
+ const ruleInstance = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(new __WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_f42d2666__.RuleInstanceBase()).current;
16
+ (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>ruleInstance.ctor(newName, rules), [
17
+ rules,
18
+ newName
19
+ ]);
20
+ ruleInstance.instance = form;
21
+ ruleInstance.sort = newSort;
22
+ const formItemInstance = (0, __WEBPACK_EXTERNAL_MODULE__useFormItem_js_cd5761e5__.useFormItem)();
23
+ (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>formItemInstance.ctor(newName, ruleInstance), []);
24
+ formItemInstance.instance = form;
25
+ formItemInstance.sort = newSort;
26
+ formItemInstance.parentDataField = parentName;
27
+ const _updated = (0, __WEBPACK_EXTERNAL_MODULE__useUpdate_js_b5f1687a__.useUpdate)();
28
+ formItemInstance.updated = _updated.current;
29
+ ruleInstance.updated = _updated.current;
30
+ (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
31
+ const unMount = form.registerFormItem(formItemInstance);
32
+ return ()=>unMount();
33
+ }, []);
34
+ return {
35
+ ruleInstance,
36
+ formItemInstance,
37
+ form,
38
+ parentName,
39
+ newName
40
+ };
41
+ };
42
+ export { useRegisterFormItem };
@@ -0,0 +1,9 @@
1
+ import { RegisterFormItemOptions } from './register.FormItem';
2
+ export interface RegisterFormListOptions extends RegisterFormItemOptions {
3
+ }
4
+ /**注册表单List到表单实例中*/
5
+ export declare const useRegisterFormList: (options: RegisterFormListOptions) => {
6
+ ruleInstance: import("@carefrees/form-utils").RuleInstanceBase;
7
+ formItemInstance: import("@carefrees/form-utils").FormItemInstanceBase;
8
+ formListInstance: import("@carefrees/form-utils").FormListInstanceBase;
9
+ };
@@ -0,0 +1,31 @@
1
+ import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
2
+ import * as __WEBPACK_EXTERNAL_MODULE__register_FormItem_js_53f62622__ from "./register.FormItem.js";
3
+ import * as __WEBPACK_EXTERNAL_MODULE__useFormList_js_fe5717d9__ from "../useFormList.js";
4
+ const useRegisterFormList = (options)=>{
5
+ const { ...rest } = options;
6
+ const { ruleInstance, formItemInstance, form, newName, parentName } = (0, __WEBPACK_EXTERNAL_MODULE__register_FormItem_js_53f62622__.useRegisterFormItem)({
7
+ ...rest
8
+ });
9
+ const formListInstance = (0, __WEBPACK_EXTERNAL_MODULE__useFormList_js_fe5717d9__.useFormList)();
10
+ (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>formListInstance.ctor(newName), [
11
+ newName
12
+ ]);
13
+ formListInstance.instance = form;
14
+ formListInstance.rule = ruleInstance;
15
+ formListInstance.sort = options.sort;
16
+ formListInstance.formItemInstance = formItemInstance;
17
+ formListInstance.parentDataField = parentName;
18
+ (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
19
+ const unMount = form.registerFormList(options.name, formListInstance);
20
+ return ()=>unMount();
21
+ }, [
22
+ options.name,
23
+ formListInstance
24
+ ]);
25
+ return {
26
+ ruleInstance,
27
+ formItemInstance,
28
+ formListInstance
29
+ };
30
+ };
31
+ export { useRegisterFormList };
@@ -0,0 +1,3 @@
1
+ import { FormInstanceBase } from '@carefrees/form-utils';
2
+ /**注册表单实例到多表单收集实例中*/
3
+ export declare const useRegisterForm: (form: FormInstanceBase, name?: string) => import("@carefrees/form-utils").MultipleInstanceBase;
@@ -0,0 +1,17 @@
1
+ import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
2
+ import * as __WEBPACK_EXTERNAL_MODULE__useMultipleForm_js_ddedf30e__ from "../useMultipleForm.js";
3
+ const useRegisterForm = (form, name)=>{
4
+ const multipleForm = (0, __WEBPACK_EXTERNAL_MODULE__useMultipleForm_js_ddedf30e__.useMultipleFormInstance)();
5
+ (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
6
+ let onMounted;
7
+ if (name) onMounted = multipleForm.ctor(name, form);
8
+ return ()=>{
9
+ onMounted?.();
10
+ };
11
+ }, [
12
+ name,
13
+ form
14
+ ]);
15
+ return multipleForm;
16
+ };
17
+ export { useRegisterForm };
@@ -0,0 +1,30 @@
1
+ export interface AttrsOptions {
2
+ /**列数据*/
3
+ colCount?: number;
4
+ /**规则校验失败错误提示位置*/
5
+ errorLayout?: 'left-bottom' | 'right-bottom' | 'top-right' | 'top-left';
6
+ /**
7
+ * label显示模式
8
+ * @platform taro 支持 between
9
+ */
10
+ labelMode?: 'left' | 'top' | 'between' | 'hide';
11
+ /**是否显示label后的冒号*/
12
+ showColon?: boolean;
13
+ /**表单项 className*/
14
+ formItemClassName?: string;
15
+ /**表单项 style*/
16
+ formItemStyle?: React.CSSProperties;
17
+ /**表单项 label className*/
18
+ formItemLabelClassName?: string;
19
+ /**表单项 label style*/
20
+ formItemLabelStyle?: React.CSSProperties;
21
+ /**
22
+ * 输入框底部边框
23
+ * @platform taro
24
+ */
25
+ inputBordered?: boolean;
26
+ }
27
+ /**公共属性 Context */
28
+ export declare const AttrsContext: import("react").Context<AttrsOptions>;
29
+ /**子项中获取公共属性*/
30
+ export declare const useAttrs: () => AttrsOptions;
@@ -0,0 +1,10 @@
1
+ import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
2
+ const AttrsContext = (0, __WEBPACK_EXTERNAL_MODULE_react__.createContext)({
3
+ colCount: 4,
4
+ errorLayout: 'left-bottom',
5
+ labelMode: 'top',
6
+ showColon: true,
7
+ inputBordered: true
8
+ });
9
+ const useAttrs = ()=>(0, __WEBPACK_EXTERNAL_MODULE_react__.useContext)(AttrsContext);
10
+ export { AttrsContext, useAttrs };
@@ -0,0 +1,7 @@
1
+ import { FormInstanceBase } from '@carefrees/form-utils';
2
+ /**表单实例 Context */
3
+ export declare const FormInstanceContext: import("react").Context<FormInstanceBase<any>>;
4
+ /**子项中获取表单实例*/
5
+ export declare function useFormInstance<T = any>(): FormInstanceBase<T>;
6
+ /**初始化表单实例*/
7
+ export declare function useForm<T = any>(form?: FormInstanceBase<T>): FormInstanceBase<T>;
@@ -0,0 +1,13 @@
1
+ import * as __WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_f42d2666__ from "@carefrees/form-utils";
2
+ import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
3
+ const FormInstanceContext = (0, __WEBPACK_EXTERNAL_MODULE_react__.createContext)(new __WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_f42d2666__.FormInstanceBase());
4
+ function useFormInstance() {
5
+ return (0, __WEBPACK_EXTERNAL_MODULE_react__.useContext)(FormInstanceContext);
6
+ }
7
+ function useForm(form) {
8
+ const ref = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)();
9
+ if (!ref.current) if (form) ref.current = form;
10
+ else ref.current = new __WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_f42d2666__.FormInstanceBase();
11
+ return ref.current;
12
+ }
13
+ export { FormInstanceContext, useForm, useFormInstance };
@@ -0,0 +1,7 @@
1
+ import { FormItemInstanceBase } from '@carefrees/form-utils';
2
+ /**表单项实例 Context */
3
+ export declare const FormItemInstanceContext: import("react").Context<FormItemInstanceBase>;
4
+ /**子项中获取表单项实例*/
5
+ export declare const useFormItemInstance: () => FormItemInstanceBase;
6
+ /**s初始化 表单项实例*/
7
+ export declare const useFormItem: (formItem?: FormItemInstanceBase) => FormItemInstanceBase;
@@ -0,0 +1,11 @@
1
+ import * as __WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_f42d2666__ from "@carefrees/form-utils";
2
+ import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
3
+ const FormItemInstanceContext = (0, __WEBPACK_EXTERNAL_MODULE_react__.createContext)(new __WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_f42d2666__.FormItemInstanceBase());
4
+ const useFormItemInstance = ()=>(0, __WEBPACK_EXTERNAL_MODULE_react__.useContext)(FormItemInstanceContext);
5
+ const useFormItem = (formItem)=>{
6
+ const ref = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)();
7
+ if (!ref.current) if (formItem) ref.current = formItem;
8
+ else ref.current = new __WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_f42d2666__.FormItemInstanceBase();
9
+ return ref.current;
10
+ };
11
+ export { FormItemInstanceContext, useFormItem, useFormItemInstance };
@@ -0,0 +1,30 @@
1
+ export declare const FormItemParentNameContext: import("react").Context<{
2
+ name: string;
3
+ sort: string;
4
+ }>;
5
+ export interface FormItemParentNamOptions {
6
+ /**字段*/
7
+ name: string;
8
+ /**排序*/
9
+ sort?: string;
10
+ /**是否拼接父级字段*/
11
+ isJoinParentField?: boolean;
12
+ }
13
+ interface FormItemParentNameProviderProps extends Omit<FormItemParentNamOptions, 'isJoinParentField'> {
14
+ children?: React.ReactNode;
15
+ }
16
+ export declare const FormItemParentNameProvider: (props: FormItemParentNameProviderProps) => import("react").FunctionComponentElement<import("react").ProviderProps<{
17
+ name: string;
18
+ sort: string;
19
+ }>>;
20
+ /**表单项获取父级字段*/
21
+ export declare const useFormItemParentName: (options: FormItemParentNamOptions) => {
22
+ newName: string;
23
+ newSort: string;
24
+ parentItem: {
25
+ name: string;
26
+ sort: string;
27
+ };
28
+ parentName: string;
29
+ };
30
+ export {};
@@ -0,0 +1,61 @@
1
+ import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
2
+ const FormItemParentNameContext = (0, __WEBPACK_EXTERNAL_MODULE_react__.createContext)({
3
+ name: '',
4
+ sort: ''
5
+ });
6
+ const FormItemParentNameProvider = (props)=>{
7
+ const { name, sort, children } = props;
8
+ const value = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>({
9
+ name,
10
+ sort
11
+ }), [
12
+ name,
13
+ sort
14
+ ]);
15
+ return (0, __WEBPACK_EXTERNAL_MODULE_react__.createElement)(FormItemParentNameContext.Provider, {
16
+ value,
17
+ children
18
+ });
19
+ };
20
+ const useFormItemParentName = (options)=>{
21
+ const { isJoinParentField = true, sort, name } = options;
22
+ const parentItem = (0, __WEBPACK_EXTERNAL_MODULE_react__.useContext)(FormItemParentNameContext);
23
+ const parentName = parentItem.name;
24
+ const parentSort = parentItem.sort;
25
+ const newName = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>{
26
+ if (parentName && isJoinParentField) {
27
+ if (/^\./.test(`${name}`)) ;
28
+ else if (name) return [
29
+ parentName,
30
+ '.',
31
+ name
32
+ ].filter(Boolean).join('');
33
+ return [
34
+ parentName,
35
+ name
36
+ ].filter(Boolean).join('');
37
+ }
38
+ return [
39
+ name
40
+ ].filter(Boolean).join('');
41
+ }, [
42
+ isJoinParentField,
43
+ name,
44
+ parentName
45
+ ]);
46
+ const newSort = (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>[
47
+ isJoinParentField ? parentSort : '',
48
+ sort
49
+ ].filter(Boolean).join('-'), [
50
+ isJoinParentField,
51
+ parentSort,
52
+ sort
53
+ ]);
54
+ return {
55
+ newName,
56
+ newSort,
57
+ parentItem,
58
+ parentName: parentName
59
+ };
60
+ };
61
+ export { FormItemParentNameContext, FormItemParentNameProvider, useFormItemParentName };
@@ -0,0 +1,7 @@
1
+ import { FormListInstanceBase } from '@carefrees/form-utils';
2
+ /**表单List实例 Context */
3
+ export declare const FormListInstanceContext: import("react").Context<FormListInstanceBase>;
4
+ /**子项中获取表单List实例*/
5
+ export declare const useFormListInstance: () => FormListInstanceBase;
6
+ /**初始化 表单List实例*/
7
+ export declare const useFormList: (formList?: FormListInstanceBase) => FormListInstanceBase;
@@ -0,0 +1,11 @@
1
+ import * as __WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_f42d2666__ from "@carefrees/form-utils";
2
+ import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
3
+ const FormListInstanceContext = (0, __WEBPACK_EXTERNAL_MODULE_react__.createContext)(new __WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_f42d2666__.FormListInstanceBase());
4
+ const useFormListInstance = ()=>(0, __WEBPACK_EXTERNAL_MODULE_react__.useContext)(FormListInstanceContext);
5
+ const useFormList = (formList)=>{
6
+ const ref = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)();
7
+ if (!ref.current) if (formList) ref.current = formList;
8
+ else ref.current = new __WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_f42d2666__.FormListInstanceBase();
9
+ return ref.current;
10
+ };
11
+ export { FormListInstanceContext, useFormList, useFormListInstance };
@@ -0,0 +1 @@
1
+ export declare const useHtmlFor: (suffix: string) => string;
@@ -0,0 +1,10 @@
1
+ import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
2
+ let localId = 0;
3
+ const useHtmlFor = (suffix)=>{
4
+ const count = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(localId++);
5
+ return (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>`carefree-form-item_${count.current.toString(32)}_${suffix}`, [
6
+ count.current,
7
+ suffix
8
+ ]);
9
+ };
10
+ export { useHtmlFor };
@@ -0,0 +1,13 @@
1
+ import { MultipleInstanceBase } from '@carefrees/form-utils';
2
+ /**多表单收集 Context */
3
+ export declare const MultipleFormInstanceContext: import("react").Context<MultipleInstanceBase>;
4
+ /**子项中获取 多表单收集 实例*/
5
+ export declare const useMultipleFormInstance: () => MultipleInstanceBase;
6
+ /**初始化 多表单收集 实例*/
7
+ export declare const useMultipleForm: (multipleForm?: MultipleInstanceBase) => MultipleInstanceBase;
8
+ export interface MultipleFormProviderProps {
9
+ children: React.ReactNode;
10
+ multipleForm?: MultipleInstanceBase;
11
+ }
12
+ /**多表单收集 Provider */
13
+ export declare const MultipleFormProvider: (props: MultipleFormProviderProps) => import("react").FunctionComponentElement<import("react").ProviderProps<MultipleInstanceBase>>;
@@ -0,0 +1,19 @@
1
+ import * as __WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_f42d2666__ from "@carefrees/form-utils";
2
+ import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
3
+ const MultipleFormInstanceContext = (0, __WEBPACK_EXTERNAL_MODULE_react__.createContext)(new __WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_f42d2666__.MultipleInstanceBase());
4
+ const useMultipleFormInstance = ()=>(0, __WEBPACK_EXTERNAL_MODULE_react__.useContext)(MultipleFormInstanceContext);
5
+ const useMultipleForm = (multipleForm)=>{
6
+ const ref = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)();
7
+ if (!ref.current) if (multipleForm) ref.current = multipleForm;
8
+ else ref.current = new __WEBPACK_EXTERNAL_MODULE__carefrees_form_utils_f42d2666__.MultipleInstanceBase();
9
+ return ref.current;
10
+ };
11
+ const MultipleFormProvider = (props)=>{
12
+ const { children, multipleForm } = props;
13
+ const multipleFormInstance = useMultipleForm(multipleForm);
14
+ return (0, __WEBPACK_EXTERNAL_MODULE_react__.createElement)(MultipleFormInstanceContext.Provider, {
15
+ value: multipleFormInstance,
16
+ children
17
+ });
18
+ };
19
+ export { MultipleFormInstanceContext, MultipleFormProvider, useMultipleForm, useMultipleFormInstance };
@@ -0,0 +1,2 @@
1
+ /**更新页面状态*/
2
+ export declare const useUpdate: () => import("react").MutableRefObject<Function>;
@@ -0,0 +1,10 @@
1
+ import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
2
+ const useUpdate = ()=>{
3
+ const [, _update] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)({});
4
+ const refUpdate = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(()=>void 0);
5
+ refUpdate.current = ()=>{
6
+ _update({});
7
+ };
8
+ return refUpdate;
9
+ };
10
+ export { useUpdate };
@@ -0,0 +1,19 @@
1
+ import { FormInstanceBase } from '@carefrees/form-utils';
2
+ export declare class WatchInstanceBase {
3
+ /**监听字段*/
4
+ name: string;
5
+ /**表单实例*/
6
+ form: FormInstanceBase;
7
+ /**老值*/
8
+ oldValue: any;
9
+ /**更新值*/
10
+ dispatch: (value: any) => void;
11
+ /**回调*/
12
+ callBack?: (value: any, form: FormInstanceBase) => void;
13
+ /**更新*/
14
+ updated: () => void;
15
+ }
16
+ /**
17
+ * 字段监听
18
+ */
19
+ export declare const useWatch: (name: string, form: FormInstanceBase, callBack?: (value: any, form: FormInstanceBase) => void) => [any, FormInstanceBase, WatchInstanceBase];
@@ -0,0 +1,41 @@
1
+ import * as __WEBPACK_EXTERNAL_MODULE_react__ from "react";
2
+ import * as __WEBPACK_EXTERNAL_MODULE__useForm_js_e31b00cd__ from "./useForm.js";
3
+ import * as __WEBPACK_EXTERNAL_MODULE__useFormItem_js_ee04de55__ from "./useFormItem.js";
4
+ class WatchInstanceBase {
5
+ name;
6
+ form;
7
+ oldValue;
8
+ dispatch;
9
+ callBack;
10
+ updated = ()=>{
11
+ const newValue = this.form.getFieldValue(this.name);
12
+ if (this.oldValue === newValue) return;
13
+ if (this.callBack) this.callBack(newValue, this.form);
14
+ else this.dispatch(newValue);
15
+ };
16
+ }
17
+ const useWatch = (name, form, callBack)=>{
18
+ const formInstance = form || (0, __WEBPACK_EXTERNAL_MODULE__useForm_js_e31b00cd__.useFormInstance)();
19
+ const [oldValue, setValue] = (0, __WEBPACK_EXTERNAL_MODULE_react__.useState)(formInstance.getFieldValue(name));
20
+ const watch = (0, __WEBPACK_EXTERNAL_MODULE_react__.useRef)(new WatchInstanceBase()).current;
21
+ watch.name = name;
22
+ watch.oldValue = oldValue;
23
+ watch.dispatch = setValue;
24
+ watch.callBack = callBack;
25
+ watch.form = formInstance;
26
+ const formItemInstance = (0, __WEBPACK_EXTERNAL_MODULE__useFormItem_js_ee04de55__.useFormItem)();
27
+ (0, __WEBPACK_EXTERNAL_MODULE_react__.useMemo)(()=>formItemInstance.ctor(name), []);
28
+ formItemInstance.instance = formInstance;
29
+ formItemInstance.isWatch = true;
30
+ formItemInstance.updated = watch.updated;
31
+ (0, __WEBPACK_EXTERNAL_MODULE_react__.useEffect)(()=>{
32
+ const unMount = formInstance.registerFormItem(formItemInstance);
33
+ return ()=>unMount();
34
+ }, []);
35
+ return [
36
+ oldValue,
37
+ formInstance,
38
+ watch
39
+ ];
40
+ };
41
+ export { WatchInstanceBase, useWatch };
package/esm/index.d.ts ADDED
@@ -0,0 +1,13 @@
1
+ export * from './hooks/register/register.FormHideItem';
2
+ export * from './hooks/register/register.FormItem';
3
+ export * from './hooks/register/register.FormList';
4
+ export * from './hooks/register/register.form';
5
+ export * from './hooks/useAttrs';
6
+ export * from './hooks/useForm';
7
+ export * from './hooks/useFormItem';
8
+ export * from './hooks/useFormItemParentName';
9
+ export * from './hooks/useFormList';
10
+ export * from './hooks/useHtmlFor';
11
+ export * from './hooks/useMultipleForm';
12
+ export * from './hooks/useUpdate';
13
+ export * from './hooks/useWatch';
package/esm/index.js ADDED
@@ -0,0 +1,13 @@
1
+ export * from "./hooks/register/register.FormHideItem.js";
2
+ export * from "./hooks/register/register.FormItem.js";
3
+ export * from "./hooks/register/register.FormList.js";
4
+ export * from "./hooks/register/register.form.js";
5
+ export * from "./hooks/useAttrs.js";
6
+ export * from "./hooks/useForm.js";
7
+ export * from "./hooks/useFormItem.js";
8
+ export * from "./hooks/useFormItemParentName.js";
9
+ export * from "./hooks/useFormList.js";
10
+ export * from "./hooks/useHtmlFor.js";
11
+ export * from "./hooks/useMultipleForm.js";
12
+ export * from "./hooks/useUpdate.js";
13
+ export * from "./hooks/useWatch.js";
@@ -0,0 +1,9 @@
1
+ import { RegisterFormItemOptions } from './register.FormItem';
2
+ interface RegisterFormHideItemOptions extends Omit<RegisterFormItemOptions, 'rules'> {
3
+ }
4
+ /**注册表单隐藏表单项到表单实例中*/
5
+ export declare const useRegisterFormHideItem: (options: RegisterFormHideItemOptions) => {
6
+ form: import("@carefrees/form-utils").FormInstanceBase<any>;
7
+ isHide: any;
8
+ };
9
+ export {};
@@ -0,0 +1,65 @@
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
+ useRegisterFormHideItem: ()=>useRegisterFormHideItem
28
+ });
29
+ const external_react_namespaceObject = require("react");
30
+ const form_utils_namespaceObject = require("@carefrees/form-utils");
31
+ const external_useFormItemParentName_js_namespaceObject = require("../useFormItemParentName.js");
32
+ const external_useForm_js_namespaceObject = require("../useForm.js");
33
+ const external_useUpdate_js_namespaceObject = require("../useUpdate.js");
34
+ const useRegisterFormHideItem = (options)=>{
35
+ const { name, sort, isJoinParentField = true } = options;
36
+ const form = (0, external_useForm_js_namespaceObject.useFormInstance)();
37
+ const _update = (0, external_useUpdate_js_namespaceObject.useUpdate)();
38
+ const { newName, newSort } = (0, external_useFormItemParentName_js_namespaceObject.useFormItemParentName)({
39
+ name,
40
+ sort,
41
+ isJoinParentField
42
+ });
43
+ const hideItemInstance = (0, external_react_namespaceObject.useRef)(new form_utils_namespaceObject.FormHideItemInstanceBase().ctor(newName)).current;
44
+ const isHide = form.getFieldHideValue(newName);
45
+ hideItemInstance.instance = form;
46
+ hideItemInstance.updated = _update.current;
47
+ hideItemInstance.sort = newSort;
48
+ (0, external_react_namespaceObject.useEffect)(()=>{
49
+ const unMount = form.registerFormHideItem(hideItemInstance);
50
+ return ()=>unMount();
51
+ }, [
52
+ newName
53
+ ]);
54
+ return {
55
+ form,
56
+ isHide
57
+ };
58
+ };
59
+ exports.useRegisterFormHideItem = __webpack_exports__.useRegisterFormHideItem;
60
+ for(var __webpack_i__ in __webpack_exports__)if (-1 === [
61
+ "useRegisterFormHideItem"
62
+ ].indexOf(__webpack_i__)) exports[__webpack_i__] = __webpack_exports__[__webpack_i__];
63
+ Object.defineProperty(exports, '__esModule', {
64
+ value: true
65
+ });
@@ -0,0 +1,23 @@
1
+ /**
2
+ * @description 注册组件
3
+ */
4
+ import { RuleInstanceBase } from '@carefrees/form-utils';
5
+ import type { RuleItem } from 'async-validator';
6
+ export interface RegisterFormItemOptions {
7
+ /**字段*/
8
+ name: string;
9
+ /**规则*/
10
+ rules?: RuleItem[];
11
+ /**排序值*/
12
+ sort?: string;
13
+ /**是否拼接父级字段*/
14
+ isJoinParentField?: boolean;
15
+ }
16
+ /**注册表单项到表单实例中*/
17
+ export declare const useRegisterFormItem: (options: RegisterFormItemOptions) => {
18
+ ruleInstance: RuleInstanceBase;
19
+ formItemInstance: import("@carefrees/form-utils").FormItemInstanceBase;
20
+ form: import("@carefrees/form-utils").FormInstanceBase<any>;
21
+ parentName: string;
22
+ newName: string;
23
+ };