Skip to Content
API Referencecontract-check-react

@stesura/contract-check-react

The contract check UI for the @stesura/contract-check plugin. Setup is in the Contract check guide.

UI extension

createContractCheckUIExtension

The contract check UI: Review-tab button and on/off switch, status-bar count, findings panel, defined-term hover card. The switch is a user preference kept in localStorage. Pass it via uiExtensions next to contractCheckPlugin() in the mount’s plugins. Create it at module level: the editor expects a stable uiExtensions array.

Parameters:
NameTypeDefault
__0ContractCheckUIExtensionOptions
Returns:
StesuraUIExtension

ContractCheckUIExtensionOptions

NameTypeDefault
settingsEndpointstring

Answers a GET with the organisation’s CheckSettings as JSON (common terms, short forms, weights, thresholds, rules). Without it the built-in settings apply.

contractCheckUIExtension

The UI with the built-in settings.

NameTypeDefault
leftPanelsLeftPanelElement[]
rightPanelsRightPanelElement[]
bottomPanelsBottomPanelElement[]
contextMenuExtensionsContextMenuExtension[]
textMenuExtensionsTextMenuExtension<string>[]
toolbarDefaultTabsPartial<Record<ToolbarDefaultTabs, false>>
toolbarDefaultExtensionsToolbarDefaultExtension[]
toolbarGroupExtensionsToolbarGroupExtension[]
toolbarTabsToolbarExtensionTab[]

Whole tabs after the built-in ones, usually contextual.

floatingMenuExtensionsFloatingMenuExtension[]
slashMenuExtensionsMenuElement[]
StatusBarElementsStatusBarElement[]
nodeViewsNodeViews
nodeViewWrappersRecord<string, ComponentType<NodeViewWrapperComponentProps>>

DOM-less wrappers composed around whichever view wins for a node type. A wrapper must render {children} (the wrapped view) and add no DOM; it contributes via context, typically NodeViewSlotsProvider. Unlike a nodeViews entry, it survives the consumer’s nodeViews overrides.

nodeViewFallback(type: NodeType) => NodeView | undefined

The view for a block type core doesn’t define and nothing registered a view for by name (a host schema’s own node), or undefined to pass. The last extension answering wins; otherwise editor-react renders the type’s toDOM with its derived values and slots (DerivedSpecView).

nodeViewWrapperFallback(type: NodeType) => ComponentType<NodeViewWrapperComponentProps> | undefined

A nodeViewWrappers entry for a block type core doesn’t define, when this extension names no wrapper for it. Composed around whichever view wins, the host’s own included, so a host node gets the extension’s behaviour (pagination’s page-break lead) without being listed.

pdfPreviewPdfPreviewCapability

Renders PDF file nodes as page previews (@stesura/pdf-viewer-react). Declared on the extension rather than set from an effect so the file view, pagination and export know it before the first layout; an effect arrives a commit late and forced a second pagination pass.

calloutFrameComponentType<CalloutFrameProps>

Replaces the callout title bar’s content (icon + title). Rendered inside the non-editable bar above the body; pagination measures it as chrome, so give it padding, never margins.

documentOverlaySlotReact.ReactNode
ResizableLayoutBottomSlotReact.ReactNode
TopLeftSlotReact.ReactNode
CommentsSlotReact.ReactNode

Components

ContractCheckPanel

Right-hand panel listing the document’s contract findings in document order: errors and warnings, then hints, then the ignored ones (collapsed). Each can be ignored or flagged; that state lives on the document, shared with collaborators. The header fixes what can be fixed (typed references made live) and saves the report as Markdown or JSON. While track changes is on, fixing needs an explicit override.

Parameters:
NameTypeDefault
props{}
Returns:
ReactNode

ContractCheckStatusBar

Status-bar count of open errors and warnings; opens the panel. Off, it says so and turns checking on.

Parameters:
NameTypeDefault
props{}
Returns:
ReactNode

ContractCheckToolbarGroup

Review-tab group: the button toggles the contract check panel, its menu turns checking on or off.

Parameters:
NameTypeDefault
props{}
Returns:
ReactNode

ContractCheckSettingsLoader

Fetches the organisation’s CheckSettings from endpoint and hands them to the contract-check plugin, which rebuilds. Renders nothing; mounted through documentOverlaySlot by createContractCheckUIExtension({ settingsEndpoint }).

Parameters:
NameTypeDefault
__0{ endpoint: string; }
Returns:
null

DefinedTermCard

A defined term’s definition, its version in a bilingual document and how often it is used, shown when the pointer is over the term or the caret is in it. Mounted through documentOverlaySlot.

Keyboard users reach it by moving the caret into a term: the card appears without taking focus, and a polite live region reads it. “Go to definition” from the keyboard is goToDefinitionAtSelection, for the host to bind. The card is viewport-fixed and a reading of one doc version, so it closes on scroll, Escape, typing and when the pointer leaves both the term and the card.

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

ContractCheckVisibleRange

Tells the contract-check plugin what is on screen, so underlines are drawn only there: decorating every use in a 200-page agreement costs a frame on each edit. Renders nothing; mounted through documentOverlaySlot.

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

Hooks

CONTRACT_CHECK_PANEL_ACTION

Right-panel action id of the contract check panel.

NameTypeDefault
toString() => string
charAt(pos: number) => string
charCodeAt(index: number) => number
concat(...strings: string[]) => string
indexOf(searchString: string, position?: number | undefined) => number
lastIndexOf(searchString: string, position?: number | undefined) => number
localeCompare{ (that: string): number; (that: string, locales?: string | string[] | undefined, options?: CollatorOptions | undefined): number; (that: string, locales?: LocalesArgument, options?: CollatorOptions | undefined): number; }
match{ (regexp: string | RegExp): RegExpMatchArray | null; (matcher: { [Symbol.match](string: string): RegExpMatchArray | null; }): RegExpMatchArray | null; }
replace{ (searchValue: string | RegExp, replaceValue: string): string; (searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string; (searchValue: { ...; }, replaceValue: string): string; (searchValue: { ...; }, replacer: (substring: string, ...args: any[]) => string): string; }
slice(start?: number | undefined, end?: number | undefined) => string
split{ (separator: string | RegExp, limit?: number | undefined): string[]; (splitter: { [Symbol.split](string: string, limit?: number | undefined): string[]; }, limit?: number | undefined): string[]; }
substring(start: number, end?: number | undefined) => string
toLowerCase() => string
toLocaleLowerCase{ (locales?: string | string[] | undefined): string; (locales?: LocalesArgument): string; }
toUpperCase() => string
toLocaleUpperCase{ (locales?: string | string[] | undefined): string; (locales?: LocalesArgument): string; }
trim() => string
lengthnumber
substr(from: number, length?: number | undefined) => string
valueOf() => string
codePointAt(pos: number) => number | undefined
includes(searchString: string, position?: number | undefined) => boolean
endsWith(searchString: string, endPosition?: number | undefined) => boolean
normalize{ (form: "NFC" | "NFD" | "NFKC" | "NFKD"): string; (form?: string | undefined): string; }
repeat(count: number) => string
startsWith(searchString: string, position?: number | undefined) => boolean
anchor(name: string) => string
big() => string
bold() => string
fixed() => string
fontcolor(color: string) => string
fontsize{ (size: number): string; (size: string): string; }
italics() => string
small() => string
strike() => string
sub() => string
sup() => string
padStart(maxLength: number, fillString?: string | undefined) => string
padEnd(maxLength: number, fillString?: string | undefined) => string
trimEnd() => string
trimStart() => string
trimLeft() => string
trimRight() => string
matchAll(regexp: RegExp) => RegExpStringIterator<RegExpExecArray>
replaceAll{ (searchValue: string | RegExp, replaceValue: string): string; (searchValue: string | RegExp, replacer: (substring: string, ...args: any[]) => string): string; }
at(index: number) => string | undefined
__@iterator@6565() => StringIterator<string>

useContractCheck

The root editor’s findings, from the debounced state; installed is false without the plugin.

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

useContractCheckActions

Actions against the root editor, stable across renders.

Parameters:
This function does not accept any parameters.
Returns:
{ fix: (selection: string[] | "all", force: boolean) => boolean | undefined; setStatus: (id: string, status: CheckReviewStatus) => boolean | undefined; focus: (id: string | null, range?: number | ... 1 more ... | undefined) => boolean | undefined; goTo: (id: string, index?: number | undefined) => boolean | undefined...
Last updated on