mirror of
https://github.com/storytold/gridcraft.git
synced 2026-11-10 12:29:58 -06:00
gridcraft-web: speak the host messages through craft-web-host
The transports, the message types and the origin checks come from the shared crate (storytold/craft-libs#420); GridCraft keeps the download hook, the open size limit, the workbook-saved rule and the author.
This commit is contained in:
@@ -87,7 +87,7 @@ downloading them. The two sides talk `postMessage` with plain window messages th
|
||||
|
||||
| Message | Direction | Fields |
|
||||
|---|---|---|
|
||||
| `gridcraft:ready` | app → page | `version`: the app is listening; send a file now |
|
||||
| `gridcraft:ready` | app → page | `version`, `appVersion`: the app is listening; send a file now |
|
||||
| `gridcraft:open` | page → app | `name`, `bytes` (an `ArrayBuffer` or `Uint8Array`): open like File › Open |
|
||||
| `gridcraft:save` | app → page | `name`, `bytes` (a transferred `ArrayBuffer`): every file the app would otherwise download (Save, Save As, Export as PDF). The page stores it and reports failures itself. |
|
||||
| `gridcraft:dirty` | app → page | `dirty`: unsaved changes appeared or went away |
|
||||
@@ -149,6 +149,8 @@ As with the parent bridge, the app starts with an empty workbook instead of a sa
|
||||
must be exactly `page`; anything else is ignored, and the app runs as a standalone page with
|
||||
downloads.
|
||||
|
||||
The messages and both transports are the shared contract of [`craft-web-host`](https://github.com/storytold/craft-libs/tree/main/crates/web-host) (storytold/craft-libs#420), the same for every Craft app: its README lists every message, including `saved`, with the compatibility notes. In `gridcraft:ready`, `version` is the contract's (`"1"`) and `appVersion` is this app's release. GridCraft reads bytes, so a host sends `bytes`, not a `File`.
|
||||
|
||||
### Trust and limits
|
||||
|
||||
- **Who is trusted.** In page host mode the page and GridCraft share one document, so any script on the page can drive the app: open files in it and receive what it saves. Use this mode only for a page you control. The iframe mode (`?host=parent`) answers only the parent window, on the page's own origin.
|
||||
|
||||
Reference in New Issue
Block a user