react-edge-dock 1.0.6 → 1.0.7

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,EAIlB,MAAM,SAAS,CAAC;AAwLjB;;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,CA2W1E"}
@@ -201,6 +201,26 @@ export function useEdgeDock(config = {}) {
201
201
  setPositionInternal(controlledPosition);
202
202
  }
203
203
  }, [controlledPosition]);
204
+ // Toggle popup
205
+ const togglePopup = useCallback(() => {
206
+ const newState = !isPopupOpen;
207
+ if (controlledPopupOpen === undefined) {
208
+ setIsPopupOpenInternal(newState);
209
+ }
210
+ onPopupChange?.(newState);
211
+ }, [isPopupOpen, controlledPopupOpen, onPopupChange]);
212
+ const closePopup = useCallback(() => {
213
+ if (controlledPopupOpen === undefined) {
214
+ setIsPopupOpenInternal(false);
215
+ }
216
+ onPopupChange?.(false);
217
+ }, [controlledPopupOpen, onPopupChange]);
218
+ const openPopup = useCallback(() => {
219
+ if (controlledPopupOpen === undefined) {
220
+ setIsPopupOpenInternal(true);
221
+ }
222
+ onPopupChange?.(true);
223
+ }, [controlledPopupOpen, onPopupChange]);
204
224
  // Calculate popup position when it opens or button moves
205
225
  useEffect(() => {
206
226
  if (isPopupOpen && buttonRef.current && popupRef.current) {
@@ -211,6 +231,28 @@ export function useEdgeDock(config = {}) {
211
231
  setPopupOrigin(result.origin);
212
232
  }
213
233
  }, [isPopupOpen, position, popupGap]);
234
+ // Close popup when clicking outside
235
+ useEffect(() => {
236
+ if (!isPopupOpen || !isBrowser)
237
+ return;
238
+ const handleClickOutside = (e) => {
239
+ const target = e.target;
240
+ // Check if click is outside both button and popup
241
+ const isOutsideButton = buttonRef.current && !buttonRef.current.contains(target);
242
+ const isOutsidePopup = popupRef.current && !popupRef.current.contains(target);
243
+ if (isOutsideButton && isOutsidePopup) {
244
+ closePopup();
245
+ }
246
+ };
247
+ // Use setTimeout to avoid closing immediately on the same click that opened it
248
+ const timeoutId = setTimeout(() => {
249
+ document.addEventListener('mousedown', handleClickOutside);
250
+ }, 0);
251
+ return () => {
252
+ clearTimeout(timeoutId);
253
+ document.removeEventListener('mousedown', handleClickOutside);
254
+ };
255
+ }, [isPopupOpen, closePopup]);
214
256
  // Notify state changes
215
257
  useEffect(() => {
216
258
  if (onDockChange) {
@@ -239,26 +281,6 @@ export function useEdgeDock(config = {}) {
239
281
  }
240
282
  setPositionInternal(finalPos);
241
283
  }, [dockMode, dockEdge, allowedEdges, edgeOffset]);
242
- // Toggle popup
243
- const togglePopup = useCallback(() => {
244
- const newState = !isPopupOpen;
245
- if (controlledPopupOpen === undefined) {
246
- setIsPopupOpenInternal(newState);
247
- }
248
- onPopupChange?.(newState);
249
- }, [isPopupOpen, controlledPopupOpen, onPopupChange]);
250
- const closePopup = useCallback(() => {
251
- if (controlledPopupOpen === undefined) {
252
- setIsPopupOpenInternal(false);
253
- }
254
- onPopupChange?.(false);
255
- }, [controlledPopupOpen, onPopupChange]);
256
- const openPopup = useCallback(() => {
257
- if (controlledPopupOpen === undefined) {
258
- setIsPopupOpenInternal(true);
259
- }
260
- onPopupChange?.(true);
261
- }, [controlledPopupOpen, onPopupChange]);
262
284
  // Pointer down handler
263
285
  const handlePointerDown = useCallback((e) => {
264
286
  if (!buttonRef.current)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-edge-dock",
3
- "version": "1.0.6",
3
+ "version": "1.0.7",
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",