@qin-ui/antd-vue-pro 1.1.25 → 2.0.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 +73 -322
- package/es/antd-vue-pro.css +52 -0
- package/es/component-provider/index-DtsWFG3s.js +154 -0
- package/es/component-provider/index.js +3 -85
- package/es/form/index.js +637 -18
- package/es/index.d.ts +778 -7488
- package/es/index.js +19 -24
- package/es/table/index.js +538 -498
- package/es/vendor/utils/lodash-es-Bu1KKNMo.js +985 -0
- package/package.json +13 -8
- package/es/form/index-1cdda7ac.js +0 -16336
- package/es/style.css +0 -43
package/es/form/index.js
CHANGED
|
@@ -1,20 +1,639 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import "vue";
|
|
3
|
-
import "ant-design-vue";
|
|
4
|
-
import "
|
|
1
|
+
import { Form, Input, Textarea, InputSearch, InputPassword, InputNumber, Select, Cascader, DatePicker, RangePicker, TimePicker, CheckboxGroup, RadioGroup, Switch, Slider, TreeSelect, Transfer, Row, Col, FormItem } from "ant-design-vue";
|
|
2
|
+
import "ant-design-vue/es/table";
|
|
3
|
+
import { useProviderDisabled, useInjectDisabled } from "ant-design-vue/es/config-provider/DisabledContext";
|
|
4
|
+
import { colProps } from "ant-design-vue/es/grid/Col";
|
|
5
|
+
import { formItemProps, useInjectFormItemContext } from "ant-design-vue/es/form";
|
|
6
|
+
import { defineComponent, provide, inject, useSlots, watchEffect, createBlock, openBlock, unref, mergeProps, withCtx, createVNode, renderSlot, computed, toValue, normalizeProps, guardReactiveProps, resolveComponent, createElementBlock, Fragment, renderList, createSlots, ref, reactive, useAttrs, createCommentVNode, resolveDynamicComponent, isVNode, createTextVNode, toDisplayString } from "vue";
|
|
7
|
+
import { I as INJECT_CONFIG, g as getObject } from "../component-provider/index-DtsWFG3s.js";
|
|
8
|
+
import { i as isPlainObject, t as toPath, g as get, s as set, c as cloneDeep } from "../vendor/utils/lodash-es-Bu1KKNMo.js";
|
|
9
|
+
const _sfc_main$6 = /* @__PURE__ */ defineComponent({
|
|
10
|
+
...{ name: "ProForm", inheritAttrs: false },
|
|
11
|
+
__name: "index",
|
|
12
|
+
props: {
|
|
13
|
+
grid: { type: [Boolean, Object], default: false },
|
|
14
|
+
form: { default: () => ({}) }
|
|
15
|
+
},
|
|
16
|
+
setup(__props) {
|
|
17
|
+
const props = __props;
|
|
18
|
+
provide(FORM, props.form);
|
|
19
|
+
const { formData, fields, setFormRef } = props.form;
|
|
20
|
+
const config = INJECT_CONFIG["pro-form"];
|
|
21
|
+
const { grid: _injectGrid, ...injectAttrs } = inject(
|
|
22
|
+
config.injectionKey,
|
|
23
|
+
config.default
|
|
24
|
+
);
|
|
25
|
+
const slots = useSlots();
|
|
26
|
+
watchEffect(() => {
|
|
27
|
+
Object.keys(slots).forEach((name) => {
|
|
28
|
+
if (name === "default") return;
|
|
29
|
+
provide(`${TeleportComponentNamePrefix}${name}`, slots[name]);
|
|
30
|
+
});
|
|
31
|
+
});
|
|
32
|
+
return (_ctx, _cache) => {
|
|
33
|
+
return openBlock(), createBlock(unref(Form), mergeProps({
|
|
34
|
+
ref: (el) => {
|
|
35
|
+
var _a;
|
|
36
|
+
return (_a = unref(setFormRef)) == null ? void 0 : _a(el);
|
|
37
|
+
},
|
|
38
|
+
model: unref(formData)
|
|
39
|
+
}, mergeProps(injectAttrs, _ctx.$attrs)), {
|
|
40
|
+
default: withCtx(() => [
|
|
41
|
+
createVNode(unref(_sfc_main$3), {
|
|
42
|
+
fields: unref(fields),
|
|
43
|
+
grid: _ctx.grid
|
|
44
|
+
}, null, 8, ["fields", "grid"]),
|
|
45
|
+
renderSlot(_ctx.$slots, "default")
|
|
46
|
+
]),
|
|
47
|
+
_: 3
|
|
48
|
+
}, 16, ["model"]);
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
const FORM_ITEM_SLOT_KEYS = ["label", "extra", "help", "tooltip"];
|
|
53
|
+
const COMPONENT_MAP = /* @__PURE__ */ new Map([
|
|
54
|
+
["input", Input],
|
|
55
|
+
["textarea", Textarea],
|
|
56
|
+
["input-search", InputSearch],
|
|
57
|
+
["input-password", InputPassword],
|
|
58
|
+
["input-number", InputNumber],
|
|
59
|
+
["select", Select],
|
|
60
|
+
["cascader", Cascader],
|
|
61
|
+
["date-picker", DatePicker],
|
|
62
|
+
["range-picker", RangePicker],
|
|
63
|
+
["time-picker", TimePicker],
|
|
64
|
+
["checkbox-group", CheckboxGroup],
|
|
65
|
+
["radio-group", RadioGroup],
|
|
66
|
+
["switch", Switch],
|
|
67
|
+
["slider", Slider],
|
|
68
|
+
["tree-select", TreeSelect],
|
|
69
|
+
["transfer", Transfer]
|
|
70
|
+
]);
|
|
71
|
+
const TeleportComponentNamePrefix = "TeleportComponent_";
|
|
72
|
+
const FORM = Symbol("form");
|
|
73
|
+
const PATH = Symbol("path");
|
|
74
|
+
const _sfc_main$5 = /* @__PURE__ */ defineComponent({
|
|
75
|
+
__name: "index",
|
|
76
|
+
props: {
|
|
77
|
+
path: {}
|
|
78
|
+
},
|
|
79
|
+
setup(__props) {
|
|
80
|
+
const props = __props;
|
|
81
|
+
const namePath = computed(() => {
|
|
82
|
+
return Array.isArray(props.path) ? props.path.join(".") : props.path;
|
|
83
|
+
});
|
|
84
|
+
provide(PATH, namePath);
|
|
85
|
+
return (_ctx, _cache) => {
|
|
86
|
+
return renderSlot(_ctx.$slots, "default", { path: namePath.value });
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
const _sfc_main$4 = /* @__PURE__ */ defineComponent({
|
|
91
|
+
__name: "index",
|
|
92
|
+
props: {
|
|
93
|
+
field: {}
|
|
94
|
+
},
|
|
95
|
+
setup(__props) {
|
|
96
|
+
const formItemPropKeys = Object.keys(formItemProps()).concat(["container"]);
|
|
97
|
+
const gridItemPropKeys = Object.keys(colProps());
|
|
98
|
+
const props = __props;
|
|
99
|
+
const config = INJECT_CONFIG["pro-form-item"];
|
|
100
|
+
const injectFormItemProps = inject(config.injectionKey, config.default);
|
|
101
|
+
const groupedAttributes = computed(() => {
|
|
102
|
+
let gridItemProps2 = {};
|
|
103
|
+
let formItemProps2 = {};
|
|
104
|
+
const componentProps = { slots: {} };
|
|
105
|
+
const formItemSlots = {};
|
|
106
|
+
if (isPlainObject(props.field)) {
|
|
107
|
+
const { path, name, fields, className, style, hidden, span, getFormItemRef, getComponentRef, getFormItemComputedProps, getComponentComputedProps, slots = {}, ...rest } = props.field;
|
|
108
|
+
const {
|
|
109
|
+
class: injectClassName,
|
|
110
|
+
style: injectStyle,
|
|
111
|
+
span: injectSpan,
|
|
112
|
+
xs,
|
|
113
|
+
sm,
|
|
114
|
+
md,
|
|
115
|
+
lg,
|
|
116
|
+
xl,
|
|
117
|
+
xxl,
|
|
118
|
+
...injectRest
|
|
119
|
+
} = injectFormItemProps;
|
|
120
|
+
const initGridItemProps = span || span === 0 ? { span } : { xs, sm, md, lg, xl, xxl, span: injectSpan };
|
|
121
|
+
gridItemProps2 = fields ? { span: span ?? 24 } : initGridItemProps;
|
|
122
|
+
formItemProps2 = mergeProps(
|
|
123
|
+
injectRest,
|
|
124
|
+
{ class: injectClassName, style: injectStyle },
|
|
125
|
+
{ class: toValue(className), style: toValue(style) }
|
|
126
|
+
);
|
|
127
|
+
Object.keys(rest).forEach((k) => {
|
|
128
|
+
if (gridItemPropKeys.includes(k)) {
|
|
129
|
+
gridItemProps2[k] = rest[k];
|
|
130
|
+
} else if (formItemPropKeys.includes(k) || k.startsWith("data-form-item")) {
|
|
131
|
+
formItemProps2[k] = rest[k];
|
|
132
|
+
} else {
|
|
133
|
+
componentProps[k] = rest[k];
|
|
134
|
+
}
|
|
135
|
+
});
|
|
136
|
+
Object.keys(slots).forEach((k) => {
|
|
137
|
+
if (FORM_ITEM_SLOT_KEYS.includes(k)) {
|
|
138
|
+
formItemSlots[k] = slots[k];
|
|
139
|
+
} else {
|
|
140
|
+
componentProps["slots"][k] = slots[k];
|
|
141
|
+
}
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
return { gridItemProps: gridItemProps2, formItemProps: formItemProps2, componentProps, formItemSlots };
|
|
145
|
+
});
|
|
146
|
+
return (_ctx, _cache) => {
|
|
147
|
+
return renderSlot(_ctx.$slots, "default", normalizeProps(guardReactiveProps(groupedAttributes.value)));
|
|
148
|
+
};
|
|
149
|
+
}
|
|
150
|
+
});
|
|
151
|
+
const _sfc_main$3 = /* @__PURE__ */ defineComponent({
|
|
152
|
+
...{ name: "BaseFormItem", inheritAttrs: false },
|
|
153
|
+
__name: "index",
|
|
154
|
+
props: {
|
|
155
|
+
grid: { type: [Boolean, Object], default: void 0 },
|
|
156
|
+
fields: { default: () => [] },
|
|
157
|
+
disabled: { type: Boolean, default: void 0 }
|
|
158
|
+
},
|
|
159
|
+
setup(__props) {
|
|
160
|
+
const props = __props;
|
|
161
|
+
const validFields = computed(
|
|
162
|
+
() => {
|
|
163
|
+
var _a, _b;
|
|
164
|
+
return (_b = (_a = props.fields).filter) == null ? void 0 : _b.call(_a, (field) => !field.hidden);
|
|
165
|
+
}
|
|
166
|
+
);
|
|
167
|
+
useProviderDisabled(computed(() => props.disabled));
|
|
168
|
+
const config = INJECT_CONFIG["pro-form"];
|
|
169
|
+
const { grid: injectGrid } = inject(config.injectionKey, config.default);
|
|
170
|
+
const enableGrid = computed(() => {
|
|
171
|
+
if (props.grid !== void 0) return !!props.grid;
|
|
172
|
+
return !!injectGrid;
|
|
173
|
+
});
|
|
174
|
+
const computedGridProps = computed(() => {
|
|
175
|
+
return enableGrid.value ? { ...getObject(injectGrid), ...getObject(props.grid) } : {};
|
|
176
|
+
});
|
|
177
|
+
const formItemRefs = [];
|
|
178
|
+
const componentRefs = [];
|
|
179
|
+
const onFormItemMounted = (index, formItemProps2) => {
|
|
180
|
+
const field = validFields.value[index];
|
|
181
|
+
Object.assign(field, {
|
|
182
|
+
getFormItemRef: () => formItemRefs[index],
|
|
183
|
+
getFormItemComputedProps: () => formItemProps2
|
|
184
|
+
});
|
|
185
|
+
};
|
|
186
|
+
const onComponentMounted = (index) => {
|
|
187
|
+
const field = validFields.value[index];
|
|
188
|
+
Object.assign(field, {
|
|
189
|
+
getComponentRef: () => {
|
|
190
|
+
var _a;
|
|
191
|
+
return (_a = componentRefs[index]) == null ? void 0 : _a.getComponentRef();
|
|
192
|
+
},
|
|
193
|
+
getComponentComputedProps: () => {
|
|
194
|
+
var _a;
|
|
195
|
+
return (_a = componentRefs[index]) == null ? void 0 : _a.getComponentComputedProps();
|
|
196
|
+
}
|
|
197
|
+
});
|
|
198
|
+
};
|
|
199
|
+
return (_ctx, _cache) => {
|
|
200
|
+
const _component_BaseFormItem = resolveComponent("BaseFormItem");
|
|
201
|
+
return openBlock(), createBlock(unref(_sfc_main$1), mergeProps({
|
|
202
|
+
component: enableGrid.value ? unref(Row) : void 0
|
|
203
|
+
}, computedGridProps.value), {
|
|
204
|
+
default: withCtx(() => [
|
|
205
|
+
(openBlock(true), createElementBlock(Fragment, null, renderList(validFields.value, ({ path: _path, name: _name, ...field }, index) => {
|
|
206
|
+
return openBlock(), createBlock(_sfc_main$5, mergeProps({
|
|
207
|
+
key: unref(toPath)(toValue(_name ?? _path)).join(".") || index
|
|
208
|
+
}, { ref_for: true }, { path: _name ?? _path }), {
|
|
209
|
+
default: withCtx(({ path }) => [
|
|
210
|
+
createVNode(_sfc_main$4, { field }, {
|
|
211
|
+
default: withCtx(({
|
|
212
|
+
gridItemProps,
|
|
213
|
+
formItemProps: { container, ...formItemProps2 },
|
|
214
|
+
componentProps,
|
|
215
|
+
formItemSlots
|
|
216
|
+
}) => [
|
|
217
|
+
createVNode(unref(_sfc_main$1), mergeProps({
|
|
218
|
+
component: enableGrid.value ? unref(Col) : void 0
|
|
219
|
+
}, { ref_for: true }, gridItemProps), {
|
|
220
|
+
default: withCtx(() => [
|
|
221
|
+
createVNode(unref(_sfc_main$1), {
|
|
222
|
+
component: container,
|
|
223
|
+
path
|
|
224
|
+
}, {
|
|
225
|
+
default: withCtx(() => [
|
|
226
|
+
createVNode(unref(FormItem), mergeProps({ ref_for: true }, formItemProps2, {
|
|
227
|
+
ref_for: true,
|
|
228
|
+
ref: (el) => formItemRefs[index] = el,
|
|
229
|
+
name: unref(toPath)(path),
|
|
230
|
+
path,
|
|
231
|
+
onVnodeMounted: ($event) => onFormItemMounted(index, formItemProps2)
|
|
232
|
+
}), createSlots({
|
|
233
|
+
default: withCtx(() => [
|
|
234
|
+
field.fields ? (openBlock(), createBlock(_component_BaseFormItem, {
|
|
235
|
+
key: 0,
|
|
236
|
+
grid: field.grid ?? _ctx.grid,
|
|
237
|
+
fields: field.fields,
|
|
238
|
+
disabled: field.disabled
|
|
239
|
+
}, null, 8, ["grid", "fields", "disabled"])) : (openBlock(), createBlock(unref(_sfc_main$2), mergeProps({
|
|
240
|
+
key: 1,
|
|
241
|
+
ref_for: true,
|
|
242
|
+
ref: (el) => componentRefs[index] = el
|
|
243
|
+
}, { ref_for: true }, componentProps, {
|
|
244
|
+
path,
|
|
245
|
+
onVnodeMounted: ($event) => onComponentMounted(index)
|
|
246
|
+
}), null, 16, ["path", "onVnodeMounted"]))
|
|
247
|
+
]),
|
|
248
|
+
_: 2
|
|
249
|
+
}, [
|
|
250
|
+
renderList(formItemSlots, (slot, name) => {
|
|
251
|
+
return {
|
|
252
|
+
name,
|
|
253
|
+
fn: withCtx((scoped) => [
|
|
254
|
+
createVNode(unref(_sfc_main), mergeProps({
|
|
255
|
+
path,
|
|
256
|
+
component: slot
|
|
257
|
+
}, { ref_for: true }, scoped), null, 16, ["path", "component"])
|
|
258
|
+
])
|
|
259
|
+
};
|
|
260
|
+
})
|
|
261
|
+
]), 1040, ["name", "path", "onVnodeMounted"])
|
|
262
|
+
]),
|
|
263
|
+
_: 2
|
|
264
|
+
}, 1032, ["component", "path"])
|
|
265
|
+
]),
|
|
266
|
+
_: 2
|
|
267
|
+
}, 1040, ["component"])
|
|
268
|
+
]),
|
|
269
|
+
_: 2
|
|
270
|
+
}, 1032, ["field"])
|
|
271
|
+
]),
|
|
272
|
+
_: 2
|
|
273
|
+
}, 1040);
|
|
274
|
+
}), 128))
|
|
275
|
+
]),
|
|
276
|
+
_: 1
|
|
277
|
+
}, 16, ["component"]);
|
|
278
|
+
};
|
|
279
|
+
}
|
|
280
|
+
});
|
|
281
|
+
const useFields = (initFields) => {
|
|
282
|
+
const fields = ref([]);
|
|
283
|
+
fields.value = initFields || [];
|
|
284
|
+
const _map = /* @__PURE__ */ new Map();
|
|
285
|
+
const cacheMatch = (pathStr, updater) => {
|
|
286
|
+
var _a;
|
|
287
|
+
const fieldPath = _map.get(pathStr) || [];
|
|
288
|
+
if (fieldPath.length === 0) return false;
|
|
289
|
+
const fieldIndex = fieldPath[fieldPath.length - 1];
|
|
290
|
+
const parentField = fieldPath.length === 1 ? fields.value : get(fields.value, fieldPath.slice(0, -2));
|
|
291
|
+
const field = (_a = parentField == null ? void 0 : parentField.fields) == null ? void 0 : _a[fieldIndex];
|
|
292
|
+
const _path = toPath((field == null ? void 0 : field.name) ?? (field == null ? void 0 : field.path)).join(".");
|
|
293
|
+
if (_path === pathStr) {
|
|
294
|
+
updater({ field, fieldIndex, parentField });
|
|
295
|
+
return true;
|
|
296
|
+
}
|
|
297
|
+
return false;
|
|
298
|
+
};
|
|
299
|
+
const updaterMatch = (path, updater, options = {}) => {
|
|
300
|
+
if (!path) return;
|
|
301
|
+
const pathStr = typeof path === "function" ? "" : toPath(path).join(".");
|
|
302
|
+
const { all = typeof path === "function" } = options;
|
|
303
|
+
if (pathStr && _map.has(pathStr) && !all) {
|
|
304
|
+
const bool = cacheMatch(pathStr, updater);
|
|
305
|
+
if (bool) return;
|
|
306
|
+
}
|
|
307
|
+
const queue = fields.value.map((field, i) => ({
|
|
308
|
+
field,
|
|
309
|
+
fieldPath: [i],
|
|
310
|
+
parentField: { fields: fields.value }
|
|
311
|
+
}));
|
|
312
|
+
while (queue.length) {
|
|
313
|
+
const { field, fieldPath, parentField } = queue.shift();
|
|
314
|
+
let matched = false;
|
|
315
|
+
const _path = toPath(field.name ?? field.path).join(".");
|
|
316
|
+
if (_path) _map.set(_path, fieldPath);
|
|
317
|
+
if (typeof path === "function") {
|
|
318
|
+
matched = path(field);
|
|
319
|
+
} else if (_path) {
|
|
320
|
+
matched = pathStr === _path;
|
|
321
|
+
}
|
|
322
|
+
if (matched) {
|
|
323
|
+
const fieldIndex = fieldPath[fieldPath.length - 1];
|
|
324
|
+
updater({ field, fieldIndex, parentField });
|
|
325
|
+
if (!all) return;
|
|
326
|
+
}
|
|
327
|
+
if (Array.isArray(field.fields)) {
|
|
328
|
+
field.fields.forEach((f, i) => {
|
|
329
|
+
queue.push({
|
|
330
|
+
field: f,
|
|
331
|
+
fieldPath: [...fieldPath, "fields", i],
|
|
332
|
+
parentField: field
|
|
333
|
+
});
|
|
334
|
+
});
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
};
|
|
338
|
+
function getField(path, options) {
|
|
339
|
+
if (!path) return void 0;
|
|
340
|
+
const res = [];
|
|
341
|
+
updaterMatch(
|
|
342
|
+
path,
|
|
343
|
+
({ field }) => {
|
|
344
|
+
res.push(field);
|
|
345
|
+
},
|
|
346
|
+
options
|
|
347
|
+
);
|
|
348
|
+
return (options == null ? void 0 : options.all) ? res : res[0];
|
|
349
|
+
}
|
|
350
|
+
function setField(path, field, options) {
|
|
351
|
+
if (!path || !field) return;
|
|
352
|
+
const { updateType = "merge", ...rest } = options || {};
|
|
353
|
+
updaterMatch(
|
|
354
|
+
path,
|
|
355
|
+
({ field: preField, fieldIndex, parentField }) => {
|
|
356
|
+
let value = field;
|
|
357
|
+
if (typeof field === "function") {
|
|
358
|
+
value = field(preField);
|
|
359
|
+
}
|
|
360
|
+
if (!value) return;
|
|
361
|
+
if (updateType === "rewrite") {
|
|
362
|
+
parentField.fields[fieldIndex] = value;
|
|
363
|
+
} else {
|
|
364
|
+
Object.assign(preField, value);
|
|
365
|
+
}
|
|
366
|
+
},
|
|
367
|
+
rest
|
|
368
|
+
);
|
|
369
|
+
}
|
|
370
|
+
function deleteField(path, options) {
|
|
371
|
+
if (!path) return;
|
|
372
|
+
updaterMatch(
|
|
373
|
+
path,
|
|
374
|
+
({ fieldIndex, parentField }) => {
|
|
375
|
+
parentField.fields.splice(fieldIndex, 1);
|
|
376
|
+
},
|
|
377
|
+
options
|
|
378
|
+
);
|
|
379
|
+
}
|
|
380
|
+
function addFields(path, newFields, options, placement) {
|
|
381
|
+
if (newFields.length === 0) return;
|
|
382
|
+
if (path) {
|
|
383
|
+
updaterMatch(
|
|
384
|
+
path,
|
|
385
|
+
({ fieldIndex, parentField }) => {
|
|
386
|
+
const index = placement === "after" ? fieldIndex + 1 : fieldIndex;
|
|
387
|
+
parentField.fields.splice(index, 0, ...newFields);
|
|
388
|
+
},
|
|
389
|
+
options
|
|
390
|
+
);
|
|
391
|
+
} else if (placement === "after") {
|
|
392
|
+
fields.value.push(...newFields);
|
|
393
|
+
} else {
|
|
394
|
+
fields.value.unshift(...newFields);
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
function appendField(path, field, options) {
|
|
398
|
+
const newFields = Array.isArray(field) ? field : [field];
|
|
399
|
+
addFields(path, newFields, options, "after");
|
|
400
|
+
}
|
|
401
|
+
function prependField(path, field, options) {
|
|
402
|
+
const newFields = Array.isArray(field) ? field : [field];
|
|
403
|
+
addFields(path, newFields, options, "before");
|
|
404
|
+
}
|
|
405
|
+
function getParentField(path, options) {
|
|
406
|
+
if (!path) return void 0;
|
|
407
|
+
const res = [];
|
|
408
|
+
updaterMatch(
|
|
409
|
+
path,
|
|
410
|
+
({ parentField }) => {
|
|
411
|
+
res.push(parentField);
|
|
412
|
+
},
|
|
413
|
+
options
|
|
414
|
+
);
|
|
415
|
+
return (options == null ? void 0 : options.all) ? res : res[0];
|
|
416
|
+
}
|
|
417
|
+
return {
|
|
418
|
+
fields,
|
|
419
|
+
getField,
|
|
420
|
+
setField,
|
|
421
|
+
deleteField,
|
|
422
|
+
appendField,
|
|
423
|
+
prependField,
|
|
424
|
+
getParentField
|
|
425
|
+
};
|
|
426
|
+
};
|
|
427
|
+
const useFormData = (initFormData = {}) => {
|
|
428
|
+
const formData = reactive(initFormData);
|
|
429
|
+
function getFormData(path) {
|
|
430
|
+
if (!path) return void 0;
|
|
431
|
+
return get(formData, path);
|
|
432
|
+
}
|
|
433
|
+
function setFormData(...args) {
|
|
434
|
+
let path;
|
|
435
|
+
let value;
|
|
436
|
+
if (args.length >= 2) {
|
|
437
|
+
[path, value] = args;
|
|
438
|
+
if (!path) return;
|
|
439
|
+
} else {
|
|
440
|
+
[value] = args;
|
|
441
|
+
}
|
|
442
|
+
if (path) {
|
|
443
|
+
if (typeof value === "function") {
|
|
444
|
+
const preValue = getFormData(path);
|
|
445
|
+
value = value(preValue);
|
|
446
|
+
}
|
|
447
|
+
set(formData, path, value);
|
|
448
|
+
} else {
|
|
449
|
+
if (typeof value === "function") {
|
|
450
|
+
const preValue = formData;
|
|
451
|
+
value = value(preValue);
|
|
452
|
+
}
|
|
453
|
+
if (!isPlainObject(value)) return;
|
|
454
|
+
Object.keys(formData).forEach((key) => {
|
|
455
|
+
delete formData[key];
|
|
456
|
+
});
|
|
457
|
+
Object.assign(formData, value);
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
return { formData, getFormData, setFormData };
|
|
461
|
+
};
|
|
462
|
+
const useFormRef = () => {
|
|
463
|
+
const formRef = ref();
|
|
464
|
+
const setFormRef = (inst) => {
|
|
465
|
+
formRef.value = inst;
|
|
466
|
+
};
|
|
467
|
+
return { formRef, setFormRef };
|
|
468
|
+
};
|
|
469
|
+
function useForm(...args) {
|
|
470
|
+
let initFormData = {}, initFields = [], root = true;
|
|
471
|
+
if (args.length === 1) {
|
|
472
|
+
root = args[0];
|
|
473
|
+
} else if (args.length >= 2) {
|
|
474
|
+
initFormData = args[0];
|
|
475
|
+
initFields = args[1];
|
|
476
|
+
root = args[2] ?? root;
|
|
477
|
+
}
|
|
478
|
+
if (!root) {
|
|
479
|
+
const injectForm = inject(FORM);
|
|
480
|
+
if (injectForm) return injectForm;
|
|
481
|
+
}
|
|
482
|
+
return {
|
|
483
|
+
...useFormData(initFormData),
|
|
484
|
+
...useFields(initFields),
|
|
485
|
+
...useFormRef()
|
|
486
|
+
};
|
|
487
|
+
}
|
|
488
|
+
const initPropsMap = /* @__PURE__ */ new Map();
|
|
489
|
+
const getInitProps = (field) => {
|
|
490
|
+
const { component, type = "" } = field;
|
|
491
|
+
if (COMPONENT_MAP.has(component)) {
|
|
492
|
+
const k = [component, type].filter(Boolean).join(".");
|
|
493
|
+
if (initPropsMap.has(k)) {
|
|
494
|
+
return initPropsMap.get(k);
|
|
495
|
+
} else if (INJECT_CONFIG[k]) {
|
|
496
|
+
const config = INJECT_CONFIG[k];
|
|
497
|
+
const injectProps = inject(config.injectionKey, config.default);
|
|
498
|
+
initPropsMap.set(k, injectProps);
|
|
499
|
+
return injectProps;
|
|
500
|
+
}
|
|
501
|
+
}
|
|
502
|
+
return {};
|
|
503
|
+
};
|
|
504
|
+
const _sfc_main$2 = /* @__PURE__ */ defineComponent({
|
|
505
|
+
...{ name: "BaseField", inheritAttrs: false },
|
|
506
|
+
__name: "index",
|
|
507
|
+
props: {
|
|
508
|
+
component: { default: void 0 },
|
|
509
|
+
path: { default: "" }
|
|
510
|
+
},
|
|
511
|
+
setup(__props, { expose: __expose }) {
|
|
512
|
+
const props = __props;
|
|
513
|
+
const form = useForm(false);
|
|
514
|
+
const { formData, getFormData, setFormData } = form;
|
|
515
|
+
const componentRef = ref();
|
|
516
|
+
const formItemContext = useInjectFormItemContext();
|
|
517
|
+
const triggerFormItemChange = () => {
|
|
518
|
+
if (COMPONENT_MAP.has(props.component)) return;
|
|
519
|
+
formItemContext.onFieldChange();
|
|
520
|
+
};
|
|
521
|
+
const attrs = useAttrs();
|
|
522
|
+
const value = computed({
|
|
523
|
+
get() {
|
|
524
|
+
return getFormData == null ? void 0 : getFormData(props.path);
|
|
525
|
+
},
|
|
526
|
+
set(val) {
|
|
527
|
+
const { valueFormatter } = attrs;
|
|
528
|
+
if (valueFormatter && typeof valueFormatter === "function") {
|
|
529
|
+
const oldVal = cloneDeep(get(formData == null ? void 0 : formData.value, props.path));
|
|
530
|
+
setFormData == null ? void 0 : setFormData(props.path, valueFormatter(val, oldVal));
|
|
531
|
+
} else {
|
|
532
|
+
setFormData == null ? void 0 : setFormData(props.path, val);
|
|
533
|
+
}
|
|
534
|
+
triggerFormItemChange();
|
|
535
|
+
}
|
|
536
|
+
});
|
|
537
|
+
const parentDisabled = useInjectDisabled();
|
|
538
|
+
const groupedAttrs = computed(() => {
|
|
539
|
+
const initProps = getInitProps({
|
|
540
|
+
component: props.component,
|
|
541
|
+
type: attrs.type
|
|
542
|
+
});
|
|
543
|
+
const mergedProps = mergeProps(
|
|
544
|
+
initProps,
|
|
545
|
+
attrs,
|
|
546
|
+
{ class: attrs.componentClassName, style: attrs.componentStyle },
|
|
547
|
+
{ class: initProps.componentClassName, style: initProps.componentStyle },
|
|
548
|
+
{ disabled: attrs.disabled ?? parentDisabled.value ?? initProps.disabled },
|
|
549
|
+
{ modelName: attrs.modelName ?? initProps.modelName ?? "value" }
|
|
550
|
+
);
|
|
551
|
+
const { valueFormatter, modelName, slots, componentClassName, componentStyle, componentContainer, ...rest } = mergedProps;
|
|
552
|
+
return { attrs: rest, slots, componentContainer, modelName };
|
|
553
|
+
});
|
|
554
|
+
const teleportComponent = inject(
|
|
555
|
+
`${TeleportComponentNamePrefix}${props.path}`,
|
|
556
|
+
void 0
|
|
557
|
+
);
|
|
558
|
+
const is = computed(() => {
|
|
559
|
+
return teleportComponent ?? COMPONENT_MAP.get(props.component) ?? props.component;
|
|
560
|
+
});
|
|
561
|
+
__expose({
|
|
562
|
+
getComponentRef: () => componentRef.value,
|
|
563
|
+
getComponentComputedProps: () => groupedAttrs.value.attrs
|
|
564
|
+
});
|
|
565
|
+
return (_ctx, _cache) => {
|
|
566
|
+
return openBlock(), createBlock(unref(_sfc_main$1), {
|
|
567
|
+
component: groupedAttrs.value.componentContainer,
|
|
568
|
+
path: _ctx.path
|
|
569
|
+
}, {
|
|
570
|
+
default: withCtx(() => [
|
|
571
|
+
is.value ? (openBlock(), createBlock(resolveDynamicComponent(is.value), mergeProps({ key: 0 }, groupedAttrs.value.attrs, {
|
|
572
|
+
ref_key: "componentRef",
|
|
573
|
+
ref: componentRef,
|
|
574
|
+
[`${groupedAttrs.value.modelName}`]: value.value,
|
|
575
|
+
[`onUpdate:${groupedAttrs.value.modelName}`]: _cache[0] || (_cache[0] = ($event) => value.value = $event),
|
|
576
|
+
path: _ctx.path
|
|
577
|
+
}), createSlots({ _: 2 }, [
|
|
578
|
+
renderList(groupedAttrs.value.slots, (slot, name) => {
|
|
579
|
+
return {
|
|
580
|
+
name,
|
|
581
|
+
fn: withCtx((scoped) => [
|
|
582
|
+
createVNode(unref(_sfc_main), mergeProps({ path: _ctx.path }, scoped, { component: slot }), null, 16, ["path", "component"])
|
|
583
|
+
])
|
|
584
|
+
};
|
|
585
|
+
})
|
|
586
|
+
]), 1040, ["path"])) : createCommentVNode("", true)
|
|
587
|
+
]),
|
|
588
|
+
_: 1
|
|
589
|
+
}, 8, ["component", "path"]);
|
|
590
|
+
};
|
|
591
|
+
}
|
|
592
|
+
});
|
|
593
|
+
const _sfc_main$1 = /* @__PURE__ */ defineComponent({
|
|
594
|
+
...{ name: "ContainerFragment", inheritAttrs: false },
|
|
595
|
+
__name: "index",
|
|
596
|
+
props: {
|
|
597
|
+
component: {}
|
|
598
|
+
},
|
|
599
|
+
setup(__props) {
|
|
600
|
+
return (_ctx, _cache) => {
|
|
601
|
+
return _ctx.component ? (openBlock(), createBlock(resolveDynamicComponent(_ctx.component), normalizeProps(mergeProps({ key: 0 }, _ctx.$attrs)), {
|
|
602
|
+
default: withCtx(() => [
|
|
603
|
+
renderSlot(_ctx.$slots, "default")
|
|
604
|
+
]),
|
|
605
|
+
_: 3
|
|
606
|
+
}, 16)) : renderSlot(_ctx.$slots, "default", { key: 1 });
|
|
607
|
+
};
|
|
608
|
+
}
|
|
609
|
+
});
|
|
610
|
+
const _sfc_main = /* @__PURE__ */ defineComponent({
|
|
611
|
+
...{ name: "SlotComponent", inheritAttrs: false },
|
|
612
|
+
__name: "index",
|
|
613
|
+
props: {
|
|
614
|
+
component: { type: [Object, String, Number, Boolean, null, Function] }
|
|
615
|
+
},
|
|
616
|
+
setup(__props) {
|
|
617
|
+
return (_ctx, _cache) => {
|
|
618
|
+
return isVNode(toValue(_ctx.component)) ? (openBlock(), createBlock(resolveDynamicComponent(_ctx.component), normalizeProps(mergeProps({ key: 0 }, _ctx.$attrs)), null, 16)) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
|
|
619
|
+
createTextVNode(toDisplayString(_ctx.component), 1)
|
|
620
|
+
], 64));
|
|
621
|
+
};
|
|
622
|
+
}
|
|
623
|
+
});
|
|
5
624
|
export {
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
625
|
+
_sfc_main$2 as BaseField,
|
|
626
|
+
_sfc_main$6 as BaseForm,
|
|
627
|
+
_sfc_main$3 as BaseFormItem,
|
|
628
|
+
COMPONENT_MAP,
|
|
629
|
+
_sfc_main$1 as ContainerFragment,
|
|
630
|
+
FORM,
|
|
631
|
+
FORM_ITEM_SLOT_KEYS,
|
|
632
|
+
PATH,
|
|
633
|
+
_sfc_main as SlotComponent,
|
|
634
|
+
TeleportComponentNamePrefix,
|
|
635
|
+
_sfc_main$6 as default,
|
|
636
|
+
useFields,
|
|
637
|
+
useForm,
|
|
638
|
+
useFormData
|
|
20
639
|
};
|