Editor state, commands and history
The command model, patches, validation and undo history behind every edit. How it works in the DocStudio designer interface.
Every edit in the designer goes through one model, so undo, validation and the JSON view always agree.
State
The editor holds an immutable state: the document (JSON), the validated template, the diagnostics, an index of nodes, the selection, undo and redo availability and a dirty flag. The state is replaced, never modified.
Commands
All edits are commands:
| Command | Effect |
|---|---|
insert, insertType |
Add a node or a new node of a type to a container |
delete, duplicate |
Remove or copy nodes |
move |
Move or reorder a node, also between containers and regions |
set |
Set a value at a path of a node or of the template |
wrap, unwrap |
Put nodes into a new container or remove a container |
replaceDocument |
Replace the whole document (the JSON tab) |
batch |
Several commands as one step |
Patches and validation
A command is planned as a list of JSON Patch operations (RFC 6902 style) together with the inverse operations. The patch is applied to a copy of the document and the result is validated. If the result is not a valid template, the command is refused with diagnostics and the state does not change. This is why the designer cannot produce an invalid template.
History
| Limit | Value |
|---|---|
| Undo history depth | 200 steps |
| Operations per command | 50,000 |
| Template nodes | 5,000 by default |
| Coalescing window | 500 ms |
Typing in one field and holding an arrow key are coalesced into one step when they use the same key and target within the window. A drag is one step.
Dirty flag
The editor is dirty after an edit and clean after the host calls markSaved. The toolbar shows Unsaved while it is dirty.
Headless use
The editor works without React. See Designer reference and the headless editor example.