react-edge-dock 1.0.2 → 1.0.3

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.
@@ -1 +1 @@
1
- {"version":3,"file":"useEdgeDock.d.ts","sourceRoot":"","sources":["../src/useEdgeDock.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EAId,iBAAiB,EAGlB,MAAM,SAAS,CAAC;AAwKjB;;GAEG;AACH,wBAAgB,WAAW,CAAC,MAAM,GAAE,cAAmB,GAAG,iBAAiB,CAwT1E"}
1
+ {"version":3,"file":"useEdgeDock.d.ts","sourceRoot":"","sources":["../src/useEdgeDock.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,cAAc,EAId,iBAAiB,EAGlB,MAAM,SAAS,CAAC;AAwKjB;;GAEG;AACH,wBAAgB,WAAW,CAAC,MAAM,GAAE,cAAmB,GAAG,iBAAiB,CAgV1E"}
@@ -131,10 +131,10 @@ export function useEdgeDock(config = {}) {
131
131
  const { dockMode = 'auto', dockEdge, allowedEdges, position: controlledPosition, animation = true, popupGap = 12, edgeOffset = 0, zIndex = 9999, onDockChange, isPopupOpen: controlledPopupOpen, onPopupChange, } = config;
132
132
  const buttonRef = useRef(null);
133
133
  const popupRef = useRef(null);
134
- // Get initial viewport safely
135
- const initialViewport = getViewport();
136
- // Internal state
137
- const [position, setPositionInternal] = useState(controlledPosition || { x: initialViewport.width - 60, y: initialViewport.height - 60 });
134
+ const isMountedRef = useRef(false);
135
+ // Use a fixed initial position to avoid SSR hydration mismatch
136
+ // This will be updated after mount on the client
137
+ const [position, setPositionInternal] = useState(controlledPosition || { x: 100, y: 100 });
138
138
  const [dockedEdge, setDockedEdge] = useState(null);
139
139
  const [isDragging, setIsDragging] = useState(false);
140
140
  const [isPopupOpenInternal, setIsPopupOpenInternal] = useState(false);
@@ -158,6 +158,28 @@ export function useEdgeDock(config = {}) {
158
158
  isDragging,
159
159
  isPopupOpen,
160
160
  };
161
+ // Initialize position after mount (client-side only) to avoid hydration mismatch
162
+ useEffect(() => {
163
+ if (!isMountedRef.current && !controlledPosition && buttonRef.current) {
164
+ isMountedRef.current = true;
165
+ const viewport = getViewport();
166
+ const buttonRect = buttonRef.current.getBoundingClientRect();
167
+ const buttonDimensions = { width: buttonRect.width, height: buttonRect.height };
168
+ // Set initial position on client after mount
169
+ let initialPos = { x: viewport.width - 60, y: viewport.height - 60 };
170
+ initialPos = constrainToViewport(initialPos, viewport, buttonDimensions);
171
+ if (dockMode === 'auto') {
172
+ const edge = getClosestEdge(initialPos, viewport, allowedEdges);
173
+ initialPos = snapToEdge(initialPos, edge, viewport, buttonDimensions, edgeOffset);
174
+ setDockedEdge(edge);
175
+ }
176
+ else if (dockMode === 'manual' && dockEdge) {
177
+ initialPos = snapToEdge(initialPos, dockEdge, viewport, buttonDimensions, edgeOffset);
178
+ setDockedEdge(dockEdge);
179
+ }
180
+ setPositionInternal(initialPos);
181
+ }
182
+ }, [controlledPosition, dockMode, dockEdge, allowedEdges, edgeOffset]);
161
183
  // Update controlled position
162
184
  useEffect(() => {
163
185
  if (controlledPosition) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-edge-dock",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
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",