grist-widget-sdk 0.3.27 → 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.
Files changed (86) hide show
  1. package/CHANGELOG.md +45 -0
  2. package/README.md +1 -1
  3. package/dist/app.cjs +1139 -4336
  4. package/dist/app.cjs.map +1 -1
  5. package/dist/app.d.cts +1 -3
  6. package/dist/app.d.ts +1 -3
  7. package/dist/app.js +3 -7
  8. package/dist/chunk-4ZGVKGDF.js +204 -0
  9. package/dist/chunk-4ZGVKGDF.js.map +1 -0
  10. package/dist/{chunk-YQNMIL33.js → chunk-B5ZZNLVS.js} +528 -181
  11. package/dist/chunk-B5ZZNLVS.js.map +1 -0
  12. package/dist/chunk-O7NY46QY.js +1830 -0
  13. package/dist/chunk-O7NY46QY.js.map +1 -0
  14. package/dist/{chunk-6Y2IONGJ.js → chunk-P6VTEKWO.js} +113 -14
  15. package/dist/chunk-P6VTEKWO.js.map +1 -0
  16. package/dist/emulator/testing.cjs +1504 -4822
  17. package/dist/emulator/testing.cjs.map +1 -1
  18. package/dist/emulator/testing.d.cts +3 -6
  19. package/dist/emulator/testing.d.ts +3 -6
  20. package/dist/emulator/testing.js +7 -20
  21. package/dist/emulator/testing.js.map +1 -1
  22. package/dist/emulator.cjs +59 -249
  23. package/dist/emulator.cjs.map +1 -1
  24. package/dist/emulator.d.cts +3 -5
  25. package/dist/emulator.d.ts +3 -5
  26. package/dist/emulator.js +5 -11
  27. package/dist/index.cjs +1373 -4859
  28. package/dist/index.cjs.map +1 -1
  29. package/dist/index.d.cts +81 -260
  30. package/dist/index.d.ts +81 -260
  31. package/dist/index.js +8 -158
  32. package/dist/{inline-DpcT8tV9.d.ts → templates-CGmRIQBV.d.cts} +89 -35
  33. package/dist/{inline-C7DkvuET.d.cts → templates-Cq94qOcf.d.ts} +89 -35
  34. package/dist/{types-D3JxUCfL.d.cts → types-DBStn0Dk.d.cts} +2 -26
  35. package/dist/{types-D3JxUCfL.d.ts → types-DBStn0Dk.d.ts} +2 -26
  36. package/dist/use-grist-BK0eke9K.d.cts +358 -0
  37. package/dist/use-grist-C5DMZ3wU.d.ts +358 -0
  38. package/package.json +8 -37
  39. package/dist/advanced.cjs +0 -2799
  40. package/dist/advanced.cjs.map +0 -1
  41. package/dist/advanced.d.cts +0 -822
  42. package/dist/advanced.d.ts +0 -822
  43. package/dist/advanced.js +0 -872
  44. package/dist/advanced.js.map +0 -1
  45. package/dist/chunk-22U7WAY3.js +0 -463
  46. package/dist/chunk-22U7WAY3.js.map +0 -1
  47. package/dist/chunk-64SVRWW7.js +0 -758
  48. package/dist/chunk-64SVRWW7.js.map +0 -1
  49. package/dist/chunk-6Y2IONGJ.js.map +0 -1
  50. package/dist/chunk-B4AKVSWV.js +0 -2362
  51. package/dist/chunk-B4AKVSWV.js.map +0 -1
  52. package/dist/chunk-ELGVOHFD.js +0 -32
  53. package/dist/chunk-ELGVOHFD.js.map +0 -1
  54. package/dist/chunk-GTTD5HPO.js +0 -36
  55. package/dist/chunk-GTTD5HPO.js.map +0 -1
  56. package/dist/chunk-NO6FYX33.js +0 -2084
  57. package/dist/chunk-NO6FYX33.js.map +0 -1
  58. package/dist/chunk-OPTOYD2Y.js +0 -277
  59. package/dist/chunk-OPTOYD2Y.js.map +0 -1
  60. package/dist/chunk-PM3B4WYV.js +0 -12
  61. package/dist/chunk-PM3B4WYV.js.map +0 -1
  62. package/dist/chunk-REV5AUXD.js +0 -25
  63. package/dist/chunk-REV5AUXD.js.map +0 -1
  64. package/dist/chunk-YQNMIL33.js.map +0 -1
  65. package/dist/create-grist-emulator-BCqp1BF9.d.ts +0 -81
  66. package/dist/create-grist-emulator-DBM8OSIR.d.cts +0 -81
  67. package/dist/emulator/devtools.cjs +0 -1404
  68. package/dist/emulator/devtools.cjs.map +0 -1
  69. package/dist/emulator/devtools.d.cts +0 -48
  70. package/dist/emulator/devtools.d.ts +0 -48
  71. package/dist/emulator/devtools.js +0 -506
  72. package/dist/emulator/devtools.js.map +0 -1
  73. package/dist/emulator/transports.cjs +0 -1132
  74. package/dist/emulator/transports.cjs.map +0 -1
  75. package/dist/emulator/transports.d.cts +0 -38
  76. package/dist/emulator/transports.d.ts +0 -38
  77. package/dist/emulator/transports.js +0 -12
  78. package/dist/emulator/transports.js.map +0 -1
  79. package/dist/templates-8k2LKoO-.d.cts +0 -24
  80. package/dist/templates-DIwi_mvI.d.ts +0 -24
  81. package/dist/use-grist-reads-DUMvJgV7.d.ts +0 -480
  82. package/dist/use-grist-reads-DpjVuI0H.d.cts +0 -480
  83. package/dist/use-grist-types-DdOLEJXN.d.cts +0 -499
  84. package/dist/use-grist-types-kwxoFeub.d.ts +0 -499
  85. package/dist/use-grist-widget-options-from-context-CGOlQ5Vc.d.cts +0 -43
  86. package/dist/use-grist-widget-options-from-context-CGOlQ5Vc.d.ts +0 -43
package/CHANGELOG.md CHANGED
@@ -1,5 +1,50 @@
1
1
  # grist-widget-sdk
2
2
 
3
+ ## 0.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - a257767: The emulator is a test harness only. Removed: `grist-widget-sdk/emulator/transports` (the iframe transport, `createIframeTransport`) and `grist-widget-sdk/emulator/devtools` (the inspector), which only the retired playground used; `createGristEmulator`'s `transport` option takes `{ kind: "inline", target? }` only. `renderWithGrist`, `smokeTestWidget` and `createGristEmulator` are unchanged. To see a widget run, use a real Grist: `pnpm demo`, or its demo page (`pnpm demo --save`).
8
+ - 74395a7: **0.4.0: a synchronous runtime and a small public surface (breaking).**
9
+
10
+ The connection to Grist is one synchronous `connect()` and one store read through `useSyncExternalStore`, instead of the handshake state machine (detection polling, a 30 s heartbeat, generations). `useGrist()` keeps its shape for what widgets use and re-renders less (a cursor move: 3 renders to 1). The root entry exports 29 runtime names instead of about 195; `grist-widget-sdk/advanced` is gone.
11
+
12
+ Fixed on the way: `fetchSelectedTable()` returned rows while typed as columns (a widget passing it to `tableDataToRows()` got nothing; it now returns columns); `mode` stuck on `"new-row"` when the selection went away; records reused and mutated by the host no longer go unnoticed. The emulator now matches Grist on `setOptions` (replaces), the add-row (`onNewRecord` only), unmapped columns (`mappedRecord` is `null`) and access (it grants what the widget asks for unless a test sets `widgetInteraction.access_level`).
13
+
14
+ What to replace, if a widget uses it (the six reference widgets need nothing):
15
+
16
+ | Removed | Use instead |
17
+ | --- | --- |
18
+ | `useGristSelection()`, `useGristStatus()`, `useGristWrites()`, `useGristTheme()` | `useGrist()` |
19
+ | `grist-widget-sdk/advanced` (`useGristReady`, `useGristHandshake`, `useGristCapabilities`, `useGristRowsFromTable`, …), `GristHandshakeProvider` | `useGrist()` (`status`, `columnMappingStatus`), or `fetchTableRows` in an effect |
20
+ | `w.capabilities` | `w.status`, `w.columnMappingStatus.ok`, `w.isReady` |
21
+ | `w.getWidgetOptions()`, `w.getWidgetOption(key)` | `w.widgetOptions` |
22
+ | `w.setWidgetOption(key, value)` | `w.patchWidgetOptions({ [key]: value })` |
23
+ | `w.clearWidgetOptions()` | `w.setWidgetOptions({})` |
24
+ | `w.fetchRow(table, id)` | `w.fetchTableRows(table)` |
25
+ | `w.fetchSelectedRecord(id)` | `w.record`, or `w.fetchSelectedTable()` |
26
+ | `w.buildReplicaDocumentFromDocApi(...)`, `buildReplicaDocumentFromDocApi` | `useGristSchema()` |
27
+ | `w.getDocName()`, `w.configure()`, `w.refreshMappings()`, `w.refreshCurrentTable()`, `w.currentTableLoading` | — (`currentTableId` and `mappings` follow Grist) |
28
+ | `w.isNewRecord`, `w.recordsMappings`, `w.newRecordMappings` | `w.mode === "new-row"`, `w.mappings` |
29
+ | `w.widgetInteraction`, `w.readError`, `w.mapBackSkipped` | the alerts `mountGristWidget()` shows |
30
+ | `w.getAccessToken()`, `w.fetchAttachmentBase64()`, `getGristAccessToken`, `fetchWithGristAuth` | `w.fetchWithAuth()`, `w.fetchAttachmentBlob()` |
31
+ | `<GristBoundary gate widget bootingFallback …>` | `<GristBoundary>`: it gates on declared columns itself |
32
+ | alert and boundary helpers (`getGristSdkAlertDescriptors`, `deriveBoundaryView`, `format…AlertMessage`, …), `validateColumnMappings` | `mountGristWidget()` shows them; `w.columnMappingStatus` |
33
+ | replica builders and normalizers, value codecs beyond `decodeGristValue` / `encodeGristValue` / `isGristCellError`, `gristBulk*` / table / document action builders | write the user-action tuple; `useGristSchema()` |
34
+ | `GristReadyOptions.availabilityMaxAttempts`, `availabilityIntervalMs`, `logWhenNotEmbedded` | — (no polling) |
35
+ - 673a02d: **Typed reads, with read-only access; no zod in a widget's bundle.**
36
+
37
+ Each mapped cell is now checked against the type its column declares in `GRIST_OPTIONS.columns`: no schema to fetch, no full access. `mappedRecord` (and the new `mappedRecords`, every row of the section) holds the value each type promises (`Text` → string, `Numeric` → number, `Date` → `Date`, `Ref` → row id, `RefList` / `Attachments` → ids, `ChoiceList` → strings); a cell that doesn't match (text Grist couldn't parse, a formula error, a column whose type changed) is `null`, and listed in the new `cellIssues` (`{ rowId, column, message, value }`), which `mountGristWidget()` shows as a `cell-issues` alert. `GristMappedRow<typeof GRIST_OPTIONS>` types the mapped records from the declaration (declare it `as const satisfies UseGristOptions`). `UseGristOptions.schema` takes any Standard Schema (zod 4, valibot, arktype) for extra rules; the SDK depends on none. `checkGristCell(type, value)` checks a value read another way.
38
+
39
+ Removed: `safeParseGristTableData`, `safeParseRowsToDisplayRows` and `fetchTableRows`'s `safeParse` option (the zod-based safe-parse), which put zod in every widget. A widget's template build goes from 129 KB to 94 KB of JavaScript, gzipped; CI now fails above 100 KB.
40
+
41
+ What to change, if a widget relies on it (the six reference widgets need nothing): a `Ref` column's value in `mappedRecord` is now its row id (it was a `Reference` object), and a cell that doesn't match its declared type is `null` (it was the raw value); safe-parse users read `mappedRecords` / `cellIssues`, or call `checkGristCell` per cell.
42
+
43
+ ### Patch Changes
44
+
45
+ - f4a467a: Routine dependency updates via Dependabot (PR #241). See the PR diff for the exact version bumps.
46
+ - f5e04b4: `fetchWithGristAuth()` (and `w.fetchWithAuth()`) now refuses an absolute URL on another origin than the document's Grist instance, instead of sending the document's access token there. The token travels as the `auth` query parameter, so a URL taken from a cell or another input could hand it to any host. Relative paths and absolute URLs on the Grist instance work as before; for other hosts, use plain `fetch()`.
47
+
3
48
  ## 0.3.27
4
49
 
5
50
  ### Patch Changes
package/README.md CHANGED
@@ -147,7 +147,7 @@ Subpath exports:
147
147
 
148
148
  ## Replica document (`GristReplicaDocument`)
149
149
 
150
- One JSON shape is used for **`useGristSchema()`**, **`getDocumentJson` / `buildDocumentJson`**, playground **`*.grist.json`** fixtures, and **`createGristEmulator({ document })`**. Valid fixtures are checked with **`parseDocument`** (Zod).
150
+ One JSON shape is used for **`useGristSchema()`**, **`getDocumentJson` / `buildDocumentJson`**, **`*.grist.json`** fixtures, and **`createGristEmulator({ document })`**. Valid fixtures are checked with **`parseDocument`** (Zod).
151
151
 
152
152
  ### Top-level fields
153
153