@altertable/data-app 0.72.0 → 0.74.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 (112) hide show
  1. package/AGENTS.md +5 -61
  2. package/CONTRIBUTING.md +130 -181
  3. package/README.md +3 -4
  4. package/REFERENCE.md +35 -345
  5. package/dist/chunks/contract-BeLPJwlO.js +558 -0
  6. package/dist/chunks/contract-BeLPJwlO.js.map +1 -0
  7. package/dist/chunks/contract-Di8SP74I.js +462 -0
  8. package/dist/chunks/contract-Di8SP74I.js.map +1 -0
  9. package/dist/chunks/diagnostics-BTZSlNtW.js +967 -0
  10. package/dist/chunks/diagnostics-BTZSlNtW.js.map +1 -0
  11. package/dist/chunks/format-BdFlv_xa.js +148 -0
  12. package/dist/chunks/format-BdFlv_xa.js.map +1 -0
  13. package/dist/chunks/operation-CSM9UmO3.js +134 -0
  14. package/dist/chunks/operation-CSM9UmO3.js.map +1 -0
  15. package/dist/chunks/request-body-H1qPmmTN.js +50 -0
  16. package/dist/chunks/request-body-H1qPmmTN.js.map +1 -0
  17. package/dist/client/index.js +273 -285
  18. package/dist/client/index.js.map +1 -13
  19. package/dist/core/appearance.js +171 -162
  20. package/dist/core/appearance.js.map +1 -10
  21. package/dist/core/config.js +49 -11
  22. package/dist/core/config.js.map +1 -9
  23. package/dist/core/contract.js +3 -73
  24. package/dist/core/format.js +1 -26
  25. package/dist/index.js +1 -12
  26. package/dist/internal.js +352 -397
  27. package/dist/internal.js.map +1 -15
  28. package/dist/server/index.js +85 -97
  29. package/dist/server/index.js.map +1 -10
  30. package/dist/types/chunks/appearance.d.ts +45 -0
  31. package/dist/types/chunks/contract.d.ts +720 -0
  32. package/dist/types/chunks/index.d.ts +240 -0
  33. package/dist/types/client/index.d.ts +3 -13
  34. package/dist/types/core/appearance.d.ts +2 -42
  35. package/dist/types/core/config.d.ts +36 -39
  36. package/dist/types/core/contract.d.ts +2 -114
  37. package/dist/types/core/format.d.ts +44 -17
  38. package/dist/types/index.d.ts +3 -3
  39. package/dist/types/internal.d.ts +312 -22
  40. package/dist/types/server/index.d.ts +15 -4
  41. package/docs/app-authoring.md +77 -128
  42. package/docs/client.md +29 -63
  43. package/docs/composition.md +44 -75
  44. package/docs/contract.md +60 -100
  45. package/docs/data-context.md +35 -61
  46. package/docs/diagnostics.md +45 -0
  47. package/docs/embed.md +86 -55
  48. package/docs/formatting-and-appearance.md +17 -38
  49. package/docs/hosted-apps.md +7 -14
  50. package/docs/layout.md +30 -47
  51. package/docs/local-data-apps.md +7 -7
  52. package/docs/react-embed.md +20 -26
  53. package/docs/react.md +10 -27
  54. package/docs/server-bun.md +2 -27
  55. package/docs/server.md +6 -12
  56. package/docs/stories-and-export.md +38 -40
  57. package/docs/styling.md +14 -22
  58. package/docs/ui-quality.md +5 -5
  59. package/docs/ui.md +93 -70
  60. package/docs/variables.md +142 -254
  61. package/docs/views.md +85 -116
  62. package/docs/widgets.md +100 -153
  63. package/docs/worker.md +15 -27
  64. package/package.json +3 -2
  65. package/dist/chunks/index-5a27erdg.js +0 -54
  66. package/dist/chunks/index-5a27erdg.js.map +0 -10
  67. package/dist/chunks/index-9yxr7nmm.js +0 -742
  68. package/dist/chunks/index-9yxr7nmm.js.map +0 -17
  69. package/dist/chunks/index-j5q5n3ra.js +0 -151
  70. package/dist/chunks/index-j5q5n3ra.js.map +0 -10
  71. package/dist/chunks/index-q75zm3a7.js +0 -153
  72. package/dist/chunks/index-q75zm3a7.js.map +0 -11
  73. package/dist/chunks/index-vhaec7m5.js +0 -30
  74. package/dist/chunks/index-vhaec7m5.js.map +0 -10
  75. package/dist/chunks/index-zp78caex.js +0 -1047
  76. package/dist/chunks/index-zp78caex.js.map +0 -19
  77. package/dist/core/contract.js.map +0 -9
  78. package/dist/core/format.js.map +0 -9
  79. package/dist/index.js.map +0 -9
  80. package/dist/types/client/annotations.d.ts +0 -27
  81. package/dist/types/client/data-client.d.ts +0 -43
  82. package/dist/types/client/download.d.ts +0 -5
  83. package/dist/types/client/iframe.d.ts +0 -59
  84. package/dist/types/client/location.d.ts +0 -13
  85. package/dist/types/client/logger.d.ts +0 -14
  86. package/dist/types/client/messages.d.ts +0 -7
  87. package/dist/types/client/navigation.d.ts +0 -15
  88. package/dist/types/client/transport.d.ts +0 -15
  89. package/dist/types/core/annotations.d.ts +0 -99
  90. package/dist/types/core/bridge-endpoint.d.ts +0 -21
  91. package/dist/types/core/bridge.d.ts +0 -172
  92. package/dist/types/core/data-view.d.ts +0 -46
  93. package/dist/types/core/date-format.d.ts +0 -24
  94. package/dist/types/core/date-range.d.ts +0 -20
  95. package/dist/types/core/dimension-source.d.ts +0 -64
  96. package/dist/types/core/dimension.d.ts +0 -71
  97. package/dist/types/core/facets.d.ts +0 -13
  98. package/dist/types/core/filters.d.ts +0 -45
  99. package/dist/types/core/invariant.d.ts +0 -2
  100. package/dist/types/core/keys.d.ts +0 -2
  101. package/dist/types/core/logger.d.ts +0 -12
  102. package/dist/types/core/messages.d.ts +0 -62
  103. package/dist/types/core/navigation.d.ts +0 -11
  104. package/dist/types/core/operation-types.d.ts +0 -80
  105. package/dist/types/core/operation.d.ts +0 -20
  106. package/dist/types/core/presentation.d.ts +0 -9
  107. package/dist/types/core/queries.d.ts +0 -84
  108. package/dist/types/core/reading.d.ts +0 -17
  109. package/dist/types/core/uuid.d.ts +0 -2
  110. package/dist/types/core/variables.d.ts +0 -133
  111. package/dist/types/server/handler.d.ts +0 -13
  112. package/dist/types/server/request-body.d.ts +0 -4
package/docs/embed.md CHANGED
@@ -12,6 +12,7 @@ message delivery. The host supplies an iframe and a validated message dispatcher
12
12
  ```ts
13
13
  import { attachDataAppBridge } from '@altertable/data-app-embed';
14
14
 
15
+ // ... iframe and authorized router
15
16
  const host = attachDataAppBridge({
16
17
  iframe,
17
18
  source: { type: 'url', url: 'https://apps.example.com/report' },
@@ -19,10 +20,10 @@ const host = attachDataAppBridge({
19
20
  });
20
21
  ```
21
22
 
22
- The host defines `iframe` and `router`; see [message contracts](contract.md#message-routes).
23
+ The host defines `iframe` and `router`; see [message contracts](#message-routes).
23
24
  Call `host.dispose()` before replacing the source or retrying. A URL source requires HTTP(S)
24
25
  and a different origin from its host. The source bridge adds `__altertable_parent` to the
25
- app URL. A hosted app must explicitly install a transport to its configured,
26
+ app URL. An app loaded by URL must install a transport to its configured,
26
27
  trusted parent origin using the [client API](client.md#iframe-transport).
27
28
  The query parameter alone does not establish trust.
28
29
 
@@ -43,11 +44,8 @@ direct network access. Data requests go through the host's dispatcher.
43
44
  Supply an HTTP(S) `bootstrapUrl` to use an externally served trusted bootstrap,
44
45
  such as the [Worker asset](worker.md).
45
46
 
46
- The host provides a self-contained JavaScript bundle. React bridges replace the
47
- iframe whenever its JavaScript content changes. Serve the bootstrap page with a CSP compatible with the bundle.
48
- Bundle mode uses `sandbox="allow-scripts"` and an opaque origin; it cannot read
49
- the host document or use same-origin privileges. Both modes use
50
- `referrerPolicy="no-referrer"`.
47
+ Supply a self-contained JavaScript bundle. Bundle mode uses an opaque
48
+ `sandbox="allow-scripts"` frame; both modes use `referrerPolicy="no-referrer"`.
51
49
 
52
50
  ## Trusted bootstrap
53
51
 
@@ -71,19 +69,15 @@ session token. Its hosting service must enforce its CSP. The bridge cannot impos
71
69
  CSP on a remote response. A starting policy for self-contained scripts and styles
72
70
  is `default-src 'none'; script-src 'unsafe-inline'; style-src 'unsafe-inline';
73
71
  img-src data: blob:; connect-src 'none'; base-uri 'none'; form-action 'none'`.
74
- The initializer installs a shared transport before evaluating the app script;
75
- data clients discover it even when independently bundled. The bootstrap contains
76
- no app navigation adapter. React mounting or URL controls attach navigation in the
77
- app bundle; non-React apps use `createDataAppNavigation()` from `/client`.
72
+ The initializer installs the transport before evaluating app code. Non-React
73
+ apps attach [navigation](client.md#app-navigation) separately.
78
74
 
79
75
  ## Delivery and navigation
80
76
 
81
- `attachDataAppBridge()` also supports connection mode for a host-owned iframe. Supply
82
- `connection: { type: 'origin', origin }` or `{ type: 'opaque', token }`, and an
83
- `onMessage` dispatcher. Both modes use the same transport. It returns `dispose()`, `setPresentation()`, and `setLogger()` methods and owns source/origin checks, request
84
- correlation, cancellation, bounded pending requests, and reconnection. Use source mode for bundle loading and token rotation. The opaque destination requires
85
- wildcard delivery, but incoming messages still require the exact iframe window,
86
- null origin, token, document, and session to match.
77
+ For an already loaded, host-owned iframe, supply
78
+ `connection: { type: 'origin', origin }` or `{ type: 'opaque', token }` with
79
+ `onMessage`. The host then owns loading and sandbox policy. Use source mode for
80
+ bundle loading and session setup.
87
81
 
88
82
  `createNavigationHandler({ window, reservedSearchParams })` handles the shared
89
83
  `navigation:update` route using browser history. Reserved host query parameters
@@ -100,17 +94,47 @@ client acknowledged initialization or a bundle script finished evaluation. It
100
94
  does not mean asynchronous data queries finished. Script errors report `failed`.
101
95
  The source bridge's `startupTimeoutMs` defaults to 30 seconds.
102
96
 
103
- `onDiagnostic` receives delivery metadata, never tokens or payloads: `direction`
104
- (`send`, `receive`, or `drop`), message `type`, and, when present, the request
105
- `id`, `route`, query `operation`, and error `code`, `message`, and `requestId`.
106
- Results and errors include `durationMs`, the host handling time. `drop` events
107
- report why a message from the connected iframe was ignored, such as a stale
108
- session or token; messages from other windows are not reported.
97
+ Use `onDiagnostic` or `logger` to inspect delivery and failures. Diagnostics omit
98
+ tokens and payloads. Handlers must authorize every data request; message
99
+ validation and iframe isolation do not grant data access.
109
100
 
110
- When a `logger` is set, the iframe also forwards its view of the bridge: messages
111
- it sends, receives, and ignores, local timeouts, reconnect resets, and the cause
112
- of a `failed` status. Routed handlers must authorize every data request. Message
113
- validation and iframe isolation do not grant access to data or execute SQL.
101
+ ## Message routes
102
+
103
+ Message contracts describe the payloads allowed between an embedded app and its
104
+ host. Share these contracts with the app; keep handlers and authorization in the
105
+ host/server.
106
+
107
+ Name routes `{scope}:{action}`, for example `data:query` or `navigation:update`.
108
+
109
+ ```ts
110
+ import {
111
+ createMessageRouter,
112
+ defineMessageRoute,
113
+ navigationUpdateRoute,
114
+ } from '@altertable/data-app/contract';
115
+ import { createNavigationHandler } from '@altertable/data-app-embed';
116
+
117
+ function parseString(value: unknown) {
118
+ if (typeof value !== 'string') throw new Error('Expected a string.');
119
+ return value;
120
+ }
121
+
122
+ const routes = {
123
+ 'demo:echo': defineMessageRoute({ input: parseString, output: parseString }),
124
+ 'navigation:update': navigationUpdateRoute,
125
+ };
126
+ const router = createMessageRouter(routes, {
127
+ 'demo:echo': value => value,
128
+ 'navigation:update': createNavigationHandler(),
129
+ });
130
+ ```
131
+
132
+ `router.dispatch()` validates route input and output. Use `MessageRoutingError`
133
+ for intentional public failures; other handler errors are hidden.
134
+
135
+ Use `defineDataQueryRoute(operationContracts)` for typed named operations or
136
+ `dataAppRoutes` for generic operation and navigation routes. Handlers must
137
+ validate operations, authorize data access, and enforce backend query limits.
114
138
 
115
139
  ## SQL query route
116
140
 
@@ -143,25 +167,17 @@ as public `source_*` errors with request IDs. Authorization failures return
143
167
  `forbidden`; unknown query errors are hidden. Custom handlers can return deliberate
144
168
  public failures with `MessageRoutingError`.
145
169
 
146
- `SqlQueryInput` (exported from `/contract`) carries
147
- `{ statement: string, limit: number, params?: QueryParameters }`; the backend
148
- interprets the unchanged statement and parameter values. Responses are
149
- `{ columns: { name: string, type?: string }[], rows: unknown[][], queryId?: string }`.
150
- The route rejects empty statements, unsafe or nonpositive limits, malformed
151
- results, and results exceeding the requested limit. The bridge's existing payload
152
- and pending-call limits apply, and cancellation reaches the handler's signal.
153
- Operation names and inputs stay in the app; query evidence is assembled there.
154
-
155
- `dataAppRoutes` retains named `data:query` and navigation routes for existing
156
- server-backed hosts. SQL hosts opt into `data:sql`; they need no named-operation
157
- handler unless they also serve HTTP-style apps. Update the host before switching
158
- an app to browser-owned operations. Older hosts reject `data:sql` as unknown.
170
+ The SQL route carries `{ statement, limit, params? }` and returns column
171
+ metadata and row arrays; see `SqlQueryInput` and `QueryResult` in the
172
+ [API reference](../REFERENCE.md). Keep SQL and parameters unchanged.
173
+ For server-owned named operations, use `dataAppRoutes` and `data:query` instead.
159
174
 
160
175
  ## Parent presentation
161
176
 
162
177
  The parent declares where the iframe is mounted and owns its resolved theme:
163
178
 
164
179
  ```ts
180
+ // ... iframe and authorized router
165
181
  const host = attachDataAppBridge({
166
182
  iframe,
167
183
  source: { type: 'url', url: 'https://apps.example.com/report' },
@@ -173,18 +189,33 @@ const host = attachDataAppBridge({
173
189
  host.setPresentation({ surface: 'embedded', theme: 'light' });
174
190
  ```
175
191
 
176
- Both source and connection modes support the `presentation` option and
177
- `host.setPresentation(presentation)` method. `DataAppPresentation` is exported from
178
- `/embed`. Use `surface: 'embedded'` when the parent provides page chrome, as in the
179
- Altertable frontend, and `'standalone'` when the app provides its own header and
180
- footer. `theme` must be resolved to `'light'` or
181
- `'dark'`; the parent decides how its system preference is resolved.
182
-
183
- Presentation travels over `postMessage()` in the authenticated `bridge:initialize` and
184
- `state:update` messages, alongside `search` and `hash`. Framework-neutral apps
185
- can narrow the unknown state returned by `bridge.snapshot()` to read its
186
- `presentation` field, and subscribe through `bridge.subscribe()`. React `<DataApp>` consumes it automatically.
187
- An embedded surface renders toolbar actions without the page header or footer.
188
- Both surfaces follow the parent's theme, including presentation mode, without
189
- changing saved viewer preferences. Omitting presentation preserves standalone behavior;
190
- `host.setPresentation(undefined)` restores it.
192
+ Use `surface: 'embedded'` when the parent supplies page chrome and
193
+ `'standalone'` when the app supplies it. Resolve the parent theme to `'light'` or
194
+ `'dark'`. React `<DataApp>` applies presentation automatically: embedded surfaces
195
+ keep toolbar actions and hide header/footer. Updates do not reload the iframe.
196
+ Call `host.setPresentation(undefined)` to restore standalone defaults.
197
+
198
+ ### Content sizing
199
+
200
+ By default the parent sizes the iframe and the app scrolls inside it. Set
201
+ `sizing: 'content'` when the parent page should scroll instead, as in a details
202
+ panel that stacks the app with other content:
203
+
204
+ ```ts
205
+ host.setPresentation({
206
+ surface: 'embedded',
207
+ theme: 'light',
208
+ sizing: 'content',
209
+ });
210
+ ```
211
+
212
+ React `<DataApp>` supports content sizing automatically; framework-neutral apps
213
+ call `bridge.supportContentSizing()`. Keep iframe flex/grid stretching and
214
+ `max-height` constraints off so the reported height can apply. Keep app document
215
+ and body heights automatic.
216
+
217
+ If sizing fails to settle, the bridge restores frame scrolling. Toggle sizing or
218
+ reload to retry. Switching to `'frame'` or disposing restores the authored height.
219
+
220
+ For shared diagnostic reports, bounded agent repair and the in-flow banner, see
221
+ [App diagnostics and repair](diagnostics.md).
@@ -35,10 +35,7 @@ formatCount(2_200_000); // "2,200,000"
35
35
  For signed or fractional measures, use `formatNumber()` with
36
36
  `notation: 'compact'` and preserve the measure's units.
37
37
 
38
- Import `chartColor()` from `@altertable/data-app-react` to select colors from the configured palette.
39
- `<PeriodSummary>` describes reporting periods; `<UpdatedAt>` and
40
- `<DateTimeTooltip>` expose readable timestamps with exact-date details.
41
- `<DataTableTimestamp>` and `<DataTableShare>` format custom table cells.
38
+ Use `chartColor()` from `@altertable/data-app-react` for palette colors.
42
39
 
43
40
  ## Display dates consistently
44
41
 
@@ -46,13 +43,17 @@ Declare date meaning on dataset columns so tables use readable values and CSV
46
43
  keeps the originals:
47
44
 
48
45
  ```ts
49
- columns: {
50
- day: { value: row => row.day, format: { kind: 'date' } },
51
- observed: {
52
- value: row => row.observed,
53
- format: { kind: 'dateTime', precision: 'second' },
46
+ // ... dailyCountsView with day and observed result fields
47
+ const dailyCounts = dailyCountsView.dataset({
48
+ // ... name, select, rowKey, and evidence
49
+ columns: {
50
+ day: { value: row => row.day, format: { kind: 'date' } },
51
+ observed: {
52
+ value: row => row.observed,
53
+ format: { kind: 'dateTime', precision: 'second' },
54
+ },
54
55
  },
55
- }
56
+ });
56
57
  ```
57
58
 
58
59
  Calendar dates use `YYYY-MM-DD`. Instants accept epoch milliseconds or timestamp
@@ -68,32 +69,10 @@ ordering matters; exact-time details remain available on timestamps.
68
69
 
69
70
  ## Configure identity and appearance
70
71
 
71
- ```ts
72
- import { defineDataApp } from '@altertable/data-app';
73
-
74
- const dataApp = defineDataApp({
75
- title: 'Product activity',
76
- description: 'Explore product usage and trends.',
77
- scope: { organization: 'Acme', environment: 'Production' },
78
- appearance: {
79
- theme: 'system',
80
- baseColor: 'neutral',
81
- density: 'comfortable',
82
- },
83
- queries: {},
84
- });
85
- ```
86
-
87
- Scope labels describe the configured connection; they do not grant access.
88
-
89
- Title and description explain the app and can be revised when regenerating it.
90
- Omit appearance to use the standard defaults.
91
-
92
- The default UI is neutral in light and dark themes. Use `baseColor` for the base
93
- palette and `accentColor` with optional `darkAccentColor` for brand emphasis.
94
- Configure chart colors separately with `chartColors`; preserve semantic status
95
- colors for favorable and unfavorable outcomes.
72
+ Set `title`, `description`, and connection `scope` in `defineDataApp()`. Scope
73
+ labels describe the connection; they do not grant access.
96
74
 
97
- Configure appearance once for the app. Theme preference is user-owned in standalone apps. A trusted parent's
98
- resolved theme takes precedence and hides local theme controls; see
99
- [parent presentation](embed.md#parent-presentation).
75
+ Keep default appearance. Customize only when requested, configuring it once: `baseColor` for
76
+ the base palette, `accentColor` and optional `darkAccentColor` for emphasis,
77
+ and `chartColors` for charts. Preserve semantic favorable/unfavorable colors.
78
+ Embedded apps follow the parent's resolved theme.
@@ -1,29 +1,22 @@
1
1
  # Author a data app
2
2
 
3
- Follow the [shared authoring flow](app-authoring.md) using [index.tsx](app-authoring.md#use-release-matched-starters) for a hosted / remote / cloud data app. Keep the app in
3
+ Follow the [shared authoring flow](app-authoring.md) with the version-matched `starter-data-app/index.tsx` for a hosted / remote / cloud data app. Keep the app in
4
4
  one file with public package imports; omit server files, HTML, credentials, and
5
5
  relative or app-alias imports.
6
6
 
7
- Declare the app once at module scope with the named `defineDataApp` import from
8
- `@altertable/data-app`. Prefer `const app = defineDataApp({ ... })`; import aliases
9
- and any variable name are allowed. Export only for other modules.
7
+ Declare `const dataApp = defineDataApp({ ... })` once at module scope using the
8
+ named import from `@altertable/data-app`.
10
9
 
11
10
  Keep the argument literal: objects, arrays, strings (including templates without
12
11
  interpolation), finite signed numbers, booleans, and null. Parentheses, `as`, and
13
12
  `satisfies` are allowed. Keep executable composition outside the call; omit spreads,
14
13
  computed keys, references, and callbacks. Static apps use `queries: {}`.
15
- TypeScript checks configuration shape. Static extraction reads the literal data
16
- without executing app code or interpreting SQL.
17
14
 
18
- Replace the sample app declaration, operations, filters, data context, CSV export, and story with
19
- an exploration of the source data you inspected. The starter uses two SQL
20
- `VALUES` rows, so it needs no production table.
15
+ Replace sample queries and bindings with inspected source data. Supply `scope`
16
+ in `defineDataApp()` and `story` and `datasets` on `<DataApp>`.
21
17
 
22
- `defineDataApp()` requires `scope`, and `<DataApp>` from `/react` requires
23
- `story` and `datasets`; the [API reference](../REFERENCE.md) marks every
24
- optional prop with `?`.
25
-
26
- For execution details, see [browser-owned operations](client.md#browser-owned-operations-for-bundle-apps).
18
+ Keep the starter's client, style injection, and mounting code. The host supplies
19
+ the transport; no bootstrap or message routes are needed in app code.
27
20
 
28
21
  ## Convert a local data app
29
22
 
package/docs/layout.md CHANGED
@@ -1,56 +1,39 @@
1
- # Layout contract
1
+ # Layout
2
2
 
3
- The shell owns page width, outer gutters, and header/body spacing. Use `<Stack>`
4
- for sections, `<Grid>` for peer widgets, and `<GridItem>` for spans. Use
5
- `<SectionHeading>` to name widget groups and `<TextContent>` for prose. Widgets own their internal padding; their parents own
6
- external spacing. Keep widget customization inside the widget so its parent can maintain consistent
7
- spacing between sections and cards.
8
-
9
- Configure density once in `app.appearance`. `<Grid>` wraps to fit its container;
10
- spans collapse when there is not enough space.
3
+ Use `<Stack>` for reading order, `<Grid>` for peer widgets, and `<GridItem>` for
4
+ spans. The shell owns page width and gutters; parents own spacing and widgets
5
+ own internal padding. Keep default density unless customization is requested.
11
6
 
12
7
  ```tsx
13
- <Stack>
14
- <SectionHeading>Activity</SectionHeading>
15
- <TextContent>
16
- <p>Explore the sources behind this finding.</p>
17
- </TextContent>
18
- <Grid columns={3}>
19
- <GridItem span={2}>{activityChart}</GridItem>
20
- <GridItem>{activityMetric}</GridItem>
21
- </Grid>
22
- </Stack>
8
+ // ... sampleCountsView, sampleCounts, and totalSamples
9
+ const sampleContent = sampleCountsView.content(result => (
10
+ <Stack>
11
+ <SectionHeading>Sample counts</SectionHeading>
12
+ <TextContent>
13
+ <p>Explore the sources behind this finding.</p>
14
+ </TextContent>
15
+ <Grid columns={3}>
16
+ <GridItem span={2}>
17
+ <TableWidget dataset={sampleCounts} source={result} />
18
+ </GridItem>
19
+ <GridItem>
20
+ <MetricWidget metric={totalSamples} source={result} />
21
+ </GridItem>
22
+ </Grid>
23
+ </Stack>
24
+ ));
23
25
  ```
24
26
 
25
- Set widget `headingLevel={3}` beneath a section heading; visual styling stays
26
- consistent across widget types.
27
-
28
- Use `<DataApp footer={...}>` for an optional source, coverage, or methodology
29
- note below the app content. The footer provides muted body text across the content
30
- width and top spacing. Compose paragraphs, links, lists, and inline components such
31
- as `<DataIdentifier>` or `<DateDisplay>` directly; no `<TextContent>` wrapper is
32
- needed. Keep headings and data widgets in the body, and app controls in
33
- `footerActions`. Keep static notes outside loading sections.
27
+ Grids wrap to fit their container and spans collapse when needed. Set widget
28
+ `headingLevel={3}` beneath a section heading.
34
29
 
35
- ```tsx
36
- <DataApp
37
- {...appProps}
38
- footer={
39
- <>
40
- <p>
41
- <strong>Coverage.</strong> Records include the last 90 days.
42
- </p>
43
- <p>Counts reflect current inventory, not an activity log.</p>
44
- </>
45
- }
46
- >
47
- <DataSection content={content} />
48
- </DataApp>
49
- ```
30
+ Use `<DataApp footer={...}>` for static source, coverage, or methodology notes.
31
+ Compose paragraphs, links, and inline components directly; no `<TextContent>`
32
+ wrapper is needed. Keep headings and widgets in the body and controls in
33
+ `footerActions`.
50
34
 
51
35
  ## Verify rendered layouts
52
36
 
53
- Check spacing, alignment, outer gutters, and
54
- horizontal overflow at phone and desktop iframe widths. Check loading, empty,
55
- error, ready, and stale states. Loading placeholders should use the same grid as
56
- the ready content.
37
+ Review authored composition with realistic labels and values. For custom layout
38
+ or sizing, check spacing and overflow at narrow and wide iframe widths. Keep
39
+ the same grid during loading and ready states.
@@ -1,14 +1,14 @@
1
1
  # Author a local data app
2
2
 
3
- Start from the CLI scaffold or the [local starter](app-authoring.md#use-release-matched-starters).
4
- Use the starter's README for setup and its AGENTS.md to find app-owned files.
3
+ Use the local scaffold supplied by your authoring workflow. Its README covers
4
+ setup and its AGENTS.md identifies app-owned files.
5
5
  Replace the connectivity screen with the exploration, CSV export, and story from the
6
6
  [shared authoring flow](app-authoring.md).
7
7
 
8
- | Task | Documentation |
9
- | --------------------------------------- | ---------------------------------------- |
10
- | Serve locally with Bun | [Bun server](server-bun.md) |
11
- | Execute and authorize server operations | [Server](server.md) |
12
- | Call operations from the browser | [HTTP client](client.md#http-operations) |
8
+ | Task | Documentation |
9
+ | ---------------------------- | ---------------------------------------- |
10
+ | Customize local serving | [Bun server](server-bun.md) |
11
+ | Authorize hosted viewers | [Server](server.md) |
12
+ | Customize the browser client | [HTTP client](client.md#http-operations) |
13
13
 
14
14
  You can also [convert the local app to a hosted data app](hosted-apps.md#convert-a-local-data-app).
@@ -1,13 +1,8 @@
1
1
  # React embedding
2
2
 
3
- Import `<DataAppBridge>` from `@altertable/data-app-embed/react`. This entry depends
4
- on React and the embedding engine, and does not load the app's widgets, React
5
- Query, or CSS. `@altertable/data-app-react` builds the UI inside the iframe;
6
- neither package imports the other. Both use the base package's contracts.
7
-
8
- The bridge owns iframe setup and `postMessage()` communication. The consuming
9
- frontend or CLI owns its shell: fetching a bundle, subscriptions, layout, loading
10
- and error UI, and retry controls. Both hosts use the same bridge and transport.
3
+ Import `<DataAppBridge>` from `@altertable/data-app-embed/react`.
4
+ The bridge owns iframe setup and communication. The host owns bundle fetching,
5
+ layout, loading/error UI, and retry controls.
11
6
 
12
7
  ## Source-managed iframe
13
8
 
@@ -20,6 +15,7 @@ import { useReducer, useState } from 'react';
20
15
  import { DataAppBridge } from '@altertable/data-app-embed/react';
21
16
  import type { DataAppStatus } from '@altertable/data-app-embed';
22
17
 
18
+ // ... authorized router
23
19
  function Shell() {
24
20
  const [status, setStatus] = useState<DataAppStatus>('connecting');
25
21
  const [attempt, retry] = useReducer(value => value + 1, 0);
@@ -41,12 +37,21 @@ function Shell() {
41
37
  }
42
38
  ```
43
39
 
44
- The host supplies `router` using [message contracts](contract.md#message-routes).
40
+ The host supplies `router` using [message contracts](embed.md#message-routes).
45
41
  The local URL must have a different origin from its shell. For hosted bundles,
46
42
  replace `source` with:
47
43
 
48
44
  ```tsx
49
- source={{ type: 'bundle', javascript }}
45
+ function Shell() {
46
+ // ... javascript bundle and router
47
+ return (
48
+ <DataAppBridge
49
+ title="Activity report"
50
+ source={{ type: 'bundle', javascript }}
51
+ onMessage={router.dispatch}
52
+ />
53
+ );
54
+ }
50
55
  ```
51
56
 
52
57
  The host supplies the JavaScript bundle. Omit `bootstrapUrl` for the packaged
@@ -58,10 +63,8 @@ bridge's React `key` to retry with a fresh frame. Handler changes use the latest
58
63
  callbacks without resetting the session. `startupTimeoutMs`, `onStatusChange`, and
59
64
  `onDiagnostic` have the same meaning as in the framework-neutral API.
60
65
 
61
- `iframeProps` forwards presentation and accessibility attributes to the iframe,
62
- including `className`, `style`, and `hidden`. The bridge controls `src`, `srcDoc`,
63
- `sandbox`, `referrerPolicy`, `loading`, and the callback ref. Loading is always
64
- `eager` so an iframe hidden until ready can start. Supply `title` directly.
66
+ Use `iframeProps` for styling, visibility, and accessibility attributes; supply
67
+ `title` directly. The bridge owns source, sandbox, loading, and ref attributes.
65
68
 
66
69
  ## Host-owned iframe
67
70
 
@@ -72,6 +75,7 @@ owns a loaded iframe and its security policy:
72
75
  import { useState, type ComponentRef } from 'react';
73
76
  import { DataAppBridge } from '@altertable/data-app-embed/react';
74
77
 
78
+ // ... appUrl and authorized router
75
79
  function Host() {
76
80
  const [iframe, setIframe] = useState<ComponentRef<'iframe'> | null>(null);
77
81
  return (
@@ -87,18 +91,8 @@ function Host() {
87
91
  }
88
92
  ```
89
93
 
90
- The app supplies `appUrl` and `router`. A callback ref lets the bridge observe late
91
- mounting and replacement; listeners attach to the iframe's owner document. This
92
- mode renders nothing and handles delivery only. Use source mode for bundle
93
- loading, sandbox policy, token rotation, and startup timeout. The two prop modes
94
- are mutually exclusive.
95
-
96
- ## Loading an embedded app
97
-
98
- The host owns loading and generation UI while an app starts. Use a neutral
99
- status that does not imply a particular app layout. `@altertable/data-app-embed/react` remains
100
- independent of UI components and styles. Once the app loads, its query and
101
- widget loading states describe the content they replace.
94
+ Supply `appUrl` and `router`. A callback ref tracks iframe mounting and
95
+ replacement. This mode renders nothing; the host owns loading and security policy.
102
96
 
103
97
  ## Parent-owned presentation
104
98
 
package/docs/react.md CHANGED
@@ -1,40 +1,23 @@
1
1
  # React
2
2
 
3
- Import hooks, components, and UI helpers from `@altertable/data-app-react`.
4
- React 19.2 or newer and React DOM 19.2 or newer are peer dependencies.
3
+ Import views, bound widgets, and layouts from `@altertable/data-app-react`.
4
+ React and React DOM 19.2 or newer are required. Start with
5
+ [app authoring](app-authoring.md).
5
6
 
6
7
  ## Mount the app
7
8
 
8
- Use `mountDataApp({ app, component })` to mount into `#root`. When mounting
9
- through another framework, wrap the root in `<DataAppProvider app={app}>` from `@altertable/data-app-react/ui`.
10
- `<DataApp>` inherits identity and appearance from that root.
11
-
12
9
  ```tsx
13
10
  import { injectDataAppStyles, mountDataApp } from '@altertable/data-app-react';
14
11
 
15
12
  injectDataAppStyles();
16
- mountDataApp({ app, component: App });
13
+ mountDataApp({ app: dataApp, component: App });
17
14
  ```
18
15
 
19
- Call `injectDataAppStyles()` before mounting; no separate stylesheet is needed.
20
- For a restrictive CSP, pass the permitted nonce on the first call.
21
- See [Styling](styling.md) for appearance, CSS tokens, and overrides.
22
-
23
- Use `@altertable/data-app-react` for declared views, bound widgets, and layouts. Use
24
- [`@altertable/data-app-react/ui`](ui.md) for setup/static screens and direct UI composition.
25
-
26
- ## Choose a task
16
+ The app supplies `dataApp`, `App`, and a `#root` element.
27
17
 
28
- | Task | Guide |
29
- | -------------------------------------------------------- | --------------------------------------------------------- |
30
- | Declare a view and handle loading, refresh, and failures | [Views](views.md) |
31
- | Configure date, text, select, and dimension controls | [Variables](variables.md) |
32
- | Render metrics, charts, tables, and narrative | [Widgets](widgets.md) |
33
- | Compose sections and responsive grids | [Layout](layout.md) |
34
- | Register sources, definitions, metrics, and evidence | [Data context](data-context.md) |
35
- | Present findings and export displayed data | [Stories and export](stories-and-export.md) |
36
- | Format values and configure appearance | [Formatting and appearance](formatting-and-appearance.md) |
37
- | Host an iframe from React | [React embed](react-embed.md) |
18
+ Keep the starter's mounting and client wiring. Use declared views and bound
19
+ widgets for exploration. Use `/ui` for setup/static screens or a custom component
20
+ only when bound components cannot express the requirement.
38
21
 
39
- Start with [app authoring](app-authoring.md) and the
40
- [single-file starter](app-authoring.md#use-release-matched-starters).
22
+ Hosts embedding an app use the separate `@altertable/data-app-embed` package;
23
+ that integration is outside ordinary app authoring.
@@ -10,7 +10,7 @@ when typechecking a Bun app.
10
10
  ```ts
11
11
  import { serveLocalApp } from '@altertable/data-app-bun';
12
12
  import page from './index.html';
13
- import { operations } from './operations';
13
+ import { operations } from './operations.ts';
14
14
 
15
15
  serveLocalApp({ page, operations, title: 'Activity' });
16
16
  ```
@@ -22,33 +22,8 @@ The server binds to `127.0.0.1`. Its default port is `25837`, overridable throug
22
22
  `ALTERTABLE_DATA_PROXY_URL` and `ALTERTABLE_DATA_PROXY_TOKEN`. It also supports
23
23
  server-only `ALTERTABLE_LAKEHOUSE_USERNAME` and
24
24
  `ALTERTABLE_LAKEHOUSE_PASSWORD`, with an optional `ALTERTABLE_API_BASE`.
25
- Missing credentials fail the query. Keep these variables out of browser code.
25
+ Missing credentials fail at startup. Keep these variables out of browser code.
26
26
 
27
27
  Local serving does not authenticate hosted viewers.
28
28
  Use [the portable server handler](server.md) with per-request authorization when
29
29
  hosting an app for other people.
30
-
31
- ## Preview a single-file app
32
-
33
- Import `serveAppFile()` from `@altertable/data-app-bun/preview` to preview
34
- an app in the hosted sandbox. The caller supplies the server-only lakehouse.
35
- The runtime owns bundling, imported-file watching, reloads, navigation, and exports.
36
-
37
- ```ts
38
- import { serveAppFile } from '@altertable/data-app-bun/preview';
39
- import { localLakehouse } from '@altertable/data-app-bun';
40
-
41
- const preview = await serveAppFile({
42
- file: '/absolute/path/index.tsx',
43
- lakehouse: localLakehouse(),
44
- });
45
- console.log(preview.url);
46
- // When the launcher stops:
47
- await preview.stop();
48
- ```
49
-
50
- The preview resolves `@altertable/data-app` and React from its own installation.
51
- It binds to localhost and accepts SQL only from its own origin,
52
- with a streaming limit of 100,000 UTF-8 bytes per query request. The caller
53
- owns profile validation, dependency installation, and credentials. This entry requires Bun and adds no Bun installation or dependency
54
- to browser consumers. Keep it separate from browser imports.