Skip to content

Commit

Permalink
Remove jquery from DragElement
Browse files Browse the repository at this point in the history
  • Loading branch information
mbraak committed Nov 14, 2023
1 parent 61b433d commit b747ee3
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 13 deletions.
22 changes: 10 additions & 12 deletions src/dragAndDropHandler/dragElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,38 +3,36 @@ interface DragElementParams {
nodeName: string;
offsetX: number;
offsetY: number;
$tree: JQuery;
treeElement: HTMLElement;
}

class DragElement {
private offsetX: number;
private offsetY: number;
private $element: JQuery<HTMLElement>;
private element: HTMLElement;

constructor({
autoEscape,
nodeName,
offsetX,
offsetY,
$tree,
treeElement,
}: DragElementParams) {
this.offsetX = offsetX;
this.offsetY = offsetY;

this.$element = this.createElement(nodeName, autoEscape);
this.element = this.createElement(nodeName, autoEscape);

$tree.append(this.$element);
treeElement.appendChild(this.element);
}

public move(pageX: number, pageY: number): void {
this.$element.offset({
left: pageX - this.offsetX,
top: pageY - this.offsetY,
});
this.element.style.left = `${pageX - this.offsetX}px`;
this.element.style.top = `${pageY - this.offsetY}px`;
}

public remove(): void {
this.$element.remove();
this.element.remove();
}

private createElement(nodeName: string, autoEscape: boolean) {
Expand All @@ -47,9 +45,9 @@ class DragElement {
element.innerHTML = nodeName;

Check warning on line 45 in src/dragAndDropHandler/dragElement.ts

View check run for this annotation

Codecov / codecov/patch

src/dragAndDropHandler/dragElement.ts#L44-L45

Added lines #L44 - L45 were not covered by tests
}

element.style.pointerEvents = "absolute";
element.style.position = "absolute";

return jQuery(element);
return element;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/dragAndDropHandler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export class DragAndDropHandler {
nodeName: node.name,
offsetX: positionInfo.pageX - left,
offsetY: positionInfo.pageY - top,
$tree: this.$treeElement,
treeElement: this.$treeElement.get(0) as HTMLElement,
});

this.isDragging = true;
Expand Down

0 comments on commit b747ee3

Please sign in to comment.