grist-widget-sdk 0.3.20 → 0.3.26

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 (38) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/dist/advanced.d.cts +3 -2
  3. package/dist/advanced.d.ts +3 -2
  4. package/dist/app.cjs +5176 -0
  5. package/dist/app.cjs.map +1 -0
  6. package/dist/app.d.cts +147 -0
  7. package/dist/app.d.ts +147 -0
  8. package/dist/app.js +527 -0
  9. package/dist/app.js.map +1 -0
  10. package/dist/chunk-PDGEZ24B.js +2366 -0
  11. package/dist/chunk-PDGEZ24B.js.map +1 -0
  12. package/dist/{create-grist-emulator-_3_JK7Rr.d.ts → create-grist-emulator-BCqp1BF9.d.ts} +2 -2
  13. package/dist/{create-grist-emulator-K-iUKUCZ.d.cts → create-grist-emulator-DBM8OSIR.d.cts} +2 -2
  14. package/dist/emulator/testing.d.cts +2 -2
  15. package/dist/emulator/testing.d.ts +2 -2
  16. package/dist/emulator/transports.d.cts +3 -3
  17. package/dist/emulator/transports.d.ts +3 -3
  18. package/dist/emulator.d.cts +5 -5
  19. package/dist/emulator.d.ts +5 -5
  20. package/dist/index.d.cts +9 -500
  21. package/dist/index.d.ts +9 -500
  22. package/dist/index.js +57 -2291
  23. package/dist/index.js.map +1 -1
  24. package/dist/{inline-A8yaddmp.d.cts → inline-C7DkvuET.d.cts} +1 -1
  25. package/dist/{inline-B7QQeWul.d.ts → inline-DpcT8tV9.d.ts} +1 -1
  26. package/dist/{templates-CB_VwjEU.d.cts → templates-8k2LKoO-.d.cts} +1 -1
  27. package/dist/{templates-pRIXc2RR.d.ts → templates-DIwi_mvI.d.ts} +1 -1
  28. package/dist/{types-YcRfo7oy.d.cts → types-D3JxUCfL.d.cts} +1 -1
  29. package/dist/{types-YcRfo7oy.d.ts → types-D3JxUCfL.d.ts} +1 -1
  30. package/dist/{use-grist-widget-options-from-context-hl-NwOwP.d.ts → use-grist-reads-DUMvJgV7.d.ts} +3 -44
  31. package/dist/{use-grist-widget-options-from-context-Bbd5-f39.d.cts → use-grist-reads-DpjVuI0H.d.cts} +3 -44
  32. package/dist/use-grist-types-DdOLEJXN.d.cts +499 -0
  33. package/dist/use-grist-types-kwxoFeub.d.ts +499 -0
  34. package/dist/use-grist-widget-options-from-context-CGOlQ5Vc.d.cts +43 -0
  35. package/dist/use-grist-widget-options-from-context-CGOlQ5Vc.d.ts +43 -0
  36. package/package.json +15 -2
  37. package/tsconfig/app.json +38 -0
  38. package/tsconfig/node.json +36 -0
package/dist/index.d.ts CHANGED
@@ -1,136 +1,21 @@
1
- import { l as GristDocApi, m as GristFormulaKind, c as GristReplicaColumn, b as GristReplicaDocument, a as GristReplicaTable, n as GristReplicaRow, o as GristColumnsToMap, d as GristWidgetColumnMap, G as GristRowRecord, f as GristWidgetInteraction, k as GristTableOperations, p as GristApplyUserActionsOptions, j as GristFetchSelectedOptions, e as GristCursorPos, i as GristReadyOptions, q as GristRequiredAccess, r as GristDocumentMode } from './types-YcRfo7oy.js';
2
- export { s as GristColumnToMap, t as GristMinimalRecord, g as GristReplicaSelection, u as GristTableNewRecord, v as GristTableOpOptions, w as GristTableUpdateRecord, x as GristTableUpsertOptions, y as GristTableUpsertRecord, h as GristWidgetConfiguration, z as GristWidgetLinkingInfo } from './types-YcRfo7oy.js';
3
- import { a as GristWidgetStatus, b as GristUserActionTuple, U as UseGristCoreResult, c as UseGristCoreOptions, d as GristCapabilities, e as GristColumnarTable, F as FetchGristTableRowsOptions, S as SafeParseGristTableDataOptions, f as GristSafeParseCellResult, L as ListTablesOptions, g as ListColumnsOptions, h as GristColumnInfo, i as GristAccessToken, j as GristNoiseColumnsOptions } from './use-grist-widget-options-from-context-hl-NwOwP.js';
1
+ import { l as GristFormulaKind, c as GristReplicaColumn, b as GristReplicaDocument, a as GristReplicaTable, m as GristReplicaRow, n as GristRequiredAccess, o as GristDocumentMode, i as GristReadyOptions } from './types-D3JxUCfL.js';
2
+ export { p as GristApplyUserActionsOptions, q as GristColumnToMap, r as GristColumnsToMap, e as GristCursorPos, s as GristDocApi, j as GristFetchSelectedOptions, t as GristMinimalRecord, g as GristReplicaSelection, G as GristRowRecord, u as GristTableNewRecord, v as GristTableOpOptions, k as GristTableOperations, w as GristTableUpdateRecord, x as GristTableUpsertOptions, y as GristTableUpsertRecord, d as GristWidgetColumnMap, h as GristWidgetConfiguration, f as GristWidgetInteraction, z as GristWidgetLinkingInfo } from './types-D3JxUCfL.js';
3
+ import { G as GristSdkAlertsWidgetSlice, a as UseGristResult, b as GetGristSdkAlertDescriptorsOptions, c as GristSdkAlertDescriptor, U as UseGristOptions, d as UseGristSelectionResult, e as UseGristStatusResult, f as UseGristThemeResult, g as UseGristWritesResult } from './use-grist-types-kwxoFeub.js';
4
+ export { B as BuildReplicaDocumentFromDocApiOptions, h as GristAttachmentUploadResult, i as GristEncodedAttachmentList, j as GristFetchedAttachment, k as GristFetchedAttachmentBlob, l as GristSdkAlertKind, m as GristSdkAlertSeverity, n as GristTheme, o as GristWidgetActionStatus, p as GristWidgetMode, R as ReplicaTableColumnMetaLite, V as ValidateColumnMappingsResult, q as buildReplicaColumnsFromColumnar, r as buildReplicaDocumentFromDocApi, s as extractAttachmentIdsFromUploadPayload, t as extractFirstAttachmentIdFromUploadPayload, u as extractGristAttachmentId, v as extractGristAttachmentIdsFromCell, w as fetchAttachmentBase64, x as fetchAttachmentBase64ForCell, y as fetchAttachmentBlob, z as formatAccessInsufficientMessage, A as formatColumnMappingAlertMessage, C as formatLinkStaleAlertMessage, D as formatMappingPendingAlertMessage, E as formatMappingUnreportedAlertMessage, F as formatSectionNotLinkedAlertMessage, H as formatSourceNotWiredAlertMessage, I as getAttachmentDownloadUrl, J as getAttachmentDownloadUrlForCell, K as getGristSdkAlertDescriptors, L as getGristSdkAlertSeverity, M as getGristSdkAlertTitle, N as gristAttachmentCellValue, O as gristAttachmentCellValues, P as isAccessInsufficientError, Q as isWidgetSectionNotLinked, S as loadColumnMetadataByTable, T as mergeGristAttachmentCellValue, W as orderedColumnIds, X as parseGristAttachmentUploadResponse, Y as parseGristAttachmentUploadResponseIds, Z as uploadGristAttachment, _ as validateColumnMappings } from './use-grist-types-kwxoFeub.js';
5
+ import { a as GristNoiseColumnsOptions } from './use-grist-reads-DUMvJgV7.js';
4
6
  import { GristWidgetSnapshot } from './advanced.js';
5
- export { k as GristCellValue, l as GristColumnLike, m as GristSafeParseIssue, n as GristSafeParseIssueCode, o as GristSafeRefListValue, p as GristSafeRefValue, q as GristSafeTableCellIssue, r as GristSafeTableCellMeta, s as GristTableRowsOrder, t as SafeParseGristTableDataResult, u as SafeParseGristValuesOptions, v as UseGristWidgetOptionsFromContextConfig, w as UseGristWidgetOptionsFromContextResult, x as computeRowCount, y as decodeColumnarToReplicaRows, z as fetchGristRow, A as fetchGristTableRows, B as fetchWithGristAuth, C as findRowIndexById, D as getGristAccessToken, E as gristAddColumnAction, H as gristAddRecordAction, I as gristAddTableAction, J as gristAddVisibleColumnAction, K as gristBulkAddRecordAction, M as gristBulkRemoveRecordAction, N as gristBulkUpdateRecordAction, O as gristCellValueSchema, P as gristDuplicateTableAction, Q as gristModifyColumnAction, R as gristRemoveColumnAction, T as gristRemoveRecordAction, V as gristRemoveTableAction, W as gristRenameColumnAction, X as gristRenameTableAction, Y as gristReplaceTableDataAction, Z as gristSafeRefListValueSchema, _ as gristSafeRefValueSchema, $ as gristSetDocumentInfoAction, a0 as gristUpdateRecordAction, a1 as inferDisplayHelpersByRef, a2 as isGristNoiseColumn, a3 as materializeGristRowsFromColumnar, a4 as rowAtIndex, a5 as safeParseGristTableData, a6 as safeParseGristValues, a7 as safeParseRowsToDisplayRows, a8 as sortRowsByGristOrder, a9 as tableDataToRows, aa as useGristWidgetOptionsFromContext } from './use-grist-widget-options-from-context-hl-NwOwP.js';
7
+ export { F as FetchGristTableRowsOptions, b as GristAccessToken, c as GristCapabilities, d as GristCellValue, e as GristColumnInfo, f as GristColumnLike, g as GristColumnarTable, h as GristSafeParseCellResult, i as GristSafeParseIssue, j as GristSafeParseIssueCode, k as GristSafeRefListValue, l as GristSafeRefValue, m as GristSafeTableCellIssue, n as GristSafeTableCellMeta, o as GristTableRowsOrder, p as GristUserActionTuple, q as GristWidgetStatus, L as ListColumnsOptions, r as ListTablesOptions, S as SafeParseGristTableDataOptions, s as SafeParseGristTableDataResult, t as SafeParseGristValuesOptions, U as UseGristCoreOptions, u as UseGristCoreResult, v as computeRowCount, w as decodeColumnarToReplicaRows, x as fetchGristRow, y as fetchGristTableRows, z as fetchWithGristAuth, A as findRowIndexById, B as getGristAccessToken, C as gristAddColumnAction, D as gristAddRecordAction, E as gristAddTableAction, H as gristAddVisibleColumnAction, I as gristBulkAddRecordAction, J as gristBulkRemoveRecordAction, K as gristBulkUpdateRecordAction, M as gristCellValueSchema, N as gristDuplicateTableAction, O as gristModifyColumnAction, P as gristRemoveColumnAction, Q as gristRemoveRecordAction, R as gristRemoveTableAction, T as gristRenameColumnAction, V as gristRenameTableAction, W as gristReplaceTableDataAction, X as gristSafeRefListValueSchema, Y as gristSafeRefValueSchema, Z as gristSetDocumentInfoAction, _ as gristUpdateRecordAction, $ as inferDisplayHelpersByRef, a0 as isGristNoiseColumn, a1 as materializeGristRowsFromColumnar, a2 as rowAtIndex, a3 as safeParseGristTableData, a4 as safeParseGristValues, a5 as safeParseRowsToDisplayRows, a6 as sortRowsByGristOrder, a7 as tableDataToRows } from './use-grist-reads-DUMvJgV7.js';
6
8
  import * as react from 'react';
7
9
  import { ReactNode } from 'react';
10
+ export { U as UseGristWidgetOptionsFromContextConfig, a as UseGristWidgetOptionsFromContextResult, u as useGristWidgetOptionsFromContext } from './use-grist-widget-options-from-context-CGOlQ5Vc.js';
8
11
  import 'zod';
9
12
 
10
- type GristFetchedAttachment = {
11
- base64: string;
12
- contentType: string;
13
- };
14
- type GristFetchedAttachmentBlob = {
15
- blob: Blob;
16
- contentType: string;
17
- };
18
- /**
19
- * All attachment ids found in a Grist attachment cell value (ordered, deduped).
20
- * Attachment columns are usually an **array** of file refs; a single id or one JSON object is also supported.
21
- */
22
- declare function extractGristAttachmentIdsFromCell(value: unknown): string[];
23
- /** First attachment id in the cell, if any (see {@link extractGristAttachmentIdsFromCell}). */
24
- declare function extractGristAttachmentId(value: unknown): string | undefined;
25
- /**
26
- * Signed Grist download URL for a single attachment id (`getAccessToken` + query auth).
27
- */
28
- declare function getAttachmentDownloadUrl(docApi: GristDocApi, attachmentId: string, options?: {
29
- readOnly?: boolean;
30
- }): Promise<string>;
31
- /** URL for the `index`’th attachment in a cell value (0-based). */
32
- declare function getAttachmentDownloadUrlForCell(docApi: GristDocApi, cellValue: unknown, index: number, options?: {
33
- readOnly?: boolean;
34
- }): Promise<string | null>;
35
- /** Token + URL + fetch for one attachment id. */
36
- declare function fetchAttachmentBase64(docApi: GristDocApi, attachmentId: string, options?: {
37
- readOnly?: boolean;
38
- }): Promise<GristFetchedAttachment>;
39
- /** Download attachment bytes as a `Blob` (preferred for large files). */
40
- declare function fetchAttachmentBlob(docApi: GristDocApi, attachmentId: string, options?: {
41
- readOnly?: boolean;
42
- }): Promise<GristFetchedAttachmentBlob>;
43
- /** Download the `index`’th attachment in a cell (0-based). */
44
- declare function fetchAttachmentBase64ForCell(docApi: GristDocApi, cellValue: unknown, index: number, options?: {
45
- readOnly?: boolean;
46
- }): Promise<GristFetchedAttachment | null>;
47
-
48
- type GristEncodedAttachmentList = ["L", ...(number | string)[]];
49
- type GristAttachmentUploadResult = {
50
- /** All attachment ids returned by `POST /attachments`. */
51
- ids: string[];
52
- /** First id in `ids` (convenience for single-file uploads). */
53
- firstId: string;
54
- };
55
- /**
56
- * Parse the body of `POST /attachments` (widget or REST).
57
- * Grist returns a JSON array of attachment ids, e.g. `[42]` or `[101, 102]`.
58
- */
59
- declare function parseGristAttachmentUploadResponseIds(raw: string, options?: {
60
- strict?: boolean;
61
- }): string[];
62
- /**
63
- * First attachment id from an upload response (see {@link parseGristAttachmentUploadResponseIds}).
64
- */
65
- declare function parseGristAttachmentUploadResponse(raw: string, options?: {
66
- strict?: boolean;
67
- }): string;
68
- declare function extractAttachmentIdsFromUploadPayload(parsed: unknown, options?: {
69
- strict?: boolean;
70
- }): string[];
71
- /** @deprecated Prefer {@link extractAttachmentIdsFromUploadPayload}. */
72
- declare function extractFirstAttachmentIdFromUploadPayload(parsed: unknown): string | undefined;
73
- /** Wire value for an Attachments cell (Grist list encoding). */
74
- declare function gristAttachmentCellValues(attachmentIds: (string | number)[]): GristEncodedAttachmentList;
75
- /** Wire value for a single-file Attachments cell. */
76
- declare function gristAttachmentCellValue(attachmentId: string | number): GristEncodedAttachmentList;
77
- /**
78
- * Merge new attachment ids into an existing Attachments cell value (deduped, order preserved).
79
- */
80
- declare function mergeGristAttachmentCellValue(existingCell: unknown, newIds: (string | number)[]): GristEncodedAttachmentList;
81
- /**
82
- * Upload a file to the current document via `POST /attachments`.
83
- *
84
- * Uses `getAccessToken({ readOnly: false })` and `?auth=` (see Grist widget docs).
85
- * Requires document **full** access in the widget.
86
- */
87
- declare function uploadGristAttachment(docApi: GristDocApi, file: Blob | File, options?: {
88
- fileName?: string;
89
- }): Promise<GristAttachmentUploadResult>;
90
-
91
13
  declare function inferGristFormulaKind(isFormula: boolean, formulaTrimmed: string): GristFormulaKind;
92
14
  /** Use when `formulaKind` may be missing (e.g. older document builds). */
93
15
  declare function resolveGristFormulaKind(col: GristReplicaColumn): GristFormulaKind;
94
16
  /** Serialize cell values for JSON output. */
95
17
  declare function serializeJsonFriendly(value: unknown): unknown;
96
18
 
97
- type ReplicaTableColumnMetaLite = {
98
- colRef?: number;
99
- type?: string;
100
- label?: string;
101
- parentPos?: number;
102
- isFormula?: boolean;
103
- formula?: string;
104
- description?: string;
105
- widgetOptions?: Record<string, unknown>;
106
- displayColRef?: number;
107
- visibleColRef?: number;
108
- };
109
- declare function loadColumnMetadataByTable(docApi: GristDocApi): Promise<Map<string, Map<string, ReplicaTableColumnMetaLite>>>;
110
- declare function orderedColumnIds(data: Record<string, unknown[]>, metaByCol: Map<string, ReplicaTableColumnMetaLite>): string[];
111
- /** Build replica column metadata from columnar `fetchTable` + `_grist_Tables_column` maps. */
112
- declare function buildReplicaColumnsFromColumnar(data: Record<string, unknown[]>, colMeta: Map<string, ReplicaTableColumnMetaLite>): Record<string, GristReplicaColumn>;
113
- type BuildReplicaDocumentFromDocApiOptions = {
114
- /** When false (default), skip fetching row data for `tableId` starting with `_grist`. */
115
- includeSystemTableData?: boolean;
116
- /**
117
- * Row bodies: omit (`false`), first N (`samples`), or full decode (`full`).
118
- * Default `samples`.
119
- */
120
- includeRows?: false | "samples" | "full";
121
- /** Max rows per table when `includeRows` is `samples`. Default 10. */
122
- sampleRowLimit?: number;
123
- /** Set on the replica as `source` for host logging / provenance. */
124
- source?: string;
125
- };
126
- /**
127
- * Build {@link GristReplicaDocument} from a host `docApi`:
128
- * metadata from `_grist_Tables` / `_grist_Tables_column` when readable, plus optional decoded `rows`.
129
- *
130
- * Prefer {@link useGrist}'s `buildReplicaDocumentFromDocApi()` when you already use the primary hook.
131
- */
132
- declare function buildReplicaDocumentFromDocApi(docApi: GristDocApi, options?: BuildReplicaDocumentFromDocApiOptions): Promise<GristReplicaDocument>;
133
-
134
19
  /**
135
20
  * Ensure `rows` is a concrete array for emulator / merge logic.
136
21
  * Call at host boundaries (`createDocument`, tests); JSON may still omit `rows` for schema-only.
@@ -233,29 +118,6 @@ declare function isGristCellError(value: unknown): value is GristEncodedError;
233
118
  */
234
119
  declare function encodeGristValue(value: unknown, column?: GristReplicaColumn): unknown;
235
120
 
236
- type ValidateColumnMappingsResult = {
237
- ok: boolean;
238
- /**
239
- * `true` while the host has not yet reported column mappings (e.g. between
240
- * `grist.ready()` resolving and the first `onRecord` / `onRecords` callback,
241
- * or before `sectionApi.mappings()` returns). Callers should not gate UI or
242
- * emit mapping alerts while pending.
243
- */
244
- pending?: boolean;
245
- /** Logical names of required columns the user has not yet mapped. */
246
- missing: string[];
247
- /** Logical names of `allowMultiple` columns mapped to an empty list. */
248
- emptyMultiples: string[];
249
- };
250
- /**
251
- * Verifies that the current Grist mappings cover every required column declared
252
- * in `grist.ready({ columns })`.
253
- *
254
- * Use this before reading `mappedRecord` so you can render a "please configure
255
- * the widget" prompt instead of a confusing `null`.
256
- */
257
- declare function validateColumnMappings(spec: GristColumnsToMap | undefined | null, mappings: GristWidgetColumnMap | null | undefined): ValidateColumnMappingsResult;
258
-
259
121
  /**
260
122
  * Pure projections from the handshake snapshot for boundary / shell UI.
261
123
  *
@@ -295,359 +157,6 @@ declare const GRIST_BOUNDARY_PREPARING_COPY: {
295
157
  readonly message: "Open the widget settings in Grist (Creator Panel → Custom widget) and connect each required column to your table.";
296
158
  };
297
159
 
298
- type GristWidgetMode = "empty" | "row" | "new-row";
299
- type UseGristSelectionOptions = {
300
- columns?: GristColumnsToMap;
301
- subscribeToWidgetOptions?: boolean;
302
- subscribeToNewRecord?: boolean;
303
- };
304
- type UseGristSelectionResult<TRow = Record<string, unknown>, TMapped = Record<string, unknown>> = {
305
- record: GristRowRecord<TRow> | null;
306
- records: GristRowRecord<TRow>[] | null;
307
- mappedRecord: TMapped | null;
308
- mappings: GristWidgetColumnMap;
309
- recordsMappings: GristWidgetColumnMap | null;
310
- columnMappingStatus: ValidateColumnMappingsResult;
311
- mode: GristWidgetMode;
312
- resolveMappedColumnId: (logicalFieldName: string) => string;
313
- mapBack: (patch: Partial<TMapped>) => Record<string, unknown>;
314
- mapBackSkipped: readonly string[];
315
- isNewRecord: boolean;
316
- newRecordMappings: GristWidgetColumnMap | null;
317
- widgetOptions: Record<string, unknown> | null;
318
- widgetInteraction: GristWidgetInteraction | null;
319
- };
320
-
321
- /**
322
- * Minimal widget slice for deriving non-fatal SDK callouts. Any
323
- * {@link import("../use-grist").UseGristResult} satisfies this.
324
- */
325
- type GristSdkAlertsWidgetSlice = {
326
- status: GristWidgetStatus;
327
- columnMappingStatus: ValidateColumnMappingsResult;
328
- actionError: string | null;
329
- /**
330
- * Last access-insufficient error from a read method (`fetchTable`, etc.).
331
- * When set and matching the access-error pattern, an "access-insufficient"
332
- * alert is emitted — same as for `actionError`.
333
- */
334
- readError?: string | null;
335
- /**
336
- * Logical column names that the most recent `mapBack(...)` call could not
337
- * reverse-map (e.g. `allowMultiple` columns where one logical name resolves
338
- * to several real columns).
339
- */
340
- mapBackSkipped?: readonly string[];
341
- /** Selection mode from `useGrist()` — used for section-not-linked detection. */
342
- mode?: GristWidgetMode;
343
- /** `onOptions` settings from Grist (`InteractionOptions`). */
344
- widgetInteraction?: GristWidgetInteraction | null;
345
- /**
346
- * Alert kinds suppressed via `UseGristOptions.suppressAlerts`.
347
- * Consumed automatically by `useGristSdkAlertDescriptors`.
348
- */
349
- suppressAlerts?: readonly GristSdkAlertKind[];
350
- /**
351
- * Whether the widget declared `allowSelectBy: true` — used to distinguish
352
- * "section-not-linked" (expects incoming link) from "source-not-wired"
353
- * (expects to drive other sections).
354
- */
355
- allowSelectBy?: boolean;
356
- };
357
- 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";
358
- /** Classic callout level for host styling: info / warning / error. */
359
- type GristSdkAlertSeverity = "info" | "warning" | "error";
360
- type GristSdkAlertDescriptor = {
361
- id: string;
362
- kind: GristSdkAlertKind;
363
- severity: GristSdkAlertSeverity;
364
- title: string;
365
- /** Suggested WAI-ARIA role for the host shell. */
366
- ariaRole: "status" | "alert";
367
- message: string;
368
- };
369
- type GetGristSdkAlertDescriptorsOptions = {
370
- /**
371
- * Handshake snapshot from `useGristHandshake()` / the provider manager.
372
- * Enables link-stale, mapping-unreported, and current-table alerts that are
373
- * not visible on the widget slice alone.
374
- */
375
- snapshot?: GristWidgetSnapshot;
376
- /** Appended to {@link formatColumnMappingAlertMessage} when a mapping alert is emitted. */
377
- columnMappingHint?: string;
378
- /** Appended to the map-back-skip message. */
379
- mapBackHint?: string;
380
- /** Override copy for {@link formatMappingPendingAlertMessage}. */
381
- mappingPendingHint?: string;
382
- /** Appended to {@link formatSectionNotLinkedAlertMessage}. */
383
- sectionNotLinkedHint?: string;
384
- /** Appended to {@link formatSourceNotWiredAlertMessage}. */
385
- sourceNotWiredHint?: string;
386
- /** Appended to {@link formatAccessInsufficientMessage}. */
387
- accessInsufficientHint?: string;
388
- /**
389
- * Alert kinds to omit from the output. Useful for widgets that intentionally
390
- * operate without a link source (`["section-not-linked"]`) or handle certain
391
- * conditions in their own UI.
392
- */
393
- suppressKinds?: readonly GristSdkAlertKind[];
394
- };
395
- /** Default alert title for shadcn / toast shells. */
396
- declare function getGristSdkAlertTitle(kind: GristSdkAlertKind): string;
397
- /** Suggested severity for host styling (destructive vs muted). */
398
- declare function getGristSdkAlertSeverity(kind: GristSdkAlertKind): GristSdkAlertSeverity;
399
- /**
400
- * Human-readable text for an incomplete column mapping (when
401
- * `columnMappingStatus.ok` is false).
402
- */
403
- declare function formatColumnMappingAlertMessage(status: ValidateColumnMappingsResult, hint?: string): string;
404
- declare function formatMappingPendingAlertMessage(hint?: string): string;
405
- declare function formatMappingUnreportedAlertMessage(hint?: string): string;
406
- declare function formatLinkStaleAlertMessage(snapshot: GristWidgetSnapshot): string;
407
- /**
408
- * True when Grist reports this section is not a link target (no selector drives
409
- * the cursor / `onRecord` stream). Requires `linking` on `widgetInteraction` so
410
- * older hosts do not trigger false positives.
411
- */
412
- declare function isWidgetSectionNotLinked(interaction: GristWidgetInteraction | null | undefined): boolean;
413
- declare function formatSectionNotLinkedAlertMessage(hint?: string): string;
414
- declare function formatSourceNotWiredAlertMessage(hint?: string): string;
415
- /**
416
- * Non-fatal SDK messages to show while `status === "ready"` (e.g. incomplete
417
- * mappings, stale link, or `actionError` when not promoted to `status === "error"`).
418
- * Host apps map each descriptor to their own UI (shadcn Alert, toast, etc.).
419
- *
420
- * Pass `options.snapshot` (from `useGristHandshake()` or the provider manager)
421
- * for FSM-only signals: link stale, mapping unreported, current-table errors.
422
- */
423
- declare function getGristSdkAlertDescriptors(widget: GristSdkAlertsWidgetSlice, options?: GetGristSdkAlertDescriptorsOptions): GristSdkAlertDescriptor[];
424
- /**
425
- * Heuristic: returns `true` when `actionError` looks like it was caused by
426
- * insufficient access rights rather than a domain / schema error.
427
- */
428
- declare function isAccessInsufficientError(message: string): boolean;
429
- declare function formatAccessInsufficientMessage(hint?: string): string;
430
-
431
- type GristWidgetActionStatus = "idle" | "running" | "error";
432
- type UseGristTableOpsBoundResult = {
433
- table: GristTableOperations;
434
- getTable: (tableId: string) => GristTableOperations;
435
- actionStatus: GristWidgetActionStatus;
436
- actionError: string | null;
437
- applyActions: (actions: GristUserActionTuple[], applyOptions?: GristApplyUserActionsOptions) => Promise<unknown>;
438
- };
439
-
440
- type GristTheme = "light" | "dark";
441
- type UseGristThemeResult = {
442
- theme: GristTheme | null;
443
- };
444
-
445
- type UseGristCurrentTableResult = {
446
- currentTableId: string | null;
447
- currentTableLoading: boolean;
448
- refreshCurrentTable: () => Promise<void>;
449
- tableError: string | null;
450
- };
451
-
452
- type GristCoreContextValue = UseGristCoreResult & {
453
- tableError: string | null;
454
- };
455
- type GristStatusSliceValue = GristCoreContextValue & UseGristCurrentTableResult;
456
-
457
- type ComposeGristWidgetOptions = UseGristCoreOptions & UseGristSelectionOptions & {
458
- /**
459
- * Alert kinds that should never be emitted for this widget.
460
- * E.g. `["section-not-linked"]` for widgets that don't need a link source.
461
- */
462
- suppressAlerts?: GristSdkAlertKind[];
463
- };
464
-
465
- type UseGristOptions = ComposeGristWidgetOptions;
466
- /** Return type of `useGristStatus()`: connection state plus current-table info. */
467
- type UseGristStatusResult = GristStatusSliceValue;
468
- /** Return type of `useGristWrites()`. */
469
- type UseGristWritesResult = UseGristTableOpsBoundResult;
470
- /**
471
- * The full Grist widget state and API surface.
472
- *
473
- * **Method stability:** all function-typed fields (`fetchTable`, `listTables`,
474
- * `patchWidgetOptions`, `getTable`, etc.) are `useCallback`-wrapped internally
475
- * and **referentially stable** as long as the underlying `docApi` hasn't changed.
476
- * You can safely use individual methods in React dependency arrays:
477
- *
478
- * ```tsx
479
- * // GOOD — w.listTables is stable, effect only runs once
480
- * useEffect(() => { void w.listTables().then(setTables) }, [w.listTables])
481
- *
482
- * // BAD — w is a new object whenever any Grist state changes (record, options, …)
483
- * useEffect(() => { void w.listTables().then(setTables) }, [w])
484
- * ```
485
- *
486
- * The `UseGristResult` object itself is **not** referentially stable — it updates
487
- * whenever any reactive field changes (e.g. `record`, `widgetOptions`, `mode`).
488
- * Do **not** use the whole object as a `useEffect` / `useMemo` dependency.
489
- */
490
- type UseGristResult<TRow = Record<string, unknown>, TMapped = Record<string, unknown>> = {
491
- /** @access `"none"` — Connection state. */
492
- status: GristWidgetStatus;
493
- /** @access `"none"` — `true` if the page is inside a Grist iframe. */
494
- isAvailable: boolean | null;
495
- /** @access `"none"` — Convenience for `status === "ready"`. */
496
- isReady: boolean;
497
- /** @access `"none"` — Connection-level error string. */
498
- error: string | null;
499
- /**
500
- * Handshake-derived gates (`canRender`, `canWriteRecords`, …).
501
- * Prefer `capabilities.canRender` over re-deriving from `columnMappingStatus` alone.
502
- * @access `"none"`
503
- */
504
- capabilities: GristCapabilities;
505
- /** @access `"none"` — Re-run the handshake from scratch. */
506
- reload: () => Promise<void>;
507
- /** @access `"none"` — Resolved Grist theme (`"light" | "dark"`) or `null` before ready. */
508
- theme: GristTheme | null;
509
- /** @access `"read table"` — Currently selected row (raw column ids). */
510
- record: GristRowRecord<TRow> | null;
511
- /** @access `"read table"` — All visible rows in the section (raw column ids). */
512
- records: GristRowRecord<TRow>[] | null;
513
- /** @access `"read table"` — Selected row with logical column names. `null` if required mappings are missing. */
514
- mappedRecord: TMapped | null;
515
- /** @access `"read table"` — Logical → real column id map for the single-record stream. */
516
- mappings: GristWidgetColumnMap;
517
- /** @access `"read table"` — Logical → real column id map for the multi-record stream. */
518
- recordsMappings: GristWidgetColumnMap | null;
519
- /** @access `"read table"` — Required-column gating result. */
520
- columnMappingStatus: ValidateColumnMappingsResult;
521
- /** @access `"read table"` — Derived from selection state: `"empty"`, `"row"`, or `"new-row"`. */
522
- mode: GristWidgetMode;
523
- /** @access `"read table"` — One-shot column resolution (returns `name` as a fallback). */
524
- resolveMappedColumnId: (logicalFieldName: string) => string;
525
- /** @access `"read table"` — Reverse-map a logical-name patch to real column ids for writes. */
526
- mapBack: (patch: Partial<TMapped>) => Record<string, unknown>;
527
- /**
528
- * Logical column names that the most recent `mapBack(...)` call could not
529
- * reverse-map (typically `allowMultiple` columns).
530
- *
531
- * Used by {@link import("./helpers/grist-sdk-alerts").getGristSdkAlertDescriptors}
532
- * to surface a non-fatal alert.
533
- * @access `"read table"`
534
- */
535
- mapBackSkipped: readonly string[];
536
- /** @access `"read table"` — `true` when the cursor is on the new-row placeholder. */
537
- isNewRecord: boolean;
538
- /** @access `"read table"` — Logical → real map for the new-row placeholder. */
539
- newRecordMappings: GristWidgetColumnMap | null;
540
- /** @access `"read table"` — `onOptions` payload from Grist, includes `access_level`. */
541
- widgetInteraction: GristWidgetInteraction | null;
542
- /** @access `"read table"` — Current section's table id. */
543
- currentTableId: string | null;
544
- /** @access `"read table"` — `true` while the SDK re-reads `selectedTable.getTableId()`. */
545
- currentTableLoading: boolean;
546
- /** @access `"read table"` — Force a re-read of the current table id. */
547
- refreshCurrentTable: () => Promise<void>;
548
- /**
549
- * Last access-insufficient error from a read method (`fetchTable`, `listColumns`, …).
550
- * `null` when no error or after a successful call clears it.
551
- * Consumed by {@link import("./helpers/grist-sdk-alerts").getGristSdkAlertDescriptors}
552
- * to surface the "access-insufficient" alert.
553
- * @access `"none"`
554
- */
555
- readError: string | null;
556
- /** @access `"full"` — Raw columnar payload for any table. Requires full document access. */
557
- fetchTable: (tableId: string) => Promise<GristColumnarTable>;
558
- /** @access `"full"` — Row-shaped, decoded, optionally safe-parsed read of any table. Requires full document access. */
559
- fetchTableRows: {
560
- <T extends Record<string, unknown> = Record<string, unknown>>(tableId: string, options: FetchGristTableRowsOptions & {
561
- safeParse: true | Omit<SafeParseGristTableDataOptions, "columns" | "order">;
562
- }): Promise<GristRowRecord<{
563
- [K in keyof T]: GristSafeParseCellResult<T[K]> | null;
564
- }>[]>;
565
- <T extends Record<string, unknown> = Record<string, unknown>>(tableId: string, options?: FetchGristTableRowsOptions): Promise<GristRowRecord<T>[]>;
566
- };
567
- /** @access `"full"` — Fetch a single row by id from any table. Requires full document access. */
568
- fetchRow: <T = Record<string, unknown>>(tableId: string, rowId: number) => Promise<GristRowRecord<T> | null>;
569
- /** @access `"read table"` — List table ids (system/hidden tables filtered by default). */
570
- listTables: (options?: ListTablesOptions) => Promise<string[]>;
571
- /** @access `"full"` — Column metadata without fetching rows. Requires full document access. */
572
- listColumns: (tableId: string, options?: ListColumnsOptions) => Promise<GristColumnInfo[]>;
573
- /** @access `"read table"` — Document name. */
574
- getDocName: () => Promise<string>;
575
- /** @access `"full"` — Build a replica document snapshot from the live doc API. Requires full document access. */
576
- buildReplicaDocumentFromDocApi: (options?: BuildReplicaDocumentFromDocApiOptions) => Promise<GristReplicaDocument>;
577
- /** @access `"read table"` — Raw columnar read of the current section. */
578
- fetchSelectedTable: (fetchOptions?: GristFetchSelectedOptions) => Promise<GristColumnarTable>;
579
- /** @access `"read table"` — Single row from the current section. */
580
- fetchSelectedRecord: (rowId: number, fetchOptions?: GristFetchSelectedOptions) => Promise<Record<string, unknown>>;
581
- /** @access `"full"` — CRUD operations on the current table (`create`, `update`, `upsert`, `destroy`). */
582
- table: GristTableOperations;
583
- /** @access `"full"` — Memoized CRUD operations for any table by id. */
584
- getTable: (tableId: string) => GristTableOperations;
585
- /** @access `"full"` — Last write status (`"idle"`, `"running"`, `"error"`). */
586
- actionStatus: GristWidgetActionStatus;
587
- /** @access `"full"` — Last write error message. */
588
- actionError: string | null;
589
- /** @access `"full"` — Apply user-action tuples atomically (schema + data mutations). */
590
- applyActions: (actions: GristUserActionTuple[], applyOptions?: GristApplyUserActionsOptions) => Promise<unknown>;
591
- /** @access `"read table"` — Current widget options from Grist's `onOptions` stream. */
592
- widgetOptions: Record<string, unknown> | null;
593
- /** @access `"read table"` — Fetch the current widget options imperatively. */
594
- getWidgetOptions: () => Promise<Record<string, unknown> | null>;
595
- /** @access `"read table"` — Fetch a single widget option by key. */
596
- getWidgetOption: (key: string) => Promise<unknown>;
597
- /** @access `"full"` — Set a single widget option. */
598
- setWidgetOption: (key: string, value: unknown) => Promise<void>;
599
- /** @access `"full"` — Replace all widget options. */
600
- setWidgetOptions: (next: Record<string, unknown>) => Promise<void>;
601
- /** @access `"full"` — Merge a patch into existing widget options. */
602
- patchWidgetOptions: (patch: Record<string, unknown>) => Promise<void>;
603
- /** @access `"full"` — Remove all widget options. */
604
- clearWidgetOptions: () => Promise<void>;
605
- /** @access `"read table"` — Move the host cursor to a row / field / section. */
606
- setCursorPosition: (pos: GristCursorPos) => Promise<void>;
607
- /** @access `"read table"` — Set the widget's linked row selection (requires `allowSelectBy`). */
608
- setLinkedRowSelection: (rowIds: null | number[]) => Promise<void>;
609
- /** @access `"full"` — Signed download URL for an attachment. */
610
- getAttachmentUrl: (attachmentId: string, options?: {
611
- readOnly?: boolean;
612
- }) => Promise<string>;
613
- /** @access `"full"` — Fetch an attachment as a base64-encoded string. */
614
- fetchAttachmentBase64: (attachmentId: string, options?: {
615
- readOnly?: boolean;
616
- }) => Promise<GristFetchedAttachment>;
617
- /** @access `"full"` — Fetch an attachment as a Blob. */
618
- fetchAttachmentBlob: (attachmentId: string, options?: {
619
- readOnly?: boolean;
620
- }) => Promise<GristFetchedAttachmentBlob>;
621
- /** @access `"full"` — Obtain a short-lived access token for the Grist REST API. */
622
- getAccessToken: (options?: {
623
- readOnly?: boolean;
624
- }) => Promise<GristAccessToken>;
625
- /** @access `"full"` — `fetch()` with the doc access token attached. Path is relative to the document API root. */
626
- fetchWithAuth: (path: string, init?: RequestInit & {
627
- readOnly?: boolean;
628
- }) => Promise<Response>;
629
- /** @access `"full"` — Upload a file via `POST /attachments` (returns attachment ids). */
630
- uploadAttachment: (file: Blob | File, options?: {
631
- fileName?: string;
632
- }) => Promise<GristAttachmentUploadResult>;
633
- /** @access `"read table"` — Re-issue `grist.ready()` with new options. */
634
- configure: (options: GristReadyOptions) => Promise<void>;
635
- /** @access `"read table"` — Force a re-read of `sectionApi.mappings()`. */
636
- refreshMappings: () => Promise<GristWidgetColumnMap | null>;
637
- /**
638
- * Alert kinds suppressed via `UseGristOptions.suppressAlerts`.
639
- * Consumed automatically by `useGristSdkAlertDescriptors`.
640
- * @access `"none"`
641
- */
642
- suppressAlerts?: readonly GristSdkAlertKind[];
643
- /**
644
- * Whether the widget declared `allowSelectBy: true` in its options.
645
- * Used by the alert system to distinguish "section-not-linked" from "source-not-wired".
646
- * @access `"none"`
647
- */
648
- allowSelectBy?: boolean;
649
- };
650
-
651
160
  /**
652
161
  * React hook: widget slice + optional handshake snapshot for
653
162
  * {@link getGristSdkAlertDescriptors}.
@@ -827,5 +336,5 @@ type UseWidgetMetadataInput = {
827
336
  };
828
337
  declare function useWidgetMetadata(input?: UseWidgetMetadataInput | null): void;
829
338
 
830
- export { FetchGristTableRowsOptions, GRIST_BOUNDARY_PREPARING_COPY, GristAccessToken, GristApplyUserActionsOptions, GristBoundary, GristBoundaryScreen, GristCapabilities, GristColumnInfo, GristColumnarTable, GristColumnsToMap, GristCursorPos, GristDocApi, GristDocumentMode, GristFetchSelectedOptions, GristFormulaKind, GristNoiseColumnsOptions, GristReadyOptions, GristReplicaColumn, GristReplicaDocument, GristReplicaRow, GristReplicaTable, GristRequiredAccess, GristRowRecord, GristSafeParseCellResult, GristTableOperations, GristUserActionTuple, GristWidgetColumnMap, GristWidgetInteraction, GristWidgetProvider, GristWidgetStatus, ListColumnsOptions, ListTablesOptions, SafeParseGristTableDataOptions, UseGristCoreOptions, UseGristCoreResult, 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 };
831
- export type { BuildReplicaDocumentFromDocApiOptions, GetGristSdkAlertDescriptorsOptions, GristAttachmentUploadResult, GristBoundaryActions, GristBoundaryBlockingKind, GristBoundaryBootPhase, GristBoundaryGate, GristBoundaryProps, GristBoundaryView, GristChoiceListEntry, GristDecodedValue, GristEncodedAttachmentList, GristEncodedBareRef, GristEncodedDate, GristEncodedDateTime, GristEncodedError, GristEncodedList, GristEncodedPending, GristEncodedRef, GristFetchedAttachment, GristFetchedAttachmentBlob, GristSchemaTableView, GristSdkAlertDescriptor, GristSdkAlertKind, GristSdkAlertSeverity, GristSdkAlertsWidgetSlice, GristTheme, GristWidgetActionStatus, GristWidgetMode, GristWidgetProviderProps, ReplicaDocumentJsonOptions, ReplicaJsonIncludeRows, ReplicaTableColumnMetaLite, UseGristOptions, UseGristResult, UseGristSchemaOptions, UseGristSchemaResult, UseGristSelectionResult, UseGristStatusResult, UseGristThemeResult, UseGristWritesResult, UseWidgetMetadataInput, ValidateColumnMappingsResult };
339
+ export { GRIST_BOUNDARY_PREPARING_COPY, GetGristSdkAlertDescriptorsOptions, GristBoundary, GristBoundaryScreen, GristDocumentMode, GristFormulaKind, GristNoiseColumnsOptions, GristReadyOptions, GristReplicaColumn, GristReplicaDocument, GristReplicaRow, GristReplicaTable, GristRequiredAccess, GristSdkAlertDescriptor, GristSdkAlertsWidgetSlice, GristWidgetProvider, UseGristOptions, UseGristResult, UseGristSelectionResult, UseGristStatusResult, UseGristThemeResult, UseGristWritesResult, buildReplicaJsonPayload, coerceGristDocApiRefRowId, decodeGristValue, deriveBoundaryBootLabel, deriveBoundaryBootPhase, deriveBoundaryView, encodeGristValue, formatBoundaryUserMessage, inferGristFormulaKind, isGristCellError, normalizeGristChoiceListEntries, normalizeReplicaDocumentInput, normalizeReplicaTableInput, parseGristWidgetOptionsCell, resolveGristFormulaKind, serializeJsonFriendly, useGrist, useGristContext, useGristOptional, useGristSchema, useGristSdkAlertDescriptors, useGristSelection, useGristStatus, useGristTheme, useGristWrites, useWidgetMetadata };
340
+ export type { GristBoundaryActions, GristBoundaryBlockingKind, GristBoundaryBootPhase, GristBoundaryGate, GristBoundaryProps, GristBoundaryView, GristChoiceListEntry, GristDecodedValue, GristEncodedBareRef, GristEncodedDate, GristEncodedDateTime, GristEncodedError, GristEncodedList, GristEncodedPending, GristEncodedRef, GristSchemaTableView, GristWidgetProviderProps, ReplicaDocumentJsonOptions, ReplicaJsonIncludeRows, UseGristSchemaOptions, UseGristSchemaResult, UseWidgetMetadataInput };