# Advanced events

> Events on document for plugin authors, custom editors, and code that sits inside the save, sync, and snapshot lifecycle.

Source: https://clayjs.com/docs/advanced/events/

For plugin authors, custom editors, and code that hooks into snapshots or sync lanes; for the everyday events, see [Events](https://clayjs.com/docs/events/).

## Events

| Event (on document) | Fires when | detail |
| --- | --- | --- |
| `clay:mutation-ready` | the mutation hub is installed, and `clay.Mutation` answers from inside the listener. Fires before `clay:ready` (mostly for plugins) | `{Mutation}` |
| `clay:presence-quiesce` | live sync paused presence while the page changes mode, so this tab publishes no caret or target (mostly for plugins) | none |
| `clay:presence-resume` | presence is allowed again, because the mode change finished or the live sync session ended (mostly for plugins) | none |
| `clay:blockeditor-adopted` | an incoming file was merged with the block editor state and applied to the article (blockeditor plugin) | `{edited, created, deleted, moved}`, plus `displaced`, `conflicts` or `copy` when that adoption carried them |
| `clay:blockeditor-save-state` | the block editor's save state changed (blockeditor plugin). The indicator plugin reads it | `{state, code, message}`, with `code` null and `message` empty when there is nothing to say. `state` is one of `pending`, `journaled`, `acknowledged`, `checkpointed`, `retrying`, `blocked`, `unavailable`, `saved` or `error` |
| `clay:snapshot-ready` | a snapshot has been cloned, before any stripping. Read `detail.documentElement`; do not change it. It is also where both change-detection baselines come from, and the change checks do not fire this event, so an edit made here is saved but never compared and the page reads dirty forever. Use `clay.addDocumentTransform(fn)` to change what gets saved. This clone is not the bytes a save sends: hooks, transforms and final serialization still run after it. | `{documentElement}` |
| `clay:conflict-store-changed` | conflicts were removed from the conflict store, so a notice showing one should reread them (mostly for plugins) | none |
| `clay:sync-resumed` | one lane stopped holding incoming frames. The other lane may still be holding, so this tab is only back in step once neither is | `{lane, el}`, with `lane` either `live` for a peer frame or `external` for a disk frame, and `el` null |
| `clay:drafts-blockeditor-external` | another tab of this visitor's draft stored a block editor page or live store unit in the draft store, so the page editor merges it into its own document (visitor-drafts plugin) | `{live, adopted}`, where `live` maps store names to state values and `adopted()` marks the unit adopted once merged |
| `clay:drafts-blockeditor-listening` | the page editor attached its listener for external visitor drafts in draft mode, prompting visitor-drafts to deliver any state another tab stored earlier (blockeditor plugin) | none |
| `clay:saves-soon` | a persistent live store recorded a local change waiting for its checkpoint save, or a checkpoint save or room landing moved the file state, waking the host unsaved-work check (live plugin) | none |
| `clay:undo-recording` | `clay.undo.setRecording(mode)` changed the page's undo recording mode (undo plugin, mostly for plugins) | `{mode}`, with `mode` `"automatic"` or `"commands"` (or `null` if unset) |
| `clay:undo-session` | the undo plugin started or disposed its edit-mode history session across a mode change (undo plugin, mostly for plugins) | `{started, pageHistory}`, both booleans (`true` while the edit session owns page history, `false` once disposed) |
| `clay:undo-skipped` | an undo or redo step could no longer replay against the document and the page session skipped past it to the next step in that direction instead of blocking the keypress (undo plugin) | `{entryId, label, direction, code}` |
| `sap:plugin-failed` | Sap failed to load a required plugin after its retry attempts; apps still asking for it report `E52`, and Sap retries on the browser's `online` event (sap plugin) | `{plugin, error}` |

### Save events and recovery

`etag` and `captureId` are additive fields, so a listener that reads `msg`, `msgType` and `timestamp` is unaffected. `clay:save-saved` carries both: `etag` is the version stamp the host accepted, or `null` when it named none, and `captureId` names the exact bytes this save captured before it went out. `clay:save-error`, `clay:save-offline` and `clay:save-conflict` carry `captureId` too, and a conflict's `etag` is the stamp it was refused against.

That id is what a local recovery copy is judged against: a revision is cleared only when that capture's own bytes contain it, so a save that was skipped, refused, conflicted or unknown clears nothing, and neither does a later save that never held the writing. `clay:snapshot-ready` cannot answer that question, because it fires on a clone taken before before-save hooks, document transforms and final serialization. See [recovery](https://clayjs.com/docs/recovery/).

### Skipped undo steps

The page undo session runs with `refused: "skip"`, so pressing Undo or Redo when the top step can no longer replay skips that step and replays the next step in that direction instead of stopping on the refusal. Each skipped step fires `clay:undo-skipped` with `{entryId, label, direction, code}`, using the same `direction` (`"undo"` or `"redo"`) and refusal `code` values as `clay:undo-refused`. Unless the skipped entry stood for a block editor step, ClayJS still writes its description to the undo recovery store behind the scenes and fires `clay:undo-kept` once settled; see [Advanced undo](https://clayjs.com/docs/advanced/undo/#recovery).
