fix(amis-editor): 优化reGenerateID逻辑

This commit is contained in:
wibetter 2023-12-26 18:53:17 +08:00
parent a151561269
commit 377db11b7c
4 changed files with 32 additions and 18 deletions

View File

@ -535,9 +535,9 @@ export default class Editor extends Component<EditorProps> {
);
if (this.store.activeId === this.curCopySchemaData.$$id) {
// 复制和粘贴是同一个元素,则直接追加到当前元素后面
this.manager.appendSiblingSchema(reGenerateID(curSimpleSchema));
this.manager.appendSiblingSchema(reGenerateID(curSimpleSchema), false);
} else {
this.manager.addElem(reGenerateID(curSimpleSchema));
this.manager.addElem(reGenerateID(curSimpleSchema), false);
}
}
}

View File

@ -923,7 +923,13 @@ export class EditorManager {
!isSpecialLayout
) {
// 布局能力提升: 点击插入新元素当wrapper为空插入布局容器时自动改为置换避免过多层级
this.replaceChild(curActiveId, curElemSchema);
this.replaceChild(
curActiveId,
curElemSchema,
subRenderer,
store.insertRegion,
reGenerateId
);
setTimeout(() => {
this.updateConfigPanel();
}, 0);
@ -1009,7 +1015,7 @@ export class EditorManager {
regionNodeRegion,
value,
nextId,
subRenderer,
subRenderer || node.info,
{
id: store.dragId,
type: store.dragType,
@ -1055,7 +1061,8 @@ export class EditorManager {
async appendSiblingSchema(
rendererSchema: Object,
beforeInsert?: boolean,
disabledAutoSelectInsertElem?: boolean
disabledAutoSelectInsertElem?: boolean,
reGenerateId?: boolean
) {
if (!rendererSchema) {
return;
@ -1113,7 +1120,14 @@ export class EditorManager {
regionNodeId,
regionNodeRegion,
rendererSchema,
nextId
nextId,
node.info,
{
id: store.dragId,
type: store.dragType,
data: store.dragSchema
},
reGenerateId
);
if (child && !disabledAutoSelectInsertElem) {
// mobx 修改数据是异步的
@ -1542,7 +1556,7 @@ export class EditorManager {
region: string,
json: any,
beforeId?: string,
subRenderer?: SubRendererInfo,
subRenderer?: SubRendererInfo | RendererInfo,
dragInfo?: {
id: string;
type: string;
@ -1625,7 +1639,7 @@ export class EditorManager {
replaceChild(
id: string,
json: any,
subRenderer?: SubRendererInfo,
subRenderer?: SubRendererInfo | RendererInfo,
region?: string,
reGenerateId?: boolean
): boolean {

View File

@ -529,7 +529,7 @@ export interface InsertEventContext extends BaseEventContext {
beforeId?: string;
index: number;
data: any;
subRenderer?: SubRendererInfo;
subRenderer?: SubRendererInfo | RendererInfo;
dragInfo?: {
id: string;
type: string;
@ -539,7 +539,7 @@ export interface InsertEventContext extends BaseEventContext {
export interface ReplaceEventContext extends BaseEventContext {
data: any;
subRenderer?: SubRendererInfo;
subRenderer?: SubRendererInfo | RendererInfo;
region?: string;
}

View File

@ -586,14 +586,14 @@ export function reGenerateID(
JSONTraverse(json, (value: any, key: string, host: any) => {
const isNodeIdFormat =
typeof value === 'string' && value.indexOf('u:') === 0;
if (key === 'id' && isNodeIdFormat && host) {
if ((key === 'id' || key === 'componentId') && isNodeIdFormat && host) {
if (reIds[value]) {
host[key] = reIds[value];
} else {
const newID = generateNodeId();
reIds[host.id] = newID;
host.id = newID;
reIds[value] = newID;
host[key] = newID;
}
// 组件ID给新的id内容
else if (key === 'componentId' && isNodeIdFormat) {
host.componentId = reIds[value] ?? value;
}
return value;