nx-kv 0.32.0 → 0.34.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 (118) hide show
  1. package/CHANGELOG.md +67 -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/index.js +59 -0
  7. package/src/modules/localtask/repo/tasks.js +23 -0
  8. package/src/modules/localtask/task-ops.js +9 -0
  9. package/src/modules/localtask/task-remove.js +69 -0
  10. package/src/modules/localtask/task-view.js +4 -0
  11. package/src/modules/tasktool/plugins/timegoal-store.js +60 -0
  12. package/src/modules/templates/index.js +65 -9
  13. package/src/modules/templates/repo/templates.js +24 -2
  14. package/src/modules/templates/scope.js +107 -0
  15. package/src/modules/templates/service.js +83 -4
  16. package/src/runtime/spec.js +6 -1
  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/icons.jsx +17 -0
  22. package/src/web/frontend/components/layout/crumbs.js +4 -1
  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 +102 -23
  27. package/src/web/frontend/components/md/sel-menu.jsx +11 -0
  28. package/src/web/frontend/components/md/tool-bar.jsx +153 -91
  29. package/src/web/frontend/components/sidebar/task-children.jsx +6 -11
  30. package/src/web/frontend/components/status-tag/index.jsx +30 -0
  31. package/src/web/frontend/components/status-tag/model.js +53 -0
  32. package/src/web/frontend/components/tool-acts/bar.jsx +156 -0
  33. package/src/web/frontend/components/tool-acts/dnd.js +59 -0
  34. package/src/web/frontend/components/tool-acts/layout-panel.jsx +289 -0
  35. package/src/web/frontend/components/tool-acts/modules.js +162 -0
  36. package/src/web/frontend/components/tool-acts/style.css +108 -0
  37. package/src/web/frontend/components/tool-acts/use-layout.js +27 -0
  38. package/src/web/frontend/modules/md/attach-mention.js +11 -0
  39. package/src/web/frontend/modules/md/md-edit-ops.js +10 -7
  40. package/src/web/frontend/modules/md/md-parse.js +8 -21
  41. package/src/web/frontend/modules/md/progress-search.js +96 -0
  42. package/src/web/frontend/modules/md/style.css +124 -14
  43. package/src/web/frontend/modules/md/use-templates.js +65 -2
  44. package/src/web/frontend/page/dir/index.jsx +73 -38
  45. package/src/web/frontend/page/dir/landing.jsx +73 -78
  46. package/src/web/frontend/page/dir/task.jsx +426 -111
  47. package/src/web/frontend/page/group/index.jsx +194 -88
  48. package/src/web/frontend/page/overview/index.jsx +168 -269
  49. package/src/web/frontend/page/progress/index.jsx +59 -9
  50. package/src/web/frontend/page/repos/index.jsx +95 -103
  51. package/src/web/frontend/page/settings/index.jsx +4 -3
  52. package/src/web/frontend/page/settings/style.css +59 -31
  53. package/src/web/frontend/page/settings/task-templates-section.jsx +94 -99
  54. package/src/web/frontend/page/templates/index.jsx +221 -203
  55. package/src/web/frontend/page/templates/scope-chips.jsx +211 -0
  56. package/src/web/frontend/panels.jsx +28 -4
  57. package/src/web/frontend/route-map.js +42 -2
  58. package/src/web/frontend/style-v2.css +33 -71
  59. package/src/web/frontend/style.css +127 -319
  60. package/src/web/frontend/workspace/areas.js +1 -1
  61. package/src/web/public/assets/Introduction-DU27b_b_.js +1 -0
  62. package/src/web/public/assets/bar-CNuQf706.js +1 -0
  63. package/src/web/public/assets/board-view-t8CKtq17.js +1 -0
  64. package/src/web/public/assets/button-BPYMY-zh.js +1 -0
  65. package/src/web/public/assets/button-DA4lNJeC.css +1 -0
  66. package/src/web/public/assets/cloud-DgNCxJsL.js +3 -0
  67. package/src/web/public/assets/{composer-launch-q1uPzWGo.js → composer-launch-BKeKTPp4.js} +1 -1
  68. package/src/web/public/assets/composer-panel-DP322mVs.js +1 -0
  69. package/src/web/public/assets/dag-C4702bOt.js +1 -0
  70. package/src/web/public/assets/dir-Cipgyv3a.js +5 -0
  71. package/src/web/public/assets/group-m61-WL4C.js +1 -0
  72. package/src/web/public/assets/index-BEkITE6q.css +1 -0
  73. package/src/web/public/assets/index-CeIJd4ee.js +30 -0
  74. package/src/web/public/assets/md-history-Uo6U7hYS.js +1 -0
  75. package/src/web/public/assets/md-panes-PS7K93Lg.js +28 -0
  76. package/src/web/public/assets/md-parse-DN9INgZn.js +25 -0
  77. package/src/web/public/assets/member-picker--32VkTmv.js +1 -0
  78. package/src/web/public/assets/overview-BmoTQJuu.js +1 -0
  79. package/src/web/public/assets/progress-CWy9bYKr.js +3 -0
  80. package/src/web/public/assets/refs-DAy1kYGf.js +1 -0
  81. package/src/web/public/assets/repos-D_NT51Dq.js +9 -0
  82. package/src/web/public/assets/route-crumb-lOriqwxP.js +1 -0
  83. package/src/web/public/assets/settings-CBrQ3Iz5.css +1 -0
  84. package/src/web/public/assets/settings-Vp3ZMC1M.js +7 -0
  85. package/src/web/public/assets/status-tag-DGlwjAg2.js +1 -0
  86. package/src/web/public/assets/task-CRpctHxx.js +9 -0
  87. package/src/web/public/assets/task-status-BP6y8MVu.js +1 -0
  88. package/src/web/public/assets/templates-D900RS5b.js +1 -0
  89. package/src/web/public/assets/tool-bar-1h2zairf.css +1 -0
  90. package/src/web/public/assets/tool-bar-C-rnP0vv.js +1 -0
  91. package/src/web/public/assets/upload-L1g-pfvZ.js +1 -0
  92. package/src/web/public/index.html +6 -5
  93. package/src/web/public/assets/Introduction-MAkTZvUX.js +0 -1
  94. package/src/web/public/assets/attach-Bw0necIf.js +0 -1
  95. package/src/web/public/assets/cloud-CG_hgVn9.js +0 -3
  96. package/src/web/public/assets/composer-panel-S2d6A3fG.js +0 -1
  97. package/src/web/public/assets/dag-CwY66RrZ.js +0 -1
  98. package/src/web/public/assets/dir-B_ySdQT1.js +0 -5
  99. package/src/web/public/assets/group-6sWouRDt.js +0 -1
  100. package/src/web/public/assets/index-DKncYqtS.js +0 -54
  101. package/src/web/public/assets/index-DO7b1M3E.css +0 -1
  102. package/src/web/public/assets/md-edit-ops-ZwnwtEax.js +0 -22
  103. package/src/web/public/assets/md-history-BxbOQtPI.js +0 -1
  104. package/src/web/public/assets/md-panes-Cso2NHbG.js +0 -7
  105. package/src/web/public/assets/member-picker-BpB9ZpWx.js +0 -1
  106. package/src/web/public/assets/overview-Bo8ivqRU.js +0 -1
  107. package/src/web/public/assets/progress-DPkGjn0P.js +0 -3
  108. package/src/web/public/assets/refs-CskU6rI7.js +0 -1
  109. package/src/web/public/assets/repos-B_tskNGw.js +0 -9
  110. package/src/web/public/assets/route-crumb-BZ6ffDRj.js +0 -1
  111. package/src/web/public/assets/settings-BMTd_p9Y.js +0 -7
  112. package/src/web/public/assets/settings-qCi-niJC.css +0 -1
  113. package/src/web/public/assets/task-Cs-9RNQn.js +0 -7
  114. package/src/web/public/assets/task-status-Bgo2Nfiw.js +0 -1
  115. package/src/web/public/assets/template-editor-CRxfV218.js +0 -1
  116. package/src/web/public/assets/templates-Apc3JKXa.js +0 -2
  117. package/src/web/public/assets/upload-C83Bwy06.js +0 -1
  118. /package/src/web/public/assets/{attach-BZrdOH46.css → task-status-BZrdOH46.css} +0 -0
@@ -0,0 +1,107 @@
1
+ // 模板可见域(scope)纯解析:无 DB、无 IO,service 与前端可共享同一套判定。
2
+ //
3
+ // 评估与裁决见 plan/2026-11-09-template-architecture-eval.md §2(任务 #123/#128):
4
+ // 不做 policy 引擎,一条可见性规则 + 一条编辑权规则,全是纯函数。
5
+ //
6
+ // scope 条目词表(写库前经 normalizeScope 归一,非法条目进不来):
7
+ // "*" 全局可见
8
+ // "topic:<key>" 指定队列主题(topics.key,含全局池 __GLOBAL__)
9
+ // "repo:<key>" 指定项目(repos.key)
10
+ // "group:<key>" 指定项目组(组也是 repos.key,type='group')
11
+ //
12
+ // 判定口径:
13
+ // 可见(use) = scope 含 "*",或命中主题行三把钥匙(key / repoKey / groupKey)之一;
14
+ // 可编辑(edit)= origin_topic 命中本主题,或 scope 显式点名本主题——比 use 严:
15
+ // "*" 只给「能用」,不给「能改」;repo/group 域同样不给改
16
+ // (改模板是全机影响,只有创建处与显式点名处可以动)。
17
+ import { badInput } from '../../core/errors.js';
18
+
19
+ export const GLOBAL_SCOPE = '*';
20
+ const KINDS = ['topic', 'repo', 'group'];
21
+ const SCOPE_MAX_ENTRIES = 32;
22
+ const KEY_MAX_LEN = 200;
23
+
24
+ /** 单条 scope 条目是否合法("*" 或 <kind>:<非空无空白 key>)。 */
25
+ export function isScopeEntry(s) {
26
+ const v = String(s ?? '');
27
+ if (v === GLOBAL_SCOPE) return true;
28
+ const i = v.indexOf(':');
29
+ if (i <= 0) return false;
30
+ const kind = v.slice(0, i);
31
+ const key = v.slice(i + 1);
32
+ return KINDS.includes(kind) && !!key && key.length <= KEY_MAX_LEN && !/\s/.test(key);
33
+ }
34
+
35
+ /**
36
+ * 归一化 scope:收数组(或 JSON 串),去重保序、丢弃非法条目、限 32 条。
37
+ * strict=true(CLI/HTTP 写入路径)时遇到非法条目直接报错——静默丢弃会让
38
+ * 「我以为设了域其实没设上」;读取路径(DB 行反解)用宽松档兜脏数据。
39
+ */
40
+ export function normalizeScope(raw, { strict = false } = {}) {
41
+ let arr = raw;
42
+ if (typeof arr === 'string') {
43
+ const s = arr.trim();
44
+ if (!s) return [];
45
+ try {
46
+ arr = JSON.parse(s);
47
+ } catch (e) {
48
+ if (strict) throw badInput(`--scope 要传 JSON 数组(形如 ["*"] 或 ["topic:<key>"]):${e.message || e}`);
49
+ return [];
50
+ }
51
+ }
52
+ if (arr == null) return strict ? [] : [];
53
+ if (!Array.isArray(arr)) {
54
+ if (strict) throw badInput('--scope 要传 JSON 数组(形如 ["*"] 或 ["topic:<key>"])');
55
+ return [];
56
+ }
57
+ const out = [];
58
+ for (const item of arr) {
59
+ const v = String(item ?? '').trim();
60
+ if (!isScopeEntry(v)) {
61
+ if (strict) {
62
+ throw badInput(
63
+ `--scope 里有不认识的条目「${v}」——合法写法:* / topic:<key> / repo:<key> / group:<key>`
64
+ );
65
+ }
66
+ continue;
67
+ }
68
+ if (!out.includes(v)) out.push(v);
69
+ if (out.length >= SCOPE_MAX_ENTRIES) break;
70
+ }
71
+ return out;
72
+ }
73
+
74
+ /** 主题判定上下文:三把钥匙(topics 行的 camelCase 影子)。 */
75
+ export function topicCtx({ key = '', repoKey = '', groupKey = '' } = {}) {
76
+ return { key: String(key || ''), repoKey: String(repoKey || ''), groupKey: String(groupKey || '') };
77
+ }
78
+
79
+ /** 条目是否命中主题上下文("*" 不在此判——它是可见性的全局短路,见 canUse)。 */
80
+ function entryHits(entry, ctx) {
81
+ const i = entry.indexOf(':');
82
+ const kind = entry.slice(0, i);
83
+ const key = entry.slice(i + 1);
84
+ if (kind === 'topic') return key === ctx.key;
85
+ if (kind === 'repo') return key === ctx.repoKey;
86
+ if (kind === 'group') return key === ctx.groupKey;
87
+ return false;
88
+ }
89
+
90
+ /** 该模板对主题 ctx 是否可用(菜单里出不出来)。 */
91
+ export function canUse(t, ctx) {
92
+ const scope = Array.isArray(t && t.scope) ? t.scope : [];
93
+ if (scope.includes(GLOBAL_SCOPE)) return true;
94
+ return scope.some((s) => isScopeEntry(s) && entryHits(s, ctx));
95
+ }
96
+
97
+ /** 该模板在主题 ctx 是否可编辑(origin 命中或 scope 显式点名;比 use 严)。 */
98
+ export function canEdit(t, ctx) {
99
+ if (t && t.originTopic && t.originTopic === ctx.key) return true;
100
+ const scope = Array.isArray(t && t.scope) ? t.scope : [];
101
+ return scope.includes(`topic:${ctx.key}`);
102
+ }
103
+
104
+ /** 一列模板按可见域过滤(保持原顺序)。 */
105
+ export function visibleTemplates(list, ctx) {
106
+ return (list || []).filter((t) => canUse(t, ctx));
107
+ }
@@ -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
 
@@ -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
  }