Read-only viewer
Display a board for viewing without allowing edits by using a command guard.
Read-only
Blocked attempts
0
What happens
This example uses addCommandGuard to register a command guard. The board still renders and the camera still moves, but the edit commands used by the demo exit early when read-only mode is enabled.
The code
Load the scene
const engine = createBoardEngine()
engine.loadDocument(JSON.parse(savedBoardJson), { mode: 'replace' })Block mutation commands
const blocked = new Set([
'beginNodeDrag',
'beginResize',
'beginTextEdit',
'createNode',
'updateNode',
'deleteSelected',
])
const stopReadOnly = engine.addCommandGuard(({ name }) =>
blocked.has(name) ? 'Board is read-only.' : true,
)Remove the guard to restore editing
stopReadOnly()Try these things
- Leave the demo in read-only mode and try dragging or deleting a node.
- Toggle back to edit mode and repeat the same action.
- Watch the blocked command counter increment when a guard rejects a mutation.