Skip to content

Commit

Permalink
fix(editor): 组件配置width为100%时,水平居中失效
Browse files Browse the repository at this point in the history
  • Loading branch information
roymondchen authored and jia000 committed May 27, 2022
1 parent 9addbdd commit 4a19017
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion packages/editor/src/services/editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,6 +194,20 @@ class Editor extends BaseService {
historyService.empty();
}

if (node?.id) {
this.get<StageCore>('stage')
?.renderer.runtime?.getApp?.()
?.emit(
'editor:select',
{
node,
page,
parent,
},
getNodePath(node.id, this.get<MApp>('root').items),
);
}

this.emit('select', node);

return node!;
Expand Down Expand Up @@ -504,7 +518,18 @@ class Editor extends BaseService {
return;
}

if (parent.style?.width && node.style?.width) {
if (!node.style) return;

const stage = this.get<StageCore>('stage');
const doc = stage?.renderer.contentWindow?.document;

if (doc) {
const parentEl = doc.getElementById(`${parent.id}`);
const el = doc.getElementById(`${node.id}`);
if (parentEl && el) {
node.style.left = (parentEl.clientWidth - el.clientWidth) / 2;
}
} else if (parent.style && isNumber(parent.style?.width) && isNumber(node.style?.width)) {
node.style.left = (parent.style.width - node.style.width) / 2;
}

Expand Down

0 comments on commit 4a19017

Please sign in to comment.