nx-kv 0.62.0 → 0.63.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 (108) hide show
  1. package/CHANGELOG.md +52 -1
  2. package/assets/nx-kv/references/B02-CLI/351/200/237/346/237/245.md +2 -1
  3. package/package.json +1 -1
  4. package/src/core/db/seed-templates.ts +75 -3
  5. package/src/modules/docs/actions/_manifest.generated.ts +3 -0
  6. package/src/modules/docs/actions/docs-main.ts +39 -0
  7. package/src/modules/docs/refs.ts +75 -0
  8. package/src/web/frontend/api/cli-tree.json +15 -0
  9. package/src/web/frontend/api/client.generated.ts +10 -0
  10. package/src/web/frontend/components/icons.tsx +12 -0
  11. package/src/web/frontend/components/md/live-block.tsx +20 -5
  12. package/src/web/frontend/components/md/md-panes-root.tsx +4 -0
  13. package/src/web/frontend/components/md/md-panes.tsx +27 -1
  14. package/src/web/frontend/components/popup/index.tsx +11 -1
  15. package/src/web/frontend/components/popup/style.css +4 -0
  16. package/src/web/frontend/components/sidebar/index.tsx +1 -0
  17. package/src/web/frontend/modules/md/styles/editor.css +24 -0
  18. package/src/web/frontend/modules/md/styles/panels.css +14 -2
  19. package/src/web/frontend/modules/md/template-locks.ts +105 -0
  20. package/src/web/frontend/modules/md/use-templates.ts +16 -5
  21. package/src/web/frontend/modules/prompts/template-preview.ts +70 -0
  22. package/src/web/frontend/page/dir/index.tsx +21 -9
  23. package/src/web/frontend/page/dir/task-actions.ts +2 -1
  24. package/src/web/frontend/page/dir/task.tsx +2 -2
  25. package/src/web/frontend/page/group/index.tsx +8 -11
  26. package/src/web/frontend/page/refs/index.tsx +49 -10
  27. package/src/web/frontend/page/refs/style.css +4 -0
  28. package/src/web/frontend/page/repos/block-tabs.tsx +30 -24
  29. package/src/web/frontend/page/repos/branch-picker.tsx +29 -20
  30. package/src/web/frontend/page/repos/doc-block.tsx +9 -2
  31. package/src/web/frontend/page/repos/icons.tsx +32 -0
  32. package/src/web/frontend/page/repos/index.tsx +84 -51
  33. package/src/web/frontend/page/repos/ref-block.tsx +9 -9
  34. package/src/web/frontend/page/repos/repo-table.tsx +18 -15
  35. package/src/web/frontend/page/repos/search-results.tsx +114 -0
  36. package/src/web/frontend/page/settings/index.tsx +0 -14
  37. package/src/web/frontend/page/templates/index.tsx +70 -30
  38. package/src/web/frontend/page/templates/style.css +62 -0
  39. package/src/web/frontend/page/templates/template-list.tsx +198 -0
  40. package/src/web/frontend/panels.tsx +2 -2
  41. package/src/web/frontend/refs/api.ts +10 -0
  42. package/src/web/frontend/refs/ops.ts +15 -0
  43. package/src/web/frontend/styles/repos-branch.css +72 -0
  44. package/src/web/frontend/styles-v2/views.css +5 -4
  45. package/src/web/frontend/types.ts +2 -0
  46. package/src/web/public/assets/app-context-DDQnrPSP.js +1 -0
  47. package/src/web/public/assets/bar-CYWfxHfm.js +1 -0
  48. package/src/web/public/assets/{board-view-CUeSVy9F.js → board-view-BVennxTs.js} +1 -1
  49. package/src/web/public/assets/button-BEWXOABr.js +1 -0
  50. package/src/web/public/assets/composer-launch-Bor4ngrQ.js +1 -0
  51. package/src/web/public/assets/composer-panel-C7mNI7EW.js +1 -0
  52. package/src/web/public/assets/dag-BzdFYMml.js +1 -0
  53. package/src/web/public/assets/dir-CcffxXL2.js +3 -0
  54. package/src/web/public/assets/doc-BxWVzWkw.js +6 -0
  55. package/src/web/public/assets/frontmatter-CN6IlxWU.js +2 -0
  56. package/src/web/public/assets/group-C5Yu3oJr.js +1 -0
  57. package/src/web/public/assets/index-BvyZ1MA2.js +2 -0
  58. package/src/web/public/assets/index-Cp-TtHyA.css +1 -0
  59. package/src/web/public/assets/md-history-DejKuR12.js +39 -0
  60. package/src/web/public/assets/{md-parse-BE6EWfZ1.js → md-parse-C9Vd6ejP.js} +1 -1
  61. package/src/web/public/assets/member-picker-Cvbv24IK.js +1 -0
  62. package/src/web/public/assets/{model-Co--HRvt.js → model-Cc2EoUQp.js} +1 -1
  63. package/src/web/public/assets/overview-CctJfO3D.js +1 -0
  64. package/src/web/public/assets/{frontmatter-BZrdOH46.css → popup-BAvk7J7u.css} +1 -1
  65. package/src/web/public/assets/{frontmatter-DEIM0yF2.js → popup-D8KWI6-Q.js} +1 -2
  66. package/src/web/public/assets/progress-CawQRCQf.js +3 -0
  67. package/src/web/public/assets/refs-DJdKV8_H.css +1 -0
  68. package/src/web/public/assets/refs-VbDnDTV0.js +2 -0
  69. package/src/web/public/assets/repo-form-modal-Dkdvu_uN.js +1 -0
  70. package/src/web/public/assets/repos-CY0eZheu.js +16 -0
  71. package/src/web/public/assets/route-crumb-BcDPd7Ht.js +1 -0
  72. package/src/web/public/assets/settings-D3T-vgCl.js +1 -0
  73. package/src/web/public/assets/status-tag-BD_0iWMB.js +1 -0
  74. package/src/web/public/assets/task-CkCD82h_.js +11 -0
  75. package/src/web/public/assets/task-row-CQgzQmzu.js +1 -0
  76. package/src/web/public/assets/{task-utils-dgdA6Pxs.js → task-utils-DpnPjZKJ.js} +1 -1
  77. package/src/web/public/assets/templates-BcuCbT4U.js +10 -0
  78. package/src/web/public/assets/templates-gNdtaMI2.css +1 -0
  79. package/src/web/public/assets/use-rail-drag-DMvr8-GE.js +1 -0
  80. package/src/web/public/assets/{workspace-C0PPPfA1.js → workspace-D3jbcTwf.js} +2 -2
  81. package/src/web/public/index.html +17 -15
  82. package/src/web/frontend/page/settings/task-templates-section.tsx +0 -124
  83. package/src/web/public/assets/app-context-CR7f0AtI.js +0 -1
  84. package/src/web/public/assets/bar-CGEZ954x.js +0 -1
  85. package/src/web/public/assets/composer-launch-Dhrj1gNT.js +0 -1
  86. package/src/web/public/assets/composer-panel-Dou1Xwih.js +0 -1
  87. package/src/web/public/assets/dag-ChYvtJCy.js +0 -1
  88. package/src/web/public/assets/dir-Bfn4tG10.js +0 -3
  89. package/src/web/public/assets/doc-Nk0fieHx.js +0 -6
  90. package/src/web/public/assets/group-DT_vHiWd.js +0 -1
  91. package/src/web/public/assets/index-IzwqMhg-.css +0 -1
  92. package/src/web/public/assets/index-RX7knClE.js +0 -2
  93. package/src/web/public/assets/md-history-BRw2I-G_.js +0 -39
  94. package/src/web/public/assets/member-picker-B_LsCqNq.js +0 -1
  95. package/src/web/public/assets/overview-DwCaowBF.js +0 -1
  96. package/src/web/public/assets/progress-C7BIqnCG.js +0 -3
  97. package/src/web/public/assets/refs-CIdrPlDN.css +0 -1
  98. package/src/web/public/assets/refs-FIEXTEYm.js +0 -2
  99. package/src/web/public/assets/repo-form-modal-CZRdlCn6.js +0 -1
  100. package/src/web/public/assets/repos-BCdFev-O.js +0 -16
  101. package/src/web/public/assets/route-crumb-CkhC1zw2.js +0 -1
  102. package/src/web/public/assets/settings-Z0Y4UhKP.js +0 -1
  103. package/src/web/public/assets/status-tag-BKA9au1l.js +0 -1
  104. package/src/web/public/assets/task-Bk7h0vlJ.js +0 -11
  105. package/src/web/public/assets/task-row-CHSIDNmR.js +0 -1
  106. package/src/web/public/assets/templates-DxBtkzVI.js +0 -1
  107. package/src/web/public/assets/use-rail-drag-H0M8oQ0Z.js +0 -1
  108. /package/src/web/public/assets/{repo-form-modal-DA4lNJeC.css → button-DA4lNJeC.css} +0 -0
@@ -340,13 +340,25 @@ button.cmp-quote:focus-visible{outline:2px solid var(--mdw-accent-line,#B7D4C8);
340
340
  }
341
341
  /* 工具栏/纸面自适应走容器查询:随编辑列实际宽度分级折叠——
342
342
  640 纸面紧凑(#78 后动作区只剩 新任务/提交/更多,无需再按宽收动作)。
343
- 此前用视口媒体查询,进程 rail 一开窄列就静默裁掉按钮( overflow:hidden 兜底) */
343
+ 此前用视口媒体查询,进程 rail 一开窄列就静默裁掉按钮( overflow:hidden 兜底)。
344
+ 2026-11-16「太挤了」:窄列只收纸面 padding 不够——大标题、标题字号、块距、
345
+ 代码块都要跟着收,整页节奏才回来;全部写在块容器/纸面层,不破坏 #31 的
346
+ 视图↔编辑等高约束 */
344
347
  @container mdwmain (max-width: 960px){
345
348
  .mdw-lp-sheet,.mdw-reader{padding:20px 22px 56px}
349
+ .mdw-lp input.mdw-lp-title,.mdw-lp textarea.mdw-lp-title,.mdw-reader-title{font-size:24px;margin-bottom:22px}
346
350
  }
347
351
  @container mdwmain (max-width: 640px){
348
352
  .mdw-lp-sheet,.mdw-reader{padding:16px 16px 48px}
349
- .mdw-lp input.mdw-lp-title,.mdw-lp textarea.mdw-lp-title,.mdw-reader-title{font-size:24px}
353
+ .mdw-lp input.mdw-lp-title,.mdw-lp textarea.mdw-lp-title,.mdw-reader-title{font-size:20px;margin-bottom:14px}
354
+ .mdw-lp-view h1,.mdw-preview h1{font-size:18px}
355
+ .mdw-lp-view h2,.mdw-preview h2{font-size:15px}
356
+ .mdw-lp-view pre,.mdw-preview pre{margin:6px 0;padding:8px 10px;font-size:11.5px;line-height:1.5}
357
+ /* 块距收一档(块容器承担,视图↔编辑仍等高) */
358
+ .mdw-lp-block.kind-h1{padding-top:6px;padding-bottom:10px}
359
+ .mdw-lp-block.kind-h2{padding-top:10px;padding-bottom:8px}
360
+ .mdw-lp-block.kind-h3{padding-top:8px;padding-bottom:8px}
361
+ .mdw-lp-gap{min-height:1.2em}
350
362
  }
351
363
 
352
364
  /* 快捷键速查面板:外壳走 popup/Modal(pp-card pp-lg + .mdw-sheet 追加类),
@@ -0,0 +1,105 @@
1
+ // 模板生成的任务 → 编辑器里哪些块是「模板骨架(只读)」、哪些是「插槽(可编辑)」。
2
+ //
3
+ // 判定依据只有两样,都在正文里,不依赖前端内存:
4
+ // 1. frontmatter 的 `template: <id>`(templateIdOf)——这条任务由哪个模板生成
5
+ // 2. 该模板当下的正文(templates 表)——骨架长什么样
6
+ //
7
+ // 为什么要比对而不是在正文里插标记:正文会被交付给 agent({{task.text}})、
8
+ // 会被 CLI 侧编辑、会被复制成新任务——任何不可见标记都会跟着跑,或在某一环被剥掉。
9
+ // 比对是**纯派生**:模板改了,锁定范围自然跟着变,不产生第二份真相。
10
+ //
11
+ // 块粒度与编辑器一致(liveBodyBlocks:剥首个 H1、frontmatter 自成一块),
12
+ // 下标可以直接喂给 .mdw-lp-block[data-i]。
13
+ import { liveBodyBlocks } from './md-blocks.js';
14
+
15
+ const SLOT_SRC = '\\{\\{\\s*[^{}\\s][^{}]*?\\s*\\}\\}';
16
+ const SLOT_RE_G = new RegExp(SLOT_SRC, 'g');
17
+ const SLOT_RE = new RegExp(SLOT_SRC);
18
+
19
+ /** 块比较口径:只剥 ZWSP 与首尾空白(内部换行/缩进必须逐字相同才算骨架)。 */
20
+ function norm(b: unknown): string {
21
+ return String(b ?? '').replace(/\u200b/g, '').trim();
22
+ }
23
+
24
+ function escapeRe(s: string): string {
25
+ return s.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
26
+ }
27
+
28
+ /** 模板块 → 正文块判定器:含槽位的块,槽位位置可任意(那是用户填的内容)。 */
29
+ function matcherOf(templateBlock: string): (block: string) => boolean {
30
+ const t = norm(templateBlock);
31
+ if (!SLOT_RE.test(t)) return (b) => norm(b) === t;
32
+ const parts = t.split(SLOT_RE_G).map(escapeRe);
33
+ const re = new RegExp(`^${parts.join('[\\s\\S]*?')}$`);
34
+ return (b) => re.test(norm(b));
35
+ }
36
+
37
+ /** 整块只有槽位(去掉槽位后没有实质文字)——这块本身就是「填这里」。 */
38
+ function isPureSlot(templateBlock: string): boolean {
39
+ const t = norm(templateBlock);
40
+ if (!SLOT_RE.test(t)) return false;
41
+ return t.replace(SLOT_RE_G, '').trim() === '';
42
+ }
43
+
44
+ export interface TemplateLocks {
45
+ /** 模板骨架块(未含槽位):只读 */
46
+ locked: Set<number>;
47
+ /** 插槽块(模板块里声明了 {{槽位}}):可编辑,但视觉上标出来 */
48
+ slots: Set<number>;
49
+ }
50
+
51
+ const EMPTY: TemplateLocks = { locked: new Set(), slots: new Set() };
52
+
53
+ /**
54
+ * 任务正文块 vs 模板正文 → 锁定/插槽块下标。
55
+ *
56
+ * 顺序匹配(双指针):模板块按原顺序在正文里找第一个对得上的块;对不上的正文块
57
+ * 视为用户新增(可编辑)。骨架块被用户删掉/改写过 → 它不再匹配,自然解锁——
58
+ * 只读只保护「原样还在的骨架」,不会把用户已经改动的内容锁死。
59
+ */
60
+ export function computeTemplateLocks(taskBody: string, templateBody: string): TemplateLocks {
61
+ if (!String(templateBody ?? '').trim()) return EMPTY;
62
+ // 没有槽位的模板不锁:只读的前提是「有可编辑的出口」,否则整篇锁死、任务没法写。
63
+ if (!SLOT_RE.test(String(templateBody))) return EMPTY;
64
+ const tpl = liveBodyBlocks(templateBody);
65
+ const blocks = liveBodyBlocks(taskBody);
66
+ if (!tpl.length || !blocks.length) return EMPTY;
67
+
68
+ const locked = new Set<number>();
69
+ const slots = new Set<number>();
70
+ let j = 0; // 模板游标
71
+ let i = 0; // 正文游标
72
+ while (j < tpl.length && i < blocks.length) {
73
+ const t = tpl[j] ?? '';
74
+ if (!norm(t)) {
75
+ j += 1; // 模板里的空块不参与对齐(splitMdBlocks 正常不会产出,ZWSP 块才会)
76
+ continue;
77
+ }
78
+ // 纯槽位块:正常情况它就占正文当前位置(顺序语义),不去后面搜索——
79
+ // 否则「万能匹配」会吃掉下一块骨架(如分隔线),把只读判成可编辑。
80
+ // 例外:用户把这块删了(当前位置已经是下一块骨架)→ 跳过它、不占位。
81
+ if (isPureSlot(t)) {
82
+ const nextTpl = tpl[j + 1];
83
+ if (nextTpl && matcherOf(nextTpl)(blocks[i] ?? '')) {
84
+ j += 1;
85
+ continue;
86
+ }
87
+ slots.add(i);
88
+ j += 1;
89
+ i += 1;
90
+ continue;
91
+ }
92
+ const hit = matcherOf(t);
93
+ // 在正文里往后找第一个对得上的块(允许用户在前面插入新块)
94
+ let k = i;
95
+ for (; k < blocks.length; k += 1) {
96
+ if (hit(blocks[k] ?? '')) break;
97
+ }
98
+ if (k >= blocks.length) break; // 骨架已被改到对不上:剩下的不再锁定
99
+ if (SLOT_RE.test(norm(t))) slots.add(k);
100
+ else locked.add(k);
101
+ j += 1;
102
+ i = k + 1;
103
+ }
104
+ return { locked, slots };
105
+ }
@@ -53,15 +53,25 @@ export function useTemplates(): TemplatesApi {
53
53
  refetch();
54
54
  }, [refetch]);
55
55
 
56
- /** 默认模板正文(未加载/拉取失败 → 内置骨架 + 默认槽位值兜底)。
57
- * 永远返回**已渲染**正文——任务里不能出现裸 `{{槽位}}`。 */
58
- const defaultBody = useCallback(() => {
56
+ /**
57
+ * 默认模板的「正文 + 模板身份」。
58
+ *
59
+ * 为什么要把 id 一起给出来:由模板生成的任务,编辑器要按模板骨架把
60
+ * 「骨架块」标成只读(#217)。身份落在正文 frontmatter 的 `template:` 上,
61
+ * 刷新 / 换设备 / CLI 侧改过之后仍然成立——只存前端内存的话一刷新就丢。
62
+ *
63
+ * 正文永远**已渲染**:任务里不能出现裸 `{{槽位}}`。
64
+ */
65
+ const defaultPick = useCallback(() => {
59
66
  const t = (state.templates || []).find((x) => x.id === state.defaultId);
60
- if (!t) return ''; // #137:没有可用模板 → 从空稿开始(出厂文本只有后端那一份)
67
+ if (!t) return { body: '', id: '' }; // #137:没有可用模板 → 从空稿开始(出厂文本只有后端那一份)
61
68
  // 缺的键用内置默认值补;用户显式留空('')仍是空——不把标记露回正文。
62
- return renderTemplateBody(t.body, t.values || {});
69
+ return { body: renderTemplateBody(t.body, t.values || {}), id: String(t.id || '') };
63
70
  }, [state]);
64
71
 
72
+ /** 默认模板正文(未加载/拉取失败 → 空稿)。 */
73
+ const defaultBody = useCallback(() => defaultPick().body, [defaultPick]);
74
+
65
75
  const add = useCallback(async (
66
76
  name: string,
67
77
  body: string,
@@ -109,6 +119,7 @@ export function useTemplates(): TemplatesApi {
109
119
  templates: state.templates,
110
120
  unsupported: state.unsupported,
111
121
  defaultBody,
122
+ defaultPick,
112
123
  refetch,
113
124
  add,
114
125
  remove,
@@ -0,0 +1,70 @@
1
+ // 任务模板的**预览**渲染(面板侧,纯函数):与真正生成任务用的
2
+ // renderTemplateBody 只差「没值的槽位怎么显示」——
3
+ // 生成任务:没值 → 留空(任务正文里不能出现裸 {{槽位}})
4
+ // 预览: 没值 → 可见占位 〔槽位名〕,用户才知道哪里要填
5
+ //
6
+ // 两套语义分开,是因为它们的消费者不同:前者进交付正文,后者进设置页的预览框。
7
+ // 预览**不写任何存储**、不改变真相——模板正文(templates.json / sqlite)仍是唯一真源。
8
+ import { parseFrontmatter, withFrontmatter } from '../../../../shared/frontmatter.js';
9
+ import { renderTemplateBody } from './render-template-body.js';
10
+
11
+ const SLOT_RE = /\{\{\s*([^}{\s][^{}]*?)\s*\}\}/g;
12
+
13
+ /** 模板正文里声明了哪些槽位(按首次出现顺序去重)。 */
14
+ export function templateSlots(body: unknown): string[] {
15
+ const seen = new Set<string>();
16
+ for (const m of String(body ?? '').matchAll(SLOT_RE)) {
17
+ const key = String(m[1] ?? '').trim();
18
+ if (key) seen.add(key);
19
+ }
20
+ return [...seen];
21
+ }
22
+
23
+ /** 预览渲染:{{槽位}} → 槽位值;没有值的槽位显示加粗占位〔槽位名〕。 */
24
+ export function renderTemplatePreview(
25
+ body: unknown,
26
+ values?: Record<string, unknown> | null,
27
+ ): string {
28
+ const vals: Record<string, unknown> = values && typeof values === 'object' ? values : {};
29
+ return String(body ?? '').replace(SLOT_RE, (_all, name) => {
30
+ const key = String(name ?? '').trim();
31
+ const v = vals[key];
32
+ const filled = v !== undefined && v !== null && String(v).trim() !== '';
33
+ return filled ? String(v) : `**〔${key}〕**`;
34
+ });
35
+ }
36
+
37
+ /**
38
+ * 从任务正文的 frontmatter 读「这条任务由哪个模板生成」(键 `template`)。
39
+ *
40
+ * 没有该键 = 不是模板生成的任务(用户直接写的),编辑器不加任何只读区。
41
+ * 为什么要落进 frontmatter:编辑器的只读判定需要**模板身份**才能拿到骨架正文;
42
+ * 模板 id 存在正文头里,刷新 / 换设备 / CLI 侧编辑后都还在,不依赖前端内存。
43
+ */
44
+ export function templateIdOf(body: unknown): string {
45
+ const fm = parseFrontmatter(body);
46
+ return String(fm.template || '').trim();
47
+ }
48
+
49
+ /**
50
+ * 由模板生成的**任务正文**:槽位按「没值留空」渲染,并把模板身份写进 frontmatter。
51
+ *
52
+ * 这是「模板 → 任务」的唯一入口(新建任务 / 新建草稿 / 组页新建都走它):
53
+ * 身份只在这一步写入,之后正文怎么改都还带着它——编辑器据此把骨架块标成只读。
54
+ * 模板 id 为空(没有可用模板)→ 原样返回,不凭空造 frontmatter。
55
+ */
56
+ export function templateDraftBody(
57
+ tpl: {
58
+ id?: string;
59
+ body?: unknown;
60
+ values?: Record<string, unknown> | null;
61
+ },
62
+ /** 同时要写的其它归属字段(board / project…)——一次成型,避免二次 withFrontmatter 把 template 冲掉 */
63
+ extra: Record<string, unknown> = {},
64
+ ): string {
65
+ const body = renderTemplateBody(tpl.body, tpl.values);
66
+ const id = String(tpl.id || '').trim();
67
+ const fields: Record<string, unknown> = { ...extra };
68
+ if (id) fields.template = id;
69
+ return Object.keys(fields).length ? withFrontmatter(body, fields) : body;
70
+ }
@@ -25,9 +25,9 @@ import { useApp } from '../../app-context.jsx';
25
25
  import Landing from './landing.jsx';
26
26
  import DagEditor from './dag-editor.jsx';
27
27
  import { findOpenPanel, openPanel } from '../../workspace.js';
28
- import { openSettingsPanel, openTemplateEditor } from '../../panels.jsx';
28
+ import { openTemplateEditor } from '../../panels.jsx';
29
29
  import { docIdOf, nextDraftId, saveDoc, scopeOf } from '../../modules/md/doc-store.js';
30
- import { renderTemplateBody } from '../../modules/prompts/render-template-body.js';
30
+ import { templateDraftBody } from '../../modules/prompts/template-preview.js';
31
31
  import { useTemplatesFor } from '../../modules/md/use-templates.js';
32
32
  import type { LocalTask, PromptTemplate, RepoRow } from '../../types.js';
33
33
  import { sortTasksForDisplay } from './task-utils.js';
@@ -167,8 +167,9 @@ export default function DirPanel({ dirKey }: DirPanelProps) {
167
167
  if (app.openPage) app.openPage({ dirKey, task, name: '新任务' });
168
168
  };
169
169
 
170
- const openTplSettings = () => {
171
- if (model) openSettingsPanel(model);
170
+ // #217:模板列表从设置搬到侧边栏入口 + 主内容区——「管理模板…」直接去那一页
171
+ const openTplList = () => {
172
+ app.onNavigate?.('#/templates');
172
173
  };
173
174
 
174
175
  const openProgress = () => {
@@ -206,13 +207,21 @@ export default function DirPanel({ dirKey }: DirPanelProps) {
206
207
  ? menuTemplates.map((t: PromptTemplate) => ({
207
208
  label: (t.id === tpl?.defaultId ? '✓ ' : '') + t.name,
208
209
  icon: 'list',
209
- // 正文按模板取值渲染(老模板可能带 {{槽位}},任务里不能出现裸标记)
210
- onClick: () => newDraft(renderTemplateBody(t.body, t.values || {})),
210
+ // 正文按模板取值渲染(老模板可能带 {{槽位}},任务里不能出现裸标记);
211
+ // 模板身份写进 frontmatter,编辑器据此把骨架块标只读(#217)
212
+ onClick: () => newDraft(templateDraftBody(t)),
211
213
  }))
212
- : [{ label: '按默认模板新建一页', icon: 'list', onClick: () => newDraft(tpl ? tpl.defaultBody() : '') }]),
214
+ : [{
215
+ label: '按默认模板新建一页',
216
+ icon: 'list',
217
+ onClick: () => {
218
+ const p = tpl ? tpl.defaultPick() : null;
219
+ newDraft(p && p.id ? templateDraftBody(p) : (p ? p.body : ''));
220
+ },
221
+ }]),
213
222
  'sep',
214
223
  { label: `为本${isGlobal ? '全局池' : '目录'}新建模板…`, icon: 'plus', onClick: newTemplateForHere },
215
- { label: '管理模板…', icon: 'gear', onClick: openTplSettings },
224
+ { label: '管理模板…', icon: 'gear', onClick: openTplList },
216
225
  ];
217
226
 
218
227
  // #79:反馈的 base 以**服务端当前正文**为准——列表行的 t.text 是 rows 快照,
@@ -453,7 +462,10 @@ export default function DirPanel({ dirKey }: DirPanelProps) {
453
462
  page={pager.page}
454
463
  pageCount={pager.pageCount}
455
464
  onPage={pager.setPage}
456
- onNew={() => newDraft(tpl ? tpl.defaultBody() : '')}
465
+ onNew={() => {
466
+ const p = tpl ? tpl.defaultPick() : null;
467
+ newDraft(p && p.id ? templateDraftBody(p) : (p ? p.body : ''));
468
+ }}
457
469
  onOpenTask={openTask}
458
470
  onDeleteTask={delTask}
459
471
  onDeleteTasks={batchDeleteTasks}
@@ -25,6 +25,7 @@ import {
25
25
  stripPhantomEmptyLines,
26
26
  withFrontmatter,
27
27
  } from '../../modules/md/md-parse.js';
28
+ import { templateDraftBody } from '../../modules/prompts/template-preview.js';
28
29
  import {
29
30
  docIdOf,
30
31
  nextDraftId,
@@ -401,7 +402,7 @@ export function useTaskActions({
401
402
  if (docFm.project) fm.project = docFm.project;
402
403
  saveDoc(docId, {
403
404
  title: '',
404
- body: withFrontmatter(tpl ? tpl.defaultBody() : '', fm),
405
+ body: tpl ? templateDraftBody(tpl.defaultPick(), fm) : withFrontmatter('', fm),
405
406
  });
406
407
  if (app.openPage) {
407
408
  app.openPage(
@@ -33,8 +33,8 @@ import {
33
33
  liveBodyBlocks,
34
34
  titleFromMd,
35
35
  stripTitleHeading,
36
- withFrontmatter,
37
36
  } from '../../modules/md/md-parse.js';
37
+ import { templateDraftBody } from '../../modules/prompts/template-preview.js';
38
38
  import {
39
39
  docIdOf,
40
40
  getDoc,
@@ -214,7 +214,7 @@ export default function PagePanel({ dirKey, groupId, task, beside = false, tabId
214
214
  getDoc(id, {
215
215
  title: '',
216
216
  body: tpl
217
- ? (groupAnchored ? withFrontmatter(tpl.defaultBody(), { board: groupId }) : tpl.defaultBody())
217
+ ? templateDraftBody(tpl.defaultPick(), groupAnchored ? { board: groupId } : {})
218
218
  : '',
219
219
  });
220
220
  } else if (taskRow) getDoc(id, { title: titleFromMd(taskRow.text), body: taskRow.text });
@@ -26,9 +26,9 @@ import { openPanel } from '../../workspace.js';
26
26
  import { openTemplateEditor } from '../../panels.jsx';
27
27
  import ToolActsBar from '../../components/tool-acts/bar.jsx';
28
28
  import { docIdOf, nextDraftId, saveDoc, scopeOf } from '../../modules/md/doc-store.js';
29
- import { parseFrontmatter, withFrontmatter } from '../../modules/md/md-parse.js';
29
+ import { parseFrontmatter } from '../../modules/md/md-parse.js';
30
30
  import { hitTaskQuery } from '../../modules/board/task-search.js';
31
- import { renderTemplateBody } from '../../modules/prompts/render-template-body.js';
31
+ import { templateDraftBody } from '../../modules/prompts/template-preview.js';
32
32
  import { useTemplates, useTemplatesFor } from '../../modules/md/use-templates.js';
33
33
  import type { LocalTask, LocalTopic, RepoData } from '../../types.js';
34
34
  import type { Model } from 'flexlayout-react';
@@ -352,7 +352,7 @@ export default function GroupView({ dirKey, rows, repoData, model }: {
352
352
  // 可改归属项目(限本组成员),按它路由进对应项目的队列。
353
353
  // 落种用 PagePanel 同一套复合键(scope::draft-N)——裸 draft 号会种不到正文上。
354
354
  // body 可选(#128):hover 面板里选了模板就带模板正文;不带 = 默认模板(旧行为)。
355
- const createTask = (body?: string) => {
355
+ const createTask = (pick?: { id?: string; body?: unknown; values?: Record<string, unknown> | null } | null) => {
356
356
  if (!board) return;
357
357
  if (!sel) return toast('这个组还没有成员——先「添加成员」,再建任务');
358
358
  const id = nextDraftId();
@@ -360,10 +360,11 @@ export default function GroupView({ dirKey, rows, repoData, model }: {
360
360
  // #/group/<id>?task=draft-N 打开寻得回同一份(#86)。以前种在成员 scope、
361
361
  // 打开走 dir 路由——组语义在建任务这步就断了。
362
362
  const docId = docIdOf(scopeOf(board.id), id);
363
- // 与目录任务页同一条 defaultBody:已按槽位值渲染,不出现裸 {{背景}}
363
+ // 与目录任务页同一条口径:槽位已渲染、模板身份写进 frontmatter(编辑器据此锁骨架,#217)
364
+ const extra = { board: board.id, project: sel.key };
364
365
  saveDoc(docId, {
365
366
  title: '',
366
- body: withFrontmatter(body || tpl.defaultBody(), { board: board.id, project: sel.key }),
367
+ body: pick ? templateDraftBody(pick, extra) : templateDraftBody(tpl.defaultPick(), extra),
367
368
  });
368
369
  app.openPage?.({ groupId: board.id, task: id, name: '新任务' });
369
370
  };
@@ -514,7 +515,7 @@ export default function GroupView({ dirKey, rows, repoData, model }: {
514
515
  className={'btn small' + (tplFlyOpen ? ' is-open' : '')}
515
516
  title="按默认模板新建任务(▾ 选模板;携带本组语义)"
516
517
  disabled={!sel}
517
- onClick={() => createTask('')}
518
+ onClick={() => createTask()}
518
519
  >
519
520
  + 新增任务
520
521
  <span
@@ -576,11 +577,7 @@ export default function GroupView({ dirKey, rows, repoData, model }: {
576
577
  role="menuitem"
577
578
  onClick={() => {
578
579
  setTplFlyOpen(false);
579
- createTask(
580
- t.fallback
581
- ? ''
582
- : renderTemplateBody(t.body, t.values || {})
583
- );
580
+ createTask(t.fallback ? null : t);
584
581
  }}
585
582
  >
586
583
  {(t.id === tpl.defaultId && !t.fallback ? '✓ ' : '') + t.name}
@@ -12,6 +12,7 @@ import type { Model } from 'flexlayout-react';
12
12
  import {
13
13
  createDoc,
14
14
  detach,
15
+ promoteToMain,
15
16
  descOf,
16
17
  docsBindings,
17
18
  filterByScope,
@@ -26,7 +27,7 @@ import { useWikiNav } from '../doc/index.jsx';
26
27
  import type { DocOpenExtra } from '../doc/index.jsx';
27
28
  import { closeRightPanelOf } from '../../workspace.js';
28
29
  import { useApp } from '../../app-context.jsx';
29
- import { useDialog } from '../../components/popup/index.jsx';
30
+ import { RowMenu, useDialog } from '../../components/popup/index.jsx';
30
31
  import { useToast } from '../../components/toast/index.jsx';
31
32
  import { onDocsChanged } from '../../modules/md/doc-bus.js';
32
33
  import { resolveFollowedHost, type FollowedHost, type FollowResolution } from '../../refs/index.js';
@@ -194,6 +195,25 @@ export default function RefsPanel({ repoKey, repoName, boardKey, boardName, scop
194
195
  openDoc(refId);
195
196
  });
196
197
 
198
+ // ⋯ → 设为主篇(#144):服务端**换位**——目标从附加篇摘出、原主篇退回附加篇,
199
+ // 两边都不丢归属(老的 `docs bind` 会把原主篇甩成孤儿,面板不走那条)。
200
+ const setMain = (b: BindingRow) => guard(async () => {
201
+ if (b.main) return;
202
+ await promoteToMain(b);
203
+ const host = b.type === 'group' ? groupNameOf(b.repoKey) : repoNameOf(b.repoKey);
204
+ toast(`已设为「${host}」的主篇`);
205
+ reload();
206
+ });
207
+
208
+ const copyRefId = async (b: BindingRow) => {
209
+ try {
210
+ await navigator.clipboard.writeText(b.refId);
211
+ toast('已复制 refId');
212
+ } catch {
213
+ toast(b.refId);
214
+ }
215
+ };
216
+
197
217
  // ×:解绑归属(文档不删)
198
218
  const removeRow = (b: BindingRow) => guard(async () => {
199
219
  const label = labelOf(b);
@@ -292,6 +312,7 @@ export default function RefsPanel({ repoKey, repoName, boardKey, boardName, scop
292
312
  {badges.map((x, i) => (
293
313
  <span key={`${x.cls}:${i}`} className={`nx-refs-scope ${x.cls}`}>{x.text}</span>
294
314
  ))}
315
+ {b.main ? <span className="nx-refs-scope main-tag" title="主篇:这个宿主的介绍文档">主篇</span> : null}
295
316
  </span>
296
317
  <span className="nx-refs-row-text">{title}</span>
297
318
  </span>
@@ -299,20 +320,38 @@ export default function RefsPanel({ repoKey, repoName, boardKey, boardName, scop
299
320
  {b.note && <span className="nx-refs-row-sub">备注:{b.note}</span>}
300
321
  </button>
301
322
  <span className="nx-refs-row-acts">
302
- <button
303
- type="button"
304
- className="nx-refs-mini danger"
305
- title="解绑归属(文档不删)"
306
- onClick={() => removeRow(b)}
307
- >
308
- ×
309
- </button>
323
+ {/* ⋯:设为主篇 / 复制 refId(#144)。主篇行不给「设为主篇」,
324
+ 组内仓库描述(group_repo)没有主篇概念,也不给。 */}
325
+ {/* #147:解绑也收进 ⋯(行尾只留一个入口,少一个红色的 × 更清爽) */}
326
+ <RowMenu
327
+ items={[
328
+ b.main || b.type === 'group_repo' ? null : {
329
+ label: '设为主篇',
330
+ icon: <Icon name="star" size={13} title={undefined} />,
331
+ hint: '把它挪到主篇位;原主篇退回附加篇(不丢归属)',
332
+ onPick: () => setMain(b),
333
+ },
334
+ {
335
+ label: '复制 refId',
336
+ icon: <Icon name="link" size={13} title={undefined} />,
337
+ hint: b.refId,
338
+ onPick: () => copyRefId(b),
339
+ },
340
+ {
341
+ label: b.type === 'group_repo' ? '摘除组内描述' : '移出列表',
342
+ icon: <Icon name="back" size={13} title={undefined} />,
343
+ hint: '只解除归属,文档本身不删',
344
+ danger: true,
345
+ onPick: () => removeRow(b),
346
+ },
347
+ ]}
348
+ />
310
349
  </span>
311
350
  </div>
312
351
  );
313
352
  })}
314
353
  </div>
315
- <div className="nx-refs-note">点一行打开文档(编辑 / 保存在那一页);× 摘除归属,不删文档。</div>
354
+ <div className="nx-refs-note">点一行打开文档(编辑 / 保存在那一页);行尾 ⋯ 里可以设为主篇 / 移出列表(不删文档)。</div>
316
355
  {dialogNode}
317
356
  </div>
318
357
  );
@@ -39,6 +39,10 @@
39
39
  .nx-refs-row-wrap:hover{background:var(--soft,#F1F0EC)}
40
40
  .nx-refs-row-wrap .nx-refs-row{flex:1;min-width:0}
41
41
  .nx-refs-row-wrap .nx-refs-row:hover{background:transparent}
42
+ /* 主篇标签(#144):原来只有标题变绿,看不出「这是主篇」——补一枚明确的章 */
43
+ .nx-refs-scope.main-tag{
44
+ border-color:#2F6F5E66;background:#2F6F5E14;color:#2F6F5E;font-weight:600;
45
+ }
42
46
  .nx-refs-row-acts{
43
47
  display:flex;flex-direction:column;gap:1px;flex:none;
44
48
  padding:6px 4px 0 0;opacity:0;transition:opacity .12s;
@@ -1,8 +1,10 @@
1
1
  // 区块切换条(#143):仓库 / 参考仓库 / 文档 三块是**独立区块**,用横向按钮切换。
2
2
  //
3
3
  // 为什么不做同屏三段:一段一张表会拉出三倍高度,用户在「找某个仓库」时反而要多滚一屏;
4
- // 横向按钮把三块压成同一块屏幕,计数就在按钮上(当前分支下各有多少条),
5
- // 右侧统一放搜索框——切区块时搜索词保留(同一个分支内的检索不该被切块清掉)。
4
+ // 横向按钮把三块压成同一块屏幕,计数就在按钮上(当前分组下各有多少条)。
5
+ //
6
+ // #146:搜索框搬到上面那一行(分组信息条)——它是**全局检索**(三块一起搜、结果同屏
7
+ // 分段列出),不该跟着区块按钮走;这里只留切换。
6
8
  import type { ReactNode } from 'react';
7
9
  import { IconSearch } from './icons.jsx';
8
10
 
@@ -17,15 +19,35 @@ export interface BlockTab {
17
19
  disabled?: boolean;
18
20
  }
19
21
 
20
- export default function BlockTabs({ tabs, value, onChange, q, onQ, placeholder, hint, right }: {
22
+ /** 全局检索框(#146):放在分组信息条上,三块一起搜。 */
23
+ export function RpSearch({ value, onChange, placeholder, count }: {
24
+ value: string;
25
+ onChange: (v: string) => void;
26
+ placeholder?: string;
27
+ /** 命中总数(有关键词时显示) */
28
+ count?: number;
29
+ }) {
30
+ return (
31
+ <label className="rp-q" title="全局检索:仓库 / 参考仓库 / 文档 一起搜">
32
+ <IconSearch size={13} />
33
+ <input
34
+ value={value}
35
+ placeholder={placeholder || '搜索仓库 / 参考仓库 / 文档…'}
36
+ aria-label="全局检索"
37
+ onChange={(e) => onChange(e.target.value)}
38
+ />
39
+ {value ? <span className="rp-q-n">{count === undefined ? '' : count}</span> : null}
40
+ {value ? (
41
+ <button type="button" className="rp-q-x" title="清空检索" onClick={() => onChange('')}>×</button>
42
+ ) : null}
43
+ </label>
44
+ );
45
+ }
46
+
47
+ export default function BlockTabs({ tabs, value, onChange }: {
21
48
  tabs: BlockTab[];
22
49
  value: string;
23
50
  onChange: (id: string) => void;
24
- q: string;
25
- onQ: (v: string) => void;
26
- placeholder?: string;
27
- hint?: string;
28
- right?: ReactNode;
29
51
  }) {
30
52
  return (
31
53
  <div className="rp-blocks">
@@ -47,22 +69,6 @@ export default function BlockTabs({ tabs, value, onChange, q, onQ, placeholder,
47
69
  </button>
48
70
  ))}
49
71
  </div>
50
- <div className="rp-block-side">
51
- {hint ? <span className="rp-block-hint">{hint}</span> : null}
52
- {right}
53
- <label className="rp-q">
54
- <IconSearch size={13} />
55
- <input
56
- value={q}
57
- placeholder={placeholder || '按名称 / 路径 / 描述筛选…'}
58
- aria-label="筛选当前区块"
59
- onChange={(e) => onQ(e.target.value)}
60
- />
61
- {q ? (
62
- <button type="button" className="rp-q-x" title="清空筛选" onClick={() => onQ('')}>×</button>
63
- ) : null}
64
- </label>
65
- </div>
66
72
  </div>
67
73
  );
68
74
  }