@elliemae/ds-hooks-keyboard-navigation 3.27.0-next.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.
@@ -0,0 +1,102 @@
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 DSHooksKeyboardNavigation_exports = {};
30
+ __export(DSHooksKeyboardNavigation_exports, {
31
+ UseKeyboardNavigationWithSchema: () => UseKeyboardNavigationWithSchema,
32
+ useKeyboardNavigation: () => useKeyboardNavigation
33
+ });
34
+ module.exports = __toCommonJS(DSHooksKeyboardNavigation_exports);
35
+ var React = __toESM(require("react"));
36
+ var import_react = require("react");
37
+ var import_ds_utilities = require("@elliemae/ds-utilities");
38
+ var import_ds_props_helpers = require("@elliemae/ds-props-helpers");
39
+ var import_react_desc_prop_types2 = require("./react-desc-prop-types.js");
40
+ const useKeyboardNavigation = (props) => {
41
+ const { options, isHorizontal, disableRoving, focusCriteria } = props;
42
+ const [focusedOption, setFocusedOption] = (0, import_react.useState)(null);
43
+ const previousFocusedOption = (0, import_react.useRef)(null);
44
+ const focusedOptionMutable = (0, import_react.useRef)(null);
45
+ const config = (0, import_react.useMemo)(
46
+ () => ({
47
+ onBlur: () => {
48
+ previousFocusedOption.current = focusedOption;
49
+ setFocusedOption(null);
50
+ }
51
+ }),
52
+ [focusedOption]
53
+ );
54
+ const handleParentOnBlur = (0, import_ds_utilities.useOnBlurOut)(config);
55
+ const arrowsKeys = (0, import_react.useMemo)(
56
+ () => isHorizontal ? ["ArrowLeft", "ArrowRight"] : ["ArrowUp", "ArrowDown"],
57
+ [isHorizontal]
58
+ );
59
+ const onKeyDown = (0, import_react.useCallback)(
60
+ (e) => {
61
+ const { key } = e;
62
+ const index = options.findIndex((option) => option === focusedOptionMutable.current);
63
+ if (key === arrowsKeys[0]) {
64
+ e.preventDefault();
65
+ const previous = (0, import_ds_utilities.findInCircularList)(options, index, focusCriteria, -1);
66
+ setFocusedOption(options[previous]);
67
+ } else if (key === arrowsKeys[1]) {
68
+ e.preventDefault();
69
+ const next = (0, import_ds_utilities.findInCircularList)(options, index, focusCriteria, 1);
70
+ setFocusedOption(options[next]);
71
+ }
72
+ },
73
+ [arrowsKeys, options, focusCriteria, setFocusedOption]
74
+ );
75
+ const getItemProps = (0, import_react.useCallback)(
76
+ (dsId) => ({
77
+ innerRef: (el) => {
78
+ if (el && dsId === focusedOption && focusedOptionMutable.current !== dsId) {
79
+ el?.focus();
80
+ focusedOptionMutable.current = dsId;
81
+ }
82
+ },
83
+ onFocus: () => setFocusedOption(dsId),
84
+ tabIndex: disableRoving || dsId === focusedOptionMutable.current || previousFocusedOption.current === dsId && focusedOptionMutable.current === null || dsId === options[0] && focusedOptionMutable.current === null && previousFocusedOption.current === null ? 0 : -1
85
+ }),
86
+ [disableRoving, focusedOption, options]
87
+ );
88
+ const getWrapperProps = (0, import_react.useCallback)(
89
+ () => ({
90
+ onKeyDown,
91
+ onBlur: handleParentOnBlur
92
+ }),
93
+ [onKeyDown, handleParentOnBlur]
94
+ );
95
+ return (0, import_react.useMemo)(
96
+ () => ({ getWrapperProps, getItemProps, focusedOption, setFocusedOption }),
97
+ [focusedOption, getWrapperProps, getItemProps]
98
+ );
99
+ };
100
+ const UseKeyboardNavigationWithSchema = (0, import_ds_props_helpers.describe)(useKeyboardNavigation);
101
+ UseKeyboardNavigationWithSchema.propTypes = import_react_desc_prop_types2.propTypes;
102
+ //# sourceMappingURL=DSHooksKeyboardNavigation.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/DSHooksKeyboardNavigation.tsx", "../../../../../scripts/build/transpile/react-shim.js"],
4
+ "sourcesContent": ["import { useCallback, useMemo, useRef, useState } from 'react';\nimport { useOnBlurOut, findInCircularList } from '@elliemae/ds-utilities';\nimport { describe } from '@elliemae/ds-props-helpers';\nimport { type DSHooksKeyboardNaviationT } from './react-desc-prop-types.js';\nimport { propTypes } from './react-desc-prop-types.js';\nconst useKeyboardNavigation = (props: DSHooksKeyboardNaviationT.Props) => {\n const { options, isHorizontal, disableRoving, focusCriteria } = props;\n const [focusedOption, setFocusedOption] = useState<string | null>(null);\n const previousFocusedOption = useRef<string | null>(null);\n const focusedOptionMutable = useRef<string | null>(null);\n\n const config = useMemo(\n () => ({\n onBlur: () => {\n previousFocusedOption.current = focusedOption;\n setFocusedOption(null);\n },\n }),\n [focusedOption],\n );\n const handleParentOnBlur = useOnBlurOut(config);\n\n const arrowsKeys = useMemo(\n () => (isHorizontal ? ['ArrowLeft', 'ArrowRight'] : ['ArrowUp', 'ArrowDown']),\n [isHorizontal],\n );\n const onKeyDown: React.KeyboardEventHandler = useCallback(\n (e) => {\n const { key } = e;\n const index = options.findIndex((option) => option === focusedOptionMutable.current);\n if (key === arrowsKeys[0]) {\n e.preventDefault();\n const previous = findInCircularList(options, index, focusCriteria, -1);\n setFocusedOption(options[previous]);\n } else if (key === arrowsKeys[1]) {\n e.preventDefault();\n const next = findInCircularList(options, index, focusCriteria, 1);\n setFocusedOption(options[next]);\n }\n },\n [arrowsKeys, options, focusCriteria, setFocusedOption],\n );\n\n const getItemProps = useCallback(\n (dsId: string) => ({\n innerRef: (el: HTMLElement | null) => {\n if (el && dsId === focusedOption && focusedOptionMutable.current !== dsId) {\n el?.focus();\n focusedOptionMutable.current = dsId;\n }\n },\n onFocus: () => setFocusedOption(dsId),\n tabIndex:\n disableRoving ||\n dsId === focusedOptionMutable.current ||\n (previousFocusedOption.current === dsId && focusedOptionMutable.current === null) ||\n (dsId === options[0] && focusedOptionMutable.current === null && previousFocusedOption.current === null)\n ? 0\n : -1,\n }),\n [disableRoving, focusedOption, options],\n );\n\n const getWrapperProps = useCallback(\n () => ({\n onKeyDown,\n onBlur: handleParentOnBlur,\n }),\n [onKeyDown, handleParentOnBlur],\n );\n\n return useMemo(\n () => ({ getWrapperProps, getItemProps, focusedOption, setFocusedOption }),\n [focusedOption, getWrapperProps, getItemProps],\n );\n};\n\nconst UseKeyboardNavigationWithSchema = describe(useKeyboardNavigation);\nUseKeyboardNavigationWithSchema.propTypes = propTypes;\n\nexport { useKeyboardNavigation, UseKeyboardNavigationWithSchema };\n", "import * as React from 'react';\nexport { React };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,mBAAuD;AACvD,0BAAiD;AACjD,8BAAyB;AAEzB,IAAAA,gCAA0B;AAC1B,MAAM,wBAAwB,CAAC,UAA2C;AACxE,QAAM,EAAE,SAAS,cAAc,eAAe,cAAc,IAAI;AAChE,QAAM,CAAC,eAAe,gBAAgB,QAAI,uBAAwB,IAAI;AACtE,QAAM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AQ,sBAAsB,YAAY,OAC/F,IACA;AAAA,IACR;AAAA,IACA,CAAC,eAAe,eAAe,OAAO;AAAA,EACxC;AAEA,QAAM,sBAAkB;AAAA,IACtB,OAAO;AAAA,MACL;AAAA,MACA,QAAQ;AAAA,IACV;AAAA,IACA,CAAC,WAAW,kBAAkB;AAAA,EAChC;AAEA,aAAO;AAAA,IACL,OAAO,EAAE,iBAAiB,cAAc,eAAe,iBAAiB;AAAA,IACxE,CAAC,eAAe,iBAAiB,YAAY;AAAA,EAC/C;AACF;AAEA,MAAM,sCAAkC,kCAAS,qBAAqB;AACtE,gCAAgC,YAAY;",
6
+ "names": ["import_react_desc_prop_types"]
7
+ }
@@ -0,0 +1,38 @@
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 src_exports = {};
30
+ __export(src_exports, {
31
+ UseKeyboardNavigationWithSchema: () => import_DSHooksKeyboardNavigation.UseKeyboardNavigationWithSchema,
32
+ useKeyboardNavigation: () => import_DSHooksKeyboardNavigation.useKeyboardNavigation
33
+ });
34
+ module.exports = __toCommonJS(src_exports);
35
+ var React = __toESM(require("react"));
36
+ var import_DSHooksKeyboardNavigation = require("./DSHooksKeyboardNavigation.js");
37
+ var import_react_desc_prop_types = require("./react-desc-prop-types.js");
38
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/index.ts", "../../../../../scripts/build/transpile/react-shim.js"],
4
+ "sourcesContent": ["export { UseKeyboardNavigationWithSchema, useKeyboardNavigation } from './DSHooksKeyboardNavigation.js';\nexport { type DSHooksKeyboardNaviationT } from './react-desc-prop-types.js';\n", "import * as React from 'react';\nexport { React };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADAvB,uCAAuE;AACvE,mCAA+C;",
6
+ "names": []
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "type": "commonjs",
3
+ "sideEffects": [
4
+ "*.css",
5
+ "*.scss"
6
+ ]
7
+ }
@@ -0,0 +1,46 @@
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 react_desc_prop_types_exports = {};
30
+ __export(react_desc_prop_types_exports, {
31
+ propTypes: () => propTypes
32
+ });
33
+ module.exports = __toCommonJS(react_desc_prop_types_exports);
34
+ var React = __toESM(require("react"));
35
+ var import_ds_utilities = require("@elliemae/ds-utilities");
36
+ const propTypes = {
37
+ options: import_ds_utilities.PropTypes.arrayOf(import_ds_utilities.PropTypes.string).description("Array of strings to be items ids.").isRequired,
38
+ isHorizontal: import_ds_utilities.PropTypes.bool.isRequired.description(
39
+ "If true, the roving tab index will be applied to the items horizontally. If false, it will be applied vertically."
40
+ ).defaultValue(false),
41
+ disableRoving: import_ds_utilities.PropTypes.bool.description("If true, the roving tab index will not be applied to the items."),
42
+ focusCriteria: import_ds_utilities.PropTypes.func.description(
43
+ "Function that returns a boolean to determine if the element should be focused."
44
+ )
45
+ };
46
+ //# sourceMappingURL=react-desc-prop-types.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/react-desc-prop-types.ts", "../../../../../scripts/build/transpile/react-shim.js"],
4
+ "sourcesContent": ["/* eslint-disable @typescript-eslint/no-empty-interface */\n\nimport type { WeakValidationMap } from 'react';\nimport { PropTypes } from '@elliemae/ds-utilities';\nimport { type useKeyboardNavigation } from './DSHooksKeyboardNavigation.js';\nexport declare namespace DSHooksKeyboardNaviationT {\n interface Props {\n options: string[];\n isHorizontal?: boolean;\n disableRoving?: boolean;\n focusCriteria?: (dsId: string) => boolean;\n }\n\n type UseKeyboardNavigationReturnType = ReturnType<typeof useKeyboardNavigation>;\n type ItemPropsT = ReturnType<UseKeyboardNavigationReturnType['getItemProps']>;\n type WrapperPropsT = ReturnType<UseKeyboardNavigationReturnType['getWrapperProps']>;\n}\n\nexport const propTypes = {\n options: PropTypes.arrayOf(PropTypes.string).description('Array of strings to be items ids.').isRequired,\n isHorizontal: PropTypes.bool.isRequired\n .description(\n 'If true, the roving tab index will be applied to the items horizontally. If false, it will be applied vertically.',\n )\n .defaultValue(false),\n disableRoving: PropTypes.bool.description('If true, the roving tab index will not be applied to the items.'),\n focusCriteria: PropTypes.func.description(\n 'Function that returns a boolean to determine if the element should be focused.',\n ),\n} as WeakValidationMap<unknown>;\n", "import * as React from 'react';\nexport { React };\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;ACAA,YAAuB;ADGvB,0BAA0B;AAenB,MAAM,YAAY;AAAA,EACvB,SAAS,8BAAU,QAAQ,8BAAU,MAAM,EAAE,YAAY,mCAAmC,EAAE;AAAA,EAC9F,cAAc,8BAAU,KAAK,WAC1B;AAAA,IACC;AAAA,EACF,EACC,aAAa,KAAK;AAAA,EACrB,eAAe,8BAAU,KAAK,YAAY,iEAAiE;AAAA,EAC3G,eAAe,8BAAU,KAAK;AAAA,IAC5B;AAAA,EACF;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,72 @@
1
+ import * as React from "react";
2
+ import { useCallback, useMemo, useRef, useState } from "react";
3
+ import { useOnBlurOut, findInCircularList } from "@elliemae/ds-utilities";
4
+ import { describe } from "@elliemae/ds-props-helpers";
5
+ import { propTypes } from "./react-desc-prop-types.js";
6
+ const useKeyboardNavigation = (props) => {
7
+ const { options, isHorizontal, disableRoving, focusCriteria } = props;
8
+ const [focusedOption, setFocusedOption] = useState(null);
9
+ const previousFocusedOption = useRef(null);
10
+ const focusedOptionMutable = useRef(null);
11
+ const config = useMemo(
12
+ () => ({
13
+ onBlur: () => {
14
+ previousFocusedOption.current = focusedOption;
15
+ setFocusedOption(null);
16
+ }
17
+ }),
18
+ [focusedOption]
19
+ );
20
+ const handleParentOnBlur = useOnBlurOut(config);
21
+ const arrowsKeys = useMemo(
22
+ () => isHorizontal ? ["ArrowLeft", "ArrowRight"] : ["ArrowUp", "ArrowDown"],
23
+ [isHorizontal]
24
+ );
25
+ const onKeyDown = useCallback(
26
+ (e) => {
27
+ const { key } = e;
28
+ const index = options.findIndex((option) => option === focusedOptionMutable.current);
29
+ if (key === arrowsKeys[0]) {
30
+ e.preventDefault();
31
+ const previous = findInCircularList(options, index, focusCriteria, -1);
32
+ setFocusedOption(options[previous]);
33
+ } else if (key === arrowsKeys[1]) {
34
+ e.preventDefault();
35
+ const next = findInCircularList(options, index, focusCriteria, 1);
36
+ setFocusedOption(options[next]);
37
+ }
38
+ },
39
+ [arrowsKeys, options, focusCriteria, setFocusedOption]
40
+ );
41
+ const getItemProps = useCallback(
42
+ (dsId) => ({
43
+ innerRef: (el) => {
44
+ if (el && dsId === focusedOption && focusedOptionMutable.current !== dsId) {
45
+ el?.focus();
46
+ focusedOptionMutable.current = dsId;
47
+ }
48
+ },
49
+ onFocus: () => setFocusedOption(dsId),
50
+ tabIndex: disableRoving || dsId === focusedOptionMutable.current || previousFocusedOption.current === dsId && focusedOptionMutable.current === null || dsId === options[0] && focusedOptionMutable.current === null && previousFocusedOption.current === null ? 0 : -1
51
+ }),
52
+ [disableRoving, focusedOption, options]
53
+ );
54
+ const getWrapperProps = useCallback(
55
+ () => ({
56
+ onKeyDown,
57
+ onBlur: handleParentOnBlur
58
+ }),
59
+ [onKeyDown, handleParentOnBlur]
60
+ );
61
+ return useMemo(
62
+ () => ({ getWrapperProps, getItemProps, focusedOption, setFocusedOption }),
63
+ [focusedOption, getWrapperProps, getItemProps]
64
+ );
65
+ };
66
+ const UseKeyboardNavigationWithSchema = describe(useKeyboardNavigation);
67
+ UseKeyboardNavigationWithSchema.propTypes = propTypes;
68
+ export {
69
+ UseKeyboardNavigationWithSchema,
70
+ useKeyboardNavigation
71
+ };
72
+ //# sourceMappingURL=DSHooksKeyboardNavigation.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../src/DSHooksKeyboardNavigation.tsx"],
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "import { useCallback, useMemo, useRef, useState } from 'react';\nimport { useOnBlurOut, findInCircularList } from '@elliemae/ds-utilities';\nimport { describe } from '@elliemae/ds-props-helpers';\nimport { type DSHooksKeyboardNaviationT } from './react-desc-prop-types.js';\nimport { propTypes } from './react-desc-prop-types.js';\nconst useKeyboardNavigation = (props: DSHooksKeyboardNaviationT.Props) => {\n const { options, isHorizontal, disableRoving, focusCriteria } = props;\n const [focusedOption, setFocusedOption] = useState<string | null>(null);\n const previousFocusedOption = useRef<string | null>(null);\n const focusedOptionMutable = useRef<string | null>(null);\n\n const config = useMemo(\n () => ({\n onBlur: () => {\n previousFocusedOption.current = focusedOption;\n setFocusedOption(null);\n },\n }),\n [focusedOption],\n );\n const handleParentOnBlur = useOnBlurOut(config);\n\n const arrowsKeys = useMemo(\n () => (isHorizontal ? ['ArrowLeft', 'ArrowRight'] : ['ArrowUp', 'ArrowDown']),\n [isHorizontal],\n );\n const onKeyDown: React.KeyboardEventHandler = useCallback(\n (e) => {\n const { key } = e;\n const index = options.findIndex((option) => option === focusedOptionMutable.current);\n if (key === arrowsKeys[0]) {\n e.preventDefault();\n const previous = findInCircularList(options, index, focusCriteria, -1);\n setFocusedOption(options[previous]);\n } else if (key === arrowsKeys[1]) {\n e.preventDefault();\n const next = findInCircularList(options, index, focusCriteria, 1);\n setFocusedOption(options[next]);\n }\n },\n [arrowsKeys, options, focusCriteria, setFocusedOption],\n );\n\n const getItemProps = useCallback(\n (dsId: string) => ({\n innerRef: (el: HTMLElement | null) => {\n if (el && dsId === focusedOption && focusedOptionMutable.current !== dsId) {\n el?.focus();\n focusedOptionMutable.current = dsId;\n }\n },\n onFocus: () => setFocusedOption(dsId),\n tabIndex:\n disableRoving ||\n dsId === focusedOptionMutable.current ||\n (previousFocusedOption.current === dsId && focusedOptionMutable.current === null) ||\n (dsId === options[0] && focusedOptionMutable.current === null && previousFocusedOption.current === null)\n ? 0\n : -1,\n }),\n [disableRoving, focusedOption, options],\n );\n\n const getWrapperProps = useCallback(\n () => ({\n onKeyDown,\n onBlur: handleParentOnBlur,\n }),\n [onKeyDown, handleParentOnBlur],\n );\n\n return useMemo(\n () => ({ getWrapperProps, getItemProps, focusedOption, setFocusedOption }),\n [focusedOption, getWrapperProps, getItemProps],\n );\n};\n\nconst UseKeyboardNavigationWithSchema = describe(useKeyboardNavigation);\nUseKeyboardNavigationWithSchema.propTypes = propTypes;\n\nexport { useKeyboardNavigation, UseKeyboardNavigationWithSchema };\n"],
5
+ "mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,aAAa,SAAS,QAAQ,gBAAgB;AACvD,SAAS,cAAc,0BAA0B;AACjD,SAAS,gBAAgB;AAEzB,SAAS,iBAAiB;AAC1B,MAAM,wBAAwB,CAAC,UAA2C;AACxE,QAAM,EAAE,SAAS,cAAc,eAAe,cAAc,IAAI;AAChE,QAAM,CAAC,eAAe,gBAAgB,IAAI,SAAwB,IAAI;AACtE,QAAM,wBAAwB,OAAsB,IAAI;AACxD,QAAM,uBAAuB,OAAsB,IAAI;AAEvD,QAAM,SAAS;AAAA,IACb,OAAO;AAAA,MACL,QAAQ,MAAM;AACZ,8BAAsB,UAAU;AAChC,yBAAiB,IAAI;AAAA,MACvB;AAAA,IACF;AAAA,IACA,CAAC,aAAa;AAAA,EAChB;AACA,QAAM,qBAAqB,aAAa,MAA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B,cAAc,eAAe,iBAAiB;AAAA,IACxE,CAAC,eAAe,iBAAiB,YAAY;AAAA,EAC/C;AACF;AAEA,MAAM,kCAAkC,SAAS,qBAAqB;AACtE,gCAAgC,YAAY;",
6
+ "names": []
7
+ }
@@ -0,0 +1,8 @@
1
+ import * as React from "react";
2
+ import { UseKeyboardNavigationWithSchema, useKeyboardNavigation } from "./DSHooksKeyboardNavigation.js";
3
+ import {} from "./react-desc-prop-types.js";
4
+ export {
5
+ UseKeyboardNavigationWithSchema,
6
+ useKeyboardNavigation
7
+ };
8
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../src/index.ts"],
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "export { UseKeyboardNavigationWithSchema, useKeyboardNavigation } from './DSHooksKeyboardNavigation.js';\nexport { type DSHooksKeyboardNaviationT } from './react-desc-prop-types.js';\n"],
5
+ "mappings": "AAAA,YAAY,WAAW;ACAvB,SAAS,iCAAiC,6BAA6B;AACvE,eAA+C;",
6
+ "names": []
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "type": "module",
3
+ "sideEffects": [
4
+ "*.css",
5
+ "*.scss"
6
+ ]
7
+ }
@@ -0,0 +1,16 @@
1
+ import * as React from "react";
2
+ import { PropTypes } from "@elliemae/ds-utilities";
3
+ const propTypes = {
4
+ options: PropTypes.arrayOf(PropTypes.string).description("Array of strings to be items ids.").isRequired,
5
+ isHorizontal: PropTypes.bool.isRequired.description(
6
+ "If true, the roving tab index will be applied to the items horizontally. If false, it will be applied vertically."
7
+ ).defaultValue(false),
8
+ disableRoving: PropTypes.bool.description("If true, the roving tab index will not be applied to the items."),
9
+ focusCriteria: PropTypes.func.description(
10
+ "Function that returns a boolean to determine if the element should be focused."
11
+ )
12
+ };
13
+ export {
14
+ propTypes
15
+ };
16
+ //# sourceMappingURL=react-desc-prop-types.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../../scripts/build/transpile/react-shim.js", "../../src/react-desc-prop-types.ts"],
4
+ "sourcesContent": ["import * as React from 'react';\nexport { React };\n", "/* eslint-disable @typescript-eslint/no-empty-interface */\n\nimport type { WeakValidationMap } from 'react';\nimport { PropTypes } from '@elliemae/ds-utilities';\nimport { type useKeyboardNavigation } from './DSHooksKeyboardNavigation.js';\nexport declare namespace DSHooksKeyboardNaviationT {\n interface Props {\n options: string[];\n isHorizontal?: boolean;\n disableRoving?: boolean;\n focusCriteria?: (dsId: string) => boolean;\n }\n\n type UseKeyboardNavigationReturnType = ReturnType<typeof useKeyboardNavigation>;\n type ItemPropsT = ReturnType<UseKeyboardNavigationReturnType['getItemProps']>;\n type WrapperPropsT = ReturnType<UseKeyboardNavigationReturnType['getWrapperProps']>;\n}\n\nexport const propTypes = {\n options: PropTypes.arrayOf(PropTypes.string).description('Array of strings to be items ids.').isRequired,\n isHorizontal: PropTypes.bool.isRequired\n .description(\n 'If true, the roving tab index will be applied to the items horizontally. If false, it will be applied vertically.',\n )\n .defaultValue(false),\n disableRoving: PropTypes.bool.description('If true, the roving tab index will not be applied to the items.'),\n focusCriteria: PropTypes.func.description(\n 'Function that returns a boolean to determine if the element should be focused.',\n ),\n} as WeakValidationMap<unknown>;\n"],
5
+ "mappings": "AAAA,YAAY,WAAW;ACGvB,SAAS,iBAAiB;AAenB,MAAM,YAAY;AAAA,EACvB,SAAS,UAAU,QAAQ,UAAU,MAAM,EAAE,YAAY,mCAAmC,EAAE;AAAA,EAC9F,cAAc,UAAU,KAAK,WAC1B;AAAA,IACC;AAAA,EACF,EACC,aAAa,KAAK;AAAA,EACrB,eAAe,UAAU,KAAK,YAAY,iEAAiE;AAAA,EAC3G,eAAe,UAAU,KAAK;AAAA,IAC5B;AAAA,EACF;AACF;",
6
+ "names": []
7
+ }
@@ -0,0 +1,17 @@
1
+ /// <reference types="react" />
2
+ import { type DSHooksKeyboardNaviationT } from './react-desc-prop-types.js';
3
+ declare const useKeyboardNavigation: (props: DSHooksKeyboardNaviationT.Props) => {
4
+ getWrapperProps: () => {
5
+ onKeyDown: import("react").KeyboardEventHandler<Element>;
6
+ onBlur: (e: import("react").FocusEvent<Element, Element>, ...args: unknown[]) => void;
7
+ };
8
+ getItemProps: (dsId: string) => {
9
+ innerRef: (el: HTMLElement | null) => void;
10
+ onFocus: () => void;
11
+ tabIndex: number;
12
+ };
13
+ focusedOption: string | null;
14
+ setFocusedOption: import("react").Dispatch<import("react").SetStateAction<string | null>>;
15
+ };
16
+ declare const UseKeyboardNavigationWithSchema: import("@elliemae/ds-props-helpers/dist/types/propTypes/types.js").DocumentedReactComponent<DSHooksKeyboardNaviationT.Props>;
17
+ export { useKeyboardNavigation, UseKeyboardNavigationWithSchema };
@@ -0,0 +1,2 @@
1
+ export { UseKeyboardNavigationWithSchema, useKeyboardNavigation } from './DSHooksKeyboardNavigation.js';
2
+ export { type DSHooksKeyboardNaviationT } from './react-desc-prop-types.js';
@@ -0,0 +1,14 @@
1
+ import type { WeakValidationMap } from 'react';
2
+ import { type useKeyboardNavigation } from './DSHooksKeyboardNavigation.js';
3
+ export declare namespace DSHooksKeyboardNaviationT {
4
+ interface Props {
5
+ options: string[];
6
+ isHorizontal?: boolean;
7
+ disableRoving?: boolean;
8
+ focusCriteria?: (dsId: string) => boolean;
9
+ }
10
+ type UseKeyboardNavigationReturnType = ReturnType<typeof useKeyboardNavigation>;
11
+ type ItemPropsT = ReturnType<UseKeyboardNavigationReturnType['getItemProps']>;
12
+ type WrapperPropsT = ReturnType<UseKeyboardNavigationReturnType['getWrapperProps']>;
13
+ }
14
+ export declare const propTypes: WeakValidationMap<unknown>;
package/package.json ADDED
@@ -0,0 +1,71 @@
1
+ {
2
+ "name": "@elliemae/ds-hooks-keyboard-navigation",
3
+ "version": "3.27.0-next.1",
4
+ "license": "MIT",
5
+ "description": "ICE MT - Dimsum - Hooks Keyboaord Navigation",
6
+ "files": [
7
+ "dist"
8
+ ],
9
+ "module": "./dist/esm/index.js",
10
+ "main": "./dist/cjs/index.js",
11
+ "types": "./dist/types/index.d.ts",
12
+ "exports": {
13
+ ".": {
14
+ "import": "./dist/esm/index.js",
15
+ "require": "./dist/cjs/index.js"
16
+ }
17
+ },
18
+ "sideEffects": [
19
+ "*.css",
20
+ "*.scss"
21
+ ],
22
+ "repository": {
23
+ "type": "git",
24
+ "url": "https://git.elliemae.io/platform-ui/dimsum.git"
25
+ },
26
+ "engines": {
27
+ "pnpm": ">=6",
28
+ "node": ">=16"
29
+ },
30
+ "author": "ICE MT",
31
+ "jestSonar": {
32
+ "sonar56x": true,
33
+ "reportPath": "reports",
34
+ "reportFile": "tests.xml",
35
+ "indent": 4
36
+ },
37
+ "dependencies": {
38
+ "@elliemae/ds-props-helpers": "3.27.0-next.1",
39
+ "@elliemae/ds-utilities": "3.27.0-next.1"
40
+ },
41
+ "devDependencies": {
42
+ "@elliemae/pui-cli": "~9.0.0-next.31",
43
+ "@xstyled/system": "3.7.0",
44
+ "styled-components": "~5.3.9",
45
+ "styled-system": "~5.1.5",
46
+ "@elliemae/ds-monorepo-devops": "3.27.0-next.1"
47
+ },
48
+ "peerDependencies": {
49
+ "lodash": "^4.17.21",
50
+ "react": "~17.0.2",
51
+ "react-dom": "^17.0.2",
52
+ "styled-components": "~5.3.9",
53
+ "styled-system": "^5.1.5"
54
+ },
55
+ "publishConfig": {
56
+ "access": "public",
57
+ "typeSafety": true
58
+ },
59
+ "scripts": {
60
+ "dev": "cross-env NODE_ENV=development node ../../../scripts/build/build.mjs --watch",
61
+ "test": "pui-cli test --passWithNoTests",
62
+ "lint": "node ../../../scripts/lint.mjs --fix",
63
+ "eslint:fix": "eslint --ext='.js,.jsx,.test.js,.ts,.tsx' --fix --config='../../../.eslintrc.js' src/",
64
+ "dts": "node ../../../scripts/dts.mjs",
65
+ "dts:withdeps": "pnpm --filter {.}... dts",
66
+ "build": "cross-env NODE_ENV=production node ../../../scripts/build/build.mjs",
67
+ "dev:build": "pnpm --filter {.}... build",
68
+ "dev:install": "pnpm --filter {.}... i --no-lockfile && pnpm run dev:build",
69
+ "checkDeps": "npm exec ../../util/ds-codemods -- check-missing-packages --projectFolderPath=\"./\" --ignorePackagesGlobPattern=\"\" --ignoreFilesGlobPattern=\"**/test-ables/*,**/tests/*\""
70
+ }
71
+ }