nx-kv 0.24.0 → 0.24.2

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 (33) hide show
  1. package/CHANGELOG.md +34 -0
  2. package/README.md +21 -0
  3. package/package.json +1 -1
  4. package/src/modules/docs/knowledge.js +175 -64
  5. package/src/modules/docs/refs.js +26 -3
  6. package/src/modules/repos/boards.js +25 -1
  7. package/src/modules/repos/index.js +5 -2
  8. package/src/modules/tasktool/groupctx.js +38 -4
  9. package/src/runtime/api.js +6 -23
  10. package/src/runtime/cli.js +8 -3
  11. package/src/runtime/cors.js +125 -0
  12. package/src/runtime/server.js +14 -1
  13. package/src/web/frontend/components/Introduction/index.jsx +5 -1
  14. package/src/web/frontend/components/Introduction/use-intro.js +31 -9
  15. package/src/web/public/assets/Introduction-Dr99GN_o.js +1 -0
  16. package/src/web/public/assets/{cloud-E33bm4CD.js → cloud-BJbs3IuB.js} +1 -1
  17. package/src/web/public/assets/{dag-ClRadqiu.js → dag-DBydHtGQ.js} +1 -1
  18. package/src/web/public/assets/{dir-Dj-3QRkO.js → dir-DgWqKcbC.js} +1 -1
  19. package/src/web/public/assets/{group-Ckwoc5tW.js → group-ji7zeaXJ.js} +1 -1
  20. package/src/web/public/assets/{index-DMp4lRKl.js → index-CHHRdALV.js} +2 -2
  21. package/src/web/public/assets/{md-history-CwtrJcZo.js → md-history-H16pOkv6.js} +1 -1
  22. package/src/web/public/assets/{member-picker-BV1a-LiO.js → member-picker-BmVwgSWB.js} +1 -1
  23. package/src/web/public/assets/{overview-CQW1MViJ.js → overview-BNovkb_k.js} +1 -1
  24. package/src/web/public/assets/{progress-CDiNmHVI.js → progress-Ck-s4Ypp.js} +1 -1
  25. package/src/web/public/assets/{repos-BYFj2sjE.js → repos-A2URD6SC.js} +1 -1
  26. package/src/web/public/assets/{route-crumb-DSgy8FTp.js → route-crumb-x1Za8gFU.js} +1 -1
  27. package/src/web/public/assets/{settings-BoAQ5YXH.js → settings-DNZkV_Be.js} +1 -1
  28. package/src/web/public/assets/{task-Br1K-bzV.js → task-BqQw-96B.js} +1 -1
  29. package/src/web/public/assets/{template-slots-CMB5ZTZE.js → template-slots-DTd6DvJ3.js} +1 -1
  30. package/src/web/public/assets/{templates-DMVIPsdx.js → templates-CHvZ38Vw.js} +1 -1
  31. package/src/web/public/assets/{upload-CzfyPGrk.js → upload-BM8dlfZG.js} +1 -1
  32. package/src/web/public/index.html +1 -1
  33. package/src/web/public/assets/Introduction-DGcd3YBk.js +0 -1
@@ -24,7 +24,7 @@ const BUILTINS = [
24
24
  {
25
25
  id: 'serve',
26
26
  cli: ['serve'],
27
- summary: '启动 Web 面板(默认 :7877;--port N 改端口;--no-open 不开浏览器;端口上已有本面板则直接打开它;NX_SERVE_NO_OPEN=1 全局不开浏览器)',
27
+ summary: '启动 Web 面板(默认 :7877;--port N 改端口;--no-open 不开浏览器;--allow-origin 收紧跨域来源;端口上已有本面板则直接打开它;NX_SERVE_NO_OPEN=1 全局不开浏览器)',
28
28
  flags: {
29
29
  port: { type: 'number', default: DEFAULT_PORT },
30
30
  'no-open': { type: 'boolean' },
@@ -34,6 +34,9 @@ const BUILTINS = [
34
34
  'auto-exit': { type: 'boolean', hint: '面板关闭后空闲自释放(wait 临时拉起实例专用)' },
35
35
  // 宽限期:连续多久无面板活动后才允许释放(与 --auto-exit 配合使用)
36
36
  idle: { type: 'number', hint: '空闲宽限期(秒;与 --auto-exit 配合,默认 120)' },
37
+ // --allow-origin:跨域来源白名单(逗号分隔)。缺省 = 放行全部——面板要能被
38
+ // 内网穿透 / 移动端访问(任务 #57)。收紧时只放行指定来源。
39
+ 'allow-origin': { type: 'string', hint: '跨域来源白名单(逗号分隔);缺省放行全部' },
37
40
  },
38
41
  run: (ctx) => cmdServe(ctx),
39
42
  },
@@ -281,6 +284,8 @@ async function cmdServe(ctx) {
281
284
  const { openBrowser } = await import('../core/open.js');
282
285
  const { autoOpenEnabled, resolvePortConflict, describeOccupant } = await import('../core/serve-port.js');
283
286
  const host = '127.0.0.1';
287
+ // 跨域放行策略:缺省放行全部;--allow-origin 传具体来源则只放行它们。
288
+ const allowOrigin = ctx['allow-origin'];
284
289
  const port = ctx.port || DEFAULT_PORT;
285
290
  const autoExit = !!ctx['auto-exit'];
286
291
  // --no-open 与 NX_SERVE_NO_OPEN 都看这里:任一为真即完全不开浏览器。
@@ -311,7 +316,7 @@ async function cmdServe(ctx) {
311
316
 
312
317
  let server;
313
318
  try {
314
- server = await startServer({ port, host, onRequest });
319
+ server = await startServer({ port, host, onRequest, allowOrigin });
315
320
  } catch (err) {
316
321
  if (!err || err.code !== 'EADDRINUSE') throw err;
317
322
 
@@ -331,7 +336,7 @@ async function cmdServe(ctx) {
331
336
  console.log(
332
337
  `端口 ${port} 已被占用(占用者: ${describeOccupant(decision.occupant)}),改用 ${decision.port}`
333
338
  );
334
- server = await startServer({ port: decision.port, host, onRequest });
339
+ server = await startServer({ port: decision.port, host, onRequest, allowOrigin });
335
340
  }
336
341
 
337
342
  const addr = `http://127.0.0.1:${server.address().port}`;
@@ -0,0 +1,125 @@
1
+ // 跨域(CORS)策略:面板对外来请求的态度。
2
+ //
3
+ // 为什么不再按 Origin 拒绝写请求(任务 #57):
4
+ // 浏览器对 POST/PUT/DELETE **一律带 Origin 头,哪怕请求与页面同源**。
5
+ // 面板原先那道校验是「Origin 的主机名必须是 127.0.0.1/localhost」——
6
+ // 走内网穿透(frp / cloudflared / ngrok)从手机或外网访问时,Origin 变成隧道
7
+ // 域名(如 https://abc.trycloudflare.com),明明是**自己面板的同源请求**,
8
+ // 却因为主机名不是本机被判成跨站 → 403,用户从外网提交任务直接失败。
9
+ // 换句话说:这道校验想拦「浏览器里的陌生网页」,却把「自己的面板从外网访问」
10
+ // 一起拦了——误伤远大于收益。
11
+ //
12
+ // 现在的分工:
13
+ // - 同源请求(含隧道同源):不需要 CORS 头,直接放行;
14
+ // - 跨源请求:浏览器先发 OPTIONS 预检,服务端回 CORS 头才放行;
15
+ // - 非浏览器客户端(curl / 原生 App / agent):本来就不带 Origin,不受影响。
16
+ //
17
+ // 安全边界(要紧):面板只绑 127.0.0.1,是本机工具。**一旦经内网穿透暴露到公网,
18
+ // 真正的边界是隧道自身的访问控制**(访问密码 / basic auth / IP 白名单)——
19
+ // 任何非浏览器客户端都能直接调 API,从头到尾不经过 Origin 校验。
20
+ // 想收紧来源:`nx-kv serve --allow-origin <origin>`(逗号分隔多个,支持 * 通配)。
21
+
22
+ const DEFAULT_ALLOWED_METHODS = 'GET,HEAD,POST,PUT,PATCH,DELETE,OPTIONS';
23
+ const DEFAULT_ALLOWED_HEADERS = 'content-type,authorization,x-requested-with';
24
+ const PREFLIGHT_MAX_AGE = '600';
25
+
26
+ /**
27
+ * 解析 --allow-origin 规格。
28
+ * @param {string|undefined|null} spec 逗号分隔的来源列表;'*' 或缺省 = 放行全部
29
+ * @returns {{all: boolean, list: string[]}} 放行策略
30
+ */
31
+ export function parseAllowOrigin(spec) {
32
+ if (spec === undefined || spec === null) return { all: true, list: [] };
33
+ const raw = String(spec).trim();
34
+ if (!raw || raw === '*') return { all: true, list: [] };
35
+ const list = raw
36
+ .split(',')
37
+ .map((s) => s.trim().replace(/\/+$/, ''))
38
+ .filter(Boolean);
39
+ if (!list.length) return { all: true, list: [] };
40
+ if (list.includes('*')) return { all: true, list: [] };
41
+ return { all: false, list };
42
+ }
43
+
44
+ /**
45
+ * 名单项匹配:支持通配(https://*.example.com)。只有通配是「宽松」的语义,
46
+ * 其余字符按字面量比对。
47
+ * @param {string} pattern 名单项
48
+ * @param {string} origin 实际来源
49
+ * @returns {boolean} 是否命中
50
+ */
51
+ function patternMatches(pattern, origin) {
52
+ if (!pattern.includes('*')) return pattern === origin;
53
+ const parts = pattern.split('*');
54
+ let rest = origin;
55
+ for (let i = 0; i < parts.length; i++) {
56
+ const part = parts[i];
57
+ if (!part) continue;
58
+ const idx = rest.indexOf(part);
59
+ if (idx === -1) return false;
60
+ if (i === 0 && idx !== 0) return false; // 首段必须贴在开头
61
+ rest = rest.slice(idx + part.length);
62
+ }
63
+ const tail = parts[parts.length - 1];
64
+ return !tail || origin.endsWith(tail);
65
+ }
66
+
67
+ /**
68
+ * 来源是否在放行名单里。
69
+ * @param {string} origin 请求的 Origin 头
70
+ * @param {{all: boolean, list: string[]}} allow 放行策略
71
+ * @returns {boolean} 是否放行
72
+ */
73
+ export function originAllowed(origin, allow) {
74
+ if (!origin) return false;
75
+ if (!allow || allow.all) return true;
76
+ const o = String(origin).replace(/\/+$/, '');
77
+ return allow.list.some((p) => patternMatches(p, o));
78
+ }
79
+
80
+ /**
81
+ * 是否是 CORS 预检请求(OPTIONS + Access-Control-Request-Method)。
82
+ * @param {{method?: string, headers: object}} req 原始请求
83
+ * @returns {boolean} 是否预检
84
+ */
85
+ export function isPreflight(req) {
86
+ return (
87
+ String((req && req.method) || '').toUpperCase() === 'OPTIONS' &&
88
+ !!(req && req.headers && req.headers['access-control-request-method'])
89
+ );
90
+ }
91
+
92
+ /**
93
+ * 给响应补 CORS 头。
94
+ * 非浏览器客户端(无 Origin)不加头;来源不在名单里也**故意不加** allow-origin
95
+ * ——让浏览器自己拦下这次跨源请求(而不是服务端回 403,那会把「跨源不支持」
96
+ * 和「请求出错」混成一种状态码)。
97
+ * @param {{headers: object}} req 原始请求
98
+ * @param {{all: boolean, list: string[]}} allow 放行策略
99
+ * @returns {Record<string, string>} CORS 响应头
100
+ */
101
+ export function corsHeaders(req, allow) {
102
+ const origin = req && req.headers ? req.headers.origin : '';
103
+ if (!origin) return { vary: 'Origin' };
104
+ if (!originAllowed(origin, allow)) return { vary: 'Origin' };
105
+ return {
106
+ 'access-control-allow-origin': allow.all ? '*' : origin,
107
+ vary: 'Origin',
108
+ };
109
+ }
110
+
111
+ /**
112
+ * 预检响应头:回显浏览器这次请求的方法与请求头(只回该次预检涉及的)。
113
+ * @param {{headers: object}} req 原始请求
114
+ * @param {{all: boolean, list: string[]}} allow 放行策略
115
+ * @returns {Record<string, string>} 预检响应头
116
+ */
117
+ export function preflightHeaders(req, allow) {
118
+ const requested = req && req.headers ? req.headers['access-control-request-headers'] : '';
119
+ return {
120
+ ...corsHeaders(req, allow),
121
+ 'access-control-allow-methods': DEFAULT_ALLOWED_METHODS,
122
+ 'access-control-allow-headers': requested ? String(requested) : DEFAULT_ALLOWED_HEADERS,
123
+ 'access-control-max-age': PREFLIGHT_MAX_AGE,
124
+ };
125
+ }
@@ -5,6 +5,7 @@ import { extname, resolve, sep } from 'node:path';
5
5
  import { fileURLToPath } from 'node:url';
6
6
  import fsp from 'node:fs/promises';
7
7
  import { handleApi, sendJson } from './api.js';
8
+ import { corsHeaders, isPreflight, parseAllowOrigin, preflightHeaders } from './cors.js';
8
9
  import { DEFAULT_PORT } from '../core/paths.js';
9
10
 
10
11
  // vite 的 outDir:src/web/public(构建产物,gitignore)
@@ -57,7 +58,9 @@ async function handlePing(_req, res) {
57
58
  sendJson(res, 200, { ok: true, data: { pong: true, ts: Date.now() } });
58
59
  }
59
60
 
60
- export function startServer({ port = DEFAULT_PORT, host = '127.0.0.1', onRequest } = {}) {
61
+ export function startServer({ port = DEFAULT_PORT, host = '127.0.0.1', onRequest, allowOrigin } = {}) {
62
+ // 跨域放行策略:缺省放行全部(面板要能被内网穿透 / 移动端访问,见 runtime/cors.js)。
63
+ const cors = parseAllowOrigin(allowOrigin);
61
64
  const server = http.createServer(async (req, res) => {
62
65
  // 活动观测:每个请求(包括 /api/ping 与静态文件)都回调一次;
63
66
  // 回调只上报,不参与响应;异常必须吞掉以免影响主流程。
@@ -66,6 +69,16 @@ export function startServer({ port = DEFAULT_PORT, host = '127.0.0.1', onRequest
66
69
  }
67
70
  try {
68
71
  const url = new URL(req.url, `http://${req.headers.host || 'localhost'}`);
72
+ // CORS 头统一在这里补:静态页与 /api 都要带(跨源嵌入面板时静态资源也得能取)。
73
+ // setHeader 的值会与后面 writeHead 的对象合并(同名以 writeHead 为准)。
74
+ for (const [k, v] of Object.entries(corsHeaders(req, cors))) res.setHeader(k, v);
75
+ // 预检(OPTIONS + Access-Control-Request-Method):不匹配路由,直接回 CORS 头。
76
+ // 浏览器要求预检通过才发真正的跨源请求——同源(含隧道同源)根本不预检。
77
+ if (url.pathname.startsWith('/api/') && isPreflight(req)) {
78
+ res.writeHead(204, preflightHeaders(req, cors));
79
+ res.end();
80
+ return;
81
+ }
69
82
  if (url.pathname === '/api/ping') {
70
83
  await handlePing(req, res);
71
84
  return;
@@ -20,7 +20,11 @@ export default function Introduction({ kind, owner, model }) {
20
20
 
21
21
  if (!owner || !docRef) return null;
22
22
 
23
- const pathLabel = docRef.startsWith('rel:') ? docRef.slice(4) : docRef;
23
+ // 主篇以「介绍文档集」为准(目录 index.md 优先 → 旧单文件回落)——
24
+ // 路径标签显示的必须是真正的主篇那篇。
25
+ const mainEntry = links.find((l) => l.main);
26
+ const mainRef = mainEntry ? mainEntry.docId : docRef;
27
+ const pathLabel = mainRef.startsWith('rel:') ? mainRef.slice(4) : mainRef;
24
28
  const extras = links.filter((l) => !l.main);
25
29
  const onAdd = () => addRef(dialog, toast).catch((e) => toast(String(e.message || e)));
26
30
 
@@ -48,6 +48,9 @@ export function useIntro({ kind, owner, model }) {
48
48
  const docRef = useMemo(() => introRefOf(owner, kind), [owner, kind]);
49
49
 
50
50
  const [links, setLinks] = useState([]); // [{ docId, label, note, main }]
51
+ // 主篇 docId:以后端返回的「介绍文档集」为准(目录 index.md 优先,
52
+ // 旧单文件回落);拿不到才用 prop 推的 docRef。
53
+ const [mainDocId, setMainDocId] = useState("");
51
54
  const [tick, setTick] = useState(0);
52
55
 
53
56
  const reload = useCallback(() => setTick((n) => n + 1), []);
@@ -64,10 +67,18 @@ export function useIntro({ kind, owner, model }) {
64
67
  .then((d) => {
65
68
  if (!alive) return;
66
69
  const out = [];
67
- if (d.main) {
68
- const id = linkDocId(d.main);
69
- if (id) out.push({ docId: id, label: d.main.rel || d.main.path || '主篇', note: d.main.note || '', tag: d.main.tag || '', main: true, ref: d.main.ref || '' });
70
+ // 主篇:文档集的主篇(目录 index.md 优先 → 旧单文件回落)
71
+ const mid = linkDocId(d.main);
72
+ setMainDocId(mid || docRef);
73
+ if (mid) {
74
+ out.push({ docId: mid, label: d.main.rel || d.main.path || '主篇', note: d.main.note || '', tag: d.main.tag || '', main: true, ref: d.main.ref || '' });
70
75
  }
76
+ // 其余:介绍目录里的补充说明(同一目录下的其他 md)
77
+ for (const l of d.extras || []) {
78
+ const id = linkDocId(l);
79
+ if (id) out.push({ docId: id, label: l.name || l.rel || l.path || '补充', note: l.note || '', tag: l.tag || '', main: false, ref: l.ref || '' });
80
+ }
81
+ // 登记在册的补充文档(外部 / ref 仓库里的文件)
71
82
  for (const l of d.links || []) {
72
83
  const id = linkDocId(l);
73
84
  // ref 随条目留着:ref 形态的链接(参考仓库内文件)不能按 rel 回写,标签编辑要对它关掉
@@ -75,7 +86,7 @@ export function useIntro({ kind, owner, model }) {
75
86
  }
76
87
  setLinks(out);
77
88
  })
78
- .catch(() => { if (alive) setLinks([]); });
89
+ .catch(() => { if (alive) { setLinks([]); setMainDocId(docRef); } });
79
90
  } else {
80
91
  // board 分支拉实时数据(GET /api/boards/:id)而不是读 owner prop——
81
92
  // owner 是父层的 repoData 快照,addRef / 改 tag 后不会自动刷新:
@@ -95,10 +106,19 @@ export function useIntro({ kind, owner, model }) {
95
106
  const links = Array.isArray(bd && bd.docLinks) ? bd.docLinks : null;
96
107
  if (!links) {
97
108
  setLinks(fromOwner());
109
+ setMainDocId(docRef);
98
110
  return;
99
111
  }
100
112
  const out = [];
101
- if (docRef) out.push({ docId: docRef, label: '主篇', note: '', tag: '', main: true, ref: '' });
113
+ // 主篇:文档集的主篇(目录 index.md 优先 → 旧单文件回落)
114
+ const mid = linkDocId(bd && bd.introMain) || docRef;
115
+ setMainDocId(mid);
116
+ if (mid) out.push({ docId: mid, label: '主篇', note: '', tag: '', main: true, ref: '' });
117
+ // 其余:介绍目录里的补充说明
118
+ for (const l of (bd && bd.introExtras) || []) {
119
+ const id = linkDocId(l);
120
+ if (id) out.push({ docId: id, label: l.name || l.rel || l.path || '补充', note: l.note || '', tag: l.tag || '', main: false, ref: l.ref || '' });
121
+ }
102
122
  // ref 随条目留着:ref 形态的链接(参考仓库内文件)不能按 rel 回写,标签编辑要对它关掉
103
123
  for (const l of links) {
104
124
  const id = linkDocId(l);
@@ -106,7 +126,7 @@ export function useIntro({ kind, owner, model }) {
106
126
  }
107
127
  setLinks(out);
108
128
  })
109
- .catch(() => { if (alive) setLinks(fromOwner()); });
129
+ .catch(() => { if (alive) { setLinks(fromOwner()); setMainDocId(docRef); } });
110
130
  }
111
131
  return () => { alive = false; };
112
132
  }, [kind, ownerKey, owner, docRef, tick]);
@@ -119,9 +139,10 @@ export function useIntro({ kind, owner, model }) {
119
139
 
120
140
  /** 打开主篇(缺文档时 DocPanel 给「创建骨架」) */
121
141
  const openMain = useCallback(() => {
122
- if (!docRef) return;
123
- openByDocId(docRef, null, openExtra);
124
- }, [docRef, openByDocId, openExtra]);
142
+ const target = mainDocId || docRef;
143
+ if (!target) return;
144
+ openByDocId(target, null, openExtra);
145
+ }, [mainDocId, docRef, openByDocId, openExtra]);
125
146
 
126
147
  const openDoc = useCallback(
127
148
  (id) => openByDocId(id, null, openExtra),
@@ -192,6 +213,7 @@ export function useIntro({ kind, owner, model }) {
192
213
  label,
193
214
  ownerKey,
194
215
  docRef,
216
+ mainDocId,
195
217
  links,
196
218
  openMain,
197
219
  openDoc,
@@ -0,0 +1 @@
1
+ import{d as e,f as t,h as n,m as r,o as i,u as a}from"./attach-v8BxRJ7p.js";import{C as o,D as s,W as c,b as l,j as u,p as d,q as f,y as p}from"./index-CHHRdALV.js";import{a as m,i as h,n as g,o as _,r as v,t as y}from"./md-history-H16pOkv6.js";var b=r({default:()=>w,useWikiNav:()=>C}),x=n(t(),1),S=e();function C(e){let t=c()||{},n=a(),r=e||t.model,i=(0,x.useRef)(null),o=(0,x.useCallback)(async()=>{if(!i.current)try{i.current=(await f(`/api/docs/index`)).index||[]}catch{i.current=[]}return i.current},[]),l=(0,x.useCallback)(async(e,t,n={})=>{let i=(t||await o()).find(t=>t.docId===e);u(r,{component:`doc`,name:i?i.name:e,config:{docId:e,...n.repoKey?{repoKey:n.repoKey}:{},...n.boardKey?{boardKey:n.boardKey,boardName:n.boardName||``}:{}},location:`center`})},[r,o]),d=(0,x.useCallback)(async e=>{let t=await o(),r=s(e,t);if(r&&r.docId)return l(r.docId,t);if(r&&r.candidates)return n(`「${e}」同名文档多份:${r.candidates.join(`、`)}`);n(`未找到「${e}」——可用 nx-kv docs add <rel> 创建`)},[o,l,n]);return{nav:d,onClick:(0,x.useCallback)(e=>{let t=e.target.closest(`[data-wl]`);t&&(e.preventDefault(),d(t.getAttribute(`data-wl`)))},[d]),ensureIndex:o,openByDocId:l}}function w({docId:e,repoKey:t,boardKey:n,boardName:r,model:s}){let c=a(),{dialog:u,node:b}=i(),w=(0,x.useRef)(new Map),E=(0,x.useRef)(null),D=(0,x.useRef)(null),{onClick:O,openByDocId:k}=C(s),A=t?`repo`:n?`board`:``,j=t||n||``,M=(0,x.useMemo)(()=>t?{repoKey:t}:n?{boardKey:n,boardName:r||``}:{},[t,n,r]),[N,P]=(0,x.useState)(null),[F,I]=(0,x.useState)(``),[te,L]=(0,x.useState)(!1),[R,z]=(0,x.useState)(`split`),[B,V]=(0,x.useState)([]),[H,U]=(0,x.useState)(null),W=(0,x.useCallback)(async()=>{I(``);try{let t=await f(`/api/docs/item?ref=`+encodeURIComponent(e||``));P(t),L(!1)}catch(e){I(String(e.message||e)),P(null)}},[e]);(0,x.useEffect)(()=>{P(null),W()},[W]);let G=(0,x.useCallback)(()=>{if(!j){V([]);return}if(A===`repo`){f(`/api/repos/docs?id=`+encodeURIComponent(j)).then(t=>{let n=[],r=(e,t)=>{if(!e)return;let r=e.rel?`rel:`+e.rel:e.path?`path:`+e.path:``;r&&n.push({docId:r,label:e.rel||e.path||(t?`主篇`:`补充`),note:e.note||``,main:t})};r(t.main||{rel:`repo/${j}.md`},!0);for(let e of t.links||[])r(e,!1);e&&!n.some(t=>t.docId===e)&&n.push({docId:e,label:`当前`,note:``,main:!0}),V(n)}).catch(()=>V(e?[{docId:e,label:`当前`,note:``,main:!0}]:[]));return}f(`/api/boards`).then(t=>{let n=(t&&t.boards||(Array.isArray(t)?t:[])).find(e=>e.id===j||e.key===j),r=[];e&&r.push({docId:e,label:`当前`,note:``,main:!0});for(let e of n&&n.docLinks||[]){let t=e.rel?`rel:${e.rel}`:e.path?`path:${e.path}`:``;t&&!r.some(e=>e.docId===t)&&r.push({docId:t,label:e.rel||e.path||`补充`,note:e.note||``,main:!1})}V(r)}).catch(()=>V(e?[{docId:e,label:`当前`,note:``,main:!0}]:[]))},[j,A,e]);(0,x.useEffect)(()=>{G()},[G]);let[K,q]=(0,x.useState)(null);(0,x.useEffect)(()=>{f(`/api/docs/index`).then(e=>{let t=new Set;for(let n of e.index||[])t.add(n.name),n.rel&&t.add(String(n.rel).toLowerCase()),n.path&&t.add(String(n.path).replace(/\\/g,`/`).toLowerCase());q(t)}).catch(()=>{})},[]);let J=!!(N&&N.writable),Y=(0,x.useMemo)(()=>N?p(N.body,[],J?K:null):``,[N,K,J]),X=(0,x.useMemo)(()=>N?d(N.body):[],[N]);(0,x.useEffect)(()=>{let e=D.current;if(!e)return;let t=()=>e.querySelector(`.mdw-preview, .mdw-lp`)||null;U(t());let n=typeof MutationObserver<`u`?new MutationObserver(()=>U(t())):null;return n&&n.observe(e,{childList:!0,subtree:!0}),()=>{n&&n.disconnect()}},[N,R,Y]);let Z=e=>e().catch(e=>c(String(e.message||e))),ne=(0,x.useCallback)(e=>k(e,null,M),[k,M]),re=()=>{j&&Z(async()=>{let t=await u({title:`补充介绍文档`,input:!0,placeholder:`文档名(如 architecture / api-notes)`});if(t===null)return;let n=l(String(t).trim()||`note`).replace(/\.md$/i,``),i=`${String(e||``).startsWith(`rel:`)?T(e):A===`repo`?`repo/${j}`:`board/${r||j}`}/reference/${n}.md`;await f(`/api/docs/item`,{method:`POST`,body:{rel:i,body:`# ${String(t).trim()||n}\n\n(待补)\n`}});try{A===`repo`?await f(`/api/repos/docs`,{method:`POST`,body:{id:j,rel:i}}):await f(`/api/docs/link`,{method:`POST`,body:{board:j,doc:i}})}catch{}c(`已补充:${i}`),G(),k(`rel:`+i,null,M)})},Q=()=>Z(async()=>{if(!N||!J)return;let t=await f(`/api/docs/item`,{method:`PATCH`,body:{ref:e,body:N.body}});P(e=>({...e,body:N.body,summary:t.summary})),L(!1),y(w.current,e),c(t.summary?`已保存,摘要已回写`:`已保存`)}),ie=(t,n=`op`)=>{N&&(g(w.current,e,{body:N.body},n),L(!0),P(e=>({...e,body:t,title:o(t,e.title)})))},ae=(t,n=`typing`)=>{if(!N)return;g(w.current,e,{body:N.body},n),L(!0);let r=/^#\s+/m.test(N.body)?N.body.replace(/^#\s+.+$/m,`# ${t||`未命名文档`}`):`# ${t||`未命名文档`}\n\n${N.body}`;P(e=>({...e,body:r,title:t}))},oe=()=>{if(!N)return;let t=h(w.current,e,{body:N.body});t&&(P(e=>({...e,body:t.body,title:o(t.body,e.title)})),L(!0),requestAnimationFrame(()=>E.current?.caretFromDiff?.(N.body,t.body)))},se=()=>{if(!N)return;let t=v(w.current,e,{body:N.body});t&&(P(e=>({...e,body:t.body,title:o(t.body,e.title)})),L(!0),requestAnimationFrame(()=>E.current?.caretFromDiff?.(N.body,t.body)))},ce=()=>Z(async()=>{let t=String(e||``).startsWith(`rel:`)?e.slice(4):String(e||``).startsWith(`path:`)?``:String(e||``);if(!t)return;let n=t.replace(/\.md$/i,``).split(`/`).pop()||`未命名文档`;await f(`/api/docs/item`,{method:`POST`,body:{rel:t,body:`# ${n}\n\n(待补)\n`}}),c(`已创建:${t}`),await W()});if(N&&N.dir)return(0,S.jsxs)(`div`,{className:`mdw docp`,children:[(0,S.jsxs)(`div`,{className:`docp-head`,children:[(0,S.jsx)(`span`,{className:`docp-path mono`,children:N.path}),(0,S.jsx)(`span`,{className:`docp-tag ext`,children:`外部目录 · 只读`})]}),(0,S.jsxs)(`div`,{className:`docp-files`,children:[N.files.map(e=>(0,S.jsx)(`button`,{className:`docp-file`,onClick:()=>k(`path:`+e,null),children:e},e)),!N.files.length&&(0,S.jsx)(`div`,{className:`muted pad`,children:`(目录里还没有 .md 文档)`})]})]});if(F)return(0,S.jsx)(`div`,{className:`mdw docp`,children:(0,S.jsxs)(`div`,{className:`pad stack`,children:[(0,S.jsx)(`div`,{children:(0,S.jsx)(`strong`,{children:`文档打开失败`})}),(0,S.jsx)(`div`,{className:`hint`,children:F})]})});if(!N)return(0,S.jsx)(`div`,{className:`mdw`,children:(0,S.jsx)(`div`,{className:`pad muted`,children:`载入中…`})});if(N.missing){let t=String(e||``).startsWith(`rel:`)||!String(e||``).startsWith(`path:`);return(0,S.jsxs)(`div`,{className:`mdw docp`,children:[(0,S.jsx)(`div`,{className:`docp-head`,children:(0,S.jsx)(`span`,{className:`docp-path mono`,children:N.rel||N.path||e})}),(0,S.jsxs)(`div`,{className:`pad stack`,children:[(0,S.jsx)(`div`,{children:(0,S.jsx)(`strong`,{children:`文档还没有落盘`})}),(0,S.jsx)(`div`,{className:`hint`,children:`描述内容的权威是磁盘上的 .md 文件——对应的字符串字段会在读取时播种,也可以直接创建骨架。`}),t&&(0,S.jsx)(`div`,{children:(0,S.jsx)(`button`,{className:`btn sm`,onClick:ce,children:`创建骨架`})})]})]})}let $=J?R:`preview`;return(0,S.jsxs)(`div`,{className:`mdw docp`,"data-mode":$,onClick:O,ref:D,children:[(0,S.jsxs)(`div`,{className:`mdw-main`,children:[(0,S.jsxs)(`div`,{className:`docp-head`,children:[(0,S.jsx)(`span`,{className:`docp-path mono`,title:N.rel||N.path,children:N.rel||N.path}),te&&(0,S.jsx)(`span`,{className:`docp-dirty`,children:`未保存`}),!J&&(0,S.jsx)(`span`,{className:`docp-tag ext`,children:`外部绑定 · 只读`}),(0,S.jsx)(`span`,{className:`grow`}),J&&(0,S.jsxs)(S.Fragment,{children:[(0,S.jsx)(_,{mode:$,onChange:z}),(0,S.jsx)(`button`,{className:`btn sm docp-save`,onClick:Q,children:`保存`})]})]}),N.summary&&J&&(0,S.jsxs)(`div`,{className:`docp-summary`,children:[`摘要(回写 desc):`,N.summary]}),(0,S.jsx)(m,{mode:$,title:N.title,body:N.body,previewHtml:Y,onTitle:J?ae:null,onBody:J?ie:null,attachments:[],docKey:e,editorApiRef:E,onSave:J?Q:null,onUndo:J?oe:null,onRedo:J?se:null}),(0,S.jsx)(`div`,{className:`docp-hint`,children:`双链 [[]] 点击跳转 · Ctrl+S 保存 · 文档即磁盘文件(~/.nx-kv/docs/)`})]}),(0,S.jsx)(ee,{headings:X,scrollRoot:H,links:B,activeDocId:e,onOpenDoc:j?ne:null,onAddRef:j?re:null}),b]})}function T(e){let t=String(e||``).startsWith(`rel:`)?String(e).slice(4):``;return t?/\/index\.md$/i.test(t)?t.replace(/\/index\.md$/i,``):/\.md$/i.test(t)?t.replace(/\.md$/i,``):t.replace(/\/+$/,``):``}function E(e,t){return e?e.doc&&e.doc.path?`path:`+e.doc.path:e.doc&&e.doc.rel?`rel:`+e.doc.rel:e.docPath?`path:`+e.docPath:e.docRel?`rel:`+e.docRel:t===`repo`&&e.key?`rel:repo/`+e.key+`.md`:``:``}function D(e){return e?e.rel?`rel:`+e.rel:e.path?`path:`+e.path:``:``}function O({kind:e,owner:t,model:n}){let{openByDocId:r}=C(n),i=e===`board`?`组介绍`:`项目介绍`,a=e===`board`?t&&(t.id||t.key):t&&t.key,o=t&&t.name,s=(0,x.useMemo)(()=>E(t,e),[t,e]),[c,u]=(0,x.useState)([]),[d,p]=(0,x.useState)(``),[m,h]=(0,x.useState)(0),g=(0,x.useCallback)(()=>h(e=>e+1),[]);(0,x.useEffect)(()=>{let n=!0;if(!a){u([]);return}if(e===`repo`)f(`/api/repos/docs?id=`+encodeURIComponent(a)).then(e=>{if(!n)return;let t=[],r=D(e.main);p(r||s),r&&t.push({docId:r,label:e.main.rel||e.main.path||`主篇`,note:e.main.note||``,tag:e.main.tag||``,main:!0,ref:e.main.ref||``});for(let n of e.extras||[]){let e=D(n);e&&t.push({docId:e,label:n.name||n.rel||n.path||`补充`,note:n.note||``,tag:n.tag||``,main:!1,ref:n.ref||``})}for(let n of e.links||[]){let e=D(n);e&&t.push({docId:e,label:n.rel||n.path||`补充`,note:n.note||``,tag:n.tag||``,main:!1,ref:n.ref||``})}u(t)}).catch(()=>{n&&(u([]),p(s))});else{let e=()=>{let e=[];s&&e.push({docId:s,label:`主篇`,note:``,tag:``,main:!0,ref:``});for(let n of t?.docLinks||[]){let t=D(n);t&&e.push({docId:t,label:n.rel||n.path||`补充`,note:n.note||``,tag:n.tag||``,main:!1,ref:n.ref||``})}return e};f(`/api/boards/`+encodeURIComponent(String(a))).then(t=>{if(!n)return;let r=Array.isArray(t&&t.docLinks)?t.docLinks:null;if(!r){u(e()),p(s);return}let i=[],a=D(t&&t.introMain)||s;p(a),a&&i.push({docId:a,label:`主篇`,note:``,tag:``,main:!0,ref:``});for(let e of t&&t.introExtras||[]){let t=D(e);t&&i.push({docId:t,label:e.name||e.rel||e.path||`补充`,note:e.note||``,tag:e.tag||``,main:!1,ref:e.ref||``})}for(let e of r){let t=D(e);t&&i.push({docId:t,label:e.rel||e.path||`补充`,note:e.note||``,tag:e.tag||``,main:!1,ref:e.ref||``})}u(i)}).catch(()=>{n&&(u(e()),p(s))})}return()=>{n=!1}},[e,a,t,s,m]);let _=(0,x.useMemo)(()=>e===`repo`&&a?{repoKey:a}:e===`board`&&a?{boardKey:a,boardName:o||``}:{},[e,a,o]);return{kind:e,label:i,ownerKey:a,docRef:s,mainDocId:d,links:c,openMain:(0,x.useCallback)(()=>{let e=d||s;e&&r(e,null,_)},[d,s,r,_]),openDoc:(0,x.useCallback)(e=>r(e,null,_),[r,_]),addRef:(0,x.useCallback)(async(t,n)=>{if(!a||!s.startsWith(`rel:`))return n&&n(`当前简介无法补充(需要自有树路径)`),null;let i=await t({title:`补充介绍文档`,input:!0,tagInput:!0,placeholder:`文档名(如 architecture / api-notes)`,tagPlaceholder:`标签(可选,如 qa)`});if(i===null)return null;let c=typeof i==`string`?i:i&&i.value||``,u=typeof i==`object`&&i&&i.tag||``,d=l(String(c).trim()||`note`).replace(/\.md$/i,``),p=`${T(s)||(e===`repo`?`repo/${a}`:`board/${o||a}`)}/reference/${d}.md`;await f(`/api/docs/item`,{method:`POST`,body:{rel:p,body:`# ${String(c).trim()||d}\n\n(待补)\n`}});try{e===`repo`?await f(`/api/repos/docs`,{method:`POST`,body:{id:a,rel:p,tag:u||void 0}}):await f(`/api/docs/link`,{method:`POST`,body:{board:a,doc:p,tag:u||void 0}})}catch{}return n&&n(`已补充:${p}${u?` [${u}]`:``}`),g(),r(`rel:`+p,null,_),p},[a,s,e,o,r,_,g]),setLinkTag:(0,x.useCallback)(async(t,n,r)=>{if(!a)throw Error(`缺少归属`);let i=String(t||``).startsWith(`path:`)?{path:String(t).slice(5)}:{rel:String(t||``).startsWith(`rel:`)?String(t).slice(4):String(t||``)},o=r&&r.note||``;e===`repo`?await f(`/api/repos/docs`,{method:`POST`,body:{id:a,...i,note:o||void 0,tag:n||void 0}}):await f(`/api/docs/link`,{method:`POST`,body:{board:a,doc:i.path||i.rel,note:o||void 0,tag:n||void 0}}),g()},[a,e,g]),reload:g,canEdit:!!s}}function k(e){return e<=1?18:e===2?12:8}function ee({headings:e=[],scrollRoot:t=null,links:n=[],activeDocId:r=``,onOpenDoc:i=null,onAddRef:a=null}){let[o,s]=(0,x.useState)(!1),[c,l]=(0,x.useState)(``),u=(0,x.useMemo)(()=>e||[],[e]),d=(0,x.useMemo)(()=>n||[],[n]);(0,x.useEffect)(()=>{let e=t;if(!e||!u.length)return;let n=()=>u.map(t=>{let n=e.querySelector(`#${CSS.escape(t.id)}`);if(!n)return null;let r=n.getBoundingClientRect(),i=e.getBoundingClientRect();return{id:t.id,y:r.top-i.top}}).filter(Boolean),r=()=>{let e=n();if(!e.length)return;let t=e[0].id;for(let n of e)n.y<=28&&(t=n.id);l(t)};return r(),e.addEventListener(`scroll`,r,{passive:!0}),()=>e.removeEventListener(`scroll`,r)},[t,u]);let f=(0,x.useCallback)(e=>{let n=t;if(!n)return;let r=n.querySelector(`#${CSS.escape(e)}`);if(!r){n.scrollTo({top:0,behavior:`smooth`}),l(e);return}r.scrollIntoView({behavior:`smooth`,block:`start`}),l(e)},[t]);return!u.length&&!d.length&&!a?null:(0,S.jsxs)(`aside`,{className:`doc-rail`+(o?` open`:``),"aria-label":`文档目录`,children:[(0,S.jsxs)(`button`,{type:`button`,className:`doc-rail-menu`,title:o?`收起目录`:`展开目录`,"aria-expanded":o,onClick:()=>s(e=>!e),children:[(0,S.jsx)(`span`,{}),(0,S.jsx)(`span`,{}),(0,S.jsx)(`span`,{})]}),(0,S.jsx)(`div`,{className:`doc-rail-ticks`,role:`navigation`,"aria-label":`章节`,children:u.map(e=>(0,S.jsx)(`button`,{type:`button`,className:`doc-rail-tick`+(c===e.id?` on`:``),style:{"--tw":`${k(e.level)}px`},title:e.text,"aria-current":c===e.id?`true`:void 0,onClick:()=>f(e.id)},e.id))}),o&&(0,S.jsxs)(`div`,{className:`doc-rail-panel`,children:[u.length>0&&(0,S.jsxs)(`div`,{className:`doc-rail-sec`,children:[(0,S.jsx)(`div`,{className:`doc-rail-sec-lab`,children:`本章`}),u.map(e=>(0,S.jsx)(`button`,{type:`button`,className:`doc-rail-row`+(c===e.id?` on`:``),"data-lv":e.level,onClick:()=>f(e.id),children:e.text},e.id))]}),(d.length>0||a)&&(0,S.jsxs)(`div`,{className:`doc-rail-sec`,children:[(0,S.jsx)(`div`,{className:`doc-rail-sec-lab`,children:`介绍文档`}),d.map(e=>(0,S.jsxs)(`button`,{type:`button`,className:`doc-rail-row`+(e.docId===r?` on`:``),title:e.note||e.label,disabled:!i,onClick:()=>i&&i(e.docId),children:[e.main?`● `:`○ `,e.label]},e.docId)),a&&(0,S.jsx)(`button`,{type:`button`,className:`doc-rail-add`,onClick:a,children:`+ 补充文档`})]})]})]})}function A({kind:e,owner:t,model:n}){let r=a(),{dialog:o,node:s}=i(),{label:c,docRef:l,links:u,openMain:d,openDoc:f,addRef:p,setLinkTag:m,canEdit:h}=O({kind:e,owner:t,model:n});if(!t||!l)return null;let g=u.find(e=>e.main),_=g?g.docId:l,v=_.startsWith(`rel:`)?_.slice(4):_,y=u.filter(e=>!e.main),b=()=>p(o,r).catch(e=>r(String(e.message||e))),x=e=>{(async()=>{let t=await o({title:`标签 · ${e.label}`,input:!0,placeholder:`标签(如 qa;留空 = 清掉)`,value:e.tag||``,okText:`保存标签`});if(t===null)return;let n=typeof t==`string`?t:t&&t.tag||``;await m(e.docId,n,e),r(n?`标签已设为 [${n}]`:`标签已清除`)})().catch(e=>r(String(e.message||e)))};return(0,S.jsxs)(`div`,{className:`nx-intro`,children:[(0,S.jsxs)(`div`,{className:`nx-intro-head`,children:[(0,S.jsx)(`button`,{type:`button`,className:`nx-intro-link-main`,title:`打开${c}(新页签阅读 / 编辑)`,onClick:d,children:c}),(0,S.jsx)(`span`,{className:`nx-intro-path mono`,children:v}),(0,S.jsx)(`span`,{className:`nx-intro-spacer`}),h&&l.startsWith(`rel:`)&&(0,S.jsx)(`button`,{type:`button`,className:`nx-intro-btn`,title:`补充一篇介绍文档(reference)`,onClick:b,children:`+ ref`})]}),y.length>0&&(0,S.jsxs)(`div`,{className:`nx-intro-links`,children:[(0,S.jsx)(`span`,{className:`nx-intro-links-lab`,children:`补充`}),y.map(e=>(0,S.jsxs)(`span`,{className:`nx-intro-link-item`,children:[(0,S.jsxs)(`button`,{type:`button`,className:`nx-intro-link`+(e.docId.startsWith(`path:`)?` ext`:``),title:e.note?`${e.label} — ${e.note}`:e.label,onClick:()=>f(e.docId),children:[(0,S.jsx)(`span`,{className:`nx-intro-link-label`,children:e.label}),e.tag?(0,S.jsx)(`span`,{className:`nx-intro-link-tag`,title:`标签:${e.tag}`,children:e.tag}):null,e.note?(0,S.jsx)(`span`,{className:`nx-intro-link-note`,children:e.note}):null,e.docId.startsWith(`path:`)?(0,S.jsx)(`span`,{className:`nx-intro-link-tag`,children:`外部`}):null]}),h&&!e.ref&&(0,S.jsx)(`button`,{type:`button`,className:`nx-intro-tag-btn`,title:e.tag?`改标签(当前:${e.tag})`:`加标签`,"aria-label":`标签:${e.label}`,onClick:()=>x(e),children:`#`})]},e.docId))]}),s]})}export{b as n,C as r,A as t};
@@ -1,3 +1,3 @@
1
- import{a as e,d as t,f as n,h as r,l as i,n as a,o,r as s,u as c}from"./attach-v8BxRJ7p.js";import{G as l,K as u,q as d}from"./index-DMp4lRKl.js";import{t as f}from"./route-crumb-DSgy8FTp.js";import{i as p,n as m,r as h,t as g}from"./upload-CzfyPGrk.js";var _=r(n(),1),v=t(),y=e=>`/api/file/content/${encodeURIComponent(e)}`;function b({text:e,compact:t=!1,className:n=``}){let r=a(e);return r.some(e=>e.type!==`text`)?(0,v.jsx)(`span`,{className:n?`mdtext ${n}`:`mdtext`,children:r.map((e,n)=>{if(e.type===`text`)return(0,v.jsx)(`span`,{className:`mdtext-plain`,children:e.value},n);let r=y(e.id);return e.type===`image`?(0,v.jsx)(`a`,{className:`embed-image`+(t?` compact`:``),href:r,target:`_blank`,rel:`noreferrer`,title:e.alt?`${e.alt}(点击看原图)`:e.id,children:(0,v.jsx)(`img`,{src:r,alt:e.alt||e.id,loading:`lazy`})},n):(0,v.jsx)(`a`,{className:`embed-file`,href:r,target:`_blank`,rel:`noreferrer`,title:e.id,children:e.alt||e.id},n)})}):(0,v.jsx)(`span`,{className:n,children:e})}function x({task:e,pick:t,group:n,onSaved:r,onCancel:i}){let a=c(),[o,s]=(0,_.useState)(e.text||``),[l,u]=(0,_.useState)(e.note||``),[f,y]=(0,_.useState)(!1),[x,S]=(0,_.useState)(null),[C,w]=(0,_.useState)(!1),T=(0,_.useRef)(null),E=(0,_.useRef)(null),D=(0,_.useRef)(o),O=e=>{D.current=e,s(e)};(0,_.useEffect)(()=>{let e=T.current;e&&(e.focus(),e.setSelectionRange(e.value.length,e.value.length))},[]);let k=e=>{if(!e)return;let t=T.current,n=D.current,r=t&&t.selectionStart!==null?t.selectionStart:n.length,i=t&&t.selectionEnd!==null?t.selectionEnd:r,a=n.slice(0,r),o=n.slice(i),s=a&&!/\s$/.test(a)?` `:``,c=`${a}${s}${e}${o&&!/^\s/.test(o)?` `:``}${o}`;O(c);let l=a.length+s.length+e.length;requestAnimationFrame(()=>{let e=T.current;e&&(e.focus(),e.setSelectionRange(l,l))})},A=async e=>{let t=Array.from(e||[]).filter(e=>e&&e.size>0);if(t.length&&!x){S({done:0,total:t.length});try{let e=await p(t,{group:n,onProgress:(e,t)=>S({done:e,total:t})});k(h(e));let r=e.filter(e=>e.isImage).length;a(e.length===1?`已插入 ${e[0].name}`:`已插入 ${e.length} 个附件${r?`(图片 ${r} 个)`:``}`)}catch(e){a(String(e&&e.message||e))}finally{S(null)}}},j=e=>{let t=g(e);t.length&&(e.preventDefault(),A(t))},M=(0,_.useRef)(null);M.current=e=>A(m(e)),(0,_.useEffect)(()=>{let e=e=>Array.from(e.dataTransfer&&e.dataTransfer.types||[]).includes(`Files`),t=t=>{e(t)&&(t.preventDefault(),w(!0))},n=e=>{e.relatedTarget||w(!1)},r=t=>{e(t)&&(t.preventDefault(),w(!1),M.current&&M.current(t))};return window.addEventListener(`dragover`,t),window.addEventListener(`dragleave`,n),window.addEventListener(`drop`,r),()=>{window.removeEventListener(`dragover`,t),window.removeEventListener(`dragleave`,n),window.removeEventListener(`drop`,r)}},[]);let N=()=>{if(f)return;if(!String(D.current).trim()){a(`正文不能为空`);return}let i={group:n,ref:e.text,pick:t,matchTopic:e.topic,text:D.current};l!==(e.note||``)&&(i.note=l),y(!0),d(`/api/todo/item`,{method:`PATCH`,body:i}).then(()=>{a(`已保存`),r()}).catch(e=>a(String(e&&e.message||e))).finally(()=>y(!1))},P=e=>{(e.ctrlKey||e.metaKey)&&e.key===`Enter`&&(e.preventDefault(),N())},F=x?`上传中 ${x.done}/${x.total}…`:`选择文件上传`,I=!String(o).trim();return(0,v.jsxs)(`div`,{className:`editor`+(C?` drag`:``),children:[(0,v.jsxs)(`div`,{className:`ed-tip`,children:[`粘贴(`,(0,v.jsx)(`kbd`,{children:`Ctrl`}),`+`,(0,v.jsx)(`kbd`,{children:`V`}),` 截图)、拖文件进来,或`,(0,v.jsx)(`button`,{type:`button`,className:`ed-link`,onClick:()=>E.current&&E.current.click(),disabled:!!x,children:`选择文件`}),`—— 会自动上传并插到光标处。`,(0,v.jsx)(`input`,{ref:E,type:`file`,multiple:!0,hidden:!0,onChange:e=>{let t=Array.from(e.target.files||[]);e.target.value=``,A(t)}})]}),(0,v.jsxs)(`div`,{className:`ed-field`,children:[(0,v.jsx)(`div`,{className:`ed-label`,children:`正文`}),(0,v.jsx)(`textarea`,{ref:T,className:`ed-textarea`,rows:4,value:o,spellCheck:`false`,placeholder:`要做什么… 图片写 ![说明](fileId),其他文件写 [文件名](fileId)`,onChange:e=>O(e.target.value),onPaste:j,onKeyDown:P}),(0,v.jsxs)(`div`,{className:`ed-meta`,children:[(0,v.jsxs)(`span`,{className:`ed-acts`,children:[(0,v.jsx)(`button`,{type:`button`,className:`btn small`,onClick:()=>E.current&&E.current.click(),disabled:!!x,children:F}),(0,v.jsxs)(`span`,{className:`hint`,children:[`图片 `,(0,v.jsx)(`code`,{children:`![说明](id)`}),` 文件 `,(0,v.jsx)(`code`,{children:`[文件名](id)`})]})]}),(0,v.jsxs)(`span`,{className:`hint`,children:[o.length,` 字符`]})]})]}),(0,v.jsxs)(`div`,{className:`ed-field`,children:[(0,v.jsx)(`div`,{className:`ed-label`,children:`预览`}),(0,v.jsx)(`div`,{className:`preview`+(I?` empty`:``),children:I?(0,v.jsx)(`span`,{className:`muted`,children:`(暂无内容)`}):(0,v.jsx)(b,{text:o})})]}),(0,v.jsxs)(`div`,{className:`ed-field`,children:[(0,v.jsx)(`div`,{className:`ed-label`,children:`备注`}),(0,v.jsx)(`textarea`,{className:`ed-textarea`,rows:2,value:l,spellCheck:`false`,placeholder:`可选:完成结果、上下文补充`,onChange:e=>u(e.target.value)})]}),(0,v.jsxs)(`div`,{className:`ed-foot`,children:[(0,v.jsxs)(`span`,{className:`hint`,children:[(0,v.jsx)(`kbd`,{children:`Ctrl`}),`+`,(0,v.jsx)(`kbd`,{children:`Enter`}),` 保存`]}),(0,v.jsxs)(`span`,{className:`ed-acts`,children:[(0,v.jsx)(`button`,{className:`btn ghost`,onClick:i,disabled:f,children:`取消`}),(0,v.jsx)(`button`,{className:`btn`,onClick:N,disabled:f||!!x,children:f?`保存中…`:`保存`})]})]})]})}function S({onClose:e}){let{boot:t,refreshBoot:n}=u(),r=c(),a=i(),{dialog:f,node:p}=o(),[m,h]=(0,_.useState)([]),[g,y]=(0,_.useState)(``),[b,x]=(0,_.useState)({name:``,description:``}),[S,C]=(0,_.useState)(null),w=(0,_.useCallback)(async()=>{try{let e=await d(`/api/groups`);h(e.groups||[]),y(``)}catch(e){y(e.message||String(e))}},[]);(0,_.useEffect)(()=>{w()},[w]);let T=t?.groupId??0,E=e=>a(async()=>{let t=await d(`/api/group`,{method:`POST`,body:{locator:e}});r(t.id===0?`已切回默认组`:`已切换到 ${t.name}`),await n(),await w()}),D=()=>a(async()=>{let e=b.name.trim();if(!e){r(`请填名称`);return}let t=await d(`/api/groups`,{method:`POST`,body:{name:e,description:b.description.trim()}});x({name:``,description:``}),r(`已新建工作空间 ${t.name}(id=${t.id})`),await n(),await w()}),O=e=>a(async()=>{let t=await f({title:`重命名「${e.name}」`,input:!0,value:e.name});t!==null&&t.trim()&&(await d(`/api/groups/${e.id}`,{method:`PATCH`,body:{name:t.trim()}}),r(`已更新名称`),await n(),await w())}),k=e=>a(async()=>{await f({message:`解散工作空间「${e.name}」(id=${e.id})?\n\n后端要求组内已无 KV 数据,否则会拒绝。此操作不可撤销。`,danger:!0})&&(await d(`/api/groups/${e.id}`,{method:`DELETE`}),r(`已解散 ${e.name}`),await n(),await w())}),A=e=>a(async()=>{let t=await d(`/api/groups/${e.id}/members`);C({group:t.group,list:t.members||[]})});return t?.loggedIn?(0,v.jsxs)(v.Fragment,{children:[(0,v.jsxs)(s,{title:`工作空间`,onClose:e,children:[(0,v.jsx)(`div`,{className:`muted`,style:{marginBottom:8},children:`清单按工作空间隔离读写。切换只改本机配置,不动服务端数据。`}),g?(0,v.jsx)(`div`,{className:`row muted`,children:g}):null,(0,v.jsxs)(`div`,{className:`list`,children:[(0,v.jsxs)(`div`,{className:`row`,children:[(0,v.jsx)(`span`,{className:`name`,children:`默认组`}),(0,v.jsx)(`span`,{className:`desc`,children:`不传 groupId,由后端回落`}),(0,v.jsx)(`span`,{className:`acts`,children:T===0?(0,v.jsx)(`span`,{className:`tag strong`,children:`当前`}):(0,v.jsx)(`button`,{className:`btn small`,onClick:()=>E(`default`),children:`切到这里`})})]}),m.map(e=>(0,v.jsxs)(`div`,{className:`row`,children:[(0,v.jsx)(l,{className:`name`,text:e.name,title:`点击复制名称`,children:e.name}),(0,v.jsx)(`span`,{className:`tag`,children:e.myRole||`member`}),e.description?(0,v.jsx)(`span`,{className:`desc`,children:e.description}):null,(0,v.jsxs)(`span`,{className:`muted mono`,children:[`id=`,e.id]}),(0,v.jsxs)(`span`,{className:`muted`,children:[e.memberCount,` 人`]}),(0,v.jsxs)(`span`,{className:`acts`,children:[e.id===T?(0,v.jsx)(`span`,{className:`tag strong`,children:`当前`}):(0,v.jsx)(`button`,{className:`btn small`,onClick:()=>E(String(e.id)),children:`切到这里`}),(0,v.jsx)(`button`,{className:`btn small ghost`,onClick:()=>A(e),children:`成员`}),(0,v.jsx)(`button`,{className:`btn small ghost`,onClick:()=>O(e),children:`改名`}),(0,v.jsx)(`button`,{className:`btn small ghost danger`,onClick:()=>k(e),children:`解散`})]})]},e.id)),!g&&!m.length?(0,v.jsx)(`div`,{className:`row muted`,children:`(没有其他工作空间)`}):null]}),(0,v.jsxs)(`div`,{className:`toolbar`,style:{marginTop:10},children:[(0,v.jsx)(`input`,{placeholder:`新工作空间名称`,size:`16`,value:b.name,onChange:e=>x({...b,name:e.target.value}),onKeyDown:e=>{e.key===`Enter`&&D()}}),(0,v.jsx)(`input`,{placeholder:`描述(可选)`,size:`20`,value:b.description,onChange:e=>x({...b,description:e.target.value})}),(0,v.jsx)(`button`,{className:`btn`,onClick:D,children:`新建`}),(0,v.jsx)(`button`,{className:`btn ghost`,onClick:()=>a(w),children:`刷新`})]})]}),S?(0,v.jsx)(s,{title:`成员 · ${S.group.name}`,onClose:()=>C(null),children:(0,v.jsx)(`div`,{className:`list`,children:S.list.length?S.list.map(e=>(0,v.jsxs)(`div`,{className:`row`,children:[(0,v.jsx)(l,{className:`name`,text:e.email,title:`点击复制邮箱`,children:e.email}),(0,v.jsx)(`span`,{className:`tag`,children:e.role||`member`}),(0,v.jsx)(`span`,{className:`muted`,children:e.nickname})]},e.userId)):(0,v.jsx)(`div`,{className:`row muted`,children:`(没有成员)`})})}):null,p]}):(0,v.jsx)(s,{title:`工作空间`,onClose:e,children:(0,v.jsx)(`div`,{className:`muted`,children:`工作空间需要登录后才能列出。`})})}var C=[[`open`,`待办`],[`done`,`已完成`],[`freeze`,`冻结`]],w=e=>e?String(e).slice(0,16).replace(`T`,` `):``,T=15,E=(e,t)=>`${e}:${t.id}:${t.text}`;function D({bucket:t,task:n,dupCount:r,onAct:i}){let a=t===`done`,o=t===`freeze`,s=a?n.doneAt:o?n.frozenAt:n.createdAt;return(0,v.jsxs)(`div`,{className:`row cloud-row`,children:[(0,v.jsxs)(`div`,{className:`row-main`,children:[(0,v.jsxs)(`span`,{className:`tid`,children:[`#`,n.id]}),(0,v.jsx)(l,{className:`topic`,text:n.topic,title:`点击复制主题`,children:n.topic}),(0,v.jsx)(`span`,{className:`text`,title:n.text,children:(0,v.jsx)(b,{text:n.text,compact:!0})}),r>1?(0,v.jsxs)(`span`,{className:`tag`,title:`同内容有 ${r} 条,操作时需要消歧`,children:[`同内容×`,r]}):null,(0,v.jsx)(`span`,{className:`muted time`,children:w(s)}),(0,v.jsxs)(`span`,{className:`acts`,children:[t===`open`?(0,v.jsx)(`button`,{className:`btn small ghost`,onClick:()=>i(`done`,n),children:`完成`}):null,o?(0,v.jsx)(`button`,{className:`btn small ghost`,onClick:()=>i(`unfreeze`,n),children:`解冻`}):null,(0,v.jsx)(e,{items:[t===`open`&&{label:`冻结`,onPick:()=>i(`freeze`,n)},{label:`编辑`,onPick:()=>i(`edit`,n,t)},{label:`删除`,danger:!0,onPick:()=>i(`remove`,n,t)}]})]})]}),n.note?(0,v.jsx)(`div`,{className:`note`,children:n.note}):null]})}function O(){let{boot:e,ui:t,patchUi:n,refreshBoot:r}=u(),a=c(),m=i(),{dialog:y,node:b}=o(),[O,k]=(0,_.useState)(null),[A,j]=(0,_.useState)(``),[M,N]=(0,_.useState)(!1),[P,F]=(0,_.useState)({topic:``,text:``}),[I,L]=(0,_.useState)(null),[ee,R]=(0,_.useState)(!1),[z,B]=(0,_.useState)({}),[V,H]=(0,_.useState)(null),[U,W]=(0,_.useState)(null),G=e?.groupId??0,te=(e?.groups||[]).find(e=>e.id===G)?.name||(G?`#${G}`:`默认组`),[K,q]=(0,_.useState)({email:e?.email||``,password:``,busy:!1,open:!1}),J=()=>m(async()=>{if(!K.email.trim()){a(`请填邮箱`);return}if(!K.password){a(`请填密码`);return}q(e=>({...e,busy:!0}));try{let e=await d(`/api/auth/login`,{method:`POST`,body:{email:K.email.trim(),password:K.password}});q(e=>({...e,password:``})),a(`已登录: ${e.email}`),await r()}finally{q(e=>({...e,busy:!1}))}}),ne=()=>m(async()=>{await d(`/api/auth/logout`,{method:`POST`}),a(`已登出`),await r()}),Y=(0,_.useCallback)(async()=>{if(e?.loggedIn)try{k(await d(`/api/todo`)),j(``)}catch(e){j(String(e.message||e))}},[e?.loggedIn]);(0,_.useEffect)(()=>{Y()},[Y,G]),(0,_.useEffect)(()=>{d(`/api/setting`).then(W).catch(()=>{})},[]);let X=!!U?.autoSyncAttachments,re=()=>m(async()=>{let e=!X,t=await d(`/api/setting`,{method:`POST`,body:{autoSyncAttachments:e}});W(t),a(e?`已开启:读任务时自动下载附件到本地`:`已关闭自动下载附件`)}),Z=(0,_.useCallback)(async()=>{N(!0);try{await Y()}finally{N(!1)}},[Y]),ie=(0,_.useMemo)(()=>{let e=new Map;if(!O)return e;for(let[t]of C)for(let n of O[t]||[])e.set(n.text,(e.get(n.text)||0)+1);return e},[O]),Q=(0,_.useMemo)(()=>{if(!O)return null;let e=t.topic,n=t=>t?e?t.filter(t=>t.topic===e):t:null;return{open:n(O.open),done:n(O.done),freeze:n(O.freeze)}},[O,t.topic]);if(!e?.loggedIn)return(0,v.jsxs)(`div`,{className:`cloud-page`,children:[(0,v.jsx)(f,{}),(0,v.jsxs)(`div`,{className:`card`,style:{padding:16,maxWidth:640},children:[(0,v.jsxs)(`div`,{className:`colhead`,children:[(0,v.jsx)(`h3`,{children:`登录云端`}),(0,v.jsx)(`span`,{className:`tag bad`,children:`未登录`})]}),(0,v.jsxs)(`div`,{className:`row-inline`,style:{padding:12},children:[(0,v.jsx)(`input`,{placeholder:`邮箱`,size:`24`,spellCheck:`false`,value:K.email,onChange:e=>q(t=>({...t,email:e.target.value}))}),(0,v.jsx)(`input`,{placeholder:`密码`,type:`password`,size:`18`,value:K.password,onChange:e=>q(t=>({...t,password:e.target.value})),onKeyDown:e=>{e.key===`Enter`&&J()}}),(0,v.jsx)(`button`,{className:`btn`,onClick:J,disabled:K.busy,children:K.busy?`登录中…`:`登录`})]}),(0,v.jsxs)(`div`,{className:`muted`,style:{padding:`0 12px 12px`,fontSize:12},children:[`密码只用于本次请求,不写入本机配置;配置里只保存 token。 也可以用 CLI:`,(0,v.jsx)(`code`,{children:`nx-kv auth login <email>`}),`。`]})]})]});let ae=async(e,t)=>{let n=[];for(let[t]of C)for(let r of O[t]||[])r.text===e.text&&n.push({bucket:t,task:r});if(n.length<=1)return{bucket:t,task:e,pick:void 0};let r=n.findIndex(n=>n.bucket===t&&n.task.createdAt===e.createdAt),i=await y({title:`「${e.text.slice(0,30)}」有 ${n.length} 条,选哪一条?`,message:n.map((e,t)=>`[${t}] ${e.bucket} ${w(e.task.createdAt)} #${e.task.id}`).join(`
1
+ import{a as e,d as t,f as n,h as r,l as i,n as a,o,r as s,u as c}from"./attach-v8BxRJ7p.js";import{G as l,K as u,q as d}from"./index-CHHRdALV.js";import{t as f}from"./route-crumb-x1Za8gFU.js";import{i as p,n as m,r as h,t as g}from"./upload-BM8dlfZG.js";var _=r(n(),1),v=t(),y=e=>`/api/file/content/${encodeURIComponent(e)}`;function b({text:e,compact:t=!1,className:n=``}){let r=a(e);return r.some(e=>e.type!==`text`)?(0,v.jsx)(`span`,{className:n?`mdtext ${n}`:`mdtext`,children:r.map((e,n)=>{if(e.type===`text`)return(0,v.jsx)(`span`,{className:`mdtext-plain`,children:e.value},n);let r=y(e.id);return e.type===`image`?(0,v.jsx)(`a`,{className:`embed-image`+(t?` compact`:``),href:r,target:`_blank`,rel:`noreferrer`,title:e.alt?`${e.alt}(点击看原图)`:e.id,children:(0,v.jsx)(`img`,{src:r,alt:e.alt||e.id,loading:`lazy`})},n):(0,v.jsx)(`a`,{className:`embed-file`,href:r,target:`_blank`,rel:`noreferrer`,title:e.id,children:e.alt||e.id},n)})}):(0,v.jsx)(`span`,{className:n,children:e})}function x({task:e,pick:t,group:n,onSaved:r,onCancel:i}){let a=c(),[o,s]=(0,_.useState)(e.text||``),[l,u]=(0,_.useState)(e.note||``),[f,y]=(0,_.useState)(!1),[x,S]=(0,_.useState)(null),[C,w]=(0,_.useState)(!1),T=(0,_.useRef)(null),E=(0,_.useRef)(null),D=(0,_.useRef)(o),O=e=>{D.current=e,s(e)};(0,_.useEffect)(()=>{let e=T.current;e&&(e.focus(),e.setSelectionRange(e.value.length,e.value.length))},[]);let k=e=>{if(!e)return;let t=T.current,n=D.current,r=t&&t.selectionStart!==null?t.selectionStart:n.length,i=t&&t.selectionEnd!==null?t.selectionEnd:r,a=n.slice(0,r),o=n.slice(i),s=a&&!/\s$/.test(a)?` `:``,c=`${a}${s}${e}${o&&!/^\s/.test(o)?` `:``}${o}`;O(c);let l=a.length+s.length+e.length;requestAnimationFrame(()=>{let e=T.current;e&&(e.focus(),e.setSelectionRange(l,l))})},A=async e=>{let t=Array.from(e||[]).filter(e=>e&&e.size>0);if(t.length&&!x){S({done:0,total:t.length});try{let e=await p(t,{group:n,onProgress:(e,t)=>S({done:e,total:t})});k(h(e));let r=e.filter(e=>e.isImage).length;a(e.length===1?`已插入 ${e[0].name}`:`已插入 ${e.length} 个附件${r?`(图片 ${r} 个)`:``}`)}catch(e){a(String(e&&e.message||e))}finally{S(null)}}},j=e=>{let t=g(e);t.length&&(e.preventDefault(),A(t))},M=(0,_.useRef)(null);M.current=e=>A(m(e)),(0,_.useEffect)(()=>{let e=e=>Array.from(e.dataTransfer&&e.dataTransfer.types||[]).includes(`Files`),t=t=>{e(t)&&(t.preventDefault(),w(!0))},n=e=>{e.relatedTarget||w(!1)},r=t=>{e(t)&&(t.preventDefault(),w(!1),M.current&&M.current(t))};return window.addEventListener(`dragover`,t),window.addEventListener(`dragleave`,n),window.addEventListener(`drop`,r),()=>{window.removeEventListener(`dragover`,t),window.removeEventListener(`dragleave`,n),window.removeEventListener(`drop`,r)}},[]);let N=()=>{if(f)return;if(!String(D.current).trim()){a(`正文不能为空`);return}let i={group:n,ref:e.text,pick:t,matchTopic:e.topic,text:D.current};l!==(e.note||``)&&(i.note=l),y(!0),d(`/api/todo/item`,{method:`PATCH`,body:i}).then(()=>{a(`已保存`),r()}).catch(e=>a(String(e&&e.message||e))).finally(()=>y(!1))},P=e=>{(e.ctrlKey||e.metaKey)&&e.key===`Enter`&&(e.preventDefault(),N())},F=x?`上传中 ${x.done}/${x.total}…`:`选择文件上传`,I=!String(o).trim();return(0,v.jsxs)(`div`,{className:`editor`+(C?` drag`:``),children:[(0,v.jsxs)(`div`,{className:`ed-tip`,children:[`粘贴(`,(0,v.jsx)(`kbd`,{children:`Ctrl`}),`+`,(0,v.jsx)(`kbd`,{children:`V`}),` 截图)、拖文件进来,或`,(0,v.jsx)(`button`,{type:`button`,className:`ed-link`,onClick:()=>E.current&&E.current.click(),disabled:!!x,children:`选择文件`}),`—— 会自动上传并插到光标处。`,(0,v.jsx)(`input`,{ref:E,type:`file`,multiple:!0,hidden:!0,onChange:e=>{let t=Array.from(e.target.files||[]);e.target.value=``,A(t)}})]}),(0,v.jsxs)(`div`,{className:`ed-field`,children:[(0,v.jsx)(`div`,{className:`ed-label`,children:`正文`}),(0,v.jsx)(`textarea`,{ref:T,className:`ed-textarea`,rows:4,value:o,spellCheck:`false`,placeholder:`要做什么… 图片写 ![说明](fileId),其他文件写 [文件名](fileId)`,onChange:e=>O(e.target.value),onPaste:j,onKeyDown:P}),(0,v.jsxs)(`div`,{className:`ed-meta`,children:[(0,v.jsxs)(`span`,{className:`ed-acts`,children:[(0,v.jsx)(`button`,{type:`button`,className:`btn small`,onClick:()=>E.current&&E.current.click(),disabled:!!x,children:F}),(0,v.jsxs)(`span`,{className:`hint`,children:[`图片 `,(0,v.jsx)(`code`,{children:`![说明](id)`}),` 文件 `,(0,v.jsx)(`code`,{children:`[文件名](id)`})]})]}),(0,v.jsxs)(`span`,{className:`hint`,children:[o.length,` 字符`]})]})]}),(0,v.jsxs)(`div`,{className:`ed-field`,children:[(0,v.jsx)(`div`,{className:`ed-label`,children:`预览`}),(0,v.jsx)(`div`,{className:`preview`+(I?` empty`:``),children:I?(0,v.jsx)(`span`,{className:`muted`,children:`(暂无内容)`}):(0,v.jsx)(b,{text:o})})]}),(0,v.jsxs)(`div`,{className:`ed-field`,children:[(0,v.jsx)(`div`,{className:`ed-label`,children:`备注`}),(0,v.jsx)(`textarea`,{className:`ed-textarea`,rows:2,value:l,spellCheck:`false`,placeholder:`可选:完成结果、上下文补充`,onChange:e=>u(e.target.value)})]}),(0,v.jsxs)(`div`,{className:`ed-foot`,children:[(0,v.jsxs)(`span`,{className:`hint`,children:[(0,v.jsx)(`kbd`,{children:`Ctrl`}),`+`,(0,v.jsx)(`kbd`,{children:`Enter`}),` 保存`]}),(0,v.jsxs)(`span`,{className:`ed-acts`,children:[(0,v.jsx)(`button`,{className:`btn ghost`,onClick:i,disabled:f,children:`取消`}),(0,v.jsx)(`button`,{className:`btn`,onClick:N,disabled:f||!!x,children:f?`保存中…`:`保存`})]})]})]})}function S({onClose:e}){let{boot:t,refreshBoot:n}=u(),r=c(),a=i(),{dialog:f,node:p}=o(),[m,h]=(0,_.useState)([]),[g,y]=(0,_.useState)(``),[b,x]=(0,_.useState)({name:``,description:``}),[S,C]=(0,_.useState)(null),w=(0,_.useCallback)(async()=>{try{let e=await d(`/api/groups`);h(e.groups||[]),y(``)}catch(e){y(e.message||String(e))}},[]);(0,_.useEffect)(()=>{w()},[w]);let T=t?.groupId??0,E=e=>a(async()=>{let t=await d(`/api/group`,{method:`POST`,body:{locator:e}});r(t.id===0?`已切回默认组`:`已切换到 ${t.name}`),await n(),await w()}),D=()=>a(async()=>{let e=b.name.trim();if(!e){r(`请填名称`);return}let t=await d(`/api/groups`,{method:`POST`,body:{name:e,description:b.description.trim()}});x({name:``,description:``}),r(`已新建工作空间 ${t.name}(id=${t.id})`),await n(),await w()}),O=e=>a(async()=>{let t=await f({title:`重命名「${e.name}」`,input:!0,value:e.name});t!==null&&t.trim()&&(await d(`/api/groups/${e.id}`,{method:`PATCH`,body:{name:t.trim()}}),r(`已更新名称`),await n(),await w())}),k=e=>a(async()=>{await f({message:`解散工作空间「${e.name}」(id=${e.id})?\n\n后端要求组内已无 KV 数据,否则会拒绝。此操作不可撤销。`,danger:!0})&&(await d(`/api/groups/${e.id}`,{method:`DELETE`}),r(`已解散 ${e.name}`),await n(),await w())}),A=e=>a(async()=>{let t=await d(`/api/groups/${e.id}/members`);C({group:t.group,list:t.members||[]})});return t?.loggedIn?(0,v.jsxs)(v.Fragment,{children:[(0,v.jsxs)(s,{title:`工作空间`,onClose:e,children:[(0,v.jsx)(`div`,{className:`muted`,style:{marginBottom:8},children:`清单按工作空间隔离读写。切换只改本机配置,不动服务端数据。`}),g?(0,v.jsx)(`div`,{className:`row muted`,children:g}):null,(0,v.jsxs)(`div`,{className:`list`,children:[(0,v.jsxs)(`div`,{className:`row`,children:[(0,v.jsx)(`span`,{className:`name`,children:`默认组`}),(0,v.jsx)(`span`,{className:`desc`,children:`不传 groupId,由后端回落`}),(0,v.jsx)(`span`,{className:`acts`,children:T===0?(0,v.jsx)(`span`,{className:`tag strong`,children:`当前`}):(0,v.jsx)(`button`,{className:`btn small`,onClick:()=>E(`default`),children:`切到这里`})})]}),m.map(e=>(0,v.jsxs)(`div`,{className:`row`,children:[(0,v.jsx)(l,{className:`name`,text:e.name,title:`点击复制名称`,children:e.name}),(0,v.jsx)(`span`,{className:`tag`,children:e.myRole||`member`}),e.description?(0,v.jsx)(`span`,{className:`desc`,children:e.description}):null,(0,v.jsxs)(`span`,{className:`muted mono`,children:[`id=`,e.id]}),(0,v.jsxs)(`span`,{className:`muted`,children:[e.memberCount,` 人`]}),(0,v.jsxs)(`span`,{className:`acts`,children:[e.id===T?(0,v.jsx)(`span`,{className:`tag strong`,children:`当前`}):(0,v.jsx)(`button`,{className:`btn small`,onClick:()=>E(String(e.id)),children:`切到这里`}),(0,v.jsx)(`button`,{className:`btn small ghost`,onClick:()=>A(e),children:`成员`}),(0,v.jsx)(`button`,{className:`btn small ghost`,onClick:()=>O(e),children:`改名`}),(0,v.jsx)(`button`,{className:`btn small ghost danger`,onClick:()=>k(e),children:`解散`})]})]},e.id)),!g&&!m.length?(0,v.jsx)(`div`,{className:`row muted`,children:`(没有其他工作空间)`}):null]}),(0,v.jsxs)(`div`,{className:`toolbar`,style:{marginTop:10},children:[(0,v.jsx)(`input`,{placeholder:`新工作空间名称`,size:`16`,value:b.name,onChange:e=>x({...b,name:e.target.value}),onKeyDown:e=>{e.key===`Enter`&&D()}}),(0,v.jsx)(`input`,{placeholder:`描述(可选)`,size:`20`,value:b.description,onChange:e=>x({...b,description:e.target.value})}),(0,v.jsx)(`button`,{className:`btn`,onClick:D,children:`新建`}),(0,v.jsx)(`button`,{className:`btn ghost`,onClick:()=>a(w),children:`刷新`})]})]}),S?(0,v.jsx)(s,{title:`成员 · ${S.group.name}`,onClose:()=>C(null),children:(0,v.jsx)(`div`,{className:`list`,children:S.list.length?S.list.map(e=>(0,v.jsxs)(`div`,{className:`row`,children:[(0,v.jsx)(l,{className:`name`,text:e.email,title:`点击复制邮箱`,children:e.email}),(0,v.jsx)(`span`,{className:`tag`,children:e.role||`member`}),(0,v.jsx)(`span`,{className:`muted`,children:e.nickname})]},e.userId)):(0,v.jsx)(`div`,{className:`row muted`,children:`(没有成员)`})})}):null,p]}):(0,v.jsx)(s,{title:`工作空间`,onClose:e,children:(0,v.jsx)(`div`,{className:`muted`,children:`工作空间需要登录后才能列出。`})})}var C=[[`open`,`待办`],[`done`,`已完成`],[`freeze`,`冻结`]],w=e=>e?String(e).slice(0,16).replace(`T`,` `):``,T=15,E=(e,t)=>`${e}:${t.id}:${t.text}`;function D({bucket:t,task:n,dupCount:r,onAct:i}){let a=t===`done`,o=t===`freeze`,s=a?n.doneAt:o?n.frozenAt:n.createdAt;return(0,v.jsxs)(`div`,{className:`row cloud-row`,children:[(0,v.jsxs)(`div`,{className:`row-main`,children:[(0,v.jsxs)(`span`,{className:`tid`,children:[`#`,n.id]}),(0,v.jsx)(l,{className:`topic`,text:n.topic,title:`点击复制主题`,children:n.topic}),(0,v.jsx)(`span`,{className:`text`,title:n.text,children:(0,v.jsx)(b,{text:n.text,compact:!0})}),r>1?(0,v.jsxs)(`span`,{className:`tag`,title:`同内容有 ${r} 条,操作时需要消歧`,children:[`同内容×`,r]}):null,(0,v.jsx)(`span`,{className:`muted time`,children:w(s)}),(0,v.jsxs)(`span`,{className:`acts`,children:[t===`open`?(0,v.jsx)(`button`,{className:`btn small ghost`,onClick:()=>i(`done`,n),children:`完成`}):null,o?(0,v.jsx)(`button`,{className:`btn small ghost`,onClick:()=>i(`unfreeze`,n),children:`解冻`}):null,(0,v.jsx)(e,{items:[t===`open`&&{label:`冻结`,onPick:()=>i(`freeze`,n)},{label:`编辑`,onPick:()=>i(`edit`,n,t)},{label:`删除`,danger:!0,onPick:()=>i(`remove`,n,t)}]})]})]}),n.note?(0,v.jsx)(`div`,{className:`note`,children:n.note}):null]})}function O(){let{boot:e,ui:t,patchUi:n,refreshBoot:r}=u(),a=c(),m=i(),{dialog:y,node:b}=o(),[O,k]=(0,_.useState)(null),[A,j]=(0,_.useState)(``),[M,N]=(0,_.useState)(!1),[P,F]=(0,_.useState)({topic:``,text:``}),[I,L]=(0,_.useState)(null),[ee,R]=(0,_.useState)(!1),[z,B]=(0,_.useState)({}),[V,H]=(0,_.useState)(null),[U,W]=(0,_.useState)(null),G=e?.groupId??0,te=(e?.groups||[]).find(e=>e.id===G)?.name||(G?`#${G}`:`默认组`),[K,q]=(0,_.useState)({email:e?.email||``,password:``,busy:!1,open:!1}),J=()=>m(async()=>{if(!K.email.trim()){a(`请填邮箱`);return}if(!K.password){a(`请填密码`);return}q(e=>({...e,busy:!0}));try{let e=await d(`/api/auth/login`,{method:`POST`,body:{email:K.email.trim(),password:K.password}});q(e=>({...e,password:``})),a(`已登录: ${e.email}`),await r()}finally{q(e=>({...e,busy:!1}))}}),ne=()=>m(async()=>{await d(`/api/auth/logout`,{method:`POST`}),a(`已登出`),await r()}),Y=(0,_.useCallback)(async()=>{if(e?.loggedIn)try{k(await d(`/api/todo`)),j(``)}catch(e){j(String(e.message||e))}},[e?.loggedIn]);(0,_.useEffect)(()=>{Y()},[Y,G]),(0,_.useEffect)(()=>{d(`/api/setting`).then(W).catch(()=>{})},[]);let X=!!U?.autoSyncAttachments,re=()=>m(async()=>{let e=!X,t=await d(`/api/setting`,{method:`POST`,body:{autoSyncAttachments:e}});W(t),a(e?`已开启:读任务时自动下载附件到本地`:`已关闭自动下载附件`)}),Z=(0,_.useCallback)(async()=>{N(!0);try{await Y()}finally{N(!1)}},[Y]),ie=(0,_.useMemo)(()=>{let e=new Map;if(!O)return e;for(let[t]of C)for(let n of O[t]||[])e.set(n.text,(e.get(n.text)||0)+1);return e},[O]),Q=(0,_.useMemo)(()=>{if(!O)return null;let e=t.topic,n=t=>t?e?t.filter(t=>t.topic===e):t:null;return{open:n(O.open),done:n(O.done),freeze:n(O.freeze)}},[O,t.topic]);if(!e?.loggedIn)return(0,v.jsxs)(`div`,{className:`cloud-page`,children:[(0,v.jsx)(f,{}),(0,v.jsxs)(`div`,{className:`card`,style:{padding:16,maxWidth:640},children:[(0,v.jsxs)(`div`,{className:`colhead`,children:[(0,v.jsx)(`h3`,{children:`登录云端`}),(0,v.jsx)(`span`,{className:`tag bad`,children:`未登录`})]}),(0,v.jsxs)(`div`,{className:`row-inline`,style:{padding:12},children:[(0,v.jsx)(`input`,{placeholder:`邮箱`,size:`24`,spellCheck:`false`,value:K.email,onChange:e=>q(t=>({...t,email:e.target.value}))}),(0,v.jsx)(`input`,{placeholder:`密码`,type:`password`,size:`18`,value:K.password,onChange:e=>q(t=>({...t,password:e.target.value})),onKeyDown:e=>{e.key===`Enter`&&J()}}),(0,v.jsx)(`button`,{className:`btn`,onClick:J,disabled:K.busy,children:K.busy?`登录中…`:`登录`})]}),(0,v.jsxs)(`div`,{className:`muted`,style:{padding:`0 12px 12px`,fontSize:12},children:[`密码只用于本次请求,不写入本机配置;配置里只保存 token。 也可以用 CLI:`,(0,v.jsx)(`code`,{children:`nx-kv auth login <email>`}),`。`]})]})]});let ae=async(e,t)=>{let n=[];for(let[t]of C)for(let r of O[t]||[])r.text===e.text&&n.push({bucket:t,task:r});if(n.length<=1)return{bucket:t,task:e,pick:void 0};let r=n.findIndex(n=>n.bucket===t&&n.task.createdAt===e.createdAt),i=await y({title:`「${e.text.slice(0,30)}」有 ${n.length} 条,选哪一条?`,message:n.map((e,t)=>`[${t}] ${e.bucket} ${w(e.task.createdAt)} #${e.task.id}`).join(`
2
2
  `),input:!0,placeholder:`输入 0..${n.length-1}`,value:String(r>=0?r:0)});if(i===null)return null;let o=Number(i);return!Number.isInteger(o)||!n[o]?(a(`请输入 0..${n.length-1}`),null):{...n[o],pick:o}},oe=(e,t,n)=>m(async()=>{let i=e===`remove`||e===`edit`?await ae(t,n):{bucket:n,task:t,pick:void 0};if(!i)return;let o={group:G,ref:i.task.text,pick:i.pick};if(e===`done`){let e=await y({title:`完成结果`,message:`完成「${t.text.slice(0,40)}」`,input:!0,placeholder:`可选:写一句完成结果`});if(e===null)return;await d(`/api/todo/done`,{method:`POST`,body:{...o,result:e||void 0}}),a(`已完成`)}else if(e===`freeze`)await d(`/api/todo/freeze`,{method:`POST`,body:o}),a(`已冻结`);else if(e===`unfreeze`)await d(`/api/todo/unfreeze`,{method:`POST`,body:o}),a(`已解冻`);else if(e===`remove`){if(!await y({message:`删除「${t.text.slice(0,40)}」?`,danger:!0}))return;await d(`/api/todo/item`,{method:`DELETE`,body:o}),a(`已删除`)}else if(e===`edit`){H({task:i.task,pick:i.pick});return}await Z(),await r()}),se=()=>m(async()=>{let e=await y({title:`归档已完成的旧记录`,message:`把「完成时间早于该日期」的记录移到冷 key(默认 30 天前)。留空用默认值。`,input:!0,placeholder:`YYYY-MM-DD,留空 = 30 天前`});if(e===null)return;let t=await d(`/api/todo/archive`,{method:`POST`,body:{before:e.trim()||void 0,group:G}});a(t.moved?`已归档 ${t.moved} 条 → ${t.coldKey}`:`没有需要归档的记录`),await Z()}),ce=async e=>{let t=g(e);if(t.length){e.preventDefault();try{let e=await p(t,{group:G}),n=h(e);F(e=>({...e,text:[e.text,n].filter(Boolean).join(` `)})),a(e.length===1?`已上传 ${e[0].name} 并附到内容里`:`已上传 ${e.length} 个附件并附到内容里`)}catch(e){a(String(e&&e.message||e))}}},$=()=>m(async()=>{let e=P.topic.trim(),t=P.text.trim();if(!e){a(`请填主题`);return}if(!t){a(`请填内容`);return}let n=await d(`/api/todo`,{method:`POST`,body:{topic:e,text:t,group:G}});F({topic:e,text:``}),a(`已加入待办${n.topicAdded?`(新主题 ${e})`:``}`),await Z()}),le=(e,t)=>z[e]?t:t.slice(0,T),ue=O?.topics||[];return(0,v.jsxs)(`div`,{className:`cloud-page`,children:[(0,v.jsxs)(`div`,{className:`cloud-toolbar`,children:[(0,v.jsxs)(`button`,{className:`pill on rp-ws-trigger`,title:`切换工作空间 / 管理(清单按工作空间隔离)`,onClick:()=>R(!0),children:[te,` `,(0,v.jsx)(`span`,{className:`rp-caret`,children:`▾`})]}),(0,v.jsx)(`span`,{className:`sep`}),(0,v.jsx)(`label`,{children:`主题`}),(0,v.jsxs)(`select`,{value:t.topic,onChange:e=>n({topic:e.target.value}),children:[(0,v.jsx)(`option`,{value:``,children:`全部`}),ue.map(e=>(0,v.jsx)(`option`,{value:e,children:e},e))]}),(0,v.jsx)(`span`,{className:`grow`}),(0,v.jsxs)(`label`,{className:`toggle`+(X?` on`:``),title:`开启后,读取任务时会把正文引用的附件下载到本地,并把本地绝对路径一并返回给 agent。
3
3
  当前目录:${U?U.resolvedDir:`(读取中…)`}`,children:[(0,v.jsx)(`input`,{type:`checkbox`,checked:X,onChange:re}),(0,v.jsx)(`span`,{className:`dot`}),`附件自动下载`]}),(0,v.jsx)(`button`,{className:`btn small ghost`,onClick:Z,disabled:M,children:M?`刷新中…`:`刷新`}),(0,v.jsx)(`button`,{className:`pill`+(K.open?` on`:``),title:`账号 ${e.email||``}(点击展开登录态 / 登出)`,onClick:()=>q(e=>({...e,open:!e.open})),children:e.email||`已登录`})]}),K.open?(0,v.jsxs)(`div`,{className:`card`,style:{padding:16,marginBottom:12},children:[(0,v.jsxs)(`div`,{className:`colhead`,children:[(0,v.jsx)(`h3`,{children:`登录态`}),(0,v.jsx)(`button`,{className:`btn small ghost danger`,onClick:ne,children:`登出`})]}),(0,v.jsxs)(`div`,{className:`settings`,children:[(0,v.jsx)(`dt`,{children:`账号`}),(0,v.jsx)(`dd`,{children:e?.email}),(0,v.jsx)(`dt`,{children:`userId`}),(0,v.jsx)(`dd`,{children:e?.userId||`-`}),(0,v.jsx)(`dt`,{children:`后端`}),(0,v.jsx)(`dd`,{className:`mono`,children:(0,v.jsx)(l,{text:e?.baseUrl,children:e?.baseUrl})}),(0,v.jsx)(`dt`,{children:`本机配置`}),(0,v.jsx)(`dd`,{className:`mono`,children:(0,v.jsx)(l,{text:e?.configPath,children:e?.configPath})})]}),(0,v.jsxs)(`div`,{className:`row-inline`,style:{padding:`10px 0 0`},children:[(0,v.jsx)(`input`,{placeholder:`切换账号:邮箱`,size:`24`,spellCheck:`false`,value:K.email,onChange:e=>q(t=>({...t,email:e.target.value}))}),(0,v.jsx)(`input`,{placeholder:`密码`,type:`password`,size:`18`,value:K.password,onChange:e=>q(t=>({...t,password:e.target.value})),onKeyDown:e=>{e.key===`Enter`&&J()}}),(0,v.jsx)(`button`,{className:`btn`,onClick:J,disabled:K.busy,children:K.busy?`登录中…`:`登录`})]})]}):null,(0,v.jsxs)(`div`,{className:`cloud-compose`,children:[(0,v.jsx)(`input`,{className:`cloud-compose-topic`,placeholder:`主题`,"aria-label":`新任务主题`,value:P.topic,onChange:e=>F({...P,topic:e.target.value}),onKeyDown:e=>{e.key===`Enter`&&$()}}),(0,v.jsx)(`input`,{className:`cloud-compose-text`,placeholder:`要做什么…(可 Ctrl+V 粘贴图片)`,"aria-label":`新任务内容`,value:P.text,title:`可以直接 Ctrl+V 粘贴截图:会自动上传为附件并附在内容里`,onChange:e=>F({...P,text:e.target.value}),onPaste:ce,onKeyDown:e=>{e.key===`Enter`&&$()}}),(0,v.jsx)(`button`,{className:`btn`,onClick:$,children:`加入待办`})]}),A?(0,v.jsxs)(`div`,{className:`cloud-error`,children:[(0,v.jsxs)(`span`,{children:[`清单读取失败:`,A]}),(0,v.jsx)(`button`,{className:`btn small ghost`,onClick:Z,children:`重试`})]}):null,!O&&!A?(0,v.jsx)(`div`,{className:`cloud-loading muted`,children:`读取中…`}):null,O?(0,v.jsx)(`div`,{className:`cols`,children:C.map(([e,t])=>(0,v.jsxs)(`div`,{className:`col col-`+e,children:[(0,v.jsxs)(`div`,{className:`colhead`,children:[(0,v.jsx)(`h3`,{children:t}),(0,v.jsx)(`span`,{className:`cnt`,children:(Q?.[e]||[]).length}),e===`done`&&(Q?.done||[]).length?(0,v.jsxs)(v.Fragment,{children:[(0,v.jsx)(`span`,{className:`grow`}),(0,v.jsx)(`button`,{className:`btn small ghost`,onClick:se,title:`把较旧的完成记录移到冷 key`,children:`归档旧记录`})]}):null]}),(0,v.jsxs)(`div`,{className:`card list`,children:[(Q?.[e]||[]).length?le(e,Q[e]).map(t=>(0,v.jsx)(D,{bucket:e,task:t,dupCount:ie.get(t.text)||1,onAct:oe},E(e,t))):(0,v.jsx)(`div`,{className:`cloud-empty`,children:e===`open`?(0,v.jsxs)(v.Fragment,{children:[`还没有待办`,(0,v.jsx)(`br`,{}),`在上方投递条输入,`,(0,v.jsx)(`kbd`,{children:`Enter`}),` 直达`]}):e===`done`?`还没有完成记录`:`没有冻结的任务`}),(Q?.[e]||[]).length>T?(0,v.jsx)(`div`,{className:`row muted`,style:{cursor:`pointer`,justifyContent:`center`},onClick:()=>B(t=>({...t,[e]:!t[e]})),children:z[e]?`收起`:`还有 ${Q[e].length-T} 条,点击展开`}):null]})]},e))}):null,ee?(0,v.jsx)(S,{onClose:()=>R(!1)}):null,V?(0,v.jsx)(s,{title:`编辑任务`,onClose:()=>H(null),children:(0,v.jsx)(x,{task:V.task,pick:V.pick,group:G,onCancel:()=>H(null),onSaved:async()=>{H(null),await Z(),await r()}})}):null,I?(0,v.jsx)(s,{title:I.title,size:`lg`,onClose:()=>L(null),children:I.node}):null,b]})}export{O as default};
@@ -1 +1 @@
1
- import{d as e,f as t,h as n,i as r,o as i,s as a,u as o}from"./attach-v8BxRJ7p.js";import{C as s,W as c,d as l,q as ee,w as te}from"./index-DMp4lRKl.js";import{t as ne}from"./graph-DM-zDRdL.js";var u=n(t(),1),d=e(),f=280,p=56,m=28,h=320,re=6,g=``;function _(e){return e&&!e.deletedAt&&!e.migratedTo}function v(e){return _(e)&&e.status!==`consumed`}function ie(e){return s(e.text)||l(e)||`#${e.id}`}function y(e,t){return`${e}:${Number(t)}`}function b(e){if(typeof e==`number`&&Number.isFinite(e)&&e>0)return{kind:`local`,id:Math.trunc(e)};let t=String(e??``).trim();if(!t)return null;let n=/^([A-Za-z0-9_-]+):(\d+)$/.exec(t);if(n)return{kind:`foreign`,key:n[1],id:Number(n[2])};if(/^\d+$/.test(t)){let e=Number(t);if(e>0)return{kind:`local`,id:e}}return null}function x(e,t){let n=b(e);return n?n.kind===`foreign`?y(n.key,n.id):y(t,n.id):null}function ae(e,t){return e.topicKey===t?Number(e.id):y(e.topicKey,e.id)}function oe(e){let t=new Map;for(let n of e)t.has(n.topicKey)||t.set(n.topicKey,[]),t.get(n.topicKey).push(n);let n=new Map,r=0;for(let[,e]of t)e.forEach((e,t)=>{n.set(e.nodeKey,{x:p+r*h,y:m+t*94})}),r+=1;return n}function S(e,t,n,r){let i=Math.max(48,Math.abs(n-e)*.5);return`M ${e} ${t} C ${e+i} ${t}, ${n-i} ${r}, ${n} ${r}`}function C(e,t,n){let r=e.getBoundingClientRect();return{x:t-r.left+e.scrollLeft,y:n-r.top+e.scrollTop}}function w({dirKey:e,groupId:t}){let n=c()||{},s=o(),{dialog:l,node:h}=i(),_=n.rows||[],w=n.refreshLocal,T=(0,u.useId)().replace(/:/g,``),se=n.repoData&&n.repoData.boards||[],E=(0,u.useMemo)(()=>se.find(e=>e.id===t||e.key===t)||null,[se,t]),D=!!E,O=(0,u.useMemo)(()=>{if(!E)return[];let e=[];for(let t of E.repos||[]){let n=_.find(e=>e.repo&&e.repo.key===t.key);if(!n)continue;let r=[E.id,E.key,E.name].filter(Boolean),i=(n.tasks||[]).filter(e=>{if(!v(e))return!1;let t=te(e.text);return t.board&&r.includes(t.board)});i.length&&e.push({key:n.key,name:t.name||t.key,cwd:n.cwd,isGlobal:!!n.isGlobal,count:i.length,total:i.length})}return e},[E,_]),[k,A]=(0,u.useState)(g);(0,u.useEffect)(()=>{D||A(g)},[D,t]);let j=(0,u.useMemo)(()=>D?null:_.find(t=>t.key===e)||null,[D,_,e]),M=(0,u.useMemo)(()=>{if(D){let e=[E.id,E.key,E.name].filter(Boolean),t=[];for(let n of E.repos||[]){let r=_.find(e=>e.repo&&e.repo.key===n.key);if(r&&!(k&&r.key!==k))for(let i of r.tasks||[]){if(!v(i))continue;let a=te(i.text);a.board&&e.includes(a.board)&&t.push({...i,topicKey:r.key,topicCwd:r.cwd,topicIsGlobal:!!r.isGlobal,projectName:n.name||n.key,nodeKey:y(r.key,i.id)})}}return t}return j?(j.tasks||[]).filter(v).map(e=>({...e,topicKey:j.key,topicCwd:j.cwd,topicIsGlobal:!!j.isGlobal,projectName:j.name||j.key,nodeKey:y(j.key,e.id)})):[]},[D,E,_,k,j]),N=(0,u.useMemo)(()=>new Map(M.map(e=>[e.nodeKey,e])),[M]),P=(0,u.useRef)(N);P.current=N;let F=(0,u.useRef)(M);F.current=M;let I=(0,u.useRef)(null),[L,ce]=(0,u.useState)(()=>new Map),R=(0,u.useRef)(L);R.current=L;let z=(0,u.useRef)(``);(0,u.useEffect)(()=>{let t=M.map(e=>e.nodeKey).join(`|`)+`#`+(D?k||`ALL`:e||``),n=z.current.split(`#`)[0]!==t.split(`#`)[0]||z.current.split(`#`)[1]!==t.split(`#`)[1];z.current=t,ce(e=>{let t=new Map,r=oe(M);for(let i of M)t.set(i.nodeKey,!n&&e.has(i.nodeKey)?e.get(i.nodeKey):r.get(i.nodeKey)||{x:p,y:m});return t})},[M,D,k,e]);let B=(0,u.useRef)(null),[V,H]=(0,u.useState)(null),[U,W]=(0,u.useState)(null),[G,K]=(0,u.useState)(null),[le,ue]=(0,u.useState)(!1),q=(0,u.useRef)(!1);q.current=le;let J=(0,u.useRef)(async()=>!1),Y=(0,u.useRef)(s);Y.current=s;let X=async(e,t,n)=>{ue(!0);try{let r={...t};Array.isArray(r.blockBy)&&(r.blockBy=r.blockBy.join(`,`));let i=e.topicIsGlobal?{key:e.topicKey}:{cwd:e.topicCwd};await ee(`/api/localtasks/item`,{method:`PATCH`,body:{...i,id:Number(e.id),...r}}),n&&s(n),w&&await w()}catch(e){s(String(e.message||e))}finally{ue(!1)}},de=(e,t)=>{let n=I.current;if(!n)return null;let{x:r,y:i}=C(n,e,t),a=F.current;for(let e=a.length-1;e>=0;e--){let t=a[e].nodeKey,o=R.current.get(t);if(!o)continue;let s=n.querySelector(`[data-node-id="${CSS.escape(t)}"]`),c=s?s.offsetHeight:64;if(r>=o.x-10&&r<=o.x+f+28&&i>=o.y-6&&i<=o.y+c+6)return t}return null},fe=e=>{let t=I.current,n=R.current.get(e)||{x:0,y:0},r=t?.querySelector(`[data-node-id="${CSS.escape(e)}"]`),i=r?r.offsetHeight:64;return{x:n.x+f,y:n.y+i/2}},pe=e=>{if(!e||e.kind!==`link`){W(null);return}W({sourceId:e.sourceId,x:e.x1,y:e.y1,cx:e.cx,cy:e.cy,overId:e.overId,dragged:!!e.dragged})},Z=()=>{B.current=null,H(null),W(null)};J.current=async(e,t)=>{if(!t||t===e)return!1;let n=P.current.get(e),r=P.current.get(t);if(!n||!r||!v(r))return Y.current(`只能连到待领取任务`),!1;if(r.blocksFollowing)return Y.current(`#${r.id} 是闸门,不能声明上游`),!1;let i=ae(n,r.topicKey),a=[...r.blockBy||[]];if(a.some(e=>{let t=b(e),n=b(i);return!t||!n||t.kind!==n.kind?!1:(t.kind===`local`||t.key===n.key)&&t.id===n.id}))return Y.current(`已有该有向边`),!1;if(ne(e=>{let t=P.current.get(e);if(!t)return[];let n=[];for(let e of t.blockBy||[]){let r=x(e,t.topicKey);r&&P.current.has(r)&&n.push(r)}return n},e,t))return Y.current(`会形成环,已取消`),!1;let o=n.topicKey!==r.topicKey;return await X(r,{blockBy:[...a,i]},o?`#${n.id}@${n.projectName} → #${r.id}@${r.projectName}`:`#${n.id} → #${r.id}`),!0},(0,u.useEffect)(()=>{let e=e=>{let t=B.current;if(!t)return;let n=I.current;if(!n)return;let r=C(n,e.clientX,e.clientY);if(t.kind===`drag`){let e=Math.max(8,r.x-t.ox),n=Math.max(8,r.y-t.oy);ce(r=>{let i=new Map(r);return i.set(t.id,{x:e,y:n}),i});return}if(t.kind===`link`){let n=de(e.clientX,e.clientY),i=n&&n!==t.sourceId?n:null,a=Math.hypot(r.x-t.sx,r.y-t.sy),o=t.dragged||a>=re,s={...t,cx:r.x,cy:r.y,overId:i,dragged:o};B.current=s,pe(s)}},t=async e=>{let t=B.current;if(t){if(t.kind===`drag`){Z();return}if(t.kind===`link`){let n=t.overId||de(e.clientX,e.clientY),r=t.sourceId;if(n&&n!==r){Z(),await J.current(r,n);return}if(t.dragged){Z();return}let i=P.current.get(r);Y.current(`已选 #${i?.id??r},再点目标画出有向边`)}}},n=e=>{e.key===`Escape`&&Z()};return window.addEventListener(`pointermove`,e),window.addEventListener(`mousemove`,e),window.addEventListener(`pointerup`,t),window.addEventListener(`mouseup`,t),window.addEventListener(`pointercancel`,Z),window.addEventListener(`keydown`,n),()=>{window.removeEventListener(`pointermove`,e),window.removeEventListener(`mousemove`,e),window.removeEventListener(`pointerup`,t),window.removeEventListener(`mouseup`,t),window.removeEventListener(`pointercancel`,Z),window.removeEventListener(`keydown`,n)}},[]);let me=(e,t)=>{if(q.current||e.button!==0||e.target.closest(`.dagp-port, .dagp-ops, .dagp-chip, button, a`))return;let n=B.current;if(n&&n.kind===`link`){if(e.preventDefault(),e.stopPropagation(),t.nodeKey===n.sourceId){Z();return}if(!v(t)){Y.current(`只能连到待领取任务`);return}let r=n.sourceId;Z(),J.current(r,t.nodeKey);return}if(B.current||!v(t))return;e.preventDefault();let r=I.current;if(!r)return;let i=R.current.get(t.nodeKey)||{x:0,y:0},a=C(r,e.clientX,e.clientY);B.current={kind:`drag`,id:t.nodeKey,ox:a.x-i.x,oy:a.y-i.y},H(t.nodeKey)},he=(e,t)=>{if(q.current||!v(t)||e.button!==0)return;if(e.preventDefault(),e.stopPropagation(),B.current?.kind===`link`&&B.current.sourceId===t.nodeKey){Z();return}let n=fe(t.nodeKey),r=I.current,i=r?C(r,e.clientX,e.clientY):{x:n.x,y:n.y},a={kind:`link`,sourceId:t.nodeKey,x1:n.x,y1:n.y,cx:i.x,cy:i.y,overId:null,dragged:!1,sx:i.x,sy:i.y};B.current=a,pe(a)},ge=e=>{B.current&&B.current.kind===`link`&&(e.target.closest(`.dagp-node`)||Z())},_e=async(e,t)=>{let n=[...e.blockBy||[]].filter(e=>{let n=b(e),r=b(t);return!n||!r?String(e)!==String(t):n.kind===r.kind?n.kind===`local`?n.id!==r.id:n.key!==r.key||n.id!==r.id:!0});await X(e,{blockBy:n},`已解除依赖 → #${e.id}`)},ve=e=>X(e,{gate:!e.blocksFollowing},e.blocksFollowing?`#${e.id} 取消闸门`:`#${e.id} 设为闸门`),ye=async e=>{let t=await l({title:`时间目标 · #${e.id}`,input:!0,placeholder:`如 2h / 90m`,value:e.timegoal?.duration||``});if(t==null)return;let n=String(t).trim();if(!n){await X(e,{clearGoal:!0},`#${e.id} 已清除时间目标`);return}await X(e,{duration:n},`#${e.id} 时间目标 ${n}`)},be=e=>{n.openPage&&n.openPage({dirKey:e.topicKey,task:String(e.id),name:`#${e.id}`})},xe=(0,u.useMemo)(()=>{let e=[];for(let t of M){let n=L.get(t.nodeKey);if(!n)continue;let r=I.current?.querySelector(`[data-node-id="${CSS.escape(t.nodeKey)}"]`),i=r?r.offsetHeight:64;for(let r of t.blockBy||[]){let a=x(r,t.topicKey);if(!a||!N.has(a))continue;let o=L.get(a);if(!o)continue;let s=I.current?.querySelector(`[data-node-id="${CSS.escape(a)}"]`),c=s?s.offsetHeight:64;e.push({from:a,to:t.nodeKey,x1:o.x+f,y1:o.y+c/2,x2:n.x,y2:n.y+i/2})}}return e},[M,L,N,V,U]),Q=(0,u.useMemo)(()=>{let e=480,t=240;for(let n of M){let r=L.get(n.nodeKey);r&&(e=Math.max(e,r.x+f+100),t=Math.max(t,r.y+140))}return U&&(e=Math.max(e,U.cx+40),t=Math.max(t,U.cy+40)),{w:e,h:t}},[M,L,U]),Se=D?E?.name||`组编排`:j?.name||e||`编排`,$=!!U,Ce=U?N.get(U.sourceId)?.id??U.sourceId:``;return(0,d.jsxs)(`div`,{className:`dagp`+($?` is-linking`:``)+(V==null?``:` is-dragging`),children:[(0,d.jsxs)(`div`,{className:`dagp-head`,children:[(0,d.jsx)(`span`,{className:`dagp-title`,children:Se}),(0,d.jsxs)(`span`,{className:`dagp-count`,children:[M.length,` 个待领取节点`]}),(0,d.jsx)(`span`,{className:`dagp-hint`,children:$?`连线中:再点目标完成 #${Ce} → 目标(Esc 取消)`:D?`组内全量任务;跨项目连线对 get 生效;未连线走各队列默认序`:`点右侧 ● 再点目标 = 有向顺序;未连线 = 无先后、走默认序`}),D&&O.length>0&&(0,d.jsxs)(`span`,{className:`dagp-queues`,children:[(0,d.jsxs)(`button`,{type:`button`,className:`dagp-queue`+(k===g?` on`:``),onClick:()=>A(g),children:[`全部`,(0,d.jsx)(`i`,{children:O.reduce((e,t)=>e+t.total,0)})]}),O.map(e=>(0,d.jsxs)(`button`,{type:`button`,className:`dagp-queue`+(e.key===k?` on`:``),title:`${e.name} · ${e.count}/${e.total}`,onClick:()=>A(e.key),children:[e.name,(0,d.jsx)(`i`,{children:e.count})]},e.key))]})]}),(0,d.jsxs)(`div`,{className:`dagp-canvas`,ref:I,onPointerDown:ge,children:[(0,d.jsxs)(`svg`,{className:`dagp-edges`,width:Q.w,height:Q.h,style:{width:Q.w,height:Q.h},"aria-hidden":`true`,children:[(0,d.jsx)(`defs`,{children:(0,d.jsx)(`marker`,{id:`dagp-arrow-${T}`,viewBox:`0 0 10 10`,refX:`9`,refY:`5`,markerWidth:`7`,markerHeight:`7`,orient:`auto`,children:(0,d.jsx)(`path`,{d:`M0 0 L10 5 L0 10 z`,fill:`var(--mdw-accent, #2F6F5E)`})})}),xe.map(e=>(0,d.jsx)(`path`,{className:`dagp-edge`,d:S(e.x1,e.y1,e.x2,e.y2),markerEnd:`url(#dagp-arrow-${T})`},`${e.from}->${e.to}`)),U&&(0,d.jsx)(`path`,{className:`dagp-edge preview`,d:S(U.x,U.y,U.cx,U.cy),markerEnd:`url(#dagp-arrow-${T})`})]}),(0,d.jsx)(`div`,{className:`dagp-nodes`,style:{width:Q.w,height:Q.h},children:M.map(e=>{let t=L.get(e.nodeKey)||{x:p,y:m},n=(e.blockBy||[]).map(t=>({token:t,key:x(t,e.topicKey)})).filter(e=>e.key&&N.has(e.key)),r=U&&U.overId===e.nodeKey,i=U&&U.sourceId===e.nodeKey;return(0,d.jsxs)(`div`,{"data-node-id":e.nodeKey,className:`dagp-node`+(V===e.nodeKey?` dragging`:``)+(r?` over`:``)+(i?` linking-src`:``)+(e.blocksFollowing?` gate`:``)+($&&!i?` link-target`:``),style:{transform:`translate(${t.x}px, ${t.y}px)`,width:f},onPointerDown:t=>me(t,e),children:[(0,d.jsx)(`span`,{className:`dagp-port in`,title:`入:箭头指向我 = 我等对方`,"aria-hidden":`true`}),(0,d.jsxs)(`div`,{className:`dagp-body`,children:[(0,d.jsxs)(`div`,{className:`dagp-top`,children:[(0,d.jsxs)(`span`,{className:`dagp-no mono`,children:[`#`,e.id]}),D&&(0,d.jsx)(`span`,{className:`dagp-chip proj`,children:e.projectName}),e.blocksFollowing&&(0,d.jsx)(`span`,{className:`dagp-chip gate`,children:`闸门`}),e.ready===!1&&(0,d.jsx)(`span`,{className:`dagp-chip lock`,children:`锁定`}),e.timegoal?.duration&&(0,d.jsxs)(`span`,{className:`dagp-chip goal`,children:[`⏱ `,e.timegoal.duration]}),(0,d.jsx)(`button`,{type:`button`,className:`dagp-ops`,title:`节点操作`,"aria-label":`节点操作`,onClick:t=>{t.stopPropagation();let n=[{label:`打开任务`,onClick:()=>be(e)},{label:e.blocksFollowing?`取消闸门`:`设为闸门(挡住后续)`,onClick:()=>ve(e)},{label:e.timegoal?.duration?`改时间目标`:`加时间目标(timegoal)`,onClick:()=>ye(e)}],r=t.currentTarget.getBoundingClientRect();K({x:r.left,y:r.bottom,items:n})},children:(0,d.jsx)(a,{name:`dots`,size:13})})]}),(0,d.jsx)(`div`,{className:`dagp-name`,title:e.text,onDoubleClick:t=>{t.stopPropagation(),be(e)},children:ie(e)}),n.length>0&&(0,d.jsx)(`div`,{className:`dagp-deps`,children:n.map(({token:t,key:n})=>{let r=N.get(n),i=r&&r.topicKey!==e.topicKey;return(0,d.jsxs)(`span`,{className:`dagp-chip dep`,title:i?`跨项目 #${r.id}@${r.projectName} → #${e.id}`:`#${r?.id} → #${e.id}`,children:[`← #`,r?.id,i?`@${r.projectName}`:``,(0,d.jsx)(`i`,{role:`button`,"aria-label":`解除依赖`,onClick:n=>{n.stopPropagation(),_e(e,t)},children:`×`})]},String(t))})})]}),(0,d.jsx)(`button`,{type:`button`,className:`dagp-port out`,title:`点一下再点目标,或按住拖到目标 = 有向顺序(可跨项目)`,"aria-label":`从 #${e.id} 开始连线`,onPointerDown:t=>he(t,e)})]},e.nodeKey)})}),!M.length&&(0,d.jsx)(`div`,{className:`dagp-empty`,children:D?`本组还没有带 board 归属的任务。连线可跨项目,对 get 生效。`:`这个队列没有任务。连线是编排里唯一的顺序关系;不连就保持默认序。`})]}),G&&(0,d.jsx)(r,{x:G.x,y:G.y,items:G.items,onClose:()=>K(null)}),h]})}export{w as default};
1
+ import{d as e,f as t,h as n,i as r,o as i,s as a,u as o}from"./attach-v8BxRJ7p.js";import{C as s,W as c,d as l,q as ee,w as te}from"./index-CHHRdALV.js";import{t as ne}from"./graph-DM-zDRdL.js";var u=n(t(),1),d=e(),f=280,p=56,m=28,h=320,re=6,g=``;function _(e){return e&&!e.deletedAt&&!e.migratedTo}function v(e){return _(e)&&e.status!==`consumed`}function ie(e){return s(e.text)||l(e)||`#${e.id}`}function y(e,t){return`${e}:${Number(t)}`}function b(e){if(typeof e==`number`&&Number.isFinite(e)&&e>0)return{kind:`local`,id:Math.trunc(e)};let t=String(e??``).trim();if(!t)return null;let n=/^([A-Za-z0-9_-]+):(\d+)$/.exec(t);if(n)return{kind:`foreign`,key:n[1],id:Number(n[2])};if(/^\d+$/.test(t)){let e=Number(t);if(e>0)return{kind:`local`,id:e}}return null}function x(e,t){let n=b(e);return n?n.kind===`foreign`?y(n.key,n.id):y(t,n.id):null}function ae(e,t){return e.topicKey===t?Number(e.id):y(e.topicKey,e.id)}function oe(e){let t=new Map;for(let n of e)t.has(n.topicKey)||t.set(n.topicKey,[]),t.get(n.topicKey).push(n);let n=new Map,r=0;for(let[,e]of t)e.forEach((e,t)=>{n.set(e.nodeKey,{x:p+r*h,y:m+t*94})}),r+=1;return n}function S(e,t,n,r){let i=Math.max(48,Math.abs(n-e)*.5);return`M ${e} ${t} C ${e+i} ${t}, ${n-i} ${r}, ${n} ${r}`}function C(e,t,n){let r=e.getBoundingClientRect();return{x:t-r.left+e.scrollLeft,y:n-r.top+e.scrollTop}}function w({dirKey:e,groupId:t}){let n=c()||{},s=o(),{dialog:l,node:h}=i(),_=n.rows||[],w=n.refreshLocal,T=(0,u.useId)().replace(/:/g,``),se=n.repoData&&n.repoData.boards||[],E=(0,u.useMemo)(()=>se.find(e=>e.id===t||e.key===t)||null,[se,t]),D=!!E,O=(0,u.useMemo)(()=>{if(!E)return[];let e=[];for(let t of E.repos||[]){let n=_.find(e=>e.repo&&e.repo.key===t.key);if(!n)continue;let r=[E.id,E.key,E.name].filter(Boolean),i=(n.tasks||[]).filter(e=>{if(!v(e))return!1;let t=te(e.text);return t.board&&r.includes(t.board)});i.length&&e.push({key:n.key,name:t.name||t.key,cwd:n.cwd,isGlobal:!!n.isGlobal,count:i.length,total:i.length})}return e},[E,_]),[k,A]=(0,u.useState)(g);(0,u.useEffect)(()=>{D||A(g)},[D,t]);let j=(0,u.useMemo)(()=>D?null:_.find(t=>t.key===e)||null,[D,_,e]),M=(0,u.useMemo)(()=>{if(D){let e=[E.id,E.key,E.name].filter(Boolean),t=[];for(let n of E.repos||[]){let r=_.find(e=>e.repo&&e.repo.key===n.key);if(r&&!(k&&r.key!==k))for(let i of r.tasks||[]){if(!v(i))continue;let a=te(i.text);a.board&&e.includes(a.board)&&t.push({...i,topicKey:r.key,topicCwd:r.cwd,topicIsGlobal:!!r.isGlobal,projectName:n.name||n.key,nodeKey:y(r.key,i.id)})}}return t}return j?(j.tasks||[]).filter(v).map(e=>({...e,topicKey:j.key,topicCwd:j.cwd,topicIsGlobal:!!j.isGlobal,projectName:j.name||j.key,nodeKey:y(j.key,e.id)})):[]},[D,E,_,k,j]),N=(0,u.useMemo)(()=>new Map(M.map(e=>[e.nodeKey,e])),[M]),P=(0,u.useRef)(N);P.current=N;let F=(0,u.useRef)(M);F.current=M;let I=(0,u.useRef)(null),[L,ce]=(0,u.useState)(()=>new Map),R=(0,u.useRef)(L);R.current=L;let z=(0,u.useRef)(``);(0,u.useEffect)(()=>{let t=M.map(e=>e.nodeKey).join(`|`)+`#`+(D?k||`ALL`:e||``),n=z.current.split(`#`)[0]!==t.split(`#`)[0]||z.current.split(`#`)[1]!==t.split(`#`)[1];z.current=t,ce(e=>{let t=new Map,r=oe(M);for(let i of M)t.set(i.nodeKey,!n&&e.has(i.nodeKey)?e.get(i.nodeKey):r.get(i.nodeKey)||{x:p,y:m});return t})},[M,D,k,e]);let B=(0,u.useRef)(null),[V,H]=(0,u.useState)(null),[U,W]=(0,u.useState)(null),[G,K]=(0,u.useState)(null),[le,ue]=(0,u.useState)(!1),q=(0,u.useRef)(!1);q.current=le;let J=(0,u.useRef)(async()=>!1),Y=(0,u.useRef)(s);Y.current=s;let X=async(e,t,n)=>{ue(!0);try{let r={...t};Array.isArray(r.blockBy)&&(r.blockBy=r.blockBy.join(`,`));let i=e.topicIsGlobal?{key:e.topicKey}:{cwd:e.topicCwd};await ee(`/api/localtasks/item`,{method:`PATCH`,body:{...i,id:Number(e.id),...r}}),n&&s(n),w&&await w()}catch(e){s(String(e.message||e))}finally{ue(!1)}},de=(e,t)=>{let n=I.current;if(!n)return null;let{x:r,y:i}=C(n,e,t),a=F.current;for(let e=a.length-1;e>=0;e--){let t=a[e].nodeKey,o=R.current.get(t);if(!o)continue;let s=n.querySelector(`[data-node-id="${CSS.escape(t)}"]`),c=s?s.offsetHeight:64;if(r>=o.x-10&&r<=o.x+f+28&&i>=o.y-6&&i<=o.y+c+6)return t}return null},fe=e=>{let t=I.current,n=R.current.get(e)||{x:0,y:0},r=t?.querySelector(`[data-node-id="${CSS.escape(e)}"]`),i=r?r.offsetHeight:64;return{x:n.x+f,y:n.y+i/2}},pe=e=>{if(!e||e.kind!==`link`){W(null);return}W({sourceId:e.sourceId,x:e.x1,y:e.y1,cx:e.cx,cy:e.cy,overId:e.overId,dragged:!!e.dragged})},Z=()=>{B.current=null,H(null),W(null)};J.current=async(e,t)=>{if(!t||t===e)return!1;let n=P.current.get(e),r=P.current.get(t);if(!n||!r||!v(r))return Y.current(`只能连到待领取任务`),!1;if(r.blocksFollowing)return Y.current(`#${r.id} 是闸门,不能声明上游`),!1;let i=ae(n,r.topicKey),a=[...r.blockBy||[]];if(a.some(e=>{let t=b(e),n=b(i);return!t||!n||t.kind!==n.kind?!1:(t.kind===`local`||t.key===n.key)&&t.id===n.id}))return Y.current(`已有该有向边`),!1;if(ne(e=>{let t=P.current.get(e);if(!t)return[];let n=[];for(let e of t.blockBy||[]){let r=x(e,t.topicKey);r&&P.current.has(r)&&n.push(r)}return n},e,t))return Y.current(`会形成环,已取消`),!1;let o=n.topicKey!==r.topicKey;return await X(r,{blockBy:[...a,i]},o?`#${n.id}@${n.projectName} → #${r.id}@${r.projectName}`:`#${n.id} → #${r.id}`),!0},(0,u.useEffect)(()=>{let e=e=>{let t=B.current;if(!t)return;let n=I.current;if(!n)return;let r=C(n,e.clientX,e.clientY);if(t.kind===`drag`){let e=Math.max(8,r.x-t.ox),n=Math.max(8,r.y-t.oy);ce(r=>{let i=new Map(r);return i.set(t.id,{x:e,y:n}),i});return}if(t.kind===`link`){let n=de(e.clientX,e.clientY),i=n&&n!==t.sourceId?n:null,a=Math.hypot(r.x-t.sx,r.y-t.sy),o=t.dragged||a>=re,s={...t,cx:r.x,cy:r.y,overId:i,dragged:o};B.current=s,pe(s)}},t=async e=>{let t=B.current;if(t){if(t.kind===`drag`){Z();return}if(t.kind===`link`){let n=t.overId||de(e.clientX,e.clientY),r=t.sourceId;if(n&&n!==r){Z(),await J.current(r,n);return}if(t.dragged){Z();return}let i=P.current.get(r);Y.current(`已选 #${i?.id??r},再点目标画出有向边`)}}},n=e=>{e.key===`Escape`&&Z()};return window.addEventListener(`pointermove`,e),window.addEventListener(`mousemove`,e),window.addEventListener(`pointerup`,t),window.addEventListener(`mouseup`,t),window.addEventListener(`pointercancel`,Z),window.addEventListener(`keydown`,n),()=>{window.removeEventListener(`pointermove`,e),window.removeEventListener(`mousemove`,e),window.removeEventListener(`pointerup`,t),window.removeEventListener(`mouseup`,t),window.removeEventListener(`pointercancel`,Z),window.removeEventListener(`keydown`,n)}},[]);let me=(e,t)=>{if(q.current||e.button!==0||e.target.closest(`.dagp-port, .dagp-ops, .dagp-chip, button, a`))return;let n=B.current;if(n&&n.kind===`link`){if(e.preventDefault(),e.stopPropagation(),t.nodeKey===n.sourceId){Z();return}if(!v(t)){Y.current(`只能连到待领取任务`);return}let r=n.sourceId;Z(),J.current(r,t.nodeKey);return}if(B.current||!v(t))return;e.preventDefault();let r=I.current;if(!r)return;let i=R.current.get(t.nodeKey)||{x:0,y:0},a=C(r,e.clientX,e.clientY);B.current={kind:`drag`,id:t.nodeKey,ox:a.x-i.x,oy:a.y-i.y},H(t.nodeKey)},he=(e,t)=>{if(q.current||!v(t)||e.button!==0)return;if(e.preventDefault(),e.stopPropagation(),B.current?.kind===`link`&&B.current.sourceId===t.nodeKey){Z();return}let n=fe(t.nodeKey),r=I.current,i=r?C(r,e.clientX,e.clientY):{x:n.x,y:n.y},a={kind:`link`,sourceId:t.nodeKey,x1:n.x,y1:n.y,cx:i.x,cy:i.y,overId:null,dragged:!1,sx:i.x,sy:i.y};B.current=a,pe(a)},ge=e=>{B.current&&B.current.kind===`link`&&(e.target.closest(`.dagp-node`)||Z())},_e=async(e,t)=>{let n=[...e.blockBy||[]].filter(e=>{let n=b(e),r=b(t);return!n||!r?String(e)!==String(t):n.kind===r.kind?n.kind===`local`?n.id!==r.id:n.key!==r.key||n.id!==r.id:!0});await X(e,{blockBy:n},`已解除依赖 → #${e.id}`)},ve=e=>X(e,{gate:!e.blocksFollowing},e.blocksFollowing?`#${e.id} 取消闸门`:`#${e.id} 设为闸门`),ye=async e=>{let t=await l({title:`时间目标 · #${e.id}`,input:!0,placeholder:`如 2h / 90m`,value:e.timegoal?.duration||``});if(t==null)return;let n=String(t).trim();if(!n){await X(e,{clearGoal:!0},`#${e.id} 已清除时间目标`);return}await X(e,{duration:n},`#${e.id} 时间目标 ${n}`)},be=e=>{n.openPage&&n.openPage({dirKey:e.topicKey,task:String(e.id),name:`#${e.id}`})},xe=(0,u.useMemo)(()=>{let e=[];for(let t of M){let n=L.get(t.nodeKey);if(!n)continue;let r=I.current?.querySelector(`[data-node-id="${CSS.escape(t.nodeKey)}"]`),i=r?r.offsetHeight:64;for(let r of t.blockBy||[]){let a=x(r,t.topicKey);if(!a||!N.has(a))continue;let o=L.get(a);if(!o)continue;let s=I.current?.querySelector(`[data-node-id="${CSS.escape(a)}"]`),c=s?s.offsetHeight:64;e.push({from:a,to:t.nodeKey,x1:o.x+f,y1:o.y+c/2,x2:n.x,y2:n.y+i/2})}}return e},[M,L,N,V,U]),Q=(0,u.useMemo)(()=>{let e=480,t=240;for(let n of M){let r=L.get(n.nodeKey);r&&(e=Math.max(e,r.x+f+100),t=Math.max(t,r.y+140))}return U&&(e=Math.max(e,U.cx+40),t=Math.max(t,U.cy+40)),{w:e,h:t}},[M,L,U]),Se=D?E?.name||`组编排`:j?.name||e||`编排`,$=!!U,Ce=U?N.get(U.sourceId)?.id??U.sourceId:``;return(0,d.jsxs)(`div`,{className:`dagp`+($?` is-linking`:``)+(V==null?``:` is-dragging`),children:[(0,d.jsxs)(`div`,{className:`dagp-head`,children:[(0,d.jsx)(`span`,{className:`dagp-title`,children:Se}),(0,d.jsxs)(`span`,{className:`dagp-count`,children:[M.length,` 个待领取节点`]}),(0,d.jsx)(`span`,{className:`dagp-hint`,children:$?`连线中:再点目标完成 #${Ce} → 目标(Esc 取消)`:D?`组内全量任务;跨项目连线对 get 生效;未连线走各队列默认序`:`点右侧 ● 再点目标 = 有向顺序;未连线 = 无先后、走默认序`}),D&&O.length>0&&(0,d.jsxs)(`span`,{className:`dagp-queues`,children:[(0,d.jsxs)(`button`,{type:`button`,className:`dagp-queue`+(k===g?` on`:``),onClick:()=>A(g),children:[`全部`,(0,d.jsx)(`i`,{children:O.reduce((e,t)=>e+t.total,0)})]}),O.map(e=>(0,d.jsxs)(`button`,{type:`button`,className:`dagp-queue`+(e.key===k?` on`:``),title:`${e.name} · ${e.count}/${e.total}`,onClick:()=>A(e.key),children:[e.name,(0,d.jsx)(`i`,{children:e.count})]},e.key))]})]}),(0,d.jsxs)(`div`,{className:`dagp-canvas`,ref:I,onPointerDown:ge,children:[(0,d.jsxs)(`svg`,{className:`dagp-edges`,width:Q.w,height:Q.h,style:{width:Q.w,height:Q.h},"aria-hidden":`true`,children:[(0,d.jsx)(`defs`,{children:(0,d.jsx)(`marker`,{id:`dagp-arrow-${T}`,viewBox:`0 0 10 10`,refX:`9`,refY:`5`,markerWidth:`7`,markerHeight:`7`,orient:`auto`,children:(0,d.jsx)(`path`,{d:`M0 0 L10 5 L0 10 z`,fill:`var(--mdw-accent, #2F6F5E)`})})}),xe.map(e=>(0,d.jsx)(`path`,{className:`dagp-edge`,d:S(e.x1,e.y1,e.x2,e.y2),markerEnd:`url(#dagp-arrow-${T})`},`${e.from}->${e.to}`)),U&&(0,d.jsx)(`path`,{className:`dagp-edge preview`,d:S(U.x,U.y,U.cx,U.cy),markerEnd:`url(#dagp-arrow-${T})`})]}),(0,d.jsx)(`div`,{className:`dagp-nodes`,style:{width:Q.w,height:Q.h},children:M.map(e=>{let t=L.get(e.nodeKey)||{x:p,y:m},n=(e.blockBy||[]).map(t=>({token:t,key:x(t,e.topicKey)})).filter(e=>e.key&&N.has(e.key)),r=U&&U.overId===e.nodeKey,i=U&&U.sourceId===e.nodeKey;return(0,d.jsxs)(`div`,{"data-node-id":e.nodeKey,className:`dagp-node`+(V===e.nodeKey?` dragging`:``)+(r?` over`:``)+(i?` linking-src`:``)+(e.blocksFollowing?` gate`:``)+($&&!i?` link-target`:``),style:{transform:`translate(${t.x}px, ${t.y}px)`,width:f},onPointerDown:t=>me(t,e),children:[(0,d.jsx)(`span`,{className:`dagp-port in`,title:`入:箭头指向我 = 我等对方`,"aria-hidden":`true`}),(0,d.jsxs)(`div`,{className:`dagp-body`,children:[(0,d.jsxs)(`div`,{className:`dagp-top`,children:[(0,d.jsxs)(`span`,{className:`dagp-no mono`,children:[`#`,e.id]}),D&&(0,d.jsx)(`span`,{className:`dagp-chip proj`,children:e.projectName}),e.blocksFollowing&&(0,d.jsx)(`span`,{className:`dagp-chip gate`,children:`闸门`}),e.ready===!1&&(0,d.jsx)(`span`,{className:`dagp-chip lock`,children:`锁定`}),e.timegoal?.duration&&(0,d.jsxs)(`span`,{className:`dagp-chip goal`,children:[`⏱ `,e.timegoal.duration]}),(0,d.jsx)(`button`,{type:`button`,className:`dagp-ops`,title:`节点操作`,"aria-label":`节点操作`,onClick:t=>{t.stopPropagation();let n=[{label:`打开任务`,onClick:()=>be(e)},{label:e.blocksFollowing?`取消闸门`:`设为闸门(挡住后续)`,onClick:()=>ve(e)},{label:e.timegoal?.duration?`改时间目标`:`加时间目标(timegoal)`,onClick:()=>ye(e)}],r=t.currentTarget.getBoundingClientRect();K({x:r.left,y:r.bottom,items:n})},children:(0,d.jsx)(a,{name:`dots`,size:13})})]}),(0,d.jsx)(`div`,{className:`dagp-name`,title:e.text,onDoubleClick:t=>{t.stopPropagation(),be(e)},children:ie(e)}),n.length>0&&(0,d.jsx)(`div`,{className:`dagp-deps`,children:n.map(({token:t,key:n})=>{let r=N.get(n),i=r&&r.topicKey!==e.topicKey;return(0,d.jsxs)(`span`,{className:`dagp-chip dep`,title:i?`跨项目 #${r.id}@${r.projectName} → #${e.id}`:`#${r?.id} → #${e.id}`,children:[`← #`,r?.id,i?`@${r.projectName}`:``,(0,d.jsx)(`i`,{role:`button`,"aria-label":`解除依赖`,onClick:n=>{n.stopPropagation(),_e(e,t)},children:`×`})]},String(t))})})]}),(0,d.jsx)(`button`,{type:`button`,className:`dagp-port out`,title:`点一下再点目标,或按住拖到目标 = 有向顺序(可跨项目)`,"aria-label":`从 #${e.id} 开始连线`,onPointerDown:t=>he(t,e)})]},e.nodeKey)})}),!M.length&&(0,d.jsx)(`div`,{className:`dagp-empty`,children:D?`本组还没有带 board 归属的任务。连线可跨项目,对 get 生效。`:`这个队列没有任务。连线是编排里唯一的顺序关系;不连就保持默认序。`})]}),G&&(0,d.jsx)(r,{x:G.x,y:G.y,items:G.items,onClose:()=>K(null)}),h]})}export{w as default};
@@ -1,3 +1,3 @@
1
- import{a as e,d as t,f as n,h as r,i,o as a,r as o,s,u as c}from"./attach-v8BxRJ7p.js";import{C as l,F as u,H as d,I as f,M as p,R as m,V as h,W as g,j as _,k as v,l as y,q as b,u as x,z as S}from"./index-DMp4lRKl.js";import{t as C}from"./route-crumb-DSgy8FTp.js";import{t as w}from"./graph-DM-zDRdL.js";import{n as T,r as E,t as D}from"./reopen-text-DSB76_rF.js";import{t as O}from"./Introduction-DGcd3YBk.js";var k=r(n(),1),A=t();function j(e){let t=String(e||``).trim();if(!t)return`—`;let n=t.match(/^(\d{4}-\d{2}-\d{2})[ T](\d{2}:\d{2})/);return n?`${n[1].slice(5)} ${n[2]}`:t.slice(0,16)}function M({isGlobal:t,topic:n,repo:r=null,model:i=null,tasks:a=[],taskCount:o=0,pendingCount:c=0,page:u=0,pageCount:d=1,onPage:f,onNew:p,onOpenTask:m,onDeleteTask:h,onReopenTask:g,onTplMenu:_,onImport:v,onProg:b,onMoveTask:x,onOpenDag:S,onOpenFlow:w,onToggleGate:T,downstreamOf:E}){let D=t?`全局池`:n?.name||`目录`,M=t?`共享池(无固定目录)`:n?.cwd||`—`,N=String(n?.summary||``).trim(),P=(0,k.useRef)(null),[F,I]=(0,k.useState)(null),[L,R]=(0,k.useState)(null),z=e=>e.status!==`consumed`&&!e.migratedTo&&!e.deletedAt,B=(e,t)=>{let n=t.getBoundingClientRect();return e.clientY<n.top+n.height/2?`before`:`after`},V=(e,t)=>{P.current={id:Number(t.id)},e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,`task:`+t.id),I(Number(t.id))},H=(e,t)=>{P.current&&z(t)&&Number(t.id)!==P.current.id&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`,R({id:Number(t.id),zone:B(e,e.currentTarget)}))},U=e=>{e.currentTarget.contains(e.relatedTarget)||R(null)},W=(e,t)=>{e.preventDefault();let n=B(e,e.currentTarget),r=P.current;P.current=null,I(null),R(null),r&&z(t)&&Number(t.id)!==r.id&&x&&x({id:r.id},t.id,n)},G=()=>{P.current=null,I(null),R(null)};return(0,A.jsxs)(`div`,{className:`mdw-land`,children:[(0,A.jsx)(C,{}),(0,A.jsxs)(`div`,{className:`mdw-land-head`,children:[(0,A.jsx)(`div`,{className:`mdw-land-name`,children:D}),(0,A.jsx)(`div`,{className:`mdw-land-path mono`,title:M,children:M}),N?(0,A.jsxs)(`div`,{className:`mdw-land-status-line`,title:N,children:[(0,A.jsx)(`span`,{className:`mdw-land-lab`,children:`现状`}),(0,A.jsx)(`span`,{className:`mdw-land-status`,children:N})]}):null]}),!t&&r?(0,A.jsx)(O,{kind:`repo`,owner:r,model:i}):null,(0,A.jsxs)(`div`,{className:`mdw-land-acts`,children:[(0,A.jsx)(`button`,{type:`button`,className:`btn sm primary`,onClick:p,children:`+ 新建页`}),(0,A.jsx)(`button`,{type:`button`,className:`btn ghost sm`,title:`按模板新建一页(末尾「管理模板…」打开任务模板面板)`,"aria-haspopup":`menu`,onClick:e=>_?.(e),children:`模板 ▾`}),v&&(0,A.jsx)(`button`,{type:`button`,className:`btn ghost sm`,title:`把一个 .md 文件导入成任务`,onClick:v,children:`导入`}),b&&(0,A.jsx)(`button`,{type:`button`,className:`btn ghost sm`,title:`打开这个目录的进程面板(可拖到任意一边、可浮出)`,onClick:b,children:`进程`}),(0,A.jsxs)(`span`,{className:`mdw-land-count`,children:[c>0&&(0,A.jsxs)(`b`,{className:`mdw-land-pending`,children:[c,` 待领取`]}),` `,o,` 个任务`]}),w&&(0,A.jsx)(`span`,{className:`dag-link mdw-land-orch`,role:`button`,tabIndex:-1,title:`打开可视化编排面板:有向连线定顺序(未连线走默认序)、设闸门、加时间目标`,onClick:e=>{e.stopPropagation(),w()},children:`编排`})]}),(0,A.jsx)(`div`,{className:`mdw-land-table-wrap`,children:(0,A.jsxs)(`table`,{className:`mdw-land-table`,children:[(0,A.jsx)(`thead`,{children:(0,A.jsxs)(`tr`,{children:[(0,A.jsx)(`th`,{scope:`col`,style:{width:`56px`},children:`#`}),(0,A.jsx)(`th`,{scope:`col`,children:`任务`}),(0,A.jsx)(`th`,{scope:`col`,style:{width:`74px`},children:`状态`}),(0,A.jsx)(`th`,{scope:`col`,style:{width:`116px`},children:`创建`}),(0,A.jsx)(`th`,{scope:`col`,style:{width:`116px`},children:`领取`}),(0,A.jsx)(`th`,{scope:`col`,style:{width:`56px`}})]})}),(0,A.jsxs)(`tbody`,{children:[a.map(t=>{let n=z(t),r=E&&E[t.id]||[];return(0,A.jsxs)(`tr`,{className:`mdw-land-tr`+(F===Number(t.id)?` dragging`:``)+(L&&L.id===Number(t.id)?` drop-`+L.zone:``),draggable:n,onDragStart:e=>n&&V(e,t),onDragOver:e=>H(e,t),onDragLeave:U,onDrop:e=>W(e,t),onDragEnd:G,onClick:()=>m(t.id),children:[(0,A.jsxs)(`td`,{className:`mono faint`,title:n?`拖动整行可调整队列顺序`:void 0,children:[`#`,t.id]}),(0,A.jsx)(`td`,{className:`tx`,children:(0,A.jsxs)(`div`,{className:`mdw-tg-row`,children:[(0,A.jsx)(`span`,{className:`mdw-tg-title`,children:l(t.text)}),t.timegoal?.duration?(0,A.jsxs)(`span`,{className:`mdw-tg`,title:`时间目标 ${t.timegoal.duration}(领取即计时,未到点不许标完成)${t.timegoal.prompt?`\n附加要求:${t.timegoal.prompt}`:``}`,children:[`⏱ `,t.timegoal.duration]}):null,t.blocksFollowing?(0,A.jsxs)(`span`,{className:`mdw-tg`,title:r.length?`闸门:未完成前挡住 ${r.length} 个后续任务(#${r.join(`, #`)})`:`闸门:未完成前挡住队列里排在后面的待领取任务`,children:[`闸门`,r.length?`×${r.length}`:``]}):null,t.status!==`consumed`&&t.ready===!1?(0,A.jsx)(`span`,{className:`mdw-tg`,title:t.blockBy?.length?`等待依赖完成:#${t.blockBy.join(`, #`)}`:`被前方闸门挡住`,children:`锁定`}):null]})}),(0,A.jsx)(`td`,{children:(0,A.jsx)(`span`,{className:`st`+(t.status===`consumed`?` done`:t.from?` run`:``),children:t.status===`consumed`?`完`:t.from?`跑`:`等`})}),(0,A.jsx)(`td`,{className:`mono faint`,children:j(t.createdAt)}),(0,A.jsx)(`td`,{className:`mono faint`,children:t.consumedAt?j(t.consumedAt):`—`}),(0,A.jsx)(`td`,{className:`act`,children:(0,A.jsxs)(`span`,{className:`act-ops`,children:[n&&(S||T)&&(0,A.jsx)(`span`,{onClick:e=>e.stopPropagation(),children:(0,A.jsx)(e,{items:[{label:`编排依赖…`,onPick:()=>S&&S(t)},{label:t.blocksFollowing?`取消闸门(不再挡后续)`:`设为闸门(挡住后续)`,onPick:()=>T&&T(t)}]})}),g&&(t.status===`consumed`||t.completedAt)&&(0,A.jsx)(`span`,{className:`op`,role:`button`,tabIndex:-1,title:t.completedAt?`重做(验收反馈):任务回到待领取,agent 可再次领取`:`反馈修改:任务回到待领取,agent 可再次领取`,"aria-label":`重开 ${l(t.text)}`,onClick:e=>{e.stopPropagation(),g(t)},children:(0,A.jsx)(s,{name:`refresh`,size:12})}),h&&(0,A.jsx)(`span`,{className:`op danger`,role:`button`,tabIndex:-1,title:`删除此任务(软删除,CLI 可恢复)`,"aria-label":`删除 ${l(t.text)}`,onClick:e=>{e.stopPropagation(),h(t)},children:(0,A.jsx)(s,{name:`x`,size:12})})]})})]},t.id)}),!a.length&&(0,A.jsx)(`tr`,{children:(0,A.jsx)(`td`,{colSpan:`6`,children:(0,A.jsxs)(`div`,{className:`mdw-land-empty`,children:[`还没有页面:点「+ 新建页」写第一篇,或让 agent 往`,t?`全局池`:`这个目录`,`投递任务。`]})})})]})]})}),o>0&&(0,A.jsx)(`div`,{className:`mdw-land-pager`,children:(0,A.jsx)(y,{page:u,pageCount:d,total:o,onPage:f,unit:`个任务`})})]})}var N=(e,t,n)=>w(e=>n.get(e)||[],e,t);function P({task:e,tasks:t,onClose:n,onSave:r}){let i=e=>Number(e.id),a=i(e),s=t.filter(e=>i(e)!==a),[c,u]=(0,k.useState)(!!e.blocksFollowing),[d,f]=(0,k.useState)(()=>new Set((e.blockBy||[]).map(Number))),[p,m]=(0,k.useState)(()=>new Set(s.filter(e=>(e.blockBy||[]).map(Number).includes(a)).map(i))),[h,g]=(0,k.useState)(!1),_=t.findIndex(e=>i(e)===a),v=t.slice(_+1).map(i),y=new Map(t.map(e=>[i(e),i(e)===a?[...d]:(e.blockBy||[]).map(Number)])),b=e=>c||!d.has(i(e))&&N(i(e),a,y),x=e=>!p.has(i(e))&&N(a,i(e),y),S=e=>t=>e(e=>{let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}),C=()=>u(e=>(e||f(new Set),!e)),w=async()=>{g(!0);try{let e=[{id:a,gate:c,blockBy:[...d]}];if(!c)for(let t of s){let n=i(t),r=p.has(n),o=(t.blockBy||[]).map(Number);r!==o.includes(a)&&e.push({id:n,blockBy:r?[...o,a]:o.filter(e=>e!==a)})}await r(e),n()}catch{}finally{g(!1)}},T=(e,t,n,r)=>{let a=l(e.text)||`#${i(e)}`;return(0,A.jsxs)(`label`,{className:`mdw-dag-item`,title:n&&!h?`会造成循环依赖或与闸门约束冲突,已禁用`:void 0,children:[(0,A.jsx)(`input`,{type:`checkbox`,checked:t,disabled:h||n,onChange:()=>r(i(e))}),(0,A.jsxs)(`span`,{className:`mono faint`,children:[`#`,i(e)]}),(0,A.jsx)(`span`,{className:`mdw-dag-name`,children:a})]},i(e))};return(0,A.jsx)(o,{title:`编排 · #${a} ${l(e.text)||``}`,onClose:n,busy:h,size:`md`,footer:(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(`button`,{type:`button`,className:`btn ghost`,disabled:h,onClick:n,children:`取消`}),(0,A.jsx)(`button`,{type:`button`,className:`btn primary`,disabled:h,onClick:w,children:h?`保存中…`:`保存编排`})]}),children:(0,A.jsxs)(`div`,{className:`mdw-dag`,children:[(0,A.jsxs)(`label`,{className:`mdw-dag-item mdw-dag-gate`,title:`闸门:本任务未完成前,队列里排在后面的全部待领取任务都不能被领取`,children:[(0,A.jsx)(`input`,{type:`checkbox`,checked:c,disabled:h,onChange:C}),(0,A.jsx)(`b`,{children:`闸门`}),(0,A.jsx)(`span`,{className:`mdw-dag-hint`,children:`挡住队列里所有排在后面的待领取任务(闸门不声明上游依赖)`})]}),c?(0,A.jsxs)(`div`,{className:`mdw-dag-note`,children:[`开启时自动挡住 `,v.length,` 个后续任务`,v.length?`:${v.map(e=>`#${e}`).join(`, `)}`:`(后面已没有待领取任务)`]}):null,(0,A.jsxs)(`div`,{className:`mdw-dag-sec`,children:[`上游依赖(我等谁完成)`,c?(0,A.jsx)(`span`,{className:`mdw-dag-hint`,children:`—— 闸门开启时不声明上游,保存后已清空`}):null]}),(0,A.jsx)(`div`,{className:`mdw-dag-list`+(c?` dim`:``),children:s.length?s.map(e=>T(e,d.has(i(e)),b(e),S(f))):(0,A.jsx)(`div`,{className:`mdw-dag-note`,children:`队列里没有其他待领取任务`})}),(0,A.jsxs)(`div`,{className:`mdw-dag-sec`,children:[`下游任务(谁被我挡)`,c?(0,A.jsx)(`span`,{className:`mdw-dag-hint`,children:`—— 闸门开启时此表不生效,自动挡住全部后续`}):null]}),(0,A.jsx)(`div`,{className:`mdw-dag-list`+(c?` dim`:``),children:s.length?s.map(e=>T(e,p.has(i(e)),c||x(e),S(m))):(0,A.jsx)(`div`,{className:`mdw-dag-note`,children:`队列里没有其他待领取任务`})}),(0,A.jsx)(`div`,{className:`mdw-dag-note`,children:`保存会同时改写相关任务的依赖(逐条落盘);勾选会成环的组合会被禁用。`})]})})}var F=20;function I({dirKey:e}){let{dialog:t,node:n}=a(),r=g()||{},o=c(),s=r.rows||[],l=r.refreshLocal,y=r.tpl,C=r.model,w=r.repoData&&r.repoData.repos||[],O=!e||e===`__GLOBAL__`,[j,N]=(0,k.useState)(null),[I,L]=(0,k.useState)(null),R=(0,k.useRef)(null),z=(0,k.useMemo)(()=>O?s.find(e=>e.isGlobal)||null:s.find(t=>t.key===e)||null,[s,e,O]),B=(0,k.useMemo)(()=>{if(!z||O)return null;let e=z.repo&&z.repo.key;if(e){let t=w.find(t=>t.key===e);if(t)return t}let t=String(z.cwd||``).replace(/\\/g,`/`).toLowerCase();return t&&w.find(e=>String(e.path||``).replace(/\\/g,`/`).toLowerCase()===t)||null},[z,w,O]),V=(0,k.useMemo)(()=>d((z?.tasks||[]).filter(e=>!e.deletedAt)),[z]),H=x(V,F),U=(0,k.useMemo)(()=>V.filter(e=>e.status!==`consumed`&&!e.migratedTo).length,[V]),W=e=>e().catch(e=>o(String(e.message||e))),G=()=>O?{key:h}:{cwd:z.cwd},K=(e,t,n)=>{W(async()=>{await b(`/api/localtasks/reorder`,{method:`PATCH`,body:{...G(),id:e.id,...n===`before`?{beforeId:t}:{afterId:t}}}),l()})},q=e=>{W(async()=>{await b(`/api/localtasks/item`,{method:`PATCH`,body:{...G(),id:e.id,gate:!e.blocksFollowing}}),o(e.blocksFollowing?`#${e.id} 闸门已取消`:`#${e.id} 已设为闸门——挡住所有后续待领取任务`),l()})},J=async e=>{try{for(let t of e)await b(`/api/localtasks/item`,{method:`PATCH`,body:{...G(),...t}});o(`编排已保存`),l()}catch(e){throw o(String(e.message||e)),e}},Y=(0,k.useMemo)(()=>{let e={},t=V.filter(e=>e.status!==`consumed`&&!e.migratedTo&&!e.deletedAt);return t.forEach((n,r)=>{n.blocksFollowing&&(e[n.id]=t.slice(r+1).map(e=>e.id))}),e},[V]),X=(0,k.useMemo)(()=>V.filter(e=>e.status!==`consumed`&&!e.migratedTo&&!e.deletedAt),[V]),Z=t=>{r.openPage&&r.openPage({dirKey:e,task:String(t),name:`#${t}`})},Q=t=>{let n=u();m(p(S(e),n),{title:``,body:t}),r.openPage&&r.openPage({dirKey:e,task:n,name:`新任务`})},$=()=>{C&&_(C,{component:`templates`,name:`任务模板`})},ee=()=>{C&&_(C,{component:`progress`,name:`进程`,config:{dirKey:e||`__GLOBAL__`},location:`right`})},te=[...y&&y.templates&&y.templates.length?y.templates.map(e=>({label:(e.id===y.defaultId?`✓ `:``)+e.name,icon:`list`,onClick:()=>Q(e.body)})):[{label:`按默认模板新建一页`,icon:`list`,onClick:()=>Q(y?y.defaultBody():``)}],`sep`,{label:`管理模板…`,icon:`gear`,onClick:$}],ne=n=>{if(!n)return;let r=(n.text||``).split(`
1
+ import{a as e,d as t,f as n,h as r,i,o as a,r as o,s,u as c}from"./attach-v8BxRJ7p.js";import{C as l,F as u,H as d,I as f,M as p,R as m,V as h,W as g,j as _,k as v,l as y,q as b,u as x,z as S}from"./index-CHHRdALV.js";import{t as C}from"./route-crumb-x1Za8gFU.js";import{t as w}from"./graph-DM-zDRdL.js";import{n as T,r as E,t as D}from"./reopen-text-DSB76_rF.js";import{t as O}from"./Introduction-Dr99GN_o.js";var k=r(n(),1),A=t();function j(e){let t=String(e||``).trim();if(!t)return`—`;let n=t.match(/^(\d{4}-\d{2}-\d{2})[ T](\d{2}:\d{2})/);return n?`${n[1].slice(5)} ${n[2]}`:t.slice(0,16)}function M({isGlobal:t,topic:n,repo:r=null,model:i=null,tasks:a=[],taskCount:o=0,pendingCount:c=0,page:u=0,pageCount:d=1,onPage:f,onNew:p,onOpenTask:m,onDeleteTask:h,onReopenTask:g,onTplMenu:_,onImport:v,onProg:b,onMoveTask:x,onOpenDag:S,onOpenFlow:w,onToggleGate:T,downstreamOf:E}){let D=t?`全局池`:n?.name||`目录`,M=t?`共享池(无固定目录)`:n?.cwd||`—`,N=String(n?.summary||``).trim(),P=(0,k.useRef)(null),[F,I]=(0,k.useState)(null),[L,R]=(0,k.useState)(null),z=e=>e.status!==`consumed`&&!e.migratedTo&&!e.deletedAt,B=(e,t)=>{let n=t.getBoundingClientRect();return e.clientY<n.top+n.height/2?`before`:`after`},V=(e,t)=>{P.current={id:Number(t.id)},e.dataTransfer.effectAllowed=`move`,e.dataTransfer.setData(`text/plain`,`task:`+t.id),I(Number(t.id))},H=(e,t)=>{P.current&&z(t)&&Number(t.id)!==P.current.id&&(e.preventDefault(),e.dataTransfer.dropEffect=`move`,R({id:Number(t.id),zone:B(e,e.currentTarget)}))},U=e=>{e.currentTarget.contains(e.relatedTarget)||R(null)},W=(e,t)=>{e.preventDefault();let n=B(e,e.currentTarget),r=P.current;P.current=null,I(null),R(null),r&&z(t)&&Number(t.id)!==r.id&&x&&x({id:r.id},t.id,n)},G=()=>{P.current=null,I(null),R(null)};return(0,A.jsxs)(`div`,{className:`mdw-land`,children:[(0,A.jsx)(C,{}),(0,A.jsxs)(`div`,{className:`mdw-land-head`,children:[(0,A.jsx)(`div`,{className:`mdw-land-name`,children:D}),(0,A.jsx)(`div`,{className:`mdw-land-path mono`,title:M,children:M}),N?(0,A.jsxs)(`div`,{className:`mdw-land-status-line`,title:N,children:[(0,A.jsx)(`span`,{className:`mdw-land-lab`,children:`现状`}),(0,A.jsx)(`span`,{className:`mdw-land-status`,children:N})]}):null]}),!t&&r?(0,A.jsx)(O,{kind:`repo`,owner:r,model:i}):null,(0,A.jsxs)(`div`,{className:`mdw-land-acts`,children:[(0,A.jsx)(`button`,{type:`button`,className:`btn sm primary`,onClick:p,children:`+ 新建页`}),(0,A.jsx)(`button`,{type:`button`,className:`btn ghost sm`,title:`按模板新建一页(末尾「管理模板…」打开任务模板面板)`,"aria-haspopup":`menu`,onClick:e=>_?.(e),children:`模板 ▾`}),v&&(0,A.jsx)(`button`,{type:`button`,className:`btn ghost sm`,title:`把一个 .md 文件导入成任务`,onClick:v,children:`导入`}),b&&(0,A.jsx)(`button`,{type:`button`,className:`btn ghost sm`,title:`打开这个目录的进程面板(可拖到任意一边、可浮出)`,onClick:b,children:`进程`}),(0,A.jsxs)(`span`,{className:`mdw-land-count`,children:[c>0&&(0,A.jsxs)(`b`,{className:`mdw-land-pending`,children:[c,` 待领取`]}),` `,o,` 个任务`]}),w&&(0,A.jsx)(`span`,{className:`dag-link mdw-land-orch`,role:`button`,tabIndex:-1,title:`打开可视化编排面板:有向连线定顺序(未连线走默认序)、设闸门、加时间目标`,onClick:e=>{e.stopPropagation(),w()},children:`编排`})]}),(0,A.jsx)(`div`,{className:`mdw-land-table-wrap`,children:(0,A.jsxs)(`table`,{className:`mdw-land-table`,children:[(0,A.jsx)(`thead`,{children:(0,A.jsxs)(`tr`,{children:[(0,A.jsx)(`th`,{scope:`col`,style:{width:`56px`},children:`#`}),(0,A.jsx)(`th`,{scope:`col`,children:`任务`}),(0,A.jsx)(`th`,{scope:`col`,style:{width:`74px`},children:`状态`}),(0,A.jsx)(`th`,{scope:`col`,style:{width:`116px`},children:`创建`}),(0,A.jsx)(`th`,{scope:`col`,style:{width:`116px`},children:`领取`}),(0,A.jsx)(`th`,{scope:`col`,style:{width:`56px`}})]})}),(0,A.jsxs)(`tbody`,{children:[a.map(t=>{let n=z(t),r=E&&E[t.id]||[];return(0,A.jsxs)(`tr`,{className:`mdw-land-tr`+(F===Number(t.id)?` dragging`:``)+(L&&L.id===Number(t.id)?` drop-`+L.zone:``),draggable:n,onDragStart:e=>n&&V(e,t),onDragOver:e=>H(e,t),onDragLeave:U,onDrop:e=>W(e,t),onDragEnd:G,onClick:()=>m(t.id),children:[(0,A.jsxs)(`td`,{className:`mono faint`,title:n?`拖动整行可调整队列顺序`:void 0,children:[`#`,t.id]}),(0,A.jsx)(`td`,{className:`tx`,children:(0,A.jsxs)(`div`,{className:`mdw-tg-row`,children:[(0,A.jsx)(`span`,{className:`mdw-tg-title`,children:l(t.text)}),t.timegoal?.duration?(0,A.jsxs)(`span`,{className:`mdw-tg`,title:`时间目标 ${t.timegoal.duration}(领取即计时,未到点不许标完成)${t.timegoal.prompt?`\n附加要求:${t.timegoal.prompt}`:``}`,children:[`⏱ `,t.timegoal.duration]}):null,t.blocksFollowing?(0,A.jsxs)(`span`,{className:`mdw-tg`,title:r.length?`闸门:未完成前挡住 ${r.length} 个后续任务(#${r.join(`, #`)})`:`闸门:未完成前挡住队列里排在后面的待领取任务`,children:[`闸门`,r.length?`×${r.length}`:``]}):null,t.status!==`consumed`&&t.ready===!1?(0,A.jsx)(`span`,{className:`mdw-tg`,title:t.blockBy?.length?`等待依赖完成:#${t.blockBy.join(`, #`)}`:`被前方闸门挡住`,children:`锁定`}):null]})}),(0,A.jsx)(`td`,{children:(0,A.jsx)(`span`,{className:`st`+(t.status===`consumed`?` done`:t.from?` run`:``),children:t.status===`consumed`?`完`:t.from?`跑`:`等`})}),(0,A.jsx)(`td`,{className:`mono faint`,children:j(t.createdAt)}),(0,A.jsx)(`td`,{className:`mono faint`,children:t.consumedAt?j(t.consumedAt):`—`}),(0,A.jsx)(`td`,{className:`act`,children:(0,A.jsxs)(`span`,{className:`act-ops`,children:[n&&(S||T)&&(0,A.jsx)(`span`,{onClick:e=>e.stopPropagation(),children:(0,A.jsx)(e,{items:[{label:`编排依赖…`,onPick:()=>S&&S(t)},{label:t.blocksFollowing?`取消闸门(不再挡后续)`:`设为闸门(挡住后续)`,onPick:()=>T&&T(t)}]})}),g&&(t.status===`consumed`||t.completedAt)&&(0,A.jsx)(`span`,{className:`op`,role:`button`,tabIndex:-1,title:t.completedAt?`重做(验收反馈):任务回到待领取,agent 可再次领取`:`反馈修改:任务回到待领取,agent 可再次领取`,"aria-label":`重开 ${l(t.text)}`,onClick:e=>{e.stopPropagation(),g(t)},children:(0,A.jsx)(s,{name:`refresh`,size:12})}),h&&(0,A.jsx)(`span`,{className:`op danger`,role:`button`,tabIndex:-1,title:`删除此任务(软删除,CLI 可恢复)`,"aria-label":`删除 ${l(t.text)}`,onClick:e=>{e.stopPropagation(),h(t)},children:(0,A.jsx)(s,{name:`x`,size:12})})]})})]},t.id)}),!a.length&&(0,A.jsx)(`tr`,{children:(0,A.jsx)(`td`,{colSpan:`6`,children:(0,A.jsxs)(`div`,{className:`mdw-land-empty`,children:[`还没有页面:点「+ 新建页」写第一篇,或让 agent 往`,t?`全局池`:`这个目录`,`投递任务。`]})})})]})]})}),o>0&&(0,A.jsx)(`div`,{className:`mdw-land-pager`,children:(0,A.jsx)(y,{page:u,pageCount:d,total:o,onPage:f,unit:`个任务`})})]})}var N=(e,t,n)=>w(e=>n.get(e)||[],e,t);function P({task:e,tasks:t,onClose:n,onSave:r}){let i=e=>Number(e.id),a=i(e),s=t.filter(e=>i(e)!==a),[c,u]=(0,k.useState)(!!e.blocksFollowing),[d,f]=(0,k.useState)(()=>new Set((e.blockBy||[]).map(Number))),[p,m]=(0,k.useState)(()=>new Set(s.filter(e=>(e.blockBy||[]).map(Number).includes(a)).map(i))),[h,g]=(0,k.useState)(!1),_=t.findIndex(e=>i(e)===a),v=t.slice(_+1).map(i),y=new Map(t.map(e=>[i(e),i(e)===a?[...d]:(e.blockBy||[]).map(Number)])),b=e=>c||!d.has(i(e))&&N(i(e),a,y),x=e=>!p.has(i(e))&&N(a,i(e),y),S=e=>t=>e(e=>{let n=new Set(e);return n.has(t)?n.delete(t):n.add(t),n}),C=()=>u(e=>(e||f(new Set),!e)),w=async()=>{g(!0);try{let e=[{id:a,gate:c,blockBy:[...d]}];if(!c)for(let t of s){let n=i(t),r=p.has(n),o=(t.blockBy||[]).map(Number);r!==o.includes(a)&&e.push({id:n,blockBy:r?[...o,a]:o.filter(e=>e!==a)})}await r(e),n()}catch{}finally{g(!1)}},T=(e,t,n,r)=>{let a=l(e.text)||`#${i(e)}`;return(0,A.jsxs)(`label`,{className:`mdw-dag-item`,title:n&&!h?`会造成循环依赖或与闸门约束冲突,已禁用`:void 0,children:[(0,A.jsx)(`input`,{type:`checkbox`,checked:t,disabled:h||n,onChange:()=>r(i(e))}),(0,A.jsxs)(`span`,{className:`mono faint`,children:[`#`,i(e)]}),(0,A.jsx)(`span`,{className:`mdw-dag-name`,children:a})]},i(e))};return(0,A.jsx)(o,{title:`编排 · #${a} ${l(e.text)||``}`,onClose:n,busy:h,size:`md`,footer:(0,A.jsxs)(A.Fragment,{children:[(0,A.jsx)(`button`,{type:`button`,className:`btn ghost`,disabled:h,onClick:n,children:`取消`}),(0,A.jsx)(`button`,{type:`button`,className:`btn primary`,disabled:h,onClick:w,children:h?`保存中…`:`保存编排`})]}),children:(0,A.jsxs)(`div`,{className:`mdw-dag`,children:[(0,A.jsxs)(`label`,{className:`mdw-dag-item mdw-dag-gate`,title:`闸门:本任务未完成前,队列里排在后面的全部待领取任务都不能被领取`,children:[(0,A.jsx)(`input`,{type:`checkbox`,checked:c,disabled:h,onChange:C}),(0,A.jsx)(`b`,{children:`闸门`}),(0,A.jsx)(`span`,{className:`mdw-dag-hint`,children:`挡住队列里所有排在后面的待领取任务(闸门不声明上游依赖)`})]}),c?(0,A.jsxs)(`div`,{className:`mdw-dag-note`,children:[`开启时自动挡住 `,v.length,` 个后续任务`,v.length?`:${v.map(e=>`#${e}`).join(`, `)}`:`(后面已没有待领取任务)`]}):null,(0,A.jsxs)(`div`,{className:`mdw-dag-sec`,children:[`上游依赖(我等谁完成)`,c?(0,A.jsx)(`span`,{className:`mdw-dag-hint`,children:`—— 闸门开启时不声明上游,保存后已清空`}):null]}),(0,A.jsx)(`div`,{className:`mdw-dag-list`+(c?` dim`:``),children:s.length?s.map(e=>T(e,d.has(i(e)),b(e),S(f))):(0,A.jsx)(`div`,{className:`mdw-dag-note`,children:`队列里没有其他待领取任务`})}),(0,A.jsxs)(`div`,{className:`mdw-dag-sec`,children:[`下游任务(谁被我挡)`,c?(0,A.jsx)(`span`,{className:`mdw-dag-hint`,children:`—— 闸门开启时此表不生效,自动挡住全部后续`}):null]}),(0,A.jsx)(`div`,{className:`mdw-dag-list`+(c?` dim`:``),children:s.length?s.map(e=>T(e,p.has(i(e)),c||x(e),S(m))):(0,A.jsx)(`div`,{className:`mdw-dag-note`,children:`队列里没有其他待领取任务`})}),(0,A.jsx)(`div`,{className:`mdw-dag-note`,children:`保存会同时改写相关任务的依赖(逐条落盘);勾选会成环的组合会被禁用。`})]})})}var F=20;function I({dirKey:e}){let{dialog:t,node:n}=a(),r=g()||{},o=c(),s=r.rows||[],l=r.refreshLocal,y=r.tpl,C=r.model,w=r.repoData&&r.repoData.repos||[],O=!e||e===`__GLOBAL__`,[j,N]=(0,k.useState)(null),[I,L]=(0,k.useState)(null),R=(0,k.useRef)(null),z=(0,k.useMemo)(()=>O?s.find(e=>e.isGlobal)||null:s.find(t=>t.key===e)||null,[s,e,O]),B=(0,k.useMemo)(()=>{if(!z||O)return null;let e=z.repo&&z.repo.key;if(e){let t=w.find(t=>t.key===e);if(t)return t}let t=String(z.cwd||``).replace(/\\/g,`/`).toLowerCase();return t&&w.find(e=>String(e.path||``).replace(/\\/g,`/`).toLowerCase()===t)||null},[z,w,O]),V=(0,k.useMemo)(()=>d((z?.tasks||[]).filter(e=>!e.deletedAt)),[z]),H=x(V,F),U=(0,k.useMemo)(()=>V.filter(e=>e.status!==`consumed`&&!e.migratedTo).length,[V]),W=e=>e().catch(e=>o(String(e.message||e))),G=()=>O?{key:h}:{cwd:z.cwd},K=(e,t,n)=>{W(async()=>{await b(`/api/localtasks/reorder`,{method:`PATCH`,body:{...G(),id:e.id,...n===`before`?{beforeId:t}:{afterId:t}}}),l()})},q=e=>{W(async()=>{await b(`/api/localtasks/item`,{method:`PATCH`,body:{...G(),id:e.id,gate:!e.blocksFollowing}}),o(e.blocksFollowing?`#${e.id} 闸门已取消`:`#${e.id} 已设为闸门——挡住所有后续待领取任务`),l()})},J=async e=>{try{for(let t of e)await b(`/api/localtasks/item`,{method:`PATCH`,body:{...G(),...t}});o(`编排已保存`),l()}catch(e){throw o(String(e.message||e)),e}},Y=(0,k.useMemo)(()=>{let e={},t=V.filter(e=>e.status!==`consumed`&&!e.migratedTo&&!e.deletedAt);return t.forEach((n,r)=>{n.blocksFollowing&&(e[n.id]=t.slice(r+1).map(e=>e.id))}),e},[V]),X=(0,k.useMemo)(()=>V.filter(e=>e.status!==`consumed`&&!e.migratedTo&&!e.deletedAt),[V]),Z=t=>{r.openPage&&r.openPage({dirKey:e,task:String(t),name:`#${t}`})},Q=t=>{let n=u();m(p(S(e),n),{title:``,body:t}),r.openPage&&r.openPage({dirKey:e,task:n,name:`新任务`})},$=()=>{C&&_(C,{component:`templates`,name:`任务模板`})},ee=()=>{C&&_(C,{component:`progress`,name:`进程`,config:{dirKey:e||`__GLOBAL__`},location:`right`})},te=[...y&&y.templates&&y.templates.length?y.templates.map(e=>({label:(e.id===y.defaultId?`✓ `:``)+e.name,icon:`list`,onClick:()=>Q(e.body)})):[{label:`按默认模板新建一页`,icon:`list`,onClick:()=>Q(y?y.defaultBody():``)}],`sep`,{label:`管理模板…`,icon:`gear`,onClick:$}],ne=n=>{if(!n)return;let r=(n.text||``).split(`
2
2
  `).find(e=>e.trim())||`#${n.id}`;W(async()=>{let i=await t({title:`反馈修改 · #${n.id}`,input:!0,placeholder:`写下要改的地方(留空 = 只重开,不改正文)`});if(i==null)return;let a=String(i).trim(),s=!!n.completedAt,c=s&&n.roundSummary||``,u=a||c?E({base:n.text||``,feedback:a,ackSummary:c,feedbackHeading:s?D:T,bold:s}):``,d=await b(`/api/localtasks/reopen`,{method:`POST`,body:{...O?{key:h}:{cwd:z.cwd},id:n.id,...u?{text:u}:{}}});if(u){let t=p(S(e),n.id),r=f(t);r&&String(r.body||``).trim()===String(n.text||``).trim()&&m(t,{body:u})}o(`已重开「${r.replace(/^#\s*/,``)}」——agent 可再次领取`+(d?.moved&&d.name?`;已改归属项目,迁到「${d.name}」#${d.task?.id}`:``)),l()})},re=async n=>{if(!n)return;let i=(n.text||``).split(`
3
3
  `).find(e=>e.trim())||`#${n.id}`;await t({title:`删除任务「${i.replace(/^#\s*/,``)}」`,message:`软删除:CLI localtask task restore 可恢复。`,danger:!0,okText:`删除`})&&W(async()=>{if(await b(`/api/localtasks/item`,{method:`DELETE`,body:O?{key:h,id:n.id}:{cwd:z.cwd,id:n.id}}),o(`已删除「${i.replace(/^#\s*/,``)}」`),C){let t=v(C,`page`,{dirKey:e,task:String(n.id)});t&&r.closePanel&&r.closePanel(t.getId())}l()})},ie=async e=>{let t=await e.text(),n=e.name.replace(/\.md$/i,``);await W(async()=>{let r=t.startsWith(`#`)?t:`# ${n}\n\n${t}`,i=await b(`/api/localtasks`,{method:`POST`,body:O?{global:!0,text:r}:{cwd:z.cwd,text:r}});o(`已导入:${e.name}`),l();let a=i?.task?.id??i?.id;a!=null&&Z(a)})};return!z&&!O?(0,A.jsx)(`div`,{className:`mdw`,children:(0,A.jsx)(`div`,{className:`mdw-main`,children:(0,A.jsx)(`div`,{className:`mdw-top`,children:(0,A.jsxs)(`div`,{className:`mdw-head`,children:[(0,A.jsx)(`div`,{className:`mdw-title`,children:`目录不存在`}),(0,A.jsx)(`div`,{className:`mdw-path`,children:`—`})]})})})}):(0,A.jsxs)(`div`,{className:`mdw`,children:[(0,A.jsx)(`div`,{className:`mdw-main`,children:(0,A.jsx)(M,{isGlobal:O,topic:z,repo:B,model:C,tasks:H.items,taskCount:H.total,pendingCount:U,page:H.page,pageCount:H.pageCount,onPage:H.setPage,onNew:()=>Q(y?y.defaultBody():``),onOpenTask:Z,onDeleteTask:re,onReopenTask:ne,onTplMenu:e=>N({x:e.clientX,y:e.clientY}),onImport:()=>R.current?.click(),onProg:ee,onMoveTask:K,onOpenDag:L,onOpenFlow:()=>C&&_(C,{component:`dag`,name:`编排`,config:{dirKey:e}}),onToggleGate:q,downstreamOf:Y})}),I&&(0,A.jsx)(P,{task:I,tasks:X,onClose:()=>L(null),onSave:J}),j&&(0,A.jsx)(i,{x:j.x,y:j.y,items:te,onClose:()=>N(null)}),(0,A.jsx)(`input`,{ref:R,type:`file`,accept:`.md,text/markdown,text/plain`,hidden:!0,onChange:e=>{let t=e.target.files?.[0];e.target.value=``,t&&ie(t)}}),n]})}export{I as default};