@chengzhao-dev/dsh-cpp-workflow 0.7.9 → 0.7.11
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/README.en.md +8 -7
- package/README.md +5 -4
- package/cordis.patch.yml +2 -2
- package/icon.svg +5 -5
- package/lib/client.js +542 -538
- package/lib/comment-policy.js +37 -33
- package/lib/workspace.js +8 -10
- package/locale/en.json +4 -4
- package/locale/zh.json +4 -4
- package/package.json +100 -100
- package/skills/building-cpp/SKILL.md +5 -5
- package/skills/building-cpp/assets/config/.clang-tidy +4 -5
- package/skills/building-cpp/assets/config/.clangd +5 -7
- package/skills/building-cpp/assets/config/.vscode/extensions.json +5 -5
- package/skills/building-cpp/assets/config/.vscode/settings.json +56 -58
- package/skills/building-cpp/examples/environment.md +13 -102
- package/skills/building-cpp/references/01-build-script.md +3 -3
- package/skills/building-cpp/references/02-environment.md +8 -8
- package/skills/building-cpp/scripts/checking-environment.mjs +424 -424
- package/skills/building-cpp/steps/01-build.md +10 -10
- package/skills/building-cpp/steps/02-tooling.md +6 -6
- package/skills/building-cpp/steps/03-check.md +2 -2
- package/skills/building-cpp/steps/04-vscode.md +4 -6
- package/skills/developing-cpp/SKILL.md +8 -9
- package/skills/developing-cpp/references/comments/01-comment-rules.md +50 -26
- package/skills/developing-cpp/references/comments/02-style.md +33 -25
- package/skills/developing-cpp/references/comments/examples/03-declaration-enum.md +14 -14
- package/skills/developing-cpp/references/comments/examples/04-declaration-file.md +12 -8
- package/skills/developing-cpp/references/comments/examples/05-declaration-function.md +20 -10
- package/skills/developing-cpp/references/comments/examples/06-declaration-member.md +4 -4
- package/skills/developing-cpp/references/comments/examples/07-declaration-predicate.md +2 -2
- package/skills/developing-cpp/references/comments/examples/08-declaration-struct.md +6 -6
- package/skills/developing-cpp/references/comments/examples/09-implementation-body.md +41 -41
- package/skills/developing-cpp/references/comments/glossary/01-comment-terms.md +17 -16
- package/skills/developing-cpp/references/design/01-project-design.md +21 -10
- package/skills/developing-cpp/references/design/02-raii.md +5 -4
- package/skills/developing-cpp/references/design/03-third-party.md +2 -2
- package/skills/developing-cpp/references/design/examples/02-coordinate-table.md +12 -12
- package/skills/developing-cpp/references/design/examples/03-header-place.md +1 -1
- package/skills/developing-cpp/references/design/examples/04-library-boundary.md +6 -6
- package/skills/developing-cpp/references/design/examples/06-move-result.md +29 -28
- package/skills/developing-cpp/references/design/examples/07-preview-read.md +24 -23
- package/skills/developing-cpp/references/design/examples/08-screen-enter-exit.md +19 -18
- package/skills/developing-cpp/references/design/examples/09-option-menu.md +6 -6
- package/skills/developing-cpp/references/design/session-layer.md +13 -22
- package/skills/developing-cpp/references/exceptions/01-exception-rules.md +57 -57
- package/skills/developing-cpp/references/exceptions/examples/01-throw-boundary.md +7 -20
- package/skills/developing-cpp/references/exceptions/examples/02-throw-build-mode.md +10 -11
- package/skills/developing-cpp/references/exceptions/examples/03-throw-catch.md +4 -4
- package/skills/developing-cpp/references/exceptions/examples/04-throw-destructor.md +9 -5
- package/skills/developing-cpp/references/exceptions/examples/07-throw-when.md +2 -2
- package/skills/developing-cpp/references/index.md +32 -35
- package/skills/developing-cpp/references/language/glossary/01-language-terms.md +3 -2
- package/skills/developing-cpp/references/language/language-basics/02-initialization.md +1 -1
- package/skills/developing-cpp/references/language/language-basics/05-expressions.md +9 -2
- package/skills/developing-cpp/references/language/language-basics/06-functions.md +2 -3
- package/skills/developing-cpp/references/language/language-basics/09-templates.md +3 -3
- package/skills/developing-cpp/references/language/language-basics/10-language-checklist.md +9 -9
- package/skills/developing-cpp/references/language/performance/03-memory.md +1 -1
- package/skills/developing-cpp/references/language/performance/07-checklist.md +6 -6
- package/skills/developing-cpp/references/language/standard-library/01-containers.md +4 -5
- package/skills/developing-cpp/references/language/standard-library/02-access.md +2 -5
- package/skills/developing-cpp/references/language/standard-library/05-string.md +1 -1
- package/skills/developing-cpp/references/language/standard-library/06-format.md +22 -20
- package/skills/developing-cpp/references/language/standard-library/{11-format-ecosystem.md → 07-format-ecosystem.md} +2 -11
- package/skills/developing-cpp/references/language/standard-library/{07-time.md → 08-time.md} +1 -1
- package/skills/developing-cpp/references/language/standard-library/{09-files.md → 10-files.md} +1 -1
- package/skills/developing-cpp/references/language/standard-library/11-library-checklist.md +8 -0
- package/skills/developing-cpp/references/language/value-types/02-signed.md +7 -7
- package/skills/developing-cpp/references/language/value-types/03-integer-roles.md +14 -2
- package/skills/developing-cpp/references/language/value-types/05-strong-type.md +2 -2
- package/skills/developing-cpp/references/language/value-types/06-const-method.md +5 -5
- package/skills/developing-cpp/references/language/value-types/07-nodiscard.md +1 -1
- package/skills/developing-cpp/references/language/value-types/08-comparison.md +1 -1
- package/skills/developing-cpp/references/language/value-types/09-subscript.md +1 -1
- package/skills/developing-cpp/references/language/value-types/11-checklist.md +7 -7
- package/skills/developing-cpp/references/layout/01-source-layout.md +13 -13
- package/skills/developing-cpp/references/layout/02-file-template.md +10 -10
- package/skills/developing-cpp/references/layout/03-declaration-order.md +83 -42
- package/skills/developing-cpp/references/naming/01-identifier-names.md +32 -30
- package/skills/developing-cpp/references/naming/examples/06-naming-lower-layer.md +15 -15
- package/skills/developing-cpp/references/naming/examples/07-naming-multiple-return.md +2 -2
- package/skills/developing-cpp/references/naming/examples/13-naming-state-change.md +24 -23
- package/skills/developing-cpp/references/naming/glossary/01-naming-terms.md +3 -3
- package/skills/developing-cpp/references/naming/glossary/02-position.md +9 -9
- package/skills/developing-cpp/references/naming/glossary/03-selection.md +5 -1
- package/skills/developing-cpp/references/naming/glossary/04-square.md +3 -3
- package/skills/developing-cpp/references/naming/glossary/05-scoring.md +2 -2
- package/skills/developing-cpp/references/naming/glossary/06-difficulty.md +7 -7
- package/skills/developing-cpp/references/naming/glossary/07-stream.md +1 -1
- package/skills/developing-cpp/references/style/01-google-cpp-style.md +13 -23
- package/skills/developing-cpp/scripts/checking-comments.mjs +961 -755
- package/skills/developing-cpp/scripts/checking-declaration-order.mjs +512 -515
- package/skills/developing-cpp/steps/01-behavior.md +0 -1
- package/skills/developing-cpp/steps/02-boundary.md +2 -3
- package/skills/developing-cpp/steps/03-declaration.md +9 -10
- package/skills/developing-cpp/steps/04-implementation.md +7 -8
- package/skills/engineering/SKILL.md +9 -10
- package/skills/engineering/references/cmake/assets/LinkSettings.cmake +1 -1
- package/skills/engineering/references/cmake/linking/02-rpath.md +5 -6
- package/skills/engineering/references/cmake/modules/01-functions.md +9 -9
- package/skills/engineering/references/cmake/standards/01-cxx-standard.md +6 -6
- package/skills/engineering/references/cmake/standards/index.md +8 -29
- package/skills/engineering/references/cmake/targets/01-target-rules.md +14 -13
- package/skills/engineering/references/cmake/targets/examples/01-rpath.md +1 -1
- package/skills/engineering/references/cmake/testing/01-ctest.md +3 -3
- package/skills/engineering/references/formatting/01-encoding.md +5 -5
- package/skills/engineering/references/formatting/02-clang-format.md +2 -2
- package/skills/engineering/references/formatting/03-clang-tidy.md +5 -5
- package/skills/engineering/references/formatting/04-clangd.md +32 -39
- package/skills/engineering/references/formatting/05-config-comments.md +88 -0
- package/skills/engineering/references/formatting/examples/02-clang-tidy.md +6 -6
- package/skills/engineering/references/formatting/examples/03-clangd.md +17 -17
- package/skills/engineering/references/index.md +5 -4
- package/skills/engineering/scripts/checking-encoding.mjs +369 -369
- package/skills/engineering/steps/01-targets.md +3 -3
- package/skills/engineering/steps/02-modules.md +1 -2
- package/skills/engineering/steps/03-check.md +2 -3
- package/templates/cpp-workflow-project/SKILL.md +1 -1
- package/templates/cpp-workflow-project/environment.json +4 -4
- package/skills/developing-cpp/references/design/examples/05-library-split.md +0 -8
- package/skills/developing-cpp/references/language/standard-library/10-library-checklist.md +0 -10
- package/skills/developing-cpp/references/naming/examples/02-naming-basic.md +0 -4
- package/skills/developing-cpp/references/naming/examples/10-naming-rename.md +0 -6
- package/skills/engineering/references/formatting/examples/04-config-comments.md +0 -70
- /package/skills/developing-cpp/references/language/standard-library/{08-random.md → 09-random.md} +0 -0
package/lib/client.js
CHANGED
|
@@ -6,15 +6,15 @@ window.__ModuleLoader__.load({
|
|
|
6
6
|
var exports = module.exports
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
9
|
+
* 注释标签策略:设置页的预览、技能快照与检查器参数共用这一份。
|
|
10
|
+
*
|
|
11
|
+
* 配置只描述「写注释时默认带哪些标签、声明用哪种注释符号」,不描述写法本身;
|
|
12
|
+
* 写法在 `skills/developing-cpp/references/comments/01-comment-rules.md`。设置页保存的值由宿主
|
|
13
|
+
* 写回插件 Config,服务端 `apply(ctx, config)` 用它生成本页快照与检查器参数。
|
|
14
|
+
*
|
|
15
|
+
* 这份文件被 `tsc` 编进 `lib/comment-policy.js`,打包客户端半侧时再内联进
|
|
16
|
+
* `lib/client.js`,所以只能依赖纯函数,不要引入 Node 或 React。
|
|
17
|
+
*/
|
|
18
18
|
/** 文件头标签。 */
|
|
19
19
|
const HEADER_TAGS = ['brief', 'author', 'date', 'copyright', 'version'];
|
|
20
20
|
/** 函数声明标签:开关决定是否要求写出。 */
|
|
@@ -50,8 +50,8 @@ const SAMPLE_BRIEF = '<一句话说明本文件>';
|
|
|
50
50
|
/** 预览里的示例文件名:只是占位符,不对应任何工程的真实文件。 */
|
|
51
51
|
const SAMPLE_FILE = '<文件名>';
|
|
52
52
|
/**
|
|
53
|
-
|
|
54
|
-
|
|
53
|
+
* 出厂配置:声明用 `///`,除 @file 与函数体 // 外全部开启;空值仍不写文件头。
|
|
54
|
+
*/
|
|
55
55
|
const DEFAULT_CONFIG = {
|
|
56
56
|
commentStyle: 'slash',
|
|
57
57
|
brief: { enabled: true, value: '' },
|
|
@@ -70,9 +70,9 @@ const DEFAULT_CONFIG = {
|
|
|
70
70
|
retval: true,
|
|
71
71
|
};
|
|
72
72
|
/**
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
73
|
+
* 宿主把 volatile 字段交给插件时给的是可读写单元(`.get()`),设置页快照给的是普通值;
|
|
74
|
+
* 两种形状都要按同一个值读取。
|
|
75
|
+
*/
|
|
76
76
|
function unwrap(value) {
|
|
77
77
|
if (value !== null &&
|
|
78
78
|
typeof value === 'object' &&
|
|
@@ -94,8 +94,8 @@ function commentStyleOf(raw) {
|
|
|
94
94
|
return unwrap(raw) === 'block' ? 'block' : 'slash';
|
|
95
95
|
}
|
|
96
96
|
/**
|
|
97
|
-
|
|
98
|
-
|
|
97
|
+
* 把宿主给的值补齐成完整配置;缺字段、旧版本或手工改坏的配置都回到出厂值。
|
|
98
|
+
*/
|
|
99
99
|
function normalizeConfig(raw) {
|
|
100
100
|
const source = raw && typeof raw === 'object' ? raw : {};
|
|
101
101
|
const config = { commentStyle: commentStyleOf(source.commentStyle) };
|
|
@@ -120,8 +120,8 @@ function separatorLine(style) {
|
|
|
120
120
|
return style === 'block' ? ' *' : '///';
|
|
121
121
|
}
|
|
122
122
|
/**
|
|
123
|
-
|
|
124
|
-
|
|
123
|
+
* 按配置渲染文件头;`@file` 始终是传入的文件名,块注释按 Doxygen 结构分行。
|
|
124
|
+
*/
|
|
125
125
|
function renderFileHeader(raw, fileName) {
|
|
126
126
|
const config = normalizeConfig(raw);
|
|
127
127
|
const name = text(fileName) || SAMPLE_FILE;
|
|
@@ -139,9 +139,9 @@ function renderFileHeader(raw, fileName) {
|
|
|
139
139
|
return lines.map((line) => `/// ${line}`);
|
|
140
140
|
}
|
|
141
141
|
/**
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
142
|
+
* 设置页的预览:文件头 + 一段函数注释,只显示当前配置会写出的标签。
|
|
143
|
+
* 返回值里的 `header` 已按声明符号排好,`contract` 是每行标签的正文。
|
|
144
|
+
*/
|
|
145
145
|
function previewParts(raw, sampleName) {
|
|
146
146
|
const config = normalizeConfig(raw);
|
|
147
147
|
const header = renderFileHeader(config, sampleName || SAMPLE_FILE);
|
|
@@ -162,9 +162,9 @@ function previewParts(raw, sampleName) {
|
|
|
162
162
|
return { header, contract, declaration: '[[nodiscard]] bool Place(int row, int column);' };
|
|
163
163
|
}
|
|
164
164
|
/**
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
165
|
+
* 设置页预览的纯文本形式;客户端半侧用同一份实现渲染 `<pre>`。
|
|
166
|
+
* 块注释的每个内容行前加 ` * `,首尾各占一行。
|
|
167
|
+
*/
|
|
168
168
|
function previewText(raw, sampleName) {
|
|
169
169
|
const config = normalizeConfig(raw);
|
|
170
170
|
const { header, contract, declaration } = previewParts(config, sampleName);
|
|
@@ -184,9 +184,9 @@ function previewText(raw, sampleName) {
|
|
|
184
184
|
return lines.join('\n');
|
|
185
185
|
}
|
|
186
186
|
/**
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
187
|
+
* 检查器参数:隐私标签要显式放行,@brief 被关掉时跳过摘要检查,
|
|
188
|
+
* 声明符号切到块注释时让检查器按块注释收口。
|
|
189
|
+
*/
|
|
190
190
|
function checkerArgs(raw) {
|
|
191
191
|
const config = normalizeConfig(raw);
|
|
192
192
|
const args = [];
|
|
@@ -194,6 +194,10 @@ function checkerArgs(raw) {
|
|
|
194
194
|
args.push('--comment-style', 'block');
|
|
195
195
|
if (!config.brief.enabled)
|
|
196
196
|
args.push('--no-brief');
|
|
197
|
+
if (!config.param)
|
|
198
|
+
args.push('--no-param');
|
|
199
|
+
if (!config.returns)
|
|
200
|
+
args.push('--no-return');
|
|
197
201
|
for (const tag of PRIVACY_TAGS) {
|
|
198
202
|
if (config[tag].enabled && config[tag].value)
|
|
199
203
|
args.push('--allow-tag', tag);
|
|
@@ -201,12 +205,12 @@ function checkerArgs(raw) {
|
|
|
201
205
|
return args;
|
|
202
206
|
}
|
|
203
207
|
/**
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
208
|
+
* 技能快照:`get()` 把它接在技能正文末尾,让代理看到当前 profile 的标签开关。
|
|
209
|
+
* 只写一行,列出声明符号、开启与关闭的标签,避免正文膨胀。
|
|
210
|
+
* `@author` 等只认默认值的文件头标签开着却没填值时单列为「未填值」:这种标签
|
|
211
|
+
* 不会写进文件,与「关闭」不是一回事,代理据此既不会漏写,也不会补空标签。
|
|
212
|
+
* `@brief` 的正文按文件写,没有默认值也仍列为开启。
|
|
213
|
+
*/
|
|
210
214
|
function snapshotText(raw) {
|
|
211
215
|
const config = normalizeConfig(raw);
|
|
212
216
|
const on = ['@file'];
|
|
@@ -248,109 +252,109 @@ const h = React.createElement
|
|
|
248
252
|
const PACKAGE_NAME = '@chengzhao-dev/dsh-cpp-workflow'
|
|
249
253
|
|
|
250
254
|
const STRINGS = {
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
255
|
+
zh: {
|
|
256
|
+
nav: 'C++ 工程流程',
|
|
257
|
+
heading: '文档注释',
|
|
258
|
+
lede: '文件头、类型与函数声明各自决定默认写入哪些标签;预览随改动即时更新。',
|
|
259
|
+
style: '注释符号',
|
|
260
|
+
styleHint: '声明用哪种注释;函数体始终用 //。',
|
|
261
|
+
bodyRow: '函数体',
|
|
262
|
+
bodyPlaceholder: '固定 //',
|
|
263
|
+
header: '文件头',
|
|
264
|
+
headerHint: '开关打开后填写内容;空值不会写进文件。',
|
|
265
|
+
type: '类型',
|
|
266
|
+
typeHint: '类型块与函数模板里的补充标签。',
|
|
267
|
+
declaration: '函数声明',
|
|
268
|
+
declarationHint: '函数契约与前置、后置条件。',
|
|
269
|
+
preview: '预览',
|
|
270
|
+
previewHint: '代码块随开关和输入即时更新。',
|
|
271
|
+
filePlaceholder: '跟随文件名',
|
|
272
|
+
briefPlaceholder: '文件摘要:留空则各文件自写',
|
|
273
|
+
authorPlaceholder: '作者署名',
|
|
274
|
+
datePlaceholder: '日期',
|
|
275
|
+
copyrightPlaceholder: '版权',
|
|
276
|
+
versionPlaceholder: '版本',
|
|
277
|
+
paramPlaceholder: '逐项说明参数',
|
|
278
|
+
returnPlaceholder: '说明返回值',
|
|
279
|
+
throwsPlaceholder: '列出可能抛出的异常',
|
|
280
|
+
prePlaceholder: '前置条件',
|
|
281
|
+
postPlaceholder: '后置条件',
|
|
282
|
+
retvalPlaceholder: '按枚举值说明返回值',
|
|
283
|
+
tparamPlaceholder: '说明模板参数',
|
|
284
|
+
notePlaceholder: '补充说明',
|
|
285
|
+
seePlaceholder: '相关接口',
|
|
286
|
+
styleSlashExample: '/// @brief 定义棋盘。',
|
|
287
|
+
styleBlockExample: '/** @brief 定义棋盘。 */',
|
|
288
|
+
save: '保存',
|
|
289
|
+
reset: '撤销修改',
|
|
290
|
+
defaults: '恢复默认值',
|
|
291
|
+
restored: '已填入内置默认值,点“保存”后生效。',
|
|
292
|
+
saved: '已保存到 ~/.dsh/profiles/<profile>/cordis.patch.yml,下一次读取技能时生效。',
|
|
293
|
+
rejected: '保存被拒绝:配置可能已在别处修改。请先撤销修改,再重新编辑。',
|
|
294
|
+
unsaved: '有未保存的改动',
|
|
295
|
+
loading: '正在读取配置…',
|
|
296
|
+
unavailable: '这个部署没有提供这份配置。',
|
|
297
|
+
unreadable: '当前账户不能修改这份配置。',
|
|
298
|
+
readOnly: '这个页面暂时没有连到配置表单,下面的值是内置默认值。重启 DeepSeek Harness 后重新打开本页即可编辑。',
|
|
299
|
+
reload: '重新载入页面',
|
|
300
|
+
noService: '(configForms 服务未连接)',
|
|
301
|
+
},
|
|
302
|
+
en: {
|
|
303
|
+
nav: 'C++ Workflow',
|
|
304
|
+
heading: 'Doxygen comments',
|
|
305
|
+
lede: 'The file header, types, and declarations each decide which tags are written by default; the preview updates as you edit.',
|
|
306
|
+
style: 'Comment symbol',
|
|
307
|
+
styleHint: 'Symbol for declarations; function bodies always use //.',
|
|
308
|
+
bodyRow: 'Body',
|
|
309
|
+
bodyPlaceholder: 'Always //',
|
|
310
|
+
header: 'File header',
|
|
311
|
+
headerHint: 'Turn a tag on, then fill in its value; empty values are not written.',
|
|
312
|
+
type: 'Types',
|
|
313
|
+
typeHint: 'Extra tags for type blocks and function templates.',
|
|
314
|
+
declaration: 'Function declarations',
|
|
315
|
+
declarationHint: 'Function contracts plus pre- and postconditions.',
|
|
316
|
+
preview: 'Preview',
|
|
317
|
+
previewHint: 'The code block updates as you toggle switches and type.',
|
|
318
|
+
filePlaceholder: 'Follows the file name',
|
|
319
|
+
briefPlaceholder: 'File summary: leave empty for each file',
|
|
320
|
+
authorPlaceholder: 'Author',
|
|
321
|
+
datePlaceholder: 'Date',
|
|
322
|
+
copyrightPlaceholder: 'Copyright',
|
|
323
|
+
versionPlaceholder: 'Version',
|
|
324
|
+
paramPlaceholder: 'Describe each parameter',
|
|
325
|
+
returnPlaceholder: 'Describe the return value',
|
|
326
|
+
throwsPlaceholder: 'List exceptions that may be thrown',
|
|
327
|
+
prePlaceholder: 'Precondition',
|
|
328
|
+
postPlaceholder: 'Postcondition',
|
|
329
|
+
retvalPlaceholder: 'Describe a named return value',
|
|
330
|
+
tparamPlaceholder: 'Describe template parameters',
|
|
331
|
+
notePlaceholder: 'Additional notes',
|
|
332
|
+
seePlaceholder: 'Related interfaces',
|
|
333
|
+
styleSlashExample: '/// @brief Defines the board.',
|
|
334
|
+
styleBlockExample: '/** @brief Defines the board. */',
|
|
335
|
+
save: 'Save',
|
|
336
|
+
reset: 'Discard changes',
|
|
337
|
+
defaults: 'Restore defaults',
|
|
338
|
+
restored: 'Built-in defaults are filled in; select Save to apply them.',
|
|
339
|
+
saved: 'Saved to ~/.dsh/profiles/<profile>/cordis.patch.yml; the next skill read uses it.',
|
|
340
|
+
rejected: 'The host rejected the save: the config changed elsewhere. Discard your changes and edit again.',
|
|
341
|
+
unsaved: 'Unsaved changes',
|
|
342
|
+
loading: 'Reading configuration…',
|
|
343
|
+
unavailable: 'This deployment does not serve this configuration.',
|
|
344
|
+
unreadable: 'This account cannot edit the configuration.',
|
|
345
|
+
readOnly: 'This page is not connected to a configuration form yet; the values below are built-in defaults. Restart DeepSeek Harness, then reopen this page to edit.',
|
|
346
|
+
reload: 'Reload page',
|
|
347
|
+
noService: ' (the configForms service is not connected)',
|
|
348
|
+
},
|
|
345
349
|
}
|
|
346
350
|
|
|
347
351
|
function language() {
|
|
348
|
-
|
|
349
|
-
|
|
352
|
+
const value = typeof navigator !== 'undefined' && navigator.language ? navigator.language : 'zh'
|
|
353
|
+
return String(value).toLowerCase().startsWith('zh') ? 'zh' : 'en'
|
|
350
354
|
}
|
|
351
355
|
|
|
352
356
|
function t() {
|
|
353
|
-
|
|
357
|
+
return STRINGS[language()]
|
|
354
358
|
}
|
|
355
359
|
|
|
356
360
|
const STYLE_ID = 'dsh-cpp-workflow-settings'
|
|
@@ -419,205 +423,205 @@ const CSS = `
|
|
|
419
423
|
`
|
|
420
424
|
|
|
421
425
|
function ensureStyles() {
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
426
|
+
if (typeof document === 'undefined' || !document.createElement) return
|
|
427
|
+
if (document.querySelector && document.querySelector(`style[data-plugin-css="${STYLE_ID}"]`)) return
|
|
428
|
+
const style = document.createElement('style')
|
|
429
|
+
style.dataset.pluginCss = STYLE_ID
|
|
430
|
+
style.textContent = CSS
|
|
431
|
+
if (document.head && document.head.appendChild) document.head.appendChild(style)
|
|
428
432
|
}
|
|
429
433
|
|
|
430
434
|
function Switch(props) {
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
435
|
+
return h(
|
|
436
|
+
'label',
|
|
437
|
+
{ className: 'dcw-switch' },
|
|
438
|
+
h('input', {
|
|
439
|
+
type: 'checkbox',
|
|
440
|
+
checked: Boolean(props.checked),
|
|
441
|
+
disabled: Boolean(props.disabled),
|
|
442
|
+
'aria-label': props.label,
|
|
443
|
+
onChange: (event) => props.onChange(event.target.checked),
|
|
444
|
+
}),
|
|
445
|
+
h('span', { className: 'dcw-track' }, h('span', { className: 'dcw-knob' })),
|
|
446
|
+
)
|
|
443
447
|
}
|
|
444
448
|
|
|
445
449
|
/** 设置页的分组卡片:标题下一句说明,正文按行排控件。 */
|
|
446
450
|
function Section(props) {
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
451
|
+
return h(
|
|
452
|
+
'section',
|
|
453
|
+
{ className: 'dcw-card' },
|
|
454
|
+
h(
|
|
455
|
+
'div',
|
|
456
|
+
{ className: 'dcw-card-head' },
|
|
457
|
+
h('h4', { className: 'dcw-card-title' }, props.title),
|
|
458
|
+
props.hint ? h('p', { className: 'dcw-card-hint' }, props.hint) : null,
|
|
459
|
+
),
|
|
460
|
+
h('div', { className: 'dcw-card-body' }, props.children),
|
|
461
|
+
)
|
|
458
462
|
}
|
|
459
463
|
|
|
460
464
|
/** 文件头可填写的一行:标题与开关一行,输入框整行在下;关闭时收起输入框。 */
|
|
461
465
|
function ValueRow(props) {
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
|
|
484
|
-
|
|
485
|
-
|
|
486
|
-
|
|
487
|
-
|
|
488
|
-
|
|
489
|
-
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
466
|
+
const entry = props.entry
|
|
467
|
+
return h(
|
|
468
|
+
'div',
|
|
469
|
+
{
|
|
470
|
+
className: 'dcw-row dcw-row-value',
|
|
471
|
+
onClick: (event) => {
|
|
472
|
+
if (props.disabled) return
|
|
473
|
+
if (event.target.closest('.dcw-switch, .dcw-input')) return
|
|
474
|
+
props.onChange({ ...entry, enabled: !entry.enabled })
|
|
475
|
+
},
|
|
476
|
+
},
|
|
477
|
+
h(
|
|
478
|
+
'div',
|
|
479
|
+
{ className: 'dcw-row-main' },
|
|
480
|
+
h('span', { className: 'dcw-row-label' }, TAG_LABEL[props.tag]),
|
|
481
|
+
),
|
|
482
|
+
h(Switch, {
|
|
483
|
+
label: TAG_LABEL[props.tag],
|
|
484
|
+
checked: entry.enabled,
|
|
485
|
+
disabled: props.disabled,
|
|
486
|
+
onChange: (enabled) => props.onChange({ ...entry, enabled }),
|
|
487
|
+
}),
|
|
488
|
+
entry.enabled
|
|
489
|
+
? h('input', {
|
|
490
|
+
className: 'dcw-input',
|
|
491
|
+
type: 'text',
|
|
492
|
+
value: entry.value,
|
|
493
|
+
placeholder: props.placeholder,
|
|
494
|
+
disabled: props.disabled,
|
|
495
|
+
'aria-label': `${TAG_LABEL[props.tag]} 的值`,
|
|
496
|
+
onChange: (event) => props.onChange({ ...entry, value: event.target.value }),
|
|
497
|
+
})
|
|
498
|
+
: null,
|
|
499
|
+
)
|
|
496
500
|
}
|
|
497
501
|
|
|
498
502
|
/** 只有开关的标签行;说明放在标题下面,不再放一个不可用的假输入框。 */
|
|
499
503
|
function FlagRow(props) {
|
|
500
|
-
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
504
|
+
return h(
|
|
505
|
+
'div',
|
|
506
|
+
{
|
|
507
|
+
className: 'dcw-row dcw-row-flag',
|
|
508
|
+
onClick: (event) => {
|
|
509
|
+
if (props.disabled) return
|
|
510
|
+
if (event.target.closest('.dcw-switch, .dcw-input')) return
|
|
511
|
+
props.onChange(!props.checked)
|
|
512
|
+
},
|
|
513
|
+
},
|
|
514
|
+
h(
|
|
515
|
+
'div',
|
|
516
|
+
{ className: 'dcw-row-main' },
|
|
517
|
+
h('span', { className: 'dcw-row-label' }, TAG_LABEL[props.tag]),
|
|
518
|
+
props.hint ? h('span', { className: 'dcw-row-hint' }, props.hint) : null,
|
|
519
|
+
),
|
|
520
|
+
h(Switch, {
|
|
521
|
+
label: TAG_LABEL[props.tag],
|
|
522
|
+
checked: props.checked,
|
|
523
|
+
disabled: props.disabled,
|
|
524
|
+
onChange: props.onChange,
|
|
525
|
+
}),
|
|
526
|
+
)
|
|
523
527
|
}
|
|
524
528
|
|
|
525
529
|
/** 值由文件或语法固定的行:右侧写成普通文本,不放锁图标。 */
|
|
526
530
|
function LockRow(props) {
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
531
|
+
return h(
|
|
532
|
+
'div',
|
|
533
|
+
{ className: 'dcw-row dcw-row-fixed' },
|
|
534
|
+
h(
|
|
535
|
+
'div',
|
|
536
|
+
{ className: 'dcw-row-main' },
|
|
537
|
+
h('span', { className: 'dcw-row-label' }, props.label),
|
|
538
|
+
),
|
|
539
|
+
h('span', { className: 'dcw-fixed-value' }, props.value),
|
|
540
|
+
)
|
|
537
541
|
}
|
|
538
542
|
|
|
539
543
|
/** 两种声明注释符号:两张等宽卡片,上面符号、下面示例。 */
|
|
540
544
|
function StyleRow(props) {
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
|
|
561
|
-
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
545
|
+
const options = [
|
|
546
|
+
{ value: 'slash', symbol: '///', example: props.slashExample },
|
|
547
|
+
{ value: 'block', symbol: '/** */', example: props.blockExample },
|
|
548
|
+
]
|
|
549
|
+
return h(
|
|
550
|
+
'div',
|
|
551
|
+
{ className: 'dcw-style-options', role: 'radiogroup', 'aria-label': props.label },
|
|
552
|
+
options.map((option) =>
|
|
553
|
+
h(
|
|
554
|
+
'button',
|
|
555
|
+
{
|
|
556
|
+
key: option.value,
|
|
557
|
+
type: 'button',
|
|
558
|
+
role: 'radio',
|
|
559
|
+
'aria-checked': props.value === option.value ? 'true' : 'false',
|
|
560
|
+
className: 'dcw-style-option',
|
|
561
|
+
disabled: props.disabled,
|
|
562
|
+
onClick: () => props.onChange(option.value),
|
|
563
|
+
},
|
|
564
|
+
h('span', { className: 'dcw-style-symbol' }, option.symbol),
|
|
565
|
+
h('span', { className: 'dcw-style-example' }, option.example),
|
|
566
|
+
),
|
|
567
|
+
),
|
|
568
|
+
)
|
|
565
569
|
}
|
|
566
570
|
|
|
567
571
|
function Preview(props) {
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
572
|
+
const s = props.strings
|
|
573
|
+
return h(
|
|
574
|
+
Section,
|
|
575
|
+
{ title: s.preview, hint: s.previewHint },
|
|
576
|
+
h(
|
|
577
|
+
'div',
|
|
578
|
+
{ className: 'dcw-preview' },
|
|
579
|
+
h('div', { className: 'dcw-preview-head' }, h('span', { className: 'dcw-preview-dot' }), SAMPLE_FILE),
|
|
580
|
+
h('pre', { className: 'dcw-preview-body' }, previewText(props.config, SAMPLE_FILE)),
|
|
581
|
+
),
|
|
582
|
+
)
|
|
579
583
|
}
|
|
580
584
|
|
|
581
585
|
function diffOperations(draft, base) {
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
|
|
589
|
-
|
|
590
|
-
|
|
591
|
-
|
|
586
|
+
const operations = []
|
|
587
|
+
for (const key of Object.keys(DEFAULT_CONFIG)) {
|
|
588
|
+
const next = draft[key]
|
|
589
|
+
const previous = base[key]
|
|
590
|
+
if (next !== null && typeof next === 'object') {
|
|
591
|
+
// 文件头字段整体不是 volatile,宿主只接受叶子路径(brief.enabled / brief.value)。
|
|
592
|
+
const before = previous !== null && typeof previous === 'object' ? previous : {}
|
|
593
|
+
for (const field of Object.keys(next)) {
|
|
594
|
+
if (JSON.stringify(next[field]) !== JSON.stringify(before[field])) {
|
|
595
|
+
operations.push({ op: 'set', path: [key, field], value: next[field] })
|
|
596
|
+
}
|
|
597
|
+
}
|
|
598
|
+
continue
|
|
599
|
+
}
|
|
600
|
+
if (JSON.stringify(next) !== JSON.stringify(previous)) {
|
|
601
|
+
operations.push({ op: 'set', path: [key], value: next })
|
|
592
602
|
}
|
|
593
|
-
}
|
|
594
|
-
continue
|
|
595
|
-
}
|
|
596
|
-
if (JSON.stringify(next) !== JSON.stringify(previous)) {
|
|
597
|
-
operations.push({ op: 'set', path: [key], value: next })
|
|
598
603
|
}
|
|
599
|
-
|
|
600
|
-
return operations
|
|
604
|
+
return operations
|
|
601
605
|
}
|
|
602
606
|
|
|
603
607
|
function snapshotOf(form) {
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
608
|
+
if (!form) return { status: 'missing', writable: false }
|
|
609
|
+
if (typeof form.getSnapshot === 'function') return form.getSnapshot()
|
|
610
|
+
return form.state || { status: 'missing', writable: false }
|
|
607
611
|
}
|
|
608
612
|
|
|
609
613
|
// 宿主的 ConfigFormController 是可订阅的外部存储;旧调用方仍可能直接给 form.state。
|
|
610
614
|
function useFormSnapshot(form) {
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
615
|
+
const [snapshot, setSnapshot] = React.useState(() => snapshotOf(form))
|
|
616
|
+
React.useEffect(() => {
|
|
617
|
+
if (!form || typeof form.subscribe !== 'function' || typeof form.getSnapshot !== 'function') {
|
|
618
|
+
setSnapshot(snapshotOf(form))
|
|
619
|
+
return undefined
|
|
620
|
+
}
|
|
621
|
+
setSnapshot(form.getSnapshot())
|
|
622
|
+
return form.subscribe(() => setSnapshot(form.getSnapshot()))
|
|
623
|
+
}, [form])
|
|
624
|
+
return snapshot
|
|
621
625
|
}
|
|
622
626
|
|
|
623
627
|
// 配置卡片本身:状态机、保存/撤销/恢复默认值,以及组合包条目里的挂点。
|
|
@@ -629,274 +633,274 @@ const ENTRY_ID = 'cpp-workflow'
|
|
|
629
633
|
|
|
630
634
|
/** 文件头可填写标签的占位文字;顺序与 HEADER_TAGS 一致。 */
|
|
631
635
|
const HEADER_PLACEHOLDER = {
|
|
632
|
-
|
|
633
|
-
|
|
634
|
-
|
|
635
|
-
|
|
636
|
-
|
|
636
|
+
brief: 'briefPlaceholder',
|
|
637
|
+
author: 'authorPlaceholder',
|
|
638
|
+
date: 'datePlaceholder',
|
|
639
|
+
copyright: 'copyrightPlaceholder',
|
|
640
|
+
version: 'versionPlaceholder',
|
|
637
641
|
}
|
|
638
642
|
|
|
639
643
|
/** 只有开关的标签按区块取占位文字。 */
|
|
640
644
|
const FLAG_PLACEHOLDER = {
|
|
641
|
-
|
|
642
|
-
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
645
|
+
param: 'paramPlaceholder',
|
|
646
|
+
returns: 'returnPlaceholder',
|
|
647
|
+
throws: 'throwsPlaceholder',
|
|
648
|
+
pre: 'prePlaceholder',
|
|
649
|
+
post: 'postPlaceholder',
|
|
650
|
+
retval: 'retvalPlaceholder',
|
|
651
|
+
tparam: 'tparamPlaceholder',
|
|
652
|
+
note: 'notePlaceholder',
|
|
653
|
+
see: 'seePlaceholder',
|
|
650
654
|
}
|
|
651
655
|
|
|
652
656
|
function ConfigPage(props) {
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
|
|
675
|
-
|
|
676
|
-
|
|
677
|
-
|
|
678
|
-
|
|
679
|
-
|
|
680
|
-
|
|
681
|
-
|
|
682
|
-
|
|
683
|
-
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
|
|
689
|
-
|
|
690
|
-
|
|
691
|
-
}
|
|
692
|
-
|
|
693
|
-
// 撤销:回到最近一次从宿主读到的值,不写盘。
|
|
694
|
-
const reset = () => {
|
|
695
|
-
setDraft(base)
|
|
696
|
-
setDirty(false)
|
|
697
|
-
setMessage('')
|
|
698
|
-
setTone('')
|
|
699
|
-
}
|
|
700
|
-
|
|
701
|
-
// 恢复默认值:只填进草稿,点“保存”后才写盘,避免误触直接覆盖已保存的配置。
|
|
702
|
-
const restoreDefaults = () => {
|
|
703
|
-
const next = normalizeConfig(DEFAULT_CONFIG)
|
|
704
|
-
setDraft(next)
|
|
705
|
-
setDirty(diffOperations(next, base).length > 0)
|
|
706
|
-
setMessage(s.restored)
|
|
707
|
-
setTone('')
|
|
708
|
-
}
|
|
709
|
-
|
|
710
|
-
const reload = () => {
|
|
711
|
-
if (typeof window !== 'undefined' && window.location && typeof window.location.reload === 'function') {
|
|
712
|
-
window.location.reload()
|
|
657
|
+
const s = t()
|
|
658
|
+
ensureStyles()
|
|
659
|
+
// 宿主把 configForms 列为必需注入,挂载时取一次表单;之后沿用同一个 controller,
|
|
660
|
+
// 不在每次绘制里调用宿主服务。
|
|
661
|
+
const [form] = React.useState(
|
|
662
|
+
() => props.form || (typeof props.resolveForm === 'function' ? props.resolveForm() : undefined),
|
|
663
|
+
)
|
|
664
|
+
const state = useFormSnapshot(form)
|
|
665
|
+
const initial = React.useMemo(() => normalizeConfig(state.value), [])
|
|
666
|
+
const [draft, setDraft] = React.useState(initial)
|
|
667
|
+
const [base, setBase] = React.useState(initial)
|
|
668
|
+
const [dirty, setDirty] = React.useState(false)
|
|
669
|
+
const [baseRevision, setBaseRevision] = React.useState(state.revision)
|
|
670
|
+
const [busy, setBusy] = React.useState(false)
|
|
671
|
+
const [message, setMessage] = React.useState('')
|
|
672
|
+
const [tone, setTone] = React.useState('')
|
|
673
|
+
const revision = state.revision
|
|
674
|
+
// 快照只有 status / writable / revision;旧版本多出来的 mode 字段已不存在,
|
|
675
|
+
// 再按它判断会把所有可写表单误判成只读。
|
|
676
|
+
const ready = Boolean(form && state.status === 'ready' && state.writable)
|
|
677
|
+
const status = state.status
|
|
678
|
+
const missing = !form
|
|
679
|
+
|
|
680
|
+
React.useEffect(() => {
|
|
681
|
+
if (dirty || state.status !== 'ready') return
|
|
682
|
+
const next = normalizeConfig(state.value)
|
|
683
|
+
setBase(next)
|
|
684
|
+
setBaseRevision(state.revision)
|
|
685
|
+
setDraft(next)
|
|
686
|
+
}, [revision, status, dirty, form, state.value])
|
|
687
|
+
|
|
688
|
+
// 脏标记按与已保存值的差集算:把开关关了又开回原值时,页面不该再说“有未保存的改动”。
|
|
689
|
+
const update = (patch) => {
|
|
690
|
+
const next = { ...draft, ...patch }
|
|
691
|
+
setDraft(next)
|
|
692
|
+
setDirty(diffOperations(next, base).length > 0)
|
|
693
|
+
setMessage('')
|
|
694
|
+
setTone('')
|
|
713
695
|
}
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
717
|
-
|
|
718
|
-
const operations = diffOperations(draft, base)
|
|
719
|
-
if (operations.length === 0) return
|
|
720
|
-
setBusy(true)
|
|
721
|
-
try {
|
|
722
|
-
// 基准 revision 与 base 同时记录:草稿期间外部若改过配置,这里传旧 revision,
|
|
723
|
-
// 宿主会拒绝,不会用新 revision 把旧草稿盖上去。
|
|
724
|
-
const accepted = await form.mutate(operations, baseRevision)
|
|
725
|
-
if (accepted) {
|
|
726
|
-
const fresh = snapshotOf(form)
|
|
727
|
-
if (fresh && fresh.status === 'ready') setBaseRevision(fresh.revision)
|
|
728
|
-
setBase(draft)
|
|
696
|
+
|
|
697
|
+
// 撤销:回到最近一次从宿主读到的值,不写盘。
|
|
698
|
+
const reset = () => {
|
|
699
|
+
setDraft(base)
|
|
729
700
|
setDirty(false)
|
|
730
|
-
setMessage(
|
|
731
|
-
setTone('
|
|
732
|
-
|
|
733
|
-
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
-
|
|
701
|
+
setMessage('')
|
|
702
|
+
setTone('')
|
|
703
|
+
}
|
|
704
|
+
|
|
705
|
+
// 恢复默认值:只填进草稿,点“保存”后才写盘,避免误触直接覆盖已保存的配置。
|
|
706
|
+
const restoreDefaults = () => {
|
|
707
|
+
const next = normalizeConfig(DEFAULT_CONFIG)
|
|
708
|
+
setDraft(next)
|
|
709
|
+
setDirty(diffOperations(next, base).length > 0)
|
|
710
|
+
setMessage(s.restored)
|
|
711
|
+
setTone('')
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
const reload = () => {
|
|
715
|
+
if (typeof window !== 'undefined' && window.location && typeof window.location.reload === 'function') {
|
|
716
|
+
window.location.reload()
|
|
738
717
|
}
|
|
739
|
-
setMessage(s.rejected)
|
|
740
|
-
setTone('warn')
|
|
741
|
-
}
|
|
742
|
-
} catch (error) {
|
|
743
|
-
setMessage(error instanceof Error ? error.message : String(error))
|
|
744
|
-
setTone('warn')
|
|
745
|
-
} finally {
|
|
746
|
-
setBusy(false)
|
|
747
718
|
}
|
|
748
|
-
|
|
749
|
-
|
|
750
|
-
|
|
751
|
-
|
|
752
|
-
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
|
|
765
|
-
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
|
|
793
|
-
|
|
794
|
-
|
|
795
|
-
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
808
|
-
|
|
809
|
-
|
|
810
|
-
|
|
811
|
-
|
|
812
|
-
|
|
813
|
-
|
|
814
|
-
|
|
815
|
-
|
|
816
|
-
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
|
|
820
|
-
|
|
821
|
-
|
|
822
|
-
|
|
823
|
-
|
|
824
|
-
|
|
825
|
-
|
|
826
|
-
|
|
827
|
-
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
|
|
831
|
-
|
|
832
|
-
|
|
833
|
-
|
|
834
|
-
|
|
835
|
-
|
|
836
|
-
|
|
837
|
-
|
|
838
|
-
|
|
839
|
-
|
|
840
|
-
|
|
841
|
-
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
719
|
+
|
|
720
|
+
const save = async () => {
|
|
721
|
+
if (!ready || busy) return
|
|
722
|
+
const operations = diffOperations(draft, base)
|
|
723
|
+
if (operations.length === 0) return
|
|
724
|
+
setBusy(true)
|
|
725
|
+
try {
|
|
726
|
+
// 基准 revision 与 base 同时记录:草稿期间外部若改过配置,这里传旧 revision,
|
|
727
|
+
// 宿主会拒绝,不会用新 revision 把旧草稿盖上去。
|
|
728
|
+
const accepted = await form.mutate(operations, baseRevision)
|
|
729
|
+
if (accepted) {
|
|
730
|
+
const fresh = snapshotOf(form)
|
|
731
|
+
if (fresh && fresh.status === 'ready') setBaseRevision(fresh.revision)
|
|
732
|
+
setBase(draft)
|
|
733
|
+
setDirty(false)
|
|
734
|
+
setMessage(s.saved)
|
|
735
|
+
setTone('ok')
|
|
736
|
+
} else {
|
|
737
|
+
// 被拒时宿主已刷新镜像;把基准对齐到新快照,撤销才不会回到过期值。
|
|
738
|
+
const fresh = snapshotOf(form)
|
|
739
|
+
if (fresh && fresh.status === 'ready') {
|
|
740
|
+
setBase(normalizeConfig(fresh.value))
|
|
741
|
+
setBaseRevision(fresh.revision)
|
|
742
|
+
}
|
|
743
|
+
setMessage(s.rejected)
|
|
744
|
+
setTone('warn')
|
|
745
|
+
}
|
|
746
|
+
} catch (error) {
|
|
747
|
+
setMessage(error instanceof Error ? error.message : String(error))
|
|
748
|
+
setTone('warn')
|
|
749
|
+
} finally {
|
|
750
|
+
setBusy(false)
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
|
|
754
|
+
const editable = Boolean(form)
|
|
755
|
+
const disabled = !ready
|
|
756
|
+
|
|
757
|
+
/** 一个标签一行:标题与说明,右侧开关。 */
|
|
758
|
+
const flag = (tag, checked) =>
|
|
759
|
+
h(FlagRow, {
|
|
760
|
+
key: tag,
|
|
761
|
+
tag,
|
|
762
|
+
checked,
|
|
763
|
+
disabled,
|
|
764
|
+
hint: s[FLAG_PLACEHOLDER[tag]],
|
|
765
|
+
onChange: (value) => update({ [tag]: value }),
|
|
766
|
+
})
|
|
767
|
+
|
|
768
|
+
return h(
|
|
769
|
+
'div',
|
|
770
|
+
{ className: 'dcw-page' },
|
|
771
|
+
h(
|
|
772
|
+
'header',
|
|
773
|
+
{ className: 'dcw-head' },
|
|
774
|
+
h('h3', { className: 'dcw-title' }, s.heading),
|
|
775
|
+
h('p', { className: 'dcw-lede' }, s.lede),
|
|
776
|
+
),
|
|
777
|
+
missing
|
|
778
|
+
? h(
|
|
779
|
+
'div',
|
|
780
|
+
{ className: 'dcw-note', role: 'status', 'data-tone': 'warn' },
|
|
781
|
+
h('span', { className: 'dcw-note-dot' }),
|
|
782
|
+
h(
|
|
783
|
+
'span',
|
|
784
|
+
null,
|
|
785
|
+
s.readOnly,
|
|
786
|
+
props.hasService === false ? h('span', { className: 'dcw-note-code' }, s.noService) : null,
|
|
787
|
+
),
|
|
788
|
+
h('button', { type: 'button', className: 'dcw-note-action', onClick: reload }, s.reload),
|
|
789
|
+
)
|
|
790
|
+
: null,
|
|
791
|
+
editable && !ready && status !== 'missing'
|
|
792
|
+
? h(
|
|
793
|
+
'div',
|
|
794
|
+
{ className: 'dcw-note', role: 'status' },
|
|
795
|
+
h('span', { className: 'dcw-note-dot' }),
|
|
796
|
+
h('span', null, status === 'loading' ? s.loading : status === 'unavailable' ? s.unavailable : s.unreadable),
|
|
797
|
+
)
|
|
798
|
+
: null,
|
|
799
|
+
h(
|
|
800
|
+
Section,
|
|
801
|
+
{ title: s.style, hint: s.styleHint },
|
|
802
|
+
h(StyleRow, {
|
|
803
|
+
label: s.style,
|
|
804
|
+
value: draft.commentStyle,
|
|
805
|
+
disabled,
|
|
806
|
+
slashExample: s.styleSlashExample,
|
|
807
|
+
blockExample: s.styleBlockExample,
|
|
808
|
+
onChange: (value) => update({ commentStyle: value }),
|
|
809
|
+
}),
|
|
810
|
+
h(LockRow, { label: s.bodyRow, value: s.bodyPlaceholder }),
|
|
811
|
+
),
|
|
812
|
+
h(
|
|
813
|
+
Section,
|
|
814
|
+
{ title: s.header, hint: s.headerHint },
|
|
815
|
+
h(LockRow, { label: TAG_LABEL.file, value: s.filePlaceholder }),
|
|
816
|
+
...HEADER_TAGS.map((tag) =>
|
|
817
|
+
h(ValueRow, {
|
|
818
|
+
key: tag,
|
|
819
|
+
tag,
|
|
820
|
+
entry: draft[tag],
|
|
821
|
+
disabled,
|
|
822
|
+
placeholder: s[HEADER_PLACEHOLDER[tag]],
|
|
823
|
+
onChange: (entry) => update({ [tag]: entry }),
|
|
824
|
+
}),
|
|
825
|
+
),
|
|
826
|
+
),
|
|
827
|
+
h(Section, { title: s.type, hint: s.typeHint }, ...TYPE_TAGS.map((tag) => flag(tag, draft[tag]))),
|
|
828
|
+
h(
|
|
829
|
+
Section,
|
|
830
|
+
{ title: s.declaration, hint: s.declarationHint },
|
|
831
|
+
...[...CONTRACT_TAGS, ...FUNCTION_EXTRA_TAGS].map((tag) => flag(tag, draft[tag])),
|
|
832
|
+
),
|
|
833
|
+
h(Preview, { config: draft, strings: s }),
|
|
834
|
+
editable
|
|
835
|
+
? h(
|
|
836
|
+
'div',
|
|
837
|
+
{ className: 'dcw-actions' },
|
|
838
|
+
h(
|
|
839
|
+
'button',
|
|
840
|
+
{
|
|
841
|
+
type: 'button',
|
|
842
|
+
className: 'dcw-btn dcw-btn-primary',
|
|
843
|
+
onClick: save,
|
|
844
|
+
disabled: busy || !ready || !dirty,
|
|
845
|
+
},
|
|
846
|
+
s.save,
|
|
847
|
+
),
|
|
848
|
+
h('button', { type: 'button', className: 'dcw-btn', onClick: reset, disabled: busy || !dirty }, s.reset),
|
|
849
|
+
h(
|
|
850
|
+
'button',
|
|
851
|
+
{ type: 'button', className: 'dcw-btn', onClick: restoreDefaults, disabled: busy || !ready },
|
|
852
|
+
s.defaults,
|
|
853
|
+
),
|
|
854
|
+
h('p', { className: 'dcw-status', role: 'status', 'data-tone': tone }, message || (dirty ? s.unsaved : '')),
|
|
855
|
+
)
|
|
856
|
+
: null,
|
|
857
|
+
)
|
|
854
858
|
}
|
|
855
859
|
|
|
856
860
|
function page(ownerProps, form, resolveForm, hasService) {
|
|
857
|
-
|
|
861
|
+
return h(ConfigPage, { ...(ownerProps || {}), form, resolveForm, hasService })
|
|
858
862
|
}
|
|
859
863
|
|
|
860
864
|
function apply(ctx) {
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
|
|
865
|
+
// 每次取表单都重新查询服务:宿主可能在本插件之后才挂载 configForms。
|
|
866
|
+
const resolveForm = () => {
|
|
867
|
+
if (!ctx.configForms || typeof ctx.configForms.get !== 'function') return undefined
|
|
868
|
+
try {
|
|
869
|
+
return ctx.configForms.get(ENTRY_ID)
|
|
870
|
+
} catch {
|
|
871
|
+
return undefined
|
|
872
|
+
}
|
|
873
|
+
}
|
|
874
|
+
const hasService = Boolean(ctx.configForms && typeof ctx.configForms.get === 'function')
|
|
875
|
+
const mount = () =>
|
|
876
|
+
ctx.slots.inject('plugins.bundle.config', () =>
|
|
877
|
+
ctx.slots.register(
|
|
878
|
+
{
|
|
879
|
+
name: 'plugins.bundle.config',
|
|
880
|
+
key: PACKAGE_NAME,
|
|
881
|
+
label: () => t().nav,
|
|
882
|
+
},
|
|
883
|
+
(ownerProps) =>
|
|
884
|
+
ownerProps && ownerProps.view === 'summary'
|
|
885
|
+
? null
|
|
886
|
+
: page(ownerProps, undefined, resolveForm, hasService),
|
|
887
|
+
),
|
|
888
|
+
)
|
|
889
|
+
if (ctx.configForms && typeof ctx.configForms.whileServed === 'function') {
|
|
890
|
+
ctx.effect(() => ctx.configForms.whileServed([ENTRY_ID], mount), 'dsh-cpp-workflow: 配置挂点')
|
|
891
|
+
} else {
|
|
892
|
+
// 旧宿主没有 whileServed 时也交给效果作用域注销挂点,卸载后不留悬挂注册。
|
|
893
|
+
ctx.effect(() => mount(), 'dsh-cpp-workflow: 配置挂点')
|
|
868
894
|
}
|
|
869
|
-
}
|
|
870
|
-
const hasService = Boolean(ctx.configForms && typeof ctx.configForms.get === 'function')
|
|
871
|
-
const mount = () =>
|
|
872
|
-
ctx.slots.inject('plugins.bundle.config', () =>
|
|
873
|
-
ctx.slots.register(
|
|
874
|
-
{
|
|
875
|
-
name: 'plugins.bundle.config',
|
|
876
|
-
key: PACKAGE_NAME,
|
|
877
|
-
label: () => t().nav,
|
|
878
|
-
},
|
|
879
|
-
(ownerProps) =>
|
|
880
|
-
ownerProps && ownerProps.view === 'summary'
|
|
881
|
-
? null
|
|
882
|
-
: page(ownerProps, undefined, resolveForm, hasService),
|
|
883
|
-
),
|
|
884
|
-
)
|
|
885
|
-
if (ctx.configForms && typeof ctx.configForms.whileServed === 'function') {
|
|
886
|
-
ctx.effect(() => ctx.configForms.whileServed([ENTRY_ID], mount), 'dsh-cpp-workflow: 配置挂点')
|
|
887
|
-
} else {
|
|
888
|
-
// 旧宿主没有 whileServed 时也交给效果作用域注销挂点,卸载后不留悬挂注册。
|
|
889
|
-
ctx.effect(() => mount(), 'dsh-cpp-workflow: 配置挂点')
|
|
890
|
-
}
|
|
891
895
|
}
|
|
892
896
|
|
|
893
897
|
module.exports = {
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
898
|
+
name: PACKAGE_NAME,
|
|
899
|
+
inject: ['slots', 'configForms'],
|
|
900
|
+
apply,
|
|
901
|
+
ConfigPage,
|
|
902
|
+
diffOperations,
|
|
903
|
+
previewText,
|
|
900
904
|
}
|
|
901
905
|
|
|
902
906
|
return module.exports
|