fix: 复制时防止 ref 重复

This commit is contained in:
rainke 2023-10-13 16:57:26 +08:00 committed by 刘菊萍(絮黎)
parent d56ed6bff1
commit 96fe876e33

View File

@ -10,6 +10,14 @@ import {
} from './icons';
import { componentDefaults, legacyIssues } from './transducers';
function deduplicateRef(node: IPublicModelNode | null | undefined) {
const currentRef = node?.getPropValue('ref');
if (currentRef) {
node?.setPropValue('ref', `${node.componentName.toLowerCase()}-${Math.random().toString(36).slice(2, 9)}`);
}
node?.children?.forEach(deduplicateRef);
}
export class ComponentActions {
private metadataTransducers: IPublicTypeMetadataTransducer[] = [];
@ -53,6 +61,7 @@ export class ComponentActions {
const { document: doc, parent, index } = node;
if (parent) {
const newNode = doc?.insertNode(parent, node, (index ?? 0) + 1, true);
deduplicateRef(newNode);
newNode?.select();
const { isRGL, rglNode } = node?.getRGL();
if (isRGL) {