@mantine/hooks 5.10.2 → 5.10.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/use-hotkeys/use-hotkeys.js +6 -3
- package/cjs/use-hotkeys/use-hotkeys.js.map +1 -1
- package/esm/use-hotkeys/use-hotkeys.js +6 -3
- package/esm/use-hotkeys/use-hotkeys.js.map +1 -1
- package/lib/use-hotkeys/use-hotkeys.d.ts +1 -1
- package/lib/use-hotkeys/use-hotkeys.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -5,17 +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, tagsToIgnore) {
|
|
8
|
+
function shouldFireEvent(event, tagsToIgnore, triggerOnContentEditable = false) {
|
|
9
9
|
if (event.target instanceof HTMLElement) {
|
|
10
|
+
if (triggerOnContentEditable) {
|
|
11
|
+
return !tagsToIgnore.includes(event.target.tagName);
|
|
12
|
+
}
|
|
10
13
|
return !event.target.isContentEditable && !tagsToIgnore.includes(event.target.tagName);
|
|
11
14
|
}
|
|
12
15
|
return true;
|
|
13
16
|
}
|
|
14
|
-
function useHotkeys(hotkeys, tagsToIgnore = ["INPUT", "TEXTAREA", "SELECT"]) {
|
|
17
|
+
function useHotkeys(hotkeys, tagsToIgnore = ["INPUT", "TEXTAREA", "SELECT"], triggerOnContentEditable = false) {
|
|
15
18
|
React.useEffect(() => {
|
|
16
19
|
const keydownListener = (event) => {
|
|
17
20
|
hotkeys.forEach(([hotkey, handler, options = { preventDefault: true }]) => {
|
|
18
|
-
if (parseHotkey.getHotkeyMatcher(hotkey)(event) && shouldFireEvent(event, tagsToIgnore)) {
|
|
21
|
+
if (parseHotkey.getHotkeyMatcher(hotkey)(event) && shouldFireEvent(event, tagsToIgnore, triggerOnContentEditable)) {
|
|
19
22
|
if (options.preventDefault) {
|
|
20
23
|
event.preventDefault();
|
|
21
24
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-hotkeys.js","sources":["../../src/use-hotkeys/use-hotkeys.ts"],"sourcesContent":["import { useEffect } from 'react';\nimport {
|
|
1
|
+
{"version":3,"file":"use-hotkeys.js","sources":["../../src/use-hotkeys/use-hotkeys.ts"],"sourcesContent":["import { useEffect } from 'react';\nimport { getHotkeyHandler, getHotkeyMatcher, HotkeyItemOptions } from './parse-hotkey';\n\nexport type { HotkeyItemOptions };\nexport { getHotkeyHandler };\n\nexport type HotkeyItem = [string, (event: KeyboardEvent) => void, HotkeyItemOptions?];\n\nfunction shouldFireEvent(\n event: KeyboardEvent,\n tagsToIgnore: string[],\n triggerOnContentEditable = false\n) {\n if (event.target instanceof HTMLElement) {\n if (triggerOnContentEditable) {\n return !tagsToIgnore.includes(event.target.tagName);\n }\n\n return !event.target.isContentEditable && !tagsToIgnore.includes(event.target.tagName);\n }\n\n return true;\n}\n\nexport function useHotkeys(\n hotkeys: HotkeyItem[],\n tagsToIgnore: string[] = ['INPUT', 'TEXTAREA', 'SELECT'],\n triggerOnContentEditable = false\n) {\n useEffect(() => {\n const keydownListener = (event: KeyboardEvent) => {\n hotkeys.forEach(([hotkey, handler, options = { preventDefault: true }]) => {\n if (\n getHotkeyMatcher(hotkey)(event) &&\n shouldFireEvent(event, tagsToIgnore, triggerOnContentEditable)\n ) {\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,wBAAwB,GAAG,KAAK,EAAE;AAChF,EAAE,IAAI,KAAK,CAAC,MAAM,YAAY,WAAW,EAAE;AAC3C,IAAI,IAAI,wBAAw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
2
2
|
import { getHotkeyMatcher } from './parse-hotkey.js';
|
|
3
3
|
export { getHotkeyHandler } from './parse-hotkey.js';
|
|
4
4
|
|
|
5
|
-
function shouldFireEvent(event, tagsToIgnore) {
|
|
5
|
+
function shouldFireEvent(event, tagsToIgnore, triggerOnContentEditable = false) {
|
|
6
6
|
if (event.target instanceof HTMLElement) {
|
|
7
|
+
if (triggerOnContentEditable) {
|
|
8
|
+
return !tagsToIgnore.includes(event.target.tagName);
|
|
9
|
+
}
|
|
7
10
|
return !event.target.isContentEditable && !tagsToIgnore.includes(event.target.tagName);
|
|
8
11
|
}
|
|
9
12
|
return true;
|
|
10
13
|
}
|
|
11
|
-
function useHotkeys(hotkeys, tagsToIgnore = ["INPUT", "TEXTAREA", "SELECT"]) {
|
|
14
|
+
function useHotkeys(hotkeys, tagsToIgnore = ["INPUT", "TEXTAREA", "SELECT"], triggerOnContentEditable = false) {
|
|
12
15
|
useEffect(() => {
|
|
13
16
|
const keydownListener = (event) => {
|
|
14
17
|
hotkeys.forEach(([hotkey, handler, options = { preventDefault: true }]) => {
|
|
15
|
-
if (getHotkeyMatcher(hotkey)(event) && shouldFireEvent(event, tagsToIgnore)) {
|
|
18
|
+
if (getHotkeyMatcher(hotkey)(event) && shouldFireEvent(event, tagsToIgnore, triggerOnContentEditable)) {
|
|
16
19
|
if (options.preventDefault) {
|
|
17
20
|
event.preventDefault();
|
|
18
21
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-hotkeys.js","sources":["../../src/use-hotkeys/use-hotkeys.ts"],"sourcesContent":["import { useEffect } from 'react';\nimport {
|
|
1
|
+
{"version":3,"file":"use-hotkeys.js","sources":["../../src/use-hotkeys/use-hotkeys.ts"],"sourcesContent":["import { useEffect } from 'react';\nimport { getHotkeyHandler, getHotkeyMatcher, HotkeyItemOptions } from './parse-hotkey';\n\nexport type { HotkeyItemOptions };\nexport { getHotkeyHandler };\n\nexport type HotkeyItem = [string, (event: KeyboardEvent) => void, HotkeyItemOptions?];\n\nfunction shouldFireEvent(\n event: KeyboardEvent,\n tagsToIgnore: string[],\n triggerOnContentEditable = false\n) {\n if (event.target instanceof HTMLElement) {\n if (triggerOnContentEditable) {\n return !tagsToIgnore.includes(event.target.tagName);\n }\n\n return !event.target.isContentEditable && !tagsToIgnore.includes(event.target.tagName);\n }\n\n return true;\n}\n\nexport function useHotkeys(\n hotkeys: HotkeyItem[],\n tagsToIgnore: string[] = ['INPUT', 'TEXTAREA', 'SELECT'],\n triggerOnContentEditable = false\n) {\n useEffect(() => {\n const keydownListener = (event: KeyboardEvent) => {\n hotkeys.forEach(([hotkey, handler, options = { preventDefault: true }]) => {\n if (\n getHotkeyMatcher(hotkey)(event) &&\n shouldFireEvent(event, tagsToIgnore, triggerOnContentEditable)\n ) {\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,wBAAwB,GAAG,KAAK,EAAE;AAChF,EAAE,IAAI,KAAK,CAAC,MAAM,YAAY,WAAW,EAAE;AAC3C,IAAI,IAAI,wBAAwB,EAAE;AAClC,MAAM,OAAO,CAAC,YAAY,CAAC,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;AAC1D,KAAK;AACL,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,wBAAwB,GAAG,KAAK,EAAE;AACtH,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,EAAE,wBAAwB,CAAC,EAAE;AAC/G,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;;;;"}
|
|
@@ -2,5 +2,5 @@ import { getHotkeyHandler, HotkeyItemOptions } from './parse-hotkey';
|
|
|
2
2
|
export type { HotkeyItemOptions };
|
|
3
3
|
export { getHotkeyHandler };
|
|
4
4
|
export type HotkeyItem = [string, (event: KeyboardEvent) => void, HotkeyItemOptions?];
|
|
5
|
-
export declare function useHotkeys(hotkeys: HotkeyItem[], tagsToIgnore?: string[]): void;
|
|
5
|
+
export declare function useHotkeys(hotkeys: HotkeyItem[], tagsToIgnore?: string[], triggerOnContentEditable?: boolean): void;
|
|
6
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,
|
|
1
|
+
{"version":3,"file":"use-hotkeys.d.ts","sourceRoot":"","sources":["../../src/use-hotkeys/use-hotkeys.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,gBAAgB,EAAoB,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEvF,YAAY,EAAE,iBAAiB,EAAE,CAAC;AAClC,OAAO,EAAE,gBAAgB,EAAE,CAAC;AAE5B,MAAM,MAAM,UAAU,GAAG,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,aAAa,KAAK,IAAI,EAAE,iBAAiB,CAAC,CAAC,CAAC;AAkBtF,wBAAgB,UAAU,CACxB,OAAO,EAAE,UAAU,EAAE,EACrB,YAAY,GAAE,MAAM,EAAoC,EACxD,wBAAwB,UAAQ,QAqBjC"}
|