fix(布局能力提升amis-saas-7924): 当wrapper为空插入布局容器时,自动改为置换

Change-Id: Icafb6c50d53ebcb876f82e5f75ca3168ab7989d1
This commit is contained in:
wibetter 2022-11-04 14:03:08 +08:00
parent 752fcdba34
commit cef36b0c62
3 changed files with 18 additions and 11 deletions

View File

@ -590,6 +590,7 @@
&.ae-AppendChild {
pointer-events: all;
position: absolute;
margin: 0;
background: $Editor-hlbox-bg;
width: 20px;
height: 20px;
@ -640,8 +641,8 @@
}
&.ae-AppendChild {
top: 10px;
right: 10px;
top: 5px;
right: 5px;
left: auto;
bottom: auto;
transform: none;
@ -1267,13 +1268,9 @@
margin: 0 6px;
}
}
// 区域仅有 [内容区]也展示头部标签
> div.region-tip.is-only-child-region {
top: -19px;
border-radius: 3px 3px 0 0;
}
// 兼容方案避免便签被遮挡
// 兼容方案避免便签被遮挡: 区域仅有 [内容区]头部标签放内部展示
> div.region-tip.is-only-child-region,
&.region-label-within > .region-tip {
top: 1px;
border-radius: 0 0 3px 3px;

View File

@ -101,10 +101,11 @@ export class RegionWrapper extends React.Component<RegionWrapperProps> {
}
render() {
const isLayoutItem = this.props.rendererName === 'wrapper' || this.props.rendererName === 'container';
return (
<EditorNodeContext.Provider value={this.editorNode}>
{this.props.children}
<span className={`ae-Region-placeholder ${this.props.rendererName === 'wrapper' ? 'layout-content' : ''}`}>
<span className={`ae-Region-placeholder ${isLayoutItem ? 'layout-content' : ''}`}>
{this.props.placeholder || this.props.label}
</span>
</EditorNodeContext.Provider>

View File

@ -726,7 +726,7 @@ export class EditorManager {
* @param rendererIdOrSchema
* ID添加新元素schema片段添加新元素
*/
async addElem(rendererIdOrSchema: string | Object) {
async addElem(rendererIdOrSchema: string | any) {
if (!rendererIdOrSchema) {
return;
}
@ -758,6 +758,15 @@ export class EditorManager {
toast.warning('请先选择一个元素作为插入的位置。');
return;
}
if (node.type === 'wrapper'
&& node.schema?.body?.length === 0
&& (schemaData?.type === 'flex' || subRenderer?.rendererName === 'flex')) {
const newSchemaData = schemaData || subRenderer?.scaffold;
// 布局能力提升: 点击插入新元素当wrapper为空插入布局容器时自动改为置换避免过多层级
this.replaceChild(id, newSchemaData);
}
const parentNode = node.parent as EditorNodeType; // 父级节点
// 插入新元素需要的字段