mirror of
https://github.com/smartxworks/sunmao-ui.git
synced 2024-11-27 08:39:59 +08:00
Merge pull request #235 from webzard-io/fix/ui-tree
fix(editor): forbid drop to component which has no slots
This commit is contained in:
commit
8399882243
@ -160,6 +160,7 @@ export const ComponentTree: React.FC<Props> = props => {
|
||||
<DropComponentWrapper
|
||||
onCreateComponent={onCreateComponent}
|
||||
onMoveComponent={onMoveComponent}
|
||||
droppable={slots.length !== 0}
|
||||
>
|
||||
<ComponentItemView
|
||||
id={component.id}
|
||||
|
@ -3,12 +3,21 @@ import { Box } from '@chakra-ui/react';
|
||||
type Props = {
|
||||
onCreateComponent: (componentType: string) => void;
|
||||
onMoveComponent: (from: string) => void;
|
||||
droppable?: boolean;
|
||||
};
|
||||
|
||||
export const DropComponentWrapper: React.FC<Props> = props => {
|
||||
const {
|
||||
onCreateComponent,
|
||||
onMoveComponent,
|
||||
droppable = true
|
||||
} = props;
|
||||
|
||||
const onDragOver = (e: React.DragEvent) => {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
if (droppable) {
|
||||
e.preventDefault();
|
||||
e.stopPropagation();
|
||||
}
|
||||
};
|
||||
|
||||
const onDrop = (e: React.DragEvent) => {
|
||||
@ -18,11 +27,11 @@ export const DropComponentWrapper: React.FC<Props> = props => {
|
||||
const movingComponent = e.dataTransfer?.getData('moveComponent') || '';
|
||||
|
||||
if (movingComponent) {
|
||||
props.onMoveComponent(movingComponent)
|
||||
onMoveComponent(movingComponent);
|
||||
}
|
||||
|
||||
if (creatingComponent) {
|
||||
props.onCreateComponent(creatingComponent);
|
||||
onCreateComponent(creatingComponent);
|
||||
}
|
||||
};
|
||||
return (
|
||||
|
Loading…
Reference in New Issue
Block a user