Skip to main content

Read-only viewer

Display a board for viewing without allowing edits by using a command guard.

Mutations blocked — try dragging or deleting.
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

ts
const engine = createBoardEngine()
engine.loadDocument(JSON.parse(savedBoardJson), { mode: 'replace' })

Block mutation commands

ts
const blocked = new Set([
  'beginNodeDrag',
  'beginResize',
  'beginTextEdit',
  'createNode',
  'updateNode',
  'deleteSelected',
])

const stopReadOnly = engine.addCommandGuard(({ name }) =>
  blocked.has(name) ? 'Board is read-only.' : true,
)

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.