Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add slots fail #1141

Merged
merged 5 commits into from
Feb 26, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions packages/canvas/DesignCanvas/src/api/useCanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -472,14 +472,28 @@ const operationTypeMap = {
// 筛选出来新增的和修改的
const changedChildren = newChildren.filter(({ id }) => !deletedIdsSet.has(id))

changedChildren.forEach((childItem, index) => {
changedChildren.forEach((childItem) => {
// 新增
if (!originChildrenSet.has(childItem.id)) {
const newChildIndex = newChildren.findIndex(({ id }) => id === childItem.id)
let position = 'after'
let referTargetNodeId = null

// 1. 新节点 index === 0 (在最前面),插入位置为 before,插入到第一个
// 2. 新节点 index > 0,插入到 index -1 节点的后面。
// 3. 默认情况(index === -1):插入到数组最后一个节点。(position: after,referTargetNodeId: nuLl)
if (newChildIndex === 0) {
position = 'before'
} else if (newChildIndex !== -1) {
position = 'after'
referTargetNodeId = newChildren[newChildIndex - 1]?.id
}

operationTypeMap.insert({
parentId: id,
newNodeData: childItem,
position: 'after',
referTargetNodeId: changedChildren?.[index]?.id
position,
referTargetNodeId
})
return
}
Expand Down