@bitbitpress/client 1.0.4 → 1.1.0-alpha.1

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 (66) hide show
  1. package/README.md +224 -0
  2. package/dist/react/index.d.ts +60 -0
  3. package/dist/react/index.d.ts.map +1 -0
  4. package/dist/react/index.js +85 -0
  5. package/dist/react/index.js.map +1 -0
  6. package/dist/react/primitives.d.ts +54 -0
  7. package/dist/react/primitives.d.ts.map +1 -0
  8. package/dist/react/primitives.js +223 -0
  9. package/dist/react/primitives.js.map +1 -0
  10. package/dist/react-native-expo/index.d.ts +53 -0
  11. package/dist/react-native-expo/index.d.ts.map +1 -0
  12. package/dist/react-native-expo/index.js +92 -0
  13. package/dist/react-native-expo/index.js.map +1 -0
  14. package/dist/react-native-expo/primitives.d.ts +58 -0
  15. package/dist/react-native-expo/primitives.d.ts.map +1 -0
  16. package/dist/react-native-expo/primitives.js +218 -0
  17. package/dist/react-native-expo/primitives.js.map +1 -0
  18. package/dist/synthesisView/context.d.ts +18 -0
  19. package/dist/synthesisView/context.d.ts.map +1 -0
  20. package/dist/synthesisView/context.js +15 -0
  21. package/dist/synthesisView/context.js.map +1 -0
  22. package/dist/synthesisView/createComponentMap.d.ts +18 -0
  23. package/dist/synthesisView/createComponentMap.d.ts.map +1 -0
  24. package/dist/synthesisView/createComponentMap.js +40 -0
  25. package/dist/synthesisView/createComponentMap.js.map +1 -0
  26. package/dist/synthesisView/devLog.d.ts +10 -0
  27. package/dist/synthesisView/devLog.d.ts.map +1 -0
  28. package/dist/synthesisView/devLog.js +23 -0
  29. package/dist/synthesisView/devLog.js.map +1 -0
  30. package/dist/synthesisView/engine.d.ts +35 -0
  31. package/dist/synthesisView/engine.d.ts.map +1 -0
  32. package/dist/synthesisView/engine.js +139 -0
  33. package/dist/synthesisView/engine.js.map +1 -0
  34. package/dist/synthesisView/primitives.d.ts +180 -0
  35. package/dist/synthesisView/primitives.d.ts.map +1 -0
  36. package/dist/synthesisView/primitives.js +29 -0
  37. package/dist/synthesisView/primitives.js.map +1 -0
  38. package/dist/synthesisView/resolve.d.ts +17 -0
  39. package/dist/synthesisView/resolve.d.ts.map +1 -0
  40. package/dist/synthesisView/resolve.js +42 -0
  41. package/dist/synthesisView/resolve.js.map +1 -0
  42. package/dist/synthesisView/types.d.ts +121 -0
  43. package/dist/synthesisView/types.d.ts.map +1 -0
  44. package/dist/synthesisView/types.js +2 -0
  45. package/dist/synthesisView/types.js.map +1 -0
  46. package/dist/synthesisView/useEventDrivenView.d.ts +32 -0
  47. package/dist/synthesisView/useEventDrivenView.d.ts.map +1 -0
  48. package/dist/synthesisView/useEventDrivenView.js +157 -0
  49. package/dist/synthesisView/useEventDrivenView.js.map +1 -0
  50. package/dist/synthesisView/useSynthesisView.d.ts +13 -0
  51. package/dist/synthesisView/useSynthesisView.d.ts.map +1 -0
  52. package/dist/synthesisView/useSynthesisView.js +49 -0
  53. package/dist/synthesisView/useSynthesisView.js.map +1 -0
  54. package/dist/user/index.d.ts +14 -1
  55. package/dist/user/index.d.ts.map +1 -1
  56. package/dist/user/index.js +6 -1
  57. package/dist/user/index.js.map +1 -1
  58. package/dist/user/synthesize-view-batch-manager.d.ts +17 -0
  59. package/dist/user/synthesize-view-batch-manager.d.ts.map +1 -0
  60. package/dist/user/synthesize-view-batch-manager.js +52 -0
  61. package/dist/user/synthesize-view-batch-manager.js.map +1 -0
  62. package/dist/user/synthesizeView.d.ts +41 -0
  63. package/dist/user/synthesizeView.d.ts.map +1 -0
  64. package/dist/user/synthesizeView.js +26 -0
  65. package/dist/user/synthesizeView.js.map +1 -0
  66. package/package.json +29 -5
package/README.md CHANGED
@@ -1141,3 +1141,227 @@ type InteractionResponseResponse = {
1141
1141
  appUserResponse: Record<string, unknown>;
1142
1142
  }
1143
1143
  ```
1144
+
1145
+ ## Synthesis Views
1146
+
1147
+ A **synthesis view** is a UI that BitBit Press generates on the server for a
1148
+ named placement in your app (a feed card, a detail panel, a settings
1149
+ screen, etc.). You set up the view once in the BitBit CMS — choose a key
1150
+ name, write a prompt, point it at a synthesis config. Then in your app you
1151
+ mount it like this:
1152
+
1153
+ ```tsx
1154
+ <BitBitView client={client} keyName="story-card" />
1155
+ ```
1156
+
1157
+ The SDK fetches the generated UI, renders it using a small library of
1158
+ built-in primitives (`Row`, `Column`, `Text`, `Image`, `Button`, etc.), and
1159
+ splices in any of your own React components you've registered. As the user
1160
+ interacts with the UI, the SDK either routes the event to you (so your app
1161
+ handles navigation, mutations, etc.) or sends it back to the server so the
1162
+ agent can generate the next UI.
1163
+
1164
+ The same surface is exported from both `@bitbitpress/client/react` and
1165
+ `@bitbitpress/client/react-native-expo`. This section uses the web names;
1166
+ the Expo entry is identical.
1167
+
1168
+ ### Quick start
1169
+
1170
+ ```tsx
1171
+ import { BitBitView } from '@bitbitpress/client/react';
1172
+ import client from '@/lib/bitbit-client';
1173
+ import { MyCard } from '@/components/my-card';
1174
+
1175
+ export function Feed({ keyName }: { keyName: string }) {
1176
+ return (
1177
+ <BitBitView
1178
+ client={client}
1179
+ keyName={keyName}
1180
+ components={{ MyCard }}
1181
+ onEvent={(event) => console.log('host event', event)}
1182
+ />
1183
+ );
1184
+ }
1185
+ ```
1186
+
1187
+ That's enough to render any view whose generated UI uses only the SDK's
1188
+ built-in primitives, plus your `MyCard`.
1189
+
1190
+ ### Registering your own components
1191
+
1192
+ In the CMS you can register a component as **"provided by your app"** —
1193
+ the server then refers to it by a name like `MyCard` in the generated UI,
1194
+ and the SDK looks it up in your registry to render it. The mapping from
1195
+ name to React component is what you pass in `components`:
1196
+
1197
+ ```tsx
1198
+ <BitBitView
1199
+ client={client}
1200
+ keyName="story-card"
1201
+ components={{ MyCard, MyButton, MyAvatar }}
1202
+ />
1203
+ ```
1204
+
1205
+ If you'll use the same component map across many views, register them
1206
+ once at the top of your app with `BitBitProvider` instead. Per-view
1207
+ `components` overrides still apply:
1208
+
1209
+ ```tsx
1210
+ import { BitBitProvider } from '@bitbitpress/client/react';
1211
+
1212
+ <BitBitProvider components={{ MyCard, MyButton, MyAvatar }}>
1213
+ <App />
1214
+ </BitBitProvider>
1215
+ ```
1216
+
1217
+ Components receive their bound props from the CMS contract you set up,
1218
+ plus a `children` prop when the view nested other components inside
1219
+ them. See [Handling events](#handling-events) below for how to also
1220
+ accept event callbacks.
1221
+
1222
+ ### Rendering pre-fetched UI
1223
+
1224
+ If you already have the generated UI as a `uiData` array (for example,
1225
+ you cached the most recent response, or you're rendering a gallery of
1226
+ tiles fetched in one shot), use `BitBitViewRenderer` to skip the fetch:
1227
+
1228
+ ```tsx
1229
+ import { BitBitViewRenderer, type FlatUiNode } from '@bitbitpress/client/react';
1230
+
1231
+ export function StaticTile({ uiData }: { uiData: FlatUiNode[] }) {
1232
+ return <BitBitViewRenderer uiData={uiData} components={{ MyCard }} />;
1233
+ }
1234
+ ```
1235
+
1236
+ ### Handling events
1237
+
1238
+ Each event the view emits has a `handleWith` setting (chosen in the CMS):
1239
+
1240
+ - **`HOST`** — the SDK forwards the event to your `onEvent` callback and
1241
+ does nothing else. Use this for navigation, mutations, anything where
1242
+ your app owns the consequence.
1243
+ - **`AGENT`** — the SDK sends the event back to the synthesis endpoint
1244
+ with the prior UI as context, the agent returns a new UI, and the SDK
1245
+ re-renders with it. Your `onEvent` is **not** called for AGENT events
1246
+ (the handling is internal); they show up in the dev log if you need to
1247
+ observe them. Nodes whose ids appear in both the old and new tree
1248
+ preserve their React state, so a well-behaved view feels like a
1249
+ partial update rather than a full reload.
1250
+
1251
+ ```tsx
1252
+ <BitBitView
1253
+ client={client}
1254
+ keyName="story-card"
1255
+ onEvent={(event) => {
1256
+ if (event.name === 'open-detail') {
1257
+ navigation.push('Detail', { id: event.payload.id });
1258
+ }
1259
+ }}
1260
+ />
1261
+ ```
1262
+
1263
+ The event object you receive is:
1264
+
1265
+ ```ts
1266
+ {
1267
+ name: string; // identifier from the CMS event binding
1268
+ componentName: string; // name of the component that fired
1269
+ slot: string; // which slot on the component (e.g. 'onClick')
1270
+ payload: object; // anything the binding declared + anything the host passed
1271
+ }
1272
+ ```
1273
+
1274
+ The runtime also includes a `nodeId` (the internal id of the rendered
1275
+ instance) and `handleWith` (always `'HOST'` by the time your callback
1276
+ runs). Both are present for debugging and rarely need to be consumed.
1277
+
1278
+ #### Events on your components
1279
+
1280
+ If you registered a component with events in its CMS contract (e.g. an
1281
+ `onClick` slot), the SDK passes a callback for that slot as a prop. Call
1282
+ it from inside your component to fire the event through the BB pipeline,
1283
+ exactly as if it had come from a built-in primitive:
1284
+
1285
+ ```tsx
1286
+ function MyCard({
1287
+ title,
1288
+ onClick,
1289
+ }: {
1290
+ title: string;
1291
+ onClick?: (payload?: unknown) => void;
1292
+ }) {
1293
+ return <Pressable onPress={() => onClick?.()}>{title}</Pressable>;
1294
+ }
1295
+ ```
1296
+
1297
+ Anything you pass (a plain object) is merged with the payload the CMS
1298
+ binding declared before the event fires.
1299
+
1300
+ ### When a component name isn't registered
1301
+
1302
+ If the generated UI references a component name you haven't registered,
1303
+ the SDK falls back to a placeholder. The default behavior depends on
1304
+ your environment:
1305
+
1306
+ - **Development** (`process.env.NODE_ENV !== 'production'`) — renders a
1307
+ labeled marker (`⚠ Unknown component: X`) so you can see what's
1308
+ missing.
1309
+ - **Production** — renders nothing. Avoids visible debug artifacts in
1310
+ real user UIs as you grow the registry over time.
1311
+
1312
+ Override with `renderUnknown`, or set `dev` to force development behavior
1313
+ in environments where `NODE_ENV` doesn't reflect what you want (for
1314
+ example, a CMS preview tool that ships as a production build but should
1315
+ still surface missing components):
1316
+
1317
+ ```tsx
1318
+ <BitBitView client={client} keyName={keyName} dev /> // always show warnings
1319
+ <BitBitView
1320
+ client={client}
1321
+ keyName={keyName}
1322
+ renderUnknown={(name) => <YourPlaceholder name={name} />}
1323
+ />
1324
+ ```
1325
+
1326
+ ### Performance: speculative preloading
1327
+
1328
+ The SDK can prefetch the next UI for AGENT events whose payload it can
1329
+ predict ahead of time, so the user's click lands on a cached response
1330
+ with no server roundtrip. This is on by default. To disable:
1331
+
1332
+ ```tsx
1333
+ <BitBitView client={client} keyName={keyName} preloadNextUi={false} />
1334
+ ```
1335
+
1336
+ ### Dev diagnostics
1337
+
1338
+ In dev mode (or when you pass `dev={true}`), the SDK prints every event
1339
+ to the console, prefixed with `[BB]`:
1340
+
1341
+ ```
1342
+ [BB] event MyCard.onClick → AGENT { name: 'open-detail', payload: { id: '…' }, ... }
1343
+ ```
1344
+
1345
+ These logs are completely stripped in production builds — no SDK chatter
1346
+ in real user devices.
1347
+
1348
+ ### Custom rendering (advanced)
1349
+
1350
+ If you want to render the UI tree yourself but still use the SDK's fetch +
1351
+ AGENT continuation + preload cache, use the hook directly:
1352
+
1353
+ ```tsx
1354
+ import { useEventDrivenView } from '@bitbitpress/client/react';
1355
+
1356
+ const { uiData, loading, error, handleEvent } = useEventDrivenView(
1357
+ client,
1358
+ keyName,
1359
+ onHostEvent,
1360
+ contentInputs,
1361
+ viewInputs,
1362
+ );
1363
+ ```
1364
+
1365
+ `uiData` is the same array `BitBitViewRenderer` consumes; wire
1366
+ `handleEvent` as your custom renderer's event callback to keep AGENT
1367
+ events flowing through the SDK.
@@ -0,0 +1,60 @@
1
+ import { type RenderUnknown, type SynthesisViewTreeProps } from '../synthesisView/engine.js';
2
+ import type { ComponentMap, ContentInput, SynthesisViewEvent, SynthesizeViewFetcher } from '../synthesisView/types.js';
3
+ export { type BitBitContextValue, BitBitProvider } from '../synthesisView/context.js';
4
+ export { createComponentMap, type GlobModules, type RequireContext, } from '../synthesisView/createComponentMap.js';
5
+ export type { ComponentMap, ContentInput, FlatUiKeyNameNode, FlatUiNode, FlatUiPrimitiveNode, SynthesisViewEvent, SynthesisViewEventInput, SynthesizeViewFetcher, ViewEventHandleWith, ViewInputs, } from '../synthesisView/types.js';
6
+ export { type UseEventDrivenViewOptions, type UseEventDrivenViewResult, useEventDrivenView, } from '../synthesisView/useEventDrivenView.js';
7
+ export { bitBitBuiltins } from './primitives.js';
8
+ export type BitBitViewRendererProps = Omit<SynthesisViewTreeProps, 'renderUnknown' | 'defaultComponents'> & {
9
+ /** Override how unregistered components render. Defaults to a dev-only
10
+ * marker (see {@link isDevEnvironment}). */
11
+ renderUnknown?: RenderUnknown;
12
+ /** Force the in-dev warning behavior regardless of `process.env.NODE_ENV`.
13
+ * Set true in CMS / preview hosts (e.g. BitBitPress's own admin UI) so
14
+ * unknown components stay visible even when those hosts are built in
15
+ * production mode. Defaults to env-derived. */
16
+ dev?: boolean;
17
+ };
18
+ /** Web renderer for a pre-fetched `uiData` array. BB built-in primitives are
19
+ * registered automatically; pass `components` to add or override entries by
20
+ * name. Use `<BitBitView>` if you want it to fetch for you. */
21
+ export declare function BitBitViewRenderer({ renderUnknown, dev, onEvent, ...rest }: BitBitViewRendererProps): import("react").FunctionComponentElement<SynthesisViewTreeProps>;
22
+ export type BitBitViewProps = {
23
+ /** A BitBitPressClient (or anything with `user.synthesizeViewItem`). */
24
+ client: SynthesizeViewFetcher;
25
+ keyName: string;
26
+ contentInputs?: ContentInput[];
27
+ components?: ComponentMap;
28
+ /** Fires for `HOST` events the component contract declared. `AGENT`
29
+ * events are handled internally — the SDK rounds-trips to the synthesis
30
+ * endpoint and swaps the UI in place; customers don't see them unless
31
+ * they explicitly opt in via the contract. */
32
+ onEvent?: (event: SynthesisViewEvent) => void;
33
+ renderUnknown?: RenderUnknown;
34
+ /** Force the in-dev warning behavior regardless of `process.env.NODE_ENV`.
35
+ * See {@link BitBitViewRendererProps.dev}. */
36
+ dev?: boolean;
37
+ /** Force a dark/light mode. Defaults to the browser's
38
+ * `prefers-color-scheme` (live-updates if the user toggles their OS
39
+ * theme). */
40
+ darkMode?: boolean;
41
+ /** When true (default), speculatively prefetches the agent's next-UI for
42
+ * AGENT events whose payloads don't need runtime input. Real clicks land
43
+ * on the cached response with zero server roundtrip. Set false to
44
+ * disable. */
45
+ preloadNextUi?: boolean;
46
+ };
47
+ /**
48
+ * Web view: fetches a synthesis view by `keyName` and renders it in place.
49
+ * AGENT-handled events drive the next UI back through the agent
50
+ * (preloaded when possible). HOST events fire to `onEvent`.
51
+ */
52
+ export declare function BitBitView({ client, keyName, contentInputs, components, onEvent, renderUnknown, dev, darkMode, preloadNextUi, }: BitBitViewProps): import("react").DetailedReactHTMLElement<{
53
+ 'data-bitbit-error': boolean;
54
+ style: {
55
+ color: "#b00020";
56
+ fontFamily: "monospace";
57
+ fontSize: number;
58
+ };
59
+ }, HTMLElement> | import("react").FunctionComponentElement<BitBitViewRendererProps> | null;
60
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,KAAK,aAAa,EAElB,KAAK,sBAAsB,EAC5B,MAAM,4BAA4B,CAAC;AACpC,OAAO,KAAK,EACV,YAAY,EACZ,YAAY,EACZ,kBAAkB,EAClB,qBAAqB,EAEtB,MAAM,2BAA2B,CAAC;AAInC,OAAO,EAAE,KAAK,kBAAkB,EAAE,cAAc,EAAE,MAAM,6BAA6B,CAAC;AACtF,OAAO,EACL,kBAAkB,EAClB,KAAK,WAAW,EAChB,KAAK,cAAc,GACpB,MAAM,wCAAwC,CAAC;AAChD,YAAY,EACV,YAAY,EACZ,YAAY,EACZ,iBAAiB,EACjB,UAAU,EACV,mBAAmB,EACnB,kBAAkB,EAClB,uBAAuB,EACvB,qBAAqB,EACrB,mBAAmB,EACnB,UAAU,GACX,MAAM,2BAA2B,CAAC;AACnC,OAAO,EACL,KAAK,yBAAyB,EAC9B,KAAK,wBAAwB,EAC7B,kBAAkB,GACnB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAsBjD,MAAM,MAAM,uBAAuB,GAAG,IAAI,CACxC,sBAAsB,EACtB,eAAe,GAAG,mBAAmB,CACtC,GAAG;IACF;iDAC6C;IAC7C,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B;;;oDAGgD;IAChD,GAAG,CAAC,EAAE,OAAO,CAAC;CACf,CAAC;AA6BF;;gEAEgE;AAChE,wBAAgB,kBAAkB,CAAC,EACjC,aAAa,EACb,GAAG,EACH,OAAO,EACP,GAAG,IAAI,EACR,EAAE,uBAAuB,oEAQzB;AAED,MAAM,MAAM,eAAe,GAAG;IAC5B,wEAAwE;IACxE,MAAM,EAAE,qBAAqB,CAAC;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,aAAa,CAAC,EAAE,YAAY,EAAE,CAAC;IAC/B,UAAU,CAAC,EAAE,YAAY,CAAC;IAC1B;;;mDAG+C;IAC/C,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,kBAAkB,KAAK,IAAI,CAAC;IAC9C,aAAa,CAAC,EAAE,aAAa,CAAC;IAC9B;mDAC+C;IAC/C,GAAG,CAAC,EAAE,OAAO,CAAC;IACd;;kBAEc;IACd,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB;;;mBAGe;IACf,aAAa,CAAC,EAAE,OAAO,CAAC;CACzB,CAAC;AAEF;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,EACzB,MAAM,EACN,OAAO,EACP,aAAa,EACb,UAAU,EACV,OAAO,EACP,aAAa,EACb,GAAG,EACH,QAAQ,EACR,aAAa,GACd,EAAE,eAAe;;;;;;;2FAgCjB"}
@@ -0,0 +1,85 @@
1
+ import { createElement, useEffect, useState } from 'react';
2
+ import { devLog, isDevEnvironment } from '../synthesisView/devLog.js';
3
+ import { SynthesisViewTree, } from '../synthesisView/engine.js';
4
+ import { useEventDrivenView } from '../synthesisView/useEventDrivenView.js';
5
+ import { bitBitBuiltins } from './primitives.js';
6
+ export { BitBitProvider } from '../synthesisView/context.js';
7
+ export { createComponentMap, } from '../synthesisView/createComponentMap.js';
8
+ export { useEventDrivenView, } from '../synthesisView/useEventDrivenView.js';
9
+ export { bitBitBuiltins } from './primitives.js';
10
+ /** Track the browser's `prefers-color-scheme` and re-render on change. Returns
11
+ * `null` during SSR or when the API isn't available — callers fall back to
12
+ * the server's default. */
13
+ function useSystemDarkMode() {
14
+ const [isDark, setIsDark] = useState(() => {
15
+ if (typeof window === 'undefined' || !window.matchMedia)
16
+ return null;
17
+ return window.matchMedia('(prefers-color-scheme: dark)').matches;
18
+ });
19
+ useEffect(() => {
20
+ if (typeof window === 'undefined' || !window.matchMedia)
21
+ return;
22
+ const mq = window.matchMedia('(prefers-color-scheme: dark)');
23
+ const onChange = (e) => setIsDark(e.matches);
24
+ mq.addEventListener('change', onChange);
25
+ return () => mq.removeEventListener('change', onChange);
26
+ }, []);
27
+ return isDark;
28
+ }
29
+ const renderUnknownWarning = (name) => createElement('span', {
30
+ 'data-bitbit-unknown': name,
31
+ style: { color: '#b00020', fontFamily: 'monospace', fontSize: 12 },
32
+ }, `⚠ Unknown component: ${name}`);
33
+ /** Silent in production: an unknown name renders nothing rather than splashing
34
+ * a debug marker in the customer's real app. */
35
+ const renderUnknownSilent = () => null;
36
+ /** Wrap `onEvent` so each emission prints to the console with the dispatch
37
+ * routing inline. Routed through {@link devLog} so the message is auto-
38
+ * prefixed with `[BB]` and stripped to a no-op outside dev. */
39
+ function withDevEventLog(dev, onEvent) {
40
+ return (event) => {
41
+ devLog(dev, `event ${event.componentName}.${event.slot} → ${event.handleWith}`, event);
42
+ onEvent?.(event);
43
+ };
44
+ }
45
+ /** Web renderer for a pre-fetched `uiData` array. BB built-in primitives are
46
+ * registered automatically; pass `components` to add or override entries by
47
+ * name. Use `<BitBitView>` if you want it to fetch for you. */
48
+ export function BitBitViewRenderer({ renderUnknown, dev, onEvent, ...rest }) {
49
+ const isDev = dev ?? isDevEnvironment();
50
+ return createElement(SynthesisViewTree, {
51
+ ...rest,
52
+ defaultComponents: bitBitBuiltins,
53
+ renderUnknown: renderUnknown ?? (isDev ? renderUnknownWarning : renderUnknownSilent),
54
+ onEvent: isDev ? withDevEventLog(dev, onEvent) : onEvent,
55
+ });
56
+ }
57
+ /**
58
+ * Web view: fetches a synthesis view by `keyName` and renders it in place.
59
+ * AGENT-handled events drive the next UI back through the agent
60
+ * (preloaded when possible). HOST events fire to `onEvent`.
61
+ */
62
+ export function BitBitView({ client, keyName, contentInputs, components, onEvent, renderUnknown, dev, darkMode, preloadNextUi, }) {
63
+ const systemDark = useSystemDarkMode();
64
+ const resolvedDark = darkMode ?? systemDark ?? undefined;
65
+ const viewInputs = resolvedDark !== undefined ? { darkMode: resolvedDark } : undefined;
66
+ const { uiData, loading, error, handleEvent } = useEventDrivenView(client, keyName, onEvent, contentInputs, viewInputs, { preloadNextUi });
67
+ if (loading)
68
+ return null;
69
+ if (error) {
70
+ return createElement('div', {
71
+ 'data-bitbit-error': true,
72
+ style: { color: '#b00020', fontFamily: 'monospace', fontSize: 12 },
73
+ }, error);
74
+ }
75
+ if (!uiData.length)
76
+ return null;
77
+ return createElement(BitBitViewRenderer, {
78
+ uiData,
79
+ components,
80
+ onEvent: handleEvent,
81
+ renderUnknown,
82
+ dev,
83
+ });
84
+ }
85
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAC3D,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AACtE,OAAO,EAEL,iBAAiB,GAElB,MAAM,4BAA4B,CAAC;AAQpC,OAAO,EAAE,kBAAkB,EAAE,MAAM,wCAAwC,CAAC;AAC5E,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AAEjD,OAAO,EAA2B,cAAc,EAAE,MAAM,6BAA6B,CAAC;AACtF,OAAO,EACL,kBAAkB,GAGnB,MAAM,wCAAwC,CAAC;AAahD,OAAO,EAGL,kBAAkB,GACnB,MAAM,wCAAwC,CAAC;AAChD,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,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O;QAAE,OAAO,IAAI,CAAC;IACzB,IAAI,KAAK,EAAE,CAAC;QACV,OAAO,aAAa,CAClB,KAAK,EACL;YACE,mBAAmB,EAAE,IAAI;YACzB,KAAK,EAAE,EAAE,KAAK,EAAE,SAAS,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,EAAE,EAAE;SACnE,EACD,KAAK,CACN,CAAC;IACJ,CAAC;IACD,IAAI,CAAC,MAAM,CAAC,MAAM;QAAE,OAAO,IAAI,CAAC;IAChC,OAAO,aAAa,CAAC,kBAAkB,EAAE;QACvC,MAAM;QACN,UAAU;QACV,OAAO,EAAE,WAAW;QACpB,aAAa;QACb,GAAG;KACJ,CAAC,CAAC;AACL,CAAC"}
@@ -0,0 +1,54 @@
1
+ import { type CSSProperties } from 'react';
2
+ import type { AudioProps, ButtonProps, CardProps, CheckboxProps, ChoicePickerProps, ColumnProps, DateTimeInputProps, DividerProps, GradientProps, HorizontalScrollProps, IconProps, ImageProps, ListProps, ModalProps, PressableProps, RowProps, SliderProps, TabsItemProps, TabsProps, TextFieldProps, TextProps, VerticalScrollProps, VideoProps } from '../synthesisView/primitives.js';
3
+ import type { ComponentMap } from '../synthesisView/types.js';
4
+ export declare function Text({ text, children, ...rest }: TextProps): import("react/jsx-runtime").JSX.Element;
5
+ export declare function Image({ src, alt, ...rest }: ImageProps): import("react/jsx-runtime").JSX.Element;
6
+ export declare function Button({ title, children, disabled, onPress, ...rest }: ButtonProps): import("react/jsx-runtime").JSX.Element;
7
+ export declare function Pressable({ children, disabled, onPress, style, ...rest }: PressableProps & {
8
+ style?: CSSProperties;
9
+ }): import("react/jsx-runtime").JSX.Element;
10
+ export declare function Icon({ name, ...rest }: IconProps): import("react/jsx-runtime").JSX.Element;
11
+ export declare function Video({ src, poster, ...rest }: VideoProps): import("react/jsx-runtime").JSX.Element;
12
+ export declare function Audio({ src, ...rest }: AudioProps): import("react/jsx-runtime").JSX.Element;
13
+ export declare function Column({ children, style, ...rest }: ColumnProps & {
14
+ style?: CSSProperties;
15
+ }): import("react/jsx-runtime").JSX.Element;
16
+ export declare function Row({ children, style, ...rest }: RowProps & {
17
+ style?: CSSProperties;
18
+ }): import("react/jsx-runtime").JSX.Element;
19
+ export declare function List({ children, style, ...rest }: ListProps & {
20
+ style?: CSSProperties;
21
+ }): import("react/jsx-runtime").JSX.Element;
22
+ export declare function Card({ children, style, ...rest }: CardProps & {
23
+ style?: CSSProperties;
24
+ }): import("react/jsx-runtime").JSX.Element;
25
+ export declare function Divider({ style, ...rest }: DividerProps & {
26
+ style?: CSSProperties;
27
+ }): import("react/jsx-runtime").JSX.Element;
28
+ export declare function VerticalScroll({ children, style, ...rest }: VerticalScrollProps & {
29
+ style?: CSSProperties;
30
+ }): import("react/jsx-runtime").JSX.Element;
31
+ export declare function HorizontalScroll({ children, style, ...rest }: HorizontalScrollProps & {
32
+ style?: CSSProperties;
33
+ }): import("react/jsx-runtime").JSX.Element;
34
+ export declare function Gradient({ colors, start, end, locations, children, style, ...rest }: GradientProps & {
35
+ style?: CSSProperties;
36
+ }): import("react/jsx-runtime").JSX.Element;
37
+ export declare function Tabs({ defaultValue, children, ...rest }: TabsProps): import("react/jsx-runtime").JSX.Element;
38
+ export declare function TabsItem({ children }: TabsItemProps): import("react/jsx-runtime").JSX.Element;
39
+ export declare function Modal({ open, children, onClose, style, ...rest }: ModalProps & {
40
+ style?: CSSProperties;
41
+ }): import("react/jsx-runtime").JSX.Element | null;
42
+ export declare function TextField({ defaultValue, placeholder, multiline, disabled, onChange, ...rest }: TextFieldProps): import("react/jsx-runtime").JSX.Element;
43
+ export declare function Checkbox({ label, defaultChecked, disabled, onChange, ...rest }: CheckboxProps): import("react/jsx-runtime").JSX.Element;
44
+ export declare function ChoicePicker({ defaultValue, options, disabled, onChange, ...rest }: ChoicePickerProps): import("react/jsx-runtime").JSX.Element;
45
+ export declare function Slider({ defaultValue, min, max, step, disabled, onChange, ...rest }: SliderProps): import("react/jsx-runtime").JSX.Element;
46
+ export declare function DateTimeInput({ defaultValue, mode, disabled, onChange, ...rest }: DateTimeInputProps): import("react/jsx-runtime").JSX.Element;
47
+ /**
48
+ * Default component map: every primitive name → its web implementation. Used
49
+ * as the fallback registry by `<BitBitView>` so a customer renders a view
50
+ * with zero registration. Spread it into a custom map to add or override:
51
+ * `<BitBitProvider components={{ ...bitBitBuiltins, MyCard }}>`.
52
+ */
53
+ export declare const bitBitBuiltins: ComponentMap;
54
+ //# sourceMappingURL=primitives.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"primitives.d.ts","sourceRoot":"","sources":["../../src/react/primitives.tsx"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,aAAa,EAKnB,MAAM,OAAO,CAAC;AACf,OAAO,KAAK,EACV,UAAU,EACV,WAAW,EACX,SAAS,EACT,aAAa,EACb,iBAAiB,EACjB,WAAW,EACX,kBAAkB,EAClB,YAAY,EAEZ,aAAa,EACb,qBAAqB,EACrB,SAAS,EACT,UAAU,EACV,SAAS,EACT,UAAU,EACV,cAAc,EACd,QAAQ,EACR,WAAW,EACX,aAAa,EACb,SAAS,EACT,cAAc,EACd,SAAS,EACT,mBAAmB,EACnB,UAAU,EACX,MAAM,gCAAgC,CAAC;AACxC,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAkB9D,wBAAgB,IAAI,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,GAAG,IAAI,EAAE,EAAE,SAAS,2CAE1D;AAID,wBAAgB,KAAK,CAAC,EAAE,GAAG,EAAE,GAAQ,EAAE,GAAG,IAAI,EAAE,EAAE,UAAU,2CAE3D;AAID,wBAAgB,MAAM,CAAC,EAAE,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,GAAG,IAAI,EAAE,EAAE,WAAW,2CAMlF;AAID,wBAAgB,SAAS,CAAC,EACxB,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,KAAK,EACL,GAAG,IAAI,EACR,EAAE,cAAc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