Skip to main content
Available since v0.10.0
Field Annotation use is not recommended because of its limited support for advanced document content (e.g., tables, advanced styling). Use the more versatile Structured Content Fields.

Configuration

handleDropOutside
boolean
default:"false"
Handle drops outside editor viewport
annotationClass
string
default:"'annotation'"
CSS class for field styling
borderColor
string
default:"'#b015b3'"
Default field border color

Usage

Basic Setup:
Form Template Workflow:

Commands

findFieldAnnotations

Find field annotations matching a predicate function
Added in v0.10.3
Parameters:
predicate
function
required
Function to test each annotation node
state
EditorState
required
ProseMirror editor state
Returns:
result
Array
Matching field annotations

findFieldAnnotationsBetween

Find all field annotations between two positions
Parameters:
from
number
required
Start position
to
number
required
End position
doc
Node
required
ProseMirror document node
Returns:
result
Array
Field annotations in range

findFieldAnnotationsByFieldId

Find field annotations by field ID(s)
Parameters:
fieldIdOrArray
string | Array.<string>
required
Single field ID or array of field IDs
state
EditorState
required
ProseMirror editor state
Returns:
result
Array
Matching field annotations

findFirstFieldAnnotationByFieldId

Find the first field annotation matching a field ID
Added in v0.10.2
Parameters:
fieldId
string
required
Field ID to search for
state
EditorState
required
ProseMirror editor state
Returns:
result
Object | null
First matching annotation or null

findHeaderFooterAnnotationsByFieldId

Find field annotations in headers and footers by field ID or array of field IDs.
Added in v0.11.2
Parameters:
fieldIdOrArray
string | Array.<string>
required
The field ID or array of field IDs
editor
Editor
required
The main editor instance
activeSectionEditor
Editor
required
The currently active section editor
Returns:
result
Array
Array of field annotations with their positions

getAllFieldAnnotations

Get all field annotations in the document
Parameters:
state
EditorState
required
ProseMirror editor state
Returns:
result
Array
Array of field annotations with positions

getAllFieldAnnotationsWithRect

Get all field annotations with their bounding rectangles
Added in v0.11.0
Parameters:
view
EditorView
required
ProseMirror editor view
state
EditorState
required
ProseMirror editor state
Returns:
result
Array
Annotations with positions and rectangles

Delete & Remove

findRemovedFieldAnnotations

Find field annotation nodes that were removed in a transaction
Added in v0.11.2
Parameters:
tr
Transaction
required
ProseMirror transaction to analyze
Returns:
result
Array
Array of removed field annotation nodes with their positions

deleteFieldAnnotations

Delete field annotations by field ID
Parameters:
fieldIdOrArray
string | Array.<string>
required
Field ID or array of field IDs to delete
Returns: boolean Command success status

deleteFieldAnnotationsByNode

Delete field annotations by node references
Parameters:
annotations
Array.<{pos: number, node: Node}>
required
Array of annotation objects to delete
Returns: boolean Command success status

deleteFieldAnnotation

Delete a single field annotation
Parameters:
annotation
Object
required
Annotation object to delete
Returns: boolean Command success status

sliceFieldAnnotations

Delete a portion of annotations associated with a field
Parameters:
fieldIdOrArray
string | Array.<string>
required
The field ID or array of field IDs
end
number
required
Index at which to end extraction
Returns: boolean Command success status

Create & Add

addFieldAnnotation

Add field annotation at specified position
Parameters:
pos
number
required
Document position to insert annotation
attrs
Object
required
Field annotation attributes
editorFocus
boolean
Whether to focus editor after insertion
Returns: boolean Command success status

addFieldAnnotationAtSelection

Add field annotation at current selection position
Parameters:
attrs
Object
default:"{}"
Field annotation attributes
editorFocus
boolean
Whether to focus editor after insertion
Returns: boolean Command success status

Update & Edit

replaceWithFieldAnnotation

Replace text ranges with field annotations
Parameters:
fieldsArray
Array.<Object>
required
Array of field replacement objects
fieldsArray[]
object
required
Options object
Returns: boolean Command success status

replaceFieldAnnotationsWithLabelInSelection

Replace field annotations with text labels in current selection
Added in v0.11.0
Parameters:
options
Object
default:"{}"
Additional options
Returns: boolean Command success status

replaceFieldAnnotationsWithLabel

Replace field annotations with text labels
Added in v0.11.0
Parameters:
fieldIdOrArray
string | Array.<string>
required
Field ID(s) to replace
options
Object
default:"{}"
Replace options
Returns: boolean Command success status

resetFieldAnnotations

Reset all field annotations to their default values
Returns: boolean Command success status

updateFieldAnnotations

Update field annotations by field ID
Parameters:
fieldIdOrArray
string | Array.<string>
required
Field ID or array of field IDs
attrs
Object
default:"{}"
Attributes to update
Returns: boolean Command success status

updateFieldAnnotation

Update a specific field annotation instance
Parameters:
annotation
Object
required
Annotation object with pos and node
attrs
Object
default:"{}"
Attributes to update
Returns: boolean Command success status

updateFieldAnnotationsAttributes

Update the attributes of annotations
Parameters:
annotations
Array.<{pos: number, node: Node}>
required
Array of annotations to update
attrs
object
default:"{}"
Attributes to update
Returns: boolean Command success status

setFieldAnnotationsHiddenByCondition

Hide field annotations based on a condition
Parameters:
predicate
function
Function to test each annotation
unsetFromOthers
boolean
Whether to show non-matching annotations
Returns: boolean Command success status

unsetFieldAnnotationsHidden

Show all hidden field annotations
Returns: boolean Command success status

setFieldAnnotationsVisibility

Set visibility for all field annotations
Parameters:
visibility
string
default:"'visible'"
Visibility value (‘visible’ or ‘hidden’)
Returns: boolean Command success status

setFieldAnnotationsHighlighted

Set highlighted status for annotations matching predicate
Parameters:
predicate
function
Function to test each annotation node
highlighted
boolean
default:"true"
Whether to highlight matching annotations
Returns: boolean Command success status

toggleFieldAnnotationsFormat

Toggle formatting for field annotations in selection
Parameters:
name
string
required
Format name (bold, italic, underline)
setSelection
boolean
Whether to set selection after toggle
Returns: boolean Command success status

setFieldAnnotationsFontFamily

Set font family for field annotations in current selection
Parameters:
fontFamily
string
required
Font family name to apply
setSelection
boolean
Whether to set node selection after update
Returns: boolean Command success status

setFieldAnnotationsFontSize

Set font size for field annotations in current selection
Parameters:
fontSize
string
required
Font size value (e.g., ‘12pt’, ‘14px’)
setSelection
boolean
Whether to set node selection after update
Returns: boolean Command success status

setFieldAnnotationsTextHighlight

Set text highlight color for field annotations in current selection
Parameters:
color
string
required
Highlight color value (e.g., ‘#ffff00’, ‘yellow’)
setSelection
boolean
Whether to set node selection after update
Returns: boolean Command success status

setFieldAnnotationsTextColor

Set text color for field annotations in current selection
Parameters:
color
string
required
Text color value (e.g., ‘#000000’, ‘black’)
setSelection
boolean
Whether to set node selection after update
Returns: boolean Command success status

Helpers

transactionDeletedAnything

Check if a transaction contains any deletion operations Parameters:
tr
Transaction
required
ProseMirror transaction to check
Returns: boolean True if transaction contains deletions

trackFieldAnnotationsDeletion

Track field annotation deletions in a transaction and emit events
Added in v0.11.2
Parameters:
editor
Editor
required
SuperDoc editor instance
tr
Transaction
required
ProseMirror transaction
Returns: void

handleDropOutside

Handle field annotation drops outside editor boundaries Parameters:
params
object
required
Drop handling parameters

Events

fieldAnnotationClicked

Field annotation clicked event Event Data:
  • node (Node) - The clicked annotation node
  • nodePos (number) - Position of the node in the document

fieldAnnotationDropped

Field annotation dropped event Event Data:
  • sourceField (object) - The dropped field attributes