@stesura/core/guards
Transaction guards keep a document within what the editor supports: numeric attr bounds, table nesting depth, where text boxes may live, unique ids, and the view/review mode gate. The editor runs them itself, so most of the module is internal. What’s public here is for a custom transport or dispatch pipeline.
Local transactions are clamped in dispatch, before track changes, so the clamped steps are what collab sends. Remote and history transactions are skipped: they were clamped at their origin. Local mounts heal the doc before mounting it (prepareDocForLoad), so the load costs no steps. Collab snapshots load verbatim: the server heals what enters it (createRoomDoc, applyServerEdit), and createNormalizeTransaction heals anything left as an ordinary edit, returning null for a clean doc.
Functions
applyInlineImageCorrections
Heals docs that predate the commit gate by deleting every node whose src
is a data: URI, back to front so positions stay valid. Convergent: racing
clients produce identical steps, and a clean doc produces none.
| Name | Type | Default |
|---|---|---|
tr | Transaction |
commitStepsContainInlineSrc
Authority-side commit gate: true if any serialized step would introduce a data: src. Malformed steps return false; the authority’s own deserialization rejects those.
| Name | Type | Default |
|---|---|---|
schema | Schema<any, any> | |
stepsJSON | unknown[] |
createNormalizeTransaction
A transaction healing the loaded doc: flattens tables past the depth cap or in note bodies, unwraps text boxes where they are banned, optionally strips inline images, clamps out-of-bounds attrs and fixes ids. Null when the doc is clean (the common case).
Dispatch once after state creation. It never rewrites the snapshot in place: in collab the result is an ordinary op, and once it lands other clients produce zero steps.
| Name | Type | Default |
|---|---|---|
state | EditorState | |
options | { removeInlineImages?: boolean; } |
fragmentContainsInlineSrc
True if any node in the fragment carries a data: URI in its src attr.
| Name | Type | Default |
|---|---|---|
fragment | Fragment |
isBlockedByMode
Read-only backstop, checked first in the dispatch updater (before the guard
and track-changes modifiers, so a refused edit is never recorded as a
suggestion). In dispatch rather than filterTransaction so plugin-appended
maintenance transactions (TOC rebuild, normalize healing) keep working in
view mode: the updater only sees root transactions.
Passes in "view" mode: non-doc-changing transactions, systemEdit ones
(see privilegedDispatch) and remote collab changes, so a read-only
client stays converged. Undo/redo is a local mutation and is blocked.
| Name | Type | Default |
|---|---|---|
state | EditorState | |
tr | Transaction |
isForcedTrackChanges
"review" mode records every local edit as a suggestion, whatever the
track-changes toggle says. Read at dispatch time so a mode flip applies to
the next transaction. Remote collab changes are excluded: they were tracked
at their origin.
| Name | Type | Default |
|---|---|---|
state | EditorState | |
tr | Transaction |
isTrackingActive
Whether a local edit dispatched now will be tracked: the toggle is on, or
"review" mode forces it. Commands that skip work while tracking (e.g.
width redistribution) must read this, not the toggle alone.
| Name | Type | Default |
|---|---|---|
state | EditorState |
stepContainsInlineSrc
True if the step could introduce a data: src: in inserted content, a
direct src AttrStep, or any other step whose JSON embeds one.
| Name | Type | Default |
|---|---|---|
step | Step |