mirror of
https://gitee.com/baidu/amis.git
synced 2024-12-02 03:48:13 +08:00
fix(amis-editor): 优化reGenerateID逻辑
This commit is contained in:
parent
a151561269
commit
377db11b7c
@ -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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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 {
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
|
Loading…
Reference in New Issue
Block a user