feat(w4): ship v1.5.0 timeline, character arc, and compliance
Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
@@ -20,6 +20,7 @@ import { InspirationModal } from '@renderer/components/inspiration/InspirationMo
|
||||
import { ImportBookModal } from '@renderer/components/import/ImportBookModal'
|
||||
import { ExportAllModal } from '@renderer/components/export/ExportAllModal'
|
||||
import { ReadModeOverlay } from '@renderer/components/read/ReadModeOverlay'
|
||||
import { TimelineModal } from '@renderer/components/timeline/TimelineModal'
|
||||
import { FocusModeOverlay } from '@renderer/components/focus/FocusModeOverlay'
|
||||
import { NamingCheckModal } from '@renderer/components/ai/NamingCheckModal'
|
||||
import { useSearchStore } from '@renderer/stores/useSearchStore'
|
||||
@@ -213,6 +214,7 @@ function AppInner(): React.JSX.Element {
|
||||
<InspirationModal />
|
||||
<ImportBookModal />
|
||||
<ExportAllModal />
|
||||
<TimelineModal />
|
||||
<NamingCheckModal open={namingCheckOpen} onClose={() => setNamingCheckOpen(false)} />
|
||||
{toast && <div className="toast">{toast}</div>}
|
||||
</div>
|
||||
|
||||
@@ -6,6 +6,7 @@ import { useAppStore } from '@renderer/stores/useAppStore'
|
||||
import { useAiStore } from '@renderer/stores/useAiStore'
|
||||
import { useSettingsStore } from '@renderer/stores/useSettingsStore'
|
||||
import { applySlashCommand } from '@renderer/lib/ai-slash-commands'
|
||||
import { useSettingsStore } from '@renderer/stores/useSettingsStore'
|
||||
import { insertToEditor } from '@renderer/lib/editor-commands'
|
||||
import { ipcCall } from '@renderer/lib/ipc-client'
|
||||
import { ContextEditorModal } from '@renderer/components/ai/ContextEditorModal'
|
||||
@@ -29,6 +30,7 @@ const QUICK_CMDS = ['/续写', '/扩写', '/润色', '/总结', '/纠错']
|
||||
export function AiPanel(): React.JSX.Element {
|
||||
const { t } = useTranslation()
|
||||
const showToast = useAppStore((s) => s.showToast)
|
||||
const customSlashCommands = useSettingsStore((s) => s.customSlashCommands)
|
||||
const bookId = useBookStore((s) => s.currentBookId)
|
||||
const sessions = useAiStore((s) => s.sessions)
|
||||
const activeSessionId = useAiStore((s) => s.activeSessionId)
|
||||
@@ -90,7 +92,7 @@ export function AiPanel(): React.JSX.Element {
|
||||
const handleSend = (): void => {
|
||||
const text = input.trim()
|
||||
if (!text || sending || disabled) return
|
||||
const { display, prompt } = applySlashCommand(text, t)
|
||||
const { display, prompt } = applySlashCommand(text, t, customSlashCommands)
|
||||
setInput('')
|
||||
void sendMessage(display, prompt !== display ? prompt : undefined)
|
||||
}
|
||||
|
||||
@@ -11,6 +11,9 @@ import { useBookStore } from '@renderer/stores/useBookStore'
|
||||
import { flushEditSession, registerEditorFlush, useEditStore } from '@renderer/stores/useEditStore'
|
||||
import { ipcCall } from '@renderer/lib/ipc-client'
|
||||
import { SettingRelationshipsEditor } from '@renderer/components/setting/SettingRelationshipsEditor'
|
||||
import { CharacterArcPanel } from '@renderer/components/setting/CharacterArcPanel'
|
||||
import { ComplianceHighlight, compliancePluginKey } from '@renderer/extensions/compliance-highlight'
|
||||
import { useSettingsStore } from '@renderer/stores/useSettingsStore'
|
||||
import { LandmarkMark } from '@renderer/extensions/landmark-mark'
|
||||
import { SettingMention } from '@renderer/extensions/mention'
|
||||
import { registerHighlightToken, registerInsertLandmark, registerEditorInsert, registerEditorGetText } from '@renderer/lib/editor-commands'
|
||||
@@ -90,20 +93,22 @@ export function TipTapEditor({ target, bookId }: TipTapEditorProps): React.JSX.E
|
||||
const [mentionFrom, setMentionFrom] = useState(0)
|
||||
const content = useTargetContent(target)
|
||||
const isChapter = target?.kind === 'chapter'
|
||||
const complianceEnabled = useSettingsStore((s) => s.enableComplianceCheck === true)
|
||||
|
||||
const extensions = useMemo(
|
||||
() =>
|
||||
isChapter
|
||||
? [
|
||||
StarterKit,
|
||||
Underline,
|
||||
LandmarkMark,
|
||||
SettingMention,
|
||||
Placeholder.configure({ placeholder: t('editor.placeholder') })
|
||||
]
|
||||
: [simplifiedKit, Placeholder.configure({ placeholder: t('editor.placeholder') })],
|
||||
[isChapter, t]
|
||||
)
|
||||
const extensions = useMemo(() => {
|
||||
if (!isChapter) {
|
||||
return [simplifiedKit, Placeholder.configure({ placeholder: t('editor.placeholder') })]
|
||||
}
|
||||
const chapterExt = [
|
||||
StarterKit,
|
||||
Underline,
|
||||
LandmarkMark,
|
||||
SettingMention,
|
||||
Placeholder.configure({ placeholder: t('editor.placeholder') })
|
||||
]
|
||||
if (complianceEnabled) chapterExt.push(ComplianceHighlight)
|
||||
return chapterExt
|
||||
}, [isChapter, t, complianceEnabled])
|
||||
|
||||
const mentionCandidates = useMemo(() => {
|
||||
const q = mentionQuery.toLowerCase()
|
||||
@@ -316,6 +321,30 @@ export function TipTapEditor({ target, bookId }: TipTapEditorProps): React.JSX.E
|
||||
return () => registerEditorInsert(null, () => {})
|
||||
}, [editor, bookId, target])
|
||||
|
||||
useEffect(() => {
|
||||
if (!editor || !complianceEnabled || target?.kind !== 'chapter') return
|
||||
let words: string[] = []
|
||||
let timer: ReturnType<typeof setTimeout> | undefined
|
||||
const apply = (): void => {
|
||||
const tr = editor.state.tr
|
||||
tr.setMeta(compliancePluginKey, words)
|
||||
editor.view.dispatch(tr)
|
||||
}
|
||||
void ipcCall(() => window.electronAPI.compliance.getWords()).then((w) => {
|
||||
words = w
|
||||
apply()
|
||||
})
|
||||
const onUpdate = (): void => {
|
||||
clearTimeout(timer)
|
||||
timer = setTimeout(apply, 300)
|
||||
}
|
||||
editor.on('update', onUpdate)
|
||||
return () => {
|
||||
editor.off('update', onUpdate)
|
||||
clearTimeout(timer)
|
||||
}
|
||||
}, [editor, complianceEnabled, target?.kind])
|
||||
|
||||
useEffect(() => {
|
||||
if (!editor) return
|
||||
if (!target) {
|
||||
@@ -368,7 +397,10 @@ export function TipTapEditor({ target, bookId }: TipTapEditorProps): React.JSX.E
|
||||
<div className="editor-content-wrap">
|
||||
<EditorContent editor={editor} />
|
||||
{settingEntry?.type === 'character' && bookId && (
|
||||
<SettingRelationshipsEditor entry={settingEntry} bookId={bookId} />
|
||||
<>
|
||||
<CharacterArcPanel entry={settingEntry} bookId={bookId} />
|
||||
<SettingRelationshipsEditor entry={settingEntry} bookId={bookId} />
|
||||
</>
|
||||
)}
|
||||
{mentionOpen && mentionCandidates.length > 0 && (
|
||||
<div className="mention-dropdown" data-testid="mention-dropdown">
|
||||
|
||||
@@ -126,6 +126,7 @@ export function EditorLayout(): React.JSX.Element {
|
||||
const [templateModalOpen, setTemplateModalOpen] = useState(false)
|
||||
const [chapterMetaOpen, setChapterMetaOpen] = useState(false)
|
||||
const openReadMode = useReadModeStore((s) => s.openForVolume)
|
||||
const setTimelineModalOpen = useAppStore((s) => s.setTimelineModalOpen)
|
||||
const [volumeMenu, setVolumeMenu] = useState<{ volumeId: string; x: number; y: number } | null>(
|
||||
null
|
||||
)
|
||||
@@ -163,6 +164,13 @@ export function EditorLayout(): React.JSX.Element {
|
||||
|
||||
useEffect(() => {
|
||||
if (!selectedChapterId) return
|
||||
if (
|
||||
target?.kind === 'setting' ||
|
||||
target?.kind === 'outline' ||
|
||||
target?.kind === 'inspiration'
|
||||
) {
|
||||
return
|
||||
}
|
||||
if (target?.kind === 'chapter' && target.id === selectedChapterId) return
|
||||
setTarget({ kind: 'chapter', id: selectedChapterId })
|
||||
}, [selectedChapterId, setTarget, target?.kind, target?.id])
|
||||
@@ -405,6 +413,11 @@ export function EditorLayout(): React.JSX.Element {
|
||||
className={`chapter-item ${target?.kind === 'chapter' && target.id === ch.id ? 'active' : ''} ${dragOverChapterId === ch.id ? 'drag-over' : ''}`}
|
||||
draggable
|
||||
data-testid={`chapter-item-${ch.id}`}
|
||||
title={
|
||||
ch.summary?.trim() ||
|
||||
ch.content.replace(/<[^>]+>/g, '').trim().slice(0, 80) ||
|
||||
undefined
|
||||
}
|
||||
onDragStart={(e) => {
|
||||
e.dataTransfer.setData('application/x-bilin-chapter', ch.id)
|
||||
e.dataTransfer.effectAllowed = 'move'
|
||||
@@ -499,6 +512,14 @@ export function EditorLayout(): React.JSX.Element {
|
||||
>
|
||||
+ {t('template.quickNew')}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
data-testid="open-timeline"
|
||||
style={{ marginTop: 6 }}
|
||||
onClick={() => setTimelineModalOpen(true)}
|
||||
>
|
||||
🕐 {t('timeline.open')}
|
||||
</button>
|
||||
<button
|
||||
type="button"
|
||||
data-testid="chapter-read-mode"
|
||||
|
||||
@@ -1,9 +1,16 @@
|
||||
import { useMemo } from 'react'
|
||||
import { useMemo, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import { useBookStore } from '@renderer/stores/useBookStore'
|
||||
import { useReferenceStore } from '@renderer/stores/useReferenceStore'
|
||||
import { useEditStore } from '@renderer/stores/useEditStore'
|
||||
|
||||
type RefItem = {
|
||||
id: string
|
||||
kind: 'setting' | 'outline' | 'inspiration'
|
||||
title: string
|
||||
preview: string
|
||||
}
|
||||
|
||||
export function ReferencePanel(): React.JSX.Element {
|
||||
const { t } = useTranslation()
|
||||
const open = useReferenceStore((s) => s.open)
|
||||
@@ -18,6 +25,7 @@ export function ReferencePanel(): React.JSX.Element {
|
||||
const outlines = useBookStore((s) => s.outlines)
|
||||
const settings = useBookStore((s) => s.settings)
|
||||
const inspirations = useBookStore((s) => s.inspirations)
|
||||
const [detailItem, setDetailItem] = useState<RefItem | null>(null)
|
||||
|
||||
const items = useMemo(() => {
|
||||
const q = query.trim().toLowerCase()
|
||||
@@ -90,13 +98,14 @@ export function ReferencePanel(): React.JSX.Element {
|
||||
{items.map((item) => (
|
||||
<div
|
||||
key={item.id}
|
||||
className="ref-item"
|
||||
className={`ref-item ${detailItem?.id === item.id ? 'active' : ''}`}
|
||||
draggable
|
||||
onDragStart={(e) => {
|
||||
const plain = item.preview.replace(/<[^>]+>/g, '').slice(0, 200)
|
||||
e.dataTransfer.setData('text/plain', plain)
|
||||
}}
|
||||
onClick={() => void switchTarget({ kind: item.kind, id: item.id })}
|
||||
onClick={() => setDetailItem(item)}
|
||||
onDoubleClick={() => void switchTarget({ kind: item.kind, id: item.id })}
|
||||
role="button"
|
||||
tabIndex={0}
|
||||
data-testid={`ref-item-${item.id}`}
|
||||
@@ -108,6 +117,26 @@ export function ReferencePanel(): React.JSX.Element {
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
{detailItem && (
|
||||
<div className="ref-detail-drawer" data-testid="reference-detail-drawer">
|
||||
<div className="ref-detail-header">
|
||||
<strong>{detailItem.title}</strong>
|
||||
<button type="button" className="btn" onClick={() => setDetailItem(null)}>
|
||||
✕
|
||||
</button>
|
||||
</div>
|
||||
<div className="ref-detail-body">
|
||||
{detailItem.preview.replace(/<[^>]+>/g, '')}
|
||||
</div>
|
||||
<button
|
||||
type="button"
|
||||
className="btn btn-primary"
|
||||
onClick={() => void switchTarget({ kind: detailItem.kind, id: detailItem.id })}
|
||||
>
|
||||
{t('reference.openInEditor')}
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,74 @@
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import type { CharacterArcNode } from '@shared/arc'
|
||||
import type { SettingEntry } from '@shared/types'
|
||||
import { useBookStore } from '@renderer/stores/useBookStore'
|
||||
import { useEditStore } from '@renderer/stores/useEditStore'
|
||||
import { ipcCall } from '@renderer/lib/ipc-client'
|
||||
|
||||
interface CharacterArcPanelProps {
|
||||
entry: SettingEntry
|
||||
bookId: string
|
||||
}
|
||||
|
||||
export function CharacterArcPanel({ entry, bookId }: CharacterArcPanelProps): React.JSX.Element {
|
||||
const { t } = useTranslation()
|
||||
const switchTarget = useEditStore((s) => s.switchTarget)
|
||||
const updateSettingLocal = useBookStore((s) => s.updateSettingLocal)
|
||||
const [nodes, setNodes] = useState<CharacterArcNode[]>([])
|
||||
const [birthDate, setBirthDate] = useState(String(entry.properties?.birthDate ?? ''))
|
||||
|
||||
useEffect(() => {
|
||||
setBirthDate(String(entry.properties?.birthDate ?? ''))
|
||||
void ipcCall(() => window.electronAPI.arc.getForCharacter(bookId, entry.id)).then(setNodes)
|
||||
}, [bookId, entry.id, entry.properties?.birthDate, entry.updatedAt])
|
||||
|
||||
const saveBirthDate = async (): Promise<void> => {
|
||||
const updated = await ipcCall(() =>
|
||||
window.electronAPI.setting.update(bookId, entry.id, {
|
||||
properties: { ...entry.properties, birthDate: birthDate.trim() || undefined }
|
||||
})
|
||||
)
|
||||
updateSettingLocal(updated)
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="character-arc-panel" data-testid="character-arc-panel">
|
||||
<h4>{t('arc.title')}</h4>
|
||||
<label className="form-label">{t('arc.birthDate')}</label>
|
||||
<div style={{ display: 'flex', gap: 8, marginBottom: 12 }}>
|
||||
<input
|
||||
className="form-control"
|
||||
data-testid="character-birth-date"
|
||||
value={birthDate}
|
||||
onChange={(e) => setBirthDate(e.target.value)}
|
||||
placeholder="732"
|
||||
/>
|
||||
<button type="button" className="btn" onClick={() => void saveBirthDate()}>
|
||||
{t('dialog.save')}
|
||||
</button>
|
||||
</div>
|
||||
{nodes.length === 0 ? (
|
||||
<p className="text-muted">{t('arc.empty')}</p>
|
||||
) : (
|
||||
<ul className="arc-node-list" data-testid="arc-node-list">
|
||||
{nodes.map((node) => (
|
||||
<li key={node.id} className="arc-node-item" data-testid={`arc-node-${node.id}`}>
|
||||
<div className="arc-node-title">{node.title}</div>
|
||||
<div className="arc-node-content">{node.content.slice(0, 120)}</div>
|
||||
{node.chapterId && (
|
||||
<button
|
||||
type="button"
|
||||
className="btn"
|
||||
onClick={() => void switchTarget({ kind: 'chapter', id: node.chapterId! })}
|
||||
>
|
||||
{node.chapterTitle ?? t('arc.jumpChapter')}
|
||||
</button>
|
||||
)}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
import { useState } from 'react'
|
||||
import { useTranslation, Trans } from 'react-i18next'
|
||||
import type { AiBackend, AiConfig } from '@shared/types'
|
||||
import type { AiBackend, AiConfig, CustomSlashCommand } from '@shared/types'
|
||||
import { useSettingsStore } from '@renderer/stores/useSettingsStore'
|
||||
import { useAppStore } from '@renderer/stores/useAppStore'
|
||||
import { ipcCall } from '@renderer/lib/ipc-client'
|
||||
@@ -22,6 +22,29 @@ export function AiSettingsPage(): React.JSX.Element {
|
||||
void settings.update({ aiConfig: { ...aiConfig, ...patch } })
|
||||
}
|
||||
|
||||
const customSlashCommands = settings.customSlashCommands ?? []
|
||||
|
||||
const updateSlashCommands = (next: CustomSlashCommand[]): void => {
|
||||
void settings.update({ customSlashCommands: next })
|
||||
}
|
||||
|
||||
const addSlashCommand = (): void => {
|
||||
updateSlashCommands([
|
||||
...customSlashCommands,
|
||||
{ id: crypto.randomUUID(), name: '/自定义', template: '' }
|
||||
])
|
||||
}
|
||||
|
||||
const patchSlashCommand = (id: string, patch: Partial<CustomSlashCommand>): void => {
|
||||
updateSlashCommands(
|
||||
customSlashCommands.map((cmd) => (cmd.id === id ? { ...cmd, ...patch } : cmd))
|
||||
)
|
||||
}
|
||||
|
||||
const removeSlashCommand = (id: string): void => {
|
||||
updateSlashCommands(customSlashCommands.filter((cmd) => cmd.id !== id))
|
||||
}
|
||||
|
||||
const handleTest = async (): Promise<void> => {
|
||||
setTesting(true)
|
||||
try {
|
||||
@@ -125,6 +148,41 @@ export function AiSettingsPage(): React.JSX.Element {
|
||||
</p>
|
||||
)}
|
||||
|
||||
<div className="setting-item" style={{ flexDirection: 'column', alignItems: 'flex-start' }}>
|
||||
<span>{t('ai.settings.customSlashCommands')}</span>
|
||||
<div className="custom-slash-list" data-testid="custom-slash-commands">
|
||||
{customSlashCommands.map((cmd) => (
|
||||
<div key={cmd.id} className="custom-slash-row">
|
||||
<input
|
||||
className="form-control"
|
||||
data-testid={`custom-slash-name-${cmd.id}`}
|
||||
value={cmd.name}
|
||||
onChange={(e) => patchSlashCommand(cmd.id, { name: e.target.value })}
|
||||
placeholder={t('ai.settings.customSlashName')}
|
||||
/>
|
||||
<input
|
||||
className="form-control"
|
||||
data-testid={`custom-slash-template-${cmd.id}`}
|
||||
value={cmd.template}
|
||||
onChange={(e) => patchSlashCommand(cmd.id, { template: e.target.value })}
|
||||
placeholder={t('ai.settings.customSlashTemplate')}
|
||||
/>
|
||||
<button type="button" className="btn" onClick={() => removeSlashCommand(cmd.id)}>
|
||||
{t('dialog.delete')}
|
||||
</button>
|
||||
</div>
|
||||
))}
|
||||
<button
|
||||
type="button"
|
||||
className="btn"
|
||||
data-testid="custom-slash-add"
|
||||
onClick={addSlashCommand}
|
||||
>
|
||||
{t('ai.settings.customSlashAdd')}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div className="setting-item">
|
||||
<span />
|
||||
<button
|
||||
|
||||
@@ -234,6 +234,39 @@ export function SettingsPage(): React.JSX.Element {
|
||||
{t('settings.goalNotifications')}
|
||||
</label>
|
||||
</div>
|
||||
<div className="setting-item">
|
||||
<label style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
|
||||
<input
|
||||
type="checkbox"
|
||||
data-testid="settings-compliance-check"
|
||||
checked={settings.enableComplianceCheck === true}
|
||||
onChange={(e) =>
|
||||
void settings.update({ enableComplianceCheck: e.target.checked })
|
||||
}
|
||||
/>
|
||||
{t('settings.complianceCheck')}
|
||||
</label>
|
||||
</div>
|
||||
{settings.enableComplianceCheck && (
|
||||
<div className="setting-item" style={{ flexDirection: 'column', alignItems: 'flex-start' }}>
|
||||
<span>{t('settings.complianceWords')}</span>
|
||||
<textarea
|
||||
className="form-control form-control--wide"
|
||||
data-testid="settings-compliance-words"
|
||||
rows={3}
|
||||
value={(settings.complianceWords ?? []).join('\n')}
|
||||
onChange={(e) =>
|
||||
void settings.update({
|
||||
complianceWords: e.target.value
|
||||
.split('\n')
|
||||
.map((s) => s.trim())
|
||||
.filter(Boolean)
|
||||
})
|
||||
}
|
||||
placeholder={t('settings.complianceWordsHint')}
|
||||
/>
|
||||
</div>
|
||||
)}
|
||||
<div className="setting-item">
|
||||
<label style={{ display: 'flex', alignItems: 'center', gap: 8 }}>
|
||||
<input
|
||||
@@ -276,7 +309,7 @@ export function SettingsPage(): React.JSX.Element {
|
||||
{section === 'shortcuts' && <ShortcutEditor />}
|
||||
{section === 'about' && (
|
||||
<p style={{ color: 'var(--text-secondary)', lineHeight: 1.8 }}>
|
||||
{t('app.name')} v1.4.0
|
||||
{t('app.name')} v1.5.0
|
||||
<br />
|
||||
{t('app.tagline')}
|
||||
</p>
|
||||
|
||||
@@ -0,0 +1,125 @@
|
||||
import { useEffect, useMemo, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import type { TimelineConflict, TimelineEntry } from '@shared/timeline'
|
||||
import { useAppStore } from '@renderer/stores/useAppStore'
|
||||
import { useBookStore } from '@renderer/stores/useBookStore'
|
||||
import { useEditStore } from '@renderer/stores/useEditStore'
|
||||
import { ipcCall } from '@renderer/lib/ipc-client'
|
||||
|
||||
export function TimelineModal(): React.JSX.Element | null {
|
||||
const { t } = useTranslation()
|
||||
const open = useAppStore((s) => s.timelineModalOpen)
|
||||
const setOpen = useAppStore((s) => s.setTimelineModalOpen)
|
||||
const bookId = useBookStore((s) => s.currentBookId)
|
||||
const settings = useBookStore((s) => s.settings)
|
||||
const switchTarget = useEditStore((s) => s.switchTarget)
|
||||
const [entries, setEntries] = useState<TimelineEntry[]>([])
|
||||
const [conflicts, setConflicts] = useState<TimelineConflict[]>([])
|
||||
const [loading, setLoading] = useState(false)
|
||||
|
||||
const conflictChapterIds = useMemo(
|
||||
() => new Set(conflicts.map((c) => c.chapterId)),
|
||||
[conflicts]
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
if (!open || !bookId) return
|
||||
setLoading(true)
|
||||
void Promise.all([
|
||||
ipcCall(() => window.electronAPI.timeline.list(bookId)),
|
||||
ipcCall(() => window.electronAPI.timeline.conflicts(bookId))
|
||||
])
|
||||
.then(([list, conf]) => {
|
||||
setEntries(list)
|
||||
setConflicts(conf)
|
||||
})
|
||||
.finally(() => setLoading(false))
|
||||
}, [open, bookId])
|
||||
|
||||
const handleJump = async (entry: TimelineEntry): Promise<void> => {
|
||||
if (!entry.chapterId) return
|
||||
await switchTarget({ kind: 'chapter', id: entry.chapterId })
|
||||
setOpen(false)
|
||||
}
|
||||
|
||||
const handleAddEvent = async (): Promise<void> => {
|
||||
if (!bookId) return
|
||||
const title = window.prompt(t('timeline.eventTitlePrompt'))
|
||||
if (!title?.trim()) return
|
||||
const storyTime = window.prompt(t('timeline.storyTimePrompt')) ?? ''
|
||||
await ipcCall(() =>
|
||||
window.electronAPI.timeline.upsert(bookId, {
|
||||
title: title.trim(),
|
||||
storyTime: storyTime.trim() || null
|
||||
})
|
||||
)
|
||||
const list = await ipcCall(() => window.electronAPI.timeline.list(bookId))
|
||||
setEntries(list)
|
||||
}
|
||||
|
||||
if (!open) return null
|
||||
|
||||
return (
|
||||
<div className="modal-overlay" data-testid="timeline-modal" role="dialog" aria-modal="true">
|
||||
<div className="modal-content modal-content--wide">
|
||||
<div className="modal-header">
|
||||
<h3>{t('timeline.title')}</h3>
|
||||
<button type="button" className="modal-close" onClick={() => setOpen(false)}>
|
||||
✕
|
||||
</button>
|
||||
</div>
|
||||
<div className="modal-body">
|
||||
{loading ? (
|
||||
<p>{t('cockpit.loading')}</p>
|
||||
) : (
|
||||
<div className="timeline-list" data-testid="timeline-list">
|
||||
{entries.map((entry) => {
|
||||
const conflict = conflicts.find((c) => c.chapterId === entry.chapterId)
|
||||
const isConflict = entry.chapterId && conflictChapterIds.has(entry.chapterId)
|
||||
return (
|
||||
<div
|
||||
key={entry.id}
|
||||
className={`timeline-item ${isConflict ? 'timeline-item--conflict' : ''}`}
|
||||
data-testid={`timeline-item-${entry.id}`}
|
||||
>
|
||||
<div className="timeline-item-main">
|
||||
<strong>{entry.title}</strong>
|
||||
<span className="timeline-item-meta">
|
||||
{entry.storyTime ? entry.storyTime : t('timeline.noTime')}
|
||||
{entry.kind === 'manual' ? ` · ${t('timeline.manual')}` : ''}
|
||||
</span>
|
||||
</div>
|
||||
{conflict && (
|
||||
<div className="timeline-conflict-msg" data-testid="timeline-conflict-msg">
|
||||
{conflict.message}
|
||||
</div>
|
||||
)}
|
||||
{entry.chapterId && (
|
||||
<button type="button" className="btn" onClick={() => void handleJump(entry)}>
|
||||
{t('timeline.jumpChapter')}
|
||||
</button>
|
||||
)}
|
||||
</div>
|
||||
)
|
||||
})}
|
||||
{entries.length === 0 && <p className="text-muted">{t('timeline.empty')}</p>}
|
||||
</div>
|
||||
)}
|
||||
{settings.filter((s) => s.type === 'character').length > 0 && (
|
||||
<p className="text-muted" style={{ marginTop: 12, fontSize: 12 }}>
|
||||
{t('timeline.characterHint')}
|
||||
</p>
|
||||
)}
|
||||
</div>
|
||||
<div className="modal-footer">
|
||||
<button type="button" className="btn" onClick={() => void handleAddEvent()}>
|
||||
{t('timeline.addEvent')}
|
||||
</button>
|
||||
<button type="button" className="btn btn-primary" onClick={() => setOpen(false)}>
|
||||
{t('dialog.cancel')}
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
)
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
import { Extension } from '@tiptap/core'
|
||||
import { Plugin, PluginKey } from '@tiptap/pm/state'
|
||||
import { Decoration, DecorationSet } from '@tiptap/pm/view'
|
||||
|
||||
export const compliancePluginKey = new PluginKey('complianceHighlight')
|
||||
|
||||
function buildDecorations(doc: { descendants: (f: (node: { isText?: boolean; text?: string | null }, pos: number) => void) => void }, words: string[]): DecorationSet {
|
||||
if (words.length === 0) return DecorationSet.empty
|
||||
const decorations: Decoration[] = []
|
||||
doc.descendants((node, pos) => {
|
||||
if (!node.isText || !node.text) return
|
||||
const text = node.text
|
||||
for (const word of words) {
|
||||
const w = word.trim()
|
||||
if (!w) continue
|
||||
let start = 0
|
||||
while (start < text.length) {
|
||||
const idx = text.indexOf(w, start)
|
||||
if (idx < 0) break
|
||||
decorations.push(
|
||||
Decoration.inline(pos + idx, pos + idx + w.length, {
|
||||
class: 'compliance-underline',
|
||||
'data-testid': 'compliance-mark'
|
||||
})
|
||||
)
|
||||
start = idx + w.length
|
||||
}
|
||||
}
|
||||
})
|
||||
return DecorationSet.create(doc as never, decorations)
|
||||
}
|
||||
|
||||
export const ComplianceHighlight = Extension.create({
|
||||
name: 'complianceHighlight',
|
||||
addProseMirrorPlugins() {
|
||||
return [
|
||||
new Plugin({
|
||||
key: compliancePluginKey,
|
||||
state: {
|
||||
init() {
|
||||
return DecorationSet.empty
|
||||
},
|
||||
apply(tr, set) {
|
||||
const words = tr.getMeta(compliancePluginKey) as string[] | undefined
|
||||
if (words) {
|
||||
return buildDecorations(tr.doc, words)
|
||||
}
|
||||
return set.map(tr.mapping, tr.doc)
|
||||
}
|
||||
},
|
||||
props: {
|
||||
decorations(state) {
|
||||
return compliancePluginKey.getState(state) ?? DecorationSet.empty
|
||||
}
|
||||
}
|
||||
})
|
||||
]
|
||||
}
|
||||
})
|
||||
|
||||
export function setComplianceWords(
|
||||
view: { dispatch: (tr: { doc: unknown; steps: unknown[]; getMeta: (k: PluginKey) => unknown; setMeta: (k: PluginKey, v: unknown) => void }) => void; state: { tr: unknown } },
|
||||
words: string[]
|
||||
): void {
|
||||
const tr = view.state.tr as { setMeta: (k: PluginKey, v: unknown) => void; doc: unknown; steps: unknown[]; getMeta: (k: PluginKey) => unknown }
|
||||
tr.setMeta(compliancePluginKey, words)
|
||||
view.dispatch(tr)
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import type { TFunction } from 'i18next'
|
||||
import type { CustomSlashCommand } from '@shared/types'
|
||||
|
||||
const SLASH_KEYS: Record<string, string> = {
|
||||
'/续写': 'ai.slash.continue',
|
||||
@@ -8,15 +9,30 @@ const SLASH_KEYS: Record<string, string> = {
|
||||
'/纠错': 'ai.slash.proofread'
|
||||
}
|
||||
|
||||
export function resolveSlashCommand(input: string, t: TFunction): string | null {
|
||||
const token = input.trim().split(/\s+/)[0]
|
||||
function normalizeToken(input: string): string {
|
||||
const token = input.trim().split(/\s+/)[0] ?? ''
|
||||
return token.startsWith('/') ? token : `/${token}`
|
||||
}
|
||||
|
||||
export function resolveSlashCommand(
|
||||
input: string,
|
||||
t: TFunction,
|
||||
custom?: CustomSlashCommand[]
|
||||
): string | null {
|
||||
const token = normalizeToken(input)
|
||||
const customMatch = custom?.find((c) => normalizeToken(c.name) === token)
|
||||
if (customMatch?.template.trim()) return customMatch.template
|
||||
const key = SLASH_KEYS[token]
|
||||
if (!key) return null
|
||||
return t(key)
|
||||
}
|
||||
|
||||
export function applySlashCommand(input: string, t: TFunction): { display: string; prompt: string } {
|
||||
export function applySlashCommand(
|
||||
input: string,
|
||||
t: TFunction,
|
||||
custom?: CustomSlashCommand[]
|
||||
): { display: string; prompt: string } {
|
||||
const display = input.trim()
|
||||
const resolved = resolveSlashCommand(display, t)
|
||||
const resolved = resolveSlashCommand(display, t, custom)
|
||||
return { display, prompt: resolved ?? display }
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ interface AppState {
|
||||
inspirationModalOpen: boolean
|
||||
importBookModalOpen: boolean
|
||||
exportAllModalOpen: boolean
|
||||
timelineModalOpen: boolean
|
||||
focusMode: boolean
|
||||
namingCheckOpen: boolean
|
||||
toast: string | null
|
||||
@@ -22,6 +23,7 @@ interface AppState {
|
||||
setInspirationModalOpen: (open: boolean) => void
|
||||
setImportBookModalOpen: (open: boolean) => void
|
||||
setExportAllModalOpen: (open: boolean) => void
|
||||
setTimelineModalOpen: (open: boolean) => void
|
||||
setFocusMode: (on: boolean) => void
|
||||
setNamingCheckOpen: (open: boolean) => void
|
||||
showToast: (message: string) => void
|
||||
@@ -37,6 +39,7 @@ export const useAppStore = create<AppState>((set) => ({
|
||||
inspirationModalOpen: false,
|
||||
importBookModalOpen: false,
|
||||
exportAllModalOpen: false,
|
||||
timelineModalOpen: false,
|
||||
focusMode: false,
|
||||
namingCheckOpen: false,
|
||||
toast: null,
|
||||
@@ -48,6 +51,7 @@ export const useAppStore = create<AppState>((set) => ({
|
||||
setInspirationModalOpen: (inspirationModalOpen) => set({ inspirationModalOpen }),
|
||||
setImportBookModalOpen: (importBookModalOpen) => set({ importBookModalOpen }),
|
||||
setExportAllModalOpen: (exportAllModalOpen) => set({ exportAllModalOpen }),
|
||||
setTimelineModalOpen: (timelineModalOpen) => set({ timelineModalOpen }),
|
||||
setFocusMode: (focusMode) => set({ focusMode }),
|
||||
setNamingCheckOpen: (namingCheckOpen) => set({ namingCheckOpen }),
|
||||
showToast: (toast) => {
|
||||
|
||||
@@ -35,6 +35,9 @@ export const useSettingsStore = create<SettingsState>((set, get) => ({
|
||||
readModeFontTheme: 'serif',
|
||||
readModeDeviceWidth: 'desktop',
|
||||
enableFocusAmbientSound: false,
|
||||
enableComplianceCheck: false,
|
||||
complianceWords: [] as string[],
|
||||
customSlashCommands: [] as { id: string; name: string; template: string }[],
|
||||
loaded: false,
|
||||
load: async () => {
|
||||
const data = await ipcCall(() => window.electronAPI.settings.get())
|
||||
|
||||
@@ -2473,3 +2473,104 @@
|
||||
.read-mode-font-eye-care .read-mode-chapter-title {
|
||||
color: #3d3428;
|
||||
}
|
||||
|
||||
.timeline-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.timeline-item {
|
||||
padding: 12px 14px;
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 8px;
|
||||
background: var(--bg-secondary);
|
||||
}
|
||||
|
||||
.timeline-item--conflict {
|
||||
border-color: #e05252;
|
||||
background: rgba(224, 82, 82, 0.08);
|
||||
}
|
||||
|
||||
.timeline-item-main {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 4px;
|
||||
}
|
||||
|
||||
.timeline-item-meta {
|
||||
font-size: 12px;
|
||||
color: var(--text-muted);
|
||||
}
|
||||
|
||||
.timeline-conflict-msg {
|
||||
margin-top: 8px;
|
||||
font-size: 12px;
|
||||
color: #e05252;
|
||||
}
|
||||
|
||||
.character-arc-panel {
|
||||
margin-top: 16px;
|
||||
padding: 14px;
|
||||
border-top: 1px solid var(--border-color);
|
||||
}
|
||||
|
||||
.arc-node-list {
|
||||
list-style: none;
|
||||
margin: 0;
|
||||
padding: 0;
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 10px;
|
||||
}
|
||||
|
||||
.arc-node-item {
|
||||
padding: 10px 12px;
|
||||
border: 1px solid var(--border-color);
|
||||
border-radius: 6px;
|
||||
background: var(--bg-secondary);
|
||||
}
|
||||
|
||||
.arc-node-title {
|
||||
font-weight: 600;
|
||||
margin-bottom: 4px;
|
||||
}
|
||||
|
||||
.arc-node-content {
|
||||
font-size: 13px;
|
||||
color: var(--text-muted);
|
||||
margin-bottom: 8px;
|
||||
}
|
||||
|
||||
.compliance-underline {
|
||||
text-decoration: underline wavy #e05252;
|
||||
text-underline-offset: 3px;
|
||||
}
|
||||
|
||||
.ref-detail-drawer {
|
||||
position: absolute;
|
||||
top: 0;
|
||||
right: 0;
|
||||
width: min(360px, 90%);
|
||||
height: 100%;
|
||||
background: var(--bg-primary);
|
||||
border-left: 1px solid var(--border-color);
|
||||
box-shadow: -4px 0 16px rgba(0, 0, 0, 0.08);
|
||||
padding: 16px;
|
||||
z-index: 5;
|
||||
overflow-y: auto;
|
||||
}
|
||||
|
||||
.custom-slash-list {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
width: 100%;
|
||||
}
|
||||
|
||||
.custom-slash-row {
|
||||
display: grid;
|
||||
grid-template-columns: 1fr 2fr auto;
|
||||
gap: 8px;
|
||||
align-items: center;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user