@qin-ui/antd-vue-pro 2.4.3 → 2.4.5

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.
Files changed (36) hide show
  1. package/AI-CONTEXT.md +4 -4
  2. package/README.md +4 -3
  3. package/api.json +2 -2
  4. package/es/antd-vue-pro.css +11 -11
  5. package/es/components/component-provider/types/index.d.ts +1 -1
  6. package/es/components/component-provider/types/index.d.ts.map +1 -1
  7. package/es/components/form/components/BaseField/index.vue.d.ts.map +1 -1
  8. package/es/components/form/components/BaseFormItem/index.vue.d.ts.map +1 -1
  9. package/es/components/form/components/ProForm/index.vue.d.ts.map +1 -1
  10. package/es/components/form/hooks/useGroupFieldAttrs.d.ts +1 -1
  11. package/es/components/form/hooks/useGroupFieldAttrs.d.ts.map +1 -1
  12. package/es/components/form/types/index.d.ts +2 -2
  13. package/es/components/form/types/index.d.ts.map +1 -1
  14. package/es/components/table/components/ColumnControl.vue.d.ts.map +1 -1
  15. package/es/components/table/components/ProTable.vue.d.ts.map +1 -1
  16. package/es/components/table/components/SearchForm.vue.d.ts +1 -1
  17. package/es/components/table/components/SearchForm.vue.d.ts.map +1 -1
  18. package/es/components/table/hooks/useTable.d.ts +1 -1
  19. package/es/index.js +321 -260
  20. package/es/index.js.map +1 -1
  21. package/es/shared/core/index.d.ts +1 -2
  22. package/es/shared/core/index.d.ts.map +1 -1
  23. package/package.json +5 -4
  24. package/src/components/component-provider/types/index.ts +1 -1
  25. package/src/components/form/components/BaseField/index.vue +25 -9
  26. package/src/components/form/components/BaseField/utils/index.ts +1 -1
  27. package/src/components/form/components/BaseFormItem/index.vue +63 -8
  28. package/src/components/form/components/ProForm/index.vue +21 -10
  29. package/src/components/form/hooks/useGroupFieldAttrs.ts +9 -17
  30. package/src/components/form/types/index.ts +2 -8
  31. package/src/components/table/components/ColumnControl.vue +5 -3
  32. package/src/components/table/components/ProTable.vue +26 -11
  33. package/src/components/table/components/SearchForm.vue +3 -3
  34. package/src/components/table/hooks/useTable.ts +1 -1
  35. package/src/shared/core/index.ts +1 -2
  36. package/tsconfig.json +23 -0
package/es/index.js CHANGED
@@ -1,12 +1,12 @@
1
1
  import "./antd-vue-pro.css";
2
- import { inject, computed, toValue, mergeProps, defineComponent, resolveComponent, createBlock, openBlock, unref, withCtx, createElementBlock, Fragment, renderList, createVNode, createSlots, toRaw, ref, useAttrs, createCommentVNode, resolveDynamicComponent, renderSlot, normalizeProps, isVNode, createTextVNode, toDisplayString, provide, useSlots, createElementVNode, normalizeStyle, useModel, watch, mergeModels, onMounted, normalizeClass, nextTick } from "vue";
2
+ import { defineComponent, createBlock, renderSlot, openBlock, resolveDynamicComponent, normalizeProps, mergeProps, withCtx, createElementBlock, isVNode, Fragment, createTextVNode, toDisplayString, inject, computed, toValue, ref, useAttrs, createCommentVNode, createSlots, renderList, createVNode, resolveComponent, unref, toRaw, provide, useSlots, shallowRef, onUpdated, triggerRef, createElementVNode, normalizeStyle, useModel, watch, mergeModels, onMounted, normalizeClass, nextTick } from "vue";
3
3
  import { Transfer, TreeSelect, Slider, Switch, RadioGroup, CheckboxGroup, TimePicker, RangePicker, DatePicker, Cascader, Select, InputNumber, InputPassword, InputSearch, Textarea, Input, Row, Col, FormItem, Form, Space, Button, theme, Dropdown, Menu, MenuItem, Checkbox, MenuDivider, Table } from "ant-design-vue";
4
- import { isPlainObject, getObject, toPath, useForm as useForm$1, resolveLocaleName, zhTW, enUS, zhCN, format, cloneDeep, InjectionFormSlotsKey, createFormProxy, InjectionFormKey, camelizeProperties, useFields as useFields$1, useFormRef as useFormRef$1, useSearchFormExpand, pick, isPromise, useTable as useTable$1 } from "@qin-ui/pro-components-core";
4
+ import { useForm as useForm$1, resolveLocaleName, zhTW, enUS, zhCN, format, cloneDeep, InjectionFormSlotsKey, isPlainObject, getObject, toPath, createFormProxy, InjectionFormKey, camelizeProperties, useFields as useFields$1, useFormRef as useFormRef$1, useSearchFormExpand, pick, isPromise, useTable as useTable$1 } from "@qin-ui/pro-components-core";
5
5
  import { enUS as enUS2, useFormData, zhCN as zhCN2, zhTW as zhTW2 } from "@qin-ui/pro-components-core";
6
- import { colProps } from "ant-design-vue/es/grid/Col";
7
- import { formItemProps, useInjectFormItemContext } from "ant-design-vue/es/form";
8
6
  import { useConfigContextInject } from "ant-design-vue/es/config-provider/context";
9
- import { useProviderDisabled, useInjectDisabled } from "ant-design-vue/es/config-provider/DisabledContext";
7
+ import { useInjectFormItemContext, formItemProps } from "ant-design-vue/es/form";
8
+ import { useInjectDisabled, useProviderDisabled } from "ant-design-vue/es/config-provider/DisabledContext";
9
+ import { colProps } from "ant-design-vue/es/grid/Col";
10
10
  import { tableProps } from "ant-design-vue/es/table";
11
11
  const getPopupContainer = (triggerNode) => {
12
12
  var _a;
@@ -148,6 +148,39 @@ const ensureInjectConfig = (key) => {
148
148
  DYNAMIC_INJECT_CONFIG[key] = created;
149
149
  return created;
150
150
  };
151
+ const _sfc_main$e = /* @__PURE__ */ defineComponent({
152
+ ...{ name: "ContainerFragment", inheritAttrs: false },
153
+ __name: "index",
154
+ props: {
155
+ component: { type: [Object, Function], default: void 0 }
156
+ },
157
+ setup(__props) {
158
+ const props = __props;
159
+ return (_ctx, _cache) => {
160
+ return props.component ? (openBlock(), createBlock(resolveDynamicComponent(props.component), normalizeProps(mergeProps({ key: 0 }, _ctx.$attrs)), {
161
+ default: withCtx(() => [
162
+ renderSlot(_ctx.$slots, "default")
163
+ ]),
164
+ _: 3
165
+ }, 16)) : renderSlot(_ctx.$slots, "default", { key: 1 });
166
+ };
167
+ }
168
+ });
169
+ const _sfc_main$d = /* @__PURE__ */ defineComponent({
170
+ ...{ name: "SlotComponent", inheritAttrs: false },
171
+ __name: "index",
172
+ props: {
173
+ component: { type: [Object, Function, String, Number, Boolean, null], default: void 0 }
174
+ },
175
+ setup(__props) {
176
+ const props = __props;
177
+ return (_ctx, _cache) => {
178
+ 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 }, [
179
+ createTextVNode(toDisplayString(props.component), 1)
180
+ ], 64));
181
+ };
182
+ }
183
+ });
151
184
  const FORM_ITEM_SLOT_KEYS = [
152
185
  "label",
153
186
  "extra",
@@ -172,12 +205,194 @@ const componentMap = {
172
205
  "tree-select": TreeSelect,
173
206
  "transfer": Transfer
174
207
  };
208
+ function useForm(...args) {
209
+ return useForm$1(...args);
210
+ }
211
+ const PLACEHOLDER_KEYS = {
212
+ input: "input.placeholder",
213
+ textarea: "input.placeholder",
214
+ "input-password": "input.placeholder",
215
+ "input-number": "input.placeholder",
216
+ select: "select.placeholder",
217
+ cascader: "select.placeholder"
218
+ };
219
+ const getPlaceholderProps = (key, injectProps, t) => {
220
+ const placeholderKey = PLACEHOLDER_KEYS[key];
221
+ if (!placeholderKey || injectProps.placeholder !== void 0) return {};
222
+ return { placeholder: t(placeholderKey) };
223
+ };
224
+ const getInitProps = (field, injectProps = {}, t) => {
225
+ const { component } = field;
226
+ const picker = component === "date-picker" ? "" : field.picker;
227
+ if (typeof component === "string") {
228
+ const k = [component, picker].filter(Boolean).join(".");
229
+ return { ...injectProps, ...getPlaceholderProps(k, injectProps, t) };
230
+ }
231
+ return {};
232
+ };
233
+ const warnedUnknownComponents = /* @__PURE__ */ new Set();
234
+ function warnUnknownComponent(name) {
235
+ if (warnedUnknownComponents.has(name)) return;
236
+ warnedUnknownComponents.add(name);
237
+ console.warn(
238
+ `[pro-components] 未识别的组件类型 "${name}",已降级为原生元素渲染。如为自定义组件请在 componentMap 或 ProComponentProvider 中注册。`
239
+ );
240
+ }
241
+ const LOCALE_INJECT_KEY = Symbol("pro-locale");
242
+ const useLocale = () => {
243
+ const config = useConfigContextInject();
244
+ const override = inject(LOCALE_INJECT_KEY, void 0);
245
+ const lang = computed(
246
+ () => {
247
+ var _a, _b;
248
+ return resolveLocaleName((_b = (_a = config.locale) == null ? void 0 : _a.value) == null ? void 0 : _b.locale);
249
+ }
250
+ );
251
+ const pack = computed(
252
+ () => lang.value === "zh-TW" ? zhTW : lang.value === "en-US" ? enUS : zhCN
253
+ );
254
+ const t = (key, params) => {
255
+ const overrides = toValue(override);
256
+ const text = (overrides == null ? void 0 : overrides[key]) ?? pack.value[key] ?? key;
257
+ return format(text, params);
258
+ };
259
+ return { t, lang };
260
+ };
261
+ const _sfc_main$c = /* @__PURE__ */ defineComponent({
262
+ ...{ name: "BaseField", inheritAttrs: false },
263
+ __name: "index",
264
+ props: {
265
+ component: { default: void 0 },
266
+ path: { default: "" }
267
+ },
268
+ setup(__props, { expose: __expose }) {
269
+ const cloneDeepIfObject = (val) => (
270
+ // 原始值直接传递,引用值克隆快照
271
+ typeof val === "object" && val !== null ? cloneDeep(val) : val
272
+ );
273
+ const props = __props;
274
+ const { t } = useLocale();
275
+ const form = useForm(false);
276
+ const componentRef = ref();
277
+ const formItemContext = useInjectFormItemContext();
278
+ const triggerFormItemChange = () => {
279
+ formItemContext.onFieldChange();
280
+ };
281
+ const attrs = useAttrs();
282
+ const pickerVal = attrs.picker;
283
+ const injectConfigKey = typeof props.component === "string" ? [props.component, pickerVal].filter(Boolean).join(".") : "";
284
+ const componentInjectConfig = injectConfigKey ? getInjectConfig(injectConfigKey) : void 0;
285
+ const rawInjectComponentProps = componentInjectConfig ? inject(componentInjectConfig.injectionKey, componentInjectConfig.default) : void 0;
286
+ const value = computed({
287
+ get() {
288
+ var _a;
289
+ let val = (_a = form.getFormData) == null ? void 0 : _a.call(form, props.path);
290
+ const { valueFormatter } = groupedAttrs.value;
291
+ if (typeof valueFormatter === "object" && typeof valueFormatter.get === "function") {
292
+ val = valueFormatter.get(val);
293
+ }
294
+ return val;
295
+ },
296
+ set(val) {
297
+ var _a, _b;
298
+ let newVal = val;
299
+ const { valueFormatter } = groupedAttrs.value;
300
+ const setFormatter = typeof valueFormatter === "function" ? valueFormatter : typeof valueFormatter === "object" && typeof (valueFormatter == null ? void 0 : valueFormatter.set) === "function" ? valueFormatter.set : void 0;
301
+ if (setFormatter) {
302
+ const oldVal = setFormatter.length > 1 ? cloneDeepIfObject((_a = form.getFormData) == null ? void 0 : _a.call(form, props.path)) : void 0;
303
+ newVal = setFormatter(val, oldVal);
304
+ }
305
+ (_b = form.setFormData) == null ? void 0 : _b.call(form, props.path, newVal);
306
+ triggerFormItemChange();
307
+ const { onUpdateValue } = groupedAttrs.value;
308
+ if (typeof onUpdateValue === "function") {
309
+ onUpdateValue(val);
310
+ } else if (Array.isArray(onUpdateValue)) {
311
+ onUpdateValue.forEach((listener) => listener(val));
312
+ }
313
+ }
314
+ });
315
+ const parentDisabled = useInjectDisabled();
316
+ const groupedAttrs = computed(() => {
317
+ const currentInjectProps = toValue(rawInjectComponentProps) || {};
318
+ const initProps = getInitProps(
319
+ { component: props.component, picker: attrs.picker },
320
+ currentInjectProps,
321
+ t
322
+ );
323
+ const effectiveModelProp = attrs.modelProp ?? initProps.modelProp ?? "value";
324
+ const mergedProps = mergeProps(
325
+ initProps,
326
+ attrs,
327
+ { class: attrs.componentClass, style: attrs.componentStyle },
328
+ { disabled: attrs.disabled ?? parentDisabled.value ?? initProps.disabled },
329
+ { modelProp: effectiveModelProp }
330
+ );
331
+ const { valueFormatter, modelProp, slots, componentClass, componentStyle, componentContainer, [effectiveModelProp]: _modelVal, [`onUpdate:${effectiveModelProp}`]: onUpdateValue, ...bindAttrs } = mergedProps;
332
+ return {
333
+ attrs: bindAttrs,
334
+ slots,
335
+ componentContainer,
336
+ modelProp,
337
+ valueFormatter,
338
+ onUpdateValue
339
+ };
340
+ });
341
+ const injectedFormSlots = inject(InjectionFormSlotsKey, void 0);
342
+ const customComponents = inject(INJECT_COMPONENTS, {});
343
+ const is = computed(() => {
344
+ var _a, _b;
345
+ const teleportSlot = props.path && ((_a = injectedFormSlots == null ? void 0 : injectedFormSlots.value) == null ? void 0 : _a[props.path]);
346
+ if (teleportSlot) return teleportSlot;
347
+ if (typeof props.component === "string") {
348
+ const resolved = ((_b = toValue(customComponents)) == null ? void 0 : _b[props.component]) || componentMap[props.component];
349
+ if (resolved) return resolved;
350
+ warnUnknownComponent(props.component);
351
+ return props.component;
352
+ }
353
+ return props.component;
354
+ });
355
+ __expose({
356
+ getComponentRef: () => componentRef.value,
357
+ getComponentComputedProps: () => groupedAttrs.value.attrs
358
+ });
359
+ return (_ctx, _cache) => {
360
+ return openBlock(), createBlock(_sfc_main$e, {
361
+ component: groupedAttrs.value.componentContainer,
362
+ path: props.path
363
+ }, {
364
+ default: withCtx(() => [
365
+ is.value ? (openBlock(), createBlock(resolveDynamicComponent(is.value), mergeProps({ key: 0 }, groupedAttrs.value.attrs, {
366
+ ref_key: "componentRef",
367
+ ref: componentRef,
368
+ [`${groupedAttrs.value.modelProp}`]: value.value,
369
+ [`onUpdate:${groupedAttrs.value.modelProp}`]: _cache[0] || (_cache[0] = ($event) => value.value = $event),
370
+ path: props.path
371
+ }), createSlots({ _: 2 }, [
372
+ renderList(groupedAttrs.value.slots, (slot, name) => {
373
+ return {
374
+ name,
375
+ fn: withCtx((scoped) => [
376
+ createVNode(_sfc_main$d, mergeProps({
377
+ path: props.path
378
+ }, scoped, { component: slot }), null, 16, ["path", "component"])
379
+ ])
380
+ };
381
+ })
382
+ ]), 1040, ["path"])) : createCommentVNode("", true)
383
+ ]),
384
+ _: 1
385
+ }, 8, ["component", "path"]);
386
+ };
387
+ }
388
+ });
175
389
  const formItemPropKeys = Object.keys(formItemProps()).concat([
176
390
  "formItemContainer"
177
391
  ]);
178
392
  const gridItemPropKeys = Object.keys(colProps());
179
393
  const gridItemPropKeySet = new Set(gridItemPropKeys);
180
394
  const formItemPropKeySet = new Set(formItemPropKeys);
395
+ const formItemSlotKeySet = new Set(FORM_ITEM_SLOT_KEYS);
181
396
  function useGroupFieldAttrs(validFields) {
182
397
  const config = INJECT_CONFIG["pro-form-item"];
183
398
  const injectFormItemProps = inject(config.injectionKey, config.default);
@@ -190,21 +405,9 @@ function useGroupFieldAttrs(validFields) {
190
405
  const formItemSlots = {};
191
406
  if (isPlainObject(field)) {
192
407
  const { path, name, fields, formItemClass, formItemStyle, hidden, span, getFormItemRef, getComponentRef, getFormItemComputedProps, getComponentComputedProps, slots = {}, formItemDataAttrs = {}, componentDataAttrs = {}, extraProps, formItemContainer, ...rest } = field;
193
- const {
194
- class: injectClassName,
195
- style: injectStyle,
196
- span: injectSpan,
197
- xs,
198
- sm,
199
- md,
200
- lg,
201
- xl,
202
- xxl,
203
- formItemContainer: injectFormItemContainer,
204
- ...injectRest
205
- } = rawInject;
408
+ const { class: injectClassName, style: injectStyle, span: injectSpan, xs, sm, md, lg, xl, xxl, formItemContainer: injectFormItemContainer, ...injectRest } = rawInject;
206
409
  const initGridItemProps = span || span === 0 ? { span } : { xs, sm, md, lg, xl, xxl, span: injectSpan };
207
- gridItemProps2 = fields ? { span: span ?? 24 } : initGridItemProps;
410
+ gridItemProps2 = fields ? { ...initGridItemProps, span: span ?? 24 } : initGridItemProps;
208
411
  const container = formItemContainer ?? injectFormItemContainer;
209
412
  formItemProps2 = mergeProps(
210
413
  injectRest,
@@ -223,7 +426,7 @@ function useGroupFieldAttrs(validFields) {
223
426
  });
224
427
  Object.assign(componentProps, componentDataAttrs);
225
428
  Object.keys(slots).forEach((k) => {
226
- if (FORM_ITEM_SLOT_KEYS.includes(k)) {
429
+ if (formItemSlotKeySet.has(k)) {
227
430
  formItemSlots[k] = slots[k];
228
431
  } else {
229
432
  componentProps.slots[k] = slots[k];
@@ -252,7 +455,7 @@ function useGroupFieldAttrs(validFields) {
252
455
  });
253
456
  });
254
457
  }
255
- const _sfc_main$e = /* @__PURE__ */ defineComponent({
458
+ const _sfc_main$b = /* @__PURE__ */ defineComponent({
256
459
  ...{ name: "BaseFormItem", inheritAttrs: false },
257
460
  __name: "index",
258
461
  props: {
@@ -261,6 +464,17 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
261
464
  disabled: { type: Boolean, default: void 0 }
262
465
  },
263
466
  setup(__props) {
467
+ let fieldKeySeed = 0;
468
+ const fieldKeyMap = /* @__PURE__ */ new WeakMap();
469
+ const getFieldKey = (field) => {
470
+ const raw = toRaw(field);
471
+ let key = fieldKeyMap.get(raw);
472
+ if (key === void 0) {
473
+ key = ++fieldKeySeed;
474
+ fieldKeyMap.set(raw, key);
475
+ }
476
+ return key;
477
+ };
264
478
  const props = __props;
265
479
  const validFields = computed(
266
480
  () => (
@@ -284,15 +498,39 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
284
498
  });
285
499
  const formItemInstanceMap = /* @__PURE__ */ new WeakMap();
286
500
  const componentInstanceMap = /* @__PURE__ */ new WeakMap();
501
+ const warnedFrozenFields = /* @__PURE__ */ new WeakSet();
502
+ const defineFieldAccessors = (raw, accessors) => {
503
+ try {
504
+ for (const [key, getter] of Object.entries(accessors)) {
505
+ Object.defineProperty(raw, key, {
506
+ value: getter,
507
+ enumerable: false,
508
+ configurable: true,
509
+ writable: true
510
+ });
511
+ }
512
+ } catch {
513
+ if (!warnedFrozenFields.has(raw)) {
514
+ warnedFrozenFields.add(raw);
515
+ console.warn(
516
+ "[pro-components] 字段配置对象不可写(如被 Object.freeze),getFormItemRef / getComponentRef 等实例访问器挂载失败。"
517
+ );
518
+ }
519
+ }
520
+ };
287
521
  const setFormItemRef = (field, el, formItemProps2) => {
288
522
  if (!field || typeof field !== "object") return;
289
523
  const raw = toRaw(field);
290
524
  if (el) {
291
525
  formItemInstanceMap.set(raw, el);
292
- raw.getFormItemRef = () => formItemInstanceMap.get(raw);
293
- raw.getFormItemComputedProps = () => formItemProps2;
526
+ defineFieldAccessors(raw, {
527
+ getFormItemRef: () => formItemInstanceMap.get(raw),
528
+ getFormItemComputedProps: () => formItemProps2
529
+ });
294
530
  } else {
295
531
  formItemInstanceMap.delete(raw);
532
+ delete raw.getFormItemRef;
533
+ delete raw.getFormItemComputedProps;
296
534
  }
297
535
  };
298
536
  const setComponentRef = (field, el) => {
@@ -300,32 +538,36 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
300
538
  const raw = toRaw(field);
301
539
  if (el) {
302
540
  componentInstanceMap.set(raw, el);
303
- raw.getComponentRef = () => {
304
- var _a;
305
- return (_a = componentInstanceMap.get(raw)) == null ? void 0 : _a.getComponentRef();
306
- };
307
- raw.getComponentComputedProps = () => {
308
- var _a;
309
- return (_a = componentInstanceMap.get(raw)) == null ? void 0 : _a.getComponentComputedProps();
310
- };
541
+ defineFieldAccessors(raw, {
542
+ getComponentRef: () => {
543
+ var _a;
544
+ return (_a = componentInstanceMap.get(raw)) == null ? void 0 : _a.getComponentRef();
545
+ },
546
+ getComponentComputedProps: () => {
547
+ var _a;
548
+ return (_a = componentInstanceMap.get(raw)) == null ? void 0 : _a.getComponentComputedProps();
549
+ }
550
+ });
311
551
  } else {
312
552
  componentInstanceMap.delete(raw);
553
+ delete raw.getComponentRef;
554
+ delete raw.getComponentComputedProps;
313
555
  }
314
556
  };
315
557
  const groupedFields = useGroupFieldAttrs(validFields);
316
558
  return (_ctx, _cache) => {
317
559
  const _component_BaseFormItem = resolveComponent("BaseFormItem");
318
- return openBlock(), createBlock(unref(_sfc_main$c), mergeProps({
560
+ return openBlock(), createBlock(_sfc_main$e, mergeProps({
319
561
  component: enableGrid.value ? unref(Row) : void 0
320
562
  }, computedGridProps.value), {
321
563
  default: withCtx(() => [
322
- (openBlock(true), createElementBlock(Fragment, null, renderList(unref(groupedFields), (item, index2) => {
323
- return openBlock(), createBlock(unref(_sfc_main$c), mergeProps({
324
- key: item.path || index2,
564
+ (openBlock(true), createElementBlock(Fragment, null, renderList(unref(groupedFields), (item) => {
565
+ return openBlock(), createBlock(_sfc_main$e, mergeProps({
566
+ key: item.path || getFieldKey(item.rawField),
325
567
  component: enableGrid.value ? unref(Col) : void 0
326
568
  }, { ref_for: true }, item.gridItemProps), {
327
569
  default: withCtx(() => [
328
- createVNode(unref(_sfc_main$c), {
570
+ createVNode(_sfc_main$e, {
329
571
  component: item.formItemContainer,
330
572
  path: item.path
331
573
  }, {
@@ -342,7 +584,7 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
342
584
  grid: item.rawField.grid ?? props.grid,
343
585
  fields: item.rawField.fields,
344
586
  disabled: toValue(item.rawField.disabled)
345
- }, null, 8, ["grid", "fields", "disabled"])) : (openBlock(), createBlock(unref(_sfc_main$d), mergeProps({
587
+ }, null, 8, ["grid", "fields", "disabled"])) : (openBlock(), createBlock(_sfc_main$c, mergeProps({
346
588
  key: 1,
347
589
  ref_for: true,
348
590
  ref: (el) => setComponentRef(item.rawField, el)
@@ -356,7 +598,7 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
356
598
  return {
357
599
  name,
358
600
  fn: withCtx((scoped) => [
359
- createVNode(unref(_sfc_main$b), mergeProps({
601
+ createVNode(_sfc_main$d, mergeProps({
360
602
  path: item.path,
361
603
  component: slot
362
604
  }, { ref_for: true }, scoped), null, 16, ["path", "component"])
@@ -377,209 +619,6 @@ const _sfc_main$e = /* @__PURE__ */ defineComponent({
377
619
  };
378
620
  }
379
621
  });
380
- function useForm(...args) {
381
- return useForm$1(...args);
382
- }
383
- const PLACEHOLDER_KEYS = {
384
- input: "input.placeholder",
385
- textarea: "input.placeholder",
386
- "input-password": "input.placeholder",
387
- "input-number": "input.placeholder",
388
- select: "select.placeholder",
389
- cascader: "select.placeholder"
390
- };
391
- const getPlaceholderProps = (key, injectProps, t) => {
392
- const placeholderKey = PLACEHOLDER_KEYS[key];
393
- if (!placeholderKey || injectProps.placeholder !== void 0) return {};
394
- return { placeholder: t(placeholderKey) };
395
- };
396
- const getInitProps = (field, injectProps = {}, t) => {
397
- const { component } = field;
398
- const picker = component === "date-picker" ? "" : field.picker;
399
- if (typeof component === "string") {
400
- const k = [component, picker].filter(Boolean).join(".");
401
- return { ...injectProps, ...getPlaceholderProps(k, injectProps, t) };
402
- }
403
- return {};
404
- };
405
- const warnedUnknownComponents = /* @__PURE__ */ new Set();
406
- function warnUnknownComponent(name) {
407
- if (warnedUnknownComponents.has(name)) return;
408
- warnedUnknownComponents.add(name);
409
- console.warn(
410
- `[pro-components] 未识别的组件类型 "${name}",已降级为原生元素渲染。如为自定义组件请在 componentMap 或 ProComponentProvider 中注册。`
411
- );
412
- }
413
- const LOCALE_INJECT_KEY = Symbol("pro-locale");
414
- const useLocale = () => {
415
- const config = useConfigContextInject();
416
- const override = inject(LOCALE_INJECT_KEY, void 0);
417
- const lang = computed(
418
- () => {
419
- var _a, _b;
420
- return resolveLocaleName((_b = (_a = config.locale) == null ? void 0 : _a.value) == null ? void 0 : _b.locale);
421
- }
422
- );
423
- const pack = computed(
424
- () => lang.value === "zh-TW" ? zhTW : lang.value === "en-US" ? enUS : zhCN
425
- );
426
- const t = (key, params) => {
427
- const overrides = toValue(override);
428
- const text = (overrides == null ? void 0 : overrides[key]) ?? pack.value[key] ?? key;
429
- return format(text, params);
430
- };
431
- return { t, lang };
432
- };
433
- const _sfc_main$d = /* @__PURE__ */ defineComponent({
434
- ...{ name: "BaseField", inheritAttrs: false },
435
- __name: "index",
436
- props: {
437
- component: { default: void 0 },
438
- path: { default: "" }
439
- },
440
- setup(__props, { expose: __expose }) {
441
- const props = __props;
442
- const { t } = useLocale();
443
- const form = useForm(false);
444
- const componentRef = ref();
445
- const formItemContext = useInjectFormItemContext();
446
- const triggerFormItemChange = () => {
447
- formItemContext.onFieldChange();
448
- };
449
- const attrs = useAttrs();
450
- const pickerVal = attrs.picker;
451
- const injectConfigKey = typeof props.component === "string" ? [props.component, pickerVal].filter(Boolean).join(".") : "";
452
- const componentInjectConfig = injectConfigKey ? getInjectConfig(injectConfigKey) : void 0;
453
- const rawInjectComponentProps = componentInjectConfig ? inject(componentInjectConfig.injectionKey, componentInjectConfig.default) : void 0;
454
- const value = computed({
455
- get() {
456
- var _a;
457
- let val = (_a = form.getFormData) == null ? void 0 : _a.call(form, props.path);
458
- const { valueFormatter } = groupedAttrs.value;
459
- if (typeof valueFormatter === "object" && typeof valueFormatter.get === "function") {
460
- val = valueFormatter.get(val);
461
- }
462
- return val;
463
- },
464
- set(val) {
465
- var _a, _b;
466
- let newVal = val;
467
- const { valueFormatter } = groupedAttrs.value;
468
- const setFormatter = typeof valueFormatter === "function" ? valueFormatter : typeof valueFormatter === "object" && typeof (valueFormatter == null ? void 0 : valueFormatter.set) === "function" ? valueFormatter.set : void 0;
469
- if (setFormatter) {
470
- const oldVal = setFormatter.length > 1 ? cloneDeep((_a = form.getFormData) == null ? void 0 : _a.call(form, props.path)) : void 0;
471
- newVal = setFormatter(val, oldVal);
472
- }
473
- (_b = form.setFormData) == null ? void 0 : _b.call(form, props.path, newVal);
474
- triggerFormItemChange();
475
- }
476
- });
477
- const parentDisabled = useInjectDisabled();
478
- const groupedAttrs = computed(() => {
479
- const currentInjectProps = toValue(rawInjectComponentProps) || {};
480
- const initProps = getInitProps(
481
- { component: props.component, picker: attrs.picker },
482
- currentInjectProps,
483
- t
484
- );
485
- const effectiveModelProp = attrs.modelProp ?? initProps.modelProp ?? "value";
486
- const mergedProps = mergeProps(
487
- initProps,
488
- attrs,
489
- { class: attrs.componentClass, style: attrs.componentStyle },
490
- { disabled: attrs.disabled ?? parentDisabled.value ?? initProps.disabled },
491
- { modelProp: effectiveModelProp }
492
- );
493
- const { valueFormatter, modelProp, slots, componentClass, componentStyle, componentContainer, [effectiveModelProp]: _modelVal, [`onUpdate:${effectiveModelProp}`]: _onUpdateModelVal, ...bindAttrs } = mergedProps;
494
- return {
495
- attrs: bindAttrs,
496
- slots,
497
- componentContainer,
498
- modelProp,
499
- valueFormatter
500
- };
501
- });
502
- const formSlots = inject(InjectionFormSlotsKey, void 0);
503
- const customComponents = inject(INJECT_COMPONENTS, {});
504
- const is = computed(() => {
505
- var _a;
506
- const teleportSlot = props.path && (formSlots == null ? void 0 : formSlots[props.path]);
507
- if (teleportSlot) return teleportSlot;
508
- if (typeof props.component === "string") {
509
- const resolved = ((_a = toValue(customComponents)) == null ? void 0 : _a[props.component]) || componentMap[props.component];
510
- if (resolved) return resolved;
511
- warnUnknownComponent(props.component);
512
- return props.component;
513
- }
514
- return props.component;
515
- });
516
- __expose({
517
- getComponentRef: () => componentRef.value,
518
- getComponentComputedProps: () => groupedAttrs.value.attrs
519
- });
520
- return (_ctx, _cache) => {
521
- return openBlock(), createBlock(unref(_sfc_main$c), {
522
- component: groupedAttrs.value.componentContainer,
523
- path: props.path
524
- }, {
525
- default: withCtx(() => [
526
- is.value ? (openBlock(), createBlock(resolveDynamicComponent(is.value), mergeProps({ key: 0 }, groupedAttrs.value.attrs, {
527
- ref_key: "componentRef",
528
- ref: componentRef,
529
- [`${groupedAttrs.value.modelProp}`]: value.value,
530
- [`onUpdate:${groupedAttrs.value.modelProp}`]: _cache[0] || (_cache[0] = ($event) => value.value = $event),
531
- path: props.path
532
- }), createSlots({ _: 2 }, [
533
- renderList(groupedAttrs.value.slots, (slot, name) => {
534
- return {
535
- name,
536
- fn: withCtx((scoped) => [
537
- createVNode(unref(_sfc_main$b), mergeProps({
538
- path: props.path
539
- }, scoped, { component: slot }), null, 16, ["path", "component"])
540
- ])
541
- };
542
- })
543
- ]), 1040, ["path"])) : createCommentVNode("", true)
544
- ]),
545
- _: 1
546
- }, 8, ["component", "path"]);
547
- };
548
- }
549
- });
550
- const _sfc_main$c = /* @__PURE__ */ defineComponent({
551
- ...{ name: "ContainerFragment", inheritAttrs: false },
552
- __name: "index",
553
- props: {
554
- component: { type: [Object, Function], default: void 0 }
555
- },
556
- setup(__props) {
557
- const props = __props;
558
- return (_ctx, _cache) => {
559
- return props.component ? (openBlock(), createBlock(resolveDynamicComponent(props.component), normalizeProps(mergeProps({ key: 0 }, _ctx.$attrs)), {
560
- default: withCtx(() => [
561
- renderSlot(_ctx.$slots, "default")
562
- ]),
563
- _: 3
564
- }, 16)) : renderSlot(_ctx.$slots, "default", { key: 1 });
565
- };
566
- }
567
- });
568
- const _sfc_main$b = /* @__PURE__ */ defineComponent({
569
- ...{ name: "SlotComponent", inheritAttrs: false },
570
- __name: "index",
571
- props: {
572
- component: { type: [Object, Function, String, Number, Boolean, null], default: void 0 }
573
- },
574
- setup(__props) {
575
- const props = __props;
576
- return (_ctx, _cache) => {
577
- 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 }, [
578
- createTextVNode(toDisplayString(props.component), 1)
579
- ], 64));
580
- };
581
- }
582
- });
583
622
  const _sfc_main$a = /* @__PURE__ */ defineComponent({
584
623
  ...{ name: "ProForm", inheritAttrs: false },
585
624
  __name: "index",
@@ -589,9 +628,9 @@ const _sfc_main$a = /* @__PURE__ */ defineComponent({
589
628
  },
590
629
  setup(__props) {
591
630
  const props = __props;
592
- const fallbackForm = props.form ? void 0 : useForm();
631
+ let fallbackForm;
593
632
  const currentForm = computed(
594
- () => props.form ?? fallbackForm
633
+ () => props.form ?? (fallbackForm ?? (fallbackForm = useForm()))
595
634
  );
596
635
  const formProxy = createFormProxy(() => currentForm.value);
597
636
  provide(InjectionFormKey, formProxy);
@@ -611,6 +650,7 @@ const _sfc_main$a = /* @__PURE__ */ defineComponent({
611
650
  let formInstanceCounter = 0;
612
651
  const formInstanceKeyMap = /* @__PURE__ */ new WeakMap();
613
652
  const getFormKey = (f) => {
653
+ if (f == null) return 0;
614
654
  if (!formInstanceKeyMap.has(f)) {
615
655
  formInstanceKeyMap.set(f, ++formInstanceCounter);
616
656
  }
@@ -629,7 +669,11 @@ const _sfc_main$a = /* @__PURE__ */ defineComponent({
629
669
  return mergeProps(injectAttrs.value, camelizeProperties(attrs));
630
670
  });
631
671
  const slots = useSlots();
632
- provide(InjectionFormSlotsKey, slots);
672
+ const formSlotsRef = shallowRef(slots);
673
+ onUpdated(() => {
674
+ triggerRef(formSlotsRef);
675
+ });
676
+ provide(InjectionFormSlotsKey, formSlotsRef);
633
677
  return (_ctx, _cache) => {
634
678
  return openBlock(), createBlock(unref(Form), mergeProps({
635
679
  key: formKey.value,
@@ -637,7 +681,7 @@ const _sfc_main$a = /* @__PURE__ */ defineComponent({
637
681
  model: formData.value
638
682
  }, formAttrs.value, { class: "pro-form" }), {
639
683
  default: withCtx(() => [
640
- createVNode(unref(_sfc_main$e), {
684
+ createVNode(_sfc_main$b, {
641
685
  fields: fields.value,
642
686
  grid: props.grid
643
687
  }, null, 8, ["fields", "grid"]),
@@ -722,7 +766,7 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
722
766
  emit("search");
723
767
  };
724
768
  return (_ctx, _cache) => {
725
- return openBlock(), createBlock(unref(_sfc_main$a), mergeProps(layoutProps.value, {
769
+ return openBlock(), createBlock(_sfc_main$a, mergeProps(layoutProps.value, {
726
770
  form: props.form,
727
771
  class: "pro-table_search-form transition"
728
772
  }), {
@@ -803,7 +847,7 @@ const _sfc_main$8 = /* @__PURE__ */ defineComponent({
803
847
  };
804
848
  }
805
849
  });
806
- const SearchForm = /* @__PURE__ */ _export_sfc(_sfc_main$8, [["__scopeId", "data-v-15688cc0"]]);
850
+ const SearchForm = /* @__PURE__ */ _export_sfc(_sfc_main$8, [["__scopeId", "data-v-2272aa98"]]);
807
851
  const _sfc_main$7 = /* @__PURE__ */ defineComponent({
808
852
  __name: "DefaultSearchFormContainer",
809
853
  setup(__props) {
@@ -962,11 +1006,12 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
962
1006
  );
963
1007
  },
964
1008
  set(val) {
1009
+ const checkedSet = new Set(val);
965
1010
  checkedColumnsOptions.value.forEach((item) => {
966
1011
  var _a, _b;
967
- if (item.disabled) return;
1012
+ if (item.disabled || item.checked === checkedSet.has(item.value)) return;
968
1013
  (_b = (_a = props.table) == null ? void 0 : _a.setColumn) == null ? void 0 : _b.call(_a, item.value, {
969
- hidden: !val.includes(item.value)
1014
+ hidden: !checkedSet.has(item.value)
970
1015
  });
971
1016
  });
972
1017
  }
@@ -1085,7 +1130,7 @@ const _sfc_main$2 = /* @__PURE__ */ defineComponent({
1085
1130
  };
1086
1131
  }
1087
1132
  });
1088
- const ColumnControl = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-ca3f82db"]]);
1133
+ const ColumnControl = /* @__PURE__ */ _export_sfc(_sfc_main$2, [["__scopeId", "data-v-9152f113"]]);
1089
1134
  const _hoisted_1 = { class: "pro-table_header" };
1090
1135
  const _hoisted_2 = {
1091
1136
  key: 0,
@@ -1147,11 +1192,27 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
1147
1192
  const size = useModel(__props, "size");
1148
1193
  const loading = useModel(__props, "loading");
1149
1194
  let searchSequence = 0;
1195
+ let warnedSearchConfig = false;
1196
+ const warnSearchConfig = (reason) => {
1197
+ if (warnedSearchConfig) return;
1198
+ warnedSearchConfig = true;
1199
+ console.warn(`[ProTable] ${reason}`);
1200
+ };
1150
1201
  const _search = async () => {
1151
1202
  var _a;
1152
- const seq = ++searchSequence;
1203
+ if (props.search && attrs.onSearch) {
1204
+ warnSearchConfig(
1205
+ "同时配置了 :search prop 与 @search 监听,@search 监听不会被执行,请仅保留其一。"
1206
+ );
1207
+ }
1153
1208
  const searchPromise = (_a = props.search || attrs.onSearch) == null ? void 0 : _a();
1154
- if (!isPromise(searchPromise)) return;
1209
+ if (!isPromise(searchPromise)) {
1210
+ warnSearchConfig(
1211
+ "search 未返回 Promise,本次查询不参与 loading 竞态管理(在途请求的 loading 状态保持不变)。"
1212
+ );
1213
+ return;
1214
+ }
1215
+ const seq = ++searchSequence;
1155
1216
  loading.value = true;
1156
1217
  try {
1157
1218
  await searchPromise;
@@ -1259,7 +1320,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
1259
1320
  const onTableChange = (...args) => {
1260
1321
  var _a, _b, _c;
1261
1322
  (_b = (_a = props.table) == null ? void 0 : _a.setPageParam) == null ? void 0 : _b.call(_a, args[0]);
1262
- (_c = attrs.onChange) == null ? void 0 : _c.call(attrs, ...args);
1323
+ (_c = attrs.onChange ?? injectProps.value.onChange) == null ? void 0 : _c(...args);
1263
1324
  _search();
1264
1325
  };
1265
1326
  const searchFormVisible = computed(() => {
@@ -1299,7 +1360,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
1299
1360
  class: normalizeClass(["pro-table", unref(attrs).class]),
1300
1361
  style: normalizeStyle(unref(attrs).style)
1301
1362
  }, [
1302
- searchFormVisible.value || _ctx.$slots["search-form"] ? (openBlock(), createBlock(unref(_sfc_main$c), {
1363
+ searchFormVisible.value || _ctx.$slots["search-form"] ? (openBlock(), createBlock(_sfc_main$e, {
1303
1364
  key: 0,
1304
1365
  component: computedSearchFormConfig.value.container
1305
1366
  }, {
@@ -1319,7 +1380,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
1319
1380
  ]),
1320
1381
  _: 3
1321
1382
  }, 8, ["component"])) : createCommentVNode("", true),
1322
- createVNode(unref(_sfc_main$c), { component: computedTableContainer.value }, {
1383
+ createVNode(_sfc_main$e, { component: computedTableContainer.value }, {
1323
1384
  default: withCtx(() => [
1324
1385
  createElementVNode("div", _hoisted_1, [
1325
1386
  _ctx.$slots["button-bar"] ? (openBlock(), createElementBlock("div", _hoisted_2, [
@@ -1329,13 +1390,13 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
1329
1390
  renderSlot(_ctx.$slots, "toolbar", {}, void 0, true)
1330
1391
  ])) : createCommentVNode("", true),
1331
1392
  computedControl.value.sizeControl ? (openBlock(), createElementBlock("div", _hoisted_4, [
1332
- createVNode(unref(SizeControl), {
1393
+ createVNode(SizeControl, {
1333
1394
  size: size.value,
1334
1395
  "onUpdate:size": _cache[0] || (_cache[0] = ($event) => size.value = $event)
1335
1396
  }, null, 8, ["size"])
1336
1397
  ])) : createCommentVNode("", true),
1337
1398
  computedControl.value.columnControl ? (openBlock(), createElementBlock("div", _hoisted_5, [
1338
- createVNode(unref(ColumnControl), {
1399
+ createVNode(ColumnControl, {
1339
1400
  columns: computedColumns.value,
1340
1401
  table: props.table,
1341
1402
  "column-control": columnControlConfig.value
@@ -1368,7 +1429,7 @@ const _sfc_main$1 = /* @__PURE__ */ defineComponent({
1368
1429
  };
1369
1430
  }
1370
1431
  });
1371
- const ProTable = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-3276e1dc"]]);
1432
+ const ProTable = /* @__PURE__ */ _export_sfc(_sfc_main$1, [["__scopeId", "data-v-a75a38c5"]]);
1372
1433
  function useTable(params) {
1373
1434
  return useTable$1(params);
1374
1435
  }
@@ -1452,12 +1513,12 @@ const index = {
1452
1513
  }
1453
1514
  };
1454
1515
  export {
1455
- _sfc_main$c as ContainerFragment,
1516
+ _sfc_main$e as ContainerFragment,
1456
1517
  LOCALE_INJECT_KEY,
1457
1518
  _sfc_main as ProComponentProvider,
1458
1519
  _sfc_main$a as ProForm,
1459
1520
  ProTable,
1460
- _sfc_main$b as SlotComponent,
1521
+ _sfc_main$d as SlotComponent,
1461
1522
  index as default,
1462
1523
  enUS2 as enUS,
1463
1524
  useFields,