@phoenix-wing/kt-codegen 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +201 -0
- package/NOTICE +4 -0
- package/README.md +328 -0
- package/dist/KtCodegenAdapter.d.ts +42 -0
- package/dist/KtCodegenAdapter.d.ts.map +1 -0
- package/dist/KtCodegenAdapter.js +90 -0
- package/dist/KtCodegenAdapter.js.map +1 -0
- package/dist/KtCodegenApply.d.ts +93 -0
- package/dist/KtCodegenApply.d.ts.map +1 -0
- package/dist/KtCodegenApply.js +194 -0
- package/dist/KtCodegenApply.js.map +1 -0
- package/dist/KtCodegenBlockPresentation.d.ts +14 -0
- package/dist/KtCodegenBlockPresentation.d.ts.map +1 -0
- package/dist/KtCodegenBlockPresentation.js +56 -0
- package/dist/KtCodegenBlockPresentation.js.map +1 -0
- package/dist/KtCodegenController.d.ts +68 -0
- package/dist/KtCodegenController.d.ts.map +1 -0
- package/dist/KtCodegenController.js +100 -0
- package/dist/KtCodegenController.js.map +1 -0
- package/dist/KtCodegenCore.d.ts +87 -0
- package/dist/KtCodegenCore.d.ts.map +1 -0
- package/dist/KtCodegenCore.js +234 -0
- package/dist/KtCodegenCore.js.map +1 -0
- package/dist/KtCodegenItem.d.ts +84 -0
- package/dist/KtCodegenItem.d.ts.map +1 -0
- package/dist/KtCodegenItem.js +88 -0
- package/dist/KtCodegenItem.js.map +1 -0
- package/dist/KtCodegenMarker.d.ts +110 -0
- package/dist/KtCodegenMarker.d.ts.map +1 -0
- package/dist/KtCodegenMarker.js +246 -0
- package/dist/KtCodegenMarker.js.map +1 -0
- package/dist/KtCodegenOptions.d.ts +29 -0
- package/dist/KtCodegenOptions.d.ts.map +1 -0
- package/dist/KtCodegenOptions.js +97 -0
- package/dist/KtCodegenOptions.js.map +1 -0
- package/dist/KtCodegenParam.d.ts +60 -0
- package/dist/KtCodegenParam.d.ts.map +1 -0
- package/dist/KtCodegenParam.js +68 -0
- package/dist/KtCodegenParam.js.map +1 -0
- package/dist/KtCodegenReader.d.ts +23 -0
- package/dist/KtCodegenReader.d.ts.map +1 -0
- package/dist/KtCodegenReader.js +28 -0
- package/dist/KtCodegenReader.js.map +1 -0
- package/dist/KtCodegenRenderer.d.ts +114 -0
- package/dist/KtCodegenRenderer.d.ts.map +1 -0
- package/dist/KtCodegenRenderer.js +1388 -0
- package/dist/KtCodegenRenderer.js.map +1 -0
- package/dist/KtCodegenTableColumns.d.ts +103 -0
- package/dist/KtCodegenTableColumns.d.ts.map +1 -0
- package/dist/KtCodegenTableColumns.js +35 -0
- package/dist/KtCodegenTableColumns.js.map +1 -0
- package/dist/KtCodegenTableCore.d.ts +61 -0
- package/dist/KtCodegenTableCore.d.ts.map +1 -0
- package/dist/KtCodegenTableCore.js +240 -0
- package/dist/KtCodegenTableCore.js.map +1 -0
- package/dist/KtCodegenTableData.d.ts +22 -0
- package/dist/KtCodegenTableData.d.ts.map +1 -0
- package/dist/KtCodegenTableData.js +17 -0
- package/dist/KtCodegenTableData.js.map +1 -0
- package/dist/api/analyze.d.ts +8 -0
- package/dist/api/analyze.d.ts.map +1 -0
- package/dist/api/analyze.js +102 -0
- package/dist/api/analyze.js.map +1 -0
- package/dist/api/contracts.d.ts +93 -0
- package/dist/api/contracts.d.ts.map +1 -0
- package/dist/api/contracts.js +3 -0
- package/dist/api/contracts.js.map +1 -0
- package/dist/api/index.d.ts +3 -0
- package/dist/api/index.d.ts.map +1 -0
- package/dist/api/index.js +4 -0
- package/dist/api/index.js.map +1 -0
- package/dist/blocks/index.d.ts +2 -0
- package/dist/blocks/index.d.ts.map +1 -0
- package/dist/blocks/index.js +3 -0
- package/dist/blocks/index.js.map +1 -0
- package/dist/blocks/legacy-blocks.d.ts +309 -0
- package/dist/blocks/legacy-blocks.d.ts.map +1 -0
- package/dist/blocks/legacy-blocks.js +343 -0
- package/dist/blocks/legacy-blocks.js.map +1 -0
- package/dist/index.d.ts +19 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +20 -0
- package/dist/index.js.map +1 -0
- package/dist/legacy/csv.d.ts +25 -0
- package/dist/legacy/csv.d.ts.map +1 -0
- package/dist/legacy/csv.js +197 -0
- package/dist/legacy/csv.js.map +1 -0
- package/dist/legacy/index.d.ts +4 -0
- package/dist/legacy/index.d.ts.map +1 -0
- package/dist/legacy/index.js +5 -0
- package/dist/legacy/index.js.map +1 -0
- package/dist/legacy/v4-json.d.ts +12 -0
- package/dist/legacy/v4-json.d.ts.map +1 -0
- package/dist/legacy/v4-json.js +363 -0
- package/dist/legacy/v4-json.js.map +1 -0
- package/dist/legacy/v4-schema.d.ts +30 -0
- package/dist/legacy/v4-schema.d.ts.map +1 -0
- package/dist/legacy/v4-schema.js +63 -0
- package/dist/legacy/v4-schema.js.map +1 -0
- package/dist/model/diagnostic.d.ts +38 -0
- package/dist/model/diagnostic.d.ts.map +1 -0
- package/dist/model/diagnostic.js +6 -0
- package/dist/model/diagnostic.js.map +1 -0
- package/dist/model/equal.d.ts +10 -0
- package/dist/model/equal.d.ts.map +1 -0
- package/dist/model/equal.js +64 -0
- package/dist/model/equal.js.map +1 -0
- package/dist/model/index.d.ts +5 -0
- package/dist/model/index.d.ts.map +1 -0
- package/dist/model/index.js +6 -0
- package/dist/model/index.js.map +1 -0
- package/dist/model/target.d.ts +58 -0
- package/dist/model/target.d.ts.map +1 -0
- package/dist/model/target.js +32 -0
- package/dist/model/target.js.map +1 -0
- package/dist/model/validate.d.ts +9 -0
- package/dist/model/validate.d.ts.map +1 -0
- package/dist/model/validate.js +52 -0
- package/dist/model/validate.js.map +1 -0
- package/dist/table/KtCodegenTable.d.ts +75 -0
- package/dist/table/KtCodegenTable.d.ts.map +1 -0
- package/dist/table/KtCodegenTable.js +541 -0
- package/dist/table/KtCodegenTable.js.map +1 -0
- package/dist/table/index.d.ts +4 -0
- package/dist/table/index.d.ts.map +1 -0
- package/dist/table/index.js +5 -0
- package/dist/table/index.js.map +1 -0
- package/doc/CAA/344/270/216Qt/345/257/271/350/257/235/346/241/206/345/217/214/345/220/221/346/233/264/346/226/260/345/235/227/350/277/201/347/247/273.md +74 -0
- package/doc/CAA/345/257/271/350/257/235/346/241/206/351/200/232/347/237/245/345/235/227/350/277/201/347/247/273.md +45 -0
- package/doc/CAA/346/216/245/345/217/243/345/244/264/346/226/207/344/273/266/345/235/227/350/277/201/347/247/273.md +75 -0
- package/doc/CAA/347/211/271/345/276/201/350/257/273/345/206/231/345/235/227/350/277/201/347/247/273.md +77 -0
- package/doc/CAA/347/233/256/345/275/225/344/270/216/346/240/221/345/267/245/345/216/202/345/235/227/350/277/201/347/247/273.md +78 -0
- package/doc/CommandAgent/347/224/237/345/221/275/345/221/250/346/234/237/345/235/227/350/277/201/347/247/273.md +47 -0
- package/doc/Command/345/212/250/344/275/234/344/270/216/346/264/273/345/212/250/345/255/227/346/256/265/345/235/227/350/277/201/347/247/273.md +46 -0
- package/doc/Command/345/233/276/344/270/216/347/212/266/346/200/201/345/235/227/350/277/201/347/247/273.md +64 -0
- package/doc/Dialog/345/255/227/346/256/265/344/270/216/345/272/237/345/274/203/345/205/274/345/256/271/345/235/227/350/277/201/347/247/273.md +60 -0
- package/doc/KtCodegen/345/221/275/345/220/215/350/277/201/347/247/273/350/257/264/346/230/216.md +55 -0
- package/doc//344/270/244/345/260/217/346/227/266/350/277/201/347/247/273/350/256/241/345/210/222/344/270/216/351/252/214/346/224/266.md +52 -0
- package/doc//346/231/256/351/200/232C++/345/217/202/346/225/260/345/235/227/350/277/201/347/247/273.md +72 -0
- package/doc//346/235/245/346/272/220/344/270/216/350/256/270/345/217/257/345/275/222/346/241/243.md +29 -0
- package/doc//347/224/237/346/210/220/345/235/227/350/277/201/347/247/273/347/237/251/351/230/265.md +75 -0
- package/doc//350/207/252/345/212/250/344/273/243/347/240/201/346/240/207/350/256/260/346/211/253/346/217/217.md +84 -0
- package/package.json +62 -0
- package/src/index.ts +20 -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 2024–2026 上海锟钛
|
|
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/NOTICE
ADDED
package/README.md
ADDED
|
@@ -0,0 +1,328 @@
|
|
|
1
|
+
# KtCodegen 参数代码生成核心
|
|
2
|
+
|
|
3
|
+
这是从 `KtAutoCode` 本地归档标签 `kt-codegen-0.1.0` 迁入 Phoenix Wing 的参数驱动代码生成核心,npm 包名为 `@phoenix-wing/kt-codegen`。归档旧仓库继续作为 VB/C++/Qt 行为、许可和来源证据。
|
|
4
|
+
|
|
5
|
+
本包提供共享数据、旧格式兼容、只读源码标记扫描、32个生成块的 Core/Renderer、宿主无关的 Apply 投影/回滚事务,以及17列 Table Web Component。它不直接打开真实文件,也不依赖 VS Code、DeskTools 或其他产品壳;宿主通过只读快照和文件读写 Port 接入。
|
|
6
|
+
|
|
7
|
+
## 文件与命名规则
|
|
8
|
+
|
|
9
|
+
主要职责类直接平铺在 `src/`,不再为了 MVC-C 建立多层目录:
|
|
10
|
+
|
|
11
|
+
```text
|
|
12
|
+
src/
|
|
13
|
+
├── KtCodegenParam.ts # 共享配置数据
|
|
14
|
+
├── KtCodegenItem.ts # 单条17列参数数据
|
|
15
|
+
├── KtCodegenOptions.ts # UI Combo 候选值
|
|
16
|
+
├── KtCodegenReader.ts # CSV/JSON读取
|
|
17
|
+
├── KtCodegenAdapter.ts # 旧格式写出、复制和清空
|
|
18
|
+
├── KtCodegenApply.ts # Apply审计、纯文本投影与宿主无关回滚事务
|
|
19
|
+
├── KtCodegenController.ts # 宿主编排
|
|
20
|
+
├── KtCodegenCore.ts # 核心生成算法入口
|
|
21
|
+
├── KtCodegenMarker.ts # 旧自动代码标记构造与只读扫描
|
|
22
|
+
├── KtCodegenRenderer.ts # 多目标生成器
|
|
23
|
+
├── KtCodegenTableCore.ts # 无 DOM 的整表编辑与 checkpoint
|
|
24
|
+
├── KtCodegenTableData.ts # 宿主交换的整表 DTO
|
|
25
|
+
├── KtCodegenTableColumns.ts # 17列描述与字段类型
|
|
26
|
+
└── table/KtCodegenTable.ts # browser-only Web Component
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
规则如下:
|
|
30
|
+
|
|
31
|
+
- 所有主要类统一使用 `KtCodegen*` 前缀;
|
|
32
|
+
- `Pnw` 保留给 Phoenix Wing 通用基础设施;参数自动代码领域即使迁入 Phoenix Wing 也继续使用 `KtCodegen`;
|
|
33
|
+
- 一个类一个 `.ts` 文件,文件名与类名完全一致;
|
|
34
|
+
- 类专用的小接口、类型可以留在同一文件;
|
|
35
|
+
- 多个共享的小枚举或类型以后可以集中到一个 `KtCodegenTypes.ts`;
|
|
36
|
+
- `index.ts` 只导出,不放实现;
|
|
37
|
+
- MVC-C 是职责划分,不通过目录层级表达。
|
|
38
|
+
|
|
39
|
+
`api/`、`blocks/`、`legacy/`、`model/` 当前只放迁移初期的纯函数、旧格式 schema 和公共类型,不承载上述主要类。
|
|
40
|
+
|
|
41
|
+
完整的类型、函数、常量和运行时身份映射见[《KtCodegen 命名迁移说明》](doc/KtCodegen命名迁移说明.md)。
|
|
42
|
+
|
|
43
|
+
旧 VB/C++/Qt 权威实现、归档标签与许可证据见[《来源与许可归档》](doc/来源与许可归档.md)。
|
|
44
|
+
|
|
45
|
+
本次迁入的时间盒、仓库边界和发布门禁见[《两小时迁移计划与验收》](doc/两小时迁移计划与验收.md)。
|
|
46
|
+
|
|
47
|
+
32个旧生成块的分派依据、主目标、废弃状态和建议迁移顺序见[《参数代码生成块迁移矩阵》](doc/生成块迁移矩阵.md)。
|
|
48
|
+
|
|
49
|
+
旧 Start/End 文本协议、源码偏移和异常配对规则见[《自动代码标记扫描》](doc/自动代码标记扫描.md)。
|
|
50
|
+
|
|
51
|
+
首组已迁移 Renderer 的逐块行为和 golden 见[《普通 C++ 参数块迁移》](doc/普通C++参数块迁移.md)。
|
|
52
|
+
|
|
53
|
+
CAA 实现类/纯虚接口 Get/Set 差异见[《CAA 接口头文件块迁移》](doc/CAA接口头文件块迁移.md)。
|
|
54
|
+
|
|
55
|
+
CAA 单参数读写与 Param 聚合桥接见[《CAA 特征读写块迁移》](doc/CAA特征读写块迁移.md)。
|
|
56
|
+
|
|
57
|
+
CAA Catalog 注册、树工厂与标题规则见[《CAA 目录与树工厂块迁移》](doc/CAA目录与树工厂块迁移.md)。
|
|
58
|
+
|
|
59
|
+
CAA Dialog Agent 通知注册见[《CAA 对话框通知块迁移》](doc/CAA对话框通知块迁移.md)。
|
|
60
|
+
|
|
61
|
+
CAA/Qt Parameter 与 Dialog 的双向更新见[《CAA 与 Qt 对话框双向更新块迁移》](doc/CAA与Qt对话框双向更新块迁移.md)。
|
|
62
|
+
|
|
63
|
+
Dialog Field 枚举、Selector 访问与废弃兼容策略见[《Dialog 字段与废弃兼容块迁移》](doc/Dialog字段与废弃兼容块迁移.md)。
|
|
64
|
+
|
|
65
|
+
Command Agent 成员声明、构造初始化与析构清理见[《Command Agent 生命周期块迁移》](doc/CommandAgent生命周期块迁移.md)。
|
|
66
|
+
|
|
67
|
+
Command BuildGraph、FIA Clear 与 UpdateState 见[《Command 图与状态块迁移》](doc/Command图与状态块迁移.md)。
|
|
68
|
+
|
|
69
|
+
Command PDA/FIA Action、废弃选择逻辑与活动 Field 见[《Command 动作与活动字段块迁移》](doc/Command动作与活动字段块迁移.md)。
|
|
70
|
+
|
|
71
|
+
## 数据类边界
|
|
72
|
+
|
|
73
|
+
`KtCodegenParam` 和 `KtCodegenItem` 是纯数据类:只包含公开、可变字段和最小构造初始化,不包含 CSV/JSON、校验、清空、复制或生成算法。
|
|
74
|
+
|
|
75
|
+
旧系统的关键优势是 MVC-C(Model–View–Control–Core)围绕同一份 Parameter 数据协作。Parameter 采用类似 C/C++ `struct` 的全公开成员形式,不生成 getter/setter。Model、View、Control、Core、CAA 特征读写、Qt 对话框和普通 C++ 代码可以直接持有同一个实例;一处修改后,其他持有者立即看到新值。
|
|
76
|
+
|
|
77
|
+
这种设计主动牺牲一部分封装,换取调用路径短、表格/JSON/CSV 映射直接、自动代码模板样板少。代价是公开成员没有 setter 防线,调用者必须协调修改。新 TS 实现保留这一取舍,但把输入、适配、诊断、核心算法和源码 Apply 分离,避免数据类继续膨胀。
|
|
78
|
+
|
|
79
|
+
旧数据载体统一为:
|
|
80
|
+
|
|
81
|
+
| 旧实现 | 新对应 |
|
|
82
|
+
| --- | --- |
|
|
83
|
+
| VB `KevinCAAFileGuide` 的 `_Name*` 与 `_FieldList` | `KtCodegenParam` |
|
|
84
|
+
| VB `KevinCAAParamInfor` | `KtCodegenItem` |
|
|
85
|
+
| C++ `KtaControlConfigData` | `KtCodegenParam` |
|
|
86
|
+
| C++ `KtaControlConfigItem` | `KtCodegenItem` |
|
|
87
|
+
| Qt `KtdAutoCodeParam` 的配置字段 | `KtCodegenParam`;文件、搜索、选中行等宿主状态不迁入 |
|
|
88
|
+
| Qt `KtdAutoCodeItem` | `KtCodegenItem` |
|
|
89
|
+
|
|
90
|
+
## 类图
|
|
91
|
+
|
|
92
|
+
```mermaid
|
|
93
|
+
classDiagram
|
|
94
|
+
class KtCodegenParam {
|
|
95
|
+
+string namePrefix
|
|
96
|
+
+string nameMiddle
|
|
97
|
+
+string nameSpace
|
|
98
|
+
+string appendFunction
|
|
99
|
+
+KtCodegenItem[] items
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
class KtCodegenItem {
|
|
103
|
+
+string nameSuffix
|
|
104
|
+
+number id
|
|
105
|
+
+string name
|
|
106
|
+
+string paramString
|
|
107
|
+
+string dataType
|
|
108
|
+
+string tcKind
|
|
109
|
+
+string defaultValue
|
|
110
|
+
+string catAttrInOut
|
|
111
|
+
+boolean isList
|
|
112
|
+
+boolean isOnTree
|
|
113
|
+
+string component
|
|
114
|
+
+number componentCount
|
|
115
|
+
+boolean isParamDlg
|
|
116
|
+
+string unit
|
|
117
|
+
+string author
|
|
118
|
+
+string createDate
|
|
119
|
+
+string notes
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
class KtCodegenOptions {
|
|
123
|
+
+tcKinds$
|
|
124
|
+
+catAttrInOutValues$
|
|
125
|
+
+components$
|
|
126
|
+
+hasTcKind(value)$ boolean
|
|
127
|
+
+hasCatAttrInOut(value)$ boolean
|
|
128
|
+
+hasComponent(value)$ boolean
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
class KtCodegenReader {
|
|
132
|
+
+readJson(input) Result~KtCodegenParam~
|
|
133
|
+
+readCsv(text) Result~KtCodegenParam~
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
class KtCodegenAdapter {
|
|
137
|
+
+replace(target, source)
|
|
138
|
+
+clear(target)
|
|
139
|
+
+writeJson(param)
|
|
140
|
+
+writeCsv(param)
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
class KtCodegenController {
|
|
144
|
+
+KtCodegenParam param
|
|
145
|
+
+KtCodegenReader reader
|
|
146
|
+
+KtCodegenAdapter adapter
|
|
147
|
+
+KtCodegenCore core
|
|
148
|
+
+readJson(input)
|
|
149
|
+
+readCsv(text)
|
|
150
|
+
+writeJson()
|
|
151
|
+
+writeCsv()
|
|
152
|
+
+analyze(request)
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
class KtCodegenCore {
|
|
156
|
+
+KtCodegenRenderer[] renderers
|
|
157
|
+
+KtCodegenMarker marker
|
|
158
|
+
+analyze(param, request) KtCodegenPlan
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
class KtCodegenMarker {
|
|
162
|
+
+createClassId(param, nameSuffix) string
|
|
163
|
+
+createStart(param, nameSuffix, blockKey, linePrefix) string
|
|
164
|
+
+createEnd(param, nameSuffix, blockKey, linePrefix) string
|
|
165
|
+
+scan(param, snapshot, blockKeys) KtCodegenMarkerScanResult
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
class KtCodegenRenderer {
|
|
169
|
+
+string id
|
|
170
|
+
+string[] targets
|
|
171
|
+
+render(context)
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
KtCodegenParam "1" *-- "0..*" KtCodegenItem
|
|
175
|
+
KtCodegenController "1" o-- "1" KtCodegenParam : maintains shared instance
|
|
176
|
+
KtCodegenController "1" o-- "1" KtCodegenReader
|
|
177
|
+
KtCodegenController "1" o-- "1" KtCodegenAdapter
|
|
178
|
+
KtCodegenController "1" o-- "1" KtCodegenCore
|
|
179
|
+
KtCodegenCore "1" o-- "1..*" KtCodegenRenderer
|
|
180
|
+
KtCodegenCore "1" o-- "1" KtCodegenMarker
|
|
181
|
+
KtCodegenReader ..> KtCodegenParam : creates
|
|
182
|
+
KtCodegenAdapter ..> KtCodegenParam : copies and writes
|
|
183
|
+
KtCodegenRenderer ..> KtCodegenParam : consumes
|
|
184
|
+
KtCodegenRenderer ..> KtCodegenMarker : consumes safe regions
|
|
185
|
+
KtCodegenMarker ..> KtCodegenParam : derives class identity
|
|
186
|
+
KtCodegenOptions ..> KtCodegenItem : UI checks strings
|
|
187
|
+
```
|
|
188
|
+
|
|
189
|
+
图中的关键边界是:`KtCodegenParam` 没有操作方法;Controller 只维护同一个共享实例;Reader 先产生临时数据,读取完整成功后再由 Adapter 用原数组 `splice` 更新共享实例;Marker 只消费 Param 和宿主源码快照,不把文件状态放回数据类;Core 把默认值算法注入 Renderer,避免 Renderer 反向依赖 Core。
|
|
190
|
+
|
|
191
|
+
## Combo 字符串规则
|
|
192
|
+
|
|
193
|
+
`tcKind`、`catAttrInOut`、`component` 等字段保持普通 `string`,不改为严格枚举。
|
|
194
|
+
|
|
195
|
+
- Reader 原样保留旧 CSV/JSON 字符串;
|
|
196
|
+
- Adapter 写回原始字符串,不清空、不替换;
|
|
197
|
+
- `KtCodegenOptions` 提供旧 Qt/VB 界面的固定候选值和查询函数;
|
|
198
|
+
- 当前值不在候选列表时,UI 负责提示错误并显示原值;
|
|
199
|
+
- 只有用户从 Combo 主动选择新值后,UI 才修改共享数据。
|
|
200
|
+
|
|
201
|
+
因此,配置即使经过界面打开,只要用户没有主动修正,未知值仍可无损写回。
|
|
202
|
+
|
|
203
|
+
## 共享 Table 组件
|
|
204
|
+
|
|
205
|
+
`KtCodegenTableCore` 从包根导出,只依赖 `KtCodegenParam`,可供 Node、测试、DeskTools store 或其他 UI 控制层直接复用。`KtCodegenTable` 从 browser-only 子路径 `@phoenix-wing/kt-codegen/table` 导出,模块加载不会自动注册自定义元素,也不会污染全局 DOM。
|
|
206
|
+
|
|
207
|
+
```ts
|
|
208
|
+
import type { KtCodegenTableData } from "@phoenix-wing/kt-codegen";
|
|
209
|
+
import {
|
|
210
|
+
ktCodegenDefineTableElement,
|
|
211
|
+
type KtCodegenTable,
|
|
212
|
+
} from "@phoenix-wing/kt-codegen/table";
|
|
213
|
+
|
|
214
|
+
ktCodegenDefineTableElement();
|
|
215
|
+
const table = document.querySelector<KtCodegenTable>("kt-codegen-table")!;
|
|
216
|
+
table.setData(data);
|
|
217
|
+
|
|
218
|
+
table.addEventListener("kt-codegen-table-change", () => {
|
|
219
|
+
// 宿主自行选择保存、页面隐藏或防抖时机,再整体取出;不需要逐单元格通信。
|
|
220
|
+
const next: KtCodegenTableData = table.getData();
|
|
221
|
+
});
|
|
222
|
+
```
|
|
223
|
+
|
|
224
|
+
- `setData()`/`getData()` 交换带 schema 与 `documentRevision` 的整表 DTO;返回值不暴露组件内部可变数组。
|
|
225
|
+
- Sort、Copy/Paste、Insert、Duplicate、Move、Delete 和列宽自适应属于组件内部操作。
|
|
226
|
+
- `kt-codegen-table-change` 只提示“内部数据变化”;宿主决定何时获取整表。`kt-codegen-table-dirty-change` 只在 clean/dirty 跃迁时发出。
|
|
227
|
+
- `configure()` 可替换列描述和 Combo 候选;未知旧值仍显示并保持,不会因渲染被清空。
|
|
228
|
+
- 文件 URI、JSON/CSV、保存冲突、Preflight 编排和 Output/Problems 留在产品宿主;Apply 的纯文本投影、指纹复核和多文件回滚事务复用 `KtCodegenApply`。DeskTools 可直接组合组件或再包一层 Vue wrapper。
|
|
229
|
+
|
|
230
|
+
## 共享 Apply 与宿主边界
|
|
231
|
+
|
|
232
|
+
`KtCodegenApply.ts` 把原先散落在产品宿主中的无 UI 算法集中为三组 API:
|
|
233
|
+
|
|
234
|
+
- `ktCodegenInspectApplyPlan()`:汇总 Target、Marker、Artifact、未命中控制符和“有 Marker 无 Artifact”状态,返回结构化数据;宿主自行格式化日志。
|
|
235
|
+
- `ktCodegenProjectApply()`:根据 `KtCodegenPlan`、源码文本与指纹形成整文件候选,校验区域缺失、重复、重叠、源码变化,并按目标 LF/CRLF 规范化生成文本;每个文件结果同时携带按源码顺序排列的 `region/artifact/block/class/line` 审计元数据。
|
|
236
|
+
- `ktCodegenCommitApplyWrites()`:通过泛型 `readFile`/`writeFile` Port 在每次写前复读字节;失败时逆序回滚,而且不会覆盖回滚期间出现的第三方内容。
|
|
237
|
+
|
|
238
|
+
Wing 不选择工作区、不弹窗、不发布 Problems、不决定源码编码,也不直接调用文件系统。VS Code/Desk Tools 负责工作区边界、未保存编辑器检查、UTF-8/GBK 编解码、真实文件 Port、Output 文本与诊断定位。这使两个宿主共享同一写回规则,同时保留各自 UI。
|
|
239
|
+
|
|
240
|
+
## 已迁移的参数核心语义
|
|
241
|
+
|
|
242
|
+
`KtCodegenCore` 已从 `KevinCAAParamInfor.vb` 提取第一组不依赖文件系统的纯 helper:
|
|
243
|
+
|
|
244
|
+
- 字符串默认值补引号;
|
|
245
|
+
- 分号恢复为 C++ 默认值列表中的逗号;
|
|
246
|
+
- `Spinner`/`QDoubleSpinBox` 的 `mm` 与 `degree/deg` 单位表达式转换;
|
|
247
|
+
- 旧3D点、向量、方向和射线类型集合;
|
|
248
|
+
- `IsParamSpecList` 的原判断顺序;
|
|
249
|
+
- 参数名末尾单独大写字符的提取规则;
|
|
250
|
+
- 五类 Dialog/Command Selector Field 的精确组件判断规则。
|
|
251
|
+
|
|
252
|
+
这些 helper 不修改 `KtCodegenItem`。默认值输出使用 [`core-default-values.json`](tests/fixtures/expected/core-default-values.json) 保存 golden cases,确保后续 Renderer 复用时保持旧行为。
|
|
253
|
+
|
|
254
|
+
## 使用方式
|
|
255
|
+
|
|
256
|
+
```ts
|
|
257
|
+
const controller = new KtCodegenController();
|
|
258
|
+
|
|
259
|
+
const loaded = controller.readCsv(csvText);
|
|
260
|
+
if (!loaded.ok) console.error(loaded.diagnostics);
|
|
261
|
+
|
|
262
|
+
// 数据类没有 getter/setter,也没有读写操作。
|
|
263
|
+
controller.param.items[0].defaultValue = "42";
|
|
264
|
+
|
|
265
|
+
// UI 可提示未知 Combo 值,但不能自动清空。
|
|
266
|
+
const known = KtCodegenOptions.hasComponent(
|
|
267
|
+
controller.param.items[0].component,
|
|
268
|
+
);
|
|
269
|
+
|
|
270
|
+
const json = controller.writeJson();
|
|
271
|
+
const plan = controller.analyze({
|
|
272
|
+
targets: ["caa.core", "qt.dialog", "cpp.parameter"],
|
|
273
|
+
snapshot: {
|
|
274
|
+
files: [{ path, text, fingerprint }],
|
|
275
|
+
},
|
|
276
|
+
});
|
|
277
|
+
|
|
278
|
+
const audit = ktCodegenInspectApplyPlan(plan);
|
|
279
|
+
const projection = ktCodegenProjectApply(plan, [{ path, text, fingerprint }]);
|
|
280
|
+
// 宿主先按原编码把 projection.changes 编码为字节,再把文件 Port 交给事务层。
|
|
281
|
+
const committed = await ktCodegenCommitApplyWrites(filePort, encodedWrites);
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
## 已实现范围
|
|
285
|
+
|
|
286
|
+
- 旧17列 CSV 读取与写出;
|
|
287
|
+
- CSV 转旧 v4 JSON;
|
|
288
|
+
- 旧 v4 JSON 读取与写出;
|
|
289
|
+
- `Count`/`ComponentCount` 等历史别名;
|
|
290
|
+
- 未知 Combo 字符串无损保留;
|
|
291
|
+
- 32个旧 block key;
|
|
292
|
+
- 32个 block 的 VB 调用、源码位置、主目标和废弃状态迁移矩阵;
|
|
293
|
+
- 第一组默认值、类型和列表核心 helper;
|
|
294
|
+
- 旧 Kevin Start/End 标记构造、只读扫描和精确替换偏移;
|
|
295
|
+
- 标记孤立、缺失、嵌套、错配和未知 block 诊断;
|
|
296
|
+
- 标记区域进入 Analyze Plan;
|
|
297
|
+
- 普通 C++ Parameter 的构造、声明、析构和赋值四块 Renderer;
|
|
298
|
+
- CAA 实现类与纯虚接口的 Get/Set 四块 Renderer;
|
|
299
|
+
- CAA 单参数 CPP Get/Set 与 Param 聚合桥接四块 Renderer;
|
|
300
|
+
- CAA Catalog 参数注册与 Factory On Tree 两块 Renderer;
|
|
301
|
+
- CAA Dialog Notify 控件通知注册块 Renderer;
|
|
302
|
+
- CAA Dialog Field 枚举及两个废弃 Selector 访问兼容块 Renderer;
|
|
303
|
+
- 废弃兼容块实际生成时返回不阻止 Apply 的结构化 warning;
|
|
304
|
+
- CAA Command Agent 声明、构造和析构三个宏块 Renderer;
|
|
305
|
+
- CAA Command BuildGraph、FIA Clear 与 UpdateState 三块 Renderer;
|
|
306
|
+
- CAA Command PDA/FIA Action、废弃 ElementSelected 与活动 Field 四块 Renderer;
|
|
307
|
+
- CAA/Qt Parameter 与 Dialog 双向更新四块 Renderer;
|
|
308
|
+
- artifact 通过 `regionId` 关联安全区域,并保留文件指纹、缩进和 LF/CRLF;
|
|
309
|
+
- Apply 计划审计、LF/CRLF 适配、整文件投影、写前复读与失败回滚;
|
|
310
|
+
- 32个归档旧 block 全部具备 Renderer、Marker artifact 与迁移状态测试;
|
|
311
|
+
- fixtures、结构化预期数据和单元测试。
|
|
312
|
+
|
|
313
|
+
当前 Analyze 读取调用者提供的不可变源码快照,`KtCodegenApply` 根据计划形成可审计的写回候选并提供文件 Port 事务;包本身仍不自行打开或写入真实文件。请求目标与标记完整时,计划可以返回 `canApply: true`,最终编码、权限、UI 与真实文件 Port 由宿主负责。
|
|
314
|
+
|
|
315
|
+
## 运行
|
|
316
|
+
|
|
317
|
+
```bash
|
|
318
|
+
pnpm typecheck
|
|
319
|
+
pnpm test
|
|
320
|
+
```
|
|
321
|
+
|
|
322
|
+
## 后续评审重点
|
|
323
|
+
|
|
324
|
+
1. `KtCodegenItem` 的17个公开字段是否完整。
|
|
325
|
+
2. `KtCodegenParam` 是否还有遗漏的类级共享字段。
|
|
326
|
+
3. Reader 与 Adapter 的职责边界是否需要继续合并。
|
|
327
|
+
4. `KtCodegenController` 是否只保留宿主编排职责。
|
|
328
|
+
5. CAA 的 model/core/control/dialog/parameter/feature-io 目标划分是否正确。
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import { type KtCodegenDataResult } from "./model/diagnostic.js";
|
|
2
|
+
import { type KtCodegenLegacyCsvWriteOptions } from "./legacy/csv.js";
|
|
3
|
+
import { KtCodegenParam } from "./KtCodegenParam.js";
|
|
4
|
+
/**
|
|
5
|
+
* 统一数据与旧格式之间的双向适配,以及共享实例的显式维护操作。
|
|
6
|
+
*
|
|
7
|
+
* Adapter 不持有业务状态。它负责把 `KtCodegenParam` 写成旧 v4 JSON/CSV,
|
|
8
|
+
* 并在 Controller 成功读取新配置后,把临时数据复制到原共享实例中。
|
|
9
|
+
* 未知 Combo 字符串不会在适配过程中被清空或替换。
|
|
10
|
+
*/
|
|
11
|
+
export declare class KtCodegenAdapter {
|
|
12
|
+
/**
|
|
13
|
+
* 用 `source` 的内容更新 `target`,但保留 `target` 及其主要嵌套容器的引用。
|
|
14
|
+
*
|
|
15
|
+
* `source` 中的 Item 会复制为新实例;`target.items`、`source.headers` 和
|
|
16
|
+
* `source.extensions` 对应的目标容器通过原地修改维护共享关系。
|
|
17
|
+
*
|
|
18
|
+
* @returns 传入的 `target`,便于 Controller 继续返回同一个共享实例。
|
|
19
|
+
*/
|
|
20
|
+
replace(target: KtCodegenParam, source: KtCodegenParam): KtCodegenParam;
|
|
21
|
+
/**
|
|
22
|
+
* 把共享实例恢复为原生空配置,同时保留该实例和主要嵌套容器的引用。
|
|
23
|
+
*
|
|
24
|
+
* @returns 已清空的 `target`。
|
|
25
|
+
*/
|
|
26
|
+
clear(target: KtCodegenParam): KtCodegenParam;
|
|
27
|
+
/**
|
|
28
|
+
* 校验并写出旧 C++/Qt 可读取的 v4 JSON 文本。
|
|
29
|
+
*
|
|
30
|
+
* 发生结构性错误时返回 `value: null`;未知 Combo 字符串不属于结构性错误,
|
|
31
|
+
* 会按原值写出。
|
|
32
|
+
*/
|
|
33
|
+
writeJson(param: KtCodegenParam, space?: number, rootKeys?: readonly string[]): KtCodegenDataResult<string>;
|
|
34
|
+
/**
|
|
35
|
+
* 校验并写出旧17列 CSV。
|
|
36
|
+
*
|
|
37
|
+
* 默认采用兼容旧 Qt `split(',')` 的简单方言,也可由 options 选择 RFC 4180。
|
|
38
|
+
* 写出结果中的 warning 用于提示简单方言可能发生的逗号或换行替换。
|
|
39
|
+
*/
|
|
40
|
+
writeCsv(param: KtCodegenParam, options?: KtCodegenLegacyCsvWriteOptions): KtCodegenDataResult<string>;
|
|
41
|
+
}
|
|
42
|
+
//# sourceMappingURL=KtCodegenAdapter.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"KtCodegenAdapter.d.ts","sourceRoot":"","sources":["../src/KtCodegenAdapter.ts"],"names":[],"mappings":"AAEA,OAAO,EAEL,KAAK,mBAAmB,EACzB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAEL,KAAK,8BAA8B,EACpC,MAAM,iBAAiB,CAAC;AAIzB,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD;;;;;;GAMG;AACH,qBAAa,gBAAgB;IAC3B;;;;;;;OAOG;IACH,OAAO,CAAC,MAAM,EAAE,cAAc,EAAE,MAAM,EAAE,cAAc,GAAG,cAAc;IA+BvE;;;;OAIG;IACH,KAAK,CAAC,MAAM,EAAE,cAAc,GAAG,cAAc;IAI7C;;;;;OAKG;IACH,SAAS,CACP,KAAK,EAAE,cAAc,EACrB,KAAK,SAAI,EACT,QAAQ,GAAE,SAAS,MAAM,EAAO,GAC/B,mBAAmB,CAAC,MAAM,CAAC;IAY9B;;;;;OAKG;IACH,QAAQ,CACN,KAAK,EAAE,cAAc,EACrB,OAAO,GAAE,8BAAmC,GAC3C,mBAAmB,CAAC,MAAM,CAAC;CAY/B"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
// SPDX-License-Identifier: Apache-2.0
|
|
2
|
+
import { ktCodegenHasDiagnosticErrors, } from "./model/diagnostic.js";
|
|
3
|
+
import { ktCodegenWriteLegacyCsv, } from "./legacy/csv.js";
|
|
4
|
+
import { ktCodegenWriteLegacyV4Json } from "./legacy/v4-json.js";
|
|
5
|
+
import { ktCodegenValidateParam } from "./model/validate.js";
|
|
6
|
+
import { KtCodegenItem } from "./KtCodegenItem.js";
|
|
7
|
+
import { KtCodegenParam } from "./KtCodegenParam.js";
|
|
8
|
+
/**
|
|
9
|
+
* 统一数据与旧格式之间的双向适配,以及共享实例的显式维护操作。
|
|
10
|
+
*
|
|
11
|
+
* Adapter 不持有业务状态。它负责把 `KtCodegenParam` 写成旧 v4 JSON/CSV,
|
|
12
|
+
* 并在 Controller 成功读取新配置后,把临时数据复制到原共享实例中。
|
|
13
|
+
* 未知 Combo 字符串不会在适配过程中被清空或替换。
|
|
14
|
+
*/
|
|
15
|
+
export class KtCodegenAdapter {
|
|
16
|
+
/**
|
|
17
|
+
* 用 `source` 的内容更新 `target`,但保留 `target` 及其主要嵌套容器的引用。
|
|
18
|
+
*
|
|
19
|
+
* `source` 中的 Item 会复制为新实例;`target.items`、`source.headers` 和
|
|
20
|
+
* `source.extensions` 对应的目标容器通过原地修改维护共享关系。
|
|
21
|
+
*
|
|
22
|
+
* @returns 传入的 `target`,便于 Controller 继续返回同一个共享实例。
|
|
23
|
+
*/
|
|
24
|
+
replace(target, source) {
|
|
25
|
+
if (target === source)
|
|
26
|
+
return target;
|
|
27
|
+
const sourceHeaders = [...source.source.headers];
|
|
28
|
+
const sourceExtensions = { ...source.source.extensions };
|
|
29
|
+
const sourceItems = source.items.map((item) => new KtCodegenItem(item));
|
|
30
|
+
target.kind = source.kind;
|
|
31
|
+
target.schemaVersion = source.schemaVersion;
|
|
32
|
+
target.source.format = source.source.format;
|
|
33
|
+
target.source.legacyType = source.source.legacyType;
|
|
34
|
+
target.source.legacyVersion = source.source.legacyVersion;
|
|
35
|
+
target.source.headers.splice(0, target.source.headers.length, ...sourceHeaders);
|
|
36
|
+
for (const key of Object.keys(target.source.extensions)) {
|
|
37
|
+
delete target.source.extensions[key];
|
|
38
|
+
}
|
|
39
|
+
Object.assign(target.source.extensions, sourceExtensions);
|
|
40
|
+
target.namePrefix = source.namePrefix;
|
|
41
|
+
target.nameMiddle = source.nameMiddle;
|
|
42
|
+
target.nameSpace = source.nameSpace;
|
|
43
|
+
target.appendFunction = source.appendFunction;
|
|
44
|
+
target.items.splice(0, target.items.length, ...sourceItems);
|
|
45
|
+
return target;
|
|
46
|
+
}
|
|
47
|
+
/**
|
|
48
|
+
* 把共享实例恢复为原生空配置,同时保留该实例和主要嵌套容器的引用。
|
|
49
|
+
*
|
|
50
|
+
* @returns 已清空的 `target`。
|
|
51
|
+
*/
|
|
52
|
+
clear(target) {
|
|
53
|
+
return this.replace(target, new KtCodegenParam());
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* 校验并写出旧 C++/Qt 可读取的 v4 JSON 文本。
|
|
57
|
+
*
|
|
58
|
+
* 发生结构性错误时返回 `value: null`;未知 Combo 字符串不属于结构性错误,
|
|
59
|
+
* 会按原值写出。
|
|
60
|
+
*/
|
|
61
|
+
writeJson(param, space = 4, rootKeys = []) {
|
|
62
|
+
const diagnostics = ktCodegenValidateParam(param);
|
|
63
|
+
if (ktCodegenHasDiagnosticErrors(diagnostics)) {
|
|
64
|
+
return { ok: false, value: null, diagnostics };
|
|
65
|
+
}
|
|
66
|
+
return {
|
|
67
|
+
ok: true,
|
|
68
|
+
value: ktCodegenWriteLegacyV4Json(param, space, rootKeys),
|
|
69
|
+
diagnostics,
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
/**
|
|
73
|
+
* 校验并写出旧17列 CSV。
|
|
74
|
+
*
|
|
75
|
+
* 默认采用兼容旧 Qt `split(',')` 的简单方言,也可由 options 选择 RFC 4180。
|
|
76
|
+
* 写出结果中的 warning 用于提示简单方言可能发生的逗号或换行替换。
|
|
77
|
+
*/
|
|
78
|
+
writeCsv(param, options = {}) {
|
|
79
|
+
const validationDiagnostics = ktCodegenValidateParam(param);
|
|
80
|
+
if (ktCodegenHasDiagnosticErrors(validationDiagnostics)) {
|
|
81
|
+
return { ok: false, value: null, diagnostics: validationDiagnostics };
|
|
82
|
+
}
|
|
83
|
+
const result = ktCodegenWriteLegacyCsv(param, options);
|
|
84
|
+
return {
|
|
85
|
+
...result,
|
|
86
|
+
diagnostics: [...validationDiagnostics, ...result.diagnostics],
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
//# sourceMappingURL=KtCodegenAdapter.js.map
|