@carefrees/form-utils-vue 0.0.12 → 0.0.14

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 (71) hide show
  1. package/README.md +54 -9
  2. package/esm/form/form.js +13 -12
  3. package/esm/formItem/form.Item.base.js +1 -6
  4. package/esm/formItem/form.Item.base.vue.d.ts +1 -0
  5. package/esm/formItem/form.hide.item.js +1 -5
  6. package/esm/formItem/form.hide.item.vue.d.ts +1 -0
  7. package/esm/formItem/formItem.js +0 -4
  8. package/esm/formItem/index.d.ts +2 -0
  9. package/esm/index.d.ts +1 -1
  10. package/esm/index.js +1 -1
  11. package/esm/interface/index.d.ts +4 -13
  12. package/esm/interface/layout.d.ts +1 -1
  13. package/esm/interface/layout.formItem.d.ts +1 -1
  14. package/esm/layout/layout.formItem.js +1 -1
  15. package/esm/layout/layout.js +1 -1
  16. package/package.json +3 -2
  17. package/src/form/form.vue +15 -12
  18. package/src/formItem/form.Item.base.vue +5 -5
  19. package/src/formItem/form.hide.item.vue +3 -1
  20. package/src/formItem/formItem.vue +2 -1
  21. package/src/index.ts +1 -1
  22. package/src/interface/index.ts +4 -15
  23. package/src/interface/layout.formItem.ts +1 -2
  24. package/src/interface/layout.ts +2 -1
  25. package/src/layout/layout.formItem.vue +2 -1
  26. package/src/layout/layout.vue +2 -1
  27. package/esm/hooks/attr/attr.FormItem.d.ts +0 -97
  28. package/esm/hooks/attr/attr.FormItem.js +0 -97
  29. package/esm/hooks/index.d.ts +0 -13
  30. package/esm/hooks/index.js +0 -13
  31. package/esm/hooks/register/register.FormHideItem.d.ts +0 -9
  32. package/esm/hooks/register/register.FormHideItem.js +0 -42
  33. package/esm/hooks/register/register.FormItem.d.ts +0 -26
  34. package/esm/hooks/register/register.FormItem.js +0 -67
  35. package/esm/hooks/register/register.FormList.d.ts +0 -9
  36. package/esm/hooks/register/register.FormList.js +0 -42
  37. package/esm/hooks/register/register.form.d.ts +0 -3
  38. package/esm/hooks/register/register.form.js +0 -10
  39. package/esm/hooks/useAttrs.d.ts +0 -25
  40. package/esm/hooks/useAttrs.js +0 -26
  41. package/esm/hooks/useEffect.d.ts +0 -2
  42. package/esm/hooks/useEffect.js +0 -12
  43. package/esm/hooks/useForm.d.ts +0 -8
  44. package/esm/hooks/useForm.js +0 -17
  45. package/esm/hooks/useFormItem.d.ts +0 -7
  46. package/esm/hooks/useFormItem.js +0 -17
  47. package/esm/hooks/useFormItemParentName.d.ts +0 -18
  48. package/esm/hooks/useFormItemParentName.js +0 -47
  49. package/esm/hooks/useFormList.d.ts +0 -7
  50. package/esm/hooks/useFormList.js +0 -17
  51. package/esm/hooks/useHtmlFor.d.ts +0 -2
  52. package/esm/hooks/useHtmlFor.js +0 -7
  53. package/esm/hooks/useMultipleForm.d.ts +0 -7
  54. package/esm/hooks/useMultipleForm.js +0 -18
  55. package/esm/instance/ruleIntsnace.d.ts +0 -49
  56. package/esm/instance/ruleIntsnace.js +0 -65
  57. package/src/hooks/attr/attr.FormItem.tsx +0 -174
  58. package/src/hooks/index.ts +0 -13
  59. package/src/hooks/register/register.FormHideItem.ts +0 -45
  60. package/src/hooks/register/register.FormItem.ts +0 -80
  61. package/src/hooks/register/register.FormList.ts +0 -49
  62. package/src/hooks/register/register.form.ts +0 -12
  63. package/src/hooks/useAttrs.ts +0 -64
  64. package/src/hooks/useEffect.ts +0 -13
  65. package/src/hooks/useForm.ts +0 -28
  66. package/src/hooks/useFormItem.ts +0 -28
  67. package/src/hooks/useFormItemParentName.ts +0 -49
  68. package/src/hooks/useFormList.ts +0 -28
  69. package/src/hooks/useHtmlFor.ts +0 -9
  70. package/src/hooks/useMultipleForm.ts +0 -29
  71. package/src/instance/ruleIntsnace.ts +0 -105
@@ -1,97 +0,0 @@
1
- import { FormInstanceBase, FormItemInstanceBase } from '@carefrees/form-utils';
2
- import { RegisterFormItemOptions } from './../register/register.FormItem';
3
- import { Ref } from 'vue';
4
- import type { RuleInstanceBase2 } from '../../instance/ruleIntsnace';
5
- export interface FormItemAttrOptions extends RegisterFormItemOptions {
6
- /**依赖更新项*/
7
- dependencies?: string[];
8
- /**通知 只用于校验规则提示 字段 */
9
- noticeOnlyRuleDataField?: string[];
10
- /**通知父级字段监听方法更新*/
11
- isNoticeParentField?: boolean;
12
- /**通知watch监听方法更新*/
13
- noticeWatchField?: string[];
14
- /**是否保护值(不进行表单项组件卸载重置初始值)*/
15
- preserve?: boolean;
16
- /**重写规则*/
17
- useRules?: (ruleInstance: Ref<RuleInstanceBase2>, form: FormInstanceBase, formItemInstance: FormItemInstanceBase) => void;
18
- /**输入框属性重写*/
19
- useAttrs?: (attrs: any, form: FormInstanceBase, formItemInstance: FormItemInstanceBase) => any;
20
- /**输入框属性*/
21
- inputAttrs?: Object;
22
- /**传递组件字段*/
23
- valuePropName?: string;
24
- /**取值字段(默认和valuePropName值相同)*/
25
- getValuePath?: string;
26
- /**自定义获取值*/
27
- getValueFromEvent?: (event: any, form: FormInstanceBase, formItemInstance: FormItemInstanceBase) => any;
28
- /**值格式化*/
29
- formatValue?: (value: any, form: FormInstanceBase, formItemInstance: FormItemInstanceBase, event: any) => any;
30
- /**触发数据更新之后触发(用于数据联动之类的)*/
31
- onAfterUpdate?: (value: any, form: FormInstanceBase, formItemInstance: FormItemInstanceBase, event: any) => void;
32
- /**事件名称*/
33
- trigger?: string;
34
- }
35
- /**表单项参数*/
36
- export declare const useFormItemAttr: (options: FormItemAttrOptions) => {
37
- valuePropName: string;
38
- htmlFor: import("vue").ComputedRef<string>;
39
- onChange: (event: any) => void;
40
- formItemInstance: FormItemInstanceBase;
41
- form: FormInstanceBase<any>;
42
- ruleInstance: Ref<RuleInstanceBase2, RuleInstanceBase2>;
43
- newAttrs: import("vue").ComputedRef<{
44
- name: string;
45
- id: string;
46
- constructor: Function;
47
- toString(): string;
48
- toLocaleString(): string;
49
- valueOf(): Object;
50
- hasOwnProperty(v: PropertyKey): boolean;
51
- isPrototypeOf(v: Object): boolean;
52
- propertyIsEnumerable(v: PropertyKey): boolean;
53
- }>;
54
- attrsLastData: Ref<{
55
- name: string;
56
- id: string;
57
- constructor: Function;
58
- toString: () => string;
59
- toLocaleString: () => string;
60
- valueOf: () => Object;
61
- hasOwnProperty: (v: PropertyKey) => boolean;
62
- isPrototypeOf: (v: Object) => boolean;
63
- propertyIsEnumerable: (v: PropertyKey) => boolean;
64
- }, {
65
- name: string;
66
- id: string;
67
- constructor: Function;
68
- toString(): string;
69
- toLocaleString(): string;
70
- valueOf(): Object;
71
- hasOwnProperty(v: PropertyKey): boolean;
72
- isPrototypeOf(v: Object): boolean;
73
- propertyIsEnumerable(v: PropertyKey): boolean;
74
- } | {
75
- name: string;
76
- id: string;
77
- constructor: Function;
78
- toString: () => string;
79
- toLocaleString: () => string;
80
- valueOf: () => Object;
81
- hasOwnProperty: (v: PropertyKey) => boolean;
82
- isPrototypeOf: (v: Object) => boolean;
83
- propertyIsEnumerable: (v: PropertyKey) => boolean;
84
- }>;
85
- validateResult: Ref<{
86
- tip: string | (string | undefined)[];
87
- isInvalid: boolean;
88
- }, {
89
- tip: string | (string | undefined)[];
90
- isInvalid: boolean;
91
- } | {
92
- tip: string | (string | undefined)[];
93
- isInvalid: boolean;
94
- }>;
95
- newSort: import("vue").ComputedRef<string>;
96
- newName: import("vue").ComputedRef<string>;
97
- };
@@ -1,97 +0,0 @@
1
- import { get } from "@carefrees/form-utils";
2
- import { useHtmlFor } from "../useHtmlFor.js";
3
- import { useRegisterFormItem } from "../register/register.FormItem.js";
4
- import { computed, ref, toValue, watch } from "vue";
5
- const useFormItemAttr = (options)=>{
6
- const { trigger = 'onChange', dependencies, noticeOnlyRuleDataField, isNoticeParentField, noticeWatchField, preserve, valuePropName = 'value', getValuePath = valuePropName, getValueFromEvent, formatValue, onAfterUpdate, useAttrs, useRules, inputAttrs, ...rest } = options;
7
- const { formItemInstance, form, ruleInstance, newName, newSort, deepRefData } = useRegisterFormItem({
8
- ...rest
9
- });
10
- formItemInstance.dependencies = dependencies;
11
- formItemInstance.noticeOnlyRuleDataField = noticeOnlyRuleDataField;
12
- formItemInstance.isNoticeParentField = isNoticeParentField;
13
- formItemInstance.onAfterUpdate = onAfterUpdate;
14
- formItemInstance.noticeWatchField = noticeWatchField;
15
- formItemInstance.preserve = preserve;
16
- const oldValue = ref(get(form.formData, toValue(newName)));
17
- watch(()=>[
18
- get(form.formData, toValue(newName)),
19
- toValue(newName)
20
- ], ()=>{
21
- oldValue.value = form.getFieldValue(toValue(newName));
22
- }, {
23
- immediate: true
24
- });
25
- const onValueChange = (event)=>{
26
- try {
27
- let value = event;
28
- if ('function' == typeof getValueFromEvent) value = getValueFromEvent(event, form, formItemInstance);
29
- else if (event && event.target && 'object' == typeof event.target && getValuePath in event.target) value = get(event.target, getValuePath);
30
- if ('function' == typeof formatValue) value = formatValue(value, form, formItemInstance, event);
31
- if (oldValue.value !== value) {
32
- form.updatedFieldValue(toValue(newName), value, 'validate');
33
- formItemInstance.onAfterUpdate?.(value, form, formItemInstance, event);
34
- if (Array.isArray(formItemInstance.noticeWatchField) && formItemInstance.noticeWatchField.length) form.noticeWatch(formItemInstance.noticeWatchField);
35
- if (Array.isArray(formItemInstance.noticeOnlyRuleDataField) && formItemInstance.noticeOnlyRuleDataField.length) form.onlyValidate(formItemInstance.noticeOnlyRuleDataField);
36
- if (formItemInstance.isNoticeParentField && formItemInstance.parentDataField) form.notice(formItemInstance.parentDataField);
37
- }
38
- } catch (error) {
39
- console.log(error);
40
- }
41
- };
42
- formItemInstance.onChange = onValueChange;
43
- const htmlFor = useHtmlFor(newName);
44
- watch(()=>htmlFor, ()=>{
45
- formItemInstance.htmlFor = htmlFor.value;
46
- }, {
47
- immediate: true
48
- });
49
- const newAttrs = computed(()=>{
50
- const _attr = inputAttrs || {};
51
- return {
52
- ..._attr,
53
- [trigger]: onValueChange,
54
- name: toValue(newName),
55
- id: toValue(htmlFor),
56
- [valuePropName]: toValue(oldValue)
57
- };
58
- });
59
- const attrsLastData = ref(toValue(newAttrs));
60
- watch(()=>[
61
- toValue(newAttrs),
62
- toValue(deepRefData),
63
- toValue(oldValue)
64
- ], ()=>{
65
- attrsLastData.value = useAttrs?.(toValue(newAttrs), form, formItemInstance) || toValue(newAttrs);
66
- }, {
67
- immediate: true
68
- });
69
- const validateResult = ref(toValue(ruleInstance).getValidateResult());
70
- watch(()=>[
71
- toValue(deepRefData),
72
- toValue(oldValue)
73
- ], ()=>{
74
- useRules?.(ruleInstance, form, formItemInstance);
75
- });
76
- watch(()=>[
77
- toValue(ruleInstance).messages,
78
- toValue(ruleInstance).rules,
79
- toValue(oldValue)
80
- ], ()=>{
81
- validateResult.value = toValue(ruleInstance).getValidateResult();
82
- });
83
- return {
84
- valuePropName,
85
- htmlFor,
86
- onChange: onValueChange,
87
- formItemInstance,
88
- form,
89
- ruleInstance,
90
- newAttrs,
91
- attrsLastData,
92
- validateResult,
93
- newSort,
94
- newName
95
- };
96
- };
97
- export { useFormItemAttr };
@@ -1,13 +0,0 @@
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';
@@ -1,13 +0,0 @@
1
- export * from "./useAttrs.js";
2
- export * from "./useForm.js";
3
- export * from "./useFormItem.js";
4
- export * from "./useFormList.js";
5
- export * from "./useHtmlFor.js";
6
- export * from "./useMultipleForm.js";
7
- export * from "./useFormItemParentName.js";
8
- export * from "./useEffect.js";
9
- export * from "./register/register.FormHideItem.js";
10
- export * from "./register/register.FormItem.js";
11
- export * from "./register/register.FormList.js";
12
- export * from "./register/register.form.js";
13
- export * from "./attr/attr.FormItem.js";
@@ -1,9 +0,0 @@
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: import("vue").Ref<any, any>;
8
- };
9
- export {};
@@ -1,42 +0,0 @@
1
- import { ref, toValue, watch } from "vue";
2
- import { FormHideItemInstanceBase } from "@carefrees/form-utils";
3
- import { useFormItemParentNameInject } from "../useFormItemParentName.js";
4
- import { useFormInject } from "../useForm.js";
5
- import { useEffect } from "../useEffect.js";
6
- const useRegisterFormHideItem = (options)=>{
7
- const { name, sort, isJoinParentField = true } = options;
8
- const form = useFormInject();
9
- const { newName, newSort } = useFormItemParentNameInject({
10
- name,
11
- sort,
12
- isJoinParentField
13
- });
14
- const hideItemInstance = ref(new FormHideItemInstanceBase().ctor(newName.value));
15
- const isHide = ref(form.getFieldHideValue(newName.value));
16
- watch(()=>[
17
- toValue(isHide)
18
- ], ()=>{
19
- hideItemInstance.value.preHideValue = isHide.value;
20
- }, {
21
- immediate: true
22
- });
23
- const setValue = ()=>{
24
- isHide.value = form.getFieldHideValue(newName.value);
25
- };
26
- hideItemInstance.value.updatedItem = setValue;
27
- watch(()=>[
28
- form,
29
- toValue(newSort)
30
- ], ()=>{
31
- hideItemInstance.value.instance = form;
32
- hideItemInstance.value.sort = toValue(newSort);
33
- }, {
34
- immediate: true
35
- });
36
- useEffect(()=>form.registerFormHideItem(toValue(hideItemInstance)));
37
- return {
38
- form,
39
- isHide
40
- };
41
- };
42
- export { useRegisterFormHideItem };
@@ -1,26 +0,0 @@
1
- /**
2
- * @description 注册组件
3
- */
4
- import { Ref } from 'vue';
5
- import type { RuleItem } from 'async-validator';
6
- import { RuleInstanceBase2 } from '../../instance/ruleIntsnace';
7
- export interface RegisterFormItemOptions {
8
- /**字段*/
9
- name: string;
10
- /**规则*/
11
- rules?: RuleItem[];
12
- /**排序值*/
13
- sort?: string;
14
- /**是否拼接父级字段*/
15
- isJoinParentField?: boolean;
16
- }
17
- /**注册表单项到表单实例中*/
18
- export declare const useRegisterFormItem: (options: RegisterFormItemOptions) => {
19
- ruleInstance: Ref<RuleInstanceBase2, RuleInstanceBase2>;
20
- formItemInstance: import("@carefrees/form-utils").FormItemInstanceBase;
21
- form: import("@carefrees/form-utils").FormInstanceBase<any>;
22
- newName: import("vue").ComputedRef<string>;
23
- newSort: import("vue").ComputedRef<string>;
24
- parentItem: import("vue").ComputedRef<import("../..").PartialComputedRefs<Omit<import("..").FormItemParentNamOptions, "isJoinParentField">>>;
25
- deepRefData: Ref<any, any>;
26
- };
@@ -1,67 +0,0 @@
1
- import { ref, toValue, watch } from "vue";
2
- import { useFormInject } from "../useForm.js";
3
- import { useFormItem } from "../useFormItem.js";
4
- import { useFormItemParentNameInject } from "../useFormItemParentName.js";
5
- import { useEffect } from "../useEffect.js";
6
- import { RuleInstanceBase2 } from "../../instance/ruleIntsnace.js";
7
- const useRegisterFormItem = (options)=>{
8
- const { name, rules, sort, isJoinParentField = true } = options;
9
- const form = useFormInject();
10
- const deepRefData = ref({});
11
- const { newName, newSort, parentItem } = useFormItemParentNameInject({
12
- name,
13
- sort,
14
- isJoinParentField
15
- });
16
- const ruleInstance = ref(new RuleInstanceBase2());
17
- const formItemInstance = useFormItem();
18
- watch(()=>[
19
- form
20
- ], ()=>{
21
- ruleInstance.value.instance = form;
22
- formItemInstance.instance = form;
23
- }, {
24
- immediate: true
25
- });
26
- watch(()=>[
27
- toValue(newName)
28
- ], ()=>{
29
- ruleInstance.value.ctor(toValue(newName), rules || []);
30
- formItemInstance.ctor(toValue(newName), toValue(ruleInstance));
31
- }, {
32
- immediate: true
33
- });
34
- watch(()=>[
35
- toValue(newSort)
36
- ], ()=>{
37
- ruleInstance.value.sort = toValue(newSort);
38
- formItemInstance.sort = toValue(newSort);
39
- }, {
40
- immediate: true
41
- });
42
- watch(()=>[
43
- toValue(parentItem)
44
- ], ()=>{
45
- formItemInstance.parentDataField = toValue(toValue(parentItem).name);
46
- }, {
47
- immediate: true
48
- });
49
- const updated = ()=>{
50
- deepRefData.value = {
51
- __temp: new Date().valueOf()
52
- };
53
- };
54
- formItemInstance.updated = updated;
55
- ruleInstance.value.updated = updated;
56
- useEffect(()=>form.registerFormItem(formItemInstance));
57
- return {
58
- ruleInstance,
59
- formItemInstance,
60
- form,
61
- newName,
62
- newSort,
63
- parentItem,
64
- deepRefData
65
- };
66
- };
67
- export { useRegisterFormItem };
@@ -1,9 +0,0 @@
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("vue").Ref<import("../../instance/ruleIntsnace").RuleInstanceBase2, import("../../instance/ruleIntsnace").RuleInstanceBase2>;
7
- formItemInstance: import("@carefrees/form-utils").FormItemInstanceBase;
8
- formListInstance: import("@carefrees/form-utils").FormListInstanceBase;
9
- };
@@ -1,42 +0,0 @@
1
- import { toValue, watch } from "vue";
2
- import { useRegisterFormItem } from "./register.FormItem.js";
3
- import { useFormList } from "../useFormList.js";
4
- import { useEffect } from "../useEffect.js";
5
- const useRegisterFormList = (options)=>{
6
- const { ruleInstance, formItemInstance, form, newName, parentItem } = useRegisterFormItem(options);
7
- const formListInstance = useFormList();
8
- watch(()=>[
9
- toValue(newName)
10
- ], ()=>{
11
- formListInstance.ctor(toValue(newName));
12
- }, {
13
- immediate: true
14
- });
15
- watch(()=>[
16
- form,
17
- formItemInstance,
18
- toValue(ruleInstance)
19
- ], ()=>{
20
- formListInstance.instance = form;
21
- formListInstance.formItemInstance = formItemInstance;
22
- formListInstance.rule = toValue(ruleInstance);
23
- }, {
24
- immediate: true
25
- });
26
- watch(()=>[
27
- options.sort,
28
- toValue(parentItem)
29
- ], ()=>{
30
- formListInstance.sort = toValue(parentItem.value.sort);
31
- formListInstance.parentDataField = toValue(parentItem.value.name);
32
- }, {
33
- immediate: true
34
- });
35
- useEffect(()=>form.registerFormList(newName.value, formListInstance));
36
- return {
37
- ruleInstance,
38
- formItemInstance,
39
- formListInstance
40
- };
41
- };
42
- export { useRegisterFormList };
@@ -1,3 +0,0 @@
1
- import { FormInstanceBase } from '@carefrees/form-utils';
2
- /**注册表单实例到多表单收集实例中*/
3
- export declare const useRegisterForm: (form: FormInstanceBase, name?: string) => import("@carefrees/form-utils").MultipleInstanceBase;
@@ -1,10 +0,0 @@
1
- import { useMultipleFormInject } from "../useMultipleForm.js";
2
- import { useEffect } from "../useEffect.js";
3
- const useRegisterForm = (form, name)=>{
4
- const multipleForm = useMultipleFormInject();
5
- useEffect(()=>{
6
- if (name) return multipleForm.ctor(name, form);
7
- });
8
- return multipleForm;
9
- };
10
- export { useRegisterForm };
@@ -1,25 +0,0 @@
1
- /**公共属性*/
2
- import { StyleValue, ComputedRef } from 'vue';
3
- import { ComputedRefBase } from '../interface';
4
- export type AttrsOptions = {
5
- /**列数据*/
6
- colCount?: ComputedRefBase<number | undefined>;
7
- /**规则校验失败错误提示位置*/
8
- errorLayout?: ComputedRefBase<'left-bottom' | 'right-bottom' | 'top-right' | 'top-left' | undefined>;
9
- /**label显示模式*/
10
- labelMode?: ComputedRefBase<'left' | 'top' | 'hide' | undefined>;
11
- /**是否显示label后的冒号*/
12
- showColon?: ComputedRefBase<boolean | undefined>;
13
- /**表单项 className*/
14
- formItemClass?: ComputedRefBase<string | undefined>;
15
- /**表单项 style*/
16
- formItemStyle?: ComputedRefBase<StyleValue | undefined>;
17
- /**表单项 label className*/
18
- formItemLabelClass?: ComputedRefBase<string | undefined>;
19
- /**表单项 label style*/
20
- formItemLabelStyle?: ComputedRefBase<StyleValue | undefined>;
21
- };
22
- /**公共属性 Context */
23
- export declare function useAttrsProvide(options: AttrsOptions): void;
24
- /**子项中获取公共属性*/
25
- export declare function useAttrsInject(): ComputedRef<AttrsOptions>;
@@ -1,26 +0,0 @@
1
- import { computed, inject, provide, reactive, ref } from "vue";
2
- const attrsProvideSymbol = Symbol('carefrees-attrs');
3
- function useAttrsProvide(options) {
4
- const { colCount = ref(4), errorLayout = ref('left-bottom'), labelMode = ref('top'), showColon = ref(true), formItemClass, formItemStyle, formItemLabelClass, formItemLabelStyle } = options;
5
- const data = computed(()=>({
6
- colCount,
7
- errorLayout,
8
- labelMode,
9
- showColon,
10
- formItemClass,
11
- formItemStyle,
12
- formItemLabelClass,
13
- formItemLabelStyle
14
- }));
15
- provide(attrsProvideSymbol, reactive(data));
16
- }
17
- function useAttrsInject() {
18
- const attrs = inject(attrsProvideSymbol, computed(()=>({
19
- colCount: ref(4),
20
- errorLayout: ref('left-bottom'),
21
- labelMode: ref('top'),
22
- showColon: ref(true)
23
- })));
24
- return attrs;
25
- }
26
- export { useAttrsInject, useAttrsProvide };
@@ -1,2 +0,0 @@
1
- /**挂载卸载*/
2
- export declare const useEffect: (fun: () => Function | undefined) => void;
@@ -1,12 +0,0 @@
1
- import { onMounted, onUnmounted, ref } from "vue";
2
- const useEffect = (fun)=>{
3
- const unRegisterRef = ref();
4
- onMounted(()=>{
5
- unRegisterRef.value = fun();
6
- });
7
- onUnmounted(()=>{
8
- 'function' == typeof unRegisterRef.value && unRegisterRef.value();
9
- unRegisterRef.value = void 0;
10
- });
11
- };
12
- export { useEffect };
@@ -1,8 +0,0 @@
1
- import { FormInstanceBase } from '@carefrees/form-utils';
2
- import { Ref } from 'vue';
3
- /**表单实例 Context */
4
- export declare function useFormProvide<T = any>(form: FormInstanceBase<T>): void;
5
- /**子项中获取表单实例*/
6
- export declare function useFormInject<T = any>(): FormInstanceBase<T>;
7
- /**初始化表单实例*/
8
- export declare function useForm<T = any>(form?: FormInstanceBase<T>): Ref<FormInstanceBase<T>>;
@@ -1,17 +0,0 @@
1
- import { FormInstanceBase } from "@carefrees/form-utils";
2
- import { inject, provide, ref } from "vue";
3
- const formProvideSymbol = Symbol('carefrees-form');
4
- function useFormProvide(form) {
5
- provide(formProvideSymbol, form);
6
- }
7
- function useFormInject() {
8
- const form = inject(formProvideSymbol, new FormInstanceBase());
9
- return form;
10
- }
11
- function useForm(form) {
12
- const refForm = ref();
13
- if (!refForm.value) if (form) refForm.value = form;
14
- else refForm.value = new FormInstanceBase();
15
- return refForm;
16
- }
17
- export { useForm, useFormInject, useFormProvide };
@@ -1,7 +0,0 @@
1
- import { FormItemInstanceBase } from '@carefrees/form-utils';
2
- /**表单项实例 Context */
3
- export declare function useFormItemProvide(formItem: FormItemInstanceBase): void;
4
- /**子项中获取表单项实例*/
5
- export declare function useFormItemInject(): FormItemInstanceBase;
6
- /**s初始化 表单项实例*/
7
- export declare function useFormItem(formItem?: FormItemInstanceBase): FormItemInstanceBase;
@@ -1,17 +0,0 @@
1
- import { FormItemInstanceBase } from "@carefrees/form-utils";
2
- import { inject, provide, ref } from "vue";
3
- const formItemProvideSymbol = Symbol('carefrees-form-item');
4
- function useFormItemProvide(formItem) {
5
- provide(formItemProvideSymbol, formItem);
6
- }
7
- function useFormItemInject() {
8
- const formItem = inject(formItemProvideSymbol, new FormItemInstanceBase());
9
- return formItem;
10
- }
11
- function useFormItem(formItem) {
12
- const refForm = ref();
13
- if (!refForm.value) if (formItem) refForm.value = formItem;
14
- else refForm.value = new FormItemInstanceBase();
15
- return refForm.value;
16
- }
17
- export { useFormItem, useFormItemInject, useFormItemProvide };
@@ -1,18 +0,0 @@
1
- import { ComputedRef } from 'vue';
2
- import { PartialComputedRefs } from '../interface';
3
- export interface FormItemParentNamOptions {
4
- /**字段*/
5
- name: string;
6
- /**排序*/
7
- sort?: string;
8
- /**是否拼接父级字段*/
9
- isJoinParentField?: boolean;
10
- }
11
- export type FormItemParentNameProviderProps = PartialComputedRefs<Omit<FormItemParentNamOptions, 'isJoinParentField'>>;
12
- export declare const useFormItemParentNameProvide: (props: FormItemParentNameProviderProps) => void;
13
- /**表单项获取父级字段*/
14
- export declare const useFormItemParentNameInject: (options: FormItemParentNamOptions) => {
15
- newName: ComputedRef<string>;
16
- newSort: ComputedRef<string>;
17
- parentItem: ComputedRef<PartialComputedRefs<Omit<FormItemParentNamOptions, "isJoinParentField">>>;
18
- };
@@ -1,47 +0,0 @@
1
- import { computed, inject, provide, ref, toValue } from "vue";
2
- const parentNameProvideSymbol = Symbol('carefrees-parent-name');
3
- const useFormItemParentNameProvide = (props)=>{
4
- const { name, sort } = props;
5
- provide(parentNameProvideSymbol, computed(()=>({
6
- name,
7
- sort
8
- })));
9
- };
10
- const useFormItemParentNameInject = (options)=>{
11
- const { isJoinParentField = true, sort, name } = options;
12
- const parentItem = inject(parentNameProvideSymbol, computed(()=>({
13
- name: ref(''),
14
- sort: ref('')
15
- })));
16
- const newName = computed(()=>{
17
- const _name = toValue(parentItem.value.name);
18
- if (_name && isJoinParentField) {
19
- if (/^\./.test(`${name}`)) ;
20
- else if (name) return [
21
- _name,
22
- '.',
23
- name
24
- ].filter(Boolean).join('');
25
- return [
26
- _name,
27
- name
28
- ].filter(Boolean).join('');
29
- }
30
- return [
31
- name
32
- ].filter(Boolean).join('');
33
- });
34
- const newSort = computed(()=>{
35
- const _sort = toValue(parentItem.value.sort);
36
- return [
37
- isJoinParentField ? _sort : '',
38
- sort
39
- ].filter(Boolean).join('-');
40
- });
41
- return {
42
- newName,
43
- newSort,
44
- parentItem
45
- };
46
- };
47
- export { useFormItemParentNameInject, useFormItemParentNameProvide };
@@ -1,7 +0,0 @@
1
- import { FormListInstanceBase } from '@carefrees/form-utils';
2
- /**表单List实例 Context */
3
- export declare function useFormListProvide(formList: FormListInstanceBase): void;
4
- /**子项中获取表单List实例*/
5
- export declare function useFormListInject(): FormListInstanceBase;
6
- /**初始化 表单List实例*/
7
- export declare function useFormList(formList?: FormListInstanceBase): FormListInstanceBase;
@@ -1,17 +0,0 @@
1
- import { FormListInstanceBase } from "@carefrees/form-utils";
2
- import { inject, provide, ref } from "vue";
3
- const formListProvideSymbol = Symbol('carefrees-form-list');
4
- function useFormListProvide(formList) {
5
- provide(formListProvideSymbol, formList);
6
- }
7
- function useFormListInject() {
8
- const formList = inject(formListProvideSymbol, new FormListInstanceBase());
9
- return formList;
10
- }
11
- function useFormList(formList) {
12
- const refForm = ref();
13
- if (!refForm.value) if (formList) refForm.value = formList;
14
- else refForm.value = new FormListInstanceBase();
15
- return refForm.value;
16
- }
17
- export { useFormList, useFormListInject, useFormListProvide };