容器与泳道
容器用于在画板上表示带边框的区域、泳道、UML 包块以及其他父子结构。容器的归属关系记录在子元素上:parentId 指向所属容器,泳道成员还会使用 laneId。
创建容器
TypeScript
const board = univerAPI.getActiveBoard()if (!board) throw new Error('No active Board')const containerId = 'scope'const containerCreated = board.createContainer({ id: containerId, title: 'Scope', left: 80, top: 80, width: 640, height: 360,})if (!containerCreated) { throw new Error('Cannot create container')}从画布插入容器
画布工具栏中的容器面板提供四个固定比例的预设磁贴:16:9、4:3、1:1 和 A4。分区标题旁还提供自定义容器操作,以及紧凑的纵向和横向泳道按钮。若要通过 API 创建,请使用 createContainer() 或 createSwimlane()。
将元素移入容器
TypeScript
board.moveElementsToContainer(['card-1', 'card-2'], containerId)board.fitContainerToContent(containerId)配置归属行为
TypeScript
board.setContainerMembershipLocked(containerId, true)board.setContainerAutoResize(containerId, false)泳道
泳道是带有分道配置的容器。专用的 facade API 可以添加、移除、调整分道大小、重排分道、折叠和重命名分道。
TypeScript
const swimlaneId = 'delivery'const swimlaneCreated = board.createSwimlane({ id: swimlaneId, left: 80, top: 80, width: 720, height: 360, orientation: 'horizontal', lanes: [ { id: 'todo', title: 'Todo', size: 240 }, { id: 'done', title: 'Done', size: 240 }, ],})if (!swimlaneCreated) { throw new Error('Cannot create swimlane')}board.renameSwimlaneLane(swimlaneId, 'todo', 'Backlog')你觉得这篇文档如何?