@asup/context-menu 2.2.0 → 2.2.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/README.md +57 -0
- package/dist/cjs/main.js +245 -140
- package/dist/cjs/main.js.map +1 -1
- package/dist/context-menu.d.ts +17 -1
- package/dist/context-menu.d.ts.map +1 -1
- package/dist/main.js +244 -141
- package/dist/main.js.map +1 -1
- package/package.json +9 -9
package/README.md
CHANGED
|
@@ -117,6 +117,63 @@ import { ContextWindow } from "@asup/context-menu";
|
|
|
117
117
|
</ContextWindow>;
|
|
118
118
|
```
|
|
119
119
|
|
|
120
|
+
### useMouseMove (Hook)
|
|
121
|
+
|
|
122
|
+
`useMouseMove` is exported for draggable interactions. The API uses `onMouseDown` / `onMouseMove` / `onMouseUp` names, and the hook now wires both mouse and pointer document listeners during an active drag.
|
|
123
|
+
|
|
124
|
+
Key behavior:
|
|
125
|
+
|
|
126
|
+
- Registers both `mousemove` + `pointermove` while active.
|
|
127
|
+
- Registers both `mouseup` + `pointerup` while active.
|
|
128
|
+
- Restores `userSelect` on the same element that started the drag, even if the release happens on a different target.
|
|
129
|
+
- Restores `userSelect` during unmount cleanup if the interaction ends unexpectedly.
|
|
130
|
+
|
|
131
|
+
```tsx
|
|
132
|
+
import { useRef, useState } from "react";
|
|
133
|
+
import { useMouseMove } from "@asup/context-menu";
|
|
134
|
+
|
|
135
|
+
export function DraggablePanel(): React.ReactElement {
|
|
136
|
+
const panelRef = useRef<HTMLDivElement | null>(null);
|
|
137
|
+
const [x, setX] = useState(0);
|
|
138
|
+
const [y, setY] = useState(0);
|
|
139
|
+
|
|
140
|
+
const { onMouseDown } = useMouseMove({
|
|
141
|
+
onMouseMove: (e) => {
|
|
142
|
+
setX((prev) => prev + e.movementX);
|
|
143
|
+
setY((prev) => prev + e.movementY);
|
|
144
|
+
},
|
|
145
|
+
onMouseUp: () => {
|
|
146
|
+
// Optional: snap/validate final position.
|
|
147
|
+
},
|
|
148
|
+
});
|
|
149
|
+
|
|
150
|
+
return (
|
|
151
|
+
<div
|
|
152
|
+
ref={panelRef}
|
|
153
|
+
style={{
|
|
154
|
+
transform: `translate(${x}px, ${y}px)`,
|
|
155
|
+
width: 220,
|
|
156
|
+
padding: 12,
|
|
157
|
+
border: "1px solid #999",
|
|
158
|
+
borderRadius: 8,
|
|
159
|
+
background: "white",
|
|
160
|
+
}}
|
|
161
|
+
>
|
|
162
|
+
<div
|
|
163
|
+
onMouseDown={onMouseDown}
|
|
164
|
+
onPointerDown={(e) =>
|
|
165
|
+
onMouseDown(e as unknown as React.MouseEvent<HTMLElement | SVGElement>)
|
|
166
|
+
}
|
|
167
|
+
style={{ cursor: "move", fontWeight: 600 }}
|
|
168
|
+
>
|
|
169
|
+
Drag Handle
|
|
170
|
+
</div>
|
|
171
|
+
<div style={{ marginTop: 8 }}>Panel body</div>
|
|
172
|
+
</div>
|
|
173
|
+
);
|
|
174
|
+
}
|
|
175
|
+
```
|
|
176
|
+
|
|
120
177
|
See the Storybook for interactive examples and more options.
|
|
121
178
|
|
|
122
179
|
## Development
|