@qin-ui/antd-vue-pro 2.0.16 → 2.0.19

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/es/form/index.js CHANGED
@@ -4,9 +4,11 @@ import "ant-design-vue/es/config-provider/context";
4
4
  import { useProviderDisabled, useInjectDisabled } from "ant-design-vue/es/config-provider/DisabledContext";
5
5
  import { colProps } from "ant-design-vue/es/grid/Col";
6
6
  import { formItemProps, useInjectFormItemContext } from "ant-design-vue/es/form";
7
- 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";
8
- import { I as INJECT_CONFIG, c as camelizeProperties, g as getObject } from "../component-provider/index-D8NF18a1.js";
9
- import { i as isPlainObject, t as toPath, g as get, s as set, o as omit, c as cloneDeep } from "../vendor/utils/lodash-es-p6jau26B.js";
7
+ import { defineComponent, provide, inject, useSlots, watchEffect, createBlock, openBlock, unref, mergeProps, withCtx, createVNode, renderSlot, computed, toValue, normalizeProps, guardReactiveProps, resolveComponent, createElementBlock, Fragment, renderList, createSlots, ref, useAttrs, createCommentVNode, resolveDynamicComponent, isVNode, createTextVNode, toDisplayString } from "vue";
8
+ import { INJECT_CONFIG } from "../component-provider/index.js";
9
+ import { I as InjectionFormKey, c as camelizeProperties, a as InjectionPathKey, g as getObject, u as useForm$1, b as useFields$1, d as useFormRef$1 } from "../core/index-BrBzu6aj.js";
10
+ import { e } from "../core/index-BrBzu6aj.js";
11
+ import { i as isPlainObject, t as toPath, o as omit, c as cloneDeep } from "../vendor/utils/lodash-es-p6jau26B.js";
10
12
  const _sfc_main$6 = /* @__PURE__ */ defineComponent({
11
13
  ...{ name: "ProForm", inheritAttrs: false },
12
14
  __name: "index",
@@ -15,9 +17,8 @@ const _sfc_main$6 = /* @__PURE__ */ defineComponent({
15
17
  form: { default: () => ({}) }
16
18
  },
17
19
  setup(__props) {
18
- const props = __props;
19
- provide(InjectionFormKey, props.form);
20
- const { formData, fields, setFormRef } = props.form;
20
+ provide(InjectionFormKey, __props.form);
21
+ const { formData, fields, setFormRef } = __props.form;
21
22
  const config = INJECT_CONFIG["pro-form"];
22
23
  const { grid: _injectGrid, ...injectAttrs } = inject(
23
24
  config.injectionKey,
@@ -70,8 +71,6 @@ const COMPONENT_MAP = /* @__PURE__ */ new Map([
70
71
  ["transfer", Transfer]
71
72
  ]);
72
73
  const TeleportComponentNamePrefix = "TeleportComponent_";
73
- const InjectionFormKey = Symbol("form");
74
- const InjectionPathKey = Symbol("path");
75
74
  const _sfc_main$5 = /* @__PURE__ */ defineComponent({
76
75
  __name: "index",
77
76
  props: {
@@ -153,27 +152,24 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
153
152
  ...{ name: "BaseFormItem", inheritAttrs: false },
154
153
  __name: "index",
155
154
  props: {
156
- grid: { type: [Boolean, Object], default: void 0 },
155
+ grid: { type: [Boolean, Object], default: () => void 0 },
157
156
  fields: { default: () => [] },
158
- disabled: { type: Boolean, default: void 0 }
157
+ disabled: { type: Boolean, default: () => void 0 }
159
158
  },
160
159
  setup(__props) {
161
- const props = __props;
162
- const validFields = computed(
163
- () => {
164
- var _a, _b;
165
- return (_b = (_a = props.fields).filter) == null ? void 0 : _b.call(_a, (field) => !field.hidden);
166
- }
167
- );
168
- useProviderDisabled(computed(() => props.disabled));
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
+ useProviderDisabled(computed(() => __props.disabled));
169
165
  const config = INJECT_CONFIG["pro-form"];
170
166
  const { grid: injectGrid } = inject(config.injectionKey, config.default);
171
167
  const enableGrid = computed(() => {
172
- if (props.grid !== void 0) return !!props.grid;
168
+ if (__props.grid !== void 0) return !!__props.grid;
173
169
  return !!injectGrid;
174
170
  });
175
171
  const computedGridProps = computed(() => {
176
- return enableGrid.value ? { ...getObject(injectGrid), ...getObject(props.grid) } : {};
172
+ return enableGrid.value ? { ...getObject(injectGrid), ...getObject(__props.grid) } : {};
177
173
  });
178
174
  const formItemRefs = [];
179
175
  const componentRefs = [];
@@ -279,220 +275,7 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
279
275
  };
280
276
  }
281
277
  });
282
- const useFields = (initFields) => {
283
- const fields = ref([]);
284
- fields.value = initFields || [];
285
- const _map = /* @__PURE__ */ new Map();
286
- const cacheMatch = (pathStr, updater) => {
287
- var _a;
288
- const fieldPath = _map.get(pathStr) || [];
289
- if (fieldPath.length === 0) return false;
290
- const fieldIndex = fieldPath[fieldPath.length - 1];
291
- const parentField = fieldPath.length === 1 ? fields.value : get(fields.value, fieldPath.slice(0, -2));
292
- const field = (_a = parentField == null ? void 0 : parentField.fields) == null ? void 0 : _a[fieldIndex];
293
- const _path = toPath((field == null ? void 0 : field.name) ?? (field == null ? void 0 : field.path)).join(".");
294
- if (_path === pathStr) {
295
- updater({ field, fieldIndex, parentField });
296
- return true;
297
- }
298
- return false;
299
- };
300
- const updaterMatch = (path, updater, options = {}) => {
301
- if (!path) return;
302
- const pathStr = typeof path === "function" ? "" : toPath(path).join(".");
303
- const { all = typeof path === "function" } = options;
304
- if (pathStr && _map.has(pathStr) && !all) {
305
- const bool = cacheMatch(pathStr, updater);
306
- if (bool) return;
307
- }
308
- const queue = fields.value.map((field, i) => ({
309
- field,
310
- fieldPath: [i],
311
- parentField: { fields: fields.value }
312
- }));
313
- while (queue.length) {
314
- const { field, fieldPath, parentField } = queue.shift();
315
- let matched = false;
316
- const _path = toPath(field.name ?? field.path).join(".");
317
- if (_path) _map.set(_path, fieldPath);
318
- if (typeof path === "function") {
319
- matched = path(field);
320
- } else if (_path) {
321
- matched = pathStr === _path;
322
- }
323
- if (matched) {
324
- const fieldIndex = fieldPath[fieldPath.length - 1];
325
- updater({ field, fieldIndex, parentField });
326
- if (!all) return;
327
- }
328
- if (Array.isArray(field.fields)) {
329
- field.fields.forEach((f, i) => {
330
- queue.push({
331
- field: f,
332
- fieldPath: [...fieldPath, "fields", i],
333
- parentField: field
334
- });
335
- });
336
- }
337
- }
338
- };
339
- function getField(path, options) {
340
- if (!path) return void 0;
341
- const res = [];
342
- updaterMatch(
343
- path,
344
- ({ field }) => {
345
- res.push(field);
346
- },
347
- options
348
- );
349
- return (options == null ? void 0 : options.all) ? res : res[0];
350
- }
351
- function setField(path, field, options) {
352
- if (!path || !field) return;
353
- const { updateType = "merge", ...rest } = options || {};
354
- updaterMatch(
355
- path,
356
- ({ field: preField, fieldIndex, parentField }) => {
357
- let value = field;
358
- if (typeof field === "function") {
359
- value = field(preField);
360
- }
361
- if (!value) return;
362
- if (updateType === "rewrite") {
363
- parentField.fields[fieldIndex] = value;
364
- } else {
365
- Object.assign(preField, value);
366
- }
367
- },
368
- rest
369
- );
370
- }
371
- function deleteField(path, options) {
372
- if (!path) return;
373
- updaterMatch(
374
- path,
375
- ({ fieldIndex, parentField }) => {
376
- parentField.fields.splice(fieldIndex, 1);
377
- },
378
- options
379
- );
380
- }
381
- function addFields(path, newFields, options, placement) {
382
- if (newFields.length === 0) return;
383
- if (path) {
384
- updaterMatch(
385
- path,
386
- ({ fieldIndex, parentField }) => {
387
- const index = placement === "after" ? fieldIndex + 1 : fieldIndex;
388
- parentField.fields.splice(index, 0, ...newFields);
389
- },
390
- options
391
- );
392
- } else if (placement === "after") {
393
- fields.value.push(...newFields);
394
- } else {
395
- fields.value.unshift(...newFields);
396
- }
397
- }
398
- function appendField(path, field, options) {
399
- const newFields = Array.isArray(field) ? field : [field];
400
- addFields(path, newFields, options, "after");
401
- }
402
- function prependField(path, field, options) {
403
- const newFields = Array.isArray(field) ? field : [field];
404
- addFields(path, newFields, options, "before");
405
- }
406
- function getParentField(path, options) {
407
- if (!path) return void 0;
408
- const res = [];
409
- updaterMatch(
410
- path,
411
- ({ parentField }) => {
412
- res.push(parentField);
413
- },
414
- options
415
- );
416
- return (options == null ? void 0 : options.all) ? res : res[0];
417
- }
418
- return {
419
- fields,
420
- getField,
421
- setField,
422
- deleteField,
423
- appendField,
424
- prependField,
425
- getParentField
426
- };
427
- };
428
- const InjectionFormDataKey = Symbol("form-data");
429
- const useFormData = (initFormData) => {
430
- if (!initFormData) {
431
- const injectFormDataStore = inject(InjectionFormDataKey, void 0);
432
- if (injectFormDataStore) return injectFormDataStore;
433
- }
434
- const formData = reactive(initFormData ?? {});
435
- function getFormData(path) {
436
- if (!path) return void 0;
437
- return get(formData, path);
438
- }
439
- function setFormData(...args) {
440
- let path;
441
- let value;
442
- if (args.length >= 2) {
443
- [path, value] = args;
444
- if (!path) return;
445
- } else {
446
- [value] = args;
447
- }
448
- if (path) {
449
- if (typeof value === "function") {
450
- const preValue = getFormData(path);
451
- value = value(preValue);
452
- }
453
- set(formData, path, value);
454
- } else {
455
- if (typeof value === "function") {
456
- const preValue = formData;
457
- value = value(preValue);
458
- }
459
- if (!isPlainObject(value)) return;
460
- Object.keys(formData).forEach((key) => {
461
- delete formData[key];
462
- });
463
- Object.assign(formData, value);
464
- }
465
- }
466
- const formDataStore = { formData, getFormData, setFormData };
467
- provide(InjectionFormDataKey, formDataStore);
468
- return formDataStore;
469
- };
470
- const useFormRef = () => {
471
- const formRef = ref();
472
- const setFormRef = (inst) => {
473
- formRef.value = inst;
474
- };
475
- return { formRef, setFormRef };
476
- };
477
- function useForm(...args) {
478
- let initFormData = {}, initFields = [], root = true;
479
- if (args.length === 1) {
480
- root = args[0];
481
- } else if (args.length >= 2) {
482
- initFormData = args[0];
483
- initFields = args[1];
484
- root = args[2] ?? root;
485
- }
486
- if (!root) {
487
- const injectForm = inject(InjectionFormKey);
488
- if (injectForm) return injectForm;
489
- }
490
- return {
491
- ...useFormData(initFormData),
492
- ...useFields(initFields),
493
- ...useFormRef()
494
- };
495
- }
278
+ const useForm = useForm$1;
496
279
  const getInitProps = (field) => {
497
280
  const { component } = field;
498
281
  const type = component === "input" ? "" : field.type;
@@ -510,11 +293,10 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
510
293
  ...{ name: "BaseField", inheritAttrs: false },
511
294
  __name: "index",
512
295
  props: {
513
- component: { default: void 0 },
296
+ component: { default: () => void 0 },
514
297
  path: { default: "" }
515
298
  },
516
299
  setup(__props, { expose: __expose }) {
517
- const props = __props;
518
300
  const form = useForm(false);
519
301
  const { getFormData, setFormData } = form;
520
302
  const componentRef = ref();
@@ -524,11 +306,11 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
524
306
  };
525
307
  const attrs = useAttrs();
526
308
  function getOldValue() {
527
- return cloneDeep(getFormData == null ? void 0 : getFormData(props.path));
309
+ return cloneDeep(getFormData == null ? void 0 : getFormData(__props.path));
528
310
  }
529
311
  const value = computed({
530
312
  get() {
531
- let val = getFormData == null ? void 0 : getFormData(props.path);
313
+ let val = getFormData == null ? void 0 : getFormData(__props.path);
532
314
  const { valueFormatter } = groupedAttrs.value;
533
315
  if (typeof valueFormatter === "object" && typeof valueFormatter.get === "function") {
534
316
  val = valueFormatter.get(val);
@@ -545,14 +327,14 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
545
327
  newVal = valueFormatter.set(val, getOldValue());
546
328
  }
547
329
  }
548
- setFormData == null ? void 0 : setFormData(props.path, newVal);
330
+ setFormData == null ? void 0 : setFormData(__props.path, newVal);
549
331
  triggerFormItemChange();
550
332
  }
551
333
  });
552
334
  const parentDisabled = useInjectDisabled();
553
335
  const groupedAttrs = computed(() => {
554
336
  const initProps = getInitProps({
555
- component: props.component,
337
+ component: __props.component,
556
338
  type: attrs.type
557
339
  });
558
340
  const mergedProps = mergeProps(
@@ -574,11 +356,11 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
574
356
  };
575
357
  });
576
358
  const teleportComponent = inject(
577
- `${TeleportComponentNamePrefix}${props.path}`,
359
+ `${TeleportComponentNamePrefix}${__props.path}`,
578
360
  void 0
579
361
  );
580
362
  const is = computed(() => {
581
- return teleportComponent ?? COMPONENT_MAP.get(props.component) ?? props.component;
363
+ return teleportComponent ?? COMPONENT_MAP.get(__props.component) ?? __props.component;
582
364
  });
583
365
  __expose({
584
366
  getComponentRef: () => componentRef.value,
@@ -643,6 +425,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
643
425
  };
644
426
  }
645
427
  });
428
+ const useFields = useFields$1;
429
+ const useFormRef = useFormRef$1;
646
430
  export {
647
431
  _sfc_main$2 as BaseField,
648
432
  _sfc_main$6 as BaseForm,
@@ -658,5 +442,6 @@ export {
658
442
  getInitProps,
659
443
  useFields,
660
444
  useForm,
661
- useFormData
445
+ e as useFormData,
446
+ useFormRef
662
447
  };