@hrnec06/react_utils 1.4.0 → 1.4.2
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/package.json
CHANGED
|
@@ -100,29 +100,32 @@ function DragArea({
|
|
|
100
100
|
onMove,
|
|
101
101
|
applyReposition = false,
|
|
102
102
|
|
|
103
|
-
...
|
|
103
|
+
...assignedSides
|
|
104
104
|
}: DragAreaProps)
|
|
105
105
|
{
|
|
106
106
|
const box = useResizeableBox();
|
|
107
107
|
|
|
108
108
|
const isAllowed = (side: RB.DragSide) => box.options.allowedSides.includes(side);
|
|
109
109
|
|
|
110
|
+
// Is a corner and allowCorners are either empty or false
|
|
110
111
|
if (isCorner && !box.options.allowCorners)
|
|
111
112
|
return undefined;
|
|
112
113
|
|
|
113
|
-
|
|
114
|
-
(enabledSides.top && !isAllowed('top')) ||
|
|
115
|
-
(enabledSides.right && !isAllowed('right')) ||
|
|
116
|
-
(enabledSides.bottom && !isAllowed('bottom')) ||
|
|
117
|
-
(enabledSides.left && !isAllowed('left'))
|
|
118
|
-
)
|
|
119
|
-
return undefined;
|
|
120
|
-
|
|
114
|
+
// Is corner and allowedCorners are array
|
|
121
115
|
if (isCorner && Array.isArray(box.options.allowCorners))
|
|
122
116
|
{
|
|
123
|
-
if (!box.options.allowCorners.some((combo) =>
|
|
117
|
+
if (!box.options.allowCorners.some((combo) => assignedSides[combo[0]] && assignedSides[combo[1]]))
|
|
124
118
|
return undefined;
|
|
125
119
|
}
|
|
120
|
+
else if (
|
|
121
|
+
(assignedSides.top && !isAllowed('top')) ||
|
|
122
|
+
(assignedSides.right && !isAllowed('right')) ||
|
|
123
|
+
(assignedSides.bottom && !isAllowed('bottom')) ||
|
|
124
|
+
(assignedSides.left && !isAllowed('left'))
|
|
125
|
+
)
|
|
126
|
+
{
|
|
127
|
+
return undefined;
|
|
128
|
+
}
|
|
126
129
|
|
|
127
130
|
const handleMouseDown = (e: React.MouseEvent<HTMLDivElement>) => {
|
|
128
131
|
if (box.drag.value !== null || !matchMouseEvent(e.nativeEvent, MouseButton.Left))
|
|
@@ -160,21 +163,21 @@ function DragArea({
|
|
|
160
163
|
box.options.dragAreaSize === 'big' && 'w-6'
|
|
161
164
|
),
|
|
162
165
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
166
|
+
assignedSides.top && clsx('bottom-full', box.options.insetAreas && 'translate-y-1/2'),
|
|
167
|
+
assignedSides.right && clsx('left-full', box.options.insetAreas && '-translate-x-1/2'),
|
|
168
|
+
assignedSides.bottom && clsx('top-full', box.options.insetAreas && '-translate-y-1/2'),
|
|
169
|
+
assignedSides.left && clsx('right-full', box.options.insetAreas && 'translate-x-1/2'),
|
|
167
170
|
|
|
168
171
|
matchBool({
|
|
169
|
-
"cursor-nw-resize":
|
|
170
|
-
"cursor-ne-resize":
|
|
171
|
-
"cursor-se-resize":
|
|
172
|
-
"cursor-sw-resize":
|
|
173
|
-
|
|
174
|
-
"cursor-n-resize":
|
|
175
|
-
"cursor-e-resize":
|
|
176
|
-
"cursor-s-resize":
|
|
177
|
-
"cursor-w-resize":
|
|
172
|
+
"cursor-nw-resize": assignedSides.top && assignedSides.left,
|
|
173
|
+
"cursor-ne-resize": assignedSides.top && assignedSides.right,
|
|
174
|
+
"cursor-se-resize": assignedSides.bottom && assignedSides.right,
|
|
175
|
+
"cursor-sw-resize": assignedSides.bottom && assignedSides.left,
|
|
176
|
+
|
|
177
|
+
"cursor-n-resize": assignedSides.top,
|
|
178
|
+
"cursor-e-resize": assignedSides.right,
|
|
179
|
+
"cursor-s-resize": assignedSides.bottom,
|
|
180
|
+
"cursor-w-resize": assignedSides.left
|
|
178
181
|
}),
|
|
179
182
|
)}
|
|
180
183
|
/>
|
|
@@ -32,8 +32,12 @@ interface ResizeableBoxProps extends React.HTMLProps<HTMLDivElement>
|
|
|
32
32
|
*/
|
|
33
33
|
$allowedSides?: RB.DragSide[],
|
|
34
34
|
/**
|
|
35
|
-
* Allow corner resizers
|
|
36
|
-
*
|
|
35
|
+
* Allow corner resizers
|
|
36
|
+
*
|
|
37
|
+
* Possible values:
|
|
38
|
+
* - `true`: Corners will be applied automatically based on allowed sides
|
|
39
|
+
* - `false`: No corners
|
|
40
|
+
* - `Vector2<RB.DragSide>[]`: Explicitely define allowed corners
|
|
37
41
|
*/
|
|
38
42
|
$allowCorners?: boolean | Vector2<RB.DragSide>[],
|
|
39
43
|
/**
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { KeyboardButton } from "@hrnec06/util";
|
|
1
2
|
import { useEffect, useState } from "react";
|
|
2
3
|
|
|
3
4
|
interface KeyListenerOptions {
|
|
@@ -5,9 +6,11 @@ interface KeyListenerOptions {
|
|
|
5
6
|
shift?: boolean,
|
|
6
7
|
alt?: boolean
|
|
7
8
|
}
|
|
8
|
-
export default function useKeyListener(key: string, options?: KeyListenerOptions) {
|
|
9
|
+
export default function useKeyListener(key: string | KeyboardButton, options?: KeyListenerOptions, element?: EventTarget) {
|
|
9
10
|
const [pressing, setPressing] = useState(false);
|
|
10
11
|
|
|
12
|
+
element ||= window;
|
|
13
|
+
|
|
11
14
|
const keyMatching = (e: KeyboardEvent, strict: boolean): boolean => {
|
|
12
15
|
if (strict && options?.ctrl && !e.ctrlKey)
|
|
13
16
|
return false;
|
|
@@ -34,12 +37,12 @@ export default function useKeyListener(key: string, options?: KeyListenerOptions
|
|
|
34
37
|
setPressing(false);
|
|
35
38
|
}
|
|
36
39
|
|
|
37
|
-
|
|
38
|
-
|
|
40
|
+
element.addEventListener('keydown', downListener as EventListenerOrEventListenerObject);
|
|
41
|
+
element.addEventListener('keyup', upListener as EventListenerOrEventListenerObject);
|
|
39
42
|
|
|
40
43
|
return () => {
|
|
41
|
-
|
|
42
|
-
|
|
44
|
+
element.removeEventListener('keydown', downListener as EventListenerOrEventListenerObject);
|
|
45
|
+
element.removeEventListener('keyup', upListener as EventListenerOrEventListenerObject);
|
|
43
46
|
}
|
|
44
47
|
}, []);
|
|
45
48
|
|