Skip to content

Commit

Permalink
Remove Position none
Browse files Browse the repository at this point in the history
  • Loading branch information
mbraak committed Dec 26, 2024
1 parent b011d0f commit 264d47c
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 32 deletions.
22 changes: 13 additions & 9 deletions src/dragAndDropHandler/generateHitAreas.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { HitArea } from "./types";

interface HitPosition {
node: Node;
position: Position;
position: null | Position;
top: number;
}

Expand All @@ -16,7 +16,11 @@ export const generateHitPositions = (
const hitPositions: HitPosition[] = [];
let lastTop = 0;

const addHitPosition = (node: Node, position: Position, top: number) => {
const addHitPosition = (
node: Node,
position: null | Position,
top: number,
) => {
hitPositions.push({
node,
position,
Expand All @@ -28,7 +32,7 @@ export const generateHitPositions = (
const handleAfterOpenFolder = (node: Node, nextNode: Node | null) => {
if (node === currentNode || nextNode === currentNode) {
// Cannot move before or after current item
addHitPosition(node, "none", lastTop);
addHitPosition(node, null, lastTop);

Check warning on line 35 in src/dragAndDropHandler/generateHitAreas.ts

View check run for this annotation

Codecov / codecov/patch

src/dragAndDropHandler/generateHitAreas.ts#L35

Added line #L35 was not covered by tests
} else {
addHitPosition(node, "after", lastTop);
}
Expand All @@ -43,7 +47,7 @@ export const generateHitPositions = (

if (node === currentNode) {
// Cannot move after current item
addHitPosition(node, "none", top);
addHitPosition(node, null, top);
} else {
addHitPosition(node, "inside", top);

Expand All @@ -69,14 +73,14 @@ export const generateHitPositions = (

if (node === currentNode) {
// Cannot move inside current item
addHitPosition(node, "none", top);
addHitPosition(node, null, top);
} else {
addHitPosition(node, "inside", top);
}

if (nextNode === currentNode || node === currentNode) {
// Cannot move before or after current item
addHitPosition(node, "none", top);
addHitPosition(node, null, top);
} else {
addHitPosition(node, "after", top);
}
Expand All @@ -89,11 +93,11 @@ export const generateHitPositions = (
// Dnd over the current element is not possible: add a position with type None for the top and the bottom.
const top = getOffsetTop(element);
const height = element.clientHeight;
addHitPosition(node, "none", top);
addHitPosition(node, null, top);

if (height > 5) {
// Subtract 5 pixels to allow more space for the next element.
addHitPosition(node, "none", top + height - 5);
addHitPosition(node, null, top + height - 5);
}

// Stop iterating
Expand Down Expand Up @@ -135,7 +139,7 @@ export const generateHitAreasForGroup = (
for (let i = 0; i < positionCount; i++) {
const position = positionsInGroup[i] as HitPosition;

if (position.position !== "none") {
if (position.position) {
hitAreas.push({
bottom: areaTop + areaHeight,
node: position.node,
Expand Down
3 changes: 1 addition & 2 deletions src/dragAndDropHandler/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -319,8 +319,7 @@ export class DragAndDropHandler {
private moveItem(positionInfo: PositionInfo): void {
if (
this.currentItem &&
this.hoveredArea &&
this.hoveredArea.position !== "none" &&
this.hoveredArea?.position &&
this.canMoveToArea(this.hoveredArea, this.currentItem)
) {
const movedNode = this.currentItem.node;
Expand Down
5 changes: 1 addition & 4 deletions src/node.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isNodeRecordWithChildren } from "./nodeUtils";

export type Position = "after" | "before" | "inside" | "none";
export type Position = "after" | "before" | "inside";

type IterateCallback = (node: Node, level: number) => boolean;

Expand Down Expand Up @@ -542,9 +542,6 @@ export class Node implements INode {
targetNode.addChildAtPosition(movedNode, 0);
return true;
}

default:
return false;
}
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/test/dragAndDropHandler/generateHitAreas.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ describe("generateHitAreasForGroup", () => {
const node = new Node(null);
const hitPosition = {
node,
position: "none" as Position,
position: null,
top: 0,
};

Expand Down Expand Up @@ -203,12 +203,12 @@ describe("generatePositions", () => {
expect(generateHitPositions(tree, node1)).toEqual([
expect.objectContaining({
node: node1,
position: "none",
position: null,
top: 100,
}),
expect.objectContaining({
node: node1,
position: "none",
position: null,
top: 100,
}),
expect.objectContaining({
Expand Down Expand Up @@ -243,12 +243,12 @@ describe("generatePositions", () => {
expect(generateHitPositions(tree, node1)).toEqual([
expect.objectContaining({
node: node1,
position: "none",
position: null,
top: 100,
}),
expect.objectContaining({
node: node1,
position: "none",
position: null,
top: 100,
}),
expect.objectContaining({
Expand Down Expand Up @@ -303,17 +303,17 @@ describe("generatePositions", () => {
}),
expect.objectContaining({
node: node1,
position: "none",
position: null,
top: 100,
}),
expect.objectContaining({
node: node2,
position: "none",
position: null,
top: 120,
}),
expect.objectContaining({
node: node2,
position: "none",
position: null,
top: 135,
}),
]);
Expand Down
8 changes: 0 additions & 8 deletions src/test/node.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1273,14 +1273,6 @@ describe("moveNode", () => {
});
});
});

context("with position None", () => {
it("returns false", () => {
expect(given.tree.moveNode(given.child2, given.node2, "none")).toBe(
false,
);
});
});
});

describe("prepend", () => {
Expand Down
2 changes: 1 addition & 1 deletion src/tree.jquery.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ interface IJQTreePlugin {
behavior: "moveNode",
node: INode,
targetNode: INode,
position: "after" | "before" | "inside" | "none",
position: "after" | "before" | "inside",
): JQuery;
(behavior: "moveUp"): JQuery;
(behavior: "openNode", node: INode): JQuery;
Expand Down

0 comments on commit 264d47c

Please sign in to comment.