@chengzhao-dev/dsh-cpp-workflow 0.6.7 → 0.6.8

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/lib/client.js CHANGED
@@ -8,8 +8,8 @@ window.__ModuleLoader__.load({
8
8
  /**
9
9
  * 注释标签策略:设置页的预览、技能快照与检查器参数共用这一份。
10
10
  *
11
- * 配置只描述「写注释时默认带哪些标签」,不描述写法本身;写法在
12
- * `skills/developing-cpp/references/comments.md`。设置页保存的值由宿主
11
+ * 配置只描述「写注释时默认带哪些标签、声明用哪种注释符号」,不描述写法本身;
12
+ * 写法在 `skills/developing-cpp/references/comments.md`。设置页保存的值由宿主
13
13
  * 写回插件 Config,服务端 `apply(ctx, config)` 用它生成本页快照与检查器参数。
14
14
  *
15
15
  * 这份文件被 `tsc` 编进 `lib/comment-policy.js`,打包客户端半侧时再内联进
@@ -17,29 +17,16 @@ window.__ModuleLoader__.load({
17
17
  */
18
18
  /** 文件头标签。 */
19
19
  const HEADER_TAGS = ['brief', 'author', 'date', 'copyright', 'version'];
20
- /** 函数契约标签:开关决定是否要求写出。 */
20
+ /** 函数声明标签:开关决定是否要求写出。 */
21
21
  const CONTRACT_TAGS = ['param', 'returns', 'throws'];
22
- /** 折叠在「更多标签」里的可选标签:默认关闭。 */
22
+ /** 函数声明里默认关闭的补充标签。 */
23
+ const FUNCTION_EXTRA_TAGS = ['pre', 'post', 'retval'];
24
+ /** 类型标签:默认关闭,函数模板共用同一组键。 */
25
+ const TYPE_TAGS = ['tparam', 'note', 'see'];
26
+ /** 全部可选标签,快照与测试按它排序。 */
23
27
  const EXTRA_TAGS = ['note', 'see', 'pre', 'post', 'tparam', 'retval'];
24
28
  /** 只有用户主动填了非空值才放行的隐私标签。 */
25
29
  const PRIVACY_TAGS = ['author', 'date', 'copyright', 'version'];
26
- /** 标签说明:设置页逐行显示,用作行的辅助文字。 */
27
- const TAG_TEXT = {
28
- brief: '一句话说明这个文件定义或实现什么',
29
- author: '只在用户填了非空值时写出',
30
- date: '只在用户填了非空值时写出',
31
- copyright: '只在用户填了非空值时写出',
32
- version: '只在用户填了非空值时写出',
33
- param: '函数参数的含义、范围或所有权',
34
- returns: '返回值的条件;返回类型自明时可以省略',
35
- throws: '抛出的异常类型与条件;不抛异常的函数不写',
36
- note: '调用方需要注意的补充说明',
37
- see: '相关函数、类型或文档',
38
- pre: '调用前必须成立的条件',
39
- post: '调用后保证成立的条件',
40
- tparam: '模板参数',
41
- retval: '特定返回值的含义',
42
- };
43
30
  /** 开关型标签在设置页的标题。 */
44
31
  const TAG_LABEL = {
45
32
  file: '@file',
@@ -62,8 +49,9 @@ const TAG_LABEL = {
62
49
  const SAMPLE_BRIEF = '<一句话说明本文件>';
63
50
  /** 预览里的示例文件名:只是占位符,不对应任何工程的真实文件。 */
64
51
  const SAMPLE_FILE = '<文件名>';
65
- /** 出厂配置:文件头只留 @file 与 @brief,契约标签全开,隐私标签全关。 */
52
+ /** 出厂配置:声明用 `///`,文件头只留 @file 与 @brief,契约标签全开,其余关闭。 */
66
53
  const DEFAULT_CONFIG = {
54
+ commentStyle: 'slash',
67
55
  brief: { enabled: true, value: '' },
68
56
  author: { enabled: false, value: '' },
69
57
  date: { enabled: false, value: '' },
@@ -99,12 +87,16 @@ function flag(value, fallback) {
99
87
  const plain = unwrap(value);
100
88
  return typeof plain === 'boolean' ? plain : fallback;
101
89
  }
90
+ /** 声明符号只认两档;未知值回到 `///`。 */
91
+ function commentStyleOf(raw) {
92
+ return unwrap(raw) === 'block' ? 'block' : 'slash';
93
+ }
102
94
  /**
103
95
  * 把宿主给的值补齐成完整配置;缺字段、旧版本或手工改坏的配置都回到出厂值。
104
96
  */
105
97
  function normalizeConfig(raw) {
106
98
  const source = raw && typeof raw === 'object' ? raw : {};
107
- const config = {};
99
+ const config = { commentStyle: commentStyleOf(source.commentStyle) };
108
100
  for (const tag of HEADER_TAGS) {
109
101
  const entry = source[tag] && typeof source[tag] === 'object' ? source[tag] : {};
110
102
  config[tag] = {
@@ -117,59 +109,85 @@ function normalizeConfig(raw) {
117
109
  }
118
110
  return config;
119
111
  }
112
+ /** 一行声明注释:`/// 内容` 或块注释里的 ` * 内容`。 */
113
+ function declarationLine(style, content) {
114
+ return style === 'block' ? ` * ${content}` : `/// ${content}`;
115
+ }
116
+ /** 文件头后面的说明行:块注释里空行写成 ` *`。 */
117
+ function separatorLine(style) {
118
+ return style === 'block' ? ' *' : '///';
119
+ }
120
120
  /**
121
- * 按配置渲染文件头;`@file` 始终是传入的文件名。
121
+ * 按配置渲染文件头;`@file` 始终是传入的文件名,块注释按 Doxygen 结构分行。
122
122
  */
123
123
  function renderFileHeader(raw, fileName) {
124
124
  const config = normalizeConfig(raw);
125
125
  const name = text(fileName) || SAMPLE_FILE;
126
- const lines = [`/// @file ${name}`];
126
+ const lines = [`@file ${name}`];
127
127
  if (config.brief.enabled) {
128
- lines.push(config.brief.value ? `/// @brief ${config.brief.value}` : '/// @brief');
128
+ lines.push(config.brief.value ? `@brief ${config.brief.value}` : '@brief');
129
129
  }
130
130
  for (const tag of ['author', 'date', 'copyright', 'version']) {
131
131
  if (config[tag].enabled && config[tag].value)
132
- lines.push(`/// @${tag} ${config[tag].value}`);
132
+ lines.push(`@${tag} ${config[tag].value}`);
133
+ }
134
+ if (config.commentStyle === 'block') {
135
+ return ['/**', ...lines.map((line) => ` * ${line}`), ' */'];
133
136
  }
134
- return lines;
137
+ return lines.map((line) => `/// ${line}`);
135
138
  }
136
139
  /**
137
140
  * 设置页的预览:文件头 + 一段函数注释,只显示当前配置会写出的标签。
141
+ * 返回值里的 `header` 已按声明符号排好,`contract` 是每行标签的正文。
138
142
  */
139
143
  function previewParts(raw, sampleName) {
140
144
  const config = normalizeConfig(raw);
141
145
  const header = renderFileHeader(config, sampleName || SAMPLE_FILE);
142
146
  // 预览是示例:@brief 开着但用户没填句子时,用示例文件自己的摘要顶替。
143
- const briefIndex = header.indexOf('/// @brief');
144
- if (briefIndex !== -1)
145
- header[briefIndex] = `/// @brief ${SAMPLE_BRIEF}`;
147
+ const briefIndex = header.findIndex((line) => /@brief$/.test(line.trim()));
148
+ if (briefIndex !== -1) {
149
+ header[briefIndex] = header[briefIndex].replace(/@brief$/, `@brief ${SAMPLE_BRIEF}`);
150
+ }
146
151
  const contract = [];
147
152
  if (config.param)
148
- contract.push('/// @param row 目标行号。');
153
+ contract.push('@param row 目标行号。');
149
154
  if (config.returns)
150
- contract.push('/// @return 放置成功时为 true。');
155
+ contract.push('@return 放置成功时为 true。');
151
156
  if (config.throws)
152
- contract.push('/// @throws std::out_of_range 行号越界时抛出。');
153
- const declaration = '[[nodiscard]] bool Place(int row, int column);';
154
- return { header, contract, declaration };
157
+ contract.push('@throws std::out_of_range 行号越界时抛出。');
158
+ return { header, contract, declaration: '[[nodiscard]] bool Place(int row, int column);' };
155
159
  }
156
160
  /**
157
161
  * 设置页预览的纯文本形式;客户端半侧用同一份实现渲染 `<pre>`。
162
+ * 块注释的每个内容行前加 ` * `,首尾各占一行。
158
163
  */
159
164
  function previewText(raw, sampleName) {
160
- const { header, contract, declaration } = previewParts(raw, sampleName);
161
- const lines = [...header, '///', '/// 放置成功时返回 true;行号越界或目标格子已占时返回 false。'];
165
+ const config = normalizeConfig(raw);
166
+ const { header, contract, declaration } = previewParts(config, sampleName);
167
+ const style = config.commentStyle;
168
+ const summary = '放置成功时返回 true;行号越界或目标格子已占时返回 false。';
169
+ if (style === 'block') {
170
+ const body = [declarationLine(style, summary)];
171
+ if (contract.length > 0) {
172
+ body.push(separatorLine(style), ...contract.map((line) => declarationLine(style, line)));
173
+ }
174
+ return [...header, '/**', ...body, ' */', declaration].join('\n');
175
+ }
176
+ const lines = [...header, separatorLine(style), declarationLine(style, summary)];
162
177
  if (contract.length > 0)
163
- lines.push('///', ...contract);
178
+ lines.push(separatorLine(style), ...contract.map((line) => declarationLine(style, line)));
164
179
  lines.push(declaration);
165
180
  return lines.join('\n');
166
181
  }
167
182
  /**
168
- * 检查器参数:隐私标签要显式放行,@brief 被关掉时跳过摘要检查。
183
+ * 检查器参数:隐私标签要显式放行,@brief 被关掉时跳过摘要检查,
184
+ * 声明符号切到块注释时让检查器按块注释收口。
169
185
  */
170
186
  function checkerArgs(raw) {
171
187
  const config = normalizeConfig(raw);
172
188
  const args = [];
189
+ if (config.commentStyle === 'block')
190
+ args.push('--comment-style', 'block');
173
191
  if (!config.brief.enabled)
174
192
  args.push('--no-brief');
175
193
  for (const tag of PRIVACY_TAGS) {
@@ -180,10 +198,11 @@ function checkerArgs(raw) {
180
198
  }
181
199
  /**
182
200
  * 技能快照:`get()` 把它接在技能正文末尾,让代理看到当前 profile 的标签开关。
201
+ * 只写一行,列出声明符号、开启与关闭的标签,避免正文膨胀。
183
202
  */
184
203
  function snapshotText(raw) {
185
204
  const config = normalizeConfig(raw);
186
- const on = [];
205
+ const on = ['@file'];
187
206
  const off = [];
188
207
  for (const tag of HEADER_TAGS) {
189
208
  const entry = config[tag];
@@ -193,17 +212,15 @@ function snapshotText(raw) {
193
212
  else
194
213
  off.push(TAG_LABEL[tag]);
195
214
  }
196
- const contract = CONTRACT_TAGS.filter((tag) => config[tag]).map((tag) => TAG_LABEL[tag]);
197
- const extra = EXTRA_TAGS.filter((tag) => config[tag]).map((tag) => TAG_LABEL[tag]);
198
- const allowed = PRIVACY_TAGS.filter((tag) => config[tag].enabled && config[tag].value);
199
- const head = `## 当前注释配置(profile)\n\n`;
200
- const body = [
201
- `- 文件头:@file 固定为文件名;开启 ${on.join('、') || '无'};关闭 ${off.join('、') || '无'}。`,
202
- `- 函数契约:${contract.length > 0 ? contract.join('、') : '不要求'}。`,
203
- `- 更多标签:${extra.length > 0 ? `可选 ${extra.join('、')}` : '未启用'}。`,
204
- `- 检查器放行:${allowed.length > 0 ? allowed.join('、') : '无'}(隐私标签只有填了非空值才放行)。`,
205
- ];
206
- return head + body.join('\n');
215
+ for (const tag of [...CONTRACT_TAGS, ...EXTRA_TAGS]) {
216
+ if (config[tag])
217
+ on.push(TAG_LABEL[tag]);
218
+ else
219
+ off.push(TAG_LABEL[tag]);
220
+ }
221
+ const style = config.commentStyle === 'block' ? '/** ... */' : '///';
222
+ const line = `- 声明符号:${style}(函数体固定 //);开启 ${on.join('、')};关闭 ${off.join('、') || '无'}。`;
223
+ return `## 当前注释配置(profile)\n\n${line}`;
207
224
  }
208
225
 
209
226
 
@@ -218,29 +235,34 @@ const PACKAGE_NAME = '@chengzhao-dev/dsh-cpp-workflow'
218
235
  const STRINGS = {
219
236
  zh: {
220
237
  nav: 'C++ 工程流程',
221
- eyebrow: '文档注释',
222
- title: '注释默认带哪些标签',
223
- intro: '这里只决定代理新写注释时的默认值。源码里已有的注释不会被改写;保存后,下一次读取技能时生效。',
238
+ heading: '文档注释',
239
+ style: '注释符号',
240
+ bodyRow: '函数体',
241
+ bodyPlaceholder: '函数体:固定 //',
224
242
  header: '文件头',
225
- headerHint: '每个手写源文件开头的 /// 注释块。',
226
- briefHint: '一句话说明这个文件定义或实现什么。留空时,每个文件自己写。',
227
- authorHint: '作者署名。默认不写;打开并填写后才写进文件头。',
228
- dateHint: '创建或最后修改日期。默认不写。',
229
- copyrightHint: '版权声明。默认不写。',
230
- versionHint: '文件版本号。默认不写。',
231
- paramHint: '函数参数的含义、范围或所有权。',
232
- returnHint: '返回值在什么条件下成立。返回类型自明时可以省略。',
233
- throwsHint: '抛出的异常类型与条件。不抛异常的函数不写。',
234
- contractHint: '函数声明的注释里必须交代的参数与失败信息。',
235
- extra: '更多标签',
236
- extraHint: '默认关闭,需要时在单个函数上补写。',
243
+ type: '类型',
244
+ declaration: '函数声明',
237
245
  preview: '预览',
238
- previewHint: '按当前开关生成,文件名用占位符表示。',
246
+ filePlaceholder: '跟随文件名',
247
+ briefPlaceholder: '文件摘要:留空则各文件自写',
248
+ authorPlaceholder: '作者署名:默认不写',
249
+ datePlaceholder: '日期:默认不写',
250
+ copyrightPlaceholder: '版权:默认不写',
251
+ versionPlaceholder: '版本:默认不写',
252
+ paramPlaceholder: '参数:默认使用',
253
+ returnPlaceholder: '返回值:默认使用',
254
+ throwsPlaceholder: '异常:默认使用',
255
+ prePlaceholder: '前置条件:默认不使用',
256
+ postPlaceholder: '后置条件:默认不使用',
257
+ retvalPlaceholder: '返回值枚举:默认不使用',
258
+ tparamPlaceholder: '模板参数:默认不使用',
259
+ notePlaceholder: '补充:默认不使用',
260
+ seePlaceholder: '参见:默认不使用',
239
261
  save: '保存',
240
262
  reset: '撤销修改',
241
263
  defaults: '恢复默认值',
242
264
  restored: '已填入内置默认值,点“保存”后生效。',
243
- saved: '已保存,下一次读取技能时生效。',
265
+ saved: '已保存到 ~/.dsh/profiles/<profile>/cordis.patch.yml,下一次读取技能时生效。',
244
266
  rejected: '保存被拒绝:配置可能已在别处修改。请先撤销修改,再重新编辑。',
245
267
  unsaved: '有未保存的改动',
246
268
  loading: '正在读取配置…',
@@ -249,38 +271,37 @@ const STRINGS = {
249
271
  readOnly: '这个页面暂时没有连到配置表单,下面的值是内置默认值。重启 DeepSeek Harness 后重新打开本页即可编辑。',
250
272
  reload: '重新载入页面',
251
273
  noService: '(configForms 服务未连接)',
252
- fixed: '跟随文件名',
253
- fixedHint: '值由实际文件决定,不写进配置。',
254
- emptyValue: '留空则由文件自己写',
255
- blankBrief: '留空则文件自述',
256
- on: '写出',
257
- off: '不写',
258
274
  },
259
275
  en: {
260
276
  nav: 'C++ Workflow',
261
- eyebrow: 'Doxygen comments',
262
- title: 'Which tags comments carry by default',
263
- intro: 'These defaults apply to comments the agent writes from now on. Existing sources are never rewritten; saving takes effect on the next skill read.',
277
+ heading: 'Doxygen comments',
278
+ style: 'Comment symbol',
279
+ bodyRow: 'Body',
280
+ bodyPlaceholder: 'Function bodies: always //',
264
281
  header: 'File header',
265
- headerHint: 'The /// block at the top of each hand-written source file.',
266
- briefHint: 'One sentence saying what the file defines or implements. Leave the value to each file.',
267
- authorHint: 'Author name. Off by default; written only when filled.',
268
- dateHint: 'Created or last modified date. Off by default.',
269
- copyrightHint: 'Copyright notice. Off by default.',
270
- versionHint: 'File version. Off by default.',
271
- paramHint: 'Meaning, range, or ownership of a parameter.',
272
- returnHint: 'When the returned value holds. Optional when the type is self-evident.',
273
- throwsHint: 'Exception type and condition. Omitted when the function does not throw.',
274
- contractHint: 'Parameters and failure information every function comment must carry.',
275
- extra: 'More tags',
276
- extraHint: 'Off by default; add them per function when needed.',
282
+ type: 'Types',
283
+ declaration: 'Function declarations',
277
284
  preview: 'Preview',
278
- previewHint: 'Generated from the switches above; the file name is a placeholder.',
285
+ filePlaceholder: 'Follows the file name',
286
+ briefPlaceholder: 'File summary: leave empty for each file',
287
+ authorPlaceholder: 'Author: off by default',
288
+ datePlaceholder: 'Date: off by default',
289
+ copyrightPlaceholder: 'Copyright: off by default',
290
+ versionPlaceholder: 'Version: off by default',
291
+ paramPlaceholder: 'Parameters: on by default',
292
+ returnPlaceholder: 'Return value: on by default',
293
+ throwsPlaceholder: 'Exceptions: on by default',
294
+ prePlaceholder: 'Preconditions: off by default',
295
+ postPlaceholder: 'Postconditions: off by default',
296
+ retvalPlaceholder: 'Named return values: off by default',
297
+ tparamPlaceholder: 'Template parameters: off by default',
298
+ notePlaceholder: 'Notes: off by default',
299
+ seePlaceholder: 'See also: off by default',
279
300
  save: 'Save',
280
301
  reset: 'Discard changes',
281
302
  defaults: 'Restore defaults',
282
303
  restored: 'Built-in defaults are filled in; select Save to apply them.',
283
- saved: 'Saved; the next skill read uses it.',
304
+ saved: 'Saved to ~/.dsh/profiles/<profile>/cordis.patch.yml; the next skill read uses it.',
284
305
  rejected: 'The host rejected the save: the config changed elsewhere. Discard your changes and edit again.',
285
306
  unsaved: 'Unsaved changes',
286
307
  loading: 'Reading configuration…',
@@ -289,12 +310,6 @@ const STRINGS = {
289
310
  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.',
290
311
  reload: 'Reload page',
291
312
  noService: ' (the configForms service is not connected)',
292
- fixed: 'Follows the file name',
293
- fixedHint: 'Derived from the file itself, never stored in the config.',
294
- emptyValue: 'Leave empty and each file writes its own',
295
- blankBrief: 'Leave empty for each file',
296
- on: 'Write',
297
- off: 'Omit',
298
313
  },
299
314
  }
300
315
 
@@ -323,14 +338,18 @@ const CSS = `
323
338
  .dcw-card-head{display:flex;flex-wrap:wrap;align-items:baseline;gap:4px 10px;padding:11px 14px 9px;border-bottom:1px solid var(--dcw-border);background:var(--dcw-bg2)}
324
339
  .dcw-card-title{margin:0;font-size:12.5px;font-weight:620;letter-spacing:.01em}
325
340
  .dcw-card-hint{margin:0;color:var(--dcw-muted);font-size:11.5px;line-height:1.5}
326
- .dcw-row{display:grid;grid-template-columns:88px minmax(0,1fr);gap:2px 14px;padding:9px 14px;border-top:1px solid var(--dcw-border)}
341
+ .dcw-row{display:grid;grid-template-columns:84px 40px minmax(0,1fr);align-items:center;gap:8px 12px;padding:8px 14px;border-top:1px solid var(--dcw-border)}
327
342
  .dcw-row:first-of-type{border-top:0}
328
- .dcw-row-label{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:12px;color:var(--dcw-fg);padding-top:3px}
329
- .dcw-row-control{display:flex;flex-wrap:wrap;align-items:center;gap:6px 10px;min-width:0}
330
- .dcw-row-hint{flex-basis:100%;margin:0;color:var(--dcw-muted);font-size:11.5px;line-height:1.55}
331
- .dcw-row-fixed .dcw-row-control{gap:8px}
332
- .dcw-static{display:inline-flex;align-items:center;gap:6px;height:26px;padding:0 9px;border:1px dashed var(--dcw-border);border-radius:6px;background:var(--dcw-bg2);color:var(--dcw-muted);font-size:12px}
333
- .dcw-static svg{flex:none;opacity:.7}
343
+ .dcw-row-label{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:12px;color:var(--dcw-fg)}
344
+ .dcw-row-style{grid-template-columns:84px minmax(0,1fr)}
345
+ .dcw-row-style .dcw-segmented{grid-column:2}
346
+ .dcw-lock{display:inline-flex;align-items:center;justify-content:center;width:26px;height:26px;border:1px dashed var(--dcw-border);border-radius:6px;background:var(--dcw-bg2);color:var(--dcw-muted)}
347
+ .dcw-segmented{display:inline-flex;padding:2px;border:1px solid var(--dcw-border);border-radius:8px;background:var(--dcw-bg2);justify-self:start}
348
+ .dcw-segment{height:26px;padding:0 12px;border:0;border-radius:6px;background:transparent;color:var(--dcw-muted);font:inherit;font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:12px;cursor:pointer}
349
+ .dcw-segment:hover:enabled{color:var(--dcw-fg)}
350
+ .dcw-segment[aria-pressed="true"]{background:var(--dcw-bg1);color:var(--dcw-fg);box-shadow:0 1px 2px rgba(0,0,0,.12)}
351
+ .dcw-segment:focus-visible{outline:2px solid var(--dcw-accent);outline-offset:1px}
352
+ .dcw-segment:disabled{opacity:.45;cursor:default}
334
353
  .dcw-switch{position:relative;display:inline-flex;align-items:center;flex:none;width:34px;height:20px;cursor:pointer}
335
354
  .dcw-switch input{position:absolute;inset:0;margin:0;opacity:0;cursor:pointer}
336
355
  .dcw-track{position:absolute;inset:0;border-radius:999px;background:color-mix(in srgb,var(--dcw-fg) 18%,transparent);transition:background .16s ease}
@@ -368,7 +387,7 @@ const CSS = `
368
387
  .dcw-note-code{font-family:ui-monospace,SFMono-Regular,Menlo,Consolas,monospace;font-size:11px;opacity:.8;margin-left:6px}
369
388
  .dcw-note-action{margin-left:auto;flex:none;padding:3px 10px;border:1px solid currentColor;border-radius:6px;background:transparent;color:inherit;font:inherit;font-size:11.5px;cursor:pointer;white-space:nowrap}
370
389
  .dcw-note-action:hover{background:var(--dcw-bg1)}
371
- @media (max-width:640px){.dcw-row{grid-template-columns:1fr;gap:4px}.dcw-row-label{padding-top:0}.dcw-flags{grid-template-columns:1fr}.dcw-flag:nth-child(2){border-top:1px solid var(--dcw-border)}}
390
+ @media (max-width:640px){.dcw-row,.dcw-row-style{grid-template-columns:1fr 40px}.dcw-row-label{grid-column:1/-1}.dcw-row-style .dcw-segmented{grid-column:1/-1}}
372
391
  `
373
392
 
374
393
  function ensureStyles() {
@@ -414,78 +433,122 @@ function Chevron() {
414
433
  )
415
434
  }
416
435
 
417
- const HINT_KEY = {
418
- brief: 'briefHint',
419
- author: 'authorHint',
420
- date: 'dateHint',
421
- copyright: 'copyrightHint',
422
- version: 'versionHint',
423
- param: 'paramHint',
424
- returns: 'returnHint',
425
- throws: 'throwsHint',
436
+ /** 五个区块统一用默认展开的 details,标题在摘要行。 */
437
+ function Section(props) {
438
+ return h(
439
+ 'details',
440
+ { className: 'dcw-card', open: true },
441
+ h('summary', null, h('span', { className: 'dcw-card-title' }, props.title), h(Chevron)),
442
+ props.children,
443
+ )
426
444
  }
427
445
 
446
+ /** 文件头可填写的一行:标签、开关、文本框。 */
428
447
  function ValueRow(props) {
429
- const s = props.strings
430
448
  const entry = props.entry
431
449
  return h(
432
450
  'div',
433
451
  { className: 'dcw-row' },
434
452
  h('div', { className: 'dcw-row-label' }, TAG_LABEL[props.tag]),
435
- h(
436
- 'div',
437
- { className: 'dcw-row-control' },
438
- h(Switch, {
439
- label: TAG_LABEL[props.tag],
440
- checked: entry.enabled,
441
- disabled: props.disabled,
442
- onChange: (enabled) => props.onChange({ ...entry, enabled }),
443
- }),
444
- h('span', { className: 'dcw-state', 'aria-hidden': 'true' }, entry.enabled ? s.on : s.off),
445
- h('input', {
446
- className: 'dcw-input',
447
- type: 'text',
448
- value: entry.value,
449
- placeholder: props.tag === 'brief' ? s.blankBrief : s.emptyValue,
450
- disabled: props.disabled || !entry.enabled,
451
- 'aria-label': `${TAG_LABEL[props.tag]} 的值`,
452
- onChange: (event) => props.onChange({ ...entry, value: event.target.value }),
453
- }),
454
- h('p', { className: 'dcw-row-hint' }, s[HINT_KEY[props.tag]] || ''),
455
- ),
453
+ h(Switch, {
454
+ label: TAG_LABEL[props.tag],
455
+ checked: entry.enabled,
456
+ disabled: props.disabled,
457
+ onChange: (enabled) => props.onChange({ ...entry, enabled }),
458
+ }),
459
+ h('input', {
460
+ className: 'dcw-input',
461
+ type: 'text',
462
+ value: entry.value,
463
+ placeholder: props.placeholder,
464
+ disabled: props.disabled || !entry.enabled,
465
+ 'aria-label': `${TAG_LABEL[props.tag]} 的值`,
466
+ onChange: (event) => props.onChange({ ...entry, value: event.target.value }),
467
+ }),
468
+ )
469
+ }
470
+
471
+ /** 只有开关的标签行;右侧框显示该标签的作用,不进入配置。 */
472
+ function FlagRow(props) {
473
+ return h(
474
+ 'div',
475
+ { className: 'dcw-row' },
476
+ h('div', { className: 'dcw-row-label' }, TAG_LABEL[props.tag]),
477
+ h(Switch, {
478
+ label: TAG_LABEL[props.tag],
479
+ checked: props.checked,
480
+ disabled: props.disabled,
481
+ onChange: props.onChange,
482
+ }),
483
+ h('input', {
484
+ className: 'dcw-input',
485
+ type: 'text',
486
+ value: '',
487
+ placeholder: props.placeholder,
488
+ disabled: true,
489
+ readOnly: true,
490
+ tabIndex: -1,
491
+ 'aria-label': props.placeholder,
492
+ }),
456
493
  )
457
494
  }
458
495
 
459
- function Flag(props) {
496
+ /** 值由文件或语法固定的行:中间锁,右侧框给出固定值。 */
497
+ function LockRow(props) {
460
498
  return h(
461
499
  'div',
462
- { className: 'dcw-flag' },
500
+ { className: 'dcw-row dcw-row-lock' },
501
+ h('div', { className: 'dcw-row-label' }, props.label),
502
+ h('span', { className: 'dcw-lock', title: props.placeholder }, h(LockIcon)),
503
+ h('input', {
504
+ className: 'dcw-input',
505
+ type: 'text',
506
+ value: '',
507
+ placeholder: props.placeholder,
508
+ disabled: true,
509
+ readOnly: true,
510
+ tabIndex: -1,
511
+ 'aria-label': props.placeholder,
512
+ }),
513
+ )
514
+ }
515
+
516
+ /** 两种声明注释符号;按钮本身可用键盘切换。 */
517
+ function StyleRow(props) {
518
+ const options = [
519
+ { value: 'slash', label: '///' },
520
+ { value: 'block', label: '/** */' },
521
+ ]
522
+ return h(
523
+ 'div',
524
+ { className: 'dcw-row dcw-row-style' },
525
+ h('div', { className: 'dcw-row-label' }, props.label),
463
526
  h(
464
527
  'div',
465
- { className: 'dcw-row-label' },
466
- TAG_LABEL[props.tag],
467
- h(Switch, {
468
- label: TAG_LABEL[props.tag],
469
- checked: props.checked,
470
- disabled: props.disabled,
471
- onChange: props.onChange,
472
- }),
528
+ { className: 'dcw-segmented', role: 'group', 'aria-label': props.label },
529
+ options.map((option) =>
530
+ h(
531
+ 'button',
532
+ {
533
+ key: option.value,
534
+ type: 'button',
535
+ className: 'dcw-segment',
536
+ 'aria-pressed': props.value === option.value ? 'true' : 'false',
537
+ disabled: props.disabled,
538
+ onClick: () => props.onChange(option.value),
539
+ },
540
+ option.label,
541
+ ),
542
+ ),
473
543
  ),
474
- h('p', { className: 'dcw-row-hint' }, props.hint || ''),
475
544
  )
476
545
  }
477
546
 
478
547
  function Preview(props) {
479
548
  const s = props.strings
480
549
  return h(
481
- 'section',
482
- { className: 'dcw-card', 'aria-label': s.preview },
483
- h(
484
- 'div',
485
- { className: 'dcw-card-head' },
486
- h('h4', { className: 'dcw-card-title' }, s.preview),
487
- h('p', { className: 'dcw-card-hint' }, s.previewHint),
488
- ),
550
+ Section,
551
+ { title: s.preview },
489
552
  h('pre', { className: 'dcw-preview' }, previewText(props.config, SAMPLE_FILE)),
490
553
  )
491
554
  }
@@ -542,6 +605,28 @@ const ENTRY_ID = 'cpp-workflow'
542
605
  const FORM_RETRY_MS = 500
543
606
  const MAX_FORM_RETRIES = 20
544
607
 
608
+ /** 文件头可填写标签的占位文字;顺序与 HEADER_TAGS 一致。 */
609
+ const HEADER_PLACEHOLDER = {
610
+ brief: 'briefPlaceholder',
611
+ author: 'authorPlaceholder',
612
+ date: 'datePlaceholder',
613
+ copyright: 'copyrightPlaceholder',
614
+ version: 'versionPlaceholder',
615
+ }
616
+
617
+ /** 只有开关的标签按区块取占位文字。 */
618
+ const FLAG_PLACEHOLDER = {
619
+ param: 'paramPlaceholder',
620
+ returns: 'returnPlaceholder',
621
+ throws: 'throwsPlaceholder',
622
+ pre: 'prePlaceholder',
623
+ post: 'postPlaceholder',
624
+ retval: 'retvalPlaceholder',
625
+ tparam: 'tparamPlaceholder',
626
+ note: 'notePlaceholder',
627
+ see: 'seePlaceholder',
628
+ }
629
+
545
630
  function ConfigPage(props) {
546
631
  const s = t()
547
632
  ensureStyles()
@@ -635,16 +720,21 @@ function ConfigPage(props) {
635
720
  const editable = Boolean(form)
636
721
  const disabled = !ready
637
722
 
723
+ /** 一个标签一行:中间开关,右侧框给默认值或占位说明。 */
724
+ const flag = (tag, checked) =>
725
+ h(FlagRow, {
726
+ key: tag,
727
+ tag,
728
+ checked,
729
+ disabled,
730
+ placeholder: s[FLAG_PLACEHOLDER[tag]],
731
+ onChange: (value) => update({ [tag]: value }),
732
+ })
733
+
638
734
  return h(
639
735
  'div',
640
736
  { className: 'dcw-page' },
641
- h(
642
- 'header',
643
- { className: 'dcw-head' },
644
- h('p', { className: 'dcw-eyebrow' }, s.eyebrow),
645
- h('h3', { className: 'dcw-title' }, s.title),
646
- h('p', { className: 'dcw-lede' }, s.intro),
647
- ),
737
+ h('header', { className: 'dcw-head' }, h('h3', { className: 'dcw-title' }, s.heading)),
648
738
  missing
649
739
  ? h(
650
740
  'div',
@@ -656,11 +746,7 @@ function ConfigPage(props) {
656
746
  s.readOnly,
657
747
  props.hasService === false ? h('span', { className: 'dcw-note-code' }, s.noService) : null,
658
748
  ),
659
- h(
660
- 'button',
661
- { type: 'button', className: 'dcw-note-action', onClick: reload },
662
- s.reload,
663
- ),
749
+ h('button', { type: 'button', className: 'dcw-note-action', onClick: reload }, s.reload),
664
750
  )
665
751
  : null,
666
752
  editable && !ready && status !== 'missing'
@@ -672,78 +758,36 @@ function ConfigPage(props) {
672
758
  )
673
759
  : null,
674
760
  h(
675
- 'section',
676
- { className: 'dcw-card', 'aria-labelledby': 'dcw-header-title' },
677
- h(
678
- 'div',
679
- { className: 'dcw-card-head' },
680
- h('h4', { className: 'dcw-card-title', id: 'dcw-header-title' }, s.header),
681
- h('p', { className: 'dcw-card-hint' }, s.headerHint),
682
- ),
683
- h(
684
- 'div',
685
- { className: 'dcw-row dcw-row-fixed' },
686
- h('div', { className: 'dcw-row-label' }, TAG_LABEL.file),
687
- h(
688
- 'div',
689
- { className: 'dcw-row-control' },
690
- h('span', { className: 'dcw-static' }, h(LockIcon), s.fixed),
691
- h('p', { className: 'dcw-row-hint' }, s.fixedHint),
692
- ),
693
- ),
761
+ Section,
762
+ { title: s.style },
763
+ h(StyleRow, {
764
+ label: s.style,
765
+ value: draft.commentStyle,
766
+ disabled,
767
+ onChange: (value) => update({ commentStyle: value }),
768
+ }),
769
+ h(LockRow, { label: s.bodyRow, placeholder: s.bodyPlaceholder }),
770
+ ),
771
+ h(
772
+ Section,
773
+ { title: s.header },
774
+ h(LockRow, { label: TAG_LABEL.file, placeholder: s.filePlaceholder }),
694
775
  ...HEADER_TAGS.map((tag) =>
695
776
  h(ValueRow, {
696
777
  key: tag,
697
778
  tag,
698
- strings: s,
699
779
  entry: draft[tag],
700
780
  disabled,
781
+ placeholder: s[HEADER_PLACEHOLDER[tag]],
701
782
  onChange: (entry) => update({ [tag]: entry }),
702
783
  }),
703
784
  ),
704
785
  ),
786
+ h(Section, { title: s.type }, ...TYPE_TAGS.map((tag) => flag(tag, draft[tag]))),
705
787
  h(
706
- 'section',
707
- { className: 'dcw-card', 'aria-labelledby': 'dcw-contract-title' },
708
- h(
709
- 'div',
710
- { className: 'dcw-card-head' },
711
- h('h4', { className: 'dcw-card-title', id: 'dcw-contract-title' }, s.contract),
712
- h('p', { className: 'dcw-card-hint' }, s.contractHint),
713
- ),
714
- h(
715
- 'div',
716
- { className: 'dcw-flags' },
717
- ...CONTRACT_TAGS.map((tag) =>
718
- h(Flag, {
719
- key: tag,
720
- tag,
721
- checked: draft[tag],
722
- disabled,
723
- hint: s[HINT_KEY[tag]],
724
- onChange: (value) => update({ [tag]: value }),
725
- }),
726
- ),
727
- ),
728
- ),
729
- h(
730
- 'details',
731
- { className: 'dcw-card' },
732
- h('summary', null, h('span', { className: 'dcw-card-title' }, s.extra), h(Chevron)),
733
- h('p', { className: 'dcw-card-hint', style: { margin: '0 14px 2px' } }, s.extraHint),
734
- h(
735
- 'div',
736
- { className: 'dcw-flags' },
737
- ...EXTRA_TAGS.map((tag) =>
738
- h(Flag, {
739
- key: tag,
740
- tag,
741
- checked: draft[tag],
742
- disabled,
743
- onChange: (value) => update({ [tag]: value }),
744
- }),
745
- ),
746
- ),
788
+ Section,
789
+ { title: s.declaration },
790
+ ...[...CONTRACT_TAGS, ...FUNCTION_EXTRA_TAGS].map((tag) => flag(tag, draft[tag])),
747
791
  ),
748
792
  h(Preview, { config: draft, strings: s }),
749
793
  editable