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: 修复空页面执行右键删除和右键复制时控制台报错的问题 #103

Merged
merged 11 commits into from
Nov 30, 2023
26 changes: 14 additions & 12 deletions packages/canvas/src/components/container/CanvasMenu.vue
Original file line number Diff line number Diff line change
Expand Up @@ -111,10 +111,10 @@ export default {

const operations = {
del() {
removeNodeById(getCurrent().schema.id)
removeNodeById(getCurrent().schema?.id)
gargameljyh marked this conversation as resolved.
Show resolved Hide resolved
},
copy() {
copyNode(getCurrent().schema.id)
copyNode(getCurrent().schema?.id)
},
config() {
useLayout().activeSetting('props')
Expand All @@ -128,17 +128,19 @@ export default {
wrap({ value, name }) {
const componentName = value || name
const { schema, parent } = getCurrent()
const index = parent.children.indexOf(schema)
const wrapSchema = {
componentName,
id: null,
props: {},
children: [schema]
if (schema && parent) {
const index = parent.children.indexOf(schema)
const wrapSchema = {
componentName,
id: null,
props: {},
children: [schema]
}

parent.children.splice(index, 1, wrapSchema)

getController().addHistory()
}

parent.children.splice(index, 1, wrapSchema)

getController().addHistory()
},
createBlock() {
if (useCanvas().isSaved()) {
Expand Down
3 changes: 3 additions & 0 deletions packages/canvas/src/components/container/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
})

export const getContext = () => {
return getRenderer().getContext()

Check failure on line 55 in packages/canvas/src/components/container/container.js

View workflow job for this annotation

GitHub Actions / push-check

'getRenderer' was used before it was defined
}

// 记录拖拽状态
Expand Down Expand Up @@ -110,7 +110,7 @@
// 如果element存在表示在iframe内部拖拽
dragState.element = element
dragState.offset = { offsetX, offsetY, horizontal, vertical, width, height, x, y }
clearHover()

Check failure on line 113 in packages/canvas/src/components/container/container.js

View workflow job for this annotation

GitHub Actions / push-check

'clearHover' was used before it was defined
}

export const clearLineState = () => {
Expand All @@ -130,7 +130,7 @@

// 重置拖拽插入位置状态
clearLineState()
smoothScroll.stop()

Check failure on line 133 in packages/canvas/src/components/container/container.js

View workflow job for this annotation

GitHub Actions / push-check

'smoothScroll' was used before it was defined
}

export const getOffset = (element) => {
Expand Down Expand Up @@ -209,9 +209,9 @@
return
}

removeNode(getNode(id, true))

Check failure on line 212 in packages/canvas/src/components/container/container.js

View workflow job for this annotation

GitHub Actions / push-check

'getNode' was used before it was defined
clearSelect()

Check failure on line 213 in packages/canvas/src/components/container/container.js

View workflow job for this annotation

GitHub Actions / push-check

'clearSelect' was used before it was defined
getController().addHistory()

Check failure on line 214 in packages/canvas/src/components/container/container.js

View workflow job for this annotation

GitHub Actions / push-check

'getController' was used before it was defined
canvasState.emit('remove')
}

Expand All @@ -237,19 +237,22 @@
}
}

select && setTimeout(() => selectNode(node.data.id))

Check failure on line 240 in packages/canvas/src/components/container/container.js

View workflow job for this annotation

GitHub Actions / push-check

'selectNode' was used before it was defined

getController().addHistory()

Check failure on line 242 in packages/canvas/src/components/container/container.js

View workflow job for this annotation

GitHub Actions / push-check

'getController' was used before it was defined
}

export const addComponent = (data, position) => {
const { schema, parent } = getCurrent()

Check failure on line 246 in packages/canvas/src/components/container/container.js

View workflow job for this annotation

GitHub Actions / push-check

'getCurrent' was used before it was defined

insertNode({ node: schema, parent, data }, position)
}

export const copyNode = (id) => {
if (!id) {
return
}
const { node, parent } = getNode(id, true)

Check failure on line 255 in packages/canvas/src/components/container/container.js

View workflow job for this annotation

GitHub Actions / push-check

'getNode' was used before it was defined

inserAfter({ parent, node, data: copyObject(node) })
getController().addHistory()
Expand Down