@altertable/data-app 0.76.0 → 0.78.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 (69) hide show
  1. package/CONTRIBUTING.md +3 -0
  2. package/REFERENCE.md +392 -276
  3. package/dist/chunks/contract-gu1rDsV0.js +1588 -0
  4. package/dist/chunks/contract-gu1rDsV0.js.map +1 -0
  5. package/dist/chunks/data-client-BMdL73Ab.js +122 -0
  6. package/dist/chunks/data-client-BMdL73Ab.js.map +1 -0
  7. package/dist/chunks/{date-time-range-value-TE8KCsfV.js → date-time-range-value-D-XfqVTT.js} +28 -31
  8. package/dist/chunks/date-time-range-value-D-XfqVTT.js.map +1 -0
  9. package/dist/chunks/{diagnostics-DhCqGklq.js → diagnostics-CX9SsU79.js} +240 -63
  10. package/dist/chunks/diagnostics-CX9SsU79.js.map +1 -0
  11. package/dist/chunks/record-Cr4Uk1K3.js +9 -0
  12. package/dist/chunks/record-Cr4Uk1K3.js.map +1 -0
  13. package/dist/client/index.js +4 -86
  14. package/dist/client/index.js.map +1 -1
  15. package/dist/core/appearance.js +3 -5
  16. package/dist/core/appearance.js.map +1 -1
  17. package/dist/core/config.js +11 -3
  18. package/dist/core/config.js.map +1 -1
  19. package/dist/core/contract.js +3 -4
  20. package/dist/core/format.js +1 -1
  21. package/dist/internal.js +58 -124
  22. package/dist/internal.js.map +1 -1
  23. package/dist/types/chunks/contract.d.ts +592 -308
  24. package/dist/types/chunks/data-client.d.ts +46 -0
  25. package/dist/types/chunks/date-time-range-value.d.ts +28 -2
  26. package/dist/types/chunks/index.d.ts +65 -53
  27. package/dist/types/client/index.d.ts +4 -3
  28. package/dist/types/core/config.d.ts +16 -6
  29. package/dist/types/core/contract.d.ts +3 -5
  30. package/dist/types/core/format.d.ts +1 -2
  31. package/dist/types/index.d.ts +4 -4
  32. package/dist/types/internal.d.ts +26 -7
  33. package/docs/app-authoring.md +23 -14
  34. package/docs/client.md +14 -48
  35. package/docs/contract.md +58 -56
  36. package/docs/data-context.md +13 -6
  37. package/docs/diagnostics.md +16 -23
  38. package/docs/embed.md +60 -25
  39. package/docs/filters.md +271 -0
  40. package/docs/hosted-apps.md +11 -10
  41. package/docs/layout.md +45 -18
  42. package/docs/local-data-apps.md +5 -6
  43. package/docs/react-embed.md +44 -2
  44. package/docs/react.md +1 -2
  45. package/docs/server-bun.md +8 -5
  46. package/docs/stories-and-export.md +23 -14
  47. package/docs/styling.md +2 -1
  48. package/docs/ui.md +18 -8
  49. package/docs/views.md +63 -26
  50. package/docs/widgets.md +40 -16
  51. package/docs/worker.md +1 -1
  52. package/package.json +1 -5
  53. package/dist/chunks/contract-DsyRYgN_.js +0 -626
  54. package/dist/chunks/contract-DsyRYgN_.js.map +0 -1
  55. package/dist/chunks/contract-kNFYPHRK.js +0 -713
  56. package/dist/chunks/contract-kNFYPHRK.js.map +0 -1
  57. package/dist/chunks/date-time-range-value-TE8KCsfV.js.map +0 -1
  58. package/dist/chunks/diagnostics-DhCqGklq.js.map +0 -1
  59. package/dist/chunks/operation-7tiT4cpJ.js +0 -134
  60. package/dist/chunks/operation-7tiT4cpJ.js.map +0 -1
  61. package/dist/chunks/request-body-H1qPmmTN.js +0 -50
  62. package/dist/chunks/request-body-H1qPmmTN.js.map +0 -1
  63. package/dist/server/index.js +0 -90
  64. package/dist/server/index.js.map +0 -1
  65. package/dist/types/chunks/contract2.d.ts +0 -207
  66. package/dist/types/chunks/date-time-range.d.ts +0 -29
  67. package/dist/types/server/index.d.ts +0 -17
  68. package/docs/server.md +0 -41
  69. package/docs/variables.md +0 -280
package/docs/client.md CHANGED
@@ -1,66 +1,32 @@
1
1
  # Client
2
2
 
3
3
  Use this guide when customizing client delivery. Standard apps keep the
4
- starter's client. Import `createDataClient()` from `@altertable/data-app/client`.
4
+ starter's client.
5
5
 
6
- ## HTTP operations
6
+ ## Registered operations
7
+
8
+ Hosted and local metric/finding starters use the same operation client:
7
9
 
8
10
  ```ts
9
- import { createDataClient } from '@altertable/data-app/client';
10
- import type { operations } from './operations.ts';
11
-
12
- const client = createDataClient<typeof operations>();
13
- const response = await client.query(
14
- 'sampleCountsByGroup',
15
- { groupName: '' },
16
- { signal }
17
- );
11
+ const operations = dataApp.defineOperations({ sampleCountsByGroup });
12
+ const client = operations.createDataClient();
18
13
  ```
19
14
 
20
- The app supplies `operations` and an optional cancellation `signal`.
21
- Inputs and data are inferred from the operation map and `run()`. Keep the import
22
- type-only so operation implementations stay on the server.
23
-
24
- The default endpoint is `/api/data`. Override it with
25
- `createDataClient<typeof operations>({ endpoint, fetch })` to change the base URL or supply a Fetch
26
- implementation. Calls POST JSON to `/api/data/:operation`; the client sends
27
- operation inputs rather than SQL or credentials.
15
+ `run()` executes in the browser. Hosted apps send each named query through
16
+ `data:query`; local apps install `installLocalQueryLakehouse()` before mounting
17
+ and send it to `POST /api/query/:queryId`. Both backends execute only registered
18
+ SQL. The local Bun server receives `app: dataApp` through `serveLocalApp()`.
19
+ Keep `run()` and its imports browser-safe in this mode.
28
20
 
29
21
  For direct client calls, render `response.data` and label it with `response.input`
30
22
  so retained results keep their original scope during refresh. React views handle
31
- this automatically. For custom error handling, import `DataAppError` from the same
32
- entry for public codes and request IDs. Pass an abort signal to cancel a request.
33
-
34
- See [contracts](contract.md), [server handlers](server.md), and
35
- [React bindings](react.md).
23
+ this automatically. Import `DataAppError` for public codes and request IDs.
24
+ Pass an abort signal to cancel a query.
36
25
 
37
- ## Browser-owned operations for bundle apps
38
-
39
- Bundle apps pass their operation registry as a value:
40
-
41
- ```ts
42
- import { createDataClient } from '@altertable/data-app/client';
43
-
44
- // ... operations declared with dataApp.defineOperation()
45
- const client = createDataClient({ operations });
46
- const response = await client.query('sampleCountsByGroup', { groupName: '' });
47
- ```
48
-
49
- Operations run in the browser and query through the host's `data:sql` route.
50
- The trusted bootstrap installs the bridge before app execution. A custom runtime
51
- must install it first or supply an authorized `lakehouse` adapter.
52
-
53
- Do not combine `operations` with `transport`, `endpoint`, or `fetch`. Browser
54
- policy bounds app requests; the [host SQL handler](embed.md#sql-query-route)
55
- must independently enforce access and resource limits.
26
+ See [contracts](contract.md) and [React bindings](react.md).
56
27
 
57
28
  ## Iframe transport
58
29
 
59
- `createDataClient<typeof operations>({ transport })` accepts a `DataTransport`. Without an explicit
60
- transport, endpoint, or Fetch implementation, it discovers an installed iframe
61
- transport before falling back to HTTP. Explicit endpoint/Fetch options select
62
- HTTP. `createHttpTransport()` provides the underlying operation delivery adapter.
63
-
64
30
  A URL-hosted app configures trust and installs the bridge before mounting:
65
31
 
66
32
  ```ts
package/docs/contract.md CHANGED
@@ -2,11 +2,14 @@
2
2
 
3
3
  Keep the starter's `defineDataApp()` declaration and operation registry. Declare
4
4
  named SQL queries with typed `params` and `projections`; execute them through
5
- `dataApp.defineOperation()`. Use descriptive `lowerCamelCase` query names.
5
+ `dataApp.defineOperation()`. Give independent results separate queries and
6
+ operations; widgets showing the same rows or related metrics from one summary
7
+ may share a result. Use descriptive `lowerCamelCase` query names.
6
8
 
7
9
  ## Execute named queries
8
10
 
9
- This is the hosted starter's query contract inside `defineDataApp()`:
11
+ This sample-count example illustrates the query contract inside `defineDataApp()`;
12
+ adapt the queries in the selected starter to the app's data:
10
13
 
11
14
  ```ts
12
15
  import { defineDataApp } from '@altertable/data-app';
@@ -35,37 +38,47 @@ ORDER BY group_name LIMIT $limit`,
35
38
 
36
39
  Replace fixture SQL with inspected data. Keep query declarations and projections
37
40
  in sync when adapting SQL to the app's inputs. Preserve metric definitions.
38
- Keep operation inputs flat; derive SQL parameters inside `run()`:
41
+ List the [filters](filters.md) an operation reads; `run()` receives one flat
42
+ field per filter, and you derive SQL parameters inside it:
39
43
 
40
44
  ```ts
41
- import { parseCount } from '@altertable/data-app/contract';
42
-
43
- // ... dataApp and parseSampleCountFilter
44
- const operations = {
45
+ import { choiceFilter, parseCount } from '@altertable/data-app/contract';
46
+
47
+ // ... dataApp
48
+ const groupName = choiceFilter({
49
+ key: 'group',
50
+ label: 'Group',
51
+ defaultValue: 'all',
52
+ options: [
53
+ { id: 'all', label: 'All groups' },
54
+ { id: 'Alpha', label: 'Alpha' },
55
+ { id: 'Beta', label: 'Beta' },
56
+ ],
57
+ });
58
+ const operations = dataApp.defineOperations({
45
59
  sampleCountsByGroup: dataApp.defineOperation({
46
- input: parseSampleCountFilter,
47
- checks: [
48
- { groupName: '' },
49
- { groupName: 'Alpha' },
50
- { groupName: 'missing' },
51
- ],
60
+ filters: { groupName },
52
61
  policy: { maxQueryRows: 10, maxDurationMs: 15000 },
53
62
  async run({ query }, { groupName }) {
54
- const result = await query('sampleCountsByGroup', { groupName });
63
+ const result = await query('sampleCountsByGroup', {
64
+ groupName: groupName === 'all' ? '' : groupName,
65
+ });
55
66
  return result.rows.map(row => ({
56
67
  groupName: row.group_name,
57
68
  sampleCount: parseCount(row.sample_count),
58
69
  }));
59
70
  },
60
71
  }),
61
- };
72
+ });
62
73
  ```
63
74
 
64
- The starter supplies `parseSampleCountFilter()` and `parseCount()`. Validate
65
- unknown input in the parser and business rules in `run()`. Include representative
66
- valid inputs in `checks`. Derive results from `query()` rows without duplicate
67
- schemas or type assertions; clients and views infer the returned type.
68
- HTTP results must be JSON-serializable.
75
+ The filters validate input and supply the operation's checks; enforce business
76
+ rules in `run()`. Omit `filters` for an operation without inputs. An operation
77
+ with its own fields, such as a detail record ID, adds an `input` parser and
78
+ representative valid `checks` for those fields; its `filters` still parse the
79
+ scope it reads. Derive results from `query()` rows
80
+ without duplicate schemas or type assertions; clients and views infer the
81
+ returned type. HTTP results must be JSON-serializable.
69
82
 
70
83
  Host `queryParams` supplies protected parameters that callers cannot override.
71
84
  Other values come from `query()` arguments or defaults. The host/backend enforces
@@ -82,51 +95,40 @@ return SQL text and declare `string` when exact numeric precision matters.
82
95
 
83
96
  Use `operations.sampleCountsByGroup.queryNames` for context and evidence.
84
97
 
85
- ### Bind datetime ranges
98
+ ### Bind date ranges
86
99
 
87
- Declare a `dateTimeRange` parameter and pass a `DateTimeRange` to `query()`.
88
- For a [comparison variable](variables.md#absolute-and-relative-datetime-ranges),
89
- pass its `range` or `comparison` bounds. Reference those bounds in SQL:
100
+ Bind a date filter's `range` or `comparison` as two string parameters. Cast
101
+ them to DuckDB `TIMESTAMP`; include the start and exclude the end:
90
102
 
91
103
  ```ts
92
104
  const dataApp = defineDataApp({
93
105
  // ... title, description, and scope
94
106
  queries: {
95
- events: {
96
- statement: `SELECT occurred_at AS "occurredAt" FROM events
97
- WHERE occurred_at >= $period.from AND occurred_at < $period.to`,
98
- params: { period: { type: 'dateTimeRange' } },
99
- projections: { occurredAt: { type: 'string' } },
107
+ dailyOrders: {
108
+ statement: `SELECT CAST(ordered_at AS DATE) AS day, count(*) AS orders
109
+ FROM orders
110
+ WHERE ordered_at >= CAST($period_from AS TIMESTAMP)
111
+ AND ordered_at < CAST($period_to AS TIMESTAMP)
112
+ GROUP BY day ORDER BY day`,
113
+ params: {
114
+ period_from: { type: 'string' },
115
+ period_to: { type: 'string' },
116
+ },
117
+ projections: {
118
+ day: { type: 'string' },
119
+ orders: { type: 'number' },
120
+ },
100
121
  },
101
122
  },
102
123
  });
103
124
  ```
104
125
 
105
- The start is inclusive and the end exclusive. Relative values resolve at query
106
- execution. Absolute values encode wall-clock fields in UTC: selecting 4 PM stores
107
- 16:00Z.
108
- SQL bounds are timezone-free timestamps. Configure the backend session to the
109
- reporting timezone and interpret timestamp-with-timezone comparisons in that
110
- same zone.
111
-
112
- ## Share reporting policy
113
-
114
- Pass an optional `defineDateRangeContract()` to `dateTimeRangeVariable()` to
115
- share coverage, duration limits, and reporting timezone between the picker and
116
- server parser. By default, coverage ends yesterday; set `completeDays: false`
117
- to include today. Declare the policy once:
118
-
119
- ```ts
120
- import { defineDateRangeContract } from '@altertable/data-app/contract';
121
-
122
- const calendar = defineDateRangeContract({
123
- minDate: '2026-01-01',
124
- maxRangeDays: 90,
125
- timeZone: 'UTC',
126
- });
127
- ```
126
+ In the operation, import `queryDateTimeRangeParams` from
127
+ `@altertable/data-app/contract` and call
128
+ `query('dailyOrders', queryDateTimeRangeParams(periodFilter, period, 'period').current)`.
129
+ This resolves relative bounds when the query runs.
128
130
 
129
- Use the shared contract in the [datetime variable workflow](variables.md#absolute-and-relative-datetime-ranges),
130
- including optional previous-period comparison. Resolved datetime requests include
131
- the start and exclude the end. Pass the variable to `defineTimeView()` and
132
- validate operation input with its parser.
131
+ Date filters pass resolved bounds in their `timeZone`, encoded as UTC wall-clock
132
+ fields: 4 PM in the reporting zone is 16:00Z. SQL bounds are therefore
133
+ timezone-free timestamps; interpret timestamp-with-timezone columns in that same
134
+ zone. Coverage and duration limits live on the [date filter](filters.md#date-ranges).
@@ -1,7 +1,8 @@
1
1
  # Data context and evidence
2
2
 
3
- Continue the starter's operation and context. Use its derived `queryNames` for
4
- business definitions and evidence. Reference only queries the view executes.
3
+ Keep the selected starter's operations and context. Build one context from every
4
+ operation's `queryNames` and share it across the app's views. Reference only
5
+ queries the app executes.
5
6
 
6
7
  ## Bind evidence
7
8
 
@@ -9,23 +10,29 @@ business definitions and evidence. Reference only queries the view executes.
9
10
  import { createDataContext } from '@altertable/data-app-react';
10
11
 
11
12
  // ... operations
12
- const queryNames = operations.sampleCountsByGroup.queryNames;
13
+ const queryNames = {
14
+ ...operations.sampleCountsByGroup.queryNames,
15
+ ...operations.sampleTotal.queryNames,
16
+ };
13
17
  const sampleDataContext = createDataContext(queryNames)({
14
18
  description: 'Sample counts for the selected groups.',
15
19
  glossary: {
16
20
  sampleCount: {
17
21
  term: 'Sample count',
18
22
  definition: 'The number of samples in each group.',
19
- queryNames: [queryNames.sampleCountsByGroup],
23
+ queryNames: [queryNames.sampleCountsByGroup, queryNames.sampleTotal],
20
24
  },
21
25
  },
22
26
  });
23
27
  ```
24
28
 
29
+ This sample-count example uses the operations illustrated in [views](views.md).
25
30
  Import `createDataContext()` from `@altertable/data-app-react`. Supply
26
- `dataContext: sampleDataContext` on `sampleCountsView`, then use its glossary IDs
31
+ `dataContext: sampleDataContext` on each view, then use its glossary IDs
27
32
  in `view.metric()` and `view.dataset()`. Reuse those bindings in widgets and stories.
28
- Detail views need their own context when their queries differ.
33
+ Include detail operations' query names and definitions in the shared context.
34
+ A detail view can use a separate context when it needs different definitions or
35
+ coverage; a different query alone does not require one.
29
36
 
30
37
  ## Register source identifiers
31
38
 
@@ -12,10 +12,7 @@ Change the revision identifier when app source changes.
12
12
 
13
13
  ```tsx
14
14
  import { createDataAppRepairSession } from '@altertable/data-app-embed';
15
- import {
16
- DataAppBridge,
17
- DataAppRepairBanner,
18
- } from '@altertable/data-app-embed/react';
15
+ import { DataAppBridge } from '@altertable/data-app-embed/react';
19
16
 
20
17
  const session = createDataAppRepairSession({
21
18
  state: restoredState, // New app: { automaticRequests: 0, attemptedRevisions: [] }
@@ -24,15 +21,12 @@ const session = createDataAppRepairSession({
24
21
  });
25
22
 
26
23
  const viewer = (
27
- <>
28
- <DataAppRepairBanner session={session} />
29
- <DataAppBridge
30
- source={{ type: 'bundle', javascript }}
31
- title="Data app"
32
- repair={{ session, revision }}
33
- onMessage={onMessage}
34
- />
35
- </>
24
+ <DataAppBridge
25
+ source={{ type: 'bundle', javascript }}
26
+ title="Data app"
27
+ repair={{ session, revision }}
28
+ onMessage={onMessage}
29
+ />
36
30
  );
37
31
  ```
38
32
 
@@ -40,18 +34,18 @@ The host owns authorization, delivery, and state retention. `onStateChange` is
40
34
  awaited before automatic delivery; reject if state cannot be retained. Three automatic
41
35
  requests are allowed per session; manual requests and healthy revisions do not
42
36
  reset the allowance. Callback resolution means acceptance, not agent execution.
43
- Omit `onRepairRequest` when delivery or reliable state retention is unavailable;
44
- the banner offers diagnostics to copy instead. Avoid sensitive values in errors.
37
+ Omit `onRepairRequest` when delivery or reliable state retention is unavailable,
38
+ and offer the diagnostics to copy instead. Avoid sensitive values in errors.
45
39
  Source locations use generated filenames and positions.
46
40
 
47
- ## Custom banners
41
+ ## Repair UI
48
42
 
49
- Use `session.snapshot()` to read diagnostics, delivery status, the automatic
50
- request count, and the latest request's start time. Subscribe with
51
- `session.subscribe()` and request a fix with `session.requestRepair()`. These APIs
52
- work without React or the default banner.
43
+ The host renders its own repair UI. Use `session.snapshot()` to read diagnostics,
44
+ delivery status, the automatic request count, and the latest request's start
45
+ time. Subscribe with `session.subscribe()` and request a fix with
46
+ `session.requestRepair()`. These APIs work without React.
53
47
 
54
- In React, pass the snapshot to your own banner:
48
+ In React, pass the snapshot to your banner:
55
49
 
56
50
  ```tsx
57
51
  import type { DataAppRepairSession } from '@altertable/data-app-embed';
@@ -78,5 +72,4 @@ function AppRepair({ session }: { session: DataAppRepairSession }) {
78
72
  The host owns agent activity and revision loading. Request acceptance does not
79
73
  mean the agent has started or finished. Clear the previous attempt's activity
80
74
  when requesting another fix, and clear progress when the updated revision's
81
- diagnostics settle. Custom banners choose their own presentation; the default
82
- `<DataAppRepairBanner>` accepts observed host activity through `progress`.
75
+ diagnostics settle.
package/docs/embed.md CHANGED
@@ -170,45 +170,36 @@ const router = createMessageRouter(routes, {
170
170
  `router.dispatch()` validates route input and output. Use `MessageRoutingError`
171
171
  for intentional public failures; other handler errors are hidden.
172
172
 
173
- Use `defineDataQueryRoute(operationContracts)` for typed named operations or
174
- `dataAppRoutes` for generic operation and navigation routes. Handlers must
175
- validate operations, authorize data access, and enforce backend query limits.
173
+ Use `registeredQueryRoute` for data requests, or `dataAppRoutes` for the shared
174
+ registered-query and navigation contracts. Handlers must resolve IDs against
175
+ the saved app, authorize data access, and enforce backend query limits.
176
176
 
177
- ## SQL query route
177
+ ## Registered query route
178
178
 
179
- Hosts serving browser-owned operations register `sqlQueryRoute` explicitly:
179
+ Hosts serving browser-owned operations register `registeredQueryRoute`:
180
180
 
181
181
  ```ts
182
182
  import {
183
183
  createMessageRouter,
184
- sqlQueryRoute,
184
+ registeredQueryRoute,
185
185
  } from '@altertable/data-app/contract';
186
- import { createSqlQueryHandler } from '@altertable/data-app-embed';
187
186
 
188
187
  const router = createMessageRouter(
189
- { 'data:sql': sqlQueryRoute },
188
+ { 'data:query': registeredQueryRoute },
190
189
  {
191
- 'data:sql': createSqlQueryHandler(async (query, { signal }) => {
192
- return authorizedLakehouseForCurrentViewer(query, signal);
193
- }),
190
+ 'data:query': async ({ queryId, params, limit }, { signal }) =>
191
+ runRegisteredQueryForCurrentViewer({ queryId, params, limit, signal }),
194
192
  }
195
193
  );
196
194
  // Supply router.dispatch as the shell's onMessage handler.
197
195
  ```
198
196
 
199
- The host supplies `authorizedLakehouseForCurrentViewer()`. Its backend must enforce
200
- viewer/dataset permissions, permitted query behavior, maximum rows, execution
201
- time, concurrency, and response size independently of browser policy. Route
202
- validation is not SQL authorization. `createSqlQueryHandler()` calls authorization
203
- for each query, forwards cancellation, and preserves `DataSourceError` reasons
204
- as public `source_*` errors with request IDs. Authorization failures return
205
- `forbidden`; unknown query errors are hidden. Custom handlers can return deliberate
206
- public failures with `MessageRoutingError`.
207
-
208
- The SQL route carries `{ statement, limit, params? }` and returns column
209
- metadata and row arrays; see `SqlQueryInput` and `QueryResult` in the
210
- [API reference](../REFERENCE.md). Keep SQL and parameters unchanged.
211
- For server-owned named operations, use `dataAppRoutes` and `data:query` instead.
197
+ The host resolves `queryId` against the app's saved `defineDataApp({ queries })`
198
+ registry and runs that SQL with the supplied parameter values. It must enforce
199
+ viewer permissions, maximum rows, execution time, concurrency, and response size.
200
+ The route carries `{ queryId, limit, params? }` and returns column metadata and
201
+ row arrays; see `RegisteredQueryInput` and `QueryResult` in the
202
+ [API reference](../REFERENCE.md). Unknown IDs must fail before execution.
212
203
 
213
204
  ## Parent presentation
214
205
 
@@ -230,9 +221,53 @@ host.setPresentation({ surface: 'embedded', theme: 'light' });
230
221
  Use `surface: 'embedded'` when the parent supplies page chrome and
231
222
  `'standalone'` when the app supplies it. Resolve the parent theme to `'light'` or
232
223
  `'dark'`. React `<DataApp>` applies presentation automatically: embedded surfaces
233
- keep toolbar actions and hide header/footer. Updates do not reload the iframe.
224
+ hide the header, footer, and page toolbar, and offer its actions to the parent
225
+ through [page actions](#page-actions). Updates do not reload the iframe.
234
226
  Call `host.setPresentation(undefined)` to restore standalone defaults.
235
227
 
228
+ The parent also owns annotation mode whenever the app shows no toolbar, as on
229
+ embedded surfaces: set `annotations.active` (omitted means inactive) and handle
230
+ the `annotation:mode` route.
231
+
232
+ ### Page actions
233
+
234
+ An embedded app shows no toolbar. It offers its page actions to the parent,
235
+ which renders the controls and runs them through the bridge:
236
+
237
+ ```ts
238
+ // ... iframe, authorized router, and refreshButton
239
+ const host = attachDataAppBridge({
240
+ iframe,
241
+ source: { type: 'url', url: 'https://apps.example.com/report' },
242
+ presentation: { surface: 'embedded', theme: 'light' },
243
+ onActionsChange(actions) {
244
+ refreshButton.hidden = !actions.refresh;
245
+ refreshButton.disabled = actions.refresh?.refreshing ?? true;
246
+ },
247
+ onMessage: router.dispatch,
248
+ });
249
+
250
+ refreshButton.onclick = () => host.runAction({ type: 'refresh' });
251
+ ```
252
+
253
+ `onActionsChange` receives the complete `DataAppActions` on every change. Render
254
+ only the keys present:
255
+
256
+ | Offered state | Run | Notes |
257
+ | --------------------------------------- | --------------------------------- | ---------------------------------------------------------------------- |
258
+ | `refresh: { refreshing, cancellable }` | `refresh`, `cancelRefresh` | Cancel only while `refreshing` and `cancellable`. |
259
+ | `exportCsv: { enabled, tables }` | `exportCsv` with optional `table` | Omit `table` to export every dataset, as a ZIP when there are several. |
260
+ | `presentStory: { enabled, presenting }` | `presentStory`, `closeStory` | Shows the iframe fullscreen while presenting. |
261
+ | `aboutData: { enabled }` | `aboutData` | Opens the data inspector in the frame. |
262
+
263
+ Call `runAction()` from the user's click: the bridge needs that gesture to show
264
+ a story fullscreen. It exits fullscreen when the story closes, and leaving
265
+ fullscreen closes the story. `presentStory` and `aboutData` move focus into the
266
+ frame; when that story closes, focus returns to the control that ran it unless
267
+ the reader has moved elsewhere. The app ignores actions it does not currently
268
+ offer. While the app reconnects, actions reset to `{}` and `runAction()` does
269
+ nothing.
270
+
236
271
  ### Content sizing
237
272
 
238
273
  By default the parent sizes the iframe and the app scrolls inside it. Set