From cda3b04b85b02e572275d73d9c3981ba87981461 Mon Sep 17 00:00:00 2001 From: roymondchen Date: Thu, 31 Aug 2023 15:29:27 +0800 Subject: [PATCH] =?UTF-8?q?fix(editor):=20=E5=BD=93=E7=BB=84=E4=BB=B6?= =?UTF-8?q?=E8=AE=BE=E7=BD=AE=E7=9A=84bottom/right=E6=98=AF=EF=BC=8C?= =?UTF-8?q?=E4=B8=8A=E4=B8=8B=E5=B7=A6=E5=8F=B3=E5=BF=AB=E6=8D=B7=E9=94=AE?= =?UTF-8?q?=E5=A4=B1=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/editor/src/services/editor.ts | 52 ++++++++++++++++++++------ 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/packages/editor/src/services/editor.ts b/packages/editor/src/services/editor.ts index dafdf9a8..8bb0a32c 100644 --- a/packages/editor/src/services/editor.ts +++ b/packages/editor/src/services/editor.ts @@ -651,9 +651,11 @@ class Editor extends BaseService { const parentEl = layout === Layout.FIXED ? doc.body : el?.offsetParent; if (parentEl && el) { node.style.left = (parentEl.clientWidth - el.clientWidth) / 2; + node.style.right = ''; } } else if (parent.style && isNumber(parent.style?.width) && isNumber(node.style?.width)) { node.style.left = (parent.style.width - node.style.width) / 2; + node.style.right = ''; } return node; @@ -792,20 +794,46 @@ class Editor extends BaseService { if (!node || isPage(node)) return; const { style, id, type } = node; - if (!style || style.position !== 'absolute') return; + if (!style || !['absolute', 'fixed'].includes(style.position)) return; - if (top && !isNumber(style.top)) return; - if (left && !isNumber(style.left)) return; + const update = (style: { [key: string]: any }) => + this.update({ + id, + type, + style, + }); - this.update({ - id, - type, - style: { - ...style, - left: Number(style.left) + left, - top: Number(style.top) + top, - }, - }); + if (top) { + if (isNumber(style.top)) { + update({ + ...style, + top: Number(style.top) + Number(top), + bottom: '', + }); + } else if (isNumber(style.bottom)) { + update({ + ...style, + bottom: Number(style.bottom) - Number(top), + top: '', + }); + } + } + + if (left) { + if (isNumber(style.left)) { + update({ + ...style, + left: Number(style.left) + Number(left), + right: '', + }); + } else if (isNumber(style.right)) { + update({ + ...style, + right: Number(style.right) - Number(left), + left: '', + }); + } + } } public resetState() {