Readonly mode
Render a document without editing, what still works in a readonly view, and how to switch between readonly and editable.
A readonly view renders the same block tree as an editable one, with the same plugins, snippets and styles, but refuses every edit. Use it to display documents, to lock an editor while saving, or to show a document to people without write access.
<script lang="ts">
import { Edytor } from 'edytor';
let { value } = $props();
</script>
<Edytor readonly {value} />
There is no separate renderer: readonly is the editable editor with contenteditable="false" on its root and aria-readonly="true". It is also the way to server-render a document.
What still works
- Selecting text with the mouse. The selection is tracked as in an editable view:
edytor.selection.valueandonSelectionChangefollow it. - Copying. Mod+C writes the same clipboard formats as an editable view (Edytor’s own format, HTML and plain text). See Clipboard.
- Keys the browser handles: arrows, Home/End, PageUp/PageDown, Escape, Mod+A, Mod+C and Mod+F (the browser’s find, also with the find plugin listed) keep their native behavior.
- Live updates. The view re-renders when the document changes: collaborators’ edits, and the document operations your code runs.
- Controls inside blocks (links, buttons and inputs a snippet renders) stay interactive.
What is turned off
- Typing, Backspace, Delete, Enter and Tab are blocked.
- Hotkeys don’t run, neither the built-in ones (undo, select-all ladder, nesting) nor the plugins’ (Mod+B, …).
- Cut, paste and drop are ignored.
- Every operation of the view is refused: after a call,
edytor.dispatcher.last.statusis'refused'and the call answersrefused. That includes data writes (block.data.title = …, refused at once without throwing, andedytor.patchData(…)),edytor.setBlock(…),edytor.clear(),historyUndo()andhistoryRedo(), so a control’s document write needs no readonly check. The refusal covers only the write: a control that does something else first, such as uploading a file or calling your server, must checkedytor.readonlyitself. The image plugin shows a passive placeholder in a readonly view for this reason.canMoveanswersfalse. - Block handles (the
+and the grip) are hidden and dragging is disabled, so the block menu cannot open. The slash menu and the selection toolbar stay closed, and to-do checkboxes do not toggle.
The bare document’s operations (edytor.document.insertText(…), …) are raw writes and are not affected by the view’s readonly: code can still change the document, and every view shows the change.
When a document that collaborators emptied is shown, a readonly view displays an empty paragraph without writing one.
A live viewer
A readonly view connects to its room like an editable one: give it room and server (or sync) and it loads the room’s content, then shows every collaborator’s edit as it arrives. readonly refuses this view’s edits, never the room’s updates.
<script lang="ts">
import { Edytor } from 'edytor';
let { documentId, token } = $props();
</script>
<Edytor readonly server="wss://rooms.example.com/rooms" room={documentId} params={{ token }} />
It waits for its room as an editable view does: until the room answers (or its readiness bound passes) it renders nothing, or the snapshot you pass, and the server render shows only that snapshot. value is the seed of a room that has nothing yet, written by whichever view decides first. To keep a user from writing whatever view they open, let the server decide: an authorize that returns readOnly: true gives the socket updates only.
Switching at runtime
readonly is one of the few props that follow updates. Toggling it keeps the same instance, document and selection:
<script lang="ts">
import { Edytor } from 'edytor';
let editing = $state(false);
</script>
<button onclick={() => (editing = !editing)}>{editing ? 'Done' : 'Edit'}</button>
<Edytor readonly={!editing} />
edytor.readonly reflects the prop; change the prop rather than the instance field. Block handles appear and disappear with it.
The connection does not change with it: a view created readonly attaches its sync (or the one its room and server create) when it mounts, and switching it to editable and back keeps that same connection, so its edits reach the room as soon as it is editable.
Read-only documents
Separately from the view’s readonly, a document can be read-only: for example when it received content it could not admit. Commands then refuse in every view of it. document.writable tells you which state it is in; see Collaboration.