@develemit/web-hooks 0.0.0-stage → 0.2.0
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/CHANGELOG.md +24 -0
- package/LICENSE +21 -0
- package/README.md +249 -2
- package/dist/auto-grow.cjs +60 -0
- package/dist/auto-grow.d.cts +14 -0
- package/dist/auto-grow.d.ts +14 -0
- package/dist/auto-grow.js +9 -0
- package/dist/chunk-3CACI4OQ.js +68 -0
- package/dist/chunk-3UGRXQIA.js +39 -0
- package/dist/chunk-5CA5RIMH.js +34 -0
- package/dist/chunk-5KIH2XLV.js +136 -0
- package/dist/chunk-6KCRVSLS.js +80 -0
- package/dist/chunk-DNU57XEJ.js +82 -0
- package/dist/chunk-IWQDAJEP.js +69 -0
- package/dist/chunk-LZKAGDER.js +22 -0
- package/dist/chunk-NKLEB5TR.js +98 -0
- package/dist/chunk-OZ4PU4E3.js +115 -0
- package/dist/chunk-S4YKMGQE.js +23 -0
- package/dist/chunk-UPVNSGIK.js +72 -0
- package/dist/chunk-UZADAINO.js +61 -0
- package/dist/clipboard.cjs +94 -0
- package/dist/clipboard.d.cts +17 -0
- package/dist/clipboard.d.ts +17 -0
- package/dist/clipboard.js +9 -0
- package/dist/debounce.cjs +96 -0
- package/dist/debounce.d.cts +21 -0
- package/dist/debounce.d.ts +21 -0
- package/dist/debounce.js +11 -0
- package/dist/drawer-swipe.cjs +149 -0
- package/dist/drawer-swipe.d.cts +26 -0
- package/dist/drawer-swipe.d.ts +26 -0
- package/dist/drawer-swipe.js +25 -0
- package/dist/escape.cjs +48 -0
- package/dist/escape.d.cts +3 -0
- package/dist/escape.d.ts +3 -0
- package/dist/escape.js +7 -0
- package/dist/focus-trap.cjs +110 -0
- package/dist/focus-trap.d.cts +17 -0
- package/dist/focus-trap.d.ts +17 -0
- package/dist/focus-trap.js +13 -0
- package/dist/hotkey.cjs +127 -0
- package/dist/hotkey.d.cts +31 -0
- package/dist/hotkey.d.ts +31 -0
- package/dist/hotkey.js +15 -0
- package/dist/index.cjs +918 -0
- package/dist/index.d.cts +14 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +115 -0
- package/dist/media-query.cjs +90 -0
- package/dist/media-query.d.cts +12 -0
- package/dist/media-query.d.ts +12 -0
- package/dist/media-query.js +15 -0
- package/dist/outside-press.cjs +66 -0
- package/dist/outside-press.d.cts +15 -0
- package/dist/outside-press.d.ts +15 -0
- package/dist/outside-press.js +11 -0
- package/dist/scroll-lock.cjs +107 -0
- package/dist/scroll-lock.d.cts +8 -0
- package/dist/scroll-lock.d.ts +8 -0
- package/dist/scroll-lock.js +11 -0
- package/dist/storage-state.cjs +161 -0
- package/dist/storage-state.d.cts +14 -0
- package/dist/storage-state.d.ts +14 -0
- package/dist/storage-state.js +7 -0
- package/dist/unsaved-guard.cjs +48 -0
- package/dist/unsaved-guard.d.cts +5 -0
- package/dist/unsaved-guard.d.ts +5 -0
- package/dist/unsaved-guard.js +9 -0
- package/dist/visibility-polling.cjs +98 -0
- package/dist/visibility-polling.d.cts +14 -0
- package/dist/visibility-polling.d.ts +14 -0
- package/dist/visibility-polling.js +9 -0
- package/package.json +126 -3
package/dist/index.d.cts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { BACK_ZONE_PX, CLOSE_DISTANCE_PX, FORWARD_ZONE_PX, MAX_SWIPE_DURATION_MS, OPEN_DISTANCE_PX, SwipeIntent, SwipePoint, UseDrawerSwipeOptions, VERTICAL_CANCEL_PX, isInOpenZone, isInsideHorizontalScroller, resolveSwipeIntent, useDrawerSwipe } from './drawer-swipe.cjs';
|
|
2
|
+
export { FOCUSABLE_SELECTOR, UseFocusTrapOptions, focusableWithin, nextFocusTarget, useFocusTrap } from './focus-trap.cjs';
|
|
3
|
+
export { useEscape } from './escape.cjs';
|
|
4
|
+
export { CopyResult, CopyStatus, copyText, useCopyFeedback } from './clipboard.cjs';
|
|
5
|
+
export { lockScroll, unlockScroll, useScrollLock } from './scroll-lock.cjs';
|
|
6
|
+
export { COARSE_POINTER_QUERY, REDUCED_MOTION_QUERY, UseMediaQueryOptions, useCoarsePointer, useMediaQuery, useReducedMotion } from './media-query.cjs';
|
|
7
|
+
export { UseOutsidePressOptions, isOutside, isPrimaryPress, useOutsidePress } from './outside-press.cjs';
|
|
8
|
+
export { UseVisibilityPollingOptions, nextDelay, useVisibilityPolling } from './visibility-polling.cjs';
|
|
9
|
+
export { DebouncedCallback, Debouncer, createDebouncer, useDebouncedCallback, useDebouncedValue } from './debounce.cjs';
|
|
10
|
+
export { StorageKind, StorageStateSetter, UseStorageStateOptions, useStorageState } from './storage-state.cjs';
|
|
11
|
+
export { handleBeforeUnload, useUnsavedChangesGuard } from './unsaved-guard.cjs';
|
|
12
|
+
export { ParsedHotkey, UseHotkeyOptions, detectApple, isEditableTarget, matchHotkey, parseHotkey, useHotkey } from './hotkey.cjs';
|
|
13
|
+
export { NextHeight, UseAutoGrowTextareaOptions, nextHeight, useAutoGrowTextarea } from './auto-grow.cjs';
|
|
14
|
+
import 'react';
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { BACK_ZONE_PX, CLOSE_DISTANCE_PX, FORWARD_ZONE_PX, MAX_SWIPE_DURATION_MS, OPEN_DISTANCE_PX, SwipeIntent, SwipePoint, UseDrawerSwipeOptions, VERTICAL_CANCEL_PX, isInOpenZone, isInsideHorizontalScroller, resolveSwipeIntent, useDrawerSwipe } from './drawer-swipe.js';
|
|
2
|
+
export { FOCUSABLE_SELECTOR, UseFocusTrapOptions, focusableWithin, nextFocusTarget, useFocusTrap } from './focus-trap.js';
|
|
3
|
+
export { useEscape } from './escape.js';
|
|
4
|
+
export { CopyResult, CopyStatus, copyText, useCopyFeedback } from './clipboard.js';
|
|
5
|
+
export { lockScroll, unlockScroll, useScrollLock } from './scroll-lock.js';
|
|
6
|
+
export { COARSE_POINTER_QUERY, REDUCED_MOTION_QUERY, UseMediaQueryOptions, useCoarsePointer, useMediaQuery, useReducedMotion } from './media-query.js';
|
|
7
|
+
export { UseOutsidePressOptions, isOutside, isPrimaryPress, useOutsidePress } from './outside-press.js';
|
|
8
|
+
export { UseVisibilityPollingOptions, nextDelay, useVisibilityPolling } from './visibility-polling.js';
|
|
9
|
+
export { DebouncedCallback, Debouncer, createDebouncer, useDebouncedCallback, useDebouncedValue } from './debounce.js';
|
|
10
|
+
export { StorageKind, StorageStateSetter, UseStorageStateOptions, useStorageState } from './storage-state.js';
|
|
11
|
+
export { handleBeforeUnload, useUnsavedChangesGuard } from './unsaved-guard.js';
|
|
12
|
+
export { ParsedHotkey, UseHotkeyOptions, detectApple, isEditableTarget, matchHotkey, parseHotkey, useHotkey } from './hotkey.js';
|
|
13
|
+
export { NextHeight, UseAutoGrowTextareaOptions, nextHeight, useAutoGrowTextarea } from './auto-grow.js';
|
|
14
|
+
import 'react';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
nextDelay,
|
|
4
|
+
useVisibilityPolling
|
|
5
|
+
} from "./chunk-UPVNSGIK.js";
|
|
6
|
+
import {
|
|
7
|
+
createDebouncer,
|
|
8
|
+
useDebouncedCallback,
|
|
9
|
+
useDebouncedValue
|
|
10
|
+
} from "./chunk-IWQDAJEP.js";
|
|
11
|
+
import {
|
|
12
|
+
useStorageState
|
|
13
|
+
} from "./chunk-5KIH2XLV.js";
|
|
14
|
+
import {
|
|
15
|
+
handleBeforeUnload,
|
|
16
|
+
useUnsavedChangesGuard
|
|
17
|
+
} from "./chunk-LZKAGDER.js";
|
|
18
|
+
import {
|
|
19
|
+
detectApple,
|
|
20
|
+
isEditableTarget,
|
|
21
|
+
matchHotkey,
|
|
22
|
+
parseHotkey,
|
|
23
|
+
useHotkey
|
|
24
|
+
} from "./chunk-NKLEB5TR.js";
|
|
25
|
+
import {
|
|
26
|
+
nextHeight,
|
|
27
|
+
useAutoGrowTextarea
|
|
28
|
+
} from "./chunk-5CA5RIMH.js";
|
|
29
|
+
import {
|
|
30
|
+
BACK_ZONE_PX,
|
|
31
|
+
CLOSE_DISTANCE_PX,
|
|
32
|
+
FORWARD_ZONE_PX,
|
|
33
|
+
MAX_SWIPE_DURATION_MS,
|
|
34
|
+
OPEN_DISTANCE_PX,
|
|
35
|
+
VERTICAL_CANCEL_PX,
|
|
36
|
+
isInOpenZone,
|
|
37
|
+
isInsideHorizontalScroller,
|
|
38
|
+
resolveSwipeIntent,
|
|
39
|
+
useDrawerSwipe
|
|
40
|
+
} from "./chunk-OZ4PU4E3.js";
|
|
41
|
+
import {
|
|
42
|
+
FOCUSABLE_SELECTOR,
|
|
43
|
+
focusableWithin,
|
|
44
|
+
nextFocusTarget,
|
|
45
|
+
useFocusTrap
|
|
46
|
+
} from "./chunk-DNU57XEJ.js";
|
|
47
|
+
import {
|
|
48
|
+
useEscape
|
|
49
|
+
} from "./chunk-S4YKMGQE.js";
|
|
50
|
+
import {
|
|
51
|
+
copyText,
|
|
52
|
+
useCopyFeedback
|
|
53
|
+
} from "./chunk-3CACI4OQ.js";
|
|
54
|
+
import {
|
|
55
|
+
lockScroll,
|
|
56
|
+
unlockScroll,
|
|
57
|
+
useScrollLock
|
|
58
|
+
} from "./chunk-6KCRVSLS.js";
|
|
59
|
+
import {
|
|
60
|
+
COARSE_POINTER_QUERY,
|
|
61
|
+
REDUCED_MOTION_QUERY,
|
|
62
|
+
useCoarsePointer,
|
|
63
|
+
useMediaQuery,
|
|
64
|
+
useReducedMotion
|
|
65
|
+
} from "./chunk-UZADAINO.js";
|
|
66
|
+
import {
|
|
67
|
+
isOutside,
|
|
68
|
+
isPrimaryPress,
|
|
69
|
+
useOutsidePress
|
|
70
|
+
} from "./chunk-3UGRXQIA.js";
|
|
71
|
+
export {
|
|
72
|
+
BACK_ZONE_PX,
|
|
73
|
+
CLOSE_DISTANCE_PX,
|
|
74
|
+
COARSE_POINTER_QUERY,
|
|
75
|
+
FOCUSABLE_SELECTOR,
|
|
76
|
+
FORWARD_ZONE_PX,
|
|
77
|
+
MAX_SWIPE_DURATION_MS,
|
|
78
|
+
OPEN_DISTANCE_PX,
|
|
79
|
+
REDUCED_MOTION_QUERY,
|
|
80
|
+
VERTICAL_CANCEL_PX,
|
|
81
|
+
copyText,
|
|
82
|
+
createDebouncer,
|
|
83
|
+
detectApple,
|
|
84
|
+
focusableWithin,
|
|
85
|
+
handleBeforeUnload,
|
|
86
|
+
isEditableTarget,
|
|
87
|
+
isInOpenZone,
|
|
88
|
+
isInsideHorizontalScroller,
|
|
89
|
+
isOutside,
|
|
90
|
+
isPrimaryPress,
|
|
91
|
+
lockScroll,
|
|
92
|
+
matchHotkey,
|
|
93
|
+
nextDelay,
|
|
94
|
+
nextFocusTarget,
|
|
95
|
+
nextHeight,
|
|
96
|
+
parseHotkey,
|
|
97
|
+
resolveSwipeIntent,
|
|
98
|
+
unlockScroll,
|
|
99
|
+
useAutoGrowTextarea,
|
|
100
|
+
useCoarsePointer,
|
|
101
|
+
useCopyFeedback,
|
|
102
|
+
useDebouncedCallback,
|
|
103
|
+
useDebouncedValue,
|
|
104
|
+
useDrawerSwipe,
|
|
105
|
+
useEscape,
|
|
106
|
+
useFocusTrap,
|
|
107
|
+
useHotkey,
|
|
108
|
+
useMediaQuery,
|
|
109
|
+
useOutsidePress,
|
|
110
|
+
useReducedMotion,
|
|
111
|
+
useScrollLock,
|
|
112
|
+
useStorageState,
|
|
113
|
+
useUnsavedChangesGuard,
|
|
114
|
+
useVisibilityPolling
|
|
115
|
+
};
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/media-query/index.ts
|
|
22
|
+
var media_query_exports = {};
|
|
23
|
+
__export(media_query_exports, {
|
|
24
|
+
COARSE_POINTER_QUERY: () => COARSE_POINTER_QUERY,
|
|
25
|
+
REDUCED_MOTION_QUERY: () => REDUCED_MOTION_QUERY,
|
|
26
|
+
useCoarsePointer: () => useCoarsePointer,
|
|
27
|
+
useMediaQuery: () => useMediaQuery,
|
|
28
|
+
useReducedMotion: () => useReducedMotion
|
|
29
|
+
});
|
|
30
|
+
module.exports = __toCommonJS(media_query_exports);
|
|
31
|
+
|
|
32
|
+
// src/media-query/use-media-query.ts
|
|
33
|
+
var import_react = require("react");
|
|
34
|
+
|
|
35
|
+
// src/media-query/media-query.ts
|
|
36
|
+
var REDUCED_MOTION_QUERY = "(prefers-reduced-motion: reduce)";
|
|
37
|
+
var COARSE_POINTER_QUERY = "(pointer: coarse)";
|
|
38
|
+
var lists = /* @__PURE__ */ new WeakMap();
|
|
39
|
+
function getList(query) {
|
|
40
|
+
if (typeof window === "undefined" || typeof window.matchMedia !== "function") return null;
|
|
41
|
+
const owner = window.matchMedia;
|
|
42
|
+
let byQuery = lists.get(owner);
|
|
43
|
+
if (!byQuery) {
|
|
44
|
+
byQuery = /* @__PURE__ */ new Map();
|
|
45
|
+
lists.set(owner, byQuery);
|
|
46
|
+
}
|
|
47
|
+
let list = byQuery.get(query);
|
|
48
|
+
if (!list) {
|
|
49
|
+
list = owner.call(window, query);
|
|
50
|
+
byQuery.set(query, list);
|
|
51
|
+
}
|
|
52
|
+
return list;
|
|
53
|
+
}
|
|
54
|
+
function getMatches(query) {
|
|
55
|
+
return getList(query)?.matches ?? null;
|
|
56
|
+
}
|
|
57
|
+
function subscribe(query, onChange) {
|
|
58
|
+
const list = getList(query);
|
|
59
|
+
if (!list) return () => {
|
|
60
|
+
};
|
|
61
|
+
if (typeof list.addEventListener === "function") {
|
|
62
|
+
list.addEventListener("change", onChange);
|
|
63
|
+
return () => list.removeEventListener("change", onChange);
|
|
64
|
+
}
|
|
65
|
+
list.addListener(onChange);
|
|
66
|
+
return () => list.removeListener(onChange);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
// src/media-query/use-media-query.ts
|
|
70
|
+
function useMediaQuery(query, options = {}) {
|
|
71
|
+
const serverDefault = options.serverDefault ?? false;
|
|
72
|
+
const subscribeToQuery = (0, import_react.useCallback)((onChange) => subscribe(query, onChange), [query]);
|
|
73
|
+
const getSnapshot = (0, import_react.useCallback)(() => getMatches(query) ?? serverDefault, [query, serverDefault]);
|
|
74
|
+
const getServerSnapshot = (0, import_react.useCallback)(() => serverDefault, [serverDefault]);
|
|
75
|
+
return (0, import_react.useSyncExternalStore)(subscribeToQuery, getSnapshot, getServerSnapshot);
|
|
76
|
+
}
|
|
77
|
+
function useReducedMotion(options) {
|
|
78
|
+
return useMediaQuery(REDUCED_MOTION_QUERY, options);
|
|
79
|
+
}
|
|
80
|
+
function useCoarsePointer(options) {
|
|
81
|
+
return useMediaQuery(COARSE_POINTER_QUERY, options);
|
|
82
|
+
}
|
|
83
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
84
|
+
0 && (module.exports = {
|
|
85
|
+
COARSE_POINTER_QUERY,
|
|
86
|
+
REDUCED_MOTION_QUERY,
|
|
87
|
+
useCoarsePointer,
|
|
88
|
+
useMediaQuery,
|
|
89
|
+
useReducedMotion
|
|
90
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
interface UseMediaQueryOptions {
|
|
2
|
+
/** Value on the server, during hydration, and where `matchMedia` is missing. Default `false`. */
|
|
3
|
+
serverDefault?: boolean;
|
|
4
|
+
}
|
|
5
|
+
declare function useMediaQuery(query: string, options?: UseMediaQueryOptions): boolean;
|
|
6
|
+
declare function useReducedMotion(options?: UseMediaQueryOptions): boolean;
|
|
7
|
+
declare function useCoarsePointer(options?: UseMediaQueryOptions): boolean;
|
|
8
|
+
|
|
9
|
+
declare const REDUCED_MOTION_QUERY = "(prefers-reduced-motion: reduce)";
|
|
10
|
+
declare const COARSE_POINTER_QUERY = "(pointer: coarse)";
|
|
11
|
+
|
|
12
|
+
export { COARSE_POINTER_QUERY, REDUCED_MOTION_QUERY, type UseMediaQueryOptions, useCoarsePointer, useMediaQuery, useReducedMotion };
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
interface UseMediaQueryOptions {
|
|
2
|
+
/** Value on the server, during hydration, and where `matchMedia` is missing. Default `false`. */
|
|
3
|
+
serverDefault?: boolean;
|
|
4
|
+
}
|
|
5
|
+
declare function useMediaQuery(query: string, options?: UseMediaQueryOptions): boolean;
|
|
6
|
+
declare function useReducedMotion(options?: UseMediaQueryOptions): boolean;
|
|
7
|
+
declare function useCoarsePointer(options?: UseMediaQueryOptions): boolean;
|
|
8
|
+
|
|
9
|
+
declare const REDUCED_MOTION_QUERY = "(prefers-reduced-motion: reduce)";
|
|
10
|
+
declare const COARSE_POINTER_QUERY = "(pointer: coarse)";
|
|
11
|
+
|
|
12
|
+
export { COARSE_POINTER_QUERY, REDUCED_MOTION_QUERY, type UseMediaQueryOptions, useCoarsePointer, useMediaQuery, useReducedMotion };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
COARSE_POINTER_QUERY,
|
|
4
|
+
REDUCED_MOTION_QUERY,
|
|
5
|
+
useCoarsePointer,
|
|
6
|
+
useMediaQuery,
|
|
7
|
+
useReducedMotion
|
|
8
|
+
} from "./chunk-UZADAINO.js";
|
|
9
|
+
export {
|
|
10
|
+
COARSE_POINTER_QUERY,
|
|
11
|
+
REDUCED_MOTION_QUERY,
|
|
12
|
+
useCoarsePointer,
|
|
13
|
+
useMediaQuery,
|
|
14
|
+
useReducedMotion
|
|
15
|
+
};
|
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/outside-press/index.ts
|
|
22
|
+
var outside_press_exports = {};
|
|
23
|
+
__export(outside_press_exports, {
|
|
24
|
+
isOutside: () => isOutside,
|
|
25
|
+
isPrimaryPress: () => isPrimaryPress,
|
|
26
|
+
useOutsidePress: () => useOutsidePress
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(outside_press_exports);
|
|
29
|
+
|
|
30
|
+
// src/outside-press/outside-press.ts
|
|
31
|
+
function isOutside(target, elements) {
|
|
32
|
+
if (!target) return false;
|
|
33
|
+
if (!target.isConnected) return false;
|
|
34
|
+
return !elements.some((el) => el?.contains(target));
|
|
35
|
+
}
|
|
36
|
+
function isPrimaryPress(event) {
|
|
37
|
+
return !(event.pointerType === "mouse" && event.button !== 0);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// src/outside-press/use-outside-press.ts
|
|
41
|
+
var import_react = require("react");
|
|
42
|
+
function useOutsidePress(refs, onOutsidePress, { enabled = true } = {}) {
|
|
43
|
+
const refsRef = (0, import_react.useRef)(refs);
|
|
44
|
+
const handlerRef = (0, import_react.useRef)(onOutsidePress);
|
|
45
|
+
(0, import_react.useEffect)(() => {
|
|
46
|
+
refsRef.current = refs;
|
|
47
|
+
handlerRef.current = onOutsidePress;
|
|
48
|
+
});
|
|
49
|
+
(0, import_react.useEffect)(() => {
|
|
50
|
+
if (!enabled) return;
|
|
51
|
+
function onPointerDown(event) {
|
|
52
|
+
if (!isPrimaryPress(event)) return;
|
|
53
|
+
const list = Array.isArray(refsRef.current) ? refsRef.current : [refsRef.current];
|
|
54
|
+
const elements = list.map((ref) => ref.current);
|
|
55
|
+
if (isOutside(event.target, elements)) handlerRef.current(event);
|
|
56
|
+
}
|
|
57
|
+
document.addEventListener("pointerdown", onPointerDown, true);
|
|
58
|
+
return () => document.removeEventListener("pointerdown", onPointerDown, true);
|
|
59
|
+
}, [enabled]);
|
|
60
|
+
}
|
|
61
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
62
|
+
0 && (module.exports = {
|
|
63
|
+
isOutside,
|
|
64
|
+
isPrimaryPress,
|
|
65
|
+
useOutsidePress
|
|
66
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
|
|
3
|
+
declare function isOutside(target: Node | null, elements: (Element | null)[]): boolean;
|
|
4
|
+
declare function isPrimaryPress(event: {
|
|
5
|
+
button?: number;
|
|
6
|
+
pointerType?: string;
|
|
7
|
+
}): boolean;
|
|
8
|
+
|
|
9
|
+
type ElementRef = RefObject<Element | null>;
|
|
10
|
+
interface UseOutsidePressOptions {
|
|
11
|
+
enabled?: boolean;
|
|
12
|
+
}
|
|
13
|
+
declare function useOutsidePress(refs: ElementRef | ElementRef[], onOutsidePress: (event: PointerEvent) => void, { enabled }?: UseOutsidePressOptions): void;
|
|
14
|
+
|
|
15
|
+
export { type UseOutsidePressOptions, isOutside, isPrimaryPress, useOutsidePress };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
|
|
3
|
+
declare function isOutside(target: Node | null, elements: (Element | null)[]): boolean;
|
|
4
|
+
declare function isPrimaryPress(event: {
|
|
5
|
+
button?: number;
|
|
6
|
+
pointerType?: string;
|
|
7
|
+
}): boolean;
|
|
8
|
+
|
|
9
|
+
type ElementRef = RefObject<Element | null>;
|
|
10
|
+
interface UseOutsidePressOptions {
|
|
11
|
+
enabled?: boolean;
|
|
12
|
+
}
|
|
13
|
+
declare function useOutsidePress(refs: ElementRef | ElementRef[], onOutsidePress: (event: PointerEvent) => void, { enabled }?: UseOutsidePressOptions): void;
|
|
14
|
+
|
|
15
|
+
export { type UseOutsidePressOptions, isOutside, isPrimaryPress, useOutsidePress };
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
"use strict";
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
7
|
+
var __export = (target, all) => {
|
|
8
|
+
for (var name in all)
|
|
9
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
10
|
+
};
|
|
11
|
+
var __copyProps = (to, from, except, desc) => {
|
|
12
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
13
|
+
for (let key of __getOwnPropNames(from))
|
|
14
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
15
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
18
|
+
};
|
|
19
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
20
|
+
|
|
21
|
+
// src/scroll-lock/index.ts
|
|
22
|
+
var scroll_lock_exports = {};
|
|
23
|
+
__export(scroll_lock_exports, {
|
|
24
|
+
lockScroll: () => lockScroll,
|
|
25
|
+
unlockScroll: () => unlockScroll,
|
|
26
|
+
useScrollLock: () => useScrollLock
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(scroll_lock_exports);
|
|
29
|
+
|
|
30
|
+
// src/scroll-lock/use-scroll-lock.ts
|
|
31
|
+
var import_react = require("react");
|
|
32
|
+
|
|
33
|
+
// src/scroll-lock/lock-styles.ts
|
|
34
|
+
var LOCKED_PROPERTIES = [
|
|
35
|
+
"position",
|
|
36
|
+
"top",
|
|
37
|
+
"left",
|
|
38
|
+
"right",
|
|
39
|
+
"width",
|
|
40
|
+
"overflow",
|
|
41
|
+
"paddingRight"
|
|
42
|
+
];
|
|
43
|
+
function computeLockStyles({ scrollY, scrollbarWidth, existingPaddingRight }) {
|
|
44
|
+
const styles = {
|
|
45
|
+
position: "fixed",
|
|
46
|
+
top: `-${scrollY}px`,
|
|
47
|
+
left: "0",
|
|
48
|
+
right: "0",
|
|
49
|
+
width: "100%",
|
|
50
|
+
overflow: "hidden"
|
|
51
|
+
};
|
|
52
|
+
if (scrollbarWidth > 0) styles.paddingRight = `${existingPaddingRight + scrollbarWidth}px`;
|
|
53
|
+
return styles;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// src/scroll-lock/scroll-lock.ts
|
|
57
|
+
var count = 0;
|
|
58
|
+
var saved = null;
|
|
59
|
+
function applyFirstLock() {
|
|
60
|
+
const { body, documentElement } = document;
|
|
61
|
+
const inline = {};
|
|
62
|
+
for (const property of LOCKED_PROPERTIES) inline[property] = body.style[property];
|
|
63
|
+
saved = { scrollY: window.scrollY, inline };
|
|
64
|
+
const styles = computeLockStyles({
|
|
65
|
+
scrollY: saved.scrollY,
|
|
66
|
+
scrollbarWidth: Math.max(0, window.innerWidth - documentElement.clientWidth),
|
|
67
|
+
existingPaddingRight: parseFloat(getComputedStyle(body).paddingRight) || 0
|
|
68
|
+
});
|
|
69
|
+
Object.assign(body.style, styles);
|
|
70
|
+
}
|
|
71
|
+
function restoreLastLock() {
|
|
72
|
+
if (!saved) return;
|
|
73
|
+
const { scrollY, inline } = saved;
|
|
74
|
+
saved = null;
|
|
75
|
+
Object.assign(document.body.style, inline);
|
|
76
|
+
window.scrollTo(0, scrollY);
|
|
77
|
+
}
|
|
78
|
+
function lockScroll() {
|
|
79
|
+
if (count === 0) applyFirstLock();
|
|
80
|
+
count += 1;
|
|
81
|
+
let released = false;
|
|
82
|
+
return () => {
|
|
83
|
+
if (released) return;
|
|
84
|
+
released = true;
|
|
85
|
+
count -= 1;
|
|
86
|
+
if (count === 0) restoreLastLock();
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
function unlockScroll() {
|
|
90
|
+
if (count === 0) return;
|
|
91
|
+
count -= 1;
|
|
92
|
+
if (count === 0) restoreLastLock();
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
// src/scroll-lock/use-scroll-lock.ts
|
|
96
|
+
function useScrollLock(active = true) {
|
|
97
|
+
(0, import_react.useEffect)(() => {
|
|
98
|
+
if (!active) return;
|
|
99
|
+
return lockScroll();
|
|
100
|
+
}, [active]);
|
|
101
|
+
}
|
|
102
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
103
|
+
0 && (module.exports = {
|
|
104
|
+
lockScroll,
|
|
105
|
+
unlockScroll,
|
|
106
|
+
useScrollLock
|
|
107
|
+
});
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
declare function useScrollLock(active?: boolean): void;
|
|
2
|
+
|
|
3
|
+
/** Locks page scroll. Locks are counted; the returned release is safe to call twice. */
|
|
4
|
+
declare function lockScroll(): () => void;
|
|
5
|
+
/** Releases one lock taken with `lockScroll()` that was not released through its own function. */
|
|
6
|
+
declare function unlockScroll(): void;
|
|
7
|
+
|
|
8
|
+
export { lockScroll, unlockScroll, useScrollLock };
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
declare function useScrollLock(active?: boolean): void;
|
|
2
|
+
|
|
3
|
+
/** Locks page scroll. Locks are counted; the returned release is safe to call twice. */
|
|
4
|
+
declare function lockScroll(): () => void;
|
|
5
|
+
/** Releases one lock taken with `lockScroll()` that was not released through its own function. */
|
|
6
|
+
declare function unlockScroll(): void;
|
|
7
|
+
|
|
8
|
+
export { lockScroll, unlockScroll, useScrollLock };
|