From cb5976edb27f54e5b9aad294fe2db70eadc6cd64 Mon Sep 17 00:00:00 2001 From: Tiel Coder Date: Fri, 20 Nov 2026 12:18:24 +0000 Subject: [PATCH] feat(training): rich-text lessons with inline images and 25 MB manuals MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Admins were authoring plain-text lessons, which made illustrated tutorials and reordering images impossible. Lesson bodies are now sanitized HTML from a Tiptap editor with alignment, sizing, drag-reorder and alt text, and inline images reuse the training_resources table so no migration is needed. Attachments grow to 25 MB, PDFs stream inline, and SVG is rejected because it can execute as a document. Legacy plain-text bodies are normalized on read. 🤖 Generated with Codebuff Co-Authored-By: Codebuff --- .env.example | 2 +- README.md | 2 +- docs/PROJECT-STATE.md | 8 +- e2e/training.spec.ts | 57 ++ package.json | 6 + pnpm-lock.yaml | 620 ++++++++++++++++++ src/app/(app)/training/guides/admin/page.tsx | 23 +- src/app/(app)/training/page.tsx | 8 +- src/app/api/dev/training/lessons/route.ts | 20 +- src/app/api/dev/training/resources/route.ts | 13 +- src/app/api/training/files/[id]/route.ts | 11 +- src/app/globals.css | 131 ++++ src/components/app/training-panel.tsx | 243 ++++--- .../app/training/rich-text-editor.tsx | 535 +++++++++++++++ src/lib/rich-text.test.ts | 64 ++ src/lib/rich-text.ts | 122 ++++ src/lib/uploads.test.ts | 16 +- src/lib/uploads.ts | 32 +- 18 files changed, 1799 insertions(+), 114 deletions(-) create mode 100644 src/components/app/training/rich-text-editor.tsx create mode 100644 src/lib/rich-text.test.ts create mode 100644 src/lib/rich-text.ts diff --git a/.env.example b/.env.example index 10c019d..2ba68e0 100644 --- a/.env.example +++ b/.env.example @@ -65,7 +65,7 @@ POSTMARK_FROM=media@localhost # Console transport directory (a named Docker volume in compose). OUTBOX_DIR=/tmp/outbox -# Training attachments (metadata in Postgres, bytes on disk; max 5 MB each). +# Training attachments (metadata in Postgres, bytes on disk; max 25 MB each). UPLOAD_DIR=/tmp/uploads # NFS archive. Mount the export on the Docker host, then point diff --git a/README.md b/README.md index b958b3d..36d3516 100644 --- a/README.md +++ b/README.md @@ -61,7 +61,7 @@ Built with Next.js 15, React 19, TypeScript, PostgreSQL 16, and Drizzle ORM. It - Volunteers record self-comfort; mentors/admins verify the real level. Every level change appends an assessment-history row. - Per-skill mentor opt-in and persisted admin approval; trainee shadow seats require a paired, mentor-ready volunteer. - Skills matrix, readiness scoring, and growth-goal domain rules. -- Training lessons with attachments (images, PDF, text, Markdown, Word; 5 MB max), draft/publish, and separate admin/volunteer guides. +- Rich-text training lessons with headings, lists, links, inline images (align, resize, drag to reorder), and PDF/Word/text manuals up to 25 MB, plus draft/publish controls and separate admin/volunteer guides. ### Events and media diff --git a/docs/PROJECT-STATE.md b/docs/PROJECT-STATE.md index 842ec5e..dc06f2f 100644 --- a/docs/PROJECT-STATE.md +++ b/docs/PROJECT-STATE.md @@ -553,10 +553,10 @@ Still missing screens (APIs exist): volunteer profile + prefs, blackout calendar ## 13. Training, uploads, settings -- Lessons: plain-text body, published flag, ordering. Volunteers see published; admins author/publish/delete. Two starter lessons seeded only when the table is empty. -- Attachments: images/PDF/plain text/Markdown/Word, ≤5 MB, random stored name, metadata in Postgres, bytes under `UPLOAD_DIR`. - - Uploads verify **magic bytes** against the declared MIME. - - Serving requires a session; only images render inline, everything else is an attachment, with `nosniff`. +- Lessons: sanitized rich-text HTML body (headings, lists, links, inline images with alignment/size/move controls), published flag, ordering. Volunteers see published; admins author/publish/delete. Two plain-text starter lessons seeded only when the table is empty and normalized to HTML on read. +- Attachments: images/PDF/plain text/Markdown/Word, ≤25 MB, random stored name, metadata in Postgres, bytes under `UPLOAD_DIR`. + - Uploads verify **magic bytes** against the declared MIME; SVG is rejected because it can execute as a document. + - Serving requires a session; images and PDFs render inline, everything else is a download, with `nosniff`. - Any signed-in team member can fetch any attachment id (team-wide content by design). - Delete removes bytes best-effort; there is no orphan-file sweep. - Runtime settings: `app_settings` holds sender/inbox and the Gmail address + AES-256-GCM app password. Blank password keeps the stored one; an empty address disconnects Gmail. Saves are audited without the secret. diff --git a/e2e/training.spec.ts b/e2e/training.spec.ts index 88bfc1c..9e20b9c 100644 --- a/e2e/training.spec.ts +++ b/e2e/training.spec.ts @@ -9,6 +9,8 @@ import { signInAs, resetDb, BASE } from "./dev"; let lessonTitle: string; let lessonId: string; +test.describe.configure({ mode: "serial" }); + test.describe("training", () => { test.beforeAll(async ({ browser }) => { const context = await browser.newContext(); @@ -59,6 +61,57 @@ test.describe("training", () => { await expect(page.getByRole("link", { name: "guide.txt" })).toBeVisible(); }); + test("admin adds a rich image and a PDF manual", async ({ page }) => { + await page.setViewportSize({ width: 1024, height: 900 }); + await signInAs(page, "admin@glenloch.local"); + await page.goto(`${BASE}/training`); + + const lesson = page + .locator("li") + .filter({ has: page.getByRole("heading", { name: lessonTitle }) }) + .first(); + await lesson.getByRole("button", { name: "Edit" }).click(); + + // 1×1 PNG, but the upload route only needs a valid PNG signature here. + const png = Buffer.from( + "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mP8/x8AAusB9Y9Z7ZkAAAAASUVORK5CYII=", + "base64", + ); + await page + .getByLabel("Upload an image for the lesson") + .setInputFiles({ name: "console.png", mimeType: "image/png", buffer: png }); + + const image = page.getByRole("img", { name: "console.png" }); + await expect(image).toBeVisible(); + await image.click(); + await expect( + page.getByRole("toolbar", { name: "Selected image" }), + ).toBeVisible(); + await page.getByRole("button", { name: "Align image right" }).click(); + await page + .getByRole("button", { name: "Set image width to 50%" }) + .click(); + await page.getByRole("button", { name: "Save lesson" }).click(); + + await expect( + lesson.locator('img[data-align="right"][width="50%"]'), + ).toBeVisible(); + + const pdf = Buffer.from("%PDF-1.7\n% E2E manual\n"); + await lesson + .getByLabel("Attach a manual or document") + .setInputFiles({ name: "audio-manual.pdf", mimeType: "application/pdf", buffer: pdf }); + await lesson.getByRole("button", { name: "Attach", exact: true }).click(); + + const manual = lesson.getByRole("link", { name: "audio-manual.pdf" }); + await expect(manual).toBeVisible(); + const href = await manual.getAttribute("href"); + expect(href).toBeTruthy(); + const download = await page.request.get(`${BASE}${href}`); + expect(download.status()).toBe(200); + expect(download.headers()["content-disposition"]).toContain("inline"); + }); + test("volunteer sees published lessons but no authoring controls", async ({ page, }) => { @@ -73,5 +126,9 @@ test.describe("training", () => { page.getByRole("button", { name: "Create lesson" }), ).toHaveCount(0); await expect(page.getByRole("link", { name: "guide.txt" })).toBeVisible(); + await expect(page.getByRole("img", { name: "console.png" })).toBeVisible(); + await expect( + page.getByRole("link", { name: "audio-manual.pdf" }), + ).toBeVisible(); }); }); diff --git a/package.json b/package.json index f62fc2f..1aaf864 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,10 @@ "dependencies": { "@radix-ui/react-label": "^2.1.17", "@radix-ui/react-slot": "^1.5.0", + "@tiptap/extension-image": "^3.34.0", + "@tiptap/pm": "^3.34.0", + "@tiptap/react": "^3.34.0", + "@tiptap/starter-kit": "^3.34.0", "archiver": "^8.0.0", "class-variance-authority": "^0.7.1", "clsx": "^2.1.1", @@ -31,6 +35,7 @@ "postgres": "^4.1.1", "react": "19.1.0", "react-dom": "19.1.0", + "sanitize-html": "^2.18.2", "sharp": "0.34.5", "tailwind-merge": "^3.7.0", "tailwindcss-animate": "^1.0.7", @@ -48,6 +53,7 @@ "@types/nodemailer": "^8.0.2", "@types/react": "^19", "@types/react-dom": "^19", + "@types/sanitize-html": "^2.16.2", "dotenv": "^18.0.10", "drizzle-kit": "^0.31.11", "eslint": "^9", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index ecd5b20..eb68d42 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -14,6 +14,18 @@ importers: '@radix-ui/react-slot': specifier: ^1.5.0 version: 1.5.0(@types/react@19.3.0)(react@19.1.0) + '@tiptap/extension-image': + specifier: ^3.34.0 + version: 3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0)) + '@tiptap/pm': + specifier: ^3.34.0 + version: 3.34.0 + '@tiptap/react': + specifier: ^3.34.0 + version: 3.34.0(@floating-ui/dom@1.8.0)(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))(@tiptap/pm@3.34.0)(@types/react-dom@19.3.0(@types/react@19.3.0))(@types/react@19.3.0)(react-dom@19.1.0(react@19.1.0))(react@19.1.0) + '@tiptap/starter-kit': + specifier: ^3.34.0 + version: 3.34.0 archiver: specifier: ^8.0.0 version: 8.0.0(bare-buffer@3.7.3) @@ -50,6 +62,9 @@ importers: react-dom: specifier: 19.1.0 version: 19.1.0(react@19.1.0) + sanitize-html: + specifier: ^2.18.2 + version: 2.18.2 sharp: specifier: 0.34.5 version: 0.34.5 @@ -96,6 +111,9 @@ importers: '@types/react-dom': specifier: ^19 version: 19.3.0(@types/react@19.3.0) + '@types/sanitize-html': + specifier: ^2.16.2 + version: 2.16.2 dotenv: specifier: ^18.0.10 version: 18.0.10 @@ -804,6 +822,15 @@ packages: '@noble/hashes': optional: true + '@floating-ui/core@1.8.0': + resolution: {integrity: sha512-0CIZ5itps/8x7BG8dEIhs53BvCUH2PCoogtakwRTut+Arm58sJooJ0AuZhLw2HJYIR5cMLNPBSS728sPho2khQ==} + + '@floating-ui/dom@1.8.0': + resolution: {integrity: sha512-yXSrzeHZBTZadLOlfyhCkJHNeLJnHRnRInwdZ40L7ZiaAtrBwoYlsDrX3v5zB1Utk7CLfzcOVnVVWoXEky7Ceg==} + + '@floating-ui/utils@0.2.12': + resolution: {integrity: sha512-HpCo8tmWzLVad5s2d19EhAz5zqrrQ6s69qd6moPMQvkOuSwDT1YgRfWSVuc4ennqrgv3OHppiOGMQ7oC13yIww==} + '@humanfs/core@0.19.2': resolution: {integrity: sha512-UhXNm+CFMWcbChXywFwkmhqjs3PRCmcSa/hfBgLIb7oQ5HNb1wS0icWsGtSAUNgefHeI+eBrA8I1fxmbHsGdvA==} engines: {node: '>=18.18.0'} @@ -1360,6 +1387,161 @@ packages: peerDependencies: '@testing-library/dom': '>=7.21.4' + '@tiptap/core@3.34.0': + resolution: {integrity: sha512-PwpE5MAXt586AxIO5bW2RyJ3OUXdPfG5M1M5v/LIMCkDwIgRKegx8uERlABoI6575mWqaH/P6Xm+tequJ5UUnw==} + peerDependencies: + '@tiptap/pm': 3.34.0 + + '@tiptap/extension-blockquote@3.34.0': + resolution: {integrity: sha512-mnqvP3WpE0HBoHE9q/R9fi+M103w7Bhw5C9bnA4OqMJ9buOdoOJquzFtfT+7YVBIphgkjRWDao1dgUdoYJgWjQ==} + peerDependencies: + '@tiptap/core': 3.34.0 + '@tiptap/pm': 3.34.0 + + '@tiptap/extension-bold@3.34.0': + resolution: {integrity: sha512-QvqHpxDe1vEnaOk88O28zsKD+jXTRWOYTBuoosLJzU+fNedC0z3uEXVqUUO4ljwJxj604mLuQBB4aVb+/7ObSg==} + peerDependencies: + '@tiptap/core': 3.34.0 + + '@tiptap/extension-bubble-menu@3.34.0': + resolution: {integrity: sha512-Q6+/RxlaYLsF+hm9MFY//wwVFA4Apfjn2EAnbjaBlaiIs1LtB/s5t5fSjRwCBzadTf9ysMvGh7parpN1hT0tug==} + peerDependencies: + '@tiptap/core': 3.34.0 + '@tiptap/pm': 3.34.0 + + '@tiptap/extension-bullet-list@3.34.0': + resolution: {integrity: sha512-3xtzmtIMoqGa3fAcNmRiR1DHTBMiGr167mgt5ksK6a+m38tCl74W+kPf59HknGojbhI/pVM+Unf2htsOdijDNw==} + peerDependencies: + '@tiptap/extension-list': 3.34.0 + + '@tiptap/extension-code-block@3.34.0': + resolution: {integrity: sha512-PTwtNuuGtlqyDTGms8E3ou0918gbDmzdh68i2taIZ4cU5vPe0doaKbtcQ2emX8Te+IOnm80NdlNM1OxIry9mnA==} + peerDependencies: + '@tiptap/core': 3.34.0 + '@tiptap/pm': 3.34.0 + + '@tiptap/extension-code@3.34.0': + resolution: {integrity: sha512-+97O+ao+wnKGMy13q7T+JUFDWsbPYvAzfPHMqo+vTMFGphiAVHnmXTQZ+4rx7V2KnWSYY1IvSpFVORb7n1sbWQ==} + peerDependencies: + '@tiptap/core': 3.34.0 + + '@tiptap/extension-document@3.34.0': + resolution: {integrity: sha512-Mvs7AUGJkUWI4HfsCNvWQF2f4YdVqR1UHKYnkFdxCifuGPwFBc8bT7rNMT6NBFjRZADbf4HrE/UIQqVQA5Gfyw==} + peerDependencies: + '@tiptap/core': 3.34.0 + + '@tiptap/extension-dropcursor@3.34.0': + resolution: {integrity: sha512-U7dpUo1pcxWbVi11iJqWqE29GMdQOewwbO7ChD3J0CWqJ3ZPWo0s777dLTQIGr3ImxpZo6lTrWyXqzkNf0rHfw==} + peerDependencies: + '@tiptap/extensions': 3.34.0 + + '@tiptap/extension-floating-menu@3.34.0': + resolution: {integrity: sha512-3D/cYVi4T5SzgMQR9A5cKSSDspVty92/o/+xnON5+buPSD/7+EVVa0XubCoRl/zNqo8jGapZX3JboslQO4Q7ng==} + peerDependencies: + '@floating-ui/dom': ^1.0.0 + '@tiptap/core': 3.34.0 + '@tiptap/pm': 3.34.0 + + '@tiptap/extension-gapcursor@3.34.0': + resolution: {integrity: sha512-qA+1MLOun+q2njlh5Wjw2N6Wyuxaw8bIgU31abwPxhNwg2XNlfBr27O3zKO5GGxDyyc2waEymhSLjat6f97hUA==} + peerDependencies: + '@tiptap/extensions': 3.34.0 + + '@tiptap/extension-hard-break@3.34.0': + resolution: {integrity: sha512-um2QJimgSKRpaUBVvAfRWItmcJEJPnv4bVz78FyOrpxvQuVSgV18giF7t9pLCMJPBJ/H+jTSPQ87t+A4Xn4whA==} + peerDependencies: + '@tiptap/core': 3.34.0 + + '@tiptap/extension-heading@3.34.0': + resolution: {integrity: sha512-bm43fyQThYPmpkxHYy8EaGhtRiAXUSfp4Sn0DI6Z/ClvLEKGngogl883wUcqwdWCeViJwz1rte7z3+AqAigrCg==} + peerDependencies: + '@tiptap/core': 3.34.0 + + '@tiptap/extension-horizontal-rule@3.34.0': + resolution: {integrity: sha512-gtKVypnxEccuoaQqZp7WFmjdlT/pNMGB+MxkTKPLi598Zw6xQaN+zJiqBaIVOmqIqu6l+jF0h1FaRyB69Tw8tA==} + peerDependencies: + '@tiptap/core': 3.34.0 + '@tiptap/pm': 3.34.0 + + '@tiptap/extension-image@3.34.0': + resolution: {integrity: sha512-IC8PfiTKWnRE9USYM/gI9aZkrGsgJ3IhduQX1JceE5wMp3ce2QKzEkDkFZrjk2EYgCPNCuvIIg5L0nbmogcKsg==} + peerDependencies: + '@tiptap/core': 3.34.0 + + '@tiptap/extension-italic@3.34.0': + resolution: {integrity: sha512-X6jRBt0bCwx2TJpNuAxPyfPw3KFyfAKdeW51iwHd44NVmYa5kK7R/RC/l+SUKMhyW8NyNh4Ia9TqeZjhZcgx7Q==} + peerDependencies: + '@tiptap/core': 3.34.0 + + '@tiptap/extension-link@3.34.0': + resolution: {integrity: sha512-yd/pHa4T/J/3oY4BMB4qHJHkde1z5V6c/2fY7OsG86R8oMrCim3Vo19yCHc7xsZC8RwjgWoCth1lAIdwvHNnLQ==} + peerDependencies: + '@tiptap/core': 3.34.0 + '@tiptap/pm': 3.34.0 + + '@tiptap/extension-list-item@3.34.0': + resolution: {integrity: sha512-NM0e2LjYoyaKMURMR8btBAbQ2KcUNxR2KiC7kTe+0b3GcGvaGArRUbZwgoWVmgHbi/QFSR63GxrU6WCiA+s8kg==} + peerDependencies: + '@tiptap/extension-list': 3.34.0 + + '@tiptap/extension-list-keymap@3.34.0': + resolution: {integrity: sha512-QG3gBIb9bbbfKNDw/ilJRl0urybJ1u+zzI5oTiDq4zVr86pROi7lPG0qj1bTW2uM3e519KLEYAJMhP6/m9SzkQ==} + peerDependencies: + '@tiptap/extension-list': 3.34.0 + + '@tiptap/extension-list@3.34.0': + resolution: {integrity: sha512-PqYWtHzDQJMaJO0NdG7v2ngprY1YUE8bBKaG1shLBJrPGoo+8XiKrXCGI+mYrh5R/HHR9hkbK8n636txVd8dZw==} + peerDependencies: + '@tiptap/core': 3.34.0 + '@tiptap/pm': 3.34.0 + + '@tiptap/extension-ordered-list@3.34.0': + resolution: {integrity: sha512-wFTfwBDKPowFwOH3VIXr1Oq3HbAa81OxslC9PW3ckEfAn9ckYXN/BWqGch87JLBPvLkW6NFYOwPD0OmwtnUBVA==} + peerDependencies: + '@tiptap/extension-list': 3.34.0 + + '@tiptap/extension-paragraph@3.34.0': + resolution: {integrity: sha512-hGoyXNl1xz7k+h5wNcSRY+UGe2uQE+YLf9iGuFPmzv2ub9XqRmuVc7MiTK6t+tDWdmPag4rH2c8waJ9GgmvzUQ==} + peerDependencies: + '@tiptap/core': 3.34.0 + + '@tiptap/extension-strike@3.34.0': + resolution: {integrity: sha512-rwzbX83SceQvdx/IcPqU5oF+7a7zB2SJFLAEkLUaXZkycCX//PC0abpaFC3KtUJ4EOCsGNxUNhXoddasgQRSKw==} + peerDependencies: + '@tiptap/core': 3.34.0 + + '@tiptap/extension-text@3.34.0': + resolution: {integrity: sha512-90gNJ24bsTrJVxfnnbXXFhsmPGUsk9ZGjwbbJ4OvqIoYX4BjmwuPBHL4NePL7kKwPtTKhcIHsm3C3ofZlVH/rg==} + peerDependencies: + '@tiptap/core': 3.34.0 + + '@tiptap/extension-underline@3.34.0': + resolution: {integrity: sha512-4/Di2L96tCUo31SalwjeElOQC64bP2lIqXsruYNndo510fAkYEmzGHhfu4Eh0a4Z94lyA9BYI9zAgJS2yTdq8w==} + peerDependencies: + '@tiptap/core': 3.34.0 + + '@tiptap/extensions@3.34.0': + resolution: {integrity: sha512-VA5kMiyactt71jqyNrdVB8kyGeD35AvjhcL1bKf12+XTTXTtOJkhS2/IQhNYK4ooCW0bpmNiuBnrdFWaeXyUOg==} + peerDependencies: + '@tiptap/core': 3.34.0 + '@tiptap/pm': 3.34.0 + + '@tiptap/pm@3.34.0': + resolution: {integrity: sha512-/r64RekPVaLw/YUjGes8tH5voz5PYWLW6gahMf+nDZKs6nK4RtoZ4O6YFI+nV8XD1hygseQZPeJkT5OOkI4AdA==} + + '@tiptap/react@3.34.0': + resolution: {integrity: sha512-DDqcnPZ0pVeU9E3hvQcK4rA5AWRe7PHDeFAGL6lW/aniYkJ1W2kKimjny3Lz43TxplvbH67f03Wey5l0GrKk8A==} + peerDependencies: + '@tiptap/core': 3.34.0 + '@tiptap/pm': 3.34.0 + '@types/react': ^17.0.0 || ^18.0.0 || ^19.0.0 + '@types/react-dom': ^17.0.0 || ^18.0.0 || ^19.0.0 + react: ^17.0.0 || ^18.0.0 || ^19.0.0 + react-dom: ^17.0.0 || ^18.0.0 || ^19.0.0 + + '@tiptap/starter-kit@3.34.0': + resolution: {integrity: sha512-SPlLjlGD8KpTBsUQJfNuRLprSCV8d69QACBloPZXCF0XGfpTmJWFzt1vGTfBzisRrI1iV/goXJJr8qw2SAIpiw==} + '@ts-morph/common@0.27.0': resolution: {integrity: sha512-Wf29UqxWDpc+i61k3oIOzcUfQt79PIT9y/MWfAGlrkjg6lBC1hwDECLXPVJAhWjiGbfBCxZd65F/LIZF3+jeJQ==} @@ -1404,6 +1586,12 @@ packages: '@types/readdir-glob@1.1.5': resolution: {integrity: sha512-raiuEPUYqXu+nvtY2Pe8s8FEmZ3x5yAH4VkLdihcPdalvsHltomrRC9BzuStrJ9yk06470hS0Crw0f1pXqD+Hg==} + '@types/sanitize-html@2.16.2': + resolution: {integrity: sha512-kuAbgDCFv418flrp3z4o/4ufLA/5ovmXRH0L419iZCPGO7w00znjeDI5Wy/KZWNIBpDQc7hucCK+J5almB6FyA==} + + '@types/use-sync-external-store@0.0.6': + resolution: {integrity: sha512-zFDAD+tlpf2r4asuHEj0XH6pY6i0g5NeAHPn+15wk3BV6JA69eERFXC1gyGThDkVa1zCyKr5jox1+2LbV/AMLg==} + '@types/validate-npm-package-name@4.0.2': resolution: {integrity: sha512-lrpDziQipxCEeK5kWxvljWYhUvOiB2A9izZd9B2AFarYAkqZshb4lPbRs7zKEic6eGtH8V/2qJW+dPp9OtF6bw==} @@ -1944,6 +2132,9 @@ packages: resolution: {integrity: sha512-BS8PfmtDGnrgYdOonGZQdLZslWIeCGFP9tpan0hi1Co2Zr2NKADsvGYA8XxuG/4UWgJ6Cjtv+YJnB6MM69QGlQ==} engines: {node: '>= 0.4'} + dayjs@1.11.23: + resolution: {integrity: sha512-QDTCU0M0MxR3hQfnlDJfwekQiaanm1ubOD231u73WBckQ/fsamwRLiE2GBz6D3a/xF1NgfiDLJjXBa1hYOYTtQ==} + debounce-fn@4.0.0: resolution: {integrity: sha512-8pYCQiL9Xdcg0UPSD3d+0KMlOjp+KGU5EPwYddgzQ7DATsg4fuUDjQtsYLmWjnk2obnNHgV3vE2Y4jejSOJVBQ==} engines: {node: '>=10'} @@ -2029,6 +2220,22 @@ packages: dom-accessibility-api@0.6.3: resolution: {integrity: sha512-7ZgogeTnjuHbo+ct10G9Ffp0mif17idi0IyWNVA/wcwcm7NPOD/WEHVP3n7n3MhXqxoIYm8d6MuZohYWIZ4T3w==} + dom-serializer@3.1.1: + resolution: {integrity: sha512-4MEa38/QexBob6gFNwu+EGdWvhJ1OKuNwdYY3Y3NyeWDQfnGeDYQUDfIRzWu5B5gsv03so2Uxd28YC6zrsx3Lw==} + engines: {node: '>=20.19.0'} + + domelementtype@3.0.0: + resolution: {integrity: sha512-umCQid3jKbDmVjx8jGaW7uUykm4DEUeyV21hPxNMo2nV955DhUThwqyOIDtreepP31hl84X7G5U9ZfsWvIB3Pg==} + engines: {node: '>=20.19.0'} + + domhandler@6.0.1: + resolution: {integrity: sha512-gYzvtM72ZtxQO0T048kd6HWSbbGCNOUwcnfQ01cqIJ4X2IYKFFHZ5mKvrQETcFXxsRObZulDaKmy//R7TPtsBg==} + engines: {node: '>=20.19.0'} + + domutils@4.0.2: + resolution: {integrity: sha512-qI4JLRKnSzqFqr7hAlS5xQDusBCjKSEG4t4+7aNrIQMHBcsC2TGEhuyABJdYkgSewL57PNLYEiibY2iPKhKpaA==} + engines: {node: '>=20.19.0'} + dot-prop@6.0.1: resolution: {integrity: sha512-tE7ztYzXHIeyvc7N+hR3oi7FIbf/NIjVP9hmAt3yMXzrQ072/fpjGLx2GxNxGxUl5V73MEqYzioOMoVhGMJ5cA==} engines: {node: '>=10'} @@ -2162,6 +2369,10 @@ packages: resolution: {integrity: sha512-rRqJg/6gd538VHvR3PSrdRBb/1Vy2YfzHqzvbhGIQpDRKIa4FgV/54b5Q1xYSxOOwKvjXweS26E0Q+nAMwp2pQ==} engines: {node: '>=8.6'} + entities@8.1.0: + resolution: {integrity: sha512-kxL7msIffSuh9aaFAMD7rxAIuTRMAHMeBtgHW2yUdWw732ZNh4MehkF2gdjvtdmikkaIP9bFDDJOPlsvm7avrA==} + engines: {node: '>=20.19.0'} + entities@9.0.0: resolution: {integrity: sha512-oJFNDJg3kTPwAD1cNn2+WmUq4wFoo09npc3Ydf1D7ED4smRiWrsKnaLxykrTWgyGEcusc87P5dxlAleol9kpkg==} engines: {node: '>=20.19.0'} @@ -2387,6 +2598,10 @@ packages: fast-deep-equal@3.1.3: resolution: {integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==} + fast-equals@5.4.5: + resolution: {integrity: sha512-yKEpcFuRPu/pTQL2VB8YKE2yFldrLlIsoWtJeBnAdqEhvu21OgkFT0C8njf/xYc2LSZGEr3K9JGjthHJxnVLvQ==} + engines: {node: '>=6.0.0'} + fast-fifo@1.3.2: resolution: {integrity: sha512-/d9sfos4yxzpwkDkuN7k2SqFKtYNmCTzgfEpz82x34IM9/zc8KGxQoXg1liNC/izpRM/MBdt44Nmx41ZWqk+FQ==} @@ -2565,6 +2780,10 @@ packages: resolution: {integrity: sha512-UikN5yr7xsCDAq87Or5or0PAlD3HJJOKVzM05az588WnpDJ4Ux7a2A53Qi6gofGg2/EtvF/H4hCi/TXfCW4Y6w==} engines: {node: ^22.13.0 || >=24.0.0} + htmlparser2@12.0.0: + resolution: {integrity: sha512-Tz7u1i95/g2x2jz81+x0FBVhBhY5aRTvD3tXXdFaljuNdzDLJ8UGNRrTcj2cgQvAg3iW/h77Fz15nLW0L0CrZw==} + engines: {node: '>=20.19.0'} + human-signals@2.1.0: resolution: {integrity: sha512-B4FFZ6q/T2jhhksgkbEW3HBvWIfDW85snkQgawt07S7J5QXTk6BkNV+0yAeZrM5QpMAdYlocGoljn0sJ/WQkFw==} engines: {node: '>=10.17.0'} @@ -2722,6 +2941,10 @@ packages: resolution: {integrity: sha512-+Pgi+vMuUNkJyExiMBt5IlFoMyKnr5zhJ4Uspz58WOhBF5QoIZkFyNHIbBAtHwzVAgk5RtndVNsDRN61/mmDqg==} engines: {node: '>=12'} + is-plain-object@5.1.0: + resolution: {integrity: sha512-bUi/yjmtKYcRVUtWRGr0UA6xEFh2I6zWUwMrUXB3s7bmYCaZ8a+0ZsTRkrawh/mzlSD1Y0Ph8bp/U+TvBpWDNw==} + engines: {node: '>=0.10.0'} + is-potential-custom-element-name@1.0.1: resolution: {integrity: sha512-bCYeRA2rVibKZd+s2625gGnGF/t7DSqDs4dP7CrLA1m7jKWz6pps0LpYLJN8Q64HtmPKJ1hrN3nzPNKFEKOUiQ==} @@ -2883,6 +3106,9 @@ packages: resolution: {integrity: sha512-MbjN408fEndfiQXbFQ1vnd+1NoLDsnQW41410oQBXiyXDMYH5z505juWa4KUE1LqxRC7DgOgZDbKLxHIwm27hA==} engines: {node: '>=0.10'} + launder@1.7.2: + resolution: {integrity: sha512-DLg3HPnHUfBi5/MxMLmJD12dmlMpFEC2HgMW6vkZ/9JR0RU00kXoRGvDxAvFmdO0o610OA77i4FgNTLucmhDVg==} + lazystream@1.0.1: resolution: {integrity: sha512-b94GiNHQNy6JNTrt5w6zNyffMrNkXZb3KTkCZJb2V1xaEGCk093vkZ2jk3tpaeP33/OiXC+WvK9AxUebnf5nbw==} engines: {node: '>= 0.6.3'} @@ -2961,6 +3187,9 @@ packages: resolution: {integrity: sha512-WkUDrojuJs0xkgGf2udWxa3yGBRxPtxUkB79i6aCZLRgc7PM8fZe9TosfPDcvEpQZbuFASnHYmRLBLUbmLOIIA==} engines: {node: '>= 12.0.0'} + linkifyjs@4.4.0: + resolution: {integrity: sha512-InTexvtbai+2c+dEVGcc6O6P2DMVIiwD9a/i4zFroazOIYLOS6FSVmAJ7kFeumnCMx6/gQqNAkbUvgMubV4+MA==} + locate-path@3.0.0: resolution: {integrity: sha512-7AO748wWnIhNqAuaty2ZWHkQHRSNfPVIsPIfwEOWO22AmaoVrWavlOcMR5nzTLNYvp36X220/maaRsrec1G65A==} engines: {node: '>=6'} @@ -3192,6 +3421,9 @@ packages: resolution: {integrity: sha512-weP+BZ8MVNnlCm8c0Qdc1WSWq4Qn7I+9CJGm7Qali6g44e/PUzbjNqJX5NJ9ljlNMosfJvg1fKEGILklK9cwnw==} engines: {node: '>=18'} + orderedmap@2.1.1: + resolution: {integrity: sha512-TvAWxi0nDe1j/rtMcWcIj94+Ffe6n7zhow33h40SKxmsmozs6dz/e+EajymfoFcHd7sxNn8yHM8839uixMOV6g==} + own-keys@1.0.2: resolution: {integrity: sha512-19YVAg7T+WTrxggPukVq7DjTv6+PJ867TmhCvBsYwmbFCsZd344rq2Ld1p0wo8f8Qrrhgp82c6FJRqdXWtSEhg==} engines: {node: '>= 0.4'} @@ -3224,6 +3456,9 @@ packages: resolution: {integrity: sha512-TXfryirbmq34y8QBwgqCVLi+8oA3oWx2eAnSn62ITyEhEYaWRlVZ2DvMM9eZbMs/RfxPu/PK/aBLyGj4IrqMHw==} engines: {node: '>=18'} + parse-srcset@1.0.2: + resolution: {integrity: sha512-/2qh0lav6CmI15FzA3i/2Bzk2zCgQhGMkvhOhKNcBVQ1ldgpbfiNTVslmooUmWJcADi1f1kIeynbDRVzNlfR6Q==} + parse5-parser-stream@8.1.1: resolution: {integrity: sha512-hMcVbbUJcQmP8rURWUdYrT1flRiBiBVjq/RYGguJpDUgIXSqdYKlE0CxthmdMWoSlBAuL5bUBa73g0pttSy7Hw==} @@ -3335,6 +3570,45 @@ packages: prop-types@15.8.1: resolution: {integrity: sha512-oj87CgZICdulUohogVAR7AjlC0327U4el4L6eAvOqCeudMDVU0NThNaV+b9Df4dXgSP1gXMTnPdhfe/2qDH5cg==} + prosemirror-changeset@2.4.6: + resolution: {integrity: sha512-P0cY3DSLm4M2boUOCmHDyaID5o6HgWmb21Bvs9p8lLqfJjKBBEHG5Ma5qW5SCmwOYamtWOLf2k+yvt6077zlTg==} + + prosemirror-commands@1.7.2: + resolution: {integrity: sha512-q6Q6szxqdu9Xd6EcdKsqXghu5nQdZTpB4Q9yd04WRc7/jt763e/rT60Owh0L1GYY+T46o5rD+9lEN36dZS43tw==} + + prosemirror-dropcursor@1.8.4: + resolution: {integrity: sha512-VmKxhcA6a+h5oPSYmfF1ZNeQqPbyYaIxqZsKqeYCyTlPtrjUgNaHL3P8vVaO19oqAV0zuaM/axkowZHrB1P3Tg==} + + prosemirror-gapcursor@1.4.1: + resolution: {integrity: sha512-pMdYaEnjNMSwl11yjEGtgTmLkR08m/Vl+Jj443167p9eB3HVQKhYCc4gmHVDsLPODfZfjr/MmirsdyZziXbQKw==} + + prosemirror-history@1.5.2: + resolution: {integrity: sha512-/VCI9OUPT69PzzoKmLJ6xLTkMCXmpt/M6/tOlctR5DjSAinniYgjkw6Ao/Obmq/f5mG5csTQi6a9AWhwFVLSNA==} + + prosemirror-inputrules@1.7.0: + resolution: {integrity: sha512-8osbijqTD9BtFWbtWbrJ47zvwwiC4/+Y993VzCKRYjPw3jK+CixvRlFu7UgT6mExqPnu12WOh+IF9l6921vqhA==} + + prosemirror-keymap@1.2.3: + resolution: {integrity: sha512-4HucRlpiLd1IPQQXNqeo81BGtkY8Ai5smHhKW9jjPKRc2wQIxksg7Hl1tTI2IfT2B/LgX6bfYvXxEpJl7aKYKw==} + + prosemirror-model@1.25.13: + resolution: {integrity: sha512-MlDMWGjYXaYOeCiO17jcybntCOzPnN+97U0809ke2QsgPtxW3n5/sD6ZKyJONUgMw1iP93ohZTjeKjnRJ7L6kQ==} + + prosemirror-schema-list@1.6.1: + resolution: {integrity: sha512-QiL/QjgCWr+3Mhukm48E5d3XCC8lVEIanixGkXbWKUyxCUGy4ntVffFapmMwQ4vxhZw+8i7117W2N6FSyqyWfA==} + + prosemirror-state@1.4.4: + resolution: {integrity: sha512-6jiYHH2CIGbCfnxdHbXZ12gySFY/fz/ulZE333G6bPqIZ4F+TXo9ifiR86nAHpWnfoNjOb3o5ESi7J8Uz1jXHw==} + + prosemirror-tables@1.8.5: + resolution: {integrity: sha512-V/0cDCsHKHe/tfWkeCmthNUcEp1IVO3p6vwN8XtwE9PZQLAZJigbw3QoraAdfJPir4NKJtNvOB8oYGKRl+t0Dw==} + + prosemirror-transform@1.12.7: + resolution: {integrity: sha512-/e87cbxcM5WJOJrL1IrM9gJqO3EK8LdQoPvs+r4ss1lRO5t5QeqkU0SlmDvcitCSDUbm8s/MxbBB6ds4pY6Xlg==} + + prosemirror-view@1.43.0: + resolution: {integrity: sha512-MZOUuhD+Gv7Cp7UlgvyhptUfb920NkLBgymhyhaM8xp+JXQyLhkssS2EXZvMI3ZU3vRoz5z7mRC32udVgNYHqg==} + punycode@2.3.1: resolution: {integrity: sha512-vYt7UD1U9Wg6138shLtLOvdAu+8DsC/ilFtEVHcH+wydcSpNE20AfSOduf6MkRFahL5FY7X1oU7nKVZFtfq8Fg==} engines: {node: '>=6'} @@ -3413,6 +3687,9 @@ packages: engines: {node: ^20.19.0 || >=22.12.0} hasBin: true + rope-sequence@1.3.4: + resolution: {integrity: sha512-UT5EDe2cu2E/6O4igUr5PSFs23nvvukicWHx6GnOPlHAiiYbzNuCRQCuiUdHJQcqKalLKlrYJnjY0ySGsXNQXQ==} + run-applescript@7.1.0: resolution: {integrity: sha512-DPe5pVFaAsinSaV6QjQ6gdiedWDcRCbUuiQfQa2wmWV7+xC9bGulGI8+TdRmoFkAPaBXk8CrAbnlY2ISniJ47Q==} engines: {node: '>=18'} @@ -3438,6 +3715,10 @@ packages: resolution: {integrity: sha512-x/+Cz4YrimQxQccJf5mKEbIa1NzeCRNI5Ecl/ekmlYaampdNLPalVyIcCZNNH3MvmqBugV5TMYZXv0ljslUlaw==} engines: {node: '>= 0.4'} + sanitize-html@2.18.2: + resolution: {integrity: sha512-LTQVNHBeKB5qIae9x2J2Fw68ORnES++8vzYaG7DFT8P4GVCJFeHffHnRUzf5Mrxfx+4GweIvMRqkBPHHodaVNg==} + engines: {node: '>=22.12.0'} + saxes@6.0.0: resolution: {integrity: sha512-xAg7SOnEhrm5zI3puOOKyy1OMcMlIJZYNJY7xLBwSze0UjhPLnWfj2GF2EpT0jmzaJKIWKHLsaSSajf35bcYnA==} engines: {node: '>=v12.22.7'} @@ -3783,6 +4064,11 @@ packages: uri-js@4.4.1: resolution: {integrity: sha512-7rKUyy33Q1yc98pQ1DAmLtwX109F7TIfWlW1Ydo8Wl1ii1SeHieeh0HHfPeL2fMXK6z0s8ecKs9frCuLJvndBg==} + use-sync-external-store@1.7.0: + resolution: {integrity: sha512-6L+EeigHMQhdaIPNIFUKwfWJSwWFQ8gJbJ2DLOs5sDIegTwR9fRxvnM3uciHKjIZhFz+KAv2emhWMRvDmMcY8A==} + peerDependencies: + react: ^16.8.0 || ^17.0.0 || ^18.0.0 || ^19.0.0 + util-deprecate@1.0.2: resolution: {integrity: sha512-EPD5q1uXyFxJpCrLnCc1nHnq3gOa6DZBocAIiI2TaSCA7VCJ1UJDMagCzIkXNsUYfD1daK//LTEQ8xiIbrHtcw==} @@ -3874,6 +4160,9 @@ packages: jsdom: optional: true + w3c-keyname@2.2.8: + resolution: {integrity: sha512-dpojBhNsCNN7T82Tm7k26A6G9ML3NkhDsnw9n/eoxSRlVBB4CEtIQ/KTCLI2Fwf3ataSXRhYFkQi3SlnFwPvPQ==} + w3c-xmlserializer@6.0.0: resolution: {integrity: sha512-4Nsy8K5Tr6SPDH9jhKJOHf7ChDrc1zufZTVSF7x72hwuEXBqxqk9G6cK+K2NRUtB3iELRJqjXb4JPDMBjMTl2Q==} engines: {node: ^22.22.2 || ^24.15.0 || >=26.0.0} @@ -4487,6 +4776,20 @@ snapshots: '@exodus/bytes@1.16.0': {} + '@floating-ui/core@1.8.0': + dependencies: + '@floating-ui/utils': 0.2.12 + optional: true + + '@floating-ui/dom@1.8.0': + dependencies: + '@floating-ui/core': 1.8.0 + '@floating-ui/utils': 0.2.12 + optional: true + + '@floating-ui/utils@0.2.12': + optional: true + '@humanfs/core@0.19.2': dependencies: '@humanfs/types': 0.15.0 @@ -4919,6 +5222,183 @@ snapshots: dependencies: '@testing-library/dom': 10.4.2 + '@tiptap/core@3.34.0(@tiptap/pm@3.34.0)': + dependencies: + '@tiptap/pm': 3.34.0 + + '@tiptap/extension-blockquote@3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))(@tiptap/pm@3.34.0)': + dependencies: + '@tiptap/core': 3.34.0(@tiptap/pm@3.34.0) + '@tiptap/pm': 3.34.0 + + '@tiptap/extension-bold@3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))': + dependencies: + '@tiptap/core': 3.34.0(@tiptap/pm@3.34.0) + + '@tiptap/extension-bubble-menu@3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))(@tiptap/pm@3.34.0)': + dependencies: + '@floating-ui/dom': 1.8.0 + '@tiptap/core': 3.34.0(@tiptap/pm@3.34.0) + '@tiptap/pm': 3.34.0 + optional: true + + '@tiptap/extension-bullet-list@3.34.0(@tiptap/extension-list@3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))(@tiptap/pm@3.34.0))': + dependencies: + '@tiptap/extension-list': 3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))(@tiptap/pm@3.34.0) + + '@tiptap/extension-code-block@3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))(@tiptap/pm@3.34.0)': + dependencies: + '@tiptap/core': 3.34.0(@tiptap/pm@3.34.0) + '@tiptap/pm': 3.34.0 + + '@tiptap/extension-code@3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))': + dependencies: + '@tiptap/core': 3.34.0(@tiptap/pm@3.34.0) + + '@tiptap/extension-document@3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))': + dependencies: + '@tiptap/core': 3.34.0(@tiptap/pm@3.34.0) + + '@tiptap/extension-dropcursor@3.34.0(@tiptap/extensions@3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))(@tiptap/pm@3.34.0))': + dependencies: + '@tiptap/extensions': 3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))(@tiptap/pm@3.34.0) + + '@tiptap/extension-floating-menu@3.34.0(@floating-ui/dom@1.8.0)(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))(@tiptap/pm@3.34.0)': + dependencies: + '@floating-ui/dom': 1.8.0 + '@tiptap/core': 3.34.0(@tiptap/pm@3.34.0) + '@tiptap/pm': 3.34.0 + optional: true + + '@tiptap/extension-gapcursor@3.34.0(@tiptap/extensions@3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))(@tiptap/pm@3.34.0))': + dependencies: + '@tiptap/extensions': 3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))(@tiptap/pm@3.34.0) + + '@tiptap/extension-hard-break@3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))': + dependencies: + '@tiptap/core': 3.34.0(@tiptap/pm@3.34.0) + + '@tiptap/extension-heading@3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))': + dependencies: + '@tiptap/core': 3.34.0(@tiptap/pm@3.34.0) + + '@tiptap/extension-horizontal-rule@3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))(@tiptap/pm@3.34.0)': + dependencies: + '@tiptap/core': 3.34.0(@tiptap/pm@3.34.0) + '@tiptap/pm': 3.34.0 + + '@tiptap/extension-image@3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))': + dependencies: + '@tiptap/core': 3.34.0(@tiptap/pm@3.34.0) + + '@tiptap/extension-italic@3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))': + dependencies: + '@tiptap/core': 3.34.0(@tiptap/pm@3.34.0) + + '@tiptap/extension-link@3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))(@tiptap/pm@3.34.0)': + dependencies: + '@tiptap/core': 3.34.0(@tiptap/pm@3.34.0) + '@tiptap/pm': 3.34.0 + linkifyjs: 4.4.0 + + '@tiptap/extension-list-item@3.34.0(@tiptap/extension-list@3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))(@tiptap/pm@3.34.0))': + dependencies: + '@tiptap/extension-list': 3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))(@tiptap/pm@3.34.0) + + '@tiptap/extension-list-keymap@3.34.0(@tiptap/extension-list@3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))(@tiptap/pm@3.34.0))': + dependencies: + '@tiptap/extension-list': 3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))(@tiptap/pm@3.34.0) + + '@tiptap/extension-list@3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))(@tiptap/pm@3.34.0)': + dependencies: + '@tiptap/core': 3.34.0(@tiptap/pm@3.34.0) + '@tiptap/pm': 3.34.0 + + '@tiptap/extension-ordered-list@3.34.0(@tiptap/extension-list@3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))(@tiptap/pm@3.34.0))': + dependencies: + '@tiptap/extension-list': 3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))(@tiptap/pm@3.34.0) + + '@tiptap/extension-paragraph@3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))': + dependencies: + '@tiptap/core': 3.34.0(@tiptap/pm@3.34.0) + + '@tiptap/extension-strike@3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))': + dependencies: + '@tiptap/core': 3.34.0(@tiptap/pm@3.34.0) + + '@tiptap/extension-text@3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))': + dependencies: + '@tiptap/core': 3.34.0(@tiptap/pm@3.34.0) + + '@tiptap/extension-underline@3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))': + dependencies: + '@tiptap/core': 3.34.0(@tiptap/pm@3.34.0) + + '@tiptap/extensions@3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))(@tiptap/pm@3.34.0)': + dependencies: + '@tiptap/core': 3.34.0(@tiptap/pm@3.34.0) + '@tiptap/pm': 3.34.0 + + '@tiptap/pm@3.34.0': + dependencies: + prosemirror-changeset: 2.4.6 + prosemirror-commands: 1.7.2 + prosemirror-dropcursor: 1.8.4 + prosemirror-gapcursor: 1.4.1 + prosemirror-history: 1.5.2 + prosemirror-inputrules: 1.7.0 + prosemirror-keymap: 1.2.3 + prosemirror-model: 1.25.13 + prosemirror-schema-list: 1.6.1 + prosemirror-state: 1.4.4 + prosemirror-tables: 1.8.5 + prosemirror-transform: 1.12.7 + prosemirror-view: 1.43.0 + + '@tiptap/react@3.34.0(@floating-ui/dom@1.8.0)(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))(@tiptap/pm@3.34.0)(@types/react-dom@19.3.0(@types/react@19.3.0))(@types/react@19.3.0)(react-dom@19.1.0(react@19.1.0))(react@19.1.0)': + dependencies: + '@tiptap/core': 3.34.0(@tiptap/pm@3.34.0) + '@tiptap/pm': 3.34.0 + '@types/react': 19.3.0 + '@types/react-dom': 19.3.0(@types/react@19.3.0) + '@types/use-sync-external-store': 0.0.6 + fast-equals: 5.4.5 + react: 19.1.0 + react-dom: 19.1.0(react@19.1.0) + use-sync-external-store: 1.7.0(react@19.1.0) + optionalDependencies: + '@tiptap/extension-bubble-menu': 3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))(@tiptap/pm@3.34.0) + '@tiptap/extension-floating-menu': 3.34.0(@floating-ui/dom@1.8.0)(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))(@tiptap/pm@3.34.0) + transitivePeerDependencies: + - '@floating-ui/dom' + + '@tiptap/starter-kit@3.34.0': + dependencies: + '@tiptap/core': 3.34.0(@tiptap/pm@3.34.0) + '@tiptap/extension-blockquote': 3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))(@tiptap/pm@3.34.0) + '@tiptap/extension-bold': 3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0)) + '@tiptap/extension-bullet-list': 3.34.0(@tiptap/extension-list@3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))(@tiptap/pm@3.34.0)) + '@tiptap/extension-code': 3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0)) + '@tiptap/extension-code-block': 3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))(@tiptap/pm@3.34.0) + '@tiptap/extension-document': 3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0)) + '@tiptap/extension-dropcursor': 3.34.0(@tiptap/extensions@3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))(@tiptap/pm@3.34.0)) + '@tiptap/extension-gapcursor': 3.34.0(@tiptap/extensions@3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))(@tiptap/pm@3.34.0)) + '@tiptap/extension-hard-break': 3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0)) + '@tiptap/extension-heading': 3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0)) + '@tiptap/extension-horizontal-rule': 3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))(@tiptap/pm@3.34.0) + '@tiptap/extension-italic': 3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0)) + '@tiptap/extension-link': 3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))(@tiptap/pm@3.34.0) + '@tiptap/extension-list': 3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))(@tiptap/pm@3.34.0) + '@tiptap/extension-list-item': 3.34.0(@tiptap/extension-list@3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))(@tiptap/pm@3.34.0)) + '@tiptap/extension-list-keymap': 3.34.0(@tiptap/extension-list@3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))(@tiptap/pm@3.34.0)) + '@tiptap/extension-ordered-list': 3.34.0(@tiptap/extension-list@3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))(@tiptap/pm@3.34.0)) + '@tiptap/extension-paragraph': 3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0)) + '@tiptap/extension-strike': 3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0)) + '@tiptap/extension-text': 3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0)) + '@tiptap/extension-underline': 3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0)) + '@tiptap/extensions': 3.34.0(@tiptap/core@3.34.0(@tiptap/pm@3.34.0))(@tiptap/pm@3.34.0) + '@tiptap/pm': 3.34.0 + '@ts-morph/common@0.27.0': dependencies: fast-glob: 3.3.3 @@ -4970,6 +5450,12 @@ snapshots: dependencies: '@types/node': 20.19.43 + '@types/sanitize-html@2.16.2': + dependencies: + htmlparser2: 12.0.0 + + '@types/use-sync-external-store@0.0.6': {} + '@types/validate-npm-package-name@4.0.2': {} '@typescript-eslint/eslint-plugin@8.73.0(@typescript-eslint/parser@8.73.0(eslint@9.39.5(jiti@2.7.0))(typescript@5.9.3))(eslint@9.39.5(jiti@2.7.0))(typescript@5.9.3)': @@ -5510,6 +5996,8 @@ snapshots: es-errors: 1.3.0 is-data-view: 1.0.2 + dayjs@1.11.23: {} + debounce-fn@4.0.0: dependencies: mimic-fn: 3.1.0 @@ -5567,6 +6055,24 @@ snapshots: dom-accessibility-api@0.6.3: {} + dom-serializer@3.1.1: + dependencies: + domelementtype: 3.0.0 + domhandler: 6.0.1 + entities: 8.1.0 + + domelementtype@3.0.0: {} + + domhandler@6.0.1: + dependencies: + domelementtype: 3.0.0 + + domutils@4.0.2: + dependencies: + dom-serializer: 3.1.1 + domelementtype: 3.0.0 + domhandler: 6.0.1 + dot-prop@6.0.1: dependencies: is-obj: 2.0.0 @@ -5608,6 +6114,8 @@ snapshots: ansi-colors: 4.1.3 strip-ansi: 6.0.1 + entities@8.1.0: {} + entities@9.0.0: {} env-paths@2.2.1: {} @@ -6058,6 +6566,8 @@ snapshots: fast-deep-equal@3.1.3: {} + fast-equals@5.4.5: {} + fast-fifo@1.3.2: {} fast-glob@3.3.1: @@ -6239,6 +6749,13 @@ snapshots: transitivePeerDependencies: - '@noble/hashes' + htmlparser2@12.0.0: + dependencies: + domelementtype: 3.0.0 + domhandler: 6.0.1 + domutils: 4.0.2 + entities: 8.1.0 + human-signals@2.1.0: {} human-signals@8.0.1: {} @@ -6372,6 +6889,8 @@ snapshots: is-plain-obj@4.1.0: {} + is-plain-object@5.1.0: {} + is-potential-custom-element-name@1.0.1: {} is-regex@1.2.1: @@ -6526,6 +7045,10 @@ snapshots: dependencies: language-subtag-registry: 0.3.23 + launder@1.7.2: + dependencies: + dayjs: 1.11.23 + lazystream@1.0.1: dependencies: readable-stream: 2.3.8 @@ -6584,6 +7107,8 @@ snapshots: lightningcss-win32-arm64-msvc: 1.33.0 lightningcss-win32-x64-msvc: 1.33.0 + linkifyjs@4.4.0: {} + locate-path@3.0.0: dependencies: p-locate: 3.0.0 @@ -6810,6 +7335,8 @@ snapshots: string-width: 7.2.0 strip-ansi: 7.2.0 + orderedmap@2.1.1: {} + own-keys@1.0.2: dependencies: call-bound: 1.0.4 @@ -6841,6 +7368,8 @@ snapshots: parse-ms@4.0.0: {} + parse-srcset@1.0.2: {} + parse5-parser-stream@8.1.1: dependencies: parse5: 8.1.1 @@ -6932,6 +7461,80 @@ snapshots: object-assign: 4.1.1 react-is: 16.13.1 + prosemirror-changeset@2.4.6: + dependencies: + prosemirror-transform: 1.12.7 + + prosemirror-commands@1.7.2: + dependencies: + prosemirror-model: 1.25.13 + prosemirror-state: 1.4.4 + prosemirror-transform: 1.12.7 + + prosemirror-dropcursor@1.8.4: + dependencies: + prosemirror-state: 1.4.4 + prosemirror-transform: 1.12.7 + prosemirror-view: 1.43.0 + + prosemirror-gapcursor@1.4.1: + dependencies: + prosemirror-keymap: 1.2.3 + prosemirror-model: 1.25.13 + prosemirror-state: 1.4.4 + prosemirror-view: 1.43.0 + + prosemirror-history@1.5.2: + dependencies: + prosemirror-state: 1.4.4 + prosemirror-transform: 1.12.7 + prosemirror-view: 1.43.0 + rope-sequence: 1.3.4 + + prosemirror-inputrules@1.7.0: + dependencies: + prosemirror-state: 1.4.4 + prosemirror-transform: 1.12.7 + + prosemirror-keymap@1.2.3: + dependencies: + prosemirror-state: 1.4.4 + w3c-keyname: 2.2.8 + + prosemirror-model@1.25.13: + dependencies: + orderedmap: 2.1.1 + + prosemirror-schema-list@1.6.1: + dependencies: + prosemirror-model: 1.25.13 + prosemirror-state: 1.4.4 + prosemirror-transform: 1.12.7 + + prosemirror-state@1.4.4: + dependencies: + prosemirror-model: 1.25.13 + prosemirror-transform: 1.12.7 + prosemirror-view: 1.43.0 + + prosemirror-tables@1.8.5: + dependencies: + prosemirror-keymap: 1.2.3 + prosemirror-model: 1.25.13 + prosemirror-state: 1.4.4 + prosemirror-transform: 1.12.7 + prosemirror-view: 1.43.0 + + prosemirror-transform@1.12.7: + dependencies: + prosemirror-model: 1.25.13 + + prosemirror-view@1.43.0: + dependencies: + prosemirror-model: 1.25.13 + prosemirror-state: 1.4.4 + prosemirror-transform: 1.12.7 + punycode@2.3.1: {} queue-microtask@1.2.3: {} @@ -7046,6 +7649,8 @@ snapshots: '@rolldown/binding-win32-arm64-msvc': 1.2.19 '@rolldown/binding-win32-x64-msvc': 1.2.19 + rope-sequence@1.3.4: {} + run-applescript@7.1.0: {} run-parallel@1.2.0: @@ -7075,6 +7680,15 @@ snapshots: es-errors: 1.3.0 is-regex: 1.2.1 + sanitize-html@2.18.2: + dependencies: + escape-string-regexp: 4.0.0 + htmlparser2: 12.0.0 + is-plain-object: 5.1.0 + launder: 1.7.2 + parse-srcset: 1.0.2 + postcss: 8.5.33 + saxes@6.0.0: dependencies: xmlchars: 2.2.0 @@ -7544,6 +8158,10 @@ snapshots: dependencies: punycode: 2.3.1 + use-sync-external-store@1.7.0(react@19.1.0): + dependencies: + react: 19.1.0 + util-deprecate@1.0.2: {} validate-npm-package-name@7.0.2: {} @@ -7584,6 +8202,8 @@ snapshots: transitivePeerDependencies: - msw + w3c-keyname@2.2.8: {} + w3c-xmlserializer@6.0.0: dependencies: xml-name-validator: 5.0.0 diff --git a/src/app/(app)/training/guides/admin/page.tsx b/src/app/(app)/training/guides/admin/page.tsx index d2cdb96..38819ee 100644 --- a/src/app/(app)/training/guides/admin/page.tsx +++ b/src/app/(app)/training/guides/admin/page.tsx @@ -677,20 +677,31 @@ export default function AdminGuidePage() { the published lessons. - Add a title, one-line summary, and the lesson body. Line breaks are - preserved, so numbered steps stay readable. + Add a title and one-line summary, then build the lesson in the + content editor. Use headings for sections, numbered or bulleted + lists for procedures, and links for related pages. + + + Press the image button to upload a screenshot. Select the image to + align it left, center, or right, choose a width, edit its + description, or move it up and down. You can also drag the image to a + new position in the lesson. Set a sort order to control the list position. Lower numbers appear first. - Publish when ready. Drafts are visible only to admins. + Publish when ready. Drafts are visible only to admins. If you add an + image before the first save, the app creates an unpublished draft so + the file has a lesson to belong to; finish and save normally. - Attach a PDF, image, or document with the file control on the lesson, - then Upload. Volunteers open attachments from the - lesson; admins can remove them. + Attach a PDF manual, Word document, Markdown file, or text file with + the file control beneath the lesson, then press{" "} + Attach. PDFs open in the browser and the other + formats download. Volunteers see documents at the end of the lesson; + admins can remove them. diff --git a/src/app/(app)/training/page.tsx b/src/app/(app)/training/page.tsx index b08fdd1..123957d 100644 --- a/src/app/(app)/training/page.tsx +++ b/src/app/(app)/training/page.tsx @@ -3,6 +3,7 @@ import { auth } from "@/auth/config"; import { hasPermission } from "@/auth/permissions"; import type { SystemRole } from "@/auth/roles"; import { listLessons } from "@/db/training"; +import { trainingBodyToHtml } from "@/lib/rich-text"; import { TrainingPanel } from "@/components/app/training-panel"; import { BookOpenCheck, Download, ShieldCheck, UserRound } from "lucide-react"; @@ -17,7 +18,12 @@ export default async function TrainingPage() { const session = await auth(); const role = (session?.user as { systemRole?: SystemRole } | undefined)?.systemRole; const canEdit = hasPermission(role, "training.author"); - const lessons = await listLessons({ includeUnpublished: canEdit }); + const lessons = (await listLessons({ includeUnpublished: canEdit })).map( + (lesson) => ({ + ...lesson, + body: trainingBodyToHtml(lesson.body), + }), + ); return (
diff --git a/src/app/api/dev/training/lessons/route.ts b/src/app/api/dev/training/lessons/route.ts index babb684..3b1cd02 100644 --- a/src/app/api/dev/training/lessons/route.ts +++ b/src/app/api/dev/training/lessons/route.ts @@ -11,6 +11,7 @@ import { listResourceStoredNames, updateLesson, } from "@/db/training"; +import { trainingBodyToHtml } from "@/lib/rich-text"; import { uploadPath } from "@/lib/uploads"; const JSON_HEADERS = { "content-type": "application/json" }; @@ -61,8 +62,14 @@ export const GET = async () => { ); } const canAuthor = hasPermission(user.systemRole, "training.author"); + const lessons = await listLessons({ includeUnpublished: canAuthor }); return new Response( - JSON.stringify({ lessons: await listLessons({ includeUnpublished: canAuthor }) }), + JSON.stringify({ + lessons: lessons.map((lesson) => ({ + ...lesson, + body: trainingBodyToHtml(lesson.body), + })), + }), { status: 200, headers: JSON_HEADERS }, ); }; @@ -78,7 +85,13 @@ export const POST = async (req: NextRequest) => { headers: JSON_HEADERS, }); } - const lesson = await createLesson(parsed.data); + const lesson = await createLesson({ + ...parsed.data, + body: + parsed.data.body === undefined + ? undefined + : trainingBodyToHtml(parsed.data.body), + }); return new Response(JSON.stringify({ lesson }), { status: 201, headers: JSON_HEADERS, @@ -104,6 +117,9 @@ export const PATCH = async (req: NextRequest) => { }); } const { id, ...patch } = parsed.data; + if (patch.body !== undefined) { + patch.body = trainingBodyToHtml(patch.body); + } const lesson = await updateLesson(id, patch); if (!lesson) { return new Response(JSON.stringify({ error: "unknown lesson" }), { diff --git a/src/app/api/dev/training/resources/route.ts b/src/app/api/dev/training/resources/route.ts index b3b3747..3a05acf 100644 --- a/src/app/api/dev/training/resources/route.ts +++ b/src/app/api/dev/training/resources/route.ts @@ -8,6 +8,7 @@ import { MAX_UPLOAD_BYTES, ensureUploadDir, isAllowedUpload, + resolveUploadMimeType, storedNameFor, uploadPath, uploadSignatureMatches, @@ -65,12 +66,14 @@ export const POST = async (req: NextRequest) => { }); } if (file.size > MAX_UPLOAD_BYTES) { - return new Response(JSON.stringify({ error: "file is larger than 5 MB" }), { - status: 400, - headers: JSON_HEADERS, - }); + return new Response( + JSON.stringify({ + error: `file is larger than ${Math.round(MAX_UPLOAD_BYTES / (1024 * 1024))} MB`, + }), + { status: 400, headers: JSON_HEADERS }, + ); } - const mimeType = file.type || "application/octet-stream"; + const mimeType = resolveUploadMimeType(file.name, file.type); if (!isAllowedUpload(mimeType)) { return new Response( JSON.stringify({ error: `file type not allowed: ${mimeType}` }), diff --git a/src/app/api/training/files/[id]/route.ts b/src/app/api/training/files/[id]/route.ts index 466dd7e..5379f1f 100644 --- a/src/app/api/training/files/[id]/route.ts +++ b/src/app/api/training/files/[id]/route.ts @@ -30,15 +30,18 @@ export const GET = async ( try { const data = await readFile(uploadPath(resource.storedName)); - const safeName = resource.filename.replaceAll('"', ""); + const safeName = resource.filename.replace(/[\r\n"\\]/g, "").trim() || "download"; + const inline = + resource.mimeType.startsWith("image/") || + resource.mimeType === "application/pdf"; return new Response(new Uint8Array(data), { status: 200, headers: { "content-type": resource.mimeType, "content-length": String(data.length), - // Only images render inline; everything else is a download, so an - // uploaded HTML/SVG payload cannot execute in this origin. - "content-disposition": `${resource.mimeType.startsWith("image/") ? "inline" : "attachment"}; filename="${safeName}"; filename*=UTF-8''${encodeURIComponent(resource.filename)}`, + // Images and PDF manuals render in the browser; everything else is a + // download, so an uploaded HTML/SVG payload cannot execute here. + "content-disposition": `${inline ? "inline" : "attachment"}; filename="${safeName}"; filename*=UTF-8''${encodeURIComponent(resource.filename)}`, "cache-control": "private, max-age=0, must-revalidate", "x-content-type-options": "nosniff", }, diff --git a/src/app/globals.css b/src/app/globals.css index 056418c..1023c6a 100644 --- a/src/app/globals.css +++ b/src/app/globals.css @@ -126,3 +126,134 @@ color: var(--primary-foreground); } } + +/* Rendered training lessons and the authoring surface share one typography + scale. The sanitizer permits only these elements, so no prose plugin is + needed for content that came from the editor. */ +.training-prose { + color: var(--foreground); + font-size: 0.875rem; + line-height: 1.7; + overflow-wrap: anywhere; +} + +.training-prose > * + * { + margin-top: 0.75rem; +} + +.training-prose h2 { + margin-top: 1.5rem; + font-size: 1.25rem; + font-weight: 600; + line-height: 1.3; + letter-spacing: -0.01em; +} + +.training-prose h3 { + margin-top: 1.25rem; + font-size: 1.05rem; + font-weight: 600; + line-height: 1.35; +} + +.training-prose h4 { + margin-top: 1rem; + font-size: 0.95rem; + font-weight: 600; +} + +.training-prose ul { + list-style: disc; + padding-left: 1.35rem; +} + +.training-prose ol { + list-style: decimal; + padding-left: 1.35rem; +} + +.training-prose li + li { + margin-top: 0.25rem; +} + +.training-prose li > p { + margin: 0; +} + +.training-prose a { + color: var(--primary); + text-decoration: underline; + text-underline-offset: 2px; +} + +.training-prose strong { + font-weight: 600; +} + +.training-prose blockquote { + border-left: 3px solid var(--primary); + padding-left: 0.85rem; + color: var(--muted-foreground); +} + +.training-prose code { + border-radius: 0.25rem; + background: var(--muted); + padding: 0.1rem 0.3rem; + font-family: var(--font-mono); + font-size: 0.83em; +} + +.training-prose pre { + overflow-x: auto; + border-radius: var(--radius); + background: var(--muted); + padding: 0.75rem; +} + +.training-prose pre code { + background: transparent; + padding: 0; +} + +.training-prose hr { + border-color: var(--border); +} + +.training-prose img { + max-width: 100%; + height: auto; + border-radius: calc(var(--radius) - 2px); + border: 1px solid var(--border); +} + +.training-prose img[data-align="left"] { + display: block; + margin-right: auto; + margin-left: 0; +} + +.training-prose img[data-align="center"] { + display: block; + margin-right: auto; + margin-left: auto; +} + +.training-prose img[data-align="right"] { + display: block; + margin-right: 0; + margin-left: auto; +} + +.training-prose img.ProseMirror-selectednode { + outline: 3px solid var(--ring); + outline-offset: 2px; +} + +.training-prose p.is-editor-empty:first-child::before { + float: left; + height: 0; + color: var(--muted-foreground); + content: attr(data-placeholder); + pointer-events: none; +} diff --git a/src/components/app/training-panel.tsx b/src/components/app/training-panel.tsx index 8925f21..d25dac3 100644 --- a/src/components/app/training-panel.tsx +++ b/src/components/app/training-panel.tsx @@ -1,15 +1,13 @@ "use client"; -import { useState } from "react"; +import { useRef, useState } from "react"; import { useRouter } from "next/navigation"; import type { TrainingLessonRow } from "@/db/training"; import { Badge } from "@/components/ui/badge"; import { Button } from "@/components/ui/button"; import { Input } from "@/components/ui/input"; import { Label } from "@/components/ui/label"; - -const TEXTAREA_CLASS = - "min-h-40 w-full rounded-md border border-input bg-background px-3 py-2 text-sm ring-offset-background focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2"; +import { RichTextEditor } from "@/components/app/training/rich-text-editor"; function formatBytes(bytes: number): string { if (bytes < 1024) return `${bytes} B`; @@ -55,8 +53,9 @@ function UploadControl({ lessonId }: { lessonId: string }) {
setFile(e.target.files?.[0] ?? null)} />
+

+ PDF, Word, text, Markdown, or an image, up to 25 MB. PDFs open in the + browser; Word and text files download. +

{error && (

{error} @@ -100,6 +103,8 @@ export function TrainingPanel({ const [busy, setBusy] = useState(false); const [error, setError] = useState(null); const [message, setMessage] = useState(null); + const [editorSession, setEditorSession] = useState(0); + const creatingDraft = useRef(false); function resetForm() { setEditingId(null); @@ -108,6 +113,7 @@ export function TrainingPanel({ setBody(""); setPublished(true); setSortOrder("0"); + setEditorSession((value) => value + 1); } function edit(lesson: TrainingLessonRow) { @@ -117,10 +123,57 @@ export function TrainingPanel({ setBody(lesson.body); setPublished(lesson.published); setSortOrder(String(lesson.sortOrder)); + setEditorSession((value) => value + 1); setError(null); setMessage(null); } + /** + * Inline images need a lesson row before they can be stored. If the author + * inserts an image before the first save, create an unpublished draft with + * the current form values and keep the editor mounted. + */ + async function ensureLessonId(): Promise { + if (editingId) return editingId; + if (!title.trim()) { + setError("Add a title before inserting images."); + return null; + } + if (creatingDraft.current) return null; + + creatingDraft.current = true; + setError(null); + try { + const res = await fetch("/api/dev/training/lessons", { + method: "POST", + headers: { "content-type": "application/json" }, + body: JSON.stringify({ + title: title.trim(), + summary: summary.trim() || null, + body, + published: false, + sortOrder: Number(sortOrder) || 0, + }), + }); + const data = (await res.json().catch(() => ({}))) as { + error?: string; + lesson?: { id?: string }; + }; + if (!res.ok || !data.lesson?.id) { + setError(data.error ?? "Could not create the lesson draft."); + return null; + } + setEditingId(data.lesson.id); + setMessage("Draft saved so images can be attached. Save when you are finished."); + return data.lesson.id; + } catch { + setError("Network error."); + return null; + } finally { + creatingDraft.current = false; + } + } + async function save(e: React.FormEvent) { e.preventDefault(); setBusy(true); @@ -128,8 +181,8 @@ export function TrainingPanel({ setMessage(null); try { const payload = { - title, - summary: summary || null, + title: title.trim(), + summary: summary.trim() || null, body, published, sortOrder: Number(sortOrder) || 0, @@ -235,13 +288,17 @@ export function TrainingPanel({

-