API reference
Every name grist-widget-sdk exports, by entry point.
The complete public surface. Anything not listed here is internal. The list
is pinned by packages/core/tests/sdk/public-api.test.ts: a name can't be
added or removed without changing it.
Entry points
| Import path | Use for |
|---|---|
grist-widget-sdk | The hooks, the provider and boundary, cell and attachment helpers, types. |
grist-widget-sdk/actions | User actions for applyActions(): schema changes and batches. |
grist-widget-sdk/app | mountGristWidget(): what src/main.tsx wires (inside- and outside-Grist pages, theme), plus useTheme() and the deploy channel helpers. |
grist-widget-sdk/emulator | The emulator, the engine of the testing helpers. |
grist-widget-sdk/emulator/testing | renderWithGrist, smokeTestWidget, presets and Testing Library. |
grist-widget-sdk/tsconfig/app.json, grist-widget-sdk/tsconfig/node.json | TypeScript settings for a widget's tsconfig.app.json and tsconfig.node.json to extends (TypeScript 5.8 or later). A stricter check only ships in a minor release. |
By entry point
Each table is generated from the SDK's own documentation comments, the ones your editor shows on hover, so it lists every public name and nothing else. The pages linked from each section explain them.
grist-widget-sdk
The hooks (useGrist,
useGristSchema), the
provider and boundary, the cell and
attachment helpers, and the types.
defineGristWidget() is explained in Typed reads.
| Name | Kind | What it is |
|---|---|---|
checkGristCell | function | Checks one value against a Grist column type ("Numeric", "Ref:People", "Text,Ref"), as typed reads do: the value the type promises, or why it doesn't fit. |
decodeGristValue | function | Decodes a Grist cell value into an idiomatic JS value. |
defineGristWidget | function | Declares a widget. The const type parameter keeps the column names and types literal, so the mapped record is typed with no annotation, no as const and no generics. |
encodeGristCell | function | A value as Grist stores it in a column of the declared type: the reverse of what typed reads give. Lists become ["L", ...] (a RefList's Reference items become their row ids), a Date for a Date or DateTime column becomes seconds since the epoch, a Reference for a Ref column its row id. A RefList or Attachments list already encoded (["L", ...], as the attachment helpers return it) and every other value pass through, so it is safe to call twice on those. A ChoiceList value is always a list of choices: a first choice "L" is kept, so give it as the choices (["L", "M"] writes the sizes L and M), never encoded. |
encodeGristValue | function | Encodes a JS value into Grist's expected wire form for a given column type. |
extractGristAttachmentId | function | First attachment id in the cell, if any (see extractGristAttachmentIdsFromCell). |
extractGristAttachmentIdsFromCell | function | All attachment ids found in a Grist attachment cell value (ordered, deduped). Attachment columns are usually an **array** of file refs; a single id or one JSON object is also supported. |
FetchRows | type | A table's rows, each { id, ...cells } under real column ids. Without a table id, the widget's own table as its section shows it (filters and sort applied); with one, any table (full access), in Grist's row order. { columnar: true } gives Grist's columns instead. |
FetchRowsOptions | type | fetchRows() options: rows (the default) or Grist's columns. |
GristApi | type | The methods useGrist() returns next to its state: reads, writes, attachments and the cursor. |
GristApplyUserActionsOptions | type | Optional second argument to docApi.applyUserActions. |
gristAttachmentCellValue | function | Wire value for a single-file Attachments cell. |
gristAttachmentCellValues | function | Wire value for an Attachments cell (Grist list encoding). |
GristAttachmentUploadResult | type | The attachment ids an upload created. |
GristBoundary | function | Renders the widget once Grist is connected, has granted the access it declares, and every required declared column is mapped; until then, a screen that says what is missing (with a retry where one can help). Requires <GristWidgetProvider>; mountGristWidget() renders both. |
GristBoundaryProps | type | The widget, shown once it is connected, has its access and its required columns mapped. |
GristCellCheck | type | What checkGristCell returns: the cell's value, or why it doesn't match its declared type. |
GristCellIssue | type | A mapped cell that didn't match its declared type, or a rule of the widget's schema. |
GristChoiceListEntry | type | One selectable choice for UI (value stored in the cell is value). |
GristColumnarTable | type | Column-oriented table payload, as Grist's grist.docApi.fetchTable and grist.fetchSelectedTable send it: { id: [...], Name: [...] }. |
GristColumnExcludeContext | type | What extraExcludeColumn is given for each column. |
GristColumnInfo | type | One column of a table, as listColumns() gives it. |
GristColumnsToMap | type | Argument shape for grist.ready({ columns }). |
GristColumnToMap | type | Single-column declaration in grist.ready({ columns }). Mirrors Grist ColumnToMap. See https://support.getgrist.com/code/interfaces/grist_plugin_api.ColumnToMap/ |
GristCursorPos | type | Argument to grist.setCursorPos (subset of Grist CursorPos). |
GristDecodedValue | type | A cell as decodeGristValue returns it: plain values, Dates and lists, or an error or a reference marker. |
GristDocumentMode | type | How row bodies were populated when the replica document was built (hint only). Loaders should still treat omitted rows like [] via normalizeReplicaTableInput. |
GristEncodedAttachmentList | type | An Attachments cell as Grist writes it: ["L", ...ids]. |
GristEncodedError | type | ["E", "ErrorClass", "message", traceback?] — Grist error sentinel. |
GristFetchedAttachmentBlob | type | An attachment's bytes, and their content type. |
GristFetchSelectedOptions | type | Options for Grist's own grist.fetchSelectedTable / grist.fetchSelectedRecord (GristView). |
GristFormulaKind | type | How Grist treats the column (from _grist_Tables_column isFormula + formula). empty_slot is Grist's "empty column" state: isFormula true with no formula text. |
GristMappedRow | type | The mapped record a declaration's columns give: { id } and each declared column, typed from its Grist type. widget.useGrist() uses it, and GristWidgetRow<typeof widget> names it for a component's props. |
GristMinimalRecord | type | The least a record has: its row id. |
GristNoiseColumnsOptions | type | Which of Grist's bookkeeping columns to leave out: the row id, helper columns, logging columns, manualSort. |
GristReadyOptions | type | Arguments accepted by grist.ready for custom widgets. |
GristRecordPatch | type | A write under declared names: any of the mapped record's fields but its id. |
GristReplicaColumn | type | Column metadata in replica JSON: Grist-native fields only (no samples / scan stats). formulaKind is optional UI convenience; use resolveGristFormulaKind when missing. |
GristReplicaDocument | type | Canonical Grist replica document: one JSON type for getDocumentJson, fixtures, and createGristEmulator({ document }). |
GristReplicaRow | type | Decoded row in replica JSON (id + fields). Same as wire fetchTable row objects, but **not** columnar Record<colId, unknown[]> — that shape is only on docApi.fetchTable. |
GristReplicaSelection | type | Selection slice persisted on replica fixtures (emulator / widget). |
GristReplicaTable | type | One table of a replica document: its columns and, optionally, its rows. |
GristRequiredAccess | type | Access level passed to grist.ready({ requiredAccess }). |
GristRowRecord | type | A row from grist.onRecord or fetchTable. Always carries a numeric id. |
GristSchemaTableView | type | Selected table slice with tableId for consumers that expect it on the object. |
GristSdkAlertKind | type | The alerts mountGristWidget() shows above a running widget: what needs the user's attention in Grist (column mapping, access, a failed write, an unlinked section). The blocking states (not connected, access refused, required columns unmapped) are <GristBoundary>'s, not alerts. |
GristTableNewRecord | type | Record for create (no id needed). |
GristTableOperations | type | Wraps grist.getTable(...) / grist.selectedTable. |
GristTableOpOptions | type | Options accepted by TableOperations.create / update. |
GristTableUpdateRecord | type | TableOperations-style record for update. Must include id; other fields are partial. |
GristTableUpsertOptions | type | Options accepted by TableOperations.upsert. |
GristTableUpsertRecord | type | Record for upsert: require is the match key set, fields is what to write. |
GristTheme | type | The widget's connection to Grist: one store, one connect(). |
GristUserActionTuple | type | Grist docApi.applyUserActions payloads are arrays of user-action tuples. |
GristWidget | type | A declared widget. Pass it to mountGristWidget() (as widget, exported from src/app/App.tsx). |
GristWidgetActionStatus | type | A write's status: none running, one running, or the last one failed (actionError says why). |
GristWidgetColumnMap | type | Mapping returned by Grist between logical widget column names and real table column ids. Single mappings are string; allowMultiple columns are string[]. |
GristWidgetConfiguration | type | Last grist.ready options mirrored with the emulator (optional on fixtures). |
GristWidgetDefinition | type | What a widget declares: UseGristOptions, plus its title, description and where to report a problem. |
GristWidgetDemo | type | A widget's demo data (src/app/demo.ts, exported as demo): the document its demo page, its real-Grist check and create-grist-widget demo open, in place of generated sample rows. The demo page is public: invented data only, and never a key in its options. |
GristWidgetDemoColumnType | type | The column types demo data takes. |
GristWidgetInteraction | type | Second argument to grist.onOptions — document ↔ widget relationship (subset of Grist InteractionOptions). |
GristWidgetLinkingInfo | type | Linking state reported by Grist in onOptions settings (InteractionOptions.linking). |
GristWidgetMetadata | type | What describes a widget rather than configures it: its title, description, report URL and languages. |
GristWidgetMode | type | Derived from the selection: no row, a row, or the add-row placeholder. |
GristWidgetProvider | function | Connects to Grist for the widgets below it: useGrist() under it reads this connection. mountGristWidget() renders it; render it yourself only for a page that manages its own React root. |
GristWidgetProviderProps | type | What the provider connects with, and the widgets below it. |
GristWidgetRow | type | The widget's mapped record type, from its declaration. |
GristWidgetStatus | type | The widget's connection to Grist, as useGrist().status reports it. |
httpUrl | function | value as a URL a widget may link to or load from: an absolute http: or https: URL, normalised, or undefined. Use it on every link or source that comes from a document's data, before it reaches an href or a src. |
isGristCellError | function | Convenience: true when the cell is a Grist error sentinel. |
ListColumnsOptions | type | listColumns()'s options: which columns to leave out. |
ListTablesOptions | type | useGrist()'s methods, created once per runtime: every one is referentially stable for the widget's lifetime, and reads grist when called (the emulator installs and removes it in tests). |
mergeGristAttachmentCellValue | function | Merge new attachment ids into an existing Attachments cell value (deduped, order preserved). |
MigrateWidgetOptions | type | Brings options written under fromVersion (lower than the widget's optionsVersion) to the current version. Return a new plain object; options it can't migrate: throw, and they are left as they are. Check the options' shape rather than trust fromVersion alone: options without a version count as version 1, and may already be in a later shape. |
normalizeGristChoiceListEntries | function | Normalizes Grist Choice / ChoiceList widgetOptions into a flat list for dropdowns. choices entries are string labels (the stored cell value). Per-choice styling lives in choiceOptions[label]. |
ReplicaDocumentJsonOptions | type | Options for getDocumentJson / buildDocumentJson on the return value of useGristSchema. |
resolveGristFormulaKind | function | Use when formulaKind may be missing (e.g. older document builds). |
StandardSchema | type | Minimal Standard Schema (https://standardschema.dev): zod 4, valibot, arktype implement it. |
tableDataToRows | function | Turn fetchTable output into row objects (order follows the id column). |
useGrist | function | The widget's Grist state and API, from the nearest <GristWidgetProvider>: mountGristWidget() renders one inside Grist, and renderWithGrist(<App />, { widget }) in a test. Throws outside one; a component that also runs outside Grist calls useGristOptional(). |
useGristOptional | function | useGrist() inside a provider, or null outside one: for components that also work without Grist. |
UseGristOptions | type | What the widget asks Grist for: access, columns to map, and the alerts it doesn't want. |
UseGristResult | type | The widget's Grist state and API. Every method is referentially stable for the widget's lifetime: safe in effect dependencies. The object itself is new whenever a value changes; depend on the members you use, not on it. |
useGristSchema | function | Grist replica-document hook: metadata + optional decoded rows per table. |
UseGristSchemaOptions | type | What useGristSchema reads. The connection (access level, columns) is the widget's declaration, from defineGristWidget(): the hook reads it through the provider mountGristWidget() renders. |
UseGristSchemaResult | type | What useGristSchema() returns: the document as a replica, and its JSON. |
useWidgetMetadata | function | Deprecated: mountGristWidget() sets the page's title and meta tags from the declaration. Sets the page's title and its description meta tags. |
UseWidgetMetadataInput | type | The page's title and description. |
ValidateColumnMappingsResult | type | Whether the declared columns are mapped: what is missing, and whether Grist has sent the mappings yet. |
grist-widget-sdk/app
Mounting a widget: mountGristWidget(), the theme and
the deploy channels.
| Name | Kind | What it is |
|---|---|---|
DeployChannel | type | Where a deployed build is being served from. |
deployChannelLabel | function | "latest", "dev", "v1" (a major's channel) or "v1.2.0". |
DeployPath | type | A served URL's channel, and the base path its channels share: what parseDeployPath returns. |
GristWidgetApp | function | The tree mountGristWidget renders, as a component: for a test, or for a page that manages its own React root. |
GristWidgetAppProps | type | What renders a widget: the component, what it asks Grist for, and the pages and alerts around it. |
GristWidgetEntry | type | A widget's entry module, src/app/App.tsx, as import * as entry gives it: the widget as its default export, its declaration as widget, and optionally its Settings, and its own Alerts, LocalDevPage and ReleasePage. |
MountedGristWidget | type | A mounted widget: unmount() removes it and its React root. |
mountGristWidget | function | Render a widget into the page: everything src/main.tsx used to wire by hand. |
MountGristWidgetConfig | type | mountGristWidget()'s older form: the widget's props, and where to render. |
parseDeployPath | function | Parse a pathname into its deploy channel and base path. A path without a channel segment (the deployed root, or a local dev server) is latest: the deploy places the latest release at the root too. |
ReleasedVersion | type | One entry of the versions.json a widget's deploy pipeline maintains. |
ResolvedWidgetTheme | type | The theme applied: "system" resolved to light or dark. |
useReleasedVersions | function | The widget's released versions, read from the versions.json next to its channels (see parseDeployPath). For a page shown outside Grist, such as a release page linking to each version. |
UseReleasedVersionsResult | type | What useReleasedVersions() returns. |
useTheme | function | The widget's current theme, for components that need it in JavaScript (a toaster, a chart). Same shape as shadcn's useTheme(). Styles should rely on the dark class that mountGristWidget keeps on <html>. Outside a mounted widget (a unit test, for instance) it reports the system theme and setTheme does nothing. |
UseThemeResult | type | What useTheme() returns. |
WidgetTheme | type | A theme choice: light, dark, or the system's. |
grist-widget-sdk/actions
User actions for applyActions().
| Name | Kind | What it is |
|---|---|---|
gristAddColumnAction | function | ["AddColumn", tableId, colId, colInfo] — colInfo shape depends on Grist version / column type. |
gristAddRecordAction | function | ["AddRecord", tableId, null, { col: value, ... }] |
gristAddTableAction | function | ["AddTable", tableId, columns]: a new table and its columns, each { id, type?, isFormula?, formula?, … }, as Grist's AddTable takes them. |
gristAddVisibleColumnAction | function | ["AddVisibleColumn", tableId, colId, colInfo] — like AddColumn but also adds the column to the current view section. |
gristBulkAddRecordAction | function | ["BulkAddRecord", tableId, rowIds | nullArray, { col: value[], ... }]. Pass null (or omit) for rowIds to let Grist allocate ids; in user-action format Grist expects an array of nulls of the same length as the value arrays. |
gristBulkRemoveRecordAction | function | ["BulkRemoveRecord", tableId, rowIds] |
gristBulkUpdateRecordAction | function | ["BulkUpdateRecord", tableId, rowIds, { col: value[], ... }] |
gristModifyColumnAction | function | ["ModifyColumn", tableId, colId, colInfo] |
gristRemoveColumnAction | function | ["RemoveColumn", tableId, colId] |
gristRemoveRecordAction | function | ["RemoveRecord", tableId, rowId] |
gristRenameColumnAction | function | ["RenameColumn", tableId, colId, newColId] |
gristUpdateRecordAction | function | ["UpdateRecord", tableId, rowId, { col: value, ... }] |
GristUserActionTuple | type | Grist docApi.applyUserActions payloads are arrays of user-action tuples. |
grist-widget-sdk/emulator
The emulator, the engine of the testing helpers.
| Name | Kind | What it is |
|---|---|---|
CreateDocumentInput | type | Replica document for createDocument; widens table columns to EmulatorColumn. |
CreateDocumentTableInput | type | Replica table for createDocument; columns may include formulaFn / inferredFormula (emulator-only). |
createGristEmulator | function | Creates an emulator for a replica document: it checks the document, installs the grist global (inline transport) and answers the widget as Grist does. Tests usually go through renderWithGrist(). |
CreateGristEmulatorOptions | type | Top-level emulator factory. Produces a fully-wired emulator instance: |
EmulatorActionError | class | A user action the emulator could not apply (a missing row, an action it does not support): the action, and why. |
EmulatorApiBundle | type | Bundles the six host-side Grist API implementations into one record so inline transport can wire them up. |
EmulatorColumn | type | Column metadata for the emulator: GristReplicaColumn plus in-process formulaFn (never serialized in replica JSON). |
EmulatorDocumentState | type | The emulator's document: its tables, the widget's selection and options. |
EmulatorEvent | type | Tiny pub-sub used to broadcast every emulator state change to: - the transports (which translate events into protocol messages), - the React DevTools inspector (timeline view), - the testing harness (assertions on emitted events). |
EmulatorRowId | type | Core types for the in-memory Grist emulator document model. |
EmulatorTable | type | One table of the emulator's document: its columns and rows. |
EmulatorTransport | type | How the emulator reaches the widget: pushes Grist's events to it. |
GristEmulator | type | An in-memory Grist document and the grist global a widget reads it through. |
GristReplicaDocument | type | Canonical Grist replica document: one JSON type for getDocumentJson, fixtures, and createGristEmulator({ document }). |
InlineGristGlobal | type | Shape of the synthesised global. Matches globalThis.grist from grist-global.d.ts. |
parseDocument | function | Checks a replica document and returns it, or throws naming each problem's path. |
presets | const | Useful templates for quick demos and tests. |
safeParseDocument | function | Checks a replica document, returning zod's result instead of throwing. |
grist-widget-sdk/emulator/testing
Testing a widget without a Grist document.
| Name | Kind | What it is |
|---|---|---|
act | re-export | Re-exported from @testing-library/react, unchanged. |
actionsOf | function | The user actions applied to the emulator, oldest first: the widget's, and the test's own apply and mutate. Read from the bus's history, which keeps the last 200 events and is cleared by dispose(). |
cleanup | re-export | Re-exported from @testing-library/react, unchanged. |
eventsOf | function | The last 200 events on the emulator's bus, oldest first (cleared by dispose()): ready, cursor, data, options, mappings, theme and user actions. |
fireEvent | re-export | Re-exported from @testing-library/react, unchanged. |
installJsdomStubs | function | Browser APIs jsdom lacks but widget UI commonly uses, as inert stand-ins: ResizeObserver (charts, virtualized lists, popovers) and window.matchMedia (the theme, responsive hooks; it reports a light, wide screen). Only installs what's missing, so a test's own mock wins. |
presets | const | Useful templates for quick demos and tests. |
render | re-export | Re-exported from @testing-library/react, unchanged. |
RenderOptions | re-export | Re-exported from @testing-library/react, unchanged. |
RenderResult | re-export | Re-exported from @testing-library/react, unchanged. |
renderWithGrist | function | Renders a component against an in-memory Grist (the emulator), behind the same grist global a widget reads in Grist. With widget, it renders the widget in its provider, boundary and alerts, every declared column mapped to a table of rows: renderWithGrist(<App />, { widget, rows }). |
RenderWithGristOptions | type | renderWithGrist(ui, options) — drop-in replacement for @testing-library/react's render(ui) that boots a Grist emulator (inline transport) and exposes it to the test. |
RenderWithGristResult | type | Testing Library's render result, with the emulator the widget runs against. |
screen | re-export | Re-exported from @testing-library/react, unchanged. |
smokeTestWidget | function | Mounts the widget the way mountGristWidget() does inside Grist, against an emulated Grist document with every column it declares mapped and the access it requests granted, and waits until it renders past GristBoundary. Resolves once it has, rejects with the widget's own error if it throws, or with what the page showed instead if it never gets there. Then unmounts. |
SmokeTestWidgetOptions | type | What smokeTestWidget() renders, and against which document. |
waitFor | re-export | Re-exported from @testing-library/react, unchanged. |
waitForEvent | function | Resolves with the next event of a kind on the emulator's bus, or rejects after the timeout, naming the last events seen. |
WaitForEventKind | type | Bus event kinds aligned with grist host callbacks (see inline transport). |
WaitForEventOptions | type | waitForEvent()'s options: how long to wait, in ms (default 1000). |
within | re-export | Re-exported from @testing-library/react, unchanged. |
How names are retired, and what each version promises: Versioning policy.