Skip to content

Commit

Permalink
fix: add default fallback for changeProps
Browse files Browse the repository at this point in the history
  • Loading branch information
chilingling committed Dec 3, 2024
1 parent e335ce7 commit 4ae4714
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 40 deletions.
8 changes: 4 additions & 4 deletions packages/canvas/DesignCanvas/src/DesignCanvas.vue
Original file line number Diff line number Diff line change
Expand Up @@ -140,11 +140,11 @@ export default {
const { getSchema, getNodePath } = useCanvas()
const schemaItem = useCanvas().getNodeById(id)
const schema = getSchema()
const pageSchema = getSchema()
// 如果选中的节点是画布,就设置成默认选中最外层schema
// TODO: 将 canvas 的 schema 改成 pageState 的 schema
useProperties().getProps(schemaItem || schema, parent)
useCanvas().setCurrentSchema(schemaItem || schema)
useProperties().getProps(schemaItem || pageSchema, parent)
useCanvas().setCurrentSchema(schemaItem || pageSchema)
footData.value = getNodePath(schemaItem?.id)
toolbars.visiblePopover = false
}
Expand Down
9 changes: 7 additions & 2 deletions packages/canvas/DesignCanvas/src/api/useCanvas.js
Original file line number Diff line number Diff line change
Expand Up @@ -348,12 +348,12 @@ const operationTypeMap = {
},
changeProps: (operation) => {
const { id, value, option: changeOption } = operation
const { node } = getNode(id, true) || {}
let { node } = getNode(id, true) || {}
const previous = deepClone(node)
const { overwrite = false } = changeOption || {}

if (!node) {
return
node = pageState.pageSchema
}

if (overwrite) {
Expand Down Expand Up @@ -451,6 +451,11 @@ const operationTypeMap = {

const lastUpdateType = ref('')

/**
* @experimental
* @param {*} operation
* @returns
*/
const operateNode = async (operation) => {
if (!operationTypeMap[operation.type]) {
return
Expand Down
38 changes: 25 additions & 13 deletions packages/canvas/render/src/RenderMain.js
Original file line number Diff line number Diff line change
Expand Up @@ -383,13 +383,6 @@ export default {
}
})

onUnmounted(() => {
window.host.unsubscribe({
topic: 'schemaChange',
subscriber: 'canvasRenderer'
})
})

watch(data, () => {
locale.value = data.value
})
Expand Down Expand Up @@ -422,35 +415,54 @@ export default {
}
)

window.host.watch(
const utilsWatchCanceler = window.host.watch(
() => window.host.appSchema?.utils,
(data) => {
setUtils(data)
},
{
immediate: true
immediate: true,
deep: true
}
)

window.host.watch(
const dataSourceWatchCanceler = window.host.watch(
() => window.host.appSchema?.dataSource,
(data) => {
setDataSourceMap(data)
},
{
immediate: true
immediate: true,
deep: true
}
)

window.host.watch(
const globalStateWatchCanceler = window.host.watch(
() => window.host.appSchema?.globalState,
(data) => {
setGlobalState(data)
},
{
immediate: true
immediate: true,
deep: true
}
)

onUnmounted(() => {
window.host.unsubscribe({
topic: 'schemaChange',
subscriber: 'canvasRenderer'
})

window.host.unsubscribe({
topic: 'schemaImport',
subscriber: 'canvasRenderer'
})

utilsWatchCanceler()
dataSourceWatchCanceler()
globalStateWatchCanceler()
})
},

render() {
Expand Down
10 changes: 2 additions & 8 deletions packages/register/src/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,7 @@ export const preprocessRegistry = (registry) => {
})
}

const maxDepth = 25

export const generateRegistry = (registry, depth = 1) => {
if (depth > maxDepth) {
return
}

export const generateRegistry = (registry) => {
Object.entries(registry).forEach(([key, value]) => {
if (typeof value === 'object' && value) {
const { id } = value
Expand All @@ -177,7 +171,7 @@ export const generateRegistry = (registry, depth = 1) => {
// TODO: 其他类型配置处理
}

generateRegistry(value, depth + 1)
generateRegistry(value)
}
})
}
Expand Down
14 changes: 1 addition & 13 deletions packages/settings/props/src/composable/useProperties.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
*
*/

import { toRaw, nextTick, shallowReactive, ref } from 'vue'
import { toRaw, shallowReactive, ref } from 'vue'
import { constants } from '@opentiny/tiny-engine-utils'
import { useCanvas, useMaterial, useTranslate } from '@opentiny/tiny-engine-meta-register'

Expand Down Expand Up @@ -139,19 +139,7 @@ const setProp = (name, value, type) => {
option: { overwrite }
})

const { updateRect } = useCanvas().canvasApi.value || {}

// 没有父级,或者不在节点上面,要更新内容。就用setState
// TODO: 确认相关场景还有没有用,没用删除
// getNodeWithParentById(properties.schema.id)?.parent || setState(useCanvas().getPageSchema().state)
propsUpdateKey.value++

// 更新根节点props不用updateRect
if (!properties.schema.id) {
return
}

nextTick(updateRect)
}

const getProp = (key) => {
Expand Down

0 comments on commit 4ae4714

Please sign in to comment.