@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.
| Name | Type | Default |
|---|---|---|
kinds | NoteKindConfig[] |
getFootnotes / getEndnotes
Parameters:| Name | Type | Default |
|---|---|---|
state | EditorState |
| Name | Type | Default |
|---|---|---|
state | EditorState |
Commands
insertCrossReference
Parameters:| Name | Type | Default |
|---|---|---|
__0 | { targetId: string; text: string; refTo: CrossRefType; separator: string | null; }Inserted between levels of a |
canInsertCrossReference
Parameters:| Name | Type | Default |
|---|---|---|
state | EditorState | |
dispatch | (tr: Transaction) => void | |
view | EditorView |
goToCrossRefTarget
Parameters:| Name | Type | Default |
|---|---|---|
reference | CrossRefLink |
insertFootnote
Parameters:| Name | Type | Default |
|---|---|---|
ref | string | |
onSuccess | (ref: string) => void |
insertEndnote
Parameters:| Name | Type | Default |
|---|---|---|
ref | string | |
onSuccess | (ref: string) => void |
deleteFootnote / deleteEndnote
Parameters:| Name | Type | Default |
|---|---|---|
ref | string |
| Name | Type | Default |
|---|---|---|
ref | string |
navigateFootnote / navigateEndnote
Parameters:| Name | Type | Default |
|---|---|---|
noteRef | string | |
direction | 1 | -1 | |
onNavigate | (ref: string) => void |
| Name | Type | Default |
|---|---|---|
noteRef | string | |
direction | 1 | -1 | |
onNavigate | (ref: string) => void |
nextFootnote / previousFootnote / nextEndnote / previousEndnote
Parameters:| Name | Type | Default |
|---|---|---|
onSuccess | (ref: string) => void |
| Name | Type | Default |
|---|---|---|
onSuccess | (ref: string) => void |
| Name | Type | Default |
|---|---|---|
onSuccess | (ref: string) => void |
| Name | Type | Default |
|---|---|---|
onSuccess | (ref: string) => void |
Helpers
isCrossRefSelected
Parameters:| Name | Type | Default |
|---|---|---|
state | EditorState |
getCrossRef
Parameters:| Name | Type | Default |
|---|---|---|
state | EditorState |
findCrossRefTargetWithPos
Parameters:| Name | Type | Default |
|---|---|---|
doc | Node | |
targetId | string |
computeFullContext
Parameters:getAboveBelowText
Parameters:| Name | Type | Default |
|---|---|---|
language | stringBCP 47 tag of the target; unknown languages fall back to English. | |
isAbove | booleanWhether the target precedes the reference. |
findFootnotes / findEndnotes
Parameters:| Name | Type | Default |
|---|---|---|
doc | Node |
| Name | Type | Default |
|---|---|---|
doc | Node |
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").
| Export | Purpose |
|---|---|
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 / endnoteEditorRegistry | Mounted note sub-editors. |
footnoteKind / endnoteKind | Sub-editor kind configs, for useSubEditor in a custom panel. |