@radix-ui/react-use-escape-keydown 0.0.0-20250116175529

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/README.md ADDED
@@ -0,0 +1,13 @@
1
+ # `react-use-escape-keydown`
2
+
3
+ ## Installation
4
+
5
+ ```sh
6
+ $ yarn add @radix-ui/react-use-escape-keydown
7
+ # or
8
+ $ npm install @radix-ui/react-use-escape-keydown
9
+ ```
10
+
11
+ ## Usage
12
+
13
+ This is an internal utility, not intended for public usage.
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Listens for when the escape key is down
3
+ */
4
+ declare function useEscapeKeydown(onEscapeKeyDownProp?: (event: KeyboardEvent) => void, ownerDocument?: Document): void;
5
+
6
+ export { useEscapeKeydown };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Listens for when the escape key is down
3
+ */
4
+ declare function useEscapeKeydown(onEscapeKeyDownProp?: (event: KeyboardEvent) => void, ownerDocument?: Document): void;
5
+
6
+ export { useEscapeKeydown };
package/dist/index.js ADDED
@@ -0,0 +1,52 @@
1
+ "use strict";
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
11
+ };
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // packages/react/use-escape-keydown/src/index.ts
31
+ var src_exports = {};
32
+ __export(src_exports, {
33
+ useEscapeKeydown: () => useEscapeKeydown
34
+ });
35
+ module.exports = __toCommonJS(src_exports);
36
+
37
+ // packages/react/use-escape-keydown/src/useEscapeKeydown.tsx
38
+ var React = __toESM(require("react"));
39
+ var import_react_use_callback_ref = require("@radix-ui/react-use-callback-ref");
40
+ function useEscapeKeydown(onEscapeKeyDownProp, ownerDocument = globalThis?.document) {
41
+ const onEscapeKeyDown = (0, import_react_use_callback_ref.useCallbackRef)(onEscapeKeyDownProp);
42
+ React.useEffect(() => {
43
+ const handleKeyDown = (event) => {
44
+ if (event.key === "Escape") {
45
+ onEscapeKeyDown(event);
46
+ }
47
+ };
48
+ ownerDocument.addEventListener("keydown", handleKeyDown, { capture: true });
49
+ return () => ownerDocument.removeEventListener("keydown", handleKeyDown, { capture: true });
50
+ }, [onEscapeKeyDown, ownerDocument]);
51
+ }
52
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts", "../src/useEscapeKeydown.tsx"],
4
+ "sourcesContent": ["export { useEscapeKeydown } from './useEscapeKeydown';\n", "import * as React from 'react';\nimport { useCallbackRef } from '@radix-ui/react-use-callback-ref';\n\n/**\n * Listens for when the escape key is down\n */\nfunction useEscapeKeydown(\n onEscapeKeyDownProp?: (event: KeyboardEvent) => void,\n ownerDocument: Document = globalThis?.document\n) {\n const onEscapeKeyDown = useCallbackRef(onEscapeKeyDownProp);\n\n React.useEffect(() => {\n const handleKeyDown = (event: KeyboardEvent) => {\n if (event.key === 'Escape') {\n onEscapeKeyDown(event);\n }\n };\n ownerDocument.addEventListener('keydown', handleKeyDown, { capture: true });\n return () => ownerDocument.removeEventListener('keydown', handleKeyDown, { capture: true });\n }, [onEscapeKeyDown, ownerDocument]);\n}\n\nexport { useEscapeKeydown };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACAA,YAAuB;AACvB,oCAA+B;AAK/B,SAAS,iBACP,qBACA,gBAA0B,YAAY,UACtC;AACA,QAAM,sBAAkB,8CAAe,mBAAmB;AAE1D,EAAM,gBAAU,MAAM;AACpB,UAAM,gBAAgB,CAAC,UAAyB;AAC9C,UAAI,MAAM,QAAQ,UAAU;AAC1B,wBAAgB,KAAK;AAAA,MACvB;AAAA,IACF;AACA,kBAAc,iBAAiB,WAAW,eAAe,EAAE,SAAS,KAAK,CAAC;AAC1E,WAAO,MAAM,cAAc,oBAAoB,WAAW,eAAe,EAAE,SAAS,KAAK,CAAC;AAAA,EAC5F,GAAG,CAAC,iBAAiB,aAAa,CAAC;AACrC;",
6
+ "names": []
7
+ }
package/dist/index.mjs ADDED
@@ -0,0 +1,19 @@
1
+ // packages/react/use-escape-keydown/src/useEscapeKeydown.tsx
2
+ import * as React from "react";
3
+ import { useCallbackRef } from "@radix-ui/react-use-callback-ref";
4
+ function useEscapeKeydown(onEscapeKeyDownProp, ownerDocument = globalThis?.document) {
5
+ const onEscapeKeyDown = useCallbackRef(onEscapeKeyDownProp);
6
+ React.useEffect(() => {
7
+ const handleKeyDown = (event) => {
8
+ if (event.key === "Escape") {
9
+ onEscapeKeyDown(event);
10
+ }
11
+ };
12
+ ownerDocument.addEventListener("keydown", handleKeyDown, { capture: true });
13
+ return () => ownerDocument.removeEventListener("keydown", handleKeyDown, { capture: true });
14
+ }, [onEscapeKeyDown, ownerDocument]);
15
+ }
16
+ export {
17
+ useEscapeKeydown
18
+ };
19
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/useEscapeKeydown.tsx"],
4
+ "sourcesContent": ["import * as React from 'react';\nimport { useCallbackRef } from '@radix-ui/react-use-callback-ref';\n\n/**\n * Listens for when the escape key is down\n */\nfunction useEscapeKeydown(\n onEscapeKeyDownProp?: (event: KeyboardEvent) => void,\n ownerDocument: Document = globalThis?.document\n) {\n const onEscapeKeyDown = useCallbackRef(onEscapeKeyDownProp);\n\n React.useEffect(() => {\n const handleKeyDown = (event: KeyboardEvent) => {\n if (event.key === 'Escape') {\n onEscapeKeyDown(event);\n }\n };\n ownerDocument.addEventListener('keydown', handleKeyDown, { capture: true });\n return () => ownerDocument.removeEventListener('keydown', handleKeyDown, { capture: true });\n }, [onEscapeKeyDown, ownerDocument]);\n}\n\nexport { useEscapeKeydown };\n"],
5
+ "mappings": ";AAAA,YAAY,WAAW;AACvB,SAAS,sBAAsB;AAK/B,SAAS,iBACP,qBACA,gBAA0B,YAAY,UACtC;AACA,QAAM,kBAAkB,eAAe,mBAAmB;AAE1D,EAAM,gBAAU,MAAM;AACpB,UAAM,gBAAgB,CAAC,UAAyB;AAC9C,UAAI,MAAM,QAAQ,UAAU;AAC1B,wBAAgB,KAAK;AAAA,MACvB;AAAA,IACF;AACA,kBAAc,iBAAiB,WAAW,eAAe,EAAE,SAAS,KAAK,CAAC;AAC1E,WAAO,MAAM,cAAc,oBAAoB,WAAW,eAAe,EAAE,SAAS,KAAK,CAAC;AAAA,EAC5F,GAAG,CAAC,iBAAiB,aAAa,CAAC;AACrC;",
6
+ "names": []
7
+ }
package/package.json ADDED
@@ -0,0 +1,49 @@
1
+ {
2
+ "name": "@radix-ui/react-use-escape-keydown",
3
+ "version": "0.0.0-20250116175529",
4
+ "license": "MIT",
5
+ "exports": {
6
+ ".": {
7
+ "import": {
8
+ "types": "./dist/index.d.mts",
9
+ "default": "./dist/index.mjs"
10
+ },
11
+ "require": {
12
+ "types": "./dist/index.d.ts",
13
+ "default": "./dist/index.js"
14
+ }
15
+ }
16
+ },
17
+ "source": "./src/index.ts",
18
+ "main": "./dist/index.js",
19
+ "module": "./dist/index.mjs",
20
+ "types": "./dist/index.d.ts",
21
+ "files": [
22
+ "dist",
23
+ "README.md"
24
+ ],
25
+ "sideEffects": false,
26
+ "scripts": {
27
+ "clean": "rm -rf dist"
28
+ },
29
+ "dependencies": {
30
+ "@radix-ui/react-use-callback-ref": "workspace:*"
31
+ },
32
+ "peerDependencies": {
33
+ "@types/react": "*",
34
+ "react": "^16.8 || ^17.0 || ^18.0 || ^19.0 || ^19.0.0-rc"
35
+ },
36
+ "peerDependenciesMeta": {
37
+ "@types/react": {
38
+ "optional": true
39
+ }
40
+ },
41
+ "homepage": "https://radix-ui.com/primitives",
42
+ "repository": {
43
+ "type": "git",
44
+ "url": "git+https://github.com/radix-ui/primitives.git"
45
+ },
46
+ "bugs": {
47
+ "url": "https://github.com/radix-ui/primitives/issues"
48
+ }
49
+ }