Skip to content

Commit

Permalink
DragAndDropHandler
Browse files Browse the repository at this point in the history
  • Loading branch information
mbraak committed Nov 14, 2023
1 parent b747ee3 commit 97c5ef6
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 24 deletions.
39 changes: 16 additions & 23 deletions src/dragAndDropHandler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ interface DragAndDropHandlerParams {
openNode: OpenNode;
refreshElements: RefreshElements;
slide: boolean;
$treeElement: JQuery<HTMLElement>;
treeElement: HTMLElement;
triggerEvent: TriggerEvent;
}

Expand All @@ -70,7 +70,7 @@ export class DragAndDropHandler {
private previousGhost: DropHint | null;
private refreshElements: RefreshElements;
private slide: boolean;
private $treeElement: JQuery<HTMLElement>;
private treeElement: HTMLElement;
private triggerEvent: TriggerEvent;

constructor({
Expand All @@ -87,7 +87,7 @@ export class DragAndDropHandler {
openNode,
refreshElements,
slide,
$treeElement,
treeElement,
triggerEvent,
}: DragAndDropHandlerParams) {
this.autoEscape = autoEscape;
Expand All @@ -103,7 +103,7 @@ export class DragAndDropHandler {
this.openNode = openNode;
this.refreshElements = refreshElements;
this.slide = slide;
this.$treeElement = $treeElement;
this.treeElement = treeElement;
this.triggerEvent = triggerEvent;

this.hoveredArea = null;
Expand Down Expand Up @@ -157,7 +157,7 @@ export class DragAndDropHandler {
nodeName: node.name,
offsetX: positionInfo.pageX - left,
offsetY: positionInfo.pageY - top,
treeElement: this.$treeElement.get(0) as HTMLElement,
treeElement: this.treeElement,
});

this.isDragging = true;
Expand Down Expand Up @@ -424,7 +424,8 @@ export class DragAndDropHandler {

if (tree) {
tree.moveNode(movedNode, targetNode, position);
this.$treeElement.empty();

this.treeElement.textContent = "";
this.refreshElements(null);
}
};
Expand All @@ -449,22 +450,14 @@ export class DragAndDropHandler {
private getTreeDimensions(): Dimensions {
// Return the dimensions of the tree. Add a margin to the bottom to allow
// to drag-and-drop after the last element.
const offset = this.$treeElement.offset();

if (!offset) {
return { left: 0, top: 0, right: 0, bottom: 0 };
} else {
const el = this.$treeElement;
const width = el.width() || 0;
const height = el.height() || 0;
const left = offset.left + this.getScrollLeft();

return {
left,
top: offset.top,
right: left + width,
bottom: offset.top + height + 16,
};
}
const left = this.treeElement.offsetLeft + this.getScrollLeft();
const top = this.treeElement.offsetTop;

return {
left,
top,
right: left + this.treeElement.clientWidth,
bottom: top + this.treeElement.clientHeight + 16,
};
}
}
3 changes: 2 additions & 1 deletion src/tree.jquery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1229,6 +1229,7 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
const refreshHitAreas = this.refreshHitAreas.bind(this);
const selectNode = this.selectNode.bind(this);
const $treeElement = this.element;
const treeElement = this.element.get(0) as HTMLElement;
const triggerEvent = this._triggerEvent.bind(this);

const selectNodeHandler = new SelectNodeHandler({
Expand Down Expand Up @@ -1280,7 +1281,7 @@ export class JqTreeWidget extends MouseWidget<JQTreeOptions> {
openNode,
refreshElements,
slide,
$treeElement,
treeElement,
triggerEvent,
});

Expand Down

0 comments on commit 97c5ef6

Please sign in to comment.