@carefrees/form-utils-vue 0.0.10 → 0.0.12

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 (161) hide show
  1. package/README.md +56 -2
  2. package/assets/index.css +23 -12
  3. package/esm/component.js +3 -0
  4. package/esm/form/form.js +156 -0
  5. package/esm/form/form.vue.d.ts +10 -7
  6. package/esm/form/index.d.ts +12 -12
  7. package/esm/form/index.js +4 -0
  8. package/esm/formItem/form.Item.base.js +162 -0
  9. package/esm/formItem/form.Item.base.vue.d.ts +6 -8
  10. package/esm/formItem/form.hide.item.js +126 -0
  11. package/esm/formItem/form.hide.item.vue.d.ts +6 -8
  12. package/esm/formItem/formItem.js +155 -0
  13. package/esm/formItem/formItem.vue.d.ts +6 -9
  14. package/esm/formItem/index.d.ts +24 -37
  15. package/esm/formItem/index.js +8 -0
  16. package/esm/hooks/attr/attr.FormItem.d.ts +5 -5
  17. package/esm/hooks/attr/attr.FormItem.js +97 -0
  18. package/esm/hooks/index.js +13 -0
  19. package/esm/hooks/register/register.FormHideItem.d.ts +2 -2
  20. package/esm/hooks/register/register.FormHideItem.js +42 -0
  21. package/esm/hooks/register/register.FormItem.d.ts +9 -6
  22. package/esm/hooks/register/register.FormItem.js +67 -0
  23. package/esm/hooks/register/register.FormList.d.ts +3 -3
  24. package/esm/hooks/register/register.FormList.js +42 -0
  25. package/esm/hooks/register/register.form.d.ts +1 -1
  26. package/esm/hooks/register/register.form.js +10 -0
  27. package/esm/hooks/useAttrs.d.ts +1 -0
  28. package/esm/hooks/useAttrs.js +26 -0
  29. package/esm/hooks/useEffect.js +12 -0
  30. package/esm/hooks/useForm.d.ts +1 -1
  31. package/esm/hooks/useForm.js +17 -0
  32. package/esm/hooks/useFormItem.js +17 -0
  33. package/esm/hooks/useFormItemParentName.js +47 -0
  34. package/esm/hooks/useFormList.js +17 -0
  35. package/esm/hooks/useHtmlFor.d.ts +1 -1
  36. package/esm/hooks/useHtmlFor.js +7 -0
  37. package/esm/hooks/useMultipleForm.d.ts +1 -1
  38. package/esm/hooks/useMultipleForm.js +18 -0
  39. package/esm/index.d.ts +1 -1
  40. package/esm/index.js +13 -0
  41. package/esm/instance/ruleIntsnace.d.ts +1 -1
  42. package/esm/instance/ruleIntsnace.js +65 -0
  43. package/esm/interface/index.d.ts +2 -0
  44. package/esm/interface/index.js +0 -0
  45. package/esm/interface/layout.formItem.js +0 -0
  46. package/esm/interface/layout.js +0 -0
  47. package/esm/layout/index.d.ts +24 -33
  48. package/esm/layout/index.js +8 -0
  49. package/esm/layout/layout.form.rows.js +21 -0
  50. package/esm/layout/layout.form.rows.vue.d.ts +8 -5
  51. package/esm/layout/layout.formItem.js +195 -0
  52. package/esm/layout/layout.formItem.vue.d.ts +6 -9
  53. package/esm/layout/layout.js +160 -0
  54. package/esm/layout/layout.vue.d.ts +6 -8
  55. package/esm/utils/index.js +1 -0
  56. package/esm/utils/withInstall.d.ts +2 -2
  57. package/esm/utils/withInstall.js +15 -0
  58. package/package.json +6 -8
  59. package/src/form/form.vue +8 -1
  60. package/src/interface/index.ts +2 -0
  61. package/esm/component.mjs +0 -12
  62. package/esm/form/form.vue.mjs +0 -110
  63. package/esm/form/form.vue2.mjs +0 -4
  64. package/esm/form/index.mjs +0 -6
  65. package/esm/formItem/form.Item.base.vue.mjs +0 -114
  66. package/esm/formItem/form.Item.base.vue2.mjs +0 -4
  67. package/esm/formItem/form.hide.item.vue.mjs +0 -78
  68. package/esm/formItem/form.hide.item.vue2.mjs +0 -4
  69. package/esm/formItem/formItem.vue.mjs +0 -102
  70. package/esm/formItem/formItem.vue2.mjs +0 -4
  71. package/esm/formItem/index.mjs +0 -12
  72. package/esm/hooks/attr/attr.FormItem.mjs +0 -120
  73. package/esm/hooks/register/register.FormHideItem.mjs +0 -38
  74. package/esm/hooks/register/register.FormItem.mjs +0 -55
  75. package/esm/hooks/register/register.FormList.mjs +0 -43
  76. package/esm/hooks/register/register.form.mjs +0 -12
  77. package/esm/hooks/useAttrs.mjs +0 -43
  78. package/esm/hooks/useEffect.mjs +0 -14
  79. package/esm/hooks/useForm.mjs +0 -26
  80. package/esm/hooks/useFormItem.mjs +0 -26
  81. package/esm/hooks/useFormItemParentName.mjs +0 -37
  82. package/esm/hooks/useFormList.mjs +0 -26
  83. package/esm/hooks/useHtmlFor.mjs +0 -11
  84. package/esm/hooks/useMultipleForm.mjs +0 -27
  85. package/esm/index.mjs +0 -59
  86. package/esm/instance/ruleIntsnace.mjs +0 -73
  87. package/esm/layout/index.mjs +0 -12
  88. package/esm/layout/layout.form.rows.vue.mjs +0 -31
  89. package/esm/layout/layout.form.rows.vue2.mjs +0 -4
  90. package/esm/layout/layout.formItem.vue.mjs +0 -216
  91. package/esm/layout/layout.formItem.vue2.mjs +0 -4
  92. package/esm/layout/layout.vue.mjs +0 -166
  93. package/esm/layout/layout.vue2.mjs +0 -4
  94. package/esm/utils/withInstall.mjs +0 -22
  95. package/lib/component.d.ts +0 -3
  96. package/lib/component.js +0 -12
  97. package/lib/form/form.vue.d.ts +0 -19
  98. package/lib/form/form.vue.js +0 -110
  99. package/lib/form/form.vue2.js +0 -4
  100. package/lib/form/index.d.ts +0 -37
  101. package/lib/form/index.js +0 -6
  102. package/lib/formItem/form.Item.base.vue.d.ts +0 -16
  103. package/lib/formItem/form.Item.base.vue.js +0 -114
  104. package/lib/formItem/form.Item.base.vue2.js +0 -4
  105. package/lib/formItem/form.hide.item.vue.d.ts +0 -16
  106. package/lib/formItem/form.hide.item.vue.js +0 -78
  107. package/lib/formItem/form.hide.item.vue2.js +0 -4
  108. package/lib/formItem/formItem.vue.d.ts +0 -18
  109. package/lib/formItem/formItem.vue.js +0 -102
  110. package/lib/formItem/formItem.vue2.js +0 -4
  111. package/lib/formItem/index.d.ts +0 -71
  112. package/lib/formItem/index.js +0 -12
  113. package/lib/hooks/attr/attr.FormItem.d.ts +0 -97
  114. package/lib/hooks/attr/attr.FormItem.js +0 -120
  115. package/lib/hooks/index.d.ts +0 -13
  116. package/lib/hooks/register/register.FormHideItem.d.ts +0 -9
  117. package/lib/hooks/register/register.FormHideItem.js +0 -38
  118. package/lib/hooks/register/register.FormItem.d.ts +0 -23
  119. package/lib/hooks/register/register.FormItem.js +0 -55
  120. package/lib/hooks/register/register.FormList.d.ts +0 -9
  121. package/lib/hooks/register/register.FormList.js +0 -43
  122. package/lib/hooks/register/register.form.d.ts +0 -3
  123. package/lib/hooks/register/register.form.js +0 -12
  124. package/lib/hooks/useAttrs.d.ts +0 -24
  125. package/lib/hooks/useAttrs.js +0 -43
  126. package/lib/hooks/useEffect.d.ts +0 -2
  127. package/lib/hooks/useEffect.js +0 -14
  128. package/lib/hooks/useForm.d.ts +0 -8
  129. package/lib/hooks/useForm.js +0 -26
  130. package/lib/hooks/useFormItem.d.ts +0 -7
  131. package/lib/hooks/useFormItem.js +0 -26
  132. package/lib/hooks/useFormItemParentName.d.ts +0 -18
  133. package/lib/hooks/useFormItemParentName.js +0 -37
  134. package/lib/hooks/useFormList.d.ts +0 -7
  135. package/lib/hooks/useFormList.js +0 -26
  136. package/lib/hooks/useHtmlFor.d.ts +0 -2
  137. package/lib/hooks/useHtmlFor.js +0 -11
  138. package/lib/hooks/useMultipleForm.d.ts +0 -7
  139. package/lib/hooks/useMultipleForm.js +0 -27
  140. package/lib/index.d.ts +0 -11
  141. package/lib/index.js +0 -59
  142. package/lib/instance/ruleIntsnace.d.ts +0 -49
  143. package/lib/instance/ruleIntsnace.js +0 -73
  144. package/lib/interface/index.d.ts +0 -36
  145. package/lib/interface/layout.d.ts +0 -28
  146. package/lib/interface/layout.formItem.d.ts +0 -39
  147. package/lib/layout/index.d.ts +0 -65
  148. package/lib/layout/index.js +0 -12
  149. package/lib/layout/layout.form.rows.vue.d.ts +0 -10
  150. package/lib/layout/layout.form.rows.vue.js +0 -31
  151. package/lib/layout/layout.form.rows.vue2.js +0 -4
  152. package/lib/layout/layout.formItem.vue.d.ts +0 -18
  153. package/lib/layout/layout.formItem.vue.js +0 -216
  154. package/lib/layout/layout.formItem.vue2.js +0 -4
  155. package/lib/layout/layout.vue.d.ts +0 -16
  156. package/lib/layout/layout.vue.js +0 -166
  157. package/lib/layout/layout.vue2.js +0 -4
  158. package/lib/utils/index.d.ts +0 -1
  159. package/lib/utils/withInstall.d.ts +0 -3
  160. package/lib/utils/withInstall.js +0 -22
  161. package/src/vite-env.d.ts +0 -1
@@ -1,5 +1,8 @@
1
+ /**
2
+ * @description 注册组件
3
+ */
1
4
  import { Ref } from 'vue';
2
- import { RuleItem } from 'async-validator';
5
+ import type { RuleItem } from 'async-validator';
3
6
  import { RuleInstanceBase2 } from '../../instance/ruleIntsnace';
4
7
  export interface RegisterFormItemOptions {
5
8
  /**字段*/
@@ -14,10 +17,10 @@ export interface RegisterFormItemOptions {
14
17
  /**注册表单项到表单实例中*/
15
18
  export declare const useRegisterFormItem: (options: RegisterFormItemOptions) => {
16
19
  ruleInstance: Ref<RuleInstanceBase2, RuleInstanceBase2>;
17
- formItemInstance: import('@carefrees/form-utils').FormItemInstanceBase;
18
- form: import('@carefrees/form-utils').FormInstanceBase<any>;
19
- newName: import('vue').ComputedRef<string>;
20
- newSort: import('vue').ComputedRef<string>;
21
- parentItem: import('vue').ComputedRef<import('../..').PartialComputedRefs<Omit<import('../useFormItemParentName').FormItemParentNamOptions, "isJoinParentField">>>;
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">>>;
22
25
  deepRefData: Ref<any, any>;
23
26
  };
@@ -0,0 +1,67 @@
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 };
@@ -3,7 +3,7 @@ export interface RegisterFormListOptions extends RegisterFormItemOptions {
3
3
  }
4
4
  /**注册表单List到表单实例中*/
5
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;
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
9
  };
@@ -0,0 +1,42 @@
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 +1,3 @@
1
1
  import { FormInstanceBase } from '@carefrees/form-utils';
2
2
  /**注册表单实例到多表单收集实例中*/
3
- export declare const useRegisterForm: (form: FormInstanceBase, name?: string) => import('@carefrees/form-utils').MultipleInstanceBase;
3
+ export declare const useRegisterForm: (form: FormInstanceBase, name?: string) => import("@carefrees/form-utils").MultipleInstanceBase;
@@ -0,0 +1,10 @@
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,3 +1,4 @@
1
+ /**公共属性*/
1
2
  import { StyleValue, ComputedRef } from 'vue';
2
3
  import { ComputedRefBase } from '../interface';
3
4
  export type AttrsOptions = {
@@ -0,0 +1,26 @@
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 };
@@ -0,0 +1,12 @@
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 };
@@ -5,4 +5,4 @@ export declare function useFormProvide<T = any>(form: FormInstanceBase<T>): void
5
5
  /**子项中获取表单实例*/
6
6
  export declare function useFormInject<T = any>(): FormInstanceBase<T>;
7
7
  /**初始化表单实例*/
8
- export declare function useForm<T = any>(form?: FormInstanceBase<T>): Ref<FormInstanceBase<T>, FormInstanceBase<T>>;
8
+ export declare function useForm<T = any>(form?: FormInstanceBase<T>): Ref<FormInstanceBase<T>>;
@@ -0,0 +1,17 @@
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 };
@@ -0,0 +1,17 @@
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 };
@@ -0,0 +1,47 @@
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 };
@@ -0,0 +1,17 @@
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 };
@@ -1,2 +1,2 @@
1
1
  import { Ref } from 'vue';
2
- export declare const useHtmlFor: (suffix: Ref<string>) => import('vue').ComputedRef<string>;
2
+ export declare const useHtmlFor: (suffix: Ref<string>) => import("vue").ComputedRef<string>;
@@ -0,0 +1,7 @@
1
+ import { computed, ref } from "vue";
2
+ let localId = 0;
3
+ const useHtmlFor = (suffix)=>{
4
+ const count = ref(localId++);
5
+ return computed(()=>`carefree-vue-form-item_${count.value.toString(32)}_${suffix.value}`);
6
+ };
7
+ export { useHtmlFor };
@@ -1,4 +1,4 @@
1
- import { MultipleInstanceBase } from '@carefrees/form-utils';
1
+ import { MultipleInstanceBase } from "@carefrees/form-utils";
2
2
  /**多表单收集 Context */
3
3
  export declare function useMultipleFormProvide(multipleForm?: MultipleInstanceBase): void;
4
4
  /**子项中获取 多表单收集 实例*/
@@ -0,0 +1,18 @@
1
+ import { MultipleInstanceBase } from "@carefrees/form-utils";
2
+ import { inject, provide, ref } from "vue";
3
+ const multipleFormProvideSymbol = Symbol("carefrees-multiple-form");
4
+ function useMultipleFormProvide(multipleForm) {
5
+ const newMultipleForm = useMultipleForm(multipleForm);
6
+ provide(multipleFormProvideSymbol, newMultipleForm);
7
+ }
8
+ function useMultipleFormInject() {
9
+ const multipleForm = inject(multipleFormProvideSymbol, new MultipleInstanceBase());
10
+ return multipleForm;
11
+ }
12
+ function useMultipleForm(multipleForm) {
13
+ const refForm = ref();
14
+ if (!refForm.value) if (multipleForm) refForm.value = multipleForm;
15
+ else refForm.value = new MultipleInstanceBase();
16
+ return refForm.value;
17
+ }
18
+ export { useMultipleForm, useMultipleFormInject, useMultipleFormProvide };
package/esm/index.d.ts CHANGED
@@ -1,10 +1,10 @@
1
- import { App } from 'vue';
2
1
  export * from './hooks';
3
2
  export * from './component';
4
3
  export * from './utils';
5
4
  export * from './interface';
6
5
  export * from './interface/layout';
7
6
  export * from './interface/layout.formItem';
7
+ import { App } from 'vue';
8
8
  declare const _default: {
9
9
  install: (app: App) => void;
10
10
  };
package/esm/index.js ADDED
@@ -0,0 +1,13 @@
1
+ export * from "./hooks/index.js";
2
+ export * from "./component.js";
3
+ export * from "./utils/index.js";
4
+ export * from "./interface/index.js";
5
+ export * from "./interface/layout.js";
6
+ export * from "./interface/layout.formItem.js";
7
+ import * as __WEBPACK_EXTERNAL_MODULE__component_js_7f599402__ from "./component.js";
8
+ const src = {
9
+ install: (app)=>{
10
+ for(const c in __WEBPACK_EXTERNAL_MODULE__component_js_7f599402__)app.use(__WEBPACK_EXTERNAL_MODULE__component_js_7f599402__[c]);
11
+ }
12
+ };
13
+ export { src as default };
@@ -1,5 +1,5 @@
1
1
  import { RuleItem } from 'async-validator';
2
- import { MessageType, FormInstanceBase } from '@carefrees/form-utils';
2
+ import type { MessageType, FormInstanceBase } from '@carefrees/form-utils';
3
3
  import { Ref } from 'vue';
4
4
  export declare class RuleInstanceBase2 {
5
5
  /**
@@ -0,0 +1,65 @@
1
+ import async_validator from "async-validator";
2
+ import { ref, toValue } from "vue";
3
+ class RuleInstanceBase2 {
4
+ sort;
5
+ instance;
6
+ name = '';
7
+ rules = ref([]);
8
+ messages = ref([]);
9
+ updated;
10
+ isRequired = ()=>{
11
+ if (this.instance?.getFieldHideRulesValue?.(this.name)) return false;
12
+ const findItem = (toValue(this.rules) || []).find((item)=>item?.required);
13
+ return !!findItem;
14
+ };
15
+ ctor = (name, rules)=>{
16
+ this.name = name;
17
+ this.rules.value = rules || [];
18
+ return this;
19
+ };
20
+ isValidate = ()=>{
21
+ if (this.instance?.getFieldHideRulesValue?.(this.name)) return false;
22
+ const _rules = toValue(this.rules);
23
+ return !!(Array.isArray(_rules) && _rules.length);
24
+ };
25
+ updatedMessages = (messages)=>{
26
+ this.messages.value = messages || [];
27
+ this.updated?.({});
28
+ };
29
+ updatedRules = (rules)=>{
30
+ this.rules.value = rules;
31
+ this.updatedMessages?.([]);
32
+ };
33
+ validate = (isOnly = false)=>new Promise((resolve, reject)=>{
34
+ const value = this.instance?.getFieldValue?.(this.name);
35
+ if (this.instance?.getFieldHideRulesValue?.(this.name)) {
36
+ this.updatedMessages([]);
37
+ resolve({
38
+ [this.name]: value
39
+ });
40
+ }
41
+ new async_validator({
42
+ [this.name]: toValue(this.rules) || []
43
+ }).validate({
44
+ [this.name]: value
45
+ }).then((values)=>{
46
+ if (!isOnly) this.updatedMessages([]);
47
+ resolve(values);
48
+ }).catch(({ errors })=>{
49
+ if (Array.isArray(errors)) {
50
+ if (!isOnly) this.updatedMessages(errors);
51
+ reject(errors);
52
+ } else reject();
53
+ });
54
+ });
55
+ getValidateResult = ()=>{
56
+ const _messages = toValue(this.messages);
57
+ const tip = Array.isArray(_messages) ? _messages.map((it)=>it.message) : '';
58
+ const isInvalid = Array.isArray(tip) ? !!tip.length : !!tip;
59
+ return {
60
+ tip,
61
+ isInvalid
62
+ };
63
+ };
64
+ }
65
+ export { RuleInstanceBase2 };
@@ -33,4 +33,6 @@ export interface FormProps<T = any> extends FormLayoutProps {
33
33
  name?: string;
34
34
  /**隐藏规则校验*/
35
35
  hideRuleData?: Record<string, boolean>;
36
+ /**背景颜色*/
37
+ bgcolor?: string;
36
38
  }
File without changes
File without changes
File without changes
@@ -1,65 +1,56 @@
1
- export declare const Layout: import('../utils').SFCWithInstall<{
2
- new (...args: any[]): import('vue').CreateComponentPublicInstanceWithMixins<Readonly<import('..').FormLayoutProps> & Readonly<{}>, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, import('vue').PublicProps, {}, false, {}, {}, import('vue').GlobalComponents, import('vue').GlobalDirectives, string, {}, any, import('vue').ComponentProvideOptions, {
1
+ export declare const Layout: import("../utils").SFCWithInstall<{
2
+ new (...args: any[]): import("vue").CreateComponentPublicInstanceWithMixins<Readonly<import("../index.js").FormLayoutProps> & Readonly<{}>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, import("vue").PublicProps, {}, false, {}, {}, import("vue").GlobalComponents, import("vue").GlobalDirectives, string, {}, any, import("vue").ComponentProvideOptions, {
3
3
  P: {};
4
4
  B: {};
5
5
  D: {};
6
6
  C: {};
7
7
  M: {};
8
8
  Defaults: {};
9
- }, Readonly<import('..').FormLayoutProps> & Readonly<{}>, {}, {}, {}, {}, {}>;
10
- __isFragment?: undefined;
11
- __isTeleport?: undefined;
12
- __isSuspense?: undefined;
13
- } & import('vue').ComponentOptionsBase<Readonly<import('..').FormLayoutProps> & Readonly<{}>, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, {}, {}, string, {}, import('vue').GlobalComponents, import('vue').GlobalDirectives, string, import('vue').ComponentProvideOptions> & import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps & (new () => {
14
- $slots: Readonly<{
15
- default: any;
16
- title: any;
17
- extra: any;
18
- }> & {
9
+ }, Readonly<import("../index.js").FormLayoutProps> & Readonly<{}>, {}, {}, {}, {}, {}>;
10
+ __isFragment?: never;
11
+ __isTeleport?: never;
12
+ __isSuspense?: never;
13
+ } & import("vue").ComponentOptionsBase<Readonly<import("../index.js").FormLayoutProps> & Readonly<{}>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, {}, {}, string, {}, import("vue").GlobalComponents, import("vue").GlobalDirectives, string, import("vue").ComponentProvideOptions> & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & (new () => {
14
+ $slots: {
19
15
  default: any;
20
16
  title: any;
21
17
  extra: any;
22
18
  };
23
19
  })> & Record<string, any>;
24
- export declare const LayoutFormItem: import('../utils').SFCWithInstall<{
25
- new (...args: any[]): import('vue').CreateComponentPublicInstanceWithMixins<Readonly<import('..').LayoutFormItemProps> & Readonly<{}>, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, import('vue').PublicProps, {}, false, {}, {}, import('vue').GlobalComponents, import('vue').GlobalDirectives, string, {}, any, import('vue').ComponentProvideOptions, {
20
+ export declare const LayoutFormItem: import("../utils").SFCWithInstall<{
21
+ new (...args: any[]): import("vue").CreateComponentPublicInstanceWithMixins<Readonly<import("../index.js").LayoutFormItemProps> & Readonly<{}>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, import("vue").PublicProps, {}, false, {}, {}, import("vue").GlobalComponents, import("vue").GlobalDirectives, string, {}, any, import("vue").ComponentProvideOptions, {
26
22
  P: {};
27
23
  B: {};
28
24
  D: {};
29
25
  C: {};
30
26
  M: {};
31
27
  Defaults: {};
32
- }, Readonly<import('..').LayoutFormItemProps> & Readonly<{}>, {}, {}, {}, {}, {}>;
33
- __isFragment?: undefined;
34
- __isTeleport?: undefined;
35
- __isSuspense?: undefined;
36
- } & import('vue').ComponentOptionsBase<Readonly<import('..').LayoutFormItemProps> & Readonly<{}>, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, {}, {}, string, {}, import('vue').GlobalComponents, import('vue').GlobalDirectives, string, import('vue').ComponentProvideOptions> & import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps & (new () => {
37
- $slots: Readonly<{
38
- default: any;
39
- label: any;
40
- helpText: any;
41
- extra: any;
42
- }> & {
28
+ }, Readonly<import("../index.js").LayoutFormItemProps> & Readonly<{}>, {}, {}, {}, {}, {}>;
29
+ __isFragment?: never;
30
+ __isTeleport?: never;
31
+ __isSuspense?: never;
32
+ } & import("vue").ComponentOptionsBase<Readonly<import("../index.js").LayoutFormItemProps> & Readonly<{}>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, {}, {}, string, {}, import("vue").GlobalComponents, import("vue").GlobalDirectives, string, import("vue").ComponentProvideOptions> & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & (new () => {
33
+ $slots: {
43
34
  default: any;
44
35
  label: any;
45
36
  helpText: any;
46
37
  extra: any;
47
38
  };
48
39
  })> & Record<string, any>;
49
- export declare const FormLayoutRows: import('../utils').SFCWithInstall<{
50
- new (...args: any[]): import('vue').CreateComponentPublicInstanceWithMixins<Readonly<import('vue').HTMLAttributes> & Readonly<{}>, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, import('vue').PublicProps, {}, false, {}, {}, import('vue').GlobalComponents, import('vue').GlobalDirectives, string, {}, any, import('vue').ComponentProvideOptions, {
40
+ export declare const FormLayoutRows: import("../utils").SFCWithInstall<{
41
+ new (...args: any[]): import("vue").CreateComponentPublicInstanceWithMixins<Readonly<import("vue").HTMLAttributes> & Readonly<{}>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, import("vue").PublicProps, {}, false, {}, {}, import("vue").GlobalComponents, import("vue").GlobalDirectives, string, {}, any, import("vue").ComponentProvideOptions, {
51
42
  P: {};
52
43
  B: {};
53
44
  D: {};
54
45
  C: {};
55
46
  M: {};
56
47
  Defaults: {};
57
- }, Readonly<import('vue').HTMLAttributes> & Readonly<{}>, {}, {}, {}, {}, {}>;
58
- __isFragment?: undefined;
59
- __isTeleport?: undefined;
60
- __isSuspense?: undefined;
61
- } & import('vue').ComponentOptionsBase<Readonly<import('vue').HTMLAttributes> & Readonly<{}>, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, {}, {}, string, {}, import('vue').GlobalComponents, import('vue').GlobalDirectives, string, import('vue').ComponentProvideOptions> & import('vue').VNodeProps & import('vue').AllowedComponentProps & import('vue').ComponentCustomProps & (new () => {
48
+ }, Readonly<import("vue").HTMLAttributes> & Readonly<{}>, {}, {}, {}, {}, {}>;
49
+ __isFragment?: never;
50
+ __isTeleport?: never;
51
+ __isSuspense?: never;
52
+ } & import("vue").ComponentOptionsBase<Readonly<import("vue").HTMLAttributes> & Readonly<{}>, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, {}, {}, string, {}, import("vue").GlobalComponents, import("vue").GlobalDirectives, string, import("vue").ComponentProvideOptions> & import("vue").VNodeProps & import("vue").AllowedComponentProps & import("vue").ComponentCustomProps & (new () => {
62
53
  $slots: {
63
- default?(_: {}): any;
54
+ default?: (props: {}) => any;
64
55
  };
65
56
  })> & Record<string, any>;
@@ -0,0 +1,8 @@
1
+ import layout from "./layout.js";
2
+ import layout_formItem from "./layout.formItem.js";
3
+ import layout_form_rows from "./layout.form.rows.js";
4
+ import { withInstall } from "../utils/index.js";
5
+ const Layout = withInstall(layout);
6
+ const LayoutFormItem = withInstall(layout_formItem);
7
+ const FormLayoutRows = withInstall(layout_form_rows);
8
+ export { FormLayoutRows, Layout, LayoutFormItem };
@@ -0,0 +1,21 @@
1
+ import { computed, createElementBlock, defineComponent, mergeProps, openBlock, renderSlot } from "vue";
2
+ import classnames from "classnames";
3
+ const preCls = "carefrees-form-layout";
4
+ const _sfc_main = /* @__PURE__ */ defineComponent({
5
+ name: "FormLayoutRows",
6
+ inheritAttrs: false,
7
+ __name: "layout.form.rows",
8
+ setup (__props) {
9
+ const props = __props;
10
+ const cls = computed(()=>classnames(preCls, props.class, {
11
+ "all-colspan": true
12
+ }));
13
+ return (_ctx, _cache)=>(openBlock(), createElementBlock("div", mergeProps(props, {
14
+ class: cls.value
15
+ }), [
16
+ renderSlot(_ctx.$slots, "default")
17
+ ], 16));
18
+ }
19
+ });
20
+ const layout_form_rows = _sfc_main;
21
+ export { layout_form_rows as default };
@@ -1,9 +1,12 @@
1
- import { HTMLAttributes } from 'vue';
2
- declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<HTMLAttributes, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<HTMLAttributes> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>, {
3
- default?(_: {}): any;
4
- }>;
1
+ import { HTMLAttributes } from "vue";
2
+ declare var __VLS_1: {};
3
+ type __VLS_Slots = {} & {
4
+ default?: (props: typeof __VLS_1) => any;
5
+ };
6
+ declare const __VLS_component: import("vue").DefineComponent<HTMLAttributes, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<HTMLAttributes> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
7
+ declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
5
8
  export default _default;
6
- type __VLS_WithTemplateSlots<T, S> = T & {
9
+ type __VLS_WithSlots<T, S> = T & {
7
10
  new (): {
8
11
  $slots: S;
9
12
  };