@iswangh/element-plus-kit-form 0.1.2 → 0.1.4

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 (42) hide show
  1. package/README.md +137 -4
  2. package/dist/FormAction.vue.d.ts +27 -1
  3. package/dist/FormAction.vue.d.ts.map +1 -1
  4. package/dist/FormItem.vue.d.ts.map +1 -1
  5. package/dist/composables/index.d.ts +3 -0
  6. package/dist/composables/index.d.ts.map +1 -0
  7. package/dist/composables/useAutoExpandOnHover.d.ts +15 -0
  8. package/dist/composables/useAutoExpandOnHover.d.ts.map +1 -0
  9. package/dist/composables/useChangeEventState.d.ts +35 -0
  10. package/dist/composables/useChangeEventState.d.ts.map +1 -0
  11. package/dist/config/action.d.ts +29 -0
  12. package/dist/config/action.d.ts.map +1 -0
  13. package/dist/config/component.d.ts +38 -0
  14. package/dist/config/component.d.ts.map +1 -0
  15. package/dist/config/form.d.ts +6 -0
  16. package/dist/config/form.d.ts.map +1 -0
  17. package/dist/config/index.d.ts +4 -64
  18. package/dist/config/index.d.ts.map +1 -1
  19. package/dist/config/scroll.d.ts +7 -0
  20. package/dist/config/scroll.d.ts.map +1 -0
  21. package/dist/index.d.ts +1 -1
  22. package/dist/index.d.ts.map +1 -1
  23. package/dist/index.js +630 -227
  24. package/dist/style.css +1 -1
  25. package/dist/types/action.d.ts +74 -0
  26. package/dist/types/common.d.ts +9 -0
  27. package/dist/types/el.d.ts +43 -0
  28. package/dist/types/form-item.d.ts +109 -0
  29. package/dist/types/index.d.ts +5 -125
  30. package/dist/types/index.d.ts.map +1 -1
  31. package/dist/types/options.d.ts +89 -0
  32. package/dist/utils/action.d.ts +10 -0
  33. package/dist/utils/action.d.ts.map +1 -0
  34. package/dist/utils/debounce.d.ts +25 -0
  35. package/dist/utils/debounce.d.ts.map +1 -0
  36. package/dist/utils/index.d.ts +5 -0
  37. package/dist/utils/index.d.ts.map +1 -0
  38. package/dist/utils/options.d.ts +21 -0
  39. package/dist/utils/options.d.ts.map +1 -0
  40. package/dist/utils/value.d.ts +27 -0
  41. package/dist/utils/value.d.ts.map +1 -0
  42. package/package.json +9 -12
@@ -0,0 +1,74 @@
1
+ import { ButtonProps } from 'element-plus';
2
+ /**
3
+ * 标准化的表单操作按钮配置项
4
+ *
5
+ * @extends {ButtonProps} el-button 的属性
6
+ * @property {string} label 按钮文字
7
+ * @property {string} eventName 事件名称
8
+ */
9
+ export interface ActionConfigButtonItem extends Partial<ButtonProps> {
10
+ label?: string
11
+ eventName: string
12
+ }
13
+
14
+ /**
15
+ * 表单操作按钮配置项
16
+ *
17
+ * 可以是标准化的按钮配置对象,也可以是预定义的按钮类型字符串
18
+ */
19
+ export type ActionConfigButtons = ActionConfigButtonItem | 'submit' | 'cancel' | 'search' | 'reset' | 'expand'
20
+
21
+ /**
22
+ * 展开规则基础配置
23
+ *
24
+ * **鼠标悬停自动展开**:
25
+ * - `autoExpandOnHover`:是否启用鼠标悬停自动展开功能
26
+ * - 当鼠标移入表单区域时自动展开(延迟 500ms)
27
+ * - 如果用户手动点击展开/收起按钮,则锁定状态,不再受鼠标移入影响
28
+ *
29
+ * **展开/收起后自动滚动**:
30
+ * - `scrollOnToggle`:是否在展开/收起后自动滚动到表单中心
31
+ * - 默认值为 false
32
+ * - 启用后,展开/收起动画完成后会自动滚动,使表单保持在页面中心
33
+ * - `scrollIntoViewOptions`:自定义滚动选项(仅在 `scrollOnToggle` 为 true 时生效)
34
+ * - 用于自定义 `scrollIntoView` 的行为(如 `block`、`behavior`、`inline` 等)
35
+ * - 默认值为 `{ behavior: 'smooth', block: 'center', inline: 'nearest' }`
36
+ * - 支持所有 `ScrollIntoViewOptions` 类型的选项配置
37
+ */
38
+ export interface ExpandRuleBase {
39
+ /** 是否启用鼠标悬停自动展开功能 */
40
+ autoExpandOnHover?: boolean
41
+ /** 是否在展开/收起后自动滚动到表单中心 */
42
+ scrollOnToggle?: boolean
43
+ /** 滚动选项配置(用于自定义 scrollIntoView 的行为) */
44
+ scrollIntoViewOptions?: ScrollIntoViewOptions
45
+ }
46
+
47
+ /**
48
+ * 默认展开规则(联合类型)
49
+ *
50
+ * 用于配置表单默认展开哪些字段,支持三种配置方式:
51
+ * - `count`:按字段数量展开(从第一个开始)
52
+ * - `include`:指定展示的字段(白名单,字段 prop 数组)
53
+ * - `exclude`:指定折叠的字段(黑名单,字段 prop 数组)
54
+ *
55
+ * **配置优先级**:`exclude` > `include` > `count`
56
+ */
57
+ export type ExpandRule
58
+ = | ({ count: number } & ExpandRuleBase)
59
+ | ({ include: string[] } & ExpandRuleBase)
60
+ | ({ exclude: string[] } & ExpandRuleBase)
61
+
62
+ /**
63
+ * 表单操作项配置
64
+ */
65
+ export interface ActionConfig {
66
+ /** 是否显示操作区域(支持函数动态判断) */
67
+ vIf?: boolean | ((data?: any) => boolean)
68
+ /** 是否显示操作区域(支持函数动态判断,使用 v-show) */
69
+ vShow?: boolean | ((data?: any) => boolean)
70
+ /** 操作按钮配置数组 */
71
+ buttons?: ActionConfigButtons[]
72
+ /** 默认展开规则(仅在 buttons 包含 'expand' 时生效) */
73
+ expand?: ExpandRule
74
+ }
@@ -0,0 +1,9 @@
1
+ import { FORM_ITEM_COMP_MAP } from '../config';
2
+ /** 允许数组类型 */
3
+ export type Arrayable<T> = T | T[]
4
+
5
+ /**
6
+ * 表单组件配置映射类型
7
+ * 共享类型定义,避免在多个文件中重复定义导致冲突
8
+ */
9
+ export type FormCompConfig = typeof FORM_ITEM_COMP_MAP
@@ -0,0 +1,43 @@
1
+ import { ElCol, ElRow, FormItemInstance, FormRules } from 'element-plus';
2
+ /**
3
+ * Element Plus Form Attributes
4
+ *
5
+ * 由于 `FormInstance['$slots']` 类型定义存在问题,
6
+ * 暂时无法直接使用 `FormInstance['$props']`,
7
+ * 因此手动定义了部分常用属性以确保类型安全。
8
+ *
9
+ * @see {@link https://element-plus.org/zh-CN/component/form.html#form-attributes Element Plus Form Attributes}
10
+ */
11
+ export interface ElFormAttrs {
12
+ // 数据相关
13
+ model?: Record<string, any>
14
+ rules?: FormRules
15
+
16
+ // 布局相关
17
+ inline?: boolean
18
+ labelPosition?: 'left' | 'right' | 'top'
19
+ labelWidth?: string | number
20
+ labelSuffix?: string
21
+
22
+ // 样式相关
23
+ size?: 'large' | 'default' | 'small'
24
+ disabled?: boolean
25
+ hideRequiredAsterisk?: boolean
26
+
27
+ // 验证相关
28
+ showMessage?: boolean
29
+ inlineMessage?: boolean
30
+ statusIcon?: boolean
31
+ validateOnRuleChange?: boolean
32
+ scrollToError?: boolean
33
+ scrollIntoViewOptions?: ScrollIntoViewOptions
34
+ }
35
+
36
+ /** Element Plus FormItem 属性 */
37
+ export type ElFormItemAttrs = FormItemInstance['$props']
38
+
39
+ /** Element Plus Row 组件属性 */
40
+ export type ElRowAttrs = InstanceType<typeof ElRow>['$props']
41
+
42
+ /** Element Plus Col 组件属性 */
43
+ export type ElColAttrs = InstanceType<typeof ElCol>['$props']
@@ -0,0 +1,109 @@
1
+ import { FormCompConfig } from './common';
2
+ import { ElColAttrs, ElFormItemAttrs, ElRowAttrs } from './el';
3
+ import { GetComponentOptionsType, InferOptionsType, IsOptionsSupported } from './options';
4
+ /** Row 布局属性(扩展自 Element Plus Row 组件属性) */
5
+ export type RowAttrs = ElRowAttrs & { span?: number }
6
+
7
+ /** Col 布局属性(Element Plus Col 组件属性) */
8
+ export type ColAttrs = ElColAttrs
9
+
10
+ /**
11
+ * 支持的表单组件枚举
12
+ *
13
+ * 显式定义所有可用的组件键名,确保类型提示正常工作
14
+ * 注意:由于 FORM_ITEM_COMP_MAP 使用了 Record<string, any> 避免类型推断超出限制,
15
+ * 我们需要显式定义键名类型,而不是从 typeof FORM_ITEM_COMP_MAP 中提取
16
+ */
17
+ export type FormItemComp
18
+ = | 'autocomplete'
19
+ | 'cascader'
20
+ | 'checkbox'
21
+ | 'color-picker'
22
+ | 'color-picker-panel'
23
+ | 'date-picker'
24
+ | 'date-picker-panel'
25
+ | 'input'
26
+ | 'input-number'
27
+ | 'input-tag'
28
+ | 'mention'
29
+ | 'radio'
30
+ | 'rate'
31
+ | 'select'
32
+ | 'select-v2'
33
+ | 'slider'
34
+ | 'switch'
35
+ | 'time-picker'
36
+ | 'time-select'
37
+ | 'transfer'
38
+ | 'tree-select'
39
+ | 'custom'
40
+
41
+ /**
42
+ * 根据组件类型推断对应的属性类型(排除事件处理器)
43
+ * @template T - 组件类型
44
+ */
45
+ export type FormItemCompAttrs<T extends FormItemComp = FormItemComp>
46
+ = Omit<InstanceType<FormCompConfig[T]>['$props'], `on${string}`>
47
+
48
+ /**
49
+ * 根据组件类型推断 options 类型
50
+ * 只有支持 options 的组件才会扩展 options 类型
51
+ * @template C - 组件类型
52
+ */
53
+ export type FormItemOptions<C extends FormItemComp> = IsOptionsSupported<C> extends true
54
+ ? InferOptionsType<C, GetComponentOptionsType<C>>
55
+ : never
56
+
57
+ /**
58
+ * FormItem 属性
59
+ *
60
+ * 扩展自 Element Plus 的 FormItem 组件属性,添加了自定义配置选项
61
+ *
62
+ * @template C - 组件类型
63
+ * @extends {ElFormItemAttrs} Element Plus FormItem 组件原始属性
64
+ * @property {C} comp 使用的组件类型
65
+ * @property {FormItemCompAttrs<C>} [compAttrs] 传递给组件的属性配置对象
66
+ * @property {boolean | ((data?: any) => boolean)} [vIf] 条件渲染控制,支持布尔值或接收表单数据的函数
67
+ * @property {boolean | ((data?: any) => boolean)} [vShow] 显示/隐藏控制,支持布尔值或接收表单数据的函数
68
+ *
69
+ * @see {@link https://element-plus.org/zh-CN/component/form.html#form-item-attributes Element Plus Form Item Attributes}
70
+ */
71
+ export interface FormItem<
72
+ C extends FormItemComp = FormItemComp,
73
+ > extends ElFormItemAttrs {
74
+ prop: string
75
+ comp: C
76
+ compAttrs?: IsOptionsSupported<C> extends true
77
+ ? FormItemCompAttrs<C> & { options?: FormItemOptions<C> } // 支持 options 的组件:直接覆盖 options 类型为扩展类型
78
+ : FormItemCompAttrs<C> // 不支持 options 的组件:使用原始属性类型
79
+ vIf?: boolean | ((data: Record<string, any>) => boolean)
80
+ vShow?: boolean | ((data: Record<string, any>) => boolean)
81
+ colAttrs?: ColAttrs
82
+ }
83
+
84
+ /** formItems 配置类型 - 推断每一项的 comp 对应的组件类型 */
85
+ export type FormItems = { [K in FormItemComp]: FormItem<K> }[FormItemComp][]
86
+
87
+ /**
88
+ * 事件拓展参数
89
+ * @template K 属性名类型
90
+ */
91
+ export interface EventExtendedParams<K = string> {
92
+ prop: K
93
+ index: number
94
+ formItem: FormItem
95
+ }
96
+
97
+ /**
98
+ * 表单项插槽作用域参数
99
+ *
100
+ * @property {any} value 当前表单项组件的值
101
+ * @property {Record<string, any>} form 表单数据
102
+ * @property {FormItem} formItem 表单项配置
103
+ */
104
+ export interface FormItemSlotScope {
105
+ value: any
106
+ form: Record<string, any>
107
+ formItem: FormItem
108
+ [key: string]: any // 允许 el-form-item 的其他作用域参数
109
+ }
@@ -1,126 +1,6 @@
1
- import { ButtonProps, ElCol, ElRow, FormItemInstance, FormRules } from 'element-plus';
2
- import { FORM_ITEM_COMP_MAP } from '../config';
3
- /**
4
- * Element Plus Form Attributes
5
- *
6
- * 由于 `FormInstance['$slots']` 类型定义存在问题,
7
- * 暂时无法直接使用 `FormInstance['$props']`,
8
- * 因此手动定义了部分常用属性以确保类型安全。
9
- *
10
- * @see {@link https://element-plus.org/zh-CN/component/form.html#form-attributes Element Plus Form Attributes}
11
- */
12
- export interface ElFormAttrs {
13
- model?: Record<string, any>;
14
- rules?: FormRules;
15
- inline?: boolean;
16
- labelPosition?: 'left' | 'right' | 'top';
17
- labelWidth?: string | number;
18
- labelSuffix?: string;
19
- size?: 'large' | 'default' | 'small';
20
- disabled?: boolean;
21
- hideRequiredAsterisk?: boolean;
22
- showMessage?: boolean;
23
- inlineMessage?: boolean;
24
- statusIcon?: boolean;
25
- validateOnRuleChange?: boolean;
26
- scrollToError?: boolean;
27
- scrollIntoViewOptions?: ScrollIntoViewOptions;
28
- }
29
- /** Element Plus FormItem 属性 */
30
- type ElFormItemAttrs = FormItemInstance['$props'];
31
- /**
32
- * 支持的表单组件枚举
33
- *
34
- * 显式定义所有可用的组件键名,确保类型提示正常工作
35
- * 注意:由于 FORM_ITEM_COMP_MAP 使用了 Record<string, any> 避免类型推断超出限制,
36
- * 我们需要显式定义键名类型,而不是从 typeof FORM_ITEM_COMP_MAP 中提取
37
- */
38
- export type FormItemComp = 'autocomplete' | 'cascader' | 'checkbox' | 'color-picker' | 'color-picker-panel' | 'date-picker' | 'date-picker-panel' | 'input' | 'input-number' | 'input-tag' | 'mention' | 'radio' | 'rate' | 'select' | 'select-v2' | 'slider' | 'switch' | 'time-picker' | 'time-select' | 'transfer' | 'tree-select' | 'custom';
39
- /** 表单组件配置映射类型 */
40
- type FormCompConfig = typeof FORM_ITEM_COMP_MAP;
41
- /**
42
- * 根据组件类型推断对应的属性类型(排除事件处理器)
43
- * @template T - 组件类型
44
- */
45
- export type FormItemCompAttrs<T extends FormItemComp = FormItemComp> = Omit<InstanceType<FormCompConfig[T]>['$props'], `on${string}`>;
46
- export type RowAttrs = InstanceType<typeof ElRow>['$props'] & {
47
- span?: number;
48
- };
49
- export type ColAttrs = InstanceType<typeof ElCol>['$props'];
50
- /**
51
- * FormItem 属性
52
- *
53
- * 扩展自 Element Plus 的 FormItem 组件属性,添加了自定义配置选项
54
- *
55
- * @template C - 组件类型
56
- * @extends {ElFormItemAttrs} Element Plus FormItem 组件原始属性
57
- * @property {C} comp 使用的组件类型
58
- * @property {FormItemCompAttrs<C>} [compAttrs] 传递给组件的属性配置对象
59
- * @property {boolean | ((data?: any) => boolean)} [vIf] 条件渲染控制,支持布尔值或接收表单数据的函数
60
- * @property {boolean | ((data?: any) => boolean)} [vShow] 显示/隐藏控制,支持布尔值或接收表单数据的函数
61
- *
62
- * @see {@link https://element-plus.org/zh-CN/component/form.html#form-item-attributes Element Plus Form Item Attributes}
63
- */
64
- export interface FormItem<C extends FormItemComp = FormItemComp> extends ElFormItemAttrs {
65
- prop: string;
66
- comp: C;
67
- compAttrs?: FormItemCompAttrs<C>;
68
- vIf?: boolean | ((data?: any) => boolean);
69
- vShow?: boolean | ((data?: any) => boolean);
70
- colAttrs?: ColAttrs;
71
- }
72
- /** formItems 配置类型 - 推断每一项的 comp 对应的组件类型 */
73
- export type FormItems = {
74
- [K in FormItemComp]: FormItem<K>;
75
- }[FormItemComp][];
76
- /**
77
- * 表单项插槽作用域参数
78
- *
79
- * @property {any} value 当前表单项组件的值
80
- * @property {Record<string, any>} form 表单数据
81
- * @property {FormItem} formItem 表单项配置
82
- */
83
- export interface FormItemSlotScope {
84
- value: any;
85
- form: Record<string, any>;
86
- formItem: FormItem;
87
- [key: string]: any;
88
- }
89
- /** 允许数组类型 */
90
- export type Arrayable<T> = T | T[];
91
- /**
92
- * 标准化的表单操作按钮配置项
93
- *
94
- * @extends {ButtonProps} el-button 的属性
95
- * @property {string} label 按钮文字
96
- * @property {string} eventName 事件名称
97
- */
98
- export interface ActionConfigButtonItem extends Partial<ButtonProps> {
99
- label?: string;
100
- eventName: string;
101
- }
102
- /** 表单操作按钮配置项 */
103
- export type ActionConfigButtons = ActionConfigButtonItem | 'submit' | 'cancel' | 'search' | 'reset';
104
- /**
105
- * 表单操作项配置
106
- *
107
- * @property {boolean | ((data?: any) => boolean)} vIf 是否显示
108
- * @property {boolean | ((data?: any) => boolean)} vShow 是否显示
109
- * @property {ActionConfigButtons[]} buttons 按钮列表
110
- */
111
- export interface ActionConfig {
112
- vIf?: boolean | ((data?: any) => boolean);
113
- vShow?: boolean | ((data?: any) => boolean);
114
- buttons?: ActionConfigButtons[];
115
- }
116
- /**
117
- * 事件拓展参数
118
- * @template K 属性名类型
119
- */
120
- export interface EventExtendedParams<K = string> {
121
- prop: K;
122
- index: number;
123
- formItem: FormItem;
124
- }
125
- export {};
1
+ export type * from './action';
2
+ export type * from './common';
3
+ export type * from './el';
4
+ export type * from './form-item';
5
+ export type * from './options';
126
6
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 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EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;IACzB,QAAQ,EAAE,QAAQ,CAAA;IAClB,CAAC,GAAG,EAAE,MAAM,GAAG,GAAG,CAAA;CACnB;AAED,aAAa;AACb,MAAM,MAAM,SAAS,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,EAAE,CAAA;AAElC;;;;;;GAMG;AACH,MAAM,WAAW,sBAAuB,SAAQ,OAAO,CAAC,WAAW,CAAC;IAClE,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,SAAS,EAAE,MAAM,CAAA;CAClB;AAED,iBAAiB;AACjB,MAAM,MAAM,mBAAmB,GAAG,sBAAsB,GAAG,QAAQ,GAAG,QAAQ,GAAG,QAAQ,GAAG,OAAO,CAAA;AAEnG;;;;;;GAMG;AACH,MAAM,WAAW,YAAY;IAC3B,GAAG,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,GAAG,KAAK,OAAO,CAAC,CAAA;IACzC,KAAK,CAAC,EAAE,OAAO,GAAG,CAAC,CAAC,IAAI,CAAC,EAAE,GAAG,KAAK,OAAO,CAAC,CAAA;IAC3C,OAAO,CAAC,EAAE,mBAAmB,EAAE,CAAA;CAChC;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB,CAAC,CAAC,GAAG,MAAM;IAC7C,IAAI,EAAE,CAAC,CAAA;IACP,KAAK,EAAE,MAAM,CAAA;IACb,QAAQ,EAAE,QAAQ,CAAA;CACnB"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/types/index.ts"],"names":[],"mappings":"AAAA,mBAAmB,UAAU,CAAA;AAC7B,mBAAmB,UAAU,CAAA;AAC7B,mBAAmB,MAAM,CAAA;AACzB,mBAAmB,aAAa,CAAA;AAChC,mBAAmB,WAAW,CAAA"}
@@ -0,0 +1,89 @@
1
+ import { FormCompConfig } from './common';
2
+ import { FormItemComp } from './form-item';
3
+ /**
4
+ * 检查组件类型是否包含 options 属性
5
+ * 通过检查组件实例的 $props 中是否包含 'options' 来判断
6
+ * @template C 组件类型
7
+ */
8
+ type HasOptionsProp<C extends FormItemComp> = 'options' extends keyof InstanceType<FormCompConfig[C]>['$props']
9
+ ? true
10
+ : false
11
+
12
+ /**
13
+ * 判断组件是否支持 options 属性
14
+ * 动态从组件类型定义中判断,不硬编码组件名称
15
+ * @template C 组件类型
16
+ */
17
+ export type IsOptionsSupported<C extends FormItemComp> = HasOptionsProp<C>
18
+
19
+ /**
20
+ * 支持 options 属性的组件类型
21
+ * 通过类型系统自动提取,不硬编码
22
+ */
23
+ export type OptionsSupportedComp = FormItemComp extends infer C
24
+ ? C extends FormItemComp
25
+ ? IsOptionsSupported<C> extends true
26
+ ? C
27
+ : never
28
+ : never
29
+ : never
30
+
31
+ /**
32
+ * Options 加载器函数类型
33
+ * @param formData 表单数据(外部依赖通过闭包访问)
34
+ * @returns 返回选项数组(支持同步和异步)
35
+ */
36
+ export type OptionsLoader = (formData: Record<string, any>) => any[] | Promise<any[]>
37
+
38
+ /**
39
+ * Options 对象模式配置
40
+ */
41
+ export interface OptionsConfig {
42
+ /**
43
+ * 选项加载器函数
44
+ * @param formData 表单数据(外部依赖通过闭包访问)
45
+ * @returns 返回选项数组(支持同步和异步)
46
+ */
47
+ loader: OptionsLoader
48
+ /**
49
+ * 是否立即加载(默认 false,需要显式设置为 true 才会立即加载)
50
+ */
51
+ immediate?: boolean
52
+ /**
53
+ * 依赖字段列表,需要监听并获取
54
+ * 支持内部依赖(表单字段),外部依赖通过闭包访问
55
+ */
56
+ deps?: string[]
57
+ }
58
+
59
+ /**
60
+ * 根据组件类型推断 options 类型
61
+ * @template C 组件类型
62
+ * @template T 组件实例类型
63
+ */
64
+ export type InferOptionsType<C extends FormItemComp, T = any> = IsOptionsSupported<C> extends true
65
+ ? T[] | OptionsLoader | OptionsConfig
66
+ : never
67
+
68
+ /**
69
+ * 获取组件原始的 options 类型
70
+ * 从组件实例的 $props 中提取 options 属性的类型
71
+ * @template C 组件类型
72
+ */
73
+ export type GetComponentOptionsType<C extends FormItemComp> = IsOptionsSupported<C> extends true
74
+ ? InstanceType<FormCompConfig[C]>['$props']['options']
75
+ : never
76
+
77
+ /**
78
+ * 检查组件类型是否包含 loading 属性
79
+ * @template C 组件类型
80
+ */
81
+ type HasLoadingProp<C extends FormItemComp> = 'loading' extends keyof InstanceType<FormCompConfig[C]>['$props']
82
+ ? true
83
+ : false
84
+
85
+ /**
86
+ * 判断组件是否支持 loading 属性
87
+ * @template C 组件类型
88
+ */
89
+ export type IsLoadingSupported<C extends FormItemComp> = HasLoadingProp<C>
@@ -0,0 +1,10 @@
1
+ import { ActionConfigButtons } from '../types';
2
+ /**
3
+ * 判断按钮列表中是否包含指定的事件名
4
+ *
5
+ * @param buttons - 按钮配置数组
6
+ * @param eventName - 事件名称
7
+ * @returns 是否包含该事件名
8
+ */
9
+ export declare function hasButtonEvent(buttons: ActionConfigButtons[] | string[] | undefined, eventName: string): boolean;
10
+ //# sourceMappingURL=action.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"action.d.ts","sourceRoot":"","sources":["../../src/utils/action.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,UAAU,CAAA;AAEnD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,mBAAmB,EAAE,GAAG,MAAM,EAAE,GAAG,SAAS,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAIhH"}
@@ -0,0 +1,25 @@
1
+ /**
2
+ * @file debounce.ts
3
+ * @description 防抖工具函数
4
+ */
5
+ /**
6
+ * 防抖函数
7
+ *
8
+ * @param fn - 要防抖的函数
9
+ * @param delay - 延迟时间(毫秒),默认 100ms
10
+ * @returns 防抖后的函数
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * const debouncedFn = debounce(() => {
15
+ * console.log('执行防抖函数')
16
+ * }, 300)
17
+ *
18
+ * // 频繁调用时,只会在最后一次调用后 300ms 执行
19
+ * debouncedFn()
20
+ * debouncedFn()
21
+ * debouncedFn() // 只有这一次会执行
22
+ * ```
23
+ */
24
+ export declare function debounce<T extends (...args: any[]) => any>(fn: T, delay?: number): (...args: Parameters<T>) => void;
25
+ //# sourceMappingURL=debounce.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"debounce.d.ts","sourceRoot":"","sources":["../../src/utils/debounce.ts"],"names":[],"mappings":"AACA;;;GAGG;AAEH;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,QAAQ,CAAC,CAAC,SAAS,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,KAAK,GAAG,EACxD,EAAE,EAAE,CAAC,EACL,KAAK,SAAM,GACV,CAAC,GAAG,IAAI,EAAE,UAAU,CAAC,CAAC,CAAC,KAAK,IAAI,CAYlC"}
@@ -0,0 +1,5 @@
1
+ export * from './action';
2
+ export * from './debounce';
3
+ export * from './options';
4
+ export * from './value';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,YAAY,CAAA;AAC1B,cAAc,WAAW,CAAA;AACzB,cAAc,SAAS,CAAA"}
@@ -0,0 +1,21 @@
1
+ import { OptionsConfig } from '../types';
2
+ /**
3
+ * 处理依赖列表:排除自身并去重
4
+ * @param deps 依赖字段列表
5
+ * @param currentProp 当前字段名,用于排除自己
6
+ */
7
+ export declare function processDeps(deps: string[], currentProp?: string): string[];
8
+ /**
9
+ * 获取依赖值
10
+ * @param deps 依赖字段列表
11
+ * @param formData 表单数据(外部依赖通过闭包访问)
12
+ * @param currentProp 当前字段名,用于排除自己
13
+ */
14
+ export declare function getDepsValues(deps: string[], formData: Record<string, any>, currentProp?: string): Record<string, any>;
15
+ /**
16
+ * 检查是否为对象模式的 options 配置
17
+ * @param options - 待检查的选项配置
18
+ * @returns 是否为对象模式配置
19
+ */
20
+ export declare function isOptionsConfig(options: any): options is OptionsConfig;
21
+ //# sourceMappingURL=options.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../../src/utils/options.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,UAAU,CAAA;AAE7C;;;;GAIG;AACH,wBAAgB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,EAAE,CAO1E;AAED;;;;;GAKG;AACH,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,EAAE,WAAW,CAAC,EAAE,MAAM,GAAG,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAOtH;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,IAAI,aAAa,CAEtE"}
@@ -0,0 +1,27 @@
1
+ /**
2
+ * 检查值是否为空
3
+ */
4
+ export declare function isEmpty(val: any): boolean;
5
+ /**
6
+ * 检查当前值是否在新的选项中
7
+ * 用于判断是否需要自动清理值:如果值在新的选项中,保留;否则清理
8
+ * @param currentValue - 当前值
9
+ * @param options - 选项数组
10
+ * @returns 是否在选项中(true 表示在选项中,不需要清理;false 表示不在,需要清理)
11
+ */
12
+ export declare function checkValueInOptions(currentValue: any, options: any[]): boolean;
13
+ /**
14
+ * 深拷贝值(仅对对象和数组)
15
+ *
16
+ * @param value - 要深拷贝的值
17
+ * @returns 深拷贝后的值
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * const obj = { a: 1, b: { c: 2 } }
22
+ * const cloned = deepCloneValue(obj)
23
+ * cloned.b.c = 3 // 不会影响原对象
24
+ * ```
25
+ */
26
+ export declare function deepCloneValue<T = Record<string, unknown>>(value: T): T;
27
+ //# sourceMappingURL=value.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"value.d.ts","sourceRoot":"","sources":["../../src/utils/value.ts"],"names":[],"mappings":"AAEA;;GAEG;AACH,wBAAgB,OAAO,CAAC,GAAG,EAAE,GAAG,GAAG,OAAO,CAEzC;AAED;;;;;;GAMG;AACH,wBAAgB,mBAAmB,CAAC,YAAY,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,OAAO,CAa9E;AAED;;;;;;;;;;;;GAYG;AACH,wBAAgB,cAAc,CAAC,CAAC,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,CAAC,CAMvE"}
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.1.2",
4
+ "version": "0.1.4",
5
5
  "description": "Element Plus Kit 表单组件包",
6
6
  "license": "Apache-2.0",
7
7
  "sideEffects": [
@@ -31,18 +31,18 @@
31
31
  "vue": "^3.5.23"
32
32
  },
33
33
  "dependencies": {
34
- "@iswangh/element-plus-kit-core": "0.1.2"
34
+ "@iswangh/element-plus-kit-core": "0.1.3"
35
35
  },
36
36
  "devDependencies": {
37
37
  "@element-plus/icons-vue": "^2.3.2",
38
38
  "@vitejs/plugin-vue": "^6.0.1",
39
- "element-plus": "^2.11.7",
40
- "sass": "^1.93.3",
41
- "typescript": "^5.9.2",
42
- "vite": "^7.1.5",
39
+ "element-plus": "^2.11.8",
40
+ "sass": "^1.94.0",
41
+ "typescript": "^5.9.3",
42
+ "vite": "^7.2.2",
43
43
  "vite-plugin-dts": "^4.5.4",
44
- "vue": "^3.5.23",
45
- "vue-tsc": "^3.0.7"
44
+ "vue": "^3.5.24",
45
+ "vue-tsc": "^3.1.3"
46
46
  },
47
47
  "publishConfig": {
48
48
  "access": "public"
@@ -50,9 +50,6 @@
50
50
  "scripts": {
51
51
  "build": "vite build",
52
52
  "dev": "vite build --watch",
53
- "type-check": "vue-tsc --noEmit",
54
- "version:patch": "pnpm version patch --no-git-tag-version",
55
- "version:minor": "pnpm version minor --no-git-tag-version",
56
- "version:major": "pnpm version major --no-git-tag-version"
53
+ "type-check": "vue-tsc --noEmit"
57
54
  }
58
55
  }