@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.
- package/README.md +104 -2
- package/assets/index.css +23 -12
- package/esm/component.js +3 -0
- package/esm/form/form.js +161 -0
- package/esm/form/form.vue.d.ts +10 -7
- package/esm/form/index.d.ts +12 -12
- package/esm/form/index.js +4 -0
- package/esm/formItem/form.Item.base.js +157 -0
- package/esm/formItem/form.Item.base.vue.d.ts +7 -8
- package/esm/formItem/form.hide.item.js +122 -0
- package/esm/formItem/form.hide.item.vue.d.ts +7 -8
- package/esm/formItem/formItem.js +151 -0
- package/esm/formItem/formItem.vue.d.ts +6 -9
- package/esm/formItem/index.d.ts +26 -37
- package/esm/formItem/index.js +8 -0
- package/esm/index.d.ts +2 -2
- package/esm/index.js +13 -0
- package/esm/interface/index.d.ts +6 -11
- package/esm/interface/index.js +0 -0
- package/esm/interface/layout.d.ts +1 -1
- package/esm/interface/layout.formItem.d.ts +1 -1
- package/esm/interface/layout.formItem.js +0 -0
- package/esm/interface/layout.js +0 -0
- package/esm/layout/index.d.ts +24 -33
- package/esm/layout/index.js +8 -0
- package/esm/layout/layout.form.rows.js +21 -0
- package/esm/layout/layout.form.rows.vue.d.ts +8 -5
- package/esm/layout/layout.formItem.js +195 -0
- package/esm/layout/layout.formItem.vue.d.ts +6 -9
- package/esm/layout/layout.js +160 -0
- package/esm/layout/layout.vue.d.ts +6 -8
- package/esm/utils/index.js +1 -0
- package/esm/utils/withInstall.d.ts +2 -2
- package/esm/utils/withInstall.js +15 -0
- package/package.json +7 -8
- package/src/form/form.vue +21 -7
- package/src/formItem/form.Item.base.vue +5 -5
- package/src/formItem/form.hide.item.vue +3 -1
- package/src/formItem/formItem.vue +2 -1
- package/src/index.ts +1 -1
- package/src/interface/index.ts +6 -13
- package/src/interface/layout.formItem.ts +1 -2
- package/src/interface/layout.ts +2 -1
- package/src/layout/layout.formItem.vue +2 -1
- package/src/layout/layout.vue +2 -1
- package/esm/component.mjs +0 -12
- package/esm/form/form.vue.mjs +0 -110
- package/esm/form/form.vue2.mjs +0 -4
- package/esm/form/index.mjs +0 -6
- package/esm/formItem/form.Item.base.vue.mjs +0 -114
- package/esm/formItem/form.Item.base.vue2.mjs +0 -4
- package/esm/formItem/form.hide.item.vue.mjs +0 -78
- package/esm/formItem/form.hide.item.vue2.mjs +0 -4
- package/esm/formItem/formItem.vue.mjs +0 -102
- package/esm/formItem/formItem.vue2.mjs +0 -4
- package/esm/formItem/index.mjs +0 -12
- package/esm/hooks/attr/attr.FormItem.d.ts +0 -97
- package/esm/hooks/attr/attr.FormItem.mjs +0 -120
- package/esm/hooks/index.d.ts +0 -13
- package/esm/hooks/register/register.FormHideItem.d.ts +0 -9
- package/esm/hooks/register/register.FormHideItem.mjs +0 -38
- package/esm/hooks/register/register.FormItem.d.ts +0 -23
- package/esm/hooks/register/register.FormItem.mjs +0 -55
- package/esm/hooks/register/register.FormList.d.ts +0 -9
- package/esm/hooks/register/register.FormList.mjs +0 -43
- package/esm/hooks/register/register.form.d.ts +0 -3
- package/esm/hooks/register/register.form.mjs +0 -12
- package/esm/hooks/useAttrs.d.ts +0 -24
- package/esm/hooks/useAttrs.mjs +0 -43
- package/esm/hooks/useEffect.d.ts +0 -2
- package/esm/hooks/useEffect.mjs +0 -14
- package/esm/hooks/useForm.d.ts +0 -8
- package/esm/hooks/useForm.mjs +0 -26
- package/esm/hooks/useFormItem.d.ts +0 -7
- package/esm/hooks/useFormItem.mjs +0 -26
- package/esm/hooks/useFormItemParentName.d.ts +0 -18
- package/esm/hooks/useFormItemParentName.mjs +0 -37
- package/esm/hooks/useFormList.d.ts +0 -7
- package/esm/hooks/useFormList.mjs +0 -26
- package/esm/hooks/useHtmlFor.d.ts +0 -2
- package/esm/hooks/useHtmlFor.mjs +0 -11
- package/esm/hooks/useMultipleForm.d.ts +0 -7
- package/esm/hooks/useMultipleForm.mjs +0 -27
- package/esm/index.mjs +0 -59
- package/esm/instance/ruleIntsnace.d.ts +0 -49
- package/esm/instance/ruleIntsnace.mjs +0 -73
- package/esm/layout/index.mjs +0 -12
- package/esm/layout/layout.form.rows.vue.mjs +0 -31
- package/esm/layout/layout.form.rows.vue2.mjs +0 -4
- package/esm/layout/layout.formItem.vue.mjs +0 -216
- package/esm/layout/layout.formItem.vue2.mjs +0 -4
- package/esm/layout/layout.vue.mjs +0 -166
- package/esm/layout/layout.vue2.mjs +0 -4
- package/esm/utils/withInstall.mjs +0 -22
- package/lib/component.d.ts +0 -3
- package/lib/component.js +0 -12
- package/lib/form/form.vue.d.ts +0 -19
- package/lib/form/form.vue.js +0 -110
- package/lib/form/form.vue2.js +0 -4
- package/lib/form/index.d.ts +0 -37
- package/lib/form/index.js +0 -6
- package/lib/formItem/form.Item.base.vue.d.ts +0 -16
- package/lib/formItem/form.Item.base.vue.js +0 -114
- package/lib/formItem/form.Item.base.vue2.js +0 -4
- package/lib/formItem/form.hide.item.vue.d.ts +0 -16
- package/lib/formItem/form.hide.item.vue.js +0 -78
- package/lib/formItem/form.hide.item.vue2.js +0 -4
- package/lib/formItem/formItem.vue.d.ts +0 -18
- package/lib/formItem/formItem.vue.js +0 -102
- package/lib/formItem/formItem.vue2.js +0 -4
- package/lib/formItem/index.d.ts +0 -71
- package/lib/formItem/index.js +0 -12
- package/lib/hooks/attr/attr.FormItem.d.ts +0 -97
- package/lib/hooks/attr/attr.FormItem.js +0 -120
- package/lib/hooks/index.d.ts +0 -13
- package/lib/hooks/register/register.FormHideItem.d.ts +0 -9
- package/lib/hooks/register/register.FormHideItem.js +0 -38
- package/lib/hooks/register/register.FormItem.d.ts +0 -23
- package/lib/hooks/register/register.FormItem.js +0 -55
- package/lib/hooks/register/register.FormList.d.ts +0 -9
- package/lib/hooks/register/register.FormList.js +0 -43
- package/lib/hooks/register/register.form.d.ts +0 -3
- package/lib/hooks/register/register.form.js +0 -12
- package/lib/hooks/useAttrs.d.ts +0 -24
- package/lib/hooks/useAttrs.js +0 -43
- package/lib/hooks/useEffect.d.ts +0 -2
- package/lib/hooks/useEffect.js +0 -14
- package/lib/hooks/useForm.d.ts +0 -8
- package/lib/hooks/useForm.js +0 -26
- package/lib/hooks/useFormItem.d.ts +0 -7
- package/lib/hooks/useFormItem.js +0 -26
- package/lib/hooks/useFormItemParentName.d.ts +0 -18
- package/lib/hooks/useFormItemParentName.js +0 -37
- package/lib/hooks/useFormList.d.ts +0 -7
- package/lib/hooks/useFormList.js +0 -26
- package/lib/hooks/useHtmlFor.d.ts +0 -2
- package/lib/hooks/useHtmlFor.js +0 -11
- package/lib/hooks/useMultipleForm.d.ts +0 -7
- package/lib/hooks/useMultipleForm.js +0 -27
- package/lib/index.d.ts +0 -11
- package/lib/index.js +0 -59
- package/lib/instance/ruleIntsnace.d.ts +0 -49
- package/lib/instance/ruleIntsnace.js +0 -73
- package/lib/interface/index.d.ts +0 -36
- package/lib/interface/layout.d.ts +0 -28
- package/lib/interface/layout.formItem.d.ts +0 -39
- package/lib/layout/index.d.ts +0 -65
- package/lib/layout/index.js +0 -12
- package/lib/layout/layout.form.rows.vue.d.ts +0 -10
- package/lib/layout/layout.form.rows.vue.js +0 -31
- package/lib/layout/layout.form.rows.vue2.js +0 -4
- package/lib/layout/layout.formItem.vue.d.ts +0 -18
- package/lib/layout/layout.formItem.vue.js +0 -216
- package/lib/layout/layout.formItem.vue2.js +0 -4
- package/lib/layout/layout.vue.d.ts +0 -16
- package/lib/layout/layout.vue.js +0 -166
- package/lib/layout/layout.vue2.js +0 -4
- package/lib/utils/index.d.ts +0 -1
- package/lib/utils/withInstall.d.ts +0 -3
- package/lib/utils/withInstall.js +0 -22
- package/src/hooks/attr/attr.FormItem.tsx +0 -174
- package/src/hooks/index.ts +0 -13
- package/src/hooks/register/register.FormHideItem.ts +0 -45
- package/src/hooks/register/register.FormItem.ts +0 -80
- package/src/hooks/register/register.FormList.ts +0 -49
- package/src/hooks/register/register.form.ts +0 -12
- package/src/hooks/useAttrs.ts +0 -64
- package/src/hooks/useEffect.ts +0 -13
- package/src/hooks/useForm.ts +0 -28
- package/src/hooks/useFormItem.ts +0 -28
- package/src/hooks/useFormItemParentName.ts +0 -49
- package/src/hooks/useFormList.ts +0 -28
- package/src/hooks/useHtmlFor.ts +0 -9
- package/src/hooks/useMultipleForm.ts +0 -29
- package/src/instance/ruleIntsnace.ts +0 -105
- 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
|
|
2
|
-
declare
|
|
3
|
-
|
|
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
|
|
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
|
|
2
|
-
|
|
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
|
-
|
|
9
|
-
|
|
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
|
|
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
|
|
2
|
-
|
|
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
|
-
|
|
8
|
-
|
|
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
|
|
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
|
|
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.
|
|
4
|
+
"version": "0.0.13",
|
|
5
5
|
"description": "",
|
|
6
|
-
"main": "
|
|
7
|
-
"module": "esm/index.
|
|
6
|
+
"main": "esm/index.js",
|
|
7
|
+
"module": "esm/index.js",
|
|
8
8
|
"types": "esm/index.d.ts",
|
|
9
9
|
"scripts": {
|
|
10
|
-
"build": "
|
|
11
|
-
"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.
|
|
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='
|
|
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,
|
|
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.
|
|
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
|
|
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 "
|
|
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 "
|
|
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