nx-kv 0.33.0 → 0.35.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (125) hide show
  1. package/CHANGELOG.md +104 -0
  2. package/package.json +1 -1
  3. package/src/core/db/migrations/index.js +2 -0
  4. package/src/core/db/migrations/v3.sql +20 -0
  5. package/src/core/db/version.js +4 -1
  6. package/src/modules/localtask/repo/rows.js +2 -0
  7. package/src/modules/localtask/repo/tasks.js +4 -2
  8. package/src/modules/localtask/task-lifecycle.js +21 -8
  9. package/src/modules/localtask/task-ops.js +9 -0
  10. package/src/modules/localtask/task-view.js +6 -0
  11. package/src/modules/templates/index.js +65 -9
  12. package/src/modules/templates/repo/templates.js +24 -2
  13. package/src/modules/templates/scope.js +107 -0
  14. package/src/modules/templates/service.js +83 -4
  15. package/src/runtime/spec.js +6 -1
  16. package/src/shared/feedback-text.js +118 -0
  17. package/src/web/frontend/App.jsx +34 -2
  18. package/src/web/frontend/components/button/index.jsx +34 -7
  19. package/src/web/frontend/components/button/style.css +1 -1
  20. package/src/web/frontend/components/doc/doc-head.jsx +164 -48
  21. package/src/web/frontend/components/layout/crumbs.js +4 -1
  22. package/src/web/frontend/components/md/ack-rail.jsx +14 -4
  23. package/src/web/frontend/components/md/attach-area.jsx +20 -11
  24. package/src/web/frontend/components/md/attach-modal.jsx +3 -2
  25. package/src/web/frontend/components/md/attach-picker.jsx +37 -7
  26. package/src/web/frontend/components/md/md-panes.jsx +109 -23
  27. package/src/web/frontend/components/md/sel-menu.jsx +11 -0
  28. package/src/web/frontend/components/md/tool-bar.jsx +151 -94
  29. package/src/web/frontend/components/repos/get-loop-modal.jsx +181 -0
  30. package/src/web/frontend/components/sidebar/task-children.jsx +6 -20
  31. package/src/web/frontend/components/status-tag/index.jsx +30 -0
  32. package/src/web/frontend/components/status-tag/model.js +53 -0
  33. package/src/web/frontend/components/tool-acts/bar.jsx +156 -0
  34. package/src/web/frontend/components/tool-acts/dnd.js +59 -0
  35. package/src/web/frontend/components/tool-acts/layout-panel.jsx +289 -0
  36. package/src/web/frontend/components/tool-acts/modules.js +187 -0
  37. package/src/web/frontend/components/tool-acts/style.css +108 -0
  38. package/src/web/frontend/components/tool-acts/use-layout.js +27 -0
  39. package/src/web/frontend/modules/board/ack-nodes.js +49 -1
  40. package/src/web/frontend/modules/board/reopen-text.js +32 -19
  41. package/src/web/frontend/modules/md/attach-mention.js +11 -0
  42. package/src/web/frontend/modules/md/md-edit-ops.js +10 -7
  43. package/src/web/frontend/modules/md/md-parse.js +49 -24
  44. package/src/web/frontend/modules/md/progress-search.js +96 -0
  45. package/src/web/frontend/modules/md/style.css +81 -27
  46. package/src/web/frontend/modules/md/use-templates.js +65 -2
  47. package/src/web/frontend/page/dag/index.jsx +104 -17
  48. package/src/web/frontend/page/dir/index.jsx +51 -38
  49. package/src/web/frontend/page/dir/landing.jsx +53 -71
  50. package/src/web/frontend/page/dir/task.jsx +85 -13
  51. package/src/web/frontend/page/group/index.jsx +194 -88
  52. package/src/web/frontend/page/overview/index.jsx +168 -269
  53. package/src/web/frontend/page/progress/index.jsx +59 -9
  54. package/src/web/frontend/page/repos/index.jsx +166 -109
  55. package/src/web/frontend/page/settings/index.jsx +9 -371
  56. package/src/web/frontend/page/settings/style.css +63 -178
  57. package/src/web/frontend/page/settings/task-templates-section.jsx +94 -99
  58. package/src/web/frontend/page/templates/index.jsx +221 -203
  59. package/src/web/frontend/page/templates/scope-chips.jsx +211 -0
  60. package/src/web/frontend/panels.jsx +28 -4
  61. package/src/web/frontend/route-map.js +42 -2
  62. package/src/web/frontend/style-v2.css +98 -77
  63. package/src/web/frontend/style.css +127 -319
  64. package/src/web/frontend/workspace/areas.js +1 -1
  65. package/src/web/public/assets/Introduction-DO6_gTk-.js +1 -0
  66. package/src/web/public/assets/bar-DoiwB4eA.js +1 -0
  67. package/src/web/public/assets/board-view-t8CKtq17.js +1 -0
  68. package/src/web/public/assets/button-DA4lNJeC.css +1 -0
  69. package/src/web/public/assets/button-M9TUn-AR.js +1 -0
  70. package/src/web/public/assets/cloud-DSu1a2Dn.js +3 -0
  71. package/src/web/public/assets/{composer-launch-CfVAwzTt.js → composer-launch-D-b7HKk5.js} +1 -1
  72. package/src/web/public/assets/composer-panel-CJuaj0Jp.js +1 -0
  73. package/src/web/public/assets/dag-_5FWJlq5.js +1 -0
  74. package/src/web/public/assets/dir-GUpDi0kq.js +5 -0
  75. package/src/web/public/assets/group-BzC_R2k-.js +1 -0
  76. package/src/web/public/assets/index-B_HPAoNR.js +30 -0
  77. package/src/web/public/assets/index-CZBR0CbL.css +1 -0
  78. package/src/web/public/assets/md-history-Uo6U7hYS.js +1 -0
  79. package/src/web/public/assets/md-panes-BvQXV_C9.js +28 -0
  80. package/src/web/public/assets/md-parse-C2bDc3IZ.js +25 -0
  81. package/src/web/public/assets/member-picker--32VkTmv.js +1 -0
  82. package/src/web/public/assets/overview-sLaedHVZ.js +1 -0
  83. package/src/web/public/assets/progress-DOI2YFEi.js +3 -0
  84. package/src/web/public/assets/refs-D97SxNRW.js +1 -0
  85. package/src/web/public/assets/reopen-text-BylkngqC.js +12 -0
  86. package/src/web/public/assets/repos-ZPiaK93i.css +1 -0
  87. package/src/web/public/assets/repos-fp0D_GDq.js +10 -0
  88. package/src/web/public/assets/route-crumb-C5LPu1Qx.js +1 -0
  89. package/src/web/public/assets/settings-BBKNCMHm.css +1 -0
  90. package/src/web/public/assets/settings-D13mfwe0.js +6 -0
  91. package/src/web/public/assets/status-tag-D4wxIj1q.js +1 -0
  92. package/src/web/public/assets/task-Cu-rh5jA.js +11 -0
  93. package/src/web/public/assets/task-status-BP6y8MVu.js +1 -0
  94. package/src/web/public/assets/templates-xbR-qZMs.js +1 -0
  95. package/src/web/public/assets/tool-bar-1h2zairf.css +1 -0
  96. package/src/web/public/assets/tool-bar-CHoZSF6T.js +1 -0
  97. package/src/web/public/assets/upload-L1g-pfvZ.js +1 -0
  98. package/src/web/public/index.html +6 -5
  99. package/src/web/public/assets/Introduction-C5sQqMIg.js +0 -1
  100. package/src/web/public/assets/attach-evLB-_o-.js +0 -1
  101. package/src/web/public/assets/cloud-B_LvtXsR.js +0 -3
  102. package/src/web/public/assets/composer-panel-DIbBPnrY.js +0 -1
  103. package/src/web/public/assets/dag-B9ujKuhg.js +0 -1
  104. package/src/web/public/assets/dir-us1qOb74.js +0 -5
  105. package/src/web/public/assets/group-BV9RUHL2.js +0 -1
  106. package/src/web/public/assets/index-B3bvje4X.css +0 -1
  107. package/src/web/public/assets/index-Dw5qvd3H.js +0 -54
  108. package/src/web/public/assets/md-edit-ops-ZwnwtEax.js +0 -22
  109. package/src/web/public/assets/md-history-DXAULvOG.js +0 -1
  110. package/src/web/public/assets/md-panes-XVBqxolq.js +0 -7
  111. package/src/web/public/assets/member-picker-caRH-T0U.js +0 -1
  112. package/src/web/public/assets/overview-BuK893nH.js +0 -1
  113. package/src/web/public/assets/progress-CXDMbg9t.js +0 -3
  114. package/src/web/public/assets/refs-CRV9oVjk.js +0 -1
  115. package/src/web/public/assets/reopen-text-DIFfS71D.js +0 -6
  116. package/src/web/public/assets/repos-B4Kzl-pe.js +0 -9
  117. package/src/web/public/assets/route-crumb-BBKKZ3aI.js +0 -1
  118. package/src/web/public/assets/settings-BaiD0fFN.js +0 -7
  119. package/src/web/public/assets/settings-qCi-niJC.css +0 -1
  120. package/src/web/public/assets/task-CLl1Jg0v.js +0 -7
  121. package/src/web/public/assets/task-status-Bgo2Nfiw.js +0 -1
  122. package/src/web/public/assets/template-editor-D_rc4c19.js +0 -1
  123. package/src/web/public/assets/templates-G3voUFjL.js +0 -2
  124. package/src/web/public/assets/upload-DV28XAi0.js +0 -1
  125. /package/src/web/public/assets/{attach-BZrdOH46.css → task-status-BZrdOH46.css} +0 -0
@@ -24,12 +24,15 @@
24
24
  // — → category 固定 'newtask'(本文件只管新建页骨架;
25
25
  // delivery/enhance/context 三个 tab 的内置模板由
26
26
  // seed 提供,编辑走同一张表)
27
+ // — → scope(v3,#128):可见域 JSON 数组,缺省 ["*"];
28
+ // origin_topic 记创建主题。判定规则在 scope.js(纯函数)
27
29
  import crypto from 'node:crypto';
28
30
  import fsp from 'node:fs/promises'; // 仅用于读用户 --body-file(存储已进库)
29
31
  import { readFileSync } from 'node:fs';
30
32
  import { badInput, notFound } from '../../core/errors.js';
31
33
  import { nowMs } from '../../core/db/time.js';
32
34
  import { NEWTASK_BODY, NEWTASK_VARS } from '../../core/db/seed-templates.js';
35
+ import { normalizeScope, topicCtx, canUse, canEdit } from './scope.js';
33
36
  import repoLayer from './repo/index.js';
34
37
 
35
38
  export const BUILTIN_ID = 'default';
@@ -51,6 +54,10 @@ function rowToView(row) {
51
54
  body: String(row.body || ''),
52
55
  values: vars,
53
56
  builtin: !!row.builtin,
57
+ // 可见域(v3,#128):scope 数组 + 创建来源主题。全为 '*' / '' 时消费方
58
+ // 可以当它不存在(与 v2 行为一致),带值的才需要展示/判定。
59
+ scope: normalizeScope(row.scope),
60
+ originTopic: String(row.origin_topic || ''),
54
61
  };
55
62
  if (row.category && row.category !== NEWTASK_CATEGORY) out.category = String(row.category);
56
63
  if (row.enabled === 0) out.enabled = false;
@@ -83,6 +90,54 @@ export async function listTemplates() {
83
90
  });
84
91
  }
85
92
 
93
+ /**
94
+ * 按可见上下文列可用模板(v3,#128 / #132):
95
+ * GET /api/templates?topic=&group=&repo=
96
+ *
97
+ * 三把钥匙平级(#132):topic / repo / group 与 `*` 都是 scope 绑定条目,
98
+ * 不是「全局 vs 定向」。组页可只传 group(项目组本身就是一个可见主体)。
99
+ *
100
+ * 返回 `scoped: true` 让前端识别「服务端确实按域过滤了」——旧 serve 不认识
101
+ * 这些参数时无 scoped 字段,前端退化回全量菜单。
102
+ */
103
+ export async function listTemplatesForTopic({
104
+ topic: rawTopic,
105
+ group: rawGroup,
106
+ repo: rawRepo,
107
+ } = {}) {
108
+ const key = String(rawTopic || '').trim();
109
+ const groupKey = String(rawGroup || '').trim();
110
+ const repoKey = String(rawRepo || '').trim();
111
+ if (!key && !groupKey && !repoKey) return { ...(await listTemplates()), scoped: false };
112
+ return repo.txw((conn) => {
113
+ const row = key ? repo.templates.getTopicKeys(key, conn) : null;
114
+ const ctx = topicCtx({
115
+ key: (row && row.key) || key,
116
+ // 显式 query 优先:组页会带 group/repo,即使成员队列行上 group_key 为空
117
+ repoKey: repoKey || (row && row.repo_key) || '',
118
+ groupKey: groupKey || (row && row.group_key) || '',
119
+ });
120
+ const defaultId = defaultIdOf(conn);
121
+ const templates = repo.templates
122
+ .listRows(conn)
123
+ .filter((r) => r.category === NEWTASK_CATEGORY)
124
+ .map((r) => {
125
+ const v = rowToView(r);
126
+ v.perm = { use: canUse(v, ctx), edit: canEdit(v, ctx) };
127
+ return v;
128
+ })
129
+ .filter((v) => v.perm.use);
130
+ return {
131
+ defaultId,
132
+ templates,
133
+ scoped: true,
134
+ topic: key || undefined,
135
+ group: groupKey || undefined,
136
+ repo: repoKey || undefined,
137
+ };
138
+ });
139
+ }
140
+
86
141
  function normalizeName(raw) {
87
142
  const name = String(raw || '').trim();
88
143
  if (!name) throw badInput('需要模板名 <name>');
@@ -140,10 +195,30 @@ async function resolveBody({ body, bodyFile } = {}) {
140
195
  }
141
196
  }
142
197
 
143
- /** 新增模板(--set-default 同时设为默认)。幂等性不做:同名允许存在,靠 id 区分。 */
144
- export async function addTemplate({ name: rawName, body: rawBody, bodyFile, values, setDefault = false } = {}) {
198
+ /**
199
+ * 新增模板(--set-default 同时设为默认)。幂等性不做:同名允许存在,靠 id 区分。
200
+ *
201
+ * 可见域(v3,#128 / #131):显式 scope 优先;否则带创建主题 topic 时默认只在
202
+ * 该主题可见(scope=[topic:<key>],origin_topic 记锚);都没有 = 空数组(未配置),
203
+ * **不再默认全局**——全局必须显式 `--scope *` / UI 勾选。内置模板仍是 `["*"]`。
204
+ */
205
+ export async function addTemplate({
206
+ name: rawName,
207
+ body: rawBody,
208
+ bodyFile,
209
+ values,
210
+ setDefault = false,
211
+ scope: rawScope,
212
+ topic: rawTopic,
213
+ } = {}) {
145
214
  const name = normalizeName(rawName);
146
215
  const body = normalizeBody(await resolveBody({ body: rawBody, bodyFile }));
216
+ const topicKey = String(rawTopic || '').trim();
217
+ const scope = rawScope !== undefined
218
+ ? normalizeScope(rawScope, { strict: true })
219
+ : topicKey
220
+ ? [`topic:${topicKey}`]
221
+ : [];
147
222
  const at = nowMs();
148
223
  return repo.txw((conn) => {
149
224
  const t = {
@@ -163,6 +238,9 @@ export async function addTemplate({ name: rawName, body: rawBody, bodyFile, valu
163
238
  isDefault: 0,
164
239
  sortOrder: repo.templates.nextSortOrder(conn, NEWTASK_CATEGORY),
165
240
  builtin: 0,
241
+ scope,
242
+ // 创建来源是事实,不随 scope 策略走:显式给了 topic 才记
243
+ originTopic: topicKey,
166
244
  createdAtMs: at,
167
245
  updatedAtMs: at,
168
246
  });
@@ -199,8 +277,8 @@ export async function removeTemplate({ id } = {}) {
199
277
  });
200
278
  }
201
279
 
202
- /** 编辑模板(改名 / 改正文 / 改槽位;只改传入的字段)。 */
203
- export async function updateTemplate({ id, name: rawName, body: rawBody, bodyFile, values } = {}) {
280
+ /** 编辑模板(改名 / 改正文 / 改槽位 / 改可见域;只改传入的字段)。 */
281
+ export async function updateTemplate({ id, name: rawName, body: rawBody, bodyFile, values, scope: rawScope } = {}) {
204
282
  const want = String(id || '').trim();
205
283
  if (!want) throw badInput('需要模板 id');
206
284
  const bodyIn = rawBody !== undefined || bodyFile ? await resolveBody({ body: rawBody, bodyFile }) : undefined;
@@ -210,6 +288,7 @@ export async function updateTemplate({ id, name: rawName, body: rawBody, bodyFil
210
288
  const patch = {};
211
289
  if (rawName !== undefined) patch.name = normalizeName(rawName);
212
290
  if (bodyIn !== undefined) patch.body = normalizeBody(bodyIn);
291
+ if (rawScope !== undefined) patch.scope = normalizeScope(rawScope, { strict: true });
213
292
  if (values !== undefined) {
214
293
  // 内置模板:槽位未给的项回落出厂默认(渲染时的兜底语义与 JSON 时代一致)
215
294
  patch.vars = normalizeValues(values, row.builtin ? BUILTIN_VALUES : rowToView(row).values);
@@ -5,7 +5,7 @@
5
5
  // 迟早分叉。现在 depth 只在 action 声明里写一次 `{ type: 'number', default: 3 }`。
6
6
  import { badInput } from '../core/errors.js';
7
7
 
8
- const TYPES = new Set(['string', 'number', 'boolean', 'array']);
8
+ const TYPES = new Set(['string', 'number', 'boolean', 'array', 'raw']);
9
9
 
10
10
  // 取 action 的 CLI 路径列表。支持两种写法:
11
11
  // 单路径 cli: ['repo', 'list']
@@ -72,6 +72,11 @@ function coerceOne(name, spec, raw) {
72
72
  if (Array.isArray(raw)) return raw.map((x) => String(x).trim()).filter(Boolean);
73
73
  return String(raw).split(',').map((x) => x.trim()).filter(Boolean);
74
74
  }
75
+ // raw = 原样透传,不做字符串化。给「值本身是数组/对象」的 flag 用
76
+ // (模板可见域 scope 就是这种:JSON 数组串、逗号短写、HTTP 直接发数组,
77
+ // 三种形态都要活着走到 action 里)。走 string 会被 String([]) 压成 ''
78
+ // ——「清空可见域」就变成了「不传」,静默吞掉一次写入。
79
+ if (type === 'raw') return raw;
75
80
  return String(raw);
76
81
  }
77
82
 
@@ -55,3 +55,121 @@ export function appendFeedback({ base, heading, quote, feedback, bold = false }
55
55
  if (!b && !sec) return '';
56
56
  return `${b ? `${b}\n\n` : ''}${sec}\n`;
57
57
  }
58
+
59
+ // ─── 轮次 callout(#144 反馈功能优化)────────────────────────────────
60
+ //
61
+ // 旧段名「## 上一轮完成总结」在多轮正文里说不清是**哪**一轮(每对段都叫上一轮);
62
+ // 改成带轮次号的 callout 块(#144:层级一眼看清):
63
+ //
64
+ // > [!NOTE] 第 1 轮 · 完成总结
65
+ // > ack 内容……
66
+ //
67
+ // > [!WARNING] 第 1 轮 · 验收反馈
68
+ // > **反馈内容……**
69
+ //
70
+ // 面板 md 渲染器(modules/md/md-parse.js)认 `[!TYPE]` 标记渲染成醒目色块;
71
+ // 纯文本(CLI / agent 读正文)也自然可读。旧段名的历史正文仍被 ack-nodes /
72
+ // 渲染器认得——只增不改,老任务页不受影响。
73
+
74
+ /** 完成总结 callout 类型 */
75
+ export const ACK_CALLOUT_TYPE = 'NOTE';
76
+ /** 验收反馈 callout 类型 */
77
+ export const FEEDBACK_CALLOUT_TYPE = 'WARNING';
78
+
79
+ const ACK_TITLE_RE = /完成总结/;
80
+ const ROUND_NUM_RE = /第\s*(\d+)\s*轮/;
81
+ const CALLOUT_TITLE_RE = /^>\s*\[![A-Za-z][\w-]*\][ \t]*(.*)$/;
82
+
83
+ /** ack callout 标题:`第 N 轮 · 完成总结` */
84
+ export function ackCalloutTitle(round) {
85
+ return `第 ${Number(round) || 1} 轮 · 完成总结`;
86
+ }
87
+
88
+ /** 反馈 callout 标题:`第 N 轮 · 验收反馈` */
89
+ export function feedbackCalloutTitle(round) {
90
+ return `第 ${Number(round) || 1} 轮 · 验收反馈`;
91
+ }
92
+
93
+ /** 多行内容 → callout 逐行(`> ` 前缀;空行给裸 `>` 保持块连续) */
94
+ function calloutBody(text) {
95
+ return String(text ?? '')
96
+ .split('\n')
97
+ .map((l) => (l.trim() ? `> ${l}` : '>'))
98
+ .join('\n');
99
+ }
100
+
101
+ /** 完成总结 callout 块;ack 空 → 空串 */
102
+ export function ackCalloutSection({ round, ack } = {}) {
103
+ const a = String(ack ?? '').trim();
104
+ if (!a) return '';
105
+ return `> [!${ACK_CALLOUT_TYPE}] ${ackCalloutTitle(round)}\n${calloutBody(a)}`;
106
+ }
107
+
108
+ /** 验收反馈 callout 块(锚定引用并进同一块);反馈空 → 空串 */
109
+ export function feedbackCalloutSection({ round, quote, feedback, bold = false } = {}) {
110
+ const fb = String(feedback ?? '').trim();
111
+ if (!fb) return '';
112
+ const body = bold ? boldFeedback(fb) : fb;
113
+ const anchor = quoteBlock(quote);
114
+ const inner = anchor ? `${anchor.replace(/^> ?/gm, '')}\n\n${body}` : body;
115
+ return `> [!${FEEDBACK_CALLOUT_TYPE}] ${feedbackCalloutTitle(round)}\n${calloutBody(inner)}`;
116
+ }
117
+
118
+ /** 正文里已有多少轮 ack:旧段名各算一轮;callout 标题带轮次号时取最大号(防手工删段后编号回退) */
119
+ export function countAckRounds(base) {
120
+ const text = String(base ?? '');
121
+ let n = 0;
122
+ let max = 0;
123
+ const legacy = text.match(/^## 上一轮完成总结\s*$/gm);
124
+ n += legacy ? legacy.length : 0;
125
+ for (const m of text.matchAll(/^>\s*\[![A-Za-z][\w-]*\][ \t]*(.*)$/gm)) {
126
+ const title = String(m[1] ?? '');
127
+ if (!ACK_TITLE_RE.test(title)) continue;
128
+ n += 1;
129
+ const r = title.match(ROUND_NUM_RE);
130
+ if (r) max = Math.max(max, Number(r[1]));
131
+ }
132
+ return Math.max(n, max);
133
+ }
134
+
135
+ /** 下一轮的轮次号:已有轮数 + 1 */
136
+ export function nextRoundOf(base) {
137
+ return countAckRounds(base) + 1;
138
+ }
139
+
140
+ /** 正文里是否已有同一份 ack 总结(旧段名与 callout 两种形态都认)——防连点两次重复追加 */
141
+ export function bodyHasAck(base, ack) {
142
+ const b = String(base ?? '');
143
+ const a = String(ack ?? '').trim();
144
+ if (!a || !b) return false;
145
+ if (b.includes(`${ACK_SUMMARY_HEADING}\n\n${a}`)) return true;
146
+ const lines = b.split('\n');
147
+ for (let i = 0; i < lines.length; i++) {
148
+ const m = lines[i].match(CALLOUT_TITLE_RE);
149
+ if (!m || !ACK_TITLE_RE.test(String(m[1] ?? ''))) continue;
150
+ const body = [];
151
+ for (let j = i + 1; j < lines.length && lines[j].startsWith('>'); j++) {
152
+ body.push(lines[j].replace(/^>[ \t]?/, ''));
153
+ }
154
+ if (body.join('\n').trim() === a) return true;
155
+ }
156
+ return false;
157
+ }
158
+
159
+ /**
160
+ * ack 场景的整段追加(#144 的拼装口径):base + 本轮完成总结 callout + 验收反馈 callout。
161
+ * ack 已在正文里(bodyHasAck)不重复追加;轮次号缺省按正文已有轮数 + 1。
162
+ * base 与 ack、反馈全空 → 空串;只有 base → base 原样(规整尾换行)。
163
+ */
164
+ export function appendAckFeedback({ base, ack, quote, feedback, bold = true, round } = {}) {
165
+ const b = String(base ?? '').trimEnd();
166
+ const r = Number(round) || nextRoundOf(b);
167
+ const parts = [];
168
+ if (b) parts.push(b);
169
+ const a = String(ack ?? '').trim();
170
+ if (a && !bodyHasAck(b, a)) parts.push(ackCalloutSection({ round: r, ack: a }));
171
+ const sec = feedbackCalloutSection({ round: r, quote, feedback, bold });
172
+ if (sec) parts.push(sec);
173
+ if (!parts.length) return '';
174
+ return `${parts.join('\n\n')}\n`;
175
+ }
@@ -81,7 +81,35 @@ function routeFromHash() {
81
81
  boardName: name,
82
82
  };
83
83
  }
84
- const KNOWN = ['global', 'overview', 'cloud', 'todo', 'repos', 'templates'];
84
+ // 任务模板编辑(#137):#/templates/new[?scope=&topic=] / #/templates/edit/<id>
85
+ // 必须带 mode,否则会与空 config 的「目录页」互相冲掉全屏编辑器。
86
+ if (path === 'templates' || path.startsWith('templates/')) {
87
+ const rest = path === 'templates' ? '' : path.slice('templates/'.length);
88
+ if (rest.startsWith('edit/')) {
89
+ return {
90
+ view: 'templates',
91
+ key: '',
92
+ task: '',
93
+ mode: 'edit',
94
+ id: decodeURIComponent(rest.slice(5)),
95
+ topic: '',
96
+ scope: '',
97
+ };
98
+ }
99
+ if (rest === 'new') {
100
+ return {
101
+ view: 'templates',
102
+ key: '',
103
+ task: '',
104
+ mode: 'new',
105
+ id: '',
106
+ topic: qs.get('topic') || '',
107
+ scope: qs.get('scope') || '',
108
+ };
109
+ }
110
+ return { view: 'templates', key: '', task: '', mode: '', id: '', topic: '', scope: '' };
111
+ }
112
+ const KNOWN = ['global', 'overview', 'cloud', 'todo', 'repos'];
85
113
  if (KNOWN.includes(path)) {
86
114
  // 全局池的页:#/global?task=1 —— 全局池的子任务表与页都在同一路由下
87
115
  return { view: path === 'todo' ? 'cloud' : path, key: path === 'global' ? '__GLOBAL__' : '', task: path === 'global' ? task : '' };
@@ -340,7 +368,7 @@ export default function App() {
340
368
  if (!m) return;
341
369
  const spec = panelSpecOfRoute(route, specCtxRef.current);
342
370
  if (!spec) return;
343
- const routeSig = `${route.view}|${route.key}|${route.task}|${route.repoKey || ''}|${route.boardKey || ''}`;
371
+ const routeSig = `${route.view}|${route.key}|${route.task}|${route.repoKey || ''}|${route.boardKey || ''}|${route.mode || ''}|${route.id || ''}|${route.topic || ''}|${route.scope || ''}`;
344
372
  const prev = openedRef.current;
345
373
  if (prev.route === routeSig && prev.key === specCtxKey) return;
346
374
  openedRef.current = { route: routeSig, key: specCtxKey };
@@ -401,6 +429,10 @@ export default function App() {
401
429
  && prev.repoKey === next.repoKey
402
430
  && prev.boardKey === next.boardKey
403
431
  && prev.boardName === next.boardName
432
+ && prev.mode === next.mode
433
+ && prev.id === next.id
434
+ && prev.topic === next.topic
435
+ && prev.scope === next.scope
404
436
  ? prev
405
437
  : next
406
438
  ));
@@ -6,13 +6,13 @@
6
6
  // primary 主按钮:实色块。**一个页面只能出现一个**——由使用约定保证,
7
7
  // 页面里第二颗想强调的按钮请降级 secondary。
8
8
  // secondary 次级按钮:浅底(.btn.ghost),表格行、工具栏里的默认形态。
9
- // DropdownButton 下拉按钮:文字右侧带向下箭头,hover 展开菜单。
9
+ // DropdownButton 下拉按钮:文字右侧带向下箭头,点击展开菜单(#138)。
10
10
  //
11
11
  // 现状(迁移口径):全库还有 ~30 个文件用裸 `<button className="btn ...">`,
12
12
  // 一次性替换 300+ 处风险过大;设置页(任务点名的重灾区)已换成本组件,
13
13
  // 其余页面靠 CSS 统一尺寸,后续按页面渐进迁移。图标按钮(.iconbtn 26×26)、
14
14
  // 开关(.toggle)不属于这三分类,不走本组件。
15
- import { useState } from 'react';
15
+ import { useEffect, useRef, useState } from 'react';
16
16
  import './style.css';
17
17
 
18
18
  const VARIANT_CLASS = { primary: '', secondary: 'ghost' };
@@ -48,8 +48,8 @@ export function Button({
48
48
  }
49
49
 
50
50
  /**
51
- * 下拉按钮:文字 + 右侧向下箭头,hover 展开菜单(纯 CSS :hover,无 portal)。
52
- * 菜单贴按钮右缘展开;空间不足的场景由调用方用 dropUp 翻转。
51
+ * 下拉按钮:文字 + 右侧向下箭头,**点击**展开菜单(#138:不要 hover)。
52
+ * 菜单贴按钮左缘;点菜单项 / 点外侧 / Esc 关闭。
53
53
  *
54
54
  * @param {object} props
55
55
  * @param {string} props.label 按钮文字
@@ -59,13 +59,40 @@ export function Button({
59
59
  */
60
60
  export function DropdownButton({ label, items = [], onSelect, variant = 'secondary', className = '', ...rest }) {
61
61
  const [open, setOpen] = useState(false);
62
+ const rootRef = useRef(null);
63
+
64
+ useEffect(() => {
65
+ if (!open) return undefined;
66
+ const onDoc = (e) => {
67
+ if (rootRef.current && !rootRef.current.contains(e.target)) setOpen(false);
68
+ };
69
+ const onKey = (e) => {
70
+ if (e.key === 'Escape') setOpen(false);
71
+ };
72
+ document.addEventListener('mousedown', onDoc);
73
+ document.addEventListener('keydown', onKey);
74
+ return () => {
75
+ document.removeEventListener('mousedown', onDoc);
76
+ document.removeEventListener('keydown', onKey);
77
+ };
78
+ }, [open]);
79
+
62
80
  return (
63
81
  <span
82
+ ref={rootRef}
64
83
  className={'nx-btn-dd' + (open ? ' open' : '') + (className ? ' ' + className : '')}
65
- onMouseEnter={() => setOpen(true)}
66
- onMouseLeave={() => setOpen(false)}
67
84
  >
68
- <Button variant={variant} className="nx-btn-dd-main" aria-haspopup="menu" aria-expanded={open} {...rest}>
85
+ <Button
86
+ variant={variant}
87
+ className="nx-btn-dd-main"
88
+ aria-haspopup="menu"
89
+ aria-expanded={open}
90
+ {...rest}
91
+ onClick={(e) => {
92
+ rest.onClick && rest.onClick(e);
93
+ setOpen((v) => !v);
94
+ }}
95
+ >
69
96
  {label}
70
97
  <span className="nx-btn-dd-arrow" aria-hidden="true">▾</span>
71
98
  </Button>
@@ -2,7 +2,7 @@
2
2
 
3
3
  .nx-btn-dd { position: relative; display: inline-flex; }
4
4
 
5
- /* 箭头:文字右侧,随 hover 态轻微下沉示意展开 */
5
+ /* 箭头:文字右侧;打开态轻微下沉示意展开(#138:点击开关,非 hover) */
6
6
  .nx-btn-dd-arrow { font-size: 10px; line-height: 1; transform: translateY(0); transition: transform .12s ease; }
7
7
  .nx-btn-dd.open .nx-btn-dd-arrow { transform: translateY(1px); }
8
8
 
@@ -3,10 +3,23 @@
3
3
  // 布局与任务页一致:`[面包屑] [标题·路径]` 一行、`[更多 · 保存]` 右对齐,
4
4
  // 下面是编辑器本体。
5
5
  //
6
- // 「更多」按 编辑 / 文档 / 查看 三层分组(沿用任务页 ToolBar 口径):
7
- // · 查看 → 文字列表:与「进程」同一个右侧边栏位,列本项目/项目组的全部文章
8
- // (refs 面板;doc 在 center、refs 在 right,互不顶替,编辑器不会被挤走)
6
+ // 「更多」按 编辑 / 文档 / 查看 三层分组(沿用任务页 ToolBar 口径);
7
+ // #143:与 task/group/dir 同套 tool-acts 编排(顺序/显隐)。
8
+ import { useState } from 'react';
9
+ import { createPortal } from 'react-dom';
9
10
  import { MenuPortal, openMenuAt, useMenu } from '../md/tool-bar.jsx';
11
+ import { inMoreOf, metaOf, onBarOf } from '../tool-acts/modules.js';
12
+ import { useToolActsLayout } from '../tool-acts/use-layout.js';
13
+ import ToolActsLayoutPanel from '../tool-acts/layout-panel.jsx';
14
+ import '../tool-acts/style.css';
15
+
16
+ const KIND = 'doc';
17
+
18
+ const MENU_GROUPS = [
19
+ { id: 'edit', label: '编辑' },
20
+ { id: 'doc', label: '文档' },
21
+ { id: 'view', label: '查看' },
22
+ ];
10
23
 
11
24
  /**
12
25
  * @param {object} p
@@ -16,7 +29,7 @@ import { MenuPortal, openMenuAt, useMenu } from '../md/tool-bar.jsx';
16
29
  * @param {boolean} p.dirty 未保存
17
30
  * @param {boolean} p.writable 可写(false 时不给「保存」与编辑类菜单)
18
31
  * @param {() => void} p.onSave
19
- * @param {Array<{label: string, items: Array}>} p.menuGroups 额外菜单分组
32
+ * @param {Array<{label: string, items: Array}>} p.menuGroups 额外菜单分组(按 id 并入编排)
20
33
  * @param {boolean} [p.saving]
21
34
  * @param {boolean} [p.external] 外部文档(页头给「外部 · 可写回」提示)
22
35
  * @param {React.ReactNode} [p.afterTitle] 标题行里追加的控件(模式切换等)
@@ -35,8 +48,93 @@ export default function DocHead({
35
48
  afterTitle = null,
36
49
  }) {
37
50
  const more = useMenu();
51
+ const { layout, setLayout } = useToolActsLayout(KIND);
52
+ const [panelOpen, setPanelOpen] = useState(false);
53
+
54
+ // 把调用方 menuGroups 摊成 id → spec(动态 label/hint/run)
55
+ const specs = {};
56
+ for (const g of menuGroups || []) {
57
+ for (const a of g?.items || []) {
58
+ if (!a || !a.id) continue;
59
+ specs[a.id] = a;
60
+ }
61
+ }
62
+ specs.save = onSave && {
63
+ id: 'save',
64
+ label: saving ? '保存中…' : onSaveLabel,
65
+ run: onSave,
66
+ primary: true,
67
+ disabled: saving || !dirty,
68
+ };
69
+
70
+ const available = (id) => id === 'more' || !!specs[id];
38
71
 
39
- const groups = menuGroups.filter((g) => g && g.items && g.items.length);
72
+ const barItems = layout.filter((x) => onBarOf(KIND, x) && available(x.id));
73
+ const moreItems = layout.filter((x) => inMoreOf(KIND, x) && available(x.id));
74
+
75
+ const runItem = (id) => {
76
+ specs[id]?.run?.();
77
+ more.setOpen(false);
78
+ };
79
+
80
+ const renderBarBtn = (id) => {
81
+ if (id === 'more') {
82
+ return (
83
+ <div className="docp-more" ref={more.ref} key="more">
84
+ <button
85
+ type="button"
86
+ className={`btn ghost sm${more.open ? ' on' : ''}`}
87
+ title="更多操作"
88
+ aria-haspopup="menu"
89
+ aria-expanded={more.open}
90
+ onClick={(e) => openMenuAt(more, e, 'right')}
91
+ >
92
+ 更多
93
+ </button>
94
+ </div>
95
+ );
96
+ }
97
+ const s = specs[id];
98
+ if (!s) return null;
99
+ return (
100
+ <button
101
+ key={id}
102
+ type="button"
103
+ className={s.primary || id === 'save' ? 'btn sm primary docp-save' : 'btn ghost sm'}
104
+ disabled={!!s.disabled}
105
+ onClick={() => runItem(id)}
106
+ >
107
+ {s.label || metaOf(KIND, id).label || id}
108
+ </button>
109
+ );
110
+ };
111
+
112
+ const groupedMore = MENU_GROUPS.map((g) => ({
113
+ ...g,
114
+ items: moreItems.filter((x) => metaOf(KIND, x.id).menuGroup === g.id),
115
+ })).filter((g) => g.items.length);
116
+ const ungroupedMore = moreItems.filter((x) => !metaOf(KIND, x.id).menuGroup);
117
+
118
+ if (!writable) {
119
+ return (
120
+ <div className="mdw-top docp-top">
121
+ {crumb}
122
+ <div className="mdw-head">
123
+ <div className="mdw-title">{title || '文档'}</div>
124
+ <div className="mdw-path">
125
+ {pathLabel}
126
+ {dirty ? ' · 未保存' : ''}
127
+ {external ? ' · 外部' : ''}
128
+ </div>
129
+ <span className="grow" />
130
+ {afterTitle}
131
+ <div className="docp-actions">
132
+ <span className="docp-tag ext">只读</span>
133
+ </div>
134
+ </div>
135
+ </div>
136
+ );
137
+ }
40
138
 
41
139
  return (
42
140
  <div className="mdw-top docp-top">
@@ -51,55 +149,73 @@ export default function DocHead({
51
149
  <span className="grow" />
52
150
  {afterTitle}
53
151
  <div className="docp-actions">
54
- {writable && groups.length > 0 && (
55
- <div className="docp-more" ref={more.ref}>
56
- <button
57
- type="button"
58
- className={`btn ghost sm${more.open ? ' on' : ''}`}
59
- title="更多操作"
60
- aria-haspopup="menu"
61
- aria-expanded={more.open}
62
- onClick={(e) => openMenuAt(more, e, 'right')}
63
- >
64
- 更多
65
- </button>
66
- <MenuPortal menu={more} className="mdw-act-menu">
67
- {groups.map((g) => (
68
- <div className="mdw-fmt-menu-group" role="group" aria-label={g.label} key={g.id || g.label}>
69
- <div className="mdw-fmt-menu-cap">{g.label}</div>
70
- {g.items.map((a) => (
71
- <button
72
- key={a.id || a.label}
73
- type="button"
74
- role="menuitem"
75
- className={'mdw-fmt-menu-item' + (a.danger ? ' danger' : '')}
76
- onClick={() => {
77
- more.setOpen(false);
78
- a.run?.();
79
- }}
80
- >
81
- {a.label}
82
- {a.hint ? <span className="hint">{a.hint}</span> : null}
83
- </button>
84
- ))}
85
- </div>
86
- ))}
87
- </MenuPortal>
88
- </div>
89
- )}
90
- {writable && (
152
+ {barItems.map((x) => renderBarBtn(x.id))}
153
+
154
+ <MenuPortal menu={more} className="mdw-act-menu">
155
+ {groupedMore.map((g) => (
156
+ <div className="mdw-fmt-menu-group" role="group" aria-label={g.label} key={g.id}>
157
+ <div className="mdw-fmt-menu-cap">{g.label}</div>
158
+ {g.items.map((x) => {
159
+ const s = specs[x.id];
160
+ const danger = s?.danger || metaOf(KIND, x.id).danger;
161
+ return (
162
+ <button
163
+ key={x.id}
164
+ type="button"
165
+ role="menuitem"
166
+ className={'mdw-fmt-menu-item' + (danger ? ' danger' : '')}
167
+ onClick={() => runItem(x.id)}
168
+ >
169
+ {s?.label || metaOf(KIND, x.id).label || x.id}
170
+ {s?.hint ? <span className="hint">{s.hint}</span> : null}
171
+ </button>
172
+ );
173
+ })}
174
+ </div>
175
+ ))}
176
+ {ungroupedMore.map((x) => {
177
+ const s = specs[x.id];
178
+ return (
179
+ <button
180
+ key={x.id}
181
+ type="button"
182
+ role="menuitem"
183
+ className={'mdw-fmt-menu-item' + (s?.danger || metaOf(KIND, x.id).danger ? ' danger' : '')}
184
+ onClick={() => runItem(x.id)}
185
+ >
186
+ {s?.label || metaOf(KIND, x.id).label || x.id}
187
+ </button>
188
+ );
189
+ })}
190
+ <div className="mdw-fmt-menu-sep" role="separator" />
91
191
  <button
92
192
  type="button"
93
- className="btn sm primary docp-save"
94
- disabled={saving || !dirty}
95
- onClick={onSave}
193
+ role="menuitem"
194
+ className="mdw-fmt-menu-item"
195
+ onClick={() => {
196
+ more.setOpen(false);
197
+ setPanelOpen(true);
198
+ }}
96
199
  >
97
- {saving ? '保存中…' : onSaveLabel}
200
+ 自定义工具栏…
98
201
  </button>
99
- )}
100
- {!writable && <span className="docp-tag ext">只读</span>}
202
+ </MenuPortal>
101
203
  </div>
102
204
  </div>
205
+
206
+ {panelOpen && createPortal(
207
+ <div className="ta-panel-mask" onClick={() => setPanelOpen(false)}>
208
+ <div className="ta-panel-wrap" onClick={(e) => e.stopPropagation()}>
209
+ <ToolActsLayoutPanel
210
+ kind={KIND}
211
+ layout={layout}
212
+ setLayout={setLayout}
213
+ onClose={() => setPanelOpen(false)}
214
+ />
215
+ </div>
216
+ </div>,
217
+ document.body
218
+ )}
103
219
  </div>
104
220
  );
105
221
  }