@elliemae/ds-floating-context 3.70.0-alpha.12 → 3.70.0-alpha.14

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.
@@ -0,0 +1,74 @@
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
+ var useFloatingEscape_exports = {};
30
+ __export(useFloatingEscape_exports, {
31
+ useFloatingEscape: () => useFloatingEscape
32
+ });
33
+ module.exports = __toCommonJS(useFloatingEscape_exports);
34
+ var React = __toESM(require("react"));
35
+ var import_react = require("react");
36
+ const useFloatingEscape = ({
37
+ enabled,
38
+ floating,
39
+ reference,
40
+ onEscapeRef,
41
+ handleClose,
42
+ returnFocusToReference
43
+ }) => {
44
+ const isFocusWithinFloatingScope = (0, import_react.useCallback)(
45
+ (active) => {
46
+ if (!active) return false;
47
+ if (floating && floating.contains(active)) return true;
48
+ if (!reference) return false;
49
+ return reference === active || reference.contains(active);
50
+ },
51
+ [floating, reference]
52
+ );
53
+ (0, import_react.useEffect)(() => {
54
+ if (!enabled) return void 0;
55
+ const listener = (event) => {
56
+ if (event.key !== "Escape") return;
57
+ if (!isFocusWithinFloatingScope(document.activeElement)) return;
58
+ const cb = onEscapeRef.current;
59
+ if (cb) {
60
+ cb(event);
61
+ } else {
62
+ handleClose();
63
+ }
64
+ if (returnFocusToReference && reference instanceof HTMLElement) {
65
+ reference.focus();
66
+ }
67
+ };
68
+ document.addEventListener("keydown", listener, true);
69
+ return () => {
70
+ document.removeEventListener("keydown", listener, true);
71
+ };
72
+ }, [enabled, handleClose, isFocusWithinFloatingScope, onEscapeRef, reference, returnFocusToReference]);
73
+ };
74
+ //# sourceMappingURL=useFloatingEscape.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/hooks/useFloatingEscape.ts", "../../../../../../scripts/build/transpile/react-shim.js"],
4
+ "sourcesContent": ["import { useCallback, useEffect, type MutableRefObject } from 'react';\n\ninterface UseFloatingEscapeParams {\n enabled: boolean;\n floating: HTMLElement | null;\n reference: Element | null;\n /** Latest-ref of the consumer's onEscape callback. Construct with `useLatestRef(onEscape)`. */\n onEscapeRef: MutableRefObject<((event: KeyboardEvent) => void) | undefined>;\n /** Fallback close handler invoked when no `onEscape` is provided. */\n handleClose: () => void;\n /** When true, calls `reference.focus()` after the escape close. */\n returnFocusToReference: boolean;\n}\n\n/**\n * Listens for `Escape` on the document and dismisses the floating element when focus is\n * within the floating element or on the reference element. Outside that scope the event is\n * ignored \u2014 we don't hijack Escape for unrelated UI on the page.\n */\nexport const useFloatingEscape = ({\n enabled,\n floating,\n reference,\n onEscapeRef,\n handleClose,\n returnFocusToReference,\n}: UseFloatingEscapeParams) => {\n const isFocusWithinFloatingScope = useCallback(\n (active: Element | null): boolean => {\n if (!active) return false;\n if (floating && floating.contains(active)) return true;\n if (!reference) return false;\n return reference === active || reference.contains(active);\n },\n [floating, reference],\n );\n\n useEffect(() => {\n if (!enabled) return undefined;\n\n const listener = (event: KeyboardEvent) => {\n if (event.key !== 'Escape') return;\n if (!isFocusWithinFloatingScope(document.activeElement)) return;\n\n const cb = onEscapeRef.current;\n if (cb) {\n cb(event);\n } else {\n handleClose();\n }\n if (returnFocusToReference && reference instanceof HTMLElement) {\n reference.focus();\n }\n };\n\n document.addEventListener('keydown', listener, true);\n return () => {\n document.removeEventListener('keydown', listener, true);\n };\n }, [enabled, handleClose, isFocusWithinFloatingScope, onEscapeRef, reference, returnFocusToReference]);\n};\n", "import * as React from 'react';\nexport { React };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,mBAA8D;AAmBvD,MAAM,oBAAoB,CAAC;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAA+B;AAC7B,QAAM,iCAA6B;AAAA,IACjC,CAAC,WAAoC;AACnC,UAAI,CAAC,OAAQ,QAAO;AACpB,UAAI,YAAY,SAAS,SAAS,MAAM,EAAG,QAAO;AAClD,UAAI,CAAC,UAAW,QAAO;AACvB,aAAO,cAAc,UAAU,UAAU,SAAS,MAAM;AAAA,IAC1D;AAAA,IACA,CAAC,UAAU,SAAS;AAAA,EACtB;AAEA,8BAAU,MAAM;AACd,QAAI,CAAC,QAAS,QAAO;AAErB,UAAM,WAAW,CAAC,UAAyB;AACzC,UAAI,MAAM,QAAQ,SAAU;AAC5B,UAAI,CAAC,2BAA2B,SAAS,aAAa,EAAG;AAEzD,YAAM,KAAK,YAAY;AACvB,UAAI,IAAI;AACN,WAAG,KAAK;AAAA,MACV,OAAO;AACL,oBAAY;AAAA,MACd;AACA,UAAI,0BAA0B,qBAAqB,aAAa;AAC9D,kBAAU,MAAM;AAAA,MAClB;AAAA,IACF;AAEA,aAAS,iBAAiB,WAAW,UAAU,IAAI;AACnD,WAAO,MAAM;AACX,eAAS,oBAAoB,WAAW,UAAU,IAAI;AAAA,IACxD;AAAA,EACF,GAAG,CAAC,SAAS,aAAa,4BAA4B,aAAa,WAAW,sBAAsB,CAAC;AACvG;",
6
+ "names": []
7
+ }
@@ -0,0 +1,44 @@
1
+ import * as React from "react";
2
+ import { useCallback, useEffect } from "react";
3
+ const useFloatingEscape = ({
4
+ enabled,
5
+ floating,
6
+ reference,
7
+ onEscapeRef,
8
+ handleClose,
9
+ returnFocusToReference
10
+ }) => {
11
+ const isFocusWithinFloatingScope = useCallback(
12
+ (active) => {
13
+ if (!active) return false;
14
+ if (floating && floating.contains(active)) return true;
15
+ if (!reference) return false;
16
+ return reference === active || reference.contains(active);
17
+ },
18
+ [floating, reference]
19
+ );
20
+ useEffect(() => {
21
+ if (!enabled) return void 0;
22
+ const listener = (event) => {
23
+ if (event.key !== "Escape") return;
24
+ if (!isFocusWithinFloatingScope(document.activeElement)) return;
25
+ const cb = onEscapeRef.current;
26
+ if (cb) {
27
+ cb(event);
28
+ } else {
29
+ handleClose();
30
+ }
31
+ if (returnFocusToReference && reference instanceof HTMLElement) {
32
+ reference.focus();
33
+ }
34
+ };
35
+ document.addEventListener("keydown", listener, true);
36
+ return () => {
37
+ document.removeEventListener("keydown", listener, true);
38
+ };
39
+ }, [enabled, handleClose, isFocusWithinFloatingScope, onEscapeRef, reference, returnFocusToReference]);
40
+ };
41
+ export {
42
+ useFloatingEscape
43
+ };
44
+ //# sourceMappingURL=useFloatingEscape.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../../scripts/build/transpile/react-shim.js", "../../../src/hooks/useFloatingEscape.ts"],
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { useCallback, useEffect, type MutableRefObject } from 'react';\n\ninterface UseFloatingEscapeParams {\n enabled: boolean;\n floating: HTMLElement | null;\n reference: Element | null;\n /** Latest-ref of the consumer's onEscape callback. Construct with `useLatestRef(onEscape)`. */\n onEscapeRef: MutableRefObject<((event: KeyboardEvent) => void) | undefined>;\n /** Fallback close handler invoked when no `onEscape` is provided. */\n handleClose: () => void;\n /** When true, calls `reference.focus()` after the escape close. */\n returnFocusToReference: boolean;\n}\n\n/**\n * Listens for `Escape` on the document and dismisses the floating element when focus is\n * within the floating element or on the reference element. Outside that scope the event is\n * ignored \u2014 we don't hijack Escape for unrelated UI on the page.\n */\nexport const useFloatingEscape = ({\n enabled,\n floating,\n reference,\n onEscapeRef,\n handleClose,\n returnFocusToReference,\n}: UseFloatingEscapeParams) => {\n const isFocusWithinFloatingScope = useCallback(\n (active: Element | null): boolean => {\n if (!active) return false;\n if (floating && floating.contains(active)) return true;\n if (!reference) return false;\n return reference === active || reference.contains(active);\n },\n [floating, reference],\n );\n\n useEffect(() => {\n if (!enabled) return undefined;\n\n const listener = (event: KeyboardEvent) => {\n if (event.key !== 'Escape') return;\n if (!isFocusWithinFloatingScope(document.activeElement)) return;\n\n const cb = onEscapeRef.current;\n if (cb) {\n cb(event);\n } else {\n handleClose();\n }\n if (returnFocusToReference && reference instanceof HTMLElement) {\n reference.focus();\n }\n };\n\n document.addEventListener('keydown', listener, true);\n return () => {\n document.removeEventListener('keydown', listener, true);\n };\n }, [enabled, handleClose, isFocusWithinFloatingScope, onEscapeRef, reference, returnFocusToReference]);\n};\n"],
5
+ "mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,aAAa,iBAAwC;AAmBvD,MAAM,oBAAoB,CAAC;AAAA,EAChC;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,MAA+B;AAC7B,QAAM,6BAA6B;AAAA,IACjC,CAAC,WAAoC;AACnC,UAAI,CAAC,OAAQ,QAAO;AACpB,UAAI,YAAY,SAAS,SAAS,MAAM,EAAG,QAAO;AAClD,UAAI,CAAC,UAAW,QAAO;AACvB,aAAO,cAAc,UAAU,UAAU,SAAS,MAAM;AAAA,IAC1D;AAAA,IACA,CAAC,UAAU,SAAS;AAAA,EACtB;AAEA,YAAU,MAAM;AACd,QAAI,CAAC,QAAS,QAAO;AAErB,UAAM,WAAW,CAAC,UAAyB;AACzC,UAAI,MAAM,QAAQ,SAAU;AAC5B,UAAI,CAAC,2BAA2B,SAAS,aAAa,EAAG;AAEzD,YAAM,KAAK,YAAY;AACvB,UAAI,IAAI;AACN,WAAG,KAAK;AAAA,MACV,OAAO;AACL,oBAAY;AAAA,MACd;AACA,UAAI,0BAA0B,qBAAqB,aAAa;AAC9D,kBAAU,MAAM;AAAA,MAClB;AAAA,IACF;AAEA,aAAS,iBAAiB,WAAW,UAAU,IAAI;AACnD,WAAO,MAAM;AACX,eAAS,oBAAoB,WAAW,UAAU,IAAI;AAAA,IACxD;AAAA,EACF,GAAG,CAAC,SAAS,aAAa,4BAA4B,aAAa,WAAW,sBAAsB,CAAC;AACvG;",
6
+ "names": []
7
+ }
@@ -0,0 +1,19 @@
1
+ import { type MutableRefObject } from 'react';
2
+ interface UseFloatingEscapeParams {
3
+ enabled: boolean;
4
+ floating: HTMLElement | null;
5
+ reference: Element | null;
6
+ /** Latest-ref of the consumer's onEscape callback. Construct with `useLatestRef(onEscape)`. */
7
+ onEscapeRef: MutableRefObject<((event: KeyboardEvent) => void) | undefined>;
8
+ /** Fallback close handler invoked when no `onEscape` is provided. */
9
+ handleClose: () => void;
10
+ /** When true, calls `reference.focus()` after the escape close. */
11
+ returnFocusToReference: boolean;
12
+ }
13
+ /**
14
+ * Listens for `Escape` on the document and dismisses the floating element when focus is
15
+ * within the floating element or on the reference element. Outside that scope the event is
16
+ * ignored — we don't hijack Escape for unrelated UI on the page.
17
+ */
18
+ export declare const useFloatingEscape: ({ enabled, floating, reference, onEscapeRef, handleClose, returnFocusToReference, }: UseFloatingEscapeParams) => void;
19
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@elliemae/ds-floating-context",
3
- "version": "3.70.0-alpha.12",
3
+ "version": "3.70.0-alpha.14",
4
4
  "license": "MIT",
5
5
  "description": "ICE MT - Dimsum - Popper Hook",
6
6
  "files": [
@@ -36,14 +36,14 @@
36
36
  "indent": 4
37
37
  },
38
38
  "dependencies": {
39
- "@elliemae/ds-hooks-headless-tooltip": "3.70.0-alpha.12",
40
- "@elliemae/ds-system": "3.70.0-alpha.12",
41
- "@elliemae/ds-typescript-helpers": "3.70.0-alpha.12",
42
- "@elliemae/ds-props-helpers": "3.70.0-alpha.12"
39
+ "@elliemae/ds-hooks-headless-tooltip": "3.70.0-alpha.14",
40
+ "@elliemae/ds-props-helpers": "3.70.0-alpha.14",
41
+ "@elliemae/ds-system": "3.70.0-alpha.14",
42
+ "@elliemae/ds-typescript-helpers": "3.70.0-alpha.14"
43
43
  },
44
44
  "devDependencies": {
45
45
  "jest": "^30.0.0",
46
- "@elliemae/ds-monorepo-devops": "3.70.0-alpha.12"
46
+ "@elliemae/ds-monorepo-devops": "3.70.0-alpha.14"
47
47
  },
48
48
  "peerDependencies": {
49
49
  "lodash-es": "^4.18.1",