grist-widget-sdk 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (70) hide show
  1. package/CHANGELOG.md +730 -0
  2. package/LICENSE +15 -0
  3. package/README.md +249 -0
  4. package/dist/advanced.cjs +2749 -0
  5. package/dist/advanced.cjs.map +1 -0
  6. package/dist/advanced.d.cts +790 -0
  7. package/dist/advanced.d.ts +790 -0
  8. package/dist/advanced.js +825 -0
  9. package/dist/advanced.js.map +1 -0
  10. package/dist/chunk-64SVRWW7.js +758 -0
  11. package/dist/chunk-64SVRWW7.js.map +1 -0
  12. package/dist/chunk-BNBV24WM.js +479 -0
  13. package/dist/chunk-BNBV24WM.js.map +1 -0
  14. package/dist/chunk-ELGVOHFD.js +32 -0
  15. package/dist/chunk-ELGVOHFD.js.map +1 -0
  16. package/dist/chunk-GTTD5HPO.js +36 -0
  17. package/dist/chunk-GTTD5HPO.js.map +1 -0
  18. package/dist/chunk-JASMM2YC.js +243 -0
  19. package/dist/chunk-JASMM2YC.js.map +1 -0
  20. package/dist/chunk-PM3B4WYV.js +12 -0
  21. package/dist/chunk-PM3B4WYV.js.map +1 -0
  22. package/dist/chunk-QKXKZ27D.js +1189 -0
  23. package/dist/chunk-QKXKZ27D.js.map +1 -0
  24. package/dist/chunk-QZG7SNUG.js +463 -0
  25. package/dist/chunk-QZG7SNUG.js.map +1 -0
  26. package/dist/chunk-REV5AUXD.js +25 -0
  27. package/dist/chunk-REV5AUXD.js.map +1 -0
  28. package/dist/chunk-XE2SKNLH.js +1641 -0
  29. package/dist/chunk-XE2SKNLH.js.map +1 -0
  30. package/dist/create-grist-emulator-C_0I4wax.d.ts +80 -0
  31. package/dist/create-grist-emulator-DBS6gmiI.d.cts +80 -0
  32. package/dist/emulator/devtools.cjs +1367 -0
  33. package/dist/emulator/devtools.cjs.map +1 -0
  34. package/dist/emulator/devtools.d.cts +46 -0
  35. package/dist/emulator/devtools.d.ts +46 -0
  36. package/dist/emulator/devtools.js +480 -0
  37. package/dist/emulator/devtools.js.map +1 -0
  38. package/dist/emulator/testing.cjs +2061 -0
  39. package/dist/emulator/testing.cjs.map +1 -0
  40. package/dist/emulator/testing.d.cts +50 -0
  41. package/dist/emulator/testing.d.ts +50 -0
  42. package/dist/emulator/testing.js +124 -0
  43. package/dist/emulator/testing.js.map +1 -0
  44. package/dist/emulator/transports.cjs +1132 -0
  45. package/dist/emulator/transports.cjs.map +1 -0
  46. package/dist/emulator/transports.d.cts +37 -0
  47. package/dist/emulator/transports.d.ts +37 -0
  48. package/dist/emulator/transports.js +12 -0
  49. package/dist/emulator/transports.js.map +1 -0
  50. package/dist/emulator.cjs +1796 -0
  51. package/dist/emulator.cjs.map +1 -0
  52. package/dist/emulator.d.cts +107 -0
  53. package/dist/emulator.d.ts +107 -0
  54. package/dist/emulator.js +26 -0
  55. package/dist/emulator.js.map +1 -0
  56. package/dist/index.cjs +5511 -0
  57. package/dist/index.cjs.map +1 -0
  58. package/dist/index.d.cts +825 -0
  59. package/dist/index.d.ts +825 -0
  60. package/dist/index.js +2447 -0
  61. package/dist/index.js.map +1 -0
  62. package/dist/inline-CRwQQ-GW.d.cts +311 -0
  63. package/dist/inline-QitZwXKP.d.ts +311 -0
  64. package/dist/templates-BC7FoSdW.d.ts +24 -0
  65. package/dist/templates-DBq719O_.d.cts +24 -0
  66. package/dist/types-Fb2wplkv.d.cts +228 -0
  67. package/dist/types-Fb2wplkv.d.ts +228 -0
  68. package/dist/use-grist-widget-options-from-context-BFhQBGRY.d.ts +522 -0
  69. package/dist/use-grist-widget-options-from-context-qpFMdoBJ.d.cts +522 -0
  70. package/package.json +131 -0
@@ -0,0 +1,825 @@
1
+ import { d as GristDocApi, g as GristFormulaKind, j as GristReplicaColumn, k as GristReplicaDocument, n as GristReplicaTable, l as GristReplicaRow, b as GristColumnsToMap, w as GristWidgetColumnMap, p as GristRowRecord, y as GristWidgetInteraction, s as GristTableOperations, G as GristApplyUserActionsOptions, f as GristFetchSelectedOptions, c as GristCursorPos, i as GristReadyOptions, o as GristRequiredAccess, e as GristDocumentMode } from './types-Fb2wplkv.js';
2
+ export { a as GristColumnToMap, h as GristMinimalRecord, m as GristReplicaSelection, q as GristTableNewRecord, r as GristTableOpOptions, t as GristTableUpdateRecord, u as GristTableUpsertOptions, v as GristTableUpsertRecord, x as GristWidgetConfiguration, z as GristWidgetLinkingInfo } from './types-Fb2wplkv.js';
3
+ import { E as GristWidgetSnapshot, H as GristWidgetStatus, D as GristUserActionTuple, N as UseGristCoreResult, U as UseGristCoreOptions, b as GristCapabilities, f as GristColumnarTable, F as FetchGristTableRowsOptions, S as SafeParseGristTableDataOptions, s as GristSafeParseCellResult, J as ListTablesOptions, L as ListColumnsOptions, d as GristColumnInfo, G as GristAccessToken, r as GristNoiseColumnsOptions } from './use-grist-widget-options-from-context-BFhQBGRY.js';
4
+ export { c as GristCellValue, e as GristColumnLike, t as GristSafeParseIssue, u as GristSafeParseIssueCode, v as GristSafeRefListValue, w as GristSafeRefValue, x as GristSafeTableCellIssue, y as GristSafeTableCellMeta, B as GristTableRowsOrder, K as SafeParseGristTableDataResult, M as SafeParseGristValuesOptions, O as UseGristWidgetOptionsFromContextConfig, P as UseGristWidgetOptionsFromContextResult, Q as computeRowCount, R as decodeColumnarToReplicaRows, T as fetchGristRow, V as fetchGristTableRows, W as fetchWithGristAuth, X as findRowIndexById, Y as getGristAccessToken, Z as gristAddColumnAction, _ as gristAddRecordAction, $ as gristAddTableAction, a0 as gristAddVisibleColumnAction, a1 as gristBulkAddRecordAction, a2 as gristBulkRemoveRecordAction, a3 as gristBulkUpdateRecordAction, a4 as gristCellValueSchema, a5 as gristDuplicateTableAction, a6 as gristModifyColumnAction, a7 as gristRemoveColumnAction, a8 as gristRemoveRecordAction, a9 as gristRemoveTableAction, aa as gristRenameColumnAction, ab as gristRenameTableAction, ac as gristReplaceTableDataAction, ad as gristSafeRefListValueSchema, ae as gristSafeRefValueSchema, af as gristSetDocumentInfoAction, ag as gristUpdateRecordAction, ah as inferDisplayHelpersByRef, ai as isGristNoiseColumn, aj as materializeGristRowsFromColumnar, ak as rowAtIndex, al as safeParseGristTableData, am as safeParseGristValues, an as safeParseRowsToDisplayRows, ao as sortRowsByGristOrder, ap as tableDataToRows, aq as useGristWidgetOptionsFromContext } from './use-grist-widget-options-from-context-BFhQBGRY.js';
5
+ import * as react_jsx_runtime from 'react/jsx-runtime';
6
+ import { ReactNode } from 'react';
7
+ import 'zod';
8
+
9
+ type GristFetchedAttachment = {
10
+ base64: string;
11
+ contentType: string;
12
+ };
13
+ type GristFetchedAttachmentBlob = {
14
+ blob: Blob;
15
+ contentType: string;
16
+ };
17
+ /**
18
+ * All attachment ids found in a Grist attachment cell value (ordered, deduped).
19
+ * Attachment columns are usually an **array** of file refs; a single id or one JSON object is also supported.
20
+ */
21
+ declare function extractGristAttachmentIdsFromCell(value: unknown): string[];
22
+ /** First attachment id in the cell, if any (see {@link extractGristAttachmentIdsFromCell}). */
23
+ declare function extractGristAttachmentId(value: unknown): string | undefined;
24
+ /**
25
+ * Signed Grist download URL for a single attachment id (`getAccessToken` + query auth).
26
+ */
27
+ declare function getAttachmentDownloadUrl(docApi: GristDocApi, attachmentId: string, options?: {
28
+ readOnly?: boolean;
29
+ }): Promise<string>;
30
+ /** URL for the `index`’th attachment in a cell value (0-based). */
31
+ declare function getAttachmentDownloadUrlForCell(docApi: GristDocApi, cellValue: unknown, index: number, options?: {
32
+ readOnly?: boolean;
33
+ }): Promise<string | null>;
34
+ /** Token + URL + fetch for one attachment id. */
35
+ declare function fetchAttachmentBase64(docApi: GristDocApi, attachmentId: string, options?: {
36
+ readOnly?: boolean;
37
+ }): Promise<GristFetchedAttachment>;
38
+ /** Download attachment bytes as a `Blob` (preferred for large files). */
39
+ declare function fetchAttachmentBlob(docApi: GristDocApi, attachmentId: string, options?: {
40
+ readOnly?: boolean;
41
+ }): Promise<GristFetchedAttachmentBlob>;
42
+ /** Download the `index`’th attachment in a cell (0-based). */
43
+ declare function fetchAttachmentBase64ForCell(docApi: GristDocApi, cellValue: unknown, index: number, options?: {
44
+ readOnly?: boolean;
45
+ }): Promise<GristFetchedAttachment | null>;
46
+
47
+ type GristEncodedAttachmentList = ["L", ...(number | string)[]];
48
+ type GristAttachmentUploadResult = {
49
+ /** All attachment ids returned by `POST /attachments`. */
50
+ ids: string[];
51
+ /** First id in `ids` (convenience for single-file uploads). */
52
+ firstId: string;
53
+ };
54
+ /**
55
+ * Parse the body of `POST /attachments` (widget or REST).
56
+ * Grist returns a JSON array of attachment ids, e.g. `[42]` or `[101, 102]`.
57
+ */
58
+ declare function parseGristAttachmentUploadResponseIds(raw: string, options?: {
59
+ strict?: boolean;
60
+ }): string[];
61
+ /**
62
+ * First attachment id from an upload response (see {@link parseGristAttachmentUploadResponseIds}).
63
+ */
64
+ declare function parseGristAttachmentUploadResponse(raw: string, options?: {
65
+ strict?: boolean;
66
+ }): string;
67
+ declare function extractAttachmentIdsFromUploadPayload(parsed: unknown, options?: {
68
+ strict?: boolean;
69
+ }): string[];
70
+ /** @deprecated Prefer {@link extractAttachmentIdsFromUploadPayload}. */
71
+ declare function extractFirstAttachmentIdFromUploadPayload(parsed: unknown): string | undefined;
72
+ /** Wire value for an Attachments cell (Grist list encoding). */
73
+ declare function gristAttachmentCellValues(attachmentIds: (string | number)[]): GristEncodedAttachmentList;
74
+ /** Wire value for a single-file Attachments cell. */
75
+ declare function gristAttachmentCellValue(attachmentId: string | number): GristEncodedAttachmentList;
76
+ /**
77
+ * Merge new attachment ids into an existing Attachments cell value (deduped, order preserved).
78
+ */
79
+ declare function mergeGristAttachmentCellValue(existingCell: unknown, newIds: (string | number)[]): GristEncodedAttachmentList;
80
+ /**
81
+ * Upload a file to the current document via `POST /attachments`.
82
+ *
83
+ * Uses `getAccessToken({ readOnly: false })` and `?auth=` (see Grist widget docs).
84
+ * Requires document **full** access in the widget.
85
+ */
86
+ declare function uploadGristAttachment(docApi: GristDocApi, file: Blob | File, options?: {
87
+ fileName?: string;
88
+ }): Promise<GristAttachmentUploadResult>;
89
+
90
+ declare function inferGristFormulaKind(isFormula: boolean, formulaTrimmed: string): GristFormulaKind;
91
+ /** Use when `formulaKind` may be missing (e.g. older document builds). */
92
+ declare function resolveGristFormulaKind(col: GristReplicaColumn): GristFormulaKind;
93
+ /** Serialize cell values for JSON output. */
94
+ declare function serializeJsonFriendly(value: unknown): unknown;
95
+
96
+ type ReplicaTableColumnMetaLite = {
97
+ colRef?: number;
98
+ type?: string;
99
+ label?: string;
100
+ parentPos?: number;
101
+ isFormula?: boolean;
102
+ formula?: string;
103
+ description?: string;
104
+ widgetOptions?: Record<string, unknown>;
105
+ displayColRef?: number;
106
+ visibleColRef?: number;
107
+ };
108
+ declare function loadColumnMetadataByTable(docApi: GristDocApi): Promise<Map<string, Map<string, ReplicaTableColumnMetaLite>>>;
109
+ declare function orderedColumnIds(data: Record<string, unknown[]>, metaByCol: Map<string, ReplicaTableColumnMetaLite>): string[];
110
+ /** Build replica column metadata from columnar `fetchTable` + `_grist_Tables_column` maps. */
111
+ declare function buildReplicaColumnsFromColumnar(data: Record<string, unknown[]>, colMeta: Map<string, ReplicaTableColumnMetaLite>): Record<string, GristReplicaColumn>;
112
+ type BuildReplicaDocumentFromDocApiOptions = {
113
+ /** When false (default), skip fetching row data for `tableId` starting with `_grist`. */
114
+ includeSystemTableData?: boolean;
115
+ /**
116
+ * Row bodies: omit (`false`), first N (`samples`), or full decode (`full`).
117
+ * Default `samples`.
118
+ */
119
+ includeRows?: false | "samples" | "full";
120
+ /** Max rows per table when `includeRows` is `samples`. Default 10. */
121
+ sampleRowLimit?: number;
122
+ /** Set on the replica as `source` for host logging / provenance. */
123
+ source?: string;
124
+ };
125
+ /**
126
+ * Build {@link GristReplicaDocument} from a host `docApi`:
127
+ * metadata from `_grist_Tables` / `_grist_Tables_column` when readable, plus optional decoded `rows`.
128
+ *
129
+ * Prefer {@link useGrist}'s `buildReplicaDocumentFromDocApi()` when you already use the primary hook.
130
+ */
131
+ declare function buildReplicaDocumentFromDocApi(docApi: GristDocApi, options?: BuildReplicaDocumentFromDocApiOptions): Promise<GristReplicaDocument>;
132
+
133
+ /**
134
+ * Ensure `rows` is a concrete array for emulator / merge logic.
135
+ * Call at host boundaries (`createDocument`, tests); JSON may still omit `rows` for schema-only.
136
+ */
137
+ declare function normalizeReplicaTableInput<T extends GristReplicaTable>(table: T): T & {
138
+ rows: GristReplicaRow[];
139
+ };
140
+ /** Apply {@link normalizeReplicaTableInput} to every table; shallow-copies the document shell. */
141
+ declare function normalizeReplicaDocumentInput<T extends GristReplicaDocument>(doc: T): T;
142
+ /** How row arrays appear in serialized replica JSON from {@link buildReplicaJsonPayload}. */
143
+ type ReplicaJsonIncludeRows = "none" | "samples" | "full";
144
+ /**
145
+ * Clone a replica document for JSON output: strip rows, cap to first N, or pass through.
146
+ * Does not mutate the source document.
147
+ */
148
+ declare function buildReplicaJsonPayload(doc: GristReplicaDocument, options: {
149
+ includeRows: ReplicaJsonIncludeRows;
150
+ sampleRowLimit?: number;
151
+ }): GristReplicaDocument;
152
+
153
+ /**
154
+ * Grist stores column widget configuration in `_grist_Tables_column.widgetOptions`
155
+ * as a JSON string. Choice fields use `choices: string[]` plus optional
156
+ * `choiceOptions: Record<string, Style>` (e.g. `fillColor`, `textColor`).
157
+ *
158
+ * @see https://github.com/gristlabs/grist-core/blob/main/app/client/widgets/ChoiceEditor.js
159
+ */
160
+ /** One selectable choice for UI (value stored in the cell is `value`). */
161
+ type GristChoiceListEntry = {
162
+ value: string;
163
+ label: string;
164
+ fillColor?: string;
165
+ textColor?: string;
166
+ };
167
+ /**
168
+ * Parse a cell value from `_grist_Tables_column.widgetOptions` into a plain object.
169
+ */
170
+ declare function parseGristWidgetOptionsCell(raw: unknown): Record<string, unknown> | undefined;
171
+ /**
172
+ * Normalizes Grist Choice / ChoiceList widgetOptions into a flat list for dropdowns.
173
+ * `choices` entries are string labels (the stored cell value). Per-choice styling
174
+ * lives in `choiceOptions[label]`.
175
+ */
176
+ declare function normalizeGristChoiceListEntries(widgetOptions: Record<string, unknown> | undefined): GristChoiceListEntry[];
177
+
178
+ /**
179
+ * Encoding helpers for Grist cell values.
180
+ *
181
+ * Grist sends some types as marshalled tuples or numeric epochs. This file
182
+ * exposes pure decode/encode functions so widget code never has to spelunk
183
+ * Grist's wire format.
184
+ *
185
+ * References: Grist `grist/RowRecord` and `grist/DocActions` typings.
186
+ */
187
+
188
+ /** `["E", "ErrorClass", "message", traceback?]` — Grist error sentinel. */
189
+ type GristEncodedError = ["E", string, string?, string?];
190
+ /** `["L", ...items]` — list (used for ChoiceList, RefList, Attachments). */
191
+ type GristEncodedList = ["L", ...unknown[]];
192
+ /** `["D", epochSeconds, "tz/Name"]` — DateTime with timezone. */
193
+ type GristEncodedDateTime = ["D", number, string];
194
+ /** `["d", epochSeconds]` — Date (no time). */
195
+ type GristEncodedDate = ["d", number];
196
+ /** `["R", tableId, rowId]` — explicit reference. */
197
+ type GristEncodedRef = ["R", string, number];
198
+ /** `["r", rowId]` — bare reference (when table is contextual). */
199
+ type GristEncodedBareRef = ["r", number];
200
+ /** `["P", encoded]` — pending marker. */
201
+ type GristEncodedPending = ["P"];
202
+ type GristDecodedValue = null | string | number | boolean | Date | GristDecodedValue[] | {
203
+ __error: true;
204
+ type: string;
205
+ message?: string;
206
+ traceback?: string;
207
+ } | {
208
+ __ref: true;
209
+ tableId?: string;
210
+ rowId: number;
211
+ };
212
+ /**
213
+ * Normalises a Grist `fetchTable` cell that points at a row in another table.
214
+ * Most payloads use a bare numeric row id, but `Ref:*` values may appear as
215
+ * `["R", tableId, rowId]` or `["r", rowId]` (same shape as {@link decodeGristValue}).
216
+ */
217
+ declare function coerceGristDocApiRefRowId(value: unknown): number | undefined;
218
+ /**
219
+ * Decodes a Grist cell value into an idiomatic JS value.
220
+ *
221
+ * Pass the column's metadata (from `useGristSchema` or `_grist_Tables_column`)
222
+ * for type-aware decoding (e.g. `Date` columns return `Date` even when stored as a number).
223
+ */
224
+ declare function decodeGristValue(value: unknown, column?: GristReplicaColumn): GristDecodedValue;
225
+ /** Convenience: true when the cell is a Grist error sentinel. */
226
+ declare function isGristCellError(value: unknown): value is GristEncodedError;
227
+ /**
228
+ * Encodes a JS value into Grist's expected wire form for a given column type.
229
+ *
230
+ * Use before passing values to `applyUserActions` or `TableOperations.update`
231
+ * for `Date`, `DateTime`, `Ref`, `RefList`, and `ChoiceList` columns.
232
+ */
233
+ declare function encodeGristValue(value: unknown, column?: GristReplicaColumn): unknown;
234
+
235
+ type ValidateColumnMappingsResult = {
236
+ ok: boolean;
237
+ /**
238
+ * `true` while the host has not yet reported column mappings (e.g. between
239
+ * `grist.ready()` resolving and the first `onRecord` / `onRecords` callback,
240
+ * or before `sectionApi.mappings()` returns). Callers should not gate UI or
241
+ * emit mapping alerts while pending.
242
+ */
243
+ pending?: boolean;
244
+ /** Logical names of required columns the user has not yet mapped. */
245
+ missing: string[];
246
+ /** Logical names of `allowMultiple` columns mapped to an empty list. */
247
+ emptyMultiples: string[];
248
+ };
249
+ /**
250
+ * Verifies that the current Grist mappings cover every required column declared
251
+ * in `grist.ready({ columns })`.
252
+ *
253
+ * Use this before reading `mappedRecord` so you can render a "please configure
254
+ * the widget" prompt instead of a confusing `null`.
255
+ */
256
+ declare function validateColumnMappings(spec: GristColumnsToMap | undefined | null, mappings: GristWidgetColumnMap | null | undefined): ValidateColumnMappingsResult;
257
+
258
+ /**
259
+ * Pure projections from the handshake snapshot for boundary / shell UI.
260
+ *
261
+ * Blocking states (`booting`, `unavailable`, `error`) map to full-screen chrome
262
+ * via `<GristBoundary>`. Non-blocking degradations stay on the alert path
263
+ * ({@link getGristSdkAlertDescriptors}).
264
+ */
265
+
266
+ type GristBoundaryBlockingKind = "booting" | "unavailable" | "error";
267
+ type GristBoundaryBootPhase = "idle" | "detecting" | "negotiating" | "generic";
268
+ type GristBoundaryView = {
269
+ mode: "blocking";
270
+ kind: GristBoundaryBlockingKind;
271
+ bootPhase?: GristBoundaryBootPhase;
272
+ title: string;
273
+ message: string;
274
+ showRetry: boolean;
275
+ } | {
276
+ mode: "ready";
277
+ };
278
+ /**
279
+ * Human-readable boot label from lifecycle phase (for spinners / progress UI).
280
+ */
281
+ declare function deriveBoundaryBootLabel(snapshot: GristWidgetSnapshot): string;
282
+ declare function deriveBoundaryBootPhase(snapshot: GristWidgetSnapshot): GristBoundaryBootPhase;
283
+ /**
284
+ * Turn internal handshake errors into short, actionable copy for `<GristBoundary>`.
285
+ */
286
+ declare function formatBoundaryUserMessage(raw: string | null, snapshot: GristWidgetSnapshot): string;
287
+ /**
288
+ * Classify how `<GristBoundary>` should render: full-screen blocking vs children.
289
+ */
290
+ declare function deriveBoundaryView(snapshot: GristWidgetSnapshot): GristBoundaryView;
291
+ /** Copy for `gate="canRender"` while column mappings are not yet usable. */
292
+ declare const GRIST_BOUNDARY_PREPARING_COPY: {
293
+ readonly title: "Map your columns";
294
+ readonly message: "Open the widget settings in Grist (Creator Panel → Custom widget) and connect each required column to your table.";
295
+ };
296
+
297
+ type GristWidgetMode = "empty" | "row" | "new-row";
298
+ type UseGristSelectionOptions = {
299
+ columns?: GristColumnsToMap;
300
+ subscribeToWidgetOptions?: boolean;
301
+ subscribeToNewRecord?: boolean;
302
+ };
303
+ type UseGristSelectionResult<TRow = Record<string, unknown>, TMapped = Record<string, unknown>> = {
304
+ record: GristRowRecord<TRow> | null;
305
+ records: GristRowRecord<TRow>[] | null;
306
+ mappedRecord: TMapped | null;
307
+ mappings: GristWidgetColumnMap;
308
+ recordsMappings: GristWidgetColumnMap | null;
309
+ columnMappingStatus: ValidateColumnMappingsResult;
310
+ mode: GristWidgetMode;
311
+ resolveMappedColumnId: (logicalFieldName: string) => string;
312
+ mapBack: (patch: Partial<TMapped>) => Record<string, unknown>;
313
+ mapBackSkipped: readonly string[];
314
+ isNewRecord: boolean;
315
+ newRecordMappings: GristWidgetColumnMap | null;
316
+ widgetOptions: Record<string, unknown> | null;
317
+ widgetInteraction: GristWidgetInteraction | null;
318
+ };
319
+
320
+ /**
321
+ * Minimal widget slice for deriving non-fatal SDK callouts. Any
322
+ * {@link import("../use-grist").UseGristResult} satisfies this.
323
+ */
324
+ type GristSdkAlertsWidgetSlice = {
325
+ status: GristWidgetStatus;
326
+ columnMappingStatus: ValidateColumnMappingsResult;
327
+ actionError: string | null;
328
+ /**
329
+ * Last access-insufficient error from a read method (`fetchTable`, etc.).
330
+ * When set and matching the access-error pattern, an "access-insufficient"
331
+ * alert is emitted — same as for `actionError`.
332
+ */
333
+ readError?: string | null;
334
+ /**
335
+ * Logical column names that the most recent `mapBack(...)` call could not
336
+ * reverse-map (e.g. `allowMultiple` columns where one logical name resolves
337
+ * to several real columns).
338
+ */
339
+ mapBackSkipped?: readonly string[];
340
+ /** Selection mode from `useGrist()` — used for section-not-linked detection. */
341
+ mode?: GristWidgetMode;
342
+ /** `onOptions` settings from Grist (`InteractionOptions`). */
343
+ widgetInteraction?: GristWidgetInteraction | null;
344
+ /**
345
+ * Alert kinds suppressed via `UseGristOptions.suppressAlerts`.
346
+ * Consumed automatically by `useGristSdkAlertDescriptors`.
347
+ */
348
+ suppressAlerts?: readonly GristSdkAlertKind[];
349
+ /**
350
+ * Whether the widget declared `allowSelectBy: true` — used to distinguish
351
+ * "section-not-linked" (expects incoming link) from "source-not-wired"
352
+ * (expects to drive other sections).
353
+ */
354
+ allowSelectBy?: boolean;
355
+ };
356
+ type GristSdkAlertKind = "column-mapping" | "mapping-pending" | "mapping-unreported" | "link-stale" | "section-not-linked" | "source-not-wired" | "current-table-error" | "action-error" | "access-insufficient" | "map-back-skip";
357
+ /** Classic callout level for host styling: info / warning / error. */
358
+ type GristSdkAlertSeverity = "info" | "warning" | "error";
359
+ type GristSdkAlertDescriptor = {
360
+ id: string;
361
+ kind: GristSdkAlertKind;
362
+ severity: GristSdkAlertSeverity;
363
+ title: string;
364
+ /** Suggested WAI-ARIA role for the host shell. */
365
+ ariaRole: "status" | "alert";
366
+ message: string;
367
+ };
368
+ type GetGristSdkAlertDescriptorsOptions = {
369
+ /**
370
+ * Handshake snapshot from `useGristHandshake()` / the provider manager.
371
+ * Enables link-stale, mapping-unreported, and current-table alerts that are
372
+ * not visible on the widget slice alone.
373
+ */
374
+ snapshot?: GristWidgetSnapshot;
375
+ /** Appended to {@link formatColumnMappingAlertMessage} when a mapping alert is emitted. */
376
+ columnMappingHint?: string;
377
+ /** Appended to the map-back-skip message. */
378
+ mapBackHint?: string;
379
+ /** Override copy for {@link formatMappingPendingAlertMessage}. */
380
+ mappingPendingHint?: string;
381
+ /** Appended to {@link formatSectionNotLinkedAlertMessage}. */
382
+ sectionNotLinkedHint?: string;
383
+ /** Appended to {@link formatSourceNotWiredAlertMessage}. */
384
+ sourceNotWiredHint?: string;
385
+ /** Appended to {@link formatAccessInsufficientMessage}. */
386
+ accessInsufficientHint?: string;
387
+ /**
388
+ * Alert kinds to omit from the output. Useful for widgets that intentionally
389
+ * operate without a link source (`["section-not-linked"]`) or handle certain
390
+ * conditions in their own UI.
391
+ */
392
+ suppressKinds?: readonly GristSdkAlertKind[];
393
+ };
394
+ /** Default alert title for shadcn / toast shells. */
395
+ declare function getGristSdkAlertTitle(kind: GristSdkAlertKind): string;
396
+ /** Suggested severity for host styling (destructive vs muted). */
397
+ declare function getGristSdkAlertSeverity(kind: GristSdkAlertKind): GristSdkAlertSeverity;
398
+ /**
399
+ * Human-readable text for an incomplete column mapping (when
400
+ * `columnMappingStatus.ok` is false).
401
+ */
402
+ declare function formatColumnMappingAlertMessage(status: ValidateColumnMappingsResult, hint?: string): string;
403
+ declare function formatMappingPendingAlertMessage(hint?: string): string;
404
+ declare function formatMappingUnreportedAlertMessage(hint?: string): string;
405
+ declare function formatLinkStaleAlertMessage(snapshot: GristWidgetSnapshot): string;
406
+ /**
407
+ * True when Grist reports this section is not a link target (no selector drives
408
+ * the cursor / `onRecord` stream). Requires `linking` on `widgetInteraction` so
409
+ * older hosts do not trigger false positives.
410
+ */
411
+ declare function isWidgetSectionNotLinked(interaction: GristWidgetInteraction | null | undefined): boolean;
412
+ declare function formatSectionNotLinkedAlertMessage(hint?: string): string;
413
+ declare function formatSourceNotWiredAlertMessage(hint?: string): string;
414
+ /**
415
+ * Non-fatal SDK messages to show while `status === "ready"` (e.g. incomplete
416
+ * mappings, stale link, or `actionError` when not promoted to `status === "error"`).
417
+ * Host apps map each descriptor to their own UI (shadcn Alert, toast, etc.).
418
+ *
419
+ * Pass `options.snapshot` (from `useGristHandshake()` or the provider manager)
420
+ * for FSM-only signals: link stale, mapping unreported, current-table errors.
421
+ */
422
+ declare function getGristSdkAlertDescriptors(widget: GristSdkAlertsWidgetSlice, options?: GetGristSdkAlertDescriptorsOptions): GristSdkAlertDescriptor[];
423
+ /**
424
+ * Heuristic: returns `true` when `actionError` looks like it was caused by
425
+ * insufficient access rights rather than a domain / schema error.
426
+ */
427
+ declare function isAccessInsufficientError(message: string): boolean;
428
+ declare function formatAccessInsufficientMessage(hint?: string): string;
429
+
430
+ type GristWidgetActionStatus = "idle" | "running" | "error";
431
+ type UseGristTableOpsBoundResult = {
432
+ table: GristTableOperations;
433
+ getTable: (tableId: string) => GristTableOperations;
434
+ actionStatus: GristWidgetActionStatus;
435
+ actionError: string | null;
436
+ applyActions: (actions: GristUserActionTuple[], applyOptions?: GristApplyUserActionsOptions) => Promise<unknown>;
437
+ };
438
+
439
+ type GristTheme = "light" | "dark";
440
+ type UseGristThemeResult = {
441
+ theme: GristTheme | null;
442
+ };
443
+
444
+ type UseGristCurrentTableResult = {
445
+ currentTableId: string | null;
446
+ currentTableLoading: boolean;
447
+ refreshCurrentTable: () => Promise<void>;
448
+ tableError: string | null;
449
+ };
450
+
451
+ type GristCoreContextValue = UseGristCoreResult & {
452
+ tableError: string | null;
453
+ };
454
+ type GristStatusSliceValue = GristCoreContextValue & UseGristCurrentTableResult;
455
+
456
+ type ComposeGristWidgetOptions = UseGristCoreOptions & UseGristSelectionOptions & {
457
+ /**
458
+ * Alert kinds that should never be emitted for this widget.
459
+ * E.g. `["section-not-linked"]` for widgets that don't need a link source.
460
+ */
461
+ suppressAlerts?: GristSdkAlertKind[];
462
+ };
463
+
464
+ type UseGristOptions = ComposeGristWidgetOptions;
465
+ /**
466
+ * The full Grist widget state and API surface.
467
+ *
468
+ * **Method stability:** all function-typed fields (`fetchTable`, `listTables`,
469
+ * `patchWidgetOptions`, `getTable`, etc.) are `useCallback`-wrapped internally
470
+ * and **referentially stable** as long as the underlying `docApi` hasn't changed.
471
+ * You can safely use individual methods in React dependency arrays:
472
+ *
473
+ * ```tsx
474
+ * // GOOD — w.listTables is stable, effect only runs once
475
+ * useEffect(() => { void w.listTables().then(setTables) }, [w.listTables])
476
+ *
477
+ * // BAD — w is a new object whenever any Grist state changes (record, options, …)
478
+ * useEffect(() => { void w.listTables().then(setTables) }, [w])
479
+ * ```
480
+ *
481
+ * The `UseGristResult` object itself is **not** referentially stable — it updates
482
+ * whenever any reactive field changes (e.g. `record`, `widgetOptions`, `mode`).
483
+ * Do **not** use the whole object as a `useEffect` / `useMemo` dependency.
484
+ */
485
+ type UseGristResult<TRow = Record<string, unknown>, TMapped = Record<string, unknown>> = {
486
+ /** @access `"none"` — Connection state. */
487
+ status: GristWidgetStatus;
488
+ /** @access `"none"` — `true` if the page is inside a Grist iframe. */
489
+ isAvailable: boolean | null;
490
+ /** @access `"none"` — Convenience for `status === "ready"`. */
491
+ isReady: boolean;
492
+ /** @access `"none"` — Connection-level error string. */
493
+ error: string | null;
494
+ /**
495
+ * Handshake-derived gates (`canRender`, `canWriteRecords`, …).
496
+ * Prefer `capabilities.canRender` over re-deriving from `columnMappingStatus` alone.
497
+ * @access `"none"`
498
+ */
499
+ capabilities: GristCapabilities;
500
+ /** @access `"none"` — Re-run the handshake from scratch. */
501
+ reload: () => Promise<void>;
502
+ /** @access `"none"` — Resolved Grist theme (`"light" | "dark"`) or `null` before ready. */
503
+ theme: GristTheme | null;
504
+ /** @access `"read table"` — Currently selected row (raw column ids). */
505
+ record: GristRowRecord<TRow> | null;
506
+ /** @access `"read table"` — All visible rows in the section (raw column ids). */
507
+ records: GristRowRecord<TRow>[] | null;
508
+ /** @access `"read table"` — Selected row with logical column names. `null` if required mappings are missing. */
509
+ mappedRecord: TMapped | null;
510
+ /** @access `"read table"` — Logical → real column id map for the single-record stream. */
511
+ mappings: GristWidgetColumnMap;
512
+ /** @access `"read table"` — Logical → real column id map for the multi-record stream. */
513
+ recordsMappings: GristWidgetColumnMap | null;
514
+ /** @access `"read table"` — Required-column gating result. */
515
+ columnMappingStatus: ValidateColumnMappingsResult;
516
+ /** @access `"read table"` — Derived from selection state: `"empty"`, `"row"`, or `"new-row"`. */
517
+ mode: GristWidgetMode;
518
+ /** @access `"read table"` — One-shot column resolution (returns `name` as a fallback). */
519
+ resolveMappedColumnId: (logicalFieldName: string) => string;
520
+ /** @access `"read table"` — Reverse-map a logical-name patch to real column ids for writes. */
521
+ mapBack: (patch: Partial<TMapped>) => Record<string, unknown>;
522
+ /**
523
+ * Logical column names that the most recent `mapBack(...)` call could not
524
+ * reverse-map (typically `allowMultiple` columns).
525
+ *
526
+ * Used by {@link import("./helpers/grist-sdk-alerts").getGristSdkAlertDescriptors}
527
+ * to surface a non-fatal alert.
528
+ * @access `"read table"`
529
+ */
530
+ mapBackSkipped: readonly string[];
531
+ /** @access `"read table"` — `true` when the cursor is on the new-row placeholder. */
532
+ isNewRecord: boolean;
533
+ /** @access `"read table"` — Logical → real map for the new-row placeholder. */
534
+ newRecordMappings: GristWidgetColumnMap | null;
535
+ /** @access `"read table"` — `onOptions` payload from Grist, includes `access_level`. */
536
+ widgetInteraction: GristWidgetInteraction | null;
537
+ /** @access `"read table"` — Current section's table id. */
538
+ currentTableId: string | null;
539
+ /** @access `"read table"` — `true` while the SDK re-reads `selectedTable.getTableId()`. */
540
+ currentTableLoading: boolean;
541
+ /** @access `"read table"` — Force a re-read of the current table id. */
542
+ refreshCurrentTable: () => Promise<void>;
543
+ /**
544
+ * Last access-insufficient error from a read method (`fetchTable`, `listColumns`, …).
545
+ * `null` when no error or after a successful call clears it.
546
+ * Consumed by {@link import("./helpers/grist-sdk-alerts").getGristSdkAlertDescriptors}
547
+ * to surface the "access-insufficient" alert.
548
+ * @access `"none"`
549
+ */
550
+ readError: string | null;
551
+ /** @access `"full"` — Raw columnar payload for any table. Requires full document access. */
552
+ fetchTable: (tableId: string) => Promise<GristColumnarTable>;
553
+ /** @access `"full"` — Row-shaped, decoded, optionally safe-parsed read of any table. Requires full document access. */
554
+ fetchTableRows: {
555
+ <T extends Record<string, unknown> = Record<string, unknown>>(tableId: string, options: FetchGristTableRowsOptions & {
556
+ safeParse: true | Omit<SafeParseGristTableDataOptions, "columns" | "order">;
557
+ }): Promise<GristRowRecord<{
558
+ [K in keyof T]: GristSafeParseCellResult<T[K]> | null;
559
+ }>[]>;
560
+ <T extends Record<string, unknown> = Record<string, unknown>>(tableId: string, options?: FetchGristTableRowsOptions): Promise<GristRowRecord<T>[]>;
561
+ };
562
+ /** @access `"full"` — Fetch a single row by id from any table. Requires full document access. */
563
+ fetchRow: <T = Record<string, unknown>>(tableId: string, rowId: number) => Promise<GristRowRecord<T> | null>;
564
+ /** @access `"read table"` — List table ids (system/hidden tables filtered by default). */
565
+ listTables: (options?: ListTablesOptions) => Promise<string[]>;
566
+ /** @access `"full"` — Column metadata without fetching rows. Requires full document access. */
567
+ listColumns: (tableId: string, options?: ListColumnsOptions) => Promise<GristColumnInfo[]>;
568
+ /** @access `"read table"` — Document name. */
569
+ getDocName: () => Promise<string>;
570
+ /** @access `"full"` — Build a replica document snapshot from the live doc API. Requires full document access. */
571
+ buildReplicaDocumentFromDocApi: (options?: BuildReplicaDocumentFromDocApiOptions) => Promise<GristReplicaDocument>;
572
+ /** @access `"read table"` — Raw columnar read of the current section. */
573
+ fetchSelectedTable: (fetchOptions?: GristFetchSelectedOptions) => Promise<GristColumnarTable>;
574
+ /** @access `"read table"` — Single row from the current section. */
575
+ fetchSelectedRecord: (rowId: number, fetchOptions?: GristFetchSelectedOptions) => Promise<Record<string, unknown>>;
576
+ /** @access `"full"` — CRUD operations on the current table (`create`, `update`, `upsert`, `destroy`). */
577
+ table: GristTableOperations;
578
+ /** @access `"full"` — Memoized CRUD operations for any table by id. */
579
+ getTable: (tableId: string) => GristTableOperations;
580
+ /** @access `"full"` — Last write status (`"idle"`, `"running"`, `"error"`). */
581
+ actionStatus: GristWidgetActionStatus;
582
+ /** @access `"full"` — Last write error message. */
583
+ actionError: string | null;
584
+ /** @access `"full"` — Apply user-action tuples atomically (schema + data mutations). */
585
+ applyActions: (actions: GristUserActionTuple[], applyOptions?: GristApplyUserActionsOptions) => Promise<unknown>;
586
+ /** @access `"read table"` — Current widget options from Grist's `onOptions` stream. */
587
+ widgetOptions: Record<string, unknown> | null;
588
+ /** @access `"read table"` — Fetch the current widget options imperatively. */
589
+ getWidgetOptions: () => Promise<Record<string, unknown> | null>;
590
+ /** @access `"read table"` — Fetch a single widget option by key. */
591
+ getWidgetOption: (key: string) => Promise<unknown>;
592
+ /** @access `"full"` — Set a single widget option. */
593
+ setWidgetOption: (key: string, value: unknown) => Promise<void>;
594
+ /** @access `"full"` — Replace all widget options. */
595
+ setWidgetOptions: (next: Record<string, unknown>) => Promise<void>;
596
+ /** @access `"full"` — Merge a patch into existing widget options. */
597
+ patchWidgetOptions: (patch: Record<string, unknown>) => Promise<void>;
598
+ /** @access `"full"` — Remove all widget options. */
599
+ clearWidgetOptions: () => Promise<void>;
600
+ /** @access `"read table"` — Move the host cursor to a row / field / section. */
601
+ setCursorPosition: (pos: GristCursorPos) => Promise<void>;
602
+ /** @access `"read table"` — Set the widget's linked row selection (requires `allowSelectBy`). */
603
+ setLinkedRowSelection: (rowIds: null | number[]) => Promise<void>;
604
+ /** @access `"full"` — Signed download URL for an attachment. */
605
+ getAttachmentUrl: (attachmentId: string, options?: {
606
+ readOnly?: boolean;
607
+ }) => Promise<string>;
608
+ /** @access `"full"` — Fetch an attachment as a base64-encoded string. */
609
+ fetchAttachmentBase64: (attachmentId: string, options?: {
610
+ readOnly?: boolean;
611
+ }) => Promise<GristFetchedAttachment>;
612
+ /** @access `"full"` — Fetch an attachment as a Blob. */
613
+ fetchAttachmentBlob: (attachmentId: string, options?: {
614
+ readOnly?: boolean;
615
+ }) => Promise<GristFetchedAttachmentBlob>;
616
+ /** @access `"full"` — Obtain a short-lived access token for the Grist REST API. */
617
+ getAccessToken: (options?: {
618
+ readOnly?: boolean;
619
+ }) => Promise<GristAccessToken>;
620
+ /** @access `"full"` — `fetch()` with the doc access token attached. Path is relative to the document API root. */
621
+ fetchWithAuth: (path: string, init?: RequestInit & {
622
+ readOnly?: boolean;
623
+ }) => Promise<Response>;
624
+ /** @access `"full"` — Upload a file via `POST /attachments` (returns attachment ids). */
625
+ uploadAttachment: (file: Blob | File, options?: {
626
+ fileName?: string;
627
+ }) => Promise<GristAttachmentUploadResult>;
628
+ /** @access `"read table"` — Re-issue `grist.ready()` with new options. */
629
+ configure: (options: GristReadyOptions) => Promise<void>;
630
+ /** @access `"read table"` — Force a re-read of `sectionApi.mappings()`. */
631
+ refreshMappings: () => Promise<GristWidgetColumnMap | null>;
632
+ /**
633
+ * Alert kinds suppressed via `UseGristOptions.suppressAlerts`.
634
+ * Consumed automatically by `useGristSdkAlertDescriptors`.
635
+ * @access `"none"`
636
+ */
637
+ suppressAlerts?: readonly GristSdkAlertKind[];
638
+ /**
639
+ * Whether the widget declared `allowSelectBy: true` in its options.
640
+ * Used by the alert system to distinguish "section-not-linked" from "source-not-wired".
641
+ * @access `"none"`
642
+ */
643
+ allowSelectBy?: boolean;
644
+ };
645
+
646
+ /**
647
+ * React hook: widget slice + optional handshake snapshot for
648
+ * {@link getGristSdkAlertDescriptors}.
649
+ */
650
+ declare function useGristSdkAlertDescriptors(widget?: GristSdkAlertsWidgetSlice | UseGristResult, options?: GetGristSdkAlertDescriptorsOptions): GristSdkAlertDescriptor[];
651
+
652
+ type GristWidgetProviderProps = {
653
+ options?: UseGristOptions;
654
+ children: ReactNode;
655
+ };
656
+ /**
657
+ * Sets up Grist once at the app root. Prefer slice hooks (`useGristSelection`,
658
+ * `useGristWrites`, …) in large widgets; use `useGristContext()` when you need everything.
659
+ *
660
+ * Owns a {@link GristHandshakeManager} and mounts the slice / full-result context
661
+ * tree underneath it so `useRpcHeartbeatCoalesce()` in slice hooks sees the manager
662
+ * (ordering required — see `tests/sdk/handshake-rpc-coalesce.test.tsx`).
663
+ */
664
+ declare function GristWidgetProvider({ options, children }: GristWidgetProviderProps): react_jsx_runtime.JSX.Element;
665
+ /**
666
+ * Access the full `UseGristResult` from inside a `<GristWidgetProvider>`.
667
+ *
668
+ * The returned object updates whenever any Grist state changes (record selection,
669
+ * widget options, etc.). Individual methods on the result (e.g. `w.fetchTable`,
670
+ * `w.listTables`) are referentially stable and safe to use in `useEffect` deps.
671
+ * See `UseGristResult` JSDoc for details.
672
+ */
673
+ declare function useGristContext<TRow = Record<string, unknown>, TMapped = Record<string, unknown>>(): UseGristResult<TRow, TMapped>;
674
+ declare function useGristOptional<TRow = Record<string, unknown>, TMapped = Record<string, unknown>>(): UseGristResult<TRow, TMapped> | null;
675
+
676
+ /**
677
+ * Primary Grist hook — use inside `<GristWidgetProvider>` via `useGristContext()`,
678
+ * or standalone in a single-leaf widget.
679
+ */
680
+ declare function useGrist<TRow = Record<string, unknown>, TMapped = Record<string, unknown>>(options?: UseGristOptions): UseGristResult<TRow, TMapped>;
681
+
682
+ /**
683
+ * Slice subscriber: status + current-table info. Re-renders on status, error,
684
+ * `currentTableId`, or `currentTableLoading` changes only.
685
+ *
686
+ * Must be called inside `<GristWidgetProvider>` — for standalone usage use
687
+ * `useGrist()` directly.
688
+ */
689
+ declare function useGristStatus(): GristStatusSliceValue;
690
+ /**
691
+ * Slice subscriber for the selection / mappings / widget-options stream.
692
+ * Must be called inside `<GristWidgetProvider>`.
693
+ */
694
+ declare function useGristSelection<TRow = Record<string, unknown>, TMapped = Record<string, unknown>>(): UseGristSelectionResult<TRow, TMapped>;
695
+ /**
696
+ * Slice subscriber for writes (`table`, `getTable`, `applyActions`, `actionStatus`).
697
+ * Must be called inside `<GristWidgetProvider>`.
698
+ */
699
+ declare function useGristWrites(): UseGristTableOpsBoundResult;
700
+ /**
701
+ * Slice subscriber for the host theme. Must be called inside `<GristWidgetProvider>`.
702
+ */
703
+ declare function useGristTheme(): UseGristThemeResult;
704
+
705
+ type GristBoundaryGate = "ready" | "canRender";
706
+ type GristBoundaryProps = {
707
+ /**
708
+ * Pass an explicit widget instance (e.g. when not using `<GristWidgetProvider>`).
709
+ * Otherwise the boundary reads from the nearest provider.
710
+ */
711
+ widget?: UseGristResult;
712
+ /**
713
+ * When `"canRender"`, children render only after mappings are usable
714
+ * (`capabilities.canRender`). Use for widgets that require mapped columns.
715
+ */
716
+ gate?: GristBoundaryGate;
717
+ /** Rendered while `grist.ready` is in flight. */
718
+ bootingFallback?: ReactNode;
719
+ /** Shown when `gate="canRender"` and mappings are not yet usable. */
720
+ preparingFallback?: ReactNode;
721
+ /** Rendered when the widget is not embedded in Grist (e.g. opened directly). */
722
+ unavailableFallback?: ReactNode | ((actions: GristBoundaryActions) => ReactNode);
723
+ /** Rendered on any error from `useGristReady`, subscriptions, or actions. */
724
+ errorFallback?: (error: string, actions: GristBoundaryActions) => ReactNode;
725
+ /**
726
+ * Delay before showing "unavailable" UI. Helps avoid false negatives on slow
727
+ * networks where the plugin API handshake arrives late.
728
+ */
729
+ unavailableGraceMs?: number;
730
+ children: ReactNode;
731
+ };
732
+ type GristBoundaryActions = {
733
+ reload: () => Promise<void>;
734
+ isReloading: boolean;
735
+ };
736
+ type GristBoundaryScreenProps = {
737
+ title: string;
738
+ message: string;
739
+ /** Affects WAI-ARIA role only (`alert` vs `status`); copy uses the same neutral styles. */
740
+ tone?: "default" | "error";
741
+ showRetry?: boolean;
742
+ actions?: GristBoundaryActions;
743
+ retryLabel?: string;
744
+ retryBusyLabel?: string;
745
+ };
746
+ /** Centered full-viewport chrome for booting / unavailable / error states. */
747
+ declare function GristBoundaryScreen({ title, message, tone, showRetry, actions, retryLabel, retryBusyLabel, }: GristBoundaryScreenProps): react_jsx_runtime.JSX.Element;
748
+ /**
749
+ * Standardised loading / unavailable / error chrome for a Grist widget.
750
+ *
751
+ * ```tsx
752
+ * <GristWidgetProvider options={{ requiredAccess: "full" }}>
753
+ * <GristBoundary>
754
+ * <MyWidget />
755
+ * </GristBoundary>
756
+ * </GristWidgetProvider>
757
+ * ```
758
+ */
759
+ declare function GristBoundary({ widget, gate, bootingFallback, preparingFallback, unavailableFallback, errorFallback, unavailableGraceMs, children, }: GristBoundaryProps): react_jsx_runtime.JSX.Element;
760
+
761
+ type ColumnExcludeContext = {
762
+ tableId: string;
763
+ colId: string;
764
+ col: GristReplicaColumn;
765
+ };
766
+ type UseGristSchemaOptions = {
767
+ requiredAccess?: GristRequiredAccess;
768
+ tableId?: string;
769
+ excludeSystemTableData?: boolean;
770
+ /**
771
+ * How row bodies are included in the replica document.
772
+ * Default `schema+samples`.
773
+ */
774
+ replicaRowMode?: GristDocumentMode;
775
+ /** When `replicaRowMode` is `schema+samples`, max rows per table. Default 10. */
776
+ sampleRowLimit?: number;
777
+ /** Stored on the replica as `source` (e.g. for logging). */
778
+ source?: string;
779
+ } & GristNoiseColumnsOptions & {
780
+ extraExcludeColumn?: (ctx: ColumnExcludeContext) => boolean;
781
+ } & Pick<GristReadyOptions, "columns" | "allowSelectBy" | "hasCustomOptions" | "onEditOptions">;
782
+ /** Selected table slice with `tableId` for consumers that expect it on the object. */
783
+ type GristSchemaTableView = GristReplicaTable & {
784
+ tableId: string;
785
+ };
786
+ /** Options for `getDocumentJson` / `buildDocumentJson` on the return value of {@link useGristSchema}. */
787
+ type ReplicaDocumentJsonOptions = {
788
+ /** How row arrays appear in JSON. Default `full` (all rows currently on the document). */
789
+ includeRows?: ReplicaJsonIncludeRows;
790
+ /** Cap per table when `includeRows` is `samples`. Default 10. */
791
+ sampleRowLimit?: number;
792
+ space?: number;
793
+ };
794
+ type UseGristSchemaResult = {
795
+ isAvailable: boolean | null;
796
+ /** Canonical replica document. */
797
+ document: GristReplicaDocument | null;
798
+ /** Same reference as `document`. */
799
+ replicaDocument: GristReplicaDocument | null;
800
+ table: GristSchemaTableView | null;
801
+ documentJson: string | null;
802
+ getDocumentJson: (options?: ReplicaDocumentJsonOptions) => string | null;
803
+ buildDocumentJson: (document: GristReplicaDocument, options?: ReplicaDocumentJsonOptions) => string;
804
+ tableJson: string | null;
805
+ getTableJson: (options?: ReplicaDocumentJsonOptions) => string | null;
806
+ buildTableJson: (table: GristSchemaTableView, options?: ReplicaDocumentJsonOptions) => string;
807
+ isNoiseColumnId: (colId: string, col?: GristReplicaColumn) => boolean;
808
+ sortColumnIds: (colIds: string[], columns: Record<string, GristReplicaColumn>) => string[];
809
+ loading: boolean;
810
+ error: string | null;
811
+ reload: () => Promise<void>;
812
+ };
813
+ /**
814
+ * Grist replica-document hook: metadata + optional decoded `rows` per table.
815
+ */
816
+ declare function useGristSchema(options?: UseGristSchemaOptions): UseGristSchemaResult;
817
+
818
+ type UseWidgetMetadataInput = {
819
+ title: string;
820
+ description: string;
821
+ syncToParent?: boolean;
822
+ };
823
+ declare function useWidgetMetadata(input?: UseWidgetMetadataInput | null): void;
824
+
825
+ export { type BuildReplicaDocumentFromDocApiOptions, FetchGristTableRowsOptions, GRIST_BOUNDARY_PREPARING_COPY, type GetGristSdkAlertDescriptorsOptions, GristAccessToken, GristApplyUserActionsOptions, type GristAttachmentUploadResult, GristBoundary, type GristBoundaryActions, type GristBoundaryBlockingKind, type GristBoundaryBootPhase, type GristBoundaryGate, type GristBoundaryProps, GristBoundaryScreen, type GristBoundaryView, GristCapabilities, type GristChoiceListEntry, GristColumnInfo, GristColumnarTable, GristColumnsToMap, GristCursorPos, type GristDecodedValue, GristDocApi, GristDocumentMode, type GristEncodedAttachmentList, type GristEncodedBareRef, type GristEncodedDate, type GristEncodedDateTime, type GristEncodedError, type GristEncodedList, type GristEncodedPending, type GristEncodedRef, GristFetchSelectedOptions, type GristFetchedAttachment, type GristFetchedAttachmentBlob, GristFormulaKind, GristNoiseColumnsOptions, GristReadyOptions, GristReplicaColumn, GristReplicaDocument, GristReplicaRow, GristReplicaTable, GristRequiredAccess, GristRowRecord, GristSafeParseCellResult, type GristSchemaTableView, type GristSdkAlertDescriptor, type GristSdkAlertKind, type GristSdkAlertSeverity, type GristSdkAlertsWidgetSlice, GristTableOperations, type GristTheme, GristUserActionTuple, type GristWidgetActionStatus, GristWidgetColumnMap, GristWidgetInteraction, type GristWidgetMode, GristWidgetProvider, type GristWidgetProviderProps, GristWidgetStatus, ListColumnsOptions, ListTablesOptions, type ReplicaDocumentJsonOptions, type ReplicaJsonIncludeRows, type ReplicaTableColumnMetaLite, SafeParseGristTableDataOptions, type UseGristOptions, type UseGristResult, type UseGristSchemaOptions, type UseGristSchemaResult, type UseWidgetMetadataInput, type ValidateColumnMappingsResult, buildReplicaColumnsFromColumnar, buildReplicaDocumentFromDocApi, buildReplicaJsonPayload, coerceGristDocApiRefRowId, decodeGristValue, deriveBoundaryBootLabel, deriveBoundaryBootPhase, deriveBoundaryView, encodeGristValue, extractAttachmentIdsFromUploadPayload, extractFirstAttachmentIdFromUploadPayload, extractGristAttachmentId, extractGristAttachmentIdsFromCell, fetchAttachmentBase64, fetchAttachmentBase64ForCell, fetchAttachmentBlob, formatAccessInsufficientMessage, formatBoundaryUserMessage, formatColumnMappingAlertMessage, formatLinkStaleAlertMessage, formatMappingPendingAlertMessage, formatMappingUnreportedAlertMessage, formatSectionNotLinkedAlertMessage, formatSourceNotWiredAlertMessage, getAttachmentDownloadUrl, getAttachmentDownloadUrlForCell, getGristSdkAlertDescriptors, getGristSdkAlertSeverity, getGristSdkAlertTitle, gristAttachmentCellValue, gristAttachmentCellValues, inferGristFormulaKind, isAccessInsufficientError, isGristCellError, isWidgetSectionNotLinked, loadColumnMetadataByTable, mergeGristAttachmentCellValue, normalizeGristChoiceListEntries, normalizeReplicaDocumentInput, normalizeReplicaTableInput, orderedColumnIds, parseGristAttachmentUploadResponse, parseGristAttachmentUploadResponseIds, parseGristWidgetOptionsCell, resolveGristFormulaKind, serializeJsonFriendly, uploadGristAttachment, useGrist, useGristContext, useGristOptional, useGristSchema, useGristSdkAlertDescriptors, useGristSelection, useGristStatus, useGristTheme, useGristWrites, useWidgetMetadata, validateColumnMappings };