nx-kv 0.68.1 → 0.68.3

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 (73) hide show
  1. package/CHANGELOG.md +58 -0
  2. package/package.json +1 -1
  3. package/src/core/db/seed-templates.ts +10 -50
  4. package/src/web/frontend/App.tsx +12 -0
  5. package/src/web/frontend/components/layout/vsc-crumbs.css +16 -9
  6. package/src/web/frontend/components/layout/vsc-crumbs.tsx +47 -25
  7. package/src/web/frontend/components/popup/index.tsx +4 -1
  8. package/src/web/frontend/components/popup/style.css +2 -0
  9. package/src/web/frontend/components/task-panel/task-page.tsx +1 -0
  10. package/src/web/frontend/components/task-panel/task-row.tsx +50 -21
  11. package/src/web/frontend/modules/md/fill-session.ts +36 -0
  12. package/src/web/frontend/modules/md/new-task-from-template.ts +22 -0
  13. package/src/web/frontend/modules/md/task-intent.ts +29 -0
  14. package/src/web/frontend/modules/prompts/render-template-body.ts +14 -0
  15. package/src/web/frontend/modules/prompts/template-preview.ts +62 -0
  16. package/src/web/frontend/page/dir/index.tsx +13 -3
  17. package/src/web/frontend/page/dir/task-beside.ts +64 -0
  18. package/src/web/frontend/page/dir/task.tsx +12 -24
  19. package/src/web/frontend/page/dir/use-auto-submit.ts +20 -0
  20. package/src/web/frontend/page/group/index.tsx +19 -3
  21. package/src/web/frontend/page/settings/style.css +12 -2
  22. package/src/web/frontend/page/templates/fill.tsx +128 -0
  23. package/src/web/frontend/page/templates/index.tsx +6 -0
  24. package/src/web/frontend/page/templates/manage.tsx +7 -33
  25. package/src/web/frontend/page/templates/style.css +32 -5
  26. package/src/web/frontend/page/templates/template-list.tsx +48 -68
  27. package/src/web/frontend/routes/templates.ts +10 -0
  28. package/src/web/frontend/styles-v2/dag.css +22 -1
  29. package/src/web/frontend/styles-v2/shell.css +16 -1
  30. package/src/web/public/assets/app-context-KCsdqNTq.js +1 -0
  31. package/src/web/public/assets/{bar-C-XvccT_.js → bar-DEY9q8mI.js} +1 -1
  32. package/src/web/public/assets/{button-Cs6w2CDi.js → button-BRGGaUcY.js} +1 -1
  33. package/src/web/public/assets/{composer-launch-DocQvHKh.js → composer-launch-DEHhs8k_.js} +1 -1
  34. package/src/web/public/assets/{composer-panel-DvUN4WhE.js → composer-panel-Cke_nbex.js} +1 -1
  35. package/src/web/public/assets/{dag-Bl0StA5e.js → dag-BvkJhdpX.js} +1 -1
  36. package/src/web/public/assets/dir-C8HhVpFz.js +1 -0
  37. package/src/web/public/assets/{doc-CKbuO1Gj.js → doc-R8KHVCxp.js} +1 -1
  38. package/src/web/public/assets/group-d9wqo1pL.js +1 -0
  39. package/src/web/public/assets/{index-DeuU-ww6.css → index-CUnLXQWJ.css} +1 -1
  40. package/src/web/public/assets/{index-BCtGuLkO.js → index-DqTSNBzX.js} +3 -3
  41. package/src/web/public/assets/manage-session-CuaL7QqQ.js +1 -0
  42. package/src/web/public/assets/{md-history-sxG54jJ_.js → md-history-BR2jLhFQ.js} +1 -1
  43. package/src/web/public/assets/{member-picker-CHX0nS0O.js → member-picker-BJ-Ucm-9.js} +1 -1
  44. package/src/web/public/assets/{popup-dBtYqEM1.js → popup-BdVXUaJk.js} +1 -1
  45. package/src/web/public/assets/{popup-BAvk7J7u.css → popup-CHK8uSG4.css} +1 -1
  46. package/src/web/public/assets/{progress-CPQSMxLp.js → progress-CLSIX544.js} +1 -1
  47. package/src/web/public/assets/{refs-Bzf1kVpx.js → refs-Cb9pmVsb.js} +1 -1
  48. package/src/web/public/assets/{reopen-text-B2d9SZi0.js → reopen-text-C3dnqygC.js} +1 -1
  49. package/src/web/public/assets/{repo-form-modal-geOSTx9x.js → repo-form-modal-awEPCcJK.js} +1 -1
  50. package/src/web/public/assets/{repos-BbKWW4no.js → repos-CIgKjolu.js} +1 -1
  51. package/src/web/public/assets/{route-crumb-CqDySF_k.js → route-crumb-DvXzznKm.js} +1 -1
  52. package/src/web/public/assets/{settings-Cy9N4Yuf.js → settings-BiqKrd8o.js} +1 -1
  53. package/src/web/public/assets/settings-CjXDi7qu.css +1 -0
  54. package/src/web/public/assets/task-C664y4Vd.js +14 -0
  55. package/src/web/public/assets/task-intent-CX5DZccN.js +1 -0
  56. package/src/web/public/assets/{task-Dcd2eA8B.css → task-j7fMfJUp.css} +1 -1
  57. package/src/web/public/assets/task-ops-D8L16-TP.js +2 -0
  58. package/src/web/public/assets/template-preview-CjQ-ucPt.js +1 -0
  59. package/src/web/public/assets/templates-BZ1EM7W4.js +10 -0
  60. package/src/web/public/assets/templates-DiEKBY-m.css +1 -0
  61. package/src/web/public/assets/{tool-bar-DpfJRjFG.js → tool-bar-CAMqYt5j.js} +1 -1
  62. package/src/web/public/assets/{use-rail-drag-DcUzHeV_.js → use-rail-drag-C3GpkThI.js} +1 -1
  63. package/src/web/public/index.html +12 -12
  64. package/src/web/frontend/page/templates/scope-chips.tsx +0 -237
  65. package/src/web/public/assets/app-context-CngKv8Tc.js +0 -1
  66. package/src/web/public/assets/dir-BgkZkxiK.js +0 -1
  67. package/src/web/public/assets/group-BkBWu0VU.js +0 -1
  68. package/src/web/public/assets/manage-session-CS8UvmUd.js +0 -1
  69. package/src/web/public/assets/settings-d2ah_h6O.css +0 -1
  70. package/src/web/public/assets/task-DQNhVFdJ.js +0 -14
  71. package/src/web/public/assets/task-ops-CdBj-EnL.js +0 -2
  72. package/src/web/public/assets/templates-B-xUIUa6.js +0 -10
  73. package/src/web/public/assets/templates-CwYDIBYn.css +0 -1
@@ -16,6 +16,8 @@ import DagEditor from '../../components/task-panel/dag-editor.jsx';
16
16
  import { findOpenPanel, openPanel } from '../../workspace.js';
17
17
  import { openTemplateEditor } from '../../panels.jsx';
18
18
  import { docIdOf, nextDraftId, saveDoc, scopeOf } from '../../modules/md/doc-store.js';
19
+ import { templateDraftBody } from '../../modules/prompts/template-preview.js';
20
+ import { startFillIfSlotted } from '../../modules/md/new-task-from-template.js';
19
21
  import { putManageSession } from '../../modules/md/manage-session.js';
20
22
  import { useTemplatesFor } from '../../modules/md/use-templates.js';
21
23
  import TaskPage from '../../components/task-panel/task-page.jsx';
@@ -185,14 +187,20 @@ export default function DirPanel({ dirKey }: DirPanelProps) {
185
187
  ? menuTemplates.map((t: PromptTemplate) => ({
186
188
  label: (t.id === tpl?.defaultId ? '✓ ' : '') + t.name,
187
189
  icon: 'list',
188
- onClick: () => newDraft(String(t.body || '')),
190
+ // #191:带 {{槽位}} → 先去参数填写页;无槽位 → 纯文本草稿直进编辑器
191
+ onClick: () => {
192
+ if (startFillIfSlotted(t, { topic: topicKeyHere, dirKey: dirKey || '' }, app)) return;
193
+ newDraft(templateDraftBody(t));
194
+ },
189
195
  }))
190
196
  : [{
191
197
  label: '按默认模板新建一页',
192
198
  icon: 'list',
193
199
  onClick: () => {
194
200
  const p = tpl ? tpl.defaultPick() : null;
195
- newDraft(p ? p.body : '');
201
+ const full = (tpl?.templates || []).find((t) => t.id === (p?.id || tpl?.defaultId));
202
+ if (full && startFillIfSlotted(full as any, { topic: topicKeyHere, dirKey: dirKey || '' }, app)) return;
203
+ newDraft(p && p.id ? templateDraftBody(p) : (p ? p.body : ''));
196
204
  },
197
205
  }]),
198
206
  'sep',
@@ -258,7 +266,9 @@ export default function DirPanel({ dirKey }: DirPanelProps) {
258
266
  tplMenuItems={tplMenuItems}
259
267
  onNew={() => {
260
268
  const p = tpl ? tpl.defaultPick() : null;
261
- newDraft(p ? p.body : '');
269
+ const full = (tpl?.templates || []).find((t) => t.id === (p?.id || tpl?.defaultId));
270
+ if (full && startFillIfSlotted(full, { topic: topicKeyHere, dirKey: dirKey || '' }, app)) return;
271
+ newDraft(p && p.id ? templateDraftBody(p) : (p ? p.body : ''));
262
272
  }}
263
273
  onOpenRow={(r) => openTask(r.task.id)}
264
274
  onImportFile={(f) => void importMd(f)}
@@ -0,0 +1,64 @@
1
+ // 旁路(beside)三件套(#259 从任务页主体抽出,行数门禁):打开来源原文 / 关闭自己 /
2
+ // 面包屑「预览原文」。都只是 openBesideMain / deleteTab 的薄封装,状态零自有。
3
+ import { useCallback } from 'react';
4
+ import type { Model } from 'flexlayout-react';
5
+ import { Actions } from 'flexlayout-react';
6
+ import { openBesideMain } from '../../workspace.js';
7
+ import type { ParentRef } from './task-utils.js';
8
+
9
+ export interface BesideOpsArgs {
10
+ parentRef: ParentRef | null;
11
+ model: Model | null;
12
+ appModel: Model | null;
13
+ toast: (msg: string) => void;
14
+ isDraft: boolean;
15
+ task: string;
16
+ topicKey: string;
17
+ tabId?: string;
18
+ }
19
+
20
+ export function useBesideOps(args: BesideOpsArgs) {
21
+ const { parentRef, model, appModel, toast, isDraft, task, topicKey, tabId } = args;
22
+
23
+ const openParentBeside = useCallback(() => {
24
+ if (!parentRef) {
25
+ toast('这条任务没有可定位的原文');
26
+ return;
27
+ }
28
+ const m = model || appModel;
29
+ if (!m) return;
30
+ openBesideMain(m, {
31
+ component: 'page',
32
+ name: parentRef.name || `原文 ${parentRef.task}`,
33
+ config: { dirKey: parentRef.dirKey, task: String(parentRef.task) },
34
+ });
35
+ }, [parentRef, model, appModel, toast]);
36
+
37
+ const closeBesideSelf = useCallback(() => {
38
+ const m = model || appModel;
39
+ if (!m || !tabId) return;
40
+ m.doAction(Actions.deleteTab(tabId));
41
+ }, [model, appModel, tabId]);
42
+
43
+ // 面包屑任务段的「预览原文」:评论任务跳它的来源原文;普通任务把自己的原文
44
+ // 旁路打开(openBesideMain 会先收掉旧旁路,同一时刻只有一块)。草稿没有原文。
45
+ const previewOriginal = useCallback(() => {
46
+ if (isDraft) {
47
+ toast('草稿还没有原文');
48
+ return;
49
+ }
50
+ if (parentRef) {
51
+ openParentBeside();
52
+ return;
53
+ }
54
+ const m = model || appModel;
55
+ if (!m) return;
56
+ openBesideMain(m, {
57
+ component: 'page',
58
+ name: `原文 #${task}`,
59
+ config: { dirKey: topicKey, task: String(task) },
60
+ });
61
+ }, [isDraft, parentRef, openParentBeside, model, appModel, toast, task, topicKey]);
62
+
63
+ return { openParentBeside, closeBesideSelf, previewOriginal };
64
+ }
@@ -9,7 +9,6 @@
9
9
  import VscCrumbs from '../../components/layout/vsc-crumbs.jsx';
10
10
  import { useCallback, useEffect, useMemo, useRef, useState } from 'react';
11
11
  import type { MouseEvent as ReactMouseEvent, ReactNode } from 'react';
12
- import { Actions } from 'flexlayout-react';
13
12
  import type { Model } from 'flexlayout-react';
14
13
  import { getTaskAttachments, previewTask } from './api.js';
15
14
  import { useToast } from '../../components/toast/index.jsx';
@@ -23,7 +22,6 @@ import { openComposer } from '../../components/md/composer/composer-launch.js';
23
22
  import ShortcutSheet from '../../components/md/shell/shortcut-sheet.jsx';
24
23
  import { TaskChainModal as TaskChainModalRaw } from '../../components/md/standalone/task-chain.jsx';
25
24
  import { useApp } from '../../app-context.jsx';
26
- import { openBesideMain } from '../../workspace.js';
27
25
  import { persistAtt } from '../../components/md/attachments/attachments.js';
28
26
  import type { Attachment } from '../../components/md/attachments/attach-common.js';
29
27
  import type { AttachAreaHandle } from '../../components/md/attachments/attach-area.jsx';
@@ -32,8 +30,9 @@ import {
32
30
  liveBodyBlocks,
33
31
  titleFromMd,
34
32
  stripTitleHeading,
35
- withFrontmatter,
36
33
  } from '../../modules/md/md-parse.js';
34
+ import { templateDraftBody } from '../../modules/prompts/template-preview.js';
35
+ import { useAutoSubmit } from './use-auto-submit.js';
37
36
  import {
38
37
  docIdOf,
39
38
  getDoc,
@@ -51,6 +50,7 @@ import { useAck } from './task-ack.js';
51
50
  import { useTaskActions } from './task-actions.js';
52
51
  import { useFeedback } from './task-feedback.js';
53
52
  import { useDerivedCtx } from './task-derived-ctx.js';
53
+ import { useBesideOps } from './task-beside.js';
54
54
  import { PreviewModal } from './task-preview-modal.jsx';
55
55
  import { DockPanel } from './task-dock-panel.jsx';
56
56
  import { StatusBar } from './task-status-bar.jsx';
@@ -213,7 +213,7 @@ export default function PagePanel({ dirKey, groupId, task, beside = false, tabId
213
213
  getDoc(id, {
214
214
  title: '',
215
215
  body: tpl
216
- ? withFrontmatter(tpl.defaultPick().body, groupAnchored ? { board: groupId } : {})
216
+ ? templateDraftBody(tpl.defaultPick(), groupAnchored ? { board: groupId } : {})
217
217
  : '',
218
218
  });
219
219
  } else if (taskRow) getDoc(id, { title: titleFromMd(taskRow.text), body: taskRow.text });
@@ -229,6 +229,9 @@ export default function PagePanel({ dirKey, groupId, task, beside = false, tabId
229
229
  });
230
230
  const { composeText, submit, importMd, delTask, canComplete, canCancel, closeTask, canPlan, togglePlan, addFiles, newTask, cloneCur, forkCur, openProgress, openAttachPanel } = actions;
231
231
 
232
+ // #191「直接提交」:参数页留下的一次性意图 → doc 就绪后自动 submit(详见 hook)
233
+ useAutoSubmit(id, doc, isDraft, submit);
234
+
232
235
  const feedback = useFeedback({
233
236
  doc, isDraft, task, taskRow, topicKey, topic, dirKey,
234
237
  groupAnchored, groupId, app, model: model || null, tabId, refreshLocal,
@@ -342,25 +345,10 @@ export default function PagePanel({ dirKey, groupId, task, beside = false, tabId
342
345
  placeSelMenu('task', text, last.right - 60, last.bottom + 8, blockRange ? { blockRange } : {});
343
346
  };
344
347
 
345
- const openParentBeside = useCallback(() => {
346
- if (!parentRef) {
347
- toast('这条任务没有可定位的原文');
348
- return;
349
- }
350
- const m = model || app.model;
351
- if (!m) return;
352
- openBesideMain(m, {
353
- component: 'page',
354
- name: parentRef.name || `原文 ${parentRef.task}`,
355
- config: { dirKey: parentRef.dirKey, task: String(parentRef.task) },
356
- });
357
- }, [parentRef, model, app.model, toast]);
358
-
359
- const closeBesideSelf = useCallback(() => {
360
- const m = model || app.model;
361
- if (!m || !tabId) return;
362
- m.doAction(Actions.deleteTab(tabId));
363
- }, [model, app.model, tabId]);
348
+ // 旁路三件套(打开来源原文 / 关闭自己 / 面包屑预览原文)抽到 task-beside.ts(行数门禁)
349
+ const { openParentBeside, closeBesideSelf, previewOriginal } = useBesideOps({
350
+ parentRef, model: model ?? null, appModel: app.model ?? null, toast, isDraft, task, topicKey, tabId,
351
+ });
364
352
 
365
353
  const pickAtt = (accept: string) => {
366
354
  if (fileAttRef.current) fileAttRef.current.accept = accept;
@@ -410,7 +398,7 @@ export default function PagePanel({ dirKey, groupId, task, beside = false, tabId
410
398
  {/* #254:顶条换 VS Code 式面包屑(命名空间 > 组/目录 > 任务;点段弹同级、
411
399
  悬浮出复制钮)。不再显示标题行——原 mdw-path 的两个信号
412
400
  (未保存 / 目录已不存在)下沉到这一行保留。 */}
413
- <VscCrumbs />
401
+ <VscCrumbs onPreview={previewOriginal} />
414
402
  {dirty ? <span className="mdw-top-note">未保存</span> : null}
415
403
  {topic?.cwdExists === false && (
416
404
  <span
@@ -0,0 +1,20 @@
1
+ // 参数填写页「直接提交」的一次性意图(#151 / #191)。
2
+ //
3
+ // 参数页渲染出纯文本草稿 → 种进 doc-store → 开到任务编辑页 → 留一个一次性 intent;
4
+ // 本 hook 在编辑页 mount 时取走意图,等 doc 就绪后自动 submit 一次(落库为待领取任务)。
5
+ // 取后即删:StrictMode 双跑 / 重复挂载只会消费一次,不会双提交。
6
+ import { useEffect, useRef } from 'react';
7
+ import type { DocState } from './task-utils.js';
8
+ import { takeTaskIntent } from '../../modules/md/task-intent.js';
9
+
10
+ export function useAutoSubmit(id: string, doc: DocState | null, isDraft: boolean, submit: () => unknown): void {
11
+ const autoSubmitRef = useRef(false);
12
+ useEffect(() => {
13
+ if (takeTaskIntent(id)?.submit) autoSubmitRef.current = true;
14
+ }, [id]);
15
+ useEffect(() => {
16
+ if (!autoSubmitRef.current || !doc || !isDraft) return;
17
+ autoSubmitRef.current = false;
18
+ submit();
19
+ }, [doc, isDraft, submit]);
20
+ }
@@ -37,7 +37,9 @@ import { openTemplateEditor } from '../../panels.jsx';
37
37
  import GetLoopMembersMenu from '../../components/repos/get-loop-members.js';
38
38
  import GetLoopModal from '../../components/repos/get-loop-modal.js';
39
39
  import { docIdOf, nextDraftId, saveDoc, scopeOf } from '../../modules/md/doc-store.js';
40
- import { parseFrontmatter, withFrontmatter } from '../../modules/md/md-parse.js';
40
+ import { parseFrontmatter } from '../../modules/md/md-parse.js';
41
+ import { templateDraftBody } from '../../modules/prompts/template-preview.js';
42
+ import { startFillIfSlotted } from '../../modules/md/new-task-from-template.js';
41
43
  import { sortTasksForDisplay } from '../../modules/board/board-view.js';
42
44
  import { putManageSession } from '../../modules/md/manage-session.js';
43
45
  import { useTemplates, useTemplatesFor } from '../../modules/md/use-templates.js';
@@ -238,9 +240,23 @@ export default function GroupView({ dirKey, rows, repoData, model }: {
238
240
 
239
241
  // 组里建任务:草稿预写 frontmatter(board + 默认归属项目),提交时编辑页的工具区
240
242
  // 可改归属项目(限本组成员),按它路由进对应项目的队列。
241
- const createTask = (pick?: { id?: string; body?: unknown } | null) => {
243
+ const createTask = (pick?: { id?: string; body?: unknown; values?: Record<string, unknown> | null } | null) => {
242
244
  if (!board) return;
243
245
  if (!sel) return toast('这个组还没有成员——先「添加成员」,再建任务');
246
+ // #191:带 {{槽位}} 的模板先去参数页(携带组 + 项目上下文);无槽位走原草稿路径。
247
+ const chosen = pick || (tpl?.templates || []).find((t) => t.id === tpl.defaultId) || null;
248
+ if (chosen && startFillIfSlotted(
249
+ chosen as any,
250
+ {
251
+ topic: sel.topicKey || '',
252
+ group: board.key || '',
253
+ repo: sel.key || '',
254
+ groupId: board.id,
255
+ board: board.id,
256
+ project: sel.key,
257
+ },
258
+ app,
259
+ )) return;
244
260
  const id = nextDraftId();
245
261
  // 草稿 doc 种在**组 scope**:从 #/group/<id>?task=draft-N 打开寻得回同一份(#86)
246
262
  const docId = docIdOf(scopeOf(board.id), id);
@@ -248,7 +264,7 @@ export default function GroupView({ dirKey, rows, repoData, model }: {
248
264
  const extra = { board: board.id, project: sel.key };
249
265
  saveDoc(docId, {
250
266
  title: '',
251
- body: withFrontmatter(pick ? String(pick.body || '') : tpl.defaultPick().body, extra),
267
+ body: pick ? templateDraftBody(pick, extra) : templateDraftBody(tpl.defaultPick(), extra),
252
268
  });
253
269
  app.openPage?.({ groupId: board.id, task: id, name: '新任务' });
254
270
  };
@@ -39,7 +39,8 @@
39
39
  background: var(--paper);
40
40
  color: var(--ink);
41
41
  font-weight: 650;
42
- box-shadow: 0 1px 2px rgba(20, 22, 26, .07);
42
+ /* #260 验收(材质):白底胶囊加发丝环,浮起但不脱手 */
43
+ box-shadow: 0 1px 2px rgba(20, 22, 26, .07), 0 0 0 1px var(--line);
43
44
  }
44
45
  .setp-navitem .ic { color: var(--mid); }
45
46
  .setp-navitem.on .ic { color: var(--ink); }
@@ -49,7 +50,7 @@
49
50
  flex: 1;
50
51
  min-width: 0;
51
52
  overflow: auto;
52
- padding: 12px 16px 18px;
53
+ padding: 14px 18px 20px;
53
54
  display: flex;
54
55
  flex-direction: column;
55
56
  gap: 10px;
@@ -60,6 +61,9 @@
60
61
  letter-spacing: 1px;
61
62
  color: var(--mid);
62
63
  text-transform: uppercase;
64
+ /* #260 验收(层级):分区标题压一条细线,与内容拉开 */
65
+ padding-bottom: 6px;
66
+ border-bottom: 1px solid var(--line);
63
67
  }
64
68
 
65
69
  .setp-row {
@@ -68,6 +72,12 @@
68
72
  gap: 10px;
69
73
  min-height: 26px;
70
74
  justify-content: space-between;
75
+ /* #260 验收(层级):相邻行之间发丝分隔(中间隔了别的元素就不画) */
76
+ padding: 3px 0;
77
+ }
78
+ .setp-row + .setp-row {
79
+ border-top: 1px solid var(--line);
80
+ padding-top: 9px;
71
81
  }
72
82
  .setp-row > span:first-child { color: var(--ink-2); }
73
83
  .setp-row .toggle { flex: none; }
@@ -0,0 +1,128 @@
1
+ // 参数填写中间页(#151):从「新建任务」下拉点带 {{槽位}} 的模板时先到这里。
2
+ //
3
+ // 槽位只活到「任务正文生成前」——这一页把模板正文渲染成**纯文本**草稿,
4
+ // 不再往任务里写 template: frontmatter、编辑器零槽位概念。两个出口:
5
+ // · 直接提交:进任务页后自动 submit() 落库为待领取任务;
6
+ // · 进入编辑页:进任务页保留草稿(不落库)。
7
+ // 所有参数都是可选长编辑框,留空按空串填充。
8
+ import { useMemo, useState } from 'react';
9
+ import RouteBreadcrumb from '../../components/layout/route-crumb.jsx';
10
+ import { popRoute } from '../../components/layout/route-history.js';
11
+ import { Button } from '../../components/button/index.jsx';
12
+ import { Icon } from '../../components/icons.jsx';
13
+ import { useApp } from '../../app-context.jsx';
14
+ import { useToast } from '../../components/toast/index.jsx';
15
+ import { docIdOf, nextDraftId, saveDoc, scopeOf } from '../../modules/md/doc-store.js';
16
+ import { titleFromMd } from '../../modules/md/md-parse.js';
17
+ import { getFillSession, dropFillSession } from '../../modules/md/fill-session.js';
18
+ import { setTaskIntent } from '../../modules/md/task-intent.js';
19
+ import { templateDraftBody, templateSlots } from '../../modules/prompts/template-preview.js';
20
+ import './style.css';
21
+
22
+ interface FillPanelProps {
23
+ config?: Record<string, any>;
24
+ }
25
+
26
+ export default function TemplateFillPanel({ config }: FillPanelProps) {
27
+ const app = useApp();
28
+ const toast = useToast();
29
+ const session = useMemo(() => getFillSession(config?.id), [config?.id]);
30
+ const tmpl = useMemo(
31
+ () => (app.tpl?.templates || []).find((t) => t.id === (session || {})?.templateId) || null,
32
+ [app.tpl?.templates, session],
33
+ );
34
+ const slots = useMemo(() => (tmpl ? templateSlots(tmpl.body) : []), [tmpl]);
35
+ const [values, setValues] = useState<Record<string, string>>(() => {
36
+ const out: Record<string, string> = {};
37
+ for (const s of slots) out[s] = String((tmpl?.values || {})[s] ?? '');
38
+ return out;
39
+ });
40
+
41
+ if (!session || !tmpl) {
42
+ return (
43
+ <div className="rp-page tpl-fill-page">
44
+ <RouteBreadcrumb />
45
+ <div className="pad muted">参数会话已失效——请从「新建任务」下拉重新选择模板。</div>
46
+ </div>
47
+ );
48
+ }
49
+
50
+ const setValue = (key: string, val: string) => setValues((m) => ({ ...m, [key]: val }));
51
+
52
+ /** 渲染正文 → 种草稿 → 开任务页。submit=true 时留一次性 intent 触发自动提交。 */
53
+ const proceed = (submit: boolean) => {
54
+ const extra: Record<string, unknown> = {};
55
+ if (session.board) extra.board = session.board;
56
+ if (session.project) extra.project = session.project;
57
+ const body = templateDraftBody(
58
+ { id: tmpl.id, body: tmpl.body, values: tmpl.values },
59
+ extra,
60
+ values,
61
+ );
62
+ const task = nextDraftId();
63
+ const rootKey = session.groupId || session.dirKey || '';
64
+ const docId = docIdOf(scopeOf(rootKey), task);
65
+ // 标题从渲染后的正文首行反推(模板常以 `# {{标题}}` 开头)——否则编辑页显示「无标题」
66
+ saveDoc(docId, { title: titleFromMd(body, ''), body });
67
+ // intent key 必须与任务页取用侧一致:task.tsx 用 docIdOf(scope, task) 取,
68
+ // 若存裸 task id 就永远取不到——「直接提交」会退化成「进入编辑页」(#156 的坑)。
69
+ if (submit) setTaskIntent(docId, { submit: true });
70
+ dropFillSession(config?.id);
71
+ const spec = session.groupId
72
+ ? { groupId: session.groupId, task, name: '新任务' }
73
+ : { dirKey: session.dirKey, task, name: '新任务' };
74
+ app.openPage?.(spec);
75
+ toast(submit ? '正在提交任务…' : '已进入草稿编辑');
76
+ };
77
+
78
+ return (
79
+ <div className="rp-page tpl-fill-page">
80
+ <RouteBreadcrumb />
81
+ <div className="page-head">
82
+ <div className="title-block">
83
+ <h2><Icon name="list" size={16} /> 填写模板参数</h2>
84
+ <p className="muted tpl-head-note">
85
+ 「{tmpl.name}」· 全部可选,留空即为空白。生成的是纯文本任务,编辑页不会再出现槽位框。
86
+ </p>
87
+ </div>
88
+ <div className="acts">
89
+ <Button
90
+ variant="secondary"
91
+ small
92
+ onClick={() => app.onNavigate?.(popRoute() || '#/templates')}
93
+ >
94
+ <Icon name="back" size={13} /> 返回
95
+ </Button>
96
+ </div>
97
+ </div>
98
+
99
+ <div className="tpl-fill-body">
100
+ {slots.length === 0 ? (
101
+ <div className="muted tpl-fill-empty">这条模板没有参数槽位,可直接进入任务编辑。</div>
102
+ ) : (
103
+ slots.map((key) => (
104
+ <label key={key} className="tpl-fill-field">
105
+ <span className="tpl-fill-label">{key}</span>
106
+ <textarea
107
+ className="tpl-fill-input"
108
+ value={values[key] ?? ''}
109
+ placeholder={`填写「${key}」(可留空)`}
110
+ onChange={(e) => setValue(key, e.target.value)}
111
+ rows={4}
112
+ />
113
+ </label>
114
+ ))
115
+ )}
116
+ </div>
117
+
118
+ <div className="tpl-fill-foot">
119
+ <Button variant="secondary" onClick={() => proceed(false)}>
120
+ <Icon name="edit" size={13} /> 进入编辑页(草稿)
121
+ </Button>
122
+ <Button variant="primary" onClick={() => proceed(true)}>
123
+ <Icon name="check" size={13} /> 直接提交
124
+ </Button>
125
+ </div>
126
+ </div>
127
+ );
128
+ }
@@ -14,6 +14,7 @@ import { clearHistory, pushHistory, redoHistory, undoHistory } from '../../modul
14
14
  import { popRoute } from '../../components/layout/route-history.js';
15
15
  import TemplateListPanel from './template-list.jsx';
16
16
  import TemplateManagePanel from './manage.jsx';
17
+ import TemplateFillPanel from './fill.jsx';
17
18
  import '../../modules/md/style.css';
18
19
  import './style.css';
19
20
 
@@ -194,6 +195,11 @@ export default function TemplatePanel({ config, model, tabId }: TemplatePanelPro
194
195
  return <TemplateManagePanel config={cfg} />;
195
196
  }
196
197
 
198
+ // #151/#191:参数填写中间页(带 {{槽位}} 的模板先填值,再生成纯文本草稿)
199
+ if (mode === 'fill') {
200
+ return <TemplateFillPanel config={cfg} />;
201
+ }
202
+
197
203
  // #142:关闭/创建后回到来处面板,不要 deleteTab 把 maincontent 拆空。
198
204
  const leaveEditor = () => {
199
205
  const prev = popRoute();
@@ -1,7 +1,7 @@
1
- // 主题级任务模板管理(#151):从「新建任务」下拉的「管理模板…」进来,只管这个
2
- // topic 下可见的模板。filter 绑定可见行(不匹配即隐藏)、ScopeChips 改可见范围、
3
- // 拖拽改顺序(落库走 template.reorder)。参考自定义工具栏的编排面板,但更贴
4
- // 数据列表:一行一条,信息密度优先。
1
+ // 主题级任务模板管理(#151 / #191):从「新建任务」下拉的「管理模板…」进来,
2
+ // 只管这个 topic 下可见的模板。#191 起可见范围不再手动配置——按 topic 维度列出
3
+ // 本主题模板,支持 filter / 拖拽改顺序(template.reorder)/ 编辑 / 设默认 / 删除。
4
+ // 参考自定义工具栏的编排面板,但更贴数据列表:一行一条,信息密度优先。
5
5
  import { useMemo, useState } from 'react';
6
6
  import RouteBreadcrumb from '../../components/layout/route-crumb.jsx';
7
7
  import { Button } from '../../components/button/index.jsx';
@@ -13,7 +13,6 @@ import { filterByKeyword } from '../../modules/list-filter.js';
13
13
  import { useTemplatesFor } from '../../modules/md/use-templates.js';
14
14
  import { getManageSession } from '../../modules/md/manage-session.js';
15
15
  import type { PromptTemplate, TemplatesApi } from '../../types.js';
16
- import ScopeChips from './scope-chips.jsx';
17
16
  import './style.css';
18
17
 
19
18
  interface ManagePanelProps {
@@ -33,15 +32,10 @@ export default function TemplateManagePanel({ config }: ManagePanelProps) {
33
32
  const [q, setQ] = useState('');
34
33
  const [dragId, setDragId] = useState<string | null>(null);
35
34
  const [overId, setOverId] = useState<string | null>(null);
36
- const [scopeOpenId, setScopeOpenId] = useState<string | null>(null);
37
35
  const [busy, setBusy] = useState(false);
38
36
 
39
37
  const rows = scoped.templates || [];
40
- const shown = filterByKeyword(rows, q, (t) => [
41
- t.name,
42
- t.body,
43
- (t.scope || []).join(' '),
44
- ]);
38
+ const shown = filterByKeyword(rows, q, (t) => [t.name, t.body]);
45
39
 
46
40
  const act = async (fn: () => Promise<unknown>, ok?: string) => {
47
41
  if (busy) return;
@@ -91,7 +85,7 @@ export default function TemplateManagePanel({ config }: ManagePanelProps) {
91
85
  <div className="title-block">
92
86
  <h2><Icon name="gear" size={16} /> 管理模板 · {label}</h2>
93
87
  <p className="muted tpl-head-note">
94
- 只显示本主题可见的模板。拖动左侧把手调整顺序,点图标改可见范围;搜索框会同步隐藏不匹配的行。
88
+ 这里管理本主题的模板:拖动左侧把手调整顺序,编辑正文 / 设默认 / 删除。搜索框会同步隐藏不匹配的行。
95
89
  </p>
96
90
  </div>
97
91
  <div className="acts">
@@ -105,7 +99,7 @@ export default function TemplateManagePanel({ config }: ManagePanelProps) {
105
99
  <ListSearch
106
100
  value={q}
107
101
  onChange={setQ}
108
- placeholder="搜索名称 / 正文 / 可见范围…"
102
+ placeholder="搜索名称 / 正文…"
109
103
  title="过滤本主题模板"
110
104
  count={shown.length}
111
105
  className="wide"
@@ -151,19 +145,8 @@ export default function TemplateManagePanel({ config }: ManagePanelProps) {
151
145
  {isDefault && <span className="tpl-badge">默认</span>}
152
146
  {t.builtin && <span className="tpl-badge soft">内置</span>}
153
147
  </div>
154
- {(t.scope || []).length > 0 && !scopeOpenId && (
155
- <div className="tpl-mng-scope-sum muted">可见:{(t.scope || []).join(' / ')}</div>
156
- )}
157
148
  </div>
158
149
  <div className="tpl-mng-acts">
159
- <button
160
- type="button"
161
- className="iconbtn"
162
- title="可见范围"
163
- onClick={() => setScopeOpenId(scopeOpenId === t.id ? null : t.id)}
164
- >
165
- <Icon name="globe" size={14} />
166
- </button>
167
150
  <button
168
151
  type="button"
169
152
  className="iconbtn"
@@ -195,15 +178,6 @@ export default function TemplateManagePanel({ config }: ManagePanelProps) {
195
178
  </button>
196
179
  )}
197
180
  </div>
198
- {scopeOpenId === t.id && (
199
- <div className="tpl-mng-scope">
200
- <ScopeChips
201
- scope={t.scope}
202
- originTopic={(t as unknown as { originTopic?: string }).originTopic}
203
- onChange={(next: string[]) => tpl!.update(t.id, { scope: next })}
204
- />
205
- </div>
206
- )}
207
181
  </div>
208
182
  );
209
183
  })}
@@ -21,12 +21,24 @@
21
21
  .tpl-badge.soft{background:var(--soft,#F1F0EC);color:var(--mid,#8A8578);border-color:var(--line,#E4E2DC)}
22
22
  /* 全局 .grow 有 max-width:340px(推右会停在半路)——卡片里要真推到右缘 */
23
23
  .tpl-card-grow{flex:1 1 auto;min-width:0;max-width:none}
24
- .tpl-card-acts{display:flex;align-items:center;gap:6px;flex-wrap:wrap;justify-content:flex-end}
24
+ .tpl-card-acts{display:flex;align-items:flex-start;gap:10px;flex-wrap:wrap;justify-content:flex-end}
25
+ /* #191:右侧操作按钮改成「上图标 + 下小文字」——比纯图标更易扫读 */
26
+ .tpl-act{
27
+ display:inline-flex;flex-direction:column;align-items:center;gap:3px;
28
+ min-width:46px;padding:5px 6px;border:1px solid transparent;border-radius:8px;
29
+ background:transparent;color:var(--mid,#8A8578);cursor:pointer;line-height:1;
30
+ transition:background .14s ease,color .14s ease,border-color .14s ease;
31
+ }
32
+ .tpl-act span{font-size:10.5px;white-space:nowrap}
33
+ .tpl-act:hover:not(:disabled){
34
+ background:var(--soft,#F1F0EC);color:var(--ink,#222);border-color:var(--line,#E4E2DC);
35
+ }
36
+ .tpl-act.is-on{background:var(--mdw-accent-soft,#E8F2EE);color:var(--mdw-accent,#2F6F5E)}
37
+ .tpl-act:disabled{opacity:.45;cursor:not-allowed}
25
38
  .tpl-card-sum{
26
39
  font-size:11.5px;color:var(--ink-2,#4B515A);line-height:1.6;
27
40
  overflow:hidden;display:-webkit-box;-webkit-line-clamp:2;-webkit-box-orient:vertical;
28
41
  }
29
- .tpl-card-scope{padding-top:6px;border-top:1px dashed var(--line,#E4E2DC)}
30
42
  .tpl-preview{
31
43
  display:flex;flex-direction:column;gap:6px;margin-top:2px;
32
44
  padding:9px 11px;border:1px dashed var(--line,#E4E2DC);border-radius:8px;
@@ -40,6 +52,24 @@
40
52
  background:var(--soft,#F1F0EC);border:1px solid var(--line,#E4E2DC);
41
53
  }
42
54
 
55
+ /* ── #191 参数填写中间页(ef449ea 曾连样式一起删,本轮恢复) ───────── */
56
+ .tpl-fill-page{gap:12px}
57
+ .tpl-fill-page .page-head h2{display:flex;align-items:center;gap:7px}
58
+ .tpl-fill-body{
59
+ display:flex;flex-direction:column;gap:14px;min-width:0;max-width:720px;
60
+ padding:14px;border:1px solid var(--line,#E4E2DC);border-radius:10px;background:var(--paper,#fff);
61
+ }
62
+ .tpl-fill-field{display:flex;flex-direction:column;gap:6px;min-width:0}
63
+ .tpl-fill-label{font-size:12px;font-weight:600;color:var(--ink-2,#4B515A)}
64
+ .tpl-fill-input{
65
+ width:100%;resize:vertical;min-height:84px;padding:8px 10px;box-sizing:border-box;
66
+ font:400 12.5px/1.6 inherit;color:var(--ink,#222);background:var(--paper,#fff);
67
+ border:1px solid var(--line,#E4E2DC);border-radius:8px;
68
+ }
69
+ .tpl-fill-input:focus{outline:none;border-color:var(--mdw-accent-line,#B7D4C8)}
70
+ .tpl-fill-empty{padding:8px 0}
71
+ .tpl-fill-foot{display:flex;gap:8px;justify-content:flex-end;max-width:720px}
72
+
43
73
  /* ── #151 主题级模板管理页 ─────────────────────────────────────────── */
44
74
  .tpl-mng-page{gap:12px}
45
75
  .tpl-mng-page .page-head h2{display:flex;align-items:center;gap:7px}
@@ -56,10 +86,7 @@
56
86
  .tpl-mng-main{min-width:0}
57
87
  .tpl-mng-line{display:flex;align-items:center;gap:6px;flex-wrap:wrap;min-width:0}
58
88
  .tpl-mng-name{font-size:12.5px;font-weight:600;color:var(--ink,#222)}
59
- .tpl-mng-scope-sum{font-size:10.5px;margin-top:3px;overflow:hidden;text-overflow:ellipsis;white-space:nowrap}
60
89
  .tpl-mng-acts{display:flex;align-items:center;gap:2px}
61
- .tpl-mng-scope{grid-column:1/-1;padding-top:8px;border-top:1px dashed var(--line,#E4E2DC)}
62
-
63
90
  /* #151 图标化:图标按钮的轻状态 */
64
91
  .tpl-card .iconbtn.is-on{background:var(--mdw-accent-soft,#E8F2EE);color:var(--mdw-accent,#2F6F5E)}
65
92
  .tpl-page .page-head h2,