glchat-a2ui-react-renderer 0.0.5 → 0.0.6
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/README.md +216 -93
- package/dist/index.d.ts +2 -18
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +4 -17
- package/dist/src/a2ui/adapter.d.ts +3 -0
- package/dist/src/a2ui/adapter.d.ts.map +1 -0
- package/dist/src/a2ui/adapter.js +11 -0
- package/dist/src/a2ui/glchatStandardCatalog.d.ts +10 -0
- package/dist/src/a2ui/glchatStandardCatalog.d.ts.map +1 -0
- package/dist/src/a2ui/glchatStandardCatalog.js +14 -0
- package/dist/src/components/custom/Button.d.ts +3 -0
- package/dist/src/components/custom/Button.d.ts.map +1 -0
- package/dist/src/components/custom/Button.js +14 -0
- package/dist/src/components/custom/Card.d.ts +3 -0
- package/dist/src/components/custom/Card.d.ts.map +1 -0
- package/dist/src/components/custom/Card.js +7 -0
- package/dist/src/components/custom/Timeout.d.ts +3 -0
- package/dist/src/components/custom/Timeout.d.ts.map +1 -0
- package/dist/src/components/custom/Timeout.js +6 -0
- package/dist/src/components/{Button.d.ts → ui/Button.d.ts} +4 -4
- package/dist/src/components/ui/Button.d.ts.map +1 -0
- package/dist/src/components/ui/Button.js +38 -0
- package/dist/src/components/{Card.d.ts → ui/Card.d.ts} +1 -1
- package/dist/src/components/ui/Card.d.ts.map +1 -0
- package/dist/src/components/ui/Card.js +16 -0
- package/dist/src/components/ui/Timeout.d.ts +6 -0
- package/dist/src/components/ui/Timeout.d.ts.map +1 -0
- package/dist/src/components/{Timeout.js → ui/Timeout.js} +3 -4
- package/package.json +9 -5
- package/styles/globals.css +103 -0
- package/styles/theme-v4.css +86 -0
- package/tailwind.config.cjs +111 -0
- package/dist/src/components/Button.d.ts.map +0 -1
- package/dist/src/components/Button.js +0 -43
- package/dist/src/components/Card.d.ts.map +0 -1
- package/dist/src/components/Card.js +0 -16
- package/dist/src/components/Checkbox.d.ts +0 -5
- package/dist/src/components/Checkbox.d.ts.map +0 -1
- package/dist/src/components/Checkbox.js +0 -9
- package/dist/src/components/Column.d.ts +0 -13
- package/dist/src/components/Column.d.ts.map +0 -1
- package/dist/src/components/Column.js +0 -20
- package/dist/src/components/Image.d.ts +0 -9
- package/dist/src/components/Image.d.ts.map +0 -1
- package/dist/src/components/Image.js +0 -21
- package/dist/src/components/Input.d.ts +0 -8
- package/dist/src/components/Input.d.ts.map +0 -1
- package/dist/src/components/Input.js +0 -9
- package/dist/src/components/Label.d.ts +0 -5
- package/dist/src/components/Label.d.ts.map +0 -1
- package/dist/src/components/Label.js +0 -8
- package/dist/src/components/Row.d.ts +0 -13
- package/dist/src/components/Row.d.ts.map +0 -1
- package/dist/src/components/Row.js +0 -20
- package/dist/src/components/Separator.d.ts +0 -5
- package/dist/src/components/Separator.d.ts.map +0 -1
- package/dist/src/components/Separator.js +0 -11
- package/dist/src/components/Text.d.ts +0 -8
- package/dist/src/components/Text.d.ts.map +0 -1
- package/dist/src/components/Text.js +0 -19
- package/dist/src/components/TextField.d.ts +0 -13
- package/dist/src/components/TextField.d.ts.map +0 -1
- package/dist/src/components/TextField.js +0 -31
- package/dist/src/components/Timeout.d.ts +0 -8
- package/dist/src/components/Timeout.d.ts.map +0 -1
- package/dist/src/helpers/messageParser.d.ts +0 -10
- package/dist/src/helpers/messageParser.d.ts.map +0 -1
- package/dist/src/helpers/messageParser.js +0 -40
- package/dist/src/hooks/useA2UIProcessor.d.ts +0 -17
- package/dist/src/hooks/useA2UIProcessor.d.ts.map +0 -1
- package/dist/src/hooks/useA2UIProcessor.js +0 -16
- package/dist/src/rendering/Surface.d.ts +0 -26
- package/dist/src/rendering/Surface.d.ts.map +0 -1
- package/dist/src/rendering/Surface.js +0 -51
- package/dist/src/rendering/catalog.d.ts +0 -41
- package/dist/src/rendering/catalog.d.ts.map +0 -1
- package/dist/src/rendering/catalog.js +0 -160
- package/dist/src/rendering/componentRegistry.d.ts +0 -9
- package/dist/src/rendering/componentRegistry.d.ts.map +0 -1
- package/dist/src/rendering/componentRegistry.js +0 -10
- package/dist/src/runtime/bindingResolver.d.ts +0 -30
- package/dist/src/runtime/bindingResolver.d.ts.map +0 -1
- package/dist/src/runtime/bindingResolver.js +0 -129
- package/dist/src/runtime/dispatcher.d.ts +0 -15
- package/dist/src/runtime/dispatcher.d.ts.map +0 -1
- package/dist/src/runtime/dispatcher.js +0 -29
- package/dist/src/runtime/messageProcessor.d.ts +0 -54
- package/dist/src/runtime/messageProcessor.d.ts.map +0 -1
- package/dist/src/runtime/messageProcessor.js +0 -85
- package/dist/src/runtime/surfaceManager.d.ts +0 -48
- package/dist/src/runtime/surfaceManager.d.ts.map +0 -1
- package/dist/src/runtime/surfaceManager.js +0 -90
- package/dist/src/types.d.ts +0 -340
- package/dist/src/types.d.ts.map +0 -1
- package/dist/src/types.js +0 -3
- package/dist/styles.css +0 -395
|
@@ -1,129 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Returns the binding path from a bound value if it has one (writable binding).
|
|
3
|
-
* Literal-only bindings have no path and cannot be updated from the UI.
|
|
4
|
-
*/
|
|
5
|
-
export function getPathFromBoundValue(boundValue) {
|
|
6
|
-
return boundValue?.path;
|
|
7
|
-
}
|
|
8
|
-
/**
|
|
9
|
-
* Sets a value at a path in the data model (immutable update).
|
|
10
|
-
* Path format: slash-separated only (e.g. "user/name" or "/user/name").
|
|
11
|
-
* Creates nested objects as needed.
|
|
12
|
-
*/
|
|
13
|
-
export function setPathValue(dataModel, path, value) {
|
|
14
|
-
if (!path)
|
|
15
|
-
return dataModel;
|
|
16
|
-
const cleanPath = path.startsWith('/') ? path.slice(1) : path;
|
|
17
|
-
const parts = cleanPath.split('/').filter(Boolean);
|
|
18
|
-
if (parts.length === 0)
|
|
19
|
-
return dataModel;
|
|
20
|
-
function setNested(obj, keys, val) {
|
|
21
|
-
const [head, ...rest] = keys;
|
|
22
|
-
if (rest.length === 0) {
|
|
23
|
-
return { ...obj, [head]: val };
|
|
24
|
-
}
|
|
25
|
-
const current = obj[head];
|
|
26
|
-
const next = current !== null && typeof current === 'object' && !Array.isArray(current)
|
|
27
|
-
? current
|
|
28
|
-
: {};
|
|
29
|
-
return { ...obj, [head]: setNested({ ...next }, rest, val) };
|
|
30
|
-
}
|
|
31
|
-
return setNested({ ...dataModel }, parts, value);
|
|
32
|
-
}
|
|
33
|
-
/**
|
|
34
|
-
* Resolves action context against the data model for user action payload.
|
|
35
|
-
* Per spec, context is an array of { key, value } entries.
|
|
36
|
-
* Returns a plain object with resolved values (used when sending UserAction).
|
|
37
|
-
*/
|
|
38
|
-
export function resolveActionContext(context, dataModel) {
|
|
39
|
-
if (!context)
|
|
40
|
-
return {};
|
|
41
|
-
const result = {};
|
|
42
|
-
for (const { key, value: boundValue } of context) {
|
|
43
|
-
const resolved = resolveBoundValue(boundValue, dataModel);
|
|
44
|
-
if (resolved !== undefined) {
|
|
45
|
-
result[key] = resolved;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
return result;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Resolves a bound value against a data model.
|
|
52
|
-
* Returns the resolved value (string, number, boolean, or undefined).
|
|
53
|
-
* Accepts any bound value shape (StringOrPathValue, BooleanOrPathValue, BoundValue, etc.).
|
|
54
|
-
* Safe against malformed input: returns undefined if boundValue is not a non-null object.
|
|
55
|
-
*/
|
|
56
|
-
export function resolveBoundValue(boundValue, dataModel) {
|
|
57
|
-
if (boundValue == null)
|
|
58
|
-
return undefined;
|
|
59
|
-
const literal = boundValue.literalString
|
|
60
|
-
?? boundValue.literalNumber
|
|
61
|
-
?? boundValue.literalBoolean
|
|
62
|
-
?? boundValue.literalArray;
|
|
63
|
-
if (literal !== undefined && boundValue.path) {
|
|
64
|
-
const pathValue = getPathValue(dataModel, boundValue.path);
|
|
65
|
-
return pathValue === undefined ? literal : pathValue;
|
|
66
|
-
}
|
|
67
|
-
if (literal !== undefined)
|
|
68
|
-
return literal;
|
|
69
|
-
if (boundValue.path) {
|
|
70
|
-
return getPathValue(dataModel, boundValue.path);
|
|
71
|
-
}
|
|
72
|
-
return undefined;
|
|
73
|
-
}
|
|
74
|
-
/**
|
|
75
|
-
* Gets a value from the data model using a path.
|
|
76
|
-
* Only slash separator is supported (e.g. "/user/name" or "user/name").
|
|
77
|
-
*/
|
|
78
|
-
function getPathValue(dataModel, path) {
|
|
79
|
-
if (!path)
|
|
80
|
-
return undefined;
|
|
81
|
-
// Remove leading slash if present
|
|
82
|
-
const cleanPath = path.startsWith('/') ? path.slice(1) : path;
|
|
83
|
-
// Split path and navigate through the model
|
|
84
|
-
const parts = cleanPath.split('/');
|
|
85
|
-
let current = dataModel;
|
|
86
|
-
for (const part of parts) {
|
|
87
|
-
if (current === null || current === undefined) {
|
|
88
|
-
return undefined;
|
|
89
|
-
}
|
|
90
|
-
if (typeof current === 'object' && part in current) {
|
|
91
|
-
current = current[part];
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
94
|
-
return undefined;
|
|
95
|
-
}
|
|
96
|
-
}
|
|
97
|
-
return current;
|
|
98
|
-
}
|
|
99
|
-
/**
|
|
100
|
-
* Updates the data model with new content
|
|
101
|
-
*/
|
|
102
|
-
export function updateDataModel(currentModel, contents) {
|
|
103
|
-
const updated = { ...currentModel };
|
|
104
|
-
for (const content of contents) {
|
|
105
|
-
const value = resolveContentValue(content);
|
|
106
|
-
if (value !== undefined) {
|
|
107
|
-
updated[content.key] = value;
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
return updated;
|
|
111
|
-
}
|
|
112
|
-
function resolveContentValue(content) {
|
|
113
|
-
if (content.valueMap) {
|
|
114
|
-
return buildValueMap(content.valueMap);
|
|
115
|
-
}
|
|
116
|
-
return content.valueString ?? content.valueNumber ?? content.valueBoolean;
|
|
117
|
-
}
|
|
118
|
-
function buildValueMap(valueMap) {
|
|
119
|
-
const result = {};
|
|
120
|
-
for (const item of valueMap) {
|
|
121
|
-
if (item.valueMap) {
|
|
122
|
-
result[item.key] = buildValueMap(item.valueMap);
|
|
123
|
-
}
|
|
124
|
-
else {
|
|
125
|
-
result[item.key] = item.valueString ?? item.valueNumber ?? item.valueBoolean;
|
|
126
|
-
}
|
|
127
|
-
}
|
|
128
|
-
return result;
|
|
129
|
-
}
|
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
import { SurfaceManager } from './surfaceManager.js';
|
|
2
|
-
import type { A2UIMessage } from '../types.js';
|
|
3
|
-
export type MessageHandler = (message: A2UIMessage) => void;
|
|
4
|
-
/**
|
|
5
|
-
* Dispatches A2UI messages to appropriate handlers
|
|
6
|
-
*/
|
|
7
|
-
export declare class MessageDispatcher {
|
|
8
|
-
private surfaceManager;
|
|
9
|
-
constructor(surfaceManager: SurfaceManager);
|
|
10
|
-
/**
|
|
11
|
-
* Dispatches a message to the appropriate handler
|
|
12
|
-
*/
|
|
13
|
-
dispatch(message: A2UIMessage): void;
|
|
14
|
-
}
|
|
15
|
-
//# sourceMappingURL=dispatcher.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"dispatcher.d.ts","sourceRoot":"","sources":["../../../src/runtime/dispatcher.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE/C,MAAM,MAAM,cAAc,GAAG,CAAC,OAAO,EAAE,WAAW,KAAK,IAAI,CAAC;AAE5D;;GAEG;AACH,qBAAa,iBAAiB;IAChB,OAAO,CAAC,cAAc;gBAAd,cAAc,EAAE,cAAc;IAElD;;OAEG;IACH,QAAQ,CAAC,OAAO,EAAE,WAAW,GAAG,IAAI;CAarC"}
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Dispatches A2UI messages to appropriate handlers
|
|
3
|
-
*/
|
|
4
|
-
export class MessageDispatcher {
|
|
5
|
-
surfaceManager;
|
|
6
|
-
constructor(surfaceManager) {
|
|
7
|
-
this.surfaceManager = surfaceManager;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Dispatches a message to the appropriate handler
|
|
11
|
-
*/
|
|
12
|
-
dispatch(message) {
|
|
13
|
-
if (message.beginRendering) {
|
|
14
|
-
this.surfaceManager.handleBeginRendering(message.beginRendering);
|
|
15
|
-
}
|
|
16
|
-
else if (message.surfaceUpdate) {
|
|
17
|
-
this.surfaceManager.handleSurfaceUpdate(message.surfaceUpdate);
|
|
18
|
-
}
|
|
19
|
-
else if (message.dataModelUpdate) {
|
|
20
|
-
this.surfaceManager.handleDataModelUpdate(message.dataModelUpdate);
|
|
21
|
-
}
|
|
22
|
-
else if (message.deleteSurface) {
|
|
23
|
-
this.surfaceManager.handleDeleteSurface(message.deleteSurface);
|
|
24
|
-
}
|
|
25
|
-
else {
|
|
26
|
-
console.warn('Unknown message type:', message);
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
}
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { SurfaceManager } from './surfaceManager.js';
|
|
2
|
-
import type { A2UIMessage, ClientToServerMessage, DispatchedEvent, SurfaceState } from '../types.js';
|
|
3
|
-
/**
|
|
4
|
-
* Message processor API aligned with official Lit/Angular renderers.
|
|
5
|
-
* Single abstraction that wraps SurfaceManager + MessageDispatcher.
|
|
6
|
-
* The app creates this, feeds messages via processMessages(), and reads
|
|
7
|
-
* getSurfaces() to render one A2UISurface per surface.
|
|
8
|
-
* User actions: subscribe to processor.events; send event.message to backend,
|
|
9
|
-
* then call event.completion(messages) after processMessages(messages).
|
|
10
|
-
*/
|
|
11
|
-
export declare class MessageProcessor {
|
|
12
|
-
private readonly surfaceManager;
|
|
13
|
-
private readonly dispatcher;
|
|
14
|
-
private readonly eventListeners;
|
|
15
|
-
/** Subscribe to user action events (e.g. button clicks). Send event.message to backend, then event.completion(messages). */
|
|
16
|
-
readonly events: {
|
|
17
|
-
subscribe: (listener: (event: DispatchedEvent) => void) => (() => void);
|
|
18
|
-
};
|
|
19
|
-
constructor();
|
|
20
|
-
/**
|
|
21
|
-
* Returns the current surfaces (same shape as Lit/Angular getSurfaces()).
|
|
22
|
-
* A defensive copy is returned so external callers cannot mutate internal state.
|
|
23
|
-
*/
|
|
24
|
-
getSurfaces(): ReadonlyMap<string, SurfaceState>;
|
|
25
|
-
/**
|
|
26
|
-
* Processes server-to-client A2UI messages.
|
|
27
|
-
* Call when messages arrive (e.g. from fetch or stream).
|
|
28
|
-
*/
|
|
29
|
-
processMessages(messages: A2UIMessage[]): void;
|
|
30
|
-
/**
|
|
31
|
-
* Clears all surfaces. Call before a new response or when replacing content.
|
|
32
|
-
*/
|
|
33
|
-
clearSurfaces(): void;
|
|
34
|
-
/**
|
|
35
|
-
* Updates the data model for a surface at the given path (e.g. when the user
|
|
36
|
-
* types in a TextField or toggles a Checkbox). Same as Lit/Angular. Pass
|
|
37
|
-
* processor + refreshSurfaces to A2UISurface so the catalog calls this and
|
|
38
|
-
* refreshSurfaces() on input change.
|
|
39
|
-
*/
|
|
40
|
-
setData(surfaceId: string, path: string, value: unknown): void;
|
|
41
|
-
/**
|
|
42
|
-
* Dispatches a client message (e.g. user action). Pushes to events;
|
|
43
|
-
* subscribers send message to backend and call completion(messages) when done.
|
|
44
|
-
* Returns a Promise that resolves with the messages passed to completion.
|
|
45
|
-
* Same signature as Angular: dispatch(message: A2UIClientEventMessage).
|
|
46
|
-
*/
|
|
47
|
-
dispatch(message: ClientToServerMessage): Promise<A2UIMessage[]>;
|
|
48
|
-
/**
|
|
49
|
-
* Access to the underlying surface manager for advanced use (e.g. resolving
|
|
50
|
-
* action context). Prefer setData() for input/checkbox value updates.
|
|
51
|
-
*/
|
|
52
|
-
getSurfaceManager(): SurfaceManager;
|
|
53
|
-
}
|
|
54
|
-
//# sourceMappingURL=messageProcessor.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"messageProcessor.d.ts","sourceRoot":"","sources":["../../../src/runtime/messageProcessor.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,KAAK,EACV,WAAW,EACX,qBAAqB,EACrB,eAAe,EACf,YAAY,EACb,MAAM,aAAa,CAAC;AAErB;;;;;;;GAOG;AACH,qBAAa,gBAAgB;IAC3B,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAiB;IAChD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAoB;IAC/C,OAAO,CAAC,QAAQ,CAAC,cAAc,CAA+C;IAE9E,4HAA4H;IAC5H,QAAQ,CAAC,MAAM;8BACS,CAAC,KAAK,EAAE,eAAe,KAAK,IAAI,KAAG,CAAC,MAAM,IAAI,CAAC;MAOrE;;IAOF;;;OAGG;IACH,WAAW,IAAI,WAAW,CAAC,MAAM,EAAE,YAAY,CAAC;IAIhD;;;OAGG;IACH,eAAe,CAAC,QAAQ,EAAE,WAAW,EAAE,GAAG,IAAI;IAM9C;;OAEG;IACH,aAAa,IAAI,IAAI;IAIrB;;;;;OAKG;IACH,OAAO,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,GAAG,IAAI;IAI9D;;;;;OAKG;IACH,QAAQ,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,WAAW,EAAE,CAAC;IAYhE;;;OAGG;IACH,iBAAiB,IAAI,cAAc;CAGpC"}
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
import { MessageDispatcher } from './dispatcher.js';
|
|
2
|
-
import { SurfaceManager } from './surfaceManager.js';
|
|
3
|
-
/**
|
|
4
|
-
* Message processor API aligned with official Lit/Angular renderers.
|
|
5
|
-
* Single abstraction that wraps SurfaceManager + MessageDispatcher.
|
|
6
|
-
* The app creates this, feeds messages via processMessages(), and reads
|
|
7
|
-
* getSurfaces() to render one A2UISurface per surface.
|
|
8
|
-
* User actions: subscribe to processor.events; send event.message to backend,
|
|
9
|
-
* then call event.completion(messages) after processMessages(messages).
|
|
10
|
-
*/
|
|
11
|
-
export class MessageProcessor {
|
|
12
|
-
surfaceManager;
|
|
13
|
-
dispatcher;
|
|
14
|
-
eventListeners = [];
|
|
15
|
-
/** Subscribe to user action events (e.g. button clicks). Send event.message to backend, then event.completion(messages). */
|
|
16
|
-
events = {
|
|
17
|
-
subscribe: (listener) => {
|
|
18
|
-
this.eventListeners.push(listener);
|
|
19
|
-
return () => {
|
|
20
|
-
const i = this.eventListeners.indexOf(listener);
|
|
21
|
-
if (i !== -1)
|
|
22
|
-
this.eventListeners.splice(i, 1);
|
|
23
|
-
};
|
|
24
|
-
},
|
|
25
|
-
};
|
|
26
|
-
constructor() {
|
|
27
|
-
this.surfaceManager = new SurfaceManager();
|
|
28
|
-
this.dispatcher = new MessageDispatcher(this.surfaceManager);
|
|
29
|
-
}
|
|
30
|
-
/**
|
|
31
|
-
* Returns the current surfaces (same shape as Lit/Angular getSurfaces()).
|
|
32
|
-
* A defensive copy is returned so external callers cannot mutate internal state.
|
|
33
|
-
*/
|
|
34
|
-
getSurfaces() {
|
|
35
|
-
return new Map(this.surfaceManager.getAllSurfaces());
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Processes server-to-client A2UI messages.
|
|
39
|
-
* Call when messages arrive (e.g. from fetch or stream).
|
|
40
|
-
*/
|
|
41
|
-
processMessages(messages) {
|
|
42
|
-
for (const message of messages) {
|
|
43
|
-
this.dispatcher.dispatch(message);
|
|
44
|
-
}
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Clears all surfaces. Call before a new response or when replacing content.
|
|
48
|
-
*/
|
|
49
|
-
clearSurfaces() {
|
|
50
|
-
this.surfaceManager.clearSurfaces();
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* Updates the data model for a surface at the given path (e.g. when the user
|
|
54
|
-
* types in a TextField or toggles a Checkbox). Same as Lit/Angular. Pass
|
|
55
|
-
* processor + refreshSurfaces to A2UISurface so the catalog calls this and
|
|
56
|
-
* refreshSurfaces() on input change.
|
|
57
|
-
*/
|
|
58
|
-
setData(surfaceId, path, value) {
|
|
59
|
-
this.surfaceManager.updateDataModelFromClient(surfaceId, path, value);
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Dispatches a client message (e.g. user action). Pushes to events;
|
|
63
|
-
* subscribers send message to backend and call completion(messages) when done.
|
|
64
|
-
* Returns a Promise that resolves with the messages passed to completion.
|
|
65
|
-
* Same signature as Angular: dispatch(message: A2UIClientEventMessage).
|
|
66
|
-
*/
|
|
67
|
-
dispatch(message) {
|
|
68
|
-
return new Promise((resolve) => {
|
|
69
|
-
const completion = (messages) => {
|
|
70
|
-
resolve(messages);
|
|
71
|
-
};
|
|
72
|
-
const event = { message, completion };
|
|
73
|
-
for (const listener of this.eventListeners) {
|
|
74
|
-
listener(event);
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Access to the underlying surface manager for advanced use (e.g. resolving
|
|
80
|
-
* action context). Prefer setData() for input/checkbox value updates.
|
|
81
|
-
*/
|
|
82
|
-
getSurfaceManager() {
|
|
83
|
-
return this.surfaceManager;
|
|
84
|
-
}
|
|
85
|
-
}
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import type { BeginRenderingMessage, ComponentDefinition, DataModelUpdateMessage, DeleteSurfaceMessage, SurfaceState, SurfaceUpdateMessage } from '../types.js';
|
|
2
|
-
export declare class SurfaceManager {
|
|
3
|
-
private surfaces;
|
|
4
|
-
/**
|
|
5
|
-
* Gets or creates a surface
|
|
6
|
-
*/
|
|
7
|
-
private getOrCreateSurface;
|
|
8
|
-
/**
|
|
9
|
-
* Handles beginRendering message
|
|
10
|
-
*/
|
|
11
|
-
handleBeginRendering(message: BeginRenderingMessage): void;
|
|
12
|
-
/**
|
|
13
|
-
* Handles surfaceUpdate message
|
|
14
|
-
*/
|
|
15
|
-
handleSurfaceUpdate(message: SurfaceUpdateMessage): void;
|
|
16
|
-
/**
|
|
17
|
-
* Handles dataModelUpdate message
|
|
18
|
-
*/
|
|
19
|
-
handleDataModelUpdate(message: DataModelUpdateMessage): void;
|
|
20
|
-
/**
|
|
21
|
-
* Updates the data model from client (e.g. user editing a TextField or CheckBox).
|
|
22
|
-
* Sets the value at the given path and replaces the surface data model so UI re-renders.
|
|
23
|
-
*/
|
|
24
|
-
updateDataModelFromClient(surfaceId: string, path: string, value: unknown): void;
|
|
25
|
-
/**
|
|
26
|
-
* Handles deleteSurface message
|
|
27
|
-
*/
|
|
28
|
-
handleDeleteSurface(message: DeleteSurfaceMessage): void;
|
|
29
|
-
/**
|
|
30
|
-
* Clears all surfaces (e.g. before a new response or new stream).
|
|
31
|
-
* Aligns with official Lit/Angular processor API.
|
|
32
|
-
*/
|
|
33
|
-
clearSurfaces(): void;
|
|
34
|
-
/**
|
|
35
|
-
* Gets a surface state
|
|
36
|
-
*/
|
|
37
|
-
getSurface(surfaceId: string): SurfaceState | undefined;
|
|
38
|
-
/**
|
|
39
|
-
* Gets all surfaces. Returns a defensive copy so callers cannot mutate
|
|
40
|
-
* the internal Map (e.g. clear, delete, set) and break SurfaceManager state.
|
|
41
|
-
*/
|
|
42
|
-
getAllSurfaces(): Map<string, SurfaceState>;
|
|
43
|
-
/**
|
|
44
|
-
* Gets a component definition from a surface
|
|
45
|
-
*/
|
|
46
|
-
getComponent(surfaceId: string, componentId: string): ComponentDefinition | undefined;
|
|
47
|
-
}
|
|
48
|
-
//# sourceMappingURL=surfaceManager.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"surfaceManager.d.ts","sourceRoot":"","sources":["../../../src/runtime/surfaceManager.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,qBAAqB,EACrB,mBAAmB,EACnB,sBAAsB,EACtB,oBAAoB,EACpB,YAAY,EACZ,oBAAoB,EACrB,MAAM,aAAa,CAAC;AAErB,qBAAa,cAAc;IACzB,OAAO,CAAC,QAAQ,CAAwC;IAExD;;OAEG;IACH,OAAO,CAAC,kBAAkB;IAY1B;;OAEG;IACH,oBAAoB,CAAC,OAAO,EAAE,qBAAqB,GAAG,IAAI;IAO1D;;OAEG;IACH,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,GAAG,IAAI;IAUxD;;OAEG;IACH,qBAAqB,CAAC,OAAO,EAAE,sBAAsB,GAAG,IAAI;IAM5D;;;OAGG;IACH,yBAAyB,CACvB,SAAS,EAAE,MAAM,EACjB,IAAI,EAAE,MAAM,EACZ,KAAK,EAAE,OAAO,GACb,IAAI;IAMP;;OAEG;IACH,mBAAmB,CAAC,OAAO,EAAE,oBAAoB,GAAG,IAAI;IAKxD;;;OAGG;IACH,aAAa,IAAI,IAAI;IAIrB;;OAEG;IACH,UAAU,CAAC,SAAS,EAAE,MAAM,GAAG,YAAY,GAAG,SAAS;IAIvD;;;OAGG;IACH,cAAc,IAAI,GAAG,CAAC,MAAM,EAAE,YAAY,CAAC;IAI3C;;OAEG;IACH,YAAY,CACV,SAAS,EAAE,MAAM,EACjB,WAAW,EAAE,MAAM,GAClB,mBAAmB,GAAG,SAAS;CAInC"}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
import { setPathValue, updateDataModel } from './bindingResolver.js';
|
|
2
|
-
export class SurfaceManager {
|
|
3
|
-
surfaces = new Map();
|
|
4
|
-
/**
|
|
5
|
-
* Gets or creates a surface
|
|
6
|
-
*/
|
|
7
|
-
getOrCreateSurface(surfaceId) {
|
|
8
|
-
if (!this.surfaces.has(surfaceId)) {
|
|
9
|
-
this.surfaces.set(surfaceId, {
|
|
10
|
-
surfaceId,
|
|
11
|
-
componentBuffer: new Map(),
|
|
12
|
-
dataModel: {},
|
|
13
|
-
ready: false,
|
|
14
|
-
});
|
|
15
|
-
}
|
|
16
|
-
return this.surfaces.get(surfaceId);
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* Handles beginRendering message
|
|
20
|
-
*/
|
|
21
|
-
handleBeginRendering(message) {
|
|
22
|
-
const { surfaceId, root } = message;
|
|
23
|
-
const surface = this.getOrCreateSurface(surfaceId);
|
|
24
|
-
surface.ready = true;
|
|
25
|
-
surface.rootId = root;
|
|
26
|
-
}
|
|
27
|
-
/**
|
|
28
|
-
* Handles surfaceUpdate message
|
|
29
|
-
*/
|
|
30
|
-
handleSurfaceUpdate(message) {
|
|
31
|
-
const { surfaceId, components } = message;
|
|
32
|
-
const surface = this.getOrCreateSurface(surfaceId);
|
|
33
|
-
// Add or update components in the buffer
|
|
34
|
-
for (const componentDef of components) {
|
|
35
|
-
surface.componentBuffer.set(componentDef.id, componentDef);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
/**
|
|
39
|
-
* Handles dataModelUpdate message
|
|
40
|
-
*/
|
|
41
|
-
handleDataModelUpdate(message) {
|
|
42
|
-
const { surfaceId, contents } = message;
|
|
43
|
-
const surface = this.getOrCreateSurface(surfaceId);
|
|
44
|
-
surface.dataModel = updateDataModel(surface.dataModel, contents);
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* Updates the data model from client (e.g. user editing a TextField or CheckBox).
|
|
48
|
-
* Sets the value at the given path and replaces the surface data model so UI re-renders.
|
|
49
|
-
*/
|
|
50
|
-
updateDataModelFromClient(surfaceId, path, value) {
|
|
51
|
-
const surface = this.surfaces.get(surfaceId);
|
|
52
|
-
if (!surface)
|
|
53
|
-
return;
|
|
54
|
-
surface.dataModel = setPathValue(surface.dataModel, path, value);
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* Handles deleteSurface message
|
|
58
|
-
*/
|
|
59
|
-
handleDeleteSurface(message) {
|
|
60
|
-
const { surfaceId } = message;
|
|
61
|
-
this.surfaces.delete(surfaceId);
|
|
62
|
-
}
|
|
63
|
-
/**
|
|
64
|
-
* Clears all surfaces (e.g. before a new response or new stream).
|
|
65
|
-
* Aligns with official Lit/Angular processor API.
|
|
66
|
-
*/
|
|
67
|
-
clearSurfaces() {
|
|
68
|
-
this.surfaces.clear();
|
|
69
|
-
}
|
|
70
|
-
/**
|
|
71
|
-
* Gets a surface state
|
|
72
|
-
*/
|
|
73
|
-
getSurface(surfaceId) {
|
|
74
|
-
return this.surfaces.get(surfaceId);
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Gets all surfaces. Returns a defensive copy so callers cannot mutate
|
|
78
|
-
* the internal Map (e.g. clear, delete, set) and break SurfaceManager state.
|
|
79
|
-
*/
|
|
80
|
-
getAllSurfaces() {
|
|
81
|
-
return new Map(this.surfaces);
|
|
82
|
-
}
|
|
83
|
-
/**
|
|
84
|
-
* Gets a component definition from a surface
|
|
85
|
-
*/
|
|
86
|
-
getComponent(surfaceId, componentId) {
|
|
87
|
-
const surface = this.surfaces.get(surfaceId);
|
|
88
|
-
return surface?.componentBuffer.get(componentId);
|
|
89
|
-
}
|
|
90
|
-
}
|