@waterwx/dsh-novel-forge 0.1.0 → 1.0.0-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.
- package/README.md +162 -111
- package/cordis.patch.yml +1 -1
- package/lib/client.js +54165 -2666
- package/lib/index.js +11895 -2211
- package/lib/types/ai-scan.d.ts +36 -0
- package/lib/types/assets.d.ts +19 -4
- package/lib/types/assistant.d.ts +6 -0
- package/lib/types/author-assets.d.ts +25 -0
- package/lib/types/bookshelf.d.ts +8 -1
- package/lib/types/client/api.d.ts +235 -3
- package/lib/types/client/index.d.ts +1 -1
- package/lib/types/client/llmLive.d.ts +33 -0
- package/lib/types/client/locales.d.ts +101 -28
- package/lib/types/client/panel/AdaptModeView.d.ts +5 -0
- package/lib/types/client/panel/AssetsTab.d.ts +6 -1
- package/lib/types/client/panel/AuthorAssetsView.d.ts +4 -0
- package/lib/types/client/panel/AuthorHome.d.ts +34 -0
- package/lib/types/client/panel/BookAnalysisView.d.ts +4 -0
- package/lib/types/client/panel/CreateBookView.d.ts +13 -0
- package/lib/types/client/panel/DirectorView.d.ts +7 -0
- package/lib/types/client/panel/FlowGuide.d.ts +22 -0
- package/lib/types/client/panel/GlobalAssetLibraryView.d.ts +4 -0
- package/lib/types/client/panel/IdeaInspirationView.d.ts +6 -0
- package/lib/types/client/panel/ImportModal.d.ts +7 -0
- package/lib/types/client/panel/KnowledgeBaseView.d.ts +4 -0
- package/lib/types/client/panel/LiveFeedLog.d.ts +5 -0
- package/lib/types/client/panel/MangaRoleLibrary.d.ts +20 -0
- package/lib/types/client/panel/MangaWorkspace.d.ts +12 -0
- package/lib/types/client/panel/MarketRadarView.d.ts +5 -0
- package/lib/types/client/panel/ModelManager.d.ts +14 -0
- package/lib/types/client/panel/ModelPicker.d.ts +11 -0
- package/lib/types/client/panel/NovelPanel.d.ts +1 -1
- package/lib/types/client/panel/ProgressConsole.d.ts +17 -0
- package/lib/types/client/panel/ProgressHomeView.d.ts +5 -0
- package/lib/types/client/panel/PropLibrary.d.ts +8 -0
- package/lib/types/client/panel/ReaderView.d.ts +8 -0
- package/lib/types/client/panel/ReasoningSection.d.ts +10 -0
- package/lib/types/client/panel/RunPanel.d.ts +5 -0
- package/lib/types/client/panel/SceneLibrary.d.ts +16 -0
- package/lib/types/client/panel/SettingsView.d.ts +16 -0
- package/lib/types/client/panel/ShelfView.d.ts +15 -0
- package/lib/types/client/panel/StoryboardTab.d.ts +19 -0
- package/lib/types/client/panel/StyleCard.d.ts +8 -0
- package/lib/types/client/panel/StyleGallery.d.ts +1 -0
- package/lib/types/client/panel/WorldTab.d.ts +10 -0
- package/lib/types/client/panel/helpers.d.ts +10 -0
- package/lib/types/client/panel/views.d.ts +77 -0
- package/lib/types/client/run-status.d.ts +19 -0
- package/lib/types/client/text.d.ts +9 -0
- package/lib/types/comic-presets.d.ts +12 -0
- package/lib/types/engine.d.ts +250 -8
- package/lib/types/global-assets.d.ts +6 -0
- package/lib/types/index.d.ts +24 -2
- package/lib/types/llm-live.d.ts +44 -0
- package/lib/types/manga-genre-rules.d.ts +22 -0
- package/lib/types/market-radar-scan.d.ts +19 -0
- package/lib/types/market-radar-sources.d.ts +31 -0
- package/lib/types/novel-context.d.ts +80 -0
- package/lib/types/prompt-utils.d.ts +35 -0
- package/lib/types/prompting.d.ts +35 -0
- package/lib/types/protocol.d.ts +1453 -5
- package/lib/types/review-policy.d.ts +97 -0
- package/lib/types/run.d.ts +32 -0
- package/lib/types/shot-language.d.ts +46 -0
- package/lib/types/src/ai-scan.d.ts +36 -0
- package/lib/types/src/assets.d.ts +37 -0
- package/lib/types/src/assistant.d.ts +45 -0
- package/lib/types/src/author-assets.d.ts +25 -0
- package/lib/types/src/bookshelf.d.ts +42 -0
- package/lib/types/src/client/api.d.ts +234 -0
- package/lib/types/src/client/docx.d.ts +15 -0
- package/lib/types/src/client/index.d.ts +14 -0
- package/lib/types/src/client/locales.d.ts +212 -0
- package/lib/types/src/client/mount.d.ts +9 -0
- package/lib/types/src/client/panel/AdaptModeView.d.ts +5 -0
- package/lib/types/src/client/panel/AssetsTab.d.ts +12 -0
- package/lib/types/src/client/panel/AssistantTab.d.ts +7 -0
- package/lib/types/src/client/panel/AuthorAssetsView.d.ts +4 -0
- package/lib/types/src/client/panel/AuthorHome.d.ts +32 -0
- package/lib/types/src/client/panel/BookshelfBar.d.ts +11 -0
- package/lib/types/src/client/panel/CreateBookView.d.ts +9 -0
- package/lib/types/src/client/panel/FlowGuide.d.ts +22 -0
- package/lib/types/src/client/panel/GlobalAssetLibraryView.d.ts +4 -0
- package/lib/types/src/client/panel/ImportModal.d.ts +7 -0
- package/lib/types/src/client/panel/MangaRoleLibrary.d.ts +20 -0
- package/lib/types/src/client/panel/MangaWorkspace.d.ts +12 -0
- package/lib/types/src/client/panel/ModelManager.d.ts +14 -0
- package/lib/types/src/client/panel/NovelPanel.d.ts +13 -0
- package/lib/types/src/client/panel/ProgressConsole.d.ts +17 -0
- package/lib/types/src/client/panel/ProgressHomeView.d.ts +5 -0
- package/lib/types/src/client/panel/PropLibrary.d.ts +8 -0
- package/lib/types/src/client/panel/ReaderView.d.ts +8 -0
- package/lib/types/src/client/panel/ReasoningSection.d.ts +10 -0
- package/lib/types/src/client/panel/RunPanel.d.ts +5 -0
- package/lib/types/src/client/panel/SceneLibrary.d.ts +16 -0
- package/lib/types/src/client/panel/SettingsView.d.ts +16 -0
- package/lib/types/src/client/panel/ShelfView.d.ts +15 -0
- package/lib/types/src/client/panel/StoryboardTab.d.ts +19 -0
- package/lib/types/src/client/panel/StyleCard.d.ts +8 -0
- package/lib/types/src/client/panel/StyleGallery.d.ts +1 -0
- package/lib/types/src/client/panel/WorldTab.d.ts +10 -0
- package/lib/types/src/client/panel/controller.d.ts +19 -0
- package/lib/types/src/client/panel/helpers.d.ts +18 -0
- package/lib/types/src/client/panel/views.d.ts +77 -0
- package/lib/types/src/client/sidebar-entry.d.ts +13 -0
- package/lib/types/src/client/text.d.ts +9 -0
- package/lib/types/src/comic-presets.d.ts +12 -0
- package/lib/types/src/docx.d.ts +19 -0
- package/lib/types/src/engine.d.ts +402 -0
- package/lib/types/src/index.d.ts +79 -0
- package/lib/types/src/manga-genre-rules.d.ts +22 -0
- package/lib/types/src/novel-context.d.ts +80 -0
- package/lib/types/src/prompt-utils.d.ts +35 -0
- package/lib/types/src/protocol.d.ts +2176 -0
- package/lib/types/src/review-policy.d.ts +97 -0
- package/lib/types/src/routes.d.ts +29 -0
- package/lib/types/src/run.d.ts +32 -0
- package/lib/types/src/shot-language.d.ts +46 -0
- package/lib/types/src/story-beat-language.d.ts +35 -0
- package/lib/types/src/style-library.d.ts +33 -0
- package/lib/types/story-beat-language.d.ts +35 -0
- package/lib/types/style-library.d.ts +33 -0
- package/package.json +57 -42
- package/scripts/patch-schemastery.mjs +47 -0
- package/src/ai-scan.ts +179 -0
- package/src/assets.ts +1774 -518
- package/src/assistant.ts +915 -547
- package/src/author-assets.ts +147 -0
- package/src/bookshelf.ts +32 -2
- package/src/client/api.ts +666 -254
- package/src/client/index.ts +3 -1
- package/src/client/llmLive.ts +101 -0
- package/src/client/locales.ts +178 -31
- package/src/client/mount.tsx +1 -1
- package/src/client/panel/AdaptModeView.tsx +535 -0
- package/src/client/panel/AssetsTab.tsx +168 -51
- package/src/client/panel/AssistantTab.tsx +339 -188
- package/src/client/panel/AuthorAssetsView.tsx +208 -0
- package/src/client/panel/AuthorHome.tsx +234 -0
- package/src/client/panel/BookAnalysisView.tsx +60 -0
- package/src/client/panel/BookshelfBar.tsx +63 -9
- package/src/client/panel/CreateBookView.tsx +371 -0
- package/src/client/panel/DirectorView.tsx +200 -0
- package/src/client/panel/GlobalAssetLibraryView.tsx +172 -0
- package/src/client/panel/IdeaInspirationView.tsx +71 -0
- package/src/client/panel/ImportModal.tsx +303 -0
- package/src/client/panel/KnowledgeBaseView.tsx +73 -0
- package/src/client/panel/LiveFeedLog.tsx +67 -0
- package/src/client/panel/MarketRadarView.tsx +374 -0
- package/src/client/panel/ModelManager.tsx +205 -0
- package/src/client/panel/NovelPanel.tsx +4713 -990
- package/src/client/panel/ProgressConsole.tsx +63 -0
- package/src/client/panel/ProgressHomeView.tsx +87 -0
- package/src/client/panel/ReaderView.tsx +306 -0
- package/src/client/panel/ReasoningSection.tsx +31 -0
- package/src/client/panel/RunPanel.tsx +204 -0
- package/src/client/panel/SettingsView.tsx +265 -0
- package/src/client/panel/ShelfView.tsx +242 -0
- package/src/client/panel/WorldTab.tsx +202 -0
- package/src/client/panel/helpers.ts +50 -0
- package/src/client/panel/panel.module.css +4325 -526
- package/src/client/panel/views.tsx +346 -0
- package/src/client/run-status.ts +100 -0
- package/src/client/sidebar-entry.ts +1 -1
- package/src/client/text.ts +28 -0
- package/src/engine.ts +4230 -1019
- package/src/global-assets.ts +59 -0
- package/src/index.ts +123 -9
- package/src/llm-live.ts +68 -0
- package/src/market-radar-scan.ts +41 -0
- package/src/market-radar-sources.ts +173 -0
- package/src/novel-context.ts +287 -0
- package/src/prompt-utils.ts +73 -0
- package/src/prompting.ts +159 -0
- package/src/protocol.ts +1998 -539
- package/src/review-policy.ts +161 -0
- package/src/routes.ts +3277 -955
- package/src/run.ts +338 -0
- package/lib/client.js.map +0 -1
- package/lib/index.js.map +0 -1
|
@@ -0,0 +1,208 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 作者资产库/总数据页:跨书可复用的笔法/红线/套路/角色模板/世界观模板。
|
|
3
|
+
* 支持 新增 / 编辑 / 删除;数据持久化到 ~/.dsh/dsh-novel-forge-author-assets.json。
|
|
4
|
+
*/
|
|
5
|
+
import { useEffect, useMemo, useState } from 'react'
|
|
6
|
+
import { Plus, Trash2, Pencil } from 'lucide-react'
|
|
7
|
+
import type { NovelApi } from '../api.ts'
|
|
8
|
+
import type { AuthorStyleAsset } from '../../protocol.ts'
|
|
9
|
+
import css from './panel.module.css'
|
|
10
|
+
|
|
11
|
+
const KIND_LABELS: Record<AuthorStyleAsset['kind'], string> = {
|
|
12
|
+
style: '笔法',
|
|
13
|
+
antiAi: '红线/反AI',
|
|
14
|
+
progression: '推进模式',
|
|
15
|
+
genre: '题材',
|
|
16
|
+
roleTemplate: '角色模板',
|
|
17
|
+
worldTemplate: '世界观模板',
|
|
18
|
+
plotBeat: '剧情桥段',
|
|
19
|
+
custom: '自定义',
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const KIND_OPTIONS = Object.keys(KIND_LABELS) as AuthorStyleAsset['kind'][]
|
|
23
|
+
|
|
24
|
+
const KIND_COLORS: Record<AuthorStyleAsset['kind'], string> = {
|
|
25
|
+
style: 'var(--nf-info)',
|
|
26
|
+
antiAi: 'var(--nf-warn)',
|
|
27
|
+
progression: 'var(--nf-accent)',
|
|
28
|
+
genre: 'var(--nf-info)',
|
|
29
|
+
roleTemplate: 'var(--nf-accent)',
|
|
30
|
+
worldTemplate: 'var(--nf-warn)',
|
|
31
|
+
plotBeat: 'var(--nf-accent)',
|
|
32
|
+
custom: 'var(--nf-muted)',
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** 计算资产的分组(分类):题材按顶层题材名('/' 之前),其余按类型。 */
|
|
36
|
+
function assetCategory(a: AuthorStyleAsset): string {
|
|
37
|
+
if (a.kind === 'genre') {
|
|
38
|
+
const top = a.name.split('/')[0]?.trim()
|
|
39
|
+
return top !== undefined && top !== '' ? top : '题材'
|
|
40
|
+
}
|
|
41
|
+
return KIND_LABELS[a.kind] ?? '其他'
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
interface EditorState {
|
|
45
|
+
id?: string
|
|
46
|
+
name: string; kind: AuthorStyleAsset['kind']; summary: string; content: string; tags: string; sourceBooks: string
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function emptyEditor(): EditorState {
|
|
50
|
+
return { name: '', kind: 'style', summary: '', content: '', tags: '', sourceBooks: '' }
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
export function AuthorAssetsView({ api }: { api: NovelApi }) {
|
|
54
|
+
const [assets, setAssets] = useState<AuthorStyleAsset[]>([]);
|
|
55
|
+
const [editing, setEditing] = useState<EditorState | null>(null);
|
|
56
|
+
const [error, setError] = useState('');
|
|
57
|
+
const [busy, setBusy] = useState(false);
|
|
58
|
+
const [kindFilter, setKindFilter] = useState<AuthorStyleAsset['kind'] | 'all'>('all');
|
|
59
|
+
|
|
60
|
+
const load = async (): Promise<void> => {
|
|
61
|
+
try { const res = await api.authorAssets(); setAssets(res.assets.items) } catch (err) { setError((err as Error).message) }
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
/** 导入默认:把书架书的写作资产/角色 + 内置全局库批量沉淀到作者资产库。 */
|
|
65
|
+
const importDefaults = async (): Promise<void> => {
|
|
66
|
+
setBusy(true); setError('');
|
|
67
|
+
try { const res = await api.authorAssetsImportDefault(); setAssets(res.assets.items) } catch (err) { setError((err as Error).message) } finally { setBusy(false) }
|
|
68
|
+
};
|
|
69
|
+
|
|
70
|
+
// 打开即加载;若资产库为空,自动导入默认(书架资产 + 内置全局库)。
|
|
71
|
+
useEffect(() => {
|
|
72
|
+
let cancelled = false
|
|
73
|
+
void (async () => {
|
|
74
|
+
try {
|
|
75
|
+
const res = await api.authorAssets()
|
|
76
|
+
if (cancelled) return
|
|
77
|
+
if (res.assets.items.length === 0) {
|
|
78
|
+
const imp = await api.authorAssetsImportDefault()
|
|
79
|
+
if (!cancelled) setAssets(imp.assets.items)
|
|
80
|
+
} else {
|
|
81
|
+
setAssets(res.assets.items)
|
|
82
|
+
}
|
|
83
|
+
} catch (err) {
|
|
84
|
+
if (!cancelled) setError((err as Error).message)
|
|
85
|
+
}
|
|
86
|
+
})()
|
|
87
|
+
return () => { cancelled = true }
|
|
88
|
+
}, [api]);
|
|
89
|
+
|
|
90
|
+
const startNew = (): void => { setEditing(emptyEditor()); setError('') };
|
|
91
|
+
const startEdit = (a: AuthorStyleAsset): void => {
|
|
92
|
+
setEditing({ id: a.id, name: a.name, kind: a.kind, summary: a.summary, content: a.content, tags: a.tags.join('、'), sourceBooks: a.sourceBooks.join('、') });
|
|
93
|
+
setError('');
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
const save = async (): Promise<void> => {
|
|
97
|
+
if (editing === null) return;
|
|
98
|
+
if (editing.name.trim() === '') { setError('请填写资产名'); return }
|
|
99
|
+
setBusy(true); setError('');
|
|
100
|
+
try {
|
|
101
|
+
const asset: AuthorStyleAsset = {
|
|
102
|
+
id: editing.id ?? '', name: editing.name.trim(), kind: editing.kind, summary: editing.summary.trim(), content: editing.content.trim(),
|
|
103
|
+
sourceBooks: editing.sourceBooks.split(/[、,,\s]+/).map(s => s.trim()).filter(Boolean),
|
|
104
|
+
tags: editing.tags.split(/[、,,\s]+/).map(s => s.trim()).filter(Boolean),
|
|
105
|
+
createdAt: '', updatedAt: '',
|
|
106
|
+
};
|
|
107
|
+
await api.authorAssetsUpsert(asset); setEditing(null); await load();
|
|
108
|
+
} catch (err) { setError((err as Error).message) } finally { setBusy(false) }
|
|
109
|
+
};
|
|
110
|
+
|
|
111
|
+
const del = async (id: string): Promise<void> => {
|
|
112
|
+
setBusy(true); setError('');
|
|
113
|
+
try { await api.authorAssetsRemove(id); await load() } catch (err) { setError((err as Error).message) } finally { setBusy(false) }
|
|
114
|
+
};
|
|
115
|
+
|
|
116
|
+
const visible = useMemo(() => (kindFilter === 'all' ? assets : assets.filter(a => a.kind === kindFilter)), [assets, kindFilter]);
|
|
117
|
+
|
|
118
|
+
/** 按分类分组展示(题材按顶层题材名,其余按类型)。 */
|
|
119
|
+
const grouped = useMemo(() => {
|
|
120
|
+
const map = new Map<string, AuthorStyleAsset[]>()
|
|
121
|
+
for (const a of visible) {
|
|
122
|
+
const cat = assetCategory(a)
|
|
123
|
+
const arr = map.get(cat) ?? []
|
|
124
|
+
arr.push(a)
|
|
125
|
+
map.set(cat, arr)
|
|
126
|
+
}
|
|
127
|
+
return Array.from(map.entries()).sort((x, y) => x[0].localeCompare(y[0], 'zh'))
|
|
128
|
+
}, [visible]);
|
|
129
|
+
|
|
130
|
+
return (
|
|
131
|
+
<div className={css.authorPageBody}>
|
|
132
|
+
<div className={css.authorPageHero}>
|
|
133
|
+
<div className={css.authorPageHeader}>
|
|
134
|
+
<div>
|
|
135
|
+
<h2 className={css.panelTitle} style={{ margin: 0 }}>🧬 作者资产库 · 总数据</h2>
|
|
136
|
+
<span className={css.meta}>跨书可复用的笔法/红线/套路/角色模板/世界观模板。任意新书与改编都能调用。</span>
|
|
137
|
+
</div>
|
|
138
|
+
<div className={css.rowEnd}>
|
|
139
|
+
<button type="button" className={css.button + ' ' + css.buttonSmall} onClick={() => { void importDefaults() }} disabled={busy} title="把书架里所有书的写作资产/角色批量沉淀到作者资产库(内置库请到全局写作资产库浏览/套用)">导入默认资产</button>
|
|
140
|
+
<button type="button" className={css.button + ' ' + css.buttonPrimary} onClick={startNew}><Plus size={14} style={{ verticalAlign: -2 }} /> 新增资产</button>
|
|
141
|
+
</div>
|
|
142
|
+
</div>
|
|
143
|
+
<div className={css.assetFilterBar}>
|
|
144
|
+
{KIND_OPTIONS.map(k => (
|
|
145
|
+
<button key={k} type="button" className={css.assetFilterChip + (kindFilter === k ? ' ' + css.assetFilterChipActive : '')} onClick={() => setKindFilter(kindFilter === k ? 'all' : k)}>{KIND_LABELS[k]} {assets.filter(a => a.kind === k).length}</button>
|
|
146
|
+
))}
|
|
147
|
+
</div>
|
|
148
|
+
</div>
|
|
149
|
+
|
|
150
|
+
{error !== '' && <div className={css.noticeError}>{error}</div>}
|
|
151
|
+
|
|
152
|
+
{editing !== null ? (
|
|
153
|
+
<div className={css.assetEditor}>
|
|
154
|
+
<h3 style={{ margin: 0 }}>{editing.id !== '' && editing.id !== undefined ? '编辑资产' : '新增资产'}</h3>
|
|
155
|
+
<div className={css.assetEditorRow}>
|
|
156
|
+
<label className={css.assetLabel}>资产名 <input className={css.input} value={editing.name} onChange={e => setEditing({ ...editing, name: e.target.value })} placeholder="如:短句快节奏爽文风" /></label>
|
|
157
|
+
<label className={css.assetLabel}>类型 <select className={css.input} value={editing.kind} onChange={e => setEditing({ ...editing, kind: e.target.value as AuthorStyleAsset['kind'] })}>{KIND_OPTIONS.map(k => <option key={k} value={k}>{KIND_LABELS[k]}</option>)}</select></label>
|
|
158
|
+
</div>
|
|
159
|
+
<label className={css.assetLabel}>一句话摘要 <input className={css.input} value={editing.summary} onChange={e => setEditing({ ...editing, summary: e.target.value })} placeholder="这个资产解决什么问题 / 有什么特点" /></label>
|
|
160
|
+
<label className={css.assetLabel}>内容(按类型约定的描述 / 规则 / 结构化文本)
|
|
161
|
+
<textarea className={`${css.input} ${css.assetTextarea}`} value={editing.content} onChange={e => setEditing({ ...editing, content: e.target.value })} placeholder={'角色模板示例:\n姓名:林越\n定位:痞坏型主角\n口头禅:"有点意思"\n性格:表面懒散、内里狠辣\n成长弧线:从底层游街到一方枭雄'} />
|
|
162
|
+
</label>
|
|
163
|
+
<div className={css.assetEditorRow}>
|
|
164
|
+
<label className={css.assetLabel}>标签(顿号分隔) <input className={css.input} value={editing.tags} onChange={e => setEditing({ ...editing, tags: e.target.value })} placeholder="扮猪吃虎、快节奏、冷面" /></label>
|
|
165
|
+
<label className={css.assetLabel}>来源书(顿号分隔) <input className={css.input} value={editing.sourceBooks} onChange={e => setEditing({ ...editing, sourceBooks: e.target.value })} placeholder="《某某传》《某某录》" /></label>
|
|
166
|
+
</div>
|
|
167
|
+
<div className={css.rowEnd}><button type="button" className={`${css.button} ${css.buttonPrimary}`} onClick={save} disabled={busy}>{busy ? '保存中…' : '保存'}</button>{(editing.id !== '' && editing.id !== undefined) && <button type="button" className={css.button + ' ' + css.buttonSmall} onClick={() => setEditing(null)}>取消</button>}</div>
|
|
168
|
+
</div>
|
|
169
|
+
) : null}
|
|
170
|
+
|
|
171
|
+
{visible.length === 0 ? (
|
|
172
|
+
<div className={css.shelfEmpty} style={{ minHeight: 160 }}>
|
|
173
|
+
<span className={css.shelfEmptyIcon}><Plus size={30} /></span>
|
|
174
|
+
<span className={css.shelfEmptyTitle}>还没有资产</span>
|
|
175
|
+
<span className={css.meta}>点「新增资产」收藏你的笔法/角色模板/套路,跨书调用。</span>
|
|
176
|
+
</div>
|
|
177
|
+
) : (
|
|
178
|
+
<div className={css.assetGroups}>
|
|
179
|
+
{grouped.map(([cat, items]) => (
|
|
180
|
+
<div key={cat} className={css.assetGroup}>
|
|
181
|
+
<div className={css.assetGroupHeader}>{cat} <span className={css.meta}>{items.length}</span></div>
|
|
182
|
+
<div className={css.assetGrid}>
|
|
183
|
+
{items.map(a => (
|
|
184
|
+
<div key={a.id} className={css.assetCard}>
|
|
185
|
+
<div className={css.assetCardTop}>
|
|
186
|
+
<span className={css.assetKind} style={{ color: KIND_COLORS[a.kind] }}>{KIND_LABELS[a.kind]}</span>
|
|
187
|
+
<div className={css.rowEnd}>
|
|
188
|
+
<button type="button" className={css.iconBtn} title="编辑" onClick={() => startEdit(a)}><Pencil size={13} /></button>
|
|
189
|
+
<button type="button" className={css.iconBtn} title="删除" onClick={() => { void del(a.id) }}><Trash2 size={13} /></button>
|
|
190
|
+
</div>
|
|
191
|
+
</div>
|
|
192
|
+
<div className={css.assetCardName}>{a.name}</div>
|
|
193
|
+
{a.summary !== '' && <div className={css.meta}>{a.summary}</div>}
|
|
194
|
+
<div className={css.assetCardContent}>{a.content}</div>
|
|
195
|
+
<div className={css.assetCardFooter}>
|
|
196
|
+
{a.tags.map(t => <span key={t} className={css.badge}>{t}</span>)}
|
|
197
|
+
{a.sourceBooks.length > 0 && <span className={css.meta}>来源:{a.sourceBooks.join(' / ')}</span>}
|
|
198
|
+
</div>
|
|
199
|
+
</div>
|
|
200
|
+
))}
|
|
201
|
+
</div>
|
|
202
|
+
</div>
|
|
203
|
+
))}
|
|
204
|
+
</div>
|
|
205
|
+
)}
|
|
206
|
+
</div>
|
|
207
|
+
);
|
|
208
|
+
}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 作者级首页容器:书架页左侧导航 + 内容区。
|
|
3
|
+
* 导航复用工作区 .panelNav 玻璃卡片样式(同款),导航项为作者级:书架/改编/资产库/全局资产库/AI 进度/设置。
|
|
4
|
+
*/
|
|
5
|
+
import { useState, useRef, useEffect } from 'react'
|
|
6
|
+
import { Library, Wand2, Boxes, Brush, Radar, FileSearch, Lightbulb, 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 LiveFeedLog from './LiveFeedLog.tsx'
|
|
16
|
+
import MarketRadarView from './MarketRadarView.tsx'
|
|
17
|
+
import BookAnalysisView from './BookAnalysisView.tsx'
|
|
18
|
+
import IdeaInspirationView from './IdeaInspirationView.tsx'
|
|
19
|
+
import css from './panel.module.css'
|
|
20
|
+
|
|
21
|
+
/** 构建时注入的插件版本(tsdown define 替换为字符串字面量)。 */
|
|
22
|
+
declare const __NOVEL_FORGE_VERSION__: string | undefined
|
|
23
|
+
const PLUGIN_VERSION: string = typeof __NOVEL_FORGE_VERSION__ !== 'undefined' ? __NOVEL_FORGE_VERSION__ : '0.0.0'
|
|
24
|
+
/** GitHub 仓库地址(关于区块点击跳转)。 */
|
|
25
|
+
const REPO_URL = 'https://github.com/watersxya/dsh-novel-forge'
|
|
26
|
+
|
|
27
|
+
type AuthorNav = 'shelf' | 'adapt' | 'assets' | 'library' | 'marketRadar' | 'bookAnalysis' | 'ideaInspiration' | 'settings';
|
|
28
|
+
|
|
29
|
+
type AuthorNavGroup = { label: string; items: Array<{ id: Exclude<AuthorNav, 'settings'>; label: string; icon: JSX.Element; hint: string }> };
|
|
30
|
+
|
|
31
|
+
const NAV_GROUPS: AuthorNavGroup[] = [
|
|
32
|
+
{
|
|
33
|
+
label: '创作',
|
|
34
|
+
items: [
|
|
35
|
+
{ id: 'shelf', label: '书架', icon: <Library size={18} />, hint: '我的书' },
|
|
36
|
+
{ id: 'adapt', label: '改编模式', icon: <Wand2 size={18} />, hint: '上传全文→可改范围' },
|
|
37
|
+
],
|
|
38
|
+
},
|
|
39
|
+
{
|
|
40
|
+
label: '灵感 · 策划',
|
|
41
|
+
items: [
|
|
42
|
+
{ id: 'marketRadar', label: '题材雷达', icon: <Radar size={18} />, hint: '热门题材雷达' },
|
|
43
|
+
{ id: 'ideaInspiration', label: '创意灵感', icon: <Lightbulb size={18} />, hint: '多方向开书灵感' },
|
|
44
|
+
{ id: 'bookAnalysis', label: '书分析', icon: <FileSearch size={18} />, hint: '拆书/卖点/可借鉴' },
|
|
45
|
+
],
|
|
46
|
+
},
|
|
47
|
+
{
|
|
48
|
+
label: '资产',
|
|
49
|
+
items: [
|
|
50
|
+
{ id: 'assets', label: '作者资产库', icon: <Boxes size={18} />, hint: '跨书总数据' },
|
|
51
|
+
{ id: 'library', label: '全局写作资产库', icon: <Brush size={18} />, hint: '内置题材/规则/模板' },
|
|
52
|
+
],
|
|
53
|
+
},
|
|
54
|
+
];
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
export function AuthorHome({ api, shelf, onOpenBook, onReadBook, onAddBook, onImportBook, onOpenSettings, onTheme, onBackground, onOpacity, onEndfieldAccent, adaptEnabled, progress, busy, busyLabel, liveBar, onClearProgress, onUseIdea }: {
|
|
58
|
+
api: NovelApi; shelf: BookshelfSnapshot;
|
|
59
|
+
onOpenBook: (id: string) => void; onReadBook: (id: string) => void; onAddBook: () => void; onImportBook: () => void;
|
|
60
|
+
/** 创意灵感 → 采纳某个灵感带入开书向导。 */
|
|
61
|
+
onUseIdea?: (idea: import('../../protocol.ts').IdeaInspirationResult['ideas'][number]) => void;
|
|
62
|
+
/** 兼容旧入口:首页设置现为独立设置页,此回调保留但不再使用。 */
|
|
63
|
+
onOpenSettings?: () => void;
|
|
64
|
+
/** 主题/模式/密度变化回调(供面板根容器实时生效)。 */
|
|
65
|
+
onTheme?: (theme: 'liquid' | 'neumorph' | 'macos' | 'clay' | 'endfield', mode: 'system' | 'light' | 'dark', density: 'comfort' | 'compact' | 'spacious') => void;
|
|
66
|
+
/** 自定义背景变化回调。 */
|
|
67
|
+
onBackground?: (bg: string | undefined, blur: number) => void;
|
|
68
|
+
/** 玻璃透明度变化回调。 */
|
|
69
|
+
onOpacity?: (n: number) => void;
|
|
70
|
+
/** 终末地强调色变化回调。 */
|
|
71
|
+
onEndfieldAccent?: (accent: 'valley' | 'wuling') => void;
|
|
72
|
+
/** 是否启用改编模式(默认 false=隐藏入口)。 */
|
|
73
|
+
adaptEnabled?: boolean;
|
|
74
|
+
/** AI 进度实时状态(与书内共享同一份)。 */
|
|
75
|
+
progress?: ProgressLine[];
|
|
76
|
+
busy?: boolean;
|
|
77
|
+
busyLabel?: string;
|
|
78
|
+
liveBar?: { text: string; ratio?: number } | null;
|
|
79
|
+
onClearProgress?: () => void;
|
|
80
|
+
}) {
|
|
81
|
+
const [nav, setNav] = useState<AuthorNav>('shelf');
|
|
82
|
+
const [updating, setUpdating] = useState(false);
|
|
83
|
+
const [progressOpen, setProgressOpen] = useState(false);
|
|
84
|
+
const [progressPos, setProgressPos] = useState(() => {
|
|
85
|
+
try {
|
|
86
|
+
const raw = window.localStorage.getItem('dsh-novel-forge.home.progress.float')
|
|
87
|
+
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 } }
|
|
88
|
+
} catch { /* ignore */ }
|
|
89
|
+
return { x: 60, y: 120 }
|
|
90
|
+
});
|
|
91
|
+
const [progressSize, setProgressSize] = useState(() => {
|
|
92
|
+
try {
|
|
93
|
+
const raw = window.localStorage.getItem('dsh-novel-forge.home.progress.size')
|
|
94
|
+
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 } }
|
|
95
|
+
} catch { /* ignore */ }
|
|
96
|
+
return { w: 460, h: 420 }
|
|
97
|
+
});
|
|
98
|
+
const dragState = useRef<{ type: 'move' | 'resize'; startX: number; startY: number; origX: number; origY: number; origW: number; origH: number } | null>(null);
|
|
99
|
+
|
|
100
|
+
useEffect(() => {
|
|
101
|
+
try {
|
|
102
|
+
window.localStorage.setItem('dsh-novel-forge.home.progress.float', JSON.stringify(progressPos))
|
|
103
|
+
window.localStorage.setItem('dsh-novel-forge.home.progress.size', JSON.stringify(progressSize))
|
|
104
|
+
} catch { /* ignore */ }
|
|
105
|
+
}, [progressPos, progressSize]);
|
|
106
|
+
|
|
107
|
+
useEffect(() => {
|
|
108
|
+
const onMove = (e: MouseEvent): void => {
|
|
109
|
+
const s = dragState.current
|
|
110
|
+
if (s === null) return
|
|
111
|
+
if (s.type === 'move') {
|
|
112
|
+
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)) })
|
|
113
|
+
} else {
|
|
114
|
+
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)) })
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
const onUp = (): void => { dragState.current = null }
|
|
118
|
+
window.addEventListener('mousemove', onMove)
|
|
119
|
+
window.addEventListener('mouseup', onUp)
|
|
120
|
+
return () => { window.removeEventListener('mousemove', onMove); window.removeEventListener('mouseup', onUp) }
|
|
121
|
+
}, []);
|
|
122
|
+
|
|
123
|
+
/** npm 最新版本(更新检测;null = 未检测/检测失败)。 */
|
|
124
|
+
const [npmLatest, setNpmLatest] = useState<string | null>(null)
|
|
125
|
+
useEffect(() => {
|
|
126
|
+
let cancelled = false
|
|
127
|
+
void (async () => {
|
|
128
|
+
try {
|
|
129
|
+
const r = await fetch('https://registry.npmjs.org/@waterwx%2Fdsh-novel-forge/latest')
|
|
130
|
+
if (!r.ok) return
|
|
131
|
+
const data = (await r.json()) as { version?: unknown }
|
|
132
|
+
if (!cancelled && typeof data.version === 'string') setNpmLatest(data.version)
|
|
133
|
+
} catch { /* best-effort */ }
|
|
134
|
+
})()
|
|
135
|
+
return () => { cancelled = true }
|
|
136
|
+
}, [])
|
|
137
|
+
|
|
138
|
+
const doUpdate = async (): Promise<void> => {
|
|
139
|
+
setUpdating(true)
|
|
140
|
+
try {
|
|
141
|
+
const res = await api.pluginUpdate()
|
|
142
|
+
window.alert(res.message)
|
|
143
|
+
} catch (err) {
|
|
144
|
+
window.alert('更新失败:' + ((err as Error).message ?? String(err)))
|
|
145
|
+
} finally {
|
|
146
|
+
setUpdating(false)
|
|
147
|
+
}
|
|
148
|
+
};
|
|
149
|
+
|
|
150
|
+
return (
|
|
151
|
+
<div className={css.authorHome}>
|
|
152
|
+
<nav className={css.panelNav} aria-label="作者级导航">
|
|
153
|
+
<div className={css.navTitle}>
|
|
154
|
+
<div className={css.navTitleLogo}>书</div>
|
|
155
|
+
<div style={{ minWidth: 0 }}>
|
|
156
|
+
<div className={css.navTitleName}>小说工坊</div>
|
|
157
|
+
<div className={css.navTitleBook}>作者级 · 跨书</div>
|
|
158
|
+
</div>
|
|
159
|
+
</div>
|
|
160
|
+
{NAV_GROUPS.map(group => (
|
|
161
|
+
<div className={css.navGroup} key={group.label}>
|
|
162
|
+
<div className={css.navGroupLabel}>{group.label}</div>
|
|
163
|
+
{group.items.filter(item => item.id !== 'adapt' || adaptEnabled).map(item => (
|
|
164
|
+
<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={() => { setNav(item.id) }}>
|
|
165
|
+
<span className={css.navTabIcon}>{item.icon}</span>
|
|
166
|
+
<span className={css.navTabLabel}>{item.label}</span>
|
|
167
|
+
</button>
|
|
168
|
+
))}
|
|
169
|
+
</div>
|
|
170
|
+
))}
|
|
171
|
+
<div className={css.navSpacer} />
|
|
172
|
+
<button type="button" role="tab" aria-selected={nav === 'settings'} data-active={nav === 'settings' ? '' : undefined} className={css.navTab} title="设置" onClick={() => setNav('settings')}>
|
|
173
|
+
<span className={css.navTabIcon}><Settings size={18} /></span>
|
|
174
|
+
<span className={css.navTabLabel}>设置</span>
|
|
175
|
+
</button>
|
|
176
|
+
<div className={css.navAbout}>
|
|
177
|
+
<button type="button" className={css.navAboutRow} title="打开 GitHub 仓库" onClick={() => { window.open(REPO_URL, '_blank', 'noopener') }}>
|
|
178
|
+
<span>ℹ️ v{PLUGIN_VERSION}</span>
|
|
179
|
+
<span className={css.meta}>GitHub ↗</span>
|
|
180
|
+
</button>
|
|
181
|
+
{npmLatest !== null && npmLatest !== PLUGIN_VERSION && (
|
|
182
|
+
<button type="button" className={css.navAboutUpdate} title="点击自动更新(下载最新 npm 版,完成后请重启 DSH)" disabled={updating} onClick={() => { void doUpdate() }}>
|
|
183
|
+
{updating ? '🔄 更新中…' : `🔄 更新到 v${npmLatest}`}
|
|
184
|
+
</button>
|
|
185
|
+
)}
|
|
186
|
+
</div>
|
|
187
|
+
</nav>
|
|
188
|
+
<div className={css.authorContent}>
|
|
189
|
+
{nav === 'shelf' && <ShelfView api={api} shelf={shelf} onOpenBook={onOpenBook} onReadBook={onReadBook} onAddBook={onAddBook} onImportBook={onImportBook} />}
|
|
190
|
+
{nav === 'adapt' && <AdaptModeView api={api} onOpenBook={onOpenBook} />}
|
|
191
|
+
{nav === 'assets' && <AuthorAssetsView api={api} />}
|
|
192
|
+
{nav === 'library' && <GlobalAssetLibraryView api={api} />}
|
|
193
|
+
{nav === 'marketRadar' && <MarketRadarView api={api} bookId={shelf?.activeBookId ?? undefined} />}
|
|
194
|
+
{nav === 'bookAnalysis' && <BookAnalysisView api={api} />}
|
|
195
|
+
{nav === 'ideaInspiration' && <IdeaInspirationView api={api} onUseIdea={onUseIdea} />}
|
|
196
|
+
{nav === 'settings' && <SettingsView api={api} onTheme={onTheme} onBackground={onBackground} onOpacity={onOpacity} onEndfieldAccent={onEndfieldAccent} />}
|
|
197
|
+
</div>
|
|
198
|
+
{progressOpen && (
|
|
199
|
+
<div className={css.assistantFloat} style={{ left: progressPos.x, top: progressPos.y, width: progressSize.w, height: progressSize.h }}>
|
|
200
|
+
<div
|
|
201
|
+
className={css.assistantFloatHeader}
|
|
202
|
+
onMouseDown={e => {
|
|
203
|
+
e.preventDefault()
|
|
204
|
+
dragState.current = { type: 'move', startX: e.clientX, startY: e.clientY, origX: progressPos.x, origY: progressPos.y, origW: progressSize.w, origH: progressSize.h }
|
|
205
|
+
}}
|
|
206
|
+
>
|
|
207
|
+
<span>
|
|
208
|
+
📊 AI 进度
|
|
209
|
+
{busy && <span style={{ color: 'var(--nf-accent)' }}> 🟢 任务进行中</span>}
|
|
210
|
+
<span className={css.meta}>(拖动标题栏移动 · 右下角拉大小)</span>
|
|
211
|
+
</span>
|
|
212
|
+
<span style={{ display: 'flex', alignItems: 'center', gap: 'var(--nf-space-4)' }}>
|
|
213
|
+
{(progress ?? []).length > 0 && <button type="button" className={`${css.button} ${css.buttonSmall}`} onClick={onClearProgress} title="清空活动记录">清空</button>}
|
|
214
|
+
<button type="button" className={css.iconButton} title="关闭" aria-label="关闭AI进度" onClick={() => setProgressOpen(false)}>×</button>
|
|
215
|
+
</span>
|
|
216
|
+
</div>
|
|
217
|
+
<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 }}>
|
|
218
|
+
<div style={{ flex: '0 2 auto', minHeight: 0, maxHeight: '42%', display: 'flex', flexDirection: 'column' }}>
|
|
219
|
+
<ProgressConsole progress={progress ?? []} busy={busy ?? false} busyLabel={busyLabel ?? ''} liveBar={liveBar ?? null} onClear={() => onClearProgress?.()} />
|
|
220
|
+
</div>
|
|
221
|
+
<LiveFeedLog />
|
|
222
|
+
</div>
|
|
223
|
+
<div
|
|
224
|
+
style={{ width: 14, height: 14, position: 'absolute', right: 0, bottom: 0, cursor: 'nwse-resize' }}
|
|
225
|
+
onMouseDown={e => {
|
|
226
|
+
e.preventDefault()
|
|
227
|
+
dragState.current = { type: 'resize', startX: e.clientX, startY: e.clientY, origX: progressPos.x, origY: progressPos.y, origW: progressSize.w, origH: progressSize.h }
|
|
228
|
+
}}
|
|
229
|
+
/>
|
|
230
|
+
</div>
|
|
231
|
+
)}
|
|
232
|
+
</div>
|
|
233
|
+
);
|
|
234
|
+
}
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 书分析/拆书:输入一本书/章节文本 → 卖点/结构/可借鉴点/风险。
|
|
3
|
+
*/
|
|
4
|
+
import { useState } from 'react'
|
|
5
|
+
import type { NovelApi } from '../api.ts'
|
|
6
|
+
import type { BookAnalysisResult } from '../../protocol.ts'
|
|
7
|
+
import css from './panel.module.css'
|
|
8
|
+
|
|
9
|
+
const SECTIONS: Array<{ key: keyof BookAnalysisResult; label: string; color: string }> = [
|
|
10
|
+
{ key: 'sellingPoints', label: '卖点', color: 'var(--nf-success)' },
|
|
11
|
+
{ key: 'structure', label: '结构', color: 'var(--nf-info)' },
|
|
12
|
+
{ key: 'lessons', label: '可借鉴', color: 'var(--nf-accent)' },
|
|
13
|
+
{ key: 'risks', label: '风险', color: 'var(--nf-error)' },
|
|
14
|
+
]
|
|
15
|
+
|
|
16
|
+
export default function BookAnalysisView({ api }: { api: NovelApi }): JSX.Element {
|
|
17
|
+
const [text, setText] = useState('')
|
|
18
|
+
const [busy, setBusy] = useState(false)
|
|
19
|
+
const [error, setError] = useState('')
|
|
20
|
+
const [result, setResult] = useState<BookAnalysisResult | null>(null)
|
|
21
|
+
|
|
22
|
+
const run = async (): Promise<void> => {
|
|
23
|
+
if (text.trim().length < 50) { setError('文本过短(<50 字符),请粘贴一段书/章节内容'); return }
|
|
24
|
+
setBusy(true); setError('')
|
|
25
|
+
try {
|
|
26
|
+
const r = await api.bookAnalysis(text.trim())
|
|
27
|
+
setResult(r.result)
|
|
28
|
+
} catch (e) { setError((e as Error).message) } finally { setBusy(false) }
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<div className={css.authorPageBody}>
|
|
33
|
+
<div className={`${css.card} ${css.settingsCard}`} style={{ gap: 'var(--nf-space-10)' }}>
|
|
34
|
+
<span className={css.cardTitle}>🔍 书分析 / 拆书</span>
|
|
35
|
+
<span className={css.meta}>粘贴一本书/章节文本 → 提炼卖点、结构、可借鉴点与风险(不照搬具体作品)。</span>
|
|
36
|
+
<textarea className={css.input} style={{ minHeight: 180, resize: 'vertical' }} value={text} onChange={e => setText(e.target.value)} placeholder="粘贴要分析的书/章节正文…" />
|
|
37
|
+
<div>
|
|
38
|
+
<button type="button" className={`${css.button} ${css.buttonPrimary}`} disabled={busy} onClick={() => { void run() }}>
|
|
39
|
+
{busy ? '分析中…' : '开始分析'}
|
|
40
|
+
</button>
|
|
41
|
+
</div>
|
|
42
|
+
</div>
|
|
43
|
+
|
|
44
|
+
{error !== '' && <div style={{ color: 'var(--nf-error)', fontSize: 13 }}>⚠ {error}</div>}
|
|
45
|
+
|
|
46
|
+
{result !== null && (
|
|
47
|
+
<div style={{ display: 'grid', gridTemplateColumns: 'repeat(auto-fit, minmax(240px, 1fr))', gap: 'var(--nf-space-10)' }}>
|
|
48
|
+
{SECTIONS.map(s => (
|
|
49
|
+
<div key={s.key} className={`${css.card} ${css.settingsCard}`} style={{ gap: 'var(--nf-space-8)' }}>
|
|
50
|
+
<div style={{ fontSize: 13, fontWeight: 600, color: s.color }}>{s.label}({(result[s.key] ?? []).length})</div>
|
|
51
|
+
<div style={{ display: 'flex', flexDirection: 'column', gap: 4 }}>
|
|
52
|
+
{(result[s.key] ?? []).length === 0 ? <span style={{ color: 'var(--nf-text-2)', fontSize: 12 }}>无</span> : (result[s.key] ?? []).map((x, i) => <div key={i} style={{ fontSize: 12, borderLeft: '3px solid ' + s.color, paddingLeft: 6 }}>{x}</div>)}
|
|
53
|
+
</div>
|
|
54
|
+
</div>
|
|
55
|
+
))}
|
|
56
|
+
</div>
|
|
57
|
+
)}
|
|
58
|
+
</div>
|
|
59
|
+
)
|
|
60
|
+
}
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 书架条:显示所有书,点击切换当前书(继续编译),+ 新建。
|
|
3
|
+
* 新建 = 开书向导:书名 + 大纲(拖拽/选择 docx 或粘贴文本),创建即建项目。
|
|
3
4
|
*/
|
|
4
|
-
import { useState } from 'react'
|
|
5
|
+
import { useRef, useState } from 'react'
|
|
5
6
|
import type { NovelApi } from '../api.ts'
|
|
7
|
+
import { extractDocxTextFromBuffer } from '../docx.ts'
|
|
6
8
|
import type { BookshelfSnapshot } from '../../protocol.ts'
|
|
7
9
|
import css from './panel.module.css'
|
|
8
10
|
|
|
@@ -18,8 +20,28 @@ export interface BookshelfBarProps {
|
|
|
18
20
|
export function BookshelfBar({ api, shelf, onSwitch }: BookshelfBarProps) {
|
|
19
21
|
const [creating, setCreating] = useState(false)
|
|
20
22
|
const [name, setName] = useState('')
|
|
23
|
+
const [outlineText, setOutlineText] = useState('')
|
|
24
|
+
const [outlineName, setOutlineName] = useState('')
|
|
21
25
|
const [busy, setBusy] = useState(false)
|
|
22
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
|
+
}
|
|
23
45
|
|
|
24
46
|
const handleCreate = async (): Promise<void> => {
|
|
25
47
|
const bookName = name.trim()
|
|
@@ -27,9 +49,11 @@ export function BookshelfBar({ api, shelf, onSwitch }: BookshelfBarProps) {
|
|
|
27
49
|
setBusy(true)
|
|
28
50
|
setError('')
|
|
29
51
|
try {
|
|
30
|
-
await api.bookCreate(bookName)
|
|
52
|
+
await api.bookCreate(bookName, undefined, outlineText.trim() !== '' ? outlineText.trim() : undefined)
|
|
31
53
|
setCreating(false)
|
|
32
54
|
setName('')
|
|
55
|
+
setOutlineText('')
|
|
56
|
+
setOutlineName('')
|
|
33
57
|
onSwitch()
|
|
34
58
|
} catch (err) {
|
|
35
59
|
setError((err as Error).message)
|
|
@@ -101,16 +125,46 @@ export function BookshelfBar({ api, shelf, onSwitch }: BookshelfBarProps) {
|
|
|
101
125
|
onKeyDown={e => { if (e.key === 'Enter') void handleCreate() }}
|
|
102
126
|
autoFocus
|
|
103
127
|
/>
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
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>
|
|
110
164
|
</div>
|
|
111
165
|
)}
|
|
112
166
|
</div>
|
|
113
|
-
{error !== '' && <span style={{ color: 'var(--nf-error)', fontSize: 12 }}>{error}</span>}
|
|
167
|
+
{error !== '' && <span style={{ color: 'var(--nf-error)', fontSize: 'var(--nf-fs-12)' }}>{error}</span>}
|
|
114
168
|
</div>
|
|
115
169
|
)
|
|
116
170
|
}
|