nx-kv 0.42.0 → 0.42.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 (27) hide show
  1. package/CHANGELOG.md +21 -0
  2. package/package.json +1 -1
  3. package/src/web/frontend/modules/md/styles/shell.css +7 -22
  4. package/src/web/frontend/page/dir/landing.jsx +80 -80
  5. package/src/web/frontend/page/repos/repo-table.jsx +10 -4
  6. package/src/web/public/assets/{Introduction-CGJg0hoV.js → Introduction-CdC8MBfL.js} +1 -1
  7. package/src/web/public/assets/{bar-5QC796WJ.js → bar-yESbzCxC.js} +1 -1
  8. package/src/web/public/assets/{cloud-D_N8DSl0.js → cloud-BotRQcvf.js} +1 -1
  9. package/src/web/public/assets/{composer-panel-n_8TM7hC.js → composer-panel-Xru2qIma.js} +1 -1
  10. package/src/web/public/assets/dir-D4Q3L20K.js +5 -0
  11. package/src/web/public/assets/{group-BreSC7Jq.js → group-Csco0TYH.js} +1 -1
  12. package/src/web/public/assets/{index-BjHbC1Pr.js → index-BrAIkzFc.js} +2 -2
  13. package/src/web/public/assets/index-CZzMw1zg.css +1 -0
  14. package/src/web/public/assets/{md-history-XRRcXn6B.js → md-history-DB5forf2.js} +1 -1
  15. package/src/web/public/assets/{overview-B31mFQ1o.js → overview-J1mQpmJt.js} +1 -1
  16. package/src/web/public/assets/{refs-BOpaaFX5.js → refs-FI1FMoGi.js} +1 -1
  17. package/src/web/public/assets/{repos-mvXPWSNa.js → repos-Oaycnb4I.js} +4 -3
  18. package/src/web/public/assets/{route-crumb-2JmLQxqZ.js → route-crumb-C8JzPIax.js} +1 -1
  19. package/src/web/public/assets/{settings-0HIgaIQY.js → settings-D5wTGhPD.js} +1 -1
  20. package/src/web/public/assets/{status-tag-DN6e7yfb.js → status-tag-BoUoKYZK.js} +1 -1
  21. package/src/web/public/assets/{task-Cl6JZ4-k.js → task-BgubFzHT.js} +1 -1
  22. package/src/web/public/assets/{task-row-J0w1AAxG.js → task-row-Bc6JBfrE.js} +1 -1
  23. package/src/web/public/assets/{templates-ChbbmSet.js → templates-6DQdUpiB.js} +1 -1
  24. package/src/web/public/assets/{tool-bar-BrQ71A9i.js → tool-bar-DGCwnUcn.js} +1 -1
  25. package/src/web/public/index.html +2 -2
  26. package/src/web/public/assets/dir-Q57Dyaih.js +0 -5
  27. package/src/web/public/assets/index-w0VRiX16.css +0 -1
package/CHANGELOG.md CHANGED
@@ -2,6 +2,27 @@
2
2
 
3
3
  本文件记录对外可见的变更。格式参考 [Keep a Changelog](https://keepachangelog.com/zh-CN/1.1.0/)。
4
4
 
5
+ ## [0.42.2] - 2026-11-10 目录页外壳与项目组页对齐
6
+
7
+ ### Changed
8
+
9
+ - **目录(dir)任务页外壳向项目组页看齐(#164 验收反馈二轮)**:根容器从
10
+ `mdw-land`(自带底色差与不同内距)换成与组页同款的 `rp-page`;头部改为
11
+ 同构的 `rp-group-head`——h2(图标 + 名字 + 「N 个任务 / N 待领取」计数 chips)
12
+ + **右对齐工具区**(原先左对齐、独立一行);目录特有的队列路径与现状弱化成
13
+ 头部末尾的一行小字。两页的背景、头部结构、工具区对齐方式、间距节奏一致,
14
+ 探针断言 + 截图对比实证。
15
+
16
+ ## [0.42.1] - 2026-11-10 仓库页文档列显示主篇标题
17
+
18
+ ### Fixed
19
+
20
+ - **仓库管理页「文档」列显示文档标题而不是摘要(#165)**:此前该列优先渲染主篇的
21
+ `summary`(正文首个非标题行,即回写 desc 的摘要),`title` 只是摘要为空时的兜底——
22
+ 用户改了文档标题后这一行永远不变,看起来像「标题无法修改、标题区头部变成了 desc」。
23
+ 现在主行显示文档标题(正文首个 `#` 行),摘要退到悬浮提示;列头提示
24
+ 「主篇摘要」改为「主篇标题」。
25
+
5
26
  ## [0.42.0] - 2026-11-10 任务面板统一(group/dir 共用组件)
6
27
 
7
28
  ### Changed
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "nx-kv",
3
- "version": "0.42.0",
3
+ "version": "0.42.2",
4
4
  "description": "nx-kv — KV 清单管理中枢(远程)+ 本机本地任务队列(localtask):serve 驱动 CLI 与 Web 面板,同源同构,附带可安装 skill 供 agent 提交 / 领取 / 阻塞接收任务",
5
5
  "type": "module",
6
6
  "bin": {
@@ -168,31 +168,16 @@
168
168
  /* 内容区 */
169
169
  .mdw-split{flex:1;display:flex;min-height:0;overflow:hidden}
170
170
 
171
- /* 目录落地页:未打开具体页面时,主区是**子任务表**(表格:编号/任务/状态/创建/领取) */
172
- .mdw-land{flex:1;min-height:0;overflow:auto;background:var(--canvas,#F5F4F1);padding:18px 22px}
173
- .mdw-land-head{margin-bottom:12px;min-width:0}
174
- .mdw-land-name{
175
- font-weight:650;font-size:15px;line-height:1.3;color:var(--ink,#16181C);
176
- overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
177
- }
178
- .mdw-land-path{
179
- margin-top:2px;font:400 11px ui-monospace,Consolas,monospace;color:var(--mid,#838A93);
180
- overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
181
- }
182
- .mdw-land-status-line{
183
- display:flex;align-items:baseline;gap:8px;min-width:0;margin-top:6px;
184
- }
185
- .mdw-land-lab{
186
- flex:none;width:28px;font-size:11px;font-weight:650;letter-spacing:.04em;
187
- color:var(--mid,#838A93);
188
- }
171
+ /* 目录落地页(#164 二轮):外壳与项目组页同构——根容器用 rp-page(同底色/同内距),
172
+ 头部用 rp-group-head(h2 + 右对齐工具区);这里只留目录特有的小字 meta 行
173
+ (队列 cwd + 现状)与翻页条。旧的 head/name/status-line/count 规则已随
174
+ 旧头部结构删除。 */
175
+ .mdw-land-meta{display:flex;align-items:baseline;gap:12px;min-width:0;margin-top:2px}
176
+ .mdw-land-meta .mdw-land-path{margin-top:0;flex:none;max-width:60%}
189
177
  .mdw-land-status{
190
- flex:1 1 auto;min-width:0;font-size:12.5px;line-height:1.45;color:var(--ink-2,#4B515A);
178
+ min-width:0;font-size:11.5px;color:var(--ink-2,#4B515A);
191
179
  overflow:hidden;text-overflow:ellipsis;white-space:nowrap;
192
180
  }
193
- .mdw-land-acts{display:flex;align-items:center;gap:10px;margin-bottom:12px}
194
- .mdw-land-count{font-size:12px;color:var(--mid,#838A93)}
195
- .mdw-land-pending{color:var(--doing,#2f5fb5);font-weight:650}
196
181
  /* 翻页条:队列长了翻页看,不再一次渲染全部 */
197
182
  .mdw-land-pager{display:flex;justify-content:flex-end;margin-top:10px}
198
183
  .mdw-land-table-wrap{
@@ -135,91 +135,91 @@ export default function Landing({
135
135
  };
136
136
 
137
137
  return (
138
- <div className="mdw-land">
138
+ // 根容器与项目组页同款(rp-page:无底色差、同内距、flex gap)——#164 验收反馈
139
+ // 「两种 ui 仍然不一,比如工具区、背景等」:外壳向 group 页看齐。
140
+ <div className="rp-page">
139
141
  <RouteBreadcrumb />
140
- <div className="mdw-land-head">
141
- <div className="mdw-land-name">{name}</div>
142
- <div className="mdw-land-path mono" title={path}>{path}</div>
143
- {status ? (
144
- <div className="mdw-land-status-line" title={status}>
145
- <span className="mdw-land-lab">现状</span>
146
- <span className="mdw-land-status">{status}</span>
147
- </div>
148
- ) : null}
149
- </div>
150
-
151
- {!isGlobal && repo ? <Introduction kind="repo" owner={repo} model={model} /> : null}
152
-
153
- <div className="mdw-land-acts">
154
- {/* #139:工具区可编排(顺序 / 显隐;隐藏收入「更多」) */}
155
- <ToolActsBar
156
- kind="dir"
157
- className="mdw-land-ta"
158
- labels={{
159
- more: deletedCount > 0 ? `更多 (${deletedCount})` : '更多',
160
- deleted: deletedCount > 0 ? `已删除任务(${deletedCount})` : '已删除任务',
161
- }}
162
- titles={{
163
- new: '按默认模板新建一页(▾ 选模板)',
164
- import: '把一个 .md 文件导入成任务',
165
- progress: '打开这个目录的进程面板',
166
- more: deletedCount > 0 ? `更多操作(含 ${deletedCount} 条已删除任务)` : '更多操作',
167
- deleted: '查看并恢复已删除任务',
168
- refs: '查看文档 / reference 列表',
169
- }}
170
- renderers={{
171
- // #161 新建按钮拆两级(视觉一颗按钮、命中区两层):
172
- // 主区点击 = 按默认模板直接新建;内嵌箭头 = 模板下拉(tplMenuItems)
173
- new: () => (
174
- <span className="rp-newtask">
175
- <button
176
- type="button"
177
- className="btn small primary"
178
- title="按默认模板新建一页(▾ 选模板)"
179
- onClick={() => onNew()}
180
- >
181
- + 新建页
182
- <span
183
- role="button"
184
- tabIndex={0}
185
- aria-label="选择模板新建一页"
186
- aria-haspopup="menu"
187
- className="rp-newtask-caret"
188
- title="选择模板新建一页"
189
- onClick={(e) => {
190
- e.stopPropagation();
191
- onTplMenu?.(e);
192
- }}
193
- onKeyDown={(e) => {
194
- if (e.key === 'Enter' || e.key === ' ') {
195
- e.preventDefault();
142
+ {/* 头部 = group 同构:h2(图标 + 名字 + 计数 chips)+ 右对齐工具区 */}
143
+ <div className="rp-group-head">
144
+ <h2>
145
+ <Icon name="folder" size={15} /> {name}
146
+ <span className="rp-chip-count">{taskCount} 个任务</span>
147
+ {pendingCount > 0 ? <span className="rp-chip-count">{pendingCount} 待领取</span> : null}
148
+ </h2>
149
+ <div className="rp-group-acts">
150
+ {/* #139:工具区可编排(顺序 / 显隐;隐藏收入「更多」) */}
151
+ <ToolActsBar
152
+ kind="dir"
153
+ labels={{
154
+ more: deletedCount > 0 ? `更多 (${deletedCount})` : '更多',
155
+ deleted: deletedCount > 0 ? `已删除任务(${deletedCount})` : '已删除任务',
156
+ }}
157
+ titles={{
158
+ new: '按默认模板新建一页(▾ 选模板)',
159
+ import: '把一个 .md 文件导入成任务',
160
+ progress: '打开这个目录的进程面板',
161
+ more: deletedCount > 0 ? `更多操作(含 ${deletedCount} 条已删除任务)` : '更多操作',
162
+ deleted: '查看并恢复已删除任务',
163
+ refs: '查看文档 / reference 列表',
164
+ }}
165
+ renderers={{
166
+ // #161 新建按钮拆两级(视觉一颗按钮、命中区两层):
167
+ // 主区点击 = 按默认模板直接新建;内嵌箭头 = 模板下拉(tplMenuItems)
168
+ new: () => (
169
+ <span className="rp-newtask">
170
+ <button
171
+ type="button"
172
+ className="btn small primary"
173
+ title="按默认模板新建一页(▾ 选模板)"
174
+ onClick={() => onNew()}
175
+ >
176
+ + 新建页
177
+ <span
178
+ role="button"
179
+ tabIndex={0}
180
+ aria-label="选择模板新建一页"
181
+ aria-haspopup="menu"
182
+ className="rp-newtask-caret"
183
+ title="选择模板新建一页"
184
+ onClick={(e) => {
196
185
  e.stopPropagation();
197
186
  onTplMenu?.(e);
198
- }
199
- }}
200
- >
201
- <Icon name="chevron" size={11} />
202
- </span>
203
- </button>
204
- </span>
205
- ),
206
- }}
207
- actions={{
208
- new: onNew,
209
- import: onImport,
210
- progress: onProg,
211
- orch: onOpenFlow,
212
- deleted: onDeleted,
213
- refs: onRefs,
214
- }}
215
- />
216
- <span className="mdw-land-count">
217
- {pendingCount > 0 && <b className="mdw-land-pending">{pendingCount} 待领取</b>}
218
- {' '}
219
- {taskCount} 个任务
220
- </span>
187
+ }}
188
+ onKeyDown={(e) => {
189
+ if (e.key === 'Enter' || e.key === ' ') {
190
+ e.preventDefault();
191
+ e.stopPropagation();
192
+ onTplMenu?.(e);
193
+ }
194
+ }}
195
+ >
196
+ <Icon name="chevron" size={11} />
197
+ </span>
198
+ </button>
199
+ </span>
200
+ ),
201
+ }}
202
+ actions={{
203
+ new: onNew,
204
+ import: onImport,
205
+ progress: onProg,
206
+ orch: onOpenFlow,
207
+ deleted: onDeleted,
208
+ refs: onRefs,
209
+ }}
210
+ />
211
+ </div>
212
+ {/* 路径与现状:group 页没有的目录特有信息,弱化成一行小字放头部末尾 */}
213
+ <div className="mdw-land-meta">
214
+ <span className="mdw-land-path mono" title={path}>{path}</span>
215
+ {status ? (
216
+ <span className="mdw-land-status mono" title={status}>现状:{status}</span>
217
+ ) : null}
218
+ </div>
221
219
  </div>
222
220
 
221
+ {!isGlobal && repo ? <Introduction kind="repo" owner={repo} model={model} /> : null}
222
+
223
223
  {pickedTasks.length > 0 && (
224
224
  <div className="mdw-land-batch">
225
225
  <span className="mdw-land-batch-count">已选 {pickedTasks.length} 条</span>
@@ -26,8 +26,11 @@ function RepoPath({ path }) {
26
26
  );
27
27
  }
28
28
 
29
- // 文档列入口(查看详情):一行主篇摘要 + 数量,点击打开 DocsModal——
29
+ // 文档列入口(查看详情):一行主篇标题 + 数量,点击打开 DocsModal——
30
30
  // 完整文档列表(主篇 / 补充 / reference / 组内)+ 复用编辑器就地编辑。
31
+ // #165:主行显示**文档标题**(正文首个 # 行),摘要(desc)只在没有标题时兜底、
32
+ // 悬浮提示里看全文——此前 summary 优先,用户改了标题这行字永远不变(它显示的
33
+ // 是回写 desc 的摘要),被当成「标题无法修改、标题区变成了 desc」。
31
34
  // 文档不再以 chip/tag 形式外显在行内(任务「简介文档优化」);未写的主篇
32
35
  // 显示「+ 写项目介绍」虚态,点开同样进弹窗创建。
33
36
  // 参考仓库面板的名单元格也复用它,所以具名导出。
@@ -35,15 +38,18 @@ export function DocsEntry({ docs, onOpen }) {
35
38
  const main = docs && docs.main;
36
39
  const links = (docs && docs.links) || [];
37
40
  const total = (main ? 1 : 0) + links.length;
41
+ const tip = main && main.exists
42
+ ? [main.title, main.summary && `摘要:${main.summary}`].filter(Boolean).join('\n')
43
+ : '查看完整文档列表(主篇 / 补充 / reference / 组内),可就地编辑';
38
44
  return (
39
45
  <button
40
46
  type="button"
41
47
  className="rp-docs-entry"
42
- title="查看完整文档列表(主篇 / 补充 / reference / 组内),可就地编辑"
48
+ title={tip}
43
49
  onClick={onOpen}
44
50
  >
45
51
  <span className={'rp-docs-entry-main' + (main && main.exists ? '' : ' ghost')}>
46
- {main && main.exists ? (main.summary || main.title) : '+ 写项目介绍'}
52
+ {main && main.exists ? (main.title || main.summary || '未命名') : '+ 写项目介绍'}
47
53
  </span>
48
54
  <span className="rp-docs-entry-n">{total > 0 ? `${total} 篇 · 查看详情` : '查看详情'}</span>
49
55
  </button>
@@ -181,7 +187,7 @@ export default function RepoTable({ shown, devRepos, filterBoard, groupRefRepoCo
181
187
  <th scope="col" style={{ width: '16%' }}>仓库</th>
182
188
  <th scope="col" style={{ width: '36%' }}>
183
189
  文档
184
- <span className="rp-th-hint">主篇摘要 · 查看详情打开完整文档列表</span>
190
+ <span className="rp-th-hint">主篇标题 · 查看详情打开完整文档列表</span>
185
191
  </th>
186
192
  <th scope="col" style={{ width: '18%' }}>参考仓库</th>
187
193
  <th scope="col" style={{ width: '14%' }}>分组</th>
@@ -1 +1 @@
1
- import{g as e,h as t,l as n,m as r,o as i,p as a,v as o,y as s}from"./task-status-BnymQMTw.js";import{r as c,v as l,w as u}from"./workspace-C_5X2gIr.js";import{n as d}from"./app-context-D7HAx67n.js";import{_ as f,a as p,i as m,n as h,p as g,r as _,t as v,u as y,v as b,y as x}from"./md-history-XRRcXn6B.js";import{a as S,i as C}from"./upload-BIMbGcCB.js";import{a as w,r as ee}from"./md-parse-awNLHAzO.js";import{t as T}from"./route-crumb-2JmLQxqZ.js";import{a as E,c as D,i as O,l as k,o as A,r as j,s as M,t as N,u as te}from"./tool-bar-BrQ71A9i.js";var P=s(e(),1),F=u(),I=t(),L=`doc`,R=[{id:`edit`,label:`编辑`},{id:`doc`,label:`文档`},{id:`view`,label:`查看`}];function ne({crumb:e=null,title:t,pathLabel:n=``,dirty:r=!1,writable:i=!1,onSave:a=null,onSaveLabel:o=`保存`,menuGroups:s=[],saving:c=!1,external:l=!1,afterTitle:u=null}){let d=O(),{layout:f,setLayout:p}=A(L),[m,h]=(0,P.useState)(!1),g={};for(let e of s||[])for(let t of e?.items||[])t&&t.id&&(g[t.id]=t);g.save=a&&{id:`save`,label:c?`保存中…`:o,run:a,primary:!0,disabled:c||!r};let _=e=>e===`more`||!!g[e],v=f.filter(e=>k(L,e)&&_(e.id)),y=f.filter(e=>M(L,e)&&_(e.id)),b=e=>{g[e]?.run?.(),d.setOpen(!1)},x=e=>{if(e===`more`)return(0,I.jsx)(`div`,{className:`docp-more`,ref:d.ref,children:(0,I.jsx)(`button`,{type:`button`,className:`btn ghost sm${d.open?` on`:``}`,title:`更多操作`,"aria-haspopup":`menu`,"aria-expanded":d.open,onClick:e=>j(d,e,`right`),children:`更多`})},`more`);let t=g[e];return t?(0,I.jsx)(`button`,{type:`button`,className:t.primary||e===`save`?`btn sm primary docp-save`:`btn ghost sm`,disabled:!!t.disabled,onClick:()=>b(e),children:t.label||D(L,e).label||e},e):null},S=R.map(e=>({...e,items:y.filter(t=>D(L,t.id).menuGroup===e.id)})).filter(e=>e.items.length),C=y.filter(e=>!D(L,e.id).menuGroup);return i?(0,I.jsxs)(`div`,{className:`mdw-top docp-top`,children:[e,(0,I.jsxs)(`div`,{className:`mdw-head`,children:[(0,I.jsx)(`div`,{className:`mdw-title`,children:t||`文档`}),(0,I.jsxs)(`div`,{className:`mdw-path`,children:[n,r?` · 未保存`:``,l?` · 外部`:``]}),(0,I.jsx)(`span`,{className:`grow`}),u,(0,I.jsxs)(`div`,{className:`docp-actions`,children:[v.map(e=>x(e.id)),(0,I.jsxs)(N,{menu:d,className:`mdw-act-menu`,children:[S.map(e=>(0,I.jsxs)(`div`,{className:`mdw-fmt-menu-group`,role:`group`,"aria-label":e.label,children:[(0,I.jsx)(`div`,{className:`mdw-fmt-menu-cap`,children:e.label}),e.items.map(e=>{let t=g[e.id],n=t?.danger||D(L,e.id).danger;return(0,I.jsxs)(`button`,{type:`button`,role:`menuitem`,className:`mdw-fmt-menu-item`+(n?` danger`:``),onClick:()=>b(e.id),children:[t?.label||D(L,e.id).label||e.id,t?.hint?(0,I.jsx)(`span`,{className:`hint`,children:t.hint}):null]},e.id)})]},e.id)),C.map(e=>{let t=g[e.id];return(0,I.jsx)(`button`,{type:`button`,role:`menuitem`,className:`mdw-fmt-menu-item`+(t?.danger||D(L,e.id).danger?` danger`:``),onClick:()=>b(e.id),children:t?.label||D(L,e.id).label||e.id},e.id)}),(0,I.jsx)(`div`,{className:`mdw-fmt-menu-sep`,role:`separator`}),(0,I.jsx)(`button`,{type:`button`,role:`menuitem`,className:`mdw-fmt-menu-item`,onClick:()=>{d.setOpen(!1),h(!0)},children:`自定义工具栏…`})]})]})]}),m&&(0,F.createPortal)((0,I.jsx)(`div`,{className:`ta-panel-mask`,onClick:()=>h(!1),children:(0,I.jsx)(`div`,{className:`ta-panel-wrap`,onClick:e=>e.stopPropagation(),children:(0,I.jsx)(E,{kind:L,layout:f,setLayout:p,onClose:()=>h(!1)})})}),document.body)]}):(0,I.jsxs)(`div`,{className:`mdw-top docp-top`,children:[e,(0,I.jsxs)(`div`,{className:`mdw-head`,children:[(0,I.jsx)(`div`,{className:`mdw-title`,children:t||`文档`}),(0,I.jsxs)(`div`,{className:`mdw-path`,children:[n,r?` · 未保存`:``,l?` · 外部`:``]}),(0,I.jsx)(`span`,{className:`grow`}),u,(0,I.jsx)(`div`,{className:`docp-actions`,children:(0,I.jsx)(`span`,{className:`docp-tag ext`,children:`只读`})})]})]})}function z(e,t,n){return{id:e,label:t,items:n.filter(Boolean)}}var B=o({default:()=>H,useWikiNav:()=>V});function V(e){let t=d()||{},n=a(),i=e||t.model,o=(0,P.useRef)(null),s=(0,P.useCallback)(async()=>{if(!o.current)try{o.current=(await r(`/api/docs/index`)).index||[]}catch{o.current=[]}return o.current},[]),l=(0,P.useCallback)(async(e,t,n={})=>{let r=(t||await s()).find(t=>t.docId===e);c(i,{component:`doc`,name:r?r.name:e,config:{docId:e,...n.repoKey?{repoKey:n.repoKey}:{},...n.boardKey?{boardKey:n.boardKey,boardName:n.boardName||``}:{}},location:`center`})},[i,s]),u=(0,P.useCallback)(async e=>{let t=await s(),r=x(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> 创建`)},[s,l,n]);return{nav:u,onClick:(0,P.useCallback)(e=>{let t=e.target.closest(`[data-wl]`);t&&(e.preventDefault(),u(t.getAttribute(`data-wl`)))},[u]),ensureIndex:s,openByDocId:l}}function H({docId:e,repoKey:t,boardKey:i,boardName:o,model:s,tabId:u}){let d=a(),{dialog:x,node:E}=n(),D=(0,P.useRef)(new Map),O=(0,P.useRef)(null),k=(0,P.useRef)(null),{onClick:A,openByDocId:j}=V(s),M=t?`repo`:i?`board`:``,N=t||i||``,F=(0,P.useMemo)(()=>t?{repoKey:t}:i?{boardKey:i,boardName:o||``}:{},[t,i,o]),[L,R]=(0,P.useState)(null),[B,H]=(0,P.useState)(``),[re,W]=(0,P.useState)(!1),[G,K]=(0,P.useState)(`split`),[q,J]=(0,P.useState)([]),[ie,Y]=(0,P.useState)(null),X=(0,P.useRef)(null);(0,P.useEffect)(()=>{X.current=L},[L]);let Z=(0,P.useCallback)(async()=>{H(``);try{let t=await r(`/api/docs/item?ref=`+encodeURIComponent(e||``));R(t),W(!1)}catch(e){H(String(e.message||e)),R(null)}},[e]);(0,P.useEffect)(()=>{R(null),Z()},[Z]);let oe=(0,P.useCallback)(()=>{if(!N){J([]);return}if(M===`repo`){r(`/api/repos/docs?id=`+encodeURIComponent(N)).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/${N}.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}),J(n)}).catch(()=>J(e?[{docId:e,label:`当前`,note:``,main:!0}]:[]));return}r(`/api/boards`).then(t=>{let n=(t&&t.boards||(Array.isArray(t)?t:[])).find(e=>e.id===N||e.key===N),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})}J(r)}).catch(()=>J(e?[{docId:e,label:`当前`,note:``,main:!0}]:[]))},[N,M,e]);(0,P.useEffect)(()=>{oe()},[oe]);let[se,ce]=(0,P.useState)(null);(0,P.useEffect)(()=>{r(`/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());ce(t)}).catch(()=>{})},[]);let Q=!!(L&&L.writable),le=(0,P.useMemo)(()=>L?b(L.body,[],Q?se:null):``,[L,se,Q]),ue=(0,P.useMemo)(()=>L?f(L.body):[],[L]);(0,P.useEffect)(()=>{let e=k.current;if(!e)return;let t=()=>e.querySelector(`.mdw-preview, .mdw-lp`)||null;Y(t());let n=typeof MutationObserver<`u`?new MutationObserver(()=>Y(t())):null;return n&&n.observe(e,{childList:!0,subtree:!0}),()=>{n&&n.disconnect()}},[L,G,le]);let $=e=>e().catch(e=>d(String(e.message||e))),de=(0,P.useCallback)(e=>j(e,null,F),[j,F]),fe=(0,P.useCallback)(()=>{let e=s;e&&N&&c(e,{component:`refs`,name:`文档列表`,config:t?{repoKey:t}:{boardKey:i,boardName:o||``},location:`right`})},[s,N,t,i,o]),pe=()=>{N&&$(async()=>{let t=await x({title:`补充介绍文档`,input:!0,placeholder:`文档名(如 architecture / api-notes)`});if(t===null)return;let n=ee(String(t).trim()||`note`).replace(/\.md$/i,``),i=`${String(e||``).startsWith(`rel:`)?U(e):M===`repo`?`repo/${N}`:`board/${o||N}`}/reference/${n}.md`;await r(`/api/docs/item`,{method:`POST`,body:{rel:i,body:`# ${String(t).trim()||n}\n\n(待补)\n`}});try{M===`repo`?await r(`/api/repos/docs`,{method:`POST`,body:{id:N,rel:i}}):await r(`/api/docs/link`,{method:`POST`,body:{board:N,doc:i}})}catch{}d(`已补充:${i}`),oe(),j(`rel:`+i,null,F)})},me=()=>$(async()=>{if(!L||!Q)return;let t=await r(`/api/docs/item`,{method:`PATCH`,body:{ref:e,body:L.body}});R(e=>({...e,body:L.body,summary:t.summary})),W(!1),v(D.current,e),d(t.summary?`已保存,摘要已回写`:`已保存`)}),he=(t,n=`op`)=>{L&&(h(D.current,e,{body:L.body},n),W(!0),R(e=>({...e,body:t,title:w(t,e.title)})))},ge=(t,n=`typing`)=>{if(!L)return;h(D.current,e,{body:L.body},n),W(!0);let r=/^#\s+/m.test(L.body)?L.body.replace(/^#\s+.+$/m,`# ${t||`未命名文档`}`):`# ${t||`未命名文档`}\n\n${L.body}`;R(e=>({...e,body:r,title:t}))},_e=()=>{if(!L)return;let t=m(D.current,e,{body:L.body});t&&(R(e=>({...e,body:t.body,title:w(t.body,e.title)})),W(!0),requestAnimationFrame(()=>O.current?.caretFromDiff?.(L.body,t.body)))},ve=()=>{if(!L)return;let t=_(D.current,e,{body:L.body});t&&(R(e=>({...e,body:t.body,title:w(t.body,e.title)})),W(!0),requestAnimationFrame(()=>O.current?.caretFromDiff?.(L.body,t.body)))},ye=async(t,n={})=>{if(!Q)return;let r=[...t||[]];if(r.length)try{let t=await S(r,{local:!0,onProgress:(e,t,n)=>d(`正在上传 ${e}/${t}:${n.name}`)}),i=C(t);if(!i)return;let a=X.current||L;if(!a)return;let o=g(a.body,i,n);h(D.current,e,{body:a.body}),W(!0),R(e=>e&&{...e,body:o.body,title:w(o.body,e.title)}),d(`已插入 ${t.length} 个附件`)}catch(e){d(`附件上传失败:${String(e.message||e)}`)}},be=()=>{L&&L.rel&&$(async()=>{let t=await x({title:`重命名文档`,input:!0,value:L.rel,placeholder:`新路径(相对 docs 根,以 .md 结尾)`});if(t===null)return;let n=String(t).trim();if(n&&n!==L.rel){if(!/\.md$/i.test(n))return d(`文档路径必须以 .md 结尾`);try{await r(`/api/docs/item`,{method:`POST`,body:{rel:n,body:L.body}})}catch(e){d(`重命名失败:${String(e.message||e)}`);return}await r(`/api/docs/item`,{method:`DELETE`,body:{ref:e}}),v(D.current,e),d(`已重命名为:${n}`),j(`rel:`+n,null,F)}})},xe=()=>{L&&$(async()=>{await x({title:`删除文档「${L.title||L.rel||e}」`,message:`磁盘上的 ${L.rel||e} 会被一并删除,不可恢复。`,danger:!0,okText:`删除`})&&(await r(`/api/docs/item`,{method:`DELETE`,body:{ref:e}}),d(`已删除:${L.rel||e}`),s&&u&&s.doAction(l.deleteTab(u)))})},Se=()=>$(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 r(`/api/docs/item`,{method:`POST`,body:{rel:t,body:`# ${n}\n\n(待补)\n`}}),d(`已创建:${t}`),await Z()});if(L&&L.dir)return(0,I.jsxs)(`div`,{className:`mdw docp`,children:[(0,I.jsxs)(`div`,{className:`docp-head`,children:[(0,I.jsx)(`span`,{className:`docp-path mono`,children:L.path}),(0,I.jsx)(`span`,{className:`docp-tag ext`,children:`外部目录 · 只读`})]}),(0,I.jsxs)(`div`,{className:`docp-files`,children:[L.files.map(e=>(0,I.jsx)(`button`,{className:`docp-file`,onClick:()=>j(`path:`+e,null),children:e},e)),!L.files.length&&(0,I.jsx)(`div`,{className:`muted pad`,children:`(目录里还没有 .md 文档)`})]})]});if(B)return(0,I.jsx)(`div`,{className:`mdw docp`,children:(0,I.jsxs)(`div`,{className:`pad stack`,children:[(0,I.jsx)(`div`,{children:(0,I.jsx)(`strong`,{children:`文档打开失败`})}),(0,I.jsx)(`div`,{className:`hint`,children:B})]})});if(!L)return(0,I.jsx)(`div`,{className:`mdw`,children:(0,I.jsx)(`div`,{className:`pad muted`,children:`载入中…`})});if(L.missing){let t=String(e||``).startsWith(`rel:`)||!String(e||``).startsWith(`path:`);return(0,I.jsxs)(`div`,{className:`mdw docp`,children:[(0,I.jsx)(`div`,{className:`docp-head`,children:(0,I.jsx)(`span`,{className:`docp-path mono`,children:L.rel||L.path||e})}),(0,I.jsxs)(`div`,{className:`pad stack`,children:[(0,I.jsx)(`div`,{children:(0,I.jsx)(`strong`,{children:`文档还没有落盘`})}),(0,I.jsx)(`div`,{className:`hint`,children:`描述内容的权威是磁盘上的 .md 文件——对应的字符串字段会在读取时播种,也可以直接创建骨架。`}),t&&(0,I.jsx)(`div`,{children:(0,I.jsx)(`button`,{className:`btn sm`,onClick:Se,children:`创建骨架`})})]})]})}let Ce=Q?G:`read`;return(0,I.jsxs)(`div`,{className:`mdw docp`,"data-mode":Ce,onClick:A,ref:k,children:[(0,I.jsxs)(`div`,{className:`mdw-main`,children:[(0,I.jsx)(ne,{crumb:(0,I.jsx)(T,{}),title:L.title||L.rel||L.path||`文档`,pathLabel:L.rel||L.path||``,dirty:re,writable:Q,external:!!L.external,menuGroups:[z(`edit`,`编辑`,[{id:`mode`,label:G===`edit`?`返回实时预览`:`源码模式`,hint:G===`edit`?`当前`:``,run:()=>K(G===`edit`?`split`:`edit`)}]),z(`doc`,`文档`,[{id:`rename`,label:`重命名`,run:be},{id:`delete`,label:`删除`,run:xe,danger:!0}]),z(`view`,`查看`,[N&&{id:`list`,label:`文字列表`,hint:`右侧边栏`,run:fe}])],onSave:me}),L.summary&&Q&&(0,I.jsxs)(`div`,{className:`docp-summary`,children:[`摘要(回写 desc):`,L.summary]}),(0,I.jsx)(p,{mode:Ce,title:L.title,body:L.body,previewHtml:le,onTitle:Q?ge:null,onBody:Q?he:null,onFiles:Q?ye:null,attachments:[],docKey:e,editorApiRef:O,onSave:Q?me:null,onUndo:Q?_e:null,onRedo:Q?ve:null}),(0,I.jsx)(te,{host:`ref`,refId:e,allow:{file:!0,url:!0,task:!1,ref:!0},disabled:!Q,disabledText:`只读文档不能添加附件。`,onOpenDoc:e=>{let t=y(e);t&&j(t,null,F)}}),(0,I.jsx)(`div`,{className:`docp-hint`,children:`双链 [[]] 点击跳转 · Ctrl+S 保存 · 文档即磁盘文件(~/.nx-kv/docs/)`})]}),(0,I.jsx)(ae,{headings:ue,scrollRoot:ie,links:q,activeDocId:e,onOpenDoc:N?de:null,onAddRef:N?pe:null}),E]})}function U(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 re(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 W(e){return e?e.rel?`rel:`+e.rel:e.path?`path:`+e.path:``:``}function G({kind:e,owner:t,model:n}){let{openByDocId:i}=V(n),a=e===`board`?`组介绍`:`项目介绍`,o=e===`board`?t&&(t.id||t.key):t&&t.key,s=t&&t.name,c=(0,P.useMemo)(()=>re(t,e),[t,e]),[l,u]=(0,P.useState)([]),[d,f]=(0,P.useState)(``),[p,m]=(0,P.useState)(0),h=(0,P.useCallback)(()=>m(e=>e+1),[]);(0,P.useEffect)(()=>{let n=!0;if(!o){u([]);return}if(e===`repo`)r(`/api/repos/docs?id=`+encodeURIComponent(o)).then(e=>{if(!n)return;let t=[],r=W(e.main);f(r||c),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=W(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=W(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([]),f(c))});else{let e=()=>{let e=[];c&&e.push({docId:c,label:`主篇`,note:``,tag:``,main:!0,ref:``});for(let n of t?.docLinks||[]){let t=W(n);t&&e.push({docId:t,label:n.rel||n.path||`补充`,note:n.note||``,tag:n.tag||``,main:!1,ref:n.ref||``})}return e};r(`/api/boards/`+encodeURIComponent(String(o))).then(t=>{if(!n)return;let r=Array.isArray(t&&t.docLinks)?t.docLinks:null;if(!r){u(e()),f(c);return}let i=[],a=W(t&&t.introMain)||c;f(a),a&&i.push({docId:a,label:`主篇`,note:``,tag:``,main:!0,ref:``});for(let e of t&&t.introExtras||[]){let t=W(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=W(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()),f(c))})}return()=>{n=!1}},[e,o,t,c,p]);let g=(0,P.useMemo)(()=>e===`repo`&&o?{repoKey:o}:e===`board`&&o?{boardKey:o,boardName:s||``}:{},[e,o,s]);return{kind:e,label:a,ownerKey:o,docRef:c,mainDocId:d,links:l,openMain:(0,P.useCallback)(()=>{let e=d||c;e&&i(e,null,g)},[d,c,i,g]),openDoc:(0,P.useCallback)(e=>i(e,null,g),[i,g]),addRef:(0,P.useCallback)(async(t,n)=>{if(!o||!c.startsWith(`rel:`))return n&&n(`当前简介无法补充(需要自有树路径)`),null;let a=await t({title:`补充介绍文档`,input:!0,tagInput:!0,placeholder:`文档名(如 architecture / api-notes)`,tagPlaceholder:`标签(可选,如 qa)`});if(a===null)return null;let l=typeof a==`string`?a:a&&a.value||``,u=typeof a==`object`&&a&&a.tag||``,d=ee(String(l).trim()||`note`).replace(/\.md$/i,``),f=`${U(c)||(e===`repo`?`repo/${o}`:`board/${s||o}`)}/reference/${d}.md`;await r(`/api/docs/item`,{method:`POST`,body:{rel:f,body:`# ${String(l).trim()||d}\n\n(待补)\n`}});try{e===`repo`?await r(`/api/repos/docs`,{method:`POST`,body:{id:o,rel:f,tag:u||void 0}}):await r(`/api/docs/link`,{method:`POST`,body:{board:o,doc:f,tag:u||void 0}})}catch{}return n&&n(`已补充:${f}${u?` [${u}]`:``}`),h(),i(`rel:`+f,null,g),f},[o,c,e,s,i,g,h]),setLinkTag:(0,P.useCallback)(async(t,n,i)=>{if(!o)throw Error(`缺少归属`);let a=String(t||``).startsWith(`path:`)?{path:String(t).slice(5)}:{rel:String(t||``).startsWith(`rel:`)?String(t).slice(4):String(t||``)},s=i&&i.note||``;e===`repo`?await r(`/api/repos/docs`,{method:`POST`,body:{id:o,...a,note:s||void 0,tag:n||void 0}}):await r(`/api/docs/link`,{method:`POST`,body:{board:o,doc:a.path||a.rel,note:s||void 0,tag:n||void 0}}),h()},[o,e,h]),reload:h,canEdit:!!c}}function K(e){return e?e.rel?`rel:`+e.rel:e.path?`path:`+e.path:``:``}function q(e){let t=e.rel||e.path||``;return String(t).replace(/[\\/]+$/,``).split(/[\\/]/).pop()||t||`未命名`}function J(e,t,n){let r=[],i=e&&(e.main||e.introMain);i&&r.push({id:K(i),kind:`main`,label:`主篇`,sub:i.rel||i.path||``,tag:``,note:``,docId:K(i),removable:n===`repo`&&!!(t&&t.doc),removeTip:`摘除主篇自定义绑定(回退约定路径,文档不删)`,taggable:!1});for(let t of e&&(e.extras||e.introExtras)||[]){let e=K(t);e&&r.push({id:e,kind:`extra`,label:q(t),sub:t.rel||t.path||``,tag:``,note:``,docId:e,removable:!1,taggable:String(e).startsWith(`rel:`)})}(e&&(e.links||e.docLinks)||[]).forEach((e,t)=>{let i=K(e);i&&r.push({id:i,kind:`link`,label:q(e),sub:e.rel||e.path||``,tag:e.tag||``,note:e.note||``,docId:i,removeIndex:n===`repo`?t+2:t+1,removable:!0,taggable:!0})});for(let e of n===`repo`&&t&&t.boards||[]){let t=e.noteDocPath||``,n=e.noteDocRel||``,i=t?`path:`+t:n?`rel:`+n:``;i&&r.push({id:i,kind:`scoped`,label:`${e.name} · 组内描述`,sub:t||n,tag:``,note:e.note||``,docId:i,removable:!1,taggable:!1})}return r.filter(e=>e.docId)}var ie={main:`● `,scoped:`◇ `,extra:`○ `,link:`○ `};function Y({kind:e,owner:t,model:o,onClose:s,onChanged:l}){let u=a(),{dialog:f,node:p}=n(),m=d()||{},h=o||m.model,g=G({kind:e,owner:t,model:h}),_=g.ownerKey,v=t&&t.name,[y,b]=(0,P.useState)([]),[x,S]=(0,P.useState)(!0),[C,w]=(0,P.useState)(``),T=(0,P.useCallback)(async()=>{if(!_){b([]),S(!1);return}S(!0);try{let n=e===`repo`?await r(`/api/repos/docs?id=`+encodeURIComponent(_)):await r(`/api/boards/`+encodeURIComponent(String(_)));b(J(n,t,e)),w(``)}catch(e){b([]),w(String(e.message||e))}finally{S(!1)}},[e,_,t]);(0,P.useEffect)(()=>{T()},[T]);let E=t=>{if(!t)return;let n=h;if(!n){u(`工作区不可用,无法打开文档`);return}c(n,{component:`doc`,name:t.label||t.sub||t.docId,config:{docId:t.docId,...e===`repo`?{repoKey:_}:{boardKey:_,boardName:v||``}},location:`center`}),s()},D=e=>e().catch(e=>u(String(e.message||e))),O=t=>D(async()=>{await f({message:`摘除「${t.label}」?${t.kind===`main`?`(只拆绑定,文档不删)`:`(文档不删,仅移出列表)`}`,danger:!0})&&(e===`repo`?await r(`/api/repos/docs`,{method:`DELETE`,body:{id:_,index:t.removeIndex}}):await r(`/api/docs/link`,{method:`POST`,body:{board:_,remove:t.removeIndex}}),u(`已摘除`),T(),l&&l())}),k=e=>D(async()=>{let t=await f({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 g.setLinkTag(e.docId,n,e),u(n?`标签已设为 [${n}]`:`标签已清除`),T(),l&&l()}),A=()=>D(async()=>{if(!_||!String(g.docRef||``).startsWith(`rel:`)){u(`当前简介无法补充(需要自有树路径)`);return}let t=await f({title:`补充介绍文档`,input:!0,tagInput:!0,placeholder:`文档名(如 architecture / api-notes)`,tagPlaceholder:`标签(可选,如 qa)`});if(t===null)return;let n=typeof t==`string`?t:t&&t.value||``,i=typeof t==`object`&&t&&t.tag||``,a=ee(String(n).trim()||`note`).replace(/\.md$/i,``),o=`${U(g.docRef)||(e===`repo`?`repo/${_}`:`board/${v||_}`)}/reference/${a}.md`;await r(`/api/docs/item`,{method:`POST`,body:{rel:o,body:`# ${String(n).trim()||a}\n\n(待补)\n`}});try{e===`repo`?await r(`/api/repos/docs`,{method:`POST`,body:{id:_,rel:o,tag:i||void 0}}):await r(`/api/docs/link`,{method:`POST`,body:{board:_,doc:o,tag:i||void 0}})}catch{}u(`已补充:${o}${i?` [${i}]`:``}`),await T(),l&&l(),E({docId:`rel:`+o,label:String(n).trim()||a,sub:o})}),j=!!String(g.docRef||``).startsWith(`rel:`)&&_,M=y.length,N=`文档列表 · ${v||``}${e===`board`?`(项目组)`:``}`;return(0,I.jsxs)(i,{size:`md`,title:N,onClose:s,children:[(0,I.jsxs)(`div`,{className:`nx-dl`,children:[(0,I.jsxs)(`div`,{className:`nx-dl-head`,children:[(0,I.jsx)(`span`,{className:`nx-dl-count`,children:M?`${M} 篇`:`还没有文档`}),(0,I.jsx)(`span`,{className:`nx-dl-hint`,children:`点标题在主内容区打开`}),(0,I.jsx)(`span`,{className:`grow`}),j&&(0,I.jsx)(`button`,{type:`button`,className:`btn ghost sm nx-dl-add`,title:`补充一篇介绍文档(reference)`,onClick:A,children:`+ 补充`})]}),C?(0,I.jsx)(`div`,{className:`rpd-err`,children:C}):null,!C&&x&&M===0?(0,I.jsx)(`div`,{className:`rpd-empty`,children:`载入中…`}):null,!C&&!x&&M===0?(0,I.jsx)(`div`,{className:`rpd-none`,children:`还没有文档 —— 点「+ 补充」写第一篇`}):null,(0,I.jsx)(`div`,{className:`nx-dl-list`,children:y.map(e=>(0,I.jsxs)(`div`,{className:`nx-dl-row-wrap`,children:[(0,I.jsxs)(`button`,{type:`button`,className:`nx-dl-row`,title:`${e.sub||e.label}\n点击在主内容区打开(可编辑)`,onClick:()=>E(e),children:[(0,I.jsxs)(`span`,{className:`nx-dl-row-title`,children:[ie[e.kind]||`○ `,e.label]}),e.tag?(0,I.jsx)(`span`,{className:`rpd-badge`,children:e.tag}):null]}),(0,I.jsxs)(`span`,{className:`nx-docs-modal-item-acts`,children:[e.taggable&&(0,I.jsx)(`button`,{type:`button`,className:`nx-docs-modal-mini`,title:e.tag?`改标签(当前:${e.tag})`:`加标签`,onClick:()=>k(e),children:`#`}),e.removable&&(0,I.jsx)(`button`,{type:`button`,className:`nx-docs-modal-mini danger`,title:e.removeTip||`摘除「${e.label}」(文档不删)`,onClick:()=>O(e),children:`×`})]})]},e.id))})]}),p]})}function X(e){return e<=1?18:e===2?12:8}function ae({headings:e=[],scrollRoot:t=null,links:n=[],activeDocId:r=``,onOpenDoc:i=null,onAddRef:a=null}){let[o,s]=(0,P.useState)(!1),[c,l]=(0,P.useState)(``),u=(0,P.useMemo)(()=>e||[],[e]),d=(0,P.useMemo)(()=>n||[],[n]);(0,P.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,P.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,I.jsxs)(`aside`,{className:`doc-rail`+(o?` open`:``),"aria-label":`文档目录`,children:[(0,I.jsxs)(`button`,{type:`button`,className:`doc-rail-menu`,title:o?`收起目录`:`展开目录`,"aria-expanded":o,onClick:()=>s(e=>!e),children:[(0,I.jsx)(`span`,{}),(0,I.jsx)(`span`,{}),(0,I.jsx)(`span`,{})]}),(0,I.jsx)(`div`,{className:`doc-rail-ticks`,role:`navigation`,"aria-label":`章节`,children:u.map(e=>(0,I.jsx)(`button`,{type:`button`,className:`doc-rail-tick`+(c===e.id?` on`:``),style:{"--tw":`${X(e.level)}px`},title:e.text,"aria-current":c===e.id?`true`:void 0,onClick:()=>f(e.id)},e.id))}),o&&(0,I.jsxs)(`div`,{className:`doc-rail-panel`,children:[u.length>0&&(0,I.jsxs)(`div`,{className:`doc-rail-sec`,children:[(0,I.jsx)(`div`,{className:`doc-rail-sec-lab`,children:`本章`}),u.map(e=>(0,I.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,I.jsxs)(`div`,{className:`doc-rail-sec`,children:[(0,I.jsx)(`div`,{className:`doc-rail-sec-lab`,children:`介绍文档`}),d.map(e=>(0,I.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,I.jsx)(`button`,{type:`button`,className:`doc-rail-add`,onClick:a,children:`+ 补充文档`})]})]})]})}function Z({kind:e,owner:t,model:n}){let{label:r,docRef:i,links:a,openMain:o}=G({kind:e,owner:t,model:n}),[s,c]=(0,P.useState)(!1);if(!t||!i)return null;let l=a.find(e=>e.main),u=l?l.docId:i,d=u.startsWith(`rel:`)?u.slice(4):u,f=a.filter(e=>!e.main).length;return(0,I.jsxs)(`div`,{className:`nx-intro`,children:[(0,I.jsxs)(`div`,{className:`nx-intro-head`,children:[(0,I.jsx)(`button`,{type:`button`,className:`nx-intro-link-main`,title:`打开${r}(在主内容区阅读 / 编辑)`,onClick:o,children:r}),(0,I.jsx)(`span`,{className:`nx-intro-path mono`,children:d}),(0,I.jsx)(`span`,{className:`nx-intro-spacer`}),(0,I.jsxs)(`button`,{type:`button`,className:`nx-intro-btn`,title:`查看${r}的全部文章(点标题在主内容区打开,可编辑)`,onClick:()=>c(!0),children:[`查看详情`,f>0?` ${f}`:``]})]}),s&&(0,I.jsx)(Y,{kind:e,owner:t,model:n,onClose:()=>c(!1)})]})}export{V as i,Y as n,B as r,Z as t};
1
+ import{g as e,h as t,l as n,m as r,o as i,p as a,v as o,y as s}from"./task-status-BnymQMTw.js";import{r as c,v as l,w as u}from"./workspace-C_5X2gIr.js";import{n as d}from"./app-context-D7HAx67n.js";import{_ as f,a as p,i as m,n as h,p as g,r as _,t as v,u as y,v as b,y as x}from"./md-history-DB5forf2.js";import{a as S,i as C}from"./upload-BIMbGcCB.js";import{a as w,r as ee}from"./md-parse-awNLHAzO.js";import{t as T}from"./route-crumb-C8JzPIax.js";import{a as E,c as D,i as O,l as k,o as A,r as j,s as M,t as N,u as te}from"./tool-bar-DGCwnUcn.js";var P=s(e(),1),F=u(),I=t(),L=`doc`,R=[{id:`edit`,label:`编辑`},{id:`doc`,label:`文档`},{id:`view`,label:`查看`}];function ne({crumb:e=null,title:t,pathLabel:n=``,dirty:r=!1,writable:i=!1,onSave:a=null,onSaveLabel:o=`保存`,menuGroups:s=[],saving:c=!1,external:l=!1,afterTitle:u=null}){let d=O(),{layout:f,setLayout:p}=A(L),[m,h]=(0,P.useState)(!1),g={};for(let e of s||[])for(let t of e?.items||[])t&&t.id&&(g[t.id]=t);g.save=a&&{id:`save`,label:c?`保存中…`:o,run:a,primary:!0,disabled:c||!r};let _=e=>e===`more`||!!g[e],v=f.filter(e=>k(L,e)&&_(e.id)),y=f.filter(e=>M(L,e)&&_(e.id)),b=e=>{g[e]?.run?.(),d.setOpen(!1)},x=e=>{if(e===`more`)return(0,I.jsx)(`div`,{className:`docp-more`,ref:d.ref,children:(0,I.jsx)(`button`,{type:`button`,className:`btn ghost sm${d.open?` on`:``}`,title:`更多操作`,"aria-haspopup":`menu`,"aria-expanded":d.open,onClick:e=>j(d,e,`right`),children:`更多`})},`more`);let t=g[e];return t?(0,I.jsx)(`button`,{type:`button`,className:t.primary||e===`save`?`btn sm primary docp-save`:`btn ghost sm`,disabled:!!t.disabled,onClick:()=>b(e),children:t.label||D(L,e).label||e},e):null},S=R.map(e=>({...e,items:y.filter(t=>D(L,t.id).menuGroup===e.id)})).filter(e=>e.items.length),C=y.filter(e=>!D(L,e.id).menuGroup);return i?(0,I.jsxs)(`div`,{className:`mdw-top docp-top`,children:[e,(0,I.jsxs)(`div`,{className:`mdw-head`,children:[(0,I.jsx)(`div`,{className:`mdw-title`,children:t||`文档`}),(0,I.jsxs)(`div`,{className:`mdw-path`,children:[n,r?` · 未保存`:``,l?` · 外部`:``]}),(0,I.jsx)(`span`,{className:`grow`}),u,(0,I.jsxs)(`div`,{className:`docp-actions`,children:[v.map(e=>x(e.id)),(0,I.jsxs)(N,{menu:d,className:`mdw-act-menu`,children:[S.map(e=>(0,I.jsxs)(`div`,{className:`mdw-fmt-menu-group`,role:`group`,"aria-label":e.label,children:[(0,I.jsx)(`div`,{className:`mdw-fmt-menu-cap`,children:e.label}),e.items.map(e=>{let t=g[e.id],n=t?.danger||D(L,e.id).danger;return(0,I.jsxs)(`button`,{type:`button`,role:`menuitem`,className:`mdw-fmt-menu-item`+(n?` danger`:``),onClick:()=>b(e.id),children:[t?.label||D(L,e.id).label||e.id,t?.hint?(0,I.jsx)(`span`,{className:`hint`,children:t.hint}):null]},e.id)})]},e.id)),C.map(e=>{let t=g[e.id];return(0,I.jsx)(`button`,{type:`button`,role:`menuitem`,className:`mdw-fmt-menu-item`+(t?.danger||D(L,e.id).danger?` danger`:``),onClick:()=>b(e.id),children:t?.label||D(L,e.id).label||e.id},e.id)}),(0,I.jsx)(`div`,{className:`mdw-fmt-menu-sep`,role:`separator`}),(0,I.jsx)(`button`,{type:`button`,role:`menuitem`,className:`mdw-fmt-menu-item`,onClick:()=>{d.setOpen(!1),h(!0)},children:`自定义工具栏…`})]})]})]}),m&&(0,F.createPortal)((0,I.jsx)(`div`,{className:`ta-panel-mask`,onClick:()=>h(!1),children:(0,I.jsx)(`div`,{className:`ta-panel-wrap`,onClick:e=>e.stopPropagation(),children:(0,I.jsx)(E,{kind:L,layout:f,setLayout:p,onClose:()=>h(!1)})})}),document.body)]}):(0,I.jsxs)(`div`,{className:`mdw-top docp-top`,children:[e,(0,I.jsxs)(`div`,{className:`mdw-head`,children:[(0,I.jsx)(`div`,{className:`mdw-title`,children:t||`文档`}),(0,I.jsxs)(`div`,{className:`mdw-path`,children:[n,r?` · 未保存`:``,l?` · 外部`:``]}),(0,I.jsx)(`span`,{className:`grow`}),u,(0,I.jsx)(`div`,{className:`docp-actions`,children:(0,I.jsx)(`span`,{className:`docp-tag ext`,children:`只读`})})]})]})}function z(e,t,n){return{id:e,label:t,items:n.filter(Boolean)}}var B=o({default:()=>H,useWikiNav:()=>V});function V(e){let t=d()||{},n=a(),i=e||t.model,o=(0,P.useRef)(null),s=(0,P.useCallback)(async()=>{if(!o.current)try{o.current=(await r(`/api/docs/index`)).index||[]}catch{o.current=[]}return o.current},[]),l=(0,P.useCallback)(async(e,t,n={})=>{let r=(t||await s()).find(t=>t.docId===e);c(i,{component:`doc`,name:r?r.name:e,config:{docId:e,...n.repoKey?{repoKey:n.repoKey}:{},...n.boardKey?{boardKey:n.boardKey,boardName:n.boardName||``}:{}},location:`center`})},[i,s]),u=(0,P.useCallback)(async e=>{let t=await s(),r=x(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> 创建`)},[s,l,n]);return{nav:u,onClick:(0,P.useCallback)(e=>{let t=e.target.closest(`[data-wl]`);t&&(e.preventDefault(),u(t.getAttribute(`data-wl`)))},[u]),ensureIndex:s,openByDocId:l}}function H({docId:e,repoKey:t,boardKey:i,boardName:o,model:s,tabId:u}){let d=a(),{dialog:x,node:E}=n(),D=(0,P.useRef)(new Map),O=(0,P.useRef)(null),k=(0,P.useRef)(null),{onClick:A,openByDocId:j}=V(s),M=t?`repo`:i?`board`:``,N=t||i||``,F=(0,P.useMemo)(()=>t?{repoKey:t}:i?{boardKey:i,boardName:o||``}:{},[t,i,o]),[L,R]=(0,P.useState)(null),[B,H]=(0,P.useState)(``),[re,W]=(0,P.useState)(!1),[G,K]=(0,P.useState)(`split`),[q,J]=(0,P.useState)([]),[ie,Y]=(0,P.useState)(null),X=(0,P.useRef)(null);(0,P.useEffect)(()=>{X.current=L},[L]);let Z=(0,P.useCallback)(async()=>{H(``);try{let t=await r(`/api/docs/item?ref=`+encodeURIComponent(e||``));R(t),W(!1)}catch(e){H(String(e.message||e)),R(null)}},[e]);(0,P.useEffect)(()=>{R(null),Z()},[Z]);let oe=(0,P.useCallback)(()=>{if(!N){J([]);return}if(M===`repo`){r(`/api/repos/docs?id=`+encodeURIComponent(N)).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/${N}.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}),J(n)}).catch(()=>J(e?[{docId:e,label:`当前`,note:``,main:!0}]:[]));return}r(`/api/boards`).then(t=>{let n=(t&&t.boards||(Array.isArray(t)?t:[])).find(e=>e.id===N||e.key===N),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})}J(r)}).catch(()=>J(e?[{docId:e,label:`当前`,note:``,main:!0}]:[]))},[N,M,e]);(0,P.useEffect)(()=>{oe()},[oe]);let[se,ce]=(0,P.useState)(null);(0,P.useEffect)(()=>{r(`/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());ce(t)}).catch(()=>{})},[]);let Q=!!(L&&L.writable),le=(0,P.useMemo)(()=>L?b(L.body,[],Q?se:null):``,[L,se,Q]),ue=(0,P.useMemo)(()=>L?f(L.body):[],[L]);(0,P.useEffect)(()=>{let e=k.current;if(!e)return;let t=()=>e.querySelector(`.mdw-preview, .mdw-lp`)||null;Y(t());let n=typeof MutationObserver<`u`?new MutationObserver(()=>Y(t())):null;return n&&n.observe(e,{childList:!0,subtree:!0}),()=>{n&&n.disconnect()}},[L,G,le]);let $=e=>e().catch(e=>d(String(e.message||e))),de=(0,P.useCallback)(e=>j(e,null,F),[j,F]),fe=(0,P.useCallback)(()=>{let e=s;e&&N&&c(e,{component:`refs`,name:`文档列表`,config:t?{repoKey:t}:{boardKey:i,boardName:o||``},location:`right`})},[s,N,t,i,o]),pe=()=>{N&&$(async()=>{let t=await x({title:`补充介绍文档`,input:!0,placeholder:`文档名(如 architecture / api-notes)`});if(t===null)return;let n=ee(String(t).trim()||`note`).replace(/\.md$/i,``),i=`${String(e||``).startsWith(`rel:`)?U(e):M===`repo`?`repo/${N}`:`board/${o||N}`}/reference/${n}.md`;await r(`/api/docs/item`,{method:`POST`,body:{rel:i,body:`# ${String(t).trim()||n}\n\n(待补)\n`}});try{M===`repo`?await r(`/api/repos/docs`,{method:`POST`,body:{id:N,rel:i}}):await r(`/api/docs/link`,{method:`POST`,body:{board:N,doc:i}})}catch{}d(`已补充:${i}`),oe(),j(`rel:`+i,null,F)})},me=()=>$(async()=>{if(!L||!Q)return;let t=await r(`/api/docs/item`,{method:`PATCH`,body:{ref:e,body:L.body}});R(e=>({...e,body:L.body,summary:t.summary})),W(!1),v(D.current,e),d(t.summary?`已保存,摘要已回写`:`已保存`)}),he=(t,n=`op`)=>{L&&(h(D.current,e,{body:L.body},n),W(!0),R(e=>({...e,body:t,title:w(t,e.title)})))},ge=(t,n=`typing`)=>{if(!L)return;h(D.current,e,{body:L.body},n),W(!0);let r=/^#\s+/m.test(L.body)?L.body.replace(/^#\s+.+$/m,`# ${t||`未命名文档`}`):`# ${t||`未命名文档`}\n\n${L.body}`;R(e=>({...e,body:r,title:t}))},_e=()=>{if(!L)return;let t=m(D.current,e,{body:L.body});t&&(R(e=>({...e,body:t.body,title:w(t.body,e.title)})),W(!0),requestAnimationFrame(()=>O.current?.caretFromDiff?.(L.body,t.body)))},ve=()=>{if(!L)return;let t=_(D.current,e,{body:L.body});t&&(R(e=>({...e,body:t.body,title:w(t.body,e.title)})),W(!0),requestAnimationFrame(()=>O.current?.caretFromDiff?.(L.body,t.body)))},ye=async(t,n={})=>{if(!Q)return;let r=[...t||[]];if(r.length)try{let t=await S(r,{local:!0,onProgress:(e,t,n)=>d(`正在上传 ${e}/${t}:${n.name}`)}),i=C(t);if(!i)return;let a=X.current||L;if(!a)return;let o=g(a.body,i,n);h(D.current,e,{body:a.body}),W(!0),R(e=>e&&{...e,body:o.body,title:w(o.body,e.title)}),d(`已插入 ${t.length} 个附件`)}catch(e){d(`附件上传失败:${String(e.message||e)}`)}},be=()=>{L&&L.rel&&$(async()=>{let t=await x({title:`重命名文档`,input:!0,value:L.rel,placeholder:`新路径(相对 docs 根,以 .md 结尾)`});if(t===null)return;let n=String(t).trim();if(n&&n!==L.rel){if(!/\.md$/i.test(n))return d(`文档路径必须以 .md 结尾`);try{await r(`/api/docs/item`,{method:`POST`,body:{rel:n,body:L.body}})}catch(e){d(`重命名失败:${String(e.message||e)}`);return}await r(`/api/docs/item`,{method:`DELETE`,body:{ref:e}}),v(D.current,e),d(`已重命名为:${n}`),j(`rel:`+n,null,F)}})},xe=()=>{L&&$(async()=>{await x({title:`删除文档「${L.title||L.rel||e}」`,message:`磁盘上的 ${L.rel||e} 会被一并删除,不可恢复。`,danger:!0,okText:`删除`})&&(await r(`/api/docs/item`,{method:`DELETE`,body:{ref:e}}),d(`已删除:${L.rel||e}`),s&&u&&s.doAction(l.deleteTab(u)))})},Se=()=>$(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 r(`/api/docs/item`,{method:`POST`,body:{rel:t,body:`# ${n}\n\n(待补)\n`}}),d(`已创建:${t}`),await Z()});if(L&&L.dir)return(0,I.jsxs)(`div`,{className:`mdw docp`,children:[(0,I.jsxs)(`div`,{className:`docp-head`,children:[(0,I.jsx)(`span`,{className:`docp-path mono`,children:L.path}),(0,I.jsx)(`span`,{className:`docp-tag ext`,children:`外部目录 · 只读`})]}),(0,I.jsxs)(`div`,{className:`docp-files`,children:[L.files.map(e=>(0,I.jsx)(`button`,{className:`docp-file`,onClick:()=>j(`path:`+e,null),children:e},e)),!L.files.length&&(0,I.jsx)(`div`,{className:`muted pad`,children:`(目录里还没有 .md 文档)`})]})]});if(B)return(0,I.jsx)(`div`,{className:`mdw docp`,children:(0,I.jsxs)(`div`,{className:`pad stack`,children:[(0,I.jsx)(`div`,{children:(0,I.jsx)(`strong`,{children:`文档打开失败`})}),(0,I.jsx)(`div`,{className:`hint`,children:B})]})});if(!L)return(0,I.jsx)(`div`,{className:`mdw`,children:(0,I.jsx)(`div`,{className:`pad muted`,children:`载入中…`})});if(L.missing){let t=String(e||``).startsWith(`rel:`)||!String(e||``).startsWith(`path:`);return(0,I.jsxs)(`div`,{className:`mdw docp`,children:[(0,I.jsx)(`div`,{className:`docp-head`,children:(0,I.jsx)(`span`,{className:`docp-path mono`,children:L.rel||L.path||e})}),(0,I.jsxs)(`div`,{className:`pad stack`,children:[(0,I.jsx)(`div`,{children:(0,I.jsx)(`strong`,{children:`文档还没有落盘`})}),(0,I.jsx)(`div`,{className:`hint`,children:`描述内容的权威是磁盘上的 .md 文件——对应的字符串字段会在读取时播种,也可以直接创建骨架。`}),t&&(0,I.jsx)(`div`,{children:(0,I.jsx)(`button`,{className:`btn sm`,onClick:Se,children:`创建骨架`})})]})]})}let Ce=Q?G:`read`;return(0,I.jsxs)(`div`,{className:`mdw docp`,"data-mode":Ce,onClick:A,ref:k,children:[(0,I.jsxs)(`div`,{className:`mdw-main`,children:[(0,I.jsx)(ne,{crumb:(0,I.jsx)(T,{}),title:L.title||L.rel||L.path||`文档`,pathLabel:L.rel||L.path||``,dirty:re,writable:Q,external:!!L.external,menuGroups:[z(`edit`,`编辑`,[{id:`mode`,label:G===`edit`?`返回实时预览`:`源码模式`,hint:G===`edit`?`当前`:``,run:()=>K(G===`edit`?`split`:`edit`)}]),z(`doc`,`文档`,[{id:`rename`,label:`重命名`,run:be},{id:`delete`,label:`删除`,run:xe,danger:!0}]),z(`view`,`查看`,[N&&{id:`list`,label:`文字列表`,hint:`右侧边栏`,run:fe}])],onSave:me}),L.summary&&Q&&(0,I.jsxs)(`div`,{className:`docp-summary`,children:[`摘要(回写 desc):`,L.summary]}),(0,I.jsx)(p,{mode:Ce,title:L.title,body:L.body,previewHtml:le,onTitle:Q?ge:null,onBody:Q?he:null,onFiles:Q?ye:null,attachments:[],docKey:e,editorApiRef:O,onSave:Q?me:null,onUndo:Q?_e:null,onRedo:Q?ve:null}),(0,I.jsx)(te,{host:`ref`,refId:e,allow:{file:!0,url:!0,task:!1,ref:!0},disabled:!Q,disabledText:`只读文档不能添加附件。`,onOpenDoc:e=>{let t=y(e);t&&j(t,null,F)}}),(0,I.jsx)(`div`,{className:`docp-hint`,children:`双链 [[]] 点击跳转 · Ctrl+S 保存 · 文档即磁盘文件(~/.nx-kv/docs/)`})]}),(0,I.jsx)(ae,{headings:ue,scrollRoot:ie,links:q,activeDocId:e,onOpenDoc:N?de:null,onAddRef:N?pe:null}),E]})}function U(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 re(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 W(e){return e?e.rel?`rel:`+e.rel:e.path?`path:`+e.path:``:``}function G({kind:e,owner:t,model:n}){let{openByDocId:i}=V(n),a=e===`board`?`组介绍`:`项目介绍`,o=e===`board`?t&&(t.id||t.key):t&&t.key,s=t&&t.name,c=(0,P.useMemo)(()=>re(t,e),[t,e]),[l,u]=(0,P.useState)([]),[d,f]=(0,P.useState)(``),[p,m]=(0,P.useState)(0),h=(0,P.useCallback)(()=>m(e=>e+1),[]);(0,P.useEffect)(()=>{let n=!0;if(!o){u([]);return}if(e===`repo`)r(`/api/repos/docs?id=`+encodeURIComponent(o)).then(e=>{if(!n)return;let t=[],r=W(e.main);f(r||c),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=W(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=W(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([]),f(c))});else{let e=()=>{let e=[];c&&e.push({docId:c,label:`主篇`,note:``,tag:``,main:!0,ref:``});for(let n of t?.docLinks||[]){let t=W(n);t&&e.push({docId:t,label:n.rel||n.path||`补充`,note:n.note||``,tag:n.tag||``,main:!1,ref:n.ref||``})}return e};r(`/api/boards/`+encodeURIComponent(String(o))).then(t=>{if(!n)return;let r=Array.isArray(t&&t.docLinks)?t.docLinks:null;if(!r){u(e()),f(c);return}let i=[],a=W(t&&t.introMain)||c;f(a),a&&i.push({docId:a,label:`主篇`,note:``,tag:``,main:!0,ref:``});for(let e of t&&t.introExtras||[]){let t=W(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=W(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()),f(c))})}return()=>{n=!1}},[e,o,t,c,p]);let g=(0,P.useMemo)(()=>e===`repo`&&o?{repoKey:o}:e===`board`&&o?{boardKey:o,boardName:s||``}:{},[e,o,s]);return{kind:e,label:a,ownerKey:o,docRef:c,mainDocId:d,links:l,openMain:(0,P.useCallback)(()=>{let e=d||c;e&&i(e,null,g)},[d,c,i,g]),openDoc:(0,P.useCallback)(e=>i(e,null,g),[i,g]),addRef:(0,P.useCallback)(async(t,n)=>{if(!o||!c.startsWith(`rel:`))return n&&n(`当前简介无法补充(需要自有树路径)`),null;let a=await t({title:`补充介绍文档`,input:!0,tagInput:!0,placeholder:`文档名(如 architecture / api-notes)`,tagPlaceholder:`标签(可选,如 qa)`});if(a===null)return null;let l=typeof a==`string`?a:a&&a.value||``,u=typeof a==`object`&&a&&a.tag||``,d=ee(String(l).trim()||`note`).replace(/\.md$/i,``),f=`${U(c)||(e===`repo`?`repo/${o}`:`board/${s||o}`)}/reference/${d}.md`;await r(`/api/docs/item`,{method:`POST`,body:{rel:f,body:`# ${String(l).trim()||d}\n\n(待补)\n`}});try{e===`repo`?await r(`/api/repos/docs`,{method:`POST`,body:{id:o,rel:f,tag:u||void 0}}):await r(`/api/docs/link`,{method:`POST`,body:{board:o,doc:f,tag:u||void 0}})}catch{}return n&&n(`已补充:${f}${u?` [${u}]`:``}`),h(),i(`rel:`+f,null,g),f},[o,c,e,s,i,g,h]),setLinkTag:(0,P.useCallback)(async(t,n,i)=>{if(!o)throw Error(`缺少归属`);let a=String(t||``).startsWith(`path:`)?{path:String(t).slice(5)}:{rel:String(t||``).startsWith(`rel:`)?String(t).slice(4):String(t||``)},s=i&&i.note||``;e===`repo`?await r(`/api/repos/docs`,{method:`POST`,body:{id:o,...a,note:s||void 0,tag:n||void 0}}):await r(`/api/docs/link`,{method:`POST`,body:{board:o,doc:a.path||a.rel,note:s||void 0,tag:n||void 0}}),h()},[o,e,h]),reload:h,canEdit:!!c}}function K(e){return e?e.rel?`rel:`+e.rel:e.path?`path:`+e.path:``:``}function q(e){let t=e.rel||e.path||``;return String(t).replace(/[\\/]+$/,``).split(/[\\/]/).pop()||t||`未命名`}function J(e,t,n){let r=[],i=e&&(e.main||e.introMain);i&&r.push({id:K(i),kind:`main`,label:`主篇`,sub:i.rel||i.path||``,tag:``,note:``,docId:K(i),removable:n===`repo`&&!!(t&&t.doc),removeTip:`摘除主篇自定义绑定(回退约定路径,文档不删)`,taggable:!1});for(let t of e&&(e.extras||e.introExtras)||[]){let e=K(t);e&&r.push({id:e,kind:`extra`,label:q(t),sub:t.rel||t.path||``,tag:``,note:``,docId:e,removable:!1,taggable:String(e).startsWith(`rel:`)})}(e&&(e.links||e.docLinks)||[]).forEach((e,t)=>{let i=K(e);i&&r.push({id:i,kind:`link`,label:q(e),sub:e.rel||e.path||``,tag:e.tag||``,note:e.note||``,docId:i,removeIndex:n===`repo`?t+2:t+1,removable:!0,taggable:!0})});for(let e of n===`repo`&&t&&t.boards||[]){let t=e.noteDocPath||``,n=e.noteDocRel||``,i=t?`path:`+t:n?`rel:`+n:``;i&&r.push({id:i,kind:`scoped`,label:`${e.name} · 组内描述`,sub:t||n,tag:``,note:e.note||``,docId:i,removable:!1,taggable:!1})}return r.filter(e=>e.docId)}var ie={main:`● `,scoped:`◇ `,extra:`○ `,link:`○ `};function Y({kind:e,owner:t,model:o,onClose:s,onChanged:l}){let u=a(),{dialog:f,node:p}=n(),m=d()||{},h=o||m.model,g=G({kind:e,owner:t,model:h}),_=g.ownerKey,v=t&&t.name,[y,b]=(0,P.useState)([]),[x,S]=(0,P.useState)(!0),[C,w]=(0,P.useState)(``),T=(0,P.useCallback)(async()=>{if(!_){b([]),S(!1);return}S(!0);try{let n=e===`repo`?await r(`/api/repos/docs?id=`+encodeURIComponent(_)):await r(`/api/boards/`+encodeURIComponent(String(_)));b(J(n,t,e)),w(``)}catch(e){b([]),w(String(e.message||e))}finally{S(!1)}},[e,_,t]);(0,P.useEffect)(()=>{T()},[T]);let E=t=>{if(!t)return;let n=h;if(!n){u(`工作区不可用,无法打开文档`);return}c(n,{component:`doc`,name:t.label||t.sub||t.docId,config:{docId:t.docId,...e===`repo`?{repoKey:_}:{boardKey:_,boardName:v||``}},location:`center`}),s()},D=e=>e().catch(e=>u(String(e.message||e))),O=t=>D(async()=>{await f({message:`摘除「${t.label}」?${t.kind===`main`?`(只拆绑定,文档不删)`:`(文档不删,仅移出列表)`}`,danger:!0})&&(e===`repo`?await r(`/api/repos/docs`,{method:`DELETE`,body:{id:_,index:t.removeIndex}}):await r(`/api/docs/link`,{method:`POST`,body:{board:_,remove:t.removeIndex}}),u(`已摘除`),T(),l&&l())}),k=e=>D(async()=>{let t=await f({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 g.setLinkTag(e.docId,n,e),u(n?`标签已设为 [${n}]`:`标签已清除`),T(),l&&l()}),A=()=>D(async()=>{if(!_||!String(g.docRef||``).startsWith(`rel:`)){u(`当前简介无法补充(需要自有树路径)`);return}let t=await f({title:`补充介绍文档`,input:!0,tagInput:!0,placeholder:`文档名(如 architecture / api-notes)`,tagPlaceholder:`标签(可选,如 qa)`});if(t===null)return;let n=typeof t==`string`?t:t&&t.value||``,i=typeof t==`object`&&t&&t.tag||``,a=ee(String(n).trim()||`note`).replace(/\.md$/i,``),o=`${U(g.docRef)||(e===`repo`?`repo/${_}`:`board/${v||_}`)}/reference/${a}.md`;await r(`/api/docs/item`,{method:`POST`,body:{rel:o,body:`# ${String(n).trim()||a}\n\n(待补)\n`}});try{e===`repo`?await r(`/api/repos/docs`,{method:`POST`,body:{id:_,rel:o,tag:i||void 0}}):await r(`/api/docs/link`,{method:`POST`,body:{board:_,doc:o,tag:i||void 0}})}catch{}u(`已补充:${o}${i?` [${i}]`:``}`),await T(),l&&l(),E({docId:`rel:`+o,label:String(n).trim()||a,sub:o})}),j=!!String(g.docRef||``).startsWith(`rel:`)&&_,M=y.length,N=`文档列表 · ${v||``}${e===`board`?`(项目组)`:``}`;return(0,I.jsxs)(i,{size:`md`,title:N,onClose:s,children:[(0,I.jsxs)(`div`,{className:`nx-dl`,children:[(0,I.jsxs)(`div`,{className:`nx-dl-head`,children:[(0,I.jsx)(`span`,{className:`nx-dl-count`,children:M?`${M} 篇`:`还没有文档`}),(0,I.jsx)(`span`,{className:`nx-dl-hint`,children:`点标题在主内容区打开`}),(0,I.jsx)(`span`,{className:`grow`}),j&&(0,I.jsx)(`button`,{type:`button`,className:`btn ghost sm nx-dl-add`,title:`补充一篇介绍文档(reference)`,onClick:A,children:`+ 补充`})]}),C?(0,I.jsx)(`div`,{className:`rpd-err`,children:C}):null,!C&&x&&M===0?(0,I.jsx)(`div`,{className:`rpd-empty`,children:`载入中…`}):null,!C&&!x&&M===0?(0,I.jsx)(`div`,{className:`rpd-none`,children:`还没有文档 —— 点「+ 补充」写第一篇`}):null,(0,I.jsx)(`div`,{className:`nx-dl-list`,children:y.map(e=>(0,I.jsxs)(`div`,{className:`nx-dl-row-wrap`,children:[(0,I.jsxs)(`button`,{type:`button`,className:`nx-dl-row`,title:`${e.sub||e.label}\n点击在主内容区打开(可编辑)`,onClick:()=>E(e),children:[(0,I.jsxs)(`span`,{className:`nx-dl-row-title`,children:[ie[e.kind]||`○ `,e.label]}),e.tag?(0,I.jsx)(`span`,{className:`rpd-badge`,children:e.tag}):null]}),(0,I.jsxs)(`span`,{className:`nx-docs-modal-item-acts`,children:[e.taggable&&(0,I.jsx)(`button`,{type:`button`,className:`nx-docs-modal-mini`,title:e.tag?`改标签(当前:${e.tag})`:`加标签`,onClick:()=>k(e),children:`#`}),e.removable&&(0,I.jsx)(`button`,{type:`button`,className:`nx-docs-modal-mini danger`,title:e.removeTip||`摘除「${e.label}」(文档不删)`,onClick:()=>O(e),children:`×`})]})]},e.id))})]}),p]})}function X(e){return e<=1?18:e===2?12:8}function ae({headings:e=[],scrollRoot:t=null,links:n=[],activeDocId:r=``,onOpenDoc:i=null,onAddRef:a=null}){let[o,s]=(0,P.useState)(!1),[c,l]=(0,P.useState)(``),u=(0,P.useMemo)(()=>e||[],[e]),d=(0,P.useMemo)(()=>n||[],[n]);(0,P.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,P.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,I.jsxs)(`aside`,{className:`doc-rail`+(o?` open`:``),"aria-label":`文档目录`,children:[(0,I.jsxs)(`button`,{type:`button`,className:`doc-rail-menu`,title:o?`收起目录`:`展开目录`,"aria-expanded":o,onClick:()=>s(e=>!e),children:[(0,I.jsx)(`span`,{}),(0,I.jsx)(`span`,{}),(0,I.jsx)(`span`,{})]}),(0,I.jsx)(`div`,{className:`doc-rail-ticks`,role:`navigation`,"aria-label":`章节`,children:u.map(e=>(0,I.jsx)(`button`,{type:`button`,className:`doc-rail-tick`+(c===e.id?` on`:``),style:{"--tw":`${X(e.level)}px`},title:e.text,"aria-current":c===e.id?`true`:void 0,onClick:()=>f(e.id)},e.id))}),o&&(0,I.jsxs)(`div`,{className:`doc-rail-panel`,children:[u.length>0&&(0,I.jsxs)(`div`,{className:`doc-rail-sec`,children:[(0,I.jsx)(`div`,{className:`doc-rail-sec-lab`,children:`本章`}),u.map(e=>(0,I.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,I.jsxs)(`div`,{className:`doc-rail-sec`,children:[(0,I.jsx)(`div`,{className:`doc-rail-sec-lab`,children:`介绍文档`}),d.map(e=>(0,I.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,I.jsx)(`button`,{type:`button`,className:`doc-rail-add`,onClick:a,children:`+ 补充文档`})]})]})]})}function Z({kind:e,owner:t,model:n}){let{label:r,docRef:i,links:a,openMain:o}=G({kind:e,owner:t,model:n}),[s,c]=(0,P.useState)(!1);if(!t||!i)return null;let l=a.find(e=>e.main),u=l?l.docId:i,d=u.startsWith(`rel:`)?u.slice(4):u,f=a.filter(e=>!e.main).length;return(0,I.jsxs)(`div`,{className:`nx-intro`,children:[(0,I.jsxs)(`div`,{className:`nx-intro-head`,children:[(0,I.jsx)(`button`,{type:`button`,className:`nx-intro-link-main`,title:`打开${r}(在主内容区阅读 / 编辑)`,onClick:o,children:r}),(0,I.jsx)(`span`,{className:`nx-intro-path mono`,children:d}),(0,I.jsx)(`span`,{className:`nx-intro-spacer`}),(0,I.jsxs)(`button`,{type:`button`,className:`nx-intro-btn`,title:`查看${r}的全部文章(点标题在主内容区打开,可编辑)`,onClick:()=>c(!0),children:[`查看详情`,f>0?` ${f}`:``]})]}),s&&(0,I.jsx)(Y,{kind:e,owner:t,model:n,onClose:()=>c(!1)})]})}export{V as i,Y as n,B as r,Z as t};
@@ -1 +1 @@
1
- import{g as e,h as t,y as n}from"./task-status-BnymQMTw.js";import{w as r}from"./workspace-C_5X2gIr.js";import{a as i,c as a,l as o,o as s,s as c}from"./tool-bar-BrQ71A9i.js";var l=n(e(),1),u=r(),d=t();function f({kind:e,renderers:t={},actions:n={},titles:r={},disabled:f={},labels:p={},className:m=``}){let{layout:h,setLayout:g}=s(e),[_,v]=(0,l.useState)(!1),[y,b]=(0,l.useState)(null),[x,S]=(0,l.useState)(!1),C=(0,l.useRef)(null),w=(0,l.useRef)(null);(0,l.useEffect)(()=>{if(!_)return;let e=e=>{C.current?.contains(e.target)||w.current?.contains(e.target)||v(!1)},t=e=>{e.key===`Escape`&&v(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[_]);let T=h.filter(t=>o(e,t)),E=h.filter(t=>c(e,t)),D=t=>p[t]||a(e,t).label||t,O=(e,t={})=>(0,d.jsx)(`button`,{type:`button`,className:t.primary?`btn small primary`:`btn small ghost`,title:r[e]||D(e),disabled:!!f[e],onClick:()=>n[e]&&n[e](),children:D(e)},e),k=n=>n===`more`?(0,d.jsxs)(`button`,{ref:C,type:`button`,className:`btn small ghost`+(_?` is-open`:``),title:r.more||`更多操作`,"aria-haspopup":`menu`,"aria-expanded":_,onClick:e=>{let t=e.currentTarget.getBoundingClientRect();b({top:t.bottom+6,right:Math.max(8,window.innerWidth-t.right)}),v(e=>!e)},children:[D(`more`),` ▾`]},`more`):t[n]?(0,d.jsx)(`span`,{className:`ta-slot`,children:t[n]({open:_})},n):O(n,{primary:a(e,n).section===`primary`});return(0,d.jsxs)(`div`,{className:`ta-bar`+(m?` ${m}`:``),children:[T.map(e=>k(e.id)),_&&y&&(0,u.createPortal)((0,d.jsxs)(`div`,{ref:w,className:`ta-more-menu`,role:`menu`,style:{top:y.top,right:y.right},children:[E.length===0&&(0,d.jsx)(`div`,{className:`ta-more-empty`,children:`没有收纳的工具——可在编排里把按钮收入更多`}),E.map(e=>(0,d.jsx)(`button`,{type:`button`,role:`menuitem`,className:`ta-more-it`,disabled:!!f[e.id],title:r[e.id]||D(e.id),onClick:()=>{v(!1),n[e.id]&&n[e.id]()},children:D(e.id)},e.id)),(0,d.jsx)(`div`,{className:`ta-more-sep`}),(0,d.jsx)(`button`,{type:`button`,role:`menuitem`,className:`ta-more-it ta-more-cfg`,onClick:()=>{v(!1),S(!0)},children:`自定义工具栏…`})]}),document.body),x&&(0,u.createPortal)((0,d.jsx)(`div`,{className:`ta-panel-mask`,onClick:()=>S(!1),children:(0,d.jsx)(`div`,{className:`ta-panel-wrap`,onClick:e=>e.stopPropagation(),children:(0,d.jsx)(i,{kind:e,layout:h,setLayout:g,onClose:()=>S(!1)})})}),document.body)]})}export{f as t};
1
+ import{g as e,h as t,y as n}from"./task-status-BnymQMTw.js";import{w as r}from"./workspace-C_5X2gIr.js";import{a as i,c as a,l as o,o as s,s as c}from"./tool-bar-DGCwnUcn.js";var l=n(e(),1),u=r(),d=t();function f({kind:e,renderers:t={},actions:n={},titles:r={},disabled:f={},labels:p={},className:m=``}){let{layout:h,setLayout:g}=s(e),[_,v]=(0,l.useState)(!1),[y,b]=(0,l.useState)(null),[x,S]=(0,l.useState)(!1),C=(0,l.useRef)(null),w=(0,l.useRef)(null);(0,l.useEffect)(()=>{if(!_)return;let e=e=>{C.current?.contains(e.target)||w.current?.contains(e.target)||v(!1)},t=e=>{e.key===`Escape`&&v(!1)};return document.addEventListener(`mousedown`,e),document.addEventListener(`keydown`,t),()=>{document.removeEventListener(`mousedown`,e),document.removeEventListener(`keydown`,t)}},[_]);let T=h.filter(t=>o(e,t)),E=h.filter(t=>c(e,t)),D=t=>p[t]||a(e,t).label||t,O=(e,t={})=>(0,d.jsx)(`button`,{type:`button`,className:t.primary?`btn small primary`:`btn small ghost`,title:r[e]||D(e),disabled:!!f[e],onClick:()=>n[e]&&n[e](),children:D(e)},e),k=n=>n===`more`?(0,d.jsxs)(`button`,{ref:C,type:`button`,className:`btn small ghost`+(_?` is-open`:``),title:r.more||`更多操作`,"aria-haspopup":`menu`,"aria-expanded":_,onClick:e=>{let t=e.currentTarget.getBoundingClientRect();b({top:t.bottom+6,right:Math.max(8,window.innerWidth-t.right)}),v(e=>!e)},children:[D(`more`),` ▾`]},`more`):t[n]?(0,d.jsx)(`span`,{className:`ta-slot`,children:t[n]({open:_})},n):O(n,{primary:a(e,n).section===`primary`});return(0,d.jsxs)(`div`,{className:`ta-bar`+(m?` ${m}`:``),children:[T.map(e=>k(e.id)),_&&y&&(0,u.createPortal)((0,d.jsxs)(`div`,{ref:w,className:`ta-more-menu`,role:`menu`,style:{top:y.top,right:y.right},children:[E.length===0&&(0,d.jsx)(`div`,{className:`ta-more-empty`,children:`没有收纳的工具——可在编排里把按钮收入更多`}),E.map(e=>(0,d.jsx)(`button`,{type:`button`,role:`menuitem`,className:`ta-more-it`,disabled:!!f[e.id],title:r[e.id]||D(e.id),onClick:()=>{v(!1),n[e.id]&&n[e.id]()},children:D(e.id)},e.id)),(0,d.jsx)(`div`,{className:`ta-more-sep`}),(0,d.jsx)(`button`,{type:`button`,role:`menuitem`,className:`ta-more-it ta-more-cfg`,onClick:()=>{v(!1),S(!0)},children:`自定义工具栏…`})]}),document.body),x&&(0,u.createPortal)((0,d.jsx)(`div`,{className:`ta-panel-mask`,onClick:()=>S(!1),children:(0,d.jsx)(`div`,{className:`ta-panel-wrap`,onClick:e=>e.stopPropagation(),children:(0,d.jsx)(i,{kind:e,layout:h,setLayout:g,onClose:()=>S(!1)})})}),document.body)]})}export{f as t};
@@ -1,3 +1,3 @@
1
- import{c as e,f as t,g as n,h as r,l as i,m as a,o,p as s,y as c}from"./task-status-BnymQMTw.js";import{a as l,i as u,l as d,n as f,t as p}from"./upload-BIMbGcCB.js";import{S as m,x as h}from"./index-BjHbC1Pr.js";import{t as g}from"./route-crumb-2JmLQxqZ.js";var _=c(n(),1),v=r(),y=e=>`/api/file/content/${encodeURIComponent(e)}`;function b({text:e,compact:t=!1,className:n=``}){let r=d(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 o=s(),[c,d]=(0,_.useState)(e.text||``),[m,h]=(0,_.useState)(e.note||``),[g,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)(c),O=e=>{D.current=e,d(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 l(t,{group:n,onProgress:(e,t)=>S({done:e,total:t})});k(u(e));let r=e.filter(e=>e.isImage).length;o(e.length===1?`已插入 ${e[0].name}`:`已插入 ${e.length} 个附件${r?`(图片 ${r} 个)`:``}`)}catch(e){o(String(e&&e.message||e))}finally{S(null)}}},j=e=>{let t=p(e);t.length&&(e.preventDefault(),A(t))},M=(0,_.useRef)(null);M.current=e=>A(f(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(g)return;if(!String(D.current).trim()){o(`正文不能为空`);return}let i={group:n,ref:e.text,pick:t,matchTopic:e.topic,text:D.current};m!==(e.note||``)&&(i.note=m),y(!0),a(`/api/todo/item`,{method:`PATCH`,body:i}).then(()=>{o(`已保存`),r()}).catch(e=>o(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(c).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:c,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:[c.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:c})})]}),(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:m,spellCheck:`false`,placeholder:`可选:完成结果、上下文补充`,onChange:e=>h(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:g,children:`取消`}),(0,v.jsx)(`button`,{className:`btn`,onClick:N,disabled:g||!!x,children:g?`保存中…`:`保存`})]})]})]})}function S({onClose:e}){let{boot:n,refreshBoot:r}=m(),c=s(),l=t(),{dialog:u,node:d}=i(),[f,p]=(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 a(`/api/groups`);p(e.groups||[]),y(``)}catch(e){y(e.message||String(e))}},[]);(0,_.useEffect)(()=>{w()},[w]);let T=n?.groupId??0,E=e=>l(async()=>{let t=await a(`/api/group`,{method:`POST`,body:{locator:e}});c(t.id===0?`已切回默认组`:`已切换到 ${t.name}`),await r(),await w()}),D=()=>l(async()=>{let e=b.name.trim();if(!e){c(`请填名称`);return}let t=await a(`/api/groups`,{method:`POST`,body:{name:e,description:b.description.trim()}});x({name:``,description:``}),c(`已新建工作空间 ${t.name}(id=${t.id})`),await r(),await w()}),O=e=>l(async()=>{let t=await u({title:`重命名「${e.name}」`,input:!0,value:e.name});t!==null&&t.trim()&&(await a(`/api/groups/${e.id}`,{method:`PATCH`,body:{name:t.trim()}}),c(`已更新名称`),await r(),await w())}),k=e=>l(async()=>{await u({message:`解散工作空间「${e.name}」(id=${e.id})?\n\n后端要求组内已无 KV 数据,否则会拒绝。此操作不可撤销。`,danger:!0})&&(await a(`/api/groups/${e.id}`,{method:`DELETE`}),c(`已解散 ${e.name}`),await r(),await w())}),A=e=>l(async()=>{let t=await a(`/api/groups/${e.id}/members`);C({group:t.group,list:t.members||[]})});return n?.loggedIn?(0,v.jsxs)(v.Fragment,{children:[(0,v.jsxs)(o,{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:`切到这里`})})]}),f.map(e=>(0,v.jsxs)(`div`,{className:`row`,children:[(0,v.jsx)(h,{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&&!f.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:()=>l(w),children:`刷新`})]})]}),S?(0,v.jsx)(o,{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)(h,{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,d]}):(0,v.jsx)(o,{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)(h,{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:n,patchUi:r,refreshBoot:c}=m(),d=s(),f=t(),{dialog:y,node:b}=i(),[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),[R,z]=(0,_.useState)(!1),[B,ee]=(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=()=>f(async()=>{if(!K.email.trim()){d(`请填邮箱`);return}if(!K.password){d(`请填密码`);return}q(e=>({...e,busy:!0}));try{let e=await a(`/api/auth/login`,{method:`POST`,body:{email:K.email.trim(),password:K.password}});q(e=>({...e,password:``})),d(`已登录: ${e.email}`),await c()}finally{q(e=>({...e,busy:!1}))}}),ne=()=>f(async()=>{await a(`/api/auth/logout`,{method:`POST`}),d(`已登出`),await c()}),Y=(0,_.useCallback)(async()=>{if(e?.loggedIn)try{k(await a(`/api/todo`)),j(``)}catch(e){j(String(e.message||e))}},[e?.loggedIn]);(0,_.useEffect)(()=>{Y()},[Y,G]),(0,_.useEffect)(()=>{a(`/api/setting`).then(W).catch(()=>{})},[]);let X=!!U?.autoSyncAttachments,re=()=>f(async()=>{let e=!X,t=await a(`/api/setting`,{method:`POST`,body:{autoSyncAttachments:e}});W(t),d(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=n.topic,t=t=>t?e?t.filter(t=>t.topic===e):t:null;return{open:t(O.open),done:t(O.done),freeze:t(O.freeze)}},[O,n.topic]);if(!e?.loggedIn)return(0,v.jsxs)(`div`,{className:`cloud-page`,children:[(0,v.jsx)(g,{}),(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{c as e,f as t,g as n,h as r,l as i,m as a,o,p as s,y as c}from"./task-status-BnymQMTw.js";import{a as l,i as u,l as d,n as f,t as p}from"./upload-BIMbGcCB.js";import{S as m,x as h}from"./index-BrAIkzFc.js";import{t as g}from"./route-crumb-C8JzPIax.js";var _=c(n(),1),v=r(),y=e=>`/api/file/content/${encodeURIComponent(e)}`;function b({text:e,compact:t=!1,className:n=``}){let r=d(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 o=s(),[c,d]=(0,_.useState)(e.text||``),[m,h]=(0,_.useState)(e.note||``),[g,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)(c),O=e=>{D.current=e,d(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 l(t,{group:n,onProgress:(e,t)=>S({done:e,total:t})});k(u(e));let r=e.filter(e=>e.isImage).length;o(e.length===1?`已插入 ${e[0].name}`:`已插入 ${e.length} 个附件${r?`(图片 ${r} 个)`:``}`)}catch(e){o(String(e&&e.message||e))}finally{S(null)}}},j=e=>{let t=p(e);t.length&&(e.preventDefault(),A(t))},M=(0,_.useRef)(null);M.current=e=>A(f(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(g)return;if(!String(D.current).trim()){o(`正文不能为空`);return}let i={group:n,ref:e.text,pick:t,matchTopic:e.topic,text:D.current};m!==(e.note||``)&&(i.note=m),y(!0),a(`/api/todo/item`,{method:`PATCH`,body:i}).then(()=>{o(`已保存`),r()}).catch(e=>o(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(c).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:c,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:[c.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:c})})]}),(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:m,spellCheck:`false`,placeholder:`可选:完成结果、上下文补充`,onChange:e=>h(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:g,children:`取消`}),(0,v.jsx)(`button`,{className:`btn`,onClick:N,disabled:g||!!x,children:g?`保存中…`:`保存`})]})]})]})}function S({onClose:e}){let{boot:n,refreshBoot:r}=m(),c=s(),l=t(),{dialog:u,node:d}=i(),[f,p]=(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 a(`/api/groups`);p(e.groups||[]),y(``)}catch(e){y(e.message||String(e))}},[]);(0,_.useEffect)(()=>{w()},[w]);let T=n?.groupId??0,E=e=>l(async()=>{let t=await a(`/api/group`,{method:`POST`,body:{locator:e}});c(t.id===0?`已切回默认组`:`已切换到 ${t.name}`),await r(),await w()}),D=()=>l(async()=>{let e=b.name.trim();if(!e){c(`请填名称`);return}let t=await a(`/api/groups`,{method:`POST`,body:{name:e,description:b.description.trim()}});x({name:``,description:``}),c(`已新建工作空间 ${t.name}(id=${t.id})`),await r(),await w()}),O=e=>l(async()=>{let t=await u({title:`重命名「${e.name}」`,input:!0,value:e.name});t!==null&&t.trim()&&(await a(`/api/groups/${e.id}`,{method:`PATCH`,body:{name:t.trim()}}),c(`已更新名称`),await r(),await w())}),k=e=>l(async()=>{await u({message:`解散工作空间「${e.name}」(id=${e.id})?\n\n后端要求组内已无 KV 数据,否则会拒绝。此操作不可撤销。`,danger:!0})&&(await a(`/api/groups/${e.id}`,{method:`DELETE`}),c(`已解散 ${e.name}`),await r(),await w())}),A=e=>l(async()=>{let t=await a(`/api/groups/${e.id}/members`);C({group:t.group,list:t.members||[]})});return n?.loggedIn?(0,v.jsxs)(v.Fragment,{children:[(0,v.jsxs)(o,{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:`切到这里`})})]}),f.map(e=>(0,v.jsxs)(`div`,{className:`row`,children:[(0,v.jsx)(h,{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&&!f.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:()=>l(w),children:`刷新`})]})]}),S?(0,v.jsx)(o,{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)(h,{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,d]}):(0,v.jsx)(o,{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)(h,{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:n,patchUi:r,refreshBoot:c}=m(),d=s(),f=t(),{dialog:y,node:b}=i(),[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),[R,z]=(0,_.useState)(!1),[B,ee]=(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=()=>f(async()=>{if(!K.email.trim()){d(`请填邮箱`);return}if(!K.password){d(`请填密码`);return}q(e=>({...e,busy:!0}));try{let e=await a(`/api/auth/login`,{method:`POST`,body:{email:K.email.trim(),password:K.password}});q(e=>({...e,password:``})),d(`已登录: ${e.email}`),await c()}finally{q(e=>({...e,busy:!1}))}}),ne=()=>f(async()=>{await a(`/api/auth/logout`,{method:`POST`}),d(`已登出`),await c()}),Y=(0,_.useCallback)(async()=>{if(e?.loggedIn)try{k(await a(`/api/todo`)),j(``)}catch(e){j(String(e.message||e))}},[e?.loggedIn]);(0,_.useEffect)(()=>{Y()},[Y,G]),(0,_.useEffect)(()=>{a(`/api/setting`).then(W).catch(()=>{})},[]);let X=!!U?.autoSyncAttachments,re=()=>f(async()=>{let e=!X,t=await a(`/api/setting`,{method:`POST`,body:{autoSyncAttachments:e}});W(t),d(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=n.topic,t=t=>t?e?t.filter(t=>t.topic===e):t:null;return{open:t(O.open),done:t(O.done),freeze:t(O.freeze)}},[O,n.topic]);if(!e?.loggedIn)return(0,v.jsxs)(`div`,{className:`cloud-page`,children:[(0,v.jsx)(g,{}),(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 a=Number(i);return!Number.isInteger(a)||!n[a]?(d(`请输入 0..${n.length-1}`),null):{...n[a],pick:a}},oe=(e,t,n)=>f(async()=>{let r=e===`remove`||e===`edit`?await ae(t,n):{bucket:n,task:t,pick:void 0};if(!r)return;let i={group:G,ref:r.task.text,pick:r.pick};if(e===`done`){let e=await y({title:`完成结果`,message:`完成「${t.text.slice(0,40)}」`,input:!0,placeholder:`可选:写一句完成结果`});if(e===null)return;await a(`/api/todo/done`,{method:`POST`,body:{...i,result:e||void 0}}),d(`已完成`)}else if(e===`freeze`)await a(`/api/todo/freeze`,{method:`POST`,body:i}),d(`已冻结`);else if(e===`unfreeze`)await a(`/api/todo/unfreeze`,{method:`POST`,body:i}),d(`已解冻`);else if(e===`remove`){if(!await y({message:`删除「${t.text.slice(0,40)}」?`,danger:!0}))return;await a(`/api/todo/item`,{method:`DELETE`,body:i}),d(`已删除`)}else if(e===`edit`){H({task:r.task,pick:r.pick});return}await Z(),await c()}),se=()=>f(async()=>{let e=await y({title:`归档已完成的旧记录`,message:`把「完成时间早于该日期」的记录移到冷 key(默认 30 天前)。留空用默认值。`,input:!0,placeholder:`YYYY-MM-DD,留空 = 30 天前`});if(e===null)return;let t=await a(`/api/todo/archive`,{method:`POST`,body:{before:e.trim()||void 0,group:G}});d(t.moved?`已归档 ${t.moved} 条 → ${t.coldKey}`:`没有需要归档的记录`),await Z()}),ce=async e=>{let t=p(e);if(t.length){e.preventDefault();try{let e=await l(t,{group:G}),n=u(e);F(e=>({...e,text:[e.text,n].filter(Boolean).join(` `)})),d(e.length===1?`已上传 ${e[0].name} 并附到内容里`:`已上传 ${e.length} 个附件并附到内容里`)}catch(e){d(String(e&&e.message||e))}}},$=()=>f(async()=>{let e=P.topic.trim(),t=P.text.trim();if(!e){d(`请填主题`);return}if(!t){d(`请填内容`);return}let n=await a(`/api/todo`,{method:`POST`,body:{topic:e,text:t,group:G}});F({topic:e,text:``}),d(`已加入待办${n.topicAdded?`(新主题 ${e})`:``}`),await Z()}),le=(e,t)=>B[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:()=>z(!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:n.topic,onChange:e=>r({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)(h,{text:e?.baseUrl,children:e?.baseUrl})}),(0,v.jsx)(`dt`,{children:`本机配置`}),(0,v.jsx)(`dd`,{className:`mono`,children:(0,v.jsx)(h,{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:()=>ee(t=>({...t,[e]:!t[e]})),children:B[e]?`收起`:`还有 ${Q[e].length-T} 条,点击展开`}):null]})]},e))}):null,R?(0,v.jsx)(S,{onClose:()=>z(!1)}):null,V?(0,v.jsx)(o,{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 c()}})}):null,I?(0,v.jsx)(o,{title:I.title,size:`lg`,onClose:()=>L(null),children:I.node}):null,b]})}export{O as default};
@@ -1 +1 @@
1
- import{g as e,h as t,p as n,u as r,y as i}from"./task-status-BnymQMTw.js";import{t as a}from"./workspace-C_5X2gIr.js";import{n as o}from"./app-context-D7HAx67n.js";import{a as s,i as c,n as l,p as u,r as d,t as f}from"./md-history-XRRcXn6B.js";import"./index-BjHbC1Pr.js";import{i as p,o as m,r as ee,t as h}from"./composer-launch-Bf4rXhLs.js";var g=i(e(),1),_=t(),v=96;function y({token:e,mode:t=`comment`,quote:i=``,prevQuote:y=``,taskLabel:b=``,taskTitle:x=``,src:S=null}){let C=o()||{},w=n(),[T,E]=(0,g.useState)(``),[D,O]=(0,g.useState)([]),[k,A]=(0,g.useState)(!1),j=(0,g.useRef)(null),M=t===`feedback`,N=(0,g.useRef)(new Map),P=`compose-`+e,F=()=>{f(N.current,P),ee(C.model,e)},I=(e,t=`op`)=>{l(N.current,P,{title:``,body:T},t),E(e)},L=()=>{let e=c(N.current,P,{title:``,body:T});e&&E(e.body)},R=()=>{let e=d(N.current,P,{title:``,body:T});e&&E(e.body)},z=async()=>{let t=String(T||``).trim();if(!t&&!D.length){w(M?`写一下要改的地方`:`写一下要提的问题`);return}let n=h(e);if(!n||!n.onSubmit){w(`提交入口已失效(来源页面已关闭)`);return}A(!0);try{await n.onSubmit({text:t,attachments:D,inserts:``}),F()}catch(e){w(String(e.message||e))}finally{A(!1)}},B=async e=>{if(!e||!e.length)return;let{items:t,imageInserts:n,fileInserts:r}=await p(e),i=[...n,...r].join(``);i&&E(e=>u(e,i,{}).body),t.length&&O(e=>[...e,...t])},V=(0,g.useRef)(null),[H,U]=(0,g.useState)(()=>localStorage.getItem(`nxkv.cmpDockOpen`)!==`0`),[W,G]=(0,g.useState)(()=>{let e=Number(localStorage.getItem(`nxkv.cmpDockH`));return Number.isFinite(e)&&e>=v?e:176}),K=(0,g.useRef)(W);K.current=W;let[q,J]=(0,g.useState)(!1),Y=(0,g.useRef)(176);(0,g.useEffect)(()=>{localStorage.setItem(`nxkv.cmpDockOpen`,H?`1`:`0`)},[H]);let X=()=>{if(q){G(Y.current),J(!1);return}Y.current=W;let e=document.querySelector(`.cmp`)?.clientHeight||window.innerHeight;G(Math.max(v,Math.round(e*.62))),J(!0)},Z=e=>{if(!H)return;e.preventDefault(),J(!1);let t=e.clientY,n=K.current,r=e=>Math.max(v,Math.min(Math.round(e),Math.round((document.querySelector(`.cmp`)?.clientHeight||window.innerHeight)*.62))),i=e=>{K.current=r(n-(e.clientY-t)),G(K.current)},a=()=>{window.removeEventListener(`mousemove`,i),window.removeEventListener(`mouseup`,a),document.body.style.userSelect=``,document.body.style.cursor=``,localStorage.setItem(`nxkv.cmpDockH`,String(K.current))};document.body.style.userSelect=`none`,document.body.style.cursor=`row-resize`,window.addEventListener(`mousemove`,i),window.addEventListener(`mouseup`,a)},Q=()=>{let e=C.model;e&&S&&S.task&&a(e,{component:`page`,name:S.name||`原文`,config:{dirKey:S.dirKey,task:String(S.task)}})},$=!!(S&&S.task);return(0,_.jsxs)(`div`,{className:`cmp`,children:[(0,_.jsxs)(`div`,{className:`cmp-head`,children:[(0,_.jsx)(`span`,{className:`cmp-tag`+(M?` is-fb`:``),children:M?`反馈`:`评论`}),(0,_.jsx)(`div`,{className:`cmp-ctx`,children:M?(0,_.jsxs)(`span`,{className:`cmp-ctx-line`,title:x||``,children:[`反馈 `,b||``,` 的任务`,x?` · ${x}`:``]}):(0,_.jsx)(`span`,{className:`cmp-ctx-line`,children:`对本任务提出问题`})}),(0,_.jsx)(`span`,{className:`grow`}),(0,_.jsx)(`button`,{type:`button`,className:`btn ghost sm`,onClick:F,disabled:k,children:`关闭`}),(0,_.jsx)(`button`,{type:`button`,className:`btn sm`,onClick:z,disabled:k,children:M?`提交反馈`:`提交评论`})]}),M?(0,_.jsxs)(`div`,{className:`cmp-quote-wrap`,children:[(0,_.jsxs)(`div`,{className:`cmp-quote-cap`,children:[`之前的引用`,$&&(0,_.jsx)(`button`,{type:`button`,className:`cmp-quote-cmp`,onClick:Q,title:`在右侧并排显示原文,方便对照`,children:`对照原文 ↗`})]}),$?(0,_.jsx)(`button`,{type:`button`,className:`cmp-quote`,onClick:Q,title:`点击在右侧并排显示原文,方便对照`,children:y||`(这条任务还没有可引用的上轮总结)`}):(0,_.jsx)(`div`,{className:`cmp-quote`,children:y||`(这条任务还没有可引用的上轮总结)`})]}):i?(0,_.jsxs)(`div`,{className:`cmp-quote-wrap`,children:[(0,_.jsxs)(`div`,{className:`cmp-quote-cap`,children:[`引用`,$&&(0,_.jsx)(`button`,{type:`button`,className:`cmp-quote-cmp`,onClick:Q,title:`在右侧并排显示原文,方便对照`,children:`对照原文 ↗`})]}),$?(0,_.jsx)(`button`,{type:`button`,className:`cmp-quote`,onClick:Q,title:`点击在右侧并排显示原文,方便对照`,children:i}):(0,_.jsx)(`div`,{className:`cmp-quote`,children:i})]}):null,(0,_.jsx)(`div`,{className:`cmp-body`,children:(0,_.jsx)(s,{mode:`split`,title:``,body:T,onTitle:()=>{},onBody:I,attachments:D,docKey:`compose-`+e,editorApiRef:j,onFiles:B,onSave:z,onUndo:L,onRedo:R,hideTitle:!0})}),H&&(0,_.jsxs)(`div`,{className:`mdw-dock`,style:{height:`${W}px`},children:[(0,_.jsx)(`div`,{className:`mdw-dock-drag`,role:`separator`,"aria-orientation":`horizontal`,title:`上下拖动调整信息面板高度(双击最大化 / 还原)`,onMouseDown:Z,onDoubleClick:X}),(0,_.jsxs)(`div`,{className:`mdw-dock-head`,children:[(0,_.jsx)(`div`,{className:`mdw-dock-tabs`,role:`tablist`,"aria-label":`信息面板`,children:(0,_.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":`true`,className:`mdw-dock-tab is-on`,onClick:()=>U(!0),children:[`附件`,D.length?(0,_.jsx)(`span`,{className:`mdw-dock-tab-num`,children:D.length}):null]})}),(0,_.jsxs)(`div`,{className:`mdw-dock-acts`,children:[(0,_.jsx)(`button`,{type:`button`,className:`mdw-dock-act`,title:`添加附件`,"aria-label":`添加附件`,onClick:()=>V.current?.click(),children:(0,_.jsx)(r,{name:`plus`})}),(0,_.jsx)(`button`,{type:`button`,className:`mdw-dock-act`,onClick:X,title:q?`还原面板高度`:`最大化面板高度`,"aria-label":q?`还原面板高度`:`最大化面板高度`,children:(0,_.jsx)(r,{name:q?`collapse`:`expand`})}),(0,_.jsx)(`button`,{type:`button`,className:`mdw-dock-act`,onClick:()=>U(!1),title:`关闭面板(底部状态栏仍保留入口)`,"aria-label":`关闭面板`,children:(0,_.jsx)(r,{name:`x`})})]})]}),(0,_.jsx)(`div`,{className:`mdw-dock-body`,children:D.length?(0,_.jsx)(m,{attachments:D,onRemove:e=>O(t=>t.filter(t=>t.id!==e))}):(0,_.jsx)(`div`,{className:`mdw-dock-empty`,children:`还没有附件——粘贴 / 拖图片进正文即附件,或点右上「+」添加文件。`})})]}),(0,_.jsxs)(`div`,{className:`mdw-sbar`,children:[(0,_.jsxs)(`button`,{type:`button`,className:`mdw-sbar-item${H?` is-on`:``}`,onClick:()=>U(e=>!e),title:`附件(点击展开/收起信息面板)`,children:[(0,_.jsx)(r,{name:`list`}),(0,_.jsx)(`span`,{className:`mdw-sbar-lab`,children:`附件`}),D.length?(0,_.jsx)(`span`,{className:`mdw-sbar-num`,children:D.length}):null]}),(0,_.jsx)(`span`,{className:`mdw-sbar-grow`}),(0,_.jsx)(`button`,{type:`button`,className:`mdw-sbar-chev${H?` is-open`:``}`,onClick:()=>U(e=>!e),title:H?`收起信息面板`:`展开信息面板`,"aria-expanded":H,"aria-label":H?`收起信息面板`:`展开信息面板`,children:(0,_.jsx)(r,{name:`chevron`})})]}),(0,_.jsx)(`input`,{ref:V,type:`file`,multiple:!0,hidden:!0,onChange:e=>{let t=Array.from(e.target.files||[]);e.target.value=``,t.length&&B(t)}})]})}export{y as default};
1
+ import{g as e,h as t,p as n,u as r,y as i}from"./task-status-BnymQMTw.js";import{t as a}from"./workspace-C_5X2gIr.js";import{n as o}from"./app-context-D7HAx67n.js";import{a as s,i as c,n as l,p as u,r as d,t as f}from"./md-history-DB5forf2.js";import"./index-BrAIkzFc.js";import{i as p,o as m,r as ee,t as h}from"./composer-launch-Bf4rXhLs.js";var g=i(e(),1),_=t(),v=96;function y({token:e,mode:t=`comment`,quote:i=``,prevQuote:y=``,taskLabel:b=``,taskTitle:x=``,src:S=null}){let C=o()||{},w=n(),[T,E]=(0,g.useState)(``),[D,O]=(0,g.useState)([]),[k,A]=(0,g.useState)(!1),j=(0,g.useRef)(null),M=t===`feedback`,N=(0,g.useRef)(new Map),P=`compose-`+e,F=()=>{f(N.current,P),ee(C.model,e)},I=(e,t=`op`)=>{l(N.current,P,{title:``,body:T},t),E(e)},L=()=>{let e=c(N.current,P,{title:``,body:T});e&&E(e.body)},R=()=>{let e=d(N.current,P,{title:``,body:T});e&&E(e.body)},z=async()=>{let t=String(T||``).trim();if(!t&&!D.length){w(M?`写一下要改的地方`:`写一下要提的问题`);return}let n=h(e);if(!n||!n.onSubmit){w(`提交入口已失效(来源页面已关闭)`);return}A(!0);try{await n.onSubmit({text:t,attachments:D,inserts:``}),F()}catch(e){w(String(e.message||e))}finally{A(!1)}},B=async e=>{if(!e||!e.length)return;let{items:t,imageInserts:n,fileInserts:r}=await p(e),i=[...n,...r].join(``);i&&E(e=>u(e,i,{}).body),t.length&&O(e=>[...e,...t])},V=(0,g.useRef)(null),[H,U]=(0,g.useState)(()=>localStorage.getItem(`nxkv.cmpDockOpen`)!==`0`),[W,G]=(0,g.useState)(()=>{let e=Number(localStorage.getItem(`nxkv.cmpDockH`));return Number.isFinite(e)&&e>=v?e:176}),K=(0,g.useRef)(W);K.current=W;let[q,J]=(0,g.useState)(!1),Y=(0,g.useRef)(176);(0,g.useEffect)(()=>{localStorage.setItem(`nxkv.cmpDockOpen`,H?`1`:`0`)},[H]);let X=()=>{if(q){G(Y.current),J(!1);return}Y.current=W;let e=document.querySelector(`.cmp`)?.clientHeight||window.innerHeight;G(Math.max(v,Math.round(e*.62))),J(!0)},Z=e=>{if(!H)return;e.preventDefault(),J(!1);let t=e.clientY,n=K.current,r=e=>Math.max(v,Math.min(Math.round(e),Math.round((document.querySelector(`.cmp`)?.clientHeight||window.innerHeight)*.62))),i=e=>{K.current=r(n-(e.clientY-t)),G(K.current)},a=()=>{window.removeEventListener(`mousemove`,i),window.removeEventListener(`mouseup`,a),document.body.style.userSelect=``,document.body.style.cursor=``,localStorage.setItem(`nxkv.cmpDockH`,String(K.current))};document.body.style.userSelect=`none`,document.body.style.cursor=`row-resize`,window.addEventListener(`mousemove`,i),window.addEventListener(`mouseup`,a)},Q=()=>{let e=C.model;e&&S&&S.task&&a(e,{component:`page`,name:S.name||`原文`,config:{dirKey:S.dirKey,task:String(S.task)}})},$=!!(S&&S.task);return(0,_.jsxs)(`div`,{className:`cmp`,children:[(0,_.jsxs)(`div`,{className:`cmp-head`,children:[(0,_.jsx)(`span`,{className:`cmp-tag`+(M?` is-fb`:``),children:M?`反馈`:`评论`}),(0,_.jsx)(`div`,{className:`cmp-ctx`,children:M?(0,_.jsxs)(`span`,{className:`cmp-ctx-line`,title:x||``,children:[`反馈 `,b||``,` 的任务`,x?` · ${x}`:``]}):(0,_.jsx)(`span`,{className:`cmp-ctx-line`,children:`对本任务提出问题`})}),(0,_.jsx)(`span`,{className:`grow`}),(0,_.jsx)(`button`,{type:`button`,className:`btn ghost sm`,onClick:F,disabled:k,children:`关闭`}),(0,_.jsx)(`button`,{type:`button`,className:`btn sm`,onClick:z,disabled:k,children:M?`提交反馈`:`提交评论`})]}),M?(0,_.jsxs)(`div`,{className:`cmp-quote-wrap`,children:[(0,_.jsxs)(`div`,{className:`cmp-quote-cap`,children:[`之前的引用`,$&&(0,_.jsx)(`button`,{type:`button`,className:`cmp-quote-cmp`,onClick:Q,title:`在右侧并排显示原文,方便对照`,children:`对照原文 ↗`})]}),$?(0,_.jsx)(`button`,{type:`button`,className:`cmp-quote`,onClick:Q,title:`点击在右侧并排显示原文,方便对照`,children:y||`(这条任务还没有可引用的上轮总结)`}):(0,_.jsx)(`div`,{className:`cmp-quote`,children:y||`(这条任务还没有可引用的上轮总结)`})]}):i?(0,_.jsxs)(`div`,{className:`cmp-quote-wrap`,children:[(0,_.jsxs)(`div`,{className:`cmp-quote-cap`,children:[`引用`,$&&(0,_.jsx)(`button`,{type:`button`,className:`cmp-quote-cmp`,onClick:Q,title:`在右侧并排显示原文,方便对照`,children:`对照原文 ↗`})]}),$?(0,_.jsx)(`button`,{type:`button`,className:`cmp-quote`,onClick:Q,title:`点击在右侧并排显示原文,方便对照`,children:i}):(0,_.jsx)(`div`,{className:`cmp-quote`,children:i})]}):null,(0,_.jsx)(`div`,{className:`cmp-body`,children:(0,_.jsx)(s,{mode:`split`,title:``,body:T,onTitle:()=>{},onBody:I,attachments:D,docKey:`compose-`+e,editorApiRef:j,onFiles:B,onSave:z,onUndo:L,onRedo:R,hideTitle:!0})}),H&&(0,_.jsxs)(`div`,{className:`mdw-dock`,style:{height:`${W}px`},children:[(0,_.jsx)(`div`,{className:`mdw-dock-drag`,role:`separator`,"aria-orientation":`horizontal`,title:`上下拖动调整信息面板高度(双击最大化 / 还原)`,onMouseDown:Z,onDoubleClick:X}),(0,_.jsxs)(`div`,{className:`mdw-dock-head`,children:[(0,_.jsx)(`div`,{className:`mdw-dock-tabs`,role:`tablist`,"aria-label":`信息面板`,children:(0,_.jsxs)(`button`,{type:`button`,role:`tab`,"aria-selected":`true`,className:`mdw-dock-tab is-on`,onClick:()=>U(!0),children:[`附件`,D.length?(0,_.jsx)(`span`,{className:`mdw-dock-tab-num`,children:D.length}):null]})}),(0,_.jsxs)(`div`,{className:`mdw-dock-acts`,children:[(0,_.jsx)(`button`,{type:`button`,className:`mdw-dock-act`,title:`添加附件`,"aria-label":`添加附件`,onClick:()=>V.current?.click(),children:(0,_.jsx)(r,{name:`plus`})}),(0,_.jsx)(`button`,{type:`button`,className:`mdw-dock-act`,onClick:X,title:q?`还原面板高度`:`最大化面板高度`,"aria-label":q?`还原面板高度`:`最大化面板高度`,children:(0,_.jsx)(r,{name:q?`collapse`:`expand`})}),(0,_.jsx)(`button`,{type:`button`,className:`mdw-dock-act`,onClick:()=>U(!1),title:`关闭面板(底部状态栏仍保留入口)`,"aria-label":`关闭面板`,children:(0,_.jsx)(r,{name:`x`})})]})]}),(0,_.jsx)(`div`,{className:`mdw-dock-body`,children:D.length?(0,_.jsx)(m,{attachments:D,onRemove:e=>O(t=>t.filter(t=>t.id!==e))}):(0,_.jsx)(`div`,{className:`mdw-dock-empty`,children:`还没有附件——粘贴 / 拖图片进正文即附件,或点右上「+」添加文件。`})})]}),(0,_.jsxs)(`div`,{className:`mdw-sbar`,children:[(0,_.jsxs)(`button`,{type:`button`,className:`mdw-sbar-item${H?` is-on`:``}`,onClick:()=>U(e=>!e),title:`附件(点击展开/收起信息面板)`,children:[(0,_.jsx)(r,{name:`list`}),(0,_.jsx)(`span`,{className:`mdw-sbar-lab`,children:`附件`}),D.length?(0,_.jsx)(`span`,{className:`mdw-sbar-num`,children:D.length}):null]}),(0,_.jsx)(`span`,{className:`mdw-sbar-grow`}),(0,_.jsx)(`button`,{type:`button`,className:`mdw-sbar-chev${H?` is-open`:``}`,onClick:()=>U(e=>!e),title:H?`收起信息面板`:`展开信息面板`,"aria-expanded":H,"aria-label":H?`收起信息面板`:`展开信息面板`,children:(0,_.jsx)(r,{name:`chevron`})})]}),(0,_.jsx)(`input`,{ref:V,type:`file`,multiple:!0,hidden:!0,onChange:e=>{let t=Array.from(e.target.files||[]);e.target.value=``,t.length&&B(t)}})]})}export{y as default};