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
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:
import { SuperDoc } from 'superdoc' ;
const superdoc = new SuperDoc ({
selector: '#editor' ,
document: yourFile ,
// Field annotations are included by default via getStarterExtensions().
// Configure options here:
fieldAnnotation: {
handleDropOutside: true ,
borderColor: '#b015b3' ,
},
});
Form Template Workflow:
// 1. Create form fields
const fields = [
{ id: 'name' , label: 'Full Name' , type: 'text' },
{ id: 'date' , label: 'Date' , type: 'text' },
{ id: 'signature' , label: 'Sign Here' , type: 'signature' }
];
// 2. Insert fields into document
fields . forEach (( field , i ) => {
editor . commands . addFieldAnnotation ( i * 100 , {
fieldId: field . id ,
displayLabel: field . label ,
type: field . type
});
});
// 3. Handle user interactions
editor . on ( 'fieldAnnotationClicked' , ({ node }) => {
openFieldEditor ( node . attrs . fieldId );
});
// 4. Fill and export
editor . annotate ([
{ input_id: 'name' , input_value: 'John Doe' },
{ input_id: 'date' , input_value: '2024-01-15' }
]);
import { SuperDoc } from 'superdoc' ;
import 'superdoc/style.css' ;
const superdoc = new SuperDoc ({
selector: '#editor' ,
document: yourFile ,
onReady : ( superdoc ) => {
const editor = superdoc . activeEditor ;
// 1. Create form fields
const fields = [
{ id: 'name' , label: 'Full Name' , type: 'text' },
{ id: 'date' , label: 'Date' , type: 'text' },
{ id: 'signature' , label: 'Sign Here' , type: 'signature' }
];
// 2. Insert fields into document
fields . forEach (( field , i ) => {
editor . commands . addFieldAnnotation ( i * 100 , {
fieldId: field . id ,
displayLabel: field . label ,
type: field . type
});
});
// 3. Handle user interactions
editor . on ( 'fieldAnnotationClicked' , ({ node }) => {
openFieldEditor ( node . attrs . fieldId );
});
// 4. Fill and export
editor . annotate ([
{ input_id: 'name' , input_value: 'John Doe' },
{ input_id: 'date' , input_value: '2024-01-15' }
]);
},
});
Commands
Find & Search
findFieldAnnotations
Find field annotations matching a predicate function
// Find all signature fields
const signatureFields = findFieldAnnotations (
node => node . attrs . type === 'signature' ,
state
);
import { SuperDoc } from 'superdoc' ;
import 'superdoc/style.css' ;
const superdoc = new SuperDoc ({
selector: '#editor' ,
document: yourFile ,
onReady : ( superdoc ) => {
const editor = superdoc . activeEditor ;
// Find all signature fields
const signatureFields = findFieldAnnotations (
node => node . attrs . type === 'signature' ,
editor . state
);
},
});
// Find fields with specific color
const redFields = findFieldAnnotations (
node => node . attrs . fieldColor === '#FF0000' ,
state
);
import { SuperDoc } from 'superdoc' ;
import 'superdoc/style.css' ;
const superdoc = new SuperDoc ({
selector: '#editor' ,
document: yourFile ,
onReady : ( superdoc ) => {
const editor = superdoc . activeEditor ;
// Find fields with specific color
const redFields = findFieldAnnotations (
node => node . attrs . fieldColor === '#FF0000' ,
editor . state
);
},
});
Parameters:
Function to test each annotation node
Returns:
Matching field annotations
findFieldAnnotationsBetween
Find all field annotations between two positions
// Find fields in selection
const { from , to } = state . selection ;
const selectedFields = findFieldAnnotationsBetween ( from , to , state . doc );
import { SuperDoc } from 'superdoc' ;
import 'superdoc/style.css' ;
const superdoc = new SuperDoc ({
selector: '#editor' ,
document: yourFile ,
onReady : ( superdoc ) => {
const editor = superdoc . activeEditor ;
// Find fields in selection
const { from , to } = editor . state . selection ;
const selectedFields = findFieldAnnotationsBetween ( from , to , editor . state . doc );
},
});
// Find fields in specific range
const rangeFields = findFieldAnnotationsBetween ( 100 , 500 , state . doc );
console . log ( `Found ${ rangeFields . length } fields in range` );
import { SuperDoc } from 'superdoc' ;
import 'superdoc/style.css' ;
const superdoc = new SuperDoc ({
selector: '#editor' ,
document: yourFile ,
onReady : ( superdoc ) => {
const editor = superdoc . activeEditor ;
// Find fields in specific range
const rangeFields = findFieldAnnotationsBetween ( 100 , 500 , editor . state . doc );
console . log ( `Found ${ rangeFields . length } fields in range` );
},
});
Parameters:
ProseMirror document node
Returns:
Field annotations in range
findFieldAnnotationsByFieldId
Find field annotations by field ID(s)
// Find single field
const fields = findFieldAnnotationsByFieldId ( 'field-123' , state );
import { SuperDoc } from 'superdoc' ;
import 'superdoc/style.css' ;
const superdoc = new SuperDoc ({
selector: '#editor' ,
document: yourFile ,
onReady : ( superdoc ) => {
const editor = superdoc . activeEditor ;
// Find single field
const fields = findFieldAnnotationsByFieldId ( 'field-123' , editor . state );
},
});
// Find multiple fields
const fields = findFieldAnnotationsByFieldId ([ 'field-1' , 'field-2' ], state );
fields . forEach (({ pos , node }) => {
console . log ( `Found ${ node . attrs . fieldId } at position ${ pos } ` );
});
import { SuperDoc } from 'superdoc' ;
import 'superdoc/style.css' ;
const superdoc = new SuperDoc ({
selector: '#editor' ,
document: yourFile ,
onReady : ( superdoc ) => {
const editor = superdoc . activeEditor ;
// Find multiple fields
const fields = findFieldAnnotationsByFieldId ([ 'field-1' , 'field-2' ], editor . state );
fields . forEach (({ pos , node }) => {
console . log ( `Found ${ node . attrs . fieldId } at position ${ pos } ` );
});
},
});
Parameters:
fieldIdOrArray
string | Array.<string>
required
Single field ID or array of field IDs
Returns:
Matching field annotations
findFirstFieldAnnotationByFieldId
Find the first field annotation matching a field ID
const firstField = findFirstFieldAnnotationByFieldId ( 'field-123' , state );
if ( firstField ) {
console . log ( `First occurrence at position ${ firstField . pos } ` );
}
import { SuperDoc } from 'superdoc' ;
import 'superdoc/style.css' ;
const superdoc = new SuperDoc ({
selector: '#editor' ,
document: yourFile ,
onReady : ( superdoc ) => {
const editor = superdoc . activeEditor ;
const firstField = findFirstFieldAnnotationByFieldId ( 'field-123' , editor . state );
if ( firstField ) {
console . log ( `First occurrence at position ${ firstField . pos } ` );
}
},
});
Parameters:
Returns:
First matching annotation or null
Find field annotations in headers and footers by field ID or array of field IDs.
const headerFooterAnnotations = findHeaderFooterAnnotationsByFieldId ( 'field-123' , editor , activeSectionEditor );
headerFooterAnnotations . forEach (({ node , pos }) => {
console . log ( `Field ${ node . attrs . fieldId } at position ${ pos } ` );
});
import { SuperDoc } from 'superdoc' ;
import 'superdoc/style.css' ;
const superdoc = new SuperDoc ({
selector: '#editor' ,
document: yourFile ,
onReady : ( superdoc ) => {
const editor = superdoc . activeEditor ;
const headerFooterAnnotations = findHeaderFooterAnnotationsByFieldId ( 'field-123' , editor , activeSectionEditor );
headerFooterAnnotations . forEach (({ node , pos }) => {
console . log ( `Field ${ node . attrs . fieldId } at position ${ pos } ` );
});
},
});
Parameters:
fieldIdOrArray
string | Array.<string>
required
The field ID or array of field IDs
The currently active section editor
Returns:
Array of field annotations with their positions
getAllFieldAnnotations
Get all field annotations in the document
import { fieldAnnotationHelpers } from 'superdoc' ;
const { getAllFieldAnnotations } = fieldAnnotationHelpers ;
const annotations = getAllFieldAnnotations ( editor . state );
console . log ( `Document contains ${ annotations . length } field annotations` );
annotations . forEach (({ pos , node }) => {
console . log ( `Field ${ node . attrs . fieldId } at position ${ pos } ` );
});
Parameters:
Returns:
Array of field annotations with positions
getAllFieldAnnotationsWithRect
Get all field annotations with their bounding rectangles
const annotationsWithRects = getAllFieldAnnotationsWithRect ( view , state );
annotationsWithRects . forEach (({ node , rect }) => {
console . log ( `Field ${ node . attrs . fieldId } at ${ rect . left } , ${ rect . top } ` );
});
import { SuperDoc } from 'superdoc' ;
import 'superdoc/style.css' ;
const superdoc = new SuperDoc ({
selector: '#editor' ,
document: yourFile ,
onReady : ( superdoc ) => {
const editor = superdoc . activeEditor ;
const annotationsWithRects = getAllFieldAnnotationsWithRect ( editor . view , editor . state );
annotationsWithRects . forEach (({ node , rect }) => {
console . log ( `Field ${ node . attrs . fieldId } at ${ rect . left } , ${ rect . top } ` );
});
},
});
Parameters:
Returns:
Annotations with positions and rectangles
Delete & Remove
findRemovedFieldAnnotations
Find field annotation nodes that were removed in a transaction
const removedFields = findRemovedFieldAnnotations ( transaction );
removedFields . forEach (({ node , pos }) => {
console . log ( `Field ${ node . attrs . fieldId } at position ${ pos } ` );
});
import { SuperDoc } from 'superdoc' ;
import 'superdoc/style.css' ;
const superdoc = new SuperDoc ({
selector: '#editor' ,
document: yourFile ,
onReady : ( superdoc ) => {
const editor = superdoc . activeEditor ;
const removedFields = findRemovedFieldAnnotations ( transaction );
removedFields . forEach (({ node , pos }) => {
console . log ( `Field ${ node . attrs . fieldId } at position ${ pos } ` );
});
},
});
Parameters:
ProseMirror transaction to analyze
Returns:
Array of removed field annotation nodes with their positions
deleteFieldAnnotations
Delete field annotations by field ID
// Delete single field annotation
editor . commands . deleteFieldAnnotations ( 'field-123' )
import { SuperDoc } from 'superdoc' ;
import 'superdoc/style.css' ;
const superdoc = new SuperDoc ({
selector: '#editor' ,
document: yourFile ,
onReady : ( superdoc ) => {
const editor = superdoc . activeEditor ;
// Delete single field annotation
editor . commands . deleteFieldAnnotations ( 'field-123' )
},
});
// Delete multiple field annotations
editor . commands . deleteFieldAnnotations ([ 'field-1' , 'field-2' ])
import { SuperDoc } from 'superdoc' ;
import 'superdoc/style.css' ;
const superdoc = new SuperDoc ({
selector: '#editor' ,
document: yourFile ,
onReady : ( superdoc ) => {
const editor = superdoc . activeEditor ;
// Delete multiple field annotations
editor . commands . deleteFieldAnnotations ([ 'field-1' , 'field-2' ])
},
});
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
const annotations = editor . helpers . fieldAnnotation . getAllFieldAnnotations ();
editor . commands . deleteFieldAnnotationsByNode ( annotations . slice ( 0 , 2 ));
import { SuperDoc } from 'superdoc' ;
import 'superdoc/style.css' ;
const superdoc = new SuperDoc ({
selector: '#editor' ,
document: yourFile ,
onReady : ( superdoc ) => {
const editor = superdoc . activeEditor ;
const annotations = editor . helpers . fieldAnnotation . getAllFieldAnnotations ();
editor . commands . deleteFieldAnnotationsByNode ( annotations . slice ( 0 , 2 ));
},
});
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
const annotation = editor . helpers . fieldAnnotation . findFieldAnnotationsByFieldId ( 'field-123' )[ 0 ];
editor . commands . deleteFieldAnnotation ( annotation );
import { SuperDoc } from 'superdoc' ;
import 'superdoc/style.css' ;
const superdoc = new SuperDoc ({
selector: '#editor' ,
document: yourFile ,
onReady : ( superdoc ) => {
const editor = superdoc . activeEditor ;
const annotation = editor . helpers . fieldAnnotation . findFieldAnnotationsByFieldId ( 'field-123' )[ 0 ];
editor . commands . deleteFieldAnnotation ( annotation );
},
});
Parameters:
Annotation object to delete
Returns: boolean Command success status
sliceFieldAnnotations
Delete a portion of annotations associated with a field
// Remove annotations starting from index 6
editor . commands . sliceFieldAnnotations ( 'field-123' , 5 )
import { SuperDoc } from 'superdoc' ;
import 'superdoc/style.css' ;
const superdoc = new SuperDoc ({
selector: '#editor' ,
document: yourFile ,
onReady : ( superdoc ) => {
const editor = superdoc . activeEditor ;
// Remove annotations starting from index 6
editor . commands . sliceFieldAnnotations ( 'field-123' , 5 )
},
});
// Remove from multiple fields
editor . commands . sliceFieldAnnotations ([ 'field-1' , 'field-2' ], 5 )
import { SuperDoc } from 'superdoc' ;
import 'superdoc/style.css' ;
const superdoc = new SuperDoc ({
selector: '#editor' ,
document: yourFile ,
onReady : ( superdoc ) => {
const editor = superdoc . activeEditor ;
// Remove from multiple fields
editor . commands . sliceFieldAnnotations ([ 'field-1' , 'field-2' ], 5 )
},
});
Parameters:
fieldIdOrArray
string | Array.<string>
required
The field ID or array of field IDs
Index at which to end extraction
Returns: boolean Command success status
Create & Add
addFieldAnnotation
Add field annotation at specified position
editor . commands . addFieldAnnotation ( 10 , {
fieldId: 'field-123' ,
displayLabel: 'Enter your name' ,
fieldType: 'TEXTINPUT' ,
fieldColor: '#980043'
})
import { SuperDoc } from 'superdoc' ;
import 'superdoc/style.css' ;
const superdoc = new SuperDoc ({
selector: '#editor' ,
document: yourFile ,
onReady : ( superdoc ) => {
const editor = superdoc . activeEditor ;
editor . commands . addFieldAnnotation ( 10 , {
fieldId: 'field-123' ,
displayLabel: 'Enter your name' ,
fieldType: 'TEXTINPUT' ,
fieldColor: '#980043'
})
},
});
Parameters:
Document position to insert annotation
Field annotation attributes Text to display in annotation
Type of field (TEXTINPUT, CHECKBOX, etc.)
Background color for annotation
Annotation type (text, image, signature, etc.)
Whether to focus editor after insertion
Returns: boolean Command success status
addFieldAnnotationAtSelection
Add field annotation at current selection position
editor . commands . addFieldAnnotationAtSelection ({
fieldId: 'field-456' ,
displayLabel: 'Signature here'
}, true )
import { SuperDoc } from 'superdoc' ;
import 'superdoc/style.css' ;
const superdoc = new SuperDoc ({
selector: '#editor' ,
document: yourFile ,
onReady : ( superdoc ) => {
const editor = superdoc . activeEditor ;
editor . commands . addFieldAnnotationAtSelection ({
fieldId: 'field-456' ,
displayLabel: 'Signature here'
}, true )
},
});
Parameters:
Field annotation attributes
Whether to focus editor after insertion
Returns: boolean Command success status
Update & Edit
replaceWithFieldAnnotation
Replace text ranges with field annotations
editor . commands . replaceWithFieldAnnotation ([{
from: 20 ,
to: 45 ,
attrs: {
fieldId: 'field-789' ,
fieldType: 'TEXTINPUT' ,
fieldColor: '#980043'
}
}])
import { SuperDoc } from 'superdoc' ;
import 'superdoc/style.css' ;
const superdoc = new SuperDoc ({
selector: '#editor' ,
document: yourFile ,
onReady : ( superdoc ) => {
const editor = superdoc . activeEditor ;
editor . commands . replaceWithFieldAnnotation ([{
from: 20 ,
to: 45 ,
attrs: {
fieldId: 'field-789' ,
fieldType: 'TEXTINPUT' ,
fieldColor: '#980043'
}
}])
},
});
Parameters:
Array of field replacement objects
Options object Field annotation attributes
Returns: boolean Command success status
replaceFieldAnnotationsWithLabelInSelection
Replace field annotations with text labels in current selection
// Replace all annotations in selection with their labels
editor . commands . replaceFieldAnnotationsWithLabelInSelection ()
import { SuperDoc } from 'superdoc' ;
import 'superdoc/style.css' ;
const superdoc = new SuperDoc ({
selector: '#editor' ,
document: yourFile ,
onReady : ( superdoc ) => {
const editor = superdoc . activeEditor ;
// Replace all annotations in selection with their labels
editor . commands . replaceFieldAnnotationsWithLabelInSelection ()
},
});
Parameters:
Returns: boolean Command success status
replaceFieldAnnotationsWithLabel
Replace field annotations with text labels
// Replace specific fields with labels
editor . commands . replaceFieldAnnotationsWithLabel ([ 'field-1' , 'field-2' ])
import { SuperDoc } from 'superdoc' ;
import 'superdoc/style.css' ;
const superdoc = new SuperDoc ({
selector: '#editor' ,
document: yourFile ,
onReady : ( superdoc ) => {
const editor = superdoc . activeEditor ;
// Replace specific fields with labels
editor . commands . replaceFieldAnnotationsWithLabel ([ 'field-1' , 'field-2' ])
},
});
// Replace only text annotations in selection
editor . commands . replaceFieldAnnotationsWithLabel ( null , {
isInSelection: true ,
types: [ 'text' ]
})
import { SuperDoc } from 'superdoc' ;
import 'superdoc/style.css' ;
const superdoc = new SuperDoc ({
selector: '#editor' ,
document: yourFile ,
onReady : ( superdoc ) => {
const editor = superdoc . activeEditor ;
// Replace only text annotations in selection
editor . commands . replaceFieldAnnotationsWithLabel ( null , {
isInSelection: true ,
types: [ 'text' ]
})
},
});
Parameters:
fieldIdOrArray
string | Array.<string>
required
Field ID(s) to replace
Replace options Replace only in selection
Add operation to undo history
Annotation types to replace
Returns: boolean Command success status
resetFieldAnnotations
Reset all field annotations to their default values
// Reset all annotations in document
editor . commands . resetFieldAnnotations ()
import { SuperDoc } from 'superdoc' ;
import 'superdoc/style.css' ;
const superdoc = new SuperDoc ({
selector: '#editor' ,
document: yourFile ,
onReady : ( superdoc ) => {
const editor = superdoc . activeEditor ;
// Reset all annotations in document
editor . commands . resetFieldAnnotations ()
},
});
Returns: boolean Command success status
updateFieldAnnotations
Update field annotations by field ID
// Update single field
editor . commands . updateFieldAnnotations ( 'field-123' , {
displayLabel: 'Updated label' ,
fieldColor: '#FF0000'
})
import { SuperDoc } from 'superdoc' ;
import 'superdoc/style.css' ;
const superdoc = new SuperDoc ({
selector: '#editor' ,
document: yourFile ,
onReady : ( superdoc ) => {
const editor = superdoc . activeEditor ;
// Update single field
editor . commands . updateFieldAnnotations ( 'field-123' , {
displayLabel: 'Updated label' ,
fieldColor: '#FF0000'
})
},
});
// Update multiple fields
editor . commands . updateFieldAnnotations ([ 'field-1' , 'field-2' ], {
hidden: true
})
import { SuperDoc } from 'superdoc' ;
import 'superdoc/style.css' ;
const superdoc = new SuperDoc ({
selector: '#editor' ,
document: yourFile ,
onReady : ( superdoc ) => {
const editor = superdoc . activeEditor ;
// Update multiple fields
editor . commands . updateFieldAnnotations ([ 'field-1' , 'field-2' ], {
hidden: true
})
},
});
Parameters:
fieldIdOrArray
string | Array.<string>
required
Field ID or array of field IDs
Returns: boolean Command success status
updateFieldAnnotation
Update a specific field annotation instance
// Update specific annotation instance
const annotation = editor . helpers . fieldAnnotation . findFirstFieldAnnotationByFieldId ( 'field-123' , state );
editor . commands . updateFieldAnnotation ( annotation , {
displayLabel: 'New label'
})
import { SuperDoc } from 'superdoc' ;
import 'superdoc/style.css' ;
const superdoc = new SuperDoc ({
selector: '#editor' ,
document: yourFile ,
onReady : ( superdoc ) => {
const editor = superdoc . activeEditor ;
// Update specific annotation instance
const annotation = editor . helpers . fieldAnnotation . findFirstFieldAnnotationByFieldId ( 'field-123' , editor . state );
editor . commands . updateFieldAnnotation ( annotation , {
displayLabel: 'New label'
})
},
});
Parameters:
Annotation object with pos and node
Returns: boolean Command success status
updateFieldAnnotationsAttributes
Update the attributes of annotations
const annotations = editor . helpers . fieldAnnotation . getAllFieldAnnotations ();
editor . commands . updateFieldAnnotationsAttributes ( annotations , {
fieldColor: '#FF0000' ,
hidden: false
});
import { SuperDoc } from 'superdoc' ;
import 'superdoc/style.css' ;
const superdoc = new SuperDoc ({
selector: '#editor' ,
document: yourFile ,
onReady : ( superdoc ) => {
const editor = superdoc . activeEditor ;
const annotations = editor . helpers . fieldAnnotation . getAllFieldAnnotations ();
editor . commands . updateFieldAnnotationsAttributes ( annotations , {
fieldColor: '#FF0000' ,
hidden: false
});
},
});
Parameters:
annotations
Array.<{pos: number, node: Node}>
required
Array of annotations to update
Returns: boolean Command success status
setFieldAnnotationsHiddenByCondition
Hide field annotations based on a condition
// Hide specific field IDs
editor . commands . setFieldAnnotationsHiddenByCondition ( node => {
const targetIds = [ 'field-1' , 'field-2' , 'field-3' ];
return targetIds . includes ( node . attrs . fieldId );
})
import { SuperDoc } from 'superdoc' ;
import 'superdoc/style.css' ;
const superdoc = new SuperDoc ({
selector: '#editor' ,
document: yourFile ,
onReady : ( superdoc ) => {
const editor = superdoc . activeEditor ;
// Hide specific field IDs
editor . commands . setFieldAnnotationsHiddenByCondition ( node => {
const targetIds = [ 'field-1' , 'field-2' , 'field-3' ];
return targetIds . includes ( node . attrs . fieldId );
})
},
});
// Hide signature fields and show others
editor . commands . setFieldAnnotationsHiddenByCondition (
node => node . attrs . type === 'signature' ,
true
)
import { SuperDoc } from 'superdoc' ;
import 'superdoc/style.css' ;
const superdoc = new SuperDoc ({
selector: '#editor' ,
document: yourFile ,
onReady : ( superdoc ) => {
const editor = superdoc . activeEditor ;
// Hide signature fields and show others
editor . commands . setFieldAnnotationsHiddenByCondition (
node => node . attrs . type === 'signature' ,
true
)
},
});
Parameters:
Function to test each annotation
Whether to show non-matching annotations
Returns: boolean Command success status
unsetFieldAnnotationsHidden
Show all hidden field annotations
// Make all annotations visible
editor . commands . unsetFieldAnnotationsHidden ()
import { SuperDoc } from 'superdoc' ;
import 'superdoc/style.css' ;
const superdoc = new SuperDoc ({
selector: '#editor' ,
document: yourFile ,
onReady : ( superdoc ) => {
const editor = superdoc . activeEditor ;
// Make all annotations visible
editor . commands . unsetFieldAnnotationsHidden ()
},
});
Returns: boolean Command success status
setFieldAnnotationsVisibility
Set visibility for all field annotations
// Make all annotations visible
editor . commands . setFieldAnnotationsVisibility ( 'visible' )
import { SuperDoc } from 'superdoc' ;
import 'superdoc/style.css' ;
const superdoc = new SuperDoc ({
selector: '#editor' ,
document: yourFile ,
onReady : ( superdoc ) => {
const editor = superdoc . activeEditor ;
// Make all annotations visible
editor . commands . setFieldAnnotationsVisibility ( 'visible' )
},
});
// Hide all annotations (preserves layout)
editor . commands . setFieldAnnotationsVisibility ( 'hidden' )
import { SuperDoc } from 'superdoc' ;
import 'superdoc/style.css' ;
const superdoc = new SuperDoc ({
selector: '#editor' ,
document: yourFile ,
onReady : ( superdoc ) => {
const editor = superdoc . activeEditor ;
// Hide all annotations (preserves layout)
editor . commands . setFieldAnnotationsVisibility ( 'hidden' )
},
});
Parameters:
visibility
string
default: "'visible'"
Visibility value (‘visible’ or ‘hidden’)
Returns: boolean Command success status
setFieldAnnotationsHighlighted
Set highlighted status for annotations matching predicate
// Highlight specific field IDs
editor . commands . setFieldAnnotationsHighlighted (( node ) => {
const targetIds = [ 'field-1' , 'field-2' , 'field-3' ];
return targetIds . includes ( node . attrs . fieldId );
}, true )
import { SuperDoc } from 'superdoc' ;
import 'superdoc/style.css' ;
const superdoc = new SuperDoc ({
selector: '#editor' ,
document: yourFile ,
onReady : ( superdoc ) => {
const editor = superdoc . activeEditor ;
// Highlight specific field IDs
editor . commands . setFieldAnnotationsHighlighted (( node ) => {
const targetIds = [ 'field-1' , 'field-2' , 'field-3' ];
return targetIds . includes ( node . attrs . fieldId );
}, true )
},
});
// Remove highlighting from all annotations
editor . commands . setFieldAnnotationsHighlighted (() => true , false )
import { SuperDoc } from 'superdoc' ;
import 'superdoc/style.css' ;
const superdoc = new SuperDoc ({
selector: '#editor' ,
document: yourFile ,
onReady : ( superdoc ) => {
const editor = superdoc . activeEditor ;
// Remove highlighting from all annotations
editor . commands . setFieldAnnotationsHighlighted (() => true , false )
},
});
Parameters:
Function to test each annotation node
Whether to highlight matching annotations
Returns: boolean Command success status
Toggle formatting for field annotations in selection
// Toggle bold formatting on selected annotations
editor . commands . toggleFieldAnnotationsFormat ( 'bold' );
import { SuperDoc } from 'superdoc' ;
import 'superdoc/style.css' ;
const superdoc = new SuperDoc ({
selector: '#editor' ,
document: yourFile ,
onReady : ( superdoc ) => {
const editor = superdoc . activeEditor ;
// Toggle bold formatting on selected annotations
editor . commands . toggleFieldAnnotationsFormat ( 'bold' );
},
});
// Toggle italic and update selection
editor . commands . toggleFieldAnnotationsFormat ( 'italic' , true );
import { SuperDoc } from 'superdoc' ;
import 'superdoc/style.css' ;
const superdoc = new SuperDoc ({
selector: '#editor' ,
document: yourFile ,
onReady : ( superdoc ) => {
const editor = superdoc . activeEditor ;
// Toggle italic and update selection
editor . commands . toggleFieldAnnotationsFormat ( 'italic' , true );
},
});
Parameters:
Format name (bold, italic, underline)
Whether to set selection after toggle
Returns: boolean Command success status
setFieldAnnotationsFontFamily
Set font family for field annotations in current selection
editor . commands . setFieldAnnotationsFontFamily ( 'Arial' , true )
import { SuperDoc } from 'superdoc' ;
import 'superdoc/style.css' ;
const superdoc = new SuperDoc ({
selector: '#editor' ,
document: yourFile ,
onReady : ( superdoc ) => {
const editor = superdoc . activeEditor ;
editor . commands . setFieldAnnotationsFontFamily ( 'Arial' , true )
},
});
Parameters:
Font family name to apply
Whether to set node selection after update
Returns: boolean Command success status
setFieldAnnotationsFontSize
Set font size for field annotations in current selection
editor . commands . setFieldAnnotationsFontSize ( '14pt' )
import { SuperDoc } from 'superdoc' ;
import 'superdoc/style.css' ;
const superdoc = new SuperDoc ({
selector: '#editor' ,
document: yourFile ,
onReady : ( superdoc ) => {
const editor = superdoc . activeEditor ;
editor . commands . setFieldAnnotationsFontSize ( '14pt' )
},
});
Parameters:
Font size value (e.g., ‘12pt’, ‘14px’)
Whether to set node selection after update
Returns: boolean Command success status
setFieldAnnotationsTextHighlight
Set text highlight color for field annotations in current selection
editor . commands . setFieldAnnotationsTextHighlight ( '#ffff00' )
import { SuperDoc } from 'superdoc' ;
import 'superdoc/style.css' ;
const superdoc = new SuperDoc ({
selector: '#editor' ,
document: yourFile ,
onReady : ( superdoc ) => {
const editor = superdoc . activeEditor ;
editor . commands . setFieldAnnotationsTextHighlight ( '#ffff00' )
},
});
Parameters:
Highlight color value (e.g., ‘#ffff00’, ‘yellow’)
Whether to set node selection after update
Returns: boolean Command success status
setFieldAnnotationsTextColor
Set text color for field annotations in current selection
editor . commands . setFieldAnnotationsTextColor ( '#0066cc' )
import { SuperDoc } from 'superdoc' ;
import 'superdoc/style.css' ;
const superdoc = new SuperDoc ({
selector: '#editor' ,
document: yourFile ,
onReady : ( superdoc ) => {
const editor = superdoc . activeEditor ;
editor . commands . setFieldAnnotationsTextColor ( '#0066cc' )
},
});
Parameters:
Text color value (e.g., ‘#000000’, ‘black’)
Whether to set node selection after update
Returns: boolean Command success status
Helpers
transactionDeletedAnything
Check if a transaction contains any deletion operations
Parameters:
ProseMirror transaction to check
Returns: boolean True if transaction contains deletions
trackFieldAnnotationsDeletion
Track field annotation deletions in a transaction and emit events
// Listen for field deletions
editor . on ( 'fieldAnnotationDeleted' , ({ removedNodes }) => {
removedNodes . forEach (({ node }) => {
console . log ( `Field ${ node . attrs . fieldId } was deleted` );
// Clean up external references
removeFieldFromDatabase ( node . attrs . fieldId );
});
});
import { SuperDoc } from 'superdoc' ;
import 'superdoc/style.css' ;
const superdoc = new SuperDoc ({
selector: '#editor' ,
document: yourFile ,
onReady : ( superdoc ) => {
const editor = superdoc . activeEditor ;
// Listen for field deletions
editor . on ( 'fieldAnnotationDeleted' , ({ removedNodes }) => {
removedNodes . forEach (({ node }) => {
console . log ( `Field ${ node . attrs . fieldId } was deleted` );
// Clean up external references
removeFieldFromDatabase ( node . attrs . fieldId );
});
});
},
});
Parameters:
Returns: void
handleDropOutside
Handle field annotation drops outside editor boundaries
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