diff --git a/packages/core/src/models/DragSource.ts b/packages/core/src/models/DragSource.ts index 069bd3ea4..ecfd7333d 100644 --- a/packages/core/src/models/DragSource.ts +++ b/packages/core/src/models/DragSource.ts @@ -1,11 +1,20 @@ +import { each, uid } from '@designable/shared' import { TreeNode, ITreeNode } from './TreeNode' export class DragSource { tree: TreeNode + prefix: string constructor() { this.tree = new TreeNode({ componentName: 'SourceRoot', }) + this.prefix = uid() + } + + setSources(sources: Record) { + each(sources, (data, group) => { + this.setSourcesByGroup(group, data) + }) } setSourcesByGroup(group: string, sources: ITreeNode[]) { @@ -16,7 +25,7 @@ export class DragSource { } else { const newParent = new TreeNode({ componentName: 'SourceGroup', - id: group, + id: `${this.prefix}_${group}`, }) newParent.setNodeChildren(...nodes) this.tree.appendNode(newParent) @@ -31,7 +40,7 @@ export class DragSource { } else { const newParent = new TreeNode({ componentName: 'SourceGroup', - id: group, + id: `${this.prefix}_${group}`, }) newParent.setNodeChildren(...nodes) this.tree.appendNode(newParent) @@ -39,7 +48,7 @@ export class DragSource { } getSourcesByGroup(group: string) { - const parent = this.tree.findById(group) + const parent = this.tree.findById(`${this.prefix}_${group}`) return parent?.children } @@ -54,7 +63,7 @@ export class DragSource { } reduceSourcesByGroup( - id: string, + group: string, callback?: ( previousValue: T, currentValue: TreeNode, @@ -63,7 +72,7 @@ export class DragSource { ) => T, init?: T ) { - const sources = this.getSourcesByGroup(id) + const sources = this.getSourcesByGroup(group) return sources?.reduce?.(callback, init) } } diff --git a/packages/react/src/widgets/DragSourceWidget/index.tsx b/packages/react/src/widgets/DragSourceWidget/index.tsx index 2080422bf..86101c984 100644 --- a/packages/react/src/widgets/DragSourceWidget/index.tsx +++ b/packages/react/src/widgets/DragSourceWidget/index.tsx @@ -59,7 +59,7 @@ export const DragSourceWidget: React.FC = observer(
- {props.title} + {props.title || `sources.${props.name}`}