Read-only API: toggle editing on and off
Control the read-only state of the editor. Toggling is in-place: the same editor instance flips modes, preserving caret position, undo history and scroll — so an edit/view toggle is `readOnly.set(!isEditing)` on ONE instance instead of destroying one editor and constructing another.
Reaching the editor instance
The methods below run on the editor you created with new Blok(). They are available once editor.isReady resolves.
// You already hold the instance returned by the constructor.
const editor = new Blok({ holder: 'editor' });
await editor.isReady;
// Call any API method on it.
editor.caret.setToLastBlock('end');Methods
readOnly.set(state, options?)
Promise<boolean>Set read-only mode to the specified boolean state. The toggle happens in place — no destroy/recreate: block instances, caret position, undo history and scroll are preserved. Pass `{ hideControls: true }` to also hide the hover toolbar, block settings and inline toolbar while read-only is active — the option writes the object form of `config.readOnly`, so the live state reflects it. Returns the new state.
When to use
The preferred way to enter/leave read-only mode — it toggles in place, preserving caret, undo history and scroll. Returns a promise resolving to the new state once applied.
Parameters
| Parameter | Type | Required | Default | Description |
|---|---|---|---|---|
state | boolean | Required | — | Read-only state to set. |
options.hideControls | boolean | — | false | Hide all editor controls (hover toolbar, block settings popover, inline toolbar) while read-only is active. |
// The edit/view toggle: ONE instance, flipped in place —
// caret, undo history and scroll survive the switch
await editor.readOnly.set(!isEditing);
// Enable read-only and hide all controls
// (hover toolbar, block settings, inline toolbar)
await editor.readOnly.set(true, { hideControls: true });
// Check state
console.log(editor.readOnly.isEnabled); // true or false
console.log(editor.readOnly.togglesInPlace); // truereadOnly.toggle(state?)
Promise<boolean>DeprecatedToggle read-only state. Without parameter, toggles current state. With parameter, sets to specified state.
Use instead: readOnly.set
When to use
Kept for compatibility; without a parameter it flips the current state.
// Toggle current state
const isReadOnly = await editor.readOnly.toggle();
// Enable read-only
await editor.readOnly.toggle(true);
// Disable read-only
await editor.readOnly.toggle(false);Properties
| Property | Type | Description |
|---|---|---|
isEnabled | boolean | Control the read-only state of the editor. Toggling is in-place: the same editor instance flips modes, preserving caret position, undo history and scroll — so an edit/view toggle is `readOnly.set(!isEditing)` on ONE instance instead of destroying one editor and constructing another. |
togglesInPlace | true | Control the read-only state of the editor. Toggling is in-place: the same editor instance flips modes, preserving caret position, undo history and scroll — so an edit/view toggle is `readOnly.set(!isEditing)` on ONE instance instead of destroying one editor and constructing another. |
// The edit/view toggle: one instance, one call.
// Caret, undo history and scroll survive the switch —
// no destroy-and-recreate.
async function setEditing(isEditing: boolean) {
await editor.readOnly.set(!isEditing);
}
// Framework adapters do this for you: change the readOnly
// prop (React/Vue) or input (Angular) and the adapter calls
// readOnly.set on the existing instance — same editor identity.