@waterwx/dsh-novel-forge 2.0.1-alpha → 2.1.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 (183) hide show
  1. package/README.md +368 -362
  2. package/lib/client.js +20340 -19622
  3. package/lib/index.js +11313 -7285
  4. package/lib/types/action-guard.d.ts +61 -0
  5. package/lib/types/ai-scan.d.ts +0 -6
  6. package/lib/types/assets.d.ts +20 -9
  7. package/lib/types/assistant.d.ts +29 -0
  8. package/lib/types/author-assets.d.ts +1 -3
  9. package/lib/types/bookshelf.d.ts +13 -3
  10. package/lib/types/client/api.d.ts +136 -27
  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/llmLive.d.ts +31 -0
  14. package/lib/types/client/locales.d.ts +15 -70
  15. package/lib/types/client/mount.d.ts +0 -2
  16. package/lib/types/client/panel/AiTag.d.ts +1 -0
  17. package/lib/types/client/panel/AssistantTab.d.ts +4 -1
  18. package/lib/types/client/panel/AuthorHome.d.ts +13 -11
  19. package/lib/types/client/panel/BookAnalysisView.d.ts +4 -0
  20. package/lib/types/client/panel/CmdPalette.d.ts +12 -0
  21. package/lib/types/client/panel/CreateBookView.d.ts +5 -1
  22. package/lib/types/client/panel/DirectorView.d.ts +7 -0
  23. package/lib/types/client/panel/IdeaInspirationView.d.ts +6 -0
  24. package/lib/types/client/panel/KnowledgeBaseView.d.ts +4 -0
  25. package/lib/types/client/panel/LiveFeedLog.d.ts +13 -0
  26. package/lib/types/client/panel/MarketRadarView.d.ts +5 -0
  27. package/lib/types/client/panel/ModelManager.d.ts +2 -2
  28. package/lib/types/client/panel/NovelPanel.d.ts +6 -1
  29. package/lib/types/client/panel/PageHeader.d.ts +18 -0
  30. package/lib/types/client/panel/PromptSlotsView.d.ts +11 -0
  31. package/lib/types/client/panel/SettingsView.d.ts +12 -9
  32. package/lib/types/client/panel/ShelfView.d.ts +10 -1
  33. package/lib/types/client/panel/SubPage.d.ts +27 -0
  34. package/lib/types/client/panel/TensionView.d.ts +18 -0
  35. package/lib/types/client/panel/TimelineView.d.ts +18 -0
  36. package/lib/types/client/panel/helpers.d.ts +5 -3
  37. package/lib/types/client/panel/market-radar-state.d.ts +56 -0
  38. package/lib/types/client/panel/outline-markdown.d.ts +112 -0
  39. package/lib/types/client/panel/status-badge.d.ts +13 -0
  40. package/lib/types/client/panel/storage-parse.d.ts +46 -0
  41. package/lib/types/client/panel/toast.d.ts +2 -0
  42. package/lib/types/client/panel/usePersistentState.d.ts +17 -0
  43. package/lib/types/client/panel/views.d.ts +21 -35
  44. package/lib/types/client/run-status.d.ts +21 -0
  45. package/lib/types/client/sidebar-entry.d.ts +0 -2
  46. package/lib/types/digest-parse.d.ts +29 -0
  47. package/lib/types/docx-core.d.ts +16 -0
  48. package/lib/types/docx.d.ts +2 -3
  49. package/lib/types/engine.d.ts +150 -103
  50. package/lib/types/global-assets.d.ts +6 -0
  51. package/lib/types/home.d.ts +11 -0
  52. package/lib/types/index.d.ts +26 -12
  53. package/lib/types/llm-live.d.ts +70 -0
  54. package/lib/types/llm-retry.d.ts +38 -0
  55. package/lib/types/market-radar-scan.d.ts +18 -0
  56. package/lib/types/market-radar-sources.d.ts +31 -0
  57. package/lib/types/migrate-output.d.ts +25 -0
  58. package/lib/types/model-capability.d.ts +119 -0
  59. package/lib/types/model-request.d.ts +36 -0
  60. package/lib/types/output-budget.d.ts +86 -0
  61. package/lib/types/plotline-align.d.ts +35 -0
  62. package/lib/types/prompt-slots.d.ts +57 -0
  63. package/lib/types/prompting.d.ts +10 -0
  64. package/lib/types/protocol.d.ts +841 -601
  65. package/lib/types/revision.d.ts +76 -0
  66. package/lib/types/routes.d.ts +9 -3
  67. package/lib/types/run-selection.d.ts +51 -0
  68. package/lib/types/run.d.ts +32 -1
  69. package/lib/types/settings-persist.d.ts +59 -0
  70. package/lib/types/snapshots.d.ts +46 -0
  71. package/lib/types/stage-contract.d.ts +58 -0
  72. package/lib/types/stream-fallback.d.ts +60 -0
  73. package/lib/types/strip-headings.d.ts +33 -0
  74. package/lib/types/tension.d.ts +53 -0
  75. package/lib/types/timeline.d.ts +37 -0
  76. package/package.json +50 -27
  77. package/assets/styles/arcane-thick-3d.webp +0 -0
  78. package/assets/styles/chinese-ink.webp +0 -0
  79. package/assets/styles/clay-stopmotion-3d.webp +0 -0
  80. package/assets/styles/dark-ghibli.webp +0 -0
  81. package/assets/styles/dark-gothic-3d.webp +0 -0
  82. package/assets/styles/film-photo.webp +0 -0
  83. package/assets/styles/guofeng-heavy.webp +0 -0
  84. package/assets/styles/guoman-2d-gufeng.webp +0 -0
  85. package/assets/styles/guoman-3d-tianyuan.webp +0 -0
  86. package/assets/styles/guoman-3d-xuanhuan.webp +0 -0
  87. package/assets/styles/horror-game-3d.webp +0 -0
  88. package/assets/styles/hyperreal-3d.webp +0 -0
  89. package/assets/styles/japan-cel-dark.webp +0 -0
  90. package/assets/styles/korean-webtoon.webp +0 -0
  91. package/assets/styles/low-cyberpunk-3d.webp +0 -0
  92. package/assets/styles/nextgen-cg.webp +0 -0
  93. package/assets/styles/noir-film.webp +0 -0
  94. package/assets/styles/openworld-survival.webp +0 -0
  95. package/assets/styles/paper-cut-3d.webp +0 -0
  96. package/assets/styles/pixar-adult-3d.webp +0 -0
  97. package/assets/styles/pop-marvel-2d.webp +0 -0
  98. package/assets/styles/sandiao-qban.webp +0 -0
  99. package/assets/styles/shinkai-anime.webp +0 -0
  100. package/assets/styles/tactical-stealth.webp +0 -0
  101. package/assets/styles/urban-lightreal-3d.webp +0 -0
  102. package/assets/styles/vaporwave-3d.webp +0 -0
  103. package/assets/styles/vhs90.webp +0 -0
  104. package/lib/types/client/panel/BookshelfBar.d.ts +0 -11
  105. package/lib/types/client/panel/FlowGuide.d.ts +0 -22
  106. package/lib/types/client/panel/MangaRoleLibrary.d.ts +0 -20
  107. package/lib/types/client/panel/MangaWorkspace.d.ts +0 -12
  108. package/lib/types/client/panel/ModelPicker.d.ts +0 -11
  109. package/lib/types/client/panel/ProgressHomeView.d.ts +0 -5
  110. package/lib/types/client/panel/PropLibrary.d.ts +0 -8
  111. package/lib/types/client/panel/SceneLibrary.d.ts +0 -16
  112. package/lib/types/client/panel/StoryboardTab.d.ts +0 -19
  113. package/lib/types/client/panel/StyleCard.d.ts +0 -8
  114. package/lib/types/client/panel/StyleGallery.d.ts +0 -1
  115. package/lib/types/comic-presets.d.ts +0 -12
  116. package/lib/types/manga-genre-rules.d.ts +0 -22
  117. package/lib/types/prompt-utils.d.ts +0 -35
  118. package/lib/types/review-policy.d.ts +0 -97
  119. package/lib/types/shot-language.d.ts +0 -46
  120. package/lib/types/story-beat-language.d.ts +0 -35
  121. package/lib/types/style-library.d.ts +0 -33
  122. package/skills/chapter-batch/SKILL.md +0 -81
  123. package/src/ai-scan.ts +0 -179
  124. package/src/assets.ts +0 -879
  125. package/src/assistant.ts +0 -770
  126. package/src/author-assets.ts +0 -147
  127. package/src/bookshelf.ts +0 -167
  128. package/src/client/api.ts +0 -617
  129. package/src/client/css-modules.d.ts +0 -8
  130. package/src/client/docx.ts +0 -69
  131. package/src/client/index.ts +0 -34
  132. package/src/client/locales.ts +0 -418
  133. package/src/client/mount.tsx +0 -97
  134. package/src/client/mount.tsx._new +0 -97
  135. package/src/client/mount.tsx._nf +0 -97
  136. package/src/client/mount.tsx._tmp +0 -97
  137. package/src/client/panel/AdaptModeView.tsx +0 -520
  138. package/src/client/panel/AssetsTab.tsx +0 -458
  139. package/src/client/panel/AssistantTab.tsx +0 -301
  140. package/src/client/panel/AuthorAssetsView.tsx +0 -208
  141. package/src/client/panel/AuthorHome.tsx +0 -204
  142. package/src/client/panel/BookshelfBar.tsx +0 -170
  143. package/src/client/panel/CreateBookView.tsx +0 -352
  144. package/src/client/panel/FlowGuide.tsx +0 -84
  145. package/src/client/panel/GlobalAssetLibraryView.tsx +0 -172
  146. package/src/client/panel/ImportModal.tsx +0 -303
  147. package/src/client/panel/MangaRoleLibrary.tsx +0 -1002
  148. package/src/client/panel/MangaWorkspace.tsx +0 -715
  149. package/src/client/panel/ModelManager.tsx +0 -205
  150. package/src/client/panel/NovelPanel.tsx +0 -4620
  151. package/src/client/panel/ProgressConsole.tsx +0 -64
  152. package/src/client/panel/ProgressHomeView.tsx +0 -87
  153. package/src/client/panel/PropLibrary.tsx +0 -175
  154. package/src/client/panel/ReaderView.tsx +0 -306
  155. package/src/client/panel/ReasoningSection.tsx +0 -31
  156. package/src/client/panel/RunPanel.tsx +0 -204
  157. package/src/client/panel/SceneLibrary.tsx +0 -453
  158. package/src/client/panel/SettingsView.tsx +0 -286
  159. package/src/client/panel/ShelfView.tsx +0 -242
  160. package/src/client/panel/StoryboardTab.tsx +0 -472
  161. package/src/client/panel/StyleCard.tsx +0 -90
  162. package/src/client/panel/StyleGallery.tsx +0 -58
  163. package/src/client/panel/WorldTab.tsx +0 -202
  164. package/src/client/panel/controller.ts +0 -45
  165. package/src/client/panel/helpers.ts +0 -67
  166. package/src/client/panel/panel.module.css +0 -4360
  167. package/src/client/panel/views.tsx +0 -314
  168. package/src/client/sidebar-entry.ts +0 -122
  169. package/src/client/text.ts +0 -28
  170. package/src/comic-presets.ts +0 -67
  171. package/src/docx.ts +0 -83
  172. package/src/engine.ts +0 -5200
  173. package/src/index.ts +0 -329
  174. package/src/manga-genre-rules.ts +0 -87
  175. package/src/novel-context.ts +0 -287
  176. package/src/prompt-utils.ts +0 -73
  177. package/src/protocol.ts +0 -2233
  178. package/src/review-policy.ts +0 -161
  179. package/src/routes.ts +0 -3419
  180. package/src/run.ts +0 -331
  181. package/src/shot-language.ts +0 -181
  182. package/src/story-beat-language.ts +0 -130
  183. package/src/style-library.ts +0 -84
@@ -1,204 +0,0 @@
1
- /**
2
- * 作者级首页容器:书架页左侧导航 + 内容区。
3
- * 导航复用工作区 .panelNav 玻璃卡片样式(同款),导航项为作者级:书架/改编/资产库/全局资产库/AI 进度/设置。
4
- */
5
- import { useState, useRef, useEffect } from 'react'
6
- import { Library, Wand2, Boxes, Brush, BarChart3, Settings } from 'lucide-react'
7
- import type { NovelApi } from '../api.ts'
8
- import type { BookshelfSnapshot } from '../../protocol.ts'
9
- import { ShelfView } from './ShelfView.tsx'
10
- import { AdaptModeView } from './AdaptModeView.tsx'
11
- import { AuthorAssetsView } from './AuthorAssetsView.tsx'
12
- import { GlobalAssetLibraryView } from './GlobalAssetLibraryView.tsx'
13
- import { ProgressConsole, type ProgressLine } from './ProgressConsole.tsx'
14
- import { SettingsView } from './SettingsView.tsx'
15
- import css from './panel.module.css'
16
-
17
- /** 构建时注入的插件版本(tsdown define 替换为字符串字面量)。 */
18
- declare const __NOVEL_FORGE_VERSION__: string | undefined
19
- const PLUGIN_VERSION: string = typeof __NOVEL_FORGE_VERSION__ !== 'undefined' ? __NOVEL_FORGE_VERSION__ : '0.0.0'
20
- /** GitHub 仓库地址(关于区块点击跳转)。 */
21
- const REPO_URL = 'https://github.com/watersxya/dsh-novel-forge'
22
-
23
- type AuthorNav = 'shelf' | 'adapt' | 'assets' | 'library' | 'progress' | 'settings';
24
-
25
- const NAV_ITEMS: Array<{ id: Exclude<AuthorNav, 'settings'>; label: string; icon: JSX.Element; hint: string }> = [
26
- { id: 'shelf', label: '书架', icon: <Library size={18} />, hint: '我的书' },
27
- { id: 'adapt', label: '改编模式', icon: <Wand2 size={18} />, hint: '上传全文→可改范围' },
28
- { id: 'assets', label: '作者资产库', icon: <Boxes size={18} />, hint: '跨书总数据' },
29
- { id: 'library', label: '全局写作资产库', icon: <Brush size={18} />, hint: '内置题材/规则/模板' },
30
- { id: 'progress', label: 'AI 进度', icon: <BarChart3 size={18} />, hint: '书架级聚合进度' },
31
- ];
32
-
33
-
34
- export function AuthorHome({ api, shelf, onOpenBook, onReadBook, onAddBook, onImportBook, onOpenSettings, onTheme, onBackground, onOpacity, onEndfieldAccent, adaptEnabled, progress, busy, busyLabel, liveBar, onClearProgress }: {
35
- api: NovelApi; shelf: BookshelfSnapshot;
36
- onOpenBook: (id: string) => void; onReadBook: (id: string) => void; onAddBook: () => void; onImportBook: () => void;
37
- /** 兼容旧入口:首页设置现为独立设置页,此回调保留但不再使用。 */
38
- onOpenSettings?: () => void;
39
- /** 主题/模式/密度变化回调(供面板根容器实时生效)。 */
40
- onTheme?: (theme: 'liquid' | 'neumorph' | 'macos' | 'clay' | 'endfield', mode: 'system' | 'light' | 'dark', density: 'comfort' | 'compact' | 'spacious') => void;
41
- /** 自定义背景变化回调。 */
42
- onBackground?: (bg: string | undefined, blur: number) => void;
43
- /** 玻璃透明度变化回调。 */
44
- onOpacity?: (n: number) => void;
45
- /** 终末地强调色变化回调。 */
46
- onEndfieldAccent?: (accent: 'valley' | 'wuling') => void;
47
- /** 是否启用改编模式(默认 false=隐藏入口)。 */
48
- adaptEnabled?: boolean;
49
- /** AI 进度实时状态(与书内共享同一份)。 */
50
- progress?: ProgressLine[];
51
- busy?: boolean;
52
- busyLabel?: string;
53
- liveBar?: { text: string; ratio?: number } | null;
54
- onClearProgress?: () => void;
55
- }) {
56
- const [nav, setNav] = useState<AuthorNav>('shelf');
57
- const [updating, setUpdating] = useState(false);
58
- const [progressOpen, setProgressOpen] = useState(false);
59
- const [progressPos, setProgressPos] = useState(() => {
60
- try {
61
- const raw = window.localStorage.getItem('dsh-novel-forge.home.progress.float')
62
- if (raw !== null) { const p = JSON.parse(raw) as { x?: unknown; y?: unknown }; return { x: typeof p.x === 'number' ? p.x : 60, y: typeof p.y === 'number' ? p.y : 120 } }
63
- } catch { /* ignore */ }
64
- return { x: 60, y: 120 }
65
- });
66
- const [progressSize, setProgressSize] = useState(() => {
67
- try {
68
- const raw = window.localStorage.getItem('dsh-novel-forge.home.progress.size')
69
- if (raw !== null) { const p = JSON.parse(raw) as { w?: unknown; h?: unknown }; return { w: typeof p.w === 'number' ? p.w : 460, h: typeof p.h === 'number' ? p.h : 420 } }
70
- } catch { /* ignore */ }
71
- return { w: 460, h: 420 }
72
- });
73
- const dragState = useRef<{ type: 'move' | 'resize'; startX: number; startY: number; origX: number; origY: number; origW: number; origH: number } | null>(null);
74
-
75
- useEffect(() => {
76
- try {
77
- window.localStorage.setItem('dsh-novel-forge.home.progress.float', JSON.stringify(progressPos))
78
- window.localStorage.setItem('dsh-novel-forge.home.progress.size', JSON.stringify(progressSize))
79
- } catch { /* ignore */ }
80
- }, [progressPos, progressSize]);
81
-
82
- useEffect(() => {
83
- const onMove = (e: MouseEvent): void => {
84
- const s = dragState.current
85
- if (s === null) return
86
- if (s.type === 'move') {
87
- setProgressPos({ x: Math.max(-340, Math.min(s.origX + e.clientX - s.startX, 3000)), y: Math.max(0, Math.min(s.origY + e.clientY - s.startY, 3000)) })
88
- } else {
89
- setProgressSize({ w: Math.max(320, Math.min(s.origW + e.clientX - s.startX, 1400)), h: Math.max(220, Math.min(s.origH + e.clientY - s.startY, 1200)) })
90
- }
91
- }
92
- const onUp = (): void => { dragState.current = null }
93
- window.addEventListener('mousemove', onMove)
94
- window.addEventListener('mouseup', onUp)
95
- return () => { window.removeEventListener('mousemove', onMove); window.removeEventListener('mouseup', onUp) }
96
- }, []);
97
-
98
- /** npm 最新版本(更新检测;null = 未检测/检测失败)。 */
99
- const [npmLatest, setNpmLatest] = useState<string | null>(null)
100
- useEffect(() => {
101
- let cancelled = false
102
- void (async () => {
103
- try {
104
- const r = await fetch('https://registry.npmjs.org/@waterwx%2Fdsh-novel-forge/latest')
105
- if (!r.ok) return
106
- const data = (await r.json()) as { version?: unknown }
107
- if (!cancelled && typeof data.version === 'string') setNpmLatest(data.version)
108
- } catch { /* best-effort */ }
109
- })()
110
- return () => { cancelled = true }
111
- }, [])
112
-
113
- const doUpdate = async (): Promise<void> => {
114
- setUpdating(true)
115
- try {
116
- const res = await api.pluginUpdate()
117
- window.alert(res.message)
118
- } catch (err) {
119
- window.alert('更新失败:' + ((err as Error).message ?? String(err)))
120
- } finally {
121
- setUpdating(false)
122
- }
123
- };
124
-
125
- return (
126
- <div className={css.authorHome}>
127
- <nav className={css.panelNav} aria-label="作者级导航">
128
- <div className={css.navTitle}>
129
- <div className={css.navTitleLogo}>书</div>
130
- <div style={{ minWidth: 0 }}>
131
- <div className={css.navTitleName}>小说工坊</div>
132
- <div className={css.navTitleBook}>作者级 · 跨书</div>
133
- </div>
134
- </div>
135
- <div className={css.navGroup}>
136
- <div className={css.navGroupLabel}>作者</div>
137
- {NAV_ITEMS.filter(item => item.id !== 'adapt' || adaptEnabled).map(item => (
138
- <button key={item.id} type="button" role="tab" aria-selected={nav === item.id} data-active={nav === item.id ? '' : undefined} className={css.navTab} title={item.hint} onClick={() => { if (item.id === 'progress') { setProgressOpen(o => !o); return } setNav(item.id) }}>
139
- <span className={css.navTabIcon}>{item.icon}</span>
140
- <span className={css.navTabLabel}>{item.label}</span>
141
- {item.id === 'progress' && busy === true && <span className={css.navTabDot} />}
142
- </button>
143
- ))}
144
- </div>
145
- <div className={css.navSpacer} />
146
- <button type="button" role="tab" aria-selected={nav === 'settings'} data-active={nav === 'settings' ? '' : undefined} className={css.navTab} title="设置" onClick={() => setNav('settings')}>
147
- <span className={css.navTabIcon}><Settings size={18} /></span>
148
- <span className={css.navTabLabel}>设置</span>
149
- </button>
150
- <div className={css.navAbout}>
151
- <button type="button" className={css.navAboutRow} title="打开 GitHub 仓库" onClick={() => { window.open(REPO_URL, '_blank', 'noopener') }}>
152
- <span>ℹ️ v{PLUGIN_VERSION}</span>
153
- <span className={css.meta}>GitHub ↗</span>
154
- </button>
155
- {npmLatest !== null && npmLatest !== PLUGIN_VERSION && (
156
- <button type="button" className={css.navAboutUpdate} title="点击自动更新(下载最新 npm 版,完成后请重启 DSH)" disabled={updating} onClick={() => { void doUpdate() }}>
157
- {updating ? '🔄 更新中…' : `🔄 更新到 v${npmLatest}`}
158
- </button>
159
- )}
160
- </div>
161
- </nav>
162
- <div className={css.authorContent}>
163
- {nav === 'shelf' && <ShelfView api={api} shelf={shelf} onOpenBook={onOpenBook} onReadBook={onReadBook} onAddBook={onAddBook} onImportBook={onImportBook} />}
164
- {nav === 'adapt' && <AdaptModeView api={api} onOpenBook={onOpenBook} />}
165
- {nav === 'assets' && <AuthorAssetsView api={api} />}
166
- {nav === 'library' && <GlobalAssetLibraryView api={api} />}
167
- {nav === 'settings' && <SettingsView api={api} onTheme={onTheme} onBackground={onBackground} onOpacity={onOpacity} onEndfieldAccent={onEndfieldAccent} />}
168
- </div>
169
- {progressOpen && (
170
- <div className={css.assistantFloat} style={{ left: progressPos.x, top: progressPos.y, width: progressSize.w, height: progressSize.h }}>
171
- <div
172
- className={css.assistantFloatHeader}
173
- onMouseDown={e => {
174
- e.preventDefault()
175
- dragState.current = { type: 'move', startX: e.clientX, startY: e.clientY, origX: progressPos.x, origY: progressPos.y, origW: progressSize.w, origH: progressSize.h }
176
- }}
177
- >
178
- <span>
179
- 📊 AI 进度
180
- {busy && <span style={{ color: 'var(--nf-accent)' }}> 🟢 任务进行中</span>}
181
- <span className={css.meta}>(拖动标题栏移动 · 右下角拉大小)</span>
182
- </span>
183
- <span style={{ display: 'flex', alignItems: 'center', gap: 'var(--nf-space-4)' }}>
184
- {(progress ?? []).length > 0 && <button type="button" className={`${css.button} ${css.buttonSmall}`} onClick={onClearProgress} title="清空活动记录">清空</button>}
185
- <button type="button" className={css.iconButton} title="关闭" aria-label="关闭AI进度" onClick={() => setProgressOpen(false)}>×</button>
186
- </span>
187
- </div>
188
- <div className={css.assistantFloatBody} style={{ padding: 'var(--nf-space-10)', display: 'flex', flexDirection: 'column', gap: 'var(--nf-space-8)', overflow: 'hidden', flex: 1, minHeight: 0 }}>
189
- <div style={{ flex: 1, minHeight: 0, display: 'flex', flexDirection: 'column' }}>
190
- <ProgressConsole progress={progress ?? []} busy={busy ?? false} busyLabel={busyLabel ?? ''} liveBar={liveBar ?? null} onClear={() => onClearProgress?.()} />
191
- </div>
192
- </div>
193
- <div
194
- style={{ width: 14, height: 14, position: 'absolute', right: 0, bottom: 0, cursor: 'nwse-resize' }}
195
- onMouseDown={e => {
196
- e.preventDefault()
197
- dragState.current = { type: 'resize', startX: e.clientX, startY: e.clientY, origX: progressPos.x, origY: progressPos.y, origW: progressSize.w, origH: progressSize.h }
198
- }}
199
- />
200
- </div>
201
- )}
202
- </div>
203
- );
204
- }
@@ -1,170 +0,0 @@
1
- /**
2
- * 书架条:显示所有书,点击切换当前书(继续编译),+ 新建。
3
- * 新建 = 开书向导:书名 + 大纲(拖拽/选择 docx 或粘贴文本),创建即建项目。
4
- */
5
- import { useRef, useState } from 'react'
6
- import type { NovelApi } from '../api.ts'
7
- import { extractDocxTextFromBuffer } from '../docx.ts'
8
- import type { BookshelfSnapshot } from '../../protocol.ts'
9
- import css from './panel.module.css'
10
-
11
- /** Props. */
12
- export interface BookshelfBarProps {
13
- api: NovelApi
14
- shelf: BookshelfSnapshot
15
- /** 刷新整个面板(切换书后重新拉状态)。 */
16
- onSwitch: () => void
17
- }
18
-
19
- /** 书架条。 */
20
- export function BookshelfBar({ api, shelf, onSwitch }: BookshelfBarProps) {
21
- const [creating, setCreating] = useState(false)
22
- const [name, setName] = useState('')
23
- const [outlineText, setOutlineText] = useState('')
24
- const [outlineName, setOutlineName] = useState('')
25
- const [busy, setBusy] = useState(false)
26
- const [error, setError] = useState('')
27
- const outlineFileRef = useRef<HTMLInputElement | null>(null)
28
-
29
- const handlePickOutlineFile = async (file: File | undefined): Promise<void> => {
30
- if (file === undefined) return
31
- try {
32
- const buffer = await file.arrayBuffer()
33
- const text = extractDocxTextFromBuffer(buffer)
34
- if (text.length < 50) {
35
- setError('大纲内容过短(<50 字符),请检查文件')
36
- return
37
- }
38
- setOutlineText(text)
39
- setOutlineName(file.name)
40
- setError('')
41
- } catch (err) {
42
- setError(`读取大纲失败:${(err as Error).message}`)
43
- }
44
- }
45
-
46
- const handleCreate = async (): Promise<void> => {
47
- const bookName = name.trim()
48
- if (bookName === '') return
49
- setBusy(true)
50
- setError('')
51
- try {
52
- await api.bookCreate(bookName, undefined, outlineText.trim() !== '' ? outlineText.trim() : undefined)
53
- setCreating(false)
54
- setName('')
55
- setOutlineText('')
56
- setOutlineName('')
57
- onSwitch()
58
- } catch (err) {
59
- setError((err as Error).message)
60
- } finally {
61
- setBusy(false)
62
- }
63
- }
64
-
65
- const handleActivate = async (id: string): Promise<void> => {
66
- if (id === shelf.activeBookId) return
67
- setBusy(true)
68
- try {
69
- await api.bookActivate(id)
70
- onSwitch()
71
- } catch (err) {
72
- setError((err as Error).message)
73
- } finally {
74
- setBusy(false)
75
- }
76
- }
77
-
78
- const handleRemove = async (id: string): Promise<void> => {
79
- setBusy(true)
80
- try {
81
- await api.bookRemove(id)
82
- onSwitch()
83
- } catch (err) {
84
- setError((err as Error).message)
85
- } finally {
86
- setBusy(false)
87
- }
88
- }
89
-
90
- return (
91
- <div className={css.bookshelf}>
92
- <span className={css.bookshelfLabel}>书架</span>
93
- <div className={css.bookshelfList}>
94
- {shelf.books.map(book => (
95
- <div
96
- key={book.id}
97
- className={`${css.bookChip} ${book.id === shelf.activeBookId ? css.bookChipActive : ''}`}
98
- onClick={() => { void handleActivate(book.id) }}
99
- title={book.outputDir}
100
- >
101
- <span className={css.bookChipName}>{book.bookName}</span>
102
- <span className={css.bookChipMeta}>{book.hasProject ? `${book.done}/${book.total} 章` : '未开书'}</span>
103
- <button
104
- type="button"
105
- className={css.bookChipRemove}
106
- title="从书架移除"
107
- onClick={(e) => { e.stopPropagation(); void handleRemove(book.id) }}
108
- >
109
- ×
110
- </button>
111
- </div>
112
- ))}
113
- {!creating ? (
114
- <button type="button" className={css.bookAdd} onClick={() => { setCreating(true) }}>
115
- + 新书
116
- </button>
117
- ) : (
118
- <div className={css.bookCreateForm}>
119
- <input
120
- className={css.input}
121
- style={{ width: 140 }}
122
- placeholder="书名"
123
- value={name}
124
- onChange={e => { setName(e.target.value) }}
125
- onKeyDown={e => { if (e.key === 'Enter') void handleCreate() }}
126
- autoFocus
127
- />
128
- {/* 开书向导:大纲(可选,推荐) */}
129
- <div className={css.bookCreateOutline}>
130
- <button
131
- type="button"
132
- className={`${css.button} ${css.buttonSmall}`}
133
- onClick={() => { outlineFileRef.current?.click() }}
134
- >
135
- {outlineName !== '' ? `✓ ${outlineName}` : '📄 选择大纲 docx'}
136
- </button>
137
- <input
138
- ref={outlineFileRef}
139
- type="file"
140
- accept=".docx,application/vnd.openxmlformats-officedocument.wordprocessingml.document"
141
- style={{ display: 'none' }}
142
- onChange={e => {
143
- void handlePickOutlineFile(e.target.files?.[0])
144
- e.target.value = ''
145
- }}
146
- />
147
- <textarea
148
- className={css.input}
149
- style={{ width: 280, minHeight: 64, resize: 'vertical' }}
150
- placeholder="或直接粘贴大纲文本(提供大纲后开书即建立项目,书名自动从大纲首行识别)"
151
- value={outlineText}
152
- onChange={e => { setOutlineText(e.target.value) }}
153
- />
154
- </div>
155
- <div className={css.row}>
156
- <button type="button" className={`${css.button} ${css.buttonSmall} ${css.buttonPrimary}`} disabled={busy || name.trim() === ''} onClick={() => { void handleCreate() }}>
157
- 开书
158
- </button>
159
- <button type="button" className={`${css.button} ${css.buttonSmall}`} onClick={() => { setCreating(false) }}>
160
- 取消
161
- </button>
162
- <span className={css.meta}>{outlineText.length > 0 ? `大纲 ${outlineText.length} 字` : '未提供大纲(稍后在大纲页导入)'}</span>
163
- </div>
164
- </div>
165
- )}
166
- </div>
167
- {error !== '' && <span style={{ color: 'var(--nf-error)', fontSize: 'var(--nf-fs-12)' }}>{error}</span>}
168
- </div>
169
- )
170
- }