@mantine/hooks 5.8.4 → 5.9.1
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/cjs/index.js +2 -0
- package/cjs/index.js.map +1 -1
- package/cjs/use-eye-dropper/use-eye-dropper.js +24 -0
- package/cjs/use-eye-dropper/use-eye-dropper.js.map +1 -0
- package/cjs/use-hash/use-hash.js +8 -4
- package/cjs/use-hash/use-hash.js.map +1 -1
- package/cjs/use-hotkeys/parse-hotkey.js +4 -2
- package/cjs/use-hotkeys/parse-hotkey.js.map +1 -1
- package/cjs/use-hotkeys/use-hotkeys.js +8 -6
- package/cjs/use-hotkeys/use-hotkeys.js.map +1 -1
- package/cjs/use-media-query/use-media-query.js +1 -1
- package/cjs/use-media-query/use-media-query.js.map +1 -1
- package/esm/index.js +1 -0
- package/esm/index.js.map +1 -1
- package/esm/use-eye-dropper/use-eye-dropper.js +20 -0
- package/esm/use-eye-dropper/use-eye-dropper.js.map +1 -0
- package/esm/use-hash/use-hash.js +8 -4
- package/esm/use-hash/use-hash.js.map +1 -1
- package/esm/use-hotkeys/parse-hotkey.js +4 -2
- package/esm/use-hotkeys/parse-hotkey.js.map +1 -1
- package/esm/use-hotkeys/use-hotkeys.js +8 -6
- package/esm/use-hotkeys/use-hotkeys.js.map +1 -1
- package/esm/use-media-query/use-media-query.js +1 -1
- package/esm/use-media-query/use-media-query.js.map +1 -1
- package/lib/index.d.ts +2 -0
- package/lib/index.d.ts.map +1 -1
- package/lib/use-eye-dropper/use-eye-dropper.d.ts +12 -0
- package/lib/use-eye-dropper/use-eye-dropper.d.ts.map +1 -0
- package/lib/use-hash/use-hash.d.ts.map +1 -1
- package/lib/use-hotkeys/parse-hotkey.d.ts +8 -1
- package/lib/use-hotkeys/parse-hotkey.d.ts.map +1 -1
- package/lib/use-hotkeys/use-hotkeys.d.ts +4 -3
- package/lib/use-hotkeys/use-hotkeys.d.ts.map +1 -1
- package/package.json +1 -1
package/cjs/index.js
CHANGED
|
@@ -56,6 +56,7 @@ var useTimeout = require('./use-timeout/use-timeout.js');
|
|
|
56
56
|
var useTextSelection = require('./use-text-selection/use-text-selection.js');
|
|
57
57
|
var usePrevious = require('./use-previous/use-previous.js');
|
|
58
58
|
var useFavicon = require('./use-favicon/use-favicon.js');
|
|
59
|
+
var useEyeDropper = require('./use-eye-dropper/use-eye-dropper.js');
|
|
59
60
|
var parseHotkey = require('./use-hotkeys/parse-hotkey.js');
|
|
60
61
|
var assignRef = require('./utils/assign-ref/assign-ref.js');
|
|
61
62
|
var clamp = require('./utils/clamp/clamp.js');
|
|
@@ -124,6 +125,7 @@ exports.useTimeout = useTimeout.useTimeout;
|
|
|
124
125
|
exports.useTextSelection = useTextSelection.useTextSelection;
|
|
125
126
|
exports.usePrevious = usePrevious.usePrevious;
|
|
126
127
|
exports.useFavicon = useFavicon.useFavicon;
|
|
128
|
+
exports.useEyeDropper = useEyeDropper.useEyeDropper;
|
|
127
129
|
exports.getHotkeyHandler = parseHotkey.getHotkeyHandler;
|
|
128
130
|
exports.assignRef = assignRef.assignRef;
|
|
129
131
|
exports.clamp = clamp.clamp;
|
package/cjs/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
+
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var useIsomorphicEffect = require('../use-isomorphic-effect/use-isomorphic-effect.js');
|
|
7
|
+
|
|
8
|
+
function useEyeDropper() {
|
|
9
|
+
const [supported, setSupported] = React.useState(false);
|
|
10
|
+
useIsomorphicEffect.useIsomorphicEffect(() => {
|
|
11
|
+
setSupported(typeof window !== "undefined" && "EyeDropper" in window);
|
|
12
|
+
}, []);
|
|
13
|
+
const open = React.useCallback((options = {}) => {
|
|
14
|
+
if (supported) {
|
|
15
|
+
const eyeDropper = new window.EyeDropper();
|
|
16
|
+
return eyeDropper.open(options);
|
|
17
|
+
}
|
|
18
|
+
return void 0;
|
|
19
|
+
}, [supported]);
|
|
20
|
+
return { supported, open };
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
exports.useEyeDropper = useEyeDropper;
|
|
24
|
+
//# sourceMappingURL=use-eye-dropper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-eye-dropper.js","sources":["../../src/use-eye-dropper/use-eye-dropper.ts"],"sourcesContent":["import { useCallback, useState } from 'react';\nimport { useIsomorphicEffect } from '../use-isomorphic-effect/use-isomorphic-effect';\n\ninterface EyeDropperOpenOptions {\n signal?: AbortSignal;\n}\n\nexport interface EyeDropperOpenReturnType {\n sRGBHex: string;\n}\n\nexport function useEyeDropper() {\n const [supported, setSupported] = useState(false);\n\n useIsomorphicEffect(() => {\n setSupported(typeof window !== 'undefined' && 'EyeDropper' in window);\n }, []);\n\n const open = useCallback(\n (options: EyeDropperOpenOptions = {}): Promise<EyeDropperOpenReturnType> => {\n if (supported) {\n const eyeDropper = new (window as any).EyeDropper();\n return eyeDropper.open(options);\n }\n\n return undefined;\n },\n [supported]\n );\n\n return { supported, open };\n}\n"],"names":["useState","useIsomorphicEffect","useCallback"],"mappings":";;;;;;;AAEO,SAAS,aAAa,GAAG;AAChC,EAAE,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAGA,cAAQ,CAAC,KAAK,CAAC,CAAC;AACpD,EAAEC,uCAAmB,CAAC,MAAM;AAC5B,IAAI,YAAY,CAAC,OAAO,MAAM,KAAK,WAAW,IAAI,YAAY,IAAI,MAAM,CAAC,CAAC;AAC1E,GAAG,EAAE,EAAE,CAAC,CAAC;AACT,EAAE,MAAM,IAAI,GAAGC,iBAAW,CAAC,CAAC,OAAO,GAAG,EAAE,KAAK;AAC7C,IAAI,IAAI,SAAS,EAAE;AACnB,MAAM,MAAM,UAAU,GAAG,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;AACjD,MAAM,OAAO,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACtC,KAAK;AACL,IAAI,OAAO,KAAK,CAAC,CAAC;AAClB,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;AAClB,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;AAC7B;;;;"}
|
package/cjs/use-hash/use-hash.js
CHANGED
|
@@ -8,14 +8,18 @@ var useWindowEvent = require('../use-window-event/use-window-event.js');
|
|
|
8
8
|
function useHash() {
|
|
9
9
|
const [hash, setHashValue] = React.useState("");
|
|
10
10
|
const setHash = (value) => {
|
|
11
|
-
|
|
12
|
-
|
|
11
|
+
const valueWithHash = value.startsWith("#") ? value : `#${value}`;
|
|
12
|
+
window.location.hash = valueWithHash;
|
|
13
|
+
setHashValue(valueWithHash);
|
|
13
14
|
};
|
|
14
15
|
useWindowEvent.useWindowEvent("hashchange", () => {
|
|
15
|
-
|
|
16
|
+
const newHash = window.location.hash;
|
|
17
|
+
if (hash !== newHash) {
|
|
18
|
+
setHashValue(hash);
|
|
19
|
+
}
|
|
16
20
|
});
|
|
17
21
|
React.useEffect(() => {
|
|
18
|
-
|
|
22
|
+
setHashValue(window.location.hash);
|
|
19
23
|
}, []);
|
|
20
24
|
return [hash, setHash];
|
|
21
25
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-hash.js","sources":["../../src/use-hash/use-hash.ts"],"sourcesContent":["import { useState, useEffect } from 'react';\nimport { useWindowEvent } from '../use-window-event/use-window-event';\n\nexport function useHash() {\n const [hash, setHashValue] = useState<string>('');\n\n const setHash = (value: string) => {\n window.location.hash =
|
|
1
|
+
{"version":3,"file":"use-hash.js","sources":["../../src/use-hash/use-hash.ts"],"sourcesContent":["import { useState, useEffect } from 'react';\nimport { useWindowEvent } from '../use-window-event/use-window-event';\n\nexport function useHash() {\n const [hash, setHashValue] = useState<string>('');\n\n const setHash = (value: string) => {\n const valueWithHash = value.startsWith('#') ? value : `#${value}`;\n window.location.hash = valueWithHash;\n setHashValue(valueWithHash);\n };\n\n useWindowEvent('hashchange', () => {\n const newHash = window.location.hash;\n if (hash !== newHash) {\n setHashValue(hash);\n }\n });\n\n useEffect(() => {\n setHashValue(window.location.hash);\n }, []);\n\n return [hash, setHash] as const;\n}\n"],"names":["useState","useWindowEvent","useEffect"],"mappings":";;;;;;;AAEO,SAAS,OAAO,GAAG;AAC1B,EAAE,MAAM,CAAC,IAAI,EAAE,YAAY,CAAC,GAAGA,cAAQ,CAAC,EAAE,CAAC,CAAC;AAC5C,EAAE,MAAM,OAAO,GAAG,CAAC,KAAK,KAAK;AAC7B,IAAI,MAAM,aAAa,GAAG,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;AACtE,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,GAAG,aAAa,CAAC;AACzC,IAAI,YAAY,CAAC,aAAa,CAAC,CAAC;AAChC,GAAG,CAAC;AACJ,EAAEC,6BAAc,CAAC,YAAY,EAAE,MAAM;AACrC,IAAI,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;AACzC,IAAI,IAAI,IAAI,KAAK,OAAO,EAAE;AAC1B,MAAM,YAAY,CAAC,IAAI,CAAC,CAAC;AACzB,KAAK;AACL,GAAG,CAAC,CAAC;AACL,EAAEC,eAAS,CAAC,MAAM;AAClB,IAAI,YAAY,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AACvC,GAAG,EAAE,EAAE,CAAC,CAAC;AACT,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AACzB;;;;"}
|
|
@@ -68,9 +68,11 @@ function getHotkeyMatcher(hotkey) {
|
|
|
68
68
|
function getHotkeyHandler(hotkeys) {
|
|
69
69
|
return (event) => {
|
|
70
70
|
const _event = "nativeEvent" in event ? event.nativeEvent : event;
|
|
71
|
-
hotkeys.forEach(([hotkey, handler]) => {
|
|
71
|
+
hotkeys.forEach(([hotkey, handler, options = { preventDefault: true }]) => {
|
|
72
72
|
if (getHotkeyMatcher(hotkey)(_event)) {
|
|
73
|
-
|
|
73
|
+
if (options.preventDefault) {
|
|
74
|
+
event.preventDefault();
|
|
75
|
+
}
|
|
74
76
|
handler(_event);
|
|
75
77
|
}
|
|
76
78
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-hotkey.js","sources":["../../src/use-hotkeys/parse-hotkey.ts"],"sourcesContent":["export type KeyboardModifiers = {\n alt: boolean;\n ctrl: boolean;\n meta: boolean;\n mod: boolean;\n shift: boolean;\n};\n\nexport type Hotkey = KeyboardModifiers & {\n key?: string;\n};\n\ntype CheckHotkeyMatch = (event: KeyboardEvent) => boolean;\n\nexport function parseHotkey(hotkey: string): Hotkey {\n const keys = hotkey\n .toLowerCase()\n .split('+')\n .map((part) => part.trim());\n\n const modifiers: KeyboardModifiers = {\n alt: keys.includes('alt'),\n ctrl: keys.includes('ctrl'),\n meta: keys.includes('meta'),\n mod: keys.includes('mod'),\n shift: keys.includes('shift'),\n };\n\n const reservedKeys = ['alt', 'ctrl', 'meta', 'shift', 'mod'];\n\n const freeKey = keys.find((key) => !reservedKeys.includes(key));\n\n return {\n ...modifiers,\n key: freeKey,\n };\n}\n\nfunction isExactHotkey(hotkey: Hotkey, event: KeyboardEvent): boolean {\n const { alt, ctrl, meta, mod, shift, key } = hotkey;\n const { altKey, ctrlKey, metaKey, shiftKey, key: pressedKey } = event;\n\n if (alt !== altKey) {\n return false;\n }\n\n if (mod) {\n if (!ctrlKey && !metaKey) {\n return false;\n }\n } else {\n if (ctrl !== ctrlKey) {\n return false;\n }\n if (meta !== metaKey) {\n return false;\n }\n }\n if (shift !== shiftKey) {\n return false;\n }\n\n if (\n key &&\n (pressedKey.toLowerCase() === key.toLowerCase() ||\n event.code.replace('Key', '').toLowerCase() === key.toLowerCase())\n ) {\n return true;\n }\n\n return false;\n}\n\nexport function getHotkeyMatcher(hotkey: string): CheckHotkeyMatch {\n return (event) => isExactHotkey(parseHotkey(hotkey), event);\n}\n\ntype HotkeyItem = [string
|
|
1
|
+
{"version":3,"file":"parse-hotkey.js","sources":["../../src/use-hotkeys/parse-hotkey.ts"],"sourcesContent":["export type KeyboardModifiers = {\n alt: boolean;\n ctrl: boolean;\n meta: boolean;\n mod: boolean;\n shift: boolean;\n};\n\nexport type Hotkey = KeyboardModifiers & {\n key?: string;\n};\n\ntype CheckHotkeyMatch = (event: KeyboardEvent) => boolean;\n\nexport function parseHotkey(hotkey: string): Hotkey {\n const keys = hotkey\n .toLowerCase()\n .split('+')\n .map((part) => part.trim());\n\n const modifiers: KeyboardModifiers = {\n alt: keys.includes('alt'),\n ctrl: keys.includes('ctrl'),\n meta: keys.includes('meta'),\n mod: keys.includes('mod'),\n shift: keys.includes('shift'),\n };\n\n const reservedKeys = ['alt', 'ctrl', 'meta', 'shift', 'mod'];\n\n const freeKey = keys.find((key) => !reservedKeys.includes(key));\n\n return {\n ...modifiers,\n key: freeKey,\n };\n}\n\nfunction isExactHotkey(hotkey: Hotkey, event: KeyboardEvent): boolean {\n const { alt, ctrl, meta, mod, shift, key } = hotkey;\n const { altKey, ctrlKey, metaKey, shiftKey, key: pressedKey } = event;\n\n if (alt !== altKey) {\n return false;\n }\n\n if (mod) {\n if (!ctrlKey && !metaKey) {\n return false;\n }\n } else {\n if (ctrl !== ctrlKey) {\n return false;\n }\n if (meta !== metaKey) {\n return false;\n }\n }\n if (shift !== shiftKey) {\n return false;\n }\n\n if (\n key &&\n (pressedKey.toLowerCase() === key.toLowerCase() ||\n event.code.replace('Key', '').toLowerCase() === key.toLowerCase())\n ) {\n return true;\n }\n\n return false;\n}\n\nexport function getHotkeyMatcher(hotkey: string): CheckHotkeyMatch {\n return (event) => isExactHotkey(parseHotkey(hotkey), event);\n}\n\nexport interface HotkeyItemOptions {\n preventDefault?: boolean;\n}\n\ntype HotkeyItem = [\n string,\n (event: React.KeyboardEvent<HTMLElement> | KeyboardEvent) => void,\n HotkeyItemOptions?\n];\n\nexport function getHotkeyHandler(hotkeys: HotkeyItem[]) {\n return (event: React.KeyboardEvent<HTMLElement> | KeyboardEvent) => {\n const _event = 'nativeEvent' in event ? event.nativeEvent : event;\n hotkeys.forEach(([hotkey, handler, options = { preventDefault: true }]) => {\n if (getHotkeyMatcher(hotkey)(_event)) {\n if (options.preventDefault) {\n event.preventDefault();\n }\n\n handler(_event);\n }\n });\n };\n}\n"],"names":[],"mappings":";;;;AAAA,IAAI,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC;AACtC,IAAI,UAAU,GAAG,MAAM,CAAC,gBAAgB,CAAC;AACzC,IAAI,iBAAiB,GAAG,MAAM,CAAC,yBAAyB,CAAC;AACzD,IAAI,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC;AACvD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC;AACnD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,oBAAoB,CAAC;AACzD,IAAI,eAAe,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,KAAK,GAAG,IAAI,GAAG,GAAG,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAChK,IAAI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AAI,KAAK,CAAC,IAAI,CAAC,OAAO,CAAC,KAAK,EAAE,EAAE,CAAC,CAAC,WAAW,EAAE,KAAK,GAAG,CAAC,WAAW,EAAE,CAAC,EAAE;AACpI,IAAI,OAAO,IAAI,CAAC;AAChB,GAAG;AACH,EAAE,OAAO,KAAK,CAAC;AACf,CAAC;AACM,SAAS,gBAAgB,CAAC,MAAM,EAAE;AACzC,EAAE,OAAO,CAAC,KAAK,KAAK,aAAa,CAAC,WAAW,CAAC,MAAM,CAAC,EAAE,KAAK,CAAC,CAAC;AAC9D,CAAC;AACM,SAAS,gBAAgB,CAAC,OAAO,EAAE;AAC1C,EAAE,OAAO,CAAC,KAAK,KAAK;AACpB,IAAI,MAAM,MAAM,GAAG,aAAa,IAAI,KAAK,GAAG,KAAK,CAAC,WAAW,GAAG,KAAK,CAAC;AACtE,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC,KAAK;AAC/E,MAAM,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,EAAE;AAC5C,QAAQ,IAAI,OAAO,CAAC,cAAc,EAAE;AACpC,UAAU,KAAK,CAAC,cAAc,EAAE,CAAC;AACjC,SAAS;AACT,QAAQ,OAAO,CAAC,MAAM,CAAC,CAAC;AACxB,OAAO;AACP,KAAK,CAAC,CAAC;AACP,GAAG,CAAC;AACJ;;;;;;"}
|
|
@@ -5,18 +5,20 @@ Object.defineProperty(exports, '__esModule', { value: true });
|
|
|
5
5
|
var React = require('react');
|
|
6
6
|
var parseHotkey = require('./parse-hotkey.js');
|
|
7
7
|
|
|
8
|
-
function shouldFireEvent(event) {
|
|
8
|
+
function shouldFireEvent(event, tagsToIgnore) {
|
|
9
9
|
if (event.target instanceof HTMLElement) {
|
|
10
|
-
return !event.target.isContentEditable && !
|
|
10
|
+
return !event.target.isContentEditable && !tagsToIgnore.includes(event.target.tagName);
|
|
11
11
|
}
|
|
12
12
|
return true;
|
|
13
13
|
}
|
|
14
|
-
function useHotkeys(hotkeys) {
|
|
14
|
+
function useHotkeys(hotkeys, tagsToIgnore = ["INPUT", "TEXTAREA", "SELECT"]) {
|
|
15
15
|
React.useEffect(() => {
|
|
16
16
|
const keydownListener = (event) => {
|
|
17
|
-
hotkeys.forEach(([hotkey, handler]) => {
|
|
18
|
-
if (parseHotkey.getHotkeyMatcher(hotkey)(event) && shouldFireEvent(event)) {
|
|
19
|
-
|
|
17
|
+
hotkeys.forEach(([hotkey, handler, options = { preventDefault: true }]) => {
|
|
18
|
+
if (parseHotkey.getHotkeyMatcher(hotkey)(event) && shouldFireEvent(event, tagsToIgnore)) {
|
|
19
|
+
if (options.preventDefault) {
|
|
20
|
+
event.preventDefault();
|
|
21
|
+
}
|
|
20
22
|
handler(event);
|
|
21
23
|
}
|
|
22
24
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-hotkeys.js","sources":["../../src/use-hotkeys/use-hotkeys.ts"],"sourcesContent":["import { useEffect } from 'react';\nimport { getHotkeyMatcher, getHotkeyHandler } from './parse-hotkey';\n\nexport { getHotkeyHandler };\n\nexport type HotkeyItem = [string, (event: KeyboardEvent) => void];\n\nfunction shouldFireEvent(event: KeyboardEvent) {\n if (event.target instanceof HTMLElement) {\n return
|
|
1
|
+
{"version":3,"file":"use-hotkeys.js","sources":["../../src/use-hotkeys/use-hotkeys.ts"],"sourcesContent":["import { useEffect } from 'react';\nimport { getHotkeyMatcher, getHotkeyHandler, HotkeyItemOptions } from './parse-hotkey';\n\nexport type { HotkeyItemOptions };\nexport { getHotkeyHandler };\n\nexport type HotkeyItem = [string, (event: KeyboardEvent) => void, HotkeyItemOptions?];\n\nfunction shouldFireEvent(event: KeyboardEvent, tagsToIgnore: string[]) {\n if (event.target instanceof HTMLElement) {\n return !event.target.isContentEditable && !tagsToIgnore.includes(event.target.tagName);\n }\n return true;\n}\n\nexport function useHotkeys(\n hotkeys: HotkeyItem[],\n tagsToIgnore: string[] = ['INPUT', 'TEXTAREA', 'SELECT']\n) {\n useEffect(() => {\n const keydownListener = (event: KeyboardEvent) => {\n hotkeys.forEach(([hotkey, handler, options = { preventDefault: true }]) => {\n if (getHotkeyMatcher(hotkey)(event) && shouldFireEvent(event, tagsToIgnore)) {\n if (options.preventDefault) {\n event.preventDefault();\n }\n\n handler(event);\n }\n });\n };\n\n document.documentElement.addEventListener('keydown', keydownListener);\n return () => document.documentElement.removeEventListener('keydown', keydownListener);\n }, [hotkeys]);\n}\n"],"names":["useEffect","getHotkeyMatcher"],"mappings":";;;;;;;AAGA,SAAS,eAAe,CAAC,KAAK,EAAE,YAAY,EAAE;AAC9C,EAAE,IAAI,KAAK,CAAC,MAAM,YAAY,WAAW,EAAE;AAC3C,IAAI,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,iBAAiB,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AAC3F,GAAG;AACH,EAAE,OAAO,IAAI,CAAC;AACd,CAAC;AACM,SAAS,UAAU,CAAC,OAAO,EAAE,YAAY,GAAG,CAAC,OAAO,EAAE,UAAU,EAAE,QAAQ,CAAC,EAAE;AACpF,EAAEA,eAAS,CAAC,MAAM;AAClB,IAAI,MAAM,eAAe,GAAG,CAAC,KAAK,KAAK;AACvC,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC,KAAK;AACjF,QAAQ,IAAIC,4BAAgB,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,IAAI,eAAe,CAAC,KAAK,EAAE,YAAY,CAAC,EAAE;AACrF,UAAU,IAAI,OAAO,CAAC,cAAc,EAAE;AACtC,YAAY,KAAK,CAAC,cAAc,EAAE,CAAC;AACnC,WAAW;AACX,UAAU,OAAO,CAAC,KAAK,CAAC,CAAC;AACzB,SAAS;AACT,OAAO,CAAC,CAAC;AACT,KAAK,CAAC;AACN,IAAI,QAAQ,CAAC,eAAe,CAAC,gBAAgB,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;AAC1E,IAAI,OAAO,MAAM,QAAQ,CAAC,eAAe,CAAC,mBAAmB,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;AAC1F,GAAG,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;AAChB;;;;;"}
|
|
@@ -25,7 +25,7 @@ function getInitialValue(query, initialValue) {
|
|
|
25
25
|
function useMediaQuery(query, initialValue, { getInitialValueInEffect } = {
|
|
26
26
|
getInitialValueInEffect: true
|
|
27
27
|
}) {
|
|
28
|
-
const [matches, setMatches] = React.useState(getInitialValueInEffect ?
|
|
28
|
+
const [matches, setMatches] = React.useState(getInitialValueInEffect ? initialValue : getInitialValue(query, initialValue));
|
|
29
29
|
const queryRef = React.useRef();
|
|
30
30
|
React.useEffect(() => {
|
|
31
31
|
if ("matchMedia" in window) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-media-query.js","sources":["../../src/use-media-query/use-media-query.ts"],"sourcesContent":["import { useState, useEffect, useRef } from 'react';\n\nexport interface UseMediaQueryOptions {\n getInitialValueInEffect: boolean;\n}\n\ntype MediaQueryCallback = (event: { matches: boolean; media: string }) => void;\n\n/**\n * Older versions of Safari (shipped withCatalina and before) do not support addEventListener on matchMedia\n * https://stackoverflow.com/questions/56466261/matchmedia-addlistener-marked-as-deprecated-addeventlistener-equivalent\n * */\nfunction attachMediaListener(query: MediaQueryList, callback: MediaQueryCallback) {\n try {\n query.addEventListener('change', callback);\n return () => query.removeEventListener('change', callback);\n } catch (e) {\n query.addListener(callback);\n return () => query.removeListener(callback);\n }\n}\n\nfunction getInitialValue(query: string, initialValue?: boolean) {\n if (typeof initialValue === 'boolean') {\n return initialValue;\n }\n\n if (typeof window !== 'undefined' && 'matchMedia' in window) {\n return window.matchMedia(query).matches;\n }\n\n return false;\n}\n\nexport function useMediaQuery(\n query: string,\n initialValue?: boolean,\n { getInitialValueInEffect }: UseMediaQueryOptions = {\n getInitialValueInEffect: true,\n }\n) {\n const [matches, setMatches] = useState(\n getInitialValueInEffect ?
|
|
1
|
+
{"version":3,"file":"use-media-query.js","sources":["../../src/use-media-query/use-media-query.ts"],"sourcesContent":["import { useState, useEffect, useRef } from 'react';\n\nexport interface UseMediaQueryOptions {\n getInitialValueInEffect: boolean;\n}\n\ntype MediaQueryCallback = (event: { matches: boolean; media: string }) => void;\n\n/**\n * Older versions of Safari (shipped withCatalina and before) do not support addEventListener on matchMedia\n * https://stackoverflow.com/questions/56466261/matchmedia-addlistener-marked-as-deprecated-addeventlistener-equivalent\n * */\nfunction attachMediaListener(query: MediaQueryList, callback: MediaQueryCallback) {\n try {\n query.addEventListener('change', callback);\n return () => query.removeEventListener('change', callback);\n } catch (e) {\n query.addListener(callback);\n return () => query.removeListener(callback);\n }\n}\n\nfunction getInitialValue(query: string, initialValue?: boolean) {\n if (typeof initialValue === 'boolean') {\n return initialValue;\n }\n\n if (typeof window !== 'undefined' && 'matchMedia' in window) {\n return window.matchMedia(query).matches;\n }\n\n return false;\n}\n\nexport function useMediaQuery(\n query: string,\n initialValue?: boolean,\n { getInitialValueInEffect }: UseMediaQueryOptions = {\n getInitialValueInEffect: true,\n }\n) {\n const [matches, setMatches] = useState(\n getInitialValueInEffect ? initialValue : getInitialValue(query, initialValue)\n );\n const queryRef = useRef<MediaQueryList>();\n\n useEffect(() => {\n if ('matchMedia' in window) {\n queryRef.current = window.matchMedia(query);\n setMatches(queryRef.current.matches);\n return attachMediaListener(queryRef.current, (event) => setMatches(event.matches));\n }\n\n return undefined;\n }, [query]);\n\n return matches;\n}\n"],"names":["useState","useRef","useEffect"],"mappings":";;;;;;AACA,SAAS,mBAAmB,CAAC,KAAK,EAAE,QAAQ,EAAE;AAC9C,EAAE,IAAI;AACN,IAAI,KAAK,CAAC,gBAAgB,CAAC,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CAAC,KAAK,KAAK,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;AACzF,KAAK;AACL,IAAI,OAAO,KAAK,CAAC,CAAC;AAClB,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;AACd,EAAE,OAAO,OAAO,CAAC;AACjB;;;;"}
|
package/esm/index.js
CHANGED
|
@@ -52,6 +52,7 @@ export { useTimeout } from './use-timeout/use-timeout.js';
|
|
|
52
52
|
export { useTextSelection } from './use-text-selection/use-text-selection.js';
|
|
53
53
|
export { usePrevious } from './use-previous/use-previous.js';
|
|
54
54
|
export { useFavicon } from './use-favicon/use-favicon.js';
|
|
55
|
+
export { useEyeDropper } from './use-eye-dropper/use-eye-dropper.js';
|
|
55
56
|
export { getHotkeyHandler } from './use-hotkeys/parse-hotkey.js';
|
|
56
57
|
export { assignRef } from './utils/assign-ref/assign-ref.js';
|
|
57
58
|
export { clamp } from './utils/clamp/clamp.js';
|
package/esm/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { useState, useCallback } from 'react';
|
|
2
|
+
import { useIsomorphicEffect } from '../use-isomorphic-effect/use-isomorphic-effect.js';
|
|
3
|
+
|
|
4
|
+
function useEyeDropper() {
|
|
5
|
+
const [supported, setSupported] = useState(false);
|
|
6
|
+
useIsomorphicEffect(() => {
|
|
7
|
+
setSupported(typeof window !== "undefined" && "EyeDropper" in window);
|
|
8
|
+
}, []);
|
|
9
|
+
const open = useCallback((options = {}) => {
|
|
10
|
+
if (supported) {
|
|
11
|
+
const eyeDropper = new window.EyeDropper();
|
|
12
|
+
return eyeDropper.open(options);
|
|
13
|
+
}
|
|
14
|
+
return void 0;
|
|
15
|
+
}, [supported]);
|
|
16
|
+
return { supported, open };
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export { useEyeDropper };
|
|
20
|
+
//# sourceMappingURL=use-eye-dropper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-eye-dropper.js","sources":["../../src/use-eye-dropper/use-eye-dropper.ts"],"sourcesContent":["import { useCallback, useState } from 'react';\nimport { useIsomorphicEffect } from '../use-isomorphic-effect/use-isomorphic-effect';\n\ninterface EyeDropperOpenOptions {\n signal?: AbortSignal;\n}\n\nexport interface EyeDropperOpenReturnType {\n sRGBHex: string;\n}\n\nexport function useEyeDropper() {\n const [supported, setSupported] = useState(false);\n\n useIsomorphicEffect(() => {\n setSupported(typeof window !== 'undefined' && 'EyeDropper' in window);\n }, []);\n\n const open = useCallback(\n (options: EyeDropperOpenOptions = {}): Promise<EyeDropperOpenReturnType> => {\n if (supported) {\n const eyeDropper = new (window as any).EyeDropper();\n return eyeDropper.open(options);\n }\n\n return undefined;\n },\n [supported]\n );\n\n return { supported, open };\n}\n"],"names":[],"mappings":";;;AAEO,SAAS,aAAa,GAAG;AAChC,EAAE,MAAM,CAAC,SAAS,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAC,KAAK,CAAC,CAAC;AACpD,EAAE,mBAAmB,CAAC,MAAM;AAC5B,IAAI,YAAY,CAAC,OAAO,MAAM,KAAK,WAAW,IAAI,YAAY,IAAI,MAAM,CAAC,CAAC;AAC1E,GAAG,EAAE,EAAE,CAAC,CAAC;AACT,EAAE,MAAM,IAAI,GAAG,WAAW,CAAC,CAAC,OAAO,GAAG,EAAE,KAAK;AAC7C,IAAI,IAAI,SAAS,EAAE;AACnB,MAAM,MAAM,UAAU,GAAG,IAAI,MAAM,CAAC,UAAU,EAAE,CAAC;AACjD,MAAM,OAAO,UAAU,CAAC,IAAI,CAAC,OAAO,CAAC,CAAC;AACtC,KAAK;AACL,IAAI,OAAO,KAAK,CAAC,CAAC;AAClB,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC,CAAC;AAClB,EAAE,OAAO,EAAE,SAAS,EAAE,IAAI,EAAE,CAAC;AAC7B;;;;"}
|
package/esm/use-hash/use-hash.js
CHANGED
|
@@ -4,14 +4,18 @@ import { useWindowEvent } from '../use-window-event/use-window-event.js';
|
|
|
4
4
|
function useHash() {
|
|
5
5
|
const [hash, setHashValue] = useState("");
|
|
6
6
|
const setHash = (value) => {
|
|
7
|
-
|
|
8
|
-
|
|
7
|
+
const valueWithHash = value.startsWith("#") ? value : `#${value}`;
|
|
8
|
+
window.location.hash = valueWithHash;
|
|
9
|
+
setHashValue(valueWithHash);
|
|
9
10
|
};
|
|
10
11
|
useWindowEvent("hashchange", () => {
|
|
11
|
-
|
|
12
|
+
const newHash = window.location.hash;
|
|
13
|
+
if (hash !== newHash) {
|
|
14
|
+
setHashValue(hash);
|
|
15
|
+
}
|
|
12
16
|
});
|
|
13
17
|
useEffect(() => {
|
|
14
|
-
|
|
18
|
+
setHashValue(window.location.hash);
|
|
15
19
|
}, []);
|
|
16
20
|
return [hash, setHash];
|
|
17
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-hash.js","sources":["../../src/use-hash/use-hash.ts"],"sourcesContent":["import { useState, useEffect } from 'react';\nimport { useWindowEvent } from '../use-window-event/use-window-event';\n\nexport function useHash() {\n const [hash, setHashValue] = useState<string>('');\n\n const setHash = (value: string) => {\n window.location.hash =
|
|
1
|
+
{"version":3,"file":"use-hash.js","sources":["../../src/use-hash/use-hash.ts"],"sourcesContent":["import { useState, useEffect } from 'react';\nimport { useWindowEvent } from '../use-window-event/use-window-event';\n\nexport function useHash() {\n const [hash, setHashValue] = useState<string>('');\n\n const setHash = (value: string) => {\n const valueWithHash = value.startsWith('#') ? value : `#${value}`;\n window.location.hash = valueWithHash;\n setHashValue(valueWithHash);\n };\n\n useWindowEvent('hashchange', () => {\n const newHash = window.location.hash;\n if (hash !== newHash) {\n setHashValue(hash);\n }\n });\n\n useEffect(() => {\n setHashValue(window.location.hash);\n }, []);\n\n return [hash, setHash] as const;\n}\n"],"names":[],"mappings":";;;AAEO,SAAS,OAAO,GAAG;AAC1B,EAAE,MAAM,CAAC,IAAI,EAAE,YAAY,CAAC,GAAG,QAAQ,CAAC,EAAE,CAAC,CAAC;AAC5C,EAAE,MAAM,OAAO,GAAG,CAAC,KAAK,KAAK;AAC7B,IAAI,MAAM,aAAa,GAAG,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,GAAG,KAAK,GAAG,CAAC,CAAC,EAAE,KAAK,CAAC,CAAC,CAAC;AACtE,IAAI,MAAM,CAAC,QAAQ,CAAC,IAAI,GAAG,aAAa,CAAC;AACzC,IAAI,YAAY,CAAC,aAAa,CAAC,CAAC;AAChC,GAAG,CAAC;AACJ,EAAE,cAAc,CAAC,YAAY,EAAE,MAAM;AACrC,IAAI,MAAM,OAAO,GAAG,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC;AACzC,IAAI,IAAI,IAAI,KAAK,OAAO,EAAE;AAC1B,MAAM,YAAY,CAAC,IAAI,CAAC,CAAC;AACzB,KAAK;AACL,GAAG,CAAC,CAAC;AACL,EAAE,SAAS,CAAC,MAAM;AAClB,IAAI,YAAY,CAAC,MAAM,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;AACvC,GAAG,EAAE,EAAE,CAAC,CAAC;AACT,EAAE,OAAO,CAAC,IAAI,EAAE,OAAO,CAAC,CAAC;AACzB;;;;"}
|
|
@@ -64,9 +64,11 @@ function getHotkeyMatcher(hotkey) {
|
|
|
64
64
|
function getHotkeyHandler(hotkeys) {
|
|
65
65
|
return (event) => {
|
|
66
66
|
const _event = "nativeEvent" in event ? event.nativeEvent : event;
|
|
67
|
-
hotkeys.forEach(([hotkey, handler]) => {
|
|
67
|
+
hotkeys.forEach(([hotkey, handler, options = { preventDefault: true }]) => {
|
|
68
68
|
if (getHotkeyMatcher(hotkey)(_event)) {
|
|
69
|
-
|
|
69
|
+
if (options.preventDefault) {
|
|
70
|
+
event.preventDefault();
|
|
71
|
+
}
|
|
70
72
|
handler(_event);
|
|
71
73
|
}
|
|
72
74
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-hotkey.js","sources":["../../src/use-hotkeys/parse-hotkey.ts"],"sourcesContent":["export type KeyboardModifiers = {\n alt: boolean;\n ctrl: boolean;\n meta: boolean;\n mod: boolean;\n shift: boolean;\n};\n\nexport type Hotkey = KeyboardModifiers & {\n key?: string;\n};\n\ntype CheckHotkeyMatch = (event: KeyboardEvent) => boolean;\n\nexport function parseHotkey(hotkey: string): Hotkey {\n const keys = hotkey\n .toLowerCase()\n .split('+')\n .map((part) => part.trim());\n\n const modifiers: KeyboardModifiers = {\n alt: keys.includes('alt'),\n ctrl: keys.includes('ctrl'),\n meta: keys.includes('meta'),\n mod: keys.includes('mod'),\n shift: keys.includes('shift'),\n };\n\n const reservedKeys = ['alt', 'ctrl', 'meta', 'shift', 'mod'];\n\n const freeKey = keys.find((key) => !reservedKeys.includes(key));\n\n return {\n ...modifiers,\n key: freeKey,\n };\n}\n\nfunction isExactHotkey(hotkey: Hotkey, event: KeyboardEvent): boolean {\n const { alt, ctrl, meta, mod, shift, key } = hotkey;\n const { altKey, ctrlKey, metaKey, shiftKey, key: pressedKey } = event;\n\n if (alt !== altKey) {\n return false;\n }\n\n if (mod) {\n if (!ctrlKey && !metaKey) {\n return false;\n }\n } else {\n if (ctrl !== ctrlKey) {\n return false;\n }\n if (meta !== metaKey) {\n return false;\n }\n }\n if (shift !== shiftKey) {\n return false;\n }\n\n if (\n key &&\n (pressedKey.toLowerCase() === key.toLowerCase() ||\n event.code.replace('Key', '').toLowerCase() === key.toLowerCase())\n ) {\n return true;\n }\n\n return false;\n}\n\nexport function getHotkeyMatcher(hotkey: string): CheckHotkeyMatch {\n return (event) => isExactHotkey(parseHotkey(hotkey), event);\n}\n\ntype HotkeyItem = [string
|
|
1
|
+
{"version":3,"file":"parse-hotkey.js","sources":["../../src/use-hotkeys/parse-hotkey.ts"],"sourcesContent":["export type KeyboardModifiers = {\n alt: boolean;\n ctrl: boolean;\n meta: boolean;\n mod: boolean;\n shift: boolean;\n};\n\nexport type Hotkey = KeyboardModifiers & {\n key?: string;\n};\n\ntype CheckHotkeyMatch = (event: KeyboardEvent) => boolean;\n\nexport function parseHotkey(hotkey: string): Hotkey {\n const keys = hotkey\n .toLowerCase()\n .split('+')\n .map((part) => part.trim());\n\n const modifiers: KeyboardModifiers = {\n alt: keys.includes('alt'),\n ctrl: keys.includes('ctrl'),\n meta: keys.includes('meta'),\n mod: keys.includes('mod'),\n shift: keys.includes('shift'),\n };\n\n const reservedKeys = ['alt', 'ctrl', 'meta', 'shift', 'mod'];\n\n const freeKey = keys.find((key) => !reservedKeys.includes(key));\n\n return {\n ...modifiers,\n key: freeKey,\n };\n}\n\nfunction isExactHotkey(hotkey: Hotkey, event: KeyboardEvent): boolean {\n const { alt, ctrl, meta, mod, shift, key } = hotkey;\n const { altKey, ctrlKey, metaKey, shiftKey, key: pressedKey } = event;\n\n if (alt !== altKey) {\n return false;\n }\n\n if (mod) {\n if (!ctrlKey && !metaKey) {\n return false;\n }\n } else {\n if (ctrl !== ctrlKey) {\n return false;\n }\n if (meta !== metaKey) {\n return false;\n }\n }\n if (shift !== shiftKey) {\n return false;\n }\n\n if (\n key &&\n (pressedKey.toLowerCase() === key.toLowerCase() ||\n event.code.replace('Key', '').toLowerCase() === key.toLowerCase())\n ) {\n return true;\n }\n\n return false;\n}\n\nexport function getHotkeyMatcher(hotkey: string): CheckHotkeyMatch {\n return (event) => isExactHotkey(parseHotkey(hotkey), event);\n}\n\nexport interface HotkeyItemOptions {\n preventDefault?: boolean;\n}\n\ntype HotkeyItem = [\n string,\n (event: React.KeyboardEvent<HTMLElement> | KeyboardEvent) => void,\n HotkeyItemOptions?\n];\n\nexport function getHotkeyHandler(hotkeys: HotkeyItem[]) {\n return (event: React.KeyboardEvent<HTMLElement> | KeyboardEvent) => {\n const _event = 'nativeEvent' in event ? event.nativeEvent : event;\n hotkeys.forEach(([hotkey, handler, options = { preventDefault: true }]) => {\n if (getHotkeyMatcher(hotkey)(_event)) {\n if (options.preventDefault) {\n event.preventDefault();\n }\n\n handler(_event);\n }\n });\n };\n}\n"],"names":[],"mappings":"AAAA,IAAI,SAAS,GAAG,MAAM,CAAC,cAAc,CAAC;AACtC,IAAI,UAAU,GAAG,MAAM,CAAC,gBAAgB,CAAC;AACzC,IAAI,iBAAiB,GAAG,MAAM,CAAC,yBAAyB,CAAC;AACzD,IAAI,mBAAmB,GAAG,MAAM,CAAC,qBAAqB,CAAC;AACvD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,cAAc,CAAC;AACnD,IAAI,YAAY,GAAG,MAAM,CAAC,SAAS,CAAC,oBAAoB,CAAC;AACzD,IAAI,eAAe,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,KAAK,KAAK,GAAG,IAAI,GAAG,GAAG,SAAS,CAAC,GAAG,EAAE,GAAG,EAAE,EAAE,UAAU,EAAE,IAAI,EAAE,YAAY,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,GAAG,GAAG,CAAC,GAAG,CAAC,GAAG,KAAK,CAAC;AAChK,IAAI,cAAc,GAAG,CAAC,CAAC,EAAE,CAAC,KAAK;AAC/B,EAAE,KAAK,IAAI,IAAI,IAAI,CAAC,KAAK,CAAC,GAAG,EAAE,CAAC;AAChC,IAAI,IAAI,YAAY,CAAC,IAAI,CAAC,CAAC,EAAE,IAAI,CAAC;AAClC,MAAM,eAAe,CAAC,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC;AACxC,EAAE,IAAI,mBAAmB;AACzB,IAAI,KAAK,IAAI,IAAI,IAAI,mBAAmB,CAAC,CAAC,CAAC,EAAE;AAC7C,MAAM,IAAI,YAAY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AAE;AAC1C,EAAE,OAAO,CAAC,KAAK,KAAK;AACpB,IAAI,MAAM,MAAM,GAAG,aAAa,IAAI,KAAK,GAAG,KAAK,CAAC,WAAW,GAAG,KAAK,CAAC;AACtE,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC,KAAK;AAC/E,MAAM,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,EAAE;AAC5C,QAAQ,IAAI,OAAO,CAAC,cAAc,EAAE;AACpC,UAAU,KAAK,CAAC,cAAc,EAAE,CAAC;AACjC,SAAS;AACT,QAAQ,OAAO,CAAC,MAAM,CAAC,CAAC;AACxB,OAAO;AACP,KAAK,CAAC,CAAC;AACP,GAAG,CAAC;AACJ;;;;"}
|
|
@@ -2,18 +2,20 @@ import { useEffect } from 'react';
|
|
|
2
2
|
import { getHotkeyMatcher } from './parse-hotkey.js';
|
|
3
3
|
export { getHotkeyHandler } from './parse-hotkey.js';
|
|
4
4
|
|
|
5
|
-
function shouldFireEvent(event) {
|
|
5
|
+
function shouldFireEvent(event, tagsToIgnore) {
|
|
6
6
|
if (event.target instanceof HTMLElement) {
|
|
7
|
-
return !event.target.isContentEditable && !
|
|
7
|
+
return !event.target.isContentEditable && !tagsToIgnore.includes(event.target.tagName);
|
|
8
8
|
}
|
|
9
9
|
return true;
|
|
10
10
|
}
|
|
11
|
-
function useHotkeys(hotkeys) {
|
|
11
|
+
function useHotkeys(hotkeys, tagsToIgnore = ["INPUT", "TEXTAREA", "SELECT"]) {
|
|
12
12
|
useEffect(() => {
|
|
13
13
|
const keydownListener = (event) => {
|
|
14
|
-
hotkeys.forEach(([hotkey, handler]) => {
|
|
15
|
-
if (getHotkeyMatcher(hotkey)(event) && shouldFireEvent(event)) {
|
|
16
|
-
|
|
14
|
+
hotkeys.forEach(([hotkey, handler, options = { preventDefault: true }]) => {
|
|
15
|
+
if (getHotkeyMatcher(hotkey)(event) && shouldFireEvent(event, tagsToIgnore)) {
|
|
16
|
+
if (options.preventDefault) {
|
|
17
|
+
event.preventDefault();
|
|
18
|
+
}
|
|
17
19
|
handler(event);
|
|
18
20
|
}
|
|
19
21
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-hotkeys.js","sources":["../../src/use-hotkeys/use-hotkeys.ts"],"sourcesContent":["import { useEffect } from 'react';\nimport { getHotkeyMatcher, getHotkeyHandler } from './parse-hotkey';\n\nexport { getHotkeyHandler };\n\nexport type HotkeyItem = [string, (event: KeyboardEvent) => void];\n\nfunction shouldFireEvent(event: KeyboardEvent) {\n if (event.target instanceof HTMLElement) {\n return
|
|
1
|
+
{"version":3,"file":"use-hotkeys.js","sources":["../../src/use-hotkeys/use-hotkeys.ts"],"sourcesContent":["import { useEffect } from 'react';\nimport { getHotkeyMatcher, getHotkeyHandler, HotkeyItemOptions } from './parse-hotkey';\n\nexport type { HotkeyItemOptions };\nexport { getHotkeyHandler };\n\nexport type HotkeyItem = [string, (event: KeyboardEvent) => void, HotkeyItemOptions?];\n\nfunction shouldFireEvent(event: KeyboardEvent, tagsToIgnore: string[]) {\n if (event.target instanceof HTMLElement) {\n return !event.target.isContentEditable && !tagsToIgnore.includes(event.target.tagName);\n }\n return true;\n}\n\nexport function useHotkeys(\n hotkeys: HotkeyItem[],\n tagsToIgnore: string[] = ['INPUT', 'TEXTAREA', 'SELECT']\n) {\n useEffect(() => {\n const keydownListener = (event: KeyboardEvent) => {\n hotkeys.forEach(([hotkey, handler, options = { preventDefault: true }]) => {\n if (getHotkeyMatcher(hotkey)(event) && shouldFireEvent(event, tagsToIgnore)) {\n if (options.preventDefault) {\n event.preventDefault();\n }\n\n handler(event);\n }\n });\n };\n\n document.documentElement.addEventListener('keydown', keydownListener);\n return () => document.documentElement.removeEventListener('keydown', keydownListener);\n }, [hotkeys]);\n}\n"],"names":[],"mappings":";;;;AAGA,SAAS,eAAe,CAAC,KAAK,EAAE,YAAY,EAAE;AAC9C,EAAE,IAAI,KAAK,CAAC,MAAM,YAAY,WAAW,EAAE;AAC3C,IAAI,OAAO,CAAC,KAAK,CAAC,MAAM,CAAC,iBAAiB,IAAI,CAAC,YAAY,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AAC3F,GAAG;AACH,EAAE,OAAO,IAAI,CAAC;AACd,CAAC;AACM,SAAS,UAAU,CAAC,OAAO,EAAE,YAAY,GAAG,CAAC,OAAO,EAAE,UAAU,EAAE,QAAQ,CAAC,EAAE;AACpF,EAAE,SAAS,CAAC,MAAM;AAClB,IAAI,MAAM,eAAe,GAAG,CAAC,KAAK,KAAK;AACvC,MAAM,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,EAAE,OAAO,EAAE,OAAO,GAAG,EAAE,cAAc,EAAE,IAAI,EAAE,CAAC,KAAK;AACjF,QAAQ,IAAI,gBAAgB,CAAC,MAAM,CAAC,CAAC,KAAK,CAAC,IAAI,eAAe,CAAC,KAAK,EAAE,YAAY,CAAC,EAAE;AACrF,UAAU,IAAI,OAAO,CAAC,cAAc,EAAE;AACtC,YAAY,KAAK,CAAC,cAAc,EAAE,CAAC;AACnC,WAAW;AACX,UAAU,OAAO,CAAC,KAAK,CAAC,CAAC;AACzB,SAAS;AACT,OAAO,CAAC,CAAC;AACT,KAAK,CAAC;AACN,IAAI,QAAQ,CAAC,eAAe,CAAC,gBAAgB,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;AAC1E,IAAI,OAAO,MAAM,QAAQ,CAAC,eAAe,CAAC,mBAAmB,CAAC,SAAS,EAAE,eAAe,CAAC,CAAC;AAC1F,GAAG,EAAE,CAAC,OAAO,CAAC,CAAC,CAAC;AAChB;;;;"}
|
|
@@ -21,7 +21,7 @@ function getInitialValue(query, initialValue) {
|
|
|
21
21
|
function useMediaQuery(query, initialValue, { getInitialValueInEffect } = {
|
|
22
22
|
getInitialValueInEffect: true
|
|
23
23
|
}) {
|
|
24
|
-
const [matches, setMatches] = useState(getInitialValueInEffect ?
|
|
24
|
+
const [matches, setMatches] = useState(getInitialValueInEffect ? initialValue : getInitialValue(query, initialValue));
|
|
25
25
|
const queryRef = useRef();
|
|
26
26
|
useEffect(() => {
|
|
27
27
|
if ("matchMedia" in window) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-media-query.js","sources":["../../src/use-media-query/use-media-query.ts"],"sourcesContent":["import { useState, useEffect, useRef } from 'react';\n\nexport interface UseMediaQueryOptions {\n getInitialValueInEffect: boolean;\n}\n\ntype MediaQueryCallback = (event: { matches: boolean; media: string }) => void;\n\n/**\n * Older versions of Safari (shipped withCatalina and before) do not support addEventListener on matchMedia\n * https://stackoverflow.com/questions/56466261/matchmedia-addlistener-marked-as-deprecated-addeventlistener-equivalent\n * */\nfunction attachMediaListener(query: MediaQueryList, callback: MediaQueryCallback) {\n try {\n query.addEventListener('change', callback);\n return () => query.removeEventListener('change', callback);\n } catch (e) {\n query.addListener(callback);\n return () => query.removeListener(callback);\n }\n}\n\nfunction getInitialValue(query: string, initialValue?: boolean) {\n if (typeof initialValue === 'boolean') {\n return initialValue;\n }\n\n if (typeof window !== 'undefined' && 'matchMedia' in window) {\n return window.matchMedia(query).matches;\n }\n\n return false;\n}\n\nexport function useMediaQuery(\n query: string,\n initialValue?: boolean,\n { getInitialValueInEffect }: UseMediaQueryOptions = {\n getInitialValueInEffect: true,\n }\n) {\n const [matches, setMatches] = useState(\n getInitialValueInEffect ?
|
|
1
|
+
{"version":3,"file":"use-media-query.js","sources":["../../src/use-media-query/use-media-query.ts"],"sourcesContent":["import { useState, useEffect, useRef } from 'react';\n\nexport interface UseMediaQueryOptions {\n getInitialValueInEffect: boolean;\n}\n\ntype MediaQueryCallback = (event: { matches: boolean; media: string }) => void;\n\n/**\n * Older versions of Safari (shipped withCatalina and before) do not support addEventListener on matchMedia\n * https://stackoverflow.com/questions/56466261/matchmedia-addlistener-marked-as-deprecated-addeventlistener-equivalent\n * */\nfunction attachMediaListener(query: MediaQueryList, callback: MediaQueryCallback) {\n try {\n query.addEventListener('change', callback);\n return () => query.removeEventListener('change', callback);\n } catch (e) {\n query.addListener(callback);\n return () => query.removeListener(callback);\n }\n}\n\nfunction getInitialValue(query: string, initialValue?: boolean) {\n if (typeof initialValue === 'boolean') {\n return initialValue;\n }\n\n if (typeof window !== 'undefined' && 'matchMedia' in window) {\n return window.matchMedia(query).matches;\n }\n\n return false;\n}\n\nexport function useMediaQuery(\n query: string,\n initialValue?: boolean,\n { getInitialValueInEffect }: UseMediaQueryOptions = {\n getInitialValueInEffect: true,\n }\n) {\n const [matches, setMatches] = useState(\n getInitialValueInEffect ? initialValue : getInitialValue(query, initialValue)\n );\n const queryRef = useRef<MediaQueryList>();\n\n useEffect(() => {\n if ('matchMedia' in window) {\n queryRef.current = window.matchMedia(query);\n setMatches(queryRef.current.matches);\n return attachMediaListener(queryRef.current, (event) => setMatches(event.matches));\n }\n\n return undefined;\n }, [query]);\n\n return matches;\n}\n"],"names":[],"mappings":";;AACA,SAAS,mBAAmB,CAAC,KAAK,EAAE,QAAQ,EAAE;AAC9C,EAAE,IAAI;AACN,IAAI,KAAK,CAAC,gBAAgB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAC/C,IAAI,OAAO,MAAM,KAAK,CAAC,mBAAmB,CAAC,QAAQ,EAAE,QAAQ,CAAC,CAAC;AAC/D,GAAG,CAAC,OAAO,CAAC,EAAE;AACd,IAAI,KAAK,CAAC,WAAW,CAAC,QAAQ,CAAC,CAAC;AAChC,IAAI,OAAO,MAAM,KAAK,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC;AAChD,GAAG;AACH,CAAC;AACD,SAAS,eAAe,CAAC,KAAK,EAAE,YAAY,EAAE;AAC9C,EAAE,IAAI,OAAO,YAAY,KAAK,SAAS,EAAE;AACzC,IAAI,OAAO,YAAY,CAAC;AACxB,GAAG;AACH,EAAE,IAAI,OAAO,MAAM,KAAK,WAAW,IAAI,YAAY,IAAI,MAAM,EAAE;AAC/D,IAAI,OAAO,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC,OAAO,CAAC;AAC5C,GAAG;AACH,EAAE,OAAO,KAAK,CAAC;AACf,CAAC;AACM,SAAS,aAAa,CAAC,KAAK,EAAE,YAAY,EAAE,EAAE,uBAAuB,EAAE,GAAG;AACjF,EAAE,uBAAuB,EAAE,IAAI;AAC/B,CAAC,EAAE;AACH,EAAE,MAAM,CAAC,OAAO,EAAE,UAAU,CAAC,GAAG,QAAQ,CAAC,uBAAuB,GAAG,YAAY,GAAG,eAAe,CAAC,KAAK,EAAE,YAAY,CAAC,CAAC,CAAC;AACxH,EAAE,MAAM,QAAQ,GAAG,MAAM,EAAE,CAAC;AAC5B,EAAE,SAAS,CAAC,MAAM;AAClB,IAAI,IAAI,YAAY,IAAI,MAAM,EAAE;AAChC,MAAM,QAAQ,CAAC,OAAO,GAAG,MAAM,CAAC,UAAU,CAAC,KAAK,CAAC,CAAC;AAClD,MAAM,UAAU,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;AAC3C,MAAM,OAAO,mBAAmB,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC,KAAK,KAAK,UAAU,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC;AACzF,KAAK;AACL,IAAI,OAAO,KAAK,CAAC,CAAC;AAClB,GAAG,EAAE,CAAC,KAAK,CAAC,CAAC,CAAC;AACd,EAAE,OAAO,OAAO,CAAC;AACjB;;;;"}
|
package/lib/index.d.ts
CHANGED
|
@@ -53,8 +53,10 @@ export { useTimeout } from './use-timeout/use-timeout';
|
|
|
53
53
|
export { useTextSelection } from './use-text-selection/use-text-selection';
|
|
54
54
|
export { usePrevious } from './use-previous/use-previous';
|
|
55
55
|
export { useFavicon } from './use-favicon/use-favicon';
|
|
56
|
+
export { useEyeDropper } from './use-eye-dropper/use-eye-dropper';
|
|
56
57
|
export type { UseMovePosition } from './use-move/use-move';
|
|
57
58
|
export type { OS } from './use-os/use-os';
|
|
58
59
|
export type { HotkeyItem } from './use-hotkeys/use-hotkeys';
|
|
59
60
|
export type { UseListStateHandlers } from './use-list-state/use-list-state';
|
|
61
|
+
export type { EyeDropperOpenReturnType } from './use-eye-dropper/use-eye-dropper';
|
|
60
62
|
//# sourceMappingURL=index.d.ts.map
|
package/lib/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AAExB,OAAO,EAAE,eAAe,EAAE,MAAM,uCAAuC,CAAC;AACxE,OAAO,EAAE,YAAY,EAAE,MAAM,+BAA+B,CAAC;AAC7D,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AACrE,OAAO,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AACvD,OAAO,EAAE,iBAAiB,EAAE,MAAM,2CAA2C,CAAC;AAC9E,OAAO,EAAE,iBAAiB,EAAE,MAAM,2CAA2C,CAAC;AAC9E,OAAO,EAAE,gBAAgB,EAAE,MAAM,yCAAyC,CAAC;AAC3E,OAAO,EAAE,qBAAqB,EAAE,MAAM,mDAAmD,CAAC;AAC1F,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,YAAY,EAAE,MAAM,iCAAiC,CAAC;AAC/D,OAAO,EAAE,cAAc,EAAE,MAAM,qCAAqC,CAAC;AACrE,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AACxC,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,6BAA6B,CAAC;AAC1D,OAAO,EAAE,mBAAmB,EAAE,MAAM,+CAA+C,CAAC;AACpF,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AM,2BAA2B,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,mCAAmC,CAAC;AAElE,YAAY,EAAE,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAC3D,YAAY,EAAE,EAAE,EAAE,MAAM,iBAAiB,CAAC;AAC1C,YAAY,EAAE,UAAU,EAAE,MAAM,2BAA2B,CAAC;AAC5D,YAAY,EAAE,oBAAoB,EAAE,MAAM,iCAAiC,CAAC;AAC5E,YAAY,EAAE,wBAAwB,EAAE,MAAM,mCAAmC,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
interface EyeDropperOpenOptions {
|
|
2
|
+
signal?: AbortSignal;
|
|
3
|
+
}
|
|
4
|
+
export interface EyeDropperOpenReturnType {
|
|
5
|
+
sRGBHex: string;
|
|
6
|
+
}
|
|
7
|
+
export declare function useEyeDropper(): {
|
|
8
|
+
supported: boolean;
|
|
9
|
+
open: (options?: EyeDropperOpenOptions) => Promise<EyeDropperOpenReturnType>;
|
|
10
|
+
};
|
|
11
|
+
export {};
|
|
12
|
+
//# sourceMappingURL=use-eye-dropper.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-eye-dropper.d.ts","sourceRoot":"","sources":["../../src/use-eye-dropper/use-eye-dropper.ts"],"names":[],"mappings":"AAGA,UAAU,qBAAqB;IAC7B,MAAM,CAAC,EAAE,WAAW,CAAC;CACtB;AAED,MAAM,WAAW,wBAAwB;IACvC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,aAAa;;qBAQf,qBAAqB,KAAQ,QAAQ,wBAAwB,CAAC;EAY3E"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-hash.d.ts","sourceRoot":"","sources":["../../src/use-hash/use-hash.ts"],"names":[],"mappings":"AAGA,wBAAgB,OAAO,8BAGG,MAAM,
|
|
1
|
+
{"version":3,"file":"use-hash.d.ts","sourceRoot":"","sources":["../../src/use-hash/use-hash.ts"],"names":[],"mappings":"AAGA,wBAAgB,OAAO,8BAGG,MAAM,WAkB/B"}
|
|
@@ -12,7 +12,14 @@ export declare type Hotkey = KeyboardModifiers & {
|
|
|
12
12
|
declare type CheckHotkeyMatch = (event: KeyboardEvent) => boolean;
|
|
13
13
|
export declare function parseHotkey(hotkey: string): Hotkey;
|
|
14
14
|
export declare function getHotkeyMatcher(hotkey: string): CheckHotkeyMatch;
|
|
15
|
-
|
|
15
|
+
export interface HotkeyItemOptions {
|
|
16
|
+
preventDefault?: boolean;
|
|
17
|
+
}
|
|
18
|
+
declare type HotkeyItem = [
|
|
19
|
+
string,
|
|
20
|
+
(event: React.KeyboardEvent<HTMLElement> | KeyboardEvent) => void,
|
|
21
|
+
HotkeyItemOptions?
|
|
22
|
+
];
|
|
16
23
|
export declare function getHotkeyHandler(hotkeys: HotkeyItem[]): (event: React.KeyboardEvent<HTMLElement> | KeyboardEvent) => void;
|
|
17
24
|
export {};
|
|
18
25
|
//# sourceMappingURL=parse-hotkey.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"parse-hotkey.d.ts","sourceRoot":"","sources":["../../src/use-hotkeys/parse-hotkey.ts"],"names":[],"mappings":";AAAA,oBAAY,iBAAiB,GAAG;IAC9B,GAAG,EAAE,OAAO,CAAC;IACb,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,OAAO,CAAC;IACd,GAAG,EAAE,OAAO,CAAC;IACb,KAAK,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF,oBAAY,MAAM,GAAG,iBAAiB,GAAG;IACvC,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,aAAK,gBAAgB,GAAG,CAAC,KAAK,EAAE,aAAa,KAAK,OAAO,CAAC;AAE1D,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAsBlD;AAqCD,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,gBAAgB,CAEjE;AAED,aAAK,UAAU,GAAG,
|
|
1
|
+
{"version":3,"file":"parse-hotkey.d.ts","sourceRoot":"","sources":["../../src/use-hotkeys/parse-hotkey.ts"],"names":[],"mappings":";AAAA,oBAAY,iBAAiB,GAAG;IAC9B,GAAG,EAAE,OAAO,CAAC;IACb,IAAI,EAAE,OAAO,CAAC;IACd,IAAI,EAAE,OAAO,CAAC;IACd,GAAG,EAAE,OAAO,CAAC;IACb,KAAK,EAAE,OAAO,CAAC;CAChB,CAAC;AAEF,oBAAY,MAAM,GAAG,iBAAiB,GAAG;IACvC,GAAG,CAAC,EAAE,MAAM,CAAC;CACd,CAAC;AAEF,aAAK,gBAAgB,GAAG,CAAC,KAAK,EAAE,aAAa,KAAK,OAAO,CAAC;AAE1D,wBAAgB,WAAW,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAsBlD;AAqCD,wBAAgB,gBAAgB,CAAC,MAAM,EAAE,MAAM,GAAG,gBAAgB,CAEjE;AAED,MAAM,WAAW,iBAAiB;IAChC,cAAc,CAAC,EAAE,OAAO,CAAC;CAC1B;AAED,aAAK,UAAU,GAAG;IAChB,MAAM;IACN,CAAC,KAAK,EAAE,KAAK,CAAC,aAAa,CAAC,WAAW,CAAC,GAAG,aAAa,KAAK,IAAI;IACjE,iBAAiB,CAAC;CACnB,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,OAAO,EAAE,UAAU,EAAE,WACrC,mBAAmB,CAAC,WAAW,CAAC,GAAG,aAAa,UAYhE"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
-
import { getHotkeyHandler } from './parse-hotkey';
|
|
1
|
+
import { getHotkeyHandler, HotkeyItemOptions } from './parse-hotkey';
|
|
2
|
+
export type { HotkeyItemOptions };
|
|
2
3
|
export { getHotkeyHandler };
|
|
3
|
-
export declare type HotkeyItem = [string, (event: KeyboardEvent) => void];
|
|
4
|
-
export declare function useHotkeys(hotkeys: HotkeyItem[]): void;
|
|
4
|
+
export declare type HotkeyItem = [string, (event: KeyboardEvent) => void, HotkeyItemOptions?];
|
|
5
|
+
export declare function useHotkeys(hotkeys: HotkeyItem[], tagsToIgnore?: string[]): void;
|
|
5
6
|
//# sourceMappingURL=use-hotkeys.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-hotkeys.d.ts","sourceRoot":"","sources":["../../src/use-hotkeys/use-hotkeys.ts"],"names":[],"mappings":"AACA,OAAO,EAAoB,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"use-hotkeys.d.ts","sourceRoot":"","sources":["../../src/use-hotkeys/use-hotkeys.ts"],"names":[],"mappings":"AACA,OAAO,EAAoB,gBAAgB,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEvF,YAAY,EAAE,iBAAiB,EAAE,CAAC;AAClC,OAAO,EAAE,gBAAgB,EAAE,CAAC;AAE5B,oBAAY,UAAU,GAAG,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAC;AAStF,wBAAgB,UAAU,CACxB,OAAO,EAAE,UAAU,EAAE,EACrB,YAAY,GAAE,MAAM,EAAoC,QAkBzD"}
|