@qin-ui/vant-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,530 @@
1
+ import { Button, Signature, Area, Cascader, TimePicker, DatePicker, Picker, RadioGroup, CheckboxGroup, Uploader, Slider, Rate, Stepper, Switch, Field, Form, Popup } from "vant";
2
+ import { inject, reactive, ref, computed, provide, defineComponent, toValue, useSlots, watchEffect, createBlock, openBlock, unref, mergeProps, withCtx, createVNode, renderSlot, createElementVNode, useAttrs, createElementBlock, Fragment, createCommentVNode, Teleport, resolveDynamicComponent, isRef, createSlots, renderList, normalizeProps, isVNode, createTextVNode, toDisplayString, guardReactiveProps, resolveComponent } from "vue";
3
+ import { INJECT_CONFIG, getInjectConfig, INJECT_COMPONENTS } from "../component-provider/index.js";
4
+ import { u as useForm$1, I as InjectionFormKey, c as camelizeProperties, a as InjectionPathKey, b as useFields$1, d as useFormRef$1 } from "../core/index-D-2iAH6o.js";
5
+ import { e } from "../core/index-D-2iAH6o.js";
6
+ import { o as omit, c as cloneDeep, i as isPlainObject, t as toPath } from "../vendor/utils/lodash-es-DN4QDiDm.js";
7
+ const componentMap = {
8
+ field: Field,
9
+ switch: Switch,
10
+ stepper: Stepper,
11
+ rate: Rate,
12
+ slider: Slider,
13
+ uploader: Uploader,
14
+ "checkbox-group": CheckboxGroup,
15
+ "radio-group": RadioGroup,
16
+ picker: Picker,
17
+ "date-picker": DatePicker,
18
+ "time-picker": TimePicker,
19
+ cascader: Cascader,
20
+ area: Area,
21
+ signature: Signature,
22
+ button: Button
23
+ };
24
+ const TeleportComponentNamePrefix = "TeleportComponent_";
25
+ const InjectionPopupKey = Symbol("form-popup");
26
+ function useFormPopup(initRoot) {
27
+ if (!initRoot) {
28
+ const injectStore = inject(InjectionPopupKey, void 0);
29
+ if (injectStore) return injectStore;
30
+ }
31
+ const props = reactive({
32
+ safeAreaInsetBottom: true,
33
+ position: "bottom",
34
+ round: true
35
+ });
36
+ const popupFieldPath = ref();
37
+ const popupFieldValue = ref();
38
+ function open(path) {
39
+ popupFieldPath.value = path;
40
+ }
41
+ function close() {
42
+ popupFieldPath.value = void 0;
43
+ popupFieldValue.value = void 0;
44
+ }
45
+ const visible = computed(() => !!popupFieldPath.value);
46
+ function updateProps(_props) {
47
+ Object.assign(props, _props);
48
+ }
49
+ const store = {
50
+ props,
51
+ open,
52
+ close,
53
+ updateProps,
54
+ visible,
55
+ popupFieldPath,
56
+ popupFieldValue
57
+ };
58
+ provide(InjectionPopupKey, store);
59
+ return store;
60
+ }
61
+ function useForm(...args) {
62
+ let root = true;
63
+ if (args.length === 1) {
64
+ root = args[0];
65
+ } else if (args.length >= 2) {
66
+ root = args[2] ?? root;
67
+ }
68
+ const form = useForm$1(...args);
69
+ const formPopup = useFormPopup(root);
70
+ return { ...form, formPopup };
71
+ }
72
+ const _sfc_main$6 = /* @__PURE__ */ defineComponent({
73
+ ...{ name: "ProForm", inheritAttrs: false },
74
+ __name: "index",
75
+ props: {
76
+ form: {}
77
+ },
78
+ setup(__props) {
79
+ const props = __props;
80
+ const form = props.form || useForm(true);
81
+ provide(InjectionFormKey, form);
82
+ const { fields, setFormRef, formPopup } = form;
83
+ const formFields = computed(() => {
84
+ const f = toValue(fields);
85
+ return Array.isArray(f) ? f : [];
86
+ });
87
+ const config = INJECT_CONFIG["pro-form"];
88
+ const injectAttrs = inject(config.injectionKey, config.default);
89
+ const slots = useSlots();
90
+ watchEffect(() => {
91
+ Object.keys(slots).forEach((name) => {
92
+ if (name === "default") return;
93
+ provide(`${TeleportComponentNamePrefix}${name}`, slots[name]);
94
+ });
95
+ });
96
+ const popupProps = computed(() => {
97
+ const { container, ...rest } = formPopup.props;
98
+ return rest;
99
+ });
100
+ return (_ctx, _cache) => {
101
+ return openBlock(), createBlock(unref(Form), mergeProps({
102
+ ref: (el) => {
103
+ var _a;
104
+ return (_a = unref(setFormRef)) == null ? void 0 : _a(el);
105
+ }
106
+ }, mergeProps(unref(injectAttrs), unref(camelizeProperties)(_ctx.$attrs)), { class: "pro-form" }), {
107
+ default: withCtx(() => [
108
+ createVNode(unref(_sfc_main), { fields: formFields.value }, null, 8, ["fields"]),
109
+ createVNode(unref(Popup), mergeProps(popupProps.value, {
110
+ show: unref(formPopup).visible.value,
111
+ teleport: "#app",
112
+ onClose: unref(formPopup).close
113
+ }), {
114
+ default: withCtx(() => [..._cache[0] || (_cache[0] = [
115
+ createElementVNode("div", { id: "pro-form-popup-content" }, null, -1)
116
+ ])]),
117
+ _: 1
118
+ }, 16, ["show", "onClose"]),
119
+ renderSlot(_ctx.$slots, "default")
120
+ ]),
121
+ _: 3
122
+ }, 16);
123
+ };
124
+ }
125
+ });
126
+ const getInitProps = (field) => {
127
+ const { component } = field;
128
+ if (typeof component === "string") {
129
+ const config = getInjectConfig(component);
130
+ if (!config) return {};
131
+ const injectProps = inject(config.injectionKey, config.default);
132
+ return injectProps;
133
+ }
134
+ return {};
135
+ };
136
+ const _sfc_main$5 = /* @__PURE__ */ defineComponent({
137
+ ...{ name: "BaseField", inheritAttrs: false },
138
+ __name: "index",
139
+ props: {
140
+ component: { default: () => void 0 },
141
+ path: { default: "" }
142
+ },
143
+ setup(__props, { expose: __expose }) {
144
+ const uiFieldPropsKeys = Object.keys(Field.props || {});
145
+ const form = useForm(false);
146
+ const { getFormData, setFormData, formPopup } = form;
147
+ const { popupFieldPath, popupFieldValue } = formPopup;
148
+ const componentRef = ref();
149
+ const fieldRef = ref();
150
+ const attrs = useAttrs();
151
+ function getOldValue() {
152
+ return cloneDeep(getFormData == null ? void 0 : getFormData(__props.path));
153
+ }
154
+ const value = computed({
155
+ get() {
156
+ let val = getFormData == null ? void 0 : getFormData(__props.path);
157
+ const { valueFormatter } = groupedAttrs.value;
158
+ if (typeof valueFormatter === "object" && typeof valueFormatter.get === "function") {
159
+ val = valueFormatter.get(val);
160
+ }
161
+ return val;
162
+ },
163
+ set(val) {
164
+ let newVal = val;
165
+ const { valueFormatter } = groupedAttrs.value;
166
+ if (valueFormatter) {
167
+ if (typeof valueFormatter === "function") {
168
+ newVal = valueFormatter(val, getOldValue());
169
+ } else if (typeof valueFormatter.set === "function") {
170
+ newVal = valueFormatter.set(val, getOldValue());
171
+ }
172
+ }
173
+ setFormData == null ? void 0 : setFormData(__props.path, newVal);
174
+ }
175
+ });
176
+ const popupCloseEventName = computed(() => {
177
+ let confirm = "onConfirm";
178
+ let cancel = "onCancel";
179
+ if (__props.component === "cascader") {
180
+ confirm = "onFinish";
181
+ cancel = "onClose";
182
+ } else if (__props.component === "signature") {
183
+ confirm = "onSubmit";
184
+ }
185
+ return { confirm, cancel };
186
+ });
187
+ const groupedAttrs = computed(() => {
188
+ const initProps = getInitProps({
189
+ component: __props.component,
190
+ type: attrs.type
191
+ });
192
+ const modelPropName = attrs.modelProp ?? initProps.modelProp ?? "modelValue";
193
+ const mergedProps = mergeProps(
194
+ initProps,
195
+ attrs,
196
+ { disabled: attrs.disabled ?? initProps.disabled },
197
+ { modelProp: modelPropName }
198
+ );
199
+ const { valueFormatter, displayFormatter, modelProp, slots, fieldClass, fieldStyle, componentContainer, popup, ...rest } = mergedProps;
200
+ const modelBindingProp = modelProp ?? "modelValue";
201
+ const bindAttrs = omit(rest, [
202
+ modelBindingProp,
203
+ `onUpdate:${modelBindingProp}`
204
+ ]);
205
+ if (popup) {
206
+ const {
207
+ [popupCloseEventName.value.confirm]: confirmEvent,
208
+ [popupCloseEventName.value.cancel]: cancelEvent
209
+ } = bindAttrs;
210
+ Object.assign(bindAttrs, {
211
+ [popupCloseEventName.value.confirm]: (...args) => {
212
+ value.value = popupFieldValue.value;
213
+ formPopup.close();
214
+ confirmEvent == null ? void 0 : confirmEvent(...args);
215
+ },
216
+ [popupCloseEventName.value.cancel]: (...args) => {
217
+ formPopup.close();
218
+ cancelEvent == null ? void 0 : cancelEvent(...args);
219
+ }
220
+ });
221
+ }
222
+ const fieldAttrs = Object.keys(bindAttrs).reduce(
223
+ (acc, key) => {
224
+ if ((uiFieldPropsKeys.includes(key) || key.startsWith("on")) && key !== "type") {
225
+ acc[key] = bindAttrs[key];
226
+ }
227
+ return acc;
228
+ },
229
+ { class: fieldClass, style: fieldStyle }
230
+ );
231
+ return {
232
+ attrs: bindAttrs,
233
+ fieldAttrs,
234
+ slots,
235
+ componentContainer,
236
+ modelProp: modelBindingProp,
237
+ valueFormatter,
238
+ displayFormatter,
239
+ popup
240
+ };
241
+ });
242
+ const teleportComponent = inject(
243
+ `${TeleportComponentNamePrefix}${__props.path}`,
244
+ void 0
245
+ );
246
+ const customComponents = inject(INJECT_COMPONENTS, {});
247
+ const is = computed(() => {
248
+ if (teleportComponent) return teleportComponent;
249
+ if (typeof __props.component === "string") {
250
+ return customComponents[__props.component] || componentMap[__props.component] || __props.component;
251
+ }
252
+ return __props.component;
253
+ });
254
+ const popupAble = computed(() => !!groupedAttrs.value.popup);
255
+ const popupContainer = computed(
256
+ () => {
257
+ var _a;
258
+ return typeof groupedAttrs.value.popup === "boolean" ? void 0 : (_a = groupedAttrs.value.popup) == null ? void 0 : _a.container;
259
+ }
260
+ );
261
+ const displayValue = computed(() => {
262
+ const { displayFormatter } = groupedAttrs.value;
263
+ if (displayFormatter && typeof displayFormatter === "function") {
264
+ return displayFormatter(value.value);
265
+ }
266
+ return value.value;
267
+ });
268
+ const onFieldClick = () => {
269
+ const attrs2 = groupedAttrs.value.attrs;
270
+ if (!popupAble.value || attrs2.disabled || attrs2.readonly) return;
271
+ const popupProps = typeof groupedAttrs.value.popup === "object" ? groupedAttrs.value.popup : {};
272
+ formPopup.updateProps(popupProps);
273
+ popupFieldValue.value = value.value;
274
+ formPopup.open(__props.path);
275
+ };
276
+ __expose({
277
+ getComponentRef: () => componentRef.value || fieldRef.value,
278
+ getComponentComputedProps: () => groupedAttrs.value.attrs
279
+ });
280
+ return (_ctx, _cache) => {
281
+ return openBlock(), createBlock(unref(_sfc_main$4), {
282
+ component: groupedAttrs.value.componentContainer,
283
+ path: __props.path
284
+ }, {
285
+ default: withCtx(() => [
286
+ popupAble.value ? (openBlock(), createElementBlock(Fragment, { key: 0 }, [
287
+ createVNode(unref(Field), mergeProps({
288
+ ref_key: "fieldRef",
289
+ ref: fieldRef
290
+ }, {
291
+ readonly: true,
292
+ clickable: true,
293
+ isLink: true,
294
+ ...groupedAttrs.value.fieldAttrs
295
+ }, {
296
+ "model-value": displayValue.value,
297
+ onClick: onFieldClick
298
+ }), null, 16, ["model-value"]),
299
+ unref(popupFieldPath) === __props.path ? (openBlock(), createBlock(unref(_sfc_main$4), {
300
+ key: 0,
301
+ component: Teleport,
302
+ to: "#pro-form-popup-content",
303
+ defer: ""
304
+ }, {
305
+ default: withCtx(() => [
306
+ createVNode(unref(_sfc_main$4), {
307
+ component: popupContainer.value,
308
+ path: __props.path
309
+ }, {
310
+ default: withCtx(() => [
311
+ is.value ? (openBlock(), createBlock(resolveDynamicComponent(is.value), mergeProps({ key: 0 }, groupedAttrs.value.attrs, {
312
+ [`${groupedAttrs.value.modelProp}`]: unref(popupFieldValue),
313
+ [`onUpdate:${groupedAttrs.value.modelProp}`]: _cache[0] || (_cache[0] = ($event) => isRef(popupFieldValue) ? popupFieldValue.value = $event : null)
314
+ }), createSlots({ _: 2 }, [
315
+ renderList(groupedAttrs.value.slots, (slot, name) => {
316
+ return {
317
+ name,
318
+ fn: withCtx((scoped) => [
319
+ createVNode(unref(_sfc_main$3), mergeProps({ path: __props.path }, scoped, { component: slot }), null, 16, ["path", "component"])
320
+ ])
321
+ };
322
+ })
323
+ ]), 1040)) : createCommentVNode("", true)
324
+ ]),
325
+ _: 1
326
+ }, 8, ["component", "path"])
327
+ ]),
328
+ _: 1
329
+ })) : createCommentVNode("", true)
330
+ ], 64)) : typeof __props.component === "string" ? (openBlock(), createElementBlock(Fragment, { key: 1 }, [
331
+ __props.component === "field" ? (openBlock(), createBlock(resolveDynamicComponent(is.value), mergeProps({ key: 0 }, groupedAttrs.value.attrs, {
332
+ ref_key: "componentRef",
333
+ ref: componentRef,
334
+ [`${groupedAttrs.value.modelProp}`]: value.value,
335
+ [`onUpdate:${groupedAttrs.value.modelProp}`]: _cache[1] || (_cache[1] = ($event) => value.value = $event),
336
+ name: __props.path
337
+ }), createSlots({ _: 2 }, [
338
+ renderList(groupedAttrs.value.slots, (slot, name) => {
339
+ return {
340
+ name,
341
+ fn: withCtx((scoped) => [
342
+ createVNode(unref(_sfc_main$3), mergeProps({ path: __props.path }, scoped, { component: slot }), null, 16, ["path", "component"])
343
+ ])
344
+ };
345
+ })
346
+ ]), 1040, ["name"])) : (openBlock(), createBlock(unref(Field), mergeProps({
347
+ key: 1,
348
+ ref_key: "fieldRef",
349
+ ref: fieldRef
350
+ }, groupedAttrs.value.fieldAttrs, { name: __props.path }), {
351
+ input: withCtx(() => [
352
+ is.value ? (openBlock(), createBlock(resolveDynamicComponent(is.value), mergeProps({ key: 0 }, groupedAttrs.value.attrs, {
353
+ ref_key: "componentRef",
354
+ ref: componentRef,
355
+ [`${groupedAttrs.value.modelProp}`]: value.value,
356
+ [`onUpdate:${groupedAttrs.value.modelProp}`]: _cache[2] || (_cache[2] = ($event) => value.value = $event)
357
+ }), createSlots({ _: 2 }, [
358
+ renderList(groupedAttrs.value.slots, (slot, name) => {
359
+ return {
360
+ name,
361
+ fn: withCtx((scoped) => [
362
+ createVNode(unref(_sfc_main$3), mergeProps({ path: __props.path }, scoped, { component: slot }), null, 16, ["path", "component"])
363
+ ])
364
+ };
365
+ })
366
+ ]), 1040)) : createCommentVNode("", true)
367
+ ]),
368
+ _: 1
369
+ }, 16, ["name"]))
370
+ ], 64)) : (openBlock(), createElementBlock(Fragment, { key: 2 }, [
371
+ is.value ? (openBlock(), createBlock(resolveDynamicComponent(is.value), mergeProps({ key: 0 }, groupedAttrs.value.attrs, {
372
+ ref_key: "componentRef",
373
+ ref: componentRef,
374
+ [`${groupedAttrs.value.modelProp}`]: value.value,
375
+ [`onUpdate:${groupedAttrs.value.modelProp}`]: _cache[3] || (_cache[3] = ($event) => value.value = $event)
376
+ }), createSlots({ _: 2 }, [
377
+ renderList(groupedAttrs.value.slots, (slot, name) => {
378
+ return {
379
+ name,
380
+ fn: withCtx((scoped) => [
381
+ createVNode(unref(_sfc_main$3), mergeProps({ path: __props.path }, scoped, { component: slot }), null, 16, ["path", "component"])
382
+ ])
383
+ };
384
+ })
385
+ ]), 1040)) : createCommentVNode("", true)
386
+ ], 64))
387
+ ]),
388
+ _: 1
389
+ }, 8, ["component", "path"]);
390
+ };
391
+ }
392
+ });
393
+ const _sfc_main$4 = /* @__PURE__ */ defineComponent({
394
+ ...{ name: "ContainerFragment", inheritAttrs: false },
395
+ __name: "index",
396
+ props: {
397
+ component: { type: [Object, Function, String, Symbol] }
398
+ },
399
+ setup(__props) {
400
+ return (_ctx, _cache) => {
401
+ return __props.component ? (openBlock(), createBlock(resolveDynamicComponent(__props.component), normalizeProps(mergeProps({ key: 0 }, _ctx.$attrs)), {
402
+ default: withCtx(() => [
403
+ renderSlot(_ctx.$slots, "default")
404
+ ]),
405
+ _: 3
406
+ }, 16)) : renderSlot(_ctx.$slots, "default", { key: 1 });
407
+ };
408
+ }
409
+ });
410
+ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
411
+ ...{ name: "SlotComponent", inheritAttrs: false },
412
+ __name: "index",
413
+ props: {
414
+ component: { type: [Object, Function, String, Number, Boolean, null] }
415
+ },
416
+ setup(__props) {
417
+ return (_ctx, _cache) => {
418
+ 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 }, [
419
+ createTextVNode(toDisplayString(__props.component), 1)
420
+ ], 64));
421
+ };
422
+ }
423
+ });
424
+ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
425
+ __name: "index",
426
+ props: {
427
+ path: {}
428
+ },
429
+ setup(__props) {
430
+ const props = __props;
431
+ const namePath = computed(() => {
432
+ return Array.isArray(props.path) ? props.path.join(".") : props.path;
433
+ });
434
+ provide(InjectionPathKey, namePath);
435
+ return (_ctx, _cache) => {
436
+ return renderSlot(_ctx.$slots, "default", { path: namePath.value });
437
+ };
438
+ }
439
+ });
440
+ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
441
+ __name: "index",
442
+ props: {
443
+ field: {}
444
+ },
445
+ setup(__props) {
446
+ const props = __props;
447
+ const groupedAttributes = computed(() => {
448
+ let componentProps = {};
449
+ if (isPlainObject(props.field)) {
450
+ const { path, formItemContainer, fields, hidden, extraProps, ...rest } = props.field;
451
+ componentProps = rest;
452
+ }
453
+ return { componentProps };
454
+ });
455
+ return (_ctx, _cache) => {
456
+ return renderSlot(_ctx.$slots, "default", normalizeProps(guardReactiveProps(groupedAttributes.value)));
457
+ };
458
+ }
459
+ });
460
+ const _sfc_main = /* @__PURE__ */ defineComponent({
461
+ ...{ name: "BaseFormItem", inheritAttrs: false },
462
+ __name: "index",
463
+ props: {
464
+ fields: {}
465
+ },
466
+ setup(__props) {
467
+ const props = __props;
468
+ const validFields = computed(() => {
469
+ const f = toValue(props.fields);
470
+ if (!Array.isArray(f)) return [];
471
+ return f.filter((field) => !toValue(field.hidden));
472
+ });
473
+ return (_ctx, _cache) => {
474
+ const _component_BaseFormItem = resolveComponent("BaseFormItem");
475
+ return openBlock(true), createElementBlock(Fragment, null, renderList(validFields.value, (field, index) => {
476
+ return openBlock(), createBlock(unref(_sfc_main$2), {
477
+ key: unref(toPath)(toValue(field.path || index)).join(".") || index,
478
+ path: toValue(field.path)
479
+ }, {
480
+ default: withCtx(({ path }) => [
481
+ createVNode(unref(_sfc_main$1), { field }, {
482
+ default: withCtx(({ componentProps }) => [
483
+ field.fields ? (openBlock(), createBlock(unref(_sfc_main$4), mergeProps({
484
+ key: 0,
485
+ component: field.fieldContainer,
486
+ path
487
+ }, { ref_for: true }, componentProps), {
488
+ default: withCtx(() => [
489
+ createVNode(_component_BaseFormItem, {
490
+ fields: field.fields
491
+ }, null, 8, ["fields"])
492
+ ]),
493
+ _: 2
494
+ }, 1040, ["component", "path"])) : (openBlock(), createBlock(unref(_sfc_main$5), mergeProps({
495
+ key: 1,
496
+ ref_for: true
497
+ }, componentProps, { path }), null, 16, ["path"]))
498
+ ]),
499
+ _: 2
500
+ }, 1032, ["field"])
501
+ ]),
502
+ _: 2
503
+ }, 1032, ["path"]);
504
+ }), 128);
505
+ };
506
+ }
507
+ });
508
+ const useFields = useFields$1;
509
+ const useFormRef = useFormRef$1;
510
+ export {
511
+ _sfc_main$5 as BaseField,
512
+ _sfc_main$6 as BaseForm,
513
+ _sfc_main as BaseFormItem,
514
+ _sfc_main$4 as ContainerFragment,
515
+ _sfc_main$1 as GroupedFieldAttrs,
516
+ InjectionFormKey,
517
+ InjectionPathKey,
518
+ InjectionPopupKey,
519
+ _sfc_main$2 as PathProvider,
520
+ _sfc_main$3 as SlotComponent,
521
+ TeleportComponentNamePrefix,
522
+ componentMap,
523
+ _sfc_main$6 as default,
524
+ getInitProps,
525
+ useFields,
526
+ useForm,
527
+ e as useFormData,
528
+ useFormPopup,
529
+ useFormRef
530
+ };