Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract position module #770

Merged
merged 2 commits into from
Dec 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/dragAndDropHandler/hitAreasGenerator.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { HitArea } from "./types";
import { Node, Position } from "../node";
import { Node } from "../node";
import { Position } from "../position";
import { getOffsetTop } from "../util";
import VisibleNodeIterator from "./visibleNodeIterator";

Expand Down
3 changes: 2 additions & 1 deletion src/dragAndDropHandler/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { getPositionName, Node, Position } from "../node";
import { Node } from "../node";
import { getPositionName, Position } from "../position";
import { DropHint, HitArea } from "./types";
import { PositionInfo } from "../mouseWidgetTypes";
import NodeElement from "../nodeElement";
Expand Down
3 changes: 2 additions & 1 deletion src/dragAndDropHandler/types.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Node, Position } from "../node";
import { Node } from "../node";
import { Position } from "../position";

export interface DropHint {
remove: () => void;
Expand Down
30 changes: 1 addition & 29 deletions src/node.ts
Original file line number Diff line number Diff line change
@@ -1,36 +1,8 @@
import { isNodeRecordWithChildren } from "./nodeUtils";

export enum Position {
Before = 1,
After,
Inside,
None,
}

const positionNames: Record<string, Position> = {
before: Position.Before,
after: Position.After,
inside: Position.Inside,
none: Position.None,
};
import { Position } from "./position";

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

export const getPositionName = (position: Position): string => {
for (const name in positionNames) {
if (Object.prototype.hasOwnProperty.call(positionNames, name)) {
if (positionNames[name] === position) {
return name;
}
}
}

return "";
};

export const getPosition = (name: string): Position | undefined =>
positionNames[name];

export class Node implements INode {
public id?: NodeId;
public name: string;
Expand Down
2 changes: 1 addition & 1 deletion src/nodeElement/folderElement.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Position } from "../node";
import { Position } from "../position";
import NodeElement, { NodeElementParams } from "./index";
import { OnFinishOpenNode, TriggerEvent } from "../jqtreeMethodTypes";

Expand Down
3 changes: 2 additions & 1 deletion src/nodeElement/ghostDropHint.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Position, Node } from "../node";
import { Node } from "../node";
import { Position } from "../position";
import { DropHint } from "../dragAndDropHandler/types";

class GhostDropHint implements DropHint {
Expand Down
3 changes: 2 additions & 1 deletion src/nodeElement/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Position, Node } from "../node";
import { Node } from "../node";
import { Position } from "../position";
import { DropHint } from "../dragAndDropHandler/types";
import BorderDropHint from "./borderDropHint";
import GhostDropHint from "./ghostDropHint";
Expand Down
28 changes: 28 additions & 0 deletions src/position.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
export enum Position {
Before = 1,
After,
Inside,
None,
}

const positionNames: Record<string, Position> = {
before: Position.Before,
after: Position.After,
inside: Position.Inside,
none: Position.None,
};

export const getPositionName = (position: Position): string => {
for (const name in positionNames) {
if (Object.prototype.hasOwnProperty.call(positionNames, name)) {
if (positionNames[name] === position) {
return name;
}
}
}

return "";
};

export const getPosition = (name: string): Position | undefined =>
positionNames[name];
3 changes: 2 additions & 1 deletion src/test/node.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import getGiven from "givens";
import { Node, Position } from "../node";
import { Node } from "../node";
import { Position } from "../position";
import exampleData from "./support/exampleData";
import "jest-extended";

Expand Down
2 changes: 1 addition & 1 deletion src/test/nodeUtil.test.ts → src/test/position.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getPosition, getPositionName, Position } from "../node";
import { getPosition, getPositionName, Position } from "../position";

const context = describe;

Expand Down
3 changes: 2 additions & 1 deletion src/tree.jquery.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import SaveStateHandler, { SavedState } from "./saveStateHandler";
import ScrollHandler from "./scrollHandler";
import SelectNodeHandler from "./selectNodeHandler";
import SimpleWidget from "./simple.widget";
import { Node, getPosition } from "./node";
import { Node } from "./node";
import { getPosition } from "./position";
import { isFunction } from "./util";
import NodeElement from "./nodeElement";
import FolderElement from "./nodeElement/folderElement";
Expand Down
Loading
Loading