Skip to content

Commit

Permalink
fix: 复制时防止 ref 重复
Browse files Browse the repository at this point in the history
  • Loading branch information
rainke authored and liujuping committed Oct 18, 2023
1 parent d56ed6b commit 96fe876
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions packages/designer/src/component-actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = [];

Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 96fe876

Please sign in to comment.