@coding-flow/flow-pc-form 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 (36) hide show
  1. package/LICENSE +201 -0
  2. package/README.md +169 -0
  3. package/dist/components/factory/form-item-factory.d.ts +9 -0
  4. package/dist/components/factory/form-item-factory.js +27 -0
  5. package/dist/components/form/index.d.ts +3 -0
  6. package/dist/components/form/index.js +25 -0
  7. package/dist/components/form/view.d.ts +19 -0
  8. package/dist/components/form/view.js +39 -0
  9. package/dist/components/item/boolean.d.ts +3 -0
  10. package/dist/components/item/boolean.js +38 -0
  11. package/dist/components/item/date.d.ts +3 -0
  12. package/dist/components/item/date.js +42 -0
  13. package/dist/components/item/double.d.ts +3 -0
  14. package/dist/components/item/double.js +39 -0
  15. package/dist/components/item/integer.d.ts +3 -0
  16. package/dist/components/item/integer.js +42 -0
  17. package/dist/components/item/long.d.ts +3 -0
  18. package/dist/components/item/long.js +42 -0
  19. package/dist/components/item/string.d.ts +3 -0
  20. package/dist/components/item/string.js +38 -0
  21. package/dist/components/table/hooks/use-table-form-presenter.d.ts +3 -0
  22. package/dist/components/table/hooks/use-table-form-presenter.js +8 -0
  23. package/dist/components/table/index.d.ts +3 -0
  24. package/dist/components/table/index.js +90 -0
  25. package/dist/components/table/presenter.d.ts +38 -0
  26. package/dist/components/table/presenter.js +74 -0
  27. package/dist/components/table/types.d.ts +14 -0
  28. package/dist/components/table/types.js +0 -0
  29. package/dist/favicon.png +0 -0
  30. package/dist/hooks/register-form-types.d.ts +1 -0
  31. package/dist/hooks/register-form-types.js +44 -0
  32. package/dist/index.d.ts +2 -0
  33. package/dist/index.js +2 -0
  34. package/dist/type.d.ts +11 -0
  35. package/dist/type.js +0 -0
  36. package/package.json +50 -0
package/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright 2025-2026 copyright codingapi
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,169 @@
1
+ # @coding-flow/flow-pc-form
2
+
3
+ Flow Engine PC 端表单组件库,提供表单设计器、表单渲染等功能。
4
+
5
+ ## 简介
6
+
7
+ `flow-pc-form` 是 Flow Engine PC 端的表单相关组件库,提供:
8
+
9
+ - 表单设计器(可视化表单设计)
10
+ - 表单渲染器(动态表单渲染)
11
+ - 表单字段组件
12
+ - 表单验证规则
13
+ - 表单权限控制
14
+
15
+ ### 依赖关系
16
+
17
+ - **依赖**: `@coding-flow/flow-core`, `@coding-flow/flow-types`
18
+
19
+ ## Setup
20
+
21
+ 安装依赖:
22
+
23
+ ```bash
24
+ pnpm install
25
+ ```
26
+
27
+ ## 开发
28
+
29
+ 构建组件库:
30
+
31
+ ```bash
32
+ pnpm run build
33
+ ```
34
+
35
+ 监听模式构建:
36
+
37
+ ```bash
38
+ pnpm run dev
39
+ ```
40
+
41
+ ## 核心功能
42
+
43
+ ### 表单设计器
44
+
45
+ 可视化表单设计器,支持:
46
+
47
+ - 拖拽添加字段
48
+ - 字段属性配置
49
+ - 字段排序
50
+ - 表单预览
51
+ - 表单 schema 导出
52
+
53
+ ```typescript
54
+ import { FormDesigner } from '@coding-flow/flow-pc-form';
55
+
56
+ <FormDesigner
57
+ schema={formSchema}
58
+ onChange={handleSchemaChange}
59
+ onPreview={handlePreview}
60
+ />
61
+ ```
62
+
63
+ ### 表单渲染器
64
+
65
+ 根据表单 schema 动态渲染表单:
66
+
67
+ ```typescript
68
+ import { FormRenderer } from '@coding-flow/flow-pc-form';
69
+
70
+ <FormRenderer
71
+ schema={formSchema}
72
+ values={formValues}
73
+ onChange={handleValuesChange}
74
+ permissions={fieldPermissions}
75
+ />
76
+ ```
77
+
78
+ ### 表单字段
79
+
80
+ 支持多种字段类型:
81
+
82
+ - 单行文本
83
+ - 多行文本
84
+ - 数字
85
+ - 日期
86
+ - 下拉选择
87
+ - 单选/多选
88
+ - 人员选择
89
+ - 部门选择
90
+ - 附件上传
91
+
92
+ ### 表单验证
93
+
94
+ 内置验证规则:
95
+
96
+ - 必填验证
97
+ - 长度限制
98
+ - 格式验证(邮箱、手机号等)
99
+ - 自定义验证规则
100
+
101
+ ### 表单权限
102
+
103
+ 字段级别权限控制:
104
+
105
+ - 可编辑
106
+ - 只读
107
+ - 隐藏
108
+ - 必填
109
+
110
+ ## 模块结构
111
+
112
+ ```
113
+ flow-pc-form/
114
+ ├── src/
115
+ │ ├── designer/ # 表单设计器
116
+ │ ├── renderer/ # 表单渲染器
117
+ │ ├── fields/ # 表单字段组件
118
+ │ ├── validator/ # 表单验证
119
+ │ ├── schema/ # 表单 schema 定义
120
+ │ └── index.ts # 统一导出
121
+ └── README.md
122
+ ```
123
+
124
+ ## 使用示例
125
+
126
+ ### 表单设计器
127
+
128
+ ```typescript
129
+ import { FormDesigner } from '@coding-flow/flow-pc-form';
130
+ import type { FlowForm } from '@coding-flow/flow-types';
131
+
132
+ const MyFormDesigner = () => {
133
+ const [schema, setSchema] = useState<FlowForm>({ ... });
134
+
135
+ return (
136
+ <FormDesigner
137
+ schema={schema}
138
+ onChange={setSchema}
139
+ onSave={handleSave}
140
+ />
141
+ );
142
+ };
143
+ ```
144
+
145
+ ### 表单渲染器
146
+
147
+ ```typescript
148
+ import { FormRenderer } from '@coding-flow/flow-pc-form';
149
+ import type { FlowForm, FormFieldPermission } from '@coding-flow/flow-types';
150
+
151
+ const MyFormRenderer = () => {
152
+ const [values, setValues] = useState({});
153
+
154
+ return (
155
+ <FormRenderer
156
+ schema={formSchema}
157
+ values={values}
158
+ onChange={setValues}
159
+ permissions={permissions}
160
+ />
161
+ );
162
+ };
163
+ ```
164
+
165
+ ## Learn more
166
+
167
+ - [Rslib documentation](https://lib.rsbuild.io/) - Rslib 特性和 API
168
+ - [Flow Engine Docs](https://github.com/codingapi/flow-engine) - 完整文档
169
+ - [CLAUDE.md](../../../CLAUDE.md) - 开发指南
@@ -0,0 +1,9 @@
1
+ import React from "react";
2
+ import { FormItemProps } from "../../type";
3
+ export declare class FormItemFactory {
4
+ private readonly cache;
5
+ private static instance;
6
+ private constructor();
7
+ static getInstance(): FormItemFactory;
8
+ createFrom(filedType: string): React.ComponentType<FormItemProps> | undefined;
9
+ }
@@ -0,0 +1,27 @@
1
+ import "react";
2
+ import { FormItemString } from "../item/string.js";
3
+ import { FormItemBoolean } from "../item/boolean.js";
4
+ import { FormItemDate } from "../item/date.js";
5
+ import { FormItemLong } from "../item/long.js";
6
+ import { FormItemInteger } from "../item/integer.js";
7
+ import { FormItemDouble } from "../item/double.js";
8
+ class FormItemFactory {
9
+ cache;
10
+ static instance = new FormItemFactory();
11
+ constructor(){
12
+ this.cache = new Map();
13
+ this.cache.set('long', FormItemLong);
14
+ this.cache.set('integer', FormItemInteger);
15
+ this.cache.set('double', FormItemDouble);
16
+ this.cache.set('string', FormItemString);
17
+ this.cache.set('date', FormItemDate);
18
+ this.cache.set('boolean', FormItemBoolean);
19
+ }
20
+ static getInstance() {
21
+ return FormItemFactory.instance;
22
+ }
23
+ createFrom(filedType) {
24
+ return this.cache.get(filedType);
25
+ }
26
+ }
27
+ export { FormItemFactory };
@@ -0,0 +1,3 @@
1
+ import React from "react";
2
+ import { FormViewProps } from "@coding-flow/flow-types";
3
+ export declare const FlowFormView: React.FC<FormViewProps>;
@@ -0,0 +1,25 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import "react";
3
+ import { FormView } from "./view.js";
4
+ import { FlowTable } from "../table/index.js";
5
+ const FlowFormView = (props)=>{
6
+ const form = props.form;
7
+ const formList = props.formList || [];
8
+ if (props.mergeable) return /*#__PURE__*/ jsx(FlowTable, {
9
+ formList: formList,
10
+ meta: props.meta,
11
+ onValuesChange: props.onValuesChange,
12
+ review: props.review,
13
+ fieldPermissions: props.fieldPermissions,
14
+ onMergeRecordIdsSelected: props.onMergeRecordIdsSelected
15
+ });
16
+ if (form) return /*#__PURE__*/ jsx(FormView, {
17
+ form: form,
18
+ data: props.data,
19
+ meta: props.meta,
20
+ onValuesChange: props.onValuesChange,
21
+ review: props.review,
22
+ fieldPermissions: props.fieldPermissions
23
+ });
24
+ };
25
+ export { FlowFormView };
@@ -0,0 +1,19 @@
1
+ import React from "react";
2
+ import { FormInstance } from "@coding-flow/flow-types";
3
+ import { FieldPermission, FlowForm, FlowTodo } from "@coding-flow/flow-types";
4
+ interface FormViewProps {
5
+ /** 流程数据 **/
6
+ data?: FlowTodo;
7
+ /** 表单操控对象 */
8
+ form: FormInstance;
9
+ /** 表单数据更新事件 */
10
+ onValuesChange?: (values: any) => void;
11
+ /** 表单元数据对象 */
12
+ meta: FlowForm;
13
+ /** 表单字段权限,为空时全部可写*/
14
+ fieldPermissions: FieldPermission[];
15
+ /** 是否预览模式 */
16
+ review: boolean;
17
+ }
18
+ export declare const FormView: React.FC<FormViewProps>;
19
+ export {};
@@ -0,0 +1,39 @@
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import react from "react";
3
+ import { FormItemFactory } from "../factory/form-item-factory.js";
4
+ import { ObjectUtils } from "@coding-flow/flow-core";
5
+ import { Form, Input } from "antd";
6
+ const FormView = (props)=>{
7
+ const [values, setValues] = react.useState({});
8
+ const form = props.form;
9
+ const meta = props.meta;
10
+ const fields = meta.fields || [];
11
+ const review = props.review;
12
+ return /*#__PURE__*/ jsx(Fragment, {
13
+ children: /*#__PURE__*/ jsxs(Form, {
14
+ form: form,
15
+ layout: "vertical",
16
+ onBlur: ()=>{
17
+ const latestValues = form.getFieldsValue();
18
+ if (ObjectUtils.isEqual(values, latestValues)) return;
19
+ setValues(latestValues);
20
+ props.onValuesChange?.(latestValues);
21
+ },
22
+ children: [
23
+ /*#__PURE__*/ jsx(Form.Item, {
24
+ name: "recordId",
25
+ hidden: true,
26
+ children: /*#__PURE__*/ jsx(Input, {})
27
+ }, "recordId"),
28
+ fields.map((field, i)=>{
29
+ const FormItem = FormItemFactory.getInstance().createFrom(field.type);
30
+ if (FormItem) return /*#__PURE__*/ jsx(FormItem, {
31
+ ...field,
32
+ readOnly: review
33
+ }, field.id);
34
+ })
35
+ ]
36
+ })
37
+ });
38
+ };
39
+ export { FormView };
@@ -0,0 +1,3 @@
1
+ import React from "react";
2
+ import { FormItemProps } from "../../type";
3
+ export declare const FormItemBoolean: React.FC<FormItemProps>;
@@ -0,0 +1,38 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import "react";
3
+ import { Form, Switch } from "antd";
4
+ const $Switch = (props)=>{
5
+ const value = props.value ? 'true' === props.value : void 0;
6
+ const defaultValue = props.defaultValue ? 'true' === props.defaultValue : void 0;
7
+ return /*#__PURE__*/ jsx(Switch, {
8
+ value: value,
9
+ disabled: props.readOnly,
10
+ defaultValue: defaultValue,
11
+ onChange: (value)=>{
12
+ props.onChange?.(value ? 'true' : 'false');
13
+ }
14
+ });
15
+ };
16
+ const FormItemBoolean = (props)=>{
17
+ const rules = props.required ? [
18
+ {
19
+ required: props.required,
20
+ message: `${props.name}不能为空`
21
+ }
22
+ ] : [];
23
+ return /*#__PURE__*/ jsx(Form.Item, {
24
+ name: props.code,
25
+ label: props.name,
26
+ required: props.required,
27
+ rules: rules,
28
+ tooltip: props.tooltip,
29
+ help: props.help,
30
+ hidden: props.hidden,
31
+ children: /*#__PURE__*/ jsx($Switch, {
32
+ defaultValue: props.defaultValue,
33
+ placeholder: props.placeholder,
34
+ readOnly: props.readOnly
35
+ })
36
+ });
37
+ };
38
+ export { FormItemBoolean };
@@ -0,0 +1,3 @@
1
+ import React from "react";
2
+ import { FormItemProps } from "../../type";
3
+ export declare const FormItemDate: React.FC<FormItemProps>;
@@ -0,0 +1,42 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import "react";
3
+ import { DatePicker, Form } from "antd";
4
+ import dayjs from "dayjs";
5
+ const $Date = (props)=>{
6
+ const handlerChange = (value)=>{
7
+ if (value) props.onChange?.(dayjs(value).format('YYYY-MM-DD'));
8
+ else props.onChange?.('');
9
+ };
10
+ const value = props.value ? dayjs(props.value) : void 0;
11
+ const defaultValue = props.defaultValue ? dayjs(props.defaultValue) : void 0;
12
+ return /*#__PURE__*/ jsx(DatePicker, {
13
+ disabled: props.readOnly,
14
+ value: value,
15
+ onChange: handlerChange,
16
+ placeholder: props.placeholder,
17
+ defaultValue: defaultValue
18
+ });
19
+ };
20
+ const FormItemDate = (props)=>{
21
+ const rules = props.required ? [
22
+ {
23
+ required: props.required,
24
+ message: `${props.name}不能为空`
25
+ }
26
+ ] : [];
27
+ return /*#__PURE__*/ jsx(Form.Item, {
28
+ name: props.code,
29
+ label: props.name,
30
+ required: props.required,
31
+ rules: rules,
32
+ tooltip: props.tooltip,
33
+ help: props.help,
34
+ hidden: props.hidden,
35
+ children: /*#__PURE__*/ jsx($Date, {
36
+ defaultValue: props.defaultValue,
37
+ placeholder: props.placeholder,
38
+ readOnly: props.readOnly
39
+ })
40
+ });
41
+ };
42
+ export { FormItemDate };
@@ -0,0 +1,3 @@
1
+ import React from "react";
2
+ import { FormItemProps } from "../../type";
3
+ export declare const FormItemDouble: React.FC<FormItemProps>;
@@ -0,0 +1,39 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import "react";
3
+ import { Form, Input } from "antd";
4
+ const $Input = (props)=>{
5
+ const value = props.value || void 0;
6
+ return /*#__PURE__*/ jsx(Input, {
7
+ type: "number",
8
+ value: value,
9
+ disabled: props.readOnly,
10
+ placeholder: props.placeholder,
11
+ defaultValue: props.defaultValue,
12
+ onChange: (event)=>{
13
+ props.onChange?.(event.target.value);
14
+ }
15
+ });
16
+ };
17
+ const FormItemDouble = (props)=>{
18
+ const rules = props.required ? [
19
+ {
20
+ required: props.required,
21
+ message: `${props.name}不能为空`
22
+ }
23
+ ] : [];
24
+ return /*#__PURE__*/ jsx(Form.Item, {
25
+ name: props.code,
26
+ label: props.name,
27
+ required: props.required,
28
+ rules: rules,
29
+ tooltip: props.tooltip,
30
+ help: props.help,
31
+ hidden: props.hidden,
32
+ children: /*#__PURE__*/ jsx($Input, {
33
+ defaultValue: props.defaultValue,
34
+ placeholder: props.placeholder,
35
+ readOnly: props.readOnly
36
+ })
37
+ });
38
+ };
39
+ export { FormItemDouble };
@@ -0,0 +1,3 @@
1
+ import React from "react";
2
+ import { FormItemProps } from "../../type";
3
+ export declare const FormItemInteger: React.FC<FormItemProps>;
@@ -0,0 +1,42 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import "react";
3
+ import { Form, InputNumber } from "antd";
4
+ const $Input = (props)=>{
5
+ const value = props.value || void 0;
6
+ return /*#__PURE__*/ jsx(InputNumber, {
7
+ style: {
8
+ width: "100%"
9
+ },
10
+ precision: 0,
11
+ value: value,
12
+ disabled: props.readOnly,
13
+ placeholder: props.placeholder,
14
+ defaultValue: props.defaultValue,
15
+ onChange: (value)=>{
16
+ if (value) props.onChange?.(value);
17
+ }
18
+ });
19
+ };
20
+ const FormItemInteger = (props)=>{
21
+ const rules = props.required ? [
22
+ {
23
+ required: props.required,
24
+ message: `${props.name}不能为空`
25
+ }
26
+ ] : [];
27
+ return /*#__PURE__*/ jsx(Form.Item, {
28
+ name: props.code,
29
+ label: props.name,
30
+ required: props.required,
31
+ rules: rules,
32
+ tooltip: props.tooltip,
33
+ help: props.help,
34
+ hidden: props.hidden,
35
+ children: /*#__PURE__*/ jsx($Input, {
36
+ defaultValue: props.defaultValue,
37
+ placeholder: props.placeholder,
38
+ readOnly: props.readOnly
39
+ })
40
+ });
41
+ };
42
+ export { FormItemInteger };
@@ -0,0 +1,3 @@
1
+ import React from "react";
2
+ import { FormItemProps } from "../../type";
3
+ export declare const FormItemLong: React.FC<FormItemProps>;
@@ -0,0 +1,42 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import "react";
3
+ import { Form, InputNumber } from "antd";
4
+ const $Input = (props)=>{
5
+ const value = props.value || void 0;
6
+ return /*#__PURE__*/ jsx(InputNumber, {
7
+ style: {
8
+ width: "100%"
9
+ },
10
+ precision: 0,
11
+ value: value,
12
+ disabled: props.readOnly,
13
+ placeholder: props.placeholder,
14
+ defaultValue: props.defaultValue,
15
+ onChange: (value)=>{
16
+ if (value) props.onChange?.(value);
17
+ }
18
+ });
19
+ };
20
+ const FormItemLong = (props)=>{
21
+ const rules = props.required ? [
22
+ {
23
+ required: props.required,
24
+ message: `${props.name}不能为空`
25
+ }
26
+ ] : [];
27
+ return /*#__PURE__*/ jsx(Form.Item, {
28
+ name: props.code,
29
+ label: props.name,
30
+ required: props.required,
31
+ rules: rules,
32
+ tooltip: props.tooltip,
33
+ help: props.help,
34
+ hidden: props.hidden,
35
+ children: /*#__PURE__*/ jsx($Input, {
36
+ defaultValue: props.defaultValue,
37
+ placeholder: props.placeholder,
38
+ readOnly: props.readOnly
39
+ })
40
+ });
41
+ };
42
+ export { FormItemLong };
@@ -0,0 +1,3 @@
1
+ import React from "react";
2
+ import { FormItemProps } from "../../type";
3
+ export declare const FormItemString: React.FC<FormItemProps>;
@@ -0,0 +1,38 @@
1
+ import { jsx } from "react/jsx-runtime";
2
+ import "react";
3
+ import { Form, Input } from "antd";
4
+ const $Input = (props)=>{
5
+ const value = props.value || void 0;
6
+ return /*#__PURE__*/ jsx(Input, {
7
+ value: value,
8
+ disabled: props.readOnly,
9
+ placeholder: props.placeholder,
10
+ defaultValue: props.defaultValue,
11
+ onChange: (event)=>{
12
+ props.onChange?.(event.target.value);
13
+ }
14
+ });
15
+ };
16
+ const FormItemString = (props)=>{
17
+ const rules = props.required ? [
18
+ {
19
+ required: props.required,
20
+ message: `${props.name}不能为空`
21
+ }
22
+ ] : [];
23
+ return /*#__PURE__*/ jsx(Form.Item, {
24
+ name: props.code,
25
+ label: props.name,
26
+ required: props.required,
27
+ rules: rules,
28
+ tooltip: props.tooltip,
29
+ help: props.help,
30
+ hidden: props.hidden,
31
+ children: /*#__PURE__*/ jsx($Input, {
32
+ defaultValue: props.defaultValue,
33
+ placeholder: props.placeholder,
34
+ readOnly: props.readOnly
35
+ })
36
+ });
37
+ };
38
+ export { FormItemString };
@@ -0,0 +1,3 @@
1
+ import { FlowTableProps } from "../types";
2
+ import { TableFormPresenter } from "../presenter";
3
+ export declare const useTableFormPresenter: (props: FlowTableProps) => TableFormPresenter;
@@ -0,0 +1,8 @@
1
+ import react from "react";
2
+ import { TableFormPresenter } from "../presenter.js";
3
+ const useTableFormPresenter = (props)=>{
4
+ const ref = react.useRef(void 0);
5
+ if (!ref.current) ref.current = new TableFormPresenter(props.meta, props.formList);
6
+ return ref.current;
7
+ };
8
+ export { useTableFormPresenter };
@@ -0,0 +1,3 @@
1
+ import React from "react";
2
+ import { FlowTableProps } from "./types";
3
+ export declare const FlowTable: React.FC<FlowTableProps>;
@@ -0,0 +1,90 @@
1
+ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
+ import react from "react";
3
+ import { useTableFormPresenter } from "./hooks/use-table-form-presenter.js";
4
+ import { Button, Flex, Table } from "antd";
5
+ import { FormView } from "../form/view.js";
6
+ import { CaretLeftOutlined } from "@ant-design/icons";
7
+ const FlowTable = (props)=>{
8
+ const presenter = useTableFormPresenter(props);
9
+ const [recordIdList, setRecordIdList] = react.useState([]);
10
+ const [currentForm, setCurrentForm] = react.useState();
11
+ const columns = react.useMemo(()=>{
12
+ const columns = presenter.getColumns();
13
+ const option = {
14
+ key: 'option',
15
+ valueType: 'option',
16
+ title: '操作',
17
+ render: (_, record)=>/*#__PURE__*/ jsx("a", {
18
+ onClick: ()=>{
19
+ const formData = presenter.getFormDataByRecordId(record.recordId);
20
+ if (formData) setCurrentForm(formData);
21
+ },
22
+ children: "查看"
23
+ })
24
+ };
25
+ return [
26
+ ...columns,
27
+ option
28
+ ];
29
+ }, []);
30
+ react.useEffect(()=>{
31
+ if (recordIdList.length > 0) props.onMergeRecordIdsSelected?.(recordIdList);
32
+ }, [
33
+ recordIdList
34
+ ]);
35
+ react.useEffect(()=>{
36
+ if (currentForm) {
37
+ const data = currentForm.form.getFieldsValue();
38
+ props.onValuesChange?.(data);
39
+ }
40
+ }, [
41
+ currentForm
42
+ ]);
43
+ return /*#__PURE__*/ jsxs(Fragment, {
44
+ children: [
45
+ !currentForm && /*#__PURE__*/ jsx(Table, {
46
+ columns: columns,
47
+ dataSource: presenter.getDatasource(),
48
+ rowKey: "recordId",
49
+ rowSelection: {
50
+ type: "checkbox",
51
+ onChange: (selectedRowId)=>{
52
+ setRecordIdList(selectedRowId);
53
+ }
54
+ }
55
+ }),
56
+ currentForm && /*#__PURE__*/ jsxs(Fragment, {
57
+ children: [
58
+ /*#__PURE__*/ jsx("div", {
59
+ style: {
60
+ width: "100%"
61
+ },
62
+ children: /*#__PURE__*/ jsx(Flex, {
63
+ justify: "end",
64
+ align: "end",
65
+ style: {
66
+ width: "100%"
67
+ },
68
+ children: /*#__PURE__*/ jsx(Button, {
69
+ icon: /*#__PURE__*/ jsx(CaretLeftOutlined, {}),
70
+ onClick: ()=>{
71
+ setCurrentForm(void 0);
72
+ },
73
+ children: "返回"
74
+ })
75
+ })
76
+ }),
77
+ /*#__PURE__*/ jsx(FormView, {
78
+ form: currentForm.form,
79
+ data: currentForm.data,
80
+ meta: props.meta,
81
+ onValuesChange: props.onValuesChange,
82
+ review: props.review,
83
+ fieldPermissions: props.fieldPermissions
84
+ })
85
+ ]
86
+ })
87
+ ]
88
+ });
89
+ };
90
+ export { FlowTable };
@@ -0,0 +1,38 @@
1
+ import { FlowForm, FormData } from "@coding-flow/flow-types";
2
+ export declare class TableFormPresenter {
3
+ private readonly meta;
4
+ private readonly formList;
5
+ constructor(meta: FlowForm, formList: FormData[]);
6
+ getFormDataByRecordId(id: number): FormData | undefined;
7
+ getColumns(): ({
8
+ title: string;
9
+ dataIndex: string;
10
+ key: string;
11
+ hidden: boolean;
12
+ } | {
13
+ title: string;
14
+ dataIndex: string;
15
+ key: string;
16
+ hidden?: undefined;
17
+ })[];
18
+ private getFormData;
19
+ getDatasource(): {
20
+ createdOperatorName: string;
21
+ createdOperatorId: number;
22
+ submitOperatorName: string | undefined;
23
+ submitOperatorId: number | undefined;
24
+ recordId: number;
25
+ createdOperator: import("@coding-flow/flow-types").FlowOperator;
26
+ submitOperator?: import("@coding-flow/flow-types").FlowOperator;
27
+ title: string;
28
+ data: Record<string, any>;
29
+ recordState: number;
30
+ flowState: number;
31
+ createTime: number;
32
+ processId: string;
33
+ workTitle: string;
34
+ nodeId: string;
35
+ nodeName: string;
36
+ nodeType: string;
37
+ }[];
38
+ }
@@ -0,0 +1,74 @@
1
+ class TableFormPresenter {
2
+ meta;
3
+ formList;
4
+ constructor(meta, formList){
5
+ this.meta = meta;
6
+ this.formList = formList;
7
+ }
8
+ getFormDataByRecordId(id) {
9
+ for (const item of this.formList){
10
+ const data = item.data;
11
+ if (data && data.recordId === id) return item;
12
+ }
13
+ }
14
+ getColumns() {
15
+ const columns = [];
16
+ const fields = this.meta.fields;
17
+ columns.push({
18
+ title: '编号',
19
+ dataIndex: 'recordId',
20
+ key: 'recordId',
21
+ hidden: false
22
+ });
23
+ columns.push({
24
+ title: '流程标题',
25
+ dataIndex: 'title',
26
+ key: 'title'
27
+ });
28
+ columns.push({
29
+ title: '流程提交人',
30
+ dataIndex: 'submitOperatorName',
31
+ key: 'submitOperatorName'
32
+ });
33
+ columns.push({
34
+ title: '流程发起人',
35
+ dataIndex: 'createdOperatorName',
36
+ key: 'createdOperatorName'
37
+ });
38
+ for (const field of fields)columns.push({
39
+ title: field.name,
40
+ dataIndex: field.code,
41
+ key: field.name
42
+ });
43
+ return columns;
44
+ }
45
+ getFormData(form) {
46
+ const formInstance = form.form;
47
+ const fields = this.meta.fields;
48
+ const data = {};
49
+ for (const field of fields)data[field.code] = formInstance.getFieldValue(field.code);
50
+ return data;
51
+ }
52
+ getDatasource() {
53
+ const datasource = [];
54
+ for (const form of this.formList){
55
+ const data = form.data;
56
+ const submitOperator = {
57
+ submitOperatorName: data.submitOperator?.name,
58
+ submitOperatorId: data.submitOperator?.id
59
+ };
60
+ const createdOperator = {
61
+ createdOperatorName: data.createdOperator.name,
62
+ createdOperatorId: data.createdOperator.id
63
+ };
64
+ datasource.push({
65
+ ...this.getFormData(form),
66
+ ...data,
67
+ ...submitOperator,
68
+ ...createdOperator
69
+ });
70
+ }
71
+ return datasource;
72
+ }
73
+ }
74
+ export { TableFormPresenter };
@@ -0,0 +1,14 @@
1
+ import { FormData, FieldPermission, FlowForm } from "@coding-flow/flow-types";
2
+ export interface FlowTableProps {
3
+ formList: FormData[];
4
+ /** 表单数据更新事件 */
5
+ onValuesChange?: (values: any) => void;
6
+ /** 表单元数据对象 */
7
+ meta: FlowForm;
8
+ /** 表单字段权限,为空时全部可写*/
9
+ fieldPermissions: FieldPermission[];
10
+ /** 是否预览模式 */
11
+ review: boolean;
12
+ /** 当合并流程选中了流程记录的回掉 **/
13
+ onMergeRecordIdsSelected?: (recordIds: number[]) => void;
14
+ }
File without changes
Binary file
@@ -0,0 +1 @@
1
+ export declare const registerFormTypes: () => void;
@@ -0,0 +1,44 @@
1
+ import react from "react";
2
+ import { FormTypeContext } from "@coding-flow/flow-types";
3
+ class RegisterRef {
4
+ }
5
+ const registerFormTypes = ()=>{
6
+ const ref = react.useRef(void 0);
7
+ if (!ref.current) {
8
+ ref.current = new RegisterRef();
9
+ const types = [
10
+ {
11
+ name: "字符串",
12
+ dataType: 'STRING',
13
+ type: 'string'
14
+ },
15
+ {
16
+ name: "布尔值",
17
+ dataType: 'BOOLEAN',
18
+ type: 'boolean'
19
+ },
20
+ {
21
+ name: "整数",
22
+ dataType: 'INTEGER',
23
+ type: 'integer'
24
+ },
25
+ {
26
+ name: "长整数",
27
+ dataType: 'LONG',
28
+ type: 'long'
29
+ },
30
+ {
31
+ name: "小数",
32
+ dataType: 'DOUBLE',
33
+ type: 'double'
34
+ },
35
+ {
36
+ name: "日期格式",
37
+ dataType: 'STRING',
38
+ type: 'date'
39
+ }
40
+ ];
41
+ FormTypeContext.getInstance().register(types);
42
+ }
43
+ };
44
+ export { registerFormTypes };
@@ -0,0 +1,2 @@
1
+ export * from './components/form';
2
+ export * from './hooks/register-form-types';
package/dist/index.js ADDED
@@ -0,0 +1,2 @@
1
+ export * from "./components/form/index.js";
2
+ export * from "./hooks/register-form-types.js";
package/dist/type.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ import { FormField } from "@coding-flow/flow-types";
2
+ export interface FormItemInputProps {
3
+ defaultValue?: string;
4
+ value?: string;
5
+ onChange?: (value: string) => void;
6
+ placeholder?: string;
7
+ readOnly?: boolean;
8
+ }
9
+ export interface FormItemProps extends FormField {
10
+ readOnly?: boolean;
11
+ }
package/dist/type.js ADDED
File without changes
package/package.json ADDED
@@ -0,0 +1,50 @@
1
+ {
2
+ "name": "@coding-flow/flow-pc-form",
3
+ "version": "0.0.1",
4
+ "description": "flow-engine pc form engine",
5
+ "type": "module",
6
+ "keywords": [
7
+ "coding-flow",
8
+ "flow-engine"
9
+ ],
10
+ "homepage": "https://github.com/codingapi/flow-frontend",
11
+ "bugs": {
12
+ "url": "https://github.com/codingapi/flow-frontend/issues"
13
+ },
14
+ "repository": {
15
+ "type": "git",
16
+ "url": "https://github.com/codingapi/flow-frontend.git"
17
+ },
18
+ "license": "Apache-2.0",
19
+ "author": "1024lorne@gmail.com",
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
+ "peerDependencies": {
31
+ "react": ">=18",
32
+ "react-dom": ">=18"
33
+ },
34
+ "dependencies": {
35
+ "@ant-design/icons": "~6.1.0",
36
+ "antd": "^6.2.1",
37
+ "dayjs": "^1.11.19",
38
+ "@coding-flow/flow-core": "0.0.1",
39
+ "@coding-flow/flow-types": "0.0.1"
40
+ },
41
+ "devDependencies": {
42
+ "@coding-flow/flow-types": "0.0.1"
43
+ },
44
+ "scripts": {
45
+ "build": "rslib build",
46
+ "dev": "rslib build --watch",
47
+ "test": "rstest",
48
+ "push": "pnpm run build && pnpm publish --access public"
49
+ }
50
+ }