@stesura/core/guards
Transaction guards: attr bounds, the view/review mode gate, nested-table and inline-image checks, and load-time healing.
Numeric attr bounds are enforced by one transaction modifier, guardTransactionModifier. Schema validate can’t do it: it can only throw, and only runs on fromJSON/createChecked, not on .create(), DOM parsing or AttrStep.apply. Per-command clamps would miss paste and import. Coverage by source:
- Local transactions: the modifier runs in dispatch, before track changes, so the clamped steps are what collab sends.
- Remote and history transactions: skipped. They were clamped at their origin, and rewriting a remote op breaks convergence.
- Doc load: snapshots load verbatim. Dispatch
createNormalizeTransaction(state)once after creating the state; it returnsnullfor a clean doc. parseDOM: its own normalizers use the same bounds.
Functions
applyInlineImageCorrections
Parameters:| Name | Type | Default |
|---|---|---|
tr | Transaction |
applyNestedTableCorrections
Parameters:| Name | Type | Default |
|---|---|---|
tr | Transaction |
clampAspectRatio
Parameters:| Name | Type | Default |
|---|---|---|
value | unknown |
clampAttrValue
Parameters:| Name | Type | Default |
|---|---|---|
nodeTypeName | string | |
attrName | string | |
value | unknown | |
allAttrs | AttrsLike |
clampBorderSide
Parameters:| Name | Type | Default |
|---|---|---|
side | unknown |
clampFontSize
Parameters:| Name | Type | Default |
|---|---|---|
value | unknown |
clampImageDim
Parameters:| Name | Type | Default |
|---|---|---|
value | unknown |
clampLineNumbers
Parameters:| Name | Type | Default |
|---|---|---|
attrs | LineNumbersAttrs |
clampMarkAttrs
Parameters:| Name | Type | Default |
|---|---|---|
markTypeName | string | |
attrs | AttrsLike |
clampMarks
Parameters:| Name | Type | Default |
|---|---|---|
marks | readonly Mark[] |
clampNodeAttrs
Parameters:| Name | Type | Default |
|---|---|---|
nodeTypeName | string | |
attrs | AttrsLike |
clampStep
Parameters:| Name | Type | Default |
|---|---|---|
step | Step | |
docBefore | Node |
collectContextualCorrections
Parameters:| Name | Type | Default |
|---|---|---|
doc | Node | |
schema | Schema<any, any> | |
ranges | GuardRange[] |
commitStepsContainInlineSrc
Parameters:| Name | Type | Default |
|---|---|---|
schema | Schema<any, any> | |
stepsJSON | unknown[] |
createNormalizeTransaction
Parameters:| Name | Type | Default |
|---|---|---|
state | EditorState | |
options | { removeInlineImages?: boolean; } |
fragmentContainsInlineSrc
Parameters:| Name | Type | Default |
|---|---|---|
fragment | Fragment |
guardTransactionModifier
Parameters:| Name | Type | Default |
|---|---|---|
state | EditorState | |
tr | Transaction |
isBlockedByMode
Parameters:| Name | Type | Default |
|---|---|---|
state | EditorState | |
tr | Transaction |
isForcedTrackChanges
Parameters:| Name | Type | Default |
|---|---|---|
state | EditorState | |
tr | Transaction |
isInForbiddenTableAncestor
Parameters:| Name | Type | Default |
|---|---|---|
$pos | ResolvedPos |
maxMarginFor
Parameters:| Name | Type | Default |
|---|---|---|
pageExtent | number | |
oppositeMargin | number |
nodeContainsTable
Parameters:| Name | Type | Default |
|---|---|---|
node | Node |
privilegedDispatch
Parameters:| Name | Type | Default |
|---|---|---|
view | EditorView |
stepContainsInlineSrc
Parameters:| Name | Type | Default |
|---|---|---|
step | Step |
Bounds
| Constant | Value | Applies to |
|---|---|---|
ASPECT_RATIO_MIN / ASPECT_RATIO_MAX | 0.1 / 10 | Image aspect ratio |
BORDER_SPACE_MIN / BORDER_SPACE_MAX | 0 / 31 pt | Border padding (Word’s maximum) |
BORDER_WIDTH_MIN / BORDER_WIDTH_MAX | 0.5 / 6 px | Border width |
COLSPAN_MAX / ROWSPAN_MAX | 1000 / 65534 | Table cell spans (HTML’s own caps) |
COLWIDTH_MIN | 25 px | Table column width |
FONT_SIZE_MIN / FONT_SIZE_MAX | 1 / 144 pt | Font size |
IMAGE_DIM_MIN / IMAGE_DIM_MAX | 8 / 5000 px | Image width and height |
MAX_ABS_LENGTH | 10000 px | Any length-like value (indents, margins, offsets) |
NUMBERING_LEVEL_MIN / NUMBERING_LEVEL_MAX | 1 / 9 | List level (1-based; OOXML is 0-based) |
PAGE_SIZE_MIN | 96 px | Page width and height |
SPACING_MIN / SPACING_MAX | 0 / 600 px | Paragraph space before/after |
TAB_STOP_MIN / TAB_STOP_MAX | 0 / 480 px | Numbering tab stop |
Types
AttrCorrection
| Name | Type | Default |
|---|---|---|
pos | number | |
attr | string | |
value | unknown |
GuardRange
| Name | Type | Default |
|---|---|---|
from | number | |
to | number |
Last updated on