@qin-ui/antd-vue-pro 2.0.15 → 2.0.18

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,10 @@ 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 { 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-BeGPcKnM.js";
9
+ import { f } from "../component-provider/index-BeGPcKnM.js";
10
+ import { i as isPlainObject, t as toPath, o as omit, c as cloneDeep } from "../vendor/utils/lodash-es-p6jau26B.js";
10
11
  const _sfc_main$6 = /* @__PURE__ */ defineComponent({
11
12
  ...{ name: "ProForm", inheritAttrs: false },
12
13
  __name: "index",
@@ -15,9 +16,8 @@ const _sfc_main$6 = /* @__PURE__ */ defineComponent({
15
16
  form: { default: () => ({}) }
16
17
  },
17
18
  setup(__props) {
18
- const props = __props;
19
- provide(InjectionFormKey, props.form);
20
- const { formData, fields, setFormRef } = props.form;
19
+ provide(InjectionFormKey, __props.form);
20
+ const { formData, fields, setFormRef } = __props.form;
21
21
  const config = INJECT_CONFIG["pro-form"];
22
22
  const { grid: _injectGrid, ...injectAttrs } = inject(
23
23
  config.injectionKey,
@@ -70,8 +70,6 @@ const COMPONENT_MAP = /* @__PURE__ */ new Map([
70
70
  ["transfer", Transfer]
71
71
  ]);
72
72
  const TeleportComponentNamePrefix = "TeleportComponent_";
73
- const InjectionFormKey = Symbol("form");
74
- const InjectionPathKey = Symbol("path");
75
73
  const _sfc_main$5 = /* @__PURE__ */ defineComponent({
76
74
  __name: "index",
77
75
  props: {
@@ -153,27 +151,24 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
153
151
  ...{ name: "BaseFormItem", inheritAttrs: false },
154
152
  __name: "index",
155
153
  props: {
156
- grid: { type: [Boolean, Object], default: void 0 },
154
+ grid: { type: [Boolean, Object], default: () => void 0 },
157
155
  fields: { default: () => [] },
158
- disabled: { type: Boolean, default: void 0 }
156
+ disabled: { type: Boolean, default: () => void 0 }
159
157
  },
160
158
  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));
159
+ const validFields = computed(() => {
160
+ var _a, _b;
161
+ return (_b = (_a = __props.fields).filter) == null ? void 0 : _b.call(_a, (field) => !field.hidden);
162
+ });
163
+ useProviderDisabled(computed(() => __props.disabled));
169
164
  const config = INJECT_CONFIG["pro-form"];
170
165
  const { grid: injectGrid } = inject(config.injectionKey, config.default);
171
166
  const enableGrid = computed(() => {
172
- if (props.grid !== void 0) return !!props.grid;
167
+ if (__props.grid !== void 0) return !!__props.grid;
173
168
  return !!injectGrid;
174
169
  });
175
170
  const computedGridProps = computed(() => {
176
- return enableGrid.value ? { ...getObject(injectGrid), ...getObject(props.grid) } : {};
171
+ return enableGrid.value ? { ...getObject(injectGrid), ...getObject(__props.grid) } : {};
177
172
  });
178
173
  const formItemRefs = [];
179
174
  const componentRefs = [];
@@ -279,232 +274,15 @@ const _sfc_main$3 = /* @__PURE__ */ defineComponent({
279
274
  };
280
275
  }
281
276
  });
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
- }
496
- const initPropsMap = /* @__PURE__ */ new Map();
277
+ const useForm = useForm$1;
497
278
  const getInitProps = (field) => {
498
279
  const { component } = field;
499
280
  const type = component === "input" ? "" : field.type;
500
281
  if (COMPONENT_MAP.has(component)) {
501
282
  const k = [component, type].filter(Boolean).join(".");
502
- if (initPropsMap.has(k)) {
503
- return initPropsMap.get(k);
504
- } else if (INJECT_CONFIG[k]) {
283
+ if (INJECT_CONFIG[k]) {
505
284
  const config = INJECT_CONFIG[k];
506
285
  const injectProps = inject(config.injectionKey, config.default);
507
- initPropsMap.set(k, injectProps);
508
286
  return injectProps;
509
287
  }
510
288
  }
@@ -514,11 +292,10 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
514
292
  ...{ name: "BaseField", inheritAttrs: false },
515
293
  __name: "index",
516
294
  props: {
517
- component: { default: void 0 },
295
+ component: { default: () => void 0 },
518
296
  path: { default: "" }
519
297
  },
520
298
  setup(__props, { expose: __expose }) {
521
- const props = __props;
522
299
  const form = useForm(false);
523
300
  const { getFormData, setFormData } = form;
524
301
  const componentRef = ref();
@@ -528,11 +305,11 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
528
305
  };
529
306
  const attrs = useAttrs();
530
307
  function getOldValue() {
531
- return cloneDeep(getFormData == null ? void 0 : getFormData(props.path));
308
+ return cloneDeep(getFormData == null ? void 0 : getFormData(__props.path));
532
309
  }
533
310
  const value = computed({
534
311
  get() {
535
- let val = getFormData == null ? void 0 : getFormData(props.path);
312
+ let val = getFormData == null ? void 0 : getFormData(__props.path);
536
313
  const { valueFormatter } = groupedAttrs.value;
537
314
  if (typeof valueFormatter === "object" && typeof valueFormatter.get === "function") {
538
315
  val = valueFormatter.get(val);
@@ -549,14 +326,14 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
549
326
  newVal = valueFormatter.set(val, getOldValue());
550
327
  }
551
328
  }
552
- setFormData == null ? void 0 : setFormData(props.path, newVal);
329
+ setFormData == null ? void 0 : setFormData(__props.path, newVal);
553
330
  triggerFormItemChange();
554
331
  }
555
332
  });
556
333
  const parentDisabled = useInjectDisabled();
557
334
  const groupedAttrs = computed(() => {
558
335
  const initProps = getInitProps({
559
- component: props.component,
336
+ component: __props.component,
560
337
  type: attrs.type
561
338
  });
562
339
  const mergedProps = mergeProps(
@@ -578,11 +355,11 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
578
355
  };
579
356
  });
580
357
  const teleportComponent = inject(
581
- `${TeleportComponentNamePrefix}${props.path}`,
358
+ `${TeleportComponentNamePrefix}${__props.path}`,
582
359
  void 0
583
360
  );
584
361
  const is = computed(() => {
585
- return teleportComponent ?? COMPONENT_MAP.get(props.component) ?? props.component;
362
+ return teleportComponent ?? COMPONENT_MAP.get(__props.component) ?? __props.component;
586
363
  });
587
364
  __expose({
588
365
  getComponentRef: () => componentRef.value,
@@ -647,6 +424,8 @@ const _sfc_main = /* @__PURE__ */ defineComponent({
647
424
  };
648
425
  }
649
426
  });
427
+ const useFields = useFields$1;
428
+ const useFormRef = useFormRef$1;
650
429
  export {
651
430
  _sfc_main$2 as BaseField,
652
431
  _sfc_main$6 as BaseForm,
@@ -662,5 +441,6 @@ export {
662
441
  getInitProps,
663
442
  useFields,
664
443
  useForm,
665
- useFormData
444
+ f as useFormData,
445
+ useFormRef
666
446
  };