fix: 🐛 add updateCellId api (#1739)
This commit is contained in:
@@ -496,6 +496,10 @@ export class Graph extends Basecoat<EventArgs> {
|
||||
return result
|
||||
}
|
||||
|
||||
updateCellId(cell: Cell, newId: string) {
|
||||
return this.model.updateCellId(cell, newId)
|
||||
}
|
||||
|
||||
// #endregion
|
||||
|
||||
// #region view
|
||||
|
@@ -306,6 +306,36 @@ export class Model extends Basecoat<Model.EventArgs> {
|
||||
return null
|
||||
}
|
||||
|
||||
updateCellId(cell: Cell, newId: string) {
|
||||
this.startBatch('update', { id: newId })
|
||||
cell.prop('id', newId)
|
||||
const newCell = cell.clone({ keepId: true })
|
||||
this.addCell(newCell)
|
||||
|
||||
// update connected edge terminal
|
||||
const edges = this.getConnectedEdges(cell)
|
||||
edges.forEach((edge) => {
|
||||
const sourceCell = edge.getSourceCell()
|
||||
const targetCell = edge.getTargetCell()
|
||||
if (sourceCell === cell) {
|
||||
edge.setSource({
|
||||
...edge.getSource(),
|
||||
cell: newId,
|
||||
})
|
||||
}
|
||||
if (targetCell === cell) {
|
||||
edge.setTarget({
|
||||
...edge.getTarget(),
|
||||
cell: newId,
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
this.removeCell(cell)
|
||||
this.startBatch('update', { id: newId })
|
||||
return newCell
|
||||
}
|
||||
|
||||
removeCells(cells: (Cell | string)[], options: Cell.RemoveOptions = {}) {
|
||||
if (cells.length) {
|
||||
return this.batchUpdate('remove', () => {
|
||||
|
@@ -282,6 +282,21 @@ getCellById(id: string)
|
||||
|------|--------|:----:|--------|-------------|
|
||||
| cell | string | ✓ | | 节点/边的 ID。 |
|
||||
|
||||
### updateCellId(...)
|
||||
|
||||
```sign
|
||||
updateCellId(cell: Cell, newId: string)
|
||||
```
|
||||
|
||||
更新节点或者边的 ID,会返回新创建的节点/边。
|
||||
|
||||
<span class="tag-param">参数<span>
|
||||
|
||||
| 名称 | 类型 | 必选 | 默认值 | 描述 |
|
||||
|------|--------|:----:|--------|-------------|
|
||||
| cell | Cell | ✓ | | 节点/边。 |
|
||||
| newId |string | ✓ | | 新的 ID。 |
|
||||
|
||||
### getCells()
|
||||
|
||||
```sign
|
||||
|
@@ -282,6 +282,21 @@ getCellById(id: string)
|
||||
|------|--------|:----:|--------|-------------|
|
||||
| cell | string | ✓ | | 节点/边的 ID。 |
|
||||
|
||||
### updateCellId(...)
|
||||
|
||||
```sign
|
||||
updateCellId(cell: Cell, newId: string)
|
||||
```
|
||||
|
||||
更新节点或者边的 ID,会返回新创建的节点/边。
|
||||
|
||||
<span class="tag-param">参数<span>
|
||||
|
||||
| 名称 | 类型 | 必选 | 默认值 | 描述 |
|
||||
|------|--------|:----:|--------|-------------|
|
||||
| cell | Cell | ✓ | | 节点/边。 |
|
||||
| newId |string | ✓ | | 新的 ID。 |
|
||||
|
||||
### getCells()
|
||||
|
||||
```sign
|
||||
|
Reference in New Issue
Block a user