Canvas: fix A2UI v0.8 rendering
This commit is contained in:
@@ -1 +1 @@
|
||||
{"version":3,"file":"model-processor.d.ts","sourceRoot":"","sources":["../../../../src/0.8/data/model-processor.ts"],"names":[],"mappings":"AAgBA,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAKhB,SAAS,EAIT,OAAO,EAGP,gBAAgB,EAGjB,MAAM,gBAAgB,CAAC;AA0BxB;;;GAGG;AACH,qBAAa,oBAAqB,YAAW,gBAAgB;;IAUzD,QAAQ,CAAC,IAAI,EAAE;QACb,OAAO,EAAE,cAAc,CAAC;QACxB,SAAS,EAAE,gBAAgB,CAAC;QAC5B,OAAO,EAAE,cAAc,CAAC;QACxB,OAAO,EAAE,iBAAiB,CAAC;KAC5B;IAdH,MAAM,CAAC,QAAQ,CAAC,kBAAkB,cAAc;gBASrC,IAAI,GAAE;QACb,OAAO,EAAE,cAAc,CAAC;QACxB,SAAS,EAAE,gBAAgB,CAAC;QAC5B,OAAO,EAAE,cAAc,CAAC;QACxB,OAAO,EAAE,iBAAiB,CAAC;KACwC;IAUvE,WAAW,IAAI,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC;IAI3C,aAAa;IAIb,eAAe,CAAC,QAAQ,EAAE,qBAAqB,EAAE,GAAG,IAAI;IA6BxD;;;;OAIG;IACH,OAAO,CACL,IAAI,EAAE,gBAAgB,EACtB,YAAY,EAAE,MAAM,EACpB,SAAS,SAA0C,GAClD,SAAS,GAAG,IAAI;IAkBnB,OAAO,CACL,IAAI,EAAE,gBAAgB,GAAG,IAAI,EAC7B,YAAY,EAAE,MAAM,EACpB,KAAK,EAAE,SAAS,EAChB,SAAS,SAA0C,GAClD,IAAI;IAuBP,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM,GAAG,MAAM;CAkqB5D"}
|
||||
{"version":3,"file":"model-processor.d.ts","sourceRoot":"","sources":["../../../../src/0.8/data/model-processor.ts"],"names":[],"mappings":"AAgBA,OAAO,EACL,qBAAqB,EACrB,gBAAgB,EAKhB,SAAS,EAIT,OAAO,EAGP,gBAAgB,EAGjB,MAAM,gBAAgB,CAAC;AA0BxB;;;GAGG;AACH,qBAAa,oBAAqB,YAAW,gBAAgB;;IAUzD,QAAQ,CAAC,IAAI,EAAE;QACb,OAAO,EAAE,cAAc,CAAC;QACxB,SAAS,EAAE,gBAAgB,CAAC;QAC5B,OAAO,EAAE,cAAc,CAAC;QACxB,OAAO,EAAE,iBAAiB,CAAC;KAC5B;IAdH,MAAM,CAAC,QAAQ,CAAC,kBAAkB,cAAc;gBASrC,IAAI,GAAE;QACb,OAAO,EAAE,cAAc,CAAC;QACxB,SAAS,EAAE,gBAAgB,CAAC;QAC5B,OAAO,EAAE,cAAc,CAAC;QACxB,OAAO,EAAE,iBAAiB,CAAC;KACwC;IAUvE,WAAW,IAAI,WAAW,CAAC,MAAM,EAAE,OAAO,CAAC;IAI3C,aAAa;IAIb,eAAe,CAAC,QAAQ,EAAE,qBAAqB,EAAE,GAAG,IAAI;IA6BxD;;;;OAIG;IACH,OAAO,CACL,IAAI,EAAE,gBAAgB,EACtB,YAAY,EAAE,MAAM,EACpB,SAAS,SAA0C,GAClD,SAAS,GAAG,IAAI;IAkBnB,OAAO,CACL,IAAI,EAAE,gBAAgB,GAAG,IAAI,EAC7B,YAAY,EAAE,MAAM,EACpB,KAAK,EAAE,SAAS,EAChB,SAAS,SAA0C,GAClD,IAAI;IAuBP,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,eAAe,CAAC,EAAE,MAAM,GAAG,MAAM;CA8qB5D"}
|
||||
@@ -360,7 +360,7 @@ export class A2uiMessageProcessor {
|
||||
const resolvedProperties = new this.#objCtor();
|
||||
if (isObject(unresolvedProperties)) {
|
||||
for (const [key, value] of Object.entries(unresolvedProperties)) {
|
||||
resolvedProperties[key] = this.#resolvePropertyValue(value, surface, visited, dataContextPath, idSuffix);
|
||||
resolvedProperties[key] = this.#resolvePropertyValue(value, surface, visited, dataContextPath, idSuffix, key);
|
||||
}
|
||||
}
|
||||
visited.delete(fullId);
|
||||
@@ -549,9 +549,13 @@ export class A2uiMessageProcessor {
|
||||
* a child node (a string that matches a component ID), an explicitList of
|
||||
* children, or a template, these will be built out here.
|
||||
*/
|
||||
#resolvePropertyValue(value, surface, visited, dataContextPath, idSuffix = "") {
|
||||
#resolvePropertyValue(value, surface, visited, dataContextPath, idSuffix = "", propertyKey = null) {
|
||||
const isComponentIdReferenceKey = (key) => key === "child" || key.endsWith("Child");
|
||||
// 1. If it's a string that matches a component ID, build that node.
|
||||
if (typeof value === "string" && surface.components.has(value)) {
|
||||
if (typeof value === "string" &&
|
||||
propertyKey &&
|
||||
isComponentIdReferenceKey(propertyKey) &&
|
||||
surface.components.has(value)) {
|
||||
return this.#buildNodeRecursive(value, surface, visited, dataContextPath, idSuffix);
|
||||
}
|
||||
// 2. If it's a ComponentArrayReference (e.g., a `children` property),
|
||||
@@ -597,7 +601,7 @@ export class A2uiMessageProcessor {
|
||||
}
|
||||
// 3. If it's a plain array, resolve each of its items.
|
||||
if (Array.isArray(value)) {
|
||||
return value.map((item) => this.#resolvePropertyValue(item, surface, visited, dataContextPath, idSuffix));
|
||||
return value.map((item) => this.#resolvePropertyValue(item, surface, visited, dataContextPath, idSuffix, propertyKey));
|
||||
}
|
||||
// 4. If it's a plain object, resolve each of its properties.
|
||||
if (isObject(value)) {
|
||||
@@ -617,7 +621,7 @@ export class A2uiMessageProcessor {
|
||||
newObj[key] = propertyValue;
|
||||
continue;
|
||||
}
|
||||
newObj[key] = this.#resolvePropertyValue(propertyValue, surface, visited, dataContextPath, idSuffix);
|
||||
newObj[key] = this.#resolvePropertyValue(propertyValue, surface, visited, dataContextPath, idSuffix, key);
|
||||
}
|
||||
return newObj;
|
||||
}
|
||||
|
||||
File diff suppressed because one or more lines are too long
@@ -314,6 +314,43 @@ describe("A2uiMessageProcessor", () => {
|
||||
assert.strictEqual(plainTree.properties.children[0].id, "child");
|
||||
assert.strictEqual(plainTree.properties.children[0].type, "Text");
|
||||
});
|
||||
it("should not treat enum-like strings as child component IDs", () => {
|
||||
processor.processMessages([
|
||||
{
|
||||
surfaceUpdate: {
|
||||
surfaceId: "@default",
|
||||
components: [
|
||||
{
|
||||
id: "root",
|
||||
component: {
|
||||
Column: { children: { explicitList: ["body"] } },
|
||||
},
|
||||
},
|
||||
{
|
||||
id: "body",
|
||||
component: {
|
||||
Text: {
|
||||
text: { literalString: "Hello" },
|
||||
usageHint: "body",
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
{
|
||||
beginRendering: {
|
||||
root: "root",
|
||||
surfaceId: "@default",
|
||||
},
|
||||
},
|
||||
]);
|
||||
const tree = processor.getSurfaces().get("@default")?.componentTree;
|
||||
const plainTree = toPlainObject(tree);
|
||||
assert.strictEqual(plainTree.id, "root");
|
||||
assert.strictEqual(plainTree.properties.children[0].id, "body");
|
||||
assert.strictEqual(plainTree.properties.children[0].type, "Text");
|
||||
});
|
||||
it("should throw an error on circular dependencies", () => {
|
||||
// First, load the components
|
||||
processor.processMessages([
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user