react-edge-dock 1.0.4 → 1.0.5
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/dist/useEdgeDock.d.ts.map +1 -1
- package/dist/useEdgeDock.js +12 -8
- package/package.json +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useEdgeDock.d.ts","sourceRoot":"","sources":["../src/useEdgeDock.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EAId,iBAAiB,EAIlB,MAAM,SAAS,CAAC;
|
|
1
|
+
{"version":3,"file":"useEdgeDock.d.ts","sourceRoot":"","sources":["../src/useEdgeDock.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EAId,iBAAiB,EAIlB,MAAM,SAAS,CAAC;AAwLjB;;GAEG;AACH,wBAAgB,WAAW,CAAC,MAAM,GAAE,cAAmB,GAAG,iBAAiB,CAgV1E"}
|
package/dist/useEdgeDock.js
CHANGED
|
@@ -76,14 +76,18 @@ function snapToEdge(pos, edge, viewport, buttonDimensions, edgeOffset) {
|
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
78
|
/**
|
|
79
|
-
* Constrain position within viewport bounds
|
|
79
|
+
* Constrain position within viewport bounds, respecting edge offsets
|
|
80
80
|
*/
|
|
81
|
-
function constrainToViewport(pos, viewport, buttonDimensions) {
|
|
81
|
+
function constrainToViewport(pos, viewport, buttonDimensions, edgeOffset) {
|
|
82
82
|
const halfWidth = buttonDimensions.width / 2;
|
|
83
83
|
const halfHeight = buttonDimensions.height / 2;
|
|
84
|
+
const leftOffset = getOffsetForEdge(edgeOffset, 'left');
|
|
85
|
+
const rightOffset = getOffsetForEdge(edgeOffset, 'right');
|
|
86
|
+
const topOffset = getOffsetForEdge(edgeOffset, 'top');
|
|
87
|
+
const bottomOffset = getOffsetForEdge(edgeOffset, 'bottom');
|
|
84
88
|
return {
|
|
85
|
-
x: Math.max(halfWidth, Math.min(viewport.width - halfWidth, pos.x)),
|
|
86
|
-
y: Math.max(halfHeight, Math.min(viewport.height - halfHeight, pos.y)),
|
|
89
|
+
x: Math.max(halfWidth + leftOffset, Math.min(viewport.width - halfWidth - rightOffset, pos.x)),
|
|
90
|
+
y: Math.max(halfHeight + topOffset, Math.min(viewport.height - halfHeight - bottomOffset, pos.y)),
|
|
87
91
|
};
|
|
88
92
|
}
|
|
89
93
|
/**
|
|
@@ -178,7 +182,7 @@ export function useEdgeDock(config = {}) {
|
|
|
178
182
|
const buttonDimensions = { width: buttonRect.width, height: buttonRect.height };
|
|
179
183
|
// Set initial position on client after mount
|
|
180
184
|
let initialPos = { x: viewport.width - 60, y: viewport.height - 60 };
|
|
181
|
-
initialPos = constrainToViewport(initialPos, viewport, buttonDimensions);
|
|
185
|
+
initialPos = constrainToViewport(initialPos, viewport, buttonDimensions, edgeOffset);
|
|
182
186
|
if (dockMode === 'auto') {
|
|
183
187
|
const edge = getClosestEdge(initialPos, viewport, allowedEdges);
|
|
184
188
|
initialPos = snapToEdge(initialPos, edge, viewport, buttonDimensions, edgeOffset);
|
|
@@ -220,7 +224,7 @@ export function useEdgeDock(config = {}) {
|
|
|
220
224
|
const buttonRect = buttonRef.current.getBoundingClientRect();
|
|
221
225
|
const viewport = getViewport();
|
|
222
226
|
const buttonDimensions = { width: buttonRect.width, height: buttonRect.height };
|
|
223
|
-
let finalPos = constrainToViewport(newPos, viewport, buttonDimensions);
|
|
227
|
+
let finalPos = constrainToViewport(newPos, viewport, buttonDimensions, edgeOffset);
|
|
224
228
|
if (dockMode === 'auto') {
|
|
225
229
|
const edge = getClosestEdge(finalPos, viewport, allowedEdges);
|
|
226
230
|
finalPos = snapToEdge(finalPos, edge, viewport, buttonDimensions, edgeOffset);
|
|
@@ -297,7 +301,7 @@ export function useEdgeDock(config = {}) {
|
|
|
297
301
|
const viewport = { width: window.innerWidth, height: window.innerHeight };
|
|
298
302
|
const buttonDimensions = { width: buttonRect.width, height: buttonRect.height };
|
|
299
303
|
// During drag, only constrain to viewport (no snapping)
|
|
300
|
-
const constrainedPos = constrainToViewport(newPos, viewport, buttonDimensions);
|
|
304
|
+
const constrainedPos = constrainToViewport(newPos, viewport, buttonDimensions, edgeOffset);
|
|
301
305
|
setPositionInternal(constrainedPos);
|
|
302
306
|
};
|
|
303
307
|
const handlePointerUp = () => {
|
|
@@ -352,7 +356,7 @@ export function useEdgeDock(config = {}) {
|
|
|
352
356
|
const buttonRect = buttonRef.current.getBoundingClientRect();
|
|
353
357
|
const viewport = getViewport();
|
|
354
358
|
const buttonDimensions = { width: buttonRect.width, height: buttonRect.height };
|
|
355
|
-
let newPos = constrainToViewport(position, viewport, buttonDimensions);
|
|
359
|
+
let newPos = constrainToViewport(position, viewport, buttonDimensions, edgeOffset);
|
|
356
360
|
if (dockMode === 'auto') {
|
|
357
361
|
const edge = getClosestEdge(newPos, viewport, allowedEdges);
|
|
358
362
|
newPos = snapToEdge(newPos, edge, viewport, buttonDimensions, edgeOffset);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-edge-dock",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.5",
|
|
4
4
|
"description": "A zero-dependency React TypeScript library for customizable draggable edge-docked floating buttons with popup support",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|