@waterwx/dsh-novel-forge 1.7.3 → 1.8.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.
- package/lib/client.js +3219 -662
- package/lib/client.js.map +1 -1
- package/lib/index.js +629 -41
- package/lib/index.js.map +1 -1
- package/lib/types/author-assets.d.ts +25 -0
- package/lib/types/client/api.d.ts +18 -0
- package/lib/types/client/panel/AdaptModeView.d.ts +4 -0
- package/lib/types/client/panel/AuthorAssetsView.d.ts +4 -0
- package/lib/types/client/panel/AuthorHome.d.ts +20 -0
- package/lib/types/client/panel/ProgressHomeView.d.ts +5 -0
- package/lib/types/client/panel/SettingsView.d.ts +14 -0
- package/lib/types/client/text.d.ts +9 -0
- package/lib/types/engine.d.ts +24 -1
- package/lib/types/index.d.ts +8 -0
- package/lib/types/protocol.d.ts +192 -0
- package/package.json +1 -1
- package/src/author-assets.ts +166 -0
- package/src/client/api.ts +41 -0
- package/src/client/mount.tsx._new +97 -0
- package/src/client/mount.tsx._nf +97 -0
- package/src/client/mount.tsx._tmp +97 -0
- package/src/client/panel/AdaptModeView.tsx +204 -0
- package/src/client/panel/AuthorAssetsView.tsx +206 -0
- package/src/client/panel/AuthorHome.tsx +93 -0
- package/src/client/panel/ImportModal.tsx +2 -1
- package/src/client/panel/NovelPanel.tsx +47 -16
- package/src/client/panel/ProgressHomeView.tsx +87 -0
- package/src/client/panel/SettingsView.tsx +285 -0
- package/src/client/panel/panel.module.css +325 -0
- package/src/client/sidebar-entry.ts +1 -1
- package/src/client/text.ts +28 -0
- package/src/engine.ts +221 -0
- package/src/index.ts +20 -0
- package/src/protocol.ts +196 -0
- package/src/routes.ts +191 -0
|
@@ -0,0 +1,206 @@
|
|
|
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
|
+
custom: '自定义',
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const KIND_OPTIONS = Object.keys(KIND_LABELS) as AuthorStyleAsset['kind'][]
|
|
22
|
+
|
|
23
|
+
const KIND_COLORS: Record<AuthorStyleAsset['kind'], string> = {
|
|
24
|
+
style: 'var(--nf-info)',
|
|
25
|
+
antiAi: 'var(--nf-warn)',
|
|
26
|
+
progression: 'var(--nf-accent)',
|
|
27
|
+
genre: 'var(--nf-info)',
|
|
28
|
+
roleTemplate: 'var(--nf-accent)',
|
|
29
|
+
worldTemplate: 'var(--nf-warn)',
|
|
30
|
+
custom: 'var(--nf-muted)',
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
/** 计算资产的分组(分类):题材按顶层题材名('/' 之前),其余按类型。 */
|
|
34
|
+
function assetCategory(a: AuthorStyleAsset): string {
|
|
35
|
+
if (a.kind === 'genre') {
|
|
36
|
+
const top = a.name.split('/')[0]?.trim()
|
|
37
|
+
return top !== undefined && top !== '' ? top : '题材'
|
|
38
|
+
}
|
|
39
|
+
return KIND_LABELS[a.kind] ?? '其他'
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
interface EditorState {
|
|
43
|
+
id?: string
|
|
44
|
+
name: string; kind: AuthorStyleAsset['kind']; summary: string; content: string; tags: string; sourceBooks: string
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
function emptyEditor(): EditorState {
|
|
48
|
+
return { name: '', kind: 'style', summary: '', content: '', tags: '', sourceBooks: '' }
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export function AuthorAssetsView({ api }: { api: NovelApi }) {
|
|
52
|
+
const [assets, setAssets] = useState<AuthorStyleAsset[]>([]);
|
|
53
|
+
const [editing, setEditing] = useState<EditorState | null>(null);
|
|
54
|
+
const [error, setError] = useState('');
|
|
55
|
+
const [busy, setBusy] = useState(false);
|
|
56
|
+
const [kindFilter, setKindFilter] = useState<AuthorStyleAsset['kind'] | 'all'>('all');
|
|
57
|
+
|
|
58
|
+
const load = async (): Promise<void> => {
|
|
59
|
+
try { const res = await api.authorAssets(); setAssets(res.assets.items) } catch (err) { setError((err as Error).message) }
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
/** 导入默认:把书架书的写作资产/角色 + 内置全局库批量沉淀到作者资产库。 */
|
|
63
|
+
const importDefaults = async (): Promise<void> => {
|
|
64
|
+
setBusy(true); setError('');
|
|
65
|
+
try { const res = await api.authorAssetsImportDefault(); setAssets(res.assets.items) } catch (err) { setError((err as Error).message) } finally { setBusy(false) }
|
|
66
|
+
};
|
|
67
|
+
|
|
68
|
+
// 打开即加载;若资产库为空,自动导入默认(书架资产 + 内置全局库)。
|
|
69
|
+
useEffect(() => {
|
|
70
|
+
let cancelled = false
|
|
71
|
+
void (async () => {
|
|
72
|
+
try {
|
|
73
|
+
const res = await api.authorAssets()
|
|
74
|
+
if (cancelled) return
|
|
75
|
+
if (res.assets.items.length === 0) {
|
|
76
|
+
const imp = await api.authorAssetsImportDefault()
|
|
77
|
+
if (!cancelled) setAssets(imp.assets.items)
|
|
78
|
+
} else {
|
|
79
|
+
setAssets(res.assets.items)
|
|
80
|
+
}
|
|
81
|
+
} catch (err) {
|
|
82
|
+
if (!cancelled) setError((err as Error).message)
|
|
83
|
+
}
|
|
84
|
+
})()
|
|
85
|
+
return () => { cancelled = true }
|
|
86
|
+
}, [api]);
|
|
87
|
+
|
|
88
|
+
const startNew = (): void => { setEditing(emptyEditor()); setError('') };
|
|
89
|
+
const startEdit = (a: AuthorStyleAsset): void => {
|
|
90
|
+
setEditing({ id: a.id, name: a.name, kind: a.kind, summary: a.summary, content: a.content, tags: a.tags.join('、'), sourceBooks: a.sourceBooks.join('、') });
|
|
91
|
+
setError('');
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
const save = async (): Promise<void> => {
|
|
95
|
+
if (editing === null) return;
|
|
96
|
+
if (editing.name.trim() === '') { setError('请填写资产名'); return }
|
|
97
|
+
setBusy(true); setError('');
|
|
98
|
+
try {
|
|
99
|
+
const asset: AuthorStyleAsset = {
|
|
100
|
+
id: editing.id ?? '', name: editing.name.trim(), kind: editing.kind, summary: editing.summary.trim(), content: editing.content.trim(),
|
|
101
|
+
sourceBooks: editing.sourceBooks.split(/[、,,\s]+/).map(s => s.trim()).filter(Boolean),
|
|
102
|
+
tags: editing.tags.split(/[、,,\s]+/).map(s => s.trim()).filter(Boolean),
|
|
103
|
+
createdAt: '', updatedAt: '',
|
|
104
|
+
};
|
|
105
|
+
await api.authorAssetsUpsert(asset); setEditing(null); await load();
|
|
106
|
+
} catch (err) { setError((err as Error).message) } finally { setBusy(false) }
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const del = async (id: string): Promise<void> => {
|
|
110
|
+
setBusy(true); setError('');
|
|
111
|
+
try { await api.authorAssetsRemove(id); await load() } catch (err) { setError((err as Error).message) } finally { setBusy(false) }
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
const visible = useMemo(() => (kindFilter === 'all' ? assets : assets.filter(a => a.kind === kindFilter)), [assets, kindFilter]);
|
|
115
|
+
|
|
116
|
+
/** 按分类分组展示(题材按顶层题材名,其余按类型)。 */
|
|
117
|
+
const grouped = useMemo(() => {
|
|
118
|
+
const map = new Map<string, AuthorStyleAsset[]>()
|
|
119
|
+
for (const a of visible) {
|
|
120
|
+
const cat = assetCategory(a)
|
|
121
|
+
const arr = map.get(cat) ?? []
|
|
122
|
+
arr.push(a)
|
|
123
|
+
map.set(cat, arr)
|
|
124
|
+
}
|
|
125
|
+
return Array.from(map.entries()).sort((x, y) => x[0].localeCompare(y[0], 'zh'))
|
|
126
|
+
}, [visible]);
|
|
127
|
+
|
|
128
|
+
return (
|
|
129
|
+
<div className={css.authorPageBody}>
|
|
130
|
+
<div className={css.authorPageHero}>
|
|
131
|
+
<div className={css.authorPageHeader}>
|
|
132
|
+
<div>
|
|
133
|
+
<h2 className={css.panelTitle} style={{ margin: 0 }}>🧬 作者资产库 · 总数据</h2>
|
|
134
|
+
<span className={css.meta}>跨书可复用的笔法/红线/套路/角色模板/世界观模板。任意新书与改编都能调用。</span>
|
|
135
|
+
</div>
|
|
136
|
+
<div className={css.rowEnd}>
|
|
137
|
+
<button type="button" className={css.button + ' ' + css.buttonSmall} onClick={() => { void importDefaults() }} disabled={busy} title="把书架里所有书的写作资产/角色 + 内置题材/反AI/风格模板/推进模式批量导入">导入默认资产</button>
|
|
138
|
+
<button type="button" className={css.button + ' ' + css.buttonPrimary} onClick={startNew}><Plus size={14} style={{ verticalAlign: -2 }} /> 新增资产</button>
|
|
139
|
+
</div>
|
|
140
|
+
</div>
|
|
141
|
+
<div className={css.assetFilterBar}>
|
|
142
|
+
{KIND_OPTIONS.map(k => (
|
|
143
|
+
<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>
|
|
144
|
+
))}
|
|
145
|
+
</div>
|
|
146
|
+
</div>
|
|
147
|
+
|
|
148
|
+
{error !== '' && <div className={css.noticeError}>{error}</div>}
|
|
149
|
+
|
|
150
|
+
{editing !== null ? (
|
|
151
|
+
<div className={css.assetEditor}>
|
|
152
|
+
<h3 style={{ margin: 0 }}>{editing.id !== '' && editing.id !== undefined ? '编辑资产' : '新增资产'}</h3>
|
|
153
|
+
<div className={css.assetEditorRow}>
|
|
154
|
+
<label className={css.assetLabel}>资产名 <input className={css.input} value={editing.name} onChange={e => setEditing({ ...editing, name: e.target.value })} placeholder="如:短句快节奏爽文风" /></label>
|
|
155
|
+
<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>
|
|
156
|
+
</div>
|
|
157
|
+
<label className={css.assetLabel}>一句话摘要 <input className={css.input} value={editing.summary} onChange={e => setEditing({ ...editing, summary: e.target.value })} placeholder="这个资产解决什么问题 / 有什么特点" /></label>
|
|
158
|
+
<label className={css.assetLabel}>内容(按类型约定的描述 / 规则 / 结构化文本)
|
|
159
|
+
<textarea className={`${css.input} ${css.assetTextarea}`} value={editing.content} onChange={e => setEditing({ ...editing, content: e.target.value })} placeholder={'角色模板示例:\n姓名:林越\n定位:痞坏型主角\n口头禅:"有点意思"\n性格:表面懒散、内里狠辣\n成长弧线:从底层游街到一方枭雄'} />
|
|
160
|
+
</label>
|
|
161
|
+
<div className={css.assetEditorRow}>
|
|
162
|
+
<label className={css.assetLabel}>标签(顿号分隔) <input className={css.input} value={editing.tags} onChange={e => setEditing({ ...editing, tags: e.target.value })} placeholder="扮猪吃虎、快节奏、冷面" /></label>
|
|
163
|
+
<label className={css.assetLabel}>来源书(顿号分隔) <input className={css.input} value={editing.sourceBooks} onChange={e => setEditing({ ...editing, sourceBooks: e.target.value })} placeholder="《某某传》《某某录》" /></label>
|
|
164
|
+
</div>
|
|
165
|
+
<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>
|
|
166
|
+
</div>
|
|
167
|
+
) : null}
|
|
168
|
+
|
|
169
|
+
{visible.length === 0 ? (
|
|
170
|
+
<div className={css.shelfEmpty} style={{ minHeight: 160 }}>
|
|
171
|
+
<span className={css.shelfEmptyIcon}><Plus size={30} /></span>
|
|
172
|
+
<span className={css.shelfEmptyTitle}>还没有资产</span>
|
|
173
|
+
<span className={css.meta}>点「新增资产」收藏你的笔法/角色模板/套路,跨书调用。</span>
|
|
174
|
+
</div>
|
|
175
|
+
) : (
|
|
176
|
+
<div className={css.assetGroups}>
|
|
177
|
+
{grouped.map(([cat, items]) => (
|
|
178
|
+
<div key={cat} className={css.assetGroup}>
|
|
179
|
+
<div className={css.assetGroupHeader}>{cat} <span className={css.meta}>{items.length}</span></div>
|
|
180
|
+
<div className={css.assetGrid}>
|
|
181
|
+
{items.map(a => (
|
|
182
|
+
<div key={a.id} className={css.assetCard}>
|
|
183
|
+
<div className={css.assetCardTop}>
|
|
184
|
+
<span className={css.assetKind} style={{ color: KIND_COLORS[a.kind] }}>{KIND_LABELS[a.kind]}</span>
|
|
185
|
+
<div className={css.rowEnd}>
|
|
186
|
+
<button type="button" className={css.iconBtn} title="编辑" onClick={() => startEdit(a)}><Pencil size={13} /></button>
|
|
187
|
+
<button type="button" className={css.iconBtn} title="删除" onClick={() => { void del(a.id) }}><Trash2 size={13} /></button>
|
|
188
|
+
</div>
|
|
189
|
+
</div>
|
|
190
|
+
<div className={css.assetCardName}>{a.name}</div>
|
|
191
|
+
{a.summary !== '' && <div className={css.meta}>{a.summary}</div>}
|
|
192
|
+
<div className={css.assetCardContent}>{a.content}</div>
|
|
193
|
+
<div className={css.assetCardFooter}>
|
|
194
|
+
{a.tags.map(t => <span key={t} className={css.badge}>{t}</span>)}
|
|
195
|
+
{a.sourceBooks.length > 0 && <span className={css.meta}>来源:{a.sourceBooks.join(' / ')}</span>}
|
|
196
|
+
</div>
|
|
197
|
+
</div>
|
|
198
|
+
))}
|
|
199
|
+
</div>
|
|
200
|
+
</div>
|
|
201
|
+
))}
|
|
202
|
+
</div>
|
|
203
|
+
)}
|
|
204
|
+
</div>
|
|
205
|
+
);
|
|
206
|
+
}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 作者级首页容器:书架页左侧导航 + 内容区。
|
|
3
|
+
* 导航复用工作区 .panelNav 玻璃卡片样式(同款),导航项为作者级:书架/改编/资产库/全局资产库/AI 进度/设置。
|
|
4
|
+
*/
|
|
5
|
+
import { useState } from 'react'
|
|
6
|
+
import { Library, Wand2, Boxes, Brush, BarChart3, Settings, Info } 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 { ProgressHomeView } from './ProgressHomeView.tsx'
|
|
13
|
+
import { SettingsView } from './SettingsView.tsx'
|
|
14
|
+
import css from './panel.module.css'
|
|
15
|
+
|
|
16
|
+
type AuthorNav = 'shelf' | 'adapt' | 'assets' | 'library' | 'progress' | 'settings';
|
|
17
|
+
|
|
18
|
+
const NAV_ITEMS: Array<{ id: Exclude<AuthorNav, 'settings'>; label: string; icon: JSX.Element; hint: string }> = [
|
|
19
|
+
{ id: 'shelf', label: '书架', icon: <Library size={18} />, hint: '我的书' },
|
|
20
|
+
{ id: 'adapt', label: '改编模式', icon: <Wand2 size={18} />, hint: '上传全文→可改范围' },
|
|
21
|
+
{ id: 'assets', label: '作者资产库', icon: <Boxes size={18} />, hint: '跨书总数据' },
|
|
22
|
+
{ id: 'library', label: '全局写作资产库', icon: <Brush size={18} />, hint: '内置题材/规则/模板' },
|
|
23
|
+
{ id: 'progress', label: 'AI 进度', icon: <BarChart3 size={18} />, hint: '书架级聚合进度' },
|
|
24
|
+
];
|
|
25
|
+
|
|
26
|
+
function Placeholder({ title, hint }: { title: string; hint: string }) {
|
|
27
|
+
return (
|
|
28
|
+
<div className={css.authorPageBody}>
|
|
29
|
+
<div className={css.authorPageHeader}><h2 className={css.panelTitle} style={{ margin: 0 }}>{title}</h2><span className={css.meta}>{hint}</span></div>
|
|
30
|
+
<div className={css.shelfEmpty} style={{ minHeight: 160 }}>
|
|
31
|
+
<span className={css.shelfEmptyIcon}><Info size={30} /></span>
|
|
32
|
+
<span className={css.shelfEmptyTitle}>此入口为占位</span>
|
|
33
|
+
<span className={css.meta}>后续版本实现。当前「全局写作资产库」可进入某本书「创作资产」页查看内置题材库/反AI规则库/风格模板;「设置」为独立设置页。</span>
|
|
34
|
+
</div>
|
|
35
|
+
</div>
|
|
36
|
+
);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export function AuthorHome({ api, shelf, onOpenBook, onReadBook, onAddBook, onImportBook, onOpenSettings, onTheme, onBackground, onOpacity, adaptEnabled }: {
|
|
40
|
+
api: NovelApi; shelf: BookshelfSnapshot;
|
|
41
|
+
onOpenBook: (id: string) => void; onReadBook: (id: string) => void; onAddBook: () => void; onImportBook: () => void;
|
|
42
|
+
/** 兼容旧入口:首页设置现为独立设置页,此回调保留但不再使用。 */
|
|
43
|
+
onOpenSettings?: () => void;
|
|
44
|
+
/** 主题/模式/密度变化回调(供面板根容器实时生效)。 */
|
|
45
|
+
onTheme?: (theme: 'liquid' | 'neumorph' | 'macos' | 'clay', mode: 'system' | 'light' | 'dark', density: 'comfort' | 'compact' | 'spacious') => void;
|
|
46
|
+
/** 自定义背景变化回调。 */
|
|
47
|
+
onBackground?: (bg: string | undefined, blur: number) => void;
|
|
48
|
+
/** 玻璃透明度变化回调。 */
|
|
49
|
+
onOpacity?: (n: number) => void;
|
|
50
|
+
/** 是否启用改编模式(默认 false=隐藏入口)。 */
|
|
51
|
+
adaptEnabled?: boolean;
|
|
52
|
+
}) {
|
|
53
|
+
const [nav, setNav] = useState<AuthorNav>('shelf');
|
|
54
|
+
|
|
55
|
+
return (
|
|
56
|
+
<div className={css.authorHome}>
|
|
57
|
+
<nav className={css.panelNav} aria-label="作者级导航">
|
|
58
|
+
<div className={css.navTitle}>
|
|
59
|
+
<div className={css.navTitleLogo}>书</div>
|
|
60
|
+
<div style={{ minWidth: 0 }}>
|
|
61
|
+
<div className={css.navTitleName}>小说工坊</div>
|
|
62
|
+
<div className={css.navTitleBook}>作者级 · 跨书</div>
|
|
63
|
+
</div>
|
|
64
|
+
</div>
|
|
65
|
+
<div className={css.navGroup}>
|
|
66
|
+
<div className={css.navGroupLabel}>作者</div>
|
|
67
|
+
{NAV_ITEMS.filter(item => item.id !== 'adapt' || adaptEnabled).map(item => (
|
|
68
|
+
<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)}>
|
|
69
|
+
<span className={css.navTabIcon}>{item.icon}</span>
|
|
70
|
+
<span className={css.navTabLabel}>{item.label}</span>
|
|
71
|
+
</button>
|
|
72
|
+
))}
|
|
73
|
+
</div>
|
|
74
|
+
<div className={css.navSpacer} />
|
|
75
|
+
<button type="button" role="tab" aria-selected={nav === 'settings'} data-active={nav === 'settings' ? '' : undefined} className={css.navTab} title="设置" onClick={() => setNav('settings')}>
|
|
76
|
+
<span className={css.navTabIcon}><Settings size={18} /></span>
|
|
77
|
+
<span className={css.navTabLabel}>设置</span>
|
|
78
|
+
</button>
|
|
79
|
+
<div className={css.navAbout}>
|
|
80
|
+
<div className={css.navAboutRow}><span>ℹ️ v1.7.3 · 改编/资产库</span></div>
|
|
81
|
+
</div>
|
|
82
|
+
</nav>
|
|
83
|
+
<div className={css.authorContent}>
|
|
84
|
+
{nav === 'shelf' && <ShelfView api={api} shelf={shelf} onOpenBook={onOpenBook} onReadBook={onReadBook} onAddBook={onAddBook} onImportBook={onImportBook} />}
|
|
85
|
+
{nav === 'adapt' && <AdaptModeView api={api} />}
|
|
86
|
+
{nav === 'assets' && <AuthorAssetsView api={api} />}
|
|
87
|
+
{nav === 'library' && <Placeholder title="🎨 全局写作资产库" hint="内置题材基底库 / 反AI规则库 / 风格模板 / 推进模式(跨书)" />}
|
|
88
|
+
{nav === 'progress' && <ProgressHomeView shelf={shelf} onOpenBook={onOpenBook} />}
|
|
89
|
+
{nav === 'settings' && <SettingsView api={api} onTheme={onTheme} onBackground={onBackground} onOpacity={onOpacity} />}
|
|
90
|
+
</div>
|
|
91
|
+
</div>
|
|
92
|
+
);
|
|
93
|
+
}
|
|
@@ -7,6 +7,7 @@
|
|
|
7
7
|
import { useEffect, useRef, useState } from 'react'
|
|
8
8
|
import type { NovelApi } from '../api.ts'
|
|
9
9
|
import type { BookImportTextPreviewResponse } from '../../protocol.ts'
|
|
10
|
+
import { readFileTextSmart } from '../text.ts'
|
|
10
11
|
import css from './panel.module.css'
|
|
11
12
|
|
|
12
13
|
type ImportMode = 'dir' | 'text'
|
|
@@ -57,7 +58,7 @@ export function ImportModal({
|
|
|
57
58
|
setFileName(file.name)
|
|
58
59
|
setPreviewing(true)
|
|
59
60
|
try {
|
|
60
|
-
const text = await file
|
|
61
|
+
const text = await readFileTextSmart(file)
|
|
61
62
|
setFileText(text)
|
|
62
63
|
const p = await api.bookImportTextPreview(text, file.name)
|
|
63
64
|
setPreview(p)
|
|
@@ -13,6 +13,7 @@ import { BarChart3, Book, BookMarked, BookOpen, Brain, Clapperboard, Factory, Fi
|
|
|
13
13
|
import { AssistantTab } from './AssistantTab.tsx'
|
|
14
14
|
import { AssetsTab } from './AssetsTab.tsx'
|
|
15
15
|
import { ShelfView } from './ShelfView.tsx'
|
|
16
|
+
import { AuthorHome } from './AuthorHome.tsx'
|
|
16
17
|
import { ReaderView } from './ReaderView.tsx'
|
|
17
18
|
import { RunPanel } from './RunPanel.tsx'
|
|
18
19
|
import { CreateBookView } from './CreateBookView.tsx'
|
|
@@ -73,36 +74,36 @@ const NAV_GROUPS: ReadonlyArray<{ id: string; label: string; items: ReadonlyArra
|
|
|
73
74
|
id: 'create',
|
|
74
75
|
label: '创作',
|
|
75
76
|
items: [
|
|
76
|
-
{ id: 'workflow', label: tt('tab.workflow'), icon: <Wrench size={
|
|
77
|
-
{ id: 'overview', label: tt('tab.overview'), icon: <FileText size={
|
|
78
|
-
{ id: 'blurb', label: '简介 / 封面', icon: <BookOpen size={
|
|
79
|
-
{ id: 'plan', label: tt('tab.plan'), icon: <BookMarked size={
|
|
80
|
-
{ id: 'plotlines', label: '长线管理', icon: <ScrollText size={
|
|
81
|
-
{ id: 'book', label: '本书设定', icon: <Library size={
|
|
77
|
+
{ id: 'workflow', label: tt('tab.workflow'), icon: <Wrench size={18} /> },
|
|
78
|
+
{ id: 'overview', label: tt('tab.overview'), icon: <FileText size={18} /> },
|
|
79
|
+
{ id: 'blurb', label: '简介 / 封面', icon: <BookOpen size={18} /> },
|
|
80
|
+
{ id: 'plan', label: tt('tab.plan'), icon: <BookMarked size={18} /> },
|
|
81
|
+
{ id: 'plotlines', label: '长线管理', icon: <ScrollText size={18} /> },
|
|
82
|
+
{ id: 'book', label: '本书设定', icon: <Library size={18} /> },
|
|
82
83
|
],
|
|
83
84
|
},
|
|
84
85
|
{
|
|
85
86
|
id: 'tools',
|
|
86
87
|
label: '工具',
|
|
87
88
|
items: [
|
|
88
|
-
{ id: 'assistant', label: tt('tab.assistant'), icon: <MessageSquare size={
|
|
89
|
-
{ id: 'progress', label: 'AI 进度', icon: <BarChart3 size={
|
|
90
|
-
{ id: 'breakdown', label: '拆书分析', icon: <Search size={
|
|
91
|
-
{ id: 'manhua', label: '漫剧工作台', icon: <Clapperboard size={
|
|
92
|
-
{ id: 'run', label: '生产单', icon: <Factory size={
|
|
89
|
+
{ id: 'assistant', label: tt('tab.assistant'), icon: <MessageSquare size={18} /> },
|
|
90
|
+
{ id: 'progress', label: 'AI 进度', icon: <BarChart3 size={18} /> },
|
|
91
|
+
{ id: 'breakdown', label: '拆书分析', icon: <Search size={18} /> },
|
|
92
|
+
{ id: 'manhua', label: '漫剧工作台', icon: <Clapperboard size={18} /> },
|
|
93
|
+
{ id: 'run', label: '生产单', icon: <Factory size={18} /> },
|
|
93
94
|
],
|
|
94
95
|
},
|
|
95
96
|
{
|
|
96
97
|
id: 'assets',
|
|
97
98
|
label: '资产',
|
|
98
99
|
items: [
|
|
99
|
-
{ id: 'assets', label: '创作资产', icon: <Wrench size={
|
|
100
|
+
{ id: 'assets', label: '创作资产', icon: <Wrench size={18} /> },
|
|
100
101
|
],
|
|
101
102
|
},
|
|
102
103
|
]
|
|
103
104
|
|
|
104
105
|
/** Settings tab — pinned to the bottom of the nav rail. */
|
|
105
|
-
const SETTINGS_TAB: { id: NovelTab; label: string; icon: ReactElement } = { id: 'settings', label: tt('tab.settings'), icon: <Settings size={
|
|
106
|
+
const SETTINGS_TAB: { id: NovelTab; label: string; icon: ReactElement } = { id: 'settings', label: tt('tab.settings'), icon: <Settings size={18} /> }
|
|
106
107
|
|
|
107
108
|
/** Common DeepSeek model presets shown in settings; users can also type any model id. */
|
|
108
109
|
const MODEL_PRESETS = ['deepseek-v4-flash', 'deepseek-v4-pro', 'deepseek-chat', 'deepseek-reasoner'] as const
|
|
@@ -316,6 +317,12 @@ function DiffList({ original, draft, fontSize }: { original: string; draft: stri
|
|
|
316
317
|
export function NovelPanel({ controller, api }: NovelPanelProps) {
|
|
317
318
|
const [activeTab, setActiveTab] = useState<NovelTab>('workflow')
|
|
318
319
|
const [config, setConfig] = useState<NovelConfig | null>(null)
|
|
320
|
+
/** 自定义背景(URL / dataURL),覆盖主题默认背景。 */
|
|
321
|
+
const [themeBg, setThemeBg] = useState<string | undefined>(undefined)
|
|
322
|
+
/** 自定义背景遮罩/模糊强度 0-80。 */
|
|
323
|
+
const [themeBgBlur, setThemeBgBlur] = useState(0)
|
|
324
|
+
/** 玻璃透明度 0-100(100=主题原样)。 */
|
|
325
|
+
const [themeOpacity, setThemeOpacity] = useState(100)
|
|
319
326
|
const [project, setProject] = useState<ProjectState | null>(null)
|
|
320
327
|
const [generatedFiles, setGeneratedFiles] = useState<string[]>([])
|
|
321
328
|
const [outlineText, setOutlineText] = useState('')
|
|
@@ -748,6 +755,17 @@ export function NovelPanel({ controller, api }: NovelPanelProps) {
|
|
|
748
755
|
}
|
|
749
756
|
}, [api, refresh, refreshShelf])
|
|
750
757
|
|
|
758
|
+
/** 首页「设置」与书内设置同入口:激活当前/首选书并跳到设置页。 */
|
|
759
|
+
const openSettingsFromHome = async (): Promise<void> => {
|
|
760
|
+
const targetId = shelf?.activeBookId ?? shelf?.books[0]?.id ?? null
|
|
761
|
+
if (targetId === null || targetId === undefined) {
|
|
762
|
+
setError('请先在书架开一本书;设置页以书籍工作台为入口')
|
|
763
|
+
return
|
|
764
|
+
}
|
|
765
|
+
await activateBook(targetId, 'workspace')
|
|
766
|
+
setActiveTab('settings')
|
|
767
|
+
}
|
|
768
|
+
|
|
751
769
|
/** Handle a docx file (pick or drag): parse locally, save outline. */
|
|
752
770
|
const handleDocxFile = useCallback(async (file: File) => {
|
|
753
771
|
setBusy(true)
|
|
@@ -2364,12 +2382,20 @@ export function NovelPanel({ controller, api }: NovelPanelProps) {
|
|
|
2364
2382
|
n += assets?.antiAiRules?.length ?? 0
|
|
2365
2383
|
return n
|
|
2366
2384
|
})()
|
|
2385
|
+
/** 自定义背景:优先用户显式选择(themeBg),否则用 config 里的持久化值。 */
|
|
2386
|
+
const effectiveBg = themeBg !== undefined && themeBg !== '' ? themeBg : (config?.themeBackground ?? '')
|
|
2387
|
+
const effectiveBgBlur = themeBgBlur > 0 ? themeBgBlur : (config?.themeBackgroundBlur ?? 0)
|
|
2388
|
+
const effectiveOpacity = themeOpacity > 0 ? themeOpacity : (config?.themeOpacity ?? 100)
|
|
2389
|
+
const panelBgStyle: Record<string, string> = {}
|
|
2390
|
+
if (effectiveBg !== '') panelBgStyle['--nf-glass-bg-image' as string] = 'url(' + effectiveBg + ')'
|
|
2391
|
+
if (effectiveBgBlur > 0) panelBgStyle['--nf-glass-bg-dim' as string] = String(effectiveBgBlur)
|
|
2392
|
+
panelBgStyle['--nf-glass-opacity' as string] = String(effectiveOpacity) + '%'
|
|
2367
2393
|
|
|
2368
2394
|
return (
|
|
2369
|
-
<div className={css.panel} data-nf-theme={panelTheme} data-nf-mode={themeMode === 'system' ? undefined : themeMode} data-nf-density={themeDensity}>
|
|
2395
|
+
<div className={css.panel} data-nf-theme={panelTheme} data-nf-mode={themeMode === 'system' ? undefined : themeMode} data-nf-density={themeDensity} style={panelBgStyle}>
|
|
2370
2396
|
{viewMode === 'shelf' ? (
|
|
2371
|
-
/*
|
|
2372
|
-
<
|
|
2397
|
+
/* 书架首页:作者级左侧导航 + 书架/改编/资产库/设置 */
|
|
2398
|
+
<AuthorHome
|
|
2373
2399
|
api={api}
|
|
2374
2400
|
shelf={shelf ?? { books: [], activeBookId: null }}
|
|
2375
2401
|
onOpenBook={async (id) => {
|
|
@@ -2380,6 +2406,11 @@ export function NovelPanel({ controller, api }: NovelPanelProps) {
|
|
|
2380
2406
|
}}
|
|
2381
2407
|
onAddBook={() => { setViewMode('create') }}
|
|
2382
2408
|
onImportBook={() => { setShowImport(true) }}
|
|
2409
|
+
onOpenSettings={() => { void openSettingsFromHome() }}
|
|
2410
|
+
onTheme={(t, m, d) => { changePanelTheme(t); changeThemeMode(m); changeThemeDensity(d) }}
|
|
2411
|
+
onBackground={(bg, blur) => { setThemeBg(bg); setThemeBgBlur(blur) }}
|
|
2412
|
+
onOpacity={(n) => { setThemeOpacity(n) }}
|
|
2413
|
+
adaptEnabled={config?.enableAdaptMode === true}
|
|
2383
2414
|
/>
|
|
2384
2415
|
) : viewMode === 'create' ? (
|
|
2385
2416
|
/* 开书向导:独立页面 */
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 首页 AI 进度视图:书架级聚合进度——总览 + 每本书进度条 + 进行中高亮。
|
|
3
|
+
* 读取 BookshelfSnapshot,不依赖打开某本书。
|
|
4
|
+
*/
|
|
5
|
+
import { useMemo } from 'react'
|
|
6
|
+
import { BarChart3, BookOpen, PenLine, CheckCircle2, Clock, RefreshCw } from 'lucide-react'
|
|
7
|
+
import type { BookshelfSnapshot } from '../../protocol.ts'
|
|
8
|
+
import css from './panel.module.css'
|
|
9
|
+
|
|
10
|
+
function relativeTime(iso: string): string {
|
|
11
|
+
const t = new Date(iso).getTime()
|
|
12
|
+
if (!Number.isFinite(t)) return '—'
|
|
13
|
+
const diff = Date.now() - t
|
|
14
|
+
if (diff < 60_000) return '刚刚'
|
|
15
|
+
if (diff < 3_600_000) return Math.floor(diff / 60_000) + ' 分钟前'
|
|
16
|
+
if (diff < 86_400_000) return Math.floor(diff / 3_600_000) + ' 小时前'
|
|
17
|
+
if (diff < 7 * 86_400_000) return Math.floor(diff / 86_400_000) + ' 天前'
|
|
18
|
+
return new Date(t).toLocaleDateString('zh-CN', { month: 'numeric', day: 'numeric' })
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
function bookStatus(book: BookshelfSnapshot['books'][number]): 'none' | 'done' | 'active' {
|
|
22
|
+
if (!book.hasProject) return 'none'
|
|
23
|
+
return book.total > 0 && book.done >= book.total ? 'done' : 'active'
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export function ProgressHomeView({ shelf, onOpenBook }: {
|
|
27
|
+
shelf: BookshelfSnapshot;
|
|
28
|
+
onOpenBook: (id: string) => void;
|
|
29
|
+
}) {
|
|
30
|
+
const stats = useMemo(() => {
|
|
31
|
+
let active = 0, done = 0, none = 0, chapters = 0, written = 0;
|
|
32
|
+
for (const b of shelf.books) {
|
|
33
|
+
const s = bookStatus(b)
|
|
34
|
+
if (s === 'none') none++; else if (s === 'done') done++; else active++;
|
|
35
|
+
chapters += b.total;
|
|
36
|
+
written += b.done;
|
|
37
|
+
}
|
|
38
|
+
return { active, done, none, chapters, written }
|
|
39
|
+
}, [shelf.books]);
|
|
40
|
+
|
|
41
|
+
const progressPct = stats.chapters > 0 ? Math.round((stats.written / stats.chapters) * 100) : 0;
|
|
42
|
+
|
|
43
|
+
return (
|
|
44
|
+
<div className={css.authorPageBody}>
|
|
45
|
+
<div className={css.authorPageHeader}><h2 className={css.panelTitle} style={{ margin: 0 }}>📊 AI 进度</h2><span className={css.meta}>跨书架聚合进度与最近活动</span></div>
|
|
46
|
+
|
|
47
|
+
<div className={css.progressOverview}>
|
|
48
|
+
<div className={css.progressOverviewCard}><span className={css.progressOverviewNum}>{shelf.books.length}</span><span className={css.meta}>总书数</span></div>
|
|
49
|
+
<div className={css.progressOverviewCard}><span className={css.progressOverviewNum}>{stats.active}</span><span className={css.meta}>进行中</span></div>
|
|
50
|
+
<div className={css.progressOverviewCard}><span className={css.progressOverviewNum}>{stats.done}</span><span className={css.meta}>已完结</span></div>
|
|
51
|
+
<div className={css.progressOverviewCard}><span className={css.progressOverviewNum}>{stats.written}/{stats.chapters}</span><span className={css.meta}>已完成章节</span></div>
|
|
52
|
+
</div>
|
|
53
|
+
|
|
54
|
+
<div className={css.progressTotalBar}><div className={css.progressTotalFill} style={{ width: progressPct + '%' }} /><span className={css.meta}>全书架整体进度 {progressPct}%</span></div>
|
|
55
|
+
|
|
56
|
+
{shelf.books.length === 0 ? (
|
|
57
|
+
<div className={css.shelfEmpty} style={{ minHeight: 160 }}>
|
|
58
|
+
<span className={css.shelfEmptyIcon}><BarChart3 size={30} /></span>
|
|
59
|
+
<span className={css.shelfEmptyTitle}>还没有书</span>
|
|
60
|
+
<span className={css.meta}>去书架开一本书或导入全文后,这里会显示进度。</span>
|
|
61
|
+
</div>
|
|
62
|
+
) : (
|
|
63
|
+
<div className={css.progressBookList}>
|
|
64
|
+
{shelf.books.map(book => {
|
|
65
|
+
const s = bookStatus(book)
|
|
66
|
+
const ratio = book.total > 0 ? Math.min(book.done / book.total, 1) : 0;
|
|
67
|
+
const statusLabel = s === 'none' ? '未开书' : s === 'done' ? '已完结' : '进行中';
|
|
68
|
+
return (
|
|
69
|
+
<div key={book.id} className={css.progressBook + (s === 'active' ? ' ' + css.progressBookActive : '')}>
|
|
70
|
+
<div className={css.progressBookHead}>
|
|
71
|
+
<span className={css.progressBookName} title={book.bookName}>{book.bookName}</span>
|
|
72
|
+
<span className={css.badge + (s === 'done' ? ' ' + css.badgeDone : s === 'active' ? ' ' + css.badgeWritten : ' ' + css.badgePending)}>{statusLabel}</span>
|
|
73
|
+
{s === 'active' && <span className={css.meta + ' ' + css.progressLive}><RefreshCw size={12} style={{ verticalAlign: -2 }} /> 创作中</span>}
|
|
74
|
+
</div>
|
|
75
|
+
<div className={css.progressBookBar}><div className={css.progressBookFill} style={{ width: Math.round(ratio * 100) + '%' }} /></div>
|
|
76
|
+
<div className={css.rowEnd} style={{ justifyContent: 'space-between' }}>
|
|
77
|
+
<span className={css.meta}>{book.total > 0 ? '已完成 ' + book.done + ' / ' + book.total + ' 章' : '尚未规划章节'} · 更新于 {relativeTime(book.updatedAt)}</span>
|
|
78
|
+
<button type="button" className={css.button + ' ' + css.buttonSmall} onClick={() => onOpenBook(book.id)}><PenLine size={12} style={{ verticalAlign: -2 }} /> 进入</button>
|
|
79
|
+
</div>
|
|
80
|
+
</div>
|
|
81
|
+
);
|
|
82
|
+
})}
|
|
83
|
+
</div>
|
|
84
|
+
)}
|
|
85
|
+
</div>
|
|
86
|
+
);
|
|
87
|
+
}
|