react-resizable-panels 1.0.9 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +9 -0
- package/README.md +29 -104
- package/dist/declarations/src/PanelResizeHandle.d.ts +3 -1
- package/dist/declarations/src/PanelResizeHandleRegistry.d.ts +20 -0
- package/dist/react-resizable-panels.browser.cjs.js +367 -140
- package/dist/react-resizable-panels.browser.development.cjs.js +367 -140
- package/dist/react-resizable-panels.browser.development.esm.js +367 -140
- package/dist/react-resizable-panels.browser.esm.js +367 -140
- package/dist/react-resizable-panels.cjs.js +367 -140
- package/dist/react-resizable-panels.development.cjs.js +367 -140
- package/dist/react-resizable-panels.development.esm.js +367 -140
- package/dist/react-resizable-panels.development.node.cjs.js +367 -140
- package/dist/react-resizable-panels.development.node.esm.js +367 -140
- package/dist/react-resizable-panels.esm.js +367 -140
- package/dist/react-resizable-panels.node.cjs.js +367 -140
- package/dist/react-resizable-panels.node.esm.js +367 -140
- package/package.json +1 -1
- package/src/Panel.test.tsx +52 -0
- package/src/PanelGroup.ts +23 -16
- package/src/PanelResizeHandle.ts +64 -82
- package/src/PanelResizeHandleRegistry.ts +263 -0
- package/src/utils/calculateDragOffsetPercentage.ts +1 -1
- package/src/utils/cursor.ts +63 -33
- package/src/utils/events/getResizeEventCoordinates.ts +24 -0
- package/src/utils/events/getResizeEventCursorPosition.ts +14 -0
- package/src/utils/{events.ts → events/index.ts} +1 -1
- package/src/utils/getInputType.ts +5 -0
- package/src/utils/getResizeEventCursorPosition.ts +0 -21
package/src/utils/cursor.ts
CHANGED
|
@@ -1,54 +1,84 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
let
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
import {
|
|
2
|
+
EXCEEDED_HORIZONTAL_MAX,
|
|
3
|
+
EXCEEDED_HORIZONTAL_MIN,
|
|
4
|
+
EXCEEDED_VERTICAL_MAX,
|
|
5
|
+
EXCEEDED_VERTICAL_MIN,
|
|
6
|
+
} from "../PanelResizeHandleRegistry";
|
|
7
|
+
|
|
8
|
+
type CursorState = "horizontal" | "intersection" | "vertical";
|
|
9
|
+
|
|
10
|
+
let currentCursorStyle: string | null = null;
|
|
11
|
+
let styleElement: HTMLStyleElement | null = null;
|
|
12
|
+
|
|
13
|
+
export function getCursorStyle(
|
|
14
|
+
state: CursorState,
|
|
15
|
+
constraintFlags: number
|
|
16
|
+
): string {
|
|
17
|
+
if (constraintFlags) {
|
|
18
|
+
const horizontalMin = (constraintFlags & EXCEEDED_HORIZONTAL_MIN) !== 0;
|
|
19
|
+
const horizontalMax = (constraintFlags & EXCEEDED_HORIZONTAL_MAX) !== 0;
|
|
20
|
+
const verticalMin = (constraintFlags & EXCEEDED_VERTICAL_MIN) !== 0;
|
|
21
|
+
const verticalMax = (constraintFlags & EXCEEDED_VERTICAL_MAX) !== 0;
|
|
22
|
+
|
|
23
|
+
if (horizontalMin) {
|
|
24
|
+
if (verticalMin) {
|
|
25
|
+
return "se-resize";
|
|
26
|
+
} else if (verticalMax) {
|
|
27
|
+
return "ne-resize";
|
|
28
|
+
} else {
|
|
29
|
+
return "e-resize";
|
|
30
|
+
}
|
|
31
|
+
} else if (horizontalMax) {
|
|
32
|
+
if (verticalMin) {
|
|
33
|
+
return "sw-resize";
|
|
34
|
+
} else if (verticalMax) {
|
|
35
|
+
return "nw-resize";
|
|
36
|
+
} else {
|
|
37
|
+
return "w-resize";
|
|
38
|
+
}
|
|
39
|
+
} else if (verticalMin) {
|
|
40
|
+
return "s-resize";
|
|
41
|
+
} else if (verticalMax) {
|
|
42
|
+
return "n-resize";
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
13
46
|
switch (state) {
|
|
14
47
|
case "horizontal":
|
|
15
48
|
return "ew-resize";
|
|
16
|
-
case "
|
|
17
|
-
return "
|
|
18
|
-
case "horizontal-min":
|
|
19
|
-
return "e-resize";
|
|
49
|
+
case "intersection":
|
|
50
|
+
return "move";
|
|
20
51
|
case "vertical":
|
|
21
52
|
return "ns-resize";
|
|
22
|
-
case "vertical-max":
|
|
23
|
-
return "n-resize";
|
|
24
|
-
case "vertical-min":
|
|
25
|
-
return "s-resize";
|
|
26
53
|
}
|
|
27
54
|
}
|
|
28
55
|
|
|
29
56
|
export function resetGlobalCursorStyle() {
|
|
30
|
-
if (
|
|
31
|
-
document.head.removeChild(
|
|
57
|
+
if (styleElement !== null) {
|
|
58
|
+
document.head.removeChild(styleElement);
|
|
32
59
|
|
|
33
|
-
|
|
34
|
-
|
|
60
|
+
currentCursorStyle = null;
|
|
61
|
+
styleElement = null;
|
|
35
62
|
}
|
|
36
63
|
}
|
|
37
64
|
|
|
38
|
-
export function setGlobalCursorStyle(
|
|
39
|
-
|
|
65
|
+
export function setGlobalCursorStyle(
|
|
66
|
+
state: CursorState,
|
|
67
|
+
constraintFlags: number
|
|
68
|
+
) {
|
|
69
|
+
const style = getCursorStyle(state, constraintFlags);
|
|
70
|
+
|
|
71
|
+
if (currentCursorStyle === style) {
|
|
40
72
|
return;
|
|
41
73
|
}
|
|
42
74
|
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
const style = getCursorStyle(state);
|
|
75
|
+
currentCursorStyle = style;
|
|
46
76
|
|
|
47
|
-
if (
|
|
48
|
-
|
|
77
|
+
if (styleElement === null) {
|
|
78
|
+
styleElement = document.createElement("style");
|
|
49
79
|
|
|
50
|
-
document.head.appendChild(
|
|
80
|
+
document.head.appendChild(styleElement);
|
|
51
81
|
}
|
|
52
82
|
|
|
53
|
-
|
|
83
|
+
styleElement.innerHTML = `*{cursor: ${style}!important;}`;
|
|
54
84
|
}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import { ResizeEvent } from "../../types";
|
|
2
|
+
import { isMouseEvent, isTouchEvent } from ".";
|
|
3
|
+
|
|
4
|
+
export function getResizeEventCoordinates(event: ResizeEvent) {
|
|
5
|
+
if (isMouseEvent(event)) {
|
|
6
|
+
return {
|
|
7
|
+
x: event.pageX,
|
|
8
|
+
y: event.pageY,
|
|
9
|
+
};
|
|
10
|
+
} else if (isTouchEvent(event)) {
|
|
11
|
+
const touch = event.touches[0];
|
|
12
|
+
if (touch && touch.pageX && touch.pageY) {
|
|
13
|
+
return {
|
|
14
|
+
x: touch.pageX,
|
|
15
|
+
y: touch.pageY,
|
|
16
|
+
};
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
return {
|
|
21
|
+
x: Infinity,
|
|
22
|
+
y: Infinity,
|
|
23
|
+
};
|
|
24
|
+
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { ResizeEvent } from "../../PanelGroupContext";
|
|
2
|
+
import { Direction } from "../../types";
|
|
3
|
+
import { getResizeEventCoordinates } from "./getResizeEventCoordinates";
|
|
4
|
+
|
|
5
|
+
export function getResizeEventCursorPosition(
|
|
6
|
+
direction: Direction,
|
|
7
|
+
event: ResizeEvent
|
|
8
|
+
): number {
|
|
9
|
+
const isHorizontal = direction === "horizontal";
|
|
10
|
+
|
|
11
|
+
const { x, y } = getResizeEventCoordinates(event);
|
|
12
|
+
|
|
13
|
+
return isHorizontal ? x : y;
|
|
14
|
+
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { ResizeEvent } from "../PanelGroupContext";
|
|
2
|
-
import { Direction } from "../types";
|
|
3
|
-
import { assert } from "./assert";
|
|
4
|
-
import { isMouseEvent, isTouchEvent } from "./events";
|
|
5
|
-
|
|
6
|
-
export function getResizeEventCursorPosition(
|
|
7
|
-
direction: Direction,
|
|
8
|
-
event: ResizeEvent
|
|
9
|
-
): number {
|
|
10
|
-
const isHorizontal = direction === "horizontal";
|
|
11
|
-
|
|
12
|
-
if (isMouseEvent(event)) {
|
|
13
|
-
return isHorizontal ? event.clientX : event.clientY;
|
|
14
|
-
} else if (isTouchEvent(event)) {
|
|
15
|
-
const firstTouch = event.touches[0];
|
|
16
|
-
assert(firstTouch);
|
|
17
|
-
return isHorizontal ? firstTouch.screenX : firstTouch.screenY;
|
|
18
|
-
} else {
|
|
19
|
-
throw Error(`Unsupported event type "${event.type}"`);
|
|
20
|
-
}
|
|
21
|
-
}
|