@qin-ui/element-plus-pro 1.3.5 → 1.4.1

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 (93) hide show
  1. package/AI-CONTEXT.md +27 -3
  2. package/README.md +42 -31
  3. package/api.json +69 -38
  4. package/es/components/component-provider/components/index.vue.d.ts +10 -3
  5. package/es/components/component-provider/components/index.vue.d.ts.map +1 -1
  6. package/es/components/component-provider/constants/index.d.ts +22 -4
  7. package/es/components/component-provider/constants/index.d.ts.map +1 -1
  8. package/es/components/component-provider/types/index.d.ts +15 -1
  9. package/es/components/component-provider/types/index.d.ts.map +1 -1
  10. package/es/components/form/components/BaseField/index.vue.d.ts.map +1 -1
  11. package/es/components/form/components/BaseField/utils/index.d.ts +15 -0
  12. package/es/components/form/components/BaseField/utils/index.d.ts.map +1 -1
  13. package/es/components/form/components/BaseFormItem/index.vue.d.ts +3 -1
  14. package/es/components/form/components/BaseFormItem/index.vue.d.ts.map +1 -1
  15. package/es/components/form/components/ContainerFragment/index.vue.d.ts.map +1 -1
  16. package/es/components/form/components/ProForm/index.vue.d.ts.map +1 -1
  17. package/es/components/form/components/SlotComponent/index.vue.d.ts.map +1 -1
  18. package/es/components/form/components/index.d.ts +4 -0
  19. package/es/components/form/components/index.d.ts.map +1 -1
  20. package/es/components/form/constants/index.d.ts +8 -2
  21. package/es/components/form/constants/index.d.ts.map +1 -1
  22. package/es/components/form/hooks/useFields.d.ts.map +1 -1
  23. package/es/components/form/hooks/useForm.d.ts.map +1 -1
  24. package/es/components/form/hooks/useGroupFieldAttrs.d.ts +9 -0
  25. package/es/components/form/hooks/useGroupFieldAttrs.d.ts.map +1 -1
  26. package/es/components/form/index.d.ts +2 -2
  27. package/es/components/form/index.d.ts.map +1 -1
  28. package/es/components/form/types/index.d.ts +65 -50
  29. package/es/components/form/types/index.d.ts.map +1 -1
  30. package/es/components/form/utils/fieldKey.d.ts +13 -0
  31. package/es/components/form/utils/fieldKey.d.ts.map +1 -0
  32. package/es/components/table/components/ColumnControl.vue.d.ts +1 -1
  33. package/es/components/table/components/ColumnControl.vue.d.ts.map +1 -1
  34. package/es/components/table/components/ProTable.vue.d.ts +15 -1
  35. package/es/components/table/components/ProTable.vue.d.ts.map +1 -1
  36. package/es/components/table/components/SearchForm.vue.d.ts +13 -1
  37. package/es/components/table/components/SearchForm.vue.d.ts.map +1 -1
  38. package/es/components/table/components/SizeControl.vue.d.ts +7 -2
  39. package/es/components/table/components/SizeControl.vue.d.ts.map +1 -1
  40. package/es/components/table/components/TableColumnRenderer.vue.d.ts +14 -14
  41. package/es/components/table/components/TableColumnRenderer.vue.d.ts.map +1 -1
  42. package/es/components/table/hooks/index.d.ts +2 -0
  43. package/es/components/table/hooks/index.d.ts.map +1 -0
  44. package/es/components/table/{useTable.d.ts → hooks/useTable.d.ts} +3 -3
  45. package/es/components/table/hooks/useTable.d.ts.map +1 -0
  46. package/es/components/table/index.d.ts +6 -2
  47. package/es/components/table/index.d.ts.map +1 -1
  48. package/es/components/table/types/index.d.ts +16 -12
  49. package/es/components/table/types/index.d.ts.map +1 -1
  50. package/es/element-plus-pro.css +14 -14
  51. package/es/index.d.ts +9 -6
  52. package/es/index.d.ts.map +1 -1
  53. package/es/index.js +307 -227
  54. package/es/index.js.map +1 -1
  55. package/es/locale/index.d.ts +2 -1
  56. package/es/locale/index.d.ts.map +1 -1
  57. package/es/shared/core/index.d.ts +1 -1
  58. package/es/shared/core/index.d.ts.map +1 -1
  59. package/es/shared/ui/index.d.ts +20 -2
  60. package/es/shared/ui/index.d.ts.map +1 -1
  61. package/package.json +5 -4
  62. package/src/components/component-provider/components/index.vue +48 -21
  63. package/src/components/component-provider/constants/index.ts +34 -6
  64. package/src/components/component-provider/types/index.ts +21 -7
  65. package/src/components/form/components/BaseField/index.vue +25 -12
  66. package/src/components/form/components/BaseField/utils/index.ts +16 -1
  67. package/src/components/form/components/BaseFormItem/index.vue +25 -32
  68. package/src/components/form/components/ContainerFragment/index.vue +3 -1
  69. package/src/components/form/components/ProForm/index.vue +41 -21
  70. package/src/components/form/components/SlotComponent/index.vue +4 -2
  71. package/src/components/form/components/index.ts +8 -1
  72. package/src/components/form/constants/index.ts +9 -2
  73. package/src/components/form/hooks/useFields.ts +5 -2
  74. package/src/components/form/hooks/useForm.ts +8 -1
  75. package/src/components/form/hooks/useGroupFieldAttrs.ts +24 -17
  76. package/src/components/form/index.ts +1 -3
  77. package/src/components/form/types/index.ts +71 -52
  78. package/src/components/form/utils/fieldKey.ts +27 -0
  79. package/src/components/table/components/ColumnControl.vue +16 -6
  80. package/src/components/table/components/ProTable.vue +183 -93
  81. package/src/components/table/components/SearchForm.vue +60 -22
  82. package/src/components/table/components/SizeControl.vue +23 -1
  83. package/src/components/table/components/TableColumnRenderer.vue +82 -63
  84. package/src/components/table/hooks/index.ts +1 -0
  85. package/src/components/table/{useTable.ts → hooks/useTable.ts} +6 -4
  86. package/src/components/table/index.ts +11 -2
  87. package/src/components/table/types/index.ts +17 -13
  88. package/src/index.ts +13 -7
  89. package/src/locale/index.ts +4 -2
  90. package/src/shared/core/index.ts +11 -0
  91. package/src/shared/ui/index.ts +29 -5
  92. package/tsconfig.json +0 -1
  93. package/es/components/table/useTable.d.ts.map +0 -1
@@ -1,31 +1,30 @@
1
- <script
2
- lang="ts"
3
- setup
4
- generic="D extends Record<string, any> = Record<string, any>"
5
- >
6
- import { get, normalizePathKey } from '../../../shared/core';
1
+ <script lang="ts">
2
+ /**
3
+ * 列配置渲染器
4
+ *
5
+ * @component TableColumnRenderer
6
+ * @description 把列数组渲染为 el-table-column 树,支持分组列(children)、自定义 render 列与深层路径取值
7
+ *
8
+ * @param {Columns} [columns] - 列配置数组
9
+ *
10
+ * @internal
11
+ */
12
+ import { defineComponent, h, toRaw, toValue, type PropType } from 'vue';
13
+ import { get, isObjectItem, normalizePathKey } from '../../../shared/core';
7
14
  import { TableColumn } from '../../../shared/ui';
8
15
  import SlotComponent from '../../form/components/SlotComponent/index.vue';
9
16
  import type { Column, Columns } from '../types';
10
- import { computed, toRaw } from 'vue';
11
-
12
- defineOptions({ name: 'TableColumnRenderer' });
13
-
14
- type Props = {
15
- columns: Columns<D>;
16
- };
17
- const props = withDefaults(defineProps<Props>(), {
18
- columns: () => [],
19
- });
20
17
 
21
18
  /*
22
- * 无 key/prop 列的稳定渲染 key:以列原始对象为 key 分配自增 id,
23
- * 列插删/重排/过滤时保持 key 与对象绑定,不随数组位置漂移
19
+ * 无 key/prop 列的渲染 key 与列对象身份绑定:
20
+ * 列增删、重排与过滤后 key 不随数组位置漂移
24
21
  */
25
22
  let columnKeySeed = 0;
26
23
  const columnKeyMap = new WeakMap<object, number>();
27
- const getStableColumnKey = (column: unknown): number => {
28
- const raw = toRaw(column as object);
24
+ const getStableColumnKey = (column: unknown): string | number => {
25
+ if (column === null || typeof column !== 'object')
26
+ return `raw_${String(column)}`;
27
+ const raw = toRaw(column);
29
28
  let key = columnKeyMap.get(raw);
30
29
  if (key === undefined) {
31
30
  key = ++columnKeySeed;
@@ -34,24 +33,20 @@ const getStableColumnKey = (column: unknown): number => {
34
33
  return key;
35
34
  };
36
35
 
37
- const getColumnKey = (column: Column<D>) => {
38
- const rawKey = column.key ?? column.prop;
39
- if (rawKey === undefined || rawKey === null)
40
- return getStableColumnKey(column);
36
+ const getColumnKey = (column: Column) => {
37
+ // 空字符串 key 视为未提供,与 getColumnProps 的 columnKey 取值一致
38
+ const rawKey = column.key || column.prop;
39
+ if (!rawKey) return getStableColumnKey(column);
41
40
  return normalizePathKey(rawKey);
42
41
  };
43
42
 
44
- const getCellValue = (row: Record<string, any>, column: Column<D>) => {
43
+ const getCellValue = (row: Record<string, any>, column: Column) => {
45
44
  const path = column.prop;
46
45
  if (!path) return undefined;
47
46
  return get(row, path);
48
47
  };
49
48
 
50
- const normalizedColumns = computed(() => {
51
- return props.columns.filter(column => !column.hidden);
52
- });
53
-
54
- const getColumnProps = (column: Column<D>) => {
49
+ const getColumnProps = (column: Column) => {
55
50
  const { hidden, render, key, children, ...rest } = column;
56
51
  const prop = column.prop ? normalizePathKey(column.prop) : undefined;
57
52
  const columnKey = key ? normalizePathKey(key) : prop;
@@ -62,38 +57,62 @@ const getColumnProps = (column: Column<D>) => {
62
57
  columnKey,
63
58
  };
64
59
  };
65
- </script>
66
60
 
67
- <template>
68
- <template v-for="column in normalizedColumns" :key="getColumnKey(column)">
69
- <!-- 分组列(递归子列) -->
70
- <TableColumn
71
- v-if="column.children && column.children.length > 0"
72
- v-bind="getColumnProps(column)"
73
- >
74
- <TableColumnRenderer :columns="column.children" />
75
- </TableColumn>
76
-
77
- <!-- 自定义 render 列 -->
78
- <TableColumn
79
- v-else-if="typeof column.render === 'function'"
80
- v-bind="getColumnProps(column)"
81
- >
82
- <template #default="scope">
83
- <!-- 经 SlotComponent 渲染:支持组件、VNode 与文本等多种形态 -->
84
- <SlotComponent
85
- :component="
86
- column.render?.({
87
- ...scope,
88
- column,
89
- cellValue: getCellValue(scope.row, column),
90
- })
91
- "
92
- />
93
- </template>
94
- </TableColumn>
61
+ /*
62
+ * 递归渲染列树:子列以同层 vnode 数组展开,深层分组同样成立;
63
+ * 每层以不可变祖先路径向下传递,重复出现的祖先引用直接剔除(含 a→b→a 互引用)
64
+ */
65
+ const renderColumn = (
66
+ column: Column,
67
+ ancestors: Set<object> = new Set()
68
+ ): any => {
69
+ const hasChildren =
70
+ Array.isArray(column.children) && column.children.length > 0;
71
+ const vnodeProps = { key: getColumnKey(column), ...getColumnProps(column) };
72
+ if (hasChildren) {
73
+ // 每层祖先路径随 vnode 创建确定,环状引用按路径截断
74
+ const nextAncestors = new Set(ancestors).add(column);
75
+ return h(TableColumn, vnodeProps, {
76
+ default: () =>
77
+ column
78
+ .children!.filter(
79
+ child =>
80
+ isObjectItem(child) &&
81
+ !nextAncestors.has(child) &&
82
+ !toValue(child.hidden)
83
+ )
84
+ .map(child => renderColumn(child, nextAncestors)),
85
+ });
86
+ }
87
+ if (typeof column.render === 'function') {
88
+ return h(TableColumn, vnodeProps, {
89
+ default: (scope: any) =>
90
+ h(SlotComponent, {
91
+ component: column.render!({
92
+ ...scope,
93
+ column,
94
+ cellValue: getCellValue(scope.row, column),
95
+ }),
96
+ }),
97
+ });
98
+ }
99
+ return h(TableColumn, vnodeProps);
100
+ };
95
101
 
96
- <!-- 普通列(Element Plus 原生渲染) -->
97
- <TableColumn v-else v-bind="getColumnProps(column)" />
98
- </template>
99
- </template>
102
+ export default defineComponent({
103
+ name: 'TableColumnRenderer',
104
+ inheritAttrs: false,
105
+ props: {
106
+ columns: {
107
+ type: Array as PropType<Columns>,
108
+ default: () => [],
109
+ },
110
+ },
111
+ setup(props) {
112
+ return () =>
113
+ props.columns
114
+ .filter(column => isObjectItem(column) && !toValue(column.hidden))
115
+ .map(column => renderColumn(column));
116
+ },
117
+ });
118
+ </script>
@@ -0,0 +1 @@
1
+ export * from './useTable';
@@ -1,15 +1,16 @@
1
1
  import {
2
2
  useTable as coreUseTable,
3
3
  type Table as _Table,
4
- } from '../../shared/core';
4
+ } from '../../../shared/core';
5
5
  import type {
6
6
  Data,
7
7
  ExtendWithAny,
8
8
  DeepPartial,
9
9
  PageParam,
10
- } from '../../shared/core';
11
- import { Fields } from '../form/types';
12
- import type { Column, Columns } from './types';
10
+ } from '../../../shared/core';
11
+ import type { Fields } from '../../form/types';
12
+ import { ELEMENT_FIELD_IDENTITY_KEYS } from '../../form/constants';
13
+ import type { Column, Columns } from '../types';
13
14
  import type { Ref } from 'vue';
14
15
 
15
16
  /**
@@ -133,6 +134,7 @@ export function useTable<
133
134
  ...rest,
134
135
  dataSource: data,
135
136
  columns: columns as any,
137
+ fieldIdentityKeys: ELEMENT_FIELD_IDENTITY_KEYS,
136
138
  });
137
139
 
138
140
  const { dataSource, ...tableWithoutDataSource } = coreTable as Omit<
@@ -5,14 +5,23 @@ import type {
5
5
  import ProTable from './components/ProTable.vue';
6
6
 
7
7
  // 仅导出组件 Props 与实例类型,不导出裸组件
8
+ /** ProTable 组件属性(由组件 Props 推导) */
8
9
  export type ProTableProps = ComponentProps<typeof ProTable>;
10
+ /** ProTable 组件实例(`defineExpose` 暴露的能力) */
9
11
  export type ProTableInstance = ComponentExposed<typeof ProTable>;
10
12
 
11
13
  // 仅导出核心列配置类型
12
- export { type Column, type Columns } from './types';
14
+ export {
15
+ type Column,
16
+ type ColumnControlConfig,
17
+ type ColumnScope,
18
+ type Columns,
19
+ } from './types';
20
+ /** Element Plus 宿主表格事件类型(仅 element 适配层提供) */
13
21
  export { type TableEmits } from '../../shared/ui';
14
22
 
15
23
  // 仅导出核心表格 Hook 与类型
16
- export { useTable, type Table } from './useTable';
24
+ export { useTable, type Table } from './hooks';
25
+ export { type PageParam } from '../../shared/core';
17
26
 
18
27
  export default ProTable;
@@ -1,5 +1,7 @@
1
1
  import type { ColumnType } from '../../../shared/ui';
2
- import { Data, ExtendWithAny, Path } from '../../../shared/core';
2
+ import type { Data, ExtendWithAny, Path } from '../../../shared/core';
3
+ import type { ComputedRef, MaybeRef } from 'vue';
4
+ type MaybeRefOrComputedRef<T = any> = MaybeRef<T> | ComputedRef<T>;
3
5
 
4
6
  type BivariantRender<D extends Data = Data> = {
5
7
  bivarianceHack(scope: ColumnScope<D>): any;
@@ -8,7 +10,7 @@ type BivariantRender<D extends Data = Data> = {
8
10
  /**
9
11
  * Element Plus 表格列作用域
10
12
  * @template D - 表格行数据类型
11
-
13
+ *
12
14
  * @public
13
15
  */
14
16
  export type ColumnScope<D extends Data = Data> = {
@@ -23,16 +25,14 @@ export type ColumnScope<D extends Data = Data> = {
23
25
  };
24
26
 
25
27
  /**
26
- * @qin-ui/element-plus-pro 表格列配置类型
28
+ * 表格列配置类型,基于宿主 ColumnType 扩展
27
29
  *
28
- * @description 基于 Element Plus 的 ColumnType 列类型,并添加:
30
+ * @description 在宿主列类型之上新增:
29
31
  * - prop 作为主要字段(Element Plus 使用 prop 而非 dataIndex)
30
32
  * - key 作为辅助标识
31
33
  * - hidden 属性
32
34
  * - render 自定义渲染函数
33
- *
34
35
  * @template D - 表格行数据类型
35
- *
36
36
  * @example
37
37
  * ```ts
38
38
  * interface User { name: string; age: number }
@@ -42,7 +42,7 @@ export type ColumnScope<D extends Data = Data> = {
42
42
  * { prop: 'age', label: '年龄', width: 80 },
43
43
  * ]
44
44
  * ```
45
-
45
+ *
46
46
  * @public
47
47
  */
48
48
  export type Column<D extends Data = Data> = Partial<
@@ -51,13 +51,16 @@ export type Column<D extends Data = Data> = Partial<
51
51
  /** 列字段标识(辅助字段) */
52
52
  key?: Path<D>;
53
53
  /**
54
- * @description 列数据路径(主要字段)
55
- * Element Plus 使用 prop 而非 dataIndex
54
+ * 列数据路径(主要字段),Element Plus 使用 prop 而非 dataIndex
56
55
  * @example 'name' | 'address.city'
57
56
  */
58
57
  prop?: Path<D>;
59
- /** 是否隐藏该列 */
60
- hidden?: boolean;
58
+ /**
59
+ * 列是否隐藏;支持布尔、Ref 与 ComputedRef 形式,渲染期按 `toValue` 取值
60
+ *
61
+ * 分组列的子列同样参与过滤(递归生效)。
62
+ */
63
+ hidden?: MaybeRefOrComputedRef<boolean>;
61
64
  /** 自定义渲染函数 */
62
65
  render?: BivariantRender<D>;
63
66
  /** 嵌套子列(用于表头分组) */
@@ -65,9 +68,10 @@ export type Column<D extends Data = Data> = Partial<
65
68
  };
66
69
 
67
70
  /**
68
- * @qin-ui/element-plus-pro 表格列配置数组类型
71
+ * 表格列配置数组类型
72
+ *
69
73
  * @template D - 表格行数据类型
70
-
74
+ *
71
75
  * @public
72
76
  */
73
77
  export type Columns<D extends Data = Data> = Array<Column<D>>;
package/src/index.ts CHANGED
@@ -26,7 +26,9 @@ export * from './locale';
26
26
  * <ProForm :form="form" />
27
27
  * </template>
28
28
  * ```
29
- *
29
+ */
30
+ export { ProForm };
31
+ /**
30
32
  * Schema 驱动的表格组件,基于 element-plus Table 封装
31
33
  *
32
34
  * @description 通过声明式列配置即可生成功能完整的表格,
@@ -42,7 +44,9 @@ export * from './locale';
42
44
  * <ProTable :table="table" />
43
45
  * </template>
44
46
  * ```
45
- *
47
+ */
48
+ export { ProTable };
49
+ /**
46
50
  * 组件提供者,用于全局配置 ProForm 和 ProTable 的默认行为
47
51
  *
48
52
  * @description 通过 `ProComponentProvider` 包裹应用根组件,
@@ -57,15 +61,14 @@ export * from './locale';
57
61
  * </template>
58
62
  * ```
59
63
  */
60
- export { ProForm, ProTable, ProComponentProvider };
64
+ export { ProComponentProvider };
61
65
 
62
66
  export default {
63
67
  /**
64
- * @qin-ui/element-plus-pro 安装方法
65
- * @description 全局注册所有组件(ProForm、ProTable、ProComponentProvider)
68
+ * 安装方法:全局注册 ProForm / ProTable / ProComponentProvider
66
69
  *
70
+ * @description 供 `app.use(ProComponents)` 调用
67
71
  * @param {App} app - Vue 应用实例
68
- *
69
72
  * @example
70
73
  * ```ts
71
74
  * import { createApp } from 'vue'
@@ -77,6 +80,9 @@ export default {
77
80
  install(app: App) {
78
81
  app.component(ProForm.name, ProForm);
79
82
  app.component(ProTable.name, ProTable);
80
- app.component(ProComponentProvider.name!, ProComponentProvider);
83
+ app.component(
84
+ ProComponentProvider.name ?? 'ProComponentProvider',
85
+ ProComponentProvider
86
+ );
81
87
  },
82
88
  };
@@ -20,7 +20,8 @@ import enUS from './en-US';
20
20
 
21
21
  export { zhCN, zhTW, enUS };
22
22
 
23
- export type ProLocale = typeof zhCN;
23
+ /** 内置文案类型:键集合与 zh-CN 对齐,取值允许任意文案覆盖 */
24
+ export type ProLocale = Record<keyof typeof zhCN, string>;
24
25
 
25
26
  /** ProComponentProvider 通过该 key 注入局部覆盖文案 */
26
27
  export const LOCALE_INJECT_KEY: InjectionKey<
@@ -50,7 +51,8 @@ export const useLocale = () => {
50
51
  const override = inject(LOCALE_INJECT_KEY, undefined);
51
52
 
52
53
  const lang = computed<ProLocaleName>(() => {
53
- if (!elLocaleContext) return 'zh-CN';
54
+ // 注入上下文为 computed/ref 包装,按取值本体判定宿主是否提供语言
55
+ if (toValue(elLocaleContext) == null) return 'zh-CN';
54
56
  return resolveLocaleName(elLang.value);
55
57
  });
56
58
  const pack = computed<Record<string, string>>(() =>
@@ -2,19 +2,28 @@
2
2
  * 统一 re-export @qin-ui/pro-components-core,包内所有文件通过此文件引入 core 内容。
3
3
  */
4
4
  export {
5
+ // types
6
+ type AdditionalMethods,
7
+ localePacks,
8
+ normalizeColumn,
9
+ normalizeColumns,
5
10
  // hooks
6
11
  useForm,
7
12
  createFormProxy,
8
13
  useTable,
9
14
  useSearchFormExpand,
10
15
  useFields,
16
+ resolveFieldIdentity,
17
+ DEFAULT_FIELD_IDENTITY_KEYS,
11
18
  useFormData,
12
19
  useFormRef,
20
+ useReactiveAttrs,
13
21
  // injection keys
14
22
  InjectionFormKey,
15
23
  InjectionFormSlotsKey,
16
24
  // utils
17
25
  getObject,
26
+ omitBy,
18
27
  get,
19
28
  set,
20
29
  normalizePathKey,
@@ -22,7 +31,9 @@ export {
22
31
  camelizeProperties,
23
32
  cloneDeep,
24
33
  pick,
34
+ omit,
25
35
  isPlainObject,
36
+ isObjectItem,
26
37
  isPromise,
27
38
  // locale
28
39
  zhCN,
@@ -27,6 +27,7 @@ import {
27
27
  ElTimeSelect as TimeSelect,
28
28
  ElPagination as Pagination,
29
29
  useFormDisabled,
30
+ useSize,
30
31
  type FormItemInstance,
31
32
  type FormInstance,
32
33
  type FormProps,
@@ -68,6 +69,7 @@ export {
68
69
  TimePicker,
69
70
  TimeSelect,
70
71
  Pagination,
72
+ useSize,
71
73
  type FormItemInstance,
72
74
  type FormInstance,
73
75
  type FormProps,
@@ -79,6 +81,7 @@ export {
79
81
  type TableEmits,
80
82
  };
81
83
 
84
+ /** 宿主 Table 属性面(放宽泛型以兼容任意行数据) */
82
85
  export type TableProps = _TableProps<any>;
83
86
 
84
87
  const _tableProps = (Table as any).props || {};
@@ -86,34 +89,55 @@ const _paginationProps = (Pagination as any).props || {};
86
89
  const _gridItemProps = (GridItem as any).props || {};
87
90
  const _formItemProps = (FormItem as any).props || {};
88
91
 
92
+ /** 宿主 Table 的静态 props 快照(透传键名白名单用) */
89
93
  export const tableProps = () => _tableProps;
94
+ /** 宿主 Pagination 的静态 props 快照(分页配置键名白名单用) */
90
95
  export const paginationProps = () => _paginationProps;
96
+ /** 宿主 Row/Col 的静态 props 快照 */
91
97
  export const gridItemProps = () => _gridItemProps;
98
+ /** 宿主 FormItem 的静态 props 快照 */
92
99
  export const formItemProps = () => _formItemProps;
93
100
 
94
101
  const DisabledContextKey = Symbol.for('pro-form-disabled-context');
95
102
 
103
+ /** 禁用上下文取值
104
+ *
105
+ * @description 字段级禁用优先,未声明时回退宿主 `el-form` 的禁用状态
106
+ * @returns {ComputedRef<boolean>} 当前生效的禁用状态
107
+ */
96
108
  export const useDisabledContext = () => {
97
109
  const formDisabled = useFormDisabled();
98
- const customDisabled = inject<any>(DisabledContextKey, undefined);
110
+ const customDisabled = inject<MaybeRefOrGetter<boolean | undefined>>(
111
+ DisabledContextKey,
112
+ undefined
113
+ );
99
114
  return computed(() => {
100
- if (customDisabled !== undefined && toValue(customDisabled) !== undefined) {
101
- return Boolean(toValue(customDisabled));
102
- }
115
+ const custom = toValue(customDisabled);
116
+ if (custom !== undefined) return Boolean(custom);
103
117
  return Boolean(formDisabled.value);
104
118
  });
105
119
  };
106
120
 
121
+ /** 禁用上下文提供者
122
+ *
123
+ * @description 与父级禁用上下文合并:未声明时保持继承,声明时(含 false)覆盖
124
+ * @param {MaybeRefOrGetter<boolean | undefined>} disabled - 本层声明的禁用状态
125
+ */
107
126
  export const useDisabledContextProvider = (
108
127
  disabled: MaybeRefOrGetter<boolean | undefined>
109
128
  ) => {
129
+ // 与父级禁用上下文合并:未声明时保持继承,声明时(含 false)覆盖
130
+ const parentDisabled = useDisabledContext();
110
131
  provide(
111
132
  DisabledContextKey,
112
- computed(() => !!toValue(disabled))
133
+ computed(() => toValue(disabled) ?? parentDisabled.value)
113
134
  );
114
135
  };
115
136
 
137
+ /** {@link useDisabledContext} 的别名 */
116
138
  export const useInjectDisabled = useDisabledContext;
139
+ /** {@link useDisabledContextProvider} 的别名 */
117
140
  export const useProviderDisabled = useDisabledContextProvider;
118
141
 
142
+ /** 字段路径:字符串、数字或分段数组 */
119
143
  export type NamePath = string | number | (string | number)[];
package/tsconfig.json CHANGED
@@ -11,7 +11,6 @@
11
11
  "esModuleInterop": true,
12
12
  "lib": ["ESNext", "ES2022", "DOM"],
13
13
  "baseUrl": ".",
14
- "types": ["element-plus/global"],
15
14
  "declaration": true,
16
15
  "declarationMap": true,
17
16
  "skipLibCheck": true,
@@ -1 +0,0 @@
1
- {"version":3,"file":"useTable.d.ts","sourceRoot":"","sources":["../../../src/components/table/useTable.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,KAAK,IAAI,MAAM,EACrB,MAAM,mBAAmB,CAAC;AAC3B,OAAO,KAAK,EACV,IAAI,EACJ,aAAa,EACb,WAAW,EACX,SAAS,EACV,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,MAAM,EAAE,MAAM,eAAe,CAAC;AACvC,OAAO,KAAK,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AAC/C,OAAO,KAAK,EAAE,GAAG,EAAE,MAAM,KAAK,CAAC;AAE/B;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAM,MAAM,KAAK,CACf,CAAC,SAAS,IAAI,GAAG,IAAI,EACrB,CAAC,SAAS,IAAI,GAAG,aAAa,CAAC,CAAC,CAAC,IAC/B,IAAI,CAAC,MAAM,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC,EAAE,YAAY,CAAC,GAAG;IAChD;;OAEG;IACH,IAAI,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC;CAChB,CAAC;AAEF,KAAK,cAAc,CACjB,CAAC,SAAS,IAAI,GAAG,IAAI,EACrB,CAAC,SAAS,IAAI,GAAG,aAAa,CAAC,CAAC,CAAC,IAC/B;IACF,YAAY;IACZ,OAAO,CAAC,EAAE,OAAO,CAAC,CAAC,CAAC,CAAC;IACrB,gDAAgD;IAChD,IAAI,CAAC,EAAE,CAAC,EAAE,CAAC;IACX,aAAa;IACb,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,aAAa;IACb,WAAW,CAAC,EAAE,aAAa,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IAC5C,eAAe;IACf,YAAY,CAAC,EAAE,MAAM,CAAC,CAAC,CAAC,CAAC;CAC1B,CAAC;AAEF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+CG;AACH,wBAAgB,QAAQ,CACtB,CAAC,SAAS,IAAI,GAAG,IAAI,EACrB,CAAC,SAAS,IAAI,GAAG,aAAa,CAAC,CAAC,CAAC,EACjC,MAAM,GAAE,cAAc,CAAC,CAAC,EAAE,CAAC,CAAM,GAAG,KAAK,CAAC,CAAC,EAAE,CAAC,CAAC,CAoBhD"}