Skip to content

Commit dbe0764

Browse files
liujupingLeoYuan
authored andcommitted
feat: the tips when dragging a component from the component panel same with the moving component
1 parent 02f8f98 commit dbe0764

File tree

1 file changed

+23
-29
lines changed
  • packages/designer/src/designer/drag-ghost

1 file changed

+23
-29
lines changed

packages/designer/src/designer/drag-ghost/index.tsx

Lines changed: 23 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
import { Component } from 'react';
1+
import { Component, ReactElement } from 'react';
22
import { observer, obx, Title, makeObservable } from '@alilc/lowcode-editor-core';
33
import { Designer } from '../designer';
4-
import { DragObject, isDragNodeObject, isDragNodeDataObject } from '../dragon';
4+
import { DragObject, isDragNodeObject } from '../dragon';
55
import { isSimulatorHost } from '../../simulator';
66
import './ghost.less';
7+
import { I18nData, NodeSchema } from '@alilc/lowcode-types';
78

89
type offBinding = () => any;
910

1011
@observer
1112
export default class DragGhost extends Component<{ designer: Designer }> {
1213
private dispose: offBinding[] = [];
1314

14-
@obx.ref private dragObject: DragObject | null = null;
15+
@obx.ref private titles: (string | I18nData | ReactElement)[] | null = null;
1516

1617
@obx.ref private x = 0;
1718

@@ -29,7 +30,7 @@ export default class DragGhost extends Component<{ designer: Designer }> {
2930
if (e.originalEvent.type.slice(0, 4) === 'drag') {
3031
return;
3132
}
32-
this.dragObject = e.dragObject;
33+
this.titles = this.getTitles(e.dragObject);
3334
this.x = e.globalX;
3435
this.y = e.globalY;
3536
}),
@@ -46,49 +47,42 @@ export default class DragGhost extends Component<{ designer: Designer }> {
4647
this.isAbsoluteLayoutContainer = false;
4748
}),
4849
this.dragon.onDragend(() => {
49-
this.dragObject = null;
50+
this.titles = null;
5051
this.x = 0;
5152
this.y = 0;
5253
}),
5354
];
5455
}
5556

57+
getTitles(dragObject: DragObject) {
58+
if (isDragNodeObject(dragObject)) {
59+
return dragObject.nodes.map((node) => node.title);
60+
}
61+
62+
const dataList = Array.isArray(dragObject.data) ? dragObject.data : [dragObject.data];
63+
64+
return dataList.map((item: NodeSchema, i) => (this.props.designer.getComponentMeta(item.componentName).title));
65+
}
66+
5667
componentWillUnmount() {
5768
if (this.dispose) {
5869
this.dispose.forEach(off => off());
5970
}
6071
}
6172

6273
renderGhostGroup() {
63-
const { dragObject } = this;
64-
if (isDragNodeObject(dragObject)) {
65-
return dragObject.nodes.map(node => {
66-
const ghost = (
67-
<div className="lc-ghost" key={node.id}>
68-
<Title title={node.title} />
69-
</div>
70-
);
71-
return ghost;
72-
});
73-
} else if (isDragNodeDataObject(dragObject)) {
74-
return Array.isArray(dragObject.data) ? (
75-
dragObject.data.map((item, index) => {
76-
return (
77-
<div className="lc-ghost" key={`ghost-${index}`}>
78-
<div className="lc-ghost-title">{item.componentName}</div>
79-
</div>
80-
);
81-
})
82-
) : (
83-
<div className="lc-ghost">
84-
<div className="lc-ghost-title">{dragObject.data.componentName}</div>
74+
return this.titles?.map((title, i) => {
75+
const ghost = (
76+
<div className="lc-ghost" key={i}>
77+
<Title title={title} />
8578
</div>
8679
);
87-
}
80+
return ghost;
81+
});
8882
}
8983

9084
render() {
91-
if (!this.dragObject) {
85+
if (!this.titles || !this.titles.length) {
9286
return null;
9387
}
9488

0 commit comments

Comments
 (0)