This commit is contained in:
pj committed 2026-06-22 09:56:20 -04:00
1 parent 78fff9b6f4
commit 7cc36e3e40
37 files changed
+55361 -103

No files matched your search

+19
View File
@@ -7,6 +7,7 @@ import {
type ChapterKind,
type Cover,
chapterKind,
cloneChapter,
createChapter,
createPage,
normalizeBook,
@@ -27,8 +28,10 @@ interface BookState {
setActiveChapter: (id: string) => void;
setChapterContent: (id: string, content: JSONContent) => void;
setChapterTitle: (id: string, title: string) => void;
setChapterNoTitle: (id: string, noTitle: boolean) => void;
addChapter: () => void;
addPage: (group: "front" | "back", title: string) => void;
duplicateChapter: (id: string) => void;
deleteChapter: (id: string) => void;
moveChapter: (from: number, to: number, toKind?: ChapterKind) => void;
setMetadata: (patch: Partial<BookMetadata>) => void;
@@ -63,6 +66,12 @@ export const useBook = create<BookState>((set) => ({
? { dirty: true, book: { ...s.book, chapters: s.book.chapters.map((c) => (c.id === id ? { ...c, title, updatedAt: Date.now() } : c)) } }
: {}
),
setChapterNoTitle: (id, noTitle) =>
set((s) =>
s.book
? { dirty: true, book: { ...s.book, chapters: s.book.chapters.map((c) => (c.id === id ? { ...c, noTitle, title: noTitle ? "" : c.title, updatedAt: Date.now() } : c)) } }
: {}
),
addChapter: () =>
set((s) => {
if (!s.book) return {};
@@ -82,6 +91,16 @@ export const useBook = create<BookState>((set) => ({
chapters.splice(insertAt, 0, page);
return { activeChapterId: page.id, dirty: true, book: { ...s.book, chapters } };
}),
duplicateChapter: (id) =>
set((s) => {
if (!s.book) return {};
const index = s.book.chapters.findIndex((c) => c.id === id);
if (index === -1) return {};
const copy = cloneChapter(s.book.chapters[index]);
const chapters = [...s.book.chapters];
chapters.splice(index + 1, 0, copy);
return { activeChapterId: copy.id, dirty: true, book: { ...s.book, chapters } };
}),
deleteChapter: (id) =>
set((s) => {
if (!s.book) return {};
+26
View File
@@ -0,0 +1,26 @@
import { create } from "zustand";
interface ProofingState {
spelling: boolean;
grammar: boolean;
ignored: Set<string>;
toggleSpelling: () => void;
toggleGrammar: () => void;
ignore: (signature: string) => void;
resetIgnored: () => void;
}
export const useProofing = create<ProofingState>((set) => ({
spelling: true,
grammar: false,
ignored: new Set(),
toggleSpelling: () => set((s) => ({ spelling: !s.spelling })),
toggleGrammar: () => set((s) => ({ grammar: !s.grammar })),
ignore: (signature) =>
set((s) => {
const ignored = new Set(s.ignored);
ignored.add(signature);
return { ignored };
}),
resetIgnored: () => set({ ignored: new Set() }),
}));