@qin-ui/antdv-next-pro 1.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.
@@ -0,0 +1,439 @@
1
+ import { defineComponent, provide, inject, useSlots, watchEffect, createBlock, openBlock, unref, mergeProps, withCtx, createVNode, renderSlot, toValue, computed, normalizeProps, guardReactiveProps, resolveComponent, createElementBlock, Fragment, renderList, createSlots, ref, useAttrs, createCommentVNode, resolveDynamicComponent, isVNode, createTextVNode, toDisplayString } from "vue";
2
+ import { FormItem, Row, Table, Form, Input, TextArea, InputSearch, InputPassword, InputNumber, InputOTP, Select, Cascader, DatePicker, DateRangePicker, TimePicker, TimeRangePicker, CheckboxGroup, RadioGroup, Switch, Slider, TreeSelect, Transfer, Col } from "antdv-next";
3
+ import { useDisabledContextProvider, useDisabledContext } from "antdv-next/dist/config-provider/DisabledContext";
4
+ import "antdv-next/dist/config-provider/SizeContext";
5
+ import { I as InjectionFormKey, a as INJECT_CONFIG, c as camelizeProperties, b as InjectionPathKey, g as getObject, u as useForm$1, d as useFields$1, e as useFormRef$1 } from "../component-provider/index-B-Yy-eoc.js";
6
+ import { i as isPlainObject, t as toPath, o as omit, c as cloneDeep } from "../vendor/utils/lodash-es-p6jau26B.js";
7
+ const tableProps = () => Table.props || {};
8
+ const gridItemProps = () => Row.props || {};
9
+ const formItemProps = () => FormItem.props || {};
10
+ const _sfc_main$6 = /* @__PURE__ */ defineComponent({
11
+ ...{ name: "ProForm", inheritAttrs: false },
12
+ __name: "index",
13
+ props: {
14
+ grid: { type: [Boolean, Object], default: false },
15
+ form: { default: () => ({}) }
16
+ },
17
+ setup(__props) {
18
+ provide(InjectionFormKey, __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, unref(camelizeProperties)(_ctx.$attrs)), { class: "pro-form" }), {
40
+ default: withCtx(() => [
41
+ createVNode(unref(_sfc_main$3), {
42
+ fields: toValue(unref(fields)),
43
+ grid: __props.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
+ ["input-otp", InputOTP],
60
+ ["select", Select],
61
+ ["cascader", Cascader],
62
+ ["date-picker", DatePicker],
63
+ ["range-picker", DateRangePicker],
64
+ ["time-picker", TimePicker],
65
+ ["time-range-picker", TimeRangePicker],
66
+ ["checkbox-group", CheckboxGroup],
67
+ ["radio-group", RadioGroup],
68
+ ["switch", Switch],
69
+ ["slider", Slider],
70
+ ["tree-select", TreeSelect],
71
+ ["transfer", Transfer]
72
+ ]);
73
+ const TeleportComponentNamePrefix = "TeleportComponent_";
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(InjectionPathKey, 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(gridItemProps());
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 validFields = computed(() => {
161
+ var _a, _b;
162
+ return (_b = (_a = __props.fields).filter) == null ? void 0 : _b.call(_a, (field) => !field.hidden);
163
+ });
164
+ useDisabledContextProvider(computed(() => __props.disabled));
165
+ const config = INJECT_CONFIG["pro-form"];
166
+ const { grid: injectGrid } = inject(config.injectionKey, config.default);
167
+ const enableGrid = computed(() => {
168
+ if (__props.grid !== void 0) return !!__props.grid;
169
+ return !!injectGrid;
170
+ });
171
+ const computedGridProps = computed(() => {
172
+ return enableGrid.value ? { ...getObject(injectGrid), ...getObject(__props.grid) } : {};
173
+ });
174
+ const formItemRefs = [];
175
+ const componentRefs = [];
176
+ const onFormItemMounted = (index, formItemProps2) => {
177
+ const field = validFields.value[index];
178
+ Object.assign(field, {
179
+ getFormItemRef: () => formItemRefs[index],
180
+ getFormItemComputedProps: () => formItemProps2
181
+ });
182
+ };
183
+ const onComponentMounted = (index) => {
184
+ const field = validFields.value[index];
185
+ Object.assign(field, {
186
+ getComponentRef: () => {
187
+ var _a;
188
+ return (_a = componentRefs[index]) == null ? void 0 : _a.getComponentRef();
189
+ },
190
+ getComponentComputedProps: () => {
191
+ var _a;
192
+ return (_a = componentRefs[index]) == null ? void 0 : _a.getComponentComputedProps();
193
+ }
194
+ });
195
+ };
196
+ return (_ctx, _cache) => {
197
+ const _component_BaseFormItem = resolveComponent("BaseFormItem");
198
+ return openBlock(), createBlock(unref(_sfc_main$1), mergeProps({
199
+ component: enableGrid.value ? unref(Row) : void 0
200
+ }, computedGridProps.value), {
201
+ default: withCtx(() => [
202
+ (openBlock(true), createElementBlock(Fragment, null, renderList(validFields.value, ({ path: _path, name: _name, ...field }, index) => {
203
+ return openBlock(), createBlock(_sfc_main$5, mergeProps({
204
+ key: unref(toPath)(toValue(_name ?? _path)).join(".") || index
205
+ }, { ref_for: true }, { path: _name ?? _path }), {
206
+ default: withCtx(({ path }) => [
207
+ createVNode(_sfc_main$4, { field }, {
208
+ default: withCtx(({
209
+ gridItemProps: gridItemProps2,
210
+ formItemProps: { container, ...formItemProps2 },
211
+ componentProps,
212
+ formItemSlots
213
+ }) => [
214
+ createVNode(unref(_sfc_main$1), mergeProps({
215
+ component: enableGrid.value ? unref(Col) : void 0
216
+ }, { ref_for: true }, gridItemProps2), {
217
+ default: withCtx(() => [
218
+ createVNode(unref(_sfc_main$1), {
219
+ component: container,
220
+ path
221
+ }, {
222
+ default: withCtx(() => [
223
+ createVNode(unref(FormItem), mergeProps({ ref_for: true }, formItemProps2, {
224
+ ref_for: true,
225
+ ref: (el) => formItemRefs[index] = el,
226
+ name: unref(toPath)(path),
227
+ path,
228
+ onVnodeMounted: ($event) => onFormItemMounted(index, formItemProps2)
229
+ }), createSlots({
230
+ default: withCtx(() => [
231
+ field.fields ? (openBlock(), createBlock(_component_BaseFormItem, {
232
+ key: 0,
233
+ grid: field.grid ?? __props.grid,
234
+ fields: field.fields,
235
+ disabled: field.disabled
236
+ }, null, 8, ["grid", "fields", "disabled"])) : (openBlock(), createBlock(unref(_sfc_main$2), mergeProps({
237
+ key: 1,
238
+ ref_for: true,
239
+ ref: (el) => componentRefs[index] = el
240
+ }, { ref_for: true }, componentProps, {
241
+ path,
242
+ onVnodeMounted: ($event) => onComponentMounted(index)
243
+ }), null, 16, ["path", "onVnodeMounted"]))
244
+ ]),
245
+ _: 2
246
+ }, [
247
+ renderList(formItemSlots, (slot, name) => {
248
+ return {
249
+ name,
250
+ fn: withCtx((scoped) => [
251
+ createVNode(unref(_sfc_main), mergeProps({
252
+ path,
253
+ component: slot
254
+ }, { ref_for: true }, scoped), null, 16, ["path", "component"])
255
+ ])
256
+ };
257
+ })
258
+ ]), 1040, ["name", "path", "onVnodeMounted"])
259
+ ]),
260
+ _: 2
261
+ }, 1032, ["component", "path"])
262
+ ]),
263
+ _: 2
264
+ }, 1040, ["component"])
265
+ ]),
266
+ _: 2
267
+ }, 1032, ["field"])
268
+ ]),
269
+ _: 2
270
+ }, 1040);
271
+ }), 128))
272
+ ]),
273
+ _: 1
274
+ }, 16, ["component"]);
275
+ };
276
+ }
277
+ });
278
+ const useForm = useForm$1;
279
+ const getInitProps = (field) => {
280
+ const { component } = field;
281
+ const type = component === "input" ? "" : field.type;
282
+ if (COMPONENT_MAP.has(component)) {
283
+ const k = [component, type].filter(Boolean).join(".");
284
+ if (INJECT_CONFIG[k]) {
285
+ const config = INJECT_CONFIG[k];
286
+ const injectProps = inject(config.injectionKey, config.default);
287
+ return injectProps;
288
+ }
289
+ }
290
+ return {};
291
+ };
292
+ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
293
+ ...{ name: "BaseField", inheritAttrs: false },
294
+ __name: "index",
295
+ props: {
296
+ component: { default: () => void 0 },
297
+ path: { default: "" }
298
+ },
299
+ setup(__props, { expose: __expose }) {
300
+ const form = useForm(false);
301
+ const { getFormData, setFormData } = form;
302
+ const componentRef = ref();
303
+ const attrs = useAttrs();
304
+ function getOldValue() {
305
+ return cloneDeep(getFormData == null ? void 0 : getFormData(__props.path));
306
+ }
307
+ const value = computed({
308
+ get() {
309
+ let val = getFormData == null ? void 0 : getFormData(__props.path);
310
+ const { valueFormatter } = groupedAttrs.value;
311
+ if (typeof valueFormatter === "object" && typeof valueFormatter.get === "function") {
312
+ val = valueFormatter.get(val);
313
+ }
314
+ return val;
315
+ },
316
+ set(val) {
317
+ let newVal = val;
318
+ const { valueFormatter } = groupedAttrs.value;
319
+ if (valueFormatter) {
320
+ if (typeof valueFormatter === "function") {
321
+ newVal = valueFormatter(val, getOldValue());
322
+ } else if (typeof valueFormatter.set === "function") {
323
+ newVal = valueFormatter.set(val, getOldValue());
324
+ }
325
+ }
326
+ setFormData == null ? void 0 : setFormData(__props.path, newVal);
327
+ }
328
+ });
329
+ const parentDisabled = useDisabledContext();
330
+ const groupedAttrs = computed(() => {
331
+ const initProps = getInitProps({
332
+ component: __props.component,
333
+ type: attrs.type
334
+ });
335
+ const mergedProps = mergeProps(
336
+ initProps,
337
+ attrs,
338
+ { class: attrs.componentClassName, style: attrs.componentStyle },
339
+ { class: initProps.componentClassName, style: initProps.componentStyle },
340
+ { disabled: attrs.disabled ?? parentDisabled.value ?? initProps.disabled },
341
+ { modelName: attrs.modelName ?? initProps.modelName ?? "value" }
342
+ );
343
+ const { valueFormatter, modelName, slots, componentClassName, componentStyle, componentContainer, ...rest } = mergedProps;
344
+ const bindAttrs = omit(rest, [modelName, `onUpdate:${modelName}`]);
345
+ return {
346
+ attrs: bindAttrs,
347
+ slots,
348
+ componentContainer,
349
+ modelName,
350
+ valueFormatter
351
+ };
352
+ });
353
+ const teleportComponent = inject(
354
+ `${TeleportComponentNamePrefix}${__props.path}`,
355
+ void 0
356
+ );
357
+ const is = computed(() => {
358
+ return teleportComponent ?? COMPONENT_MAP.get(__props.component) ?? __props.component;
359
+ });
360
+ __expose({
361
+ getComponentRef: () => componentRef.value,
362
+ getComponentComputedProps: () => groupedAttrs.value.attrs
363
+ });
364
+ return (_ctx, _cache) => {
365
+ return openBlock(), createBlock(unref(_sfc_main$1), {
366
+ component: groupedAttrs.value.componentContainer,
367
+ path: __props.path
368
+ }, {
369
+ default: withCtx(() => [
370
+ is.value ? (openBlock(), createBlock(resolveDynamicComponent(is.value), mergeProps({ key: 0 }, groupedAttrs.value.attrs, {
371
+ ref_key: "componentRef",
372
+ ref: componentRef,
373
+ [`${groupedAttrs.value.modelName}`]: value.value,
374
+ [`onUpdate:${groupedAttrs.value.modelName}`]: _cache[0] || (_cache[0] = ($event) => value.value = $event),
375
+ path: __props.path
376
+ }), createSlots({ _: 2 }, [
377
+ renderList(groupedAttrs.value.slots, (slot, name) => {
378
+ return {
379
+ name,
380
+ fn: withCtx((scoped) => [
381
+ createVNode(unref(_sfc_main), mergeProps({ path: __props.path }, scoped, { component: slot }), null, 16, ["path", "component"])
382
+ ])
383
+ };
384
+ })
385
+ ]), 1040, ["path"])) : createCommentVNode("", true)
386
+ ]),
387
+ _: 1
388
+ }, 8, ["component", "path"]);
389
+ };
390
+ }
391
+ });
392
+ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
393
+ ...{ name: "ContainerFragment", inheritAttrs: false },
394
+ __name: "index",
395
+ props: {
396
+ component: { type: [Object, Function] }
397
+ },
398
+ setup(__props) {
399
+ return (_ctx, _cache) => {
400
+ return __props.component ? (openBlock(), createBlock(resolveDynamicComponent(__props.component), normalizeProps(mergeProps({ key: 0 }, _ctx.$attrs)), {
401
+ default: withCtx(() => [
402
+ renderSlot(_ctx.$slots, "default")
403
+ ]),
404
+ _: 3
405
+ }, 16)) : renderSlot(_ctx.$slots, "default", { key: 1 });
406
+ };
407
+ }
408
+ });
409
+ const _sfc_main = /* @__PURE__ */ defineComponent({
410
+ ...{ name: "SlotComponent", inheritAttrs: false },
411
+ __name: "index",
412
+ props: {
413
+ component: { type: [Object, Function, String, Number, Boolean, null] }
414
+ },
415
+ setup(__props) {
416
+ return (_ctx, _cache) => {
417
+ return isVNode(__props.component) || typeof __props.component === "function" ? (openBlock(), createBlock(resolveDynamicComponent(__props.component), normalizeProps(mergeProps({ key: 0 }, _ctx.$attrs)), null, 16)) : (openBlock(), createElementBlock(Fragment, { key: 1 }, [
418
+ createTextVNode(toDisplayString(__props.component), 1)
419
+ ], 64));
420
+ };
421
+ }
422
+ });
423
+ const useFields = useFields$1;
424
+ const useFormRef = useFormRef$1;
425
+ export {
426
+ COMPONENT_MAP as C,
427
+ FORM_ITEM_SLOT_KEYS as F,
428
+ TeleportComponentNamePrefix as T,
429
+ _sfc_main$6 as _,
430
+ _sfc_main$1 as a,
431
+ _sfc_main$3 as b,
432
+ _sfc_main$2 as c,
433
+ _sfc_main as d,
434
+ useFields as e,
435
+ useFormRef as f,
436
+ getInitProps as g,
437
+ tableProps as t,
438
+ useForm as u
439
+ };
@@ -0,0 +1,20 @@
1
+ import { c, _, b, C, a, F, d, T, _ as _2, g, e, u, f } from "./index-DnjfDQC_.js";
2
+ import { I, b as b2, f as f2 } from "../component-provider/index-B-Yy-eoc.js";
3
+ export {
4
+ c as BaseField,
5
+ _ as BaseForm,
6
+ b as BaseFormItem,
7
+ C as COMPONENT_MAP,
8
+ a as ContainerFragment,
9
+ F as FORM_ITEM_SLOT_KEYS,
10
+ I as InjectionFormKey,
11
+ b2 as InjectionPathKey,
12
+ d as SlotComponent,
13
+ T as TeleportComponentNamePrefix,
14
+ _2 as default,
15
+ g as getInitProps,
16
+ e as useFields,
17
+ u as useForm,
18
+ f2 as useFormData,
19
+ f as useFormRef
20
+ };