@cognitap/radiant 0.0.90 → 0.0.92
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.
- package/CHANGELOG.md +18 -0
- package/dist/library/a2ui/A2uiPlaceholder.d.ts +14 -0
- package/dist/library/a2ui/A2uiPlaceholder.d.ts.map +1 -0
- package/dist/library/a2ui/A2uiPlaceholder.js +44 -0
- package/dist/library/a2ui/A2uiPlaceholder.js.map +1 -0
- package/dist/library/a2ui/A2uiSurface.d.ts +33 -0
- package/dist/library/a2ui/A2uiSurface.d.ts.map +1 -0
- package/dist/library/a2ui/A2uiSurface.js +542 -0
- package/dist/library/a2ui/A2uiSurface.js.map +1 -0
- package/dist/library/a2ui/accessibility.d.ts +31 -0
- package/dist/library/a2ui/accessibility.d.ts.map +1 -0
- package/dist/library/a2ui/accessibility.js +108 -0
- package/dist/library/a2ui/accessibility.js.map +1 -0
- package/dist/library/a2ui/accessibilityRules.d.ts +28 -0
- package/dist/library/a2ui/accessibilityRules.d.ts.map +1 -0
- package/dist/library/a2ui/accessibilityRules.js +73 -0
- package/dist/library/a2ui/accessibilityRules.js.map +1 -0
- package/dist/library/a2ui/catalogGenerator.d.ts +29 -0
- package/dist/library/a2ui/catalogGenerator.d.ts.map +1 -0
- package/dist/library/a2ui/catalogGenerator.js +578 -0
- package/dist/library/a2ui/catalogGenerator.js.map +1 -0
- package/dist/library/a2ui/coerce.d.ts +16 -0
- package/dist/library/a2ui/coerce.d.ts.map +1 -0
- package/dist/library/a2ui/coerce.js +254 -0
- package/dist/library/a2ui/coerce.js.map +1 -0
- package/dist/library/a2ui/entries.d.ts +6 -0
- package/dist/library/a2ui/entries.d.ts.map +1 -0
- package/dist/library/a2ui/entries.js +277 -0
- package/dist/library/a2ui/entries.js.map +1 -0
- package/dist/library/a2ui/fixtures.d.ts +38 -0
- package/dist/library/a2ui/fixtures.d.ts.map +1 -0
- package/dist/library/a2ui/fixtures.js +389 -0
- package/dist/library/a2ui/fixtures.js.map +1 -0
- package/dist/library/a2ui/index.d.ts +17 -0
- package/dist/library/a2ui/index.d.ts.map +1 -0
- package/dist/library/a2ui/index.js +9 -0
- package/dist/library/a2ui/index.js.map +1 -0
- package/dist/library/a2ui/protocolErrors.d.ts +13 -0
- package/dist/library/a2ui/protocolErrors.d.ts.map +1 -0
- package/dist/library/a2ui/protocolErrors.js +48 -0
- package/dist/library/a2ui/protocolErrors.js.map +1 -0
- package/dist/library/a2ui/registry.d.ts +58 -0
- package/dist/library/a2ui/registry.d.ts.map +1 -0
- package/dist/library/a2ui/registry.js +128 -0
- package/dist/library/a2ui/registry.js.map +1 -0
- package/dist/library/a2ui/sanitize.d.ts +7 -0
- package/dist/library/a2ui/sanitize.d.ts.map +1 -0
- package/dist/library/a2ui/sanitize.js +54 -0
- package/dist/library/a2ui/sanitize.js.map +1 -0
- package/dist/library/a2ui/surfaceRuntime.d.ts +34 -0
- package/dist/library/a2ui/surfaceRuntime.d.ts.map +1 -0
- package/dist/library/a2ui/surfaceRuntime.js +284 -0
- package/dist/library/a2ui/surfaceRuntime.js.map +1 -0
- package/dist/library/catalog/actions.d.ts +40 -0
- package/dist/library/catalog/actions.d.ts.map +1 -0
- package/dist/library/catalog/actions.js +70 -0
- package/dist/library/catalog/actions.js.map +1 -0
- package/dist/library/catalog/coerce.d.ts +70 -0
- package/dist/library/catalog/coerce.d.ts.map +1 -0
- package/dist/library/catalog/coerce.js +332 -0
- package/dist/library/catalog/coerce.js.map +1 -0
- package/dist/library/catalog/index.d.ts +9 -0
- package/dist/library/catalog/index.d.ts.map +1 -0
- package/dist/library/catalog/index.js +6 -0
- package/dist/library/catalog/index.js.map +1 -0
- package/dist/library/catalog/radiantCatalog.d.ts +9 -0
- package/dist/library/catalog/radiantCatalog.d.ts.map +1 -0
- package/dist/library/catalog/radiantCatalog.js +902 -0
- package/dist/library/catalog/radiantCatalog.js.map +1 -0
- package/dist/library/catalog/types.d.ts +113 -0
- package/dist/library/catalog/types.d.ts.map +1 -0
- package/dist/library/catalog/types.js +27 -0
- package/dist/library/catalog/types.js.map +1 -0
- package/dist/library/catalog/validate.d.ts +31 -0
- package/dist/library/catalog/validate.d.ts.map +1 -0
- package/dist/library/catalog/validate.js +420 -0
- package/dist/library/catalog/validate.js.map +1 -0
- package/dist/library/components/Card/Card.d.ts +6 -2
- package/dist/library/components/Card/Card.d.ts.map +1 -1
- package/dist/library/components/Card/Card.js +12 -4
- package/dist/library/components/Card/Card.js.map +1 -1
- package/dist/library/components/Checkbox/Checkbox.d.ts.map +1 -1
- package/dist/library/components/Checkbox/Checkbox.js +2 -2
- package/dist/library/components/Checkbox/Checkbox.js.map +1 -1
- package/dist/library/components/Collapsible/Collapsible.js +1 -1
- package/dist/library/components/Collapsible/Collapsible.js.map +1 -1
- package/dist/library/components/InputGroup/InputGroup.js +1 -1
- package/dist/library/components/InputGroup/InputGroup.js.map +1 -1
- package/dist/library/components/NavLink/NavLink.d.ts.map +1 -1
- package/dist/library/components/NavLink/NavLink.js +1 -1
- package/dist/library/components/NavLink/NavLink.js.map +1 -1
- package/dist/library/components/RadioGroup/RadioGroup.d.ts.map +1 -1
- package/dist/library/components/RadioGroup/RadioGroup.js +3 -3
- package/dist/library/components/RadioGroup/RadioGroup.js.map +1 -1
- package/dist/library/components/ScrollArea/ScrollArea.d.ts.map +1 -1
- package/dist/library/components/ScrollArea/ScrollArea.js +4 -1
- package/dist/library/components/ScrollArea/ScrollArea.js.map +1 -1
- package/dist/library/components/Switch/Switch.d.ts.map +1 -1
- package/dist/library/components/Switch/Switch.js +2 -2
- package/dist/library/components/Switch/Switch.js.map +1 -1
- package/dist/library/components/Table/Table.d.ts +6 -2
- package/dist/library/components/Table/Table.d.ts.map +1 -1
- package/dist/library/components/Table/Table.js +10 -4
- package/dist/library/components/Table/Table.js.map +1 -1
- package/dist/library/components/TagsInput/TagsInput.d.ts.map +1 -1
- package/dist/library/components/TagsInput/TagsInput.js +1 -1
- package/dist/library/components/TagsInput/TagsInput.js.map +1 -1
- package/dist/library/components/TimeInput/TimeInput.d.ts.map +1 -1
- package/dist/library/components/TimeInput/TimeInput.js +28 -20
- package/dist/library/components/TimeInput/TimeInput.js.map +1 -1
- package/dist/library/components/Toast/Toast.js +1 -1
- package/dist/library/components/Toast/Toast.js.map +1 -1
- package/dist/library/components/ToggleGroup/ToggleGroup.js +1 -1
- package/dist/library/components/ToggleGroup/ToggleGroup.js.map +1 -1
- package/dist/library/index.d.ts +1 -1
- package/dist/library/index.d.ts.map +1 -1
- package/dist/library/presentation.d.ts +3 -0
- package/dist/library/presentation.d.ts.map +1 -1
- package/dist/library/styles.css +1 -1
- package/dist/library/themes/components.d.ts +6 -0
- package/dist/library/themes/components.d.ts.map +1 -1
- package/dist/library/themes/components.js +6 -0
- package/dist/library/themes/components.js.map +1 -1
- package/dist/library/themes/tokens.d.ts +4 -0
- package/dist/library/themes/tokens.d.ts.map +1 -1
- package/dist/library/themes/tokens.js +3 -0
- package/dist/library/themes/tokens.js.map +1 -1
- package/docs/accessibility.md +6 -0
- package/docs/architecture.md +20 -1
- package/docs/theming.md +13 -0
- package/package.json +17 -5
- package/src/a2ui/A2uiPlaceholder.tsx +64 -0
- package/src/a2ui/A2uiSurface.tsx +790 -0
- package/src/a2ui/accessibility.ts +145 -0
- package/src/a2ui/accessibilityRules.ts +106 -0
- package/src/a2ui/catalog.json +317 -0
- package/src/a2ui/catalogGenerator.ts +717 -0
- package/src/a2ui/coerce.ts +379 -0
- package/src/a2ui/entries.tsx +519 -0
- package/src/a2ui/fixtures.ts +402 -0
- package/src/a2ui/index.ts +50 -0
- package/src/a2ui/protocolErrors.ts +63 -0
- package/src/a2ui/registry.ts +221 -0
- package/src/a2ui/sanitize.ts +51 -0
- package/src/a2ui/surfaceRuntime.ts +317 -0
- package/src/catalog/actions.ts +108 -0
- package/src/catalog/coerce.ts +447 -0
- package/src/catalog/index.ts +67 -0
- package/src/catalog/radiantCatalog.ts +949 -0
- package/src/catalog/types.ts +159 -0
- package/src/catalog/validate.ts +454 -0
- package/src/components/Card/Card.tsx +35 -19
- package/src/components/Checkbox/Checkbox.tsx +2 -0
- package/src/components/Collapsible/Collapsible.tsx +1 -1
- package/src/components/InputGroup/InputGroup.tsx +2 -2
- package/src/components/NavLink/NavLink.tsx +1 -6
- package/src/components/RadioGroup/RadioGroup.tsx +3 -0
- package/src/components/ScrollArea/ScrollArea.tsx +5 -1
- package/src/components/Switch/Switch.tsx +2 -0
- package/src/components/Table/Table.tsx +16 -3
- package/src/components/TagsInput/TagsInput.tsx +1 -0
- package/src/components/TimeInput/TimeInput.tsx +100 -75
- package/src/components/Toast/Toast.tsx +1 -1
- package/src/components/ToggleGroup/ToggleGroup.tsx +1 -1
- package/src/index.ts +1 -1
- package/src/presentation.ts +3 -0
- package/src/themes/baseline.css +3 -0
- package/src/themes/components.ts +6 -0
- package/src/themes/tokens.ts +7 -0
package/CHANGELOG.md
CHANGED
|
@@ -4,6 +4,24 @@
|
|
|
4
4
|
|
|
5
5
|
## Unreleased
|
|
6
6
|
|
|
7
|
+
## 0.0.92
|
|
8
|
+
|
|
9
|
+
- Add `@cognitap/radiant/catalog` defining Radiant's canonical, protocol-independent model-facing catalog with schema validation, forbidden-prop guardrails, and `extendCatalog`.
|
|
10
|
+
- Add `@cognitap/radiant/a2ui` with `A2uiSurface`, the A2UI 1.0 component registry, and generated `catalog.json` for rendering A2UI surfaces with Radiant components.
|
|
11
|
+
- Coerce invalid, missing, forbidden, and mixed controlled/uncontrolled props at the A2UI boundary, isolate failing nodes inside per-node text-fallback error boundaries, and report structured diagnostics via `onDiagnostic` and `summarizeCatalogDiagnostics`.
|
|
12
|
+
- Add the protocol-independent `CatalogActionEvent` contract (`{ action, surfaceId, nodeId, state }`) in `@cognitap/radiant/catalog`, bind `CheckBox`, `ChoicePicker`, and `Slider` to client-local surface state in `@cognitap/radiant/a2ui`, and deliver immutable state snapshots on named outbound actions.
|
|
13
|
+
- Add the themeable `tight | normal | airy` spacing scale (`--rad-spacing-tight`, `-normal`, `-airy`), `Card` `padding` and `Table` `density` steps with per-step component overrides, and the `Spacing` type.
|
|
14
|
+
- Stream A2UI surfaces progressively: components arrive in any order as `aria-hidden` Skeleton placeholders under an `aria-busy` surface, updates before `createSurface` are buffered, and unknown components and catalog or protocol errors reach `onDiagnostic` as `kind: 'error'` diagnostics with a `code` (counted in `summarizeCatalogDiagnostics().errors`).
|
|
15
|
+
- Merge incremental A2UI surface patches by stable node ID against detached wire history to preserve local state, focus, scroll position, and drags, animate newly added rendered instances once, and restore lost focus in active documents.
|
|
16
|
+
- Add `validateA2uiAccessibility` to `@cognitap/radiant/a2ui`, a pure check of A2UI surfaces against per-entry accessibility rules with optional safe fixes; `A2uiSurface` warns in development, and every registry entry must declare `accessibility` rules.
|
|
17
|
+
|
|
18
|
+
## 0.0.91
|
|
19
|
+
|
|
20
|
+
- `ToastViewport` anchors to logical inline-end so notifications appear on the left in RTL.
|
|
21
|
+
- `Collapsible`, `Accordion`, `Spoiler`, and `NavLinkGroup` mirror their disclosure chevron in RTL.
|
|
22
|
+
- `TimeInput` keeps numeric clock segments (`hour:minute[:second]`) left-to-right in RTL while keeping `dayPeriod` in the ambient flow.
|
|
23
|
+
- `Switch`, `Checkbox`, `Radio`, and `TagsInput` forward direct `dir` overrides to their root wrappers, and `ScrollArea` and `ToggleGroup` react to dynamic ancestor direction changes.
|
|
24
|
+
|
|
7
25
|
## 0.0.90
|
|
8
26
|
|
|
9
27
|
- InlineEdit supports single-line editing with explicit save, cancel, and validation.
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
/** Counts mounted placeholders so the surface can expose `aria-busy` while it is incomplete. */
|
|
2
|
+
export declare function createPlaceholderTracker(): {
|
|
3
|
+
add(): () => void;
|
|
4
|
+
subscribe(listener: () => void): () => void;
|
|
5
|
+
getSnapshot: () => number;
|
|
6
|
+
};
|
|
7
|
+
export type PlaceholderTracker = ReturnType<typeof createPlaceholderTracker>;
|
|
8
|
+
/** Decorative stand-in for a component that has not streamed in yet. */
|
|
9
|
+
export declare function A2uiPlaceholder({ nodeId, inline, tracker }: {
|
|
10
|
+
readonly nodeId?: string;
|
|
11
|
+
readonly inline: boolean;
|
|
12
|
+
readonly tracker: PlaceholderTracker;
|
|
13
|
+
}): import("react").JSX.Element;
|
|
14
|
+
//# sourceMappingURL=A2uiPlaceholder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"A2uiPlaceholder.d.ts","sourceRoot":"","sources":["../../../src/a2ui/A2uiPlaceholder.tsx"],"names":[],"mappings":"AAMA,gGAAgG;AAChG,wBAAgB,wBAAwB;;wBAehB,MAAM,IAAI;;EAQjC;AAED,MAAM,MAAM,kBAAkB,GAAG,UAAU,CAAC,OAAO,wBAAwB,CAAC,CAAA;AAY5E,wEAAwE;AACxE,wBAAgB,eAAe,CAAC,EAC9B,MAAM,EACN,MAAM,EACN,OAAO,EACR,EAAE;IACD,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,CAAA;IACxB,QAAQ,CAAC,MAAM,EAAE,OAAO,CAAA;IACxB,QAAQ,CAAC,OAAO,EAAE,kBAAkB,CAAA;CACrC,+BAUA"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx } from "react/jsx-runtime";
|
|
3
|
+
import { useLayoutEffect } from 'react';
|
|
4
|
+
import { Skeleton } from '../components/Skeleton/Skeleton.js';
|
|
5
|
+
/** Counts mounted placeholders so the surface can expose `aria-busy` while it is incomplete. */
|
|
6
|
+
export function createPlaceholderTracker() {
|
|
7
|
+
let count = 0;
|
|
8
|
+
const listeners = new Set();
|
|
9
|
+
const notify = () => {
|
|
10
|
+
for (const listener of listeners)
|
|
11
|
+
listener();
|
|
12
|
+
};
|
|
13
|
+
return {
|
|
14
|
+
add() {
|
|
15
|
+
count++;
|
|
16
|
+
notify();
|
|
17
|
+
return () => {
|
|
18
|
+
count--;
|
|
19
|
+
notify();
|
|
20
|
+
};
|
|
21
|
+
},
|
|
22
|
+
subscribe(listener) {
|
|
23
|
+
listeners.add(listener);
|
|
24
|
+
return () => {
|
|
25
|
+
listeners.delete(listener);
|
|
26
|
+
};
|
|
27
|
+
},
|
|
28
|
+
getSnapshot: () => count
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
// One body line, so a streamed Text or inline label replaces it without reflow.
|
|
32
|
+
const BLOCK_STYLE = {
|
|
33
|
+
'--rad-skeleton-height': 'calc(var(--rad-typography-roles-ui-body-size,1rem) * var(--rad-typography-roles-ui-body-line-height,1.5))'
|
|
34
|
+
};
|
|
35
|
+
const INLINE_STYLE = {
|
|
36
|
+
'--rad-skeleton-width': '6ch',
|
|
37
|
+
'--rad-skeleton-height': '1lh'
|
|
38
|
+
};
|
|
39
|
+
/** Decorative stand-in for a component that has not streamed in yet. */
|
|
40
|
+
export function A2uiPlaceholder({ nodeId, inline, tracker }) {
|
|
41
|
+
useLayoutEffect(() => tracker.add(), [tracker]);
|
|
42
|
+
return (_jsx(Skeleton, { "data-slot": "a2ui-placeholder", "data-node-id": nodeId, className: inline ? 'inline-block align-middle' : undefined, style: inline ? INLINE_STYLE : BLOCK_STYLE }));
|
|
43
|
+
}
|
|
44
|
+
//# sourceMappingURL=A2uiPlaceholder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"A2uiPlaceholder.js","sourceRoot":"","sources":["../../../src/a2ui/A2uiPlaceholder.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAA;;AAEZ,OAAO,EAAE,eAAe,EAAE,MAAM,OAAO,CAAA;AACvC,OAAO,EAAE,QAAQ,EAAE,MAAM,oCAAoC,CAAA;AAG7D,gGAAgG;AAChG,MAAM,UAAU,wBAAwB;IACtC,IAAI,KAAK,GAAG,CAAC,CAAA;IACb,MAAM,SAAS,GAAG,IAAI,GAAG,EAAc,CAAA;IACvC,MAAM,MAAM,GAAG,GAAG,EAAE;QAClB,KAAK,MAAM,QAAQ,IAAI,SAAS;YAAE,QAAQ,EAAE,CAAA;IAC9C,CAAC,CAAA;IACD,OAAO;QACL,GAAG;YACD,KAAK,EAAE,CAAA;YACP,MAAM,EAAE,CAAA;YACR,OAAO,GAAG,EAAE;gBACV,KAAK,EAAE,CAAA;gBACP,MAAM,EAAE,CAAA;YACV,CAAC,CAAA;QACH,CAAC;QACD,SAAS,CAAC,QAAoB;YAC5B,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,CAAA;YACvB,OAAO,GAAG,EAAE;gBACV,SAAS,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;YAC5B,CAAC,CAAA;QACH,CAAC;QACD,WAAW,EAAE,GAAG,EAAE,CAAC,KAAK;KACzB,CAAA;AACH,CAAC;AAID,gFAAgF;AAChF,MAAM,WAAW,GAAe;IAC9B,uBAAuB,EACrB,2GAA2G;CAC9G,CAAA;AACD,MAAM,YAAY,GAAe;IAC/B,sBAAsB,EAAE,KAAK;IAC7B,uBAAuB,EAAE,KAAK;CAC/B,CAAA;AAED,wEAAwE;AACxE,MAAM,UAAU,eAAe,CAAC,EAC9B,MAAM,EACN,MAAM,EACN,OAAO,EAKR;IACC,eAAe,CAAC,GAAG,EAAE,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,CAAA;IAC/C,OAAO,CACL,KAAC,QAAQ,iBACG,kBAAkB,kBACd,MAAM,EACpB,SAAS,EAAE,MAAM,CAAC,CAAC,CAAC,2BAA2B,CAAC,CAAC,CAAC,SAAS,EAC3D,KAAK,EAAE,MAAM,CAAC,CAAC,CAAC,YAAY,CAAC,CAAC,CAAC,WAAW,GAC1C,CACH,CAAA;AACH,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { ActionPayload } from '@a2ui/web_core/state';
|
|
2
|
+
import { type CatalogActionEvent, type CatalogDiagnostic } from '../catalog/index.js';
|
|
3
|
+
import type { A2uiRegistry } from './registry.js';
|
|
4
|
+
import type { A2uiMessage } from './sanitize.js';
|
|
5
|
+
/**
|
|
6
|
+
* Outbound action payload delivered by `A2uiSurface`.
|
|
7
|
+
* Implements the protocol-independent `CatalogActionEvent` (`{ action, surfaceId, nodeId, state }`)
|
|
8
|
+
* while preserving the underlying A2UI wire fields (`name`, `sourceComponentId`, `context`, `timestamp`).
|
|
9
|
+
*/
|
|
10
|
+
export type A2uiActionPayload = CatalogActionEvent & ActionPayload;
|
|
11
|
+
export type A2uiSurfaceProps = {
|
|
12
|
+
/** Identifier of the A2UI surface to render. */
|
|
13
|
+
readonly surfaceId: string;
|
|
14
|
+
/** A2UI 1.0 protocol messages defining and updating the surface. */
|
|
15
|
+
readonly messages: readonly A2uiMessage[];
|
|
16
|
+
/** Registry mapping A2UI component names to Radiant adapters. Defaults to `radiantA2uiRegistry`. */
|
|
17
|
+
readonly registry?: A2uiRegistry;
|
|
18
|
+
/** Host callback invoked when an outbound A2UI action event fires. */
|
|
19
|
+
readonly onAction?: (action: A2uiActionPayload) => void;
|
|
20
|
+
/**
|
|
21
|
+
* Host callback invoked whenever a prop is coerced, defaulted, stripped, or falls back, and for
|
|
22
|
+
* catalog or protocol errors (`kind: 'error'` with a `code`).
|
|
23
|
+
*/
|
|
24
|
+
readonly onDiagnostic?: (diagnostic: CatalogDiagnostic) => void;
|
|
25
|
+
};
|
|
26
|
+
/**
|
|
27
|
+
* Renders an A2UI 1.0 surface directly onto Radiant components via `@a2ui/web_core`.
|
|
28
|
+
* Merges appended patches incrementally by stable node ID to keep local state, focus,
|
|
29
|
+
* scroll position, and drags intact, animates newly added instances once, and recovers
|
|
30
|
+
* removed-node focus as documented in `docs/architecture.md`.
|
|
31
|
+
*/
|
|
32
|
+
export declare function A2uiSurface({ surfaceId, messages, registry, onAction, onDiagnostic }: A2uiSurfaceProps): import("react").JSX.Element;
|
|
33
|
+
//# sourceMappingURL=A2uiSurface.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"A2uiSurface.d.ts","sourceRoot":"","sources":["../../../src/a2ui/A2uiSurface.tsx"],"names":[],"mappings":"AAwBA,OAAO,KAAK,EAAE,aAAa,EAAgB,MAAM,sBAAsB,CAAA;AACvE,OAAO,EAGL,KAAK,kBAAkB,EACvB,KAAK,iBAAiB,EACvB,MAAM,qBAAqB,CAAA;AAwB5B,OAAO,KAAK,EAAE,YAAY,EAAqB,MAAM,eAAe,CAAA;AACpE,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,eAAe,CAAA;AAahD;;;;GAIG;AACH,MAAM,MAAM,iBAAiB,GAAG,kBAAkB,GAAG,aAAa,CAAA;AAElE,MAAM,MAAM,gBAAgB,GAAG;IAC7B,gDAAgD;IAChD,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAA;IAC1B,oEAAoE;IACpE,QAAQ,CAAC,QAAQ,EAAE,SAAS,WAAW,EAAE,CAAA;IACzC,oGAAoG;IACpG,QAAQ,CAAC,QAAQ,CAAC,EAAE,YAAY,CAAA;IAChC,sEAAsE;IACtE,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,MAAM,EAAE,iBAAiB,KAAK,IAAI,CAAA;IACvD;;;OAGG;IACH,QAAQ,CAAC,YAAY,CAAC,EAAE,CAAC,UAAU,EAAE,iBAAiB,KAAK,IAAI,CAAA;CAChE,CAAA;AAonBD;;;;;GAKG;AACH,wBAAgB,WAAW,CAAC,EAC1B,SAAS,EACT,QAAQ,EACR,QAA8B,EAC9B,QAAQ,EACR,YAAY,EACb,EAAE,gBAAgB,+BA4DlB"}
|
|
@@ -0,0 +1,542 @@
|
|
|
1
|
+
'use client';
|
|
2
|
+
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
3
|
+
import { cloneElement, Component, Fragment, isValidElement, memo, useCallback, useContext, useEffect, useLayoutEffect, useRef, useState, useSyncExternalStore } from 'react';
|
|
4
|
+
import { cn } from 'cn';
|
|
5
|
+
import { MessageProcessor } from '@a2ui/web_core/processing';
|
|
6
|
+
import { effect, getValue, peekValue } from '@a2ui/web_core/reactivity';
|
|
7
|
+
import { NodeResolver } from '@a2ui/web_core/resolution';
|
|
8
|
+
import { createCatalogActionEvent, snapshotSurfaceState } from '../catalog/index.js';
|
|
9
|
+
import { isPlainRecord } from '../catalog/coerce.js';
|
|
10
|
+
import { focusRingClass } from '../components/shared/focusStyles.js';
|
|
11
|
+
import { MotionProfileContext } from '../motion/context.js';
|
|
12
|
+
import { useComposedRefs } from '../react/useComposedRefs.js';
|
|
13
|
+
import { warnA2uiAccessibility } from './accessibility.js';
|
|
14
|
+
import { A2UI_PROTOCOL_VERSION } from './catalogGenerator.js';
|
|
15
|
+
import { COERCED_NOOP_ACTION_NAME, coerceA2uiMessages, extractA2uiNodeFallbackText, getRegistryEntry } from './coerce.js';
|
|
16
|
+
import { A2uiPlaceholder, createPlaceholderTracker } from './A2uiPlaceholder.js';
|
|
17
|
+
import { radiantA2uiRegistry } from './entries.js';
|
|
18
|
+
import { createsSurface, deletesSurface, streamedComponents, protocolErrorDiagnostic, supersededBy, updatesSurface } from './protocolErrors.js';
|
|
19
|
+
import { animateNodeEntry, captureFocusSnapshot, cloneMessageValue, createMicrotaskCoalescer, isHtmlElement, isMessagePrefix, restoreFocusFallback } from './surfaceRuntime.js';
|
|
20
|
+
function isVisibleHost(element) {
|
|
21
|
+
if (!element.isConnected || element.hidden || element.getClientRects().length === 0)
|
|
22
|
+
return false;
|
|
23
|
+
const win = element.ownerDocument.defaultView;
|
|
24
|
+
return !win || win.getComputedStyle(element).visibility !== 'hidden';
|
|
25
|
+
}
|
|
26
|
+
function createSurfaceDomRuntime(initialMotionProfile) {
|
|
27
|
+
const hosts = new Map();
|
|
28
|
+
const mountedInstances = new Map();
|
|
29
|
+
const containers = new Set();
|
|
30
|
+
const committedInstances = new Set();
|
|
31
|
+
const pendingMounts = new Set();
|
|
32
|
+
const unmountedInstances = new Set();
|
|
33
|
+
let surfaceElement = null;
|
|
34
|
+
let motionProfile = initialMotionProfile;
|
|
35
|
+
let pendingFocus = null;
|
|
36
|
+
const placeholders = createPlaceholderTracker();
|
|
37
|
+
// Text nodes whose latest definition has not streamed its text yet; they reserve a line.
|
|
38
|
+
const pendingText = new Set();
|
|
39
|
+
function flushBatch() {
|
|
40
|
+
if (pendingFocus) {
|
|
41
|
+
const snapshot = pendingFocus;
|
|
42
|
+
pendingFocus = null;
|
|
43
|
+
restoreFocusFallback(surfaceElement, snapshot, hosts);
|
|
44
|
+
}
|
|
45
|
+
if (surfaceElement?.isConnected && pendingMounts.size > 0) {
|
|
46
|
+
for (const nodeId of pendingMounts) {
|
|
47
|
+
const host = hosts.get(nodeId);
|
|
48
|
+
if (!host || host.isContainer || !host.element.isConnected)
|
|
49
|
+
continue;
|
|
50
|
+
if (committedInstances.has(host.instanceId) && unmountedInstances.has(host.instanceId)) {
|
|
51
|
+
continue;
|
|
52
|
+
}
|
|
53
|
+
for (const el of host.elements ?? [host.element]) {
|
|
54
|
+
if (el.isConnected)
|
|
55
|
+
animateNodeEntry(el, motionProfile);
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
pendingMounts.clear();
|
|
59
|
+
}
|
|
60
|
+
for (const [nodeId, host] of hosts) {
|
|
61
|
+
if (!mountedInstances.has(nodeId) || !host.element.isConnected)
|
|
62
|
+
hosts.delete(nodeId);
|
|
63
|
+
}
|
|
64
|
+
for (const nodeId of containers) {
|
|
65
|
+
if (!mountedInstances.has(nodeId))
|
|
66
|
+
containers.delete(nodeId);
|
|
67
|
+
}
|
|
68
|
+
unmountedInstances.clear();
|
|
69
|
+
committedInstances.clear();
|
|
70
|
+
for (const instanceId of mountedInstances.values())
|
|
71
|
+
committedInstances.add(instanceId);
|
|
72
|
+
}
|
|
73
|
+
const scheduleBatchFlush = createMicrotaskCoalescer(flushBatch);
|
|
74
|
+
function captureFocus() {
|
|
75
|
+
if (!pendingFocus)
|
|
76
|
+
pendingFocus = captureFocusSnapshot(surfaceElement, hosts);
|
|
77
|
+
if (pendingFocus)
|
|
78
|
+
scheduleBatchFlush();
|
|
79
|
+
}
|
|
80
|
+
return {
|
|
81
|
+
placeholders,
|
|
82
|
+
pendingText,
|
|
83
|
+
setSurfaceElement(element) {
|
|
84
|
+
surfaceElement = element;
|
|
85
|
+
},
|
|
86
|
+
setMotionProfile(nextProfile) {
|
|
87
|
+
motionProfile = nextProfile;
|
|
88
|
+
},
|
|
89
|
+
setNodeHost(nodeId, instanceId, element, isContainer, elements) {
|
|
90
|
+
if (isHtmlElement(element)) {
|
|
91
|
+
hosts.set(nodeId, {
|
|
92
|
+
nodeId,
|
|
93
|
+
instanceId,
|
|
94
|
+
element,
|
|
95
|
+
elements,
|
|
96
|
+
isContainer: isContainer ?? containers.has(nodeId)
|
|
97
|
+
});
|
|
98
|
+
}
|
|
99
|
+
else if (element === null) {
|
|
100
|
+
hosts.delete(nodeId);
|
|
101
|
+
}
|
|
102
|
+
},
|
|
103
|
+
captureFocus,
|
|
104
|
+
onNodeMount(nodeId, instanceId, requestProbe) {
|
|
105
|
+
mountedInstances.set(nodeId, instanceId);
|
|
106
|
+
pendingMounts.add(nodeId);
|
|
107
|
+
const host = hosts.get(nodeId);
|
|
108
|
+
if (!containers.has(nodeId) &&
|
|
109
|
+
(!host || host.instanceId !== instanceId || !host.element.isConnected)) {
|
|
110
|
+
requestProbe();
|
|
111
|
+
}
|
|
112
|
+
scheduleBatchFlush();
|
|
113
|
+
},
|
|
114
|
+
onNodeUnmount(nodeId, instanceId) {
|
|
115
|
+
mountedInstances.delete(nodeId);
|
|
116
|
+
pendingMounts.delete(nodeId);
|
|
117
|
+
unmountedInstances.add(instanceId);
|
|
118
|
+
captureFocus();
|
|
119
|
+
scheduleBatchFlush();
|
|
120
|
+
},
|
|
121
|
+
setNodeContainer(nodeId, isContainer) {
|
|
122
|
+
if (isContainer)
|
|
123
|
+
containers.add(nodeId);
|
|
124
|
+
else
|
|
125
|
+
containers.delete(nodeId);
|
|
126
|
+
const host = hosts.get(nodeId);
|
|
127
|
+
if (host && host.isContainer !== isContainer)
|
|
128
|
+
hosts.set(nodeId, { ...host, isContainer });
|
|
129
|
+
},
|
|
130
|
+
onSurfaceRebuild() {
|
|
131
|
+
committedInstances.clear();
|
|
132
|
+
pendingMounts.clear();
|
|
133
|
+
unmountedInstances.clear();
|
|
134
|
+
}
|
|
135
|
+
};
|
|
136
|
+
}
|
|
137
|
+
function useSignalValue(signal) {
|
|
138
|
+
return useSyncExternalStore(onStoreChange => {
|
|
139
|
+
if (!signal)
|
|
140
|
+
return () => { };
|
|
141
|
+
let initial = true;
|
|
142
|
+
return effect(() => {
|
|
143
|
+
getValue(signal);
|
|
144
|
+
if (initial) {
|
|
145
|
+
initial = false;
|
|
146
|
+
return;
|
|
147
|
+
}
|
|
148
|
+
onStoreChange();
|
|
149
|
+
});
|
|
150
|
+
}, () => (signal ? peekValue(signal) : undefined), () => (signal ? peekValue(signal) : undefined));
|
|
151
|
+
}
|
|
152
|
+
const boundaryFallbackText = (node, token) => extractA2uiNodeFallbackText(node, isPlainRecord(token) ? token : undefined);
|
|
153
|
+
class A2uiNodeErrorBoundary extends Component {
|
|
154
|
+
state = { failed: false, failedToken: undefined };
|
|
155
|
+
static getDerivedStateFromError() {
|
|
156
|
+
return { failed: true };
|
|
157
|
+
}
|
|
158
|
+
static getDerivedStateFromProps(next, prev) {
|
|
159
|
+
if (!prev.failed)
|
|
160
|
+
return null;
|
|
161
|
+
if (prev.failedToken === undefined)
|
|
162
|
+
return { failed: true, failedToken: next.resetToken };
|
|
163
|
+
return next.resetToken !== prev.failedToken ? { failed: false, failedToken: undefined } : null;
|
|
164
|
+
}
|
|
165
|
+
componentDidCatch(error, _info) {
|
|
166
|
+
const { node, resetToken, onDiagnostic } = this.props;
|
|
167
|
+
onDiagnostic({
|
|
168
|
+
kind: 'fallback',
|
|
169
|
+
nodeId: node.componentId,
|
|
170
|
+
component: node.type,
|
|
171
|
+
prop: 'render',
|
|
172
|
+
received: error.message || 'Render error',
|
|
173
|
+
used: boundaryFallbackText(node, resetToken),
|
|
174
|
+
reason: 'Component threw during render.'
|
|
175
|
+
});
|
|
176
|
+
}
|
|
177
|
+
render() {
|
|
178
|
+
if (!this.state.failed)
|
|
179
|
+
return this.props.children;
|
|
180
|
+
const text = boundaryFallbackText(this.props.node, this.props.resetToken);
|
|
181
|
+
return text ? (_jsx("span", { ref: this.props.onFallbackRef, "data-slot": "a2ui-fallback", "data-node-id": this.props.node.componentId, children: text })) : null;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
const A2uiNodeRenderer = memo(function A2uiNodeRenderer({ node, registry, inline, onDiagnostic, runtime }) {
|
|
185
|
+
const props = useSignalValue(node.props);
|
|
186
|
+
const resolved = Boolean(props) && node.state === 'resolved';
|
|
187
|
+
const entry = resolved ? getRegistryEntry(registry, node.type) : undefined;
|
|
188
|
+
const active = Boolean(entry);
|
|
189
|
+
let hasChildNodes = false;
|
|
190
|
+
const adapted = props && entry
|
|
191
|
+
? entry.adapter(props, {
|
|
192
|
+
node,
|
|
193
|
+
inline,
|
|
194
|
+
renderNode(child, options) {
|
|
195
|
+
if (!options?.inline)
|
|
196
|
+
hasChildNodes = true;
|
|
197
|
+
return (_jsx(A2uiNodeRenderer, { node: child, registry: registry, inline: options?.inline ?? false, onDiagnostic: onDiagnostic, runtime: runtime }, child.id));
|
|
198
|
+
}
|
|
199
|
+
})
|
|
200
|
+
: null;
|
|
201
|
+
// Text whose text has not streamed yet stays empty but reserves its line.
|
|
202
|
+
const rendered = runtime.pendingText.has(node.componentId) &&
|
|
203
|
+
isValidElement(adapted) &&
|
|
204
|
+
adapted.type !== Fragment
|
|
205
|
+
? cloneElement(adapted, {
|
|
206
|
+
className: cn(adapted.props.className, inline ? 'inline-block min-h-[1lh]' : 'block min-h-[1lh]')
|
|
207
|
+
})
|
|
208
|
+
: adapted;
|
|
209
|
+
const isContainer = node.type === 'Column' || hasChildNodes;
|
|
210
|
+
const [probing, setProbing] = useState(false);
|
|
211
|
+
const startRef = useRef(null);
|
|
212
|
+
const setHostRef = useCallback((element) => runtime.setNodeHost(node.id, node.instanceId, element), [node.id, node.instanceId, runtime]);
|
|
213
|
+
const hostElement = !inline && isValidElement(rendered) && rendered.type !== Fragment
|
|
214
|
+
? rendered
|
|
215
|
+
: null;
|
|
216
|
+
const composedRef = useComposedRefs(setHostRef, hostElement?.props.ref);
|
|
217
|
+
useLayoutEffect(() => {
|
|
218
|
+
if (active && !inline)
|
|
219
|
+
runtime.setNodeContainer(node.id, isContainer);
|
|
220
|
+
}, [active, inline, isContainer, node.id, props, runtime]);
|
|
221
|
+
useLayoutEffect(() => {
|
|
222
|
+
if (!active || inline)
|
|
223
|
+
return;
|
|
224
|
+
runtime.onNodeMount(node.id, node.instanceId, () => setProbing(true));
|
|
225
|
+
return () => runtime.onNodeUnmount(node.id, node.instanceId);
|
|
226
|
+
}, [active, inline, node.id, node.instanceId, runtime]);
|
|
227
|
+
if (node.state === 'pending') {
|
|
228
|
+
return (_jsx(A2uiPlaceholder, { nodeId: node.componentId, inline: inline, tracker: runtime.placeholders }));
|
|
229
|
+
}
|
|
230
|
+
if (!props || !entry)
|
|
231
|
+
return null;
|
|
232
|
+
return (_jsxs(A2uiNodeErrorBoundary, { node: node, resetToken: props, onDiagnostic: onDiagnostic, onFallbackRef: inline ? undefined : setHostRef, children: [probing ? _jsx("template", { ref: startRef }) : null, hostElement ? cloneElement(hostElement, { ref: composedRef }) : rendered, probing ? (_jsx("template", { ref: end => {
|
|
233
|
+
if (!end)
|
|
234
|
+
return;
|
|
235
|
+
const start = startRef.current;
|
|
236
|
+
if (start && start.parentNode === end.parentNode) {
|
|
237
|
+
const visible = [];
|
|
238
|
+
for (let el = start.nextElementSibling; el && el !== end; el = el.nextElementSibling) {
|
|
239
|
+
if (isHtmlElement(el) && isVisibleHost(el))
|
|
240
|
+
visible.push(el);
|
|
241
|
+
}
|
|
242
|
+
if (visible.length > 0) {
|
|
243
|
+
runtime.setNodeHost(node.id, node.instanceId, visible[0], isContainer, visible.length > 1 ? visible : undefined);
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
setProbing(false);
|
|
247
|
+
} })) : null] }, node.id));
|
|
248
|
+
});
|
|
249
|
+
function createSurfaceStore(initialSurfaceId, initialRegistry, initialMessages, initialOnAction, initialOnDiagnostic, runtime) {
|
|
250
|
+
let surfaceId = initialSurfaceId;
|
|
251
|
+
let registry = initialRegistry;
|
|
252
|
+
let processedMessages = [];
|
|
253
|
+
let reported;
|
|
254
|
+
let actionHandler = initialOnAction;
|
|
255
|
+
let diagnosticHandler = initialOnDiagnostic;
|
|
256
|
+
let disposed = false;
|
|
257
|
+
let processor;
|
|
258
|
+
let resolver;
|
|
259
|
+
let stopRootEffect;
|
|
260
|
+
let stopErrors;
|
|
261
|
+
let resolvedSurface;
|
|
262
|
+
// Errors are queued during sync, dropped on an identical rebuild, and delivered directly otherwise.
|
|
263
|
+
let errorMode = 'direct';
|
|
264
|
+
// `awaiting` until createSurface succeeds; `closed` after deleteSurface or a failed create.
|
|
265
|
+
let phase = 'awaiting';
|
|
266
|
+
// Updates that arrive before their createSurface wait here instead of failing.
|
|
267
|
+
let bufferedUpdates = [];
|
|
268
|
+
// Unknown components report once per node and type for each engine build.
|
|
269
|
+
let reportedUnknown = new Set();
|
|
270
|
+
const pendingDiagnostics = [];
|
|
271
|
+
const listeners = new Set();
|
|
272
|
+
const notify = () => {
|
|
273
|
+
for (const listener of listeners)
|
|
274
|
+
listener();
|
|
275
|
+
};
|
|
276
|
+
function flushDiagnostics() {
|
|
277
|
+
const batch = pendingDiagnostics.splice(0, pendingDiagnostics.length);
|
|
278
|
+
if (diagnosticHandler)
|
|
279
|
+
for (const d of batch)
|
|
280
|
+
diagnosticHandler(d);
|
|
281
|
+
}
|
|
282
|
+
function bindRootSignal() {
|
|
283
|
+
stopRootEffect?.();
|
|
284
|
+
stopRootEffect = undefined;
|
|
285
|
+
if (listeners.size === 0 || !resolver)
|
|
286
|
+
return;
|
|
287
|
+
const rootSignal = resolver.rootNode;
|
|
288
|
+
let initial = true;
|
|
289
|
+
stopRootEffect = effect(() => {
|
|
290
|
+
getValue(rootSignal);
|
|
291
|
+
if (initial) {
|
|
292
|
+
initial = false;
|
|
293
|
+
return;
|
|
294
|
+
}
|
|
295
|
+
notify();
|
|
296
|
+
});
|
|
297
|
+
}
|
|
298
|
+
function teardownEngine() {
|
|
299
|
+
stopRootEffect?.();
|
|
300
|
+
stopRootEffect = undefined;
|
|
301
|
+
stopErrors?.();
|
|
302
|
+
stopErrors = undefined;
|
|
303
|
+
resolver?.dispose();
|
|
304
|
+
resolver = undefined;
|
|
305
|
+
resolvedSurface = undefined;
|
|
306
|
+
processor?.dispose();
|
|
307
|
+
processor = undefined;
|
|
308
|
+
}
|
|
309
|
+
const makeResolver = (s) => s ? new NodeResolver(s) : undefined;
|
|
310
|
+
function withErrors(mode, run) {
|
|
311
|
+
const previous = errorMode;
|
|
312
|
+
errorMode = mode;
|
|
313
|
+
try {
|
|
314
|
+
run();
|
|
315
|
+
}
|
|
316
|
+
finally {
|
|
317
|
+
errorMode = previous;
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
// Rebinds the resolver whenever the surface model is created, deleted, or recreated.
|
|
321
|
+
function refreshResolver(target) {
|
|
322
|
+
const surface = target.getSurface(surfaceId);
|
|
323
|
+
if (resolver && !resolver.disposed && resolvedSurface === surface)
|
|
324
|
+
return;
|
|
325
|
+
resolver?.dispose();
|
|
326
|
+
resolvedSurface = surface;
|
|
327
|
+
resolver = makeResolver(surface);
|
|
328
|
+
bindRootSignal();
|
|
329
|
+
}
|
|
330
|
+
function trackPendingText(coerced, diagnostics) {
|
|
331
|
+
for (const message of coerced) {
|
|
332
|
+
for (const component of streamedComponents(message, surfaceId)) {
|
|
333
|
+
if (component.component === 'Text')
|
|
334
|
+
runtime.pendingText.delete(String(component.id));
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
for (const d of diagnostics) {
|
|
338
|
+
if (d.component === 'Text' && d.prop === 'text' && d.kind === 'defaulted') {
|
|
339
|
+
runtime.pendingText.add(d.nodeId);
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
function dropBuffered(reason) {
|
|
344
|
+
if (bufferedUpdates.length === 0)
|
|
345
|
+
return;
|
|
346
|
+
pendingDiagnostics.push({
|
|
347
|
+
kind: 'error',
|
|
348
|
+
code: 'DROPPED_UPDATES',
|
|
349
|
+
nodeId: '',
|
|
350
|
+
component: 'surface',
|
|
351
|
+
prop: 'message',
|
|
352
|
+
received: bufferedUpdates.length,
|
|
353
|
+
used: undefined,
|
|
354
|
+
reason
|
|
355
|
+
});
|
|
356
|
+
bufferedUpdates = [];
|
|
357
|
+
}
|
|
358
|
+
// Each message is applied on its own so one protocol error cannot drop the rest of a batch.
|
|
359
|
+
function processBatch(target, targetRegistry, batch, record) {
|
|
360
|
+
const detached = batch.map(message => cloneMessageValue(message));
|
|
361
|
+
const { messages: coerced, diagnostics } = coerceA2uiMessages(detached, targetRegistry);
|
|
362
|
+
trackPendingText(coerced, diagnostics);
|
|
363
|
+
if (record) {
|
|
364
|
+
for (const diagnostic of diagnostics) {
|
|
365
|
+
if (diagnostic.code === 'UNKNOWN_COMPONENT_TYPE') {
|
|
366
|
+
const key = `${diagnostic.nodeId}\u0000${String(diagnostic.received)}`;
|
|
367
|
+
if (reportedUnknown.has(key))
|
|
368
|
+
continue;
|
|
369
|
+
reportedUnknown.add(key);
|
|
370
|
+
}
|
|
371
|
+
pendingDiagnostics.push(diagnostic);
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
const apply = (message) => target.processMessages([message]);
|
|
375
|
+
for (const message of coerced) {
|
|
376
|
+
if (phase === 'awaiting' && updatesSurface(message, surfaceId)) {
|
|
377
|
+
bufferedUpdates.push(message);
|
|
378
|
+
continue;
|
|
379
|
+
}
|
|
380
|
+
apply(message);
|
|
381
|
+
if (createsSurface(message, surfaceId)) {
|
|
382
|
+
if (target.getSurface(surfaceId)) {
|
|
383
|
+
phase = 'live';
|
|
384
|
+
const held = bufferedUpdates.filter(update => !supersededBy(message, update));
|
|
385
|
+
bufferedUpdates = [];
|
|
386
|
+
for (const update of held)
|
|
387
|
+
apply(update);
|
|
388
|
+
}
|
|
389
|
+
else if (phase === 'awaiting') {
|
|
390
|
+
phase = 'closed';
|
|
391
|
+
dropBuffered('createSurface failed; buffered updates were dropped.');
|
|
392
|
+
}
|
|
393
|
+
}
|
|
394
|
+
else if (deletesSurface(message, surfaceId) && !target.getSurface(surfaceId)) {
|
|
395
|
+
phase = 'closed';
|
|
396
|
+
}
|
|
397
|
+
refreshResolver(target);
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
function buildEngine(nextSurfaceId, nextRegistry, nextMessages) {
|
|
401
|
+
teardownEngine();
|
|
402
|
+
runtime.onSurfaceRebuild();
|
|
403
|
+
disposed = false;
|
|
404
|
+
surfaceId = nextSurfaceId;
|
|
405
|
+
registry = nextRegistry;
|
|
406
|
+
bufferedUpdates = [];
|
|
407
|
+
reportedUnknown = new Set();
|
|
408
|
+
runtime.pendingText.clear();
|
|
409
|
+
phase = 'awaiting';
|
|
410
|
+
const wireSnapshot = nextMessages.map(message => cloneMessageValue(message));
|
|
411
|
+
processedMessages = wireSnapshot;
|
|
412
|
+
const sameBatch = reported?.[0] === nextSurfaceId &&
|
|
413
|
+
reported[1] === nextRegistry &&
|
|
414
|
+
reported[2].length === wireSnapshot.length &&
|
|
415
|
+
isMessagePrefix(reported[2], wireSnapshot);
|
|
416
|
+
processor = new MessageProcessor([nextRegistry.toWebCoreCatalog()], action => {
|
|
417
|
+
if (action.name === COERCED_NOOP_ACTION_NAME)
|
|
418
|
+
return;
|
|
419
|
+
const state = processor?.getSurface(action.surfaceId)?.dataModel.get('/');
|
|
420
|
+
const catalogEvent = createCatalogActionEvent({
|
|
421
|
+
action: action.name,
|
|
422
|
+
surfaceId: action.surfaceId,
|
|
423
|
+
nodeId: action.sourceComponentId,
|
|
424
|
+
state
|
|
425
|
+
});
|
|
426
|
+
const contextSnapshot = snapshotSurfaceState(action.context);
|
|
427
|
+
const context = (isPlainRecord(contextSnapshot) ? contextSnapshot : Object.freeze({}));
|
|
428
|
+
actionHandler?.(Object.freeze({ ...action, ...catalogEvent, context }));
|
|
429
|
+
}, { version: A2UI_PROTOCOL_VERSION, reportErrorsOnly: true });
|
|
430
|
+
const errorSubscription = processor.model.onError.subscribe(error => {
|
|
431
|
+
if (errorMode === 'suppress' || (error.surfaceId && error.surfaceId !== surfaceId))
|
|
432
|
+
return;
|
|
433
|
+
const diagnostic = protocolErrorDiagnostic(error);
|
|
434
|
+
if (errorMode === 'queue')
|
|
435
|
+
pendingDiagnostics.push(diagnostic);
|
|
436
|
+
else
|
|
437
|
+
diagnosticHandler?.(diagnostic);
|
|
438
|
+
});
|
|
439
|
+
stopErrors = () => errorSubscription.unsubscribe();
|
|
440
|
+
const target = processor;
|
|
441
|
+
withErrors(sameBatch ? 'suppress' : 'queue', () => {
|
|
442
|
+
const before = pendingDiagnostics.length;
|
|
443
|
+
processBatch(target, nextRegistry, wireSnapshot, Boolean(diagnosticHandler) && !sameBatch);
|
|
444
|
+
refreshResolver(target);
|
|
445
|
+
if (sameBatch)
|
|
446
|
+
pendingDiagnostics.length = before;
|
|
447
|
+
});
|
|
448
|
+
reported = [nextSurfaceId, nextRegistry, wireSnapshot];
|
|
449
|
+
}
|
|
450
|
+
buildEngine(initialSurfaceId, initialRegistry, initialMessages);
|
|
451
|
+
return {
|
|
452
|
+
subscribe(listener) {
|
|
453
|
+
listeners.add(listener);
|
|
454
|
+
if (listeners.size === 1)
|
|
455
|
+
bindRootSignal();
|
|
456
|
+
return () => {
|
|
457
|
+
listeners.delete(listener);
|
|
458
|
+
if (listeners.size === 0) {
|
|
459
|
+
stopRootEffect?.();
|
|
460
|
+
stopRootEffect = undefined;
|
|
461
|
+
}
|
|
462
|
+
};
|
|
463
|
+
},
|
|
464
|
+
getSnapshot() {
|
|
465
|
+
return resolver ? peekValue(resolver.rootNode) : undefined;
|
|
466
|
+
},
|
|
467
|
+
getPhase: () => phase,
|
|
468
|
+
reportDiagnostic(diagnostic) {
|
|
469
|
+
diagnosticHandler?.(diagnostic);
|
|
470
|
+
},
|
|
471
|
+
sync(nextSurfaceId, nextRegistry, nextMessages, nextOnAction, nextOnDiagnostic) {
|
|
472
|
+
actionHandler = nextOnAction;
|
|
473
|
+
diagnosticHandler = nextOnDiagnostic;
|
|
474
|
+
if (!diagnosticHandler)
|
|
475
|
+
pendingDiagnostics.length = 0;
|
|
476
|
+
if (disposed ||
|
|
477
|
+
!processor ||
|
|
478
|
+
surfaceId !== nextSurfaceId ||
|
|
479
|
+
registry !== nextRegistry ||
|
|
480
|
+
!isMessagePrefix(processedMessages, nextMessages)) {
|
|
481
|
+
runtime.captureFocus();
|
|
482
|
+
buildEngine(nextSurfaceId, nextRegistry, nextMessages);
|
|
483
|
+
flushDiagnostics();
|
|
484
|
+
notify();
|
|
485
|
+
return;
|
|
486
|
+
}
|
|
487
|
+
if (nextMessages.length > processedMessages.length) {
|
|
488
|
+
runtime.captureFocus();
|
|
489
|
+
const delta = nextMessages
|
|
490
|
+
.slice(processedMessages.length)
|
|
491
|
+
.map(message => cloneMessageValue(message));
|
|
492
|
+
const target = processor;
|
|
493
|
+
withErrors('queue', () => {
|
|
494
|
+
processBatch(target, nextRegistry, delta, Boolean(diagnosticHandler));
|
|
495
|
+
refreshResolver(target);
|
|
496
|
+
});
|
|
497
|
+
processedMessages.push(...delta);
|
|
498
|
+
flushDiagnostics();
|
|
499
|
+
notify();
|
|
500
|
+
return;
|
|
501
|
+
}
|
|
502
|
+
flushDiagnostics();
|
|
503
|
+
},
|
|
504
|
+
dispose() {
|
|
505
|
+
if (disposed)
|
|
506
|
+
return;
|
|
507
|
+
disposed = true;
|
|
508
|
+
teardownEngine();
|
|
509
|
+
}
|
|
510
|
+
};
|
|
511
|
+
}
|
|
512
|
+
const zeroPlaceholders = () => 0;
|
|
513
|
+
/**
|
|
514
|
+
* Renders an A2UI 1.0 surface directly onto Radiant components via `@a2ui/web_core`.
|
|
515
|
+
* Merges appended patches incrementally by stable node ID to keep local state, focus,
|
|
516
|
+
* scroll position, and drags intact, animates newly added instances once, and recovers
|
|
517
|
+
* removed-node focus as documented in `docs/architecture.md`.
|
|
518
|
+
*/
|
|
519
|
+
export function A2uiSurface({ surfaceId, messages, registry = radiantA2uiRegistry, onAction, onDiagnostic }) {
|
|
520
|
+
const surfaceRef = useRef(null);
|
|
521
|
+
const motionProfile = useContext(MotionProfileContext);
|
|
522
|
+
const [runtime] = useState(() => createSurfaceDomRuntime(motionProfile));
|
|
523
|
+
const [store] = useState(() => createSurfaceStore(surfaceId, registry, messages, onAction, onDiagnostic, runtime));
|
|
524
|
+
useLayoutEffect(() => {
|
|
525
|
+
runtime.setSurfaceElement(surfaceRef.current);
|
|
526
|
+
return () => runtime.setSurfaceElement(null);
|
|
527
|
+
}, [runtime]);
|
|
528
|
+
useLayoutEffect(() => {
|
|
529
|
+
runtime.setMotionProfile(motionProfile);
|
|
530
|
+
}, [runtime, motionProfile]);
|
|
531
|
+
useEffect(() => {
|
|
532
|
+
store.sync(surfaceId, registry, messages, onAction, onDiagnostic);
|
|
533
|
+
}, [store, surfaceId, registry, messages, onAction, onDiagnostic]);
|
|
534
|
+
useEffect(() => () => store.dispose(), [store]);
|
|
535
|
+
useEffect(() => warnA2uiAccessibility(messages, registry), [messages, registry]);
|
|
536
|
+
const rootNode = useSyncExternalStore(store.subscribe, store.getSnapshot, store.getSnapshot);
|
|
537
|
+
const phase = useSyncExternalStore(store.subscribe, store.getPhase, store.getPhase);
|
|
538
|
+
const placeholders = useSyncExternalStore(runtime.placeholders.subscribe, runtime.placeholders.getSnapshot, zeroPlaceholders);
|
|
539
|
+
const waiting = !rootNode && phase !== 'closed';
|
|
540
|
+
return (_jsx("div", { ref: surfaceRef, tabIndex: -1, className: focusRingClass, "aria-busy": waiting || placeholders > 0 ? true : undefined, "data-slot": "a2ui-surface", "data-surface-id": surfaceId, children: rootNode ? (_jsx(A2uiNodeRenderer, { node: rootNode, registry: registry, inline: false, onDiagnostic: store.reportDiagnostic, runtime: runtime })) : waiting ? (_jsx(A2uiPlaceholder, { inline: false, tracker: runtime.placeholders })) : null }));
|
|
541
|
+
}
|
|
542
|
+
//# sourceMappingURL=A2uiSurface.js.map
|