logoAnt Design X

设计研发组件X MarkdownX SDKX CardX Skill演示国内镜像
  • 介绍
  • A2UI v0.8
  • A2UI v0.9

A2UI v0.9

API

通用属性参考:通用属性

BoxProps

Box 组件作为容器,用于管理 Card 实例和命令分发。

属性说明类型默认值版本
children子元素React.ReactNode--
components自定义组件映射,组件名称必须以大写字母开头Record<string, React.ComponentType<any>>--
commandsA2UI 命令对象A2UICommand_v0_9 | XAgentCommand_v0_8--
onActionCard 内部组件触发 action 时的回调函数(payload: ActionPayload) => void--

CardProps

Card 组件用于渲染单个 Surface。

属性说明类型默认值版本
idSurface ID,对应命令中的 surfaceIdstring--

ActionPayload

action 事件的数据结构。

属性说明类型默认值版本
name事件名称string--
surfaceId触发该 action 的 surfaceIdstring--
context当前 surface 的完整 dataModel 快照Record<string, any>--

A2UICommand_v0_9

v0.9 版本的命令类型,支持以下命令:

CreateSurfaceCommand

创建新的 Surface。

属性说明类型默认值版本
version版本号'v0.9'--
createSurface.surfaceIdSurface IDstring--
createSurface.catalogId组件目录 URL 或本地标识string--

UpdateComponentsCommand

更新 Surface 上的组件。

属性说明类型默认值版本
version版本号'v0.9'--
updateComponents.surfaceIdSurface IDstring--
updateComponents.components组件列表BaseComponent_v0_9[]--

BaseComponent_v0_9

typescript
interface BaseComponent_v0_9 {
id: string;
component: string;
child?: string;
children?: string[];
[key: string]: any | PathValue;
}

UpdateDataModelCommand

更新数据模型。

属性说明类型默认值版本
version版本号'v0.9'--
updateDataModel.surfaceIdSurface IDstring--
updateDataModel.path数据路径string--
updateDataModel.value数据值any--

DeleteSurfaceCommand

删除 Surface。

属性说明类型默认值版本
version版本号'v0.9'--
deleteSurface.surfaceIdSurface IDstring--

PathValue

数据绑定路径对象。

typescript
interface PathValue {
path: string;
}

Catalog

组件目录定义。

typescript
interface Catalog {
$schema?: string;
$id?: string;
title?: string;
description?: string;
catalogId?: string;
components?: Record<string, CatalogComponent>;
functions?: Record<string, any>;
$defs?: Record<string, any>;
}

CatalogComponent

Catalog 中的组件定义。

typescript
interface CatalogComponent {
type: 'object';
allOf?: any[];
properties?: Record<string, any>;
required?: string[];
[key: string]: any;
}

Catalog 相关方法

registerCatalog

注册本地 catalog。

typescript
registerCatalog(catalog: Catalog): void

loadCatalog

加载 catalog(支持远程 URL 或本地注册的 schema)。

typescript
loadCatalog(catalogId: string): Promise<Catalog>

validateComponent

验证组件是否符合 catalog 定义。

typescript
validateComponent(catalog: Catalog, componentName: string, componentProps: Record<string, any>): boolean

clearCatalogCache

清除 catalog 缓存。

typescript
clearCatalogCache(): void
基础

使用 XCard 实现 A2UI v0.9 协议的基础示例。演示了如何使用 XAgentCommand_v0_9 命令配合本地 catalog.json 来创建咖啡预订场景的交互卡片。v0.9 版本引入了更简洁的命令结构和 catalog 机制。

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
渐进式

使用 XCard 实现 A2UI v0.9 协议的渐进式加载示例。演示了如何分批次加载产品数据,并通过 updateComponents 命令渐进式更新组件,配合加载指示器展示加载进度,实现流畅的加载体验。

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
流式渲染

使用 XCard 实现 A2UI v0.9 协议的流式内容与实时更新示例。演示了 AI 推荐结果的流式展示、组件逐步加载动画和加载进度指示,配合 catalog 机制。

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
嵌套交互

使用 XCard 实现 A2UI v0.9 协议的复杂交互与嵌套组件示例。演示了可展开的详情卡片、树形文件浏览器和手风琴折叠面板,配合 catalog 机制。

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
多卡片同步

使用 XCard 实现 A2UI v0.9 协议的多卡片协同与状态同步示例。演示了购物车场景中多个 Surface 之间的数据共享、跨卡片通信和实时价格计算,配合 catalog 机制。

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
筛选搜索

使用 XCard 实现 A2UI v0.9 协议的动态数据筛选与搜索示例。演示了如何使用 antd 组件配合 catalog 机制实现实时搜索、多条件筛选和结果动态更新。

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code
表单验证

使用 XCard 实现 A2UI v0.9 协议的表单验证与错误处理示例。演示了如何使用 antd Form 组件配合 catalog 机制实现实时验证、错误状态管理和多步骤表单流程。

CodeSandbox Icon
codepen icon
External Link Icon
expand codeexpand code