@iswangh/element-plus-kit-form 0.2.1 → 0.3.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.
@@ -1,5 +1,5 @@
1
- import { ElAutocomplete, ElCascader, ElCheckboxGroup, ElColorPicker, ElColorPickerPanel, ElDatePicker, ElDatePickerPanel, ElInput, ElInputNumber, ElInputTag, ElMention, ElRadioGroup, ElRate, ElSelect, ElSelectV2, ElSlider, ElSwitch, ElTimePicker, ElTimeSelect, ElTransfer, ElTreeSelect } from 'element-plus';
2
- import { EXPAND_COMP_MAP } from '../config';
1
+ import { WCheckTag } from '@iswangh/element-plus-kit-tag';
2
+ import { ElAutocomplete, ElCascader, ElCheckbox, ElCheckboxGroup, ElColorPicker, ElColorPickerPanel, ElDatePicker, ElDatePickerPanel, ElInput, ElInputNumber, ElInputTag, ElMention, ElRadioGroup, ElRate, ElSelect, ElSelectV2, ElSlider, ElSwitch, ElTimePicker, ElTimeSelect, ElTransfer, ElTreeSelect } from 'element-plus';
3
3
  /**
4
4
  * Element Plus 组件映射类型
5
5
  *
@@ -9,7 +9,8 @@ import { EXPAND_COMP_MAP } from '../config';
9
9
  interface ElCompMap {
10
10
  readonly 'autocomplete': typeof ElAutocomplete
11
11
  readonly 'cascader': typeof ElCascader
12
- readonly 'checkbox': typeof ElCheckboxGroup
12
+ readonly 'checkbox': typeof ElCheckbox
13
+ readonly 'checkbox-group': typeof ElCheckboxGroup
13
14
  readonly 'color-picker-panel': typeof ElColorPickerPanel
14
15
  readonly 'color-picker': typeof ElColorPicker
15
16
  readonly 'date-picker-panel': typeof ElDatePickerPanel
@@ -18,7 +19,7 @@ interface ElCompMap {
18
19
  readonly 'input-number': typeof ElInputNumber
19
20
  readonly 'input-tag': typeof ElInputTag
20
21
  readonly 'mention': typeof ElMention
21
- readonly 'radio': typeof ElRadioGroup
22
+ readonly 'radio-group': typeof ElRadioGroup
22
23
  readonly 'rate': typeof ElRate
23
24
  readonly 'select': typeof ElSelect
24
25
  readonly 'select-v2': typeof ElSelectV2
@@ -30,17 +31,28 @@ interface ElCompMap {
30
31
  readonly 'tree-select': typeof ElTreeSelect
31
32
  }
32
33
 
34
+ /**
35
+ * 扩展组件映射类型
36
+ *
37
+ * 手动定义扩展组件的类型映射,确保类型提示正常工作
38
+ * 与 comp.ts 中的 EXPAND_COMP_MAP 保持同步
39
+ */
40
+ interface ExpandCompMap {
41
+ readonly 'custom': typeof HTMLDivElement
42
+ readonly 'w-check-tag': typeof WCheckTag
43
+ }
44
+
33
45
  /**
34
46
  * 表单组件配置映射类型
35
47
  *
36
48
  * 合并 Element Plus 组件映射和扩展组件映射的类型
37
49
  * - ElCompMap: 手动定义,避免类型推断超出限制
38
- * - typeof EXPAND_COMP_MAP: 从运行时值提取类型(简单映射,不会超出限制)
50
+ * - ExpandCompMap: 手动定义扩展组件类型,确保类型提示正常工作
39
51
  *
40
52
  * 注意:不使用 typeof FORM_ITEM_COMP_MAP,因为 FORM_ITEM_COMP_MAP 使用了
41
53
  * Record<string, any> 避免类型推断超出编译器序列化限制
42
54
  */
43
- export type FormCompConfig = ElCompMap & typeof EXPAND_COMP_MAP
55
+ export type FormCompConfig = ElCompMap & ExpandCompMap
44
56
 
45
57
  /**
46
58
  * 支持的表单组件枚举
@@ -49,30 +61,31 @@ export type FormCompConfig = ElCompMap & typeof EXPAND_COMP_MAP
49
61
  * 注意:由于 FORM_ITEM_COMP_MAP 使用了 Record<string, any> 避免类型推断超出限制,
50
62
  * 我们需要显式定义键名类型,而不是从 typeof FORM_ITEM_COMP_MAP 中提取
51
63
  */
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
-
64
+ export type FormItemComp
65
+ = 'autocomplete'
66
+ | 'cascader'
67
+ | 'checkbox'
68
+ | 'checkbox-group'
69
+ | 'color-picker'
70
+ | 'color-picker-panel'
71
+ | 'date-picker'
72
+ | 'date-picker-panel'
73
+ | 'input'
74
+ | 'input-number'
75
+ | 'input-tag'
76
+ | 'mention'
77
+ | 'radio-group'
78
+ | 'rate'
79
+ | 'select'
80
+ | 'select-v2'
81
+ | 'slider'
82
+ | 'switch'
83
+ | 'time-picker'
84
+ | 'time-select'
85
+ | 'transfer'
86
+ | 'tree-select'
87
+ | 'custom'
88
+ | 'w-check-tag'
76
89
  /**
77
90
  * 根据组件类型获取组件实例类型
78
91
  * @template T 组件类型
@@ -1,30 +1,16 @@
1
1
  import { ElCol, ElRow, FormItemInstance, FormRules } from 'element-plus';
2
- /**
3
- * Element Plus Form Props
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
- */
2
+ /** Element Plus Form Props */
11
3
  export interface ElFormProps {
12
- // 数据相关
13
4
  model?: Record<string, any>
14
5
  rules?: FormRules
15
-
16
- // 布局相关
17
6
  inline?: boolean
18
7
  labelPosition?: 'left' | 'right' | 'top'
19
8
  labelWidth?: string | number
20
9
  labelSuffix?: string
21
-
22
- // 样式相关
23
10
  size?: 'large' | 'default' | 'small'
24
11
  disabled?: boolean
25
12
  hideRequiredAsterisk?: boolean
26
-
27
- // 验证相关
13
+ requireAsteriskPosition?: 'left' | 'right'
28
14
  showMessage?: boolean
29
15
  inlineMessage?: boolean
30
16
  statusIcon?: boolean
@@ -2,25 +2,16 @@ import { Condition } from './common';
2
2
  import { FormItemComp, FormItemCompProps } from './comp';
3
3
  import { ElFormItemProps } from './el';
4
4
  import { ColProps } from './layout';
5
- import { InferOptionsType, IsOptionsSupported } from './options';
5
+ import { HasOptionsProp, OptionsLoaderType } from './options';
6
6
  import { CompSlotsConfig, FormItemSlotsConfig } from './scope';
7
- /**
8
- * 根据组件类型推断 options 类型
9
- * 只有支持 options 的组件才会扩展 options 类型
10
- * @template T - 组件类型
11
- */
12
- export type FormItemOptions<T extends FormItemComp> = IsOptionsSupported<T> extends true
13
- ? InferOptionsType<T>
14
- : never
15
-
16
7
  /**
17
8
  * 根据组件类型推断 compProps 类型(扩展版本)
18
- * 支持扩展属性,如 options、slots 等
9
+ * 支持扩展属性,如 options、optionsLoader、slots 等
19
10
  * @template T - 组件类型
20
11
  */
21
12
  export type FormItemCompPropsExtended<T extends FormItemComp>
22
- = (IsOptionsSupported<T> extends true
23
- ? Omit<FormItemCompProps<T>, 'options'> & { options?: FormItemOptions<T> }
13
+ = (HasOptionsProp<T> extends true
14
+ ? FormItemCompProps<T> & { optionsLoader?: OptionsLoaderType }
24
15
  : FormItemCompProps<T>)
25
16
  & { slots?: CompSlotsConfig<T> }
26
17
 
@@ -1,9 +1,8 @@
1
- export type * from './action';
2
- export type * from './common';
3
- export type * from './comp';
4
- export type * from './el';
5
- export type * from './form-item';
6
- export type * from './layout';
7
- export type * from './options';
8
- export type * from './scope';
9
- //# sourceMappingURL=index.d.ts.map
1
+ export * from './action'
2
+ export * from './common'
3
+ export * from './comp'
4
+ export * from './el'
5
+ export * from './form-item'
6
+ export * from './layout'
7
+ export * from './options'
8
+ export * from './scope'
@@ -4,70 +4,11 @@ import { FormItemComp, FormItemCompProps } from './comp';
4
4
  * 通过检查组件实例的 $props 中是否包含 'options' 来判断
5
5
  * @template T 组件类型
6
6
  */
7
- type HasOptionsProp<T extends FormItemComp> = 'options' extends keyof FormItemCompProps<T>
7
+ export type HasOptionsProp<T extends FormItemComp> = 'options' extends keyof FormItemCompProps<T>
8
8
  ? true
9
9
  : false
10
10
 
11
11
  /**
12
- * 判断组件是否支持 options 属性
13
- * 动态从组件类型定义中判断,不硬编码组件名称
14
- * @template T 组件类型
15
- */
16
- export type IsOptionsSupported<T extends FormItemComp> = HasOptionsProp<T>
17
-
18
- /**
19
- * 支持 options 属性的组件类型
20
- * 通过类型系统自动提取,不硬编码
21
- */
22
- export type OptionsSupportedComp = FormItemComp extends infer T
23
- ? T extends FormItemComp
24
- ? IsOptionsSupported<T> extends true
25
- ? T
26
- : never
27
- : never
28
- : never
29
-
30
- /**
31
- * Options 加载器函数类型
32
- * @param formData 表单数据(外部依赖通过闭包访问)
33
- * @returns 返回选项数组(支持同步和异步)
34
- */
35
- export type OptionsLoader = (formData: Record<string, any>) => any[] | Promise<any[]>
36
-
37
- /**
38
- * Options 对象模式配置
39
- */
40
- export interface OptionsConfig {
41
- /**
42
- * 选项加载器函数
43
- * @param formData 表单数据(外部依赖通过闭包访问)
44
- * @returns 返回选项数组(支持同步和异步)
45
- */
46
- loader: OptionsLoader
47
- /**
48
- * 是否立即加载(默认 false,需要显式设置为 true 才会立即加载)
49
- */
50
- immediate?: boolean
51
- /**
52
- * 依赖字段列表,需要监听并获取
53
- * 支持内部依赖(表单字段),外部依赖通过闭包访问
54
- */
55
- deps?: string[]
56
- }
57
-
58
- /**
59
- * 根据组件类型推断 options 类型
60
- * @template T 组件类型
61
- */
62
- export type InferOptionsType<T extends FormItemComp> = IsOptionsSupported<T> extends true
63
- ? OptionsLoader | OptionsConfig | any[]
64
- : never
65
-
66
- /**
67
- * 获取组件原始的 options 类型
68
- * 从组件实例的 $props 中提取 options 属性的类型
69
- * @template T 组件类型
12
+ * OptionsLoader 类型
70
13
  */
71
- export type GetCompOptionsType<T extends FormItemComp> = IsOptionsSupported<T> extends true
72
- ? FormItemCompProps<T>['options']
73
- : never
14
+ export type OptionsLoaderType = (formData?: Record<string, any>) => any[] | Promise<any[]>
@@ -1 +1 @@
1
- {"version":3,"file":"action.d.ts","sourceRoot":"","sources":["../../src/utils/action.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAEjD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,iBAAiB,EAAE,GAAG,MAAM,EAAE,GAAG,SAAS,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAI9G"}
1
+ {"version":3,"file":"action.d.ts","sourceRoot":"","sources":["../../src/utils/action.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,UAAU,CAAA;AAEjD;;;;;;GAMG;AACH,wBAAgB,cAAc,CAAC,OAAO,EAAE,iBAAiB,EAAE,GAAG,MAAM,EAAE,GAAG,SAAS,EAAE,SAAS,EAAE,MAAM,GAAG,OAAO,CAE9G"}
@@ -1,5 +1,3 @@
1
1
  export * from './action';
2
2
  export * from './lodash';
3
- export * from './options';
4
- export * from './value';
5
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,UAAU,CAAA;AACxB,cAAc,WAAW,CAAA;AACzB,cAAc,SAAS,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,UAAU,CAAA;AACxB,cAAc,UAAU,CAAA"}
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.1",
4
+ "version": "0.3.1",
5
5
  "description": "Element Plus Kit 表单组件包",
6
6
  "license": "Apache-2.0",
7
7
  "sideEffects": [
@@ -31,23 +31,25 @@
31
31
  "vue": "^3.5.23"
32
32
  },
33
33
  "dependencies": {
34
- "lodash-es": "^4.17.21",
35
- "@iswangh/element-plus-kit-core": "0.2.1"
34
+ "lodash-es": "^4.17.22",
35
+ "@iswangh/element-plus-kit-tag": "0.0.2",
36
+ "@iswangh/element-plus-kit-core": "0.2.2"
36
37
  },
37
38
  "devDependencies": {
38
39
  "@element-plus/icons-vue": "^2.3.2",
39
40
  "@types/lodash-es": "^4.17.12",
40
- "@vitejs/plugin-vue": "^6.0.1",
41
- "element-plus": "^2.11.8",
42
- "sass": "^1.94.0",
41
+ "@vitejs/plugin-vue": "^6.0.3",
42
+ "element-plus": "^2.13.0",
43
+ "sass": "^1.97.1",
43
44
  "typescript": "^5.9.3",
44
- "vite": "^7.2.2",
45
+ "vite": "^7.3.0",
45
46
  "vite-plugin-dts": "^4.5.4",
46
- "vue": "^3.5.24",
47
- "vue-tsc": "^3.1.3"
47
+ "vue": "^3.5.26",
48
+ "vue-tsc": "^3.2.1"
48
49
  },
49
50
  "publishConfig": {
50
- "access": "public"
51
+ "access": "public",
52
+ "registry": "https://registry.npmjs.org/"
51
53
  },
52
54
  "scripts": {
53
55
  "build": "vite build",
@@ -1,17 +0,0 @@
1
- /**
2
- * 清理状态管理组合式函数
3
- * 用于管理依赖变更时的清理操作,支持用户在 change 事件中设置默认值
4
- */
5
- export declare function useClearState(): {
6
- /** 是否正在处理依赖变更 */
7
- readonly changing: boolean;
8
- /** 用户是否在 change 事件中设置了值 */
9
- readonly hasUserValue: boolean;
10
- /** 开始依赖变更处理 */
11
- start(): void;
12
- /** 结束依赖变更处理 */
13
- end(): void;
14
- /** 标记用户在 change 事件中设置了值 */
15
- markValue(): void;
16
- };
17
- //# sourceMappingURL=useClearState.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"useClearState.d.ts","sourceRoot":"","sources":["../../src/composables/useClearState.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,wBAAgB,aAAa;IAKzB,iBAAiB;;IAKjB,2BAA2B;;IAK3B,eAAe;;IAMf,eAAe;;IAMf,2BAA2B;;EAK9B"}
@@ -1 +0,0 @@
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,QAAQ,CAAA;AAC3B,mBAAmB,MAAM,CAAA;AACzB,mBAAmB,aAAa,CAAA;AAChC,mBAAmB,UAAU,CAAA;AAC7B,mBAAmB,WAAW,CAAA;AAC9B,mBAAmB,SAAS,CAAA"}
@@ -1,21 +0,0 @@
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
@@ -1 +0,0 @@
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,CAGtH;AAED;;;;GAIG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,GAAG,GAAG,OAAO,IAAI,aAAa,CAEtE"}
@@ -1,21 +0,0 @@
1
- /**
2
- * 检查值是否在选项中的参数
3
- */
4
- export interface CheckValueInOptionsParams {
5
- /** 当前值(支持单个值或数组值) */
6
- modelValue: any;
7
- /** 选项数组 */
8
- options: any[];
9
- /** 表单项配置,用于获取组件类型等信息 */
10
- formItem: {
11
- compType: string;
12
- };
13
- }
14
- /**
15
- * 检查当前值是否在新的选项中
16
- * 用于判断是否需要自动清理值:如果值在新的选项中,保留;否则清理
17
- * @param params - 检查参数
18
- * @returns 是否在选项中(true 表示在选项中,不需要清理;false 表示不在,需要清理)
19
- */
20
- export declare function checkValueInOptions(params: CheckValueInOptionsParams): boolean;
21
- //# sourceMappingURL=value.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"value.d.ts","sourceRoot":"","sources":["../../src/utils/value.ts"],"names":[],"mappings":"AAGA;;GAEG;AACH,MAAM,WAAW,yBAAyB;IACxC,qBAAqB;IACrB,UAAU,EAAE,GAAG,CAAA;IACf,WAAW;IACX,OAAO,EAAE,GAAG,EAAE,CAAA;IACd,wBAAwB;IACxB,QAAQ,EAAE;QAAE,QAAQ,EAAE,MAAM,CAAA;KAAE,CAAA;CAC/B;AA4BD;;;;;GAKG;AACH,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,yBAAyB,GAAG,OAAO,CA+B9E"}