@manohub/ui 0.6.0
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 +141 -0
- package/dist/components/avatar/index.d.ts +283 -0
- package/dist/components/avatar/index.js +167 -0
- package/dist/components/badge/index.d.ts +132 -0
- package/dist/components/badge/index.js +99 -0
- package/dist/components/button/index.d.ts +578 -0
- package/dist/components/button/index.js +191 -0
- package/dist/components/capsule/index.d.ts +161 -0
- package/dist/components/capsule/index.js +101 -0
- package/dist/components/card/index.d.ts +456 -0
- package/dist/components/card/index.js +231 -0
- package/dist/components/checkbox/index.d.ts +331 -0
- package/dist/components/checkbox/index.js +165 -0
- package/dist/components/code/index.d.ts +134 -0
- package/dist/components/code/index.js +117 -0
- package/dist/components/code-editor/index.d.ts +163 -0
- package/dist/components/code-editor/index.js +98 -0
- package/dist/components/collapse/index.d.ts +125 -0
- package/dist/components/collapse/index.js +95 -0
- package/dist/components/control-size.d.ts +8 -0
- package/dist/components/dialog/index.d.ts +224 -0
- package/dist/components/dialog/index.js +194 -0
- package/dist/components/divider/index.d.ts +64 -0
- package/dist/components/divider/index.js +62 -0
- package/dist/components/drawer/index.d.ts +226 -0
- package/dist/components/drawer/index.js +190 -0
- package/dist/components/filter/index.d.ts +391 -0
- package/dist/components/filter/index.js +203 -0
- package/dist/components/form/index.d.ts +704 -0
- package/dist/components/form/index.js +329 -0
- package/dist/components/input/index.d.ts +980 -0
- package/dist/components/input/index.js +334 -0
- package/dist/components/layout/index.d.ts +162 -0
- package/dist/components/layout/index.js +100 -0
- package/dist/components/list-view/index.d.ts +563 -0
- package/dist/components/list-view/index.js +221 -0
- package/dist/components/loading/index.d.ts +77 -0
- package/dist/components/loading/index.js +40 -0
- package/dist/components/nav/index.d.ts +293 -0
- package/dist/components/nav/index.js +164 -0
- package/dist/components/notice/index.d.ts +137 -0
- package/dist/components/notice/index.js +101 -0
- package/dist/components/notification/index.d.ts +118 -0
- package/dist/components/notification/index.js +99 -0
- package/dist/components/page/index.d.ts +276 -0
- package/dist/components/page/index.js +351 -0
- package/dist/components/page/split-resize.d.ts +42 -0
- package/dist/components/page/split-resize.js +36 -0
- package/dist/components/pagination/index.d.ts +171 -0
- package/dist/components/pagination/index.js +226 -0
- package/dist/components/panel/index.d.ts +401 -0
- package/dist/components/panel/index.js +193 -0
- package/dist/components/part-padding.d.ts +27 -0
- package/dist/components/part-padding.js +23 -0
- package/dist/components/query-state/index.d.ts +207 -0
- package/dist/components/query-state/index.js +181 -0
- package/dist/components/radio/index.d.ts +473 -0
- package/dist/components/radio/index.js +250 -0
- package/dist/components/search/index.d.ts +167 -0
- package/dist/components/search/index.js +105 -0
- package/dist/components/select/index.d.ts +252 -0
- package/dist/components/select/index.js +281 -0
- package/dist/components/skeleton/index.d.ts +88 -0
- package/dist/components/skeleton/index.js +56 -0
- package/dist/components/steps/index.d.ts +199 -0
- package/dist/components/steps/index.js +117 -0
- package/dist/components/switch/index.d.ts +150 -0
- package/dist/components/switch/index.js +103 -0
- package/dist/components/table/index.d.ts +351 -0
- package/dist/components/table/index.js +286 -0
- package/dist/components/tabs/index.d.ts +179 -0
- package/dist/components/tabs/index.js +153 -0
- package/dist/components/tabset/index.d.ts +105 -0
- package/dist/components/tabset/index.js +68 -0
- package/dist/components/tag/index.d.ts +203 -0
- package/dist/components/tag/index.js +144 -0
- package/dist/components/toast/index.d.ts +271 -0
- package/dist/components/toast/index.js +116 -0
- package/dist/components/tooltip/index.d.ts +126 -0
- package/dist/components/tooltip/index.js +97 -0
- package/dist/components/tree/index.d.ts +317 -0
- package/dist/components/tree/index.js +251 -0
- package/dist/components/upload/index.d.ts +384 -0
- package/dist/components/upload/index.js +172 -0
- package/dist/index.d.ts +63 -0
- package/dist/index.js +102 -0
- package/dist/services/base.d.ts +21 -0
- package/dist/services/base.js +42 -0
- package/dist/services/dialog.d.ts +41 -0
- package/dist/services/dialog.js +83 -0
- package/dist/services/index.d.ts +12 -0
- package/dist/services/loading.d.ts +21 -0
- package/dist/services/loading.js +41 -0
- package/dist/services/toast.d.ts +40 -0
- package/dist/services/toast.js +74 -0
- package/dist/styles/components/avatar.css +128 -0
- package/dist/styles/components/avatar.tokens.css +24 -0
- package/dist/styles/components/badge.css +237 -0
- package/dist/styles/components/button.css +454 -0
- package/dist/styles/components/button.tokens.css +56 -0
- package/dist/styles/components/capsule.css +120 -0
- package/dist/styles/components/capsule.tokens.css +27 -0
- package/dist/styles/components/card.css +192 -0
- package/dist/styles/components/checkbox.css +145 -0
- package/dist/styles/components/checkbox.tokens.css +26 -0
- package/dist/styles/components/code-editor.css +91 -0
- package/dist/styles/components/code-editor.tokens.css +24 -0
- package/dist/styles/components/code.css +153 -0
- package/dist/styles/components/code.tokens.css +29 -0
- package/dist/styles/components/collapse.css +62 -0
- package/dist/styles/components/collapse.tokens.css +20 -0
- package/dist/styles/components/dialog.css +106 -0
- package/dist/styles/components/dialog.tokens.css +24 -0
- package/dist/styles/components/divider.css +71 -0
- package/dist/styles/components/divider.tokens.css +21 -0
- package/dist/styles/components/drawer.css +143 -0
- package/dist/styles/components/drawer.tokens.css +22 -0
- package/dist/styles/components/filter.css +41 -0
- package/dist/styles/components/filter.tokens.css +14 -0
- package/dist/styles/components/form.css +220 -0
- package/dist/styles/components/form.tokens.css +15 -0
- package/dist/styles/components/input.css +445 -0
- package/dist/styles/components/input.tokens.css +41 -0
- package/dist/styles/components/layout.css +198 -0
- package/dist/styles/components/list-view.css +244 -0
- package/dist/styles/components/loading.css +76 -0
- package/dist/styles/components/loading.tokens.css +23 -0
- package/dist/styles/components/nav.css +48 -0
- package/dist/styles/components/notice.css +153 -0
- package/dist/styles/components/notice.tokens.css +17 -0
- package/dist/styles/components/notification.css +159 -0
- package/dist/styles/components/notification.tokens.css +37 -0
- package/dist/styles/components/page.css +473 -0
- package/dist/styles/components/pagination.css +297 -0
- package/dist/styles/components/pagination.tokens.css +32 -0
- package/dist/styles/components/panel.css +77 -0
- package/dist/styles/components/query-state.css +88 -0
- package/dist/styles/components/radio.css +271 -0
- package/dist/styles/components/radio.tokens.css +26 -0
- package/dist/styles/components/search.css +30 -0
- package/dist/styles/components/select.css +242 -0
- package/dist/styles/components/select.tokens.css +33 -0
- package/dist/styles/components/skeleton.css +60 -0
- package/dist/styles/components/skeleton.tokens.css +27 -0
- package/dist/styles/components/steps.css +157 -0
- package/dist/styles/components/steps.tokens.css +42 -0
- package/dist/styles/components/switch.css +165 -0
- package/dist/styles/components/switch.tokens.css +26 -0
- package/dist/styles/components/table.css +439 -0
- package/dist/styles/components/table.tokens.css +41 -0
- package/dist/styles/components/tabs.css +234 -0
- package/dist/styles/components/tabs.tokens.css +30 -0
- package/dist/styles/components/tag.css +200 -0
- package/dist/styles/components/tag.tokens.css +30 -0
- package/dist/styles/components/toast.css +150 -0
- package/dist/styles/components/toast.tokens.css +26 -0
- package/dist/styles/components/tooltip.css +89 -0
- package/dist/styles/components/tooltip.tokens.css +25 -0
- package/dist/styles/components/tree.css +139 -0
- package/dist/styles/components/tree.tokens.css +20 -0
- package/dist/styles/components/upload.css +150 -0
- package/dist/styles/components/upload.tokens.css +27 -0
- package/dist/styles/index.css +149 -0
- package/dist/styles/operations/collapse.css +84 -0
- package/dist/styles/operations/popup.css +189 -0
- package/dist/styles/operations/tabset.css +57 -0
- package/dist/utils/state-illustration.d.ts +31 -0
- package/dist/utils/state-illustration.js +156 -0
- package/package.json +62 -0
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
import { defineComponent, inject, watch, createVNode, createTextVNode, provide, toRef, ref, computed, isVNode } from "vue";
|
|
2
|
+
import { mergePartStyle } from "../part-padding.js";
|
|
3
|
+
const FORM_LABEL_WIDTH = /* @__PURE__ */ Symbol("mh-form-label-width");
|
|
4
|
+
const FORM_CONTROL_WIDTH = /* @__PURE__ */ Symbol("mh-form-control-width");
|
|
5
|
+
const FORM_LABEL_ALIGN = /* @__PURE__ */ Symbol("mh-form-label-align");
|
|
6
|
+
const FORM_TEXT_EMPTY = "—";
|
|
7
|
+
const FORM_STORE = /* @__PURE__ */ Symbol("mh-form-store");
|
|
8
|
+
const FormItem = /* @__PURE__ */ defineComponent({
|
|
9
|
+
name: "FormItem",
|
|
10
|
+
inheritAttrs: false,
|
|
11
|
+
props: {
|
|
12
|
+
/** 字段名(绑定的键);不传即纯布局行(值由消费方自己在控件上绑定) */
|
|
13
|
+
name: {
|
|
14
|
+
type: String,
|
|
15
|
+
default: void 0
|
|
16
|
+
},
|
|
17
|
+
label: {
|
|
18
|
+
type: String,
|
|
19
|
+
default: void 0
|
|
20
|
+
},
|
|
21
|
+
required: {
|
|
22
|
+
type: Boolean,
|
|
23
|
+
default: false
|
|
24
|
+
},
|
|
25
|
+
error: {
|
|
26
|
+
type: String,
|
|
27
|
+
default: ""
|
|
28
|
+
},
|
|
29
|
+
hint: {
|
|
30
|
+
type: String,
|
|
31
|
+
default: ""
|
|
32
|
+
},
|
|
33
|
+
labelWidth: {
|
|
34
|
+
type: Number,
|
|
35
|
+
default: void 0
|
|
36
|
+
},
|
|
37
|
+
labelAlign: {
|
|
38
|
+
type: String,
|
|
39
|
+
default: void 0
|
|
40
|
+
},
|
|
41
|
+
controlWidth: {
|
|
42
|
+
type: Number,
|
|
43
|
+
default: void 0
|
|
44
|
+
},
|
|
45
|
+
fullWidth: {
|
|
46
|
+
type: Boolean,
|
|
47
|
+
default: false
|
|
48
|
+
},
|
|
49
|
+
/** `undefined` 与「传了空串」必须区分:前者走插槽(控件形态),后者是「值为空的只读行」 */
|
|
50
|
+
text: {
|
|
51
|
+
type: String,
|
|
52
|
+
default: void 0
|
|
53
|
+
},
|
|
54
|
+
/** 只读展示行(label 弱化,内容走插槽):用于控件位是徽标 / 链接这类非文本的只读内容 */
|
|
55
|
+
readonly: {
|
|
56
|
+
type: Boolean,
|
|
57
|
+
default: false
|
|
58
|
+
}
|
|
59
|
+
},
|
|
60
|
+
slots: Object,
|
|
61
|
+
setup(props, {
|
|
62
|
+
slots,
|
|
63
|
+
attrs
|
|
64
|
+
}) {
|
|
65
|
+
const inheritedLabelWidth = inject(FORM_LABEL_WIDTH, void 0);
|
|
66
|
+
const inheritedLabelAlign = inject(FORM_LABEL_ALIGN, void 0);
|
|
67
|
+
const inheritedControlWidth = inject(FORM_CONTROL_WIDTH, void 0);
|
|
68
|
+
const store = inject(FORM_STORE, null);
|
|
69
|
+
if (props.name) store?.register(props.name);
|
|
70
|
+
watch(() => props.name, (name) => {
|
|
71
|
+
if (name) store?.register(name);
|
|
72
|
+
});
|
|
73
|
+
const setValue = (value) => {
|
|
74
|
+
if (props.name) store?.write(props.name, value);
|
|
75
|
+
};
|
|
76
|
+
const clear = () => setValue(void 0);
|
|
77
|
+
const scope = () => ({
|
|
78
|
+
value: props.name ? store?.read(props.name) : void 0,
|
|
79
|
+
setValue,
|
|
80
|
+
clear
|
|
81
|
+
});
|
|
82
|
+
return () => {
|
|
83
|
+
const labelWidth = props.labelWidth ?? inheritedLabelWidth?.value;
|
|
84
|
+
const labelAlign = props.labelAlign ?? inheritedLabelAlign?.value;
|
|
85
|
+
const controlWidth = props.controlWidth ?? inheritedControlWidth?.value;
|
|
86
|
+
const styles = [attrs.style, labelWidth ? {
|
|
87
|
+
"--mh-form-label-width": `${labelWidth}px`
|
|
88
|
+
} : null].filter(Boolean);
|
|
89
|
+
const showLabel = !!props.label || props.required;
|
|
90
|
+
const hasText = props.text !== void 0;
|
|
91
|
+
const textIsEmpty = hasText && !props.text.trim();
|
|
92
|
+
const isReadonlyRow = hasText || props.readonly;
|
|
93
|
+
return createVNode("div", {
|
|
94
|
+
"class": [
|
|
95
|
+
"mh-form-item",
|
|
96
|
+
props.error ? "is-invalid" : "",
|
|
97
|
+
props.fullWidth ? "mh-form-item--full" : "",
|
|
98
|
+
// 右对齐是基类默认值,只有左对齐需要额外的修饰类(两处都挂会让「谁胜出」依赖源码顺序)
|
|
99
|
+
labelAlign === "left" ? "mh-form-item--label-left" : "",
|
|
100
|
+
// 只读展示行:label 降一档为次要色,与值拉开层级(样式见 `.mh-form-item--readonly .mh-form-item__label`)
|
|
101
|
+
isReadonlyRow ? "mh-form-item--readonly" : "",
|
|
102
|
+
attrs.class
|
|
103
|
+
].filter(Boolean).join(" "),
|
|
104
|
+
"data-invalid": props.error ? "true" : "false",
|
|
105
|
+
"style": styles
|
|
106
|
+
}, [showLabel ? createVNode("label", {
|
|
107
|
+
"class": "mh-form-item__label"
|
|
108
|
+
}, [createVNode("span", {
|
|
109
|
+
"class": "mh-form-item__label-text"
|
|
110
|
+
}, [props.label]), props.required ? createVNode("span", {
|
|
111
|
+
"class": "mh-form-item__required"
|
|
112
|
+
}, [createTextVNode("*")]) : null]) : null, createVNode("div", {
|
|
113
|
+
"class": "mh-form-item__control",
|
|
114
|
+
"style": controlWidth ? {
|
|
115
|
+
maxWidth: `${controlWidth}px`
|
|
116
|
+
} : void 0
|
|
117
|
+
}, [hasText ? (
|
|
118
|
+
/*
|
|
119
|
+
* 只读文本形态(摘要 / 详情行):控件位直接渲染业务值,占位与换行规则都在组件里
|
|
120
|
+
* —— 应用侧不再自绘 label/value 表格(那套几何与表单行迟早会漂开)。
|
|
121
|
+
*/
|
|
122
|
+
createVNode("div", {
|
|
123
|
+
"class": "mh-form-item__text",
|
|
124
|
+
"data-empty": textIsEmpty ? "true" : "false"
|
|
125
|
+
}, [textIsEmpty ? FORM_TEXT_EMPTY : props.text])
|
|
126
|
+
) : slots.default?.(scope()), props.error ? createVNode("div", {
|
|
127
|
+
"class": "mh-form-item__error"
|
|
128
|
+
}, [props.error]) : null, props.hint ? createVNode("div", {
|
|
129
|
+
"class": "mh-form-item__hint"
|
|
130
|
+
}, [props.hint]) : null])]);
|
|
131
|
+
};
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
const FormHeader = /* @__PURE__ */ defineComponent({
|
|
135
|
+
name: "FormHeader",
|
|
136
|
+
inheritAttrs: false,
|
|
137
|
+
props: {
|
|
138
|
+
title: {
|
|
139
|
+
type: String,
|
|
140
|
+
default: void 0
|
|
141
|
+
},
|
|
142
|
+
description: {
|
|
143
|
+
type: String,
|
|
144
|
+
default: void 0
|
|
145
|
+
}
|
|
146
|
+
},
|
|
147
|
+
slots: Object,
|
|
148
|
+
setup(props, {
|
|
149
|
+
slots,
|
|
150
|
+
attrs
|
|
151
|
+
}) {
|
|
152
|
+
return () => {
|
|
153
|
+
const hasTitleRow = !!props.title || !!slots.extra;
|
|
154
|
+
if (!hasTitleRow && !props.description) return null;
|
|
155
|
+
return createVNode("div", {
|
|
156
|
+
"class": ["mh-form__header", attrs.class].filter(Boolean).join(" "),
|
|
157
|
+
"style": attrs.style
|
|
158
|
+
}, [hasTitleRow ? createVNode("div", {
|
|
159
|
+
"class": "mh-form__title"
|
|
160
|
+
}, [props.title ? createVNode("span", {
|
|
161
|
+
"class": "mh-form__title-text"
|
|
162
|
+
}, [props.title]) : null, slots.extra ? createVNode("div", {
|
|
163
|
+
"class": "mh-form__title-extra"
|
|
164
|
+
}, [slots.extra()]) : null]) : null, props.description ? createVNode("div", {
|
|
165
|
+
"class": "mh-form__description"
|
|
166
|
+
}, [props.description]) : null]);
|
|
167
|
+
};
|
|
168
|
+
}
|
|
169
|
+
});
|
|
170
|
+
function splitFormHeader(children) {
|
|
171
|
+
const header = [];
|
|
172
|
+
const rest = [];
|
|
173
|
+
for (const child of children) {
|
|
174
|
+
if (isVNode(child) && child.type === FormHeader) header.push(child);
|
|
175
|
+
else rest.push(child);
|
|
176
|
+
}
|
|
177
|
+
return {
|
|
178
|
+
header,
|
|
179
|
+
rest
|
|
180
|
+
};
|
|
181
|
+
}
|
|
182
|
+
const FormRoot = /* @__PURE__ */ defineComponent({
|
|
183
|
+
name: "Form",
|
|
184
|
+
inheritAttrs: false,
|
|
185
|
+
props: {
|
|
186
|
+
/** 表单级 label 列宽(px);`Form.Item` 的 `labelWidth` 优先级更高 */
|
|
187
|
+
labelWidth: {
|
|
188
|
+
type: Number,
|
|
189
|
+
default: void 0
|
|
190
|
+
},
|
|
191
|
+
/** 表单级 label 对齐;`Form.Item` 的 `labelAlign` 优先级更高 */
|
|
192
|
+
labelAlign: {
|
|
193
|
+
type: String,
|
|
194
|
+
default: void 0
|
|
195
|
+
},
|
|
196
|
+
/** 表单级控件列宽上限(px);`Form.Item` 的 `controlWidth` 优先级更高 */
|
|
197
|
+
controlWidth: {
|
|
198
|
+
type: Number,
|
|
199
|
+
default: void 0
|
|
200
|
+
},
|
|
201
|
+
/** 列数:1(逐行,默认)/ 2(容器够宽才并排,窄了自动回落一列) */
|
|
202
|
+
columns: {
|
|
203
|
+
type: Number,
|
|
204
|
+
default: 1
|
|
205
|
+
},
|
|
206
|
+
/** 表单内距(px 数字,或 `{ y, x }`);缺省 0 = 贴容器边(弹窗 / 抽屉里常用它自带内距) */
|
|
207
|
+
padding: {
|
|
208
|
+
type: [Number, Object],
|
|
209
|
+
default: void 0
|
|
210
|
+
},
|
|
211
|
+
/**
|
|
212
|
+
* 排布:`horizontal`(label 在左,缺省)/ `vertical`(label 在控件上方)。
|
|
213
|
+
*
|
|
214
|
+
* 窄容器(抽屉 / 移动端)与「字段名很长」的场景请用纵向 —— 横向时 label 列宽会把控件压得很窄。
|
|
215
|
+
*/
|
|
216
|
+
layout: {
|
|
217
|
+
type: String,
|
|
218
|
+
default: "horizontal"
|
|
219
|
+
},
|
|
220
|
+
/**
|
|
221
|
+
* 行距(px,字段行之间 / 与 `Form.Header` 之间);缺省沿用样式里的 8px 档。
|
|
222
|
+
*
|
|
223
|
+
* 筛选条这类「上行 + 一行字段」的紧凑排布要 16(设计稿口径);长表单也可以调松。
|
|
224
|
+
*/
|
|
225
|
+
gap: {
|
|
226
|
+
type: Number,
|
|
227
|
+
default: void 0
|
|
228
|
+
},
|
|
229
|
+
/** 受控表单值(字段名 → 值);不传即非受控(由 `defaultValue` 起) */
|
|
230
|
+
modelValue: {
|
|
231
|
+
type: Object,
|
|
232
|
+
default: void 0
|
|
233
|
+
},
|
|
234
|
+
/** 非受控初值;其中的键会一并成为快照的键(不必等字段挂载) */
|
|
235
|
+
defaultValue: {
|
|
236
|
+
type: Object,
|
|
237
|
+
default: void 0
|
|
238
|
+
},
|
|
239
|
+
/** 值变更(快照含**全部已登记字段**,未设值的字段为 `undefined`) */
|
|
240
|
+
onChange: {
|
|
241
|
+
type: Function,
|
|
242
|
+
default: void 0
|
|
243
|
+
}
|
|
244
|
+
},
|
|
245
|
+
emits: {
|
|
246
|
+
"update:modelValue": (values) => true
|
|
247
|
+
},
|
|
248
|
+
slots: Object,
|
|
249
|
+
setup(props, {
|
|
250
|
+
slots,
|
|
251
|
+
attrs,
|
|
252
|
+
emit,
|
|
253
|
+
expose
|
|
254
|
+
}) {
|
|
255
|
+
provide(FORM_LABEL_WIDTH, toRef(props, "labelWidth"));
|
|
256
|
+
provide(FORM_LABEL_ALIGN, toRef(props, "labelAlign"));
|
|
257
|
+
provide(FORM_CONTROL_WIDTH, toRef(props, "controlWidth"));
|
|
258
|
+
const inner = ref({
|
|
259
|
+
...props.defaultValue ?? {}
|
|
260
|
+
});
|
|
261
|
+
const registered = ref([]);
|
|
262
|
+
const source = computed(() => props.modelValue ?? inner.value);
|
|
263
|
+
const names = computed(() => [.../* @__PURE__ */ new Set([...registered.value, ...Object.keys(props.defaultValue ?? {})])]);
|
|
264
|
+
const values = computed(() => {
|
|
265
|
+
const out = {};
|
|
266
|
+
for (const name of names.value) out[name] = source.value[name];
|
|
267
|
+
return out;
|
|
268
|
+
});
|
|
269
|
+
const register = (name) => {
|
|
270
|
+
if (name && !registered.value.includes(name)) registered.value = [...registered.value, name];
|
|
271
|
+
};
|
|
272
|
+
const apply = (next) => {
|
|
273
|
+
if (props.modelValue === void 0) inner.value = next;
|
|
274
|
+
emit("update:modelValue", next);
|
|
275
|
+
props.onChange?.(next);
|
|
276
|
+
};
|
|
277
|
+
const write = (name, value) => {
|
|
278
|
+
register(name);
|
|
279
|
+
apply({
|
|
280
|
+
...values.value,
|
|
281
|
+
[name]: value
|
|
282
|
+
});
|
|
283
|
+
};
|
|
284
|
+
provide(FORM_STORE, {
|
|
285
|
+
register,
|
|
286
|
+
read: (name) => source.value[name],
|
|
287
|
+
write
|
|
288
|
+
});
|
|
289
|
+
expose({
|
|
290
|
+
/** 当前快照(含全部已登记字段) */
|
|
291
|
+
getValues: () => values.value,
|
|
292
|
+
/**
|
|
293
|
+
* 清空全部字段(置 `undefined`;受控模式下同样会发 `update:modelValue`)。
|
|
294
|
+
*
|
|
295
|
+
* **返回清空后的快照**:受控时外部还没回写 `modelValue`,调用方此刻再 `getValues()`
|
|
296
|
+
* 会读到清空前的旧值 —— 直接吃返回值才不依赖回写时序。
|
|
297
|
+
*/
|
|
298
|
+
clear: () => {
|
|
299
|
+
const cleared = {};
|
|
300
|
+
for (const name of names.value) cleared[name] = void 0;
|
|
301
|
+
apply(cleared);
|
|
302
|
+
return cleared;
|
|
303
|
+
}
|
|
304
|
+
});
|
|
305
|
+
return () => {
|
|
306
|
+
const raw = slots.default?.();
|
|
307
|
+
const list = Array.isArray(raw) ? raw : raw == null ? [] : [raw];
|
|
308
|
+
const {
|
|
309
|
+
header,
|
|
310
|
+
rest
|
|
311
|
+
} = splitFormHeader(list);
|
|
312
|
+
return createVNode("div", {
|
|
313
|
+
"class": ["mh-form", props.columns === 2 ? "mh-form--two-column" : "", props.layout === "vertical" ? "mh-form--vertical" : "", attrs.class].filter(Boolean).join(" "),
|
|
314
|
+
"style": [mergePartStyle(attrs.style, props.padding), props.gap !== void 0 ? {
|
|
315
|
+
gap: `${props.gap}px`
|
|
316
|
+
} : null]
|
|
317
|
+
}, [header, rest]);
|
|
318
|
+
};
|
|
319
|
+
}
|
|
320
|
+
});
|
|
321
|
+
const Form = Object.assign(FormRoot, {
|
|
322
|
+
Header: FormHeader,
|
|
323
|
+
Item: FormItem
|
|
324
|
+
});
|
|
325
|
+
export {
|
|
326
|
+
Form,
|
|
327
|
+
FormHeader,
|
|
328
|
+
FormItem
|
|
329
|
+
};
|