@waterwx/dsh-novel-forge 1.3.2 → 1.3.3-alpha

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 (172) hide show
  1. package/README.md +288 -279
  2. package/lib/client.js +56288 -12061
  3. package/lib/index.js +14655 -5573
  4. package/lib/types/action-guard.d.ts +61 -0
  5. package/lib/types/ai-scan.d.ts +30 -0
  6. package/lib/types/assets.d.ts +22 -9
  7. package/lib/types/assistant.d.ts +29 -0
  8. package/lib/types/author-assets.d.ts +23 -0
  9. package/lib/types/bookshelf.d.ts +18 -3
  10. package/lib/types/client/api.d.ts +187 -10
  11. package/lib/types/client/chip-prefs.d.ts +36 -0
  12. package/lib/types/client/docx.d.ts +2 -2
  13. package/lib/types/client/index.d.ts +1 -1
  14. package/lib/types/client/llmLive.d.ts +31 -0
  15. package/lib/types/client/locales.d.ts +29 -67
  16. package/lib/types/client/mount.d.ts +0 -2
  17. package/lib/types/client/panel/AdaptModeView.d.ts +5 -0
  18. package/lib/types/client/panel/AiTag.d.ts +1 -0
  19. package/lib/types/client/panel/AssistantTab.d.ts +4 -1
  20. package/lib/types/client/panel/AuthorAssetsView.d.ts +4 -0
  21. package/lib/types/client/panel/AuthorHome.d.ts +34 -0
  22. package/lib/types/client/panel/BookAnalysisView.d.ts +4 -0
  23. package/lib/types/client/panel/CmdPalette.d.ts +12 -0
  24. package/lib/types/client/panel/CreateBookView.d.ts +5 -1
  25. package/lib/types/client/panel/DirectorView.d.ts +7 -0
  26. package/lib/types/client/panel/GlobalAssetLibraryView.d.ts +4 -0
  27. package/lib/types/client/panel/IdeaInspirationView.d.ts +6 -0
  28. package/lib/types/client/panel/ImportModal.d.ts +7 -0
  29. package/lib/types/client/panel/KnowledgeBaseView.d.ts +4 -0
  30. package/lib/types/client/panel/LiveFeedLog.d.ts +13 -0
  31. package/lib/types/client/panel/MarketRadarView.d.ts +5 -0
  32. package/lib/types/client/panel/ModelManager.d.ts +14 -0
  33. package/lib/types/client/panel/NovelPanel.d.ts +6 -1
  34. package/lib/types/client/panel/PageHeader.d.ts +18 -0
  35. package/lib/types/client/panel/ProgressConsole.d.ts +17 -0
  36. package/lib/types/client/panel/ProgressHomeView.d.ts +5 -0
  37. package/lib/types/client/panel/PromptSlotsView.d.ts +11 -0
  38. package/lib/types/client/panel/ReasoningSection.d.ts +10 -0
  39. package/lib/types/client/panel/SettingsView.d.ts +19 -0
  40. package/lib/types/client/panel/ShelfView.d.ts +12 -1
  41. package/lib/types/client/panel/SubPage.d.ts +27 -0
  42. package/lib/types/client/panel/TensionView.d.ts +18 -0
  43. package/lib/types/client/panel/TimelineView.d.ts +18 -0
  44. package/lib/types/client/panel/helpers.d.ts +5 -3
  45. package/lib/types/client/panel/market-radar-state.d.ts +56 -0
  46. package/lib/types/client/panel/toast.d.ts +2 -0
  47. package/lib/types/client/panel/views.d.ts +21 -35
  48. package/lib/types/client/run-status.d.ts +21 -0
  49. package/lib/types/client/sidebar-entry.d.ts +0 -2
  50. package/lib/types/client/text.d.ts +9 -0
  51. package/lib/types/docx-core.d.ts +16 -0
  52. package/lib/types/docx.d.ts +2 -3
  53. package/lib/types/engine.d.ts +186 -45
  54. package/lib/types/global-assets.d.ts +6 -0
  55. package/lib/types/home.d.ts +11 -0
  56. package/lib/types/index.d.ts +36 -10
  57. package/lib/types/llm-live.d.ts +70 -0
  58. package/lib/types/llm-retry.d.ts +38 -0
  59. package/lib/types/market-radar-scan.d.ts +18 -0
  60. package/lib/types/market-radar-sources.d.ts +31 -0
  61. package/lib/types/migrate-output.d.ts +25 -0
  62. package/lib/types/model-capability.d.ts +93 -0
  63. package/lib/types/novel-context.d.ts +80 -0
  64. package/lib/types/output-budget.d.ts +86 -0
  65. package/lib/types/prompt-slots.d.ts +57 -0
  66. package/lib/types/prompt-utils.d.ts +35 -0
  67. package/lib/types/prompting.d.ts +10 -0
  68. package/lib/types/protocol.d.ts +1378 -166
  69. package/lib/types/review-policy.d.ts +97 -0
  70. package/lib/types/revision.d.ts +76 -0
  71. package/lib/types/routes.d.ts +9 -3
  72. package/lib/types/run.d.ts +23 -1
  73. package/lib/types/settings-persist.d.ts +59 -0
  74. package/lib/types/snapshots.d.ts +46 -0
  75. package/lib/types/stage-contract.d.ts +58 -0
  76. package/lib/types/tension.d.ts +53 -0
  77. package/lib/types/timeline.d.ts +37 -0
  78. package/package.json +54 -28
  79. package/src/action-guard.ts +127 -0
  80. package/src/ai-scan.ts +155 -0
  81. package/src/assets.ts +1801 -520
  82. package/src/assistant.ts +1098 -770
  83. package/src/author-assets.ts +131 -0
  84. package/src/bookshelf.ts +193 -151
  85. package/src/client/api.ts +380 -23
  86. package/src/client/chip-prefs.ts +121 -0
  87. package/src/client/docx.ts +32 -69
  88. package/src/client/index.ts +3 -1
  89. package/src/client/llmLive.ts +111 -0
  90. package/src/client/locales.ts +29 -253
  91. package/src/client/mount.tsx +4 -3
  92. package/src/client/panel/AdaptModeView.tsx +535 -0
  93. package/src/client/panel/AiTag.tsx +7 -0
  94. package/src/client/panel/AssetsTab.tsx +448 -458
  95. package/src/client/panel/AssistantTab.tsx +355 -301
  96. package/src/client/panel/AuthorAssetsView.tsx +206 -0
  97. package/src/client/panel/AuthorHome.tsx +309 -0
  98. package/src/client/panel/BookAnalysisView.tsx +63 -0
  99. package/src/client/panel/CmdPalette.tsx +102 -0
  100. package/src/client/panel/CreateBookView.tsx +366 -348
  101. package/src/client/panel/DirectorView.tsx +200 -0
  102. package/src/client/panel/GlobalAssetLibraryView.tsx +168 -0
  103. package/src/client/panel/IdeaInspirationView.tsx +76 -0
  104. package/src/client/panel/ImportModal.tsx +303 -0
  105. package/src/client/panel/KnowledgeBaseView.tsx +125 -0
  106. package/src/client/panel/LiveFeedLog.tsx +204 -0
  107. package/src/client/panel/MarketRadarView.tsx +415 -0
  108. package/src/client/panel/ModelManager.tsx +205 -0
  109. package/src/client/panel/NovelPanel.tsx +3013 -2500
  110. package/src/client/panel/PageHeader.tsx +37 -0
  111. package/src/client/panel/ProgressConsole.tsx +63 -0
  112. package/src/client/panel/PromptSlotsView.tsx +97 -0
  113. package/src/client/panel/ReaderView.tsx +306 -306
  114. package/src/client/panel/ReasoningSection.tsx +31 -0
  115. package/src/client/panel/RunPanel.tsx +64 -32
  116. package/src/client/panel/SettingsView.tsx +355 -0
  117. package/src/client/panel/ShelfView.tsx +266 -236
  118. package/src/client/panel/SubPage.tsx +42 -0
  119. package/src/client/panel/TensionView.tsx +212 -0
  120. package/src/client/panel/TimelineView.tsx +208 -0
  121. package/src/client/panel/WorldTab.tsx +202 -202
  122. package/src/client/panel/helpers.ts +7 -5
  123. package/src/client/panel/market-radar-state.ts +79 -0
  124. package/src/client/panel/panel.module.css +4481 -1655
  125. package/src/client/panel/toast.ts +51 -0
  126. package/src/client/panel/views.tsx +316 -314
  127. package/src/client/run-status.ts +171 -0
  128. package/src/client/sidebar-entry.ts +4 -4
  129. package/src/client/text.ts +28 -0
  130. package/src/docx-core.ts +53 -0
  131. package/src/docx.ts +44 -83
  132. package/src/engine.ts +4759 -2943
  133. package/src/global-assets.ts +58 -0
  134. package/src/home.ts +33 -0
  135. package/src/index.ts +206 -65
  136. package/src/llm-live.ts +245 -0
  137. package/src/llm-retry.ts +77 -0
  138. package/src/market-radar-scan.ts +35 -0
  139. package/src/market-radar-sources.ts +173 -0
  140. package/src/migrate-output.ts +76 -0
  141. package/src/model-capability.ts +215 -0
  142. package/src/novel-context.ts +286 -0
  143. package/src/output-budget.ts +147 -0
  144. package/src/prompt-slots.ts +125 -0
  145. package/src/prompting.ts +26 -0
  146. package/src/protocol.ts +1405 -158
  147. package/src/revision.ts +283 -0
  148. package/src/routes.ts +1959 -436
  149. package/src/run.ts +118 -21
  150. package/src/settings-persist.ts +114 -0
  151. package/src/snapshots.ts +174 -0
  152. package/src/stage-contract.ts +186 -0
  153. package/src/tension.ts +251 -0
  154. package/src/timeline.ts +159 -0
  155. package/lib/client.js.map +0 -1
  156. package/lib/index.js.map +0 -1
  157. package/lib/types/comic-presets.d.ts +0 -12
  158. package/scripts/assistant-frames.txt +0 -8
  159. package/scripts/diagnose-adapter.mts +0 -81
  160. package/scripts/diagnose-assistant.mjs +0 -58
  161. package/scripts/diagnose-bible.mjs +0 -72
  162. package/scripts/diagnose-harness.mts +0 -75
  163. package/scripts/novel-forge-restart.log +0 -10
  164. package/scripts/novel-forge-web.stderr.log +0 -2
  165. package/scripts/novel-forge-web.stdout.log +0 -1
  166. package/scripts/outline-sample.txt +0 -449
  167. package/scripts/probe.mjs +0 -6
  168. package/scripts/restart-web.ps1 +0 -88
  169. package/scripts/smoke.mts +0 -72
  170. package/scripts/upload-github.ps1 +0 -51
  171. package/src/client/panel/BookshelfBar.tsx +0 -170
  172. package/src/comic-presets.ts +0 -67
@@ -1,314 +1,316 @@
1
- /**
2
- * 纯展示组件(views):所有状态与事件处理器都留在 NovelPanel,
3
- * 这里只接收 props 渲染。便于单独维护与复用。
4
- */
5
- import type { ReactElement } from 'react'
6
- import type { AuditIssue, Plotline, PlotlineHealthReport, PlotlinePlan, RoleRecord, RoleStatusCard } from '../../protocol.ts'
7
- import { tt, ROLE_LABELS, roleColor, kindLabel, plotlineStatusLabel, plotlineStatusColor } from './helpers.ts'
8
- import css from './panel.module.css'
9
-
10
- /** 统计格:状态摘要条 / 资产健康通用。 */
11
- export function StatCell(props: {
12
- label: string
13
- value: string
14
- detail: string
15
- /** 值颜色(可选)。 */
16
- valueColor?: string
17
- /** 值字号覆盖(如长文本用 13)。 */
18
- valueFontSize?: number
19
- /** detail 悬浮提示(可选)。 */
20
- detailTitle?: string
21
- }): ReactElement {
22
- return (
23
- <div className={css.assetStat}>
24
- <span className={css.assetStatLabel}>{props.label}</span>
25
- <span className={css.assetStatValue} style={{ color: props.valueColor, fontSize: props.valueFontSize }}>
26
- {props.value}
27
- </span>
28
- <span className={css.assetStatDetail} title={props.detailTitle}>{props.detail}</span>
29
- </div>
30
- )
31
- }
32
-
33
- /** 待办队列行。 */
34
- export function TodoRow(props: {
35
- tone: 'danger' | 'warning' | 'info' | 'success'
36
- title: string
37
- description: string
38
- actionLabel: string
39
- disabled: boolean
40
- onAction: () => void
41
- }): ReactElement {
42
- return (
43
- <div className={`${css.todoItem} ${props.tone === 'danger' ? css.todoDanger : props.tone === 'warning' ? css.todoWarning : css.todoInfo}`}>
44
- <span className={css.todoText}>
45
- {props.title}
46
- {props.description !== '' && <span className={css.meta}> — {props.description}</span>}
47
- </span>
48
- <button type="button" className={`${css.button} ${css.buttonSmall}`} disabled={props.disabled} onClick={props.onAction}>
49
- {props.actionLabel}
50
- </button>
51
- </div>
52
- )
53
- }
54
-
55
- /** 全书质检问题行。 */
56
- export function AuditIssueRow(props: {
57
- issue: AuditIssue
58
- disabled: boolean
59
- onFix: () => void
60
- }): ReactElement {
61
- const { issue } = props
62
- return (
63
- <div className={`${css.todoItem} ${issue.severity === 'high' ? css.todoDanger : issue.severity === 'medium' ? css.todoWarning : css.todoInfo}`}>
64
- <span className={css.todoText}>
65
- <span>
66
- {issue.chapterNo > 0 ? `第 ${issue.chapterNo} 章` : '未定位章节'} · [{issue.severity}] {issue.item}
67
- </span>
68
- {issue.suggestion !== '' && <span className={css.meta}>建议:{issue.suggestion}</span>}
69
- </span>
70
- {issue.chapterNo > 0 && (
71
- <button type="button" className={`${css.button} ${css.buttonSmall}`} disabled={props.disabled} onClick={props.onFix}>
72
- 去修订
73
- </button>
74
- )}
75
- </div>
76
- )
77
- }
78
-
79
- /** 剧情线卡片(列表主体)。 */
80
- export function PlotlineCard(props: {
81
- line: Plotline
82
- disabled: boolean
83
- onRefresh: () => void
84
- onEdit: () => void
85
- onRemove: () => void
86
- }): ReactElement {
87
- const { line } = props
88
- return (
89
- <div key={line.id} style={{ border: '1px solid var(--nf-border)', borderRadius: 10, padding: '8px 12px', fontSize: 12, display: 'flex', flexDirection: 'column', gap: 4 }}>
90
- <div className={css.row} style={{ justifyContent: 'space-between', flexWrap: 'wrap' }}>
91
- <span style={{ display: 'flex', alignItems: 'center', gap: 6, flexWrap: 'wrap' }}>
92
- <b>{line.name}</b>
93
- <span className={css.badge} style={{ borderColor: 'var(--nf-accent)', color: 'var(--nf-accent)' }}>{kindLabel(line.kind)}</span>
94
- <span className={css.badge} style={{ borderColor: plotlineStatusColor(line.status), color: plotlineStatusColor(line.status) }}>{plotlineStatusLabel(line.status)}</span>
95
- </span>
96
- <span style={{ display: 'flex', gap: 6 }}>
97
- <button
98
- type="button"
99
- className={`${css.button} ${css.buttonSmall}`}
100
- disabled={props.disabled}
101
- onClick={props.onRefresh}
102
- title="AI 结合编年录与章节摘要,自动更新这条线的当前进度"
103
- >
104
- ↻ AI 刷新进度
105
- </button>
106
- <button type="button" className={`${css.button} ${css.buttonSmall}`} disabled={props.disabled} onClick={props.onEdit}>
107
- {tt('plotlines.edit')}
108
- </button>
109
- <button type="button" className={`${css.button} ${css.buttonSmall}`} disabled={props.disabled} onClick={props.onRemove}>
110
- {tt('plotlines.remove')}
111
- </button>
112
- </span>
113
- </div>
114
- {line.goal !== '' && <div className={css.meta}><b>{tt('plotlines.goal')}:</b>{line.goal}</div>}
115
- {line.progress !== '' && <div className={css.meta}><b>{tt('plotlines.progress')}:</b>{line.progress}</div>}
116
- <div className={css.meta}>
117
- {tt('plotlines.chapters')}:{line.chapters.length > 0 ? line.chapters.map(n => `第${n}章`).join('、') : '—'}
118
- </div>
119
- </div>
120
- )
121
- }
122
-
123
- /** AI 候选角色行(提炼结果,可采纳/修改后采纳)。 */
124
- export function RoleCandidateRow(props: {
125
- candidate: RoleRecord
126
- disabled: boolean
127
- onAdopt: () => void
128
- onEdit: () => void
129
- }): ReactElement {
130
- const { candidate: r } = props
131
- const label = ROLE_LABELS[r.roleLabel] ?? r.roleLabel
132
- const color = roleColor(r.roleLabel)
133
- return (
134
- <div key={r.name} style={{ border: '1px solid var(--nf-border)', borderRadius: 8, padding: '6px 10px', fontSize: 12 }}>
135
- <div className={css.row} style={{ justifyContent: 'space-between', flexWrap: 'wrap' }}>
136
- <span style={{ display: 'flex', alignItems: 'center', gap: 6, flexWrap: 'wrap' }}>
137
- <b>{r.name}</b>
138
- <span className={css.badge} style={{ borderColor: color, color }}>{label}</span>
139
- {r.identity !== '' && <span className={css.meta}>{r.identity}</span>}
140
- </span>
141
- <span style={{ display: 'flex', gap: 6 }}>
142
- <button type="button" className={`${css.button} ${css.buttonSmall} ${css.buttonPrimary}`} disabled={props.disabled} onClick={props.onAdopt}>
143
- + 采纳
144
- </button>
145
- <button type="button" className={`${css.button} ${css.buttonSmall}`} disabled={props.disabled} onClick={props.onEdit} title="修改后再采纳(候选列表保留)">
146
- ✏️ 修改后采纳
147
- </button>
148
- </span>
149
- </div>
150
- {r.goals !== '' && <div className={css.meta}>目标:{r.goals}</div>}
151
- {r.relations.length > 0 && <div className={css.meta}>关系:{r.relations.join('、')}</div>}
152
- </div>
153
- )
154
- }
155
-
156
- /** 已收录角色卡(含从编年录刷新的当前状态行)。 */
157
- export function RoleCard(props: {
158
- role: RoleRecord
159
- status?: RoleStatusCard
160
- disabled: boolean
161
- onEdit: () => void
162
- onRemove: () => void
163
- }): ReactElement {
164
- const { role: r, status: st } = props
165
- const label = ROLE_LABELS[r.roleLabel] ?? r.roleLabel
166
- const color = roleColor(r.roleLabel)
167
- return (
168
- <div key={r.name} style={{ border: '1px solid var(--nf-border)', borderRadius: 8, padding: '6px 10px', fontSize: 12 }}>
169
- <div className={css.row} style={{ justifyContent: 'space-between', flexWrap: 'wrap' }}>
170
- <span style={{ display: 'flex', alignItems: 'center', gap: 6, flexWrap: 'wrap' }}>
171
- <b>{r.name}</b>
172
- <span className={css.badge} style={{ borderColor: color, color }}>{label}</span>
173
- {r.identity !== '' && <span className={css.meta}>{r.identity}</span>}
174
- </span>
175
- <span style={{ display: 'flex', gap: 6 }}>
176
- <button type="button" className={`${css.button} ${css.buttonSmall}`} disabled={props.disabled} onClick={props.onEdit}>编辑</button>
177
- <button type="button" className={`${css.button} ${css.buttonSmall}`} disabled={props.disabled} onClick={props.onRemove}>删除</button>
178
- </span>
179
- </div>
180
- {r.goals !== '' && <div className={css.meta}>目标:{r.goals}</div>}
181
- {st !== undefined && (
182
- <div className={css.meta} style={{ color: 'var(--nf-accent)' }}>
183
- <b>当前状态:</b>{st.status !== '' ? st.status : '(编年录暂无该角色记录)'}
184
- {' · 出场 '}{st.appearances} 次 · 最近 第 {st.lastChapter} 章
185
- </div>
186
- )}
187
- {r.relations.length > 0 && <div className={css.meta}>关系:{r.relations.join('、')}</div>}
188
- {r.arc.length > 0 && <div className={css.meta}>成长线:{r.arc.join(' → ')}</div>}
189
- {r.knowledge.length > 0 && <div className={css.meta}>知情度:{r.knowledge.join(';')}</div>}
190
- </div>
191
- )
192
- }
193
-
194
- /** 🩺 剧情健康检查报告面板。 */
195
- export function PlotlineHealthPanel(props: {
196
- report: PlotlineHealthReport
197
- disabled: boolean
198
- onPlan: () => void
199
- onClose: () => void
200
- }): ReactElement {
201
- const { report } = props
202
- return (
203
- <div style={{ display: 'flex', flexDirection: 'column', gap: 6, border: '1px solid var(--nf-info)', borderRadius: 12, padding: 10 }}>
204
- <div className={css.row} style={{ justifyContent: 'space-between', flexWrap: 'wrap' }}>
205
- <b>🩺 剧情健康检查</b>
206
- <span style={{ display: 'flex', gap: 8 }}>
207
- <button
208
- type="button"
209
- className={`${css.button} ${css.buttonSmall}`}
210
- disabled={props.disabled}
211
- onClick={props.onPlan}
212
- title="基于本次诊断生成下一阶段剧情方案"
213
- >
214
- ✨ 基于此设计方案
215
- </button>
216
- <button type="button" className={`${css.button} ${css.buttonSmall}`} onClick={props.onClose}>收起</button>
217
- </span>
218
- </div>
219
- <div style={{ fontSize: 12, fontWeight: 700, color: 'var(--nf-accent)' }}>判定:{report.verdict}</div>
220
- {report.timing !== '' && <div className={css.meta}><b>建议时机:</b>{report.timing}</div>}
221
- {report.reasons.length > 0 && (
222
- <div style={{ display: 'flex', flexDirection: 'column', gap: 2, fontSize: 12 }}>
223
- {report.reasons.map((r, i) => <div key={i} className={css.meta}>· {r}</div>)}
224
- </div>
225
- )}
226
- {report.lines.length > 0 && (
227
- <div style={{ display: 'flex', flexDirection: 'column', gap: 4, fontSize: 12 }}>
228
- {report.lines.map((l, i) => {
229
- const color = l.health === 'ok' ? 'var(--nf-success)' : l.health === 'warning' ? 'var(--nf-warn)' : 'var(--nf-error)'
230
- const label = l.health === 'ok' ? '健康' : l.health === 'warning' ? '预警' : '搁置过久'
231
- return (
232
- <div key={i} style={{ display: 'flex', gap: 8, alignItems: 'flex-start' }}>
233
- <span className={css.badge} style={{ borderColor: color, color, flex: 'none', marginTop: 1 }}>{label}</span>
234
- <span className={css.meta}><b>{l.name}</b>:{l.note}</span>
235
- </div>
236
- )
237
- })}
238
- </div>
239
- )}
240
- </div>
241
- )
242
- }
243
-
244
- /** ✨ AI 剧情方案面板。 */
245
- export function PlotlinePlanPanel(props: {
246
- plan: PlotlinePlan
247
- disabled: boolean
248
- onAdopt: (suggestion: Plotline) => void
249
- onClose: () => void
250
- }): ReactElement {
251
- const { plan } = props
252
- return (
253
- <div style={{ display: 'flex', flexDirection: 'column', gap: 6, border: '1px solid var(--nf-accent)', borderRadius: 12, padding: 10 }}>
254
- <div className={css.row} style={{ justifyContent: 'space-between', flexWrap: 'wrap' }}>
255
- <b>✨ AI 剧情方案</b>
256
- <button type="button" className={`${css.button} ${css.buttonSmall}`} onClick={props.onClose}>收起</button>
257
- </div>
258
- {plan.direction !== '' && (
259
- <div className={css.meta} style={{ fontSize: 12 }}><b>下一阶段方向:</b>{plan.direction}</div>
260
- )}
261
- {plan.suggestions.length > 0 && (
262
- <div style={{ display: 'flex', flexDirection: 'column', gap: 4, fontSize: 12 }}>
263
- {plan.suggestions.map((s, i) => (
264
- <div key={i} style={{ border: '1px solid var(--nf-border)', borderRadius: 8, padding: '6px 10px' }}>
265
- <div className={css.row} style={{ justifyContent: 'space-between', flexWrap: 'wrap' }}>
266
- <span style={{ display: 'flex', alignItems: 'center', gap: 6, flexWrap: 'wrap' }}>
267
- <b>{s.name}</b>
268
- <span className={css.badge} style={{ borderColor: 'var(--nf-accent)', color: 'var(--nf-accent)' }}>{kindLabel(s.kind)}</span>
269
- </span>
270
- <button type="button" className={`${css.button} ${css.buttonSmall} ${css.buttonPrimary}`} disabled={props.disabled} onClick={() => { props.onAdopt(s) }}>
271
- + 采纳
272
- </button>
273
- </div>
274
- {s.goal !== '' && <div className={css.meta}>{s.goal}</div>}
275
- {s.progress !== '' && <div className={css.meta}>初始进度:{s.progress}</div>}
276
- </div>
277
- ))}
278
- </div>
279
- )}
280
- </div>
281
- )
282
- }
283
-
284
- /** ✨ AI 建议剧情线面板。 */
285
- export function PlotlineSuggestionPanel(props: {
286
- suggestions: Plotline[]
287
- disabled: boolean
288
- onAdopt: (suggestion: Plotline) => void
289
- onClose: () => void
290
- }): ReactElement {
291
- return (
292
- <div style={{ display: 'flex', flexDirection: 'column', gap: 6, border: '1px solid var(--nf-info)', borderRadius: 12, padding: 10 }}>
293
- <div className={css.row} style={{ justifyContent: 'space-between', flexWrap: 'wrap' }}>
294
- <b>✨ AI 建议({props.suggestions.length} 条)</b>
295
- <button type="button" className={`${css.button} ${css.buttonSmall}`} onClick={props.onClose}>收起</button>
296
- </div>
297
- {props.suggestions.length === 0 && <span className={css.meta}>没有候选线。</span>}
298
- {props.suggestions.map((s, i) => (
299
- <div key={i} style={{ border: '1px solid var(--nf-border)', borderRadius: 8, padding: '6px 10px', fontSize: 12 }}>
300
- <div className={css.row} style={{ justifyContent: 'space-between', flexWrap: 'wrap' }}>
301
- <span style={{ display: 'flex', alignItems: 'center', gap: 6, flexWrap: 'wrap' }}>
302
- <b>{s.name}</b>
303
- <span className={css.badge} style={{ borderColor: 'var(--nf-accent)', color: 'var(--nf-accent)' }}>{kindLabel(s.kind)}</span>
304
- </span>
305
- <button type="button" className={`${css.button} ${css.buttonSmall} ${css.buttonPrimary}`} disabled={props.disabled} onClick={() => { props.onAdopt(s) }}>
306
- + 采纳
307
- </button>
308
- </div>
309
- {s.goal !== '' && <div className={css.meta}>{s.goal}</div>}
310
- </div>
311
- ))}
312
- </div>
313
- )
314
- }
1
+ /**
2
+ * 纯展示组件(views):所有状态与事件处理器都留在 NovelPanel,
3
+ * 这里只接收 props 渲染。便于单独维护与复用。
4
+ */
5
+ import { useCallback, useEffect, useRef, useState } from 'react'
6
+ import type { ReactElement } from 'react'
7
+ import type { Plotline, PlotlineHealthReport, PlotlinePlan, RoleRecord, RoleStatusCard } from '../../protocol.ts'
8
+ import { tt, ROLE_LABELS, roleColor, kindLabel, plotlineStatusLabel, plotlineStatusColor } from './helpers.ts'
9
+ import css from './panel.module.css'
10
+
11
+ /** 滑轨胶囊导航(B5-5):active 高亮为滑动指示块,随选中项平移。 */
12
+ export function SlideNav<T extends string>(props: {
13
+ ariaLabel: string
14
+ items: ReadonlyArray<{ id: T; label: ReactElement | string }>
15
+ active: T
16
+ onSelect: (id: T) => void
17
+ }): JSX.Element {
18
+ const { ariaLabel, items, active, onSelect } = props
19
+ const ref = useRef<HTMLDivElement | null>(null)
20
+ const [slider, setSlider] = useState<{ left: number; width: number } | null>(null)
21
+ const update = useCallback(() => {
22
+ const el = ref.current
23
+ if (el === null) return
24
+ const btn = el.querySelector<HTMLButtonElement>('button[data-active=""]')
25
+ if (btn === null) { setSlider(null); return }
26
+ const left = btn.offsetLeft
27
+ const width = btn.offsetWidth
28
+ setSlider(prev => (prev !== null && prev.left === left && prev.width === width ? prev : { left, width }))
29
+ }, [])
30
+ // 每次渲染后测量(set 前做等值比较,不会引发循环)。
31
+ useEffect(() => { update() })
32
+ useEffect(() => {
33
+ const el = ref.current
34
+ if (el === null) return
35
+ const ro = new ResizeObserver(() => { update() })
36
+ ro.observe(el)
37
+ return () => { ro.disconnect() }
38
+ }, [update])
39
+ return (
40
+ <div ref={ref} className={`${css.pillNav} ${css.pillNavSliding}`} role="tablist" aria-label={ariaLabel}>
41
+ {slider !== null && (
42
+ <span
43
+ className={css.pillNavSlider}
44
+ style={{ transform: `translateX(${slider.left}px)`, width: `${slider.width}px` }}
45
+ aria-hidden
46
+ />
47
+ )}
48
+ {items.map(it => (
49
+ <button
50
+ key={it.id}
51
+ type="button"
52
+ role="tab"
53
+ aria-selected={active === it.id}
54
+ data-active={active === it.id ? '' : undefined}
55
+ className={css.pillNavPill}
56
+ onClick={() => { onSelect(it.id) }}
57
+ >
58
+ {it.label}
59
+ </button>
60
+ ))}
61
+ </div>
62
+ )
63
+ }
64
+
65
+ /** 剧情线卡片(列表主体)。 */
66
+ export function PlotlineCard(props: {
67
+ line: Plotline
68
+ disabled: boolean
69
+ onRefresh: () => void
70
+ onEdit: () => void
71
+ onRemove: () => void
72
+ }): ReactElement {
73
+ const { line } = props
74
+ return (
75
+ <div key={line.id} style={{ border: '1px solid var(--nf-border)', borderRadius: 'var(--nf-radius-10)', padding: 'var(--nf-space-8) var(--nf-space-12)', fontSize: 'var(--nf-fs-12)', display: 'flex', flexDirection: 'column', gap: 'var(--nf-space-4)' }}>
76
+ <div className={css.row} style={{ justifyContent: 'space-between', flexWrap: 'wrap' }}>
77
+ <span style={{ display: 'flex', alignItems: 'center', gap: 'var(--nf-space-6)', flexWrap: 'wrap' }}>
78
+ <b>{line.name}</b>
79
+ <span className={css.badge} style={{ borderColor: 'var(--nf-accent)', color: 'var(--nf-accent)' }}>{kindLabel(line.kind)}</span>
80
+ <span className={css.badge} style={{ borderColor: plotlineStatusColor(line.status), color: plotlineStatusColor(line.status) }}>{plotlineStatusLabel(line.status)}</span>
81
+ </span>
82
+ <span style={{ display: 'flex', gap: 'var(--nf-space-6)' }}>
83
+ <button
84
+ type="button"
85
+ className={`${css.button} ${css.buttonSmall}`}
86
+ disabled={props.disabled}
87
+ onClick={props.onRefresh}
88
+ title="AI 结合编年录与章节摘要,自动更新这条线的当前进度"
89
+ >
90
+ ↻ 刷新进度
91
+ </button>
92
+ <button type="button" className={`${css.button} ${css.buttonSmall}`} disabled={props.disabled} onClick={props.onEdit}>
93
+ {tt('plotlines.edit')}
94
+ </button>
95
+ <button type="button" className={`${css.button} ${css.buttonSmall}`} disabled={props.disabled} onClick={props.onRemove}>
96
+ {tt('plotlines.remove')}
97
+ </button>
98
+ </span>
99
+ </div>
100
+ {line.goal !== '' && <div className={css.meta}><b>{tt('plotlines.goal')}:</b>{line.goal}</div>}
101
+ {line.progress !== '' && <div className={css.meta}><b>{tt('plotlines.progress')}:</b>{line.progress}</div>}
102
+ <div className={css.meta}>
103
+ {tt('plotlines.chapters')}:{line.chapters.length > 0 ? line.chapters.map(n => `第${n}章`).join('、') : '—'}
104
+ </div>
105
+ </div>
106
+ )
107
+ }
108
+
109
+ /** AI 候选角色行(提炼结果,可采纳/修改后采纳)。 */
110
+ export function RoleCandidateRow(props: {
111
+ candidate: RoleRecord
112
+ disabled: boolean
113
+ onAdopt: () => void
114
+ onEdit: () => void
115
+ }): ReactElement {
116
+ const { candidate: r } = props
117
+ const label = ROLE_LABELS[r.roleLabel] ?? r.roleLabel
118
+ const color = roleColor(r.roleLabel)
119
+ return (
120
+ <div key={r.name} style={{ border: '1px solid var(--nf-border)', borderRadius: 'var(--nf-radius-8)', padding: 'var(--nf-space-6) var(--nf-space-10)', fontSize: 'var(--nf-fs-12)' }}>
121
+ <div className={css.row} style={{ justifyContent: 'space-between', flexWrap: 'wrap' }}>
122
+ <span style={{ display: 'flex', alignItems: 'center', gap: 'var(--nf-space-6)', flexWrap: 'wrap' }}>
123
+ <b>{r.name}</b>
124
+ <span className={css.badge} style={{ borderColor: color, color }}>{label}</span>
125
+ {r.identity !== '' && <span className={css.meta}>{r.identity}</span>}
126
+ </span>
127
+ <span style={{ display: 'flex', gap: 'var(--nf-space-6)' }}>
128
+ <button type="button" className={`${css.button} ${css.buttonSmall} ${css.buttonPrimary}`} disabled={props.disabled} onClick={props.onAdopt}>
129
+ + 采纳
130
+ </button>
131
+ <button type="button" className={`${css.button} ${css.buttonSmall}`} disabled={props.disabled} onClick={props.onEdit} title="修改后再采纳(候选列表保留)">
132
+ 修改后采纳
133
+ </button>
134
+ </span>
135
+ </div>
136
+ {r.goals !== '' && <div className={css.meta}>目标:{r.goals}</div>}
137
+ {r.relations.length > 0 && <div className={css.meta}>关系:{r.relations.join('、')}</div>}
138
+ </div>
139
+ )
140
+ }
141
+
142
+ /** 已收录角色卡(含从编年录刷新的当前状态行)。 */
143
+ export function RoleCard(props: {
144
+ role: RoleRecord
145
+ status?: RoleStatusCard
146
+ disabled: boolean
147
+ onEdit: () => void
148
+ onRemove: () => void
149
+ }): ReactElement {
150
+ const { role: r, status: st } = props
151
+ const label = ROLE_LABELS[r.roleLabel] ?? r.roleLabel
152
+ const color = roleColor(r.roleLabel)
153
+ return (
154
+ <div key={r.name} style={{ border: '1px solid var(--nf-border)', borderRadius: 'var(--nf-radius-8)', padding: 'var(--nf-space-6) var(--nf-space-10)', fontSize: 'var(--nf-fs-12)' }}>
155
+ <div className={css.row} style={{ justifyContent: 'space-between', flexWrap: 'wrap' }}>
156
+ <span style={{ display: 'flex', alignItems: 'center', gap: 'var(--nf-space-6)', flexWrap: 'wrap' }}>
157
+ <b>{r.name}</b>
158
+ <span className={css.badge} style={{ borderColor: color, color }}>{label}</span>
159
+ {r.identity !== '' && <span className={css.meta}>{r.identity}</span>}
160
+ </span>
161
+ <span style={{ display: 'flex', gap: 'var(--nf-space-6)' }}>
162
+ <button type="button" className={`${css.button} ${css.buttonSmall}`} disabled={props.disabled} onClick={props.onEdit}>编辑</button>
163
+ <button type="button" className={`${css.button} ${css.buttonSmall}`} disabled={props.disabled} onClick={props.onRemove}>删除</button>
164
+ </span>
165
+ </div>
166
+ {r.goals !== '' && <div className={css.meta}>目标:{r.goals}</div>}
167
+ {st !== undefined && (
168
+ <div className={css.meta} style={{ color: 'var(--nf-accent)' }}>
169
+ <b>当前状态:</b>{st.status !== '' ? st.status : '(编年录暂无该角色记录)'}
170
+ {' · 出场 '}{st.appearances} 次 · 最近 第 {st.lastChapter} 章
171
+ </div>
172
+ )}
173
+ {r.relations.length > 0 && <div className={css.meta}>关系:{r.relations.join('、')}</div>}
174
+ {r.arc.length > 0 && <div className={css.meta}>成长线:{r.arc.join(' → ')}</div>}
175
+ {r.knowledge.length > 0 && <div className={css.meta}>知情度:{r.knowledge.join(';')}</div>}
176
+ </div>
177
+ )
178
+ }
179
+
180
+ /** 剧情健康检查报告面板。 */
181
+ export function PlotlineHealthPanel(props: {
182
+ report: PlotlineHealthReport
183
+ disabled: boolean
184
+ onPlan: () => void
185
+ onClose: () => void
186
+ }): ReactElement {
187
+ const { report } = props
188
+ return (
189
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 'var(--nf-space-6)', border: '1px solid var(--nf-info)', borderRadius: 'var(--nf-radius-12)', padding: 'var(--nf-space-10)' }}>
190
+ <div className={css.row} style={{ justifyContent: 'space-between', flexWrap: 'wrap' }}>
191
+ <b> 剧情健康检查</b>
192
+ <span style={{ display: 'flex', gap: 'var(--nf-space-8)' }}>
193
+ <button
194
+ type="button"
195
+ className={`${css.button} ${css.buttonSmall}`}
196
+ disabled={props.disabled}
197
+ onClick={props.onPlan}
198
+ title="基于本次诊断生成下一阶段剧情方案"
199
+ >
200
+ 基于此设计方案
201
+ </button>
202
+ <button type="button" className={`${css.button} ${css.buttonSmall}`} onClick={props.onClose}>收起</button>
203
+ </span>
204
+ </div>
205
+ <div style={{ fontSize: 'var(--nf-fs-12)', fontWeight: 700, color: 'var(--nf-accent)' }}>判定:{report.verdict}</div>
206
+ {report.timing !== '' && <div className={css.meta}><b>建议时机:</b>{report.timing}</div>}
207
+ {report.reasons.length > 0 && (
208
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 'var(--nf-space-2)', fontSize: 'var(--nf-fs-12)' }}>
209
+ {report.reasons.map((r, i) => <div key={i} className={css.meta}>· {r}</div>)}
210
+ </div>
211
+ )}
212
+ {report.lines.length > 0 && (
213
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 'var(--nf-space-4)', fontSize: 'var(--nf-fs-12)' }}>
214
+ {report.lines.map((l, i) => {
215
+ const color = l.health === 'ok' ? 'var(--nf-success)' : l.health === 'warning' ? 'var(--nf-warn)' : 'var(--nf-error)'
216
+ const label = l.health === 'ok' ? '健康' : l.health === 'warning' ? '预警' : '搁置过久'
217
+ return (
218
+ <div key={i} style={{ display: 'flex', gap: 'var(--nf-space-8)', alignItems: 'flex-start' }}>
219
+ <span className={css.badge} style={{ borderColor: color, color, flex: 'none', marginTop: 'var(--nf-space-2)' }}>{label}</span>
220
+ <span className={css.meta}><b>{l.name}</b>:{l.note}</span>
221
+ </div>
222
+ )
223
+ })}
224
+ </div>
225
+ )}
226
+ </div>
227
+ )
228
+ }
229
+
230
+ /** 剧情方案面板。 */
231
+ export function PlotlinePlanPanel(props: {
232
+ plan: PlotlinePlan
233
+ disabled: boolean
234
+ onAdopt: (suggestion: Plotline) => void
235
+ onClose: () => void
236
+ }): ReactElement {
237
+ const { plan } = props
238
+ return (
239
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 'var(--nf-space-6)', border: '1px solid var(--nf-accent)', borderRadius: 'var(--nf-radius-12)', padding: 'var(--nf-space-10)' }}>
240
+ <div className={css.row} style={{ justifyContent: 'space-between', flexWrap: 'wrap' }}>
241
+ <b> 剧情方案</b>
242
+ <button type="button" className={`${css.button} ${css.buttonSmall}`} onClick={props.onClose}>收起</button>
243
+ </div>
244
+ {plan.direction !== '' && (
245
+ <div className={css.meta} style={{ fontSize: 'var(--nf-fs-12)' }}><b>下一阶段方向:</b>{plan.direction}</div>
246
+ )}
247
+ {plan.suggestions.length > 0 && (
248
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 'var(--nf-space-4)', fontSize: 'var(--nf-fs-12)' }}>
249
+ {plan.suggestions.map((s, i) => (
250
+ <div key={i} style={{ border: '1px solid var(--nf-border)', borderRadius: 'var(--nf-radius-8)', padding: 'var(--nf-space-6) var(--nf-space-10)' }}>
251
+ <div className={css.row} style={{ justifyContent: 'space-between', flexWrap: 'wrap' }}>
252
+ <span style={{ display: 'flex', alignItems: 'center', gap: 'var(--nf-space-6)', flexWrap: 'wrap' }}>
253
+ <b>{s.name}</b>
254
+ <span className={css.badge} style={{ borderColor: 'var(--nf-accent)', color: 'var(--nf-accent)' }}>{kindLabel(s.kind)}</span>
255
+ </span>
256
+ <button type="button" className={`${css.button} ${css.buttonSmall} ${css.buttonPrimary}`} disabled={props.disabled} onClick={() => { props.onAdopt(s) }}>
257
+ + 采纳
258
+ </button>
259
+ </div>
260
+ {s.goal !== '' && <div className={css.meta}>{s.goal}</div>}
261
+ {s.progress !== '' && <div className={css.meta}>初始进度:{s.progress}</div>}
262
+ </div>
263
+ ))}
264
+ </div>
265
+ )}
266
+ </div>
267
+ )
268
+ }
269
+
270
+ /** 建议剧情线面板。 */
271
+ export function PlotlineSuggestionPanel(props: {
272
+ suggestions: Plotline[]
273
+ disabled: boolean
274
+ onAdopt: (suggestion: Plotline) => void
275
+ onClose: () => void
276
+ }): ReactElement {
277
+ return (
278
+ <div style={{ display: 'flex', flexDirection: 'column', gap: 'var(--nf-space-6)', border: '1px solid var(--nf-info)', borderRadius: 'var(--nf-radius-12)', padding: 'var(--nf-space-10)' }}>
279
+ <div className={css.row} style={{ justifyContent: 'space-between', flexWrap: 'wrap' }}>
280
+ <b> 建议({props.suggestions.length} 条)</b>
281
+ <button type="button" className={`${css.button} ${css.buttonSmall}`} onClick={props.onClose}>收起</button>
282
+ </div>
283
+ {props.suggestions.length === 0 && <span className={css.meta}>没有候选线。</span>}
284
+ {props.suggestions.map((s, i) => (
285
+ <div key={i} style={{ border: '1px solid var(--nf-border)', borderRadius: 'var(--nf-radius-8)', padding: 'var(--nf-space-6) var(--nf-space-10)', fontSize: 'var(--nf-fs-12)' }}>
286
+ <div className={css.row} style={{ justifyContent: 'space-between', flexWrap: 'wrap' }}>
287
+ <span style={{ display: 'flex', alignItems: 'center', gap: 'var(--nf-space-6)', flexWrap: 'wrap' }}>
288
+ <b>{s.name}</b>
289
+ <span className={css.badge} style={{ borderColor: 'var(--nf-accent)', color: 'var(--nf-accent)' }}>{kindLabel(s.kind)}</span>
290
+ </span>
291
+ <button type="button" className={`${css.button} ${css.buttonSmall} ${css.buttonPrimary}`} disabled={props.disabled} onClick={() => { props.onAdopt(s) }}>
292
+ + 采纳
293
+ </button>
294
+ </div>
295
+ {s.goal !== '' && <div className={css.meta}>{s.goal}</div>}
296
+ </div>
297
+ ))}
298
+ </div>
299
+ )
300
+ }
301
+
302
+ /** 空状态基元:图标 + 标题 + 可选提示。compact 变体用于列表/卡片内嵌场景。 */
303
+ export function EmptyState(props: {
304
+ icon?: string
305
+ title: string
306
+ hint?: string
307
+ compact?: boolean
308
+ }): ReactElement {
309
+ return (
310
+ <div className={css.emptyState} data-compact={props.compact === true ? 'true' : undefined}>
311
+ {props.icon !== undefined && <span className={css.emptyStateIcon}>{props.icon}</span>}
312
+ <span className={css.emptyStateTitle}>{props.title}</span>
313
+ {props.hint !== undefined && <span className={css.emptyStateHint}>{props.hint}</span>}
314
+ </div>
315
+ )
316
+ }