Skip to Content
API Referencereferences

@stesura/references

Framework-free footnotes, endnotes and cross-references: plugins, commands, helpers and the note-panel store. The UI is in @stesura/references-react; the nodes are in the core schema. See the references guide for how the feature behaves.

Plugins

referencesPlugins

Every plugin the feature needs, in order. Place them after the core numbering plugins, so cross-references see counters updated in the same transaction.

import { referencesPlugins } from '@stesura/references/plugins' const plugins = [...stesuraPlugins(schema, editorId), ...referencesPlugins()]

The cross-reference and note-panel binding plugins are only available through referencesPlugins(), which keeps their order right.

notesPlugin

Note numbering on its own, for hosts that want neither cross-references nor the note panels. Takes an optional list of NoteKindConfigs; the default is footnotes and endnotes.

Parameters:
NameTypeDefault
kindsNoteKindConfig[]
Returns:
Plugin<NotesPluginState>

getFootnotes / getEndnotes

Parameters:
NameTypeDefault
stateEditorState
Returns:
FootnoteItem[]
Parameters:
NameTypeDefault
stateEditorState
Returns:
EndnoteItem[]

Commands

insertCrossReference

Parameters:
NameTypeDefault
__0{ targetId: string; text: string; refTo: CrossRefType; separator: string | null; }

Inserted between levels of a fullContext reference.

Returns:
Command

canInsertCrossReference

Parameters:
NameTypeDefault
stateEditorState
dispatch(tr: Transaction) => void
viewEditorView
Returns:
boolean

goToCrossRefTarget

Parameters:
NameTypeDefault
referenceCrossRefLink
Returns:
Command

insertFootnote

Parameters:
NameTypeDefault
refstring
onSuccess(ref: string) => void
Returns:
Command

insertEndnote

Parameters:
NameTypeDefault
refstring
onSuccess(ref: string) => void
Returns:
Command

deleteFootnote / deleteEndnote

Parameters:
NameTypeDefault
refstring
Returns:
Command
Parameters:
NameTypeDefault
refstring
Returns:
Command
Parameters:
NameTypeDefault
noteRefstring
direction1 | -1
onNavigate(ref: string) => void
Returns:
Command
Parameters:
NameTypeDefault
noteRefstring
direction1 | -1
onNavigate(ref: string) => void
Returns:
Command

nextFootnote / previousFootnote / nextEndnote / previousEndnote

Parameters:
NameTypeDefault
onSuccess(ref: string) => void
Returns:
Command
Parameters:
NameTypeDefault
onSuccess(ref: string) => void
Returns:
Command
Parameters:
NameTypeDefault
onSuccess(ref: string) => void
Returns:
Command
Parameters:
NameTypeDefault
onSuccess(ref: string) => void
Returns:
Command

Helpers

isCrossRefSelected

Parameters:
NameTypeDefault
stateEditorState
Returns:
boolean

getCrossRef

Parameters:
NameTypeDefault
stateEditorState
Returns:
Node | null

findCrossRefTargetWithPos

Parameters:
NameTypeDefault
docNode
targetIdstring
Returns:
NodeWithPos | undefined

computeFullContext

Parameters:
NameTypeDefault
stateEditorState
listRefstring

List whose level configs format the path.

pathstring

Dot-separated counter path, e.g. "1.2.3".

languagestring

BCP 47 tag for localized formats; falls back to en-GB.

separatorstring

Inserted between levels. Defaults to "".

Returns:
string

E.g. "1.2.a", or "" when nothing resolves.

getAboveBelowText

Parameters:
NameTypeDefault
languagestring

BCP 47 tag of the target; unknown languages fall back to English.

isAboveboolean

Whether the target precedes the reference.

Returns:
string

findFootnotes / findEndnotes

Parameters:
NameTypeDefault
docNode
Returns:
NodeWithPos | undefined
Parameters:
NameTypeDefault
docNode
Returns:
NodeWithPos | undefined

Also exported from @stesura/references/helpers: findFootnoteAnchor, findFootnoteBodyPos, findEndnoteBodyPos, the kind-generic findNoteAnchor / findNoteBodyPos / findNoteContainer, and isHeaderFooterRegion / isSkippedNoteRegion.

Note-panel store

Exported from the package root. Which note is open is tracked per editor and per kind ("footnote" | "endnote").

ExportPurpose
openNotePanel(editorId, kind, ref, options?)Opens the panel on ref and closes the other kind’s. { focusOnOpen: false } leaves focus where it is.
closeNotePanel(editorId, kind)Closes the panel.
activeNoteRefAtom(editorId, kind)Atom holding the open note’s ref, or null. Stable per editor and kind.
noteFocusRequestAtom(editorId, kind){ id, focus }, with a new id on every open and close. Consumed by <FocusOnRequest>.
shouldFocusNoteOnOpen(editorId, kind)Whether the current open asked for focus.
disposeNotePanelState(editorId, kind?)Releases an editor’s atoms. The panels call it on unmount.
footnoteEditorRegistry / endnoteEditorRegistryMounted note sub-editors.
footnoteKind / endnoteKindSub-editor kind configs, for useSubEditor in a custom panel.
Last updated on