@zerodep-dev/flow-ts-ui 0.0.0-stage → 1.0.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/LICENSE +202 -0
- package/dist/diagram/process-diagram.d.ts +38 -0
- package/dist/diagram/process-diagram.js +128 -0
- package/dist/diagram/process-diagram.js.map +1 -0
- package/dist/form/form-values.d.ts +5 -0
- package/dist/form/form-values.js +85 -0
- package/dist/form/form-values.js.map +1 -0
- package/dist/form/manifest-schema.d.ts +4 -0
- package/dist/form/manifest-schema.js +95 -0
- package/dist/form/manifest-schema.js.map +1 -0
- package/dist/form/useFlowForm.d.ts +30 -0
- package/dist/form/useFlowForm.js +64 -0
- package/dist/form/useFlowForm.js.map +1 -0
- package/dist/form-designer/FieldProperties.d.ts +18 -0
- package/dist/form-designer/FieldProperties.js +333 -0
- package/dist/form-designer/FieldProperties.js.map +1 -0
- package/dist/form-designer/FormDesigner.d.ts +12 -0
- package/dist/form-designer/FormDesigner.js +257 -0
- package/dist/form-designer/FormDesigner.js.map +1 -0
- package/dist/form-designer/form-fields.d.ts +31 -0
- package/dist/form-designer/form-fields.js +193 -0
- package/dist/form-designer/form-fields.js.map +1 -0
- package/dist/index.d.ts +15 -0
- package/dist/index.js +12 -0
- package/dist/process-designer/AccessMatrix.d.ts +11 -0
- package/dist/process-designer/AccessMatrix.js +60 -0
- package/dist/process-designer/AccessMatrix.js.map +1 -0
- package/dist/process-designer/NodePanel.d.ts +17 -0
- package/dist/process-designer/NodePanel.js +464 -0
- package/dist/process-designer/NodePanel.js.map +1 -0
- package/dist/process-designer/form-access.d.ts +41 -0
- package/dist/process-designer/form-access.js +104 -0
- package/dist/process-designer/form-access.js.map +1 -0
- package/dist/utils/object.d.ts +3 -0
- package/dist/utils/object.js +11 -0
- package/dist/utils/object.js.map +1 -0
- package/package.json +67 -3
- package/README.md +0 -3
package/LICENSE
ADDED
|
@@ -0,0 +1,202 @@
|
|
|
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 [yyyy] [name of copyright owner]
|
|
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.
|
|
202
|
+
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 流程定义 → 画布:模型包的定义换成 Diagram 的节点与连线(形状、大小、状态、退回的线),排版交给 layoutLayers。
|
|
3
|
+
* 设计器、审批单的进度图共用;节点的样子要按业务改时,renderStep 换成自己的。
|
|
4
|
+
*
|
|
5
|
+
* const { nodes, edges } = processDiagram(definition, { current: ['manager'], done: ['start', 'start-manager'] });
|
|
6
|
+
* <Diagram nodes={nodes} edges={edges} getNodeLabel={stepLabel} edgeText={(flow) => flow.text} routing="orthogonal">
|
|
7
|
+
* {renderStep}
|
|
8
|
+
* </Diagram>
|
|
9
|
+
*/
|
|
10
|
+
import type { ProcessDefinition, ProcessNode } from '@zerodep-dev/flow-ts-model';
|
|
11
|
+
import { type DiagramEdgeItem, type DiagramNodeItem } from '@zerodep-dev/vue-tsx-pro-ui/diagram';
|
|
12
|
+
/** 节点在这次审批里的状态 */
|
|
13
|
+
export type StepState = 'done' | 'current' | 'failed' | 'idle';
|
|
14
|
+
/** 画布上的一个环节 */
|
|
15
|
+
export interface StepItem extends DiagramNodeItem {
|
|
16
|
+
node: ProcessNode;
|
|
17
|
+
state: StepState;
|
|
18
|
+
}
|
|
19
|
+
/** 画布上的一条线 */
|
|
20
|
+
export interface FlowItem extends DiagramEdgeItem {
|
|
21
|
+
/** 线上的字:按钮的名字、分支的条件 */
|
|
22
|
+
text?: string;
|
|
23
|
+
}
|
|
24
|
+
/** 审批进度:正在处理的节点、走过的节点与连线、出错的节点 */
|
|
25
|
+
export interface ProcessProgress {
|
|
26
|
+
current?: readonly string[];
|
|
27
|
+
done?: readonly string[];
|
|
28
|
+
failed?: readonly string[];
|
|
29
|
+
}
|
|
30
|
+
/** 定义换成画布的节点与连线;定义的 layout 里存了位置的节点(设计器拖过的)用它 */
|
|
31
|
+
export declare function processDiagram(definition: ProcessDefinition, { current, done, failed }?: ProcessProgress): {
|
|
32
|
+
nodes: StepItem[];
|
|
33
|
+
edges: FlowItem[];
|
|
34
|
+
};
|
|
35
|
+
/** 读屏念的:名称加状态 */
|
|
36
|
+
export declare const stepLabel: (step: StepItem) => string;
|
|
37
|
+
/** 环节的样子:网关画符号,别的写名称与类型;状态用色调,正在处理的加光晕 */
|
|
38
|
+
export declare function renderStep(step: StepItem): import("@zerodep-dev/vue-tsx-pro-tsx/jsx-runtime").JSX.Element;
|
|
@@ -0,0 +1,128 @@
|
|
|
1
|
+
import { createVNode } from "vue";
|
|
2
|
+
import { DiagramNode, layoutLayers } from "@zerodep-dev/vue-tsx-pro-ui/diagram";
|
|
3
|
+
// src/diagram/process-diagram.tsx
|
|
4
|
+
/**
|
|
5
|
+
* 流程定义 → 画布:模型包的定义换成 Diagram 的节点与连线(形状、大小、状态、退回的线),排版交给 layoutLayers。
|
|
6
|
+
* 设计器、审批单的进度图共用;节点的样子要按业务改时,renderStep 换成自己的。
|
|
7
|
+
*
|
|
8
|
+
* const { nodes, edges } = processDiagram(definition, { current: ['manager'], done: ['start', 'start-manager'] });
|
|
9
|
+
* <Diagram nodes={nodes} edges={edges} getNodeLabel={stepLabel} edgeText={(flow) => flow.text} routing="orthogonal">
|
|
10
|
+
* {renderStep}
|
|
11
|
+
* </Diagram>
|
|
12
|
+
*/
|
|
13
|
+
/** 节点在这次审批里的状态 */
|
|
14
|
+
/** 画布上的一个环节 */
|
|
15
|
+
/** 画布上的一条线 */
|
|
16
|
+
/** 审批进度:正在处理的节点、走过的节点与连线、出错的节点 */
|
|
17
|
+
var STATE_TONES = {
|
|
18
|
+
done: "success",
|
|
19
|
+
current: "accent",
|
|
20
|
+
failed: "danger",
|
|
21
|
+
idle: "neutral"
|
|
22
|
+
};
|
|
23
|
+
var STATE_TEXT = {
|
|
24
|
+
done: "已走过",
|
|
25
|
+
current: "正在处理",
|
|
26
|
+
failed: "出错",
|
|
27
|
+
idle: ""
|
|
28
|
+
};
|
|
29
|
+
var GATEWAY_MARKS = {
|
|
30
|
+
exclusive: "×",
|
|
31
|
+
parallel: "+",
|
|
32
|
+
inclusive: "○"
|
|
33
|
+
};
|
|
34
|
+
var TYPE_TEXT = {
|
|
35
|
+
service: "自动处理",
|
|
36
|
+
call: "子流程",
|
|
37
|
+
timer: "定时",
|
|
38
|
+
receive: "等外部消息",
|
|
39
|
+
cc: "抄送"
|
|
40
|
+
};
|
|
41
|
+
/** 节点的形状与大小:开始、结束是圆,网关是菱形,其余是圆角矩形 */
|
|
42
|
+
function boxOf(node) {
|
|
43
|
+
if (node.type === "start" || node.type === "end") return {
|
|
44
|
+
shape: "circle",
|
|
45
|
+
width: 52,
|
|
46
|
+
height: 52
|
|
47
|
+
};
|
|
48
|
+
if (GATEWAY_MARKS[node.type]) return {
|
|
49
|
+
shape: "diamond",
|
|
50
|
+
width: 56,
|
|
51
|
+
height: 56
|
|
52
|
+
};
|
|
53
|
+
return {
|
|
54
|
+
shape: "rect",
|
|
55
|
+
width: 136,
|
|
56
|
+
height: 56
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
/** 退回、提级的线往回走:不参与排版,从下面绕回去 */
|
|
60
|
+
var isBack = (edge) => edge.kind === "return" || edge.kind === "escalate";
|
|
61
|
+
/** 按钮分出的线对应的按钮 */
|
|
62
|
+
function outcomeOf(definition, edge) {
|
|
63
|
+
const from = definition.nodes.find((node) => node.id === edge.from);
|
|
64
|
+
return edge.outcome && from?.type === "task" ? from.outcomes.find((outcome) => outcome.key === edge.outcome) : void 0;
|
|
65
|
+
}
|
|
66
|
+
/** 定义换成画布的节点与连线;定义的 layout 里存了位置的节点(设计器拖过的)用它 */
|
|
67
|
+
function processDiagram(definition, { current = [], done = [], failed = [] } = {}) {
|
|
68
|
+
const stateOf = (id) => failed.includes(id) ? "failed" : current.includes(id) ? "current" : done.includes(id) ? "done" : "idle";
|
|
69
|
+
const boxes = definition.nodes.map((node) => ({
|
|
70
|
+
id: node.id,
|
|
71
|
+
...boxOf(node),
|
|
72
|
+
...definition.layout?.nodes?.[node.id]
|
|
73
|
+
}));
|
|
74
|
+
const placed = layoutLayers(boxes, definition.edges.filter((edge) => !isBack(edge)), {
|
|
75
|
+
roots: definition.nodes.filter((node) => node.type === "start").map((node) => node.id),
|
|
76
|
+
columnGap: 208,
|
|
77
|
+
rowGap: 96
|
|
78
|
+
});
|
|
79
|
+
const centerY = (id) => {
|
|
80
|
+
const box = placed.find((node) => node.id === id);
|
|
81
|
+
return box ? box.y + box.height / 2 : 0;
|
|
82
|
+
};
|
|
83
|
+
/** 线怎么走:退回的从下面绕回去;驳回的从上边或下边出去(朝终点那边),右边留给往下走的线 */
|
|
84
|
+
const route = (edge) => {
|
|
85
|
+
if (isBack(edge)) return {
|
|
86
|
+
tone: "danger",
|
|
87
|
+
dashed: true,
|
|
88
|
+
fromSide: "bottom",
|
|
89
|
+
toSide: "bottom"
|
|
90
|
+
};
|
|
91
|
+
const toned = done.includes(edge.id) ? { tone: "success" } : {};
|
|
92
|
+
if (outcomeOf(definition, edge)?.kind !== "reject") return toned;
|
|
93
|
+
return {
|
|
94
|
+
...toned,
|
|
95
|
+
fromSide: centerY(edge.to) < centerY(edge.from) ? "top" : "bottom"
|
|
96
|
+
};
|
|
97
|
+
};
|
|
98
|
+
return {
|
|
99
|
+
nodes: definition.nodes.map((node, index) => ({
|
|
100
|
+
...placed[index],
|
|
101
|
+
shape: boxes[index].shape,
|
|
102
|
+
node,
|
|
103
|
+
state: stateOf(node.id)
|
|
104
|
+
})),
|
|
105
|
+
edges: definition.edges.map((edge) => ({
|
|
106
|
+
id: edge.id,
|
|
107
|
+
from: edge.from,
|
|
108
|
+
to: edge.to,
|
|
109
|
+
text: edge.label ?? outcomeOf(definition, edge)?.label,
|
|
110
|
+
...route(edge)
|
|
111
|
+
}))
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
/** 读屏念的:名称加状态 */
|
|
115
|
+
var stepLabel = (step) => [step.node.name, STATE_TEXT[step.state]].filter(Boolean).join(",");
|
|
116
|
+
/** 环节的样子:网关画符号,别的写名称与类型;状态用色调,正在处理的加光晕 */
|
|
117
|
+
function renderStep(step) {
|
|
118
|
+
const mark = GATEWAY_MARKS[step.node.type];
|
|
119
|
+
return createVNode(DiagramNode, {
|
|
120
|
+
"title": mark ?? step.node.name,
|
|
121
|
+
"description": mark ? void 0 : TYPE_TEXT[step.node.type],
|
|
122
|
+
"tone": STATE_TONES[step.state],
|
|
123
|
+
"active": step.state === "current"
|
|
124
|
+
}, null);
|
|
125
|
+
}
|
|
126
|
+
export { processDiagram, renderStep, stepLabel };
|
|
127
|
+
|
|
128
|
+
//# sourceMappingURL=process-diagram.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"process-diagram.js","names":["_createVNode"],"sources":["../../src/diagram/process-diagram.tsx"],"sourcesContent":["/**\n * 流程定义 → 画布:模型包的定义换成 Diagram 的节点与连线(形状、大小、状态、退回的线),排版交给 layoutLayers。\n * 设计器、审批单的进度图共用;节点的样子要按业务改时,renderStep 换成自己的。\n *\n * const { nodes, edges } = processDiagram(definition, { current: ['manager'], done: ['start', 'start-manager'] });\n * <Diagram nodes={nodes} edges={edges} getNodeLabel={stepLabel} edgeText={(flow) => flow.text} routing=\"orthogonal\">\n * {renderStep}\n * </Diagram>\n */\nimport type { ProcessDefinition, ProcessEdge, ProcessNode } from '@zerodep-dev/flow-ts-model';\nimport {\n DiagramNode,\n layoutLayers,\n type DiagramEdgeItem,\n type DiagramNodeItem,\n type DiagramNodeShape,\n} from '@zerodep-dev/vue-tsx-pro-ui/diagram';\n\n/** 节点在这次审批里的状态 */\nexport type StepState = 'done' | 'current' | 'failed' | 'idle';\n\n/** 画布上的一个环节 */\nexport interface StepItem extends DiagramNodeItem {\n node: ProcessNode;\n state: StepState;\n}\n\n/** 画布上的一条线 */\nexport interface FlowItem extends DiagramEdgeItem {\n /** 线上的字:按钮的名字、分支的条件 */\n text?: string;\n}\n\n/** 审批进度:正在处理的节点、走过的节点与连线、出错的节点 */\nexport interface ProcessProgress {\n current?: readonly string[];\n done?: readonly string[];\n failed?: readonly string[];\n}\n\nconst STATE_TONES = {\n done: 'success',\n current: 'accent',\n failed: 'danger',\n idle: 'neutral',\n} as const;\nconst STATE_TEXT: Record<StepState, string> = {\n done: '已走过',\n current: '正在处理',\n failed: '出错',\n idle: '',\n};\nconst GATEWAY_MARKS: Partial<Record<string, string>> = {\n exclusive: '×',\n parallel: '+',\n inclusive: '○',\n};\nconst TYPE_TEXT: Partial<Record<string, string>> = {\n service: '自动处理',\n call: '子流程',\n timer: '定时',\n receive: '等外部消息',\n cc: '抄送',\n};\n\n/** 节点的形状与大小:开始、结束是圆,网关是菱形,其余是圆角矩形 */\nfunction boxOf(node: ProcessNode): { shape: DiagramNodeShape; width: number; height: number } {\n if (node.type === 'start' || node.type === 'end')\n return { shape: 'circle', width: 52, height: 52 };\n if (GATEWAY_MARKS[node.type]) return { shape: 'diamond', width: 56, height: 56 };\n return { shape: 'rect', width: 136, height: 56 };\n}\n\n/** 退回、提级的线往回走:不参与排版,从下面绕回去 */\nconst isBack = (edge: ProcessEdge) => edge.kind === 'return' || edge.kind === 'escalate';\n\n/** 按钮分出的线对应的按钮 */\nfunction outcomeOf(definition: ProcessDefinition, edge: ProcessEdge) {\n const from = definition.nodes.find((node) => node.id === edge.from);\n return edge.outcome && from?.type === 'task'\n ? from.outcomes.find((outcome) => outcome.key === edge.outcome)\n : undefined;\n}\n\n/** 定义换成画布的节点与连线;定义的 layout 里存了位置的节点(设计器拖过的)用它 */\nexport function processDiagram(\n definition: ProcessDefinition,\n { current = [], done = [], failed = [] }: ProcessProgress = {},\n): { nodes: StepItem[]; edges: FlowItem[] } {\n const stateOf = (id: string): StepState =>\n failed.includes(id)\n ? 'failed'\n : current.includes(id)\n ? 'current'\n : done.includes(id)\n ? 'done'\n : 'idle';\n const boxes = definition.nodes.map((node) => ({\n id: node.id,\n ...boxOf(node),\n ...definition.layout?.nodes?.[node.id],\n }));\n const placed = layoutLayers(\n boxes,\n definition.edges.filter((edge) => !isBack(edge)),\n {\n roots: definition.nodes.filter((node) => node.type === 'start').map((node) => node.id),\n columnGap: 208,\n rowGap: 96,\n },\n );\n const centerY = (id: string) => {\n const box = placed.find((node) => node.id === id);\n return box ? box.y + box.height / 2 : 0;\n };\n /** 线怎么走:退回的从下面绕回去;驳回的从上边或下边出去(朝终点那边),右边留给往下走的线 */\n const route = (edge: ProcessEdge): Partial<FlowItem> => {\n if (isBack(edge)) return { tone: 'danger', dashed: true, fromSide: 'bottom', toSide: 'bottom' };\n const toned = done.includes(edge.id) ? { tone: 'success' as const } : {};\n if (outcomeOf(definition, edge)?.kind !== 'reject') return toned;\n return { ...toned, fromSide: centerY(edge.to) < centerY(edge.from) ? 'top' : 'bottom' };\n };\n return {\n nodes: definition.nodes.map((node, index) => ({\n ...placed[index]!,\n shape: boxes[index]!.shape,\n node,\n state: stateOf(node.id),\n })),\n edges: definition.edges.map((edge): FlowItem => ({\n id: edge.id,\n from: edge.from,\n to: edge.to,\n text: edge.label ?? outcomeOf(definition, edge)?.label,\n ...route(edge),\n })),\n };\n}\n\n/** 读屏念的:名称加状态 */\nexport const stepLabel = (step: StepItem) =>\n [step.node.name, STATE_TEXT[step.state]].filter(Boolean).join(',');\n\n/** 环节的样子:网关画符号,别的写名称与类型;状态用色调,正在处理的加光晕 */\nexport function renderStep(step: StepItem) {\n const mark = GATEWAY_MARKS[step.node.type];\n return (\n <DiagramNode\n title={mark ?? step.node.name}\n description={mark ? undefined : TYPE_TEXT[step.node.type]}\n tone={STATE_TONES[step.state]}\n active={step.state === 'current'}\n />\n );\n}\n"],"mappings":";;;;;;;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AA,IAAY,UAAU,KAAK,KAAK;EAAK,QACnD,YAAY,KAAK;EAAM,UACrB,KAAK,UAAU;CAAS,GAAA,IAAA;AAGtC"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type FormManifest } from '@zerodep-dev/flow-ts-model';
|
|
2
|
+
/** 单据的值(线上的形状)→ 表单里的;timeZone 是日期时间按哪个时区显示 */
|
|
3
|
+
export declare function toFormValues(manifest: FormManifest, values: unknown, timeZone: string): Record<string, unknown>;
|
|
4
|
+
/** 表单里的值 → 单据的值(线上的形状):交给引擎的发起、处理 */
|
|
5
|
+
export declare function fromFormValues(manifest: FormManifest, values: unknown, timeZone: string): Record<string, unknown>;
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import { typedValue } from "@zerodep-dev/flow-ts-model";
|
|
2
|
+
import { parseDateTime, toCalendarDateTime, toTimeZone, toZoned } from "@internationalized/date";
|
|
3
|
+
// src/form/form-values.ts
|
|
4
|
+
/**
|
|
5
|
+
* 单据的值在线上(json-wire 还原后)与在表单里的两种形状,按字段清单互换:
|
|
6
|
+
*
|
|
7
|
+
* | 字段类型 | 线上 | 表单里 |
|
|
8
|
+
* | --- | --- | --- |
|
|
9
|
+
* | date | CalendarDate | 'YYYY-MM-DD'(DatePicker 的值) |
|
|
10
|
+
* | datetime | ZonedDateTime | 不带时区的 'YYYY-MM-DDTHH:mm:ss',按 timeZone 换算 |
|
|
11
|
+
* | select | 选项的值(文字或数字) | 文字(组件库的选项值是文字) |
|
|
12
|
+
* | file | `{ id, name, size, url? }` | Upload 的文件(上传返回的 `{ id, url }` 记在 response 上) |
|
|
13
|
+
*
|
|
14
|
+
* 其余(文字、数字、Decimal、布尔、人员)两边一样。清单里没有的键原样留着。
|
|
15
|
+
*/
|
|
16
|
+
/** 文字里写了时区(Z、+08:00、[Asia/Shanghai]):是线上的时刻,不是表单里的本地写法 */
|
|
17
|
+
var hasZone = (text) => /(?:[zZ]|[+-]\d{2}:?\d{2})(?:\[[^\]]+\])?$/.test(text);
|
|
18
|
+
var isObject = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
|
|
19
|
+
/** 值是数组的字段:人员、附件、明细表、多选 */
|
|
20
|
+
var holdsList = (field) => field.type === "people" || field.type === "file" || field.type === "list" || field.type === "select" && field.multiple === true;
|
|
21
|
+
/** 一个值从线上换成表单里的;数组型的字段没填(null)时是空数组,组件只认数组 */
|
|
22
|
+
function toFormValue(field, value, timeZone) {
|
|
23
|
+
if (value === null || value === void 0) return holdsList(field) ? [] : value;
|
|
24
|
+
switch (field.type) {
|
|
25
|
+
case "date": return typeof value === "string" ? value : value.toString();
|
|
26
|
+
case "decimal": return typeof value === "string" ? typedValue(field, value) : value;
|
|
27
|
+
case "datetime": {
|
|
28
|
+
const zoned = typeof value === "string" && hasZone(value) ? typedValue(field, value) : value;
|
|
29
|
+
if (typeof zoned === "string") return zoned;
|
|
30
|
+
return toCalendarDateTime(toTimeZone(zoned, timeZone)).toString();
|
|
31
|
+
}
|
|
32
|
+
case "select": return Array.isArray(value) ? value.map((item) => String(item)) : String(value);
|
|
33
|
+
case "file": return Array.isArray(value) ? value.map((file) => ({
|
|
34
|
+
id: file.id,
|
|
35
|
+
name: file.name,
|
|
36
|
+
size: file.size,
|
|
37
|
+
status: "done",
|
|
38
|
+
...file.url && { url: file.url },
|
|
39
|
+
response: {
|
|
40
|
+
id: file.id,
|
|
41
|
+
url: file.url
|
|
42
|
+
}
|
|
43
|
+
})) : value;
|
|
44
|
+
case "list": return Array.isArray(value) ? value.map((row) => toFormValues(field.fields ?? {}, row, timeZone)) : value;
|
|
45
|
+
default: return value;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
/** 一个值从表单里换成线上的(强类型的读成 Decimal、CalendarDate、ZonedDateTime) */
|
|
49
|
+
function fromFormValue(field, value, timeZone) {
|
|
50
|
+
if (value === null || value === void 0 || value === "") return value;
|
|
51
|
+
switch (field.type) {
|
|
52
|
+
case "datetime":
|
|
53
|
+
if (typeof value !== "string") return value;
|
|
54
|
+
return hasZone(value) ? typedValue(field, value) : toZoned(parseDateTime(value), timeZone);
|
|
55
|
+
case "select": {
|
|
56
|
+
const options = Array.isArray(field.options) ? field.options : [];
|
|
57
|
+
const original = (item) => options.find((option) => String(option.value) === item)?.value ?? item;
|
|
58
|
+
return Array.isArray(value) ? value.map(original) : original(value);
|
|
59
|
+
}
|
|
60
|
+
case "file": return Array.isArray(value) ? value.map((file) => {
|
|
61
|
+
const response = isObject(file.response) ? file.response : {};
|
|
62
|
+
return {
|
|
63
|
+
id: typeof response.id === "string" ? response.id : file.id,
|
|
64
|
+
name: file.name,
|
|
65
|
+
size: file.size ?? 0,
|
|
66
|
+
...typeof response.url === "string" && { url: response.url }
|
|
67
|
+
};
|
|
68
|
+
}) : value;
|
|
69
|
+
case "list": return Array.isArray(value) ? value.map((row) => fromFormValues(field.fields ?? {}, row, timeZone)) : value;
|
|
70
|
+
default: return typedValue(field, value);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/** 单据的值(线上的形状)→ 表单里的;timeZone 是日期时间按哪个时区显示 */
|
|
74
|
+
function toFormValues(manifest, values, timeZone) {
|
|
75
|
+
if (!isObject(values)) return {};
|
|
76
|
+
return Object.fromEntries(Object.entries(values).map(([name, value]) => [name, manifest[name] ? toFormValue(manifest[name], value, timeZone) : value]));
|
|
77
|
+
}
|
|
78
|
+
/** 表单里的值 → 单据的值(线上的形状):交给引擎的发起、处理 */
|
|
79
|
+
function fromFormValues(manifest, values, timeZone) {
|
|
80
|
+
if (!isObject(values)) return {};
|
|
81
|
+
return Object.fromEntries(Object.entries(values).map(([name, value]) => [name, manifest[name] ? fromFormValue(manifest[name], value, timeZone) : value]));
|
|
82
|
+
}
|
|
83
|
+
export { fromFormValues, toFormValues };
|
|
84
|
+
|
|
85
|
+
//# sourceMappingURL=form-values.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"form-values.js","names":[],"sources":["../../src/form/form-values.ts"],"sourcesContent":["/**\n * 单据的值在线上(json-wire 还原后)与在表单里的两种形状,按字段清单互换:\n *\n * | 字段类型 | 线上 | 表单里 |\n * | --- | --- | --- |\n * | date | CalendarDate | 'YYYY-MM-DD'(DatePicker 的值) |\n * | datetime | ZonedDateTime | 不带时区的 'YYYY-MM-DDTHH:mm:ss',按 timeZone 换算 |\n * | select | 选项的值(文字或数字) | 文字(组件库的选项值是文字) |\n * | file | `{ id, name, size, url? }` | Upload 的文件(上传返回的 `{ id, url }` 记在 response 上) |\n *\n * 其余(文字、数字、Decimal、布尔、人员)两边一样。清单里没有的键原样留着。\n */\nimport {\n parseDateTime,\n type CalendarDate,\n toCalendarDateTime,\n toTimeZone,\n toZoned,\n type ZonedDateTime,\n} from '@internationalized/date';\nimport { typedValue, type FieldDefinition, type FormManifest } from '@zerodep-dev/flow-ts-model';\n\n/** 文字里写了时区(Z、+08:00、[Asia/Shanghai]):是线上的时刻,不是表单里的本地写法 */\nconst hasZone = (text: string) => /(?:[zZ]|[+-]\\d{2}:?\\d{2})(?:\\[[^\\]]+\\])?$/.test(text);\n\nconst isObject = (value: unknown): value is Record<string, unknown> =>\n typeof value === 'object' && value !== null && !Array.isArray(value);\n\n/** 值是数组的字段:人员、附件、明细表、多选 */\nconst holdsList = (field: FieldDefinition) =>\n field.type === 'people' ||\n field.type === 'file' ||\n field.type === 'list' ||\n (field.type === 'select' && field.multiple === true);\n\n/** 一个值从线上换成表单里的;数组型的字段没填(null)时是空数组,组件只认数组 */\nfunction toFormValue(field: FieldDefinition, value: unknown, timeZone: string): unknown {\n if (value === null || value === undefined) return holdsList(field) ? [] : value;\n switch (field.type) {\n case 'date':\n return typeof value === 'string' ? value : (value as CalendarDate).toString();\n case 'decimal':\n // 引擎存的是文字('12.50'):表单里是 Decimal(NumberField 按它精确运算)\n return typeof value === 'string' ? typedValue(field, value) : value;\n case 'datetime': {\n // 存的是带时区的文字('…Z')或 ZonedDateTime:换算成这个时区的本地时间;已经是本地写法的原样\n const zoned = typeof value === 'string' && hasZone(value) ? typedValue(field, value) : value;\n if (typeof zoned === 'string') return zoned;\n return toCalendarDateTime(toTimeZone(zoned as ZonedDateTime, timeZone)).toString();\n }\n case 'select':\n // 选项的值是文字或数字\n return Array.isArray(value)\n ? value.map((item: string | number) => String(item))\n : String(value as string | number);\n case 'file':\n return Array.isArray(value)\n ? value.map((file: { id: string; name: string; size?: number; url?: string }) => ({\n id: file.id,\n name: file.name,\n size: file.size,\n status: 'done',\n ...(file.url && { url: file.url }),\n response: { id: file.id, url: file.url },\n }))\n : value;\n case 'list':\n return Array.isArray(value)\n ? value.map((row) => toFormValues(field.fields ?? {}, row, timeZone))\n : value;\n default:\n return value;\n }\n}\n\n/** 一个值从表单里换成线上的(强类型的读成 Decimal、CalendarDate、ZonedDateTime) */\nfunction fromFormValue(field: FieldDefinition, value: unknown, timeZone: string): unknown {\n if (value === null || value === undefined || value === '') return value;\n switch (field.type) {\n case 'datetime':\n if (typeof value !== 'string') return value;\n // 带时区的文字直接读;表单里的本地写法按 timeZone 换算\n return hasZone(value) ? typedValue(field, value) : toZoned(parseDateTime(value), timeZone);\n case 'select': {\n const options = Array.isArray(field.options) ? field.options : [];\n const original = (item: unknown) =>\n options.find((option) => String(option.value) === item)?.value ?? item;\n return Array.isArray(value) ? value.map(original) : original(value);\n }\n case 'file':\n return Array.isArray(value)\n ? value.map((file: { id: string; name: string; size?: number; response?: unknown }) => {\n const response = isObject(file.response) ? file.response : {};\n return {\n id: typeof response.id === 'string' ? response.id : file.id,\n name: file.name,\n size: file.size ?? 0,\n ...(typeof response.url === 'string' && { url: response.url }),\n };\n })\n : value;\n case 'list':\n return Array.isArray(value)\n ? value.map((row) => fromFormValues(field.fields ?? {}, row, timeZone))\n : value;\n default:\n return typedValue(field, value);\n }\n}\n\n/** 单据的值(线上的形状)→ 表单里的;timeZone 是日期时间按哪个时区显示 */\nexport function toFormValues(\n manifest: FormManifest,\n values: unknown,\n timeZone: string,\n): Record<string, unknown> {\n if (!isObject(values)) return {};\n return Object.fromEntries(\n Object.entries(values).map(([name, value]) => [\n name,\n manifest[name] ? toFormValue(manifest[name], value, timeZone) : value,\n ]),\n );\n}\n\n/** 表单里的值 → 单据的值(线上的形状):交给引擎的发起、处理 */\nexport function fromFormValues(\n manifest: FormManifest,\n values: unknown,\n timeZone: string,\n): Record<string, unknown> {\n if (!isObject(values)) return {};\n return Object.fromEntries(\n Object.entries(values).map(([name, value]) => [\n name,\n manifest[name] ? fromFormValue(manifest[name], value, timeZone) : value,\n ]),\n );\n}\n"],"mappings":";;;;;;;;;;;;;;;;AAuBA,IAAM,WAAW,SAAiB,4CAA4C,KAAK,IAAI;AAEvF,IAAM,YAAY,UAChB,OAAO,UAAU,YAAY,UAAU,QAAQ,CAAC,MAAM,QAAQ,KAAK;;AAGrE,IAAM,aAAa,UACjB,MAAM,SAAS,YACf,MAAM,SAAS,UACf,MAAM,SAAS,UACd,MAAM,SAAS,YAAY,MAAM,aAAa;;AAGjD,SAAS,YAAY,OAAwB,OAAgB,UAA2B;CACtF,IAAI,UAAU,QAAQ,UAAU,KAAA,GAAW,OAAO,UAAU,KAAK,IAAI,CAAC,IAAI;CAC1E,QAAQ,MAAM,MAAd;EACE,KAAK,QACH,OAAO,OAAO,UAAU,WAAW,QAAS,MAAuB,SAAS;EAC9E,KAAK,WAEH,OAAO,OAAO,UAAU,WAAW,WAAW,OAAO,KAAK,IAAI;EAChE,KAAK,YAAY;GAEf,MAAM,QAAQ,OAAO,UAAU,YAAY,QAAQ,KAAK,IAAI,WAAW,OAAO,KAAK,IAAI;GACvF,IAAI,OAAO,UAAU,UAAU,OAAO;GACtC,OAAO,mBAAmB,WAAW,OAAwB,QAAQ,CAAC,CAAC,CAAC,SAAS;EACnF;EACA,KAAK,UAEH,OAAO,MAAM,QAAQ,KAAK,IACtB,MAAM,KAAK,SAA0B,OAAO,IAAI,CAAC,IACjD,OAAO,KAAwB;EACrC,KAAK,QACH,OAAO,MAAM,QAAQ,KAAK,IACtB,MA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,MAAM,KAAK,QAAQ,eAAe,MAAM,UAAU,CAAC,GAAG,KAAK,QAAQ,CAAC,IACpE;EACN,SACE,OAAO,WAAW,OAAO,KAAK;CAClC;AACF;;AAGA,SAAgB,aACd,UACA,QACA,UACyB;CACzB,IAAI,CAAC,SAAS,MAAM,GAAG,OAAO,CAAC;CAC/B,OAAO,OAAO,YACZ,OAAO,QAAQ,MAAM,CAAC,CAAC,KAAK,CAAC,MAAM,WAAW,CAC5C,MACA,SAAS,QAAQ,YAAY,SAAS,OAAO,OAAO,QAAQ,IAAI,KAClE,CAAC,CACH;AACF;;AAGA,SAAgB,eACd,UACA,QACA,UACyB;CACzB,IAAI,CAAC,SAAS,MAAM,GAAG,OAAO,CAAC;CAC/B,OAAO,OAAO,YACZ,OAAO,QAAQ,MAAM,CAAC,CAAC,KAAK,CAAC,MAAM,WAAW,CAC5C,MACA,SAAS,QAAQ,cAAc,SAAS,OAAO,OAAO,QAAQ,IAAI,KACpE,CAAC,CACH;AACF"}
|
|
@@ -0,0 +1,95 @@
|
|
|
1
|
+
import { decimalSchema } from "@zerodep-dev/vue-tsx-pro-ui";
|
|
2
|
+
import Decimal from "decimal.js";
|
|
3
|
+
import { z } from "zod";
|
|
4
|
+
// src/form/manifest-schema.ts
|
|
5
|
+
/**
|
|
6
|
+
* 字段清单 → 组件库表单用的 zod schema:类型、范围、选项与控件写进 schema 与 meta,SchemaForm、SchemaView 照它生成字段。
|
|
7
|
+
*
|
|
8
|
+
* 必填、显示、能不能改不在这里:它们随节点与值变,由 {@link manifestAccess} 按模型包的 fieldStates 合算(与后端同一套规则),
|
|
9
|
+
* 交给 useForm 的 access。所以每个字段在 schema 里都可以空着,范围、格式这些也只查有值的(同模型包的 checkFieldValue)。
|
|
10
|
+
*
|
|
11
|
+
* 值在表单里的形状见 form-values.ts:日期、日期时间是 ISO 文字,选项的值是文字,decimal 是 Decimal。
|
|
12
|
+
*/
|
|
13
|
+
/** 文字长度、格式:空着不查(必填另算);问题用 zod 的标准错误码,提示跟着使用方配置的 zod 语言 */
|
|
14
|
+
function textSchema(field) {
|
|
15
|
+
const { minLength, maxLength, pattern } = field;
|
|
16
|
+
const regex = pattern === void 0 ? void 0 : new RegExp(`^(?:${pattern})$`, "u");
|
|
17
|
+
return (maxLength === void 0 ? z.string() : z.string().max(maxLength)).check((ctx) => {
|
|
18
|
+
const value = ctx.value;
|
|
19
|
+
if (value === "") return;
|
|
20
|
+
if (minLength !== void 0 && value.length < minLength) ctx.issues.push({
|
|
21
|
+
code: "too_small",
|
|
22
|
+
origin: "string",
|
|
23
|
+
minimum: minLength,
|
|
24
|
+
inclusive: true,
|
|
25
|
+
input: value
|
|
26
|
+
});
|
|
27
|
+
if (regex && !regex.test(value)) ctx.issues.push({
|
|
28
|
+
code: "invalid_format",
|
|
29
|
+
format: "regex",
|
|
30
|
+
pattern,
|
|
31
|
+
input: value
|
|
32
|
+
});
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
/** 一个字段的 schema(不含 meta) */
|
|
36
|
+
function valueSchema(field) {
|
|
37
|
+
switch (field.type) {
|
|
38
|
+
case "text": return textSchema(field);
|
|
39
|
+
case "number": {
|
|
40
|
+
let schema = field.integer ? z.number().int() : z.number();
|
|
41
|
+
if (typeof field.min === "number") schema = schema.min(field.min);
|
|
42
|
+
if (typeof field.max === "number") schema = schema.max(field.max);
|
|
43
|
+
return schema;
|
|
44
|
+
}
|
|
45
|
+
case "decimal": return decimalSchema({
|
|
46
|
+
...field.min !== void 0 && { min: String(field.min) },
|
|
47
|
+
...field.max !== void 0 && { max: String(field.max) },
|
|
48
|
+
...field.scale !== void 0 && { scale: field.scale },
|
|
49
|
+
type: Decimal
|
|
50
|
+
});
|
|
51
|
+
case "boolean": return z.boolean();
|
|
52
|
+
case "date": return z.iso.date();
|
|
53
|
+
case "datetime": return z.iso.datetime({ local: true });
|
|
54
|
+
case "select": {
|
|
55
|
+
const one = Array.isArray(field.options) ? z.enum(field.options.map((option) => String(option.value))) : z.string();
|
|
56
|
+
return field.multiple ? z.array(one) : one;
|
|
57
|
+
}
|
|
58
|
+
case "people": return z.array(z.object({
|
|
59
|
+
id: z.union([z.string(), z.number()]),
|
|
60
|
+
type: z.string()
|
|
61
|
+
}).loose());
|
|
62
|
+
case "file": return z.array(z.object({
|
|
63
|
+
id: z.string(),
|
|
64
|
+
name: z.string()
|
|
65
|
+
}).loose());
|
|
66
|
+
case "list": {
|
|
67
|
+
let schema = z.array(manifestSchema(field.fields ?? {}));
|
|
68
|
+
if (field.minItems !== void 0) schema = schema.min(field.minItems);
|
|
69
|
+
if (field.maxItems !== void 0) schema = schema.max(field.maxItems);
|
|
70
|
+
return schema;
|
|
71
|
+
}
|
|
72
|
+
default: return z.unknown();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
/** 字段的 meta:标签、说明、控件、选项 */
|
|
76
|
+
function metaOf(field) {
|
|
77
|
+
const meta = { title: field.label };
|
|
78
|
+
if (field.description) meta.description = field.description;
|
|
79
|
+
if (field.type === "select") {
|
|
80
|
+
if (field.options && "source" in field.options) meta.source = field.options.source;
|
|
81
|
+
else if (field.options) meta.options = Object.fromEntries(field.options.map((option) => [String(option.value), option.label]));
|
|
82
|
+
if (field.multiple) meta.control = "multiselect";
|
|
83
|
+
}
|
|
84
|
+
if (field.type === "people") meta.control = "people";
|
|
85
|
+
if (field.type === "file") meta.control = "file";
|
|
86
|
+
if (field.type === "list") meta.control = "table";
|
|
87
|
+
return meta;
|
|
88
|
+
}
|
|
89
|
+
/** 字段清单 → zod schema:交给 useForm(useFlowForm 已经接好)、SchemaForm、SchemaView */
|
|
90
|
+
function manifestSchema(manifest) {
|
|
91
|
+
return z.object(Object.fromEntries(Object.entries(manifest).map(([name, field]) => [name, valueSchema(field).nullable().optional().meta(metaOf(field))])));
|
|
92
|
+
}
|
|
93
|
+
export { manifestSchema };
|
|
94
|
+
|
|
95
|
+
//# sourceMappingURL=manifest-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"manifest-schema.js","names":[],"sources":["../../src/form/manifest-schema.ts"],"sourcesContent":["/**\n * 字段清单 → 组件库表单用的 zod schema:类型、范围、选项与控件写进 schema 与 meta,SchemaForm、SchemaView 照它生成字段。\n *\n * 必填、显示、能不能改不在这里:它们随节点与值变,由 {@link manifestAccess} 按模型包的 fieldStates 合算(与后端同一套规则),\n * 交给 useForm 的 access。所以每个字段在 schema 里都可以空着,范围、格式这些也只查有值的(同模型包的 checkFieldValue)。\n *\n * 值在表单里的形状见 form-values.ts:日期、日期时间是 ISO 文字,选项的值是文字,decimal 是 Decimal。\n */\nimport { decimalSchema } from '@zerodep-dev/vue-tsx-pro-ui';\nimport type { FieldDefinition, FormManifest } from '@zerodep-dev/flow-ts-model';\nimport Decimal from 'decimal.js';\nimport { z } from 'zod';\n\n/** 文字长度、格式:空着不查(必填另算);问题用 zod 的标准错误码,提示跟着使用方配置的 zod 语言 */\nfunction textSchema(field: FieldDefinition) {\n const { minLength, maxLength, pattern } = field;\n const regex = pattern === undefined ? undefined : new RegExp(`^(?:${pattern})$`, 'u');\n const schema = maxLength === undefined ? z.string() : z.string().max(maxLength);\n return schema.check((ctx) => {\n const value = ctx.value;\n if (value === '') return;\n if (minLength !== undefined && value.length < minLength)\n ctx.issues.push({\n code: 'too_small',\n origin: 'string',\n minimum: minLength,\n inclusive: true,\n input: value,\n });\n if (regex && !regex.test(value))\n ctx.issues.push({ code: 'invalid_format', format: 'regex', pattern: pattern!, input: value });\n });\n}\n\n/** 一个字段的 schema(不含 meta) */\nfunction valueSchema(field: FieldDefinition): z.ZodType {\n switch (field.type) {\n case 'text':\n return textSchema(field);\n case 'number': {\n let schema = field.integer ? z.number().int() : z.number();\n if (typeof field.min === 'number') schema = schema.min(field.min);\n if (typeof field.max === 'number') schema = schema.max(field.max);\n return schema;\n }\n case 'decimal':\n return decimalSchema({\n ...(field.min !== undefined && { min: String(field.min) }),\n ...(field.max !== undefined && { max: String(field.max) }),\n ...(field.scale !== undefined && { scale: field.scale }),\n type: Decimal,\n });\n case 'boolean':\n return z.boolean();\n case 'date':\n return z.iso.date();\n case 'datetime':\n return z.iso.datetime({ local: true });\n case 'select': {\n // 组件库的选项值是文字:数字选项在表单里写成文字,提交时换回(form-values.ts)\n const one = Array.isArray(field.options)\n ? z.enum(field.options.map((option) => String(option.value)) as [string, ...string[]])\n : z.string();\n return field.multiple ? z.array(one) : one;\n }\n case 'people':\n return z.array(z.object({ id: z.union([z.string(), z.number()]), type: z.string() }).loose());\n case 'file':\n return z.array(z.object({ id: z.string(), name: z.string() }).loose());\n case 'list': {\n let schema = z.array(manifestSchema(field.fields ?? {}));\n if (field.minItems !== undefined) schema = schema.min(field.minItems);\n if (field.maxItems !== undefined) schema = schema.max(field.maxItems);\n return schema;\n }\n default:\n // 接入方注册的字段类型:值的形状由注册的实现定,表单这边不约束\n return z.unknown();\n }\n}\n\n/** 字段的 meta:标签、说明、控件、选项 */\nfunction metaOf(field: FieldDefinition): Record<string, unknown> {\n const meta: Record<string, unknown> = { title: field.label };\n if (field.description) meta.description = field.description;\n if (field.type === 'select') {\n // Array.isArray 收窄不了只读数组,按有没有 source 分\n if (field.options && 'source' in field.options) meta.source = field.options.source;\n else if (field.options)\n meta.options = Object.fromEntries(\n field.options.map((option) => [String(option.value), option.label]),\n );\n if (field.multiple) meta.control = 'multiselect';\n }\n if (field.type === 'people') meta.control = 'people';\n if (field.type === 'file') meta.control = 'file';\n if (field.type === 'list') meta.control = 'table';\n return meta;\n}\n\n/** 字段清单 → zod schema:交给 useForm(useFlowForm 已经接好)、SchemaForm、SchemaView */\nexport function manifestSchema(manifest: FormManifest): z.ZodObject {\n return z.object(\n Object.fromEntries(\n Object.entries(manifest).map(([name, field]) => [\n name,\n valueSchema(field).nullable().optional().meta(metaOf(field)),\n ]),\n ),\n );\n}\n"],"mappings":";;;;;;;;;;;;;AAcA,SAAS,WAAW,OAAwB;CAC1C,MAAM,EAAE,WAAW,WAAW,YAAY;CAC1C,MAAM,Q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