@iswangh/element-plus-kit-form 0.2.0 → 0.2.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.
- package/README.md +101 -1
- package/dist/FormItem.vue.d.ts +6 -9
- package/dist/FormItem.vue.d.ts.map +1 -1
- package/dist/config/comp.d.ts +1 -5
- package/dist/config/comp.d.ts.map +1 -1
- package/dist/config/form-item.d.ts +6 -0
- package/dist/config/form-item.d.ts.map +1 -0
- package/dist/config/index.d.ts +1 -0
- package/dist/config/index.d.ts.map +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +700 -670
- package/dist/style.css +1 -1
- package/dist/types/comp.d.ts +29 -29
- package/dist/types/el.d.ts +3 -0
- package/dist/types/form-item.d.ts +12 -7
- package/dist/types/scope.d.ts +30 -0
- package/package.json +2 -2
package/dist/types/comp.d.ts
CHANGED
|
@@ -49,29 +49,29 @@ export type FormCompConfig = ElCompMap & typeof EXPAND_COMP_MAP
|
|
|
49
49
|
* 注意:由于 FORM_ITEM_COMP_MAP 使用了 Record<string, any> 避免类型推断超出限制,
|
|
50
50
|
* 我们需要显式定义键名类型,而不是从 typeof FORM_ITEM_COMP_MAP 中提取
|
|
51
51
|
*/
|
|
52
|
-
export type FormItemComp
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
52
|
+
export type FormItemComp = 'custom'
|
|
53
|
+
| 'autocomplete'
|
|
54
|
+
| 'cascader'
|
|
55
|
+
| 'checkbox'
|
|
56
|
+
| 'color-picker'
|
|
57
|
+
| 'color-picker-panel'
|
|
58
|
+
| 'date-picker'
|
|
59
|
+
| 'date-picker-panel'
|
|
60
|
+
| 'input'
|
|
61
|
+
| 'input-number'
|
|
62
|
+
| 'input-tag'
|
|
63
|
+
| 'mention'
|
|
64
|
+
| 'radio'
|
|
65
|
+
| 'rate'
|
|
66
|
+
| 'select'
|
|
67
|
+
| 'select-v2'
|
|
68
|
+
| 'slider'
|
|
69
|
+
| 'switch'
|
|
70
|
+
| 'time-picker'
|
|
71
|
+
| 'time-select'
|
|
72
|
+
| 'transfer'
|
|
73
|
+
| 'tree-select'
|
|
74
|
+
| 'custom'
|
|
75
75
|
|
|
76
76
|
/**
|
|
77
77
|
* 根据组件类型获取组件实例类型
|
|
@@ -80,14 +80,14 @@ export type FormItemComp
|
|
|
80
80
|
export type FormItemCompInstance<T extends FormItemComp> = InstanceType<FormCompConfig[T]>
|
|
81
81
|
|
|
82
82
|
/**
|
|
83
|
-
*
|
|
84
|
-
* @template T 组件类型
|
|
83
|
+
* 根据组件类型推断对应的 Props 类型(包含事件处理器)
|
|
84
|
+
* @template T - 组件类型
|
|
85
85
|
*/
|
|
86
|
-
type
|
|
86
|
+
export type FormItemCompProps<T extends FormItemComp = FormItemComp>
|
|
87
|
+
= FormItemCompInstance<T>['$props']
|
|
87
88
|
|
|
88
89
|
/**
|
|
89
|
-
*
|
|
90
|
+
* 根据组件类型推断对应的插槽类型
|
|
90
91
|
* @template T - 组件类型
|
|
91
92
|
*/
|
|
92
|
-
export type
|
|
93
|
-
= Omit<FormItemCompPropsFull<T>, `on${string}`>
|
|
93
|
+
export type FormItemCompSlots<T extends FormItemComp> = FormItemCompInstance<T>['$slots']
|
package/dist/types/el.d.ts
CHANGED
|
@@ -36,6 +36,9 @@ export interface ElFormProps {
|
|
|
36
36
|
/** Element Plus FormItem Props */
|
|
37
37
|
export type ElFormItemProps = FormItemInstance['$props']
|
|
38
38
|
|
|
39
|
+
/** Element Plus FormItem Slots */
|
|
40
|
+
export type ElFormItemSlots = FormItemInstance['$slots']
|
|
41
|
+
|
|
39
42
|
/** Element Plus Row 组件 Props */
|
|
40
43
|
export type ElRowProps = InstanceType<typeof ElRow>['$props']
|
|
41
44
|
|
|
@@ -3,6 +3,7 @@ import { FormItemComp, FormItemCompProps } from './comp';
|
|
|
3
3
|
import { ElFormItemProps } from './el';
|
|
4
4
|
import { ColProps } from './layout';
|
|
5
5
|
import { InferOptionsType, IsOptionsSupported } from './options';
|
|
6
|
+
import { CompSlotsConfig, FormItemSlotsConfig } from './scope';
|
|
6
7
|
/**
|
|
7
8
|
* 根据组件类型推断 options 类型
|
|
8
9
|
* 只有支持 options 的组件才会扩展 options 类型
|
|
@@ -14,12 +15,14 @@ export type FormItemOptions<T extends FormItemComp> = IsOptionsSupported<T> exte
|
|
|
14
15
|
|
|
15
16
|
/**
|
|
16
17
|
* 根据组件类型推断 compProps 类型(扩展版本)
|
|
17
|
-
* 支持扩展属性,如 options 等
|
|
18
|
+
* 支持扩展属性,如 options、slots 等
|
|
18
19
|
* @template T - 组件类型
|
|
19
20
|
*/
|
|
20
|
-
export type FormItemCompPropsExtended<T extends FormItemComp>
|
|
21
|
-
|
|
22
|
-
|
|
21
|
+
export type FormItemCompPropsExtended<T extends FormItemComp>
|
|
22
|
+
= (IsOptionsSupported<T> extends true
|
|
23
|
+
? Omit<FormItemCompProps<T>, 'options'> & { options?: FormItemOptions<T> }
|
|
24
|
+
: FormItemCompProps<T>)
|
|
25
|
+
& { slots?: CompSlotsConfig<T> }
|
|
23
26
|
|
|
24
27
|
/**
|
|
25
28
|
* FormItem Props
|
|
@@ -27,9 +30,10 @@ export type FormItemCompPropsExtended<T extends FormItemComp> = IsOptionsSupport
|
|
|
27
30
|
* 扩展自 Element Plus 的 FormItem 组件 Props,添加了自定义配置选项
|
|
28
31
|
*
|
|
29
32
|
* @template T - 组件类型
|
|
30
|
-
* @extends {ElFormItemProps} Element Plus FormItem 组件原始 Props
|
|
33
|
+
* @extends {ElFormItemProps} Element Plus FormItem 组件原始 Props(包含事件处理器)
|
|
31
34
|
* @property {T} compType 使用的组件类型
|
|
32
|
-
* @property {FormItemCompPropsExtended<T>} [compProps] 传递给组件的 Props
|
|
35
|
+
* @property {FormItemCompPropsExtended<T>} [compProps] 传递给组件的 Props 配置对象(包含事件处理器和插槽,用于动态组件)
|
|
36
|
+
* @property {FormItemSlotsConfig} [slots] FormItem 插槽配置(用于 el-form-item 的插槽)
|
|
33
37
|
* @property {Condition} [vIf] 条件渲染控制,支持布尔值或接收表单数据的函数
|
|
34
38
|
* @property {Condition} [vShow] 显示/隐藏控制,支持布尔值或接收表单数据的函数
|
|
35
39
|
*
|
|
@@ -38,7 +42,8 @@ export type FormItemCompPropsExtended<T extends FormItemComp> = IsOptionsSupport
|
|
|
38
42
|
export interface FormItem<T extends FormItemComp = FormItemComp> extends ElFormItemProps {
|
|
39
43
|
prop: string
|
|
40
44
|
compType: T
|
|
41
|
-
compProps?: FormItemCompPropsExtended<T>
|
|
45
|
+
compProps?: FormItemCompPropsExtended<T> // 包含事件处理器和插槽(动态组件的事件和插槽)
|
|
46
|
+
slots?: FormItemSlotsConfig // FormItem 插槽配置
|
|
42
47
|
vIf?: Condition
|
|
43
48
|
vShow?: Condition
|
|
44
49
|
colProps?: ColProps
|
package/dist/types/scope.d.ts
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { VNode } from 'vue';
|
|
2
|
+
import { FormItemComp, FormItemCompSlots } from './comp';
|
|
3
|
+
import { ElFormItemSlots } from './el';
|
|
1
4
|
import { FormItem } from './form-item';
|
|
2
5
|
/**
|
|
3
6
|
* 表单项事件扩展参数
|
|
@@ -32,3 +35,30 @@ export interface FormItemSlotScope {
|
|
|
32
35
|
formItem: FormItem
|
|
33
36
|
[key: string]: any // 允许 el-form-item 的其他作用域参数
|
|
34
37
|
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 插槽渲染函数类型
|
|
41
|
+
*
|
|
42
|
+
* 允许返回 VNode 或 VNode[],兼容 h() 函数返回单个 VNode 的情况
|
|
43
|
+
* Vue 的 component :is 可以接受返回 VNode 或 VNode[] 的函数
|
|
44
|
+
* 用于插槽配置,提供比 Vue 的 Slot 类型更灵活的返回值支持
|
|
45
|
+
* 接受 FormItemSlotScope 参数(或扩展类型),包含 value、form、formItem 等属性
|
|
46
|
+
* 使用泛型支持扩展参数类型,如 FormItemSlotScope & { label: string } 用于 label 插槽
|
|
47
|
+
*/
|
|
48
|
+
export type SlotRenderFn<T extends FormItemSlotScope = FormItemSlotScope> = (props: T) => VNode | VNode[]
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* 动态组件插槽配置类型
|
|
52
|
+
*
|
|
53
|
+
* @template T - 组件类型
|
|
54
|
+
*/
|
|
55
|
+
export type CompSlotsConfig<T extends FormItemComp> = {
|
|
56
|
+
[K in keyof FormItemCompSlots<T>]?: SlotRenderFn
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* FormItem 插槽配置类型
|
|
61
|
+
*/
|
|
62
|
+
export type FormItemSlotsConfig = {
|
|
63
|
+
[K in keyof ElFormItemSlots]?: SlotRenderFn
|
|
64
|
+
}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@iswangh/element-plus-kit-form",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.2.
|
|
4
|
+
"version": "0.2.1",
|
|
5
5
|
"description": "Element Plus Kit 表单组件包",
|
|
6
6
|
"license": "Apache-2.0",
|
|
7
7
|
"sideEffects": [
|
|
@@ -32,7 +32,7 @@
|
|
|
32
32
|
},
|
|
33
33
|
"dependencies": {
|
|
34
34
|
"lodash-es": "^4.17.21",
|
|
35
|
-
"@iswangh/element-plus-kit-core": "0.2.
|
|
35
|
+
"@iswangh/element-plus-kit-core": "0.2.1"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
38
|
"@element-plus/icons-vue": "^2.3.2",
|