# Project Status (Writer)

Updated: 2026-01-29

## Where we are
- Custom canvas-based editor is fully functional (pagination, caret/selection, formatting, headings, font size, alignment, ruler, TOC, search/replace, status bar, export, permissions, comments).
- Editor UI: fixed menubar + toolbar + ruler, sticky TOC overlay, status bar, search panel, comments panel in top-right.
- Theme switching triggers canvas redraw.

## Core Features Implemented
- Canvas editor with:
  - Cursor, selection, copy/cut/paste, undo/redo, CTRL+F/H search & replace.
  - Formatting spans (bold/italic/underline/strike), paragraph types (p/h1/h2), alignments, font size.
  - Ruler indentation (left/first line).
  - Pagination and page numbers.
  - Status bar (chars + author sheets for document and selection).
- Table of contents (H1/H2) with click-to-scroll.
- Comments:
  - Add comment from selection via "+" button near page.
  - Comment cards anchored to text, highlight attached range.
  - Resolve/reject actions.
  - Comments panel (top menu) with filters: Unresolved / Resolved, click to scroll.
- Export:
  - TXT, MD, DOCX, PDF. Formatting/indent/align preserved for DOCX/PDF.
  - PDF fixed for Cyrillic using DejaVu Serif.
- Permissions:
  - Share by email; pending permissions attached on registration.
  - Viewer/Commenter/Editor roles.

## Routes / Controllers
- `GET /documents/{document}` -> EditorController@index
- `GET /documents/new` -> EditorController@create
- `DELETE /documents/{document}` -> EditorController@destroy
- `GET /documents/{document}/export/{format}` -> EditorController@export
- `POST /documents/{document}/comments` -> DocumentCommentController@store
- `PATCH /documents/{document}/comments/{comment}` -> DocumentCommentController@update

## Key Files
- Editor UI: `resources/views/pages/editor.blade.php`
- Menubar: `resources/views/livewire/documents/menubar.blade.php`
- Canvas editor core: `resources/js/app.js`
- Styles: `resources/scss/_components.scss`
- Export: `app/Services/DocumentExporter.php`
- Permissions UI: `app/Livewire/Documents/Permissions.php`
- Comments controller: `app/Http/Controllers/DocumentCommentController.php`
- Policies: `app/Policies/DocumentPolicy.php`

## Data / Models
- Document data: `documents` table (body_md, caret_offset, indent_left, indent_first, format_spans, paragraph_alignments, paragraph_types, font_size).
- Permissions: `document_permissions` with optional `invite_email` for pending users.
- Comments: `document_comments` with start/end offsets, body, status (open/resolved/rejected).

## Recent Fixes
- Read-only mode: no Livewire saves when user lacks edit rights.
- Search/replace: works with panel, highlights current match only.
- Menu: desktop-style File/Edit/Help with actions.
- Z-index ordering: menu above TOC.

## Known TODO / Next
- Optional: comment threads (replies).
- Optional: comment archive view (rejected/hidden).
- Optional: export with comments.
- Optional: share links / notifications.

## Setup Notes
- After package changes: `composer update` (includes dompdf/phpword/doctrine/dbal).
- Rebuild frontend after JS/CSS changes: `npm run dev`.

