@coding-form/form-engine 0.0.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 (67) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +23 -0
  3. package/dist/context/form-context.d.ts +25 -0
  4. package/dist/context/form-context.js +44 -0
  5. package/dist/context/index.d.ts +1 -0
  6. package/dist/context/index.js +1 -0
  7. package/dist/event/event-context.d.ts +10 -0
  8. package/dist/event/event-context.js +35 -0
  9. package/dist/event/index.d.ts +1 -0
  10. package/dist/event/index.js +1 -0
  11. package/dist/factory/index.d.ts +13 -0
  12. package/dist/factory/index.js +51 -0
  13. package/dist/form/index.d.ts +8 -0
  14. package/dist/form/index.js +37 -0
  15. package/dist/form/sub-view.d.ts +8 -0
  16. package/dist/form/sub-view.js +29 -0
  17. package/dist/hooks/create-form-instance.d.ts +3 -0
  18. package/dist/hooks/create-form-instance.js +3 -0
  19. package/dist/hooks/index.d.ts +3 -0
  20. package/dist/hooks/index.js +3 -0
  21. package/dist/hooks/register-form-items.d.ts +8 -0
  22. package/dist/hooks/register-form-items.js +14 -0
  23. package/dist/hooks/use-form-context.d.ts +7 -0
  24. package/dist/hooks/use-form-context.js +42 -0
  25. package/dist/index.d.ts +10 -0
  26. package/dist/index.js +10 -0
  27. package/dist/instance/control.d.ts +14 -0
  28. package/dist/instance/control.js +40 -0
  29. package/dist/instance/index.d.ts +24 -0
  30. package/dist/instance/index.js +72 -0
  31. package/dist/layout/default-layout.d.ts +5 -0
  32. package/dist/layout/default-layout.js +10 -0
  33. package/dist/layout/index.d.ts +8 -0
  34. package/dist/layout/index.js +35 -0
  35. package/dist/presenters/form-presenter.d.ts +14 -0
  36. package/dist/presenters/form-presenter.js +124 -0
  37. package/dist/presenters/index.d.ts +1 -0
  38. package/dist/presenters/index.js +1 -0
  39. package/dist/register/form.d.ts +11 -0
  40. package/dist/register/form.js +20 -0
  41. package/dist/register/index.d.ts +2 -0
  42. package/dist/register/index.js +2 -0
  43. package/dist/register/layout.d.ts +10 -0
  44. package/dist/register/layout.js +18 -0
  45. package/dist/store/index.d.ts +15 -0
  46. package/dist/store/index.js +24 -0
  47. package/dist/types/dispatch.d.ts +4 -0
  48. package/dist/types/dispatch.js +0 -0
  49. package/dist/types/event.d.ts +10 -0
  50. package/dist/types/event.js +0 -0
  51. package/dist/types/index.d.ts +8 -0
  52. package/dist/types/index.js +8 -0
  53. package/dist/types/item.d.ts +31 -0
  54. package/dist/types/item.js +0 -0
  55. package/dist/types/layout.d.ts +17 -0
  56. package/dist/types/layout.js +0 -0
  57. package/dist/types/state.d.ts +10 -0
  58. package/dist/types/state.js +5 -0
  59. package/dist/types/types.d.ts +16 -0
  60. package/dist/types/types.js +23 -0
  61. package/dist/types/validate.d.ts +11 -0
  62. package/dist/types/validate.js +0 -0
  63. package/dist/types/view.d.ts +80 -0
  64. package/dist/types/view.js +0 -0
  65. package/dist/validate/index.d.ts +15 -0
  66. package/dist/validate/index.js +53 -0
  67. package/package.json +43 -0
@@ -0,0 +1,80 @@
1
+ import { DataType } from "./types";
2
+ import { FormInstance } from "../instance";
3
+ import { FormEvent, FormFieldValidator } from "./";
4
+ /**
5
+ * 附加属性
6
+ */
7
+ export interface FieldAttribute {
8
+ key: string;
9
+ label?: string;
10
+ value?: string;
11
+ }
12
+ /**
13
+ * 流程表单字段元数据
14
+ */
15
+ export interface FormField {
16
+ id: string;
17
+ name: string;
18
+ code: string;
19
+ type: string;
20
+ dataType: DataType;
21
+ hidden: boolean;
22
+ required: boolean;
23
+ defaultValue?: string;
24
+ placeholder?: string;
25
+ tooltip?: string;
26
+ help?: string;
27
+ attributes?: FieldAttribute[];
28
+ }
29
+ /**
30
+ * 流程表单元数据
31
+ */
32
+ export interface FormMeta {
33
+ name: string;
34
+ code: string;
35
+ fields: FormField[];
36
+ subForms?: FormMeta[];
37
+ }
38
+ /**
39
+ * 字段唯一标识
40
+ */
41
+ export interface FieldCode {
42
+ /** 表单code **/
43
+ formCode?: string;
44
+ /** 字段code **/
45
+ fieldCode: string;
46
+ }
47
+ /**
48
+ * 表单布局
49
+ */
50
+ export interface FormLayout {
51
+ /** 所属表单 **/
52
+ formCode: string;
53
+ /** 布局类型 **/
54
+ type: string;
55
+ /** 表单属性 **/
56
+ props: any;
57
+ }
58
+ /**
59
+ * 字段唯一标识
60
+ */
61
+ export type FieldKey = string | FieldCode;
62
+ /**
63
+ * 表单视图属性
64
+ */
65
+ export interface FormViewProps {
66
+ /** 表单定义 **/
67
+ meta: FormMeta;
68
+ /** 表单操控对象 */
69
+ form?: FormInstance;
70
+ /** 表单数据更新事件 */
71
+ onValuesChange?: (values: any) => void;
72
+ /** 是否预览模式 */
73
+ review?: boolean;
74
+ /** 字段校验逻辑 */
75
+ validators?: FormFieldValidator[];
76
+ /** 事件定义 **/
77
+ events?: FormEvent[];
78
+ /** 布局控制 **/
79
+ layouts?: FormLayout[];
80
+ }
File without changes
@@ -0,0 +1,15 @@
1
+ import { FieldKey, FormFieldValidator } from "../types";
2
+ import { FormInstance } from "../instance";
3
+ import { FormMeta } from "../types";
4
+ export declare class FormValidate {
5
+ private readonly meta;
6
+ private readonly instance;
7
+ private readonly validators;
8
+ private readonly formList;
9
+ constructor(meta: FormMeta, instance: FormInstance, validators: FormFieldValidator[]);
10
+ private getFormField;
11
+ private supportValidator;
12
+ getValidatorRules(fieldKey: FieldKey): {
13
+ validator: (rule: any, value: any, callback: any) => Promise<undefined>;
14
+ }[];
15
+ }
@@ -0,0 +1,53 @@
1
+ class FormValidate {
2
+ meta;
3
+ instance;
4
+ validators;
5
+ formList;
6
+ constructor(meta, instance, validators){
7
+ this.meta = meta;
8
+ this.instance = instance;
9
+ this.validators = validators;
10
+ this.formList = [];
11
+ this.formList.push(meta);
12
+ const subForms = meta.subForms || [];
13
+ for (const subForm of subForms)this.formList.push(subForm);
14
+ }
15
+ getFormField(fieldKey) {
16
+ if ("string" == typeof fieldKey) {
17
+ const fields = this.meta.fields;
18
+ for (const field of fields)if (field.code === fieldKey) return field;
19
+ } else {
20
+ const fieldCode = fieldKey;
21
+ for (const subForm of this.formList)if (subForm.code === fieldCode.formCode) {
22
+ const fields = subForm.fields;
23
+ for (const field of fields)if (field.code === fieldCode.fieldCode) return field;
24
+ }
25
+ }
26
+ }
27
+ supportValidator(fieldKey, validator) {
28
+ if (validator.target === fieldKey) return true;
29
+ if ("string" == typeof validator.target && "string" == typeof fieldKey) return validator.target === fieldKey;
30
+ if ("string" == typeof validator.target && "string" != typeof fieldKey) {
31
+ const fieldCode = fieldKey;
32
+ return validator.target === fieldCode.fieldCode;
33
+ }
34
+ if ("string" != typeof validator.target && "string" == typeof fieldKey) {
35
+ const targetField = validator.target;
36
+ if (!targetField.formCode) return targetField.fieldCode = fieldKey;
37
+ }
38
+ return false;
39
+ }
40
+ getValidatorRules(fieldKey) {
41
+ const rules = [];
42
+ const formField = this.getFormField(fieldKey);
43
+ if (formField && formField.hidden) return [];
44
+ for (const validator of this.validators)if (this.supportValidator(fieldKey, validator)) rules.push({
45
+ validator: async (rule, value, callback)=>{
46
+ const res = validator.validator(this.instance, value);
47
+ if (true !== res) return Promise.reject(new Error(res));
48
+ }
49
+ });
50
+ return rules;
51
+ }
52
+ }
53
+ export { FormValidate };
package/package.json ADDED
@@ -0,0 +1,43 @@
1
+ {
2
+ "name": "@coding-form/form-engine",
3
+ "version": "0.0.1",
4
+ "description": "form-engine components",
5
+ "keywords": [
6
+ "coding-flow",
7
+ "flow-engine"
8
+ ],
9
+ "homepage": "https://github.com/codingapi/form-engine",
10
+ "bugs": {
11
+ "url": "https://github.com/codingapi/form-engine/issues"
12
+ },
13
+ "repository": {
14
+ "type": "git",
15
+ "url": "https://github.com/codingapi/form-engine.git"
16
+ },
17
+ "license": "Apache-2.0",
18
+ "author": "1024lorne@gmail.com",
19
+ "type": "module",
20
+ "exports": {
21
+ ".": {
22
+ "types": "./dist/index.d.ts",
23
+ "import": "./dist/index.js"
24
+ }
25
+ },
26
+ "types": "./dist/index.d.ts",
27
+ "files": [
28
+ "dist"
29
+ ],
30
+ "dependencies": {
31
+ "@reduxjs/toolkit": "^2.11.2",
32
+ "react-redux": "^9.2.0"
33
+ },
34
+ "peerDependencies": {
35
+ "react": ">=18",
36
+ "react-dom": ">=18"
37
+ },
38
+ "scripts": {
39
+ "build": "rslib build",
40
+ "dev": "rslib build --watch",
41
+ "push": "pnpm run build && pnpm publish --access public"
42
+ }
43
+ }