MCPcopy Create free account
hub / github.com/wavetermdev/waveterm / determineDropDirection

Function determineDropDirection

frontend/layout/lib/utils.ts:12–59  ·  view source on GitHub ↗
(dimensions?: Dimensions, offset?: XYCoord | null)

Source from the content-addressed store, hash-verified

10}
11
12export function determineDropDirection(dimensions?: Dimensions, offset?: XYCoord | null): DropDirection | undefined {
13 // console.log("determineDropDirection", dimensions, offset);
14 if (!offset || !dimensions) return undefined;
15 const { width, height, left, top } = dimensions;
16 let { x, y } = offset;
17 x -= left;
18 y -= top;
19
20 // Lies outside of the box
21 if (y < 0 || y > height || x < 0 || x > width) return undefined;
22
23 // Determines if a drop point falls within the center fifth of the box, meaning we should return Center.
24 const centerX1 = (2 * width) / 5;
25 const centerX2 = (3 * width) / 5;
26 const centerY1 = (2 * height) / 5;
27 const centerY2 = (3 * height) / 5;
28
29 if (x > centerX1 && x < centerX2 && y > centerY1 && y < centerY2) return DropDirection.Center;
30
31 const diagonal1 = y * width - x * height;
32 const diagonal2 = y * width + x * height - height * width;
33
34 // Lies on diagonal
35 if (diagonal1 == 0 || diagonal2 == 0) return undefined;
36
37 let code = 0;
38
39 if (diagonal2 > 0) {
40 code += 1;
41 }
42
43 if (diagonal1 > 0) {
44 code += 2;
45 code = 5 - code;
46 }
47
48 // Determines whether a drop is close to an edge of the box, meaning drop direction should be OuterX, instead of X
49 const xOuter1 = width / 5;
50 const xOuter2 = width - width / 5;
51 const yOuter1 = height / 5;
52 const yOuter2 = height - height / 5;
53
54 if (y < yOuter1 || y > yOuter2 || x < xOuter1 || x > xOuter2) {
55 code += 4;
56 }
57
58 return code;
59}
60
61export function setTransform(
62 { top, left, width, height }: Dimensions,

Callers 2

TileLayout.tsxFile · 0.90
utils.test.tsFile · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected