@vef-framework-react/approval-form-bridge 2.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/README +62 -0
- package/dist/cjs/index.cjs +1 -0
- package/dist/cjs/issues.cjs +1 -0
- package/dist/cjs/project.cjs +1 -0
- package/dist/cjs/registry.cjs +1 -0
- package/dist/cjs/validate.cjs +1 -0
- package/dist/es/index.js +5 -0
- package/dist/es/issues.js +84 -0
- package/dist/es/project.js +173 -0
- package/dist/es/registry.js +18 -0
- package/dist/es/validate.js +18 -0
- package/dist/types/contract.d.ts +76 -0
- package/dist/types/index.d.ts +5 -0
- package/dist/types/issues.d.ts +32 -0
- package/dist/types/project.d.ts +39 -0
- package/dist/types/project.test.d.ts +1 -0
- package/dist/types/registry.d.ts +25 -0
- package/dist/types/registry.test.d.ts +1 -0
- package/dist/types/validate.d.ts +27 -0
- package/dist/types/validate.test.d.ts +1 -0
- package/package.json +63 -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 [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.
|
package/README
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
# @vef-framework-react/approval-form-bridge
|
|
2
|
+
|
|
3
|
+
Projection bridge from `@vef-framework-react/form-editor` schemas to the approval form contract
|
|
4
|
+
(`approval/form_definition.go` in the Go backend), plus the approval capability profile for the designer.
|
|
5
|
+
|
|
6
|
+
## Installation
|
|
7
|
+
|
|
8
|
+
```bash
|
|
9
|
+
pnpm add @vef-framework-react/approval-form-bridge
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
## Usage
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
import {
|
|
16
|
+
createApprovalRegistries,
|
|
17
|
+
projectFormSchema,
|
|
18
|
+
validateApprovalSchema
|
|
19
|
+
} from "@vef-framework-react/approval-form-bridge";
|
|
20
|
+
|
|
21
|
+
// 1. Design under the approval profile (no switch / daterange / button).
|
|
22
|
+
// The registries prop is honored on first mount only — keep one instance.
|
|
23
|
+
const [registries] = useState(createApprovalRegistries);
|
|
24
|
+
<FormEditor registries={registries} onSchemaChange={setSchema} />;
|
|
25
|
+
|
|
26
|
+
// 2. One projection feeds every consumer.
|
|
27
|
+
const { definition, formFields, issues, valid } = projectFormSchema(schema);
|
|
28
|
+
// definition → DeployFlowCmd.FormDefinition (backend payload)
|
|
29
|
+
// formFields → ApprovalFlowEditor plugins.formFields (condition / permission editors)
|
|
30
|
+
// valid → gate persistence on it; errors are contract-breaking
|
|
31
|
+
|
|
32
|
+
// 3. Save-time gate (structural validateSchema + projection in one pass).
|
|
33
|
+
const gate = validateApprovalSchema(candidate, registries);
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
## Projection rules
|
|
37
|
+
|
|
38
|
+
- Only root-scope keyed nodes project; both device presentations are walked (pc wins a key collision,
|
|
39
|
+
mobile-only fields still project — the backend's form data is a closed contract).
|
|
40
|
+
- A subform becomes a single-level `table` field: template leaves are its columns, layout containers in
|
|
41
|
+
the template are transparent, a nested subform is an error. `minRows` / `maxRows` map to
|
|
42
|
+
`validation.minLength` / `maxLength` (row-count bounds); `minRows >= 1` sets `isRequired`.
|
|
43
|
+
- `switch` (boolean) and `daterange` (array) are unprojectable — the Go runtime validates `input` /
|
|
44
|
+
`date` values as strings — and raise error issues. Unknown keyed widget types do too, never a silent drop.
|
|
45
|
+
- Options: static (inline or referenced) inline into `options`; remote sources omit `options` with a
|
|
46
|
+
warning — the backend then accepts any submitted value.
|
|
47
|
+
- `columnType` is emitted from the explicit designer override, else from `inferColumnType` — EXCEPT a
|
|
48
|
+
precision-less number, which stays ungated (no columnType): the backend enforces `integer` at submit
|
|
49
|
+
time regardless of storage mode, so auto-inferring it would reject every fractional value. Configure a
|
|
50
|
+
`precision` (→ `decimal` + `scale`) or pin the type explicitly when you want the gate.
|
|
51
|
+
- A `pattern` using constructs RE2 does not support (lookahead / lookbehind / backreferences) is an
|
|
52
|
+
error: JS accepts them, the Go deploy rejects them.
|
|
53
|
+
- Cross-device conflicts on a shared key are errors when they break the submit contract: different
|
|
54
|
+
projected kinds, or a detail table whose column sets differ. Same-kind divergence in options /
|
|
55
|
+
validation between devices is NOT detected (pc wins silently) — keep those aligned by hand.
|
|
56
|
+
- Linkage does not survive projection (warning): a linkage-hidden field's value is dropped from the
|
|
57
|
+
submit payload, which can conflict with a static `isRequired`.
|
|
58
|
+
- Under `table` storage the backend additionally constrains field keys at deploy time (reserved column
|
|
59
|
+
names such as `id` / `instance_id` / `row_index` / `created_at`, case-insensitive uniqueness, ≤63
|
|
60
|
+
chars, no leading digit). The bridge does not pre-check these — it cannot know the storage mode.
|
|
61
|
+
- `defaultValue` and `props` are declared on the contract but never emitted today (no designer source /
|
|
62
|
+
no consumer) — they are the extension points for host-enriched definitions.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./project.cjs"),t=require("./registry.cjs"),n=require("./validate.cjs");exports.APPROVAL_EXCLUDED_FIELD_TYPES=t.APPROVAL_EXCLUDED_FIELD_TYPES,exports.createApprovalRegistries=t.createApprovalRegistries,exports.projectFormSchema=e.projectFormSchema,exports.validateApprovalSchema=n.validateApprovalSchema;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e,t){return{path:e,code:`unmappable_field_type`,severity:`error`,message:`字段 "${e}" 的控件类型 "${t}" 无法映射到审批表单契约(值形状与服务端校验不兼容)`}}function t(e,t){return{path:e,code:`unknown_field_type_unprojectable`,severity:`error`,message:`字段 "${e}" 的控件类型 "${t}" 未注册,无法投影(审批表单数据是封闭契约,未投影的字段会导致提交被拒)`}}function n(e){return{path:e,code:`nested_subform_unsupported`,severity:`error`,message:`明细表模板中嵌套了子表 "${e}",审批明细表仅支持单级`}}function r(e){return{path:e,code:`table_columns_empty`,severity:`error`,message:`明细表 "${e}" 没有可投影的列`}}function i(e){return{path:e,code:`pattern_unsupported`,severity:`error`,message:`字段 "${e}" 的正则包含服务端(RE2)不支持的构造(lookahead / lookbehind / 反向引用),部署将被拒绝`}}function a(e){return{path:e,code:`decimal_scale_missing`,severity:`warning`,message:`字段 "${e}" 的列类型为 decimal 但未配置小数位数(precision),独立表存储将按 0 位小数舍入`}}function o(e){return{path:e,code:`options_not_static`,severity:`warning`,message:`字段 "${e}" 的选项来源无法静态解析,投影结果不含选项(服务端将放行任意选项值)`}}function s(e){return{path:e,code:`linkage_not_projected`,severity:`warning`,message:`字段 "${e}" 配置了联动规则,审批服务端不理解联动(被联动隐藏的字段不提交值,可能与必填校验冲突)`}}function c(e,t,n){return{path:e,code:`cross_device_kind_mismatch`,severity:`error`,message:`字段 "${e}" 在 PC 与移动端映射到不同的类型("${t}" / "${n}"),投影以 PC 为准——另一端提交的值形状不符,提交将被服务端拒绝`}}function l(e){return{path:e,code:`cross_device_table_mismatch`,severity:`error`,message:`明细表 "${e}" 在 PC 与移动端的列结构不一致,投影以 PC 为准——另一端提交的行包含未定义的列,提交将被服务端拒绝`}}exports.issueCrossDeviceKindMismatch=c,exports.issueCrossDeviceTableMismatch=l,exports.issueDecimalScaleMissing=a,exports.issueLinkageNotProjected=s,exports.issueNestedSubform=n,exports.issueOptionsNotStatic=o,exports.issuePatternUnsupported=i,exports.issueTableColumnsEmpty=r,exports.issueUnknownFieldType=t,exports.issueUnmappableFieldType=e;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require("./issues.cjs");let t=require("@vef-framework-react/form-editor");var n={textfield:`input`,"code-editor":`textarea`,textarea:`textarea`,number:`number`,select:`select`,radio:`select`,"checkbox-group":`select`,date:`date`,datetime:`date`},r=new Set([`switch`,`daterange`]);function i(n){let r=[],i=[],l=[],u=new Map((n.dataSources??[]).map(e=>[e.id,e])),d=new Map;for(let f of[n.presentations.pc,n.presentations.mobile])f!==void 0&&(0,t.walkNodes)(f,(n,f)=>{if(f.length>0||!(0,t.isKeyedNode)(n))return;let p=d.get(n.key);if(p!==void 0){if(p!==null){let t=a(n);t!==null&&t!==p.kind?r.push(e.issueCrossDeviceKindMismatch(n.key,p.kind,t)):t===`table`&&p.tableSignature!==void 0&&o(n)!==p.tableSignature&&r.push(e.issueCrossDeviceTableMismatch(n.key))}return}let m=n.type===`subform`,h=m?c(n,u,r):s(n,n.key,u,r);d.set(n.key,h===void 0?null:{kind:h.approval.kind,...m&&{tableSignature:o(n)}}),h!==void 0&&(i.push({...h.approval,sortOrder:i.length}),l.push(h.flow))});return{definition:{fields:i},formFields:l,issues:r,valid:r.every(e=>e.severity!==`error`)}}function a(e){return e.type===`subform`?`table`:n[e.type]??null}function o(e){let r=[],i=new Set;return(0,t.walkNodes)({children:e.template},(e,a)=>{a.length>0||!(0,t.isKeyedNode)(e)||i.has(e.key)||(i.add(e.key),r.push(`${e.key}:${e.type===`subform`?`table`:n[e.type]??`?`}`))}),r.join(`,`)}function s(t,i,a,o){let s=n[t.type];if(s===void 0){o.push(r.has(t.type)?e.issueUnmappableFieldType(i,t.type):e.issueUnknownFieldType(i,t.type));return}p(t,i,o);let c=t.label??t.key,m=l(t,i,a,o),{isRequired:h,rule:g}=f(t),_=u(t),{precision:v}=t,{placeholder:y}=t,b=v!==void 0&&v>0;return g?.pattern!==void 0&&d(g.pattern)&&o.push(e.issuePatternUnsupported(i)),_===`decimal`&&!b&&o.push(e.issueDecimalScaleMissing(i)),{approval:{key:t.key,kind:s,label:c,...y!==void 0&&{placeholder:y},...h&&{isRequired:h},...m!==void 0&&{options:m},...g!==void 0&&{validation:g},..._!==void 0&&{columnType:_},..._===`decimal`&&b&&{scale:v}},flow:{key:t.key,kind:s,label:c,...m!==void 0&&{options:m}}}}function c(n,r,i){let a=[],o=[],c=new Set,l=!1;if((0,t.walkNodes)({children:n.template},(u,d)=>{if(d.length>0||!(0,t.isKeyedNode)(u)||c.has(u.key))return;if(c.add(u.key),u.type===`subform`){l=!0,i.push(e.issueNestedSubform(`${n.key}.${u.key}`));return}let f=s(u,`${n.key}.${u.key}`,r,i);f!==void 0&&(a.push({...f.approval,sortOrder:a.length}),o.push(f.flow))}),a.length===0){l||i.push(e.issueTableColumnsEmpty(n.key));return}p(n,n.key,i);let u=n.label??n.key,d=(n.minRows??0)>=1,f={...n.minRows!==void 0&&n.minRows>0&&{minLength:n.minRows},...n.maxRows!==void 0&&{maxLength:n.maxRows}},m=f.minLength!==void 0||f.maxLength!==void 0;return{approval:{key:n.key,kind:`table`,label:u,...d&&{isRequired:d},...m&&{validation:f},columns:a},flow:{key:n.key,kind:`table`,label:u,columns:o}}}function l(t,n,r,i){let a=t.dataSource;if(a!==void 0){if(a.kind===`static`)return a.options;if(a.kind===`ref`){let e=r.get(a.dataSourceId);if(e?.kind===`static`)return e.options}i.push(e.issueOptionsNotStatic(n))}}function u(e){if(e.columnType!==void 0)return e.columnType;let n=(0,t.inferColumnType)(e);return e.type===`number`&&n===`integer`?void 0:n}function d(e){let t=!1;for(let n=0;n<e.length;n++){let r=e[n];if(r===`\\`){let r=e[n+1];if(!t&&r!==void 0&&r>=`1`&&r<=`9`)return!0;n++;continue}if(r===`[`){t=!0;continue}if(r===`]`){t=!1;continue}if(!t&&r===`(`&&e[n+1]===`?`){let t=e.slice(n+2);if(t.startsWith(`=`)||t.startsWith(`!`)||t.startsWith(`<=`)||t.startsWith(`<!`))return!0}}return!1}function f(e){let{required:t,...n}=e.validate??{},r=Object.entries(n).filter(([,e])=>e!==void 0);return{isRequired:t===!0,...r.length>0&&{rule:Object.fromEntries(r)}}}function p(t,n,r){let{linkage:i}=t;i!==void 0&&(i.defaults!==void 0||(i.rules?.length??0)>0)&&r.push(e.issueLinkageNotProjected(n))}exports.projectFormSchema=i;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
let e=require("@vef-framework-react/form-editor");var t=[`switch`,`daterange`,`button`];function n(){let n=(0,e.createDefaultRegistry)(),r=(0,e.createDefaultMobileRegistry)();for(let e of t)n.unregister(e),r.unregister(e);return{pc:n,mobile:r}}exports.APPROVAL_EXCLUDED_FIELD_TYPES=t,exports.createApprovalRegistries=n;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
const e=require("./project.cjs");let t=require("@vef-framework-react/form-editor");function n(n,r){let i=(0,t.validateSchema)(n,r);if(i.schema===void 0)return{valid:!1,issues:i.issues};let a=e.projectFormSchema(i.schema);return{valid:i.valid&&a.valid,issues:[...i.issues,...a.issues]}}exports.validateApprovalSchema=n;
|
package/dist/es/index.js
ADDED
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
/*! @vef-framework-react/approval-form-bridge v2.8.0 made by Venus | 2026-07-07T01:44:11.626Z */
|
|
2
|
+
import { projectFormSchema as e } from "./project.js";
|
|
3
|
+
import { APPROVAL_EXCLUDED_FIELD_TYPES as t, createApprovalRegistries as n } from "./registry.js";
|
|
4
|
+
import { validateApprovalSchema as r } from "./validate.js";
|
|
5
|
+
export { t as APPROVAL_EXCLUDED_FIELD_TYPES, n as createApprovalRegistries, e as projectFormSchema, r as validateApprovalSchema };
|
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
/*! @vef-framework-react/approval-form-bridge v2.8.0 made by Venus | 2026-07-07T01:44:11.626Z */
|
|
2
|
+
//#region src/issues.ts
|
|
3
|
+
function e(e, t) {
|
|
4
|
+
return {
|
|
5
|
+
path: e,
|
|
6
|
+
code: "unmappable_field_type",
|
|
7
|
+
severity: "error",
|
|
8
|
+
message: `字段 "${e}" 的控件类型 "${t}" 无法映射到审批表单契约(值形状与服务端校验不兼容)`
|
|
9
|
+
};
|
|
10
|
+
}
|
|
11
|
+
function t(e, t) {
|
|
12
|
+
return {
|
|
13
|
+
path: e,
|
|
14
|
+
code: "unknown_field_type_unprojectable",
|
|
15
|
+
severity: "error",
|
|
16
|
+
message: `字段 "${e}" 的控件类型 "${t}" 未注册,无法投影(审批表单数据是封闭契约,未投影的字段会导致提交被拒)`
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
function n(e) {
|
|
20
|
+
return {
|
|
21
|
+
path: e,
|
|
22
|
+
code: "nested_subform_unsupported",
|
|
23
|
+
severity: "error",
|
|
24
|
+
message: `明细表模板中嵌套了子表 "${e}",审批明细表仅支持单级`
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
function r(e) {
|
|
28
|
+
return {
|
|
29
|
+
path: e,
|
|
30
|
+
code: "table_columns_empty",
|
|
31
|
+
severity: "error",
|
|
32
|
+
message: `明细表 "${e}" 没有可投影的列`
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
function i(e) {
|
|
36
|
+
return {
|
|
37
|
+
path: e,
|
|
38
|
+
code: "pattern_unsupported",
|
|
39
|
+
severity: "error",
|
|
40
|
+
message: `字段 "${e}" 的正则包含服务端(RE2)不支持的构造(lookahead / lookbehind / 反向引用),部署将被拒绝`
|
|
41
|
+
};
|
|
42
|
+
}
|
|
43
|
+
function a(e) {
|
|
44
|
+
return {
|
|
45
|
+
path: e,
|
|
46
|
+
code: "decimal_scale_missing",
|
|
47
|
+
severity: "warning",
|
|
48
|
+
message: `字段 "${e}" 的列类型为 decimal 但未配置小数位数(precision),独立表存储将按 0 位小数舍入`
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
function o(e) {
|
|
52
|
+
return {
|
|
53
|
+
path: e,
|
|
54
|
+
code: "options_not_static",
|
|
55
|
+
severity: "warning",
|
|
56
|
+
message: `字段 "${e}" 的选项来源无法静态解析,投影结果不含选项(服务端将放行任意选项值)`
|
|
57
|
+
};
|
|
58
|
+
}
|
|
59
|
+
function s(e) {
|
|
60
|
+
return {
|
|
61
|
+
path: e,
|
|
62
|
+
code: "linkage_not_projected",
|
|
63
|
+
severity: "warning",
|
|
64
|
+
message: `字段 "${e}" 配置了联动规则,审批服务端不理解联动(被联动隐藏的字段不提交值,可能与必填校验冲突)`
|
|
65
|
+
};
|
|
66
|
+
}
|
|
67
|
+
function c(e, t, n) {
|
|
68
|
+
return {
|
|
69
|
+
path: e,
|
|
70
|
+
code: "cross_device_kind_mismatch",
|
|
71
|
+
severity: "error",
|
|
72
|
+
message: `字段 "${e}" 在 PC 与移动端映射到不同的类型("${t}" / "${n}"),投影以 PC 为准——另一端提交的值形状不符,提交将被服务端拒绝`
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
function l(e) {
|
|
76
|
+
return {
|
|
77
|
+
path: e,
|
|
78
|
+
code: "cross_device_table_mismatch",
|
|
79
|
+
severity: "error",
|
|
80
|
+
message: `明细表 "${e}" 在 PC 与移动端的列结构不一致,投影以 PC 为准——另一端提交的行包含未定义的列,提交将被服务端拒绝`
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
//#endregion
|
|
84
|
+
export { c as issueCrossDeviceKindMismatch, l as issueCrossDeviceTableMismatch, a as issueDecimalScaleMissing, s as issueLinkageNotProjected, n as issueNestedSubform, o as issueOptionsNotStatic, i as issuePatternUnsupported, r as issueTableColumnsEmpty, t as issueUnknownFieldType, e as issueUnmappableFieldType };
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/*! @vef-framework-react/approval-form-bridge v2.8.0 made by Venus | 2026-07-07T01:44:11.626Z */
|
|
2
|
+
import { issueCrossDeviceKindMismatch as e, issueCrossDeviceTableMismatch as t, issueDecimalScaleMissing as n, issueLinkageNotProjected as r, issueNestedSubform as i, issueOptionsNotStatic as a, issuePatternUnsupported as o, issueTableColumnsEmpty as s, issueUnknownFieldType as c, issueUnmappableFieldType as l } from "./issues.js";
|
|
3
|
+
import { inferColumnType as u, isKeyedNode as d, walkNodes as f } from "@vef-framework-react/form-editor";
|
|
4
|
+
//#region src/project.ts
|
|
5
|
+
var p = {
|
|
6
|
+
textfield: "input",
|
|
7
|
+
"code-editor": "textarea",
|
|
8
|
+
textarea: "textarea",
|
|
9
|
+
number: "number",
|
|
10
|
+
select: "select",
|
|
11
|
+
radio: "select",
|
|
12
|
+
"checkbox-group": "select",
|
|
13
|
+
date: "date",
|
|
14
|
+
datetime: "date"
|
|
15
|
+
}, m = /* @__PURE__ */ new Set(["switch", "daterange"]);
|
|
16
|
+
function h(n) {
|
|
17
|
+
let r = [], i = [], a = [], o = new Map((n.dataSources ?? []).map((e) => [e.id, e])), s = /* @__PURE__ */ new Map();
|
|
18
|
+
for (let c of [n.presentations.pc, n.presentations.mobile]) c !== void 0 && f(c, (n, c) => {
|
|
19
|
+
if (c.length > 0 || !d(n)) return;
|
|
20
|
+
let l = s.get(n.key);
|
|
21
|
+
if (l !== void 0) {
|
|
22
|
+
if (l !== null) {
|
|
23
|
+
let i = g(n);
|
|
24
|
+
i !== null && i !== l.kind ? r.push(e(n.key, l.kind, i)) : i === "table" && l.tableSignature !== void 0 && _(n) !== l.tableSignature && r.push(t(n.key));
|
|
25
|
+
}
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
let u = n.type === "subform", f = u ? y(n, o, r) : v(n, n.key, o, r);
|
|
29
|
+
s.set(n.key, f === void 0 ? null : {
|
|
30
|
+
kind: f.approval.kind,
|
|
31
|
+
...u && { tableSignature: _(n) }
|
|
32
|
+
}), f !== void 0 && (i.push({
|
|
33
|
+
...f.approval,
|
|
34
|
+
sortOrder: i.length
|
|
35
|
+
}), a.push(f.flow));
|
|
36
|
+
});
|
|
37
|
+
return {
|
|
38
|
+
definition: { fields: i },
|
|
39
|
+
formFields: a,
|
|
40
|
+
issues: r,
|
|
41
|
+
valid: r.every((e) => e.severity !== "error")
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
function g(e) {
|
|
45
|
+
return e.type === "subform" ? "table" : p[e.type] ?? null;
|
|
46
|
+
}
|
|
47
|
+
function _(e) {
|
|
48
|
+
let t = [], n = /* @__PURE__ */ new Set();
|
|
49
|
+
return f({ children: e.template }, (e, r) => {
|
|
50
|
+
r.length > 0 || !d(e) || n.has(e.key) || (n.add(e.key), t.push(`${e.key}:${e.type === "subform" ? "table" : p[e.type] ?? "?"}`));
|
|
51
|
+
}), t.join(",");
|
|
52
|
+
}
|
|
53
|
+
function v(e, t, r, i) {
|
|
54
|
+
let a = p[e.type];
|
|
55
|
+
if (a === void 0) {
|
|
56
|
+
i.push(m.has(e.type) ? l(t, e.type) : c(t, e.type));
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
w(e, t, i);
|
|
60
|
+
let s = e.label ?? e.key, u = b(e, t, r, i), { isRequired: d, rule: f } = C(e), h = x(e), { precision: g } = e, { placeholder: _ } = e, v = g !== void 0 && g > 0;
|
|
61
|
+
return f?.pattern !== void 0 && S(f.pattern) && i.push(o(t)), h === "decimal" && !v && i.push(n(t)), {
|
|
62
|
+
approval: {
|
|
63
|
+
key: e.key,
|
|
64
|
+
kind: a,
|
|
65
|
+
label: s,
|
|
66
|
+
..._ !== void 0 && { placeholder: _ },
|
|
67
|
+
...d && { isRequired: d },
|
|
68
|
+
...u !== void 0 && { options: u },
|
|
69
|
+
...f !== void 0 && { validation: f },
|
|
70
|
+
...h !== void 0 && { columnType: h },
|
|
71
|
+
...h === "decimal" && v && { scale: g }
|
|
72
|
+
},
|
|
73
|
+
flow: {
|
|
74
|
+
key: e.key,
|
|
75
|
+
kind: a,
|
|
76
|
+
label: s,
|
|
77
|
+
...u !== void 0 && { options: u }
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
}
|
|
81
|
+
function y(e, t, n) {
|
|
82
|
+
let r = [], a = [], o = /* @__PURE__ */ new Set(), c = !1;
|
|
83
|
+
if (f({ children: e.template }, (s, l) => {
|
|
84
|
+
if (l.length > 0 || !d(s) || o.has(s.key)) return;
|
|
85
|
+
if (o.add(s.key), s.type === "subform") {
|
|
86
|
+
c = !0, n.push(i(`${e.key}.${s.key}`));
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
let u = v(s, `${e.key}.${s.key}`, t, n);
|
|
90
|
+
u !== void 0 && (r.push({
|
|
91
|
+
...u.approval,
|
|
92
|
+
sortOrder: r.length
|
|
93
|
+
}), a.push(u.flow));
|
|
94
|
+
}), r.length === 0) {
|
|
95
|
+
c || n.push(s(e.key));
|
|
96
|
+
return;
|
|
97
|
+
}
|
|
98
|
+
w(e, e.key, n);
|
|
99
|
+
let l = e.label ?? e.key, u = (e.minRows ?? 0) >= 1, p = {
|
|
100
|
+
...e.minRows !== void 0 && e.minRows > 0 && { minLength: e.minRows },
|
|
101
|
+
...e.maxRows !== void 0 && { maxLength: e.maxRows }
|
|
102
|
+
}, m = p.minLength !== void 0 || p.maxLength !== void 0;
|
|
103
|
+
return {
|
|
104
|
+
approval: {
|
|
105
|
+
key: e.key,
|
|
106
|
+
kind: "table",
|
|
107
|
+
label: l,
|
|
108
|
+
...u && { isRequired: u },
|
|
109
|
+
...m && { validation: p },
|
|
110
|
+
columns: r
|
|
111
|
+
},
|
|
112
|
+
flow: {
|
|
113
|
+
key: e.key,
|
|
114
|
+
kind: "table",
|
|
115
|
+
label: l,
|
|
116
|
+
columns: a
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
function b(e, t, n, r) {
|
|
121
|
+
let i = e.dataSource;
|
|
122
|
+
if (i !== void 0) {
|
|
123
|
+
if (i.kind === "static") return i.options;
|
|
124
|
+
if (i.kind === "ref") {
|
|
125
|
+
let e = n.get(i.dataSourceId);
|
|
126
|
+
if (e?.kind === "static") return e.options;
|
|
127
|
+
}
|
|
128
|
+
r.push(a(t));
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
function x(e) {
|
|
132
|
+
if (e.columnType !== void 0) return e.columnType;
|
|
133
|
+
let t = u(e);
|
|
134
|
+
return e.type === "number" && t === "integer" ? void 0 : t;
|
|
135
|
+
}
|
|
136
|
+
function S(e) {
|
|
137
|
+
let t = !1;
|
|
138
|
+
for (let n = 0; n < e.length; n++) {
|
|
139
|
+
let r = e[n];
|
|
140
|
+
if (r === "\\") {
|
|
141
|
+
let r = e[n + 1];
|
|
142
|
+
if (!t && r !== void 0 && r >= "1" && r <= "9") return !0;
|
|
143
|
+
n++;
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
if (r === "[") {
|
|
147
|
+
t = !0;
|
|
148
|
+
continue;
|
|
149
|
+
}
|
|
150
|
+
if (r === "]") {
|
|
151
|
+
t = !1;
|
|
152
|
+
continue;
|
|
153
|
+
}
|
|
154
|
+
if (!t && r === "(" && e[n + 1] === "?") {
|
|
155
|
+
let t = e.slice(n + 2);
|
|
156
|
+
if (t.startsWith("=") || t.startsWith("!") || t.startsWith("<=") || t.startsWith("<!")) return !0;
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
return !1;
|
|
160
|
+
}
|
|
161
|
+
function C(e) {
|
|
162
|
+
let { required: t, ...n } = e.validate ?? {}, r = Object.entries(n).filter(([, e]) => e !== void 0);
|
|
163
|
+
return {
|
|
164
|
+
isRequired: t === !0,
|
|
165
|
+
...r.length > 0 && { rule: Object.fromEntries(r) }
|
|
166
|
+
};
|
|
167
|
+
}
|
|
168
|
+
function w(e, t, n) {
|
|
169
|
+
let { linkage: i } = e;
|
|
170
|
+
i !== void 0 && (i.defaults !== void 0 || (i.rules?.length ?? 0) > 0) && n.push(r(t));
|
|
171
|
+
}
|
|
172
|
+
//#endregion
|
|
173
|
+
export { h as projectFormSchema };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*! @vef-framework-react/approval-form-bridge v2.8.0 made by Venus | 2026-07-07T01:44:11.626Z */
|
|
2
|
+
import { createDefaultMobileRegistry as e, createDefaultRegistry as t } from "@vef-framework-react/form-editor";
|
|
3
|
+
//#region src/registry.ts
|
|
4
|
+
var n = [
|
|
5
|
+
"switch",
|
|
6
|
+
"daterange",
|
|
7
|
+
"button"
|
|
8
|
+
];
|
|
9
|
+
function r() {
|
|
10
|
+
let r = t(), i = e();
|
|
11
|
+
for (let e of n) r.unregister(e), i.unregister(e);
|
|
12
|
+
return {
|
|
13
|
+
pc: r,
|
|
14
|
+
mobile: i
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { n as APPROVAL_EXCLUDED_FIELD_TYPES, r as createApprovalRegistries };
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
/*! @vef-framework-react/approval-form-bridge v2.8.0 made by Venus | 2026-07-07T01:44:11.626Z */
|
|
2
|
+
import { projectFormSchema as e } from "./project.js";
|
|
3
|
+
import { validateSchema as t } from "@vef-framework-react/form-editor";
|
|
4
|
+
//#region src/validate.ts
|
|
5
|
+
function n(n, r) {
|
|
6
|
+
let i = t(n, r);
|
|
7
|
+
if (i.schema === void 0) return {
|
|
8
|
+
valid: !1,
|
|
9
|
+
issues: i.issues
|
|
10
|
+
};
|
|
11
|
+
let a = e(i.schema);
|
|
12
|
+
return {
|
|
13
|
+
valid: i.valid && a.valid,
|
|
14
|
+
issues: [...i.issues, ...a.issues]
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
//#endregion
|
|
18
|
+
export { n as validateApprovalSchema };
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import { ColumnDataType } from '@vef-framework-react/form-editor';
|
|
2
|
+
/**
|
|
3
|
+
* Field kind stored by the approval backend (`approval/form_definition.go`
|
|
4
|
+
* `FieldKind` / `approval/enums.go`). The Go enum is the source of truth;
|
|
5
|
+
* this union mirrors it literal-for-literal so drift fails the type-check at
|
|
6
|
+
* every assignment site.
|
|
7
|
+
*/
|
|
8
|
+
export type ApprovalFieldKind = "input" | "textarea" | "select" | "number" | "date" | "upload" | "table";
|
|
9
|
+
/**
|
|
10
|
+
* A selectable option of a `select` field, mirroring the Go backend's
|
|
11
|
+
* `FieldOption`. `value` is `unknown` because the Go side types it `any`;
|
|
12
|
+
* the projector only ever writes `string | number`.
|
|
13
|
+
*/
|
|
14
|
+
export interface ApprovalFieldOption {
|
|
15
|
+
label: string;
|
|
16
|
+
value: unknown;
|
|
17
|
+
}
|
|
18
|
+
/**
|
|
19
|
+
* Per-field validation rule, structurally equal to the Go backend's
|
|
20
|
+
* `ValidationRule`. On a `table` field `minLength` / `maxLength` bound the
|
|
21
|
+
* ROW COUNT rather than a string length.
|
|
22
|
+
*/
|
|
23
|
+
export interface ApprovalValidationRule {
|
|
24
|
+
minLength?: number;
|
|
25
|
+
maxLength?: number;
|
|
26
|
+
min?: number;
|
|
27
|
+
max?: number;
|
|
28
|
+
pattern?: string;
|
|
29
|
+
message?: string;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* A single form field flattened to the Go backend's `FormFieldDefinition`.
|
|
33
|
+
* The field list IS the data model: under `table` storage each entry becomes
|
|
34
|
+
* a column (each `table` field its own child table), under `json` storage a
|
|
35
|
+
* JSONB key.
|
|
36
|
+
*
|
|
37
|
+
* `defaultValue` and `props` exist on the wire contract but are never emitted
|
|
38
|
+
* by the projector today — the designer has no static default-value source,
|
|
39
|
+
* and nothing consumes `props` yet. They are declared so hand-built or
|
|
40
|
+
* host-enriched definitions round-trip losslessly.
|
|
41
|
+
*/
|
|
42
|
+
export interface ApprovalFormField {
|
|
43
|
+
key: string;
|
|
44
|
+
kind: ApprovalFieldKind;
|
|
45
|
+
label: string;
|
|
46
|
+
placeholder?: string;
|
|
47
|
+
defaultValue?: unknown;
|
|
48
|
+
isRequired?: boolean;
|
|
49
|
+
options?: ApprovalFieldOption[];
|
|
50
|
+
validation?: ApprovalValidationRule;
|
|
51
|
+
props?: Record<string, unknown>;
|
|
52
|
+
sortOrder: number;
|
|
53
|
+
/**
|
|
54
|
+
* Table-storage column type hint, honored when the flow version uses
|
|
55
|
+
* `table` storage. Reuses form-editor's {@link ColumnDataType}, which
|
|
56
|
+
* already mirrors the Go `ColumnDataType` enum.
|
|
57
|
+
*/
|
|
58
|
+
columnType?: ColumnDataType;
|
|
59
|
+
/**
|
|
60
|
+
* Decimal scale, paired with `columnType: "decimal"`.
|
|
61
|
+
*/
|
|
62
|
+
scale?: number;
|
|
63
|
+
/**
|
|
64
|
+
* Row shape of a detail-table field (`kind === "table"`). Single-level —
|
|
65
|
+
* columns never nest another table (enforced by the Go deploy validation
|
|
66
|
+
* and by the projector).
|
|
67
|
+
*/
|
|
68
|
+
columns?: ApprovalFormField[];
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* The flat form definition the approval backend deploys
|
|
72
|
+
* (`DeployFlowCmd.FormDefinition`).
|
|
73
|
+
*/
|
|
74
|
+
export interface ApprovalFormDefinition {
|
|
75
|
+
fields: ApprovalFormField[];
|
|
76
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
export { type ApprovalFieldKind, type ApprovalFieldOption, type ApprovalFormDefinition, type ApprovalFormField, type ApprovalValidationRule } from './contract';
|
|
2
|
+
export { type ProjectionIssue, type ProjectionIssueCode } from './issues';
|
|
3
|
+
export { projectFormSchema, type ProjectionResult } from './project';
|
|
4
|
+
export { APPROVAL_EXCLUDED_FIELD_TYPES, createApprovalRegistries } from './registry';
|
|
5
|
+
export { validateApprovalSchema, type ApprovalSchemaIssue, type ApprovalSchemaValidationResult } from './validate';
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Diagnostic code raised by the schema→approval projection. Error-severity
|
|
3
|
+
* codes are contract-breaking (the Go deploy or runtime validation would
|
|
4
|
+
* reject the result); warning-severity codes flag fidelity loss the host
|
|
5
|
+
* should surface but may accept.
|
|
6
|
+
*/
|
|
7
|
+
export type ProjectionIssueCode = "unmappable_field_type" | "unknown_field_type_unprojectable" | "nested_subform_unsupported" | "table_columns_empty" | "pattern_unsupported" | "decimal_scale_missing" | "options_not_static" | "linkage_not_projected" | "cross_device_kind_mismatch" | "cross_device_table_mismatch";
|
|
8
|
+
/**
|
|
9
|
+
* One projection diagnostic. Structurally aligned with form-editor's
|
|
10
|
+
* `ValidationIssue` (`path` / `code` / `severity` / `message`) so hosts can
|
|
11
|
+
* render both kinds through one list, but the code namespace is the bridge's
|
|
12
|
+
* own — form-editor's `ValidationIssueCode` is a closed union.
|
|
13
|
+
*
|
|
14
|
+
* `path` is the field-key chain: `"amount"` for a top-level field,
|
|
15
|
+
* `"items.price"` for a detail-table column.
|
|
16
|
+
*/
|
|
17
|
+
export interface ProjectionIssue {
|
|
18
|
+
path: string;
|
|
19
|
+
code: ProjectionIssueCode;
|
|
20
|
+
severity: "error" | "warning";
|
|
21
|
+
message: string;
|
|
22
|
+
}
|
|
23
|
+
export declare function issueUnmappableFieldType(path: string, type: string): ProjectionIssue;
|
|
24
|
+
export declare function issueUnknownFieldType(path: string, type: string): ProjectionIssue;
|
|
25
|
+
export declare function issueNestedSubform(path: string): ProjectionIssue;
|
|
26
|
+
export declare function issueTableColumnsEmpty(path: string): ProjectionIssue;
|
|
27
|
+
export declare function issuePatternUnsupported(path: string): ProjectionIssue;
|
|
28
|
+
export declare function issueDecimalScaleMissing(path: string): ProjectionIssue;
|
|
29
|
+
export declare function issueOptionsNotStatic(path: string): ProjectionIssue;
|
|
30
|
+
export declare function issueLinkageNotProjected(path: string): ProjectionIssue;
|
|
31
|
+
export declare function issueCrossDeviceKindMismatch(path: string, pcKind: string, mobileKind: string): ProjectionIssue;
|
|
32
|
+
export declare function issueCrossDeviceTableMismatch(path: string): ProjectionIssue;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { FormFieldDefinition as FlowFormFieldDefinition } from '@vef-framework-react/approval-flow-editor';
|
|
2
|
+
import { FormSchema } from '@vef-framework-react/form-editor';
|
|
3
|
+
import { ApprovalFormDefinition } from './contract';
|
|
4
|
+
import { ProjectionIssue } from './issues';
|
|
5
|
+
/**
|
|
6
|
+
* Result of projecting a designed {@link FormSchema} onto the approval form
|
|
7
|
+
* contract. One walk feeds both consumers so they cannot disagree:
|
|
8
|
+
* `definition` is the flat backend payload (`DeployFlowCmd.FormDefinition`),
|
|
9
|
+
* `formFields` is the same inventory in the shape the approval flow editor
|
|
10
|
+
* consumes through `EditorPlugins.formFields` (detail-table fields included,
|
|
11
|
+
* with their columns, so the condition editor's aggregate UI works).
|
|
12
|
+
*/
|
|
13
|
+
export interface ProjectionResult {
|
|
14
|
+
definition: ApprovalFormDefinition;
|
|
15
|
+
formFields: FlowFormFieldDefinition[];
|
|
16
|
+
issues: ProjectionIssue[];
|
|
17
|
+
/**
|
|
18
|
+
* `true` when no error-severity issue was raised. The backend's form data
|
|
19
|
+
* is a closed contract — deploying an invalid projection either fails the
|
|
20
|
+
* deploy validation or poisons every submit — so hosts must gate
|
|
21
|
+
* persistence on this flag.
|
|
22
|
+
*/
|
|
23
|
+
valid: boolean;
|
|
24
|
+
}
|
|
25
|
+
/**
|
|
26
|
+
* Project a designed form schema onto the approval form contract.
|
|
27
|
+
*
|
|
28
|
+
* Both device presentations are walked (pc first) and deduped by key — the
|
|
29
|
+
* submitted data contract is shared across devices, and the backend's form
|
|
30
|
+
* data is closed, so a mobile-only field must still project. Only root-scope
|
|
31
|
+
* keyed nodes become fields: leaf fields map by {@link KIND_BY_TYPE}, a
|
|
32
|
+
* subform becomes a single-level `table` field whose template's keyed leaves
|
|
33
|
+
* are its columns (layout containers in the template are transparent — only
|
|
34
|
+
* a subform opens a value scope, so the submitted row stays a flat record).
|
|
35
|
+
*
|
|
36
|
+
* Conservation rule: a keyed node that cannot be mapped is always an
|
|
37
|
+
* error-severity issue, never silently dropped.
|
|
38
|
+
*/
|
|
39
|
+
export declare function projectFormSchema(schema: FormSchema): ProjectionResult;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { DeviceRegistries } from '@vef-framework-react/form-editor';
|
|
2
|
+
/**
|
|
3
|
+
* Widget types the approval profile removes from the default registries.
|
|
4
|
+
*
|
|
5
|
+
* - `switch` / `daterange`: bind values (boolean / [start, end] array) the
|
|
6
|
+
* approval contract cannot carry — see the projector's `KIND_BY_TYPE`.
|
|
7
|
+
* - `button`: binds no value, but its `submit` / `reset` actions fight the
|
|
8
|
+
* approval shell's own submission control.
|
|
9
|
+
*
|
|
10
|
+
* A host that disagrees builds its own registries instead of calling
|
|
11
|
+
* {@link createApprovalRegistries}.
|
|
12
|
+
*/
|
|
13
|
+
export declare const APPROVAL_EXCLUDED_FIELD_TYPES: readonly ["switch", "daterange", "button"];
|
|
14
|
+
/**
|
|
15
|
+
* Build the approval-profile device registries: the form-editor defaults
|
|
16
|
+
* minus {@link APPROVAL_EXCLUDED_FIELD_TYPES}. Because the palette listing,
|
|
17
|
+
* the schema-import validation, and the properties panel all derive from the
|
|
18
|
+
* registry, passing this to `<FormEditor registries={...}>` keeps the
|
|
19
|
+
* excluded widgets out of the designer entirely — a user cannot author a
|
|
20
|
+
* form the approval backend would reject on those types.
|
|
21
|
+
*
|
|
22
|
+
* Returns fresh instances on every call; the `registries` prop is honored on
|
|
23
|
+
* first mount only, so memoize the result (`useState(createApprovalRegistries)`).
|
|
24
|
+
*/
|
|
25
|
+
export declare function createApprovalRegistries(): DeviceRegistries;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { DeviceRegistries, ValidationIssue } from '@vef-framework-react/form-editor';
|
|
2
|
+
import { ProjectionIssue } from './issues';
|
|
3
|
+
/**
|
|
4
|
+
* A diagnostic from either layer of the save gate: form-editor's structural
|
|
5
|
+
* validation or the bridge's projection. Both are `{ path, code, severity,
|
|
6
|
+
* message }`-shaped, so hosts render them through one list.
|
|
7
|
+
*/
|
|
8
|
+
export type ApprovalSchemaIssue = ValidationIssue | ProjectionIssue;
|
|
9
|
+
export interface ApprovalSchemaValidationResult {
|
|
10
|
+
valid: boolean;
|
|
11
|
+
issues: ApprovalSchemaIssue[];
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Save-time gate for an approval-bound form schema: form-editor's
|
|
15
|
+
* `validateSchema` (structural + registry membership) followed by the
|
|
16
|
+
* approval projection (contract fit). Call before persisting or deploying —
|
|
17
|
+
* the designer itself cannot enforce everything (e.g. a nested subform is
|
|
18
|
+
* legal in a general-purpose form, and `initialSchema` is ingested without
|
|
19
|
+
* validation), so this is the single choke point.
|
|
20
|
+
*
|
|
21
|
+
* Structural errors short-circuit the projection: `validateSchema` returns a
|
|
22
|
+
* schema only when it found no error, and the projector assumes well-typed
|
|
23
|
+
* input, so running it on a malformed tree would trade one clear structural
|
|
24
|
+
* diagnostic for a crash. Fix structure first; contract issues surface on
|
|
25
|
+
* the next pass.
|
|
26
|
+
*/
|
|
27
|
+
export declare function validateApprovalSchema(candidate: unknown, registries: DeviceRegistries): ApprovalSchemaValidationResult;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@vef-framework-react/approval-form-bridge",
|
|
3
|
+
"version": "2.8.0",
|
|
4
|
+
"private": false,
|
|
5
|
+
"description": "Projection bridge from form-editor schemas to the approval form contract",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"vef",
|
|
8
|
+
"framework",
|
|
9
|
+
"react",
|
|
10
|
+
"approval",
|
|
11
|
+
"form"
|
|
12
|
+
],
|
|
13
|
+
"homepage": "https://vef.ilxqx.com",
|
|
14
|
+
"license": "Apache-2.0",
|
|
15
|
+
"author": {
|
|
16
|
+
"name": "Venus",
|
|
17
|
+
"email": "iweixiaopeng@163.com",
|
|
18
|
+
"url": "https://github.com/ilxqx"
|
|
19
|
+
},
|
|
20
|
+
"sideEffects": false,
|
|
21
|
+
"type": "module",
|
|
22
|
+
"exports": {
|
|
23
|
+
".": {
|
|
24
|
+
"vef": "./src/index.ts",
|
|
25
|
+
"import": {
|
|
26
|
+
"types": "./dist/types/index.d.ts",
|
|
27
|
+
"default": "./dist/es/index.js"
|
|
28
|
+
},
|
|
29
|
+
"require": {
|
|
30
|
+
"types": "./dist/types/index.d.ts",
|
|
31
|
+
"default": "./dist/cjs/index.cjs"
|
|
32
|
+
}
|
|
33
|
+
},
|
|
34
|
+
"./package.json": "./package.json"
|
|
35
|
+
},
|
|
36
|
+
"main": "dist/cjs/index.cjs",
|
|
37
|
+
"module": "dist/es/index.js",
|
|
38
|
+
"types": "dist/types/index.d.ts",
|
|
39
|
+
"files": [
|
|
40
|
+
"dist"
|
|
41
|
+
],
|
|
42
|
+
"dependencies": {
|
|
43
|
+
"@vef-framework-react/approval-flow-editor": "2.8.0",
|
|
44
|
+
"@vef-framework-react/form-editor": "2.8.0"
|
|
45
|
+
},
|
|
46
|
+
"devDependencies": {
|
|
47
|
+
"react": "^19.2.7"
|
|
48
|
+
},
|
|
49
|
+
"peerDependencies": {
|
|
50
|
+
"react": ">=19"
|
|
51
|
+
},
|
|
52
|
+
"engines": {
|
|
53
|
+
"node": ">=22.x"
|
|
54
|
+
},
|
|
55
|
+
"publishConfig": {
|
|
56
|
+
"access": "public"
|
|
57
|
+
},
|
|
58
|
+
"scripts": {
|
|
59
|
+
"build": "vite build",
|
|
60
|
+
"clean": "rimraf dist",
|
|
61
|
+
"typecheck": "tsc --noEmit"
|
|
62
|
+
}
|
|
63
|
+
}
|