diff --git a/src/App.tsx b/src/App.tsx index 313d258..c82fec8 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -1,35 +1,29 @@ import { useState } from "react"; - -const CHAPTERS = [ - { n: "1", title: "The Lighthouse" }, - { n: "2", title: "Salt and Iron" }, - { n: "3", title: "What the Tide Left" }, - { n: "4", title: "Homecoming" }, -]; - -const BODY = [ - "The lamp had not been lit in thirty years, and yet the islanders still set their clocks by a light that no longer came. Mara climbed the iron stair each evening out of a habit older than memory, and each evening she found the same dark glass waiting, patient as the sea.", - "Her grandfather had kept the flame. Her mother had let it die. Between those two facts lay the whole of the family's quarrel with the water, and Mara had inherited both the quarrel and the key that opened the lantern room.", - "She did not light it that night either. She only stood at the gallery rail and counted the boats coming in, the way she had been taught to count them, as though arithmetic alone could keep them safe until morning.", -]; - -function Icon({ d }: { d: string }) { - return ( - - - - ); -} +import { Sidebar } from "./components/Sidebar"; +import { Dock } from "./components/Dock"; +import { Icon } from "./components/Icon"; +import { Editor } from "./editor/Editor"; +import { useBook } from "./store/useBook"; function App() { - const [active, setActive] = useState("1"); const [dock, setDock] = useState(true); - const current = CHAPTERS.find((c) => c.n === active)!; + const title = useBook((s) => s.book.metadata.title); + const author = useBook((s) => s.book.metadata.author); + const chapters = useBook((s) => s.book.chapters); + const activeChapterId = useBook((s) => s.activeChapterId); + const setChapterContent = useBook((s) => s.setChapterContent); + const setChapterTitle = useBook((s) => s.setChapterTitle); + + const idx = chapters.findIndex((c) => c.id === activeChapterId); + const chapter = chapters[idx]; return (
- Untitled — a novel + + {title || "Untitled"} + {author ? ` — ${author}` : ""} +
- - +
-
+
-
Chapter {current.n}
-

{current.title}

+
Chapter {idx + 1}
+ setChapterTitle(chapter.id, e.target.value)} + />
- {BODY.map((t, i) => ( -

{t}

- ))} -
⁂
-

Morning came the color of pewter. The tide had left its usual accounting along the shingle — a torn net, a single boot, the pale architecture of a gull — and Mara walked the length of it without hurry, naming each thing as her grandfather had named them to her.

+ setChapterContent(chapter.id, content)} + />
- - {dock && ( -
-
- Preview - 6 × 9 in · 1 of 1 -
-
-
-
Chapter {current.n}
-
{current.title}
-
- {BODY.map((t, i) => ( -

{t}

- ))} -
7
-
-
- )} + {dock && }
); diff --git a/src/components/Dock.tsx b/src/components/Dock.tsx new file mode 100644 index 0000000..92cbe2b --- /dev/null +++ b/src/components/Dock.tsx @@ -0,0 +1,40 @@ +import { useMemo } from "react"; +import { generateHTML } from "@tiptap/core"; +import { useBook } from "../store/useBook"; +import { editorExtensions } from "../editor/extensions"; + +const TRIM_LABEL: Record = { + "6x9": "6 × 9 in", + "5.5x8.5": "5.5 × 8.5 in", + "5x8": "5 × 8 in", + a5: "A5", +}; + +export function Dock() { + const chapters = useBook((s) => s.book.chapters); + const trim = useBook((s) => s.book.settings.trim); + const activeChapterId = useBook((s) => s.activeChapterId); + + const idx = chapters.findIndex((c) => c.id === activeChapterId); + const chapter = chapters[idx]; + const html = useMemo(() => generateHTML(chapter.content, editorExtensions), [chapter.content]); + + return ( +
+
+ Preview + + {TRIM_LABEL[trim]} · {idx + 1} of {chapters.length} + +
+
+
+
Chapter {idx + 1}
+
{chapter.title || "Untitled"}
+
+
+
{idx * 8 + 7}
+
+
+ ); +} diff --git a/src/components/Icon.tsx b/src/components/Icon.tsx new file mode 100644 index 0000000..dbcd7ff --- /dev/null +++ b/src/components/Icon.tsx @@ -0,0 +1,21 @@ +interface IconProps { + d: string; + size?: number; +} + +export function Icon({ d, size = 16 }: IconProps) { + return ( + + + + ); +} diff --git a/src/components/Sidebar.tsx b/src/components/Sidebar.tsx new file mode 100644 index 0000000..de66c2e --- /dev/null +++ b/src/components/Sidebar.tsx @@ -0,0 +1,36 @@ +import { useBook } from "../store/useBook"; +import { Icon } from "./Icon"; + +export function Sidebar() { + const chapters = useBook((s) => s.book.chapters); + const activeChapterId = useBook((s) => s.activeChapterId); + const setActiveChapter = useBook((s) => s.setActiveChapter); + const addChapter = useBook((s) => s.addChapter); + + return ( + + ); +} diff --git a/src/styles/app.css b/src/styles/app.css index 2c5cb95..361546b 100644 --- a/src/styles/app.css +++ b/src/styles/app.css @@ -383,3 +383,69 @@ button { ::-webkit-scrollbar-track { background: transparent; } + +.chapter-title-input { + width: 100%; + margin: 15px 0 0; + padding: 0; + border: 0; + background: transparent; + text-align: center; + font-family: var(--font-book); + font-weight: 500; + font-size: 31px; + line-height: 1.16; + letter-spacing: -0.01em; + color: var(--ink); +} + +.chapter-title-input:focus { + outline: none; +} + +.chapter-title-input::placeholder { + color: var(--ink-faint); +} + +.editor-host, +.ProseMirror { + outline: none; +} + +.ProseMirror { + min-height: 62vh; +} + +.ProseMirror > p:first-child { + text-indent: 0; +} + +.ProseMirror > p:first-child::first-letter { + float: left; + font-size: 3.1em; + line-height: 0.82; + padding: 0.05em 0.09em 0 0; + font-weight: 500; +} + +.ProseMirror hr { + border: none; + border-top: 1px solid var(--line-strong); + width: 56px; + margin: 2rem auto; +} + +.ProseMirror p.is-editor-empty:first-child::before { + content: attr(data-placeholder); + color: var(--ink-faint); + float: left; + height: 0; + pointer-events: none; +} + +.page-body hr { + border: none; + border-top: 1px solid var(--line-strong); + width: 22px; + margin: 9px auto; +}