diff --git a/.claude/skills/ui-conventions/SKILL.md b/.claude/skills/ui-conventions/SKILL.md index e67d9df..036b920 100644 --- a/.claude/skills/ui-conventions/SKILL.md +++ b/.claude/skills/ui-conventions/SKILL.md @@ -67,4 +67,6 @@ Active project reference docs (read the relevant one before changing that area): ## Features - **Note Import Assistant:** Raw PDF/TXT/MD converted to structured Markdown via `src/lib/note-importer.ts`. Noise (page numbers, headers/footers, watermarks) removed, PDF mid-sentence line wraps re-joined, headings (`##`) and bullet lists formatted, OCR-unreadable artifacts flagged with `⚠️ Some content may be unreadable due to OCR/extraction issues`. Never invent content or add fluff preamble. Lives in a dedicated `SidePanel` triggered from the Notes page header, right of the "Yeni Not" button. +- **Notes editor:** Personal notes open as full pages — `/notes/new` and `/notes/$id` (`NoteDocument`) — not side panels. Bodies are HTML written by `NoteRichEditor` (contentEditable, sticky toolbar, ⌘S save, ⌘K link, unsaved-changes blocker); course notes use the same editor inside `NoteForm`. Stored Markdown-ish bodies (imports, older notes) load through `toRichTextHtml`. +- **Rendering stored HTML:** anything a user wrote that reaches `innerHTML` (notes, messages, homework submissions) goes through `sanitizeRichText` / `toRichTextHtml` from `src/lib/rich-text.ts`. Card excerpts use `richTextExcerpt` (plain text), never `innerHTML`. - **Drawing Canvas (`DrawCanvas`):** Freehand drawings saved as `.hzdraw.png` with embedded scene JSON metadata. Live drawing effects must guard `initialScene` against re-initializing during active strokes. diff --git a/src/components/layout/command-palette.tsx b/src/components/layout/command-palette.tsx index 955b604..9c215f2 100644 --- a/src/components/layout/command-palette.tsx +++ b/src/components/layout/command-palette.tsx @@ -153,7 +153,7 @@ export function CommandPalette(props: CommandPaletteProps) { keywords: "note not ekle ders notu kaydet", icon: IconNote, shortcut: `${mod}N`, - onSelect: () => void navigate({ to: "/notes", search: { action: "new" } as any }), + onSelect: () => void navigate({ to: "/notes/new" }), }); list.push({ diff --git a/src/components/notes/note-card.tsx b/src/components/notes/note-card.tsx index b9ae2e9..5b3c9c4 100644 --- a/src/components/notes/note-card.tsx +++ b/src/components/notes/note-card.tsx @@ -3,9 +3,11 @@ import { formatApiError } from "@/api/client"; import type { Note } from "@/api/client"; import { NoteForm } from "@/components/notes/note-form"; import { ConfirmDialog } from "@/components/ui/confirm-dialog"; -import { IconEdit, IconTrash } from "@/components/ui/icons"; +import { IconChevronRight, IconEdit, IconTrash } from "@/components/ui/icons"; import { SidePanel } from "@/components/ui/side-panel"; import { TableRowActions } from "@/components/ui/table-row-actions"; +import { cn } from "@/lib/cn"; +import { richTextExcerpt, toRichTextHtml } from "@/lib/rich-text"; import { useT } from "@/stores/preferences-context"; export function NoteCard(props: { @@ -13,6 +15,8 @@ export function NoteCard(props: { /** Hides the edit/delete menu when false. Defaults to true. */ canManage?: boolean; onOpen: (note: Note) => void; + /** Edits somewhere else (the full-page editor) instead of the side panel. */ + onEdit?: (note: Note) => void; onUpdate: (id: string, values: { title: string; content: string }) => Promise; onDelete: (id: string) => Promise; }) { @@ -21,13 +25,14 @@ export function NoteCard(props: { const [error, setError] = createSignal(""); const [deleteOpen, setDeleteOpen] = createSignal(false); const canManage = () => props.canManage !== false; + const excerpt = () => richTextExcerpt(toRichTextHtml(props.note.content), 320); return ( <>
props.onOpen(props.note)} onKeyDown={(event) => { if (event.key === "Enter" || event.key === " ") { @@ -36,17 +41,17 @@ export function NoteCard(props: { } }} > -
-

{props.note.title}

+
+

{props.note.title}

-
event.stopPropagation()}> +
event.stopPropagation()}> , - onSelect: () => setEditing(true), + onSelect: () => (props.onEdit ? props.onEdit(props.note) : setEditing(true)), }, { label: t("common.delete"), @@ -59,15 +64,15 @@ export function NoteCard(props: {
-
- {t("notes.noContent")}

} - > -
- - {error() &&

{error()}

} -
+ {/* Plain-text excerpt: the card never renders stored HTML. */} +

+ {excerpt() || t("notes.noContent")} +

+ + {t("notes.open")} + + + {error() &&

{error()}

}
diff --git a/src/components/notes/note-document.tsx b/src/components/notes/note-document.tsx new file mode 100644 index 0000000..df7770a --- /dev/null +++ b/src/components/notes/note-document.tsx @@ -0,0 +1,179 @@ +import { Link, useBlocker, useNavigate } from "@tanstack/solid-router"; +import { Show, createSignal, onCleanup, onMount } from "solid-js"; +import { formatApiError, type Note } from "@/api/client"; +import { deleteNoteById, patchNoteById, postNote } from "@/api/notes"; +import { NoteFilesPanel } from "@/components/notes/note-files-panel"; +import { NoteRichEditor } from "@/components/notes/note-rich-editor"; +import { Alert } from "@/components/ui/alert"; +import { Button } from "@/components/ui/button"; +import { ConfirmDialog } from "@/components/ui/confirm-dialog"; +import { IconAlert, IconChevronLeft, IconTrash } from "@/components/ui/icons"; +import { cn } from "@/lib/cn"; +import { personalNoteFiles } from "@/lib/note-source"; +import { useT } from "@/stores/preferences-context"; + +const MAX_TITLE = 200; +const MAX_CONTENT = 10_000; +const MOD_KEY = typeof navigator !== "undefined" && /Mac|iPhone|iPad/.test(navigator.userAgent) ? "⌘" : "Ctrl"; + +/** + * A personal note as a full-page document: title, editor, attachments. A new + * note (no `note`) becomes a real one on first save and moves to its own URL, + * where attachments open up. Leaving with unsaved edits asks first. + */ +export function NoteDocument(props: { note?: Note }) { + const t = useT(); + const navigate = useNavigate(); + const [title, setTitle] = createSignal(props.note?.title ?? ""); + const [content, setContent] = createSignal(props.note?.content ?? ""); + const [baseline, setBaseline] = createSignal(JSON.stringify([props.note?.title ?? "", props.note?.content ?? ""])); + const [saving, setSaving] = createSignal(false); + const [error, setError] = createSignal(""); + const [deleteOpen, setDeleteOpen] = createSignal(false); + const dirty = () => JSON.stringify([title(), content()]) !== baseline(); + const isNew = () => !props.note; + + let leaving = false; + const blocker = useBlocker({ shouldBlockFn: () => dirty(), enableBeforeUnload: () => dirty(), withResolver: true }); + + const save = async () => { + if (saving()) return; + const trimmed = title().trim(); + if (!trimmed) return setError(t("form.titleRequired")); + if (trimmed.length > MAX_TITLE) return setError(t("form.titleMax")); + if (content().length > MAX_CONTENT) return setError(t("form.contentMax")); + setError(""); + setSaving(true); + // What is being saved, captured now: typing that lands while the request + // is out must still count as unsaved afterwards. + const body = content(); + try { + if (props.note) { + await patchNoteById(props.note.id, { title: trimmed, content: body }); + if (title().trim() === trimmed) setTitle(trimmed); + setBaseline(JSON.stringify([trimmed, body])); + } else { + const created = await postNote({ title: trimmed, content: body || undefined }); + // Settle the baseline first so the move to the note's URL is not blocked. + setBaseline(JSON.stringify([title(), content()])); + await navigate({ to: "/notes/$id", params: { id: created.id }, replace: true }); + } + } catch (err) { + setError(formatApiError(err)); + } finally { + setSaving(false); + } + }; + + onMount(() => { + const onKey = (event: KeyboardEvent) => { + if (!(event.metaKey || event.ctrlKey) || event.altKey || event.shiftKey || event.key.toLowerCase() !== "s") return; + event.preventDefault(); + void save(); + }; + window.addEventListener("keydown", onKey); + onCleanup(() => window.removeEventListener("keydown", onKey)); + }); + + const status = () => (saving() ? t("notes.saving") : dirty() ? t("notes.unsaved") : isNew() ? "" : t("notes.allSaved")); + + return ( +
+
+ + + {t("notes.backToNotebook")} + + + {status()} + + + + +
+ + + {error()} + + +
+
+ setTitle(event.currentTarget.value)} + onKeyDown={(event) => { + if (event.key === "Enter") event.preventDefault(); + }} + /> + + + + + } + /> +
+ + +
+ + { + if (!props.note) return; + await deleteNoteById(props.note.id); + setBaseline(JSON.stringify([title(), content()])); + await navigate({ to: "/notes" }); + }} + /> + + { + // The dialog also closes itself after "Leave"; only a dismissal resets. + if (!open && !leaving && blocker().status === "blocked") blocker().reset?.(); + }} + title={t("notes.leaveTitle")} + description={t("notes.leaveHint")} + summary={title().trim() || t("notes.titlePlaceholder")} + variant="destructive" + icon={} + confirmLabel={t("notes.leaveConfirm")} + onConfirm={() => { + leaving = true; + blocker().proceed?.(); + }} + /> +
+ ); +} diff --git a/src/components/notes/note-form.tsx b/src/components/notes/note-form.tsx index cf76138..6848d71 100644 --- a/src/components/notes/note-form.tsx +++ b/src/components/notes/note-form.tsx @@ -3,6 +3,7 @@ import { createResource } from "@/lib/create-resource"; import { formatApiError } from "@/api/client"; import { getSettings } from "@/api/settings"; import type { Note } from "@/api/client"; +import { NoteRichEditor } from "@/components/notes/note-rich-editor"; import { Button } from "@/components/ui/button"; import { ConfirmDialog } from "@/components/ui/confirm-dialog"; import { FormDialog } from "@/components/ui/form-dialog"; @@ -10,8 +11,6 @@ import { IconEdit, IconPlus, IconTrash } from "@/components/ui/icons"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; import { PageSpinner } from "@/components/ui/page-spinner"; -import { RichTextEditor } from "@/components/ui/rich-text-editor"; -import { Tabs, TabsContent, TabsList, TabsTrigger } from "@/components/ui/tabs"; import { formatBytes, maxUploadBytes } from "@/lib/upload-limits"; import { useT } from "@/stores/preferences-context"; @@ -38,7 +37,6 @@ export function NoteForm(props: { const isUpdate = () => !!props.initial?.id; const [title, setTitle] = createSignal(props.initial?.title ?? ""); const [content, setContent] = createSignal(props.initial?.content ?? ""); - const [contentView, setContentView] = createSignal<"write" | "preview">("write"); const [files, setFiles] = createSignal([]); const [error, setError] = createSignal(""); const [pending, setPending] = createSignal(false); @@ -125,35 +123,15 @@ export function NoteForm(props: { onInput={(e) => setTitle(e.currentTarget.value)} /> -
-
- - setContentView(value as "write" | "preview")}> - - {t("notes.write")} - {t("notes.preview")} - - -
- - {t("notes.noContent")}

}> -
- -
- } - > - -
+
+ +
diff --git a/src/components/notes/note-list.tsx b/src/components/notes/note-list.tsx index 51fc8f0..692e4da 100644 --- a/src/components/notes/note-list.tsx +++ b/src/components/notes/note-list.tsx @@ -13,6 +13,8 @@ export function NoteList(props: { canManage?: boolean; emptyTitle: string; emptyDescription?: string; + /** Opens a note somewhere else (its own page) instead of the reader panel; also used for edit. */ + onOpen?: (note: Note) => void; onUpdate: (id: string, values: { title: string; content: string }) => Promise; onDelete: (id: string) => Promise; }) { @@ -30,14 +32,15 @@ export function NoteList(props: { /> } > -
    +
      {(note) => (
    • (props.onOpen ? props.onOpen(item) : setReadingNote(item))} + onEdit={props.onOpen} onUpdate={props.onUpdate} onDelete={props.onDelete} /> diff --git a/src/components/notes/note-reader-panel.tsx b/src/components/notes/note-reader-panel.tsx index 9d5f156..ccde703 100644 --- a/src/components/notes/note-reader-panel.tsx +++ b/src/components/notes/note-reader-panel.tsx @@ -4,6 +4,7 @@ import type { NoteFileSource } from "@/lib/note-source"; import { NoteFilesPanel } from "@/components/notes/note-files-panel"; import { RagOutputsPanel } from "@/components/notes/rag-outputs-panel"; import { SidePanel } from "@/components/ui/side-panel"; +import { toRichTextHtml } from "@/lib/rich-text"; import { useT } from "@/stores/preferences-context"; export function NoteReaderPanel(props: { @@ -27,15 +28,13 @@ export function NoteReaderPanel(props: { {(n) => (
      -
      -
      - {t("notes.noContent")}

      } - > -
      - -
      +
      + {t("notes.noContent")}

      } + > +
      +
      diff --git a/src/components/notes/note-rich-editor.tsx b/src/components/notes/note-rich-editor.tsx new file mode 100644 index 0000000..b302742 --- /dev/null +++ b/src/components/notes/note-rich-editor.tsx @@ -0,0 +1,250 @@ +import { For, createSignal, onCleanup, onMount, type JSX } from "solid-js"; +import { ConfirmDialog } from "@/components/ui/confirm-dialog"; +import { + IconArrowRedo, + IconArrowUndo, + IconBold, + IconCodeBlock, + IconHeading2, + IconHeading3, + IconItalic, + IconLink, + IconListBullets, + IconListNumbers, + IconParagraph, + IconQuote, + IconStrikethrough, + IconUnderline, +} from "@/components/ui/icons"; +import { cn } from "@/lib/cn"; +import { isRichTextEmpty, sanitizeRichText, toRichTextHtml } from "@/lib/rich-text"; +import { useT } from "@/stores/preferences-context"; + +type Block = "p" | "h2" | "h3" | "blockquote" | "pre"; +type InlineState = { bold: boolean; italic: boolean; underline: boolean; strikeThrough: boolean; ul: boolean; ol: boolean; block: Block }; + +const IDLE: InlineState = { bold: false, italic: false, underline: false, strikeThrough: false, ul: false, ol: false, block: "p" }; + +/** + * Document-style note editor: a sticky formatting bar over a contentEditable + * body that grows with its text (the page scrolls, not a small box). The body + * is HTML — the format notes are stored in — and every paste and every value + * loaded from the server is sanitized before it reaches the DOM. + */ +export function NoteRichEditor(props: { + value: string; + onChange: (html: string) => void; + placeholder?: string; + /** Sticky offset for the formatting bar, e.g. below the app header. */ + toolbarClass?: string; + class?: string; + /** Right side of the formatting bar — the page's save control lives here. */ + actions?: JSX.Element; + /** Minimum body height; a full page wants most of the viewport, a side panel less. */ + bodyClass?: string; +}) { + const t = useT(); + let body: HTMLDivElement | undefined; + let savedRange: Range | null = null; + const [state, setState] = createSignal(IDLE); + const [empty, setEmpty] = createSignal(isRichTextEmpty(props.value)); + const [linkOpen, setLinkOpen] = createSignal(false); + const [linkInitial, setLinkInitial] = createSignal("https://"); + const [linkText, setLinkText] = createSignal(""); + + const emit = () => { + if (!body) return; + const blank = isRichTextEmpty(body.innerHTML); + setEmpty(blank); + // A first line typed into an empty body is a bare text node. Store it as a + // paragraph, so the value is recognisably HTML and its entities (`<`) + // are never mistaken for plain text and escaped twice on the next load. + const html = body.firstElementChild ? body.innerHTML : `

      ${body.innerHTML}

      `; + props.onChange(blank ? "" : html); + }; + + const selectionInside = () => { + const selection = window.getSelection(); + return !!(body && selection && selection.rangeCount > 0 && body.contains(selection.anchorNode)); + }; + + const refreshState = () => { + if (!selectionInside()) return; + const block = String(document.queryCommandValue("formatBlock") || "p").toLowerCase().replace(/[<>]/g, ""); + setState({ + bold: document.queryCommandState("bold"), + italic: document.queryCommandState("italic"), + underline: document.queryCommandState("underline"), + strikeThrough: document.queryCommandState("strikeThrough"), + ul: document.queryCommandState("insertUnorderedList"), + ol: document.queryCommandState("insertOrderedList"), + block: (["h2", "h3", "blockquote", "pre"].includes(block) ? block : "p") as Block, + }); + }; + + const run = (command: string, value?: string) => { + body?.focus(); + document.execCommand(command, false, value); + emit(); + refreshState(); + }; + + // Clicking the active block style again returns the line to a paragraph. + const toggleBlock = (block: Block) => run("formatBlock", `<${state().block === block ? "p" : block}>`); + + onMount(() => { + if (!body) return; + body.innerHTML = toRichTextHtml(props.value); + const onSelection = () => refreshState(); + document.addEventListener("selectionchange", onSelection); + onCleanup(() => document.removeEventListener("selectionchange", onSelection)); + }); + + const openLink = () => { + const selection = window.getSelection(); + savedRange = selectionInside() && selection ? selection.getRangeAt(0).cloneRange() : null; + const anchor = selection?.anchorNode?.parentElement?.closest("a"); + setLinkInitial(anchor?.getAttribute("href") ?? "https://"); + setLinkText(savedRange?.toString().trim() || anchor?.textContent?.trim() || "—"); + setLinkOpen(true); + }; + + const applyLink = (raw: string | undefined) => { + body?.focus(); + const selection = window.getSelection(); + if (savedRange && selection) { + selection.removeAllRanges(); + selection.addRange(savedRange); + } + const value = raw?.trim() ?? ""; + if (!value || value === "https://") return run("unlink"); + const href = /^(https?:|mailto:)/i.test(value) ? value : `https://${value}`; + if (selection?.isCollapsed) { + const link = document.createElement("a"); + link.href = href; + link.textContent = value; + run("insertHTML", sanitizeRichText(link.outerHTML)); + } else { + run("createLink", href); + } + }; + + const onKeyDown = (event: KeyboardEvent) => { + const mod = event.metaKey || event.ctrlKey; + if (mod && !event.shiftKey && event.key.toLowerCase() === "k") { + // Inside the body ⌘K means "link"; stop it before the window-level + // command palette listener opens on top of the link dialog. + event.preventDefault(); + event.stopPropagation(); + openLink(); + } else if (event.key === "Tab" && (state().ul || state().ol)) { + event.preventDefault(); + run(event.shiftKey ? "outdent" : "indent"); + } + }; + + const onPaste = (event: ClipboardEvent) => { + const data = event.clipboardData; + if (!data) return; + event.preventDefault(); + const html = data.getData("text/html"); + if (html) run("insertHTML", sanitizeRichText(html)); + else run("insertText", data.getData("text/plain")); + }; + + type Tool = { label: () => string; icon: (p: { class?: string }) => JSX.Element; active?: () => boolean; onClick: () => void }; + const groups: Tool[][] = [ + [ + { label: () => t("editor.undo"), icon: IconArrowUndo, onClick: () => run("undo") }, + { label: () => t("editor.redo"), icon: IconArrowRedo, onClick: () => run("redo") }, + ], + [ + { label: () => t("editor.paragraph"), icon: IconParagraph, active: () => state().block === "p" && !state().ul && !state().ol, onClick: () => run("formatBlock", "

      ") }, + { label: () => t("editor.heading2"), icon: IconHeading2, active: () => state().block === "h2", onClick: () => toggleBlock("h2") }, + { label: () => t("editor.heading3"), icon: IconHeading3, active: () => state().block === "h3", onClick: () => toggleBlock("h3") }, + ], + [ + { label: () => t("editor.bold"), icon: IconBold, active: () => state().bold, onClick: () => run("bold") }, + { label: () => t("editor.italic"), icon: IconItalic, active: () => state().italic, onClick: () => run("italic") }, + { label: () => t("editor.underline"), icon: IconUnderline, active: () => state().underline, onClick: () => run("underline") }, + { label: () => t("editor.strike"), icon: IconStrikethrough, active: () => state().strikeThrough, onClick: () => run("strikeThrough") }, + { label: () => t("editor.link"), icon: IconLink, onClick: openLink }, + ], + [ + { label: () => t("editor.bulletList"), icon: IconListBullets, active: () => state().ul, onClick: () => run("insertUnorderedList") }, + { label: () => t("editor.numberedList"), icon: IconListNumbers, active: () => state().ol, onClick: () => run("insertOrderedList") }, + { label: () => t("editor.quote"), icon: IconQuote, active: () => state().block === "blockquote", onClick: () => toggleBlock("blockquote") }, + { label: () => t("editor.codeBlock"), icon: IconCodeBlock, active: () => state().block === "pre", onClick: () => toggleBlock("pre") }, + ], + ]; + + return ( +

      +
      + {/* One row at every width: the tools scroll sideways on a phone so the + save control on the right never wraps out of reach. */} +
      + + {(group, index) => ( + <> +
      +
      + + {(tool) => ( + + )} + +
      + + )} + +
      +
      {props.actions}
      +
      +
      +
      document.execCommand("defaultParagraphSeparator", false, "p")} + onInput={emit} + onKeyDown={onKeyDown} + onPaste={onPaste} + onKeyUp={refreshState} + onMouseUp={refreshState} + /> +
      + + } + prompt={{ label: t("editor.linkUrl"), initialValue: linkInitial(), singleLine: true, maxLength: 2000 }} + onConfirm={applyLink} + /> +
      + ); +} diff --git a/src/components/ui/icons.tsx b/src/components/ui/icons.tsx index c864a97..de6665c 100644 --- a/src/components/ui/icons.tsx +++ b/src/components/ui/icons.tsx @@ -49,6 +49,20 @@ import waveformUrl from "@phosphor-icons/core/regular/waveform.svg?url"; import wifiHighUrl from "@phosphor-icons/core/regular/wifi-high.svg?url"; import wifiSlashUrl from "@phosphor-icons/core/regular/wifi-slash.svg?url"; import xUrl from "@phosphor-icons/core/regular/x.svg?url"; +import textBUrl from "@phosphor-icons/core/regular/text-b.svg?url"; +import textItalicUrl from "@phosphor-icons/core/regular/text-italic.svg?url"; +import textUnderlineUrl from "@phosphor-icons/core/regular/text-underline.svg?url"; +import textStrikethroughUrl from "@phosphor-icons/core/regular/text-strikethrough.svg?url"; +import textHTwoUrl from "@phosphor-icons/core/regular/text-h-two.svg?url"; +import textHThreeUrl from "@phosphor-icons/core/regular/text-h-three.svg?url"; +import textTUrl from "@phosphor-icons/core/regular/text-t.svg?url"; +import listBulletsUrl from "@phosphor-icons/core/regular/list-bullets.svg?url"; +import listNumbersUrl from "@phosphor-icons/core/regular/list-numbers.svg?url"; +import quotesUrl from "@phosphor-icons/core/regular/quotes.svg?url"; +import codeBlockUrl from "@phosphor-icons/core/regular/code-block.svg?url"; +import linkSimpleUrl from "@phosphor-icons/core/regular/link-simple.svg?url"; +import arrowUUpLeftUrl from "@phosphor-icons/core/regular/arrow-u-up-left.svg?url"; +import arrowUUpRightUrl from "@phosphor-icons/core/regular/arrow-u-up-right.svg?url"; type IconProps = { class?: string; @@ -646,3 +660,59 @@ export function IconWifi(props: IconProps) { export function IconWifiOff(props: IconProps) { return ; } + +export function IconBold(props: IconProps) { + return ; +} + +export function IconItalic(props: IconProps) { + return ; +} + +export function IconUnderline(props: IconProps) { + return ; +} + +export function IconStrikethrough(props: IconProps) { + return ; +} + +export function IconHeading2(props: IconProps) { + return ; +} + +export function IconHeading3(props: IconProps) { + return ; +} + +export function IconParagraph(props: IconProps) { + return ; +} + +export function IconListBullets(props: IconProps) { + return ; +} + +export function IconListNumbers(props: IconProps) { + return ; +} + +export function IconQuote(props: IconProps) { + return ; +} + +export function IconCodeBlock(props: IconProps) { + return ; +} + +export function IconLink(props: IconProps) { + return ; +} + +export function IconArrowUndo(props: IconProps) { + return ; +} + +export function IconArrowRedo(props: IconProps) { + return ; +} diff --git a/src/i18n/messages.ts b/src/i18n/messages.ts index 8470e1e..0233f5f 100644 --- a/src/i18n/messages.ts +++ b/src/i18n/messages.ts @@ -152,6 +152,29 @@ export type MessageKey = | "editor.numberedListLabel" | "editor.clearFormattingLabel" | "editor.bodyPlaceholder" + | "editor.paragraph" + | "editor.heading2" + | "editor.heading3" + | "editor.quote" + | "editor.codeBlock" + | "editor.link" + | "editor.linkTitle" + | "editor.linkHint" + | "editor.linkUrl" + | "editor.undo" + | "editor.redo" + | "notes.backToNotebook" + | "notes.titlePlaceholder" + | "notes.bodyPlaceholder" + | "notes.saveShortcut" + | "notes.unsaved" + | "notes.allSaved" + | "notes.saving" + | "notes.leaveTitle" + | "notes.leaveHint" + | "notes.leaveConfirm" + | "notes.filesAfterSave" + | "notes.open" | "messages.refreshList" | "messages.deleteDraft" | "messages.restoreFromTrash" @@ -2045,6 +2068,29 @@ const en: Dict = { "editor.numberedListLabel": "1. List", "editor.clearFormattingLabel": "Clear format", "editor.bodyPlaceholder": "Write your message here…", + "editor.paragraph": "Paragraph", + "editor.heading2": "Heading", + "editor.heading3": "Subheading", + "editor.quote": "Quote", + "editor.codeBlock": "Code block", + "editor.link": "Link (Ctrl+K)", + "editor.linkTitle": "Add a link", + "editor.linkHint": "Leave the address empty to remove the link.", + "editor.linkUrl": "Address", + "editor.undo": "Undo", + "editor.redo": "Redo", + "notes.backToNotebook": "Notebook", + "notes.titlePlaceholder": "Untitled note", + "notes.bodyPlaceholder": "Start writing…", + "notes.saveShortcut": "{key}+S to save", + "notes.unsaved": "Unsaved changes", + "notes.allSaved": "All changes saved", + "notes.saving": "Saving…", + "notes.leaveTitle": "Leave without saving?", + "notes.leaveHint": "Your unsaved changes to this note will be lost.", + "notes.leaveConfirm": "Leave", + "notes.filesAfterSave": "Save the note first, then attach files and drawings here.", + "notes.open": "Open", "messages.refreshList": "Refresh messages", "messages.deleteDraft": "Delete draft", "messages.restoreFromTrash": "Restore from trash", @@ -3946,6 +3992,29 @@ const tr: Dict = { "editor.numberedListLabel": "1. Liste", "editor.clearFormattingLabel": "Biçimi temizle", "editor.bodyPlaceholder": "Mesajınızı buraya yazın…", + "editor.paragraph": "Paragraf", + "editor.heading2": "Başlık", + "editor.heading3": "Alt başlık", + "editor.quote": "Alıntı", + "editor.codeBlock": "Kod bloğu", + "editor.link": "Bağlantı (Ctrl+K)", + "editor.linkTitle": "Bağlantı ekle", + "editor.linkHint": "Bağlantıyı kaldırmak için adresi boş bırak.", + "editor.linkUrl": "Adres", + "editor.undo": "Geri al", + "editor.redo": "Yinele", + "notes.backToNotebook": "Defter", + "notes.titlePlaceholder": "Başlıksız not", + "notes.bodyPlaceholder": "Yazmaya başla…", + "notes.saveShortcut": "Kaydetmek için {key}+S", + "notes.unsaved": "Kaydedilmemiş değişiklikler", + "notes.allSaved": "Tüm değişiklikler kaydedildi", + "notes.saving": "Kaydediliyor…", + "notes.leaveTitle": "Kaydetmeden çıkılsın mı?", + "notes.leaveHint": "Bu nottaki kaydedilmemiş değişiklikler kaybolacak.", + "notes.leaveConfirm": "Çık", + "notes.filesAfterSave": "Önce notu kaydet, sonra buraya dosya ve çizim ekleyebilirsin.", + "notes.open": "Aç", "messages.refreshList": "Mesajları yenile", "messages.deleteDraft": "Taslağı sil", "messages.restoreFromTrash": "Çöp kutusundan çıkar", diff --git a/src/index.css b/src/index.css index 679b494..7a84ed2 100644 --- a/src/index.css +++ b/src/index.css @@ -555,3 +555,53 @@ linear-gradient(120deg, hsl(var(--primary) / 0.28), transparent 65%); background-size: 8px 8px, 8px 8px, 100% 100%; } + +/* Note bodies: the stored HTML from the note editor, read or edited. One + stylesheet for both keeps what you type identical to what you read. */ +@layer components { + .note-prose { + color: hsl(var(--foreground)); + font-size: 0.95rem; + line-height: 1.75; + overflow-wrap: anywhere; + } + .note-prose > * + * { margin-top: 0.75em; } + .note-prose h2 { margin-top: 1.4em; font-size: 1.4rem; font-weight: 650; line-height: 1.3; letter-spacing: -0.01em; } + .note-prose h3 { margin-top: 1.2em; font-size: 1.12rem; font-weight: 650; line-height: 1.35; } + .note-prose > :first-child { margin-top: 0; } + .note-prose ul { padding-left: 1.4em; list-style: disc; } + .note-prose ol { padding-left: 1.4em; list-style: decimal; } + .note-prose li + li { margin-top: 0.25em; } + .note-prose li::marker { color: hsl(var(--muted-foreground)); } + .note-prose blockquote { + border-left: 3px solid hsl(var(--primary) / 0.55); + padding-left: 1em; + color: hsl(var(--muted-foreground)); + } + .note-prose pre { + border: 1px solid hsl(var(--border)); + border-radius: 0.5rem; + background: hsl(var(--muted) / 0.6); + padding: 0.75em 1em; + font-family: ui-monospace, SFMono-Regular, Menlo, monospace; + font-size: 0.85rem; + line-height: 1.6; + white-space: pre-wrap; + } + .note-prose code { + border-radius: 0.3rem; + background: hsl(var(--muted) / 0.8); + padding: 0.1em 0.35em; + font-family: ui-monospace, SFMono-Regular, Menlo, monospace; + font-size: 0.85em; + } + .note-prose pre code { background: transparent; padding: 0; } + .note-prose a { color: hsl(var(--primary)); text-decoration: underline; text-underline-offset: 2px; } + /* Placeholder for an empty contentEditable body. */ + .note-prose[data-empty="true"]::before { + content: attr(data-placeholder); + color: hsl(var(--muted-foreground) / 0.7); + pointer-events: none; + position: absolute; + } +} diff --git a/src/pages/note-editor-page.tsx b/src/pages/note-editor-page.tsx new file mode 100644 index 0000000..4061b81 --- /dev/null +++ b/src/pages/note-editor-page.tsx @@ -0,0 +1,31 @@ +import { useLocation } from "@tanstack/solid-router"; +import { Show, Suspense, createMemo } from "solid-js"; +import { getNoteById } from "@/api/notes"; +import { formatApiError } from "@/api/client"; +import { RouteGuard } from "@/components/layout/route-guard"; +import { NoteDocument } from "@/components/notes/note-document"; +import { ErrorAlert } from "@/components/ui/error-alert"; +import { PageSpinner } from "@/components/ui/page-spinner"; +import { createResource } from "@/lib/create-resource"; + +/** `/notes/new` and `/notes/$id` — the router remounts this page per note. */ +export default function NoteEditorPage() { + const location = useLocation(); + const id = createMemo(() => { + const match = /^\/notes\/([^/]+)$/.exec(location().pathname); + return match && match[1] !== "new" ? decodeURIComponent(match[1]) : null; + }); + const [note, { refetch }] = createResource(id, (noteId) => getNoteById(noteId)); + + return ( + + }> + }> + void refetch()} />}> + {(loaded) => } + + + + + ); +} diff --git a/src/pages/notes-page.tsx b/src/pages/notes-page.tsx index 69dd854..c719434 100644 --- a/src/pages/notes-page.tsx +++ b/src/pages/notes-page.tsx @@ -1,16 +1,14 @@ import { Show, Suspense, createEffect, createMemo, createSignal } from "solid-js"; import { createResource } from "@/lib/create-resource"; -import { useLocation } from "@tanstack/solid-router"; +import { useLocation, useNavigate } from "@tanstack/solid-router"; import { deleteNoteById } from "@/api/notes"; import { getNotes } from "@/api/notes"; import { patchNoteById } from "@/api/notes"; import { postNote } from "@/api/notes"; -import { postNoteFile } from "@/api/notes"; import { formatApiError } from "@/api/client"; import { Alert } from "@/components/ui/alert"; import { RouteGuard } from "@/components/layout/route-guard"; import { DataSection } from "@/components/ui/data-section"; -import { NoteForm } from "@/components/notes/note-form"; import { NoteImportPanel } from "@/components/notes/note-import-panel"; import { NoteList } from "@/components/notes/note-list"; import { Button } from "@/components/ui/button"; @@ -36,12 +34,13 @@ export default function NotesPage() { function NotesContent() { const t = useT(); const location = useLocation(); + const navigate = useNavigate(); const [error, setError] = createSignal(""); const [flash, setFlash] = createFlash(); - const [createOpen, setCreateOpen] = createSignal(location().searchStr.includes("action=new")); const [importOpen, setImportOpen] = createSignal(location().searchStr.includes("action=import")); createEffect(() => { - if (location().searchStr.includes("action=new")) setCreateOpen(true); + // Old deep link: the new-note side panel is now its own page. + if (location().searchStr.includes("action=new")) void navigate({ to: "/notes/new", replace: true }); if (location().searchStr.includes("action=import")) setImportOpen(true); }); const [page, setPage] = createSignal(0); @@ -91,43 +90,13 @@ function NotesContent() { /> - - setCreateOpen(false)} - onSubmit={async (values) => { - setError(""); - const note = await postNote({ - title: values.title, - content: values.content || undefined, - }); - let failedUploads = 0; - for (const file of values.files) { - try { - await postNoteFile(note.id, file); - } catch { - failedUploads += 1; - } - } - await refetch(); - setCreateOpen(false); - if (failedUploads > 0) { - setError(t("notes.fileUploadPartial", { count: failedUploads })); - return; - } - setFlash(t("common.created")); - }} - /> - -
      - @@ -141,7 +110,7 @@ function NotesContent() { {flash()} - + {error()} }> @@ -152,6 +121,7 @@ function NotesContent() { void navigate({ to: "/notes/$id", params: { id: note.id } })} emptyTitle={t("dashboard.emptyNotesTitle")} emptyDescription={t("notes.empty")} onUpdate={(id, values) => diff --git a/src/routes/router.tsx b/src/routes/router.tsx index 31d61d9..7a1b067 100644 --- a/src/routes/router.tsx +++ b/src/routes/router.tsx @@ -28,6 +28,7 @@ const LoginPage = lazyRoute(() => import("@/pages/login-page")); const RegisterPage = lazyRoute(() => import("@/pages/register-page")); const DashboardPage = lazyRoute(() => import("@/pages/dashboard-page")); const NotesPage = lazyRoute(() => import("@/pages/notes-page")); +const NoteEditorPage = lazyRoute(() => import("@/pages/note-editor-page")); const EventsPage = lazyRoute(() => import("@/pages/events-page")); const EventDetailPage = lazyRoute(() => import("@/pages/event-detail-page")); const HomeworkPage = lazyRoute(() => import("@/pages/homework-page")); @@ -118,6 +119,18 @@ const notesRoute = createRoute({ component: NotesPage, }); +const noteNewRoute = createRoute({ + getParentRoute: () => rootRoute, + path: "/notes/new", + component: NoteEditorPage, +}); + +const noteDetailRoute = createRoute({ + getParentRoute: () => rootRoute, + path: "/notes/$id", + component: NoteEditorPage, +}); + const eventsRoute = createRoute({ getParentRoute: () => rootRoute, path: "/events", @@ -482,6 +495,8 @@ const routeTree = rootRoute.addChildren([ loginRoute, registerRoute, notesRoute, + noteNewRoute, + noteDetailRoute, eventsRoute, eventDetailRoute, homeworkRoute,