@carefrees/form-utils-vue 0.0.11 → 0.0.13

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 (176) hide show
  1. package/README.md +104 -2
  2. package/assets/index.css +23 -12
  3. package/esm/component.js +3 -0
  4. package/esm/form/form.js +161 -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 +157 -0
  9. package/esm/formItem/form.Item.base.vue.d.ts +7 -8
  10. package/esm/formItem/form.hide.item.js +122 -0
  11. package/esm/formItem/form.hide.item.vue.d.ts +7 -8
  12. package/esm/formItem/formItem.js +151 -0
  13. package/esm/formItem/formItem.vue.d.ts +6 -9
  14. package/esm/formItem/index.d.ts +26 -37
  15. package/esm/formItem/index.js +8 -0
  16. package/esm/index.d.ts +2 -2
  17. package/esm/index.js +13 -0
  18. package/esm/interface/index.d.ts +6 -11
  19. package/esm/interface/index.js +0 -0
  20. package/esm/interface/layout.d.ts +1 -1
  21. package/esm/interface/layout.formItem.d.ts +1 -1
  22. package/esm/interface/layout.formItem.js +0 -0
  23. package/esm/interface/layout.js +0 -0
  24. package/esm/layout/index.d.ts +24 -33
  25. package/esm/layout/index.js +8 -0
  26. package/esm/layout/layout.form.rows.js +21 -0
  27. package/esm/layout/layout.form.rows.vue.d.ts +8 -5
  28. package/esm/layout/layout.formItem.js +195 -0
  29. package/esm/layout/layout.formItem.vue.d.ts +6 -9
  30. package/esm/layout/layout.js +160 -0
  31. package/esm/layout/layout.vue.d.ts +6 -8
  32. package/esm/utils/index.js +1 -0
  33. package/esm/utils/withInstall.d.ts +2 -2
  34. package/esm/utils/withInstall.js +15 -0
  35. package/package.json +7 -8
  36. package/src/form/form.vue +21 -7
  37. package/src/formItem/form.Item.base.vue +5 -5
  38. package/src/formItem/form.hide.item.vue +3 -1
  39. package/src/formItem/formItem.vue +2 -1
  40. package/src/index.ts +1 -1
  41. package/src/interface/index.ts +6 -13
  42. package/src/interface/layout.formItem.ts +1 -2
  43. package/src/interface/layout.ts +2 -1
  44. package/src/layout/layout.formItem.vue +2 -1
  45. package/src/layout/layout.vue +2 -1
  46. package/esm/component.mjs +0 -12
  47. package/esm/form/form.vue.mjs +0 -110
  48. package/esm/form/form.vue2.mjs +0 -4
  49. package/esm/form/index.mjs +0 -6
  50. package/esm/formItem/form.Item.base.vue.mjs +0 -114
  51. package/esm/formItem/form.Item.base.vue2.mjs +0 -4
  52. package/esm/formItem/form.hide.item.vue.mjs +0 -78
  53. package/esm/formItem/form.hide.item.vue2.mjs +0 -4
  54. package/esm/formItem/formItem.vue.mjs +0 -102
  55. package/esm/formItem/formItem.vue2.mjs +0 -4
  56. package/esm/formItem/index.mjs +0 -12
  57. package/esm/hooks/attr/attr.FormItem.d.ts +0 -97
  58. package/esm/hooks/attr/attr.FormItem.mjs +0 -120
  59. package/esm/hooks/index.d.ts +0 -13
  60. package/esm/hooks/register/register.FormHideItem.d.ts +0 -9
  61. package/esm/hooks/register/register.FormHideItem.mjs +0 -38
  62. package/esm/hooks/register/register.FormItem.d.ts +0 -23
  63. package/esm/hooks/register/register.FormItem.mjs +0 -55
  64. package/esm/hooks/register/register.FormList.d.ts +0 -9
  65. package/esm/hooks/register/register.FormList.mjs +0 -43
  66. package/esm/hooks/register/register.form.d.ts +0 -3
  67. package/esm/hooks/register/register.form.mjs +0 -12
  68. package/esm/hooks/useAttrs.d.ts +0 -24
  69. package/esm/hooks/useAttrs.mjs +0 -43
  70. package/esm/hooks/useEffect.d.ts +0 -2
  71. package/esm/hooks/useEffect.mjs +0 -14
  72. package/esm/hooks/useForm.d.ts +0 -8
  73. package/esm/hooks/useForm.mjs +0 -26
  74. package/esm/hooks/useFormItem.d.ts +0 -7
  75. package/esm/hooks/useFormItem.mjs +0 -26
  76. package/esm/hooks/useFormItemParentName.d.ts +0 -18
  77. package/esm/hooks/useFormItemParentName.mjs +0 -37
  78. package/esm/hooks/useFormList.d.ts +0 -7
  79. package/esm/hooks/useFormList.mjs +0 -26
  80. package/esm/hooks/useHtmlFor.d.ts +0 -2
  81. package/esm/hooks/useHtmlFor.mjs +0 -11
  82. package/esm/hooks/useMultipleForm.d.ts +0 -7
  83. package/esm/hooks/useMultipleForm.mjs +0 -27
  84. package/esm/index.mjs +0 -59
  85. package/esm/instance/ruleIntsnace.d.ts +0 -49
  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/hooks/attr/attr.FormItem.tsx +0 -174
  162. package/src/hooks/index.ts +0 -13
  163. package/src/hooks/register/register.FormHideItem.ts +0 -45
  164. package/src/hooks/register/register.FormItem.ts +0 -80
  165. package/src/hooks/register/register.FormList.ts +0 -49
  166. package/src/hooks/register/register.form.ts +0 -12
  167. package/src/hooks/useAttrs.ts +0 -64
  168. package/src/hooks/useEffect.ts +0 -13
  169. package/src/hooks/useForm.ts +0 -28
  170. package/src/hooks/useFormItem.ts +0 -28
  171. package/src/hooks/useFormItemParentName.ts +0 -49
  172. package/src/hooks/useFormList.ts +0 -28
  173. package/src/hooks/useHtmlFor.ts +0 -9
  174. package/src/hooks/useMultipleForm.ts +0 -29
  175. package/src/instance/ruleIntsnace.ts +0 -105
  176. package/src/vite-env.d.ts +0 -1
@@ -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
  };
@@ -0,0 +1,195 @@
1
+ import { Fragment, computed, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, defineComponent, normalizeClass, normalizeStyle, openBlock, renderSlot, toDisplayString, toValue, useSlots } from "vue";
2
+ import classnames from "classnames";
3
+ import { useAttrsInject } from "@carefrees/form-utils-vue-hooks";
4
+ const _hoisted_1 = [
5
+ "for"
6
+ ];
7
+ const preCls = "carefrees-form-item";
8
+ const _sfc_main = /* @__PURE__ */ defineComponent({
9
+ name: "LayoutFormItem",
10
+ inheritAttrs: false,
11
+ __name: "layout.formItem",
12
+ props: {
13
+ errorLayout: {},
14
+ required: {
15
+ type: Boolean
16
+ },
17
+ labelMode: {},
18
+ onlyRuleStyle: {
19
+ type: Boolean
20
+ },
21
+ label: {
22
+ type: [
23
+ Object,
24
+ String,
25
+ Number,
26
+ Boolean,
27
+ null,
28
+ Array
29
+ ]
30
+ },
31
+ helpText: {
32
+ type: [
33
+ Object,
34
+ String,
35
+ Number,
36
+ Boolean,
37
+ null,
38
+ Array
39
+ ]
40
+ },
41
+ extra: {
42
+ type: [
43
+ Object,
44
+ String,
45
+ Number,
46
+ Boolean,
47
+ null,
48
+ Array
49
+ ]
50
+ },
51
+ showColon: {
52
+ type: Boolean
53
+ },
54
+ colSpan: {},
55
+ rowSpan: {},
56
+ htmlFor: {},
57
+ validateResult: {},
58
+ style: {
59
+ type: [
60
+ Boolean,
61
+ null,
62
+ String,
63
+ Object,
64
+ Array
65
+ ]
66
+ },
67
+ class: {},
68
+ labelStyle: {
69
+ type: [
70
+ Boolean,
71
+ null,
72
+ String,
73
+ Object,
74
+ Array
75
+ ]
76
+ },
77
+ labelClass: {}
78
+ },
79
+ setup (__props) {
80
+ const attrs = useAttrsInject();
81
+ const props = __props;
82
+ const solts = useSlots();
83
+ const labelMode = computed(()=>props.labelMode ?? toValue(attrs.value.labelMode) ?? "top");
84
+ const showColon = computed(()=>props.showColon ?? toValue(attrs.value.showColon));
85
+ const errorLayout = computed(()=>props.errorLayout ?? toValue(attrs.value.errorLayout) ?? "left-bottom");
86
+ const tips = computed(()=>{
87
+ const v = toValue(props.validateResult)?.tip;
88
+ if (Array.isArray(v)) return v.join(",");
89
+ return v;
90
+ });
91
+ const cls = computed(()=>classnames(preCls, props.class, toValue(attrs.value.formItemClass), {
92
+ "dx-invalid": !!toValue(props.validateResult)?.isInvalid
93
+ }));
94
+ const containerCls = computed(()=>classnames(`${preCls}-container`, {
95
+ [`${labelMode.value}`]: !!labelMode.value
96
+ }));
97
+ const labelCls = computed(()=>classnames(`${preCls}-label`, {
98
+ required: !!props.required,
99
+ "show-colon": showColon && ("left" === labelMode.value || "between" === labelMode.value)
100
+ }));
101
+ const labelWarpCls = computed(()=>classnames(`${preCls}-label-warp`, toValue(props.labelClass), toValue(attrs.value.formItemLabelClass)));
102
+ const inputCls = computed(()=>classnames(`${preCls}-body-input`));
103
+ const errorCls = computed(()=>classnames(`${preCls}-body-error`, {
104
+ [errorLayout.value]: !!errorLayout.value
105
+ }));
106
+ const _isLabel = computed(()=>(props.label || solts.label) && "hide" !== labelMode.value);
107
+ const style = computed(()=>{
108
+ const css = {};
109
+ if (props.onlyRuleStyle) css.padding = "0px";
110
+ if (props.colSpan) {
111
+ const colCount = toValue(attrs.value.colCount) || 4;
112
+ const end = colCount > props.colSpan ? props.colSpan : colCount;
113
+ css.gridColumnEnd = `span ${end}`;
114
+ }
115
+ if (props.rowSpan) css.gridRowEnd = `span ${props.rowSpan}`;
116
+ return [
117
+ toValue(attrs.value.formItemStyle),
118
+ props.style,
119
+ css
120
+ ];
121
+ });
122
+ const labelStyle = computed(()=>[
123
+ toValue(attrs.value.formItemLabelStyle),
124
+ props.labelStyle
125
+ ]);
126
+ const isHelpText = computed(()=>!!props.helpText || solts.helpText);
127
+ const isExtra = computed(()=>!!props.extra || solts.extra);
128
+ return (_ctx, _cache)=>(openBlock(), createElementBlock("div", {
129
+ class: normalizeClass(cls.value),
130
+ style: normalizeStyle(style.value)
131
+ }, [
132
+ createElementVNode("div", {
133
+ class: normalizeClass(containerCls.value)
134
+ }, [
135
+ _isLabel.value ? (openBlock(), createElementBlock("div", {
136
+ key: 0,
137
+ class: normalizeClass(labelWarpCls.value)
138
+ }, [
139
+ createElementVNode("label", {
140
+ style: normalizeStyle(labelStyle.value),
141
+ class: normalizeClass(labelCls.value),
142
+ for: toValue(props.htmlFor)
143
+ }, [
144
+ props.label ? (openBlock(), createElementBlock(Fragment, {
145
+ key: 0
146
+ }, [
147
+ createTextVNode(toDisplayString(props.label), 1)
148
+ ], 64)) : renderSlot(_ctx.$slots, "label", {
149
+ key: 1
150
+ })
151
+ ], 14, _hoisted_1)
152
+ ], 2)) : createCommentVNode("", true),
153
+ createElementVNode("div", {
154
+ class: normalizeClass(preCls + "-body")
155
+ }, [
156
+ createElementVNode("div", {
157
+ class: normalizeClass(inputCls.value)
158
+ }, [
159
+ renderSlot(_ctx.$slots, "default")
160
+ ], 2),
161
+ isHelpText.value ? (openBlock(), createElementBlock("div", {
162
+ key: 0,
163
+ class: normalizeClass(preCls + "-body-help")
164
+ }, [
165
+ props.helpText ? (openBlock(), createElementBlock(Fragment, {
166
+ key: 0
167
+ }, [
168
+ createTextVNode(toDisplayString(props.helpText), 1)
169
+ ], 64)) : renderSlot(_ctx.$slots, "helpText", {
170
+ key: 1
171
+ })
172
+ ], 2)) : createCommentVNode("", true),
173
+ tips.value ? (openBlock(), createElementBlock("div", {
174
+ key: 1,
175
+ class: normalizeClass(errorCls.value)
176
+ }, toDisplayString(tips.value), 3)) : createCommentVNode("", true)
177
+ ], 2)
178
+ ], 2),
179
+ isExtra.value ? (openBlock(), createElementBlock("div", {
180
+ key: 0,
181
+ class: normalizeClass(preCls + "-extra")
182
+ }, [
183
+ props.extra ? (openBlock(), createElementBlock(Fragment, {
184
+ key: 0
185
+ }, [
186
+ createTextVNode(toDisplayString(props.extra), 1)
187
+ ], 64)) : renderSlot(_ctx.$slots, "extra", {
188
+ key: 1
189
+ })
190
+ ], 2)) : createCommentVNode("", true)
191
+ ], 6));
192
+ }
193
+ });
194
+ const layout_formItem = _sfc_main;
195
+ export { layout_formItem as default };
@@ -1,17 +1,14 @@
1
- import { LayoutFormItemProps } from '../interface/layout.formItem';
2
- declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<LayoutFormItemProps, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<LayoutFormItemProps> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>, Readonly<{
1
+ import type { LayoutFormItemProps } from "../interface/layout.formItem";
2
+ type __VLS_Slots = {
3
3
  default: any;
4
4
  label: any;
5
5
  helpText: any;
6
6
  extra: any;
7
- }> & {
8
- default: any;
9
- label: any;
10
- helpText: any;
11
- extra: any;
12
- }>;
7
+ };
8
+ declare const __VLS_component: import("vue").DefineComponent<LayoutFormItemProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<LayoutFormItemProps> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
9
+ declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
13
10
  export default _default;
14
- type __VLS_WithTemplateSlots<T, S> = T & {
11
+ type __VLS_WithSlots<T, S> = T & {
15
12
  new (): {
16
13
  $slots: S;
17
14
  };
@@ -0,0 +1,160 @@
1
+ import { Fragment, computed, createCommentVNode, createElementBlock, createElementVNode, createTextVNode, defineComponent, normalizeClass, normalizeStyle, openBlock, renderSlot, toDisplayString, toValue, useSlots } from "vue";
2
+ import classnames from "classnames";
3
+ import { useAttrsInject, useAttrsProvide } from "@carefrees/form-utils-vue-hooks";
4
+ const preCls = "carefrees-form-layout";
5
+ const _sfc_main = /* @__PURE__ */ defineComponent({
6
+ name: "Layout",
7
+ inheritAttrs: false,
8
+ __name: "layout",
9
+ props: {
10
+ title: {
11
+ type: [
12
+ Object,
13
+ String,
14
+ Number,
15
+ Boolean,
16
+ null,
17
+ Array
18
+ ]
19
+ },
20
+ extra: {
21
+ type: [
22
+ Object,
23
+ String,
24
+ Number,
25
+ Boolean,
26
+ null,
27
+ Array
28
+ ]
29
+ },
30
+ isAllColSpan: {
31
+ type: Boolean
32
+ },
33
+ class: {},
34
+ headerClass: {},
35
+ bodyClass: {},
36
+ style: {
37
+ type: [
38
+ Boolean,
39
+ null,
40
+ String,
41
+ Object,
42
+ Array
43
+ ]
44
+ },
45
+ headerStyle: {
46
+ type: [
47
+ Boolean,
48
+ null,
49
+ String,
50
+ Object,
51
+ Array
52
+ ]
53
+ },
54
+ bodyStyle: {
55
+ type: [
56
+ Boolean,
57
+ null,
58
+ String,
59
+ Object,
60
+ Array
61
+ ]
62
+ },
63
+ bordered: {
64
+ type: Boolean
65
+ },
66
+ colCount: {},
67
+ gap: {},
68
+ errorLayout: {},
69
+ labelMode: {},
70
+ showColon: {},
71
+ formItemClass: {},
72
+ formItemStyle: {},
73
+ formItemLabelClass: {},
74
+ formItemLabelStyle: {}
75
+ },
76
+ setup (__props) {
77
+ const attrs = useAttrsInject();
78
+ const props = __props;
79
+ const solts = useSlots();
80
+ const colCount = computed(()=>toValue(props.colCount) ?? toValue(attrs.value.colCount));
81
+ const errorLayout = computed(()=>toValue(props.errorLayout) ?? toValue(attrs.value.errorLayout));
82
+ const labelMode = computed(()=>toValue(props.labelMode) ?? toValue(attrs.value.labelMode));
83
+ const showColon = computed(()=>toValue(props.showColon) ?? toValue(attrs.value.showColon));
84
+ const formItemClass = computed(()=>toValue(props.formItemClass) ?? toValue(attrs.value.formItemClass));
85
+ const formItemStyle = computed(()=>toValue(props.formItemStyle) ?? toValue(attrs.value.formItemStyle));
86
+ const formItemLabelClass = computed(()=>toValue(props.formItemLabelClass) ?? toValue(attrs.value.formItemLabelClass));
87
+ const formItemLabelStyle = computed(()=>toValue(props.formItemLabelStyle) ?? toValue(attrs.value.formItemLabelStyle));
88
+ useAttrsProvide({
89
+ colCount,
90
+ errorLayout,
91
+ labelMode,
92
+ showColon,
93
+ formItemClass,
94
+ formItemStyle,
95
+ formItemLabelClass,
96
+ formItemLabelStyle
97
+ });
98
+ const cls = computed(()=>classnames(preCls, props.class, {
99
+ "all-colspan": props.isAllColSpan,
100
+ bordered: props.bordered
101
+ }));
102
+ const bodyCls = computed(()=>classnames(`${preCls}-body`, props.bodyClass));
103
+ const headerCls = computed(()=>classnames(`${preCls}-header`, props.headerClass));
104
+ const headerTitleCls = computed(()=>classnames(`${preCls}-header-title`));
105
+ const headerExtraCls = computed(()=>classnames(`${preCls}-header-extra`));
106
+ const bodyStyle = computed(()=>{
107
+ const css = {};
108
+ if ("string" == typeof props.gap) css.gap = props.gap;
109
+ if ("number" == typeof props.gap) css.gap = `${props.gap}px`;
110
+ if (colCount.value) css.gridTemplateColumns = `repeat(${colCount.value}, auto)`;
111
+ return [
112
+ css,
113
+ props.bodyStyle
114
+ ];
115
+ });
116
+ const isTitle = computed(()=>!!props.title || solts.title);
117
+ const isExtra = computed(()=>!!props.extra || solts.extra);
118
+ return (_ctx, _cache)=>(openBlock(), createElementBlock("div", {
119
+ style: normalizeStyle(props.style),
120
+ class: normalizeClass(cls.value)
121
+ }, [
122
+ isExtra.value || isTitle.value ? (openBlock(), createElementBlock("div", {
123
+ key: 0,
124
+ style: normalizeStyle(_ctx.headerStyle),
125
+ class: normalizeClass(headerCls.value)
126
+ }, [
127
+ createElementVNode("div", {
128
+ class: normalizeClass(headerTitleCls.value)
129
+ }, [
130
+ props.title ? (openBlock(), createElementBlock(Fragment, {
131
+ key: 0
132
+ }, [
133
+ createTextVNode(toDisplayString(props.title), 1)
134
+ ], 64)) : renderSlot(_ctx.$slots, "title", {
135
+ key: 1
136
+ })
137
+ ], 2),
138
+ createElementVNode("div", {
139
+ class: normalizeClass(headerExtraCls.value)
140
+ }, [
141
+ props.extra ? (openBlock(), createElementBlock(Fragment, {
142
+ key: 0
143
+ }, [
144
+ createTextVNode(toDisplayString(props.extra), 1)
145
+ ], 64)) : renderSlot(_ctx.$slots, "extra", {
146
+ key: 1
147
+ })
148
+ ], 2)
149
+ ], 6)) : createCommentVNode("", true),
150
+ createElementVNode("div", {
151
+ style: normalizeStyle(bodyStyle.value),
152
+ class: normalizeClass(bodyCls.value)
153
+ }, [
154
+ renderSlot(_ctx.$slots, "default")
155
+ ], 6)
156
+ ], 6));
157
+ }
158
+ });
159
+ const layout = _sfc_main;
160
+ export { layout as default };
@@ -1,15 +1,13 @@
1
- import { FormLayoutProps } from '../interface/layout';
2
- declare const _default: __VLS_WithTemplateSlots<import('vue').DefineComponent<FormLayoutProps, {}, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<FormLayoutProps> & Readonly<{}>, {}, {}, {}, {}, string, import('vue').ComponentProvideOptions, false, {}, any>, Readonly<{
1
+ import type { FormLayoutProps } from "../interface/layout";
2
+ type __VLS_Slots = {
3
3
  default: any;
4
4
  title: any;
5
5
  extra: any;
6
- }> & {
7
- default: any;
8
- title: any;
9
- extra: any;
10
- }>;
6
+ };
7
+ declare const __VLS_component: import("vue").DefineComponent<FormLayoutProps, {}, {}, {}, {}, import("vue").ComponentOptionsMixin, import("vue").ComponentOptionsMixin, {}, string, import("vue").PublicProps, Readonly<FormLayoutProps> & Readonly<{}>, {}, {}, {}, {}, string, import("vue").ComponentProvideOptions, false, {}, any>;
8
+ declare const _default: __VLS_WithSlots<typeof __VLS_component, __VLS_Slots>;
11
9
  export default _default;
12
- type __VLS_WithTemplateSlots<T, S> = T & {
10
+ type __VLS_WithSlots<T, S> = T & {
13
11
  new (): {
14
12
  $slots: S;
15
13
  };
@@ -0,0 +1 @@
1
+ export * from "./withInstall.js";
@@ -1,3 +1,3 @@
1
- import { Plugin } from 'vue';
1
+ import type { Plugin } from 'vue';
2
2
  export type SFCWithInstall<T> = T & Plugin;
3
- export declare const withInstall: <T, E extends Record<string, any> = Record<string, any>, K extends Record<string, any> = Record<string, any>>(main: T, extra?: E | undefined, childComponents?: K | undefined) => SFCWithInstall<T> & E & K;
3
+ export declare const withInstall: <T, E extends Record<string, any> = Record<string, any>, K extends Record<string, any> = Record<string, any>>(main: T, extra?: E, childComponents?: K) => SFCWithInstall<T> & E & K;
@@ -0,0 +1,15 @@
1
+ const withInstall = (main, extra, childComponents)=>{
2
+ main.install = (app)=>{
3
+ for (const comp of [
4
+ main,
5
+ ...Object.values(childComponents ?? {})
6
+ ]){
7
+ const name = comp.name || comp.__name;
8
+ app.component(name, comp);
9
+ }
10
+ };
11
+ if (childComponents) for (const [key, comp] of Object.entries(childComponents))main[key] = comp;
12
+ if (extra) for (const [key, comp] of Object.entries(extra))main[key] = comp;
13
+ return main;
14
+ };
15
+ export { withInstall };
package/package.json CHANGED
@@ -1,14 +1,14 @@
1
1
  {
2
2
  "name": "@carefrees/form-utils-vue",
3
3
  "author": "SunLxy <1011771396@qq.com>",
4
- "version": "0.0.11",
4
+ "version": "0.0.13",
5
5
  "description": "",
6
- "main": "lib/index.js",
7
- "module": "esm/index.mjs",
6
+ "main": "esm/index.js",
7
+ "module": "esm/index.js",
8
8
  "types": "esm/index.d.ts",
9
9
  "scripts": {
10
- "build": "saqu-vue build",
11
- "watch": "saqu-vue build --watch"
10
+ "build": "carefrees-rslib build --vue --esm",
11
+ "watch": "carefrees-rslib build --watch --vue --esm"
12
12
  },
13
13
  "publishConfig": {
14
14
  "access": "public"
@@ -16,17 +16,16 @@
16
16
  "files": [
17
17
  "assets",
18
18
  "src",
19
- "lib",
20
19
  "esm"
21
20
  ],
22
21
  "keywords": [],
23
22
  "license": "ISC",
24
23
  "devDependencies": {
25
- "@saqu-vue/core": "^1.0.1",
26
24
  "vue": "^3.5.13"
27
25
  },
28
26
  "dependencies": {
29
- "@carefrees/form-utils": "^0.0.11",
27
+ "@carefrees/form-utils": "^0.0.13",
28
+ "@carefrees/form-utils-vue-hooks": "^0.0.13",
30
29
  "async-validator": "~4.2.5",
31
30
  "classnames": "2.5.1"
32
31
  }
package/src/form/form.vue CHANGED
@@ -1,5 +1,5 @@
1
1
  <template>
2
- <form :class='cls' :style='style' @submit='onSubmit'>
2
+ <form :class='cls' :style='formStyle' @submit='onSubmit'>
3
3
  <FormLayout v-bind='rest' :class='layoutClass' :style='layoutStyle'>
4
4
  <slot />
5
5
  </FormLayout>
@@ -8,12 +8,11 @@
8
8
  </template>
9
9
 
10
10
  <script lang="ts" setup>
11
- import { computed, defineProps, withDefaults, reactive, defineEmits } from "vue"
11
+ import { computed, defineProps, withDefaults, defineEmits, ref, watch } from "vue"
12
12
  import type { FormProps } from "../interface/index"
13
- import { useRegisterForm } from "../hooks/register/register.form"
14
- import { useForm, useFormProvide } from "../hooks/useForm"
15
13
  import FormLayout from "../layout/layout.vue"
16
14
  import clx from 'classnames';
15
+ import { useRegisterForm, useForm, useFormProvide } from "@carefrees/form-utils-vue-hooks"
17
16
 
18
17
  defineOptions({
19
18
  name: 'Form',
@@ -27,20 +26,35 @@ const {
27
26
  style,
28
27
  formData,
29
28
  hideData,
30
- hideRuleData,
31
29
  name,
32
30
  onFinish,
33
31
  onFinishFailed,
34
32
  onValuesChange,
35
33
  layoutStyle,
36
34
  layoutClass,
35
+ bgcolor,
37
36
  ...rest
38
37
  } = props
39
38
 
40
39
  const cls = computed(() => clx('carefrees-form', props.class));
41
40
 
41
+ const formStyle = computed(() => {
42
+ if (bgcolor)
43
+ return [{ backgroundColor: bgcolor }, props.style];
44
+ return [props.style]
45
+ });
46
+
42
47
  const formInstance = useForm(props.form);
43
- formInstance.value.ctor(reactive(props.formData || {}), reactive(props.hideData || {}), reactive(props.hideRuleData || {}));
48
+ formInstance.value.formData = ref(props.formData || {});
49
+ formInstance.value.hideState = ref(props.hideData || {});
50
+
51
+ watch(() => props.formData, (newVal) => {
52
+ formInstance.value.formData = ref(newVal || {});
53
+ })
54
+
55
+ watch(() => props.hideData, (newVal) => {
56
+ formInstance.value.hideState = ref(newVal || {});
57
+ })
44
58
 
45
59
  const emits = defineEmits(["finish", 'valuesChange', 'finishFailed'])
46
60
 
@@ -53,7 +67,7 @@ formInstance.value.onValuesChange = (...rest) => {
53
67
  formInstance.value.onFinishFailed = (...rest) => {
54
68
  emits("finishFailed", ...rest)
55
69
  };
56
- useRegisterForm(formInstance.value, props.name)
70
+ useRegisterForm(formInstance, props.name)
57
71
 
58
72
  const onSubmit = (event: Event) => {
59
73
  event?.preventDefault?.();
@@ -8,12 +8,12 @@
8
8
  :col-span='props.colSpan' :row-span='props.rowSpan' :html-for='formAttrs.htmlFor' :style='props.style'
9
9
  :class='props.class' :label-style='props.labelStyle' :label-class='props.labelClass'
10
10
  :validate-result='formAttrs.validateResult'>
11
- <template v-for="(item, name) in slots" #[name]="slotProps">
12
- <slot :name="name" v-bind="slotProps"></slot>
13
- </template>
14
11
  <template v-slot:default>
15
12
  <component :is="props.input" v-bind='toValue(formAttrs.attrsLastData)' />
16
13
  </template>
14
+ <template v-for="(item, name) in slots" #[name]="slotProps">
15
+ <slot :name="name" v-bind="slotProps"></slot>
16
+ </template>
17
17
  </LayoutFormItem>
18
18
  </template>
19
19
  </template>
@@ -21,9 +21,8 @@
21
21
  <script lang="ts" setup>
22
22
  import { defineProps, withDefaults, computed, toValue } from "vue"
23
23
  import type { FormItemProps } from "../interface/index"
24
- import { useFormItemAttr } from "../hooks/attr/attr.FormItem"
25
24
  import LayoutFormItem from "../layout/layout.formItem.vue";
26
- import { useFormItemParentNameProvide } from "../hooks/useFormItemParentName"
25
+ import { useFormItemParentNameProvide, useFormItemAttr } from "@carefrees/form-utils-vue-hooks"
27
26
 
28
27
  defineOptions({
29
28
  name: 'FormItemBase',
@@ -42,6 +41,7 @@ useFormItemParentNameProvide({
42
41
 
43
42
  const slots = defineSlots<{
44
43
  label: (params: any) => any,
44
+ default: (params: any) => any,
45
45
  helpText: (params: any) => any,
46
46
  extra: (params: any) => any,
47
47
  }>()
@@ -12,7 +12,8 @@
12
12
  import { defineProps, withDefaults, } from "vue"
13
13
  import type { FormItemProps } from "../interface/index"
14
14
  import FormItemBase from "./form.Item.base.vue"
15
- import { useRegisterFormHideItem } from "../hooks/register/register.FormHideItem"
15
+ import { useRegisterFormHideItem } from "@carefrees/form-utils-vue-hooks"
16
+
16
17
  defineOptions({
17
18
  name: 'FormHideItem',
18
19
  inheritAttrs: false, // 可选,防止属性自动应用到根元素
@@ -21,6 +22,7 @@ const props = withDefaults(defineProps<FormItemProps>(), {
21
22
  })
22
23
  const slots = defineSlots<{
23
24
  label: (params: any) => any,
25
+ default: (params: any) => any,
24
26
  helpText: (params: any) => any,
25
27
  extra: (params: any) => any,
26
28
  }>()
@@ -19,7 +19,7 @@
19
19
  </template>
20
20
 
21
21
  <script lang="ts" setup>
22
- import { defineProps, withDefaults } from "vue"
22
+ import { defineProps, withDefaults, } from "vue"
23
23
  import type { FormItemProps } from "../interface/index"
24
24
  import LayoutFormItem from "../layout/layout.formItem.vue";
25
25
  import FormItemBase from "./form.Item.base.vue"
@@ -29,6 +29,7 @@ defineOptions({
29
29
  });
30
30
  const props = withDefaults(defineProps<Partial<FormItemProps>>(), {
31
31
  })
32
+
32
33
  const slots = defineSlots<{
33
34
  default: (params: any) => any,
34
35
  label: (params: any) => any,
package/src/index.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import * as components from './component';
2
- export * from './hooks';
2
+ export * from '@carefrees/form-utils-vue-hooks';
3
3
  export * from './component';
4
4
  export * from './utils';
5
5
  export * from './interface';