Skip to Content
API Referencebibliography-react

@stesura/bibliography-react

React UI for citations and bibliographies. Most hosts only need createBibliographyUiExtension; the pieces are exported for hosts that build their own toolbar, panels or dialogs. The plugins and commands are in @stesura/bibliography; setup and the adapter contract are in the citations guide.

UI extension

import { bibliographyPlugins } from '@stesura/bibliography' import { createBibliographyUiExtension, withBundledStyles } from '@stesura/bibliography-react' // One adapter for both: the plugin formats with it, the UI looks up and searches with it. const adapter = withBundledStyles({ lookup, searchLibrary, enrich }) // Module scope: `uiExtensions` must be referentially stable. const uiExtensions = [createBibliographyUiExtension({ adapter })] const extraPlugins = () => [...bibliographyPlugins({ adapter })]

extraPlugins goes on the mount hook, uiExtensions on StesuraEditor.

createBibliographyUiExtension

The bibliography feature as one UI extension: the references-tab group, the sources panel, the citation and bibliography menus and node views, and the picker and source dialogs in the document overlay.

Parameters:
NameTypeDefault
__0BibliographyUiOptions
Returns:
StesuraUIExtension

BibliographyUiOptions

Options for createBibliographyUiExtension.

NameTypeDefault
adapterPartial<BibliographyAdapter>

The same adapter as bibliographyPlugins; missing optional methods hide their affordances.

fieldWidgetsPartial<Record<FieldKind, ComponentType<FieldWidgetProps>>>

Field widgets by kind for the source dialog, over the defaults.

withBundledStyles

The host’s adapter over the bundled styles and locales: what the host leaves out of the formatting half falls back to APA, MLA, Chicago, IEEE, Harvard and Vancouver. Pass the same object to bibliographyPlugins.

Parameters:
NameTypeDefault
adapterPartial<BibliographyAdapter>
Returns:
BibliographyAdapter

bibliographyNodeViews

The citation and bibliography node views, keyed by node name, for wiring by hand. The UI extension already registers them. Without them both nodes fall back to the schema’s toDOM, which shows the cached text without the retraction warning or the click and keyboard behaviour.

Placing the pieces yourself

Each piece reads the adapter from BibliographyAdapterProvider, so wrap them in one. The dialogs are mounted once per root editor and opened through useCitationPicker and useSourceDialog.

ExportContents
BibliographyGroupReferences-tab group: insert a citation or a bibliography, open the sources panel
SourcesPanelThe document’s sources: usage, problems, signals, library updates, style, import
BibliographyContextMenuContext menu entries for a selected citation or bibliography
CitationPickerDialogThe citation picker (library search, lookups, locators)
SourceDialogThe source form dialog; takes widgets to override field widgets
SourceSignalsLoaderFetches enrich signals and library change reports; renders nothing

BibliographyAdapterProvider

Supplies the adapter to the bibliography components below it; createBibliographyUiExtension wraps its pieces in one.

Parameters:
NameTypeDefault
__0{ adapter: BibliographyAdapter; children: ReactNode; }
Returns:
Element

useBibliographyAdapter

The host’s adapter. Optional methods it lacks hide their affordances.

Parameters:
This function does not accept any parameters.
Returns:
BibliographyAdapter

Hooks

useDocBibliography

The root document’s sources, style and locale (debounced). Stable while the attr is: bibliographyOf caches per attr object.

Parameters:
This function does not accept any parameters.
Returns:
BibliographyDocAttr

useCitationPicker

The root editor’s citation picker: request is what it’s open on (null when closed); open(view, { editPos?, asFootnote? }) inserts, or edits the citation at editPos. CitationPickerDialog renders it.

Parameters:
This function does not accept any parameters.
Returns:
{ request: PickerRequest | null; open: (view: EditorView, options?: { editPos?: number | null; asFootnote?: boolean; }) => void; close: () => void; }

PickerRequest

The citation picker, open on view: inserting, or editing the citation at editPos. editNode is that citation when the picker opened: the doc may change while it’s open, so submit re-finds the node rather than trusting the pos.

NameTypeDefault
viewEditorView
editPosnumber | null
editNodeNode | null
asFootnoteboolean

useSourceDialog

The root editor’s source dialog: open a new source (sourceId: null) or an existing one. SourceDialog renders it.

Parameters:
This function does not accept any parameters.
Returns:
{ request: SourceDialogRequest | null; open: (next: SourceDialogRequest) => void; close: () => void; }

SourceDialogRequest

The source dialog: a new source (sourceId null) or an existing one.

NameTypeDefault
sourceIdstring | null
initialPartial<BibliographySource>

Prefills a new source (a lookup result).

pastestring

Seeds a new source’s “Paste a reference” box (text dropped on the panel).

onSaved(sourceId: string) => void

Called with the saved source’s id.

useSourceSignals

The adapter’s enrich signals for a DOI (retraction, corrections, counts), once SourceSignalsLoader has fetched them.

Parameters:
NameTypeDefault
doiunknown
Returns:
SourceSignals | undefined

Headless source form

For hosts building their own source dialog: useSourceForm loads the Zotero-derived field layout for the chosen type and validates the draft as it changes.

useSourceForm

The state behind the source dialog, without the dialog: the type’s field layout from the Zotero schema (lazy-loaded), the draft, contributor rows and inline validation. Hosts building their own form use this directly.

Parameters:
NameTypeDefault
__0{ initial?: SourceDraft; locale: string; }
Returns:
{ ready: boolean; loadError: boolean; retryLoad: () => void; labels: ZoteroLabels | null; layout: FormLayout | null; types: { type: CslItemType; label: string; }[]; ... 20 more ...; toSource: (id: string) => BibliographySource | null; }

SourceForm

What useSourceForm returns.

NameTypeDefault
readyboolean
loadErrorboolean

The schema or labels failed to load; retryLoad tries again.

retryLoad() => void
labelsZoteroLabels | null
layoutFormLayout | null
types{ type: CslItemType; label: string; }[]
draftSourceDraft
setType(type: CslItemType) => void
typeChosenboolean

The user picked a type: a fill keeps it.

setId(id: string) => void
fill(found: SourceDraft, { adoptType }?: { adoptType?: boolean; }) => string[]
attachmentsSourceAttachment[]
addAttachment(attachment: SourceAttachment) => void
removeAttachment(index: number) => void
setField(field: FormField, value: string | number | CslDate | undefined) => void
creatorsCreatorRow[]
addCreator(role?: CslNameVariable | undefined) => void
updateCreator(index: number, patch: Partial<CreatorRow>) => void
removeCreator(index: number) => void
moveCreator(index: number, by: 1 | -1) => void
problemsBibliographyProblem[]
problemsOf(variable: string) => BibliographyProblem[]
revealProblems() => void
isDirtyboolean
isUnverified(variable: string) => boolean
toDraft() => SourceDraft
toSource(id: string) => BibliographySource | null

SourceDraft

A draft: a source without its id until saved, id kept when editing.

NameTypeDefault
numberstring | number
editorCslName[]
typeCslItemType
titlestring | number
partstring | number
sectionstring | number
abstractstring | number
annotestring | number
archivestring | number
archive_collectionstring | number
archive_locationstring | number
archive-placestring | number
authoritystring | number
call-numberstring | number
chapter-numberstring | number
citation-keystring | number
citation-labelstring | number
collection-numberstring | number
collection-titlestring | number
container-titlestring | number
container-title-shortstring | number
dimensionsstring | number
divisionstring | number
DOIstring | number
editionstring | number
event-placestring | number
event-titlestring | number
genrestring | number
ISBNstring | number
ISSNstring | number
issuestring | number
jurisdictionstring | number
keywordstring | number
languagestring | number
licensestring | number
mediumstring | number
notestring | number
number-of-pagesstring | number
number-of-volumesstring | number
original-publisherstring | number
original-publisher-placestring | number
original-titlestring | number
pagestring | number
page-firststring | number
part-titlestring | number
PMCIDstring | number
PMIDstring | number
printingstring | number
publisherstring | number
publisher-placestring | number
referencesstring | number
reviewed-genrestring | number
reviewed-titlestring | number
scalestring | number
sourcestring | number
statusstring | number
supplementstring | number
title-shortstring | number
URLstring | number
versionstring | number
volumestring | number
volume-titlestring | number
year-suffixstring | number
authorCslName[]
chairCslName[]
collection-editorCslName[]
compilerCslName[]
composerCslName[]
container-authorCslName[]
contributorCslName[]
curatorCslName[]
directorCslName[]
editorial-directorCslName[]
executive-producerCslName[]
guestCslName[]
hostCslName[]
illustratorCslName[]
interviewerCslName[]
narratorCslName[]
organizerCslName[]
original-authorCslName[]
performerCslName[]
producerCslName[]
recipientCslName[]
reviewed-authorCslName[]
script-writerCslName[]
series-creatorCslName[]
translatorCslName[]
accessedCslDate
available-dateCslDate
event-dateCslDate
issuedCslDate
original-dateCslDate
submittedCslDate
attachmentsSourceAttachment[]
provenanceSourceProvenance
libraryRefSourceLibraryRef
word{ tag?: string; guid?: string; }

Word’s b:Tag and b:Guid, kept for lossless DOCX round-trip.

idstring

CreatorRow

A contributor row in the source form.

NameTypeDefault
roleCslNameVariable
nameCslName
singleboolean

One field: an organisation or a mononym, kept as literal.

FormLayout

The source form for one CSL type, in Zotero’s field order.

NameTypeDefault
zoteroTypestring

The Zotero item type the layout follows, for its labels.

fieldsFormField[]
creatorRoles{ role: CslNameVariable; zoteroCreatorType: string; }[]

Contributor roles the type offers, the primary one first.

FormField

One field of the source form: the CSL variable it fills and its Zotero counterpart.

NameTypeDefault
kind"date" | "url" | "text" | "long" | "identifier"
variableCslStandardVariable | CslDateVariable
zoteroFieldstring

FieldKind

type FieldKind = "text" | "long" | "date" | "url" | "identifier"

What renders a field: the key into the field widget registry (defaultFieldWidgets, or fieldWidgets on createBibliographyUiExtension).

defaultFieldWidgets

Field widgets by kind. Override entries to change how a kind renders; the creators list and the type select are the dialog’s own.

NameTypeDefault
dateComponentType<FieldWidgetProps>
urlComponentType<FieldWidgetProps>
textComponentType<FieldWidgetProps>
longComponentType<FieldWidgetProps>
identifierComponentType<FieldWidgetProps>

FieldWidgetProps

What every field widget receives.

NameTypeDefault
idstring
labelstring
valueunknown
onChange(value: string | CslDate | undefined) => void
problemsBibliographyProblem[]
unverifiedboolean

A model filled it and nothing verified it.

problemMessage

A problem’s message in the UI language.

Parameters:
NameTypeDefault
tTranslationKeys
problemBibliographyProblem
Returns:
string
Last updated on