Skip to content
This repository has been archived by the owner on Oct 23, 2023. It is now read-only.

Commit

Permalink
feat: select dragged element on drag start
Browse files Browse the repository at this point in the history
  • Loading branch information
marionebl authored and tilmx committed May 28, 2018
1 parent a55a00f commit 10ee949
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 13 deletions.
18 changes: 7 additions & 11 deletions src/container/element-list/element-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -106,8 +106,6 @@ export class ElementList extends React.Component {
}

private handleDragEnd(e: React.DragEvent<HTMLElement>): void {
this.setState({ dragging: false });

if (this.dragImg && this.dragImg.parentNode) {
this.dragImg.parentNode.removeChild(this.dragImg);
}
Expand Down Expand Up @@ -160,30 +158,30 @@ export class ElementList extends React.Component {
}

private handleDragStart(e: React.DragEvent<HTMLElement>): void {
const element = elementFromTarget(e.target, { sibling: false });
const store = Store.ViewStore.getInstance();
const draggedElement = elementFromTarget(e.target, { sibling: false });

if (!element) {
if (!draggedElement) {
e.preventDefault();
return;
}

if (element.isNameEditable()) {
if (draggedElement.isNameEditable()) {
e.preventDefault();
return;
}

this.setState({ dragging: true });
draggedElement.setDragged(true);
store.setSelectedElement(draggedElement);

const dragImg = document.createElement('div');
dragImg.textContent = element.getName();
dragImg.textContent = draggedElement.getName();
dragImg.setAttribute('style', DRAG_IMG_STYLE);
document.body.appendChild(dragImg);

e.dataTransfer.effectAllowed = 'copy';
e.dataTransfer.setDragImage(dragImg, 75, 15);
this.dragImg = dragImg;

element.setDragged(true);
}

private handleDrop(e: React.DragEvent<HTMLElement>): void {
Expand Down Expand Up @@ -291,7 +289,6 @@ export class ElementList extends React.Component {

if (element) {
element.setHighlighted(false);
this.setState({ dragging: true });
}
}

Expand All @@ -310,7 +307,6 @@ export class ElementList extends React.Component {

if (label && element) {
element.setHighlighted(true);
this.setState({ dragging: false });
}
}

Expand Down
3 changes: 1 addition & 2 deletions src/preview/preview.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import * as uuid from 'uuid';
Mobx.extras.shareGlobalState();

declare var renderer: Types.Renderer;
declare var preview: HTMLElement;

interface InitialData {
data: {
Expand Down Expand Up @@ -146,7 +145,7 @@ function main(): void {
onOutsideClick,
store
},
preview
document.getElementById('preview') as HTMLElement
);
};

Expand Down

0 comments on commit 10ee949

Please sign in to comment.