feat: 组件id重复后,重新赋值 (#10943)

Co-authored-by: qinhaoyan <30946345+qinhaoyan@users.noreply.github.com>
This commit is contained in:
qkiroc 2024-09-23 14:00:57 +08:00 committed by GitHub
parent a97bf77ee6
commit 9180df9dcd
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 15 additions and 3 deletions

View File

@ -1879,6 +1879,7 @@ export class EditorManager {
this.patching = true;
this.patchingInvalid = false;
const batch: Array<{id: string; value: any}> = [];
const ids = new Map();
let patchList = (list: Array<EditorNodeType>) => {
// 深度优先
list.forEach((node: EditorNodeType) => {
@ -1887,9 +1888,14 @@ export class EditorManager {
}
if (isAlive(node) && !node.isRegion) {
node.patch(this.store, force, (id, value) =>
batch.unshift({id, value})
const schema = node.schema;
node.patch(
this.store,
force,
(id, value) => batch.unshift({id, value}),
ids
);
ids.set(schema.id, true);
}
});
};

View File

@ -698,7 +698,8 @@ export const EditorNode = types
patch(
store: any,
force = false,
setPatchInfo?: (id: string, value: any) => void
setPatchInfo?: (id: string, value: any) => void,
ids?: Map<string, boolean>
) {
// 避免重复 patch
if (self.patched && !force) {
@ -720,6 +721,11 @@ export const EditorNode = types
patched = {...patched, id: 'u:' + guid()};
}
// id重复了重新生成一个
if (ids?.has(patched.id)) {
patched = {...patched, id: 'u:' + guid()};
}
if (
(Array.isArray(info.regions) && info.regions.length) ||
Array.isArray(info.patchContainers)