# 容器与泳道

- Human documentation: [https://docs.univer.ai/zh-CN/guides/boards/features/core/containers](https://docs.univer.ai/zh-CN/guides/boards/features/core/containers)

- Agent Markdown: [https://docs.univer.ai/zh-CN/guides/boards/features/core/containers.md](https://docs.univer.ai/zh-CN/guides/boards/features/core/containers.md)

- Requested language: `zh-CN`

- Content language: `zh-CN`

- Documentation version: `1.0.0-rc.0`

- Source: [boards/features/core/containers.zh-CN.mdx](https://github.com/dream-num/documentation/blob/dev/content/guides/boards/features/core/containers.zh-CN.mdx)

---

容器让画板能够表示带边框的区域、泳道、UML 包块以及其他父子结构。容器的归属关系通过子元素的 `parentId` 存储；对于泳道，则还会使用 `laneId`。

## 创建容器

```ts
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')
}
```

## 将元素移入容器

```ts
board.moveElementsToContainer(['card-1', 'card-2'], containerId)
board.fitContainerToContent(containerId)
```

## 配置归属行为

```ts
board.setContainerMembershipLocked(containerId, true)
board.setContainerAutoResize(containerId, false)
```

## 泳道

泳道是带有分道配置的容器。使用专用的 facade API 可以添加、移除分道，调整分道大小与顺序，以及折叠和重命名分道。

```ts
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')
```
