@lytjs/plugin-form 6.6.0 → 6.8.0
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/dist/index.d.cts +118 -0
- package/dist/index.d.ts +118 -0
- package/package.json +52 -52
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import * as _lytjs_core from '@lytjs/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @lytjs/plugin-form - 类型定义
|
|
5
|
+
*/
|
|
6
|
+
interface FieldValidationRule {
|
|
7
|
+
/** 校验类型 */
|
|
8
|
+
type: 'required' | 'email' | 'phone' | 'number' | 'min' | 'max' | 'minLength' | 'maxLength' | 'pattern' | 'custom';
|
|
9
|
+
/** 错误消息 */
|
|
10
|
+
message?: string;
|
|
11
|
+
/** 校验值(如 min/max 值等) */
|
|
12
|
+
value?: unknown;
|
|
13
|
+
/** 自定义校验函数 */
|
|
14
|
+
validator?: (value: unknown, allValues: Record<string, unknown>) => boolean | Promise<boolean>;
|
|
15
|
+
}
|
|
16
|
+
interface FieldConfig {
|
|
17
|
+
/** 字段初始值 */
|
|
18
|
+
initialValue?: unknown;
|
|
19
|
+
/** 校验规则 */
|
|
20
|
+
rules?: FieldValidationRule[];
|
|
21
|
+
/** 字段标签 */
|
|
22
|
+
label?: string;
|
|
23
|
+
/** 字段是否禁用 */
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
/** 字段是否只读 */
|
|
26
|
+
readOnly?: boolean;
|
|
27
|
+
}
|
|
28
|
+
interface FormConfig {
|
|
29
|
+
/** 字段配置 */
|
|
30
|
+
fields?: Record<string, FieldConfig>;
|
|
31
|
+
/** 初始值 */
|
|
32
|
+
initialValues?: Record<string, unknown>;
|
|
33
|
+
/** 是否在提交时校验 */
|
|
34
|
+
validateOnSubmit?: boolean;
|
|
35
|
+
/** 是否在字段变化时校验 */
|
|
36
|
+
validateOnChange?: boolean;
|
|
37
|
+
/** 是否在字段失焦时校验 */
|
|
38
|
+
validateOnBlur?: boolean;
|
|
39
|
+
}
|
|
40
|
+
interface FieldState {
|
|
41
|
+
/** 字段值 */
|
|
42
|
+
value: unknown;
|
|
43
|
+
/** 字段错误 */
|
|
44
|
+
errors: string[];
|
|
45
|
+
/** 字段是否被触碰过 */
|
|
46
|
+
touched: boolean;
|
|
47
|
+
/** 字段是否禁用 */
|
|
48
|
+
disabled: boolean;
|
|
49
|
+
/** 字段是否只读 */
|
|
50
|
+
readOnly: boolean;
|
|
51
|
+
/** 字段是否正在校验中 */
|
|
52
|
+
validating: boolean;
|
|
53
|
+
/** 字段是否校验通过 */
|
|
54
|
+
valid: boolean;
|
|
55
|
+
}
|
|
56
|
+
interface FormState {
|
|
57
|
+
/** 所有字段状态 */
|
|
58
|
+
fields: Record<string, FieldState>;
|
|
59
|
+
/** 表单是否正在提交 */
|
|
60
|
+
isSubmitting: boolean;
|
|
61
|
+
/** 表单是否有效 */
|
|
62
|
+
isValid: boolean;
|
|
63
|
+
/** 表单是否被触碰过 */
|
|
64
|
+
isTouched: boolean;
|
|
65
|
+
/** 表单是否正在校验 */
|
|
66
|
+
isValidating: boolean;
|
|
67
|
+
/** 表单是否被修改过 */
|
|
68
|
+
isDirty: boolean;
|
|
69
|
+
}
|
|
70
|
+
interface FormInstance {
|
|
71
|
+
/** 表单当前状态 */
|
|
72
|
+
readonly state: FormState;
|
|
73
|
+
/** 获取字段值 */
|
|
74
|
+
getValue: (name: string) => unknown;
|
|
75
|
+
/** 设置字段值 */
|
|
76
|
+
setValue: (name: string, value: unknown) => void;
|
|
77
|
+
/** 获取所有值 */
|
|
78
|
+
getValues: () => Record<string, unknown>;
|
|
79
|
+
/** 设置多个字段值 */
|
|
80
|
+
setValues: (values: Record<string, unknown>) => void;
|
|
81
|
+
/** 获取字段错误 */
|
|
82
|
+
getErrors: (name: string) => string[];
|
|
83
|
+
/** 设置字段错误 */
|
|
84
|
+
setErrors: (name: string, errors: string[]) => void;
|
|
85
|
+
/** 标记字段为已触碰 */
|
|
86
|
+
touchField: (name: string) => void;
|
|
87
|
+
/** 触碰所有字段 */
|
|
88
|
+
touchAllFields: () => void;
|
|
89
|
+
/** 重置表单 */
|
|
90
|
+
reset: () => void;
|
|
91
|
+
/** 重置为初始值 */
|
|
92
|
+
resetToInitial: () => void;
|
|
93
|
+
/** 校验单个字段 */
|
|
94
|
+
validateField: (name: string) => Promise<boolean>;
|
|
95
|
+
/** 校验整个表单 */
|
|
96
|
+
validate: () => Promise<boolean>;
|
|
97
|
+
/** 提交表单 */
|
|
98
|
+
submit: (callback?: (values: Record<string, unknown>) => void | Promise<void>) => Promise<boolean>;
|
|
99
|
+
/** 设置字段禁用状态 */
|
|
100
|
+
setFieldDisabled: (name: string, disabled: boolean) => void;
|
|
101
|
+
/** 设置字段只读状态 */
|
|
102
|
+
setFieldReadOnly: (name: string, readOnly: boolean) => void;
|
|
103
|
+
/** 获取字段配置 */
|
|
104
|
+
getFieldConfig: (name: string) => FieldConfig | undefined;
|
|
105
|
+
/** 注册新字段 */
|
|
106
|
+
registerField: (name: string, config?: FieldConfig) => void;
|
|
107
|
+
/** 注销字段 */
|
|
108
|
+
unregisterField: (name: string) => void;
|
|
109
|
+
}
|
|
110
|
+
interface FormOptions extends FormConfig {
|
|
111
|
+
/** 插件名称 */
|
|
112
|
+
name?: string;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
declare function createFormManager(options?: FormOptions): FormInstance;
|
|
116
|
+
declare const pluginForm: _lytjs_core.PluginDefinition<unknown>;
|
|
117
|
+
|
|
118
|
+
export { type FieldConfig, type FieldState, type FieldValidationRule, type FormInstance, type FormOptions, type FormState, createFormManager, pluginForm as default };
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import * as _lytjs_core from '@lytjs/core';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @lytjs/plugin-form - 类型定义
|
|
5
|
+
*/
|
|
6
|
+
interface FieldValidationRule {
|
|
7
|
+
/** 校验类型 */
|
|
8
|
+
type: 'required' | 'email' | 'phone' | 'number' | 'min' | 'max' | 'minLength' | 'maxLength' | 'pattern' | 'custom';
|
|
9
|
+
/** 错误消息 */
|
|
10
|
+
message?: string;
|
|
11
|
+
/** 校验值(如 min/max 值等) */
|
|
12
|
+
value?: unknown;
|
|
13
|
+
/** 自定义校验函数 */
|
|
14
|
+
validator?: (value: unknown, allValues: Record<string, unknown>) => boolean | Promise<boolean>;
|
|
15
|
+
}
|
|
16
|
+
interface FieldConfig {
|
|
17
|
+
/** 字段初始值 */
|
|
18
|
+
initialValue?: unknown;
|
|
19
|
+
/** 校验规则 */
|
|
20
|
+
rules?: FieldValidationRule[];
|
|
21
|
+
/** 字段标签 */
|
|
22
|
+
label?: string;
|
|
23
|
+
/** 字段是否禁用 */
|
|
24
|
+
disabled?: boolean;
|
|
25
|
+
/** 字段是否只读 */
|
|
26
|
+
readOnly?: boolean;
|
|
27
|
+
}
|
|
28
|
+
interface FormConfig {
|
|
29
|
+
/** 字段配置 */
|
|
30
|
+
fields?: Record<string, FieldConfig>;
|
|
31
|
+
/** 初始值 */
|
|
32
|
+
initialValues?: Record<string, unknown>;
|
|
33
|
+
/** 是否在提交时校验 */
|
|
34
|
+
validateOnSubmit?: boolean;
|
|
35
|
+
/** 是否在字段变化时校验 */
|
|
36
|
+
validateOnChange?: boolean;
|
|
37
|
+
/** 是否在字段失焦时校验 */
|
|
38
|
+
validateOnBlur?: boolean;
|
|
39
|
+
}
|
|
40
|
+
interface FieldState {
|
|
41
|
+
/** 字段值 */
|
|
42
|
+
value: unknown;
|
|
43
|
+
/** 字段错误 */
|
|
44
|
+
errors: string[];
|
|
45
|
+
/** 字段是否被触碰过 */
|
|
46
|
+
touched: boolean;
|
|
47
|
+
/** 字段是否禁用 */
|
|
48
|
+
disabled: boolean;
|
|
49
|
+
/** 字段是否只读 */
|
|
50
|
+
readOnly: boolean;
|
|
51
|
+
/** 字段是否正在校验中 */
|
|
52
|
+
validating: boolean;
|
|
53
|
+
/** 字段是否校验通过 */
|
|
54
|
+
valid: boolean;
|
|
55
|
+
}
|
|
56
|
+
interface FormState {
|
|
57
|
+
/** 所有字段状态 */
|
|
58
|
+
fields: Record<string, FieldState>;
|
|
59
|
+
/** 表单是否正在提交 */
|
|
60
|
+
isSubmitting: boolean;
|
|
61
|
+
/** 表单是否有效 */
|
|
62
|
+
isValid: boolean;
|
|
63
|
+
/** 表单是否被触碰过 */
|
|
64
|
+
isTouched: boolean;
|
|
65
|
+
/** 表单是否正在校验 */
|
|
66
|
+
isValidating: boolean;
|
|
67
|
+
/** 表单是否被修改过 */
|
|
68
|
+
isDirty: boolean;
|
|
69
|
+
}
|
|
70
|
+
interface FormInstance {
|
|
71
|
+
/** 表单当前状态 */
|
|
72
|
+
readonly state: FormState;
|
|
73
|
+
/** 获取字段值 */
|
|
74
|
+
getValue: (name: string) => unknown;
|
|
75
|
+
/** 设置字段值 */
|
|
76
|
+
setValue: (name: string, value: unknown) => void;
|
|
77
|
+
/** 获取所有值 */
|
|
78
|
+
getValues: () => Record<string, unknown>;
|
|
79
|
+
/** 设置多个字段值 */
|
|
80
|
+
setValues: (values: Record<string, unknown>) => void;
|
|
81
|
+
/** 获取字段错误 */
|
|
82
|
+
getErrors: (name: string) => string[];
|
|
83
|
+
/** 设置字段错误 */
|
|
84
|
+
setErrors: (name: string, errors: string[]) => void;
|
|
85
|
+
/** 标记字段为已触碰 */
|
|
86
|
+
touchField: (name: string) => void;
|
|
87
|
+
/** 触碰所有字段 */
|
|
88
|
+
touchAllFields: () => void;
|
|
89
|
+
/** 重置表单 */
|
|
90
|
+
reset: () => void;
|
|
91
|
+
/** 重置为初始值 */
|
|
92
|
+
resetToInitial: () => void;
|
|
93
|
+
/** 校验单个字段 */
|
|
94
|
+
validateField: (name: string) => Promise<boolean>;
|
|
95
|
+
/** 校验整个表单 */
|
|
96
|
+
validate: () => Promise<boolean>;
|
|
97
|
+
/** 提交表单 */
|
|
98
|
+
submit: (callback?: (values: Record<string, unknown>) => void | Promise<void>) => Promise<boolean>;
|
|
99
|
+
/** 设置字段禁用状态 */
|
|
100
|
+
setFieldDisabled: (name: string, disabled: boolean) => void;
|
|
101
|
+
/** 设置字段只读状态 */
|
|
102
|
+
setFieldReadOnly: (name: string, readOnly: boolean) => void;
|
|
103
|
+
/** 获取字段配置 */
|
|
104
|
+
getFieldConfig: (name: string) => FieldConfig | undefined;
|
|
105
|
+
/** 注册新字段 */
|
|
106
|
+
registerField: (name: string, config?: FieldConfig) => void;
|
|
107
|
+
/** 注销字段 */
|
|
108
|
+
unregisterField: (name: string) => void;
|
|
109
|
+
}
|
|
110
|
+
interface FormOptions extends FormConfig {
|
|
111
|
+
/** 插件名称 */
|
|
112
|
+
name?: string;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
declare function createFormManager(options?: FormOptions): FormInstance;
|
|
116
|
+
declare const pluginForm: _lytjs_core.PluginDefinition<unknown>;
|
|
117
|
+
|
|
118
|
+
export { type FieldConfig, type FieldState, type FieldValidationRule, type FormInstance, type FormOptions, type FormState, createFormManager, pluginForm as default };
|
package/package.json
CHANGED
|
@@ -1,52 +1,52 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "@lytjs/plugin-form",
|
|
3
|
-
"version": "6.
|
|
4
|
-
"description": "LytJS official form plugin for form state management, validation, and submission",
|
|
5
|
-
"type": "module",
|
|
6
|
-
"main": "./dist/index.cjs",
|
|
7
|
-
"module": "./dist/index.mjs",
|
|
8
|
-
"types": "./dist/index.d.ts",
|
|
9
|
-
"exports": {
|
|
10
|
-
".": {
|
|
11
|
-
"types": "./dist/index.d.ts",
|
|
12
|
-
"import": "./dist/index.mjs",
|
|
13
|
-
"require": "./dist/index.cjs"
|
|
14
|
-
},
|
|
15
|
-
"./package.json": "./package.json"
|
|
16
|
-
},
|
|
17
|
-
"files": [
|
|
18
|
-
"dist"
|
|
19
|
-
],
|
|
20
|
-
"sideEffects": false,
|
|
21
|
-
"scripts": {
|
|
22
|
-
"build": "tsup",
|
|
23
|
-
"dev": "tsup --watch",
|
|
24
|
-
"test": "vitest run",
|
|
25
|
-
"test:watch": "vitest",
|
|
26
|
-
"test:coverage": "vitest run --coverage",
|
|
27
|
-
"type-check": "tsc --noEmit",
|
|
28
|
-
"lint": "eslint \"src/**/*.ts\"",
|
|
29
|
-
"clean": "rm -rf dist"
|
|
30
|
-
},
|
|
31
|
-
"dependencies": {
|
|
32
|
-
"@lytjs/core": "workspace:*",
|
|
33
|
-
"@lytjs/reactivity": "workspace:*"
|
|
34
|
-
},
|
|
35
|
-
"devDependencies": {
|
|
36
|
-
"tsup": "^8.0.0",
|
|
37
|
-
"typescript": "^5.4.0",
|
|
38
|
-
"vitest": "^3.0.0"
|
|
39
|
-
},
|
|
40
|
-
"license": "MIT",
|
|
41
|
-
"repository": {
|
|
42
|
-
"type": "git",
|
|
43
|
-
"url": "https://gitee.com/lytjs/lytjs.git",
|
|
44
|
-
"directory": "packages/plugins/packages/plugin-form"
|
|
45
|
-
},
|
|
46
|
-
"keywords": [
|
|
47
|
-
"lytjs",
|
|
48
|
-
"form",
|
|
49
|
-
"validation",
|
|
50
|
-
"form-state"
|
|
51
|
-
]
|
|
52
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "@lytjs/plugin-form",
|
|
3
|
+
"version": "6.8.0",
|
|
4
|
+
"description": "LytJS official form plugin for form state management, validation, and submission",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./dist/index.cjs",
|
|
7
|
+
"module": "./dist/index.mjs",
|
|
8
|
+
"types": "./dist/index.d.ts",
|
|
9
|
+
"exports": {
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.mjs",
|
|
13
|
+
"require": "./dist/index.cjs"
|
|
14
|
+
},
|
|
15
|
+
"./package.json": "./package.json"
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
],
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"scripts": {
|
|
22
|
+
"build": "tsup",
|
|
23
|
+
"dev": "tsup --watch",
|
|
24
|
+
"test": "vitest run",
|
|
25
|
+
"test:watch": "vitest",
|
|
26
|
+
"test:coverage": "vitest run --coverage",
|
|
27
|
+
"type-check": "tsc --noEmit",
|
|
28
|
+
"lint": "eslint \"src/**/*.ts\"",
|
|
29
|
+
"clean": "rm -rf dist"
|
|
30
|
+
},
|
|
31
|
+
"dependencies": {
|
|
32
|
+
"@lytjs/core": "workspace:*",
|
|
33
|
+
"@lytjs/reactivity": "workspace:*"
|
|
34
|
+
},
|
|
35
|
+
"devDependencies": {
|
|
36
|
+
"tsup": "^8.0.0",
|
|
37
|
+
"typescript": "^5.4.0",
|
|
38
|
+
"vitest": "^3.0.0"
|
|
39
|
+
},
|
|
40
|
+
"license": "MIT",
|
|
41
|
+
"repository": {
|
|
42
|
+
"type": "git",
|
|
43
|
+
"url": "https://gitee.com/lytjs/lytjs.git",
|
|
44
|
+
"directory": "packages/plugins/packages/plugin-form"
|
|
45
|
+
},
|
|
46
|
+
"keywords": [
|
|
47
|
+
"lytjs",
|
|
48
|
+
"form",
|
|
49
|
+
"validation",
|
|
50
|
+
"form-state"
|
|
51
|
+
]
|
|
52
|
+
}
|