react-edge-dock 1.0.4 → 1.0.6

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 CHANGED
@@ -129,4 +129,4 @@ export default function MyComponent() {
129
129
 
130
130
  ## API
131
131
 
132
- See the [example.tsx](./example.tsx) file for more detailed usage examples.
132
+ See the [example.tsx](https://github.com/Shivampatel07/react-edge-dock/blob/master/example.tsx) file for more detailed usage examples.
@@ -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;AAkLjB;;GAEG;AACH,wBAAgB,WAAW,CAAC,MAAM,GAAE,cAAmB,GAAG,iBAAiB,CAgV1E"}
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"}
@@ -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.4",
3
+ "version": "1.0.6",
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",
@@ -11,12 +11,12 @@
11
11
  ],
12
12
  "repository": {
13
13
  "type": "git",
14
- "url": "https://github.com/yourusername/react-edge-dock.git"
14
+ "url": "https://github.com/Shivampatel07/react-edge-dock"
15
15
  },
16
16
  "bugs": {
17
- "url": "https://github.com/yourusername/react-edge-dock/issues"
17
+ "url": "https://github.com/Shivampatel07/react-edge-dock/issues"
18
18
  },
19
- "homepage": "https://github.com/yourusername/react-edge-dock#readme",
19
+ "homepage": "https://github.com/Shivampatel07/react-edge-dock#readme",
20
20
  "scripts": {
21
21
  "build": "tsc",
22
22
  "dev": "tsc --watch",