@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.
| Name | Type | Default |
|---|---|---|
__0 | BibliographyUiOptions |
BibliographyUiOptions
Options for createBibliographyUiExtension.
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.
| Name | Type | Default |
|---|---|---|
adapter | Partial<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.
| Export | Contents |
|---|---|
BibliographyGroup | References-tab group: insert a citation or a bibliography, open the sources panel |
SourcesPanel | The document’s sources: usage, problems, signals, library updates, style, import |
BibliographyContextMenu | Context menu entries for a selected citation or bibliography |
CitationPickerDialog | The citation picker (library search, lookups, locators) |
SourceDialog | The source form dialog; takes widgets to override field widgets |
SourceSignalsLoader | Fetches enrich signals and library change reports; renders nothing |
BibliographyAdapterProvider
Supplies the adapter to the bibliography components below it; createBibliographyUiExtension wraps its pieces in one.
| Name | Type | Default |
|---|---|---|
__0 | { adapter: BibliographyAdapter; children: ReactNode; } |
useBibliographyAdapter
The host’s adapter. Optional methods it lacks hide their affordances.
Hooks
useDocBibliography
The root document’s sources, style and locale (debounced). Stable while the
attr is: bibliographyOf caches per attr object.
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.
{ 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.
| Name | Type | Default |
|---|---|---|
view | EditorView | |
editPos | number | null | |
editNode | Node | null | |
asFootnote | boolean |
useSourceDialog
The root editor’s source dialog: open a new source (sourceId: null) or an existing one. SourceDialog renders it.
{ request: SourceDialogRequest | null; open: (next: SourceDialogRequest) => void; close: () => void; }SourceDialogRequest
The source dialog: a new source (sourceId null) or an existing one.
useSourceSignals
The adapter’s enrich signals for a DOI (retraction, corrections, counts), once SourceSignalsLoader has fetched them.
| Name | Type | Default |
|---|---|---|
doi | unknown |
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.
| Name | Type | Default |
|---|---|---|
__0 | { initial?: SourceDraft; locale: string; } |
{ 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.
SourceDraft
A draft: a source without its id until saved, id kept when editing.
CreatorRow
A contributor row in the source form.
| Name | Type | Default |
|---|---|---|
role | CslNameVariable | |
name | CslName | |
single | booleanOne field: an organisation or a mononym, kept as |
FormLayout
The source form for one CSL type, in Zotero’s field order.
FormField
One field of the source form: the CSL variable it fills and its Zotero counterpart.
| Name | Type | Default |
|---|---|---|
kind | "date" | "url" | "text" | "long" | "identifier" | |
variable | CslStandardVariable | CslDateVariable | |
zoteroField | string |
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.
| Name | Type | Default |
|---|---|---|
date | ComponentType<FieldWidgetProps> | |
url | ComponentType<FieldWidgetProps> | |
text | ComponentType<FieldWidgetProps> | |
long | ComponentType<FieldWidgetProps> | |
identifier | ComponentType<FieldWidgetProps> |
FieldWidgetProps
What every field widget receives.
| Name | Type | Default |
|---|---|---|
id | string | |
label | string | |
value | unknown | |
onChange | (value: string | CslDate | undefined) => void | |
problems | BibliographyProblem[] | |
unverified | booleanA model filled it and nothing verified it. |
problemMessage
A problem’s message in the UI language.
| Name | Type | Default |
|---|---|---|
t | TranslationKeys | |
problem | BibliographyProblem |