From ce0c941bf15987b01cf4949dea57313486768ed9 Mon Sep 17 00:00:00 2001 From: roymondchen Date: Mon, 13 Nov 2023 20:01:32 +0800 Subject: [PATCH] =?UTF-8?q?fix(editor):=20=E5=9C=A8=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E6=A0=91=E5=B0=86=E7=BB=84=E4=BB=B6=E6=8B=96=E5=85=A5=E4=B8=8D?= =?UTF-8?q?=E5=90=8C=E5=B8=83=E5=B1=80=E7=9A=84=E5=AE=B9=E5=99=A8=E5=86=85?= =?UTF-8?q?=EF=BC=8C=E9=9C=80=E8=A6=81=E6=94=B9=E5=8F=98=E5=85=B6=E5=B8=83?= =?UTF-8?q?=E5=B1=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fix #552 --- packages/editor/src/services/editor.ts | 13 ++++++++-- packages/editor/src/utils/editor.ts | 35 +++++++++++++++----------- 2 files changed, 31 insertions(+), 17 deletions(-) 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 = {