diff --git a/packages/editor/src/services/editor.ts b/packages/editor/src/services/editor.ts index d8882845..04c13763 100644 --- a/packages/editor/src/services/editor.ts +++ b/packages/editor/src/services/editor.ts @@ -36,6 +36,7 @@ import { getInitPositionStyle, getNodeIndex, isFixed, + setChilrenLayout, setLayout, } from '@editor/utils/editor'; import { beforePaste, getAddParent } from '@editor/utils/operator'; @@ -510,8 +511,8 @@ class Editor extends BaseService { const newLayout = await this.getLayout(newConfig); const layout = await this.getLayout(node); - if (newLayout !== layout) { - newConfig = setLayout(newConfig, newLayout); + if (Array.isArray(newConfig.items) && newLayout !== layout) { + newConfig = setChilrenLayout(newConfig as MContainer, newLayout); } parentNodeItems[index] = newConfig; @@ -788,7 +789,15 @@ class Editor extends BaseService { } } + const layout = await this.getLayout(parent); + const newLayout = await this.getLayout(targetParent); + + if (newLayout !== layout) { + setLayout(config, newLayout); + } + parent.items?.splice(index, 1); + targetParent.items?.splice(targetIndex, 0, config); const page = this.get('page'); diff --git a/packages/editor/src/utils/editor.ts b/packages/editor/src/utils/editor.ts index a554dab1..6946abd0 100644 --- a/packages/editor/src/utils/editor.ts +++ b/packages/editor/src/utils/editor.ts @@ -129,26 +129,31 @@ export const getInitPositionStyle = (style: Record = {}, layout: La return style; }; -export const setLayout = (node: MNode, layout: Layout) => { +export const setChilrenLayout = (node: MContainer, layout: Layout) => { node.items?.forEach((child: MNode) => { - if (isPop(child)) return; - - const style = child.style || {}; - - // 是 fixed 不做处理 - if (style.position === 'fixed') return; - - if (layout !== Layout.RELATIVE) { - style.position = 'absolute'; - } else { - child.style = getRelativeStyle(style); - child.style.right = 'auto'; - child.style.bottom = 'auto'; - } + setLayout(child, layout); }); return node; }; +export const setLayout = (node: MNode, layout: Layout) => { + if (isPop(node)) return; + + const style = node.style || {}; + + // 是 fixed 不做处理 + if (style.position === 'fixed') return; + + if (layout !== Layout.RELATIVE) { + style.position = 'absolute'; + } else { + node.style = getRelativeStyle(style); + node.style.right = 'auto'; + node.style.bottom = 'auto'; + } + return node; +}; + export const change2Fixed = (node: MNode, root: MApp) => { const path = getNodePath(node.id, root.items); const offset = {