@develemit/web-hooks 0.1.0 → 0.3.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 +28 -0
- package/README.md +311 -0
- 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-4PVVTQ5V.js +74 -0
- package/dist/chunk-5CA5RIMH.js +34 -0
- package/dist/chunk-5KIH2XLV.js +136 -0
- package/dist/chunk-5XRVPZHD.js +125 -0
- package/dist/chunk-6KCRVSLS.js +80 -0
- package/dist/chunk-DNU57XEJ.js +82 -0
- package/dist/chunk-DQBKU7HI.js +46 -0
- package/dist/chunk-EXEJI4FK.js +43 -0
- package/dist/chunk-FE3BQD2I.js +44 -0
- package/dist/chunk-HTVNN2NM.js +29 -0
- package/dist/chunk-IWQDAJEP.js +69 -0
- package/dist/chunk-JG3GPTMY.js +101 -0
- package/dist/chunk-LZKAGDER.js +22 -0
- package/dist/chunk-NKLEB5TR.js +98 -0
- package/dist/chunk-S4YKMGQE.js +23 -0
- package/dist/chunk-TNEJ34T5.js +86 -0
- package/dist/chunk-UJ366T3Y.js +146 -0
- package/dist/chunk-UPVNSGIK.js +72 -0
- package/dist/chunk-WVM2LTWQ.js +42 -0
- package/dist/chunk-WXL22EWK.js +21 -0
- package/dist/chunk-YFMMSLMB.js +41 -0
- package/dist/chunk-Z3X27PCA.js +108 -0
- package/dist/clipboard.cjs +18 -0
- package/dist/clipboard.d.cts +10 -1
- package/dist/clipboard.d.ts +10 -1
- package/dist/clipboard.js +8 -57
- 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 +16 -4
- package/dist/drawer-swipe.d.cts +7 -3
- package/dist/drawer-swipe.d.ts +7 -3
- package/dist/drawer-swipe.js +16 -101
- package/dist/escape.cjs +1 -0
- package/dist/escape.js +3 -17
- package/dist/focus-trap.cjs +3 -1
- package/dist/focus-trap.js +6 -72
- 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 +1207 -7
- package/dist/index.d.cts +20 -60
- package/dist/index.d.ts +20 -60
- package/dist/index.js +167 -247
- package/dist/keyboard-inset.cjs +113 -0
- package/dist/keyboard-inset.d.cts +25 -0
- package/dist/keyboard-inset.d.ts +25 -0
- package/dist/keyboard-inset.js +11 -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 +17 -0
- package/dist/online-status.cjs +46 -0
- package/dist/online-status.d.cts +3 -0
- package/dist/online-status.d.ts +3 -0
- package/dist/online-status.js +7 -0
- package/dist/outside-press.cjs +73 -0
- package/dist/outside-press.d.cts +17 -0
- package/dist/outside-press.d.ts +17 -0
- package/dist/outside-press.js +11 -0
- package/dist/push.cjs +201 -0
- package/dist/push.d.cts +37 -0
- package/dist/push.d.ts +37 -0
- package/dist/push.js +14 -0
- package/dist/pwa.cjs +198 -0
- package/dist/pwa.d.cts +35 -0
- package/dist/pwa.d.ts +35 -0
- package/dist/pwa.js +22 -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/service-worker.cjs +128 -0
- package/dist/service-worker.d.cts +23 -0
- package/dist/service-worker.d.ts +23 -0
- package/dist/service-worker.js +11 -0
- package/dist/share.cjs +139 -0
- package/dist/share.d.cts +23 -0
- package/dist/share.d.ts +23 -0
- package/dist/share.js +16 -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 +85 -2
|
@@ -0,0 +1,113 @@
|
|
|
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/keyboard-inset/index.ts
|
|
22
|
+
var keyboard_inset_exports = {};
|
|
23
|
+
__export(keyboard_inset_exports, {
|
|
24
|
+
computeKeyboardInset: () => computeKeyboardInset,
|
|
25
|
+
isEditableElement: () => isEditableElement,
|
|
26
|
+
useKeyboardInset: () => useKeyboardInset
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(keyboard_inset_exports);
|
|
29
|
+
|
|
30
|
+
// src/keyboard-inset/use-keyboard-inset.ts
|
|
31
|
+
var import_react = require("react");
|
|
32
|
+
|
|
33
|
+
// src/keyboard-inset/compute-inset.ts
|
|
34
|
+
var DEFAULT_MIN_INSET = 150;
|
|
35
|
+
function computeKeyboardInset(r) {
|
|
36
|
+
if (!r.editableFocused) return 0;
|
|
37
|
+
const occluded = r.layoutHeight - r.visualHeight - r.visualOffsetTop;
|
|
38
|
+
return occluded >= (r.minInset ?? DEFAULT_MIN_INSET) ? Math.round(occluded) : 0;
|
|
39
|
+
}
|
|
40
|
+
var NON_TEXT_INPUT_TYPES = /* @__PURE__ */ new Set([
|
|
41
|
+
"button",
|
|
42
|
+
"checkbox",
|
|
43
|
+
"radio",
|
|
44
|
+
"range",
|
|
45
|
+
"submit",
|
|
46
|
+
"reset",
|
|
47
|
+
"file",
|
|
48
|
+
"color",
|
|
49
|
+
"image",
|
|
50
|
+
"hidden"
|
|
51
|
+
]);
|
|
52
|
+
function isEditableElement(el) {
|
|
53
|
+
if (!el) return false;
|
|
54
|
+
const tag = el.tagName.toLowerCase();
|
|
55
|
+
if (tag === "select") return !el.disabled;
|
|
56
|
+
if (tag === "textarea" || tag === "input") {
|
|
57
|
+
const field = el;
|
|
58
|
+
if (field.readOnly || field.disabled) return false;
|
|
59
|
+
return tag === "textarea" || !NON_TEXT_INPUT_TYPES.has(field.type);
|
|
60
|
+
}
|
|
61
|
+
if (el.isContentEditable === true) return true;
|
|
62
|
+
const attr = el.getAttribute("contenteditable");
|
|
63
|
+
return attr !== null && attr !== "false";
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
// src/keyboard-inset/use-keyboard-inset.ts
|
|
67
|
+
function useKeyboardInset({ minInset = DEFAULT_MIN_INSET, enabled = true } = {}) {
|
|
68
|
+
const [inset, setInset] = (0, import_react.useState)(0);
|
|
69
|
+
(0, import_react.useEffect)(() => {
|
|
70
|
+
const vv = typeof window === "undefined" ? null : window.visualViewport;
|
|
71
|
+
if (!enabled || !vv) {
|
|
72
|
+
setInset(0);
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const update = () => setInset(
|
|
76
|
+
computeKeyboardInset({
|
|
77
|
+
layoutHeight: window.innerHeight,
|
|
78
|
+
visualHeight: vv.height,
|
|
79
|
+
visualOffsetTop: vv.offsetTop,
|
|
80
|
+
editableFocused: isEditableElement(document.activeElement),
|
|
81
|
+
minInset
|
|
82
|
+
})
|
|
83
|
+
);
|
|
84
|
+
let frame = 0;
|
|
85
|
+
const onFocusOut = () => {
|
|
86
|
+
cancelAnimationFrame(frame);
|
|
87
|
+
frame = requestAnimationFrame(update);
|
|
88
|
+
};
|
|
89
|
+
const onFocusIn = () => {
|
|
90
|
+
cancelAnimationFrame(frame);
|
|
91
|
+
update();
|
|
92
|
+
};
|
|
93
|
+
vv.addEventListener("resize", update);
|
|
94
|
+
vv.addEventListener("scroll", update);
|
|
95
|
+
document.addEventListener("focusin", onFocusIn);
|
|
96
|
+
document.addEventListener("focusout", onFocusOut);
|
|
97
|
+
update();
|
|
98
|
+
return () => {
|
|
99
|
+
cancelAnimationFrame(frame);
|
|
100
|
+
vv.removeEventListener("resize", update);
|
|
101
|
+
vv.removeEventListener("scroll", update);
|
|
102
|
+
document.removeEventListener("focusin", onFocusIn);
|
|
103
|
+
document.removeEventListener("focusout", onFocusOut);
|
|
104
|
+
};
|
|
105
|
+
}, [enabled, minInset]);
|
|
106
|
+
return inset;
|
|
107
|
+
}
|
|
108
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
109
|
+
0 && (module.exports = {
|
|
110
|
+
computeKeyboardInset,
|
|
111
|
+
isEditableElement,
|
|
112
|
+
useKeyboardInset
|
|
113
|
+
});
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
interface UseKeyboardInsetOptions {
|
|
2
|
+
minInset?: number;
|
|
3
|
+
enabled?: boolean;
|
|
4
|
+
}
|
|
5
|
+
declare function useKeyboardInset({ minInset, enabled }?: UseKeyboardInsetOptions): number;
|
|
6
|
+
|
|
7
|
+
interface InsetReading {
|
|
8
|
+
layoutHeight: number;
|
|
9
|
+
visualHeight: number;
|
|
10
|
+
visualOffsetTop: number;
|
|
11
|
+
editableFocused: boolean;
|
|
12
|
+
minInset?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* How far the keyboard covers the bottom of the layout viewport. Zero unless a
|
|
16
|
+
* text field is focused: on newer iPhones the standalone PWA reports a gap
|
|
17
|
+
* between the layout and visual viewport with no keyboard up, which padded the
|
|
18
|
+
* composer ~100pt off the bottom of the screen. The smallest iOS keyboard is
|
|
19
|
+
* well over `minInset`; anything less is viewport noise (home-indicator area,
|
|
20
|
+
* toolbar, a stale post-dismiss offset).
|
|
21
|
+
*/
|
|
22
|
+
declare function computeKeyboardInset(r: InsetReading): number;
|
|
23
|
+
declare function isEditableElement(el: Element | null | undefined): boolean;
|
|
24
|
+
|
|
25
|
+
export { type InsetReading, type UseKeyboardInsetOptions, computeKeyboardInset, isEditableElement, useKeyboardInset };
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
interface UseKeyboardInsetOptions {
|
|
2
|
+
minInset?: number;
|
|
3
|
+
enabled?: boolean;
|
|
4
|
+
}
|
|
5
|
+
declare function useKeyboardInset({ minInset, enabled }?: UseKeyboardInsetOptions): number;
|
|
6
|
+
|
|
7
|
+
interface InsetReading {
|
|
8
|
+
layoutHeight: number;
|
|
9
|
+
visualHeight: number;
|
|
10
|
+
visualOffsetTop: number;
|
|
11
|
+
editableFocused: boolean;
|
|
12
|
+
minInset?: number;
|
|
13
|
+
}
|
|
14
|
+
/**
|
|
15
|
+
* How far the keyboard covers the bottom of the layout viewport. Zero unless a
|
|
16
|
+
* text field is focused: on newer iPhones the standalone PWA reports a gap
|
|
17
|
+
* between the layout and visual viewport with no keyboard up, which padded the
|
|
18
|
+
* composer ~100pt off the bottom of the screen. The smallest iOS keyboard is
|
|
19
|
+
* well over `minInset`; anything less is viewport noise (home-indicator area,
|
|
20
|
+
* toolbar, a stale post-dismiss offset).
|
|
21
|
+
*/
|
|
22
|
+
declare function computeKeyboardInset(r: InsetReading): number;
|
|
23
|
+
declare function isEditableElement(el: Element | null | undefined): boolean;
|
|
24
|
+
|
|
25
|
+
export { type InsetReading, type UseKeyboardInsetOptions, computeKeyboardInset, isEditableElement, useKeyboardInset };
|
|
@@ -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,17 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
import {
|
|
3
|
+
useCoarsePointer,
|
|
4
|
+
useMediaQuery,
|
|
5
|
+
useReducedMotion
|
|
6
|
+
} from "./chunk-HTVNN2NM.js";
|
|
7
|
+
import {
|
|
8
|
+
COARSE_POINTER_QUERY,
|
|
9
|
+
REDUCED_MOTION_QUERY
|
|
10
|
+
} from "./chunk-WVM2LTWQ.js";
|
|
11
|
+
export {
|
|
12
|
+
COARSE_POINTER_QUERY,
|
|
13
|
+
REDUCED_MOTION_QUERY,
|
|
14
|
+
useCoarsePointer,
|
|
15
|
+
useMediaQuery,
|
|
16
|
+
useReducedMotion
|
|
17
|
+
};
|
|
@@ -0,0 +1,46 @@
|
|
|
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/online-status/index.ts
|
|
22
|
+
var online_status_exports = {};
|
|
23
|
+
__export(online_status_exports, {
|
|
24
|
+
useOnlineStatus: () => useOnlineStatus
|
|
25
|
+
});
|
|
26
|
+
module.exports = __toCommonJS(online_status_exports);
|
|
27
|
+
|
|
28
|
+
// src/online-status/use-online-status.ts
|
|
29
|
+
var import_react = require("react");
|
|
30
|
+
function subscribe(callback) {
|
|
31
|
+
window.addEventListener("online", callback);
|
|
32
|
+
window.addEventListener("offline", callback);
|
|
33
|
+
return () => {
|
|
34
|
+
window.removeEventListener("online", callback);
|
|
35
|
+
window.removeEventListener("offline", callback);
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
var getSnapshot = () => navigator.onLine;
|
|
39
|
+
var getServerSnapshot = () => true;
|
|
40
|
+
function useOnlineStatus() {
|
|
41
|
+
return (0, import_react.useSyncExternalStore)(subscribe, getSnapshot, getServerSnapshot);
|
|
42
|
+
}
|
|
43
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
44
|
+
0 && (module.exports = {
|
|
45
|
+
useOnlineStatus
|
|
46
|
+
});
|
|
@@ -0,0 +1,73 @@
|
|
|
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, ignoreSelector) {
|
|
32
|
+
if (!target) return false;
|
|
33
|
+
if (!target.isConnected) return false;
|
|
34
|
+
if (ignoreSelector && isInIgnoredRegion(target, ignoreSelector)) return false;
|
|
35
|
+
return !elements.some((el) => el?.contains(target));
|
|
36
|
+
}
|
|
37
|
+
function isPrimaryPress(event) {
|
|
38
|
+
return !(event.pointerType === "mouse" && event.button !== 0);
|
|
39
|
+
}
|
|
40
|
+
function isInIgnoredRegion(target, selector) {
|
|
41
|
+
const element = target instanceof Element ? target : target.parentElement;
|
|
42
|
+
return element?.closest(selector) != null;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// src/outside-press/use-outside-press.ts
|
|
46
|
+
var import_react = require("react");
|
|
47
|
+
function useOutsidePress(refs, onOutsidePress, { enabled = true, ignore } = {}) {
|
|
48
|
+
const refsRef = (0, import_react.useRef)(refs);
|
|
49
|
+
const handlerRef = (0, import_react.useRef)(onOutsidePress);
|
|
50
|
+
const ignoreRef = (0, import_react.useRef)(ignore);
|
|
51
|
+
(0, import_react.useEffect)(() => {
|
|
52
|
+
ignoreRef.current = ignore;
|
|
53
|
+
refsRef.current = refs;
|
|
54
|
+
handlerRef.current = onOutsidePress;
|
|
55
|
+
});
|
|
56
|
+
(0, import_react.useEffect)(() => {
|
|
57
|
+
if (!enabled) return;
|
|
58
|
+
function onPointerDown(event) {
|
|
59
|
+
if (!isPrimaryPress(event)) return;
|
|
60
|
+
const list = Array.isArray(refsRef.current) ? refsRef.current : [refsRef.current];
|
|
61
|
+
const elements = list.map((ref) => ref.current);
|
|
62
|
+
if (isOutside(event.target, elements, ignoreRef.current)) handlerRef.current(event);
|
|
63
|
+
}
|
|
64
|
+
document.addEventListener("pointerdown", onPointerDown, true);
|
|
65
|
+
return () => document.removeEventListener("pointerdown", onPointerDown, true);
|
|
66
|
+
}, [enabled]);
|
|
67
|
+
}
|
|
68
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
69
|
+
0 && (module.exports = {
|
|
70
|
+
isOutside,
|
|
71
|
+
isPrimaryPress,
|
|
72
|
+
useOutsidePress
|
|
73
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
|
|
3
|
+
declare function isOutside(target: Node | null, elements: (Element | null)[], ignoreSelector?: string | 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
|
+
/** A press inside an element matching this selector counts as inside. */
|
|
13
|
+
ignore?: string;
|
|
14
|
+
}
|
|
15
|
+
declare function useOutsidePress(refs: ElementRef | ElementRef[], onOutsidePress: (event: PointerEvent) => void, { enabled, ignore }?: UseOutsidePressOptions): void;
|
|
16
|
+
|
|
17
|
+
export { type UseOutsidePressOptions, isOutside, isPrimaryPress, useOutsidePress };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { RefObject } from 'react';
|
|
2
|
+
|
|
3
|
+
declare function isOutside(target: Node | null, elements: (Element | null)[], ignoreSelector?: string | 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
|
+
/** A press inside an element matching this selector counts as inside. */
|
|
13
|
+
ignore?: string;
|
|
14
|
+
}
|
|
15
|
+
declare function useOutsidePress(refs: ElementRef | ElementRef[], onOutsidePress: (event: PointerEvent) => void, { enabled, ignore }?: UseOutsidePressOptions): void;
|
|
16
|
+
|
|
17
|
+
export { type UseOutsidePressOptions, isOutside, isPrimaryPress, useOutsidePress };
|