nx-kv 0.48.2 → 0.50.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (309) hide show
  1. package/CHANGELOG.md +85 -0
  2. package/README.md +103 -216
  3. package/assets/groups.json +1 -1
  4. package/assets/kv-get/SKILL.md +1 -1
  5. package/assets/kv-get/references/localget.md +2 -2
  6. package/assets/kv-get/references/timegoal-workflow.md +3 -3
  7. package/assets/kv-get/references/timegoal.md +1 -1
  8. package/assets/kv-get/references/wait-workflow.md +2 -3
  9. package/assets/kv-get/references/waitloop.md +3 -3
  10. package/assets/kv-repo/SKILL.md +1 -1
  11. package/assets/kv-submit/SKILL.md +3 -3
  12. package/assets/nx-kv/SKILL.md +111 -76
  13. package/assets/nx-kv/references/agent-workflow.md +58 -47
  14. package/assets/nx-kv/references/localtask-commands.md +179 -0
  15. package/package.json +3 -4
  16. package/src/core/attachmentdb/bodies.ts +193 -0
  17. package/src/core/attachmentdb/docs.ts +158 -33
  18. package/src/core/attachmentdb/ids.ts +27 -1
  19. package/src/core/attachmentdb/mdfile.ts +249 -0
  20. package/src/core/attachmentdb/query.ts +14 -1
  21. package/src/core/attachmentdb/resources.ts +28 -2
  22. package/src/core/attachmentdb.ts +27 -0
  23. package/src/core/config.ts +13 -133
  24. package/src/core/db/bootstrap.ts +5 -5
  25. package/src/core/db/import-json/refs.ts +27 -13
  26. package/src/core/db/migrations/index.ts +9 -0
  27. package/src/core/db/migrations/v2-data.ts +4 -4
  28. package/src/core/db/migrations/v5.sql +100 -0
  29. package/src/core/db/migrations/v6-data.ts +261 -0
  30. package/src/core/db/migrations/v6.sql +67 -0
  31. package/src/core/db/migrations/v7.sql +8 -0
  32. package/src/core/db/seed-templates.ts +3 -1
  33. package/src/core/db/version.ts +12 -1
  34. package/src/core/filekind.ts +95 -0
  35. package/src/core/instruction-template.ts +6 -4
  36. package/src/core/localatt.ts +3 -6
  37. package/src/core/paths.ts +11 -1
  38. package/src/index.ts +0 -2
  39. package/src/modules/docs/actions/_manifest.generated.ts +18 -0
  40. package/src/modules/docs/actions/doc-attach.ts +2 -1
  41. package/src/modules/docs/actions/doc-link-file.ts +28 -0
  42. package/src/modules/docs/actions/doc-mdfile.ts +28 -0
  43. package/src/modules/docs/actions/doc-mdfiles.ts +29 -0
  44. package/src/modules/docs/actions/doc-ref.ts +36 -0
  45. package/src/modules/docs/actions/doc-unbind.ts +34 -0
  46. package/src/modules/docs/actions/doc-update.ts +3 -2
  47. package/src/modules/docs/actions/docs-bind.ts +1 -1
  48. package/src/modules/docs/actions/docs-bindings.ts +108 -0
  49. package/src/modules/docs/actions/docs-notebind.ts +1 -1
  50. package/src/modules/docs/attach.ts +16 -3
  51. package/src/modules/docs/bound-docs.ts +74 -0
  52. package/src/modules/docs/docref.ts +18 -3
  53. package/src/modules/docs/knowledge-md.ts +51 -0
  54. package/src/modules/docs/knowledge.ts +112 -112
  55. package/src/modules/docs/links.ts +7 -1
  56. package/src/modules/docs/mdfile.ts +24 -0
  57. package/src/modules/docs/paths.ts +6 -9
  58. package/src/modules/docs/ref-sync.ts +166 -0
  59. package/src/modules/docs/refs.ts +16 -5
  60. package/src/modules/docs/render.ts +33 -15
  61. package/src/modules/docs/seed.ts +1 -1
  62. package/src/modules/docs/service.ts +300 -30
  63. package/src/modules/docs/store.ts +147 -74
  64. package/src/modules/file/actions/_manifest.generated.ts +0 -9
  65. package/src/modules/file/actions/file-content.ts +3 -4
  66. package/src/modules/file/actions/file-get.ts +2 -3
  67. package/src/modules/file/actions/file-upload.ts +1 -4
  68. package/src/modules/file/service.ts +52 -253
  69. package/src/modules/localtask/action-render.ts +5 -5
  70. package/src/modules/localtask/actions/_manifest.generated.ts +0 -6
  71. package/src/modules/localtask/actions/localtask-attach.ts +4 -2
  72. package/src/modules/localtask/actions/localtask-cancelMany.ts +1 -1
  73. package/src/modules/localtask/actions/localtask-closeMany.ts +4 -3
  74. package/src/modules/localtask/actions/localtask-get.ts +1 -1
  75. package/src/modules/localtask/repo/tasks.ts +12 -6
  76. package/src/modules/localtask/service.ts +0 -2
  77. package/src/modules/localtask/task-ops.ts +4 -4
  78. package/src/modules/localtask/task-remove.ts +33 -16
  79. package/src/modules/localtask/task-templates.ts +2 -3
  80. package/src/modules/localtask/task-view.ts +2 -2
  81. package/src/modules/repos/actions/_manifest.generated.ts +0 -3
  82. package/src/modules/repos/actions/repo-update.ts +2 -4
  83. package/src/modules/repos/cli/render.ts +0 -15
  84. package/src/modules/repos/service/bind-topics.ts +8 -18
  85. package/src/modules/repos/service.ts +1 -1
  86. package/src/modules/repos/transfer/export.ts +4 -1
  87. package/src/modules/setting/actions/setting-set.ts +0 -2
  88. package/src/modules/setting/service.ts +6 -25
  89. package/src/modules/system/actions/bootstrap.ts +2 -31
  90. package/src/modules/system/actions/health.ts +4 -31
  91. package/src/modules/system/routes.ts +1 -1
  92. package/src/modules/tasktool/attach-resource.ts +68 -42
  93. package/src/modules/tasktool/attach-template.ts +73 -54
  94. package/src/modules/tasktool/attach.ts +98 -71
  95. package/src/modules/tasktool/delivery-template.ts +14 -4
  96. package/src/modules/tasktool/doc-inline.ts +63 -29
  97. package/src/modules/tasktool/get.ts +1 -1
  98. package/src/modules/tasktool/groupctx.ts +19 -11
  99. package/src/modules/tasktool/plugins/waitgoal-config.ts +24 -55
  100. package/src/modules/tasktool/plugins/waitgoal.ts +0 -2
  101. package/src/modules/tasktool/preview.ts +2 -3
  102. package/src/modules/tasktool/wait.ts +6 -9
  103. package/src/runtime/cli.ts +3 -15
  104. package/src/runtime/container.ts +1 -5
  105. package/src/runtime/help.ts +1 -4
  106. package/src/runtime/registry.ts +0 -6
  107. package/src/shared/prompt-blocks.ts +37 -33
  108. package/src/shared/task-status.ts +3 -3
  109. package/src/web/frontend/App.tsx +3 -3
  110. package/src/web/frontend/api/cli-tree.json +115 -608
  111. package/src/web/frontend/api/client.generated.ts +88 -401
  112. package/src/web/frontend/components/Introduction/index.tsx +26 -14
  113. package/src/web/frontend/components/Introduction/rail.tsx +28 -3
  114. package/src/web/frontend/components/Introduction/style.css +3 -33
  115. package/src/web/frontend/components/Introduction/use-intro.ts +0 -80
  116. package/src/web/frontend/components/{cloud → attach}/upload.ts +7 -20
  117. package/src/web/frontend/components/bindings/bind-tags.tsx +183 -0
  118. package/src/web/frontend/components/doc/doc-head.tsx +29 -26
  119. package/src/web/frontend/components/icons.tsx +0 -1
  120. package/src/web/frontend/components/layout/crumbs.ts +0 -2
  121. package/src/web/frontend/components/md/ack-rail.tsx +10 -142
  122. package/src/web/frontend/components/md/attach-area.tsx +64 -9
  123. package/src/web/frontend/components/md/attach-common.ts +8 -3
  124. package/src/web/frontend/components/md/attach-modal.tsx +22 -17
  125. package/src/web/frontend/components/md/attach-picker.tsx +2 -2
  126. package/src/web/frontend/components/md/attachments.ts +2 -3
  127. package/src/web/frontend/components/popup/dismiss.ts +1 -1
  128. package/src/web/frontend/components/repos/get-loop-modal.tsx +20 -207
  129. package/src/web/frontend/components/sidebar/index.tsx +32 -6
  130. package/src/web/frontend/components/sidebar/model.ts +71 -0
  131. package/src/web/frontend/components/sidebar/task-children.tsx +41 -20
  132. package/src/web/frontend/components/status-tag/model.ts +1 -1
  133. package/src/web/frontend/components/task-panel/index.tsx +4 -1
  134. package/src/web/frontend/components/task-panel/task-row.tsx +2 -2
  135. package/src/web/frontend/components/tool-acts/modules.ts +0 -3
  136. package/src/web/frontend/components/use-rail-drag.ts +177 -0
  137. package/src/web/frontend/modules/board/ack-rail-pos.ts +17 -7
  138. package/src/web/frontend/modules/board/board-view.ts +2 -2
  139. package/src/web/frontend/modules/board/task-search.ts +81 -0
  140. package/src/web/frontend/modules/md/attach-mention.ts +6 -1
  141. package/src/web/frontend/modules/md/doc-bus.ts +22 -0
  142. package/src/web/frontend/modules/md/md-render.ts +9 -2
  143. package/src/web/frontend/modules/md/styles/chrome.css +25 -0
  144. package/src/web/frontend/modules/md/styles/docs.css +32 -21
  145. package/src/web/frontend/modules/md/styles/shell.css +1 -10
  146. package/src/web/frontend/page/dir/api.ts +7 -0
  147. package/src/web/frontend/page/dir/index.tsx +24 -58
  148. package/src/web/frontend/page/dir/landing.tsx +85 -72
  149. package/src/web/frontend/page/dir/task-actions.ts +17 -5
  150. package/src/web/frontend/page/dir/task-dock-panel.tsx +87 -2
  151. package/src/web/frontend/page/dir/task-dock.ts +21 -10
  152. package/src/web/frontend/page/dir/task-goal.ts +2 -2
  153. package/src/web/frontend/page/dir/task-status-bar.tsx +14 -1
  154. package/src/web/frontend/page/dir/task.tsx +5 -3
  155. package/src/web/frontend/page/doc/api.ts +71 -5
  156. package/src/web/frontend/page/doc/bindings.tsx +240 -0
  157. package/src/web/frontend/page/doc/doc-dock.tsx +159 -0
  158. package/src/web/frontend/page/doc/index.tsx +131 -212
  159. package/src/web/frontend/page/doc/use-wiki-nav.ts +101 -0
  160. package/src/web/frontend/page/group/index.tsx +61 -87
  161. package/src/web/frontend/page/overview/index.tsx +1 -2
  162. package/src/web/frontend/page/refs/api.ts +60 -8
  163. package/src/web/frontend/page/refs/index.tsx +177 -90
  164. package/src/web/frontend/page/refs/style.css +45 -2
  165. package/src/web/frontend/page/repos/doc-search-modal.tsx +7 -0
  166. package/src/web/frontend/page/repos/index.tsx +21 -60
  167. package/src/web/frontend/page/repos/repo-table.tsx +85 -77
  168. package/src/web/frontend/page/settings/index.tsx +3 -27
  169. package/src/web/frontend/page/settings/prompt-template-params.ts +18 -28
  170. package/src/web/frontend/panels.tsx +52 -6
  171. package/src/web/frontend/registry.ts +1 -2
  172. package/src/web/frontend/routes/index.ts +1 -2
  173. package/src/web/frontend/routes/static.ts +2 -3
  174. package/src/web/frontend/store.tsx +1 -8
  175. package/src/web/frontend/style.css +1 -0
  176. package/src/web/frontend/styles/base.css +0 -17
  177. package/src/web/frontend/styles/bindings.css +75 -0
  178. package/src/web/frontend/styles/buttons-cards.css +0 -72
  179. package/src/web/frontend/styles/repos-admin.css +7 -5
  180. package/src/web/frontend/styles-v2/dir.css +1 -9
  181. package/src/web/frontend/styles-v2/shell.css +0 -2
  182. package/src/web/frontend/styles-v2/sidebar.css +12 -0
  183. package/src/web/frontend/styles-v2/views.css +22 -102
  184. package/src/web/frontend/workspace/areas.ts +0 -2
  185. package/src/web/public/assets/Introduction-CohW6Xit.js +6 -0
  186. package/src/web/public/assets/Introduction-Iuxssa-b.css +1 -0
  187. package/src/web/public/assets/app-context-BgpTewyA.js +1 -0
  188. package/src/web/public/assets/{bar-B52NTf_v.js → bar-C2mfoqmj.js} +1 -1
  189. package/src/web/public/assets/{board-view-DABoVkaA.js → board-view-aAIEbSQi.js} +1 -1
  190. package/src/web/public/assets/button-xyR2UROd.js +1 -0
  191. package/src/web/public/assets/composer-launch-eTktHT_f.js +1 -0
  192. package/src/web/public/assets/{composer-panel-DpiU2h50.js → composer-panel-C0OOIXxz.js} +1 -1
  193. package/src/web/public/assets/dag-Gm4RcvEg.js +1 -0
  194. package/src/web/public/assets/dir-PjuMRbWo.js +3 -0
  195. package/src/web/public/assets/group-D94y_Lq6.js +1 -0
  196. package/src/web/public/assets/index-CBJKsJU3.css +1 -0
  197. package/src/web/public/assets/index-Crxdmsux.js +2 -0
  198. package/src/web/public/assets/md-history-CU_1I6ht.js +39 -0
  199. package/src/web/public/assets/{md-parse-b6GY5eBl.js → md-parse-CLyUaUto.js} +1 -1
  200. package/src/web/public/assets/{member-picker-B5I7KuOR.js → member-picker-XT12VRe6.js} +1 -1
  201. package/src/web/public/assets/model-CWJ8_2dN.js +2 -0
  202. package/src/web/public/assets/{overview-B3kHI66i.js → overview-BQm8BLCG.js} +1 -1
  203. package/src/web/public/assets/{progress-CdhFz0Lz.js → progress-CNam3Wuj.js} +2 -2
  204. package/src/web/public/assets/refs-C5idWnUj.css +1 -0
  205. package/src/web/public/assets/refs-ClETk1cj.js +2 -0
  206. package/src/web/public/assets/repos-BioGejZo.js +14 -0
  207. package/src/web/public/assets/route-crumb-Fc68LcQ4.js +1 -0
  208. package/src/web/public/assets/settings-BIzumXLD.js +8 -0
  209. package/src/web/public/assets/status-tag-CBFf_-ae.js +1 -0
  210. package/src/web/public/assets/task-CGmO3I2y.js +11 -0
  211. package/src/web/public/assets/task-row-DRBa11tf.js +1 -0
  212. package/src/web/public/assets/{task-status-DSrx0i66.js → task-status-BHF-y9Aq.js} +2 -1
  213. package/src/web/public/assets/{task-utils-_JAWRAz6.js → task-utils-DjODjVdc.js} +2 -2
  214. package/src/web/public/assets/{templates-CbRyW3PJ.js → templates-j8EzXHXf.js} +1 -1
  215. package/src/web/public/assets/ui-Y0aL-bGk.js +1 -0
  216. package/src/web/public/assets/use-rail-drag-DNfz4Gcx.js +1 -0
  217. package/src/web/public/assets/{workspace-4tw7trV7.js → workspace-D_G-B3TX.js} +4 -4
  218. package/src/web/public/index.html +9 -9
  219. package/assets/nx-kv/references/todo-commands.md +0 -269
  220. package/src/core/attachstore.ts +0 -360
  221. package/src/core/fileapi.ts +0 -267
  222. package/src/core/kvapi.ts +0 -237
  223. package/src/modules/auth/actions/_manifest.generated.ts +0 -26
  224. package/src/modules/auth/actions/auth-login.ts +0 -31
  225. package/src/modules/auth/actions/auth-logout.ts +0 -33
  226. package/src/modules/auth/actions/auth-me.ts +0 -33
  227. package/src/modules/auth/actions/auth-status.ts +0 -41
  228. package/src/modules/auth/index.ts +0 -24
  229. package/src/modules/auth/support.ts +0 -28
  230. package/src/modules/file/actions/file-list.ts +0 -31
  231. package/src/modules/file/actions/file-remove.ts +0 -31
  232. package/src/modules/file/actions/file-sync.ts +0 -33
  233. package/src/modules/localtask/actions/localtask-importRemote.ts +0 -51
  234. package/src/modules/localtask/actions/task-move.ts +0 -67
  235. package/src/modules/localtask/move-prims.ts +0 -170
  236. package/src/modules/localtask/move.ts +0 -174
  237. package/src/modules/localtask/remote-import.ts +0 -159
  238. package/src/modules/repos/actions/repo-ref-backfill.ts +0 -33
  239. package/src/modules/repos/ref-backfill.ts +0 -219
  240. package/src/modules/todo/actions/_manifest.generated.ts +0 -89
  241. package/src/modules/todo/actions/group-add.ts +0 -34
  242. package/src/modules/todo/actions/group-current.ts +0 -36
  243. package/src/modules/todo/actions/group-get.ts +0 -43
  244. package/src/modules/todo/actions/group-list.ts +0 -41
  245. package/src/modules/todo/actions/group-members.ts +0 -41
  246. package/src/modules/todo/actions/group-remove.ts +0 -44
  247. package/src/modules/todo/actions/group-update.ts +0 -37
  248. package/src/modules/todo/actions/group-use.ts +0 -43
  249. package/src/modules/todo/actions/prompt-get.ts +0 -31
  250. package/src/modules/todo/actions/prompt-remove.ts +0 -31
  251. package/src/modules/todo/actions/prompt-set.ts +0 -32
  252. package/src/modules/todo/actions/todo-add.ts +0 -34
  253. package/src/modules/todo/actions/todo-archive.ts +0 -33
  254. package/src/modules/todo/actions/todo-attach.ts +0 -37
  255. package/src/modules/todo/actions/todo-attachments.ts +0 -33
  256. package/src/modules/todo/actions/todo-done.ts +0 -33
  257. package/src/modules/todo/actions/todo-freeze.ts +0 -32
  258. package/src/modules/todo/actions/todo-get.ts +0 -33
  259. package/src/modules/todo/actions/todo-list.ts +0 -32
  260. package/src/modules/todo/actions/todo-remove.ts +0 -32
  261. package/src/modules/todo/actions/todo-unfreeze.ts +0 -34
  262. package/src/modules/todo/actions/todo-update.ts +0 -42
  263. package/src/modules/todo/actions/topic-add.ts +0 -31
  264. package/src/modules/todo/actions/topic-list.ts +0 -35
  265. package/src/modules/todo/actions/topic-remove.ts +0 -36
  266. package/src/modules/todo/attachments.ts +0 -194
  267. package/src/modules/todo/group.ts +0 -207
  268. package/src/modules/todo/index.ts +0 -26
  269. package/src/modules/todo/locate.ts +0 -103
  270. package/src/modules/todo/service.ts +0 -476
  271. package/src/modules/todo/store.ts +0 -176
  272. package/src/modules/todo/support.ts +0 -93
  273. package/src/web/frontend/components/Introduction/docs-modal.tsx +0 -338
  274. package/src/web/frontend/components/cloud/editor.tsx +0 -254
  275. package/src/web/frontend/components/cloud/group-popup.tsx +0 -198
  276. package/src/web/frontend/components/cloud/markdown.tsx +0 -60
  277. package/src/web/frontend/components/migrate/dialog.tsx +0 -120
  278. package/src/web/frontend/components/migrate/undo.tsx +0 -73
  279. package/src/web/frontend/components/migrate/use-move.ts +0 -137
  280. package/src/web/frontend/page/cloud/api.ts +0 -99
  281. package/src/web/frontend/page/cloud/index.tsx +0 -516
  282. package/src/web/frontend/page/dir/deleted-panel.tsx +0 -77
  283. package/src/web/public/assets/Introduction-BcPrmROW.css +0 -1
  284. package/src/web/public/assets/Introduction-Du_dycft.js +0 -6
  285. package/src/web/public/assets/app-context-BASCGAA-.js +0 -1
  286. package/src/web/public/assets/cloud-Droja_aT.js +0 -3
  287. package/src/web/public/assets/composer-launch-mK9Nr6mZ.js +0 -1
  288. package/src/web/public/assets/dag-Ca-wjIxQ.js +0 -1
  289. package/src/web/public/assets/deleted-panel-K9GgfR8t.js +0 -1
  290. package/src/web/public/assets/dir-DacRpcBt.js +0 -5
  291. package/src/web/public/assets/frontmatter-CLLxCmTv.js +0 -2
  292. package/src/web/public/assets/group-TPuU-QVc.js +0 -2
  293. package/src/web/public/assets/index-BkLkooKe.js +0 -2
  294. package/src/web/public/assets/index-DP3qBv1o.css +0 -1
  295. package/src/web/public/assets/md-history-0GBWw4qr.js +0 -39
  296. package/src/web/public/assets/model-Bn2fG6CC.js +0 -2
  297. package/src/web/public/assets/prompt-blocks-BovFd039.js +0 -8
  298. package/src/web/public/assets/refs-BDxfuH6R.js +0 -1
  299. package/src/web/public/assets/refs-CY4i7PoC.css +0 -1
  300. package/src/web/public/assets/repos-C8jRM7wS.js +0 -15
  301. package/src/web/public/assets/repos-ZPiaK93i.css +0 -1
  302. package/src/web/public/assets/route-crumb-QvahotvN.js +0 -1
  303. package/src/web/public/assets/settings-BBcdGLTc.js +0 -1
  304. package/src/web/public/assets/status-tag-BheHByek.js +0 -1
  305. package/src/web/public/assets/task-CUkQaLBZ.js +0 -11
  306. package/src/web/public/assets/tool-bar-BAmT-BI-.js +0 -1
  307. package/src/web/public/assets/upload-BcMhRsMn.js +0 -1
  308. /package/src/web/public/assets/{prompt-blocks-DA4lNJeC.css → button-DA4lNJeC.css} +0 -0
  309. /package/src/web/public/assets/{tool-bar-1h2zairf.css → use-rail-drag-1h2zairf.css} +0 -0
@@ -1,93 +0,0 @@
1
- // todo 模块的辅助函数/常量(legacy 形态里与 action 表同文件,迁来时一并搬到这里)。
2
- //
3
- // 参数与返回值暂用宽松类型(迁移期),服务层类型化推进时逐个收紧。
4
- import { listGroups } from '../../core/kvapi.js';
5
- import { badInput, notFound } from '../../core/errors.js';
6
-
7
- export function renderTaskList(d: any) {
8
- const groups: any = [
9
- ['open', '待办'],
10
- ['done', '已完成'],
11
- ['freeze', '冻结'],
12
- ].filter(([k]: any) => d[k]);
13
-
14
- const lines: any = [];
15
- if (d.topic) lines.push(`topic=${d.topic}`);
16
- // 只在真同步过时才出现(见 service.listTodos);失败数单独提出来,
17
- // 因为「清单读到了、附件没下下来」是使用者必须看见的一件事。
18
- if (d.attachmentsSync) {
19
- const s: any = d.attachmentsSync;
20
- lines.push(
21
- `附件同步: 目录 ${s.dir || '—'} · 下载 ${s.downloaded || 0} · 跳过 ${s.skipped || 0}` +
22
- (s.failures && s.failures.length ? ` · 失败 ${s.failures.length}` : '')
23
- );
24
- }
25
- for (const [key, label] of groups) {
26
- const items: any = d[key];
27
- if (!items) continue;
28
- if (!items.length) {
29
- lines.push(`${label}: (空)`);
30
- continue;
31
- }
32
- lines.push(`${label}(${items.length}):`);
33
- const w: any = Math.max(...items.map((t: any) => String(t.id).length));
34
- for (const t of items) {
35
- const mark: any = key === 'done' ? `✓ ${shortTime(t.doneAt)}` : key === 'freeze' ? `❄ ${shortTime(t.frozenAt)}` : '';
36
- // id 只作展示位(对齐列的宽度由它决定),**操作时不要用它定位** ——
37
- // 定位一律用 --ref <内容>,见文件头的说明。
38
- lines.push(` ${String(t.id).padStart(w)} [${t.topic}] ${t.text}${mark ? ' ' + mark : ''}`);
39
- if (t.note) lines.push(` ${' '.repeat(w)} note: ${t.note.slice(0, 100)}`);
40
- for (const a of t.attachments || []) {
41
- lines.push(
42
- ` ${' '.repeat(w)} ${a.kind === 'image' ? '图片' : '附件'}: ${a.localPath || a.name}${a.localPath ? '' : '(未同步)'}`
43
- );
44
- }
45
- }
46
- }
47
- return lines.join('\n');
48
- }
49
-
50
- export const shortTime: any = (s: any) => (s ? String(s).slice(0, 16).replace('T', ' ') : '');
51
-
52
- export const renderTask: any = (t: any) => [
53
- `[${t.topic}] ${t.text}`,
54
- ` 状态: ${t.doneAt ? '已完成' : t.frozenAt ? '冻结' : '待办'}${t.bucket ? `(在 ${t.bucket})` : ''}`,
55
- ` 创建: ${t.createdAt}`,
56
- t.doneAt ? ` 完成: ${t.doneAt}` : '',
57
- t.frozenAt ? ` 冻结: ${t.frozenAt}` : '',
58
- t.note ? ` 备注: ${t.note}` : '',
59
- ...(t.attachments || []).map(
60
- (a: any) => ` 附件: ${a.localPath || a.name}${a.localPath ? '' : `(未同步;nx-kv file sync --ids ${a.id})`}`
61
- ),
62
- ]
63
- .filter(Boolean)
64
- .join('\n');
65
-
66
- export function renderTaskAttachments(d: any) {
67
- const lines: any = [`[${d.task.topic}] ${d.task.text}`];
68
- if (!d.count) {
69
- lines.push(' (这条任务没有引用附件)');
70
- return lines.join('\n');
71
- }
72
- lines.push(` 本地目录: ${d.localDir}(自动下载 ${d.autoSync ? '开' : '关'})`);
73
- for (const a of d.attachments) {
74
- lines.push(` ${a.kind === 'image' ? '图片' : '附件'} ${a.name} [${a.id}]`);
75
- lines.push(` ${a.localPath || '(未同步;nx-kv file sync --ids ' + a.id + ')'}`);
76
- }
77
- return lines.join('\n');
78
- }
79
-
80
- export const renderGroupLine: any = (g: any, current: any) => `${current ? '*' : ' '} ${String(g.id).padStart(4)} ${g.name.padEnd(14)} ${(g.myRole || '').padEnd(6)} ${g.memberCount} 人 ${g.description || ''}`;
81
-
82
- export async function findGroup(locator: any) {
83
- const s: any = String(locator ?? '').trim();
84
- if (!s) throw badInput('必须给出工作空间 id 或名称(nx-kv group list 可查看)');
85
- const groups: any = await listGroups();
86
- const hit: any = /^\d+$/.test(s)
87
- ? groups.find((g: any) => g.id === Number(s))
88
- : groups.find((g: any) => g.name.toLowerCase() === s.toLowerCase());
89
- if (!hit) {
90
- throw notFound(`工作空间不存在或无权访问: ${s}(nx-kv group list 查看可用项)`);
91
- }
92
- return hit;
93
- }
@@ -1,338 +0,0 @@
1
- // 「查看详情」弹窗(项目 / 项目组统一):**只有文章列表**,不是编辑器。
2
- //
3
- // #88 口径修正(2026-11-07):编辑页就是 maincontent,不是弹窗面板。
4
- // ① 弹窗只干一件事:列出当前项目 / 项目组的全部文章,只显示标题(不铺 tag、不渲染正文);
5
- // ② 点一行 → 在工作区**主内容区**打开该文档(component:'doc',落点 maincontent),
6
- // 再由 DocPanel 承担编辑 / 保存 / 更多(那一页本来就是"任务页同构"的编辑器);
7
- // ③ 弹窗里的行内小动作只留管理类:改标签(#)、摘除(×)、+补充——都不该跳页。
8
- //
9
- // 为什么不在这里内嵌编辑器:maincontent 是**单面板位**(areas.js),弹窗里再套一个
10
- // 编辑器等于两套编辑器、两套保存语义,用户点"更多 → 文字列表"还会被模态遮罩压住。
11
- // 唯一的数据面在 DocPanel 那边,这里只负责"选哪篇"。
12
- //
13
- // 数据面:repo → GET /api/repos/docs(main/extras/links 三段),
14
- // board → GET /api/boards/:id(introMain/introExtras/docLinks)。列表实时拉取,
15
- // 加/摘/改标签后重拉即可见(不读父层快照——Introduction 旧实现的教训)。
16
- import { useCallback, useEffect, useState } from 'react';
17
- import type { Model } from 'flexlayout-react';
18
- import { api } from '../../api/client.js';
19
- import { useApp } from '../../app-context.jsx';
20
- import { Modal, useDialog } from '../popup/index.jsx';
21
- import { useToast } from '../toast/index.jsx';
22
- import { useIntro, introDirFromRef } from './use-intro.js';
23
- import type { DialogResult, IntroDocEntry, IntroKind, IntroOwner } from './use-intro.js';
24
- import { slugName } from '../../modules/md/md-parse.js';
25
- import { openPanel } from '../../workspace.js';
26
- import './style.css';
27
-
28
- /** 列表条目:sections = 主篇 / 补充 / reference / 组内(仅项目)。
29
- * removable=摘除入口(登记的 docLinks 与主篇自定义绑定);taggable=可改标签。 */
30
- interface DocsItem {
31
- id: string;
32
- kind: string;
33
- label: string;
34
- sub: string;
35
- tag: string;
36
- note: string;
37
- docId: string;
38
- removable: boolean;
39
- taggable: boolean;
40
- removeTip?: string;
41
- removeIndex?: number;
42
- }
43
-
44
- /** 「在主内容区打开」只需要这三个字段(+补充后直接开新文档)。 */
45
- interface OpenTarget {
46
- docId: string;
47
- label?: string;
48
- sub?: string;
49
- }
50
-
51
- export interface DocsModalProps {
52
- /** 调用方(仓库页 DocsTarget)传的是 string;实际只会是 'repo' | 'board'。 */
53
- kind: string;
54
- /** 仓库 / 看板对象(repoData 行,含 doc / boards / key|id)。 */
55
- owner: IntroOwner;
56
- /** FlexLayout model(主内容区开文档用);不给则取全局 model。 */
57
- model?: Model | null;
58
- /** 增删改后通知父层刷新。 */
59
- onChanged?: () => void;
60
- onClose: () => void;
61
- }
62
-
63
- function docIdOf(l: IntroDocEntry | null | undefined): string {
64
- if (!l) return '';
65
- if (l.rel) return 'rel:' + l.rel;
66
- if (l.path) return 'path:' + l.path;
67
- return '';
68
- }
69
-
70
- function baseLabel(l: IntroDocEntry): string {
71
- const s = l.rel || l.path || '';
72
- return String(s).replace(/[\\/]+$/, '').split(/[\\/]/).pop() || s || '未命名';
73
- }
74
-
75
- function buildSections(
76
- data: Record<string, any> | null | undefined,
77
- owner: IntroOwner | null | undefined,
78
- kind: string
79
- ): DocsItem[] {
80
- const out: DocsItem[] = [];
81
- const main = (data && (data.main || data.introMain)) as IntroDocEntry | null | undefined;
82
- if (main) {
83
- out.push({
84
- id: docIdOf(main),
85
- kind: 'main',
86
- label: '主篇',
87
- sub: main.rel || main.path || '',
88
- tag: '',
89
- note: '',
90
- docId: docIdOf(main),
91
- removable: kind === 'repo' && !!(owner && owner.doc),
92
- removeTip: '摘除主篇自定义绑定(回退约定路径,文档不删)',
93
- taggable: false,
94
- });
95
- }
96
- for (const l of ((data && (data.extras || data.introExtras)) || []) as IntroDocEntry[]) {
97
- const id = docIdOf(l);
98
- if (!id) continue;
99
- out.push({
100
- id,
101
- kind: 'extra',
102
- label: baseLabel(l),
103
- sub: l.rel || l.path || '',
104
- tag: '',
105
- note: '',
106
- docId: id,
107
- removable: false,
108
- taggable: String(id).startsWith('rel:'),
109
- });
110
- }
111
- // 登记的 reference:repo 与 board 的响应字段名不同(links / docLinks)
112
- const registered = ((data && (data.links || data.docLinks)) || []) as IntroDocEntry[];
113
- registered.forEach((l, i) => {
114
- const id = docIdOf(l);
115
- if (!id) return;
116
- out.push({
117
- id,
118
- kind: 'link',
119
- label: baseLabel(l),
120
- sub: l.rel || l.path || '',
121
- tag: l.tag || '',
122
- note: l.note || '',
123
- docId: id,
124
- // repo:1=主篇绑定,≥2=docLinks[n-2];board:docLinks 1-based
125
- removeIndex: kind === 'repo' ? i + 2 : i + 1,
126
- removable: true,
127
- taggable: true,
128
- });
129
- });
130
- // 组内描述(仅项目):仓库 × 分组这一层,全部所属组逐条列出
131
- for (const b of (kind === 'repo' && owner && owner.boards) || []) {
132
- const abs = b.noteDocPath || '';
133
- const rel = b.noteDocRel || '';
134
- const id = abs ? 'path:' + abs : rel ? 'rel:' + rel : '';
135
- if (!id) continue;
136
- out.push({
137
- id,
138
- kind: 'scoped',
139
- label: `${b.name} · 组内描述`,
140
- sub: abs || rel,
141
- tag: '',
142
- note: b.note || '',
143
- docId: id,
144
- removable: false,
145
- taggable: false,
146
- });
147
- }
148
- return out.filter((x) => x.docId);
149
- }
150
-
151
- const KIND_MARK: Record<string, string> = { main: '● ', scoped: '◇ ', extra: '○ ', link: '○ ' };
152
-
153
- export default function DocsModal({ kind, owner, model, onClose, onChanged }: DocsModalProps) {
154
- const toast = useToast();
155
- const { dialog, node: dialogNode } = useDialog();
156
- // model 兜底取全局:仓库页/项目组页调用时并没有把 FlexLayout model 往下传,
157
- // 少这一层兜底 → 点行只会提示「工作区不可用」,文档页永远开不起来(探针实证)。
158
- const app = useApp();
159
- const wsModel = model || app.model;
160
- // kind 在调用方是 string(DocsTarget 的历史形状),实际只会是 repo / board
161
- const intro = useIntro({ kind: kind as IntroKind, owner, model: wsModel });
162
- const ownerKey = intro.ownerKey;
163
- const ownerName = owner && owner.name;
164
-
165
- const [items, setItems] = useState<DocsItem[]>([]);
166
- const [loading, setLoading] = useState(true);
167
- const [err, setErr] = useState('');
168
-
169
- // ─── 列表:实时拉取(repo / board 两个端点,结构化三段)─────────────────
170
- const reload = useCallback(async () => {
171
- if (!ownerKey) { setItems([]); setLoading(false); return; }
172
- setLoading(true);
173
- try {
174
- const d = kind === 'repo'
175
- ? await api('/api/repos/docs?id=' + encodeURIComponent(ownerKey))
176
- : await api('/api/boards/' + encodeURIComponent(String(ownerKey)));
177
- setItems(buildSections(d, owner, kind));
178
- setErr('');
179
- } catch (e) {
180
- setItems([]);
181
- setErr(String((e as Error).message || e));
182
- } finally {
183
- setLoading(false);
184
- }
185
- }, [kind, ownerKey, owner]);
186
-
187
- useEffect(() => { reload(); }, [reload]);
188
-
189
- // ─── 点一行 → 主内容区开文档页(编辑 / 保存 / 更多都在那一页)────────────
190
- const openInMain = (it: OpenTarget | null | undefined) => {
191
- if (!it) return;
192
- const m = wsModel;
193
- if (!m) { toast('工作区不可用,无法打开文档'); return; }
194
- openPanel(m, {
195
- component: 'doc',
196
- name: it.label || it.sub || it.docId,
197
- config: {
198
- docId: it.docId,
199
- ...(kind === 'repo'
200
- ? { repoKey: ownerKey }
201
- : { boardKey: ownerKey, boardName: ownerName || '' }),
202
- },
203
- location: 'center',
204
- });
205
- // 文档页已经落到 maincontent,弹窗(模态)留着只会挡住它
206
- onClose();
207
- };
208
-
209
- // ─── 管理:摘除 / 标签 / +补充(行内小动作,都不跳页)────────────────────
210
- const guard = (fn: () => Promise<unknown>) => fn().catch((e: Error) => toast(String(e.message || e)));
211
-
212
- const removeItem = (it: DocsItem) => guard(async () => {
213
- const ok = await dialog({
214
- message: `摘除「${it.label}」?${it.kind === 'main' ? '(只拆绑定,文档不删)' : '(文档不删,仅移出列表)'}`,
215
- danger: true,
216
- });
217
- if (!ok) return;
218
- if (kind === 'repo') {
219
- await api('/api/repos/docs', { method: 'DELETE', body: { id: ownerKey, index: it.removeIndex } });
220
- } else {
221
- await api('/api/docs/link', { method: 'POST', body: { board: ownerKey, remove: it.removeIndex } });
222
- }
223
- toast('已摘除');
224
- reload();
225
- if (onChanged) onChanged();
226
- });
227
-
228
- const editTag = (it: DocsItem) => guard(async () => {
229
- // dialog() 的 resolve 是 unknown(popup 原语不建模返回值形状):这是外部原语边界
230
- const res = (await dialog({
231
- title: `标签 · ${it.label}`,
232
- input: true,
233
- placeholder: '标签(如 qa;留空 = 清掉)',
234
- value: it.tag || '',
235
- okText: '保存标签',
236
- })) as DialogResult;
237
- if (res === null) return;
238
- const tag = typeof res === 'string' ? res : (res && res.tag) || '';
239
- await intro.setLinkTag(it.docId, tag, it);
240
- toast(tag ? `标签已设为 [${tag}]` : '标签已清除');
241
- reload();
242
- if (onChanged) onChanged();
243
- });
244
-
245
- // +补充:落一篇 reference 并登记——就地刷新列表(不跳文档页,免得弹窗被卸载)
246
- const addDoc = () => guard(async () => {
247
- if (!ownerKey || !String(intro.docRef || '').startsWith('rel:')) {
248
- toast('当前简介无法补充(需要自有树路径)');
249
- return;
250
- }
251
- // dialog() 的 resolve 是 unknown:外部原语边界,按「单输入 / 双输入」两种口径收口
252
- const res = (await dialog({
253
- title: '补充介绍文档',
254
- input: true,
255
- tagInput: true,
256
- placeholder: '文档名(如 architecture / api-notes)',
257
- tagPlaceholder: '标签(可选,如 qa)',
258
- })) as DialogResult;
259
- if (res === null) return;
260
- const name = typeof res === 'string' ? res : (res && res.value) || '';
261
- const tag = typeof res === 'object' && res ? (res.tag || '') : '';
262
- const slug = slugName(String(name).trim() || 'note').replace(/\.md$/i, '');
263
- const dir = introDirFromRef(intro.docRef) || (kind === 'repo' ? `repo/${ownerKey}` : `board/${ownerName || ownerKey}`);
264
- const rel = `${dir}/reference/${slug}.md`;
265
- await api('/api/docs/item', { method: 'POST', body: { rel, body: `# ${String(name).trim() || slug}\n\n(待补)\n` } });
266
- try {
267
- if (kind === 'repo') {
268
- await api('/api/repos/docs', { method: 'POST', body: { id: ownerKey, rel, tag: tag || undefined } });
269
- } else {
270
- await api('/api/docs/link', { method: 'POST', body: { board: ownerKey, doc: rel, tag: tag || undefined } });
271
- }
272
- } catch {
273
- /* 集里已有 / 旧数据:文件已创建即可——同 doc 重复添加 = 更新(tag 以本次为准) */
274
- }
275
- toast(`已补充:${rel}${tag ? ` [${tag}]` : ''}`);
276
- await reload();
277
- if (onChanged) onChanged();
278
- // 新建完直接在主内容区打开它(用户已确认这个口径:少一次点击)
279
- openInMain({
280
- docId: 'rel:' + rel,
281
- label: String(name).trim() || slug,
282
- sub: rel,
283
- });
284
- });
285
-
286
- const canAdd = !!String(intro.docRef || '').startsWith('rel:') && ownerKey;
287
- const total = items.length;
288
- const title = `文档列表 · ${ownerName || ''}${kind === 'board' ? '(项目组)' : ''}`;
289
-
290
- return (
291
- <Modal size="md" title={title} onClose={onClose}>
292
- <div className="nx-dl">
293
- <div className="nx-dl-head">
294
- <span className="nx-dl-count">{total ? `${total} 篇` : '还没有文档'}</span>
295
- <span className="nx-dl-hint">点标题在主内容区打开</span>
296
- <span className="grow" />
297
- {canAdd && (
298
- <button type="button" className="btn ghost sm nx-dl-add" title="补充一篇介绍文档(reference)" onClick={addDoc}>
299
- + 补充
300
- </button>
301
- )}
302
- </div>
303
- {err ? <div className="rpd-err">{err}</div> : null}
304
- {!err && loading && total === 0 ? <div className="rpd-empty">载入中…</div> : null}
305
- {!err && !loading && total === 0 ? (
306
- <div className="rpd-none">还没有文档 —— 点「+ 补充」写第一篇</div>
307
- ) : null}
308
- <div className="nx-dl-list">
309
- {items.map((it) => (
310
- <div key={it.id} className="nx-dl-row-wrap">
311
- <button
312
- type="button"
313
- className="nx-dl-row"
314
- title={`${it.sub || it.label}\n点击在主内容区打开(可编辑)`}
315
- onClick={() => openInMain(it)}
316
- >
317
- <span className="nx-dl-row-title">
318
- {KIND_MARK[it.kind] || '○ '}
319
- {it.label}
320
- </span>
321
- {it.tag ? <span className="rpd-badge">{it.tag}</span> : null}
322
- </button>
323
- <span className="nx-docs-modal-item-acts">
324
- {it.taggable && (
325
- <button type="button" className="nx-docs-modal-mini" title={it.tag ? `改标签(当前:${it.tag})` : '加标签'} onClick={() => editTag(it)}>#</button>
326
- )}
327
- {it.removable && (
328
- <button type="button" className="nx-docs-modal-mini danger" title={it.removeTip || `摘除「${it.label}」(文档不删)`} onClick={() => removeItem(it)}>×</button>
329
- )}
330
- </span>
331
- </div>
332
- ))}
333
- </div>
334
- </div>
335
- {dialogNode}
336
- </Modal>
337
- );
338
- }
@@ -1,254 +0,0 @@
1
- // 任务编辑器:编辑正文时**直接上传图片 / docx 等附件**,插入标准 markdown 嵌入。
2
- //
3
- // 为什么不再是原来那个单行 dialog:
4
- // 1. 正文现在会长出 markdown 嵌入,单行输入框看不见也编辑不了;
5
- // 2. 上传必须发生在编辑现场(选完/粘完立刻插到光标处),
6
- // 否则用户得先记住 fileId 再手拼语法 —— 那是给机器用的接口,不是给人用的。
7
- //
8
- // 三条上传路径共用一套逻辑(./upload.js):**选择文件 / Ctrl+V 粘贴 / 拖进来**。
9
- // 其中粘贴截图是最常用的那条 —— 截图工具连文件名都不给,所以 upload.js 会替它起名。
10
- import { useEffect, useRef, useState } from 'react';
11
- import type { ClipboardEvent as ReactClipboardEvent, KeyboardEvent as ReactKeyboardEvent } from 'react';
12
- import { api } from '../../api/client.js';
13
- import { useToast } from '../toast/index.jsx';
14
- import { AttachmentText } from './markdown.jsx';
15
- import { clipboardFiles, droppedFiles, snippetsOf, uploadMany } from './upload.js';
16
-
17
- /**
18
- * 编辑器打开的那条待办。
19
- *
20
- * 只声明真正读到的字段(不抄 /api/todo 的 schema)——调用方传自己的行类型也能过,
21
- * 不必为了 index signature 去改造它的接口。
22
- */
23
- export interface EditorTask {
24
- text?: string;
25
- topic?: string;
26
- note?: string;
27
- }
28
-
29
- export interface TaskEditorProps {
30
- task: EditorTask;
31
- /** 编辑目标在清单里的定位(原样回传,语义在后端)。 */
32
- pick?: number | string;
33
- /** 工作空间 id(上传附件的归属)。 */
34
- group?: number;
35
- onSaved: () => void;
36
- onCancel: () => void;
37
- }
38
-
39
- export default function TaskEditor({ task, pick, group, onSaved, onCancel }: TaskEditorProps) {
40
- const toast = useToast();
41
- const [text, setText] = useState(task.text || '');
42
- const [note, setNote] = useState(task.note || '');
43
- const [busy, setBusy] = useState(false);
44
- const [progress, setProgress] = useState<{ done: number; total: number } | null>(null); // { done, total }
45
- const [dragOver, setDragOver] = useState(false);
46
- const taRef = useRef<HTMLTextAreaElement | null>(null);
47
- const fileRef = useRef<HTMLInputElement | null>(null);
48
-
49
- // 正文的「权威值」。插入要同步读到**最新的** text,而 setState 是异步的 ——
50
- // 用 ref 保持同步,就不必在闭包里跟陈旧 state 斗智。
51
- const textRef = useRef(text);
52
- const writeText = (v: string) => {
53
- textRef.current = v;
54
- setText(v);
55
- };
56
-
57
- useEffect(() => {
58
- const ta = taRef.current;
59
- if (ta) {
60
- ta.focus();
61
- ta.setSelectionRange(ta.value.length, ta.value.length); // 光标落尾:粘贴/拖入紧接着追加
62
- }
63
- }, []);
64
-
65
- /** 插到**光标处**(未聚焦时落尾)。 */
66
- const insert = (snippet: string) => {
67
- if (!snippet) return;
68
- const ta = taRef.current;
69
- const cur = textRef.current;
70
- // textarea 的 selectionStart/End 恒为 number(null 只会出现在不支持选区能力的 input 上)
71
- const start = ta ? ta.selectionStart : cur.length;
72
- const end = ta ? ta.selectionEnd : start;
73
- const before = cur.slice(0, start);
74
- const after = cur.slice(end);
75
- // 与前后内容之间垫一个空格,免得嵌入跟前文粘成一串
76
- const needBefore = before && !/\s$/.test(before) ? ' ' : '';
77
- const needAfter = after && !/^\s/.test(after) ? ' ' : '';
78
- const next = `${before}${needBefore}${snippet}${needAfter}${after}`;
79
- writeText(next);
80
-
81
- const caret = before.length + needBefore.length + snippet.length;
82
- requestAnimationFrame(() => {
83
- const el = taRef.current;
84
- if (!el) return;
85
- el.focus();
86
- el.setSelectionRange(caret, caret);
87
- });
88
- };
89
-
90
- const uploadAll = async (files: FileList | File[] | null) => {
91
- const list: File[] = Array.from(files || []).filter((f) => f && f.size > 0);
92
- if (!list.length || progress) return;
93
- setProgress({ done: 0, total: list.length });
94
- try {
95
- const results = await uploadMany(list, {
96
- group,
97
- onProgress: (done, total) => setProgress({ done, total }),
98
- });
99
- // 一次插入全部片段:连续插入会跟光标位置打架(见 upload.js 的注释)
100
- insert(snippetsOf(results));
101
- const imgs = results.filter((r) => r.isImage).length;
102
- toast(
103
- results.length === 1
104
- ? `已插入 ${results[0].name}`
105
- : `已插入 ${results.length} 个附件${imgs ? `(图片 ${imgs} 个)` : ''}`
106
- );
107
- } catch (err) {
108
- toast(String((err as Error).message || err));
109
- } finally {
110
- setProgress(null);
111
- }
112
- };
113
-
114
- const onPaste = (e: ReactClipboardEvent<HTMLTextAreaElement>) => {
115
- const files = clipboardFiles(e);
116
- // 没有文件就是普通文本粘贴:不要 preventDefault,
117
- // 交给浏览器按默认行为插到光标处 —— 「Ctrl+V 直接复制到对应位置」。
118
- if (!files.length) return;
119
- e.preventDefault();
120
- uploadAll(files);
121
- };
122
-
123
- // 拖拽挂在 **window** 上而不是编辑器容器上:用户是往弹窗里丢文件的,
124
- // 落点差一点(丢在标题上、丢在预览区外)也该接住,而不是让浏览器把文件打开。
125
- // 用 ref 拿最新的处理器,避免把 window 监听跟着每次状态变化重新注册。
126
- const dropRef = useRef<((e: DragEvent) => void) | null>(null);
127
- dropRef.current = (e: DragEvent) => uploadAll(droppedFiles(e));
128
-
129
- useEffect(() => {
130
- // 只在**拖文件**时介入:拖选中的文字/链接不该弹「松手即上传」
131
- const hasFiles = (e: DragEvent) => Array.from((e.dataTransfer && e.dataTransfer.types) || []).includes('Files');
132
- const over = (e: DragEvent) => { if (!hasFiles(e)) return; e.preventDefault(); setDragOver(true); };
133
- const leave = (e: DragEvent) => { if (!e.relatedTarget) setDragOver(false); };
134
- const drop = (e: DragEvent) => {
135
- if (!hasFiles(e)) return;
136
- e.preventDefault();
137
- setDragOver(false);
138
- if (dropRef.current) dropRef.current(e);
139
- };
140
- window.addEventListener('dragover', over);
141
- window.addEventListener('dragleave', leave);
142
- window.addEventListener('drop', drop);
143
- return () => {
144
- window.removeEventListener('dragover', over);
145
- window.removeEventListener('dragleave', leave);
146
- window.removeEventListener('drop', drop);
147
- };
148
- }, []);
149
-
150
- const save = () => {
151
- if (busy) return;
152
- if (!String(textRef.current).trim()) {
153
- toast('正文不能为空');
154
- return;
155
- }
156
- // 外部数据边界:/api/todo/item 的补丁体,字段按后端契约拼
157
- const body: Record<string, unknown> = { group, ref: task.text, pick, matchTopic: task.topic, text: textRef.current };
158
- // 备注只在真的改过时才发:PATCH 的语义是「只改传入的字段」
159
- if (note !== (task.note || '')) body.note = note;
160
- setBusy(true);
161
- api('/api/todo/item', { method: 'PATCH', body })
162
- .then(() => { toast('已保存'); onSaved(); })
163
- .catch((err: unknown) => toast(String(((err as Error) && (err as Error).message) || err)))
164
- .finally(() => setBusy(false));
165
- };
166
-
167
- const onKeyDown = (e: ReactKeyboardEvent<HTMLTextAreaElement>) => {
168
- if ((e.ctrlKey || e.metaKey) && e.key === 'Enter') {
169
- e.preventDefault();
170
- save();
171
- }
172
- };
173
-
174
- const uploadingLabel = progress
175
- ? `上传中 ${progress.done}/${progress.total}…`
176
- : '选择文件上传';
177
- const empty = !String(text).trim();
178
-
179
- return (
180
- <div className={'editor' + (dragOver ? ' drag' : '')}>
181
- <div className="ed-tip">
182
- 粘贴(<kbd>Ctrl</kbd>+<kbd>V</kbd> 截图)、拖文件进来,或
183
- <button type="button" className="ed-link" onClick={() => fileRef.current && fileRef.current.click()} disabled={!!progress}>
184
- 选择文件
185
- </button>
186
- —— 会自动上传并插到光标处。
187
- <input
188
- ref={fileRef}
189
- type="file"
190
- multiple
191
- hidden
192
- onChange={(e) => {
193
- // ⚠️ 必须先拷成数组再清空 value:FileList 是**活的**,
194
- // `value = ''` 会当场把它清空,之后 uploadAll 拿到的是空列表。
195
- const picked = Array.from(e.target.files || []);
196
- e.target.value = '';
197
- uploadAll(picked);
198
- }}
199
- />
200
- </div>
201
-
202
- <div className="ed-field">
203
- <div className="ed-label">正文</div>
204
- <textarea
205
- ref={taRef}
206
- className="ed-textarea"
207
- rows={4}
208
- value={text}
209
- spellCheck="false"
210
- placeholder="要做什么… 图片写 ![说明](fileId),其他文件写 [文件名](fileId)"
211
- onChange={(e) => writeText(e.target.value)}
212
- onPaste={onPaste}
213
- onKeyDown={onKeyDown}
214
- />
215
- <div className="ed-meta">
216
- <span className="ed-acts">
217
- <button type="button" className="btn small" onClick={() => fileRef.current && fileRef.current.click()} disabled={!!progress}>
218
- {uploadingLabel}
219
- </button>
220
- <span className="hint">图片 <code>![说明](id)</code> 文件 <code>[文件名](id)</code></span>
221
- </span>
222
- <span className="hint">{text.length} 字符</span>
223
- </div>
224
- </div>
225
-
226
- <div className="ed-field">
227
- <div className="ed-label">预览</div>
228
- <div className={'preview' + (empty ? ' empty' : '')}>
229
- {empty ? <span className="muted">(暂无内容)</span> : <AttachmentText text={text} />}
230
- </div>
231
- </div>
232
-
233
- <div className="ed-field">
234
- <div className="ed-label">备注</div>
235
- <textarea
236
- className="ed-textarea"
237
- rows={2}
238
- value={note}
239
- spellCheck="false"
240
- placeholder="可选:完成结果、上下文补充"
241
- onChange={(e) => setNote(e.target.value)}
242
- />
243
- </div>
244
-
245
- <div className="ed-foot">
246
- <span className="hint"><kbd>Ctrl</kbd>+<kbd>Enter</kbd> 保存</span>
247
- <span className="ed-acts">
248
- <button className="btn ghost" onClick={onCancel} disabled={busy}>取消</button>
249
- <button className="btn" onClick={save} disabled={busy || !!progress}>{busy ? '保存中…' : '保存'}</button>
250
- </span>
251
- </div>
252
- </div>
253
- );
254
- }