defuss-shadcn / Application / Scaffolds / scaffold-document-editor
Document Editor
A Google-Docs-style editor as a clickdummy - "Margin". Four Markdown documents open in the Editor.js block editor, the Toolbar formats the selection and the current block, and the Document Comments column on the right scrolls on its own: select text and press Comment to open a thread on it, click a highlight to find its card, click a card to find its text, walk the comments with the up and down buttons, reply in place, follow a quote to another span. A Menubar carries the commands: File opens a Markdown file or its annotations (or drop the files on the editor) - a comments model, or the JSON an editorial review pipeline wrote for that Markdown, which becomes comments anchored to the quoted text - saves the document in this browser, saves it as a Markdown file and exports its comments as JSON. Comments, replies and replies still being typed are kept as they happen, so a reload loses none of them. Every control is a shipped component. Part of the Application Scaffolds.
On this page (2)
§Document editor
The whole editor in one source. The documents are Markdown in a JSON script; opening one renders it in Editor.js and loads its comments; switching keeps the edits. Comments are a JSON model - comment on a selection with the toolbar's Comment button, reply under a card, follow a quote. File > Open loads a Markdown file, then its annotations - or drop them on the editor; Save keeps the document in this browser (this preview has no storage - full screen keeps it across reloads), Save as and Export download it as Markdown and its comments as JSON; comments, replies and open reply drafts are kept as they happen. Importprüfung shows a review pipeline's run as comments: findings by severity, summary entries linked to the entries they refer to, Findings / Summary layers in the status bar.
§How it works
A page, not a component: it composes the library and keeps its own glue small - the menu commands, open and save a document, comment on a selection, a status bar, the narrow layout.
- Documents - Markdown. The open one is the Editor.js element's source; the others wait in a JSON script and are rendered with
setMarkdownwhen their Sidebar link is clicked. Switching keeps the edits: the current document is read back as Markdown first. Block ids are deterministic (b1,b2, ...), so a comment can name the block its text lives in. - Formatting - the Toolbar is bound with
data-toolbar; every button carries adata-editor-command, and the toggles follow the caret (bold, italic, the current block's type). A toolbar button never takes the selection away. - Comments - the Document Comments column is a JSON model per document: author, colour, the anchored span (block + text), a Markdown body, quotes to other spans, replies. Select text and press Comment (or ⌘ K): a Dialog shows the quote, takes the text and a colour from a Toggle Group, and
docComments.add()places the mark and the card. Marks are re-placed after every editor change. - Navigation - click a mark to find its card, the card's excerpt to find its mark, the up and down buttons to walk the comments, a quote to flash another span. Reply opens the Textarea composer under the card.
- Menus - a Menubar of Dropdown Menus: File (New, Open ▸ Markdown / Comment annotations, Save, Save as, Export ▸ Comment annotations, Share), Edit (Comment, previous / next comment), Insert and Format (the toolbar's commands through
editorjs.command()), View (the document list, the annotation layers). A menu takes the focus, so the glue remembers the editor's last selection and puts it back before a command runs. - Open - File > Open > Markdown clicks a hidden file input inside the menu's click, so the browser opens its picker; the Markdown becomes a document in the list. File > Open > Comment annotations puts a file's annotations on the open document. Files dragged over the editor show a drop target whose label says what a drop does; a dropped Markdown file opens like File > Open, a JSON file puts its annotations on the open document, and both dropped together open the document annotated. The glue listens in the capture phase on the app, so Editor.js never takes a dropped file as pasted text. Annotations are a Document Comments model, or the output of an editorial review pipeline: a summary of entries (
summary.eintraege: id, kind, content, verbatim terms, evidence quotes, references to other entries) and the findings of its review (custom: quote, findings with rule, severity, confidence, action and comment, evidence). The pipeline quotes the Markdown source -{ seite, zitat, vorkommen }: the part of the document, the exact text, its occurrence there - so the glue rebuilds the parts (the Markdown split at headings, as many as the run'ssteps) andeditorjs.locate()turns each quote into the block and the rendered text a comment anchors to:# Einschränkunganchors Einschränkung in the heading block. Findings are coloured by severity; a summary entry links the entries it refers to (a link selects that comment); evidence quotes flash their span. The Findings / Summary toggles in the status bar hide a layer. A quote that is not in the document leaves its card without a mark, and the card says so; a toast counts what found its text and names the file the annotations were made for when it differs. Importprüfung is such a run, built in. - Saving - two persisted stores (
df$.store.persisted) keep the work in this browser. Save (⌘ S) stores the open document: title, Markdown, comments. A document opened from a file or made new is stored at once, and comments and replies are stored the moment they are added - so a reply never waits for Save. Every open reply composer is a draft: the column reports its text on each keystroke (doc-comments-draft), the glue stores it per document, andsetDrafts()opens the composers again after a reload. The status bar says Unsaved changes until the document is saved. In this preview the browser refuses storage, the stores keep everything for the visit and Save says so; the full-screen page keeps it across reloads. - Save as and Export - Save as writes the Markdown (⇧ ⌘ S), Export the comments model with every comment, the replies included, and the annotation layers - File > Open > Comment annotations reads it back. Where the browser has a Save dialog (the File System Access API) it opens; elsewhere, and in this sandboxed preview, the file is a download.
- Toasts - a Toast confirms a save, a copied link and a new comment, and counts the annotations an opened file anchored.
- Words and the saved state - after
editorjs-changethe glue reads the Markdown back, debounced: it counts the words and compares the text with what was opened or last saved. - Narrow - the document list is open or closed (no icon rail) and sits in the flow, so the page narrows instead of being covered; below 56rem the comment column becomes an overlay toggled from the header.
- Routing - defuss-dom-router in hash mode: every document is
#/docs/:id- the list links are router links, a new document's address follows it, and a deep link opens its document once the editor is ready;#/opens the one open last time. Inside the docs preview the same routes match the frame's hash. See Client-side Routing. - Translation - defuss-i18n: the language switch beside Share translates the editor's frame - the document list, the menus, the toolbar, the dialogs and every label - between English and German. The documents, the comments and the toasts stay as written. See Translation.
- Full screen - app-document-editor.html is generated from this page's example at build time and loads only this scaffold's bundle; the Editor.js builds come from jsDelivr, pinned.
Comments, ideas or improvements? Edit this page's source on GitHub