grist-widget-sdk 0.3.26 → 0.4.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.
- package/CHANGELOG.md +53 -0
- package/README.md +1 -1
- package/dist/app.cjs +1139 -4336
- package/dist/app.cjs.map +1 -1
- package/dist/app.d.cts +1 -3
- package/dist/app.d.ts +1 -3
- package/dist/app.js +9 -517
- package/dist/app.js.map +1 -1
- package/dist/chunk-4ZGVKGDF.js +204 -0
- package/dist/chunk-4ZGVKGDF.js.map +1 -0
- package/dist/{chunk-YQNMIL33.js → chunk-B5ZZNLVS.js} +528 -181
- package/dist/chunk-B5ZZNLVS.js.map +1 -0
- package/dist/chunk-O7NY46QY.js +1830 -0
- package/dist/chunk-O7NY46QY.js.map +1 -0
- package/dist/chunk-P6VTEKWO.js +618 -0
- package/dist/chunk-P6VTEKWO.js.map +1 -0
- package/dist/emulator/testing.cjs +2084 -391
- package/dist/emulator/testing.cjs.map +1 -1
- package/dist/emulator/testing.d.cts +55 -7
- package/dist/emulator/testing.d.ts +55 -7
- package/dist/emulator/testing.js +144 -19
- package/dist/emulator/testing.js.map +1 -1
- package/dist/emulator.cjs +59 -249
- package/dist/emulator.cjs.map +1 -1
- package/dist/emulator.d.cts +3 -5
- package/dist/emulator.d.ts +3 -5
- package/dist/emulator.js +5 -11
- package/dist/index.cjs +1373 -4859
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +81 -260
- package/dist/index.d.ts +81 -260
- package/dist/index.js +8 -161
- package/dist/{inline-C7DkvuET.d.cts → templates-CGmRIQBV.d.cts} +89 -35
- package/dist/{inline-DpcT8tV9.d.ts → templates-Cq94qOcf.d.ts} +89 -35
- package/dist/{types-D3JxUCfL.d.cts → types-DBStn0Dk.d.cts} +2 -26
- package/dist/{types-D3JxUCfL.d.ts → types-DBStn0Dk.d.ts} +2 -26
- package/dist/use-grist-BK0eke9K.d.cts +358 -0
- package/dist/use-grist-C5DMZ3wU.d.ts +358 -0
- package/package.json +8 -37
- package/dist/advanced.cjs +0 -2799
- package/dist/advanced.cjs.map +0 -1
- package/dist/advanced.d.cts +0 -822
- package/dist/advanced.d.ts +0 -822
- package/dist/advanced.js +0 -875
- package/dist/advanced.js.map +0 -1
- package/dist/chunk-22U7WAY3.js +0 -463
- package/dist/chunk-22U7WAY3.js.map +0 -1
- package/dist/chunk-64SVRWW7.js +0 -758
- package/dist/chunk-64SVRWW7.js.map +0 -1
- package/dist/chunk-ELGVOHFD.js +0 -32
- package/dist/chunk-ELGVOHFD.js.map +0 -1
- package/dist/chunk-EPEBKXVN.js +0 -470
- package/dist/chunk-EPEBKXVN.js.map +0 -1
- package/dist/chunk-GTTD5HPO.js +0 -36
- package/dist/chunk-GTTD5HPO.js.map +0 -1
- package/dist/chunk-JASMM2YC.js +0 -243
- package/dist/chunk-JASMM2YC.js.map +0 -1
- package/dist/chunk-N3X46JW2.js +0 -37
- package/dist/chunk-N3X46JW2.js.map +0 -1
- package/dist/chunk-PDGEZ24B.js +0 -2366
- package/dist/chunk-PDGEZ24B.js.map +0 -1
- package/dist/chunk-PM3B4WYV.js +0 -12
- package/dist/chunk-PM3B4WYV.js.map +0 -1
- package/dist/chunk-REV5AUXD.js +0 -25
- package/dist/chunk-REV5AUXD.js.map +0 -1
- package/dist/chunk-TZB3OZA6.js +0 -1630
- package/dist/chunk-TZB3OZA6.js.map +0 -1
- package/dist/chunk-YQNMIL33.js.map +0 -1
- package/dist/create-grist-emulator-BCqp1BF9.d.ts +0 -81
- package/dist/create-grist-emulator-DBM8OSIR.d.cts +0 -81
- package/dist/emulator/devtools.cjs +0 -1404
- package/dist/emulator/devtools.cjs.map +0 -1
- package/dist/emulator/devtools.d.cts +0 -48
- package/dist/emulator/devtools.d.ts +0 -48
- package/dist/emulator/devtools.js +0 -508
- package/dist/emulator/devtools.js.map +0 -1
- package/dist/emulator/transports.cjs +0 -1132
- package/dist/emulator/transports.cjs.map +0 -1
- package/dist/emulator/transports.d.cts +0 -38
- package/dist/emulator/transports.d.ts +0 -38
- package/dist/emulator/transports.js +0 -12
- package/dist/emulator/transports.js.map +0 -1
- package/dist/templates-8k2LKoO-.d.cts +0 -24
- package/dist/templates-DIwi_mvI.d.ts +0 -24
- package/dist/use-grist-reads-DUMvJgV7.d.ts +0 -480
- package/dist/use-grist-reads-DpjVuI0H.d.cts +0 -480
- package/dist/use-grist-types-DdOLEJXN.d.cts +0 -499
- package/dist/use-grist-types-kwxoFeub.d.ts +0 -499
- package/dist/use-grist-widget-options-from-context-CGOlQ5Vc.d.cts +0 -43
- package/dist/use-grist-widget-options-from-context-CGOlQ5Vc.d.ts +0 -43
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/sdk/helpers/grist-table-data.ts","../src/sdk/helpers/grist-schema-formula.ts","../src/sdk/helpers/grist-widget-options.ts","../src/sdk/helpers/grist-attachment-download.ts","../src/sdk/helpers/grist-fetch-with-auth.ts","../src/sdk/helpers/grist-attachment-upload.ts","../src/sdk/runtime/cells.ts","../src/sdk/use-grist.ts","../src/sdk/helpers/build-replica-document.ts","../src/sdk/helpers/grist-columns-filters.ts","../src/sdk/runtime/api.ts","../src/sdk/helpers/grist-mappings.ts","../src/sdk/runtime/derive.ts","../src/sdk/helpers/grist-widget-interaction.ts","../src/sdk/runtime/host.ts","../src/sdk/runtime/ready.ts","../src/sdk/helpers/grist-theme-payload.ts","../src/sdk/runtime/runtime.ts","../src/sdk/components/grist-widget-provider.tsx","../src/sdk/components/grist-boundary.tsx","../src/sdk/use-grist-schema.ts","../src/sdk/use-widget-metadata.ts"],"sourcesContent":["import type { GristDocApi, GristReplicaColumn, GristRowRecord } from \"../types\"\nimport { decodeGristValue } from \"./grist-value-codec\"\n\n/** Column-oriented table payload (`fetchTable`, `fetchSelectedTable`): `{ id: [...], Name: [...] }`. */\nexport type GristColumnarTable = Record<string, unknown[]>\nexport type GristTableRowsOrder = \"none\" | \"id\" | \"grist\"\nexport type FetchGristTableRowsOptions = {\n /** Column metadata, to decode each cell (except `id`) with `decodeGristValue`. */\n columns?: Record<string, GristReplicaColumn>\n /**\n * Row order:\n * - `grist` (default): `manualSort` ascending when present, then `id`.\n * - `id`: numeric `id` ascending.\n * - `none`: as `fetchTable` returned them.\n */\n order?: GristTableRowsOrder\n}\n\n/** Row count from columnar `fetchTable` data (prefers `id` column length). */\nexport function computeRowCount(data: Record<string, unknown[]>): number {\n const idCol = data.id\n if (Array.isArray(idCol)) return idCol.length\n for (const key of Object.keys(data)) {\n const col = data[key]\n if (Array.isArray(col)) return col.length\n }\n return 0\n}\n\n/**\n * Decode columnar `fetchTable` into replica row objects (same convention as the playground grid).\n */\nexport function decodeColumnarToReplicaRows(\n data: GristColumnarTable,\n columnIds: string[],\n columns: Record<string, GristReplicaColumn>,\n maxRows?: number\n): GristRowRecord[] {\n const nFull = computeRowCount(data)\n const n = maxRows !== undefined ? Math.min(nFull, maxRows) : nFull\n const out: GristRowRecord[] = []\n for (let i = 0; i < n; i++) {\n const row: Record<string, unknown> = {}\n for (const k of columnIds) {\n const arr = data[k]\n const raw = Array.isArray(arr) ? arr[i] : undefined\n if (k === \"id\") {\n row[k] = raw\n } else {\n row[k] = decodeGristValue(raw, columns[k]) as unknown\n }\n }\n out.push(row as GristRowRecord)\n }\n return out\n}\n\n/** Turn `fetchTable` output into row objects (order follows the `id` column). */\nexport function tableDataToRows<T = Record<string, unknown>>(\n data: GristColumnarTable\n): GristRowRecord<T>[] {\n const idCol = data.id\n if (!Array.isArray(idCol) || idCol.length === 0) return []\n const keys = Object.keys(data)\n const n = idCol.length\n const rows: GristRowRecord<T>[] = []\n for (let i = 0; i < n; i++) {\n const row: Record<string, unknown> = {}\n for (const k of keys) {\n const col = data[k]\n row[k] = Array.isArray(col) ? col[i] : undefined\n }\n rows.push(row as GristRowRecord<T>)\n }\n return rows\n}\n\nfunction manualSortKey(row: Record<string, unknown>): number | null {\n const v = row.manualSort\n if (typeof v === \"number\" && !Number.isNaN(v)) return v\n if (typeof v === \"string\" && v.trim() !== \"\") {\n const n = Number(v)\n if (!Number.isNaN(n)) return n\n }\n return null\n}\n\n/**\n * Sort rows by Grist's display order: `manualSort` ascending when present on\n * any row, otherwise numeric `id` ascending.\n */\nexport function sortRowsByGristOrder<T = Record<string, unknown>>(\n rows: readonly GristRowRecord<T>[]\n): GristRowRecord<T>[] {\n const hasManual = rows.some((r) => manualSortKey(r as Record<string, unknown>) !== null)\n if (!hasManual) {\n return [...rows].sort((a, b) => {\n const ida = typeof a.id === \"number\" ? a.id : 0\n const idb = typeof b.id === \"number\" ? b.id : 0\n return ida - idb\n })\n }\n return [...rows].sort((a, b) => {\n const ma = manualSortKey(a as Record<string, unknown>)\n const mb = manualSortKey(b as Record<string, unknown>)\n if (ma !== null && mb !== null && ma !== mb) return ma - mb\n if (ma !== null && mb === null) return -1\n if (ma === null && mb !== null) return 1\n const ida = typeof a.id === \"number\" ? a.id : 0\n const idb = typeof b.id === \"number\" ? b.id : 0\n return ida - idb\n })\n}\n\n/**\n * Same row materialization as {@link fetchGristTableRows} after `fetchTable`\n * returns columnar data. Hosts that already have columnar data (e.g. the\n * emulator building from in-memory rows) can use this and skip `docApi.fetchTable`.\n */\nexport function materializeGristRowsFromColumnar<T extends Record<string, unknown> = Record<string, unknown>>(\n data: GristColumnarTable,\n options?: FetchGristTableRowsOptions\n): GristRowRecord<T>[] {\n const order = options?.order ?? \"grist\"\n let rows: GristRowRecord<T>[]\n if (options?.columns) {\n const columnIds = Object.keys(data)\n rows = decodeColumnarToReplicaRows(data, columnIds, options.columns) as GristRowRecord<T>[]\n } else {\n rows = tableDataToRows<T>(data)\n }\n\n if (order === \"none\") return rows\n if (order === \"id\") {\n return [...rows].sort((a, b) => {\n const ida = typeof a.id === \"number\" ? a.id : 0\n const idb = typeof b.id === \"number\" ? b.id : 0\n return ida - idb\n })\n }\n return sortRowsByGristOrder(rows)\n}\n\n/**\n * Fetch a table and return rows as objects, optionally decoded from schema and sorted.\n */\nexport async function fetchGristTableRows<T extends Record<string, unknown> = Record<string, unknown>>(\n docApi: GristDocApi,\n tableId: string,\n options?: FetchGristTableRowsOptions\n): Promise<GristRowRecord<T>[]> {\n const data = (await docApi.fetchTable(tableId)) as GristColumnarTable\n return materializeGristRowsFromColumnar<T>(data, options)\n}\n","import type { GristFormulaKind, GristReplicaColumn } from \"../types\"\n\nexport function inferGristFormulaKind(isFormula: boolean, formulaTrimmed: string): GristFormulaKind {\n if (formulaTrimmed.length > 0) return isFormula ? \"computed\" : \"trigger\"\n return isFormula ? \"empty_slot\" : \"none\"\n}\n\n/** Use when `formulaKind` may be missing (e.g. older document builds). */\nexport function resolveGristFormulaKind(col: GristReplicaColumn): GristFormulaKind {\n if (col.formulaKind) return col.formulaKind\n const f = col.formula?.trim() ?? \"\"\n if (f.length > 0) return col.isFormula === true ? \"computed\" : \"trigger\"\n return col.isFormula === true ? \"empty_slot\" : \"none\"\n}\n\n/** Serialize cell values for JSON output. */\nexport function serializeJsonFriendly(value: unknown): unknown {\n if (value === null || value === undefined) return null\n if (typeof value === \"string\" || typeof value === \"number\" || typeof value === \"boolean\") return value\n try {\n return JSON.parse(JSON.stringify(value)) as unknown\n } catch {\n return String(value)\n }\n}\n","/**\n * Grist stores column widget configuration in `_grist_Tables_column.widgetOptions`\n * as a JSON string. Choice fields use `choices: string[]` plus optional\n * `choiceOptions: Record<string, Style>` (e.g. `fillColor`, `textColor`).\n *\n * @see https://github.com/gristlabs/grist-core/blob/main/app/client/widgets/ChoiceEditor.js\n */\n\n/** One selectable choice for UI (value stored in the cell is `value`). */\nexport type GristChoiceListEntry = {\n value: string\n label: string\n fillColor?: string\n textColor?: string\n}\n\n/**\n * Parse a cell value from `_grist_Tables_column.widgetOptions` into a plain object.\n */\nexport function parseGristWidgetOptionsCell(raw: unknown): Record<string, unknown> | undefined {\n if (raw == null || raw === \"\") return undefined\n if (typeof raw === \"string\") {\n try {\n const parsed: unknown = JSON.parse(raw)\n if (parsed && typeof parsed === \"object\" && !Array.isArray(parsed)) {\n return parsed as Record<string, unknown>\n }\n } catch {\n return undefined\n }\n return undefined\n }\n if (typeof raw === \"object\" && !Array.isArray(raw)) {\n return raw as Record<string, unknown>\n }\n return undefined\n}\n\nfunction readStyleColor(style: Record<string, unknown>, key: string): string | undefined {\n const v = style[key]\n return typeof v === \"string\" ? v : undefined\n}\n\n/**\n * Normalizes Grist Choice / ChoiceList widgetOptions into a flat list for dropdowns.\n * `choices` entries are string labels (the stored cell value). Per-choice styling\n * lives in `choiceOptions[label]`.\n */\nexport function normalizeGristChoiceListEntries(\n widgetOptions: Record<string, unknown> | undefined\n): GristChoiceListEntry[] {\n if (!widgetOptions) return []\n const rawChoices = widgetOptions.choices\n if (!Array.isArray(rawChoices)) return []\n\n const choiceOptionsRaw = widgetOptions.choiceOptions\n const choiceOptions: Record<string, Record<string, unknown>> =\n choiceOptionsRaw &&\n typeof choiceOptionsRaw === \"object\" &&\n !Array.isArray(choiceOptionsRaw)\n ? (choiceOptionsRaw as Record<string, Record<string, unknown>>)\n : {}\n\n const out: GristChoiceListEntry[] = []\n for (const c of rawChoices) {\n const value = typeof c === \"string\" ? c : c != null ? String(c) : \"\"\n if (!value) continue\n const style = choiceOptions[value] ?? {}\n out.push({\n value,\n label: value,\n fillColor: readStyleColor(style, \"fillColor\"),\n textColor: readStyleColor(style, \"textColor\"),\n })\n }\n return out\n}\n","import type { GristDocApi } from \"../types\"\n\nexport type GristFetchedAttachment = {\n base64: string\n contentType: string\n}\n\nexport type GristFetchedAttachmentBlob = {\n blob: Blob\n contentType: string\n}\n\nfunction attachmentIdFromObjectRecord(record: Record<string, unknown>): string | undefined {\n for (const candidate of [record.id, record.attachmentId, record.fileId]) {\n if (candidate === undefined || candidate === null) continue\n return String(candidate)\n }\n return undefined\n}\n\n/**\n * All attachment ids found in a Grist attachment cell value (ordered, deduped).\n * Attachment columns are usually an **array** of file refs; a single id or one JSON object is also supported.\n */\nexport function extractGristAttachmentIdsFromCell(value: unknown): string[] {\n const out: string[] = []\n const seen = new Set<string>()\n const push = (id: string) => {\n if (seen.has(id)) return\n seen.add(id)\n out.push(id)\n }\n\n const walk = (v: unknown): void => {\n if (v === undefined || v === null) return\n if (typeof v === \"number\") {\n push(String(v))\n return\n }\n if (typeof v === \"string\") {\n const trimmed = v.trim()\n if (!trimmed) return\n if (/^\\d+$/.test(trimmed)) {\n push(trimmed)\n return\n }\n try {\n walk(JSON.parse(trimmed) as unknown)\n } catch {\n /* ignore */\n }\n return\n }\n if (Array.isArray(v)) {\n for (const item of v) walk(item)\n return\n }\n if (typeof v === \"object\") {\n const record = v as Record<string, unknown>\n const direct = attachmentIdFromObjectRecord(record)\n if (direct !== undefined) {\n push(direct)\n return\n }\n for (const nested of Object.values(record)) walk(nested)\n }\n }\n\n walk(value)\n return out\n}\n\n/** First attachment id in the cell, if any (see {@link extractGristAttachmentIdsFromCell}). */\nexport function extractGristAttachmentId(value: unknown): string | undefined {\n return extractGristAttachmentIdsFromCell(value)[0]\n}\n\n/**\n * Signed Grist download URL for a single attachment id (`getAccessToken` + query auth).\n */\nexport async function getAttachmentDownloadUrl(\n docApi: GristDocApi,\n attachmentId: string,\n options?: { readOnly?: boolean }\n): Promise<string> {\n const getAccessToken = docApi.getAccessToken\n if (!getAccessToken) {\n throw new Error(\"getAccessToken is not available on docApi\")\n }\n const { token, baseUrl } = await getAccessToken({ readOnly: options?.readOnly ?? false })\n return `${baseUrl}/attachments/${attachmentId}/download?auth=${token}`\n}\n\n/** URL for the `index`’th attachment in a cell value (0-based). */\nexport async function getAttachmentDownloadUrlForCell(\n docApi: GristDocApi,\n cellValue: unknown,\n index: number,\n options?: { readOnly?: boolean }\n): Promise<string | null> {\n const ids = extractGristAttachmentIdsFromCell(cellValue)\n const id = ids[index]\n if (!id) return null\n return getAttachmentDownloadUrl(docApi, id, options)\n}\n\nasync function fetchBytesFromSignedAttachmentUrl(url: string): Promise<{\n buffer: ArrayBuffer\n contentType: string\n}> {\n const response = await fetch(url)\n const contentType = response.headers.get(\"content-type\")?.trim() || \"application/octet-stream\"\n if (!response.ok) {\n throw new Error(`Attachment download failed (${response.status})`)\n }\n const buffer = await response.arrayBuffer()\n return { buffer, contentType }\n}\n\nfunction bufferToBase64(buffer: ArrayBuffer): string {\n const bytes = new Uint8Array(buffer)\n let binary = \"\"\n for (let i = 0; i < bytes.length; i++) binary += String.fromCharCode(bytes[i])\n return btoa(binary)\n}\n\n/** Token + URL + fetch for one attachment id. */\nexport async function fetchAttachmentBase64(\n docApi: GristDocApi,\n attachmentId: string,\n options?: { readOnly?: boolean }\n): Promise<GristFetchedAttachment> {\n const url = await getAttachmentDownloadUrl(docApi, attachmentId, options)\n const { buffer, contentType } = await fetchBytesFromSignedAttachmentUrl(url)\n return { base64: bufferToBase64(buffer), contentType }\n}\n\n/** Download attachment bytes as a `Blob` (preferred for large files). */\nexport async function fetchAttachmentBlob(\n docApi: GristDocApi,\n attachmentId: string,\n options?: { readOnly?: boolean }\n): Promise<GristFetchedAttachmentBlob> {\n const url = await getAttachmentDownloadUrl(docApi, attachmentId, options)\n const { buffer, contentType } = await fetchBytesFromSignedAttachmentUrl(url)\n return { blob: new Blob([buffer], { type: contentType }), contentType }\n}\n\n/** Download the `index`’th attachment in a cell (0-based). */\nexport async function fetchAttachmentBase64ForCell(\n docApi: GristDocApi,\n cellValue: unknown,\n index: number,\n options?: { readOnly?: boolean }\n): Promise<GristFetchedAttachment | null> {\n const url = await getAttachmentDownloadUrlForCell(docApi, cellValue, index, options)\n if (!url) return null\n const { buffer, contentType } = await fetchBytesFromSignedAttachmentUrl(url)\n return { base64: bufferToBase64(buffer), contentType }\n}\n","import type { GristDocApi } from \"../types\"\n\nexport type GristAccessToken = {\n token: string\n baseUrl: string\n}\n\ntype TokenCacheEntry = {\n token: GristAccessToken\n fetchedAt: number\n}\n\nconst TOKEN_TTL_MS = 45_000\nconst cache = new Map<string, TokenCacheEntry>()\nconst inFlight = new Map<string, Promise<GristAccessToken>>()\n\nfunction cacheKey(readOnly: boolean): string {\n return readOnly ? \"ro\" : \"rw\"\n}\n\n/**\n * Returns an access token suitable for calling Grist's REST API directly.\n * Tokens are short-lived; results are cached briefly and coalesced per readOnly flag.\n */\nexport async function getGristAccessToken(\n docApi: GristDocApi,\n options?: { readOnly?: boolean }\n): Promise<GristAccessToken> {\n if (!docApi.getAccessToken) {\n throw new Error(\"getAccessToken is not available on docApi (need higher access level)\")\n }\n\n const readOnly = options?.readOnly ?? false\n const key = cacheKey(readOnly)\n const now = Date.now()\n const hit = cache.get(key)\n if (hit && now - hit.fetchedAt < TOKEN_TTL_MS) {\n return hit.token\n }\n\n const pending = inFlight.get(key)\n if (pending) return pending\n\n const next = docApi.getAccessToken({ readOnly }).then((token) => {\n cache.set(key, { token, fetchedAt: Date.now() })\n inFlight.delete(key)\n return token\n })\n\n inFlight.set(key, next)\n return next\n}\n\n/** Clear cached tokens (tests or after auth errors). */\nexport function clearGristAccessTokenCache(): void {\n cache.clear()\n inFlight.clear()\n}\n\n/**\n * `fetch()` against Grist's REST API with the doc access token attached.\n */\nexport async function fetchWithGristAuth(\n docApi: GristDocApi,\n path: string,\n init?: RequestInit & { readOnly?: boolean }\n): Promise<Response> {\n const readOnly = init?.readOnly ?? false\n let token: GristAccessToken\n try {\n token = await getGristAccessToken(docApi, { readOnly })\n } catch (err) {\n clearGristAccessTokenCache()\n throw err\n }\n\n const isAbsolute = /^https?:\\/\\//i.test(path)\n const cleanPath = isAbsolute ? path : path.startsWith(\"/\") ? path : `/${path}`\n\n const url = isAbsolute\n ? new URL(path)\n : new URL(`${token.baseUrl.replace(/\\/$/, \"\")}${cleanPath}`)\n\n // The token goes into the URL, so it may only go to the Grist instance that\n // issued it. An absolute URL to any other origin (one read from a cell, say)\n // would hand the document's access token to that host.\n const gristOrigin = new URL(token.baseUrl).origin\n if (url.origin !== gristOrigin) {\n throw new Error(\n `fetchWithGristAuth: refusing to send the Grist access token to ${url.origin}; ` +\n `absolute URLs must point at this document's Grist instance (${gristOrigin}). ` +\n `Use plain fetch() for other hosts.`\n )\n }\n\n // Grist signs widget REST calls with a short-lived `auth` query parameter.\n // Do not send `Authorization: Bearer` from the browser: many Grist deployments\n // omit it from Access-Control-Allow-Headers, which breaks POST (e.g. attachment upload).\n if (!url.searchParams.has(\"auth\")) url.searchParams.set(\"auth\", token.token)\n\n const headers = new Headers(init?.headers ?? {})\n headers.delete(\"Authorization\")\n\n const response = await fetch(url.toString(), { ...init, headers })\n if (response.status === 401) {\n clearGristAccessTokenCache()\n const retryToken = await getGristAccessToken(docApi, { readOnly })\n url.searchParams.set(\"auth\", retryToken.token)\n return fetch(url.toString(), { ...init, headers })\n }\n return response\n}\n","import type { GristDocApi } from \"../types\"\nimport { extractGristAttachmentIdsFromCell } from \"./grist-attachment-download\"\nimport { fetchWithGristAuth } from \"./grist-fetch-with-auth\"\nimport { encodeGristValue } from \"./grist-value-codec\"\n\nconst ATTACHMENTS_COLUMN = { type: \"Attachments\" as const }\n\nexport type GristEncodedAttachmentList = [\"L\", ...(number | string)[]]\n\nexport type GristAttachmentUploadResult = {\n /** All attachment ids returned by `POST /attachments`. */\n ids: string[]\n /** First id in `ids` (convenience for single-file uploads). */\n firstId: string\n}\n\n/**\n * Parse the body of `POST /attachments` (widget or REST).\n * Grist returns a JSON array of attachment ids, e.g. `[42]` or `[101, 102]`.\n */\nexport function parseGristAttachmentUploadResponseIds(\n raw: string,\n options?: { strict?: boolean }\n): string[] {\n const trimmed = raw.trim()\n if (!trimmed) {\n throw new Error(\"Attachment upload returned an empty response.\")\n }\n\n let parsed: unknown\n try {\n parsed = JSON.parse(trimmed) as unknown\n } catch {\n if (options?.strict) {\n throw new Error(\"Attachment upload returned non-JSON response.\")\n }\n parsed = trimmed\n }\n\n return extractAttachmentIdsFromUploadPayload(parsed, options)\n}\n\n/**\n * First attachment id from an upload response (see {@link parseGristAttachmentUploadResponseIds}).\n */\nexport function parseGristAttachmentUploadResponse(\n raw: string,\n options?: { strict?: boolean }\n): string {\n const ids = parseGristAttachmentUploadResponseIds(raw, options)\n return ids[0]!\n}\n\nexport function extractAttachmentIdsFromUploadPayload(\n parsed: unknown,\n options?: { strict?: boolean }\n): string[] {\n if (options?.strict) {\n return extractAttachmentIdsFromUploadPayloadStrict(parsed)\n }\n\n const first = extractFirstAttachmentIdFromUploadPayload(parsed)\n if (first !== undefined) {\n if (Array.isArray(parsed)) {\n const ids: string[] = []\n const seen = new Set<string>()\n for (const item of parsed) {\n const id = coerceAttachmentId(item)\n if (id && !seen.has(id)) {\n seen.add(id)\n ids.push(id)\n }\n }\n return ids.length > 0 ? ids : [first]\n }\n return [first]\n }\n\n throw new Error(\"Attachment upload returned an unexpected response shape.\")\n}\n\nfunction extractAttachmentIdsFromUploadPayloadStrict(parsed: unknown): string[] {\n if (typeof parsed === \"number\" && Number.isFinite(parsed)) {\n return [String(parsed)]\n }\n\n if (Array.isArray(parsed)) {\n const ids: string[] = []\n const seen = new Set<string>()\n for (const item of parsed) {\n if (typeof item !== \"number\" || !Number.isFinite(item)) {\n throw new Error(\"Attachment upload returned an unexpected response shape.\")\n }\n const id = String(item)\n if (!seen.has(id)) {\n seen.add(id)\n ids.push(id)\n }\n }\n if (ids.length === 0) {\n throw new Error(\"Attachment upload returned an empty id list.\")\n }\n return ids\n }\n\n throw new Error(\"Attachment upload returned an unexpected response shape.\")\n}\n\n/** @deprecated Prefer {@link extractAttachmentIdsFromUploadPayload}. */\nexport function extractFirstAttachmentIdFromUploadPayload(parsed: unknown): string | undefined {\n if (typeof parsed === \"number\" && Number.isFinite(parsed)) {\n return String(parsed)\n }\n\n if (typeof parsed === \"string\" && parsed.trim()) {\n return parsed.trim()\n }\n\n if (Array.isArray(parsed)) {\n for (const item of parsed) {\n const id = coerceAttachmentId(item)\n if (id) return id\n }\n return undefined\n }\n\n if (parsed && typeof parsed === \"object\") {\n const record = parsed as Record<string, unknown>\n for (const key of [\"id\", \"attachmentId\", \"fileId\"]) {\n const id = coerceAttachmentId(record[key])\n if (id) return id\n }\n }\n\n return undefined\n}\n\nfunction coerceAttachmentId(value: unknown): string | undefined {\n if (typeof value === \"number\" && Number.isFinite(value)) {\n return String(value)\n }\n if (typeof value === \"string\" && value.trim()) {\n return value.trim()\n }\n return undefined\n}\n\nfunction normalizeAttachmentIdForWire(id: string | number): number | string {\n const numeric = typeof id === \"number\" ? id : Number(id)\n if (Number.isFinite(numeric) && String(numeric) === String(id).trim()) {\n return numeric\n }\n return typeof id === \"number\" ? String(id) : id.trim()\n}\n\n/** Wire value for an Attachments cell (Grist list encoding). */\nexport function gristAttachmentCellValues(\n attachmentIds: (string | number)[]\n): GristEncodedAttachmentList {\n const items = attachmentIds.map(normalizeAttachmentIdForWire)\n const encoded = encodeGristValue(items, ATTACHMENTS_COLUMN)\n if (!Array.isArray(encoded) || encoded[0] !== \"L\") {\n return [\"L\", ...items]\n }\n return encoded as GristEncodedAttachmentList\n}\n\n/** Wire value for a single-file Attachments cell. */\nexport function gristAttachmentCellValue(attachmentId: string | number): GristEncodedAttachmentList {\n return gristAttachmentCellValues([attachmentId])\n}\n\n/**\n * Merge new attachment ids into an existing Attachments cell value (deduped, order preserved).\n */\nexport function mergeGristAttachmentCellValue(\n existingCell: unknown,\n newIds: (string | number)[]\n): GristEncodedAttachmentList {\n const existing = extractGristAttachmentIdsFromCell(existingCell)\n const merged: string[] = []\n const seen = new Set<string>()\n const push = (raw: string | number) => {\n const id = String(raw).trim()\n if (!id || seen.has(id)) return\n seen.add(id)\n merged.push(id)\n }\n for (const id of existing) push(id)\n for (const id of newIds) push(id)\n return gristAttachmentCellValues(merged)\n}\n\nconst UPLOAD_HEADERS = {\n \"X-Requested-With\": \"XMLHttpRequest\",\n Accept: \"application/json\",\n} as const\n\n/**\n * Upload a file to the current document via `POST /attachments`.\n *\n * Uses `getAccessToken({ readOnly: false })` and `?auth=` (see Grist widget docs).\n * Requires document **full** access in the widget.\n */\nexport async function uploadGristAttachment(\n docApi: GristDocApi,\n file: Blob | File,\n options?: { fileName?: string }\n): Promise<GristAttachmentUploadResult> {\n const form = new FormData()\n const fileName =\n options?.fileName ?? (file instanceof File && file.name ? file.name : \"upload\")\n form.append(\"upload\", file, fileName)\n\n let response: Response\n try {\n response = await fetchWithGristAuth(docApi, \"/attachments\", {\n method: \"POST\",\n body: form,\n readOnly: false,\n headers: UPLOAD_HEADERS,\n })\n } catch (err) {\n const msg = err instanceof Error ? err.message : String(err)\n if (/failed to fetch/i.test(msg)) {\n const widgetOrigin =\n typeof globalThis.location !== \"undefined\"\n ? globalThis.location.origin\n : \"this widget origin\"\n throw new Error(\n `Attachment upload was blocked by the Grist host (CORS). The browser could not POST from ${widgetOrigin} to the document API. If upload worked from a dev URL (e.g. ngrok) but fails after deploy, add the new widget URL to your Grist server CORS allowlist (see grist-core#2040).`,\n { cause: err }\n )\n }\n throw err\n }\n\n const raw = await response.text()\n if (!response.ok) {\n throw new Error(\n raw.trim()\n ? `Attachment upload failed (${response.status}): ${raw.slice(0, 200)}`\n : `Attachment upload failed (${response.status})`\n )\n }\n\n const ids = parseGristAttachmentUploadResponseIds(raw)\n return { ids, firstId: ids[0]! }\n}\n","/**\n * Typed reads, with read-only access: each mapped cell checked against the\n * type its column declares in `GRIST_OPTIONS.columns`.\n *\n * Grist's mapping panel only offers the columns of the declared type, so for\n * a mapped column the declaration is the contract; and the plugin API's\n * decoded values already say what they are (a `Date`, a `Reference` with a\n * `rowId`, a list of ids, a `RaisedException` for a formula error, the raw\n * text of an invalid cell). Checked in Grist 1.7.22, every type, both\n * `cellFormat`s. So a cell is turned into the JS value its type promises, or\n * into `null` with an issue: no schema to fetch, no full access, no\n * dependency.\n */\n\nimport type { GristColumnsToMap, GristWidgetColumnMap } from \"../types\"\n\n/** A mapped cell that didn't match its declared type, or a rule of the widget's schema. */\nexport type GristCellIssue = {\n rowId: number\n /** The declared column name, or \"\" for a schema rule on the whole record. */\n column: string\n message: string\n /** The value Grist sent. */\n value: unknown\n}\n\ntype Check = { ok: true; value: unknown } | { ok: false; message: string }\n\nconst ok = (value: unknown): Check => ({ ok: true, value })\nconst bad = (message: string): Check => ({ ok: false, message })\n\n/** A formula error, as the plugin API decodes it (`RaisedException`) or encodes it (`[\"E\", name, …]`). */\nfunction formulaError(value: unknown): string | null {\n if (Array.isArray(value) && value[0] === \"E\") return String(value[1] ?? \"error\")\n if (value && typeof value === \"object\" && (value as { constructor?: { name?: string } }).constructor?.name === \"RaisedException\") {\n return String((value as { name?: unknown }).name ?? \"error\")\n }\n return null\n}\n\nfunction rowIdOf(value: unknown): number | null | undefined {\n if (typeof value === \"number\" && Number.isInteger(value)) return value === 0 ? null : value\n if (value && typeof value === \"object\" && typeof (value as { rowId?: unknown }).rowId === \"number\") {\n const id = (value as { rowId: number }).rowId\n return id === 0 ? null : id\n }\n if (Array.isArray(value) && value[0] === \"R\" && typeof value[2] === \"number\") return value[2] === 0 ? null : value[2]\n return undefined\n}\n\nfunction idsOf(value: unknown): number[] | undefined {\n if (value === null || value === undefined) return []\n const list = Array.isArray(value)\n ? value[0] === \"L\"\n ? value.slice(1)\n : value\n : value && typeof value === \"object\" && Array.isArray((value as { rowIds?: unknown }).rowIds)\n ? (value as { rowIds: unknown[] }).rowIds\n : undefined\n return list?.every((v) => typeof v === \"number\") ? (list as number[]) : undefined\n}\n\nfunction checkOne(base: string, value: unknown): Check {\n switch (base) {\n case \"Any\":\n return ok(value)\n case \"Text\":\n return value === null || typeof value === \"string\" ? ok(value ?? \"\") : bad(\"not text\")\n case \"Numeric\":\n return value === null || (typeof value === \"number\" && Number.isFinite(value)) ? ok(value) : bad(\"not a number\")\n case \"Int\":\n return value === null || (typeof value === \"number\" && Number.isInteger(value)) ? ok(value) : bad(\"not an integer\")\n case \"Bool\":\n return value === null || typeof value === \"boolean\" ? ok(value ?? false) : bad(\"not true or false\")\n case \"Date\":\n case \"DateTime\":\n if (value === null) return ok(null)\n if (value instanceof Date && !Number.isNaN(value.getTime())) return ok(value)\n // Seconds since the epoch: Grist's \"normal\" format, and the emulator's raw rows.\n if (typeof value === \"number\" && Number.isFinite(value)) return ok(new Date(value * 1000))\n return bad(\"not a date\")\n case \"Choice\":\n return value === null || typeof value === \"string\" ? ok(value) : bad(\"not a choice\")\n case \"ChoiceList\": {\n if (value === null || value === undefined) return ok([])\n const list = Array.isArray(value) ? (value[0] === \"L\" ? value.slice(1) : value) : undefined\n return list?.every((v) => typeof v === \"string\") ? ok(list) : bad(\"not a list of choices\")\n }\n case \"Ref\": {\n if (value === null) return ok(null)\n const id = rowIdOf(value)\n return id === undefined ? bad(\"not a reference\") : ok(id)\n }\n case \"RefList\":\n case \"Attachments\": {\n const ids = idsOf(value)\n return ids === undefined ? bad(base === \"RefList\" ? \"not a list of references\" : \"not a list of attachments\") : ok(ids)\n }\n default:\n return ok(value)\n }\n}\n\n/**\n * `value` as its declared `type` promises (\"Numeric\", \"Ref:Tasks\",\n * \"Text,Ref\"…): a match of any listed type, or a failure that says why.\n * Without a type (or \"Any\"), the value as it is.\n */\nexport function checkGristCell(type: string | undefined, value: unknown): Check {\n const error = formulaError(value)\n if (error) return bad(`formula error (${error})`)\n const bases = (type ?? \"Any\")\n .split(\",\")\n .map((t) => t.trim().split(\":\")[0]!)\n .filter(Boolean)\n if (bases.length === 0 || bases.includes(\"Any\")) return ok(value === undefined ? null : value)\n let first: Check | null = null\n for (const base of bases) {\n const check = checkOne(base, value)\n if (check.ok) return check\n first ??= check\n }\n return first!\n}\n\nconst nameOf = (c: GristColumnsToMap[number]) => (typeof c === \"string\" ? c : c.name)\nconst typeOf = (c: GristColumnsToMap[number]) => (typeof c === \"string\" ? undefined : c.type)\nconst isOptional = (c: GristColumnsToMap[number]) => typeof c === \"object\" && c.optional === true\n\n/** Minimal Standard Schema (https://standardschema.dev): zod 4, valibot, arktype implement it. */\nexport type StandardSchema<T = unknown> = {\n readonly \"~standard\": {\n readonly version: 1\n readonly vendor: string\n readonly validate: (\n value: unknown\n ) =>\n | { readonly value: T; readonly issues?: undefined }\n | { readonly issues: ReadonlyArray<{ readonly message: string; readonly path?: ReadonlyArray<PropertyKey | { key: PropertyKey }> }> }\n | Promise<unknown>\n }\n}\n\n/**\n * A record under the widget's declared names, each cell checked against its\n * column's declared type, then the record against `schema` if given. Returns\n * null (no issues) while a required column isn't mapped, like Grist's\n * `mapColumnNames`; the record itself without declared columns.\n */\nexport function mapAndCheck<T>(\n record: Record<string, unknown> | null,\n columns: GristColumnsToMap | undefined,\n mappings: GristWidgetColumnMap | null,\n schema?: StandardSchema\n): { value: T | null; issues: GristCellIssue[] } {\n if (!record) return { value: null, issues: [] }\n if (!columns?.length) return { value: record as T, issues: [] }\n if (mappings === null) return { value: null, issues: [] }\n const rowId = typeof record.id === \"number\" ? record.id : 0\n const out: Record<string, unknown> = { id: record.id }\n const issues: GristCellIssue[] = []\n for (const col of columns) {\n const name = nameOf(col)\n const real = mappings[name]\n const take = (raw: unknown) => {\n const check = checkGristCell(typeOf(col), raw)\n if (check.ok) return check.value\n issues.push({ rowId, column: name, message: check.message, value: raw })\n return null\n }\n if (Array.isArray(real) && real.length > 0) out[name] = real.map((r) => take(record[r]))\n else if (typeof real === \"string\" && real) out[name] = take(record[real])\n else if (!isOptional(col)) return { value: null, issues: [] }\n }\n if (schema) {\n const result = schema[\"~standard\"].validate(out)\n if (result instanceof Promise) {\n issues.push({ rowId, column: \"\", message: \"the schema validates asynchronously; useGrist() needs a synchronous one\", value: out })\n } else if (\"issues\" in result && result.issues) {\n for (const issue of result.issues) {\n const key = issue.path?.[0]\n const column = key === undefined ? \"\" : String(typeof key === \"object\" ? key.key : key)\n issues.push({ rowId, column, message: issue.message, value: column ? out[column] : out })\n }\n } else if (\"value\" in result) {\n return { value: result.value as T, issues }\n }\n }\n return { value: out as T, issues }\n}\n\n// ---------------------------------------------------------------------------\n// Types from a declaration\n// ---------------------------------------------------------------------------\n\ntype BaseOf<T extends string> = T extends `${infer B}:${string}` ? B : T\n\ntype CellOf<T extends string> = T extends `${infer A},${infer Rest}`\n ? CellOf<A> | CellOf<Rest>\n : BaseOf<T> extends \"Text\"\n ? string\n : BaseOf<T> extends \"Numeric\" | \"Int\"\n ? number | null\n : BaseOf<T> extends \"Bool\"\n ? boolean\n : BaseOf<T> extends \"Date\" | \"DateTime\"\n ? Date | null\n : BaseOf<T> extends \"Choice\"\n ? string | null\n : BaseOf<T> extends \"ChoiceList\"\n ? string[]\n : BaseOf<T> extends \"Ref\"\n ? number | null\n : BaseOf<T> extends \"RefList\" | \"Attachments\"\n ? number[]\n : unknown\n\ntype ColumnValue<C> = C extends { type: infer T extends string; allowMultiple: true }\n ? CellOf<T>[]\n : C extends { type: infer T extends string }\n ? CellOf<T>\n : C extends { allowMultiple: true }\n ? unknown[]\n : unknown\n\ntype RequiredName<C> = C extends { optional: true } ? never : C extends string ? C : C extends { name: infer N extends string } ? N : never\ntype OptionalName<C> = C extends { optional: true; name: infer N extends string } ? N : never\ntype ByName<Cs, N> = Extract<Cs, N | { name: N }>\n\n/**\n * The mapped record a `GRIST_OPTIONS` declaration gives, for `useGrist`'s\n * second type argument. Declare the options with `as const satisfies\n * UseGristOptions` so the column names and types stay literal:\n *\n * ```ts\n * export const GRIST_OPTIONS = {\n * requiredAccess: \"read table\",\n * columns: [{ name: \"Title\", type: \"Text\" }, { name: \"Due\", type: \"Date\", optional: true }],\n * } as const satisfies UseGristOptions\n *\n * const w = useGrist<GristRowRecord, GristMappedRow<typeof GRIST_OPTIONS>>()\n * w.mappedRecord?.Due // Date | null | undefined\n * ```\n */\nexport type GristMappedRow<O extends { columns?: readonly unknown[] }> = O[\"columns\"] extends readonly (infer C)[]\n ? { id: number } & { [N in RequiredName<C>]: ColumnValue<ByName<C, N>> } & { [N in OptionalName<C>]?: ColumnValue<ByName<C, N>> }\n : Record<string, unknown>\n","/**\n * `useGrist()`: the widget's one object for Grist — its connection, the\n * selected record and the section's records, column mapping, writes, widget\n * options, linking and the document's REST API.\n *\n * Inside `<GristWidgetProvider>` (what `mountGristWidget()` renders) it reads\n * the provider's connection; outside one, a page-wide connection made with\n * the first caller's options.\n */\n\nimport { createContext, useCallback, useContext, useEffect, useMemo, useSyncExternalStore } from \"react\"\n\nimport type { ValidateColumnMappingsResult } from \"./helpers/grist-mappings\"\nimport { createGristApi, type GristApi } from \"./runtime/api\"\nimport {\n deriveColumnMappingStatus,\n deriveError,\n deriveStatus,\n mapBackPatch,\n type GristWidgetStatus,\n} from \"./runtime/derive\"\nimport { mapAndCheck, type GristCellIssue } from \"./runtime/cells\"\nimport { ALL_STREAMS } from \"./runtime/host\"\nimport { resetGristReady } from \"./runtime/ready\"\nimport {\n createGristRuntime,\n initialRuntimeState,\n type GristRuntime,\n type GristRuntimeOptions,\n type GristRuntimeState,\n type GristTheme,\n type GristWidgetActionStatus,\n} from \"./runtime/runtime\"\nimport type { GristRowRecord, GristWidgetColumnMap } from \"./types\"\n\nexport type { GristTheme, GristWidgetActionStatus, GristWidgetStatus }\nexport type { GristColumnInfo, ListColumnsOptions, ListTablesOptions } from \"./runtime/api\"\n\n/** What the widget asks Grist for: access, columns to map, and the alerts it doesn't want. */\nexport type UseGristOptions = GristRuntimeOptions\n\n/** Derived from the selection: no row, a row, or the add-row placeholder. */\nexport type GristWidgetMode = \"empty\" | \"row\" | \"new-row\"\n\n/**\n * The widget's Grist state and API. Every method is referentially stable for\n * the widget's lifetime: safe in effect dependencies. The object itself is\n * new whenever a value changes; depend on the members you use, not on it.\n */\nexport type UseGristResult<TRow = Record<string, unknown>, TMapped = Record<string, unknown>> = Omit<\n GristApi,\n \"fetchTableRows\"\n> & {\n /** `\"booting\"` until Grist answers, then `\"ready\"`; `\"unavailable\"` outside Grist; `\"error\"` otherwise. */\n status: GristWidgetStatus\n /** Inside Grist with its plugin API (null while connecting). */\n isAvailable: boolean | null\n isReady: boolean\n /** Why the widget can't run (status `\"error\"` or `\"unavailable\"`), else null. */\n error: string | null\n /** Grist's light or dark theme, null until Grist sends it. */\n theme: GristTheme | null\n\n /** The selected row, raw column ids. */\n record: GristRowRecord<TRow> | null\n /** The section's rows (what its filters show), raw column ids. */\n records: GristRowRecord<TRow>[] | null\n /**\n * The selected row under the declared column names, each cell the JS value\n * its declared type promises (a cell that doesn't match is null, and in\n * `cellIssues`); null until every required column is mapped.\n */\n mappedRecord: TMapped | null\n /** Every row of the section, like `mappedRecord`. */\n mappedRecords: TMapped[] | null\n /** The mapped cells that didn't match their declared type (or the widget's `schema`), by row. */\n cellIssues: readonly GristCellIssue[]\n /** Declared column name → the Grist column id(s) mapped to it. */\n mappings: GristWidgetColumnMap\n /** Whether every required declared column is mapped (`pending` until Grist reports mappings). */\n columnMappingStatus: ValidateColumnMappingsResult\n mode: GristWidgetMode\n /** The Grist column id mapped to a declared name, or the name itself. */\n resolveMappedColumnId: (name: string) => string\n /** A patch under declared names, as real column ids for a write (multi-column mappings are skipped). */\n mapBack: (patch: Partial<TMapped>) => Record<string, unknown>\n /** The section's table id. */\n currentTableId: string | null\n\n /** Any table as rows (full access). */\n fetchTableRows: <T extends Record<string, unknown> = Record<string, unknown>>(\n tableId: string,\n options?: Parameters<GristApi[\"fetchTableRows\"]>[1]\n ) => Promise<GristRowRecord<T>[]>\n\n /** The last write's state. */\n actionStatus: GristWidgetActionStatus\n actionError: string | null\n\n /** The options Grist stores for this widget, null until it sends them. */\n widgetOptions: Record<string, unknown> | null\n}\n\ntype GristContextValue = { runtime: GristRuntime; api: GristApi }\n\nconst GristContext = createContext<GristContextValue | null>(null)\nGristContext.displayName = \"GristContext\"\n\n/** @internal The provider's (or the page's) runtime, for the SDK's own components. */\nexport function useGristRuntime(): GristContextValue | null {\n return useContext(GristContext)\n}\n\nfunction newConnection(options: UseGristOptions | undefined): GristContextValue {\n const runtime = createGristRuntime(options)\n return { runtime, api: createGristApi(runtime) }\n}\n\nlet pageConnection: GristContextValue | null = null\n\n/** @internal Tests: forget the page's connection and every Grist binding. */\nexport function resetGristForTests(): void {\n pageConnection = null\n resetGristReady()\n for (const s of ALL_STREAMS) s.reset()\n}\n\nexport const GristContextProvider = GristContext.Provider\nexport { newConnection }\n\nconst serverState = () => initialRuntimeState()\n\n/** The connection's state, re-rendering on every change. */\nexport function useGristState(connection: GristContextValue): GristRuntimeState {\n const { runtime } = connection\n useEffect(() => runtime.start(), [runtime])\n return useSyncExternalStore(runtime.subscribe, runtime.getState, serverState)\n}\n\ntype Mapped<TMapped> = { record: TMapped | null; records: TMapped[] | null; issues: readonly GristCellIssue[] }\n\nconst NO_ISSUES: readonly GristCellIssue[] = Object.freeze([])\n\n/** The mapped, checked record and records; recomputed only when they, the mappings or the options change. */\nfunction useMapped<TMapped>(state: GristRuntimeState, options: GristRuntimeOptions): Mapped<TMapped> {\n const { record, records, mappings } = state\n const { columns, schema } = options\n return useMemo(() => {\n const issues: GristCellIssue[] = []\n const rows =\n records && (columns?.length ? mappings !== null : true)\n ? records.map((r) => {\n const out = mapAndCheck<TMapped>(r, columns, mappings, schema)\n issues.push(...out.issues)\n return out.value\n })\n : null\n const selected = mapAndCheck<TMapped>(record, columns, mappings, schema)\n if (record && !records?.some((r) => r.id === record.id)) issues.push(...selected.issues)\n const mappedRecords = rows && rows.every((r) => r !== null) ? (rows as TMapped[]) : null\n return { record: selected.value, records: mappedRecords, issues: issues.length ? issues : NO_ISSUES }\n }, [record, records, mappings, columns, schema])\n}\n\nfunction buildResult<TRow, TMapped>(\n state: GristRuntimeState,\n mapped: Mapped<TMapped>,\n connection: GristContextValue,\n mapBack: (patch: Partial<TMapped>) => Record<string, unknown>,\n resolveMappedColumnId: (name: string) => string\n): UseGristResult<TRow, TMapped> {\n const { runtime, api } = connection\n const status = deriveStatus(state)\n const columns = runtime.options.columns\n return {\n ...api,\n status,\n isAvailable: state.connection === \"connecting\" ? null : state.connection !== \"not-embedded\" && state.connection !== \"unavailable\",\n isReady: status === \"ready\",\n error: deriveError(state),\n theme: state.theme,\n record: state.record as GristRowRecord<TRow> | null,\n records: state.records as GristRowRecord<TRow>[] | null,\n mappedRecord: mapped.record,\n mappedRecords: mapped.records,\n cellIssues: mapped.issues,\n mappings: state.mappings ?? EMPTY_MAPPINGS,\n columnMappingStatus: deriveColumnMappingStatus(columns, state.mappings),\n mode: state.isNewRecord ? \"new-row\" : state.record ? \"row\" : \"empty\",\n resolveMappedColumnId,\n mapBack,\n currentTableId: state.currentTableId,\n actionStatus: state.actionStatus,\n actionError: state.actionError,\n widgetOptions: state.widgetOptions,\n }\n}\n\nconst EMPTY_MAPPINGS: GristWidgetColumnMap = Object.freeze({}) as GristWidgetColumnMap\n\nfunction useGristResult<TRow, TMapped>(connection: GristContextValue): UseGristResult<TRow, TMapped> {\n const state = useGristState(connection)\n const mappings = state.mappings ?? EMPTY_MAPPINGS\n const { runtime } = connection\n const resolveMappedColumnId = useCallback(\n (name: string) => {\n const real = mappings[name]\n if (typeof real === \"string\" && real) return real\n if (Array.isArray(real) && typeof real[0] === \"string\") return real[0]\n return name\n },\n [mappings]\n )\n const mapBack = useCallback(\n (patch: Partial<TMapped>) => {\n const { fields, skipped } = mapBackPatch(patch as Record<string, unknown>, mappings)\n const previous = runtime.getState().mapBackSkipped\n if (previous.join(\"\\0\") !== skipped.join(\"\\0\")) runtime.update({ mapBackSkipped: skipped })\n return fields\n },\n [mappings, runtime]\n )\n const mapped = useMapped<TMapped>(state, runtime.options)\n return useMemo(\n () => buildResult<TRow, TMapped>(state, mapped, connection, mapBack, resolveMappedColumnId),\n [state, mapped, connection, mapBack, resolveMappedColumnId]\n )\n}\n\n/**\n * The widget's Grist state and API. Inside `<GristWidgetProvider>` it uses the\n * provider's connection and ignores `options`; outside one, the page's, made\n * with the first caller's `options`.\n */\nexport function useGrist<TRow = Record<string, unknown>, TMapped = Record<string, unknown>>(\n options?: UseGristOptions\n): UseGristResult<TRow, TMapped> {\n const fromProvider = useContext(GristContext)\n const connection = fromProvider ?? (pageConnection ??= newConnection(options))\n return useGristResult<TRow, TMapped>(connection)\n}\n\n/** `useGrist()` inside a provider, or null outside one: for components that also work without Grist. */\nexport function useGristOptional<TRow = Record<string, unknown>, TMapped = Record<string, unknown>>(): UseGristResult<\n TRow,\n TMapped\n> | null {\n const fromProvider = useContext(GristContext)\n // The hooks below run in both branches; the provider only decides which connection they read.\n const result = useGristResult<TRow, TMapped>(fromProvider ?? DETACHED)\n return fromProvider ? result : null\n}\n\n/** `useGrist()` inside `<GristWidgetProvider>`; throws outside one. */\nexport function useGristContext<TRow = Record<string, unknown>, TMapped = Record<string, unknown>>(): UseGristResult<\n TRow,\n TMapped\n> {\n if (!useContext(GristContext)) {\n throw new Error(\"useGristContext() must be used inside <GristWidgetProvider> (mountGristWidget renders one).\")\n }\n return useGrist<TRow, TMapped>()\n}\n\n/** A connection that never starts: what useGristOptional reads outside a provider. */\nconst DETACHED: GristContextValue = (() => {\n const state = initialRuntimeState()\n const runtime: GristRuntime = {\n options: {},\n getState: () => state,\n subscribe: () => () => {},\n start: () => () => {},\n reload: async () => {},\n update: () => {},\n }\n return { runtime, api: createGristApi(runtime) }\n})()\n\n/** @internal The nearest provider's connection and its state (idle outside one). */\nexport function useNearestGristState(): {\n connection: GristContextValue | null\n state: GristRuntimeState\n cellIssues: readonly GristCellIssue[]\n} {\n const connection = useContext(GristContext)\n const state = useGristState(connection ?? DETACHED)\n const { issues } = useMapped(state, (connection ?? DETACHED).runtime.options)\n return { connection, state, cellIssues: issues }\n}\n","import type {\n GristDocApi,\n GristDocumentMode,\n GristReplicaColumn,\n GristReplicaDocument,\n GristReplicaTable,\n} from \"../types\"\nimport { computeRowCount, decodeColumnarToReplicaRows, type GristColumnarTable } from \"./grist-table-data\"\nimport { inferGristFormulaKind } from \"./grist-schema-formula\"\nimport { parseGristWidgetOptionsCell } from \"./grist-widget-options\"\nimport { coerceGristDocApiRefRowId } from \"./grist-value-codec\"\n\nexport type ReplicaTableColumnMetaLite = {\n colRef?: number\n type?: string\n label?: string\n parentPos?: number\n isFormula?: boolean\n formula?: string\n description?: string\n widgetOptions?: Record<string, unknown>\n displayColRef?: number\n visibleColRef?: number\n}\n\nconst FORMULA_PREVIEW_MAX = 500\n\nfunction readCellStr(table: Record<string, unknown[]>, key: string, rowIndex: number): string | undefined {\n const col = table[key]\n if (!Array.isArray(col)) return undefined\n const v = col[rowIndex]\n if (v === null || v === undefined) return undefined\n if (typeof v === \"string\") return v\n if (typeof v === \"number\" || typeof v === \"boolean\") return String(v)\n return undefined\n}\n\nfunction readCellNum(table: Record<string, unknown[]>, key: string, rowIndex: number): number | undefined {\n const col = table[key]\n if (!Array.isArray(col)) return undefined\n const v = col[rowIndex]\n if (typeof v === \"number\" && !Number.isNaN(v)) return v\n if (typeof v === \"string\" && v.trim() !== \"\") {\n const n = Number(v)\n if (!Number.isNaN(n)) return n\n }\n return undefined\n}\n\nfunction pickColumnMeta(meta: ReplicaTableColumnMetaLite | undefined): GristReplicaColumn {\n if (!meta) return {}\n const out: GristReplicaColumn = {}\n if (meta.colRef !== undefined) out.colRef = meta.colRef\n if (meta.type) out.type = meta.type\n if (meta.label) out.label = meta.label\n if (meta.parentPos !== undefined) out.parentPos = meta.parentPos\n if (meta.isFormula) out.isFormula = true\n const formulaRaw = meta.formula?.trim() ?? \"\"\n out.formulaKind = inferGristFormulaKind(Boolean(meta.isFormula), formulaRaw)\n if (formulaRaw) {\n out.formula =\n formulaRaw.length > FORMULA_PREVIEW_MAX ? `${formulaRaw.slice(0, FORMULA_PREVIEW_MAX)}...` : formulaRaw\n }\n if (meta.description) out.description = meta.description\n if (meta.widgetOptions && Object.keys(meta.widgetOptions).length > 0) {\n out.widgetOptions = meta.widgetOptions\n }\n if (meta.displayColRef !== undefined) out.displayColRef = meta.displayColRef\n if (meta.visibleColRef !== undefined) out.visibleColRef = meta.visibleColRef\n return out\n}\n\nexport async function loadColumnMetadataByTable(\n docApi: GristDocApi\n): Promise<Map<string, Map<string, ReplicaTableColumnMetaLite>>> {\n const byTable = new Map<string, Map<string, ReplicaTableColumnMetaLite>>()\n try {\n const tables = await docApi.fetchTable(\"_grist_Tables\")\n const columns = await docApi.fetchTable(\"_grist_Tables_column\")\n const tableIds = tables.tableId\n const tableInternalIds = tables.id\n if (!Array.isArray(tableIds) || !Array.isArray(tableInternalIds)) return byTable\n\n const internalIdToTableId = new Map<number, string>()\n for (let i = 0; i < tableInternalIds.length; i++) {\n const tid = tableIds[i]\n const iid = coerceGristDocApiRefRowId(tableInternalIds[i])\n if (typeof tid === \"string\" && iid !== undefined) internalIdToTableId.set(iid, tid)\n }\n\n const parentIds = columns.parentId\n const colIds = columns.colId\n const columnIds = columns.id\n if (\n !Array.isArray(parentIds) ||\n !Array.isArray(colIds) ||\n !Array.isArray(columnIds) ||\n parentIds.length !== colIds.length ||\n colIds.length !== columnIds.length\n ) {\n return byTable\n }\n\n const n = parentIds.length\n for (let i = 0; i < n; i++) {\n const parentRowId = coerceGristDocApiRefRowId(parentIds[i])\n const colRef = coerceGristDocApiRefRowId(columnIds[i])\n const colId = colIds[i]\n if (parentRowId === undefined || colRef === undefined || typeof colId !== \"string\") continue\n const tableId = internalIdToTableId.get(parentRowId)\n if (!tableId) continue\n\n let colMap = byTable.get(tableId)\n if (!colMap) {\n colMap = new Map()\n byTable.set(tableId, colMap)\n }\n\n const parentPos = readCellNum(columns, \"parentPos\", i)\n const isFormulaCol = columns.isFormula\n const isFormula = Array.isArray(isFormulaCol) ? Boolean(isFormulaCol[i]) : false\n\n const woCol = columns.widgetOptions\n const widgetOptions =\n Array.isArray(woCol) && i < woCol.length ? parseGristWidgetOptionsCell(woCol[i]) : undefined\n const displayColRef = coerceGristDocApiRefRowId(\n Array.isArray(columns.displayCol) ? columns.displayCol[i] : undefined\n )\n const visibleColRef = coerceGristDocApiRefRowId(\n Array.isArray(columns.visibleCol) ? columns.visibleCol[i] : undefined\n )\n\n colMap.set(colId, {\n colRef,\n type: readCellStr(columns, \"type\", i),\n label: readCellStr(columns, \"label\", i),\n parentPos: parentPos !== undefined ? parentPos : undefined,\n isFormula,\n formula: readCellStr(columns, \"formula\", i),\n description: readCellStr(columns, \"description\", i) ?? readCellStr(columns, \"descr\", i),\n widgetOptions,\n displayColRef,\n visibleColRef,\n })\n }\n } catch {\n // Metadata is best-effort; document build still works from cell data alone.\n }\n return byTable\n}\n\nexport function orderedColumnIds(\n data: Record<string, unknown[]>,\n metaByCol: Map<string, ReplicaTableColumnMetaLite>\n): string[] {\n const keys = Object.keys(data).filter((k) => Array.isArray(data[k]))\n keys.sort((a, b) => {\n const pa = metaByCol.get(a)?.parentPos\n const pb = metaByCol.get(b)?.parentPos\n if (pa !== undefined && pb !== undefined && pa !== pb) return pa - pb\n if (pa !== undefined && pb === undefined) return -1\n if (pa === undefined && pb !== undefined) return 1\n return a.localeCompare(b)\n })\n return keys\n}\n\n/** Build replica column metadata from columnar `fetchTable` + `_grist_Tables_column` maps. */\nexport function buildReplicaColumnsFromColumnar(\n data: Record<string, unknown[]>,\n colMeta: Map<string, ReplicaTableColumnMetaLite>\n): Record<string, GristReplicaColumn> {\n const columnIds = orderedColumnIds(data, colMeta)\n const columns: Record<string, GristReplicaColumn> = {}\n for (const colId of columnIds) {\n const arr = data[colId]\n if (!Array.isArray(arr)) continue\n const meta = colMeta.get(colId)\n columns[colId] = pickColumnMeta(meta)\n }\n return columns\n}\n\nfunction rowModeFromIncludeRows(includeRows: false | \"samples\" | \"full\"): GristDocumentMode {\n if (includeRows === false) return \"schema-only\"\n if (includeRows === \"samples\") return \"schema+samples\"\n return \"schema+data\"\n}\n\nexport type BuildReplicaDocumentFromDocApiOptions = {\n /** When false (default), skip fetching row data for `tableId` starting with `_grist`. */\n includeSystemTableData?: boolean\n /**\n * Row bodies: omit (`false`), first N (`samples`), or full decode (`full`).\n * Default `samples`.\n */\n includeRows?: false | \"samples\" | \"full\"\n /** Max rows per table when `includeRows` is `samples`. Default 10. */\n sampleRowLimit?: number\n /** Set on the replica as `source` for host logging / provenance. */\n source?: string\n}\n\n/**\n * Build {@link GristReplicaDocument} from a host `docApi`:\n * metadata from `_grist_Tables` / `_grist_Tables_column` when readable, plus optional decoded `rows`.\n *\n * Prefer {@link useGrist}'s `buildReplicaDocumentFromDocApi()` when you already use the primary hook.\n */\nexport async function buildReplicaDocumentFromDocApi(\n docApi: GristDocApi,\n options?: BuildReplicaDocumentFromDocApiOptions\n): Promise<GristReplicaDocument> {\n const includeSystemTableData = options?.includeSystemTableData ?? false\n const includeRows = options?.includeRows ?? \"samples\"\n const sampleRowLimit = options?.sampleRowLimit ?? 10\n const rowMode = rowModeFromIncludeRows(includeRows)\n\n const metaByTable = await loadColumnMetadataByTable(docApi)\n\n let docName: string | undefined\n try {\n docName = String(await Promise.resolve(docApi.getDocName()))\n } catch {\n docName = undefined\n }\n\n const tableIdsRaw = await Promise.resolve(docApi.listTables())\n const tableIds = Array.isArray(tableIdsRaw) ? [...tableIdsRaw] : []\n\n const tables: Record<string, GristReplicaTable> = {}\n\n for (const tableId of tableIds) {\n const omitData = !includeSystemTableData && tableId.startsWith(\"_grist\")\n if (omitData) {\n tables[tableId] = {\n rowCount: 0,\n dataOmitted: true,\n dataOmittedReason:\n \"Row scan skipped for tables whose id starts with `_grist` unless `includeSystemTableData` is true.\",\n columns: {},\n }\n continue\n }\n\n try {\n const data = (await docApi.fetchTable(tableId)) as GristColumnarTable\n const rowCount = computeRowCount(data)\n const colMeta = metaByTable.get(tableId) ?? new Map<string, ReplicaTableColumnMetaLite>()\n const columnIds = orderedColumnIds(data, colMeta)\n const columns = buildReplicaColumnsFromColumnar(data, colMeta)\n\n const table: GristReplicaTable = { columns, rowCount }\n if (includeRows === \"full\") {\n table.rows = decodeColumnarToReplicaRows(data, columnIds, columns)\n } else if (includeRows === \"samples\") {\n table.rows = decodeColumnarToReplicaRows(data, columnIds, columns, sampleRowLimit)\n }\n tables[tableId] = table\n } catch (err) {\n tables[tableId] = {\n rowCount: 0,\n error: err instanceof Error ? err.message : String(err),\n columns: {},\n }\n }\n }\n\n const out: GristReplicaDocument = {\n generatedAt: new Date().toISOString(),\n docName,\n mode: rowMode,\n tables,\n }\n if (options?.source !== undefined && options.source !== \"\") {\n out.source = options.source\n }\n return out\n}\n","export type GristColumnLike = {\n formula?: string\n}\n\nexport type GristNoiseColumnsOptions = {\n excludeId?: boolean\n excludeGristHelpers?: boolean\n excludeLoggingColumns?: boolean\n /**\n * When `true`, treat Grist's `manualSort` column as noise (omit from filtered replicas).\n * Default `false` — `manualSort` is kept unless you opt in.\n */\n excludeManualSort?: boolean\n}\n\nconst NOISE_COLUMN_FORMULAS = new Set([\"now()\"])\n\nfunction normalizeFormulaForComparison(formula: string): string {\n return formula.trim().toLowerCase().replace(/\\s+/g, \"\")\n}\n\n/**\n * Grist-centric \"technical column\" detection used by document hooks and widgets.\n *\n * - `id` (when {@link GristNoiseColumnsOptions.excludeId} is true — default)\n * - `manualSort` (only when {@link GristNoiseColumnsOptions.excludeManualSort} is true)\n * - `gristHelper_*` (when `excludeGristHelpers` is true — default)\n * - trigger/logging formulas (`NOW()`, `user.*`) (when `excludeLoggingColumns` is true — default)\n */\nexport function isGristNoiseColumn(\n colId: string,\n col?: GristColumnLike,\n options?: GristNoiseColumnsOptions\n): boolean {\n const excludeId = options?.excludeId ?? true\n const excludeGristHelpers = options?.excludeGristHelpers ?? true\n const excludeLoggingColumns = options?.excludeLoggingColumns ?? true\n const excludeManualSort = options?.excludeManualSort ?? false\n\n if (excludeId && colId === \"id\") return true\n if (excludeManualSort && colId === \"manualSort\") return true\n if (excludeGristHelpers && colId.startsWith(\"gristHelper_\")) return true\n\n if (excludeLoggingColumns) {\n const formula = typeof col?.formula === \"string\" ? normalizeFormulaForComparison(col.formula) : \"\"\n if (formula && NOISE_COLUMN_FORMULAS.has(formula)) return true\n if (formula.startsWith(\"user.\")) return true\n }\n\n return false\n}\n","/**\n * `useGrist()`'s methods, created once per runtime: every one is\n * referentially stable for the widget's lifetime, and reads `grist` when\n * called (the emulator installs and removes it in tests).\n */\n\nimport { loadColumnMetadataByTable } from \"../helpers/build-replica-document\"\nimport { isGristNoiseColumn, type GristNoiseColumnsOptions } from \"../helpers/grist-columns-filters\"\nimport { fetchAttachmentBlob, getAttachmentDownloadUrl, type GristFetchedAttachmentBlob } from \"../helpers/grist-attachment-download\"\nimport { uploadGristAttachment, type GristAttachmentUploadResult } from \"../helpers/grist-attachment-upload\"\nimport { fetchWithGristAuth } from \"../helpers/grist-fetch-with-auth\"\nimport { fetchGristTableRows, type FetchGristTableRowsOptions, type GristColumnarTable } from \"../helpers/grist-table-data\"\nimport type { GristUserActionTuple } from \"../helpers/grist-user-actions\"\nimport type {\n GristApplyUserActionsOptions,\n GristCursorPos,\n GristDocApi,\n GristFetchSelectedOptions,\n GristRowRecord,\n GristTableOperations,\n} from \"../types\"\nimport type { GristRuntime } from \"./runtime\"\n\nexport type ListTablesOptions = {\n /** Include Grist's own tables (`_grist_*`, `GristHidden_*`). */\n includeSystem?: boolean\n}\n\nexport type ListColumnsOptions = GristNoiseColumnsOptions & {\n /** Include every column, Grist's helper and bookkeeping ones too. */\n includeSystem?: boolean\n}\n\nexport type GristColumnInfo = {\n colId: string\n type?: string\n label?: string\n isFormula?: boolean\n formula?: string\n description?: string\n}\n\nexport type GristApi = {\n reload: () => Promise<void>\n fetchSelectedTable: (options?: GristFetchSelectedOptions) => Promise<GristColumnarTable>\n fetchTable: (tableId: string) => Promise<GristColumnarTable>\n fetchTableRows: <T extends Record<string, unknown> = Record<string, unknown>>(\n tableId: string,\n options?: FetchGristTableRowsOptions\n ) => Promise<GristRowRecord<T>[]>\n listTables: (options?: ListTablesOptions) => Promise<string[]>\n listColumns: (tableId: string, options?: ListColumnsOptions) => Promise<GristColumnInfo[]>\n table: GristTableOperations\n getTable: (tableId: string) => GristTableOperations\n applyActions: (actions: GristUserActionTuple[], options?: GristApplyUserActionsOptions) => Promise<unknown>\n setWidgetOptions: (options: Record<string, unknown>) => Promise<void>\n patchWidgetOptions: (patch: Record<string, unknown>) => Promise<void>\n setCursorPosition: (pos: GristCursorPos) => Promise<void>\n setLinkedRowSelection: (rowIds: number[] | null) => Promise<void>\n getAttachmentUrl: (attachmentId: string, options?: { readOnly?: boolean }) => Promise<string>\n fetchAttachmentBlob: (attachmentId: string, options?: { readOnly?: boolean }) => Promise<GristFetchedAttachmentBlob>\n uploadAttachment: (file: Blob | File, options?: { fileName?: string }) => Promise<GristAttachmentUploadResult>\n fetchWithAuth: (path: string, init?: RequestInit & { readOnly?: boolean }) => Promise<Response>\n}\n\nconst ACCESS_ERROR = [/access not granted/i, /need higher access level/i, /requires.*full.*access/i, /RPC_ONCALL_ERROR Access/i]\n\nexport function isAccessInsufficientError(message: string): boolean {\n return ACCESS_ERROR.some((re) => re.test(message))\n}\n\nconst message = (err: unknown) => (err instanceof Error ? err.message : String(err))\n\nexport function createGristApi(runtime: GristRuntime): GristApi {\n const docApi = (): GristDocApi => {\n if (runtime.getState().connection !== \"ready\" || typeof grist === \"undefined\" || !grist.docApi) {\n throw new Error(\"Grist is not ready: wait for useGrist().status === \\\"ready\\\".\")\n }\n return grist.docApi\n }\n\n /** A read: an access refusal is kept for the alerts, cleared by the next read that succeeds. */\n const read = async <T>(fn: () => Promise<T>): Promise<T> => {\n try {\n const out = await fn()\n if (runtime.getState().readError) runtime.update({ readError: null })\n return out\n } catch (err) {\n if (isAccessInsufficientError(message(err))) runtime.update({ readError: message(err) })\n throw err\n }\n }\n\n /** A write: tracked in `actionStatus` / `actionError`. */\n const write = async <T>(fn: () => Promise<T>): Promise<T> => {\n runtime.update({ actionStatus: \"running\", actionError: null })\n try {\n const out = await fn()\n runtime.update({ actionStatus: \"idle\" })\n return out\n } catch (err) {\n runtime.update({ actionStatus: \"error\", actionError: message(err) })\n throw err\n }\n }\n\n const tableOps = (resolve: () => GristTableOperations): GristTableOperations => ({\n getTableId: () => resolve().getTableId(),\n create: ((records: never, opts?: never) => write(() => resolve().create(records, opts))) as GristTableOperations[\"create\"],\n update: (records, opts) => write(() => resolve().update(records, opts)),\n upsert: (records, opts) => write(() => resolve().upsert(records, opts)),\n destroy: (ids) => write(() => resolve().destroy(ids)),\n })\n const tables = new Map<string, GristTableOperations>()\n\n return {\n reload: () => runtime.reload(),\n\n fetchSelectedTable: (options) =>\n read(async () => {\n const impl = docApi().fetchSelectedTable ?? grist.fetchSelectedTable\n if (!impl) throw new Error(\"fetchSelectedTable is not available in this Grist version\")\n return (await impl({ keepEncoded: false, ...options })) as GristColumnarTable\n }),\n fetchTable: (tableId) => read(async () => (await docApi().fetchTable(tableId)) as GristColumnarTable),\n fetchTableRows: (tableId, options) => read(() => fetchGristTableRows(docApi(), tableId, options ?? {})) as never,\n listTables: (options) =>\n read(async () => {\n const all = [...(await docApi().listTables())]\n return options?.includeSystem ? all : all.filter((t) => !t.startsWith(\"_grist\") && !t.startsWith(\"GristHidden_\"))\n }),\n listColumns: (tableId, options) =>\n read(async () => {\n const meta = (await loadColumnMetadataByTable(docApi())).get(tableId)\n if (!meta) return []\n const noise: GristNoiseColumnsOptions = {\n excludeId: options?.excludeId ?? true,\n excludeGristHelpers: options?.excludeGristHelpers ?? true,\n excludeLoggingColumns: options?.excludeLoggingColumns ?? true,\n excludeManualSort: options?.excludeManualSort ?? true,\n }\n return [...meta]\n .filter(([colId, m]) => options?.includeSystem || !isGristNoiseColumn(colId, m, noise))\n .map(([colId, m]) => ({ colId, type: m.type, label: m.label, isFormula: m.isFormula, formula: m.formula, description: m.description }))\n }),\n\n table: tableOps(() => {\n if (!grist.selectedTable) throw new Error(\"grist.selectedTable is not available in this Grist version\")\n return grist.selectedTable\n }),\n getTable: (tableId) => {\n let ops = tables.get(tableId)\n if (!ops) {\n tables.set(\n tableId,\n (ops = tableOps(() => {\n if (typeof grist.getTable !== \"function\") throw new Error(\"grist.getTable is not available in this Grist version\")\n return grist.getTable(tableId)\n }))\n )\n }\n return ops\n },\n applyActions: (actions, options) => write(() => docApi().applyUserActions(actions, options)),\n\n setWidgetOptions: async (options) => {\n await grist.setOptions(options)\n },\n patchWidgetOptions: async (patch) => {\n const current = ((await grist.getOptions()) as Record<string, unknown> | null) ?? {}\n await grist.setOptions({ ...current, ...patch })\n },\n\n setCursorPosition: async (pos) => {\n if (!grist.setCursorPos) throw new Error(\"setCursorPos is not available in this Grist version\")\n await grist.setCursorPos(pos)\n },\n setLinkedRowSelection: async (rowIds) => {\n if (!grist.setSelectedRows) throw new Error(\"setSelectedRows is not available in this Grist version\")\n await grist.setSelectedRows(rowIds)\n },\n\n getAttachmentUrl: (id, options) => read(() => getAttachmentDownloadUrl(docApi(), id, options)),\n fetchAttachmentBlob: (id, options) => read(() => fetchAttachmentBlob(docApi(), id, options)),\n uploadAttachment: (file, options) => write(() => uploadGristAttachment(docApi(), file, options)),\n fetchWithAuth: (path, init) => read(() => fetchWithGristAuth(docApi(), path, init)),\n }\n}\n","import type { GristColumnsToMap, GristColumnToMap, GristWidgetColumnMap } from \"../types\"\n\nexport type ValidateColumnMappingsResult = {\n ok: boolean\n /**\n * `true` while the host has not yet reported column mappings (e.g. between\n * `grist.ready()` resolving and the first `onRecord` / `onRecords` callback,\n * or before `sectionApi.mappings()` returns). Callers should not gate UI or\n * emit mapping alerts while pending.\n */\n pending?: boolean\n /** Logical names of required columns the user has not yet mapped. */\n missing: string[]\n /** Logical names of `allowMultiple` columns mapped to an empty list. */\n emptyMultiples: string[]\n}\n\n/**\n * Merges mapping payloads from `onRecord`, `onRecords`, and `sectionApi.mappings()`.\n * Later sources win; `undefined` sources are skipped; `null` means \"host reported\n * no mappings\" but still counts as a known (empty) payload.\n */\nexport function mergeWidgetColumnMaps(\n ...sources: (GristWidgetColumnMap | null | undefined)[]\n): GristWidgetColumnMap | null | undefined {\n let merged: GristWidgetColumnMap = {}\n let sawDefined = false\n for (const src of sources) {\n if (src === undefined) continue\n sawDefined = true\n if (src === null) continue\n merged = { ...merged, ...src }\n }\n if (!sawDefined) return undefined\n return merged\n}\n\nfunction asColumnSpec(entry: string | GristColumnToMap): GristColumnToMap {\n return typeof entry === \"string\" ? { name: entry } : entry\n}\n\n/**\n * Verifies that the current Grist mappings cover every required column declared\n * in `grist.ready({ columns })`.\n *\n * Use this before reading `mappedRecord` so you can render a \"please configure\n * the widget\" prompt instead of a confusing `null`.\n */\nexport function validateColumnMappings(\n spec: GristColumnsToMap | undefined | null,\n mappings: GristWidgetColumnMap | null | undefined\n): ValidateColumnMappingsResult {\n const missing: string[] = []\n const emptyMultiples: string[] = []\n if (!spec) return { ok: true, pending: false, missing, emptyMultiples }\n\n const m = mappings ?? {}\n for (const raw of spec) {\n const col = asColumnSpec(raw)\n if (col.optional) continue\n const value = m[col.name]\n if (col.allowMultiple) {\n if (value === undefined) {\n missing.push(col.name)\n } else if (!Array.isArray(value) || value.length === 0) {\n emptyMultiples.push(col.name)\n }\n } else {\n if (value === undefined || value === null || value === \"\") missing.push(col.name)\n }\n }\n return {\n ok: missing.length === 0 && emptyMultiples.length === 0,\n pending: false,\n missing,\n emptyMultiples,\n }\n}\n\n/** Status while waiting for the host to report mappings (see `pending`). */\nexport const pendingColumnMappingStatus: ValidateColumnMappingsResult = {\n ok: true,\n pending: true,\n missing: [],\n emptyMultiples: [],\n}\n","/**\n * What `useGrist()` shows, derived from the runtime state: status, error,\n * column-mapping status, the mapped record, and the access check. Pure\n * functions, so they are tested without React or Grist.\n */\n\nimport { validateColumnMappings, type ValidateColumnMappingsResult } from \"../helpers/grist-mappings\"\nimport type { GristColumnsToMap, GristRequiredAccess, GristWidgetColumnMap } from \"../types\"\nimport type { GristRuntimeState } from \"./runtime\"\n\n/** The widget's connection to Grist, as `useGrist().status` reports it. */\nexport type GristWidgetStatus = \"booting\" | \"ready\" | \"unavailable\" | \"error\"\n\nexport const ACCESS_RANK: Record<GristRequiredAccess, number> = { none: 0, \"read table\": 1, full: 2 }\n\nexport function parseAccess(raw: unknown): GristRequiredAccess | null {\n return raw === \"none\" || raw === \"read table\" || raw === \"full\" ? raw : null\n}\n\nexport function accessLabel(level: GristRequiredAccess): string {\n return level === \"full\" ? \"Full document access\" : level === \"read table\" ? \"Read selected table\" : \"No document access\"\n}\n\n/** Grist granted less than the widget declared (Grist reports it with the widget options). */\nexport function accessDenied(state: GristRuntimeState): boolean {\n return state.grantedAccess !== null && ACCESS_RANK[state.grantedAccess] < ACCESS_RANK[state.declaredAccess]\n}\n\nexport function deriveStatus(state: GristRuntimeState): GristWidgetStatus {\n switch (state.connection) {\n case \"connecting\":\n return \"booting\"\n case \"not-embedded\":\n case \"unavailable\":\n return \"unavailable\"\n case \"error\":\n return \"error\"\n case \"ready\":\n return accessDenied(state) ? \"error\" : \"ready\"\n }\n}\n\nexport function deriveError(state: GristRuntimeState): string | null {\n if (state.connection === \"not-embedded\") return \"This page is not embedded in a Grist document.\"\n if (state.connection === \"unavailable\") return \"The Grist plugin API (grist-plugin-api.js) did not load.\"\n if (state.connection === \"error\") return state.connectionError\n if (state.connection === \"ready\" && accessDenied(state)) {\n return `Grist granted \"${accessLabel(state.grantedAccess!)}\"; this widget needs \"${accessLabel(state.declaredAccess)}\". Set the access level in the Custom widget settings.`\n }\n return null\n}\n\nconst MAPPINGS_OK: ValidateColumnMappingsResult = Object.freeze({ ok: true, pending: false, missing: [], emptyMultiples: [] }) as ValidateColumnMappingsResult\nconst MAPPINGS_PENDING: ValidateColumnMappingsResult = Object.freeze({ ok: true, pending: true, missing: [], emptyMultiples: [] }) as ValidateColumnMappingsResult\n\n/** Whether the declared columns are mapped: pending until Grist reports mappings. */\nexport function deriveColumnMappingStatus(\n columns: GristColumnsToMap | undefined,\n mappings: GristWidgetColumnMap | null\n): ValidateColumnMappingsResult {\n if (!columns?.length) return MAPPINGS_OK\n if (mappings === null) return MAPPINGS_PENDING\n return validateColumnMappings(columns, mappings)\n}\n\n/**\n * A logical-name patch as real column ids, for a write. A column mapped to\n * several Grist columns (`allowMultiple`) can't be written back and is\n * reported in `skipped`; a name with no mapping passes through unchanged.\n */\nexport function mapBackPatch(\n patch: Record<string, unknown>,\n mappings: GristWidgetColumnMap\n): { fields: Record<string, unknown>; skipped: string[] } {\n const fields: Record<string, unknown> = {}\n const skipped: string[] = []\n for (const [name, value] of Object.entries(patch)) {\n if (value === undefined) continue\n const real = mappings[name]\n if (Array.isArray(real)) skipped.push(name)\n else fields[typeof real === \"string\" && real ? real : name] = value\n }\n return { fields, skipped }\n}\n","import type { GristWidgetInteraction, GristWidgetLinkingInfo } from \"../types\"\n\n/**\n * Parse `InteractionOptions.linking` from a Grist `onOptions` settings payload.\n */\nexport function parseGristWidgetLinkingInfo(raw: unknown): GristWidgetLinkingInfo | undefined {\n if (!raw || typeof raw !== \"object\" || !(\"asTarget\" in raw)) return undefined\n const linking = raw as { asTarget: unknown; asSource?: unknown }\n return {\n asTarget: linking.asTarget == null ? null : String(linking.asTarget),\n asSource: Boolean(linking.asSource),\n }\n}\n\n/**\n * Normalize the second argument to `grist.onOptions` (Grist `InteractionOptions`).\n * Hosts use `accessLevel` (camelCase); the emulator uses `access_level`.\n */\nexport function normalizeWidgetInteraction(\n interaction: GristWidgetInteraction | null\n): GristWidgetInteraction | null {\n if (!interaction || typeof interaction !== \"object\") return interaction\n const raw = interaction as Record<string, unknown>\n const access_level =\n typeof raw.access_level === \"string\"\n ? raw.access_level\n : typeof raw.accessLevel === \"string\"\n ? raw.accessLevel\n : undefined\n const linking = parseGristWidgetLinkingInfo(raw.linking)\n return {\n ...interaction,\n ...(access_level ? { access_level } : {}),\n ...(linking ? { linking } : {}),\n }\n}\n","/**\n * Grist's event streams, bound once per page.\n *\n * `grist.onRecord`, `onRecords`, `onOptions`, `onNewRecord` and `on(\"message\")`\n * are add-only: there is no `off`. Binding them in every provider (React's\n * StrictMode mounts twice; a widget may remount) would stack handlers for the\n * page's lifetime. Each stream here binds at its first subscriber and fans out\n * to the current ones; a late subscriber gets the last value at once.\n *\n * Records are bound with the plugin API's decoded rows (`keepEncoded: false`,\n * rows for `onRecords`), the shape widget code reads.\n */\n\nimport { normalizeWidgetInteraction } from \"../helpers/grist-widget-interaction\"\nimport type { GristWidgetColumnMap, GristWidgetInteraction } from \"../types\"\n\ntype Listener<T> = (value: T) => void\n\nexport class HostStream<T> {\n private listeners = new Set<Listener<T>>()\n private bound = false\n private has = false\n private last: T | undefined\n\n constructor(private readonly bind: (emit: (value: T) => void) => void) {}\n\n subscribe(listener: Listener<T>): () => void {\n this.listeners.add(listener)\n if (!this.bound) {\n this.bound = true\n try {\n this.bind((value) => this.emit(value))\n } catch (err) {\n console.error(\"[grist-widget-sdk] could not subscribe to a Grist event:\", err)\n }\n }\n if (this.has) listener(this.last as T)\n return () => {\n this.listeners.delete(listener)\n }\n }\n\n peek(): T | undefined {\n return this.last\n }\n\n /** Tests: deliver a value as if Grist had sent it. */\n emit(value: T): void {\n this.has = true\n this.last = value\n for (const l of [...this.listeners]) l(value)\n }\n\n /** Tests: forget the binding, so a new `window.grist` binds afresh. */\n reset(): void {\n this.listeners.clear()\n this.bound = false\n this.has = false\n this.last = undefined\n }\n}\n\nexport type RecordPayload = { record: Record<string, unknown> | null; mappings: GristWidgetColumnMap | null }\nexport type RecordsPayload = { records: Record<string, unknown>[]; mappings: GristWidgetColumnMap | null }\nexport type OptionsPayload = { options: Record<string, unknown> | null; interaction: GristWidgetInteraction | null }\nexport type NewRecordPayload = { mappings: GristWidgetColumnMap | null }\n\nconst asMappings = (m: unknown) => (m && typeof m === \"object\" ? (m as GristWidgetColumnMap) : null)\n\nexport const recordStream = new HostStream<RecordPayload>((emit) => {\n grist.onRecord((record, mappings) => emit({ record, mappings: asMappings(mappings) }), { keepEncoded: false })\n\n // Grist's RecordNotifier posts `{ tableId, rowId }` on a cursor move. The\n // plugin API's onRecord handles it, but refetching here when the row\n // changes keeps a widget from sticking on its first row if that path is\n // skipped (seen in production iframes).\n const fetchSelectedRecord = grist.fetchSelectedRecord ?? grist.docApi?.fetchSelectedRecord\n if (typeof grist.on !== \"function\" || typeof fetchSelectedRecord !== \"function\") return\n let lastRowId: number | undefined\n grist.on(\"message\", async (msg: unknown) => {\n const host = msg as { tableId?: string; rowId?: unknown } | null\n if (!host?.tableId || typeof host.rowId !== \"number\" || host.rowId === lastRowId) return\n lastRowId = host.rowId\n try {\n const record = await fetchSelectedRecord(host.rowId, { keepEncoded: false })\n emit({ record, mappings: recordStream.peek()?.mappings ?? null })\n } catch (err) {\n console.error(\"[grist-widget-sdk] fetchSelectedRecord on a cursor move failed:\", err)\n }\n })\n})\n\nexport const recordsStream = new HostStream<RecordsPayload>((emit) => {\n grist.onRecords((records, mappings) => emit({ records, mappings: asMappings(mappings) }), {\n keepEncoded: false,\n format: \"rows\",\n })\n})\n\nexport const optionsStream = new HostStream<OptionsPayload>((emit) => {\n grist.onOptions((options, interaction) =>\n emit({\n options: options ? { ...options } : null,\n interaction: normalizeWidgetInteraction((interaction as GristWidgetInteraction | null) ?? null),\n })\n )\n})\n\nexport const newRecordStream = new HostStream<NewRecordPayload>((emit) => {\n if (typeof grist.onNewRecord !== \"function\") return\n grist.onNewRecord((mappings) => emit({ mappings: asMappings(mappings) }))\n})\n\n/** Grist's host messages (`grist.on(\"message\")`): the theme travels here. */\nexport const messageStream = new HostStream<unknown>((emit) => {\n if (typeof grist.on !== \"function\") return\n grist.on(\"message\", (msg: unknown) => emit(msg))\n})\n\nexport const ALL_STREAMS = [recordStream, recordsStream, optionsStream, newRecordStream, messageStream] as const\n","/**\n * Single-call wrapper around `grist.ready()`.\n *\n * Grist's contract is \"call ready once\". Multiple `useGristReady` calls (or\n * `useGristWidget` from sibling components) would otherwise race. We:\n *\n * - Coalesce concurrent calls into one in-flight promise.\n * - Re-call `grist.ready` only when `requiredAccess` widens (so an action-capable\n * hook can upgrade a previously read-only handshake).\n */\n\nimport type { GristColumnsToMap, GristReadyOptions, GristRequiredAccess } from \"../types\"\n\nconst ACCESS_RANK: Record<GristRequiredAccess, number> = {\n none: 0,\n \"read table\": 1,\n full: 2,\n}\n\nlet inFlight: Promise<void> | null = null\nlet lastAccess: GristRequiredAccess | null = null\nlet lastColumnNames: ReadonlySet<string> | null = null\n\nfunction columnNamesOf(columns: GristColumnsToMap | undefined): Set<string> {\n return new Set((columns ?? []).map((c) => (typeof c === \"string\" ? c : c.name)))\n}\n\n/**\n * Re-init whenever the new payload asks for strictly more than what's\n * already cached: a higher access level, or a column name the cached\n * payload didn't declare. Prevents a bare fallback caller (e.g. a status\n * chip with no declared columns) from permanently sticking a widget's real,\n * richer requirements to the host once it happens to win the initial race.\n */\nfunction shouldReinit(next: GristRequiredAccess, nextColumns: ReadonlySet<string>): boolean {\n if (!lastAccess) return true\n if (ACCESS_RANK[next] > ACCESS_RANK[lastAccess]) return true\n for (const name of nextColumns) {\n if (!lastColumnNames?.has(name)) return true\n }\n return false\n}\n\n/**\n * Calls `grist.ready` at most once per page (re-called only if access widens\n * or previously-undeclared columns are requested).\n * Returns the same promise for all concurrent callers.\n */\nexport function ensureGristReady(payload: GristReadyOptions): Promise<void> {\n const access = payload.requiredAccess ?? \"read table\"\n const columns = columnNamesOf(payload.columns)\n if (inFlight && !shouldReinit(access, columns)) return inFlight\n\n lastAccess = access\n lastColumnNames = columns\n const next = Promise.resolve().then(() => {\n const result = grist.ready(payload)\n return result instanceof Promise ? result : Promise.resolve()\n })\n\n inFlight = next.catch((err) => {\n inFlight = null\n lastAccess = null\n lastColumnNames = null\n throw err\n })\n return inFlight\n}\n\n/**\n * Forget the cached ready state. Subsequent calls to {@link ensureGristReady}\n * will re-issue `grist.ready` even at the same access level.\n *\n * Production uses: the handshake manager's `reload()` clears the singleton so\n * a soft retry triggers a fresh `grist.ready` (otherwise the cached promise\n * would short-circuit and the user-visible reload would be a no-op).\n *\n * Tests use this between test cases when swapping `window.grist`.\n */\nexport function resetGristReady(): void {\n inFlight = null\n lastAccess = null\n lastColumnNames = null\n}\n\n/** @deprecated Use {@link resetGristReadySingleton}. Kept for test back-compat. */\n","export type GristThemeName = \"light\" | \"dark\"\n\n/**\n * Normalize theme from `grist.on(\"message\")` host payloads (`msg.theme`).\n * Grist sends a theme object with `appearance`; some hosts may send a bare string.\n */\nexport function parseGristThemePayload(payload: unknown): GristThemeName | null {\n if (!payload || typeof payload !== \"object\") return null\n const raw = payload as Record<string, unknown>\n const top = raw.theme\n if (top === \"light\" || top === \"dark\") return top\n if (top && typeof top === \"object\") {\n const appearance = (top as Record<string, unknown>).appearance\n if (appearance === \"light\" || appearance === \"dark\") return appearance\n }\n return null\n}\n","/**\n * The widget's connection to Grist: one store, one `connect()`.\n *\n * The template loads `grist-plugin-api.js` with a classic blocking script, so\n * `window.grist` is there when the widget starts, or it never will be: the\n * check is synchronous (with one more look at `load`, for a page that loads\n * the script asynchronously). Then `grist.ready()` once, and every Grist\n * stream (records, options, mappings, theme) feeds one immutable state that\n * React reads through `useSyncExternalStore`. No polling, no heartbeat: the\n * iframe lives and dies with the Grist page, and a failed call fails where it\n * was made.\n */\n\nimport { parseGristThemePayload } from \"../helpers/grist-theme-payload\"\nimport type { GristSdkAlertKind } from \"../helpers/grist-sdk-alerts\"\nimport type { StandardSchema } from \"./cells\"\nimport type {\n GristReadyOptions,\n GristRequiredAccess,\n GristRowRecord,\n GristWidgetColumnMap,\n GristWidgetInteraction,\n} from \"../types\"\nimport { parseAccess } from \"./derive\"\nimport { messageStream, newRecordStream, optionsStream, recordsStream, recordStream } from \"./host\"\nimport { ensureGristReady, resetGristReady } from \"./ready\"\n\nexport type GristConnection = \"connecting\" | \"ready\" | \"not-embedded\" | \"unavailable\" | \"error\"\nexport type GristTheme = \"light\" | \"dark\"\nexport type GristWidgetActionStatus = \"idle\" | \"running\" | \"error\"\n\nexport type GristRuntimeState = {\n connection: GristConnection\n /** Why the connection failed (`connection === \"error\"`). */\n connectionError: string | null\n declaredAccess: GristRequiredAccess\n /** The access Grist reports with the widget options; null before it does. */\n grantedAccess: GristRequiredAccess | null\n record: GristRowRecord | null\n records: GristRowRecord[] | null\n isNewRecord: boolean\n /** Logical → real column ids; null until Grist reports them. */\n mappings: GristWidgetColumnMap | null\n widgetOptions: Record<string, unknown> | null\n interaction: GristWidgetInteraction | null\n currentTableId: string | null\n theme: GristTheme | null\n actionStatus: GristWidgetActionStatus\n actionError: string | null\n /** The last read that Grist refused for lack of access, for the alerts. */\n readError: string | null\n /** Logical columns the last `mapBack` couldn't write (allowMultiple), for the alerts. */\n mapBackSkipped: readonly string[]\n}\n\n/** What a widget asks Grist for (`UseGristOptions`). */\nexport type GristRuntimeOptions = GristReadyOptions & {\n /** Alert kinds mountGristWidget() never shows for this widget, e.g. [\"section-not-linked\"]. */\n suppressAlerts?: GristSdkAlertKind[]\n /**\n * Extra rules for the mapped records, as a Standard Schema (zod 4,\n * valibot, arktype…), checked after each cell's declared type. A record\n * that fails keeps its typed values; its issues go to `cellIssues`.\n */\n schema?: StandardSchema\n}\n\nexport type GristRuntime = {\n readonly options: GristRuntimeOptions\n getState(): GristRuntimeState\n subscribe(listener: () => void): () => void\n /** Connects (idempotent). Returns a function that stops listening. */\n start(): () => void\n /** Re-runs `grist.ready()` and re-reads mappings and the table. */\n reload(): Promise<void>\n update(patch: Partial<GristRuntimeState>): void\n}\n\nconst READY_TIMEOUT_MS = 30_000\n\nexport function initialRuntimeState(options: GristReadyOptions = {}): GristRuntimeState {\n return {\n connection: \"connecting\",\n connectionError: null,\n declaredAccess: options.requiredAccess ?? \"read table\",\n grantedAccess: null,\n record: null,\n records: null,\n isNewRecord: false,\n mappings: null,\n widgetOptions: null,\n interaction: null,\n currentTableId: null,\n theme: null,\n actionStatus: \"idle\",\n actionError: null,\n readError: null,\n mapBackSkipped: [],\n }\n}\n\nfunction isEmbedded(): boolean {\n try {\n return typeof window !== \"undefined\" && window.self !== window.top\n } catch {\n return true // a cross-origin parent throws: we are in an iframe\n }\n}\n\nconst hasGrist = () => typeof grist !== \"undefined\" && grist !== null\n\nexport function createGristRuntime(options: GristRuntimeOptions = {}): GristRuntime {\n let state = initialRuntimeState(options)\n const listeners = new Set<() => void>()\n let starts = 0\n let stopStreams: (() => void) | null = null\n let attempt = 0\n\n const update = (patch: Partial<GristRuntimeState>) => {\n let changed = false\n for (const key of Object.keys(patch) as (keyof GristRuntimeState)[]) {\n if (!Object.is(state[key], patch[key])) changed = true\n }\n if (!changed) return\n state = { ...state, ...patch }\n for (const l of [...listeners]) l()\n }\n\n const payload: GristReadyOptions = {\n requiredAccess: options.requiredAccess ?? \"read table\",\n columns: options.columns ?? [],\n ...(options.allowSelectBy !== undefined ? { allowSelectBy: options.allowSelectBy } : {}),\n ...(options.hasCustomOptions !== undefined ? { hasCustomOptions: options.hasCustomOptions } : {}),\n ...(options.onEditOptions ? { onEditOptions: options.onEditOptions } : {}),\n }\n\n const refreshTable = async () => {\n try {\n const tableId = await grist.selectedTable?.getTableId()\n if (tableId) update({ currentTableId: tableId })\n } catch {\n // Not every host answers; currentTableId stays as it was.\n }\n }\n\n const refreshMappings = async () => {\n if (typeof grist.sectionApi?.mappings !== \"function\") return\n try {\n const mappings = await grist.sectionApi.mappings()\n // A stream may have reported newer mappings while this was in flight.\n if (state.mappings === null) update({ mappings: (mappings as GristWidgetColumnMap | null) ?? {} })\n } catch {\n // The streams report mappings too.\n }\n }\n\n const connect = async () => {\n const mine = ++attempt\n update({ connection: \"connecting\", connectionError: null })\n let timer: ReturnType<typeof setTimeout> | undefined\n try {\n await Promise.race([\n ensureGristReady(payload),\n new Promise((_, reject) => {\n timer = setTimeout(() => reject(new Error(`Grist did not answer grist.ready() within ${READY_TIMEOUT_MS / 1000} s.`)), READY_TIMEOUT_MS)\n }),\n ])\n } catch (err) {\n if (mine === attempt) update({ connection: \"error\", connectionError: err instanceof Error ? err.message : String(err) })\n return\n } finally {\n clearTimeout(timer)\n }\n if (mine !== attempt) return\n update({ connection: \"ready\" })\n await Promise.all([refreshMappings(), refreshTable()])\n }\n\n const listen = () => {\n const offs = [\n // Copies: a host may reuse one record object and mutate it in place.\n recordStream.subscribe(({ record, mappings }) =>\n update({\n record: record ? ({ ...record } as GristRowRecord) : null,\n isNewRecord: false,\n ...(mappings ? { mappings } : {}),\n })\n ),\n recordsStream.subscribe(({ records, mappings }) => {\n update({ records: records.map((r) => ({ ...r }) as GristRowRecord), ...(mappings ? { mappings } : {}) })\n void refreshTable()\n }),\n optionsStream.subscribe(({ options: widgetOptions, interaction }) =>\n update({\n widgetOptions,\n interaction,\n grantedAccess: parseAccess(interaction?.access_level) ?? state.grantedAccess,\n })\n ),\n newRecordStream.subscribe(({ mappings }) => update({ isNewRecord: true, ...(mappings ? { mappings } : {}) })),\n messageStream.subscribe((msg) => {\n const theme = parseGristThemePayload(msg)\n if (theme) update({ theme })\n }),\n ]\n return () => offs.forEach((off) => off())\n }\n\n const begin = () => {\n if (!isEmbedded()) return update({ connection: \"not-embedded\" })\n if (!hasGrist()) {\n // A page that loads the plugin API asynchronously: one more look once\n // everything has loaded, then it is unavailable.\n if (typeof document !== \"undefined\" && document.readyState !== \"complete\" && typeof window !== \"undefined\") {\n window.addEventListener(\"load\", () => (hasGrist() ? begin() : update({ connection: \"unavailable\" })), { once: true })\n return\n }\n return update({ connection: \"unavailable\" })\n }\n // Bound before ready(): Grist may push the first record during it.\n stopStreams ??= listen()\n void connect()\n }\n\n return {\n options,\n getState: () => state,\n subscribe(listener) {\n listeners.add(listener)\n return () => listeners.delete(listener)\n },\n start() {\n if (starts++ === 0) begin()\n return () => {\n if (--starts > 0) return\n stopStreams?.()\n stopStreams = null\n }\n },\n async reload() {\n if (!hasGrist() || !isEmbedded()) return begin()\n resetGristReady()\n update({ mappings: null })\n stopStreams ??= listen()\n await connect()\n },\n update,\n }\n}\n","import { useState, type ReactNode } from \"react\"\n\nimport { GristContextProvider, newConnection, type UseGristOptions } from \"../use-grist\"\n\nexport type GristWidgetProviderProps = {\n /** Read once, at mount: what the widget asks Grist for. */\n options?: UseGristOptions\n children: ReactNode\n}\n\n/**\n * Connects to Grist for the widgets below it: `useGrist()` under it reads this\n * connection. `mountGristWidget()` renders it; render it yourself only for a\n * page that manages its own React root.\n */\nexport function GristWidgetProvider({ options, children }: GristWidgetProviderProps) {\n const [connection] = useState(() => newConnection(options))\n return <GristContextProvider value={connection}>{children}</GristContextProvider>\n}\n","import { useCallback, useState, type CSSProperties, type ReactNode } from \"react\"\n\nimport { accessDenied, accessLabel, deriveColumnMappingStatus } from \"../runtime/derive\"\nimport type { GristRuntimeState } from \"../runtime/runtime\"\nimport { useGristRuntime, useGristState } from \"../use-grist\"\n\nexport type GristBoundaryProps = {\n children: ReactNode\n}\n\nexport type GristBoundaryActions = {\n reload: () => Promise<void>\n isReloading: boolean\n}\n\nconst shellStyle: CSSProperties = {\n alignItems: \"center\",\n background: \"var(--background)\",\n boxSizing: \"border-box\",\n color: \"var(--foreground)\",\n display: \"flex\",\n flexDirection: \"column\",\n justifyContent: \"center\",\n minHeight: \"100%\",\n padding: \"clamp(16px, 5vh, 32px)\",\n width: \"100%\",\n}\n\nconst cardStyle: CSSProperties = {\n background: \"var(--card)\",\n border: \"1px solid var(--border)\",\n borderRadius: 12,\n boxShadow: \"0 1px 3px rgb(0 0 0 / 0.12)\",\n maxWidth: 420,\n padding: \"20px 22px\",\n textAlign: \"center\",\n width: \"100%\",\n}\n\nconst titleStyle: CSSProperties = {\n color: \"var(--foreground)\",\n fontSize: 15,\n fontWeight: 600,\n lineHeight: 1.35,\n margin: 0,\n}\n\nconst messageStyle: CSSProperties = {\n color: \"var(--muted-foreground)\",\n fontSize: 14,\n lineHeight: 1.5,\n margin: \"10px 0 0\",\n}\n\nconst buttonStyle: CSSProperties = {\n background: \"var(--background)\",\n border: \"1px solid var(--border)\",\n borderRadius: 8,\n color: \"var(--foreground)\",\n cursor: \"pointer\",\n fontSize: 13,\n fontWeight: 500,\n marginTop: 16,\n padding: \"8px 14px\",\n}\n\ntype GristBoundaryScreenProps = {\n title: string\n message: string\n /** Affects WAI-ARIA role only (`alert` vs `status`); copy uses the same neutral styles. */\n tone?: \"default\" | \"error\"\n showRetry?: boolean\n actions?: GristBoundaryActions\n retryLabel?: string\n retryBusyLabel?: string\n}\n\n/** Centered full-viewport chrome for booting / unavailable / error states. */\nexport function GristBoundaryScreen({\n title,\n message,\n tone = \"default\",\n showRetry = false,\n actions,\n retryLabel = \"Try reconnecting\",\n retryBusyLabel = \"Reconnecting…\",\n}: GristBoundaryScreenProps) {\n return (\n <div style={shellStyle} role={tone === \"error\" ? \"alert\" : \"status\"}>\n <div style={cardStyle}>\n <h2 style={titleStyle}>{title}</h2>\n <p style={messageStyle}>{message}</p>\n {showRetry && actions ? (\n <button\n disabled={actions.isReloading}\n onClick={() => void actions.reload()}\n style={{\n ...buttonStyle,\n cursor: actions.isReloading ? \"not-allowed\" : \"pointer\",\n opacity: actions.isReloading ? 0.7 : 1,\n }}\n type=\"button\"\n >\n {actions.isReloading ? retryBusyLabel : retryLabel}\n </button>\n ) : null}\n </div>\n </div>\n )\n}\n\ntype Screen = { title: string; message: string; tone?: \"default\" | \"error\"; retry?: boolean }\n\n/** What the boundary shows instead of the widget, or null to render it. */\nexport function boundaryScreen(state: GristRuntimeState, columns: Parameters<typeof deriveColumnMappingStatus>[0]): Screen | null {\n switch (state.connection) {\n case \"connecting\":\n return { title: \"Connecting to Grist\", message: \"Asking Grist for the access this widget needs…\" }\n case \"not-embedded\":\n return {\n title: \"Open inside Grist\",\n message: \"Open this page as a custom widget inside a Grist document (it runs in an embedded panel, not on its own).\",\n retry: true,\n }\n case \"unavailable\":\n return {\n title: \"Open inside Grist\",\n message: \"The Grist plugin did not load. Reload the page, or open this URL as a custom widget inside a Grist document.\",\n retry: true,\n }\n case \"error\":\n return {\n title: \"Something went wrong\",\n message: state.connectionError ?? \"Something went wrong connecting to Grist. Try again, or reload the page.\",\n tone: \"error\",\n retry: true,\n }\n }\n if (accessDenied(state)) {\n return {\n title: \"More access needed\",\n message: `Set Access level to at least \"${accessLabel(state.declaredAccess)}\" in the Custom widget settings.`,\n tone: \"error\",\n retry: true,\n }\n }\n const mapping = deriveColumnMappingStatus(columns, state.mappings)\n if (mapping.pending) return { title: \"Connecting to Grist\", message: \"Waiting for Grist to report the column mapping…\" }\n if (!mapping.ok) {\n return {\n title: \"Map your columns\",\n message:\n \"Open the widget settings in Grist (Creator Panel → Custom widget) and connect each required column to your table.\",\n }\n }\n return null\n}\n\n/**\n * Renders the widget once Grist is connected, has granted the access it\n * declares, and every required declared column is mapped; until then, a\n * screen that says what is missing (with a retry where one can help).\n * Requires `<GristWidgetProvider>`; `mountGristWidget()` renders both.\n */\nexport function GristBoundary({ children }: GristBoundaryProps) {\n const connection = useGristRuntime()\n if (!connection) throw new Error(\"<GristBoundary> must be used inside <GristWidgetProvider> (mountGristWidget renders both).\")\n const state = useGristState(connection)\n const [isReloading, setIsReloading] = useState(false)\n const reload = useCallback(async () => {\n setIsReloading(true)\n try {\n await connection.runtime.reload()\n } catch (err) {\n console.error(\"[grist-widget-sdk] reload failed:\", err)\n } finally {\n setIsReloading(false)\n }\n }, [connection])\n\n const screen = boundaryScreen(state, connection.runtime.options.columns)\n if (!screen) return <>{children}</>\n return (\n <GristBoundaryScreen\n title={screen.title}\n message={screen.message}\n tone={screen.tone}\n showRetry={screen.retry}\n actions={{ reload, isReloading }}\n retryLabel={screen.tone === \"error\" ? \"Try again\" : \"Try reconnecting\"}\n retryBusyLabel={screen.tone === \"error\" ? \"Retrying…\" : \"Reconnecting…\"}\n />\n )\n}\n","import { useCallback, useEffect, useMemo, useState } from \"react\"\n\nimport { buildReplicaDocumentFromDocApi } from \"./helpers/build-replica-document\"\nimport { isGristNoiseColumn, type GristNoiseColumnsOptions } from \"./helpers/grist-columns-filters\"\nimport {\n buildReplicaJsonPayload,\n type ReplicaJsonIncludeRows,\n} from \"./helpers/replica-normalize\"\nimport { isAccessInsufficientError } from \"./runtime/api\"\nimport { useGrist, useGristRuntime } from \"./use-grist\"\nimport type {\n GristDocumentMode,\n GristReadyOptions,\n GristReplicaColumn,\n GristReplicaDocument,\n GristReplicaTable,\n GristRequiredAccess,\n} from \"./types\"\n\ntype ColumnExcludeContext = {\n tableId: string\n colId: string\n col: GristReplicaColumn\n}\n\nexport type UseGristSchemaOptions = {\n requiredAccess?: GristRequiredAccess\n tableId?: string\n excludeSystemTableData?: boolean\n /**\n * How row bodies are included in the replica document.\n * Default `schema+samples`.\n */\n replicaRowMode?: GristDocumentMode\n /** When `replicaRowMode` is `schema+samples`, max rows per table. Default 10. */\n sampleRowLimit?: number\n /** Stored on the replica as `source` (e.g. for logging). */\n source?: string\n} & GristNoiseColumnsOptions & {\n extraExcludeColumn?: (ctx: ColumnExcludeContext) => boolean\n } & Pick<GristReadyOptions, \"columns\" | \"allowSelectBy\" | \"hasCustomOptions\" | \"onEditOptions\">\n\n/** Selected table slice with `tableId` for consumers that expect it on the object. */\nexport type GristSchemaTableView = GristReplicaTable & { tableId: string }\n\n/** Options for `getDocumentJson` / `buildDocumentJson` on the return value of {@link useGristSchema}. */\nexport type ReplicaDocumentJsonOptions = {\n /** How row arrays appear in JSON. Default `full` (all rows currently on the document). */\n includeRows?: ReplicaJsonIncludeRows\n /** Cap per table when `includeRows` is `samples`. Default 10. */\n sampleRowLimit?: number\n space?: number\n}\n\nexport type UseGristSchemaResult = {\n isAvailable: boolean | null\n /** Canonical replica document. */\n document: GristReplicaDocument | null\n /** Same reference as `document`. */\n replicaDocument: GristReplicaDocument | null\n table: GristSchemaTableView | null\n documentJson: string | null\n getDocumentJson: (options?: ReplicaDocumentJsonOptions) => string | null\n buildDocumentJson: (document: GristReplicaDocument, options?: ReplicaDocumentJsonOptions) => string\n tableJson: string | null\n getTableJson: (options?: ReplicaDocumentJsonOptions) => string | null\n buildTableJson: (table: GristSchemaTableView, options?: ReplicaDocumentJsonOptions) => string\n isNoiseColumnId: (colId: string, col?: GristReplicaColumn) => boolean\n sortColumnIds: (colIds: string[], columns: Record<string, GristReplicaColumn>) => string[]\n loading: boolean\n error: string | null\n reload: () => Promise<void>\n}\n\nfunction filterReplicaDocumentColumns(\n document: GristReplicaDocument,\n options?: GristNoiseColumnsOptions,\n extraExcludeColumn?: (ctx: ColumnExcludeContext) => boolean\n): GristReplicaDocument {\n return {\n ...document,\n tables: Object.fromEntries(\n Object.entries(document.tables).map(([tableId, table]) => [\n tableId,\n {\n ...table,\n columns: Object.fromEntries(\n Object.entries(table.columns ?? {}).filter(([colId, col]) => {\n if (isGristNoiseColumn(colId, col, options)) return false\n if (extraExcludeColumn?.({ tableId, colId, col })) return false\n return true\n })\n ),\n },\n ])\n ),\n }\n}\n\n/**\n * Grist replica-document hook: metadata + optional decoded `rows` per table.\n */\nexport function useGristSchema(options?: UseGristSchemaOptions): UseGristSchemaResult {\n const requiredAccess = options?.requiredAccess ?? \"read table\"\n const requestedTableId = options?.tableId\n const excludeSystemTableData = options?.excludeSystemTableData ?? true\n const replicaRowMode = options?.replicaRowMode ?? \"schema+samples\"\n const sampleRowLimit = options?.sampleRowLimit ?? 10\n const replicaSource = options?.source\n const excludeId = options?.excludeId ?? true\n const excludeGristHelpers = options?.excludeGristHelpers ?? true\n const excludeLoggingColumns = options?.excludeLoggingColumns ?? true\n const excludeManualSort = options?.excludeManualSort ?? false\n const extraExcludeColumn = options?.extraExcludeColumn\n\n // Inside a provider, its connection; standalone, the page's, with these options.\n const w = useGrist({\n requiredAccess,\n columns: options?.columns,\n allowSelectBy: options?.allowSelectBy,\n hasCustomOptions: options?.hasCustomOptions,\n onEditOptions: options?.onEditOptions,\n })\n const connection = useGristRuntime()\n const isAvailable = w.isAvailable\n const readyError = w.status === \"error\" || w.status === \"unavailable\" ? w.error : null\n const docApi = w.isReady && typeof grist !== \"undefined\" ? (grist.docApi ?? null) : null\n\n const [document, setDocument] = useState<GristReplicaDocument | null>(null)\n const [loading, setLoading] = useState(false)\n const [error, setError] = useState<string | null>(null)\n\n const includeRowsForBuild: false | \"samples\" | \"full\" =\n replicaRowMode === \"schema-only\" ? false : replicaRowMode === \"schema+data\" ? \"full\" : \"samples\"\n\n const load = useCallback(async () => {\n if (!docApi) return\n setLoading(true)\n setError(null)\n try {\n const buildOpts = {\n includeSystemTableData: !excludeSystemTableData,\n includeRows: includeRowsForBuild,\n sampleRowLimit,\n source: replicaSource,\n }\n const raw = await buildReplicaDocumentFromDocApi(docApi, buildOpts)\n const filtered = filterReplicaDocumentColumns(\n raw,\n {\n excludeId,\n excludeGristHelpers,\n excludeLoggingColumns,\n excludeManualSort,\n },\n extraExcludeColumn\n )\n setDocument(filtered)\n } catch (err) {\n const message = err instanceof Error ? err.message : String(err)\n setDocument(null)\n setError(message)\n // The access alert above the widget says what to change in Grist.\n if (isAccessInsufficientError(message)) connection?.runtime.update({ readError: message })\n } finally {\n setLoading(false)\n }\n }, [\n docApi,\n connection,\n excludeSystemTableData,\n replicaRowMode,\n sampleRowLimit,\n excludeId,\n excludeGristHelpers,\n excludeLoggingColumns,\n excludeManualSort,\n extraExcludeColumn,\n replicaSource,\n ])\n\n useEffect(() => {\n if (docApi) void load()\n }, [docApi, load])\n\n const buildDocumentJson = useCallback((target: GristReplicaDocument, options?: ReplicaDocumentJsonOptions): string => {\n const includeRows = options?.includeRows ?? \"full\"\n const space = options?.space ?? 2\n const payload = buildReplicaJsonPayload(target, {\n includeRows,\n sampleRowLimit: options?.sampleRowLimit ?? sampleRowLimit,\n })\n return JSON.stringify(payload, null, space)\n }, [sampleRowLimit])\n\n const getDocumentJson = useCallback(\n (options?: ReplicaDocumentJsonOptions): string | null => {\n if (!document) return null\n return buildDocumentJson(document, options)\n },\n [document, buildDocumentJson]\n )\n\n const table = useMemo((): GristSchemaTableView | null => {\n if (!document || !requestedTableId) return null\n const slice = document.tables[requestedTableId]\n if (!slice) return null\n return { tableId: requestedTableId, ...slice }\n }, [document, requestedTableId])\n\n const buildTableJson = useCallback(\n (target: GristSchemaTableView, options?: ReplicaDocumentJsonOptions): string => {\n const includeRows = options?.includeRows ?? \"full\"\n const limit = options?.sampleRowLimit ?? sampleRowLimit\n const space = options?.space ?? 2\n const { tableId, ...rest } = target\n let body: GristReplicaTable = { ...rest }\n if (includeRows === \"none\") {\n const { rows: _r, ...r } = body\n body = r\n } else if (includeRows === \"samples\") {\n const r = body.rows ?? []\n body = { ...body, rows: r.slice(0, limit) }\n }\n return JSON.stringify({ tableId, ...body }, null, space)\n },\n [sampleRowLimit]\n )\n\n const getTableJson = useCallback(\n (options?: ReplicaDocumentJsonOptions): string | null => {\n if (!table) return null\n return buildTableJson(table, options)\n },\n [table, buildTableJson]\n )\n\n const noiseColumnMatcher = useCallback(\n (colId: string, col?: GristReplicaColumn): boolean =>\n isGristNoiseColumn(colId, col, {\n excludeId,\n excludeGristHelpers,\n excludeLoggingColumns,\n excludeManualSort,\n }),\n [excludeId, excludeGristHelpers, excludeLoggingColumns, excludeManualSort]\n )\n\n const sortColumns = useCallback((colIds: string[], columns: Record<string, GristReplicaColumn>): string[] => {\n return [...colIds].sort((a, b) => {\n const la = (columns[a]?.label || a).toLowerCase()\n const lb = (columns[b]?.label || b).toLowerCase()\n if (la !== lb) return la.localeCompare(lb)\n return a.localeCompare(b)\n })\n }, [])\n\n return {\n isAvailable,\n document,\n replicaDocument: document,\n table,\n documentJson: document ? buildDocumentJson(document) : null,\n getDocumentJson,\n buildDocumentJson,\n tableJson: table ? buildTableJson(table) : null,\n getTableJson,\n buildTableJson,\n isNoiseColumnId: noiseColumnMatcher,\n sortColumnIds: sortColumns,\n loading,\n error: readyError ?? error,\n reload: load,\n }\n}\n","import { useEffect } from \"react\"\n\nexport type UseWidgetMetadataInput = {\n title: string\n description: string\n}\n\nexport function useWidgetMetadata(input?: UseWidgetMetadataInput | null) {\n useEffect(() => {\n if (!input) return\n\n const { title, description } = input\n const canonicalUrl = window.location.href\n\n document.title = title\n setMetaTag(\"name\", \"title\", title)\n setMetaTag(\"name\", \"description\", description)\n setMetaTag(\"property\", \"og:title\", title)\n setMetaTag(\"property\", \"og:description\", description)\n setMetaTag(\"property\", \"og:type\", \"website\")\n setMetaTag(\"property\", \"og:url\", canonicalUrl)\n setMetaTag(\"name\", \"twitter:card\", \"summary\")\n setMetaTag(\"name\", \"twitter:title\", title)\n setMetaTag(\"name\", \"twitter:description\", description)\n\n }, [input])\n}\n\nfunction setMetaTag(key: \"name\" | \"property\", value: string, content: string) {\n let meta = document.head.querySelector<HTMLMetaElement>(\n `meta[${key}=\"${value}\"]`\n )\n if (!meta) {\n meta = document.createElement(\"meta\")\n meta.setAttribute(key, value)\n document.head.appendChild(meta)\n }\n meta.setAttribute(\"content\", content)\n}\n"],"mappings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AkB,OAAuC;AACvE,EAAAA,WAAU,MAAM;AACd,QAAI,CAAC,MAAO;AAEZ,UAAM,EAAE,OAAO,YAAY,IAAI;AAC/B,UAAM,eAAe,OAAO,SAAS;AAErC,aAAS,QAAQ;AACjB,eAAW,QAAQ,SAAS,KAAK;AACjC,eAAW,QAAQ,eAAe,WAAW;AAC7C,eAAW,YAAY,YAAY,KAAK;AACxC,eAAW,YAAY,kBAAkB,WAAW;AACpD,eAAW,YAAY,WAAW,SAAS;AAC3C,eAAW,YAAY,UAAU,YAAY;AAC7C,eAAW,QAAQ,gBAAgB,SAAS;AAC5C,eAAW,QAAQ,iBAAiB,KAAK;AACzC,eAAW,QAAQ,uBAAuB,WAAW;AAAA,EAEvD,GAAG,CAAC,KAAK,CAAC;AACZ;AAEA,SAAS,WAAW,KAA0B,OAAe,SAAiB;AAC5E,MAAI,OAAO,SAAS,KAAK;AAAA,IACvB,QAAQ,GAAG,KAAK,KAAK;AAAA,EACvB;AACA,MAAI,CAAC,MAAM;AACT,WAAO,SAAS,cAAc,MAAM;AACpC,SAAK,aAAa,KAAK,KAAK;AAC5B,aAAS,KAAK,YAAY,IAAI;AAAA,EAChC;AACA,OAAK,aAAa,WAAW,OAAO;AACtC;","names":["message","message","ACCESS_RANK","inFlight","useCallback","useState","jsx","message","useState","useCallback","useCallback","useEffect","useMemo","useState","document","useState","useCallback","message","useEffect","options","useMemo","useEffect"]}
|